diff --git a/media/kit.png b/media/kit.png index d27b88d..415fc84 100644 Binary files a/media/kit.png and b/media/kit.png differ diff --git a/models.lock.json b/models.lock.json index f23822a..b52eacd 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-23T06:28:21.677Z", + "installedAt": "2026-08-23T07:16:33.689Z", "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-23T06:28:21.655Z", + "installedAt": "2026-08-23T07:16:33.667Z", "files": [ { "path": "src\\models\\medieval-kit\\core\\geometry.ts", @@ -94,7 +94,7 @@ }, { "path": "src\\models\\medieval-kit\\core\\materials.ts", - "sourceHash": "3bb775f0c90186daeb1afc8aa1a662b5b1b693dc3764cf3de235e978ff3e72b7" + "sourceHash": "b8732fb49a51716c21aa89357f8f37b7290bc6eb73007cd13ab0b8eb0da089a1" }, { "path": "src\\models\\medieval-kit\\core\\random.ts", @@ -106,7 +106,7 @@ }, { "path": "src\\models\\medieval-kit\\core\\kit.ts", - "sourceHash": "ff20b1ec0c81cf73b4b22f48a7d539c73e272f07ace1231b2c625699ae99b00e" + "sourceHash": "ef4905d2ab9a4fd587cc1e10e5fa1ed878656f7cf93e4479e8d3cd43cc56c8f6" }, { "path": "src\\models\\medieval-kit\\core\\tool.ts", @@ -129,7 +129,7 @@ "address": "@medieval-kit/wooden-crate", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T06:28:21.682Z", + "installedAt": "2026-08-23T07:16:33.694Z", "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-23T06:28:21.689Z", + "installedAt": "2026-08-23T07:16:33.700Z", "files": [], "dependencies": [] }, @@ -152,7 +152,7 @@ "address": "@medieval-kit/iron-anvil", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T06:28:21.664Z", + "installedAt": "2026-08-23T07:16:33.675Z", "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-23T06:28:21.680Z", + "installedAt": "2026-08-23T07:16:33.692Z", "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-23T06:28:21.683Z", + "installedAt": "2026-08-23T07:16:33.695Z", "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-23T06:28:21.684Z", + "installedAt": "2026-08-23T07:16:33.696Z", "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-23T06:28:21.686Z", + "installedAt": "2026-08-23T07:16:33.697Z", "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-23T06:28:21.687Z", + "installedAt": "2026-08-23T07:16:33.698Z", "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-23T06:28:21.688Z", + "installedAt": "2026-08-23T07:16:33.699Z", "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-23T06:28:21.689Z", + "installedAt": "2026-08-23T07:16:33.700Z", "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-23T06:28:21.659Z", + "installedAt": "2026-08-23T07:16:33.671Z", "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-23T06:28:21.668Z", + "installedAt": "2026-08-23T07:16:33.679Z", "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-23T06:28:21.675Z", + "installedAt": "2026-08-23T07:16:33.687Z", "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-23T06:28:21.681Z", + "installedAt": "2026-08-23T07:16:33.693Z", "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-23T06:28:21.662Z", + "installedAt": "2026-08-23T07:16:33.674Z", "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-23T06:28:21.671Z", + "installedAt": "2026-08-23T07:16:33.682Z", "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-23T06:28:21.678Z", + "installedAt": "2026-08-23T07:16:33.690Z", "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-23T06:28:21.667Z", + "installedAt": "2026-08-23T07:16:33.678Z", "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-23T06:28:21.669Z", + "installedAt": "2026-08-23T07:16:33.680Z", "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-23T06:28:21.673Z", + "installedAt": "2026-08-23T07:16:33.685Z", "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-23T06:28:21.657Z", + "installedAt": "2026-08-23T07:16:33.670Z", "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-23T06:28:21.665Z", + "installedAt": "2026-08-23T07:16:33.676Z", "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-23T06:28:21.674Z", + "installedAt": "2026-08-23T07:16:33.686Z", "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-23T06:28:21.660Z", + "installedAt": "2026-08-23T07:16:33.672Z", "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-23T06:28:21.661Z", + "installedAt": "2026-08-23T07:16:33.673Z", "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-23T06:28:21.666Z", + "installedAt": "2026-08-23T07:16:33.677Z", "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-23T06:28:21.676Z", + "installedAt": "2026-08-23T07:16:33.688Z", "files": [ { "path": "src\\models\\medieval-kit\\wicker-basket\\model.ts", @@ -527,7 +527,7 @@ "address": "@medieval-kit/post-mill", "source": "file:my-registry/dist/registry.json", "version": "workspace", - "installedAt": "2026-08-23T06:28:21.672Z", + "installedAt": "2026-08-23T07:16:33.683Z", "files": [ { "path": "src\\models\\medieval-kit\\post-mill\\model.ts", @@ -537,6 +537,21 @@ "dependencies": [ "three@>=0.185.0" ] + }, + "@medieval-kit/stone-well": { + "address": "@medieval-kit/stone-well", + "source": "file:my-registry/dist/registry.json", + "version": "workspace", + "installedAt": "2026-08-23T07:16:33.684Z", + "files": [ + { + "path": "src\\models\\medieval-kit\\stone-well\\model.ts", + "sourceHash": "9ebb0b37eacf8258944f044bde2a4e5de0ef8d5f54d78f50676fbb70a01d1490" + } + ], + "dependencies": [ + "three@>=0.185.0" + ] } } } diff --git a/my-registry/README.md b/my-registry/README.md index 5e62eb1..a24c757 100644 --- a/my-registry/README.md +++ b/my-registry/README.md @@ -26,7 +26,7 @@ Configure `models.json` first so the namespace resolves: ## Models -28 models and one shared lib. Addresses are `@medieval-kit/`. This table is +29 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,9 +60,10 @@ 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 | | +| `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 | | -**20 667 triangles** in total. The whole kit in one scene costs less than a +**22 043 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 @@ -125,7 +126,7 @@ rebuilds topology and is not cheap. Anything that changes per frame belongs in ## Material slots -Eleven slots, and each one exists because a single material could not carry the +Twelve slots, and each one exists because a single material could not carry the difference. | Slot | What it covers | Why it is separate | @@ -141,6 +142,7 @@ difference. | `produce` | fruit and vegetable skin | given straw's roughness, an apple would look like dry grass | | `ember` | flame | `MeshBasicMaterial` — it does not receive light, it emits | | `char` | charcoal and pitch | — | +| `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 entirely while ambient occlusion and mottle are baked. The reason is simple — diff --git a/my-registry/meta.ts b/my-registry/meta.ts index 2582069..4cc4988 100644 --- a/my-registry/meta.ts +++ b/my-registry/meta.ts @@ -450,6 +450,24 @@ export const MODEL_META: Readonly> = { materialSlots: ['oak'], parts: ['rails', 'rungs'], }, + 'stone-well': { + title: 'Stone Well', + description: + 'Village well: a drystone kerb, a timber frame over it, and a windlass with rope and bucket.', + category: 'Structure', + tags: ['medieval', 'lowpoly', 'structure', 'procedural'], + controls: { + radius: { type: 'number', label: 'Kerb radius', min: 0.35, max: 1.1, step: 0.01, unit: 'm' }, + wallHeight: { type: 'number', label: 'Kerb height', min: 0.3, max: 1.1, step: 0.02, unit: 'm' }, + courses: { type: 'number', label: 'Stone courses', min: 2, max: 7, step: 1 }, + blocks: { type: 'number', label: 'Blocks per course', min: 6, max: 18, step: 1 }, + frameHeight: { type: 'number', label: 'Frame height', min: 1.2, max: 2.8, step: 0.05, unit: 'm' }, + depth: { type: 'number', label: 'Bucket drop', min: 0, max: 1, step: 0.02 }, + seed: { type: 'number', label: 'Variation seed', min: 1, max: 64, step: 1 }, + }, + materialSlots: ['stone', 'oak', 'iron', 'cloth'], + parts: ['kerb', 'frame', 'windlass', 'bucket'], + }, 'post-mill': { title: 'Post Mill', description: diff --git a/my-registry/models/core/kit.ts b/my-registry/models/core/kit.ts index 78030ce..5b9f3cc 100644 --- a/my-registry/models/core/kit.ts +++ b/my-registry/models/core/kit.ts @@ -142,6 +142,10 @@ const MOTTLE_BY_SLOT: Readonly> = { brass: 0.35, steel: 0.22, glass: 0.15, + // Between timber and iron. Rubble masonry varies block to block, but each + // block is fairly even in itself, so the mottle wants to read at the scale + // of a stone rather than of a grain. + stone: 0.75, ember: 0, // a flame is not mottled: its colour is already the final colour } diff --git a/my-registry/models/core/materials.ts b/my-registry/models/core/materials.ts index e463473..2d71bb3 100644 --- a/my-registry/models/core/materials.ts +++ b/my-registry/models/core/materials.ts @@ -25,6 +25,7 @@ export type MedievalSlot = | 'produce' // fruit and vegetable skin | 'ember' // flame — does not take light, it emits it | 'char' // charcoal, pitch + | 'stone' // dressed and rubble masonry /** * The material TYPE can differ per slot. `ember` is an unlit MeshBasicMaterial; @@ -43,6 +44,7 @@ export interface SlotMaterial { readonly produce: MeshStandardMaterial readonly ember: MeshBasicMaterial readonly char: MeshStandardMaterial + readonly stone: MeshStandardMaterial } export interface MedievalPalette { @@ -92,6 +94,17 @@ export interface MedievalPalette { readonly char: Color /** Charcoal that is still glowing. */ readonly charHot: Color + /** + * Masonry. + * + * The kit had no stone at all, which for a medieval catalogue is a hole + * rather than an omission: a well, a trough, a millstone, a boundary wall + * and a hearth are all stone before they are anything else. Its colour is + * close to weathered oak on purpose -- what separates the two at a glance is + * not hue but that stone scatters light completely flat, which is carried by + * the material's roughness rather than by the palette. + */ + readonly stone: Color } /** @@ -140,6 +153,7 @@ export const MEDIEVAL_PALETTE: MedievalPalette = { ember: new Color(0xffd27a), emberTip: new Color(0xd8571b), char: new Color(0x241f1c), + stone: new Color(0x6e6b63), charHot: new Color(0xc4441a), } @@ -267,6 +281,15 @@ export function createMedievalMaterials( vertexColors: true, toneMapped: false, }), + stone: () => new MeshStandardMaterial({ + name: 'medieval-kit / stone', + color: 0xffffff, + vertexColors: true, + // Rougher than anything else here. Dressed stone is not polished and + // rubble certainly is not; any sheen at all reads as ceramic. + roughness: 0.97, + metalness: 0, + }), char: () => new MeshStandardMaterial({ name: 'medieval-kit / charcoal', color: 0xffffff, diff --git a/my-registry/models/stone-well/model.ts b/my-registry/models/stone-well/model.ts new file mode 100644 index 0000000..7a007d7 --- /dev/null +++ b/my-registry/models/stone-well/model.ts @@ -0,0 +1,387 @@ +/** + * @medieval-kit/stone-well + * + * A village well: a drystone kerb, a timber frame over it, and a windlass to + * wind the bucket up on. + * + * The kerb is the point of the thing and it is worth saying why. A well is a + * hole; what makes it an OBJECT is the ring of stone built round its mouth, and + * that ring is there for a reason — it keeps the surface water, and whatever the + * surface water is carrying, from running back down into the drinking water. So + * the courses are laid dry, staggered, and stand well proud of the ground. + * + * Four parts: + * + * - `kerb` — the stone ring. Every block is placed individually, because a + * turned cylinder with lines drawn on it reads as a pot. + * - `frame` — two uprights standing OUTSIDE the kerb, and the head beam + * across them with their tenons showing through it. + * - `windlass`— the roller between the uprights, its end collars, and the + * crank. The rope is wound on the middle of the roller. + * - `bucket` — rope and bucket, hung from the roller. Its origin is the + * roller's axis, so `setDepth` lowers it down the shaft without + * moving anything else. + * + * This is the model that brought `stone` into the palette. The kit had no + * masonry at all, which for a medieval catalogue is a hole rather than an + * omission. + */ +import { Color, type BufferGeometry } from 'three' + +import { + bandGeometry, + boxGeometry, + chamferedBoxGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + roughenGeometry, + staveGeometry, + taperedBoxGeometry, + type Level, +} from '../core/index.ts' + +export interface StoneWellConfig { + /** Outer radius of the stone kerb (metres). */ + readonly radius: number + /** Height of the kerb above the ground (metres). */ + readonly wallHeight: number + /** Courses of stone. */ + readonly courses: number + /** Blocks in each course. */ + readonly blocks: number + /** Height from the ground to the top of the head beam (metres). */ + readonly frameHeight: number + /** How far down the bucket hangs. 0 = at the roller, 1 = at the water. */ + readonly depth: number + readonly seed: number +} + +export const stoneWellDefaults: StoneWellConfig = { + radius: 0.62, + wallHeight: 0.66, + courses: 4, + blocks: 11, + frameHeight: 1.95, + depth: 0.34, + seed: 17, +} + +export type StoneWellParts = 'kerb' | 'frame' | 'windlass' | 'bucket' + +export interface StoneWellActions { + /** Sends the bucket down (1) or brings it up (0). */ + setDepth(t: number): void + depth(): number + /** Winds continuously until stopped. Positive winds up. */ + setWinding(speed: number): void +} + +export function createModel(overrides: Partial = {}) { + let depth = 0 + let winding = 0 + let travel = 0 + /** + * Where the part's own origin put the anchor. + * + * `origin` places the anchor at the roller's axis at build time, and the + * geometry is authored around it. Writing an absolute `position.y` here + * therefore DESTROYS that placement -- which is what the first version did, + * setting it to 0 and dropping the whole rope and bucket by the height of the + * roller, so the rope started a hand's width below the barrel it hangs from. + * Everything the actions do is now an offset from this. + */ + let restY = 0 + + return createKitModel({ + id: 'stone-well', + defaults: stoneWellDefaults, + slots: ['stone', 'oak', 'iron', 'cloth'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = config.frameHeight + const floor = -H / 2 + const R = config.radius + const wall = R * 0.34 + + // --- Kerb --------------------------------------------------------------- + const masonry: BufferGeometry[] = [] + const courses = Math.max(1, Math.round(config.courses)) + const blocks = Math.max(5, Math.round(config.blocks)) + const courseH = config.wallHeight / courses + const midR = R - wall / 2 + + for (let c = 0; c < courses; c += 1) { + // Every other course is offset by half a block: a joint running + // straight up through four courses is a crack waiting to happen, and a + // waller knows it. It is also what stops the ring reading as a stack of + // identical rings. + const phase = (c % 2) * 0.5 + for (let b = 0; b < blocks; b += 1) { + const a = ((b + phase) / blocks) * Math.PI * 2 + const arc = (Math.PI * 2 * midR) / blocks + // Plain tapered boxes, not chamfered ones. A chamfer is 44 triangles + // against 12, and at forty-four blocks that is 1 900 of them spent on + // edges the `roughenGeometry` pass below softens anyway. Stone is the + // one material in this kit where a sharp arris is not wrong. + // ARC first, WALL second. `rotateY(a)` carries the footprint's +Z out + // along the radius and its +X round the circumference, so writing the + // wall thickness first put every block across the ring instead of + // along it: each one stuck a block's length out of a wall a block's + // width thick, and the kerb came out as rubble thrown at a circle. + // The variation is small on purpose. At +-10% on the arc and +-9% on + // the thickness, every block sat at its own radius and its own width: + // the ring came out as rubble rather than as courses, and a waller + // who laid it like that would be looking for other work. A dry wall + // is irregular in the way a hand-cut stone is irregular, which is a + // few percent, not a tenth. + // Blocks are cut a little LONGER than their share of the arc, and + // courses a little taller than their share of the height, so + // neighbours bite into each other. + // + // A flat-faced box on a curve cannot close the joint at its outer + // corner: the chord is shorter than the arc, so anything sized to its + // exact share leaves a wedge of daylight at every joint and the wall + // reads as a ring of separate stones. Letting them overlap is the + // same rule the rest of the kit follows for joints, and it is safe + // here because each block is rotated to its own angle, so no two + // adjoining faces are parallel. + const block = taperedBoxGeometry( + [arc * (1.04 + jitter(random, 0.03)), wall * (0.99 + jitter(random, 0.04))], + [arc * (1.02 + jitter(random, 0.03)), wall * (0.95 + jitter(random, 0.04))], + courseH * (1.03 + jitter(random, 0.025)), + [0, 0, 0], + tint('stone', jitter(random, 0.09)), + ) + // Built facing +Z and swung round: rotating first and placing second + // is what keeps each block square to the ring rather than to the axes. + block.rotateY(a) + block.translate( + Math.sin(a) * midR, + floor + courseH * (c + 0.5), + Math.cos(a) * midR, + ) + masonry.push(block) + } + } + // Rough dressing. Small: the blocks are already irregular in size, and + // displacing them further only opens the dry joints between them. + const kerb = mergeColoured(masonry) + roughenGeometry(kerb, wall * 0.03, { salt: 13 }) + + // --- Frame -------------------------------------------------------------- + const timber: BufferGeometry[] = [] + const postSide = R * 0.24 + const postX = R + postSide * 0.55 + const beamH = R * 0.2 + const beamY = floor + H - beamH / 2 + // The uprights run PAST the beam and show as tenons on top of it. + const postTop = floor + H + beamH * 0.34 + + for (const side of [-1, 1]) { + timber.push(chamferedBoxGeometry( + [postSide * 1.06, postSide * 1.06], + [postSide * 0.94, postSide * 0.94], + postTop - floor, + postSide * 0.09, + [side * postX, (floor + postTop) / 2, 0], + tint('oak', -0.03 + jitter(random, 0.04)), + )) + } + timber.push(chamferedBoxGeometry( + [postX * 2 + postSide * 2.2, beamH * 0.86], + [postX * 2 + postSide * 1.9, beamH * 0.78], + beamH, + beamH * 0.09, + [0, beamY, 0], + tint('oak', 0.03), + )) + + // --- Windlass ----------------------------------------------------------- + // The roller sits well below the beam: the rope has to come off it and + // fall clear down the middle of the well, and a roller tucked under the + // beam would foul it. + const rollerY = floor + H * 0.62 + const rollerR = R * 0.15 + const rollerHalf = postX - postSide * 0.25 + const gear: BufferGeometry[] = [] + const iron: BufferGeometry[] = [] + + const rollerProfile: Level[] = [ + { y: -rollerHalf, radius: rollerR * 0.86 }, + { y: -rollerHalf * 0.88, radius: rollerR }, + { y: rollerHalf * 0.88, radius: rollerR }, + { y: rollerHalf, radius: rollerR * 0.86 }, + ] + const roller = latheGeometry(rollerProfile, 9, [0, 0, 0], tint('oak', 0.02, 1.2)) + // Built along Y like every lathe here; +90 about Z lays it along X, + // spanning the gap between the uprights. + roller.rotateZ(Math.PI / 2) + roller.translate(0, rollerY, 0) + gear.push(roller) + + // End collars: the raised shoulders that keep the rope from wandering off + // the barrel and into the bearing. + for (const side of [-1, 1]) { + const collar = bandGeometry( + rollerR * 1.5, 0, rollerR * 0.55, rollerR * 0.5, 9, + tint('oak', -0.06, 1.2), { inner: true }, + ) + collar.rotateZ(Math.PI / 2) + collar.translate(side * rollerHalf * 0.62, rollerY, 0) + gear.push(collar) + } + + // The rope wound on the barrel, between the collars. + const coil = bandGeometry( + rollerR * 1.34, 0, rollerR * 1.05, rollerR * 0.34, 9, + tint('cloth', -0.04, 1.3), { inner: true }, + ) + coil.rotateZ(Math.PI / 2) + coil.translate(0, rollerY, 0) + gear.push(coil) + + // Crank: an iron elbow through the upright with a wooden grip on the end. + const crankOut = postX + postSide * 0.9 + iron.push(taperedBoxGeometry( + [rollerR * 0.5, rollerR * 0.5], + [rollerR * 0.42, rollerR * 0.42], + postSide * 2.4, + [0, 0, 0], + tint('iron', 0.02, 0.7), + ).rotateZ(Math.PI / 2).translate(postX + postSide * 0.5, rollerY, 0)) + iron.push(boxGeometry( + [rollerR * 0.46, rollerR * 2.6, rollerR * 0.46], + [crankOut, rollerY - rollerR * 1.2, 0], + new Color(tint('iron', -0.02, 0.7)), + )) + gear.push(taperedBoxGeometry( + [rollerR * 0.72, rollerR * 0.72], + [rollerR * 0.58, rollerR * 0.58], + rollerR * 2.1, + [0, 0, 0], + tint('oak', 0.05), + ).rotateZ(Math.PI / 2).translate(crankOut + rollerR * 0.9, rollerY - rollerR * 2.2, 0)) + + // --- Rope and bucket ---------------------------------------------------- + // Authored hanging from the ROLLER'S AXIS, which is where the part's + // origin goes, so lowering the bucket is one rotation-free translation. + const bucketR = R * 0.3 + const bucketH = bucketR * 1.5 + const fall = H * 0.34 * Math.min(1, Math.max(0, config.depth)) + const hanging: BufferGeometry[] = [] + + // The rope from barrel to bail. It has to stretch with the drop, so its + // length is derived rather than fixed. + // The rope leaves the COIL, not the axis. + // + // Starting it at y = 0 put its whole surface inside the roller's hollow + // interior, touching nothing -- these are surfaces, not solids, so a rope + // threaded up the middle of a barrel is joined to it only in the sense + // that it is inside it. The support check called the bucket floating and + // it was right. Beginning just inside the coil's inner face means the + // rope crosses the coil's outer face on its way down. + // Inside the coil's MATERIAL, which is the band from 1.0 to 1.34 of the + // roller radius -- not at 0.95, which is the hole through the middle of + // it. Starting there the rope hung in the ring's eye touching nothing; + // starting at 1.15 it begins within the wound rope and crosses its outer + // face on the way down. + const ropeTop = -rollerR * 1.15 + const ropeLength = Math.max(rollerR * 1.6, fall) - ropeTop + hanging.push(latheGeometry( + [ + { y: ropeTop - ropeLength, radius: rollerR * 0.11 }, + { y: ropeTop, radius: rollerR * 0.12 }, + ] as Level[], + 6, [0, 0, 0], tint('cloth', -0.08, 1.3), + { capTop: false, capBottom: false }, + )) + + // Bail: the iron loop the bucket hangs by. + const bail = bandGeometry( + bucketR * 0.94, 0, rollerR * 0.16, rollerR * 0.13, 9, + tint('iron', 0.04, 0.7), { inner: true }, + ) + bail.rotateX(Math.PI / 2) + bail.translate(0, ropeTop - ropeLength - bucketR * 0.5, 0) + hanging.push(bail) + + // A small stave bucket, built the way the kit's bucket is: separate + // boards, not a turned cup. + const staves = 11 + const step = (Math.PI * 2) / staves + const bucketY = ropeTop - ropeLength - bucketR * 0.5 - bucketH * 0.52 + for (let i = 0; i < staves; i += 1) { + hanging.push(staveGeometry( + [ + { y: bucketY - bucketH / 2, radius: bucketR * 0.82 }, + { y: bucketY + bucketH / 2, radius: bucketR }, + ] as Level[], + i * step + step * 0.06, + (i + 1) * step - step * 0.06, + bucketR * 0.14, + tint('oak', jitter(random, 0.06)), + )) + } + for (const at of [-0.34, 0.32]) { + const hoop = bandGeometry( + bucketR * (at < 0 ? 0.88 : 1.01), bucketY + bucketH * at, + bucketH * 0.1, bucketR * 0.05, staves, + tint('iron', 0.03, 0.7), + ) + hanging.push(hoop) + } + hanging.push(latheGeometry( + [ + { y: bucketY - bucketH * 0.44, radius: bucketR * 0.78 }, + { y: bucketY - bucketH * 0.38, radius: bucketR * 0.8 }, + ] as Level[], + staves, [0, 0, 0], tint('oak', -0.1), + )) + + return { + kerb: { slot: 'stone' as const, geometry: kerb }, + frame: { slot: 'oak' as const, geometry: mergeColoured(timber) }, + windlass: { + slot: 'oak' as const, + geometry: mergeColoured(gear), + extras: [{ slot: 'iron' as const, geometry: mergeColoured(iron) }], + }, + bucket: { + slot: 'oak' as const, + geometry: mergeColoured(hanging), + origin: [0, rollerY, 0] as const, + }, + } + }, + + actions: ({ parts, getConfig }) => { + depth = getConfig().depth + travel = 0 + restY = parts.bucket.anchor.position.y + return { + setDepth: (t) => { + winding = 0 + depth = Math.min(1, Math.max(0, t)) + travel = 0 + }, + depth: () => depth, + setWinding: (speed) => { winding = speed }, + } + }, + + update: (deltaSeconds, { parts, getConfig }) => { + if (winding === 0) return + // Winding moves the bucket by TRANSLATION rather than by rebuilding the + // rope, so the action costs nothing per frame. The rope's own length is + // fixed by `depth` at build time; between rebuilds the bucket slides on + // it, which is exactly what a bucket on a rope does. + const H = getConfig().frameHeight + travel = Math.min(H * 0.34, Math.max(-H * 0.2, travel + winding * deltaSeconds * H * 0.18)) + parts.bucket.anchor.position.y = restY + travel + }, + }, overrides) +} diff --git a/scripts/verify-model.ts b/scripts/verify-model.ts index ee9711c..2425ef1 100644 --- a/scripts/verify-model.ts +++ b/scripts/verify-model.ts @@ -50,6 +50,7 @@ import { createModel as createPhial } from '@/models/medieval-kit/glass-phial/mo import { createModel as createPouch } from '@/models/medieval-kit/coin-pouch/model.ts' 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' const failures: string[] = [] function expect(label: string, condition: boolean): void { @@ -304,6 +305,10 @@ 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: 'stone-well', make: as(createWell), patch: { courses: 6, blocks: 15 }, + parts: 4, ownSlot: 'stone', borrowSlot: 'oak', + variants: [{ courses: 2 }, { depth: 1 }, { blocks: 6 }], + maxSize: [2.2, 2.2, 1.7] }, { id: 'post-mill', make: as(createMill), patch: { sailBars: 12, ladderRungs: 17 }, parts: 4, ownSlot: 'oak', borrowSlot: 'iron', variants: [{ sailBars: 3 }, { sailWidth: 0.28 }, { height: 3.5 }], diff --git a/src/catalog.ts b/src/catalog.ts index 73f5497..47982fb 100644 --- a/src/catalog.ts +++ b/src/catalog.ts @@ -44,6 +44,7 @@ import { createModel as createPhial } from '@/models/medieval-kit/glass-phial/mo import { createModel as createPouch } from '@/models/medieval-kit/coin-pouch/model.ts' 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' export interface ParamSpec { readonly key: string @@ -149,6 +150,7 @@ const FACTORIES: Readonly KitModel>> = { 'coin-pouch': as(createPouch), 'wicker-basket': as(createBasket), 'post-mill': as(createMill), + 'stone-well': as(createWell), 'wooden-ladder': as(createLadder), 'wooden-fence': as(createFence), 'wooden-hoe': as(createHoe), @@ -303,6 +305,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. + 'stone-well', 'post-mill', ] as const diff --git a/src/models/medieval-kit/core/kit.ts b/src/models/medieval-kit/core/kit.ts index fa93aa6..6279130 100644 --- a/src/models/medieval-kit/core/kit.ts +++ b/src/models/medieval-kit/core/kit.ts @@ -142,6 +142,10 @@ const MOTTLE_BY_SLOT: Readonly> = { brass: 0.35, steel: 0.22, glass: 0.15, + // Between timber and iron. Rubble masonry varies block to block, but each + // block is fairly even in itself, so the mottle wants to read at the scale + // of a stone rather than of a grain. + stone: 0.75, ember: 0, // a flame is not mottled: its colour is already the final colour } diff --git a/src/models/medieval-kit/core/materials.ts b/src/models/medieval-kit/core/materials.ts index a944c1f..fca5194 100644 --- a/src/models/medieval-kit/core/materials.ts +++ b/src/models/medieval-kit/core/materials.ts @@ -25,6 +25,7 @@ export type MedievalSlot = | 'produce' // fruit and vegetable skin | 'ember' // flame — does not take light, it emits it | 'char' // charcoal, pitch + | 'stone' // dressed and rubble masonry /** * The material TYPE can differ per slot. `ember` is an unlit MeshBasicMaterial; @@ -43,6 +44,7 @@ export interface SlotMaterial { readonly produce: MeshStandardMaterial readonly ember: MeshBasicMaterial readonly char: MeshStandardMaterial + readonly stone: MeshStandardMaterial } export interface MedievalPalette { @@ -92,6 +94,17 @@ export interface MedievalPalette { readonly char: Color /** Charcoal that is still glowing. */ readonly charHot: Color + /** + * Masonry. + * + * The kit had no stone at all, which for a medieval catalogue is a hole + * rather than an omission: a well, a trough, a millstone, a boundary wall + * and a hearth are all stone before they are anything else. Its colour is + * close to weathered oak on purpose -- what separates the two at a glance is + * not hue but that stone scatters light completely flat, which is carried by + * the material's roughness rather than by the palette. + */ + readonly stone: Color } /** @@ -140,6 +153,7 @@ export const MEDIEVAL_PALETTE: MedievalPalette = { ember: new Color(0xffd27a), emberTip: new Color(0xd8571b), char: new Color(0x241f1c), + stone: new Color(0x6e6b63), charHot: new Color(0xc4441a), } @@ -267,6 +281,15 @@ export function createMedievalMaterials( vertexColors: true, toneMapped: false, }), + stone: () => new MeshStandardMaterial({ + name: 'medieval-kit / stone', + color: 0xffffff, + vertexColors: true, + // Rougher than anything else here. Dressed stone is not polished and + // rubble certainly is not; any sheen at all reads as ceramic. + roughness: 0.97, + metalness: 0, + }), char: () => new MeshStandardMaterial({ name: 'medieval-kit / charcoal', color: 0xffffff, diff --git a/src/models/medieval-kit/stone-well/model.ts b/src/models/medieval-kit/stone-well/model.ts new file mode 100644 index 0000000..7a007d7 --- /dev/null +++ b/src/models/medieval-kit/stone-well/model.ts @@ -0,0 +1,387 @@ +/** + * @medieval-kit/stone-well + * + * A village well: a drystone kerb, a timber frame over it, and a windlass to + * wind the bucket up on. + * + * The kerb is the point of the thing and it is worth saying why. A well is a + * hole; what makes it an OBJECT is the ring of stone built round its mouth, and + * that ring is there for a reason — it keeps the surface water, and whatever the + * surface water is carrying, from running back down into the drinking water. So + * the courses are laid dry, staggered, and stand well proud of the ground. + * + * Four parts: + * + * - `kerb` — the stone ring. Every block is placed individually, because a + * turned cylinder with lines drawn on it reads as a pot. + * - `frame` — two uprights standing OUTSIDE the kerb, and the head beam + * across them with their tenons showing through it. + * - `windlass`— the roller between the uprights, its end collars, and the + * crank. The rope is wound on the middle of the roller. + * - `bucket` — rope and bucket, hung from the roller. Its origin is the + * roller's axis, so `setDepth` lowers it down the shaft without + * moving anything else. + * + * This is the model that brought `stone` into the palette. The kit had no + * masonry at all, which for a medieval catalogue is a hole rather than an + * omission. + */ +import { Color, type BufferGeometry } from 'three' + +import { + bandGeometry, + boxGeometry, + chamferedBoxGeometry, + createKitModel, + createTinter, + jitter, + latheGeometry, + mergeColoured, + roughenGeometry, + staveGeometry, + taperedBoxGeometry, + type Level, +} from '../core/index.ts' + +export interface StoneWellConfig { + /** Outer radius of the stone kerb (metres). */ + readonly radius: number + /** Height of the kerb above the ground (metres). */ + readonly wallHeight: number + /** Courses of stone. */ + readonly courses: number + /** Blocks in each course. */ + readonly blocks: number + /** Height from the ground to the top of the head beam (metres). */ + readonly frameHeight: number + /** How far down the bucket hangs. 0 = at the roller, 1 = at the water. */ + readonly depth: number + readonly seed: number +} + +export const stoneWellDefaults: StoneWellConfig = { + radius: 0.62, + wallHeight: 0.66, + courses: 4, + blocks: 11, + frameHeight: 1.95, + depth: 0.34, + seed: 17, +} + +export type StoneWellParts = 'kerb' | 'frame' | 'windlass' | 'bucket' + +export interface StoneWellActions { + /** Sends the bucket down (1) or brings it up (0). */ + setDepth(t: number): void + depth(): number + /** Winds continuously until stopped. Positive winds up. */ + setWinding(speed: number): void +} + +export function createModel(overrides: Partial = {}) { + let depth = 0 + let winding = 0 + let travel = 0 + /** + * Where the part's own origin put the anchor. + * + * `origin` places the anchor at the roller's axis at build time, and the + * geometry is authored around it. Writing an absolute `position.y` here + * therefore DESTROYS that placement -- which is what the first version did, + * setting it to 0 and dropping the whole rope and bucket by the height of the + * roller, so the rope started a hand's width below the barrel it hangs from. + * Everything the actions do is now an offset from this. + */ + let restY = 0 + + return createKitModel({ + id: 'stone-well', + defaults: stoneWellDefaults, + slots: ['stone', 'oak', 'iron', 'cloth'], + + build: ({ config, random }) => { + const tint = createTinter(random) + const H = config.frameHeight + const floor = -H / 2 + const R = config.radius + const wall = R * 0.34 + + // --- Kerb --------------------------------------------------------------- + const masonry: BufferGeometry[] = [] + const courses = Math.max(1, Math.round(config.courses)) + const blocks = Math.max(5, Math.round(config.blocks)) + const courseH = config.wallHeight / courses + const midR = R - wall / 2 + + for (let c = 0; c < courses; c += 1) { + // Every other course is offset by half a block: a joint running + // straight up through four courses is a crack waiting to happen, and a + // waller knows it. It is also what stops the ring reading as a stack of + // identical rings. + const phase = (c % 2) * 0.5 + for (let b = 0; b < blocks; b += 1) { + const a = ((b + phase) / blocks) * Math.PI * 2 + const arc = (Math.PI * 2 * midR) / blocks + // Plain tapered boxes, not chamfered ones. A chamfer is 44 triangles + // against 12, and at forty-four blocks that is 1 900 of them spent on + // edges the `roughenGeometry` pass below softens anyway. Stone is the + // one material in this kit where a sharp arris is not wrong. + // ARC first, WALL second. `rotateY(a)` carries the footprint's +Z out + // along the radius and its +X round the circumference, so writing the + // wall thickness first put every block across the ring instead of + // along it: each one stuck a block's length out of a wall a block's + // width thick, and the kerb came out as rubble thrown at a circle. + // The variation is small on purpose. At +-10% on the arc and +-9% on + // the thickness, every block sat at its own radius and its own width: + // the ring came out as rubble rather than as courses, and a waller + // who laid it like that would be looking for other work. A dry wall + // is irregular in the way a hand-cut stone is irregular, which is a + // few percent, not a tenth. + // Blocks are cut a little LONGER than their share of the arc, and + // courses a little taller than their share of the height, so + // neighbours bite into each other. + // + // A flat-faced box on a curve cannot close the joint at its outer + // corner: the chord is shorter than the arc, so anything sized to its + // exact share leaves a wedge of daylight at every joint and the wall + // reads as a ring of separate stones. Letting them overlap is the + // same rule the rest of the kit follows for joints, and it is safe + // here because each block is rotated to its own angle, so no two + // adjoining faces are parallel. + const block = taperedBoxGeometry( + [arc * (1.04 + jitter(random, 0.03)), wall * (0.99 + jitter(random, 0.04))], + [arc * (1.02 + jitter(random, 0.03)), wall * (0.95 + jitter(random, 0.04))], + courseH * (1.03 + jitter(random, 0.025)), + [0, 0, 0], + tint('stone', jitter(random, 0.09)), + ) + // Built facing +Z and swung round: rotating first and placing second + // is what keeps each block square to the ring rather than to the axes. + block.rotateY(a) + block.translate( + Math.sin(a) * midR, + floor + courseH * (c + 0.5), + Math.cos(a) * midR, + ) + masonry.push(block) + } + } + // Rough dressing. Small: the blocks are already irregular in size, and + // displacing them further only opens the dry joints between them. + const kerb = mergeColoured(masonry) + roughenGeometry(kerb, wall * 0.03, { salt: 13 }) + + // --- Frame -------------------------------------------------------------- + const timber: BufferGeometry[] = [] + const postSide = R * 0.24 + const postX = R + postSide * 0.55 + const beamH = R * 0.2 + const beamY = floor + H - beamH / 2 + // The uprights run PAST the beam and show as tenons on top of it. + const postTop = floor + H + beamH * 0.34 + + for (const side of [-1, 1]) { + timber.push(chamferedBoxGeometry( + [postSide * 1.06, postSide * 1.06], + [postSide * 0.94, postSide * 0.94], + postTop - floor, + postSide * 0.09, + [side * postX, (floor + postTop) / 2, 0], + tint('oak', -0.03 + jitter(random, 0.04)), + )) + } + timber.push(chamferedBoxGeometry( + [postX * 2 + postSide * 2.2, beamH * 0.86], + [postX * 2 + postSide * 1.9, beamH * 0.78], + beamH, + beamH * 0.09, + [0, beamY, 0], + tint('oak', 0.03), + )) + + // --- Windlass ----------------------------------------------------------- + // The roller sits well below the beam: the rope has to come off it and + // fall clear down the middle of the well, and a roller tucked under the + // beam would foul it. + const rollerY = floor + H * 0.62 + const rollerR = R * 0.15 + const rollerHalf = postX - postSide * 0.25 + const gear: BufferGeometry[] = [] + const iron: BufferGeometry[] = [] + + const rollerProfile: Level[] = [ + { y: -rollerHalf, radius: rollerR * 0.86 }, + { y: -rollerHalf * 0.88, radius: rollerR }, + { y: rollerHalf * 0.88, radius: rollerR }, + { y: rollerHalf, radius: rollerR * 0.86 }, + ] + const roller = latheGeometry(rollerProfile, 9, [0, 0, 0], tint('oak', 0.02, 1.2)) + // Built along Y like every lathe here; +90 about Z lays it along X, + // spanning the gap between the uprights. + roller.rotateZ(Math.PI / 2) + roller.translate(0, rollerY, 0) + gear.push(roller) + + // End collars: the raised shoulders that keep the rope from wandering off + // the barrel and into the bearing. + for (const side of [-1, 1]) { + const collar = bandGeometry( + rollerR * 1.5, 0, rollerR * 0.55, rollerR * 0.5, 9, + tint('oak', -0.06, 1.2), { inner: true }, + ) + collar.rotateZ(Math.PI / 2) + collar.translate(side * rollerHalf * 0.62, rollerY, 0) + gear.push(collar) + } + + // The rope wound on the barrel, between the collars. + const coil = bandGeometry( + rollerR * 1.34, 0, rollerR * 1.05, rollerR * 0.34, 9, + tint('cloth', -0.04, 1.3), { inner: true }, + ) + coil.rotateZ(Math.PI / 2) + coil.translate(0, rollerY, 0) + gear.push(coil) + + // Crank: an iron elbow through the upright with a wooden grip on the end. + const crankOut = postX + postSide * 0.9 + iron.push(taperedBoxGeometry( + [rollerR * 0.5, rollerR * 0.5], + [rollerR * 0.42, rollerR * 0.42], + postSide * 2.4, + [0, 0, 0], + tint('iron', 0.02, 0.7), + ).rotateZ(Math.PI / 2).translate(postX + postSide * 0.5, rollerY, 0)) + iron.push(boxGeometry( + [rollerR * 0.46, rollerR * 2.6, rollerR * 0.46], + [crankOut, rollerY - rollerR * 1.2, 0], + new Color(tint('iron', -0.02, 0.7)), + )) + gear.push(taperedBoxGeometry( + [rollerR * 0.72, rollerR * 0.72], + [rollerR * 0.58, rollerR * 0.58], + rollerR * 2.1, + [0, 0, 0], + tint('oak', 0.05), + ).rotateZ(Math.PI / 2).translate(crankOut + rollerR * 0.9, rollerY - rollerR * 2.2, 0)) + + // --- Rope and bucket ---------------------------------------------------- + // Authored hanging from the ROLLER'S AXIS, which is where the part's + // origin goes, so lowering the bucket is one rotation-free translation. + const bucketR = R * 0.3 + const bucketH = bucketR * 1.5 + const fall = H * 0.34 * Math.min(1, Math.max(0, config.depth)) + const hanging: BufferGeometry[] = [] + + // The rope from barrel to bail. It has to stretch with the drop, so its + // length is derived rather than fixed. + // The rope leaves the COIL, not the axis. + // + // Starting it at y = 0 put its whole surface inside the roller's hollow + // interior, touching nothing -- these are surfaces, not solids, so a rope + // threaded up the middle of a barrel is joined to it only in the sense + // that it is inside it. The support check called the bucket floating and + // it was right. Beginning just inside the coil's inner face means the + // rope crosses the coil's outer face on its way down. + // Inside the coil's MATERIAL, which is the band from 1.0 to 1.34 of the + // roller radius -- not at 0.95, which is the hole through the middle of + // it. Starting there the rope hung in the ring's eye touching nothing; + // starting at 1.15 it begins within the wound rope and crosses its outer + // face on the way down. + const ropeTop = -rollerR * 1.15 + const ropeLength = Math.max(rollerR * 1.6, fall) - ropeTop + hanging.push(latheGeometry( + [ + { y: ropeTop - ropeLength, radius: rollerR * 0.11 }, + { y: ropeTop, radius: rollerR * 0.12 }, + ] as Level[], + 6, [0, 0, 0], tint('cloth', -0.08, 1.3), + { capTop: false, capBottom: false }, + )) + + // Bail: the iron loop the bucket hangs by. + const bail = bandGeometry( + bucketR * 0.94, 0, rollerR * 0.16, rollerR * 0.13, 9, + tint('iron', 0.04, 0.7), { inner: true }, + ) + bail.rotateX(Math.PI / 2) + bail.translate(0, ropeTop - ropeLength - bucketR * 0.5, 0) + hanging.push(bail) + + // A small stave bucket, built the way the kit's bucket is: separate + // boards, not a turned cup. + const staves = 11 + const step = (Math.PI * 2) / staves + const bucketY = ropeTop - ropeLength - bucketR * 0.5 - bucketH * 0.52 + for (let i = 0; i < staves; i += 1) { + hanging.push(staveGeometry( + [ + { y: bucketY - bucketH / 2, radius: bucketR * 0.82 }, + { y: bucketY + bucketH / 2, radius: bucketR }, + ] as Level[], + i * step + step * 0.06, + (i + 1) * step - step * 0.06, + bucketR * 0.14, + tint('oak', jitter(random, 0.06)), + )) + } + for (const at of [-0.34, 0.32]) { + const hoop = bandGeometry( + bucketR * (at < 0 ? 0.88 : 1.01), bucketY + bucketH * at, + bucketH * 0.1, bucketR * 0.05, staves, + tint('iron', 0.03, 0.7), + ) + hanging.push(hoop) + } + hanging.push(latheGeometry( + [ + { y: bucketY - bucketH * 0.44, radius: bucketR * 0.78 }, + { y: bucketY - bucketH * 0.38, radius: bucketR * 0.8 }, + ] as Level[], + staves, [0, 0, 0], tint('oak', -0.1), + )) + + return { + kerb: { slot: 'stone' as const, geometry: kerb }, + frame: { slot: 'oak' as const, geometry: mergeColoured(timber) }, + windlass: { + slot: 'oak' as const, + geometry: mergeColoured(gear), + extras: [{ slot: 'iron' as const, geometry: mergeColoured(iron) }], + }, + bucket: { + slot: 'oak' as const, + geometry: mergeColoured(hanging), + origin: [0, rollerY, 0] as const, + }, + } + }, + + actions: ({ parts, getConfig }) => { + depth = getConfig().depth + travel = 0 + restY = parts.bucket.anchor.position.y + return { + setDepth: (t) => { + winding = 0 + depth = Math.min(1, Math.max(0, t)) + travel = 0 + }, + depth: () => depth, + setWinding: (speed) => { winding = speed }, + } + }, + + update: (deltaSeconds, { parts, getConfig }) => { + if (winding === 0) return + // Winding moves the bucket by TRANSLATION rather than by rebuilding the + // rope, so the action costs nothing per frame. The rope's own length is + // fixed by `depth` at build time; between rebuilds the bucket slides on + // it, which is exactly what a bucket on a rope does. + const H = getConfig().frameHeight + travel = Math.min(H * 0.34, Math.max(-H * 0.2, travel + winding * deltaSeconds * H * 0.18)) + parts.bucket.anchor.position.y = restY + travel + }, + }, overrides) +}