First Light: Vagant
README.md
meshkit
The geometry kit the monks and the Blight are carved with. Robes are solids of revolution with cloth wobble in them, tools are tapered tubes and hand-cut blades, the blight is faceted crystal. Nothing here is imported and nothing is a grey box.
local Kit = require("game.units.meshkit")
local b = Kit.builder()
b:revolve({
{ r = 0.46, y = 0.00, c = { 0.20, 0.17, 0.12 } }, -- the hem, in the mud
{ r = 0.32, y = 1.30, c = { 0.42, 0.55, 0.28 } }, -- the shoulder
}, 10, { wobble = 0.11, seed = 4, capBottom = true })
b:bakeFill(0, { -0.55, 0.42, -0.72 }, 0.82, 1.62)
someEntity.component.add("Model", { model = b:mesh(), material = mat })
Two ideas do most of the work
Vertex colour. The engine's pbr shader multiplies input.vertex_color into
base colour, so wear, dirt at a hem and the warm bounce up a sleeve are baked
into the geometry itself instead of costing a material per shade. A whole monk
is two materials.
Facets. Every quad emits its own four vertices carrying the face's own
normal, so a surface reads as carved planes — the illuminated-manuscript
register the game is drawn in. smooth(mark) averages coincident normals where
a rounded read is wanted (heads, orbs); crystal and blades never ask for it.
The builder
| Call | Makes |
|---|---|
b:revolve(profile, segs, opts) | a solid of revolution — robes, hoods, tanks, censers |
b:tube(path, radii, segs, colour, opts) | a swept tube — arms, shafts, hoses, chains, pipes |
b:box(cx, cy, cz, hx, hy, hz, colour) | a box with a distinct colour per face |
b:sphere(cx, cy, cz, r, colour, opts) | a sphere, squashable — heads, seed pods |
b:blade(outline, thick, colour, edge) | a flat blade with a bright cut edge |
b:shard(cx, cy, cz, r, h, colour, tip, opts) | a jagged crystal — the Blight's whole vocabulary |
b:quad(a, b, c, d, ...) / b:tri(a, b, c, ...) | the primitives underneath |
profile is a bottom-to-top list of rings, { r = radius, y = height, c = colour }.
revolve's opts carry capTop / capBottom, sx / sz (squash the circle
into an ellipse), lean (forward tilt per unit of height), smoothed,
inward (flip the winding, for the dark lining inside a hood), skip(ri, si, segs)
(leave a quad out — this is how a cowl gets a face opening) and, most usefully,
wobble: a deterministic per-segment radius variation, which is what makes
cloth read as cloth rather than as a lampshade.
The passes that make it look painted
| Call | Does |
|---|---|
b:bakeFill(from, dir, lo, hi) | a painter's fill light, carried in the vertex colours. The greenhouse's key falls almost straight down, so a robe's sides would otherwise sit in near-black. |
b:bakeGroundDirt(from, y0, y1, k) | the contact shadow and the mud a hem picks up |
b:warp(from, fn) | move everything added since a mark through a function of position — a hood pulled forward, a body leaned into a stoop |
b:smooth(from) | average coincident normals |
b:mark() | the mark the four above take |
Kit.hash / Kit.sn are deterministic noise (same seed, same shape, every
boot — a body must not shimmer between rebuilds); Kit.mix, Kit.shade and
Kit.grain are the colour helpers, and grain is the one that keeps a
flat-shaded surface from reading as plastic.
b:mesh() hands the accumulated geometry to the GPU and returns the MeshHandle
a Model component takes straight in its model field. b:tris() is the
budget check — a whole monk is 3000–5000 triangles.