mirror of
https://github.com/blender/blender
synced 2026-09-29 04:37:17 +03:00
Anim: simplify object/pose autokeying code
Both `autokeyframe_object()` and `autokeyframe_pose_channel()` had an odd structure where they would call completely different keying functions depending on whether "Only Insert Available" was toggled on or not. This not only overcomplicated the code, but also introduced the possibility for divergent keyframing behavior depending on whether that flag was set or not, beyond the intended effect of the flag. This commit changes both functions to call the same keyframing function (which already handles that flag correctly on its own) regardless of whether that flag is set or not, unifying the keyframing behavior and simplifying the code. As a happy side effect, auto-keyframing failures are now reported even when "Only Insert Available" is disabled, which wasn't the case before. (An example of the aforementioned unintentional divergent behavior.) Pull Request: https://projects.blender.org/blender/blender/pulls/121476
This commit is contained in:
parent
44d020771d
commit
fa201712e1
1 changed files with 27 additions and 74 deletions
|
|
@ -137,43 +137,24 @@ void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<std::string
|
|||
return;
|
||||
}
|
||||
|
||||
if (is_keying_flag(scene, AUTOKEY_FLAG_INSERTAVAILABLE)) {
|
||||
/* Only key on available channels. */
|
||||
AnimData *adt = ob->adt;
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
Main *bmain = CTX_data_main(C);
|
||||
|
||||
if (adt && adt->action) {
|
||||
CombinedKeyingResult combined_result;
|
||||
LISTBASE_FOREACH (FCurve *, fcu, &adt->action->curves) {
|
||||
CombinedKeyingResult result = insert_keyframe(bmain,
|
||||
*id,
|
||||
(fcu->grp ? fcu->grp->name : nullptr),
|
||||
fcu->rna_path,
|
||||
fcu->array_index,
|
||||
&anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
combined_result.merge(result);
|
||||
}
|
||||
if (combined_result.get_count(SingleKeyingResult::SUCCESS) == 0) {
|
||||
combined_result.generate_reports(reports);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const float scene_frame = BKE_scene_frame_get(scene);
|
||||
Main *bmain = CTX_data_main(C);
|
||||
|
||||
CombinedKeyingResult combined_result;
|
||||
for (PointerRNA ptr : sources) {
|
||||
insert_key_rna(&ptr,
|
||||
rna_paths,
|
||||
scene_frame,
|
||||
flag,
|
||||
eBezTriple_KeyframeType(scene->toolsettings->keyframe_type),
|
||||
bmain,
|
||||
anim_eval_context);
|
||||
const CombinedKeyingResult result = insert_key_rna(
|
||||
&ptr,
|
||||
rna_paths,
|
||||
scene_frame,
|
||||
flag,
|
||||
eBezTriple_KeyframeType(scene->toolsettings->keyframe_type),
|
||||
bmain,
|
||||
anim_eval_context);
|
||||
combined_result.merge(result);
|
||||
}
|
||||
|
||||
if (combined_result.get_count(SingleKeyingResult::SUCCESS) == 0) {
|
||||
combined_result.generate_reports(reports);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -227,15 +208,12 @@ void autokeyframe_pose_channel(bContext *C,
|
|||
|
||||
Main *bmain = CTX_data_main(C);
|
||||
ID *id = &ob->id;
|
||||
AnimData *adt = ob->adt;
|
||||
bAction *act = (adt) ? adt->action : nullptr;
|
||||
|
||||
if (!blender::animrig::autokeyframe_cfra_can_key(scene, id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReportList *reports = CTX_wm_reports(C);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene);
|
||||
Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
|
||||
const float scene_frame = BKE_scene_frame_get(scene);
|
||||
|
|
@ -265,46 +243,21 @@ void autokeyframe_pose_channel(bContext *C,
|
|||
return;
|
||||
}
|
||||
|
||||
/* only insert into available channels? */
|
||||
if (is_keying_flag(scene, AUTOKEY_FLAG_INSERTAVAILABLE)) {
|
||||
if (!act) {
|
||||
return;
|
||||
}
|
||||
LISTBASE_FOREACH (FCurve *, fcu, &act->curves) {
|
||||
/* only insert keyframes for this F-Curve if it affects the current bone */
|
||||
char pchan_name[sizeof(pose_channel->name)];
|
||||
if (!BLI_str_quoted_substr(fcu->rna_path, "bones[", pchan_name, sizeof(pchan_name))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* only if bone name matches too...
|
||||
* NOTE: this will do constraints too, but those are ok to do here too?
|
||||
*/
|
||||
if (STREQ(pchan_name, pose_channel->name)) {
|
||||
CombinedKeyingResult result = insert_keyframe(bmain,
|
||||
*id,
|
||||
((fcu->grp) ? (fcu->grp->name) : (nullptr)),
|
||||
fcu->rna_path,
|
||||
fcu->array_index,
|
||||
&anim_eval_context,
|
||||
eBezTriple_KeyframeType(ts->keyframe_type),
|
||||
flag);
|
||||
if (result.get_count(SingleKeyingResult::SUCCESS) == 0) {
|
||||
result.generate_reports(reports);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
CombinedKeyingResult combined_result;
|
||||
for (PointerRNA &ptr : sources) {
|
||||
const CombinedKeyingResult result = insert_key_rna(
|
||||
&ptr,
|
||||
rna_paths,
|
||||
scene_frame,
|
||||
flag,
|
||||
eBezTriple_KeyframeType(scene->toolsettings->keyframe_type),
|
||||
bmain,
|
||||
anim_eval_context);
|
||||
combined_result.merge(result);
|
||||
}
|
||||
|
||||
for (PointerRNA &ptr : sources) {
|
||||
insert_key_rna(&ptr,
|
||||
rna_paths,
|
||||
scene_frame,
|
||||
flag,
|
||||
eBezTriple_KeyframeType(scene->toolsettings->keyframe_type),
|
||||
bmain,
|
||||
anim_eval_context);
|
||||
if (combined_result.get_count(SingleKeyingResult::SUCCESS) == 0) {
|
||||
combined_result.generate_reports(reports);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue