23#include <Qt3DRender/QGeometryRenderer>
26#include "terrainchunkloader.h"
31class QuantizedMeshTerrainChunkLoader :
public TerrainChunkLoader
34 QuantizedMeshTerrainChunkLoader( Terrain *terrain, ChunkNode *node )
35 : TerrainChunkLoader( terrain, node )
38 const Map3D &map = mTerrain->map3D();
42 tileRect = map.terrainGenerator->terrainTilingScheme.tileToExtent( tx, ty, tz );
45 mapSettings.setLayers( map.layers() );
46 mapSettings.setOutputSize( QSize( map.tileTextureSize, map.tileTextureSize ) );
47 mapSettings.setDestinationCrs( map.crs );
48 mapSettings.setExtent( mTerrain->terrainToMapTransform().transformBoundingBox( tileRect ) );
60 virtual Qt3DCore::QEntity *createEntity( Qt3DCore::QEntity *parent )
62 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity;
66 Qt3DRender::QGeometryRenderer *mesh =
new Qt3DRender::QGeometryRenderer;
67 mesh->setGeometry(
new QuantizedMeshGeometry( qmt, mTerrain->map3D(), mapSettings.mapToPixel(), mTerrain->terrainToMapTransform(), mesh ) );
68 entity->addComponent( mesh );
72 createTextureComponent( entity );
76 Qt3DCore::QTransform *transform =
nullptr;
77 transform =
new Qt3DCore::QTransform();
78 entity->addComponent( transform );
80 const Map3D &map = mTerrain->map3D();
82 transform->setScale3D( QVector3D( 1.f, map.zExaggeration, 1.f ) );
85 float x0 = mapExtent.
xMinimum() - map.originX;
86 float y0 = mapExtent.
yMinimum() - map.originY;
87 float x1 = mapExtent.
xMaximum() - map.originX;
88 float y1 = mapExtent.
yMaximum() - map.originY;
89 float z0 = qmt->header.MinimumHeight, z1 = qmt->header.MaximumHeight;
91 node->setExactBbox( AABB( x0, z0 * map.zExaggeration, -y0, x1, z1 * map.zExaggeration, -y1 ) );
94 entity->setEnabled(
false );
95 entity->setParent( parent );
127 int multiplier = pow( 2, z );
135 return TerrainGenerator::QuantizedMesh;
160 return new QuantizedMeshTerrainChunkLoader(
mTerrain, node );
This class represents a coordinate reference system (CRS).
The QgsMapSettings class contains configuration for rendering of the map.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
QgsTerrainEntity * mTerrain
static void downloadTileIfMissing(int tx, int ty, int tz)
Downloads a tile to to a file in the local disk cache.
static QuantizedMeshTile * readTile(int tx, int ty, int tz, const QgsRectangle &extent)
Reads a tile from a file in the local disk cache.
QgsTerrainGenerator::Type type() const override
What texture generator implementation is this.
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.
int terrainBaseZ
Coordinates of the base tile.
QgsChunkLoader * createChunkLoader(QgsChunkNode *node) const override SIP_FACTORY
void readXml(const QDomElement &elem) override
Read terrain generator's configuration from XML.
QuantizedMeshTerrainGenerator()
void setBaseTileFromExtent(const QgsRectangle &extentInTerrainCrs)
Determines base tile from map extent.
void writeXml(QDomElement &elem) const override
Write terrain generator's configuration to XML.
QgsRectangle extent() const override
extent of the terrain in terrain's CRS