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/makesrna/intern/rna_armature.c | |
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/makesrna/intern/rna_armature.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_armature.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index d1e3cb1c860..ffd28b4eb76 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -575,6 +575,20 @@ static void rna_Armature_bones_next(CollectionPropertyIterator *iter) iter->valid = (internal->link != NULL); } +/* not essential, but much faster then the default lookup function */ +static int rna_Armature_bones_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) +{ + bArmature *arm = (bArmature *)ptr->data; + Bone *bone = BKE_armature_find_bone_name(arm, key); + if (bone) { + RNA_pointer_create(ptr->id.data, &RNA_Bone, bone, r_ptr); + return true; + } + else { + return false; + } +} + static bool rna_Armature_is_editmode_get(PointerRNA *ptr) { bArmature *arm = (bArmature *)ptr->id.data; @@ -1285,8 +1299,15 @@ static void rna_def_armature(BlenderRNA *brna) /* Collections */ prop = RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "bonebase", NULL); - RNA_def_property_collection_funcs( - prop, NULL, "rna_Armature_bones_next", NULL, NULL, NULL, NULL, NULL, NULL); + RNA_def_property_collection_funcs(prop, + NULL, + "rna_Armature_bones_next", + NULL, + NULL, + NULL, + NULL, + "rna_Armature_bones_lookup_string", + NULL); RNA_def_property_struct_type(prop, "Bone"); RNA_def_property_ui_text(prop, "Bones", ""); rna_def_armature_bones(brna, prop); |