diff --git a/slice_test.html b/slice_test.html
index 637a997..f6c0270 100644
--- a/slice_test.html
+++ b/slice_test.html
@@ -78,7 +78,7 @@ function init () {
scene.add(mesh);
- var slicer = new D3D.Slicer().setMesh(mesh.geometry, mesh.matrix);
+ var slicer = new D3D.Slicer().setMesh(mesh);
//var canvas = document.getElementById("canvas");
//var context = canvas.getContext("2d");
@@ -96,7 +96,7 @@ function createScene () {
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview"), antialias: true});
renderer.setClearColor(0xffffff, 1);
- var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
+ var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width / renderer.domElement.height, 1, 10000);
scene.add(camera);
var light = new THREE.AmbientLight(0x404040);
diff --git a/src/box.js b/src/box.js
index 05cac3f..fe07035 100644
--- a/src/box.js
+++ b/src/box.js
@@ -3,15 +3,10 @@
* WiFi-Box
* Representation of de Doodle3D-WiFi Box
* Handles all communication with the doodle box
-* JavaScript shell for api communication
* Check http://www.doodle3d.com/help/api-documentation
*
******************************************************/
-//TODO
-//Als meerdere clients met box zouden verbinden zal de api te veel requests krijgen waardoor hij crasht
-//implimentatie van het veranderen van onder andere naam, netwerkverbinding etc
-
D3D.Box = function (localIp) {
"use strict";
var scope = this;
@@ -82,12 +77,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
- //Bij error wordt gelijk zelfde data opnieuw gestuurd
- //Als DoodleBox ontkoppeld wordt komt er een error in de loop waardoor pagina breekt en ververst moet worden
if (this._printBatches.length > 0 && (this.status["buffered_lines"] + this._printBatches[0].length) <= this.maxBufferedLines) {
//if (this._printBatches.length > 0 ) {
diff --git a/src/gcode.js b/src/gcode.js
index 2cf5955..dcff344 100644
--- a/src/gcode.js
+++ b/src/gcode.js
@@ -24,7 +24,7 @@ D3D.GCode = function () {
D3D.GCode.prototype._addGCode = function (command) {
"use strict";
- var str = [];
+ var str = "";
var first = true;
for (var i in command) {
@@ -114,7 +114,7 @@ D3D.GCode.prototype.lineTo = function (x, y, layer, type) {
var lineLength = this._nozzlePosition.distanceTo(newNozzlePosition);
- var filamentSurfaceArea = Math.pow((filamentThickness/2), 2) * Math.PI;
+ var filamentSurfaceArea = Math.pow((filamentThickness / 2), 2) * Math.PI;
this.extruder += lineLength * nozzleDiameter * layerHeight / filamentSurfaceArea * flowRate;
this._addGCode({
diff --git a/src/slicer.js b/src/slicer.js
index 370dcfc..32b71cb 100644
--- a/src/slicer.js
+++ b/src/slicer.js
@@ -17,7 +17,14 @@ D3D.Slicer = function () {
generatedGCode: false
};
};
-D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
+D3D.Slicer.prototype.setMesh = function (mesh) {
+ "use strict";
+
+ this.setGeometry(mesh.geometry, mesh.matrix);
+
+ return this;
+};
+D3D.Slicer.prototype.setGeometry = function (geometry, matrix) {
"use strict";
//convert buffergeometry to geometry;
@@ -46,15 +53,12 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
};
D3D.Slicer.prototype.getGCode = function (printer) {
"use strict";
-
- var layerHeight = printer.config["layerHeight"];
- var dimensionsZ = printer.config["dimensionsZ"];
var useSupport = printer.config["supportUse"];
//get unique lines from geometry;
- this._createLines(printer);
+ var lines = this._createLines(printer);
- var slices = this._slice(printer);
+ var slices = this._slice(lines, printer);
this._generateInnerLines(slices, printer);
@@ -70,36 +74,10 @@ D3D.Slicer.prototype.getGCode = function (printer) {
return gcode;
};
-D3D.Slicer.prototype._updateProgress = function () {
- 'use strict';
-
- var useSupport = printer.config["supportUse"];
-
- var progress = {};
-
- var procent = 0;
- var length = 0;
- for (var i in this.progress) {
- if (!(!useSupport && i === "generatedSupport")) {
- progress[i] = this.progress[i];
- if (this.progress[i]) {
- procent ++;
- }
- length ++;
- }
- }
-
- progress.procent = procent / length;
-
- if (this.onProgress !== undefined) {
-
- this.onProgress(progress);
- }
-};
D3D.Slicer.prototype._createLines = function (printer) {
"use strict";
- this._lines = [];
+ var lines = [];
var lineLookup = {};
var self = this;
@@ -107,10 +85,10 @@ D3D.Slicer.prototype._createLines = function (printer) {
var index = lineLookup[b + "_" + a];
if (index === undefined) {
- index = self._lines.length;
+ index = lines.length;
lineLookup[a + "_" + b] = index;
- self._lines.push({
+ lines.push({
line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]),
connects: [],
normals: []
@@ -133,20 +111,22 @@ D3D.Slicer.prototype._createLines = function (printer) {
var c = addLine(face.c, face.a);
//set connecting lines (based on face)
- this._lines[a].connects.push(b, c);
- this._lines[b].connects.push(c, a);
- this._lines[c].connects.push(a, b);
+ lines[a].connects.push(b, c);
+ lines[b].connects.push(c, a);
+ lines[c].connects.push(a, b);
- this._lines[a].normals.push(normal);
- this._lines[b].normals.push(normal);
- this._lines[c].normals.push(normal);
+ lines[a].normals.push(normal);
+ lines[b].normals.push(normal);
+ lines[c].normals.push(normal);
}
}
this.progress.createdLines = true;
this._updateProgress(printer);
+
+ return lines;
};
-D3D.Slicer.prototype._slice = function (printer) {
+D3D.Slicer.prototype._slice = function (lines, printer) {
"use strict";
var layerHeight = printer.config["layerHeight"];
@@ -161,8 +141,8 @@ D3D.Slicer.prototype._slice = function (printer) {
layersIntersections[layer] = [];
}
- for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex ++) {
- var line = this._lines[lineIndex].line;
+ for (var lineIndex = 0; lineIndex < lines.length; lineIndex ++) {
+ var line = lines[lineIndex].line;
var min = Math.ceil(Math.min(line.start.y, line.end.y) / layerHeight);
var max = Math.floor(Math.max(line.start.y, line.end.y) / layerHeight);
@@ -187,7 +167,7 @@ D3D.Slicer.prototype._slice = function (printer) {
var intersections = [];
for (var i = 0; i < layerIntersections.length; i ++) {
var index = layerIntersections[i];
- var line = this._lines[index].line;
+ var line = lines[index].line;
if (line.start.y === line.end.y) {
var x = line.start.x;
@@ -203,9 +183,9 @@ D3D.Slicer.prototype._slice = function (printer) {
/*testPoints.push({
x: z,
y: x,
- connects: this._lines[index].connects,
+ connects: lines[index].connects,
index: index,
- normals: this._lines[index].normals
+ normals: lines[index].normals
});*/
}
@@ -224,8 +204,8 @@ D3D.Slicer.prototype._slice = function (printer) {
//uppercase X and Y because clipper vector
shape.push({X: intersection.x, Y: intersection.y});
- var connects = this._lines[index].connects.clone();
- var faceNormals = this._lines[index].normals.clone();
+ var connects = lines[index].connects.clone();
+ var faceNormals = lines[index].normals.clone();
for (var j = 0; j < connects.length; j ++) {
index = connects[j];
@@ -239,8 +219,8 @@ D3D.Slicer.prototype._slice = function (printer) {
if (a.distanceTo(b) === 0 || faceNormal.length() === 0) {
done.push(index);
- connects = connects.concat(this._lines[index].connects);
- faceNormals = faceNormals.concat(this._lines[index].normals);
+ connects = connects.concat(lines[index].connects);
+ faceNormals = faceNormals.concat(lines[index].normals);
index = -1;
}
else {
@@ -387,7 +367,12 @@ D3D.Slicer.prototype._generateInfills = function (slices, printer) {
var fillArea = inset.offset(-nozzleRadius);
if (surroundingLayer) {
- var highFillArea = fillArea.difference(surroundingLayer).offset(infillOverlap).intersect(fillArea);
+ if (infillOverlap === 0) {
+ var highFillArea = fillArea.difference(surroundingLayer).intersect(fillArea);
+ }
+ else {
+ var highFillArea = fillArea.difference(surroundingLayer).offset(infillOverlap).intersect(fillArea);
+ }
}
else {
var highFillArea = fillArea;
@@ -573,6 +558,8 @@ D3D.Slicer.prototype._slicesToGCode = function (slices, printer) {
var point = shape[j % shape.length];
if (j === 0) {
+ //TODO
+ //moveTo should impliment combing
gcode.moveTo(point.X, point.Y, layer);
if (unRetract) {
@@ -625,4 +612,29 @@ D3D.Slicer.prototype._slicesToGCode = function (slices, printer) {
return gcode.getGCode();
+};
+D3D.Slicer.prototype._updateProgress = function () {
+ 'use strict';
+
+ if (this.onProgress !== undefined) {
+ var useSupport = printer.config["supportUse"];
+
+ var progress = {};
+
+ var procent = 0;
+ var length = 0;
+ for (var i in this.progress) {
+ if (!(!useSupport && i === "generatedSupport")) {
+ progress[i] = this.progress[i];
+ if (this.progress[i]) {
+ procent ++;
+ }
+ length ++;
+ }
+ }
+
+ progress.procent = procent / length;
+
+ this.onProgress(progress);
+ }
};
\ No newline at end of file
diff --git a/src/slicerworker.js b/src/slicerworker.js
index 81e633b..b387b54 100644
--- a/src/slicerworker.js
+++ b/src/slicerworker.js
@@ -46,11 +46,20 @@ D3D.SlicerWorker.prototype.setSettings = function (USER_SETTINGS, PRINTER_SETTIN
D3D.SlicerWorker.prototype.setMesh = function (mesh) {
'use strict';
- if (mesh.geometry instanceof THREE.Geometry) {
- var geometry = new THREE.BufferGeometry().fromGeometry(mesh.geometry);
+ mesh.updateMatrix();
+
+ this.setGeometry(mesh.geometry, mesh.matrix);
+
+ return this;
+};
+D3D.SlicerWorker.prototype.setGeometry = function (geometry, matrix) {
+ 'use strict';
+
+ if (geometry instanceof THREE.Geometry) {
+ geometry = new THREE.BufferGeometry().fromGeometry(geometry);
}
else {
- var geometry = mesh.geometry.clone();
+ geometry = geometry.clone();
}
var buffers = [];
@@ -60,15 +69,13 @@ D3D.SlicerWorker.prototype.setMesh = function (mesh) {
buffers.push(geometry.attributes[key].array.buffer);
}
- mesh.updateMatrix();
-
this.worker.postMessage({
'cmd': 'SET_MESH',
'geometry': {
'attributes': geometry.attributes,
'attributesKeys': geometry.attributesKeys
},
- 'matrix': mesh.matrix.toArray()
+ 'matrix': matrix.toArray()
}, buffers);
return this;
diff --git a/src/utils.js b/src/utils.js
index f2058f4..a6467b2 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -73,7 +73,7 @@ function getAPI (url, callback) {
function downloadFile (file, data) {
'use strict';
- var blob = new Blob([data], {type:'text/plain'});
+ var blob = new Blob([data], {type: 'text/plain'});
var button = document.createElement('a');
button.download = file;
diff --git a/three.js-master/editor_slicer/js/Sidebar.Slicer.js b/three.js-master/editor_slicer/js/Sidebar.Slicer.js
index 71d049a..6f09ae8 100644
--- a/three.js-master/editor_slicer/js/Sidebar.Slicer.js
+++ b/three.js-master/editor_slicer/js/Sidebar.Slicer.js
@@ -133,9 +133,6 @@ Sidebar.Slicer = function ( editor ) {
geometryCombined.computeBoundingBox();
- var mesh = new THREE.Mesh(geometryCombined, new THREE.MeshBasicMaterial);
- mesh.position.y = -geometryCombined.boundingBox.min.y;
-
var slicer = new D3D.SlicerWorker();
slicer.onprogress = function (_progress) {
@@ -162,7 +159,9 @@ Sidebar.Slicer = function ( editor ) {
};
slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS[selectedPrinter]);
- slicer.setMesh(mesh);
+
+ var matrix = new THREE.Matrix().setPosition(new THREE.Vector(0, -geometryCombined.boundingBox.min.y, 0));
+ slicer.setGeometry(geometryCombined, matrix);
slicer.slice();
diff --git a/webworker/worker.js b/webworker/worker.js
index 8b321d1..a6ef410 100644
--- a/webworker/worker.js
+++ b/webworker/worker.js
@@ -30,7 +30,7 @@ self.addEventListener('message', function (event) {
var geometry = new THREE.Geometry().fromBufferGeometry(event.data['geometry']);
var matrix = new THREE.Matrix4().fromArray(event.data['matrix']);
- slicer.setMesh(geometry, matrix);
+ slicer.setGeometry(geometry, matrix);
break;
case 'SET_SETTINGS':
diff --git a/webworker_test.html b/webworker_test.html
index 37ccf07..f4bb086 100644
--- a/webworker_test.html
+++ b/webworker_test.html
@@ -93,7 +93,7 @@ function init () {
var loader = new THREE.STLLoader();
loader.load('models/dom.stl', function (geometry) {
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
- var geometry = new THREE.TorusKnotGeometry( 100, 43, 64, 8 );
+ //var geometry = new THREE.TorusKnotGeometry( 100, 43, 64, 8 );
var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false});
@@ -176,7 +176,7 @@ function createScene () {
}
(function animate () {
- //requestAnimationFrame(animate);
+ requestAnimationFrame(animate);
renderer.render(scene, camera);
})();