QGIS API Documentation 4.1.0-Master (3fcefe620d1)
Loading...
Searching...
No Matches
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 <optional>
20
21#include "qgis_core.h"
23
24#include <QColor>
25
26class QgsMaterial;
27class QDomElement;
28
39{
40 public:
42
43 QString type() const override;
44
49
54
56 bool equals( const QgsAbstractMaterialSettings *other ) const override;
58
60 QColor ambient() const { return mAmbient; }
62 QColor specular() const { return mSpecular; }
64 double shininess() const { return mShininess; }
65
71 QString diffuseTexturePath() const { return mDiffuseTexturePath; }
72
82 double textureScale() const { return mTextureScale; }
83
89 double textureRotation() const { return mTextureRotation; }
90
97 QPointF textureOffset() const { return mTextureOffset; }
98
99 bool requiresTextureCoordinates() const override;
100
105 double opacity() const { return mOpacity; }
106
108 void setAmbient( const QColor &ambient ) { mAmbient = ambient; }
109
111 void setSpecular( const QColor &specular ) { mSpecular = specular; }
113 void setShininess( double shininess ) { mShininess = shininess; }
114
119 void setDiffuseTexturePath( const QString &path )
120 {
121 mDiffuseTexturePath = path;
122 mTextureAverageColor.reset();
123 }
124
130 void setTextureScale( double scale ) { mTextureScale = scale; }
131
133 void setTextureRotation( double rotation ) { mTextureRotation = rotation; }
134
141 void setTextureOffset( QPointF offset ) { mTextureOffset = offset; }
142
147 void setOpacity( double opacity ) { mOpacity = opacity; }
148
161 QColor averageColor() const override;
162
178 void setColorsFromBase( const QColor &baseColor, float metallic );
179
194 void setColorsFromBase( const QColor &baseColor ) override;
195
196 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
197 void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
198
199 // TODO c++20 - replace with = default
201 {
202 return mAmbient == other.mAmbient
203 && mSpecular == other.mSpecular
204 && mShininess == other.mShininess
205 && mOpacity == other.mOpacity
206 && mDiffuseTexturePath == other.mDiffuseTexturePath
207 && mTextureScale == other.mTextureScale
208 && mTextureRotation == other.mTextureRotation
209 && qgsDoubleNear( mTextureOffset.x(), other.mTextureOffset.x() )
210 && qgsDoubleNear( mTextureOffset.y(), other.mTextureOffset.y() )
212 }
213
214 private:
215 QColor textureAverageColor() const;
216
217 private:
218 QColor mAmbient { QColor::fromRgbF( 0.1f, 0.1f, 0.1f, 1.0f ) };
219 QColor mSpecular { QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
220 double mShininess = 0.0;
221 double mOpacity = 1.0;
222 QString mDiffuseTexturePath;
223 double mTextureScale { 1.0f };
224 double mTextureRotation { 0.0f };
225 QPointF mTextureOffset { 0.0, 0.0 };
226 mutable std::optional<QColor> mTextureAverageColor;
227};
228
229
230#endif // QGSPHONGTEXTUREDMATERIALSETTINGS_H
MaterialRenderingTechnique
Material rendering techniques.
Definition qgis.h:4375
Abstract base class for material settings.
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
virtual QColor averageColor() const =0
Returns an approximate color representing the blended material color.
virtual QString type() const =0
Returns the unique type name for the material.
virtual void setColorsFromBase(const QColor &baseColor)=0
Decomposes a base color into the material's color components, and sets the material's colors accordin...
QgsPropertyCollection dataDefinedProperties() const
Returns the symbol material property collection, used for data defined overrides.
virtual bool requiresTextureCoordinates() const
Returns true if the material requires texture coordinates to be generated during triangulation.
Base class for all materials used within QGIS 3D views.
Definition qgsmaterial.h:40
QSet< QgsAbstractMaterialSettings::Property > supportedProperties() const override
Returns the set of data-defined properties supported by this material.
void setShininess(double shininess)
Sets shininess of the surface.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
void setTextureOffset(QPointF offset)
Sets the texture offset.
bool equals(const QgsAbstractMaterialSettings *other) const override
Returns true if this settings exactly matches an other settings.
void setTextureRotation(double rotation)
Sets the texture rotation in degrees.
void setSpecular(const QColor &specular)
Sets specular color component.
void setDiffuseTexturePath(const QString &path)
Sets the path of the diffuse texture.
QString diffuseTexturePath() const
Returns the diffuse texture path.
QColor specular() const
Returns specular color component.
double textureRotation() const
Returns the texture rotation, in degrees.
void setTextureScale(double scale)
Sets the texture scale The texture scale changes the size of the displayed texture in the 3D scene If...
QPointF textureOffset() const
Returns the texture offset.
void setAmbient(const QColor &ambient)
Sets ambient color component.
double shininess() const
Returns shininess of the surface.
double opacity() const
Returns the opacity of the surface.
QgsPhongTexturedMaterialSettings * clone() const override
Clones the material settings.
void setOpacity(double opacity)
Sets opacity of the surface.
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsPhongTexturedMaterialSettings.
bool operator==(const QgsPhongTexturedMaterialSettings &other) const
double textureScale() const
Returns the texture scale.
QColor ambient() const
Returns ambient color component.
A container for the context for various read/write operations on objects.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:7340
#define SIP_FACTORY
Definition qgis_sip.h:83