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.
This commit is contained in:
parent
65d25ed813
commit
cd8f1853ed
|
@ -373,6 +373,13 @@ static bool rna_BoneCollection_is_editable_get(PointerRNA *ptr)
|
||||||
return ANIM_armature_bonecoll_is_editable(arm, bcoll);
|
return ANIM_armature_bonecoll_is_editable(arm, bcoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int rna_BoneCollection_index_get(PointerRNA *ptr)
|
||||||
|
{
|
||||||
|
bArmature *arm = reinterpret_cast<bArmature *>(ptr->owner_id);
|
||||||
|
BoneCollection *bcoll = static_cast<BoneCollection *>(ptr->data);
|
||||||
|
return blender::animrig::armature_bonecoll_find_index(arm, bcoll);
|
||||||
|
}
|
||||||
|
|
||||||
/* BoneCollection.bones iterator functions. */
|
/* BoneCollection.bones iterator functions. */
|
||||||
|
|
||||||
static void rna_BoneCollection_bones_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
|
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 "
|
"Parent bone collection. Note that accessing this requires a scan of "
|
||||||
"all the bone collections to find the parent");
|
"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);
|
RNA_api_bonecollection(srna);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,12 +200,6 @@ static int rna_BoneCollection_move_to_parent(ID *owner_id,
|
||||||
return new_bcoll_index;
|
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
|
#else
|
||||||
|
|
||||||
void RNA_api_armature_edit_bone(StructRNA *srna)
|
void RNA_api_armature_edit_bone(StructRNA *srna)
|
||||||
|
@ -398,17 +392,6 @@ void RNA_api_bonecollection(StructRNA *srna)
|
||||||
-1,
|
-1,
|
||||||
INT_MAX);
|
INT_MAX);
|
||||||
RNA_def_function_return(func, parm);
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue