QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsphongmaterialsettings.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsphongmaterialsettings.h
3 --------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 by Martin Dobias
6 Email : wonder dot sk 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 QGSPHONGMATERIALSETTINGS_H
17#define QGSPHONGMATERIALSETTINGS_H
18
19#include "qgis_3d.h"
21#include "qgsmaterial.h"
22
23#include <QColor>
24
25class QDomElement;
26
37{
38 public:
39
41
42 QString type() const override;
43
47 static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );
48
53
54 QgsPhongMaterialSettings *clone() const override SIP_FACTORY;
55
57 QColor ambient() const { return mAmbient; }
59 QColor diffuse() const { return mDiffuse; }
61 QColor specular() const { return mSpecular; }
63 double shininess() const { return mShininess; }
64
69 double opacity() const { return mOpacity; }
70
80 double ambientCoefficient() const { return mAmbientCoefficient; }
81
91 double diffuseCoefficient() const { return mDiffuseCoefficient; }
92
102 double specularCoefficient() const { return mSpecularCoefficient; }
103
104 QMap<QString, QString> toExportParameters() const override;
105
107 void setAmbient( const QColor &ambient ) { mAmbient = ambient; }
109 void setDiffuse( const QColor &diffuse ) { mDiffuse = diffuse; }
111 void setSpecular( const QColor &specular ) { mSpecular = specular; }
113 void setShininess( double shininess ) { mShininess = shininess; }
114
119 void setOpacity( double opacity ) { mOpacity = opacity; }
120
130 void setAmbientCoefficient( double coefficient ) { mAmbientCoefficient = coefficient; }
131
141 void setDiffuseCoefficient( double coefficient ) { mDiffuseCoefficient = coefficient; }
142
152 void setSpecularCoefficient( double coefficient ) { mSpecularCoefficient = coefficient; }
153
154 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
155 void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
156
157#ifndef SIP_RUN
159 void addParametersToEffect( Qt3DRender::QEffect *effect, const QgsMaterialContext &materialContext ) const override;
160
161 QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const override;
162 int dataDefinedByteStride() const override;
163#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
164 void applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
165#else
166 void applyDataDefinedToGeometry( Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
167#endif
168#endif
169
170 // TODO c++20 - replace with = default
171 bool operator==( const QgsPhongMaterialSettings &other ) const
172 {
173 return mAmbient == other.mAmbient &&
174 mDiffuse == other.mDiffuse &&
175 mOpacity == other.mOpacity &&
176 mSpecular == other.mSpecular &&
177 mShininess == other.mShininess &&
178 mAmbientCoefficient == other.mAmbientCoefficient &&
179 mDiffuseCoefficient == other.mDiffuseCoefficient &&
180 mSpecularCoefficient == other.mSpecularCoefficient;
181 }
182
183 private:
184 QColor mAmbient{ QColor::fromRgbF( 0.1f, 0.1f, 0.1f, 1.0f ) };
185 QColor mDiffuse{ QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) };
186 QColor mSpecular{ QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
187 double mShininess = 0.0;
188
189 double mAmbientCoefficient = 1.0;
190 double mDiffuseCoefficient = 1.0;
191 double mSpecularCoefficient = 1.0;
192
193 double mOpacity = 1.0;
194
196 QgsMaterial *buildMaterial( const QgsMaterialContext &context ) const;
197};
198
199
200#endif // QGSPHONGMATERIALSETTINGS_H
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
virtual QByteArray dataDefinedVertexColorsAsByte(const QgsExpressionContext &expressionContext) const
Returns byte array corresponding to the data defined colors depending of the expressionContext,...
virtual QMap< QString, QString > toExportParameters() const =0
Returns the parameters to be exported to .mtl file.
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
virtual int dataDefinedByteStride() const
Returns byte stride of the data defined colors,used to fill the vertex colors data defined buffer for...
virtual void addParametersToEffect(Qt3DRender::QEffect *effect, const QgsMaterialContext &materialContext) const =0
Adds parameters from the material to a destination effect.
virtual QString type() const =0
Returns the unique type name for the material.
virtual void applyDataDefinedToGeometry(Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes) const
Applies the data defined bytes, dataDefinedBytes, on the geometry by filling a specific vertex buffer...
virtual QgsMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const =0
Creates a new QgsMaterial object representing the material settings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
double ambientCoefficient() const
Returns the coefficient for the ambient color contribution (ie strength factor of the ambient color).
void setOpacity(double opacity)
Sets opacity of the surface.
bool operator==(const QgsPhongMaterialSettings &other) const
void setDiffuse(const QColor &diffuse)
Sets diffuse color component.
void setDiffuseCoefficient(double coefficient)
Sets the coefficient for the diffuse color contribution (ie strength factor of the diffuse color).
void setShininess(double shininess)
Sets shininess of the surface.
QColor diffuse() const
Returns diffuse color component.
double opacity() const
Returns the opacity of the surface.
QColor specular() const
Returns specular color component.
void setAmbient(const QColor &ambient)
Sets ambient color component.
void setSpecularCoefficient(double coefficient)
Sets the coefficient for the specular color contribution (ie strength factor of the specular color).
double specularCoefficient() const
Returns the coefficient for the specular color contribution (ie strength factor of the specular color...
double shininess() const
Returns shininess of the surface.
QgsPhongMaterialSettings()=default
double diffuseCoefficient() const
Returns the coefficient for the diffuse color contribution (ie strength factor of the diffuse color).
void setSpecular(const QColor &specular)
Sets specular color component.
void setAmbientCoefficient(double coefficient)
Sets the coefficient for the ambient color contribution (ie strength factor of the ambient color).
The class is used as a container of context for various read/write operations on other objects.
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
#define SIP_FACTORY
Definition qgis_sip.h:76