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

This commit is contained in:
2026-08-04 20:36:21 +00:00
parent a63478a3ba
commit 5ce3636933
+27 -2
View File
@@ -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<THREE.Vector3>;
}) => {
const meshRef = useRef<THREE.Mesh>(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;
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() : [];
const gp = gamepads[0];
gp = gamepads[0] || null;
}
if (gp && !lockedRef.current && alignPhase === 'IDLE') {
const lx = gp.axes[0] ?? 0;