QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 namespace Qt3DRender
24 {
25  class QRenderSettings;
26  class QCamera;
27  class QPickEvent;
28 }
29 
30 namespace Qt3DLogic
31 {
32  class QFrameAction;
33 }
34 
35 namespace Qt3DExtras
36 {
37  class QForwardRenderer;
38 }
39 
42 class QgsMapLayer;
45 class Qgs3DMapSettings;
46 class QgsTerrainEntity;
47 class QgsChunkedEntity;
48 
54 class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
55 {
56  Q_OBJECT
57  public:
59  Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *engine );
60 
62  QgsCameraController *cameraController() { return mCameraController; }
64  QgsTerrainEntity *terrainEntity() { return mTerrain; }
65 
67  void viewZoomFull();
68 
70  int terrainPendingJobsCount() const;
71 
74  {
77  };
78 
80  SceneState sceneState() const { return mSceneState; }
81 
83  void registerPickHandler( Qgs3DMapScenePickHandler *pickHandler );
85  void unregisterPickHandler( Qgs3DMapScenePickHandler *pickHandler );
86 
91  float worldSpaceError( float epsilon, float distance );
92 
93  signals:
95  void terrainEntityChanged();
97  void terrainPendingJobsCountChanged();
99  void sceneStateChanged();
100 
101  private slots:
102  void onCameraChanged();
103  void onFrameTriggered( float dt );
104  void createTerrain();
105  void onLayerRenderer3DChanged();
106  void onLayersChanged();
107  void createTerrainDeferred();
108  void onBackgroundColorChanged();
109  void onLayerEntityPickEvent( Qt3DRender::QPickEvent *event );
110  void updateLights();
111  void updateCameraLens();
112  void onRenderersChanged();
113  private:
114  void addLayerEntity( QgsMapLayer *layer );
115  void removeLayerEntity( QgsMapLayer *layer );
116  void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
117  void setSceneState( SceneState state );
118  void updateSceneState();
119  void updateScene();
120  bool updateCameraNearFarPlanes();
121  void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
122 
123  private:
124  const Qgs3DMapSettings &mMap;
125  QgsAbstract3DEngine *mEngine = nullptr;
127  Qt3DLogic::QFrameAction *mFrameAction = nullptr;
128  QgsCameraController *mCameraController = nullptr;
129  QgsTerrainEntity *mTerrain = nullptr;
130  QList<QgsChunkedEntity *> mChunkEntities;
132  Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
134  QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
135  QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
136  bool mTerrainUpdateScheduled = false;
137  SceneState mSceneState = Ready;
139  QList<Qgs3DMapScenePickHandler *> mPickHandlers;
141  QList<Qt3DCore::QEntity *> mLightEntities;
142 };
143 
144 #endif // QGS3DMAPSCENE_H
3 Abstract base class for handlers that process pick events from a 3D map scene.
Base class for all map layer types.
Definition: qgsmaplayer.h:79
Base class for all renderers that may to participate in 3D view.
SceneState
Enumeration of possible states of the 3D scene.
Definition: qgs3dmapscene.h:73
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:64
3 Definition of the world
SceneState sceneState() const
Returns the current state of the scene.
Definition: qgs3dmapscene.h:80
3 Base class for 3D engine implementation.
3 Object that controls camera movement based on user input
The scene is fully loaded/updated.
Definition: qgs3dmapscene.h:75
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children...
Definition: qgs3dmapscene.h:54
The scene is still being loaded/updated.
Definition: qgs3dmapscene.h:76
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:62