From 5ce3636933ce7fc028073faf4446e8bc694a4202 Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Tue, 4 Aug 2026 20:36:21 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Auto-deploy:=20melhoria=20no=20s?= =?UTF-8?q?nap=20e=20medi=C3=A7=C3=A3o=20AR=20em=2004/08/2026=2020:36:21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lab/QuestCubeLab.tsx | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) 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;