33#include <Qt3DRender/QCullFace>
34#include <Qt3DRender/QTechnique>
35#include <Qt3DRender/QTexture>
37#include "moc_qgsterraintileloader.cpp"
41QgsTerrainTileLoader::QgsTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node )
42 : QgsChunkLoader( node )
46 const QgsChunkNodeId nodeId = node->tileId();
49 mTileDebugText = nodeId.text();
52void QgsTerrainTileLoader::loadTexture()
54 connect( mTerrain->textureGenerator(), &QgsTerrainTextureGenerator::tileReady,
this, &QgsTerrainTileLoader::onImageReady );
55 mTextureJobId = mTerrain->textureGenerator()->render( mExtentMapCrs, mNode->tileId(), mTileDebugText );
58void QgsTerrainTileLoader::createTextureComponent( QgsTerrainTileEntity *entity,
bool isShadingEnabled,
const QgsPhongMaterialSettings &shadingMaterial,
bool useTexture )
60 Qt3DRender::QTexture2D *texture = useTexture || !isShadingEnabled ? createTexture( entity ) : nullptr;
65 if ( isShadingEnabled )
67 QgsPhongTexturedMaterial *phongTexturedMaterial =
new QgsPhongTexturedMaterial();
68 phongTexturedMaterial->setAmbient( shadingMaterial.
ambient() );
69 phongTexturedMaterial->setSpecular( shadingMaterial.
specular() );
70 phongTexturedMaterial->setShininess(
static_cast<float>( shadingMaterial.
shininess() ) );
71 phongTexturedMaterial->setDiffuseTexture( texture );
72 phongTexturedMaterial->setOpacity(
static_cast<float>( shadingMaterial.
opacity() ) );
73 material = phongTexturedMaterial;
77 QgsTextureMaterial *textureMaterial =
new QgsTextureMaterial;
78 textureMaterial->setTexture( texture );
79 material = textureMaterial;
90 const QVector<Qt3DRender::QTechnique *> techniques = material->effect()->techniques();
91 for ( Qt3DRender::QTechnique *technique : techniques )
93 const QVector<Qt3DRender::QRenderPass *> passes = technique->renderPasses();
94 for ( Qt3DRender::QRenderPass *pass : passes )
96 Qt3DRender::QCullFace *cullFace =
new Qt3DRender::QCullFace;
97 cullFace->setMode( Qt3DRender::QCullFace::NoCulling );
98 pass->addRenderState( cullFace );
102 entity->addComponent( material );
105Qt3DRender::QTexture2D *QgsTerrainTileLoader::createTexture( QgsTerrainTileEntity *entity )
107 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D;
108 QgsTerrainTextureImage *textureImage =
new QgsTerrainTextureImage( mTextureImage, mExtentMapCrs, mTileDebugText );
109 texture->addTextureImage( textureImage );
110 texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
111 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
112 texture->setFormat( Qt3DRender::QAbstractTexture::SRGB8_Alpha8 );
114 entity->setTextureImage( textureImage );
119void QgsTerrainTileLoader::onTextureLoaded()
124void QgsTerrainTileLoader::onImageReady(
int jobId,
const QImage &image )
126 if ( mTextureJobId == jobId )
128 mTextureImage = image;
@ Triangles
Triangle based rendering (default).
QgsTerrainGenerator * terrainGenerator() const
Returns the terrain generator.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
static QgsRectangle tryReprojectExtent2D(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs1, const QgsCoordinateReferenceSystem &crs2, const QgsCoordinateTransformContext &context)
Reprojects extent from crs1 to crs2 coordinate reference system with context context.
static QgsMaterial * toMaterial(const QgsAbstractMaterialSettings *settings, Qgis::MaterialRenderingTechnique technique, const QgsMaterialContext &context)
Creates a new QgsMaterial object representing the material settings.
Context settings for a material.
void setIsSelected(bool isSelected)
Sets whether 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...
double opacity() const
Returns the opacity of the surface.
QColor specular() const
Returns specular color component.
QColor ambient() const
Returns ambient color component.
double shininess() const
Returns shininess of the surface.
A rectangle specified with double values.
virtual QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.