()
| 15 | import { useCameraMatchesStoreFacade } from './useCameraMatchesStoreFacade'; |
| 16 | |
| 17 | export function CameraMatches() { |
| 18 | const { reconstruction } = useCameraMatchesStoreFacade(); |
| 19 | |
| 20 | const cameras = useCamerasNode(); |
| 21 | const selection = useSelectionNode(); |
| 22 | const matches = useMatchesNode(); |
| 23 | |
| 24 | const { selectedImageId } = selection; |
| 25 | const { displayMode: cameraDisplayMode } = cameras; |
| 26 | const { |
| 27 | visible: showMatches, |
| 28 | displayMode: matchesDisplayMode, |
| 29 | opacity: matchesOpacity, |
| 30 | color: matchesColor, |
| 31 | lineWidth: matchesLineWidth, |
| 32 | } = matches; |
| 33 | |
| 34 | const blinkPhaseRef = useRef(0); |
| 35 | |
| 36 | const linePositions = useMemo(() => buildCameraMatchLinePositions({ |
| 37 | reconstruction, |
| 38 | selectedImageId, |
| 39 | showMatches, |
| 40 | cameraDisplayMode, |
| 41 | }), [reconstruction, selectedImageId, showMatches, cameraDisplayMode]); |
| 42 | |
| 43 | const fatLines = useMemo(() => { |
| 44 | if (!linePositions) return null; |
| 45 | return createFatLineSegmentsObject({ |
| 46 | positions: linePositions, |
| 47 | lineWidth: 1, |
| 48 | depthTest: false, |
| 49 | depthWrite: false, |
| 50 | renderOrder: 999, |
| 51 | }); |
| 52 | }, [linePositions]); |
| 53 | |
| 54 | useEffect(() => { |
| 55 | if (!fatLines) return undefined; |
| 56 | return () => disposeFatLineSegmentsObject(fatLines); |
| 57 | }, [fatLines]); |
| 58 | |
| 59 | useLayoutEffect(() => { |
| 60 | if (!fatLines) return; |
| 61 | syncMaterialColor(fatLines.material, matchesColor); |
| 62 | syncMaterialLineWidth(fatLines.material, matchesLineWidth); |
| 63 | syncMaterialOpacity(fatLines.material, getMatchesDisplayOpacity( |
| 64 | matchesOpacity, |
| 65 | matchesDisplayMode, |
| 66 | blinkPhaseRef.current |
| 67 | )); |
| 68 | }, [fatLines, matchesColor, matchesLineWidth, matchesOpacity, matchesDisplayMode]); |
| 69 | |
| 70 | useFrame((_, delta) => { |
| 71 | if (!showMatches || !fatLines) return; |
| 72 | |
| 73 | if (matchesDisplayMode === 'blink') { |
| 74 | blinkPhaseRef.current = (blinkPhaseRef.current + delta) % 2; |
nothing calls this directly
no test coverage detected