QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
41 class QgsMapLayer;
44 class Qgs3DMapSettings;
45 class QgsTerrainEntity;
46 class QgsChunkedEntity;
47 
53 class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
54 {
55  Q_OBJECT
56  public:
58  Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *engine );
59 
61  QgsCameraController *cameraController() { return mCameraController; }
63  QgsTerrainEntity *terrainEntity() { return mTerrain; }
64 
66  void viewZoomFull();
67 
69  int terrainPendingJobsCount() const;
70 
73  {
76  };
77 
79  SceneState sceneState() const { return mSceneState; }
80 
82  void registerPickHandler( Qgs3DMapScenePickHandler *pickHandler );
84  void unregisterPickHandler( Qgs3DMapScenePickHandler *pickHandler );
85 
90  float worldSpaceError( float epsilon, float distance );
91 
92  signals:
94  void terrainEntityChanged();
96  void terrainPendingJobsCountChanged();
98  void sceneStateChanged();
99 
100  private slots:
101  void onCameraChanged();
102  void onFrameTriggered( float dt );
103  void createTerrain();
104  void onLayerRenderer3DChanged();
105  void onLayersChanged();
106  void createTerrainDeferred();
107  void onBackgroundColorChanged();
108  void onLayerEntityPickEvent( Qt3DRender::QPickEvent *event );
109  void updateLights();
110  void updateCameraLens();
111  private:
112  void addLayerEntity( QgsMapLayer *layer );
113  void removeLayerEntity( QgsMapLayer *layer );
114  void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
115  void setSceneState( SceneState state );
116  void updateSceneState();
117  void updateScene();
118  bool updateCameraNearFarPlanes();
119 
120  private:
121  const Qgs3DMapSettings &mMap;
122  QgsAbstract3DEngine *mEngine = nullptr;
124  Qt3DLogic::QFrameAction *mFrameAction = nullptr;
125  QgsCameraController *mCameraController = nullptr;
126  QgsTerrainEntity *mTerrain = nullptr;
127  QList<QgsChunkedEntity *> mChunkEntities;
129  Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
131  QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
132  bool mTerrainUpdateScheduled = false;
133  SceneState mSceneState = Ready;
135  QList<Qgs3DMapScenePickHandler *> mPickHandlers;
137  QList<Qt3DCore::QEntity *> mLightEntities;
138 };
139 
140 #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:78
SceneState
Enumeration of possible states of the 3D scene.
Definition: qgs3dmapscene.h:72
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:63
3 Definition of the world
SceneState sceneState() const
Returns the current state of the scene.
Definition: qgs3dmapscene.h:79
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:74
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children...
Definition: qgs3dmapscene.h:53
The scene is still being loaded/updated.
Definition: qgs3dmapscene.h:75
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:61