diff --git a/src/interface/index.js b/src/interface/index.js index bc0b57c..00b8fa0 100644 --- a/src/interface/index.js +++ b/src/interface/index.js @@ -53,6 +53,14 @@ class Interface extends React.Component { sliced: false }; + constructor(props) { + super(props); + this.state = { + printer: props.defaultPrinter + }; + } + + componentDidMount() { const { canvas } = this.refs; const scene = createScene(canvas, this.props, this.state); @@ -84,11 +92,11 @@ class Interface extends React.Component { }; slice = async () => { - const { mesh, render, scene, control } = this.state; + const { mesh, render, scene, control, printer } = this.state; const settings = { ...baseSettings, ...materialSettings.pla, - ...printerSettings[this.props.defaultPrinter] + ...printerSettings[printer] }; const { dimensions } = settings; diff --git a/src/interface/utils.js b/src/interface/utils.js index 865bc7a..af53438 100644 --- a/src/interface/utils.js +++ b/src/interface/utils.js @@ -26,7 +26,8 @@ export function createScene(canvas, props, state) { const centerZ = (geometry.boundingBox.max.z + geometry.boundingBox.min.z) / 2; geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-centerX, -centerY, -centerZ)); - const { width, height, printers, defaultPrinter } = props; + const { width, height, printers } = props; + const { controlMode, printer } = state; const renderer = new THREE.WebGLRenderer({ canvas, alpha: true }); renderer.setClearColor(0xffffff, 0); @@ -52,7 +53,7 @@ export function createScene(canvas, props, state) { const editorControls = new THREE.EditorControls(camera, canvas); const control = new THREE.TransformControls(camera, canvas); - control.setMode(state.controlMode); + control.setMode(controlMode); control.setRotationSnap(THREE.Math.degToRad(45)); control.addEventListener('mouseDown', () => editorControls.enabled = false); control.addEventListener('mouseUp', () => { @@ -76,7 +77,7 @@ export function createScene(canvas, props, state) { box.material.color.setHex(0x72bcd4); scene.add(box); - const { dimensions } = printers[defaultPrinter]; + const { dimensions } = printers[printer]; box.scale.set(dimensions.y, dimensions.z, dimensions.x); render();