Hello,
Would anyone know how to use a javascript to replicate the context menu items:
"Fit Visible" and "Zoom to Part"?
I'm just trying to create a button to allow the user to easily fill the screen with the current or selected objects without having to go to the model tree and opening the context menu.
Any help would be greatly appreciated.
Cheers
George
The logic for "zoom to part" is relatively straightforward - the bounding box of the mesh node is collected, and the camera's target set to the center of the box. Then, using the field of view of the camera and basic trigonometry, it's moved closer until one corner of the bounding box falls outside the angle (hence the screen). The same function will work for "fit visible", just using the scene's bounding box.
It's more complex than that in practice, as you need to make sure you're not stopping the camera inside another part of the mesh.