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
This commit is contained in:
David Carter
2024-10-28 13:05:48 -04:00
committed by Chris Hennes
parent 7f10bef82b
commit d6660f88ed
2 changed files with 14 additions and 1 deletions

View File

@@ -188,8 +188,19 @@ void ViewProviderGeometryObject::updateData(const App::Property* prop)
// Set the appearance from the material
auto geometry = dynamic_cast<App::GeoFeature*>(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;
}
}