27 #include <Qt3DRender/QTexture>
29 #include <Qt3DExtras/QTextureMaterial>
30 #include <Qt3DExtras/QDiffuseSpecularMaterial>
31 #include <Qt3DExtras/QPhongMaterial>
37 QgsTerrainTileLoader::QgsTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node )
38 : QgsChunkLoader( node )
52 const QgsChunkNodeId nodeId = node->tileId();
57 mTileDebugText = nodeId.text();
60 void QgsTerrainTileLoader::loadTexture()
62 connect( mTerrain->textureGenerator(), &QgsTerrainTextureGenerator::tileReady,
this, &QgsTerrainTileLoader::onImageReady );
63 mTextureJobId = mTerrain->textureGenerator()->render( mExtentMapCrs, mNode->tileId(), mTileDebugText );
66 void QgsTerrainTileLoader::createTextureComponent( QgsTerrainTileEntity *entity,
bool isShadingEnabled,
const QgsPhongMaterialSettings &shadingMaterial,
bool useTexture )
68 Qt3DRender::QTexture2D *texture = useTexture || !isShadingEnabled ? createTexture( entity ) : nullptr;
70 Qt3DRender::QMaterial *material =
nullptr;
73 if ( isShadingEnabled )
75 Qt3DExtras::QDiffuseSpecularMaterial *diffuseMapMaterial =
new Qt3DExtras::QDiffuseSpecularMaterial;
76 diffuseMapMaterial->setDiffuse( QVariant::fromValue( texture ) );
77 material = diffuseMapMaterial;
78 diffuseMapMaterial->setAmbient( shadingMaterial.
ambient() );
79 diffuseMapMaterial->setSpecular( shadingMaterial.
specular() );
80 diffuseMapMaterial->setShininess( shadingMaterial.
shininess() );
81 material = diffuseMapMaterial;
85 Qt3DExtras::QTextureMaterial *textureMaterial =
new Qt3DExtras::QTextureMaterial;
86 textureMaterial->setTexture( texture );
87 material = textureMaterial;
92 Qt3DExtras::QPhongMaterial *phongMaterial =
new Qt3DExtras::QPhongMaterial;
93 phongMaterial->setDiffuse( shadingMaterial.
diffuse() );
94 phongMaterial->setAmbient( shadingMaterial.
ambient() );
95 phongMaterial->setSpecular( shadingMaterial.
specular() );
96 phongMaterial->setShininess( shadingMaterial.
shininess() );
97 material = phongMaterial;
100 entity->addComponent( material );
103 Qt3DRender::QTexture2D *QgsTerrainTileLoader::createTexture( QgsTerrainTileEntity *entity )
105 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D;
106 QgsTerrainTextureImage *textureImage =
new QgsTerrainTextureImage( mTextureImage, mExtentMapCrs, mTileDebugText );
107 texture->addTextureImage( textureImage );
108 texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
109 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
111 entity->setTextureImage( textureImage );
116 void QgsTerrainTileLoader::onImageReady(
int jobId,
const QImage &image )
118 if ( mTextureJobId == jobId )
120 mTextureImage = image;
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data.
QColor diffuse() const
Returns diffuse color component.
QColor specular() const
Returns specular color component.
QColor ambient() const
Returns ambient color component.
float shininess() const
Returns shininess of the surface.
A rectangle specified with double values.
const QgsTilingScheme & tilingScheme() const
Returns tiling scheme of the terrain.
virtual Type type() const =0
What texture generator implementation is this.
QgsRectangle tileToExtent(int x, int y, int z) const
Returns map coordinates of the extent of a tile.
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.