diff --git a/models/support_test.stl b/models/support_test.stl index 8984779..0d4dc1e 100644 Binary files a/models/support_test.stl and b/models/support_test.stl differ diff --git a/settings/user_settings.json b/settings/user_settings.json index 6203867..30c2156 100644 --- a/settings/user_settings.json +++ b/settings/user_settings.json @@ -15,10 +15,10 @@ "printer.temperature": 210.0, "printer.topThickness": 0.8, "printer.travelSpeed": 200.0, - "printer.support.minArea": 2.0, - "printer.support.distanceY": 0.15, + "printer.support.accaptanceSize": 1.5, + "printer.support.distanceY": 0.4, "printer.support.use": true, - "printer.support.size": 3, - "printer.support.margin": 1.0, - "printer.support.offset": 1.0 + "printer.support.gritSize": 6.0, + "printer.support.margin": 2.0, + "printer.support.plateSize": 4.0 } \ No newline at end of file diff --git a/slice_test.html b/slice_test.html index e261536..d6dc373 100644 --- a/slice_test.html +++ b/slice_test.html @@ -36,7 +36,7 @@ function init () { var printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS["ultimaker"]); var loader = new THREE.STLLoader(); - loader.load('models/robot.stl', function (geometry) { + loader.load('models/support_test.stl', function (geometry) { //var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1); //var geometry = new THREE.SphereGeometry(10, 20, 10); //var geometry = new THREE.TorusGeometry(20, 10, 30, 30); @@ -71,8 +71,10 @@ function init () { mesh.rotation.x = -Math.PI/2; mesh.scale.x = mesh.scale.y = mesh.scale.z = 1; mesh.position.y = -0.1; - mesh.position.x = 100; - mesh.position.z = 100; + mesh.position.x = 60; + mesh.position.z = 60; + + mesh.updateMatrix(); scene.add(mesh); diff --git a/src/box.js b/src/box.js index 3b909c2..0f407de 100644 --- a/src/box.js +++ b/src/box.js @@ -14,7 +14,7 @@ D3D.Box = function (localIp) { "use strict"; - var self = this; + var scope = this; this.batchSize = 512; this.maxBufferedLines = 4096; @@ -31,13 +31,13 @@ D3D.Box = function (localIp) { this.loaded = false; this.getConfigAll(function (data) { - self.updateConfig(data); + scope.updateConfig(data); - self.update(); + scope.update(); - self.loaded = true; - if (self.onload !== undefined) { - self.onload(); + scope.loaded = true; + if (scope.onload !== undefined) { + scope.onload(); } }); }; @@ -52,6 +52,7 @@ D3D.Box.prototype.updateConfig = function (config) { }; D3D.Box.prototype.update = function () { "use strict"; + var scope = this; //TODO //Code is zo op gezet dat maar api call te gelijk is //Bij error wordt gelijk zelfde data opnieuw gestuurd @@ -62,22 +63,24 @@ D3D.Box.prototype.update = function () { this.printBatch(); } else { - this.updateState(); + setTimeout(function () { + scope.updateState(); + }, 1000); } }; D3D.Box.prototype.updateState = function () { //que api calls so they don't overload the d3d box "use strict"; - var self = this; + var scope = this; this.getInfoStatus(function (data) { - self.status = data; + scope.status = data; - if (self.onupdate !== undefined) { - self.onupdate(data); + if (scope.onupdate !== undefined) { + scope.onupdate(data); } - self.update(); + scope.update(); }); }; D3D.Box.prototype.print = function (gcode) { @@ -98,7 +101,7 @@ D3D.Box.prototype.print = function (gcode) { }; D3D.Box.prototype.printBatch = function () { "use strict"; - var self = this; + var scope = this; var gcode = this.printBatches.shift(); @@ -108,17 +111,17 @@ D3D.Box.prototype.printBatch = function () { "gcode": gcode.join("\n"), "last": ((this.printBatches.length === 0) ? true : false) //only for debug purposes }, function (data) { - console.log("batch sent: " + self.currentBatch, data); + console.log("batch sent: " + scope.currentBatch, data); - if (self.printBatches.length > 0) { + if (scope.printBatches.length > 0) { //sent new batch - self.currentBatch ++; + scope.currentBatch ++; } else { //finish sending } - self.updateState(); + scope.updateState(); }); }; D3D.Box.prototype.stopPrint = function (printer) { @@ -154,12 +157,12 @@ D3D.Box.prototype.getConfigAll = function (callback) { }; D3D.Box.prototype.setConfig = function (data, callback) { "use strict"; - var self = this; + var scope = this; sendAPI(this.api + "config", data, function (response) { for (var i in response.validation) { if (response.validation[i] === "ok") { - self[i] = data[i]; + scope[i] = data[i]; } } diff --git a/src/gcode.js b/src/gcode.js index 0fe9989..e60a06e 100644 --- a/src/gcode.js +++ b/src/gcode.js @@ -4,6 +4,8 @@ * * Manages the gcode * Also handles different flavours of gcode +* TODO +* calculate extrusion length and total time * ******************************************************/ diff --git a/src/paths.js b/src/paths.js index 302985d..84cc4a1 100644 --- a/src/paths.js +++ b/src/paths.js @@ -168,7 +168,8 @@ D3D.Paths.prototype.areas = function () { for (var i = 0; i < this.length; i ++) { var shape = this[i]; - areas.push(ClipperLib.Clipper.Area(shape)); + var area = Math.abs(ClipperLib.Clipper.Area(shape)); + areas.push(area); } return areas; @@ -209,6 +210,16 @@ D3D.Paths.prototype.bounds = function () { return ClipperLib.Clipper.GetBounds(this); }; +D3D.Paths.prototype.boundSize = function () { + "use strict"; + + var bounds = this.bounds(); + + var width = bounds.right - bounds.left; + var height = bounds.top - bounds.bottom; + + return width * height; +}; D3D.Paths.prototype.draw = function (context, color) { "use strict"; diff --git a/src/slicer.js b/src/slicer.js index 260f507..a2bd59a 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -237,7 +237,7 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) { //think this check is not nescesary, always higher as 0 if (shape.length > 0) { - slice.push(new D3D.Paths([shape])); + slice.push(new D3D.Paths([shape], true)); } } } @@ -281,20 +281,21 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) { var scale = 100; - var layerHeight = printer.config["printer.layerHeight"] * scale; - var dimensionsZ = printer.config["printer.dimensions.z"] * scale; + var layerHeight = printer.config["printer.layerHeight"]; var nozzleDiameter = printer.config["printer.nozzleDiameter"] * scale; var shellThickness = printer.config["printer.shellThickness"] * scale; var fillSize = printer.config["printer.fillSize"] * scale; var brimOffset = printer.config["printer.brimOffset"] * scale; - var bottomThickness = printer.config["printer.bottomThickness"] * scale; - var topThickness = printer.config["printer.topThickness"] * scale; + var bottomThickness = printer.config["printer.bottomThickness"]; + var topThickness = printer.config["printer.topThickness"]; var useSupport = printer.config["printer.support.use"]; - var supportSize = printer.config["printer.support.size"] * scale; - var supportMinArea = printer.config["printer.support.minArea"] * Math.pow(scale, 2); + var supportGritSize = printer.config["printer.support.gritSize"] * scale; + var supportAccaptanceSize = printer.config["printer.support.accaptanceSize"] * scale; var supportMargin = printer.config["printer.support.margin"] * scale; - var supportOffset = printer.config["printer.support.offset"] * scale; + var plateSize = printer.config["printer.support.plateSize"] * scale; + var supportDistanceY = printer.config["printer.support.distanceY"]; + var supportDistanceLayers = Math.ceil(supportDistanceY / layerHeight); var bottomSkinCount = Math.ceil(bottomThickness/layerHeight); var topSkinCount = Math.ceil(topThickness/layerHeight); var nozzleRadius = nozzleDiameter / 2; @@ -395,58 +396,57 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) { top: this.geometry.boundingBox.min.x * scale, right: this.geometry.boundingBox.max.z * scale, bottom: this.geometry.boundingBox.max.x * scale - }, supportSize, true, true); + }, supportGritSize, true, true); var supportAreas = new D3D.Paths([], true); - for (var layer = data.length - 1; layer >= 0; layer --) { - var slice = data[layer]; - + for (var layer = data.length - 1 - supportDistanceLayers; layer >= 0; layer --) { if (supportAreas.length > 0) { - var currentSkin = new D3D.Paths([], true); - for (var i = 0; i < slice.length; i ++) { - currentSkin.join(slice[i].outerLayer); + + if (layer >= supportDistanceLayers) { + var sliceSkin = new D3D.Paths([], true); + var slice = data[layer - supportDistanceLayers]; + + for (var i = 0; i < slice.length; i ++) { + sliceSkin.join(slice[i].outerLayer); + } + sliceSkin = sliceSkin.offset(supportMargin); + + supportAreas = supportAreas.difference(sliceSkin); } - currentSkin = currentSkin.offset(supportMargin); - supportAreas = supportAreas.difference(currentSkin); + var currentSlice = data[layer]; - slice[0].support = supportTemplate.intersect(supportAreas); + if (layer === 0) { + supportAreas = supportAreas.offset(plateSize).difference(sliceSkin); + + var template = this.getFillTemplate(supportAreas.bounds(), nozzleDiameter, true, false); + + currentSlice[0].support = template.intersect(supportAreas); + } + else { + currentSlice[0].support = supportTemplate.intersect(supportAreas).join(supportAreas.clone()); + } } - if (layer !== 0) { + var supportSlice = data[layer + supportDistanceLayers - 1]; + var supportSkin = new D3D.Paths([], true); + for (var i = 0; i < supportSlice.length; i ++) { + //supportSkin = supportSkin.union(supportSlice[i].outerLayer); + supportSkin.join(supportSlice[i].outerLayer); + } - var supportSkin = new D3D.Paths([], true); - if (layer - 1 >= 0) { - var supportLayer = data[layer - 1]; - for (var i = 0; i < supportLayer.length; i ++) { - supportSkin.join(supportLayer[i].outerLayer); - } - } + var slice = data[layer + supportDistanceLayers]; + for (var i = 0; i < slice.length; i ++) { + var slicePart = slice[i]; + var outerLayer = slicePart.outerLayer; - for (var i = 0; i < slice.length; i ++) { - var slicePart = slice[i]; - var outerLayer = slicePart.outerLayer; + var overlap = supportSkin.offset(supportAccaptanceSize).intersect(outerLayer); + var overhang = outerLayer.difference(overlap); - var overlap = supportSkin.intersect(outerLayer); - var overhang = outerLayer.difference(overlap); - - if (overlap.length === 0) { - var supportArea = overhang.offset(supportOffset); - supportAreas = supportAreas.union(supportArea); - } - else if (overhang.length > 0) { - var areas = overhang.areas(); - - for (var j = 0; j < areas.length; j ++) { - var area = areas[i]; - - if (area > supportMinArea) { - var supportArea = new D3D.Paths([overhang[i]], false).offset(supportOffset); - supportAreas = supportAreas.union(supportArea); - } - } - } + if (overlap.length === 0 || overhang.length > 0) { + var supportArea = outerLayer.difference(supportSkin.intersect(outerLayer)); + supportAreas = supportAreas.union(supportArea); } } } @@ -546,10 +546,10 @@ D3D.Slicer.prototype.dataToGCode = function (data, printer) { sliceToGCode(layerPart.outerLayer, false, true); sliceToGCode(layerPart.insets, false, false); - sliceToGCode(layerPart.fill, (layerPart.support === undefined), false); + sliceToGCode(layerPart.fill, true, false); if (layerPart.support !== undefined) { - sliceToGCode(layerPart.support, true, false); + sliceToGCode(layerPart.support, true, true); } } diff --git a/webworker_test.html b/webworker_test.html index e5fec5e..f148bdd 100644 --- a/webworker_test.html +++ b/webworker_test.html @@ -47,19 +47,19 @@ function init () { var scene = createScene(); var localIp = location.hash.substring(1); - //doodleBox = new D3D.Box(localIp); + doodleBox = new D3D.Box(localIp); - //doodleBox.onupdate = function (data) { - // document.getElementById('state').innerHTML = data.state; - // document.getElementById('bed_temp').innerHTML = data.bed; - // document.getElementById('bed_target_temp').innerHTML = data.bed_target; - // document.getElementById('nozzle_temp').innerHTML = data.hotend; - // document.getElementById('nozzle_target_temp').innerHTML = data.hotend_target; - // document.getElementById('current_line').innerHTML = data.current_line; - // document.getElementById('buffered_lines').innerHTML = data.buffered_lines; - // document.getElementById('total_lines').innerHTML = data.total_lines; - // document.getElementById('print_batches').innerHTML = doodleBox.printBatches.length; - //}; + doodleBox.onupdate = function (data) { + document.getElementById('state').innerHTML = data.state; + document.getElementById('bed_temp').innerHTML = data.bed; + document.getElementById('bed_target_temp').innerHTML = data.bed_target; + document.getElementById('nozzle_temp').innerHTML = data.hotend; + document.getElementById('nozzle_target_temp').innerHTML = data.hotend_target; + document.getElementById('current_line').innerHTML = data.current_line; + document.getElementById('buffered_lines').innerHTML = data.buffered_lines; + document.getElementById('total_lines').innerHTML = data.total_lines; + document.getElementById('print_batches').innerHTML = doodleBox.printBatches.length; + }; printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS['ultimaker2go']);