Doodle3D-Slicer/src/slicer.worker.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-10-13 14:22:04 +02:00
import slice from './sliceActions/slice.js';
import { Matrix4 } from 'three/src/math/Matrix4.js';
import JSONToSketchData from 'doodle3d-core/shape/JSONToSketchData';
import createSceneData from 'doodle3d-core/d3/createSceneData.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
});
}
self.addEventListener('message', async (event) => {
2016-08-19 14:46:02 +02:00
const { message, data } = event.data;
switch (message) {
case 'SLICE': {
2017-11-12 11:53:45 +01:00
const buffers = [];
const { settings, sketch: sketchData, matrix: matrixArray, constructLinePreview } = data;
const sketch = createSceneData(await JSONToSketchData(sketchData));
const matrix = new Matrix4().fromArray(matrixArray);
2016-08-19 14:46:02 +02:00
const gcode = slice(settings, sketch, matrix, constructLinePreview, onProgress);
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);