Blender V4.3
pose.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "ANIM_pose.hh"
10#include "BKE_action.hh"
11#include "BKE_animsys.h"
12#include "BKE_armature.hh"
13#include "BLI_listbase.h"
14#include "DNA_anim_types.h"
15#include "DNA_object_types.h"
16#include "RNA_access.hh"
17
18#include "ANIM_action.hh"
19
20namespace blender::animrig {
21
22namespace {
23
24using ActionApplier = blender::FunctionRef<void(
26
27void pose_apply_restore_fcurves(bAction *action)
28{
29 /* TODO(Sybren): Restore the FCurve flags, instead of just erasing the 'disabled' flag. */
30 LISTBASE_FOREACH (FCurve *, fcu, &action->curves) {
31 fcu->flag &= ~FCURVE_DISABLED;
32 }
33}
34
35void pose_apply_disable_fcurves_for_unselected_bones(
36 bAction *action, const blender::bke::BoneNameSet &selected_bone_names)
37{
38 auto disable_unselected_fcurve = [&](FCurve *fcu, const char *bone_name) {
39 const bool is_bone_selected = selected_bone_names.contains(bone_name);
40 if (!is_bone_selected) {
41 fcu->flag |= FCURVE_DISABLED;
42 }
43 };
44 blender::bke::BKE_action_find_fcurves_with_bones(action, disable_unselected_fcurve);
45}
46
47void pose_apply(Object *ob,
48 bAction *action,
49 const slot_handle_t slot_handle,
50 const AnimationEvalContext *anim_eval_context,
51 ActionApplier applier)
52{
53 bPose *pose = ob->pose;
54 if (pose == nullptr) {
55 return;
56 }
57
58 const bArmature *armature = (bArmature *)ob->data;
59 const blender::bke::BoneNameSet selected_bone_names =
61 const bool limit_to_selected_bones = !selected_bone_names.is_empty();
62
63 if (limit_to_selected_bones) {
64 /* Mute all FCurves that are not associated with selected bones. This separates the concept of
65 * bone selection from the FCurve evaluation code. */
66 pose_apply_disable_fcurves_for_unselected_bones(action, selected_bone_names);
67 }
68
69 /* Apply the Action. */
70 PointerRNA pose_owner_ptr = RNA_id_pointer_create(&ob->id);
71
72 applier(&pose_owner_ptr, action, slot_handle, anim_eval_context);
73
74 if (limit_to_selected_bones) {
75 pose_apply_restore_fcurves(action);
76 }
77}
78
79} // namespace
80
82 bAction *action,
83 const int32_t slot_handle,
84 const AnimationEvalContext *anim_eval_context)
85{
86 auto evaluate_and_apply = [](PointerRNA *ptr,
87 bAction *act,
88 const int32_t slot_handle,
89 const AnimationEvalContext *anim_eval_context) {
90 animsys_evaluate_action(ptr, act, slot_handle, anim_eval_context, false);
91 };
92
93 pose_apply(ob, action, slot_handle, anim_eval_context, evaluate_and_apply);
94}
95
97 bAction *action,
98 const int32_t slot_handle,
99 const AnimationEvalContext *anim_eval_context)
100{
101 PointerRNA pose_owner_ptr = RNA_id_pointer_create(&ob->id);
102 animsys_evaluate_action(&pose_owner_ptr, action, slot_handle, anim_eval_context, false);
103}
104
106 bAction *action,
107 const int32_t slot_handle,
108 const AnimationEvalContext *anim_eval_context,
109 const float blend_factor)
110{
111 auto evaluate_and_blend = [blend_factor](PointerRNA *ptr,
112 bAction *act,
113 const int32_t slot_handle,
114 const AnimationEvalContext *anim_eval_context) {
115 animsys_blend_in_action(ptr, act, slot_handle, anim_eval_context, blend_factor);
116 };
117
118 pose_apply(ob, action, slot_handle, anim_eval_context, evaluate_and_blend);
119}
120
121} // namespace blender::animrig
Functions and classes to work with Actions.
Functions to work with animation poses.
Blender kernel action and pose functionality.
void animsys_blend_in_action(struct PointerRNA *ptr, struct bAction *act, int32_t action_slot_handle, const AnimationEvalContext *anim_eval_context, float blend_factor)
Definition anim_sys.cc:916
void animsys_evaluate_action(struct PointerRNA *ptr, struct bAction *act, int32_t action_slot_handle, const struct AnimationEvalContext *anim_eval_context, bool flush_to_original)
#define LISTBASE_FOREACH(type, var, list)
@ FCURVE_DISABLED
Object is a sort of wrapper for general info.
bool contains(const Key &key) const
Definition BLI_set.hh:291
bool is_empty() const
Definition BLI_set.hh:572
void pose_apply_action_all_bones(Object *ob, bAction *action, slot_handle_t slot_handle, const AnimationEvalContext *anim_eval_context)
void pose_apply_action_selected_bones(Object *ob, bAction *action, slot_handle_t slot_handle, const AnimationEvalContext *anim_eval_context)
decltype(::ActionSlot::handle) slot_handle_t
void pose_apply_action_blend(Object *ob, bAction *action, slot_handle_t slot_handle, const AnimationEvalContext *anim_eval_context, float blend_factor)
void BKE_action_find_fcurves_with_bones(const bAction *action, FoundFCurveCallback callback)
BoneNameSet BKE_armature_find_selected_bone_names(const bArmature *armature)
PointerRNA RNA_id_pointer_create(ID *id)
signed int int32_t
Definition stdint.h:77
struct bPose * pose
ListBase curves
PointerRNA * ptr
Definition wm_files.cc:4126