From f243d984313b25f73950afaf944703156c916635 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Thu, 14 Dec 2017 14:00:16 +0100 Subject: [PATCH] add download stl function --- index.js | 13 ++++++++++++- models/simple_hole.d3sketch | 1 + package-lock.json | 5 +++++ package.json | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 models/simple_hole.d3sketch diff --git a/index.js b/index.js index c2baef3..eb34922 100644 --- a/index.js +++ b/index.js @@ -19,9 +19,20 @@ const store = createStore(reducer, enhancer); import actionWrapper from 'redux-action-wrapper'; import * as actions from './src/actions/index.js'; window.actions = actionWrapper(actions, store.dispatch); +import { saveAs as saveAsLib } from 'file-saver'; + +// download file +import { createFile } from './src/utils/exportUtils.js'; +window.downloadStl = () => { + store.dispatch(async (dispatch, getState) => { + const state = getState(); + const blob = await createFile(state.sketcher.present, 'stl-blob'); + saveAsLib(blob, 'doodle.stl'); + }); +}; // add model to store -import modelData from './models/noodlebot.d3sketch'; +import modelData from './models/simple_hole.d3sketch'; import JSONToSketchData from './src/shape/JSONToSketchData.js'; JSONToSketchData(JSON.parse(modelData)).then(data => { store.dispatch(actions.openSketch({ data })); diff --git a/models/simple_hole.d3sketch b/models/simple_hole.d3sketch new file mode 100644 index 0000000..24f0336 --- /dev/null +++ b/models/simple_hole.d3sketch @@ -0,0 +1 @@ +{"data":"{\"spaces\":[{\"matrix\":{\"metadata\":{\"type\":\"Matrix4\",\"library\":\"three.js\"},\"elements\":[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},\"objects\":[{\"height\":21.005096748926302,\"transform\":{\"metadata\":{\"library\":\"CAL\",\"type\":\"Matrix\"},\"matrix\":[1,0,8.214849921011051,0,1,-3.7914691943127927]},\"z\":7.243224684956081,\"sculpt\":[{\"pos\":0,\"scale\":1},{\"pos\":1,\"scale\":1}],\"twist\":0,\"fill\":true,\"solid\":false,\"star\":{\"rays\":5,\"innerRadius\":18.00947867298578,\"outerRadius\":38.54660347551342},\"color\":6873597,\"type\":\"STAR\"},{\"height\":20,\"transform\":{\"metadata\":{\"library\":\"CAL\",\"type\":\"Matrix\"},\"matrix\":[1,0,-14.533965244865726,0,1,7.266982622432863]},\"z\":0,\"sculpt\":[{\"pos\":0,\"scale\":1},{\"pos\":1,\"scale\":1}],\"twist\":0,\"fill\":true,\"solid\":true,\"star\":{\"rays\":5,\"innerRadius\":18.00947867298578,\"outerRadius\":38.54660347551342},\"color\":6873597,\"type\":\"STAR\"}]}]}","appVersion":"0.17.4"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8cef737..fb92540 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4306,6 +4306,11 @@ "object-assign": "4.1.1" } }, + "file-saver": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-1.3.3.tgz", + "integrity": "sha1-zdTETTqiZOrC9o7BZbx5HDSvEjI=" + }, "filename-regex": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", diff --git a/package.json b/package.json index 3007d54..cd738bf 100755 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "eslint": "^1.10.3", "eslint-config-airbnb": "^3.1.0", "eslint-plugin-react": "^3.16.1", + "file-saver": "^1.3.3", "html-webpack-plugin": "^2.30.1", "html-webpack-template": "^6.0.2", "jss-preset-default": "^4.0.1",