2.5 - Armatures Code
authorJoshua Leung <aligorith@gmail.com>
Fri, 6 Feb 2009 10:48:00 +0000 (10:48 +0000)
committerJoshua Leung <aligorith@gmail.com>
Fri, 6 Feb 2009 10:48:00 +0000 (10:48 +0000)
* 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

source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/armature_ops.c
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/poseobject.c
source/blender/editors/include/ED_armature.h
source/blender/editors/space_view3d/space_view3d.c

index a9d4b9396578e6620007a571d030bb5db9e822a5..fd91b70dcdd0c0d2cebb5e928e7255767e438af5 100644 (file)
@@ -33,9 +33,9 @@ struct wmOperatorType;
 
 /* 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);
index 69efc8cb4a41a84af962ffd7a72b022071137687..6736561e36c7fd7537871476837dc90c735e823e 100644 (file)
@@ -85,7 +85,7 @@ static int armature_test_exec (bContext *C, wmOperator *op)
        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 ARMATURE_OT_test(wmOperatorType *ot)
 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 @@ void ED_keymap_armature(wmWindowManager *wm)
        /* 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 ------------------------ */
index 1d9aeb9d30828e74d4053c3d2dcd5dda14980257..1d3d1f9b567a5ba310320441aae2250d71680885 100644 (file)
@@ -1556,7 +1556,7 @@ static void delete_bone(ListBase *edbo, EditBone* exBone)
 }
 
 /* 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 @@ void delete_armature(Scene *scene)
                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 @@ void delete_armature(Scene *scene)
 }
 
 /* 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 @@ void auto_align_ebone_tocursor(Scene *scene, View3D *v3d, EditBone *ebone)
        }
 }
 
-/* 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,19 +1940,36 @@ void auto_align_armature(Scene *scene, View3D *v3d, short mode)
                        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= "Recalculate Roll";
+       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 ************** */
@@ -2046,14 +2065,14 @@ static EditBone *add_editbone(Object *obedit, char *name)
        BLI_addtail(arm->edbo, bone);
        
        bone->flag |= BONE_TIPSEL;
-       bone->weight= 1.0F;
-       bone->dist= 0.25F;
-       bone->xwidth= 0.1;
-       bone->zwidth= 0.1;
-       bone->ease1= 1.0;
-       bone->ease2= 1.0;
-       bone->rad_head= 0.10;
-       bone->rad_tail= 0.05;
+       bone->weight= 1.0f;
+       bone->dist= 0.25f;
+       bone->xwidth= 0.1f;
+       bone->zwidth= 0.1f;
+       bone->ease1= 1.0f;
+       bone->ease2= 1.0f;
+       bone->rad_head= 0.10f;
+       bone->rad_tail= 0.05f;
        bone->segments= 1;
        bone->layer= arm->layer;
        
@@ -2168,7 +2187,7 @@ void addvert_armature(Scene *scene, View3D *v3d)
        /* 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 @@ void adduplicate_armature(Scene *scene)
                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 @@ void make_bone_parent(Scene *scene)
                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 @@ void make_bone_parent(Scene *scene)
                                                 * - 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 @@ void clear_bone_parent(Scene *scene)
                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 @@ void extrude_armature(Scene *scene, int forked)
                                /* 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 @@ void subdivide_armature(Scene *scene, int numcuts)
                                                /* 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 @@ static int armature_align_bones_exec(bContext *C, wmOperator *op)
                 * - 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 @@ void transform_armature_mirror_update(Object *obedit)
        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 */
index 0771806a4a2ccdaa652f3689695ba102b84de4ec..ea0b492486e182857ba07abcf24b675ad1e27f59 100644 (file)
@@ -1385,7 +1385,7 @@ void pose_movetolayer(Scene *scene)
                                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;
                                        }
index 4d22f30c44cac5c6b3c28c7bcd3725ae53de5c4f..9c17e002cb029f8d5d6333298ac4161cd2de1b1d 100644 (file)
@@ -100,6 +100,7 @@ int ED_do_pose_selectbuffer(struct Scene *scene, struct Base *base, unsigned int
 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]);
+EditBone *ED_armature_bone_get_mirrored(struct ListBase *edbo, EditBone *ebo); // XXX this is needed for populating the context iterators
 
 void transform_armature_mirror_update(struct Object *obedit);
 void clear_armature(struct Scene *scene, struct Object *ob, char mode);
index 1bc770ea8a6b5b4f3d9090eb99061686921c2b16..a87506fc5eb6114e8ac979105836c92bee0b2560 100644 (file)
@@ -43,6 +43,7 @@
 #include "BLI_arithb.h"
 #include "BLI_rand.h"
 
+#include "BKE_action.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
@@ -478,7 +479,7 @@ static int view3d_context(const bContext *C, bContextDataMember member, bContext
                                         * bones will be operated on twice.
                                         */
                                        if (arm->flag & ARM_MIRROR_EDIT)
-                                               flipbone = armature_bone_get_mirrored(arm->edbo, ebone);
+                                               flipbone = ED_armature_bone_get_mirrored(arm->edbo, ebone);
                                        
                                        /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
                                        if (member == CTX_DATA_SELECTED_EDITABLE_BONES) {