I'm trying to get a grasp on how to set up broadphase layers, object layers and collision filtering.
Unfortunately, broadphase layers are directly linked to object layers, because you have to map from an object layer to a broadphase layer and (AFAIK) can't set the broadphaase layer of a body directly.
IMO the most flexible solution would be, if I could just set the broadphase layer of a body or shape directly. Another option would be to change the ObjectToBroadPhaseLayer type from a fixed array to a function pointer.
Here is what I am trying to achieve:
Users should be able to configure their own collision groups (up to 32 or 64 maybe). For every group they can decide with which other group those objects should collide with, so you get an NxN matrix. At runtime you need an array of size N which contains uint32 or uint64 masks that tell you which other collision group this group would collide with, so that you can make a quick bitmask check.
That is all data driven. Additionally, on the broadphase I want to have a few fixed layers:
- Static geometry -> collides with dynamic and debris
- Dynamic objects -> collides with static, dynamic and triggers
- Triggers -> collides with dynamic
- Query shapes -> collides with nothing, only for raycasts and overlap queries
- Debris -> collides with static only
The assignment of these broadphase layers should not be up to the user, but simply depend on what kind of body is created. That means the same collision layer might be in use in different broadphase layers.
Under the restriction that I can't set the broadphase directly, I was thinking of using the 16 bit of the object layer, to store the broadphase layer index in the upper 8 bit and the collision group in the lower 8 bit. Then in my ObjectVsBroadPhaseLayerFilter I could easily extract the broadphase layer index from the object layer and check whether the two broadphase layers should interact.
However, since ObjectToBroadPhaseLayer is an array, I would need to create a huge lookup table to cover all combinations.
Finally, it would also be nice to set the object layer per shape, rather than per body, so that one can easily add details to an object that, for example, are picked up by certain raycasts, but are ignored when colliding with the world.
Told you I'd have some feedback :D Overall Jolt is really, really awesome, it's so polished for a first version, I'm quite impressed and am looking forward to seeing some of these remaining rough edges improved.
Cheers,
Jan.