I have an app that has a navigation menu with two links : 3D scene and a form.
When the user clicks on the 3D scene, it shows a threejs scene and loads a glb file into it (in this example I’m showing Suzanne). When the user clicks on form, it goes to another page/link.
My question is : When the user wants to return to the scene, How can I keep the same view (camera position and orientation) as when the user has left it.
I’m using react as my front end stack. What I tried is storing the camera position into the global state, but it causes many renders as soon as I make any action on my scene (raycasting, orbitcontrols, etc.).
if you are using react make sure to use react-three-fiber if you don’t already do. but now there is no disparity between your dom and the canvas, it’s all just a react tree. your routes are within your scene while your canvas persists. it’s often not a good idea to mount/unmount the canvas between pages due to performance and memory overhead. as for transferring camera coordinates, this becomes a non issue because the camera and the controls also persist.
i think something like this, the problem is that orbitcontrols will overwrite any change to the camera, as the name suggests it controls the camera. but calling update i believe will work.