forked from expo/expo-three
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoints.js
47 lines (40 loc) · 1.38 KB
/
Points.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
import { AR } from 'expo';
import ExpoTHREE, { THREE, AR as ThreeAR } from 'expo-three';
import React from 'react';
import { View as GraphicsView } from 'expo-graphics';
export default class App extends React.Component {
static url = 'screens/AR/Points.js';
render() {
return (
<GraphicsView
style={{ flex: 1 }}
onContextCreate={this.onContextCreate}
onRender={this.onRender}
onResize={this.onResize}
arTrackingConfiguration={AR.TrackingConfigurations.World}
isArEnabled
isArRunningStateEnabled
isArCameraStateEnabled
/>
);
}
onContextCreate = async ({ gl, scale: pixelRatio, width, height }) => {
AR.setPlaneDetection(AR.PlaneDetectionTypes.Horizontal);
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);
this.points = new ThreeAR.Points();
this.scene.add(this.points);
};
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.points.update();
this.renderer.render(this.scene, this.camera);
};
}