Skip to content
Permalink
Browse files

Changed vector layer parsing function

  • Loading branch information
NEDJIMAbelgacem committed Jul 11, 2020
1 parent 38b72ef commit e233fcab149307ce69145ae8cd7ca4ece25b2e7e
Showing with 45 additions and 32 deletions.
  1. +1 −1 src/3d/qgs3dmapscene.cpp
  2. +38 −28 src/3d/qgs3dsceneexporter.cpp
  3. +6 −3 src/3d/qgs3dsceneexporter.h
@@ -787,7 +787,7 @@ void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
switch ( layerType )
{
case QgsMapLayerType::VectorLayer:
if ( !exporter.parseVectorLayerEntity( rootEntity ) )
if ( !exporter.parseVectorLayerEntity( rootEntity, qobject_cast<QgsVectorLayer *>(layer) ) )
notParsedLayers.push_back( layer->name() );
break;
case QgsMapLayerType::RasterLayer:
@@ -55,6 +55,11 @@
#include "qgsmeshlayer.h"
#include "qgsmesh3dentity_p.h"
#include "qgsmeshterraingenerator.h"
#include "qgsvectorlayer.h"
#include "qgsabstract3drenderer.h"
#include "qgsabstractvectorlayer3drenderer.h"
#include "qgsvectorlayer3drenderer.h"
#include "qgspolygon3dsymbol.h"

#include <numeric>

@@ -115,40 +120,45 @@ Qgs3DSceneExporter::Qgs3DSceneExporter( Qt3DCore::QNode *parent )

}

bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity )
{
if ( entity == nullptr )
return false;
bool isValid = false;
// We iterate over every component and find components that represent a tessellated geometry
for ( Qt3DCore::QComponent *c : entity->components() )
{
Qt3DRender::QGeometryRenderer *comp = qobject_cast<Qt3DRender::QGeometryRenderer *>( c );
if ( comp == nullptr )
continue;
Qt3DRender::QGeometry *geom = comp->geometry();
bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer ) {
QgsAbstract3DRenderer* abstractRenderer = layer->renderer3D();
QString rendererType = abstractRenderer->type();

QgsTessellatedPolygonGeometry *tessellated = qobject_cast<QgsTessellatedPolygonGeometry *>( geom );
if ( tessellated != nullptr )
if ( rendererType == "mesh" )
{
// TODO: handle mesh layer
}
else
{
QgsAbstractVectorLayer3DRenderer *abstractVectorRenderer = dynamic_cast< QgsAbstractVectorLayer3DRenderer *>( abstractRenderer );
if ( rendererType == "rulebased" )
{
processPolygonGeometry( tessellated );
isValid = true;
continue;
// TODO: handle rule based renderers
}
else
{
QgsVectorLayer3DRenderer *vectorLayerRenderer = dynamic_cast< QgsVectorLayer3DRenderer *>( abstractVectorRenderer );
const QgsAbstract3DSymbol *symbol = vectorLayerRenderer->symbol();
QString symbolType = symbol->type();
if (symbolType == "polygon")
{
QList<QgsTessellatedPolygonGeometry *> geometries = entity->findChildren<QgsTessellatedPolygonGeometry *>();
const QgsPolygon3DSymbol *polygonSymbol = dynamic_cast<const QgsPolygon3DSymbol *>( symbol );
for (QgsTessellatedPolygonGeometry * polygonGeometry : geometries)
processPolygonGeometry( polygonGeometry, polygonSymbol);
return geometries.size() != 0;
}
else if (symbolType == "line")
{

// pocessPoistionAttributes(geom);
}
}
else if (symbolType == "point")
{

for ( QObject *child : entity->children() )
{
Qt3DCore::QEntity *childEntity = qobject_cast<Qt3DCore::QEntity *>( child );
if ( childEntity != nullptr )
{
bool validChild = parseVectorLayerEntity( childEntity );
isValid = isValid || validChild;
}
}
}
return isValid;
return false;
}

void Qgs3DSceneExporter::parseTerrain( QgsTerrainEntity *terrain )
@@ -325,7 +335,7 @@ void Qgs3DSceneExporter::parseDemTile( QgsTerrainTileEntity *tileEntity )
}
}

void Qgs3DSceneExporter::processPolygonGeometry( QgsTessellatedPolygonGeometry *geom )
void Qgs3DSceneExporter::processPolygonGeometry( QgsTessellatedPolygonGeometry *geom, const QgsPolygon3DSymbol *polygonSymbol )
{
Qgs3DExportObject *object = new Qgs3DExportObject( getObjectName( "polygon_geometry" ), "", this );
mObjects.push_back( object );
@@ -31,6 +31,8 @@ class QgsDemTerrainGenerator;
class QgsChunkNode;
class Qgs3DExportObject;
class QgsTerrainTextureGenerator;
class QgsVectorLayer;
class QgsPolygon3DSymbol;

/**
* \brief The Qgs3DSceneExporter class
@@ -47,9 +49,10 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity

/**
* Creates necessary export objects from entity if it represents valid vector layer entity
* Returns false if the entity doesn't represent a vector layer
* Returns false if the no 3D object was extracted from the vector layer
*/
bool parseVectorLayerEntity( Qt3DCore::QEntity *entity );
bool parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer );

//! Creates terrain export objects from the terrain entity
void parseTerrain( QgsTerrainEntity *terrain );
//! Saves the scene to a .obj file
@@ -88,7 +91,7 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity
//! Processes the attribute directly by taking a position buffer and converting it to Qgs3DExportObject
void pocessPoistionAttributes( Qt3DRender::QGeometry *geometry );
//! constructs Qgs3DExportObject from the polygon geometry
void processPolygonGeometry( QgsTessellatedPolygonGeometry *geom );
void processPolygonGeometry( QgsTessellatedPolygonGeometry *geom, const QgsPolygon3DSymbol *polygonSymbol );

//! Returns a tile entity that contains the geometry to be exported and necessary scaling parameters
QgsTerrainTileEntity *getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );

0 comments on commit e233fca

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