QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 "qgspropertycollection.h"
22 
23 #include <QColor>
24 
25 #ifndef SIP_RUN
26 namespace Qt3DRender
27 {
28  class QGeometry;
29 }
30 #endif //SIP_RUN
31 
32 class QDomElement;
33 
45 {
46  public:
47 
52 
53  QString type() const override;
54 
58  static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );
59 
64 
65  QgsPhongMaterialSettings *clone() const override SIP_FACTORY;
66 
68  QColor ambient() const { return mAmbient; }
70  QColor diffuse() const { return mDiffuse; }
72  QColor specular() const { return mSpecular; }
74  float shininess() const { return mShininess; }
75 
76  QMap<QString, QString> toExportParameters() const override;
77 
79  void setAmbient( const QColor &ambient ) { mAmbient = ambient; }
81  void setDiffuse( const QColor &diffuse ) { mDiffuse = diffuse; }
83  void setSpecular( const QColor &specular ) { mSpecular = specular; }
85  void setShininess( float shininess ) { mShininess = shininess; }
86 
87  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
88  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
89 
90 #ifndef SIP_RUN
91  Qt3DRender::QMaterial *toMaterial( QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context ) const override SIP_FACTORY;
92  void addParametersToEffect( Qt3DRender::QEffect *effect ) const override;
93 
94  QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const override;
95  int dataDefinedByteStride() const override;
96  void applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
97 #endif
98 
99  bool operator==( const QgsPhongMaterialSettings &other ) const
100  {
101  return mAmbient == other.mAmbient &&
102  mDiffuse == other.mDiffuse &&
103  mSpecular == other.mSpecular &&
104  mShininess == other.mShininess;
105  }
106 
107  private:
108  QColor mAmbient{ QColor::fromRgbF( 0.1f, 0.1f, 0.1f, 1.0f ) };
109  QColor mDiffuse{ QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) };
110  QColor mSpecular{ QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
111  float mShininess = 0.0f;
112 
114  Qt3DRender::QMaterial *dataDefinedMaterial() const;
115 };
116 
117 
118 #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 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 QString type() const =0
Returns the unique type name for the material.
virtual QMap< QString, QString > toExportParameters() const =0
Returns the parameters to be exported to .mtl file.
virtual void addParametersToEffect(Qt3DRender::QEffect *effect) const =0
Adds parameters from the material to a destination effect.
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...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool operator==(const QgsPhongMaterialSettings &other) const
void setDiffuse(const QColor &diffuse)
Sets diffuse color component.
QColor diffuse() const
Returns diffuse color component.
QColor specular() const
Returns specular color component.
void setAmbient(const QColor &ambient)
Sets ambient color component.
float shininess() const
Returns shininess of the surface.
QgsPhongMaterialSettings()=default
Constructor for QgsPhongMaterialSettings.
void setShininess(float shininess)
Sets shininess of the surface.
void setSpecular(const QColor &specular)
Sets specular color component.
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