QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
Loading...
Searching...
No Matches
qgsmetalroughmaterial3dhandler.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmetalroughmaterial3dhandler.cpp
3 --------------------------------------
4 Date : December 2023
5 Copyright : (C) 2023 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
17
21
22#include <QString>
23#include <Qt3DCore/QEntity>
24#include <Qt3DRender/QParameter>
25
26using namespace Qt::StringLiterals;
27
29{
30 const QgsMetalRoughMaterialSettings *metalRoughSettings = dynamic_cast< const QgsMetalRoughMaterialSettings * >( settings );
31 Q_ASSERT( metalRoughSettings );
32
33 switch ( technique )
34 {
39 {
40 if ( context.isHighlighted() )
41 {
42 return new QgsHighlightMaterial( technique );
43 }
44
45 QgsMetalRoughMaterial *material = new QgsMetalRoughMaterial;
46 material->setObjectName( u"metalRoughMaterial"_s );
47 material->setBaseColor( context.isSelected() ? context.selectionColor() : metalRoughSettings->baseColor() );
48 material->setMetalness( std::clamp( metalRoughSettings->metalness(), 0.0, 1.0 ) );
49 material->setRoughness( std::clamp( metalRoughSettings->roughness(), 0.0, 1.0 ) );
50 return material;
51 }
52
57 return nullptr;
58 }
59 return nullptr;
60}
61
63{
64 QMap<QString, QString> parameters;
65 return parameters;
66}
67
70
71bool QgsMetalRoughMaterial3DHandler::updatePreviewScene( Qt3DCore::QEntity *sceneRoot, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext & ) const
72{
73 const QgsMetalRoughMaterialSettings *metalRoughSettings = qgis::down_cast< const QgsMetalRoughMaterialSettings * >( settings );
74
75 QgsMaterial *material = sceneRoot->findChild<QgsMaterial *>();
76 if ( material->objectName() != "metalRoughMaterial"_L1 )
77 return false;
78
79 Qt3DRender::QEffect *effect = material->effect();
80
81 if ( Qt3DRender::QParameter *p = findParameter( effect, u"baseColor"_s ) )
82 p->setValue( metalRoughSettings->baseColor() );
83 if ( Qt3DRender::QParameter *p = findParameter( effect, u"metalness"_s ) )
84 p->setValue( metalRoughSettings->metalness() );
85 if ( Qt3DRender::QParameter *p = findParameter( effect, u"roughness"_s ) )
86 p->setValue( metalRoughSettings->roughness() );
87 return true;
88}
MaterialRenderingTechnique
Material rendering techniques.
Definition qgis.h:4327
@ Points
Point based rendering, requires point data.
Definition qgis.h:4331
@ Triangles
Triangle based rendering (default).
Definition qgis.h:4328
@ TrianglesFromModel
Triangle based rendering, using a model object source.
Definition qgis.h:4333
@ Lines
Line based rendering, requires line data.
Definition qgis.h:4329
@ Billboards
Flat billboard rendering.
Definition qgis.h:4335
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
Definition qgis.h:4334
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
Definition qgis.h:4330
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering).
Definition qgis.h:4332
static Qt3DRender::QParameter * findParameter(Qt3DRender::QEffect *effect, const QString &name)
Finds an existing parameter in an effect by name.
Abstract base class for material settings.
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.
Definition qgsmaterial.h:40
bool updatePreviewScene(Qt3DCore::QEntity *sceneRoot, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context) const override
Updates an existing material preview scene with new material settings.
QMap< QString, QString > toExportParameters(const QgsAbstractMaterialSettings *settings) const override
Returns the parameters to be exported to .mtl file.
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.
A PBR metal rough shading material used for rendering.
double roughness() const
Returns the material's roughness, as a value between 0 and 1.
double metalness() const
Returns the material's metalness, as a value between 0 and 1.
QColor baseColor() const
Returns the base material color.