diff --git a/src/lab/QuestCubeLab.tsx b/src/lab/QuestCubeLab.tsx index 41f7710..541ba4c 100644 --- a/src/lab/QuestCubeLab.tsx +++ b/src/lab/QuestCubeLab.tsx @@ -7,7 +7,7 @@ import { Environment, PerspectiveCamera, } from "@react-three/drei"; -import { XR } from "@react-three/xr"; +import { XR, useXR } from "@react-three/xr"; import { xrStore as store } from "@/stores/useXRStore"; import * as THREE from "three"; import { @@ -66,6 +66,7 @@ const CubeControlado = ({ face2Ref: React.MutableRefObject; }) => { const meshRef = useRef(null); + const session = useXR((state) => state.session); const materials = [ new THREE.MeshStandardMaterial({ color: "#ef4444" }), // +x @@ -79,8 +80,32 @@ const CubeControlado = ({ useFrame((state, delta) => { if (!meshRef.current) return; - const gamepads = navigator.getGamepads ? navigator.getGamepads() : []; - const gp = gamepads[0]; + let gp: Gamepad | null = null; + + // Tenta pegar o controle direito da sessão XR + if (session && session.inputSources) { + for (const source of session.inputSources) { + if (source.gamepad && source.handedness === 'right') { + gp = source.gamepad; + break; + } + } + // Se não achar o direito, pega o esquerdo + if (!gp) { + for (const source of session.inputSources) { + if (source.gamepad && source.handedness === 'left') { + gp = source.gamepad; + break; + } + } + } + } + + // Fallback para Gamepad API nativa (desktop) + if (!gp) { + const gamepads = navigator.getGamepads ? navigator.getGamepads() : []; + gp = gamepads[0] || null; + } if (gp && !lockedRef.current && alignPhase === 'IDLE') { const lx = gp.axes[0] ?? 0;