mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-09 00:08:52 -04:00
Moved finding geometries from parseVectorLayerEntity to each symbol class
This commit is contained in:
parent
300ebd4af2
commit
a656da3b75
@ -113,6 +113,13 @@ Returns material used for shading of the symbol
|
||||
Sets the ``material`` settings used for shading of the symbol.
|
||||
|
||||
Ownership of ``material`` is transferred to the symbol.
|
||||
%End
|
||||
|
||||
virtual bool exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const;
|
||||
|
||||
%Docstring
|
||||
Exports the geometries contained withing the hierarchy of entity.
|
||||
Returns whether any objects were exported
|
||||
%End
|
||||
|
||||
};
|
||||
|
@ -138,6 +138,12 @@ Sets transform for individual objects represented by the symbol
|
||||
Returns transform for billboards
|
||||
%End
|
||||
|
||||
virtual bool exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const;
|
||||
|
||||
%Docstring
|
||||
Exports the geometries contained withing the hierarchy of entity.
|
||||
Returns whether any objects were exported
|
||||
%End
|
||||
private:
|
||||
QgsPoint3DSymbol &operator=( const QgsPoint3DSymbol & );
|
||||
};
|
||||
|
@ -183,6 +183,15 @@ Sets which facade of the buildings is rendered (0 for None, 1 for Walls, 2 for R
|
||||
%Docstring
|
||||
Returns which facade of the buildings is rendered (0 for None, 1 for Walls, 2 for Roofs, 3 for WallsAndRoofs)
|
||||
|
||||
.. versionadded:: 3.16
|
||||
%End
|
||||
|
||||
virtual bool exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const;
|
||||
|
||||
%Docstring
|
||||
Exports the geometries contained withing the hierarchy of entity.
|
||||
Returns whether any objects were exported
|
||||
|
||||
.. versionadded:: 3.16
|
||||
%End
|
||||
|
||||
|
@ -10,6 +10,9 @@
|
||||
|
||||
|
||||
|
||||
namespace Qt3DCore
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
class QgsAbstract3DSymbol
|
||||
@ -76,6 +79,13 @@ Returns a reference to the symbol layer's property collection, used for data def
|
||||
void setDataDefinedProperties( const QgsPropertyCollection &collection );
|
||||
%Docstring
|
||||
Sets the symbol layer's property collection, used for data defined overrides.
|
||||
%End
|
||||
|
||||
virtual bool exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const;
|
||||
%Docstring
|
||||
Exports the geometries contained withing the hierarchy of entity.
|
||||
Returns whether any objects were exported
|
||||
If this function is not overloaded we don't try to export anything
|
||||
%End
|
||||
|
||||
protected:
|
||||
|
@ -218,88 +218,8 @@ 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" )
|
||||
{
|
||||
QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
|
||||
for ( Qt3DRender::QGeometryRenderer *r : renderers )
|
||||
{
|
||||
Qgs3DExportObject *object = processGeometryRenderer( r, layer->name() + QStringLiteral( "_" ) );
|
||||
if ( object == nullptr ) continue;
|
||||
processEntityMaterial( entity, object );
|
||||
mObjects.push_back( object );
|
||||
}
|
||||
return renderers.size() != 0;
|
||||
}
|
||||
else if ( symbolType == "line" )
|
||||
{
|
||||
const QgsLine3DSymbol *lineSymbol = dynamic_cast<const QgsLine3DSymbol *>( symbol );
|
||||
if ( lineSymbol->renderAsSimpleLines() )
|
||||
{
|
||||
QVector<Qgs3DExportObject *> objs = processLines( entity, layer->name() + QStringLiteral( "_" ) );
|
||||
mObjects << objs;
|
||||
return objs.size() != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
|
||||
for ( Qt3DRender::QGeometryRenderer *r : renderers )
|
||||
{
|
||||
Qgs3DExportObject *object = processGeometryRenderer( r, layer->name() + QStringLiteral( "_" ) );
|
||||
if ( object == nullptr ) continue;
|
||||
object->setupMaterial( lineSymbol->material() );
|
||||
mObjects.push_back( object );
|
||||
}
|
||||
return renderers.size() != 0;
|
||||
}
|
||||
}
|
||||
else if ( symbolType == "point" )
|
||||
{
|
||||
const QgsPoint3DSymbol *pointSymbol = dynamic_cast<const QgsPoint3DSymbol *>( symbol );
|
||||
if ( pointSymbol->shape() == QgsPoint3DSymbol::Model )
|
||||
{
|
||||
Qt3DRender::QSceneLoader *sceneLoader = entity->findChild<Qt3DRender::QSceneLoader *>();
|
||||
if ( sceneLoader != nullptr )
|
||||
{
|
||||
QVector<Qgs3DExportObject *> objects = processSceneLoaderGeometries( sceneLoader, layer->name() + QStringLiteral( "_" ) );
|
||||
for ( Qgs3DExportObject *obj : objects )
|
||||
{
|
||||
obj->setSmoothEdges( mSmoothEdges );
|
||||
obj->setupMaterial( pointSymbol->material() );
|
||||
}
|
||||
mObjects << objects;
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<Qt3DRender::QMesh *> meshes = entity->findChildren<Qt3DRender::QMesh *>();
|
||||
for ( Qt3DRender::QMesh *mesh : meshes )
|
||||
{
|
||||
Qgs3DExportObject *object = processGeometryRenderer( mesh, layer->name() + QStringLiteral( "_" ) );
|
||||
if ( object == nullptr ) continue;
|
||||
object->setSmoothEdges( mSmoothEdges );
|
||||
object->setupMaterial( pointSymbol->material() );
|
||||
mObjects << object;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ( pointSymbol->shape() == QgsPoint3DSymbol::Billboard )
|
||||
{
|
||||
Qgs3DExportObject *obj = processPoints( entity, layer->name() + QStringLiteral( "_" ) );
|
||||
if ( obj != nullptr ) mObjects << obj;
|
||||
if ( obj != nullptr ) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QVector<Qgs3DExportObject *> objects = processInstancedPointGeometry( entity, layer->name() + QStringLiteral( "_" ) );
|
||||
for ( Qgs3DExportObject *obj : objects )
|
||||
{
|
||||
obj->setupMaterial( pointSymbol->material() );
|
||||
mObjects << obj;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
bool exported = symbol->exportGeometries( this, entity, layer->name() + QStringLiteral( "_" ) );
|
||||
return exported;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -140,6 +140,10 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity
|
||||
bool mExportTextures = false;
|
||||
int mTerrainTextureResolution = 512;
|
||||
float mScale = 1.0f;
|
||||
|
||||
friend QgsPolygon3DSymbol;
|
||||
friend QgsLine3DSymbol;
|
||||
friend QgsPoint3DSymbol;
|
||||
};
|
||||
|
||||
#endif // QGS3DSCENEEXPORTER_H
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "qgsline3dsymbol.h"
|
||||
#include "qgsphongmaterialsettings.h"
|
||||
#include "qgs3dutils.h"
|
||||
#include "qgs3dexportobject.h"
|
||||
#include "qgs3dsceneexporter.h"
|
||||
|
||||
QgsLine3DSymbol::QgsLine3DSymbol()
|
||||
: mMaterial( qgis::make_unique< QgsPhongMaterialSettings >() )
|
||||
@ -92,3 +94,26 @@ QgsAbstract3DSymbol *QgsLine3DSymbol::create()
|
||||
{
|
||||
return new QgsLine3DSymbol();
|
||||
}
|
||||
|
||||
bool QgsLine3DSymbol::exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const
|
||||
{
|
||||
if ( renderAsSimpleLines() )
|
||||
{
|
||||
QVector<Qgs3DExportObject *> objs = exporter->processLines( entity, objectNamePrefix );
|
||||
exporter->mObjects << objs;
|
||||
return objs.size() != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
|
||||
for ( Qt3DRender::QGeometryRenderer *r : renderers )
|
||||
{
|
||||
Qgs3DExportObject *object = exporter->processGeometryRenderer( r, objectNamePrefix );
|
||||
if ( object == nullptr ) continue;
|
||||
object->setupMaterial( material() );
|
||||
exporter->mObjects.push_back( object );
|
||||
}
|
||||
return renderers.size() != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -92,6 +92,12 @@ class _3D_EXPORT QgsLine3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCTORS
|
||||
*/
|
||||
void setMaterial( QgsAbstractMaterialSettings *material SIP_TRANSFER );
|
||||
|
||||
/**
|
||||
* Exports the geometries contained withing the hierarchy of entity.
|
||||
* Returns whether any objects were exported
|
||||
*/
|
||||
bool exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const override;
|
||||
|
||||
private:
|
||||
//! how to handle altitude of vector features
|
||||
Qgs3DTypes::AltitudeClamping mAltClamping = Qgs3DTypes::AltClampRelative;
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "qgsreadwritecontext.h"
|
||||
#include "qgsxmlutils.h"
|
||||
#include "qgssymbollayerutils.h"
|
||||
#include "qgs3dexportobject.h"
|
||||
#include "qgs3dsceneexporter.h"
|
||||
|
||||
|
||||
QgsAbstract3DSymbol *QgsPoint3DSymbol::clone() const
|
||||
@ -163,3 +165,50 @@ void QgsPoint3DSymbol::setMaterial( QgsAbstractMaterialSettings *material )
|
||||
mMaterial.reset( material );
|
||||
}
|
||||
|
||||
bool QgsPoint3DSymbol::exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const
|
||||
{
|
||||
if ( shape() == QgsPoint3DSymbol::Model )
|
||||
{
|
||||
Qt3DRender::QSceneLoader *sceneLoader = entity->findChild<Qt3DRender::QSceneLoader *>();
|
||||
if ( sceneLoader != nullptr )
|
||||
{
|
||||
QVector<Qgs3DExportObject *> objects = exporter->processSceneLoaderGeometries( sceneLoader, objectNamePrefix );
|
||||
for ( Qgs3DExportObject *obj : objects )
|
||||
{
|
||||
obj->setSmoothEdges( exporter->smoothEdges() );
|
||||
obj->setupMaterial( material() );
|
||||
}
|
||||
exporter->mObjects << objects;
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<Qt3DRender::QMesh *> meshes = entity->findChildren<Qt3DRender::QMesh *>();
|
||||
for ( Qt3DRender::QMesh *mesh : meshes )
|
||||
{
|
||||
Qgs3DExportObject *object = exporter->processGeometryRenderer( mesh, objectNamePrefix );
|
||||
if ( object == nullptr ) continue;
|
||||
object->setSmoothEdges( exporter->smoothEdges() );
|
||||
object->setupMaterial( material() );
|
||||
exporter->mObjects << object;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ( shape() == QgsPoint3DSymbol::Billboard )
|
||||
{
|
||||
Qgs3DExportObject *obj = exporter->processPoints( entity, objectNamePrefix );
|
||||
if ( obj != nullptr ) exporter->mObjects << obj;
|
||||
if ( obj != nullptr ) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
QVector<Qgs3DExportObject *> objects = exporter->processInstancedPointGeometry( entity, objectNamePrefix );
|
||||
for ( Qgs3DExportObject *obj : objects )
|
||||
{
|
||||
obj->setupMaterial( material() );
|
||||
exporter->mObjects << obj;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -114,6 +114,11 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCTOR
|
||||
//! Returns transform for billboards
|
||||
QMatrix4x4 billboardTransform() const;
|
||||
|
||||
/**
|
||||
* Exports the geometries contained withing the hierarchy of entity.
|
||||
* Returns whether any objects were exported
|
||||
*/
|
||||
bool exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const override;
|
||||
private:
|
||||
//! how to handle altitude of vector features
|
||||
Qgs3DTypes::AltitudeClamping mAltClamping = Qgs3DTypes::AltClampRelative;
|
||||
|
@ -15,8 +15,11 @@
|
||||
|
||||
#include "qgspolygon3dsymbol.h"
|
||||
|
||||
#include <Qt3DCore/QEntity>
|
||||
|
||||
#include "qgs3dutils.h"
|
||||
#include "qgssymbollayerutils.h"
|
||||
#include "qgs3dsceneexporter.h"
|
||||
|
||||
QgsPolygon3DSymbol::QgsPolygon3DSymbol()
|
||||
: mMaterial( qgis::make_unique< QgsPhongMaterialSettings >() )
|
||||
@ -124,3 +127,16 @@ void QgsPolygon3DSymbol::setMaterial( QgsAbstractMaterialSettings *material )
|
||||
|
||||
mMaterial.reset( material );
|
||||
}
|
||||
|
||||
bool QgsPolygon3DSymbol::exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const
|
||||
{
|
||||
QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
|
||||
for ( Qt3DRender::QGeometryRenderer *r : renderers )
|
||||
{
|
||||
Qgs3DExportObject *object = exporter->processGeometryRenderer( r, objectNamePrefix );
|
||||
if ( object == nullptr ) continue;
|
||||
exporter->processEntityMaterial( entity, object );
|
||||
exporter->mObjects.push_back( object );
|
||||
}
|
||||
return renderers.size() != 0;
|
||||
}
|
||||
|
@ -154,6 +154,13 @@ class _3D_EXPORT QgsPolygon3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCT
|
||||
*/
|
||||
int renderedFacade() const { return mRenderedFacade; }
|
||||
|
||||
/**
|
||||
* Exports the geometries contained withing the hierarchy of entity.
|
||||
* Returns whether any objects were exported
|
||||
* \since QGIS 3.16
|
||||
*/
|
||||
bool exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const override;
|
||||
|
||||
private:
|
||||
//! how to handle altitude of vector features
|
||||
Qgs3DTypes::AltitudeClamping mAltClamping = Qgs3DTypes::AltClampRelative;
|
||||
|
@ -25,6 +25,11 @@ class QDomElement;
|
||||
class QString;
|
||||
|
||||
class QgsReadWriteContext;
|
||||
class Qgs3DSceneExporter;
|
||||
namespace Qt3DCore
|
||||
{
|
||||
class QEntity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -74,6 +79,19 @@ class CORE_EXPORT QgsAbstract3DSymbol
|
||||
//! Sets the symbol layer's property collection, used for data defined overrides.
|
||||
void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
|
||||
|
||||
/**
|
||||
* Exports the geometries contained withing the hierarchy of entity.
|
||||
* Returns whether any objects were exported
|
||||
* If this function is not overloaded we don't try to export anything
|
||||
*/
|
||||
virtual bool exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const
|
||||
{
|
||||
Q_UNUSED( exporter );
|
||||
Q_UNUSED( entity );
|
||||
Q_UNUSED( objectNamePrefix );
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user