Log inGet started
World

First Light: Lavic Odyssey

Branchmain
Branchesmain
Commit1698ee71e5

README.md

kit

The small toolkit the knights slice builds every made thing out of: attaching armour to an animated bone, sizing a part in metres on a rig that is authored in centimetres, and the easing its moments run on.

local kit = require("game.knights.kit")

local sock  = kit.socket(headBone, yawDegrees, "helm_socket", { 0, 0.065, 0 })
local plate = kit.piece(sock, "plate", {
    model = "rounded_box", material = "game.knights.knight_bronze",
    pos = { 0, 0.03, 0.02 }, size = { 0.45, 0.44, 0.30 },
})
local bracer = kit.bridge(sock, "bracer", elbow.position, hand.position, {
    model = "rounded_box", material = "game.knights.knight_bronze",
    width = 0.19, thickness = 0.195, span = 0.94,
})

Why sockets

The humanoid avatar's skeleton comes from a centimetre-authored model, so every bone stands under a parent scaled by 0.01: a child of a bone with localScale 1 draws a hundredth of the size it says. And a bone's axes point along the bone, not along the world, so "10 cm above the head" written as a local offset lands somewhere different on every joint.

kit.socket answers both. It returns an empty child of the bone whose own world scale is exactly 1 and whose rotation is the character's yaw, so everything hung off it is written in plain metres in the character's own frame: +x is across, +y is up, +z is the way the pilgrim faces.

kit.bridge is the other half — a plate that spans two joints, aimed down the limb and scaled to the distance between them. It is how a bracer or a greave goes on correctly whatever pose the avatar happens to be standing in when the dressing is put on, and stays correct as the limb bends.

What is in it

CallWhat it does
worldScale(e)The scale a bone is really drawn at — the product up the chain.
socket(bone, yaw, name, offset?)A unit-scale, yaw-aligned anchor on a bone.
piece(socket, name, spec)One dressed part inside a socket, authored in metres.
bridge(socket, name, from, to, spec)A plate spanning two joints, aimed down the limb.
attach(bone, anchor, yaw, name, spec)One part straight onto a bone, no socket.
prop(parent, name, worldPos, spec)A free-standing part at a world point.
fitHeight(e, metres)Rescale anything with bounds to the height it should occupy.
eachModel(e, fn) / repaint / tintAllReach every Model in a subtree.
clamp01 / easeOut / easeInOut / lerp / nlerpQuatThe easing every moment runs on.
despawn(e)Despawn if it still exists.

spec fields are model (a primitive name or an asset identity), material, pos/size/rot in metres and degrees, and tint + tintBlend for a per-entity colour that no other entity wearing the same material sees.