42using namespace blender::animrig;
50constexpr auto bonecoll_default_name =
"Bones";
60 if (name ==
nullptr || name[0] ==
'\0') {
62 name =
DATA_(bonecoll_default_name);
70 bcoll->
flags = default_flags;
78 "bone collection still has bones assigned to it, will cause dangling pointers in "
124 [&](
Bone *bone) { bone->runtime.collections.free_no_destruct(); });
136 auto bonecoll_name_is_duplicate = [&](
const StringRef name) ->
bool {
138 if (bcoll_iter != bcoll && bcoll_iter->
name == name) {
146 DATA_(bonecoll_default_name),
149 sizeof(bcoll->
name));
161 BLI_assert(index <= armature->collection_array_num);
185 BLI_assert(at_index <= armature->collection_root_count);
198 const int parent_index)
200 BLI_assert_msg(parent_index >= 0,
"Armature bone collection index should be 0 or larger");
202 "Parent bone collection index should not point beyond the end of the array");
215 return insert_at_index;
220 const int parent_index)
231 if (parent_index < 0) {
297 const int parent_bcoll_dst_index,
301 "this function can only add children to another collection, it cannot add roots");
318 for (
int bcoll_src_index = parent_bcoll_src->
child_index;
319 bcoll_src_index < parent_bcoll_src->child_index + parent_bcoll_src->
child_count;
326 armature_dst, bcoll_dst, parent_bcoll_dst_index);
331 "expecting children to be added to the array AFTER their parent");
333 (void)bcoll_index_dst;
343 BLI_assert_msg(new_parent_bcoll_dst_index == parent_bcoll_dst_index,
344 "did not expect parent_bcoll_dst_index to change");
349 "all children should have been copied");
350 for (
int child_num = 0; child_num < parent_bcoll_dst->
child_count; child_num++) {
351 const int bcoll_src_index = parent_bcoll_src->
child_index + child_num;
352 const int bcoll_dst_index = parent_bcoll_dst->
child_index + child_num;
371 "Armature \"%s\" has library override operation that adds non-root bone collection "
372 "\"%s\". This is unexpected, please file a bug report.\n",
373 armature_src->
id.
name + 2,
374 bcoll_to_copy->
name);
381 const int bcoll_index = anchor_index + 1;
383 bcoll_index <= armature_dst->collection_root_count,
384 "did not expect library override to add a child bone collection, only roots are expected");
405 if (bcoll ==
nullptr) {
445 if (active_name.empty()) {
452 if (bcoll->name == active_name) {
484 const int from_index,
488 from_index == to_index)
501 if (parent_index < 0) {
510 const int old_parent_child_index = parent_bcoll->
child_index;
514 parent_bcoll->
child_index = old_parent_child_index;
520 const int parent_bcoll_index,
521 const int bcoll_index)
523 if (parent_bcoll_index < 0) {
534 const int from_index,
541 if (from_parent_index != to_parent_index) {
549 armature, from_index, to_child_num, from_parent_index, to_parent_index);
553 switch (before_after) {
555 if (to_index > from_index) {
562 if (to_index < from_index) {
577 if (bcoll ==
nullptr) {
582 const int to_index = bcoll_index +
step;
597 char old_name[
sizeof(bcoll->
name)];
601 if (name[0] ==
'\0') {
666 if (parent_bcoll_index >= 0) {
668 armature, parent_bcoll, parent_bcoll_index);
670 "could not find bone collection parent after moving things around");
677 if (parent_bcoll_index < 0) {
698 if (active_collection_index >= 0) {
707 else if (active_collection_index > 0 &&
709 armature, parent_bcoll_index, active_collection_index - 1))
721 const bool is_solo = bcoll->is_solo();
737template<
typename MaybeConstBoneCollection>
741 for (MaybeConstBoneCollection *bcoll : bonecolls) {
742 if (
STREQ(bcoll->name, name)) {
768 for (
BoneCollection *bcoll : armature->collection_children(parent_bcoll)) {
777 if (!parent_bcoll->is_visible_with_ancestors()) {
787 for (
BoneCollection *bcoll : armature->collection_children(parent_bcoll)) {
798 if (parent_bcoll ==
nullptr || parent_bcoll->is_visible_with_ancestors()) {
821 const bool is_visible)
850 bool any_bcoll_solo =
false;
851 for (
const BoneCollection *bcoll : armature->collections_span()) {
853 any_bcoll_solo =
true;
858 if (any_bcoll_solo) {
871 if (is_solo_active) {
873 return bcoll->is_solo();
876 return bcoll->is_visible_with_ancestors();
908 if (member.
bone == bone) {
923 if (ref.
bcoll == bcoll) {
959 bool was_found =
false;
963 if (member.bone == bone) {
974 if (ref.bcoll == bcoll) {
1001 bool was_found =
false;
1005 if (ref.bcoll == bcoll) {
1018 bcoll->bones.free_no_destruct();
1023 for (BoneCollectionReference &ref : bone->runtime.collections) {
1024 add_membership(ref.bcoll, bone);
1030 const ListBaseT<BoneCollectionReference> *collection_refs)
1087 if (bcoll == bcoll_ref.bcoll) {
1097 if (armature->
edbo) {
1150 for (
const BoneCollection *arm_bcoll : armature->collections_span()) {
1151 if (arm_bcoll == bcoll) {
1162 if (bcoll_index < armature->collection_root_count) {
1168 for (
const BoneCollection *potential_parent : armature->collections_span()) {
1169 if (potential_parent->child_index <= bcoll_index &&
1170 bcoll_index < potential_parent->child_index + potential_parent->child_count)
1191 int new_child_number)
1200 if (parent_index < 0) {
1201 parent_bcoll = &fake_armature_parent;
1208 if (new_child_number >= parent_bcoll->
child_count) {
1211 if (new_child_number < 0) {
1217 const int old_parent_child_index = parent_bcoll->
child_index;
1218 const int to_index = parent_bcoll->
child_index + new_child_number;
1221 parent_bcoll->
child_index = old_parent_child_index;
1238 const int potential_parent_index,
1239 const int potential_child_index)
1243 return potential_parent_index == -1;
1245 if (potential_parent_index < 0) {
1252 return potential_parent->
child_index <= potential_child_index &&
1253 potential_child_index < upper_bound;
1257 const int potential_parent_index,
1258 const int potential_descendant_index)
1261 "Potential descendant has to exist for this function call to make sense.");
1272 for (
int visit_index = potential_parent->
child_index; visit_index < upper_bound; visit_index++) {
1297 auto find_old = [bcolls_source](
const char *name,
const int index) ->
const BoneCollection * {
1313 for (
int i = 0; i < bcolls_dest.
size(); i++) {
1326 const int from_bcoll_index,
1328 const int from_parent_index,
1329 const int to_parent_index)
1331 BLI_assert(0 <= from_bcoll_index && from_bcoll_index < armature->collection_array_num);
1332 BLI_assert(-1 <= from_parent_index && from_parent_index < armature->collection_array_num);
1333 BLI_assert(-1 <= to_parent_index && to_parent_index < armature->collection_array_num);
1335 if (from_parent_index == to_parent_index) {
1337 return from_bcoll_index;
1346 armature_root.
flags = default_flags;
1354 BLI_assert_msg(-1 <= to_child_num && to_child_num <= to_parent->child_count,
1355 "to_child_num must point to an index of a child of the new parent, or the index "
1356 "of the last child + 1, or be -1 to indicate 'after last child'");
1357 if (to_child_num < 0) {
1368 to_bcoll_index = to_parent->
child_index + to_child_num;
1373 if (to_bcoll_index > from_bcoll_index) {
1381 const bool needs_post_move_child_index_bump = from_parent->
child_index == from_bcoll_index &&
1382 to_bcoll_index <= from_bcoll_index;
1385 const bool becomes_new_first_child = to_child_num == 0 || to_parent->
child_count == 0;
1394 else if (needs_post_move_child_index_bump) {
1405 if (becomes_new_first_child) {
1417 return to_bcoll_index;
1424 int *bcoll_array_dst_num,
1426 const int bcoll_array_src_num,
1427 const bool do_id_user)
1433 *bcoll_array_dst_num = bcoll_array_src_num;
1436 for (
int i = 0; i < bcoll_array_src_num; i++) {
1441 bcoll_dst->
bones.clear_no_delete();
1443 if (bcoll_src->
prop) {
1452 (*bcoll_array_dst)[i] = bcoll_dst;
1454 bcoll_map.
add(bcoll_src, bcoll_dst);
1461 int *bcoll_array_num,
1462 const bool do_id_user)
1464 for (
int i = 0; i < *bcoll_array_num; i++) {
1479 bcoll->
bones.free_no_destruct();
1483 MEM_SAFE_DELETE(*bcoll_array);
1485 *bcoll_array_num = 0;
1492 const int start_index,
1494 const int direction)
1512 const int move_from_index = (direction > 0 ? start_index + count : start_index - 1);
1513 const int move_to_index = (direction > 0 ? start_index : start_index + count - 1);
1517 memmove(
static_cast<void *
>(start + direction),
1518 static_cast<void *
>(start),
1527 if (bcoll->child_index == 0 && bcoll->child_count == 0) {
1533 if (start_index <= bcoll->child_index && bcoll->child_index < start_index + count) {
1534 bcoll->child_index += direction;
1540 if (active_index == move_from_index) {
1543 else if (start_index <= active_index && active_index < start_index + count) {
1550 if (from_index == to_index) {
1555 BLI_assert(from_index < armature->collection_array_num);
1557 BLI_assert(to_index < armature->collection_array_num);
1559 if (from_index < to_index) {
1560 const int block_start_index = from_index + 1;
1561 const int block_count = to_index - from_index;
1565 const int block_start_index = to_index;
1566 const int block_count = from_index - to_index;
1575 if (collections[
index] == bcoll) {
1578 if (
index > 0 && collections[
index - 1] == bcoll) {
1589 printf(
"\033[38;5;214mBone collections of armature \"%s\":\033[0m\n", armature->
id.
name + 2);
1590 constexpr int root_ansi_color = 95;
1595 printf(
" - \033[%dmcolls[%d] = %24s\033[0m ",
1596 i < armature->collection_root_count ? root_ansi_color : 0,
1615 if (armature->
edbo) {
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
#define STRNCPY_UTF8(dst, src)
#define ID_IS_LINKED(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
Read Blender memory allocation and freeing.
#define ND_BONE_COLLECTION
#define BLI_assert_msg(a, msg)
Internal C++ functions to deal with bone collections. These are mostly here for internal use in bone_...
bool add(const Key &key, const Value &value)
constexpr int64_t size() const
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
void bonecolls_rotate_block(bArmature *armature, const int start_index, const int count, const int direction)
void bonecolls_debug_list(const bArmature *armature)
void bonecoll_unassign_and_free(bArmature *armature, BoneCollection *bcoll)
int bonecolls_find_index_near(bArmature *armature, BoneCollection *bcoll, const int index)
void bonecolls_move_to_index(bArmature *armature, const int from_index, const int to_index)
static void ANIM_armature_foreach_bone(ListBaseT< Bone > *bones, CB callback)
int armature_bonecoll_find_index(const bArmature *armature, const BoneCollection *bcoll)
bool armature_bonecoll_is_root(const bArmature *armature, int bcoll_index)
void bonecolls_copy_expanded_flag(Span< BoneCollection * > bcolls_dest, Span< const BoneCollection * > bcolls_source)
Map< BoneCollection *, BoneCollection * > ANIM_bonecoll_array_copy_no_membership(BoneCollection ***bcoll_array_dst, int *bcoll_array_dst_num, BoneCollection **bcoll_array_src, int bcoll_array_src_num, bool do_id_user)
bool bonecoll_has_children(const BoneCollection *bcoll)
int armature_bonecoll_child_number_set(bArmature *armature, BoneCollection *bcoll, int new_child_number)
bool armature_bonecoll_is_descendant_of(const bArmature *armature, int potential_parent_index, int potential_descendant_index)
int armature_bonecoll_find_parent_index(const bArmature *armature, int bcoll_index)
int armature_bonecoll_child_number_find(const bArmature *armature, const BoneCollection *bcoll)
void ANIM_bonecoll_array_free(BoneCollection ***bcoll_array, int *bcoll_array_num, bool do_id_user)
int armature_bonecoll_move_to_parent(bArmature *armature, int from_bcoll_index, int to_child_num, int from_parent_index, int to_parent_index)
bool armature_bonecoll_is_child_of(const bArmature *armature, int potential_parent_index, int potential_child_index)
void WM_main_add_notifier(uint type, void *reference)
void ANIM_armature_runtime_free(bArmature *armature)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ANIM_bonecoll_show(bArmature *armature, BoneCollection *bcoll)
void ANIM_armature_bonecoll_is_expanded_set(BoneCollection *bcoll, bool is_expanded)
void IDP_FreeProperty_ex(IDProperty *prop, bool do_id_user)
bool ANIM_armature_bonecoll_assign(BoneCollection *bcoll, Bone *bone)
char * STRNCPY(char(&dst)[N], const char *src)
bool ANIM_armature_bonecoll_assign_editbone(BoneCollection *bcoll, EditBone *ebone)
static BoneCollection * copy_and_update_ownership(const bArmature *armature_dst, const BoneCollection *bcoll_to_copy)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void armature_bonecoll_active_clear(bArmature *armature)
void ANIM_armature_bonecoll_active_index_set(bArmature *armature, int bone_collection_index)
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
BoneCollection * ANIM_armature_bonecoll_new(bArmature *armature, const char *name, int parent_index=-1)
std::string RNA_path_name_to_infix(const StringRefNull string)
static void bonecoll_ensure_name_unique(bArmature *armature, BoneCollection *bcoll)
void ANIM_armature_bonecoll_remove(bArmature *armature, BoneCollection *bcoll)
bool ANIM_bone_in_visible_collection(const bArmature *armature, const Bone *bone)
bool ANIM_armature_bonecoll_assign_and_move(BoneCollection *bcoll, Bone *bone)
BoneCollection * ANIM_bonecoll_new(const char *name) ATTR_WARN_UNUSED_RESULT
void ANIM_armature_bonecoll_active_runtime_refresh(bArmature *armature)
void ANIM_bonecoll_free(BoneCollection *bcoll, bool do_id_user_count=true)
bool BKE_lib_override_library_is_system_defined(const Main *bmain, const ID *id)
static bool any_bone_collection_visible(const bArmature *armature, const ListBaseT< BoneCollectionReference > *collection_refs)
static void bonecoll_insert_as_root(bArmature *armature, BoneCollection *bcoll, int at_index)
@ LIB_ID_CREATE_NO_USER_REFCOUNT
void ANIM_armature_bonecoll_hide_all(bArmature *armature)
void ANIM_armature_refresh_solo_active(bArmature *armature)
void BKE_animdata_fix_paths(ID &id, StringRef prefix, StringRef old_infix, StringRef new_infix, bool verify_paths, const DriverMap &driver_map)
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
static bool bcoll_list_contains(const ListBaseT< BoneCollectionReference > *collection_refs, const BoneCollection *bcoll)
BoneCollection * ANIM_armature_bonecoll_insert_copy_after(bArmature *armature_dst, const bArmature *armature_src, const BoneCollection *anchor_in_dst, const BoneCollection *bcoll_to_copy)
static void ancestors_visible_update(bArmature *armature, const BoneCollection *parent_bcoll, BoneCollection *bcoll)
void ANIM_armature_bonecoll_unassign_all(Bone *bone)
static void ancestors_visible_descendants_clear(bArmature *armature, BoneCollection *parent_bcoll)
void ANIM_armature_bonecoll_reconstruct(bArmature *armature)
static MaybeConstBoneCollection * bonecolls_get_by_name(Span< MaybeConstBoneCollection * > bonecolls, const char *name)
bool ANIM_armature_bonecoll_unassign_editbone(BoneCollection *bcoll, EditBone *ebone)
bool ANIM_bonecoll_is_visible_editbone(const bArmature *armature, const EditBone *ebone)
BoneCollection * ANIM_armature_bonecoll_get_by_name(bArmature *armature, const char *name) ATTR_WARN_UNUSED_RESULT
static void bonecoll_insert_at_index(bArmature *armature, BoneCollection *bcoll, const int index)
DriverMap BKE_animdata_build_driver_target_map(Main &bmain)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void ANIM_armature_bonecoll_remove_from_index(bArmature *armature, const int index)
bool ANIM_armature_bonecoll_contains_active_bone(const bArmature *armature, const BoneCollection *bcoll)
void ANIM_bonecoll_hide(bArmature *armature, BoneCollection *bcoll)
static void liboverride_recursively_add_children(bArmature *armature_dst, const bArmature *armature_src, const int parent_bcoll_dst_index, const BoneCollection *parent_bcoll_src)
void ANIM_armature_bonecoll_active_name_set(bArmature *armature, const char *name)
static void add_reverse_pointers(BoneCollection *bcoll)
bool ANIM_armature_bonecoll_assign_and_move_editbone(BoneCollection *bcoll, EditBone *ebone)
void ANIM_armature_bonecoll_show_all(bArmature *armature)
void ANIM_armature_bonecoll_show_from_ebone(bArmature *armature, const EditBone *ebone)
int ANIM_armature_bonecoll_get_index_by_name(bArmature *armature, const char *name) ATTR_WARN_UNUSED_RESULT
static int bonecoll_child_number(const bArmature *armature, const int parent_bcoll_index, const int bcoll_index)
void ANIM_armature_bonecoll_show_from_pchan(bArmature *armature, const bPoseChannel *pchan)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static void add_membership(BoneCollection *bcoll, Bone *bone)
void ANIM_armature_bonecoll_assign_from_other_editbone(EditBone *dst, EditBone *src)
void ANIM_armature_bonecoll_active_set(bArmature *armature, BoneCollection *bcoll)
void ANIM_armature_bonecoll_assign_active(const bArmature *armature, EditBone *ebone)
static void ancestors_visible_descendants_update(bArmature *armature, BoneCollection *parent_bcoll)
static int bonecoll_insert_as_child(bArmature *armature, BoneCollection *bcoll, const int parent_index)
static void add_reference(Bone *bone, BoneCollection *bcoll)
void ANIM_armature_bonecoll_name_set(Main &bmain, bArmature *armature, BoneCollection *bcoll, const char *name)
Map< ID *, Vector< DriverTarget * > > DriverMap
@ BONE_COLLECTION_OVERRIDE_LIBRARY_LOCAL
@ BONE_COLLECTION_SELECTABLE
@ BONE_COLLECTION_EXPANDED
@ BONE_COLLECTION_VISIBLE
@ BONE_COLLECTION_ANCESTORS_VISIBLE
void ANIM_armature_runtime_refresh(bArmature *armature)
bool ANIM_armature_bonecoll_unassign(BoneCollection *bcoll, Bone *bone)
bool ANIM_armature_bonecoll_move_to_index(bArmature *armature, int from_index, int to_index)
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void ANIM_armature_bonecoll_is_visible_set(bArmature *armature, BoneCollection *bcoll, bool is_visible)
void *(*) MEM_realloc_uninitialized_id(void *vmemh, size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(2)
int ANIM_armature_bonecoll_move_before_after_index(bArmature *armature, int from_index, int to_index, MoveLocation before_after)
bool ANIM_armature_bonecoll_is_visible_effectively(const bArmature *armature, const BoneCollection *bcoll)
bool ANIM_armature_bonecoll_move(bArmature *armature, BoneCollection *bcoll, int step)
Bone * BKE_armature_find_bone_name(bArmature *arm, const char *name)
void ANIM_armature_bonecoll_solo_set(bArmature *armature, BoneCollection *bcoll, bool is_solo)
bool ANIM_armature_bonecoll_is_editable(const bArmature *armature, const BoneCollection *bcoll)
void ANIM_armature_bonecoll_show_from_bone(bArmature *armature, const Bone *bone)
void ANIM_armature_bonecoll_unassign_all_editbone(EditBone *ebone)
struct BoneCollection * bcoll
eBoneCollection_Flag flags
struct IDProperty * system_properties
ListBaseT< BoneCollectionMember > bones
ListBaseT< BoneCollectionReference > collections
ListBaseT< BoneCollectionReference > bone_collections
ListBaseT< EditBone > * edbo
struct EditBone * act_edbone
bke::bArmature_Runtime * runtime
char active_collection_name[64]
ListBaseT< Bone > bonebase
struct BoneCollection ** collection_array
int collection_root_count
int active_collection_index
BoneCollection * active_collection