Getting width / height / depth of an instantiated node

Hi, I’ve found the geometry namespaces in the Cocos Creator v3 docs, but there is no example on how to get AABB of an instantiated node.

What I want was getting the size in cocos metrics ( width/ height/ depth ) of the node so that I could placing them next to each other ( based on their width for example )

Is there such function/property that I missed somewhere ?

Thanks.

You can use this API: getBoundingBoxToWorld

1 Like

Wow, I missed such critical part, was looking at getComponent(UITransform) but didn’t go forward and type in getBoundingBox, there is also computeAABB which I really need, thanks so much
:smiley:

I’ve just checked the API, it was defined inside 2d rendering so I guess it would work if working with UI element. But since I’m creating some object in 3d so the getComponent(UITransfrom) is null, hence the getBoundingBox, and computeAABB is unavailable, I’m currently looking at the Mesh and MeshRenderer, but to no avail since no public function to get the boundingBox/AABB yet.

How about trying getBoneSpaceBounds?

1 Like

Hi, I found out the way to calculate it now although I need to check the output values to be sure it corrects :smiley:
Since the node only has MeshRenderer ( as we all have seen in Cocos Inspector ), we should get the MeshRenderer component from node and via the model property, get the worldBounds and it’s the AABB of the mesh.

Thanks :smiley:

1 Like

Can I see your code of getting the AABB? I cannot see any method to get worldBounds from MeshRenderer in version 3.8