Doodle3D-Slicer/example/save.js

28 lines
966 B
JavaScript
Raw Normal View History

2017-07-18 12:38:03 +02:00
import * as THREE from 'three';
2017-07-18 11:39:38 +02:00
import { defaultSettings, Slicer } from 'src/index.js';
2017-05-13 15:39:45 +02:00
import { saveAs } from 'file-saver';
const settings = {
...defaultSettings.base,
...defaultSettings.material.pla,
...defaultSettings.printer.ultimaker2go,
2017-07-18 11:39:38 +02:00
...defaultSettings.quality.high
};
2017-05-13 15:39:45 +02:00
2017-07-18 10:22:26 +02:00
const jsonLoader = new THREE.JSONLoader();
jsonLoader.load('models/airplane.json', async geometry => {
2017-05-13 15:39:45 +02:00
geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI / -2));
2017-07-18 12:30:56 +02:00
geometry.applyMatrix(new THREE.Matrix4().setPosition(new THREE.Vector3(50, -0.1, 50)));
2017-05-13 15:39:45 +02:00
geometry.computeFaceNormals();
const slicer = new Slicer().setGeometry(geometry);
2017-07-18 12:26:30 +02:00
const gcode = await slicer.slice(settings)
.progress(({ progress: { done, total, action } }) => {
2017-07-18 12:26:30 +02:00
const percentage = `${(done / total * 100).toFixed()}%`
document.write(`<p>${action}, ${percentage}</p>`);
});
2017-05-13 15:39:45 +02:00
2017-07-18 10:34:20 +02:00
const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
2017-05-13 15:39:45 +02:00
saveAs(file);
});