From 4f5538f3a82f3e1eeba6ee039e3a25ab67ed9cb0 Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Tue, 4 Aug 2026 20:46:52 +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:46:52?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lab/QuestCubeLab.tsx | 75 +++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/lab/QuestCubeLab.tsx b/src/lab/QuestCubeLab.tsx index 541ba4c..479c473 100644 --- a/src/lab/QuestCubeLab.tsx +++ b/src/lab/QuestCubeLab.tsx @@ -80,41 +80,48 @@ const CubeControlado = ({ useFrame((state, delta) => { if (!meshRef.current) return; - let gp: Gamepad | null = null; + let gpRight: Gamepad | null = null; + let gpLeft: Gamepad | null = null; + let isWebXR = false; - // Tenta pegar o controle direito da sessão XR if (session && session.inputSources) { + isWebXR = true; 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; - } - } + if (source.gamepad && source.handedness === 'right') gpRight = source.gamepad; + if (source.gamepad && source.handedness === 'left') gpLeft = source.gamepad; } } - // Fallback para Gamepad API nativa (desktop) - if (!gp) { + let gpDesktop: Gamepad | null = null; + if (!isWebXR) { const gamepads = navigator.getGamepads ? navigator.getGamepads() : []; - gp = gamepads[0] || null; + gpDesktop = gamepads[0] || null; } - if (gp && !lockedRef.current && alignPhase === 'IDLE') { - const lx = gp.axes[0] ?? 0; - const ly = gp.axes[1] ?? 0; - const rx = gp.axes[2] ?? 0; - const ry = gp.axes[3] ?? 0; - const lt = gp.buttons[6]?.value ?? 0; - const rt = gp.buttons[7]?.value ?? 0; - const aBtn = gp.buttons[0]?.pressed; + if ((gpRight || gpDesktop) && !lockedRef.current && alignPhase === 'IDLE') { + let lx = 0, ly = 0, rx = 0, ry = 0; + let lt = 0, rt = 0; + let resetBtn = false; + + if (isWebXR) { + // WebXR: Analógicos são os índices 2 e 3. Grips são o botão 1. Botão A/B são 4 e 5. + lx = gpLeft?.axes[2] ?? 0; + ly = gpLeft?.axes[3] ?? 0; + rx = gpRight?.axes[2] ?? 0; + ry = gpRight?.axes[3] ?? 0; + lt = gpLeft?.buttons[1]?.value ?? 0; + rt = gpRight?.buttons[1]?.value ?? 0; + resetBtn = gpRight?.buttons[4]?.pressed || gpRight?.buttons[5]?.pressed || false; + } else { + // Desktop nativo + lx = gpDesktop!.axes[0] ?? 0; + ly = gpDesktop!.axes[1] ?? 0; + rx = gpDesktop!.axes[2] ?? 0; + ry = gpDesktop!.axes[3] ?? 0; + lt = gpDesktop!.buttons[6]?.value ?? 0; + rt = gpDesktop!.buttons[7]?.value ?? 0; + resetBtn = gpDesktop!.buttons[0]?.pressed || false; + } const ax = Math.abs(lx) > STICK_DEADZONE ? lx : 0; const ay = Math.abs(ly) > STICK_DEADZONE ? ly : 0; @@ -133,15 +140,21 @@ const CubeControlado = ({ scaleRef.current = Math.max(0.2, Math.min(3, scaleRef.current + scaleDelta * SCALE_SPEED * delta)); } - if (aBtn && !gamepadRef.current.a) { + if (resetBtn && !gamepadRef.current.a) { posRef.current = { x: 0, y: 0.5, z: 0 }; rotRef.current = { x: 0, y: 0, z: 0 }; scaleRef.current = 1; } - gamepadRef.current.a = aBtn; - } else if (gp && lockedRef.current) { - const rx = gp.axes[2] ?? 0; - const ry = gp.axes[3] ?? 0; + gamepadRef.current.a = resetBtn; + } else if ((gpRight || gpDesktop) && lockedRef.current) { + let rx = 0, ry = 0; + if (isWebXR) { + rx = gpRight?.axes[2] ?? 0; + ry = gpRight?.axes[3] ?? 0; + } else { + rx = gpDesktop!.axes[2] ?? 0; + ry = gpDesktop!.axes[3] ?? 0; + } const arx = Math.abs(rx) > STICK_DEADZONE ? rx : 0; const ary = Math.abs(ry) > STICK_DEADZONE ? ry : 0; rotRef.current.x = (rotRef.current.x + ary * ROT_SPEED * delta) % (Math.PI * 2);