diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-03-29 23:28:05 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-03-30 02:03:47 +0300 |
commit | 156b548208ba21db261c1a8df06f89470f86eaa8 (patch) | |
tree | 6afefdb8357ec78b39e5e1e19d2981e17e6974aa /source/blender/blenkernel/intern/collection.c | |
parent | 1251043636d37f36bc2e7c845e6542898476707d (diff) |
Collections: API to get collection from index
Diffstat (limited to 'source/blender/blenkernel/intern/collection.c')
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index aed0ffb9fc3..669bbfb00cc 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -523,6 +523,38 @@ bool BKE_collection_object_exists(struct SceneCollection *scene_collection, stru return false; } +static SceneCollection *scene_collection_from_index_recursive(SceneCollection *scene_collection, const int index, int *index_current) +{ + if (index == (*index_current)) { + return scene_collection; + } + + (*index_current)++; + + for (SceneCollection *scene_collection_iter = scene_collection->scene_collections.first; + scene_collection_iter != NULL; + scene_collection_iter = scene_collection_iter->next) + { + SceneCollection *nested = scene_collection_from_index_recursive(scene_collection_iter, index, index_current); + if (nested != NULL) { + return nested; + } + } + return NULL; +} + +/** + * Return Scene Collection for a given index. + * + * The index is calculated from top to bottom counting the children before the siblings. + */ +SceneCollection *BKE_collection_from_index(Scene *scene, const int index) +{ + int index_current = 0; + SceneCollection *master_collection = BKE_collection_master(&scene->id); + return scene_collection_from_index_recursive(master_collection, index, &index_current); +} + static void layer_collection_sync(LayerCollection *lc_dst, LayerCollection *lc_src) { lc_dst->flag = lc_src->flag; |