Exemplo n.º 1
0
def waterlineChunksFromCSV(operation, chunks):
    layers = oclWaterlineLayerHeights(operation)
    wl_index = 0
    for layer in layers:
        csv_file = open(os.path.join(tempfile.gettempdir(), 'oclWaterline') + str(wl_index) + '.txt', 'r')
        print(str(wl_index) + "\n")
        for line in csv_file:
            if line[0] == 'l':
                chunks.append(camPathChunk(inpoints=[]))
            else:
                point = [float(coord) / OCL_SCALE for coord in line.split()]
                chunks[-1].points.append((point[0], point[1], point[2]))
        wl_index += 1
        csv_file.close()
    chunks.append(camPathChunk(inpoints=[]))
Exemplo n.º 2
0
def waterlineChunksFromCSV( operation, chunks ):
	layers = oclWaterlineLayerHeights( operation )
	wl_index = 0
	for layer in layers:
		csv_file = open(tempfile.gettempdir() + '/oclWaterline' + str(wl_index) + '.txt', 'r')
		print(str(wl_index) + "\n")
		for line in csv_file:
			if( line[0] == 'l'):
				chunks.append( camPathChunk( inpoints = [] ) )
			else:
				point = [ float(coord)/OCL_SCALE for coord in line.split() ]
				chunks[-1].points.append( (point[0], point[1], point[2] ) )
		wl_index += 1
		csv_file.close()
	chunks.append( camPathChunk( inpoints = [] ) )
Exemplo n.º 3
0
def waterlineChunksFromCSV( operation, chunks ):
	layers = oclWaterlineLayerHeights( operation )
	wl_index = 0
	for layer in layers:
		csv_file = open( 'oclWaterline' + str(wl_index) + '.txt', 'r')
		for line in csv_file:
			if( line[0] == 'l'):
				chunks.append( camPathChunk( inpoints = [] ) )
			else:
				point = [ float(coord)/BULLET_SCALE for coord in line.split() ]
				chunks[-1].points.append( (point[0], point[1], point[2] ) )
		wl_index += 1
		csv_file.close()
Exemplo n.º 4
0
def sliceObject(ob):
    settings = bpy.context.scene.cam_slice

    layers = getSlices(ob, settings.slice_distance)
    # print(layers)
    sliceobjects = []
    i = 1
    for layer in layers:
        pi = 1
        layerpolys = []
        for slicechunk in layer:
            # these functions here are totally useless conversions, could generate slices more directly, just lazy to  write new functions
            # print (slicechunk)
            nchp = []
            for p in slicechunk:
                nchp.append((p[0], p[1]))
            # print(slicechunk)
            ch = chunk.camPathChunk(nchp)

            # print(ch)
            pslices = chunk.chunksToShapely([ch])
            # print(pslices)
            for pslice in pslices:
                p = pslice  # -p1
                # print(p)
                text = '%i - %i' % (i, pi)
                bpy.ops.object.text_add()
                textob = bpy.context.active_object
                textob.data.size = 0.0035
                textob.data.body = text
                textob.data.align = 'CENTER'

                # print(len(ch.points))
                sliceobject = polygon_utils_cam.shapelyToCurve(
                    'slice', p, slicechunk[0][2])
                textob.location = (0, 0, 0)

                textob.parent = sliceobject

                sliceobject.data.extrude = settings.slice_distance / 2
                sliceobject.data.dimensions = '2D'
                sliceobjects.append(sliceobject)
                pi += 1
        # FIXME: the polys on same layer which are hollow are not joined by now, this prevents doing hollow surfaces :(
        # for p in layerpolys:
        # for p1 in layerpolys:

        i += 1
    for o in sliceobjects:
        o.select = True
    bpy.ops.group.create(name='slices')
Exemplo n.º 5
0
def sliceObject(ob):
	settings=bpy.context.scene.cam_slice
	
	layers = getSlices(ob, settings.slice_distance)
	#print(layers)
	sliceobjects=[]
	i=1
	for layer in layers:
		pi=1
		layerpolys=[]
		for slicechunk in layer:
			#these functions here are totally useless conversions, could generate slices more directly, just lazy to  write new functions
			#print (slicechunk)
			nchp=[]
			for p in slicechunk:
				nchp.append((p[0],p[1]))
			#print(slicechunk)
			ch = chunk.camPathChunk(nchp)

			#print(ch)
			pslices=chunk.chunksToPolys([ch])
			#p1=outlinePoly(pslice,o.dist_between_paths,o.circle_detail,o.optimize,o.optimize_threshold,False)
			#print(pslices)
			for pslice in pslices:
				p = pslice#-p1
				#print(p)
				text = '%i - %i' % (i,pi)
				bpy.ops.object.text_add()
				textob = bpy.context.active_object
				textob.data.size = 0.0035
				textob.data.body = text
				textob.data.align = 'CENTER'
				
				#print(len(ch.points))
				sliceobject = polygon_utils_cam.polyToMesh('slice',p,slicechunk[0][2])
				textob.location=(0,0,0)
				
				textob.parent=sliceobject
				
				sliceobject.data.extrude = settings.slice_distance/2
				sliceobject.data.dimensions = '2D'
				sliceobjects.append(sliceobject)
				pi+=1
		#FIXME: the polys on same layer which are hollow are not joined by now, this prevents doing hollow surfaces :(
		#for p in layerpolys:
			#for p1 in layerpolys:
				
		i+=1
	for o in sliceobjects:
		o.select=True
	bpy.ops.group.create(name='slices')
Exemplo n.º 6
0
def oclResampleChunks(operation, chunks_to_resample):
    tmp_chunks = list()
    tmp_chunks.append(camPathChunk(inpoints=[]))
    for chunk, i_start, i_length in chunks_to_resample:
        for p_index in range(i_start, i_start + i_length):
            tmp_chunks[0].append(chunk.points[p_index])

    samples = ocl_sample(operation, tmp_chunks)

    sample_index = 0
    for chunk, i_start, i_length in chunks_to_resample:
        for p_index in range(i_start, i_start + i_length):
            z = samples[sample_index].z / OCL_SCALE
            sample_index += 1
            if z > chunk.points[p_index][2]:
                chunk.points[p_index][2] = z
Exemplo n.º 7
0
def oclGetWaterline(operation, chunks):
    layers = oclWaterlineLayerHeights(operation)
    oclSTL = get_oclSTL(operation)

    cutter_props = operation.getOpCuttingTool()

    op_cutter_type = cutter_props.cutter_type
    op_cutter_diameter = cutter_props.cutter_diameter
    op_minz = operation.minz
    if op_cutter_type == "VCARVE":
        op_cutter_tip_angle = cutter_props.cutter_tip_angle

    cutter = None
    cutter_length = 150  #TODO: automatically determine necessary cutter length depending on object size

    if op_cutter_type == 'END':
        cutter = ocl.CylCutter(
            (op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
    elif op_cutter_type == 'BALLNOSE':
        cutter = ocl.BallCutter(
            (op_cutter_diameter + operation.skin * 2) * 1000, cutter_length)
    elif op_cutter_type == 'VCARVE':
        cutter = ocl.ConeCutter(
            (op_cutter_diameter + operation.skin * 2) * 1000,
            op_cutter_tip_angle, cutter_length)
    else:
        print("Cutter unsupported: {0}\n".format(op_cutter_type))
        quit()

    waterline = ocl.Waterline()
    waterline.setSTL(oclSTL)
    waterline.setCutter(cutter)
    waterline.setSampling(0.1)  #TODO: add sampling setting to UI
    for height in layers:
        print(str(height) + '\n')
        waterline.reset()
        waterline.setZ(height * OCL_SCALE)
        waterline.run2()
        wl_loops = waterline.getLoops()
        for l in wl_loops:
            chunks.append(camPathChunk(inpoints=[]))
            for p in l:
                chunks[-1].points.append(
                    (p.x / OCL_SCALE, p.y / OCL_SCALE, p.z / OCL_SCALE))
            chunks[-1].append(chunks[-1].points[0])
            chunks[-1].closed = True
            chunks[-1].poly = sgeometry.Polygon(chunks[-1].points)