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.
This commit is contained in:
Bastien Montagne 2019-08-12 15:37:58 +02:00
parent 102035373a
commit 37b4384b59
Notes: blender-bot 2023-02-14 11:01:33 +01:00
Referenced by issue #67032, Collections:  Appending scene links random collections to existing scene - Need to change policy on 'orphaned' objects in link/append code
1 changed files with 25 additions and 17 deletions

View File

@ -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;
}