Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created July 27, 2015 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/fc6bdbff76897a621a88 to your computer and use it in GitHub Desktop.
Save zeffii/fc6bdbff76897a621a88 to your computer and use it in GitHub Desktop.
import bpy
from mathutils import Vector
def adjust_bezier_controls(instruction='average'):
'''
W -> resize longest
W -> resize shortest
W -> normalize
W -> average
'''
bpy.ops.object.mode_set(mode = 'OBJECT')
ao = bpy.context.active_object
if not ao.type == 'CURVE':
return
active_spline = ao.data.splines.active
for s in active_spline.bezier_points:
if not (s.select_control_point and s.select_left_handle and s.select_right_handle):
continue
else:
distance_1 = (s.co - s.handle_left).length
distance_2 = (s.co - s.handle_right).length
if instruction == 'average':
avg = (distance_1 + distance_2) / 2
s.handle_left = s.co.lerp(s.handle_left, avg / distance_1)
s.handle_right = s.co.lerp(s.handle_right, avg / distance_2)
# break
bpy.ops.object.mode_set(mode = 'EDIT')
adjust_bezier_controls(instruction='average')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment