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.
This commit is contained in:
Sybren A. Stüvel 2021-07-12 11:28:15 +02:00
parent b40e05fcd1
commit 9473c61b36
3 changed files with 47 additions and 9 deletions

View File

@ -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]);

View File

@ -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;

View File

@ -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);