splice slice sync and slice async

This commit is contained in:
casperlamboo 2016-08-19 15:12:20 +02:00 committed by Simon Voordouw
parent 12c18df053
commit a7c1a9b4fd
2 changed files with 23 additions and 25 deletions

View File

@ -11,6 +11,6 @@ const geometry = new THREE.TorusGeometry(20, 10, 30, 30);
const slicer = new SLICER.Slicer(); const slicer = new SLICER.Slicer();
slicer.setGeometry(geometry); slicer.setGeometry(geometry);
slicer.slice(settings, true).then(gcode => { slicer.slice(settings).then(gcode => {
document.getElementById('gcode').innerHTML = gcode.replace(/(?:\r\n|\r|\n)/g, '<br />'); document.getElementById('gcode').innerHTML = gcode.replace(/(?:\r\n|\r|\n)/g, '<br />');
}); });

View File

@ -30,16 +30,18 @@ export default class {
return this; return this;
} }
async slice(settings, async = false) { sliceSync(settings) {
let gcode; return slice(this.geometry, settings);
}
if (async) { slice(settings) {
const sliceWorker = new SliceWorker(); const sliceWorker = new SliceWorker();
const geometry = this.geometry.toJSON(); const geometry = this.geometry.toJSON();
const { config } = settings; const { config } = settings;
gcode = await new Promise((resolve) => { return new Promise((resolve, reject) => {
sliceWorker.onerror = reject;
sliceWorker.addEventListener('message', (event) => { sliceWorker.addEventListener('message', (event) => {
const { message, data } = event.data; const { message, data } = event.data;
switch (message) { switch (message) {
@ -55,9 +57,5 @@ export default class {
data: { geometry, config } data: { geometry, config }
}); });
}); });
} else {
gcode = slice(this.geometry, settings);
}
return gcode;
} }
} }