Python: Add to_curve method to the object API

This patch adds a to_curve method to the Object ID. This method is
analogous to the to_mesh method. The method can operate on curve and
text objects. For text objects, the text is converted into a 3D Curve ID
and that curve is returned. For curve objects, if apply_modifiers is
true, the spline deform modifiers will be applied and a Curve ID with
the result will be returned, otherwise a copy of the curve will be
returned.

The goal of this addition is to allow the developer to access the splines
of text objects and to get the result of modifier applications which was
otherwise not possible.

Reviewed By: Brecht

Differential Revision: https://developer.blender.org/D10354
This commit is contained in:
2021-02-20 18:05:13 +02:00
parent 5dced2a063
commit f2c0bbed1c
10 changed files with 270 additions and 10 deletions

View File

@@ -404,6 +404,29 @@ static void rna_Object_to_mesh_clear(Object *object)
BKE_object_to_mesh_clear(object);
}
static Curve *rna_Object_to_curve(Object *object,
ReportList *reports,
Depsgraph *depsgraph,
bool apply_modifiers)
{
if (!ELEM(object->type, OB_FONT, OB_CURVE)) {
BKE_report(reports, RPT_ERROR, "Object is not a curve or a text");
return NULL;
}
if (depsgraph == NULL) {
BKE_report(reports, RPT_ERROR, "Invalid depsgraph");
return NULL;
}
return BKE_object_to_curve(object, depsgraph, apply_modifiers);
}
static void rna_Object_to_curve_clear(Object *object)
{
BKE_object_to_curve_clear(object);
}
static PointerRNA rna_Object_shape_key_add(
Object *ob, bContext *C, ReportList *reports, const char *name, bool from_mix)
{
@@ -977,6 +1000,29 @@ void RNA_api_object(StructRNA *srna)
func = RNA_def_function(srna, "to_mesh_clear", "rna_Object_to_mesh_clear");
RNA_def_function_ui_description(func, "Clears mesh data-block created by to_mesh()");
/* curve */
func = RNA_def_function(srna, "to_curve", "rna_Object_to_curve");
RNA_def_function_ui_description(
func,
"Create a Curve data-block from the current state of the object. This only works for curve "
"and text objects. The object owns the data-block. To force free it, use to_curve_clear(). "
"The result is temporary and can not be used by objects from the main database");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
parm = RNA_def_pointer(
func, "depsgraph", "Depsgraph", "Dependency Graph", "Evaluated dependency graph");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
RNA_def_boolean(func,
"apply_modifiers",
false,
"",
"Apply the deform modifiers on the control points of the curve. This is only "
"supported for curve objects");
parm = RNA_def_pointer(func, "curve", "Curve", "", "Curve created from object");
RNA_def_function_return(func, parm);
func = RNA_def_function(srna, "to_curve_clear", "rna_Object_to_curve_clear");
RNA_def_function_ui_description(func, "Clears curve data-block created by to_curve()");
/* Armature */
func = RNA_def_function(srna, "find_armature", "BKE_modifiers_is_deformed_by_armature");
RNA_def_function_ui_description(