kopia lustrzana https://github.com/vilemduha/blendercam
medial axis auto - increase curves resolution before computation
rodzic
7cb8902d88
commit
d75d699187
|
|
@ -3063,127 +3063,148 @@ def getPath3axis(context, operation):
|
||||||
angle=o.cutter_tip_angle
|
angle=o.cutter_tip_angle
|
||||||
slope=math.tan(math.pi*(90-angle/2)/180)
|
slope=math.tan(math.pi*(90-angle/2)/180)
|
||||||
|
|
||||||
|
#remember resolutions of curves, to refine them,
|
||||||
|
#otherwise medial axis computation yields too many branches in curved parts
|
||||||
|
resolutions_before=[]
|
||||||
for ob in o.objects:
|
for ob in o.objects:
|
||||||
polys=getOperationSilhouete(o)
|
if ob.type == 'CURVE':
|
||||||
mpoly = sgeometry.asMultiPolygon(polys)
|
resolutions_before.append(ob.data.resolution_u)
|
||||||
for poly in polys:
|
if ob.data.resolution_u < 64:
|
||||||
schunks=shapelyToChunks(poly,-1)
|
ob.data.resolution_u=64
|
||||||
schunks = chunksRefineThreshold(schunks,o.dist_along_paths, o.crazy_threshold1)#chunksRefine(schunks,o)
|
|
||||||
|
|
||||||
|
polys=getOperationSilhouete(o)
|
||||||
|
mpoly = sgeometry.asMultiPolygon(polys)
|
||||||
|
for poly in polys:
|
||||||
|
schunks=shapelyToChunks(poly,-1)
|
||||||
|
schunks = chunksRefineThreshold(schunks,o.dist_along_paths, o.crazy_threshold1)#chunksRefine(schunks,o)
|
||||||
|
|
||||||
|
'''
|
||||||
|
chunksFromCurve.extend(polyToChunks(p,-1))
|
||||||
|
|
||||||
|
for i,c in enumerate(p):
|
||||||
|
gp.addContour(c,p.isHole(i))
|
||||||
|
|
||||||
'''
|
|
||||||
chunksFromCurve.extend(polyToChunks(p,-1))
|
chunksFromCurve = chunksRefine(chunksFromCurve,o)
|
||||||
|
|
||||||
for i,c in enumerate(p):
|
|
||||||
gp.addContour(c,p.isHole(i))
|
|
||||||
|
points=[]
|
||||||
|
for ch in chunksFromCurve:
|
||||||
chunksFromCurve = chunksRefine(chunksFromCurve,o)
|
for pt in ch.points:
|
||||||
|
pvoro = Site(pt[0], pt[1])
|
||||||
|
points.append(pt)#(pt[0], pt[1]), pt[2])
|
||||||
|
'''
|
||||||
points=[]
|
verts=[]
|
||||||
for ch in chunksFromCurve:
|
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])
|
||||||
points.append(pt)#(pt[0], pt[1]), pt[2])
|
verts.append(pt)#(pt[0], pt[1]), pt[2])
|
||||||
'''
|
#verts= points#[[vert.x, vert.y, vert.z] for vert in vertsPts]
|
||||||
verts=[]
|
nDupli,nZcolinear = unique(verts)
|
||||||
for ch in schunks:
|
nVerts=len(verts)
|
||||||
for pt in ch.points:
|
print(str(nDupli)+" duplicates points ignored")
|
||||||
#pvoro = Site(pt[0], pt[1])
|
print(str(nZcolinear)+" z colinear points excluded")
|
||||||
verts.append(pt)#(pt[0], pt[1]), pt[2])
|
if nVerts < 3:
|
||||||
#verts= points#[[vert.x, vert.y, vert.z] for vert in vertsPts]
|
self.report({'ERROR'}, "Not enough points")
|
||||||
nDupli,nZcolinear = unique(verts)
|
return {'FINISHED'}
|
||||||
nVerts=len(verts)
|
#Check colinear
|
||||||
print(str(nDupli)+" duplicates points ignored")
|
xValues=[pt[0] for pt in verts]
|
||||||
print(str(nZcolinear)+" z colinear points excluded")
|
yValues=[pt[1] for pt in verts]
|
||||||
if nVerts < 3:
|
if checkEqual(xValues) or checkEqual(yValues):
|
||||||
self.report({'ERROR'}, "Not enough points")
|
self.report({'ERROR'}, "Points are colinear")
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
#Check colinear
|
#Create diagram
|
||||||
xValues=[pt[0] for pt in verts]
|
print("Tesselation... ("+str(nVerts)+" points)")
|
||||||
yValues=[pt[1] for pt in verts]
|
xbuff, ybuff = 5, 5 # %
|
||||||
if checkEqual(xValues) or checkEqual(yValues):
|
zPosition=0
|
||||||
self.report({'ERROR'}, "Points are colinear")
|
vertsPts= [Point(vert[0], vert[1], vert[2]) for vert in verts]
|
||||||
return {'FINISHED'}
|
#vertsPts= [Point(vert[0], vert[1]) for vert in verts]
|
||||||
#Create diagram
|
|
||||||
print("Tesselation... ("+str(nVerts)+" points)")
|
pts, edgesIdx = computeVoronoiDiagram(vertsPts, xbuff, ybuff, polygonsOutput=False, formatOutput=True)
|
||||||
xbuff, ybuff = 5, 5 # %
|
|
||||||
zPosition=0
|
#
|
||||||
vertsPts= [Point(vert[0], vert[1], vert[2]) for vert in verts]
|
#pts=[[pt[0], pt[1], zPosition] for pt in pts]
|
||||||
#vertsPts= [Point(vert[0], vert[1]) for vert in verts]
|
newIdx=0
|
||||||
|
vertr=[]
|
||||||
pts, edgesIdx = computeVoronoiDiagram(vertsPts, xbuff, ybuff, polygonsOutput=False, formatOutput=True)
|
filteredPts=[]
|
||||||
|
print('filter points')
|
||||||
#
|
for p in pts:
|
||||||
#pts=[[pt[0], pt[1], zPosition] for pt in pts]
|
if not poly.contains(sgeometry.Point(p)):
|
||||||
newIdx=0
|
vertr.append((True,-1))
|
||||||
vertr=[]
|
else:
|
||||||
filteredPts=[]
|
vertr.append((False,newIdx))
|
||||||
print('filter points')
|
if o.cutter_type == 'VCARVE':
|
||||||
for p in pts:
|
|
||||||
if not poly.contains(sgeometry.Point(p)):
|
|
||||||
vertr.append((True,-1))
|
|
||||||
else:
|
|
||||||
vertr.append((False,newIdx))
|
|
||||||
z=-mpoly.boundary.distance(sgeometry.Point(p))*slope
|
z=-mpoly.boundary.distance(sgeometry.Point(p))*slope
|
||||||
#print(mpoly.distance(sgeometry.Point(0,0)))
|
elif o.cutter_type == 'BALL' or o.cutter_type == 'BALLNOSE':
|
||||||
#if(z!=0):print(z)
|
d = -mpoly.boundary.distance(sgeometry.Point(p))
|
||||||
filteredPts.append((p[0],p[1],z))
|
|
||||||
newIdx+=1
|
|
||||||
|
|
||||||
print('filter edges')
|
z = sqr() - sqr(d) * math.tan(math.pi*(90-angle/2)/180)
|
||||||
filteredEdgs=[]
|
|
||||||
ledges=[]
|
#print(mpoly.distance(sgeometry.Point(0,0)))
|
||||||
for e in edgesIdx:
|
#if(z!=0):print(z)
|
||||||
|
filteredPts.append((p[0],p[1],z))
|
||||||
|
newIdx+=1
|
||||||
|
|
||||||
do=True
|
print('filter edges')
|
||||||
p1=pts[e[0]]
|
filteredEdgs=[]
|
||||||
p2=pts[e[1]]
|
ledges=[]
|
||||||
#print(p1,p2,len(vertr))
|
for e in edgesIdx:
|
||||||
if vertr[e[0]][0]: # exclude edges with allready excluded points
|
|
||||||
do=False
|
do=True
|
||||||
elif vertr[e[1]][0]:
|
p1=pts[e[0]]
|
||||||
do=False
|
p2=pts[e[1]]
|
||||||
if do:
|
#print(p1,p2,len(vertr))
|
||||||
filteredEdgs.append(((vertr[e[0]][1],vertr[e[1]][1])))
|
if vertr[e[0]][0]: # exclude edges with allready excluded points
|
||||||
ledges.append(sgeometry.LineString((filteredPts[vertr[e[0]][1]],filteredPts[vertr[e[1]][1]])))
|
do=False
|
||||||
#print(ledges[-1].has_z)
|
elif vertr[e[1]][0]:
|
||||||
|
do=False
|
||||||
lines = shapely.ops.linemerge(ledges)
|
if do:
|
||||||
#shapelyToCurve('test',lines,0)
|
filteredEdgs.append(((vertr[e[0]][1],vertr[e[1]][1])))
|
||||||
chunks.extend( shapelyToChunks(lines,0))
|
ledges.append(sgeometry.LineString((filteredPts[vertr[e[0]][1]],filteredPts[vertr[e[1]][1]])))
|
||||||
#segments=[]
|
#print(ledges[-1].has_z)
|
||||||
#processEdges=filteredEdgs.copy()
|
|
||||||
#chunk=camPathChunk([])
|
|
||||||
#chunk.points.append(filteredEdgs.pop())
|
|
||||||
#while len(filteredEdgs)>0:
|
|
||||||
|
|
||||||
#Create new mesh structure
|
lines = shapely.ops.linemerge(ledges)
|
||||||
|
#shapelyToCurve('test',lines,0)
|
||||||
|
chunks.extend( shapelyToChunks(lines,0))
|
||||||
|
#segments=[]
|
||||||
|
#processEdges=filteredEdgs.copy()
|
||||||
|
#chunk=camPathChunk([])
|
||||||
|
#chunk.points.append(filteredEdgs.pop())
|
||||||
|
#while len(filteredEdgs)>0:
|
||||||
|
|
||||||
print("Create mesh...")
|
#Create new mesh structure
|
||||||
voronoiDiagram = bpy.data.meshes.new("VoronoiDiagram") #create a new mesh
|
'''
|
||||||
|
print("Create mesh...")
|
||||||
|
voronoiDiagram = bpy.data.meshes.new("VoronoiDiagram") #create a new mesh
|
||||||
|
|
||||||
voronoiDiagram.from_pydata(filteredPts, filteredEdgs, []) #Fill the mesh with triangles
|
|
||||||
|
|
||||||
voronoiDiagram.update(calc_edges=True) #Update mesh with new data
|
voronoiDiagram.from_pydata(filteredPts, filteredEdgs, []) #Fill the mesh with triangles
|
||||||
#create an object with that mesh
|
|
||||||
voronoiObj = bpy.data.objects.new("VoronoiDiagram", voronoiDiagram)
|
voronoiDiagram.update(calc_edges=True) #Update mesh with new data
|
||||||
#place object
|
#create an object with that mesh
|
||||||
#bpy.ops.view3d.snap_cursor_to_selected()#move 3d-cursor
|
voronoiObj = bpy.data.objects.new("VoronoiDiagram", voronoiDiagram)
|
||||||
|
#place object
|
||||||
#update scene
|
#bpy.ops.view3d.snap_cursor_to_selected()#move 3d-cursor
|
||||||
bpy.context.scene.objects.link(voronoiObj) #Link object to scene
|
|
||||||
bpy.context.scene.objects.active = voronoiObj
|
#update scene
|
||||||
voronoiObj.select = True
|
bpy.context.scene.objects.link(voronoiObj) #Link object to scene
|
||||||
|
bpy.context.scene.objects.active = voronoiObj
|
||||||
|
voronoiObj.select = True
|
||||||
#bpy.ops.object.convert(target='CURVE')
|
|
||||||
bpy.ops.object.join()
|
'''
|
||||||
chunks = sortChunks(chunks, o )
|
#bpy.ops.object.convert(target='CURVE')
|
||||||
chunksToMesh(chunks, o )
|
oi=0
|
||||||
|
for ob in o.objects:
|
||||||
|
if ob.type == 'CURVE':
|
||||||
|
ob.data.resolution_u=resolutions_before[oi]
|
||||||
|
oi+=1
|
||||||
|
|
||||||
|
#bpy.ops.object.join()
|
||||||
|
chunks = sortChunks(chunks, o )
|
||||||
|
chunksToMesh(chunks, o )
|
||||||
#
|
#
|
||||||
''''
|
''''
|
||||||
pt_list = []
|
pt_list = []
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue