QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 "qgsfeatureid.h"
24 
25 namespace Qt3DRender
26 {
27  class QRenderSettings;
28  class QCamera;
29  class QPickEvent;
30  class QObjectPicker;
31 }
32 
33 namespace Qt3DLogic
34 {
35  class QFrameAction;
36 }
37 
38 namespace Qt3DExtras
39 {
40  class QForwardRenderer;
41 }
42 
45 class QgsMapLayer;
48 class Qgs3DMapSettings;
49 class QgsTerrainEntity;
50 class QgsChunkedEntity;
51 
52 #define SIP_NO_FILE
53 
60 class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
61 {
62  Q_OBJECT
63  public:
65  Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *engine );
66 
68  QgsCameraController *cameraController() { return mCameraController; }
70  QgsTerrainEntity *terrainEntity() { return mTerrain; }
71 
73  void viewZoomFull();
74 
76  int terrainPendingJobsCount() const;
77 
82  int totalPendingJobsCount() const;
83 
86  {
89  };
90 
92  SceneState sceneState() const { return mSceneState; }
93 
95  void registerPickHandler( Qgs3DMapScenePickHandler *pickHandler );
97  void unregisterPickHandler( Qgs3DMapScenePickHandler *pickHandler );
98 
103  float worldSpaceError( float epsilon, float distance );
104 
105  signals:
107  void terrainEntityChanged();
109  void terrainPendingJobsCountChanged();
110 
115  void totalPendingJobsCountChanged();
117  void sceneStateChanged();
118 
119  public slots:
121  void updateTemporal();
122 
123  private slots:
124  void onCameraChanged();
125  void onFrameTriggered( float dt );
126  void createTerrain();
127  void onLayerRenderer3DChanged();
128  void onLayersChanged();
129  void createTerrainDeferred();
130  void onBackgroundColorChanged();
131  void onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
132  void updateLights();
133  void updateCameraLens();
134  void onRenderersChanged();
135  private:
136  void addLayerEntity( QgsMapLayer *layer );
137  void removeLayerEntity( QgsMapLayer *layer );
138  void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
139  void setSceneState( SceneState state );
140  void updateSceneState();
141  void updateScene();
142  bool updateCameraNearFarPlanes();
143  void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
144  int maximumTextureSize() const;
145 
146  private:
147  const Qgs3DMapSettings &mMap;
148  QgsAbstract3DEngine *mEngine = nullptr;
150  Qt3DLogic::QFrameAction *mFrameAction = nullptr;
151  QgsCameraController *mCameraController = nullptr;
152  QgsTerrainEntity *mTerrain = nullptr;
153  QList<QgsChunkedEntity *> mChunkEntities;
155  Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
157  QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
158  QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
159  bool mTerrainUpdateScheduled = false;
160  SceneState mSceneState = Ready;
162  QList<Qgs3DMapScenePickHandler *> mPickHandlers;
164  QList<Qt3DCore::QEntity *> mLightEntities;
165 };
166 
167 #endif // QGS3DMAPSCENE_H
Qgs3DMapScene::terrainEntity
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:70
QgsAbstract3DRenderer
Definition: qgsabstract3drenderer.h:48
qgsfeatureid.h
Qgs3DMapScene::Updating
@ Updating
The scene is still being loaded/updated.
Definition: qgs3dmapscene.h:88
Qgs3DMapScene::sceneState
SceneState sceneState() const
Returns the current state of the scene.
Definition: qgs3dmapscene.h:92
Qt3DLogic
Definition: qgs3dmapscene.h:33
Qgs3DMapScene::cameraController
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:68
Qt3DRender
Definition: qgs3dmapscene.h:25
Qgs3DMapSettings
Definition: qgs3dmapsettings.h:51
QgsAbstract3DEngine
Definition: qgsabstract3dengine.h:56
Qgs3DMapScene
Definition: qgs3dmapscene.h:60
Qgs3DMapScene::SceneState
SceneState
Enumeration of possible states of the 3D scene.
Definition: qgs3dmapscene.h:85
Qgs3DMapScene::Ready
@ Ready
The scene is fully loaded/updated.
Definition: qgs3dmapscene.h:87
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsCameraController
Definition: qgscameracontroller.h:59
Qt3DExtras
Definition: qgs3dmapscene.h:38
Qgs3DMapScenePickHandler
Definition: qgs3dmapscenepickhandler.h:35
QgsFeatureId
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25