QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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 "qgsrectangle.h"
24#include "qgscameracontroller.h"
25
26#ifndef SIP_RUN
27namespace Qt3DRender
28{
29 class QRenderSettings;
30 class QCamera;
31}
32
33namespace Qt3DLogic
34{
35 class QFrameAction;
36}
37
38namespace Qt3DExtras
39{
40 class QForwardRenderer;
41 class QSkyboxEntity;
42}
43#endif
44
45
46class Qgs3DAxis;
49class QgsMapLayer;
51class QgsTerrainEntity;
52class QgsChunkedEntity;
53class QgsSkyboxEntity;
57class QgsChunkNode;
58class QgsDoubleRange;
59class Qgs3DMapSceneEntity;
60
61
66#ifndef SIP_RUN
67class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
68{
69#else
70class _3D_EXPORT Qgs3DMapScene : public QObject
71{
72#endif
73
74 Q_OBJECT
75 public:
78
80 QgsCameraController *cameraController() const { return mCameraController; }
81
86 QgsTerrainEntity *terrainEntity() SIP_SKIP { return mTerrain; }
87
89 void viewZoomFull();
90
96 void setViewFrom2DExtent( const QgsRectangle &extent );
97
103 QVector<QgsPointXY> viewFrustum2DExtent() const;
104
106 int terrainPendingJobsCount() const;
107
112 int totalPendingJobsCount() const;
113
116 {
119 };
120
122 SceneState sceneState() const { return mSceneState; }
123
128 float worldSpaceError( float epsilon, float distance ) const;
129
131 void exportScene( const Qgs3DMapExportSettings &exportSettings );
132
138 QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
139
145 QList<QgsMapLayer *> layers() const SIP_SKIP { return mLayerEntities.keys(); }
146
152 Qt3DCore::QEntity *layerEntity( QgsMapLayer *layer ) const SIP_SKIP { return mLayerEntities.value( layer ); }
153
159 QgsRectangle sceneExtent() const;
160
167 QgsDoubleRange elevationRange() const;
168
174 Qgs3DAxis *get3DAxis() const SIP_SKIP { return m3DAxis; }
175
181 QgsAbstract3DEngine *engine() const SIP_SKIP { return mEngine; }
182
188 Qgs3DMapSettings *mapSettings() const { return &mMap; }
189
197 bool hasSceneUpdatesEnabled() const { return mSceneUpdatesEnabled; }
198
206 void setSceneUpdatesEnabled( bool enabled ) { mSceneUpdatesEnabled = enabled; }
207
215 Q_DECL_DEPRECATED static QMap< QString, Qgs3DMapScene * > openScenes() SIP_DEPRECATED;
216
237 void enableClipping( const QList<QVector4D> &clipPlaneEquations );
238
245 void disableClipping();
246
247#ifndef SIP_RUN
249 static std::function< QMap< QString, Qgs3DMapScene * >() > sOpenScenesFunction;
250#endif
251
252 signals:
257
265
267 void fpsCountChanged( float fpsCount );
269 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
270
276 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
277
284
285 public slots:
287 void updateTemporal();
288
289 private slots:
290 void onCameraChanged();
291 void onFrameTriggered( float dt );
292 void createTerrain();
293 void onLayerRenderer3DChanged();
294 void onLayersChanged();
295 void createTerrainDeferred();
296 void onBackgroundColorChanged();
297 void updateLights();
298 void updateCameraLens();
299 void onSkyboxSettingsChanged();
300 void onShadowSettingsChanged();
301 void onAmbientOcclusionSettingsChanged();
302 void onEyeDomeShadingSettingsChanged();
303 void onDebugShadowMapSettingsChanged();
304 void onDebugDepthMapSettingsChanged();
305 void onCameraMovementSpeedChanged();
306 void onCameraNavigationModeChanged();
307 void onDebugOverlayEnabledChanged();
308
309 void on3DAxisSettingsChanged();
310
311 bool updateCameraNearFarPlanes();
312
313 private:
314#ifdef SIP_RUN
316 Qgs3DMapScene( const Qgs3DMapScene &other );
317#endif
318
319 void addLayerEntity( QgsMapLayer *layer );
320 void removeLayerEntity( QgsMapLayer *layer );
321 void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
322 void addCameraRotationCenterEntity( QgsCameraController *controller );
323 void setSceneState( SceneState state );
324 void updateSceneState();
325 void updateScene( bool forceUpdate = false );
326 void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
327 int maximumTextureSize() const;
328
329 void handleClippingOnEntity( QEntity *entity ) const;
330 void handleClippingOnAllEntities() const;
331
332 private:
333
334 Qgs3DMapSettings &mMap;
335 QgsAbstract3DEngine *mEngine = nullptr;
337 Qt3DLogic::QFrameAction *mFrameAction = nullptr;
338 QgsCameraController *mCameraController = nullptr;
339 QgsTerrainEntity *mTerrain = nullptr;
340 QList<Qgs3DMapSceneEntity *> mSceneEntities;
342 Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
344 QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
345 bool mTerrainUpdateScheduled = false;
346 SceneState mSceneState = Ready;
348 QList<Qt3DCore::QEntity *> mLightEntities;
349 QList<QgsMapLayer *> mModelVectorLayers;
350 QgsSkyboxEntity *mSkybox = nullptr;
352 Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
353
355 Qgs3DAxis *m3DAxis = nullptr;
356
357 bool mSceneUpdatesEnabled = true;
358
359 QList<QVector4D> mClipPlanesEquations;
360
361};
362#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.
Qgs3DAxis * get3DAxis() const
Returns the 3D axis object.
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.
Qgs3DMapSettings * mapSettings() const
Returns the 3D map settings.
QgsAbstract3DEngine * engine() const
Returns the abstract 3D engine.
void gpuMemoryLimitReached()
Emitted when one of the entities reaches its GPU memory limit and it is not possible to lower the GPU...
QgsCameraController * cameraController() const
Returns camera controller.
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)
bool hasSceneUpdatesEnabled() const
Returns whether updates of the 3D scene's entities are allowed.
void totalPendingJobsCountChanged()
Emitted when the total number of pending jobs changes.
Qt3DCore::QEntity * layerEntity(QgsMapLayer *layer) const
Returns the entity belonging to layer.
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.
QList< QgsMapLayer * > layers() const
Returns the layers that contain chunked entities.
void terrainEntityChanged()
Emitted when the current terrain entity is replaced by a new one.
void setSceneUpdatesEnabled(bool enabled)
Sets whether updates of the 3D scene's entities are allowed.
Base class for all renderers that may to participate in 3D view.
QgsRange which stores a range of double values.
Definition qgsrange.h:231
Base class for all map layer types.
Definition qgsmaplayer.h:76
A rectangle specified with double values.
Base class for all skybox types.
Contains the configuration of a skybox entity.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126