diff --git a/example/index.html b/example/index.html index ffecf60..cde4fdc 100644 --- a/example/index.html +++ b/example/index.html @@ -1,29 +1,11 @@ - Doodle3D Slicer - - - - - - - - - - - -
- +

Viewer

+

Save

diff --git a/example/save.html b/example/save.html new file mode 100644 index 0000000..f5d44d6 --- /dev/null +++ b/example/save.html @@ -0,0 +1,19 @@ + + + + + Doodle3D Slicer - Save + + + + + + + + + + + + diff --git a/example/save.js b/example/save.js new file mode 100644 index 0000000..63c3e8e --- /dev/null +++ b/example/save.js @@ -0,0 +1,25 @@ +import 'three.js'; +import 'three.js/loaders/STLLoader'; +import { Settings, printerSettings, userSettings, Slicer } from 'src/index.js'; +import { saveAs } from 'file-saver'; + +const settings = new Settings({ + ...printerSettings['ultimaker2go'], + ...userSettings +}); + +const stlLoader = new THREE.STLLoader(); +stlLoader.load('stl/traktor.stl', async (geometry) => { + geometry = new THREE.Geometry().fromBufferGeometry(geometry); + + geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI / -2)); + geometry.applyMatrix(new THREE.Matrix4().setPosition(new THREE.Vector3(50, -0.1, 50))); + geometry.mergeVertices(); + geometry.computeFaceNormals(); + + const slicer = new Slicer().setGeometry(geometry); + const gcode = await slicer.slice(settings); + + const file = new File([gcode], 'traktor.gcode', { type: 'text/plain' }); + saveAs(file); +}); diff --git a/example/viewer.html b/example/viewer.html new file mode 100644 index 0000000..9aa2724 --- /dev/null +++ b/example/viewer.html @@ -0,0 +1,29 @@ + + + + + Doodle3D Slicer - Viewer + + + + + + + + + + + + + + +
+ + + diff --git a/example/app.js b/example/viewer.js similarity index 53% rename from example/app.js rename to example/viewer.js index c008881..e2ed29b 100644 --- a/example/app.js +++ b/example/viewer.js @@ -12,8 +12,9 @@ const settings = new SLICER.Settings({ }); const stlLoader = new THREE.STLLoader(); - stlLoader.load('stl/Airplane.stl', (geometry) => { + geometry = new THREE.Geometry().fromBufferGeometry(geometry); + 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().scale(0.8)); @@ -22,24 +23,13 @@ stlLoader.load('stl/Airplane.stl', (geometry) => { const rawData = generateRawData(geometry, settings); - render(, document.getElementById('container')); + render( + , + document.getElementById('container') + ); }); - -// const geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone(); -// geometry.applyMatrix(new THREE.Matrix4().setPosition(new THREE.Vector3(60, 0, 60))); -// geometry.mergeVertices(); -// geometry.computeFaceNormals(); -// -// const rawData = generateRawData(geometry, settings); -// -// render(, document.getElementById('container')); diff --git a/jspm.config.js b/jspm.config.js index 6484f4a..504d761 100644 --- a/jspm.config.js +++ b/jspm.config.js @@ -19,7 +19,8 @@ SystemJS.config({ "https": "npm:jspm-nodelibs-https@0.2.0", "react-dom": "npm:react-dom@15.3.2", "babel-plugin-transform-react-jsx": "npm:babel-plugin-transform-react-jsx@6.8.0", - "three.js/loaders/STLLoader": "github:mrdoob/three.js@r83/examples/js/loaders/STLLoader.js" + "three.js/loaders/STLLoader": "github:mrdoob/three.js@r83/examples/js/loaders/STLLoader.js", + "file-saver": "npm:file-saver@1.3.3" }, "packages": { "npm:babel-runtime@5.8.38": { diff --git a/package.json b/package.json index 1cf3137..9a267e0 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "core-js": "npm:core-js@^1.2.0", "domain": "npm:jspm-nodelibs-domain@^0.2.0", "https": "npm:jspm-nodelibs-https@^0.2.0", + "file-saver": "npm:file-saver@^1.3.3", "plugin-babel": "npm:systemjs-plugin-babel@^0.0.12", "react": "npm:react@^15.3.2", "react-dom": "npm:react-dom@^15.3.2",