From d6660f88ed752dff430ca896d1681a34c6fd9d77 Mon Sep 17 00:00:00 2001 From: David Carter Date: Mon, 28 Oct 2024 13:05:48 -0400 Subject: [PATCH] Materials: Selectively apply appearances Change the appearance only if the appearance hasn't been set explicitly. A cached material appearance is used to see if the current appearance matches the last material. It is also compared against an empty material to see if the saved material value has been initialized. This solves the problem of material changes overwriting appearance changes --- src/Gui/ViewProviderGeometryObject.cpp | 13 ++++++++++++- src/Gui/ViewProviderGeometryObject.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Gui/ViewProviderGeometryObject.cpp b/src/Gui/ViewProviderGeometryObject.cpp index d7c1754c15..d4d4cba0e3 100644 --- a/src/Gui/ViewProviderGeometryObject.cpp +++ b/src/Gui/ViewProviderGeometryObject.cpp @@ -188,8 +188,19 @@ void ViewProviderGeometryObject::updateData(const App::Property* prop) // Set the appearance from the material auto geometry = dynamic_cast(getObject()); if (geometry) { + /* + * Change the appearance only if the appearance hasn't been set explicitly. A cached + * material appearance is used to see if the current appearance matches the last + * material. It is also compared against an empty material to see if the saved + * material value has been initialized. + */ + App::Material defaultMaterial; auto material = geometry->getMaterialAppearance(); - ShapeAppearance.setValue(material); + if ((materialAppearance == defaultMaterial) + || (ShapeAppearance.getSize() == 1 && ShapeAppearance[0] == materialAppearance)) { + ShapeAppearance.setValue(material); + } + materialAppearance = material; } } diff --git a/src/Gui/ViewProviderGeometryObject.h b/src/Gui/ViewProviderGeometryObject.h index 607cd42d2f..3561b1178a 100644 --- a/src/Gui/ViewProviderGeometryObject.h +++ b/src/Gui/ViewProviderGeometryObject.h @@ -116,6 +116,8 @@ protected: SoFCBoundingBox* pcBoundingBox {nullptr}; SoSwitch* pcBoundSwitch {nullptr}; SoBaseColor* pcBoundColor {nullptr}; + + App::Material materialAppearance; }; } // namespace Gui