diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-08-30 06:19:50 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-08-30 06:42:28 +0300 |
commit | 2778937fb6b965d4c428f87551cccb2eafd56bf1 (patch) | |
tree | fea666d43b4bf44edcc8f771464b22e5ac6a4c51 /source/blender/blenkernel/intern/layer_utils.c | |
parent | e06050945e25c26167c4f193d214936e70a231a8 (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern/layer_utils.c')
-rw-r--r-- | source/blender/blenkernel/intern/layer_utils.c | 57 |
1 files changed, 57 insertions, 0 deletions
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 @@ -35,6 +35,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 * \{ */ |