Added slice abstraction to Slice class

This commit is contained in:
casperlamboo 2015-06-11 14:34:30 +02:00 committed by Simon Voordouw
parent ccd650c533
commit 75d4d4758a
11 changed files with 221 additions and 262 deletions

View File

@ -11,7 +11,8 @@
"printer.retraction.speed": 50, "printer.retraction.speed": 50,
"printer.retraction.minDistance": 5.0, "printer.retraction.minDistance": 5.0,
"printer.shellThickness": 0.4, "printer.shellThickness": 0.4,
"printer.speed": 50.0, "printer.speed": 50.0,
"printer.brimOffset": 5.0,
"printer.temperature": 210.0, "printer.temperature": 210.0,
"printer.topThickness": 0.8, "printer.topThickness": 0.8,
"printer.travelSpeed": 200.0, "printer.travelSpeed": 200.0,

View File

@ -14,6 +14,7 @@
<script src="src/paths.js"></script> <script src="src/paths.js"></script>
<script src="src/gcode.js"></script> <script src="src/gcode.js"></script>
<script src="src/slicer.js"></script> <script src="src/slicer.js"></script>
<script src="src/slice.js"></script>
<style> <style>
canvas {border: 1px solid black;} canvas {border: 1px solid black;}
@ -36,7 +37,7 @@ function init () {
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/support_test.stl', function (geometry) { loader.load('models/pokemon/pikachu.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);
@ -159,6 +160,8 @@ function createScene () {
//loadSettings; //loadSettings;
(function () { (function () {
'use strict';
var loadedItems = 0; var loadedItems = 0;
function loaded () { function loaded () {
loadedItems ++; loadedItems ++;
@ -167,13 +170,22 @@ function createScene () {
} }
} }
loadSettings("settings/user_settings.json", function (data) { $.ajax({
USER_SETTINGS = data; url: 'settings/user_settings.json',
loaded(); dataType: 'json',
success: function (response) {
USER_SETTINGS = response;
loaded();
}
}); });
loadSettings("settings/printer_settings.json", function (data) {
PRINTER_SETTINGS = data; $.ajax({
loaded(); url: 'settings/printer_settings.json',
dataType: 'json',
success: function (response) {
PRINTER_SETTINGS = response;
loaded();
}
}); });
})(); })();
</script> </script>

View File

@ -133,10 +133,9 @@ D3D.Box.prototype.print = function (gcode) {
this.currentBatch = 0; this.currentBatch = 0;
//clone gcode to remove array links gcode = gcode.split("\n");
gcode = gcode.clone();
//gcode split in batches //split gcode in batches
while (gcode.length > 0) { while (gcode.length > 0) {
var gcodeBatch = gcode.splice(0, Math.min(this.batchSize, gcode.length)); var gcodeBatch = gcode.splice(0, Math.min(this.batchSize, gcode.length));
this.printBatches.push(gcodeBatch); this.printBatches.push(gcodeBatch);
@ -158,6 +157,7 @@ D3D.Box.prototype.printBatch = function () {
}, function (error, data) { }, function (error, data) {
if (error) { if (error) {
scope.printBatches.unshift(gcode); scope.printBatches.unshift(gcode);
console.warn(error); console.warn(error);
scope.init(); scope.init();

70
src/slice.js Normal file
View File

@ -0,0 +1,70 @@
/******************************************************
*
* Slice
*
******************************************************/
D3D.Slice = function () {
'use strict';
this.parts = [];
};
D3D.Slice.prototype.optimizePaths = function (start) {
'use strict';
if (this.brim !== undefined && this.brim.length > 0) {
this.brim = this.brim.optimizePath(start);
start = this.brim.lastPoint();
}
//instead of for loop pick the closest shape to start;
for (var i = 0; i < this.parts.length; i ++) {
var part = this.parts[i];
if (part.outerLine.length > 0) {
part.outerLine = part.outerLine.optimizePath(start);
start = part.outerLine.lastPoint();
}
for (var j = 0; j < part.innerLines.length; j ++) {
var innerLine = part.innerLines[j];
if (innerLine.length > 0) {
part.innerLines[j] = innerLine.optimizePath(start);
//start = part.innerLines[j].lastPoint();
}
}
if (part.fill.length > 0) {
part.fill = part.fill.optimizePath(start);
start = part.fill.lastPoint();
}
}
if (this.support !== undefined && this.support.length > 0) {
this.support = this.support.optimizePath(start);
//start = this.support.lastPoint();
}
return start;
};
D3D.Slice.prototype.getOutline = function () {
'use strict';
var outLines = new D3D.Paths([], true);
for (var i = 0; i < this.parts.length; i ++) {
outLines.join(this.parts[i].outerLine);
}
return outLines;
};
D3D.Slice.prototype.addIntersect = function (intersect) {
'use strict';
this.parts.push({
intersect: intersect,
innerLines: [],
outerLine: new D3D.Paths([], true),
fill: new D3D.Paths([], false)
});
};

View File

@ -120,6 +120,7 @@ D3D.Slicer.prototype.createLines = function () {
}; };
D3D.Slicer.prototype.slice = function (layerHeight, height) { D3D.Slicer.prototype.slice = function (layerHeight, height) {
"use strict"; "use strict";
var numLayers = height / layerHeight; var numLayers = height / layerHeight;
var layersIntersections = []; var layersIntersections = [];
@ -169,7 +170,7 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
} }
var done = []; var done = [];
var slice = []; var sliceParts = [];
for (var i = 0; i < layerIntersections.length; i ++) { for (var i = 0; i < layerIntersections.length; i ++) {
var index = layerIntersections[i]; var index = layerIntersections[i];
@ -242,39 +243,32 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
//think this check is not nescesary, always higher as 0 //think this check is not nescesary, always higher as 0
if (shape.length > 0) { if (shape.length > 0) {
slice.push(new D3D.Paths([shape], true)); sliceParts.push(new D3D.Paths([shape], true));
} }
} }
} }
var slice = new D3D.Slice();
var layerParts = []; for (var i = 0; i < sliceParts.length; i ++) {
var slicePart1 = sliceParts[i];
for (var i = 0; i < slice.length; i ++) {
var layerPart1 = slice[i];
var merge = false; var merge = false;
for (var j = 0; j < layerParts.length; j ++) { for (var j = 0; j < slice.parts.length; j ++) {
var layerPart2 = layerParts[j]; var slicePart2 = slice.parts[j].intersect;
if (layerPart2.intersect(layerPart1).length > 0) { if (slicePart2.intersect(slicePart1).length > 0) {
layerPart2.join(layerPart1); slicePart2.join(slicePart1);
merge = true; merge = true;
break; break;
} }
} }
if (!merge) { if (!merge) {
layerParts.push(layerPart1); slice.addIntersect(slicePart1);
} }
} }
//stop when ther are no intersects slices.push(slice);
if (layerParts.length > 0) {
slices.push(layerParts);
}
else {
break;
}
this.progress.sliceLayer = layer; this.progress.sliceLayer = layer;
this.updateProgress(); this.updateProgress();
@ -299,6 +293,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
var supportMargin = printer.config["printer.support.margin"] * scale; var supportMargin = printer.config["printer.support.margin"] * scale;
var plateSize = printer.config["printer.support.plateSize"] * scale; var plateSize = printer.config["printer.support.plateSize"] * scale;
var supportDistanceY = printer.config["printer.support.distanceY"]; var supportDistanceY = printer.config["printer.support.distanceY"];
var brimOffset = printer.config["printer.brimOffset"] * scale;
var supportDistanceLayers = Math.ceil(supportDistanceY / layerHeight); var supportDistanceLayers = Math.ceil(supportDistanceY / layerHeight);
var bottomSkinCount = Math.ceil(bottomThickness/layerHeight); var bottomSkinCount = Math.ceil(bottomThickness/layerHeight);
@ -312,81 +307,63 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
bottom: this.geometry.boundingBox.max.x * scale bottom: this.geometry.boundingBox.max.x * scale
}, fillSize, true, true); }, fillSize, true, true);
var data = []; console.log("generating outer lines and inner lines");
//generate outerLayer and insets
for (var layer = 0; layer < slices.length; layer ++) { for (var layer = 0; layer < slices.length; layer ++) {
var slice = slices[layer]; var slice = slices[layer];
var layerData = []; for (var i = 0; i < slice.parts.length; i ++) {
data.push(layerData); var part = slice.parts[i];
for (var i = 0; i < slice.length; i ++) { var outerLine = part.intersect.clone().scaleUp(scale).offset(-nozzleRadius);
var part = slice[i];
var outerLayer = part.clone().scaleUp(scale).offset(-nozzleRadius); if (outerLine.length > 0) {
part.outerLine = outerLine;
var insets = new D3D.Paths([], true);
if (outerLayer.length > 0) {
for (var offset = nozzleDiameter; offset <= shellThickness; offset += nozzleDiameter) { for (var offset = nozzleDiameter; offset <= shellThickness; offset += nozzleDiameter) {
var inset = outerLayer.offset(-offset); var innerLine = outerLine.offset(-offset);
insets.join(inset); if (innerLine.length > 0) {
part.innerLines.push(innerLine);
}
else {
break;
}
} }
layerData.push({
outerLayer: outerLayer,
insets: insets
});
} }
} }
} }
//generate infills console.log("generating infills");
for (var layer = 0; layer < data.length; layer ++) { for (var layer = 0; layer < slices.length; layer ++) {
var slice = data[layer]; var slice = slices[layer];
var downSkin = new D3D.Paths([], true); var downSkin = (layer - bottomSkinCount >= 0) ? slices[layer - bottomSkinCount].getOutline() : new D3D.Paths([], true);
if (layer - bottomSkinCount >= 0) { var upSkin = (layer + topSkinCount < slices.length) ? slices[layer + topSkinCount].getOutline() : new D3D.Paths([], true);
var downLayer = data[layer - bottomSkinCount]; var surroundingLayer = (downSkin.length === 0 || upSkin.length === 0) ? new D3D.Paths([], true) : upSkin.intersect(downSkin);
for (var i = 0; i < downLayer.length; i ++) {
downSkin.join(downLayer[i].outerLayer);
}
}
var upSkin = new D3D.Paths([], true);
if (layer + topSkinCount < data.length) {
var upLayer = data[layer + topSkinCount];
for (var i = 0; i < upLayer.length; i ++) {
upSkin.join(upLayer[i].outerLayer);
}
}
var surroundingLayer = upSkin.intersect(downSkin);
var sliceData = [];
for (var i = 0; i < slice.length; i ++) { for (var i = 0; i < slice.parts.length; i ++) {
var part = slice[i]; var part = slice.parts[i];
var outerLayer = part.outerLayer; var outerLine = part.outerLine;
var insets = part.insets;
if (outerLayer.length > 0) { if (outerLine.length > 0) {
var fillArea = ((insets.length > 0) ? insets : outerLayer).offset(-nozzleRadius); var inset = ((part.innerLines.length > 0) ? part.innerLines[part.innerLines.length - 1] : outerLine);
var fillArea = inset.offset(-nozzleRadius);
var highFillArea = fillArea.difference(surroundingLayer); var highFillArea = fillArea.difference(surroundingLayer);
var lowFillArea = fillArea.difference(highFillArea); var lowFillArea = fillArea.difference(highFillArea);
var fill = new D3D.Paths([], false); var fill = new D3D.Paths([], false);
if (lowFillTemplate.length > 0) { if (lowFillTemplate.length > 0) {
fill.join(lowFillTemplate.intersect(lowFillArea)); part.fill.join(lowFillTemplate.intersect(lowFillArea));
} }
if (highFillArea.length > 0) { if (highFillArea.length > 0) {
var bounds = highFillArea.bounds(); var bounds = highFillArea.bounds();
var even = (layer % 2 === 0); var even = (layer % 2 === 0);
var highFillTemplate = this.getFillTemplate(bounds, nozzleDiameter, even, !even); var highFillTemplate = this.getFillTemplate(bounds, nozzleDiameter, even, !even);
fill.join(highFillTemplate.intersect(highFillArea)); part.fill.join(highFillTemplate.intersect(highFillArea));
} }
part.fill = fill;
} }
} }
@ -394,8 +371,9 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
this.updateProgress(); this.updateProgress();
} }
//generate support
if (useSupport) { if (useSupport) {
console.log("generating support");
var supportTemplate = this.getFillTemplate({ var supportTemplate = this.getFillTemplate({
left: this.geometry.boundingBox.min.z * scale, left: this.geometry.boundingBox.min.z * scale,
top: this.geometry.boundingBox.min.x * scale, top: this.geometry.boundingBox.min.x * scale,
@ -405,90 +383,84 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
var supportAreas = new D3D.Paths([], true); var supportAreas = new D3D.Paths([], true);
for (var layer = data.length - 1 - supportDistanceLayers; layer >= 0; layer --) { for (var layer = slices.length - 1 - supportDistanceLayers; layer >= 0; layer --) {
if (supportAreas.length > 0) { if (supportAreas.length > 0) {
if (layer >= supportDistanceLayers) { if (layer >= supportDistanceLayers) {
var sliceSkin = new D3D.Paths([], true); var sliceSkin = slices[layer - supportDistanceLayers].getOutline();
var slice = data[layer - supportDistanceLayers];
for (var i = 0; i < slice.length; i ++) {
sliceSkin.join(slice[i].outerLayer);
}
sliceSkin = sliceSkin.offset(supportMargin); sliceSkin = sliceSkin.offset(supportMargin);
supportAreas = supportAreas.difference(sliceSkin); supportAreas = supportAreas.difference(sliceSkin);
} }
var currentSlice = data[layer]; var currentSlice = slices[layer];
if (layer === 0) { if (layer === 0) {
supportAreas = supportAreas.offset(plateSize).difference(sliceSkin); supportAreas = supportAreas.offset(plateSize).difference(sliceSkin);
var template = this.getFillTemplate(supportAreas.bounds(), nozzleDiameter, true, false); var template = this.getFillTemplate(supportAreas.bounds(), nozzleDiameter, true, false);
currentSlice[0].support = template.intersect(supportAreas); currentSlice.support = template.intersect(supportAreas);
} }
else { else {
currentSlice[0].support = supportTemplate.intersect(supportAreas).join(supportAreas.clone()); currentSlice.support = supportTemplate.intersect(supportAreas).join(supportAreas.clone());
} }
} }
var supportSlice = data[layer + supportDistanceLayers - 1]; var supportSkin = slices[layer + supportDistanceLayers - 1].getOutline();
var supportSkin = new D3D.Paths([], true);
for (var i = 0; i < supportSlice.length; i ++) {
//supportSkin = supportSkin.union(supportSlice[i].outerLayer);
supportSkin.join(supportSlice[i].outerLayer);
}
var slice = data[layer + supportDistanceLayers]; var slice = slices[layer + supportDistanceLayers];
for (var i = 0; i < slice.length; i ++) { for (var i = 0; i < slice.parts.length; i ++) {
var slicePart = slice[i]; var slicePart = slice.parts[i];
var outerLayer = slicePart.outerLayer; var outerLine = slicePart.outerLine;
var overlap = supportSkin.offset(supportAccaptanceMargin).intersect(outerLayer); var overlap = supportSkin.offset(supportAccaptanceMargin).intersect(outerLine);
var overhang = outerLayer.difference(overlap); var overhang = outerLine.difference(overlap);
if (overlap.length === 0 || overhang.length > 0) { if (overlap.length === 0 || overhang.length > 0) {
//var supportArea = outerLayer.difference(supportSkin.intersect(outerLayer)); //var supportArea = outerLine.difference(supportSkin.intersect(outerLine));
//supportAreas = supportAreas.union(supportArea); //supportAreas = supportAreas.union(supportArea);
//supportAreas = supportAreas.union(overhang); //supportAreas = supportAreas.union(overhang);
supportAreas = supportAreas.union(overhang.offset(supportAccaptanceMargin).intersect(outerLayer)); supportAreas = supportAreas.union(overhang.offset(supportAccaptanceMargin).intersect(outerLine));
} }
} }
} }
} }
//finalize paths console.log("opimize paths");
var start = new THREE.Vector2(0, 0); var start = new THREE.Vector2(0, 0);
var order = ["outerLayer", "insets", "fill", "support"];
for (var layer = 0; layer < data.length; layer ++) { for (var layer = 0; layer < slices.length; layer ++) {
var slice = data[layer]; var slice = slices[layer];
for (var i = 0; i < slice.length; i ++) { if (layer === 0) {
var part = slice[i]; slice.brim = slice.getOutline().offset(brimOffset);
}
for (var j = 0; j < order.length; j ++) { var start = slice.optimizePaths(start);
var property = order[j];
if (part[property] !== undefined && part[property].length > 0) { for (var i = 0; i < slice.parts.length; i ++) {
part[property] = part[property].optimizePath(start); var part = slice.parts[i];
start = part[property].lastPoint();
} part.outerLine.scaleDown(scale);
for (var j = 0; j < part.innerLines.length; j ++) {
var innerLine = part.innerLines[j];
innerLine.scaleDown(scale);
} }
part.fill.scaleDown(scale);
}
part.outerLayer.scaleDown(100); if (slice.support !== undefined) {
part.insets.scaleDown(100); slice.support.scaleDown(scale);
part.fill.scaleDown(100); }
if (part.support !== undefined) { if (slice.brim !== undefined) {
part.support.scaleDown(100); slice.brim.scaleDown(scale);
}
} }
} }
return data; return slices;
}; };
D3D.Slicer.prototype.getFillTemplate = function (bounds, size, even, uneven) { D3D.Slicer.prototype.getFillTemplate = function (bounds, size, even, uneven) {
@ -550,16 +522,23 @@ D3D.Slicer.prototype.dataToGCode = function (data, printer) {
gcode.bottom = false; gcode.bottom = false;
} }
for (var i = 0; i < slice.length; i ++) { if (slice.brim !== undefined) {
var layerPart = slice[i]; sliceToGCode(slice.brim, true, true);
}
sliceToGCode(layerPart.outerLayer, false, true); for (var i = 0; i < slice.parts.length; i ++) {
sliceToGCode(layerPart.insets, false, false); var part = slice.parts[i];
sliceToGCode(layerPart.fill, true, false);
if (layerPart.support !== undefined) { sliceToGCode(part.outerLine, false, true);
sliceToGCode(layerPart.support, true, true); for (var j = 0; j < part.innerLines.length; j ++) {
var innerLine = part.innerLines[j];
sliceToGCode(innerLine, false, false);
} }
sliceToGCode(part.fill, true, false);
}
if (slice.support !== undefined) {
sliceToGCode(slice.support, true, true);
} }
this.progress.gcodeLayer = layer; this.progress.gcodeLayer = layer;
@ -585,12 +564,12 @@ D3D.Slicer.prototype.getGCode = function (printer) {
console.log("Slicing: " + (end - start) + "ms"); console.log("Slicing: " + (end - start) + "ms");
start = new Date().getTime(); start = new Date().getTime();
var data = this.slicesToData(slices, printer); this.slicesToData(slices, printer);
end = new Date().getTime(); end = new Date().getTime();
console.log("Data: " + (end - start) + "ms"); console.log("Data: " + (end - start) + "ms");
start = new Date().getTime(); start = new Date().getTime();
var gcode = this.dataToGCode(data, printer); var gcode = this.dataToGCode(slices, printer);
end = new Date().getTime(); end = new Date().getTime();
console.log("Gcode: " + (end - start) + "ms"); console.log("Gcode: " + (end - start) + "ms");

View File

@ -19,7 +19,7 @@ D3D.SlicerWorker = function () {
if (scope.onfinish !== undefined) { if (scope.onfinish !== undefined) {
var reader = new FileReader(); var reader = new FileReader();
reader.addEventListener("loadend", function() { reader.addEventListener("loadend", function() {
var gcode = reader.result.split("\n"); var gcode = reader.result;
scope.onfinish(gcode); scope.onfinish(gcode);
}); });
reader.readAsBinaryString(event.data['gcode']); reader.readAsBinaryString(event.data['gcode']);

View File

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

View File

@ -1,58 +1,57 @@
importScripts("../library/three.js"); importScripts('../library/three.js');
importScripts("../library/clipper.js"); importScripts('../library/clipper.js');
importScripts("../src/utils.js"); importScripts('../src/utils.js');
importScripts("../src/printer.js"); importScripts('../src/printer.js');
importScripts("../src/paths.js"); importScripts('../src/paths.js');
importScripts("../src/slicer.js"); importScripts('../src/slicer.js');
importScripts("../src/gcode.js"); importScripts('../src/gcode.js');
importScripts('../src/slice.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) { slicer.onProgress = function (progress) {
"use strict"; 'use strict';
self.postMessage({ self.postMessage({
"cmd": "PROGRESS", 'cmd': 'PROGRESS',
"progress": progress 'progress': progress
}); });
}; };
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':
//hack... //hack...
//because boundings loses functions when converting //because boundings loses prototype functions when converting
event.data["geometry"].boundingBox = event.data["geometry"].boundingSphere = null; event.data['geometry'].boundingBox = event.data['geometry'].boundingSphere = null;
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.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']);
break; break;
case "SLICE": case 'SLICE':
var gcode = slicer.getGCode(printer); var gcode = slicer.getGCode(printer);
var blob = new Blob([gcode], {type: 'text/plain'}); var blob = new Blob([gcode], {type: 'text/plain'});
//need to send the buffer of blob sepperatly;
//not sure how to send that
self.postMessage({ self.postMessage({
"cmd": "GCODE", 'cmd': 'GCODE',
"gcode": blob 'gcode': blob
}); });
break; break;
case "CLOSE": case 'CLOSE':
self.close(); self.close();
break; break;
} }
}); });

View File

@ -1,74 +0,0 @@
<!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

@ -1,19 +0,0 @@
----------- 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

@ -86,7 +86,7 @@ function init () {
downloadButton.style.display = 'initial'; downloadButton.style.display = 'initial';
downloadButton.onclick = function () { downloadButton.onclick = function () {
downloadFile("gcode.gcode", gcode.join('\n')); downloadFile("gcode.gcode", gcode);
}; };
}; };
@ -99,7 +99,7 @@ function init () {
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 = -0.1; mesh.position.y = -0.1;
mesh.position.x = 60; mesh.position.x = 60;
mesh.position.z = 60; mesh.position.z = 60;