I'm new to Three.js and I would like to create a fly-around camera to my scene.
I've see that THREE.Geometry has .computeBoundingSphere()
method and .boundingSphere
propetry that gives me the center and the radious of that object bounding sphere.
Supposing I only have one mesh in my scene, I can get it with scene.children[0].computeBoundingSphere
The idea is to use .boundingSphere.center
to set myCamera.lookAt
and use .boundingSphere.center
and .boundingSphere.radius
with Math.sin/cos of my viewing angle to set myCamera position.
Question No.1: is this the best way to proceed or does Three.js provides any special classes or helpers for that scope?
Question No.2: what if my scene contains more than a mesh and I want a global scene boundingSphere? Do I have manually iterate through all scene.children
(skip camera, lights etc) and mathematically create a "boundingSphere" of single meshes' boundingSphere or is there a smarter way to do that? Is that possible to add a "root" dummy object which contains all my scene meshes and get its boundingSphere as a result of all it's children boundingSpheres?