blob: 4fd8e805f669970a57ce41e8e9b97beadbc3363c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/**
* Display an STL file in a 3D viewer i.e. for Nora
*/
import React, { Component } from 'react'
import { connect } from 'react-redux'
import STLViewer from '../stl/STLViewer'
import { STL_FILES } from '../stl-files.js'
class StlOverlay extends Component {
state = {
stl: null,
}
constructor(props) {
super(props)
}
componentDidMount() {
this.load()
}
componentDidUpdate(prevProps) {
// console.log(this.props.location.pathname, prevProps.location.pathname)
if (this.props.location.pathname !== prevProps.location.pathname) {
this.load()
}
}
load() {
const { page_name } = this.props.match.params
if (STL_FILES[page_name]) {
this.setState({
stl: STL_FILES[page_name],
})
} else {
this.setState({
stl: null,
})
}
}
render() {
const { stl } = this.state
if (!this.props.interactive || !stl) return null
return (
<STLViewer
url={stl?.url}
style={stl?.style}
transform={stl?.transform}
width={stl?.width()}
height={stl?.height()}
modelMaterial={stl?.modelMaterial}
backgroundColor='#000000'
rotate={true}
orbitControls={true}
/>
);
}
}
const mapStateToProps = state => ({
interactive: state.site.interactive,
})
export default connect(mapStateToProps)(StlOverlay)
|