🚀 Auto-deploy: melhoria no snap e medição AR em 29/05/2026 20:54:50
This commit is contained in:
@@ -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<string>('idle');
|
||||
const ignoreTriggerUntilReleaseRef = useRef<boolean>(false);
|
||||
|
||||
const raycaster = useRef(new THREE.Raycaster());
|
||||
const tmpOrigin = 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-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;
|
||||
if ((!measureMode && !selectionMode && !isAligning) || !frame) {
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user