Skip to content

Commit

Permalink
Merge pull request #5798 from wonder-sk/polygon-3d-fixes
Browse files Browse the repository at this point in the history
[3d] Tessellator fixes + culling mode configuration for 3D polygons
  • Loading branch information
wonder-sk committed Dec 5, 2017
2 parents db9fc28 + 1f6cd31 commit ba9e199
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 150 deletions.
24 changes: 24 additions & 0 deletions src/3d/qgs3dutils.cpp
Expand Up @@ -82,6 +82,30 @@ AltitudeBinding Qgs3DUtils::altBindingFromString( const QString &str )
return AltBindCentroid; 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 ) void Qgs3DUtils::clampAltitudes( QgsLineString *lineString, AltitudeClamping altClamp, AltitudeBinding altBind, const QgsPoint &centroid, float height, const Qgs3DMapSettings &map )
{ {
Expand Down
7 changes: 7 additions & 0 deletions src/3d/qgs3dutils.h
Expand Up @@ -22,6 +22,8 @@ class QgsPolygon;
#include "qgs3dmapsettings.h" #include "qgs3dmapsettings.h"
#include "qgsaabb.h" #include "qgsaabb.h"


#include <Qt3DRender/QCullFace>

//! how to handle altitude of vector features //! how to handle altitude of vector features
enum AltitudeClamping enum AltitudeClamping
{ {
Expand Down Expand Up @@ -64,6 +66,11 @@ class _3D_EXPORT Qgs3DUtils
//! Converts a string to a value from AltitudeBinding enum //! Converts a string to a value from AltitudeBinding enum
static AltitudeBinding altBindingFromString( const QString &str ); 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 //! 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 ); 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 //! Clamps altitude of vertices of a polygon according to the settings
Expand Down
6 changes: 2 additions & 4 deletions src/3d/qgstessellatedpolygongeometry.cpp
Expand Up @@ -58,14 +58,10 @@ QgsTessellatedPolygonGeometry::QgsTessellatedPolygonGeometry( QNode *parent )


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


void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &polygons, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon ) 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 ); QgsTessellator tessellator( origin.x(), origin.y(), mWithNormals );
for ( int i = 0; i < polygons.count(); ++i ) for ( int i = 0; i < polygons.count(); ++i )
{ {
Expand All @@ -74,6 +70,8 @@ void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &poly
tessellator.addPolygon( *polygon, extr ); tessellator.addPolygon( *polygon, extr );
} }


qDeleteAll( polygons );

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


Expand Down
1 change: 0 additions & 1 deletion src/3d/qgstessellatedpolygongeometry.h
Expand Up @@ -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>() ); void setPolygons( const QList<QgsPolygon *> &polygons, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon = QList<float>() );


private: private:
QList<QgsPolygon *> mPolygons;


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

0 comments on commit ba9e199

Please sign in to comment.