public static MeshNode generate_sphere(float x, float y, float z, float radius, int generations) { //cube length float length = 2 * radius / Mathf.Sqrt(3.0f); Vector3 center = new Vector3(x, y, z); //first generate cube; MeshNode head = generate_cube(x, y, z, length, length, length); for (int i = 0; i < generations; i++) { Queue <KeyValuePair <MeshNode, MeshNode> > splitQueue = new Queue <KeyValuePair <MeshNode, MeshNode> >(); sphere_recurse(center, radius, head, splitQueue); while (splitQueue.Count > 0) { KeyValuePair <MeshNode, MeshNode> n = splitQueue.Dequeue(); Vector3 position = n.Key.GetEdgeCenter(n.Value); position = center + (position - center) * Mathf.Abs(radius / ((position - center).magnitude)); n.Key.SplitEdge(n.Value, position, position - center); } head.ResetVisited(); } return(head); }