From 90b3bd84daf24199aa8b389277a88dd722f7ab06 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 10 Oct 2011 12:56:21 +0000 Subject: [PATCH] fix [#28850] With "Auto-keyframe" on, the "Selection to Cursor" option doesn't create keyframe. --- source/blender/editors/animation/keyframing.c | 53 +++++++++++++++++ source/blender/editors/armature/poseobject.c | 57 +++---------------- .../blender/editors/include/ED_keyframing.h | 5 ++ .../blender/editors/object/object_transform.c | 18 +----- .../editors/space_view3d/view3d_snap.c | 20 ++++--- 5 files changed, 82 insertions(+), 71 deletions(-) diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index b52550832c3..fb34245d338 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -1748,3 +1748,56 @@ short id_frame_has_keyframe (ID *id, float frame, short filter) } /* ************************************************** */ + +int ED_autokeyframe_object(bContext *C, Scene *scene, Object *ob, KeyingSet *ks) +{ + /* auto keyframing */ + if (autokeyframe_cfra_can_key(scene, &ob->id)) { + ListBase dsources = {NULL, NULL}; + + /* now insert the keyframe(s) using the Keying Set + * 1) add datasource override for the Object + * 2) insert keyframes + * 3) free the extra info + */ + ANIM_relative_keyingset_add_source(&dsources, &ob->id, NULL, NULL); + ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); + BLI_freelistN(&dsources); + + return TRUE; + } + else { + return FALSE; + } +} + +int ED_autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks) +{ + if (autokeyframe_cfra_can_key(scene, &ob->id)) { + ListBase dsources = {NULL, NULL}; + + /* now insert the keyframe(s) using the Keying Set + * 1) add datasource override for the PoseChannel + * 2) insert keyframes + * 3) free the extra info + */ + ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan); + ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); + BLI_freelistN(&dsources); + + /* clear any unkeyed tags */ + if (pchan->bone) { + pchan->bone->flag &= ~BONE_UNKEYED; + } + + return TRUE; + } + else { + /* add unkeyed tags */ + if (pchan->bone) { + pchan->bone->flag |= BONE_UNKEYED; + } + + return FALSE; + } +} diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index 43122ea08d3..61935aa72ca 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -1149,7 +1149,10 @@ static int pose_paste_exec (bContext *C, wmOperator *op) bPoseChannel *chan; int flip= RNA_boolean_get(op->ptr, "flipped"); int selOnly= RNA_boolean_get(op->ptr, "selected_mask"); - + + /* get KeyingSet to use */ + KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "LocRotScale"); + /* sanity checks */ if ELEM(NULL, ob, ob->pose) return OPERATOR_CANCELLED; @@ -1166,7 +1169,7 @@ static int pose_paste_exec (bContext *C, wmOperator *op) if (CTX_DATA_COUNT(C, selected_pose_bones) == 0) selOnly = 0; } - + /* Safely merge all of the channels in the buffer pose into any existing pose */ for (chan= g_posebuf->chanbase.first; chan; chan=chan->next) { if (chan->flag & POSE_KEY) { @@ -1175,30 +1178,7 @@ static int pose_paste_exec (bContext *C, wmOperator *op) if (pchan) { /* keyframing tagging for successful paste */ - if (autokeyframe_cfra_can_key(scene, &ob->id)) { - ListBase dsources = {NULL, NULL}; - - /* get KeyingSet to use */ - KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "LocRotScale"); - - /* now insert the keyframe(s) using the Keying Set - * 1) add datasource override for the PoseChannel - * 2) insert keyframes - * 3) free the extra info - */ - ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); - BLI_freelistN(&dsources); - - /* clear any unkeyed tags */ - if (chan->bone) - chan->bone->flag &= ~BONE_UNKEYED; - } - else { - /* add unkeyed tags */ - if (chan->bone) - chan->bone->flag |= BONE_UNKEYED; - } + ED_autokeyframe_pchan(C, scene, ob, pchan, ks); } } } @@ -2194,29 +2174,8 @@ static int pose_flip_quats_exec (bContext *C, wmOperator *UNUSED(op)) if (pchan->rotmode == ROT_MODE_QUAT) { /* quaternions have 720 degree range */ negate_v4(pchan->quat); - - /* tagging */ - if (autokeyframe_cfra_can_key(scene, &ob->id)) { - ListBase dsources = {NULL, NULL}; - - /* now insert the keyframe(s) using the Keying Set - * 1) add datasource override for the PoseChannel - * 2) insert keyframes - * 3) free the extra info - */ - ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); - BLI_freelistN(&dsources); - - /* clear any unkeyed tags */ - if (pchan->bone) - pchan->bone->flag &= ~BONE_UNKEYED; - } - else { - /* add unkeyed tags */ - if (pchan->bone) - pchan->bone->flag |= BONE_UNKEYED; - } + + ED_autokeyframe_pchan(C, scene, ob, pchan, ks); } } CTX_DATA_END; diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h index cda3c4f3e71..8dd543d8f63 100644 --- a/source/blender/editors/include/ED_keyframing.h +++ b/source/blender/editors/include/ED_keyframing.h @@ -313,6 +313,11 @@ typedef enum eAnimFilterFlags { ANIMFILTER_KEYS_NOSKEY = (1<<10), /* don't include shape keys (for geometry) */ } eAnimFilterFlags; +/* utility funcs for auto keyframe */ +int ED_autokeyframe_object(struct bContext *C, struct Scene *scene, struct Object *ob, struct KeyingSet *ks); +int ED_autokeyframe_pchan(struct bContext *C, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, struct KeyingSet *ks); + + #ifdef __cplusplus } #endif diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 4c29490b0f0..4ca7d272503 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -230,21 +230,9 @@ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op, if (!(ob->mode & OB_MODE_WEIGHT_PAINT)) { /* run provided clearing function */ clear_func(ob); - - /* auto keyframing */ - if (autokeyframe_cfra_can_key(scene, &ob->id)) { - ListBase dsources = {NULL, NULL}; - - /* now insert the keyframe(s) using the Keying Set - * 1) add datasource override for the Object - * 2) insert keyframes - * 3) free the extra info - */ - ANIM_relative_keyingset_add_source(&dsources, &ob->id, NULL, NULL); - ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA); - BLI_freelistN(&dsources); - } - + + ED_autokeyframe_object(C, scene, ob, ks); + /* tag for updates */ DAG_id_tag_update(&ob->id, OB_RECALC_OB); } diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 1ed65f7875f..fa3007d2fb7 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -65,6 +65,7 @@ #include "ED_armature.h" #include "ED_mesh.h" +#include "ED_keyframing.h" #include "ED_screen.h" #include "ED_curve.h" /* for curve_editnurbs */ @@ -494,6 +495,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op)) } else { + struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location"); CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { if(ob->mode & OB_MODE_POSE) { @@ -522,6 +524,9 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op)) pchan->loc[0]= vecN[1]; if ((pchan->protectflag & OB_LOCK_LOCZ)==0) pchan->loc[0]= vecN[2]; + + /* auto-keyframing */ + ED_autokeyframe_pchan(C, scene, ob, pchan, ks); } /* if the bone has a parent and is connected to the parent, * don't do anything - will break chain unless we do auto-ik. @@ -531,8 +536,6 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op)) } ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); - /* auto-keyframing */ -// XXX autokeyframe_pose_cb_func(ob, TFM_TRANSLATION, 0); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { @@ -556,7 +559,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *UNUSED(op)) ob->loc[2]+= vec[2]; /* auto-keyframing */ -// XXX autokeyframe_ob_cb_func(ob, TFM_TRANSLATION); + ED_autokeyframe_object(C, scene, ob, ks); } } CTX_DATA_END; @@ -622,6 +625,8 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op)) } else { + struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, "Location"); + CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) { if(ob->mode & OB_MODE_POSE) { bPoseChannel *pchan; @@ -648,6 +653,9 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op)) pchan->loc[1]= curspn[1]; if ((pchan->protectflag & OB_LOCK_LOCZ)==0) pchan->loc[2]= curspn[2]; + + /* auto-keyframing */ + ED_autokeyframe_pchan(C, scene, ob, pchan, ks); } /* if the bone has a parent and is connected to the parent, * don't do anything - will break chain unless we do auto-ik. @@ -657,8 +665,6 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op)) } ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); - /* auto-keyframing */ -// XXX autokeyframe_pose_cb_func(ob, TFM_TRANSLATION, 0); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { @@ -680,9 +686,9 @@ static int snap_sel_to_curs(bContext *C, wmOperator *UNUSED(op)) ob->loc[1]+= vec[1]; if ((ob->protectflag & OB_LOCK_LOCZ)==0) ob->loc[2]+= vec[2]; - + /* auto-keyframing */ -// XXX autokeyframe_ob_cb_func(ob, TFM_TRANSLATION); + ED_autokeyframe_object(C, scene, ob, ks); } } CTX_DATA_END;