2017-12-19 12:38:58 +01:00
|
|
|
import 'core-js'; // polyfills
|
2016-10-13 14:22:04 +02:00
|
|
|
import slice from './sliceActions/slice.js';
|
2017-12-18 16:37:03 +01:00
|
|
|
import { Matrix4 } from 'three/src/math/Matrix4.js';
|
2017-12-19 12:38:58 +01:00
|
|
|
import { JSONLoader } from 'three/src/loaders/JSONLoader.js';
|
2016-08-19 14:46:02 +02:00
|
|
|
|
2017-07-18 12:26:30 +02:00
|
|
|
const onProgress = progress => {
|
|
|
|
self.postMessage({
|
|
|
|
message: 'PROGRESS',
|
2017-07-20 10:29:33 +02:00
|
|
|
data: progress
|
2017-07-18 12:26:30 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-19 12:38:58 +01:00
|
|
|
const loader = new JSONLoader();
|
|
|
|
|
2017-12-18 16:37:03 +01:00
|
|
|
self.addEventListener('message', async (event) => {
|
2016-08-19 14:46:02 +02:00
|
|
|
const { message, data } = event.data;
|
|
|
|
switch (message) {
|
|
|
|
case 'SLICE': {
|
2017-12-19 12:38:58 +01:00
|
|
|
const { settings, geometry: JSONGeometry, constructLinePreview, openObjectIndexes } = data;
|
|
|
|
const { geometry } = loader.parse(JSONGeometry.data);
|
2016-08-19 14:46:02 +02:00
|
|
|
|
2017-12-19 12:38:58 +01:00
|
|
|
const gcode = slice(settings, geometry, openObjectIndexes, constructLinePreview, onProgress);
|
2017-11-12 11:53:45 +01:00
|
|
|
|
2017-12-19 12:38:58 +01:00
|
|
|
const buffers = [];
|
2017-11-12 11:53:45 +01:00
|
|
|
if (gcode.linePreview) {
|
|
|
|
const position = gcode.linePreview.geometry.getAttribute('position').array;
|
|
|
|
const color = gcode.linePreview.geometry.getAttribute('color').array;
|
|
|
|
buffers.push(position.buffer, color.buffer);
|
|
|
|
gcode.linePreview = { position, color };
|
|
|
|
}
|
2016-08-19 14:46:02 +02:00
|
|
|
|
|
|
|
self.postMessage({
|
|
|
|
message: 'SLICE',
|
|
|
|
data: { gcode }
|
2017-11-12 11:53:45 +01:00
|
|
|
}, buffers);
|
2016-08-19 14:46:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, false);
|