# Easy way to get static AABB for animated model

This topic is 481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm using assimp to import models. As I read each vertex I stored the min/max values for its bindpose and so I can get the whole AABB for the model in bindpose. Easy enough.

Now I want to get the same pre-computed AABB but based on all its various poses played during all of its animations. This seems like quite a headache, the way I understand it I have to go through each animation, calculate all bone transforms for every tick and apply them to each vertex based on vertex-bone indices/weights. Basically re-implementing the whole animation pipeline but with CPU skinning :(

Is there an easier way to do this than the above?

##### Share on other sites

one lazy thing is to create a "worst case AABB" in the scene and use that. Otherwise I think that performing the skinning is the only solution that assimg offers(correct me if I'm wrong).

Usually the lazy solution is good enough.

##### Share on other sites

If you assume that bones can only rotate, not translate/scale:

Pick a bone to be the center. Walk outwards from there along all paths to leaf bones. Along the way, sum the distance between each bone, giving the total distance travelled from the center bone. Pick the maximum distance value produced by any of the leaves. A sphere of that size, centered on the center-bone will always enclose all bones.

Vertices form a shell around the bones though, so for each bone, iterate through every vertex that is skinned to this bone (has a weight>0 for this bone) and compute the distance between the bone and this vertex. Keep track of the maximum ditsance between any bone and associated vertex. Add this distance to the sphere generated earlier. Now you've got a sphere that's guaranteed always bound any in the model, no matter how it's bones are rotated.

At runtime, you can cull using these "conservative" spheres before doing animation. After animation, you can generate a slightly tighter bounding volume if required, by taking the min/max of the animated bones and adding the "shell size" that was computed above.

If you happen to use software skinning, then you can compute the min/max vertex position during skinning to get an even tighter bounding volume still -- but not many people use software skinning any more :)

Edited by Hodgman

##### Share on other sites
My plan for this, which I have not yet implemented, has been to sample the animation at various times during export (every 100 or 200 milliseconds, for example) and generate an AABB for that keyframe and interpolate between them at run-time.
This will generate a more conservative AABB than other methods, but will not necessarily work on objects with non-forward kinematic animations (inverse kinematics or any other kind of run-time dynamic animation or pose).
For those, Hodgman’s suggestion is likely best.

L. Spiro

##### Share on other sites

This will generate a more conservative AABB than other methods, but will not necessarily work on objects with non-forward kinematic animations (inverse kinematics or any other kind of run-time dynamic animation or pose)

Sampled bounding volumes also stop being valid if you blend animations together. After blending two animations, the bounds of the produced pose have no relation whatsoever to the source pose bounds.

##### Share on other sites

Here is another idea: if you have a simple collision mesh for your model, you can use it to compute the AABB in real time on per-frame basis. No need to store a big database of pre-computed AABBs for each model for each key frame. Plus, the computed skinning transformation of the collision mesh can be reused later, for erm... determining collisions.  :)

Edited by vanka78bg

##### Share on other sites
if you have a simple collision mesh for your model,

yeah but often that collision mesh is thinner compared to the actual model.

##### Share on other sites

This topic is 481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.