TriangleMesh Collision Issues

Apr 28, 2010 at 9:42 PM
I'm having some issues getting single Box collision shapes, as well as collision groups made up of several boxes, to collide correctly with TriangleMesh collision shapes. My single Box collision shape is just that: a box. The collision group has 3 boxes: 1 flat wide one in the middle, and two slightly taller but thinner ones on the sides (almost like a dumbbell). This is essentially a movable platform that holds the single box. The TriangleMesh shape is basically a model of several boxes in various configurations (and later will also contain triangular wedges). The lone box sits on the "platform" collision group, which can be moved by adding forces. That works great, and the platform and box collide perfectly. But those two pieces don't react very well to the TriangleMesh shape. The lone box shape will, for the most part, collide as you'd expect, unless it's hitting very close to a sharp edge on the TriangleMesh shape. If that happens, the box will start to fall into the TriangleMesh slightly as it moves. The "platform" shape (which again is made up of 3 box collision shapes inside one collision group) is much worse. When it hits the Triangle Mesh, it stops briefly (as if the collision worked) and then starts to slowly sink into the shape, regardless of where it makes contact. When I converted the TriangleMesh to a bunch of regular Box shapes, everything worked great. That unfortunately won't work for the eventual wedge shapes I need to add. Are these known issues? Is there some other combination of shapes I could use to get a similar effect? I can provide a video if my description isn't very helpful. Thanks! -Chris
May 1, 2010 at 7:59 AM

If you have a moment to create a video that would be great.  I'm actually in the middle of attempting to fix some of the issues with box collisions, mainly against meshes and other boxes. 

I do know that there are issues with CollisionGroups made up of multiple CollisionShapes, mainly that the inertia tensor won't calculate correctly.  I'm also working on this at the moment.

Some questions:

- Do you have PhysicsComponent.DrawAABBs = true?  You can see the collisions if you do this and might be able to determine what might be going on.

- What are the size of your triangles?  Larger triangles normally produce better colllision manifolds since there should be a lot less contact points.

Let me know.

May 9, 2010 at 4:05 AM
Edited May 9, 2010 at 4:11 AM

It's been a busy week, but I finally got around to making a video of my issue:  YouTube  It's still processing, so hopefully you'll be able to watch a higher res version once it's done. 

- I have a single shape and a compound shape collide with a triangle mesh. The single shape is the crate, which uses a box collision shape. The compound shape is the platform, which uses 3 box shapes in one collision group.  The floating blocks are one big triangle mesh.  (The reason they're a triangle mesh and not a bunch of boxes is because the game will contain other, non-box shapes as well).

 - I'm not using the AABB's.  I do however draw my own bounding boxes that match up with the corners of the actual (rotated) box shapes.

 - You should be able to approximate the size of the triangles in my triangle mesh by looking at the stone "blocks" in the video.

 - The only input I'm giving the system is firing the left or right thrusters on the platform (the fire coming out) which adds a force to the left or right of the platform.  I also press a button to reset the position of the crate and platform.

I hope this helps a bit.  If you have any other questions for me, let me know!



May 11, 2010 at 6:52 PM

Hey vixorien,  thanks for the video (nice graphics!). 

It looks to be resolving the collisions a bit slowly over time instead of immediately, which could be a problem with the collision detection (box-to-mesh, BoxMeshCollisionDetector.cs) or collision resolution(Collision.PreStep/Collision.Solve).

If you look at the code for the BoxMeshCollisionDetector class, there are a few TODO comments in there point to the issue of not calculating collision depth correctly.  Before my next release, you can try modifying these calculations.  What's suppose to happen is each intersection with a triangle should retain the collision points and penetration depth.  Right now, it's combining them all together into one depth/group of points.

...or you can wait until I fix it in my next release.  I'm working on box-box right now and will be doing box-mesh next.

In the Collision.PreStep method, I'm limiting the actual change in velocity allowed per simulation step, which could be adding a bit to the problem if the object you are using are large...possibly.  Look for the constant of "2.5f".

I'm expecting another release in June that should hopefully resolve these problems.  Good luck!


May 17, 2010 at 7:28 PM
Thanks for the info! I might muck around in the Oops code one of these days, although you'll probably have that release ready before I get the chance. I have a physics abstraction layer in the game right now that lets me swap between Oops, JigLibX and Box2D at will. I wasn't sure which physics engine would work out the best, so I just implemented them all. Oops has definitely been more stable than JigLibX. I'm excited for your next release :) -Chris