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

Merged
Nathan Vegdahl merged 49 commits from nathanvegdahl/blender:combine_keying_functions into main 2024-06-11 16:43:08 +02:00
4 changed files with 16 additions and 4 deletions
Showing only changes of commit d6b6638ad9 - Show all commits

View File

@ -263,8 +263,9 @@ CombinedKeyingResult insert_key_action(Main *bmain,
*/
CombinedKeyingResult insert_key_rna(Main *bmain,
ID &id,
std::optional<std::string> channel_group,
const blender::Span<RNAPath> rna_paths,
float scene_frame,
std::optional<float> scene_frame,
const AnimationEvalContext &anim_eval_context,
eBezTriple_KeyframeType key_type,
eInsertKeyFlags insert_key_flags);

View File

@ -915,6 +915,7 @@ CombinedKeyingResult insert_key_action(Main *bmain,
bAction *action,
PointerRNA *ptr,
PropertyRNA *prop,
const std::optional<std::string> channel_group,
const std::string &rna_path,
const float frame,
const Span<float> values,
@ -926,7 +927,10 @@ CombinedKeyingResult insert_key_action(Main *bmain,
BLI_assert(action != nullptr);
std::string group;
if (ptr->type == &RNA_PoseBone) {
if (channel_group.has_value()) {
group = *channel_group;
}
else if (ptr->type == &RNA_PoseBone) {
bPoseChannel *pose_channel = static_cast<bPoseChannel *>(ptr->data);
group = pose_channel->name;
}
@ -961,8 +965,9 @@ CombinedKeyingResult insert_key_action(Main *bmain,
CombinedKeyingResult insert_key_rna(Main *bmain,
ID &id,
const std::optional<std::string> channel_group,
const blender::Span<RNAPath> rna_paths,
const float scene_frame,
const std::optional<float> scene_frame,
const AnimationEvalContext &anim_eval_context,
const eBezTriple_KeyframeType key_type,
const eInsertKeyFlags insert_key_flags)
@ -972,6 +977,8 @@ CombinedKeyingResult insert_key_rna(Main *bmain,
bAction *action = id_action_ensure(bmain, &id);
CombinedKeyingResult combined_result;
const float frame = scene_frame.value_or(anim_eval_context.eval_time);
if (action == nullptr) {
return combined_result;
}
@ -988,7 +995,7 @@ CombinedKeyingResult insert_key_rna(Main *bmain,
&nla_cache, &id_pointer, adt, &anim_eval_context);
}
const float nla_frame = BKE_nla_tweakedit_remap(adt, scene_frame, NLATIME_CONVERT_UNMAP);
const float nla_frame = BKE_nla_tweakedit_remap(adt, frame, NLATIME_CONVERT_UNMAP);
const bool visual_keyframing = insert_key_flags & INSERTKEY_MATRIX;
for (const RNAPath &rna_path : rna_paths) {
@ -1016,6 +1023,7 @@ CombinedKeyingResult insert_key_rna(Main *bmain,
action,
&rna_pointer,
prop,
channel_group,
rna_path_id_to_prop->c_str(),
nla_frame,
rna_values.as_span(),

View File

@ -145,6 +145,7 @@ void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<RNAPath> rn
const CombinedKeyingResult result = insert_key_rna(
bmain,
*ptr.owner_id,
std::nullopt,
rna_paths,
scene_frame,
anim_eval_context,
@ -248,6 +249,7 @@ void autokeyframe_pose_channel(bContext *C,
const CombinedKeyingResult result = insert_key_rna(
bmain,
*ptr.owner_id,
std::nullopt,
rna_paths,
scene_frame,
anim_eval_context,

View File

@ -404,6 +404,7 @@ static int insert_key(bContext *C, wmOperator *op)
combined_result.merge(animrig::insert_key_rna(bmain,
*selected_id,
std::nullopt,
rna_paths.as_span(),
scene_frame,
anim_eval_context,