diff options
author | Piotr Makal <pmakal> | 2021-06-28 10:04:34 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-06-28 12:51:49 +0300 |
commit | 1c8c91384c8d7d23b9a966802182e3ef607103ac (patch) | |
tree | c9ab22b882e374073acb6d713b005a1a959fc625 /source/blender/editors/object/object_select.c | |
parent | ab31c2432225f9e82fbfe6a15cef14e8f65d3f05 (diff) |
Apply random selection precisely for curves, lattices & objects
This patch is part of: T87228.
Support accurate random selection for:
- CURVE_OT_select_random
- LATTICE_OT_select_random
- OBJECT_OT_select_random
Ref D11685
Diffstat (limited to 'source/blender/editors/object/object_select.c')
-rw-r--r-- | source/blender/editors/object/object_select.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c index 2fcf432bf18..1a0c5a6a83f 100644 --- a/source/blender/editors/object/object_select.c +++ b/source/blender/editors/object/object_select.c @@ -26,6 +26,8 @@ #include <stdlib.h> #include <string.h> +#include "MEM_guardedalloc.h" + #include "DNA_anim_types.h" #include "DNA_armature_types.h" #include "DNA_collection_types.h" @@ -1454,20 +1456,28 @@ void OBJECT_OT_select_less(wmOperatorType *ot) static int object_select_random_exec(bContext *C, wmOperator *op) { + const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT); const float randfac = RNA_float_get(op->ptr, "ratio"); const int seed = WM_operator_properties_select_random_seed_increment_get(op); - const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT); - RNG *rng = BLI_rng_new_srandom(seed); + ListBase ctx_data_list; + CTX_data_selectable_bases(C, &ctx_data_list); + const int tot = BLI_listbase_count(&ctx_data_list); + int elem_map_len = 0; + Base **elem_map = MEM_mallocN(sizeof(*elem_map) * tot, __func__); - CTX_DATA_BEGIN (C, Base *, base, selectable_bases) { - if (BLI_rng_get_float(rng) < randfac) { - ED_object_base_select(base, select); - } + CollectionPointerLink *ctx_link; + for (ctx_link = ctx_data_list.first; ctx_link; ctx_link = ctx_link->next) { + elem_map[elem_map_len++] = ctx_link->ptr.data; } - CTX_DATA_END; + BLI_freelistN(&ctx_data_list); - BLI_rng_free(rng); + BLI_array_randomize(elem_map, sizeof(*elem_map), elem_map_len, seed); + const int count_select = elem_map_len * randfac; + for (int i = 0; i < count_select; i++) { + ED_object_base_select(elem_map[i], select); + } + MEM_freeN(elem_map); Scene *scene = CTX_data_scene(C); DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); |