QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsgoochmaterialsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgoochmaterialsettings.cpp
3  --------------------------------------
4  Date : July 2020
5  Copyright : (C) 2020 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 
18 #include "qgssymbollayerutils.h"
19 #include "qgslinematerial_p.h"
20 #include <Qt3DExtras/QGoochMaterial>
21 
23 {
24  return QStringLiteral( "gooch" );
25 }
26 
28 {
29  return new QgsGoochMaterialSettings();
30 }
31 
33 {
34  switch ( technique )
35  {
36  case QgsMaterialSettingsRenderingTechnique::Triangles:
38  return true;
39 
40  case QgsMaterialSettingsRenderingTechnique::Lines:
41  case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
43  return false;
44  }
45  return false;
46 }
47 
49 {
50  return new QgsGoochMaterialSettings( *this );
51 }
52 
53 void QgsGoochMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext & )
54 {
55  mWarm = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "warm" ), QStringLiteral( "107,0,107" ) ) );
56  mCool = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "cool" ), QStringLiteral( "255,130,0" ) ) );
57  mDiffuse = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "diffuse" ), QStringLiteral( "178,178,178" ) ) );
58  mSpecular = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "specular" ) ) );
59  mShininess = elem.attribute( QStringLiteral( "shininess2" ), QStringLiteral( "100" ) ).toFloat();
60  mAlpha = elem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "0.25" ) ).toFloat();
61  mBeta = elem.attribute( QStringLiteral( "beta" ), QStringLiteral( "0.5" ) ).toFloat();
62 }
63 
64 void QgsGoochMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext & ) const
65 {
66  elem.setAttribute( QStringLiteral( "warm" ), QgsSymbolLayerUtils::encodeColor( mWarm ) );
67  elem.setAttribute( QStringLiteral( "cool" ), QgsSymbolLayerUtils::encodeColor( mCool ) );
68  elem.setAttribute( QStringLiteral( "diffuse" ), QgsSymbolLayerUtils::encodeColor( mDiffuse ) );
69  elem.setAttribute( QStringLiteral( "specular" ), QgsSymbolLayerUtils::encodeColor( mSpecular ) );
70  elem.setAttribute( QStringLiteral( "shininess2" ), mShininess );
71  elem.setAttribute( QStringLiteral( "alpha" ), mAlpha );
72  elem.setAttribute( QStringLiteral( "beta" ), mBeta );
73 }
74 
75 QMap<QString, QString> QgsGoochMaterialSettings::toExportParameters() const
76 {
77  return QMap<QString, QString>();
78 }
79 
81 {
82  switch ( technique )
83  {
84  case QgsMaterialSettingsRenderingTechnique::Triangles:
86  {
87  Qt3DExtras::QGoochMaterial *material = new Qt3DExtras::QGoochMaterial;
88  material->setDiffuse( mDiffuse );
89  material->setWarm( mWarm );
90  material->setCool( mCool );
91 
92  material->setSpecular( mSpecular );
93  material->setShininess( mShininess );
94  material->setAlpha( mAlpha );
95  material->setBeta( mBeta );
96 
97  if ( context.isSelected() )
98  {
99  // update the material with selection colors
100  material->setDiffuse( context.selectionColor() );
101  }
102  return material;
103  }
104 
105  case QgsMaterialSettingsRenderingTechnique::Lines:
106  case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
108  return nullptr;
109  }
110  return nullptr;
111 }
112 
113 void QgsGoochMaterialSettings::addParametersToEffect( Qt3DRender::QEffect * ) const
114 {
115 }
QgsGoochMaterialSettings::toMaterial
Qt3DRender::QMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QMaterial object representing the material settings.
Definition: qgsgoochmaterialsettings.cpp:80
qgsgoochmaterialsettings.h
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:52
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
qgssymbollayerutils.h
QgsGoochMaterialSettings::toExportParameters
QMap< QString, QString > toExportParameters() const override
Returns the parameters to be exported to .mtl file.
Definition: qgsgoochmaterialsettings.cpp:75
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsMaterialContext::selectionColor
QColor selectionColor() const
Returns the color for representing materials in a selected state.
Definition: qgsabstractmaterialsettings.h:77
QgsMaterialContext
3 Context settings for a material.
Definition: qgsabstractmaterialsettings.h:55
qgslinematerial_p.h
QgsGoochMaterialSettings::type
QString type() const override
Returns the unique type name for the material.
Definition: qgsgoochmaterialsettings.cpp:22
QgsGoochMaterialSettings::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
Definition: qgsgoochmaterialsettings.cpp:53
QgsAbstractMaterialSettings
3 Abstract base class for material settings.
Definition: qgsabstractmaterialsettings.h:105
QgsGoochMaterialSettings::QgsGoochMaterialSettings
QgsGoochMaterialSettings()=default
Constructor for QgsGoochMaterialSettings.
QgsMaterialSettingsRenderingTechnique::Triangles
@ Triangles
Triangle based rendering (default)
QgsMaterialSettingsRenderingTechnique
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
Definition: qgsabstractmaterialsettings.h:36
QgsGoochMaterialSettings::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
Definition: qgsgoochmaterialsettings.cpp:64
QgsGoochMaterialSettings::addParametersToEffect
void addParametersToEffect(Qt3DRender::QEffect *effect) const override
Adds parameters from the material to a destination effect.
Definition: qgsgoochmaterialsettings.cpp:113
QgsGoochMaterialSettings::create
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsGoochMaterialSettings.
Definition: qgsgoochmaterialsettings.cpp:27
QgsGoochMaterialSettings::supportsTechnique
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the Gooch material.
Definition: qgsgoochmaterialsettings.cpp:32
QgsGoochMaterialSettings::clone
QgsGoochMaterialSettings * clone() const override
Clones the material settings.
Definition: qgsgoochmaterialsettings.cpp:48
QgsGoochMaterialSettings
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
Definition: qgsgoochmaterialsettings.h:37
QgsMaterialSettingsRenderingTechnique::Points
@ Points
Point based rendering, requires point data.
QgsMaterialContext::isSelected
bool isSelected() const
Returns true if the material should represent a selected state.
Definition: qgsabstractmaterialsettings.h:63