From cd8f1853ed558bb73beac38be285997641e7877a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 2 Jan 2024 16:54:30 +0100 Subject: [PATCH] Anim: replace `bone_collection.find_index()` with `.index` property Replace the RNA function `bone_collection.find_index()` with a read-only property `.index`. The functionality is the same, just exposed to RNA differently. Note that this property still does an array scan, and thus has complexity `O(n)` in the number of bone collections. Since this number is relatively small, this shouldn't be a problem. --- source/blender/makesrna/intern/rna_armature.cc | 16 ++++++++++++++++ .../blender/makesrna/intern/rna_armature_api.cc | 17 ----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/source/blender/makesrna/intern/rna_armature.cc b/source/blender/makesrna/intern/rna_armature.cc index af86d1633a4..aed5316ecaf 100644 --- a/source/blender/makesrna/intern/rna_armature.cc +++ b/source/blender/makesrna/intern/rna_armature.cc @@ -373,6 +373,13 @@ static bool rna_BoneCollection_is_editable_get(PointerRNA *ptr) return ANIM_armature_bonecoll_is_editable(arm, bcoll); } +static int rna_BoneCollection_index_get(PointerRNA *ptr) +{ + bArmature *arm = reinterpret_cast(ptr->owner_id); + BoneCollection *bcoll = static_cast(ptr->data); + return blender::animrig::armature_bonecoll_find_index(arm, bcoll); +} + /* BoneCollection.bones iterator functions. */ static void rna_BoneCollection_bones_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) @@ -2269,6 +2276,15 @@ static void rna_def_bonecollection(BlenderRNA *brna) "Parent bone collection. Note that accessing this requires a scan of " "all the bone collections to find the parent"); + prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE); + RNA_def_property_int_funcs(prop, "rna_BoneCollection_index_get", nullptr, nullptr); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text( + prop, + "Index", + "Index of this bone collection in the armature.collections.all array. Note that finding " + "this index requires a scan of all the bone collections, so do access this with care"); + RNA_api_bonecollection(srna); } diff --git a/source/blender/makesrna/intern/rna_armature_api.cc b/source/blender/makesrna/intern/rna_armature_api.cc index 1876d6bdc57..30bccd418b2 100644 --- a/source/blender/makesrna/intern/rna_armature_api.cc +++ b/source/blender/makesrna/intern/rna_armature_api.cc @@ -200,12 +200,6 @@ static int rna_BoneCollection_move_to_parent(ID *owner_id, return new_bcoll_index; } -static int rna_BoneCollection_find_index(ID *owner_id, BoneCollection *self) -{ - bArmature *armature = (bArmature *)owner_id; - return blender::animrig::armature_bonecoll_find_index(armature, self); -} - #else void RNA_api_armature_edit_bone(StructRNA *srna) @@ -398,17 +392,6 @@ void RNA_api_bonecollection(StructRNA *srna) -1, INT_MAX); RNA_def_function_return(func, parm); - - /* collection.find_index() */ - func = RNA_def_function(srna, "find_index", "rna_BoneCollection_find_index"); - RNA_def_function_ui_description(func, - "Find the index of this bone collection. This scans through all " - "the Armature's bone collections"); - RNA_def_function_flag(func, FUNC_USE_SELF_ID); - /* Return value. */ - parm = RNA_def_int( - func, "index", -1, -1, INT_MAX, "Index", "Index of the bone collection", -1, INT_MAX); - RNA_def_function_return(func, parm); } #endif