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

Similar to what we already had using an object as 'template'.
This commit is contained in:
Bastien Montagne 2020-07-15 18:07:56 +02:00
parent a082e49671
commit ba100c883c
2 changed files with 32 additions and 0 deletions

View File

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

View File

@ -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);
}
/** \} */
/* -------------------------------------------------------------------- */