Skip to content

Commit

Permalink
Fix rendering of 3d extruded lines
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 27, 2020
1 parent d096dfd commit 4205ebf
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/3d/symbols/qgsline3dsymbol_p.cpp
Expand Up @@ -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;
Expand Down
93 changes: 93 additions & 0 deletions tests/src/3d/testqgs3drendering.cpp
Expand Up @@ -65,6 +65,8 @@ class TestQgs3DRendering : public QObject
void testMeshTerrain();
void testExtrudedPolygons();
void testLineRendering();
void testBufferedLineRendering();
void testBufferedLineRenderingWidth();
void testMapTheme();
void testMesh();
void testRuleBasedRenderer();
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/testdata/3d/lines.cpg
@@ -0,0 +1 @@
UTF-8
Binary file added tests/testdata/3d/lines.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions tests/testdata/3d/lines.prj
@@ -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 added tests/testdata/3d/lines.shp
Binary file not shown.
Binary file added tests/testdata/3d/lines.shx
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4205ebf

Please sign in to comment.