Auto-Keyframing and Clear Transform Operators:
authorJoshua Leung <aligorith@gmail.com>
Mon, 23 Nov 2009 11:58:30 +0000 (11:58 +0000)
committerJoshua Leung <aligorith@gmail.com>
Mon, 23 Nov 2009 11:58:30 +0000 (11:58 +0000)
Clear Location/Rotation/Scale (Alt-G/R/S) now insert keyframes when Auto-Keyframing is enabled.

source/blender/editors/animation/keyingsets.c
source/blender/editors/armature/editarmature.c
source/blender/editors/object/object_transform.c

index bb3182b3d6e869e389dc6bd2e04578f6527cb073..d7406a7bcfdbe0932f1c0d37ebcaa0628aa7ee44 100644 (file)
@@ -1294,6 +1294,10 @@ int modify_keyframes (Scene *scene, ListBase *dsources, bAction *act, KeyingSet
        int kflag=0, success= 0;
        char *groupname= NULL;
        
+       /* sanity checks */
+       if (ks == NULL)
+               return 0;
+       
        /* get flags to use */
        if (mode == MODIFYKEY_MODE_INSERT) {
                /* use KeyingSet's flags as base */
index 8c858536fc5250eec1951220718638c6afb306a9..3936bc92bb99666ceaa1b18de535f88801c1ba18 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_anim_types.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_constraint_types.h"
@@ -83,6 +84,7 @@
 #include "WM_types.h"
 
 #include "ED_armature.h"
+#include "ED_keyframing.h"
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
@@ -4843,8 +4845,17 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mod
 
 static int pose_clear_scale_exec(bContext *C, wmOperator *op) 
 {
+       Scene *scene= CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
        
+       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling");
+       bCommonKeySrc cks;
+       ListBase dsources = {&cks, &cks};
+       
+       /* init common-key-source for use by KeyingSets */
+       memset(&cks, 0, sizeof(bCommonKeySrc));
+       cks.id= &ob->id;
+       
        /* only clear those channels that are not locked */
        CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
                if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
@@ -4854,8 +4865,21 @@ static int pose_clear_scale_exec(bContext *C, wmOperator *op)
                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;
+               /* do auto-keyframing as appropriate */
+               if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+                       /* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
+                       cks.pchan= pchan;
+                       modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+                       
+                       /* clear any unkeyed tags */
+                       if (pchan->bone)
+                               pchan->bone->flag &= ~BONE_UNKEYED;
+               }
+               else {
+                       /* add unkeyed tags */
+                       if (pchan->bone)
+                               pchan->bone->flag |= BONE_UNKEYED;
+               }
        }
        CTX_DATA_END;
        
@@ -4884,10 +4908,20 @@ void POSE_OT_scale_clear(wmOperatorType *ot)
 
 static int pose_clear_loc_exec(bContext *C, wmOperator *op) 
 {
+       Scene *scene= CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
        
+       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location");
+       bCommonKeySrc cks;
+       ListBase dsources = {&cks, &cks};
+       
+       /* init common-key-source for use by KeyingSets */
+       memset(&cks, 0, sizeof(bCommonKeySrc));
+       cks.id= &ob->id;
+       
        /* only clear those channels that are not locked */
        CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
+               /* clear location */
                if ((pchan->protectflag & OB_LOCK_LOCX)==0)
                        pchan->loc[0]= 0.0f;
                if ((pchan->protectflag & OB_LOCK_LOCY)==0)
@@ -4895,8 +4929,21 @@ static int pose_clear_loc_exec(bContext *C, wmOperator *op)
                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;
+               /* do auto-keyframing as appropriate */
+               if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+                       /* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
+                       cks.pchan= pchan;
+                       modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+                       
+                       /* clear any unkeyed tags */
+                       if (pchan->bone)
+                               pchan->bone->flag &= ~BONE_UNKEYED;
+               }
+               else {
+                       /* add unkeyed tags */
+                       if (pchan->bone)
+                               pchan->bone->flag |= BONE_UNKEYED;
+               }
        }
        CTX_DATA_END;
        
@@ -4925,8 +4972,17 @@ void POSE_OT_loc_clear(wmOperatorType *ot)
 
 static int pose_clear_rot_exec(bContext *C, wmOperator *op) 
 {
+       Scene *scene= CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
        
+       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation");
+       bCommonKeySrc cks;
+       ListBase dsources = {&cks, &cks};
+       
+       /* init common-key-source for use by KeyingSets */
+       memset(&cks, 0, sizeof(bCommonKeySrc));
+       cks.id= &ob->id;
+       
        /* only clear those channels that are not locked */
        CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
                if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) {
@@ -5021,8 +5077,21 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op)
                        }
                }
                
-               /* the current values from IPO's may not be zero, so tag as unkeyed */
-               //pchan->bone->flag |= BONE_UNKEYED;
+               /* do auto-keyframing as appropriate */
+               if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+                       /* init cks for this PoseChannel, then use the relative KeyingSets to keyframe it */
+                       cks.pchan= pchan;
+                       modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+                       
+                       /* clear any unkeyed tags */
+                       if (pchan->bone)
+                               pchan->bone->flag &= ~BONE_UNKEYED;
+               }
+               else {
+                       /* add unkeyed tags */
+                       if (pchan->bone)
+                               pchan->bone->flag |= BONE_UNKEYED;
+               }
        }
        CTX_DATA_END;
        
index fcd8a989dc77777abca8db1fff274384901b0729..20d93083410c22074ad41cdbf9179657a563d2c7 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <stdlib.h>
 
+#include "DNA_anim_types.h"
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
@@ -61,6 +62,7 @@
 #include "ED_anim_api.h"
 #include "ED_armature.h"
 #include "ED_curve.h"
+#include "ED_keyframing.h"
 #include "ED_mesh.h"
 #include "ED_object.h"
 #include "ED_screen.h"
 
 static int object_location_clear_exec(bContext *C, wmOperator *op)
 {
-       int armature_clear= 0;
-
+       Scene *scene= CTX_data_scene(C);
+       
+       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Location");
+       bCommonKeySrc cks;
+       ListBase dsources = {&cks, &cks};
+       
+       /* init common-key-source for use by KeyingSets */
+       memset(&cks, 0, sizeof(bCommonKeySrc));
+       
+       /* clear location of selected objects if not in weight-paint mode */
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
                if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
                        if((ob->protectflag & OB_LOCK_LOCX)==0)
@@ -82,13 +92,17 @@ static int object_location_clear_exec(bContext *C, wmOperator *op)
                                ob->loc[1]= ob->dloc[1]= 0.0f;
                        if((ob->protectflag & OB_LOCK_LOCZ)==0)
                                ob->loc[2]= ob->dloc[2]= 0.0f;
+                               
+                       /* do auto-keyframing as appropriate */
+                       if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+                               /* init cks for this object, then use the relative KeyingSets to keyframe it */
+                               cks.id= &ob->id;
+                               modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+                       }
                }
                ob->recalc |= OB_RECALC_OB;
        }
        CTX_DATA_END;
-
-       if(armature_clear==0) /* in this case flush was done */
-               ED_anim_dag_flush_update(C);    
        
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
        
@@ -112,8 +126,16 @@ void OBJECT_OT_location_clear(wmOperatorType *ot)
 
 static int object_rotation_clear_exec(bContext *C, wmOperator *op)
 {
-       int armature_clear= 0;
-
+       Scene *scene= CTX_data_scene(C);
+       
+       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Rotation");
+       bCommonKeySrc cks;
+       ListBase dsources = {&cks, &cks};
+       
+       /* init common-key-source for use by KeyingSets */
+       memset(&cks, 0, sizeof(bCommonKeySrc));
+       
+       /* clear rotation of selected objects if not in weight-paint mode */
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
                if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
                        if (ob->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ|OB_LOCK_ROTW)) {
@@ -206,13 +228,17 @@ static int object_rotation_clear_exec(bContext *C, wmOperator *op)
                                        ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0f;
                                }
                        }
+                       
+                       /* do auto-keyframing as appropriate */
+                       if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+                               /* init cks for this object, then use the relative KeyingSets to keyframe it */
+                               cks.id= &ob->id;
+                               modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+                       }
                }
                ob->recalc |= OB_RECALC_OB;
        }
        CTX_DATA_END;
-
-       if(armature_clear==0) /* in this case flush was done */
-               ED_anim_dag_flush_update(C);    
        
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
        
@@ -236,8 +262,16 @@ void OBJECT_OT_rotation_clear(wmOperatorType *ot)
 
 static int object_scale_clear_exec(bContext *C, wmOperator *op)
 {
-       int armature_clear= 0;
-
+       Scene *scene= CTX_data_scene(C);
+       
+       KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, "Scaling");
+       bCommonKeySrc cks;
+       ListBase dsources = {&cks, &cks};
+       
+       /* init common-key-source for use by KeyingSets */
+       memset(&cks, 0, sizeof(bCommonKeySrc));
+       
+       /* clear scales of selected objects if not in weight-paint mode */
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
                if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
                        if((ob->protectflag & OB_LOCK_SCALEX)==0) {
@@ -252,14 +286,18 @@ static int object_scale_clear_exec(bContext *C, wmOperator *op)
                                ob->dsize[2]= 0.0f;
                                ob->size[2]= 1.0f;
                        }
+                       
+                       /* do auto-keyframing as appropriate */
+                       if (autokeyframe_cfra_can_key(scene, &ob->id)) {
+                               /* init cks for this object, then use the relative KeyingSets to keyframe it */
+                               cks.id= &ob->id;
+                               modify_keyframes(scene, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+                       }
                }
                ob->recalc |= OB_RECALC_OB;
        }
        CTX_DATA_END;
        
-       if(armature_clear==0) /* in this case flush was done */
-               ED_anim_dag_flush_update(C);    
-       
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
        
        return OPERATOR_FINISHED;