From fa38d8117e07ba3af7b6e863ed43ec347d5324c4 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Wed, 26 Aug 2015 18:27:56 +0200 Subject: [PATCH] fixed clipper alert error --- config.js | 10 +++---- src/gcode.js | 72 +++++++++++++++++++++++++-------------------------- src/index.js | 5 ++++ src/paths.js | 3 --- src/slice.js | 3 ++- src/slicer.js | 8 ++++-- 6 files changed, 54 insertions(+), 47 deletions(-) diff --git a/config.js b/config.js index 09c1b53..3c1311a 100644 --- a/config.js +++ b/config.js @@ -15,8 +15,8 @@ System.config({ System.config({ "map": { - "babel": "npm:babel-core@5.6.20", - "babel-runtime": "npm:babel-runtime@5.6.20", + "babel": "npm:babel-core@5.8.21", + "babel-runtime": "npm:babel-runtime@5.8.20", "clipper-lib": "npm:clipper-lib@1.0.0", "core-js": "npm:core-js@0.9.18", "json": "github:systemjs/plugin-json@0.1.0", @@ -39,7 +39,7 @@ System.config({ "npm:argparse@1.0.2": { "assert": "github:jspm/nodelibs-assert@0.1.0", "fs": "github:jspm/nodelibs-fs@0.1.2", - "lodash": "npm:lodash@3.10.0", + "lodash": "npm:lodash@3.10.1", "path": "github:jspm/nodelibs-path@0.1.0", "process": "github:jspm/nodelibs-process@0.1.1", "sprintf-js": "npm:sprintf-js@1.0.3", @@ -48,7 +48,7 @@ System.config({ "npm:assert@1.3.0": { "util": "npm:util@0.10.3" }, - "npm:babel-runtime@5.6.20": { + "npm:babel-runtime@5.8.20": { "process": "github:jspm/nodelibs-process@0.1.1" }, "npm:clipper-lib@1.0.0": { @@ -75,7 +75,7 @@ System.config({ "systemjs-json": "github:systemjs/plugin-json@0.1.0", "util": "github:jspm/nodelibs-util@0.1.0" }, - "npm:lodash@3.10.0": { + "npm:lodash@3.10.1": { "process": "github:jspm/nodelibs-process@0.1.1" }, "npm:path-browserify@0.0.0": { diff --git a/src/gcode.js b/src/gcode.js index 6a7881d..f54b6dc 100644 --- a/src/gcode.js +++ b/src/gcode.js @@ -2,7 +2,7 @@ import THREE from 'three.js'; export default class { constructor () { - this.gcode = ""; + this.gcode = ''; this.current = {}; this.extruder = 0.0; @@ -13,7 +13,7 @@ export default class { } _addGCode (command) { - var str = ""; + var str = ''; var first = true; for (var i in command) { @@ -23,13 +23,13 @@ export default class { first = false; } else if (this.current[i] !== command[i]) { - str += " " + i + command[i]; + str += ' ' + i + command[i]; this.current[i] = command[i]; } } - this.gcode += str + "\n"; + this.gcode += str + '\n'; } setSettings (settings) { @@ -42,11 +42,11 @@ export default class { this.isFanOn = true; var gcode = { - "M": 106 + 'M': 106 } if (fanSpeed !== undefined) { - gcode["S"] = fanSpeed; + gcode['S'] = fanSpeed; } this._addGCode(gcode); @@ -58,23 +58,23 @@ export default class { this.isFanOn = false; this._addGCode({ - "M": 107 + 'M': 107 }); return this; } moveTo (x, y, layer) { - var layerHeight = this.settings.config["layerHeight"]; - var travelSpeed = this.settings.config["travelSpeed"]; + var layerHeight = this.settings.config['layerHeight']; + var travelSpeed = this.settings.config['travelSpeed']; var z = (layer + 1) * layerHeight; var speed = travelSpeed * 60; this._addGCode({ - "G": 0, - "X": x.toFixed(3), "Y": y.toFixed(3), "Z": z.toFixed(3), - "F": speed.toFixed(3) + 'G': 0, + 'X': x.toFixed(3), 'Y': y.toFixed(3), 'Z': z.toFixed(3), + 'F': speed.toFixed(3) }); this._nozzlePosition.set(x, y); @@ -85,15 +85,15 @@ export default class { lineTo (x, y, layer, type) { var newNozzlePosition = new THREE.Vector2(x, y); - var layerHeight = this.settings.config["layerHeight"]; - var nozzleDiameter = this.settings.config["nozzleDiameter"]; - var filamentThickness = this.settings.config["filamentThickness"]; - var travelSpeed = this.settings.config["travelSpeed"]; + var layerHeight = this.settings.config['layerHeight']; + var nozzleDiameter = this.settings.config['nozzleDiameter']; + var filamentThickness = this.settings.config['filamentThickness']; + var travelSpeed = this.settings.config['travelSpeed']; - var profile = this.settings.config[(this.bottom ? "bottom" : type)]; + var profile = this.settings.config[(this.bottom ? 'bottom' : type)]; - var speed = profile["speed"] * 60; - var flowRate = profile["flowRate"]; + var speed = profile['speed'] * 60; + var flowRate = profile['flowRate']; var z = (layer + 1) * layerHeight; var lineLength = this._nozzlePosition.distanceTo(newNozzlePosition); @@ -102,10 +102,10 @@ export default class { this.extruder += lineLength * nozzleDiameter * layerHeight / filamentSurfaceArea * flowRate; this._addGCode({ - "G": 1, - "X": x.toFixed(3), "Y": y.toFixed(3), "Z": z.toFixed(3), - "F": speed.toFixed(3), - "E": this.extruder.toFixed(3) + 'G': 1, + 'X': x.toFixed(3), 'Y': y.toFixed(3), 'Z': z.toFixed(3), + 'F': speed.toFixed(3), + 'E': this.extruder.toFixed(3) }); this._nozzlePosition.copy(newNozzlePosition); @@ -114,9 +114,9 @@ export default class { } unRetract () { - var retractionEnabled = this.settings.config["retractionEnabled"]; - var retractionMinDistance = this.settings.config["retractionMinDistance"]; - var retractionSpeed = this.settings.config["retractionSpeed"]; + var retractionEnabled = this.settings.config['retractionEnabled']; + var retractionMinDistance = this.settings.config['retractionMinDistance']; + var retractionSpeed = this.settings.config['retractionSpeed']; if (this.isRetracted && retractionEnabled) { this.isRetracted = false; @@ -125,9 +125,9 @@ export default class { if (this.extruder > retractionMinDistance) { this._addGCode({ - "G": 0, - "E": this.extruder.toFixed(3), - "F": speed.toFixed(3) + 'G': 0, + 'E': this.extruder.toFixed(3), + 'F': speed.toFixed(3) }); } } @@ -136,10 +136,10 @@ export default class { } retract () { - var retractionAmount = this.settings.config["retractionAmount"]; - var retractionEnabled = this.settings.config["retractionEnabled"]; - var retractionMinDistance = this.settings.config["retractionMinDistance"]; - var retractionSpeed = this.settings.config["retractionSpeed"]; + var retractionAmount = this.settings.config['retractionAmount']; + var retractionEnabled = this.settings.config['retractionEnabled']; + var retractionMinDistance = this.settings.config['retractionMinDistance']; + var retractionSpeed = this.settings.config['retractionSpeed']; if (!this.isRetracted && retractionEnabled) { this.isRetracted = true; @@ -148,9 +148,9 @@ export default class { if (this.extruder > retractionMinDistance && retractionEnabled) { this._addGCode({ - "G": 0, - "E": (this.extruder - retractionAmount).toFixed(3), - "F": speed.toFixed(3) + 'G': 0, + 'E': (this.extruder - retractionAmount).toFixed(3), + 'F': speed.toFixed(3) }); } } diff --git a/src/index.js b/src/index.js index 33120cf..6105f16 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,10 @@ import Slicer from './slicer.js'; import SlicerWorker from './slicerworker.js'; import Settings from './settings.js'; +import ClipperLib from 'clipper-lib'; + +ClipperLib.Error = function (message) { + console.error(message); +}; export {Slicer, SlicerWorker, Settings}; diff --git a/src/paths.js b/src/paths.js index 33020e8..f69bbdf 100644 --- a/src/paths.js +++ b/src/paths.js @@ -212,9 +212,6 @@ export default class Paths extends Array { } isHole () { - if (this.length !== 1) { - console.log('wtf?'); - } return !ClipperLib.Clipper.Orientation(this[0]); } diff --git a/src/slice.js b/src/slice.js index cc6eb33..c3c13d3 100644 --- a/src/slice.js +++ b/src/slice.js @@ -21,9 +21,10 @@ export default class { } if (part2.intersect(part1).length > 0) { - this.parts[i].intersect = part1.union(part2); + part1 = this.parts[i].intersect = part1.union(part2); this.parts.splice(j, 1); + j --; } } } diff --git a/src/slicer.js b/src/slicer.js index 3192dcb..968a620 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -338,6 +338,10 @@ export default class { } } + outlines.sort((a, b) => { + return a.boundSize() - b.boundSize(); + }); + for (var i = 0; i < holes.length; i ++) { var hole = holes[i]; @@ -384,8 +388,8 @@ export default class { continue; } - var outerLine = part.intersect.clone().scaleUp(scale).offset(-nozzleRadius); - //var outerLine = part.intersect.scaleUp(scale).offset(-nozzleRadius); + // var outerLine = part.intersect.clone().scaleUp(scale).offset(-nozzleRadius); + var outerLine = part.intersect.scaleUp(scale).offset(-nozzleRadius); if (outerLine.length > 0) { part.outerLine = outerLine;