Exemple #1
0
 private void LateUpdate()
 {
     if (triangulationJobHandler != null)
     {
         var shape = triangulationJobHandler.Complete(Allocator.Temp);
         this.UpdateMesh(shape);
         shape.Dispose();
         triangulationJobHandler = null;
     }
 }
Exemple #2
0
        private void UpdateShape(int n, float radius)
        {
            float da0   = 2f * Mathf.PI / n;
            float da1   = 16f * Mathf.PI / n;
            float delta = k * radius;

            var hull = new NativeArray <Vector2>(n, Allocator.Temp);

            float a0 = 0f;
            float a1 = 0f;

            for (int i = 0; i < n; ++i)
            {
                float r = radius + delta * Mathf.Sin(a1);
                float x = r * Mathf.Cos(a0);
                float y = r * Mathf.Sin(a0);
                a0     -= da0;
                a1     -= da1;
                hull[i] = new Vector2(x, y);
            }

            var hole = new NativeArray <Vector2>(n, Allocator.Temp);

            for (int i = 0; i < n; ++i)
            {
                var v = 0.5f * hull[n - i - 1];
                hole[i] = v;
            }

            switch (state)
            {
            case 0:
                triangulationJobHandler = new TriangulationJobHandler();
                triangulationJobHandler.Invoke(hull, hole, false);
                break;

            default:
                triangulationJobHandler = new TriangulationJobHandler();
                triangulationJobHandler.Invoke(hull, hole, true);
                break;
            }

            hull.Dispose();
            hole.Dispose();
        }