public static Mesh ConvertToMesh(List<Triangle> triangles, string name = "TriangleMesh")
{
Mesh mesh = new Mesh();
mesh.name = name;
int[] indices = new int[triangles.Count*3];
Vector3[] positions = new Vector3[triangles.Count*3];
Vector2[] uvs = new Vector2[triangles.Count*3];
int i = 0;
foreach (var t in triangles){
for (int j=0;j<3;j++){
indices[i] = i;
positions[i] = t.points[j].ToVector3();
uvs[i] = t.uvs[j].ToVector2() ;
i++;
}
}
mesh.vertices = positions;
mesh.uv = uvs;
mesh.SetIndices(indices, MeshTopology.Triangles,0);
return mesh;
}