26 #include <Qt3DRender/QTexture> 28 #include <Qt3DExtras/QTextureMaterial> 29 #include <Qt3DExtras/QDiffuseMapMaterial> 35 QgsTerrainTileLoader::QgsTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node )
36 : QgsChunkLoader( node )
57 mExtentMapCrs = terrain->terrainToMapTransform().transformBoundingBox( extentTerrainCrs );
58 mTileDebugText = QStringLiteral(
"%1 | %2 | %3" ).arg( tx ).arg( ty ).arg( tz );
61 void QgsTerrainTileLoader::loadTexture()
63 connect(
mTerrain->textureGenerator(), &QgsTerrainTextureGenerator::tileReady,
this, &QgsTerrainTileLoader::onImageReady );
64 mTextureJobId =
mTerrain->textureGenerator()->render( mExtentMapCrs, mTileDebugText );
67 void QgsTerrainTileLoader::createTextureComponent( QgsTerrainTileEntity *entity,
bool isShadingEnabled,
const QgsPhongMaterialSettings &shadingMaterial )
69 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D( entity );
70 QgsTerrainTextureImage *textureImage =
new QgsTerrainTextureImage( mTextureImage, mExtentMapCrs, mTileDebugText );
71 texture->addTextureImage( textureImage );
72 texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
73 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
75 Qt3DRender::QMaterial *material =
nullptr;
76 if ( isShadingEnabled )
78 Qt3DExtras::QDiffuseMapMaterial *diffuseMapMaterial;
79 diffuseMapMaterial =
new Qt3DExtras::QDiffuseMapMaterial;
80 diffuseMapMaterial->setDiffuse( texture );
81 diffuseMapMaterial->setAmbient( shadingMaterial.
ambient() );
82 diffuseMapMaterial->setSpecular( shadingMaterial.
specular() );
83 diffuseMapMaterial->setShininess( shadingMaterial.
shininess() );
84 material = diffuseMapMaterial;
88 Qt3DExtras::QTextureMaterial *textureMaterial =
new Qt3DExtras::QTextureMaterial;
89 textureMaterial->setTexture( texture );
90 material = textureMaterial;
93 entity->setTextureImage( textureImage );
94 entity->addComponent( material );
97 void QgsTerrainTileLoader::onImageReady(
int jobId,
const QImage &image )
99 if ( mTextureJobId == jobId )
101 mTextureImage = image;
A rectangle specified with double values.
float shininess() const
Returns shininess of the surface.
QColor specular() const
Returns specular color component.
virtual Type type() const =0
What texture generator implementation is this.
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
3 Definition of the world
void quadTreeTileToBaseTile(int x, int y, int z, int &tx, int &ty, int &tz) const
Converts tile coordinates (x,y,z) in our quadtree to tile coordinates of quantized mesh tree...
3 Terrain generator using downloaded terrain tiles using quantized mesh specification ...
QgsTerrainEntity * mTerrain
const QgsTilingScheme & tilingScheme() const
Returns tiling scheme of the terrain.
QColor ambient() const
Returns ambient color component.
QgsRectangle tileToExtent(int x, int y, int z) const
Returns map coordinates of the extent of a tile.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data...