Added Action.fcurves.find(data_path, array_index=0)
Finding a specific F-Curve is often needed in Python, and usually consists of a construct like: ``` [fcurve for fcurve in ob.animation_data.action.fcurves if fcurve.data_path == "location"][1] ``` This can now be written as `ob.animation_data.action.fcurves.find('location', 1)` This new function `Action.fcurves.find()` is still O(N) in the number of FCurves in the Action, but at least it allows us to remove boiler-plate code. It is also faster than the Python equivalent, as only the found F-Curve is converted to Python. Reviewers: campbellbarton, aligorith Reviewed By: aligorith Differential Revision: https://developer.blender.org/D1427
This commit is contained in:
parent
e7fc8d98f5
commit
89e5c75666
Notes:
blender-bot
2023-02-14 09:02:41 +01:00
Referenced by commit b3ac7c07ff
, Added NlaStrip.fcurves.find(data_path, array_index=0)
Referenced by issue #45515, Dynamic Paint doesn't work in Solid Shading Mode (only in Textured Mode)
|
@ -119,6 +119,17 @@ static FCurve *rna_Action_fcurve_new(bAction *act, ReportList *reports, const ch
|
|||
return verify_fcurve(act, group, NULL, data_path, index, 1);
|
||||
}
|
||||
|
||||
static FCurve *rna_Action_fcurve_find(bAction *act, ReportList *reports, const char *data_path, int index)
|
||||
{
|
||||
if (data_path[0] == '\0') {
|
||||
BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Returns NULL if not found. */
|
||||
return list_find_fcurve(&act->curves, data_path, index);
|
||||
}
|
||||
|
||||
static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, PointerRNA *fcu_ptr)
|
||||
{
|
||||
FCurve *fcu = fcu_ptr->data;
|
||||
|
@ -576,6 +587,7 @@ static void rna_def_action_fcurves(BlenderRNA *brna, PropertyRNA *cprop)
|
|||
RNA_def_struct_sdna(srna, "bAction");
|
||||
RNA_def_struct_ui_text(srna, "Action F-Curves", "Collection of action F-Curves");
|
||||
|
||||
/* Action.fcurves.new(...) */
|
||||
func = RNA_def_function(srna, "new", "rna_Action_fcurve_new");
|
||||
RNA_def_function_ui_description(func, "Add an F-Curve to the action");
|
||||
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||
|
@ -587,7 +599,19 @@ static void rna_def_action_fcurves(BlenderRNA *brna, PropertyRNA *cprop)
|
|||
parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "Newly created F-Curve");
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
/* Action.fcurves.find(...) */
|
||||
func = RNA_def_function(srna, "find", "rna_Action_fcurve_find");
|
||||
RNA_def_function_ui_description(func, "Find an F-Curve. Note that this function performs a linear scan "
|
||||
"of all F-Curves in the action.");
|
||||
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||
parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
|
||||
|
||||
parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "The found F-Curve, or None if it doesn't exist");
|
||||
RNA_def_function_return(func, parm);
|
||||
|
||||
/* Action.fcurves.remove(...) */
|
||||
func = RNA_def_function(srna, "remove", "rna_Action_fcurve_remove");
|
||||
RNA_def_function_ui_description(func, "Remove action group");
|
||||
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||
|
|
Loading…
Reference in New Issue