diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_collection.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 32 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 29 |
3 files changed, 34 insertions, 28 deletions
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h index b646d1d5e40..bfdafc3ad23 100644 --- a/source/blender/blenkernel/BKE_collection.h +++ b/source/blender/blenkernel/BKE_collection.h @@ -59,6 +59,7 @@ bool BKE_collection_object_remove(struct Main *bmain, struct ID *owner_id, struc bool BKE_collections_object_remove(struct Main *bmain, struct ID *owner_id, struct Object *object, const bool free_us); void BKE_collection_object_move(struct ID *owner_id, struct SceneCollection *sc_dst, struct SceneCollection *sc_src, struct Object *ob); bool BKE_collection_object_exists(struct SceneCollection *scene_collection, struct Object *ob); +struct SceneCollection *BKE_collection_from_index(struct Scene *scene, const int index); struct Group *BKE_collection_group_create(struct Main *bmain, struct Scene *scene, struct LayerCollection *lc); 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; diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 951513d351b..593c1aa3d35 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -2048,33 +2048,6 @@ bool ED_object_editmode_calc_active_center(Object *obedit, const bool select_onl #define COLLECTION_INVALID_INDEX -1 -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; -} - -static SceneCollection *scene_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 int move_to_collection_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); @@ -2089,7 +2062,7 @@ static int move_to_collection_exec(bContext *C, wmOperator *op) } int collection_index = RNA_property_int_get(op->ptr, prop); - scene_collection = scene_collection_from_index(CTX_data_scene(C), collection_index); + scene_collection = BKE_collection_from_index(CTX_data_scene(C), collection_index); if (scene_collection == NULL) { BKE_report(op->reports, RPT_ERROR, "Unexpected error, collection not found"); return OPERATOR_CANCELLED; |