Blender V5.3
animrig/intern/armature.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "ANIM_armature.hh"
10
11#include "BKE_action.hh"
12#include "BKE_pose.hh"
13
14#include "BLI_listbase.hh"
15
16#include "DNA_object_types.h"
17
18namespace blender::animrig {
19
21 bPoseChannel &pchan,
22 FunctionRef<void(bPoseChannel &child_bone)> callback)
23{
24 /* Needed for fast name lookups. */
26
27 int i = 0;
28 /* This is not using an std::deque because the implementation of that has issues on windows. */
29 Vector<bPoseChannel *> descendants = {&pchan};
30 while (i < descendants.size()) {
31 bPoseChannel *descendant = descendants[i];
32 i++;
33 callback(*descendant);
34 Bone *descendant_bone = descendant->bone_get(pose_ob);
35 for (Bone &child_bone : descendant_bone->childbase) {
36 bPoseChannel *child_pose_bone = BKE_pose_channel_find_name(pose_ob.pose, child_bone.name);
37 if (!child_pose_bone) {
38 /* Can happen if the pose is not rebuilt. */
40 continue;
41 }
42 descendants.append(child_pose_bone);
43 }
44 }
45};
46
48 bke::PChanBone pchanbone,
49 FunctionRef<bool(bPoseChannel &child_bone)> callback)
50{
51 if (!callback(*pchanbone.pchan)) {
52 return false;
53 }
54 bool success = true;
55 for (Bone &child_bone : pchanbone.bone->childbase) {
56 bPoseChannel *child_pose_bone = BKE_pose_channel_find_name(pose_ob.pose, child_bone.name);
57 if (!child_pose_bone) {
59 success = false;
60 continue;
61 }
62 success &= pose_depth_iterator_recursive(pose_ob, {child_pose_bone, &child_bone}, callback);
63 }
64 return success;
65}
66
68 bPoseChannel &pchan,
69 FunctionRef<bool(bPoseChannel &child_bone)> callback)
70{
71 /* Needed for fast name lookups. */
73 return pose_depth_iterator_recursive(pose_ob, {&pchan, pchan.bone_get(pose_ob)}, callback);
74}
75
76} // namespace blender::animrig
Functions to deal with Armatures.
Blender kernel action and pose functionality.
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
int64_t size() const
void append(const T &value)
static bool pose_depth_iterator_recursive(Object &pose_ob, bke::PChanBone pchanbone, FunctionRef< bool(bPoseChannel &child_bone)> callback)
bool pose_bone_descendent_depth_iterator(Object &pose_ob, bPoseChannel &pchan, FunctionRef< bool(bPoseChannel &child_bone)> callback)
void pose_bone_descendent_iterator(Object &pose_ob, bPoseChannel &pchan, FunctionRef< void(bPoseChannel &child_bone)> callback)
PChanBoneT< bPoseChannel, Bone > PChanBone
Definition BKE_pose.hh:88
void BKE_pose_channels_hash_ensure(bPose *pose) ATTR_NONNULL(1)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
ListBaseT< Bone > childbase
struct bPose * pose
PoseChannelT * pchan
Definition BKE_pose.hh:61