QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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:
120 
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 
148  private:
149  void addLayerEntity( QgsMapLayer *layer );
150  void removeLayerEntity( QgsMapLayer *layer );
151  void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
152  void setSceneState( SceneState state );
153  void updateSceneState();
154  void updateScene();
155  bool updateCameraNearFarPlanes();
156  void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
157  int maximumTextureSize() const;
158 
159  private:
160  const Qgs3DMapSettings &mMap;
161  QgsAbstract3DEngine *mEngine = nullptr;
163  Qt3DLogic::QFrameAction *mFrameAction = nullptr;
164  QgsCameraController *mCameraController = nullptr;
165  QgsTerrainEntity *mTerrain = nullptr;
166  QList<QgsChunkedEntity *> mChunkEntities;
168  Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
170  QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
171  QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
172  bool mTerrainUpdateScheduled = false;
173  SceneState mSceneState = Ready;
175  QList<Qgs3DMapScenePickHandler *> mPickHandlers;
177  QList<Qt3DCore::QEntity *> mLightEntities;
179  QList<Qt3DCore::QEntity *> mLightOriginEntities;
180  QList<QgsMapLayer *> mModelVectorLayers;
181  QgsSkyboxEntity *mSkybox = nullptr;
182 };
183 
184 #endif // QGS3DMAPSCENE_H
Qgs3DMapScene::terrainEntity
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:78
Qgs3DMapScene::terrainPendingJobsCountChanged
void terrainPendingJobsCountChanged()
Emitted when the number of terrain's pending jobs changes.
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:49
QgsSkyboxSettings
class containing the configuration of a skybox entity 3
Definition: qgsskyboxsettings.h:36
qgsfeatureid.h
QgsSkyboxEntity
base class for all skybox types It holds the common member data between different skybox entity types...
Definition: qgsskyboxentity.h:44
Qgs3DMapScene::Updating
@ Updating
The scene is still being loaded/updated.
Definition: qgs3dmapscene.h:96
QgsShadowRenderingFrameGraph
3 Container class that holds different objects related to shadow rendering
Definition: qgsshadowrenderingframegraph.h:57
qgsshadowrenderingframegraph.h
Qgs3DMapScene::sceneState
SceneState sceneState() const
Returns the current state of the scene.
Definition: qgs3dmapscene.h:100
Qgs3DMapScene::sceneStateChanged
void sceneStateChanged()
Emitted when the scene's state has changed.
Qt3DLogic
Definition: qgs3dmapscene.h:35
Qgs3DMapExportSettings
The Qgs3DMapExportSettings class Manages the various settings the user can choose from when exporting...
Definition: qgs3dmapexportsettings.h:32
Qgs3DMapScene::cameraController
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:76
Qt3DRender
Definition: qgs3dmapscene.h:27
Qgs3DMapSettings
3 Definition of the world
Definition: qgs3dmapsettings.h:54
Qgs3DMapScene::terrainEntityChanged
void terrainEntityChanged()
Emitted when the current terrain entity is replaced by a new one.
QgsAbstract3DEngine
3 Base class for 3D engine implementation.
Definition: qgsabstract3dengine.h:58
Qgs3DMapScene
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
Definition: qgs3dmapscene.h:69
Qgs3DMapScene::SceneState
SceneState
Enumeration of possible states of the 3D scene.
Definition: qgs3dmapscene.h:94
Qgs3DMapScene::Ready
@ Ready
The scene is fully loaded/updated.
Definition: qgs3dmapscene.h:95
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
Qgs3DMapScene::totalPendingJobsCountChanged
void totalPendingJobsCountChanged()
Emitted when the total number of pending jobs changes.
QgsCameraController
3 Object that controls camera movement based on user input
Definition: qgscameracontroller.h:60
QgsPostprocessingEntity
3 An entity that is responsible for applying post processing effect Now it is used to make shadows
Definition: qgspostprocessingentity.h:39
Qt3DExtras
Definition: qgs3dmapscene.h:40
Qgs3DMapScenePickHandler
3 Abstract base class for handlers that process pick events from a 3D map scene.
Definition: qgs3dmapscenepickhandler.h:36
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28