Log inGet started
Package

tabletopMinis.package

This package holds more than this page lists. See all of its files in its world.

README.md

Tabletop Minis

Original miniature figure looks for the units of a tactics, wargame or board game: 9 unit roles in 4 hand-modelled styles (painted fantasy figures, tin toy soldiers, woodland critters, brass clockwork automatons), each standing on its own base, recoloured to any team with a one-line scheme change, with simple procedural poses (idle bob, attack lunge, hit recoil, topple, cheer). 36 pre-baked figures, about 3,300 to 6,800 triangles and 5 to 8 draw calls each, so a full board stays cheap on a phone. Every unit type of tacticsKit maps to a figure of its own (Minis.ROLE_FOR), and any figure renders into a small head-and-shoulders portrait texture for turn order bars, unit cards and rosters (Minis.portrait). Every design is original to this package.

Install it and call one function from any module, component or scene:

local Minis = require("tabletopMinis.api")

local knight = Minis.spawn(nil, { role = "melee", style = "painted", team = 1, position = { 0, 0, 0 } })
local bulwark = Minis.spawn(nil, { role = "tank", style = "tin", team = 2, position = { 2, 0, 0 } })
Minis.pose(knight, "attack")
Minis.pose(bulwark, "hit")
print(Minis.describe("tank", "tin").name) --> Tin Bulwark

Quick start

  1. Install the package (zeromind.installAsset with its guid).
  2. local Minis = require("tabletopMinis.api").
  3. Minis.spawn(parentEntity, { role, style, team or scheme, height = 1.6 }) wherever your game creates a unit, and Minis.pose(unitEnt, "attack") when it acts.

The SkirmishDemo component (tabletopMinis.SkirmishDemo) plays a whole self-running chessboard battle so you can see everything moving: entity.spawn("Skirmish").component.add("tabletopMinis.SkirmishDemo", { styleA = "tin", styleB = "critters" }).

API

local Minis = require("tabletopMinis.api")

calldoes
Minis.ROLESmelee, ranged, healer, tank, scout, area, leader, heavy, duelist
Minis.ROLE_FORtacticsKit unit type id -> role: soldier melee, scout scout, heavy heavy, sniper ranged, medic healer, grenadier area, shield tank, commander leader, duelist duelist (add your own ids)
Minis.roleFor(unitType, fallback?)ROLE_FOR[unitType], else the id itself when it is a role, else fallback (default "melee")
Minis.STYLESpainted, tin, critters, clockwork
Minis.SCHEMESteam colour schemes by key, each { label, primary, secondary, trim } (hex colours)
Minis.SCHEME_ORDERthe scheme keys in team order
Minis.schemeFor(team)scheme key for a team index: 1 azure, 2 ember, 3 verdant, 4 amethyst, 5 gold, 6 frost, 7 onyx, 8 rose (wraps)
Minis.defineScheme(key, { primary, secondary?, trim?, label? })add or replace a scheme
Minis.spawn(parent, opts)spawns a miniature, returns its entity (see below)
Minis.setScheme(ent, schemeKeyOrColours)recolours a spawned miniature; a key or { primary, secondary, trim }
Minis.pose(ent, name, opts?)idle, attack, hit, down, cheer, rest (below)
Minis.currentPose(ent)the pose playing now
Minis.describe(role, style){ name, blurb, role, style }, an evocative unit name and one-line flavour text
Minis.info(ent){ role, style, scheme, height, figure, parts } of a spawned miniature
Minis.despawn(ent)destroys a miniature and forgets it
Minis.triangles(role, style)triangle count of one figure
Minis.portrait(role, style, scheme, opts?)renders the figure head and shoulders into a square texture once and answers its handle { guid, width, height, name }; a UI image shows it with src = handle.guid; cached per (role, style, scheme, size, background, angle) (below)
Minis.clearPortraits(role?, style?)frees cached portrait textures (all, or one role / style)

Minis.spawn(parent, opts)

optiondefaultmeaning
role"melee"one of Minis.ROLES
style"painted"one of Minis.STYLES
schemefrom teama scheme key, or a { primary, secondary, trim } colour table
team1used when scheme is not given, through Minis.schemeFor
height1.6metres from the bottom of the base to the crown of the figure's head (raised weapons and banners rise above it)
basetruefalse drops the base; the feet then stand on the entity's origin
temporarytruefalse keeps the miniature in scene saves (use in a scene's build.luau)
position, rotation, namethe returned entity's transform and name
shadowstruefalse stops the figure casting shadows

parent is an entity (or id) or nil. The returned entity's origin is the bottom centre of the base and the figure faces +Z (its right hand is on -X); turn the returned entity to face it another way, for instance rotation = { 0, 1, 0, 0 } faces -Z. Move and turn the returned entity freely; leave its figure child alone, the poses drive it. The base radius is 0.3 * height / 1.0 (0.48 m at 1.6 m tall), so height = 0.85 * cellSize fits one figure per grid square.

Poses

Minis.pose(ent, name, opts?) animates the figure by moving its transform only (no skeleton):

  • idle: a slow bob and sway, loops.
  • attack: wind-up, lunge forward, return (0.6 s), then back to idle.
  • hit: recoil backwards with a shake (0.5 s), then back to idle.
  • cheer: two hops and a full spin (1.1 s), then back to idle.
  • down: topples backwards onto the base edge and stays down.
  • rest: stands still, stops animating.

Calling the pose that is already playing does nothing, so it is safe to call every frame from a state machine. opts.restart = true replays it; opts.after = "rest" picks what a one-shot returns to; opts.t = seconds applies that single frame of the pose and does not animate (drive it from your own clock or timeline).

Multiplayer

Spawning is deterministic: the same (role, style, scheme, height, base) draws the identical miniature, with nothing random and nothing synced. Keep those values (and positions) in your game's synced state and call Minis.spawn locally on every peer, with the default temporary = true; call Minis.pose on every peer from the same synced events (a move, a hit). Nothing in this package writes synced state.

Portraits

Minis.portrait(role, style, scheme, opts?) renders one figure's head and shoulders (three-quarter view) into a square GPU texture and answers the handle { guid, width, height, name }. Show it with an image widget:

local tex = Minis.portrait("heavy", "tin", "ember")   -- a role or a tacticsKit unit type id
{ type = "image", props = { src = tex.guid }, style = { width = 96, height = 96 } }
optiondefaultmeaning
size192texture edge in pixels
background"scheme"the scheme's primary, darkened; or "transparent", a hex colour, or { r, g, b, a }
angle22camera yaw round the figure, degrees
fov24vertical field of view
team1picks the scheme through schemeFor when scheme is nil

Each (role, style, scheme, size, background, angle) renders once and is cached, so calling it from every UI rebuild is free. The handle answers at once and never changes; the picture fills in a moment later (a fraction of a second; a few seconds for a whole roster asked for at once on the web). The figure is staged far below the scene on the minis_portrait render layer with its own lights and an isolated camera; the staging waits until every mesh of the figure is on the GPU (on the web client they stream in), renders, reads the texture back and only marks the portrait ready when the picture shows the figure and two readbacks agree. A blank or still-filling picture is staged again into the same texture, so an image that already shows the guid updates by itself. Stagings run Minis.PORTRAIT_CONCURRENCY (4) at a time.

callanswers
Minis.portraitStatus(tex)"pending", "ready" or "failed" (every attempt read back blank; the next portrait call for it renders it again)
Minis.portraitReady(tex)true once the picture is verified
Minis.awaitPortrait(tex, timeout?)yields until ready (true) or failed / timed out (false, default 30 s)
Minis.portraitInfo(tex){ state, attempts, coverage, meshesResident }
Minis.portraitCoverage(tex)share of a texture's pixels that differ from its clear colour (0 for a blank render)

Minis.clearPortraits(role?, style?) frees the textures.

Unit types (tacticsKit)

unit typerolepaintedtincrittersclockwork
soldiermeleeOathbladeTin SabreurThistleback DuelistCog Reaver
scoutscoutWildrunnerTin OutriderRusset Fox PathfinderSpring Strider
heavyheavyIronhide JuggernautTin Gatling GunnerTuskbreaker BoarGatling Colossus
sniperrangedThornwood RangerTin MusketeerHollowmoon OwlBrass Arbalest
medichealerLamplight MenderTin MedicBadger HerbalistMender Automaton
grenadierareaEmberwrightTin MortarmanMole SapperKettle Mortar
shieldtankBastion WardenTin BulwarkOakheart BearBoiler Golem
commanderleaderBanner MarshalTin CaptainHare HeraldGearwright Regent
duelistduelistBladedancerTin Fencing MasterTomcat SwashbucklerMainspring Fencer

Minis.spawn(board, { role = Minis.roleFor(unit.type.id), style = "painted", team = unit.side }) gives each unit type its own figure.

Gallery: roles x styles

rolepainted (fantasy figures)tin (toy soldiers)critters (woodland folk)clockwork (brass automatons)
meleeOathblade: raised longsword, buckler, crested helmTin Sabreur: plumed shako, curved sabreThistleback Duelist: hedgehog with sword and acorn bucklerCog Reaver: buzz-saw arm, claw
rangedThornwood Ranger: hooded, drawn yew bow, quiverTin Musketeer: bearskin hat, levelled musketHollowmoon Owl: owl archer with feathered capBrass Arbalest: drum-fed repeating crossbow, antenna
healerLamplight Mender: robe, halo, crook lantern, satchelTin Medic: heart cap, lamp, bandage satchelBadger Herbalist: lantern staff, herb satchel, potionMender Automaton: halo cog, lantern staff, wrench
tankBastion Warden: great helm, tower shield, maceTin Bulwark: spiked helmet, riveted tower shieldOakheart Bear: iron half-helm, tower shield, clubBoiler Golem: smoke stacks, tower shield, piston hammer
scoutWildrunner: hood, flaring cloak, twin daggers, sprintTin Outrider: kepi, short cape, spyglassRusset Fox Pathfinder: cloak, scarf, twin knives, bushy tailSpring Strider: coil-sprung legs, antenna, scarf
areaEmberwright: pointed hat, beard, ember orb staff, fireballTin Mortarman: bomb in arms, field mortar beside himMole Sapper: goggles, bomb pack, lit bombKettle Mortar: back-mounted mortar, glowing shell
leaderBanner Marshal: plumed helm, cape, banner and swordTin Captain: bicorne, epaulettes, colours and swordHare Herald: circlet, cape, banner and swordGearwright Regent: gear crown, cape, cogwheel banner
heavyIronhide Juggernaut: horned bucket helm, fur mantle, spiked great maulTin Gatling Gunner: pickelhaube, hand-cranked rotary gun, ammo drum on the backTuskbreaker Boar: tusks, bristle crest, great wooden malletGatling Colossus: boiler pack and chimney, rotary-cannon arm, huge fist
duelistBladedancer: plumed cavalier hat, short cape, rapier lunge, parrying daggerTin Fencing Master: plumed hat, short cape, rapier lungeTomcat Swashbuckler: tuxedo cat, plumed hat, rapier lunge, curling tailMainspring Fencer: slim automaton, rapier lunge, spinning balance wheel

Bases: painted figures stand on grassy round bases with pebbles, tin soldiers on stamped green plates, critters on cut log slices with a mushroom, clockwork on brass gear plinths. Every base carries a band in the team's primary colour, so the team reads from straight above.

Schemes

keyprimarysecondarytrim
azureroyal blueparchment whitegold
embercrimsonsoot blackgold
verdantforest greenwheatbronze
amethystvioletlilacsilver
goldmarigolddark browncream
frostice bluewhitesteel
onyxcharcoalredsilver
roserose pinkblush whitegold

Primary colours tunics, shields, flags and base bands; secondary capes, hoods, plumes and emblems; trim belts, fittings, crowns and shield rims. Any colours work: Minis.setScheme(ent, { primary = "#118877", secondary = "#ffee88", trim = "#cccccc" }).

How it is built

Each figure is modelled in Luau (designs on top of the figure parts kit and the tiny geo mesh builder) and baked once by bake into mesh assets under meshes/ with vertex colours: base, baseTeam, body, primary, secondary, trim and one glow_* mesh per glow colour. The body uses one shared material per style (matte paint, glossy enamel tin, soft fur, metallic brass); the team parts use one shared white material per style tinted per entity through the Model tint, so a scheme change is a tint change and never a new material. manifest (generated) names every asset by literal, so an install carries all of them.

To change a design, edit designs.module, then run require("@root::tabletopMinis.bake").all() in the authoring world.

Contents

  • api.module: the public API above.
  • SkirmishDemo.component: self-playing chessboard skirmish (the example guide's code).
  • meshes/, materials/, manifest.module: the baked figures.
  • designs.module, figure.module, geo.module, bake.module: how the figures are modelled and baked.
  • tabletopMinisTests.testSuite: the test suite (catalogue, unit type mapping, spawning and schemes, poses, portraits).
  • docs/: guides "How to give tactics game units miniature figure looks with team colours" and "Example: a chessboard skirmish with tin soldiers vs woodland critters".

Version

1.1.1

Changelog

  • 1.1.1: portraits no longer come out blank or half-drawn on the web client. Before, the staging rendered in the figure's first frames and cached that picture forever; on the web the figure's meshes are still streaming in then (and a taken-down figure gives its buffers back, so a retry was just as cold), and a whole roster staged at once left parts out. Now each staging waits until every mesh of the figure is on the GPU, reads the texture back and marks the portrait ready only when it shows the figure and two readbacks agree, re-rendering into the same handle otherwise; stagings run four at a time. New: Minis.portraitStatus, portraitReady, awaitPortrait, portraitInfo, portraitCoverage. Docs drop the fit prop the image widget ignores. Tests cover readiness and that a blank result is never cached.
  • 1.1.0: two new roles in all four styles, heavy (a two-handed brute or heavy gunner on a wide planted stance) and duelist (a deep fencing lunge with a rapier), so there are 36 figures and every tacticsKit unit type has a silhouette of its own; Minis.ROLE_FOR and Minis.roleFor map the nine tacticsKit unit type ids to roles 1:1; Minis.portrait renders a cached head-and-shoulders portrait texture for UI images, and Minis.clearPortraits frees them; the SkirmishDemo fields heavy and duelist; a test suite (tabletopMinisTests); the demo lineup shows all 36.
  • 1.0.1: poses animate again. The pose driver was a task owned by whichever script posed first (a component's start in edit mode, an execute call), so when that script ended or entering play rebuilt the scene, the driver died while a module flag still said it was running and every miniature stayed frozen for the session; it is now a system task that the next pose restarts whenever it is no longer live, and a paused play session still freezes poses. currentPose now reads idle (or after) once a one-shot ends. The SkirmishDemo board sits 2 cm above its entity so its tiles no longer z-fight with a ground at the same height.
  • 1.0.0: first release. 7 roles x 4 styles (28 original figures), 8 team schemes plus defineScheme, spawn / setScheme / describe / pose / info / despawn, six procedural poses, baseless spawning, the SkirmishDemo component and two guides.