Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

enter image description here

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:

enter image description here

(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.

share|improve this question
    
Heh, I see Age of Goblins is under heavy development ;) –  Liosan Nov 19 '12 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. –  Byte56 Nov 19 '12 at 20:52
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
2  
This is also a valuable technique if there is a need to handle "hit locations" using a sub-mesh tree. –  Sean Middleditch Nov 19 '12 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. –  Byte56 Nov 19 '12 at 6:33
    
Thanks, this works great. i.imgur.com/x4pj5.png –  Byte56 Nov 20 '12 at 0:39
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.