roamwright 0.61.12 → 0.61.14
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.
- package/README.md +2 -1
- package/examples/animals.js +3 -2
- package/examples/crowds.js +3 -2
- package/examples/figure-motion.js +3 -2
- package/examples/figure.js +23 -31
- package/examples/fliers.js +3 -2
- package/examples/fortification.js +3 -2
- package/examples/house-kit.js +3 -2
- package/examples/island.js +22 -30
- package/examples/pacing.js +3 -2
- package/examples/props-and-plants.js +3 -2
- package/examples/ruins.html +60 -0
- package/examples/ruins.js +326 -0
- package/examples/ships.js +3 -2
- package/examples/small-world-land.js +2 -2
- package/examples/soundscape.js +3 -2
- package/examples/stage.js +3 -19
- package/examples/towns.js +3 -2
- package/geometry/heightfield.js +31 -1
- package/geometry/paved-road.js +443 -0
- package/geometry/ruins-hill.js +392 -0
- package/geometry/ruins-mound.js +484 -0
- package/geometry/ruins-rubble.js +161 -0
- package/geometry/strata-rocks.js +270 -0
- package/index.js +29 -0
- package/package.json +1 -1
- package/rendering/paved-ground.js +218 -0
- package/rendering/paved-road.js +353 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hilltop ruin builder: tumbled stone blocks, leaning tower remnants, wall-stump building footprints,
|
|
3
|
+
* exposed older masonry courses along slumped flanks, near-range scree, and draped standing pools
|
|
4
|
+
* and sinkhole mouths. Pure geometry assembly, worker-safe.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { pickR } from '../math/random.js';
|
|
10
|
+
import { TAU } from '../math/scalar.js';
|
|
11
|
+
import { GB } from './builder.js';
|
|
12
|
+
import { C as defaultColor, TRS as defaultTransform, createUnitShapes } from './primitives.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Default palettes (sRGB hex), feature counts and drape geometry settings for {@link buildHillRuin}.
|
|
16
|
+
* Distances and offsets are in metres.
|
|
17
|
+
*/
|
|
18
|
+
export const HILL_RUIN = Object.freeze({
|
|
19
|
+
/** Weathered pale limestone and marble palette for top blocks, drums and wall stumps. */
|
|
20
|
+
pale: Object.freeze([0xd9d2c0, 0xcfc6b0, 0xe2dccb, 0xbfb6a0, 0xd2c6ac]),
|
|
21
|
+
/** Mud and fired brick tones for older buried walls and flank sherds. */
|
|
22
|
+
oldBrick: Object.freeze([0xa8875f, 0x9a6a4a, 0xb39169, 0x8e5f42]),
|
|
23
|
+
/** Share of the hill radius covered by the flat ruined summit. */
|
|
24
|
+
top: 0.7,
|
|
25
|
+
/** Count of tumbled blocks, beams, drums and leaning tower stumps across the summit. */
|
|
26
|
+
tumbled: 320,
|
|
27
|
+
/** Count of rectangular wall-stump room footprints traced across the summit. */
|
|
28
|
+
rooms: 16,
|
|
29
|
+
/** Count of boulders and blocks slid down the hill flanks. */
|
|
30
|
+
flank: 520,
|
|
31
|
+
/** Count of near-range small stones and brick sherds strewn over the flanks. */
|
|
32
|
+
scree: 3400,
|
|
33
|
+
/** Visibility range in metres beyond the hill radius for the near-range scree mesh. */
|
|
34
|
+
screeSeen: 300,
|
|
35
|
+
/** Count of older masonry courses protruding from the slumped flanks. */
|
|
36
|
+
oldWalls: 240,
|
|
37
|
+
/** Count of standing water pools draped in level hollows on the summit. */
|
|
38
|
+
pools: 8,
|
|
39
|
+
/** Count of dark sinkhole mouths ringed with broken stone on the summit. */
|
|
40
|
+
sinkholes: 6,
|
|
41
|
+
/** Vertical clearance in metres a draped surface sits above the underlying ground. */
|
|
42
|
+
lift: 0.08,
|
|
43
|
+
/** Angular segment count around each draped hollow. */
|
|
44
|
+
segments: 20,
|
|
45
|
+
/** Radial irregularity of a hollow edge as a share of its radius. */
|
|
46
|
+
ragged: 0.16,
|
|
47
|
+
/** Candidate positions sampled per pool; the levellest hollow is kept. */
|
|
48
|
+
poolTries: 6,
|
|
49
|
+
/** Water fill height as a share from lowest to highest rim elevation. */
|
|
50
|
+
poolFill: 0.4,
|
|
51
|
+
/** Metres the inner edge of a pool's silt bank stands above the water level. */
|
|
52
|
+
bankOver: 0.03,
|
|
53
|
+
/** Concentric `[radiusShare, hex]` rings of a sinkhole mouth from throat to rim. */
|
|
54
|
+
mouth: Object.freeze([
|
|
55
|
+
Object.freeze([0, 0x0b0908]),
|
|
56
|
+
Object.freeze([0.45, 0x14100c]),
|
|
57
|
+
Object.freeze([0.75, 0x3a2e22]),
|
|
58
|
+
Object.freeze([1, 0x7a6449]),
|
|
59
|
+
Object.freeze([1.35, 0xa08868]),
|
|
60
|
+
]),
|
|
61
|
+
/** Concentric `[radiusShare, hex]` rings of standing pool water. */
|
|
62
|
+
water: Object.freeze([Object.freeze([0, 0x1f3029]), Object.freeze([0.6, 0x2c4236]), Object.freeze([0.9, 0x4a5644])]),
|
|
63
|
+
/** Concentric `[radiusShare, hex]` rings of wet-to-dry silt bank around a pool. */
|
|
64
|
+
bank: Object.freeze([Object.freeze([0.82, 0x403829]), Object.freeze([1, 0x655844]), Object.freeze([1.45, 0xa48e70])]),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const STONE = new THREE.IcosahedronGeometry(0.5, 0); // twenty-face pebble for dense near-range scree
|
|
68
|
+
let fallbackShapes = null;
|
|
69
|
+
const defaultShapes = () => (fallbackShapes ??= createUnitShapes());
|
|
70
|
+
|
|
71
|
+
// Sample a point inside `[from, share]` of the hill radius, returning null if inside any cleared circle.
|
|
72
|
+
function spot(hill, random, share, from = 0) {
|
|
73
|
+
const angle = random() * TAU;
|
|
74
|
+
const r = Math.sqrt(from * from + random() * (share * share - from * from)) * hill.r;
|
|
75
|
+
const u = hill.u + Math.cos(angle) * r;
|
|
76
|
+
const v = hill.v + Math.sin(angle) * r;
|
|
77
|
+
return (hill.clear ?? []).some(([cu, cv, cr]) => Math.hypot(u - cu, v - cv) < cr) ? null : [u, v];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Tumbled boulders, stone beams, fallen column drums, and occasional leaning tower remnants across the summit.
|
|
81
|
+
function tumbled(ctx, random, pale) {
|
|
82
|
+
const { hill, Y, rock, stone, solid, shapes, transform, cfg } = ctx;
|
|
83
|
+
for (let i = 0; i < cfg.tumbled; i++) {
|
|
84
|
+
const at = spot(hill, random, cfg.top);
|
|
85
|
+
const pick = random();
|
|
86
|
+
if (!at) continue;
|
|
87
|
+
const [u, v] = at;
|
|
88
|
+
const y = Y(u, v);
|
|
89
|
+
if (pick < 0.5)
|
|
90
|
+
rock.add(
|
|
91
|
+
shapes.rock,
|
|
92
|
+
pale(),
|
|
93
|
+
transform(u, y - 0.2, -v, 1 + random() * 3.4, 0.6 + random() * 1.6, 1 + random() * 2.6, random() * TAU, (random() - 0.5) * 0.5),
|
|
94
|
+
);
|
|
95
|
+
else if (pick < 0.78)
|
|
96
|
+
stone.box(
|
|
97
|
+
u,
|
|
98
|
+
y - 0.6,
|
|
99
|
+
-v,
|
|
100
|
+
0.9 + random() * 0.5,
|
|
101
|
+
1.2 + random() * 3.8,
|
|
102
|
+
2.5 + random() * 7,
|
|
103
|
+
pale(),
|
|
104
|
+
random() * TAU,
|
|
105
|
+
(random() - 0.5) * 0.14,
|
|
106
|
+
(random() - 0.5) * 0.14,
|
|
107
|
+
);
|
|
108
|
+
else if (pick < 0.94)
|
|
109
|
+
stone.add(
|
|
110
|
+
shapes.cyl16,
|
|
111
|
+
pale(),
|
|
112
|
+
transform(u, y + 0.3, -v, 1.1, 0.9 + random() * 2.2, 1.1, random() * TAU, random() < 0.6 ? Math.PI / 2 : (random() - 0.5) * 0.3),
|
|
113
|
+
);
|
|
114
|
+
else {
|
|
115
|
+
const h = 9 + random() * 12;
|
|
116
|
+
const w = 4 + random() * 2.5;
|
|
117
|
+
stone.box(u, y - 2, -v, w, h, w, pale(), random() * TAU, (random() - 0.5) * 0.3, (random() - 0.5) * 0.3);
|
|
118
|
+
solid(u, v, w / 2, w / 2);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Broken wall stumps tracing the rectangular footprints of collapsed summit buildings.
|
|
124
|
+
function rooms(ctx, random, pale) {
|
|
125
|
+
const { hill, Y, stone, solid, cfg } = ctx;
|
|
126
|
+
for (let i = 0; i < cfg.rooms; i++) {
|
|
127
|
+
const at = spot(hill, random, cfg.top * 0.85);
|
|
128
|
+
if (!at) continue;
|
|
129
|
+
const [cu, cv] = at;
|
|
130
|
+
const w = 10 + random() * 16;
|
|
131
|
+
const d = 8 + random() * 14;
|
|
132
|
+
const turn = random() * TAU;
|
|
133
|
+
const c = Math.cos(turn);
|
|
134
|
+
const s = Math.sin(turn);
|
|
135
|
+
const col = pale();
|
|
136
|
+
for (const [x0, z0, x1, z1] of [
|
|
137
|
+
[-w / 2, -d / 2, w / 2, -d / 2],
|
|
138
|
+
[w / 2, -d / 2, w / 2, d / 2],
|
|
139
|
+
[w / 2, d / 2, -w / 2, d / 2],
|
|
140
|
+
[-w / 2, d / 2, -w / 2, -d / 2],
|
|
141
|
+
]) {
|
|
142
|
+
const len = Math.hypot(x1 - x0, z1 - z0);
|
|
143
|
+
const runs = 2 + ((random() * 3) | 0);
|
|
144
|
+
for (let k = 0; k < runs; k++) {
|
|
145
|
+
if (random() < 0.3) continue; // breached gap
|
|
146
|
+
const t0 = (k + random() * 0.25) / runs;
|
|
147
|
+
const t1 = (k + 1 - random() * 0.3) / runs;
|
|
148
|
+
const tm = (t0 + t1) / 2;
|
|
149
|
+
const lx = x0 + (x1 - x0) * tm;
|
|
150
|
+
const lz = z0 + (z1 - z0) * tm;
|
|
151
|
+
const u = cu + lx * c - lz * s;
|
|
152
|
+
const v = cv + lx * s + lz * c;
|
|
153
|
+
const h = 0.6 + random() * random() * 4;
|
|
154
|
+
const ry = turn + Math.atan2(z1 - z0, x1 - x0);
|
|
155
|
+
if (Math.hypot(u - hill.u, v - hill.v) > cfg.top * hill.r) continue;
|
|
156
|
+
stone.box(u, Y(u, v) - 0.6, -v, (t1 - t0) * len + 0.9, h + 0.6, 0.9, col, ry);
|
|
157
|
+
if (h > 1.6) solid(u, v, ((t1 - t0) * len) / 2 + 0.45, 0.45, ry);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Short masonry and brick courses of older buried structures protruding along the slumped hill contours.
|
|
164
|
+
function oldWalls(ctx, random, pale) {
|
|
165
|
+
const { hill, Y, stone, color, cfg } = ctx;
|
|
166
|
+
for (let i = 0; i < cfg.oldWalls; i++) {
|
|
167
|
+
const at = spot(hill, random, 0.98, 0.76);
|
|
168
|
+
if (!at) continue;
|
|
169
|
+
const [u, v] = at;
|
|
170
|
+
const h = 0.8 + random() * 1.8;
|
|
171
|
+
const along = Math.atan2(v - hill.v, u - hill.u) + Math.PI / 2;
|
|
172
|
+
const col = random() < 0.35 ? color(pickR(random, cfg.oldBrick), 0.08, random) : pale();
|
|
173
|
+
stone.box(u, Y(u, v) - h * 0.55, -v, 3 + random() * 8, h, 1.2 + random(), col, along, (random() - 0.5) * 0.1, (random() - 0.5) * 0.1);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Medium boulders and fallen blocks strewn down the flanks of the hill.
|
|
178
|
+
function flank(ctx, random, pale) {
|
|
179
|
+
const { hill, Y, rock, stone, shapes, transform, cfg } = ctx;
|
|
180
|
+
for (let i = 0; i < cfg.flank; i++) {
|
|
181
|
+
const at = spot(hill, random, 1.06, 0.72);
|
|
182
|
+
if (!at) continue;
|
|
183
|
+
const [u, v] = at;
|
|
184
|
+
const y = Y(u, v);
|
|
185
|
+
const size = 0.5 + random() * random() * 2.8;
|
|
186
|
+
if (random() < 0.75)
|
|
187
|
+
rock.add(shapes.rock, pale(), transform(u, y - 0.15, -v, size * 1.3, size * 0.7, size, random() * TAU, (random() - 0.5) * 0.4));
|
|
188
|
+
else
|
|
189
|
+
stone.box(
|
|
190
|
+
u,
|
|
191
|
+
y - 0.4,
|
|
192
|
+
-v,
|
|
193
|
+
0.7 + random() * 0.4,
|
|
194
|
+
0.6 + random() * 0.8,
|
|
195
|
+
1.4 + random() * 2.6,
|
|
196
|
+
pale(),
|
|
197
|
+
random() * TAU,
|
|
198
|
+
(random() - 0.5) * 0.4,
|
|
199
|
+
(random() - 0.5) * 0.4,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Fine near-range scree and brick sherds on the flanks, emitted as a range-culled shadowless order.
|
|
205
|
+
function scree(ctx, random, pale) {
|
|
206
|
+
const { hill, Y, rock, orders, world, Builder, color, transform, cfg } = ctx;
|
|
207
|
+
const small = new Builder();
|
|
208
|
+
small.M = rock.M;
|
|
209
|
+
for (let i = 0; i < cfg.scree; i++) {
|
|
210
|
+
const at = spot(hill, random, 1.12, 0.74);
|
|
211
|
+
if (!at) continue;
|
|
212
|
+
const [u, v] = at;
|
|
213
|
+
const y = Y(u, v);
|
|
214
|
+
const size = 0.16 + random() * random() * 0.75;
|
|
215
|
+
if (random() < 0.68)
|
|
216
|
+
small.add(
|
|
217
|
+
STONE,
|
|
218
|
+
pale(),
|
|
219
|
+
transform(
|
|
220
|
+
u,
|
|
221
|
+
y - size * 0.25,
|
|
222
|
+
-v,
|
|
223
|
+
size * (1 + random() * 0.6),
|
|
224
|
+
size * (0.45 + random() * 0.4),
|
|
225
|
+
size,
|
|
226
|
+
random() * TAU,
|
|
227
|
+
(random() - 0.5) * 0.6,
|
|
228
|
+
),
|
|
229
|
+
);
|
|
230
|
+
else
|
|
231
|
+
small.box(
|
|
232
|
+
u,
|
|
233
|
+
y - size * 0.2,
|
|
234
|
+
-v,
|
|
235
|
+
size * 1.8,
|
|
236
|
+
size * 0.45,
|
|
237
|
+
size * 0.9,
|
|
238
|
+
color(pickR(random, cfg.oldBrick), 0.1, random),
|
|
239
|
+
random() * TAU,
|
|
240
|
+
(random() - 0.5) * 0.5,
|
|
241
|
+
(random() - 0.5) * 0.5,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
const [x, z] = world(hill.u, hill.v);
|
|
245
|
+
orders.push({ mesh: small, mat: 'rock', shadow: false, seen: { x, z, range: hill.r + cfg.screeSeen } });
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Irregular radial factors around a draped hollow, shared across all of its rings.
|
|
249
|
+
function raggedEdge(random, segments, ragged) {
|
|
250
|
+
const out = [];
|
|
251
|
+
for (let k = 0; k < segments; k++) out.push(1 + (random() - 0.5) * 2 * ragged);
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Drape concentric rings over the terrain around `(u, v)` using terrain surface normals so sloped ground does not clip.
|
|
256
|
+
function drape(builder, ctx, u, v, r, edge, rings, heightAt) {
|
|
257
|
+
const { G, color, cfg } = ctx;
|
|
258
|
+
const segments = cfg.segments;
|
|
259
|
+
const tone = rings.map(([share, hex]) => [share, color(hex)]);
|
|
260
|
+
const at = (ring, k) => {
|
|
261
|
+
const a = (k / segments) * TAU;
|
|
262
|
+
const rr = ring[0] * r * edge[k % segments];
|
|
263
|
+
const pu = u + Math.cos(a) * rr;
|
|
264
|
+
const pv = v + Math.sin(a) * rr;
|
|
265
|
+
const dgu = G(pu + 0.5, pv) - G(pu - 0.5, pv);
|
|
266
|
+
const dgv = G(pu, pv + 0.5) - G(pu, pv - 0.5);
|
|
267
|
+
const n = Math.hypot(dgu, 1, dgv);
|
|
268
|
+
return [pu, heightAt(pu, pv), -pv, -dgu / n, 1 / n, dgv / n, ...ring[1]];
|
|
269
|
+
};
|
|
270
|
+
for (let i = 0; i + 1 < tone.length; i++)
|
|
271
|
+
for (let k = 0; k < segments; k++) {
|
|
272
|
+
const a0 = at(tone[i], k);
|
|
273
|
+
const a1 = at(tone[i], k + 1);
|
|
274
|
+
const b0 = at(tone[i + 1], k);
|
|
275
|
+
const b1 = at(tone[i + 1], k + 1);
|
|
276
|
+
if (tone[i][0] > 0) {
|
|
277
|
+
builder.raw(...a0);
|
|
278
|
+
builder.raw(...b1);
|
|
279
|
+
builder.raw(...a1);
|
|
280
|
+
}
|
|
281
|
+
builder.raw(...a0);
|
|
282
|
+
builder.raw(...b0);
|
|
283
|
+
builder.raw(...b1);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Minimum and maximum ground height sampled around a ring of radius `r`.
|
|
288
|
+
function groundSpan(G, u, v, r) {
|
|
289
|
+
let lo = 1e9;
|
|
290
|
+
let hi = -1e9;
|
|
291
|
+
for (let k = 0; k < 8; k++) {
|
|
292
|
+
const g = G(u + Math.cos((k / 8) * TAU) * r, v + Math.sin((k / 8) * TAU) * r);
|
|
293
|
+
lo = Math.min(lo, g);
|
|
294
|
+
hi = Math.max(hi, g);
|
|
295
|
+
}
|
|
296
|
+
return [lo, hi];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Draped dark sinkhole mouth ringed with broken boulders and a blocking collider.
|
|
300
|
+
function sinkhole(ctx, random, pale, ground, u, v) {
|
|
301
|
+
const { Y, G, rock, solid, shapes, transform, cfg } = ctx;
|
|
302
|
+
const r = 1.6 + random() * 1.6;
|
|
303
|
+
drape(ground, ctx, u, v, r, raggedEdge(random, cfg.segments, cfg.ragged), cfg.mouth, (pu, pv) => G(pu, pv) + cfg.lift);
|
|
304
|
+
for (let k = 0; k < 10; k++) {
|
|
305
|
+
const a = (k / 10) * TAU + random() * 0.3;
|
|
306
|
+
const su = u + Math.cos(a) * (r + 0.4);
|
|
307
|
+
const sv = v + Math.sin(a) * (r + 0.4);
|
|
308
|
+
rock.add(
|
|
309
|
+
shapes.rock,
|
|
310
|
+
pale(),
|
|
311
|
+
transform(su, Y(su, sv) - 0.2, -sv, 0.9 + random(), 0.5 + random() * 0.6, 0.8 + random(), random() * TAU, (random() - 0.5) * 0.6),
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
solid(u, v, r, r);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Standing water pool placed in the levellest candidate hollow, rimmed by a silt bank.
|
|
318
|
+
function pool(ctx, random, water, ground) {
|
|
319
|
+
const { hill, G, cfg } = ctx;
|
|
320
|
+
const r = 2 + random() * 3;
|
|
321
|
+
let best = null;
|
|
322
|
+
for (let t = 0; t < cfg.poolTries; t++) {
|
|
323
|
+
const at = spot(hill, random, cfg.top * 0.9);
|
|
324
|
+
if (!at) continue;
|
|
325
|
+
const span = groundSpan(G, at[0], at[1], r);
|
|
326
|
+
if (!best || span[1] - span[0] < best.span[1] - best.span[0]) best = { at, span };
|
|
327
|
+
}
|
|
328
|
+
if (!best) return;
|
|
329
|
+
const [u, v] = best.at;
|
|
330
|
+
const [lo, hi] = best.span;
|
|
331
|
+
const level = lo + (hi - lo) * cfg.poolFill + cfg.lift;
|
|
332
|
+
const edge = raggedEdge(random, cfg.segments, cfg.ragged);
|
|
333
|
+
drape(water, ctx, u, v, r, edge, cfg.water, () => level);
|
|
334
|
+
drape(ground, ctx, u, v, r, edge, cfg.bank, (pu, pv) => {
|
|
335
|
+
const g = G(pu, pv) + cfg.lift;
|
|
336
|
+
return Math.hypot(pu - u, pv - v) < r * 0.99 ? Math.max(g, level + cfg.bankOver) : g;
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Standing pools and sinkholes across the summit, appended as shadowless rock and pool orders.
|
|
341
|
+
function hollows(ctx, random, pale) {
|
|
342
|
+
const { hill, rock, orders, Builder, cfg } = ctx;
|
|
343
|
+
const ground = new Builder();
|
|
344
|
+
const water = new Builder();
|
|
345
|
+
ground.M = water.M = rock.M;
|
|
346
|
+
for (let i = 0; i < cfg.pools; i++) pool(ctx, random, water, ground);
|
|
347
|
+
for (let i = 0; i < cfg.sinkholes; i++) {
|
|
348
|
+
const at = spot(hill, random, cfg.top * 0.9);
|
|
349
|
+
if (at) sinkhole(ctx, random, pale, ground, ...at);
|
|
350
|
+
}
|
|
351
|
+
orders.push({ mesh: ground, mat: 'rock', shadow: false }, { mesh: water, mat: 'pool', shadow: false });
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Populate a ruined hilltop fort, temple or collapsed quarter into a town-frame kit: tumbled masonry,
|
|
356
|
+
* leaning tower remnants, wall-stump room outlines, exposed older flank walls, slid flank boulders,
|
|
357
|
+
* near-range scree, standing pools and sinkholes.
|
|
358
|
+
*
|
|
359
|
+
* @param {object} kit - Town-frame build kit (e.g. from `createCityFortification().cityKit`) supplying
|
|
360
|
+
* `stone` and `rock` builders, `orders` array, `Y(u, v)` surface height, optional `G(u, v)` bare terrain height,
|
|
361
|
+
* optional `solid(u, v, hx, hz, rot?)` collider callback, `hill` (or `p.hill`), and `f.world(u, v)`.
|
|
362
|
+
* @param {() => number} [random=Math.random] - Repeatable random stream in `[0, 1)`.
|
|
363
|
+
* @param {object} [options] - Optional overrides and geometry bindings.
|
|
364
|
+
* @param {{ u: number, v: number, r: number, clear?: number[][] }} [options.hill] - Hill footprint in local `(u, v)` metres (defaults to `kit.hill ?? kit.p.hill`).
|
|
365
|
+
* @param {(u: number, v: number) => [number, number]} [options.world] - Converts local `(u, v)` to world `[x, z]` (defaults to `kit.f.world` or `(u, v) => [u, -v]`).
|
|
366
|
+
* @param {{ rock: import('three').BufferGeometry, cyl16: import('three').BufferGeometry }} [options.shapes] - Unit shapes (`createUnitShapes`).
|
|
367
|
+
* @param {typeof GB} [options.Builder] - Geometry builder constructor (defaults to `GB`).
|
|
368
|
+
* @param {(hex: number, jitter?: number, rng?: () => number) => number[]} [options.color] - Linear RGB colour helper.
|
|
369
|
+
* @param {Function} [options.transform] - Matrix4 transform helper (`TRS`).
|
|
370
|
+
* @param {Partial<typeof HILL_RUIN>} [options.shape] - Overrides to {@link HILL_RUIN}.
|
|
371
|
+
*/
|
|
372
|
+
export function buildHillRuin(kit, random = Math.random, options = {}) {
|
|
373
|
+
const hill = options.hill ?? kit.hill ?? kit.p?.hill;
|
|
374
|
+
if (!hill) return;
|
|
375
|
+
const shapes = options.shapes ?? defaultShapes();
|
|
376
|
+
const Builder = options.Builder ?? GB;
|
|
377
|
+
const color = options.color ?? defaultColor;
|
|
378
|
+
const transform = options.transform ?? defaultTransform;
|
|
379
|
+
const cfg = options.shape ? { ...HILL_RUIN, ...options.shape } : HILL_RUIN;
|
|
380
|
+
const Y = kit.Y ?? (() => 0);
|
|
381
|
+
const G = kit.G ?? Y;
|
|
382
|
+
const solid = kit.solid ?? (() => {});
|
|
383
|
+
const world = options.world ?? (kit.f ? (u, v) => kit.f.world(u, v) : (u, v) => [u, -v]);
|
|
384
|
+
const ctx = { hill, Y, G, rock: kit.rock, stone: kit.stone, solid, orders: kit.orders, world, shapes, Builder, color, transform, cfg };
|
|
385
|
+
const pale = () => color(pickR(random, cfg.pale), 0.08, random);
|
|
386
|
+
tumbled(ctx, random, pale);
|
|
387
|
+
rooms(ctx, random, pale);
|
|
388
|
+
oldWalls(ctx, random, pale);
|
|
389
|
+
flank(ctx, random, pale);
|
|
390
|
+
scree(ctx, random, pale);
|
|
391
|
+
hollows(ctx, random, pale);
|
|
392
|
+
}
|