Newbie modeling question

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
diadem
Posts: 10
Joined: Sat Jan 17, 2009 4:19 am

Newbie modeling question

Post by diadem »

I looked at the multi threaded physics demo to get a grasp of how things worked.

I see the physics side has boxes and such to represent how the shapes interact, and the draw side grabs the position and facings of these shapes and draws their representation so the user can see them.

I want to draw a complex model from truespace or blender instead of just a basic box.

What is the best way to get their bounds to pass into the physics engine? Is there a way to look at a model and generate a ConvexHull, or at least a Box, based on the models dimensions?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newbie modeling question

Post by Norbo »

I would recommend creating a custom content processor to extract the vertex positions from the model and giving that position list to the ConvexHull. A sample content processor can be found in the picking example on the Creators Club website: http://creators.xna.com/en-US/sample/pickingtriangle.

If, however, your shape can be approximated by a simpler shape (either a less complicated convex hull or one of the other primitive entities), consider using the simpler version. This won't matter much unless things get really complicated (or quite a few objects are in play), but it's good to keep in mind.
diadem
Posts: 10
Joined: Sat Jan 17, 2009 4:19 am

Re: Newbie modeling question

Post by diadem »

I got most of it, but I seem to be having one strange error. After spending a few hours on it, I am conceding to the fact I need help (and that I should start reading more to understand how things work underneath).

The problem is that the physics location and the draw location don't seem to sync up 100%. When I drew the coordinates of the convexhull and the model itself, this is what i got -
Image

It seems that the car is always a few feet too high. Is this because the exact center of the model isn't 0,0,0? If this is the case, what's the best way to correct it?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newbie modeling question

Post by Norbo »

It looks like the origin of your model is offset from the center of mass of the convex hull. Applying a base transformation that scoots the model down before applying the rotation and translation of the entity should do the trick. It'll require a bit of tweaking since it's not immediately obvious where the centers are in relation to each other.
diadem
Posts: 10
Joined: Sat Jan 17, 2009 4:19 am

Re: Newbie modeling question

Post by diadem »

Is there no automated way to do this? I tried to use the center of the boundingsphere to find the values for the translation, but to no avail.

I guess if worse comes to worse I can make a program that lets me try to center it using the keyboard and spits out the translation values. If I need to make one, I'll post the solution for others to use once I'm done.

Does the convexhull smooth itself out automatically? I noticed that the side mirrors and wheels don't appear.

Finally, what exactly does getconvexhull do? I can't seem to find any documentation on it.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newbie modeling question

Post by Norbo »

You could try to use the Entity.getExtremePoint function in some arbitrary direction (up?) and compare the extreme point to the center of the hull. The offset can then be used to position your model since you know where the extreme point of the convex hull should be on the model.

The missing mirrors and such are hopefully just the meshes that weren't in the list of vertices provided to the Toolbox.getConvexHull. If you collect the vertices from all of the meshes into one list and hand it to the getConvexHull method, it will create a set of points that compose the exterior of the now 'shrinkwrapped' shape.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newbie modeling question

Post by Norbo »

I forgot to mention that when you give a list of points to a ConvexHull constructor, Toolbox.getConvexHull is called internally so you don't need to do it before you pass in a point list.
diadem
Posts: 10
Joined: Sat Jan 17, 2009 4:19 am

Re: Newbie modeling question

Post by diadem »

Thanks for your help. My models are all working fine now.

I am running all my models through truespace and that seemed to fix the centering problems.
ThatsAMorais
Posts: 18
Joined: Mon Oct 05, 2009 5:24 am

Re: Newbie modeling question

Post by ThatsAMorais »

I keep looking around but I can't figure out how to draw the convex hull so I can determine what it looks like. any help?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newbie modeling question

Post by Norbo »

You can look at the DisplayConvexHull class in the BEPUphysicsDemos to see how to get a triangle-based representation. Basically, part of what the Toolbox.getConvexHull method computes is the surface triangles.
ThatsAMorais
Posts: 18
Joined: Mon Oct 05, 2009 5:24 am

Re: Newbie modeling question

Post by ThatsAMorais »

Thanks! I don't know how I overlooked this. I have some example code, but I don't know how I don't have this. Its not as though you had it strewn around the site. Nonetheless, these are really great debugging tools for me and I'm looking forward to trying them out.
Post Reply