Collision detection with TriangleMesh

May 14, 2013 at 10:34 AM

I'm trying to know when 2 models are collided with the highest precision, ie when the triangles are overlapped.
I generated two meshes (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 available 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

_model .Physics.Shape = GoblinXNA.Physics.ShapeType.TriangleMesh;
_model.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.