[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18826] branches/blender2.5/blender/source /blender/editors: 2.5 - Armatures Code

Joshua Leung aligorith at gmail.com
Fri Feb 6 11:48:13 CET 2009


Revision: 18826
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18826
Author:   aligorith
Date:     2009-02-06 11:48:00 +0100 (Fri, 06 Feb 2009)

Log Message:
-----------
2.5 - Armatures Code

* Brought back recalculate bone roll (Ctrl N). This should be quite a straightforward example of a cleaned-up + ported armature tool. 

* Cleaned up a few warnings 

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/armature/armature_intern.h
    branches/blender2.5/blender/source/blender/editors/armature/armature_ops.c
    branches/blender2.5/blender/source/blender/editors/armature/editarmature.c
    branches/blender2.5/blender/source/blender/editors/armature/poseobject.c
    branches/blender2.5/blender/source/blender/editors/include/ED_armature.h
    branches/blender2.5/blender/source/blender/editors/space_view3d/space_view3d.c

Modified: branches/blender2.5/blender/source/blender/editors/armature/armature_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/armature_intern.h	2009-02-06 10:04:44 UTC (rev 18825)
+++ branches/blender2.5/blender/source/blender/editors/armature/armature_intern.h	2009-02-06 10:48:00 UTC (rev 18826)
@@ -33,9 +33,9 @@
 
 /* editarmature.c */
 void armature_bone_rename(Object *ob, char *oldnamep, char *newnamep);
-EditBone *armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo); // XXX this is needed for populating the context iterators
 
 void ARMATURE_OT_align_bones(struct wmOperatorType *ot);
+void ARMATURE_OT_calculate_roll(struct wmOperatorType *ot);
 
 void POSE_OT_hide(struct wmOperatorType *ot);
 void POSE_OT_reveil(struct wmOperatorType *ot);

Modified: branches/blender2.5/blender/source/blender/editors/armature/armature_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/armature_ops.c	2009-02-06 10:04:44 UTC (rev 18825)
+++ branches/blender2.5/blender/source/blender/editors/armature/armature_ops.c	2009-02-06 10:48:00 UTC (rev 18826)
@@ -85,7 +85,7 @@
 	printf("\tActive Bone \n");
 	{
 		EditBone *ebone= CTX_data_active_bone(C);
-		if (ebone) printf("\t\tEditBone '%s' \n");
+		if (ebone) printf("\t\tEditBone '%s' \n", ebone->name);
 		else printf("\t\t<None> \n");
 	}
 	
@@ -108,6 +108,7 @@
 void ED_operatortypes_armature(void)
 {
 	WM_operatortype_append(ARMATURE_OT_align_bones);
+	WM_operatortype_append(ARMATURE_OT_calculate_roll);
 	
 	WM_operatortype_append(POSE_OT_hide);
 	WM_operatortype_append(POSE_OT_reveil);
@@ -129,6 +130,8 @@
 	/* only set in editmode armature, by space_view3d listener */
 //	WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, 0, 0);
 	WM_keymap_add_item(keymap, "ARMATURE_OT_align_bones", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
+	WM_keymap_add_item(keymap, "ARMATURE_OT_calculate_roll", NKEY, KM_PRESS, KM_CTRL, 0);
+	
 	WM_keymap_add_item(keymap, "ARMATURE_OT_test", TKEY, KM_PRESS, 0, 0);  // XXX temp test for context iterators... to be removed
 	
 	/* Pose ------------------------ */

Modified: branches/blender2.5/blender/source/blender/editors/armature/editarmature.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/editarmature.c	2009-02-06 10:04:44 UTC (rev 18825)
+++ branches/blender2.5/blender/source/blender/editors/armature/editarmature.c	2009-02-06 10:48:00 UTC (rev 18826)
@@ -1556,7 +1556,7 @@
 }
 
 /* context: editmode armature */
-EditBone *armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo)
+EditBone *ED_armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo)
 {
 	EditBone *eboflip= NULL;
 	char name[32];
@@ -1592,7 +1592,7 @@
 		for (curBone=arm->edbo->first; curBone; curBone=curBone->next) {
 			if (arm->layer & curBone->layer) {
 				if (curBone->flag & BONE_SELECTED) {
-					next = armature_bone_get_mirrored(arm->edbo, curBone);
+					next = ED_armature_bone_get_mirrored(arm->edbo, curBone);
 					if (next)
 						next->flag |= BONE_SELECTED;
 				}
@@ -1656,10 +1656,10 @@
 }
 
 /* toggle==0: deselect
-toggle==1: swap (based on test)
-toggle==2: only active tag
-toggle==3: swap (no test)
-*/
+ * toggle==1: swap (based on test)
+ * toggle==2: only active tag
+ * toggle==3: swap (no test)
+ */
 void deselectall_armature(Object *obedit, int toggle, int doundo)
 {
 	bArmature *arm= obedit->data;
@@ -1916,20 +1916,22 @@
 	}
 }
 
-/* Sets the roll value of selected bones, depending on the mode
- * 	mode == 0: their z-axes point upwards 
- * 	mode == 1: their z-axes point towards 3d-cursor
- */
-void auto_align_armature(Scene *scene, View3D *v3d, short mode)
+
+static EnumPropertyItem prop_calc_roll_types[] = {
+	{0, "GLOBALUP", "Z-Axis Up", ""},
+	{1, "CURSOR", "Z-Axis to Cursor", ""},
+	{0, NULL, NULL, NULL}
+};
+
+static int armature_calc_roll_exec(bContext *C, wmOperator *op) 
 {
-	Object *obedit= scene->obedit;
-	bArmature *arm= obedit->data;
-	EditBone *ebone;
-	EditBone *flipbone = NULL;
+	Scene *scene= CTX_data_scene(C);
+	View3D *v3d= (View3D *)CTX_wm_space_data(C);
+	Object *ob= CTX_data_edit_object(C);
 	void (*roll_func)(Scene *, View3D *, EditBone *) = NULL;
 	
 	/* specific method used to calculate roll depends on mode */
-	switch (mode) {
+	switch (RNA_enum_get(op->ptr, "type")) {
 		case 1:  /* Z-Axis point towards cursor */
 			roll_func= auto_align_ebone_tocursor;
 			break;
@@ -1938,21 +1940,38 @@
 			break;
 	}
 	
-	for (ebone = arm->edbo->first; ebone; ebone=ebone->next) {
-		if (EBONE_VISIBLE(arm, ebone)) {
-			if (arm->flag & ARM_MIRROR_EDIT)
-				flipbone = armature_bone_get_mirrored(arm->edbo, ebone);
-			
-			if ((ebone->flag & BONE_SELECTED) || 
-				(flipbone && (flipbone->flag & BONE_SELECTED))) 
-			{
-				/* roll func is a callback which assumes that all is well */
-				roll_func(scene, v3d, ebone);			
-			}
-		}
+	/* recalculate roll on selected bones */
+	CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) {
+		/* roll func is a callback which assumes that all is well */
+		roll_func(scene, v3d, ebone);
 	}
+	CTX_DATA_END;
+	
+
+	/* note, notifier might evolve */
+	WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
+	
+	return OPERATOR_FINISHED;
 }
 
+void ARMATURE_OT_calculate_roll(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Align Bones";
+	ot->idname= "ARMATURE_OT_calculate_roll";
+	
+	/* api callbacks */
+	ot->invoke = WM_menu_invoke;
+	ot->exec = armature_calc_roll_exec;
+	ot->poll = ED_operator_editarmature;
+	
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+	
+	/* properties */
+	RNA_def_enum(ot->srna, "type", prop_calc_roll_types, 0, "Type", "");
+}
+
 /* **************** undo for armatures ************** */
 
 static void undoBones_to_editBones(void *lbuv, void *lbev)
@@ -2168,7 +2187,7 @@
 	/* we re-use code for mirror editing... */
 	flipbone= NULL;
 	if (arm->flag & ARM_MIRROR_EDIT)
-		flipbone= armature_bone_get_mirrored(arm->edbo, ebone);
+		flipbone= ED_armature_bone_get_mirrored(arm->edbo, ebone);
 
 	for (a=0; a<2; a++) {
 		if (a==1) {
@@ -2309,7 +2328,7 @@
 		for (curBone=arm->edbo->first; curBone; curBone=curBone->next) {
 			if (EBONE_VISIBLE(arm, curBone)) {
 				if (curBone->flag & BONE_SELECTED) {
-					eBone = armature_bone_get_mirrored(arm->edbo, curBone);
+					eBone = ED_armature_bone_get_mirrored(arm->edbo, curBone);
 					if (eBone)
 						eBone->flag |= BONE_SELECTED;
 				}
@@ -2989,7 +3008,7 @@
 		bone_connect_to_existing_parent(actbone);
 		
 		if (arm->flag & ARM_MIRROR_EDIT) {
-			flipbone = armature_bone_get_mirrored(arm->edbo, actbone);
+			flipbone = ED_armature_bone_get_mirrored(arm->edbo, actbone);
 			if (flipbone)
 				bone_connect_to_existing_parent(flipbone);
 		}
@@ -3009,8 +3028,8 @@
 						 * - if there's no mirrored copy of actbone (i.e. actbone = "parent.C" or "parent")
 						 *	then just use actbone. Useful when doing upper arm to spine.
 						 */
-						flipbone = armature_bone_get_mirrored(arm->edbo, selbone);
-						flippar = armature_bone_get_mirrored(arm->edbo, actbone);
+						flipbone = ED_armature_bone_get_mirrored(arm->edbo, selbone);
+						flippar = ED_armature_bone_get_mirrored(arm->edbo, actbone);
 						
 						if (flipbone) {
 							if (flippar)
@@ -3056,7 +3075,7 @@
 		if (EBONE_VISIBLE(arm, ebone)) {
 			if (ebone->flag & BONE_SELECTED) {
 				if (arm->flag & ARM_MIRROR_EDIT)
-					flipbone = armature_bone_get_mirrored(arm->edbo, ebone);
+					flipbone = ED_armature_bone_get_mirrored(arm->edbo, ebone);
 					
 				if (flipbone)
 					editbone_clear_parent(flipbone, val);
@@ -3108,7 +3127,7 @@
 				/* we re-use code for mirror editing... */
 				flipbone= NULL;
 				if (arm->flag & ARM_MIRROR_EDIT) {
-					flipbone= armature_bone_get_mirrored(arm->edbo, ebone);
+					flipbone= ED_armature_bone_get_mirrored(arm->edbo, ebone);
 					if (flipbone) {
 						forked= 0;	// we extrude 2 different bones
 						if (flipbone->flag & (BONE_TIPSEL|BONE_ROOTSEL|BONE_SELECTED))
@@ -3226,7 +3245,7 @@
 						/* try to find mirrored bone on a != 0 */
 						if (a) {
 							if (arm->flag & ARM_MIRROR_EDIT)
-								ebone= armature_bone_get_mirrored(arm->edbo, mbone);
+								ebone= ED_armature_bone_get_mirrored(arm->edbo, mbone);
 							else 
 								ebone= NULL;
 						}
@@ -3421,7 +3440,7 @@
 		 * - if there's no mirrored copy of actbone (i.e. actbone = "parent.C" or "parent")
 		 *	then just use actbone. Useful when doing upper arm to spine.
 		 */
-		actmirb= armature_bone_get_mirrored(arm->edbo, actbone);
+		actmirb= ED_armature_bone_get_mirrored(arm->edbo, actbone);
 		if (actmirb == NULL) 
 			actmirb= actbone;
 	}
@@ -4524,7 +4543,7 @@
 	for (ebo= arm->edbo->first; ebo; ebo=ebo->next) {
 		/* no layer check, correct mirror is more important */
 		if (ebo->flag & (BONE_TIPSEL|BONE_ROOTSEL)) {
-			eboflip= armature_bone_get_mirrored(arm->edbo, ebo);
+			eboflip= ED_armature_bone_get_mirrored(arm->edbo, ebo);
 			
 			if (eboflip) {
 				/* we assume X-axis flipping for now */

Modified: branches/blender2.5/blender/source/blender/editors/armature/poseobject.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/armature/poseobject.c	2009-02-06 10:04:44 UTC (rev 18825)
+++ branches/blender2.5/blender/source/blender/editors/armature/poseobject.c	2009-02-06 10:48:00 UTC (rev 18826)
@@ -1385,7 +1385,7 @@
 				if (ebo->flag & BONE_SELECTED) {
 					ebo->layer= lay;
 					if (arm->flag & ARM_MIRROR_EDIT) {
-						flipBone = armature_bone_get_mirrored(arm->edbo, ebo);
+						flipBone = ED_armature_bone_get_mirrored(arm->edbo, ebo);
 						if (flipBone)
 							flipBone->layer = lay;
 					}

Modified: branches/blender2.5/blender/source/blender/editors/include/ED_armature.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/ED_armature.h	2009-02-06 10:04:44 UTC (rev 18825)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_armature.h	2009-02-06 10:48:00 UTC (rev 18826)
@@ -100,6 +100,7 @@
 void mouse_armature(struct bContext *C, short mval[2], int extend);
 struct Bone *get_indexed_bone (struct Object *ob, int index);
 float ED_rollBoneToVector(EditBone *bone, float new_up_axis[3]);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list