QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgs3dmapscene.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dmapscene.h
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGS3DMAPSCENE_H
17 #define QGS3DMAPSCENE_H
18 
19 #include "qgis_3d.h"
20 
21 #include <Qt3DCore/QEntity>
22 
23 #include "qgsfeatureid.h"
25 #include "qgsray3d.h"
26 #include "qgscameracontroller.h"
27 
28 namespace Qt3DRender
29 {
30  class QRenderSettings;
31  class QCamera;
32  class QPickEvent;
33  class QObjectPicker;
34 }
35 
36 namespace Qt3DLogic
37 {
38  class QFrameAction;
39 }
40 
41 namespace Qt3DExtras
42 {
43  class QForwardRenderer;
44  class QSkyboxEntity;
45 }
46 
47 class Qgs3DAxis;
50 class QgsMapLayer;
52 class Qgs3DMapSettings;
53 class QgsTerrainEntity;
54 class QgsChunkedEntity;
55 class QgsSkyboxEntity;
56 class QgsSkyboxSettings;
60 class QgsChunkNode;
61 
62 #define SIP_NO_FILE
63 
70 class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
71 {
72  Q_OBJECT
73  public:
76 
78  QgsCameraController *cameraController() { return mCameraController; }
80  QgsTerrainEntity *terrainEntity() { return mTerrain; }
81 
83  void viewZoomFull();
84 
90  void setViewFrom2DExtent( const QgsRectangle &extent );
91 
97  QVector<QgsPointXY> viewFrustum2DExtent();
98 
100  int terrainPendingJobsCount() const;
101 
106  int totalPendingJobsCount() const;
107 
110  {
113  };
114 
116  SceneState sceneState() const { return mSceneState; }
117 
119  void registerPickHandler( Qgs3DMapScenePickHandler *pickHandler );
121  void unregisterPickHandler( Qgs3DMapScenePickHandler *pickHandler );
122 
127  float worldSpaceError( float epsilon, float distance );
128 
130  void exportScene( const Qgs3DMapExportSettings &exportSettings );
131 
137  QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
138 
144  QgsRectangle sceneExtent();
145 
151  Qgs3DAxis *get3DAxis() { return m3DAxis; }
152 
158  QgsAbstract3DEngine *engine() { return mEngine; }
159 
160  signals:
162  void terrainEntityChanged();
164  void terrainPendingJobsCountChanged();
165 
170  void totalPendingJobsCountChanged();
172  void sceneStateChanged();
173 
175  void fpsCountChanged( float fpsCount );
177  void fpsCounterEnabledChanged( bool fpsCounterEnabled );
178 
184  void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
185 
186  public slots:
188  void updateTemporal();
189 
190  private slots:
191  void onCameraChanged();
192  void onFrameTriggered( float dt );
193  void createTerrain();
194  void onLayerRenderer3DChanged();
195  void onLayersChanged();
196  void createTerrainDeferred();
197  void onBackgroundColorChanged();
198  void onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
199  void updateLights();
200  void updateCameraLens();
201  void onRenderersChanged();
202  void onSkyboxSettingsChanged();
203  void onShadowSettingsChanged();
204  void onEyeDomeShadingSettingsChanged();
205  void onDebugShadowMapSettingsChanged();
206  void onDebugDepthMapSettingsChanged();
207  void onCameraMovementSpeedChanged();
208  void onCameraNavigationModeChanged();
209  void onDebugOverlayEnabledChanged();
210 
211  void on3DAxisSettingsChanged();
212 
213  bool updateCameraNearFarPlanes();
214 
215  private:
216  void addLayerEntity( QgsMapLayer *layer );
217  void removeLayerEntity( QgsMapLayer *layer );
218  void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
219  void addCameraRotationCenterEntity( QgsCameraController *controller );
220  void setSceneState( SceneState state );
221  void updateSceneState();
222  void updateScene();
223  void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
224  int maximumTextureSize() const;
225 
226  private:
227  Qgs3DMapSettings &mMap;
228  QgsAbstract3DEngine *mEngine = nullptr;
230  Qt3DLogic::QFrameAction *mFrameAction = nullptr;
231  QgsCameraController *mCameraController = nullptr;
232  QgsTerrainEntity *mTerrain = nullptr;
233  QList<QgsChunkedEntity *> mChunkEntities;
235  Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
237  QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
238  QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
239  bool mTerrainUpdateScheduled = false;
240  SceneState mSceneState = Ready;
242  QList<Qgs3DMapScenePickHandler *> mPickHandlers;
244  QList<Qt3DCore::QEntity *> mLightEntities;
245  QList<QgsMapLayer *> mModelVectorLayers;
246  QgsSkyboxEntity *mSkybox = nullptr;
248  Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
249 
251  Qgs3DAxis *m3DAxis = nullptr;
252 
253 };
254 
255 #endif // QGS3DMAPSCENE_H
Qgs3DMapScene::terrainEntity
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:80
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:48
QgsSkyboxSettings
Contains the configuration of a skybox entity.
Definition: qgsskyboxsettings.h:36
qgsfeatureid.h
QgsSkyboxEntity
Base class for all skybox types.
Definition: qgsskyboxentity.h:44
Qgs3DMapScene::Updating
@ Updating
The scene is still being loaded/updated.
Definition: qgs3dmapscene.h:112
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsShadowRenderingFrameGraph
Container class that holds different objects related to shadow rendering.
Definition: qgsshadowrenderingframegraph.h:59
qgsshadowrenderingframegraph.h
Qgs3DMapScene::sceneState
SceneState sceneState() const
Returns the current state of the scene.
Definition: qgs3dmapscene.h:116
Qt3DLogic
Definition: qgs3dmapscene.h:36
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
Qgs3DMapExportSettings
Manages the various settings the user can choose from when exporting a 3D scene.
Definition: qgs3dmapexportsettings.h:30
Qgs3DMapScene::cameraController
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:78
qgsray3d.h
Qt3DRender
Definition: qgs3dmapscene.h:28
Qgs3DAxis
Display 3D ortho axis in the main 3D view.
Definition: qgs3daxis.h:56
Qgs3DMapSettings
Definition of the world.
Definition: qgs3dmapsettings.h:57
qgscameracontroller.h
QgsAbstract3DEngine
Base class for 3D engine implementation. A 3D engine is responsible for setting up rendering with Qt3...
Definition: qgsabstract3dengine.h:60
Qgs3DMapScene
Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
Definition: qgs3dmapscene.h:70
Qgs3DMapScene::SceneState
SceneState
Enumeration of possible states of the 3D scene.
Definition: qgs3dmapscene.h:109
Qgs3DMapScene::Ready
@ Ready
The scene is fully loaded/updated.
Definition: qgs3dmapscene.h:111
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
Qgs3DMapScene::engine
QgsAbstract3DEngine * engine()
Returns the abstract 3D engine.
Definition: qgs3dmapscene.h:158
QgsCameraController
Object that controls camera movement based on user input.
Definition: qgscameracontroller.h:61
QgsPostprocessingEntity
An entity that is responsible for applying post processing effect.
Definition: qgspostprocessingentity.h:39
Qt3DExtras
Definition: qgs3dmapscene.h:41
Qgs3DMapScenePickHandler
Abstract base class for handlers that process pick events from a 3D map scene.
Definition: qgs3dmapscenepickhandler.h:36
Qgs3DMapScene::get3DAxis
Qgs3DAxis * get3DAxis()
Returns the 3D axis object.
Definition: qgs3dmapscene.h:151
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28