Fix T92224: Refactor of append code unexpectedly changed behavior with 'localize all' off.

In 2.93 and before, when appending wityh 'localize all' off, all linked
IDs (including indirectly linked ones) from initial library would be
made local.
In 3.0, after refactor from rB3be5ce4aad5e, only directly linked IDs
(i.e. user-selected IDs) would be made local.

This change was not intentional (result of confusing code and naming in
previous implementation), and old behavior is used in some workflows to
control which data is kept linked and which data is made local.

This commit revert to 2.93 behavior.

NOTE: there is still an (extreme) corner case where behavior is
different between 2.93 and 3.0:
If you append (at the same time) object A from LibA.blend, and object B
from LibB.blend, and object B uses somehow a material from LibA.blend:
* In 2.93, that material would have been made local (because it belonged
  to one of the 'initial' libraries, even though not the initial lib of
  object B).
* In 3.0, this material will remain linked, since from object B
  persective it comes from a different library.
This commit is contained in:
Bastien Montagne 2021-10-19 16:08:03 +02:00
parent 1c5722ba07
commit b3b7319de7
Notes: blender-bot 2023-05-03 10:14:48 +02:00
Referenced by issue #92224, Handling of appending collections that contain linked materials has changed from 2.93 to 3.0, no longer works as expected
2 changed files with 11 additions and 4 deletions

View File

@ -220,7 +220,9 @@ typedef enum eBLOLibLinkFlags {
BLO_LIBLINK_NEEDS_ID_TAG_DOIT = 1 << 18,
/** Set fake user on appended IDs. */
BLO_LIBLINK_APPEND_SET_FAKEUSER = 1 << 19,
/** Append (make local) also indirect dependencies of appended IDs. */
/** Append (make local) also indirect dependencies of appended IDs comming from other libraries.
* NOTE: All IDs (including indirectly linked ones) coming from the same initial library are
* always made local. */
BLO_LIBLINK_APPEND_RECURSIVE = 1 << 20,
/** Try to re-use previously appended matching ID on new append. */
BLO_LIBLINK_APPEND_LOCAL_ID_REUSE = 1 << 21,

View File

@ -619,6 +619,13 @@ static int foreach_libblock_append_callback(LibraryIDLinkCallbackData *cb_data)
return IDWALK_RET_NOP;
}
const bool do_recursive = (data->lapp_data->flag & BLO_LIBLINK_APPEND_RECURSIVE) != 0;
if (!do_recursive && cb_data->id_owner->lib != id->lib) {
/* When `do_recursive` is false, we only make local IDs from same library(-ies) as the
* initially directly linked ones. */
return IDWALK_RET_NOP;
}
WMLinkAppendDataItem *item = BLI_ghash_lookup(data->lapp_data->new_id_to_item, id);
if (item == NULL) {
item = wm_link_append_data_item_add(data->lapp_data, id->name, GS(id->name), NULL);
@ -651,7 +658,6 @@ static void wm_append_do(WMLinkAppendData *lapp_data,
{
BLI_assert((lapp_data->flag & FILE_LINK) == 0);
const bool do_recursive = (lapp_data->flag & BLO_LIBLINK_APPEND_RECURSIVE) != 0;
const bool set_fakeuser = (lapp_data->flag & BLO_LIBLINK_APPEND_SET_FAKEUSER) != 0;
const bool do_reuse_local_id = (lapp_data->flag & BLO_LIBLINK_APPEND_LOCAL_ID_REUSE) != 0;
@ -723,8 +729,7 @@ static void wm_append_do(WMLinkAppendData *lapp_data,
/* Only check dependencies if we are not keeping linked data, nor re-using existing local data.
*/
if (do_recursive &&
!ELEM(item->append_action, WM_APPEND_ACT_KEEP_LINKED, WM_APPEND_ACT_REUSE_LOCAL)) {
if (!ELEM(item->append_action, WM_APPEND_ACT_KEEP_LINKED, WM_APPEND_ACT_REUSE_LOCAL)) {
WMLinkAppendDataCallBack cb_data = {
.lapp_data = lapp_data, .item = item, .reports = reports};
BKE_library_foreach_ID_link(