25#include <Qt3DCore/QAttribute>
26#include <Qt3DCore/QBuffer>
27#include <Qt3DCore/QGeometry>
28#include <Qt3DRender/QEffect>
29#include <Qt3DRender/QGraphicsApiFilter>
30#include <Qt3DRender/QParameter>
31#include <Qt3DRender/QTechnique>
33using namespace Qt::StringLiterals;
57 Q_ASSERT( unlitSettings );
59 auto material =
new QgsUnlitMaterial();
60 material->setObjectName( u
"unlitMaterial"_s );
67 material->setColor( color );
69 material->setDataDefinedEnabled( dataDefined );
88 Q_ASSERT( unlitSettings );
93 array.resize(
sizeof(
float ) * 3 );
94 float *fptr =
reinterpret_cast<float *
>( array.data() );
96 *fptr++ = color.redF();
97 *fptr++ = color.greenF();
98 *fptr++ = color.blueF();
105 Qt3DCore::QBuffer *dataBuffer =
new Qt3DCore::QBuffer( geometry );
107 Qt3DCore::QAttribute *baseColorAttribute =
new Qt3DCore::QAttribute( geometry );
108 baseColorAttribute->setName( u
"dataDefinedBaseColor"_s );
109 baseColorAttribute->setVertexBaseType( Qt3DCore::QAttribute::Float );
110 baseColorAttribute->setVertexSize( 3 );
111 baseColorAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
112 baseColorAttribute->setBuffer( dataBuffer );
113 baseColorAttribute->setByteStride( 3 *
sizeof(
float ) );
114 baseColorAttribute->setByteOffset( 0 );
115 baseColorAttribute->setCount( vertexCount );
116 geometry->addAttribute( baseColorAttribute );
118 dataBuffer->setData( data );
123 auto unlitSettings = qgis::down_cast< const QgsUnlitMaterialSettings * >( settings );
125 QgsUnlitMaterial *material = sceneRoot->findChild<QgsUnlitMaterial *>();
126 if ( !material || material->objectName() !=
"unlitMaterial"_L1 )
129 material->setColor( unlitSettings->color() );
138 auto unlitSettings = qgis::down_cast< const QgsUnlitMaterialSettings * >( settings );
140 auto material =
new QgsUnlitMaterial();
141 material->setInstancingEnabled(
true, flags );
142 material->setInstancingMeshTransform( transform );
143 material->setObjectName( u
"unlitMaterial"_s );
146 material->setColor( color );
MaterialRenderingTechnique
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.
@ Billboards
Flat billboard rendering.
@ 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).
QFlags< InstancedMaterialFlag > InstancedMaterialFlags
static QColor srgbToLinear(const QColor &color)
Converts a SRGB color to a linear color.
static QgsUnlitMaterial * createHighlightMaterial()
Creates a new highlight material, consisting of an unlit material respecting the user's map highlight...
Abstract base class for material settings.
@ BaseColor
Base color (metal-rough material).
QgsPropertyCollection dataDefinedProperties() const
Returns the symbol material property collection, used for data defined overrides.
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.
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.
Base class for all materials used within QGIS 3D views.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
QgsMaterial * toInstancedMaterial(const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context, Qgis::InstancedMaterialFlags flags, const QMatrix4x4 &transform=QMatrix4x4()) const override
Creates a QgsMaterial for instanced point rendering.
QMap< QString, QString > toExportParameters(const QgsAbstractMaterialSettings *settings) const override
Returns the parameters to be exported to .mtl file.
void applyDataDefinedToGeometry(const QgsAbstractMaterialSettings *settings, Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &data) const override
Applies the data defined bytes, dataDefinedBytes, on the geometry by filling a specific vertex buffer...
bool updatePreviewScene(Qt3DCore::QEntity *sceneRoot, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context) const override
Updates an existing material preview scene with new material settings.
QByteArray dataDefinedVertexColorsAsByte(const QgsAbstractMaterialSettings *settings, const QgsExpressionContext &expressionContext) const override
Returns byte array corresponding to the data defined colors depending of the expressionContext,...
QgsMaterial * toMaterial(const QgsAbstractMaterialSettings *settings, Qgis::MaterialRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QgsMaterial object representing the material settings.
Basic shading material used for rendering solid color, unlit objects.
QColor color() const
Returns the material color.