static Mesh GenerateRoundedCube(Vec3 dimensions, float edgeRadius, int subdivisions)

Vec3 dimensions How large is this cube on each axis, in meters?
float edgeRadius Radius of the corner rounding, in meters.
int subdivisions How many subdivisions should be used for creating the corners? A larger value results in smoother corners, but can decrease performance.
RETURNS: Mesh A cube mesh with rounded corners, pre-sized to the given dimensions.

Generates a cube mesh with rounded corners, pre-sized to the given dimensions. UV coordinates are 0,0 -> 1,1 on each face, meeting at the middle of the rounded corners.


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  roundedCubeMesh  = Mesh.GenerateRoundedCube(Vec3.One * 0.4f, 0.05f);
Model roundedCubeModel = Model.FromMesh(roundedCubeMesh, 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 roundedCubeTransform = Matrix.T(-0.5f, 0, 1);
Renderer.Add(roundedCubeMesh, Default.Material, roundedCubeTransform);

roundedCubeTransform = Matrix.T(-0.5f, 0, -1);
Renderer.Add(roundedCubeModel, roundedCubeTransform);