🚀 Auto-deploy: melhoria no snap e medição AR em 04/08/2026 20:46:52
This commit is contained in:
+44
-31
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user