diff --git a/README.md b/README.md index 6b75049..6877abb 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ on an opaque package. This repository holds one such registry. ![The whole kit in one scene](media/kit.png) -35 models and one shared library, **31,404 triangles** for the whole kit — less +36 models and one shared library, **31,748 triangles** for the whole kit — less than a single medium-detail character. Every one is procedural source you own and edit, not an asset you load. diff --git a/REFERENCE.md b/REFERENCE.md index fb99a42..609443a 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -79,7 +79,7 @@ src/viewer.ts · src/viewer.css the model viewer (WebGPU, sky, shadow) src/catalog.ts the viewer's catalog — DERIVED from meta.ts src/glb.ts GLB export (shared by viewer and CLI) src/models/scifi-kit/pressure-gauge/ the installed sci-fi model -src/models/medieval-kit/… your OWN installed models (35 models) +src/models/medieval-kit/… your OWN installed models (36 models) my-registry/ meta.ts the SINGLE source of catalog metadata build.ts the registry.json generator @@ -338,7 +338,7 @@ the same, the physical package changes. ## 5. Lowpoly medieval — yes, no problem This is not an assumption: `@medieval-kit` works, is validated and currently -contains **35 models + 1 lib**. The table is generated from the models +contains **36 models + 1 lib**. The 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 in fact it had gone stale once. @@ -377,10 +377,11 @@ on the first model you add, and in fact it had gone stale once. | `round-shield` | Arms | 729 | 3 | 0.73×0.73×0.17 | oak, leather, iron | | | `forge-hearth` | Smithy | 1426 | 4 | 2.06×1.78×0.87 | stone, char, ember, oak, leather, iron | | | `stone-well` | Structure | 1376 | 4 | 1.88×2.00×1.28 | stone, oak, iron, cloth | | +| `stone-trough` | Structure | 344 | 2 | 1.52×0.45×0.60 | stone, water | | | `post-mill` | Structure | 1672 | 4 | 6.60×7.23×6.98 | oak, iron | | | `oak-tree` | Nature | 2310 | 3 | 8.57×6.96×9.05 | oak, leaf | | -**31,404 triangles** in total. The whole kit in one scene has a budget smaller +**31,748 triangles** in total. The whole kit in one scene has a budget smaller than a single medium-complexity character model. ### 5.1 One source: `my-registry/meta.ts` @@ -404,7 +405,7 @@ declaration means a hidden material the consumer cannot reach with this check was added it caught a real drift in four models (a `steel` slot had been added but not declared). -### 5.2 The material vocabulary — thirteen slots +### 5.2 The material vocabulary — fourteen slots | Slot | What | Why separate | | --- | --- | --- | @@ -421,6 +422,7 @@ been added but not declared). | `char` | charcoal, pitch | — | | `stone` | dressed and rubble masonry | its color is close to weathered oak; what tells them apart at a glance is that stone scatters light completely flat, and roughness is not something vertex color can carry | | `leaf` | living foliage | the most matte thing here after stone: any sheen at all and a crown reads as plastic shrubbery, which is the usual failure of a lowpoly tree and is a material setting rather than a modelling one | +| `water` | standing water | a thin transparent film over whatever holds it: it works through opacity rather than through a colour of its own | `ember` also works as a rule in two places: bodies in this slot are skipped entirely while occlusion and mottle are baked. The reason is simple — on an diff --git a/media/kit.png b/media/kit.png index ecee56b..9306c8e 100644 Binary files a/media/kit.png and b/media/kit.png differ diff --git a/media/models.png b/media/models.png index f3dbb12..4196f57 100644 Binary files a/media/models.png and b/media/models.png differ diff --git a/models.lock.json b/models.lock.json index 85dfb78..5582a0d 100644 --- a/models.lock.json +++ b/models.lock.json @@ -82,7 +82,7 @@ "address": "@medieval-kit/core", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-26T19:00:27.476Z", + "installedAt": "2026-08-26T19:43:46.488Z", "files": [ { "path": "src\\models\\medieval-kit\\core\\geometry.ts", @@ -94,7 +94,7 @@ }, { "path": "src\\models\\medieval-kit\\core\\materials.ts", - "sourceHash": "e39ce86ff1a3bd6e23ae9067b3dd241d449299b3ab24a0164eb8cb997c1e96cc" + "sourceHash": "1863cbe82d9cab014a6f83af57a5f647a2fb8d248759ffd1b5ae663e2b8ebac0" }, { "path": "src\\models\\medieval-kit\\core\\random.ts", @@ -106,7 +106,7 @@ }, { "path": "src\\models\\medieval-kit\\core\\kit.ts", - "sourceHash": "d2332388b6d4b2baec730dbe56572fa82ff9e8a0e155295b1b0910a2dc91d22d" + "sourceHash": "bcaafdb326cc4478305b28524f7b1472598530380c71441f8f0570c27e42f99f" }, { "path": "src\\models\\medieval-kit\\core\\tool.ts", @@ -642,6 +642,21 @@ "dependencies": [ "three@>=0.185.0" ] + }, + "@medieval-kit/stone-trough": { + "address": "@medieval-kit/stone-trough", + "source": "file:my-registry/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-26T19:43:46.491Z", + "files": [ + { + "path": "src\\models\\medieval-kit\\stone-trough\\model.ts", + "sourceHash": "b582bcde5ea5ceae090bc16f3879619c1c10819333b571b11f5e1807d45a009a" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] } } } diff --git a/my-registry/README.md b/my-registry/README.md index 0d90c75..b602fa0 100644 --- a/my-registry/README.md +++ b/my-registry/README.md @@ -28,7 +28,7 @@ Configure `models.json` first so the namespace resolves: ## Models -35 models and one shared lib. Addresses are `@medieval-kit/`. This table is +36 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. @@ -68,10 +68,11 @@ did once. | `round-shield` | Arms | 729 | 3 | 0.73×0.73×0.17 | oak, leather, iron | | | `forge-hearth` | Smithy | 1426 | 4 | 2.06×1.78×0.87 | stone, char, ember, oak, leather, iron | | | `stone-well` | Structure | 1376 | 4 | 1.88×2.00×1.28 | stone, oak, iron, cloth | | +| `stone-trough` | Structure | 344 | 2 | 1.52×0.45×0.60 | stone, water | | | `post-mill` | Structure | 1672 | 4 | 6.60×7.23×6.98 | oak, iron | | | `oak-tree` | Nature | 2310 | 3 | 8.57×6.96×9.05 | oak, leaf | | -**31 404 triangles** in total. The whole kit in one scene costs less than a +**31 748 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 @@ -134,7 +135,7 @@ rebuilds topology and is not cheap. Anything that changes per frame belongs in ## Material slots -Thirteen slots, and each one exists because a single material could not carry the +Fourteen slots, and each one exists because a single material could not carry the difference. | Slot | What it covers | Why it is separate | @@ -151,6 +152,7 @@ difference. | `ember` | flame | `MeshBasicMaterial` — it does not receive light, it emits | | `char` | charcoal and pitch | — | | `leaf` | living foliage | the most matte thing here after stone: any sheen at all and a crown reads as plastic shrubbery, which is the usual failure of a lowpoly tree and is a material setting rather than a modelling one | +| `water` | standing water | a thin transparent film over whatever holds it: in the reference trough the basin reads hue 39.5, which is the hue of the STONE underneath, so it works through opacity rather than colour | | `stone` | dressed and rubble masonry | its colour is close to weathered oak; what separates them at a glance is that stone scatters light completely flat, and roughness is not something vertex colour can carry | `ember` also acts as a rule in two places: bodies in that slot are skipped diff --git a/my-registry/meta.ts b/my-registry/meta.ts index 476d745..49eca39 100644 --- a/my-registry/meta.ts +++ b/my-registry/meta.ts @@ -468,6 +468,23 @@ export const MODEL_META: Readonly> = { materialSlots: ['oak', 'leather', 'iron'], parts: ['boards', 'rim', 'boss'], }, + 'stone-trough': { + title: 'Stone Trough', + description: + 'Watering trough cut from one block of weathered limestone, with a heavy rim, a worn basin and a film of standing water.', + category: 'Structure', + tags: ['medieval', 'lowpoly', 'structure', 'procedural'], + controls: { + length: { type: 'number', label: 'Length', min: 0.8, max: 2.6, step: 0.05, unit: 'm' }, + width: { type: 'number', label: 'Width', min: 0.35, max: 0.95, step: 0.02, unit: 'm' }, + height: { type: 'number', label: 'Height', min: 0.25, max: 0.7, step: 0.02, unit: 'm' }, + wall: { type: 'number', label: 'Wall thickness', min: 0.12, max: 0.34, step: 0.01 }, + water: { type: 'number', label: 'Water level', min: 0, max: 1, step: 0.05 }, + seed: { type: 'number', label: 'Variation seed', min: 1, max: 64, step: 1 }, + }, + materialSlots: ['stone', 'water'], + parts: ['block', 'water'], + }, 'oak-tree': { title: 'Oak Tree', description: diff --git a/my-registry/models/core/kit.ts b/my-registry/models/core/kit.ts index 70f0c46..98aac63 100644 --- a/my-registry/models/core/kit.ts +++ b/my-registry/models/core/kit.ts @@ -161,6 +161,9 @@ const MOTTLE_BY_SLOT: Readonly> = { // the machinery that already reproduces that detail -- which is the third // time this kit has learned that, after straw's saturation and bark's value. leaf: 0.95, + // Barely mottled. Ripples are a shape, not a stain, and a surface this + // smooth shows speckle as dirt floating on it. + water: 0.2, } export function createKitModel< diff --git a/my-registry/models/core/materials.ts b/my-registry/models/core/materials.ts index ac52c7a..ab1fff2 100644 --- a/my-registry/models/core/materials.ts +++ b/my-registry/models/core/materials.ts @@ -27,6 +27,7 @@ export type MedievalSlot = | 'char' // charcoal, pitch | 'stone' // dressed and rubble masonry | 'leaf' // living foliage + | 'water' // standing water /** * The material TYPE can differ per slot. `ember` is an unlit MeshBasicMaterial; @@ -47,6 +48,7 @@ export interface SlotMaterial { readonly char: MeshStandardMaterial readonly stone: MeshStandardMaterial readonly leaf: MeshStandardMaterial + readonly water: MeshStandardMaterial } export interface MedievalPalette { @@ -156,6 +158,36 @@ export interface MedievalPalette { * lit and shadowed alike. */ readonly leaf: Color + + /** + * Weathered limestone, which is NOT the same rock as `stone`. + * + * `stone` was measured off dressed and rubble masonry: hue 44, saturation + * 0.05 — a wall stone, grey, and grey because a wall is quarried and laid + * face out. A trough is one block left in the open for a century, and the + * same measurement on one reads hue 36, saturation 0.16, lightness 0.48: + * warmer, THREE TIMES more saturated, and lighter. Reaching for `stone` on + * it gives a concrete planter. + * + * Both are correct and neither replaces the other, which is why this is a + * palette key rather than an edit to `stone` — the well and the forge were + * each measured against their own references and are not this rock. + */ + readonly limestone: Color + + /** + * Standing water, and it is far less green than it feels. + * + * Sampled inside the reference trough's basin the film reads hue 39.5 — + * which is the hue of the stone underneath it, not a colour of its own. It + * is shallow and it is clear; what it does is DARKEN and slightly saturate + * whatever it lies on (lightness 0.48 down to 0.36, saturation 0.16 up to + * 0.23). So this is nearly neutral, barely cool, and it does its work + * through the material's transparency rather than through its hue. Painted + * the pond green a first-instinct would have reached for, the composite + * would have missed the reference by 100 degrees of hue. + */ + readonly water: Color } /** @@ -207,6 +239,8 @@ export const MEDIEVAL_PALETTE: MedievalPalette = { stone: new Color(0x6e6b63), charHot: new Color(0xc4441a), bark: new Color(0x585032), + limestone: new Color(0x94846b), + water: new Color(0x3b4e45), leaf: new Color(0x6d8632), } @@ -356,6 +390,21 @@ export function createMedievalMaterials( roughness: 0.93, metalness: 0, }), + // Water is a THIN TRANSPARENT FILM, not a body of liquid. Everything in + // this kit that holds water holds a few centimetres of it over a floor you + // can see, so the colour that reaches the eye is mostly what is underneath + // — which is why the opacity is the important number here and the hue is + // nearly not a number at all. Smooth, because a trough out of the wind is + // the one surface in this kit that reflects. + water: () => new MeshStandardMaterial({ + name: 'medieval-kit / standing water', + color: 0xffffff, + vertexColors: true, + roughness: 0.11, + metalness: 0, + transparent: true, + opacity: 0.72, + }), char: () => new MeshStandardMaterial({ name: 'medieval-kit / charcoal', color: 0xffffff, diff --git a/my-registry/models/stone-trough/model.ts b/my-registry/models/stone-trough/model.ts new file mode 100644 index 0000000..aed6c08 --- /dev/null +++ b/my-registry/models/stone-trough/model.ts @@ -0,0 +1,243 @@ +/** + * @medieval-kit/stone-trough + * + * A watering trough cut from one block of limestone. + * + * The kit could water nobody. It has a well, a bucket and a cauldron, and all + * three are things you carry water IN; a trough is the thing a village keeps + * water in, standing in the street outside the smithy where the horses are. + * + * It is not the same ROCK as the well. `stone` in this palette was measured + * off dressed and rubble masonry and is grey, because a wall is quarried and + * laid face out. One block left in the open for a century reads hue 36 and + * saturation 0.16 against the wall's 44 and 0.05 — warmer, three times more + * saturated, lighter. Hence `limestone`, and the rendered block now matches + * the reference to within a fifth of a degree of hue and 0.004 of lightness. + * + * What took three attempts was making it read as CARVED rather than sawn, and + * the two failures are worth keeping because they are opposite errors: + * + * 1. Each wall in two tiers, to give `roughenGeometry` more corners to move. + * The tiers' corners sit at different positions, so the hash moved them + * by different amounts and left a hard seam right round the block — a lid + * on a base. + * 2. One box per wall, roughened harder to compensate. A box has eight + * corners and every face is two triangles, so moving those corners folded + * each wall along its own diagonal. Not stone: creased cardboard. + * + * Both tried to get subdivision out of the wrong thing. The walls are + * `dishedSheetGeometry` — one continuous body with levels along its length, + * which is what that helper's own docstring says the trough wants. The rim + * undulates because each level carries its own height, the wall thickens and + * thins because each carries its own thickness, and there is no join anywhere + * for a seam to open in. + * + * The basin is made the way everything hollow in this kit is made: by not + * filling it. Four walls and a floor, no boolean, corners overlapping. + */ +import { Color, type BufferGeometry } from 'three' + +import { + boxGeometry, + createKitModel, + createTinter, + dishedSheetGeometry, + jitter, + mergeColoured, + roughenGeometry, + type SheetLevel, +} from '../core/index.ts' + +export interface StoneTroughConfig { + /** Along the trough (metres). */ + readonly length: number + /** Across it (metres). */ + readonly width: number + /** Height of the block (metres). */ + readonly height: number + /** Wall thickness as a fraction of the width. */ + readonly wall: number + /** How full it stands, as a fraction of the basin's depth. 0 is dry. */ + readonly water: number + readonly seed: number +} + +export const stoneTroughDefaults: StoneTroughConfig = { + length: 1.5, + width: 0.58, + height: 0.44, + // Heavy, but not as heavy as I first made it. A trough is a block with a + // dish taken out of it rather than a vessel, and at 0.27 the two walls came + // to more than half the width and the basin shut so far that a three-quarter + // view showed only its inner face. The reference's opening is about three + // fifths of the block across, which is this. + wall: 0.21, + // Nearly full, and that is the reference rather than a preference: its water + // stands a couple of centimetres under the rim. It is also the only level at + // which the water is VISIBLE from anywhere but straight above — at 0.55 the + // surface sits below the near rim and the trough reads as dry from every + // angle anyone will look at it from. + water: 0.85, + seed: 19, +} + +export type StoneTroughParts = 'block' | 'water' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'stone-trough', + defaults: stoneTroughDefaults, + slots: ['stone', 'water'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const L = Math.max(0.3, config.length) + const W = Math.max(0.2, config.width) + const H = Math.max(0.15, config.height) + const wall = Math.max(0.02, Math.min(0.4, config.wall)) * W + // The floor is thicker than the walls. A trough wears out from the + // inside and the bottom is what is left when it does. + const floor = H * 0.3 + const basin = H - floor + + /** + * One wall as a single sheet, laid along +X and centred on the origin. + * + * `dishedSheetGeometry` builds in the XY plane: levels run along Y, + * `halfWidth` spans X, `thickness` spans Z. One turn about Z lays that + * down so the levels run along the trough and the half-width becomes the + * wall's HEIGHT — which is the whole trick, because every level can then + * carry a different height and the rim undulates on its own, with no + * roughening involved and no seam to tear open. + */ + const wallSheet = (len: number, thick: number, tall: number, lift: number): BufferGeometry => { + const steps = 7 + const levels: SheetLevel[] = [] + for (let i = 0; i < steps; i += 1) { + levels.push({ + y: len * (i / (steps - 1)), + halfWidth: (tall / 2) * (1 + jitter(random, 0.035)), + thickness: thick * (0.88 + random() * 0.24), + curve: 0, + }) + } + const sheet = dishedSheetGeometry(levels, 2, tint('limestone', lift, 0.85)) + sheet.rotateZ(-Math.PI / 2) + sheet.translate(-len / 2, 0, 0) + return sheet + } + + const stone: BufferGeometry[] = [] + + /** + * The solid bottom, and the ONLY thing that touches the ground. + * + * Built as four walls standing on the floor, every piece had a face on + * the ground plane, and where the corners overlapped — which is exactly + * where they are meant to overlap — two downward faces shared the plane + * y = 0. The checker found it twice, and the second time was after I had + * "fixed" it by lifting the basin floor, which only moved the pairing + * from floor-against-wall to wall-against-wall. + * + * The answer is not to separate the overlaps but to stop there being + * four things down there. A trough IS solid below the water line: one + * block from the ground to the basin, and the walls stand on top of it. + * One piece on the ground, one bottom face, nothing to pair with. + */ + const foot = wall * 0.5 + stone.push(boxGeometry( + [L - foot, floor, W - foot], + [0, floor / 2, 0], + new Color(tint('limestone', -0.05, 0.7)), + )) + + /** + * The four walls, sunk into that block by DIFFERENT amounts. + * + * Sunk, so their undersides are buried in solid stone rather than + * meeting its top face in a plane. By different amounts, because the + * long pair and the end pair overlap each other at the corners, and two + * buried faces in one plane are still two faces in one plane whether + * anybody can see them or not. + * + * The WALLS are flush with the block's nominal outline and the base is + * tucked in behind them, not the other way round. Standing the walls + * inset on a full-width base put a sharp ledge right round the bottom and + * the thing read as a planter on a concrete plinth. Tucked under, the + * base is invisible from above and the block is one face from rim to + * ground. + * + * Their outer faces cannot land in the base's plane by accident either: + * each level of a sheet carries its own thickness, so a wall's outer + * surface is a run of slightly different planes rather than one. + */ + const inset = 0 + const longSink = H * 0.06 + const endSink = H * 0.095 + for (const side of [-1, 1] as const) { + const w = wallSheet(L - inset * 2, wall, basin + longSink, jitter(random, 0.04)) + stone.push(w.translate( + 0, + floor - longSink + (basin + longSink) / 2, + (side * (W - wall - inset * 2)) / 2, + )) + } + for (const side of [-1, 1] as const) { + const end = wallSheet(W - wall * 0.5, wall, basin + endSink, 0.03 + jitter(random, 0.04)) + // Built along +X like the others, then turned a quarter about Y, which + // sends +X to -Z and leaves the height alone. + end.rotateY(Math.PI / 2) + stone.push(end.translate( + (side * (L - wall - inset * 2)) / 2, + floor - endSink + (basin + endSink) / 2, + 0, + )) + } + + const block = mergeColoured(stone) + // Light, now that the sheets carry the shape themselves. This is grain + // on a face, not the shape of the block. + roughenGeometry(block, wall * 0.09, { salt: 41, scaleY: 0.5 }) + + /** + * Put the block back on the floor. + * + * Roughening moves every corner including the ones on the ground, and so + * does the per-level height jitter, so the block ends up balanced on + * three corners with daylight under the rest of it. The same treatment + * the oak's bole gets: flatten everything below the bottom band back to + * exactly zero, leaving all of the irregularity above that line. + */ + const position = block.getAttribute('position') + for (let i = 0; i < position.count; i += 1) { + if (position.getY(i) < H * 0.04) position.setY(i, 0) + } + position.needsUpdate = true + block.computeVertexNormals() + + // --- Water ------------------------------------------------------------ + // A film, not a body. It is a slab rather than a plane because a plane + // seen edge-on from a low angle vanishes, and a trough is looked into + // from above and along. Sunk into the floor rather than resting on it, + // because a surface laid exactly ON another leaves two faces in a plane. + const level = Math.max(0, Math.min(1, config.water)) + const depth = basin * level + const sink = H * 0.035 + const water = depth > H * 0.01 + ? boxGeometry( + [L - wall * 1.6, depth + sink, W - wall * 1.6], + [0, floor - sink + (depth + sink) / 2, 0], + new Color(tint('water', jitter(random, 0.03), 0.6)), + ) + : undefined + + return { + block: { slot: 'stone' as const, geometry: block }, + // Present and undefined when it is dry, never missing: the kit clears a + // part's anchor before it checks whether there is anything to put in + // it, so a key that is absent leaves last build's water hanging there. + water: water ? { slot: 'water' as const, geometry: water } : undefined, + } + }, + }, overrides) +} diff --git a/scripts/verify-model.ts b/scripts/verify-model.ts index 28bccd8..f1b44aa 100644 --- a/scripts/verify-model.ts +++ b/scripts/verify-model.ts @@ -57,6 +57,7 @@ import { createModel as createVeg } from '@/models/medieval-kit/vegetables/model import { createModel as createShield } from '@/models/medieval-kit/round-shield/model.ts' import { createModel as createForge } from '@/models/medieval-kit/forge-hearth/model.ts' import { createModel as createOak } from '@/models/medieval-kit/oak-tree/model.ts' +import { createModel as createTrough } from '@/models/medieval-kit/stone-trough/model.ts' const failures: string[] = [] function expect(label: string, condition: boolean): void { @@ -315,6 +316,10 @@ const CASES: readonly Case[] = [ parts: 3, ownSlot: 'leather', borrowSlot: 'oak', variants: [{ planks: 3 }, { lean: 0 }, { rivets: 0 }], maxSize: [1.3, 1.3, 0.9] }, + { id: 'stone-trough', make: as(createTrough), patch: { wall: 0.3, water: 0.8 }, + parts: 2, ownSlot: 'water', borrowSlot: 'stone', + variants: [{ water: 0 }, { wall: 0.12 }, { wall: 0.34 }, { height: 0.25 }], + maxSize: [2.8, 0.8, 1.1] }, { id: 'oak-tree', make: as(createOak), patch: { limbs: 11, spread: 1.5 }, parts: 3, ownSlot: 'leaf', borrowSlot: 'oak', variants: [{ leafiness: 0 }, { limbs: 3 }, { autumn: 1 }, { spread: 0.6 }, { height: 3 }], diff --git a/src/catalog.ts b/src/catalog.ts index 274d2d4..b6def7e 100644 --- a/src/catalog.ts +++ b/src/catalog.ts @@ -51,6 +51,7 @@ import { createModel as createVeg } from '@/models/medieval-kit/vegetables/model import { createModel as createShield } from '@/models/medieval-kit/round-shield/model.ts' import { createModel as createForge } from '@/models/medieval-kit/forge-hearth/model.ts' import { createModel as createOak } from '@/models/medieval-kit/oak-tree/model.ts' +import { createModel as createTrough } from '@/models/medieval-kit/stone-trough/model.ts' export interface ParamSpec { readonly key: string @@ -163,6 +164,7 @@ const FACTORIES: Readonly KitModel>> = { 'round-shield': as(createShield), 'forge-hearth': as(createForge), 'oak-tree': as(createOak), + 'stone-trough': as(createTrough), 'wooden-ladder': as(createLadder), 'wooden-fence': as(createFence), 'wooden-hoe': as(createHoe), @@ -319,6 +321,7 @@ const MEDIEVAL_ORDER = [ // the order that makes the scale of it land. 'iron-cauldron', 'hand-cart', 'vegetables', 'round-shield', 'forge-hearth', 'stone-well', + 'stone-trough', 'post-mill', // After the mill, because it is taller than the mill and half again as wide. // A tour that ends on the only living thing in the kit ends better than one diff --git a/src/models/medieval-kit/core/kit.ts b/src/models/medieval-kit/core/kit.ts index 387ac57..cc48ed8 100644 --- a/src/models/medieval-kit/core/kit.ts +++ b/src/models/medieval-kit/core/kit.ts @@ -161,6 +161,9 @@ const MOTTLE_BY_SLOT: Readonly> = { // the machinery that already reproduces that detail -- which is the third // time this kit has learned that, after straw's saturation and bark's value. leaf: 0.95, + // Barely mottled. Ripples are a shape, not a stain, and a surface this + // smooth shows speckle as dirt floating on it. + water: 0.2, } export function createKitModel< diff --git a/src/models/medieval-kit/core/materials.ts b/src/models/medieval-kit/core/materials.ts index 316558a..0ac6349 100644 --- a/src/models/medieval-kit/core/materials.ts +++ b/src/models/medieval-kit/core/materials.ts @@ -27,6 +27,7 @@ export type MedievalSlot = | 'char' // charcoal, pitch | 'stone' // dressed and rubble masonry | 'leaf' // living foliage + | 'water' // standing water /** * The material TYPE can differ per slot. `ember` is an unlit MeshBasicMaterial; @@ -47,6 +48,7 @@ export interface SlotMaterial { readonly char: MeshStandardMaterial readonly stone: MeshStandardMaterial readonly leaf: MeshStandardMaterial + readonly water: MeshStandardMaterial } export interface MedievalPalette { @@ -156,6 +158,36 @@ export interface MedievalPalette { * lit and shadowed alike. */ readonly leaf: Color + + /** + * Weathered limestone, which is NOT the same rock as `stone`. + * + * `stone` was measured off dressed and rubble masonry: hue 44, saturation + * 0.05 — a wall stone, grey, and grey because a wall is quarried and laid + * face out. A trough is one block left in the open for a century, and the + * same measurement on one reads hue 36, saturation 0.16, lightness 0.48: + * warmer, THREE TIMES more saturated, and lighter. Reaching for `stone` on + * it gives a concrete planter. + * + * Both are correct and neither replaces the other, which is why this is a + * palette key rather than an edit to `stone` — the well and the forge were + * each measured against their own references and are not this rock. + */ + readonly limestone: Color + + /** + * Standing water, and it is far less green than it feels. + * + * Sampled inside the reference trough's basin the film reads hue 39.5 — + * which is the hue of the stone underneath it, not a colour of its own. It + * is shallow and it is clear; what it does is DARKEN and slightly saturate + * whatever it lies on (lightness 0.48 down to 0.36, saturation 0.16 up to + * 0.23). So this is nearly neutral, barely cool, and it does its work + * through the material's transparency rather than through its hue. Painted + * the pond green a first-instinct would have reached for, the composite + * would have missed the reference by 100 degrees of hue. + */ + readonly water: Color } /** @@ -207,6 +239,8 @@ export const MEDIEVAL_PALETTE: MedievalPalette = { stone: new Color(0x6e6b63), charHot: new Color(0xc4441a), bark: new Color(0x585032), + limestone: new Color(0x94846b), + water: new Color(0x3b4e45), leaf: new Color(0x6d8632), } @@ -356,6 +390,21 @@ export function createMedievalMaterials( roughness: 0.93, metalness: 0, }), + // Water is a THIN TRANSPARENT FILM, not a body of liquid. Everything in + // this kit that holds water holds a few centimetres of it over a floor you + // can see, so the colour that reaches the eye is mostly what is underneath + // — which is why the opacity is the important number here and the hue is + // nearly not a number at all. Smooth, because a trough out of the wind is + // the one surface in this kit that reflects. + water: () => new MeshStandardMaterial({ + name: 'medieval-kit / standing water', + color: 0xffffff, + vertexColors: true, + roughness: 0.11, + metalness: 0, + transparent: true, + opacity: 0.72, + }), char: () => new MeshStandardMaterial({ name: 'medieval-kit / charcoal', color: 0xffffff, diff --git a/src/models/medieval-kit/stone-trough/model.ts b/src/models/medieval-kit/stone-trough/model.ts new file mode 100644 index 0000000..aed6c08 --- /dev/null +++ b/src/models/medieval-kit/stone-trough/model.ts @@ -0,0 +1,243 @@ +/** + * @medieval-kit/stone-trough + * + * A watering trough cut from one block of limestone. + * + * The kit could water nobody. It has a well, a bucket and a cauldron, and all + * three are things you carry water IN; a trough is the thing a village keeps + * water in, standing in the street outside the smithy where the horses are. + * + * It is not the same ROCK as the well. `stone` in this palette was measured + * off dressed and rubble masonry and is grey, because a wall is quarried and + * laid face out. One block left in the open for a century reads hue 36 and + * saturation 0.16 against the wall's 44 and 0.05 — warmer, three times more + * saturated, lighter. Hence `limestone`, and the rendered block now matches + * the reference to within a fifth of a degree of hue and 0.004 of lightness. + * + * What took three attempts was making it read as CARVED rather than sawn, and + * the two failures are worth keeping because they are opposite errors: + * + * 1. Each wall in two tiers, to give `roughenGeometry` more corners to move. + * The tiers' corners sit at different positions, so the hash moved them + * by different amounts and left a hard seam right round the block — a lid + * on a base. + * 2. One box per wall, roughened harder to compensate. A box has eight + * corners and every face is two triangles, so moving those corners folded + * each wall along its own diagonal. Not stone: creased cardboard. + * + * Both tried to get subdivision out of the wrong thing. The walls are + * `dishedSheetGeometry` — one continuous body with levels along its length, + * which is what that helper's own docstring says the trough wants. The rim + * undulates because each level carries its own height, the wall thickens and + * thins because each carries its own thickness, and there is no join anywhere + * for a seam to open in. + * + * The basin is made the way everything hollow in this kit is made: by not + * filling it. Four walls and a floor, no boolean, corners overlapping. + */ +import { Color, type BufferGeometry } from 'three' + +import { + boxGeometry, + createKitModel, + createTinter, + dishedSheetGeometry, + jitter, + mergeColoured, + roughenGeometry, + type SheetLevel, +} from '../core/index.ts' + +export interface StoneTroughConfig { + /** Along the trough (metres). */ + readonly length: number + /** Across it (metres). */ + readonly width: number + /** Height of the block (metres). */ + readonly height: number + /** Wall thickness as a fraction of the width. */ + readonly wall: number + /** How full it stands, as a fraction of the basin's depth. 0 is dry. */ + readonly water: number + readonly seed: number +} + +export const stoneTroughDefaults: StoneTroughConfig = { + length: 1.5, + width: 0.58, + height: 0.44, + // Heavy, but not as heavy as I first made it. A trough is a block with a + // dish taken out of it rather than a vessel, and at 0.27 the two walls came + // to more than half the width and the basin shut so far that a three-quarter + // view showed only its inner face. The reference's opening is about three + // fifths of the block across, which is this. + wall: 0.21, + // Nearly full, and that is the reference rather than a preference: its water + // stands a couple of centimetres under the rim. It is also the only level at + // which the water is VISIBLE from anywhere but straight above — at 0.55 the + // surface sits below the near rim and the trough reads as dry from every + // angle anyone will look at it from. + water: 0.85, + seed: 19, +} + +export type StoneTroughParts = 'block' | 'water' + +export function createModel(overrides: Partial = {}) { + return createKitModel({ + id: 'stone-trough', + defaults: stoneTroughDefaults, + slots: ['stone', 'water'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const L = Math.max(0.3, config.length) + const W = Math.max(0.2, config.width) + const H = Math.max(0.15, config.height) + const wall = Math.max(0.02, Math.min(0.4, config.wall)) * W + // The floor is thicker than the walls. A trough wears out from the + // inside and the bottom is what is left when it does. + const floor = H * 0.3 + const basin = H - floor + + /** + * One wall as a single sheet, laid along +X and centred on the origin. + * + * `dishedSheetGeometry` builds in the XY plane: levels run along Y, + * `halfWidth` spans X, `thickness` spans Z. One turn about Z lays that + * down so the levels run along the trough and the half-width becomes the + * wall's HEIGHT — which is the whole trick, because every level can then + * carry a different height and the rim undulates on its own, with no + * roughening involved and no seam to tear open. + */ + const wallSheet = (len: number, thick: number, tall: number, lift: number): BufferGeometry => { + const steps = 7 + const levels: SheetLevel[] = [] + for (let i = 0; i < steps; i += 1) { + levels.push({ + y: len * (i / (steps - 1)), + halfWidth: (tall / 2) * (1 + jitter(random, 0.035)), + thickness: thick * (0.88 + random() * 0.24), + curve: 0, + }) + } + const sheet = dishedSheetGeometry(levels, 2, tint('limestone', lift, 0.85)) + sheet.rotateZ(-Math.PI / 2) + sheet.translate(-len / 2, 0, 0) + return sheet + } + + const stone: BufferGeometry[] = [] + + /** + * The solid bottom, and the ONLY thing that touches the ground. + * + * Built as four walls standing on the floor, every piece had a face on + * the ground plane, and where the corners overlapped — which is exactly + * where they are meant to overlap — two downward faces shared the plane + * y = 0. The checker found it twice, and the second time was after I had + * "fixed" it by lifting the basin floor, which only moved the pairing + * from floor-against-wall to wall-against-wall. + * + * The answer is not to separate the overlaps but to stop there being + * four things down there. A trough IS solid below the water line: one + * block from the ground to the basin, and the walls stand on top of it. + * One piece on the ground, one bottom face, nothing to pair with. + */ + const foot = wall * 0.5 + stone.push(boxGeometry( + [L - foot, floor, W - foot], + [0, floor / 2, 0], + new Color(tint('limestone', -0.05, 0.7)), + )) + + /** + * The four walls, sunk into that block by DIFFERENT amounts. + * + * Sunk, so their undersides are buried in solid stone rather than + * meeting its top face in a plane. By different amounts, because the + * long pair and the end pair overlap each other at the corners, and two + * buried faces in one plane are still two faces in one plane whether + * anybody can see them or not. + * + * The WALLS are flush with the block's nominal outline and the base is + * tucked in behind them, not the other way round. Standing the walls + * inset on a full-width base put a sharp ledge right round the bottom and + * the thing read as a planter on a concrete plinth. Tucked under, the + * base is invisible from above and the block is one face from rim to + * ground. + * + * Their outer faces cannot land in the base's plane by accident either: + * each level of a sheet carries its own thickness, so a wall's outer + * surface is a run of slightly different planes rather than one. + */ + const inset = 0 + const longSink = H * 0.06 + const endSink = H * 0.095 + for (const side of [-1, 1] as const) { + const w = wallSheet(L - inset * 2, wall, basin + longSink, jitter(random, 0.04)) + stone.push(w.translate( + 0, + floor - longSink + (basin + longSink) / 2, + (side * (W - wall - inset * 2)) / 2, + )) + } + for (const side of [-1, 1] as const) { + const end = wallSheet(W - wall * 0.5, wall, basin + endSink, 0.03 + jitter(random, 0.04)) + // Built along +X like the others, then turned a quarter about Y, which + // sends +X to -Z and leaves the height alone. + end.rotateY(Math.PI / 2) + stone.push(end.translate( + (side * (L - wall - inset * 2)) / 2, + floor - endSink + (basin + endSink) / 2, + 0, + )) + } + + const block = mergeColoured(stone) + // Light, now that the sheets carry the shape themselves. This is grain + // on a face, not the shape of the block. + roughenGeometry(block, wall * 0.09, { salt: 41, scaleY: 0.5 }) + + /** + * Put the block back on the floor. + * + * Roughening moves every corner including the ones on the ground, and so + * does the per-level height jitter, so the block ends up balanced on + * three corners with daylight under the rest of it. The same treatment + * the oak's bole gets: flatten everything below the bottom band back to + * exactly zero, leaving all of the irregularity above that line. + */ + const position = block.getAttribute('position') + for (let i = 0; i < position.count; i += 1) { + if (position.getY(i) < H * 0.04) position.setY(i, 0) + } + position.needsUpdate = true + block.computeVertexNormals() + + // --- Water ------------------------------------------------------------ + // A film, not a body. It is a slab rather than a plane because a plane + // seen edge-on from a low angle vanishes, and a trough is looked into + // from above and along. Sunk into the floor rather than resting on it, + // because a surface laid exactly ON another leaves two faces in a plane. + const level = Math.max(0, Math.min(1, config.water)) + const depth = basin * level + const sink = H * 0.035 + const water = depth > H * 0.01 + ? boxGeometry( + [L - wall * 1.6, depth + sink, W - wall * 1.6], + [0, floor - sink + (depth + sink) / 2, 0], + new Color(tint('water', jitter(random, 0.03), 0.6)), + ) + : undefined + + return { + block: { slot: 'stone' as const, geometry: block }, + // Present and undefined when it is dry, never missing: the kit clears a + // part's anchor before it checks whether there is anything to put in + // it, so a key that is absent leaves last build's water hanging there. + water: water ? { slot: 'water' as const, geometry: water } : undefined, + } + }, + }, overrides) +}