LibOverride: Improve/Fix issues in override resync process.

When we have a local override, its linked reference may not be detected
as needing to be overridden anymore.

In that case, if there is no actual override defined by the user, assume
that we can get rid of this local override as part of the resync
process, and use the linked data directly instead.
This commit is contained in:
Bastien Montagne 2021-02-04 19:20:28 +01:00
parent 0f893656f4
commit 7d5640ee10
1 changed files with 32 additions and 2 deletions

View File

@ -789,9 +789,11 @@ bool BKE_lib_override_library_resync(Main *bmain, Scene *scene, ViewLayer *view_
ID *id_root_reference = id_root->override_library->reference;
BKE_main_relations_create(bmain, 0);
lib_override_local_group_tag(bmain, id_root, LIB_TAG_DOIT, LIB_TAG_MISSING);
lib_override_linked_group_tag(bmain, id_root_reference, LIB_TAG_DOIT, LIB_TAG_MISSING, true);
lib_override_linked_group_tag(bmain, id_root_reference, LIB_TAG_DOIT, LIB_TAG_MISSING, false);
/* Make a mapping 'linked reference IDs' -> 'Local override IDs' of existing overrides. */
GHash *linkedref_to_old_override = BLI_ghash_new(
@ -804,12 +806,40 @@ bool BKE_lib_override_library_resync(Main *bmain, Scene *scene, ViewLayer *view_
* same linked ID in a same hierarchy. */
if (!BLI_ghash_haskey(linkedref_to_old_override, id->override_library->reference)) {
BLI_ghash_insert(linkedref_to_old_override, id->override_library->reference, id);
BLI_assert(id->override_library->reference->tag & LIB_TAG_DOIT);
if ((id->override_library->reference->tag & LIB_TAG_DOIT) == 0) {
/* We have an override, but now it does not seem to be necessary to override that ID
* anymore. Check if there are some actual overrides from the user, otherwise assume
* that we can get rid of this local override. */
LISTBASE_FOREACH (IDOverrideLibraryProperty *, op, &id->override_library->properties) {
if (op->rna_prop_type != PROP_POINTER) {
id->override_library->reference->tag |= LIB_TAG_DOIT;
break;
}
bool do_break = false;
LISTBASE_FOREACH (IDOverrideLibraryPropertyOperation *, opop, &op->operations) {
if ((opop->flag & IDOVERRIDE_LIBRARY_FLAG_IDPOINTER_MATCH_REFERENCE) == 0) {
id->override_library->reference->tag |= LIB_TAG_DOIT;
do_break = true;
break;
}
}
if (do_break) {
break;
}
}
}
}
}
}
FOREACH_MAIN_ID_END;
/* Code above may have added some tags, we need to update this too. */
lib_override_hierarchy_dependencies_recursive_tag(
bmain, id_root_reference, LIB_TAG_DOIT, LIB_TAG_MISSING);
BKE_main_relations_free(bmain);
/* Make new override from linked data. */
/* Note that this call also remaps all pointers of tagged IDs from old override IDs to new
* override IDs (including within the old overrides themselves, since those are tagged too