2.5
authorMichael Fox <mfoxdogg@gmail.com>
Thu, 5 Feb 2009 05:13:08 +0000 (05:13 +0000)
committerMichael Fox <mfoxdogg@gmail.com>
Thu, 5 Feb 2009 05:13:08 +0000 (05:13 +0000)
*******
-ported clear loc,rot,scale operators to pose mode operators
- for some reason when animated and you clear anything, the whole aramture clears. somthing to do with the depsgraph stuff that was directly ported  from clear armature()

source/blender/blenkernel/BKE_context.h
source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/armature_ops.c
source/blender/editors/armature/editarmature.c
source/blender/editors/object/object_edit.c

index 5af97a7d8d5e9aff4f984951c3f95ee3a7097498..e9544cf4a6f59ec1bcd0c059f24a6e7fe10702d4 100644 (file)
@@ -40,6 +40,8 @@ struct EditMesh;
 struct ListBase;
 struct Main;
 struct Object;
+struct Bone;
+struct bArmature;
 struct PointerRNA;
 struct ReportList;
 struct Scene;
index 7673acabe3aeda1ea5903ce1fb44f57ff10062a2..2ee48e150061b405c199d909d005a3cbba484dfd 100644 (file)
@@ -37,7 +37,9 @@ EditBone *armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo);
 
 void POSE_OT_hide(struct wmOperatorType *ot);
 void POSE_OT_reveil(struct wmOperatorType *ot);
-
+void POSE_OT_rot_clear(struct wmOperatorType *ot);
+void POSE_OT_loc_clear(struct wmOperatorType *ot);
+void POSE_OT_scale_clear(struct wmOperatorType *ot);
 
 #endif /* ED_ARMATURE_INTERN_H */
 
index e8f75bd4440448b5488c0a437af497ad12ec7786..c5aeef055d2d4108d866e587f8ce6efb4b809cc8 100644 (file)
@@ -109,6 +109,9 @@ void ED_operatortypes_armature(void)
 {
        WM_operatortype_append(POSE_OT_hide);
        WM_operatortype_append(POSE_OT_reveil);
+       WM_operatortype_append(POSE_OT_rot_clear);
+       WM_operatortype_append(POSE_OT_loc_clear);
+       WM_operatortype_append(POSE_OT_scale_clear);
        
        WM_operatortype_append(ARMATURE_OT_test); // XXX temp test for context iterators... to be removed
 }
@@ -133,6 +136,9 @@ void ED_keymap_armature(wmWindowManager *wm)
        kmi= WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
        RNA_boolean_set(kmi->ptr, "invert", 1);
        WM_keymap_add_item(keymap, "POSE_OT_reveil", HKEY, KM_PRESS, KM_ALT, 0);
-
+       /*clear pose*/
+       WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0);
+       WM_keymap_add_item(keymap, "POSE_OT_loc_clear", GKEY, KM_PRESS, KM_ALT, 0);
+       WM_keymap_add_item(keymap, "POSE_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0);
 }
 
index d083dbec103887c06962754d1d7033062a105a99..803d9c63cf2fb6bdb1f59f97af7dfa6ed20c036f 100644 (file)
@@ -3483,74 +3483,6 @@ void align_selected_bones(Scene *scene)
 
 /* ***************** Pose tools ********************* */
 
-void clear_armature(Scene *scene, Object *ob, char mode)
-{
-       bPoseChannel *pchan;
-       bArmature       *arm= ob->data;
-       
-       /* only clear those channels that are not locked */
-       for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-               if (pchan->bone && (pchan->bone->flag & BONE_SELECTED)) {
-                       if (arm->layer & pchan->bone->layer) {
-                               switch (mode) {
-                                       case 'r':
-                                               if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ)) {
-                                                       float eul[3], oldeul[3], quat1[4];
-                                                       
-                                                       QUATCOPY(quat1, pchan->quat);
-                                                       QuatToEul(pchan->quat, oldeul);
-                                                       eul[0]= eul[1]= eul[2]= 0.0f;
-                                                       
-                                                       if (pchan->protectflag & OB_LOCK_ROTX)
-                                                               eul[0]= oldeul[0];
-                                                       if (pchan->protectflag & OB_LOCK_ROTY)
-                                                               eul[1]= oldeul[1];
-                                                       if (pchan->protectflag & OB_LOCK_ROTZ)
-                                                               eul[2]= oldeul[2];
-                                                       
-                                                       EulToQuat(eul, pchan->quat);
-                                                       /* quaternions flip w sign to accumulate rotations correctly */
-                                                       if ((quat1[0]<0.0f && pchan->quat[0]>0.0f) || (quat1[0]>0.0f && pchan->quat[0]<0.0f)) {
-                                                               QuatMulf(pchan->quat, -1.0f);
-                                                       }
-                                               }                                               
-                                               else { 
-                                                       pchan->quat[1]=pchan->quat[2]=pchan->quat[3]=0.0F; 
-                                                       pchan->quat[0]=1.0F;
-                                               }
-                                               break;
-                                       case 'g':
-                                               if ((pchan->protectflag & OB_LOCK_LOCX)==0)
-                                                       pchan->loc[0]= 0.0f;
-                                               if ((pchan->protectflag & OB_LOCK_LOCY)==0)
-                                                       pchan->loc[1]= 0.0f;
-                                               if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
-                                                       pchan->loc[2]= 0.0f;
-                                               break;
-                                       case 's':
-                                               if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
-                                                       pchan->size[0]= 1.0f;
-                                               if ((pchan->protectflag & OB_LOCK_SCALEY)==0)
-                                                       pchan->size[1]= 1.0f;
-                                               if ((pchan->protectflag & OB_LOCK_SCALEZ)==0)
-                                                       pchan->size[2]= 1.0f;
-                                               break;
-                                               
-                               }
-                               
-                               /* the current values from IPO's may not be zero, so tag as unkeyed */
-                               pchan->bone->flag |= BONE_UNKEYED;
-                       }
-               }
-       }
-       
-       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
-       /* no update for this object, this will execute the action again */
-       /* is weak... like for ipo editing which uses ctime now... */
-       where_is_pose (scene, ob);
-       ob->recalc= 0;
-}
-
 /* helper for function below */
 static int clear_active_flag(Object *ob, Bone *bone, void *data) 
 {
@@ -4079,7 +4011,169 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par)
                break;
        }
 } 
+/* ************* Clear Pose *****************************/
+static int pose_clear_scale_exec(bContext *C, wmOperator *op) 
+{
+       Scene *scene = CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm= ob->data;
+       
+       /* only clear those channels that are not locked */
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
+               if (arm->layer & pchan->bone->layer) {
+                       if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
+                               pchan->size[0]= 1.0f;
+                       if ((pchan->protectflag & OB_LOCK_SCALEY)==0)
+                               pchan->size[1]= 1.0f;
+                       if ((pchan->protectflag & OB_LOCK_SCALEZ)==0)
+                               pchan->size[2]= 1.0f;
+                       /* the current values from IPO's may not be zero, so tag as unkeyed */
+                       pchan->bone->flag |= BONE_UNKEYED;
+               }
+       }
+       CTX_DATA_END;
+               
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+       /* no update for this object, this will execute the action again */
+       /* is weak... like for ipo editing which uses ctime now... */
+       where_is_pose (scene, ob);
+       ob->recalc= 0;
+
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
+       
+       return OPERATOR_FINISHED;
+}
+
+void POSE_OT_scale_clear(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Clear Pose Scale";
+       ot->idname= "POSE_OT_scale_clear";
+       
+       /* api callbacks */
+       ot->invoke = WM_operator_confirm;
+       ot->exec = pose_clear_scale_exec;
+       ot->poll = ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_UNDO;
+}
+
+static int pose_clear_loc_exec(bContext *C, wmOperator *op) 
+{
+       Scene *scene = CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm= ob->data;
+       
+       /* only clear those channels that are not locked */
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
+               if (arm->layer & pchan->bone->layer) {
+                       if ((pchan->protectflag & OB_LOCK_LOCX)==0)
+                               pchan->loc[0]= 0.0f;
+                       if ((pchan->protectflag & OB_LOCK_LOCY)==0)
+                               pchan->loc[1]= 0.0f;
+                       if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
+                               pchan->loc[2]= 0.0f;
+                       /* the current values from IPO's may not be zero, so tag as unkeyed */
+                       pchan->bone->flag |= BONE_UNKEYED;
+               }
+       }
+       CTX_DATA_END;
+               
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+       /* no update for this object, this will execute the action again */
+       /* is weak... like for ipo editing which uses ctime now... */
+       where_is_pose (scene, ob);
+       ob->recalc= 0;
+
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
+       
+       return OPERATOR_FINISHED;
+}
+
+void POSE_OT_loc_clear(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Clear Pose Location";
+       ot->idname= "POSE_OT_loc_clear";
+       
+       /* api callbacks */
+       ot->invoke = WM_operator_confirm;
+       ot->exec = pose_clear_loc_exec;
+       ot->poll = ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_UNDO;
+}
+
+static int pose_clear_rot_exec(bContext *C, wmOperator *op) 
+{
+       Scene *scene = CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm= ob->data;
+       
+       /* only clear those channels that are not locked */
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
+               if (arm->layer & pchan->bone->layer) {
+                       if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ)) {
+                               float eul[3], oldeul[3], quat1[4];
+                                       
+                               QUATCOPY(quat1, pchan->quat);
+                               QuatToEul(pchan->quat, oldeul);
+                               eul[0]= eul[1]= eul[2]= 0.0f;
+                               
+                               if (pchan->protectflag & OB_LOCK_ROTX)
+                                       eul[0]= oldeul[0];
+                               if (pchan->protectflag & OB_LOCK_ROTY)
+                                       eul[1]= oldeul[1];
+                               if (pchan->protectflag & OB_LOCK_ROTZ)
+                                       eul[2]= oldeul[2];
+                                                       
+                               EulToQuat(eul, pchan->quat);
+                               /* quaternions flip w sign to accumulate rotations correctly */
+                               if ((quat1[0]<0.0f && pchan->quat[0]>0.0f) || (quat1[0]>0.0f && pchan->quat[0]<0.0f)) {
+                                       QuatMulf(pchan->quat, -1.0f);
+                               }
+                       }                                               
+                       else { 
+                               pchan->quat[1]=pchan->quat[2]=pchan->quat[3]=0.0F; 
+                               pchan->quat[0]=1.0F;
+                       }
+                       /* the current values from IPO's may not be zero, so tag as unkeyed */
+                       pchan->bone->flag |= BONE_UNKEYED;
+               }
+       }
+       CTX_DATA_END;
+               
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+       /* no update for this object, this will execute the action again */
+       /* is weak... like for ipo editing which uses ctime now... */
+       where_is_pose (scene, ob);
+       ob->recalc= 0;
 
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
+       
+       return OPERATOR_FINISHED;
+}
+
+void POSE_OT_rot_clear(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Clear Pose Rotation";
+       ot->idname= "POSE_OT_rot_clear";
+       
+       /* api callbacks */
+       ot->invoke = WM_operator_confirm;
+       ot->exec = pose_clear_rot_exec;
+       ot->poll = ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_UNDO;
+
+} 
 /* ************* hide/unhide pose bones ******************* */
 
 static int hide_selected_pose_bone(Object *ob, Bone *bone, void *ptr) 
index 1d9d5d9aa2b250b886373a679d1b92123e0b27c1..b90009adfa83d62c01540809cec16b83e04d535a 100644 (file)
@@ -1669,17 +1669,7 @@ static int object_clear_location_exec(bContext *C, wmOperator *op)
        int armature_clear= 0;
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if ((ob->flag & OB_POSEMODE)) {
-                       /* only clear pose transforms if:
-                        *      - with a mesh in weightpaint mode, it's related armature needs to be cleared
-                        *      - with clearing transform of object being edited at the time
-                        */
-                       if ((G.f & G_WEIGHTPAINT) || (ob==OBACT)) {
-                               clear_armature(scene, ob, 'g');
-                               armature_clear= 1;      /* silly system to prevent another dag update, so no action applied */
-                       }
-               }
-               else if((G.f & G_WEIGHTPAINT)==0) {
+               if((G.f & G_WEIGHTPAINT)==0) {
                        if ((ob->protectflag & OB_LOCK_LOCX)==0)
                                ob->loc[0]= ob->dloc[0]= 0.0f;
                        if ((ob->protectflag & OB_LOCK_LOCY)==0)
@@ -1722,17 +1712,7 @@ static int object_clear_rotation_exec(bContext *C, wmOperator *op)
        int armature_clear= 0;
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if ((ob->flag & OB_POSEMODE)) {
-                       /* only clear pose transforms if:
-                        *      - with a mesh in weightpaint mode, it's related armature needs to be cleared
-                        *      - with clearing transform of object being edited at the time
-                        */
-                       if ((G.f & G_WEIGHTPAINT) || (ob==OBACT)) {
-                               clear_armature(scene, ob, 'r');
-                               armature_clear= 1;      /* silly system to prevent another dag update, so no action applied */
-                       }
-               }
-               else if((G.f & G_WEIGHTPAINT)==0) {
+               if((G.f & G_WEIGHTPAINT)==0) {
                        /* eulers can only get cleared if they are not protected */
                        if ((ob->protectflag & OB_LOCK_ROTX)==0)
                                ob->rot[0]= ob->drot[0]= 0.0f;
@@ -1776,17 +1756,7 @@ static int object_clear_scale_exec(bContext *C, wmOperator *op)
        int armature_clear= 0;
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if ((ob->flag & OB_POSEMODE)) {
-                       /* only clear pose transforms if:
-                        *      - with a mesh in weightpaint mode, it's related armature needs to be cleared
-                        *      - with clearing transform of object being edited at the time
-                        */
-                       if ((G.f & G_WEIGHTPAINT) || (ob==OBACT)) {
-                               clear_armature(scene, ob, 's');
-                               armature_clear= 1;      /* silly system to prevent another dag update, so no action applied */
-                       }
-               }
-               else if((G.f & G_WEIGHTPAINT)==0) {
+               if((G.f & G_WEIGHTPAINT)==0) {
                        if ((ob->protectflag & OB_LOCK_SCALEX)==0) {
                                ob->dsize[0]= 0.0f;
                                ob->size[0]= 1.0f;