kopia lustrzana https://github.com/vilemduha/blendercam
-optimized optimizeChunk function, is much faster now with larger paths
-optimized parallel pattern generation, about 2x faster now -fixed several bugspull/4/head
rodzic
7b57d028bc
commit
7957676c8e
|
|
@ -173,7 +173,7 @@ def updateStrategy(o,context):
|
|||
|
||||
def updateCutout(o,context):
|
||||
if o.outlines_count>1:
|
||||
o.use_bridges=false
|
||||
o.use_bridges=False
|
||||
|
||||
|
||||
def updateExact(o,context):
|
||||
|
|
@ -187,7 +187,8 @@ def updateExact(o,context):
|
|||
def updateBridges(o,context):
|
||||
print('update bridges ')
|
||||
o.changed=True
|
||||
utils.setupBridges(o)
|
||||
#utils.setupBridges(o)
|
||||
|
||||
def updateRest(o,context):
|
||||
print('update rest ')
|
||||
o.changed=True
|
||||
|
|
|
|||
|
|
@ -130,7 +130,12 @@ class camPathChunk:
|
|||
self.startpoints.pop(index)
|
||||
self.endpoints.pop(index)
|
||||
self.rotations.pop(index)
|
||||
|
||||
def append(self, point, startpoint=None,endpoint=None):
|
||||
self.points.append(point)
|
||||
if startpoint!=None:
|
||||
self.startpoints.append(startpoint)
|
||||
if endpoint!=None:
|
||||
self.endpoints.append(endpoint)
|
||||
def rampContour(self,zstart,zend,o):
|
||||
|
||||
stepdown=zstart-zend
|
||||
|
|
@ -331,18 +336,46 @@ def setChunksZ(chunks,z):
|
|||
|
||||
|
||||
def optimizeChunk(chunk,operation):
|
||||
points=chunk.points
|
||||
|
||||
chunk.points=[points[0]]
|
||||
spoints=False
|
||||
if len(chunk.startpoints)>0:
|
||||
startpoints=chunk.startpoints
|
||||
endpoints=chunk.endpoints
|
||||
chunk.startpoints=[startpoints[0]]
|
||||
chunk.endpoints=[endpoints[0]]
|
||||
spoints=True
|
||||
'''this was replaced by append. Pop method was much much slower! still testing however.
|
||||
for vi in range(len(chunk.points)-2,0,-1):
|
||||
#vmiddle=Vector()
|
||||
#v1=Vector()
|
||||
#v2=Vector()
|
||||
if compare(chunk.points[vi-1],chunk.points[vi+1],chunk.points[vi],operation.optimize_threshold):
|
||||
|
||||
chunk.pop(vi)
|
||||
|
||||
#vi-=1
|
||||
#protect_vertical=True
|
||||
if operation.protect_vertical and operation.axes=='3':#protect vertical surfaces so far only for 3 axes..doesn't have now much logic for n axes, right?
|
||||
chunk.pop(vi)
|
||||
'''
|
||||
protect_vertical = operation.protect_vertical and operation.axes=='3'
|
||||
for vi in range(0,len(points)-1):
|
||||
#vmiddle=Vector()
|
||||
#v1=Vector()
|
||||
#v2=Vector()
|
||||
if not compare(chunk.points[-1],points[vi+1],points[vi],operation.optimize_threshold):
|
||||
if spoints:
|
||||
chunk.append(points[vi],startpoints[vi],endpoints[vi])
|
||||
else:
|
||||
chunk.points.append(points[vi])
|
||||
if protect_vertical:
|
||||
v1=chunk.points[-1]
|
||||
v2=chunk.points[-2]
|
||||
v1c,v2c=isVerticalLimit(v1,v2,operation.protect_vertical_limit)
|
||||
if v1c!=v1:
|
||||
chunk.points[-1]=v1c
|
||||
elif v2c!=v2:
|
||||
chunk.points[-2]=v2c
|
||||
#=True
|
||||
'''
|
||||
if:#protect vertical surfaces so far only for 3 axes..doesn't have now much logic for n axes, right?
|
||||
#print('verticality test')
|
||||
|
||||
|
||||
|
|
@ -357,6 +390,7 @@ def optimizeChunk(chunk,operation):
|
|||
|
||||
|
||||
#print(vcorrected)
|
||||
'''
|
||||
return chunk
|
||||
|
||||
def limitChunks(chunks,o):#TODO: this should at least add point on area border... but shouldn't be needed at all at the first place...
|
||||
|
|
|
|||
|
|
@ -1182,9 +1182,9 @@ def renderSampleImage(o):
|
|||
resx=ceil(sx/o.pixsize)+2*o.borderwidth
|
||||
resy=ceil(sy/o.pixsize)+2*o.borderwidth
|
||||
|
||||
#if not o.update_zbufferimage_tag and len(o.zbuffer_image)==resx and len(o.zbuffer_image[0])==resy :#if we call this accidentally in more functions, which currently happens...
|
||||
if not o.update_zbufferimage_tag and len(o.zbuffer_image)==resx and len(o.zbuffer_image[0])==resy :#if we call this accidentally in more functions, which currently happens...
|
||||
#print('has zbuffer')
|
||||
#return o.zbuffer_image
|
||||
return o.zbuffer_image
|
||||
####setup image name
|
||||
#fn=bpy.data.filepath
|
||||
#iname=bpy.path.abspath(fn)
|
||||
|
|
@ -1280,7 +1280,7 @@ def renderSampleImage(o):
|
|||
r.image_settings.color_mode=cm
|
||||
|
||||
i=bpy.data.images.load(iname)
|
||||
bpy.context.scene.render.engine='BLENDERCAM_RENDER'
|
||||
bpy.context.scene.render.engine='BLENDER_CAM'
|
||||
a=imagetonumpy(i)
|
||||
a=1.0-a
|
||||
o.zbuffer_image=a
|
||||
|
|
@ -1298,7 +1298,7 @@ def renderSampleImage(o):
|
|||
ex=i.size[0]
|
||||
sy=0
|
||||
ey=i.size[1]
|
||||
|
||||
|
||||
o.offset_image.resize(ex-sx+2*o.borderwidth,ey-sy+2*o.borderwidth)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,14 +33,17 @@ def getPathPatternParallel(o,angle):
|
|||
#ar=numpy.array((1.1,1.1))
|
||||
#ar.resize()
|
||||
#if bpy.app.debug_value==0:
|
||||
dirvect=Vector((0,1,0))
|
||||
dirvect.rotate(e)
|
||||
dirvect.normalize()
|
||||
dirvect*=pathstep
|
||||
for a in range(int(-dim/pathd), int(dim/pathd)):#this is highly ineffective, computes path2x the area needed...
|
||||
chunk=camPathChunk([])
|
||||
v=Vector((a*pathd,int(-dim/pathstep)*pathstep,0))
|
||||
v.rotate(e)
|
||||
v+=vm#shifting for the rotation, so pattern rotates around middle...
|
||||
for b in range(int(-dim/pathstep),int(dim/pathstep)):
|
||||
v.x=a*pathd
|
||||
v.y=b*pathstep
|
||||
|
||||
v.rotate(e)
|
||||
v+=vm#shifting for the rotation, so pattern rotates around middle...
|
||||
v+=dirvect
|
||||
if v.x>o.min.x and v.x<o.max.x and v.y>o.min.y and v.y<o.max.y:
|
||||
chunk.points.append((v.x,v.y,zlevel))
|
||||
if (reverse and o.movement_type=='MEANDER') or (o.movement_type=='CONVENTIONAL' and o.spindle_rotation_direction=='CW') or (o.movement_type=='CLIMB' and o.spindle_rotation_direction=='CCW') :
|
||||
|
|
|
|||
|
|
@ -238,6 +238,7 @@ def sampleChunks(o,pathSamples,layers):
|
|||
zinvert=ob.location.z+maxz#ob.bound_box[6][2]
|
||||
|
||||
n=0
|
||||
last_percent=-1
|
||||
#timing for optimisation
|
||||
samplingtime=timinginit()
|
||||
sortingtime=timinginit()
|
||||
|
|
@ -256,8 +257,9 @@ def sampleChunks(o,pathSamples,layers):
|
|||
#for t in range(0,threads):
|
||||
|
||||
for s in patternchunk.points:
|
||||
if o.strategy!='WATERLINE' and n/200.0==int(n/200.0):
|
||||
progress('sampling paths ',int(100*n/totlen))
|
||||
if o.strategy!='WATERLINE' and int(100*n/totlen)!=last_percent:
|
||||
last_percent=int(100*n/totlen)
|
||||
progress('sampling paths ',last_percent)
|
||||
n+=1
|
||||
x=s[0]
|
||||
y=s[1]
|
||||
|
|
@ -753,6 +755,7 @@ def doSimulation(name,operations):
|
|||
|
||||
def chunksToMesh(chunks,o):
|
||||
##########convert sampled chunks to path, optimization of paths
|
||||
t=time.time()
|
||||
s=bpy.context.scene
|
||||
origin=(0,0,o.free_movement_height)
|
||||
verts = [origin]
|
||||
|
|
@ -761,8 +764,12 @@ def chunksToMesh(chunks,o):
|
|||
progress('building paths from chunks')
|
||||
e=0.0001
|
||||
lifted=True
|
||||
test=bpy.app.debug_value
|
||||
|
||||
for chi in range(0,len(chunks)):
|
||||
print(chi)
|
||||
ch=chunks[chi]
|
||||
nverts=[]
|
||||
if o.optimize:
|
||||
ch=optimizeChunk(ch,o)
|
||||
|
||||
|
|
@ -802,7 +809,9 @@ def chunksToMesh(chunks,o):
|
|||
#print(verts_rotations)
|
||||
if o.use_exact:
|
||||
cleanupBulletCollision(o)
|
||||
|
||||
print(time.time()-t)
|
||||
t=time.time()
|
||||
|
||||
#actual blender object generation starts here:
|
||||
edges=[]
|
||||
for a in range(0,len(verts)-1):
|
||||
|
|
@ -835,9 +844,10 @@ def chunksToMesh(chunks,o):
|
|||
ob=object_utils.object_data_add(bpy.context, mesh, operator=None)
|
||||
ob=ob.object
|
||||
|
||||
print(time.time()-t)
|
||||
|
||||
ob.location=(0,0,0)
|
||||
o.path_object_name=oname
|
||||
verts=ob.data.vertices
|
||||
exportGcodePath(o.filename,[ob.data],[o])
|
||||
|
||||
|
||||
|
|
@ -2214,6 +2224,8 @@ def getPath3axis(context,operation):
|
|||
if o.strategy=='OUTLINEFILL':
|
||||
getOperationSilhouete(o)
|
||||
pathSamples=getPathPattern(o)
|
||||
#chunksToMesh(pathSamples,o)#for testing pattern script
|
||||
#return
|
||||
if o.strategy=='OUTLINEFILL':
|
||||
pathSamples=sortChunks(pathSamples,o)
|
||||
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue