This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.js
118 lines (99 loc) · 2.45 KB
/
index.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import React from 'react';
import React3 from 'react-three-renderer';
import * as THREE from 'three';
import ExampleBase from '../ExampleBase';
import Info from './Info';
class Manual extends ExampleBase {
constructor(props, context) {
super(props, context);
this.cameraPosition = new THREE.Vector3(0, 0, 5);
this._onManualRenderTriggerCreated = (renderTrigger) => {
// assign to variable to be able to reuse the trigger
this._renderTrigger = renderTrigger;
};
this.state = {
cubeColor: 0x00ff00,
forceManual: true,
};
}
componentDidMount() {
// render one frame to show initial scene
this._renderTrigger();
setTimeout(() => {
// this should not be visible!
this.setState({
cubeColor: 0x0000ff,
});
}, 20);
setTimeout(() => {
// render again after updating color
this.setState({
cubeColor: 0xff0000,
}, () => {
this._renderTrigger();
});
}, 1000);
}
_onUpdateColorButtonPress = () => {
this.setState({
cubeColor: Math.floor(Math.random() * 0xffffff),
});
};
_onRenderButtonPress = () => {
this._renderTrigger();
};
_onManualButtonPress = () => {
this.setState({
forceManual: !this.state.forceManual,
});
};
render() {
const {
width,
height,
} = this.props;
const {
forceManual,
cubeColor,
} = this.state;
return (<div>
<div>
<Info
onUpdateColorButtonPress={this._onUpdateColorButtonPress}
onRenderButtonPress={this._onRenderButtonPress}
onManualButtonPress={this._onManualButtonPress}
forceManual={forceManual}
cubeColor={cubeColor}
/>
</div>
<React3
width={width}
height={height}
forceManualRender={forceManual}
onManualRenderTriggerCreated={this._onManualRenderTriggerCreated}
mainCamera="camera"
>
<scene>
<perspectiveCamera
name="camera"
fov={75}
aspect={width / height}
near={0.1}
far={1000}
position={this.cameraPosition}
/>
<mesh>
<boxGeometry
width={1}
height={1}
depth={1}
/>
<meshBasicMaterial
color={cubeColor}
/>
</mesh>
</scene>
</React3></div>);
}
}
export default Manual;