QGIS API Documentation  3.20.0-Odense (decaadbb31)
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  public:
62  {
63  for ( Qgs3DExportObject *obj : mObjects )
64  delete obj;
65  }
66 
71  bool parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer );
72 
74  void parseTerrain( QgsTerrainEntity *terrain, const QString &layer );
75 
77  void save( const QString &sceneName, const QString &sceneFolderPath );
78 
80  void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
82  bool smoothEdges() const { return mSmoothEdges; }
83 
85  void setExportNormals( bool exportNormals ) { mExportNormals = exportNormals; }
87  bool exportNormals() const { return mExportNormals; }
88 
90  void setExportTextures( bool exportTextures ) { mExportTextures = exportTextures; }
92  bool exportTextures() const { return mExportTextures; }
93 
95  void setTerrainResolution( int resolution ) { mTerrainResolution = resolution; }
97  int terrainResolution() const { return mTerrainResolution; }
98 
100  void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }
102  int terrainTextureResolution() const { return mTerrainTextureResolution; }
104  void setScale( float scale ) { mScale = scale; }
106  float scale() const { return mScale; }
107 
108  private:
110  QVector<Qgs3DExportObject *> processInstancedPointGeometry( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
112  QVector<Qgs3DExportObject *> processSceneLoaderGeometries( Qt3DRender::QSceneLoader *sceneLoader, const QString &objectNamePrefix );
114  Qgs3DExportObject *processGeometryRenderer( Qt3DRender::QGeometryRenderer *mesh, const QString &objectNamePrefix, float sceneScale = 1.0f, QVector3D sceneTranslation = QVector3D( 0.0f, 0.0f, 0.0f ) );
116  void processEntityMaterial( Qt3DCore::QEntity *entity, Qgs3DExportObject *object );
118  QVector<Qgs3DExportObject *> processLines( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
120  Qgs3DExportObject *processPoints( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
121 
123  QgsTerrainTileEntity *getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
125  QgsTerrainTileEntity *getDemTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
127  QgsTerrainTileEntity *getMeshTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
128 
130  void parseDemTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
132  void parseFlatTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
134  void parseMeshTile( QgsTerrainTileEntity *meshEntity, const QString &layerName );
135 
136  QString getObjectName( const QString &name );
137  private:
138  QMap<QString, int> usedObjectNamesCounter;
139  QVector<Qgs3DExportObject *> mObjects;
140 
141  bool mSmoothEdges = false;
142  int mTerrainResolution = 128;
143  bool mExportNormals = true;
144  bool mExportTextures = false;
145  int mTerrainTextureResolution = 512;
146  float mScale = 1.0f;
147 
148  friend QgsPolygon3DSymbol;
149  friend QgsLine3DSymbol;
150  friend QgsPoint3DSymbol;
151 };
152 
153 #endif // QGS3DSCENEEXPORTER_H
Manages the data of each object of the scene (positions, normals, texture coordinates ....
Entity that handles the exporting of 3D scene.
bool exportTextures() const
Returns whether the textures will be exported.
int terrainResolution() const
Returns the terrain resolution.
void setExportTextures(bool exportTextures)
Sets whether the textures will be exported.
~Qgs3DSceneExporter()
Destructor.
void setTerrainResolution(int resolution)
Sets the terrain resolution.
bool smoothEdges() const
Returns whether the triangles will look smooth.
Qgs3DSceneExporter()
Constructor.
void setTerrainTextureResolution(int resolution)
Sets the terrain texture resolution.
bool exportNormals() const
Returns whether the normals will be exported.
float scale() const
Returns the scale of the exported 3D model.
void setScale(float scale)
Sets the scale of the exported 3D model.
void setExportNormals(bool exportNormals)
Sets whether the normals will be exported.
void setSmoothEdges(bool smoothEdges)
Sets whether the triangles will look smooth.
int terrainTextureResolution() const
Returns the terrain resolution.
Represents a vector layer which manages a vector based data sets.