roamwright 0.61.26 → 0.61.28

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,457 @@
1
+ /**
2
+ * Large-scale bedded cliff faces wrapped as continuous creased rock sheets:
3
+ * 1) `createBeddedButte`: a ridge-line limestone butte with stepped beds, a high fissure shelf,
4
+ * an arched foot cave, a broken skyline with clefts and top knobs, a stepped back slope, a
5
+ * concave talus apron, async `breathe()` chunking, and flanking outcrop stacks.
6
+ * 2) `createEscarpmentCliff`: a tall stratified escarpment cliff with scree toe, dipping hard/soft
7
+ * beds, vertical buttresses and gullies, grassy ledges, a tapering upland plateau, an analytical
8
+ * floor profile for flyers, and a carved switchback cliff stair (`buildSwitchbackStair`).
9
+ * Pure geometry builders; worker-safe.
10
+ * @module
11
+ */
12
+
13
+ import { dim } from '../math/color.js';
14
+ import { lerp, sstep } from '../math/scalar.js';
15
+ import { GB } from './builder.js';
16
+ import { defaultRockHash as defaultHash, defaultRockNoise as defaultNoise, rockSheet, sampleRockSheet } from './creased-sheet.js';
17
+ import { C as defaultColor, TRS as defaultTransform, defaultUnitShapes } from './primitives.js';
18
+ import { buildOutcrop } from './rock-sheets.js';
19
+ import { jointed } from './strata-rocks.js';
20
+
21
+ const defaultRock = () => defaultUnitShapes().rock;
22
+
23
+ /** Default dimensions, bedding profile and limestone tones for {@link createBeddedButte}. */
24
+ export const BEDDED_BUTTE_DEFAULTS = Object.freeze({
25
+ half: 105,
26
+ ends: 34,
27
+ height: 44,
28
+ bury: 2,
29
+ crestX: 57,
30
+ backX: 62,
31
+ slope: 36,
32
+ bedTops: Object.freeze([0.2, 0.34, 0.6, 0.8, 1]),
33
+ shelfBed: 2,
34
+ fissure: Object.freeze({ half: 4.4, depth: 13 }),
35
+ cave: Object.freeze({ z: 20, half: 3, height: 4.4, depth: 9 }),
36
+ bedTones: Object.freeze([0xc6baa2, 0xd8cdb6, 0xbdb098, 0xded4bf, 0xcdc1a9]),
37
+ dust: 0xcdbb9d,
38
+ crest: 0.16,
39
+ jags: 0.07,
40
+ cleft: 0.17,
41
+ knobs: 0.08,
42
+ bays: 14,
43
+ streaks: 0.16,
44
+ nests: 0.4,
45
+ faceShade: 0.9,
46
+ keep: Object.freeze([35, 50]),
47
+ endSteps: 3,
48
+ apron: Object.freeze({ up: 0.14, out: 0.42 }),
49
+ stacks: Object.freeze([
50
+ Object.freeze([-8, 22, 7, 0.55, 3]),
51
+ Object.freeze([-20, 34, 5, 0.32, 5]),
52
+ Object.freeze([10, 26, 8, 0.46, 7]),
53
+ Object.freeze([24, 40, 4.5, 0.27, 11]),
54
+ ]),
55
+ faceRows: Object.freeze([
56
+ [0, 0],
57
+ [0.05, 0],
58
+ [0.09, 0],
59
+ [0.12, 0],
60
+ [0.145, 0],
61
+ [0.17, 0],
62
+ [0.2, 0],
63
+ [0.2, 1],
64
+ [0.27, 1],
65
+ [0.34, 1],
66
+ [0.34, 2],
67
+ [0.47, 2],
68
+ [0.6, 2],
69
+ [0.6, 3],
70
+ [0.7, 3],
71
+ [0.8, 3],
72
+ [0.8, 4],
73
+ [0.9, 4],
74
+ [1, 4],
75
+ ]),
76
+ topRows: 7,
77
+ backRows: 8,
78
+ rowsPerBand: 9,
79
+ cellsPerBand: 30,
80
+ });
81
+
82
+ /**
83
+ * Create a bedded ridge-line cliff butte handle whose local origin sits at the foot of the west
84
+ * cliff face (+X into the rock, +Z along the face). Provides analytical face/ledge queries and an
85
+ * async `build(origin, ground, breathe)` method that shapes the rock sheet in frame-friendly bands.
86
+ *
87
+ * @param {Partial<typeof BEDDED_BUTTE_DEFAULTS> & {
88
+ * noise?: (x: number, z: number, salt: number) => number,
89
+ * hash?: (x: number, y: number, salt: number) => number,
90
+ * rock?: import('three').BufferGeometry,
91
+ * color?: Function,
92
+ * transform?: Function,
93
+ * Builder?: typeof GB,
94
+ * }} [options]
95
+ * @returns {{
96
+ * faceX: (z: number, bed: number) => number,
97
+ * heightAt: (z: number) => number,
98
+ * stand: (worldGround: (x: number, z: number) => number, origin: { x: number, z: number }) => { foot: number, top: number, shelf: number, ledge: (z: number, bed: number) => [number, number, number] },
99
+ * build: (origin: { x: number, z: number }, ground: (x: number, z: number) => number, breathe?: () => Promise<void>) => Promise<GB>,
100
+ * }}
101
+ */
102
+ export function createBeddedButte(options = {}) {
103
+ const cfg = { ...BEDDED_BUTTE_DEFAULTS, ...options };
104
+ const vnoise = options.noise ?? defaultNoise();
105
+ const hash2 = options.hash ?? defaultHash();
106
+ const rock = options.rock ?? defaultRock();
107
+ const color = options.color ?? defaultColor;
108
+ const transform = options.transform ?? defaultTransform;
109
+ const Builder = options.Builder ?? GB;
110
+ const {
111
+ half: HALF,
112
+ ends: ENDS,
113
+ height: HEIGHT,
114
+ bury: BURY,
115
+ crestX: CREST_X,
116
+ backX: BACK_X,
117
+ slope: SLOPE,
118
+ bedTops: BED_TOPS,
119
+ shelfBed: SHELF_BED,
120
+ fissure: FISSURE,
121
+ cave: CAVE,
122
+ bedTones: BED_TONES,
123
+ dust: DUST,
124
+ crest: CREST,
125
+ jags: JAGS,
126
+ cleft: CLEFT,
127
+ knobs: KNOBS,
128
+ bays: BAYS,
129
+ streaks: STREAKS,
130
+ nests: NESTS,
131
+ faceShade: FACE_SHADE,
132
+ keep: KEEP,
133
+ endSteps: END_STEPS,
134
+ apron: APRON,
135
+ stacks: STACKS,
136
+ faceRows: FACE_ROWS,
137
+ topRows: TOP_ROWS,
138
+ backRows: BACK_ROWS,
139
+ rowsPerBand: ROWS_A_BAND,
140
+ cellsPerBand: CELLS_A_BAND,
141
+ } = cfg;
142
+
143
+ const rise = z => jointed(sstep(HALF, HALF - ENDS, Math.abs(z)), 4);
144
+ const plan = z => {
145
+ const round = Math.max(0, 1 - (z / HALF) ** 2) ** 0.25;
146
+ return lerp(round, jointed(round, END_STEPS), sstep(KEEP[0], KEEP[1], Math.abs(z)));
147
+ };
148
+ const broken = z => sstep(2.5, 6, Math.abs(z));
149
+ const skyline = z => sstep(9, 22, Math.abs(z));
150
+ const heightAt = z =>
151
+ HEIGHT *
152
+ rise(z) *
153
+ (1 + (CREST * (jointed(vnoise(z * 0.035, 7.7, 919), 3) - 0.4) + JAGS * (jointed(vnoise(z * 0.16, 4.4, 923), 2) - 0.5)) * skyline(z));
154
+ const cleftAt = z => HEIGHT * CLEFT * rise(z) * sstep(0.64, 0.76, vnoise(z * 0.08, 2.9, 924)) * skyline(z);
155
+ const caveDepth = (z, y) => {
156
+ const dz = Math.abs(z - CAVE.z);
157
+ const arch = CAVE.height * Math.sqrt(Math.max(0, 1 - (dz / (CAVE.half + 0.9)) ** 2));
158
+ return CAVE.depth * sstep(CAVE.half + 0.9, CAVE.half, dz) * sstep(arch + 0.5, arch - 0.6, y);
159
+ };
160
+ const faceX = (z, bed) => {
161
+ const bays = BAYS * (vnoise(z * 0.017, 5.5, 926) - 0.5) * sstep(KEEP[0] - 5, KEEP[1], Math.abs(z));
162
+ const buttress = 5.5 * (jointed(vnoise(z * 0.05, 3.1, 911), 4) - 0.35) * broken(z);
163
+ const chipped =
164
+ (1.6 * (jointed(vnoise(z * 0.17 + bed * 7.1, 1.7, 912), 3) - 0.3) + 1.1 * (jointed(vnoise(z * 0.21, bed * 3.3, 917), 2) - 0.5)) *
165
+ broken(z);
166
+ const cleft = bed >= SHELF_BED ? FISSURE.depth * sstep(FISSURE.half + 1.2, FISSURE.half, Math.abs(z)) : 0;
167
+ return lerp(CREST_X, 0, plan(z)) + bed * 1.1 + bays + buttress + chipped + cleft;
168
+ };
169
+
170
+ async function build(O, ground, breathe = async () => {}) {
171
+ const builder = new Builder();
172
+ const columns = [];
173
+ for (let z = -HALF; z <= HALF; z += Math.abs(z) < 8 || Math.abs(z - CAVE.z) < 6 ? 0.8 : 1.2) columns.push(z);
174
+ const footY = z => ground(faceX(z, 0), z);
175
+ const topY = z => footY(z) + heightAt(z);
176
+ const knob = (x, z, t) => HEIGHT * KNOBS * rise(z) * jointed(vnoise(x * 0.07, z * 0.15, 925), 3) * Math.sin(Math.PI * t);
177
+ const point = (z, r) => {
178
+ const foot = footY(z);
179
+ const top = topY(z);
180
+ const cut = top - cleftAt(z);
181
+ if (r < FACE_ROWS.length) {
182
+ const [up, bed] = FACE_ROWS[r];
183
+ const y = Math.min(cut, foot - BURY + (top - foot + BURY) * up);
184
+ const inner = r > 0 && r < FACE_ROWS.length - 1 && FACE_ROWS[r - 1][1] === bed && FACE_ROWS[r + 1][1] === bed;
185
+ const bulge = inner ? 1.1 * (jointed(vnoise(z * 0.3, y * 0.3, 914), 3) - 0.5) * broken(z) : 0;
186
+ return [faceX(z, bed) + bulge + caveDepth(z, y - foot), y, z];
187
+ }
188
+ const brow = faceX(z, BED_TOPS.length - 1);
189
+ const back = lerp(CREST_X + 2, BACK_X, plan(z));
190
+ if (r < FACE_ROWS.length + TOP_ROWS) {
191
+ const t = (r - FACE_ROWS.length + 1) / TOP_ROWS;
192
+ const x = lerp(brow, Math.max(back, brow + 1), t);
193
+ const floor = lerp(cut, top, sstep(0.15, 0.6, t));
194
+ return [x, floor + 1.8 * (vnoise(x * 0.06, z * 0.06, 913) - 0.5) * Math.sin(Math.PI * Math.min(1, t * 1.2)) + knob(x, z, t), z];
195
+ }
196
+ const t = (r - FACE_ROWS.length - TOP_ROWS + 1) / BACK_ROWS;
197
+ const reach = Math.max(back, brow + 1) + (SLOPE * plan(z) + 2) * t;
198
+ const end = Math.max(back, brow + 1) + SLOPE * plan(z) + 2;
199
+ const fall = 0.55 * t + 0.45 * jointed(t, 4);
200
+ return [reach + 1.5 * (vnoise(z * 0.11, t * 5, 915) - 0.5), lerp(top, ground(end, z) - BURY, fall), z];
201
+ };
202
+ const dust = color(DUST);
203
+ const tone = (z, r, p) => {
204
+ if (r >= FACE_ROWS.length) return dust.map(v => v * (0.9 + 0.2 * vnoise(p[0] * 0.08, z * 0.08, 916)));
205
+ const streak = 1 - STREAKS * sstep(0.45, 0.8, vnoise(z * 0.55, p[1] * 0.025, 918)) * (0.5 + 0.5 * vnoise(z * 0.06, 1.3, 921));
206
+ const nest = 1 - NESTS * sstep(0.8, 0.86, vnoise(z * 0.42, p[1] * 0.5, 920)) * broken(z);
207
+ const shade = FACE_SHADE * (0.88 + 0.22 * vnoise(z * 0.21, p[1] * 0.21, 916)) * streak * nest;
208
+ const dark = 1 - 0.9 * sstep(0.6, 4, caveDepth(z, p[1] - footY(z)));
209
+ return color(BED_TONES[FACE_ROWS[r][1]]).map(v => v * shade * dark);
210
+ };
211
+ const rows = [];
212
+ const tones = [];
213
+ for (let r = 0; r < FACE_ROWS.length + TOP_ROWS + BACK_ROWS; r++) {
214
+ const line = columns.map(z => point(z, r));
215
+ rows.push(line.map(([x, y, z]) => [O.x + x, y, O.z + z]));
216
+ tones.push(line.map((p, i) => tone(columns[i], r, p)));
217
+ if (r % ROWS_A_BAND === ROWS_A_BAND - 1) await breathe();
218
+ }
219
+ const apron = [1, 0.4].map(f =>
220
+ columns.map(z => {
221
+ const k = sstep(KEEP[0], KEEP[1], Math.abs(z)) * rise(z) * (0.6 + 0.8 * vnoise(z * 0.045, 6.1, 927));
222
+ const x = faceX(z, 0) - HEIGHT * APRON.out * k * f - 0.3;
223
+ const lift = HEIGHT * APRON.up * k * (1 - f) ** 1.8;
224
+ return [O.x + x, ground(x, z) + lift - (f === 1 ? 0.3 : 0.05 + 0.5 * (1 - k)), O.z + z];
225
+ }),
226
+ );
227
+ const scree = apron.map((row, j) =>
228
+ row.map((p, i) => {
229
+ const stone = color(BED_TONES[i % 2 ? 0 : 2]);
230
+ return stone.map((v, c) => lerp(v * 0.9, dust[c], j ? 0.55 : 0.85) * (0.9 + 0.2 * vnoise(p[0] * 0.1, p[2] * 0.1, 928)));
231
+ }),
232
+ );
233
+ await breathe();
234
+ const sheet = [...apron, ...rows];
235
+ const shades = [...scree, ...tones];
236
+ for (let from = 0; from < columns.length - 1; from += CELLS_A_BAND) {
237
+ rockSheet(builder, sheet, shades, { dust, columns: [from, Math.min(from + CELLS_A_BAND, columns.length - 1)] });
238
+ await breathe();
239
+ }
240
+ const outcropOpts = { noise: vnoise, hash: hash2, rock, color, transform };
241
+ for (const end of [-1, 1])
242
+ for (const [past, inward, half, tall, seed] of STACKS) {
243
+ const z = end * (HALF + past);
244
+ const x = CREST_X - inward;
245
+ buildOutcrop(
246
+ builder,
247
+ (wx, wz) => ground(wx - O.x, wz - O.z),
248
+ {
249
+ x: O.x + x,
250
+ z: O.z + z,
251
+ rx: half,
252
+ rz: half * 1.3,
253
+ h: HEIGHT * tall,
254
+ beds: 3,
255
+ yaw: seed,
256
+ seed: seed * end,
257
+ taper: 0.15,
258
+ tones: BED_TONES,
259
+ dust: DUST,
260
+ talus: 0.8,
261
+ },
262
+ outcropOpts,
263
+ );
264
+ await breathe();
265
+ }
266
+ return builder;
267
+ }
268
+
269
+ function stand(worldGround, O) {
270
+ const ground = (x, z) => worldGround(O.x + x, O.z + z);
271
+ const foot = ground(faceX(0, 0), 0);
272
+ return {
273
+ foot,
274
+ top: foot + HEIGHT,
275
+ shelf: foot - BURY + (HEIGHT + BURY) * BED_TOPS[SHELF_BED - 1],
276
+ ledge(z, bed) {
277
+ const base = ground(faceX(z, 0), z);
278
+ return [faceX(z, bed + 1) - 0.25, base - BURY + (heightAt(z) + BURY) * BED_TOPS[bed], z];
279
+ },
280
+ };
281
+ }
282
+
283
+ return { faceX, heightAt, stand, build };
284
+ }
285
+
286
+ /** Default dimensions, bedding profile and grey limestone tones for {@link createEscarpmentCliff}. */
287
+ export const ESCARPMENT_CLIFF_DEFAULTS = Object.freeze({
288
+ half: 340,
289
+ toeZ: -184,
290
+ footZ: -236,
291
+ lean: 11,
292
+ top: 150,
293
+ back: 640,
294
+ bedTops: Object.freeze([0.11, 0.2, 0.34, 0.45, 0.58, 0.7, 0.83, 1]),
295
+ bedStep: 0.9,
296
+ soft: 0.7,
297
+ bedTones: Object.freeze([0x6f6b63, 0x7e796f, 0x625f58, 0x8a847a, 0x5c5a54, 0x78736a, 0x67645d, 0x827d73]),
298
+ ledgeTone: 0x4f5442,
299
+ screeTone: 0x6a6660,
300
+ turfTone: 0x434a36,
301
+ keepX: 40,
302
+ keepFlatRange: Object.freeze([48, 75]),
303
+ bedRows: Object.freeze([0, 0.18, 0.45, 0.75, 1]),
304
+ screeRows: Object.freeze([0, 0.25, 0.5, 0.75]),
305
+ topRows: Object.freeze([0.04, 0.12, 0.3, 0.48, 0.62, 0.76, 0.9, 1]),
306
+ columnStep: 1.6,
307
+ });
308
+
309
+ /**
310
+ * Create a tall bedded escarpment cliff handle facing south (+Z) along X with scree toe, dipping
311
+ * hard/soft limestone beds, gullies, buttresses, grassy ledges, a tapering upland plateau, and a
312
+ * carved switchback stair helper.
313
+ *
314
+ * @param {Partial<typeof ESCARPMENT_CLIFF_DEFAULTS> & {
315
+ * noise?: (x: number, z: number, salt: number) => number,
316
+ * hash?: (x: number, y: number, salt: number) => number,
317
+ * color?: Function,
318
+ * Builder?: typeof GB,
319
+ * }} [options]
320
+ * @returns {{
321
+ * browY: (x: number) => number,
322
+ * faceZ: (x: number, up: number, bed: number) => number,
323
+ * shoulder: (x: number, z: number) => number,
324
+ * floorHeight: (x: number, z: number, ground: number) => number,
325
+ * buildSheet: (origin: { x: number, z: number }, ground: (x: number, z: number) => number) => GB,
326
+ * buildStair: (ground: (x: number, z: number) => number, builder: GB, random: () => number, stair: { x0: number, x1: number, legs: number, steps: number, treadTone?: number, wallTone?: number }) => void,
327
+ * }}
328
+ */
329
+ export function createEscarpmentCliff(options = {}) {
330
+ const cfg = { ...ESCARPMENT_CLIFF_DEFAULTS, ...options };
331
+ const vnoise = options.noise ?? defaultNoise();
332
+ const hash2 = options.hash ?? defaultHash();
333
+ const color = options.color ?? defaultColor;
334
+ const Builder = options.Builder ?? GB;
335
+ const {
336
+ half: HALF,
337
+ toeZ: TOE_Z,
338
+ footZ: FOOT_Z,
339
+ lean: LEAN,
340
+ top: TOP,
341
+ back: BACK,
342
+ bedTops: BED_TOPS,
343
+ bedStep: BED_STEP,
344
+ soft: SOFT,
345
+ bedTones: BED_TONES,
346
+ ledgeTone: LEDGE,
347
+ screeTone: SCREE,
348
+ turfTone: TURF,
349
+ keepX: KEEP_X,
350
+ keepFlatRange: KEEP_RANGE,
351
+ bedRows: BED_ROWS,
352
+ screeRows: SCREE_ROWS,
353
+ topRows: TOP_ROWS,
354
+ columnStep: COLUMN_STEP,
355
+ } = cfg;
356
+
357
+ const ROWS = [
358
+ ...SCREE_ROWS.map(t => ['scree', t, 0, 0]),
359
+ ...BED_TOPS.flatMap((top, b) => BED_ROWS.map((t, k) => ['face', t, b, k])),
360
+ ...TOP_ROWS.map(t => ['top', t, BED_TOPS.length - 1, 0]),
361
+ ];
362
+ const hard = b => hash2(b, 3, 950) > 0.45;
363
+ const nearKeep = x => sstep(KEEP_RANGE[0], KEEP_RANGE[1], Math.abs(x - KEEP_X));
364
+ const browY = x => TOP + 7 * (jointed(vnoise(x * 0.018, 4.1, 951), 3) - 0.45) * nearKeep(x);
365
+ const gully = x => sstep(0.74, 0.86, vnoise(x * 0.026, 6.7, 953));
366
+ const buttress = x =>
367
+ (12 * (jointed(vnoise(x * 0.019, 2.3, 952), 4) - 0.4) - 14 * gully(x)) * lerp(0.2, 1, nearKeep(x)) -
368
+ 150 * sstep(190, HALF, Math.abs(x)) ** 2;
369
+ const chipped = (x, b) =>
370
+ 2.8 * (jointed(vnoise(x * 0.11 + b * 5.3, 1.9, 954), 2) - 0.5) + 1.2 * (jointed(vnoise(x * 0.37, b * 2.9, 955), 2) - 0.5);
371
+ const boundary = (x, b) =>
372
+ b < 0
373
+ ? 0
374
+ : b >= BED_TOPS.length - 1
375
+ ? 1
376
+ : BED_TOPS[b] + 0.018 * Math.sin(x * 0.0061 + 0.4) + 0.012 * (vnoise(x * 0.02, b * 1.3, 949) - 0.5);
377
+ const faceZ = (x, up, b) => FOOT_Z - LEAN * up - b * BED_STEP + buttress(x) + chipped(x, b) - (hard(b) ? 0 : 1.6);
378
+ const shoulder = (x, z) => sstep(HALF, 225, Math.abs(x)) * sstep(-835 + 45 * Math.sin(x / 97), -490, z);
379
+
380
+ function floorHeight(x, z, ground) {
381
+ if (Math.abs(x) >= HALF || z > TOE_Z + 4 || z < -900) return ground;
382
+ const toe = TOE_Z + buttress(x) * 0.5 + 4;
383
+ const foot = faceZ(x, 0, 0) + 4;
384
+ const brow = faceZ(x, 1, BED_TOPS.length - 1) + 7;
385
+ const rise = sstep(toe, foot, z);
386
+ const shelf = lerp(ground, ground + 28, rise);
387
+ const height = lerp(shelf, browY(x) + 4, sstep(foot + 10, brow + 4, z));
388
+ return lerp(ground, height, shoulder(x, z));
389
+ }
390
+
391
+ function buildSheet(O, ground) {
392
+ const builder = new Builder();
393
+ const footY = x => ground(x, FOOT_Z) + 14 + 4 * vnoise(x * 0.03, 8.8, 956) + 9 * gully(x);
394
+ const at = (u, v) => {
395
+ const x = (u - 0.5) * 2 * HALF;
396
+ const [kind, t, b, k] = ROWS[Math.round(v * (ROWS.length - 1))];
397
+ const yF = footY(x);
398
+ const yT = browY(x);
399
+ let pz, py;
400
+ if (kind === 'scree') {
401
+ pz = lerp(TOE_Z + 4 * (vnoise(x * 0.05, 1.1, 957) - 0.5) + buttress(x) * 0.5, faceZ(x, 0, 0) - SOFT, t);
402
+ py = lerp(ground(x, TOE_Z) - 1.5, yF, t * t);
403
+ } else if (kind === 'face') {
404
+ const up = lerp(boundary(x, b - 1), boundary(x, b), t);
405
+ const y = lerp(yF, yT, up);
406
+ const inner = k > 0 && k < BED_ROWS.length - 1;
407
+ const bulge = inner ? 1.4 * (jointed(vnoise(x * 0.23, y * 0.21, 958), 3) - 0.5) : 0;
408
+ const foot = k === 0 ? -SOFT * (hard(b) ? 1 : 2) : 0;
409
+ const brim = k === BED_ROWS.length - 1 && hard(b) ? 0.6 : 0;
410
+ py = y;
411
+ pz = faceZ(x, up, b) + bulge + foot + brim;
412
+ } else {
413
+ const brow = faceZ(x, 1, b);
414
+ pz = brow - BACK * t * t - 1.2 * (t > 0 ? 1 : 0);
415
+ py = yT + 3 * t + 2.2 * (vnoise(x * 0.04, t * 6, 960) - 0.5) * sstep(0, 0.2, t) * nearKeep(x);
416
+ }
417
+ const edge = shoulder(x, pz);
418
+ if (edge < 1) py = lerp(ground(x, pz) - 1.5, py, edge);
419
+ return [O.x + x, py, O.z + pz];
420
+ };
421
+ const tone = (u, v) => {
422
+ const x = (u - 0.5) * 2 * HALF;
423
+ const r = Math.min(ROWS.length - 2, Math.floor(v * (ROWS.length - 1)));
424
+ const [kind, , b, k] = ROWS[r];
425
+ const next = ROWS[r + 1];
426
+ const shade = (0.84 + 0.3 * vnoise(x * 0.13, r * 0.7, 961)) * (1 - 0.3 * gully(x));
427
+ let c;
428
+ if (kind === 'scree') c = color(SCREE);
429
+ else if (kind === 'top') c = color(TURF);
430
+ else if (k === BED_ROWS.length - 1 && next[0] !== 'top') c = color(LEDGE);
431
+ else {
432
+ const streak = 1 - 0.24 * sstep(0.5, 0.8, vnoise(x * 0.35, 3.3, 962));
433
+ c = dim(color(BED_TONES[b % BED_TONES.length]), (k === 0 ? 0.72 : 1) * (hard(b) ? 1.06 : 0.9) * streak);
434
+ }
435
+ return [c[0] * shade, c[1] * shade, c[2] * shade];
436
+ };
437
+ sampleRockSheet(builder, Math.round(HALF / COLUMN_STEP), ROWS.length - 1, at, tone);
438
+ return builder;
439
+ }
440
+
441
+ function buildStair(ground, stone, rng, { x0, x1, legs, steps, treadTone = 0x5e5b55, wallTone = 0x67645d }) {
442
+ const rise = (browY(KEEP_X) - ground(KEEP_X, FOOT_Z) - 14) / legs;
443
+ for (let leg = 0; leg < legs; leg++)
444
+ for (let k = 0; k < steps; k++) {
445
+ const u = k / (steps - 1);
446
+ const x = leg % 2 ? lerp(x1, x0, u) : lerp(x0, x1, u);
447
+ const up = (leg + u) / legs;
448
+ const y = ground(x, FOOT_Z) + 14 + rise * legs * up;
449
+ const bed = BED_TOPS.findIndex(top => top >= up);
450
+ const z = Math.max(faceZ(x, up, bed), faceZ(x, up, Math.max(0, bed - 1))) + 2.4;
451
+ stone.box(x, y - 2, z, 1.2, 2.3, 3.4, color(treadTone, 0.06, rng));
452
+ stone.box(x, y + 0.3, z + 1.55, 1.2, 0.9, 0.35, color(wallTone, 0.06, rng));
453
+ }
454
+ }
455
+
456
+ return { browY, faceZ, shoulder, floorHeight, buildSheet, buildStair };
457
+ }
@@ -1,5 +1,14 @@
1
+ import { createNoise } from '../math/noise.js';
2
+ import { createHash } from '../math/random.js';
1
3
  import { sstep } from '../math/scalar.js';
2
4
 
5
+ let fallbackNoise = null;
6
+ /** Lazily created default 2D value-noise sampler for rock/cliff sheet builders. */
7
+ export const defaultRockNoise = () => (fallbackNoise ??= createNoise().vnoise);
8
+ let fallbackHash = null;
9
+ /** Lazily created default 2D coordinate hash for rock/cliff sheet builders. */
10
+ export const defaultRockHash = () => (fallbackHash ??= createHash());
11
+
3
12
  /**
4
13
  * `creasedSheet(builder, rows, colors, options)` triangulates a rectangular grid of XYZ points with matching linear
5
14
  * RGB triples. Corner normals are area weighted over adjoining faces whose cosine is at least `crease` (default −1).
@@ -150,3 +159,33 @@ export function creasedSheet(
150
159
  export function rockSheet(builder, rows, tones, { wrap, inside, crease = 0.55, dust, columns } = {}) {
151
160
  creasedSheet(builder, rows, tones, { wrap, inside, crease, tint: dust, slopeFrom: 0.6, slopeTo: 0.86, columns });
152
161
  }
162
+
163
+ /**
164
+ * Sample a parametric rock surface `at(u, v) -> [x, y, z]` and `tone(u, v) -> [r, g, b]` across an
165
+ * `nu` by `nv` cell grid (`u` and `v` in `[0, 1]`) and emit it through {@link rockSheet}.
166
+ * The outward face has `u` to the right and `v` upward; pass `inside = true` (or `{ inside: true }`)
167
+ * to flip winding for cave walls or ceilings.
168
+ *
169
+ * @param {object} builder - A geometry builder with `raw(x, y, z, nx, ny, nz, r, g, b)`.
170
+ * @param {number} nu - Horizontal cell divisions along `u`.
171
+ * @param {number} nv - Vertical cell divisions along `v`.
172
+ * @param {(u: number, v: number) => [number, number, number]} at - Surface position sampler in metres.
173
+ * @param {(u: number, v: number) => [number, number, number]} tone - Linear RGB colour sampler.
174
+ * @param {boolean | { wrap?: boolean, inside?: boolean, crease?: number, dust?: number[] | null, columns?: [number, number] | null }} [options=false]
175
+ */
176
+ export function sampleRockSheet(builder, nu, nv, at, tone, options = false) {
177
+ const opts = typeof options === 'boolean' ? { inside: options } : options;
178
+ const rows = [];
179
+ const tones = [];
180
+ for (let j = 0; j <= nv; j++) {
181
+ const row = [];
182
+ const shades = [];
183
+ for (let i = 0; i <= nu; i++) {
184
+ row.push(at(i / nu, j / nv));
185
+ shades.push(tone(i / nu, j / nv));
186
+ }
187
+ rows.push(row);
188
+ tones.push(shades);
189
+ }
190
+ rockSheet(builder, rows, tones, opts);
191
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Pure geometry array builders for concentric cylindrical dust curtains and atmospheric veil sheets.
3
+ * Worker-safe (no Three.js or DOM imports).
4
+ * @module
5
+ */
6
+
7
+ import { TAU } from '../math/scalar.js';
8
+
9
+ /** Default cylindrical curtain geometry dimensions in metres. */
10
+ export const DUST_CURTAIN_SHAPE = Object.freeze({
11
+ rings: Object.freeze([46, 64]),
12
+ height: 95,
13
+ sink: 4,
14
+ flare: 0.25,
15
+ around: 72,
16
+ up: 12,
17
+ uvSpan: 30,
18
+ });
19
+
20
+ /**
21
+ * Build indexed vertex arrays (`position`, `uv`, `index`) for one or more concentric flaring
22
+ * cylindrical curtain sheets centred on the Y axis.
23
+ *
24
+ * @param {object} [options]
25
+ * @param {readonly number[]} [options.rings=DUST_CURTAIN_SHAPE.rings] - Ring base radii in metres.
26
+ * @param {number} [options.height=DUST_CURTAIN_SHAPE.height] - Curtain height in metres.
27
+ * @param {number} [options.sink=DUST_CURTAIN_SHAPE.sink] - Base burial depth below `y = 0` in metres.
28
+ * @param {number} [options.flare=DUST_CURTAIN_SHAPE.flare] - Fractional outward radial flare at the top.
29
+ * @param {number} [options.around=DUST_CURTAIN_SHAPE.around] - Circumferential segment count.
30
+ * @param {number} [options.up=DUST_CURTAIN_SHAPE.up] - Vertical segment count.
31
+ * @param {number} [options.uvSpan=DUST_CURTAIN_SHAPE.uvSpan] - Arc length in metres per unit horizontal UV.
32
+ * @returns {{ position: Float32Array, uv: Float32Array, index: Uint16Array | Uint32Array }}
33
+ */
34
+ export function dustCurtainArrays({
35
+ rings = DUST_CURTAIN_SHAPE.rings,
36
+ height = DUST_CURTAIN_SHAPE.height,
37
+ sink = DUST_CURTAIN_SHAPE.sink,
38
+ flare = DUST_CURTAIN_SHAPE.flare,
39
+ around = DUST_CURTAIN_SHAPE.around,
40
+ up = DUST_CURTAIN_SHAPE.up,
41
+ uvSpan = DUST_CURTAIN_SHAPE.uvSpan,
42
+ } = {}) {
43
+ const pos = [];
44
+ const st = [];
45
+ const idx = [];
46
+ for (const r of rings) {
47
+ const base = pos.length / 3;
48
+ for (let i = 0; i <= around; i++) {
49
+ const a = (i / around) * TAU;
50
+ for (let j = 0; j <= up; j++) {
51
+ const v = j / up;
52
+ pos.push(Math.cos(a) * r * (1 + flare * v), v * height - sink, Math.sin(a) * r * (1 + flare * v));
53
+ st.push((a * r) / uvSpan, v);
54
+ if (i && j) {
55
+ const k = base + i * (up + 1) + j;
56
+ idx.push(k - up - 2, k - 1, k, k - up - 2, k, k - up - 1);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ const vertexCount = pos.length / 3;
62
+ return {
63
+ position: new Float32Array(pos),
64
+ uv: new Float32Array(st),
65
+ index: vertexCount > 65535 ? new Uint32Array(idx) : new Uint16Array(idx),
66
+ };
67
+ }