From 44d1964b5fd117fd37c4565eb9305e2be4685e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 15 Sep 2023 10:55:20 +0200 Subject: [PATCH] Anim: add reverse pointers from bone to collection on overrides When inserting a bone collection via a library override, make sure that the reverse pointers (from the bones in the collection to the collection itself) are also added. These are used for the "given the active bone, which collections is it in?" kind of queries. --- .../animrig/intern/bone_collections.cc | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/source/blender/animrig/intern/bone_collections.cc b/source/blender/animrig/intern/bone_collections.cc index c1b64b67cb0..c4a217f9848 100644 --- a/source/blender/animrig/intern/bone_collections.cc +++ b/source/blender/animrig/intern/bone_collections.cc @@ -73,6 +73,20 @@ void ANIM_bonecoll_free(BoneCollection *bcoll) MEM_delete(bcoll); } +/** + * Construct the mapping from the bones to this collection. + * + * This assumes that the bones do not have such a pointer yet, i.e. calling this + * twice for the same bone collection will cause duplicate pointers. */ +static void add_reverse_pointers(BoneCollection *bcoll) +{ + LISTBASE_FOREACH (BoneCollectionMember *, member, &bcoll->bones) { + BoneCollectionReference *ref = MEM_cnew(__func__); + ref->bcoll = bcoll; + BLI_addtail(&member->bone->runtime.collections, ref); + } +} + void ANIM_armature_runtime_refresh(bArmature *armature) { ANIM_armature_runtime_free(armature); @@ -83,11 +97,7 @@ void ANIM_armature_runtime_refresh(bArmature *armature) /* Construct the bone-to-collections mapping. */ LISTBASE_FOREACH (BoneCollection *, bcoll, &armature->collections) { - LISTBASE_FOREACH (BoneCollectionMember *, member, &bcoll->bones) { - BoneCollectionReference *ref = MEM_cnew(__func__); - ref->bcoll = bcoll; - BLI_addtail(&member->bone->runtime.collections, ref); - } + add_reverse_pointers(bcoll); } } @@ -143,6 +153,7 @@ BoneCollection *ANIM_armature_bonecoll_insert_copy_after(bArmature *armature, BLI_insertlinkafter(&armature->collections, anchor, bcoll); bonecoll_ensure_name_unique(armature, bcoll); + add_reverse_pointers(bcoll); return bcoll; }