roamwright 0.61.14 → 0.61.15

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.
@@ -0,0 +1,343 @@
1
+ /**
2
+ * Walled courtyard gardens for planned towns: rendered perimeter wall with brick plinth, stone coping and pointed-arch
3
+ * gate, four-quarter layout cut by paved walks and stone-lined water rills meeting at a central square pool, a pillared
4
+ * domed pavilion closing the long walk, sunken raked flower and shrub beds bordered by clipped hedges, shade trees along
5
+ * the walls, benches, water planes, and colliders. Worker-safe.
6
+ * @module
7
+ */
8
+
9
+ import * as THREE from 'three';
10
+ import { dim } from '../math/color.js';
11
+ import { mulberry32 as defaultRandom, pickR as defaultPick } from '../math/random.js';
12
+ import { TAU } from '../math/scalar.js';
13
+ import { createHouseKit } from './house-kit.js';
14
+ import { kitTilled as defaultKitTilled } from './house-kit-marks.js';
15
+ import { partitionInstances } from './instances.js';
16
+ import { C as defaultColor, createUnitShapes, TRS as defaultTransform } from './primitives.js';
17
+ import { createTownWorks, DEFAULT_TOWN_PROPS, placeInTown, townFacing } from './town-works.js';
18
+
19
+ const WALL_H = 3.4; // perimeter wall height, metres
20
+ const WALK = 3; // main paved walk width, metres
21
+ const RILL = 0.6; // stone-lined water rill width down each walk, metres
22
+ const POOL = 8; // central square pool side length, metres
23
+ const GATE = 3.6; // clear gate opening width, metres
24
+
25
+ const HEDGE_STEP = 1.2; // metres of clipped border per hedge segment
26
+ const DRIFT_BAND = 1.4; // metres inside the hedge reserved for flower drifts
27
+ const SHRUB_ROOM = 0.45; // minimum clearance between shrub canopies, metres
28
+ const SHRUBS_PER_M2 = 0.55;
29
+ const TREE_CHANCE = 0.1; // share of bed shrubs grown as small ornamental trees on bare trunks
30
+ const RAKE = 1.2; // raked-earth strip pitch across sunken beds, metres
31
+
32
+ const DEFAULT_PALETTE = {
33
+ dressed: [0xd9cfb4, 0xcfc4a8, 0xe2d9c2],
34
+ fired: [0x9a6a4a, 0x8e5f42, 0xa5765a],
35
+ domes: [0x2f6f80, 0x3a7a8a, 0xd8d0bc],
36
+ timber: [0x5a4632, 0x4a3828, 0x6a5238],
37
+ brass: 0xb08b46,
38
+ earth: 0xa8916c,
39
+ water: 0x2a6f78,
40
+ leaf: [0x3d5c32, 0x4b6a3c, 0x2e4a28],
41
+ bloom: [0xc44838, 0xd8963a, 0xd8c8a0, 0x8e4a7a],
42
+ };
43
+ const DEFAULT_RENDER = [0xebe3d0, 0xe4d9c0, 0xf0e9da];
44
+ const DEFAULT_SEEN = { shrub: 320, hedge: 260, bloom: 200, crop: 170 };
45
+
46
+ /**
47
+ * Returns a point `s` metres along the perimeter of rectangle `[x0, x1, z0, z1]`, starting at `(x0, z0)`.
48
+ * @param {[number, number, number, number]} rect - Rectangle bounds `[x0, x1, z0, z1]` in metres.
49
+ * @param {number} s - Distance along the perimeter in metres.
50
+ * @returns {[number, number]} Coordinates `[x, z]` on the rectangle rim.
51
+ */
52
+ export function alongRim([x0, x1, z0, z1], s) {
53
+ const w = x1 - x0;
54
+ const d = z1 - z0;
55
+ if (s < w) return [x0 + s, z0];
56
+ if ((s -= w) < d) return [x1, z0 + s];
57
+ if ((s -= d) < w) return [x1 - s, z1];
58
+ return [x0, z1 - (s - w)];
59
+ }
60
+
61
+ function defaultPlantList(kitFrame) {
62
+ const of = { shrub: { m: [], t: [] }, hedge: { m: [], t: [] }, bloom: { m: [], t: [] }, crop: { m: [], t: [] } };
63
+ const at = new THREE.Matrix4();
64
+ const plant = (shape, tone, m) => {
65
+ if (kitFrame) at.multiplyMatrices(kitFrame, m);
66
+ else at.copy(m);
67
+ of[shape].m.push(...at.elements);
68
+ of[shape].t.push(tone[0], tone[1], tone[2]);
69
+ };
70
+ plant.orders = () =>
71
+ Object.keys(of)
72
+ .filter(shape => of[shape].t.length)
73
+ .map(shape => {
74
+ const mats = of[shape].m;
75
+ let x0 = Infinity;
76
+ let x1 = -Infinity;
77
+ let z0 = Infinity;
78
+ let z1 = -Infinity;
79
+ for (let i = 12; i < mats.length; i += 16) {
80
+ x0 = Math.min(x0, mats[i]);
81
+ x1 = Math.max(x1, mats[i]);
82
+ z0 = Math.min(z0, mats[i + 2]);
83
+ z1 = Math.max(z1, mats[i + 2]);
84
+ }
85
+ return {
86
+ plants: {
87
+ shape,
88
+ cells: partitionInstances({ matrices: new Float32Array(mats), colours: new Float32Array(of[shape].t) }, 64),
89
+ },
90
+ seen: {
91
+ x: (x0 + x1) / 2,
92
+ z: (z0 + z1) / 2,
93
+ range: Math.hypot(x1 - x0, z1 - z0) / 2 + (DEFAULT_SEEN[shape] ?? 260),
94
+ },
95
+ };
96
+ });
97
+ return plant;
98
+ }
99
+
100
+ /**
101
+ * Creates a walled town-garden builder bound to unit shapes, house-kit primitives, props, palettes and plant collection.
102
+ * @param {object} [options] - Geometry, house-kit, prop, palette and plant-collector bindings.
103
+ * @param {object} [options.shapes] - Unit shapes (`{ box, cyl6, cyl16, dome16, sph, taper }`).
104
+ * @param {(hex: number, jitter?: number, rng?: () => number) => number[]} [options.color] - Linear RGB colour helper.
105
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
106
+ * @param {(rng: () => number, list: Array<any>) => any} [options.pick] - Seeded array picker.
107
+ * @param {(seed: number) => () => number} [options.random] - Seeded PRNG factory (`mulberry32`) for bed-local planting streams.
108
+ * @param {Function} [options.archRing] - House-kit `archRing` builder.
109
+ * @param {Function} [options.facePut] - House-kit `facePut` helper.
110
+ * @param {Function} [options.kitPush] - House-kit `kitPush(x, y, z, ry)` helper.
111
+ * @param {Function} [options.kitPop] - House-kit `kitPop()` helper.
112
+ * @param {Function} [options.kitTilled] - House-kit raked-earth decal helper (`kitTilled`).
113
+ * @param {Function} [options.kitAt] - House-kit `kitAt` prop placer.
114
+ * @param {THREE.Matrix4} [options.kitFrame] - House-kit current frame matrix (used by the default plant collector).
115
+ * @param {Function} [options.facing] - Direction-to-yaw helper (`townFacing`).
116
+ * @param {Function} [options.levelFloor] - Flat deck levelling helper (`createTownWorks().levelFloor`).
117
+ * @param {Function} [options.benchProp] - Bench prop builder `(kit, rng) => void`.
118
+ * @param {object} [options.palette] - Material palettes `{ dressed, fired, domes, timber, brass, earth, water, leaf, bloom }`.
119
+ * @param {number[]} [options.renderPalette] - sRGB hex plaster palette for perimeter walls and pavilion.
120
+ * @param {() => Function} [options.createPlantList] - Factory returning a `plant(shape, tone, matrix)` collector with `.orders()`.
121
+ * @returns {{
122
+ * gardenWall: (kit: object, w: number, d: number, col: number[], stone: number[], brick: number[], drop: number) => void,
123
+ * pavilion: (kit: object, rng: () => number, z: number, col: number[], stone: number[], dome: number[], timber: number[]) => void,
124
+ * beds: (kit: object, plant: Function, xa: number, xb: number, z0: number, z1: number) => void,
125
+ * walledGarden: (K: object, rng: () => number, u: number, v: number, w: number, d: number, palms: Array<number[]>, plant: Function) => void,
126
+ * townGardens: (K: object, rng: () => number, plan: object, palms: Array<number[]>) => void,
127
+ * }} Garden building helpers.
128
+ */
129
+ export function createTownGarden(options = {}) {
130
+ const shapes = options.shapes ?? createUnitShapes();
131
+ const color = options.color ?? defaultColor;
132
+ const transform = options.transform ?? defaultTransform;
133
+ const pick = options.pick ?? defaultPick;
134
+ const random = options.random ?? defaultRandom;
135
+ let kitFallback = null;
136
+ const getKit = () => (kitFallback ??= createHouseKit({ shapes }));
137
+ const archRing = options.archRing ?? getKit().archRing;
138
+ const facePut = options.facePut ?? getKit().facePut;
139
+ const kitPush = options.kitPush ?? getKit().kitPush;
140
+ const kitPop = options.kitPop ?? getKit().kitPop;
141
+ const kitTilled = options.kitTilled ?? defaultKitTilled;
142
+ const kitAt = options.kitAt ?? getKit().kitAt;
143
+ const kitFrame = options.kitFrame ?? null;
144
+ const facing = options.facing ?? townFacing;
145
+ let worksFallback = null;
146
+ const getWorks = () => (worksFallback ??= createTownWorks({ shapes, color, transform, pick, kitAt }));
147
+ const levelFloor = options.levelFloor ?? getWorks().levelFloor;
148
+ const benchProp = options.benchProp ?? DEFAULT_TOWN_PROPS.bench;
149
+ const palette = { ...DEFAULT_PALETTE, ...options.palette };
150
+ const renderPalette = options.renderPalette ?? DEFAULT_RENDER;
151
+ const createPlantList = options.createPlantList ?? (() => defaultPlantList(kitFrame ?? getKit().kitFrame));
152
+
153
+ const setDown = (K, rng, u, v, ry, prop, y) => placeInTown(kitAt, K, rng, u, v, ry, prop, y);
154
+ // A bed's own deterministic stream keyed by its corner so planting changes never perturb the rest of the town.
155
+ const bedStream = (x0, z0) => random((Math.round(x0 * 37 + 1013) * 7919) ^ Math.round(z0 * 53 + 4099));
156
+
157
+ function gardenWall(kit, w, d, col, stone, brick, drop) {
158
+ const run = (len, x, z, ry) => {
159
+ kit.stone.box(x, -drop - 0.6, z, len, drop + 1, 0.75, brick, ry);
160
+ kit.wall.box(x, 0.4, z, len, WALL_H - 0.4, 0.6, col, ry);
161
+ kit.stone.box(x, WALL_H, z, len + 0.1, 0.18, 0.8, stone, ry);
162
+ };
163
+ const side = (w - GATE) / 2;
164
+ for (const s of [-1, 1]) {
165
+ run(side, s * (GATE / 2 + side / 2), d / 2, 0);
166
+ run(d, s * (w / 2), 0, Math.PI / 2);
167
+ kit.stone.box(s * (GATE / 2 + 0.5), -drop - 0.6, d / 2, 1.1, drop + WALL_H + 3.5, 1, dim(col, 1.05));
168
+ }
169
+ run(w, 0, -d / 2, 0);
170
+ archRing(kit.stone, facePut(0, 0, d / 2), stone, 0, WALL_H - 0.2, GATE / 2, 0, 0.3, 0.9, 0.3, shapes.box);
171
+ kit.wall.box(0, WALL_H + 2, d / 2, GATE + 0.6, 0.9, 0.9, col);
172
+ }
173
+
174
+ function pavilion(kit, rng, z, col, stone, dome, timber) {
175
+ const w = 11;
176
+ const d = 6.5;
177
+ const h = 4.2;
178
+ kit.stone.box(0, -0.5, z, w + 1.4, 1.1, d + 1.4, dim(stone, 0.92));
179
+ for (let k = 0; k < 3; k++) kit.stone.box(0, -0.5, z + d / 2 + 0.7 + 0.35 * (k + 0.5), 4, 0.6 - k * 0.2, 0.35, stone);
180
+ for (let i = 0; i < 5; i++)
181
+ for (const zz of [z + d / 2 - 0.4, z - d / 2 + 0.4]) {
182
+ const x = -w / 2 + 0.5 + i * ((w - 1) / 4);
183
+ kit.wood.add(shapes.cyl6, timber, transform(x, 0.6, zz, 0.32, h - 0.6, 0.32));
184
+ kit.wood.add(shapes.taper, dim(timber, 1.2), transform(x, h - 0.55, zz, 0.75, 0.5, 0.75, 0, Math.PI));
185
+ }
186
+ kit.wood.box(0, h - 0.05, z, w + 0.4, 0.3, d + 0.4, timber);
187
+ kit.wall.box(0, h + 0.25, z, w + 0.6, 0.35, d + 0.6, col);
188
+ kit.wall.box(0, h + 0.6, z + d / 2 + 0.15, w + 0.6, 0.6, 0.3, col);
189
+ kit.stone.add(shapes.cyl16, col, transform(0, h + 0.6, z, 4.2, 1.4, 4.2));
190
+ kit.roof.add(shapes.dome16, dome, transform(0, h + 1.95, z, 4.2, 3.6, 4.2));
191
+ kit.stone.add(shapes.sph, color(palette.brass), transform(0, h + 3.7, z, 0.4, 0.6, 0.4));
192
+ }
193
+
194
+ function beds(kit, plant, xa, xb, z0, z1) {
195
+ const x0 = Math.min(xa, xb);
196
+ const x1 = Math.max(xa, xb);
197
+ const rng = bedStream(x0, z0);
198
+ const hedge = color(palette.leaf[1], 0.04, rng);
199
+ kit.cloth.box((x0 + x1) / 2, -0.2, (z0 + z1) / 2, x1 - x0, 0.24, z1 - z0, [0.24, 0.18, 0.12]);
200
+ for (let z = z0; z < z1 - 0.3; z += RAKE)
201
+ kitTilled(kit, (x0 + x1) / 2, 0.05, z + Math.min(RAKE, z1 - z) / 2, x1 - x0, Math.min(RAKE, z1 - z));
202
+ const border = (ax, az, bx, bz) => {
203
+ const len = Math.hypot(bx - ax, bz - az);
204
+ const n = Math.max(1, Math.round(len / HEDGE_STEP));
205
+ const ry = Math.atan2(bx - ax, bz - az);
206
+ for (let i = 0; i < n; i++) {
207
+ const t = (i + 0.5) / n;
208
+ plant(
209
+ 'hedge',
210
+ dim(hedge, 0.92 + rng() * 0.16),
211
+ transform(ax + (bx - ax) * t, -0.06, az + (bz - az) * t, 0.66, 0.6 + rng() * 0.08, len / n + 0.3, ry),
212
+ );
213
+ }
214
+ };
215
+ const e = 0.35;
216
+ border(x0 + e, z0 + e, x1 - e, z0 + e);
217
+ border(x0 + e, z1 - e, x1 - e, z1 - e);
218
+ border(x0 + e, z0 + e + 0.6, x0 + e, z1 - e - 0.6);
219
+ border(x1 - e, z0 + e + 0.6, x1 - e, z1 - e - 0.6);
220
+
221
+ const inner = [x0 + 0.9, x1 - 0.9, z0 + 0.9, z1 - 0.9];
222
+ const perimeter = 2 * (inner[1] - inner[0] + inner[3] - inner[2]);
223
+ for (let s = rng() * 1.5; s < perimeter; s += 1.1 + rng() * 1.1) {
224
+ if (rng() < 0.15) continue;
225
+ const [dx, dz] = alongRim(inner, s);
226
+ const bloom = color(pick(rng, palette.bloom), 0.08, rng);
227
+ const n = 2 + Math.floor(rng() * 3);
228
+ for (let k = 0; k < n; k++) {
229
+ const a = rng() * TAU;
230
+ const r = rng() * 0.5;
231
+ const sz = 0.45 + rng() * 0.3;
232
+ const m = transform(dx + Math.cos(a) * r, -0.06, dz + Math.sin(a) * r, sz, sz * (0.9 + rng() * 0.5), sz, rng() * TAU);
233
+ plant('shrub', color(pick(rng, palette.leaf), 0.1, rng), m);
234
+ plant('bloom', dim(bloom, 0.9 + rng() * 0.2), m);
235
+ }
236
+ }
237
+
238
+ const mx0 = x0 + DRIFT_BAND;
239
+ const mx1 = x1 - DRIFT_BAND;
240
+ const mz0 = z0 + DRIFT_BAND;
241
+ const mz1 = z1 - DRIFT_BAND;
242
+ if (mx1 <= mx0 || mz1 <= mz0) return;
243
+ const want = Math.round((mx1 - mx0) * (mz1 - mz0) * SHRUBS_PER_M2);
244
+ const placed = [];
245
+ for (let tries = 0; placed.length < want && tries < want * 12; tries++) {
246
+ const x = mx0 + rng() * (mx1 - mx0);
247
+ const z = mz0 + rng() * (mz1 - mz0);
248
+ const tree = rng() < TREE_CHANCE;
249
+ const r = tree ? 0.9 + rng() * 0.4 : 0.35 + rng() * 0.4;
250
+ let clear = true;
251
+ for (let i = 0; i < placed.length && clear; i++) {
252
+ const p = placed[i];
253
+ clear = Math.hypot(p[0] - x, p[1] - z) > p[2] + r + SHRUB_ROOM * rng();
254
+ }
255
+ if (!clear) continue;
256
+ placed.push([x, z, r]);
257
+ const leaf = color(pick(rng, palette.leaf), 0.1, rng);
258
+ if (tree) {
259
+ const trunk = 0.9 + rng() * 0.5;
260
+ kit.wood.add(
261
+ shapes.taper,
262
+ color(pick(rng, palette.timber), 0.08, rng),
263
+ transform(x, 0, z, 0.12, trunk + 0.3, 0.12, 0, (rng() - 0.5) * 0.15),
264
+ );
265
+ plant('shrub', leaf, transform(x, trunk - r * 0.3, z, r * 2.1, r * 1.8, r * 2.1, rng() * TAU));
266
+ } else {
267
+ plant('shrub', leaf, transform(x, -0.06, z, r * 2, r * (1.25 + rng() * 0.5), r * 2, rng() * TAU));
268
+ }
269
+ }
270
+ }
271
+
272
+ function walledGarden(K, rng, u, v, w, d, palms, plant) {
273
+ const col = color(pick(rng, renderPalette), 0.03, rng);
274
+ const stone = color(pick(rng, palette.dressed), 0.03, rng);
275
+ const brick = color(pick(rng, palette.fired), 0.04, rng);
276
+ const dome = color(palette.domes[0], 0.05, rng);
277
+ const timber = color(pick(rng, palette.timber), 0.05, rng);
278
+ const ry = facing(0, 1);
279
+ const { y, drop } = levelFloor(K, u, v, w, d);
280
+ const frame = (x, z) => [u - x, v + z];
281
+ const inW = w / 2 - 1;
282
+ const inD = d / 2 - 1;
283
+ const pavX = inW - 4.4;
284
+ const bedEnd = pavX - 5;
285
+ const quarter = w / 4;
286
+ setDown(K, rng, u, v, ry, kit => {
287
+ gardenWall(kit, w, d, col, stone, brick, drop);
288
+ kit.wall.box(0, -drop - 0.5, 0, w - 0.6, drop + 0.48, d - 0.6, color(palette.earth, 0.04, rng));
289
+ kit.stone.box(0, -0.1, 0, w - 1.2, 0.16, WALK, stone);
290
+ kit.stone.box(0, -0.1, 0, WALK, 0.16, d - 1.2, stone);
291
+ for (const x of [-quarter, quarter]) kit.stone.box(x, -0.1, 0, WALK * 0.8, 0.16, d - 1.2, dim(stone, 0.96));
292
+ kit.stone.box(0, -0.2, 0, RILL + 0.3, 0.32, d - 2, dim(stone, 0.8));
293
+ kit.stone.box(-1, -0.2, 0, w - 4, 0.32, RILL + 0.3, dim(stone, 0.8));
294
+ kit.stone.box(0, -0.3, 0, POOL, 0.32, POOL, dim(stone, 0.7));
295
+ for (const s of [-1, 1]) {
296
+ kit.stone.box(0, -0.25, s * (POOL / 2 + 0.25), POOL + 1, 0.6, 0.5, dim(stone, 1.04));
297
+ kit.stone.box(s * (POOL / 2 + 0.25), -0.25, 0, 0.5, 0.6, POOL, dim(stone, 1.04));
298
+ }
299
+ kitPush(pavX, 0, 0, -Math.PI / 2);
300
+ pavilion(kit, rng, 0, col, stone, dome, timber);
301
+ kitPop();
302
+ for (const sz of [-1, 1]) {
303
+ const za = sz < 0 ? -inD : WALK / 2 + 0.3;
304
+ const zb = sz < 0 ? -WALK / 2 - 0.3 : inD;
305
+ for (const sx of [-1, 1]) {
306
+ const near = POOL / 2 + 1.2;
307
+ const mid = quarter - WALK * 0.4 - 0.2;
308
+ const far = sx > 0 ? bedEnd : inW;
309
+ beds(kit, plant, sx * near, sx * mid, za, zb);
310
+ beds(kit, plant, sx * (quarter + WALK * 0.4 + 0.2), sx * far, za, zb);
311
+ }
312
+ }
313
+ });
314
+ const water = (x, z, sx, sz, h = 0.14) => {
315
+ const [fu, fv] = frame(x, z);
316
+ const [wx, wz] = K.f.world(fu, fv);
317
+ K.glow('plane', [sx, sz], palette.water, 0.45, [wx, y + h, wz], K.f.yaw + ry);
318
+ };
319
+ water(0, 0, RILL, d - 2.2);
320
+ water(-1, 0, w - 4.2, RILL);
321
+ water(0, 0, POOL, POOL, 0.22);
322
+ for (let x = -inW + 2; x < bedEnd; x += 6.5) for (const z of [-inD + 1.6, inD - 1.6]) palms.push([...frame(x, z), 0.85 + rng() * 0.35]);
323
+ for (const s of [-1, 1]) {
324
+ const [bu, bv] = frame(s * (POOL / 2 + 2.2), WALK / 2 + 0.7);
325
+ setDown(K, rng, bu, bv, ry + Math.PI, benchProp, y);
326
+ }
327
+ const side = (w - GATE) / 2;
328
+ for (const s of [-1, 1]) {
329
+ K.solid(...frame(s * (GATE / 2 + side / 2), d / 2), side / 2, 0.4);
330
+ K.solid(...frame(s * (w / 2), 0), 0.4, d / 2);
331
+ }
332
+ K.solid(...frame(0, -d / 2), w / 2, 0.4);
333
+ K.solid(...frame(pavX, 0), 4, 6.2);
334
+ }
335
+
336
+ function townGardens(K, rng, plan, palms) {
337
+ const plant = createPlantList();
338
+ for (const k of plan.town.kept) if (k.garden) walledGarden(K, rng, k.u, k.v, k.w - 2, k.d - 2, palms, plant);
339
+ K.orders.push(...plant.orders());
340
+ }
341
+
342
+ return { gardenWall, pavilion, beds, walledGarden, townGardens };
343
+ }
package/index.js CHANGED
@@ -124,8 +124,12 @@ export { createTownHouses } from './geometry/town-houses.js';
124
124
  export { ARCADE_BAY, ARCADE_WALK, createTownWorks, townFacing } from './geometry/town-works.js';
125
125
  export { createTownLights, distantTownLights } from './geometry/town-lights.js';
126
126
  export { createCourtyardInn } from './geometry/town-courtyard-inn.js';
127
- export { createStreetLamps } from './rendering/street-lamps.js';
127
+ export { alongRim, createTownGarden } from './geometry/town-garden.js';
128
+ export { createGardenPlantShapes, GARDEN_PLANT_LOBES } from './geometry/plant-garden.js';
129
+ export { createGardenPlants } from './rendering/plant-garden.js';
130
+ export { CITY_GLOW_FALLOFF, createCityGlow, createStreetLampNight, createStreetLamps } from './rendering/street-lamps.js';
128
131
  export { createLampLightMap } from './rendering/lamp-light-map.js';
132
+ export { createCityLamplight, createNearestLampMaps, lampMapTexture } from './rendering/lamp-maps.js';
129
133
  export { createWallRuns } from './geometry/wall-runs.js';
130
134
  export {
131
135
  addBattlement,
@@ -160,6 +164,7 @@ export { createRoomMaterials } from './rendering/room-materials.js';
160
164
  export { finishRoom } from './rendering/room-space.js';
161
165
 
162
166
  // ── Vessels ──────────────────────────────────────────────────────────────
167
+ export { createHarbourKit } from './geometry/harbour-kit.js';
163
168
  export { createShipKit } from './geometry/ship-kit.js';
164
169
  export { SHIP_PRESETS } from './geometry/ship-presets.js';
165
170
  export { createShipMeshes } from './rendering/ship-meshes.js';
@@ -232,6 +237,8 @@ export { DEFAULT_PARTICLE_LOOK, createParticleNoiseTexture, createParticleSystem
232
237
  export { createFireLightWatch } from './rendering/fire-light-watch.js';
233
238
  export { createEffectsFrame, syncEffectsUniforms } from './rendering/effects-frame.js';
234
239
  export { createRippleRingMaterial, createWaterRises, fishGeometry } from './rendering/effects-water-rises.js';
240
+ export { STORM_WALL_DEFAULTS, stormWallArrays } from './geometry/storm-wall.js';
241
+ export { STORM_WALL_COLORS, createStormWall, stormWallGeometry, stormWallNoise } from './rendering/storm-wall.js';
235
242
  export { createPracticalFlame, createSceneLights } from './rendering/scene-lights.js';
236
243
  export { createSiteSchedule } from './runtime/effect-sites.js';
237
244
  export { createSoundscape } from './runtime/soundscape.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roamwright",
3
- "version": "0.61.14",
3
+ "version": "0.61.15",
4
4
  "description": "A procedural worldbuilding engine built on top of Three.js. Generate landscapes with rivers and changing weather, animate crowds, and explore on foot or in flight.",
5
5
  "keywords": [
6
6
  "threejs",
@@ -2,6 +2,8 @@
2
2
  // the viewer is in. Towns lie kilometres apart, so the map changes hands far from both. Each town's points of light in the
3
3
  // distance are shown by night while the viewer is near enough to see them.
4
4
  import * as THREE from 'three';
5
+ import { lampTexels } from '../math/lamp-texels.js';
6
+ import { createLightPoints } from './light-points.js';
5
7
  import { onCardOnly } from './textures.js';
6
8
 
7
9
  /**
@@ -60,3 +62,88 @@ export function createNearestLampMaps({ camera, map, rect, night, land, span = 2
60
62
  }
61
63
  return { add, bindNearest, count: () => maps.length };
62
64
  }
65
+
66
+ /**
67
+ * Registers per-city baked lamp-light texel maps and depth-tested distant point batches, binding the nearest city's map
68
+ * to shared surface uniforms when the viewer approaches.
69
+ * @param {object} options
70
+ * @param {THREE.Camera} options.camera - Viewer camera.
71
+ * @param {{ value: any }} options.map - Surface shader lamp-map texture uniform.
72
+ * @param {{ value: { set: Function } }} options.rect - Surface shader lamp-map bounds uniform.
73
+ * @param {{ value: number }} options.night - Night intensity uniform (`0..1`).
74
+ * @param {() => string} options.land - Active land/space id accessor.
75
+ * @param {{ value: number }} options.pointScale - Pixel scale uniform for `createLightPoints`.
76
+ * @param {{ uniform: { value: THREE.Color }, color: [number, number, number] }} [options.tint] - Optional surface lamp-colour uniform set once on first registration.
77
+ * @param {(fn: () => void) => void} [options.watch] - Optional callback registered once with `bindNearest` when the first city is added.
78
+ * @param {number} [options.texel=1.5] - Metres per texel of each city's lamp map.
79
+ * @param {number} [options.reach=8] - Metres each lamp's wall light reaches.
80
+ * @param {number} [options.strength=1] - Peak lamp-map value at a lamp.
81
+ * @param {number} [options.span=2500] - Metres from a city's centre within which its lamp map is bound.
82
+ * @param {number} [options.lastLight=4200] - Metres beyond which distant city point lights fade out and hide.
83
+ * @param {THREE.Color | [number, number, number] | number} [options.pointColor=0xffd28a] - Distant point light colour.
84
+ * @param {object} [options.pointOptions] - Extra options forwarded to `createLightPoints`.
85
+ * @param {number} [options.renderOrder=8] - Render order of the distant point batch.
86
+ * @param {string} [options.name='Distant city lanterns and windows'] - Object name for the distant point batch.
87
+ * @returns {{
88
+ * addCity: (space: { id: string, group: THREE.Object3D }, x: number, z: number, data: { lamps: number[], lights: Float32Array }) => THREE.Object3D | null,
89
+ * bindNearest: () => void,
90
+ * count: () => number,
91
+ * }} City lamplight registry.
92
+ */
93
+ export function createCityLamplight({
94
+ camera,
95
+ map,
96
+ rect,
97
+ night,
98
+ land,
99
+ pointScale,
100
+ tint = null,
101
+ watch = null,
102
+ texel = 1.5,
103
+ reach = 8,
104
+ strength = 1,
105
+ span = 2500,
106
+ lastLight = 4200,
107
+ pointColor = 0xffd28a,
108
+ pointOptions = {},
109
+ renderOrder = 8,
110
+ name = 'Distant city lanterns and windows',
111
+ }) {
112
+ const maps = createNearestLampMaps({ camera, map, rect, night, land, span, lastLight });
113
+
114
+ function addCity(sp, x, z, { lamps, lights }) {
115
+ if (!lamps.length) return null;
116
+ const texels = lampTexels(lamps, { texel, reach, strength });
117
+ const texture = lampMapTexture(texels);
118
+ if (!maps.count()) {
119
+ if (tint) tint.uniform.value.setRGB(...tint.color);
120
+ if (watch) watch(maps.bindNearest);
121
+ }
122
+ const color =
123
+ pointColor instanceof THREE.Color
124
+ ? pointColor.clone()
125
+ : Array.isArray(pointColor)
126
+ ? new THREE.Color().setRGB(...pointColor)
127
+ : new THREE.Color(pointColor);
128
+ const points = createLightPoints({
129
+ positions: lights,
130
+ color,
131
+ intensity: night,
132
+ pointScale,
133
+ emitterDiameter: 0,
134
+ haloDiameter: 3.8,
135
+ minPixels: 6,
136
+ distantGain: 2.8,
137
+ fadeIn: [48, 160],
138
+ fadeOut: [1600, lastLight],
139
+ ...pointOptions,
140
+ });
141
+ points.name = name;
142
+ points.renderOrder = renderOrder;
143
+ sp.group.add(points);
144
+ maps.add({ land: sp.id, x, z, points, texture, rect: texels.rect });
145
+ return points;
146
+ }
147
+
148
+ return { addCity, bindNearest: maps.bindNearest, count: maps.count };
149
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Instanced garden plant cell renderer: binds cached multi-lobe garden plant shapes (`createGardenPlantShapes`) to a
3
+ * foliage material across spatial cells so each pass can frustum-cull cells independently.
4
+ * @module
5
+ */
6
+
7
+ import * as THREE from 'three';
8
+ import { instancedMesh } from '../geometry/instances.js';
9
+ import { createGardenPlantShapes } from '../geometry/plant-garden.js';
10
+
11
+ /**
12
+ * Creates a garden plant mesh builder bound to a foliage material and shared cached plant geometries.
13
+ * @param {object} [options] - Geometry and material options.
14
+ * @param {(seed: number, detail?: number) => THREE.BufferGeometry} [options.crownBlob] - Displaced crown lump helper (`createPlantTints().crownBlob`).
15
+ * @param {(hex: number) => (x: number, y: number, z: number, out: number[]) => void} [options.crownTint] - Foliage vertex tint helper (`createPlantTints().crownTint`).
16
+ * @param {THREE.Material | (() => THREE.Material)} [options.material] - Foliage material (or lazy factory called on mesh build).
17
+ * @param {Record<string, number[][]>} [options.lobes] - Lobe definitions per plant kind (`GARDEN_PLANT_LOBES`).
18
+ * @param {number} [options.detail=1] - Icosahedron subdivision detail per lobe.
19
+ * @param {number} [options.color=0xffffff] - Base sRGB hex colour before per-instance tinting.
20
+ * @returns {{
21
+ * plantShape: (kind: string) => THREE.BufferGeometry,
22
+ * plantsMesh: (order: { shape: string, cells: Array<{ matrices: Float32Array, colours: Float32Array }> }) => THREE.Group,
23
+ * geometries: WeakSet<THREE.BufferGeometry>,
24
+ * }} Cached shape builder, cell group builder, and shared-geometry membership set (to protect cached geometries on unload).
25
+ */
26
+ export function createGardenPlants(options = {}) {
27
+ const { plantShape, geometries } = createGardenPlantShapes(options);
28
+ let fallbackMaterial = null;
29
+ const resolveMaterial =
30
+ typeof options.material === 'function'
31
+ ? options.material
32
+ : options.material
33
+ ? () => options.material
34
+ : () => (fallbackMaterial ??= new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9 }));
35
+
36
+ function plantsMesh({ shape, cells }) {
37
+ const group = new THREE.Group();
38
+ const geometry = plantShape(shape);
39
+ const material = resolveMaterial();
40
+ for (const cell of cells) {
41
+ const mesh = instancedMesh(geometry, material, cell);
42
+ mesh.castShadow = mesh.receiveShadow = true;
43
+ mesh.matrixAutoUpdate = false;
44
+ mesh.computeBoundingSphere();
45
+ group.add(mesh);
46
+ }
47
+ return group;
48
+ }
49
+
50
+ return { plantShape, plantsMesh, geometries };
51
+ }