🚀 Auto-deploy: melhoria no snap e medição AR em 29/05/2026 20:54:50

This commit is contained in:
2026-05-29 20:54:50 +00:00
parent c820808184
commit 540eb2f31f
+26 -2
View File
@@ -1,4 +1,4 @@
import { useRef, useState } from 'react'; import { useRef, useState, useEffect } from 'react';
import { useFrame, useThree } from '@react-three/fiber'; import { useFrame, useThree } from '@react-three/fiber';
import * as THREE from 'three'; import * as THREE from 'three';
import { useModelStore } from '@/stores/useModelStore'; import { useModelStore } from '@/stores/useModelStore';
@@ -11,7 +11,7 @@ import {
detectCircularEdgeAtPoint3D, detectCircularEdgeAtPoint3D,
findNearestEdgeSegment3D findNearestEdgeSegment3D
} from './SmartMeasure'; } from './SmartMeasure';
import { xrCalibration, pushXRRealPoint } from './xrCalibrationBus'; import { xrCalibration, pushXRRealPoint, subscribeXRCalibration } from './xrCalibrationBus';
import { toast } from 'sonner'; import { toast } from 'sonner';
const TRIG_ON = 0.7; const TRIG_ON = 0.7;
@@ -58,6 +58,13 @@ export function XRControllerMeasure() {
const lTrigState = useRef(false); const lTrigState = useRef(false);
const [snapEnabled, setSnapEnabled] = useState(true); const [snapEnabled, setSnapEnabled] = useState(true);
// Escuta o barramento de calibração do XR para sincronização e re-renderizações
const [, forceCalib] = useState(0);
useEffect(() => subscribeXRCalibration(() => forceCalib((t) => t + 1)), []);
const lastStepRef = useRef<string>('idle');
const ignoreTriggerUntilReleaseRef = useRef<boolean>(false);
const raycaster = useRef(new THREE.Raycaster()); const raycaster = useRef(new THREE.Raycaster());
const tmpOrigin = useRef(new THREE.Vector3()); const tmpOrigin = useRef(new THREE.Vector3());
const tmpDir = useRef(new THREE.Vector3()); const tmpDir = useRef(new THREE.Vector3());
@@ -98,6 +105,13 @@ export function XRControllerMeasure() {
xrCalibration.step === 'await-real-3' || xrCalibration.step === 'await-real-3' ||
xrCalibration.step === 'await-virtual-3'); xrCalibration.step === 'await-virtual-3');
if (xrCalibration.step !== lastStepRef.current) {
lastStepRef.current = xrCalibration.step;
if (xrCalibration.step !== 'idle' && xrCalibration.step !== 'done') {
ignoreTriggerUntilReleaseRef.current = true;
}
}
if (laserRef.current) laserRef.current.visible = false; if (laserRef.current) laserRef.current.visible = false;
if (tipRef.current) tipRef.current.visible = false; if (tipRef.current) tipRef.current.visible = false;
if ((!measureMode && !selectionMode && !isAligning) || !frame) { if ((!measureMode && !selectionMode && !isAligning) || !frame) {
@@ -344,8 +358,18 @@ export function XRControllerMeasure() {
// ── Right trigger: add point (measure) OR toggle selection ──────── // ── Right trigger: add point (measure) OR toggle selection ────────
const trigVal = gp?.buttons?.[0]?.value ?? (gp?.buttons?.[0]?.pressed ? 1 : 0); const trigVal = gp?.buttons?.[0]?.value ?? (gp?.buttons?.[0]?.pressed ? 1 : 0);
if (trigVal < TRIG_OFF) {
ignoreTriggerUntilReleaseRef.current = false;
}
if (!trigState.current && trigVal > TRIG_ON) { if (!trigState.current && trigVal > TRIG_ON) {
trigState.current = true; trigState.current = true;
if (ignoreTriggerUntilReleaseRef.current) {
return;
}
const st = useModelStore.getState(); const st = useModelStore.getState();
if (isRealStep) { if (isRealStep) {