def updateSizeOffsets(self, force=False): newOffsets = numpy.array(profile.calculateObjectSizeOffsets(), numpy.float32) minExtruderCount = profile.minimalExtruderCount() if not force and numpy.array_equal( self._sizeOffsets, newOffsets) and self._minExtruderCount == minExtruderCount: return self._sizeOffsets = newOffsets self._minExtruderCount = minExtruderCount extends = [ numpy.array([[-newOffsets[0], -newOffsets[1]], [newOffsets[0], -newOffsets[1]], [newOffsets[0], newOffsets[1]], [-newOffsets[0], newOffsets[1]]], numpy.float32) ] for n in xrange(1, 4): headOffset = numpy.array( [[0, 0], [ -profile.getMachineSettingFloat('extruder_offset_x%d' % (n)), -profile.getMachineSettingFloat('extruder_offset_y%d' % (n)) ]], numpy.float32) extends.append(polygon.minkowskiHull(extends[n - 1], headOffset)) if minExtruderCount > 1: extends[0] = extends[1] for obj in self._objectList: obj.setPrintAreaExtends(extends[len(obj._meshList) - 1])
def updateSizeOffsets(self, force=False): newOffsets = numpy.array(profile.calculateObjectSizeOffsets(), numpy.float32) minExtruderCount = profile.minimalExtruderCount() if not force and numpy.array_equal(self._sizeOffsets, newOffsets) and self._minExtruderCount == minExtruderCount: return self._sizeOffsets = newOffsets self._minExtruderCount = minExtruderCount extends = [numpy.array([[-newOffsets[0],-newOffsets[1]],[ newOffsets[0],-newOffsets[1]],[ newOffsets[0], newOffsets[1]],[-newOffsets[0], newOffsets[1]]], numpy.float32)] for n in xrange(1, 4): headOffset = numpy.array([[0, 0], [-profile.getMachineSettingFloat('extruder_offset_x%d' % (n)), -profile.getMachineSettingFloat('extruder_offset_y%d' % (n))]], numpy.float32) extends.append(polygon.minkowskiHull(extends[n-1], headOffset)) if minExtruderCount > 1: extends[0] = extends[1] for obj in self._objectList: obj.setPrintAreaExtends(extends[len(obj._meshList) - 1])
def _engineSettings(self, extruderCount): settings = { 'layerThickness': int(profile.getProfileSettingFloat('layer_height') * 1000), 'initialLayerThickness': int(profile.getProfileSettingFloat('bottom_thickness') * 1000) if profile.getProfileSettingFloat('bottom_thickness') > 0.0 else int( profile.getProfileSettingFloat('layer_height') * 1000), 'filamentDiameter': int(profile.getProfileSettingFloat('filament_diameter') * 1000), 'filamentFlow': int(profile.getProfileSettingFloat('filament_flow')), 'extrusionWidth': int(profile.calculateEdgeWidth() * 1000), 'insetCount': int(profile.calculateLineCount()), 'downSkinCount': int(profile.calculateSolidLayerCount()) if profile.getProfileSetting('solid_bottom') == 'True' else 0, 'upSkinCount': int(profile.calculateSolidLayerCount()) if profile.getProfileSetting('solid_top') == 'True' else 0, 'infillOverlap': int(profile.getProfileSettingFloat('fill_overlap')), 'initialSpeedupLayers': int(4), 'initialLayerSpeed': int(profile.getProfileSettingFloat('bottom_layer_speed')), 'printSpeed': int(profile.getProfileSettingFloat('print_speed')), 'infillSpeed': int(profile.getProfileSettingFloat('infill_speed')) if int(profile.getProfileSettingFloat('infill_speed')) > 0 else int( profile.getProfileSettingFloat('print_speed')), 'inset0Speed': int(profile.getProfileSettingFloat('inset0_speed')) if int(profile.getProfileSettingFloat('inset0_speed')) > 0 else int( profile.getProfileSettingFloat('print_speed')), 'insetXSpeed': int(profile.getProfileSettingFloat('insetx_speed')) if int(profile.getProfileSettingFloat('insetx_speed')) > 0 else int( profile.getProfileSettingFloat('print_speed')), 'moveSpeed': int(profile.getProfileSettingFloat('travel_speed')), 'fanSpeedMin': int(profile.getProfileSettingFloat('fan_speed')) if profile.getProfileSetting('fan_enabled') == 'True' else 0, 'fanSpeedMax': int(profile.getProfileSettingFloat('fan_speed_max')) if profile.getProfileSetting('fan_enabled') == 'True' else 0, 'supportAngle': int(-1) if profile.getProfileSetting('support') == 'None' else int( profile.getProfileSettingFloat('support_angle')), 'supportEverywhere': int(1) if profile.getProfileSetting('support') == 'Everywhere' else int(0), 'supportLineDistance': int(100 * profile.calculateEdgeWidth() * 1000 / profile.getProfileSettingFloat('support_fill_rate')) if profile.getProfileSettingFloat('support_fill_rate') > 0 else -1, 'supportXYDistance': int(1000 * profile.getProfileSettingFloat('support_xy_distance')), 'supportZDistance': int(1000 * profile.getProfileSettingFloat('support_z_distance')), 'supportExtruder': 0 if profile.getProfileSetting('support_dual_extrusion') == 'First extruder' else (1 if profile.getProfileSetting('support_dual_extrusion') == 'Second extruder' and profile.minimalExtruderCount() > 1 else -1), 'retractionAmount': int(profile.getProfileSettingFloat('retraction_amount') * 1000) if profile.getProfileSetting('retraction_enable') == 'True' else 0, 'retractionSpeed': int(profile.getProfileSettingFloat('retraction_speed')), 'retractionMinimalDistance': int( profile.getProfileSettingFloat('retraction_min_travel') * 1000), 'retractionAmountExtruderSwitch': int( profile.getProfileSettingFloat('retraction_dual_amount') * 1000), 'retractionZHop': int(profile.getProfileSettingFloat('retraction_hop') * 1000), 'minimalExtrusionBeforeRetraction': int( profile.getProfileSettingFloat('retraction_minimal_extrusion') * 1000), 'enableCombing': 1 if profile.getProfileSetting('retraction_combing') == 'True' else 0, 'multiVolumeOverlap': int(profile.getProfileSettingFloat('overlap_dual') * 1000), 'objectSink': max(0, int(profile.getProfileSettingFloat('object_sink') * 1000)), 'minimalLayerTime': int(profile.getProfileSettingFloat('cool_min_layer_time')), 'minimalFeedrate': int(profile.getProfileSettingFloat('cool_min_feedrate')), 'coolHeadLift': 1 if profile.getProfileSetting('cool_head_lift') == 'True' else 0, 'startCode': profile.getAlterationFileContents('start.gcode', extruderCount), 'endCode': profile.getAlterationFileContents('end.gcode', extruderCount), 'relativeE': 1 if profile.getMachineSetting('relative_extrusion') == 'True' else 0, 'perimInset': int(profile.getProfileSettingFloat('perimeter_inset') * 1000), 'extruderOffset[1].X': int(profile.getMachineSettingFloat('extruder_offset_x1') * 1000), 'extruderOffset[1].Y': int(profile.getMachineSettingFloat('extruder_offset_y1') * 1000), 'extruderOffset[2].X': int(profile.getMachineSettingFloat('extruder_offset_x2') * 1000), 'extruderOffset[2].Y': int(profile.getMachineSettingFloat('extruder_offset_y2') * 1000), 'extruderOffset[3].X': int(profile.getMachineSettingFloat('extruder_offset_x3') * 1000), 'extruderOffset[3].Y': int(profile.getMachineSettingFloat('extruder_offset_y3') * 1000), 'fixHorrible': 0, } fanFullHeight = int( profile.getProfileSettingFloat('fan_full_height') * 1000) settings['fanFullOnLayerNr'] = (fanFullHeight - settings['initialLayerThickness'] - 1) / settings['layerThickness'] + 1 if settings['fanFullOnLayerNr'] < 0: settings['fanFullOnLayerNr'] = 0 if profile.getProfileSetting('support_type') == 'Lines': settings['supportType'] = 1 if profile.getProfileSettingFloat('fill_density') == 0: settings['sparseInfillLineDistance'] = -1 elif profile.getProfileSettingFloat('fill_density') == 100: settings['sparseInfillLineDistance'] = settings['extrusionWidth'] #Set the up/down skins height to 10000 if we want a 100% filled object. # This gives better results then normal 100% infill as the sparse and up/down skin have some overlap. settings['downSkinCount'] = 10000 settings['upSkinCount'] = 10000 else: settings['sparseInfillLineDistance'] = int( 100 * profile.calculateEdgeWidth() * 1000 / profile.getProfileSettingFloat('fill_density')) if profile.getProfileSetting('platform_adhesion') == 'Brim': settings['skirtDistance'] = 0 settings['skirtLineCount'] = int( profile.getProfileSettingFloat('brim_line_count')) elif profile.getProfileSetting('platform_adhesion') == 'Raft': settings['skirtDistance'] = 0 settings['skirtLineCount'] = 0 settings['raftMargin'] = int( profile.getProfileSettingFloat('raft_margin') * 1000) settings['raftLineSpacing'] = int( profile.getProfileSettingFloat('raft_line_spacing') * 1000) settings['raftBaseThickness'] = int( profile.getProfileSettingFloat('raft_base_thickness') * 1000) settings['raftBaseLinewidth'] = int( profile.getProfileSettingFloat('raft_base_linewidth') * 1000) settings['raftInterfaceThickness'] = int( profile.getProfileSettingFloat('raft_interface_thickness') * 1000) settings['raftInterfaceLinewidth'] = int( profile.getProfileSettingFloat('raft_interface_linewidth') * 1000) else: settings['skirtDistance'] = int( profile.getProfileSettingFloat('skirt_gap') * 1000) settings['skirtLineCount'] = int( profile.getProfileSettingFloat('skirt_line_count')) settings['skirtMinLength'] = int( profile.getProfileSettingFloat('skirt_minimal_length') * 1000) if profile.getProfileSetting( 'fix_horrible_union_all_type_a') == 'True': settings['fixHorrible'] |= 0x01 if profile.getProfileSetting( 'fix_horrible_union_all_type_b') == 'True': settings['fixHorrible'] |= 0x02 if profile.getProfileSetting('fix_horrible_use_open_bits') == 'True': settings['fixHorrible'] |= 0x10 if profile.getProfileSetting( 'fix_horrible_extensive_stitching') == 'True': settings['fixHorrible'] |= 0x04 if settings['layerThickness'] <= 0: settings['layerThickness'] = 1000 if profile.getMachineSetting('gcode_flavor') == 'UltiGCode': settings['gcodeFlavor'] = 1 elif profile.getMachineSetting('gcode_flavor') == 'MakerBot': settings['gcodeFlavor'] = 2 if profile.getProfileSetting('spiralize') == 'True': settings['spiralizeMode'] = 1 if profile.getProfileSetting( 'wipe_tower') == 'True' and extruderCount > 1: settings['wipeTowerSize'] = int( math.sqrt( profile.getProfileSettingFloat('wipe_tower_volume') * 1000 * 1000 * 1000 / settings['layerThickness'])) if profile.getProfileSetting('ooze_shield') == 'True': settings['enableOozeShield'] = 1 return settings
def runEngine(self, scene): if len(scene.objects()) < 1: return extruderCount = 1 for obj in scene.objects(): if scene.checkPlatform(obj): extruderCount = max(extruderCount, len(obj._meshList)) extruderCount = max(extruderCount, profile.minimalExtruderCount()) commandList = [getEngineFilename(), '-v', '-p'] for k, v in self._engineSettings(extruderCount).iteritems(): commandList += ['-s', '%s=%s' % (k, str(v))] commandList += ['-g', '%d' % (self._serverPortNr)] self._objCount = 0 engineModelData = [] hash = hashlib.sha512() order = scene.printOrder() if order is None: pos = numpy.array(profile.getMachineCenterCoords()) * 1000 objMin = None objMax = None for obj in scene.objects(): if scene.checkPlatform(obj): oMin = obj.getMinimum()[0:2] + obj.getPosition() oMax = obj.getMaximum()[0:2] + obj.getPosition() if objMin is None: objMin = oMin objMax = oMax else: objMin[0] = min(oMin[0], objMin[0]) objMin[1] = min(oMin[1], objMin[1]) objMax[0] = max(oMax[0], objMax[0]) objMax[1] = max(oMax[1], objMax[1]) if objMin is None: return pos += (objMin + objMax) / 2.0 * 1000 commandList += [ '-s', 'posx=%d' % int(pos[0]), '-s', 'posy=%d' % int(pos[1]) ] vertexTotal = [0] * 4 meshMax = 1 for obj in scene.objects(): if scene.checkPlatform(obj): meshMax = max(meshMax, len(obj._meshList)) for n in xrange(0, len(obj._meshList)): vertexTotal[n] += obj._meshList[n].vertexCount for n in xrange(0, meshMax): verts = numpy.zeros((0, 3), numpy.float32) for obj in scene.objects(): if scene.checkPlatform(obj): if n < len(obj._meshList): vertexes = (numpy.matrix(obj._meshList[n].vertexes, copy=False) * numpy.matrix(obj._matrix, numpy.float32)).getA() vertexes -= obj._drawOffset vertexes += numpy.array([ obj.getPosition()[0], obj.getPosition()[1], 0.0 ]) verts = numpy.concatenate((verts, vertexes)) hash.update(obj._meshList[n].vertexes.tostring()) engineModelData.append((vertexTotal[n], verts)) commandList += ['$' * meshMax] self._objCount = 1 else: for n in order: obj = scene.objects()[n] for mesh in obj._meshList: engineModelData.append((mesh.vertexCount, mesh.vertexes)) hash.update(mesh.vertexes.tostring()) pos = obj.getPosition() * 1000 pos += numpy.array(profile.getMachineCenterCoords()) * 1000 commandList += [ '-m', ','.join(map(str, obj._matrix.getA().flatten())) ] commandList += [ '-s', 'posx=%d' % int(pos[0]), '-s', 'posy=%d' % int(pos[1]) ] commandList += ['$' * len(obj._meshList)] self._objCount += 1 modelHash = hash.hexdigest() if self._objCount > 0: self._modelData = engineModelData self._thread = threading.Thread(target=self._watchProcess, args=(commandList, self._thread, modelHash)) self._thread.daemon = True self._thread.start()
def _engineSettings(self, extruderCount): settings = { 'layerThickness': int(profile.getProfileSettingFloat('layer_height') * 1000), 'initialLayerThickness': int(profile.getProfileSettingFloat('bottom_thickness') * 1000) if profile.getProfileSettingFloat('bottom_thickness') > 0.0 else int(profile.getProfileSettingFloat('layer_height') * 1000), 'filamentDiameter': int(profile.getProfileSettingFloat('filament_diameter') * 1000), 'filamentFlow': int(profile.getProfileSettingFloat('filament_flow')), 'extrusionWidth': int(profile.calculateEdgeWidth() * 1000), 'insetCount': int(profile.calculateLineCount()), 'downSkinCount': int(profile.calculateSolidLayerCount()) if profile.getProfileSetting('solid_bottom') == 'True' else 0, 'upSkinCount': int(profile.calculateSolidLayerCount()) if profile.getProfileSetting('solid_top') == 'True' else 0, 'infillOverlap': int(profile.getProfileSettingFloat('fill_overlap')), 'initialSpeedupLayers': int(4), 'initialLayerSpeed': int(profile.getProfileSettingFloat('bottom_layer_speed')), 'printSpeed': int(profile.getProfileSettingFloat('print_speed')), 'infillSpeed': int(profile.getProfileSettingFloat('infill_speed')) if int(profile.getProfileSettingFloat('infill_speed')) > 0 else int(profile.getProfileSettingFloat('print_speed')), 'moveSpeed': int(profile.getProfileSettingFloat('travel_speed')), 'fanSpeedMin': int(profile.getProfileSettingFloat('fan_speed')) if profile.getProfileSetting('fan_enabled') == 'True' else 0, 'fanSpeedMax': int(profile.getProfileSettingFloat('fan_speed_max')) if profile.getProfileSetting('fan_enabled') == 'True' else 0, 'supportAngle': int(-1) if profile.getProfileSetting('support') == 'None' else int(60), 'supportEverywhere': int(1) if profile.getProfileSetting('support') == 'Everywhere' else int(0), 'supportLineDistance': int(100 * profile.calculateEdgeWidth() * 1000 / profile.getProfileSettingFloat('support_fill_rate')) if profile.getProfileSettingFloat('support_fill_rate') > 0 else -1, 'supportXYDistance': int(1000 * profile.getProfileSettingFloat('support_xy_distance')), 'supportZDistance': int(1000 * profile.getProfileSettingFloat('support_z_distance')), 'supportExtruder': 0 if profile.getProfileSetting('support_dual_extrusion') == 'First extruder' else (1 if profile.getProfileSetting('support_dual_extrusion') == 'Second extruder' and profile.minimalExtruderCount() > 1 else -1), 'retractionAmount': int(profile.getProfileSettingFloat('retraction_amount') * 1000) if profile.getProfileSetting('retraction_enable') == 'True' else 0, 'retractionSpeed': int(profile.getProfileSettingFloat('retraction_speed')), 'retractionMinimalDistance': int(profile.getProfileSettingFloat('retraction_min_travel') * 1000), 'retractionAmountExtruderSwitch': int(profile.getProfileSettingFloat('retraction_dual_amount') * 1000), 'minimalExtrusionBeforeRetraction': int(profile.getProfileSettingFloat('retraction_minimal_extrusion') * 1000), 'enableCombing': 1 if profile.getProfileSetting('retraction_combing') == 'True' else 0, 'multiVolumeOverlap': int(profile.getProfileSettingFloat('overlap_dual') * 1000), 'objectSink': int(profile.getProfileSettingFloat('object_sink') * 1000), 'minimalLayerTime': int(profile.getProfileSettingFloat('cool_min_layer_time')), 'minimalFeedrate': int(profile.getProfileSettingFloat('cool_min_feedrate')), 'coolHeadLift': 1 if profile.getProfileSetting('cool_head_lift') == 'True' else 0, 'startCode': profile.getAlterationFileContents('start.gcode', extruderCount), 'endCode': profile.getAlterationFileContents('end.gcode', extruderCount), 'extruderOffset[1].X': int(profile.getMachineSettingFloat('extruder_offset_x1') * 1000), 'extruderOffset[1].Y': int(profile.getMachineSettingFloat('extruder_offset_y1') * 1000), 'extruderOffset[2].X': int(profile.getMachineSettingFloat('extruder_offset_x2') * 1000), 'extruderOffset[2].Y': int(profile.getMachineSettingFloat('extruder_offset_y2') * 1000), 'extruderOffset[3].X': int(profile.getMachineSettingFloat('extruder_offset_x3') * 1000), 'extruderOffset[3].Y': int(profile.getMachineSettingFloat('extruder_offset_y3') * 1000), 'fixHorrible': 0, } fanFullHeight = int(profile.getProfileSettingFloat('fan_full_height') * 1000) settings['fanFullOnLayerNr'] = (fanFullHeight - settings['initialLayerThickness'] - 1) / settings['layerThickness'] + 1 if settings['fanFullOnLayerNr'] < 0: settings['fanFullOnLayerNr'] = 0 if profile.getProfileSettingFloat('fill_density') == 0: settings['sparseInfillLineDistance'] = -1 elif profile.getProfileSettingFloat('fill_density') == 100: settings['sparseInfillLineDistance'] = settings['extrusionWidth'] #Set the up/down skins height to 10000 if we want a 100% filled object. # This gives better results then normal 100% infill as the sparse and up/down skin have some overlap. settings['downSkinCount'] = 10000 settings['upSkinCount'] = 10000 else: settings['sparseInfillLineDistance'] = int(100 * profile.calculateEdgeWidth() * 1000 / profile.getProfileSettingFloat('fill_density')) if profile.getProfileSetting('platform_adhesion') == 'Brim': settings['skirtDistance'] = 0 settings['skirtLineCount'] = int(profile.getProfileSettingFloat('brim_line_count')) elif profile.getProfileSetting('platform_adhesion') == 'Raft': settings['skirtDistance'] = 0 settings['skirtLineCount'] = 0 settings['raftMargin'] = int(profile.getProfileSettingFloat('raft_margin') * 1000) settings['raftLineSpacing'] = int(profile.getProfileSettingFloat('raft_line_spacing') * 1000) settings['raftBaseThickness'] = int(profile.getProfileSettingFloat('raft_base_thickness') * 1000) settings['raftBaseLinewidth'] = int(profile.getProfileSettingFloat('raft_base_linewidth') * 1000) settings['raftInterfaceThickness'] = int(profile.getProfileSettingFloat('raft_interface_thickness') * 1000) settings['raftInterfaceLinewidth'] = int(profile.getProfileSettingFloat('raft_interface_linewidth') * 1000) else: settings['skirtDistance'] = int(profile.getProfileSettingFloat('skirt_gap') * 1000) settings['skirtLineCount'] = int(profile.getProfileSettingFloat('skirt_line_count')) settings['skirtMinLength'] = int(profile.getProfileSettingFloat('skirt_minimal_length') * 1000) if profile.getProfileSetting('fix_horrible_union_all_type_a') == 'True': settings['fixHorrible'] |= 0x01 if profile.getProfileSetting('fix_horrible_union_all_type_b') == 'True': settings['fixHorrible'] |= 0x02 if profile.getProfileSetting('fix_horrible_use_open_bits') == 'True': settings['fixHorrible'] |= 0x10 if profile.getProfileSetting('fix_horrible_extensive_stitching') == 'True': settings['fixHorrible'] |= 0x04 if settings['layerThickness'] <= 0: settings['layerThickness'] = 1000 if profile.getMachineSetting('gcode_flavor') == 'UltiGCode': settings['gcodeFlavor'] = 1 if profile.getProfileSetting('spiralize') == 'True': settings['spiralizeMode'] = 1 if profile.getProfileSetting('wipe_tower') == 'True': settings['wipeTowerSize'] = int(math.sqrt(profile.getProfileSettingFloat('wipe_tower_volume') * 1000 * 1000 * 1000 / settings['layerThickness'])) if profile.getProfileSetting('ooze_shield') == 'True': settings['enableOozeShield'] = 1 return settings
def runSlicer(self, scene): if len(scene.objects()) < 1: return extruderCount = 1 for obj in scene.objects(): if scene.checkPlatform(obj): extruderCount = max(extruderCount, len(obj._meshList)) extruderCount = max(extruderCount, profile.minimalExtruderCount()) commandList = [getEngineFilename(), '-vv'] for k, v in self._engineSettings(extruderCount).iteritems(): commandList += ['-s', '%s=%s' % (k, str(v))] commandList += ['-o', self._exportFilename] commandList += ['-b', self._binaryStorageFilename] self._objCount = 0 with open(self._binaryStorageFilename, "wb") as f: hash = hashlib.sha512() order = scene.printOrder() if order is None: pos = numpy.array(profile.getMachineCenterCoords()) * 1000 objMin = None objMax = None for obj in scene.objects(): if scene.checkPlatform(obj): oMin = obj.getMinimum()[0:2] + obj.getPosition() oMax = obj.getMaximum()[0:2] + obj.getPosition() if objMin is None: objMin = oMin objMax = oMax else: objMin[0] = min(oMin[0], objMin[0]) objMin[1] = min(oMin[1], objMin[1]) objMax[0] = max(oMax[0], objMax[0]) objMax[1] = max(oMax[1], objMax[1]) pos += (objMin + objMax) / 2.0 * 1000 commandList += ['-s', 'posx=%d' % int(pos[0]), '-s', 'posy=%d' % int(pos[1])] vertexTotal = [0] * 4 meshMax = 1 for obj in scene.objects(): if scene.checkPlatform(obj): meshMax = max(meshMax, len(obj._meshList)) for n in xrange(0, len(obj._meshList)): vertexTotal[n] += obj._meshList[n].vertexCount for n in xrange(0, meshMax): f.write(numpy.array([vertexTotal[n]], numpy.int32).tostring()) for obj in scene.objects(): if scene.checkPlatform(obj): if n < len(obj._meshList): vertexes = (numpy.matrix(obj._meshList[n].vertexes, copy = False) * numpy.matrix(obj._matrix, numpy.float32)).getA() vertexes -= obj._drawOffset vertexes += numpy.array([obj.getPosition()[0], obj.getPosition()[1], 0.0]) f.write(vertexes.tostring()) hash.update(obj._meshList[n].vertexes.tostring()) commandList += ['#' * meshMax] self._objCount = 1 else: for n in order: obj = scene.objects()[n] for mesh in obj._meshList: f.write(numpy.array([mesh.vertexCount], numpy.int32).tostring()) s = mesh.vertexes.tostring() f.write(s) hash.update(s) pos = obj.getPosition() * 1000 pos += numpy.array(profile.getMachineCenterCoords()) * 1000 commandList += ['-m', ','.join(map(str, obj._matrix.getA().flatten()))] commandList += ['-s', 'posx=%d' % int(pos[0]), '-s', 'posy=%d' % int(pos[1])] commandList += ['#' * len(obj._meshList)] self._objCount += 1 self._modelHash = hash.hexdigest() if self._objCount > 0: self._thread = threading.Thread(target=self._watchProcess, args=(commandList, self._thread)) self._thread.daemon = True self._thread.start()
def runSlicer(self, scene): if len(scene.objects()) < 1: return extruderCount = 1 for obj in scene.objects(): if scene.checkPlatform(obj): extruderCount = max(extruderCount, len(obj._meshList)) extruderCount = max(extruderCount, profile.minimalExtruderCount()) commandList = [getEngineFilename(), '-vv'] for k, v in self._engineSettings(extruderCount).iteritems(): commandList += ['-s', '%s=%s' % (k, str(v))] commandList += ['-o', self._exportFilename] commandList += ['-b', self._binaryStorageFilename] self._objCount = 0 with open(self._binaryStorageFilename, "wb") as f: hash = hashlib.sha512() order = scene.printOrder() if order is None: pos = numpy.array(profile.getMachineCenterCoords()) * 1000. objMin = None objMax = None for obj in scene.objects(): if scene.checkPlatform(obj): oMin = obj.getMinimum()[0:2] + obj.getPosition() oMax = obj.getMaximum()[0:2] + obj.getPosition() if objMin is None: objMin = oMin objMax = oMax else: objMin[0] = min(oMin[0], objMin[0]) objMin[1] = min(oMin[1], objMin[1]) objMax[0] = max(oMax[0], objMax[0]) objMax[1] = max(oMax[1], objMax[1]) pos += (numpy.float64(objMin) + numpy.float64(objMax)) / 2.0 * 1000. commandList += [ '-s', 'posx=%d' % int(pos[0]), '-s', 'posy=%d' % int(pos[1]) ] vertexTotal = [0] * 4 meshMax = 1 for obj in scene.objects(): if scene.checkPlatform(obj): meshMax = max(meshMax, len(obj._meshList)) for n in xrange(0, len(obj._meshList)): vertexTotal[n] += obj._meshList[n].vertexCount for n in xrange(0, meshMax): f.write( numpy.array([vertexTotal[n]], numpy.int32).tostring()) for obj in scene.objects(): if scene.checkPlatform(obj): if n < len(obj._meshList): vertexes = ( numpy.matrix(obj._meshList[n].vertexes, copy=False) * numpy.matrix(obj._matrix, numpy.float32)).getA() vertexes -= obj._drawOffset vertexes += numpy.array([ obj.getPosition()[0], obj.getPosition()[1], 0.0 ]) f.write(vertexes.tostring()) hash.update( obj._meshList[n].vertexes.tostring()) commandList += ['#' * meshMax] self._objCount = 1 else: for n in order: obj = scene.objects()[n] for mesh in obj._meshList: f.write( numpy.array([mesh.vertexCount], numpy.int32).tostring()) s = mesh.vertexes.tostring() f.write(s) hash.update(s) pos = obj.getPosition() * 1000. pos += numpy.array( profile.getMachineCenterCoords()) * 1000. commandList += [ '-m', ','.join(map(str, obj._matrix.getA().flatten())) ] commandList += [ '-s', 'posx=%d' % int(pos[0]), '-s', 'posy=%d' % int(pos[1]) ] commandList += ['#' * len(obj._meshList)] self._objCount += 1 self._modelHash = hash.hexdigest() if self._objCount > 0: self._thread = threading.Thread(target=self._watchProcess, args=(commandList, self._thread)) self._thread.daemon = True self._thread.start()