-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
181 lines (157 loc) · 6.01 KB
/
App.tsx
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { ExpoWebGLRenderingContext, GLView } from 'expo-gl'
import { Renderer, TextureLoader } from 'expo-three'
import React, { useRef, useEffect, useState } from 'react'
import {
AmbientLight,
BoxBufferGeometry,
Fog,
GridHelper,
Mesh,
MeshStandardMaterial,
PerspectiveCamera,
PointLight,
Scene,
SpotLight,
} from 'three'
import { View } from 'react-native'
//expo camera
import { Camera } from 'expo-camera'
import * as FaceDetector from 'expo-face-detector'
export default function App() {
let timeout
React.useEffect(() => {
// Clear the animation loop when the component unmounts
return () => clearTimeout(timeout)
}, [])
const cameraRef = useRef()
const coordinateX = useRef(0)
const coordinateY = useRef(0)
const [y, setY] = useState(0)
useEffect(() => {
const getPerm = async () => {
const { status } = await Camera.requestPermissionsAsync()
// setHasPermission(status === 'granted')
// if (status === 'granted') {
// props.navigation.navigate('CameraScreen')
// } else {
// return
// }
}
getPerm()
}, [])
return (
<View style={{ flex: 1 }}>
<Camera
style={{
flex: 1,
position: 'absolute',
right: 0,
top: 0,
left: 0,
bottom: 0,
}}
ref={cameraRef}
type={Camera.Constants.Type.front}
// flashMode={flashMode}
// zoom={zooming}
onFacesDetected={(face) => {
// console.log(face.faces)
if (face.faces.length > 0) {
coordinateX.current = face.faces[0].noseBasePosition.y
coordinateY.current = face.faces[0].noseBasePosition.y
// console.log(face.faces)
// console.log(coordinateY.current.toFixed(1) / 100)
}
}}
faceDetectorSettings={{
mode: FaceDetector.Constants.Mode.fast,
detectLandmarks: FaceDetector.Constants.Landmarks.all,
runClassifications:
FaceDetector.Constants.Classifications.none,
minDetectionInterval: 100,
tracking: true,
}}
></Camera>
<GLView
style={{
flex: 1,
position: 'absolute',
right: 0,
top: 0,
left: 0,
bottom: 0,
}}
onContextCreate={async (gl: ExpoWebGLRenderingContext) => {
const {
drawingBufferWidth: width,
drawingBufferHeight: height,
} = gl
const sceneColor = 'rgba(0,0,0)'
// Create a WebGLRenderer without a DOM element
const renderer = new Renderer({ gl })
renderer.setSize(width, height)
// renderer.setClearColor(sceneColor)
const camera = new PerspectiveCamera(
// closeness and farness of camera
20,
width / height,
1,
1000
)
camera.position.set(0, 50, 1)
const scene = new Scene()
scene.fog = new Fog(sceneColor, 1, 10000)
// scene.add(new GridHelper(10, 10))
const ambientLight = new AmbientLight(0x101010)
scene.add(ambientLight)
const pointLight = new PointLight(0xffffff, 2, 1000, 1)
pointLight.position.set(300, 400, 200)
scene.add(pointLight)
const spotLight = new SpotLight(0xffffff, 0.5)
spotLight.position.set(0, 100, 100)
spotLight.lookAt(scene.position)
scene.add(spotLight)
const cube = new IconMesh()
cube.position.set(0, 0, 0)
scene.add(cube)
camera.lookAt(cube.position)
// camera.up.set(0, 0, -10)
function update() {
// cube.rotation.Y +=
// coordinateX.current.toFixed(1) / 10000
cube.rotation.x +=
coordinateY.current.toFixed(1) / 10000
// cube.translateX(coordinateX.current.toFixed(1) / 100000)
// cube.translateY(
// -(coordinateY.current.toFixed(1) / 100000)
// )
// cube.translateX(coordinateX.current.toFixed(1) / 10000)
// cube.translateY(coordinateY.current.toFixed(1) / 100000)
// cube.translateZ(coordinateY.current.toFixed(1) / 100000)
// camera.translateZ(0.05)
// camera.rotateOnAxis(new THREE.Vector3(0, 0, 0), 3)
}
// Setup an animation loop
const render = () => {
timeout = requestAnimationFrame(render)
update()
renderer.render(scene, camera)
gl.endFrameEXP()
}
render()
}}
/>
</View>
)
}
class IconMesh extends Mesh {
constructor() {
super(
new BoxBufferGeometry(1.0, 1.0, 1.0),
new MeshStandardMaterial({
map: new TextureLoader().load(require('./assets/icon.png')),
color: 0xff0000,
})
)
}
}