QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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#include "qgscameracontroller.h"
21#include "qgsrectangle.h"
22
23#include <QVector4D>
24#include <Qt3DCore/QEntity>
25
26#ifndef SIP_RUN
27namespace Qt3DRender
28{
29 class QRenderSettings;
30 class QCamera;
31} // namespace Qt3DRender
32
33namespace Qt3DLogic
34{
35 class QFrameAction;
36}
37
38namespace Qt3DExtras
39{
40 class QForwardRenderer;
41 class QSkyboxEntity;
42} // namespace Qt3DExtras
43#endif
44
45
46class Qgs3DAxis;
49class QgsMapLayer;
51class QgsTerrainEntity;
52class QgsGlobeEntity;
53class QgsChunkedEntity;
54class 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
87 QgsTerrainEntity *terrainEntity() SIP_SKIP { return mTerrain; }
88
95 QgsGlobeEntity *globeEntity() SIP_SKIP { return mGlobe; }
96
98 void viewZoomFull();
99
105 void setViewFrom2DExtent( const QgsRectangle &extent );
106
112 QVector<QgsPointXY> viewFrustum2DExtent() const;
113
118 int totalPendingJobsCount() const;
119
122 {
125 };
126
128 SceneState sceneState() const { return mSceneState; }
129
134 double worldSpaceError( double epsilon, double distance ) const;
135
140 bool exportScene( const Qgs3DMapExportSettings &exportSettings );
141
147 QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
148
154 QList<QgsMapLayer *> layers() const SIP_SKIP { return mLayerEntities.keys(); }
155
161 Qt3DCore::QEntity *layerEntity( QgsMapLayer *layer ) const SIP_SKIP { return mLayerEntities.value( layer ); }
162
168 QgsRectangle sceneExtent() const;
169
176 QgsDoubleRange elevationRange( bool ignoreTerrain = false ) const;
177
183 Qgs3DAxis *get3DAxis() const SIP_SKIP { return m3DAxis; }
184
190 QgsAbstract3DEngine *engine() const SIP_SKIP { return mEngine; }
191
197 Qgs3DMapSettings *mapSettings() const { return &mMap; }
198
206 bool hasSceneUpdatesEnabled() const { return mSceneUpdatesEnabled; }
207
215 void setSceneUpdatesEnabled( bool enabled ) { mSceneUpdatesEnabled = enabled; }
216
231 bool hasSceneOriginShiftEnabled() const { return mSceneOriginShiftEnabled; }
232
242 void setSceneOriginShiftEnabled( bool enabled ) { mSceneOriginShiftEnabled = enabled; }
243
251 Q_DECL_DEPRECATED static QMap<QString, Qgs3DMapScene *> openScenes() SIP_DEPRECATED;
252
273 void enableClipping( const QList<QVector4D> &clipPlaneEquations );
274
281 void disableClipping();
282
289 void addSceneEntity( Qgs3DMapSceneEntity *entity ) SIP_SKIP;
290
296 void removeSceneEntity( Qgs3DMapSceneEntity *entity ) SIP_SKIP;
297
304 QList<QVector4D> clipPlaneEquations() const { return mClipPlanesEquations; };
305
306#ifndef SIP_RUN
308 static std::function<QMap<QString, Qgs3DMapScene *>()> sOpenScenesFunction;
309#endif
310
311 signals:
314
322
324 void fpsCountChanged( float fpsCount );
326 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
327
333 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
334
341
342 public slots:
344 void updateTemporal();
345
346 private slots:
347 void onCameraChanged();
348 void onFrameTriggered( float dt );
349 void createTerrain();
350 void onLayerRenderer3DChanged();
351 void onLayersChanged();
352 void createTerrainDeferred();
353 void onBackgroundColorChanged();
354 void updateLights();
355 void updateCameraLens();
356 void onSkyboxSettingsChanged();
357 void onShadowSettingsChanged();
358 void onAmbientOcclusionSettingsChanged();
359 void onEyeDomeShadingSettingsChanged();
360 void onDebugShadowMapSettingsChanged();
361 void onDebugDepthMapSettingsChanged();
362 void onCameraMovementSpeedChanged();
363 void onCameraNavigationModeChanged();
364 void onDebugOverlayEnabledChanged();
365 void onStopUpdatesChanged();
366 void on3DAxisSettingsChanged();
367
368 void onOriginChanged();
369
370 bool updateCameraNearFarPlanes();
371
372 private:
373#ifdef SIP_RUN
375 Qgs3DMapScene( const Qgs3DMapScene &other );
376#endif
377
378 void addLayerEntity( QgsMapLayer *layer );
379 void removeLayerEntity( QgsMapLayer *layer );
380 void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
381 void addCameraRotationCenterEntity( QgsCameraController *controller );
382 void setSceneState( SceneState state );
383 void updateSceneState();
385 bool 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 friend class TestQgs3DRendering;
424};
425#endif // QGS3DMAPSCENE_H
Display 3D ortho axis in the main 3D view.
Definition qgs3daxis.h:51
Manages the various settings the user can choose from when exporting a 3D scene.
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.
QList< QVector4D > clipPlaneEquations() const
Returns list of clipping planes if clipping is enabled, otherwise an empty list.
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 ...
friend class TestQgs3DRendering
Qgs3DMapScene(Qgs3DMapSettings &map, QgsAbstract3DEngine *engine)
Constructs a 3D scene based on map settings and Qt 3D renderer configuration.
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 updateTemporal()
Updates the temporale entities.
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:80
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:114
#define SIP_SKIP
Definition qgis_sip.h:134