def print_from_mp5(): mp5_as_json = "".join(sys.stdin.readlines()) mp5 = json.loads(mp5_as_json) config_select = { 0: "mp5slicer/config/config.mp5", 1: "mp5slicer/config/config_0.mp5", 2: "mp5slicer/config/config_1.mp5" } dict_conf_file = config_select[mp5['printerSettings']['config_select']] with open(dict_conf_file) as data_file: dict_conf = json.load(data_file) # hack to force config to_file in print_from_file_cpp to true dict_conf['TO_FILE'] = True if 'printerSettings' in mp5: ConfigFactory(dict_conf=dict_conf) else: ConfigFactory() import mp5slicer.config.config as config config.reset() combined_mesh = build_geometry(mp5) print_mesh(combined_mesh, "mp5")
def print_layer(node): if self.layer_index < 2: config.INFILL_SPEED = 1500 config.SKIN_SPEED = 1500 config.BOUNDARY_SPEED = 1500 config.HOLE_SPEED = 1500 config.SUPPORT_SPEED = 1500 # allow change of layerThickness for each layer if self.layerThickness_list: # open happen if it is adaptive slicing config.LAYER_THICKNESS = self.layerThickness_list[ self.layer_index] else: pass if self.layerThickness_list: # open happen if it is adaptive slicing gcodeEnvironment.Z += self.layerThickness_list[ self.layer_index] else: gcodeEnvironment.Z += config.LAYER_THICKNESS for node in node.sub_lines: gotroughgroup(node) config.reset()
def print_raft_layer(node): config.EXTRUSION_MULTIPLIER = 1.1 gcodeEnvironment.Z += config.RAFT_LAYER_THICKNESS for node in node.sub_lines: gotroughgroup(node) config.reset()
def __init__(self, print_tree, layers, index, bounding_box, support_polylines=[]): self.print_tree = print_tree self.layers = layers self.islands = [] self.index = index self.bounding_box = bounding_box if self.index == 0 and config.RAFT is True: config.LINE_WIDTH = 0.35 self.process_islands() # self.support_line_stack = support_polylines[0] # self.support_polylines = \ # self.support_polygon_difference_with_outline(support_polylines) config.reset() # support self.support_offset_value = \ config.LAYER_THICKNESS*np.tan(np.radians(config.SUPPORT_OVERHANG_ANGLE)) self.support_boundary_ps = PolygonStack()
def layer(self, line_group): if self.layer_index > 1: pass elif self.layer_index == 0: config.LINE_WIDTH = config.FIRST_LAYER_LINE_WIDTH config.INFILL_SPEED = config.FIRST_LAYER_INFILL_SPEED config.SKIN_SPEED = config.FIRST_LAYER_SKIN_SPEED config.BOUNDARY_SPEED = config.FIRST_LAYER_BOUNDARY_SPEED config.INNER_BOUNDARY_SPEED = config.FIRST_LAYER_INNER_BOUNDARY_SPEED config.HOLE_SPEED = config.FIRST_LAYER_HOLE_SPEED config.SUPPORT_SPEED = config.FIRST_LAYER_SUPPORT_SPEED config.RAFT_SPEED = config.FIRST_LAYER_RAFT_SPEED config.LAYER_THICKNESS = config.FIRST_LAYER_THICKNESS config.INTERIOR_FAN_SPEED = 0 # for sticking in the line elif self.layer_index == 1: config.reset() else: raise StandardError("layer_index doesn't make sense") # allow change of layerThickness for each layer if self.layerthickness_list: # open happen if it is adaptive slicing config.LAYER_THICKNESS = self.layerthickness_list[self.layer_index] else: pass self.type_gcode_start('layer') if self.layerthickness_list: # open happen if it is adaptive slicing z_change = self.layerthickness_list[self.layer_index] else: z_change = config.LAYER_THICKNESS import copy # only support 1 decimal place now assert z_change == 0 or len(str(z_change).split('.')[1]) in [1, 2] old_height = copy.copy(self.Z) self.Z += z_change self.Z = np.around(self.Z, decimals=2) # delete next line, for debug only if self.layer_index not in [0, 1]: assert np.around(self.Z - old_height, decimals=2) == \ config.LAYER_THICKNESS pass self.gcode_recorder.append_change_z(self.Z) # self.gcode_recorder.append_unretract() # gcode_recorder speed = config.SPEED_RATE self.speed = config.SPEED_RATE self.gcode_recorder.append_rewrite_speed(speed) self.type_gcode_end('layer') self.layer_index += 1
def print_from_mp5(): mp5_as_json = "".join(sys.stdin.readlines()) mp5 = json.loads(mp5_as_json) run_ConfigFactory_on_MP5_file(mp5, False) import mp5slicer.config.config as config config.reset() combined_mesh = build_geometry(mp5) print_mesh(combined_mesh, "mp5")
def contact_layer(self, line_group): config.INFILL_SPEED = 1100 config.SKIN_SPEED = 1000 config.BOUNDARY_SPEED = 1000 config.HOLE_SPEED = 1000 config.EXTERIOR_FAN_SPEED = 1 config.INTERIOR_FAN_SPEED = 1 config.EXTRUSION_MULTIPLIER = 1.2 self.gcode_recorder.append_change_z(config.LAYER_THICKNESS + 0.2) config.reset()
def print_from_file(): args = sys.argv args = args[1:] stl_file_name = args[0] conf_file_name = args[1] ConfigFactory(conf_file_name) import mp5slicer.config.config as config config.reset() mesh = get_stl_from_file(stl_file_name) print_mesh(mesh, stl_file_name)
def main(): from stl import mesh as np_mesh from mp5slicer.mesh_processing import mesh_operations import datetime # import mp5slicer.config.config as config config.reset() start_time = datetime.datetime.now() mesh_name = "reaper.stl" stl_mesh = np_mesh.Mesh.from_file(mesh_name) our_mesh = mesh_operations.mesh(stl_mesh.vectors, fix_mesh=True) bbox = our_mesh.bounding_box() sup = Support(our_mesh, bbox) sup.visulisation(require_group=True, require_support_lines=True)
def top_raft(self, line_group): self.type_gcode_start('top_raft') config.EXTRUSION_MULTIPLIER = 0.8 self.basic_writing_gcode(line_group, config.RAFT_SPEED, config.RAFT_FAN_SPEED, config.EXTRUSION_MULTIPLIER, config.RAFT_LAYER_THICKNESS) self.wait_point = line_group.sub_lines[0][0] # self.gcode_output.write(self.gcodeEnvironment.goToNextPoint(self.wait_point, False)) # self.gcode_output.write(self.gcodeEnvironment.wait_for_cooling(196, 60000)) self.type_gcode_end('top_raft') config.reset()
def print_from_pipe(): conf_file_name = sys.argv[1] ConfigFactory(conf_file_name) import mp5slicer.config.config as config config.reset() # mp5_as_json = "".join(sys.stdin.readlines()) mp5 = '{"printerSettings":{"name":"test","layerThickness":0.2,"emptyLayer":0,"infillSpace":4,"topThickness":0.6,"paramSamples":75,"speedRate":1000,"circleSpeedRate":1000,"temperature":220,"inAirSpeed":7000,"flowRate":0.035,"criticalLength":35,"retractionSpeed":2400,"retractionLength":5,"shellNumber":3,"material":"PLA 2.85mm","autoZScar":true,"zScarGap":0.5,"critLayerTime":6,"filamentDiameter":2.85},"mp5-version":"0.3","root":{"type":"root","children":[{"type":"Difference","protected":false,"children":[{"type":"cylinder","displayColor":{"x":0.7675997200783986,"y":0.03892568708507049,"z":0.1754374135888661},"matrix":[46.276738560910324,0,0,0,0,71.03955320184234,0,0,0,0,10,0,0,0,0,1],"index":652818},{"type":"cylinder","displayColor":{"x":0.11421729990684737,"y":0.07562705374348999,"z":0.6324600862122098},"matrix":[43.70523314805503,0,0,-0.03336494987031813,0,23.811935098864172,0,-1.473401670043664,0,0,23.811935098864172,5.569059618774723,0,0,0,1],"index":2463576}],"initialSize":{"x":1,"y":1,"z":1},"displayColor":{"x":0.6745098039215687,"y":0.47843137254901963,"z":0.6509803921568628},"matrix":[0.7697738537889303,0,0,4.16759433777402,0,0.030894923516336208,-0.7691536190371745,1.3949227857422084,0,0.7691536190371742,0.030894923516336176,27.65249099731288,0,0,0,1],"index":1939910}]}}' mp5 = json.loads(mp5) stl = puppy_magic(mp5) # stl.save("mp5.stl") print_mesh(stl, "mp5")
def print_from_pipe(): import mp5slicer.config.config as config # conf_file_name = sys.argv[1] # ConfigFactory(conf_file_name) # import mp5slicer.config.config as config # config.reset() # mp5_as_json = "".join(sys.stdin.readlines()) # mp5 = '{"printerSettings":{"name":"test","layerThickness":0.2,"emptyLayer":0,"infillSpace":4,"topThickness":0.6,"paramSamples":75,"speedRate":1000,"circleSpeedRate":1000,"temperature":220,"inAirSpeed":7000,"flowRate":0.035,"criticalLength":35,"retractionSpeed":2400,"retractionLength":5,"shellNumber":3,"material":"PLA 2.85mm","autoZScar":true,"zScarGap":0.5,"critLayerTime":6,"filamentDiameter":2.85},"mp5-version":"0.3","root":{"type":"root","children":[{"type":"Difference","protected":false,"children":[{"type":"cylinder","displayColor":{"x":0.7675997200783986,"y":0.03892568708507049,"z":0.1754374135888661},"matrix":[46.276738560910324,0,0,0,0,71.03955320184234,0,0,0,0,10,0,0,0,0,1],"index":652818},{"type":"cylinder","displayColor":{"x":0.11421729990684737,"y":0.07562705374348999,"z":0.6324600862122098},"matrix":[43.70523314805503,0,0,-0.03336494987031813,0,23.811935098864172,0,-1.473401670043664,0,0,23.811935098864172,5.569059618774723,0,0,0,1],"index":2463576}],"initialSize":{"x":1,"y":1,"z":1},"displayColor":{"x":0.6745098039215687,"y":0.47843137254901963,"z":0.6509803921568628},"matrix":[0.7697738537889303,0,0,4.16759433777402,0,0.030894923516336208,-0.7691536190371745,1.3949227857422084,0,0.7691536190371742,0.030894923516336176,27.65249099731288,0,0,0,1],"index":1939910}]}}' # double mushroom mp5 = '{"printerSettings":{"LAYER_THICKNESS":0.2, "TO_FILE":true},"mp5-version":"0.3","root":{"type":"root","children":[{"type":"implicit_double_mushroom","displayColor":{"x":6,"y":0.7,"z":0.7},"matrix":[10,0,0,84.55341967686932,0,10,0,121.11403382006986,0,0,10,5,0,0,0,1],"index":2375196}]}}' # cube # mp5 = '''{"printerSettings":{"LAYER_THICKNESS":0.2, "TO_FILE":true}, # "mp5-version":"0.3","root":{"type":"root","children":[{"type":"icube","displayColor":{"x":0.7,"y":0.7,"z":7}, # "matrix":[10,0,0,0, # 0,10,0,0, # 0,0,10,0, # 0,0,0,1], # "index":5498993}]}}''' # tetrahedron # mp5 = '{"printerSettings":{"LAYER_THICKNESS":0.2, "TO_FILE":true},"mp5-version":"0.3","root":{"type":"root","children":[{"type":"tetrahedron","displayColor":{"x":0.71,"y":0.164,"z":0},"matrix":[10,0,0,122.29212041120184,0,10,0,114.23374799066498,0,0,10,5.000000000211934,0,0,0,1],"corners":[[0,0,0.31649658092772615],[0.5,0,-0.5],[-0.5,0.5,-0.5],[-0.5,-0.5,-0.5]],"index":3194877}]}}' # ellisoid # mp5 = '{"printerSettings":{"LAYER_THICKNESS":0.2, "TO_FILE":true},"mp5-version":"0.3","root":{"type":"root","children":[{"type":"iellipsoid", "matrix":[10,0,0,0, 0,10,0,0, 0,0,10,0, 0,0,0,1],"index":5498993}]}}' stls = [] mp5 = json.loads(mp5) ConfigFactory(dict_conf=mp5['printerSettings']) config.reset() for son_position in range(len(mp5["root"]["children"])): mc = get_mc_params(mp5, son_position) mc_params = to_json_mc_params(mc) mp5_string = json.dumps(mp5["root"]["children"][son_position]) pymplicit.build_geometry(mp5_string, mc_params) verts = pymplicit.get_verts() faces = pymplicit.get_faces() pymplicit.finish_geometry() stl = m2stl_mesh(verts, faces) stls.append(stl.data) combined_stl = mesh.Mesh(np.concatenate(stls)) combined_stl.save("mp5.stl") print_mesh(combined_stl, "mp5")
def print_from_mp5_file(): args = sys.argv args = args[1:] mp5_file_path = args[0] # ConfigFactory(user_config_mp5, printer_config_mp5, filament_config_mp5) with open(mp5_file_path) as data_file: mp5_file = json.load(data_file) run_ConfigFactory_on_MP5_file(mp5_file, True) import mp5slicer.config.config as config config.reset() combined_mesh = build_geometry(mp5_file) print_mesh(combined_mesh, "mp5")
def print_from_mp5(): mp5_file_name = sys.argv[2] conf_file_name = sys.argv[1] ConfigFactory(conf_file_name) import mp5slicer.config.config as config config.reset() mp5 = json.load(open(mp5_file_name)) stl = puppy_magic(mp5) # iobj = json2implicit_func(json) # iobj.implicitGradient(x) # iobj.implicitFunction(x) # stl = demo_combination_plus_qem(iobj) stl.save("mp5.stl") print_mesh(stl, "mp5")
def print_from_pipe(): mp5_as_json = "".join(sys.stdin.readlines()) mp5 = json.loads(mp5_as_json) config_select = {0:"mp5slicer/config/config.json", 1:"mp5slicer/config/config_0.json", 2:"mp5slicer/config/config_1.json"} dict_conf_file = config_select[mp5['printerSettings']['config_select']] with open(dict_conf_file) as data_file: dict_conf = json.load(data_file) # hack to force config to_file in print_from_file_cpp to true dict_conf['TO_FILE'] = False if 'printerSettings' in mp5: ConfigFactory(dict_conf=dict_conf) else: ConfigFactory() import mp5slicer.config.config as config config.reset() stls = [] for son_position in range(len(mp5["root"]["children"])): mc = get_mc_params(mp5, son_position) mc_params = to_json_mc_params(mc) mp5_string = json.dumps(mp5["root"]["children"][son_position]) pymplicit.build_geometry(mp5_string, mc_params) verts = pymplicit.get_verts() faces = pymplicit.get_faces() pymplicit.finish_geometry() stl = m2stl_mesh(verts, faces) stls.append(stl.data) stl = mesh.Mesh(np.concatenate(stls)) # stl = puppy_magic(mp5) # stl.save("mp5.stl") print_mesh(stl, "mp5")
def print_contact_layer(node): config.INFILL_SPEED = 1100 config.SKIN_SPEED = 1000 config.BOUNDARY_SPEED = 1000 config.HOLE_SPEED = 1000 config.EXTERIOR_FAN_SPEED = 1 config.INTERIOR_FAN_SPEED = 1 config.EXTRUSION_MULTIPLIER = 1.2 gcodeEnvironment.Z += config.LAYER_THICKNESS + 0.2 for node in node.sub_lines: gotroughgroup(node) # gcode_output.write("M104 S220 \n") gcode_output.write( gcodeEnvironment.goToNextPoint(self.wait_point, True)) gcode_output.write( gcodeEnvironment.wait_for_cooling(config.temperature, 25000)) config.reset()
def print_from_file_next_generation(): args = sys.argv args = args[1:] stl_file_name = args[0] default_config_mp5_path = args[1] user_config_mp5_path = args[2] printer_config_mp5_path = args[3] filament_config_mp5_path = args[4] print_from_file_config_mp5_path = args[5] # ConfigFactory(user_config_mp5, printer_config_mp5, filament_config_mp5) ConfigFactoryNextGeneration( ['default', 'user', 'printer', 'filament', 'print_from_file'], [4, 1, 2, 3, 0], default_config_mp5_path, user_config_mp5_path, printer_config_mp5_path, filament_config_mp5_path, print_from_file_config_mp5_path) import mp5slicer.config.config as config config.reset() mesh = get_stl_from_file(stl_file_name) print_mesh(mesh, stl_file_name)
def raft_layer(self, line_group): config.EXTRUSION_MULTIPLIER = 1.1 # self.gcodeEnvironment.Z += config.RAFT_LAYER_THICKNESS self.gcode_recorder.append_change_z(config.RAFT_LAYER_THICKNESS) config.reset()
def process_infill(self): if self.index == 0 and config.RAFT is True: config.LINE_WIDTH = 0.35 for island in self.islands: island.process_infill() config.reset()
def prepare_skins(self): if self.index == 0 and config.RAFT is True: config.LINE_WIDTH = 0.35 for island in self.islands: island.prepare_skins() config.reset()