import { ContactShadows, Environment } from '@react-three/drei'; import { useThree } from '@react-three/fiber'; import { useEffect } from 'react'; import { ACESFilmicToneMapping, Color, PCFSoftShadowMap, SRGBColorSpace } from 'three'; import { useViewerStore } from '../../store/viewerStore'; import { LOCAL_ENVIRONMENT_HDR } from './localEnvironment'; export interface ViewerEnvironmentProps { hdrUrl?: string; } export function ViewerEnvironment({ hdrUrl = import.meta.env.VITE_MECHANICA_HDR_URL ?? LOCAL_ENVIRONMENT_HDR, }: ViewerEnvironmentProps) { const display = useViewerStore((state) => state.display); const gl = useThree((state) => state.gl); const scene = useThree((state) => state.scene); useEffect(() => { gl.toneMapping = ACESFilmicToneMapping; gl.toneMappingExposure = display.exposure; gl.outputColorSpace = SRGBColorSpace; gl.shadowMap.enabled = display.shadows; gl.shadowMap.type = PCFSoftShadowMap; gl.localClippingEnabled = true; scene.background = new Color('#0B0E14'); scene.fog = null; }, [display.exposure, display.shadows, gl, scene]); return ( <> {display.environment ? ( hdrUrl ? ( ) : ( ) ) : null} {display.grid ? ( ) : null} {display.shadows ? ( ) : null} ); }