Mesh.GenerateSphere

static Mesh GenerateSphere(float diameter, int subdivisions)

   
float diameter The diameter of the sphere in meters, or 2*radius. This is the full length from one side to the other.
int subdivisions How many times should the initial cube be subdivided?
RETURNS: Mesh A sphere mesh, pre-sized to the given diameter, created by sphereifying a subdivided cube! UV coordinates are taken from the initial unspherified cube.

Generates a sphere mesh, pre-sized to the given diameter, created by sphereifying a subdivided cube! UV coordinates are taken from the initial unspherified cube.

Examples

Procedural Geometry Demo Here’s a quick example of generating a mesh! You can store it in just a Mesh, or you can attach it to a Model for easier rendering later on.

Mesh  sphereMesh  = Mesh.GenerateSphere(0.4f);
Model sphereModel = Model.FromMesh(sphereMesh, Default.Material);

Drawing both a Mesh and a Model generated this way is reasonably simple, here’s a short example! For the Mesh, you’ll need to create your own material, we just loaded up the default Material here.

Matrix sphereTransform = Matrix.T(0.0f, 0, 1);
Renderer.Add(sphereMesh, Default.Material, sphereTransform);

sphereTransform = Matrix.T(0.0f, 0, -1);
Renderer.Add(sphereModel, sphereTransform);