QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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#ifndef SIP_RUN
29namespace Qt3DRender
30{
31 class QRenderSettings;
32 class QCamera;
33 class QPickEvent;
34 class QObjectPicker;
35}
36
37namespace Qt3DLogic
38{
39 class QFrameAction;
40}
41
42namespace Qt3DExtras
43{
44 class QForwardRenderer;
45 class QSkyboxEntity;
46}
47#endif
48
49
50class Qgs3DAxis;
53class QgsMapLayer;
56class QgsTerrainEntity;
57class QgsChunkedEntity;
58class QgsSkyboxEntity;
63class QgsChunkNode;
64class QgsDoubleRange;
65
72#ifndef SIP_RUN
73class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
74{
75#else
76class _3D_EXPORT Qgs3DMapScene : public QObject
77{
78#endif
79
80 Q_OBJECT
81 public:
84
86 QgsCameraController *cameraController() { return mCameraController; }
87
92 QgsTerrainEntity *terrainEntity() SIP_SKIP { return mTerrain; }
93
95 void viewZoomFull();
96
102 void setViewFrom2DExtent( const QgsRectangle &extent );
103
109 QVector<QgsPointXY> viewFrustum2DExtent();
110
112 int terrainPendingJobsCount() const;
113
118 int totalPendingJobsCount() const;
119
122 {
125 };
126
128 SceneState sceneState() const { return mSceneState; }
129
131 void registerPickHandler( Qgs3DMapScenePickHandler *pickHandler ) SIP_SKIP;
133 void unregisterPickHandler( Qgs3DMapScenePickHandler *pickHandler ) SIP_SKIP;
134
139 float worldSpaceError( float epsilon, float distance );
140
142 void exportScene( const Qgs3DMapExportSettings &exportSettings );
143
149 QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
150
156 QgsRectangle sceneExtent();
157
164 QgsDoubleRange elevationRange() const;
165
171 Qgs3DAxis *get3DAxis() SIP_SKIP { return m3DAxis; }
172
178 QgsAbstract3DEngine *engine() SIP_SKIP { return mEngine; }
179
185 Qgs3DMapSettings *mapSettings() const { return &mMap; }
186
194 static QMap< QString, Qgs3DMapScene * > openScenes();
195
196#ifndef SIP_RUN
198 static std::function< QMap< QString, Qgs3DMapScene * >() > sOpenScenesFunction;
199#endif
200
201 signals:
206
214
216 void fpsCountChanged( float fpsCount );
218 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
219
225 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
226
227 public slots:
229 void updateTemporal();
230
231 private slots:
232 void onCameraChanged();
233 void onFrameTriggered( float dt );
234 void createTerrain();
235 void onLayerRenderer3DChanged();
236 void onLayersChanged();
237 void createTerrainDeferred();
238 void onBackgroundColorChanged();
239 void onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
240 void updateLights();
241 void updateCameraLens();
242 void onRenderersChanged();
243 void onSkyboxSettingsChanged();
244 void onShadowSettingsChanged();
245 void onAmbientOcclusionSettingsChanged();
246 void onEyeDomeShadingSettingsChanged();
247 void onDebugShadowMapSettingsChanged();
248 void onDebugDepthMapSettingsChanged();
249 void onCameraMovementSpeedChanged();
250 void onCameraNavigationModeChanged();
251 void onDebugOverlayEnabledChanged();
252
253 void on3DAxisSettingsChanged();
254
255 bool updateCameraNearFarPlanes();
256
257 private:
258#ifdef SIP_RUN
260 Qgs3DMapScene( const Qgs3DMapScene &other );
261#endif
262
263 void addLayerEntity( QgsMapLayer *layer );
264 void removeLayerEntity( QgsMapLayer *layer );
265 void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
266 void addCameraRotationCenterEntity( QgsCameraController *controller );
267 void setSceneState( SceneState state );
268 void updateSceneState();
269 void updateScene();
270 void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
271 int maximumTextureSize() const;
272
273 private:
274 Qgs3DMapSettings &mMap;
275 QgsAbstract3DEngine *mEngine = nullptr;
277 Qt3DLogic::QFrameAction *mFrameAction = nullptr;
278 QgsCameraController *mCameraController = nullptr;
279 QgsTerrainEntity *mTerrain = nullptr;
280 QList<QgsChunkedEntity *> mChunkEntities;
282 Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
284 QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
285 QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
286 bool mTerrainUpdateScheduled = false;
287 SceneState mSceneState = Ready;
289 QList<Qgs3DMapScenePickHandler *> mPickHandlers;
291 QList<Qt3DCore::QEntity *> mLightEntities;
292 QList<QgsMapLayer *> mModelVectorLayers;
293 QgsSkyboxEntity *mSkybox = nullptr;
295 Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
296
298 Qgs3DAxis *m3DAxis = nullptr;
299
300};
301
302#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.
QgsAbstract3DEngine * engine()
Returns the abstract 3D engine.
void fpsCountChanged(float fpsCount)
Emitted when the FPS count changes.
Qgs3DMapSettings * mapSettings() const
Returns the 3D map settings.
SceneState
Enumeration of possible states of the 3D scene.
@ Ready
The scene is fully loaded/updated.
@ Updating
The scene is still being loaded/updated.
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:92
void totalPendingJobsCountChanged()
Emitted when the total number of pending jobs changes.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is activated or deactivated.
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.
Qgs3DAxis * get3DAxis()
Returns the 3D axis object.
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:86
static std::function< QMap< QString, Qgs3DMapScene * >() > sOpenScenesFunction
Static function for returning open 3D map scenes.
Base class for all renderers that may to participate in 3D view.
QgsRange which stores a range of double values.
Definition: qgsrange.h:203
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