Mesh.GenerateCylinder

static Mesh GenerateCylinder(float diameter, float depth, Vec3 direction, int subdivisions)

   
float diameter Diameter of the circular part of the cylinder in meters. Diameter is 2*radius.
float depth How tall is this cylinder, in meters?
Vec3 direction What direction do the circular surfaces face? This is the surface normal for the top, it does not need to be normalized.
int subdivisions How many vertices compose the edges of the cylinder? More is smoother, but less performant.
RETURNS: Mesh Returns a cylinder mesh, pre-sized to the given diameter and depth, UV coordinates are from a flattened top view right now.

Generates a cylinder mesh, pre-sized to the given diameter and depth, UV coordinates are from a flattened top view right now. Additional development is needed for making better UVs for the edges.

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  cylinderMesh  = Mesh.GenerateCylinder(0.4f, 0.4f, Vec3.Up);
Model cylinderModel = Model.FromMesh(cylinderMesh, 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 cylinderTransform = Matrix.T(0.5f, 0, 1);
Renderer.Add(cylinderMesh, Default.Material, cylinderTransform);

cylinderTransform = Matrix.T(0.5f, 0, -1);
Renderer.Add(cylinderModel, cylinderTransform);