[Bf-blender-cvs] [9c97624] master: Select Random in Particle Edit Mode, by jezv

Lukas Tönne noreply at git.blender.org
Wed Oct 8 18:10:36 CEST 2014


Commit: 9c97624fc966000008e940eaffe279afb2e28b07
Author: Lukas Tönne
Date:   Wed Oct 8 18:09:32 2014 +0200
Branches: master
https://developer.blender.org/rB9c97624fc966000008e940eaffe279afb2e28b07

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

===================================================================

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/physics/physics_intern.h
M	source/blender/editors/physics/physics_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 2249d2b..cbae63e 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 76344b7..9a3433b 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 77ce5a3..b8955c8 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 48cc51f..ff89909 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);




More information about the Bf-blender-cvs mailing list