Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to compute the bounding volume for an animated (skinned) mesh ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#1 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 07 November 2013 - 07:48 AM

Hello

 

An example maybe :

Usually a human being is forming a T with his arms in model space.

Then I compute the bounding volume using this pose.

But if the arms within an animation are towards the up direction they'll get out of the bounding volume and they would be frustum-culled even if they are visible ...

 

How can I avoid this please ? (sorry for the poor explanation, but it's quite hard for me to explain that in English)

 

Thanks



Sponsor:

#2 AgentC   Members   -  Reputation: 1297

Like
3Likes
Like

Posted 07 November 2013 - 08:51 AM

You could store local-space bounding boxes or bounding spheres for the bones in your model asset format. To calculate them, find out which vertices the bone influences with sufficiently big weight ("sufficient" is an arbitrary value for you to choose), and those vertices form the bounding box/sphere. Remember to transform them into the bone's local space!

 

At runtime, transform the bone bounding boxes/spheres with the bones' world transforms after applying animation, and merge them together to get the model's final world-space bounding box. The individual bone bounds will also be useful in per-bone collision detection ("hitboxes").

 

This operation is fairly CPU-intensive, so all engines eg. Unity or OGRE don't do it. But if you're for example already splitting your animation update into multiple threads, the bounding box calculation can also be part of the threaded update.

 

Btw. if you were doing software skinning (I hope you aren't), you could also simply merge an updated bounding box from the vertices you're transforming, without having bone bounding boxes at hand. This is what Horde3D is doing, or at least was doing some years ago.


Edited by AgentC, 07 November 2013 - 08:58 AM.

Every time you add a boolean member variable, God kills a kitten. Every time you create a Manager class, God kills a kitten. Every time you create a Singleton...

Urho3D (engine)  Hessian (C64 game project)


#3 osmanb   Crossbones+   -  Reputation: 1561

Like
3Likes
Like

Posted 07 November 2013 - 10:28 AM

We have a couple different solutions to this. In the past, if the set of animations for a particular character was small (and known up front), we would compute the bounding box of the transformed mesh during a pre-process step, and store that information. These days, we just pick an arbitrary scale factor, relative to the original T-pose. For example, we assume that the actual bounds of the mesh will never be more than 3x the original bounds, and use that for culling. Doing something with the bones themselves would be better, obviously. You could probably find a minimal set of bones that always determine the extents of the full model (intermediate bones along appendages aren't going to push the mesh out further than the hand/foot bones, for example). You could also store the maximum distance to a weighted vertex from each bone, so you know how big the virtual spheres around each bone need to be.



#4 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 07 November 2013 - 12:46 PM

Thank you for your answers.

Finally I think I will explicitly define an extra geometry in the asset defining the bounding volume. (only for animated meshes)

The modeler will have to create it, bounding all poses the mesh can have.


Edited by Tournicoti, 07 November 2013 - 12:49 PM.


#5 Stragen   Members   -  Reputation: 275

Like
1Likes
Like

Posted 10 November 2013 - 02:53 AM

Calculate the bounding volume after the geometry data has been formed and manipulated, if you're basing the bounding volume on the 'at rest' pose or what ever your first keyframe is then you're going to be losing accuracy in the space filled by the volume.



#6 Digitalfragment   Members   -  Reputation: 827

Like
1Likes
Like

Posted 10 November 2013 - 04:37 PM

Calculate a bounding box for each joint in the body in the orientation of that joint, based only on the vertices that are skinned to that joint.

Then at runtime, project the joint-oriented bounding boxes into worldspace, taking the min and max of each of those bounding boxes.

 

There's no real reason to have an artist make the bounding volumes.



#7 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 11 November 2013 - 06:20 AM

Calculate the bounding volume after the geometry data has been formed and manipulated, if you're basing the bounding volume on the 'at rest' pose or what ever your first keyframe is then you're going to be losing accuracy in the space filled by the volume.

In fact I calculate the AABB in model-space, then I convert it to OBB to transform it in world space, then I calculate the final AABB

 

Calculate a bounding box for each joint in the body in the orientation of that joint, based only on the vertices that are skinned to that joint.

Then at runtime, project the joint-oriented bounding boxes into worldspace, taking the min and max of each of those bounding boxes.

 

There's no real reason to have an artist make the bounding volumes.

Thank you, this is probably the best way, but before implementing this I prefer use simpler methods. (i.e. the artist provides the model space's AABB). But your method is the best, and will try it latersmile.png


Edited by Tournicoti, 11 November 2013 - 06:20 AM.


#8 lunkhound   Members   -  Reputation: 607

Like
1Likes
Like

Posted 11 November 2013 - 07:09 PM

Another way:

 

Compute the bounding box of all of the skinning bones (that aren't scaled to zero).  Inflate the resulting box by a precomputed amount (scaled according to the maximum scale applied to any skinning bone).

 

Advantage:  Cheaper in CPU cost to compute (compared to the bounding box per bone method); also no per-bone extra data

 

Disadvantage:  Less optimal fit.



#9 Stragen   Members   -  Reputation: 275

Like
1Likes
Like

Posted 12 November 2013 - 01:11 AM

 

Calculate the bounding volume after the geometry data has been formed and manipulated, if you're basing the bounding volume on the 'at rest' pose or what ever your first keyframe is then you're going to be losing accuracy in the space filled by the volume.

In fact I calculate the AABB in model-space, then I convert it to OBB to transform it in world space, then I calculate the final AABB

 

Why are you calculating two AABB's?

 

The AABB in model space should be the same volumetricly as the OBB, albeit the OBB is translated and rotated to be aligned to the facing of the object, the AABB in world space from the OBB will have large areas of 'empty' space, thereby negating the advantage of calculating an OBB. If your intent is to only ever use Axis Alligned, then calculating an AABB straight up would save you a tonne of time and could be done by calculating the max x,y,z post the scale, translate and rotate for any step in the animation.

 

Just to add something, the image below is what i expect that your concern is.

 

boundingboxexample.png

 

Left hand image is the model at the da Vinci Pose (the T pose), the right hand is the model with its arms up.

 

Your concern, as i understand it, is that your binding box (the black boxes) is not changing from frame to frame.

Am i on the right track?


Edited by Stragen, 12 November 2013 - 01:20 AM.


#10 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 12 November 2013 - 03:04 AM

Thank you for your answers smile.png

 


Why are you calculating two AABB's?

 

The AABB in model space is precomputed. It is an "axis-aligned OBB" in model-space ready for world transformation.

 

At runtime : model-space OBB  -> world transform -> world-space OBB -> world-space AABB

 

EDIT : But maybe you mean that I can just transform in world space the 2 vertices (min & max) of the AABB and compute the new AABB according to the 2 transformed vertices instead of the 8 transformed vertices of the OBB?


Edited by Tournicoti, 14 November 2013 - 12:37 PM.


#11 Stragen   Members   -  Reputation: 275

Like
2Likes
Like

Posted 13 November 2013 - 03:18 AM

If you are really needing to create an AABB, you will have to generate it based on the largest X,Y,Z value of the post scaled, translated, and rotated model. Its more important to do it against the post rotated model as you need the X,Y,Z based on where it lies after rotation, the result could then be scaled and translated. This will still need to be done each animation step as this is going to change where the BB is going to lie based on the location of the verticies changing each step.

 

You probably shouldn't bother with the generation of the maxes prior to transforming the model if you're not concerned with the OBB, so once you've transformed it calculate based on the same process that you did when calculating the 'OBB' the first time.

 

If you calculate the model maxes prior to the translation/scale/rotate you will get the maxes based on the model only in model space, and applying the same transformation will result in a OBB in world space.

 

Just to consider, below is an example of where an AABB is going to give you something that doesnt look right for the volume taken up by an object.

 

boundingboxexample2.png

 

The blue boxes are the same size, the AABB box has been cast in red on the box on the right.

The OBB for the blue box on the right will be the same space as the blue box.

 

If you go to investigate collision detection later down the track, AABB's are great for quick culling for proximity, OBB's create better accuracy for your final pass.


Edited by Stragen, 13 November 2013 - 03:20 AM.


#12 JohnnyCode   Members   -  Reputation: 228

Like
1Likes
Like

Posted 13 November 2013 - 06:05 PM

In case you need very accurate AABB and do not wish to compute it at animation run time - animated AABB? You would simply bind AABB to your asset as per frame object, though this would create an (unwanted) joint between animation - mesh.



#13 JohnnyCode   Members   -  Reputation: 228

Like
1Likes
Like

Posted 13 November 2013 - 06:09 PM

If you are really needing to create an AABB, you will have to generate it based on the largest X,Y,Z value of the post scaled, translated, and rotated model. Its more important to do it against the post rotated model as you need the X,Y,Z based on where it lies after rotation, the result could then be scaled and translated. This will still need to be done each animation step as this is going to change where the BB is going to lie based on the location of the verticies changing each step.

Animation of a mesh is an object space transformation, just as AABB is a object space axis aligned box. Further than object space transformations apply to AABB as well -with the same transformation result. The OP wants to have objects space box that encapsulates object space geometry every animation frame accurately.



#14 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 14 November 2013 - 12:13 PM

Hello

Since my skinned meshes will be drawned within a single draw call, I'm not sure I need a per-bone frustum culling, because even if a small part of the mesh is visible I'll have to draw it entirely. So I think my method of asking the artist to create a bounding-box for the skinned meshes, that bounds all the animations the mesh will have, could be not so bad finally .... I can get more false positives ("to be rendered") cases sure, but this technique has the benefit to be very cheap at CPU-side level.

 

Thank you for your positive help, guys smile.png


Edited by Tournicoti, 14 November 2013 - 12:25 PM.


#15 Kryzon   Prime Members   -  Reputation: 2956

Like
2Likes
Like

Posted 17 November 2013 - 09:01 PM

Your artist could put all that time to better use.

This is an iterative operation that could be done much faster with a procedural approach. If you have several different characters that need this, the benefit would be exponential.

 

Once you have all the animation sequences for a character production-ready, have a tool or piece of code that builds a bounding box for each single frame and then collects the biggest one. You can then save these dimensions in a configuration file or similar for your later use.

Depending on the software being used by the artist, you can program this tool right there with the script API for the software (Maya & MEL, 3DS Max & MaxScript, Blender & Python etc.).

 

For special sequences like those of special moves (when the character may fly around or have broad movements) you will have to use something else as the skeleton and mesh may travel away from the node's transform, having the bounding box staying with the node and the mesh becoming independent and leaving the bounding box. For these cases you may not even use culling at all.


Edited by Kryzon, 17 November 2013 - 09:09 PM.


#16 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 18 November 2013 - 02:48 AM

Once you have all the animation sequences for a character production-ready, have a tool or piece of code that builds a bounding box for each single frame and then collects the biggest one. 

 

 

This is a very good idea thank you, I think I will do this. I'll add this in my tool that import the meshes. rolleyes.gif

 

(Even if the artist (the friend with who I have this mario-kart like racing game project) really doesn't mind to add a box in the asset in 30 seconds ...wink.png )



#17 Stragen   Members   -  Reputation: 275

Like
0Likes
Like

Posted 18 November 2013 - 04:08 AM

 

If you are really needing to create an AABB, you will have to generate it based on the largest X,Y,Z value of the post scaled, translated, and rotated model. Its more important to do it against the post rotated model as you need the X,Y,Z based on where it lies after rotation, the result could then be scaled and translated. This will still need to be done each animation step as this is going to change where the BB is going to lie based on the location of the verticies changing each step.

Animation of a mesh is an object space transformation, just as AABB is a object space axis aligned box. Further than object space transformations apply to AABB as well -with the same transformation result. The OP wants to have objects space box that encapsulates object space geometry every animation frame accurately.

 

The definition of the animation steps is just a case of being specific, you could calculate the AABB once, for example at model loading, and you could say thats it. Sure you have a BB, but it wont represent the simplified volume taken up by the model as the arms and legs of the model flail around outside of the initial BB volume.



#18 Kryzon   Prime Members   -  Reputation: 2956

Like
1Likes
Like

Posted 18 November 2013 - 06:08 PM

 

Once you have all the animation sequences for a character production-ready, have a tool or piece of code that builds a bounding box for each single frame and then collects the biggest one. 

 

 

This is a very good idea thank you, I think I will do this. I'll add this in my tool that import the meshes. rolleyes.gif

 

(Even if the artist (the friend with who I have this mario-kart like racing game project) really doesn't mind to add a box in the asset in 30 seconds ...wink.png )

 

 

A small correction: Collect the biggest dimensions from each frame separately. 

The biggest height, the biggest width and the biggest depth may not necessarily all come from the same frame (one frame may have the biggest height, but another may have the biggest width etc.).

In the end, this "all-encompassing" bounding box is formed by the biggest dimensions that you find among all the frames.



#19 Tournicoti   Prime Members   -  Reputation: 683

Like
0Likes
Like

Posted 19 November 2013 - 06:11 AM

 

 

Once you have all the animation sequences for a character production-ready, have a tool or piece of code that builds a bounding box for each single frame and then collects the biggest one. 

 

 

This is a very good idea thank you, I think I will do this. I'll add this in my tool that import the meshes. rolleyes.gif

 

(Even if the artist (the friend with who I have this mario-kart like racing game project) really doesn't mind to add a box in the asset in 30 seconds ...wink.png )

 

 

A small correction: Collect the biggest dimensions from each frame separately. 

The biggest height, the biggest width and the biggest depth may not necessarily all come from the same frame (one frame may have the biggest height, but another may have the biggest width etc.).

In the end, this "all-encompassing" bounding box is formed by the biggest dimensions that you find among all the frames.

 

Thanks, I understood your idea this way.

 

I talked about this with my friend, and he told me that it would certainly work in most cases but in some others he would have to add more key frames : for instance imagine a planet and its satellite, there would be only two key frames (0->180 and 180->360) . This wouldn't be enought to correctly compute the bounding volume : 4 key frames would be needed (0° , 90°, 180° and 270°).

 

Either he would have to add unecessary key frames in his animations, or .... stick with my provided bounding box idea sad.png  and he prefers the latter ...


Edited by Tournicoti, 19 November 2013 - 06:25 AM.


#20 Buckshag   Members   -  Reputation: 518

Like
2Likes
Like

Posted 19 November 2013 - 06:46 AM

It depends a bit on how your animation system works, but what works well for static boxes is to just take the bounds of the mesh, and get maximum of width/height/depth and size the box in all dimensions with that amount. So the same as mentioned above but without using any keyframes.

 

Some methods of calculating bounds that I implemented:

1.) Contain all node/bone global positions

2.) Contain all (skinned) vertex positions

3.) Contain all OBB's of each node/bone

4.) Static box that moves with the position of the actor (method as described above)

 

The method using keyframes would only work if you do not blend or combine motions or do not do any procedural things. Or you would have to pass your full motion database through it. But this is quite overkill. Also if you choose to go with this method, you most likely will sample your animation curves when importing them from the software you exported with. For example if you load an FBX or use an exporter from Max or Maya you sample the transforms every n frames and possibly optimize that data. This means that it is highly unlikely that you would hit a case where you export just 2 keyframes for a 360 degree rotation.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS