Physics TriangleMesh

Oct 2, 2010 at 2:48 AM

I would like to use  triangle mesh for physics of a low poly, non-convex, static object. I'm using Newton. I cannot get it to work. Here is what I am doing currently:

pitNode.Model = pitModel;
pitNode.Physics.MeshProvider = pitModel;
pitNode.AddToPhysicsEngine = true;
pitNode.Physics.Collidable = true;
pitNode.Physics.Shape = ShapeType.TriangleMesh;

With this, it does not detect any collisions. The pitmodel loads fine as a meshprovider. It's primitive type is a triangle list. How can I fix this?

Oct 10, 2010 at 7:05 AM

It should work. Did you initialize NewtonPhysics like in Tutorial 5?

Also, is your pitModel a type of GoblinXNA.Model class, or your own IModel + IMeshProvider implementation?


Oct 10, 2010 at 6:20 PM
Edited Oct 10, 2010 at 6:22 PM

pitModel is a .x file. I use goblins implementations of everything. It is initialized the same a tutorial 5. I have other physics like bounding box collisions working consistently well.


it seems that it is the way I did my model. i have tried it with a few other models and it some times works for part of the model and then other parts it does not work. the pit model seems to be particularly bad perhaps because there are a lot of in-facing triangles (i.e., it  is a UNC-style pit like from the classic presence experiments)? I also tried a model that I imported from Oblivion - a dragon. it mostly works as a triangle mesh but there were parts of the model that did not detect collisions. im pretty sure that all of those triangles have outward facing normals.

do you have any suggestions of how to make models work for triangle meshes?


Oct 10, 2010 at 8:15 PM

I thought I solved those issues on v3.4, but there might be some exceptions. You can probably turn on scene.RenderCollisionMesh to see if the physics mesh are correctly created in the physics engine. Even if the mesh is correct, if the winding is inconsistent, then it won't work correctly with Newton (it will work on Havok even if the windings are inconsistent). The .x models I've tried so far works correctly, and I use Google SketchUp's plug in to do conversion from other formats to .x format.


Apr 25, 2013 at 3:22 PM

I have the same problem than "jpq". I generated two mesh (format fbx) from google sketchup and I want to know when theses objects are collided.
I don't use MarkerNode as it is not an AR application.
I searched on different discussions but i did not find any solution.

I initialized my Physisc engine as Tutorial 5 and then my code is more or less like this :
void initialize()
         //Object1 creation  
          Model model = (Model)_modelLoader.Load("", "myModel1");
            _model1 = new GeometryNode("Model1");
            _model1.Model = model;
            ((Model)_model1.Model).UseInternalMaterials = true;
            ((Model)_model1.Model).UseLighting = true;
            _model1.Physics.Shape = GoblinXNA.Physics.ShapeType.TriangleMesh;
            _model1.Physics.Pickable = true;
            _model1.AddToPhysicsEngine = true;
            _model1.Physics.Collidable = true;    

         //Object2 creation  
            model = (Model)_modelLoader.Load("", "myModel2");
            _model2 = new GeometryNode("Model2");
            _model2 .Model = model;
            ((Model)_model2 .Model).UseInternalMaterials = true;
            ((Model)_model2 .Model).UseLighting = true;
            _model2 .Physics.Shape = GoblinXNA.Physics.ShapeType.TriangleMesh;
            _model2 .Physics.Pickable = true;
            _model2 .AddToPhysicsEngine = true;
            _model2 .Physics.Collidable = true;  

            NewtonPhysics.CollisionPair pair = new NewtonPhysics.CollisionPair(_model1.Physics, _model2 .Physics);
            ((NewtonPhysics)_scene.PhysicsEngine).AddCollisionCallback(pair, onCollision);

          ..... /*add to transformeNode and to the scene */

void onCollision(NewtonPhysics.CollisionPair pair)
            UI2DRenderer.WriteText(new Vector2(100, 100), "COLLISION", Color.Black, _font);

void update()
/* here I change my object transformation and update the scene*/

void draw()
            ((NewtonPhysics)_scene.PhysicsEngine).SetTransform(_model1.Physics, _model1.WorldTransformation);
            ((NewtonPhysics)_scene.PhysicsEngine).SetTransform(_model2.Physics, _model2.WorldTransformation);

/* here I draw the scene */
My problem is, I never enter onCollision() method. Nonetheless, it works when I replace

_model1 .Physics.Shape = GoblinXNA.Physics.ShapeType.TriangleMesh;
_model1.Physics.Shape = GoblinXNA.Physics.ShapeType.Box;

For additional information the picking method and the shadow map work perfectly with those objects, that is why I suppose they are correct.

I also set the boolean at True of "scene.RenderCollisionMesh" and here you have a screenshot of the result.


Please if you have an idea about this problem, let me know!
Thank you very much.