-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.vr.js
96 lines (79 loc) · 2.45 KB
/
index.vr.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
'use strict';
import React from 'react';
import {
AppRegistry,
AmbientLight,
asset,
Model,
Pano,
Text,
Sound,
View,
VrButton,
NativeModules,
} from 'react-vr';
// Native Module defined in vr/client.js
const SphereModule = NativeModules.SphereModule;
class SphereSample extends React.Component {
constructor(props) {
super(props);
this.state = {btnColor: 'white', sphereColor: 'yellow'};
SphereModule.changeSphereColor(this.state.sphereColor);
}
render() {
return (
<View
style={{
transform:[{translate: [0, 0, -3]}],
layoutOrigin: [0.5, 0, 0],
alignItems: 'center',
}}>
<Sound
source={{
mp3: asset('ambient.mp3'),
}}
/>
<Pano source={ { uri: [
'../static_assets/lagoon_rt.jpg',
'../static_assets/lagoon_lf.jpg',
'../static_assets/lagoon_up.jpg',
'../static_assets/lagoon_dn.jpg',
'../static_assets/lagoon_bk.jpg',
'../static_assets/lagoon_ft.jpg' ] } } />
<AmbientLight intensity={ 2.6 } />
<Model style={{ transform: [ {translate: [-28, 14, -28]}, {scale: 0.1 }, {rotateY: -130}, {rotateX: 20}, {rotateZ: -10} ], }}
source={{mesh:asset('moon.obj'), mtl:asset('moon.mtl'), lit: true}} />
<VrButton
style={{
backgroundColor: this.state.btnColor,
borderRadius: 0.05,
margin: 0.05,
}}
onEnter={()=>{this.setState({btnColor: this.state.sphereColor})}}
onExit={()=>{this.setState({btnColor: 'white'})}}
onClick={()=>{
let hexColor = Math.floor(Math.random()*0xffffff).toString(16);
hexColor = '#'+(('000000'+hexColor).slice(-6));
this.setState({sphereColor: hexColor, btnColor: hexColor});
SphereModule.changeSphereColor(hexColor);
}}
onClickSound={asset('freesound__146721__fins__menu-click.wav')}
onEnterSound={asset('freesound__278205__ianstargem__switch-flip-1.wav')}
>
<Text style={{
fontSize: 0.15,
paddingTop: 0.025,
paddingBottom: 0.025,
paddingLeft: 0.05,
paddingRight: 0.05,
textAlign:'center',
textAlignVertical:'center',
}}>
button
</Text>
</VrButton>
</View>
);
}
};
AppRegistry.registerComponent('SphereSample', () => SphereSample);