Object.getBoundBox()

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Object.getBoundBox()

Post by stiv »

In a bug report in the Tracker ( #1206 ), Olly noticed that Object.getBoundBox() was returning coordinates in objdata space untransformed by the object matrix.

The 8 sets of coordinates getBoundBox() returns is nice for drawing the bounding box, but Olly suggested a that a method returning the min and max for each axis would be more useful for collision detection. The return value could be formatted a couple of ways like

Code: Select all

[[xmin,xmax], [ymin, ymax], [zmin,zmax]]  
or
 [[xmin,ymin,zmin], [xmax,ymax,zmas]]
Or perhaps, diagonally opposite corners of the bounding box. I am not sure which is more useful, but then again, I have not been writing collision detection code.

Anyone have any thoughts?
( we can argue about the name too! I vote for getMinMaxBounds() )

ollyw
Posts: 0
Joined: Wed May 05, 2004 10:10 am

Re: Object.getBoundBox()

Post by ollyw »

I would prefer [[xmin,ymin,zmin], [xmax,ymax,zmas]] because it holds per vertex information together. But it would be even more useful to directly move the information to the new builtin Vector class. So [minVector,maxVector] seems the best solution to me.

> Or perhaps, diagonally opposite corners of the bounding box. I am not >sure which is more useful, but then again, I have not been writing collision >detection code.

These two vertices ARE the opposite corners of the bounding box! :o

>Anyone have any thoughts?
>( we can argue about the name too! I vote for getMinMaxBounds() )[/quote]

This issue came up because I was new to blender and I expected the existent function "Blender.Object.getBoundBox()" to return the MinMax bounds in world space, in fact the BoundingBox coordinates of the object as they are visible in the scene. I found out that the bounding box is drawn the right way, but when asking for its coordinates with Python, those values were pretty different.
I would encourage to move a getBoundBox() to the NMesh class (and any other classes which represent visible objects in a scene; subdivs, etc.) too which can return the untransformed mesh extends in local space - as you get them currently. When you ask its transformation object node for the bounding box you get the two corner vertices as described above with the coordinates as you see them in 3D view.
Currently I'm waiting everyday for the new Python API documentation to come out and the games API docs as well. Maybe then all weapons for effective intersection tasks are already included. I'm very excited about that!
Best regards
Oliver

breakin
Posts: 0
Joined: Fri Aug 22, 2003 3:33 am

Post by breakin »

In object-space min/max-point is the best thing (the two opposit corners of the box). The only sensible alternative is (centerPoint, halfSize) but I like #1 better personally...

But this is only applicable for an axis-aligned bounding-boxes (AABB) not for oriented bounding-boxes (OBB). In worldspace the AABB is rotated and thus not axis-aligned anymore so it become an OBB where you would need eight points to specify it (or a center, a size and euler-angles or something else, an center plus 3x3-matrix or whatever).

So anyway I suggest just having AABB in the NMesh and then let the user transform or whatever he/she wants when using an Object. It's trivial to construct the eight corners in object-space and then transform by the world matrix.

Sidenote: For some purposes it could be nice to have an OBB in object-space as well as it could be more closely fit than an AABB but it's very hard to calculate properly so perhaps it's better be left alone, AABB is just fine.

ollyw
Posts: 0
Joined: Wed May 05, 2004 10:10 am

Post by ollyw »

Yes, good point!
Oliver

Post Reply