diff --git a/src/components/three/XRGrabbable.tsx b/src/components/three/XRGrabbable.tsx index a565099..5fa624c 100644 --- a/src/components/three/XRGrabbable.tsx +++ b/src/components/three/XRGrabbable.tsx @@ -1,5 +1,6 @@ import { useRef, ReactNode, useEffect } from 'react'; import { useFrame } from '@react-three/fiber'; +import { useXR } from '@react-three/xr'; import * as THREE from 'three'; import { useControllerGrab, ControllerGrabSnapshot } from '@/hooks/useControllerGrab'; import { useModelStore } from '@/stores/useModelStore'; @@ -57,6 +58,7 @@ const _tmpQuat = new THREE.Quaternion(); export function XRGrabbable({ allowScale = true, lockedActive = false, onGrabStart, children }: XRGrabbableProps) { const groupRef = useRef(null); const grab = useControllerGrab(); + const session = useXR((s) => s.session); const single = useRef(null); const dual = useRef(null); @@ -74,9 +76,10 @@ export function XRGrabbable({ allowScale = true, lockedActive = false, onGrabSta }, [scaleResetNonce]); useEffect(() => { - activeModelGroupRef.current = groupRef.current; + const currentGroup = groupRef.current; + activeModelGroupRef.current = currentGroup; return () => { - if (activeModelGroupRef.current === groupRef.current) { + if (activeModelGroupRef.current === currentGroup) { activeModelGroupRef.current = null; } }; @@ -232,7 +235,8 @@ export function XRGrabbable({ allowScale = true, lockedActive = false, onGrabSta } // Rotação Y via analógico do controle ativo - const gp = slot.gamepad; + const inputSource = session?.inputSources ? Array.from(session.inputSources).find(s => s.handedness === activeHand) : null; + const gp = inputSource?.gamepad; if (gp && gp.axes.length >= 4) { const stickX = gp.axes[2]; // horizontal do thumbstick const deadzone = 0.15;