diff --git a/media/kit.png b/media/kit.png index 415fc84..1c8047b 100644 Binary files a/media/kit.png and b/media/kit.png differ diff --git a/models.lock.json b/models.lock.json index b52eacd..9c8b910 100644 --- a/models.lock.json +++ b/models.lock.json @@ -67,7 +67,7 @@ "address": "@medieval-kit/wooden-barrel", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.689Z", + "installedAt": "2026-08-23T07:55:04.538Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-barrel\\model.ts", @@ -82,7 +82,7 @@ "address": "@medieval-kit/core", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.667Z", + "installedAt": "2026-08-23T07:55:04.505Z", "files": [ { "path": "src\\models\\medieval-kit\\core\\geometry.ts", @@ -129,7 +129,7 @@ "address": "@medieval-kit/wooden-crate", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.694Z", + "installedAt": "2026-08-23T07:55:04.544Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-crate\\model.ts", @@ -144,7 +144,7 @@ "address": "@medieval-kit/kit", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.700Z", + "installedAt": "2026-08-23T07:55:04.553Z", "files": [], "dependencies": [] }, @@ -152,7 +152,7 @@ "address": "@medieval-kit/iron-anvil", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.675Z", + "installedAt": "2026-08-23T07:55:04.517Z", "files": [ { "path": "src\\models\\medieval-kit\\iron-anvil\\model.ts", @@ -167,7 +167,7 @@ "address": "@medieval-kit/wooden-bucket", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.692Z", + "installedAt": "2026-08-23T07:55:04.541Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-bucket\\model.ts", @@ -182,7 +182,7 @@ "address": "@medieval-kit/wooden-fence", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.695Z", + "installedAt": "2026-08-23T07:55:04.545Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-fence\\model.ts", @@ -197,7 +197,7 @@ "address": "@medieval-kit/wooden-hoe", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.696Z", + "installedAt": "2026-08-23T07:55:04.547Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-hoe\\model.ts", @@ -212,7 +212,7 @@ "address": "@medieval-kit/wooden-ladder", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.697Z", + "installedAt": "2026-08-23T07:55:04.548Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-ladder\\model.ts", @@ -227,7 +227,7 @@ "address": "@medieval-kit/wooden-pitchfork", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.698Z", + "installedAt": "2026-08-23T07:55:04.550Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-pitchfork\\model.ts", @@ -242,7 +242,7 @@ "address": "@medieval-kit/wooden-shovel", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.699Z", + "installedAt": "2026-08-23T07:55:04.551Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-shovel\\model.ts", @@ -257,7 +257,7 @@ "address": "@medieval-kit/wooden-stool", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.700Z", + "installedAt": "2026-08-23T07:55:04.553Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-stool\\model.ts", @@ -272,7 +272,7 @@ "address": "@medieval-kit/cart-wheel", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.671Z", + "installedAt": "2026-08-23T07:55:04.509Z", "files": [ { "path": "src\\models\\medieval-kit\\cart-wheel\\model.ts", @@ -287,7 +287,7 @@ "address": "@medieval-kit/log-pile", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.679Z", + "installedAt": "2026-08-23T07:55:04.524Z", "files": [ { "path": "src\\models\\medieval-kit\\log-pile\\model.ts", @@ -302,7 +302,7 @@ "address": "@medieval-kit/trestle-table", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.687Z", + "installedAt": "2026-08-23T07:55:04.535Z", "files": [ { "path": "src\\models\\medieval-kit\\trestle-table\\model.ts", @@ -317,7 +317,7 @@ "address": "@medieval-kit/wooden-chest", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.693Z", + "installedAt": "2026-08-23T07:55:04.542Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-chest\\model.ts", @@ -332,7 +332,7 @@ "address": "@medieval-kit/hay-bale", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.674Z", + "installedAt": "2026-08-23T07:55:04.515Z", "files": [ { "path": "src\\models\\medieval-kit\\hay-bale\\model.ts", @@ -347,7 +347,7 @@ "address": "@medieval-kit/pitch-torch", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.682Z", + "installedAt": "2026-08-23T07:55:04.527Z", "files": [ { "path": "src\\models\\medieval-kit\\pitch-torch\\model.ts", @@ -362,7 +362,7 @@ "address": "@medieval-kit/wooden-bench", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.690Z", + "installedAt": "2026-08-23T07:55:04.539Z", "files": [ { "path": "src\\models\\medieval-kit\\wooden-bench\\model.ts", @@ -377,7 +377,7 @@ "address": "@medieval-kit/linen-sack", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.678Z", + "installedAt": "2026-08-23T07:55:04.523Z", "files": [ { "path": "src\\models\\medieval-kit\\linen-sack\\model.ts", @@ -392,7 +392,7 @@ "address": "@medieval-kit/oak-tankard", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.680Z", + "installedAt": "2026-08-23T07:55:04.525Z", "files": [ { "path": "src\\models\\medieval-kit\\oak-tankard\\model.ts", @@ -407,7 +407,7 @@ "address": "@medieval-kit/straw-broom", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.685Z", + "installedAt": "2026-08-23T07:55:04.532Z", "files": [ { "path": "src\\models\\medieval-kit\\straw-broom\\model.ts", @@ -422,7 +422,7 @@ "address": "@medieval-kit/bronze-bell", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.670Z", + "installedAt": "2026-08-23T07:55:04.507Z", "files": [ { "path": "src\\models\\medieval-kit\\bronze-bell\\model.ts", @@ -437,7 +437,7 @@ "address": "@medieval-kit/iron-lantern", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.676Z", + "installedAt": "2026-08-23T07:55:04.519Z", "files": [ { "path": "src\\models\\medieval-kit\\iron-lantern\\model.ts", @@ -452,7 +452,7 @@ "address": "@medieval-kit/tavern-sign", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.686Z", + "installedAt": "2026-08-23T07:55:04.533Z", "files": [ { "path": "src\\models\\medieval-kit\\tavern-sign\\model.ts", @@ -467,7 +467,7 @@ "address": "@medieval-kit/coin-pouch", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.672Z", + "installedAt": "2026-08-23T07:55:04.510Z", "files": [ { "path": "src\\models\\medieval-kit\\coin-pouch\\model.ts", @@ -482,7 +482,7 @@ "address": "@medieval-kit/glass-phial", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.673Z", + "installedAt": "2026-08-23T07:55:04.512Z", "files": [ { "path": "src\\models\\medieval-kit\\glass-phial\\model.ts", @@ -497,7 +497,7 @@ "address": "@medieval-kit/leather-book", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.677Z", + "installedAt": "2026-08-23T07:55:04.521Z", "files": [ { "path": "src\\models\\medieval-kit\\leather-book\\model.ts", @@ -512,7 +512,7 @@ "address": "@medieval-kit/wicker-basket", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.688Z", + "installedAt": "2026-08-23T07:55:04.536Z", "files": [ { "path": "src\\models\\medieval-kit\\wicker-basket\\model.ts", @@ -527,11 +527,11 @@ "address": "@medieval-kit/post-mill", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.683Z", + "installedAt": "2026-08-23T07:55:04.528Z", "files": [ { "path": "src\\models\\medieval-kit\\post-mill\\model.ts", - "sourceHash": "b6cc30f2332c600739147783cdbd7d0c1a59379bd02fac1cec61e08278da1ed9" + "sourceHash": "226b2b20aaf8c98b5570d799d4d739a731cdd771a5d9ad9cc6fe0dff35dfb01f" } ], "dependencies": [ @@ -542,7 +542,7 @@ "address": "@medieval-kit/stone-well", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T07:16:33.684Z", + "installedAt": "2026-08-23T07:55:04.530Z", "files": [ { "path": "src\\models\\medieval-kit\\stone-well\\model.ts", @@ -552,6 +552,36 @@ "dependencies": [ "three@>=0.185.0" ] + }, + "@medieval-kit/hand-cart": { + "address": "@medieval-kit/hand-cart", + "source": "file:my-registry/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-23T07:55:04.514Z", + "files": [ + { + "path": "src\\models\\medieval-kit\\hand-cart\\model.ts", + "sourceHash": "40d4ad99efecc86f186885ac84cf0f4bbf87a3609b1e4501ffc943feb8e1c08f" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] + }, + "@medieval-kit/iron-cauldron": { + "address": "@medieval-kit/iron-cauldron", + "source": "file:my-registry/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-23T07:55:04.518Z", + "files": [ + { + "path": "src\\models\\medieval-kit\\iron-cauldron\\model.ts", + "sourceHash": "0311aa3190cd1be0b1d7e7a3a337e04dcb10081558054580cb85d83e800ffb0c" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] } } } diff --git a/my-registry/README.md b/my-registry/README.md index a24c757..ac46ebb 100644 --- a/my-registry/README.md +++ b/my-registry/README.md @@ -26,7 +26,7 @@ Configure `models.json` first so the namespace resolves: ## Models -29 models and one shared lib. Addresses are `@medieval-kit/`. This table is +31 models and one shared lib. Addresses are `@medieval-kit/`. This table is generated from the models themselves with `bun scripts/catalog-table.ts` — a hand-written list goes stale on the first model you add, and this one already did once. @@ -60,10 +60,12 @@ did once. | `wooden-hoe` | Tools | 394 | 3 | 0.23×1.23×0.33 | oak, iron, steel | | | `wooden-shovel` | Tools | 496 | 3 | 0.27×1.20×0.08 | oak, iron | | | `wooden-pitchfork` | Tools | 392 | 3 | 0.27×1.58×0.15 | oak, iron | | +| `iron-cauldron` | Lighting | 1134 | 3 | 1.09×1.37×1.10 | stone, iron, char, ember | | +| `hand-cart` | Structure | 2044 | 4 | 0.88×1.03×2.60 | oak, iron | | | `stone-well` | Structure | 1376 | 4 | 1.88×2.00×1.28 | stone, oak, iron, cloth | | | `post-mill` | Structure | 1672 | 4 | 6.60×7.23×6.98 | oak, iron | | -**22 043 triangles** in total. The whole kit in one scene costs less than a +**25 221 triangles** in total. The whole kit in one scene costs less than a single mid-complexity character model. Every model depends on `@medieval-kit/core`, a shared support item holding the diff --git a/my-registry/meta.ts b/my-registry/meta.ts index 4cc4988..1de7d75 100644 --- a/my-registry/meta.ts +++ b/my-registry/meta.ts @@ -450,6 +450,43 @@ export const MODEL_META: Readonly> = { materialSlots: ['oak'], parts: ['rails', 'rungs'], }, + 'iron-cauldron': { + title: 'Iron Cauldron', + description: + 'Cauldron slung from an iron tripod over a ring of hearth stones, with embers that can be lit or put out.', + category: 'Lighting', + tags: ['medieval', 'lowpoly', 'hearth', 'procedural'], + controls: { + height: { type: 'number', label: 'Tripod height', min: 0.8, max: 2, step: 0.02, unit: 'm' }, + hearthRadius: { type: 'number', label: 'Hearth radius', min: 0.28, max: 0.8, step: 0.01, unit: 'm' }, + stones: { type: 'number', label: 'Hearth stones', min: 6, max: 20, step: 1 }, + potRadius: { type: 'number', label: 'Cauldron radius', min: 0.12, max: 0.36, step: 0.01, unit: 'm' }, + links: { type: 'number', label: 'Chain links', min: 2, max: 8, step: 1 }, + lit: { type: 'number', label: 'Lit', min: 0, max: 1, step: 1 }, + seed: { type: 'number', label: 'Variation seed', min: 1, max: 64, step: 1 }, + }, + materialSlots: ['stone', 'iron', 'char', 'ember'], + parts: ['hearth', 'tripod', 'pot'], + }, + 'hand-cart': { + title: 'Hand Cart', + description: + 'Two-wheeled handcart: planked body on an axle set aft of centre, with shafts that rest on the ground.', + category: 'Structure', + tags: ['medieval', 'lowpoly', 'structure', 'procedural'], + controls: { + bedLength: { type: 'number', label: 'Bed length', min: 0.8, max: 2.1, step: 0.02, unit: 'm' }, + bedWidth: { type: 'number', label: 'Bed width', min: 0.4, max: 1.1, step: 0.02, unit: 'm' }, + sideHeight: { type: 'number', label: 'Side height', min: 0.1, max: 0.5, step: 0.01, unit: 'm' }, + wheelRadius: { type: 'number', label: 'Wheel radius', min: 0.18, max: 0.5, step: 0.01, unit: 'm' }, + spokes: { type: 'number', label: 'Spokes', min: 6, max: 14, step: 1 }, + shaftLength: { type: 'number', label: 'Shaft length', min: 0.6, max: 1.8, step: 0.02, unit: 'm' }, + roll: { type: 'number', label: 'Wheel rotation', min: 0, max: 6.28, step: 0.02, unit: 'rad' }, + seed: { type: 'number', label: 'Variation seed', min: 1, max: 64, step: 1 }, + }, + materialSlots: ['oak', 'iron'], + parts: ['wheels', 'bed', 'sides', 'shafts'], + }, 'stone-well': { title: 'Stone Well', description: diff --git a/my-registry/models/hand-cart/model.ts b/my-registry/models/hand-cart/model.ts new file mode 100644 index 0000000..ca421ca --- /dev/null +++ b/my-registry/models/hand-cart/model.ts @@ -0,0 +1,342 @@ +/** + * @medieval-kit/hand-cart + * + * A two-wheeled handcart: a planked body on an axle, with two shafts to pull + * it by. + * + * The kit already had `cart-wheel` and nothing to put it on. That is the gap + * this fills, and it fills a second one at the same time: every container in + * the catalogue — crates, sacks, barrels, baskets — is a thing you would + * MOVE, and there was no way to move any of it. + * + * Two details carry the whole design, and both are about where the axle is: + * + * - It sits BEHIND the middle of the bed, not under it. A handcart is + * balanced so that a loaded body rests a little weight on the puller's + * hands rather than trying to tip backwards out of them, and the wheels go + * aft of centre to do it. + * - The shafts slope DOWN from the bed's front and rest on the ground when + * the cart is parked. That is not the cart tipping: the bed stays level + * and the shafts leave it at an angle, which is what lets one person pick + * them up to waist height without the load shifting. + * + * Parts: `wheels` (the pair and their axle, with its own origin at the axle so + * `setRoll` turns them in place), `bed`, `sides` and `shafts`. + */ +import { Color, type BufferGeometry } from 'three' + +import { + bandGeometry, + boxGeometry, + chamferedBoxGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + taperedBoxGeometry, + type Level, +} from '../core/index.ts' + +export interface HandCartConfig { + /** Length of the cart's bed (metres). */ + readonly bedLength: number + /** Width of the bed (metres). */ + readonly bedWidth: number + /** Height of the side boards above the bed (metres). */ + readonly sideHeight: number + /** Wheel radius (metres). */ + readonly wheelRadius: number + /** Spokes in each wheel. */ + readonly spokes: number + /** Length of the shafts beyond the bed (metres). */ + readonly shaftLength: number + /** Wheel rotation (radians). */ + readonly roll: number + readonly seed: number +} + +export const handCartDefaults: HandCartConfig = { + bedLength: 1.34, + bedWidth: 0.66, + sideHeight: 0.28, + wheelRadius: 0.33, + spokes: 10, + shaftLength: 1.15, + roll: 0, + seed: 61, +} + +export type HandCartParts = 'wheels' | 'bed' | 'sides' | 'shafts' + +export interface HandCartActions { + /** Turns the wheels. */ + setRoll(radians: number): void + roll(): number +} + +export function createModel(overrides: Partial = {}) { + let roll = 0 + + return createKitModel({ + id: 'hand-cart', + defaults: handCartDefaults, + slots: ['oak', 'iron'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const L = config.bedLength + const W = config.bedWidth + const wheelR = config.wheelRadius + const plank = W * 0.035 + + // Ground at y = 0: this model rests on its wheels and its shaft tips, and + // building from the floor up keeps all three of those at one datum. + const axleY = wheelR + const bedY = axleY + plank * 2.6 + // Aft of centre, so a load leans on the puller rather than away from him. + const axleZ = L * 0.16 + + // --- Wheels and axle ------------------------------------------------------ + const spokes = Math.max(6, Math.round(config.spokes)) + const felloeOuter = wheelR * 0.9 + const felloeInner = felloeOuter * 0.8 + const hubR = wheelR * 0.19 + const wheelX = W / 2 + plank * 2.2 + const wheelBody: BufferGeometry[] = [] + const wheelIron: BufferGeometry[] = [] + + for (const side of [-1, 1]) { + const parts: BufferGeometry[] = [] + // Hub, turned and belled at both ends the way a nave is. + parts.push(latheGeometry( + [ + { y: -wheelR * 0.16, radius: hubR * 0.72 }, + { y: -wheelR * 0.1, radius: hubR }, + { y: wheelR * 0.1, radius: hubR }, + { y: wheelR * 0.16, radius: hubR * 0.72 }, + ] as Level[], + 9, [0, 0, 0], tint('oak', -0.02, 1.1), + )) + // Spokes. Each reaches INTO the hub at one end and INTO the felloe at + // the other, so both joints are overlaps rather than faces meeting. + const spokeInner = hubR * 0.5 + const spokeLength = felloeInner - spokeInner + wheelR * 0.06 + for (let i = 0; i < spokes; i += 1) { + const a = (i / spokes) * Math.PI * 2 + const spoke = taperedBoxGeometry( + [wheelR * 0.075, wheelR * 0.055], + [wheelR * 0.058, wheelR * 0.045], + spokeLength, + [0, spokeLength / 2 + spokeInner, 0], + tint('oak', jitter(random, 0.05)), + ) + spoke.rotateZ(a + jitter(random, 0.012)) + parts.push(spoke) + } + // Felloe: separate segments, because a wheel rim is built from arcs of + // timber and a turned ring reads as a hoop. + for (let i = 0; i < spokes; i += 1) { + const a = ((i + 0.5) / spokes) * Math.PI * 2 + const mid = (felloeOuter + felloeInner) / 2 + const arc = (Math.PI * 2 * mid) / spokes + const seg = taperedBoxGeometry( + [arc * 1.06, felloeOuter - felloeInner], + [arc * 1.02, (felloeOuter - felloeInner) * 0.96], + wheelR * 0.14 * (1 + jitter(random, 0.05)), + [0, 0, 0], + tint('oak', -0.05 + jitter(random, 0.05)), + ) + // Built lying flat with its height along Y; standing it on edge and + // then swinging it round puts its thickness across the wheel. + seg.rotateX(Math.PI / 2) + seg.rotateZ(a) + seg.translate(Math.cos(a) * mid, Math.sin(a) * mid, 0) + parts.push(seg) + } + const wheel = mergeColoured(parts) + wheel.rotateY(Math.PI / 2) + wheel.translate(side * wheelX, axleY, axleZ) + wheelBody.push(wheel) + + // Iron tyre, set INTO the tread and narrower than the felloe, the same + // way the cart wheel's is: anything within the felloe's own thickness + // will sooner or later share a plane with one of its segments. + const tyre = bandGeometry( + wheelR, 0, wheelR * 0.115, wheelR * 0.1, spokes * 2, + tint('iron', jitter(random, 0.04), 0.7), { inner: true }, + ) + tyre.rotateZ(Math.PI / 2) + tyre.translate(side * wheelX, axleY, axleZ) + wheelIron.push(tyre) + } + + // Axle: through both hubs, so the pair is one object. + const axle = taperedBoxGeometry( + [hubR * 0.8, hubR * 0.8], + [hubR * 0.8, hubR * 0.8], + wheelX * 2 + hubR, + [0, 0, 0], + tint('oak', -0.1), + ) + axle.rotateZ(Math.PI / 2) + axle.translate(0, axleY, axleZ) + wheelBody.push(axle) + + // --- Bed ------------------------------------------------------------------ + const floorBoards: BufferGeometry[] = [] + const boards = 5 + for (let i = 0; i < boards; i += 1) { + const w = W / boards + floorBoards.push(chamferedBoxGeometry( + [w * 0.97, L], + [w * 0.95, L * 0.998], + plank, + plank * 0.14, + [(i + 0.5) * w - W / 2, bedY, 0], + tint('oak', 0.03 + jitter(random, 0.05)), + )) + } + // Cross bearers under the boards, and the axle bed they sit on. + for (const at of [-0.36, 0, 0.36]) { + floorBoards.push(chamferedBoxGeometry( + [W * 1.02, L * 0.07], + [W * 0.99, L * 0.06], + plank * 1.5, + plank * 0.12, + [0, bedY - plank * 1.2, at * L], + tint('oak', -0.08), + )) + } + floorBoards.push(chamferedBoxGeometry( + [wheelX * 2 - hubR, L * 0.1], + [wheelX * 2 - hubR * 1.6, L * 0.09], + plank * 1.8, + plank * 0.12, + [0, bedY - plank * 2.3, axleZ], + tint('oak', -0.12), + )) + + // --- Sides ---------------------------------------------------------------- + const walls: BufferGeometry[] = [] + const iron: BufferGeometry[] = [] + const sideH = config.sideHeight + + for (const side of [-1, 1]) { + // Two boards to a side, with a gap between them: a cart side is + // planked, not panelled, and the gap is what says so. + for (const [row, at] of [[0, 0.27], [1, 0.74]] as const) { + walls.push(chamferedBoxGeometry( + [plank, L * 0.99], + [plank * 0.94, L * 0.985], + sideH * 0.42, + plank * 0.16, + [side * (W / 2 + plank * 0.5), bedY + sideH * at, 0], + tint('oak', (row === 0 ? -0.02 : 0.04) + jitter(random, 0.05)), + )) + } + // Corner and middle stakes: the uprights the boards are nailed to. + for (const at of [-0.46, 0, 0.46]) { + walls.push(chamferedBoxGeometry( + [plank * 1.4, L * 0.055], + [plank * 1.2, L * 0.05], + sideH * 1.08, + plank * 0.16, + [side * (W / 2 + plank * 1.1), bedY + sideH * 0.5, at * L], + tint('oak', -0.05), + )) + } + } + // End boards, front and back. + for (const end of [-1, 1]) { + walls.push(chamferedBoxGeometry( + [W + plank * 2.2, plank], + [W + plank * 1.9, plank * 0.94], + sideH * 0.92, + plank * 0.16, + [0, bedY + sideH * 0.5, end * (L / 2 - plank * 0.5)], + tint('oak', -0.01 + jitter(random, 0.04)), + )) + } + + // --- Shafts --------------------------------------------------------------- + // They leave the bed's front and slope down to the ground. The angle is + // DERIVED from where they have to end, not chosen: a shaft that stops + // short hangs in the air and one that goes long pushes the cart over. + const shafts: BufferGeometry[] = [] + const rootY = bedY - plank * 1.2 + const rootZ = -L / 2 + const shaftDrop = rootY + const reach = config.shaftLength + const lean = Math.atan2(shaftDrop, reach) + const shaftLength = Math.hypot(shaftDrop, reach) + const shaftX = W / 2 - plank * 1.6 + + for (const side of [-1, 1]) { + const shaft = latheGeometry( + [ + { y: -shaftLength / 2, radius: plank * 0.62 }, + { y: -shaftLength * 0.42, radius: plank * 0.72 }, + { y: shaftLength * 0.36, radius: plank * 0.86 }, + { y: shaftLength / 2, radius: plank * 0.95 }, + ] as Level[], + 7, [0, 0, 0], tint('oak', 0.02 + jitter(random, 0.05), 1.1), + ) + // Built upright; leaning it about X drops its lower end forward, and + // the 4% overrun at the top buries its head in the cart's frame. + shaft.rotateX(Math.PI / 2 - lean) + shaft.translate( + side * shaftX, + rootY - shaftDrop / 2, + rootZ - reach / 2, + ) + shafts.push(shaft) + + // The strap that holds the shaft to the frame. It is the only reason + // the two are joined at all. + iron.push(boxGeometry( + [plank * 2.4, plank * 0.5, L * 0.09], + [side * shaftX, rootY + plank * 0.5, rootZ + L * 0.03], + new Color(tint('iron', 0.02, 0.7)), + )) + } + // Cross handle between the shaft tips, so the cart can be pulled by one + // person with both hands. + shafts.push(latheGeometry( + [ + { y: -shaftX - plank, radius: plank * 0.6 }, + { y: shaftX + plank, radius: plank * 0.6 }, + ] as Level[], + 7, [0, 0, 0], tint('oak', 0.06, 1.1), + ).rotateZ(Math.PI / 2).translate(0, plank * 0.62, rootZ - reach * 0.88)) + + return { + wheels: { + slot: 'oak' as const, + geometry: mergeColoured(wheelBody), + extras: [{ slot: 'iron' as const, geometry: mergeColoured(wheelIron) }], + origin: [0, axleY, axleZ] as const, + }, + bed: { slot: 'oak' as const, geometry: mergeColoured(floorBoards) }, + sides: { + slot: 'oak' as const, + geometry: mergeColoured(walls), + extras: [{ slot: 'iron' as const, geometry: mergeColoured(iron) }], + }, + shafts: { slot: 'oak' as const, geometry: mergeColoured(shafts) }, + } + }, + + actions: ({ parts, getConfig }) => { + roll = getConfig().roll + parts.wheels.anchor.rotation.x = roll + return { + setRoll: (radians) => { + roll = radians + parts.wheels.anchor.rotation.x = roll + }, + roll: () => roll, + } + }, + }, overrides) +} diff --git a/my-registry/models/iron-cauldron/model.ts b/my-registry/models/iron-cauldron/model.ts new file mode 100644 index 0000000..ad8f11d --- /dev/null +++ b/my-registry/models/iron-cauldron/model.ts @@ -0,0 +1,334 @@ +/** + * @medieval-kit/iron-cauldron + * + * A cauldron slung from a tripod over a ring of hearth stones. + * + * The kit had two light sources — a torch and a lantern — and no HEARTH, which + * is the wrong way round for a medieval catalogue. A cooking fire is where + * everyone in the scene is facing, and it is the only light in most of them. + * + * Three things about the shape are worth stating because they are what make it + * read as a cauldron rather than as a pot: + * + * - The belly is WIDER than the mouth. A cauldron is bulbous, so that its + * contents sit over the fire rather than beside it, and so that the walls + * take the heat evenly. Straight-sided, it is a bucket. + * - It has three short feet. It spends as much time standing in the ashes as + * hanging over them, and a round-bottomed pot cannot stand at all. + * - It hangs by a BAIL — a semicircular loop pinned to two lugs — and not by + * the rim. The bail is what the chain grips, and it swings, which is how a + * cauldron is taken off the fire without touching it. + * + * Parts: `hearth` (the stone ring and its bed of embers), `tripod`, and `pot` + * (the cauldron with its bail and the chain it hangs on). The chain belongs to + * the pot rather than to the tripod because it moves with what it carries. + */ +import { type BufferGeometry } from 'three' + +import { + arcBarGeometry, + bandGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + prismGeometry, + roughenGeometry, + taperedBoxGeometry, + type Level, +} from '../core/index.ts' + +export interface IronCauldronConfig { + /** Height from the ground to the tripod's apex (metres). */ + readonly height: number + /** Outer radius of the ring of hearth stones (metres). */ + readonly hearthRadius: number + /** Stones in the ring. */ + readonly stones: number + /** Radius of the cauldron at its belly (metres). */ + readonly potRadius: number + /** Links in the chain. */ + readonly links: number + /** Whether the fire is lit (0/1). */ + readonly lit: number + readonly seed: number +} + +export const ironCauldronDefaults: IronCauldronConfig = { + height: 1.28, + hearthRadius: 0.46, + stones: 12, + potRadius: 0.22, + links: 4, + lit: 1, + seed: 29, +} + +export type IronCauldronParts = 'hearth' | 'tripod' | 'pot' + +export interface IronCauldronActions { + /** Lights or puts out the fire. When out, the embers are hidden. */ + setLit(on: boolean): void + isLit(): boolean +} + +export function createModel(overrides: Partial = {}) { + let lit = true + + return createKitModel({ + id: 'iron-cauldron', + defaults: ironCauldronDefaults, + slots: ['stone', 'iron', 'char', 'ember'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = config.height + const floor = -H / 2 + const hearthR = config.hearthRadius + + // --- Hearth ------------------------------------------------------------- + const stones: BufferGeometry[] = [] + const count = Math.max(5, Math.round(config.stones)) + const stoneH = hearthR * 0.32 + const ringR = hearthR - stoneH * 0.5 + + for (let i = 0; i < count; i += 1) { + const a = (i / count) * Math.PI * 2 + jitter(random, 0.05) + const arc = (Math.PI * 2 * ringR) / count + // Cut long, like the well's kerb: a flat-faced block on a curve cannot + // close its joint otherwise, and a fire ring with daylight through it + // is not a fire ring. + const stone = taperedBoxGeometry( + [arc * (1.06 + jitter(random, 0.08)), stoneH * (1 + jitter(random, 0.1))], + [arc * (0.78 + jitter(random, 0.1)), stoneH * (0.72 + jitter(random, 0.12))], + stoneH * (0.86 + jitter(random, 0.14)), + [0, 0, 0], + tint('stone', jitter(random, 0.1)), + ) + stone.rotateY(a) + stone.translate( + Math.sin(a) * ringR, + floor + stoneH * 0.4, + Math.cos(a) * ringR, + ) + stones.push(stone) + } + const hearth = mergeColoured(stones) + roughenGeometry(hearth, stoneH * 0.08, { salt: 19 }) + + // Ash bed inside the ring, and the embers on it. The bed is char and the + // embers sit slightly proud of it; separating them is what lets the fire + // be put out without the ashes going with it. + const ashR = ringR - stoneH * 0.42 + const ash = latheGeometry( + [ + { y: floor + hearthR * 0.005, radius: ashR }, + { y: floor + hearthR * 0.055, radius: ashR * 0.9 }, + ] as Level[], + 11, [0, 0, 0], tint('char', 0.04), + ) + + const emberPieces: BufferGeometry[] = [] + const emberCount = Math.max(4, Math.round(count * 0.7)) + for (let i = 0; i < emberCount; i += 1) { + const a = i * 2.399963 + const r = ashR * 0.72 * Math.sqrt((i + 0.4) / emberCount) + const size = hearthR * (0.05 + random() * 0.045) + const coal = prismGeometry( + size, size * 0.6, size * 0.7, 5, [0, 0, 0], + tint(i % 3 === 0 ? 'emberTip' : 'ember', jitter(random, 0.05), 0.4), + ) + coal.rotateY(random() * Math.PI * 2) + coal.translate( + Math.sin(a) * r, + floor + hearthR * 0.06, + Math.cos(a) * r, + ) + emberPieces.push(coal) + } + + // --- Tripod ------------------------------------------------------------- + const apexY = floor + H + const iron: BufferGeometry[] = [] + const legFoot = hearthR * 1.34 + const legRise = apexY - floor + const legLength = Math.hypot(legFoot, legRise) + const barT = hearthR * 0.045 + + for (let i = 0; i < 3; i += 1) { + // Three legs, not four. A tripod cannot rock: whatever the ground does, + // three feet are always on it, which is why every cooking fire in + // Europe stood on one. + const a = (i / 3) * Math.PI * 2 + 0.4 + const leg = taperedBoxGeometry( + [barT * 1.15, barT * 1.15], + [barT * 0.8, barT * 0.8], + legLength * 1.02, + [0, 0, 0], + tint('iron', -0.02 + jitter(random, 0.04), 0.7), + ) + // NEGATIVE. `rotateX(+t)` carries the bar's TOP towards +Z, and the + // translate that follows also moves it +Z, so the two add: the head + // ends up at the full outboard radius and the foot at the axis. The + // brace stands on its head, splayed at the top and gathered at the + // bottom, which is the opposite of what carries a load. The bounding + // box is identical either way, which is why it survives inspection. + leg.rotateX(-Math.atan2(legFoot, legRise)) + leg.rotateY(a) + leg.translate( + Math.sin(a) * legFoot * 0.5, + (floor + apexY) / 2, + Math.cos(a) * legFoot * 0.5, + ) + iron.push(leg) + } + // Apex ring: what gathers the three heads and carries the chain. + iron.push(bandGeometry( + barT * 2.3, apexY - barT * 0.9, barT * 1.8, barT * 0.7, 8, + tint('iron', 0.05, 0.7), { inner: true }, + )) + + // --- Pot ---------------------------------------------------------------- + // Authored hanging from the APEX, which is where the part's origin goes, + // so the whole assembly can be raised and lowered on its chain later + // without any of it being rebuilt. + const R = config.potRadius + // Low over the fire, which is the only place a cooking pot is any use. + // At 0.36 of the tripod's height the cauldron hung half a metre clear of + // the embers -- close enough to look like a cauldron and far enough to + // cook nothing. + const potHang = -H * 0.62 + const pot: BufferGeometry[] = [] + const potIron: BufferGeometry[] = [] + + // Chain, from the apex ring down to the bail. + const linkCount = Math.max(2, Math.round(config.links)) + const chainDrop = -potHang - R * 1.5 + // The link radius comes from the SPACING the links are actually laid out + // at, which is over (count - 1) gaps, not over count. Dividing by the + // count made each link a little smaller than half its own gap, so the + // chain came apart the moment the drop grew -- the same arithmetic slip + // the tavern sign's chain had, and the support check caught this one for + // the same reason it caught that one. + const linkGap = (chainDrop - barT * 1.2) / Math.max(1, linkCount - 1) + const linkR = Math.max(barT * 0.9, linkGap * 0.62) + for (let i = 0; i < linkCount; i += 1) { + const y = -barT * 1.2 - linkGap * i + const ring = bandGeometry( + linkR, 0, barT * 0.7, barT * 0.42, 6, + tint('iron', jitter(random, 0.05), 0.7), { inner: true }, + ) + // Successive links pass through each other at right angles. + ring.rotateY(i * 0.41) + ring.rotateX(i % 2 === 0 ? Math.PI / 2 : 0) + ring.rotateZ(i % 2 === 0 ? 0 : Math.PI / 2) + ring.translate(0, y, 0) + potIron.push(ring) + } + + // The cauldron itself. The widest point is BELOW the mouth. + const belly = potHang + const profile: Level[] = [ + { y: belly - R * 0.82, radius: R * 0.34 }, + { y: belly - R * 0.62, radius: R * 0.66 }, + { y: belly - R * 0.2, radius: R * 0.97 }, + { y: belly + R * 0.1, radius: R }, + { y: belly + R * 0.5, radius: R * 0.86 }, + { y: belly + R * 0.72, radius: R * 0.82 }, + ] + pot.push(latheGeometry(profile, 11, [0, 0, 0], tint('char', 0.05, 0.5), { + colourTop: tint('char', 0.11, 0.5), + capTop: false, + })) + // The inside, so the mouth is not a hole through to nothing. + pot.push(latheGeometry( + [ + { y: belly - R * 0.55, radius: R * 0.6 }, + { y: belly + R * 0.72, radius: R * 0.76 }, + ] as Level[], + 11, [0, 0, 0], tint('char', -0.06, 0.4), { capTop: false }, + )) + // Rim, and the girth band round the belly: cast ridges, and the two lines + // that stop the body reading as a smooth blob. + potIron.push(bandGeometry( + R * 0.86, belly + R * 0.7, R * 0.1, R * 0.06, 11, + tint('iron', -0.04, 0.6), + )) + potIron.push(bandGeometry( + R * 1.02, belly + R * 0.06, R * 0.07, R * 0.05, 11, + tint('iron', -0.08, 0.6), + )) + + // Three feet. Short, splayed, and the reason it can stand in the ashes. + for (let i = 0; i < 3; i += 1) { + const a = (i / 3) * Math.PI * 2 + 0.9 + const foot = taperedBoxGeometry( + [R * 0.14, R * 0.14], + [R * 0.1, R * 0.1], + R * 0.38, + [0, 0, 0], + tint('iron', -0.05, 0.6), + ) + foot.rotateX(0.22) + foot.rotateY(a) + foot.translate( + Math.sin(a) * R * 0.52, + belly - R * 0.86, + Math.cos(a) * R * 0.52, + ) + potIron.push(foot) + } + + // Bail: a real arc, pinned to two lugs. `arcBarGeometry` sweeps from 0 to + // PI in the XY plane, which is already the shape of a handle standing + // over the pot, so no rotation is involved. + const bailR = R * 0.92 + potIron.push(arcBarGeometry( + bailR, barT * 0.75, -0.22, Math.PI + 0.22, 9, + [0, belly + R * 0.42, 0], + tint('iron', 0.06, 0.7), + )) + for (const side of [-1, 1]) { + potIron.push(bandGeometry( + R * 0.13, belly + R * 0.5, R * 0.13, R * 0.06, 6, + tint('iron', 0.02, 0.6), { inner: true }, + ).translate(side * bailR * 0.94, 0, 0)) + } + + return { + hearth: { + slot: 'stone' as const, + geometry: hearth, + extras: [ + { slot: 'char' as const, geometry: ash }, + { slot: 'ember' as const, geometry: mergeColoured(emberPieces) }, + ], + }, + tripod: { slot: 'iron' as const, geometry: mergeColoured(iron) }, + pot: { + slot: 'char' as const, + geometry: mergeColoured(pot), + extras: [{ slot: 'iron' as const, geometry: mergeColoured(potIron) }], + origin: [0, apexY, 0] as const, + }, + } + }, + + actions: ({ parts, getConfig }) => { + lit = getConfig().lit >= 0.5 + // The embers are the SECOND body of the hearth part. Hiding the part + // itself would take the stones with it. + const embers = parts.hearth.anchor.children[2] + if (embers) embers.visible = lit + return { + setLit: (on) => { + lit = on + const body = parts.hearth.anchor.children[2] + if (body) body.visible = on + }, + isLit: () => lit, + } + }, + }, overrides) +} diff --git a/my-registry/models/post-mill/model.ts b/my-registry/models/post-mill/model.ts index 5ce8efc..776a390 100644 --- a/my-registry/models/post-mill/model.ts +++ b/my-registry/models/post-mill/model.ts @@ -163,7 +163,18 @@ export function createModel(overrides: Partial = {}) { ) // Built upright, leaned outwards, then swung to its arm. Rotating about // X leans it in the YZ plane; rotating about Y carries that lean round. - bar.rotateX(Math.atan2(barFoot, barRise)) + // + // The sign is NEGATIVE, and it was not. `rotateX(+t)` carries the bar's + // top towards +Z and the translate below moves it +Z as well, so the + // two add and the quarter-bars stood on their heads -- feet gathered at + // the post, heads splayed out over the cross-trees, which is precisely + // backwards for a brace whose whole job is to carry the post's load out + // to the ground. Nothing caught it: the bar joins post to cross-tree + // either way round, so the mass stays connected and the bounding box is + // identical. It surfaced in the cauldron, where the same expression + // built a tripod standing on its apex and the support check finally had + // something to say. + bar.rotateX(-Math.atan2(barFoot, barRise)) bar.rotateY(a) bar.translate( Math.sin(a) * barFoot * 0.5, diff --git a/scripts/verify-model.ts b/scripts/verify-model.ts index 2425ef1..33287a3 100644 --- a/scripts/verify-model.ts +++ b/scripts/verify-model.ts @@ -51,6 +51,8 @@ import { createModel as createPouch } from '@/models/medieval-kit/coin-pouch/mod import { createModel as createBasket } from '@/models/medieval-kit/wicker-basket/model.ts' import { createModel as createMill } from '@/models/medieval-kit/post-mill/model.ts' import { createModel as createWell } from '@/models/medieval-kit/stone-well/model.ts' +import { createModel as createCauldron } from '@/models/medieval-kit/iron-cauldron/model.ts' +import { createModel as createCart } from '@/models/medieval-kit/hand-cart/model.ts' const failures: string[] = [] function expect(label: string, condition: boolean): void { @@ -305,6 +307,14 @@ const CASES: readonly Case[] = [ { id: 'wooden-ladder', make: as(createLadder), patch: { rungCount: 12 }, parts: 2, ownSlot: 'oak', borrowSlot: 'oak', closed: true, variants: [{ rungCount: 3 }, { taper: 0 }] , maxSize: [0.6, 2.4, 0.12] }, + { id: 'iron-cauldron', make: as(createCauldron), patch: { stones: 16, links: 6 }, + parts: 3, ownSlot: 'stone', borrowSlot: 'iron', + variants: [{ lit: 0 }, { stones: 6 }, { potRadius: 0.36 }], + maxSize: [1.6, 1.5, 1.6] }, + { id: 'hand-cart', make: as(createCart), patch: { spokes: 13, sideHeight: 0.42 }, + parts: 4, ownSlot: 'iron', borrowSlot: 'oak', + variants: [{ spokes: 6 }, { shaftLength: 1.8 }, { wheelRadius: 0.5 }], + maxSize: [1.5, 1.2, 3.0] }, { id: 'stone-well', make: as(createWell), patch: { courses: 6, blocks: 15 }, parts: 4, ownSlot: 'stone', borrowSlot: 'oak', variants: [{ courses: 2 }, { depth: 1 }, { blocks: 6 }], diff --git a/src/catalog.ts b/src/catalog.ts index 47982fb..e0813f2 100644 --- a/src/catalog.ts +++ b/src/catalog.ts @@ -45,6 +45,8 @@ import { createModel as createPouch } from '@/models/medieval-kit/coin-pouch/mod import { createModel as createBasket } from '@/models/medieval-kit/wicker-basket/model.ts' import { createModel as createMill } from '@/models/medieval-kit/post-mill/model.ts' import { createModel as createWell } from '@/models/medieval-kit/stone-well/model.ts' +import { createModel as createCauldron } from '@/models/medieval-kit/iron-cauldron/model.ts' +import { createModel as createCart } from '@/models/medieval-kit/hand-cart/model.ts' export interface ParamSpec { readonly key: string @@ -151,6 +153,8 @@ const FACTORIES: Readonly KitModel>> = { 'wicker-basket': as(createBasket), 'post-mill': as(createMill), 'stone-well': as(createWell), + 'iron-cauldron': as(createCauldron), + 'hand-cart': as(createCart), 'wooden-ladder': as(createLadder), 'wooden-fence': as(createFence), 'wooden-hoe': as(createHoe), @@ -305,6 +309,7 @@ const MEDIEVAL_ORDER = [ 'wooden-hoe', 'wooden-shovel', 'wooden-pitchfork', // Last, because it is the landmark: a 6 m mill after a row of hand tools is // the order that makes the scale of it land. + 'iron-cauldron', 'hand-cart', 'stone-well', 'post-mill', ] as const diff --git a/src/models/medieval-kit/hand-cart/model.ts b/src/models/medieval-kit/hand-cart/model.ts new file mode 100644 index 0000000..ca421ca --- /dev/null +++ b/src/models/medieval-kit/hand-cart/model.ts @@ -0,0 +1,342 @@ +/** + * @medieval-kit/hand-cart + * + * A two-wheeled handcart: a planked body on an axle, with two shafts to pull + * it by. + * + * The kit already had `cart-wheel` and nothing to put it on. That is the gap + * this fills, and it fills a second one at the same time: every container in + * the catalogue — crates, sacks, barrels, baskets — is a thing you would + * MOVE, and there was no way to move any of it. + * + * Two details carry the whole design, and both are about where the axle is: + * + * - It sits BEHIND the middle of the bed, not under it. A handcart is + * balanced so that a loaded body rests a little weight on the puller's + * hands rather than trying to tip backwards out of them, and the wheels go + * aft of centre to do it. + * - The shafts slope DOWN from the bed's front and rest on the ground when + * the cart is parked. That is not the cart tipping: the bed stays level + * and the shafts leave it at an angle, which is what lets one person pick + * them up to waist height without the load shifting. + * + * Parts: `wheels` (the pair and their axle, with its own origin at the axle so + * `setRoll` turns them in place), `bed`, `sides` and `shafts`. + */ +import { Color, type BufferGeometry } from 'three' + +import { + bandGeometry, + boxGeometry, + chamferedBoxGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + taperedBoxGeometry, + type Level, +} from '../core/index.ts' + +export interface HandCartConfig { + /** Length of the cart's bed (metres). */ + readonly bedLength: number + /** Width of the bed (metres). */ + readonly bedWidth: number + /** Height of the side boards above the bed (metres). */ + readonly sideHeight: number + /** Wheel radius (metres). */ + readonly wheelRadius: number + /** Spokes in each wheel. */ + readonly spokes: number + /** Length of the shafts beyond the bed (metres). */ + readonly shaftLength: number + /** Wheel rotation (radians). */ + readonly roll: number + readonly seed: number +} + +export const handCartDefaults: HandCartConfig = { + bedLength: 1.34, + bedWidth: 0.66, + sideHeight: 0.28, + wheelRadius: 0.33, + spokes: 10, + shaftLength: 1.15, + roll: 0, + seed: 61, +} + +export type HandCartParts = 'wheels' | 'bed' | 'sides' | 'shafts' + +export interface HandCartActions { + /** Turns the wheels. */ + setRoll(radians: number): void + roll(): number +} + +export function createModel(overrides: Partial = {}) { + let roll = 0 + + return createKitModel({ + id: 'hand-cart', + defaults: handCartDefaults, + slots: ['oak', 'iron'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const L = config.bedLength + const W = config.bedWidth + const wheelR = config.wheelRadius + const plank = W * 0.035 + + // Ground at y = 0: this model rests on its wheels and its shaft tips, and + // building from the floor up keeps all three of those at one datum. + const axleY = wheelR + const bedY = axleY + plank * 2.6 + // Aft of centre, so a load leans on the puller rather than away from him. + const axleZ = L * 0.16 + + // --- Wheels and axle ------------------------------------------------------ + const spokes = Math.max(6, Math.round(config.spokes)) + const felloeOuter = wheelR * 0.9 + const felloeInner = felloeOuter * 0.8 + const hubR = wheelR * 0.19 + const wheelX = W / 2 + plank * 2.2 + const wheelBody: BufferGeometry[] = [] + const wheelIron: BufferGeometry[] = [] + + for (const side of [-1, 1]) { + const parts: BufferGeometry[] = [] + // Hub, turned and belled at both ends the way a nave is. + parts.push(latheGeometry( + [ + { y: -wheelR * 0.16, radius: hubR * 0.72 }, + { y: -wheelR * 0.1, radius: hubR }, + { y: wheelR * 0.1, radius: hubR }, + { y: wheelR * 0.16, radius: hubR * 0.72 }, + ] as Level[], + 9, [0, 0, 0], tint('oak', -0.02, 1.1), + )) + // Spokes. Each reaches INTO the hub at one end and INTO the felloe at + // the other, so both joints are overlaps rather than faces meeting. + const spokeInner = hubR * 0.5 + const spokeLength = felloeInner - spokeInner + wheelR * 0.06 + for (let i = 0; i < spokes; i += 1) { + const a = (i / spokes) * Math.PI * 2 + const spoke = taperedBoxGeometry( + [wheelR * 0.075, wheelR * 0.055], + [wheelR * 0.058, wheelR * 0.045], + spokeLength, + [0, spokeLength / 2 + spokeInner, 0], + tint('oak', jitter(random, 0.05)), + ) + spoke.rotateZ(a + jitter(random, 0.012)) + parts.push(spoke) + } + // Felloe: separate segments, because a wheel rim is built from arcs of + // timber and a turned ring reads as a hoop. + for (let i = 0; i < spokes; i += 1) { + const a = ((i + 0.5) / spokes) * Math.PI * 2 + const mid = (felloeOuter + felloeInner) / 2 + const arc = (Math.PI * 2 * mid) / spokes + const seg = taperedBoxGeometry( + [arc * 1.06, felloeOuter - felloeInner], + [arc * 1.02, (felloeOuter - felloeInner) * 0.96], + wheelR * 0.14 * (1 + jitter(random, 0.05)), + [0, 0, 0], + tint('oak', -0.05 + jitter(random, 0.05)), + ) + // Built lying flat with its height along Y; standing it on edge and + // then swinging it round puts its thickness across the wheel. + seg.rotateX(Math.PI / 2) + seg.rotateZ(a) + seg.translate(Math.cos(a) * mid, Math.sin(a) * mid, 0) + parts.push(seg) + } + const wheel = mergeColoured(parts) + wheel.rotateY(Math.PI / 2) + wheel.translate(side * wheelX, axleY, axleZ) + wheelBody.push(wheel) + + // Iron tyre, set INTO the tread and narrower than the felloe, the same + // way the cart wheel's is: anything within the felloe's own thickness + // will sooner or later share a plane with one of its segments. + const tyre = bandGeometry( + wheelR, 0, wheelR * 0.115, wheelR * 0.1, spokes * 2, + tint('iron', jitter(random, 0.04), 0.7), { inner: true }, + ) + tyre.rotateZ(Math.PI / 2) + tyre.translate(side * wheelX, axleY, axleZ) + wheelIron.push(tyre) + } + + // Axle: through both hubs, so the pair is one object. + const axle = taperedBoxGeometry( + [hubR * 0.8, hubR * 0.8], + [hubR * 0.8, hubR * 0.8], + wheelX * 2 + hubR, + [0, 0, 0], + tint('oak', -0.1), + ) + axle.rotateZ(Math.PI / 2) + axle.translate(0, axleY, axleZ) + wheelBody.push(axle) + + // --- Bed ------------------------------------------------------------------ + const floorBoards: BufferGeometry[] = [] + const boards = 5 + for (let i = 0; i < boards; i += 1) { + const w = W / boards + floorBoards.push(chamferedBoxGeometry( + [w * 0.97, L], + [w * 0.95, L * 0.998], + plank, + plank * 0.14, + [(i + 0.5) * w - W / 2, bedY, 0], + tint('oak', 0.03 + jitter(random, 0.05)), + )) + } + // Cross bearers under the boards, and the axle bed they sit on. + for (const at of [-0.36, 0, 0.36]) { + floorBoards.push(chamferedBoxGeometry( + [W * 1.02, L * 0.07], + [W * 0.99, L * 0.06], + plank * 1.5, + plank * 0.12, + [0, bedY - plank * 1.2, at * L], + tint('oak', -0.08), + )) + } + floorBoards.push(chamferedBoxGeometry( + [wheelX * 2 - hubR, L * 0.1], + [wheelX * 2 - hubR * 1.6, L * 0.09], + plank * 1.8, + plank * 0.12, + [0, bedY - plank * 2.3, axleZ], + tint('oak', -0.12), + )) + + // --- Sides ---------------------------------------------------------------- + const walls: BufferGeometry[] = [] + const iron: BufferGeometry[] = [] + const sideH = config.sideHeight + + for (const side of [-1, 1]) { + // Two boards to a side, with a gap between them: a cart side is + // planked, not panelled, and the gap is what says so. + for (const [row, at] of [[0, 0.27], [1, 0.74]] as const) { + walls.push(chamferedBoxGeometry( + [plank, L * 0.99], + [plank * 0.94, L * 0.985], + sideH * 0.42, + plank * 0.16, + [side * (W / 2 + plank * 0.5), bedY + sideH * at, 0], + tint('oak', (row === 0 ? -0.02 : 0.04) + jitter(random, 0.05)), + )) + } + // Corner and middle stakes: the uprights the boards are nailed to. + for (const at of [-0.46, 0, 0.46]) { + walls.push(chamferedBoxGeometry( + [plank * 1.4, L * 0.055], + [plank * 1.2, L * 0.05], + sideH * 1.08, + plank * 0.16, + [side * (W / 2 + plank * 1.1), bedY + sideH * 0.5, at * L], + tint('oak', -0.05), + )) + } + } + // End boards, front and back. + for (const end of [-1, 1]) { + walls.push(chamferedBoxGeometry( + [W + plank * 2.2, plank], + [W + plank * 1.9, plank * 0.94], + sideH * 0.92, + plank * 0.16, + [0, bedY + sideH * 0.5, end * (L / 2 - plank * 0.5)], + tint('oak', -0.01 + jitter(random, 0.04)), + )) + } + + // --- Shafts --------------------------------------------------------------- + // They leave the bed's front and slope down to the ground. The angle is + // DERIVED from where they have to end, not chosen: a shaft that stops + // short hangs in the air and one that goes long pushes the cart over. + const shafts: BufferGeometry[] = [] + const rootY = bedY - plank * 1.2 + const rootZ = -L / 2 + const shaftDrop = rootY + const reach = config.shaftLength + const lean = Math.atan2(shaftDrop, reach) + const shaftLength = Math.hypot(shaftDrop, reach) + const shaftX = W / 2 - plank * 1.6 + + for (const side of [-1, 1]) { + const shaft = latheGeometry( + [ + { y: -shaftLength / 2, radius: plank * 0.62 }, + { y: -shaftLength * 0.42, radius: plank * 0.72 }, + { y: shaftLength * 0.36, radius: plank * 0.86 }, + { y: shaftLength / 2, radius: plank * 0.95 }, + ] as Level[], + 7, [0, 0, 0], tint('oak', 0.02 + jitter(random, 0.05), 1.1), + ) + // Built upright; leaning it about X drops its lower end forward, and + // the 4% overrun at the top buries its head in the cart's frame. + shaft.rotateX(Math.PI / 2 - lean) + shaft.translate( + side * shaftX, + rootY - shaftDrop / 2, + rootZ - reach / 2, + ) + shafts.push(shaft) + + // The strap that holds the shaft to the frame. It is the only reason + // the two are joined at all. + iron.push(boxGeometry( + [plank * 2.4, plank * 0.5, L * 0.09], + [side * shaftX, rootY + plank * 0.5, rootZ + L * 0.03], + new Color(tint('iron', 0.02, 0.7)), + )) + } + // Cross handle between the shaft tips, so the cart can be pulled by one + // person with both hands. + shafts.push(latheGeometry( + [ + { y: -shaftX - plank, radius: plank * 0.6 }, + { y: shaftX + plank, radius: plank * 0.6 }, + ] as Level[], + 7, [0, 0, 0], tint('oak', 0.06, 1.1), + ).rotateZ(Math.PI / 2).translate(0, plank * 0.62, rootZ - reach * 0.88)) + + return { + wheels: { + slot: 'oak' as const, + geometry: mergeColoured(wheelBody), + extras: [{ slot: 'iron' as const, geometry: mergeColoured(wheelIron) }], + origin: [0, axleY, axleZ] as const, + }, + bed: { slot: 'oak' as const, geometry: mergeColoured(floorBoards) }, + sides: { + slot: 'oak' as const, + geometry: mergeColoured(walls), + extras: [{ slot: 'iron' as const, geometry: mergeColoured(iron) }], + }, + shafts: { slot: 'oak' as const, geometry: mergeColoured(shafts) }, + } + }, + + actions: ({ parts, getConfig }) => { + roll = getConfig().roll + parts.wheels.anchor.rotation.x = roll + return { + setRoll: (radians) => { + roll = radians + parts.wheels.anchor.rotation.x = roll + }, + roll: () => roll, + } + }, + }, overrides) +} diff --git a/src/models/medieval-kit/iron-cauldron/model.ts b/src/models/medieval-kit/iron-cauldron/model.ts new file mode 100644 index 0000000..ad8f11d --- /dev/null +++ b/src/models/medieval-kit/iron-cauldron/model.ts @@ -0,0 +1,334 @@ +/** + * @medieval-kit/iron-cauldron + * + * A cauldron slung from a tripod over a ring of hearth stones. + * + * The kit had two light sources — a torch and a lantern — and no HEARTH, which + * is the wrong way round for a medieval catalogue. A cooking fire is where + * everyone in the scene is facing, and it is the only light in most of them. + * + * Three things about the shape are worth stating because they are what make it + * read as a cauldron rather than as a pot: + * + * - The belly is WIDER than the mouth. A cauldron is bulbous, so that its + * contents sit over the fire rather than beside it, and so that the walls + * take the heat evenly. Straight-sided, it is a bucket. + * - It has three short feet. It spends as much time standing in the ashes as + * hanging over them, and a round-bottomed pot cannot stand at all. + * - It hangs by a BAIL — a semicircular loop pinned to two lugs — and not by + * the rim. The bail is what the chain grips, and it swings, which is how a + * cauldron is taken off the fire without touching it. + * + * Parts: `hearth` (the stone ring and its bed of embers), `tripod`, and `pot` + * (the cauldron with its bail and the chain it hangs on). The chain belongs to + * the pot rather than to the tripod because it moves with what it carries. + */ +import { type BufferGeometry } from 'three' + +import { + arcBarGeometry, + bandGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + prismGeometry, + roughenGeometry, + taperedBoxGeometry, + type Level, +} from '../core/index.ts' + +export interface IronCauldronConfig { + /** Height from the ground to the tripod's apex (metres). */ + readonly height: number + /** Outer radius of the ring of hearth stones (metres). */ + readonly hearthRadius: number + /** Stones in the ring. */ + readonly stones: number + /** Radius of the cauldron at its belly (metres). */ + readonly potRadius: number + /** Links in the chain. */ + readonly links: number + /** Whether the fire is lit (0/1). */ + readonly lit: number + readonly seed: number +} + +export const ironCauldronDefaults: IronCauldronConfig = { + height: 1.28, + hearthRadius: 0.46, + stones: 12, + potRadius: 0.22, + links: 4, + lit: 1, + seed: 29, +} + +export type IronCauldronParts = 'hearth' | 'tripod' | 'pot' + +export interface IronCauldronActions { + /** Lights or puts out the fire. When out, the embers are hidden. */ + setLit(on: boolean): void + isLit(): boolean +} + +export function createModel(overrides: Partial = {}) { + let lit = true + + return createKitModel({ + id: 'iron-cauldron', + defaults: ironCauldronDefaults, + slots: ['stone', 'iron', 'char', 'ember'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = config.height + const floor = -H / 2 + const hearthR = config.hearthRadius + + // --- Hearth ------------------------------------------------------------- + const stones: BufferGeometry[] = [] + const count = Math.max(5, Math.round(config.stones)) + const stoneH = hearthR * 0.32 + const ringR = hearthR - stoneH * 0.5 + + for (let i = 0; i < count; i += 1) { + const a = (i / count) * Math.PI * 2 + jitter(random, 0.05) + const arc = (Math.PI * 2 * ringR) / count + // Cut long, like the well's kerb: a flat-faced block on a curve cannot + // close its joint otherwise, and a fire ring with daylight through it + // is not a fire ring. + const stone = taperedBoxGeometry( + [arc * (1.06 + jitter(random, 0.08)), stoneH * (1 + jitter(random, 0.1))], + [arc * (0.78 + jitter(random, 0.1)), stoneH * (0.72 + jitter(random, 0.12))], + stoneH * (0.86 + jitter(random, 0.14)), + [0, 0, 0], + tint('stone', jitter(random, 0.1)), + ) + stone.rotateY(a) + stone.translate( + Math.sin(a) * ringR, + floor + stoneH * 0.4, + Math.cos(a) * ringR, + ) + stones.push(stone) + } + const hearth = mergeColoured(stones) + roughenGeometry(hearth, stoneH * 0.08, { salt: 19 }) + + // Ash bed inside the ring, and the embers on it. The bed is char and the + // embers sit slightly proud of it; separating them is what lets the fire + // be put out without the ashes going with it. + const ashR = ringR - stoneH * 0.42 + const ash = latheGeometry( + [ + { y: floor + hearthR * 0.005, radius: ashR }, + { y: floor + hearthR * 0.055, radius: ashR * 0.9 }, + ] as Level[], + 11, [0, 0, 0], tint('char', 0.04), + ) + + const emberPieces: BufferGeometry[] = [] + const emberCount = Math.max(4, Math.round(count * 0.7)) + for (let i = 0; i < emberCount; i += 1) { + const a = i * 2.399963 + const r = ashR * 0.72 * Math.sqrt((i + 0.4) / emberCount) + const size = hearthR * (0.05 + random() * 0.045) + const coal = prismGeometry( + size, size * 0.6, size * 0.7, 5, [0, 0, 0], + tint(i % 3 === 0 ? 'emberTip' : 'ember', jitter(random, 0.05), 0.4), + ) + coal.rotateY(random() * Math.PI * 2) + coal.translate( + Math.sin(a) * r, + floor + hearthR * 0.06, + Math.cos(a) * r, + ) + emberPieces.push(coal) + } + + // --- Tripod ------------------------------------------------------------- + const apexY = floor + H + const iron: BufferGeometry[] = [] + const legFoot = hearthR * 1.34 + const legRise = apexY - floor + const legLength = Math.hypot(legFoot, legRise) + const barT = hearthR * 0.045 + + for (let i = 0; i < 3; i += 1) { + // Three legs, not four. A tripod cannot rock: whatever the ground does, + // three feet are always on it, which is why every cooking fire in + // Europe stood on one. + const a = (i / 3) * Math.PI * 2 + 0.4 + const leg = taperedBoxGeometry( + [barT * 1.15, barT * 1.15], + [barT * 0.8, barT * 0.8], + legLength * 1.02, + [0, 0, 0], + tint('iron', -0.02 + jitter(random, 0.04), 0.7), + ) + // NEGATIVE. `rotateX(+t)` carries the bar's TOP towards +Z, and the + // translate that follows also moves it +Z, so the two add: the head + // ends up at the full outboard radius and the foot at the axis. The + // brace stands on its head, splayed at the top and gathered at the + // bottom, which is the opposite of what carries a load. The bounding + // box is identical either way, which is why it survives inspection. + leg.rotateX(-Math.atan2(legFoot, legRise)) + leg.rotateY(a) + leg.translate( + Math.sin(a) * legFoot * 0.5, + (floor + apexY) / 2, + Math.cos(a) * legFoot * 0.5, + ) + iron.push(leg) + } + // Apex ring: what gathers the three heads and carries the chain. + iron.push(bandGeometry( + barT * 2.3, apexY - barT * 0.9, barT * 1.8, barT * 0.7, 8, + tint('iron', 0.05, 0.7), { inner: true }, + )) + + // --- Pot ---------------------------------------------------------------- + // Authored hanging from the APEX, which is where the part's origin goes, + // so the whole assembly can be raised and lowered on its chain later + // without any of it being rebuilt. + const R = config.potRadius + // Low over the fire, which is the only place a cooking pot is any use. + // At 0.36 of the tripod's height the cauldron hung half a metre clear of + // the embers -- close enough to look like a cauldron and far enough to + // cook nothing. + const potHang = -H * 0.62 + const pot: BufferGeometry[] = [] + const potIron: BufferGeometry[] = [] + + // Chain, from the apex ring down to the bail. + const linkCount = Math.max(2, Math.round(config.links)) + const chainDrop = -potHang - R * 1.5 + // The link radius comes from the SPACING the links are actually laid out + // at, which is over (count - 1) gaps, not over count. Dividing by the + // count made each link a little smaller than half its own gap, so the + // chain came apart the moment the drop grew -- the same arithmetic slip + // the tavern sign's chain had, and the support check caught this one for + // the same reason it caught that one. + const linkGap = (chainDrop - barT * 1.2) / Math.max(1, linkCount - 1) + const linkR = Math.max(barT * 0.9, linkGap * 0.62) + for (let i = 0; i < linkCount; i += 1) { + const y = -barT * 1.2 - linkGap * i + const ring = bandGeometry( + linkR, 0, barT * 0.7, barT * 0.42, 6, + tint('iron', jitter(random, 0.05), 0.7), { inner: true }, + ) + // Successive links pass through each other at right angles. + ring.rotateY(i * 0.41) + ring.rotateX(i % 2 === 0 ? Math.PI / 2 : 0) + ring.rotateZ(i % 2 === 0 ? 0 : Math.PI / 2) + ring.translate(0, y, 0) + potIron.push(ring) + } + + // The cauldron itself. The widest point is BELOW the mouth. + const belly = potHang + const profile: Level[] = [ + { y: belly - R * 0.82, radius: R * 0.34 }, + { y: belly - R * 0.62, radius: R * 0.66 }, + { y: belly - R * 0.2, radius: R * 0.97 }, + { y: belly + R * 0.1, radius: R }, + { y: belly + R * 0.5, radius: R * 0.86 }, + { y: belly + R * 0.72, radius: R * 0.82 }, + ] + pot.push(latheGeometry(profile, 11, [0, 0, 0], tint('char', 0.05, 0.5), { + colourTop: tint('char', 0.11, 0.5), + capTop: false, + })) + // The inside, so the mouth is not a hole through to nothing. + pot.push(latheGeometry( + [ + { y: belly - R * 0.55, radius: R * 0.6 }, + { y: belly + R * 0.72, radius: R * 0.76 }, + ] as Level[], + 11, [0, 0, 0], tint('char', -0.06, 0.4), { capTop: false }, + )) + // Rim, and the girth band round the belly: cast ridges, and the two lines + // that stop the body reading as a smooth blob. + potIron.push(bandGeometry( + R * 0.86, belly + R * 0.7, R * 0.1, R * 0.06, 11, + tint('iron', -0.04, 0.6), + )) + potIron.push(bandGeometry( + R * 1.02, belly + R * 0.06, R * 0.07, R * 0.05, 11, + tint('iron', -0.08, 0.6), + )) + + // Three feet. Short, splayed, and the reason it can stand in the ashes. + for (let i = 0; i < 3; i += 1) { + const a = (i / 3) * Math.PI * 2 + 0.9 + const foot = taperedBoxGeometry( + [R * 0.14, R * 0.14], + [R * 0.1, R * 0.1], + R * 0.38, + [0, 0, 0], + tint('iron', -0.05, 0.6), + ) + foot.rotateX(0.22) + foot.rotateY(a) + foot.translate( + Math.sin(a) * R * 0.52, + belly - R * 0.86, + Math.cos(a) * R * 0.52, + ) + potIron.push(foot) + } + + // Bail: a real arc, pinned to two lugs. `arcBarGeometry` sweeps from 0 to + // PI in the XY plane, which is already the shape of a handle standing + // over the pot, so no rotation is involved. + const bailR = R * 0.92 + potIron.push(arcBarGeometry( + bailR, barT * 0.75, -0.22, Math.PI + 0.22, 9, + [0, belly + R * 0.42, 0], + tint('iron', 0.06, 0.7), + )) + for (const side of [-1, 1]) { + potIron.push(bandGeometry( + R * 0.13, belly + R * 0.5, R * 0.13, R * 0.06, 6, + tint('iron', 0.02, 0.6), { inner: true }, + ).translate(side * bailR * 0.94, 0, 0)) + } + + return { + hearth: { + slot: 'stone' as const, + geometry: hearth, + extras: [ + { slot: 'char' as const, geometry: ash }, + { slot: 'ember' as const, geometry: mergeColoured(emberPieces) }, + ], + }, + tripod: { slot: 'iron' as const, geometry: mergeColoured(iron) }, + pot: { + slot: 'char' as const, + geometry: mergeColoured(pot), + extras: [{ slot: 'iron' as const, geometry: mergeColoured(potIron) }], + origin: [0, apexY, 0] as const, + }, + } + }, + + actions: ({ parts, getConfig }) => { + lit = getConfig().lit >= 0.5 + // The embers are the SECOND body of the hearth part. Hiding the part + // itself would take the stones with it. + const embers = parts.hearth.anchor.children[2] + if (embers) embers.visible = lit + return { + setLit: (on) => { + lit = on + const body = parts.hearth.anchor.children[2] + if (body) body.visible = on + }, + isLit: () => lit, + } + }, + }, overrides) +} diff --git a/src/models/medieval-kit/post-mill/model.ts b/src/models/medieval-kit/post-mill/model.ts index 5ce8efc..776a390 100644 --- a/src/models/medieval-kit/post-mill/model.ts +++ b/src/models/medieval-kit/post-mill/model.ts @@ -163,7 +163,18 @@ export function createModel(overrides: Partial = {}) { ) // Built upright, leaned outwards, then swung to its arm. Rotating about // X leans it in the YZ plane; rotating about Y carries that lean round. - bar.rotateX(Math.atan2(barFoot, barRise)) + // + // The sign is NEGATIVE, and it was not. `rotateX(+t)` carries the bar's + // top towards +Z and the translate below moves it +Z as well, so the + // two add and the quarter-bars stood on their heads -- feet gathered at + // the post, heads splayed out over the cross-trees, which is precisely + // backwards for a brace whose whole job is to carry the post's load out + // to the ground. Nothing caught it: the bar joins post to cross-tree + // either way round, so the mass stays connected and the bounding box is + // identical. It surfaced in the cauldron, where the same expression + // built a tripod standing on its apex and the support check finally had + // something to say. + bar.rotateX(-Math.atan2(barFoot, barRise)) bar.rotateY(a) bar.translate( Math.sin(a) * barFoot * 0.5,