27#include <Qt3DCore/QEntity>
28#include <Qt3DRender/QEffect>
29#include <Qt3DRender/QGraphicsApiFilter>
30#include <Qt3DRender/QPaintedTextureImage>
31#include <Qt3DRender/QParameter>
32#include <Qt3DRender/QTechnique>
33#include <Qt3DRender/QTexture>
35using namespace Qt::StringLiterals;
40 Q_ASSERT( texturedSettings );
49 return new QgsHighlightMaterial( technique );
52 QgsMetalRoughMaterial *material =
new QgsMetalRoughMaterial();
53 material->setObjectName( u
"metalRoughTexturedMaterial"_s );
54 applySettingsToMaterial( texturedSettings, material, context );
66 QMap<QString, QString> parameters;
77 QgsMetalRoughMaterial *material = sceneRoot->findChild<QgsMetalRoughMaterial *>();
78 if ( !material || material->objectName() !=
"metalRoughTexturedMaterial"_L1 )
81 applySettingsToMaterial( metalRoughTexturedSettings, material, context );
85Qt3DRender::QTexture2D *QgsMetalRoughTexturedMaterial3DHandler::loadTexture(
const QString &path,
bool isSrgb,
const QgsMaterialContext &context )
90 bool fitsInCache =
false;
95 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D();
99 texture->setFormat( Qt3DRender::QAbstractTexture::SRGB8_Alpha8 );
103 texture->setFormat( Qt3DRender::QAbstractTexture::RGBA8_UNorm );
106 texture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::Repeat );
107 texture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::Repeat );
111 texture->addTextureImage(
new QgsImageTexture( image ) );
118 material->setTextureScale(
static_cast<float>( texturedSettings->
textureScale() ) );
119 material->setTextureRotation(
static_cast<float>( texturedSettings->
textureRotation() ) );
122 if ( Qt3DRender::QTexture2D *baseTex = loadTexture( texturedSettings->
baseColorTexturePath(),
true, context ) )
125 material->setBaseColorTexture( baseTex );
130 material->setBaseColor( QColor(
"grey" ) );
134 if ( Qt3DRender::QTexture2D *metalTex = loadTexture( texturedSettings->
metalnessTexturePath(),
false, context ) )
137 material->setMetalnessTexture( metalTex );
142 material->setMetalness( 0.0 );
146 if ( Qt3DRender::QTexture2D *roughTex = loadTexture( texturedSettings->
roughnessTexturePath(),
false, context ) )
149 material->setRoughnessTexture( roughTex );
154 material->setRoughness( 0.5 );
157 if ( Qt3DRender::QTexture2D *normalTex = loadTexture( texturedSettings->
normalTexturePath(),
false, context ) )
160 material->setNormalTexture( normalTex );
165 material->setNormalTexture(
nullptr );
168 if ( Qt3DRender::QTexture2D *heightTex = loadTexture( texturedSettings->
heightTexturePath(),
false, context ) )
170 material->setHeightTexture( heightTex );
175 material->setHeightTexture(
nullptr );
177 material->setParallaxScale( texturedSettings->
parallaxScale() );
183 material->setAmbientOcclusionTexture( aoTex );
188 material->setAmbientOcclusionTexture(
nullptr );
191 if ( Qt3DRender::QTexture2D *emissionTex = loadTexture( texturedSettings->
emissionTexturePath(),
true, context ) )
193 material->setEmissionTexture( emissionTex );
198 material->setEmissionTexture(
nullptr );
201 material->setEmissionFactor( texturedSettings->
emissionFactor() );
202 material->setOpacity(
static_cast< float >( texturedSettings->
opacity() ) );
MaterialRenderingTechnique
Material rendering techniques.
@ Triangles
Triangle based rendering (default).
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
static void setTextureFiltering(Qt3DRender::QAbstractTexture *texture, const QgsMaterialContext &context)
Sets the default filtering options for a texture.
Abstract base class for material settings.
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
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.
Context settings for a material.
bool isHighlighted() const
Returns true if the material should represent a highlighted state.
Base class for all materials used within QGIS 3D views.
bool updatePreviewScene(Qt3DCore::QEntity *sceneRoot, const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context) const override
Updates an existing material preview scene with new 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.
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.
A PBR metal rough shading material used for rendering with support for image texture maps.
double emissionFactor() const
Returns the emission factor, which dictates the strength of the emission effect.
QString roughnessTexturePath() const
Returns the path to the roughness texture map.
double textureRotation() const
Returns the texture rotation, in degrees.
double textureScale() const
Returns the texture scale.
double opacity() const
Returns the opacity of the surface.
QString normalTexturePath() const
Returns the path to the normal texture map.
QString ambientOcclusionTexturePath() const
Returns the path to the ambient occlusion texture map.
QString metalnessTexturePath() const
Returns the path to the metalness texture map.
QString baseColorTexturePath() const
Returns the path to the base color texture map.
QString heightTexturePath() const
Returns the path to the height texture map.
QString emissionTexturePath() const
Returns the path to the emission/luminosity texture map.
double parallaxScale() const
Returns the parallax scale, which dictates the strength of the height displacement effect.