Fix T92780: Lost material in case of local object, and missing linked obdata.

By default, when syncing materials slots between object and its obdata,
the amount of slots in obdata is the reference.

Missing linked obdata is replaced by an empty placeholder that has no
material. In that specific case, if we have a valid object ID, we want
to update the (placeholder) obdata's material count from the object one,
and not the other way around.
This commit is contained in:
Bastien Montagne 2021-11-03 17:57:45 +01:00
parent d17128520d
commit c29f9e14e4
Notes: blender-bot 2023-02-14 10:37:50 +01:00
Referenced by issue #92780, Relocate Library Override loses local Materials (but not for automatically overridden data)
1 changed files with 11 additions and 1 deletions

View File

@ -900,7 +900,17 @@ void BKE_object_materials_test(Main *bmain, Object *ob, ID *id)
return;
}
BKE_object_material_resize(bmain, ob, *totcol, false);
if ((ob->id.tag & LIB_TAG_MISSING) == 0 && (id->tag & LIB_TAG_MISSING) != 0) {
/* Exception: In case the object is a valid data, but its obdata is an empty place-holder,
* use object's material slots amount as reference.
* This avoids loosing materials in a local object when its linked obdata gets missing.
* See T92780. */
BKE_id_material_resize(bmain, id, (short)ob->totcol, false);
}
else {
/* Normal case: the use the obdata amount of materials slots to update the object's one. */
BKE_object_material_resize(bmain, ob, *totcol, false);
}
}
void BKE_objects_materials_test_all(Main *bmain, ID *id)