QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsgoochmaterialsettings.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgoochmaterialsettings.h
3 --------------------------------------
4 Date : July 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 QGSGOOCHMATERIALSETTINGS_H
17#define QGSGOOCHMATERIALSETTINGS_H
18
19#include "qgis_3d.h"
21#include "qgsmaterial.h"
22
23#include <QColor>
24
25class QDomElement;
26
38{
39 public:
41
42 QString type() const override;
43
48
52 static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );
53
54 QgsGoochMaterialSettings *clone() const override SIP_FACTORY;
55 bool equals( const QgsAbstractMaterialSettings *other ) const override;
56
58 QColor warm() const { return mWarm; }
59
61 QColor cool() const { return mCool; }
62
64 QColor diffuse() const { return mDiffuse; }
66 QColor specular() const { return mSpecular; }
68 double shininess() const { return mShininess; }
69
71 double alpha() const { return mAlpha; }
72
74 double beta() const { return mBeta; }
75
77 void setWarm( const QColor &warm ) { mWarm = warm; }
78
80 void setCool( const QColor &cool ) { mCool = cool; }
81
83 void setDiffuse( const QColor &diffuse ) { mDiffuse = diffuse; }
85 void setSpecular( const QColor &specular ) { mSpecular = specular; }
87 void setShininess( double shininess ) { mShininess = shininess; }
88
90 void setAlpha( double alpha ) { mAlpha = alpha; }
91
93 void setBeta( double beta ) { mBeta = beta; }
94
95 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
96 void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
97 QMap<QString, QString> toExportParameters() const override;
98
99#ifndef SIP_RUN
100 QgsMaterial *toMaterial( QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context ) const override;
101 void addParametersToEffect( Qt3DRender::QEffect *effect, const QgsMaterialContext &materialContext ) const override;
102
103 QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const override;
104 int dataDefinedByteStride() const override;
105#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
106 void applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
107#else
108 void applyDataDefinedToGeometry( Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
109#endif
110
111#endif
112
113 // TODO c++20 - replace with = default
114 bool operator==( const QgsGoochMaterialSettings &other ) const
115 {
116 return mDiffuse == other.mDiffuse && mSpecular == other.mSpecular && mWarm == other.mWarm && mCool == other.mCool && qgsDoubleNear( mShininess, other.mShininess ) && qgsDoubleNear( mAlpha, other.mAlpha ) && qgsDoubleNear( mBeta, other.mBeta ) && dataDefinedProperties() == other.dataDefinedProperties();
117 }
118
119 private:
120 QColor mDiffuse { QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) };
121 QColor mSpecular { QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
122 QColor mWarm { QColor( 107, 0, 107 ) };
123 QColor mCool { QColor( 255, 130, 0 ) };
124 double mShininess = 100.0;
125 double mAlpha = 0.25;
126 double mBeta = 0.5;
127
129 QgsMaterial *buildMaterial( const QgsMaterialContext &context ) const;
130};
131
132
133#endif // QGSGOOCHMATERIALSETTINGS_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.
QgsPropertyCollection dataDefinedProperties() const
Returns the symbol material property collection, used for data defined overrides.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QColor specular() const
Returns specular color component.
double alpha() const
Returns the alpha value.
void setCool(const QColor &cool)
Sets cool color component.
void setWarm(const QColor &warm)
Sets warm color component.
QColor cool() const
Returns cool color component.
void setSpecular(const QColor &specular)
Sets specular color component.
QColor diffuse() const
Returns diffuse color component.
double beta() const
Returns the beta value.
bool operator==(const QgsGoochMaterialSettings &other) const
QgsGoochMaterialSettings()=default
void setBeta(double beta)
Sets beta value.
void setShininess(double shininess)
Sets shininess of the surface.
void setAlpha(double alpha)
Sets alpha value.
void setDiffuse(const QColor &diffuse)
Sets diffuse color component.
double shininess() const
Returns shininess of the surface.
The class is used as a container of context for various read/write operations on other objects.
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:6024
#define SIP_FACTORY
Definition qgis_sip.h:76