Curve Editing - Recalculate handles #37799

Closed
opened 2013-12-13 03:19:02 +01:00 by Simon Repp · 11 comments

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 [[ http://wiki.blender.org/index.php/Dev:Doc/Quick_Hacks

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):
recalculate_handles.png

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. ;)

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 [[ http://wiki.blender.org/index.php/Dev:Doc/Quick_Hacks | 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): ![recalculate_handles.png](https://archive.blender.org/developer/F39309/recalculate_handles.png) 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. ;)
Author

Changed status to: 'Open'

Changed status to: 'Open'
Simon Repp self-assigned this 2013-12-13 03:19:02 +01:00
Author

Added subscriber: @simonrepp

Added subscriber: @simonrepp

Added subscribers: @Sergey, @KevinMackay, @ideasman42

Added subscribers: @Sergey, @KevinMackay, @ideasman42

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.

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.

Added subscriber: @brecht

Added subscriber: @brecht

Hey!

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.

@ideasman42, @brecht: do you have strong opinion on this?

Hey! 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. @ideasman42, @brecht: do you have strong opinion on this?
Author

hey,

thanks for the feedback, i just tried implementing the simplified approach @ideasman42 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. :)

hey, thanks for the feedback, i just tried implementing the simplified approach @ideasman42 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. :)
Author

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

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

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Committed c456cd94b2

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.
Committed c456cd94b2 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.
Author

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

Cool thanks, learned a lot here. On to new tasks ... :)
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#37799
No description provided.