Blender V4.3
ANIM_bone_collections.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#pragma once
12
13#ifndef __cplusplus
14# error This is a C++ header.
15#endif
16
17#include <stdbool.h>
18
19#include "BLI_map.hh"
20#include "BLI_math_bits.h"
21
22#include "BKE_armature.hh"
23
24#include "DNA_action_types.h"
25#include "DNA_armature_types.h"
26
27struct bArmature;
28struct Bone;
29struct BoneCollection;
30struct bPoseChannel;
31struct EditBone;
32
44
56void ANIM_bonecoll_free(BoneCollection *bcoll, bool do_id_user_count = true);
57
64
70
80 const char *name,
81 int parent_index = -1);
82
93 const bArmature *armature_src,
94 const BoneCollection *anchor_in_dst,
95 const BoneCollection *bcoll_to_copy);
96
100void ANIM_armature_bonecoll_remove_from_index(bArmature *armature, const int index);
101
106
116
122void ANIM_armature_bonecoll_active_index_set(bArmature *armature, int bone_collection_index);
123
130void ANIM_armature_bonecoll_active_name_set(bArmature *armature, const char *name);
131
142
149bool ANIM_armature_bonecoll_is_editable(const bArmature *armature, const BoneCollection *bcoll);
150
177bool ANIM_armature_bonecoll_move_to_index(bArmature *armature, int from_index, int to_index);
178
179enum class MoveLocation {
180 Before, /* Move to before the item at the given index. */
181 After, /* Move to after the item at the given index. */
182};
183
185 int from_index,
186 int to_index,
187 MoveLocation before_after);
188
200bool ANIM_armature_bonecoll_move(bArmature *armature, BoneCollection *bcoll, int step);
201
203 const char *name) ATTR_WARN_UNUSED_RESULT;
204
210 const char *name) ATTR_WARN_UNUSED_RESULT;
211
212void ANIM_armature_bonecoll_name_set(bArmature *armature, BoneCollection *bcoll, const char *name);
213
219void ANIM_bonecoll_show(bArmature *armature, BoneCollection *bcoll);
220
226void ANIM_bonecoll_hide(bArmature *armature, BoneCollection *bcoll);
227
239 BoneCollection *bcoll,
240 bool is_visible);
241
245void ANIM_armature_bonecoll_solo_set(bArmature *armature, BoneCollection *bcoll, bool is_solo);
246
251
257 const BoneCollection *bcoll);
258
262void ANIM_armature_bonecoll_is_expanded_set(BoneCollection *bcoll, bool is_expanded);
263
280
281/* Assign the edit bone to the armature's active collection. */
283
288 const BoneCollection *bcoll);
289
297
298/*
299 * Armature/Bone Layer abstractions. These functions are intended as the sole
300 * accessors for `bone->layer`, `armature->layer`, etc. to get a grip on which
301 * queries & operations are performed.
302 *
303 * The functions are named "bonecoll" (short for "bone collection"), as that's
304 * the soon-to-be-introduced replacement for armature layers. This API is the
305 * first step towards replacement.
306 */
307
309bool ANIM_bone_in_visible_collection(const bArmature *armature, const Bone *bone);
310
311inline bool ANIM_bone_is_visible(const bArmature *armature, const Bone *bone)
312{
313 const bool bone_itself_visible = (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0;
314 return bone_itself_visible && ANIM_bone_in_visible_collection(armature, bone);
315}
316
317bool ANIM_bonecoll_is_visible_editbone(const bArmature *armature, const EditBone *ebone);
318
319inline bool ANIM_bone_is_visible_editbone(const bArmature *armature, const EditBone *ebone)
320{
321 const bool bone_itself_visible = (ebone->flag & BONE_HIDDEN_A) == 0;
322 return bone_itself_visible && ANIM_bonecoll_is_visible_editbone(armature, ebone);
323}
324
325inline bool ANIM_bonecoll_is_visible_pchan(const bArmature *armature, const bPoseChannel *pchan)
326{
327 return ANIM_bone_in_visible_collection(armature, pchan->bone);
328}
329
330inline bool ANIM_bonecoll_is_visible_actbone(const bArmature *armature)
331{
332 return ANIM_bone_in_visible_collection(armature, armature->act_bone);
333}
334
337
341
342namespace blender::animrig {
343
348int armature_bonecoll_find_index(const bArmature *armature, const ::BoneCollection *bcoll);
349
353int armature_bonecoll_find_parent_index(const bArmature *armature, int bcoll_index);
354
363int armature_bonecoll_child_number_find(const bArmature *armature, const ::BoneCollection *bcoll);
364
374 ::BoneCollection *bcoll,
375 int new_child_number);
376
377bool armature_bonecoll_is_root(const bArmature *armature, int bcoll_index);
378
379bool armature_bonecoll_is_child_of(const bArmature *armature,
380 int potential_parent_index,
381 int potential_child_index);
382
384 int potential_parent_index,
385 int potential_descendant_index);
386
387bool bonecoll_has_children(const BoneCollection *bcoll);
388
397 Span<const BoneCollection *> bcolls_source);
398
413 int from_bcoll_index,
414 int to_child_num,
415 int from_parent_index,
416 int to_parent_index);
417
418/* --------------------------------------------------------------------
419 * The following functions are only used by edit-mode Armature undo:
420 */
421
450 BoneCollection ***bcoll_array_dst,
451 int *bcoll_array_dst_num,
452 BoneCollection **bcoll_array_src,
453 int bcoll_array_src_num,
454 bool do_id_user);
472void ANIM_bonecoll_array_free(BoneCollection ***bcoll_array,
473 int *bcoll_array_num,
474 bool do_id_user);
475
476} // namespace blender::animrig
void ANIM_armature_bonecoll_unassign_all_editbone(EditBone *ebone)
void ANIM_armature_refresh_solo_active(bArmature *armature)
void ANIM_armature_runtime_free(bArmature *armature)
bool ANIM_armature_bonecoll_assign_and_move(BoneCollection *bcoll, Bone *bone)
void ANIM_armature_bonecoll_active_set(bArmature *armature, BoneCollection *bcoll)
void ANIM_armature_bonecoll_hide_all(bArmature *armature)
bool ANIM_armature_bonecoll_is_editable(const bArmature *armature, 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)
bool ANIM_armature_bonecoll_assign_and_move_editbone(BoneCollection *bcoll, EditBone *ebone)
void ANIM_armature_bonecoll_is_expanded_set(BoneCollection *bcoll, bool is_expanded)
int ANIM_armature_bonecoll_move_before_after_index(bArmature *armature, int from_index, int to_index, MoveLocation before_after)
void ANIM_bonecoll_hide(bArmature *armature, BoneCollection *bcoll)
void ANIM_armature_runtime_refresh(bArmature *armature)
void ANIM_armature_bonecoll_active_name_set(bArmature *armature, const char *name)
void ANIM_armature_bonecoll_show_from_ebone(bArmature *armature, const EditBone *ebone)
void ANIM_armature_bonecoll_show_from_bone(bArmature *armature, const Bone *bone)
bool ANIM_bone_is_visible_editbone(const bArmature *armature, const EditBone *ebone)
bool ANIM_bone_is_visible(const bArmature *armature, const Bone *bone)
bool ANIM_bonecoll_is_visible_editbone(const bArmature *armature, const EditBone *ebone)
BoneCollection * ANIM_bonecoll_new(const char *name) ATTR_WARN_UNUSED_RESULT
bool ANIM_armature_bonecoll_unassign_editbone(BoneCollection *bcoll, EditBone *ebone)
void ANIM_bonecoll_free(BoneCollection *bcoll, bool do_id_user_count=true)
void ANIM_armature_bonecoll_assign_active(const bArmature *armature, EditBone *ebone)
bool ANIM_armature_bonecoll_assign(BoneCollection *bcoll, Bone *bone)
void ANIM_armature_bonecoll_remove(bArmature *armature, BoneCollection *bcoll)
bool ANIM_armature_bonecoll_unassign(BoneCollection *bcoll, Bone *bone)
void ANIM_armature_bonecoll_unassign_all(Bone *bone)
void ANIM_bonecoll_show(bArmature *armature, BoneCollection *bcoll)
bool ANIM_armature_bonecoll_move_to_index(bArmature *armature, int from_index, int to_index)
void ANIM_armature_bonecoll_remove_from_index(bArmature *armature, const int index)
void ANIM_armature_bonecoll_show_from_pchan(bArmature *armature, const bPoseChannel *pchan)
bool ANIM_bonecoll_is_visible_pchan(const bArmature *armature, const bPoseChannel *pchan)
void ANIM_armature_bonecoll_active_runtime_refresh(bArmature *armature)
bool ANIM_armature_bonecoll_is_visible_effectively(const bArmature *armature, const BoneCollection *bcoll)
void ANIM_armature_bonecoll_name_set(bArmature *armature, BoneCollection *bcoll, const char *name)
void ANIM_armature_bonecoll_solo_set(bArmature *armature, BoneCollection *bcoll, bool is_solo)
int ANIM_armature_bonecoll_get_index_by_name(bArmature *armature, const char *name) ATTR_WARN_UNUSED_RESULT
void ANIM_armature_bonecoll_show_all(bArmature *armature)
bool ANIM_armature_bonecoll_move(bArmature *armature, BoneCollection *bcoll, int step)
BoneCollection * ANIM_armature_bonecoll_new(bArmature *armature, const char *name, int parent_index=-1)
void ANIM_armature_bonecoll_reconstruct(bArmature *armature)
bool ANIM_bonecoll_is_visible_actbone(const bArmature *armature)
bool ANIM_armature_bonecoll_contains_active_bone(const bArmature *armature, const BoneCollection *bcoll)
bool ANIM_bone_in_visible_collection(const bArmature *armature, const Bone *bone)
void ANIM_armature_bonecoll_is_visible_set(bArmature *armature, BoneCollection *bcoll, bool is_visible)
BoneCollection * ANIM_armature_bonecoll_get_by_name(bArmature *armature, const char *name) ATTR_WARN_UNUSED_RESULT
bool ANIM_armature_bonecoll_assign_editbone(BoneCollection *bcoll, EditBone *ebone)
void ANIM_armature_bonecoll_active_index_set(bArmature *armature, int bone_collection_index)
#define ATTR_WARN_UNUSED_RESULT
@ BONE_HIDDEN_A
@ BONE_HIDDEN_P
@ BONE_HIDDEN_PG
blender::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 armature_bonecoll_is_root(const bArmature *armature, int bcoll_index)
void bonecolls_copy_expanded_flag(Span< BoneCollection * > bcolls_dest, Span< const BoneCollection * > bcolls_source)
int armature_bonecoll_child_number_find(const bArmature *armature, const ::BoneCollection *bcoll)
bool bonecoll_has_children(const BoneCollection *bcoll)
int armature_bonecoll_find_index(const bArmature *armature, const ::BoneCollection *bcoll)
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_set(bArmature *armature, ::BoneCollection *bcoll, int new_child_number)
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)
Bone * bone
EditBone * ebone
struct Bone * bone