diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-07-20 17:13:14 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-07-20 18:12:01 +0300 |
commit | 6754d7aef613ee2eb12baa85b7f99969045c91e2 (patch) | |
tree | fd47349c44d9209b32ed3de8bb1f5684a7907942 /source/blender/blenkernel/intern/armature_pose.cc | |
parent | c4f71f319366eb34e732f05b5162d627a02752c7 (diff) |
Pose Library: remove assumption about Action group names
Remove the assumption of the pose library that Action groups are named
after the bones in the armature. Even though this assumption is correct
when the keys are created by Blender, action groups can be renamed. Keys
created by Python scripts can also use arbitrary group names.
Since there is more code in Blender making this assumption, and looping
over selected bones is also a common occurrence, this commit contains
some generic functionality to aid in this:
- `BKE_armature_find_selected_bones`: function that iterates over all
bones in an armature and calls a callback for each selected one. It
returns a struct with info about the selection states (all or no bones
selected).
- `BKE_armature_find_selected_bone_names(armature)` uses the above
function to return a set of selected bone names.
- `BKE_pose_find_fcurves_with_bones()` calls a callback for each FCurve
in an Action that targets a bone, also passing it the bone name.
Diffstat (limited to 'source/blender/blenkernel/intern/armature_pose.cc')
-rw-r--r-- | source/blender/blenkernel/intern/armature_pose.cc | 56 |
1 files changed, 11 insertions, 45 deletions
diff --git a/source/blender/blenkernel/intern/armature_pose.cc b/source/blender/blenkernel/intern/armature_pose.cc index 2b2268c6302..a62a32d9633 100644 --- a/source/blender/blenkernel/intern/armature_pose.cc +++ b/source/blender/blenkernel/intern/armature_pose.cc @@ -23,8 +23,9 @@ * \ingroup bke */ +#include "BKE_action.hh" #include "BKE_animsys.h" -#include "BKE_armature.h" +#include "BKE_armature.hh" #include "BLI_function_ref.hh" #include "BLI_set.hh" @@ -36,14 +37,14 @@ #include "RNA_access.h" +using namespace blender::bke; + 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); @@ -102,7 +103,7 @@ void pose_apply(struct Object *ob, } const bArmature *armature = (bArmature *)ob->data; - const BoneNameSet selected_bone_names = pose_apply_find_selected_bones(armature, pose); + const BoneNameSet selected_bone_names = BKE_armature_find_selected_bone_names(armature); const bool limit_to_selected_bones = !selected_bone_names.is_empty(); if (limit_to_selected_bones) { @@ -122,30 +123,6 @@ void pose_apply(struct Object *ob, } } -BoneNameSet pose_apply_find_selected_bones(const bArmature *armature, const bPose *pose) -{ - BoneNameSet selected_bone_names; - bool all_bones_selected = true; - bool no_bones_selected = true; - - LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { - const bool is_selected = PBONE_SELECTED(armature, pchan->bone); - all_bones_selected &= is_selected; - no_bones_selected &= !is_selected; - - if (is_selected) { - /* Bone names are unique, so no need to check for duplicates. */ - selected_bone_names.add_new(pchan->name); - } - } - - /* If no bones are selected, act as if all are. */ - if (all_bones_selected || no_bones_selected) { - return BoneNameSet(); /* An empty set means "ignore bone selection". */ - } - return selected_bone_names; -} - void pose_apply_restore_fcurves(bAction *action) { /* TODO(Sybren): Restore the FCurve flags, instead of just erasing the 'disabled' flag. */ @@ -157,24 +134,13 @@ void pose_apply_restore_fcurves(bAction *action) void pose_apply_disable_fcurves_for_unselected_bones(bAction *action, const BoneNameSet &selected_bone_names) { - LISTBASE_FOREACH (FCurve *, fcu, &action->curves) { - if (!fcu->rna_path || !strstr(fcu->rna_path, "pose.bones[")) { - continue; - } - - /* Get bone name, and check if this bone is selected. */ - char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); - if (!bone_name) { - continue; - } - const bool is_selected = selected_bone_names.contains(bone_name); - MEM_freeN(bone_name); - if (is_selected) { - continue; + auto disable_unselected_fcurve = [&](FCurve *fcu, const char *bone_name) { + const bool is_bone_selected = selected_bone_names.contains(bone_name); + if (!is_bone_selected) { + fcu->flag |= FCURVE_DISABLED; } - - fcu->flag |= FCURVE_DISABLED; - } + }; + BKE_action_find_fcurves_with_bones(action, disable_unselected_fcurve); } } // namespace |