import { useState, useEffect } from 'react' import { EngineCommandManagerEvents } from 'lang/std/engineConnection' import { engineCommandManager, sceneInfra } from 'lib/singletons' import { throttle, isReducedMotion } from 'lib/utils' const updateDollyZoom = throttle( (newFov: number) => sceneInfra.camControls.dollyZoom(newFov), 1000 / 15 ) export const CamToggle = () => { const [isPerspective, setIsPerspective] = useState(true) const [fov, setFov] = useState(40) const [enableRotate, setEnableRotate] = useState(true) useEffect(() => { engineCommandManager.addEventListener( EngineCommandManagerEvents.SceneReady, async () => { sceneInfra.camControls.dollyZoom(fov) } ) }, []) const toggleCamera = () => { if (isPerspective) { isReducedMotion() ? sceneInfra.camControls.useOrthographicCamera() : sceneInfra.camControls.animateToOrthographic() } else { isReducedMotion() ? sceneInfra.camControls.usePerspectiveCamera() : sceneInfra.camControls.animateToPerspective() } setIsPerspective(!isPerspective) } const handleFovChange = (newFov: number) => { setFov(newFov) updateDollyZoom(newFov) } return (
{isPerspective && (
handleFovChange(Number(e.target.value))} className="w-full cursor-pointer pointer-events-auto" />
)}
) }