Skip to content

Commit b773d61

Browse files
committed
[3d] Tessellator fixes + culling mode configuration for 3D polygons
- missing vertical walls since a recent tessellator crash fix (fixes #17604) - choice of the culling mode - no culling / back face / front face (fixes #17619) - more unit tests for tessellator
1 parent f8788b9 commit b773d61

11 files changed

+339
-150
lines changed

src/3d/qgs3dutils.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ AltitudeBinding Qgs3DUtils::altBindingFromString( const QString &str )
8282
return AltBindCentroid;
8383
}
8484

85+
QString Qgs3DUtils::cullingModeToString( Qt3DRender::QCullFace::CullingMode mode )
86+
{
87+
switch ( mode )
88+
{
89+
case Qt3DRender::QCullFace::NoCulling: return QStringLiteral( "no-culling" );
90+
case Qt3DRender::QCullFace::Front: return QStringLiteral( "front" );
91+
case Qt3DRender::QCullFace::Back: return QStringLiteral( "back" );
92+
case Qt3DRender::QCullFace::FrontAndBack: return QStringLiteral( "front-and-back" );
93+
default: return QString();
94+
}
95+
}
96+
97+
Qt3DRender::QCullFace::CullingMode Qgs3DUtils::cullingModeFromString( const QString &str )
98+
{
99+
if ( str == QStringLiteral( "front" ) )
100+
return Qt3DRender::QCullFace::Front;
101+
else if ( str == QStringLiteral( "back" ) )
102+
return Qt3DRender::QCullFace::Back;
103+
else if ( str == QStringLiteral( "front-and-back" ) )
104+
return Qt3DRender::QCullFace::FrontAndBack;
105+
else
106+
return Qt3DRender::QCullFace::NoCulling;
107+
}
108+
85109

86110
void Qgs3DUtils::clampAltitudes( QgsLineString *lineString, AltitudeClamping altClamp, AltitudeBinding altBind, const QgsPoint &centroid, float height, const Qgs3DMapSettings &map )
87111
{

src/3d/qgs3dutils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class QgsPolygon;
2222
#include "qgs3dmapsettings.h"
2323
#include "qgsaabb.h"
2424

25+
#include <Qt3DRender/QCullFace>
26+
2527
//! how to handle altitude of vector features
2628
enum AltitudeClamping
2729
{
@@ -64,6 +66,11 @@ class _3D_EXPORT Qgs3DUtils
6466
//! Converts a string to a value from AltitudeBinding enum
6567
static AltitudeBinding altBindingFromString( const QString &str );
6668

69+
//! Converts a value from CullingMode enum to a string
70+
static QString cullingModeToString( Qt3DRender::QCullFace::CullingMode mode );
71+
//! Converts a string to a value from CullingMode enum
72+
static Qt3DRender::QCullFace::CullingMode cullingModeFromString( const QString &str );
73+
6774
//! Clamps altitude of vertices of a linestring according to the settings
6875
static void clampAltitudes( QgsLineString *lineString, AltitudeClamping altClamp, AltitudeBinding altBind, const QgsPoint &centroid, float height, const Qgs3DMapSettings &map );
6976
//! Clamps altitude of vertices of a polygon according to the settings

src/3d/qgstessellatedpolygongeometry.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,10 @@ QgsTessellatedPolygonGeometry::QgsTessellatedPolygonGeometry( QNode *parent )
5858

5959
QgsTessellatedPolygonGeometry::~QgsTessellatedPolygonGeometry()
6060
{
61-
qDeleteAll( mPolygons );
6261
}
6362

6463
void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &polygons, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon )
6564
{
66-
qDeleteAll( mPolygons );
67-
mPolygons = polygons;
68-
6965
QgsTessellator tessellator( origin.x(), origin.y(), mWithNormals );
7066
for ( int i = 0; i < polygons.count(); ++i )
7167
{
@@ -74,6 +70,8 @@ void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &poly
7470
tessellator.addPolygon( *polygon, extr );
7571
}
7672

73+
qDeleteAll( polygons );
74+
7775
QByteArray data( ( const char * )tessellator.data().constData(), tessellator.data().count() * sizeof( float ) );
7876
int nVerts = data.count() / tessellator.stride();
7977

src/3d/qgstessellatedpolygongeometry.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class QgsTessellatedPolygonGeometry : public Qt3DRender::QGeometry
4545
void setPolygons( const QList<QgsPolygon *> &polygons, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon = QList<float>() );
4646

4747
private:
48-
QList<QgsPolygon *> mPolygons;
4948

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

0 commit comments

Comments
 (0)