use printer from state

This commit is contained in:
casperlamboo 2017-11-12 01:41:05 +01:00
parent ccc676ebd1
commit 40d505d754
2 changed files with 14 additions and 5 deletions

View File

@ -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;

View File

@ -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();