27#include <Qt3DRender/QEffect>
28#include <Qt3DRender/QGraphicsApiFilter>
29#include <Qt3DRender/QPaintedTextureImage>
30#include <Qt3DRender/QParameter>
31#include <Qt3DRender/QTechnique>
32#include <Qt3DRender/QTexture>
34using namespace Qt::StringLiterals;
38 return u
"phongtextured"_s;
75 return *
this == *otherPhong;
80 return mTextureRotation;
87 mShininess = elem.attribute( u
"shininess"_s ).toDouble();
88 mOpacity = elem.attribute( u
"opacity"_s, u
"1.0"_s ).toDouble();
89 mDiffuseTexturePath = elem.attribute( u
"diffuse_texture_path"_s, QString() );
90 mTextureScale = elem.attribute( u
"texture_scale"_s, QString(
"1.0" ) ).toDouble();
91 mTextureRotation = elem.attribute( u
"texture-rotation"_s, QString(
"0.0" ) ).toDouble();
100 elem.setAttribute( u
"shininess"_s, mShininess );
101 elem.setAttribute( u
"opacity"_s, mOpacity );
102 elem.setAttribute( u
"diffuse_texture_path"_s, mDiffuseTexturePath );
103 elem.setAttribute( u
"texture_scale"_s, mTextureScale );
104 elem.setAttribute( u
"texture-rotation"_s, mTextureRotation );
120 bool fitsInCache =
false;
122 ( void ) fitsInCache;
126 if ( textureSourceImage.isNull() )
130 phongSettings.
setDiffuse( QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) );
138 QgsPhongTexturedMaterial *material =
new QgsPhongTexturedMaterial();
140 int opacity =
static_cast<int>( mOpacity * 255.0 );
143 material->setSpecular( QColor( mSpecular.red(), mSpecular.green(), mSpecular.blue(),
opacity ) );
144 material->setShininess(
static_cast<float>( mShininess ) );
145 material->setOpacity(
static_cast<float>( mOpacity ) );
150 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D();
151 texture->addTextureImage( textureImage );
153 texture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::Repeat );
154 texture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::Repeat );
155 texture->wrapMode()->setZ( Qt3DRender::QTextureWrapMode::Repeat );
157 texture->setSamples( 4 );
159 texture->setGenerateMipMaps(
true );
160 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
161 texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
163 material->setDiffuseTexture( texture );
164 material->setDiffuseTextureScale(
static_cast<float>( mTextureScale ) );
177 QMap<QString, QString> parameters;
178 parameters[u
"Ka"_s] = u
"%1 %2 %3"_s.arg( mAmbient.redF() ).arg( mAmbient.greenF() ).arg( mAmbient.blueF() );
179 parameters[u
"Ks"_s] = u
"%1 %2 %3"_s.arg( mSpecular.redF() ).arg( mSpecular.greenF() ).arg( mSpecular.blueF() );
180 parameters[u
"Ns"_s] = QString::number( mShininess );
188 Qt3DRender::QParameter *ambientParameter =
new Qt3DRender::QParameter( u
"ambientColor"_s, ambientColor );
189 Qt3DRender::QParameter *specularParameter =
new Qt3DRender::QParameter( u
"specularColor"_s, mSpecular );
190 Qt3DRender::QParameter *shininessParameter =
new Qt3DRender::QParameter( u
"shininess"_s,
static_cast<float>( mShininess ) );
192 effect->addParameter( ambientParameter );
193 effect->addParameter( specularParameter );
194 effect->addParameter( shininessParameter );
Abstract base class for material settings.
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
QImage pathAsImage(const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache, bool blocking=false, double targetDpi=96, int frameNumber=-1, bool *isMissing=nullptr)
Returns the specified path rendered as an image.
Holds an image that can be used as a texture in the 3D view.
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.
Base class for all materials used within QGIS 3D views.
Basic shading material used for rendering based on the Phong shading model with three color component...
void setOpacity(double opacity)
Sets opacity of the surface.
QgsMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QgsMaterial object representing the material settings.
void setDiffuse(const QColor &diffuse)
Sets diffuse color component.
void setShininess(double shininess)
Sets shininess of the surface.
void setAmbient(const QColor &ambient)
Sets ambient color component.
void setSpecular(const QColor &specular)
Sets specular color component.
QgsPhongTexturedMaterialSettings()=default
void addParametersToEffect(Qt3DRender::QEffect *effect, const QgsMaterialContext &materialContext) const override
Adds parameters from the material to a destination effect.
QgsMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QgsMaterial object representing the material settings.
bool equals(const QgsAbstractMaterialSettings *other) const override
Returns true if this settings exactly matches an other settings.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
double textureRotation() const
Returns the texture rotation, in degrees.
QString type() const override
Returns the unique type name for the material.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
double opacity() const
Returns the opacity of the surface.
QgsPhongTexturedMaterialSettings * clone() const override
Clones the material settings.
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsPhongTexturedMaterialSettings.
QMap< QString, QString > toExportParameters() const override
Returns the parameters to be exported to .mtl file.
QColor ambient() const
Returns ambient color component.
A container for the context for various read/write operations on objects.
QgsMaterialSettingsRenderingTechnique
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.
@ 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).