From 2778937fb6b965d4c428f87551cccb2eafd56bf1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 30 Aug 2020 13:19:50 +1000 Subject: BKE_layer: add BKE_view_layer_array_selected_objects_params Useful for similar situations as BKE_view_layer_array_from_bases_in_mode_params without depending on the active objects mode. --- source/blender/blenkernel/intern/layer_utils.c | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/layer_utils.c b/source/blender/blenkernel/intern/layer_utils.c index 20ad0cb6af1..513bc9e1420 100644 --- a/source/blender/blenkernel/intern/layer_utils.c +++ b/source/blender/blenkernel/intern/layer_utils.c @@ -34,6 +34,63 @@ #include "MEM_guardedalloc.h" +/* -------------------------------------------------------------------- */ +/** \name Selected Object Array + * \{ */ + +Object **BKE_view_layer_array_selected_objects_params( + struct ViewLayer *view_layer, + const struct View3D *v3d, + uint *r_len, + const struct ObjectsInViewLayerParams *params) +{ + if (params->no_dup_data) { + FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) { + ID *id = ob_iter->data; + if (id) { + id->tag |= LIB_TAG_DOIT; + } + } + FOREACH_SELECTED_OBJECT_END; + } + + Object **object_array = NULL; + BLI_array_declare(object_array); + + FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) { + if (params->filter_fn) { + if (!params->filter_fn(ob_iter, params->filter_userdata)) { + continue; + } + } + + if (params->no_dup_data) { + ID *id = ob_iter->data; + if (id) { + if (id->tag & LIB_TAG_DOIT) { + id->tag &= ~LIB_TAG_DOIT; + } + else { + continue; + } + } + } + + BLI_array_append(object_array, ob_iter); + } + FOREACH_SELECTED_OBJECT_END; + + object_array = MEM_reallocN(object_array, sizeof(*object_array) * BLI_array_len(object_array)); + /* We always need a valid allocation (prevent crash on free). */ + if (object_array == NULL) { + object_array = MEM_mallocN(0, __func__); + } + *r_len = BLI_array_len(object_array); + return object_array; +} + +/** \} */ + /* -------------------------------------------------------------------- */ /** \name Objects in Mode Array * \{ */ -- cgit v1.2.3