bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.25k stars 261 forks source link

MeshReduction shape type generalization #156

Open RossNordby opened 2 years ago

RossNordby commented 2 years ago

For 2.4, MeshReduction has taken a dependency on the Mesh type. Previously, it worked for any IHomogeneousCompoundShape<Triangle, TriangleWide>, and I'd like to return to that level of support. Mesh is the only such type at the moment, but that is planned to change later.

Given that generic type awareness of the container cannot be passed through at the function level (convex-triangle tests are batched from many sources, so you'd only have the type parameter for the last call prior to flushing), there needs to be an indirection. Currently, a switch chooses from the various hardcoded reduction paths. That switch could be swapped out for a more general indirection, allowing custom reduction passes.

This would require the CollisionBatcher consume a continuation registry, like it currently consumes a pair type registry. Could also use a indirectionless fast path for the most common 'no reduction' case.

The cost of the indirection is effectively meaningless compared to what the reduction algorithms do, especially for meshes.