AABB size

Hi guys,

I’m here with a very trivial code snipplet: with these few lines you can calculate X, Y, Z size components of a NodePath or ODE geometry AABB (Axis Aligned Bounding Box):

NodePath:

node_path = loader.loadModel('/load/something.egg')

min = Point3()
max = Point3()
node_path.calcTightBounds(min, max)
size = Point3(max - min)

OdeGeom:

geom = OdeBoxGeom(OdeSimpleSpace(), 1, 1, 1)

min = Point3()
max = Point3()
geom.getAABB(min, max)
size = Point3(max - min)

:wink:

Ha, because its Panda3D, it can be done much easier. Try this:

NodePath:

node_path = loader.loadModel('/load/something.egg')

min, max = node_path.getTightBounds()
size = Point3(max - min)

OdeGeom:

geom = OdeBoxGeom(OdeSimpleSpace(), 1, 1, 1)

min, max = geom.getAABounds()
size = Point3(max - min)

Yep, thanks for this! :wink:

Only a question: is “getAABounds()” an OdeGeom method? I can’t find it in the reference API.

It is, but its a python extension to the C++ class (which you can find in pandac/libpandaodeModules.py) and those are not described in the API. Same as with getTightBounds, which is in libpandaModules.py.

Ok, thank you!

Is there a way to get the center of the bounding box in relation to the origin of a model?

EDIT:
Thanks to pro-rsoft for the following code:

min, max = node.getTightBounds()
boundCenter = (min+max) * 0.5

This seems to also give the same result:

node.getBounds().getApproxCenter()