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 );
54 return new QgsHighlightMaterial( technique );
57 QgsMetalRoughMaterial *material =
new QgsMetalRoughMaterial(
nullptr );
58 material->setEnvironmentalLightingEnabled( !context.
isPreview() );
59 material->setObjectName( u
"metalRoughTexturedMaterial"_s );
60 applySettingsToMaterial( texturedSettings, material, context );
74 QgsMetalRoughMaterial *material =
new QgsMetalRoughMaterial();
75 material->setEnvironmentalLightingEnabled(
true );
76 material->setInstancingEnabled(
true, flags );
78 material->setObjectName( u
"metalRoughTexturedMaterial"_s );
79 applySettingsToMaterial( texturedSettings, material, context );
86 QMap<QString, QString> parameters;
94 QgsMetalRoughMaterial *material = sceneRoot->findChild<QgsMetalRoughMaterial *>();
95 if ( !material || material->objectName() !=
"metalRoughTexturedMaterial"_L1 )
98 applySettingsToMaterial( metalRoughTexturedSettings, material, context );
102Qt3DRender::QTexture2D *QgsMetalRoughTexturedMaterial3DHandler::loadTexture(
const QString &path,
bool isSrgb,
const QgsMaterialContext &context )
104 if ( path.isEmpty() )
107 bool fitsInCache =
false;
109 if ( image.isNull() )
112 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D();
116 texture->setFormat( Qt3DRender::QAbstractTexture::SRGB8_Alpha8 );
120 texture->setFormat( Qt3DRender::QAbstractTexture::RGBA8_UNorm );
123 texture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::Repeat );
124 texture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::Repeat );
128 texture->addTextureImage(
new QgsImageTexture( image ) );
135 material->setTextureScale(
static_cast<float>( texturedSettings->
textureScale() ) );
136 material->setTextureRotation(
static_cast<float>( texturedSettings->
textureRotation() ) );
139 if ( Qt3DRender::QTexture2D *baseTex = loadTexture( texturedSettings->
baseColorTexturePath(),
true, context ) )
142 material->setBaseColorTexture( baseTex );
147 material->setBaseColor( QColor(
"grey" ) );
151 if ( Qt3DRender::QTexture2D *metalTex = loadTexture( texturedSettings->
metalnessTexturePath(),
false, context ) )
154 material->setMetalnessTexture( metalTex );
159 material->setMetalness( 0.0 );
163 if ( Qt3DRender::QTexture2D *roughTex = loadTexture( texturedSettings->
roughnessTexturePath(),
false, context ) )
166 material->setRoughnessTexture( roughTex );
171 material->setRoughness( 0.5 );
174 if ( Qt3DRender::QTexture2D *normalTex = loadTexture( texturedSettings->
normalTexturePath(),
false, context ) )
177 material->setNormalTexture( normalTex );
182 material->setNormalTexture(
nullptr );
185 if ( Qt3DRender::QTexture2D *heightTex = loadTexture( texturedSettings->
heightTexturePath(),
false, context ) )
187 material->setHeightTexture( heightTex );
192 material->setHeightTexture(
nullptr );
194 material->setParallaxScale( texturedSettings->
parallaxScale() );
200 material->setAmbientOcclusionTexture( aoTex );
205 material->setAmbientOcclusionTexture(
nullptr );
208 if ( Qt3DRender::QTexture2D *emissionTex = loadTexture( texturedSettings->
emissionTexturePath(),
true, context ) )
210 material->setEmissionTexture( emissionTex );
215 material->setEmissionTexture(
nullptr );
218 material->setEmissionFactor( texturedSettings->
emissionFactor() );
219 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.
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
QFlags< InstancedMaterialFlag > InstancedMaterialFlags
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.
bool isPreview() const
Returns true if the material is being shown in a preview widget.
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.
QgsMaterial * toInstancedMaterial(const QgsAbstractMaterialSettings *settings, const QgsMaterialContext &context, Qgis::InstancedMaterialFlags flags) const override
Creates a QgsMaterial for instanced point rendering.
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.