From 540eb2f31f019f3995fe5d17446b9881bdf3e624 Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Fri, 29 May 2026 20:54:50 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Auto-deploy:=20melhoria=20no=20s?= =?UTF-8?q?nap=20e=20medi=C3=A7=C3=A3o=20AR=20em=2029/05/2026=2020:54:50?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/three/XRControllerMeasure.tsx | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/components/three/XRControllerMeasure.tsx b/src/components/three/XRControllerMeasure.tsx index 60e0596..56969fd 100644 --- a/src/components/three/XRControllerMeasure.tsx +++ b/src/components/three/XRControllerMeasure.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from 'react'; +import { useRef, useState, useEffect } from 'react'; import { useFrame, useThree } from '@react-three/fiber'; import * as THREE from 'three'; import { useModelStore } from '@/stores/useModelStore'; @@ -11,7 +11,7 @@ import { detectCircularEdgeAtPoint3D, findNearestEdgeSegment3D } from './SmartMeasure'; -import { xrCalibration, pushXRRealPoint } from './xrCalibrationBus'; +import { xrCalibration, pushXRRealPoint, subscribeXRCalibration } from './xrCalibrationBus'; import { toast } from 'sonner'; const TRIG_ON = 0.7; @@ -58,6 +58,13 @@ export function XRControllerMeasure() { const lTrigState = useRef(false); 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('idle'); + const ignoreTriggerUntilReleaseRef = useRef(false); + const raycaster = useRef(new THREE.Raycaster()); const tmpOrigin = useRef(new THREE.Vector3()); const tmpDir = useRef(new THREE.Vector3()); @@ -97,6 +104,13 @@ export function XRControllerMeasure() { xrCalibration.step === 'await-virtual-2' || xrCalibration.step === 'await-real-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 (tipRef.current) tipRef.current.visible = false; @@ -344,8 +358,18 @@ export function XRControllerMeasure() { // ── Right trigger: add point (measure) OR toggle selection ──────── 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) { trigState.current = true; + + if (ignoreTriggerUntilReleaseRef.current) { + return; + } + const st = useModelStore.getState(); if (isRealStep) {