QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
22 #include <QColor>
23 
24 class QDomElement;
25 
37 {
38  public:
39 
43  QgsGoochMaterialSettings() = default;
44 
45  QString type() const override;
46 
51 
55  static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );
56 
57  QgsGoochMaterialSettings *clone() const override SIP_FACTORY;
58 
60  QColor warm() const { return mWarm; }
61 
63  QColor cool() const { return mCool; }
64 
66  QColor diffuse() const { return mDiffuse; }
68  QColor specular() const { return mSpecular; }
70  float shininess() const { return mShininess; }
71 
73  float alpha() const { return mAlpha; }
74 
76  float beta() const { return mBeta; }
77 
79  void setWarm( const QColor &warm ) { mWarm = warm; }
80 
82  void setCool( const QColor &cool ) { mCool = cool; }
83 
85  void setDiffuse( const QColor &diffuse ) { mDiffuse = diffuse; }
87  void setSpecular( const QColor &specular ) { mSpecular = specular; }
89  void setShininess( float shininess ) { mShininess = shininess; }
90 
92  void setAlpha( float alpha ) { mAlpha = alpha; }
93 
95  void setBeta( float beta ) { mBeta = beta; }
96 
97  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
98  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
99  QMap<QString, QString> toExportParameters() const override;
100 
101 #ifndef SIP_RUN
102  Qt3DRender::QMaterial *toMaterial( QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context ) const override;
103  void addParametersToEffect( Qt3DRender::QEffect *effect ) const override;
104 
105  QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const override;
106  int dataDefinedByteStride() const override;
107  void applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
108 
109 #endif
110 
111  // TODO c++20 - replace with = default
112  bool operator==( const QgsGoochMaterialSettings &other ) const
113  {
114  return mDiffuse == other.mDiffuse &&
115  mSpecular == other.mSpecular &&
116  mWarm == other.mWarm &&
117  mCool == other.mCool &&
118  mShininess == other.mShininess &&
119  mAlpha == other.mAlpha &&
120  mBeta == other.mBeta;
121  }
122 
123  private:
124  QColor mDiffuse{ QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) };
125  QColor mSpecular{ QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
126  QColor mWarm {QColor( 107, 0, 107 ) };
127  QColor mCool {QColor( 255, 130, 0 )};
128  float mShininess = 100.0f;
129  float mAlpha = 0.25f;
130  float mBeta = 0.5f;
131 
133  Qt3DRender::QMaterial *dataDefinedMaterial() const;
134 };
135 
136 
137 #endif // QGSGOOCHMATERIALSETTINGS_H
QgsGoochMaterialSettings::specular
QColor specular() const
Returns specular color component.
Definition: qgsgoochmaterialsettings.h:68
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsAbstractMaterialSettings::type
virtual QString type() const =0
Returns the unique type name for the material.
QgsAbstractMaterialSettings::applyDataDefinedToGeometry
virtual void applyDataDefinedToGeometry(Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes) const
Applies the data defined bytes, dataDefinedBytes, on the geometry by filling a specific vertex buffer...
Definition: qgsabstractmaterialsettings.cpp:54
QgsGoochMaterialSettings::setShininess
void setShininess(float shininess)
Sets shininess of the surface.
Definition: qgsgoochmaterialsettings.h:89
QgsGoochMaterialSettings::cool
QColor cool() const
Returns cool color component.
Definition: qgsgoochmaterialsettings.h:63
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsGoochMaterialSettings::setAlpha
void setAlpha(float alpha)
Sets alpha value.
Definition: qgsgoochmaterialsettings.h:92
QgsAbstractMaterialSettings::toExportParameters
virtual QMap< QString, QString > toExportParameters() const =0
Returns the parameters to be exported to .mtl file.
QgsGoochMaterialSettings::setCool
void setCool(const QColor &cool)
Sets cool color component.
Definition: qgsgoochmaterialsettings.h:82
QgsGoochMaterialSettings::setSpecular
void setSpecular(const QColor &specular)
Sets specular color component.
Definition: qgsgoochmaterialsettings.h:87
QgsGoochMaterialSettings::shininess
float shininess() const
Returns shininess of the surface.
Definition: qgsgoochmaterialsettings.h:70
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsAbstractMaterialSettings::dataDefinedVertexColorsAsByte
virtual QByteArray dataDefinedVertexColorsAsByte(const QgsExpressionContext &expressionContext) const
Returns byte array corresponding to the data defined colors depending of the expressionContext,...
Definition: qgsabstractmaterialsettings.cpp:48
QgsGoochMaterialSettings::setDiffuse
void setDiffuse(const QColor &diffuse)
Sets diffuse color component.
Definition: qgsgoochmaterialsettings.h:85
QgsMaterialContext
Context settings for a material.
Definition: qgsabstractmaterialsettings.h:64
qgsabstractmaterialsettings.h
QgsGoochMaterialSettings::beta
float beta() const
Returns the beta value.
Definition: qgsgoochmaterialsettings.h:76
QgsGoochMaterialSettings::operator==
bool operator==(const QgsGoochMaterialSettings &other) const
Definition: qgsgoochmaterialsettings.h:112
QgsAbstractMaterialSettings
Abstract base class for material settings.
Definition: qgsabstractmaterialsettings.h:114
QgsAbstractMaterialSettings::dataDefinedByteStride
virtual int dataDefinedByteStride() const
Returns byte stride of the data defined colors,used to fill the vertex colors data defined buffer for...
Definition: qgsabstractmaterialsettings.h:234
QgsGoochMaterialSettings::setBeta
void setBeta(float beta)
Sets beta value.
Definition: qgsgoochmaterialsettings.h:95
QgsAbstractMaterialSettings::addParametersToEffect
virtual void addParametersToEffect(Qt3DRender::QEffect *effect) const =0
Adds parameters from the material to a destination effect.
QgsAbstractMaterialSettings::writeXml
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
Definition: qgsabstractmaterialsettings.cpp:27
QgsMaterialSettingsRenderingTechnique
QgsMaterialSettingsRenderingTechnique
Material rendering techniques.
Definition: qgsabstractmaterialsettings.h:43
QgsGoochMaterialSettings::setWarm
void setWarm(const QColor &warm)
Sets warm color component.
Definition: qgsgoochmaterialsettings.h:79
QgsAbstractMaterialSettings::toMaterial
virtual Qt3DRender::QMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const =0
Creates a new QMaterial object representing the material settings.
QgsAbstractMaterialSettings::readXml
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
Definition: qgsabstractmaterialsettings.cpp:20
QgsGoochMaterialSettings
Basic shading material used for rendering based on the Phong shading model with three color component...
Definition: qgsgoochmaterialsettings.h:36
QgsGoochMaterialSettings::alpha
float alpha() const
Returns the alpha value.
Definition: qgsgoochmaterialsettings.h:73
QgsAbstractMaterialSettings::clone
virtual QgsAbstractMaterialSettings * clone() const =0
Clones the material settings.
QgsGoochMaterialSettings::diffuse
QColor diffuse() const
Returns diffuse color component.
Definition: qgsgoochmaterialsettings.h:66
QgsGoochMaterialSettings::warm
QColor warm() const
Returns warm color component.
Definition: qgsgoochmaterialsettings.h:60