QGIS API Documentation 3.99.0-Master (8e76e220402)
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
20#include "qgssymbollayerutils.h"
21
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27{
28 return u"metalrough"_s;
29}
30
48
53
58
60{
61 const QgsMetalRoughMaterialSettings *otherMetal = dynamic_cast<const QgsMetalRoughMaterialSettings *>( other );
62 if ( !otherMetal )
63 return false;
64
65 return *this == *otherMetal;
66}
67
68void QgsMetalRoughMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
69{
70 mBaseColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( u"base"_s, u"125,125,125"_s ) );
71 mMetalness = elem.attribute( u"metalness"_s ).toDouble();
72 mRoughness = elem.attribute( u"roughness"_s ).toDouble();
73
75}
76
77void QgsMetalRoughMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
78{
79 elem.setAttribute( u"base"_s, QgsSymbolLayerUtils::encodeColor( mBaseColor ) );
80 elem.setAttribute( u"metalness"_s, mMetalness );
81 elem.setAttribute( u"roughness"_s, mRoughness );
82
84}
85
87{
88 switch ( technique )
89 {
94 {
95 if ( context.isHighlighted() )
96 {
97 return new QgsHighlightMaterial( technique );
98 }
99
100 QgsMetalRoughMaterial *material = new QgsMetalRoughMaterial;
101 material->setBaseColor( context.isSelected() ? context.selectionColor() : mBaseColor );
102 material->setMetalness( mMetalness );
103 material->setRoughness( mRoughness );
104 return material;
105 }
106
110 return nullptr;
111 }
112 return nullptr;
113}
114
116{
117 QMap<QString, QString> parameters;
118 return parameters;
119}
120
122{
123}
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.
Context settings for a material.
QColor selectionColor() const
Returns the color for representing materials in a selected state.
bool isSelected() const
Returns true if the material should represent a selected state.
bool isHighlighted() const
Returns true if the material should represent a highlighted state.
Base class for all materials used within QGIS 3D views.
Definition qgsmaterial.h:39
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsMetalRoughMaterialSettings.
QgsMetalRoughMaterialSettings * clone() const override
Clones the material settings.
QString type() const override
Returns the unique type name for the material.
QgsMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QgsMaterial object representing the material settings.
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 addParametersToEffect(Qt3DRender::QEffect *effect, const QgsMaterialContext &materialContext) const override
Adds parameters from the material to a destination effect.
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the metal rough material.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
QMap< QString, QString > toExportParameters() const override
Returns the parameters to be exported to .mtl file.
A container for the context for various read/write operations on objects.
static QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
QgsMaterialSettingsRenderingTechnique
Material rendering techniques.
@ Points
Point based rendering, requires point data.
@ Triangles
Triangle based rendering (default).
@ TrianglesFromModel
Triangle based rendering, using a model object source.
@ Lines
Line based rendering, requires line data.
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering).