# Calculate an AABB for bone animated model

I have a model that has its initial bounding box calculated by finding the maximum and minimum on the x, y and z axes. Producing a correct result like so:

The vertices are then stored in a VBO and only altered with matrices for rotation and bone animation. Currently the bounds are not updated when the model is altered. So the animated and rotated model has bounds like so:

(Maybe it's hard to tell, but the bounds are the same as before, and don't accurately represent the rotated/animated model)

So my question is, how can I calculate the bounding box using the armature matrices and rotation/translation matrices for each model? Keep in mind the modified vertex data is not available because those calculations are performed on the GPU in the shader.

The end result I want is to have an accurate AABB the represents the animated model for picking/basic collision checks.

• Heh, I see Age of Goblins is under heavy development ;) Nov 19, 2012 at 7:16
• @Liosan Heavy is a strong word. I wish I had enough time to make it heavy development :) It's coming along though.
– House
Nov 19, 2012 at 20:52

You could precalculate a bounding box in bone local space for each bone, using just the vertices that have a non-zero weight for that bone. At runtime, transform each of these boxes to world space using the bone matrices for the current pose, then calculate an AABB that encloses all of the bone boxes.

The AABB calculated this way will likely be a bit larger than strictly necessary, because of the extra space taken by the bone boxes, but it should be better than what you have now. Also, after checking for collisions against the whole model AABB you could then check for collisions against the individual bone boxes to get a more precise result, if you wish.

• This is also a valuable technique if there is a need to handle "hit locations" using a sub-mesh tree. Nov 19, 2012 at 5:00
• Sounds promising, since I also wanted to draw bones for certain effects and debugging. This would be a step in the right direction for that too. I'll check back when I've made steps towards implementing this. Thanks.
– House
Nov 19, 2012 at 6:33

First, it depends on the purpose of the bounding volume.

Normally, bounding volume is used for culling (view frustum culling, occlusion culling, etc.).

As you do skinning on GPU, you have already rendered the model before generating the bounding volume for culling.

Therefore, you should compute the conservative bounding volume as tight as possible on CPU.

There are several methods for this.

1. Manually create a static bounding volume.
2. Compute the longest bone chain from root bone, and then use it to generate a bounding sphere. The advantage is that no matter what animation applies (no scaling/translating), you need not to update the bounding sphere. Disadvantage is that the sphere is static and often too big.
3. Compute AABB/OBB from all OBB/Capsule of bones in the current poses. It needed to be done after animation update. A little bit more complicated but creating tighter bounding volume than method 2.
4. Similar to method 2, but just treats bones as line segments. Finally expand the OBB by a constant radius (maximum distance between vertices and their associated bones).

These solutions trades accuracy with run-time performance. If the created bounding volume is conservative (not culled incorrectly), then you may choose any one that suits.