Skip to content
Permalink
Browse files

rule based renderer initial implementation

  • Loading branch information
NEDJIMAbelgacem committed Jul 14, 2020
1 parent babce71 commit 7aa015bc5b187b9274d88c350d227cc2e67d359a
Showing with 52 additions and 11 deletions.
  1. +40 −11 src/3d/qgs3dsceneexporter.cpp
  2. +10 −0 src/3d/qgs3dutils.cpp
  3. +2 −0 src/3d/qgs3dutils.h
@@ -41,6 +41,7 @@
#include <Qt3DExtras/QCuboidGeometry>
#include <Qt3DExtras/QTorusGeometry>
#include <Qt3DExtras/QExtrudedTextMesh>
#include <Qt3DExtras/QPhongMaterial>

#include <QByteArray>
#include <QFile>
@@ -72,6 +73,7 @@
#include "qgsline3dsymbol.h"
#include "qgspoint3dsymbol.h"
#include "qgsrulebased3drenderer.h"
#include "qgs3dutils.h"

#include <numeric>

@@ -180,7 +182,20 @@ bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsV
QgsAbstractVectorLayer3DRenderer *abstractVectorRenderer = dynamic_cast< QgsAbstractVectorLayer3DRenderer *>( abstractRenderer );
if ( rendererType == "rulebased" )
{
// TODO: handle rule based renderers
// Potential bug: meshes loaded using Qt3DRender::QSceneLoader will probably have wrong scale and translation
QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
for ( Qt3DRender::QGeometryRenderer *renderer : renderers )
{
Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>( renderer->parent() );
if ( entity == nullptr ) continue;
Qgs3DExportObject *object = processGeometryRenderer( renderer );
if ( object == nullptr ) continue;
mObjects.push_back( object );
Qt3DExtras::QPhongMaterial *material = findTypedComponent<Qt3DExtras::QPhongMaterial>( entity );
if ( material == nullptr ) continue;
object->setupPhongMaterial( Qgs3DUtils::phongMaterialFromQt3DComponent( material ) );
}
return true;
}
else
{
@@ -536,26 +551,40 @@ Qgs3DExportObject *Qgs3DSceneExporter::processGeometryRenderer( Qt3DRender::QGeo

Qt3DRender::QAttribute *positionAttribute = findAttribute( geometry, Qt3DRender::QAttribute::defaultPositionAttributeName(), Qt3DRender::QAttribute::VertexAttribute );
Qt3DRender::QAttribute *indexAttribute = nullptr;
QByteArray indexBytes, vertexBytes;
QVector<uint> indexData;
QVector<float> positionData;
for ( Qt3DRender::QAttribute *attribute : geometry->attributes() )
{
if ( attribute->attributeType() == Qt3DRender::QAttribute::IndexAttribute )
indexAttribute = attribute;
}
if ( positionAttribute == nullptr || indexAttribute == nullptr )
if ( indexAttribute != nullptr )
{
qDebug() << "renderer with null data";
return nullptr;
getData( indexAttribute->buffer() );
if ( indexAttribute->vertexBaseType() == Qt3DRender::QAttribute::VertexBaseType::UnsignedInt ) indexData = getIndexData<quint32>( indexBytes );
if ( indexAttribute->vertexBaseType() == Qt3DRender::QAttribute::VertexBaseType::UnsignedShort ) indexData = getIndexData<quint16>( indexBytes );
}

QByteArray vertexBytes = getData( positionAttribute->buffer() );
QByteArray indexBytes = getData( indexAttribute->buffer() );
if ( positionAttribute != nullptr )
{
vertexBytes = getData( positionAttribute->buffer() );
positionData = getAttributeData<float>( positionAttribute, vertexBytes );
}
// For tesselated polygons that doesn't have index attributes
if ( positionAttribute != nullptr && indexAttribute == nullptr )
{
for ( int i = 0; i < positionData.size() / 3; ++i )
indexData.push_back( i );
}

QVector<float> positionData = getAttributeData<float>( positionAttribute, vertexBytes );
QVector<uint> indexData;
if ( indexAttribute->vertexBaseType() == Qt3DRender::QAttribute::VertexBaseType::UnsignedInt ) indexData = getIndexData<quint32>( indexBytes );
if ( indexAttribute->vertexBaseType() == Qt3DRender::QAttribute::VertexBaseType::UnsignedShort ) indexData = getIndexData<quint16>( indexBytes );
Qgs3DExportObject *object = new Qgs3DExportObject( getObjectName( "mesh_geometry" ), "", this );
if ( positionAttribute == nullptr )
{
qDebug() << "WARNING: renderer with null data";
return nullptr;
}

Qgs3DExportObject *object = new Qgs3DExportObject( getObjectName( "mesh_geometry" ), "", this );
object->setupPositionCoordinates( positionData, scale * sceneScale, translation + sceneTranslation );
object->setupFaces( indexData );

@@ -581,3 +581,13 @@ Qt3DExtras::QPhongMaterial *Qgs3DUtils::phongMaterial( const QgsPhongMaterialSet
phong->setShininess( settings.shininess() );
return phong;
}

QgsPhongMaterialSettings Qgs3DUtils::phongMaterialFromQt3DComponent( Qt3DExtras::QPhongMaterial *material )
{
QgsPhongMaterialSettings settings;
settings.setAmbient( material->ambient() );
settings.setDiffuse( material->diffuse() );
settings.setSpecular( material->specular() );
settings.setShininess( material->shininess() );
return settings;
}
@@ -177,6 +177,8 @@ class _3D_EXPORT Qgs3DUtils

//! Returns phong material object based on the material settings
static Qt3DExtras::QPhongMaterial *phongMaterial( const QgsPhongMaterialSettings &settings );
//! Returns phong material settings object based on the Qt3D material
static QgsPhongMaterialSettings phongMaterialFromQt3DComponent( Qt3DExtras::QPhongMaterial *material );
};

#endif // QGS3DUTILS_H

0 comments on commit 7aa015b

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