26#include <Qt3DCore/QEntity>
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;
39 Q_ASSERT( texturedSettings );
48 return new QgsHighlightMaterial( technique );
51 QgsMetalRoughMaterial *material =
new QgsMetalRoughMaterial();
52 material->setObjectName( u
"metalRoughTexturedMaterial"_s );
53 applySettingsToMaterial( texturedSettings, material );
65 QMap<QString, QString> parameters;
76 QgsMetalRoughMaterial *material = sceneRoot->findChild<QgsMetalRoughMaterial *>();
77 if ( !material || material->objectName() !=
"metalRoughTexturedMaterial"_L1 )
80 applySettingsToMaterial( metalRoughTexturedSettings, material );
84Qt3DRender::QTexture2D *QgsMetalRoughTexturedMaterial3DHandler::loadTexture(
const QString &path )
89 bool fitsInCache =
false;
95 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D();
97 texture->addTextureImage( textureImage );
99 texture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::Repeat );
100 texture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::Repeat );
101 texture->setGenerateMipMaps(
true );
102 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
103 texture->setMinificationFilter( Qt3DRender::QTexture2D::LinearMipMapLinear );
110 material->setTextureScale(
static_cast<float>( texturedSettings->
textureScale() ) );
113 if ( Qt3DRender::QTexture2D *baseTex = loadTexture( texturedSettings->
baseColorTexturePath() ) )
116 material->setBaseColor( QVariant::fromValue( baseTex ) );
121 material->setBaseColor( QColor(
"grey" ) );
125 if ( Qt3DRender::QTexture2D *metalTex = loadTexture( texturedSettings->
metalnessTexturePath() ) )
128 material->setMetalness( QVariant::fromValue( metalTex ) );
133 material->setMetalness( 0.0 );
137 if ( Qt3DRender::QTexture2D *roughTex = loadTexture( texturedSettings->
roughnessTexturePath() ) )
140 material->setRoughness( QVariant::fromValue( roughTex ) );
145 material->setRoughness( 0.5 );
152 material->setAmbientOcclusion( QVariant::fromValue( aoTex ) );
157 material->setAmbientOcclusion( QVariant() );
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.
QString roughnessTexturePath() const
Returns the path to the roughness texture map.
double textureScale() const
Returns the texture scale.
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.