Skip to content
Permalink
Browse files

clone terrain generator before editing the resolution

set terrain in clone function
disconnect future watcher connections properly
  • Loading branch information
NEDJIMAbelgacem committed Jul 10, 2020
1 parent 059c9b4 commit 6b608b4e56ee26d8d44c3820694a500b8428f74d
@@ -218,15 +218,14 @@ QgsTerrainTileEntity *Qgs3DSceneExporter::getDemTerrainEntity( QgsTerrainEntity
{
// Just create a new tile (we don't need to export exact level of details as in the scene)
// create the entity synchronously and then it will be deleted once our scene exporter instance is deallocated
QgsDemTerrainGenerator *generator = static_cast<QgsDemTerrainGenerator *>( terrain->map3D().terrainGenerator() );
int oldResolution = generator->resolution();
QgsDemTerrainGenerator *generator = dynamic_cast<QgsDemTerrainGenerator *>( terrain->map3D().terrainGenerator()->clone() );
generator->setResolution( mTerrainResolution );
QgsDemTerrainTileLoader *loader = qobject_cast<QgsDemTerrainTileLoader *>( generator->createChunkLoader( node ) );
generator->heightMapGenerator()->waitForFinished();
if ( mExportTextures )
terrain->textureGenerator()->waitForFinished();
QgsTerrainTileEntity *tileEntity = qobject_cast<QgsTerrainTileEntity *>( loader->createEntity( this ) );
generator->setResolution( oldResolution );
delete generator;
return tileEntity;
}

@@ -45,6 +45,7 @@ void QgsDemTerrainGenerator::setCrs( const QgsCoordinateReferenceSystem &crs, co
QgsTerrainGenerator *QgsDemTerrainGenerator::clone() const
{
QgsDemTerrainGenerator *cloned = new QgsDemTerrainGenerator;
cloned->setTerrain( mTerrain );
cloned->mCrs = mCrs;
cloned->mLayer = mLayer;
cloned->mResolution = mResolution;
@@ -98,14 +99,10 @@ void QgsDemTerrainGenerator::resolveReferences( const QgsProject &project )

QgsChunkLoader *QgsDemTerrainGenerator::createChunkLoader( QgsChunkNode *node ) const
{
return new QgsDemTerrainTileLoader( mTerrain, node );
// A bit of a hack to make cloning terrain generator work properly
return new QgsDemTerrainTileLoader( mTerrain, node, const_cast<QgsDemTerrainGenerator *>( this ) );
}

//QgsChunkLoader *QgsDemTerrainGenerator::createSynchronousChunkLoader( QgsChunkNode *node ) const
//{
// return new QgsDemTerrainTileLoader( mTerrain, node, true );
//}

void QgsDemTerrainGenerator::updateGenerator()
{
QgsRasterLayer *dem = layer();
@@ -76,9 +76,6 @@ class _3D_EXPORT QgsDemTerrainGenerator : public QgsTerrainGenerator

QgsChunkLoader *createChunkLoader( QgsChunkNode *node ) const override SIP_FACTORY;

//! create a chunk loader that creates the node entity synchronously
// QgsChunkLoader *createSynchronousChunkLoader( QgsChunkNode *node ) const;

private:
void updateGenerator();

@@ -24,6 +24,7 @@
#include "qgsterrainentity_p.h"
#include "qgsterraintexturegenerator_p.h"
#include "qgsterraintileentity_p.h"
#include "qgsterraingenerator.h"

#include <Qt3DRender/QGeometryRenderer>

@@ -52,23 +53,21 @@ static void _heightMapMinMax( const QByteArray &heightMap, float &zMin, float &z
}


QgsDemTerrainTileLoader::QgsDemTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node )
QgsDemTerrainTileLoader::QgsDemTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node, QgsTerrainGenerator *terrainGenerator )
: QgsTerrainTileLoader( terrain, node )
, mResolution( 0 )
{

const Qgs3DMapSettings &map = terrain->map3D();

QgsDemHeightMapGenerator *heightMapGenerator = nullptr;
if ( map.terrainGenerator()->type() == QgsTerrainGenerator::Dem )
if ( terrainGenerator->type() == QgsTerrainGenerator::Dem )
{
QgsDemTerrainGenerator *generator = static_cast<QgsDemTerrainGenerator *>( map.terrainGenerator() );
QgsDemTerrainGenerator *generator = static_cast<QgsDemTerrainGenerator *>( terrainGenerator );
heightMapGenerator = generator->heightMapGenerator();
mSkirtHeight = generator->skirtHeight();
}
else if ( map.terrainGenerator()->type() == QgsTerrainGenerator::Online )
else if ( terrainGenerator->type() == QgsTerrainGenerator::Online )
{
QgsOnlineTerrainGenerator *generator = static_cast<QgsOnlineTerrainGenerator *>( map.terrainGenerator() );
QgsOnlineTerrainGenerator *generator = static_cast<QgsOnlineTerrainGenerator *>( terrainGenerator );
heightMapGenerator = generator->heightMapGenerator();
mSkirtHeight = generator->skirtHeight();
}
@@ -246,6 +245,11 @@ int QgsDemHeightMapGenerator::render( int x, int y, int z )

void QgsDemHeightMapGenerator::waitForFinished()
{
for ( QFutureWatcher<QByteArray> *fw : mJobs.keys() )
{
disconnect( fw, &QFutureWatcher<QByteArray>::finished, this, &QgsDemHeightMapGenerator::onFutureFinished );
disconnect( fw, &QFutureWatcher<QByteArray>::finished, fw, &QObject::deleteLater );
}
QVector<QFutureWatcher<QByteArray>*> toBeDeleted;
for ( QFutureWatcher<QByteArray> *fw : mJobs.keys() )
{
@@ -41,6 +41,7 @@
class QgsRasterDataProvider;
class QgsRasterLayer;
class QgsCoordinateTransformContext;
class QgsTerrainGenerator;

/**
* \ingroup 3d
@@ -52,7 +53,7 @@ class QgsDemTerrainTileLoader : public QgsTerrainTileLoader
Q_OBJECT
public:
//! Constructs loader for the given chunk node
QgsDemTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node );
QgsDemTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node, QgsTerrainGenerator *terrainGenerator );

Qt3DCore::QEntity *createEntity( Qt3DCore::QEntity *parent ) override;

@@ -24,12 +24,13 @@ QgsOnlineTerrainGenerator::~QgsOnlineTerrainGenerator() = default;

QgsChunkLoader *QgsOnlineTerrainGenerator::createChunkLoader( QgsChunkNode *node ) const
{
return new QgsDemTerrainTileLoader( mTerrain, node );
return new QgsDemTerrainTileLoader( mTerrain, node, const_cast<QgsOnlineTerrainGenerator *>( this ) );
}

QgsTerrainGenerator *QgsOnlineTerrainGenerator::clone() const
{
QgsOnlineTerrainGenerator *cloned = new QgsOnlineTerrainGenerator;
cloned->setTerrain( mTerrain );
cloned->mCrs = mCrs;
cloned->mExtent = mExtent;
cloned->mResolution = mResolution;
@@ -76,6 +76,8 @@ void QgsTerrainTextureGenerator::cancelJob( int jobId )

void QgsTerrainTextureGenerator::waitForFinished()
{
for ( QgsMapRendererSequentialJob *job : mJobs.keys() )
disconnect( job, &QgsMapRendererJob::finished, this, &QgsTerrainTextureGenerator::onRenderingFinished );
QVector<QgsMapRendererSequentialJob *> toBeDeleted;
for ( QgsMapRendererSequentialJob *mapJob : mJobs.keys() )
{

0 comments on commit 6b608b4

Please sign in to comment.
You can’t perform that action at this time.