Created
July 27, 2015 10:38
-
-
Save zeffii/fc6bdbff76897a621a88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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