QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <QObject>
20 #include <QTextStream>
21 #include <QVector>
22 #include <QVector3D>
23 #include <QImage>
24 #include <Qt3DRender/QAttribute>
25 
26 #include "qgis_3d.h"
27 
28 #define SIP_NO_FILE
29 
31 
41 class _3D_EXPORT Qgs3DExportObject
42 {
43  public:
46  {
49  Points
50  };
51 
60  Qgs3DExportObject( const QString &name ) : mName( name ) { }
61 
63  QString name() const { return mName; }
65  void setName( const QString &name ) { mName = name; }
66 
68  ObjectType type() const { return mType; }
70  void setType( ObjectType type ) { mType = type; }
71 
73  bool smoothEdges() { return mSmoothEdges; }
75  void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
76 
78  void setupPositionCoordinates( const QVector<float> &positionsBuffer, float scale = 1.0f, const QVector3D &translation = QVector3D( 0, 0, 0 ) );
80  void setupFaces( const QVector<uint> &facesIndexes );
82  void setupLine( const QVector<uint> &facesIndexes );
83 
85  void setupNormalCoordinates( const QVector<float> &normalsBuffer );
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() { return mTextureImage; }
95 
101  void objectBounds( float &minX, float &minY, float &minZ, float &maxX, float &maxY, float &maxZ );
102 
104  void setMaterialParameter( const QString &parameter, const QString &value ) { mMaterialParameters[parameter] = value; }
105 
107  void saveTo( QTextStream &out, float scale, const QVector3D &center );
109  QString saveMaterial( QTextStream &mtlOut, const QString &folder );
110 
111  private:
112  QString mName;
113  ObjectType mType = ObjectType::TriangularFaces;
114  QString mParentName;
115  QVector<float> mVertexPosition;
116  QVector<float> mNormals;
117  QVector<float> mTexturesUV;
118  QVector<unsigned int> mIndexes;
119  QMap<QString, QString> mMaterialParameters;
120 
121  QImage mTextureImage;
122 
123  bool mSmoothEdges = false;
124 };
125 
126 #endif // Qgs3DExportObject_H
Qgs3DExportObject::setName
void setName(const QString &name)
Sets the object name.
Definition: qgs3dexportobject.h:65
Qgs3DExportObject::TriangularFaces
@ TriangularFaces
Definition: qgs3dexportobject.h:47
Qgs3DExportObject::setSmoothEdges
void setSmoothEdges(bool smoothEdges)
Sets whether triangles edges will look smooth.
Definition: qgs3dexportobject.h:75
Qgs3DExportObject::ObjectType
ObjectType
The type of exported geometry.
Definition: qgs3dexportobject.h:46
Qgs3DExportObject::setTextureImage
void setTextureImage(const QImage &image)
Sets the texture image used by the object.
Definition: qgs3dexportobject.h:92
Qgs3DExportObject
The Qgs3DExportObject class Manages the data of each object of the scene (positions,...
Definition: qgs3dexportobject.h:42
Qgs3DExportObject::textureImage
QImage textureImage()
Returns the texture image used by the object.
Definition: qgs3dexportobject.h:94
Qgs3DExportObject::name
QString name() const
Returns the object name.
Definition: qgs3dexportobject.h:63
Qgs3DExportObject::setType
void setType(ObjectType type)
Sets the object type.
Definition: qgs3dexportobject.h:70
Qgs3DExportObject::smoothEdges
bool smoothEdges()
Returns whether object edges will look smooth.
Definition: qgs3dexportobject.h:73
QgsAbstractMaterialSettings
3 Abstract base class for material settings.
Definition: qgsabstractmaterialsettings.h:105
Qgs3DExportObject::LineStrip
@ LineStrip
Definition: qgs3dexportobject.h:48
Qgs3DExportObject::type
ObjectType type() const
Returns the object type.
Definition: qgs3dexportobject.h:68
Qgs3DExportObject::Qgs3DExportObject
Qgs3DExportObject(const QString &name)
Qgs3DExportObject Constructs an export object that will be filled with coordinates later.
Definition: qgs3dexportobject.h:60
Qgs3DExportObject::setMaterialParameter
void setMaterialParameter(const QString &parameter, const QString &value)
Sets a material parameter to be exported in the .mtl file.
Definition: qgs3dexportobject.h:104