QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgs3dsceneexporter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dsceneexporter.h
3  --------------------------------------
4  Date : June 2020
5  Copyright : (C) 2020 by Belgacem Nedjima
6  Email : gb underscore nedjima at esi dot dz
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 QGS3DSCENEEXPORTER_H
17 #define QGS3DSCENEEXPORTER_H
18 
19 #include <Qt3DCore/QEntity>
20 #include <Qt3DRender/QAttribute>
21 #include <Qt3DExtras/QPlaneGeometry>
22 #include <Qt3DRender/QSceneLoader>
23 #include <Qt3DRender/QMesh>
24 #include <QMap>
25 #include <QFile>
26 #include <QVector3D>
27 
28 #include "qgs3dexportobject.h"
29 
31 class QgsTerrainTileEntity;
32 class QgsTerrainEntity;
33 class Qgs3DMapSettings;
36 class QgsChunkNode;
37 class Qgs3DExportObject;
38 class QgsTerrainTextureGenerator;
39 class QgsVectorLayer;
40 class QgsPolygon3DSymbol;
41 class QgsLine3DSymbol;
42 class QgsPoint3DSymbol;
43 class QgsMeshEntity;
44 
45 #define SIP_NO_FILE
46 
56 class _3D_EXPORT Qgs3DSceneExporter : public Qt3DCore::QEntity
57 {
58  public:
63  {
64  for ( Qgs3DExportObject *obj : mObjects )
65  delete obj;
66  }
67 
72  bool parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer );
73 
75  void parseTerrain( QgsTerrainEntity *terrain, const QString &layer );
76 
78  void save( const QString &sceneName, const QString &sceneFolderPath );
79 
81  void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
83  bool smoothEdges() const { return mSmoothEdges; }
84 
86  void setExportNormals( bool exportNormals ) { mExportNormals = exportNormals; }
88  bool exportNormals() const { return mExportNormals; }
89 
91  void setExportTextures( bool exportTextures ) { mExportTextures = exportTextures; }
93  bool exportTextures() const { return mExportTextures; }
94 
96  void setTerrainResolution( int resolution ) { mTerrainResolution = resolution; }
98  int terrainResolution() const { return mTerrainResolution; }
99 
101  void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }
103  int terrainTextureResolution() const { return mTerrainTextureResolution; }
105  void setScale( float scale ) { mScale = scale; }
107  float scale() const { return mScale; }
108 
109  private:
111  QVector<Qgs3DExportObject *> processInstancedPointGeometry( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
113  QVector<Qgs3DExportObject *> processSceneLoaderGeometries( Qt3DRender::QSceneLoader *sceneLoader, const QString &objectNamePrefix );
115  Qgs3DExportObject *processGeometryRenderer( Qt3DRender::QGeometryRenderer *mesh, const QString &objectNamePrefix, float sceneScale = 1.0f, QVector3D sceneTranslation = QVector3D( 0.0f, 0.0f, 0.0f ) );
117  void processEntityMaterial( Qt3DCore::QEntity *entity, Qgs3DExportObject *object );
119  QVector<Qgs3DExportObject *> processLines( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
121  Qgs3DExportObject *processPoints( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
122 
124  QgsTerrainTileEntity *getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
126  QgsTerrainTileEntity *getDemTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
128  QgsTerrainTileEntity *getMeshTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
129 
131  void parseDemTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
133  void parseFlatTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
135  void parseMeshTile( QgsTerrainTileEntity *meshEntity, const QString &layerName );
136 
137  QString getObjectName( const QString &name );
138  private:
139  QMap<QString, int> usedObjectNamesCounter;
140  QVector<Qgs3DExportObject *> mObjects;
141 
142  bool mSmoothEdges = false;
143  int mTerrainResolution = 128;
144  bool mExportNormals = true;
145  bool mExportTextures = false;
146  int mTerrainTextureResolution = 512;
147  float mScale = 1.0f;
148 
149  friend QgsPolygon3DSymbol;
150  friend QgsLine3DSymbol;
151  friend QgsPoint3DSymbol;
152 };
153 
154 #endif // QGS3DSCENEEXPORTER_H
Qgs3DSceneExporter::exportNormals
bool exportNormals() const
Returns whether the normals will be exported.
Definition: qgs3dsceneexporter.h:88
Qgs3DSceneExporter::setScale
void setScale(float scale)
Sets the scale of the exported 3D model.
Definition: qgs3dsceneexporter.h:105
qgs3dexportobject.h
Qgs3DExportObject
The Qgs3DExportObject class Manages the data of each object of the scene (positions,...
Definition: qgs3dexportobject.h:42
Qgs3DSceneExporter::setSmoothEdges
void setSmoothEdges(bool smoothEdges)
Sets whether the triangles will look smooth.
Definition: qgs3dsceneexporter.h:81
Qgs3DSceneExporter::setExportNormals
void setExportNormals(bool exportNormals)
Sets whether the normals will be exported.
Definition: qgs3dsceneexporter.h:86
QgsPolygon3DSymbol
3 3D symbol that draws polygon geometries as planar polygons, optionally extruded (with added walls).
Definition: qgspolygon3dsymbol.h:38
Qgs3DSceneExporter::scale
float scale() const
Returns the scale of the exported 3D model.
Definition: qgs3dsceneexporter.h:107
Qgs3DSceneExporter::exportTextures
bool exportTextures() const
Returns whether the textures will be exported.
Definition: qgs3dsceneexporter.h:93
Qgs3DSceneExporter
The Qgs3DSceneExporter class Entity that handles the exporting of 3D scene.
Definition: qgs3dsceneexporter.h:57
Qgs3DSceneExporter::setTerrainTextureResolution
void setTerrainTextureResolution(int resolution)
Sets the terrain texture resolution.
Definition: qgs3dsceneexporter.h:101
QgsLine3DSymbol
3 3D symbol that draws linestring geometries as planar polygons (created from lines using a buffer wi...
Definition: qgsline3dsymbol.h:36
Qgs3DSceneExporter::terrainTextureResolution
int terrainTextureResolution() const
Returns the terrain resolution.
Definition: qgs3dsceneexporter.h:103
Qgs3DMapSettings
3 Definition of the world
Definition: qgs3dmapsettings.h:54
QgsFlatTerrainGenerator
3 Terrain generator that creates a simple square flat area.
Definition: qgsflatterraingenerator.h:54
Qgs3DSceneExporter::smoothEdges
bool smoothEdges() const
Returns whether the triangles will look smooth.
Definition: qgs3dsceneexporter.h:83
QgsDemTerrainGenerator
3 Implementation of terrain generator that uses a raster layer with DEM to build terrain.
Definition: qgsdemterraingenerator.h:42
Qgs3DSceneExporter::terrainResolution
int terrainResolution() const
Returns the terrain resolution.
Definition: qgs3dsceneexporter.h:98
Qgs3DSceneExporter::~Qgs3DSceneExporter
~Qgs3DSceneExporter()
Destructor.
Definition: qgs3dsceneexporter.h:62
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
Qgs3DSceneExporter::setExportTextures
void setExportTextures(bool exportTextures)
Sets whether the textures will be exported.
Definition: qgs3dsceneexporter.h:91
QgsTessellatedPolygonGeometry
3 Class derived from Qt3DRender::QGeometry that represents polygons tessellated into 3D geometry.
Definition: qgstessellatedpolygongeometry.h:45
QgsPoint3DSymbol
3 3D symbol that draws point geometries as 3D objects using one of the predefined shapes.
Definition: qgspoint3dsymbol.h:39
Qgs3DSceneExporter::setTerrainResolution
void setTerrainResolution(int resolution)
Sets the terrain resolution.
Definition: qgs3dsceneexporter.h:96
Qgs3DSceneExporter::Qgs3DSceneExporter
Qgs3DSceneExporter()
Constructor.
Definition: qgs3dsceneexporter.h:60