diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-10-10 15:47:41 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-10-10 15:52:11 +0300 |
commit | 05acf3d43a1d9655ee41d68470647d9409eaff40 (patch) | |
tree | 751802b51470d2225ec3442f031778553ba61482 /source/blender/editors/physics | |
parent | 240f356166e70dc495b44a4628d36181c93ff1a0 (diff) |
Random Select Seed Option
Add 'Seed' option for all random select operators
D1508 by @mba105, w/ edits
Diffstat (limited to 'source/blender/editors/physics')
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 892545a8efd..32cd1f7a1ce 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -1634,7 +1634,10 @@ static int select_random_exec(bContext *C, wmOperator *op) int p; int k; - const float randf = RNA_float_get (op->ptr, "percent") / 100.0f; + const float randfac = RNA_float_get (op->ptr, "percent") / 100.0f; + const int seed = RNA_int_get(op->ptr, "seed"); + const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT); + RNG *rng; type = RNA_enum_get(op->ptr, "type"); @@ -1644,10 +1647,12 @@ static int select_random_exec(bContext *C, wmOperator *op) ob = CTX_data_active_object(C); edit = PE_get_current(scene, ob); + rng = BLI_rng_new_srandom(seed); + switch (type) { case RAN_HAIR: LOOP_VISIBLE_POINTS { - int flag = (BLI_frand() < randf) ? SEL_SELECT : SEL_DESELECT; + int flag = ((BLI_rng_get_float(rng) < randfac) == select) ? SEL_SELECT : SEL_DESELECT; LOOP_KEYS { select_action_apply (point, key, flag); } @@ -1656,13 +1661,15 @@ static int select_random_exec(bContext *C, wmOperator *op) case RAN_POINTS: LOOP_VISIBLE_POINTS { LOOP_VISIBLE_KEYS { - int flag = (BLI_frand() < randf) ? SEL_SELECT : SEL_DESELECT; + int flag = ((BLI_rng_get_float(rng) < randfac) == select) ? SEL_SELECT : SEL_DESELECT; select_action_apply (point, key, flag); } } break; } + BLI_rng_free(rng); + PE_update_selection(data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); @@ -1684,9 +1691,7 @@ void PARTICLE_OT_select_random(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ - RNA_def_float_percentage (ot->srna, "percent", 50.0f, 0.0f, 100.0f, "Percent", - "Percentage (mean) of elements in randomly selected set", - 0.0f, 100.0f); + WM_operator_properties_select_random(ot); ot->prop = RNA_def_enum (ot->srna, "type", select_random_type_items, RAN_HAIR, "Type", "Select either hair or points"); } |