Page 1 of 1
Bounding shapes
Posted: Wed Oct 17, 2012 5:09 pm
by bdpdonp
This may be a simple question, but I have not yet grasped the answer. I load in a 3D model and wish to put a bounding rectangle around it. How do I know the size of the rectangle I need? As I did not build the 3D model myself, I do not think I would have the details I need to determine this, even if the units in bepu and the modelling program math.
Re: Bounding shapes
Posted: Wed Oct 17, 2012 5:45 pm
by Norbo
Assuming there's no metadata describing artist-defined bounding volumes in the model somewhere, iterate through every vertex location and compute the minimum and maximum values along the X, Y, and Z axes as you go. Once you are done, you will have an axis aligned bounding box. BEPUphysics is unitless, so you don't need to worry about converting to another unit system. BEPUphysics can use the numbers in the model directly.
(There are some reasons to constrain the size of your objects, though. The engine likes individual objects in the range of 0.5 to 10 units. It's very possible to go outside of this range, but if you go crazy with it, numerical and tuning issues will creep in. Using something like the BEPUphysicsDemos ConfigurationHelper.ApplyScale method can help adjust the engine's scale 'interpretation' to handle much larger or smaller scales, but I generally recommend just scaling stuff to be close to the default size range.)
Re: Bounding shapes
Posted: Wed Oct 17, 2012 6:01 pm
by bdpdonp
Thanks for the response.
I am building a space flight simulation, and some of the models are large,thought I do scale them for the 3D graphics. For the physics world, it sounds like I can scale everything down and perform the collisions etc and then use the results to effect the graphics.
Re: Bounding shapes
Posted: Wed Oct 17, 2012 6:04 pm
by Norbo
I should clarify that when I said individual objects, I meant individual convex collidable pieces. For a triangle mesh, this would mean each triangle would be roughly in the range from 0.5 to 10 units. So if you've got a model that's 1000 units long but is composed of 100 triangles lengthwise, it's probably perfectly fine (unless there some near-degenerate single triangles stretching across the entire length; those should be dealt with directly rather than attempting to scale the whole model down to compensate).