roamwright 0.61.14 → 0.61.16

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,92 @@
1
+ /**
2
+ * Procedural multi-lobe garden plant shapes (shrubs, clipped hedges, field crops and blossom clusters) built from
3
+ * displaced foliage blobs with vertex ambient shading and leaf flags. Worker-safe.
4
+ * @module
5
+ */
6
+
7
+ import * as THREE from 'three';
8
+ import { createNoise } from '../math/noise.js';
9
+ import { createHash } from '../math/random.js';
10
+ import { addShape, partsGeometry, shapeParts } from './foliage.js';
11
+ import { createPlantTints } from './plant-tints.js';
12
+
13
+ const BLOSSOMS = 6;
14
+ const DEFAULT_LOBE_DETAIL = 1; // icosahedron subdivided once: 80 triangles per lobe
15
+ const DEFAULT_BASE_COLOR = 0xffffff; // shaded in white so per-instance colours tint each plant
16
+
17
+ /**
18
+ * Default unit-plant lobe tables standing on `y = 0`: each entry is `[x, y, z, width, height, depth]` in local metres.
19
+ */
20
+ export const GARDEN_PLANT_LOBES = {
21
+ shrub: [
22
+ [0, 0.42, 0, 0.95, 0.82, 0.95],
23
+ [0.24, 0.3, 0.12, 0.62, 0.56, 0.6],
24
+ [-0.2, 0.3, -0.16, 0.64, 0.52, 0.6],
25
+ ],
26
+ hedge: [
27
+ // Clipped hedge unit 1 m along z: two lobes across and three along so border segments merge cleanly.
28
+ ...[-0.17, 0.17].flatMap(x => [-0.33, 0, 0.33].map(z => [x, 0.33, z, 0.52, 0.74, 0.56])),
29
+ ],
30
+ crop: [
31
+ // Lighter two-lobe row-crop tuft for dense fields.
32
+ [0, 0.34, 0, 0.92, 0.7, 0.92],
33
+ [0.16, 0.24, -0.12, 0.6, 0.5, 0.6],
34
+ ],
35
+ bloom: [
36
+ // Blossom clusters emerging from the top of a flowering shrub.
37
+ ...Array.from({ length: BLOSSOMS }, (_, i) => {
38
+ const a = i * 2.4;
39
+ const r = 0.08 + 0.34 * Math.sqrt((i + 0.5) / BLOSSOMS);
40
+ return [Math.cos(a) * r, 0.86 - r * 0.62, Math.sin(a) * r, 0.3, 0.2, 0.3];
41
+ }),
42
+ ],
43
+ };
44
+
45
+ /**
46
+ * Creates a cached geometry factory for multi-lobe garden plants (`shrub`, `hedge`, `crop`, `bloom`, or custom kinds).
47
+ * @param {object} [options] - Plant tint helpers and lobe overrides.
48
+ * @param {(seed: number, detail?: number) => THREE.BufferGeometry} [options.crownBlob] - Displaced crown lump helper (`createPlantTints().crownBlob`).
49
+ * @param {(hex: number) => (x: number, y: number, z: number, out: number[]) => void} [options.crownTint] - Foliage vertex tint helper (`createPlantTints().crownTint`).
50
+ * @param {Record<string, number[][]>} [options.lobes] - Map of plant kind name to `[x, y, z, w, h, d]` lobe lists.
51
+ * @param {number} [options.detail=1] - Icosahedron subdivision detail per lobe.
52
+ * @param {number} [options.color=0xffffff] - Base sRGB hex colour before per-instance tinting.
53
+ * @returns {{
54
+ * plantShape: (kind: string) => THREE.BufferGeometry,
55
+ * geometries: WeakSet<THREE.BufferGeometry>,
56
+ * }} Cached geometry accessor and shared-geometry membership set.
57
+ */
58
+ export function createGardenPlantShapes(options = {}) {
59
+ let tintsFallback = null;
60
+ const getTints = () => {
61
+ if (!tintsFallback) {
62
+ const { fbm, vnoise } = createNoise(0);
63
+ tintsFallback = createPlantTints({ fbm, vnoise, hash: createHash(0) });
64
+ }
65
+ return tintsFallback;
66
+ };
67
+ const crownBlob = options.crownBlob ?? getTints().crownBlob;
68
+ const crownTint = options.crownTint ?? getTints().crownTint;
69
+ const lobes = options.lobes ?? GARDEN_PLANT_LOBES;
70
+ const detail = options.detail ?? DEFAULT_LOBE_DETAIL;
71
+ const baseColor = options.color ?? DEFAULT_BASE_COLOR;
72
+
73
+ const shapes = {};
74
+ const geometries = new WeakSet();
75
+
76
+ function plantShape(kind) {
77
+ if (shapes[kind]) return shapes[kind];
78
+ const spec = lobes[kind];
79
+ if (!spec) throw new Error(`Unknown garden plant shape: ${kind}`);
80
+ const parts = shapeParts();
81
+ const m = new THREE.Matrix4();
82
+ spec.forEach(([x, y, z, w, h, d], i) => {
83
+ m.makeScale(w, h, d).setPosition(x, y, z);
84
+ addShape(parts, crownBlob(i * 3.7 + kind.length, detail), m, crownTint(baseColor), 1);
85
+ });
86
+ const geometry = partsGeometry(parts);
87
+ geometries.add(geometry);
88
+ return (shapes[kind] = geometry);
89
+ }
90
+
91
+ return { plantShape, geometries };
92
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Pure typed-array geometry builder for a curved multi-layer storm curtain wall (sandstorm, blizzard, or ash wall):
3
+ * concentric vertical strips following a circular arc with ground-conforming footings, scrolling UVs, and per-vertex
4
+ * arc-end and layer-depth attributes. Worker-safe and free of Three.js.
5
+ * @module
6
+ */
7
+
8
+ /** Default subdivision and layout constants for a layered storm wall mesh. */
9
+ export const STORM_WALL_DEFAULTS = {
10
+ layers: 5,
11
+ along: 150,
12
+ up: 10,
13
+ footSink: 8,
14
+ uvScale: 210,
15
+ layerUvOffset: 0.37,
16
+ };
17
+
18
+ /**
19
+ * Generates vertex attribute and index typed arrays for a concentric multi-curtain storm wall arc.
20
+ * @param {object} options
21
+ * @param {number} [options.x=0] - Arc centre world X coordinate in metres.
22
+ * @param {number} [options.z=0] - Arc centre world Z coordinate in metres.
23
+ * @param {number} [options.radius=1200] - Mean arc radius in metres.
24
+ * @param {number} [options.sweep=1.5] - Half-angle of the arc on each side of `+x` in radians.
25
+ * @param {number} [options.width=150] - Radial thickness spanned across all curtain layers in metres.
26
+ * @param {number} [options.height=300] - Curtain wall height in metres.
27
+ * @param {(x: number, z: number) => number} [options.ground] - Ground height sampler `(x, z) => y` in metres (defaults to 0).
28
+ * @param {number} [options.layers=5] - Number of concentric curtain sheets.
29
+ * @param {number} [options.along=150] - Horizontal segments along the arc.
30
+ * @param {number} [options.up=10] - Vertical segments from foot to crest.
31
+ * @param {number} [options.footSink=8] - Metres the bottom edge sinks below ground so slopes never expose a gap.
32
+ * @param {number} [options.uvScale=210] - Arc-length metres per U repeat.
33
+ * @param {number} [options.layerUvOffset=0.37] - U phase shift per curtain layer so layers never align.
34
+ * @returns {{ position: Float32Array, uv: Float32Array, aEdge: Float32Array, index: Uint16Array | Uint32Array }} Typed mesh arrays.
35
+ */
36
+ export function stormWallArrays({
37
+ x: cx = 0,
38
+ z: cz = 0,
39
+ radius = 1200,
40
+ sweep = 1.5,
41
+ width = 150,
42
+ height = 300,
43
+ ground = () => 0,
44
+ layers = STORM_WALL_DEFAULTS.layers,
45
+ along = STORM_WALL_DEFAULTS.along,
46
+ up = STORM_WALL_DEFAULTS.up,
47
+ footSink = STORM_WALL_DEFAULTS.footSink,
48
+ uvScale = STORM_WALL_DEFAULTS.uvScale,
49
+ layerUvOffset = STORM_WALL_DEFAULTS.layerUvOffset,
50
+ } = {}) {
51
+ const row = up + 1;
52
+ const vertsPerLayer = (along + 1) * row;
53
+ const totalVerts = layers * vertsPerLayer;
54
+ const position = new Float32Array(totalVerts * 3);
55
+ const uv = new Float32Array(totalVerts * 2);
56
+ const aEdge = new Float32Array(totalVerts * 2);
57
+ const index = totalVerts > 65535 ? new Uint32Array(layers * along * up * 6) : new Uint16Array(layers * along * up * 6);
58
+ const layerSpan = layers > 1 ? layers - 1 : 1;
59
+
60
+ let p = 0;
61
+ let u = 0;
62
+ let e = 0;
63
+ let idx = 0;
64
+ for (let layer = 0; layer < layers; layer++) {
65
+ const r = radius + (layers > 1 ? layer / layerSpan - 0.5 : 0) * width;
66
+ const base = layer * vertsPerLayer;
67
+ const layerShare = layers > 1 ? layer / layerSpan : 0.5;
68
+ for (let i = 0; i <= along; i++) {
69
+ const t = i / along;
70
+ const a = (t * 2 - 1) * sweep;
71
+ const x = cx + Math.cos(a) * r;
72
+ const z = cz + Math.sin(a) * r;
73
+ const foot = Math.max(ground(x, z), 0) - footSink;
74
+ const stU = (a * r) / uvScale + layer * layerUvOffset;
75
+ const edgeT = Math.min(t, 1 - t);
76
+ for (let j = 0; j <= up; j++) {
77
+ const v = j / up;
78
+ position[p++] = x;
79
+ position[p++] = foot + v * height;
80
+ position[p++] = z;
81
+ uv[u++] = stU;
82
+ uv[u++] = v;
83
+ aEdge[e++] = edgeT;
84
+ aEdge[e++] = layerShare;
85
+ if (i && j) {
86
+ const k = base + i * row + j;
87
+ index[idx++] = k - row - 1;
88
+ index[idx++] = k - row;
89
+ index[idx++] = k;
90
+ index[idx++] = k - row - 1;
91
+ index[idx++] = k;
92
+ index[idx++] = k - 1;
93
+ }
94
+ }
95
+ }
96
+ }
97
+ return { position, uv, aEdge, index };
98
+ }
@@ -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.16",
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
+ }