From 3141440c425e789b5dc551dcb2f60f2dd3dd9b86 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Wed, 1 Jul 2015 14:51:41 +0200 Subject: [PATCH] move THREE normal function to utils --- library/three.js | 12 ------ settings/printer_settings.json | 2 +- src/box.js | 1 + src/paths.js | 2 +- src/slicer.js | 75 +++++++++++++++++++++------------- src/utils.js | 12 ++++++ 6 files changed, 61 insertions(+), 43 deletions(-) diff --git a/library/three.js b/library/three.js index f589aff..927aef4 100644 --- a/library/three.js +++ b/library/three.js @@ -1578,18 +1578,6 @@ THREE.Vector2.prototype = { return new THREE.Vector2( this.x, this.y ); - }, - - normal : function () { - - var x = this.y; - var y = -this.x; - - this.x = x; - this.y = y; - - return this; - } }; diff --git a/settings/printer_settings.json b/settings/printer_settings.json index fd84b9c..2fe6e21 100644 --- a/settings/printer_settings.json +++ b/settings/printer_settings.json @@ -36,7 +36,7 @@ "dimensionsX": 120, "dimensionsY": 120, "dimensionsZ": 115, - "endCode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)\n", + "endCode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)\n", "filamentThickness": 2.85, "heatedBed": false, "heatupBedTemperature": 70, diff --git a/src/box.js b/src/box.js index ff7027c..05cac3f 100644 --- a/src/box.js +++ b/src/box.js @@ -82,6 +82,7 @@ D3D.Box.prototype.init = function () { }; D3D.Box.prototype._updateLoop = function () { "use strict"; + console.log("loop", this.status["buffered_lines"]); var scope = this; //TODO //Code is zo op gezet dat maar api call te gelijk is diff --git a/src/paths.js b/src/paths.js index 9ee7d89..80e1e48 100644 --- a/src/paths.js +++ b/src/paths.js @@ -66,7 +66,7 @@ D3D.Paths.prototype.offset = function (offset) { var solution = new ClipperLib.Paths(); var co = new ClipperLib.ClipperOffset(1, 1); - co.AddPaths(this, ClipperLib.JoinType.jtMiter, ClipperLib.EndType.etClosedPolygon); + co.AddPaths(this, ClipperLib.JoinType.jtSquare, ClipperLib.EndType.etClosedPolygon); co.Execute(solution, offset); return new D3D.Paths(solution); diff --git a/src/slicer.js b/src/slicer.js index b5d531e..537031c 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -8,12 +8,13 @@ D3D.Slicer = function () { "use strict"; this.progress = { - totalFaces: 0, - currentFace: 0, - totalLayers: 0, - sliceLayer: 0, - dataLayer: 0, - gcodeLayer: 0 + createdLines: false, + sliced: false, + generatedInnerLines: false, + generatedInfills: false, + generatedSupport: false, + optimizedPaths: false, + generatedGCode: false }; }; D3D.Slicer.prototype.setMesh = function (geometry, matrix) { @@ -76,24 +77,28 @@ D3D.Slicer.prototype.getGCode = function (printer) { }; D3D.Slicer.prototype._updateProgress = function () { 'use strict'; - - var faces = this.progress.currentFace / (this.progress.totalFaces - 1); - var slice = this.progress.sliceLayer / (this.progress.totalLayers - 1); - var data = this.progress.dataLayer / (this.progress.totalLayers - 2); - var gcode = this.progress.gcodeLayer / (this.progress.totalLayers - 2); - this.progress.procent = (faces + slice + data + gcode) / 4; + var progress = {}; + + var procent = 0; + var length = 0; + for (var i in this.progress) { + progress[i] = this.progress[i]; + procent += this.progress[i] ? 1 : 0; + length ++; + } + + console.log(procent, length); + progress.procent = procent / length; if (this.onProgress !== undefined) { - this.onProgress(this.progress); + this.onProgress(progress); } }; D3D.Slicer.prototype._createLines = function () { "use strict"; - this.progress.totalFaces = this.geometry.faces.length; - this._lines = []; var lineLookup = {}; @@ -136,10 +141,10 @@ D3D.Slicer.prototype._createLines = function () { this._lines[b].normals.push(normal); this._lines[c].normals.push(normal); } - - this.progress.currentFace = i; - this._updateProgress(); } + + this.progress.createdLines = true; + this._updateProgress(); }; D3D.Slicer.prototype._slice = function (layerHeight, height) { "use strict"; @@ -287,13 +292,13 @@ D3D.Slicer.prototype._slice = function (layerHeight, height) { pathData: slice.parts }); } - - this.progress.sliceLayer = layer; - this._updateProgress(); } } - console.log(JSON.stringify(testData)); + //console.log(JSON.stringify(testData)); + + this.progress.sliced = true; + this._updateProgress(); return slices; }; @@ -316,7 +321,7 @@ D3D.Slicer.prototype._generateInnerLines = function (slices, printer) { for (var i = 0; i < slice.parts.length; i ++) { var part = slice.parts[i]; - var outerLine = part.intersect.clone().scaleUp(scale).offset(-nozzleRadius); + var outerLine = part.intersect.clone().scaleUp(scale); if (outerLine.length > 0) { part.outerLine = outerLine; @@ -334,6 +339,9 @@ D3D.Slicer.prototype._generateInnerLines = function (slices, printer) { } } } + + this.progress.generatedInnerLines = true; + this._updateProgress(); }; D3D.Slicer.prototype._generateInfills = function (slices, printer) { "use strict"; @@ -401,10 +409,10 @@ D3D.Slicer.prototype._generateInfills = function (slices, printer) { } } } - - this.progress.dataLayer = layer; - this._updateProgress(); } + + this.progress.generatedInfills = true; + this._updateProgress(); }; D3D.Slicer.prototype._generateSupport = function (slices, printer) { "use strict"; @@ -466,6 +474,10 @@ D3D.Slicer.prototype._generateSupport = function (slices, printer) { } } } + + this.progress.generatedSupport = true; + this._updateProgress(); + }; D3D.Slicer.prototype._optimizePaths = function (slices, printer) { "use strict"; @@ -506,6 +518,10 @@ D3D.Slicer.prototype._optimizePaths = function (slices, printer) { slice.brim.scaleDown(scale); } } + + this.progress.optimizedPaths = true; + this._updateProgress(); + } D3D.Slicer.prototype._getFillTemplate = function (bounds, size, even, uneven) { "use strict"; @@ -599,10 +615,11 @@ D3D.Slicer.prototype._slicesToGCode = function (slices, printer) { if (slice.support !== undefined) { pathToGCode(slice.support, true, true, "support"); } - - this.progress.gcodeLayer = layer; - this._updateProgress(); } + this.progress.generatedGCode = true; + this._updateProgress(); + + return gcode.getGCode(); }; \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index 9b1b73a..f2058f4 100644 --- a/src/utils.js +++ b/src/utils.js @@ -11,6 +11,18 @@ var D3D = { 'contact': 'develop@doodle3d.com' }; +THREE.Vector2.prototype.normal = function () { + "use strict"; + + var x = this.y; + var y = -this.x; + + this.x = x; + this.y = y; + + return this; +}; + function sendAPI (url, data, callback) { 'use strict';