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 );
66 QMap<QString, QString> parameters;
77 QgsMetalRoughMaterial *material = sceneRoot->findChild<QgsMetalRoughMaterial *>();
78 if ( !material || material->objectName() !=
"metalRoughTexturedMaterial"_L1 )
81 applySettingsToMaterial( metalRoughTexturedSettings, material );
85Qt3DRender::QTexture2D *QgsMetalRoughTexturedMaterial3DHandler::loadTexture(
const QString &path,
bool isSrgb )
90 bool fitsInCache =
false;
96 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D();
98 texture->addTextureImage( textureImage );
102 texture->setFormat( Qt3DRender::QAbstractTexture::SRGB8_Alpha8 );
106 texture->setFormat( Qt3DRender::QAbstractTexture::RGBA8_UNorm );
109 texture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::Repeat );
110 texture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::Repeat );
111 texture->setGenerateMipMaps(
true );
112 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
113 texture->setMinificationFilter( Qt3DRender::QTexture2D::LinearMipMapLinear );
120 material->setTextureScale(
static_cast<float>( texturedSettings->
textureScale() ) );
121 material->setTextureRotation(
static_cast<float>( texturedSettings->
textureRotation() ) );
124 if ( Qt3DRender::QTexture2D *baseTex = loadTexture( texturedSettings->
baseColorTexturePath(),
true ) )
127 material->setBaseColorTexture( baseTex );
132 material->setBaseColor( QColor(
"grey" ) );
136 if ( Qt3DRender::QTexture2D *metalTex = loadTexture( texturedSettings->
metalnessTexturePath(),
false ) )
139 material->setMetalnessTexture( metalTex );
144 material->setMetalness( 0.0 );
148 if ( Qt3DRender::QTexture2D *roughTex = loadTexture( texturedSettings->
roughnessTexturePath(),
false ) )
151 material->setRoughnessTexture( roughTex );
156 material->setRoughness( 0.5 );
159 if ( Qt3DRender::QTexture2D *normalTex = loadTexture( texturedSettings->
normalTexturePath(),
false ) )
162 material->setNormalTexture( normalTex );
167 material->setNormalTexture(
nullptr );
174 material->setAmbientOcclusionTexture( aoTex );
179 material->setAmbientOcclusionTexture(
nullptr );
182 if ( Qt3DRender::QTexture2D *emissionTex = loadTexture( texturedSettings->
emissionTexturePath(),
true ) )
184 material->setEmissionTexture( emissionTex );
189 material->setEmissionTexture(
nullptr );
192 material->setEmissionFactor( texturedSettings->
emissionFactor() );
MaterialRenderingTechnique
Material rendering techniques.
@ Triangles
Triangle based rendering (default).
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
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.
Holds an image that can be used as a texture in the 3D view.
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.
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 emissionTexturePath() const
Returns the path to the emission/luminosity texture map.