2015-06-11 14:34:30 +02:00
|
|
|
importScripts('../library/three.js');
|
|
|
|
importScripts('../library/clipper.js');
|
|
|
|
importScripts('../src/utils.js');
|
|
|
|
importScripts('../src/printer.js');
|
|
|
|
importScripts('../src/paths.js');
|
|
|
|
importScripts('../src/slicer.js');
|
|
|
|
importScripts('../src/gcode.js');
|
|
|
|
importScripts('../src/slice.js');
|
2015-05-27 12:25:51 +02:00
|
|
|
|
|
|
|
var printer = new D3D.Printer();
|
|
|
|
var slicer = new D3D.Slicer();
|
2015-05-29 13:51:18 +02:00
|
|
|
slicer.onProgress = function (progress) {
|
2015-06-11 14:34:30 +02:00
|
|
|
'use strict';
|
2015-05-29 13:51:18 +02:00
|
|
|
|
|
|
|
self.postMessage({
|
2015-06-11 14:34:30 +02:00
|
|
|
'cmd': 'PROGRESS',
|
|
|
|
'progress': progress
|
2015-05-29 13:51:18 +02:00
|
|
|
});
|
|
|
|
};
|
2015-05-27 12:25:51 +02:00
|
|
|
|
2015-06-11 14:34:30 +02:00
|
|
|
self.addEventListener('message', function (event) {
|
|
|
|
'use strict';
|
2015-05-27 12:25:51 +02:00
|
|
|
|
2015-06-11 14:34:30 +02:00
|
|
|
switch (event.data['cmd']) {
|
|
|
|
case 'SET_MESH':
|
2015-06-01 12:06:11 +02:00
|
|
|
//hack...
|
2015-06-11 14:34:30 +02:00
|
|
|
//because boundings loses prototype functions when converting
|
|
|
|
event.data['geometry'].boundingBox = event.data['geometry'].boundingSphere = null;
|
2015-06-01 12:06:11 +02:00
|
|
|
|
2015-06-11 14:34:30 +02:00
|
|
|
var geometry = new THREE.Geometry().fromBufferGeometry(event.data['geometry']);
|
|
|
|
var matrix = new THREE.Matrix4().fromArray(event.data['matrix']);
|
2015-05-27 12:25:51 +02:00
|
|
|
|
2015-07-10 12:59:50 +02:00
|
|
|
slicer.setGeometry(geometry, matrix);
|
2015-05-27 12:25:51 +02:00
|
|
|
break;
|
|
|
|
|
2015-06-11 14:34:30 +02:00
|
|
|
case 'SET_SETTINGS':
|
|
|
|
printer.updateConfig(event.data['USER_SETTINGS']);
|
|
|
|
printer.updateConfig(event.data['PRINTER_SETTINGS']);
|
2015-05-27 12:25:51 +02:00
|
|
|
break;
|
|
|
|
|
2015-06-11 14:34:30 +02:00
|
|
|
case 'SLICE':
|
2015-06-09 11:08:06 +02:00
|
|
|
var gcode = slicer.getGCode(printer);
|
2015-06-11 11:08:56 +02:00
|
|
|
var blob = new Blob([gcode], {type: 'text/plain'});
|
2015-05-27 12:25:51 +02:00
|
|
|
|
2015-06-11 14:34:30 +02:00
|
|
|
//need to send the buffer of blob sepperatly;
|
|
|
|
//not sure how to send that
|
2015-06-17 21:26:49 +02:00
|
|
|
|
2015-05-29 13:51:18 +02:00
|
|
|
self.postMessage({
|
2015-06-11 14:34:30 +02:00
|
|
|
'cmd': 'GCODE',
|
|
|
|
'gcode': blob
|
2015-05-29 13:51:18 +02:00
|
|
|
});
|
2015-05-27 12:25:51 +02:00
|
|
|
break;
|
|
|
|
|
2015-06-11 14:34:30 +02:00
|
|
|
case 'CLOSE':
|
2015-05-27 12:25:51 +02:00
|
|
|
self.close();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|