QGIS API Documentation 3.43.0-Master (3ee7834ace6)
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#include <QVector4D>
26
27#ifndef SIP_RUN
28namespace Qt3DRender
29{
30 class QRenderSettings;
31 class QCamera;
32} // namespace Qt3DRender
33
34namespace Qt3DLogic
35{
36 class QFrameAction;
37}
38
39namespace Qt3DExtras
40{
41 class QForwardRenderer;
42 class QSkyboxEntity;
43} // namespace Qt3DExtras
44#endif
45
46
47class Qgs3DAxis;
50class QgsMapLayer;
52class QgsTerrainEntity;
53class QgsChunkedEntity;
54class QgsSkyboxEntity;
58class QgsChunkNode;
59class QgsDoubleRange;
60class Qgs3DMapSceneEntity;
61
62
67#ifndef SIP_RUN
68class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
69{
70#else
71class _3D_EXPORT Qgs3DMapScene : public QObject
72{
73#endif
74
75 Q_OBJECT
76 public:
79
81 QgsCameraController *cameraController() const { return mCameraController; }
82
87 QgsTerrainEntity *terrainEntity() SIP_SKIP { return mTerrain; }
88
90 void viewZoomFull();
91
97 void setViewFrom2DExtent( const QgsRectangle &extent );
98
104 QVector<QgsPointXY> viewFrustum2DExtent() const;
105
107 int terrainPendingJobsCount() const;
108
113 int totalPendingJobsCount() const;
114
117 {
120 };
121
123 SceneState sceneState() const { return mSceneState; }
124
129 float worldSpaceError( float epsilon, float distance ) const;
130
135 bool exportScene( const Qgs3DMapExportSettings &exportSettings );
136
142 QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
143
149 QList<QgsMapLayer *> layers() const SIP_SKIP { return mLayerEntities.keys(); }
150
156 Qt3DCore::QEntity *layerEntity( QgsMapLayer *layer ) const SIP_SKIP { return mLayerEntities.value( layer ); }
157
163 QgsRectangle sceneExtent() const;
164
171 QgsDoubleRange elevationRange() const;
172
178 Qgs3DAxis *get3DAxis() const SIP_SKIP { return m3DAxis; }
179
185 QgsAbstract3DEngine *engine() const SIP_SKIP { return mEngine; }
186
192 Qgs3DMapSettings *mapSettings() const { return &mMap; }
193
201 bool hasSceneUpdatesEnabled() const { return mSceneUpdatesEnabled; }
202
210 void setSceneUpdatesEnabled( bool enabled ) { mSceneUpdatesEnabled = enabled; }
211
226 bool hasSceneOriginShiftEnabled() const { return mSceneOriginShiftEnabled; }
227
237 void setSceneOriginShiftEnabled( bool enabled ) { mSceneOriginShiftEnabled = enabled; }
238
246 Q_DECL_DEPRECATED static QMap<QString, Qgs3DMapScene *> openScenes() SIP_DEPRECATED;
247
268 void enableClipping( const QList<QVector4D> &clipPlaneEquations );
269
276 void disableClipping();
277
278#ifndef SIP_RUN
280 static std::function<QMap<QString, Qgs3DMapScene *>()> sOpenScenesFunction;
281#endif
282
283 signals:
288
296
298 void fpsCountChanged( float fpsCount );
300 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
301
307 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
308
315
316 public slots:
318 void updateTemporal();
319
320 private slots:
321 void onCameraChanged();
322 void onFrameTriggered( float dt );
323 void createTerrain();
324 void onLayerRenderer3DChanged();
325 void onLayersChanged();
326 void createTerrainDeferred();
327 void onBackgroundColorChanged();
328 void updateLights();
329 void updateCameraLens();
330 void onSkyboxSettingsChanged();
331 void onShadowSettingsChanged();
332 void onAmbientOcclusionSettingsChanged();
333 void onEyeDomeShadingSettingsChanged();
334 void onDebugShadowMapSettingsChanged();
335 void onDebugDepthMapSettingsChanged();
336 void onCameraMovementSpeedChanged();
337 void onCameraNavigationModeChanged();
338 void onDebugOverlayEnabledChanged();
339 void onStopUpdatesChanged();
340 void on3DAxisSettingsChanged();
341
342 void onOriginChanged();
343
344 bool updateCameraNearFarPlanes();
345
346 private:
347#ifdef SIP_RUN
349 Qgs3DMapScene( const Qgs3DMapScene &other );
350#endif
351
352 void addLayerEntity( QgsMapLayer *layer );
353 void removeLayerEntity( QgsMapLayer *layer );
354 void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
355 void addCameraRotationCenterEntity( QgsCameraController *controller );
356 void setSceneState( SceneState state );
357 void updateSceneState();
358 void updateScene( bool forceUpdate = false );
359 void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
360 int maximumTextureSize() const;
361
362 void handleClippingOnEntity( QEntity *entity ) const;
363 void handleClippingOnAllEntities() const;
364
365 private:
366 Qgs3DMapSettings &mMap;
367 QgsAbstract3DEngine *mEngine = nullptr;
369 Qt3DLogic::QFrameAction *mFrameAction = nullptr;
370 QgsCameraController *mCameraController = nullptr;
371 QgsTerrainEntity *mTerrain = nullptr;
372 QList<Qgs3DMapSceneEntity *> mSceneEntities;
374 Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
376 QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
377 bool mTerrainUpdateScheduled = false;
378 SceneState mSceneState = Ready;
380 QList<Qt3DCore::QEntity *> mLightEntities;
381 QList<QgsMapLayer *> mModelVectorLayers;
382 QgsSkyboxEntity *mSkybox = nullptr;
384 Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
385
387 Qgs3DAxis *m3DAxis = nullptr;
388
389 bool mSceneUpdatesEnabled = true;
390 bool mSceneOriginShiftEnabled = true;
391
392 QList<QVector4D> mClipPlanesEquations;
393 int mMaxClipPlanes = 6;
394};
395#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.
bool hasSceneOriginShiftEnabled() const
Returns whether the 3D scene is allowed to automatically move the scene's origin.
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.
void setSceneOriginShiftEnabled(bool enabled)
Returns whether the 3D scene is allowed to automatically move the scene's origin.
Base class for all renderers that may to participate in 3D view.
QgsRange which stores a range of double values.
Definition qgsrange.h:233
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