QGIS API Documentation 3.39.0-Master (3aed037ce22)
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
22#include <QColor>
23
24class QDomElement;
25
36{
37 public:
38
40
41 QString type() const override;
42
46 static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );
47
52
53 QgsPhongMaterialSettings *clone() const override SIP_FACTORY;
54
56 QColor ambient() const { return mAmbient; }
58 QColor diffuse() const { return mDiffuse; }
60 QColor specular() const { return mSpecular; }
62 double shininess() const { return mShininess; }
63
68 double opacity() const { return mOpacity; }
69
79 double ambientCoefficient() const { return mAmbientCoefficient; }
80
90 double diffuseCoefficient() const { return mDiffuseCoefficient; }
91
101 double specularCoefficient() const { return mSpecularCoefficient; }
102
103 QMap<QString, QString> toExportParameters() const override;
104
106 void setAmbient( const QColor &ambient ) { mAmbient = ambient; }
108 void setDiffuse( const QColor &diffuse ) { mDiffuse = diffuse; }
110 void setSpecular( const QColor &specular ) { mSpecular = specular; }
112 void setShininess( float shininess ) { mShininess = shininess; }
113
118 void setOpacity( double opacity ) { mOpacity = opacity; }
119
129 void setAmbientCoefficient( double coefficient ) { mAmbientCoefficient = coefficient; }
130
140 void setDiffuseCoefficient( double coefficient ) { mDiffuseCoefficient = coefficient; }
141
151 void setSpecularCoefficient( double coefficient ) { mSpecularCoefficient = coefficient; }
152
153 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
154 void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
155
156#ifndef SIP_RUN
157 Qt3DRender::QMaterial *toMaterial( QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context ) const override SIP_FACTORY;
158 void addParametersToEffect( Qt3DRender::QEffect *effect, const QgsMaterialContext &materialContext ) const override;
159
160 QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const override;
161 int dataDefinedByteStride() const override;
162#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
163 void applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
164#else
165 void applyDataDefinedToGeometry( Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
166#endif
167#endif
168
169 // TODO c++20 - replace with = default
170 bool operator==( const QgsPhongMaterialSettings &other ) const
171 {
172 return mAmbient == other.mAmbient &&
173 mDiffuse == other.mDiffuse &&
174 mOpacity == other.mOpacity &&
175 mSpecular == other.mSpecular &&
176 mShininess == other.mShininess &&
177 mAmbientCoefficient == other.mAmbientCoefficient &&
178 mDiffuseCoefficient == other.mDiffuseCoefficient &&
179 mSpecularCoefficient == other.mSpecularCoefficient;
180 }
181
182 private:
183 QColor mAmbient{ QColor::fromRgbF( 0.1f, 0.1f, 0.1f, 1.0f ) };
184 QColor mDiffuse{ QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) };
185 QColor mSpecular{ QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
186 double mShininess = 0.0;
187
188 double mAmbientCoefficient = 1.0;
189 double mDiffuseCoefficient = 1.0;
190 double mSpecularCoefficient = 1.0;
191
192 double mOpacity = 1.0;
193
195 Qt3DRender::QMaterial *buildMaterial( const QgsMaterialContext &context ) const;
196};
197
198
199#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 Qt3DRender::QMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const =0
Creates a new QMaterial object representing the material settings.
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...
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).
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
void setShininess(float shininess)
Sets shininess of the surface.
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