QGIS API Documentation 4.1.0-Master (64dc32379c2)
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;
37
38namespace Qt3DCore
39{
40 class QGeometry;
41}
42
43
53class _3D_EXPORT QgsMaterialContext
54{
55 public:
62
68 bool isSelected() const { return mIsSelected; }
69
75 void setIsSelected( bool isSelected ) { mIsSelected = isSelected; }
76
82 QColor selectionColor() const { return mSelectedColor; }
83
89 void setSelectionColor( const QColor &color ) { mSelectedColor = color; }
90
97 bool isHighlighted() const { return mIsHighlighted; }
98
105 void setIsHighlighted( bool isHighlighted ) { mIsHighlighted = isHighlighted; }
106
113 Qgis::TextureFilterQuality textureFilterQuality() const { return mTextureFilterQuality; }
114
121 void setTextureFilterQuality( Qgis::TextureFilterQuality quality ) { mTextureFilterQuality = quality; }
122
123 private:
124 bool mIsSelected = false;
125 bool mIsHighlighted = false;
126
127 QColor mSelectedColor;
129};
130
131
141{
142 public:
143 virtual ~QgsAbstractMaterial3DHandler() = default;
144
152
156 virtual QMap<QString, QString> toExportParameters( const QgsAbstractMaterialSettings *settings ) const = 0;
157
161 virtual void addParametersToEffect( Qt3DRender::QEffect *effect, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &materialContext ) const = 0;
162
166 virtual void applyDataDefinedToGeometry( const QgsAbstractMaterialSettings *settings, Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const;
167
174 virtual QByteArray dataDefinedVertexColorsAsByte( const QgsAbstractMaterialSettings *settings, const QgsExpressionContext &expressionContext ) const;
175
180 virtual int dataDefinedByteStride( const QgsAbstractMaterialSettings *settings ) const;
181
186 {
188 QString type;
190 QString displayName;
191 };
192
196 virtual QList< PreviewMeshType > previewMeshTypes() const;
197
206 virtual Qt3DCore::QEntity *createPreviewMesh( const QString &type, Qt3DCore::QEntity *parent ) const;
207
217 virtual Qt3DCore::QEntity *createPreviewScene( const QgsAbstractMaterialSettings *settings, const QString &type, const QgsMaterialContext &context, QWindow *window, Qt3DCore::QEntity *parent ) const;
218
228 virtual bool updatePreviewScene( Qt3DCore::QEntity *sceneRoot, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context ) const = 0;
229
230 protected:
237 static Qt3DRender::QParameter *findParameter( Qt3DRender::QEffect *effect, const QString &name );
238};
239
240
241#endif // QGSMATERIAL3DHANDLER_H
TextureFilterQuality
Texture filtering qualities.
Definition qgis.h:4360
@ Trilinear
Trilinear (LinearMipmapLinear).
Definition qgis.h:4361
MaterialRenderingTechnique
Material rendering techniques.
Definition qgis.h:4342
Rendering context for preparation of 3D entities.
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 Qt3DCore::QEntity * createPreviewScene(const QgsAbstractMaterialSettings *settings, const QString &type, const QgsMaterialContext &context, QWindow *window, Qt3DCore::QEntity *parent) const
Builds a complete self-contained scene for previewing the material, using the specified mesh type.
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 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.
void setTextureFilterQuality(Qgis::TextureFilterQuality quality)
Sets the texture filtering quality.
Qgis::TextureFilterQuality textureFilterQuality() const
Returns the texture filtering quality.
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.
static QgsMaterialContext fromRenderContext(const Qgs3DRenderContext &context)
Constructs a material context from the settings in a 3D render context.
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.