Skip to content

Commit

Permalink
Law & order in the main "3d" directory
Browse files Browse the repository at this point in the history
Just renames / cleanup - no code changes
  • Loading branch information
wonder-sk committed Sep 27, 2017
1 parent 97b46d9 commit 2b31127
Show file tree
Hide file tree
Showing 23 changed files with 213 additions and 169 deletions.
16 changes: 8 additions & 8 deletions src/3d/qgs3dmapscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, Qt3DExtras::QForwardR

// create entities of renderers

Q_FOREACH ( const QgsAbstract3DRenderer *renderer, map.renderers )
Q_FOREACH ( const QgsAbstract3DRenderer *renderer, map.renderers() )
{
Qt3DCore::QEntity *newEntity = renderer->createEntity( map );
newEntity->setParent( this );
Expand Down Expand Up @@ -128,11 +128,11 @@ Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, Qt3DExtras::QForwardR
meshEntity->setParent( this );
#endif

if ( map.skybox )
if ( map.hasSkyboxEnabled() )
{
Qt3DExtras::QSkyboxEntity *skybox = new Qt3DExtras::QSkyboxEntity;
skybox->setBaseName( map.skyboxFileBase );
skybox->setExtension( map.skyboxFileExtension );
skybox->setBaseName( map.skyboxFileBase() );
skybox->setExtension( map.skyboxFileExtension() );
skybox->setParent( this );

// docs say frustum culling must be disabled for skybox.
Expand Down Expand Up @@ -166,7 +166,7 @@ QgsChunkedEntity::SceneState _sceneState( QgsCameraController *cameraController

void Qgs3DMapScene::onCameraChanged()
{
Q_FOREACH ( QgsChunkedEntity *entity, chunkEntities )
Q_FOREACH ( QgsChunkedEntity *entity, mChunkEntities )
{
if ( entity->isEnabled() )
entity->update( _sceneState( mCameraController ) );
Expand Down Expand Up @@ -244,7 +244,7 @@ void Qgs3DMapScene::onFrameTriggered( float dt )
{
mCameraController->frameTriggered( dt );

Q_FOREACH ( QgsChunkedEntity *entity, chunkEntities )
Q_FOREACH ( QgsChunkedEntity *entity, mChunkEntities )
{
if ( entity->isEnabled() && entity->needsUpdate() )
{
Expand All @@ -258,7 +258,7 @@ void Qgs3DMapScene::createTerrain()
{
if ( mTerrain )
{
chunkEntities.removeOne( mTerrain );
mChunkEntities.removeOne( mTerrain );

mTerrain->deleteLater();
mTerrain = nullptr;
Expand Down Expand Up @@ -286,7 +286,7 @@ void Qgs3DMapScene::createTerrainDeferred()

mCameraController->addTerrainPicker( mTerrain->terrainPicker() );

chunkEntities << mTerrain;
mChunkEntities << mTerrain;

onCameraChanged(); // force update of the new terrain

Expand Down
2 changes: 1 addition & 1 deletion src/3d/qgs3dmapscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
QgsTerrainEntity *mTerrain;
//! Forward renderer provided by 3D window
Qt3DExtras::QForwardRenderer *mForwardRenderer;
QList<QgsChunkedEntity *> chunkEntities;
QList<QgsChunkedEntity *> mChunkEntities;
//! Keeps track of entities that belong to a particular layer
QMap<QgsMapLayer *, Qt3DCore::QEntity *> mLayerEntities;
bool mTerrainUpdateScheduled = false;
Expand Down
87 changes: 52 additions & 35 deletions src/3d/qgs3dmapsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,26 @@


Qgs3DMapSettings::Qgs3DMapSettings()
: originX( 0 )
, originY( 0 )
, originZ( 0 )
, skybox( false )
: mOriginX( 0 )
, mOriginY( 0 )
, mOriginZ( 0 )
, mBackgroundColor( Qt::black )
, mTerrainVerticalScale( 1 )
, mMapTileResolution( 512 )
, mMaxTerrainScreenError( 3.f )
, mMaxTerrainGroundError( 1.f )
, mShowTerrainBoundingBoxes( false )
, mShowTerrainTileInfo( false )
, mSkyboxEnabled( false )
{
}

Qgs3DMapSettings::Qgs3DMapSettings( const Qgs3DMapSettings &other )
: QObject()
, originX( other.originX )
, originY( other.originY )
, originZ( other.originZ )
, crs( other.crs )
, skybox( other.skybox )
, skyboxFileBase( other.skyboxFileBase )
, skyboxFileExtension( other.skyboxFileExtension )
, mOriginX( other.mOriginX )
, mOriginY( other.mOriginY )
, mOriginZ( other.mOriginZ )
, mCrs( other.mCrs )
, mBackgroundColor( other.mBackgroundColor )
, mTerrainVerticalScale( other.mTerrainVerticalScale )
, mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
Expand All @@ -45,27 +42,30 @@ Qgs3DMapSettings::Qgs3DMapSettings( const Qgs3DMapSettings &other )
, mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
, mShowTerrainTileInfo( other.mShowTerrainTileInfo )
, mLayers( other.mLayers )
, mSkyboxEnabled( other.mSkyboxEnabled )
, mSkyboxFileBase( other.mSkyboxFileBase )
, mSkyboxFileExtension( other.mSkyboxFileExtension )
{
Q_FOREACH ( QgsAbstract3DRenderer *renderer, other.renderers )
Q_FOREACH ( QgsAbstract3DRenderer *renderer, other.mRenderers )
{
renderers << renderer->clone();
mRenderers << renderer->clone();
}
}

Qgs3DMapSettings::~Qgs3DMapSettings()
{
qDeleteAll( renderers );
qDeleteAll( mRenderers );
}

void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
QDomElement elemOrigin = elem.firstChildElement( "origin" );
originX = elemOrigin.attribute( "x" ).toDouble();
originY = elemOrigin.attribute( "y" ).toDouble();
originZ = elemOrigin.attribute( "z" ).toDouble();
mOriginX = elemOrigin.attribute( "x" ).toDouble();
mOriginY = elemOrigin.attribute( "y" ).toDouble();
mOriginZ = elemOrigin.attribute( "z" ).toDouble();

QDomElement elemCrs = elem.firstChildElement( "crs" );
crs.readXml( elemCrs );
mCrs.readXml( elemCrs );

QDomElement elemTerrain = elem.firstChildElement( "terrain" );
mTerrainVerticalScale = elemTerrain.attribute( "exaggeration", "1" ).toFloat();
Expand Down Expand Up @@ -97,13 +97,13 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
else // "flat"
{
QgsFlatTerrainGenerator *flatGen = new QgsFlatTerrainGenerator;
flatGen->setCrs( crs );
flatGen->setCrs( mCrs );
mTerrainGenerator.reset( flatGen );
}
mTerrainGenerator->readXml( elemTerrainGenerator );

qDeleteAll( renderers );
renderers.clear();;
qDeleteAll( mRenderers );
mRenderers.clear();

QDomElement elemRenderers = elem.firstChildElement( "renderers" );
QDomElement elemRenderer = elemRenderers.firstChildElement( "renderer" );
Expand All @@ -119,15 +119,15 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
if ( renderer )
{
renderer->readXml( elemRenderer, context );
renderers.append( renderer );
mRenderers.append( renderer );
}
elemRenderer = elemRenderer.nextSiblingElement( "renderer" );
}

QDomElement elemSkybox = elem.firstChildElement( "skybox" );
skybox = elemSkybox.attribute( "enabled", "0" ).toInt();
skyboxFileBase = elemSkybox.attribute( "file-base" );
skyboxFileExtension = elemSkybox.attribute( "file-ext" );
mSkyboxEnabled = elemSkybox.attribute( "enabled", "0" ).toInt();
mSkyboxFileBase = elemSkybox.attribute( "file-base" );
mSkyboxFileExtension = elemSkybox.attribute( "file-ext" );

QDomElement elemDebug = elem.firstChildElement( "debug" );
mShowTerrainBoundingBoxes = elemDebug.attribute( "bounding-boxes", "0" ).toInt();
Expand All @@ -139,13 +139,13 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
QDomElement elem = doc.createElement( "qgis3d" );

QDomElement elemOrigin = doc.createElement( "origin" );
elemOrigin.setAttribute( "x", QString::number( originX ) );
elemOrigin.setAttribute( "y", QString::number( originY ) );
elemOrigin.setAttribute( "z", QString::number( originZ ) );
elemOrigin.setAttribute( "x", QString::number( mOriginX ) );
elemOrigin.setAttribute( "y", QString::number( mOriginY ) );
elemOrigin.setAttribute( "z", QString::number( mOriginZ ) );
elem.appendChild( elemOrigin );

QDomElement elemCrs = doc.createElement( "crs" );
crs.writeXml( elemCrs, doc );
mCrs.writeXml( elemCrs, doc );
elem.appendChild( elemCrs );

QDomElement elemTerrain = doc.createElement( "terrain" );
Expand All @@ -168,7 +168,7 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
elem.appendChild( elemTerrain );

QDomElement elemRenderers = doc.createElement( "renderers" );
Q_FOREACH ( const QgsAbstract3DRenderer *renderer, renderers )
Q_FOREACH ( const QgsAbstract3DRenderer *renderer, mRenderers )
{
QDomElement elemRenderer = doc.createElement( "renderer" );
elemRenderer.setAttribute( "type", renderer->type() );
Expand All @@ -178,10 +178,10 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
elem.appendChild( elemRenderers );

QDomElement elemSkybox = doc.createElement( "skybox" );
elemSkybox.setAttribute( "enabled", skybox ? 1 : 0 );
elemSkybox.setAttribute( "enabled", mSkyboxEnabled ? 1 : 0 );
// TODO: use context for relative paths, maybe explicitly list all files(?)
elemSkybox.setAttribute( "file-base", skyboxFileBase );
elemSkybox.setAttribute( "file-ext", skyboxFileExtension );
elemSkybox.setAttribute( "file-base", mSkyboxFileBase );
elemSkybox.setAttribute( "file-ext", mSkyboxFileExtension );
elem.appendChild( elemSkybox );

QDomElement elemDebug = doc.createElement( "debug" );
Expand All @@ -202,13 +202,25 @@ void Qgs3DMapSettings::resolveReferences( const QgsProject &project )

mTerrainGenerator->resolveReferences( project );

for ( int i = 0; i < renderers.count(); ++i )
for ( int i = 0; i < mRenderers.count(); ++i )
{
QgsAbstract3DRenderer *renderer = renderers[i];
QgsAbstract3DRenderer *renderer = mRenderers[i];
renderer->resolveReferences( project );
}
}

void Qgs3DMapSettings::setOrigin( double originX, double originY, double originZ )
{
mOriginX = originX;
mOriginY = originY;
mOriginZ = originZ;
}

void Qgs3DMapSettings::setCrs( const QgsCoordinateReferenceSystem &crs )
{
mCrs = crs;
}

void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
{
if ( color == mBackgroundColor )
Expand Down Expand Up @@ -327,6 +339,11 @@ void Qgs3DMapSettings::setTerrainGenerator( QgsTerrainGenerator *gen )
emit terrainGeneratorChanged();
}

void Qgs3DMapSettings::setRenderers( const QList<QgsAbstract3DRenderer *> &renderers )
{
mRenderers = renderers;
}

void Qgs3DMapSettings::setShowTerrainBoundingBoxes( bool enabled )
{
if ( mShowTerrainBoundingBoxes == enabled )
Expand Down
50 changes: 37 additions & 13 deletions src/3d/qgs3dmapsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,19 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
//! Resolves references to other objects (map layers) after the call to readXml()
void resolveReferences( const QgsProject &project );

double originX, originY, originZ; //!< Coordinates in map CRS at which our 3D world has origin (0,0,0)
QgsCoordinateReferenceSystem crs; //!< Destination coordinate system of the world (TODO: not needed? can be
//! Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
void setOrigin( double originX, double originY, double originZ );
//! Returns X coordinate in map CRS at which 3D scene has origin (zero)
double originX() const { return mOriginX; }
//! Returns Y coordinate in map CRS at which 3D scene has origin (zero)
double originY() const { return mOriginY; }
//! Returns Z coordinate in map CRS at which 3D scene has origin (zero)
double originZ() const { return mOriginZ; }

//! Sets coordinate reference system used in the 3D scene
void setCrs( const QgsCoordinateReferenceSystem &crs );
//! Returns coordinate reference system used in the 3D scene
QgsCoordinateReferenceSystem crs() const { return mCrs; }

//! Sets background color of the 3D map view
void setBackgroundColor( const QColor &color );
Expand Down Expand Up @@ -99,19 +110,26 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject

//! Sets terrain generator. It takes care of producing terrain tiles from the input data.
//! Takes ownership of the generator
void setTerrainGenerator( QgsTerrainGenerator *gen );
void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER );
//! Returns terrain generator. It takes care of producing terrain tiles from the input data.
QgsTerrainGenerator *terrainGenerator() const { return mTerrainGenerator.get(); }

//
// 3D renderers
//

QList<QgsAbstract3DRenderer *> renderers; //!< Stuff to render as 3D object

bool skybox; //!< Whether to render skybox
QString skyboxFileBase;
QString skyboxFileExtension;
//! Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
//! Returns list of extra 3D renderers
QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }

//! Sets skybox configuration. When enabled, map scene will try to load six texture files
//! using the following syntax of filenames: "[base]_[side][extension]" where [side] is one
//! of the following: posx/posy/posz/negx/negy/negz and [base] and [extension] are the arguments
//! passed this method.
void setSkybox( bool enabled, const QString &fileBase = QString(), const QString &fileExtension = QString() );
//! Returns whether skybox is enabled
bool hasSkyboxEnabled() const { return mSkyboxEnabled; }
//! Returns base part of filenames of skybox (see setSkybox())
QString skyboxFileBase() const { return mSkyboxFileBase; }
//! Returns extension part of filenames of skybox (see setSkybox())
QString skyboxFileExtension() const { return mSkyboxFileExtension; }

//! Sets whether to display bounding boxes of terrain tiles (for debugging)
void setShowTerrainBoundingBoxes( bool enabled );
Expand Down Expand Up @@ -145,8 +163,10 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
void showTerrainTilesInfoChanged();

private:
double mOriginX, mOriginY, mOriginZ; //!< Coordinates in map CRS at which our 3D world has origin (0,0,0)
QgsCoordinateReferenceSystem mCrs; //!< Destination coordinate system of the world
QColor mBackgroundColor; //!< Background color of the scene
QColor mSelectionColor;
QColor mSelectionColor; //!< Color to be used for selected map features
double mTerrainVerticalScale; //!< Multiplier of terrain heights to make the terrain shape more pronounced
std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator; //!< Implementation of the terrain generation
int mMapTileResolution; //!< Size of map textures of tiles in pixels (width/height)
Expand All @@ -155,6 +175,10 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
bool mShowTerrainBoundingBoxes; //!< Whether to show bounding boxes of entities - useful for debugging
bool mShowTerrainTileInfo; //!< Whether to draw extra information about terrain tiles to the textures - useful for debugging
QList<QgsMapLayerRef> mLayers; //!< Layers to be rendered
QList<QgsAbstract3DRenderer *> mRenderers; //!< Extra stuff to render as 3D object
bool mSkyboxEnabled; //!< Whether to render skybox
QString mSkyboxFileBase; //!< Base part of the files with skybox textures
QString mSkyboxFileExtension; //!< Extension part of the files with skybox textures
};


Expand Down
2 changes: 1 addition & 1 deletion src/3d/qgs3dutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ QList<QVector3D> Qgs3DUtils::positions( const Qgs3DMapSettings &map, QgsVectorLa
QgsPoint *pt = static_cast<QgsPoint *>( g );
// TODO: use Z coordinates if the point is 3D
float h = map.terrainGenerator()->heightAt( pt->x(), pt->y(), map ) * map.terrainVerticalScale();
positions.append( QVector3D( pt->x() - map.originX, h, -( pt->y() - map.originY ) ) );
positions.append( QVector3D( pt->x() - map.originX(), h, -( pt->y() - map.originY() ) ) );
//qDebug() << positions.last();
}
else
Expand Down
Loading

0 comments on commit 2b31127

Please sign in to comment.