Cleanup: reduce code indentation in autokeyframe_pose()
This makes the code a bit simpler to follow, by replacing `if (x) { all the code here }` with `if (!x) { continue; }` and un-indenting the remaining code, and by returning early. No functional changes.
This commit is contained in:
parent
cf258b02f4
commit
ef7229d69a
|
@ -1581,137 +1581,7 @@ void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short t
|
|||
FCurve *fcu;
|
||||
|
||||
// TODO: this should probably be done per channel instead...
|
||||
if (autokeyframe_cfra_can_key(scene, id)) {
|
||||
ReportList *reports = CTX_wm_reports(C);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene);
|
||||
ListBase nla_cache = {NULL, NULL};
|
||||
float cfra = (float)CFRA;
|
||||
eInsertKeyFlags flag = 0;
|
||||
|
||||
/* flag is initialized from UserPref keyframing settings
|
||||
* - special exception for targetless IK - INSERTKEY_MATRIX keyframes should get
|
||||
* visual keyframes even if flag not set, as it's not that useful otherwise
|
||||
* (for quick animation recording)
|
||||
*/
|
||||
flag = ANIM_get_keyframing_flags(scene, true);
|
||||
|
||||
if (targetless_ik) {
|
||||
flag |= INSERTKEY_MATRIX;
|
||||
}
|
||||
|
||||
for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
|
||||
if ((pchan->bone->flag & BONE_TRANSFORM) ||
|
||||
((pose->flag & POSE_MIRROR_EDIT) && (pchan->bone->flag & BONE_TRANSFORM_MIRROR))) {
|
||||
ListBase dsources = {NULL, NULL};
|
||||
|
||||
/* clear any 'unkeyed' flag it may have */
|
||||
pchan->bone->flag &= ~BONE_UNKEYED;
|
||||
|
||||
/* add datasource override for the camera object */
|
||||
ANIM_relative_keyingset_add_source(&dsources, id, &RNA_PoseBone, pchan);
|
||||
|
||||
/* only insert into active keyingset? */
|
||||
if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) {
|
||||
/* run the active Keying Set on the current datasource */
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
/* only insert into available channels? */
|
||||
else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) {
|
||||
if (act) {
|
||||
for (fcu = act->curves.first; fcu; fcu = fcu->next) {
|
||||
/* only insert keyframes for this F-Curve if it affects the current bone */
|
||||
if (strstr(fcu->rna_path, "bones")) {
|
||||
char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
|
||||
|
||||
/* only if bone name matches too...
|
||||
* NOTE: this will do constraints too, but those are ok to do here too?
|
||||
*/
|
||||
if (pchanName && STREQ(pchanName, pchan->name)) {
|
||||
insert_keyframe(bmain,
|
||||
reports,
|
||||
id,
|
||||
act,
|
||||
((fcu->grp) ? (fcu->grp->name) : (NULL)),
|
||||
fcu->rna_path,
|
||||
fcu->array_index,
|
||||
cfra,
|
||||
ts->keyframe_type,
|
||||
&nla_cache,
|
||||
flag);
|
||||
}
|
||||
|
||||
if (pchanName) {
|
||||
MEM_freeN(pchanName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* only insert keyframe if needed? */
|
||||
else if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) {
|
||||
bool do_loc = false, do_rot = false, do_scale = false;
|
||||
|
||||
/* Filter the conditions when this happens
|
||||
* (assume that 'curarea->spacetype == SPACE_VIEW3D'). */
|
||||
if (tmode == TFM_TRANSLATION) {
|
||||
if (targetless_ik) {
|
||||
do_rot = true;
|
||||
}
|
||||
else {
|
||||
do_loc = true;
|
||||
}
|
||||
}
|
||||
else if (ELEM(tmode, TFM_ROTATION, TFM_TRACKBALL)) {
|
||||
if (ELEM(scene->toolsettings->transform_pivot_point,
|
||||
V3D_AROUND_CURSOR,
|
||||
V3D_AROUND_ACTIVE)) {
|
||||
do_loc = true;
|
||||
}
|
||||
|
||||
if ((scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
|
||||
do_rot = true;
|
||||
}
|
||||
}
|
||||
else if (tmode == TFM_RESIZE) {
|
||||
if (ELEM(scene->toolsettings->transform_pivot_point,
|
||||
V3D_AROUND_CURSOR,
|
||||
V3D_AROUND_ACTIVE)) {
|
||||
do_loc = true;
|
||||
}
|
||||
|
||||
if ((scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
|
||||
do_scale = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (do_loc) {
|
||||
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID);
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
if (do_rot) {
|
||||
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID);
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
if (do_scale) {
|
||||
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID);
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
}
|
||||
/* insert keyframe in all (transform) channels */
|
||||
else {
|
||||
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID);
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
|
||||
/* free temp info */
|
||||
BLI_freelistN(&dsources);
|
||||
}
|
||||
}
|
||||
|
||||
BKE_animsys_free_nla_keyframing_context_cache(&nla_cache);
|
||||
}
|
||||
else {
|
||||
if (!autokeyframe_cfra_can_key(scene, id)) {
|
||||
/* tag channels that should have unkeyed data */
|
||||
for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
|
||||
if (pchan->bone->flag & BONE_TRANSFORM) {
|
||||
|
@ -1719,7 +1589,140 @@ void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short t
|
|||
pchan->bone->flag |= BONE_UNKEYED;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ReportList *reports = CTX_wm_reports(C);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene);
|
||||
ListBase nla_cache = {NULL, NULL};
|
||||
float cfra = (float)CFRA;
|
||||
eInsertKeyFlags flag = 0;
|
||||
|
||||
/* flag is initialized from UserPref keyframing settings
|
||||
* - special exception for targetless IK - INSERTKEY_MATRIX keyframes should get
|
||||
* visual keyframes even if flag not set, as it's not that useful otherwise
|
||||
* (for quick animation recording)
|
||||
*/
|
||||
flag = ANIM_get_keyframing_flags(scene, true);
|
||||
|
||||
if (targetless_ik) {
|
||||
flag |= INSERTKEY_MATRIX;
|
||||
}
|
||||
|
||||
for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
|
||||
if ((pchan->bone->flag & BONE_TRANSFORM) == 0 &&
|
||||
!((pose->flag & POSE_MIRROR_EDIT) && (pchan->bone->flag & BONE_TRANSFORM_MIRROR))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ListBase dsources = {NULL, NULL};
|
||||
|
||||
/* clear any 'unkeyed' flag it may have */
|
||||
pchan->bone->flag &= ~BONE_UNKEYED;
|
||||
|
||||
/* add datasource override for the camera object */
|
||||
ANIM_relative_keyingset_add_source(&dsources, id, &RNA_PoseBone, pchan);
|
||||
|
||||
/* only insert into active keyingset? */
|
||||
if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (active_ks)) {
|
||||
/* run the active Keying Set on the current datasource */
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, active_ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
/* only insert into available channels? */
|
||||
else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL)) {
|
||||
if (act) {
|
||||
for (fcu = act->curves.first; fcu; fcu = fcu->next) {
|
||||
/* only insert keyframes for this F-Curve if it affects the current bone */
|
||||
if (strstr(fcu->rna_path, "bones") == NULL) {
|
||||
continue;
|
||||
}
|
||||
char *pchanName = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
|
||||
|
||||
/* only if bone name matches too...
|
||||
* NOTE: this will do constraints too, but those are ok to do here too?
|
||||
*/
|
||||
if (pchanName && STREQ(pchanName, pchan->name)) {
|
||||
insert_keyframe(bmain,
|
||||
reports,
|
||||
id,
|
||||
act,
|
||||
((fcu->grp) ? (fcu->grp->name) : (NULL)),
|
||||
fcu->rna_path,
|
||||
fcu->array_index,
|
||||
cfra,
|
||||
ts->keyframe_type,
|
||||
&nla_cache,
|
||||
flag);
|
||||
}
|
||||
|
||||
if (pchanName) {
|
||||
MEM_freeN(pchanName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* only insert keyframe if needed? */
|
||||
else if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) {
|
||||
bool do_loc = false, do_rot = false, do_scale = false;
|
||||
|
||||
/* Filter the conditions when this happens
|
||||
* (assume that 'curarea->spacetype == SPACE_VIEW3D'). */
|
||||
if (tmode == TFM_TRANSLATION) {
|
||||
if (targetless_ik) {
|
||||
do_rot = true;
|
||||
}
|
||||
else {
|
||||
do_loc = true;
|
||||
}
|
||||
}
|
||||
else if (ELEM(tmode, TFM_ROTATION, TFM_TRACKBALL)) {
|
||||
if (ELEM(scene->toolsettings->transform_pivot_point,
|
||||
V3D_AROUND_CURSOR,
|
||||
V3D_AROUND_ACTIVE)) {
|
||||
do_loc = true;
|
||||
}
|
||||
|
||||
if ((scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
|
||||
do_rot = true;
|
||||
}
|
||||
}
|
||||
else if (tmode == TFM_RESIZE) {
|
||||
if (ELEM(scene->toolsettings->transform_pivot_point,
|
||||
V3D_AROUND_CURSOR,
|
||||
V3D_AROUND_ACTIVE)) {
|
||||
do_loc = true;
|
||||
}
|
||||
|
||||
if ((scene->toolsettings->transform_flag & SCE_XFORM_AXIS_ALIGN) == 0) {
|
||||
do_scale = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (do_loc) {
|
||||
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID);
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
if (do_rot) {
|
||||
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID);
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
if (do_scale) {
|
||||
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_SCALING_ID);
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
}
|
||||
/* insert keyframe in all (transform) channels */
|
||||
else {
|
||||
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID);
|
||||
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
|
||||
}
|
||||
|
||||
/* free temp info */
|
||||
BLI_freelistN(&dsources);
|
||||
}
|
||||
|
||||
BKE_animsys_free_nla_keyframing_context_cache(&nla_cache);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
Loading…
Reference in New Issue