Skip to content

Commit

Permalink
Fixes bugs in "merge ends" operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Apr 24, 2020
1 parent ac5bc26 commit 94e5b4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cad.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class MergeEnds(bpy.types.Operator):
bl_description = bl_label = 'Merge Ends'
bl_options = {'REGISTER', 'UNDO'}

max_dist: bpy.props.FloatProperty(name='Distance', description='Threshold of the maximum distance at which two controll points are merged', unit='LENGTH', min=0.0, default=0.1)
max_dist: bpy.props.FloatProperty(name='Distance', description='Threshold of the maximum distance at which two control points are merged', unit='LENGTH', min=0.0, default=0.1)

@classmethod
def poll(cls, context):
Expand Down
24 changes: 7 additions & 17 deletions internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,34 +638,24 @@ def addBezierSpline(obj, cyclic, vertices, weights=None, select=False):
return spline

def mergeEnds(splines, points, is_last_point):
if not is_last_point[1]:
splines[1], splines[0] = splines[0], splines[1]
points[1], points[0] = points[0], points[1]
is_last_point[1], is_last_point[0] = is_last_point[0], is_last_point[1]

points[0].handle_left_type = 'FREE'
points[0].handle_right_type = 'FREE'
bpy.ops.curve.select_all(action='DESELECT')
points[0].handle_left_type = points[0].handle_right_type = 'FREE'
new_co = (points[0].co+points[1].co)*0.5
handle = (points[1].handle_left if is_last_point[1] else points[1].handle_right)+new_co-points[1].co
points[0].select_left_handle = points[0].select_right_handle = True
if is_last_point[0]:
points[0].handle_left += new_co-points[0].co
points[0].handle_right = handle
else:
points[0].handle_right += new_co-points[0].co
points[0].handle_left = handle
points[0].co = new_co

point_index = [len(splines[0].bezier_points), len(splines[1].bezier_points)]
bpy.ops.curve.select_all(action='DESELECT')
points[0].select_control_point = True
points[1].select_control_point = True
points[0].select_control_point = points[1].select_control_point = True
bpy.ops.curve.make_segment()
# print(is_last_point, point_index, splines[0].bezier_points, splines[1].bezier_points)
spline = splines[0] if len(splines[0].bezier_points) == point_index[0]+point_index[1] else splines[1]
point = splines[0].bezier_points[0] if splines[0] == splines[1] else (splines[0].bezier_points[point_index[1]] if spline == splines[0] else splines[1].bezier_points[point_index[0]])
point.select_control_point = False
spline = splines[0] if splines[0] in bpy.context.object.data.splines.values() else splines[1]
point = next(point for point in spline.bezier_points if point.select_left_handle)
point.select_left_handle = point.select_right_handle = point.select_control_point = False
bpy.ops.curve.delete()

return spline

def polygonArcAt(center, radius, begin_angle, angle, step_angle, include_ends):
Expand Down

0 comments on commit 94e5b4e

Please sign in to comment.