Merge pull request #191 from opensourcecnc/master

Fix for the Profile/On Line and Curve to Path strategies not working when the curve contains splines made of polylines that have 2 points
pull/273/head
Alain Pelletier 2024-09-22 09:52:27 -03:00 zatwierdzone przez GitHub
commit 5f19a20fb9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 28 dodań i 0 usunięć

Wyświetl plik

@ -841,3 +841,26 @@ def active_to_shapely_poly():
"""
# convert coordinates to shapely Polygon datastructure
return Polygon(active_to_coords())
#checks for curve splines shorter than three points and subdivides if necessary
def subdivide_short_lines(co):
"""Subdivide all polylines to have at least three points.
This function iterates through the splines of a curve, checks if they are not bezier
and if they have less or equal to two points. If so, each spline is subdivided to get
at least three points.
Args:
co (Object): A curve object to be analyzed and modified.
"""
bpy.ops.object.mode_set(mode="EDIT")
for sp in co.data.splines:
if len(sp.points) == 2 and sp.type != 'BEZIER':
bpy.ops.curve.select_all(action='DESELECT')
for pt in sp.points:
pt.select = True
bpy.ops.curve.subdivide()
bpy.ops.object.editmode_toggle()
bpy.ops.object.select_all(action='SELECT')

Wyświetl plik

@ -49,6 +49,7 @@ from .simple import (
join_multiple,
progress,
remove_multiple,
subdivide_short_lines,
)
from .utils import (
Add_Pocket,
@ -123,6 +124,8 @@ async def cutout(o):
bpy.ops.object.curve_remove_doubles(merg_distance=0.0001, keep_bezier=True)
else:
bpy.ops.object.curve_remove_doubles()
#make sure all polylines are at least three points long
subdivide_short_lines(ob)
if o.cut_type == 'ONLINE' and o.onlycurves: # is separate to allow open curves :)
print('separate')
@ -283,6 +286,8 @@ async def curve(o):
raise CamException("All Objects Must Be Curves for This Operation.")
for ob in o.objects:
#make sure all polylines are at least three points long
subdivide_short_lines(ob)
# make the chunks from curve here
pathSamples.extend(curveToChunks(ob))
# sort before sampling