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/lattice/editlattice_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/lattice/editlattice_select.c')
-rw-r--r-- | source/blender/editors/lattice/editlattice_select.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/source/blender/editors/lattice/editlattice_select.c b/source/blender/editors/lattice/editlattice_select.c index cb3f9a89e62..8d8e1e9f06a 100644 --- a/source/blender/editors/lattice/editlattice_select.c +++ b/source/blender/editors/lattice/editlattice_select.c @@ -108,9 +108,9 @@ bool ED_lattice_deselect_all_multi(struct bContext *C) static int lattice_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); ViewLayer *view_layer = CTX_data_view_layer(C); uint objects_len = 0; @@ -119,29 +119,36 @@ static int lattice_select_random_exec(bContext *C, wmOperator *op) for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *obedit = objects[ob_index]; Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt; + int seed_iter = seed; - RNG *rng = BLI_rng_new_srandom(seed); + /* This gives a consistent result regardless of object order. */ + if (ob_index) { + seed_iter += BLI_ghashutil_strhash_p(obedit->id.name); + } - int tot; - BPoint *bp; + int a = lt->pntsu * lt->pntsv * lt->pntsw; + int elem_map_len = 0; + BPoint **elem_map = MEM_mallocN(sizeof(*elem_map) * a, __func__); + BPoint *bp = lt->def; - tot = lt->pntsu * lt->pntsv * lt->pntsw; - bp = lt->def; - while (tot--) { + while (a--) { if (!bp->hide) { - if (BLI_rng_get_float(rng) < randfac) { - bpoint_select_set(bp, select); - } + elem_map[elem_map_len++] = bp; } bp++; } + BLI_array_randomize(elem_map, sizeof(*elem_map), elem_map_len, seed_iter); + const int count_select = elem_map_len * randfac; + for (int i = 0; i < count_select; i++) { + bpoint_select_set(elem_map[i], select); + } + MEM_freeN(elem_map); + if (select == false) { lt->actbp = LT_ACTBP_NONE; } - BLI_rng_free(rng); - DEG_id_tag_update(obedit->data, ID_RECALC_SELECT); WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); } |