From 05acf3d43a1d9655ee41d68470647d9409eaff40 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 10 Oct 2015 23:47:41 +1100 Subject: Random Select Seed Option Add 'Seed' option for all random select operators D1508 by @mba105, w/ edits --- source/blender/editors/metaball/mball_edit.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'source/blender/editors/metaball') 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 *****************************/ -- cgit v1.2.3