mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 13:37:58 +01:00
better resize handling
This commit is contained in:
parent
81d842cc8c
commit
8e985669ed
@ -11,6 +11,9 @@ injectTapEventPlugin();
|
|||||||
|
|
||||||
document.body.style.margin = 0;
|
document.body.style.margin = 0;
|
||||||
document.body.style.padding = 0;
|
document.body.style.padding = 0;
|
||||||
|
document.body.style.height = '100%';
|
||||||
|
document.documentElement.style.height = '100%'
|
||||||
|
document.getElementById('app').style.height = '100%';
|
||||||
|
|
||||||
const downloadGCode = gcode => {
|
const downloadGCode = gcode => {
|
||||||
const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
|
const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
|
||||||
@ -23,8 +26,6 @@ jsonLoader.load(fileURL, geometry => {
|
|||||||
<MuiThemeProvider>
|
<MuiThemeProvider>
|
||||||
<Interface
|
<Interface
|
||||||
geometry={geometry}
|
geometry={geometry}
|
||||||
width={window.innerWidth}
|
|
||||||
height={window.innerHeight}
|
|
||||||
onCompleteActions={[{ title: 'Download', callback: downloadGCode }]}
|
onCompleteActions={[{ title: 'Download', callback: downloadGCode }]}
|
||||||
/>
|
/>
|
||||||
</MuiThemeProvider>
|
</MuiThemeProvider>
|
||||||
|
8
package-lock.json
generated
8
package-lock.json
generated
@ -3362,6 +3362,14 @@
|
|||||||
"theming": "1.1.0"
|
"theming": "1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"react-resize-detector": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-resize-detector/-/react-resize-detector-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-68KVcQlhcWQGXMAie82YueCa4f4yqwEoiQbVyYlSgJEin1zMtNBLLeU/+6FLNf1TTgjwSfpbMTJTw/uU0HNgtQ==",
|
||||||
|
"requires": {
|
||||||
|
"prop-types": "15.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-transition-group": {
|
"react-transition-group": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-1.2.1.tgz",
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"react": "^16.1.0",
|
"react": "^16.1.0",
|
||||||
"react-dom": "^16.1.0",
|
"react-dom": "^16.1.0",
|
||||||
"react-jss": "^7.2.0",
|
"react-jss": "^7.2.0",
|
||||||
|
"react-resize-detector": "^1.1.0",
|
||||||
"three": "^0.83.0"
|
"three": "^0.83.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -10,10 +10,6 @@ import { grey500 } from 'material-ui/styles/colors';
|
|||||||
const styles = {
|
const styles = {
|
||||||
textFieldRow: {
|
textFieldRow: {
|
||||||
display: 'flex'
|
display: 'flex'
|
||||||
},
|
|
||||||
content: {
|
|
||||||
maxHeight: '500px',
|
|
||||||
overflowY: 'auto'
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -59,8 +55,8 @@ class Settings extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<Tab label="basic settings">
|
<Tab label="basic">
|
||||||
<div className={classes.content}>
|
<div>
|
||||||
<SelectField name="printers" floatingLabelText="Printer" fullWidth>
|
<SelectField name="printers" floatingLabelText="Printer" fullWidth>
|
||||||
{Object.entries(printers).map(([value, { title }]) => (
|
{Object.entries(printers).map(([value, { title }]) => (
|
||||||
<MenuItem key={value} value={value} primaryText={title} />
|
<MenuItem key={value} value={value} primaryText={title} />
|
||||||
@ -78,8 +74,8 @@ class Settings extends React.Component {
|
|||||||
</SelectField>
|
</SelectField>
|
||||||
</div>
|
</div>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab label="advanced settings">
|
<Tab label="advanced">
|
||||||
<div className={classes.content}>
|
<div>
|
||||||
<SettingsGroup name="Printer dimensions">
|
<SettingsGroup name="Printer dimensions">
|
||||||
<div className={classes.textFieldRow}>
|
<div className={classes.textFieldRow}>
|
||||||
<TextField name="settings.dimensions.x" fullWidth floatingLabelText="X" type="number" />
|
<TextField name="settings.dimensions.x" fullWidth floatingLabelText="X" type="number" />
|
||||||
|
@ -6,34 +6,40 @@ import { placeOnGround, createScene, createGcodeGeometry } from './utils.js';
|
|||||||
import injectSheet from 'react-jss';
|
import injectSheet from 'react-jss';
|
||||||
import { sliceGeometry } from '../slicer.js';
|
import { sliceGeometry } from '../slicer.js';
|
||||||
import RaisedButton from 'material-ui/RaisedButton';
|
import RaisedButton from 'material-ui/RaisedButton';
|
||||||
import Paper from 'material-ui/Paper';
|
|
||||||
import Slider from 'material-ui/Slider';
|
import Slider from 'material-ui/Slider';
|
||||||
import { grey50 } from 'material-ui/styles/colors';
|
import { grey100, grey300 } from 'material-ui/styles/colors';
|
||||||
import Settings from './Settings.js';
|
import Settings from './Settings.js';
|
||||||
import baseSettings from '../settings/default.yml';
|
import baseSettings from '../settings/default.yml';
|
||||||
import printerSettings from '../settings/printer.yml';
|
import printerSettings from '../settings/printer.yml';
|
||||||
import materialSettings from '../settings/material.yml';
|
import materialSettings from '../settings/material.yml';
|
||||||
import qualitySettings from '../settings/quality.yml';
|
import qualitySettings from '../settings/quality.yml';
|
||||||
|
import ReactResizeDetector from 'react-resize-detector';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
container: {
|
container: {
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
backgroundColor: grey50
|
display: 'flex',
|
||||||
},
|
height: '100%',
|
||||||
canvas: {
|
backgroundColor: grey100,
|
||||||
position: 'absolute',
|
overflow: 'hidden'
|
||||||
},
|
},
|
||||||
controlBar: {
|
controlBar: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
bottom: '10px',
|
bottom: '10px',
|
||||||
left: '10px'
|
left: '10px'
|
||||||
},
|
},
|
||||||
|
d3View: {
|
||||||
|
flexGrow: 1
|
||||||
|
},
|
||||||
|
canvas: {
|
||||||
|
position: 'absolute'
|
||||||
|
},
|
||||||
sliceBar: {
|
sliceBar: {
|
||||||
position: 'absolute',
|
width: '240px',
|
||||||
top: '10px',
|
padding: '0 10px',
|
||||||
right: '10px',
|
overflowY: 'auto',
|
||||||
width: '380px',
|
backgroundColor: 'white',
|
||||||
padding: '10px 20px',
|
borderLeft: `1px solid ${grey300}`
|
||||||
},
|
},
|
||||||
overlay: {
|
overlay: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
@ -164,17 +170,26 @@ class Interface extends React.Component {
|
|||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
if (setSize && nextProps.width !== this.props.width || nextProps.height !== this.props.height || nextProps.pixelRatio !== this.props.pixelRatio) {
|
if (setSize && nextProps.width !== this.props.width || nextProps.height !== this.props.height || nextProps.pixelRatio !== this.props.pixelRatio) {
|
||||||
console.log('update pixel ratio');
|
|
||||||
setSize(nextProps.width, nextProps.height, nextProps.pixelRatio);
|
setSize(nextProps.width, nextProps.height, nextProps.pixelRatio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onResize = (width, height) => {
|
||||||
|
window.requestAnimationFrame(() => {
|
||||||
|
const { setSize } = this.state;
|
||||||
|
const { pixelRatio } = this.props;
|
||||||
|
setSize(width, height, pixelRatio);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { width, height, classes, onCompleteActions, defaultPrinter, defaultQuality, defaultMaterial } = this.props;
|
const { width, height, classes, onCompleteActions, defaultPrinter, defaultQuality, defaultMaterial } = this.props;
|
||||||
const { sliced, isSlicing, progress, gcode, controlMode, settings } = this.state;
|
const { sliced, isSlicing, progress, gcode, controlMode, settings } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ width, height }} className={classes.container}>
|
<div className={classes.container}>
|
||||||
|
<div className={classes.d3View}>
|
||||||
|
<ReactResizeDetector handleWidth handleHeight onResize={this.onResize} />
|
||||||
<canvas className={classes.canvas} ref="canvas" width={width} height={height} />
|
<canvas className={classes.canvas} ref="canvas" width={width} height={height} />
|
||||||
{!sliced && <div className={classes.controlBar}>
|
{!sliced && <div className={classes.controlBar}>
|
||||||
<RaisedButton className={classes.controlButton} onTouchTap={this.resetMesh} primary label="reset" />
|
<RaisedButton className={classes.controlButton} onTouchTap={this.resetMesh} primary label="reset" />
|
||||||
@ -182,6 +197,7 @@ class Interface extends React.Component {
|
|||||||
<RaisedButton className={classes.controlButton} disabled={controlMode === 'rotate'} onTouchTap={() => this.setState({ controlMode: 'rotate' })} primary label="rotate" />
|
<RaisedButton className={classes.controlButton} disabled={controlMode === 'rotate'} onTouchTap={() => this.setState({ controlMode: 'rotate' })} primary label="rotate" />
|
||||||
<RaisedButton className={classes.controlButton} disabled={controlMode === 'scale'} onTouchTap={() => this.setState({ controlMode: 'scale' })} primary label="scale" />
|
<RaisedButton className={classes.controlButton} disabled={controlMode === 'scale'} onTouchTap={() => this.setState({ controlMode: 'scale' })} primary label="scale" />
|
||||||
</div>}
|
</div>}
|
||||||
|
</div>
|
||||||
{sliced && <div className={classes.controlBar}>
|
{sliced && <div className={classes.controlBar}>
|
||||||
<Slider
|
<Slider
|
||||||
axis="y"
|
axis="y"
|
||||||
@ -193,7 +209,7 @@ class Interface extends React.Component {
|
|||||||
onChange={this.updateDrawRange}
|
onChange={this.updateDrawRange}
|
||||||
/>
|
/>
|
||||||
</div>}
|
</div>}
|
||||||
{!sliced && <Paper className={classes.sliceBar}>
|
{!sliced && <div className={classes.sliceBar}>
|
||||||
<Settings
|
<Settings
|
||||||
printers={printerSettings}
|
printers={printerSettings}
|
||||||
defaultPrinter={defaultPrinter}
|
defaultPrinter={defaultPrinter}
|
||||||
@ -205,13 +221,13 @@ class Interface extends React.Component {
|
|||||||
onChange={this.onChangeSettings}
|
onChange={this.onChangeSettings}
|
||||||
/>
|
/>
|
||||||
<RaisedButton className={classes.button} fullWidth disabled={isSlicing} onTouchTap={this.slice} primary label="slice" />
|
<RaisedButton className={classes.button} fullWidth disabled={isSlicing} onTouchTap={this.slice} primary label="slice" />
|
||||||
</Paper>}
|
</div>}
|
||||||
{sliced && <Paper className={classes.sliceBar}>
|
{sliced && <div className={classes.sliceBar}>
|
||||||
<RaisedButton className={classes.button} fullWidth onTouchTap={this.reset} primary label="slice again" />
|
<RaisedButton className={classes.button} fullWidth onTouchTap={this.reset} primary label="slice again" />
|
||||||
{onCompleteActions.map(({ title, callback }, i) => (
|
{onCompleteActions.map(({ title, callback }, i) => (
|
||||||
<RaisedButton className={classes.button} key={i} fullWidth onTouchTap={() => callback(gcode.gcode, settings)} primary label={title} />
|
<RaisedButton className={classes.button} key={i} fullWidth onTouchTap={() => callback(gcode.gcode, settings)} primary label={title} />
|
||||||
))}
|
))}
|
||||||
</Paper>}
|
</div>}
|
||||||
{isSlicing && <div className={classes.overlay}>
|
{isSlicing && <div className={classes.overlay}>
|
||||||
<p>Slicing: {progress.percentage.toLocaleString(navigator.language, { style: 'percent' })}</p>
|
<p>Slicing: {progress.percentage.toLocaleString(navigator.language, { style: 'percent' })}</p>
|
||||||
<ul className={classes.sliceActions}>
|
<ul className={classes.sliceActions}>
|
||||||
@ -228,8 +244,6 @@ Interface.propTypes = {
|
|||||||
throw new Error('invalid prop, is not geometry');
|
throw new Error('invalid prop, is not geometry');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
width: PropTypes.number.isRequired,
|
|
||||||
height: PropTypes.number.isRequired,
|
|
||||||
classes: PropTypes.objectOf(PropTypes.string),
|
classes: PropTypes.objectOf(PropTypes.string),
|
||||||
onCompleteActions: PropTypes.arrayOf(PropTypes.shape({ title: PropTypes.string, callback: PropTypes.func })).isRequired,
|
onCompleteActions: PropTypes.arrayOf(PropTypes.shape({ title: PropTypes.string, callback: PropTypes.func })).isRequired,
|
||||||
defaultSettings: PropTypes.object.isRequired,
|
defaultSettings: PropTypes.object.isRequired,
|
||||||
@ -249,8 +263,6 @@ Interface.defaultProps = {
|
|||||||
defaultQuality: 'medium',
|
defaultQuality: 'medium',
|
||||||
material: materialSettings,
|
material: materialSettings,
|
||||||
defaultMaterial: 'pla',
|
defaultMaterial: 'pla',
|
||||||
width: 720,
|
|
||||||
height: 480,
|
|
||||||
pixelRatio: 1
|
pixelRatio: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ export function placeOnGround(mesh) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createScene(canvas, props, state) {
|
export function createScene(canvas, props, state) {
|
||||||
const { width, height, geometry, pixelRatio } = props;
|
const { geometry, pixelRatio } = props;
|
||||||
const { controlMode, settings } = state;
|
const { controlMode, settings } = state;
|
||||||
|
|
||||||
// center geometry
|
// center geometry
|
||||||
@ -78,7 +78,5 @@ export function createScene(canvas, props, state) {
|
|||||||
const { dimensions } = settings;
|
const { dimensions } = settings;
|
||||||
box.scale.set(dimensions.y, dimensions.z, dimensions.x);
|
box.scale.set(dimensions.y, dimensions.z, dimensions.x);
|
||||||
|
|
||||||
setSize(width, height, pixelRatio);
|
|
||||||
|
|
||||||
return { control, editorControls, scene, mesh, camera, renderer, render, box, setSize };
|
return { control, editorControls, scene, mesh, camera, renderer, render, box, setSize };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user