fix [#28850] With "Auto-keyframe" on, the "Selection to Cursor" option doesn't create keyframe.

This commit is contained in:
Campbell Barton 2011-10-10 12:56:21 +00:00
parent 92c4fe8713
commit 90b3bd84da
5 changed files with 82 additions and 71 deletions

@ -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;
}
}

@ -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;

@ -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

@ -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);
}

@ -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;