Skip to content

Commit 50dd4b1

Browse files
committed
Edge highlighting for extruded polygons
1 parent 78da017 commit 50dd4b1

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/3d/symbols/qgslinevertexdata_p.cpp

+31-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Qt3DRender::QGeometry *QgsLineVertexData::createGeometry( Qt3DCore::QNode *paren
9696
return geom;
9797
}
9898

99-
void QgsLineVertexData::addLineString( const QgsLineString &lineString )
99+
void QgsLineVertexData::addLineString( const QgsLineString &lineString, float extraHeightOffset )
100100
{
101101
if ( withAdjacency )
102102
indexes << vertices.count(); // add the following vertex (for adjacency)
@@ -108,7 +108,7 @@ void QgsLineVertexData::addLineString( const QgsLineString &lineString )
108108
for ( int i = 0; i < lineString.vertexCount(); ++i )
109109
{
110110
QgsPoint p = lineString.pointN( i );
111-
float z = Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight, centroid, *mapSettings );
111+
float z = Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight + extraHeightOffset, centroid, *mapSettings );
112112

113113
vertices << QVector3D( p.x() - mapSettings->origin().x(), z, -( p.y() - mapSettings->origin().y() ) );
114114
indexes << vertices.count() - 1;
@@ -120,4 +120,33 @@ void QgsLineVertexData::addLineString( const QgsLineString &lineString )
120120
indexes << 0; // add primitive restart
121121
}
122122

123+
124+
void QgsLineVertexData::addVerticalLines( const QgsLineString &lineString, float verticalLength )
125+
{
126+
QgsPoint centroid;
127+
if ( altBinding == Qgs3DTypes::AltBindCentroid )
128+
centroid = lineString.centroid();
129+
130+
for ( int i = 0; i < lineString.vertexCount(); ++i )
131+
{
132+
QgsPoint p = lineString.pointN( i );
133+
float z = Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight, centroid, *mapSettings );
134+
float z2 = z + verticalLength;
135+
136+
if ( withAdjacency )
137+
indexes << vertices.count(); // add the following vertex (for adjacency)
138+
139+
vertices << QVector3D( p.x() - mapSettings->origin().x(), z, -( p.y() - mapSettings->origin().y() ) );
140+
indexes << vertices.count() - 1;
141+
vertices << QVector3D( p.x() - mapSettings->origin().x(), z2, -( p.y() - mapSettings->origin().y() ) );
142+
indexes << vertices.count() - 1;
143+
144+
if ( withAdjacency )
145+
indexes << vertices.count() - 1; // add the last vertex (for adjacency)
146+
147+
indexes << 0; // add primitive restart
148+
}
149+
}
150+
151+
123152
/// @endcond

src/3d/symbols/qgslinevertexdata_p.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ struct QgsLineVertexData
7878
QByteArray createIndexBuffer();
7979
Qt3DRender::QGeometry *createGeometry( Qt3DCore::QNode *parent );
8080

81-
void addLineString( const QgsLineString &lineString );
81+
void addLineString( const QgsLineString &lineString, float extraHeightOffset = 0 );
82+
void addVerticalLines( const QgsLineString &lineString, float verticalLength );
8283
};
8384

8485
/// @endcond

src/3d/symbols/qgspolygon3dsymbol_p.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,19 @@ void QgsPolygon3DSymbolHandler::processPolygon( QgsPolygon *polyClone, QgsFeatur
9393
for ( int i = 0; i < polyClone->numInteriorRings(); ++i )
9494
outEdges.addLineString( *static_cast<const QgsLineString *>( polyClone->interiorRing( i ) ) );
9595

96-
// TODO: if has extrusion: also add vertical edges for each vertex
96+
if ( extrusionHeight )
97+
{
98+
// add roof and wall edges
99+
const QgsLineString *exterior = static_cast<const QgsLineString *>( polyClone->exteriorRing() );
100+
outEdges.addLineString( *exterior, extrusionHeight );
101+
outEdges.addVerticalLines( *exterior, extrusionHeight );
102+
for ( int i = 0; i < polyClone->numInteriorRings(); ++i )
103+
{
104+
const QgsLineString *interior = static_cast<const QgsLineString *>( polyClone->interiorRing( i ) );
105+
outEdges.addLineString( *interior, extrusionHeight );
106+
outEdges.addVerticalLines( *interior, extrusionHeight );
107+
}
108+
}
97109
}
98110

99111
Qgs3DUtils::clampAltitudes( polyClone, mSymbol.altitudeClamping(), mSymbol.altitudeBinding(), height, context.map() );

0 commit comments

Comments
 (0)