QGIS API Documentation  3.17.0-Master (a035f434f4)
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 
26 namespace Qt3DRender
27 {
28  class QRenderSettings;
29  class QCamera;
30  class QPickEvent;
31  class QObjectPicker;
32 }
33 
34 namespace Qt3DLogic
35 {
36  class QFrameAction;
37 }
38 
39 namespace Qt3DExtras
40 {
41  class QForwardRenderer;
42  class QSkyboxEntity;
43 }
44 
47 class QgsMapLayer;
50 class Qgs3DMapSettings;
51 class QgsTerrainEntity;
52 class QgsChunkedEntity;
53 class QgsSkyboxEntity;
54 class QgsSkyboxSettings;
58 
59 
60 #define SIP_NO_FILE
61 
68 class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
69 {
70  Q_OBJECT
71  public:
73  Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *engine );
74 
76  QgsCameraController *cameraController() { return mCameraController; }
78  QgsTerrainEntity *terrainEntity() { return mTerrain; }
79 
81  void viewZoomFull();
82 
84  int terrainPendingJobsCount() const;
85 
90  int totalPendingJobsCount() const;
91 
94  {
97  };
98 
100  SceneState sceneState() const { return mSceneState; }
101 
103  void registerPickHandler( Qgs3DMapScenePickHandler *pickHandler );
105  void unregisterPickHandler( Qgs3DMapScenePickHandler *pickHandler );
106 
111  float worldSpaceError( float epsilon, float distance );
112 
114  void exportScene( const Qgs3DMapExportSettings &exportSettings );
115  signals:
117  void terrainEntityChanged();
119  void terrainPendingJobsCountChanged();
120 
125  void totalPendingJobsCountChanged();
127  void sceneStateChanged();
128 
129  public slots:
131  void updateTemporal();
132 
133  private slots:
134  void onCameraChanged();
135  void onFrameTriggered( float dt );
136  void createTerrain();
137  void onLayerRenderer3DChanged();
138  void onLayersChanged();
139  void createTerrainDeferred();
140  void onBackgroundColorChanged();
141  void onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
142  void updateLights();
143  void updateCameraLens();
144  void onRenderersChanged();
145  void onSkyboxSettingsChanged();
146  void onShadowSettingsChanged();
147  void onEyeDomeShadingSettingsChanged();
148  void onDebugShadowMapSettingsChanged();
149  void onDebugDepthMapSettingsChanged();
150 
151  private:
152  void addLayerEntity( QgsMapLayer *layer );
153  void removeLayerEntity( QgsMapLayer *layer );
154  void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
155  void setSceneState( SceneState state );
156  void updateSceneState();
157  void updateScene();
158  bool updateCameraNearFarPlanes();
159  void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
160  int maximumTextureSize() const;
161 
162  private:
163  const Qgs3DMapSettings &mMap;
164  QgsAbstract3DEngine *mEngine = nullptr;
166  Qt3DLogic::QFrameAction *mFrameAction = nullptr;
167  QgsCameraController *mCameraController = nullptr;
168  QgsTerrainEntity *mTerrain = nullptr;
169  QList<QgsChunkedEntity *> mChunkEntities;
171  Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
173  QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
174  QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
175  bool mTerrainUpdateScheduled = false;
176  SceneState mSceneState = Ready;
178  QList<Qgs3DMapScenePickHandler *> mPickHandlers;
180  QList<Qt3DCore::QEntity *> mLightEntities;
182  QList<Qt3DCore::QEntity *> mLightOriginEntities;
183  QList<QgsMapLayer *> mModelVectorLayers;
184  QgsSkyboxEntity *mSkybox = nullptr;
185 };
186 
187 #endif // QGS3DMAPSCENE_H
3 Abstract base class for handlers that process pick events from a 3D map scene.
Base class for all map layer types.
Definition: qgsmaplayer.h:83
Base class for all renderers that may to participate in 3D view.
class containing the configuration of a skybox entity 3
SceneState
Enumeration of possible states of the 3D scene.
Definition: qgs3dmapscene.h:93
base class for all skybox types It holds the common member data between different skybox entity types...
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features ...
Definition: qgsfeatureid.h:28
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:78
3 Definition of the world
SceneState sceneState() const
Returns the current state of the scene.
3 Base class for 3D engine implementation.
3 Object that controls camera movement based on user input
The scene is fully loaded/updated.
Definition: qgs3dmapscene.h:95
3 An entity that is responsible for applying post processing effect Now it is used to make shadows ...
The Qgs3DMapExportSettings class Manages the various settings the user can choose from when exporting...
3 Container class that holds different objects related to shadow rendering
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children...
Definition: qgs3dmapscene.h:68
The scene is still being loaded/updated.
Definition: qgs3dmapscene.h:96
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:76