Skip to content

Commit

Permalink
testqgs3drendering: Add a unit test for phong textured material
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjano committed Jul 19, 2024
1 parent 7abb795 commit 5e71c6e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/src/3d/testqgs3drendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "qgsdirectionallightsettings.h"
#include "qgsmetalroughmaterialsettings.h"
#include "qgspointlightsettings.h"
#include "qgsphongtexturedmaterialsettings.h"

#include <QFileInfo>
#include <QDir>
Expand All @@ -75,6 +76,7 @@ class TestQgs3DRendering : public QgsTest
void testEpsg4978LineRendering();
void testExtrudedPolygons();
void testPhongShading();
void testExtrudedPolygonsTexturedPhong();
void testExtrudedPolygonsDataDefinedPhong();
void testExtrudedPolygonsDataDefinedGooch();
void testExtrudedPolygonsGoochShading();
Expand Down Expand Up @@ -485,6 +487,51 @@ void TestQgs3DRendering::testPhongShading()
QGSVERIFYIMAGECHECK( "phong_shading", "phong_shading", img, QString(), 40, QSize( 0, 0 ), 2 );
}

void TestQgs3DRendering::testExtrudedPolygonsTexturedPhong()
{
QgsPhongTexturedMaterialSettings materialSettings;
materialSettings.setAmbient( QColor( 26, 26, 26 ) );
materialSettings.setSpecular( QColor( 10, 10, 10 ) );
materialSettings.setShininess( 1.0 );
materialSettings.setDiffuseTexturePath( testDataPath( "/sample_image.png" ) );
QgsPolygon3DSymbol *symbol3d = new QgsPolygon3DSymbol;
symbol3d->setMaterialSettings( materialSettings.clone() );
symbol3d->setExtrusionHeight( 10.f );
QgsVectorLayer3DRenderer *renderer3d = new QgsVectorLayer3DRenderer( symbol3d );
mLayerBuildings->setRenderer3D( renderer3d );

const QgsRectangle fullExtent = mLayerDtm->extent();

Qgs3DMapSettings *map = new Qgs3DMapSettings;
map->setCrs( mProject->crs() );
map->setExtent( fullExtent );
map->setLayers( QList<QgsMapLayer *>() << mLayerBuildings << mLayerRgb );
QgsPointLightSettings defaultLight;
defaultLight.setIntensity( 1.0 );
defaultLight.setPosition( QgsVector3D( 0, 1000, 0 ) );
map->setLightSources( { defaultLight.clone() } );

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

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

scene->cameraController()->setLookingAtPoint( QgsVector3D( -60, 10, 360 ), 100, 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 );

delete scene;
delete map;
QGSVERIFYIMAGECHECK( "polygon3d_extrusion_textured_phong", "polygon3d_extrusion_textured_phong", img, QString(), 40, QSize( 0, 0 ), 2 );
}

void TestQgs3DRendering::testExtrudedPolygonsDataDefinedPhong()
{
QgsPropertyCollection propertyColection;
Expand Down
Loading
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 5e71c6e

Please sign in to comment.