QGIS API Documentation  3.25.0-Master (6b426f5f8a)
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 
49 class QgsMapLayer;
51 class Qgs3DMapSettings;
52 class QgsTerrainEntity;
53 class QgsChunkedEntity;
54 class QgsSkyboxEntity;
55 class QgsSkyboxSettings;
59 class QgsChunkNode;
60 
61 #define SIP_NO_FILE
62 
69 class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
70 {
71  Q_OBJECT
72  public:
74  Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *engine );
75 
77  QgsCameraController *cameraController() { return mCameraController; }
79  QgsTerrainEntity *terrainEntity() { return mTerrain; }
80 
82  void viewZoomFull();
83 
89  void setViewFrom2DExtent( const QgsRectangle &extent );
90 
96  QVector<QgsPointXY> viewFrustum2DExtent();
97 
99  int terrainPendingJobsCount() const;
100 
105  int totalPendingJobsCount() const;
106 
109  {
112  };
113 
115  SceneState sceneState() const { return mSceneState; }
116 
118  void registerPickHandler( Qgs3DMapScenePickHandler *pickHandler );
120  void unregisterPickHandler( Qgs3DMapScenePickHandler *pickHandler );
121 
126  float worldSpaceError( float epsilon, float distance );
127 
129  void exportScene( const Qgs3DMapExportSettings &exportSettings );
130 
136  QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
137 
143  QgsRectangle sceneExtent();
144  signals:
149 
157 
159  void fpsCountChanged( float fpsCount );
161  void fpsCounterEnabledChanged( bool fpsCounterEnabled );
162 
168  void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
169 
170  public slots:
172  void updateTemporal();
173 
174  private slots:
175  void onCameraChanged();
176  void onFrameTriggered( float dt );
177  void createTerrain();
178  void onLayerRenderer3DChanged();
179  void onLayersChanged();
180  void createTerrainDeferred();
181  void onBackgroundColorChanged();
182  void onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
183  void updateLights();
184  void updateCameraLens();
185  void onRenderersChanged();
186  void onSkyboxSettingsChanged();
187  void onShadowSettingsChanged();
188  void onEyeDomeShadingSettingsChanged();
189  void onDebugShadowMapSettingsChanged();
190  void onDebugDepthMapSettingsChanged();
191  void onCameraMovementSpeedChanged();
192 
193  bool updateCameraNearFarPlanes();
194 
195  private:
196  void addLayerEntity( QgsMapLayer *layer );
197  void removeLayerEntity( QgsMapLayer *layer );
198  void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
199  void addCameraRotationCenterEntity( QgsCameraController *controller );
200  void setSceneState( SceneState state );
201  void updateSceneState();
202  void updateScene();
203  void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
204  int maximumTextureSize() const;
205 
206  private:
207  const Qgs3DMapSettings &mMap;
208  QgsAbstract3DEngine *mEngine = nullptr;
210  Qt3DLogic::QFrameAction *mFrameAction = nullptr;
211  QgsCameraController *mCameraController = nullptr;
212  QgsTerrainEntity *mTerrain = nullptr;
213  QList<QgsChunkedEntity *> mChunkEntities;
215  Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
217  QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
218  QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
219  bool mTerrainUpdateScheduled = false;
220  SceneState mSceneState = Ready;
222  QList<Qgs3DMapScenePickHandler *> mPickHandlers;
224  QList<Qt3DCore::QEntity *> mLightEntities;
225  QList<QgsMapLayer *> mModelVectorLayers;
226  QgsSkyboxEntity *mSkybox = nullptr;
228  Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
229 };
230 
231 #endif // QGS3DMAPSCENE_H
Manages the various settings the user can choose from when exporting a 3D scene 3.
void terrainPendingJobsCountChanged()
Emitted when the number of terrain's pending jobs changes.
void viewed2DExtentFrom3DChanged(QVector< QgsPointXY > extent)
Emitted when the viewed 2D extent seen by the 3D camera has changed.
void fpsCountChanged(float fpsCount)
Emitted when the FPS count changes.
SceneState
Enumeration of possible states of the 3D scene.
@ Ready
The scene is fully loaded/updated.
@ Updating
The scene is still being loaded/updated.
void totalPendingJobsCountChanged()
Emitted when the total number of pending jobs changes.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is activated or deactivated.
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:77
void sceneStateChanged()
Emitted when the scene's state has changed.
SceneState sceneState() const
Returns the current state of the scene.
void terrainEntityChanged()
Emitted when the current terrain entity is replaced by a new one.
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:79
Base class for all renderers that may to participate in 3D view.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Base class for all skybox types.
Contains the configuration of a skybox entity.
#define SIP_SKIP
Definition: qgis_sip.h:126
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28