diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt index b8c18d6929a..9c16149255a 100644 --- a/source/blender/CMakeLists.txt +++ b/source/blender/CMakeLists.txt @@ -131,6 +131,7 @@ set(SRC_DNA_DEFAULTS_INC add_subdirectory(datatoc) add_subdirectory(editors) add_subdirectory(windowmanager) +add_subdirectory(animrig) add_subdirectory(asset_system) add_subdirectory(blenkernel) add_subdirectory(blenlib) diff --git a/source/blender/animrig/ANIM_bone_collections.h b/source/blender/animrig/ANIM_bone_collections.h new file mode 100644 index 00000000000..3506f5c0610 --- /dev/null +++ b/source/blender/animrig/ANIM_bone_collections.h @@ -0,0 +1,83 @@ +/* SPDX-FileCopyrightText: 2023 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup animrig + * + * \brief Functions to deal with Armature collections (i.e. the successor of bone layers). + */ + +#pragma once + +#include + +#include "BLI_math_bits.h" + +#include "BKE_armature.h" + +#include "DNA_action_types.h" +#include "DNA_armature_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct bArmature; +struct Bone; +struct bPoseChannel; +struct EditBone; + +/** + * Armature/Bone Layer abstractions. These functions are intended as the sole + * accessors for `bone->layer`, `armature->layer`, etc. to get a grip on which + * queries & operations are performed. + * + * The functions are named "bonecoll" (short for "bone collection"), as that's + * the soon-to-be-introduced replacement for armature layers. This API is the + * first step towards replacement. + */ + +inline bool ANIM_bonecoll_is_visible(const struct bArmature *armature, const struct Bone *bone) +{ + return armature->layer & bone->layer; +} + +inline bool ANIM_bone_is_visible(const struct bArmature *armature, const struct Bone *bone) +{ + const bool bone_itself_visible = (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0; + return bone_itself_visible && ANIM_bonecoll_is_visible(armature, bone); +} + +inline bool ANIM_bonecoll_is_visible_editbone(const struct bArmature *armature, + const struct EditBone *ebone) +{ + return armature->layer & ebone->layer; +} + +inline bool ANIM_bonecoll_is_visible_pchan(const struct bArmature *armature, + const struct bPoseChannel *pchan) +{ + return ANIM_bonecoll_is_visible(armature, pchan->bone); +} + +inline bool ANIM_bonecoll_is_visible_actbone(const struct bArmature *armature) +{ + return ANIM_bonecoll_is_visible(armature, armature->act_bone); +} + +void ANIM_armature_enable_layers(struct bArmature *armature, const int layers); +void ANIM_armature_disable_all_layers(struct bArmature *armature); +void ANIM_bone_set_layer_ebone(struct EditBone *ebone, int layer); +void ANIM_bone_set_ebone_layer_from_armature(struct EditBone *ebone, + const struct bArmature *armature); +void ANIM_armature_ensure_first_layer_enabled(struct bArmature *armature); +void ANIM_armature_ensure_layer_enabled_from_bone(struct bArmature *armature, + const struct Bone *bone); +void ANIM_armature_ensure_layer_enabled_from_ebone(struct bArmature *armature, + const struct EditBone *ebone); +void ANIM_armature_ensure_layer_enabled_from_pchan(struct bArmature *armature, + const struct bPoseChannel *pchan); +#ifdef __cplusplus +} +#endif diff --git a/source/blender/animrig/CMakeLists.txt b/source/blender/animrig/CMakeLists.txt new file mode 100644 index 00000000000..5caa531b998 --- /dev/null +++ b/source/blender/animrig/CMakeLists.txt @@ -0,0 +1,39 @@ +# SPDX-FileCopyrightText: 2023 Blender Foundation +# +# SPDX-License-Identifier: GPL-2.0-or-later + +set(INC + PUBLIC . + intern + + ../blenkernel +) + +set(INC_SYS +) + +set(SRC + intern/bone_collections.cc + + ANIM_bone_collections.h +) + +set(LIB + bf_blenkernel + bf::blenlib + bf::dna +) + + +blender_add_lib(bf_animrig "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +add_library(bf::animrig ALIAS bf_animrig) + +# if(WITH_GTESTS) +# set(TEST_SRC +# ) +# set(TEST_LIB +# PRIVATE bf::animrig +# ) +# include(GTestTesting) +# blender_add_test_lib(bf_animrig_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}") +# endif() diff --git a/source/blender/animrig/intern/bone_collections.cc b/source/blender/animrig/intern/bone_collections.cc new file mode 100644 index 00000000000..00d9d296754 --- /dev/null +++ b/source/blender/animrig/intern/bone_collections.cc @@ -0,0 +1,62 @@ +/* SPDX-FileCopyrightText: 2023 Blender Foundation + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup animrig + */ + +#include "DNA_armature_types.h" + +#include "BLI_math_bits.h" + +#include "ANIM_bone_collections.h" + +/* ********************************* */ +/* Armature Layers transitional API. */ + +void ANIM_armature_enable_layers(bArmature *armature, const int layers) +{ + armature->layer |= layers; +} + +void ANIM_armature_disable_all_layers(bArmature *armature) +{ + armature->layer = 0; +} + +void ANIM_bone_set_layer_ebone(EditBone *ebone, const int layer) +{ + ebone->layer = layer; +} + +void ANIM_bone_set_ebone_layer_from_armature(EditBone *ebone, const bArmature *armature) +{ + ebone->layer = armature->layer; +} + +void ANIM_armature_ensure_first_layer_enabled(bArmature *armature) +{ + armature->layer = 1; +} + +void ANIM_armature_ensure_layer_enabled_from_bone(bArmature *armature, const Bone *bone) +{ + if (ANIM_bonecoll_is_visible(armature, bone)) { + return; + } + armature->layer |= 1U << bitscan_forward_uint(bone->layer); +} + +void ANIM_armature_ensure_layer_enabled_from_ebone(bArmature *armature, const EditBone *ebone) +{ + if (ANIM_bonecoll_is_visible_editbone(armature, ebone)) { + return; + } + armature->layer |= 1U << bitscan_forward_uint(ebone->layer); +} + +void ANIM_armature_ensure_layer_enabled_from_pchan(bArmature *armature, const bPoseChannel *pchan) +{ + ANIM_armature_ensure_layer_enabled_from_bone(armature, pchan->bone); +} diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 9e981cc7bff..8f72b0dc8b2 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -814,6 +814,7 @@ endforeach() blender_add_lib(bf_draw_shaders "${GLSL_C}" "" "" "") list(APPEND LIB + PRIVATE bf::animrig bf_draw_shaders ) diff --git a/source/blender/draw/engines/overlay/overlay_armature.cc b/source/blender/draw/engines/overlay/overlay_armature.cc index dc016b65a60..aff5c4be08f 100644 --- a/source/blender/draw/engines/overlay/overlay_armature.cc +++ b/source/blender/draw/engines/overlay/overlay_armature.cc @@ -35,6 +35,8 @@ #include "ED_armature.h" #include "ED_view3d.h" +#include "ANIM_bone_collections.h" + #include "UI_resources.h" #include "draw_common.h" @@ -2560,7 +2562,7 @@ static void draw_armature_edit(const ArmatureDrawContext *ctx) eBone; eBone = eBone->next, index += 0x10000) { - if ((eBone->layer & arm->layer) == 0) { + if (!ANIM_bonecoll_is_visible_editbone(arm, eBone)) { continue; } if (eBone->flag & BONE_HIDDEN_A) { diff --git a/source/blender/editors/animation/CMakeLists.txt b/source/blender/editors/animation/CMakeLists.txt index 97c11770259..dc220e79355 100644 --- a/source/blender/editors/animation/CMakeLists.txt +++ b/source/blender/editors/animation/CMakeLists.txt @@ -44,6 +44,7 @@ set(SRC set(LIB bf_blenkernel + PRIVATE bf::animrig PRIVATE bf::blenlib PRIVATE bf::dna PRIVATE bf::intern::guardedalloc diff --git a/source/blender/editors/animation/anim_filter.cc b/source/blender/editors/animation/anim_filter.cc index d0d6ac6ad48..7392a2556e4 100644 --- a/source/blender/editors/animation/anim_filter.cc +++ b/source/blender/editors/animation/anim_filter.cc @@ -89,6 +89,8 @@ #include "SEQ_sequencer.h" #include "SEQ_utils.h" +#include "ANIM_bone_collections.h" + #include "UI_resources.h" /* for TH_KEYFRAME_SCALE lookup */ /* ************************************************************ */ @@ -1038,7 +1040,7 @@ static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id bArmature *arm = (bArmature *)ob->data; /* skipping - not visible on currently visible layers */ - if ((arm->layer & pchan->bone->layer) == 0) { + if (!ANIM_bonecoll_is_visible_pchan(arm, pchan)) { return true; } /* skipping - is currently hidden */ diff --git a/source/blender/editors/animation/anim_motion_paths.cc b/source/blender/editors/animation/anim_motion_paths.cc index 36041b1b66d..ba32d91eb4d 100644 --- a/source/blender/editors/animation/anim_motion_paths.cc +++ b/source/blender/editors/animation/anim_motion_paths.cc @@ -33,6 +33,8 @@ #include "ED_anim_api.h" #include "ED_keyframes_keylist.h" +#include "ANIM_bone_collections.h" + #include "CLG_log.h" static CLG_LogRef LOG = {"ed.anim.motion_paths"}; @@ -112,7 +114,7 @@ void animviz_get_object_motionpaths(Object *ob, ListBase *targets) for (pchan = static_cast(ob->pose->chanbase.first); pchan; pchan = pchan->next) { - if ((pchan->bone) && (arm->layer & pchan->bone->layer) && (pchan->mpath)) { + if ((pchan->bone) && ANIM_bonecoll_is_visible_pchan(arm, pchan) && (pchan->mpath)) { /* new target for bone */ mpt = static_cast(MEM_callocN(sizeof(MPathTarget), "MPathTarget PoseBone")); BLI_addtail(targets, mpt); diff --git a/source/blender/editors/animation/keyframing.cc b/source/blender/editors/animation/keyframing.cc index e4717d717b4..51e0fb3bacd 100644 --- a/source/blender/editors/animation/keyframing.cc +++ b/source/blender/editors/animation/keyframing.cc @@ -57,6 +57,8 @@ #include "ED_object.h" #include "ED_screen.h" +#include "ANIM_bone_collections.h" + #include "UI_interface.h" #include "UI_resources.h" @@ -2436,7 +2438,7 @@ static int delete_key_v3d_without_keying_set(bContext *C, wmOperator *op) bArmature *arm = (bArmature *)ob->data; /* skipping - not visible on currently visible layers */ - if ((arm->layer & pchan->bone->layer) == 0) { + if (!ANIM_bonecoll_is_visible_pchan(arm, pchan)) { continue; } /* skipping - is currently hidden */ diff --git a/source/blender/editors/armature/CMakeLists.txt b/source/blender/editors/armature/CMakeLists.txt index de0f7c627a9..a229fe555f9 100644 --- a/source/blender/editors/armature/CMakeLists.txt +++ b/source/blender/editors/armature/CMakeLists.txt @@ -46,6 +46,7 @@ set(SRC ) set(LIB + PRIVATE bf::animrig bf_blenkernel PRIVATE bf::blenlib PRIVATE bf::dna diff --git a/source/blender/editors/armature/armature_add.cc b/source/blender/editors/armature/armature_add.cc index e4ba3347162..c437a80fb77 100644 --- a/source/blender/editors/armature/armature_add.cc +++ b/source/blender/editors/armature/armature_add.cc @@ -43,6 +43,8 @@ #include "ED_screen.h" #include "ED_view3d.h" +#include "ANIM_bone_collections.h" + #include "DEG_depsgraph.h" #include "armature_intern.h" @@ -66,7 +68,7 @@ EditBone *ED_armature_ebone_add(bArmature *arm, const char *name) bone->rad_head = 0.10f; bone->rad_tail = 0.05f; bone->segments = 1; - bone->layer = arm->layer; + ANIM_bone_set_ebone_layer_from_armature(bone, arm); /* Bendy-Bone parameters */ bone->roll1 = 0.0f; diff --git a/source/blender/editors/armature/armature_edit.cc b/source/blender/editors/armature/armature_edit.cc index 9c0a7bd03de..9b233cb0f9a 100644 --- a/source/blender/editors/armature/armature_edit.cc +++ b/source/blender/editors/armature/armature_edit.cc @@ -41,6 +41,8 @@ #include "ED_screen.h" #include "ED_view3d.h" +#include "ANIM_bone_collections.h" + #include "DEG_depsgraph.h" #include "armature_intern.h" @@ -1221,7 +1223,7 @@ static bool armature_delete_ebone_cb(const char *bone_name, void *arm_p) EditBone *ebone; ebone = ED_armature_ebone_find_name(arm->edbo, bone_name); - return (ebone && (ebone->flag & BONE_SELECTED) && (arm->layer & ebone->layer)); + return (ebone && (ebone->flag & BONE_SELECTED) && ANIM_bonecoll_is_visible_editbone(arm, ebone)); } /* previously delete_armature */ @@ -1252,7 +1254,7 @@ static int armature_delete_selected_exec(bContext *C, wmOperator * /*op*/) for (curBone = static_cast(arm->edbo->first); curBone; curBone = ebone_next) { ebone_next = curBone->next; - if (arm->layer & curBone->layer) { + if (ANIM_bonecoll_is_visible_editbone(arm, curBone)) { if (curBone->flag & BONE_SELECTED) { if (curBone == arm->act_edbone) { arm->act_edbone = nullptr; @@ -1384,13 +1386,13 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/) for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { /* break connections for unseen bones */ - if (((arm->layer & ebone->layer) && + if ((ANIM_bonecoll_is_visible_editbone(arm, ebone) && (ED_armature_ebone_selectflag_get(ebone) & (BONE_TIPSEL | BONE_SELECTED))) == 0) { ebone->temp.ebone = nullptr; } - if (((arm->layer & ebone->layer) && + if ((ANIM_bonecoll_is_visible_editbone(arm, ebone) && (ED_armature_ebone_selectflag_get(ebone) & (BONE_ROOTSEL | BONE_SELECTED))) == 0) { if (ebone->parent && (ebone->flag & BONE_CONNECTED)) { @@ -1565,7 +1567,7 @@ static int armature_reveal_exec(bContext *C, wmOperator *op) bool changed = false; LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { - if (arm->layer & ebone->layer) { + if (ANIM_bonecoll_is_visible_editbone(arm, ebone)) { if (ebone->flag & BONE_HIDDEN_A) { if (!(ebone->flag & BONE_UNSELECTABLE)) { SET_FLAG_FROM_TEST(ebone->flag, select, (BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL)); diff --git a/source/blender/editors/armature/armature_skinning.cc b/source/blender/editors/armature/armature_skinning.cc index 90d17381a6a..b5df2f984c1 100644 --- a/source/blender/editors/armature/armature_skinning.cc +++ b/source/blender/editors/armature/armature_skinning.cc @@ -37,6 +37,8 @@ #include "ED_armature.h" #include "ED_mesh.h" +#include "ANIM_bone_collections.h" + #include "armature_intern.h" #include "meshlaplacian.h" @@ -159,7 +161,9 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap) segments = 1; } - if (!data->is_weight_paint || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))) { + if (!data->is_weight_paint || + (ANIM_bonecoll_is_visible(arm, bone) && (bone->flag & BONE_SELECTED))) + { if (!(defgroup = BKE_object_defgroup_find_name(ob, bone->name))) { defgroup = BKE_object_defgroup_add_name(ob, bone->name); } @@ -376,7 +380,7 @@ static void add_verts_to_dgroups(ReportList *reports, /* set selected */ if (wpmode) { - if ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED)) { + if (ANIM_bonecoll_is_visible(arm, bone) && (bone->flag & BONE_SELECTED)) { selected[j] = 1; } } diff --git a/source/blender/editors/armature/armature_utils.cc b/source/blender/editors/armature/armature_utils.cc index 06e8693a3c3..966b02ddfde 100644 --- a/source/blender/editors/armature/armature_utils.cc +++ b/source/blender/editors/armature/armature_utils.cc @@ -28,6 +28,8 @@ #include "ED_armature.h" #include "ED_util.h" +#include "ANIM_bone_collections.h" + #include "armature_intern.h" /* -------------------------------------------------------------------- */ @@ -297,7 +299,7 @@ void armature_select_mirrored_ex(bArmature *arm, const int flag) EditBone *curBone, *ebone_mirr; for (curBone = static_cast(arm->edbo->first); curBone; curBone = curBone->next) { - if (arm->layer & curBone->layer) { + if (ANIM_bonecoll_is_visible_editbone(arm, curBone)) { if (curBone->flag & flag) { ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, curBone); if (ebone_mirr) { @@ -326,7 +328,7 @@ void armature_tag_select_mirrored(bArmature *arm) /* Select mirrored bones */ if (arm->flag & ARM_MIRROR_EDIT) { for (curBone = static_cast(arm->edbo->first); curBone; curBone = curBone->next) { - if (arm->layer & curBone->layer) { + if (ANIM_bonecoll_is_visible_editbone(arm, curBone)) { if (curBone->flag & (BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL)) { EditBone *ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, curBone); if (ebone_mirr && (ebone_mirr->flag & BONE_SELECTED) == 0) { diff --git a/source/blender/editors/armature/pose_edit.cc b/source/blender/editors/armature/pose_edit.cc index 79016843711..90311ea9de7 100644 --- a/source/blender/editors/armature/pose_edit.cc +++ b/source/blender/editors/armature/pose_edit.cc @@ -50,6 +50,8 @@ #include "ED_screen.h" #include "ED_view3d.h" +#include "ANIM_bone_collections.h" + #include "UI_interface.h" #include "armature_intern.h" @@ -995,7 +997,7 @@ static int hide_pose_bone_fn(Object *ob, Bone *bone, void *ptr) bArmature *arm = static_cast(ob->data); const bool hide_select = bool(POINTER_AS_INT(ptr)); int count = 0; - if (arm->layer & bone->layer) { + if (ANIM_bonecoll_is_visible(arm, bone)) { if (((bone->flag & BONE_SELECTED) != 0) == hide_select) { bone->flag |= BONE_HIDDEN_P; /* only needed when 'hide_select' is true, but harmless. */ @@ -1065,7 +1067,7 @@ static int show_pose_bone_cb(Object *ob, Bone *bone, void *data) bArmature *arm = static_cast(ob->data); int count = 0; - if (arm->layer & bone->layer) { + if (ANIM_bonecoll_is_visible(arm, bone)) { if (bone->flag & BONE_HIDDEN_P) { if (!(bone->flag & BONE_UNSELECTABLE)) { SET_FLAG_FROM_TEST(bone->flag, select, BONE_SELECTED); diff --git a/source/blender/editors/armature/pose_transform.cc b/source/blender/editors/armature/pose_transform.cc index 02d1599938d..0d4aa963436 100644 --- a/source/blender/editors/armature/pose_transform.cc +++ b/source/blender/editors/armature/pose_transform.cc @@ -46,6 +46,8 @@ #include "ED_screen.h" #include "ED_util.h" +#include "ANIM_bone_collections.h" + #include "UI_interface.h" #include "UI_resources.h" @@ -605,7 +607,7 @@ static void set_pose_keys(Object *ob) if (ob->pose) { for (chan = static_cast(ob->pose->chanbase.first); chan; chan = chan->next) { Bone *bone = chan->bone; - if ((bone) && (bone->flag & BONE_SELECTED) && (arm->layer & bone->layer)) { + if ((bone) && (bone->flag & BONE_SELECTED) && ANIM_bonecoll_is_visible(arm, bone)) { chan->flag |= POSE_KEY; } else { diff --git a/source/blender/editors/gpencil_legacy/CMakeLists.txt b/source/blender/editors/gpencil_legacy/CMakeLists.txt index fe4a6465cf1..dae735cbf01 100644 --- a/source/blender/editors/gpencil_legacy/CMakeLists.txt +++ b/source/blender/editors/gpencil_legacy/CMakeLists.txt @@ -57,6 +57,7 @@ set(SRC ) set(LIB + PRIVATE bf::animrig bf_blenkernel PRIVATE bf::blenlib PRIVATE bf::dna diff --git a/source/blender/editors/gpencil_legacy/gpencil_armature.cc b/source/blender/editors/gpencil_legacy/gpencil_armature.cc index fed4c4a548a..6910c8480e8 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_armature.cc +++ b/source/blender/editors/gpencil_legacy/gpencil_armature.cc @@ -46,6 +46,8 @@ #include "ED_mesh.h" #include "ED_object.h" +#include "ANIM_bone_collections.h" + #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" @@ -203,7 +205,7 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap) segments = 1; } - if (arm->layer & bone->layer) { + if (ANIM_bonecoll_is_visible(arm, bone)) { if (!(defgroup = BKE_object_defgroup_find_name(ob, bone->name))) { defgroup = BKE_object_defgroup_add_name(ob, bone->name); } diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt index cc7f19ddda7..32b9017b3e4 100644 --- a/source/blender/editors/object/CMakeLists.txt +++ b/source/blender/editors/object/CMakeLists.txt @@ -61,6 +61,7 @@ set(SRC ) set(LIB + PRIVATE bf::animrig bf_blenkernel PRIVATE bf::blenlib PRIVATE bf::dna diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index 8d521b91545..febf4ed6368 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -89,6 +89,8 @@ #include "ED_screen.h" #include "ED_sculpt.h" +#include "ANIM_bone_collections.h" + #include "UI_interface.h" #include "WM_api.h" @@ -2957,7 +2959,7 @@ static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain, Object *arm_ob = BKE_object_add(bmain, scene, view_layer, OB_ARMATURE, nullptr); BKE_object_transform_copy(arm_ob, skin_ob); bArmature *arm = static_cast(arm_ob->data); - arm->layer = 1; + ANIM_armature_ensure_first_layer_enabled(arm); arm_ob->dtx |= OB_DRAW_IN_FRONT; arm->drawtype = ARM_LINE; arm->edbo = MEM_cnew("edbo armature"); diff --git a/source/blender/editors/object/object_select.cc b/source/blender/editors/object/object_select.cc index 94f2adb8dfd..98e2960e334 100644 --- a/source/blender/editors/object/object_select.cc +++ b/source/blender/editors/object/object_select.cc @@ -61,6 +61,8 @@ #include "ED_screen.h" #include "ED_select_utils.h" +#include "ANIM_bone_collections.h" + #include "UI_interface.h" #include "UI_resources.h" @@ -311,10 +313,7 @@ bool ED_object_jump_to_bone(bContext *C, if (reveal_hidden) { /* Unhide the bone. */ ebone->flag &= ~BONE_HIDDEN_A; - - if ((arm->layer & ebone->layer) == 0) { - arm->layer |= 1U << bitscan_forward_uint(ebone->layer); - } + ANIM_armature_ensure_layer_enabled_from_ebone(arm, ebone); } /* Select it. */ @@ -338,10 +337,7 @@ bool ED_object_jump_to_bone(bContext *C, if (reveal_hidden) { /* Unhide the bone. */ pchan->bone->flag &= ~BONE_HIDDEN_P; - - if ((arm->layer & pchan->bone->layer) == 0) { - arm->layer |= 1U << bitscan_forward_uint(pchan->bone->layer); - } + ANIM_armature_ensure_layer_enabled_from_pchan(arm, pchan); } /* Select it. */ diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt index c12ecdd1602..3b7afee7f08 100644 --- a/source/blender/editors/space_view3d/CMakeLists.txt +++ b/source/blender/editors/space_view3d/CMakeLists.txt @@ -78,6 +78,7 @@ set(SRC ) set(LIB + PRIVATE bf::animrig PRIVATE bf::blenlib PRIVATE bf::dna bf_editor_curves diff --git a/source/blender/editors/space_view3d/view3d_buttons.cc b/source/blender/editors/space_view3d/view3d_buttons.cc index 5a765da141f..0cb459c651e 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.cc +++ b/source/blender/editors/space_view3d/view3d_buttons.cc @@ -55,6 +55,8 @@ #include "ED_object.h" #include "ED_screen.h" +#include "ANIM_bone_collections.h" + #include "UI_interface.h" #include "UI_resources.h" @@ -1630,7 +1632,7 @@ static void v3d_editarmature_buts(uiLayout *layout, Object *ob) ebone = arm->act_edbone; - if (!ebone || (ebone->layer & arm->layer) == 0) { + if (!ebone || !ANIM_bonecoll_is_visible_editbone(arm, ebone)) { uiItemL(layout, IFACE_("Nothing selected"), ICON_NONE); return; } diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index c988e921e3b..d5a3d6614bf 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -58,6 +58,8 @@ #include "ED_view3d_offscreen.h" #include "ED_viewer_path.hh" +#include "ANIM_bone_collections.h" + #include "DEG_depsgraph_query.h" #include "GPU_batch.h" @@ -1371,7 +1373,7 @@ static void draw_selected_name( else if (ob->mode & OB_MODE_POSE) { if (arm->act_bone) { - if (arm->act_bone->layer & arm->layer) { + if (ANIM_bonecoll_is_visible_actbone(arm)) { info_array[i++] = msg_sep; info_array[i++] = arm->act_bone->name; } @@ -1386,7 +1388,7 @@ static void draw_selected_name( if (armobj && armobj->mode & OB_MODE_POSE) { bArmature *arm = static_cast(armobj->data); if (arm->act_bone) { - if (arm->act_bone->layer & arm->layer) { + if (ANIM_bonecoll_is_visible_actbone(arm)) { info_array[i++] = msg_sep; info_array[i++] = arm->act_bone->name; } diff --git a/source/blender/editors/space_view3d/view3d_snap.cc b/source/blender/editors/space_view3d/view3d_snap.cc index a4bc3f2dc8b..4afbfffe1c1 100644 --- a/source/blender/editors/space_view3d/view3d_snap.cc +++ b/source/blender/editors/space_view3d/view3d_snap.cc @@ -41,6 +41,8 @@ #include "ED_screen.h" #include "ED_transverts.h" +#include "ANIM_bone_collections.h" + #include "view3d_intern.h" static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_cursor[3]); @@ -125,7 +127,7 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator * /*op*/) pchan_eval = pchan_eval->next) { if (pchan_eval->bone->flag & BONE_SELECTED) { - if (pchan_eval->bone->layer & arm_eval->layer) { + if (ANIM_bonecoll_is_visible_pchan(arm_eval, pchan_eval)) { if ((pchan_eval->bone->flag & BONE_CONNECTED) == 0) { float nLoc[3]; @@ -843,7 +845,7 @@ static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_curs for (pchan = static_cast(obact_eval->pose->chanbase.first); pchan; pchan = pchan->next) { - if (arm->layer & pchan->bone->layer) { + if (ANIM_bonecoll_is_visible_pchan(arm, pchan)) { if (pchan->bone->flag & BONE_SELECTED) { copy_v3_v3(vec, pchan->pose_head); mul_m4_v3(obact_eval->object_to_world, vec); diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt index 42c647328a1..34a72efc145 100644 --- a/source/blender/editors/transform/CMakeLists.txt +++ b/source/blender/editors/transform/CMakeLists.txt @@ -115,6 +115,7 @@ set(SRC ) set(LIB + PRIVATE bf::animrig bf_blenfont bf_blenkernel PRIVATE bf::blenlib diff --git a/source/blender/editors/transform/transform_orientations.cc b/source/blender/editors/transform/transform_orientations.cc index e35f506ba21..580b95eae35 100644 --- a/source/blender/editors/transform/transform_orientations.cc +++ b/source/blender/editors/transform/transform_orientations.cc @@ -41,6 +41,8 @@ #include "ED_armature.h" +#include "ANIM_bone_collections.h" + #include "SEQ_select.h" #include "transform.hh" @@ -551,7 +553,7 @@ static int armature_bone_transflags_update_recursive(bArmature *arm, bone->flag &= ~BONE_TRANSFORM; do_next = do_it; if (do_it) { - if (bone->layer & arm->layer) { + if (ANIM_bonecoll_is_visible(arm, bone)) { if (bone->flag & BONE_SELECTED) { bone->flag |= BONE_TRANSFORM; total++; @@ -1302,7 +1304,7 @@ int getTransformOrientation_ex(const Scene *scene, zero_v3(fallback_plane); for (ebone = static_cast(arm->edbo->first); ebone; ebone = ebone->next) { - if (arm->layer & ebone->layer) { + if (ANIM_bonecoll_is_visible_editbone(arm, ebone)) { if (ebone->flag & BONE_SELECTED) { ED_armature_ebone_to_mat3(ebone, tmat); add_v3_v3(normal, tmat[2]); diff --git a/source/blender/editors/transform/transform_snap_object_armature.cc b/source/blender/editors/transform/transform_snap_object_armature.cc index b2a6525693d..0dc14e76621 100644 --- a/source/blender/editors/transform/transform_snap_object_armature.cc +++ b/source/blender/editors/transform/transform_snap_object_armature.cc @@ -16,6 +16,8 @@ #include "ED_transform_snap_object_context.h" +#include "ANIM_bone_collections.h" + #include "transform_snap_object.hh" using blender::float4x4; @@ -56,7 +58,7 @@ eSnapMode snapArmature(SnapObjectContext *sctx, if (arm->edbo) { LISTBASE_FOREACH (EditBone *, eBone, arm->edbo) { - if (eBone->layer & arm->layer) { + if (ANIM_bonecoll_is_visible_editbone(arm, eBone)) { if (eBone->flag & BONE_HIDDEN_A) { /* Skip hidden bones. */ continue; diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index 58b3c891916..c0de8a02eaf 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -107,6 +107,7 @@ set(SRC ) set(LIB + PRIVATE bf::animrig PRIVATE bf::blenlib PRIVATE bf::dna PRIVATE bf::intern::guardedalloc diff --git a/source/blender/editors/util/ed_transverts.cc b/source/blender/editors/util/ed_transverts.cc index 8a05e388f46..7d9331dadfc 100644 --- a/source/blender/editors/util/ed_transverts.cc +++ b/source/blender/editors/util/ed_transverts.cc @@ -34,6 +34,8 @@ #include "ED_armature.h" #include "ED_curves.hh" +#include "ANIM_bone_collections.h" + #include "ED_transverts.h" /* own include */ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit) @@ -327,7 +329,7 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit, MEM_callocN(totmalloc * sizeof(TransVert), __func__)); for (ebo = static_cast(arm->edbo->first); ebo; ebo = ebo->next) { - if (ebo->layer & arm->layer) { + if (ANIM_bonecoll_is_visible_editbone(arm, ebo)) { const bool tipsel = (ebo->flag & BONE_TIPSEL) != 0; const bool rootsel = (ebo->flag & BONE_ROOTSEL) != 0; const bool rootok = !(ebo->parent && (ebo->flag & BONE_CONNECTED) && diff --git a/source/blender/io/collada/ArmatureImporter.cpp b/source/blender/io/collada/ArmatureImporter.cpp index 6a4e9efc0d3..a375dd67347 100644 --- a/source/blender/io/collada/ArmatureImporter.cpp +++ b/source/blender/io/collada/ArmatureImporter.cpp @@ -20,6 +20,8 @@ #include "BLI_string.h" #include "ED_armature.h" +#include "ANIM_bone_collections.h" + #include "DEG_depsgraph.h" #include "ArmatureImporter.h" @@ -139,9 +141,10 @@ int ArmatureImporter::create_bone(SkinInfo *skin, BoneExtended &be = add_bone_extended(bone, node, totchild, layer_labels, extended_bones); int layer = be.get_bone_layers(); if (layer) { - bone->layer = layer; + ANIM_bone_set_layer_ebone(bone, layer); } - arm->layer |= layer; /* ensure that all populated bone layers are visible after import */ + /* Ensure that all populated bone layers are visible after import. */ + ANIM_armature_enable_layers(arm, layer); float *tail = be.get_tail(); int use_connect = be.get_use_connect(); @@ -486,7 +489,8 @@ void ArmatureImporter::create_armature_bones(Main *bmain, std::vector } ED_armature_to_edit(armature); - armature->layer = 0; /* layer is set according to imported bone set in create_bone() */ + /* Layers are enabled according to imported bone set in create_bone(). */ + ANIM_armature_disable_all_layers(armature); create_bone( nullptr, node, nullptr, node->getChildNodes().getCount(), nullptr, armature, layer_labels); diff --git a/source/blender/io/collada/CMakeLists.txt b/source/blender/io/collada/CMakeLists.txt index fb1c1a7d3a6..2a9cd948646 100644 --- a/source/blender/io/collada/CMakeLists.txt +++ b/source/blender/io/collada/CMakeLists.txt @@ -114,6 +114,7 @@ set(LIB ${OPENCOLLADA_LIBRARIES} ${PCRE_LIBRARIES} ${XML2_LIBRARIES} + PRIVATE bf::animrig PRIVATE bf::blenlib PRIVATE bf::dna PRIVATE bf::intern::guardedalloc