23 #include <Qt3DRender/QGeometryRenderer> 25 #include "chunknode.h" 26 #include "terrainchunkloader.h" 31 class 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 );
115 terrainBaseX = terrainBaseY = terrainBaseZ = 0;
121 terrainTilingScheme.extentToTile( extentInTerrainCrs, terrainBaseX, terrainBaseY, terrainBaseZ );
127 int multiplier = pow( 2, z );
128 tx = terrainBaseX * multiplier + x;
129 ty = terrainBaseY * multiplier + y;
130 tz = terrainBaseZ + z;
135 return TerrainGenerator::QuantizedMesh;
140 return terrainTilingScheme.tileToExtent( terrainBaseX, terrainBaseY, terrainBaseZ );
145 elem.setAttribute(
"base-x", terrainBaseX );
146 elem.setAttribute(
"base-y", terrainBaseY );
147 elem.setAttribute(
"base-z", terrainBaseZ );
152 terrainBaseX = elem.attribute(
"base-x" ).toInt();
153 terrainBaseY = elem.attribute(
"base-y" ).toInt();
154 terrainBaseZ = elem.attribute(
"base-z" ).toInt();
160 return new QuantizedMeshTerrainChunkLoader( mTerrain, node );
A rectangle specified with double values.
static QuantizedMeshTile * readTile(int tx, int ty, int tz, const QgsRectangle &extent)
Reads a tile from a file in the local disk cache.
void readXml(const QDomElement &elem) override
Read terrain generator's configuration from XML.
QuantizedMeshTerrainGenerator()
QgsChunkLoader * createChunkLoader(QgsChunkNode *node) const override SIP_FACTORY
QgsRectangle extent() const override
extent of the terrain in terrain's CRS
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...
3 Terrain generator using downloaded terrain tiles using quantized mesh specification ...
The QgsMapSettings class contains configuration for rendering of the map.
void writeXml(QDomElement &elem) const override
Write terrain generator's configuration to XML.
3 Stores vertex and index buffer for one tile of quantized mesh terrain.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
This class represents a coordinate reference system (CRS).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void setBaseTileFromExtent(const QgsRectangle &extentInTerrainCrs)
Determines base tile from map extent.
static void downloadTileIfMissing(int tx, int ty, int tz)
Downloads a tile to to a file in the local disk cache.