useDefaultCamera
This hook will return the default camera used by the scene. Normally, you would not need to use this hook. If you change the default camera, you would need to set the new default camera using the setDefaultCamera
function. And get the new default camera using the camera returned by this hook.
Note that if you change the default camera with
makeDefault
for example, you will need to set the default camera withsetDefaultCamera
. Otherwise, the image or the video exported won't be with the new default camera.
Example of use.
import { PerspectiveCamera } from '@react-three/drei'
import { useThree } from '@react-three/fiber'
import { useControl, useDefaultCamera } from './effect-control'
export default function App() {
const { setDefaultCamera } = useDefaultCamera()
return (
<>
<PerspectiveCamera
ref={setDefaultCamera}
makeDefault
/>
<Component />
</>
)
}
function Component() {
const { camera } = useDefaultCamera()
const { scene } = useThree()
const { myNumber } = useControl({
myNumber: {
label: 'A number',
value: 2,
},
})
useEffect(() => {
gl.render(scene, camera)
}, [myNumber])
return (
<>
...
</>
)
}