34#include "moc_qgsterraingenerator.cpp"
36using namespace Qt::StringLiterals;
78 return u
"quantizedmesh"_s;
93 QgsTerrainTileEntity *entity = qobject_cast<QgsTerrainTileEntity *>( node->entity() );
94 return mTerrain->textureGenerator()->render( entity->textureImage()->imageExtent(), node->tileId(), entity->textureImage()->imageDebugText() ).then(
this, [entity]( QImage image ) {
95 return QgsChunkLoaderResult { [entity, image]( Qt3DCore::QEntity *parent ) {
97 entity->textureImage()->setImage( image );
98 entity->setParent( parent );
112 const QgsChunkNodeId nodeId = node->tileId();
115 const QString tileDebugText = node->tileId().text();
117 return mTerrain->textureGenerator()->render( extentMapCrs, node->tileId(), tileDebugText ).then(
this, [extentTerrainCrs, extentMapCrs, tileDebugText]( QImage img ) {
132 Qt3DRender::QTexture2D *texture = useTexture || !isShadingEnabled ?
applyTexture( entity, materialContext, resources ) :
nullptr;
137 if ( isShadingEnabled )
139 QgsPhongTexturedMaterial *phongTexturedMaterial =
new QgsPhongTexturedMaterial();
140 phongTexturedMaterial->setAmbient( shadingMaterial.
ambient() );
141 phongTexturedMaterial->setSpecular( shadingMaterial.
specular() );
142 phongTexturedMaterial->setShininess(
static_cast<float>( shadingMaterial.
shininess() ) );
143 phongTexturedMaterial->setDiffuseTexture( texture );
144 phongTexturedMaterial->setOpacity(
static_cast<float>( shadingMaterial.
opacity() ) );
145 material = phongTexturedMaterial;
149 QgsTextureMaterial *textureMaterial =
new QgsTextureMaterial;
150 textureMaterial->setTexture( texture );
151 material = textureMaterial;
161 const QVector<Qt3DRender::QTechnique *> techniques = material->effect()->techniques();
162 for ( Qt3DRender::QTechnique *technique : techniques )
164 const QVector<Qt3DRender::QRenderPass *> passes = technique->renderPasses();
165 for ( Qt3DRender::QRenderPass *pass : passes )
167 Qt3DRender::QCullFace *cullFace =
new Qt3DRender::QCullFace;
168 cullFace->setMode( Qt3DRender::QCullFace::NoCulling );
169 pass->addRenderState( cullFace );
173 entity->addComponent( material );
178 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D;
181 texture->setFormat( Qt3DRender::QAbstractTexture::SRGB8_Alpha8 );
182 texture->addTextureImage( textureImage );
184 entity->setTextureImage( textureImage );
@ Triangles
Triangle based rendering (default).
const QgsAbstractTerrainSettings * terrainSettings() const
Returns the terrain settings.
QgsTerrainGenerator * terrainGenerator() const
Returns the terrain generator.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Rendering context for preparation of 3D entities.
static void setTextureFiltering(Qt3DRender::QAbstractTexture *texture, const QgsMaterialContext &context)
Sets the default filtering options for a texture.
static QgsRectangle tryReprojectExtent2D(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs1, const QgsCoordinateReferenceSystem &crs2, const QgsCoordinateTransformContext &context)
Reprojects extent from crs1 to crs2 coordinate reference system with context context.
static constexpr double MINIMUM_VECTOR_Z_ESTIMATE
static constexpr double MAXIMUM_VECTOR_Z_ESTIMATE
static QgsMaterial * toMaterial(const QgsAbstractMaterialSettings *settings, Qgis::MaterialRenderingTechnique technique, const QgsMaterialContext &context)
Creates a new QgsMaterial object representing the material settings.
int mapTileResolution() const
Returns the resolution (in pixels) of the texture of a terrain tile.
A 3-dimensional box composed of x, y, z coordinates.
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Context settings for a material.
void setIsSelected(bool isSelected)
Sets whether the material should represent a selected state.
static QgsMaterialContext fromRenderContext(const Qgs3DRenderContext &context)
Constructs a material context from the settings in a 3D render context.
Base class for all materials used within QGIS 3D views.
Basic shading material used for rendering based on the Phong shading model with three color component...
double opacity() const
Returns the opacity of the surface.
QColor specular() const
Returns specular color component.
QColor ambient() const
Returns ambient color component.
double shininess() const
Returns shininess of the surface.
A rectangle specified with double values.
Type
Enumeration of the available terrain generators.
@ QuantizedMesh
Terrain is built from quantized mesh tiles.
@ Dem
Terrain is built from raster layer with digital elevation model.
@ Online
Terrain is built from downloaded tiles with digital elevation model.
@ Mesh
Terrain is built from mesh layer with z value on vertices.
@ Flat
The whole terrain is flat area.
QgsTerrainGenerator()
Create new terrain generator.
virtual Type type() const =0
What texture generator implementation is this.
~QgsTerrainGenerator() override
virtual QgsBox3D rootChunkBox3D(const Qgs3DMapSettings &map) const
Returns 3D box (in map coordinates) of the root chunk.
virtual float rootChunkError(const Qgs3DMapSettings &map) const
Returns error of the root chunk in world coordinates.
void applyMaterial(const TerrainTextureResources &resources, QgsTerrainTileEntity *entity, bool isShadingEnabled, const QgsPhongMaterialSettings &shadingMaterial, bool useTexture, const Qgs3DRenderContext &context)
Creates material component for the entity with the rendered map as a texture.
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
virtual QgsRectangle rootChunkExtent() const =0
extent of the terrain's root chunk in terrain's CRS
QgsTerrainEntity * mTerrain
QFuture< TerrainTextureResources > loadTextureResources(QgsChunkNode *node)
Asynchronously loads resources for creating texture.
QFuture< QgsChunkLoaderResult > updateChunk(QgsChunkNode *node) override
virtual void rootChunkHeightRange(float &hMin, float &hMax) const
Returns height range of the root chunk in world coordinates.
QFlags< Capability > Capabilities
Qt3DRender::QTexture2D * applyTexture(QgsTerrainTileEntity *entity, const QgsMaterialContext &context, const TerrainTextureResources &resources) const
Creates a new texture that is linked to the entity.
@ NoCapabilities
No specific capabilities.
virtual QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
const QgsTilingScheme & tilingScheme() const
Returns tiling scheme of the terrain.
virtual QgsTerrainGenerator::Capabilities capabilities() const
Returns flags containing the supported capabilities.
bool isValid() const
Returns whether the terrain generator is valid.
virtual void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the CRS associated with the terrain.
QgsRectangle tileToExtent(int x, int y, int z) const
Returns map coordinates of the extent of a tile.
#define QGIS_CHECK_MAIN_THREAD_ACCESS
QgsRectangle extentMapCrs