2017-07-18 12:38:03 +02:00
|
|
|
import * as THREE from 'three';
|
2017-07-20 10:29:33 +02:00
|
|
|
import { defaultSettings, sliceGeometry } from 'src/index.js';
|
2017-07-20 00:10:29 +02:00
|
|
|
import fileSaver from 'file-saver';
|
2017-05-13 15:39:45 +02:00
|
|
|
|
2017-07-18 11:26:11 +02:00
|
|
|
const settings = {
|
|
|
|
...defaultSettings.base,
|
|
|
|
...defaultSettings.material.pla,
|
|
|
|
...defaultSettings.printer.ultimaker2go,
|
2017-07-18 11:39:38 +02:00
|
|
|
...defaultSettings.quality.high
|
2017-07-18 11:26:11 +02:00
|
|
|
};
|
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-20 00:10:29 +02:00
|
|
|
geometry.applyMatrix(new THREE.Matrix4().setPosition(new THREE.Vector3(50, -0.0, 50)));
|
2017-05-13 15:39:45 +02:00
|
|
|
geometry.computeFaceNormals();
|
|
|
|
|
2017-07-20 10:29:33 +02:00
|
|
|
const onProgress = ({ progress: { done, total, action } }) => {
|
2017-07-20 00:10:29 +02:00
|
|
|
const percentage = `${(done / total * 100).toFixed()}%`
|
|
|
|
document.write(`<p>${action}, ${percentage}</p>`);
|
2017-07-20 10:29:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const gcode = await sliceGeometry(settings, geometry, null, false, onProgress);
|
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-07-20 00:10:29 +02:00
|
|
|
fileSaver.saveAs(file);
|
2017-05-13 15:39:45 +02:00
|
|
|
});
|