diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2014-10-08 20:09:32 +0400 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2014-10-08 20:10:27 +0400 |
commit | 9c97624fc966000008e940eaffe279afb2e28b07 (patch) | |
tree | 1eb404e7cbc7a9238c230a06d86cce66fa57451e /source/blender/editors/physics/particle_edit.c | |
parent | 0ba84b7124e17eda444d8fca856f2e5c252a59f0 (diff) |
Select Random in Particle Edit Mode, by jezv
Added the select random functionality in particle edit mode for hairs or control points.
Reviewers: campbellbarton, lukastoenne
Reviewed By: lukastoenne
Subscribers: campbellbarton, kevindietrich, jezv
Projects: #quick_hacks, #bf_blender, #physics
Maniphest Tasks: T37873
Differential Revision: https://developer.blender.org/D809
Diffstat (limited to 'source/blender/editors/physics/particle_edit.c')
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 76344b77dd3..9a3433b0ccf 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -1588,6 +1588,87 @@ void PARTICLE_OT_select_tips(wmOperatorType *ot) WM_operator_properties_select_action(ot, SEL_SELECT); } +/*********************** select random operator ************************/ + +enum { RAN_HAIR, RAN_POINTS }; + +static EnumPropertyItem select_random_type_items[] = { + {RAN_HAIR, "HAIR", 0, "Hair", ""}, + {RAN_POINTS, "POINTS", 0, "Points", ""}, + {0, NULL, 0, NULL, NULL} +}; + +static int select_random_exec(bContext *C, wmOperator *op) +{ + PEData data; + int type; + Scene *scene; + Object *ob; + + /* used by LOOP_VISIBLE_POINTS, LOOP_VISIBLE_KEYS and LOOP_KEYS */ + PTCacheEdit *edit; + PTCacheEditPoint *point; + PTCacheEditKey *key; + int p; + int k; + + const float randf = RNA_float_get (op->ptr, "percent") / 100.0f; + + type = RNA_enum_get(op->ptr, "type"); + + PE_set_data(C, &data); + data.select_action = SEL_SELECT; + scene = CTX_data_scene(C); + ob = CTX_data_active_object(C); + edit = PE_get_current(scene, ob); + + switch (type) { + case RAN_HAIR: + LOOP_VISIBLE_POINTS { + int flag = (BLI_frand() < randf) ? SEL_SELECT : SEL_DESELECT; + LOOP_KEYS { + select_action_apply (point, key, flag); + } + } + break; + case RAN_POINTS: + LOOP_VISIBLE_POINTS { + LOOP_VISIBLE_KEYS { + int flag = (BLI_frand() < randf) ? SEL_SELECT : SEL_DESELECT; + select_action_apply (point, key, flag); + } + } + break; + } + + PE_update_selection(data.scene, data.ob, 1); + WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_select_random(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Select Random"; + ot->idname = "PARTICLE_OT_select_random"; + ot->description = "Select a randomly distributed set of hair or points"; + + /* api callbacks */ + ot->exec = select_random_exec; + ot->poll = PE_poll; + + /* flags */ + 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); + ot->prop = RNA_def_enum (ot->srna, "type", select_random_type_items, RAN_HAIR, + "Type", "Select either hair or points"); +} + /************************ select linked operator ************************/ static int select_linked_exec(bContext *C, wmOperator *op) |