QGIS API Documentation 3.43.0-Master (a93bf8b6462)
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 QgsGlobeEntity;
54class QgsChunkedEntity;
55class 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
88 QgsTerrainEntity *terrainEntity() SIP_SKIP { return mTerrain; }
89
96 QgsGlobeEntity *globeEntity() SIP_SKIP { return mGlobe; }
97
99 void viewZoomFull();
100
106 void setViewFrom2DExtent( const QgsRectangle &extent );
107
113 QVector<QgsPointXY> viewFrustum2DExtent() const;
114
119 int totalPendingJobsCount() const;
120
123 {
126 };
127
129 SceneState sceneState() const { return mSceneState; }
130
135 float worldSpaceError( float epsilon, float distance ) const;
136
141 bool exportScene( const Qgs3DMapExportSettings &exportSettings );
142
148 QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
149
155 QList<QgsMapLayer *> layers() const SIP_SKIP { return mLayerEntities.keys(); }
156
162 Qt3DCore::QEntity *layerEntity( QgsMapLayer *layer ) const SIP_SKIP { return mLayerEntities.value( layer ); }
163
169 QgsRectangle sceneExtent() const;
170
177 QgsDoubleRange elevationRange( bool ignoreTerrain = false ) const;
178
184 Qgs3DAxis *get3DAxis() const SIP_SKIP { return m3DAxis; }
185
191 QgsAbstract3DEngine *engine() const SIP_SKIP { return mEngine; }
192
198 Qgs3DMapSettings *mapSettings() const { return &mMap; }
199
207 bool hasSceneUpdatesEnabled() const { return mSceneUpdatesEnabled; }
208
216 void setSceneUpdatesEnabled( bool enabled ) { mSceneUpdatesEnabled = enabled; }
217
232 bool hasSceneOriginShiftEnabled() const { return mSceneOriginShiftEnabled; }
233
243 void setSceneOriginShiftEnabled( bool enabled ) { mSceneOriginShiftEnabled = enabled; }
244
252 Q_DECL_DEPRECATED static QMap<QString, Qgs3DMapScene *> openScenes() SIP_DEPRECATED;
253
274 void enableClipping( const QList<QVector4D> &clipPlaneEquations );
275
282 void disableClipping();
283
290 void addSceneEntity( Qgs3DMapSceneEntity *entity ) SIP_SKIP;
291
297 void removeSceneEntity( Qgs3DMapSceneEntity *entity ) SIP_SKIP;
298
305 QList<QVector4D> clipPlaneEquations() const { return mClipPlanesEquations; };
306
307#ifndef SIP_RUN
309 static std::function<QMap<QString, Qgs3DMapScene *>()> sOpenScenesFunction;
310#endif
311
312 signals:
315
323
325 void fpsCountChanged( float fpsCount );
327 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
328
334 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
335
342
343 public slots:
345 void updateTemporal();
346
347 private slots:
348 void onCameraChanged();
349 void onFrameTriggered( float dt );
350 void createTerrain();
351 void onLayerRenderer3DChanged();
352 void onLayersChanged();
353 void createTerrainDeferred();
354 void onBackgroundColorChanged();
355 void updateLights();
356 void updateCameraLens();
357 void onSkyboxSettingsChanged();
358 void onShadowSettingsChanged();
359 void onAmbientOcclusionSettingsChanged();
360 void onEyeDomeShadingSettingsChanged();
361 void onDebugShadowMapSettingsChanged();
362 void onDebugDepthMapSettingsChanged();
363 void onCameraMovementSpeedChanged();
364 void onCameraNavigationModeChanged();
365 void onDebugOverlayEnabledChanged();
366 void onStopUpdatesChanged();
367 void on3DAxisSettingsChanged();
368
369 void onOriginChanged();
370
371 bool updateCameraNearFarPlanes();
372
373 private:
374#ifdef SIP_RUN
376 Qgs3DMapScene( const Qgs3DMapScene &other );
377#endif
378
379 void addLayerEntity( QgsMapLayer *layer );
380 void removeLayerEntity( QgsMapLayer *layer );
381 void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
382 void addCameraRotationCenterEntity( QgsCameraController *controller );
383 void setSceneState( SceneState state );
384 void updateSceneState();
385 void updateScene( bool forceUpdate = false );
386 void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
387 int maximumTextureSize() const;
388
389 void handleClippingOnEntity( QEntity *entity ) const;
390 void handleClippingOnAllEntities() const;
391
392 private:
393 Qgs3DMapSettings &mMap;
394 QgsAbstract3DEngine *mEngine = nullptr;
396 Qt3DLogic::QFrameAction *mFrameAction = nullptr;
397 QgsCameraController *mCameraController = nullptr;
398 QgsTerrainEntity *mTerrain = nullptr;
399 QgsGlobeEntity *mGlobe = nullptr;
400 QList<Qgs3DMapSceneEntity *> mSceneEntities;
402 Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
404 QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
405 bool mTerrainUpdateScheduled = false;
406 SceneState mSceneState = Ready;
408 QList<Qt3DCore::QEntity *> mLightEntities;
409 QList<QgsMapLayer *> mModelVectorLayers;
410 QgsSkyboxEntity *mSkybox = nullptr;
412 Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
413
415 Qgs3DAxis *m3DAxis = nullptr;
416
417 bool mSceneUpdatesEnabled = true;
418 bool mSceneOriginShiftEnabled = true;
419
420 QList<QVector4D> mClipPlanesEquations;
421 int mMaxClipPlanes = 6;
422};
423#endif // QGS3DMAPSCENE_H
Display 3D ortho axis in the main 3D view.
Definition qgs3daxis.h:52
Manages the various settings the user can choose from when exporting a 3D scene.
Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children.
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.
QgsGlobeEntity * globeEntity()
Returns globe entity (may be nullptr if not using globe scene, terrain rendering is disabled or when ...
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 nullptr if using globe scene, terrain rendering is disabled or when te...
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.
Definition of the world.
Base class for 3D engine implementation.
Base class for all renderers that participate in 3D views.
Object that controls camera movement based on user input.
QgsRange which stores a range of double values.
Definition qgsrange.h:233
Base class for all map layer types.
Definition qgsmaplayer.h:77
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