roamwright 0.61.24 → 0.61.26

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,244 @@
1
+ /**
2
+ * Underground and vaulted stone-hall masonry builders: coursed stone walls with lintelled doorways
3
+ * and walk colliders, flagstone floors with optional cutouts, beam-and-slab flat ceilings, ribbed
4
+ * barrel vaults, eight-sided chambers, and corbelled stone roofs. Worker-safe.
5
+ * @module
6
+ */
7
+
8
+ import { dim } from '../math/color.js';
9
+ import { createHash } from '../math/random.js';
10
+ import { C as defaultColor, TRS as defaultTransform, createUnitShapes } from './primitives.js';
11
+
12
+ let fallbackShapes = null;
13
+ const defaultShapes = () => (fallbackShapes ??= createUnitShapes());
14
+ let fallbackHash = null;
15
+ const defaultHash = () => (fallbackHash ??= createHash(42));
16
+
17
+ /** Default thickness of a coursed stone hall wall in metres. */
18
+ export const HALL_WALL_THICKNESS = 0.8;
19
+
20
+ /** Default pale dressed limestone sRGB hex colour for stone halls. */
21
+ export const HALL_STONE_TONE = 0xb9ad94;
22
+
23
+ /** Default darker stone sRGB hex colour for older underground chambers and corbelled roofs. */
24
+ export const HALL_OLD_STONE_TONE = 0x8a7c68;
25
+
26
+ /**
27
+ * Create a set of stone-hall masonry builders bound to a world's hash, unit shapes, transform
28
+ * helper and default wall thickness and tones.
29
+ *
30
+ * @param {object} [options]
31
+ * @param {(i: number, j: number, salt?: number) => number} [options.hash] - Seeded 2D hash in `[0, 1)`.
32
+ * @param {{ box: import('three').BufferGeometry }} [options.shapes] - Unit shapes providing `box` for vault voussoirs.
33
+ * @param {(hex: number, jitter?: number, rng?: () => number) => number[]} [options.color] - Linear RGB colour helper.
34
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
35
+ * @param {number} [options.wallThickness=HALL_WALL_THICKNESS] - Wall thickness in metres.
36
+ * @param {number} [options.tone=HALL_STONE_TONE] - Default stone sRGB hex colour for walls, floors, slab ceilings and barrel vaults.
37
+ * @param {number} [options.oldTone=HALL_OLD_STONE_TONE] - Default darker stone sRGB hex colour for octagonal chambers and corbel roofs.
38
+ * @returns {{
39
+ * wall: (K: object, a: [number, number], b: [number, number], y: number, h: number, gaps?: Array<{ at: number, w: number, h: number }>, stoneTone?: number, course?: number) => void,
40
+ * flags: (K: object, x0: number, x1: number, z0: number, z1: number, y: number, size?: number, stoneTone?: number, skip?: ((x: number, z: number) => boolean) | null) => void,
41
+ * slabCeiling: (K: object, x0: number, x1: number, z0: number, z1: number, y: number, stoneTone?: number) => void,
42
+ * barrelVault: (K: object, x0: number, x1: number, z0: number, z1: number, y: number, rise: number, stoneTone?: number) => void,
43
+ * octagonWalls: (K: object, c: { x: number, z: number }, r: number, y: number, h: number, doors?: Record<number, { w: number, h: number }>, stoneTone?: number) => void,
44
+ * corbelRoof: (K: object, c: { x: number, z: number }, r: number, y: number, stoneTone?: number) => void,
45
+ * }}
46
+ */
47
+ export function createStoneHalls(options = {}) {
48
+ const {
49
+ hash = defaultHash(),
50
+ shapes = defaultShapes(),
51
+ color = defaultColor,
52
+ transform = defaultTransform,
53
+ wallThickness = HALL_WALL_THICKNESS,
54
+ tone: defaultTone = HALL_STONE_TONE,
55
+ oldTone: defaultOldTone = HALL_OLD_STONE_TONE,
56
+ } = options;
57
+
58
+ /**
59
+ * Build a wall of coursed stone blocks along the centre line from `a` to `b` (`[x, z]` in metres),
60
+ * standing on elevation `y` and `h` metres high. Doorways in `gaps` (`{ at, w, h }`) receive stone
61
+ * jambs and lintels and are carved out of the box colliders pushed to `K.solid`.
62
+ */
63
+ function wall(K, a, b, y, h, gaps = [], stoneTone = defaultTone, course = 0.52) {
64
+ const len = Math.hypot(b[0] - a[0], b[1] - a[1]),
65
+ ux = (b[0] - a[0]) / len,
66
+ uz = (b[1] - a[1]) / len,
67
+ ry = -Math.atan2(uz, ux),
68
+ rows = Math.max(1, Math.round(h / course)),
69
+ rise = h / rows,
70
+ seed = Math.round(a[0] * 31 + a[1] * 17 + b[0] * 7 + b[1] * 3),
71
+ stone = color(stoneTone),
72
+ lay = (s0, s1, y0, sy, t, k) =>
73
+ K.B.stone.box(a[0] + ux * ((s0 + s1) / 2), y0, a[1] + uz * ((s0 + s1) / 2), s1 - s0, sy, t, dim(stone, k), ry);
74
+ for (let i = 0; i < rows; i++) {
75
+ const y0 = y + i * rise;
76
+ let s = i % 2 ? -0.5 : 0;
77
+ while (s < len - 0.01) {
78
+ const s0 = Math.max(0, s),
79
+ gap = gaps.find(g => y0 - y < g.h - 0.02 && s + 0.85 > g.at - g.w / 2 + 0.01 && s0 < g.at + g.w / 2 - 0.01);
80
+ if (gap) {
81
+ if (s0 < gap.at - gap.w / 2 - 0.05) lay(s0, gap.at - gap.w / 2, y0, rise - 0.015, wallThickness, 0.86);
82
+ s = gap.at + gap.w / 2;
83
+ continue;
84
+ }
85
+ let e = Math.min(len, s + 0.85 + 0.5 * hash(i, Math.round(s * 10), seed));
86
+ const next = gaps.find(g => y0 - y < g.h - 0.02 && e > g.at - g.w / 2 && s0 < g.at - g.w / 2);
87
+ if (next) e = next.at - next.w / 2;
88
+ else if (len - e < 0.3) e = len;
89
+ const worn = hash(Math.round(s * 10), i, seed + 1);
90
+ lay(s0, e - 0.015, y0, rise - 0.015, wallThickness + (worn - 0.5) * 0.05, 0.8 + 0.22 * worn - (i === 0 ? 0.08 : 0));
91
+ s = e;
92
+ }
93
+ }
94
+ for (const g of gaps) {
95
+ for (const sg of [-1, 1]) {
96
+ lay(g.at + sg * (g.w / 2 + 0.11) - 0.11, g.at + sg * (g.w / 2 + 0.11) + 0.11, y, g.h, wallThickness + 0.1, 1.04);
97
+ }
98
+ lay(g.at - g.w / 2 - 0.4, g.at + g.w / 2 + 0.4, y + g.h, 0.4, wallThickness + 0.12, 1.08);
99
+ }
100
+ // Walk colliders cover the wall segments less its doorways.
101
+ if (K.solid) {
102
+ const ox = K.O?.x ?? 0,
103
+ oz = K.O?.z ?? 0,
104
+ edges = [0, ...gaps.flatMap(g => [g.at - g.w / 2, g.at + g.w / 2]).sort((p, q) => p - q), len];
105
+ for (let i = 0; i < edges.length; i += 2) {
106
+ const m = (edges[i] + edges[i + 1]) / 2;
107
+ if (edges[i + 1] - edges[i] > 0.05) {
108
+ K.solid.push({ x: ox + a[0] + ux * m, z: oz + a[1] + uz * m, hx: (edges[i + 1] - edges[i]) / 2, hz: wallThickness / 2, rot: ry });
109
+ }
110
+ }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Lay a floor of square stone flags over `(x0, z0)..(x1, z1)` with their top surfaces at `y`.
116
+ * An optional `skip(x, z)` callback omits individual flags for drains, pits or stair wells.
117
+ */
118
+ function flags(K, x0, x1, z0, z1, y, size = 1, stoneTone = defaultTone, skip = null) {
119
+ const nx = Math.round((x1 - x0) / size),
120
+ nz = Math.round((z1 - z0) / size),
121
+ sx = (x1 - x0) / nx,
122
+ sz = (z1 - z0) / nz;
123
+ for (let i = 0; i < nx; i++) {
124
+ for (let j = 0; j < nz; j++) {
125
+ const x = x0 + (i + 0.5) * sx,
126
+ z = z0 + (j + 0.5) * sz,
127
+ k = hash(i + Math.round(x0), j + Math.round(z0), 771);
128
+ if (skip && skip(x, z)) continue;
129
+ K.B.stone.box(x, y - 0.3, z, sx - 0.02, 0.3 - (k < 0.12 ? 0.02 : 0), sz - 0.02, dim(color(stoneTone), 0.66 + 0.2 * k));
130
+ }
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Build a flat stone ceiling at elevation `y` over `(x0, z0)..(x1, z1)`: cross-beams spanning the
136
+ * narrower dimension carrying roof slabs laid above them.
137
+ */
138
+ function slabCeiling(K, x0, x1, z0, z1, y, stoneTone = defaultTone) {
139
+ const alongX = x1 - x0 > z1 - z0,
140
+ run = alongX ? x1 - x0 : z1 - z0,
141
+ n = Math.max(1, Math.round(run / 2.2));
142
+ for (let i = 0; i <= n; i++) {
143
+ const s = (i / n) * run;
144
+ if (alongX) K.B.stone.box(x0 + s, y - 0.34, (z0 + z1) / 2, 0.42, 0.34, z1 - z0 + 0.5, dim(color(stoneTone), 0.6));
145
+ else K.B.stone.box((x0 + x1) / 2, y - 0.34, z0 + s, x1 - x0 + 0.5, 0.34, 0.42, dim(color(stoneTone), 0.6));
146
+ }
147
+ for (let i = 0; i < n; i++) {
148
+ const s = ((i + 0.5) / n) * run,
149
+ k = 0.5 + 0.12 * hash(i, Math.round(x0 + z0), 772);
150
+ if (alongX) K.B.stone.box(x0 + s, y, (z0 + z1) / 2, run / n - 0.02, 0.4, z1 - z0 + 0.6, dim(color(stoneTone), k));
151
+ else K.B.stone.box((x0 + x1) / 2, y, z0 + s, x1 - x0 + 0.6, 0.4, run / n - 0.02, dim(color(stoneTone), k));
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Build a stone barrel vault running along `x` from `x0` to `x1` over the span `z0..z1`, springing
157
+ * at elevation `y` and rising by `rise` metres, with transverse ribs proud of the voussoirs.
158
+ */
159
+ function barrelVault(K, x0, x1, z0, z1, y, rise, stoneTone = defaultTone) {
160
+ const half = (z1 - z0) / 2,
161
+ zc = (z0 + z1) / 2,
162
+ N = 14,
163
+ point = f => [zc + half * Math.cos(f), y + rise * Math.sin(f)],
164
+ ribs = Math.round((x1 - x0) / 4.5),
165
+ span = (xa, xb, proud, k0) => {
166
+ for (let j = 0; j < N; j++) {
167
+ const [za, ya] = point((j / N) * Math.PI),
168
+ [zb, yb] = point(((j + 1) / N) * Math.PI),
169
+ lenZ = Math.hypot(zb - za, yb - ya),
170
+ fm = ((j + 0.5) / N) * Math.PI,
171
+ nz = Math.cos(fm) / half,
172
+ ny = Math.sin(fm) / rise,
173
+ n = Math.hypot(nz, ny),
174
+ tilt = Math.atan2(nz / n, ny / n);
175
+ K.B.stone.add(
176
+ shapes.box,
177
+ dim(color(stoneTone), k0 + 0.1 * hash(j, Math.round(xa * 3), 773)),
178
+ transform(
179
+ (xa + xb) / 2,
180
+ (ya + yb) / 2 - (proud * ny) / n,
181
+ (za + zb) / 2 - (proud * nz) / n,
182
+ xb - xa - 0.02,
183
+ 0.5,
184
+ lenZ + 0.06,
185
+ 0,
186
+ tilt,
187
+ ),
188
+ );
189
+ }
190
+ };
191
+ for (let i = 0; i < ribs; i++) span(x0 + (i / ribs) * (x1 - x0), x0 + ((i + 1) / ribs) * (x1 - x0), 0, 0.5);
192
+ for (let i = 0; i <= ribs; i++) {
193
+ const x = Math.min(x1 - 0.25, Math.max(x0 + 0.25, x0 + (i / ribs) * (x1 - x0)));
194
+ span(x - 0.25, x + 0.25, 0.22, 0.7);
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Build the eight coursed walls of an octagonal chamber centred at `c` (`{ x, z }`) with apothem
200
+ * `r` metres to the inner face. `doors` maps side index (`0` east, `2` south, `4` west, `6` north)
201
+ * to `{ w, h }`.
202
+ */
203
+ function octagonWalls(K, c, r, y, h, doors = {}, stoneTone = defaultOldTone) {
204
+ const mid = r + wallThickness / 2,
205
+ half = (r + wallThickness) * Math.tan(Math.PI / 8);
206
+ for (let k = 0; k < 8; k++) {
207
+ const t = (k * Math.PI) / 4,
208
+ cx = c.x + Math.cos(t) * mid,
209
+ cz = c.z + Math.sin(t) * mid,
210
+ dx = -Math.sin(t),
211
+ dz = Math.cos(t),
212
+ gap = doors[k];
213
+ wall(K, [cx - dx * half, cz - dz * half], [cx + dx * half, cz + dz * half], y, h, gap ? [{ at: half, ...gap }] : [], stoneTone, 0.6);
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Build a seven-ring stepped corbelled stone roof over an octagonal chamber centred at `c` with
219
+ * apothem `r` metres, springing at elevation `y` and closed by a top capstone.
220
+ */
221
+ function corbelRoof(K, c, r, y, stoneTone = defaultOldTone) {
222
+ const rings = 7;
223
+ for (let i = 0; i < rings; i++) {
224
+ const ri = r + 0.5 - i * (r / rings),
225
+ half = (ri + 0.6) * Math.tan(Math.PI / 8);
226
+ for (let k = 0; k < 8; k++) {
227
+ const t = (k * Math.PI) / 4;
228
+ K.B.stone.box(
229
+ c.x + Math.cos(t) * ri,
230
+ y + i * 0.46,
231
+ c.z + Math.sin(t) * ri,
232
+ 1.9,
233
+ 0.5,
234
+ 2 * half,
235
+ dim(color(stoneTone), 0.62 - i * 0.03 + 0.08 * hash(i, k, 774)),
236
+ -t,
237
+ );
238
+ }
239
+ }
240
+ K.B.stone.box(c.x, y + rings * 0.46, c.z, 2.6, 0.4, 2.6, dim(color(stoneTone), 0.4), Math.PI / 8);
241
+ }
242
+
243
+ return { wall, flags, slabCeiling, barrelVault, octagonWalls, corbelRoof };
244
+ }
@@ -8,6 +8,7 @@
8
8
  import { dim } from '../math/color.js';
9
9
  import { createNoise } from '../math/noise.js';
10
10
  import { TAU, lerp, sstep } from '../math/scalar.js';
11
+ import { craterDip as defaultCraterDip } from './crater-profile.js';
11
12
  import { C as defaultColor, TRS as defaultTransform, createUnitShapes } from './primitives.js';
12
13
  import { sampleSurface } from './sampled-surface.js';
13
14
 
@@ -33,11 +34,7 @@ export const CRATER_PALETTE = Object.freeze({
33
34
 
34
35
  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
 
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
- }
37
+ export { defaultCraterDip as craterDip };
41
38
 
42
39
  /**
43
40
  * Build a high-resolution impact crater bowl and thrown-subsoil lip blended cleanly into surrounding
@@ -4,11 +4,15 @@
4
4
  * @module
5
5
  */
6
6
 
7
+ import * as THREE from 'three';
8
+ import { createHash } from '../math/random.js';
7
9
  import { TAU } from '../math/scalar.js';
8
10
  import { C as defaultColor, TRS as defaultTransform, createUnitShapes } from './primitives.js';
9
11
 
10
12
  let fallbackRock = null;
11
13
  const defaultRock = () => (fallbackRock ??= createUnitShapes().rock);
14
+ let fallbackHash = null;
15
+ const defaultHash = () => (fallbackHash ??= createHash(42));
12
16
 
13
17
  /**
14
18
  * Default tone and weathering settings for heaped fallen masonry built by {@link buildRubbleHeap}.
@@ -38,6 +42,30 @@ export const RUBBLE_SCATTER = Object.freeze({
38
42
  dressed: 0.45,
39
43
  });
40
44
 
45
+ /**
46
+ * Build a cheap, angular faceted rubble-stone `BufferGeometry` by displacing an icosahedron's
47
+ * vertices with a seeded 2D hash and slightly lifting its base so scattered fragments seat cleanly
48
+ * on heaps and broken masonry.
49
+ *
50
+ * @param {object} [options]
51
+ * @param {(x: number, z: number, salt?: number) => number} [options.hash] - Seeded 2D hash in `[0, 1)`.
52
+ * @param {number} [options.radius=0.5] - Base icosahedron radius in metres.
53
+ * @param {number} [options.salt=23] - Hash salt.
54
+ * @returns {THREE.BufferGeometry}
55
+ */
56
+ export function createRubbleStone({ hash = defaultHash(), radius = 0.5, salt = 23 } = {}) {
57
+ const g = new THREE.IcosahedronGeometry(radius, 0);
58
+ const a = g.attributes.position.array;
59
+ for (let i = 0; i < a.length; i += 3) {
60
+ const k = 0.7 + 0.6 * hash(Math.round(a[i] * 9), Math.round(a[i + 2] * 9 + a[i + 1] * 5), salt);
61
+ a[i] *= k;
62
+ a[i + 1] = a[i + 1] * k * 0.8 + 0.3;
63
+ a[i + 2] *= k;
64
+ }
65
+ g.computeVertexNormals();
66
+ return g;
67
+ }
68
+
41
69
  function weatheredTone(hue, random, course, cfg, color) {
42
70
  const col = color(hue, cfg.jitter, random);
43
71
  const k = (course < cfg.dampCourses ? 0.8 + 0.08 * course : 1) * (random() < cfg.stained ? 0.78 : 1);
@@ -101,3 +101,106 @@ export function planScatterInstances({
101
101
  total,
102
102
  };
103
103
  }
104
+
105
+ /**
106
+ * Default grid tiling, LOD transition, scale, lean, tint and trunk collider settings for
107
+ * {@link planTreeGrove} and `scatterTreeGrove`.
108
+ */
109
+ export const TREE_GROVE = Object.freeze({
110
+ /** Grid square edge length in metres used to batch neighbouring trees into one LOD stand. */
111
+ squareSize: 80,
112
+ /** Distance in metres at which each tiled stand switches from near to far geometry. */
113
+ nearDistance: 340,
114
+ /** Vertical sink below the sampled ground surface in metres. */
115
+ sink: 0.15,
116
+ /** Uniform tree scale `[minScale, scaleSpan]`. */
117
+ scaleRange: Object.freeze([0.8, 0.55]),
118
+ /** Maximum trunk pitch lean span in radians (`[-leanSpan/2, +leanSpan/2]`). */
119
+ leanSpan: 0.06,
120
+ /** Greyscale tint multiplier `[minShade, shadeSpan]`. */
121
+ shadeRange: Object.freeze([0.82, 0.3]),
122
+ /** Trunk circle-collider radius per unit scale in metres. */
123
+ colliderRadius: 0.6,
124
+ /** Default number of tree variants built when no prebuilt models are supplied. */
125
+ variants: 3,
126
+ });
127
+
128
+ /**
129
+ * Plan a wood or grove of trees over a rectangle `[x - rx, x + rx] × [z - rz, z + rz]` in a local
130
+ * frame anchored at `origin`, skipping points where `clear(px, pz)` is truthy, binning accepted
131
+ * trees into `squareSize`-metre tiles and recording circle trunk colliders. Worker-safe.
132
+ *
133
+ * @param {object} [options]
134
+ * @param {{ x: number, z: number }} [options.origin={ x: 0, z: 0 }] - Local frame world origin in metres.
135
+ * @param {(x: number, z: number) => number} [options.ground] - Local ground elevation sampler `(px, pz) => y` in metres.
136
+ * @param {() => number} [options.random] - Deterministic PRNG in `[0, 1)`.
137
+ * @param {number} [options.x=0] - Grove centre local X in metres.
138
+ * @param {number} [options.z=0] - Grove centre local Z in metres.
139
+ * @param {number} [options.rx=40] - Grove half-width along X in metres.
140
+ * @param {number} [options.rz=40] - Grove half-depth along Z in metres.
141
+ * @param {number} [options.count=40] - Candidate tree positions to sample.
142
+ * @param {(px: number, pz: number) => boolean} [options.clear] - Exclusion predicate in local coordinates.
143
+ * @param {number} [options.squareSize=TREE_GROVE.squareSize] - Tile square edge length in metres.
144
+ * @param {number} [options.sink=TREE_GROVE.sink] - Vertical sink below `ground(px, pz)` in metres.
145
+ * @param {readonly [number, number]} [options.scaleRange=TREE_GROVE.scaleRange] - Scale `[min, span]`.
146
+ * @param {number} [options.leanSpan=TREE_GROVE.leanSpan] - Trunk lean span in radians.
147
+ * @param {readonly [number, number]} [options.shadeRange=TREE_GROVE.shadeRange] - Greyscale shade `[min, span]`.
148
+ * @param {number} [options.colliderRadius=TREE_GROVE.colliderRadius] - Trunk collider radius per unit scale in metres.
149
+ * @returns {{
150
+ * squares: Array<{ key: number, mid: [number, number, number], trees: Array<[number, number, number, number, number, number, number]> }>,
151
+ * solids: Array<{ x: number, z: number, r: number }>,
152
+ * total: number,
153
+ * }}
154
+ */
155
+ export function planTreeGrove({
156
+ origin = { x: 0, z: 0 },
157
+ ground = () => 0,
158
+ random = mulberry32(1),
159
+ x = 0,
160
+ z = 0,
161
+ rx = 40,
162
+ rz = 40,
163
+ count = 40,
164
+ clear = () => false,
165
+ squareSize = TREE_GROVE.squareSize,
166
+ sink = TREE_GROVE.sink,
167
+ scaleRange = TREE_GROVE.scaleRange,
168
+ leanSpan = TREE_GROVE.leanSpan,
169
+ shadeRange = TREE_GROVE.shadeRange,
170
+ colliderRadius = TREE_GROVE.colliderRadius,
171
+ } = {}) {
172
+ const buckets = new Map();
173
+ const solids = [];
174
+ let total = 0;
175
+ for (let i = 0; i < count; i++) {
176
+ const px = x + (random() * 2 - 1) * rx;
177
+ const pz = z + (random() * 2 - 1) * rz;
178
+ if (clear(px, pz)) continue;
179
+ const size = scaleRange[0] + random() * scaleRange[1];
180
+ const key = Math.floor(px / squareSize) * 1e4 + Math.floor(pz / squareSize);
181
+ let trees = buckets.get(key);
182
+ if (!trees) {
183
+ trees = [];
184
+ buckets.set(key, trees);
185
+ }
186
+ const wx = origin.x + px;
187
+ const wz = origin.z + pz;
188
+ trees.push([
189
+ wx,
190
+ ground(px, pz) - sink,
191
+ wz,
192
+ size,
193
+ random() * TAU,
194
+ (random() - 0.5) * leanSpan,
195
+ shadeRange[0] + random() * shadeRange[1],
196
+ ]);
197
+ solids.push({ x: wx, z: wz, r: colliderRadius * size });
198
+ total++;
199
+ }
200
+ const squares = [];
201
+ for (const [key, trees] of buckets) {
202
+ const mid = trees.reduce((m, t) => [m[0] + t[0] / trees.length, m[1] + t[1] / trees.length, m[2] + t[2] / trees.length], [0, 0, 0]);
203
+ squares.push({ key, mid, trees });
204
+ }
205
+ return { squares, solids, total };
206
+ }
package/index.js CHANGED
@@ -70,7 +70,7 @@ export { MESA_CLIFF, buildMesaCliff } from './geometry/strata-mesa.js';
70
70
  export { HILL_RUIN, buildHillRuin } from './geometry/ruins-hill.js';
71
71
  export { MOUND_RUINS, buildMoundRuins, buildMoundSherds, buildMoundWalls, createMoundRuins } from './geometry/ruins-mound.js';
72
72
  export { MOUND_RUINS_LOD, raiseMoundRuins, registerMoundRuins } from './rendering/ruins-mound.js';
73
- export { RUBBLE_HEAP, RUBBLE_SCATTER, buildRubbleHeap, scatterRubble } from './geometry/ruins-rubble.js';
73
+ export { RUBBLE_HEAP, RUBBLE_SCATTER, buildRubbleHeap, createRubbleStone, scatterRubble } from './geometry/ruins-rubble.js';
74
74
  export { RUIN_WALL, buildRuinWall, coursedWall, tumbleBlock } from './geometry/ruins-walls.js';
75
75
  export {
76
76
  ASHLAR_COURSE,
@@ -91,7 +91,16 @@ export {
91
91
  createLightPoolTexture,
92
92
  } from './rendering/ruins-fittings.js';
93
93
  export { DEFAULT_SCORCH_PALETTE, addEmberSkin, buildBreachFan, buildRubbleMound } from './geometry/ruins-breach.js';
94
- export { CRATER_PALETTE, buildCraterBowl, buildFallenBoulder } from './geometry/ruins-crater.js';
94
+ export { CRATER_PALETTE, buildCraterBowl, buildFallenBoulder, craterDip } from './geometry/ruins-crater.js';
95
+ export {
96
+ GROUND_PATCH_DEFAULTS,
97
+ GROUND_PATCH_KINDS,
98
+ buildDrapePebbleGeometry,
99
+ createGroundPatchData,
100
+ drapeGroundPatch,
101
+ scatterPatchBits,
102
+ } from './geometry/ground-drape.js';
103
+ export { GROUND_DRAPE_FRAGMENT, createGroundDrape, createGroundDrapeMaterial } from './rendering/ground-drape.js';
95
104
  export { createShapeBatches } from './geometry/instances.js';
96
105
  export { planStreamBanks } from './geometry/stream-banks.js';
97
106
  export { meshStreamBanks } from './rendering/stream-banks.js';
@@ -118,7 +127,15 @@ export { PAVED_GROUND_LIMITS, createPavedGroundMaterial } from './rendering/pave
118
127
  export { createRoadTraffic, ROAD_TRAFFIC } from './motion/road-traffic.js';
119
128
  export { createFieldSurvey, FIELD_SURVEY, FIELD_USE } from './geometry/field-survey.js';
120
129
  export { FIELD_BITS, NO_PATH_DISTANCE, createFieldCoverCache, packFieldBits, packSparsePlain } from './geometry/field-map.js';
121
- export { DEFAULT_FLOWER_LOOKS, FLOWER_KINDS, TUFT_SHAPE, tuftGeometry } from './geometry/plant-tuft.js';
130
+ export {
131
+ DEFAULT_DRIFT_SCALE,
132
+ DEFAULT_FLOWER_DRIFTS,
133
+ DEFAULT_FLOWER_LOOKS,
134
+ FLOWER_KINDS,
135
+ TUFT_SHAPE,
136
+ createFlowerDrift,
137
+ tuftGeometry,
138
+ } from './geometry/plant-tuft.js';
122
139
  export { TUFT_SHADER, createGrassTuft, createTuftMaterial } from './rendering/plant-tuft.js';
123
140
  export { LAND_TRAILS, LAND_TRAIL_MARKS, boundsOverlap, createLandTrails, rasterizeTrailMarks } from './geometry/land-trails.js';
124
141
  export { createTrailMarks, trailMarksGLSL } from './rendering/land-trail-surface.js';
@@ -127,8 +144,8 @@ export { DEFAULT_CROP_STANDS, FARM_CROPS, createCropPlacer } from './geometry/fa
127
144
  export { createIrrigatedFieldSurface, IRRIGATED_FIELD_KIND, IRRIGATED_FIELD_SURFACE } from './rendering/irrigated-field-surface.js';
128
145
  export { DRYSTONE_WALL, FIELD_STONE, drystoneStone, planDrystoneWall } from './geometry/drystone-wall.js';
129
146
  export { DEFAULT_FENCE_STYLE, addFenceRing, buildFenceRing } from './geometry/timber-fence.js';
130
- export { planScatterInstances } from './geometry/scatter-instances.js';
131
- export { scatterInstances, scatterTrees, scatterTussocks } from './rendering/scatter-instances.js';
147
+ export { TREE_GROVE, planScatterInstances, planTreeGrove } from './geometry/scatter-instances.js';
148
+ export { scatterInstances, scatterTreeGrove, scatterTrees, scatterTussocks } from './rendering/scatter-instances.js';
132
149
  export { FARM_BOUNDARIES, planFieldBoundaries } from './geometry/farm-boundaries.js';
133
150
  export { meshFarmCells, scatterFarmLots } from './rendering/farm-cells.js';
134
151
  export { DEFAULT_LIVESTOCK_CASTS, createLivestockCache } from './rendering/farm-livestock.js';
@@ -200,6 +217,7 @@ export { TERRACE_DEFAULTS, createTerraceFrame, planTerrace, wallAt } from './geo
200
217
  export { createTerraceWall } from './geometry/fort-terrace-wall.js';
201
218
  export { createTerraceGates } from './geometry/fort-terrace-gates.js';
202
219
  export { createRoomKit } from './geometry/room-kit.js';
220
+ export { HALL_OLD_STONE_TONE, HALL_STONE_TONE, HALL_WALL_THICKNESS, createStoneHalls } from './geometry/room-halls.js';
203
221
  export { createRoomMaterials } from './rendering/room-materials.js';
204
222
  export { finishRoom } from './rendering/room-space.js';
205
223
 
@@ -301,6 +319,7 @@ export { createSoundscape } from './runtime/soundscape.js';
301
319
  export { createStrideFoley } from './runtime/foley-strides.js';
302
320
  export { createScriptFoley } from './runtime/foley-script.js';
303
321
  export { createPool } from './runtime/pool.js';
322
+ export { createBreather, createLazySets, createSetFrame } from './runtime/lazy-sets.js';
304
323
  export { describeDevice, readDevice } from './runtime/device.js';
305
324
  export { choosePostPipeline, createDeviceQuality, groundRenderOrder, resolveDevicePresets } from './runtime/device-quality.js';
306
325
  export { LEVELS, createQualityStore } from './runtime/quality-store.js';
@@ -362,6 +381,7 @@ export { DEFAULT_POSE_SHOTS, actorHeadTop, createSceneCoverage } from './renderi
362
381
  export { createSceneShots, gallopTremorLevel, protectMasterHeadroom, trackOrigin } from './rendering/scene-shots.js';
363
382
  export { createPropContact } from './motion/prop-contact.js';
364
383
  export { createSceneProps } from './rendering/scene-props.js';
384
+ export { createSceneFlash } from './rendering/scene-flash.js';
365
385
  export { createSceneMarkers, createShaftLabel, DEFAULT_MARKER_COLORS, projectWaypoint } from './rendering/scene-markers.js';
366
386
 
367
387
  // ── Map kit ──────────────────────────────────────────────────────────────
@@ -412,6 +432,30 @@ export { createWorldControls } from './runtime/world-controls.js';
412
432
  export { COMPASS_POINTS, compassStripHtml, createCompassStrip } from './runtime/compass-strip.js';
413
433
  export { createWayBack } from './runtime/way-back.js';
414
434
  export { createHudFrame, formatDayClock } from './runtime/hud-frame.js';
435
+ export { createHudRoom } from './runtime/hud-room.js';
436
+ export {
437
+ ARTICLE_LINK,
438
+ collectArticleLinks,
439
+ createArticleCatalog,
440
+ formatArticleText,
441
+ parseArticle,
442
+ plainArticleParagraph,
443
+ } from './runtime/articles.js';
444
+ export { createArticlePageRenderer, escapeHtml, renderArticleParagraph } from './runtime/article-page.js';
445
+ export { createJourneyStore } from './runtime/journey.js';
446
+ export { createSitePages, slugify } from './runtime/site-pages.js';
447
+ export {
448
+ DEFAULT_BACKDROP_RANGES,
449
+ DEFAULT_BACKDROP_SKY,
450
+ DEFAULT_BACKDROP_VEIL,
451
+ applyBackdropFinish,
452
+ createCanvasSprite,
453
+ createTitleBackdrop,
454
+ paintCumulusSprite,
455
+ paintMountainRange,
456
+ paintSkyGradient,
457
+ ridgeNoise,
458
+ } from './rendering/title-backdrop.js';
415
459
  export {
416
460
  COMPASS_CARDINALS,
417
461
  DEFAULT_PLACE_KINDS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roamwright",
3
- "version": "0.61.24",
3
+ "version": "0.61.26",
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",