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, mNode->tileId(), mTileDebugText );
67 void QgsTerrainTileLoader::createTextureComponent( QgsTerrainTileEntity *entity,
bool isShadingEnabled,
const QgsPhongMaterialSettings &shadingMaterial )
69 Qt3DRender::QTexture2D *texture = createTexture( entity );
71 Qt3DRender::QMaterial *material =
nullptr;
72 if ( isShadingEnabled )
74 Qt3DExtras::QDiffuseMapMaterial *diffuseMapMaterial;
75 diffuseMapMaterial =
new Qt3DExtras::QDiffuseMapMaterial;
76 diffuseMapMaterial->setDiffuse( texture );
77 diffuseMapMaterial->setAmbient( shadingMaterial.
ambient() );
78 diffuseMapMaterial->setSpecular( shadingMaterial.
specular() );
79 diffuseMapMaterial->setShininess( shadingMaterial.
shininess() );
80 material = diffuseMapMaterial;
84 Qt3DExtras::QTextureMaterial *textureMaterial =
new Qt3DExtras::QTextureMaterial;
85 textureMaterial->setTexture( texture );
86 material = textureMaterial;
89 entity->addComponent( material );
92 Qt3DRender::QTexture2D *QgsTerrainTileLoader::createTexture( QgsTerrainTileEntity *entity )
94 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D;
95 QgsTerrainTextureImage *textureImage =
new QgsTerrainTextureImage( mTextureImage, mExtentMapCrs, mTileDebugText );
96 texture->addTextureImage( textureImage );
97 texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
98 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
100 entity->setTextureImage( textureImage );
105 void QgsTerrainTileLoader::onImageReady(
int jobId,
const QImage &image )
107 if ( mTextureJobId == jobId )
109 mTextureImage = image;