update save example

This commit is contained in:
casperlamboo 2017-07-20 00:10:29 +02:00
parent 0564f3e7bc
commit ed05c6fda9

View File

@ -1,6 +1,6 @@
import * as THREE from 'three'; import * as THREE from 'three';
import { defaultSettings, Slicer } from 'src/index.js'; import { defaultSettings, Slicer } from 'src/index.js';
import { saveAs } from 'file-saver'; import fileSaver from 'file-saver';
const settings = { const settings = {
...defaultSettings.base, ...defaultSettings.base,
@ -12,16 +12,15 @@ const settings = {
const jsonLoader = new THREE.JSONLoader(); const jsonLoader = new THREE.JSONLoader();
jsonLoader.load('models/airplane.json', async geometry => { jsonLoader.load('models/airplane.json', async geometry => {
geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI / -2)); 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(); geometry.computeFaceNormals();
const slicer = new Slicer().setGeometry(geometry); const slicer = new Slicer().setGeometry(geometry);
const gcode = await slicer.slice(settings) const gcode = await slicer.slice(settings, ({ progress: { done, total, action } }) => {
.progress(({ progress: { done, total, action } }) => { const percentage = `${(done / total * 100).toFixed()}%`
const percentage = `${(done / total * 100).toFixed()}%` document.write(`<p>${action}, ${percentage}</p>`);
document.write(`<p>${action}, ${percentage}</p>`); });
});
const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' }); const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
saveAs(file); fileSaver.saveAs(file);
}); });