kopia lustrzana https://github.com/vilemduha/blendercam
fix + medial axis work
now also 2-point lines get processed correctly for various operations. medial axis actually produces g-code, but still highly un-tuned.pull/25/head
rodzic
cb18e89077
commit
ca8dc95750
|
|
@ -549,7 +549,7 @@ def limitChunks(chunks,o, force=False):#TODO: this should at least add point on
|
||||||
elif sampled:
|
elif sampled:
|
||||||
nch.points.append(s)
|
nch.points.append(s)
|
||||||
prevsampled=sampled
|
prevsampled=sampled
|
||||||
if len(nch.points)>1 and closed and ch.closed and ch.points[0]==ch.points[1]:
|
if len(nch.points)>2 and closed and ch.closed and ch.points[0]==ch.points[1]:
|
||||||
nch.closed=True
|
nch.closed=True
|
||||||
elif ch.closed and nch!=nch1 and len(nch.points)>1 and nch.points[-1]==nch1.points[0]:#here adds beginning of closed chunk to the end, if the chunks were split during limiting
|
elif ch.closed and nch!=nch1 and len(nch.points)>1 and nch.points[-1]==nch1.points[0]:#here adds beginning of closed chunk to the end, if the chunks were split during limiting
|
||||||
nch.points.extend(nch1.points)
|
nch.points.extend(nch1.points)
|
||||||
|
|
@ -891,19 +891,23 @@ def shapelyToChunks(p,zlevel):#
|
||||||
i=0
|
i=0
|
||||||
for s in seq:
|
for s in seq:
|
||||||
#progress(p[i])
|
#progress(p[i])
|
||||||
if len(s)>2:
|
if len(s)>1:
|
||||||
chunk=camPathChunk([])
|
chunk=camPathChunk([])
|
||||||
chunk.poly=spolygon.Polygon(s)#this should maybe be LineString? but for sorting, we need polygon inside functions.
|
if len(s)==2:
|
||||||
|
sgeometry.LineString(s)
|
||||||
|
else:
|
||||||
|
chunk.poly=spolygon.Polygon(s)#this should maybe be LineString? but for sorting, we need polygon inside functions.
|
||||||
for v in s:
|
for v in s:
|
||||||
#progress (v)
|
#progress (v)
|
||||||
|
#print(v)
|
||||||
if len(v)>2:
|
if p.has_z:
|
||||||
chunk.points.append((v[0],v[1],v[2]))
|
chunk.points.append((v[0],v[1],v[2]))
|
||||||
else:
|
else:
|
||||||
chunk.points.append((v[0],v[1],zlevel))
|
chunk.points.append((v[0],v[1],zlevel))
|
||||||
|
|
||||||
chunk.points.append((chunk.points[0][0],chunk.points[0][1],chunk.points[0][2]))#last point =first point
|
#chunk.points.append((chunk.points[0][0],chunk.points[0][1],chunk.points[0][2]))#last point =first point
|
||||||
chunk.closed=True
|
if chunk.points[0]==chunk.points[-1] and len(s)>2:
|
||||||
|
chunk.closed=True
|
||||||
chunks.append(chunk)
|
chunks.append(chunk)
|
||||||
i+=1
|
i+=1
|
||||||
chunks.reverse()#this is for smaller shapes first.
|
chunks.reverse()#this is for smaller shapes first.
|
||||||
|
|
|
||||||
|
|
@ -3057,14 +3057,15 @@ def getPath3axis(context, operation):
|
||||||
|
|
||||||
from cam.voronoi import Site, computeVoronoiDiagram
|
from cam.voronoi import Site, computeVoronoiDiagram
|
||||||
|
|
||||||
chunksFromCurve=[]
|
chunks=[]
|
||||||
|
|
||||||
gpoly=spolygon.Polygon()
|
gpoly=spolygon.Polygon()
|
||||||
for ob in o.objects:
|
for ob in o.objects:
|
||||||
polys=getOperationSilhouete(o)
|
polys=getOperationSilhouete(o)
|
||||||
|
mpoly = sgeometry.asMultiPolygon(polys)
|
||||||
for poly in polys:
|
for poly in polys:
|
||||||
chunks=shapelyToChunks(poly,-1)
|
schunks=shapelyToChunks(poly,-1)
|
||||||
chunks = chunksRefine(chunks,o)
|
schunks = chunksRefine(schunks,o)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
chunksFromCurve.extend(polyToChunks(p,-1))
|
chunksFromCurve.extend(polyToChunks(p,-1))
|
||||||
|
|
@ -3084,7 +3085,7 @@ def getPath3axis(context, operation):
|
||||||
points.append(pt)#(pt[0], pt[1]), pt[2])
|
points.append(pt)#(pt[0], pt[1]), pt[2])
|
||||||
'''
|
'''
|
||||||
verts=[]
|
verts=[]
|
||||||
for ch in chunks:
|
for ch in schunks:
|
||||||
for pt in ch.points:
|
for pt in ch.points:
|
||||||
#pvoro = Site(pt[0], pt[1])
|
#pvoro = Site(pt[0], pt[1])
|
||||||
verts.append(pt)#(pt[0], pt[1]), pt[2])
|
verts.append(pt)#(pt[0], pt[1]), pt[2])
|
||||||
|
|
@ -3112,7 +3113,7 @@ def getPath3axis(context, operation):
|
||||||
pts, edgesIdx = computeVoronoiDiagram(vertsPts, xbuff, ybuff, polygonsOutput=False, formatOutput=True)
|
pts, edgesIdx = computeVoronoiDiagram(vertsPts, xbuff, ybuff, polygonsOutput=False, formatOutput=True)
|
||||||
|
|
||||||
#
|
#
|
||||||
pts=[[pt[0], pt[1], zPosition] for pt in pts]
|
#pts=[[pt[0], pt[1], zPosition] for pt in pts]
|
||||||
newIdx=0
|
newIdx=0
|
||||||
vertr=[]
|
vertr=[]
|
||||||
filteredPts=[]
|
filteredPts=[]
|
||||||
|
|
@ -3122,23 +3123,33 @@ def getPath3axis(context, operation):
|
||||||
vertr.append((True,-1))
|
vertr.append((True,-1))
|
||||||
else:
|
else:
|
||||||
vertr.append((False,newIdx))
|
vertr.append((False,newIdx))
|
||||||
filteredPts.append(p)
|
z=-mpoly.boundary.distance(sgeometry.Point(p))
|
||||||
|
#print(mpoly.distance(sgeometry.Point(0,0)))
|
||||||
|
#if(z!=0):print(z)
|
||||||
|
filteredPts.append((p[0],p[1],z))
|
||||||
newIdx+=1
|
newIdx+=1
|
||||||
|
|
||||||
print('filter edges')
|
print('filter edges')
|
||||||
filteredEdgs=[]
|
filteredEdgs=[]
|
||||||
|
ledges=[]
|
||||||
for e in edgesIdx:
|
for e in edgesIdx:
|
||||||
|
|
||||||
do=True
|
do=True
|
||||||
p1=pts[e[0]]
|
p1=pts[e[0]]
|
||||||
p2=pts[e[1]]
|
p2=pts[e[1]]
|
||||||
#print(p1,p2,len(vertr))
|
#print(p1,p2,len(vertr))
|
||||||
if vertr[e[0]][0]:
|
if vertr[e[0]][0]: # exclude edges with allready excluded points
|
||||||
do=False
|
do=False
|
||||||
elif vertr[e[1]][0]:
|
elif vertr[e[1]][0]:
|
||||||
do=False
|
do=False
|
||||||
if do:
|
if do:
|
||||||
filteredEdgs.append(((vertr[e[0]][1],vertr[e[1]][1])))
|
filteredEdgs.append(((vertr[e[0]][1],vertr[e[1]][1])))
|
||||||
|
ledges.append(sgeometry.LineString((filteredPts[vertr[e[0]][1]],filteredPts[vertr[e[1]][1]])))
|
||||||
|
#print(ledges[-1].has_z)
|
||||||
|
|
||||||
|
lines = shapely.ops.linemerge(ledges)
|
||||||
|
#shapelyToCurve('test',lines,0)
|
||||||
|
chunks.extend( shapelyToChunks(lines,0))
|
||||||
|
|
||||||
#segments=[]
|
#segments=[]
|
||||||
#processEdges=filteredEdgs.copy()
|
#processEdges=filteredEdgs.copy()
|
||||||
|
|
@ -3147,7 +3158,7 @@ def getPath3axis(context, operation):
|
||||||
#while len(filteredEdgs)>0:
|
#while len(filteredEdgs)>0:
|
||||||
|
|
||||||
#Create new mesh structure
|
#Create new mesh structure
|
||||||
|
'''
|
||||||
print("Create mesh...")
|
print("Create mesh...")
|
||||||
voronoiDiagram = bpy.data.meshes.new("VoronoiDiagram") #create a new mesh
|
voronoiDiagram = bpy.data.meshes.new("VoronoiDiagram") #create a new mesh
|
||||||
|
|
||||||
|
|
@ -3165,10 +3176,11 @@ def getPath3axis(context, operation):
|
||||||
bpy.context.scene.objects.link(voronoiObj) #Link object to scene
|
bpy.context.scene.objects.link(voronoiObj) #Link object to scene
|
||||||
bpy.context.scene.objects.active = voronoiObj
|
bpy.context.scene.objects.active = voronoiObj
|
||||||
voronoiObj.select = True
|
voronoiObj.select = True
|
||||||
|
'''
|
||||||
|
|
||||||
#bpy.ops.object.convert(target='CURVE')
|
#bpy.ops.object.convert(target='CURVE')
|
||||||
bpy.ops.object.join()
|
chunksToMesh(chunks, o )
|
||||||
|
#bpy.ops.object.join()
|
||||||
''''
|
''''
|
||||||
pt_list = []
|
pt_list = []
|
||||||
x_max = obj[0][0]
|
x_max = obj[0][0]
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue