Skip to content
Permalink
Browse files

altitude clamping with terrain elevation offset

  • Loading branch information
NEDJIMAbelgacem committed Nov 10, 2020
1 parent eefc978 commit ed363ab20b58e89af6000f5b5dcfb13a409836cf
@@ -588,7 +588,7 @@ void Qgs3DMapSettings::setTerrainElevationOffset( float offset )
if ( mTerrainElevationOffset == offset )
return;
mTerrainElevationOffset = offset;
emit terrainElevationOffsetChanged();
emit terrainElevationOffsetChanged( mTerrainElevationOffset );
}

float Qgs3DMapSettings::maxTerrainGroundError() const
@@ -557,7 +557,7 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
* Emitted when the terrain elevation offset is changed
* \since QGIS 3.16
*/
void terrainElevationOffsetChanged();
void terrainElevationOffsetChanged( float newElevation );

/**
* Emitted when terrain shading enabled flag or terrain shading material has changed
@@ -389,7 +389,7 @@ Qt3DCore::QEntity *QgsRuleBased3DRenderer::createEntity( const Qgs3DMapSettings
double zMin, zMax;
Qgs3DUtils::estimateVectorLayerZRange( vl, zMin, zMax );

return new QgsRuleBasedChunkedEntity( vl, zMin, zMax, tilingSettings(), mRootRule, map );
return new QgsRuleBasedChunkedEntity( vl, zMin + map.terrainElevationOffset(), zMax + map.terrainElevationOffset(), tilingSettings(), mRootRule, map );
}

void QgsRuleBased3DRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
@@ -171,6 +171,11 @@ QgsRuleBasedChunkedEntity::QgsRuleBasedChunkedEntity( QgsVectorLayer *vl, double
: QgsChunkedEntity( -1, // max. allowed screen error (negative tau means that we need to go until leaves are reached)
new QgsRuleBasedChunkLoaderFactory( map, vl, rootRule, tilingSettings.zoomLevelsCount() - 1, zMin, zMax ), true )
{
mTransform = new Qt3DCore::QTransform;
mTransform->setTranslation( QVector3D( 0.0f, map.terrainElevationOffset(), 0.0f ) );
this->addComponent( mTransform );
connect( &map, &Qgs3DMapSettings::terrainElevationOffsetChanged, this, &QgsRuleBasedChunkedEntity::onTerrainElevationOffsetChanged );

setShowBoundingBoxes( tilingSettings.showBoundingBoxes() );
}

@@ -180,4 +185,9 @@ QgsRuleBasedChunkedEntity::~QgsRuleBasedChunkedEntity()
cancelActiveJobs();
}

void QgsRuleBasedChunkedEntity::onTerrainElevationOffsetChanged( float newOffset )
{
mTransform->setTranslation( QVector3D( 0.0f, newOffset, 0.0f ) );
}

/// @endcond
@@ -40,6 +40,10 @@ class QgsVectorLayerFeatureSource;
class QgsAbstract3DSymbol;
class QgsFeature3DHandler;

namespace Qt3DCore
{
class QTransform;
}

/**
* \ingroup 3d
@@ -113,6 +117,10 @@ class QgsRuleBasedChunkedEntity : public QgsChunkedEntity
explicit QgsRuleBasedChunkedEntity( QgsVectorLayer *vl, double zMin, double zMax, const QgsVectorLayer3DTilingSettings &tilingSettings, QgsRuleBased3DRenderer::Rule *rootRule, const Qgs3DMapSettings &map );

~QgsRuleBasedChunkedEntity();
private slots:
void onTerrainElevationOffsetChanged( float newOffset );
private:
Qt3DCore::QTransform *mTransform = nullptr;
};

/// @endcond
@@ -73,7 +73,7 @@ Qt3DCore::QEntity *QgsVectorLayer3DRenderer::createEntity( const Qgs3DMapSetting
double zMin, zMax;
Qgs3DUtils::estimateVectorLayerZRange( vl, zMin, zMax );

return new QgsVectorLayerChunkedEntity( vl, zMin, zMax, tilingSettings(), mSymbol.get(), map );
return new QgsVectorLayerChunkedEntity( vl, zMin + map.terrainElevationOffset(), zMax + + map.terrainElevationOffset(), tilingSettings(), mSymbol.get(), map );
}

void QgsVectorLayer3DRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
@@ -31,6 +31,10 @@

class QgsVectorLayer;

namespace Qt3DCore
{
class QTransform;
}

/**
* \ingroup core
@@ -77,6 +81,7 @@ class _3D_EXPORT QgsVectorLayer3DRenderer : public QgsAbstractVectorLayer3DRende

private:
std::unique_ptr<QgsAbstract3DSymbol> mSymbol; //!< 3D symbol that defines appearance
Qt3DCore::QTransform *mTransform = nullptr;

private:
#ifdef SIP_RUN
@@ -32,6 +32,7 @@
#include "qgs3dsymbolregistry.h"

#include <QtConcurrent>
#include <Qt3DCore/QTransform>

///@cond PRIVATE

@@ -157,6 +158,12 @@ QgsVectorLayerChunkedEntity::QgsVectorLayerChunkedEntity( QgsVectorLayer *vl, do
: QgsChunkedEntity( -1, // max. allowed screen error (negative tau means that we need to go until leaves are reached)
new QgsVectorLayerChunkLoaderFactory( map, vl, symbol, tilingSettings.zoomLevelsCount() - 1, zMin, zMax ), true )
{
mTransform = new Qt3DCore::QTransform;
mTransform->setTranslation( QVector3D( 0.0f, map.terrainElevationOffset(), 0.0f ) );
this->addComponent( mTransform );

connect( &map, &Qgs3DMapSettings::terrainElevationOffsetChanged, this, &QgsVectorLayerChunkedEntity::onTerrainElevationOffsetChanged );

setShowBoundingBoxes( tilingSettings.showBoundingBoxes() );
}

@@ -166,4 +173,10 @@ QgsVectorLayerChunkedEntity::~QgsVectorLayerChunkedEntity()
cancelActiveJobs();
}

void QgsVectorLayerChunkedEntity::onTerrainElevationOffsetChanged( float newOffset )
{
qDebug() << "QgsVectorLayerChunkedEntity::onTerrainElevationOffsetChanged";
mTransform->setTranslation( QVector3D( 0.0f, newOffset, 0.0f ) );
}

/// @endcond
@@ -40,6 +40,11 @@ class QgsVectorLayerFeatureSource;
class QgsAbstract3DSymbol;
class QgsFeature3DHandler;

namespace Qt3DCore
{
class QTransform;
}

#include <QFutureWatcher>


@@ -112,6 +117,11 @@ class QgsVectorLayerChunkedEntity : public QgsChunkedEntity
explicit QgsVectorLayerChunkedEntity( QgsVectorLayer *vl, double zMin, double zMax, const QgsVectorLayer3DTilingSettings &tilingSettings, QgsAbstract3DSymbol *symbol, const Qgs3DMapSettings &map );

~QgsVectorLayerChunkedEntity();
private slots:
void onTerrainElevationOffsetChanged( float newOffset );

private:
Qt3DCore::QTransform *mTransform = nullptr;
};

/// @endcond
@@ -187,9 +187,9 @@ void QgsTerrainEntity::connectToLayersRepaintRequest()
}
}

void QgsTerrainEntity::onTerrainElevationOffsetChanged()
void QgsTerrainEntity::onTerrainElevationOffsetChanged( float newOffset )
{
mTerrainTransform->setTranslation( QVector3D( 0.0f, mMap.terrainElevationOffset(), 0.0f ) );
mTerrainTransform->setTranslation( QVector3D( 0.0f, newOffset, 0.0f ) );
}

float QgsTerrainEntity::terrainElevationOffset() const
@@ -92,7 +92,7 @@ class QgsTerrainEntity : public QgsChunkedEntity
void onShowBoundingBoxesChanged();
void invalidateMapImages();
void onLayersChanged();
void onTerrainElevationOffsetChanged();
void onTerrainElevationOffsetChanged( float newOffset );

private:

0 comments on commit ed363ab

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