mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-19 12:27:56 +01:00
added benchmark for web workers
This commit is contained in:
parent
e75db6d5bd
commit
32dc7df061
3919
library/benchmark.js
Normal file
3919
library/benchmark.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -9342,6 +9342,21 @@ THREE.BufferGeometry.prototype = {
|
|||||||
|
|
||||||
this.dispatchEvent( { type: 'dispose' } );
|
this.dispatchEvent( { type: 'dispose' } );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
getBuffers: function () {
|
||||||
|
|
||||||
|
var buffers = [];
|
||||||
|
|
||||||
|
for ( var i = 0; i < this.attributesKeys.length; i ++ ) {
|
||||||
|
|
||||||
|
var key = this.attributesKeys[ i ];
|
||||||
|
buffers.push( this.attributes[ key ].array.buffer );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffers;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
BIN
models/dom.stl
Normal file
BIN
models/dom.stl
Normal file
Binary file not shown.
@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"printer.normalFlowRate": 1.0,
|
"printer.normalFlowRate": 1.0,
|
||||||
"printer.bottomFlowRate": 2.0,
|
"printer.bottomFlowRate": 2.0,
|
||||||
"printer.bottomLayerSpeed": 35,
|
"printer.bottomLayerSpeed": 35.0,
|
||||||
"printer.bottomThickness": 0.4,
|
"printer.bottomThickness": 0.4,
|
||||||
"printer.fillSize": 5,
|
"printer.fillSize": 10.0,
|
||||||
"printer.firstLayerSlow": true,
|
"printer.firstLayerSlow": true,
|
||||||
"printer.layerHeight": 0.2,
|
"printer.layerHeight": 0.2,
|
||||||
"printer.retraction.amount": 3,
|
"printer.retraction.amount": 3.0,
|
||||||
"printer.retraction.enabled": true,
|
"printer.retraction.enabled": true,
|
||||||
"printer.retraction.speed": 50,
|
"printer.retraction.speed": 50,
|
||||||
"printer.retraction.minDistance": 5,
|
"printer.retraction.minDistance": 5.0,
|
||||||
"printer.shellThickness": 0.4,
|
"printer.shellThickness": 0.4,
|
||||||
"printer.speed": 50,
|
"printer.speed": 50.0,
|
||||||
"printer.temperature": 230,
|
"printer.temperature": 230.0,
|
||||||
"printer.topThickness": 0.8,
|
"printer.topThickness": 0.8,
|
||||||
"printer.travelSpeed": 200
|
"printer.travelSpeed": 200.0
|
||||||
}
|
}
|
@ -30,12 +30,12 @@ function init () {
|
|||||||
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 printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS["ultimaker"]);
|
var printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS["ultimaker"]);
|
||||||
|
|
||||||
var loader = new THREE.STLLoader();
|
var loader = new THREE.STLLoader();
|
||||||
loader.load("models/pokemon/pikachu.stl", function (geometry) {
|
loader.load("models/dom.stl", function (geometry) {
|
||||||
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
||||||
//var geometry = new THREE.SphereGeometry(10, 20, 10);
|
//var geometry = new THREE.SphereGeometry(10, 20, 10);
|
||||||
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
||||||
|
@ -19,11 +19,12 @@ 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;
|
||||||
|
/*
|
||||||
for (var i = 0; i < geometry.vertices.length; i ++) {
|
for (var i = 0; i < geometry.vertices.length; i ++) {
|
||||||
var vertexA = geometry.vertices[i];
|
var vertexA = geometry.vertices[i];
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
geometry.mergeVertices();
|
geometry.mergeVertices();
|
||||||
|
|
||||||
//apply mesh matrix on geometry;
|
//apply mesh matrix on geometry;
|
||||||
@ -111,7 +113,7 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
|
|||||||
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);
|
||||||
|
|
||||||
for (var layerIndex = min; layerIndex <= max; layerIndex ++) {
|
for (var layerIndex = min; layerIndex <= max; layerIndex ++) {
|
||||||
if (layerIndex >= 0) {
|
if (layerIndex >= 0 && layerIndex < height / layerHeight) {
|
||||||
if (layersIntersections[layerIndex] === undefined) {
|
if (layersIntersections[layerIndex] === undefined) {
|
||||||
layersIntersections[layerIndex] = [];
|
layersIntersections[layerIndex] = [];
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ D3D.SlicerWorker = function () {
|
|||||||
|
|
||||||
this.worker.addEventListener('message', function (event) {
|
this.worker.addEventListener('message', function (event) {
|
||||||
console.log(event);
|
console.log(event);
|
||||||
|
gcode = event.data;
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
D3D.SlicerWorker.prototype.setSettings = function (USER_SETTINGS, PRINTER_SETTINGS) {
|
D3D.SlicerWorker.prototype.setSettings = function (USER_SETTINGS, PRINTER_SETTINGS) {
|
||||||
@ -23,16 +24,23 @@ D3D.SlicerWorker.prototype.setMesh = function (mesh) {
|
|||||||
var geometry = new THREE.BufferGeometry().fromGeometry(mesh.geometry);
|
var geometry = new THREE.BufferGeometry().fromGeometry(mesh.geometry);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var geometry = mesh.geometry;
|
var geometry = mesh.geometry.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
var buffers = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < geometry.attributesKeys.length; i ++) {
|
||||||
|
var key = geometry.attributesKeys[i];
|
||||||
|
buffers.push(geometry.attributes[key].array.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.updateMatrix();
|
mesh.updateMatrix();
|
||||||
|
|
||||||
this.worker.postMessage({
|
this.worker.postMessage({
|
||||||
"cmd": "SET_MESH",
|
"cmd": "SET_MESH",
|
||||||
"geometry": geometry.toJSON().data,
|
"geometry": geometry,
|
||||||
"matrix": mesh.matrix.toArray()
|
"matrix": mesh.matrix.toArray()
|
||||||
});
|
}, buffers);
|
||||||
};
|
};
|
||||||
D3D.SlicerWorker.prototype.slice = function () {
|
D3D.SlicerWorker.prototype.slice = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
9
webworker/benchmark.js
Normal file
9
webworker/benchmark.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
self.addEventListener("message", function (event) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
//console.log(event.data);
|
||||||
|
|
||||||
|
if (event.data === "close") {
|
||||||
|
self.close();
|
||||||
|
}
|
||||||
|
});
|
@ -8,34 +8,38 @@ importScripts("../src/slicer.js");
|
|||||||
var printer = new D3D.Printer();
|
var printer = new D3D.Printer();
|
||||||
var slicer = new D3D.Slicer();
|
var slicer = new D3D.Slicer();
|
||||||
|
|
||||||
self.addEventListener('message', function (event) {
|
self.addEventListener("message", function (event) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
switch (event.data["cmd"]) {
|
switch (event.data["cmd"]) {
|
||||||
case "SET_MESH":
|
case "SET_MESH":
|
||||||
var loader = new THREE.BufferGeometryLoader();
|
|
||||||
var geometry = loader.parse(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.setMesh(geometry, matrix);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SET_SETTINGS":
|
case "SET_SETTINGS":
|
||||||
printer.updateConfig(event.data["USER_SETTINGS"]);
|
printer.updateConfig(event.data["USER_SETTINGS"]);
|
||||||
printer.updateConfig(event.data["PRINTER_SETTINGS"]);
|
printer.updateConfig(event.data["PRINTER_SETTINGS"]);
|
||||||
|
|
||||||
console.log(printer);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "SLICE":
|
case "SLICE":
|
||||||
var gcode = slicer.getGcode(printer);
|
var gcode = slicer.getGcode(printer);
|
||||||
|
|
||||||
self.postMessage('gcode generated');
|
self.postMessage(gcode);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "CLOSE":
|
case "CLOSE":
|
||||||
self.close();
|
self.close();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
//console.log(event);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
74
webworker_benchmark.html
Normal file
74
webworker_benchmark.html
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<script src="library/benchmark.js"></script>
|
||||||
|
<script src="library/three.js"></script>
|
||||||
|
|
||||||
|
<title>Doedel Drie Dee || Webworker Benchmark</title>
|
||||||
|
<style>
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var worker = new Worker('webworker/benchmark.js');
|
||||||
|
var geometry = new THREE.BoxGeometry(10, 30, 10).clone();
|
||||||
|
//var geometry = new THREE.TorusKnotGeometry(10, 3, 200, 200).clone();
|
||||||
|
|
||||||
|
new Benchmark.Suite().add('Buffer Geometry', function () {
|
||||||
|
|
||||||
|
var bufferGeometry = new THREE.BufferGeometry().fromGeometry(geometry);
|
||||||
|
|
||||||
|
worker.postMessage(bufferGeometry);
|
||||||
|
|
||||||
|
//this happens in the worker
|
||||||
|
var workerGeometry = new THREE.Geometry().fromBufferGeometry(bufferGeometry);
|
||||||
|
workerGeometry.mergeVertices();
|
||||||
|
|
||||||
|
}).add('Buffer Geometry Transferrable Object', function () {
|
||||||
|
|
||||||
|
var bufferGeometry = new THREE.BufferGeometry().fromGeometry(geometry);
|
||||||
|
|
||||||
|
var buffers = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < bufferGeometry.attributesKeys.length; i ++) {
|
||||||
|
var key = bufferGeometry.attributesKeys[i];
|
||||||
|
buffers.push(bufferGeometry.attributes[key].array.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
worker.postMessage(bufferGeometry, buffers);
|
||||||
|
|
||||||
|
//this happens in the worker
|
||||||
|
//this is redundant...
|
||||||
|
//buffers are transferred to worker so the do not exist in this part of the script
|
||||||
|
//[TEST NOT VIABLE]
|
||||||
|
var workerGeometry = new THREE.Geometry().fromBufferGeometry(bufferGeometry);
|
||||||
|
workerGeometry.mergeVertices();
|
||||||
|
|
||||||
|
}).add('Geometry JSON', function () {
|
||||||
|
|
||||||
|
var json = geometry.toJSON().data;
|
||||||
|
worker.postMessage(json);
|
||||||
|
|
||||||
|
//worker.postMessage(geometry);
|
||||||
|
|
||||||
|
//this happens in the worker
|
||||||
|
var loader = new THREE.JSONLoader();
|
||||||
|
var workerGeometry = loader.parse(json).geometry;
|
||||||
|
workerGeometry.mergeVertices();
|
||||||
|
|
||||||
|
}).on('cycle', function (event) {
|
||||||
|
|
||||||
|
document.body.innerHTML += "<p>" + String(event.target) + "</p>";
|
||||||
|
|
||||||
|
}).on('complete', function () {
|
||||||
|
|
||||||
|
document.body.innerHTML += "<p>" + 'Fastest is "' + this.filter('fastest').pluck('name') + '"' + "</p>";
|
||||||
|
|
||||||
|
}).run({
|
||||||
|
'async': true
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -42,6 +42,7 @@ function init () {
|
|||||||
|
|
||||||
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 = 1;
|
||||||
|
mesh.position.y = -9.260265119962973e-17;
|
||||||
mesh.position.x = 100;
|
mesh.position.x = 100;
|
||||||
mesh.position.z = 100;
|
mesh.position.z = 100;
|
||||||
|
|
||||||
@ -49,6 +50,8 @@ function init () {
|
|||||||
|
|
||||||
slicer.setMesh(mesh);
|
slicer.setMesh(mesh);
|
||||||
slicer.slice();
|
slicer.slice();
|
||||||
|
|
||||||
|
slicer.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user