Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Address reviews
  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Mar 1, 2021
1 parent 18bdcf0 commit 364959a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/3d/qgsoffscreen3dengine.h
Expand Up @@ -96,8 +96,6 @@ class _3D_EXPORT QgsOffscreen3DEngine : public QgsAbstract3DEngine
Qt3DRender::QRenderSettings *mRenderSettings = nullptr; // The render settings, which control the general rendering behavior.
Qt3DCore::QNode *mSceneRoot = nullptr; // The scene root, which becomes a child of the engine's root entity.
Qt3DCore::QEntity *mRoot = nullptr;

// QgsShadowRenderingFrameGraph *mFrameGraph = nullptr;
};

#endif // QGSOFFSCREEN3DENGINE_H
5 changes: 1 addition & 4 deletions src/3d/qgsshadowrenderingframegraph.cpp
Expand Up @@ -456,8 +456,5 @@ void QgsShadowRenderingFrameGraph::setRenderCaptureEnabled( bool enabled )
if ( enabled == mRenderCaptureEnabled )
return;
mRenderCaptureEnabled = enabled;
if ( mRenderCaptureEnabled )
mRenderCaptureTargetSelector->setParent( mPostprocessPassLayerFilter );
else
mRenderCaptureTargetSelector->setParent( ( Qt3DCore::QNode * ) nullptr );
mRenderCaptureTargetSelector->setEnabled( mRenderCaptureEnabled );
}
30 changes: 21 additions & 9 deletions src/app/3d/qgs3dmapcanvas.cpp
Expand Up @@ -18,6 +18,7 @@
#include <QBoxLayout>
#include <Qt3DExtras/Qt3DWindow>
#include <Qt3DRender/QRenderCapture>
#include <Qt3DLogic/QFrameAction>
#include <QMouseEvent>


Expand All @@ -43,6 +44,13 @@ Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent )
QgsSettings setting;
mEngine = new QgsWindow3DEngine( this );

connect( mEngine, &QgsAbstract3DEngine::imageCaptured, [ = ]( const QImage & image )
{
image.save( mCaptureFileName, mCaptureFileFormat.toLocal8Bit().data() );
mEngine->setRenderCaptureEnabled( false );
emit savedAsImage( mCaptureFileName );
} );

mContainer = QWidget::createWindowContainer( mEngine->window() );
mNavigationWidget = new Qgs3DNavigationWidget( this );

Expand Down Expand Up @@ -172,15 +180,19 @@ void Qgs3DMapCanvas::saveAsImage( const QString fileName, const QString fileForm
{
if ( !fileName.isEmpty() )
{
QgsOffscreen3DEngine engine;
engine.setSize( size() );
Qgs3DMapScene scene( *mMap, &engine );
engine.setRootEntity( &scene );
QgsCameraController *cameraController = mScene->cameraController();
scene.cameraController()->setLookingAtPoint( cameraController->lookingAtPoint(), cameraController->distance(), cameraController->pitch(), cameraController->yaw() );
QImage img = Qgs3DUtils::captureSceneImage( engine, &scene );
img.save( fileName, fileFormat.toLocal8Bit().data() );
emit savedAsImage( fileName );
mCaptureFileName = fileName;
mCaptureFileFormat = fileFormat;
mEngine->setRenderCaptureEnabled( true );
// Setup a frame action that is used to wait until next frame
Qt3DLogic::QFrameAction *screenCaptureFrameAction = new Qt3DLogic::QFrameAction;
mScene->addComponent( screenCaptureFrameAction );
// Wait to have the render capture enabled in the next frame
connect( screenCaptureFrameAction, &Qt3DLogic::QFrameAction::triggered, [ = ]( float )
{
mEngine->requestCaptureImage();
mScene->removeComponent( screenCaptureFrameAction );
screenCaptureFrameAction->deleteLater();
} );
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/app/3d/qgs3dmapcanvas.h
Expand Up @@ -27,6 +27,11 @@ namespace Qt3DExtras
class Qt3DWindow;
}

namespace Qt3DLogic
{
class QFrameAction;
}

class Qgs3DMapSettings;
class Qgs3DMapScene;
class Qgs3DMapTool;
Expand Down Expand Up @@ -95,7 +100,7 @@ class Qgs3DMapCanvas : public QWidget

signals:
//! Emitted when the 3D map canvas was successfully saved as image
void savedAsImage( QString fileName );
void savedAsImage( const QString &fileName );

//! Emitted when the the map setting is changed
void mapSettingsChanged();
Expand Down Expand Up @@ -133,6 +138,9 @@ class Qgs3DMapCanvas : public QWidget
//! Active map tool that receives events (if NULLPTR then mouse/keyboard events are used for camera manipulation)
Qgs3DMapTool *mMapTool = nullptr;

QString mCaptureFileName;
QString mCaptureFileFormat;

//! On-Screen Navigation widget.
Qgs3DNavigationWidget *mNavigationWidget = nullptr;

Expand Down

0 comments on commit 364959a

Please sign in to comment.