roamwright 0.61.25 → 0.61.27

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,259 @@
1
+ /**
2
+ * Carried troop standards: instanced pole and flag meshes built per faction/body, tracked into
3
+ * the standard-bearer's posed right fist while standing or riding, and toppled flat onto sloped
4
+ * terrain when the bearer falls.
5
+ * @module
6
+ */
7
+
8
+ import * as THREE from 'three';
9
+ import { placement } from '../geometry/placement.js';
10
+ import { C } from '../geometry/primitives.js';
11
+ import { mulberry32 } from '../math/random.js';
12
+ import { lerp } from '../math/scalar.js';
13
+ import { BEARER_POLE, crowdHold, holdAt } from '../motion/crowd-hold.js';
14
+
15
+ /** Default carried standard dimensions in metres: pole height `h`, flag length `L`, and flag depth `hh`. */
16
+ export const STANDARD_CARRIED = { h: 4.4, L: 1.7, hh: 1.0 };
17
+
18
+ /** Metres the pole extends below the standard's origin foot (`propStandard`). */
19
+ export const STANDARD_BELOW = 0.3;
20
+
21
+ /** Metres from the pole's butt up to the bearer's fist unless ground clearance intervenes. */
22
+ export const STANDARD_GRIP_UP = 1.0;
23
+
24
+ /** Minimum metres above ground for the butt of a pole held low (seated or kneeling bearer). */
25
+ export const STANDARD_CLEAR = 0.02;
26
+
27
+ /** Residual flag fold scale when a dropped standard lies flat on the ground. */
28
+ export const STANDARD_LAID_FLAT = 0.3;
29
+
30
+ const _m = new THREE.Matrix4();
31
+ const _place = placement();
32
+
33
+ function showInstanced(mesh) {
34
+ mesh.visible = mesh.count > 0;
35
+ if (mesh.count) mesh.instanceMatrix.needsUpdate = true;
36
+ }
37
+
38
+ /**
39
+ * Computes the column-major 4x4 transform matrix of an upright standard held in a bearer's fist.
40
+ * Aligns the pole along the grip axis `(h.ax, h.ay, h.az)` through `(h.x, h.y, h.z)` with its
41
+ * flag trailing behind the bearer's facing `yaw`.
42
+ *
43
+ * @param {Float32Array|number[]} e Destination 16-element column-major matrix array.
44
+ * @param {{ x: number, y: number, z: number, ax: number, ay: number, az: number, floor: number }} h Bearer hold record.
45
+ * @param {number} yaw Bearer facing angle in radians.
46
+ * @param {boolean} mounted True when the bearer is mounted on a horse (no ground clamp on pole butt).
47
+ * @param {object} [options]
48
+ * @param {number} [options.below=0.3] Pole length below standard foot (metres).
49
+ * @param {number} [options.gripUp=1.0] Distance from pole butt to fist (metres).
50
+ * @param {number} [options.clear=0.02] Minimum clearance above `h.floor` when on foot (metres).
51
+ * @returns {Float32Array|number[]} The populated `e` array.
52
+ */
53
+ export function poleInFistMatrix(e, h, yaw, mounted, { below = STANDARD_BELOW, gripUp = STANDARD_GRIP_UP, clear = STANDARD_CLEAR } = {}) {
54
+ const ux = h.ax,
55
+ uy = h.ay,
56
+ uz = h.az;
57
+ let gripBelow = gripUp;
58
+ if (!mounted && uy > 0.5) gripBelow = Math.min(gripBelow, Math.max(0, (h.y - h.floor - clear) / uy));
59
+ const foot = below - gripBelow;
60
+ // Behind the bearer, projected perpendicular to the pole axis so the flag trails rearward.
61
+ let bx = -Math.sin(yaw),
62
+ bz = -Math.cos(yaw);
63
+ const along = bx * ux + bz * uz;
64
+ let px = bx - ux * along,
65
+ py = -uy * along,
66
+ pz = bz - uz * along;
67
+ const n = Math.sqrt(px * px + py * py + pz * pz) || 1;
68
+ px /= n;
69
+ py /= n;
70
+ pz /= n;
71
+ bx = py * uz - pz * uy;
72
+ bz = px * uy - py * ux;
73
+ const by = pz * ux - px * uz;
74
+ e[0] = px;
75
+ e[1] = py;
76
+ e[2] = pz;
77
+ e[3] = 0;
78
+ e[4] = ux;
79
+ e[5] = uy;
80
+ e[6] = uz;
81
+ e[7] = 0;
82
+ e[8] = bx;
83
+ e[9] = by;
84
+ e[10] = bz;
85
+ e[11] = 0;
86
+ e[12] = h.x + ux * foot;
87
+ e[13] = h.y + uy * foot;
88
+ e[14] = h.z + uz * foot;
89
+ e[15] = 1;
90
+ return e;
91
+ }
92
+
93
+ /**
94
+ * Computes the column-major 4x4 transform matrix of a standard toppling to the bearer's right and
95
+ * settling along sloped ground as the bearer falls (`fall` in `(0, 1]`).
96
+ *
97
+ * @param {Float32Array|number[]} e Destination 16-element column-major matrix array.
98
+ * @param {{ x: number, y: number, z: number }} h Upright bearer grip position (`holdAt`).
99
+ * @param {{ dir: number, mounted?: boolean }} g Bearer crowd figure record.
100
+ * @param {(x: number, z: number) => number} groundAt Ground height sampler in metres.
101
+ * @param {number} fall Fall progress in `[0, 1]`.
102
+ * @param {object} [options]
103
+ * @param {{ h: number }} [options.carried] Carried standard dimensions (`h` pole height above foot).
104
+ * @param {number} [options.below=0.3] Pole length below standard foot (metres).
105
+ * @param {number} [options.gripUp=1.0] Distance from pole butt to fist while held (metres).
106
+ * @param {number} [options.clear=0.02] Ground clearance of butt while held on foot (metres).
107
+ * @param {number} [options.laidFlat=0.3] Residual flag fold scale once lying flat.
108
+ * @returns {Float32Array|number[]} The populated `e` array.
109
+ */
110
+ export function poleDroppedMatrix(
111
+ e,
112
+ h,
113
+ g,
114
+ groundAt,
115
+ fall,
116
+ {
117
+ carried = STANDARD_CARRIED,
118
+ below = STANDARD_BELOW,
119
+ gripUp = STANDARD_GRIP_UP,
120
+ clear = STANDARD_CLEAR,
121
+ laidFlat = STANDARD_LAID_FLAT,
122
+ } = {},
123
+ ) {
124
+ const c = Math.cos(g.dir),
125
+ d = Math.sin(g.dir),
126
+ long = carried.h + below,
127
+ floor = groundAt(h.x, h.z),
128
+ middle = groundAt(h.x + (c * long) / 2, h.z - (d * long) / 2),
129
+ end = groundAt(h.x + c * long, h.z - d * long),
130
+ over = fall * (Math.PI / 2 - Math.atan2(end - floor, long)),
131
+ s = Math.sin(over),
132
+ k = Math.cos(over),
133
+ flat = lerp(1, laidFlat, fall),
134
+ held = g.mounted ? h.y - gripUp : Math.max(floor + clear, h.y - gripUp),
135
+ butt = lerp(held, Math.max(floor, middle - (end - floor) / 2) + BEARER_POLE, fall);
136
+ // Kit +x points behind the bearer, +y along the pole toppling right, and +z flattens as it lands.
137
+ e[0] = -d;
138
+ e[1] = 0;
139
+ e[2] = -c;
140
+ e[3] = 0;
141
+ e[4] = c * s;
142
+ e[5] = k;
143
+ e[6] = -d * s;
144
+ e[7] = 0;
145
+ e[8] = c * k * flat;
146
+ e[9] = -s * flat;
147
+ e[10] = -d * k * flat;
148
+ e[11] = 0;
149
+ e[12] = h.x + e[4] * below;
150
+ e[13] = butt + e[5] * below;
151
+ e[14] = h.z + e[6] * below;
152
+ e[15] = 1;
153
+ return e;
154
+ }
155
+
156
+ /**
157
+ * Creates a carried troop-standards factory bound to a world's house kit, instanced kit meshes,
158
+ * standard prop builder, frame counter, and faction standard colour lookup.
159
+ *
160
+ * @param {object} config
161
+ * @param {() => object} config.kitNew Creates a new house-kit builder container (`createHouseKit`).
162
+ * @param {Function} config.kitAt Places a prop builder into a house-kit container at a local transform.
163
+ * @param {(kit: object, count: number, parent: THREE.Object3D) => THREE.InstancedMesh[]} config.kitInstanced Builds instanced meshes from a kit (`createHouseKitMeshes`).
164
+ * @param {Function} config.propStandard Standard prop geometry builder (`createProps`).
165
+ * @param {() => number} [config.getFrame] Returns the current render frame index for comparing against `held.frame`.
166
+ * @param {(bodyId: string|undefined, troop: object) => [number, number]|null|undefined} [config.standardOf] Resolves `[fieldHex, edgeHex]` for a troop; defaults to `troop.spec.standard`.
167
+ * @param {{ h: number, L: number, hh: number }} [config.carried] Carried standard pole and flag dimensions (metres).
168
+ * @param {number} [config.below=0.3] Pole length below standard foot (metres).
169
+ * @param {number} [config.gripUp=1.0] Distance from pole butt to fist (metres).
170
+ * @param {number} [config.clear=0.02] Ground clearance of butt when held low (metres).
171
+ * @param {number} [config.laidFlat=0.3] Residual flag fold scale when dropped flat.
172
+ * @param {string} [config.meshName='host-standards'] Name assigned to generated standard meshes.
173
+ * @returns {{ makeStandards: (group: THREE.Object3D, troops: object[]) => { draw: (spaceOrGround: object|Function) => void, bearers: object[], meshes: THREE.InstancedMesh[] } }}
174
+ */
175
+ export function createTroopStandards({
176
+ kitNew,
177
+ kitAt,
178
+ kitInstanced,
179
+ propStandard,
180
+ getFrame = () => 0,
181
+ standardOf = (_bodyId, troop) => troop?.spec?.standard || null,
182
+ carried = STANDARD_CARRIED,
183
+ below = STANDARD_BELOW,
184
+ gripUp = STANDARD_GRIP_UP,
185
+ clear = STANDARD_CLEAR,
186
+ laidFlat = STANDARD_LAID_FLAT,
187
+ meshName = 'host-standards',
188
+ }) {
189
+ const poleOptions = { carried, below, gripUp, clear, laidFlat };
190
+
191
+ function makeStandards(group, troops) {
192
+ const kinds = new Map(),
193
+ all = [],
194
+ bearers = [];
195
+ for (const troop of troops) {
196
+ const id = troop.spec.body,
197
+ flag = standardOf(id, troop);
198
+ if (!flag || troop.spec.beast) continue;
199
+ const key = id ?? `${flag[0]}:${flag[1]}`;
200
+ if (!kinds.has(key)) {
201
+ const kit = kitNew(),
202
+ n = id
203
+ ? troops.filter(t => t.spec.body === id).length
204
+ : troops.filter(t => {
205
+ const f = standardOf(t.spec.body, t);
206
+ return !t.spec.beast && f && (t.spec.body ?? `${f[0]}:${f[1]}`) === key;
207
+ }).length;
208
+ kitAt(
209
+ kit,
210
+ 0,
211
+ 0,
212
+ 0,
213
+ 0,
214
+ false,
215
+ (B, R) => propStandard(B, R, carried.h, carried.L, carried.hh, C(flag[0]), C(flag[1]), 2 * BEARER_POLE),
216
+ mulberry32(n),
217
+ );
218
+ const meshes = kitInstanced(kit, n, group);
219
+ for (const mesh of meshes) mesh.name = meshName;
220
+ kinds.set(key, meshes);
221
+ all.push(...meshes);
222
+ }
223
+ const wide = troop.spec.wide || Math.ceil(Math.sqrt(troop.spec.n * 2)),
224
+ g = troop.list[Math.min(troop.list.length - 1, (wide - 1) >> 1)];
225
+ g.held = crowdHold();
226
+ bearers.push({ meshes: kinds.get(key), g });
227
+ }
228
+ return {
229
+ bearers,
230
+ meshes: all,
231
+ draw(spaceOrGround) {
232
+ const groundAt = typeof spaceOrGround === 'function' ? spaceOrGround : spaceOrGround.ground;
233
+ const frame = getFrame();
234
+ for (let i = 0; i < all.length; i++) all[i].count = 0;
235
+ for (let b = 0; b < bearers.length; b++) {
236
+ const { meshes, g } = bearers[b],
237
+ h = g.held;
238
+ if (g.home === -1) continue;
239
+ const fall = Math.abs(g.fall || 0);
240
+ if (fall || h.frame !== frame) {
241
+ _place.x = g.ax;
242
+ _place.z = g.az;
243
+ _place.y = groundAt(g.ax, g.az) + g.lift;
244
+ _place.s = g.s;
245
+ _place.ry = g.dir;
246
+ _place.rx = 0;
247
+ holdAt(g, _place, false);
248
+ }
249
+ if (fall) poleDroppedMatrix(_m.elements, h, g, groundAt, fall, poleOptions);
250
+ else poleInFistMatrix(_m.elements, h, g.dir, g.mounted, poleOptions);
251
+ for (let i = 0; i < meshes.length; i++) meshes[i].setMatrixAt(meshes[i].count++, _m);
252
+ }
253
+ for (let i = 0; i < all.length; i++) showInstanced(all[i]);
254
+ },
255
+ };
256
+ }
257
+
258
+ return { makeStandards };
259
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Instanced arrow/javelin volley pool bound to `createVolleyState`, warming its shader
3
+ * asynchronously before drawing and firing optional impact-dust and launch-foley callbacks
4
+ * with zero per-frame allocations.
5
+ * @module
6
+ */
7
+
8
+ import * as THREE from 'three';
9
+ import { geometryView } from '../geometry/builder.js';
10
+ import { TRS } from '../geometry/primitives.js';
11
+ import { TROOP_VOLLEY_DEFAULTS, createVolleyState } from '../motion/troop-volleys.js';
12
+
13
+ const _shaftColor = new THREE.Color(0xcab58a);
14
+ const _darkShaftColor = new THREE.Color(0x9a8260);
15
+ const VOLLEY_IMPACT_DIST2 = 115 * 115;
16
+
17
+ /**
18
+ * Builds an instanced arrow/javelin volley pool bound to `createVolleyState`.
19
+ *
20
+ * @param {object} config
21
+ * @param {THREE.Object3D} config.group Parent group receiving the instanced volley mesh.
22
+ * @param {() => THREE.Material} [config.material] Tinted material factory for volley shafts.
23
+ * @param {(mesh: THREE.Object3D) => Promise<void>} [config.warmShaders] Async shader warmer.
24
+ * @param {(x: number, y: number, z: number, radius: number, nearOnly?: boolean, casts?: boolean) => boolean} [config.inView] Frustum visibility check.
25
+ * @param {{ position: { x: number, z: number } }} [config.camera] Camera for impact-dust distance gating.
26
+ * @param {() => number} [config.getFxShare] Returns `[0, 1]` particle-effect budget share.
27
+ * @param {((x: number, y: number, z: number, count: number, size: number, speed: number) => void)|null} [config.onDust] Optional dust puff callback.
28
+ * @param {((x: number, y: number, z: number, count: number) => void)|null} [config.onVolley] Optional volley audio callback.
29
+ * @param {number} [config.pool=96] Maximum simultaneous projectiles.
30
+ * @param {number} [config.gravity=16.5] Arc gravity (m/s^2).
31
+ * @param {number} [config.speed=24] Nominal horizontal flight speed (m/s).
32
+ * @param {number} [config.stick=1.6] Seconds a landed shaft stays visible.
33
+ * @param {number} [config.saddle=1.2] Mounted shooter height offset (metres).
34
+ * @param {number} [config.unseen=-1] Hidden `home` sentinel.
35
+ * @param {string} [config.meshName='host-volleys'] Mesh name assigned to the instanced volley pool.
36
+ * @returns {{ mesh: THREE.InstancedMesh, reset: () => void, launch: Function, draw: Function }}
37
+ */
38
+ export function createTroopVolleys({
39
+ group,
40
+ material = () => new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.9 }),
41
+ warmShaders = () => Promise.resolve(),
42
+ inView = () => true,
43
+ camera = { position: { x: 0, z: 0 } },
44
+ getFxShare = () => 1,
45
+ onDust = null,
46
+ onVolley = null,
47
+ pool = TROOP_VOLLEY_DEFAULTS.pool,
48
+ gravity = TROOP_VOLLEY_DEFAULTS.gravity,
49
+ speed = TROOP_VOLLEY_DEFAULTS.speed,
50
+ stick = TROOP_VOLLEY_DEFAULTS.stick,
51
+ saddle = 1.2,
52
+ unseen = -1,
53
+ meshName = 'host-volleys',
54
+ }) {
55
+ const shaft = new THREE.CylinderGeometry(0.02, 0.026, 1.32, 4);
56
+ const posAttr = shaft.attributes.position;
57
+ // Orient along +Z (flight axis) with dark steel tip, weathered shaft, and pale fletching.
58
+ shaft.rotateX(Math.PI / 2);
59
+ const colors = new Float32Array(posAttr.count * 3);
60
+ for (let i = 0; i < posAttr.count; i++) {
61
+ const z = posAttr.getZ(i);
62
+ if (z > 0.45) {
63
+ colors[i * 3] = 0.25;
64
+ colors[i * 3 + 1] = 0.27;
65
+ colors[i * 3 + 2] = 0.3;
66
+ } else if (z < -0.35) {
67
+ colors[i * 3] = 0.98;
68
+ colors[i * 3 + 1] = 0.95;
69
+ colors[i * 3 + 2] = 0.88;
70
+ } else {
71
+ colors[i * 3] = 0.32;
72
+ colors[i * 3 + 1] = 0.24;
73
+ colors[i * 3 + 2] = 0.16;
74
+ }
75
+ }
76
+ shaft.setAttribute('color', new THREE.BufferAttribute(colors, 3));
77
+ const mesh = new THREE.InstancedMesh(geometryView(shaft), material(), pool);
78
+ mesh.name = meshName;
79
+ mesh.frustumCulled = false;
80
+ mesh.castShadow = false;
81
+ mesh.receiveShadow = false;
82
+ mesh.count = 0;
83
+ mesh.visible = false;
84
+ mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
85
+ mesh.setColorAt(0, _shaftColor);
86
+ mesh.instanceColor.setUsage(THREE.DynamicDrawUsage);
87
+ group.add(mesh);
88
+
89
+ let ready = false;
90
+ warmShaders(mesh).then(() => (ready = true));
91
+
92
+ const state = createVolleyState({ pool, gravity, speed, stick, saddle, unseen });
93
+ let curGround = null,
94
+ curCamX = 0,
95
+ curCamZ = 0;
96
+
97
+ function handleImpact(i, x, _y, z) {
98
+ if ((i & 3) === 0 && getFxShare() > 0 && onDust) {
99
+ const d2 = (x - curCamX) * (x - curCamX) + (z - curCamZ) * (z - curCamZ);
100
+ if (d2 < VOLLEY_IMPACT_DIST2) onDust(x, curGround(x, z) + 0.08, z, 1, 0.55, 0.65);
101
+ }
102
+ }
103
+
104
+ function handleDraw(i, px, py, pz, yaw, pitch) {
105
+ if (!inView(px, py, pz, 1.2, false, false)) return;
106
+ mesh.setMatrixAt(mesh.count, TRS(px, py, pz, 1, 1, 1, yaw, pitch, 0));
107
+ mesh.setColorAt(mesh.count++, (i & 1) === 0 ? _shaftColor : _darkShaftColor);
108
+ }
109
+
110
+ return {
111
+ mesh,
112
+ reset() {
113
+ state.reset();
114
+ mesh.count = 0;
115
+ mesh.visible = false;
116
+ },
117
+ launch(fromTroop, toTroop, spaceOrGround, t, rng) {
118
+ if (!ready) return;
119
+ const groundAt = typeof spaceOrGround === 'function' ? spaceOrGround : spaceOrGround.ground;
120
+ const res = state.launch(fromTroop, toTroop, groundAt, t, rng);
121
+ if (res.fired > 0 && onVolley) onVolley(res.x, res.y, res.z, res.fired);
122
+ },
123
+ draw(t, spaceOrGround) {
124
+ if (!ready || !state.getLiveCount()) {
125
+ if (mesh.visible) {
126
+ mesh.count = 0;
127
+ mesh.visible = false;
128
+ }
129
+ return;
130
+ }
131
+ mesh.count = 0;
132
+ curGround = typeof spaceOrGround === 'function' ? spaceOrGround : spaceOrGround.ground;
133
+ curCamX = camera.position.x;
134
+ curCamZ = camera.position.z;
135
+ state.sample(t, handleImpact, handleDraw);
136
+ mesh.visible = mesh.count > 0;
137
+ if (mesh.count > 0) {
138
+ mesh.instanceMatrix.needsUpdate = true;
139
+ mesh.instanceColor.needsUpdate = true;
140
+ }
141
+ },
142
+ };
143
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Roamwright's public runtime, interface and pacing helpers, grouped by subsystem. Re-exported whole from `roamwright`.
3
+ * @module
4
+ */
5
+
6
+ // ── Context, math & core geometry ────────────────────────────────────────
7
+ export { createNextTask } from './next-task.js';
8
+
9
+ // ── Terrain & land baking ────────────────────────────────────────────────
10
+ export { createLandBake } from './land-bake.js';
11
+
12
+ // ── Settlements, houses, fortifications & interiors ──────────────────────
13
+ export { createRegionPass } from './region-pass.js';
14
+ export { createRegionPasses } from './region-pass-lay.js';
15
+
16
+ // ── Figures, animals & fliers ────────────────────────────────────────────
17
+ export { createBodyOrders } from './figure-orders.js';
18
+
19
+ // ── Effects, audio, pacing & runtime ─────────────────────────────────────
20
+ export { createSiteSchedule } from './effect-sites.js';
21
+ export { createSoundscape } from './soundscape.js';
22
+ export { createStrideFoley } from './foley-strides.js';
23
+ export { createScriptFoley } from './foley-script.js';
24
+ export { createPool } from './pool.js';
25
+ export { createBreather, createLazySets, createSetFrame } from './lazy-sets.js';
26
+ export { describeDevice, readDevice } from './device.js';
27
+ export { choosePostPipeline, createDeviceQuality, groundRenderOrder, resolveDevicePresets } from './device-quality.js';
28
+ export { LEVELS, createQualityStore } from './quality-store.js';
29
+ export { createQualityFit } from './quality-fit.js';
30
+ export { createSteadyFrames } from './steady-frames.js';
31
+ export { createFramePacingMonitor } from './frame-pacing.js';
32
+ export { createPerfWatch, formatLongFrameAttribution, formatLongFrameMessage } from './perf-watch.js';
33
+ export { createPerfBoxState, formatPerfBoxLines } from './perf-box-text.js';
34
+ export { createFrameSampler } from './perf-probe.js';
35
+
36
+ // ── Scene playback, melee, projectiles, beams, props & markers ───────────
37
+ export { applyBurstWear, resolveScenePos, resolveSceneY, stepRidesProp, stepWalksOn } from './scene-script.js';
38
+ export { DEFAULT_ZONE_STRIDE, captionIndexAt, collectSceneZones, prepareSceneZones, resolveSceneAnchor } from './scene-zones.js';
39
+ export { createSurfaceClassifier } from './foley-surface.js';
40
+
41
+ // ── Map kit ──────────────────────────────────────────────────────────────
42
+ export {
43
+ clampViewCenter,
44
+ clusterMapPoints,
45
+ fitMapDimensions,
46
+ frameMapSheet,
47
+ pickMapHit,
48
+ rectUnionOutline,
49
+ sheetMaxZoom,
50
+ sheetMinZoom,
51
+ } from './map-view.js';
52
+ export { COMPASS_WINDS, describeMapSpot, findLandAtAtlas, formatSpotCard, isOnLand, landOffCentre } from './map-spot.js';
53
+ export {
54
+ brokenCoast,
55
+ buildAtlasMarks,
56
+ rangePeaks,
57
+ routeLength,
58
+ routeMidpoint,
59
+ scatterReliefMarks,
60
+ shadeTerrainPixel,
61
+ } from './map-relief.js';
62
+
63
+ // ── Controls, HUD & wayfinding ───────────────────────────────────────────
64
+ export { createStageFrame } from './stage-frame.js';
65
+ export { createWorldControls } from './world-controls.js';
66
+ export { COMPASS_POINTS, compassStripHtml, createCompassStrip } from './compass-strip.js';
67
+ export { createWayBack } from './way-back.js';
68
+ export { createHudFrame, formatDayClock } from './hud-frame.js';
69
+ export { createHudRoom } from './hud-room.js';
70
+ export {
71
+ ARTICLE_LINK,
72
+ collectArticleLinks,
73
+ createArticleCatalog,
74
+ formatArticleText,
75
+ parseArticle,
76
+ plainArticleParagraph,
77
+ } from './articles.js';
78
+ export { createArticlePageRenderer, escapeHtml, renderArticleParagraph } from './article-page.js';
79
+ export { createJourneyStore } from './journey.js';
80
+ export { createSitePages, slugify } from './site-pages.js';
81
+ export {
82
+ COMPASS_CARDINALS,
83
+ DEFAULT_PLACE_KINDS,
84
+ bearingOf,
85
+ createWhereabouts,
86
+ distanceText,
87
+ inSentence,
88
+ roundedDistance,
89
+ } from './whereabouts.js';
90
+ export { createUrlRouter, defaultSlug, normalizeSlash, parseRoutePath } from './url-router.js';
91
+ export { createPanelShell, scrollItemIntoView } from './panel-shell.js';
92
+ export { boxesOverlapOBB, placeLinkLabel, renderRelationGraph } from './relation-graph.js';
93
+ export { lowerQualityLevel, watchContextLost } from './context-lost.js';
94
+ export { extractBuildId, watchBuildFreshness } from './build-freshness.js';
95
+ export { findClearExit, stepDoorwayTrigger } from './doorways.js';
@@ -1,3 +1,4 @@
1
+ import { mulberry32 } from '../math/random.js';
1
2
  import { nextFrame } from './frame-yield.js';
2
3
 
3
4
  /**
@@ -103,3 +104,71 @@ export function createLazySets({ build, unfetched: tellUnfetched = () => {} }) {
103
104
 
104
105
  return { declare, fetch, raise, raiseWithin, raiseNearest, stands, declared };
105
106
  }
107
+
108
+ /**
109
+ * Creates a local-frame set builder helper anchored at `origin` in `space`: binds a seeded PRNG,
110
+ * kit and optional rock geometry builders, a local ground sampler `Y(x, z)`, collider recording via
111
+ * `block`, kit placement via `build`, and a `finish(group, enter)` finaliser that meshes static
112
+ * geometry and registers colliders. Worker-safe.
113
+ *
114
+ * @param {object} options
115
+ * @param {{ ground: (x: number, z: number) => number, group?: object }} options.space - Host space providing `ground(x, z)` and default `group`.
116
+ * @param {{ x: number, z: number }} options.origin - Local frame world origin in metres.
117
+ * @param {number} [options.seed=0] - Per-set seed offset added to `baseSeed`.
118
+ * @param {number} [options.baseSeed=0] - World seed offset added before seeding `mulberry32`.
119
+ * @param {() => number} [options.random] - Optional pre-seeded PRNG (defaults to `mulberry32(baseSeed + seed)`).
120
+ * @param {() => object} [options.createKit] - Factory for the set's kit builders.
121
+ * @param {(() => { ox?: number, oz?: number, p?: ArrayLike<number> }) | null} [options.createRock=null] - Optional factory for the set's rock geometry builder; receives `ox` and `oz` origin offsets.
122
+ * @param {(kit: object, x: number, y: number, z: number, yaw: number, plain: boolean, parts: Function, rng: () => number) => void} [options.placeKit] - Places `parts` into `kit` at `(x, y, z)`.
123
+ * @param {(kit: object, group: object) => void} [options.meshKit] - Meshes `kit` into `group` on `finish`.
124
+ * @param {(rock: object, group: object) => void} [options.meshRock] - Meshes `rock` into `group` on `finish` when `rock.p.length > 0`.
125
+ * @param {(space: object, solids: object[]) => void} [options.addSolids] - Registers collected colliders on `finish` when `enter` is true.
126
+ * @returns {{
127
+ * O: { x: number, z: number },
128
+ * B: object,
129
+ * rock: object | null,
130
+ * rng: () => number,
131
+ * Y: (x: number, z: number) => number,
132
+ * block: (s: object) => number,
133
+ * build: (parts: Function) => void,
134
+ * solid: object[],
135
+ * finish: (group?: object, enter?: boolean) => void,
136
+ * }}
137
+ */
138
+ export function createSetFrame({
139
+ space,
140
+ origin,
141
+ seed = 0,
142
+ baseSeed = 0,
143
+ random,
144
+ createKit = () => ({}),
145
+ createRock = null,
146
+ placeKit = (kit, _x, _y, _z, _yaw, _plain, parts, rng) => parts(kit, rng),
147
+ meshKit = () => {},
148
+ meshRock = () => {},
149
+ addSolids = () => {},
150
+ }) {
151
+ const B = createKit();
152
+ const rock = createRock ? createRock() : null;
153
+ const rng = random ?? mulberry32(baseSeed + seed);
154
+ const solid = [];
155
+ if (rock) {
156
+ rock.ox = origin.x;
157
+ rock.oz = origin.z;
158
+ }
159
+ return {
160
+ O: origin,
161
+ B,
162
+ rock,
163
+ rng,
164
+ Y: (x, z) => space.ground(origin.x + x, origin.z + z),
165
+ block: s => solid.push({ ...s, x: origin.x + s.x, z: origin.z + s.z }),
166
+ build: parts => placeKit(B, origin.x, 0, origin.z, 0, false, parts, rng),
167
+ solid,
168
+ finish(group = space.group, enter = true) {
169
+ meshKit(B, group);
170
+ if (rock?.p?.length) meshRock(rock, group);
171
+ if (enter) addSolids(space, solid);
172
+ },
173
+ };
174
+ }