Page 1 of 1

"multiple mesh parts" with btBvhTriangleMeshShape?

Posted: Fri Mar 19, 2021 6:17 pm
by acu192
The User's Manual says that a btBvhTriangleMeshShape can store "multiple mesh parts" (page 14).

I studied the source of btTriangleMesh and it only uses one (1) "part" (i.e. only one entry goes into the `m_indexedMeshes` array).

So, my question (I've tried studying the code deeper, and also searching the forum, but I can't find the answer myself) is ...

Is there ever a reason to use "multiple mesh parts" in my btBvhTriangleMeshShape? If so, when should I use multiple "parts"?

My general idea is that if my mesh has more than one "connected components" (to use a graph theory term), then each "connected components" (again, graph theory term) should become a "part" in the btBvhTriangleMeshShape?

In other places on this forum, @drleviathan has called the btBvhTriangleMeshShape a "triangle soup". If that's really the case, then having multiple "parts" wouldn't change any of the underlying computation?

Thank you!

Re: "multiple mesh parts" with btBvhTriangleMeshShape?

Posted: Fri Mar 19, 2021 10:23 pm
by drleviathan
My interpretation of the manual (although I wasn't able to find a copy with the section you describe) is: if you have multiple distinct mesh "parts"... then you could store them in single btBvhTriangleMeshShape instance in one RigidBody... and the collision behavior would be identical to what you'd get if you stored each part in its own btBvhTriangleMeshShape instance on a distinct RigidBody.

Of course... you would NOT want to store multiple "parts" in a single shape when you need to add/remove parts dynamically at runtime.

Re: "multiple mesh parts" with btBvhTriangleMeshShape?

Posted: Fri Mar 19, 2021 11:30 pm
by acu192
Here's the manual I was referring to: ... Manual.pdf (middle-ish of page 14) Says, "The btBvhTriangleMeshShape can store multiple mesh parts. It keeps a triangle index and part index in a 32bit structure, reserving 10 bits for the part Id and the remaining 22 bits for triangle index."

Your interpretation seems reasonable. There's another sentence in the manual (page 35) that says "Many small btBvhTriangleMeshShape pollute the broadphase. Better combine them." So... your interpretation is consistent with that idea as well.

Another interesting bit: None of the examples in the bullet source code uses multiple "parts" in a single btBvhTriangleMeshShape. So I'm hesitant to go down that road since it's apparently not common enough to make it into an example.

I'm assuming, @drleviathan, that you've never used multiple "parts" in a single btBvhTriangleMeshShape then?

Re: "multiple mesh parts" with btBvhTriangleMeshShape?

Posted: Mon Mar 22, 2021 3:39 pm
by drleviathan
Ah I see... looking closer at the code I rediscover: the btBvhTriangleMeshShape uses an instance of something that implements the btStridingMeshInterface and that interface supports having the mesh split into sub-parts. Yes, I recall taking advantage of that multiple parts API. At one time we were loading FBX files into memory and the triangle mesh info would be divided into multiple parts, depending on how the FBX mesh was created. We wrote a FbxMeshInterface class to give the btBvhTriangleMeshShape access to the raw data, which was also used for rendering.

Re: "multiple mesh parts" with btBvhTriangleMeshShape?

Posted: Tue Mar 23, 2021 3:30 pm
by acu192
Yes, that's actually how I ran into this myself (except we're loading GLTF instead of FBX but whatever, conceptually the same).

Actually I went ahead and am just using btTriangleMesh (implements btStridingMeshInterface) and I'm just adding all triangles to one "part" (because that's a limitation of btTriangleMesh). It seems to be working totally fine on all my models so far. But my original question was essentially: Is the underlying computation of btBvhTriangleMeshShape **different** if you add all triangles to one "part" vs. if you honor your GLTF and add triangles to several "parts"? I have a feeling that the answer is "no, it's all just a triangle soup no matter what" -- but I haven't been able to verify that. I tried studying the code deeper but I'm not seeing the answer.