26 #include <Qt3DRender/QTexture>
28 #include <Qt3DExtras/QTextureMaterial>
29 #include <Qt3DExtras/QDiffuseMapMaterial>
30 #include <Qt3DExtras/QPhongMaterial>
36 QgsTerrainTileLoader::QgsTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node )
37 : QgsChunkLoader( node )
58 mExtentMapCrs = terrain->terrainToMapTransform().transformBoundingBox( extentTerrainCrs );
59 mTileDebugText = QStringLiteral(
"%1 | %2 | %3" ).arg( tx ).arg( ty ).arg( tz );
62 void QgsTerrainTileLoader::loadTexture()
64 connect( mTerrain->textureGenerator(), &QgsTerrainTextureGenerator::tileReady,
this, &QgsTerrainTileLoader::onImageReady );
65 mTextureJobId = mTerrain->textureGenerator()->render( mExtentMapCrs, mNode->tileId(), mTileDebugText );
68 void QgsTerrainTileLoader::createTextureComponent( QgsTerrainTileEntity *entity,
bool isShadingEnabled,
const QgsPhongMaterialSettings &shadingMaterial,
bool useTexture )
70 Qt3DRender::QTexture2D *texture = useTexture || !isShadingEnabled ? createTexture( entity ) : nullptr;
72 Qt3DRender::QMaterial *material =
nullptr;
75 if ( isShadingEnabled )
77 Qt3DExtras::QDiffuseMapMaterial *diffuseMapMaterial;
78 diffuseMapMaterial =
new Qt3DExtras::QDiffuseMapMaterial;
79 diffuseMapMaterial->setDiffuse( texture );
80 diffuseMapMaterial->setAmbient( shadingMaterial.
ambient() );
81 diffuseMapMaterial->setSpecular( shadingMaterial.
specular() );
82 diffuseMapMaterial->setShininess( shadingMaterial.
shininess() );
83 material = diffuseMapMaterial;
87 Qt3DExtras::QTextureMaterial *textureMaterial =
new Qt3DExtras::QTextureMaterial;
88 textureMaterial->setTexture( texture );
89 material = textureMaterial;
94 Qt3DExtras::QPhongMaterial *phongMaterial =
new Qt3DExtras::QPhongMaterial;
95 phongMaterial->setDiffuse( shadingMaterial.
diffuse() );
96 phongMaterial->setAmbient( shadingMaterial.
ambient() );
97 phongMaterial->setSpecular( shadingMaterial.
specular() );
98 phongMaterial->setShininess( shadingMaterial.
shininess() );
99 material = phongMaterial;
102 entity->addComponent( material );
105 Qt3DRender::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 );
113 entity->setTextureImage( textureImage );
118 void QgsTerrainTileLoader::onImageReady(
int jobId,
const QImage &image )
120 if ( mTextureJobId == jobId )
122 mTextureImage = image;