Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo committed Jul 20, 2017
2 parents 281b037 + ed05c6f commit fb69ad8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 7 additions & 8 deletions example/save.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three';
import { defaultSettings, Slicer } from 'src/index.js';
import { saveAs } from 'file-saver';
import fileSaver from 'file-saver';

const settings = {
...defaultSettings.base,
Expand All @@ -12,16 +12,15 @@ const settings = {
const jsonLoader = new THREE.JSONLoader();
jsonLoader.load('models/airplane.json', async geometry => {
geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI / -2));
geometry.applyMatrix(new THREE.Matrix4().setPosition(new THREE.Vector3(50, -0.1, 50)));
geometry.applyMatrix(new THREE.Matrix4().setPosition(new THREE.Vector3(50, -0.0, 50)));
geometry.computeFaceNormals();

const slicer = new Slicer().setGeometry(geometry);
const gcode = await slicer.slice(settings)
.progress(({ progress: { done, total, action } }) => {
const percentage = `${(done / total * 100).toFixed()}%`
document.write(`<p>${action}, ${percentage}</p>`);
});
const gcode = await slicer.slice(settings, ({ progress: { done, total, action } }) => {
const percentage = `${(done / total * 100).toFixed()}%`
document.write(`<p>${action}, ${percentage}</p>`);
});

const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
saveAs(file);
fileSaver.saveAs(file);
});
10 changes: 8 additions & 2 deletions src/Slicer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ export default class {
return this;
}
sliceSync(settings, onProgress) {
if (typeof this.geometry === 'undefined') {
throw new Error('Geometry is not set, use Slicer.setGeometry or Slicer.setMesh first');
}

return slice(this.geometry, settings, onProgress);
}
slice(settings, onProgress) {
if (!this.geometry) {
if (typeof this.geometry === 'undefined') {
throw new Error('Geometry is not set, use Slicer.setGeometry or Slicer.setMesh first');
}

Expand All @@ -48,7 +52,9 @@ export default class {
break;
}
case 'PROGRESS': {
onProgress(data);
if (typeof onProgress !== 'undefined') {
onProgress(data);
}
break;
}
}
Expand Down

0 comments on commit fb69ad8

Please sign in to comment.