QGIS API Documentation 4.1.0-Master (3fcefe620d1)
Loading...
Searching...
No Matches
qgsmetalroughmaterialsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmetalroughmaterialsettings.cpp
3 --------------------------------------
4 Date : December 2023
5 Copyright : (C) 2023 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
17
18#include "qgssymbollayerutils.h"
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
25{
26 return u"metalrough"_s;
27}
28
33
52
57
62
64{
65 const QgsMetalRoughMaterialSettings *otherMetal = dynamic_cast<const QgsMetalRoughMaterialSettings *>( other );
66 if ( !otherMetal )
67 return false;
68
69 return *this == *otherMetal;
70}
71
73{
74 return mAnisotropy > 0;
75}
76
77void QgsMetalRoughMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
78{
79 mBaseColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( u"base"_s, u"125,125,125"_s ) );
80 if ( elem.hasAttribute( u"emission_color"_s ) )
81 mEmissiveColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( u"emission_color"_s ) );
82 else
83 mEmissiveColor = QColor();
84 mEmissionFactor = elem.attribute( u"emission_factor"_s, u"1.0"_s ).toDouble();
85
86 mClearCoatFactor = elem.attribute( u"clear_coat_factor"_s, u"0.0"_s ).toDouble();
87 mClearCoatRoughness = elem.attribute( u"clear_coat_roughness"_s, u"0.0"_s ).toDouble();
88
89 mMetalness = elem.attribute( u"metalness"_s, u"0.0"_s ).toDouble();
90 mRoughness = elem.attribute( u"roughness"_s, u"0.5"_s ).toDouble();
91 mOpacity = elem.attribute( u"opacity"_s, u"1.0"_s ).toDouble();
92 mReflectance = elem.attribute( u"reflectance"_s, u"0.5"_s ).toDouble();
93 mAnisotropy = elem.attribute( u"anisotropy"_s, u"0.0"_s ).toDouble();
94 mAnisotropyRotation = elem.attribute( u"anisotropy_rotation"_s, u"0.0"_s ).toDouble();
95
97}
98
99void QgsMetalRoughMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
100{
101 elem.setAttribute( u"base"_s, QgsSymbolLayerUtils::encodeColor( mBaseColor ) );
102 elem.setAttribute( u"metalness"_s, mMetalness );
103 elem.setAttribute( u"roughness"_s, mRoughness );
104 if ( !qgsDoubleNear( mReflectance, 0.5 ) )
105 {
106 elem.setAttribute( u"reflectance"_s, mReflectance );
107 }
108 if ( !qgsDoubleNear( mAnisotropy, 0.0 ) )
109 {
110 elem.setAttribute( u"anisotropy"_s, mAnisotropy );
111 }
112 if ( !qgsDoubleNear( mAnisotropyRotation, 0.0 ) )
113 {
114 elem.setAttribute( u"anisotropy_rotation"_s, mAnisotropyRotation );
115 }
116 if ( mEmissiveColor.isValid() )
117 elem.setAttribute( u"emission_color"_s, QgsSymbolLayerUtils::encodeColor( mEmissiveColor ) );
118 if ( !qgsDoubleNear( mEmissionFactor, 1.0 ) )
119 {
120 elem.setAttribute( u"emission_factor"_s, mEmissionFactor );
121 }
122
123 if ( !qgsDoubleNear( mClearCoatFactor, 0.0 ) )
124 {
125 elem.setAttribute( u"clear_coat_factor"_s, mClearCoatFactor );
126 }
127 if ( !qgsDoubleNear( mClearCoatRoughness, 0.0 ) )
128 {
129 elem.setAttribute( u"clear_coat_roughness"_s, mClearCoatRoughness );
130 }
131
132 if ( !qgsDoubleNear( mOpacity, 1 ) )
133 {
134 elem.setAttribute( u"opacity"_s, mOpacity );
135 }
136
138}
139
141{
142 return baseColor();
143}
144
MaterialRenderingTechnique
Material rendering techniques.
Definition qgis.h:4375
@ Points
Point based rendering, requires point data.
Definition qgis.h:4379
@ Triangles
Triangle based rendering (default).
Definition qgis.h:4376
@ TrianglesFromModel
Triangle based rendering, using a model object source.
Definition qgis.h:4381
@ Lines
Line based rendering, requires line data.
Definition qgis.h:4377
@ Billboards
Flat billboard rendering.
Definition qgis.h:4383
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
Definition qgis.h:4382
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
Definition qgis.h:4378
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering).
Definition qgis.h:4380
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.
@ BaseColor
Base color (metal-rough material).
@ EmissionColor
Emission color (metal-rough material).
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsMetalRoughMaterialSettings.
void setColorsFromBase(const QColor &baseColor) override
Decomposes a base color into the material's color components, and sets the material's color according...
bool requiresTangents() const override
Returns true if the material requires tangents generated during triangulation.
QSet< QgsAbstractMaterialSettings::Property > supportedProperties() const override
Returns the set of data-defined properties supported by this material.
QColor averageColor() const override
Returns an approximate color representing the blended material color.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the metal rough material.
QgsMetalRoughMaterialSettings * clone() const override
Clones the material settings.
QString type() const override
Returns the unique type name for the material.
bool equals(const QgsAbstractMaterialSettings *other) const override
Returns true if this settings exactly matches an other settings.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
void setBaseColor(const QColor &color)
Sets the base material color.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
QColor baseColor() const
Returns the base material color.
A container for the context for various read/write operations on objects.
static QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
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