24#include <Qt3DCore/QAttribute>
25#include <Qt3DCore/QBuffer>
26#include <Qt3DCore/QGeometry>
28using namespace Qt::StringLiterals;
33 return QMap<QString, QString>();
47 return new QgsHighlightMaterial( technique );
50 return buildMaterial( settings, context );
68 Q_ASSERT( goochSettings );
76 array.resize(
sizeof(
unsigned char ) * 12 );
77 unsigned char *fptr =
reinterpret_cast<unsigned char *
>( array.data() );
79 *fptr++ =
static_cast<unsigned char>( diffuse.red() );
80 *fptr++ =
static_cast<unsigned char>( diffuse.green() );
81 *fptr++ =
static_cast<unsigned char>( diffuse.blue() );
83 *fptr++ =
static_cast<unsigned char>( warm.red() );
84 *fptr++ =
static_cast<unsigned char>( warm.green() );
85 *fptr++ =
static_cast<unsigned char>( warm.blue() );
87 *fptr++ =
static_cast<unsigned char>( cool.red() );
88 *fptr++ =
static_cast<unsigned char>( cool.green() );
89 *fptr++ =
static_cast<unsigned char>( cool.blue() );
91 *fptr++ =
static_cast<unsigned char>( specular.red() );
92 *fptr++ =
static_cast<unsigned char>( specular.green() );
93 *fptr++ =
static_cast<unsigned char>( specular.blue() );
100 return 12 *
sizeof(
unsigned char );
105 Qt3DCore::QBuffer *dataBuffer =
new Qt3DCore::QBuffer( geometry );
107 Qt3DCore::QAttribute *diffuseAttribute =
new Qt3DCore::QAttribute( geometry );
108 diffuseAttribute->setName( u
"dataDefinedDiffuseColor"_s );
109 diffuseAttribute->setVertexBaseType( Qt3DCore::QAttribute::UnsignedByte );
110 diffuseAttribute->setVertexSize( 3 );
111 diffuseAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
112 diffuseAttribute->setBuffer( dataBuffer );
113 diffuseAttribute->setByteStride( 12 *
sizeof(
unsigned char ) );
114 diffuseAttribute->setByteOffset( 0 );
115 diffuseAttribute->setCount( vertexCount );
116 geometry->addAttribute( diffuseAttribute );
118 Qt3DCore::QAttribute *warmAttribute =
new Qt3DCore::QAttribute( geometry );
119 warmAttribute->setName( u
"dataDefinedWarmColor"_s );
120 warmAttribute->setVertexBaseType( Qt3DCore::QAttribute::UnsignedByte );
121 warmAttribute->setVertexSize( 3 );
122 warmAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
123 warmAttribute->setBuffer( dataBuffer );
124 warmAttribute->setByteStride( 12 *
sizeof(
unsigned char ) );
125 warmAttribute->setByteOffset( 3 *
sizeof(
unsigned char ) );
126 warmAttribute->setCount( vertexCount );
127 geometry->addAttribute( warmAttribute );
129 Qt3DCore::QAttribute *coolAttribute =
new Qt3DCore::QAttribute( geometry );
130 coolAttribute->setName( u
"dataDefinedCoolColor"_s );
131 coolAttribute->setVertexBaseType( Qt3DCore::QAttribute::UnsignedByte );
132 coolAttribute->setVertexSize( 3 );
133 coolAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
134 coolAttribute->setBuffer( dataBuffer );
135 coolAttribute->setByteStride( 12 *
sizeof(
unsigned char ) );
136 coolAttribute->setByteOffset( 6 *
sizeof(
unsigned char ) );
137 coolAttribute->setCount( vertexCount );
138 geometry->addAttribute( coolAttribute );
140 Qt3DCore::QAttribute *specularAttribute =
new Qt3DCore::QAttribute( geometry );
141 specularAttribute->setName( u
"dataDefinedSpecularColor"_s );
142 specularAttribute->setVertexBaseType( Qt3DCore::QAttribute::UnsignedByte );
143 specularAttribute->setVertexSize( 3 );
144 specularAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
145 specularAttribute->setBuffer( dataBuffer );
146 specularAttribute->setByteStride( 12 *
sizeof(
unsigned char ) );
147 specularAttribute->setByteOffset( 9 *
sizeof(
unsigned char ) );
148 specularAttribute->setCount( vertexCount );
149 geometry->addAttribute( specularAttribute );
151 dataBuffer->setData( data );
158 QgsGoochMaterial *material = sceneRoot->findChild<QgsGoochMaterial *>();
159 if ( !material || material->objectName() !=
"goochMaterial"_L1 )
162 applySettingsToMaterial( goochSettings, material );
170 Q_ASSERT( goochSettings );
173 QgsGoochMaterial *material =
new QgsGoochMaterial;
174 material->setObjectName( u
"goochMaterial"_s );
176 applySettingsToMaterial( goochSettings, material );
184void QgsGoochMaterial3DHandler::applySettingsToMaterial(
const QgsGoochMaterialSettings *settings, QgsGoochMaterial *material )
186 material->setDiffuse( settings->
diffuse() );
187 material->setSpecular( settings->
specular() );
188 material->setCool( settings->
cool() );
189 material->setWarm( settings->
warm() );
190 material->setShininess(
static_cast<float>( settings->
shininess() ) );
191 material->setAlpha(
static_cast<float>( settings->
alpha() ) );
192 material->setBeta(
static_cast<float>( settings->
beta() ) );
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).
static QColor srgbToLinear(const QColor &color)
Converts a SRGB color to a linear color.
Abstract base class for material settings.
@ Warm
Warm color (gooch material).
@ Cool
Cool color (gooch material).
@ Specular
Specular color.
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...
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...
QgsMaterial * toMaterial(const QgsAbstractMaterialSettings *settings, Qgis::MaterialRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QgsMaterial object representing the material settings.
void addParametersToEffect(Qt3DRender::QEffect *effect, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &materialContext) const override
Adds parameters from the material settings to a destination effect.
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,...
int dataDefinedByteStride(const QgsAbstractMaterialSettings *settings) const override
Returns byte stride of the data defined colors,used to fill the vertex colors data defined buffer for...
Basic shading material used for rendering based on the Phong shading model with three color component...
QColor specular() const
Returns specular color component.
double alpha() const
Returns the alpha value.
QColor cool() const
Returns cool color component.
QColor warm() const
Returns warm color component.
QColor diffuse() const
Returns diffuse color component.
double beta() const
Returns the beta value.
double shininess() const
Returns shininess of the surface.
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 hasActiveProperties() const final
Returns true if the collection has any active properties, or false if all properties within the colle...