QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
22 #include <QColor>
23 #include <Qt3DRender/qmaterial.h>
24 #include "qgspropertycollection.h"
25 
26 class QDomElement;
28 class QgsLineMaterial;
30 
31 #ifndef SIP_RUN
32 namespace Qt3DRender
33 {
34  class QGeometry;
35 }
36 #endif //SIP_RUN
37 
44  {
45  Triangles,
46  Lines,
48  Points,
52 };
53 
54 
64 class _3D_EXPORT QgsMaterialContext
65 {
66  public:
67 
73  bool isSelected() const { return mIsSelected; }
74 
80  void setIsSelected( bool isSelected ) { mIsSelected = isSelected; }
81 
87  QColor selectionColor() const { return mSelectedColor; }
88 
94  void setSelectionColor( const QColor &color ) { mSelectedColor = color; }
95 
96  private:
97 
98  bool mIsSelected = false;
99 
100  QColor mSelectedColor;
101 
102 };
103 
104 
115 {
116 
117 #ifdef SIP_RUN
119  if ( sipCpp->type() == QLatin1String( "gooch" ) )
120  {
121  sipType = sipType_QgsGoochMaterialSettings;
122  }
123  else if ( sipCpp->type() == QLatin1String( "phong" ) )
124  {
125  sipType = sipType_QgsPhongMaterialSettings;
126  }
127  else if ( sipCpp->type() == "phongtextured" )
128  {
129  sipType = sipType_QgsPhongTexturedMaterialSettings;
130  }
131  else if ( sipCpp->type() == "simpleline" )
132  {
133  sipType = sipType_QgsSimpleLineMaterialSettings;
134  }
135  else if ( sipCpp->type() == "null" )
136  {
137  sipType = sipType_QgsNullMaterialSettings;
138  }
139  else
140  {
141  sipType = 0;
142  }
143  SIP_END
144 #endif
145 
146  public:
147 
148  virtual ~QgsAbstractMaterialSettings() = default;
149 
153  virtual QString type() const = 0;
154 
161 
163  virtual void readXml( const QDomElement &element, const QgsReadWriteContext & );
164 
166  virtual void writeXml( QDomElement &element, const QgsReadWriteContext & ) const;
167 
168 #ifndef SIP_RUN
169 
176  virtual Qt3DRender::QMaterial *toMaterial( QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context ) const = 0 SIP_FACTORY;
177 
181  virtual QMap<QString, QString> toExportParameters() const = 0;
182 
186  virtual void addParametersToEffect( Qt3DRender::QEffect *effect ) const = 0;
187 
189  enum Property
190  {
195  Specular
196  };
197 
202  void setDataDefinedProperties( const QgsPropertyCollection &collection );
203 
208  QgsPropertyCollection dataDefinedProperties() const;
209 
214  const QgsPropertiesDefinition &propertyDefinitions() const;
215 
220  virtual void applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const;
221 
228  virtual QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const;
229 
234  virtual int dataDefinedByteStride() const {return 0;}
235 #endif
236 
237  private:
238  QgsPropertyCollection mDataDefinedProperties;
239  static QgsPropertiesDefinition sPropertyDefinitions;
240  void initPropertyDefinitions() const;
241 };
242 
243 
244 #endif // QGSABSTRACTMATERIALSETTINGS_H
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 ~QgsAbstractMaterialSettings()=default
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 QgsAbstractMaterialSettings * clone() const =0
Clones the material settings.
@ Ambient
Ambient color (phong material)
@ Warm
Warm color (gooch material)
@ Cool
Cool color (gooch material)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
The class is used as a container of context for various read/write operations on other objects.
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
@ 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:177
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition: qgis_sip.h:257
#define SIP_ABSTRACT
Definition: qgis_sip.h:199
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:194
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.