I’m currently working on a project using the Treble SDK for React and I’m trying to find a way to access and manipulate the camera in the Threekit player.
Specifically, I want to store the last camera position and then programmatically set a different user’s camera angle to match the stored one. This would allow us to create a consistent viewing experience across different users.
I’ve looked through the Treble SDK documentation but couldn’t find detailed information on accessing or manipulating the camera directly. In the context of Three.js, I understand that the camera is usually accessible through the scene or renderer. However, I’m not sure how this translates to the Threekit player in the Treble SDK.
Here’s a general approach I’m considering:
// Access the player or scene
const player = usePlayer();
const scene = useScene();
// Access the camera
const camera = player.camera; // or scene.camera
// Manipulate the camera
camera.position.set(x, y, z);
camera.rotation.set(rx, ry, rz);
camera.updateProjectionMatrix();
I’m not sure if the usePlayer or useScene hooks exist, or if the camera is accessible through the player or scene in this way. I’m also unsure about the methods for manipulating the camera.
Could you please provide some guidance on how to access and manipulate the camera in the Threekit player using the Treble SDK? Any examples or references to the relevant parts of the documentation would be greatly appreciated.
As I’m still a little new to the Treble SDK, would can you guide me on how to access the threekit object from within React? Is there a hook that returns it?
Ah, yes! The threekit object is tied to the window when the player is initialized and it’s not super obvious so apologies for not being more clear. Treble pretty much does this: