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.
This commit is contained in:
parent
e06050945e
commit
2778937fb6
|
@ -352,6 +352,19 @@ void BKE_view_layer_visible_bases_iterator_end(BLI_Iterator *iter);
|
|||
|
||||
/* layer_utils.c */
|
||||
|
||||
struct ObjectsInViewLayerParams {
|
||||
uint no_dup_data : 1;
|
||||
|
||||
bool (*filter_fn)(struct Object *ob, void *user_data);
|
||||
void *filter_userdata;
|
||||
};
|
||||
|
||||
struct Object **BKE_view_layer_array_selected_objects_params(
|
||||
struct ViewLayer *view_layer,
|
||||
const struct View3D *v3d,
|
||||
uint *r_len,
|
||||
const struct ObjectsInViewLayerParams *params);
|
||||
|
||||
struct ObjectsInModeParams {
|
||||
int object_mode;
|
||||
uint no_dup_data : 1;
|
||||
|
|
|
@ -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
|
||||
* \{ */
|
||||
|
|
Loading…
Reference in New Issue