Skip to content

Instantly share code, notes, and snippets.

@Densyakun
Created February 21, 2023 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Densyakun/12dee767692215617a2cf324d231c96e to your computer and use it in GitHub Desktop.
Save Densyakun/12dee767692215617a2cf324d231c96e to your computer and use it in GitHub Desktop.
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