Пример #1
0
    def convert(self):
        'The main sub-- it converts stl to inc/pov to png to gcode'
        self.base_fname, dot, extension = self.filename.rpartition('.');

        ## Generate inc file from stl
        if extension != 'stl':
            povray_inc = povray.object(self.base_fname + '.inc') # pull object from file
        else:
            povray_inc = povray_include(self.base_fname, self.inside_vector)
            if self.target == 'inc': return povray_inc

        ## Generate pov file from stl
        if extension in (['stl', 'inc']):
            make_pov(self.base_fname, povray_inc, self.step_x, self.step_y, self.step_z)
            if self.target == 'pov': return

        layers = int((povray_inc.max_y() - povray_inc.min_y()) / self.step_y) 

        ## Generate png files from pov and inc
        if extension in (['stl', 'inc', 'pov']):
            make_png(self.base_fname, layers, povray_inc, self.step_x, self.step_z)
            if self.target == 'png': return

        ## Generate gcode files from png
        if extension in (['stl', 'inc', 'pov', 'png']):
            png_to_gcode(self.base_fname, layers, self.step_x, self.step_z, self.depth)
Пример #2
0
def povray_include (base_fname, inside_vector):
    'Convert an stl file into a POVRAY include object'
    ## TODO: use the -e distance option for stl2pov
	## NOTE: The -s (smooth) option causes the min/max values to be calculated
	##       incorrectly (off by 1) sometimes causing blank png images
    stdout_handle = os.popen("stl2pov -s " + base_fname + '.stl', "r")
    inc = stdout_handle.read()

    vec_string = 'inside_vector <%f, %f, %f>' % (
        inside_vector[0],inside_vector[1],inside_vector[2])

    ## write out include file with inside vector added
    out = open(base_fname+'.inc', 'w')
    out.write(inc.rpartition('} //')[0] + vec_string + "\n}\n")
    out.close

    return povray.object(inc);