As a newcomer to Three.js, I am looking to implement a fly-around camera in my scene.
I have discovered that THREE.Geometry has a method called .computeBoundingSphere()
and a property called .boundingSphere
that provides me with the center and radius of the object's bounding sphere. If I have only one mesh in my scene, I can obtain it by using
scene.children[0].computeBoundingSphere
.
The plan is to utilize .boundingSphere.center
to set myCamera.lookAt
and to use .boundingSphere.center
and .boundingSphere.radius
with Math.sin/cos of my viewing angle to determine the position of my camera.
Question No.1: Is this the most efficient approach, or does Three.js offer any specific classes or utilities for this purpose?
Question No.2: What if my scene consists of multiple meshes and I need a global scene boundingSphere? Do I need to manually iterate through all scene.children
(excluding cameras, lights, etc.) and calculate a boundingSphere of individual meshes or is there a more efficient method? Is it possible to include a "root" dummy object that encompasses all scene meshes and retrieve its boundingSphere as a combination of all its children's boundingSpheres?