/
qgsphongmaterialsettings.h
134 lines (108 loc) · 4.62 KB
/
qgsphongmaterialsettings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/***************************************************************************
qgsphongmaterialsettings.h
--------------------------------------
Date : July 2017
Copyright : (C) 2017 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPHONGMATERIALSETTINGS_H
#define QGSPHONGMATERIALSETTINGS_H
#include "qgis_3d.h"
#include "qgsabstractmaterialsettings.h"
#include "qgspropertycollection.h"
#include <QColor>
#ifndef SIP_RUN
namespace Qt3DRender
{
class QGeometry;
}
#endif //SIP_RUN
class QDomElement;
/**
* \ingroup 3d
* \brief Basic shading material used for rendering based on the Phong shading model
* with three color components: ambient, diffuse and specular.
*
* \warning This is not considered stable API, and may change in future QGIS releases. It is
* exposed to the Python bindings as a tech preview only.
*
* \since QGIS 3.0
*/
class _3D_EXPORT QgsPhongMaterialSettings : public QgsAbstractMaterialSettings
{
public:
/**
* Constructor for QgsPhongMaterialSettings.
*/
QgsPhongMaterialSettings() = default;
QString type() const override;
/**
* Returns TRUE if the specified \a technique is supported by the Phong material.
*/
static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );
/**
* Returns a new instance of QgsPhongMaterialSettings.
*/
static QgsAbstractMaterialSettings *create() SIP_FACTORY;
QgsPhongMaterialSettings *clone() const override SIP_FACTORY;
//! Returns ambient color component
QColor ambient() const { return mAmbient; }
//! Returns diffuse color component
QColor diffuse() const { return mDiffuse; }
//! Returns specular color component
QColor specular() const { return mSpecular; }
//! Returns shininess of the surface
float shininess() const { return mShininess; }
/**
* Returns the opacity of the surface
* \since QGIS 3.26
*/
float opacity() const { return mOpacity; }
QMap<QString, QString> toExportParameters() const override;
//! Sets ambient color component
void setAmbient( const QColor &ambient ) { mAmbient = ambient; }
//! Sets diffuse color component
void setDiffuse( const QColor &diffuse ) { mDiffuse = diffuse; }
//! Sets specular color component
void setSpecular( const QColor &specular ) { mSpecular = specular; }
//! Sets shininess of the surface
void setShininess( float shininess ) { mShininess = shininess; }
/**
* Sets shininess of the surface
* \since QGIS 3.26
*/
void setOpacity( float opacity ) { mOpacity = opacity; }
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
#ifndef SIP_RUN
Qt3DRender::QMaterial *toMaterial( QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context ) const override SIP_FACTORY;
void addParametersToEffect( Qt3DRender::QEffect *effect ) const override;
QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const override;
int dataDefinedByteStride() const override;
void applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &data ) const override;
#endif
// TODO c++20 - replace with = default
bool operator==( const QgsPhongMaterialSettings &other ) const
{
return mAmbient == other.mAmbient &&
mDiffuse == other.mDiffuse &&
mSpecular == other.mSpecular &&
mShininess == other.mShininess;
}
private:
QColor mAmbient{ QColor::fromRgbF( 0.1f, 0.1f, 0.1f, 1.0f ) };
QColor mDiffuse{ QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) };
QColor mSpecular{ QColor::fromRgbF( 1.0f, 1.0f, 1.0f, 1.0f ) };
float mShininess = 0.0f;
float mOpacity = 1.0f;
//! Constructs a material from shader files
Qt3DRender::QMaterial *dataDefinedMaterial() const;
};
#endif // QGSPHONGMATERIALSETTINGS_H