diff --git a/src/interface/index.js b/src/interface/index.js
index 00b8fa0..c6b236c 100644
--- a/src/interface/index.js
+++ b/src/interface/index.js
@@ -124,6 +124,12 @@ class Interface extends React.Component {
render();
};
+ updateDrawRange = (event) => {
+ const { gcode, render } = this.state;
+ gcode.linePreview.geometry.setDrawRange(0, event.target.value);
+ render();
+ };
+
componentWillUnmount() {
if (this.state.editorControls) this.state.editorControls.dispose();
if (this.state.control) this.state.control.dispose();
@@ -147,6 +153,16 @@ class Interface extends React.Component {
}
+ {sliced &&
+
+
}
{!sliced &&
}
diff --git a/src/slicer.js b/src/slicer.js
index d608723..84d808f 100644
--- a/src/slicer.js
+++ b/src/slicer.js
@@ -110,15 +110,16 @@ function gcodeToString(gcode) {
const MAX_SPEED = 100 * 60;
function createGcodeGeometry(gcode) {
- const geometry = new THREE.Geometry();
+ const geometry = new THREE.BufferGeometry();
+
+ const positions = [];
+ const colors = [];
let lastPoint
for (let i = 0; i < gcode.length; i ++) {
const { G, F, X, Y, Z } = gcode[i];
if (X || Y || Z) {
- const point = new THREE.Vector3(Y, Z, X);
-
let color;
if (G === 0) {
color = new THREE.Color(0x00ff00);
@@ -127,16 +128,20 @@ function createGcodeGeometry(gcode) {
}
if (G === 1) {
- if (lastPoint) geometry.vertices.push(lastPoint);
- geometry.vertices.push(new THREE.Vector3(Y, Z, X));
- geometry.colors.push(color);
- geometry.colors.push(color);
+ if (lastPoint) positions.push(lastPoint[0], lastPoint[1], lastPoint[2]);
+ positions.push(Y, Z, X);
+
+ colors.push(color.r, color.g, color.b);
+ colors.push(color.r, color.g, color.b);
}
- lastPoint = point;
+ lastPoint = [Y, Z, X];
}
}
+ geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3));
+ geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(colors), 3));
+
const material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
const line = new THREE.LineSegments(geometry, material);