Skip to content
Permalink
Browse files

Merge pull request #5798 from wonder-sk/polygon-3d-fixes

[3d] Tessellator fixes + culling mode configuration for 3D polygons
  • Loading branch information
wonder-sk committed Dec 5, 2017
2 parents db9fc28 + 1f6cd31 commit ba9e19954bdc99d249bea0c408d0c8f6b0f52d2c
@@ -82,6 +82,30 @@ AltitudeBinding Qgs3DUtils::altBindingFromString( const QString &str )
return AltBindCentroid;
}

QString Qgs3DUtils::cullingModeToString( Qt3DRender::QCullFace::CullingMode mode )
{
switch ( mode )
{
case Qt3DRender::QCullFace::NoCulling: return QStringLiteral( "no-culling" );
case Qt3DRender::QCullFace::Front: return QStringLiteral( "front" );
case Qt3DRender::QCullFace::Back: return QStringLiteral( "back" );
case Qt3DRender::QCullFace::FrontAndBack: return QStringLiteral( "front-and-back" );
}
return QString();
}

Qt3DRender::QCullFace::CullingMode Qgs3DUtils::cullingModeFromString( const QString &str )
{
if ( str == QStringLiteral( "front" ) )
return Qt3DRender::QCullFace::Front;
else if ( str == QStringLiteral( "back" ) )
return Qt3DRender::QCullFace::Back;
else if ( str == QStringLiteral( "front-and-back" ) )
return Qt3DRender::QCullFace::FrontAndBack;
else
return Qt3DRender::QCullFace::NoCulling;
}


void Qgs3DUtils::clampAltitudes( QgsLineString *lineString, AltitudeClamping altClamp, AltitudeBinding altBind, const QgsPoint &centroid, float height, const Qgs3DMapSettings &map )
{
@@ -22,6 +22,8 @@ class QgsPolygon;
#include "qgs3dmapsettings.h"
#include "qgsaabb.h"

#include <Qt3DRender/QCullFace>

//! how to handle altitude of vector features
enum AltitudeClamping
{
@@ -64,6 +66,11 @@ class _3D_EXPORT Qgs3DUtils
//! Converts a string to a value from AltitudeBinding enum
static AltitudeBinding altBindingFromString( const QString &str );

//! Converts a value from CullingMode enum to a string
static QString cullingModeToString( Qt3DRender::QCullFace::CullingMode mode );
//! Converts a string to a value from CullingMode enum
static Qt3DRender::QCullFace::CullingMode cullingModeFromString( const QString &str );

//! Clamps altitude of vertices of a linestring according to the settings
static void clampAltitudes( QgsLineString *lineString, AltitudeClamping altClamp, AltitudeBinding altBind, const QgsPoint &centroid, float height, const Qgs3DMapSettings &map );
//! Clamps altitude of vertices of a polygon according to the settings
@@ -58,14 +58,10 @@ QgsTessellatedPolygonGeometry::QgsTessellatedPolygonGeometry( QNode *parent )

QgsTessellatedPolygonGeometry::~QgsTessellatedPolygonGeometry()
{
qDeleteAll( mPolygons );
}

void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &polygons, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon )
{
qDeleteAll( mPolygons );
mPolygons = polygons;

QgsTessellator tessellator( origin.x(), origin.y(), mWithNormals );
for ( int i = 0; i < polygons.count(); ++i )
{
@@ -74,6 +70,8 @@ void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &poly
tessellator.addPolygon( *polygon, extr );
}

qDeleteAll( polygons );

QByteArray data( ( const char * )tessellator.data().constData(), tessellator.data().count() * sizeof( float ) );
int nVerts = data.count() / tessellator.stride();

@@ -45,7 +45,6 @@ class QgsTessellatedPolygonGeometry : public Qt3DRender::QGeometry
void setPolygons( const QList<QgsPolygon *> &polygons, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon = QList<float>() );

private:
QList<QgsPolygon *> mPolygons;

Qt3DRender::QAttribute *mPositionAttribute = nullptr;
Qt3DRender::QAttribute *mNormalAttribute = nullptr;

0 comments on commit ba9e199

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