mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 19:43:48 +01:00
added setMesh and setGeometry
This commit is contained in:
parent
40cfcd4579
commit
890bc8bb56
@ -78,7 +78,7 @@ function init () {
|
|||||||
|
|
||||||
scene.add(mesh);
|
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 canvas = document.getElementById("canvas");
|
||||||
//var context = canvas.getContext("2d");
|
//var context = canvas.getContext("2d");
|
||||||
|
10
src/box.js
10
src/box.js
@ -3,15 +3,10 @@
|
|||||||
* WiFi-Box
|
* WiFi-Box
|
||||||
* Representation of de Doodle3D-WiFi Box
|
* Representation of de Doodle3D-WiFi Box
|
||||||
* Handles all communication with the doodle box
|
* Handles all communication with the doodle box
|
||||||
* JavaScript shell for api communication
|
|
||||||
* Check http://www.doodle3d.com/help/api-documentation
|
* 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) {
|
D3D.Box = function (localIp) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var scope = this;
|
var scope = this;
|
||||||
@ -82,12 +77,7 @@ D3D.Box.prototype.init = function () {
|
|||||||
};
|
};
|
||||||
D3D.Box.prototype._updateLoop = function () {
|
D3D.Box.prototype._updateLoop = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
console.log("loop", this.status["buffered_lines"]);
|
|
||||||
var scope = this;
|
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 && (this.status["buffered_lines"] + this._printBatches[0].length) <= this.maxBufferedLines) {
|
||||||
//if (this._printBatches.length > 0 ) {
|
//if (this._printBatches.length > 0 ) {
|
||||||
|
@ -24,7 +24,7 @@ D3D.GCode = function () {
|
|||||||
D3D.GCode.prototype._addGCode = function (command) {
|
D3D.GCode.prototype._addGCode = function (command) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var str = [];
|
var str = "";
|
||||||
var first = true;
|
var first = true;
|
||||||
|
|
||||||
for (var i in command) {
|
for (var i in command) {
|
||||||
|
114
src/slicer.js
114
src/slicer.js
@ -17,7 +17,14 @@ D3D.Slicer = function () {
|
|||||||
generatedGCode: false
|
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";
|
"use strict";
|
||||||
|
|
||||||
//convert buffergeometry to geometry;
|
//convert buffergeometry to geometry;
|
||||||
@ -46,15 +53,12 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
|
|||||||
};
|
};
|
||||||
D3D.Slicer.prototype.getGCode = function (printer) {
|
D3D.Slicer.prototype.getGCode = function (printer) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var layerHeight = printer.config["layerHeight"];
|
|
||||||
var dimensionsZ = printer.config["dimensionsZ"];
|
|
||||||
var useSupport = printer.config["supportUse"];
|
var useSupport = printer.config["supportUse"];
|
||||||
|
|
||||||
//get unique lines from geometry;
|
//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);
|
this._generateInnerLines(slices, printer);
|
||||||
|
|
||||||
@ -70,36 +74,10 @@ D3D.Slicer.prototype.getGCode = function (printer) {
|
|||||||
|
|
||||||
return gcode;
|
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) {
|
D3D.Slicer.prototype._createLines = function (printer) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this._lines = [];
|
var lines = [];
|
||||||
var lineLookup = {};
|
var lineLookup = {};
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -107,10 +85,10 @@ D3D.Slicer.prototype._createLines = function (printer) {
|
|||||||
var index = lineLookup[b + "_" + a];
|
var index = lineLookup[b + "_" + a];
|
||||||
|
|
||||||
if (index === undefined) {
|
if (index === undefined) {
|
||||||
index = self._lines.length;
|
index = lines.length;
|
||||||
lineLookup[a + "_" + b] = index;
|
lineLookup[a + "_" + b] = index;
|
||||||
|
|
||||||
self._lines.push({
|
lines.push({
|
||||||
line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]),
|
line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]),
|
||||||
connects: [],
|
connects: [],
|
||||||
normals: []
|
normals: []
|
||||||
@ -133,20 +111,22 @@ D3D.Slicer.prototype._createLines = function (printer) {
|
|||||||
var c = addLine(face.c, face.a);
|
var c = addLine(face.c, face.a);
|
||||||
|
|
||||||
//set connecting lines (based on face)
|
//set connecting lines (based on face)
|
||||||
this._lines[a].connects.push(b, c);
|
lines[a].connects.push(b, c);
|
||||||
this._lines[b].connects.push(c, a);
|
lines[b].connects.push(c, a);
|
||||||
this._lines[c].connects.push(a, b);
|
lines[c].connects.push(a, b);
|
||||||
|
|
||||||
this._lines[a].normals.push(normal);
|
lines[a].normals.push(normal);
|
||||||
this._lines[b].normals.push(normal);
|
lines[b].normals.push(normal);
|
||||||
this._lines[c].normals.push(normal);
|
lines[c].normals.push(normal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.progress.createdLines = true;
|
this.progress.createdLines = true;
|
||||||
this._updateProgress(printer);
|
this._updateProgress(printer);
|
||||||
|
|
||||||
|
return lines;
|
||||||
};
|
};
|
||||||
D3D.Slicer.prototype._slice = function (printer) {
|
D3D.Slicer.prototype._slice = function (lines, printer) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var layerHeight = printer.config["layerHeight"];
|
var layerHeight = printer.config["layerHeight"];
|
||||||
@ -161,8 +141,8 @@ D3D.Slicer.prototype._slice = function (printer) {
|
|||||||
layersIntersections[layer] = [];
|
layersIntersections[layer] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var lineIndex = 0; lineIndex < this._lines.length; lineIndex ++) {
|
for (var lineIndex = 0; lineIndex < lines.length; lineIndex ++) {
|
||||||
var line = this._lines[lineIndex].line;
|
var line = lines[lineIndex].line;
|
||||||
|
|
||||||
var min = Math.ceil(Math.min(line.start.y, line.end.y) / layerHeight);
|
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);
|
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 = [];
|
var intersections = [];
|
||||||
for (var i = 0; i < layerIntersections.length; i ++) {
|
for (var i = 0; i < layerIntersections.length; i ++) {
|
||||||
var index = layerIntersections[i];
|
var index = layerIntersections[i];
|
||||||
var line = this._lines[index].line;
|
var line = lines[index].line;
|
||||||
|
|
||||||
if (line.start.y === line.end.y) {
|
if (line.start.y === line.end.y) {
|
||||||
var x = line.start.x;
|
var x = line.start.x;
|
||||||
@ -203,9 +183,9 @@ D3D.Slicer.prototype._slice = function (printer) {
|
|||||||
/*testPoints.push({
|
/*testPoints.push({
|
||||||
x: z,
|
x: z,
|
||||||
y: x,
|
y: x,
|
||||||
connects: this._lines[index].connects,
|
connects: lines[index].connects,
|
||||||
index: index,
|
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
|
//uppercase X and Y because clipper vector
|
||||||
shape.push({X: intersection.x, Y: intersection.y});
|
shape.push({X: intersection.x, Y: intersection.y});
|
||||||
|
|
||||||
var connects = this._lines[index].connects.clone();
|
var connects = lines[index].connects.clone();
|
||||||
var faceNormals = this._lines[index].normals.clone();
|
var faceNormals = lines[index].normals.clone();
|
||||||
for (var j = 0; j < connects.length; j ++) {
|
for (var j = 0; j < connects.length; j ++) {
|
||||||
index = connects[j];
|
index = connects[j];
|
||||||
|
|
||||||
@ -239,8 +219,8 @@ D3D.Slicer.prototype._slice = function (printer) {
|
|||||||
if (a.distanceTo(b) === 0 || faceNormal.length() === 0) {
|
if (a.distanceTo(b) === 0 || faceNormal.length() === 0) {
|
||||||
done.push(index);
|
done.push(index);
|
||||||
|
|
||||||
connects = connects.concat(this._lines[index].connects);
|
connects = connects.concat(lines[index].connects);
|
||||||
faceNormals = faceNormals.concat(this._lines[index].normals);
|
faceNormals = faceNormals.concat(lines[index].normals);
|
||||||
index = -1;
|
index = -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -387,8 +367,13 @@ D3D.Slicer.prototype._generateInfills = function (slices, printer) {
|
|||||||
|
|
||||||
var fillArea = inset.offset(-nozzleRadius);
|
var fillArea = inset.offset(-nozzleRadius);
|
||||||
if (surroundingLayer) {
|
if (surroundingLayer) {
|
||||||
|
if (infillOverlap === 0) {
|
||||||
|
var highFillArea = fillArea.difference(surroundingLayer).intersect(fillArea);
|
||||||
|
}
|
||||||
|
else {
|
||||||
var highFillArea = fillArea.difference(surroundingLayer).offset(infillOverlap).intersect(fillArea);
|
var highFillArea = fillArea.difference(surroundingLayer).offset(infillOverlap).intersect(fillArea);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
var highFillArea = fillArea;
|
var highFillArea = fillArea;
|
||||||
}
|
}
|
||||||
@ -573,6 +558,8 @@ D3D.Slicer.prototype._slicesToGCode = function (slices, printer) {
|
|||||||
var point = shape[j % shape.length];
|
var point = shape[j % shape.length];
|
||||||
|
|
||||||
if (j === 0) {
|
if (j === 0) {
|
||||||
|
//TODO
|
||||||
|
//moveTo should impliment combing
|
||||||
gcode.moveTo(point.X, point.Y, layer);
|
gcode.moveTo(point.X, point.Y, layer);
|
||||||
|
|
||||||
if (unRetract) {
|
if (unRetract) {
|
||||||
@ -626,3 +613,28 @@ D3D.Slicer.prototype._slicesToGCode = function (slices, printer) {
|
|||||||
|
|
||||||
return gcode.getGCode();
|
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);
|
||||||
|
}
|
||||||
|
};
|
@ -46,11 +46,20 @@ D3D.SlicerWorker.prototype.setSettings = function (USER_SETTINGS, PRINTER_SETTIN
|
|||||||
D3D.SlicerWorker.prototype.setMesh = function (mesh) {
|
D3D.SlicerWorker.prototype.setMesh = function (mesh) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
if (mesh.geometry instanceof THREE.Geometry) {
|
mesh.updateMatrix();
|
||||||
var geometry = new THREE.BufferGeometry().fromGeometry(mesh.geometry);
|
|
||||||
|
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 {
|
else {
|
||||||
var geometry = mesh.geometry.clone();
|
geometry = geometry.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
var buffers = [];
|
var buffers = [];
|
||||||
@ -60,15 +69,13 @@ D3D.SlicerWorker.prototype.setMesh = function (mesh) {
|
|||||||
buffers.push(geometry.attributes[key].array.buffer);
|
buffers.push(geometry.attributes[key].array.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.updateMatrix();
|
|
||||||
|
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
'cmd': 'SET_MESH',
|
'cmd': 'SET_MESH',
|
||||||
'geometry': {
|
'geometry': {
|
||||||
'attributes': geometry.attributes,
|
'attributes': geometry.attributes,
|
||||||
'attributesKeys': geometry.attributesKeys
|
'attributesKeys': geometry.attributesKeys
|
||||||
},
|
},
|
||||||
'matrix': mesh.matrix.toArray()
|
'matrix': matrix.toArray()
|
||||||
}, buffers);
|
}, buffers);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -133,9 +133,6 @@ Sidebar.Slicer = function ( editor ) {
|
|||||||
|
|
||||||
geometryCombined.computeBoundingBox();
|
geometryCombined.computeBoundingBox();
|
||||||
|
|
||||||
var mesh = new THREE.Mesh(geometryCombined, new THREE.MeshBasicMaterial);
|
|
||||||
mesh.position.y = -geometryCombined.boundingBox.min.y;
|
|
||||||
|
|
||||||
var slicer = new D3D.SlicerWorker();
|
var slicer = new D3D.SlicerWorker();
|
||||||
|
|
||||||
slicer.onprogress = function (_progress) {
|
slicer.onprogress = function (_progress) {
|
||||||
@ -162,7 +159,9 @@ Sidebar.Slicer = function ( editor ) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS[selectedPrinter]);
|
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();
|
slicer.slice();
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ self.addEventListener('message', function (event) {
|
|||||||
var geometry = new THREE.Geometry().fromBufferGeometry(event.data['geometry']);
|
var geometry = new THREE.Geometry().fromBufferGeometry(event.data['geometry']);
|
||||||
var matrix = new THREE.Matrix4().fromArray(event.data['matrix']);
|
var matrix = new THREE.Matrix4().fromArray(event.data['matrix']);
|
||||||
|
|
||||||
slicer.setMesh(geometry, matrix);
|
slicer.setGeometry(geometry, matrix);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'SET_SETTINGS':
|
case 'SET_SETTINGS':
|
||||||
|
@ -93,7 +93,7 @@ function init () {
|
|||||||
var loader = new THREE.STLLoader();
|
var loader = new THREE.STLLoader();
|
||||||
loader.load('models/dom.stl', function (geometry) {
|
loader.load('models/dom.stl', function (geometry) {
|
||||||
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
|
//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});
|
var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false});
|
||||||
@ -176,7 +176,7 @@ function createScene () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(function animate () {
|
(function animate () {
|
||||||
//requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user