Change camera dynamically #709
Replies: 4 comments 11 replies
-
https://codesandbox.io/s/switching-between-cameras-2jod7 export default function App() {
const [ortho, set] = useState(false)
useEffect(() => {
const interval = setInterval(() => set((state) => !state), 1000)
return () => clearInterval(interval)
}, [])
return (
<Canvas>
<PerspectiveCamera position={[0, 0, 2.5]} fov={100} makeDefault={!ortho} />
<OrthographicCamera position={[0, 0, 5]} zoom={170} makeDefault={ortho} /> |
Beta Was this translation helpful? Give feedback.
-
@drcmda apologies that it took me so long to get around to this. Here's a sandbox that will switch from ortho -> perspective on keypress. EDIT: updated the sandbox and these problems are now fixed, thanks @drcmda. The issues with OrbitControls that I mentioned above seem to be ok now. However, when using postprocessing there are two problems.
Actually I seem to remember having this problem before when trying to switch effects on regress. I thought we had solved it though? 🤔 EDIT: Yup, I already raised an issue for the crash here: pmndrs/react-postprocessing#97 Created another issue here |
Beta Was this translation helpful? Give feedback.
-
I had trouble getting a seamless transition between a perspective and an orthographic camera myself. After some work I finally got it working. For future reference see https://gist.github.com/nickyvanurk/9ac33a6aff7dd7bd5cd5b8a20d4db0dc for a working implementation in r3f and vanilla three.js. |
Beta Was this translation helpful? Give feedback.
-
The code sandboxes are very helpful. My need was a little different - to modify the "Views" example: https://codesandbox.io/s/bp6tmc |
Beta Was this translation helpful? Give feedback.
-
Hi,
Can someone please point me to the best way I could swap an orthographic camera with a perspective one dynamically? I'm managing it myself with setDefaultCamera, but can't figure out how to swap between the two. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions