28 #include <Qt3DRender/QObjectPicker> 34 class TerrainMapUpdateJobFactory :
public QgsChunkQueueJobFactory
37 TerrainMapUpdateJobFactory( QgsTerrainTextureGenerator *textureGenerator )
38 : mTextureGenerator( textureGenerator )
42 QgsChunkQueueJob *createJob( QgsChunkNode *chunk )
override 44 return new TerrainMapUpdateJob( mTextureGenerator, chunk );
48 QgsTerrainTextureGenerator *mTextureGenerator =
nullptr;
55 QgsTerrainEntity::QgsTerrainEntity(
int maxLevel,
const Qgs3DMapSettings &map, Qt3DCore::QNode *parent )
56 : QgsChunkedEntity( map.terrainGenerator()->rootChunkBbox( map ),
57 map.terrainGenerator()->rootChunkError( map ),
58 map.maxTerrainScreenError(), maxLevel, map.terrainGenerator(), parent )
69 connectToLayersRepaintRequest();
73 mTextureGenerator =
new QgsTerrainTextureGenerator( map );
75 mUpdateJobFactory.reset(
new TerrainMapUpdateJobFactory( mTextureGenerator ) );
77 mTerrainPicker =
new Qt3DRender::QObjectPicker;
80 addComponent( mTerrainPicker );
83 QgsTerrainEntity::~QgsTerrainEntity()
89 delete mTextureGenerator;
90 delete mTerrainToMapTransform;
93 void QgsTerrainEntity::onShowBoundingBoxesChanged()
95 setShowBoundingBoxes( mMap.showTerrainBoundingBoxes() );
99 void QgsTerrainEntity::invalidateMapImages()
103 updateNodes( mActiveNodes, mUpdateJobFactory.get() );
107 QList<QgsChunkNode *> inactiveNodes;
108 Q_FOREACH ( QgsChunkNode *node, mRootNode->descendants() )
110 if ( !node->entity() )
112 if ( mActiveNodes.contains( node ) )
114 inactiveNodes << node;
117 updateNodes( inactiveNodes, mUpdateJobFactory.get() );
119 setNeedsUpdate(
true );
122 void QgsTerrainEntity::onLayersChanged()
124 connectToLayersRepaintRequest();
125 invalidateMapImages();
128 void QgsTerrainEntity::connectToLayersRepaintRequest()
135 mLayers = mMap.layers();
147 TerrainMapUpdateJob::TerrainMapUpdateJob( QgsTerrainTextureGenerator *textureGenerator, QgsChunkNode *node )
148 : QgsChunkQueueJob( node )
149 , mTextureGenerator( textureGenerator )
151 QgsTerrainTileEntity *entity = qobject_cast<QgsTerrainTileEntity *>( node->entity() );
152 connect( textureGenerator, &QgsTerrainTextureGenerator::tileReady,
this, &TerrainMapUpdateJob::onTileReady );
153 mJobId = textureGenerator->render( entity->textureImage()->imageExtent(), entity->textureImage()->imageDebugText() );
156 void TerrainMapUpdateJob::cancel()
159 mTextureGenerator->cancelJob( mJobId );
163 void TerrainMapUpdateJob::onTileReady(
int jobId,
const QImage &image )
165 if ( mJobId == jobId )
167 QgsTerrainTileEntity *entity = qobject_cast<QgsTerrainTileEntity *>( mNode->entity() );
168 entity->textureImage()->setImage( image );
Base class for all map layer types.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
void layersChanged()
Emitted when the list of map layers for terrain texture has changed.
QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
3 Definition of the world
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain's bounding boxes are shown has changed.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void showTerrainTilesInfoChanged()
Emitted when the flag whether terrain's tile info is shown has changed.
void showLabelsChanged()
Emitted when the flag whether labels are displayed on terrain tiles has changed.
void setTerrain(QgsTerrainEntity *t)
Sets terrain entity for the generator (does not transfer ownership)
void backgroundColorChanged()
Emitted when the background color has changed.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data...