Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

2018 Dynamic MeshCollider Solution For Large Meshes and Fluid Dynamic

Discussion in 'Physics' started by pan-master, Jul 8, 2018.

  1. pan-master


    Nov 11, 2013
    This post is created to solve a problem of dynamic large MeshColliders with fluid collisions
    1.Static MeshColiders are creatd from the shareMesh, Where are the collision calculations being executed? CPU vs GPU?( maybe it depends?, some can Use CPU as Rigidbodies, and some can be calculated on GPUs using cuda/uFlex?

    2. What is the Maximum limit of tringles for a mesh collider?(255)?
    3. Where do the deformatnios of SkinnedMesh take place. CPU or GPU?
    4. if Deformations happen on GPU, can We Pull Deformed SharedMesh from GPU to Update MeshCollider.shardMesh?
    5. If we calculate collisions on the GPU using cuda. would it be possible to copy shardMesh data within GPU to update on GPU MeshCollider Data?, without pulling back and forward data between GPU,CPU?,
    6. If the limit of polygons for MeshCollider is 255, Would it be posible, to create secondary Set of Meshes,Each 255, that would fallow and deform mapped parts of main Large Mesh?
    7. How woud we map secondary Meshes to fallow parts of large Main Skinned Deforming Mesh
    8.Any ideas for different solutions?
  2. Edy


    Jun 3, 2010
    I can answer a few of these:

    Physics run on CPU only.

    Convex mesh colliders have a limit of 255 triangles. Note that this doesn't apply to the original mesh. When you mark a mesh collider as Convex a convex-hull is computed out of the original mesh. The resulting mesh is limited to 255 triangles, no matter the number of triangles in the original mesh.

    Non-convex mesh colliders have the same limits as regular meshes (65535 triangles, but objects are split automatically by Unity upon import). However, the less triangles the more efficient collisions. Also, it's highly recommended to split large mesh colliders in smaller colliders because collisions involve calculations using the bounding boxes.

    Again, this is different among Convex and non-convex mesh colliders:

    Convex mesh colliders are limited to 255 triangles, but you may split your collider in smaller colliders in order to resemble non-convex shapes. When you modify the sharedMesh of a Convex collider then a new convex-hull is calculated out of the new mesh data. Note that a Convex collider with less than 255 triangles may result in a convex collider with more than 255 triangles after being modified, even having modified the vertices only in the original mesh. It depends on the resulting convex shape.

    Non-convex mesh colliders may be modified straight away and the collisions will result as expected.
  3. pan-master


    Nov 11, 2013

    Code (CSharp):
    1.  [Range(0.005f,1)]
    2.     public float RateOfUpdate = 0;
    3.     MeshCollider meshColider;
    4.     SkinnedMeshRenderer skinnedMeshRenderer;
    5.     Mesh bakedMesh;
    6.     MeshFilter meshFilter;
    7.     // Use this for initialization
    8.     void Start () {
    9.         skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
    10.         meshFilter = GetComponent<MeshFilter>();
    11.         meshColider = GetComponent<MeshCollider>();
    13.         bakedMesh = new Mesh();
    15.         InvokeRepeating("BakeNewShapeForMeshCol", 1,RateOfUpdate);
    16.         InvokeRepeating("UpdateShapeOfMeshCollider", 1.1f, RateOfUpdate);
    17.     }
    19.     void UpdateShapeOfMeshCollider() {
    21.         meshColider.sharedMesh = bakedMesh;
    22.         meshColider.sharedMesh.RecalculateBounds();
    23.         //MF.sharedMesh = bMesh;
    25.     }
    26.     void BakeNewShapeForMeshCol()
    27.     {
    28.        skinnedMeshRenderer.BakeMesh(bakedMesh);
    30.         meshFilter.mesh = bakedMesh;
    31.         meshFilter.mesh.RecalculateBounds();
    32.     }
    33. }
    Fluid Dynamic Solution Might come from uFlex
    Last edited: Jul 8, 2018
  4. pan-master


    Nov 11, 2013
    Now the Question is, Why is it so slow for bigger meshes, Are these calculations being done on CPU? I thought that this sort of Physic could be done on GPU
    Could it be possible to run additional fixedUpdate, in additional Thread to dobule the performance?
    This solution is too slow for bigger meshes