I use get_AABB in godot 4 which is bounding box of mesh, I actually use get_center which is center of mesh. my question is get_center which is vector3 is in world environment space or mesh environment? how can I convert from mesh environment to world environment.
Thanks in advance
The
get_aabbmethod formVisualInstance3Dreturns anAABBin its local space.To get it in global coordinates do this:
Be aware, of course, that an
AABBcan't represent rotation, so what this is doing is transforming the extreme points of the AABB, and giving you the smaller AABB that contains them. The center position will be correct, but there is no guarantee that it will preserve its size.Each class that extends
VisualInstance3Dprovides its own implementation. In the case of aMeshInstance3Dyou get the bounding box of itsmesh.Another caveat worth mentioning is that you get the
AABBof theVisualInstance3Ditself, disregarding children.Addendum
The above is code for Godot 4. As you are aware, in Godot 3 there was a
get_transformed_aabbmethod. However it was removed to avoid confusion on what it did, and because it is easy to reimplement, as it did the same thing as the code I posted above. See: https://github.com/godotengine/godot/pull/66940About getting the scale, you can find how the transform scales the object like this:
Here we are doing a component-wise multiplication (a.k.a direct product) of the two vectors (not to be confused with dot product or cross product).
Here
visual_instance.global_transform.basis.get_scale()gives you the scaling before rotation.You can, of course, use the size of AABB:
But is not the same thing. As the latter is size of the
AABBthat contains the extreme points of the originalAABBafter transforming them (including rotation and scaling).