diff options
author | Omar Emara <mail@OmarEmara.dev> | 2021-02-20 19:05:13 +0300 |
---|---|---|
committer | Omar Emara <mail@OmarEmara.dev> | 2021-02-20 19:05:13 +0300 |
commit | f2c0bbed1ce5270eee1332a02da02c1819bb230c (patch) | |
tree | 3bc309ba191cc1a4c81d3daa6e1b57fa987ef6a1 /source/blender/makesrna/intern/rna_object_api.c | |
parent | 5dced2a0636a7f3db73be09139cf8abd952612e7 (diff) |
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
Diffstat (limited to 'source/blender/makesrna/intern/rna_object_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_object_api.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 9fb883568c9..df628caa000 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -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( |