[Bf-blender-cvs] [72794d9] gooseberry: ShapeKey propagate operator for hair edit mode.

Lukas Tönne noreply at git.blender.org
Mon Apr 20 20:23:58 CEST 2015


Commit: 72794d9e01a1fba6deee0d4af5586f596db162dd
Author: Lukas Tönne
Date:   Mon Apr 20 20:21:02 2015 +0200
Branches: gooseberry
https://developer.blender.org/rB72794d9e01a1fba6deee0d4af5586f596db162dd

ShapeKey propagate operator for hair edit mode.

This implements roughly the same functionality as the equivalent mesh
shape propagate operator, with some tweaks specific to hair editing.

The operator copies selected points to all the shape keys. Unlike meshes
these points may be shifted afterward to achieve consistent segment
length (this can be avoided by selected entire strands before using the
operator).

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

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 95bcf7b..7f3f48b 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1802,6 +1802,9 @@ class VIEW3D_MT_particle_specials(Menu):
         layout.separator()
 
         layout.operator("particle.mirror")
+        layout.separator()
+        
+        layout.operator("particle.shape_propagate_to_all")
 
         if particle_edit.select_mode == 'POINT':
             layout.separator()
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index ab50313..51a68eb 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -4843,3 +4843,89 @@ void PARTICLE_OT_edited_clear(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/************************ Propagate Shape Key *************************/
+
+static int PE_count_keys(PTCacheEdit *edit)
+{
+	int totkey = 0, p;
+	for (p = 0; p < edit->totpoint; ++p) {
+		totkey += edit->points[p].totkey;
+	}
+	return totkey;
+}
+
+static void shape_propagate(PTCacheEdit *edit, int totkey, KeyBlock *kb, wmOperator *UNUSED(op))
+{
+	PTCacheEditPoint *point;
+	float *fp;
+	int i, k;
+	
+	if (kb->totelem != totkey)
+		return;
+	
+	fp = kb->data;
+	point = edit->points;
+	for (i = 0; i < edit->totpoint; ++i, ++point) {
+		PTCacheEditKey *key = point->keys;
+		const bool use_point = !(point->flag & PEP_HIDE);
+		
+		for (k = 0; k < point->totkey; ++k, ++key) {
+			const bool use_key = (key->flag & PEK_SELECT) && !(key->flag & PEK_HIDE);
+			
+			if (use_point && use_key) {
+				copy_v3_v3(fp, key->co);
+				
+				point->flag |= PEP_EDIT_RECALC;
+			}
+			
+			fp += 3;
+		}
+	}
+}
+
+static int particle_shape_propagate_to_all_exec(bContext *C, wmOperator *op)
+{
+	Scene *scene = CTX_data_scene(C);
+	ParticleEditSettings *pset = PE_settings(scene);
+	Object *ob = ED_object_context(C);
+	ParticleSystem *psys = psys_get_current(ob);
+	PTCacheEdit *edit = psys->edit;
+	Key *key = psys->key;
+	KeyBlock *kb;
+	const int totkey = PE_count_keys(edit);
+
+	if (!key)
+		return OPERATOR_CANCELLED;
+
+	/* we might need world space coordinates, update to be sure */
+	update_world_cos(ob, edit);
+
+	for (kb = key->block.first; kb; kb = kb->next)
+		shape_propagate(edit, totkey, kb, op);
+	
+	update_world_cos(ob, edit);
+	PE_update_object(scene, ob, 1);
+	
+	if (!(pset->flag & PE_KEEP_LENGTHS))
+		recalc_lengths(edit);
+
+	WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
+
+	return OPERATOR_FINISHED;
+}
+
+
+void PARTICLE_OT_shape_propagate_to_all(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Shape Propagate";
+	ot->description = "Apply selected vertex locations to all other shape keys";
+	ot->idname = "PARTICLE_OT_shape_propagate_to_all";
+
+	/* api callbacks */
+	ot->exec = particle_shape_propagate_to_all_exec;
+	ot->poll = PE_hair_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h
index 0d3a86a..1d68a42 100644
--- a/source/blender/editors/physics/physics_intern.h
+++ b/source/blender/editors/physics/physics_intern.h
@@ -61,6 +61,8 @@ void PARTICLE_OT_shape_cut(struct wmOperatorType *ot);
 void PARTICLE_OT_particle_edit_toggle(struct wmOperatorType *ot);
 void PARTICLE_OT_edited_clear(struct wmOperatorType *ot);
 
+void PARTICLE_OT_shape_propagate_to_all(struct wmOperatorType *ot);
+
 /* particle_object.c */
 void OBJECT_OT_particle_system_add(struct wmOperatorType *ot);
 void OBJECT_OT_particle_system_remove(struct wmOperatorType *ot);
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index ef27817..4d78e74 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -69,6 +69,8 @@ static void operatortypes_particle(void)
 	WM_operatortype_append(PARTICLE_OT_particle_edit_toggle);
 	WM_operatortype_append(PARTICLE_OT_edited_clear);
 
+	WM_operatortype_append(PARTICLE_OT_shape_propagate_to_all);
+
 
 	WM_operatortype_append(OBJECT_OT_particle_system_add);
 	WM_operatortype_append(OBJECT_OT_particle_system_remove);




More information about the Bf-blender-cvs mailing list