diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-07-12 12:28:15 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-07-15 17:12:36 +0300 |
commit | 9473c61b366cb3d55bac873e4a6cebd77595ee0d (patch) | |
tree | 1045a156de352308c82c0373f277ed936f8b548b | |
parent | b40e05fcd134e5b9d5aac7ba9e5f45e4e9733607 (diff) |
Animation: apply pose to all or selected bones of armature
New function `BKE_pose_apply_action_all_bones()`, which will be
necessary for the upcoming pose library v2.0.
This renames the function `BKE_pose_apply_action` to
`BKE_pose_apply_action_selected_bones`, to reflect that it only works on
selected bones, to contrast it to the new function.
-rw-r--r-- | source/blender/blenkernel/BKE_armature.h | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/armature_pose.cc | 43 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_pose_api.c | 2 |
3 files changed, 47 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 86aa18e5739..a09c3e361b6 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -207,9 +207,14 @@ void BKE_pose_where_is_bone_tail(struct bPoseChannel *pchan); /* Evaluate the action and apply it to the pose. If any pose bones are selected, only FCurves that * relate to those bones are evaluated. */ -void BKE_pose_apply_action(struct Object *ob, - struct bAction *action, - struct AnimationEvalContext *anim_eval_context); +void BKE_pose_apply_action_selected_bones(struct Object *ob, + struct bAction *action, + struct AnimationEvalContext *anim_eval_context); +/* Evaluate the action and apply it to the pose. Ignore selection state of the bones. */ +void BKE_pose_apply_action_all_bones(struct Object *ob, + struct bAction *action, + struct AnimationEvalContext *anim_eval_context); + void vec_roll_to_mat3(const float vec[3], const float roll, float r_mat[3][3]); void vec_roll_to_mat3_normalized(const float nor[3], const float roll, float r_mat[3][3]); diff --git a/source/blender/blenkernel/intern/armature_pose.cc b/source/blender/blenkernel/intern/armature_pose.cc index ca11692372b..9f4b1a31114 100644 --- a/source/blender/blenkernel/intern/armature_pose.cc +++ b/source/blender/blenkernel/intern/armature_pose.cc @@ -26,6 +26,7 @@ #include "BKE_animsys.h" #include "BKE_armature.h" +#include "BLI_function_ref.hh" #include "BLI_set.hh" #include "DNA_action_types.h" @@ -38,16 +39,48 @@ namespace { using BoneNameSet = blender::Set<std::string>; +using ActionApplier = + blender::FunctionRef<void(PointerRNA *, bAction *, const AnimationEvalContext *)>; + // Forward declarations. BoneNameSet pose_apply_find_selected_bones(const bArmature *armature, const bPose *pose); void pose_apply_disable_fcurves_for_unselected_bones(bAction *action, const BoneNameSet &selected_bone_names); void pose_apply_restore_fcurves(bAction *action); + +void pose_apply(struct Object *ob, + struct bAction *action, + struct AnimationEvalContext *anim_eval_context, + ActionApplier applier); + } // namespace -void BKE_pose_apply_action(struct Object *ob, - struct bAction *action, - struct AnimationEvalContext *anim_eval_context) +void BKE_pose_apply_action_selected_bones(struct Object *ob, + struct bAction *action, + struct AnimationEvalContext *anim_eval_context) +{ + auto evaluate_and_apply = + [](PointerRNA *ptr, bAction *act, const AnimationEvalContext *anim_eval_context) { + animsys_evaluate_action(ptr, act, anim_eval_context, false); + }; + + pose_apply(ob, action, anim_eval_context, evaluate_and_apply); +} + +void BKE_pose_apply_action_all_bones(struct Object *ob, + struct bAction *action, + struct AnimationEvalContext *anim_eval_context) +{ + PointerRNA pose_owner_ptr; + RNA_id_pointer_create(&ob->id, &pose_owner_ptr); + animsys_evaluate_action(&pose_owner_ptr, action, anim_eval_context, false); +} + +namespace { +void pose_apply(struct Object *ob, + struct bAction *action, + struct AnimationEvalContext *anim_eval_context, + ActionApplier applier) { bPose *pose = ob->pose; if (pose == nullptr) { @@ -67,14 +100,14 @@ void BKE_pose_apply_action(struct Object *ob, /* Apply the Action. */ PointerRNA pose_owner_ptr; RNA_id_pointer_create(&ob->id, &pose_owner_ptr); - animsys_evaluate_action(&pose_owner_ptr, action, anim_eval_context, false); + + applier(&pose_owner_ptr, action, anim_eval_context); if (limit_to_selected_bones) { pose_apply_restore_fcurves(action); } } -namespace { BoneNameSet pose_apply_find_selected_bones(const bArmature *armature, const bPose *pose) { BoneNameSet selected_bone_names; diff --git a/source/blender/makesrna/intern/rna_pose_api.c b/source/blender/makesrna/intern/rna_pose_api.c index 0d35365c2d8..1e1667f0ae8 100644 --- a/source/blender/makesrna/intern/rna_pose_api.c +++ b/source/blender/makesrna/intern/rna_pose_api.c @@ -117,7 +117,7 @@ static void rna_Pose_apply_pose_from_action(ID *pose_owner, Object *pose_owner_ob = (Object *)pose_owner; AnimationEvalContext anim_eval_context = {CTX_data_depsgraph_pointer(C), evaluation_time}; - BKE_pose_apply_action(pose_owner_ob, action, &anim_eval_context); + BKE_pose_apply_action_selected_bones(pose_owner_ob, action, &anim_eval_context); /* Do NOT tag with ID_RECALC_ANIMATION, as that would overwrite the just-applied pose. */ DEG_id_tag_update(pose_owner, ID_RECALC_GEOMETRY); |