added progress bar

This commit is contained in:
casperlamboo 2015-05-29 13:51:18 +02:00
parent 32dc7df061
commit 389dcc27d2
8 changed files with 2419 additions and 27 deletions

2329
library/cal.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
"printer.bottomFlowRate": 2.0, "printer.bottomFlowRate": 2.0,
"printer.bottomLayerSpeed": 35.0, "printer.bottomLayerSpeed": 35.0,
"printer.bottomThickness": 0.4, "printer.bottomThickness": 0.4,
"printer.fillSize": 10.0, "printer.fillSize": 5.0,
"printer.firstLayerSlow": true, "printer.firstLayerSlow": true,
"printer.layerHeight": 0.2, "printer.layerHeight": 0.2,
"printer.retraction.amount": 3.0, "printer.retraction.amount": 3.0,

View File

@ -72,14 +72,11 @@ function init () {
mesh.position.x = 100; mesh.position.x = 100;
mesh.position.z = 100; mesh.position.z = 100;
//scene.add(mesh); scene.add(mesh);
mesh.updateMatrix(); mesh.updateMatrix();
var slicer = new D3D.Slicer().setMesh(mesh.geometry, mesh.matrix); var slicer = new D3D.Slicer().setMesh(mesh.geometry, mesh.matrix);
var mesh = new THREE.Mesh(slicer.geometry, material);
scene.add(mesh);
//var canvas = document.getElementById("canvas"); //var canvas = document.getElementById("canvas");
//var context = canvas.getContext("2d"); //var context = canvas.getContext("2d");

View File

@ -14,14 +14,21 @@
D3D.Slicer = function () { D3D.Slicer = function () {
"use strict"; "use strict";
this.progress = {
totalLayers: 0,
sliceLayer: 0,
dataLayer: 0,
gcodeLayer: 0
};
}; };
D3D.Slicer.prototype.setMesh = function (geometry, matrix) { D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
"use strict"; "use strict";
//convert buffergeometry to geometry; //convert buffergeometry to geometry;
//if (geometry instanceof THREE.BufferGeometry) { if (geometry instanceof THREE.BufferGeometry) {
// geometry = new THREE.Geometry().fromBufferGeometry(geometry); geometry = new THREE.Geometry().fromBufferGeometry(geometry);
//} }
//remove duplicate vertices; //remove duplicate vertices;
/* /*
@ -51,6 +58,11 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
return this; return this;
}; };
D3D.Slicer.prototype.updateProgress = function () {
if (this.onProgress !== undefined) {
this.onProgress(this.progress);
}
};
D3D.Slicer.prototype.createLines = function () { D3D.Slicer.prototype.createLines = function () {
"use strict"; "use strict";
@ -70,8 +82,7 @@ D3D.Slicer.prototype.createLines = function () {
self.lines.push({ self.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: []
ignore: 0
}); });
} }
@ -168,12 +179,12 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
var normal = a.sub(b).normal().normalize(); var normal = a.sub(b).normal().normalize();
var faceNormal = faceNormals[Math.floor(j/2)]; var faceNormal = faceNormals[Math.floor(j/2)];
if (normal.dot(faceNormal) > 0) { //if (normal.dot(faceNormal) > 0) {
break; break;
} //}
else { //else {
index = -1; // index = -1;
} //}
} }
else { else {
index = -1; index = -1;
@ -237,6 +248,9 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
else { else {
break; break;
} }
this.progress.sliceLayer = layer;
this.updateProgress();
} }
return slices; return slices;
@ -351,6 +365,9 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
}); });
} }
} }
this.progress.dataLayer = layer;
this.updateProgress();
} }
return data; return data;
@ -481,6 +498,9 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
gcode = gcode.concat(sliceToGcode(layerPart.insets)); gcode = gcode.concat(sliceToGcode(layerPart.insets));
gcode = gcode.concat(sliceToGcode(layerPart.fill)); gcode = gcode.concat(sliceToGcode(layerPart.fill));
} }
this.progress.gcodeLayer = layer;
this.updateProgress();
} }
gcode = gcode.concat(printer.getEndCode()); gcode = gcode.concat(printer.getEndCode());
@ -523,6 +543,11 @@ D3D.Slicer.prototype.getGcode = function (printer) {
var layerHeight = printer.config["printer.layerHeight"]; var layerHeight = printer.config["printer.layerHeight"];
var dimensionsZ = printer.config["printer.dimensions.z"]; var dimensionsZ = printer.config["printer.dimensions.z"];
this.progress.totalLayers = Math.floor(this.geometry.boundingBox.max.y / layerHeight);
this.progress.sliceLayer = 0;
this.progress.dataLayer = 0;
this.progress.gcodeLayer = 0;
var start = new Date().getTime(); var start = new Date().getTime();
var slices = this.slice(layerHeight, dimensionsZ); var slices = this.slice(layerHeight, dimensionsZ);
var end = new Date().getTime(); var end = new Date().getTime();

View File

@ -3,9 +3,21 @@ D3D.SlicerWorker = function () {
this.worker = new Worker('webworker/worker.js'); this.worker = new Worker('webworker/worker.js');
var progressBar = document.getElementById("progress-bar");
var scope = this;
this.worker.addEventListener('message', function (event) { this.worker.addEventListener('message', function (event) {
console.log(event);
gcode = event.data; switch (event.data["cmd"]) {
case "PROGRESS":
var progress = event.data["progress"];
var procent = (progress.sliceLayer + progress.dataLayer + progress.gcodeLayer) / progress.totalLayers / 3;
progressBar.style.width = procent * 100 + "%";
break;
case "GCODE":
gcode = event.data["gcode"];
break;
}
}, false); }, false);
} }
D3D.SlicerWorker.prototype.setSettings = function (USER_SETTINGS, PRINTER_SETTINGS) { D3D.SlicerWorker.prototype.setSettings = function (USER_SETTINGS, PRINTER_SETTINGS) {

View File

@ -7,6 +7,16 @@ importScripts("../src/slicer.js");
var printer = new D3D.Printer(); var printer = new D3D.Printer();
var slicer = new D3D.Slicer(); var slicer = new D3D.Slicer();
slicer.onProgress = function (progress) {
"use strict";
self.postMessage({
"cmd": "PROGRESS",
"progress": progress
});
//console.log(progress);
};
self.addEventListener("message", function (event) { self.addEventListener("message", function (event) {
"use strict"; "use strict";
@ -29,17 +39,15 @@ self.addEventListener("message", function (event) {
case "SLICE": case "SLICE":
var gcode = slicer.getGcode(printer); var gcode = slicer.getGcode(printer);
self.postMessage(gcode); self.postMessage({
"cmd": "GCODE",
"gcode": gcode
});
break; break;
case "CLOSE": case "CLOSE":
self.close(); self.close();
break; break;
default:
//console.log(event);
break;
} }
}); });

View File

@ -0,0 +1,19 @@
----------- RESULTATEN TORUS KNOT --------------
Buffer Geometry x 0.53 ops/sec ±134.70% (8 runs sampled)
Buffer Geometry Transferrable Object x 63.04 ops/sec ±2.19% (67 runs sampled)
Geometry JSON x 0.50 ops/sec ±6.55% (6 runs sampled)
Fastest is "Buffer Geometry Transferrable Object"
----------- RESULTATEN KUBUS --------------
Buffer Geometry x 5,360 ops/sec ±19.42% (85 runs sampled)
Buffer Geometry Transferrable Object x 1,535 ops/sec ±10.17% (35 runs sampled)
Geometry JSON x 3,831 ops/sec ±2.52% (82 runs sampled)
Fastest is "Buffer Geometry"

View File

@ -12,36 +12,38 @@
<title>Doedel Drie Dee || Webworker Test</title> <title>Doedel Drie Dee || Webworker Test</title>
<style> <style>
canvas {border: 1px solid black;} canvas {border: 1px solid black;}
#progress {height: 20px; width: 200px; border: 1px solid black; overflow: hidden;}
#progress-bar {height: 20px; background-color: lightblue; width: 0%;}
</style> </style>
</head> </head>
<body> <body>
<canvas id="3d-preview" height="400" width="400"></canvas> <canvas id="3d-preview" height="400" width="400"></canvas>
<canvas id="canvas" width="400" height="400"></canvas> <canvas id="canvas" width="400" height="400"></canvas>
<div id="progress"><div id="progress-bar"></div></div>
<script> <script>
var USER_SETTINGS, PRINTER_SETTINGS, doodleBox, gcode, slicerWorker; var USER_SETTINGS, PRINTER_SETTINGS, doodleBox, gcode, slicerWorker;
function init () { function init () {
"use strict"; "use strict";
var scene = createScene(); var scene = createScene();
var localIp = location.hash.substring(1); var localIp = location.hash.substring(1);
doodleBox = new D3D.Box(localIp); //doodleBox = new D3D.Box(localIp);
var slicer = new D3D.SlicerWorker(); var slicer = new D3D.SlicerWorker();
slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS["ultimaker"]); slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS["ultimaker"]);
var loader = new THREE.STLLoader(); var loader = new THREE.STLLoader();
loader.load("models/pokemon/pikachu.stl", function (geometry) { loader.load("models/stanford_bunny_high.stl", function (geometry) {
var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false}); var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false});
var mesh = new THREE.Mesh(geometry, material); var mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI/2; mesh.rotation.x = -Math.PI/2;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1; mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.5;
mesh.position.y = -9.260265119962973e-17; mesh.position.y = -9.260265119962973e-17;
mesh.position.x = 100; mesh.position.x = 100;
mesh.position.z = 100; mesh.position.z = 100;