QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
55 class _3D_EXPORT Qgs3DSceneExporter : public Qt3DCore::QEntity
56 {
57  Q_OBJECT
58 
59  public:
64  {
65  for ( Qgs3DExportObject *obj : mObjects )
66  delete obj;
67  }
68 
73  bool parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer );
74 
76  void parseTerrain( QgsTerrainEntity *terrain, const QString &layer );
77 
79  void save( const QString &sceneName, const QString &sceneFolderPath );
80 
82  void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
84  bool smoothEdges() const { return mSmoothEdges; }
85 
87  void setExportNormals( bool exportNormals ) { mExportNormals = exportNormals; }
89  bool exportNormals() const { return mExportNormals; }
90 
92  void setExportTextures( bool exportTextures ) { mExportTextures = exportTextures; }
94  bool exportTextures() const { return mExportTextures; }
95 
97  void setTerrainResolution( int resolution ) { mTerrainResolution = resolution; }
99  int terrainResolution() const { return mTerrainResolution; }
100 
102  void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }
104  int terrainTextureResolution() const { return mTerrainTextureResolution; }
106  void setScale( float scale ) { mScale = scale; }
108  float scale() const { return mScale; }
109 
110  private:
112  QVector<Qgs3DExportObject *> processInstancedPointGeometry( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
114  QVector<Qgs3DExportObject *> processSceneLoaderGeometries( Qt3DRender::QSceneLoader *sceneLoader, const QString &objectNamePrefix );
116  Qgs3DExportObject *processGeometryRenderer( Qt3DRender::QGeometryRenderer *mesh, const QString &objectNamePrefix, float sceneScale = 1.0f, QVector3D sceneTranslation = QVector3D( 0.0f, 0.0f, 0.0f ) );
118  void processEntityMaterial( Qt3DCore::QEntity *entity, Qgs3DExportObject *object );
120  QVector<Qgs3DExportObject *> processLines( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
122  Qgs3DExportObject *processPoints( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
123 
125  QgsTerrainTileEntity *getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
127  QgsTerrainTileEntity *getDemTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
129  QgsTerrainTileEntity *getMeshTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
130 
132  void parseDemTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
134  void parseFlatTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
136  void parseMeshTile( QgsTerrainTileEntity *meshEntity, const QString &layerName );
137 
138  QString getObjectName( const QString &name );
139  private:
140  QMap<QString, int> usedObjectNamesCounter;
141  QVector<Qgs3DExportObject *> mObjects;
142 
143  bool mSmoothEdges = false;
144  int mTerrainResolution = 128;
145  bool mExportNormals = true;
146  bool mExportTextures = false;
147  int mTerrainTextureResolution = 512;
148  float mScale = 1.0f;
149 
150  friend QgsPolygon3DSymbol;
151  friend QgsLine3DSymbol;
152  friend QgsPoint3DSymbol;
153 };
154 
155 #endif // QGS3DSCENEEXPORTER_H
Qgs3DSceneExporter::exportNormals
bool exportNormals() const
Returns whether the normals will be exported.
Definition: qgs3dsceneexporter.h:89
Qgs3DSceneExporter::setScale
void setScale(float scale)
Sets the scale of the exported 3D model.
Definition: qgs3dsceneexporter.h:106
qgs3dexportobject.h
Qgs3DExportObject
Manages the data of each object of the scene (positions, normals, texture coordinates ....
Definition: qgs3dexportobject.h:40
Qgs3DSceneExporter::setSmoothEdges
void setSmoothEdges(bool smoothEdges)
Sets whether the triangles will look smooth.
Definition: qgs3dsceneexporter.h:82
Qgs3DSceneExporter::setExportNormals
void setExportNormals(bool exportNormals)
Sets whether the normals will be exported.
Definition: qgs3dsceneexporter.h:87
QgsPolygon3DSymbol
3D symbol that draws polygon geometries as planar polygons, optionally extruded (with added walls).
Definition: qgspolygon3dsymbol.h:37
Qgs3DSceneExporter::scale
float scale() const
Returns the scale of the exported 3D model.
Definition: qgs3dsceneexporter.h:108
Qgs3DSceneExporter::exportTextures
bool exportTextures() const
Returns whether the textures will be exported.
Definition: qgs3dsceneexporter.h:94
Qgs3DSceneExporter
Entity that handles the exporting of 3D scene.
Definition: qgs3dsceneexporter.h:55
Qgs3DSceneExporter::setTerrainTextureResolution
void setTerrainTextureResolution(int resolution)
Sets the terrain texture resolution.
Definition: qgs3dsceneexporter.h:102
QgsLine3DSymbol
3D symbol that draws linestring geometries as planar polygons (created from lines using a buffer with...
Definition: qgsline3dsymbol.h:35
Qgs3DSceneExporter::terrainTextureResolution
int terrainTextureResolution() const
Returns the terrain resolution.
Definition: qgs3dsceneexporter.h:104
Qgs3DMapSettings
Definition of the world.
Definition: qgs3dmapsettings.h:57
QgsFlatTerrainGenerator
Terrain generator that creates a simple square flat area.
Definition: qgsflatterraingenerator.h:53
Qgs3DSceneExporter::smoothEdges
bool smoothEdges() const
Returns whether the triangles will look smooth.
Definition: qgs3dsceneexporter.h:84
QgsDemTerrainGenerator
Implementation of terrain generator that uses a raster layer with DEM to build terrain.
Definition: qgsdemterraingenerator.h:41
Qgs3DSceneExporter::terrainResolution
int terrainResolution() const
Returns the terrain resolution.
Definition: qgs3dsceneexporter.h:99
Qgs3DSceneExporter::~Qgs3DSceneExporter
~Qgs3DSceneExporter()
Destructor.
Definition: qgs3dsceneexporter.h:63
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
Qgs3DSceneExporter::setExportTextures
void setExportTextures(bool exportTextures)
Sets whether the textures will be exported.
Definition: qgs3dsceneexporter.h:92
QgsTessellatedPolygonGeometry
Class derived from Qt3DRender::QGeometry that represents polygons tessellated into 3D geometry.
Definition: qgstessellatedpolygongeometry.h:44
QgsPoint3DSymbol
3D symbol that draws point geometries as 3D objects using one of the predefined shapes.
Definition: qgspoint3dsymbol.h:38
Qgs3DSceneExporter::setTerrainResolution
void setTerrainResolution(int resolution)
Sets the terrain resolution.
Definition: qgs3dsceneexporter.h:97
Qgs3DSceneExporter::Qgs3DSceneExporter
Qgs3DSceneExporter()
Constructor.
Definition: qgs3dsceneexporter.h:61