[ODE] ODE.NET Model Processor

Jason Perkins starkos at gmail.com
Thu Jun 21 09:47:26 MST 2007


Richard Barrington has contributed a .x model loader for use with
ODE.NET, which now available in SVN. I'll just include his README by
way of introduction. Thanks Richard!

This is a Content Processor and Tag library written for use with
Microsoft Visual C# 2005 Express Edition and Microsoft XNA Game
Studio Express 1.0.

It can be used to read .x model vertex and index data before
insertion into the content pipeline. This is used to build ODE
Triangle Meshes which are then used for collision detection that
is more accurate than the default XNA bounding boxes or spheres.

Usage is simple:
Build the library and reference the DLL in your project.
Add the DLL to the Content Pipeline
Set the content processor for you .x models to OdeModelProcessor.

Create triangle meshes as follows:
1) Create a space, but only one for all of models.
2) Create a triangle data.
3) Load the model.
4) Retreive the tag from the model.
5) Build the triangle mesh with the tag.getTriangleMesh method,
   passing in the space and the empty triangle data.

Eg:

IntPtr odeSpace;
odeSpace = d.SimpleSpaceCreate(odeSpace);
IntPtr triData = d.GeomTriMeshDataCreate();
Model obj = content.Load<Model>("Content\\mycube");
OdeTag tag = (OdeTag)obj.Tag;
IntPtr odeTri = tag.getTriangleMesh(odeSpace, triData);

You can load multiple models and test for collisions with something
like this in the update method:

d.GeomSetPosition(odeTri1, obj1Position.X, obj1Position.Y, obj1Position.Z);
d.GeomSetPosition(odeTri2, obj2Position.X, obj2Position.Y, obj2Position.Z);
int numberOfContacts = d.Collide(odeTri1, odeTri2, ODE_CONTACTS,
                           contactGeom, d.ContactGeom.SizeOf);

Where odeTri1 and odeTri2 are triangle meshes you've created, obj1Position
and obj2Position are the positions of your rendered models in the scene,
ODE_CONTACTS is a constant defining the maximum number of contacts
to test for, contactGeom is a d.ContactGeom[] of length ODE_CONTACTS.

If numberOfContacts is greater than 0, you have a collision.

Other ODE functions such as d.SpaceCollide() should also work.


More information about the ODE mailing list