QGIS API Documentation 3.43.0-Master (c67cf405802)
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;
59class QgsChunkNode;
60class QgsDoubleRange;
61class Qgs3DMapSceneEntity;
62
63
68#ifndef SIP_RUN
69class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
70{
71#else
72class _3D_EXPORT Qgs3DMapScene : public QObject
73{
74#endif
75
76 Q_OBJECT
77 public:
80
82 QgsCameraController *cameraController() const { return mCameraController; }
83
89 QgsTerrainEntity *terrainEntity() SIP_SKIP { return mTerrain; }
97 QgsGlobeEntity *globeEntity() SIP_SKIP { return mGlobe; }
98
100 void viewZoomFull();
101
107 void setViewFrom2DExtent( const QgsRectangle &extent );
108
114 QVector<QgsPointXY> viewFrustum2DExtent() const;
115
120 int totalPendingJobsCount() const;
121
124 {
127 };
128
130 SceneState sceneState() const { return mSceneState; }
131
136 float worldSpaceError( float epsilon, float distance ) const;
137
142 bool exportScene( const Qgs3DMapExportSettings &exportSettings );
143
149 QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
150
156 QList<QgsMapLayer *> layers() const SIP_SKIP { return mLayerEntities.keys(); }
157
163 Qt3DCore::QEntity *layerEntity( QgsMapLayer *layer ) const SIP_SKIP { return mLayerEntities.value( layer ); }
164
170 QgsRectangle sceneExtent() const;
171
178 QgsDoubleRange elevationRange( bool ignoreTerrain = false ) const;
179
185 Qgs3DAxis *get3DAxis() const SIP_SKIP { return m3DAxis; }
186
192 QgsAbstract3DEngine *engine() const SIP_SKIP { return mEngine; }
193
199 Qgs3DMapSettings *mapSettings() const { return &mMap; }
200
208 bool hasSceneUpdatesEnabled() const { return mSceneUpdatesEnabled; }
209
217 void setSceneUpdatesEnabled( bool enabled ) { mSceneUpdatesEnabled = enabled; }
218
233 bool hasSceneOriginShiftEnabled() const { return mSceneOriginShiftEnabled; }
234
244 void setSceneOriginShiftEnabled( bool enabled ) { mSceneOriginShiftEnabled = enabled; }
245
253 Q_DECL_DEPRECATED static QMap<QString, Qgs3DMapScene *> openScenes() SIP_DEPRECATED;
254
275 void enableClipping( const QList<QVector4D> &clipPlaneEquations );
276
283 void disableClipping();
284
291 void addSceneEntity( Qgs3DMapSceneEntity *entity ) SIP_SKIP;
292
298 void removeSceneEntity( Qgs3DMapSceneEntity *entity ) SIP_SKIP;
299
306 QList<QVector4D> clipPlaneEquations() const { return mClipPlanesEquations; };
307
308#ifndef SIP_RUN
310 static std::function<QMap<QString, Qgs3DMapScene *>()> sOpenScenesFunction;
311#endif
312
313 signals:
316
324
326 void fpsCountChanged( float fpsCount );
328 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
329
335 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
336
343
344 public slots:
346 void updateTemporal();
347
348 private slots:
349 void onCameraChanged();
350 void onFrameTriggered( float dt );
351 void createTerrain();
352 void onLayerRenderer3DChanged();
353 void onLayersChanged();
354 void createTerrainDeferred();
355 void onBackgroundColorChanged();
356 void updateLights();
357 void updateCameraLens();
358 void onSkyboxSettingsChanged();
359 void onShadowSettingsChanged();
360 void onAmbientOcclusionSettingsChanged();
361 void onEyeDomeShadingSettingsChanged();
362 void onDebugShadowMapSettingsChanged();
363 void onDebugDepthMapSettingsChanged();
364 void onCameraMovementSpeedChanged();
365 void onCameraNavigationModeChanged();
366 void onDebugOverlayEnabledChanged();
367 void onStopUpdatesChanged();
368 void on3DAxisSettingsChanged();
369
370 void onOriginChanged();
371
372 bool updateCameraNearFarPlanes();
373
374 private:
375#ifdef SIP_RUN
377 Qgs3DMapScene( const Qgs3DMapScene &other );
378#endif
379
380 void addLayerEntity( QgsMapLayer *layer );
381 void removeLayerEntity( QgsMapLayer *layer );
382 void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
383 void addCameraRotationCenterEntity( QgsCameraController *controller );
384 void setSceneState( SceneState state );
385 void updateSceneState();
386 void updateScene( bool forceUpdate = false );
387 void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
388 int maximumTextureSize() const;
389
390 void handleClippingOnEntity( QEntity *entity ) const;
391 void handleClippingOnAllEntities() const;
392
393 private:
394 Qgs3DMapSettings &mMap;
395 QgsAbstract3DEngine *mEngine = nullptr;
397 Qt3DLogic::QFrameAction *mFrameAction = nullptr;
398 QgsCameraController *mCameraController = nullptr;
399 QgsTerrainEntity *mTerrain = nullptr;
400 QgsGlobeEntity *mGlobe = nullptr;
401 QList<Qgs3DMapSceneEntity *> mSceneEntities;
403 Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
405 QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
406 bool mTerrainUpdateScheduled = false;
407 SceneState mSceneState = Ready;
409 QList<Qt3DCore::QEntity *> mLightEntities;
410 QList<QgsMapLayer *> mModelVectorLayers;
411 QgsSkyboxEntity *mSkybox = nullptr;
413 Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
414
416 Qgs3DAxis *m3DAxis = nullptr;
417
418 bool mSceneUpdatesEnabled = true;
419 bool mSceneOriginShiftEnabled = true;
420
421 QList<QVector4D> mClipPlanesEquations;
422 int mMaxClipPlanes = 6;
423};
424#endif // QGS3DMAPSCENE_H
Display 3D ortho axis in the main 3D view.
Definition qgs3daxis.h:55
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
An entity that is responsible for applying post processing effects.
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