AABB size

Return to Code Snippets

AABB size

Postby zuck » Mon Dec 22, 2008 9:18 pm

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:
Code: Select all
node_path = loader.loadModel('/load/something.egg')

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


OdeGeom:
Code: Select all
geom = OdeBoxGeom(OdeSimpleSpace(), 1, 1, 1)

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


;)
Emanuele Bertoldi
zuck
 
Posts: 115
Joined: Wed Dec 10, 2008 12:37 pm
Location: Udine, ITA

Re: AABB size

Postby rdb » Tue Dec 23, 2008 3:47 am

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

NodePath:
Code: Select all
node_path = loader.loadModel('/load/something.egg')

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


OdeGeom:
Code: Select all
geom = OdeBoxGeom(OdeSimpleSpace(), 1, 1, 1)

min, max = geom.getAABounds()
size = Point3(max - min)
I prefer e-mail over PM
rdb
 
Posts: 8545
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby zuck » Tue Dec 23, 2008 6:52 am

Yep, thanks for this! ;)

Only a question: is "getAABounds()" an OdeGeom method? I can't find it in the reference API.
Emanuele Bertoldi
zuck
 
Posts: 115
Joined: Wed Dec 10, 2008 12:37 pm
Location: Udine, ITA

Postby rdb » Tue Dec 23, 2008 7:38 am

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.
I prefer e-mail over PM
rdb
 
Posts: 8545
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby zuck » Tue Dec 23, 2008 7:42 am

Ok, thank you!
Emanuele Bertoldi
zuck
 
Posts: 115
Joined: Wed Dec 10, 2008 12:37 pm
Location: Udine, ITA

Postby ZeroByte » Mon Mar 09, 2009 8:54 am

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:
Code: Select all
min, max = node.getTightBounds()
boundCenter = (min+max) * 0.5


This seems to also give the same result:
Code: Select all
node.getBounds().getApproxCenter()
User avatar
ZeroByte
 
Posts: 308
Joined: Wed Feb 28, 2007 7:10 am


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 0 guests