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 | |
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
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d.py | 8 | ||||
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 81 | ||||
-rw-r--r-- | source/blender/editors/physics/physics_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/physics/physics_ops.c | 1 |
4 files changed, 91 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 2249d2b04b8..cbae63e1f9a 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -604,6 +604,10 @@ class VIEW3D_MT_select_particle(Menu): layout.separator() + layout.operator("particle.select_random") + + layout.separator() + layout.operator("particle.select_roots", text="Roots") layout.operator("particle.select_tips", text="Tips") @@ -1725,6 +1729,10 @@ class VIEW3D_MT_particle_specials(Menu): layout.separator() + layout.operator("particle.select_random") + + layout.separator() + layout.operator("particle.select_more") layout.operator("particle.select_less") 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) diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h index 77ce5a334e6..b8955c8c397 100644 --- a/source/blender/editors/physics/physics_intern.h +++ b/source/blender/editors/physics/physics_intern.h @@ -39,6 +39,7 @@ struct wmOperatorType; void PARTICLE_OT_select_all(struct wmOperatorType *ot); void PARTICLE_OT_select_roots(struct wmOperatorType *ot); void PARTICLE_OT_select_tips(struct wmOperatorType *ot); +void PARTICLE_OT_select_random(struct wmOperatorType *ot); void PARTICLE_OT_select_linked(struct wmOperatorType *ot); void PARTICLE_OT_select_less(struct wmOperatorType *ot); void PARTICLE_OT_select_more(struct wmOperatorType *ot); diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c index 48cc51ffb55..ff89909b124 100644 --- a/source/blender/editors/physics/physics_ops.c +++ b/source/blender/editors/physics/physics_ops.c @@ -51,6 +51,7 @@ static void operatortypes_particle(void) WM_operatortype_append(PARTICLE_OT_select_all); WM_operatortype_append(PARTICLE_OT_select_roots); WM_operatortype_append(PARTICLE_OT_select_tips); + WM_operatortype_append(PARTICLE_OT_select_random); WM_operatortype_append(PARTICLE_OT_select_linked); WM_operatortype_append(PARTICLE_OT_select_less); WM_operatortype_append(PARTICLE_OT_select_more); |