From c55dca00338cb8b8dbbb3b8f7ebbf7fdd995c85b Mon Sep 17 00:00:00 2001 From: ochafik Date: Thu, 26 Dec 2024 19:12:24 +0000 Subject: [PATCH] axes: use axes viewer for snapping logic (model viewer wiggles b/c of the prompt) --- src/components/ViewerPanel.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/ViewerPanel.tsx b/src/components/ViewerPanel.tsx index a8c083b..2832e3d 100644 --- a/src/components/ViewerPanel.tsx +++ b/src/components/ViewerPanel.tsx @@ -79,10 +79,11 @@ export default function ViewerPanel({className, style}: {className?: string, sty }, [ref.current, otherRef.current]); } + // Cycle through predefined views when user clicks on the axes viewer useEffect(() => { let mouseDownSpherePoint: [number, number, number] | undefined; function getSpherePoint() { - const orbit = modelViewerRef.current.getCameraOrbit(); + const orbit = axesViewerRef.current.getCameraOrbit(); return spherePoint(orbit.theta, orbit.phi); } function onMouseDown(e: MouseEvent) { @@ -100,13 +101,14 @@ export default function ViewerPanel({className, style}: {className?: string, sty if (clickDist > euclEps) { return; } - // Cycle through orbits - const orbit = modelViewerRef.current.getCameraOrbit(); - const [currentIndex, dist, radDist] = getClosestPredefinedOrbitIndex(orbit.theta, orbit.phi); + // Note: unlike the axes viewer, the model viewer has a prompt that makes the model wiggle around, we only fetch it to get the radius. + const axesOrbit = axesViewerRef.current.getCameraOrbit(); + const modelOrbit = modelViewerRef.current.getCameraOrbit(); + const [currentIndex, dist, radDist] = getClosestPredefinedOrbitIndex(axesOrbit.theta, axesOrbit.phi); const newIndex = dist < euclEps && radDist < radEps ? (currentIndex + 1) % PREDEFINED_ORBITS.length : currentIndex; const [name, theta, phi] = PREDEFINED_ORBITS[newIndex]; - Object.assign(orbit, {theta, phi}); - const newOrbit = modelViewerRef.current.cameraOrbit = axesViewerRef.current.cameraOrbit = orbit.toString(); + Object.assign(modelOrbit, {theta, phi}); + const newOrbit = modelViewerRef.current.cameraOrbit = axesViewerRef.current.cameraOrbit = modelOrbit.toString(); toastRef.current?.show({severity: 'info', detail: `${name} view`, life: 1000,}); setInteractionPrompt('none'); } @@ -119,7 +121,7 @@ export default function ViewerPanel({className, style}: {className?: string, sty window.removeEventListener('mousedown', onMouseDown); window.removeEventListener('mouseup', onMouseUp); }; - }, [axesViewerRef.current]); + }); return (