Improvement suggestions for bounding boxes/AABB/OOBB #10282
yosimba2000
started this conversation in
3D
Replies: 2 comments 3 replies
-
I agree with all of your points, but just so you know, issue 1 and 2 can be solved by multiplying AABB with the global transform of your node, like so:
(note that the order matters, transform should be on the left) |
Beta Was this translation helpful? Give feedback.
3 replies
-
I am running into issue 3 right now. Having a simple function call to get the AABB of all the children of a Node3D would be quite useful. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is inspired from a bug thread I recently made (but it's not a bug, just a misunderstanding):
godotengine/godot#94758
Currently, AABBs are only calculated from Mesh Resource, and not the MeshInstance3D.
Issue 1:
Mesh Resources are typically assigned into a 3D node, like MeshInstance3D.
This MeshInstance3D can have various transformations.
However, retrieving the MeshInstance3D's AABB does NOT return the MeshInstance3D's AABB.
It actually returns the Mesh Resource's AABB that is used in the MeshInstance3D.
Imagine a MeshInstance3D with scale=(2,2,2), and is assigned a Box Mesh Resource with dimensions 1x1x1.
If you return the AABB of the MeshInstance3D, you get dimensions (1,1,1) instead of (2,2,2), because the AABB returned is actually the Mesh Resource's and not MeshInstance3D's.
This is confusing because this code seems to imply I will retrieve the MeshInstance3D's AABB, not the Mesh Resource's AABB.
MeshInstance3D.GetAABB()
//using this via 4.2/4.3 RC1 only gets AABB for the Mesh Resource.I propose something like this:
MeshInstance3D.GetAABB()
//this will retrieve the AABB of the MeshInstance3D itself after its transforms have been applied.MeshInstance3D.GetMeshResource.GetAABB()
//this will retrieve the AABB of the MeshResource, and is not affected by MeshInstance3D's transforms.Now, you CAN calculate the MeshInstance3D's AABB if you have the Mesh Resource's AABB and the MeshInstance3D's transforms. But this requires linear algebra, and I'll admit I'm not good at it. I think there should be an easy way to get separate AABBs for both the MeshInstance3D, and for the Mesh Resource inside.
Issue 2:
Currently the AABBs are in mesh-local space. There is no "easy" way to retrieve the AABB in Global Coordinates.
I propose something like this:
Rename the current usage of AABB to OOBB, or Object Oriented Bounding Box. This is because the current AABB is actually defined in mesh/object space.
Create a new AABB method that retrieves the bounding box in Global/World Coordinates. I think this matches much better with existing terminology. For example, if you Google AABB vs OOBB, you'll see that Godot's AABB is actually OOBB.
Please see here:
https://en.wikipedia.org/wiki/Bounding_volume#Common_types
https://www.youtube.com/watch?v=HYO5Pthe3TE
Issue 3:
There is no convenient way of retrieving a parent's cumulative AABB from its children.
Imagine this example: A Node3D parent, and it has 10 MeshInstance3D children.
The current way to get the AABB for the Node3D parent would be to loop through all of its MeshInstance3D children and get their AABBs, then
AABB.Merge()
them all together. This will return the AABB that encloses all of the Node3D's children.However, this is very inconvenient because you have to manually track all MeshInstance3D children/grandchildren/etc, then merge them one at a time.
I propose something like this:
All Node3D and its derivatives should have a method to easily retrieve the cumulative AABB/OOBB that encloses all of its children's AABB/OOBB.
In fact, this already partially exists in the form of OOBB.
*If you use a different parent type, like a MeshInstance3D parent, you don't observe the orange box that surrounds all of its children. You only observe the orange box around that MeshInstance3D's Mesh Resource. Perhaps this can be changed?
*Maybe these ideas can be extended to 2D mode as well?
Beta Was this translation helpful? Give feedback.
All reactions