QGIS API Documentation 4.1.0-Master (376402f9aeb)
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 "qgsmapoverlayentity.h"
21#include "qgsrectangle.h"
22#include "qobjectuniqueptr.h"
23
24#include <QVector4D>
25#include <Qt3DCore/QEntity>
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;
63
64
69#ifndef SIP_RUN
70class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
71{
72#else
73class _3D_EXPORT Qgs3DMapScene : public QObject
74{
75#endif
76
77 Q_OBJECT
78 public:
81
83 QgsCameraController *cameraController() const { return mCameraController; }
84
90 QgsTerrainEntity *terrainEntity() SIP_SKIP { return mTerrain; }
91
98 QgsGlobeEntity *globeEntity() SIP_SKIP { return mGlobe; }
101 void viewZoomFull();
102
108 void setViewFrom2DExtent( const QgsRectangle &extent );
109
115 QVector<QgsPointXY> viewFrustum2DExtent() const;
116
121 int totalPendingJobsCount() const;
122
125 {
128 };
129
131 SceneState sceneState() const { return mSceneState; }
132
137 double worldSpaceError( double epsilon, double distance ) const;
138
143 bool exportScene( const Qgs3DMapExportSettings &exportSettings );
144
150 QVector<const QgsChunkNode *> getLayerActiveChunkNodes( QgsMapLayer *layer ) SIP_SKIP;
151
157 QList<QgsMapLayer *> layers() const SIP_SKIP { return mLayerEntities.keys(); }
158
164 Qt3DCore::QEntity *layerEntity( QgsMapLayer *layer ) const SIP_SKIP { return mLayerEntities.value( layer ); }
165
171 QgsRectangle sceneExtent() const;
172
179 QgsDoubleRange elevationRange( bool ignoreTerrain = false ) const;
180
186 Qgs3DAxis *get3DAxis() const SIP_SKIP { return m3DAxis; }
187
193 QgsAbstract3DEngine *engine() const SIP_SKIP { return mEngine; }
194
200 Qgs3DMapSettings *mapSettings() const { return &mMap; }
201
209 bool hasSceneUpdatesEnabled() const { return mSceneUpdatesEnabled; }
210
218 void setSceneUpdatesEnabled( bool enabled ) { mSceneUpdatesEnabled = enabled; }
219
234 bool hasSceneOriginShiftEnabled() const { return mSceneOriginShiftEnabled; }
235
245 void setSceneOriginShiftEnabled( bool enabled ) { mSceneOriginShiftEnabled = enabled; }
246
254 Q_DECL_DEPRECATED static QMap<QString, Qgs3DMapScene *> openScenes() SIP_DEPRECATED;
255
276 void enableClipping( const QList<QVector4D> &clipPlaneEquations );
277
284 void disableClipping();
285
292 void addSceneEntity( Qgs3DMapSceneEntity *entity ) SIP_SKIP;
293
299 void removeSceneEntity( Qgs3DMapSceneEntity *entity ) SIP_SKIP;
300
307 QList<QVector4D> clipPlaneEquations() const { return mClipPlanesEquations; };
308
309#ifndef SIP_RUN
311 static std::function<QMap<QString, Qgs3DMapScene *>()> sOpenScenesFunction;
312#endif
313
314 signals:
317
325
327 void fpsCountChanged( float fpsCount );
329 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
330
336 void viewed2DExtentFrom3DChanged( QVector<QgsPointXY> extent );
337
344
345 public slots:
347 void updateTemporal();
348
349 private slots:
350 void onCameraChanged();
351 void onFrameTriggered( float dt );
352 void createTerrain();
353 void onLayerRenderer3DChanged();
354 void onLayersChanged();
355 void createTerrainDeferred();
356 void onBackgroundColorChanged();
357 void updateLights();
358 void updateCameraLens();
359 void onSkyboxSettingsChanged();
360 void onGradientBackgroundChanged();
361 void onShadowSettingsChanged();
362 void onAmbientOcclusionSettingsChanged();
363 void onEyeDomeShadingSettingsChanged();
364 void onMsaaEnabledChanged();
365 void onDebugShadowMapSettingsChanged();
366 void onDebugDepthMapSettingsChanged();
367 void onCameraMovementSpeedChanged();
368 void onCameraNavigationModeChanged();
369 void onDebugOverlayEnabledChanged();
370 void onStopUpdatesChanged();
371 void on3DAxisSettingsChanged();
372 void onShowMapOverlayChanged();
373
374 void onOriginChanged();
375
376 bool updateCameraNearFarPlanes();
377
378 void applyPendingOverlayUpdate();
379
380 private:
381#ifdef SIP_RUN
383 Qgs3DMapScene( const Qgs3DMapScene &other );
384#endif
385
386 void addLayerEntity( QgsMapLayer *layer );
387 void removeLayerEntity( QgsMapLayer *layer );
388 void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
389 void addCameraRotationCenterEntity( QgsCameraController *controller );
390 void setSceneState( SceneState state );
391 void updateSceneState();
393 bool updateScene( bool forceUpdate = false );
394 void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
395 int maximumTextureSize() const;
396
397 void handleClippingOnEntity( QEntity *entity ) const;
398 void handleClippingOnAllEntities() const;
399
400 void schedule2DMapOverlayUpdate();
401 void update2DMapOverlay( const QVector<QgsPointXY> &extent2DAsPoints );
402
403 private:
404 Qgs3DMapSettings &mMap;
405 QgsAbstract3DEngine *mEngine = nullptr;
407 Qt3DLogic::QFrameAction *mFrameAction = nullptr;
408 QgsCameraController *mCameraController = nullptr;
409 QgsTerrainEntity *mTerrain = nullptr;
410 QgsGlobeEntity *mGlobe = nullptr;
411 QList<Qgs3DMapSceneEntity *> mSceneEntities;
413 Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
415 QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
416 bool mTerrainUpdateScheduled = false;
417 SceneState mSceneState = Ready;
419 QList<Qt3DCore::QEntity *> mLightEntities;
420 QList<QgsMapLayer *> mModelVectorLayers;
421 QgsSkyboxEntity *mSkybox = nullptr;
422 QgsGradientBackgroundEntity *mGradientBackground = nullptr;
424 Qt3DCore::QEntity *mEntityRotationCenter = nullptr;
425
427 Qgs3DAxis *m3DAxis = nullptr;
428
429 bool mSceneUpdatesEnabled = true;
430 bool mSceneOriginShiftEnabled = true;
431
432 QList<QVector4D> mClipPlanesEquations;
433 int mMaxClipPlanes = 6;
434
436 QObjectUniquePtr<QgsMapOverlayEntity> mMapOverlayEntity = nullptr;
437 QTimer *mOverlayUpdateTimer = nullptr;
438
439 friend class TestQgs3DRendering;
440};
441#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:68
Manages the various settings the user can choose from when exporting a 3D scene.
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.
friend class TestQgs3DRendering
void setViewFrom2DExtent(const QgsRectangle &extent)
Resets camera view to show the extent extent (top view).
QgsTerrainEntity * terrainEntity() SIP_SKIP
Returns terrain entity (may be nullptr if using globe scene, terrain rendering is disabled or when te...
Qgs3DMapSettings * mapSettings() const
Returns the 3D map settings.
Qgs3DAxis * get3DAxis() const SIP_SKIP
Returns the 3D axis object.
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.
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.
QList< QgsMapLayer * > layers() const SIP_SKIP
Returns the layers that contain chunked entities.
void updateTemporal()
Updates the temporale entities.
void totalPendingJobsCountChanged()
Emitted when the total number of pending jobs changes.
Qgs3DMapScene(Qgs3DMapSettings &map, QgsAbstract3DEngine *engine) SIP_SKIP
Constructs a 3D scene based on map settings and Qt 3D renderer configuration.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is activated or deactivated.
void sceneStateChanged()
Emitted when the scene's state has changed.
QgsAbstract3DEngine * engine() const SIP_SKIP
Returns the abstract 3D engine.
SceneState sceneState() const
Returns the current state of the scene.
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.
Qt3DCore::QEntity * layerEntity(QgsMapLayer *layer) const SIP_SKIP
Returns the entity belonging to layer.
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).
QgsGlobeEntity * globeEntity() SIP_SKIP
Returns globe entity (may be nullptr if not using globe scene, terrain rendering is disabled or when ...
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:217
A background entity that renders a two-color gradient behind all 3D scene geometry.
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:113
#define SIP_SKIP
Definition qgis_sip.h:133