mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-16 02:57:57 +01:00
30645f634a
@peteruithoven @mith I think this is a somewhat nicer API for the slicer. I completely removed the Slicer class and instead added two function: sliceGeometry and sliceMesh
28 lines
967 B
JavaScript
28 lines
967 B
JavaScript
import * as THREE from 'three';
|
|
import { defaultSettings, sliceGeometry } from 'src/index.js';
|
|
import fileSaver from 'file-saver';
|
|
|
|
const settings = {
|
|
...defaultSettings.base,
|
|
...defaultSettings.material.pla,
|
|
...defaultSettings.printer.ultimaker2go,
|
|
...defaultSettings.quality.high
|
|
};
|
|
|
|
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.0, 50)));
|
|
geometry.computeFaceNormals();
|
|
|
|
const onProgress = ({ progress: { done, total, action } }) => {
|
|
const percentage = `${(done / total * 100).toFixed()}%`
|
|
document.write(`<p>${action}, ${percentage}</p>`);
|
|
};
|
|
|
|
const gcode = await sliceGeometry(settings, geometry, null, false, onProgress);
|
|
|
|
const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
|
|
fileSaver.saveAs(file);
|
|
});
|