cleanup Slicer

This commit is contained in:
casperlamboo 2017-07-19 17:36:20 +02:00
parent 3f140d7f03
commit 8c57e16998

View File

@ -7,9 +7,7 @@ export default class {
setMesh(mesh) { setMesh(mesh) {
mesh.updateMatrix(); mesh.updateMatrix();
this.setGeometry(mesh.geometry, mesh.matrix); return this.setGeometry(mesh.geometry, mesh.matrix);
return this;
} }
setGeometry(geometry, matrix) { setGeometry(geometry, matrix) {
if (geometry.isBufferGeometry) { if (geometry.isBufferGeometry) {
@ -20,7 +18,7 @@ export default class {
throw new Error('Geometry is not an instance of BufferGeometry or Geometry'); throw new Error('Geometry is not an instance of BufferGeometry or Geometry');
} }
if (matrix) { if (typeof matrix !== 'undefined') {
geometry.applyMatrix(matrix); geometry.applyMatrix(matrix);
} }
@ -32,13 +30,16 @@ export default class {
return slice(this.geometry, settings, onprogress); return slice(this.geometry, settings, onprogress);
} }
slice(settings) { slice(settings) {
const slicerWorker = new SlicerWorker(); if (!this.geometry) {
throw new Error('Geometry is not set, use Slicer.setGeometry or Slicer.setMesh first');
const geometry = this.geometry.toJSON(); }
return new ProgressPromise((resolve, reject, progress) => { return new ProgressPromise((resolve, reject, progress) => {
// create the slicer worker
const slicerWorker = new SlicerWorker();
slicerWorker.onerror = reject; slicerWorker.onerror = reject;
// listen to messages send from worker
slicerWorker.addEventListener('message', (event) => { slicerWorker.addEventListener('message', (event) => {
const { message, data } = event.data; const { message, data } = event.data;
switch (message) { switch (message) {
@ -54,6 +55,8 @@ export default class {
} }
}); });
// send geometry and settings to worker to start the slicing progress
const geometry = this.geometry.toJSON();
slicerWorker.postMessage({ slicerWorker.postMessage({
message: 'SLICE', message: 'SLICE',
data: { geometry, settings } data: { geometry, settings }