예제 #1
0
        public static Mesh DelaunayTriangulate(this PlainShape shape, IntGeom iGeom)
        {
            int n        = shape.points.Length;
            var vertices = new Vector3[n];

            for (int i = 0; i < n; ++i)
            {
                var v = iGeom.Float(shape.points[i]);
                vertices[i] = new Vector3(v.x, v.y, 0);
            }
            var extraPoints = new NativeArray <IntVector>(0, Allocator.Temp);
            var delaunay    = shape.Delaunay(0, extraPoints, Allocator.Temp);

            extraPoints.Dispose();

            var nTriangles = delaunay.Indices(Allocator.Temp);

            delaunay.Dispose();

            var mesh = new Mesh {
                vertices  = vertices,
                triangles = nTriangles.ToArray()
            };

            nTriangles.Dispose();

            return(mesh);
        }
예제 #2
0
        public static Delaunay Delaunay(this PlainShape shape, Allocator allocator)
        {
            var extraPoints = new NativeArray <IntVector>(0, Allocator.Temp);
            var delaunay    = shape.Delaunay(0, extraPoints, allocator);

            extraPoints.Dispose();
            return(delaunay);
        }
예제 #3
0
        public static List ConvexPolygons(this PlainShape self, Allocator allocator, IntGeom intGeom)
        {
            var delaunay = self.Delaunay(Allocator.Temp);
            var list     = delaunay.ConvexPolygons(intGeom, allocator);

            delaunay.Dispose();
            return(list);
        }
예제 #4
0
        public static NativeArray <int> DelaunayTriangulate(this PlainShape shape, Allocator allocator, NativeArray <IntVector> extraPoints)
        {
            var delaunay  = shape.Delaunay(0, extraPoints, allocator);
            var triangles = delaunay.Indices(allocator);

            delaunay.Dispose();

            return(triangles);
        }
예제 #5
0
        public static List MakeCentroidNet(this PlainShape self, Allocator allocator, IntGeom intGeom, float maxEdge, float maxArea = 0, float minArea = 0, bool onlyConvex = false)
        {
            long  iEdge    = intGeom.Int(maxEdge);
            var   delaunay = self.Delaunay(iEdge, Allocator.Temp);
            float aMaxArea;

            if (maxArea > 0)
            {
                aMaxArea = maxArea;
            }
            else
            {
                aMaxArea = 0.4f * maxEdge * maxEdge;
            }

            delaunay.Tessellate(intGeom, aMaxArea);

            var iMinArea = intGeom.SqrInt(minArea);
            var shape    = delaunay.MakeCentroidNet(Allocator.Temp, iMinArea, onlyConvex);

            delaunay.Dispose();

            int n           = shape.layouts.Length;
            var dynamicList = new DynamicList(8 * n, n, allocator);

            for (int i = 0; i < n; ++i)
            {
                var iPath   = shape.Get(i);
                var path    = intGeom.Float(iPath, Allocator.Temp);
                var polygon = new Polygon(path, Allocator.Temp);
                dynamicList.Add(polygon);
            }

            shape.Dispose();

            return(dynamicList.Convert());
        }