-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgs3dsceneexporter.h
116 lines (100 loc) · 4.84 KB
/
qgs3dsceneexporter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***************************************************************************
qgs3dsceneexporter.h
--------------------------------------
Date : June 2020
Copyright : (C) 2020 by Belgacem Nedjima
Email : gb underscore nedjima at esi dot dz
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGS3DSCENEEXPORTER_H
#define QGS3DSCENEEXPORTER_H
#include <Qt3DCore/QEntity>
#include <Qt3DRender/QAttribute>
#include <Qt3DExtras/QPlaneGeometry>
#include <QMap>
#include <QFile>
class QgsTessellatedPolygonGeometry;
class QgsTerrainTileEntity;
class QgsTerrainEntity;
class Qgs3DMapSettings;
class QgsFlatTerrainGenerator;
class QgsDemTerrainGenerator;
class QgsChunkNode;
class Qgs3DExportObject;
class QgsTerrainTextureGenerator;
/**
* \brief The Qgs3DSceneExporter class
* Entity that handles the exporting of 3D scene
* \ingroup 3d
* \since QGIS 3.16
*/
class Qgs3DSceneExporter : public Qt3DCore::QEntity
{
Q_OBJECT
public:
//! Constructor
Qgs3DSceneExporter( Qt3DCore::QNode *parent = nullptr );
/**
* Creates necessary export objects from entity if it represents valid vector layer entity
* If the entity doesn't define exportable object it will be ignored
*/
void parseVectorLayerEntity( Qt3DCore::QEntity *entity );
//! Creates terrain export objects from the terrain entity
void parseTerrain( QgsTerrainEntity *terrain );
//! Saves the scene to a .obj file
void save( const QString &sceneName, const QString &sceneFolderPath );
//! Sets whether the triangles will look smooth
void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
//! Returns whether the triangles will look smooth
bool smoothEdges() const { return mSmoothEdges; }
//! Sets whether the normals will be exported
void setExportNormals( bool exportNormals ) { mExportNormals = exportNormals; }
//! Returns whether the normals will be exported
bool exportNormals() const { return mExportNormals; }
//! Sets whether the textures will be exported
void setExportTextures( bool exportTextures ) { mExportTextures = exportTextures; }
//! Returns whether the textures will be exported
bool exportTextures() const { return mExportTextures; }
//! Sets the terrain resolution
void setTerrainResolution( int resolution ) { mTerrainResolution = resolution; }
//! Returns the terrain resolution
int terrainResolution() const { return mTerrainResolution; }
//! Sets the terrain texture resolution
void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }
//! Returns the terrain resolution
int terrainTextureResolution() const { return mTerrainTextureResolution; }
//! Sets the scale of the exported 3D model
void setScale( float scale ) { mScale = scale; }
//! Returns the scale of the exported 3D model
float scale() const { return mScale; }
private:
//! Processes the attribute directly by taking a position buffer and converting it to Qgs3DExportObject
void pocessPoistionAttributes( Qt3DRender::QGeometry *geometry );
//! constructs Qgs3DExportObject from the polygon geometry
void processPolygonGeometry( QgsTessellatedPolygonGeometry *geom );
//! Returns a tile entity that contains the geometry to be exported and necessary scaling parameters
QgsTerrainTileEntity *getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
//! Returns a tile entity that contains the geometry to be exported and necessary scaling parameters
QgsTerrainTileEntity *getDemTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
//! Constructs a Qgs3DExportObject from the DEM tile entity
void parseDemTile( QgsTerrainTileEntity *tileEntity, QgsTerrainTextureGenerator *textureGenerator );
//! Constructs a Qgs3DExportObject from the flat tile entity
void parseFlatTile( QgsTerrainTileEntity *tileEntity, QgsTerrainTextureGenerator *textureGenerator );
QString getObjectName( const QString &name );
private:
QMap<QString, int> usedObjectNamesCounter;
QVector<Qgs3DExportObject *> mObjects;
bool mSmoothEdges;
int mTerrainResolution;
bool mExportNormals;
bool mExportTextures;
int mTerrainTextureResolution;
float mScale;
};
#endif // QGS3DSCENEEXPORTER_H