-
How do I get the bounding box of a scene graph object (including its children)? For example if I want to zoom out to show the entire scene or zoom in on a specific object in the scene. If I need to walk the graph and calculate it myself, how do I get the bounds of a mesh? It seems like an obvious thing to expect from a scene graph, but I haven't been able to find anything related to it here or in the docs. Thanks for any pointers! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
How precise do you want the bounding volume to be? Does it have to be a box, or is a bounding sphere okay as well? Is the scene static or can the transformation change? A Then, assuming a dynamic scene, where objects can translate and rotate freely but use only uniform scaling, I think the best way to do this is to remember a bounding sphere for each such mesh. Then, when a bounding box is desired, you transform those based on the absolute transformation of objects to which each mesh is attached, then turn the transformed sphere centers + radii into AABBs, and combine them together with for example Math::join(). I'm suggesting a bounding sphere because, when rotated, I assume it'd produce a tighter bounding volume than a rotated AABB. If the scene is static, then you could avoid problems with rotated bounding boxes and calculate AABBs right from mesh vertex positions in their final transformation. For example you can call MeshTools::transform3D() on each such mesh with the absolute transformation it'll be in, and calculate bounding boxes from the transformed mesh data. If the scene is static and imported from a Finally, if you use glTF as a format for models or scenes, the files likely contain bounding ranges for vertex position data inside accessor Cheers, hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Thanks Vladimír! That's a lot more involved than I'd hoped, but very helpful. I do need the bounding box for some calculations, but I guess I can use a bounding sphere for the zooming stuff I mentioned. I have a static(ish) scene using some primitives and some custom geometry (visualization of internal data, not read from a model format), and it's updated programmatically (i.e. it needs to update itself when other data in the application is updated). I'll work on it! (Aside: In the docs for SceneTools::absoluteFieldTransformations3D():
Shouldn't that be 3D?) |
Beta Was this translation helpful? Give feedback.
How precise do you want the bounding volume to be? Does it have to be a box, or is a bounding sphere okay as well? Is the scene static or can the transformation change?
A
GL::Mesh
doesn't contain any information about what's in it anymore, if you want to calculate a bounding volume, you have to do it from the vertex data before they're turned into a GL mesh. There is MeshTools::boundingSphereBouncingBubble() that gives you a bounding sphere, or MeshTools::boundingRange() (which is basically just a call to Math::minmax() inside) for a axis-aligned bounding box, all of them accept a list of three-component positions. If your meshes are imported asTrade::MeshData
, you can passmesh.attribut…