Doodle3D-Slicer/simpleExample/index.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-07-20 12:12:25 +02:00
import * as THREE from 'three';
2017-07-20 16:32:48 +02:00
import { defaultSettings, sliceGeometry } from 'doodle3d-slicer';
2017-08-24 10:55:58 +02:00
import fileURL from '!url-loader!./models/combingtest.json';
2017-08-17 16:13:30 +02:00
import fileSaver from 'file-saver';
2017-07-07 18:10:29 +02:00
2017-07-20 12:12:25 +02:00
const settings = {
...defaultSettings.base,
...defaultSettings.material.pla,
...defaultSettings.printer.ultimaker2go,
...defaultSettings.quality.high
};
2017-07-07 18:10:29 +02:00
2017-08-17 16:13:30 +02:00
const jsonLoader = new THREE.JSONLoader();
jsonLoader.load(fileURL, geometry => {
geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI / -2));
geometry.applyMatrix(new THREE.Matrix4().setPosition(new THREE.Vector3(50, -0.0, 50)));
2017-07-07 18:10:29 +02:00
2017-08-17 16:13:30 +02:00
const onProgress = ({ progress: { done, total, action } }) => {
const percentage = `${(done / total * 100).toFixed()}%`
document.write(`<p>${action}, ${percentage}</p>`);
};
2017-07-20 16:32:48 +02:00
2017-08-17 16:13:30 +02:00
const { filament, duration, gcode } = sliceGeometry(settings, geometry, null, true, onProgress);
// console.log('filament: ', filament);
// console.log('duration: ', duration);
// document.body.innerHTML = gcode.replace(/(?:\r\n|\r|\n)/g, '<br />');
const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
fileSaver.saveAs(file);
2017-07-28 10:48:46 +02:00
});