🚀 Auto-deploy: melhoria no snap e medição AR em 04/08/2026 21:12:43

This commit is contained in:
2026-08-04 21:12:43 +00:00
parent 8807b18c55
commit 028221ab04
+27 -30
View File
@@ -38,7 +38,7 @@ const TRIGGER_DEADZONE = 0.05;
const MOVE_SPEED = 1.5; const MOVE_SPEED = 1.5;
const ROT_SPEED = 1.2; const ROT_SPEED = 1.2;
const SCALE_SPEED = 0.6; const SCALE_SPEED = 0.6;
const CUBE_SIZE = 1; const CUBE_SIZE = 0.3;
type AlignPhase = 'IDLE' | 'WAIT_SURFACE' | 'WAIT_FACE2' | 'WAIT_EDGE'; type AlignPhase = 'IDLE' | 'WAIT_SURFACE' | 'WAIT_FACE2' | 'WAIT_EDGE';
@@ -99,19 +99,11 @@ const CubeControlado = ({
gpDesktop = gamepads[0] || null; gpDesktop = gamepads[0] || null;
} }
if ((gpRight || gpDesktop) && !lockedRef.current && alignPhase === 'IDLE') {
let lx = 0, ly = 0, rx = 0, ry = 0;
let lt = 0, rt = 0;
let resetBtn = false; let resetBtn = false;
let lx = 0, ly = 0, rx = 0, ry = 0;
if (gpRight || gpDesktop) {
if (isWebXR) { 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 = resetBtn =
gpRight?.buttons[4]?.pressed || gpRight?.buttons[4]?.pressed ||
gpRight?.buttons[5]?.pressed || gpRight?.buttons[5]?.pressed ||
@@ -119,14 +111,32 @@ const CubeControlado = ({
gpLeft?.buttons[5]?.pressed || gpLeft?.buttons[5]?.pressed ||
false; false;
} else { } else {
// Desktop nativo resetBtn = gpDesktop!.buttons[0]?.pressed || false;
}
// Reset total (funciona a qualquer momento, cancela até os passos do alinhamento)
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;
if (alignPhase !== 'IDLE') {
setAlignPhase('IDLE');
}
}
gamepadRef.current.a = resetBtn;
}
if ((gpRight || gpDesktop) && !lockedRef.current && alignPhase === 'IDLE') {
if (isWebXR) {
lx = gpLeft?.axes[2] ?? 0;
ly = gpLeft?.axes[3] ?? 0;
rx = gpRight?.axes[2] ?? 0;
ry = gpRight?.axes[3] ?? 0;
} else {
lx = gpDesktop!.axes[0] ?? 0; lx = gpDesktop!.axes[0] ?? 0;
ly = gpDesktop!.axes[1] ?? 0; ly = gpDesktop!.axes[1] ?? 0;
rx = gpDesktop!.axes[2] ?? 0; rx = gpDesktop!.axes[2] ?? 0;
ry = gpDesktop!.axes[3] ?? 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 ax = Math.abs(lx) > STICK_DEADZONE ? lx : 0;
@@ -136,24 +146,11 @@ const CubeControlado = ({
posRef.current.x -= ax * MOVE_SPEED * delta; posRef.current.x -= ax * MOVE_SPEED * delta;
posRef.current.z -= ay * MOVE_SPEED * delta; posRef.current.z -= ay * MOVE_SPEED * delta;
posRef.current.y = Math.max(0.5, posRef.current.y); posRef.current.y = Math.max(0.15, posRef.current.y);
rotRef.current.x = (rotRef.current.x + ary * ROT_SPEED * delta) % (Math.PI * 2); rotRef.current.x = (rotRef.current.x + ary * ROT_SPEED * delta) % (Math.PI * 2);
rotRef.current.y = (rotRef.current.y - arx * ROT_SPEED * delta) % (Math.PI * 2); rotRef.current.y = (rotRef.current.y - arx * ROT_SPEED * delta) % (Math.PI * 2);
const scaleDelta = rt - lt;
if (Math.abs(scaleDelta) > TRIGGER_DEADZONE) {
scaleRef.current = Math.max(0.2, Math.min(3, scaleRef.current + scaleDelta * SCALE_SPEED * delta));
}
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 = resetBtn;
} else if ((gpRight || gpDesktop) && lockedRef.current) { } else if ((gpRight || gpDesktop) && lockedRef.current) {
let rx = 0, ry = 0;
if (isWebXR) { if (isWebXR) {
rx = gpRight?.axes[2] ?? 0; rx = gpRight?.axes[2] ?? 0;
ry = gpRight?.axes[3] ?? 0; ry = gpRight?.axes[3] ?? 0;
@@ -174,7 +171,7 @@ const CubeControlado = ({
return ( return (
<XRGrabbable <XRGrabbable
allowScale={true} allowScale={false}
lockedActive={lockedRef.current} lockedActive={lockedRef.current}
onSync={(deltaPos, deltaQuat, deltaScale) => { onSync={(deltaPos, deltaQuat, deltaScale) => {
// Matriz atual do cubo // Matriz atual do cubo