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 );
127 int multiplier = pow( 2, z );
135 return TerrainGenerator::QuantizedMesh;
160 return new QuantizedMeshTerrainChunkLoader(
mTerrain, node );