Skip to content
Permalink
Browse files

Edge highlighting for extruded polygons

  • Loading branch information
wonder-sk committed Apr 9, 2019
1 parent 78da017 commit 50dd4b13173b1dc84135f4b3e3cddc86cb0397da
@@ -96,7 +96,7 @@ Qt3DRender::QGeometry *QgsLineVertexData::createGeometry( Qt3DCore::QNode *paren
return geom;
}

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

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


void QgsLineVertexData::addVerticalLines( const QgsLineString &lineString, float verticalLength )
{
QgsPoint centroid;
if ( altBinding == Qgs3DTypes::AltBindCentroid )
centroid = lineString.centroid();

for ( int i = 0; i < lineString.vertexCount(); ++i )
{
QgsPoint p = lineString.pointN( i );
float z = Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight, centroid, *mapSettings );
float z2 = z + verticalLength;

if ( withAdjacency )
indexes << vertices.count(); // add the following vertex (for adjacency)

vertices << QVector3D( p.x() - mapSettings->origin().x(), z, -( p.y() - mapSettings->origin().y() ) );
indexes << vertices.count() - 1;
vertices << QVector3D( p.x() - mapSettings->origin().x(), z2, -( p.y() - mapSettings->origin().y() ) );
indexes << vertices.count() - 1;

if ( withAdjacency )
indexes << vertices.count() - 1; // add the last vertex (for adjacency)

indexes << 0; // add primitive restart
}
}


/// @endcond
@@ -78,7 +78,8 @@ struct QgsLineVertexData
QByteArray createIndexBuffer();
Qt3DRender::QGeometry *createGeometry( Qt3DCore::QNode *parent );

void addLineString( const QgsLineString &lineString );
void addLineString( const QgsLineString &lineString, float extraHeightOffset = 0 );
void addVerticalLines( const QgsLineString &lineString, float verticalLength );
};

/// @endcond
@@ -93,7 +93,19 @@ void QgsPolygon3DSymbolHandler::processPolygon( QgsPolygon *polyClone, QgsFeatur
for ( int i = 0; i < polyClone->numInteriorRings(); ++i )
outEdges.addLineString( *static_cast<const QgsLineString *>( polyClone->interiorRing( i ) ) );

// TODO: if has extrusion: also add vertical edges for each vertex
if ( extrusionHeight )
{
// add roof and wall edges
const QgsLineString *exterior = static_cast<const QgsLineString *>( polyClone->exteriorRing() );
outEdges.addLineString( *exterior, extrusionHeight );
outEdges.addVerticalLines( *exterior, extrusionHeight );
for ( int i = 0; i < polyClone->numInteriorRings(); ++i )
{
const QgsLineString *interior = static_cast<const QgsLineString *>( polyClone->interiorRing( i ) );
outEdges.addLineString( *interior, extrusionHeight );
outEdges.addVerticalLines( *interior, extrusionHeight );
}
}
}

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

0 comments on commit 50dd4b1

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