diff --git a/example/SlicerViewer.js b/example/SlicerViewer.js
new file mode 100644
index 0000000..d82fc44
--- /dev/null
+++ b/example/SlicerViewer.js
@@ -0,0 +1,45 @@
+import React from 'react';
+
+export default class SlicerViewer extends React.Component {
+ state = {
+ slice: 0
+ };
+
+ changeSlider = (event) => {
+ this.setState({
+ ...this.state,
+ slice: parseInt(event.target.value)
+ });
+ };
+
+ render() {
+ const { slice } = this.state;
+ const { layerIntersectionPoints, settings, layerShapes } = this.props;
+
+ const numLayers = settings.dimensionsZ / settings.layerHeight;
+
+ const intersectionPoints = layerIntersectionPoints[slice + 1];
+ const shape = layerShapes[slice];
+
+ return (
+
+
+
+
+ );
+ }
+}
diff --git a/example/app.js b/example/app.js
index f07c9c9..2f978b1 100644
--- a/example/app.js
+++ b/example/app.js
@@ -1,16 +1,24 @@
import THREE from 'three.js';
-import * as SLICER from 'src/index';
+import React from 'react';
+import ReactDOM, { render } from 'react-dom';
+import * as SLICER from 'src/index.js';
+import generateRawData from './generateRawData.js';
+import SlicerViewer from './SlicerViewer.js';
const settings = new SLICER.Settings({
...SLICER.printerSettings['ultimaker2go'],
...SLICER.userSettings
});
-const geometry = new THREE.TorusGeometry(20, 10, 30, 30);
+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 slicer = new SLICER.Slicer();
+const rawData = generateRawData(geometry, settings);
-slicer.setGeometry(geometry);
-slicer.slice(settings).then(gcode => {
- document.getElementById('gcode').innerHTML = gcode.replace(/(?:\r\n|\r|\n)/g, '
');
-});
+render(, document.getElementById('container'));
diff --git a/example/generateRawData.js b/example/generateRawData.js
new file mode 100644
index 0000000..333a15a
--- /dev/null
+++ b/example/generateRawData.js
@@ -0,0 +1,54 @@
+import calculateLayersIntersections from 'src/sliceActions/calculateLayersIntersections.js';
+import createLines from 'src/sliceActions/createLines.js';
+import generateInfills from 'src/sliceActions/generateInfills.js';
+import generateInnerLines from 'src/sliceActions/generateInnerLines.js';
+import generateSupport from 'src/sliceActions/generateSupport.js';
+import intersectionsToShapes from 'src/sliceActions/intersectionsToShapes.js';
+import addBrim from 'src/sliceActions/addBrim.js';
+import optimizePaths from 'src/sliceActions/optimizePaths.js';
+import shapesToSlices from 'src/sliceActions/shapesToSlices.js';
+import slicesToGCode from 'src/sliceActions/slicesToGCode.js';
+import applyPrecision from 'src/sliceActions/applyPrecision.js';
+import removePrecision from 'src/sliceActions/removePrecision.js';
+
+export default function generateRawData(geometry, settings) {
+ const rawData = {};
+
+ const lines = createLines(geometry, settings);
+
+ const {
+ layerIntersectionIndexes,
+ layerIntersectionPoints
+ } = calculateLayersIntersections(lines, settings);
+
+ rawData.layerIntersectionPoints = layerIntersectionPoints
+ .map(intersectionPoints => intersectionPoints.map(intersectionPoint => intersectionPoint.clone()));
+
+ const layerShapes = intersectionsToShapes(layerIntersectionIndexes, layerIntersectionPoints, lines, settings);
+
+ rawData.layerShapes = layerShapes
+ .map(({ closedShapes, openShapes }) => ({
+ closedShapes: closedShapes.map(closedShape => closedShape.map(vector => vector.clone())),
+ openShapes: openShapes.map(openShape => openShape.map(vector => vector.clone()))
+ }));
+
+
+ applyPrecision(layerShapes);
+
+ const slices = shapesToSlices(layerShapes, settings);
+
+ generateInnerLines(slices, settings);
+ generateInfills(slices, settings);
+ generateSupport(slices, settings);
+ addBrim(slices, settings);
+ optimizePaths(slices, settings);
+ removePrecision(slices);
+
+ rawData.slices = slices;
+
+ const gcode = slicesToGCode(slices, settings);
+
+ rawData.gcode = gcode;
+
+ return rawData;
+}
diff --git a/example/index.html b/example/index.html
index f85f1ec..1d01f2c 100644
--- a/example/index.html
+++ b/example/index.html
@@ -13,6 +13,8 @@
+
+
@@ -21,7 +23,7 @@
-
+