natiny.mesh.capsule

Lua
natiny.mesh.capsule([radius [, height [, segments [, rings]]]]) -> mesh

Builds a one-part capsule standing upright along Y and centred on the origin: a cylindrical side closed by a hemisphere at each end. The generated mesh has normals and UV coordinates but no texture.

Parameters

Name Type Default Description
radius number 0.5 Radius of the side and of both hemispheres
height number radius * 4 Total height end to end, hemispheres included
segments integer 32 Meridians around Y; values below 3 are clamped
rings integer 8 Rings per hemisphere; values below 1 are clamped

Returns

Type Description
number Mesh handle

Example

Lua
local capsule = natiny.mesh.capsule(0.4, 1.8)
local player  = natiny.model.create()
natiny.model.set_mesh(player, capsule)

Notes

  • height is the whole shape, so the cylindrical side is height - 2 * radius tall and the mesh spans -height / 2 to +height / 2 along Y.
  • A height at or below 2 * radius produces a sphere: the side is clamped to zero height rather than inverted, and the band that would draw it is skipped.
  • rings counts the rings of one hemisphere, so a capsule at rings = 8 has the same cap detail as natiny.mesh.sphere at rings = 16.
  • UVs wrap once around Y in u, and v runs from the +Y pole to -Y proportionally to arc length, so a long side is not stretched against the caps. Normals point outward.
  • natiny.physics.capsule takes the same radius and height and produces a collider that lines up with this mesh.