private Vector3[] GenerateVertices(out Vector2[] uvs)
{
Vector3[] vertices = new Vector3[latitudeLines * longitudeLines];
Vector2[] nUVs = new Vector2[latitudeLines * longitudeLines];
int vertexIndex = 0;
for (int y = 0; y < latitudeLines; y++)
{
float latitude = Mathf.Lerp(-PI, PI, (float)y / (latitudeLines - 1));
for (int x = 0; x < longitudeLines; x++)
{
float longitude = Mathf.Lerp(-PI, PI, (float)x / (longitudeLines - 1));
Vector3 vertex = new()
{
x = Mathf.Cos(latitude) * Mathf.Cos(longitude),
y = Mathf.Cos(latitude) * Mathf.Sin(longitude),
z = Mathf.Sin(latitude),
};
Vector2 uv = new()
{
x = x / (longitudeLines - 1),
y = y / (latitudeLines - 1),
};
vertices[vertexIndex] = vertex;
nUVs[vertexIndex] = uv;
vertexIndex += 1;
}
}
uvs = nUVs;
return vertices;
}