Page MenuHome

Curve Editing - Recalculate handles
Closed, ResolvedPublic


First off: I just started looking into Blender development, did my first build yesterday, wrote my first lines of blender code today, and this is my first post here - hi everyone! :)

For my first challenge I picked one of the beginner dev tasks from the [[

Quick Hacks ]] listing in the wiki:
Curve, Recalculate handles

In Mesh editmode you can recalculate face flipping, however a similar functionality would be nice to have in curve editmode, to recalculate handles (without changing handle types). This can use the same calculation thats used for setting auto handles.

I already have an implementation ready, but before going into code review I would like to open a quick round for discussing my approach as to how it works and where it is appears in the UI. (And to be totally frank, I still need to figure out a bug that occurs only on the second consecutive run :D ...)

Here's where I placed the button (3D View Toolshelf in Editmode below the handle type settting buttons):

My implementation is:

  • Store the currently set handle types of all points
  • Set all selected handles to type HD_AUTO
  • Recalculate all handles (with BKE_nurb_handles_calc(...))
  • Reset all handle types back to their original type
  • Recalculate handles once again

Thus the use-case for this functionality would be to reset the curvature on a curve that contains sharp (Vector) and soft (Free/Aligned/Auto) turns, but retaining the sharp turns.

Ok so that's it from my side, I'm looking forward to your comments! Feel free to also abandon the idea altogether, it really is a bit exotic, and i won't be disappointed if it turns out this idea was "approved" (see wiki) too long ago, and the needs have changed now.

P.s.: I'll see if i can get the code changes uploaded here tomorrow, it's all a bit much at the moment in terms of learning all the procedures and I'm too tired now anyway to tackle this as well. ;)


Differential Revisions
D100: Curve Editing - Recalculate handles

Event Timeline

Simon Repp (simonrepp) claimed this task.
Simon Repp (simonrepp) raised the priority of this task from to Confirmed, Low.
Simon Repp (simonrepp) updated the task description. (Show Details)
Simon Repp (simonrepp) set Type to Design.

Hi Simon,

I think this can be done with one less step, check on uses of BKE_nurb_handle_calc / BKE_nurb_handle_calc_simple

You could loop over every bezier point, store its h1, h2 values, run BKE_nurb_handle_calc_simple(), and restore h1, h2 immediately after.

After that loop - run BKE_nurb_handles_calc on the entire spline.

This can work because BKE_nurb_handle_calc only uses the locations of the next/prev points, not their handle types.


Campbell's solution is simple and might work, yeah. Just somehow thinking of adding BKE_nurb_handle_calc_ex with additional argument force_handle_type, so no temporary modifications to DNA is needed.

@Campbell Barton (campbellbarton), @Brecht Van Lommel (brecht): do you have strong opinion on this?


thanks for the feedback, i just tried implementing the simplified approach @Campbell Barton (campbellbarton) suggested, and it works perfectly! (also got rid of the breakage on consecutive runs this way)

While playing around with this I actually discovered that the functionality isn't that exotic at all, it's really quite cool for moving around a single or a few points in the curve and then recalculating the handles just for that selection to get it back to a sane curvature. (Comparable to using 'Smooth vertex' when working with a mesh), so I'm actually in favor for integrating it now, and of course I'm looking forward to your opinion on this!

I'll try to get the code up now, so you can look at the nitty gritty details and try the functionality out for yourself. :)

I just uploaded the diff and attached it to this task, hope I did this the correct way too.

Committed rBc456cd94b23af53b53ac13219ea488ed6e7eb5c2

Ended up making some changes.

  • Pass flag as an option (so you could use non-selected points).
  • Optionally don't recalculate handle length (only direction).
  • Recalculating a single free-handle failed, now always calculate both handles and restore the handles of unflagged vertices.
  • Added menu item.

Cool thanks, learned a lot here. On to new tasks ... :)