add slice again button

This commit is contained in:
casperlamboo 2017-11-12 01:04:26 +01:00
parent 849f3f893a
commit 3b4df148ed

View File

@ -68,7 +68,19 @@ class Interface extends React.Component {
placeOnGround(mesh); placeOnGround(mesh);
render(); render();
} }
} };
reset = () => {
const { control, mesh, render, gcode, scene } = this.state;
control.visible = true;
mesh.visible = true;
scene.remove(gcode.linePreview);
gcode.linePreview.geometry.dispose();
this.setState({ sliced: false, gcode: null });
render();
};
slice = async () => { slice = async () => {
const { mesh, render, scene, control } = this.state; const { mesh, render, scene, control } = this.state;
@ -86,20 +98,21 @@ class Interface extends React.Component {
mesh.updateMatrix(); mesh.updateMatrix();
const matrix = new THREE.Matrix4().makeTranslation(centerY, 0, centerX).multiply(mesh.matrix); const matrix = new THREE.Matrix4().makeTranslation(centerY, 0, centerX).multiply(mesh.matrix);
const { gcode, linePreview } = await sliceGeometry(settings, geometry, matrix, true, true, (process) => { const gcode = await sliceGeometry(settings, geometry, matrix, true, true, (process) => {
console.log('process: ', process); console.log('process: ', process);
}); });
// can't disable control so remove it // TODO
control.dispose(); // can't disable control
scene.remove(control, mesh); control.visible = false;
mesh.visible = false;
linePreview.position.x = -centerY; gcode.linePreview.position.x = -centerY;
linePreview.position.z = -centerX; gcode.linePreview.position.z = -centerX;
scene.add(linePreview); scene.add(gcode.linePreview);
this.setState({ sliced: true, gcode });
render(); render();
this.setState({ sliced: true });
}; };
componentWillUnmount() { componentWillUnmount() {
@ -127,6 +140,10 @@ class Interface extends React.Component {
{!sliced && <div className={classes.sliceBar}> {!sliced && <div className={classes.sliceBar}>
<button onClick={this.slice}>Slice</button> <button onClick={this.slice}>Slice</button>
</div>} </div>}
{sliced && <div className={classes.sliceBar}>
<button onClick={this.reset}>Slice Again</button>
<button>Download</button>
</div>}
</div> </div>
); );
} }