Skip to content

setDefaultCamera removed in v6.x. #1148

Answered by taseenb
nyan-left asked this question in Q&A
Discussion options

You must be logged in to vote

Use const { set } = useThree()

function CustomCamera (props) {
    const cameraRef = useRef()
    const set = useThree(({ set }) => set)
    const size = useThree(({ size }) => size)
    
    useLayoutEffect(() => {
        if (cameraRef.current) {
          cameraRef.current.aspect = size.width / size.height
          cameraRef.current.updateProjectionMatrix()
        }
      }, [size, props])
    
      useLayoutEffect(() => {
        set({ camera: cameraRef.current })
      }, [])
    
    return <perspectiveCamera ref={cameraRef} />
}

https://github.com/pmndrs/react-three-fiber/blob/master/markdown/api.md#usethree

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@drcmda
Comment options

Answer selected by drcmda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1147 on March 30, 2021 16:45.