Skip to content
Permalink
Browse files

Added buffered lines export

  • Loading branch information
NEDJIMAbelgacem committed Jul 11, 2020
1 parent e233fca commit 9fe793ae965a5d2150eddebb8aba195e1080d7cb
Showing with 46 additions and 10 deletions.
  1. +1 −1 src/3d/qgs3dmapscene.cpp
  2. +42 −9 src/3d/qgs3dsceneexporter.cpp
  3. +3 −0 src/3d/qgs3dsceneexporter.h
@@ -787,7 +787,7 @@ void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
switch ( layerType )
{
case QgsMapLayerType::VectorLayer:
if ( !exporter.parseVectorLayerEntity( rootEntity, qobject_cast<QgsVectorLayer *>(layer) ) )
if ( !exporter.parseVectorLayerEntity( rootEntity, qobject_cast<QgsVectorLayer *>( layer ) ) )
notParsedLayers.push_back( layer->name() );
break;
case QgsMapLayerType::RasterLayer:
@@ -60,6 +60,7 @@
#include "qgsabstractvectorlayer3drenderer.h"
#include "qgsvectorlayer3drenderer.h"
#include "qgspolygon3dsymbol.h"
#include "qgsline3dsymbol.h"

#include <numeric>

@@ -120,8 +121,9 @@ Qgs3DSceneExporter::Qgs3DSceneExporter( Qt3DCore::QNode *parent )

}

bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer ) {
QgsAbstract3DRenderer* abstractRenderer = layer->renderer3D();
bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsVectorLayer *layer )
{
QgsAbstract3DRenderer *abstractRenderer = layer->renderer3D();
QString rendererType = abstractRenderer->type();

if ( rendererType == "mesh" )
@@ -140,19 +142,30 @@ bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsV
QgsVectorLayer3DRenderer *vectorLayerRenderer = dynamic_cast< QgsVectorLayer3DRenderer *>( abstractVectorRenderer );
const QgsAbstract3DSymbol *symbol = vectorLayerRenderer->symbol();
QString symbolType = symbol->type();
if (symbolType == "polygon")
if ( symbolType == "polygon" )
{
QList<QgsTessellatedPolygonGeometry *> geometries = entity->findChildren<QgsTessellatedPolygonGeometry *>();
const QgsPolygon3DSymbol *polygonSymbol = dynamic_cast<const QgsPolygon3DSymbol *>( symbol );
for (QgsTessellatedPolygonGeometry * polygonGeometry : geometries)
processPolygonGeometry( polygonGeometry, polygonSymbol);
QList<QgsTessellatedPolygonGeometry *> geometries = entity->findChildren<QgsTessellatedPolygonGeometry *>();
for ( QgsTessellatedPolygonGeometry *polygonGeometry : geometries )
processPolygonGeometry( polygonGeometry, polygonSymbol );
return geometries.size() != 0;
}
else if (symbolType == "line")
else if ( symbolType == "line" )
{

const QgsLine3DSymbol *lineSymbol = dynamic_cast<const QgsLine3DSymbol *>( symbol );
if ( lineSymbol->renderAsSimpleLines() )
{

}
else
{
QList<QgsTessellatedPolygonGeometry *> geometries = entity->findChildren<QgsTessellatedPolygonGeometry *>();
for ( QgsTessellatedPolygonGeometry *lineGeometry : geometries )
processBufferedLineGeometry( lineGeometry, lineSymbol );
return geometries.size() != 0;
}
}
else if (symbolType == "point")
else if ( symbolType == "point" )
{

}
@@ -355,6 +368,26 @@ void Qgs3DSceneExporter::processPolygonGeometry( QgsTessellatedPolygonGeometry *
// TODO: handle textures
}

void Qgs3DSceneExporter::processBufferedLineGeometry( QgsTessellatedPolygonGeometry *geom, const QgsLine3DSymbol *lineSymbol )
{
Qgs3DExportObject *object = new Qgs3DExportObject( getObjectName( "line_geometry" ), "", this );
mObjects.push_back( object );

Qt3DRender::QAttribute *positionAttribute = geom->mPositionAttribute;
QByteArray positionBytes = positionAttribute->buffer()->data();
QVector<float> positionData = getAttributeData<float>( positionAttribute, positionBytes );
object->setupPositionCoordinates( positionData );

if ( mExportNormals )
{
Qt3DRender::QAttribute *normalsAttribute = geom->mNormalAttribute;
QByteArray normalsBytes = normalsAttribute->buffer()->data();
QVector<float> normalsData = getAttributeData<float>( normalsAttribute, normalsBytes );
object->setupNormalCoordinates( normalsData );
}
// TODO: handle material
}

void Qgs3DSceneExporter::save( const QString &sceneName, const QString &sceneFolderPath )
{
QString objFilePath = QDir( sceneFolderPath ).filePath( sceneName + ".obj" );
@@ -33,6 +33,7 @@ class Qgs3DExportObject;
class QgsTerrainTextureGenerator;
class QgsVectorLayer;
class QgsPolygon3DSymbol;
class QgsLine3DSymbol;

/**
* \brief The Qgs3DSceneExporter class
@@ -93,6 +94,8 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity
//! constructs Qgs3DExportObject from the polygon geometry
void processPolygonGeometry( QgsTessellatedPolygonGeometry *geom, const QgsPolygon3DSymbol *polygonSymbol );

void processBufferedLineGeometry( QgsTessellatedPolygonGeometry *geom, const QgsLine3DSymbol *lineSymbol );

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

0 comments on commit 9fe793a

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