🚀 Auto-deploy: melhoria no snap e medição AR em 04/08/2026 20:36:21
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
|||||||
Environment,
|
Environment,
|
||||||
PerspectiveCamera,
|
PerspectiveCamera,
|
||||||
} from "@react-three/drei";
|
} 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 { xrStore as store } from "@/stores/useXRStore";
|
||||||
import * as THREE from "three";
|
import * as THREE from "three";
|
||||||
import {
|
import {
|
||||||
@@ -66,6 +66,7 @@ const CubeControlado = ({
|
|||||||
face2Ref: React.MutableRefObject<THREE.Vector3>;
|
face2Ref: React.MutableRefObject<THREE.Vector3>;
|
||||||
}) => {
|
}) => {
|
||||||
const meshRef = useRef<THREE.Mesh>(null);
|
const meshRef = useRef<THREE.Mesh>(null);
|
||||||
|
const session = useXR((state) => state.session);
|
||||||
|
|
||||||
const materials = [
|
const materials = [
|
||||||
new THREE.MeshStandardMaterial({ color: "#ef4444" }), // +x
|
new THREE.MeshStandardMaterial({ color: "#ef4444" }), // +x
|
||||||
@@ -79,8 +80,32 @@ const CubeControlado = ({
|
|||||||
useFrame((state, delta) => {
|
useFrame((state, delta) => {
|
||||||
if (!meshRef.current) return;
|
if (!meshRef.current) return;
|
||||||
|
|
||||||
const gamepads = navigator.getGamepads ? navigator.getGamepads() : [];
|
let gp: Gamepad | null = null;
|
||||||
const gp = gamepads[0];
|
|
||||||
|
// 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') {
|
if (gp && !lockedRef.current && alignPhase === 'IDLE') {
|
||||||
const lx = gp.axes[0] ?? 0;
|
const lx = gp.axes[0] ?? 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user