own mesh with physic applied

Oct 28, 2009 at 11:09 PM

Hi.

I need to know how can I load a mesh (created in 3ds max) into my XNA 3.1 project, and how to apply physics to it usig oops! Framework.

Are you still updating and supporting oops! Framwork? Because the docs seems to be old and non updated.

Best Regards

Coordinator
Oct 29, 2009 at 12:15 AM

Hey.  You are correct.  The docs on this wiki are old.  I plan to update them now that there's a dedicated Documentation tab.  It'll be a bit.

Example 7 (Example7Screen.cs) in the Oops.Xna.Framework.Testing.App project has an example of using a mesh for a collision detection.  You can use the same Microsoft.Xna.Framework.Graphics.Model instance you use to draw the mesh for the collision detection as well.  Essentially, you do the following:

// Get the model.
Model model = Content.Load<Model>("World");

// Create a collision mesh.
CollisionMesh mesh = new CollisionMesh(new CollisionMeshProxy(model));

// Create a collision group and add the collision mesh to it.
CollisionGroup group = new CollisionGroup();
group.CollisionShapes.Add(mesh);

// Add the collision group to the physics component.
this.physics.CollisionSystem.CollisionGroups.Add(group);
Good luck!
May 8, 2010 at 4:53 AM
Edited May 8, 2010 at 4:59 AM

I am also having trouble getting my own meshes to work.  I've got an fbx model that I've exported from Blender. Content Importer is Autodesk FBX - XNA Framework. I'm trying to get it to work in example7.

 

I load the mesh just like I would any normal model:

this.model = Content.Load<Model>(@".\Content\Models\myModel");

 

In my Reset method, I try to call this, as you show:

this.mesh = new CollisionMesh(new CollisionMeshProxy(model));

But I get this error:

Error    7    Cannot create an instance of the abstract class or interface 'Oops.Xna.Framework.Physics.CollisionMeshProxy'

I've also tried calling this instead:

this.mesh = new CollisionMesh(new ModelCollisionMeshProxy(model));

But none of the dropped balls collide with my mesh.

 

Here's the full Reset method:

protected override void Reset()
        {
            this.Reset(0, 30);

            // Create the ground plane.  
            this.mesh = new CollisionMesh(new ModelCollisionMeshProxy(model));
            
            // Create a collision group and add the mesh.
            CollisionGroup collisionGroup = new CollisionGroup();
            collisionGroup.CollisionShapes.Add(this.mesh);

            // Add the mesh's collision group to the collision system.
            this.physics.CollisionSystem.CollisionGroups.Add(collisionGroup);
        }

Coordinator
May 8, 2010 at 3:11 PM

Hi xpox,

It looks like you are correctly creating the CollisionMesh and adding it to the physics component.  Two things that come to mind that may be the issue is winding order of your triangles in the mesh or you are accidently drawing the mesh transformed(scale/orientation/position) differently than where it's collision shape is. 

For the winding order, you can change that in the content processor properties.

For the mismatch drawing issue, If you press F2 (assuming you based your code on the examples) you get a bounding box around all physics objects.  Is there a bounding box around your collision mesh? If not this may be the issue.  Try setting your transform properties, again, in the content processor properties instead of when drawing.

Let me know how it goes.  Good luck.

May 9, 2010 at 3:51 AM

Thanks.  F2 helped me figure it out.  My model was a flat box whose rotation was incorrect.  When turned on its side, it was coincidentally too thin for any of the dropped spheres to hit. 

One issue I'm still seeing is that either the collision mesh is being generated at 100 times the scale of the model, or the model is being drawn at 1/100th the size of the collision mesh.  Not sure what's going on there.  For now, I can just upscale my models by 100.  I may try out another draw method to see if that changes anything.