public static void AddPolygon(this IMeshBuilder meshBuilder, Vector2[] poly) { Triangulator triangulator = new Triangulator(poly); int[] tris = triangulator.Triangulate(); for (int i = 0; i < poly.Length; i++) { var v = new Vector3(poly[i].x, 0f, poly[i].y); meshBuilder.AddVertex(v); meshBuilder.UVs.Add(new Vector2(v.x, v.z)); } meshBuilder.SetTriangles(tris); }
public static void SplitVertices(this IMeshBuilder meshBuilder) { var triangles = meshBuilder.Indices.ToArray(); meshBuilder.Normals.Clear(); meshBuilder.UVs.Clear(); meshBuilder.Colors.Clear(); var vertices = new Vector3[triangles.Length]; for (int i = 0; i < triangles.Length; i++) { vertices[i] = meshBuilder.Vertices[triangles[i]]; triangles[i] = i; } meshBuilder.SetVertices(vertices); meshBuilder.SetTriangles(triangles); }