mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-26 15:34:57 +01:00
splice slice sync and slice async
This commit is contained in:
parent
12c18df053
commit
a7c1a9b4fd
@ -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 />');
|
||||||
});
|
});
|
||||||
|
@ -30,34 +30,32 @@ export default class {
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
async slice(settings, async = false) {
|
sliceSync(settings) {
|
||||||
let gcode;
|
return slice(this.geometry, settings);
|
||||||
|
}
|
||||||
|
slice(settings) {
|
||||||
|
const sliceWorker = new SliceWorker();
|
||||||
|
|
||||||
if (async) {
|
const geometry = this.geometry.toJSON();
|
||||||
const sliceWorker = new SliceWorker();
|
const { config } = settings;
|
||||||
|
|
||||||
const geometry = this.geometry.toJSON();
|
return new Promise((resolve, reject) => {
|
||||||
const { config } = settings;
|
sliceWorker.onerror = reject;
|
||||||
|
|
||||||
gcode = await new Promise((resolve) => {
|
sliceWorker.addEventListener('message', (event) => {
|
||||||
sliceWorker.addEventListener('message', (event) => {
|
const { message, data } = event.data;
|
||||||
const { message, data } = event.data;
|
switch (message) {
|
||||||
switch (message) {
|
case 'SLICE': {
|
||||||
case 'SLICE': {
|
sliceWorker.terminate();
|
||||||
sliceWorker.terminate();
|
resolve(data.gcode);
|
||||||
resolve(data.gcode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
sliceWorker.postMessage({
|
|
||||||
message: 'SLICE',
|
|
||||||
data: { geometry, config }
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
gcode = slice(this.geometry, settings);
|
sliceWorker.postMessage({
|
||||||
}
|
message: 'SLICE',
|
||||||
return gcode;
|
data: { geometry, config }
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user