QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "qgs3dexportobject.h"
20#include "qgsfeatureid.h"
21
22#include <QFile>
23#include <QMap>
24#include <QMatrix4x4>
25#include <QVector3D>
26#include <Qt3DCore/QEntity>
27#include <Qt3DExtras/QPlaneGeometry>
28#include <Qt3DRender/QMesh>
29#include <Qt3DRender/QSceneLoader>
30
32class QgsTerrainTileEntity;
33class QgsTerrainEntity;
37class QgsChunkNode;
39class QgsTerrainTextureGenerator;
40class QgsVector3D;
41class QgsVectorLayer;
43class QgsLine3DSymbol;
45class QgsMeshEntity;
46class TestQgs3DExporter;
47
48#define SIP_NO_FILE
49
58class _3D_EXPORT Qgs3DSceneExporter : public Qt3DCore::QEntity
59{
60 Q_OBJECT
61
62 public:
64
66 {
67 for ( Qgs3DExportObject *obj : mObjects )
68 delete obj;
69 }
70
75 bool parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer );
76
78 void parseTerrain( QgsTerrainEntity *terrain, const QString &layer );
79
84 bool save( const QString &sceneName, const QString &sceneFolderPath, int precision = 6 ) const;
85
87 void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
89 bool smoothEdges() const { return mSmoothEdges; }
90
92 void setExportNormals( bool exportNormals ) { mExportNormals = exportNormals; }
94 bool exportNormals() const { return mExportNormals; }
95
97 void setExportTextures( bool exportTextures ) { mExportTextures = exportTextures; }
99 bool exportTextures() const { return mExportTextures; }
100
102 void setTerrainResolution( int resolution ) { mTerrainResolution = resolution; }
104 int terrainResolution() const { return mTerrainResolution; }
105
107 void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }
109 int terrainTextureResolution() const { return mTerrainTextureResolution; }
111 void setScale( float scale ) { mScale = scale; }
113 float scale() const { return mScale; }
114
115 private:
117 QVector<Qgs3DExportObject *> processInstancedPointGeometry( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
119 QVector<Qgs3DExportObject *> processSceneLoaderGeometries( Qt3DRender::QSceneLoader *sceneLoader, const QString &objectNamePrefix );
121 Qgs3DExportObject *processGeometryRenderer( Qt3DRender::QGeometryRenderer *mesh, const QString &objectNamePrefix, const QMatrix4x4 &sceneTransform = QMatrix4x4() );
123 void processEntityMaterial( Qt3DCore::QEntity *entity, Qgs3DExportObject *object ) const;
125 QVector<Qgs3DExportObject *> processLines( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
127 Qgs3DExportObject *processPoints( Qt3DCore::QEntity *entity, const QString &objectNamePrefix );
128
130 QgsTerrainTileEntity *getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node, const QgsVector3D &mapOrigin );
132 QgsTerrainTileEntity *getDemTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node, const QgsVector3D &mapOrigin );
134 QgsTerrainTileEntity *getMeshTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node, const QgsVector3D &mapOrigin );
135
137 void parseDemTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
139 void parseFlatTile( QgsTerrainTileEntity *tileEntity, const QString &layerName );
141 void parseMeshTile( QgsTerrainTileEntity *meshEntity, const QString &layerName );
142
143 QString getObjectName( const QString &name );
144
145 private:
146 QMap<QString, int> mUsedObjectNamesCounter;
147 QVector<Qgs3DExportObject *> mObjects;
148
149 bool mSmoothEdges = false;
150 int mTerrainResolution = 128;
151 bool mExportNormals = true;
152 bool mExportTextures = false;
153 int mTerrainTextureResolution = 512;
154 float mScale = 1.0f;
155
156 QSet<QgsFeatureId> mExportedFeatureIds;
157
158 friend QgsPolygon3DSymbol;
159 friend QgsLine3DSymbol;
160 friend QgsPoint3DSymbol;
161 friend TestQgs3DExporter;
162};
163
164#endif // QGS3DSCENEEXPORTER_H
Manages the data of each object of the scene (positions, normals, texture coordinates ....
Definition of the world.
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.
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:30
Represents a vector layer which manages a vector based dataset.