diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-14 21:48:22 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2019-05-14 21:56:57 +0300 |
commit | 26d2652d6d4287801d56dc8d41b1037750af701a (patch) | |
tree | e6d71dcc75782c28859d06d7eb39d7929c412b7b /source/blender/editors/armature | |
parent | 987c6da6c0dd7b4f8c64561c030d4c381f2725c5 (diff) |
Armature: implement universal hash table lookup of Bone objects by name.
Since drivers on Bone properties are really supposed to be stored
in Armature data and access bones via its bones[] collection, this
lookup path should work efficiently.
Mass lookup of bones by name was already done through hashes,
but they were built temporarily every time that was needed. This
simply replaces it with a common hash table computed immediately
after file load, copy, or Edit to Object mode switch.
Diffstat (limited to 'source/blender/editors/armature')
-rw-r--r-- | source/blender/editors/armature/armature_naming.c | 10 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_utils.c | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/editors/armature/armature_naming.c b/source/blender/editors/armature/armature_naming.c index 083967d5d41..9a1582679a4 100644 --- a/source/blender/editors/armature/armature_naming.c +++ b/source/blender/editors/armature/armature_naming.c @@ -180,7 +180,17 @@ void ED_armature_bone_rename(Main *bmain, if (bone) { unique_bone_name(arm, newname); + + if (arm->bonehash) { + BLI_assert(BLI_ghash_haskey(arm->bonehash, bone->name)); + BLI_ghash_remove(arm->bonehash, bone->name, NULL, NULL); + } + BLI_strncpy(bone->name, newname, MAXBONENAME); + + if (arm->bonehash) { + BLI_ghash_insert(arm->bonehash, bone->name, bone); + } } else { return; diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index b23081cd6fa..20dc7b6c826 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -650,6 +650,7 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) Object *obt; /* armature bones */ + BKE_armature_bone_hash_free(arm); BKE_armature_bonelist_free(&arm->bonebase); arm->act_bone = NULL; @@ -754,6 +755,8 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) /* Finalize definition of restpose data (roll, bone_mat, arm_mat, head/tail...). */ armature_finalize_restpose(&arm->bonebase, arm->edbo); + BKE_armature_bone_hash_make(arm); + /* so all users of this armature should get rebuilt */ for (obt = bmain->objects.first; obt; obt = obt->id.next) { if (obt->data == arm) { |