Refactor: combine insert_keyframe() and insert_key_rna() into a single function

The goal of this PR is to merge `insert_keyframe()` and `insert_key_rna()` into
a single function, `insert_keyframes()`, that fully accommodates the
functionality of both.  This results in a bit of a mega function, which isn't
great, but it centralizes a lot of otherwise redundant keyframing code so it
only needs to be changed in one place in the future.

Future PRs can work to reduce the "mega" aspect of this function, stripping it
down to its core functionality and eliminating left over incidental redundancy
(e.g. passing both `scene_frame` and `anim_eval_context`).

As a wonderful side effect, this PR also makes layered action keyframing work in
most of the remaining places left over from #121661, such as buttons, the
dopesheet, the graph editor, etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/122053
This commit is contained in:
Nathan Vegdahl
2024-06-11 16:42:55 +02:00
committed by Nathan Vegdahl
parent 7a9b7f527e
commit 1a4f084806
9 changed files with 809 additions and 1112 deletions

View File

@@ -402,17 +402,19 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
}
}
else {
ID *id = self->ptr.owner_id;
BLI_assert(BKE_id_is_in_global_main(self->ptr.owner_id));
BLI_assert(BKE_id_is_in_global_main(id));
CombinedKeyingResult combined_result = insert_keyframe(G_MAIN,
*id,
group_name,
path_full,
index,
&anim_eval_context,
eBezTriple_KeyframeType(keytype),
eInsertKeyFlags(options));
const std::optional<blender::StringRefNull> channel_group = group_name ?
std::optional(group_name) :
std::nullopt;
CombinedKeyingResult combined_result = insert_keyframes(G_MAIN,
&self->ptr,
channel_group,
{{path_full, {}, index}},
std::nullopt,
anim_eval_context,
eBezTriple_KeyframeType(keytype),
eInsertKeyFlags(options));
const int success_count = combined_result.get_count(SingleKeyingResult::SUCCESS);
if (success_count == 0) {
/* Ideally this would use the GUI presentation of RPT_ERROR, as the resulting pop-up has more