[Bf-blender-cvs] [ba100c883c8] master: BKE collection: add util to add a collection using another collection as 'template'.

Bastien Montagne noreply at git.blender.org
Wed Jul 15 18:17:39 CEST 2020


Commit: ba100c883c854572fc8fe0898ba89e48da5c1155
Author: Bastien Montagne
Date:   Wed Jul 15 18:07:56 2020 +0200
Branches: master
https://developer.blender.org/rBba100c883c854572fc8fe0898ba89e48da5c1155

BKE collection: add util to add a collection using another collection as 'template'.

Similar to what we already had using an object as 'template'.

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

M	source/blender/blenkernel/BKE_collection.h
M	source/blender/blenkernel/intern/collection.c

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

diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index 4cf33640ebd..db2fe651c91 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -56,6 +56,10 @@ void BKE_collection_add_from_object(struct Main *bmain,
                                     struct Scene *scene,
                                     const struct Object *ob_src,
                                     struct Collection *collection_dst);
+void BKE_collection_add_from_collection(struct Main *bmain,
+                                        struct Scene *scene,
+                                        struct Collection *collection_src,
+                                        struct Collection *collection_dst);
 void BKE_collection_free(struct Collection *collection);
 bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bool hierarchy);
 
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 7e22048379b..4bd0c77af28 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -249,6 +249,34 @@ void BKE_collection_add_from_object(Main *bmain,
   BKE_main_collection_sync(bmain);
 }
 
+/**
+ * Add \a collection_dst to all scene collections that reference collection \a collection_src is
+ * in.
+ *
+ * Logic is very similar to #BKE_collection_object_add_from().
+ */
+void BKE_collection_add_from_collection(Main *bmain,
+                                        Scene *scene,
+                                        Collection *collection_src,
+                                        Collection *collection_dst)
+{
+  bool is_instantiated = false;
+
+  FOREACH_SCENE_COLLECTION_BEGIN (scene, collection) {
+    if (!ID_IS_LINKED(collection) && BKE_collection_has_collection(collection, collection_src)) {
+      collection_child_add(collection, collection_dst, 0, true);
+      is_instantiated = true;
+    }
+  }
+  FOREACH_SCENE_COLLECTION_END;
+
+  if (!is_instantiated) {
+    collection_child_add(scene->master_collection, collection_dst, 0, true);
+  }
+
+  BKE_main_collection_sync(bmain);
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */



More information about the Bf-blender-cvs mailing list