diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-11-23 14:58:30 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-11-23 14:58:30 +0300 |
commit | 78b76cc39fdada13c088e4404b72792bdab5414d (patch) | |
tree | da348541f65e01614b4c9ea510128c36ba21c50d | |
parent | f8d40d2da04e07481acbe8affc7249cb7165c649 (diff) |
Auto-Keyframing and Clear Transform Operators:
Clear Location/Rotation/Scale (Alt-G/R/S) now insert keyframes when Auto-Keyframing is enabled.
-rw-r--r-- | source/blender/editors/animation/keyingsets.c | 4 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature.c | 81 | ||||
-rw-r--r-- | source/blender/editors/object/object_transform.c | 68 |
3 files changed, 132 insertions, 21 deletions
diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index bb3182b3d6e..d7406a7bcfd 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -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 */ diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 8c858536fc5..3936bc92bb9 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -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; diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index fcd8a989dc7..20d93083410 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -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" @@ -72,8 +74,16 @@ 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; |