Skip to content
Permalink
Browse files

Export mesh terrain position data

  • Loading branch information
NEDJIMAbelgacem committed Jul 16, 2020
1 parent 25a83d3 commit 5323fbed12e015efd5dc8e6bc070096d8c62bb75
Showing with 34 additions and 5 deletions.
  1. +1 −0 src/3d/mesh/qgsmeshterraingenerator.h
  2. +28 −5 src/3d/qgs3dsceneexporter.cpp
  3. +5 −0 src/3d/qgs3dsceneexporter.h
@@ -32,6 +32,7 @@
//! Chunk loader for mesh terrain implementation
class QgsMeshTerrainTileLoader: public QgsTerrainTileLoader
{
Q_OBJECT
public:
//! Construct the loader for a node
QgsMeshTerrainTileLoader( QgsTerrainEntity *terrain,
@@ -42,6 +42,7 @@
#include <Qt3DExtras/QTorusGeometry>
#include <Qt3DExtras/QExtrudedTextMesh>
#include <Qt3DExtras/QPhongMaterial>
#include <Qt3DRender/QBufferDataGenerator>

#include <QByteArray>
#include <QFile>
@@ -61,7 +62,6 @@
#include "qgsterraintextureimage_p.h"
#include "qgsterraintexturegenerator_p.h"
#include "qgsmesh3dgeometry_p.h"
#include <Qt3DRender/qbufferdatagenerator.h>
#include "qgsmeshlayer.h"
#include "qgsmesh3dentity_p.h"
#include "qgsmeshterraingenerator.h"
@@ -178,7 +178,7 @@ bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsV

if ( rendererType == "mesh" )
{
// TODO: handle mesh layer
// TODO: handle mesh layers
}
else
{
@@ -274,7 +274,6 @@ bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsV
else
{
QVector<Qgs3DExportObject *> objects = processInstancedPointGeometry( entity, pointSymbol );
qDebug() << "Instanced geometries count: " << objects.size();
mObjects << objects;
return true;
}
@@ -292,20 +291,23 @@ void Qgs3DSceneExporter::parseTerrain( QgsTerrainEntity *terrain )
QgsTerrainGenerator *generator = settings.terrainGenerator();
QgsTerrainTileEntity *terrainTile = nullptr;
QgsTerrainTextureGenerator *textureGenerator = terrain->textureGenerator();
textureGenerator->waitForFinished();
QSize oldResolution = textureGenerator->textureSize();
textureGenerator->setTextureSize( QSize( mTerrainTextureResolution, mTerrainTextureResolution ) );
switch ( generator->type() )
{
case QgsTerrainGenerator::Dem:
terrainTile = getDemTerrainEntity( terrain, node );
this->parseDemTile( terrainTile );
parseDemTile( terrainTile );
break;
case QgsTerrainGenerator::Flat:
terrainTile = getFlatTerrainEntity( terrain, node );
this->parseFlatTile( terrainTile );
parseFlatTile( terrainTile );
break;
// TODO: implement other terrain types
case QgsTerrainGenerator::Mesh:
terrainTile = getMeshTerrainEntity( terrain, node );
parseMeshTile( terrainTile );
break;
case QgsTerrainGenerator::Online:
break;
@@ -340,6 +342,16 @@ QgsTerrainTileEntity *Qgs3DSceneExporter::getDemTerrainEntity( QgsTerrainEntity
return tileEntity;
}

QgsTerrainTileEntity *Qgs3DSceneExporter::getMeshTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node )
{
QgsMeshTerrainGenerator *generator = dynamic_cast<QgsMeshTerrainGenerator *>( terrain->map3D().terrainGenerator() );;
QgsMeshTerrainTileLoader *loader = qobject_cast<QgsMeshTerrainTileLoader *>( generator->createChunkLoader( node ) );
// TODO: export textures
QgsTerrainTileEntity *tileEntity = qobject_cast<QgsTerrainTileEntity *>( loader->createEntity( this ) );
delete generator;
return tileEntity;
}

void Qgs3DSceneExporter::parseFlatTile( QgsTerrainTileEntity *tileEntity )
{
Qt3DRender::QGeometryRenderer *mesh = findTypedComponent<Qt3DRender::QGeometryRenderer>( tileEntity );
@@ -446,6 +458,17 @@ void Qgs3DSceneExporter::parseDemTile( QgsTerrainTileEntity *tileEntity )
}
}

void Qgs3DSceneExporter::parseMeshTile( QgsTerrainTileEntity *tileEntity )
{
QList<Qt3DRender::QGeometryRenderer *> renderers = tileEntity->findChildren<Qt3DRender::QGeometryRenderer *>();
for ( Qt3DRender::QGeometryRenderer *renderer : renderers )
{
Qgs3DExportObject *obj = processGeometryRenderer( renderer );
if ( obj == nullptr ) continue;
mObjects << obj;
}
}

QVector<Qgs3DExportObject *> Qgs3DSceneExporter::processInstancedPointGeometry( Qt3DCore::QEntity *entity, const QgsPoint3DSymbol *pointSymbol )
{
QVector<Qgs3DExportObject *> objects;
@@ -38,6 +38,7 @@ class QgsVectorLayer;
class QgsPolygon3DSymbol;
class QgsLine3DSymbol;
class QgsPoint3DSymbol;
class QgsMeshEntity;

/**
* \brief The Qgs3DSceneExporter class
@@ -104,11 +105,15 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity
QgsTerrainTileEntity *getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
//! Returns a tile entity that contains the geometry to be exported and necessary scaling parameters
QgsTerrainTileEntity *getDemTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );
//! Returns a tile entity that contains the geometry to be exported and necessary scaling parameters
QgsTerrainTileEntity *getMeshTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node );

//! Constructs a Qgs3DExportObject from the DEM tile entity
void parseDemTile( QgsTerrainTileEntity *tileEntity );
//! Constructs a Qgs3DExportObject from the flat tile entity
void parseFlatTile( QgsTerrainTileEntity *tileEntity );
//! Constructs a Qgs3DExportObject from the mesh terrain entity
void parseMeshTile( QgsTerrainTileEntity *meshEntity );

QString getObjectName( const QString &name );
private:

0 comments on commit 5323fbe

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