Blender V5.0
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 <deque>
10
11#include "ANIM_armature.hh"
12#include "BKE_action.hh"
13#include "BLI_listbase.h"
14
15namespace blender::animrig {
16
18 bPoseChannel &pose_bone,
19 FunctionRef<void(bPoseChannel &child_bone)> callback)
20{
21 /* Needed for fast name lookups. */
23
24 int i = 0;
25 /* This is not using an std::deque because the implementation of that has issues on windows. */
26 Vector<bPoseChannel *> descendants = {&pose_bone};
27 while (i < descendants.size()) {
28 bPoseChannel *descendant = descendants[i];
29 i++;
30 callback(*descendant);
31 LISTBASE_FOREACH (Bone *, child_bone, &descendant->bone->childbase) {
32 bPoseChannel *child_pose_bone = BKE_pose_channel_find_name(&pose, child_bone->name);
33 if (!child_pose_bone) {
34 /* Can happen if the pose is not rebuilt. */
36 continue;
37 }
38 descendants.append(child_pose_bone);
39 }
40 }
41};
42
44 bPoseChannel &pose_bone,
45 FunctionRef<bool(bPoseChannel &child_bone)> callback)
46{
47 if (!callback(pose_bone)) {
48 return false;
49 }
50 if (!pose_bone.bone) {
52 return false;
53 }
54 bool success = true;
55 LISTBASE_FOREACH (Bone *, child_bone, &pose_bone.bone->childbase) {
56 bPoseChannel *child_pose_bone = BKE_pose_channel_find_name(&pose, child_bone->name);
57 if (!child_pose_bone) {
59 success = false;
60 continue;
61 }
62 success &= pose_depth_iterator_recursive(pose, *child_pose_bone, callback);
63 }
64 return success;
65}
66
68 bPoseChannel &pose_bone,
69 FunctionRef<bool(bPoseChannel &child_bone)> callback)
70{
71 /* Needed for fast name lookups. */
73 return pose_depth_iterator_recursive(pose, pose_bone, callback);
74}
75
76} // namespace blender::animrig
Functions to deal with Armatures.
Blender kernel action and pose functionality.
void BKE_pose_channels_hash_ensure(bPose *pose) ATTR_NONNULL(1)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define LISTBASE_FOREACH(type, var, list)
int64_t size() const
void append(const T &value)
void pose_bone_descendent_iterator(bPose &pose, bPoseChannel &pose_bone, FunctionRef< void(bPoseChannel &child_bone)> callback)
static bool pose_depth_iterator_recursive(bPose &pose, bPoseChannel &pose_bone, FunctionRef< bool(bPoseChannel &child_bone)> callback)
bool pose_bone_descendent_depth_iterator(bPose &pose, bPoseChannel &pose_bone, FunctionRef< bool(bPoseChannel &child_bone)> callback)
ListBase childbase
struct Bone * bone
i
Definition text_draw.cc:230