QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
58 class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
59 {
60  Q_OBJECT
61  public:
63  Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *engine );
64 
66  QgsCameraController *cameraController() { return mCameraController; }
68  QgsTerrainEntity *terrainEntity() { return mTerrain; }
69 
71  void viewZoomFull();
72 
74  int terrainPendingJobsCount() const;
75 
80  int totalPendingJobsCount() const;
81 
84  {
87  };
88 
90  SceneState sceneState() const { return mSceneState; }
91 
93  void registerPickHandler( Qgs3DMapScenePickHandler *pickHandler );
95  void unregisterPickHandler( Qgs3DMapScenePickHandler *pickHandler );
96 
101  float worldSpaceError( float epsilon, float distance );
102 
103  signals:
105  void terrainEntityChanged();
107  void terrainPendingJobsCountChanged();
108 
113  void totalPendingJobsCountChanged();
115  void sceneStateChanged();
116 
117  private slots:
118  void onCameraChanged();
119  void onFrameTriggered( float dt );
120  void createTerrain();
121  void onLayerRenderer3DChanged();
122  void onLayersChanged();
123  void createTerrainDeferred();
124  void onBackgroundColorChanged();
125  void onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid );
126  void updateLights();
127  void updateCameraLens();
128  void onRenderersChanged();
129  private:
130  void addLayerEntity( QgsMapLayer *layer );
131  void removeLayerEntity( QgsMapLayer *layer );
132  void addCameraViewCenterEntity( Qt3DRender::QCamera *camera );
133  void setSceneState( SceneState state );
134  void updateSceneState();
135  void updateScene();
136  bool updateCameraNearFarPlanes();
137  void finalizeNewEntity( Qt3DCore::QEntity *newEntity );
138 
139  private:
140  const Qgs3DMapSettings &mMap;
141  QgsAbstract3DEngine *mEngine = nullptr;
143  Qt3DLogic::QFrameAction *mFrameAction = nullptr;
144  QgsCameraController *mCameraController = nullptr;
145  QgsTerrainEntity *mTerrain = nullptr;
146  QList<QgsChunkedEntity *> mChunkEntities;
148  Qt3DCore::QEntity *mEntityCameraViewCenter = nullptr;
150  QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
151  QMap<const QgsAbstract3DRenderer *, Qt3DCore::QEntity *> mRenderersEntities;
152  bool mTerrainUpdateScheduled = false;
153  SceneState mSceneState = Ready;
155  QList<Qgs3DMapScenePickHandler *> mPickHandlers;
157  QList<Qt3DCore::QEntity *> mLightEntities;
158 };
159 
160 #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:83
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
QgsTerrainEntity * terrainEntity()
Returns terrain entity (may be temporarily nullptr)
Definition: qgs3dmapscene.h:68
3 Definition of the world
SceneState sceneState() const
Returns the current state of the scene.
Definition: qgs3dmapscene.h:90
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:85
3 Entity that encapsulates our 3D scene - contains all other entities (such as terrain) as children...
Definition: qgs3dmapscene.h:58
The scene is still being loaded/updated.
Definition: qgs3dmapscene.h:86
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:66