From ba100c883c854572fc8fe0898ba89e48da5c1155 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 15 Jul 2020 18:07:56 +0200 Subject: BKE collection: add util to add a collection using another collection as 'template'. Similar to what we already had using an object as 'template'. --- source/blender/blenkernel/BKE_collection.h | 4 ++++ source/blender/blenkernel/intern/collection.c | 28 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'source/blender') 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); +} + /** \} */ /* -------------------------------------------------------------------- */ -- cgit v1.2.3