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/metaball/mball_edit.c | |
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/metaball/mball_edit.c')
-rw-r--r-- | source/blender/editors/metaball/mball_edit.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index 42eda235276..de725d391f7 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -372,17 +372,22 @@ static int select_random_metaelems_exec(bContext *C, wmOperator *op) MetaBall *mb = (MetaBall *)obedit->data; MetaElem *ml; const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT); - float percent = 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"); + RNG *rng = BLI_rng_new_srandom(seed); + for (ml = mb->editelems->first; ml; ml = ml->next) { - if (BLI_frand() < percent) { + if (BLI_rng_get_float(rng) < randfac) { if (select) ml->flag |= SELECT; else ml->flag &= ~SELECT; } } - + + BLI_rng_free(rng); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, mb); return OPERATOR_FINISHED; @@ -404,9 +409,7 @@ void MBALL_OT_select_random_metaelems(struct wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, - "Percent", "Percentage of elements to select randomly", 0.0f, 100.0f); - WM_operator_properties_select_action_simple(ot, SEL_SELECT); + WM_operator_properties_select_random(ot); } /***************************** Duplicate operator *****************************/ |