How to sync the orbit control for multiple canvases simententiously? (Using React fiber & Drei) #2928
Replies: 1 comment 1 reply
-
IF, by any chance, your multiple canvases are stacked on top of each other and also full screen, you can do what I did: <>
<Canvas>
<SceneA />
<OrbitControls domElement={document.body} />
</Canvas>
<Canvas>
<SceneB />
<OrbitControls domElement={document.body} />
</Canvas>
<Canvas>
<SceneC/>
<OrbitControls domElement={document.body} />
</Canvas>
</> This just attaches the mouse/zoom/etc listeners to a common global element. I was able to determine that I'd be able to do this by looking at the Three JS and drei OrbitControls source: https://github.com/mrdoob/three.js/blob/7cfa3efe0a801c5b36fcc8478e1dc5f0ab0255ea/examples/jsm/controls/OrbitControls.js This technically means that 3 sets of event listeners for the same thing are created, but I'm not sure there is a better way to do it. I remember clearly an issue on Three JS where the creator says there is not a way to programmatically control the orbit angle and zoom, and that a way will not be added. |
Beta Was this translation helpful? Give feedback.
-
0
I have 4 differet canvases with Cube geometry. I have written common scene for this and using them in diff canvas. I want to share the orbitcontrol for all simententiously. As of now orbitcontrols are working individually for each canvas.
Here is my Scene.jsx -
and in Parent component, I'm consuming like this -
//same way 4 times
I tried this wraaper -
but orbit controls individual canvas. I'm expecting to sync all canvas.
Beta Was this translation helpful? Give feedback.
All reactions