QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
Loading...
Searching...
No Matches
qgsmaterial3dhandler.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaterial3dhandler.h
3 --------------------------------------
4 Date : March 2026
5 Copyright : (C) 2026 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 QGSMATERIAL3DHANDLER_H
17#define QGSMATERIAL3DHANDLER_H
18
19#include "qgis_3d.h"
20#include "qgis_sip.h"
21#include "qgsmaterial.h"
23
24#include <QColor>
25#include <QString>
26
27#define SIP_NO_FILE
28
29using namespace Qt::StringLiterals;
30
31class QDomElement;
33class QgsLineMaterial;
36
37namespace Qt3DCore
38{
39 class QGeometry;
40}
41namespace Qt3DExtras
42{
43 class Qt3DWindow;
44}
45
55class _3D_EXPORT QgsMaterialContext
56{
57 public:
63 bool isSelected() const { return mIsSelected; }
64
70 void setIsSelected( bool isSelected ) { mIsSelected = isSelected; }
71
77 QColor selectionColor() const { return mSelectedColor; }
78
84 void setSelectionColor( const QColor &color ) { mSelectedColor = color; }
85
92 bool isHighlighted() const { return mIsHighlighted; }
93
100 void setIsHighlighted( bool isHighlighted ) { mIsHighlighted = isHighlighted; }
101
102 private:
103 bool mIsSelected = false;
104 bool mIsHighlighted = false;
105
106 QColor mSelectedColor;
107};
108
109
119{
120 public:
121 virtual ~QgsAbstractMaterial3DHandler() = default;
122
130
134 virtual QMap<QString, QString> toExportParameters( const QgsAbstractMaterialSettings *settings ) const = 0;
135
139 virtual void addParametersToEffect( Qt3DRender::QEffect *effect, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &materialContext ) const = 0;
140
144 virtual void applyDataDefinedToGeometry( const QgsAbstractMaterialSettings *settings, Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const;
145
152 virtual QByteArray dataDefinedVertexColorsAsByte( const QgsAbstractMaterialSettings *settings, const QgsExpressionContext &expressionContext ) const;
153
158 virtual int dataDefinedByteStride( const QgsAbstractMaterialSettings *settings ) const;
159
164 {
166 QString type;
168 QString displayName;
169 };
170
174 virtual QList< PreviewMeshType > previewMeshTypes() const;
175
184 virtual Qt3DCore::QEntity *createPreviewMesh( const QString &type, Qt3DCore::QEntity *parent ) const;
185
195 virtual Qt3DCore::QEntity *createPreviewScene(
196 const QgsAbstractMaterialSettings *settings, const QString &type, const QgsMaterialContext &context, Qt3DExtras::Qt3DWindow *window, Qt3DCore::QEntity *parent
197 ) const;
198
208 virtual bool updatePreviewScene( Qt3DCore::QEntity *sceneRoot, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context ) const = 0;
209
210 protected:
217 static Qt3DRender::QParameter *findParameter( Qt3DRender::QEffect *effect, const QString &name );
218};
219
220
221#endif // QGSMATERIAL3DHANDLER_H
MaterialRenderingTechnique
Material rendering techniques.
Definition qgis.h:4327
Abstract base class for material 3D handlers.
virtual void addParametersToEffect(Qt3DRender::QEffect *effect, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &materialContext) const =0
Adds parameters from the material settings to a destination effect.
virtual ~QgsAbstractMaterial3DHandler()=default
static Qt3DRender::QParameter * findParameter(Qt3DRender::QEffect *effect, const QString &name)
Finds an existing parameter in an effect by name.
virtual int dataDefinedByteStride(const QgsAbstractMaterialSettings *settings) const
Returns byte stride of the data defined colors,used to fill the vertex colors data defined buffer for...
virtual void applyDataDefinedToGeometry(const QgsAbstractMaterialSettings *settings, Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes) const
Applies the data defined bytes, dataDefinedBytes, on the geometry by filling a specific vertex buffer...
virtual Qt3DCore::QEntity * createPreviewMesh(const QString &type, Qt3DCore::QEntity *parent) const
Creates a new entity representing a suitable preview mesh for this material type.
virtual bool updatePreviewScene(Qt3DCore::QEntity *sceneRoot, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context) const =0
Updates an existing material preview scene with new material settings.
virtual QgsMaterial * toMaterial(const QgsAbstractMaterialSettings *settings, Qgis::MaterialRenderingTechnique technique, const QgsMaterialContext &context) const =0
Creates a new QgsMaterial object representing the material settings.
virtual QList< PreviewMeshType > previewMeshTypes() const
Returns a list of available preview mesh types for the material.
virtual QMap< QString, QString > toExportParameters(const QgsAbstractMaterialSettings *settings) const =0
Returns the parameters to be exported to .mtl file.
virtual Qt3DCore::QEntity * createPreviewScene(const QgsAbstractMaterialSettings *settings, const QString &type, const QgsMaterialContext &context, Qt3DExtras::Qt3DWindow *window, Qt3DCore::QEntity *parent) const
Builds a complete self-contained scene for previewing the material, using the specified mesh type.
virtual QByteArray dataDefinedVertexColorsAsByte(const QgsAbstractMaterialSettings *settings, const QgsExpressionContext &expressionContext) const
Returns byte array corresponding to the data defined colors depending of the expressionContext,...
Abstract base class for 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.
bool isHighlighted() const
Returns true if the material should represent a highlighted state.
void setIsHighlighted(bool isHighlighted)
Sets whether the material should represent a highlighted state.
Base class for all materials used within QGIS 3D views.
Definition qgsmaterial.h:40
A container for the context for various read/write operations on objects.
#define SIP_ABSTRACT
Definition qgis_sip.h:220
#define SIP_FACTORY
Definition qgis_sip.h:83
Encapsulates information about available preview meshes.
QString displayName
Translated, user-friendly name.