24#include <Qt3DCore/QAttribute>
25#include <Qt3DCore/QBuffer>
26#include <Qt3DCore/QEntity>
27#include <Qt3DCore/QGeometry>
28#include <Qt3DRender/QParameter>
30using namespace Qt::StringLiterals;
35 Q_ASSERT( metalRoughSettings );
46 return new QgsHighlightMaterial( technique );
49 QgsMetalRoughMaterial *material =
new QgsMetalRoughMaterial;
50 material->setObjectName( u
"metalRoughMaterial"_s );
51 applySettingsToMaterial( metalRoughSettings, material, context );
52 material->setDataDefinedEnabled(
72 QgsMetalRoughMaterial *material =
new QgsMetalRoughMaterial();
73 material->setInstancingEnabled(
true, flags );
75 material->setObjectName( u
"metalRoughMaterial"_s );
76 applySettingsToMaterial( metalRoughSettings, material, context );
83 QMap<QString, QString> parameters;
91 QgsMetalRoughMaterial *material = sceneRoot->findChild<QgsMetalRoughMaterial *>();
92 if ( material->objectName() !=
"metalRoughMaterial"_L1 )
95 applySettingsToMaterial( metalRoughSettings, material, context );
102 Q_ASSERT( metalRoughSettings );
109 array.resize(
sizeof(
float ) * 6 );
110 float *fptr =
reinterpret_cast<float *
>( array.data() );
112 *fptr++ = base.redF();
113 *fptr++ = base.greenF();
114 *fptr++ = base.blueF();
116 if ( emission.isValid() )
118 *fptr++ = emission.redF();
119 *fptr++ = emission.greenF();
120 *fptr++ = emission.blueF();
133 Qt3DCore::QBuffer *dataBuffer =
new Qt3DCore::QBuffer( geometry );
135 Qt3DCore::QAttribute *baseColorAttribute =
new Qt3DCore::QAttribute( geometry );
136 baseColorAttribute->setName( u
"dataDefinedBaseColor"_s );
137 baseColorAttribute->setVertexBaseType( Qt3DCore::QAttribute::Float );
138 baseColorAttribute->setVertexSize( 3 );
139 baseColorAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
140 baseColorAttribute->setBuffer( dataBuffer );
141 baseColorAttribute->setByteStride( 6 *
sizeof(
float ) );
142 baseColorAttribute->setByteOffset( 0 );
143 baseColorAttribute->setCount( vertexCount );
144 geometry->addAttribute( baseColorAttribute );
146 Qt3DCore::QAttribute *emissionColorAttribute =
new Qt3DCore::QAttribute( geometry );
147 emissionColorAttribute->setName( u
"dataDefinedEmissionColor"_s );
148 emissionColorAttribute->setVertexBaseType( Qt3DCore::QAttribute::Float );
149 emissionColorAttribute->setVertexSize( 3 );
150 emissionColorAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
151 emissionColorAttribute->setBuffer( dataBuffer );
152 emissionColorAttribute->setByteStride( 6 *
sizeof(
float ) );
153 emissionColorAttribute->setByteOffset( 3 *
sizeof(
float ) );
154 emissionColorAttribute->setCount( vertexCount );
155 geometry->addAttribute( emissionColorAttribute );
157 dataBuffer->setData( data );
163 material->setEmissionColor( metalRoughSettings->
emissionColor().isValid() ? metalRoughSettings->
emissionColor() : QColor( 0, 0, 0 ) );
164 material->setEmissionFactor(
static_cast< float>( metalRoughSettings->
emissionFactor() ) );
165 material->setMetalness(
static_cast< float >( metalRoughSettings->
metalness() ) );
166 material->setRoughness(
static_cast< float >( metalRoughSettings->
roughness() ) );
167 material->setOpacity(
static_cast< float >( metalRoughSettings->
opacity() ) );
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.
Abstract base class for material settings.
@ BaseColor
Base color (metal-rough material).
@ EmissionColor
Emission color (metal-rough material).
QgsPropertyCollection dataDefinedProperties() const
Returns the symbol material property collection, used for data defined overrides.
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
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.