Page MenuHome

Python: Add to_curve method to the object API
ClosedPublic

Authored by Omar Emara (OmarSquircleArt) on Feb 7 2021, 10:17 PM.

Details

Summary

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.

Depends on: D10351

Diff Detail

Repository
rB Blender

Event Timeline

Omar Emara (OmarSquircleArt) requested review of this revision.Feb 7 2021, 10:17 PM
Omar Emara (OmarSquircleArt) created this revision.

I think this is a nice and consistent counterpart of to_mesh().

What is a bit weak is the loops which applies modifiers. The current code seems to lack check for tessellation point. Also, should be possible to re-use curve_get_tessellate_point and curve_calc_modifiers_pre.

Additionally, I'd suggest adding an example it doc/ similar to what is done for to_mesh().

Do we really need custom modifier stack evaluation code for this API function? Can't it be shared with existing code?

  • Promote curve_calc_modifiers_pre to a BKE function.
  • Split the nurb parameter in BKE_curve_calc_modifiers_pre to a source and target to allow out of place application.
  • Use BKE_curve_calc_modifiers_pre for modifier application.
  • Add an example for Object.to_curve() to docs.

@Sergey Sharybin (sergey) @Brecht Van Lommel (brecht) I replaced the modifier evaluation loop with curve_calc_modifiers_pre. Is this what you wanted?

Brecht Van Lommel (brecht) added inline comments.
doc/python_api/examples/bpy.types.Depsgraph.7.py
10

curve one -> curve object

15

text one -> text object

16

the apply_modifiers -> apply_modifiers

19–22

result curve -> resulting curve

This revision is now accepted and ready to land.Feb 18 2021, 7:26 PM

@Sergey Sharybin (sergey) @Brecht Van Lommel (brecht) I replaced the modifier evaluation loop with curve_calc_modifiers_pre. Is this what you wanted?

Yup.

  • Update doc example description
Omar Emara (OmarSquircleArt) marked 4 inline comments as done.Feb 18 2021, 10:44 PM