forked from expo/expo-three
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic.js
59 lines (52 loc) · 1.66 KB
/
Basic.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
import { AR } from 'expo';
import ExpoTHREE, { AR as ThreeAR, THREE } from 'expo-three';
import React from 'react';
import { Text, View } from 'react-native';
import { View as GraphicsView } from 'expo-graphics';
export default class App extends React.Component {
static url = 'screens/AR/Basic.js';
render() {
return (
<View style={{ flex: 1 }}>
<GraphicsView
style={{ flex: 2 }}
onContextCreate={this.onContextCreate}
onRender={this.onRender}
onResize={this.onResize}
isArEnabled
isArRunningStateEnabled
isArCameraStateEnabled
arTrackingConfiguration={AR.TrackingConfigurations.World}
/>
<View
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>😮 Works with any size viewport, try rotating your phone.</Text>
</View>
</View>
);
}
onContextCreate = props => {
AR.setPlaneDetection(AR.PlaneDetectionTypes.Horizontal);
this.commonSetup(props);
};
commonSetup = ({ gl, scale: pixelRatio, width, height }) => {
this.renderer = new ExpoTHREE.Renderer({
gl,
pixelRatio,
width,
height,
});
this.scene = new THREE.Scene();
this.scene.background = new ThreeAR.BackgroundTexture(this.renderer);
this.camera = new ThreeAR.Camera(width, height, 0.01, 1000);
};
onResize = ({ x, y, scale, width, height }) => {
this.camera.aspect = width / height;
this.camera.updateProjectionMatrix();
this.renderer.setPixelRatio(scale);
this.renderer.setSize(width, height);
};
onRender = () => {
this.renderer.render(this.scene, this.camera);
};
}