added benchmark for web workers

This commit is contained in:
casperlamboo 2015-05-29 10:41:44 +02:00
parent e75db6d5bd
commit 32dc7df061
11 changed files with 4060 additions and 26 deletions

3919
library/benchmark.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9342,6 +9342,21 @@ THREE.BufferGeometry.prototype = {
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

Binary file not shown.

View File

@ -1,18 +1,18 @@
{
"printer.normalFlowRate": 1.0,
"printer.bottomFlowRate": 2.0,
"printer.bottomLayerSpeed": 35,
"printer.bottomLayerSpeed": 35.0,
"printer.bottomThickness": 0.4,
"printer.fillSize": 5,
"printer.fillSize": 10.0,
"printer.firstLayerSlow": true,
"printer.layerHeight": 0.2,
"printer.retraction.amount": 3,
"printer.retraction.amount": 3.0,
"printer.retraction.enabled": true,
"printer.retraction.speed": 50,
"printer.retraction.minDistance": 5,
"printer.retraction.minDistance": 5.0,
"printer.shellThickness": 0.4,
"printer.speed": 50,
"printer.temperature": 230,
"printer.speed": 50.0,
"printer.temperature": 230.0,
"printer.topThickness": 0.8,
"printer.travelSpeed": 200
"printer.travelSpeed": 200.0
}

View File

@ -30,12 +30,12 @@ function init () {
var scene = createScene();
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 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.SphereGeometry(10, 20, 10);
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);

View File

@ -19,11 +19,12 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
"use strict";
//convert buffergeometry to geometry;
if (geometry instanceof THREE.BufferGeometry) {
geometry = new THREE.Geometry().fromBufferGeometry(geometry);
}
//if (geometry instanceof THREE.BufferGeometry) {
// geometry = new THREE.Geometry().fromBufferGeometry(geometry);
//}
//remove duplicate vertices;
/*
for (var i = 0; i < geometry.vertices.length; i ++) {
var vertexA = geometry.vertices[i];
@ -35,6 +36,7 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
}
}
}
*/
geometry.mergeVertices();
//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);
for (var layerIndex = min; layerIndex <= max; layerIndex ++) {
if (layerIndex >= 0) {
if (layerIndex >= 0 && layerIndex < height / layerHeight) {
if (layersIntersections[layerIndex] === undefined) {
layersIntersections[layerIndex] = [];
}
@ -127,7 +129,7 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
for (var layer = 1; layer < layersIntersections.length-1; layer ++) {
//for (var layer = 0; layer < layersIntersections.length; layer ++) {
var layerIntersections = layersIntersections[layer];
var y = layer*layerHeight;
var y = layer * layerHeight;
var intersections = [];
for (var i = 0; i < layerIntersections.length; i ++) {

View File

@ -5,6 +5,7 @@ D3D.SlicerWorker = function () {
this.worker.addEventListener('message', function (event) {
console.log(event);
gcode = event.data;
}, false);
}
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);
}
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();
this.worker.postMessage({
"cmd": "SET_MESH",
"geometry": geometry.toJSON().data,
"geometry": geometry,
"matrix": mesh.matrix.toArray()
});
}, buffers);
};
D3D.SlicerWorker.prototype.slice = function () {
"use strict";

9
webworker/benchmark.js Normal file
View File

@ -0,0 +1,9 @@
self.addEventListener("message", function (event) {
"use strict";
//console.log(event.data);
if (event.data === "close") {
self.close();
}
});

View File

@ -8,34 +8,38 @@ importScripts("../src/slicer.js");
var printer = new D3D.Printer();
var slicer = new D3D.Slicer();
self.addEventListener('message', function (event) {
self.addEventListener("message", function (event) {
"use strict";
switch (event.data["cmd"]) {
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"]);
slicer.setMesh(geometry, matrix);
break;
case "SET_SETTINGS":
printer.updateConfig(event.data["USER_SETTINGS"]);
printer.updateConfig(event.data["PRINTER_SETTINGS"]);
console.log(printer);
break;
case "SLICE":
var gcode = slicer.getGcode(printer);
self.postMessage('gcode generated');
self.postMessage(gcode);
break;
case "CLOSE":
self.close();
break;
default:
//console.log(event);
break;
}
});

74
webworker_benchmark.html Normal file
View 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>

View File

@ -42,6 +42,7 @@ function init () {
mesh.rotation.x = -Math.PI/2;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
mesh.position.y = -9.260265119962973e-17;
mesh.position.x = 100;
mesh.position.z = 100;
@ -49,6 +50,8 @@ function init () {
slicer.setMesh(mesh);
slicer.slice();
slicer.close();
});
}