Skip to content
Permalink
Browse files

Fix rendering of 3d extruded lines

  • Loading branch information
nyalldawson committed Jul 27, 2020
1 parent d096dfd commit 4205ebfb7bbc33cc881a0ad84d8bbc592cd93fba
@@ -165,7 +165,7 @@ void QgsBufferedLine3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, cons
QByteArray data( ( const char * )out.tessellator->data().constData(), out.tessellator->data().count() * sizeof( float ) );
int nVerts = data.count() / out.tessellator->stride();

QgsTessellatedPolygonGeometry *geometry = new QgsTessellatedPolygonGeometry( false, false, false, false );
QgsTessellatedPolygonGeometry *geometry = new QgsTessellatedPolygonGeometry( true, false, false, false );
geometry->setData( data, nVerts, out.triangleIndexFids, out.triangleIndexStartingIndices );

Qt3DRender::QGeometryRenderer *renderer = new Qt3DRender::QGeometryRenderer;
@@ -65,6 +65,8 @@ class TestQgs3DRendering : public QObject
void testMeshTerrain();
void testExtrudedPolygons();
void testLineRendering();
void testBufferedLineRendering();
void testBufferedLineRenderingWidth();
void testMapTheme();
void testMesh();
void testRuleBasedRenderer();
@@ -391,6 +393,97 @@ void TestQgs3DRendering::testLineRendering()
delete layerLines;
}

void TestQgs3DRendering::testBufferedLineRendering()
{
QgsRectangle fullExtent = mLayerDtm->extent();

QgsVectorLayer *layerLines = new QgsVectorLayer( QString( TEST_DATA_DIR ) + "/3d/lines.shp", "lines", "ogr" );
QVERIFY( layerLines->isValid() );

QgsLine3DSymbol *lineSymbol = new QgsLine3DSymbol;
lineSymbol->setWidth( 10 );
lineSymbol->setExtrusionHeight( 30 );
QgsPhongMaterialSettings mat;
mat.setAmbient( Qt::red );
lineSymbol->setMaterial( mat.clone() );
layerLines->setRenderer3D( new QgsVectorLayer3DRenderer( lineSymbol ) );

Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << layerLines );
QgsPointLightSettings defaultLight;
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setPointLights( QList<QgsPointLightSettings>() << defaultLight );

QgsFlatTerrainGenerator *flatTerrain = new QgsFlatTerrainGenerator;
flatTerrain->setCrs( map->crs() );
flatTerrain->setExtent( fullExtent );
map->setTerrainGenerator( flatTerrain );

QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );

scene->cameraController()->setLookingAtPoint( QgsVector3D( 300, 0, 250 ), 500, 45, 0 );

// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
Qgs3DUtils::captureSceneImage( engine, scene );

QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QVERIFY( renderCheck( "buffered_lines", img, 40 ) );

delete layerLines;
}

void TestQgs3DRendering::testBufferedLineRenderingWidth()
{
QgsRectangle fullExtent = mLayerDtm->extent();

QgsVectorLayer *layerLines = new QgsVectorLayer( QString( TEST_DATA_DIR ) + "/3d/lines.shp", "lines", "ogr" );
QVERIFY( layerLines->isValid() );

QgsLine3DSymbol *lineSymbol = new QgsLine3DSymbol;
lineSymbol->setWidth( 20 );
lineSymbol->setExtrusionHeight( 30 );
lineSymbol->setHeight( 10 );
QgsPhongMaterialSettings mat;
mat.setAmbient( Qt::red );
lineSymbol->setMaterial( mat.clone() );
layerLines->setRenderer3D( new QgsVectorLayer3DRenderer( lineSymbol ) );

Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setOrigin( QgsVector3D( fullExtent.center().x(), fullExtent.center().y(), 0 ) );
map->setLayers( QList<QgsMapLayer *>() << layerLines );
QgsPointLightSettings defaultLight;
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setPointLights( QList<QgsPointLightSettings>() << defaultLight );

QgsFlatTerrainGenerator *flatTerrain = new QgsFlatTerrainGenerator;
flatTerrain->setCrs( map->crs() );
flatTerrain->setExtent( fullExtent );
map->setTerrainGenerator( flatTerrain );

QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *map, &engine );
engine.setRootEntity( scene );

scene->cameraController()->setLookingAtPoint( QgsVector3D( 300, 0, 250 ), 500, 45, 0 );

// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
Qgs3DUtils::captureSceneImage( engine, scene );

QImage img = Qgs3DUtils::captureSceneImage( engine, scene );
QVERIFY( renderCheck( "buffered_lines_width", img, 40 ) );

delete layerLines;
}

void TestQgs3DRendering::testMapTheme()
{
QgsRectangle fullExtent = mLayerDtm->extent();
@@ -0,0 +1 @@
UTF-8
Binary file not shown.
@@ -0,0 +1 @@
PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 4205ebf

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