import { signal, computed } from '@preact/signals-core' import { useGLTF } from '@react-three/drei' import { useFrame, useThree } from '@react-three/fiber' import { Root, Text, Container } from '@react-three/uikit' import { FootprintsIcon, GoalIcon, PlayIcon } from '@react-three/uikit-lucide' import { XRHandModel, XRSpace } from '@react-three/xr' import { Suspense, useMemo, useRef, useState } from 'react' import { Vector3 } from 'three' export function HandWithWatch() { return ( <> ) } const vectorHelper = new Vector3() export function Watch(props: any) { const { nodes, materials } = useGLTF('watch-v1.glb') const [state, setState] = useState<'walking' | 'paused' | 'stopped'>('stopped') const distanceSignal = useMemo(() => signal(0), []) const camera = useThree((state) => state.camera) const ref = useRef(null) useFrame(() => { if (state != 'walking') { return } camera.getWorldPosition(vectorHelper) if (ref.current == null) { // eslint-disable-next-line @react-three/no-clone-in-loop ref.current = vectorHelper.clone() return } ref.current.sub(vectorHelper) ref.current.y = 0 distanceSignal.value += ref.current.length() ref.current.copy(vectorHelper) }) return ( {state === 'stopped' && ( setState('walking')} > Let's go )} {state === 'walking' && ( setState('paused')} > {computed(() => distanceSignal.value.toFixed(0))} METER )} {state === 'paused' && ( setState('walking')} > RESUME { distanceSignal.value = 0 setState('stopped') }} backgroundOpacity={0.2} hover={{ backgroundColor: 'white' }} cursor="pointer" > FINISH )} ) }