Commit: bb4de77b82f2099e0ee350b7067a7fd5f75b1b6f
Author: Bastien Montagne
Date:   Tue Dec 21 09:51:18 2021 +0100
Branches: master
https://developer.blender.org/rBbb4de77b82f2099e0ee350b7067a7fd5f75b1b6f

Fix T93839: Copy/Paste of empty instantiating a collection.

Do not also instantiate a collection in the view layer, if it is already
instantiated through an empty object.

===================================================================

M       source/blender/blenkernel/intern/blendfile_link_append.c

===================================================================

diff --git a/source/blender/blenkernel/intern/blendfile_link_append.c 
b/source/blender/blenkernel/intern/blendfile_link_append.c
index c265a6e2b7d..14ed99487d9 100644
--- a/source/blender/blenkernel/intern/blendfile_link_append.c
+++ b/source/blender/blenkernel/intern/blendfile_link_append.c
@@ -440,6 +440,16 @@ static bool object_in_any_collection(Main *bmain, Object 
*ob)
   return false;
 }
 
+static bool collection_instantiated_by_any_object(Main *bmain, Collection 
*collection)
+{
+  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
+    if (ob->type == OB_EMPTY && ob->instance_collection == collection) {
+      return true;
+    }
+  }
+  return false;
+}
+
 static ID *loose_data_instantiate_process_check(LooseDataInstantiateContext 
*instantiate_context,
                                                 BlendfileLinkAppendContextItem 
*item)
 {
@@ -633,12 +643,19 @@ static void loose_data_instantiate_collection_process(
      * children.
      */
     Collection *collection = (Collection *)id;
+    /* The collection could be linked/appended together with an Empty object 
instantiating it,
+     * better not instantiate the collection in the viewlayer in that case.
+     *
+     * Can easily happen when copy/pasting such instantiating empty, see 
T93839. */
+    const bool collection_is_instantiated = 
collection_instantiated_by_any_object(bmain,
+                                                                               
   collection);
     /* Always consider adding collections directly selected by the user. */
-    bool do_add_collection = (item->tag & LINK_APPEND_TAG_INDIRECT) == 0;
+    bool do_add_collection = (item->tag & LINK_APPEND_TAG_INDIRECT) == 0 &&
+                             !collection_is_instantiated;
     /* In linking case, do not enforce instantiating non-directly linked 
collections/objects.
      * This avoids cluttering the ViewLayers, user can instantiate themselves 
specific collections
      * or objects easily from the Outliner if needed. */
-    if (!do_add_collection && do_append) {
+    if (!do_add_collection && do_append && !collection_is_instantiated) {
       LISTBASE_FOREACH (CollectionObject *, coll_ob, &collection->gobject) {
         Object *ob = coll_ob->ob;
         if (!object_in_any_scene(bmain, ob)) {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to