run without leap
s-ol
3 years ago
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | const update = (frame) => { | |
292 | const hand = frame.hands[0]; | |
293 | if (!hand) | |
294 | return; | |
295 | ||
296 | palm.position.set(...hand.palmPosition); | |
297 | palm.quaternion.setFromUnitVectors(new T.Vector3(0, -1, 0), new T.Vector3(...hand.palmNormal)); | |
298 | ||
299 | for (var finger of hand.fingers) { | |
300 | const i = finger.type; | |
301 | fingers[i].update(finger); | |
302 | } | |
303 | } | |
304 | ||
305 | 291 | restore(localStorage.getItem('data')); |
306 | 292 | setInterval(() => { |
307 | 293 | const data = fingers.map(finger => finger.store()); |
308 | 294 | localStorage.setItem('data', JSON.stringify(data)); |
309 | 295 | }, 2000); |
310 | 296 | |
297 | const loop = () => { | |
298 | orbit.update(); | |
299 | renderer.render(scene, camera); | |
300 | ||
301 | requestAnimationFrame(loop); | |
302 | }; | |
303 | loop(); | |
311 | 304 | |
312 | 305 | const controller = Leap.loop({ |
313 | 306 | frameEventName: 'animationFrame', |
315 | 308 | // optimizeHMD: true, |
316 | 309 | background: true, |
317 | 310 | }, frame => { |
318 | update(frame); | |
319 | ||
320 | orbit.update(); | |
321 | renderer.render(scene, camera); | |
311 | const hand = frame.hands[0]; | |
312 | if (!hand) | |
313 | return; | |
314 | ||
315 | palm.position.set(...hand.palmPosition); | |
316 | palm.quaternion.setFromUnitVectors(new T.Vector3(0, -1, 0), new T.Vector3(...hand.palmNormal)); | |
317 | ||
318 | for (var finger of hand.fingers) { | |
319 | const i = finger.type; | |
320 | fingers[i].update(finger); | |
321 | } | |
322 | 322 | }); |
323 |