QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsabstractmaterialsettings.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsabstractmaterialsettings.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 QGSABSTRACTMATERIALSETTINGS_H
17#define QGSABSTRACTMATERIALSETTINGS_H
18
19#include "qgis_3d.h"
20#include "qgis_sip.h"
21#include "qgsmaterial.h"
23
24#include <QColor>
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
29class QDomElement;
31class QgsLineMaterial;
33
34#ifndef SIP_RUN
35namespace Qt3DCore
36{
37 class QGeometry;
38}
39#endif //SIP_RUN
40
56
57
67class _3D_EXPORT QgsMaterialContext
68{
69 public:
75 bool isSelected() const { return mIsSelected; }
76
82 void setIsSelected( bool isSelected ) { mIsSelected = isSelected; }
83
89 QColor selectionColor() const { return mSelectedColor; }
90
96 void setSelectionColor( const QColor &color ) { mSelectedColor = color; }
97
98 private:
99 bool mIsSelected = false;
100
101 QColor mSelectedColor;
102};
103
104
114{
115#ifdef SIP_RUN
117 if ( sipCpp->type() == "gooch"_L1 )
118 {
119 sipType = sipType_QgsGoochMaterialSettings;
120 }
121 else if ( sipCpp->type() == "phong"_L1 )
122 {
123 sipType = sipType_QgsPhongMaterialSettings;
124 }
125 else if ( sipCpp->type() == "phongtextured" )
126 {
127 sipType = sipType_QgsPhongTexturedMaterialSettings;
128 }
129 else if ( sipCpp->type() == "simpleline" )
130 {
131 sipType = sipType_QgsSimpleLineMaterialSettings;
132 }
133 else if ( sipCpp->type() == "null" )
134 {
135 sipType = sipType_QgsNullMaterialSettings;
136 }
137 else
138 {
139 sipType = 0;
140 }
141 SIP_END
142#endif
143
144 public:
145 virtual ~QgsAbstractMaterialSettings() = default;
146
150 virtual QString type() const = 0;
151
158
160 virtual void readXml( const QDomElement &element, const QgsReadWriteContext & );
161
163 virtual void writeXml( QDomElement &element, const QgsReadWriteContext & ) const;
164
170 virtual bool equals( const QgsAbstractMaterialSettings *other ) const = 0;
171
172#ifndef SIP_RUN
173
181
185 virtual QMap<QString, QString> toExportParameters() const = 0;
186
190 virtual void addParametersToEffect( Qt3DRender::QEffect *effect, const QgsMaterialContext &materialContext ) const = 0;
191
192 // *INDENT-OFF*
195 {
196 Diffuse,
197 Ambient,
198 Warm,
199 Cool,
200 Specular
201 };
202 // *INDENT-ON*
203
208 void setDataDefinedProperties( const QgsPropertyCollection &collection );
209
214 QgsPropertyCollection dataDefinedProperties() const;
215
220 const QgsPropertiesDefinition &propertyDefinitions() const;
221
226 virtual void applyDataDefinedToGeometry( Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const;
227
234 virtual QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const;
235
240 virtual int dataDefinedByteStride() const { return 0; }
241#endif
242
243 private:
244 QgsPropertyCollection mDataDefinedProperties;
245 static QgsPropertiesDefinition sPropertyDefinitions;
246 void initPropertyDefinitions() const;
247};
248
249
250#endif // QGSABSTRACTMATERIALSETTINGS_H
Abstract base class for material settings.
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
virtual bool equals(const QgsAbstractMaterialSettings *other) const =0
Returns true if this settings exactly matches an other settings.
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 QgsAbstractMaterialSettings * clone() const =0
Clones the material settings.
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 ~QgsAbstractMaterialSettings()=default
virtual QString type() const =0
Returns the unique type name for the material.
virtual QgsMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const =0
Creates a new QgsMaterial object representing the material settings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Context settings for a material.
QColor selectionColor() const
Returns the color for representing materials in a selected state.
void setIsSelected(bool isSelected)
Sets whether the material should represent a selected state.
void setSelectionColor(const QColor &color)
Sets the color for representing materials in a selected state.
bool isSelected() const
Returns true if the material should represent a selected state.
Base class for all materials used within QGIS 3D views.
Definition qgsmaterial.h:39
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
A container for the context for various read/write operations on objects.
QgsMaterialSettingsRenderingTechnique
Material rendering techniques.
@ Points
Point based rendering, requires point data.
@ Triangles
Triangle based rendering (default).
@ TrianglesFromModel
Triangle based rendering, using a model object source.
@ Lines
Line based rendering, requires line data.
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering).
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:268
#define SIP_ABSTRACT
Definition qgis_sip.h:221
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.