QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsphongtexturedmaterialsettings.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsphongtexturedmaterialsettings.h
3  --------------------------------------
4  Date : August 2020
5  Copyright : (C) 2020 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
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 QGSPHONGTEXTUREDMATERIALSETTINGS_H
17 #define QGSPHONGTEXTUREDMATERIALSETTINGS_H
18 
19 #include "qgis_3d.h"
21 
22 #include <QColor>
23 
24 class QDomElement;
25 
36 {
37  public:
38 
43 
44  QString type() const override;
45 
49  static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );
50 
55 
56  QgsPhongTexturedMaterialSettings *clone() const override SIP_FACTORY;
57 
59  QColor ambient() const { return mAmbient; }
61  QColor specular() const { return mSpecular; }
63  float shininess() const { return mShininess; }
64 
65  QMap<QString, QString> toExportParameters() const override;
66 
72  QString diffuseTexturePath() const { return mDiffuseTexturePath; }
73 
79  float textureScale() const { return mTextureScale; }
80 
85  bool requiresTextureCoordinates() const { return !mDiffuseTexturePath.isEmpty(); }
86 
90  float textureRotation() const;
91 
93  void setAmbient( const QColor &ambient ) { mAmbient = ambient; }
94 
96  void setSpecular( const QColor &specular ) { mSpecular = specular; }
98  void setShininess( float shininess ) { mShininess = shininess; }
99 
104  void setDiffuseTexturePath( const QString &path ) { mDiffuseTexturePath = path; }
105 
111  void setTextureScale( float scale ) { mTextureScale = scale; }
112 
114  void setTextureRotation( float rotation ) { mTextureRotation = rotation; }
115 
116  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
117  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
118 #ifndef SIP_RUN
119  Qt3DRender::QMaterial *toMaterial( QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context ) const override SIP_FACTORY;
120  void addParametersToEffect( Qt3DRender::QEffect *effect ) const override;
121 #endif
122 
123  bool operator==( const QgsPhongTexturedMaterialSettings &other ) const
124  {
125  return mAmbient == other.mAmbient &&
126  mSpecular == other.mSpecular &&
127  mShininess == other.mShininess &&
128  mDiffuseTexturePath == other.mDiffuseTexturePath &&
129  mTextureScale == other.mTextureScale &&
130  mTextureRotation == other.mTextureRotation;
131  }
132 
133  private:
134  QColor mAmbient{ QColor::fromRgbF( 0.1f, 0.1f, 0.1f, 1.0f ) };
135  QColor mSpecular{ QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
136  float mShininess = 0.0f;
137  QString mDiffuseTexturePath;
138  float mTextureScale{ 1.0f };
139  float mTextureRotation{ 0.0f };
140 };
141 
142 
143 #endif // QGSPHONGTEXTUREDMATERIALSETTINGS_H
QgsAbstractMaterialSettings::type
virtual QString type() const =0
Returns the unique type name for the material.
QgsPhongTexturedMaterialSettings::QgsPhongTexturedMaterialSettings
QgsPhongTexturedMaterialSettings()=default
Constructor for QgsPhongTexturedMaterialSettings.
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsPhongTexturedMaterialSettings::specular
QColor specular() const
Returns specular color component.
Definition: qgsphongtexturedmaterialsettings.h:61
QgsAbstractMaterialSettings::toExportParameters
virtual QMap< QString, QString > toExportParameters() const =0
Returns the parameters to be exported to .mtl file.
QgsAbstractMaterialSettings::readXml
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads settings from a DOM element.
QgsPhongTexturedMaterialSettings::setTextureRotation
void setTextureRotation(float rotation)
Sets the texture rotation in degrees.
Definition: qgsphongtexturedmaterialsettings.h:114
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMaterialContext
3 Context settings for a material.
Definition: qgsabstractmaterialsettings.h:55
qgsabstractmaterialsettings.h
QgsPhongTexturedMaterialSettings::diffuseTexturePath
QString diffuseTexturePath() const
Returns the diffuse texture path.
Definition: qgsphongtexturedmaterialsettings.h:72
QgsPhongTexturedMaterialSettings::textureScale
float textureScale() const
Returns the texture scale The texture scale changes the size of the displayed texture in the 3D scene...
Definition: qgsphongtexturedmaterialsettings.h:79
QgsAbstractMaterialSettings
3 Abstract base class for material settings.
Definition: qgsabstractmaterialsettings.h:105
QgsPhongTexturedMaterialSettings::shininess
float shininess() const
Returns shininess of the surface.
Definition: qgsphongtexturedmaterialsettings.h:63
QgsPhongTexturedMaterialSettings::setSpecular
void setSpecular(const QColor &specular)
Sets specular color component.
Definition: qgsphongtexturedmaterialsettings.h:96
QgsAbstractMaterialSettings::addParametersToEffect
virtual void addParametersToEffect(Qt3DRender::QEffect *effect) const =0
Adds parameters from the material to a destination effect.
QgsPhongTexturedMaterialSettings::setTextureScale
void setTextureScale(float scale)
Sets the texture scale The texture scale changes the size of the displayed texture in the 3D scene If...
Definition: qgsphongtexturedmaterialsettings.h:111
QgsAbstractMaterialSettings::writeXml
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &context) const =0
Writes settings to a DOM element.
QgsMaterialSettingsRenderingTechnique
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
Definition: qgsabstractmaterialsettings.h:36
QgsPhongTexturedMaterialSettings
3 A phong shading model with diffuse texture map.
Definition: qgsphongtexturedmaterialsettings.h:36
QgsAbstractMaterialSettings::toMaterial
virtual Qt3DRender::QMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const =0
Creates a new QMaterial object representing the material settings.
QgsPhongTexturedMaterialSettings::setShininess
void setShininess(float shininess)
Sets shininess of the surface.
Definition: qgsphongtexturedmaterialsettings.h:98
QgsPhongTexturedMaterialSettings::operator==
bool operator==(const QgsPhongTexturedMaterialSettings &other) const
Definition: qgsphongtexturedmaterialsettings.h:123
QgsPhongTexturedMaterialSettings::setAmbient
void setAmbient(const QColor &ambient)
Sets ambient color component.
Definition: qgsphongtexturedmaterialsettings.h:93
QgsPhongTexturedMaterialSettings::requiresTextureCoordinates
bool requiresTextureCoordinates() const
Returns true if the material requires texture coordinates to be generated during triangulation....
Definition: qgsphongtexturedmaterialsettings.h:85
QgsPhongTexturedMaterialSettings::setDiffuseTexturePath
void setDiffuseTexturePath(const QString &path)
Sets the path of the diffuse texture.
Definition: qgsphongtexturedmaterialsettings.h:104