mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 11:33:49 +01:00
added setMesh and setGeometry
This commit is contained in:
parent
40cfcd4579
commit
890bc8bb56
@ -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");
|
||||
|
10
src/box.js
10
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 ) {
|
||||
|
@ -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
src/slicer.js
114
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,8 +367,13 @@ D3D.Slicer.prototype._generateInfills = function (slices, printer) {
|
||||
|
||||
var fillArea = inset.offset(-nozzleRadius);
|
||||
if (surroundingLayer) {
|
||||
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) {
|
||||
@ -626,3 +613,28 @@ 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);
|
||||
}
|
||||
};
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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':
|
||||
|
@ -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);
|
||||
})();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user