26 #include <Qt3DRender/QTexture>
28 #include <Qt3DExtras/QTextureMaterial>
29 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
30 #include <Qt3DExtras/QDiffuseMapMaterial>
32 #include <Qt3DExtras/QDiffuseSpecularMaterial>
34 #include <Qt3DExtras/QPhongMaterial>
40 QgsTerrainTileLoader::QgsTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node )
41 : QgsChunkLoader( node )
55 QgsChunkNodeId nodeId = node->tileId();
57 mExtentMapCrs = terrain->terrainToMapTransform().transformBoundingBox( extentTerrainCrs );
58 mTileDebugText = nodeId.text();
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,
bool useTexture )
69 Qt3DRender::QTexture2D *texture = useTexture || !isShadingEnabled ? createTexture( entity ) : nullptr;
71 Qt3DRender::QMaterial *material =
nullptr;
74 if ( isShadingEnabled )
76 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
77 Qt3DExtras::QDiffuseMapMaterial *diffuseMapMaterial;
78 diffuseMapMaterial =
new Qt3DExtras::QDiffuseMapMaterial;
79 diffuseMapMaterial->setDiffuse( texture );
81 Qt3DExtras::QDiffuseSpecularMaterial *diffuseMapMaterial =
new Qt3DExtras::QDiffuseSpecularMaterial;
82 diffuseMapMaterial->setDiffuse( QVariant::fromValue( texture ) );
83 material = diffuseMapMaterial;
85 diffuseMapMaterial->setAmbient( shadingMaterial.
ambient() );
86 diffuseMapMaterial->setSpecular( shadingMaterial.
specular() );
87 diffuseMapMaterial->setShininess( shadingMaterial.
shininess() );
88 material = diffuseMapMaterial;
92 Qt3DExtras::QTextureMaterial *textureMaterial =
new Qt3DExtras::QTextureMaterial;
93 textureMaterial->setTexture( texture );
94 material = textureMaterial;
99 Qt3DExtras::QPhongMaterial *phongMaterial =
new Qt3DExtras::QPhongMaterial;
100 phongMaterial->setDiffuse( shadingMaterial.
diffuse() );
101 phongMaterial->setAmbient( shadingMaterial.
ambient() );
102 phongMaterial->setSpecular( shadingMaterial.
specular() );
103 phongMaterial->setShininess( shadingMaterial.
shininess() );
104 material = phongMaterial;
107 entity->addComponent( material );
110 Qt3DRender::QTexture2D *QgsTerrainTileLoader::createTexture( QgsTerrainTileEntity *entity )
112 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D;
113 QgsTerrainTextureImage *textureImage =
new QgsTerrainTextureImage( mTextureImage, mExtentMapCrs, mTileDebugText );
114 texture->addTextureImage( textureImage );
115 texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
116 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
118 entity->setTextureImage( textureImage );
123 void QgsTerrainTileLoader::onImageReady(
int jobId,
const QImage &image )
125 if ( mTextureJobId == jobId )
127 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.