QGIS API Documentation 3.99.0-Master (1d785854362)
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 "qgsmapoverlayentity.h"
22#include "qgsrectangle.h"
23#include "qobjectuniqueptr.h"
24
25#include <QVector4D>
26#include <Qt3DCore/QEntity>
27
28#ifndef SIP_RUN
29namespace Qt3DRender
30{
31 class QRenderSettings;
32 class QCamera;
33} // namespace Qt3DRender
34
35namespace Qt3DLogic
36{
37 class QFrameAction;
38}
39
40namespace Qt3DExtras
41{
42 class QForwardRenderer;
43 class QSkyboxEntity;
44} // namespace Qt3DExtras
45#endif
46
47
48class Qgs3DAxis;
51class QgsMapLayer;
53class QgsTerrainEntity;
54class QgsGlobeEntity;
55class QgsChunkedEntity;
56class 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; }
90
97 QgsGlobeEntity *globeEntity() SIP_SKIP { return mGlobe; }
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 double worldSpaceError( double epsilon, double 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 void onShowMapOverlayChanged();
370
371 void onOriginChanged();
372
373 bool updateCameraNearFarPlanes();
374
375 void applyPendingOverlayUpdate();
376
377 private:
378#ifdef SIP_RUN
380 Qgs3DMapScene( const Qgs3DMapScene &other );
381#endif
382
383 void addLayerEntity( QgsMapLayer *layer );
384 void removeLayerEntity( QgsMapLayer *layer );
385 void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
386 void addCameraRotationCenterEntity( QgsCameraController *controller );
387 void setSceneState( SceneState state );
388 void updateSceneState();
390 bool updateScene( bool forceUpdate = false );
391 void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
392 int maximumTextureSize() const;
393
394 void handleClippingOnEntity( QEntity *entity ) const;
395 void handleClippingOnAllEntities() const;
396
397 void schedule2DMapOverlayUpdate();
398 void update2DMapOverlay( const QVector<QgsPointXY> &extent2DAsPoints );
399
400 private:
401 Qgs3DMapSettings &mMap;
402 QgsAbstract3DEngine *mEngine = nullptr;
404 Qt3DLogic::QFrameAction *mFrameAction = nullptr;
405 QgsCameraController *mCameraController = nullptr;
406 QgsTerrainEntity *mTerrain = nullptr;
407 QgsGlobeEntity *mGlobe = nullptr;
408 QList<Qgs3DMapSceneEntity *> mSceneEntities;
410 Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
412 QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
413 bool mTerrainUpdateScheduled = false;
414 SceneState mSceneState = Ready;
416 QList<Qt3DCore::QEntity *> mLightEntities;
417 QList<QgsMapLayer *> mModelVectorLayers;
418 QgsSkyboxEntity *mSkybox = nullptr;
420 Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
421
423 Qgs3DAxis *m3DAxis = nullptr;
424
425 bool mSceneUpdatesEnabled = true;
426 bool mSceneOriginShiftEnabled = true;
427
428 QList<QVector4D> mClipPlanesEquations;
429 int mMaxClipPlanes = 6;
430
432 QObjectUniquePtr<QgsMapOverlayEntity> mMapOverlayEntity = nullptr;
433 QTimer *mOverlayUpdateTimer = nullptr;
434
435 friend class TestQgs3DRendering;
436};
437#endif // QGS3DMAPSCENE_H
Keeps a pointer to a QObject and deletes it whenever this object is deleted.
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
void setViewFrom2DExtent(const QgsRectangle &extent)
Resets camera view to show the extent extent (top view).
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.
int totalPendingJobsCount() const
Returns number of pending jobs for all chunked entities.
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.
QVector< QgsPointXY > viewFrustum2DExtent() const
Calculates the 2D extent viewed by the 3D camera as the vertices of the viewed trapezoid.
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.
void viewZoomFull()
Resets camera view to show the whole scene (top view).
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:236
Base class for all map layer types.
Definition qgsmaplayer.h:83
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