From 597b74638f4406ee10df123834ff46669d456299 Mon Sep 17 00:00:00 2001 From: Thomas JANVIER Date: Mon, 20 Jan 2025 10:07:52 +0100 Subject: [PATCH] 3d: Use absolute clamping for 3d data by default When providing a project DTM/DEM, the default behavior for vector feature with a z-component is to offset the $z coordinates from the terrain elevation model in the elevation profile view. However, the geometry coordinates are supposed to be absolute. So it makes more sense, to only use the $z coordinate by default in that case. The different unit tests are updated accordingly. Closes: https://github.com/qgis/QGIS/issues/59757 --- src/3d/symbols/qgsline3dsymbol.h | 2 +- src/3d/symbols/qgslinevertexdata_p.h | 2 +- src/3d/symbols/qgsmesh3dsymbol.h | 2 +- src/3d/symbols/qgspoint3dsymbol.h | 2 +- src/3d/symbols/qgspolygon3dsymbol.h | 2 +- tests/src/3d/testqgs3drendering.cpp | 9 +++++++++ tests/src/python/test_qgsmesh3dsymbol.py | 8 ++++---- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/3d/symbols/qgsline3dsymbol.h b/src/3d/symbols/qgsline3dsymbol.h index 12dc7920c8d5..ae644df21064 100644 --- a/src/3d/symbols/qgsline3dsymbol.h +++ b/src/3d/symbols/qgsline3dsymbol.h @@ -123,7 +123,7 @@ class _3D_EXPORT QgsLine3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCTORS private: //! how to handle altitude of vector features - Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative; + Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Absolute; //! how to handle clamping of vertices of individual features Qgis::AltitudeBinding mAltBinding = Qgis::AltitudeBinding::Centroid; diff --git a/src/3d/symbols/qgslinevertexdata_p.h b/src/3d/symbols/qgslinevertexdata_p.h index d1b338c073c5..76f4305e8d5e 100644 --- a/src/3d/symbols/qgslinevertexdata_p.h +++ b/src/3d/symbols/qgslinevertexdata_p.h @@ -77,7 +77,7 @@ struct QgsLineVertexData bool withAdjacency = false; //!< Whether line strip with adjacency primitive will be used // extra info to calculate elevation - Qgis::AltitudeClamping altClamping = Qgis::AltitudeClamping::Relative; + Qgis::AltitudeClamping altClamping = Qgis::AltitudeClamping::Absolute; Qgis::AltitudeBinding altBinding = Qgis::AltitudeBinding::Vertex; float baseHeight = 0; Qgs3DRenderContext renderContext; // used for altitude clamping diff --git a/src/3d/symbols/qgsmesh3dsymbol.h b/src/3d/symbols/qgsmesh3dsymbol.h index 486b038f6aba..7f89164a67ef 100644 --- a/src/3d/symbols/qgsmesh3dsymbol.h +++ b/src/3d/symbols/qgsmesh3dsymbol.h @@ -354,7 +354,7 @@ class _3D_EXPORT QgsMesh3DSymbol : public QgsAbstract3DSymbol #endif //! how to handle altitude of vector features - Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative; + Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Absolute; float mHeight = 0.0f; //!< Base height of triangles std::unique_ptr mMaterialSettings; //!< Defines appearance of objects bool mAddBackFaces = false; diff --git a/src/3d/symbols/qgspoint3dsymbol.h b/src/3d/symbols/qgspoint3dsymbol.h index 45bef877e3fc..6d14fff38673 100644 --- a/src/3d/symbols/qgspoint3dsymbol.h +++ b/src/3d/symbols/qgspoint3dsymbol.h @@ -175,7 +175,7 @@ class _3D_EXPORT QgsPoint3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCTOR private: //! how to handle altitude of vector features - Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative; + Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Absolute; std::unique_ptr mMaterialSettings; //!< Defines appearance of objects Qgis::Point3DShape mShape = Qgis::Point3DShape::Cylinder; //!< What kind of shape to use diff --git a/src/3d/symbols/qgspolygon3dsymbol.h b/src/3d/symbols/qgspolygon3dsymbol.h index 712a12d554f3..047d912f878c 100644 --- a/src/3d/symbols/qgspolygon3dsymbol.h +++ b/src/3d/symbols/qgspolygon3dsymbol.h @@ -186,7 +186,7 @@ class _3D_EXPORT QgsPolygon3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCT private: //! how to handle altitude of vector features - Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative; + Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Absolute; //! how to handle clamping of vertices of individual features Qgis::AltitudeBinding mAltBinding = Qgis::AltitudeBinding::Centroid; diff --git a/tests/src/3d/testqgs3drendering.cpp b/tests/src/3d/testqgs3drendering.cpp index c7aa368e8d29..f129886a477f 100644 --- a/tests/src/3d/testqgs3drendering.cpp +++ b/tests/src/3d/testqgs3drendering.cpp @@ -2003,6 +2003,15 @@ void TestQgs3DRendering::testAmbientOcclusion() mapSettings.setLightSources( { defaultPointLight.clone() } ); mapSettings.setOutputDpi( 92 ); + QgsPhongMaterialSettings materialSettings; + materialSettings.setAmbient( Qt::lightGray ); + QgsPolygon3DSymbol *symbol3d = new QgsPolygon3DSymbol; + symbol3d->setMaterialSettings( materialSettings.clone() ); + symbol3d->setExtrusionHeight( 10.f ); + symbol3d->setAltitudeClamping( Qgis::AltitudeClamping::Relative ); + QgsVectorLayer3DRenderer *renderer3d = new QgsVectorLayer3DRenderer( symbol3d ); + mLayerBuildings->setRenderer3D( renderer3d ); + // =========== creating Qgs3DMapScene QPoint winSize = QPoint( 640, 480 ); // default window size diff --git a/tests/src/python/test_qgsmesh3dsymbol.py b/tests/src/python/test_qgsmesh3dsymbol.py index 5f4fab240e37..e527bce5e434 100644 --- a/tests/src/python/test_qgsmesh3dsymbol.py +++ b/tests/src/python/test_qgsmesh3dsymbol.py @@ -38,9 +38,9 @@ def test_getters_and_setters(self): self.assertEqual(symbol.cullingMode(), Qgs3DTypes.Front) # Test altitude clamping - self.assertEqual(symbol.altitudeClamping(), Qgis.AltitudeClamping.Relative) - symbol.setAltitudeClamping(Qgis.AltitudeClamping.Absolute) self.assertEqual(symbol.altitudeClamping(), Qgis.AltitudeClamping.Absolute) + symbol.setAltitudeClamping(Qgis.AltitudeClamping.Relative) + self.assertEqual(symbol.altitudeClamping(), Qgis.AltitudeClamping.Relative) # Test height self.assertEqual(symbol.height(), 0.0) @@ -152,9 +152,9 @@ def test_equality(self): self.assertEqual(symbol1, symbol2) # Test altitude clamping - symbol2.setAltitudeClamping(Qgis.AltitudeClamping.Absolute) - self.assertNotEqual(symbol1, symbol2) symbol2.setAltitudeClamping(Qgis.AltitudeClamping.Relative) + self.assertNotEqual(symbol1, symbol2) + symbol2.setAltitudeClamping(Qgis.AltitudeClamping.Absolute) self.assertEqual(symbol1, symbol2) # Test height