I'm trying to disable triangles in a btBvhTriangleMeshShape.
Would it somehow be possible to set a child-node's triangle index to -1 and adding an early-out-check for -1 in btBvhTriangleMeshShape::processAllTriangles::MyNodeOverlapCallback?
If so, how would I be able to do that? I assume something similar to the way that the collision-pipeline is implemented. Could I just use a btNodeOverlapCallback to get each nodeSubPart/nodeTriangleIndex and disable all intersecting triangles (with a ray or a convex shape). Or is there any easier way to do it?
Cheers,
Simon
Disabling a triangle in a btBvhTriangleMeshShape
-
S.Lundmark
- Posts: 50
- Joined: Thu Jul 09, 2009 1:46 pm
-
Erwin Coumans
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Disabling a triangle in a btBvhTriangleMeshShape
For a given triangle, you know the subpart and triangleIndex, right?
A simple brute force solution would be to keep an array of 'disabled' parts/indices and check for those in a derived version of btBvhTriangleMeshShape::processAllTriangles::MyNodeOverlapCallback.
If checking an array of disabled indices is not efficient, you could implement your suggestion indeed: for disabled triangles make their node's part or triangle index negative. Unless I missed something, it seems just a bit of bookkeeping. I would suggest implementing the "making the index negative" in btOptimizedBvh, similar to btOptimizedBvh::refitPartial.
Thanks,
Erwin
A simple brute force solution would be to keep an array of 'disabled' parts/indices and check for those in a derived version of btBvhTriangleMeshShape::processAllTriangles::MyNodeOverlapCallback.
If checking an array of disabled indices is not efficient, you could implement your suggestion indeed: for disabled triangles make their node's part or triangle index negative. Unless I missed something, it seems just a bit of bookkeeping. I would suggest implementing the "making the index negative" in btOptimizedBvh, similar to btOptimizedBvh::refitPartial.
It is not clear what the problem is. Can you go more in detail what you mean by 'that', so I can try to help?If so, how would I be able to do that?
Thanks,
Erwin
-
S.Lundmark
- Posts: 50
- Joined: Thu Jul 09, 2009 1:46 pm
Re: Disabling a triangle in a btBvhTriangleMeshShape
Hey Erwin!
Thanks for the answer.
Really I don't know subpart/triangleindex for the mesh. They're all built up from faces which can have 3 or more vertices. I could build a mapping from faces-index-to-triangle-indices to avoid that though. The array-solution would unfortunately be too inefficient since the mesh could potentially contain hundreds of disabled triangles.
What I'm not certain of is how the Bvh actually works. By looking into the btOptimizedBvh::refitPartial, it looks like it is just a brute-force check against all subtree's. If I understand the code correctly, each subtree contains a certain amount of nodes. Each node can be a leaf node, and if it is then it has a partId and a triangleIndex. These could obviously be used to do the solution we've been discussing.
Using the aabb-query to disable all triangles wouldn't yield exact results though, would it? I mean, unless I do an aabb-triangle-overlap test for each triangle in the overlapped nodes.
I'll try this solution (using aabb-intersection-tests) and see how it works. There'll be a slight discrepency of precision compared to what is really happening in-game, but I'm hoping that it will work good enough.
Thanks!
Simon
Thanks for the answer.
Really I don't know subpart/triangleindex for the mesh. They're all built up from faces which can have 3 or more vertices. I could build a mapping from faces-index-to-triangle-indices to avoid that though. The array-solution would unfortunately be too inefficient since the mesh could potentially contain hundreds of disabled triangles.
What I'm not certain of is how the Bvh actually works. By looking into the btOptimizedBvh::refitPartial, it looks like it is just a brute-force check against all subtree's. If I understand the code correctly, each subtree contains a certain amount of nodes. Each node can be a leaf node, and if it is then it has a partId and a triangleIndex. These could obviously be used to do the solution we've been discussing.
Using the aabb-query to disable all triangles wouldn't yield exact results though, would it? I mean, unless I do an aabb-triangle-overlap test for each triangle in the overlapped nodes.
I'll try this solution (using aabb-intersection-tests) and see how it works. There'll be a slight discrepency of precision compared to what is really happening in-game, but I'm hoping that it will work good enough.
Thanks!
Simon
-
S.Lundmark
- Posts: 50
- Joined: Thu Jul 09, 2009 1:46 pm
Re: Disabling a triangle in a btBvhTriangleMeshShape
Seems to work really good! Thanks.