Doodle3D-Slicer/src/slicer.worker.js

35 lines
946 B
JavaScript
Raw Normal View History

import 'core-js'; // polyfills
2016-10-13 14:22:04 +02:00
import slice from './sliceActions/slice.js';
import { stringToTypedArray } from './sliceActions/helpers/binary.js';
2016-08-19 14:46:02 +02:00
2017-07-18 12:26:30 +02:00
const onProgress = progress => {
self.postMessage({
message: 'PROGRESS',
data: progress
2017-07-18 12:26:30 +02:00
});
}
2018-01-17 15:27:42 +01:00
self.addEventListener('message', (event) => {
2016-08-19 14:46:02 +02:00
const { message, data } = event.data;
switch (message) {
case 'SLICE': {
const { settings, geometry, constructLinePreview, openObjectIndexes } = data;
2016-08-19 14:46:02 +02:00
const gcode = slice(settings, geometry, openObjectIndexes, constructLinePreview, onProgress);
gcode.gcode = stringToTypedArray(gcode.gcode);
const buffers = [gcode.gcode.buffer];
2018-02-12 11:07:06 +01:00
if (gcode.linePreview) {
buffers.push(gcode.linePreview.positions.buffer);
buffers.push(gcode.linePreview.colors.buffer);
}
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);