[Bf-blender-cvs] [f5076d5] master: 'Transform' Python Function for armature, curve and lattice.

Campbell Barton noreply at git.blender.org
Tue Dec 17 13:05:04 CET 2013


Commit: f5076d54cb3a95ab583cddb7de07ed746d2e2be6
Author: Campbell Barton
Date:   Tue Dec 17 22:13:15 2013 +1100
http://developer.blender.org/rBf5076d54cb3a95ab583cddb7de07ed746d2e2be6

'Transform' Python Function for armature, curve and lattice.

patch by Paolo Acampora with some edits.

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

M	source/blender/collada/ArmatureImporter.cpp
M	source/blender/editors/armature/armature_edit.c
M	source/blender/editors/armature/armature_relations.c
M	source/blender/editors/armature/armature_utils.c
M	source/blender/editors/armature/editarmature_retarget.c
M	source/blender/editors/armature/pose_transform.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/include/ED_armature.h
M	source/blender/editors/include/ED_curve.h
M	source/blender/editors/include/ED_lattice.h
M	source/blender/editors/include/ED_mball.h
M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/editors/metaball/mball_edit.c
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/object/object_lattice.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/object/object_transform.c
M	source/blender/editors/util/ed_util.c
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_armature.c
M	source/blender/makesrna/intern/rna_curve.c
A	source/blender/makesrna/intern/rna_curve_api.c
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_lattice.c
A	source/blender/makesrna/intern/rna_lattice_api.c
M	source/blender/makesrna/intern/rna_mesh_api.c
M	source/blender/makesrna/intern/rna_meta_api.c
M	source/blenderplayer/bad_level_call_stubs/stubs.c

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

diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp
index 74db208..ddc05b5 100644
--- a/source/blender/collada/ArmatureImporter.cpp
+++ b/source/blender/collada/ArmatureImporter.cpp
@@ -341,7 +341,7 @@ void ArmatureImporter::create_armature_bones( )
 		if (!ob_arm)
 			continue;
 
-		ED_armature_to_edit(ob_arm);
+		ED_armature_to_edit(ob_arm->data);
 
 		/*
 		 * TODO:
@@ -356,12 +356,12 @@ void ArmatureImporter::create_armature_bones( )
 		// exit armature edit mode
 		unskinned_armature_map[(*ri)->getUniqueId()] = ob_arm;
 
-		ED_armature_from_edit(ob_arm);
+		ED_armature_from_edit(ob_arm->data);
 
 		//This serves no purpose, as pose is automatically reset later, in BKE_where_is_bone()
 		//set_pose(ob_arm, *ri, NULL, NULL);
 
-		ED_armature_edit_free(ob_arm);
+		ED_armature_edit_free(ob_arm->data);
 		DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
 	}
 }
@@ -454,7 +454,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
 	}
 
 	// enter armature edit mode
-	ED_armature_to_edit(ob_arm);
+	ED_armature_to_edit(ob_arm->data);
 
 	leaf_bones.clear();
 	totbone = 0;
@@ -485,8 +485,8 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
 	fix_leaf_bones();
 
 	// exit armature edit mode
-	ED_armature_from_edit(ob_arm);
-	ED_armature_edit_free(ob_arm);
+	ED_armature_from_edit(ob_arm->data);
+	ED_armature_edit_free(ob_arm->data);
 	DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
 
 }
diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c
index c284769..9bc94e0 100644
--- a/source/blender/editors/armature/armature_edit.c
+++ b/source/blender/editors/armature/armature_edit.c
@@ -65,17 +65,27 @@
 
 void ED_armature_apply_transform(Object *ob, float mat[4][4])
 {
-	EditBone *ebone;
 	bArmature *arm = ob->data;
+
+	/* Put the armature into editmode */
+	ED_armature_to_edit(arm);
+
+	/* Transform the bones*/
+	ED_armature_transform_bones(arm, mat);
+
+	/* Turn the list into an armature */
+	ED_armature_from_edit(arm);
+	ED_armature_edit_free(arm);
+}
+
+void ED_armature_transform_bones(struct bArmature *arm, float mat[4][4])
+{
+	EditBone *ebone;
 	float scale = mat4_to_scale(mat);   /* store the scale of the matrix here to use on envelopes */
 	float mat3[3][3];
-	
+
 	copy_m3_m4(mat3, mat);
 	normalize_m3(mat3);
-	
-	/* Put the armature into editmode */
-	ED_armature_to_edit(ob);
-	
 	/* Do the rotations */
 	for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
 		float tmat[3][3];
@@ -89,7 +99,7 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4])
 		/* transform the bone */
 		mul_m4_v3(mat, ebone->head);
 		mul_m4_v3(mat, ebone->tail);
-		
+
 		/* apply the transfiormed roll back */
 		mat3_to_vec_roll(tmat, NULL, &ebone->roll);
 		
@@ -101,10 +111,24 @@ void ED_armature_apply_transform(Object *ob, float mat[4][4])
 		ebone->xwidth   *= scale;
 		ebone->zwidth   *= scale;
 	}
-	
-	/* Turn the list into an armature */
-	ED_armature_from_edit(ob);
-	ED_armature_edit_free(ob);
+}
+
+void ED_armature_transform(struct bArmature *arm, float mat[4][4])
+{
+	if (arm->edbo) {
+		ED_armature_transform_bones(arm, mat);
+	}
+	else {
+		/* Put the armature into editmode */
+		ED_armature_to_edit(arm);
+
+		/* Transform the bones */
+		ED_armature_transform_bones(arm, mat);
+
+		/* Go back to object mode*/
+		ED_armature_from_edit(arm);
+		ED_armature_edit_free(arm);
+	}
 }
 
 /* exported for use in editors/object/ */
@@ -118,7 +142,7 @@ void ED_armature_origin_set(Scene *scene, Object *ob, float cursor[3], int cente
 
 	/* Put the armature into editmode */
 	if (ob != obedit) {
-		ED_armature_to_edit(ob);
+		ED_armature_to_edit(arm);
 		obedit = NULL; /* we cant use this so behave as if there is no obedit */
 	}
 
@@ -160,8 +184,8 @@ void ED_armature_origin_set(Scene *scene, Object *ob, float cursor[3], int cente
 	
 	/* Turn the list into an armature */
 	if (obedit == NULL) {
-		ED_armature_from_edit(ob);
-		ED_armature_edit_free(ob);
+		ED_armature_from_edit(arm);
+		ED_armature_edit_free(arm);
 	}
 
 	/* Adjust object location for new centerpoint */
diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c
index 087e9a8..7a5d43a 100644
--- a/source/blender/editors/armature/armature_relations.c
+++ b/source/blender/editors/armature/armature_relations.c
@@ -204,7 +204,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
 	}
 
 	/* Get editbones of active armature to add editbones to */
-	ED_armature_to_edit(ob);
+	ED_armature_to_edit(arm);
 	
 	/* get pose of active object and move it out of posemode */
 	pose = ob->pose;
@@ -216,7 +216,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
 			bArmature *curarm = base->object->data;
 			
 			/* Make a list of editbones in current armature */
-			ED_armature_to_edit(base->object);
+			ED_armature_to_edit(base->object->data);
 			
 			/* Get Pose of current armature */
 			opose = base->object->pose;
@@ -286,8 +286,8 @@ int join_armature_exec(bContext *C, wmOperator *op)
 	
 	DAG_relations_tag_update(bmain);  /* because we removed object(s) */
 
-	ED_armature_from_edit(ob);
-	ED_armature_edit_free(ob);
+	ED_armature_from_edit(arm);
+	ED_armature_edit_free(arm);
 
 	WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
 	
@@ -409,7 +409,7 @@ static void separate_armature_bones(Object *ob, short sel)
 	EditBone *curbone;
 	
 	/* make local set of editbones to manipulate here */
-	ED_armature_to_edit(ob);
+	ED_armature_to_edit(arm);
 	
 	/* go through pose-channels, checking if a bone should be removed */
 	for (pchan = ob->pose->chanbase.first; pchan; pchan = pchann) {
@@ -449,8 +449,8 @@ static void separate_armature_bones(Object *ob, short sel)
 	}
 	
 	/* exit editmode (recalculates pchans too) */
-	ED_armature_from_edit(ob);
-	ED_armature_edit_free(ob);
+	ED_armature_from_edit(ob->data);
+	ED_armature_edit_free(ob->data);
 }
 
 /* separate selected bones into their armature */
@@ -492,8 +492,8 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
 	oldob->mode &= ~OB_MODE_POSE;
 	//oldbase->flag &= ~OB_POSEMODE;
 	
-	ED_armature_from_edit(obedit);
-	ED_armature_edit_free(obedit);
+	ED_armature_from_edit(obedit->data);
+	ED_armature_edit_free(obedit->data);
 	
 	/* 2) duplicate base */
 	newbase = ED_object_add_duplicate(bmain, scene, oldbase, USER_DUP_ARM); /* only duplicate linked armature */
@@ -518,7 +518,7 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
 	/* 5) restore original conditions */
 	obedit = oldob;
 	
-	ED_armature_to_edit(obedit);
+	ED_armature_to_edit(obedit->data);
 	
 	BKE_report(op->reports, RPT_INFO, "Separated bones");
 
diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c
index 7d6b371..7c70276 100644
--- a/source/blender/editors/armature/armature_utils.c
+++ b/source/blender/editors/armature/armature_utils.c
@@ -492,9 +492,8 @@ static void fix_bonelist_roll(ListBase *bonelist, ListBase *editbonelist)
 }
 
 /* put EditMode back in Object */
-void ED_armature_from_edit(Object *obedit)
+void ED_armature_from_edit(bArmature *arm)
 {
-	bArmature *arm = obedit->data;
 	EditBone *eBone, *neBone;
 	Bone *newBone;
 	Object *obt;
@@ -601,12 +600,11 @@ void ED_armature_from_edit(Object *obedit)
 			BKE_pose_rebuild(obt, arm);
 	}
 	
-	DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+	DAG_id_tag_update(&arm->id, 0);
 }
 
-void ED_armature_edit_free(struct Object *ob)
+void ED_armature_edit_free(struct bArmature *arm)
 {
-	bArmature *arm = ob->data;
 	EditBone *eBone;
 	
 	/*	Clear the editbones list */
@@ -628,11 +626,9 @@ void ED_armature_edit_free(struct Object *ob)
 }
 
 /* Put armature in EditMode */
-void ED_armature_to_edit(Object *ob)
+void ED_armature_to_edit(bArmature *arm)
 {
-	bArmature *arm = ob->data;
-	
-	ED_armature_edit_free(ob);
+	ED_armature_edit_free(arm);
 	arm->edbo = MEM_callocN(sizeof(ListBase), "edbo armature");
 	arm->act_edbone = make_boneList(arm->edbo, &arm->bonebase, NULL, arm->act_bone);
 
diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c
index 2c00c5e..4ea564b 100644
--- a/source/blender/editors/armature/editarmature_retarget.c
+++ b/source/blender/editors/armature/editarmature_retarget.c
@@ -2416,7 +2416,7 @@ static void adjustGraphs(bContext *C, RigGraph *rigg)
 
 	/* Turn the list into an armature */
 	arm->edbo = rigg->editbones;
-	ED_armature_from_edit(rigg->ob);
+	ED_armature_from_edit(arm);
 	
 	ED_undo_push(C, "Retarget Skeleton");
 }
@@ -2443,7 +2443,7 @@ static void retargetGraphs(bContext *C, RigGraph *rigg)
 
 	/* Turn the list into an armature */
 	arm->edbo = rigg->editbones;
-	ED_armature_from_edit(rigg->ob);
+	ED_armature_from_edit(arm);
 }
 
 const char *RIG_nameBone(RigGraph *rg, int arc_index, int bone_index)
diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c
index 578f048..993b0cc 100644
--- a/source/blender/editors/armature/pose_transform.c
+++ b/source/blender/editors/armature/pose_transform.c
@@ -112,7 +112,7 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op)
 		           "transforms stored are relative to the old rest pose");
 
 	/* Get editbones of active armature to alter */
-	ED_armature_to_edit(ob);
+	ED_armature_to_edit(arm);
 	
 	/* get pose of active object and move it out of posemode */
 	pose = ob->pose;
@@ -160,8 +160,8 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op)
 	}
 	
 	/* convert editbones back to bones, and then free the edit-data */
-	ED_armature_from_edit(ob);
-	ED_armature_edit_free(ob);
+	ED_armature_from_edit(arm);
+	ED_armature_edit_free(arm);
 	
 	/* flush positions of posebones */
 	BKE_pose_where_is(scene, ob);
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index e6ea74b..bc97515 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -1370,6 +1370,37 @@ void CU_select_swap(Object *obedit)
 	}
 }
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list