QGIS API Documentation 4.1.0-Master (64dc32379c2)
Loading...
Searching...
No Matches
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 "qgis_3d.h"
20#include "qgs3dexportobject.h"
21#include "qgsfeatureid.h"
22
23#include <QFile>
24#include <QMap>
25#include <QMatrix4x4>
26#include <QVector3D>
27#include <Qt3DCore/QEntity>
28#include <Qt3DExtras/QPlaneGeometry>
29#include <Qt3DRender/QMesh>
30#include <Qt3DRender/QSceneLoader>
31
32#define SIP_NO_FILE
33
35class QgsTerrainTileEntity;
36class QgsTerrainEntity;
40class QgsChunkNode;
42class QgsTerrainTextureGenerator;
43class QgsVector3D;
44class QgsVectorLayer;
46class QgsLine3DSymbol;
48class QgsMeshEntity;
49class TestQgs3DExporter;
50
51
60class _3D_EXPORT Qgs3DSceneExporter : public Qt3DCore::QEntity
61{
62 Q_OBJECT
63
64 public:
66
68 {
69 for ( Qgs3DExportObject *obj : mObjects )
70 delete obj;
71 }
72
77 bool parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer );
78
80 void parseTerrain( QgsTerrainEntity *terrain, const QString &layer );
81
86 bool save( QString sceneName, QString sceneFolderPath, const Qgis::Export3DSceneFormat &exportFormat = Qgis::Export3DSceneFormat::Obj, int precision = 6 ) const;
87
89 void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
91 bool smoothEdges() const { return mSmoothEdges; }
92
94 void setExportNormals( bool exportNormals ) { mExportNormals = exportNormals; }
96 bool exportNormals() const { return mExportNormals; }
97
99 void setExportTextures( bool exportTextures ) { mExportTextures = exportTextures; }
101 bool exportTextures() const { return mExportTextures; }
102
104 void setTerrainResolution( int resolution ) { mTerrainResolution = resolution; }
106 int terrainResolution() const { return mTerrainResolution; }
107
109 void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }
111 int terrainTextureResolution() const { return mTerrainTextureResolution; }
113 void setScale( float scale ) { mScale = scale; }
115 float scale() const { return mScale; }
116
125 bool terrainExportEnabled() const { return mTerrainExportEnabled; }
126
133 void setTerrainExportEnabled( bool enabled ) { mTerrainExportEnabled = enabled; }
134
135 private:
137 QVector<Qgs3DExportObject *> processInstancedPointGeometry( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
139 QVector<Qgs3DExportObject *> processSceneLoaderGeometries( Qt3DRender::QSceneLoader *sceneLoader, const QString &objectNamePrefix );
141 Qgs3DExportObject *processGeometryRenderer( Qt3DRender::QGeometryRenderer *mesh, const QString &objectNamePrefix, const QMatrix4x4 &sceneTransform = QMatrix4x4() );
143 void processEntityMaterial( Qt3DCore::QEntity *entity, Qgs3DExportObject *object ) const;
145 QVector<Qgs3DExportObject *> processLines( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
147 Qgs3DExportObject *processPoints( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
148
150 QgsTerrainTileEntity *getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node, const QgsVector3D &mapOrigin );
152 QgsTerrainTileEntity *getDemTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node, const QgsVector3D &mapOrigin );
154 QgsTerrainTileEntity *getMeshTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node, const QgsVector3D &mapOrigin );
155
157 void parseDemTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
159 void parseFlatTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
161 void parseMeshTile( QgsTerrainTileEntity *meshEntity, const QString &layerName );
162
163 QString getObjectName( const QString &name );
164
166 void getSceneCenterAndScale( QVector3D &center, float &scale ) const;
167
169 bool saveObj( QString sceneName, QString sceneFolderPath, int precision ) const;
170
172 bool saveStl( QString sceneName, QString sceneFolderPath, int precision ) const;
173
174 private:
175 QMap<QString, int> mUsedObjectNamesCounter;
176 QVector<Qgs3DExportObject *> mObjects;
177
178 bool mSmoothEdges = false;
179 int mTerrainResolution = 128;
180 bool mExportNormals = true;
181 bool mExportTextures = false;
182 int mTerrainTextureResolution = 512;
183 float mScale = 1.0f;
184 bool mTerrainExportEnabled = true;
185
186 QSet<QgsFeatureId> mExportedFeatureIds;
187
188 friend QgsPolygon3DSymbol;
189 friend QgsLine3DSymbol;
190 friend QgsPoint3DSymbol;
191 friend TestQgs3DExporter;
192};
193
194#endif // QGS3DSCENEEXPORTER_H
Export3DSceneFormat
The file format used when exporting a 3D scene.
Definition qgis.h:4452
@ Obj
Wavefront OBJ format.
Definition qgis.h:4453
Manages the data of each object of the scene (positions, normals, texture coordinates ....
Definition of the world.
bool terrainExportEnabled() const
Returns whether terrain export is enabled.
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.
void setTerrainResolution(int resolution)
Sets the terrain resolution.
bool smoothEdges() const
Returns whether the triangles will look smooth.
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.
void setTerrainExportEnabled(bool enabled)
Sets whether terrain export is enabled.
Implementation of terrain generator that uses a raster layer with DEM to build terrain.
Terrain generator that creates a simple square flat area.
3D symbol that draws linestring geometries as planar polygons (created from lines using a buffer with...
3D symbol that draws point geometries as 3D objects using one of the predefined shapes.
3D symbol that draws polygon geometries as planar polygons, optionally extruded (with added walls).
Qt3DRender::QGeometry subclass that represents polygons tessellated into 3D geometry.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33
Represents a vector layer which manages a vector based dataset.