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();
49 QgsMetalRoughMaterial *material =
new QgsMetalRoughMaterial(
nullptr );
50 material->setEnvironmentalLightingEnabled( !context.
isPreview() );
51 material->setObjectName( u
"metalRoughMaterial"_s );
52 applySettingsToMaterial( metalRoughSettings, material, context );
53 material->setDataDefinedEnabled(
75 QgsMetalRoughMaterial *material =
new QgsMetalRoughMaterial();
76 material->setEnvironmentalLightingEnabled(
true );
77 material->setInstancingEnabled(
true, flags );
78 material->setInstancingMeshTransform( transform );
80 material->setObjectName( u
"metalRoughMaterial"_s );
81 applySettingsToMaterial( metalRoughSettings, material, context );
88 QMap<QString, QString> parameters;
96 QgsMetalRoughMaterial *material = sceneRoot->findChild<QgsMetalRoughMaterial *>();
97 if ( material->objectName() !=
"metalRoughMaterial"_L1 )
100 applySettingsToMaterial( metalRoughSettings, material, context );
107 Q_ASSERT( metalRoughSettings );
114 array.resize(
sizeof(
float ) * 6 );
115 float *fptr =
reinterpret_cast<float *
>( array.data() );
117 *fptr++ = base.redF();
118 *fptr++ = base.greenF();
119 *fptr++ = base.blueF();
121 if ( emission.isValid() )
123 *fptr++ = emission.redF();
124 *fptr++ = emission.greenF();
125 *fptr++ = emission.blueF();
138 Qt3DCore::QBuffer *dataBuffer =
new Qt3DCore::QBuffer( geometry );
140 Qt3DCore::QAttribute *baseColorAttribute =
new Qt3DCore::QAttribute( geometry );
141 baseColorAttribute->setName( u
"dataDefinedBaseColor"_s );
142 baseColorAttribute->setVertexBaseType( Qt3DCore::QAttribute::Float );
143 baseColorAttribute->setVertexSize( 3 );
144 baseColorAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
145 baseColorAttribute->setBuffer( dataBuffer );
146 baseColorAttribute->setByteStride( 6 *
sizeof(
float ) );
147 baseColorAttribute->setByteOffset( 0 );
148 baseColorAttribute->setCount( vertexCount );
149 geometry->addAttribute( baseColorAttribute );
151 Qt3DCore::QAttribute *emissionColorAttribute =
new Qt3DCore::QAttribute( geometry );
152 emissionColorAttribute->setName( u
"dataDefinedEmissionColor"_s );
153 emissionColorAttribute->setVertexBaseType( Qt3DCore::QAttribute::Float );
154 emissionColorAttribute->setVertexSize( 3 );
155 emissionColorAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
156 emissionColorAttribute->setBuffer( dataBuffer );
157 emissionColorAttribute->setByteStride( 6 *
sizeof(
float ) );
158 emissionColorAttribute->setByteOffset( 3 *
sizeof(
float ) );
159 emissionColorAttribute->setCount( vertexCount );
160 geometry->addAttribute( emissionColorAttribute );
162 dataBuffer->setData( data );
168 material->setEmissionColor( metalRoughSettings->
emissionColor().isValid() ? metalRoughSettings->
emissionColor() : QColor( 0, 0, 0 ) );
169 material->setEmissionFactor(
static_cast< float>( metalRoughSettings->
emissionFactor() ) );
170 material->setClearCoatFactor(
static_cast< float >( metalRoughSettings->
clearCoatFactor() ) );
171 material->setClearCoatRoughness(
static_cast< float >( metalRoughSettings->
clearCoatRoughness() ) );
172 material->setMetalness(
static_cast< float >( metalRoughSettings->
metalness() ) );
173 material->setRoughness(
static_cast< float >( metalRoughSettings->
roughness() ) );
174 material->setReflectance(
static_cast< float >( metalRoughSettings->
reflectance() ) );
175 material->setAnisotropy(
static_cast< float >( metalRoughSettings->
anisotropy() ) );
176 material->setAnisotropyRotation(
static_cast< float >( metalRoughSettings->
anisotropyRotation() ) );
177 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.
bool isPreview() const
Returns true if the material is being shown in a preview widget.
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.