Obi Official Forum
Help Alembic Cache Mesh as Collider? - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help Alembic Cache Mesh as Collider? (/thread-2560.html)



Alembic Cache Mesh as Collider? - mattstrangio - 31-10-2020

Hello,

I have an animation in Maya that I exported out as an alembic cache, and have successfully imported into Unity as a GameObject.  I was hoping to use that animated GameObject as a collider for a ObiRope.  Basically, it's an animation of a horse, and I was looking to create the reins and sim them using ObiRope.  I can get the child mesh to act as a collider, but only the first frame mesh of the alembic cache.  It's not the entire animated GameObject.  Any advice for what I'm trying to achieve?


RE: Alembic Cache Mesh as Collider? - josemendez - 03-11-2020

(31-10-2020, 08:04 PM)mattstrangio Wrote: Hello,

I have an animation in Maya that I exported out as an alembic cache, and have successfully imported into Unity as a GameObject.  I was hoping to use that animated GameObject as a collider for a ObiRope.  Basically, it's an animation of a horse, and I was looking to create the reins and sim them using ObiRope.  I can get the child mesh to act as a collider, but only the first frame mesh of the alembic cache.  It's not the entire animated GameObject.  Any advice for what I'm trying to achieve?

animated MeshColliders are not supported by Unity, or at the very least, not intended to be used like this. (and as a consequence, not supported by Obi either). Same goes for pretty much any realtime game engine.

There's some workarounds, but they universally result in terrible performance as MeshColliders rely on pre-processing the mesh to allow for fast collision queries. The mesh is inserted into a spatial subdivision structure (BVH, BIH, KD-Tree, or similar) when the MeshCollider is created, then this structure is used to quickly find the closes triangle(s) to a certain position during collision detection. If you change the shared mesh every frame, then this structure needs to be recreated from scratch every frame which pretty much defeats the purpose of using it (as generating the entire structure can be slower than brute-forcing collision detection by iterating trough all triangles).

For one such workaround, see:
https://answers.unity.com/questions/1197217/can-a-mesh-collider-work-with-an-animated-skinned.html

This updates the collider in sync with a SkinnedMeshRenderer. You should be able to adapt the code to update the collider in sync with the alembic cache.


RE: Alembic Cache Mesh as Collider? - mattstrangio - 05-11-2020

(03-11-2020, 09:35 AM)josemendez Wrote: animated MeshColliders are not supported by Unity, or at the very least, not intended to be used like this. (and as a consequence, not supported by Obi either). Same goes for pretty much any realtime game engine.

There's some workarounds, but they universally result in terrible performance as MeshColliders rely on pre-processing the mesh to allow for fast collision queries. The mesh is inserted into a spatial subdivision structure (BVH, BIH, KD-Tree, or similar) when the MeshCollider is created, then this structure is used to quickly find the closes triangle(s) to a certain position during collision detection. If you change the shared mesh every frame, then this structure needs to be recreated from scratch every frame which pretty much defeats the purpose of using it (as generating the entire structure can be slower than brute-forcing collision detection by iterating trough all triangles).

For one such workaround, see:
https://answers.unity.com/questions/1197217/can-a-mesh-collider-work-with-an-animated-skinned.html

This updates the collider in sync with a SkinnedMeshRenderer. You should be able to adapt the code to update the collider in sync with the alembic cache.

Thank you Jose, this is very informative, much appreciated!  For this particular project, I'm aiming to use Unity as an "offline" renderer for a film-type project rather than real-time, so I'm not quite as concerned with the speed performance.  I just like your sim tools more, as they're more effective and easier to use than I find Maya's sim tools.  Anyhow...  Thanks again!

-Matt