Created
February 21, 2023 10:11
-
-
Save Densyakun/12dee767692215617a2cf324d231c96e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import * as THREE from 'three' | |
import { OrthographicCamera, useHelper } from '@react-three/drei' | |
import { proxy, ref } from 'valtio' | |
export const state = proxy<{ | |
directionalLight: { value?: THREE.DirectionalLight }; | |
}>({ | |
directionalLight: ref<{ value?: THREE.DirectionalLight }>({}), | |
}) | |
export default function Sun() { | |
const shadowCamera = React.useRef<THREE.OrthographicCamera>(null!) | |
useHelper(shadowCamera, THREE.CameraHelper) | |
if (shadowCamera.current && state.directionalLight.value) | |
state.directionalLight.value.shadow.camera = shadowCamera.current | |
const directionalLightRef = React.useCallback((directionalLight: THREE.DirectionalLight) => { | |
state.directionalLight.value = directionalLight | |
}, []) | |
return ( | |
<> | |
<directionalLight | |
ref={directionalLightRef} | |
castShadow | |
/> | |
<OrthographicCamera ref={shadowCamera} /> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment