QGIS API Documentation 4.1.0-Master (376402f9aeb)
Loading...
Searching...
No Matches
qgs3dexportobject.h
Go to the documentation of this file.
1/***************************************************************************
2 Qgs3DExportObject.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 Qgs3DExportObject_H
17#define Qgs3DExportObject_H
18
19#include "qgis.h"
20#include "qgis_3d.h"
21
22#include <QImage>
23#include <QMap>
24#include <QMatrix4x4>
25#include <QObject>
26#include <QTextStream>
27#include <QVector>
28#include <QVector3D>
29
30#define SIP_NO_FILE
31
33
42class _3D_EXPORT Qgs3DExportObject
43{
44 public:
52
58 Qgs3DExportObject( const QString &name )
59 : mName( name )
60 {}
61
63 QString name() const { return mName; }
65 void setName( const QString &name ) { mName = name; }
66
68 ObjectType type() const { return mType; }
69
71 bool smoothEdges() const { return mSmoothEdges; }
73 void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
74
76 void setupLine( const QVector<float> &positionsBuffer );
77
79 void setupTriangle( const QVector<float> &positionsBuffer, const QVector<uint> &facesIndexes, const QMatrix4x4 &transform );
80
82 void setupPoint( const QVector<float> &positionsBuffer );
83
85 void setupNormalCoordinates( const QVector<float> &normalsBuffer, const QMatrix4x4 &transform );
87 void setupTextureCoordinates( const QVector<float> &texturesBuffer );
89 void setupMaterial( QgsAbstractMaterialSettings *material );
90
92 void setTextureImage( const QImage &image ) { this->mTextureImage = image; };
94 QImage textureImage() const { return mTextureImage; }
95
101 void objectBounds( float &minX, float &minY, float &minZ, float &maxX, float &maxY, float &maxZ ) const;
102
119 void saveTo(
120 QTextStream &out, float scale, const QVector3D &center, const Qgis::Export3DSceneFormat &exportFormat = Qgis::Export3DSceneFormat::Obj, int precision = 6, QString materialName = QString()
121 ) const;
122
124 QString saveMaterial( QTextStream &mtlOut, const QString &folder ) const;
125
127 QVector<float> vertexPosition() const { return mVertexPosition; }
128
130 QVector<float> normals() const { return mNormals; }
131
133 QVector<float> texturesUV() const { return mTexturesUV; }
134
136 QVector<unsigned int> indexes() const { return mIndexes; }
137
138 private:
140 void setupPositionCoordinates( const QVector<float> &positionsBuffer, const QMatrix4x4 &transform = QMatrix4x4() );
141
143 void saveToObj( QTextStream &out, float scale, const QVector3D &center, int precision = 6, QString materialName = QString() ) const;
144
146 void saveToStl( QTextStream &out, float scale, const QVector3D &center, int precision = 6 ) const;
147
148 private:
149 QString mName;
150 ObjectType mType = ObjectType::TriangularFaces;
151 QString mParentName;
152 QVector<float> mVertexPosition;
153 QVector<float> mNormals;
154 QVector<float> mTexturesUV;
155 QVector<unsigned int> mIndexes;
156 QMap<QString, QString> mMaterialParameters;
157
158 QImage mTextureImage;
159
160 bool mSmoothEdges = false;
161};
162
163#endif // Qgs3DExportObject_H
Export3DSceneFormat
The file format used when exporting a 3D scene.
Definition qgis.h:4438
@ Obj
Wavefront OBJ format.
Definition qgis.h:4439
QVector< float > texturesUV() const
Returns the vertex texture coordinates.
QImage textureImage() const
Returns the texture image used by the object.
QVector< unsigned int > indexes() const
Returns the vertex indexes.
Qgs3DExportObject(const QString &name)
Qgs3DExportObject Constructs an export object that will be filled with coordinates later.
QVector< float > vertexPosition() const
Returns the vertex coordinates.
ObjectType type() const
Returns the object type.
ObjectType
The type of exported geometry.
QString name() const
Returns the object name.
QVector< float > normals() const
Returns the vertex normal coordinates.
void setTextureImage(const QImage &image)
Sets the texture image used by the object.
bool smoothEdges() const
Returns whether object edges will look smooth.
void setName(const QString &name)
Sets the object name.
void setSmoothEdges(bool smoothEdges)
Sets whether triangles edges will look smooth.
Abstract base class for material settings.