Open Hayden-Fluff opened 3 years ago
Unfortunately this isn't really feasible. Mesh Colliders require heavy pre-computations, which can take up to several seconds to complete. Doing this every frame isn't feasible.
What titles have you seen use this? I don't think that they actually had Skinned Mesh Colliders, but rather just accurate hand-made primitive colliders.
At most we could potentially automatically split the mesh collider into static meshes by whichever bone affects them the most, which might work ok-enough, but I'm not fully sure if it's worth any development time, since you should really be using primitive colliders for anything that has to do with such shapes instead. You mention that you encountered cases where this would be useful, but you do not mention any.
I've encountered this in a game called Heat, though NSFW, the level of interaction it has is astounding. At first I thought it was using really well approximated primitive colliders, but upon further inspection through messing with the in-game mechanics, I found that the collisions are hollow, and also very accurately conform to the mesh, and Skinned Mesh collision is really the only way I could have thought of that would allow for that level of accuracy. I even asked the main developer how they're handling it, and they confirmed that the game uses a lower detail mesh for skinned mesh collision.
Lower resolution mesh is the key here. And the kind of physics engine they are using for the collision calculation. I believe, BEPUv2 "compiles" mesh colliders into low-level code that could check for collisions very effectively, but the initial conversion takes some time (much longer than a frame time) instead.
Hmm I see. If it's sufficiently low poly, then the recalculation should be reasonably fast. There's one way to approach this - add a procedural mesh provider that performs skinned mesh transformations on the CPU and then feed this into mesh collider as any other procedural mesh.
This way the input mesh is technically static, just changing often. Though this might also introduce some overheads, but would utilize existing systems better and be easier to implement. Those are also double-buffered, ensuring that there won't be weird ghost or missed collisions.
Alternatively we could invest more time and make something more optimized, that will progressively refit and refine the mesh collider, but that's usually pretty expensive for this and might not work well with parallelization.
@shadowpanther The meshes aren't compiled specifically, but the principle is the same. BEPUv2 computes a bounding box tree - a data structure that allow efficiently querying triangles within a particular area.
Is your feature request related to a problem? Please describe.
I've encountered cases where it'd be nice to have a skinned mesh have collision accurate to the mesh, however there's no way of doing this. Currently if you throw a mesh collider on a skinned mesh, the collision will only be accurate to the default pose.
Relevant issues
None to be found.
Describe the solution you'd like
An additional component to implement skinned mesh collision, similar to a Skinnned Mesh Renderer, where it accepts a mesh and a list of bones.
Describe alternatives you've considered
I can't really think of any good alternatives, as making primitive approximations along the armature can introduce it's own issues, as well as not allowing for hollow collisions. This also does not really work with meshes designed to be used as an interior, especially if there's more complex geometry.
Additional context
I understand that doing this may be insanely expensive, however I have seen other VR titles pull this off before, and the accuracy it can provide can be really good for certain situations.