From 37b4384b59c09684ac4ece5e39bf20187968f737 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 12 Aug 2019 15:37:58 +0200 Subject: Fix T67032: Do not systematically link 'orphaned' indirectly linked objects to scene. Not even in append case. If those objects are already part of a collection, we can now leave them fully un-instantiated in any scene, since user can easily do it themselves as they need to. --- source/blender/blenloader/intern/readfile.c | 42 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 9a4fde8cc42..65120fc4c10 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -11129,6 +11129,19 @@ static bool object_in_any_scene(Main *bmain, Object *ob) return false; } +static bool object_in_any_collection(Main *bmain, Object *ob) +{ + Collection *collection; + + for (collection = bmain->collections.first; collection; collection = collection->id.next) { + if (BKE_collection_has_object(collection, ob)) { + return true; + } + } + + return false; +} + static void add_loose_objects_to_scene(Main *mainvar, Main *bmain, Scene *scene, @@ -11138,7 +11151,7 @@ static void add_loose_objects_to_scene(Main *mainvar, const short flag) { Collection *active_collection = NULL; - const bool is_link = (flag & FILE_LINK) != 0; + const bool do_append = (flag & FILE_LINK) == 0; BLI_assert(scene); @@ -11147,14 +11160,13 @@ static void add_loose_objects_to_scene(Main *mainvar, for (Object *ob = mainvar->objects.first; ob; ob = ob->id.next) { bool do_it = (ob->id.tag & LIB_TAG_DOIT) != 0; if (do_it || ((ob->id.tag & LIB_TAG_INDIRECT) && (ob->id.tag & LIB_TAG_PRE_EXISTING) == 0)) { - if (!is_link) { + if (do_append) { if (ob->id.us == 0) { do_it = true; } - else if ((ob->id.lib == lib) && (object_in_any_scene(bmain, ob) == 0)) { - /* When appending, make sure any indirectly loaded objects get a base, - * else they cant be accessed at all - * (see T27437). */ + else if ((ob->id.lib == lib) && (object_in_any_collection(bmain, ob) == 0)) { + /* When appending, make sure any indirectly loaded object gets a base, + * when they are not part of any collection yet. */ do_it = true; } } @@ -11204,8 +11216,6 @@ static void add_collections_to_scene(Main *mainvar, Library *lib, const short flag) { - const bool do_append = (flag & FILE_LINK) == 0; - Collection *active_collection = scene->master_collection; if (flag & FILE_ACTIVE_COLLECTION) { LayerCollection *lc = BKE_layer_collection_get_active(view_layer); @@ -11244,12 +11254,10 @@ static void add_collections_to_scene(Main *mainvar, ob->transflag |= OB_DUPLICOLLECTION; copy_v3_v3(ob->loc, scene->cursor.location); } - /* We do not want to force instantiation of indirectly linked collections... - * Except when we are appending (since in that case, we'll end up instantiating all objects, - * it's better to do it via their own collections if possible). - * Reports showing that desired difference in behaviors between link and append: - * See T62570, T61796. */ - else if (do_append || (collection->id.tag & LIB_TAG_INDIRECT) == 0) { + /* We do not want to force instantiation of indirectly linked collections, + * not even when appending. Users can now easily instantiate collections (and their objects) + * as needed by themsleves. See T67032. */ + else if ((collection->id.tag & LIB_TAG_INDIRECT) == 0) { bool do_add_collection = (collection->id.tag & LIB_TAG_DOIT) != 0; if (!do_add_collection) { /* We need to check that objects in that collections are already instantiated in a scene. @@ -11261,9 +11269,8 @@ static void add_collections_to_scene(Main *mainvar, for (CollectionObject *coll_ob = collection->gobject.first; coll_ob != NULL; coll_ob = coll_ob->next) { Object *ob = coll_ob->ob; - if ((ob->id.tag & LIB_TAG_PRE_EXISTING) == 0 && (ob->id.tag & LIB_TAG_DOIT) == 0 && - (do_append || (ob->id.tag & LIB_TAG_INDIRECT) == 0) && (ob->id.lib == lib) && - (object_in_any_scene(bmain, ob) == 0)) { + if ((ob->id.tag & (LIB_TAG_PRE_EXISTING | LIB_TAG_DOIT | LIB_TAG_INDIRECT)) == 0 && + (ob->id.lib == lib) && (object_in_any_scene(bmain, ob) == 0)) { do_add_collection = true; break; } @@ -11285,6 +11292,7 @@ static void add_collections_to_scene(Main *mainvar, } } + /* Those are kept for safety and consistency, but should not be needed anymore? */ collection->id.tag &= ~LIB_TAG_INDIRECT; collection->id.tag |= LIB_TAG_EXTERN; } -- cgit v1.2.3