roamwright 0.61.16 → 0.61.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +25 -24
  2. package/examples/land-features.js +130 -9
  3. package/examples/land.html +2 -1
  4. package/examples/land.js +17 -2
  5. package/examples/ruins.html +3 -2
  6. package/examples/ruins.js +184 -37
  7. package/examples/world-map.html +162 -0
  8. package/examples/world-map.js +475 -0
  9. package/geometry/farm-props.js +59 -0
  10. package/geometry/field-map.js +147 -0
  11. package/geometry/instances.js +40 -0
  12. package/geometry/plant-tuft.js +138 -0
  13. package/geometry/ruins-breach.js +329 -0
  14. package/geometry/ruins-crater.js +269 -0
  15. package/geometry/ruins-masonry.js +323 -0
  16. package/geometry/ruins-walls.js +272 -0
  17. package/geometry/strata-mesa.js +114 -0
  18. package/geometry/strata-rocks.js +73 -2
  19. package/index.js +109 -1
  20. package/package.json +1 -1
  21. package/rendering/contact-shadows.js +56 -0
  22. package/rendering/crowd-lifecycle.js +80 -0
  23. package/rendering/farm-plough.js +145 -0
  24. package/rendering/map-glyphs.js +494 -0
  25. package/rendering/map-input.js +143 -0
  26. package/rendering/map-labels.js +181 -0
  27. package/rendering/map-relief.js +330 -0
  28. package/rendering/map-signs.js +124 -0
  29. package/rendering/place-names.js +408 -0
  30. package/rendering/plant-tuft.js +190 -0
  31. package/rendering/portrait-studio.js +213 -0
  32. package/rendering/ruins-fittings.js +199 -0
  33. package/rendering/ruins-mound.js +103 -0
  34. package/rendering/screen-pick.js +75 -0
  35. package/runtime/build-freshness.js +133 -0
  36. package/runtime/compass-strip.js +232 -0
  37. package/runtime/context-lost.js +108 -0
  38. package/runtime/doorways.js +98 -0
  39. package/runtime/hud-frame.js +74 -0
  40. package/runtime/map-relief.js +236 -0
  41. package/runtime/map-spot.js +120 -0
  42. package/runtime/map-view.js +229 -0
  43. package/runtime/panel-shell.js +90 -0
  44. package/runtime/relation-graph.js +163 -0
  45. package/runtime/stage-frame.js +263 -0
  46. package/runtime/url-router.js +162 -0
  47. package/runtime/way-back.js +71 -0
  48. package/runtime/whereabouts.js +210 -0
  49. package/runtime/world-controls.js +265 -0
@@ -0,0 +1,269 @@
1
+ /**
2
+ * Impact crater bowls and shattered fallen boulders: high-resolution crater surfaces with thrown
3
+ * subsoil lips and rim stones blended cleanly into sloped ground, plus shattered boulder clusters
4
+ * with surrounding rock aprons. Pure geometry assembly into `GB` builders; worker-safe.
5
+ * @module
6
+ */
7
+
8
+ import { dim } from '../math/color.js';
9
+ import { createNoise } from '../math/noise.js';
10
+ import { TAU, lerp, sstep } from '../math/scalar.js';
11
+ import { C as defaultColor, TRS as defaultTransform, createUnitShapes } from './primitives.js';
12
+ import { sampleSurface } from './sampled-surface.js';
13
+
14
+ const BOWL_ROUND = 64;
15
+ const BOWL_OUT = 20;
16
+ const TINT_ROUND = 36;
17
+ const TINT_OUT = 12;
18
+ const BOWL_LIFT = 0.1;
19
+ const APRON_SINK = 0.1;
20
+
21
+ let fallbackShapes = null;
22
+ const defaultShapes = () => (fallbackShapes ??= createUnitShapes());
23
+ let fallbackNoise = null;
24
+ const defaultVnoise = () => (fallbackNoise ??= createNoise().vnoise);
25
+
26
+ /** Default linear RGB soil/ash colours for impact craters built by {@link buildCraterBowl}. */
27
+ export const CRATER_PALETTE = Object.freeze({
28
+ char: Object.freeze([0.034, 0.029, 0.024]),
29
+ ash: Object.freeze([0.072, 0.068, 0.062]),
30
+ subsoil: Object.freeze([0.088, 0.064, 0.04]),
31
+ turf: Object.freeze([0.052, 0.046, 0.03]),
32
+ });
33
+
34
+ const mix3 = (a, b, k) => [lerp(a[0], b[0], k), lerp(a[1], b[1], k), lerp(a[2], b[2], k)];
35
+
36
+ function defaultCraterDip(crater, dx, dz, vnoise) {
37
+ const d = Math.hypot(dx, dz) || 1e-3;
38
+ const t = d / (crater.r * (0.86 + 0.28 * vnoise((dx / d) * 1.6 + crater.x, (dz / d) * 1.6 + crater.z, 381)));
39
+ return (t < 1 ? -crater.deep * (1 - t * t) : 0) + crater.deep * 0.42 * Math.exp(-(((t - 1.06) / 0.3) ** 2));
40
+ }
41
+
42
+ /**
43
+ * Build a high-resolution impact crater bowl and thrown-subsoil lip blended cleanly into surrounding
44
+ * sloped ground, ringed by ejected stones.
45
+ *
46
+ * @param {object} options
47
+ * @param {{ earth: import('./builder.js').GB, rock: import('./builder.js').GB }} options.builders - Destination builders.
48
+ * @param {() => number} [options.random=Math.random] - Repeatable PRNG in `[0, 1)`.
49
+ * @param {(x: number, z: number) => number} [options.ground] - Surface height sampler `(x, z) => y`.
50
+ * @param {number} [options.x=0] - Crater centre X in metres.
51
+ * @param {number} [options.z=0] - Crater centre Z in metres.
52
+ * @param {{ r: number, deep?: number, x?: number, z?: number }} options.crater - Crater dimensions (`r` radius, `deep` depth in metres).
53
+ * @param {(crater: object, dx: number, dz: number) => number} [options.craterDip] - Crater height profile offset `(q, dx, dz) => dy`.
54
+ * @param {typeof CRATER_PALETTE} [options.palette=CRATER_PALETTE] - Linear RGB soil/ash colours.
55
+ * @param {import('three').BufferGeometry} [options.stoneShape] - Angular stone geometry for rim boulders.
56
+ * @param {(x: number, z: number, salt: number) => number} [options.vnoise] - Value noise in `[0, 1)`.
57
+ * @param {Function} [options.color] - Linear RGB colour helper.
58
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
59
+ */
60
+ export function buildCraterBowl(options) {
61
+ const {
62
+ builders,
63
+ random = Math.random,
64
+ ground = () => 0,
65
+ x = 0,
66
+ z = 0,
67
+ crater: q,
68
+ vnoise = defaultVnoise(),
69
+ craterDip = (cr, dx, dz) => defaultCraterDip(cr, dx, dz, vnoise),
70
+ palette = CRATER_PALETTE,
71
+ stoneShape = defaultShapes().rock,
72
+ color = defaultColor,
73
+ transform = defaultTransform,
74
+ } = options;
75
+ const between = (a, b) => a + random() * (b - a);
76
+ const sd = random() * 40;
77
+ const tints = Float32Array.from({ length: TINT_ROUND * TINT_OUT }, () => random());
78
+ const n = 8;
79
+ const R = q.r * 1.75;
80
+ let base = 0;
81
+ let gx = 0;
82
+ let gz = 0;
83
+ for (let i = 0; i < n; i++) {
84
+ const a = (i * TAU) / n;
85
+ const h = ground(x + Math.cos(a) * R, z + Math.sin(a) * R);
86
+ base += h / n;
87
+ gx += (2 * h * Math.cos(a)) / (n * R);
88
+ gz += (2 * h * Math.sin(a)) / (n * R);
89
+ }
90
+ const before = (px, pz) => base + gx * (px - x) + gz * (pz - z);
91
+ const pastApron = (px, pz) => sstep(1.12, 1.55, (Math.hypot(px - x, pz - z) / q.r) * (0.9 + 0.2 * vnoise(px * 0.4, pz * 0.4, 38)));
92
+ const surfaceAt = (px, pz) => {
93
+ const g = ground(px, pz);
94
+ const fine = before(px, pz) + craterDip(q, px - x, pz - z) * (0.85 + 0.3 * vnoise(px * 0.5 + sd, pz * 0.5, 36));
95
+ return lerp(Math.max(fine, g + BOWL_LIFT), g - APRON_SINK, pastApron(px, pz));
96
+ };
97
+ const bowlAt = (u, v) => {
98
+ const a = u * TAU;
99
+ const t = 0.05 + 1.5 * v;
100
+ const px = x + Math.cos(a) * t * q.r;
101
+ const pz = z + Math.sin(a) * t * q.r;
102
+ return [px, pz, t];
103
+ };
104
+ const tintAt = (u, v) => {
105
+ const fu = u * TINT_ROUND;
106
+ const fv = Math.min(v * (TINT_OUT - 1), TINT_OUT - 1.001);
107
+ const i0 = Math.floor(fu) % TINT_ROUND;
108
+ const i1 = (i0 + 1) % TINT_ROUND;
109
+ const j0 = Math.floor(fv);
110
+ const ku = sstep(0, 1, fu - Math.floor(fu));
111
+ const kv = sstep(0, 1, fv - j0);
112
+ const at = (i, j) => tints[j * TINT_ROUND + i];
113
+ return lerp(lerp(at(i0, j0), at(i1, j0), ku), lerp(at(i0, j0 + 1), at(i1, j0 + 1), ku), kv);
114
+ };
115
+ sampleSurface(
116
+ builders.earth,
117
+ BOWL_ROUND,
118
+ BOWL_OUT,
119
+ (u, v) => {
120
+ const [px, pz] = bowlAt(u, v);
121
+ return [px, surfaceAt(px, pz), pz];
122
+ },
123
+ (u, v) => {
124
+ const [px, pz, t] = bowlAt(u, v);
125
+ const lip = Math.exp(-(((t - 1.06) / 0.2) ** 2));
126
+ const ash = sstep(0.45, 0.75, vnoise(px * 0.35 + sd, pz * 0.35, 39)) * (1 - lip);
127
+ const clods = lip * (0.45 + 0.55 * vnoise(px * 0.9, pz * 0.9, 37));
128
+ const rays = sstep(0.58, 0.8, vnoise(u * 23 + sd, t * 1.3, 40)) * sstep(0.95, 1.1, t) * (1 - sstep(1.25, 1.5, t));
129
+ let c = mix3(palette.char, palette.ash, ash * 0.55);
130
+ c = mix3(c, palette.subsoil, Math.min(1, clods * 1.3 + rays * 0.8));
131
+ c = mix3(c, palette.turf, pastApron(px, pz) * (1 - rays * 0.6));
132
+ return dim(c, 0.88 + 0.24 * tintAt(u, v));
133
+ },
134
+ { flip: true, blend: true },
135
+ );
136
+ for (let i = 0; i < 12; i++) {
137
+ const a = random() * TAU;
138
+ const d = q.r * between(0.95, 1.5);
139
+ const s2 = between(0.2, 0.55);
140
+ const px = x + Math.cos(a) * d;
141
+ const pz = z + Math.sin(a) * d;
142
+ builders.rock.add(
143
+ stoneShape,
144
+ color(0x3f3832, 0.2, random),
145
+ transform(px, Math.max(ground(px, pz), surfaceAt(px, pz)) - s2 * 0.3, pz, s2 * 1.5, s2, s2 * 1.2, random() * 6, random(), random()),
146
+ );
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Build a shattered fallen boulder cluster with surrounding rock fragments, optional circle
152
+ * collider, ground scorch scar, and impact crater bowl ({@link buildCraterBowl}).
153
+ *
154
+ * @param {object} options
155
+ * @param {{ basalt: import('./builder.js').GB, earth?: import('./builder.js').GB, rock?: import('./builder.js').GB }} options.builders - Destination builders.
156
+ * @param {() => number} [options.random=Math.random] - Repeatable PRNG in `[0, 1)`.
157
+ * @param {(x: number, z: number) => number} [options.ground] - Surface height sampler `(x, z) => y`.
158
+ * @param {number} [options.x=0] - Impact X in metres.
159
+ * @param {number} [options.z=0] - Impact Z in metres.
160
+ * @param {number} [options.size=3] - Main boulder nominal scale in metres.
161
+ * @param {number} [options.lift=0.08] - Vertical lift share of `size`.
162
+ * @param {number} [options.fragments=3] - Secondary large boulder fragments around the core.
163
+ * @param {number} [options.scarRadius] - Ground scar radius in metres (defaults to `size * 3.4`).
164
+ * @param {object | null} [options.crater=null] - Optional crater descriptor forwarded to {@link buildCraterBowl}.
165
+ * @param {(crater: object, dx: number, dz: number) => number} [options.craterDip] - Crater height profile callback.
166
+ * @param {import('three').BufferGeometry} [options.rockShape] - Main boulder unit shape.
167
+ * @param {import('three').BufferGeometry} [options.chipShape] - Small scattered fragment shape.
168
+ * @param {() => number[]} [options.rockColor] - Returns linear RGB boulder colour.
169
+ * @param {((x: number, z: number, radius: number) => void) | null} [options.onCollider=null] - Optional circle collider callback.
170
+ * @param {((x: number, z: number, radius: number, weight: number) => void) | null} [options.onScar=null] - Optional ground scar callback.
171
+ * @param {(x: number, z: number, salt: number) => number} [options.vnoise] - Value noise forwarded to {@link buildCraterBowl}.
172
+ * @param {Function} [options.color] - Linear RGB colour helper.
173
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
174
+ */
175
+ export function buildFallenBoulder(options) {
176
+ const {
177
+ builders,
178
+ random = Math.random,
179
+ ground = () => 0,
180
+ x = 0,
181
+ z = 0,
182
+ size: s = 3,
183
+ lift = 0.08,
184
+ fragments = 3,
185
+ scarRadius = undefined,
186
+ crater = null,
187
+ craterDip = undefined,
188
+ rockShape = defaultShapes().rock,
189
+ chipShape = defaultShapes().rock,
190
+ rockColor = null,
191
+ onCollider = null,
192
+ onScar = null,
193
+ vnoise = defaultVnoise(),
194
+ color = defaultColor,
195
+ transform = defaultTransform,
196
+ } = options;
197
+ const between = (a, b) => a + random() * (b - a);
198
+ const y = ground(x, z);
199
+ const bc =
200
+ rockColor ??
201
+ (() => {
202
+ const t = between(0.012, 0.03);
203
+ return [t, t, t * 1.15];
204
+ });
205
+ builders.basalt.add(
206
+ rockShape,
207
+ bc(),
208
+ transform(
209
+ x,
210
+ y + s * lift,
211
+ z,
212
+ s * between(1.3, 1.7),
213
+ s * between(0.95, 1.25),
214
+ s * between(0.95, 1.2),
215
+ random() * 6,
216
+ between(-0.35, 0.35),
217
+ between(-0.35, 0.35),
218
+ ),
219
+ );
220
+ for (let i = 0; i < fragments; i++) {
221
+ const a = random() * TAU;
222
+ const d = s * between(0.35, 0.8);
223
+ const q = s * between(0.35, 0.7);
224
+ builders.basalt.add(
225
+ rockShape,
226
+ bc(),
227
+ transform(
228
+ x + Math.cos(a) * d,
229
+ y - q * 0.3 + (i ? 0 : s * 0.35),
230
+ z + Math.sin(a) * d,
231
+ q * between(0.9, 1.6),
232
+ q * between(0.8, 1.5),
233
+ q,
234
+ random() * 6,
235
+ between(-0.7, 0.7),
236
+ between(-0.7, 0.7),
237
+ ),
238
+ );
239
+ }
240
+ for (let i = 0, n = Math.round(8 + s * 3); i < n; i++) {
241
+ const a = random() * TAU;
242
+ const d = s * between(0.8, 2.6);
243
+ const q = between(0.25, 0.9) * Math.min(1.6, s * 0.3);
244
+ const px = x + Math.cos(a) * d;
245
+ const pz = z + Math.sin(a) * d;
246
+ builders.basalt.add(
247
+ chipShape,
248
+ bc(),
249
+ transform(px, ground(px, pz) - q * 0.3, pz, q * between(0.8, 1.8), q, q, random() * 6, random(), random()),
250
+ );
251
+ }
252
+ onCollider?.(x, z, s * 0.72);
253
+ onScar?.(x, z, scarRadius ?? s * 3.4, 1);
254
+ if (crater) {
255
+ buildCraterBowl({
256
+ builders,
257
+ random,
258
+ ground,
259
+ x,
260
+ z,
261
+ crater,
262
+ craterDip,
263
+ stoneShape: chipShape,
264
+ vnoise,
265
+ color,
266
+ transform,
267
+ });
268
+ }
269
+ }
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Dressed masonry and architectural fittings geometry: coursed ashlar walls with optional ragged
3
+ * ruined tops and open doorways, square flagstone paving, fluted standing or fallen column drums
4
+ * built via `rockSheet`, brass oil-lamp stands, and iron bracketed wall lanterns. Worker-safe.
5
+ * @module
6
+ */
7
+
8
+ import * as THREE from 'three';
9
+ import { dim } from '../math/color.js';
10
+ import { createNoise } from '../math/noise.js';
11
+ import { createHash } from '../math/random.js';
12
+ import { TAU, sstep } from '../math/scalar.js';
13
+ import { rockSheet } from './creased-sheet.js';
14
+ import { C as defaultColor, TRS as defaultTransform, createUnitShapes, stick } from './primitives.js';
15
+
16
+ let fallbackShapes = null;
17
+ const defaultShapes = () => (fallbackShapes ??= createUnitShapes());
18
+ let fallbackNoise = null;
19
+ const defaultNoise = () => (fallbackNoise ??= createNoise().vnoise);
20
+ let fallbackHash = null;
21
+ const defaultHash = () => (fallbackHash ??= createHash(42));
22
+
23
+ /** Default dressed ashlar course height in metres. */
24
+ export const ASHLAR_COURSE = 0.42;
25
+
26
+ /** Default linear RGB colours for iron lantern fittings and brass lamp stands. */
27
+ export const MASONRY_METAL = Object.freeze({
28
+ iron: Object.freeze([0.05, 0.048, 0.05]),
29
+ brass: Object.freeze([0.62, 0.46, 0.16]),
30
+ });
31
+
32
+ /** Default fluting and axial profile settings for {@link buildColumnDrum}. */
33
+ export const COLUMN_DRUM = Object.freeze({
34
+ flutes: 20,
35
+ fluteDepth: 0.07,
36
+ along: Object.freeze([0, 0.025, 0.07, 0.2, 0.35, 0.5, 0.65, 0.8, 0.93, 0.975, 1]),
37
+ end: Object.freeze([1, 0.8, 0.45, 0.12, 0]),
38
+ });
39
+
40
+ const _drum = new THREE.Matrix4();
41
+
42
+ /**
43
+ * Build an axis-aligned wall of coursed dressed ashlar blocks from `(x0, z0)` to `(x1, z1)` over a
44
+ * darker recessed core so masonry joints read cleanly. Supports ragged ruined tops and open gaps.
45
+ *
46
+ * @param {Pick<import('./builder.js').GB, 'box'>} stone - Destination stone geometry builder.
47
+ * @param {() => number} [random=Math.random] - Repeatable PRNG in `[0, 1)`.
48
+ * @param {object} options
49
+ * @param {number} options.x0 - Start X in metres.
50
+ * @param {number} options.z0 - Start Z in metres.
51
+ * @param {number} options.x1 - End X in metres.
52
+ * @param {number} options.z1 - End Z in metres.
53
+ * @param {number} [options.y=0] - Wall base elevation in metres.
54
+ * @param {number} [options.height=3] - Standing wall height in metres.
55
+ * @param {number} [options.thickness=0.6] - Wall thickness in metres.
56
+ * @param {number} [options.colorHex=0xb9a686] - Stone sRGB hex colour.
57
+ * @param {number} [options.ragged=0] - Ruin wear amplitude (`0` intact, `0..1` ragged crest).
58
+ * @param {[number, number, number] | null} [options.gap=null] - Optional open doorway `[from, to, height]` along the wall in metres.
59
+ * @param {number} [options.seed=1] - Crest wear hash seed.
60
+ * @param {number} [options.course=ASHLAR_COURSE] - Course height in metres.
61
+ * @param {(x: number, z: number, salt?: number) => number} [options.hash] - Seeded 2D hash in `[0, 1)`.
62
+ * @param {Function} [options.color] - Linear RGB colour helper.
63
+ */
64
+ export function buildAshlarWall(stone, random = Math.random, options) {
65
+ const {
66
+ x0,
67
+ z0,
68
+ x1,
69
+ z1,
70
+ y = 0,
71
+ height = 3,
72
+ thickness = 0.6,
73
+ colorHex = 0xb9a686,
74
+ ragged = 0,
75
+ gap = null,
76
+ seed = 1,
77
+ course = ASHLAR_COURSE,
78
+ hash = defaultHash(),
79
+ color = defaultColor,
80
+ } = options;
81
+ const along = Math.abs(x1 - x0) > Math.abs(z1 - z0);
82
+ const len = along ? Math.abs(x1 - x0) : Math.abs(z1 - z0);
83
+ const ax = Math.min(x0, x1);
84
+ const az = Math.min(z0, z1);
85
+ const top = u =>
86
+ height - (ragged ? ragged * height * (0.5 + 0.5 * Math.sin(u * 1.7 + seed * 2.1)) * (0.4 + 0.6 * hash((u * 2) | 0, seed, 71)) : 0);
87
+ const open = (u, v) => gap && u > gap[0] && u < gap[1] && v < gap[2];
88
+ const place = (u, v, lu, hv, thick, c) => {
89
+ const cu = u + lu / 2;
90
+ if (along) stone.box(ax + cu, y + v, z0, lu, hv, thick, c);
91
+ else stone.box(x0, y + v, az + cu, thick, hv, lu, c);
92
+ };
93
+ for (let row = 0, v = 0; v < height; row++, v += course) {
94
+ let u = row % 2 ? -0.45 : 0;
95
+ while (u < len) {
96
+ const lu = 0.7 + random() * 0.55;
97
+ const a = Math.max(0, u);
98
+ const b = Math.min(len, u + lu);
99
+ u += lu;
100
+ if (b - a < 0.12 || v + course * 0.5 > top((a + b) / 2) || open((a + b) / 2, v + course / 2)) continue;
101
+ place(a + 0.012, v + 0.012, b - a - 0.024, course - 0.024, thickness, color(colorHex, 0.07, random));
102
+ place(a, v, b - a, course, thickness - 0.07, dim(color(colorHex), 0.5));
103
+ }
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Lay a rectangular floor of individually shaded, slightly tilted square flagstones over
109
+ * `(x0, z0)..(x1, z1)` with their top faces at elevation `y`.
110
+ *
111
+ * @param {Pick<import('./builder.js').GB, 'box'>} stone - Destination stone geometry builder.
112
+ * @param {object} options
113
+ * @param {number} options.x0 - Minimum X in metres.
114
+ * @param {number} options.z0 - Minimum Z in metres.
115
+ * @param {number} options.x1 - Maximum X in metres.
116
+ * @param {number} options.z1 - Maximum Z in metres.
117
+ * @param {number} [options.y=0] - Top surface elevation in metres.
118
+ * @param {number} [options.size=1] - Nominal flagstone side length in metres.
119
+ * @param {number} [options.colorHex=0xb9a686] - Flagstone sRGB hex colour.
120
+ * @param {number} [options.seed=1] - Hash seed for shade and tilt variation.
121
+ * @param {(x: number, z: number, salt?: number) => number} [options.hash] - Seeded 2D hash in `[0, 1)`.
122
+ * @param {Function} [options.color] - Linear RGB colour helper.
123
+ */
124
+ export function buildFlagstones(stone, options) {
125
+ const { x0, z0, x1, z1, y = 0, size = 1, colorHex = 0xb9a686, seed = 1, hash = defaultHash(), color = defaultColor } = options;
126
+ for (let x = x0; x < x1 - 0.01; x += size) {
127
+ for (let z = z0; z < z1 - 0.01; z += size) {
128
+ const w = Math.min(size, x1 - x);
129
+ const d = Math.min(size, z1 - z);
130
+ const k = 0.84 + 0.18 * hash(x * 7 + seed, z * 7, 31);
131
+ stone.box(x + w / 2, y - 0.12, z + d / 2, w - 0.016, 0.12, d - 0.016, dim(color(colorHex), k), (hash(x, z, seed + 32) - 0.5) * 0.015);
132
+ }
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Build a fluted stone column drum (lying on its side) or broken standing column stump using a
138
+ * creased `rockSheet` mesh with chipped ends, fluted hollows and rising damp shading.
139
+ *
140
+ * @param {Pick<import('./builder.js').GB, 'raw'>} wall - Destination dressed-stone geometry builder.
141
+ * @param {() => number} [random=Math.random] - Repeatable PRNG in `[0, 1)`.
142
+ * @param {object} options
143
+ * @param {number} [options.x=0] - Column X position in metres.
144
+ * @param {number} [options.y=0] - Resting ground elevation in metres.
145
+ * @param {number} [options.z=0] - Column Z position in metres.
146
+ * @param {number} [options.radius=0.4] - Column radius in metres.
147
+ * @param {number} [options.length=2] - Drum or stump length in metres.
148
+ * @param {number} [options.colorHex=0xb8a888] - Stone sRGB hex colour.
149
+ * @param {boolean} [options.lying=true] - True for a fallen horizontal drum, false for a broken standing stump.
150
+ * @param {number} [options.yaw=0] - Orientation around Y in radians.
151
+ * @param {(x: number, z: number, salt?: number) => number} [options.hash] - Seeded 2D hash in `[0, 1)`.
152
+ * @param {(x: number, z: number, salt?: number) => number} [options.noise] - Seeded value noise in `[0, 1)`.
153
+ * @param {Function} [options.color] - Linear RGB colour helper.
154
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
155
+ * @param {Partial<typeof COLUMN_DRUM>} [options.shape] - Overrides to {@link COLUMN_DRUM}.
156
+ */
157
+ export function buildColumnDrum(wall, random = Math.random, options = {}) {
158
+ const {
159
+ x = 0,
160
+ y = 0,
161
+ z = 0,
162
+ radius: r = 0.4,
163
+ length: len = 2,
164
+ colorHex = 0xb8a888,
165
+ lying = true,
166
+ yaw = 0,
167
+ hash = defaultHash(),
168
+ noise = defaultNoise(),
169
+ color = defaultColor,
170
+ transform = defaultTransform,
171
+ } = options;
172
+ const cfg = options.shape ? { ...COLUMN_DRUM, ...options.shape } : COLUMN_DRUM;
173
+ const around = cfg.flutes * 3;
174
+ const key = random();
175
+ const c = dim(color(colorHex), 0.8 + 0.1 * key);
176
+ const seed = Math.floor(key * 997);
177
+ const e = _drum.copy(transform(x, y + (lying ? r : 0), z, 1, 1, 1, yaw, lying ? Math.PI / 2 : 0)).elements;
178
+ const place = (px, py, pz) => [
179
+ e[0] * px + e[4] * py + e[8] * pz + e[12],
180
+ e[1] * px + e[5] * py + e[9] * pz + e[13],
181
+ e[2] * px + e[6] * py + e[10] * pz + e[14],
182
+ ];
183
+ const slope = lying ? 0 : 0.2 * len * (0.4 + 0.6 * hash(seed, 2, 731));
184
+ const facing = TAU * hash(seed, 3, 732);
185
+ const topAt = (ca, sa, f) => len - slope * 0.5 * (1 + f * (ca * Math.cos(facing) + sa * Math.sin(facing)));
186
+ const radiusAt = (a, along, end) => {
187
+ const t = (a / TAU) * cfg.flutes;
188
+ const hollow = Math.sin(Math.PI * (t - Math.floor(t)));
189
+ const chip = 0.14 * sstep(0.62, 0.85, noise(Math.cos(a) * 3 + seed, Math.sin(a) * 3 + along * 4, 733)) * sstep(0.25, 0, end);
190
+ return r * (1 - cfg.fluteDepth * hollow) * (1 - chip) * (end < 0.004 ? 0.95 : 1);
191
+ };
192
+ const tone = (shade, low) => {
193
+ const k = shade * (lying ? 1 : 1 - 0.22 * sstep(0.5, 0, low));
194
+ return [c[0] * k, c[1] * k, c[2] * k];
195
+ };
196
+ const rows = [];
197
+ const tones = [];
198
+ const ring = (fn, tn) => {
199
+ const row = [];
200
+ const shades = [];
201
+ for (let i = 0; i < around; i++) {
202
+ const a = (i / around) * TAU;
203
+ const p = fn(a, Math.cos(a), Math.sin(a));
204
+ row.push(place(p[0], p[1], p[2]));
205
+ shades.push(tn(a));
206
+ }
207
+ rows.push(row);
208
+ tones.push(shades);
209
+ };
210
+ const grain = (a, along) => 0.9 + 0.16 * noise(Math.cos(a) * 2 + seed + along * 1.3, Math.sin(a) * 2, 734);
211
+ if (lying) {
212
+ for (const f of [...cfg.end].reverse()) {
213
+ ring(
214
+ (a, ca, sa) => [ca * radiusAt(a, 0, 0) * f, 0.01 * (1 - f), sa * radiusAt(a, 0, 0) * f],
215
+ a => tone(grain(a, 0) * 0.92, 1),
216
+ );
217
+ }
218
+ }
219
+ for (const share of cfg.along) {
220
+ ring(
221
+ (a, ca, sa) => {
222
+ const top = topAt(ca, sa, 1);
223
+ const along = share * top;
224
+ const rr = radiusAt(a, along, Math.min(along, top - along));
225
+ return [ca * rr, along, sa * rr];
226
+ },
227
+ a => {
228
+ const t = (a / TAU) * cfg.flutes;
229
+ const hollow = Math.sin(Math.PI * (t - Math.floor(t)));
230
+ return tone(grain(a, share * len) * (1 - 0.12 * hollow), share * len);
231
+ },
232
+ );
233
+ }
234
+ for (const f of cfg.end.slice(1)) {
235
+ ring(
236
+ (a, ca, sa) => {
237
+ const rr = radiusAt(a, len, 0) * f;
238
+ const rough = lying ? 0.004 : 0.05 * r * (noise(ca * f * 4 + seed, sa * f * 4, 735) - 0.5);
239
+ return [ca * rr, topAt(ca, sa, f) + rough * (1 - f * f), sa * rr];
240
+ },
241
+ a => tone(grain(a, len) * (lying ? 0.92 : 1.04), len),
242
+ );
243
+ }
244
+ rockSheet(wall, rows, tones, { wrap: true, inside: true });
245
+ }
246
+
247
+ /**
248
+ * Emit the brass stand and oil-lamp vessel geometry into `kit.trim` and `kit.cloth`, returning the
249
+ * local `[x, y, z]` wick position for a flame.
250
+ *
251
+ * @param {{ trim: import('./builder.js').GB, cloth: import('./builder.js').GB }} kit - Destination geometry builders.
252
+ * @param {object} [options]
253
+ * @param {number} [options.x=0] - Base X in metres.
254
+ * @param {number} [options.y=0] - Base elevation in metres.
255
+ * @param {number} [options.z=0] - Base Z in metres.
256
+ * @param {number} [options.height=1.25] - Stand height in metres.
257
+ * @param {readonly [number, number, number]} [options.metal=MASONRY_METAL.brass] - Linear RGB metal colour.
258
+ * @param {object} [options.shapes] - Unit shapes (`createUnitShapes()`).
259
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
260
+ * @returns {[number, number, number]} Wick position `[x, y, z]` in metres.
261
+ */
262
+ export function buildLampStandGeometry(kit, options = {}) {
263
+ const {
264
+ x = 0,
265
+ y = 0,
266
+ z = 0,
267
+ height: h = 1.25,
268
+ metal = MASONRY_METAL.brass,
269
+ shapes = defaultShapes(),
270
+ transform = defaultTransform,
271
+ } = options;
272
+ kit.trim.add(shapes.cyl16, dim(metal, 0.7), transform(x, y, z, 0.3, 0.03, 0.3));
273
+ kit.trim.add(shapes.cyl6, dim(metal, 0.8), transform(x, y, z, 0.035, h, 0.035));
274
+ kit.trim.add(shapes.cyl16, metal, transform(x, y + h, z, 0.2, 0.02, 0.2));
275
+ kit.cloth.add(shapes.sph, metal, transform(x, y + h + 0.01, z, 0.17, 0.09, 0.12));
276
+ kit.cloth.add(shapes.cone6, metal, transform(x + 0.1, y + h + 0.04, z, 0.04, 0.09, 0.04, 0, 0, -1.2));
277
+ return [x + 0.16, y + h + 0.13, z];
278
+ }
279
+
280
+ /**
281
+ * Emit an iron wall bracket and six-bar lantern cage into `kit.trim`, returning the lantern centre
282
+ * `[lx, y, lz]` in local metres.
283
+ *
284
+ * @param {{ trim: import('./builder.js').GB }} kit - Destination geometry builder container.
285
+ * @param {object} [options]
286
+ * @param {number} [options.x=0] - Wall anchor X in metres.
287
+ * @param {number} [options.y=2.5] - Bracket height in metres.
288
+ * @param {number} [options.z=0] - Wall anchor Z in metres.
289
+ * @param {number} [options.out=0] - Outward bearing in radians (`0` east, clockwise through south).
290
+ * @param {readonly [number, number, number]} [options.metal=MASONRY_METAL.iron] - Linear RGB metal colour.
291
+ * @param {object} [options.shapes] - Unit shapes (`createUnitShapes()`).
292
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
293
+ * @param {Function} [options.stickFn] - Tapered rod helper (`stick`).
294
+ * @returns {{ x: number, y: number, z: number }} Lantern centre position in metres.
295
+ */
296
+ export function buildWallLanternGeometry(kit, options = {}) {
297
+ const {
298
+ x = 0,
299
+ y = 2.5,
300
+ z = 0,
301
+ out = 0,
302
+ metal = MASONRY_METAL.iron,
303
+ shapes = defaultShapes(),
304
+ transform = defaultTransform,
305
+ stickFn = stick,
306
+ } = options;
307
+ const dx = Math.cos(out);
308
+ const dz = Math.sin(out);
309
+ const lx = x + dx * 0.55;
310
+ const lz = z + dz * 0.55;
311
+ stickFn(kit.trim, [x, y + 0.34, z], [lx, y + 0.34, lz], 0.016, metal);
312
+ stickFn(kit.trim, [x, y - 0.1, z], [x + dx * 0.4, y + 0.34, z + dz * 0.4], 0.012, metal);
313
+ stickFn(kit.trim, [lx, y + 0.34, lz], [lx, y + 0.22, lz], 0.008, metal);
314
+ kit.trim.add(shapes.cone6, metal, transform(lx, y + 0.14, lz, 0.2, 0.09, 0.2));
315
+ kit.trim.add(shapes.cyl6, metal, transform(lx, y - 0.16, lz, 0.17, 0.025, 0.17));
316
+ for (let k = 0; k < 6; k++) {
317
+ const a = (k / 6) * TAU;
318
+ const bx = lx + Math.cos(a) * 0.075;
319
+ const bz = lz + Math.sin(a) * 0.075;
320
+ stickFn(kit.trim, [bx, y - 0.14, bz], [bx, y + 0.14, bz], 0.006, metal);
321
+ }
322
+ return { x: lx, y, z: lz };
323
+ }