Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Manual convert MeshCollider to Unity.Physics.ConvexCollider?

Discussion in 'Physics for ECS' started by Guedez, Aug 13, 2021.

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    This is clearly not working. R̶a̶y̶c̶a̶s̶t̶ ̶a̶l̶w̶a̶y̶s̶ ̶m̶i̶s̶s̶e̶s̶ ̶t̶o̶o (Edit: Raycast was missing the filter field). It also seems to be leaking memory without complaining about leaking. The BlobAssetReference is disposed on OnDestroy, but my UnityEditor is using more and more and more memory each time I enter playmode even since I started testing with the Unity.Physics package.
    upload_2021-8-13_15-18-20.png

    Generation code:
    Code (CSharp):
    1.     private BlobAssetReference<Unity.Physics.Collider> Convert(UnityEngine.MeshCollider t, int i, ref Bounds[] BoundsArray) {
    2.         Vector3[] points = t.sharedMesh.vertices;
    3.         Matrix4x4 mat = t.transform.localToWorldMatrix;
    4.         HashSet<float3> hash = new HashSet<float3>();
    5.         for (int j = 0; j < points.Length; j++) {
    6.             points[j] = ((float4)(mat * new Vector4(points[j].x, points[j].y, points[j].z, 1))).xyz;
    7.             hash.Add(points[j]);
    8.         }
    9.         NativeArray<float3> vpoints = new NativeArray<float3>(hash.ToArray(), Allocator.Temp);
    10.         BlobAssetReference<Unity.Physics.Collider> Collider = ConvexCollider.Create(vpoints, ConvexHullGenerationParameters.Default);
    11.         BoundsArray[i] = ToBounds(vpoints);
    12.         vpoints.Dispose();
    13.         return Collider;
    14.     }
     
    Last edited: Aug 13, 2021