Add the stone trough, and water to put in it

The kit could water nobody. It had 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.

Two additions to the core, both earned by measurement rather than by wanting
them:

  - `limestone`, a palette key. `stone` 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. Both are right and neither replaces the other. The rendered block
    now matches its reference to within a fifth of a degree of hue and 0.004
    of lightness.
  - `water`, a slot, and it is far less green than instinct says. Sampled
    inside the reference's basin the film reads hue 39.5 — which is the hue of
    the stone UNDERNEATH it, not a colour of its own. It darkens and slightly
    saturates whatever it lies on and does that through the material's
    opacity. Painted the pond green I was about to reach for, the composite
    would have missed the reference by a hundred degrees.

Making it read as CARVED rather than sawn took three goes, and the two failures
are opposite errors worth keeping:

  1. Each wall in two tiers, to give `roughenGeometry` more corners to move.
     The tiers' corners sit at different positions, the hash moved them by
     different amounts, and the render showed a lid on a base with a hard seam
     right round it.
  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 were trying to get subdivision out of the wrong thing. The walls are
`dishedSheetGeometry`, whose own docstring says the trough wants it: one
continuous body with levels along its length, so 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 for a seam to open in.

The z-fight checker earned its keep twice on the same plane, `0,-1,0 | 0`.
Four walls standing on the ground all have a face down there, and where the
corners overlap — which is where they are MEANT to overlap — two of those
faces share it. Lifting the basin floor only moved the pairing from
floor-against-wall to wall-against-wall. The answer was to stop there being
four things down there at all: a trough is solid below the water line, so it
is one block from the ground to the basin with the walls sunk into it, by
different amounts, because two buried faces in one plane are still two faces
in one plane.

Last, two defaults that the render corrected rather than the reference. The
walls at 0.27 of the width shut the basin so far that a three-quarter view
showed only its inner face, against the reference's opening of about three
fifths — now 0.21. And the water at 0.55 of the basin's depth sits below the
near rim and the trough reads as dry from every angle anyone will look at it
from; the reference stands a couple of centimetres under the rim, which is
0.85.

36 models, 31 748 triangles, fourteen material slots, all checks pass, 0
floating cases, GLB round-trip clean, Conformant, documentation in step.
This commit is contained in:
CRTkafa 2026-08-27 02:46:05 +07:00
parent 30c7c4863a
commit 0b2623755f
15 changed files with 645 additions and 11 deletions

View file

@ -14,7 +14,7 @@ on an opaque package. This repository holds one such registry.
![The whole kit in one scene](media/kit.png) ![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 than a single medium-detail character. Every one is procedural source you own
and edit, not an asset you load. and edit, not an asset you load.

View file

@ -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/catalog.ts the viewer's catalog — DERIVED from meta.ts
src/glb.ts GLB export (shared by viewer and CLI) src/glb.ts GLB export (shared by viewer and CLI)
src/models/scifi-kit/pressure-gauge/ the installed sci-fi model 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/ my-registry/
meta.ts the SINGLE source of catalog metadata meta.ts the SINGLE source of catalog metadata
build.ts the registry.json generator build.ts the registry.json generator
@ -338,7 +338,7 @@ the same, the physical package changes.
## 5. Lowpoly medieval — yes, no problem ## 5. Lowpoly medieval — yes, no problem
This is not an assumption: `@medieval-kit` works, is validated and currently 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 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. 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 | | | `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 | | | `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-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 | | | `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 | | | `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. than a single medium-complexity character model.
### 5.1 One source: `my-registry/meta.ts` ### 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 this check was added it caught a real drift in four models (a `steel` slot had
been added but not declared). been added but not declared).
### 5.2 The material vocabulary — thirteen slots ### 5.2 The material vocabulary — fourteen slots
| Slot | What | Why separate | | Slot | What | Why separate |
| --- | --- | --- | | --- | --- | --- |
@ -421,6 +422,7 @@ been added but not declared).
| `char` | charcoal, pitch | — | | `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 | | `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 | | `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 `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 entirely while occlusion and mottle are baked. The reason is simple — on an

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

After

Width:  |  Height:  |  Size: 133 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 430 KiB

After

Width:  |  Height:  |  Size: 442 KiB

Before After
Before After

View file

@ -82,7 +82,7 @@
"address": "@medieval-kit/core", "address": "@medieval-kit/core",
"source": "file:my-registry/dist/registry.json", "source": "file:my-registry/dist/registry.json",
"version": "workspace", "version": "workspace",
"installedAt": "2026-08-26T19:00:27.476Z", "installedAt": "2026-08-26T19:43:46.488Z",
"files": [ "files": [
{ {
"path": "src\\models\\medieval-kit\\core\\geometry.ts", "path": "src\\models\\medieval-kit\\core\\geometry.ts",
@ -94,7 +94,7 @@
}, },
{ {
"path": "src\\models\\medieval-kit\\core\\materials.ts", "path": "src\\models\\medieval-kit\\core\\materials.ts",
"sourceHash": "e39ce86ff1a3bd6e23ae9067b3dd241d449299b3ab24a0164eb8cb997c1e96cc" "sourceHash": "1863cbe82d9cab014a6f83af57a5f647a2fb8d248759ffd1b5ae663e2b8ebac0"
}, },
{ {
"path": "src\\models\\medieval-kit\\core\\random.ts", "path": "src\\models\\medieval-kit\\core\\random.ts",
@ -106,7 +106,7 @@
}, },
{ {
"path": "src\\models\\medieval-kit\\core\\kit.ts", "path": "src\\models\\medieval-kit\\core\\kit.ts",
"sourceHash": "d2332388b6d4b2baec730dbe56572fa82ff9e8a0e155295b1b0910a2dc91d22d" "sourceHash": "bcaafdb326cc4478305b28524f7b1472598530380c71441f8f0570c27e42f99f"
}, },
{ {
"path": "src\\models\\medieval-kit\\core\\tool.ts", "path": "src\\models\\medieval-kit\\core\\tool.ts",
@ -642,6 +642,21 @@
"dependencies": [ "dependencies": [
"three@>=0.185.0" "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"
]
} }
} }
} }

View file

@ -28,7 +28,7 @@ Configure `models.json` first so the namespace resolves:
## Models ## Models
35 models and one shared lib. Addresses are `@medieval-kit/<id>`. This table is 36 models and one shared lib. Addresses are `@medieval-kit/<id>`. This table is
generated from the models themselves with `bun scripts/catalog-table.ts` — a 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 hand-written list goes stale on the first model you add, and this one already
did once. did once.
@ -68,10 +68,11 @@ did once.
| `round-shield` | Arms | 729 | 3 | 0.73×0.73×0.17 | oak, leather, iron | | | `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 | | | `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-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 | | | `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 | | | `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. single mid-complexity character model.
Every model depends on `@medieval-kit/core`, a shared support item holding the 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 ## 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. difference.
| Slot | What it covers | Why it is separate | | Slot | What it covers | Why it is separate |
@ -151,6 +152,7 @@ difference.
| `ember` | flame | `MeshBasicMaterial` — it does not receive light, it emits | | `ember` | flame | `MeshBasicMaterial` — it does not receive light, it emits |
| `char` | charcoal and pitch | — | | `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 | | `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 | | `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 `ember` also acts as a rule in two places: bodies in that slot are skipped

View file

@ -468,6 +468,23 @@ export const MODEL_META: Readonly<Record<string, ModelMeta>> = {
materialSlots: ['oak', 'leather', 'iron'], materialSlots: ['oak', 'leather', 'iron'],
parts: ['boards', 'rim', 'boss'], 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': { 'oak-tree': {
title: 'Oak Tree', title: 'Oak Tree',
description: description:

View file

@ -161,6 +161,9 @@ const MOTTLE_BY_SLOT: Readonly<Record<MedievalSlot, number>> = {
// the machinery that already reproduces that detail -- which is the third // 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. // time this kit has learned that, after straw's saturation and bark's value.
leaf: 0.95, 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< export function createKitModel<

View file

@ -27,6 +27,7 @@ export type MedievalSlot =
| 'char' // charcoal, pitch | 'char' // charcoal, pitch
| 'stone' // dressed and rubble masonry | 'stone' // dressed and rubble masonry
| 'leaf' // living foliage | 'leaf' // living foliage
| 'water' // standing water
/** /**
* The material TYPE can differ per slot. `ember` is an unlit MeshBasicMaterial; * The material TYPE can differ per slot. `ember` is an unlit MeshBasicMaterial;
@ -47,6 +48,7 @@ export interface SlotMaterial {
readonly char: MeshStandardMaterial readonly char: MeshStandardMaterial
readonly stone: MeshStandardMaterial readonly stone: MeshStandardMaterial
readonly leaf: MeshStandardMaterial readonly leaf: MeshStandardMaterial
readonly water: MeshStandardMaterial
} }
export interface MedievalPalette { export interface MedievalPalette {
@ -156,6 +158,36 @@ export interface MedievalPalette {
* lit and shadowed alike. * lit and shadowed alike.
*/ */
readonly leaf: Color 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), stone: new Color(0x6e6b63),
charHot: new Color(0xc4441a), charHot: new Color(0xc4441a),
bark: new Color(0x585032), bark: new Color(0x585032),
limestone: new Color(0x94846b),
water: new Color(0x3b4e45),
leaf: new Color(0x6d8632), leaf: new Color(0x6d8632),
} }
@ -356,6 +390,21 @@ export function createMedievalMaterials<S extends MedievalSlot>(
roughness: 0.93, roughness: 0.93,
metalness: 0, 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({ char: () => new MeshStandardMaterial({
name: 'medieval-kit / charcoal', name: 'medieval-kit / charcoal',
color: 0xffffff, color: 0xffffff,

View file

@ -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<StoneTroughConfig> = {}) {
return createKitModel<StoneTroughConfig, 'stone' | 'water', StoneTroughParts>({
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)
}

View file

@ -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 createShield } from '@/models/medieval-kit/round-shield/model.ts'
import { createModel as createForge } from '@/models/medieval-kit/forge-hearth/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 createOak } from '@/models/medieval-kit/oak-tree/model.ts'
import { createModel as createTrough } from '@/models/medieval-kit/stone-trough/model.ts'
const failures: string[] = [] const failures: string[] = []
function expect(label: string, condition: boolean): void { function expect(label: string, condition: boolean): void {
@ -315,6 +316,10 @@ const CASES: readonly Case[] = [
parts: 3, ownSlot: 'leather', borrowSlot: 'oak', parts: 3, ownSlot: 'leather', borrowSlot: 'oak',
variants: [{ planks: 3 }, { lean: 0 }, { rivets: 0 }], variants: [{ planks: 3 }, { lean: 0 }, { rivets: 0 }],
maxSize: [1.3, 1.3, 0.9] }, 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 }, { id: 'oak-tree', make: as(createOak), patch: { limbs: 11, spread: 1.5 },
parts: 3, ownSlot: 'leaf', borrowSlot: 'oak', parts: 3, ownSlot: 'leaf', borrowSlot: 'oak',
variants: [{ leafiness: 0 }, { limbs: 3 }, { autumn: 1 }, { spread: 0.6 }, { height: 3 }], variants: [{ leafiness: 0 }, { limbs: 3 }, { autumn: 1 }, { spread: 0.6 }, { height: 3 }],

View file

@ -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 createShield } from '@/models/medieval-kit/round-shield/model.ts'
import { createModel as createForge } from '@/models/medieval-kit/forge-hearth/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 createOak } from '@/models/medieval-kit/oak-tree/model.ts'
import { createModel as createTrough } from '@/models/medieval-kit/stone-trough/model.ts'
export interface ParamSpec { export interface ParamSpec {
readonly key: string readonly key: string
@ -163,6 +164,7 @@ const FACTORIES: Readonly<Record<string, () => KitModel>> = {
'round-shield': as(createShield), 'round-shield': as(createShield),
'forge-hearth': as(createForge), 'forge-hearth': as(createForge),
'oak-tree': as(createOak), 'oak-tree': as(createOak),
'stone-trough': as(createTrough),
'wooden-ladder': as(createLadder), 'wooden-ladder': as(createLadder),
'wooden-fence': as(createFence), 'wooden-fence': as(createFence),
'wooden-hoe': as(createHoe), 'wooden-hoe': as(createHoe),
@ -319,6 +321,7 @@ const MEDIEVAL_ORDER = [
// the order that makes the scale of it land. // the order that makes the scale of it land.
'iron-cauldron', 'hand-cart', 'vegetables', 'round-shield', 'forge-hearth', 'iron-cauldron', 'hand-cart', 'vegetables', 'round-shield', 'forge-hearth',
'stone-well', 'stone-well',
'stone-trough',
'post-mill', 'post-mill',
// After the mill, because it is taller than the mill and half again as wide. // 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 // A tour that ends on the only living thing in the kit ends better than one

View file

@ -161,6 +161,9 @@ const MOTTLE_BY_SLOT: Readonly<Record<MedievalSlot, number>> = {
// the machinery that already reproduces that detail -- which is the third // 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. // time this kit has learned that, after straw's saturation and bark's value.
leaf: 0.95, 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< export function createKitModel<

View file

@ -27,6 +27,7 @@ export type MedievalSlot =
| 'char' // charcoal, pitch | 'char' // charcoal, pitch
| 'stone' // dressed and rubble masonry | 'stone' // dressed and rubble masonry
| 'leaf' // living foliage | 'leaf' // living foliage
| 'water' // standing water
/** /**
* The material TYPE can differ per slot. `ember` is an unlit MeshBasicMaterial; * The material TYPE can differ per slot. `ember` is an unlit MeshBasicMaterial;
@ -47,6 +48,7 @@ export interface SlotMaterial {
readonly char: MeshStandardMaterial readonly char: MeshStandardMaterial
readonly stone: MeshStandardMaterial readonly stone: MeshStandardMaterial
readonly leaf: MeshStandardMaterial readonly leaf: MeshStandardMaterial
readonly water: MeshStandardMaterial
} }
export interface MedievalPalette { export interface MedievalPalette {
@ -156,6 +158,36 @@ export interface MedievalPalette {
* lit and shadowed alike. * lit and shadowed alike.
*/ */
readonly leaf: Color 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), stone: new Color(0x6e6b63),
charHot: new Color(0xc4441a), charHot: new Color(0xc4441a),
bark: new Color(0x585032), bark: new Color(0x585032),
limestone: new Color(0x94846b),
water: new Color(0x3b4e45),
leaf: new Color(0x6d8632), leaf: new Color(0x6d8632),
} }
@ -356,6 +390,21 @@ export function createMedievalMaterials<S extends MedievalSlot>(
roughness: 0.93, roughness: 0.93,
metalness: 0, 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({ char: () => new MeshStandardMaterial({
name: 'medieval-kit / charcoal', name: 'medieval-kit / charcoal',
color: 0xffffff, color: 0xffffff,

View file

@ -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<StoneTroughConfig> = {}) {
return createKitModel<StoneTroughConfig, 'stone' | 'water', StoneTroughParts>({
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)
}