roamwright 0.61.17 → 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.
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Coursed ruined stone walls laid in running bond with weathered open joints, stepped broken tops,
3
+ * tumbled fallen blocks at the foot, and optional surrounding rubble heaps and box colliders.
4
+ * Pure geometry assembly into a `GB` builder; worker-safe.
5
+ * @module
6
+ */
7
+
8
+ import { createNoise } from '../math/noise.js';
9
+ import { clamp } from '../math/scalar.js';
10
+ import { C as defaultColor, TRS as defaultTransform, createUnitShapes } from './primitives.js';
11
+ import { buildRubbleHeap } from './ruins-rubble.js';
12
+
13
+ let fallbackRock = null;
14
+ const defaultRock = () => (fallbackRock ??= createUnitShapes().rock);
15
+ let fallbackFbm = null;
16
+ const defaultFbm = () => (fallbackFbm ??= createNoise().fbm);
17
+
18
+ /**
19
+ * Default masonry course height, block lengths, weathering and wear parameters (metres) for
20
+ * {@link coursedWall}, {@link tumbleBlock} and {@link buildRuinWall}.
21
+ */
22
+ export const RUIN_WALL = Object.freeze({
23
+ /** Height of one masonry course in metres. */
24
+ course: 0.42,
25
+ /** Shortest and longest stone block lengths in metres. */
26
+ block: Object.freeze([0.7, 1.35]),
27
+ /** Open weathered joint width in metres. */
28
+ joint: 0.03,
29
+ /** Footing depth sunk below ground in metres. */
30
+ footing: 0.3,
31
+ /** Number of lowest courses darkened by rising damp. */
32
+ dampCourses: 2,
33
+ /** Share of blocks darkened by lichen and run-off staining. */
34
+ stained: 0.12,
35
+ /** Spatial frequency per metre of the ruined crest wear profile. */
36
+ wearGrain: 0.2,
37
+ /** End-zone length in metres where wall corners stand higher. */
38
+ corner: 4,
39
+ /** Default stone colour in sRGB hex. */
40
+ hue: 0xb39c76,
41
+ /** Default share of fallen courses and strewn foot rubble. */
42
+ fallen: 0.6,
43
+ /** Default share of crest blocks shifted loose. */
44
+ loose: 0.35,
45
+ });
46
+
47
+ function blockColour(hue, rng, course, top, cfg, color) {
48
+ const col = color(hue, 0.1, rng);
49
+ const k = (course < cfg.dampCourses ? 0.8 + 0.08 * course : 1) * (top ? 1.07 : 1) * (rng() < cfg.stained ? 0.78 : 1);
50
+ return [col[0] * k, col[1] * k, col[2] * k];
51
+ }
52
+
53
+ /**
54
+ * Emit one (or occasionally two broken halves of a) masonry block tumbled off course `course` onto
55
+ * the ground beside a wall.
56
+ *
57
+ * @param {Pick<import('./builder.js').GB, 'box'>} builder - Destination stone geometry builder.
58
+ * @param {() => number} [random=Math.random] - Repeatable PRNG in `[0, 1)`.
59
+ * @param {object} options
60
+ * @param {number} options.x - Wall-axis position X in local metres.
61
+ * @param {number} options.z - Wall-axis position Z in local metres.
62
+ * @param {[number, number]} options.across - Unit vector perpendicular to the wall `[ax, az]`.
63
+ * @param {number} options.length - Fallen block length along the wall in metres.
64
+ * @param {number} options.thickness - Wall thickness in metres.
65
+ * @param {number} options.course - Zero-based course index from which the block fell.
66
+ * @param {number} [options.hue=RUIN_WALL.hue] - Stone sRGB hex colour.
67
+ * @param {number} [options.turn=0] - Wall yaw bearing in radians.
68
+ * @param {(x: number, z: number) => number} [options.ground] - Surface height sampler `(x, z) => y`.
69
+ * @param {Function} [options.color] - Linear RGB colour helper.
70
+ * @param {Partial<typeof RUIN_WALL>} [options.shape] - Overrides to {@link RUIN_WALL}.
71
+ */
72
+ export function tumbleBlock(builder, random = Math.random, options) {
73
+ const { x, z, across, length, thickness, course, hue = RUIN_WALL.hue, turn = 0, ground = () => 0, color = defaultColor } = options;
74
+ const cfg = options.shape ? { ...RUIN_WALL, ...options.shape } : RUIN_WALL;
75
+ const pieces = random() < 0.3 ? 2 : 1;
76
+ for (let i = 0; i < pieces; i++) {
77
+ const side = random() < 0.5 ? -1 : 1;
78
+ const out = thickness * 0.6 + 0.3 + random() * (0.4 + course * cfg.course * 0.6);
79
+ const px = x + across[0] * side * out + (random() - 0.5) * 0.8;
80
+ const pz = z + across[1] * side * out + (random() - 0.5) * 0.8;
81
+ const size = length / pieces;
82
+ builder.box(
83
+ px,
84
+ ground(px, pz) - 0.12,
85
+ pz,
86
+ thickness * (0.9 + random() * 0.15),
87
+ cfg.course * 0.95,
88
+ size * (0.85 + random() * 0.15),
89
+ blockColour(hue, random, 1 + (random() < 0.5), false, cfg, color),
90
+ turn + (random() - 0.5) * 1.4,
91
+ (random() - 0.5) * 0.5,
92
+ (random() - 0.5) * 0.4,
93
+ );
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Build a running-bond coursed stone wall from `(ax, az)` to `(bx, bz)` following `ground(x, z)`,
99
+ * stepping its courses to `heightAt(u)` (`u` in `[0, 1]`), shifting loose crest blocks and tumbling
100
+ * missing upper blocks beside the wall.
101
+ *
102
+ * @param {Pick<import('./builder.js').GB, 'box'>} builder - Destination stone geometry builder.
103
+ * @param {() => number} [random=Math.random] - Repeatable PRNG in `[0, 1)`.
104
+ * @param {object} options
105
+ * @param {number} options.ax - Start X in local metres.
106
+ * @param {number} options.az - Start Z in local metres.
107
+ * @param {number} options.bx - End X in local metres.
108
+ * @param {number} options.bz - End Z in local metres.
109
+ * @param {number} [options.thickness=0.6] - Wall thickness in metres.
110
+ * @param {(u: number) => number} [options.heightAt] - Standing height above ground at normalized position `u`.
111
+ * @param {number} [options.hue=RUIN_WALL.hue] - Stone sRGB hex colour.
112
+ * @param {number} [options.fallen=0.36] - Probability a missing upper block lies tumbled nearby.
113
+ * @param {number} [options.loose=RUIN_WALL.loose] - Probability a crest block sits shifted half off the wall.
114
+ * @param {(x: number, z: number) => number} [options.ground] - Surface height sampler `(x, z) => y`.
115
+ * @param {Function} [options.color] - Linear RGB colour helper.
116
+ * @param {Partial<typeof RUIN_WALL>} [options.shape] - Overrides to {@link RUIN_WALL}.
117
+ */
118
+ export function coursedWall(builder, random = Math.random, options) {
119
+ const {
120
+ ax,
121
+ az,
122
+ bx,
123
+ bz,
124
+ thickness = 0.6,
125
+ heightAt = () => 2,
126
+ hue = RUIN_WALL.hue,
127
+ fallen = 0.36,
128
+ loose = RUIN_WALL.loose,
129
+ ground = () => 0,
130
+ color = defaultColor,
131
+ } = options;
132
+ const cfg = options.shape ? { ...RUIN_WALL, ...options.shape } : RUIN_WALL;
133
+ const len = Math.hypot(bx - ax, bz - az);
134
+ const turn = Math.atan2(bx - ax, bz - az);
135
+ const along = [(bx - ax) / len, (bz - az) / len];
136
+ const across = [along[1], -along[0]];
137
+ const courses = Math.ceil((Math.max(heightAt(0), heightAt(0.5), heightAt(1)) + cfg.footing) / cfg.course) + 2;
138
+ for (let k = 0; k < courses; k++) {
139
+ let s = k % 2 ? -random() * cfg.block[0] : 0;
140
+ while (s < len) {
141
+ const e = Math.min(len, s + cfg.block[0] + random() * (cfg.block[1] - cfg.block[0]));
142
+ const from = Math.max(0, s);
143
+ s = e;
144
+ if (e - from < 0.25) continue;
145
+ const mid = (from + e) / 2;
146
+ const x = ax + along[0] * mid;
147
+ const z = az + along[1] * mid;
148
+ const stands = heightAt(mid / len) + cfg.footing + (random() - 0.5) * 0.3;
149
+ const base = ground(x, z) - cfg.footing;
150
+ if (k > 0 && (k + 1) * cfg.course > stands) {
151
+ if (random() < fallen) {
152
+ tumbleBlock(builder, random, {
153
+ x,
154
+ z,
155
+ across,
156
+ length: e - from,
157
+ thickness,
158
+ course: k,
159
+ hue,
160
+ turn,
161
+ ground,
162
+ color,
163
+ shape: cfg,
164
+ });
165
+ }
166
+ continue;
167
+ }
168
+ const top = (k + 2) * cfg.course > stands;
169
+ const shifted = top && random() < loose;
170
+ const depth = (shifted ? 0.55 : 1) * thickness * (0.94 + random() * 0.08);
171
+ const off = (shifted ? (random() < 0.5 ? -1 : 1) * thickness * 0.22 : 0) + (random() - 0.5) * 0.04;
172
+ builder.box(
173
+ x + across[0] * off,
174
+ base + k * cfg.course,
175
+ z + across[1] * off,
176
+ depth,
177
+ cfg.course - cfg.joint * (0.6 + random() * 0.8),
178
+ e - from - cfg.joint,
179
+ blockColour(hue, random, k, top, cfg, color),
180
+ turn + (random() - 0.5) * (shifted ? 0.2 : 0.025),
181
+ );
182
+ }
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Build a breached, unevenly weathered coursed stone ruin wall from `(ax, az)` to `(bx, bz)`,
188
+ * tallest near its corners, strewn with foot rubble via {@link buildRubbleHeap}, and optionally
189
+ * appending standing-stretch box colliders into `solid`.
190
+ *
191
+ * @param {Pick<import('./builder.js').GB, 'box' | 'add'>} builder - Destination stone geometry builder.
192
+ * @param {() => number} [random=Math.random] - Repeatable PRNG in `[0, 1)`.
193
+ * @param {object} options
194
+ * @param {number} options.ax - Start X in local metres.
195
+ * @param {number} options.az - Start Z in local metres.
196
+ * @param {number} options.bx - End X in local metres.
197
+ * @param {number} options.bz - End Z in local metres.
198
+ * @param {number} [options.tall=2.5] - Peak wall height in metres.
199
+ * @param {(x: number, z: number) => number} [options.ground] - Surface height sampler `(x, z) => y`.
200
+ * @param {number} [options.originX=0] - World X offset added when pushing `solid` box colliders.
201
+ * @param {number} [options.originZ=0] - World Z offset added when pushing `solid` box colliders.
202
+ * @param {Array<object> | null} [options.solid=null] - Optional array receiving `{ x, z, hx, hz, rot }` colliders.
203
+ * @param {number} [options.hue=RUIN_WALL.hue] - Stone sRGB hex colour.
204
+ * @param {number} [options.fallen=RUIN_WALL.fallen] - Fallen-block and foot-rubble density share.
205
+ * @param {(x: number, z: number, octaves: number, salt: number) => number} [options.fbm] - Fractal noise for crest wear.
206
+ * @param {import('three').BufferGeometry} [options.rock] - Unit broken stone geometry for foot rubble.
207
+ * @param {Function} [options.color] - Linear RGB colour helper.
208
+ * @param {Function} [options.transform] - Transform matrix helper (`TRS`).
209
+ * @param {Partial<typeof RUIN_WALL>} [options.shape] - Overrides to {@link RUIN_WALL}.
210
+ */
211
+ export function buildRuinWall(builder, random = Math.random, options) {
212
+ const {
213
+ ax,
214
+ az,
215
+ bx,
216
+ bz,
217
+ tall = 2.5,
218
+ ground = () => 0,
219
+ originX = 0,
220
+ originZ = 0,
221
+ solid = null,
222
+ hue = RUIN_WALL.hue,
223
+ fallen = RUIN_WALL.fallen,
224
+ fbm = defaultFbm(),
225
+ rock = defaultRock(),
226
+ color = defaultColor,
227
+ transform = defaultTransform,
228
+ } = options;
229
+ const cfg = options.shape ? { ...RUIN_WALL, ...options.shape } : RUIN_WALL;
230
+ const len = Math.hypot(bx - ax, bz - az);
231
+ const turn = Math.atan2(bx - ax, bz - az);
232
+ const thick = 0.55 + random() * 0.2;
233
+ const seed = Math.floor(random() * 1e4);
234
+ const heightAt = u => {
235
+ const end = Math.max(0, 1 - (Math.min(u, 1 - u) * len) / cfg.corner);
236
+ const wear = fbm(u * len * cfg.wearGrain, seed * 0.37, 3, seed);
237
+ return tall * clamp(1.5 * (wear - 0.28) + 0.55 * end, 0.04, 1);
238
+ };
239
+ coursedWall(builder, random, {
240
+ ax,
241
+ az,
242
+ bx,
243
+ bz,
244
+ thickness: thick,
245
+ heightAt,
246
+ hue,
247
+ fallen: fallen * 0.6,
248
+ ground,
249
+ color,
250
+ shape: cfg,
251
+ });
252
+ const n = Math.max(2, Math.round(len / 1.5));
253
+ for (let i = 0; i < n; i++) {
254
+ const u = (i + 0.5) / n;
255
+ const x = ax + (bx - ax) * u;
256
+ const z = az + (bz - az) * u;
257
+ if (heightAt(u) > 0.9 && solid) solid.push({ x: originX + x, z: originZ + z, hx: thick / 2, hz: len / n / 2, rot: turn });
258
+ if (random() < fallen * 0.6) {
259
+ buildRubbleHeap(builder, random, {
260
+ x: x + (random() - 0.5) * 2.4,
261
+ z: z + (random() - 0.5) * 2.4,
262
+ radius: 0.9,
263
+ count: 3,
264
+ ground,
265
+ hue,
266
+ rock,
267
+ color,
268
+ transform,
269
+ });
270
+ }
271
+ }
272
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Stepped sedimentary cliff walls wrapping flat-topped mesas: stacked rock beds broken into
3
+ * vertical buttresses and clefts along geological joints, stepping back beneath dust-covered ledges.
4
+ * Pure geometry builder, worker-safe.
5
+ * @module
6
+ */
7
+
8
+ import { createNoise } from '../math/noise.js';
9
+ import { TAU, clamp, lerp } from '../math/scalar.js';
10
+ import { GB } from './builder.js';
11
+ import { C } from './primitives.js';
12
+ import { flatQuad, jointed } from './strata-rocks.js';
13
+
14
+ let fallbackNoise = null;
15
+ const defaultNoise = () => (fallbackNoise ??= createNoise().vnoise);
16
+
17
+ /**
18
+ * Default bedding fractions, horizontal vertex spacing (metres) and weathered sandstone sRGB tones
19
+ * for mesa cliff walls built by {@link buildMesaCliff}.
20
+ */
21
+ export const MESA_CLIFF = Object.freeze({
22
+ /** Fractional wall heights where each rock bed ends, bottom to top. */
23
+ bedTops: Object.freeze([0.3, 0.41, 0.7, 0.82, 1]),
24
+ /** Target horizontal spacing between perimeter cliff vertices in metres. */
25
+ step: 2.3,
26
+ /** sRGB hex base tone for each rock bed, bottom to top. */
27
+ bedTones: Object.freeze([0x8f6548, 0xa57856, 0x86593f, 0xae825e, 0x94694a]),
28
+ /** sRGB hex dust-ledge tone between consecutive beds. */
29
+ ledgeTone: 0xa98462,
30
+ /** Radial foot fraction passed to `mesaEdge` when sampling the cliff plinth. */
31
+ cliffFoot: 1.0,
32
+ /** Radial brow fraction passed to `mesaEdge` when sampling the cap rim. */
33
+ cliffBrow: 0.72,
34
+ });
35
+
36
+ /**
37
+ * Build the stepped, jointed sedimentary cliff wall around a flat-topped mesa resting on `ground`.
38
+ *
39
+ * @param {{ x: number, z: number, r: number }} mesa - Mesa centre `(x, z)` and nominal radius `r` in metres.
40
+ * @param {(x: number, z: number) => number} [ground] - Terrain height sampler `(x, z) => y` in metres.
41
+ * @param {object} [options]
42
+ * @param {(mesa: object, angle: number, fraction: number) => number} [options.mesaEdge] - Radial outline distance at `angle` (radians) and `fraction`.
43
+ * @param {number} [options.cliffFoot=MESA_CLIFF.cliffFoot] - Foot fraction forwarded to `mesaEdge`.
44
+ * @param {number} [options.cliffBrow=MESA_CLIFF.cliffBrow] - Brow fraction forwarded to `mesaEdge`.
45
+ * @param {(x: number, z: number, salt: number) => number} [options.noise] - Value noise in `[0, 1)`.
46
+ * @param {typeof GB} [options.Builder=GB] - Geometry builder class.
47
+ * @param {Partial<typeof MESA_CLIFF>} [options.shape] - Overrides to {@link MESA_CLIFF}.
48
+ * @returns {GB} Populated geometry builder containing the cliff wall and ledges.
49
+ */
50
+ export function buildMesaCliff(mesa, ground = () => 0, options = {}) {
51
+ const cfg = options.shape ? { ...MESA_CLIFF, ...options.shape } : MESA_CLIFF;
52
+ const vnoise = options.noise ?? defaultNoise();
53
+ const Builder = options.Builder ?? GB;
54
+ const cliffFoot = options.cliffFoot ?? cfg.cliffFoot;
55
+ const cliffBrow = options.cliffBrow ?? cfg.cliffBrow;
56
+ const mesaEdge = options.mesaEdge ?? ((m, _angle, fraction) => m.r * fraction);
57
+ const bedTops = cfg.bedTops;
58
+ const bedTones = cfg.bedTones;
59
+ const beds = bedTops.length;
60
+
61
+ const builder = new Builder();
62
+ const round = Math.round(clamp((TAU * mesa.r) / cfg.step, 72, 280));
63
+ const columns = [];
64
+ for (let i = 0; i < round; i++) {
65
+ const angle = (i / round) * TAU;
66
+ const c = Math.cos(angle);
67
+ const s = Math.sin(angle);
68
+ const foot = mesaEdge(mesa, angle, cliffFoot + 0.1);
69
+ const brow = mesaEdge(mesa, angle, cliffFoot + 0.03);
70
+ const cap = mesaEdge(mesa, angle, cliffBrow - 0.05);
71
+ columns.push({
72
+ c,
73
+ s,
74
+ foot,
75
+ brow,
76
+ cap,
77
+ low: ground(mesa.x + c * (foot + 2), mesa.z + s * (foot + 2)) - 1.5,
78
+ high: ground(mesa.x + c * cap, mesa.z + s * cap) + 0.12,
79
+ });
80
+ }
81
+ const point = (i, k, top) => {
82
+ const col = columns[i % round];
83
+ const x = mesa.x + col.c * col.foot;
84
+ const z = mesa.z + col.s * col.foot;
85
+ // Buttresses share noise across beds so vertical ribs and clefts run up the whole cliff.
86
+ const buttress = 3.4 * (jointed(vnoise(x * 0.075, z * 0.075, 881), 5) - 0.25);
87
+ const broken = 1.1 * (jointed(vnoise(x * 0.17 + k * 7.1, z * 0.17, 882), 3) - 0.3);
88
+ const r = lerp(col.foot, col.brow, k / (beds - 1)) + buttress + broken - 0.3 * top;
89
+ const up = top ? bedTops[k] : k ? bedTops[k - 1] : 0;
90
+ return [mesa.x + col.c * r, lerp(col.low, col.high, up), mesa.z + col.s * r];
91
+ };
92
+ const ledge = C(cfg.ledgeTone);
93
+ for (let k = 0; k < beds; k++) {
94
+ const tone = C(bedTones[k]);
95
+ const dark = tone.map(v => v * 0.78);
96
+ const head = k < beds - 1 ? ledge : tone;
97
+ for (let i = 0; i < round; i++) {
98
+ const a = point(i, k, 0);
99
+ const b = point(i + 1, k, 0);
100
+ const c = point(i + 1, k, 1);
101
+ const d = point(i, k, 1);
102
+ const shade = 0.82 + 0.36 * vnoise(a[0] * 0.21, a[2] * 0.21 + k, 883);
103
+ const high = tone.map(v => v * shade);
104
+ const low = dark.map(v => v * shade);
105
+ flatQuad(builder, b, a, d, c, low, high);
106
+ const col = columns[i];
107
+ const next = columns[(i + 1) % round];
108
+ const e = k < beds - 1 ? point(i, k + 1, 0) : [mesa.x + col.c * col.cap, col.high, mesa.z + col.s * col.cap];
109
+ const f = k < beds - 1 ? point(i + 1, k + 1, 0) : [mesa.x + next.c * next.cap, next.high, mesa.z + next.s * next.cap];
110
+ flatQuad(builder, c, d, e, f, head, head);
111
+ }
112
+ }
113
+ return builder;
114
+ }
@@ -7,6 +7,7 @@
7
7
 
8
8
  import * as THREE from 'three';
9
9
  import { createNoise } from '../math/noise.js';
10
+ import { mulberry32 } from '../math/random.js';
10
11
  import { TAU, lerp, sstep } from '../math/scalar.js';
11
12
  import { GB } from './builder.js';
12
13
  import { lump } from './primitives.js';
@@ -70,8 +71,10 @@ const _quat = new THREE.Quaternion();
70
71
  const _euler = new THREE.Euler();
71
72
  const _scale = new THREE.Vector3();
72
73
 
73
- let fallbackNoise = null;
74
- const defaultNoise = () => (fallbackNoise ??= createNoise().vnoise);
74
+ let fallbackNoiseObj = null;
75
+ const defaultNoiseObj = () => (fallbackNoiseObj ??= createNoise());
76
+ const defaultNoise = () => defaultNoiseObj().vnoise;
77
+ const defaultFbm = () => defaultNoiseObj().fbm;
75
78
 
76
79
  /**
77
80
  * Append a flat-shaded quad `(a, b, c, d)` (anticlockwise from front) into a geometry builder,
@@ -268,3 +271,71 @@ export function createRockShapes(options = {}) {
268
271
  farOutcropShapes: () => outcropSeeds.map(seed => outcrop(seed, true)),
269
272
  };
270
273
  }
274
+
275
+ /**
276
+ * Build a roughly half-metre radius crag rock cut by two intersecting joint planes with a flat
277
+ * underside, shaded smoothly over rounded faces.
278
+ *
279
+ * @param {number} fineness - Icosahedron subdivision level (`0` stone, `1` boulder, `2` slab).
280
+ * @param {object} [options]
281
+ * @param {(x: number, z: number, octaves: number, salt: number) => number} [options.fbm] - Seeded fractal noise (`createNoise().fbm`).
282
+ * @returns {import('three').BufferGeometry}
283
+ */
284
+ export function cragRock(fineness, options = {}) {
285
+ const fbm = options.fbm ?? defaultFbm();
286
+ return lump(fineness, (dir, out) => {
287
+ const bulge = 0.74 + 0.5 * fbm(dir.x * 1.3 + 7, dir.z * 1.3 + dir.y * 1.1, 3, 733);
288
+ const joint = Math.min(
289
+ 1,
290
+ 0.86 / Math.max(Math.abs(dir.x * 0.8 + dir.z * 0.6), Math.abs(dir.z * 0.8 - dir.x * 0.6 + dir.y * 0.3), 0.01),
291
+ );
292
+ return out.set(dir.x * 0.5 * bulge * joint, Math.max(dir.y * 0.5 * bulge, -0.36), dir.z * 0.5 * bulge * joint);
293
+ });
294
+ }
295
+
296
+ /**
297
+ * Build a metre-long weathered stone with a tilted fracture plane across its top, a flat underside,
298
+ * smooth normals over rounded parts and white vertex colours ready for per-instance tinting.
299
+ *
300
+ * @param {number} detail - Icosahedron subdivision level (`0`, `1` or `2`).
301
+ * @param {number} [seed=1] - Seed for fracture plane tilt and surface noise.
302
+ * @param {object} [options]
303
+ * @param {(x: number, z: number, salt: number) => number} [options.vnoise] - Seeded value noise (`createNoise().vnoise`).
304
+ * @returns {import('three').BufferGeometry}
305
+ */
306
+ export function fallenStone(detail, seed = 1, options = {}) {
307
+ const vnoise = options.vnoise ?? options.noise ?? defaultNoise();
308
+ const rng = mulberry32(seed);
309
+ const cx = (rng() - 0.5) * 0.5;
310
+ const cz = (rng() - 0.5) * 0.5;
311
+ const g = lump(detail, (dir, out) => {
312
+ const x = dir.x * 0.5;
313
+ const y = dir.y * 0.5;
314
+ const z = dir.z * 0.5;
315
+ const r = 0.78 + 0.38 * vnoise(x * 3 + seed, z * 3 + y * 2, 611);
316
+ return out.set(x * r * 1.15, Math.max(Math.min(y * r, 0.28 + x * cx + z * cz), -0.3), z * r);
317
+ });
318
+ g.setAttribute('color', new THREE.Float32BufferAttribute(new Float32Array(g.attributes.position.count * 3).fill(1), 3));
319
+ return g;
320
+ }
321
+
322
+ /**
323
+ * Create a cached library of crag rocks and fallen stones bound to a world's noise functions.
324
+ *
325
+ * @param {object} [options]
326
+ * @param {(x: number, z: number, octaves: number, salt: number) => number} [options.fbm] - Seeded fractal noise (`createNoise().fbm`).
327
+ * @param {(x: number, z: number, salt: number) => number} [options.vnoise] - Seeded value noise (`createNoise().vnoise`).
328
+ * @returns {{
329
+ * crag: (fineness: number) => import('three').BufferGeometry,
330
+ * fallenStone: (detail: number, seed?: number) => import('three').BufferGeometry,
331
+ * }}
332
+ */
333
+ export function createCragLibrary(options = {}) {
334
+ const fbm = options.fbm ?? defaultFbm();
335
+ const vnoise = options.vnoise ?? defaultNoise();
336
+ const crags = [];
337
+ return {
338
+ crag: fineness => (crags[fineness] ??= cragRock(fineness, { fbm })),
339
+ fallenStone: (detail, seed = 1) => fallenStone(detail, seed, { vnoise }),
340
+ };
341
+ }
package/index.js CHANGED
@@ -57,14 +57,41 @@ export {
57
57
  WORN_STONE_FOOT,
58
58
  WORN_STONE_FORMS,
59
59
  beddedOutcrop,
60
+ cragRock,
61
+ createCragLibrary,
60
62
  createRockShapes,
63
+ fallenStone,
61
64
  flatQuad,
62
65
  jointed,
63
66
  wornStone,
64
67
  } from './geometry/strata-rocks.js';
68
+ export { MESA_CLIFF, buildMesaCliff } from './geometry/strata-mesa.js';
65
69
  export { HILL_RUIN, buildHillRuin } from './geometry/ruins-hill.js';
66
70
  export { MOUND_RUINS, buildMoundRuins, buildMoundSherds, buildMoundWalls, createMoundRuins } from './geometry/ruins-mound.js';
71
+ export { MOUND_RUINS_LOD, raiseMoundRuins, registerMoundRuins } from './rendering/ruins-mound.js';
67
72
  export { RUBBLE_HEAP, RUBBLE_SCATTER, buildRubbleHeap, scatterRubble } from './geometry/ruins-rubble.js';
73
+ export { RUIN_WALL, buildRuinWall, coursedWall, tumbleBlock } from './geometry/ruins-walls.js';
74
+ export {
75
+ ASHLAR_COURSE,
76
+ COLUMN_DRUM,
77
+ MASONRY_METAL,
78
+ buildAshlarWall,
79
+ buildColumnDrum,
80
+ buildFlagstones,
81
+ buildLampStandGeometry,
82
+ buildWallLanternGeometry,
83
+ } from './geometry/ruins-masonry.js';
84
+ export {
85
+ LIGHT_POOL,
86
+ addLampStand,
87
+ addLightPool,
88
+ addStillPool,
89
+ addWallLantern,
90
+ createLightPoolTexture,
91
+ } from './rendering/ruins-fittings.js';
92
+ export { DEFAULT_SCORCH_PALETTE, addEmberSkin, buildBreachFan, buildRubbleMound } from './geometry/ruins-breach.js';
93
+ export { CRATER_PALETTE, buildCraterBowl, buildFallenBoulder } from './geometry/ruins-crater.js';
94
+ export { createShapeBatches } from './geometry/instances.js';
68
95
  export { planStreamBanks } from './geometry/stream-banks.js';
69
96
  export { meshStreamBanks } from './rendering/stream-banks.js';
70
97
  export { SPRING_COLOURS, SPRING_HEAD, planSpringRocks, planSprings, springFrame, springWetGround } from './geometry/stream-springs.js';
@@ -89,6 +116,9 @@ export { createAvenueHandover, farRoadPavingMaterial, layPavedRoad, layRoadAvenu
89
116
  export { PAVED_GROUND_LIMITS, createPavedGroundMaterial } from './rendering/paved-ground.js';
90
117
  export { createRoadTraffic, ROAD_TRAFFIC } from './motion/road-traffic.js';
91
118
  export { createFieldSurvey, FIELD_SURVEY, FIELD_USE } from './geometry/field-survey.js';
119
+ export { FIELD_BITS, NO_PATH_DISTANCE, createFieldCoverCache, packFieldBits, packSparsePlain } from './geometry/field-map.js';
120
+ export { DEFAULT_FLOWER_LOOKS, FLOWER_KINDS, TUFT_SHAPE, tuftGeometry } from './geometry/plant-tuft.js';
121
+ export { TUFT_SHADER, createGrassTuft, createTuftMaterial } from './rendering/plant-tuft.js';
92
122
  export { LAND_TRAILS, LAND_TRAIL_MARKS, boundsOverlap, createLandTrails, rasterizeTrailMarks } from './geometry/land-trails.js';
93
123
  export { createTrailMarks, trailMarksGLSL } from './rendering/land-trail-surface.js';
94
124
  export { createIrrigatedFields, IRRIGATED_FIELDS } from './geometry/irrigated-fields.js';
@@ -101,10 +131,19 @@ export { scatterInstances, scatterTrees, scatterTussocks } from './rendering/sca
101
131
  export { FARM_BOUNDARIES, planFieldBoundaries } from './geometry/farm-boundaries.js';
102
132
  export { meshFarmCells, scatterFarmLots } from './rendering/farm-cells.js';
103
133
  export { DEFAULT_LIVESTOCK_CASTS, createLivestockCache } from './rendering/farm-livestock.js';
134
+ export {
135
+ DEFAULT_OX_COATS,
136
+ DEFAULT_PLOUGHMAN_LOOK,
137
+ PLOUGHMAN_SEEN_DISTANCE,
138
+ PLOUGHMAN_STANCE,
139
+ buildPloughman,
140
+ createPloughTeam,
141
+ posePloughman,
142
+ } from './rendering/farm-plough.js';
104
143
  export { DEFAULT_FARM_HERDS, FARM_LIFE, herdPlaces, parcelPlaces, planFarmLife, ploughSite } from './geometry/farm-life.js';
105
144
  export { STOOK, createStook } from './geometry/prop-stook.js';
106
145
  export { PLOUGH, ploughGear } from './geometry/prop-plough.js';
107
- export { FARM_HAYSTACK, FARM_STONE_PILE, buildHaystacks, buildStonePile } from './geometry/farm-props.js';
146
+ export { FARM_BARN_DOORS, FARM_HAYSTACK, FARM_STONE_PILE, buildBarnDoors, buildHaystacks, buildStonePile } from './geometry/farm-props.js';
108
147
 
109
148
  // ── Settlements, houses, fortifications & interiors ──────────────────────
110
149
  export { createHouseKit } from './geometry/house-kit.js';
@@ -230,6 +269,8 @@ export {
230
269
  createLookPicker,
231
270
  } from './rendering/crowd-batches.js';
232
271
  export { createCrowdUpdater, registerCrowd } from './rendering/crowd-update.js';
272
+ export { createCrowdLifecycle } from './rendering/crowd-lifecycle.js';
273
+ export { ContactShadows, createFootShadows } from './rendering/contact-shadows.js';
233
274
  export { createCrowdSystem } from './rendering/crowd-system.js';
234
275
 
235
276
  // ── Effects, audio, pacing & runtime ─────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roamwright",
3
- "version": "0.61.17",
3
+ "version": "0.61.18",
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",
@@ -1,4 +1,5 @@
1
1
  import * as THREE from 'three';
2
+ import { sstep } from '../math/scalar.js';
2
3
 
3
4
  // Soft contact shadows on horizontal receivers. Supply the height of the receiving
4
5
  // surface in mesh-local coordinates. One quad per contact, in one draw.
@@ -80,3 +81,58 @@ export class ContactShadows {
80
81
  this.mesh.material.dispose();
81
82
  }
82
83
  }
84
+
85
+ /**
86
+ * Create a distance-culled and smoothly faded contact-shadow collector for feet, hooves, paws and
87
+ * supine bodies, backed by a single {@link ContactShadows} draw call.
88
+ *
89
+ * @param {object} [options]
90
+ * @param {THREE.Object3D | null} [options.scene=null] - Optional scene or group receiving the shadow mesh.
91
+ * @param {number} [options.capacity=512] - Maximum contact quads per frame.
92
+ * @param {number} [options.opacity=0.42] - Peak contact darkening opacity.
93
+ * @param {number} [options.lift=0.03] - Vertical offset above the receiver surface in metres.
94
+ * @param {number} [options.reach=42] - Distance in metres beyond which contacts are omitted.
95
+ * @param {number} [options.fadeFrom=0.7] - Fraction of `reach` where distance fade begins.
96
+ * @param {number} [options.renderOrder=2] - Three.js `renderOrder` for the contact shadow mesh.
97
+ * @param {number | null} [options.layer=1] - Render layer index assigned to the mesh (`null` leaves default layer 0).
98
+ * @param {string} [options.name='Foot shade'] - Scene-graph name for the contact shadow mesh.
99
+ * @returns {{
100
+ * add: (x: number, y: number, z: number, size: number, distanceSquared: number, intensityScale?: number) => void,
101
+ * begin: () => void,
102
+ * end: () => void,
103
+ * batch: ContactShadows,
104
+ * mesh: THREE.Mesh,
105
+ * dispose: () => void,
106
+ * }}
107
+ */
108
+ export function createFootShadows({
109
+ scene = null,
110
+ capacity = 512,
111
+ opacity = 0.42,
112
+ lift = 0.03,
113
+ reach = 42,
114
+ fadeFrom = 0.7,
115
+ renderOrder = 2,
116
+ layer = 1,
117
+ name = 'Foot shade',
118
+ } = {}) {
119
+ const batch = new ContactShadows({ capacity, opacity, lift });
120
+ batch.mesh.name = name;
121
+ batch.mesh.renderOrder = renderOrder;
122
+ if (layer !== null) batch.mesh.layers.set(layer);
123
+ if (scene) scene.add(batch.mesh);
124
+ const reachSq = reach * reach;
125
+ const fadeStart = reach * fadeFrom;
126
+ return {
127
+ add(x, y, z, size, distanceSquared, intensityScale = 1) {
128
+ if (distanceSquared >= reachSq) return;
129
+ const strength = (1 - sstep(fadeStart, reach, Math.sqrt(distanceSquared))) * intensityScale;
130
+ batch.add(x, y, z, size * 0.5, strength);
131
+ },
132
+ begin: () => batch.begin(),
133
+ end: () => batch.end(),
134
+ batch,
135
+ mesh: batch.mesh,
136
+ dispose: () => batch.dispose(),
137
+ };
138
+ }