Change order nodes are processed by BvhTriangleMeshShape?

jeff
Posts: 6
Joined: Thu Aug 02, 2012 12:40 am

Change order nodes are processed by BvhTriangleMeshShape?

Post by jeff »

Is it possible to change the order that nodes are processed by a BvhTriangleMeshShape, or would that conflict with the algorithm it uses? When using a regular TriangleMeshShape, I can sort the triangles by their normal before adding them to the shape, and they will be processed in that order.

The reason that I'm trying to do this is: when a sphere is at the corner formed by two planes (like when on the edge of a cliff), I can use a contact added callback to find the normal of the triangle the sphere is colliding with. However, only one contact seems to be added, and its for the triangle that is handled first. I need to get the normal for the horizontal triangle, not the vertical triangle. By sorting the triangles by the Y component of their normal (descending), I am able to get this behavior for TriangleMeshShape, but obviously that won't work for BvhTriangleMeshShape.

simple diagram

Code: Select all

_____o    <--- need to get normal for this top triangle from the contact
     |    <--- not the normal from this one
     |
Would it be possible for me to tweak BvhTriangleMeshShape to get that kind of behavior? Or is there a better approach?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Change order nodes are processed by BvhTriangleMeshShape

Post by Erwin Coumans »

There is currently no way to sort the triangles when using a btBvhTriangleMeshShape.

The btInternalEdgeUtility is made to deal with such internal edge normals, see Bullet/Demos/InternalEdgeDemo.

One other solution is to cache the triangles of the btBvhTriangleMeshShape, and sort the cached triangles before passing them to the narrowphase. We did this for some games using Bullet, but it requires some modifications. Such cache can also improve performance (as long as the object is within the enlarged AABB of the cache, you don't need to perform any mesh/btBvhTriangleMeshShape query.
jeff
Posts: 6
Joined: Thu Aug 02, 2012 12:40 am

Re: Change order nodes are processed by BvhTriangleMeshShape

Post by jeff »

btInternalEdgeUtility is causing me other problems, so I'm trying to avoid using it.

Sorting the triangles before the narrowphase was easier than I expected. Thanks for the help.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Change order nodes are processed by BvhTriangleMeshShape

Post by Erwin Coumans »

Do you mind sharing your changes to sort the triangles? It could help others.

Also, what kind of troubles do you have with btInternalEdgeUtility?
Thanks for your feedback,
Erwin