public static Mesh generate(int triangle_budget) { Mesh original_mesh = TessellatedMesh.generate(Octahedron.octahedron_mesh(), triangle_budget, 1)[0]; Vector2[] uvs = new Vector2[original_mesh.vertices.Length]; for (int vertex = 0; vertex < original_mesh.vertices.Length; vertex += 1) { if (original_mesh.vertices[vertex] != Vector3.down) // almost every point uses polar coordinates from the underlying texture { float angle = Vector3.SignedAngle(Vector3.right, Vector3.ProjectOnPlane(original_mesh.vertices[vertex], Vector3.up).normalized, Vector3.up) * Mathf.Deg2Rad; float radius = Vector3.Angle(Vector3.up, original_mesh.vertices[vertex]) * Mathf.Deg2Rad; Vector2 uv = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); uv *= (radius / Mathf.PI); uv = uv / 2 + new Vector2(0.5f, 0.5f); uvs[vertex] = uv; } else // for points at 2PI, the four corners are identical and need to be handled separately. { if (original_mesh.uv[vertex] == Vector2.one) { uvs[vertex] = (new Vector2(+1, +1)).normalized; } else if (original_mesh.uv[vertex] == Vector2.up) { uvs[vertex] = (new Vector2(-1, +1)).normalized; } else if (original_mesh.uv[vertex] == Vector2.zero) { uvs[vertex] = (new Vector2(-1, -1)).normalized; } else //if (original_mesh.uv[vertex] == Vector2.right) { uvs[vertex] = (new Vector2(+1, -1)).normalized; } } } original_mesh.uv = uvs; return(original_mesh); }
public static Mesh generate(int triangle_budget) { return(TessellatedMesh.generate(Octahedron.octahedron_mesh(), triangle_budget, 1)[0]); }