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 );
61 Qt3DRender::QTexture2D *texture = useTexture || !isShadingEnabled ? createTexture( entity, materialContext ) : nullptr;
66 if ( isShadingEnabled )
68 QgsPhongTexturedMaterial *phongTexturedMaterial =
new QgsPhongTexturedMaterial();
69 phongTexturedMaterial->setAmbient( shadingMaterial.
ambient() );
70 phongTexturedMaterial->setSpecular( shadingMaterial.
specular() );
71 phongTexturedMaterial->setShininess(
static_cast<float>( shadingMaterial.
shininess() ) );
72 phongTexturedMaterial->setDiffuseTexture( texture );
73 phongTexturedMaterial->setOpacity(
static_cast<float>( shadingMaterial.
opacity() ) );
74 material = phongTexturedMaterial;
78 QgsTextureMaterial *textureMaterial =
new QgsTextureMaterial;
79 textureMaterial->setTexture( texture );
80 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,
const QgsMaterialContext &context )
107 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D;
108 QgsTerrainTextureImage *textureImage =
new QgsTerrainTextureImage( mTextureImage, mExtentMapCrs, mTileDebugText );
110 texture->setFormat( Qt3DRender::QAbstractTexture::SRGB8_Alpha8 );
111 texture->addTextureImage( textureImage );
113 entity->setTextureImage( textureImage );
118void QgsTerrainTileLoader::onTextureLoaded()
123void QgsTerrainTileLoader::onImageReady(
int jobId,
const QImage &image )
125 if ( mTextureJobId == jobId )
127 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...
Rendering context for preparation of 3D entities.
static void setTextureFiltering(Qt3DRender::QAbstractTexture *texture, const QgsMaterialContext &context)
Sets the default filtering options for a texture.
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.
static QgsMaterialContext fromRenderContext(const Qgs3DRenderContext &context)
Constructs a material context from the settings in a 3D render context.
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.