Multiple partIds in btOptimizedBvh

Tim Johansson
Posts: 2
Joined: Sun Nov 04, 2007 4:17 pm

Multiple partIds in btOptimizedBvh

Post by Tim Johansson »

Hi,

I recently started looking at integrating bullet in some of my stuff, most of the it seems to work well, but I ran in to two problems when integrating it.

The most serious one was that btBvhTriangleMesh cannot create an optimized bvh if you create it with a btTriangleIndexVertexArray with multiple btIndexMesh objects in it.

The other issue I encountered was that you cannot create a btTriangleIndexVertexArray with shorts as indices.

I fixed both these issues in my local tree. I would be happy to send a patch if anyone is interested. Is there some official/prefered way of sending patches?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Multiple partIds in btOptimizedBvh

Post by Erwin Coumans »

Tim Johansson wrote:The most serious one was that btBvhTriangleMesh cannot create an optimized bvh if you create it with a btTriangleIndexVertexArray with multiple btIndexMesh objects in it.
Can you describe what is going wrong with multiple parts? Some demo/unit-test should be added to test this feature.
The other issue I encountered was that you cannot create a btTriangleIndexVertexArray with shorts as indices.

I fixed both these issues in my local tree. I would be happy to send a patch if anyone is interested. Is there some official/prefered way of sending patches?
That sounds great. Contributions are very welcome, I'm happy to review and submit them into the repository. Can you attach a zipfile with the modified files, or a patch against latest SVN?
Thanks a lot,
Erwin
Tim Johansson
Posts: 2
Joined: Sun Nov 04, 2007 4:17 pm

Re: Multiple partIds in btOptimizedBvh

Post by Tim Johansson »

I've attached a zip file with the modified files. All the files comes fomr src/BulletCollision/CollisionShapes .

The problem with multiple parts in btOptimizedBvh was that btQuantizedBvhNode only stored triangle index, not partId. All places where the triangles where used later assumed that the triangle index was an index in the first part. (There was an assert in internalProcessTriangleIndex to make sure there was only one part, so it was really easy to figure out :))

It should be fairly easy to modify some demo to use multiple parts, or write a new one which does. Just split the vertex/index arrays in two and call btTriangleIndexVertexArray::addIndexedMesh more than once.
You do not have the required permissions to view the files attached to this post.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Multiple partIds in btOptimizedBvh

Post by Erwin Coumans »

Your patch looks great. I just realized the part index was not added, just to keep the size of the node 16 bytes, but your compromise of sharing bits for partId/triangle index is reasonable. It just reduces the maximum number of triangles in a mesh from 2147483648 to 2097152 (1024 times less), but that shouldn't be a problem for most game scenarios.

I didn't add short-int indices, to avoid the check in the innerloop, but I suppose it doesn't harm performance too much, so I'll accept it too.

I'll test the patch and commit it soon,
Thanks a lot,
Erwin
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Multiple partIds in btOptimizedBvh

Post by Erwin Coumans »

The patch has been applied, so it will be available from Bullet 2.65 onwards.

Thanks a lot,
Erwin