26 #include <Qt3DRender/QTexture>
28 #include <Qt3DExtras/QTextureMaterial>
29 #include <Qt3DExtras/QDiffuseSpecularMaterial>
30 #include <Qt3DExtras/QPhongMaterial>
36 QgsTerrainTileLoader::QgsTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node )
37 : QgsChunkLoader( node )
51 QgsChunkNodeId nodeId = node->tileId();
53 mExtentMapCrs = terrain->terrainToMapTransform().transformBoundingBox( extentTerrainCrs );
54 mTileDebugText = nodeId.text();
57 void QgsTerrainTileLoader::loadTexture()
59 connect( mTerrain->textureGenerator(), &QgsTerrainTextureGenerator::tileReady,
this, &QgsTerrainTileLoader::onImageReady );
60 mTextureJobId = mTerrain->textureGenerator()->render( mExtentMapCrs, mNode->tileId(), mTileDebugText );
63 void QgsTerrainTileLoader::createTextureComponent( QgsTerrainTileEntity *entity,
bool isShadingEnabled,
const QgsPhongMaterialSettings &shadingMaterial,
bool useTexture )
65 Qt3DRender::QTexture2D *texture = useTexture || !isShadingEnabled ? createTexture( entity ) : nullptr;
67 Qt3DRender::QMaterial *material =
nullptr;
70 if ( isShadingEnabled )
72 Qt3DExtras::QDiffuseSpecularMaterial *diffuseMapMaterial =
new Qt3DExtras::QDiffuseSpecularMaterial;
73 diffuseMapMaterial->setDiffuse( QVariant::fromValue( texture ) );
74 material = diffuseMapMaterial;
75 diffuseMapMaterial->setAmbient( shadingMaterial.
ambient() );
76 diffuseMapMaterial->setSpecular( shadingMaterial.
specular() );
77 diffuseMapMaterial->setShininess( shadingMaterial.
shininess() );
78 material = diffuseMapMaterial;
82 Qt3DExtras::QTextureMaterial *textureMaterial =
new Qt3DExtras::QTextureMaterial;
83 textureMaterial->setTexture( texture );
84 material = textureMaterial;
89 Qt3DExtras::QPhongMaterial *phongMaterial =
new Qt3DExtras::QPhongMaterial;
90 phongMaterial->setDiffuse( shadingMaterial.
diffuse() );
91 phongMaterial->setAmbient( shadingMaterial.
ambient() );
92 phongMaterial->setSpecular( shadingMaterial.
specular() );
93 phongMaterial->setShininess( shadingMaterial.
shininess() );
94 material = phongMaterial;
97 entity->addComponent( material );
100 Qt3DRender::QTexture2D *QgsTerrainTileLoader::createTexture( QgsTerrainTileEntity *entity )
102 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D;
103 QgsTerrainTextureImage *textureImage =
new QgsTerrainTextureImage( mTextureImage, mExtentMapCrs, mTileDebugText );
104 texture->addTextureImage( textureImage );
105 texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
106 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
108 entity->setTextureImage( textureImage );
113 void QgsTerrainTileLoader::onImageReady(
int jobId,
const QImage &image )
115 if ( mTextureJobId == jobId )
117 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.