@voluma/vlam 0.3.2 → 0.3.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voluma/vlam",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "VLAM! - A lightweight WebGPU Gaussian splat viewer for three.js, built for high performance, streaming LOD, and fully customizable rendering through an open shader pipeline.",
5
5
  "license": "MIT",
6
6
  "author": "Voluma",
@@ -1,383 +0,0 @@
1
- var G = Object.defineProperty;
2
- var M = (p, s, i) => s in p ? G(p, s, { enumerable: !0, configurable: !0, writable: !0, value: i }) : p[s] = i;
3
- var h = (p, s, i) => M(p, typeof s != "symbol" ? s + "" : s, i);
4
- import * as S from "three/webgpu";
5
- function P(p) {
6
- return `${p.file}:${p.level}:${p.offset}:${p.count}`;
7
- }
8
- const L = -1, y = 128e3, w = 0.1, T = 500, R = 0.1, D = 3;
9
- class N {
10
- constructor(s, i) {
11
- /** World-unit distance inside which the finest level (0) is used. */
12
- h(this, "lodBaseDistance");
13
- /** Distance ratio between successive LOD levels. */
14
- h(this, "lodMultiplier");
15
- /** Maximum active splats; the desired set is demoted to fit. */
16
- h(this, "budget");
17
- h(this, "leaves");
18
- h(this, "coarsest");
19
- /** Per leaf: lowest/highest LOD level that has data. */
20
- h(this, "minLevel");
21
- h(this, "maxLevel");
22
- /**
23
- * Per leaf: the distance *ambition* - the finest level the camera distance
24
- * asks for, with hysteresis/dwell applied. This is the hysteresis *state*:
25
- * only {@link selectLevels} writes it, so budget demotion can never feed
26
- * back into the dead-band/dwell logic and oscillate. With `fillPastDistance`
27
- * false, {@link fillBudget} restores {@link resolved} only up to here.
28
- */
29
- h(this, "level");
30
- /**
31
- * Per leaf: the resolved target - the ambition capped to fit the budget by
32
- * {@link enforceBudget}, then refilled from leftover headroom by
33
- * {@link fillBudget} (or DROPPED). This is what {@link coalesceRuns} emits.
34
- */
35
- h(this, "resolved");
36
- /** Per leaf: timestamp of the last distance-level change, for dwell. */
37
- h(this, "changedAt");
38
- h(this, "distance");
39
- h(this, "inFrustum");
40
- /** Leaves that must move through the budget cut together. */
41
- h(this, "budgetGroups");
42
- /** Per-leaf physical coverage group, when the manifest defines one. */
43
- h(this, "coverageGroups");
44
- /** Whether view-frustum membership affects distance and fill priority. */
45
- h(this, "frustumAware");
46
- /** Fraction of the usable budget that optional refinement may consume. */
47
- h(this, "budgetFillFraction");
48
- /** Absolute cap on optional refinement; distance-selected detail may exceed it. */
49
- h(this, "budgetFillCap");
50
- /** Whether a budget that holds every finest leaf forces a full-finest cut. */
51
- h(this, "forceFinestWhenFits");
52
- /**
53
- * Leaves at or inside this camera distance always resolve to their finest
54
- * available level (no hysteresis climb). Classic LCC uses a multi-band
55
- * radius so adjacent broad cells do not paint coarse discs at startup.
56
- */
57
- h(this, "forceFinestWithin");
58
- /**
59
- * When false, {@link fillBudget} only restores toward each leaf's
60
- * distance-selected {@link level} - never finer. Classic LCC sets this so
61
- * a mid-range cell does not fetch L0 only to demote to L1 once the cut
62
- * settles.
63
- */
64
- h(this, "fillPastDistance");
65
- /**
66
- * What the last cut actually decided, for the HUD.
67
- *
68
- * The resident splat count alone cannot distinguish "the scheduler asked for
69
- * this" from "the scheduler asked for more and the mesh could not apply it",
70
- * and those have opposite fixes. Measured rather than inferred after a
71
- * zoomed-out `sandwijck` sat at exactly its coarsest total (190,730) with a
72
- * 600k budget - 68% of the budget unspent, with no way to see which stage
73
- * declined to spend it.
74
- */
75
- h(this, "stats", {
76
- /** Leaves the frustum test accepted - `fillBudget`'s candidate set. */
77
- inFrustum: 0,
78
- /** Total leaves in the tree. */
79
- leaves: 0,
80
- /** Splats implied by the resolved cut, before the mesh applies anything. */
81
- desired: 0,
82
- /** Splats `fillBudget` added on top of the distance-chosen levels. */
83
- filled: 0
84
- });
85
- h(this, "scratchBox", new S.Box3());
86
- h(this, "scratchSize", new S.Vector3());
87
- h(this, "scratchCenter", new S.Vector3());
88
- h(this, "screenImportance");
89
- /** Whether the last selection pass received a camera-forward vector. */
90
- h(this, "hasScreenImportance", !1);
91
- /**
92
- * Persistent leaf-index ordering scratch for {@link enforceBudget} and
93
- * {@link fillBudget}, sorted in place per call instead of allocating a
94
- * fresh `[...keys]` array. Comparators break ties on the index itself so
95
- * the order is identical to the stable `Array#sort` this replaces
96
- * (`TypedArray#sort` stability is not guaranteed).
97
- */
98
- h(this, "orderScratch");
99
- if (this.leaves = s.leaves, this.coarsest = s.lodLevels - 1, this.budget = i.budget, this.lodBaseDistance = i.lodBaseDistance, this.lodMultiplier = i.lodMultiplier, this.frustumAware = i.frustumAware !== !1, this.budgetFillFraction = i.budgetFillFraction ?? 0.9, this.budgetFillCap = i.budgetFillCap ?? Number.POSITIVE_INFINITY, this.forceFinestWhenFits = i.forceFinestWhenFits !== !1, this.forceFinestWithin = i.forceFinestWithin, this.fillPastDistance = i.fillPastDistance !== !1, this.budgetFillFraction <= 0 || this.budgetFillFraction > 1)
100
- throw new RangeError("LodScheduler budgetFillFraction must be in (0, 1].");
101
- if (!(this.budgetFillCap > 0))
102
- throw new RangeError("LodScheduler budgetFillCap must be positive.");
103
- if (this.forceFinestWithin !== void 0 && !(this.forceFinestWithin >= 0))
104
- throw new RangeError("LodScheduler forceFinestWithin must be >= 0.");
105
- const e = this.leaves.length;
106
- this.minLevel = new Int32Array(e), this.maxLevel = new Int32Array(e), this.level = new Int32Array(e).fill(this.coarsest), this.resolved = new Int32Array(e).fill(this.coarsest), this.changedAt = new Float64Array(e), this.distance = new Float64Array(e), this.inFrustum = new Uint8Array(e), this.screenImportance = new Float32Array(e), this.orderScratch = new Uint32Array(e), this.coverageGroups = new Int32Array(e).fill(-1);
107
- const l = [], d = /* @__PURE__ */ new Map();
108
- for (let n = 0; n < e; n++) {
109
- const r = this.leaves[n].budgetGroup;
110
- if (r === void 0) {
111
- l.push([n]);
112
- continue;
113
- }
114
- let t = d.get(r);
115
- t === void 0 && (t = l.length, d.set(r, t), l.push([])), l[t].push(n), this.coverageGroups[n] = r;
116
- }
117
- this.budgetGroups = l.map((n) => Uint32Array.from(n));
118
- for (let n = 0; n < e; n++) {
119
- const r = this.leaves[n].lods;
120
- let t = this.coarsest, a = 0;
121
- for (let o = 0; o < r.length; o++)
122
- r[o] !== void 0 && (t = Math.min(t, o), a = Math.max(a, o));
123
- this.minLevel[n] = t, this.maxLevel[n] = a, this.level[n] = a;
124
- }
125
- }
126
- /**
127
- * Recomputes the desired resident run set for the current camera.
128
- *
129
- * @param cameraLocal - Camera position in the mesh's local space.
130
- * @param frustum - View frustum in the mesh's local space.
131
- * @param now - Monotonic timestamp (ms) for dwell hysteresis.
132
- */
133
- computeDesiredRuns(s, i, e, l) {
134
- if (this.selectLevels(s, i, e, l), this.forceFinestWhenFits && this.budget >= this.finestTotal()) {
135
- for (let n = 0; n < this.leaves.length; n++)
136
- this.resolved[n] = this.minLevel[n];
137
- return this.stats.desired = this.activeTotal(), this.stats.filled = 0, this.coalesceRuns();
138
- }
139
- this.resolved.set(this.level), this.enforceBudget();
140
- const d = this.activeTotal();
141
- return this.fillBudget(), this.stats.desired = this.activeTotal(), this.stats.filled = this.stats.desired - d, this.coalesceRuns();
142
- }
143
- /** Total active splats implied by the current resolved levels. */
144
- activeTotal() {
145
- var i;
146
- let s = 0;
147
- for (let e = 0; e < this.leaves.length; e++) {
148
- const l = this.resolved[e];
149
- l !== L && (s += ((i = this.leaves[e].lods[l]) == null ? void 0 : i.count) ?? 0);
150
- }
151
- return s;
152
- }
153
- /** Splats if every leaf sat at its finest available level (none dropped). */
154
- finestTotal() {
155
- var i;
156
- let s = 0;
157
- for (let e = 0; e < this.leaves.length; e++) {
158
- const l = this.minLevel[e];
159
- s += ((i = this.leaves[e].lods[l]) == null ? void 0 : i.count) ?? 0;
160
- }
161
- return s;
162
- }
163
- selectLevels(s, i, e, l) {
164
- const { lodBaseDistance: d, lodMultiplier: n } = this;
165
- this.hasScreenImportance = l !== void 0;
166
- let r = 0;
167
- this.stats.leaves = this.leaves.length;
168
- for (let t = 0; t < this.leaves.length; t++) {
169
- const a = this.leaves[t], o = a.bounds.distanceToPoint(s);
170
- this.distance[t] = o, this.scratchBox.copy(a.bounds), a.bounds.getSize(this.scratchSize), this.scratchBox.expandByScalar(this.scratchSize.length() * R);
171
- const c = i.intersectsBox(this.scratchBox);
172
- if (this.inFrustum[t] = c ? 1 : 0, c && r++, l) {
173
- a.bounds.getCenter(this.scratchCenter).sub(s);
174
- const f = this.scratchCenter.dot(l), F = Math.max(0, this.scratchCenter.lengthSq() - f * f);
175
- this.screenImportance[t] = f > 0 ? Math.sqrt(F) / Math.max(f, 0.25) : Number.POSITIVE_INFINITY;
176
- } else
177
- this.screenImportance[t] = 0;
178
- const u = this.level[t];
179
- if (this.fillPastDistance && this.forceFinestWithin !== void 0 && o <= this.forceFinestWithin) {
180
- const f = this.minLevel[t];
181
- u !== f && (this.level[t] = f, this.changedAt[t] = e);
182
- continue;
183
- }
184
- const v = !this.frustumAware || c ? o : o * D;
185
- if (!this.fillPastDistance) {
186
- const f = this.distanceBandLevel(t, v, d, n);
187
- if (this.changedAt[t] === 0 && u === this.maxLevel[t]) {
188
- f !== u && (this.level[t] = f, this.changedAt[t] = e);
189
- continue;
190
- }
191
- if (f === u) continue;
192
- const b = this.hysteresisLevel(t, v, d, n, u);
193
- if (b === u) continue;
194
- (b > u || e - this.changedAt[t] >= T) && (this.level[t] = b, this.changedAt[t] = e);
195
- continue;
196
- }
197
- const m = this.hysteresisLevel(t, v, d, n, u);
198
- if (m === u) continue;
199
- (this.changedAt[t] === 0 && u === this.maxLevel[t] || e - this.changedAt[t] >= T) && (this.level[t] = m, this.changedAt[t] = e);
200
- }
201
- this.stats.inFrustum = r;
202
- }
203
- /**
204
- * Pure distance→level band (independent of the leaf's current level), so a
205
- * classic LCC cut never has to dwell through intermediate rungs.
206
- */
207
- distanceBandLevel(s, i, e, l) {
208
- const d = this.minLevel[s], n = this.maxLevel[s];
209
- let r = d;
210
- for (; r < n && i > e * l ** r * (1 + w); ) r++;
211
- return this.resolveAvailable(s, r);
212
- }
213
- /**
214
- * Stable level from distance: coarsen only past `threshold·(1 + margin)`,
215
- * refine only within `threshold·(1 − margin)`. The available-level clamp
216
- * keeps leaves that lack a level on their nearest coarser one.
217
- */
218
- hysteresisLevel(s, i, e, l, d) {
219
- const n = this.minLevel[s], r = this.maxLevel[s];
220
- let t = Math.min(r, Math.max(n, d));
221
- for (; t < r && i > e * l ** t * (1 + w); ) t++;
222
- for (; t > n && i <= e * l ** (t - 1) * (1 - w); ) t--;
223
- return this.resolveAvailable(s, t);
224
- }
225
- resolveAvailable(s, i) {
226
- const e = this.leaves[s].lods;
227
- for (let l = i; l <= this.maxLevel[s]; l++) if (e[l]) return l;
228
- for (let l = i - 1; l >= this.minLevel[s]; l--) if (e[l]) return l;
229
- return this.maxLevel[s];
230
- }
231
- /** Demotes/drops lowest-priority leaves until the total fits the budget. */
232
- enforceBudget() {
233
- var e, l, d;
234
- let s = this.activeTotal();
235
- if (s <= this.budget) return;
236
- const i = this.orderScratch.subarray(0, this.budgetGroups.length);
237
- for (let n = 0; n < i.length; n++) i[n] = n;
238
- i.sort((n, r) => {
239
- const t = this.budgetGroups[n][0], a = this.budgetGroups[r][0];
240
- if (this.frustumAware) {
241
- const o = this.inFrustum[t], c = this.inFrustum[a];
242
- if (o !== c) return o - c;
243
- }
244
- return this.distance[a] - this.distance[t] || t - a;
245
- });
246
- for (const n of i) {
247
- const r = this.budgetGroups[n];
248
- for (; s > this.budget; ) {
249
- let t = 0, a = !1;
250
- for (const o of r) {
251
- const c = this.resolved[o];
252
- if (c >= this.maxLevel[o]) continue;
253
- const u = this.leaves[o].lods, v = this.resolveAvailable(o, c + 1);
254
- v !== c && (t += (((e = u[c]) == null ? void 0 : e.count) ?? 0) - (((l = u[v]) == null ? void 0 : l.count) ?? 0), this.resolved[o] = v, a = !0);
255
- }
256
- if (!a) break;
257
- s -= t;
258
- }
259
- if (s <= this.budget) return;
260
- }
261
- for (const n of i) {
262
- if (s <= this.budget) return;
263
- for (const r of this.budgetGroups[n])
264
- this.resolved[r] !== L && (s -= ((d = this.leaves[r].lods[this.resolved[r]]) == null ? void 0 : d.count) ?? 0, this.resolved[r] = L);
265
- }
266
- }
267
- /**
268
- * Uses leftover budget to restore detail after {@link enforceBudget}
269
- * demoted leaves, nearest first, while the total stays under the fill
270
- * target. By default this may also refine *past* the distance-chosen level
271
- * when headroom remains (octree / page-table streams). With
272
- * {@link fillPastDistance} false (classic LCC), fill never goes finer than
273
- * each leaf's distance-selected level - so a cell at the L1 band does not
274
- * fetch L0 only to demote moments later with the camera still.
275
- */
276
- fillBudget() {
277
- var d, n;
278
- const s = this.forceFinestWhenFits && this.budget >= this.finestTotal() ? this.budget : Math.min(this.budget, this.budgetFillCap) * this.budgetFillFraction;
279
- let i = this.activeTotal();
280
- if (i >= s) return;
281
- let e = 0;
282
- for (let r = 0; r < this.budgetGroups.length; r++) {
283
- const t = this.budgetGroups[r][0];
284
- (!this.frustumAware || this.inFrustum[t] === 1) && this.resolved[t] !== L && (this.orderScratch[e++] = r);
285
- }
286
- const l = this.orderScratch.subarray(0, e);
287
- l.sort((r, t) => {
288
- const a = this.budgetGroups[r][0], o = this.budgetGroups[t][0];
289
- return this.distance[a] - this.distance[o] || a - o;
290
- });
291
- for (const r of l) {
292
- const t = this.budgetGroups[r];
293
- for (; ; ) {
294
- let a = 0, o = !1;
295
- for (const c of t) {
296
- const u = this.resolved[c], v = this.fillPastDistance ? this.minLevel[c] : this.level[c];
297
- if (u <= v) continue;
298
- const m = this.leaves[c];
299
- let g = u - 1;
300
- for (; g > v && !m.lods[g]; ) g--;
301
- g < v || !m.lods[g] || (a += (((d = m.lods[g]) == null ? void 0 : d.count) ?? 0) - (((n = m.lods[u]) == null ? void 0 : n.count) ?? 0), o = !0);
302
- }
303
- if (!o || i + a > s) break;
304
- for (const c of t) {
305
- const u = this.resolved[c], v = this.fillPastDistance ? this.minLevel[c] : this.level[c];
306
- if (u <= v) continue;
307
- const m = this.leaves[c];
308
- let g = u - 1;
309
- for (; g > v && !m.lods[g]; ) g--;
310
- g >= v && m.lods[g] && (this.resolved[c] = g);
311
- }
312
- i += a;
313
- }
314
- }
315
- }
316
- coalesceRuns() {
317
- return this.buildRuns(0, this.leaves.length, (s) => this.resolved[s]);
318
- }
319
- /**
320
- * Runs covering [from, to) at each leaf's coarsest available level - used
321
- * to substitute always-cached coverage while a finer level is fetching.
322
- */
323
- coarsestRunsFor(s, i) {
324
- return this.buildRuns(s, i, (e) => this.maxLevel[e]);
325
- }
326
- /**
327
- * Runs covering [from, to) at `level`, clamped per leaf to an available rung
328
- * (prefer the requested level, else the next coarser, else the next finer).
329
- */
330
- runsAtLevelFor(s, i, e) {
331
- const l = Math.floor(e);
332
- return this.buildRuns(s, i, (d) => this.clampLeafLevel(d, l));
333
- }
334
- /** Prefer `wanted`, else next coarser, else next finer; {@link DROPPED} if none. */
335
- clampLeafLevel(s, i) {
336
- const e = this.leaves[s];
337
- if (e.lods[i]) return i;
338
- for (let l = i + 1; l < e.lods.length; l++)
339
- if (e.lods[l]) return l;
340
- for (let l = i - 1; l >= 0; l--)
341
- if (e.lods[l]) return l;
342
- return L;
343
- }
344
- /** Coalesces leaves [from, to) at `levelOf(leaf)` into contiguous runs. */
345
- buildRuns(s, i, e) {
346
- const l = [];
347
- let d = -1, n = -1, r = 0, t = 0, a = -1, o = -1, c = -1, u = Number.POSITIVE_INFINITY, v = !1, m = Number.POSITIVE_INFINITY;
348
- const g = () => {
349
- t > 0 && l.push({
350
- file: d,
351
- level: n,
352
- offset: r,
353
- count: t,
354
- leafStart: a,
355
- leafEnd: o,
356
- distance: u,
357
- inView: v,
358
- ...this.hasScreenImportance ? { screenImportance: m } : {},
359
- ...c >= 0 ? { coverageGroup: c } : {}
360
- }), t = 0;
361
- };
362
- for (let f = s; f < i; f++) {
363
- const F = e(f);
364
- if (F === L) {
365
- g();
366
- continue;
367
- }
368
- const b = this.leaves[f].lods[F];
369
- if (!b) {
370
- g();
371
- continue;
372
- }
373
- const I = this.coverageGroups[f], A = this.distance[f], x = this.inFrustum[f] === 1;
374
- t > 0 && b.file === d && F === n && I === c && b.offset === r + t && t + b.count <= y ? (t += b.count, o = f + 1, A < u && (u = A), x && (v = !0), m = Math.min(m, this.screenImportance[f])) : (g(), d = b.file, n = F, r = b.offset, t = b.count, a = f, o = f + 1, c = I, u = A, v = x, m = this.screenImportance[f]);
375
- }
376
- return g(), l;
377
- }
378
- }
379
- export {
380
- N as L,
381
- P as r
382
- };
383
- //# sourceMappingURL=lod-scheduler-B0a_uBlv.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lod-scheduler-B0a_uBlv.js","sources":["../src/lib/streaming/lod-scheduler.ts"],"sourcesContent":["import * as THREE from 'three/webgpu';\nimport type { LodLeaf, LodManifest } from './lod-manifest';\nimport type { LodSource } from './lod-source';\n\n/**\n * A contiguous splat range within one chunk file, at one LOD level - the\n * unit the pool activates. Adjacent manifest leaves that resolve to the same\n * `(file, level)` and whose ranges abut are coalesced into one run, so the\n * pool sees a handful of large ranges instead of thousands of tiny leaves.\n */\nexport interface LodRun {\n readonly file: number;\n readonly level: number;\n readonly offset: number;\n readonly count: number;\n /** First manifest-leaf index this run covers. */\n readonly leafStart: number;\n /** One past the last covered leaf index. */\n readonly leafEnd: number;\n /**\n * Physical-coverage identity when several manifest leaves form one region.\n * A classic LCC cell may be split into fetch-sized leaves, but its slices\n * must still swap as one visible unit. Undefined retains interval-based\n * grouping for hierarchical sources.\n */\n readonly coverageGroup?: number;\n /**\n * Camera distance (mesh-local) of the nearest leaf in this run, from the\n * last {@link LodScheduler.computeDesiredRuns} pass. Streamed meshes use it\n * to fetch near detail before far coarse coverage. Absent on sources that\n * do not track per-leaf distance.\n */\n readonly distance?: number;\n /**\n * True when any leaf in this run intersects the view frustum (with the\n * scheduler's edge margin). Used to rank classic-path fetches so in-view\n * detail beats behind-camera work; absent when the source does not track it.\n */\n readonly inView?: boolean;\n /**\n * Fetch-only angular distance from the camera's forward axis. Smaller values\n * are nearer the screen centre. It never affects LOD selection or budget.\n */\n readonly screenImportance?: number;\n}\n\n/** Stable identity of a run, for diffing desired vs. resident sets. */\nexport function runKey(run: LodRun): string {\n return `${run.file}:${run.level}:${run.offset}:${run.count}`;\n}\n\n/** Sentinel level meaning \"this leaf is currently dropped (renders nothing)\". */\nconst DROPPED = -1;\n\n/**\n * Maximum splats in one run. Large contiguous regions are split into several\n * runs so no single pool append (and thus no single frame) does an unbounded\n * amount of copy + upload work. Split runs stay contiguous, so they still\n * upload as one coalesced rectangle.\n */\nconst MAX_RUN_SPLATS = 128_000;\n\n/** Hysteresis dead-band around each LOD distance threshold. */\nconst THRESHOLD_MARGIN = 0.1;\n/** Minimum time a leaf must hold a level before changing again, ms. */\nconst DWELL_MS = 500;\n/** Frustum test margin, as a fraction of each leaf's own size. */\nconst FRUSTUM_MARGIN = 0.1;\n/**\n * Out-of-frustum leaves act this many times farther away instead of being\n * hard-coarsened. Rotating the camera then re-ranks leaves smoothly (and\n * dwell applies), rather than mass-flipping edge leaves every frame -\n * PlayCanvas uses the same behind-camera-penalty idea.\n */\nconst FRUSTUM_PENALTY = 3;\n\n/**\n * Chooses a level of detail per spatial leaf from the camera, keeps the\n * total within a splat budget, and coalesces the result into runs.\n *\n * The scheduler is pure with respect to rendering: it takes a camera\n * position and frustum (both in the mesh's local space) and returns the set\n * of runs that should be resident. It owns only the small amount of state\n * needed for temporal stability (each leaf's current level and when it last\n * changed), so it is straightforward to drive from a test harness.\n *\n * LOD distance model (PlayCanvas-compatible): level 0 is used within\n * `lodBaseDistance`; each successive level covers a band `lodMultiplier`×\n * farther out. By default out-of-frustum leaves act {@link FRUSTUM_PENALTY}×\n * farther away. Formats with broad spatial cells can disable that bias so an\n * orbit does not churn already-refined cells at the frustum edges.\n *\n * The distance model only sets the *floor* and the *priority*: when the\n * distance-chosen set leaves budget unused, {@link fillBudget} promotes\n * in-frustum leaves nearest-first until its configured headroom target is\n * spent (90% by default). Formats can cap that optional refinement and avoid\n * a full-finest cut even when an explicitly large budget could hold it. The\n * budget\n * therefore decides how far refinement reaches - a desktop budget yields\n * full detail even with the whole scene in view, a mobile budget refines\n * only near the camera.\n */\nexport class LodScheduler implements LodSource {\n /** World-unit distance inside which the finest level (0) is used. */\n lodBaseDistance: number;\n /** Distance ratio between successive LOD levels. */\n lodMultiplier: number;\n /** Maximum active splats; the desired set is demoted to fit. */\n budget: number;\n\n private readonly leaves: readonly LodLeaf[];\n private readonly coarsest: number;\n /** Per leaf: lowest/highest LOD level that has data. */\n private readonly minLevel: Int32Array;\n private readonly maxLevel: Int32Array;\n /**\n * Per leaf: the distance *ambition* - the finest level the camera distance\n * asks for, with hysteresis/dwell applied. This is the hysteresis *state*:\n * only {@link selectLevels} writes it, so budget demotion can never feed\n * back into the dead-band/dwell logic and oscillate. With `fillPastDistance`\n * false, {@link fillBudget} restores {@link resolved} only up to here.\n */\n private readonly level: Int32Array;\n /**\n * Per leaf: the resolved target - the ambition capped to fit the budget by\n * {@link enforceBudget}, then refilled from leftover headroom by\n * {@link fillBudget} (or DROPPED). This is what {@link coalesceRuns} emits.\n */\n private readonly resolved: Int32Array;\n /** Per leaf: timestamp of the last distance-level change, for dwell. */\n private readonly changedAt: Float64Array;\n\n private readonly distance: Float64Array;\n private readonly inFrustum: Uint8Array;\n /** Leaves that must move through the budget cut together. */\n private readonly budgetGroups: readonly Uint32Array[];\n /** Per-leaf physical coverage group, when the manifest defines one. */\n private readonly coverageGroups: Int32Array;\n /** Whether view-frustum membership affects distance and fill priority. */\n private readonly frustumAware: boolean;\n /** Fraction of the usable budget that optional refinement may consume. */\n private readonly budgetFillFraction: number;\n /** Absolute cap on optional refinement; distance-selected detail may exceed it. */\n private readonly budgetFillCap: number;\n /** Whether a budget that holds every finest leaf forces a full-finest cut. */\n private readonly forceFinestWhenFits: boolean;\n /**\n * Leaves at or inside this camera distance always resolve to their finest\n * available level (no hysteresis climb). Classic LCC uses a multi-band\n * radius so adjacent broad cells do not paint coarse discs at startup.\n */\n private readonly forceFinestWithin: number | undefined;\n /**\n * When false, {@link fillBudget} only restores toward each leaf's\n * distance-selected {@link level} - never finer. Classic LCC sets this so\n * a mid-range cell does not fetch L0 only to demote to L1 once the cut\n * settles.\n */\n private readonly fillPastDistance: boolean;\n\n /**\n * What the last cut actually decided, for the HUD.\n *\n * The resident splat count alone cannot distinguish \"the scheduler asked for\n * this\" from \"the scheduler asked for more and the mesh could not apply it\",\n * and those have opposite fixes. Measured rather than inferred after a\n * zoomed-out `sandwijck` sat at exactly its coarsest total (190,730) with a\n * 600k budget - 68% of the budget unspent, with no way to see which stage\n * declined to spend it.\n */\n readonly stats = {\n /** Leaves the frustum test accepted - `fillBudget`'s candidate set. */\n inFrustum: 0,\n /** Total leaves in the tree. */\n leaves: 0,\n /** Splats implied by the resolved cut, before the mesh applies anything. */\n desired: 0,\n /** Splats `fillBudget` added on top of the distance-chosen levels. */\n filled: 0,\n };\n\n private readonly scratchBox = new THREE.Box3();\n private readonly scratchSize = new THREE.Vector3();\n private readonly scratchCenter = new THREE.Vector3();\n private readonly screenImportance: Float32Array;\n /** Whether the last selection pass received a camera-forward vector. */\n private hasScreenImportance = false;\n /**\n * Persistent leaf-index ordering scratch for {@link enforceBudget} and\n * {@link fillBudget}, sorted in place per call instead of allocating a\n * fresh `[...keys]` array. Comparators break ties on the index itself so\n * the order is identical to the stable `Array#sort` this replaces\n * (`TypedArray#sort` stability is not guaranteed).\n */\n private readonly orderScratch: Uint32Array;\n\n constructor(\n manifest: LodManifest,\n options: {\n budget: number;\n lodBaseDistance: number;\n lodMultiplier: number;\n frustumAware?: boolean;\n budgetFillFraction?: number;\n budgetFillCap?: number;\n forceFinestWhenFits?: boolean;\n forceFinestWithin?: number;\n /**\n * When false, leftover-budget fill never refines past the distance-\n * selected level (see {@link fillPastDistance}). Default true.\n */\n fillPastDistance?: boolean;\n },\n ) {\n this.leaves = manifest.leaves;\n this.coarsest = manifest.lodLevels - 1;\n this.budget = options.budget;\n this.lodBaseDistance = options.lodBaseDistance;\n this.lodMultiplier = options.lodMultiplier;\n this.frustumAware = options.frustumAware !== false;\n this.budgetFillFraction = options.budgetFillFraction ?? 0.9;\n this.budgetFillCap = options.budgetFillCap ?? Number.POSITIVE_INFINITY;\n this.forceFinestWhenFits = options.forceFinestWhenFits !== false;\n this.forceFinestWithin = options.forceFinestWithin;\n this.fillPastDistance = options.fillPastDistance !== false;\n if (this.budgetFillFraction <= 0 || this.budgetFillFraction > 1) {\n throw new RangeError('LodScheduler budgetFillFraction must be in (0, 1].');\n }\n if (!(this.budgetFillCap > 0)) {\n throw new RangeError('LodScheduler budgetFillCap must be positive.');\n }\n if (this.forceFinestWithin !== undefined && !(this.forceFinestWithin >= 0)) {\n throw new RangeError('LodScheduler forceFinestWithin must be >= 0.');\n }\n\n const n = this.leaves.length;\n this.minLevel = new Int32Array(n);\n this.maxLevel = new Int32Array(n);\n this.level = new Int32Array(n).fill(this.coarsest);\n this.resolved = new Int32Array(n).fill(this.coarsest);\n this.changedAt = new Float64Array(n);\n this.distance = new Float64Array(n);\n this.inFrustum = new Uint8Array(n);\n this.screenImportance = new Float32Array(n);\n this.orderScratch = new Uint32Array(n);\n this.coverageGroups = new Int32Array(n).fill(-1);\n\n const groups: number[][] = [];\n const explicitGroups = new Map<number, number>();\n for (let i = 0; i < n; i++) {\n const key = (this.leaves[i] as LodLeaf).budgetGroup;\n if (key === undefined) {\n groups.push([i]);\n continue;\n }\n let groupIndex = explicitGroups.get(key);\n if (groupIndex === undefined) {\n groupIndex = groups.length;\n explicitGroups.set(key, groupIndex);\n groups.push([]);\n }\n (groups[groupIndex] as number[]).push(i);\n this.coverageGroups[i] = key;\n }\n this.budgetGroups = groups.map((members) => Uint32Array.from(members));\n\n for (let i = 0; i < n; i++) {\n const lods = (this.leaves[i] as LodLeaf).lods;\n let min = this.coarsest;\n let max = 0;\n for (let l = 0; l < lods.length; l++) {\n if (lods[l] === undefined) continue;\n min = Math.min(min, l);\n max = Math.max(max, l);\n }\n this.minLevel[i] = min;\n this.maxLevel[i] = max;\n this.level[i] = max; // start coarse\n }\n }\n\n /**\n * Recomputes the desired resident run set for the current camera.\n *\n * @param cameraLocal - Camera position in the mesh's local space.\n * @param frustum - View frustum in the mesh's local space.\n * @param now - Monotonic timestamp (ms) for dwell hysteresis.\n */\n computeDesiredRuns(\n cameraLocal: THREE.Vector3,\n frustum: THREE.Frustum,\n now: number,\n cameraForward?: THREE.Vector3,\n ): LodRun[] {\n this.selectLevels(cameraLocal, frustum, now, cameraForward);\n // When the budget already holds every leaf's finest level, skip distance /\n // frustum demotion entirely. Otherwise a small rotate marks leaves\n // out-of-frustum (×{@link FRUSTUM_PENALTY}), coarsens them, and the mesh\n // aborts fine fetches / swaps to coarse LCC discs - then has to climb\n // back when they re-enter the view.\n if (this.forceFinestWhenFits && this.budget >= this.finestTotal()) {\n for (let i = 0; i < this.leaves.length; i++) {\n this.resolved[i] = this.minLevel[i] as number;\n }\n this.stats.desired = this.activeTotal();\n this.stats.filled = 0;\n return this.coalesceRuns();\n }\n // Copy the ambition into the resolved target, cap it to the budget, then\n // refill leftover headroom. Budget stages touch only `resolved`, never the\n // ambition/hysteresis state - a stationary camera therefore resolves the\n // same cut every pass instead of oscillating red↔orange.\n this.resolved.set(this.level);\n this.enforceBudget();\n const beforeFill = this.activeTotal();\n this.fillBudget();\n this.stats.desired = this.activeTotal();\n this.stats.filled = this.stats.desired - beforeFill;\n return this.coalesceRuns();\n }\n\n /** Total active splats implied by the current resolved levels. */\n private activeTotal(): number {\n let total = 0;\n for (let i = 0; i < this.leaves.length; i++) {\n const level = this.resolved[i] as number;\n if (level === DROPPED) continue;\n total += (this.leaves[i] as LodLeaf).lods[level]?.count ?? 0;\n }\n return total;\n }\n\n /** Splats if every leaf sat at its finest available level (none dropped). */\n private finestTotal(): number {\n let total = 0;\n for (let i = 0; i < this.leaves.length; i++) {\n const level = this.minLevel[i] as number;\n total += (this.leaves[i] as LodLeaf).lods[level]?.count ?? 0;\n }\n return total;\n }\n\n private selectLevels(\n cameraLocal: THREE.Vector3,\n frustum: THREE.Frustum,\n now: number,\n cameraForward?: THREE.Vector3,\n ): void {\n const { lodBaseDistance: base, lodMultiplier: m } = this;\n this.hasScreenImportance = cameraForward !== undefined;\n let visibleCount = 0;\n this.stats.leaves = this.leaves.length;\n for (let i = 0; i < this.leaves.length; i++) {\n const leaf = this.leaves[i] as LodLeaf;\n const d = leaf.bounds.distanceToPoint(cameraLocal);\n this.distance[i] = d;\n\n // Widen the box by a fraction of its own size for edge stability.\n this.scratchBox.copy(leaf.bounds);\n leaf.bounds.getSize(this.scratchSize);\n this.scratchBox.expandByScalar(this.scratchSize.length() * FRUSTUM_MARGIN);\n const visible = frustum.intersectsBox(this.scratchBox);\n this.inFrustum[i] = visible ? 1 : 0;\n if (visible) visibleCount++;\n\n // Broad classic-LCC tiles frequently all intersect the frustum, so the\n // boolean above cannot tell the centre of the screen from its edges.\n // This is deliberately fetch metadata only: distance remains the source\n // of truth for the resolved LOD and the budget cut.\n if (cameraForward) {\n leaf.bounds.getCenter(this.scratchCenter).sub(cameraLocal);\n const depth = this.scratchCenter.dot(cameraForward);\n const lateralSquared = Math.max(0, this.scratchCenter.lengthSq() - depth * depth);\n this.screenImportance[i] =\n depth > 0 ? Math.sqrt(lateralSquared) / Math.max(depth, 0.25) : Number.POSITIVE_INFINITY;\n } else {\n this.screenImportance[i] = 0;\n }\n\n const current = this.level[i] as number;\n // Blanket force-finest only when fill may still climb past the distance\n // band (octree / page-table). Classic LCC never uses this path.\n if (\n this.fillPastDistance &&\n this.forceFinestWithin !== undefined &&\n d <= this.forceFinestWithin\n ) {\n const finest = this.minLevel[i] as number;\n if (current !== finest) {\n this.level[i] = finest;\n this.changedAt[i] = now;\n }\n continue;\n }\n\n const effectiveDistance = !this.frustumAware || visible ? d : d * FRUSTUM_PENALTY;\n\n // Classic LCC: the ambition tracks the pure distance band only. Budget\n // demotions live in `resolved`, never here, so they cannot feed back\n // into hysteresis. A cold cell snaps straight to its band (no dwell\n // climb through intermediate LODs); afterward only a band *crossing*\n // moves the ambition - a stationary camera in the same band holds,\n // even if the budget just demoted its resolved level.\n if (!this.fillPastDistance) {\n const band = this.distanceBandLevel(i, effectiveDistance, base, m);\n const coldStart =\n (this.changedAt[i] as number) === 0 && current === (this.maxLevel[i] as number);\n if (coldStart) {\n if (band !== current) {\n this.level[i] = band;\n this.changedAt[i] = now;\n }\n continue;\n }\n if (band === current) continue;\n const proposed = this.hysteresisLevel(i, effectiveDistance, base, m, current);\n if (proposed === current) continue;\n // Coarsen immediately (moving away should not linger over budget);\n // only refinement waits out the dwell window.\n const coarsening = proposed > current;\n if (coarsening || now - (this.changedAt[i] as number) >= DWELL_MS) {\n this.level[i] = proposed;\n this.changedAt[i] = now;\n }\n continue;\n }\n\n const proposed = this.hysteresisLevel(i, effectiveDistance, base, m, current);\n if (proposed === current) continue;\n const coldSnap =\n (this.changedAt[i] as number) === 0 && current === (this.maxLevel[i] as number);\n if (coldSnap || now - (this.changedAt[i] as number) >= DWELL_MS) {\n this.level[i] = proposed;\n this.changedAt[i] = now;\n }\n }\n this.stats.inFrustum = visibleCount;\n }\n\n /**\n * Pure distance→level band (independent of the leaf's current level), so a\n * classic LCC cut never has to dwell through intermediate rungs.\n */\n private distanceBandLevel(index: number, d: number, base: number, m: number): number {\n const min = this.minLevel[index] as number;\n const max = this.maxLevel[index] as number;\n let level = min;\n while (level < max && d > base * m ** level * (1 + THRESHOLD_MARGIN)) level++;\n return this.resolveAvailable(index, level);\n }\n\n /**\n * Stable level from distance: coarsen only past `threshold·(1 + margin)`,\n * refine only within `threshold·(1 − margin)`. The available-level clamp\n * keeps leaves that lack a level on their nearest coarser one.\n */\n private hysteresisLevel(\n index: number,\n d: number,\n base: number,\n m: number,\n current: number,\n ): number {\n const min = this.minLevel[index] as number;\n const max = this.maxLevel[index] as number;\n let level = Math.min(max, Math.max(min, current));\n // threshold(L) = base·m^L is the boundary between level L and L+1.\n while (level < max && d > base * m ** level * (1 + THRESHOLD_MARGIN)) level++;\n while (level > min && d <= base * m ** (level - 1) * (1 - THRESHOLD_MARGIN)) level--;\n // Resolve to the nearest available level (prefer coarser) if this exact\n // one has no data (leaves need not carry every level).\n return this.resolveAvailable(index, level);\n }\n\n private resolveAvailable(index: number, target: number): number {\n const lods = (this.leaves[index] as LodLeaf).lods;\n for (let l = target; l <= (this.maxLevel[index] as number); l++) if (lods[l]) return l;\n for (let l = target - 1; l >= (this.minLevel[index] as number); l--) if (lods[l]) return l;\n return this.maxLevel[index] as number;\n }\n\n /** Demotes/drops lowest-priority leaves until the total fits the budget. */\n private enforceBudget(): void {\n let total = this.activeTotal();\n if (total <= this.budget) return;\n\n // Demote lowest priority first. When frustum-aware: out-of-frustum before\n // in-frustum, then farthest. Classic LCC sets frustumAware false - broad\n // XY cells often sit mostly behind the camera while the user stands in\n // them (d≈0); frustum demotion would coarsen that cell first and let\n // thinner cells ahead keep fine detail (backwards load). Distance only.\n const order = this.orderScratch.subarray(0, this.budgetGroups.length);\n for (let i = 0; i < order.length; i++) order[i] = i;\n order.sort((a, b) => {\n const ia = (this.budgetGroups[a] as Uint32Array)[0] as number;\n const ib = (this.budgetGroups[b] as Uint32Array)[0] as number;\n if (this.frustumAware) {\n const fa = this.inFrustum[ia] as number;\n const fb = this.inFrustum[ib] as number;\n if (fa !== fb) return fa - fb; // out-of-frustum (0) first\n }\n return (this.distance[ib] as number) - (this.distance[ia] as number) || ia - ib;\n });\n\n // Pass 1: coarsen toward the coarsest available level.\n for (const groupIndex of order) {\n const group = this.budgetGroups[groupIndex] as Uint32Array;\n while (total > this.budget) {\n let reduction = 0;\n let changed = false;\n for (const i of group) {\n const current = this.resolved[i] as number;\n if (current >= (this.maxLevel[i] as number)) continue;\n const lods = (this.leaves[i] as LodLeaf).lods;\n const nextLevel = this.resolveAvailable(i, current + 1);\n if (nextLevel === current) continue;\n reduction += (lods[current]?.count ?? 0) - (lods[nextLevel]?.count ?? 0);\n this.resolved[i] = nextLevel;\n changed = true;\n }\n if (!changed) break;\n total -= reduction;\n }\n if (total <= this.budget) return;\n }\n\n // Pass 2 (last resort): drop groups entirely, lowest priority first.\n for (const groupIndex of order) {\n if (total <= this.budget) return;\n for (const i of this.budgetGroups[groupIndex] as Uint32Array) {\n if ((this.resolved[i] as number) === DROPPED) continue;\n total -= (this.leaves[i] as LodLeaf).lods[this.resolved[i] as number]?.count ?? 0;\n this.resolved[i] = DROPPED;\n }\n }\n }\n\n /**\n * Uses leftover budget to restore detail after {@link enforceBudget}\n * demoted leaves, nearest first, while the total stays under the fill\n * target. By default this may also refine *past* the distance-chosen level\n * when headroom remains (octree / page-table streams). With\n * {@link fillPastDistance} false (classic LCC), fill never goes finer than\n * each leaf's distance-selected level - so a cell at the L1 band does not\n * fetch L0 only to demote moments later with the camera still.\n */\n private fillBudget(): void {\n const target =\n this.forceFinestWhenFits && this.budget >= this.finestTotal()\n ? this.budget\n : Math.min(this.budget, this.budgetFillCap) * this.budgetFillFraction;\n let total = this.activeTotal();\n if (total >= target) return;\n\n // Candidate in-frustum groups, nearest first (ties keep manifest order),\n // packed into the front of the shared index scratch.\n let candidateCount = 0;\n for (let groupIndex = 0; groupIndex < this.budgetGroups.length; groupIndex++) {\n const first = (this.budgetGroups[groupIndex] as Uint32Array)[0] as number;\n if (\n (!this.frustumAware || this.inFrustum[first] === 1) &&\n (this.resolved[first] as number) !== DROPPED\n ) {\n this.orderScratch[candidateCount++] = groupIndex;\n }\n }\n const order = this.orderScratch.subarray(0, candidateCount);\n order.sort((a, b) => {\n const ia = (this.budgetGroups[a] as Uint32Array)[0] as number;\n const ib = (this.budgetGroups[b] as Uint32Array)[0] as number;\n return (this.distance[ia] as number) - (this.distance[ib] as number) || ia - ib;\n });\n\n // Nearest groups refine first (up to the distance floor when capped).\n for (const groupIndex of order) {\n const group = this.budgetGroups[groupIndex] as Uint32Array;\n while (true) {\n let growth = 0;\n let canPromote = false;\n for (const i of group) {\n const current = this.resolved[i] as number;\n const floor = this.fillPastDistance\n ? (this.minLevel[i] as number)\n : (this.level[i] as number);\n if (current <= floor) continue;\n const leaf = this.leaves[i] as LodLeaf;\n let finer = current - 1;\n while (finer > floor && !leaf.lods[finer]) finer--;\n if (finer < floor || !leaf.lods[finer]) continue;\n growth += (leaf.lods[finer]?.count ?? 0) - (leaf.lods[current]?.count ?? 0);\n canPromote = true;\n }\n if (!canPromote || total + growth > target) break;\n for (const i of group) {\n const current = this.resolved[i] as number;\n const floor = this.fillPastDistance\n ? (this.minLevel[i] as number)\n : (this.level[i] as number);\n if (current <= floor) continue;\n const leaf = this.leaves[i] as LodLeaf;\n let finer = current - 1;\n while (finer > floor && !leaf.lods[finer]) finer--;\n if (finer >= floor && leaf.lods[finer]) this.resolved[i] = finer;\n }\n total += growth;\n }\n }\n }\n\n private coalesceRuns(): LodRun[] {\n return this.buildRuns(0, this.leaves.length, (i) => this.resolved[i] as number);\n }\n\n /**\n * Runs covering [from, to) at each leaf's coarsest available level - used\n * to substitute always-cached coverage while a finer level is fetching.\n */\n coarsestRunsFor(from: number, to: number): LodRun[] {\n return this.buildRuns(from, to, (i) => this.maxLevel[i] as number);\n }\n\n /**\n * Runs covering [from, to) at `level`, clamped per leaf to an available rung\n * (prefer the requested level, else the next coarser, else the next finer).\n */\n runsAtLevelFor(from: number, to: number, level: number): LodRun[] {\n const wanted = Math.floor(level);\n return this.buildRuns(from, to, (i) => this.clampLeafLevel(i, wanted));\n }\n\n /** Prefer `wanted`, else next coarser, else next finer; {@link DROPPED} if none. */\n private clampLeafLevel(leafIndex: number, wanted: number): number {\n const leaf = this.leaves[leafIndex] as LodLeaf;\n if (leaf.lods[wanted]) return wanted;\n for (let l = wanted + 1; l < leaf.lods.length; l++) {\n if (leaf.lods[l]) return l;\n }\n for (let l = wanted - 1; l >= 0; l--) {\n if (leaf.lods[l]) return l;\n }\n return DROPPED;\n }\n\n /** Coalesces leaves [from, to) at `levelOf(leaf)` into contiguous runs. */\n private buildRuns(from: number, to: number, levelOf: (index: number) => number): LodRun[] {\n const runs: LodRun[] = [];\n let file = -1;\n let level = -1;\n let offset = 0;\n let count = 0;\n let leafStart = -1;\n let leafEnd = -1;\n let coverageGroup = -1;\n let distance = Number.POSITIVE_INFINITY;\n let inView = false;\n let screenImportance = Number.POSITIVE_INFINITY;\n const flush = (): void => {\n if (count > 0) {\n runs.push({\n file,\n level,\n offset,\n count,\n leafStart,\n leafEnd,\n distance,\n inView,\n ...(this.hasScreenImportance ? { screenImportance } : {}),\n ...(coverageGroup >= 0 ? { coverageGroup } : {}),\n });\n }\n count = 0;\n };\n\n for (let i = from; i < to; i++) {\n const l = levelOf(i);\n if (l === DROPPED) {\n flush();\n continue;\n }\n const range = (this.leaves[i] as LodLeaf).lods[l];\n if (!range) {\n flush();\n continue;\n }\n const leafCoverageGroup = this.coverageGroups[i] as number;\n const leafDistance = this.distance[i] as number;\n const leafInView = (this.inFrustum[i] as number) === 1;\n if (\n count > 0 &&\n range.file === file &&\n l === level &&\n leafCoverageGroup === coverageGroup &&\n range.offset === offset + count &&\n count + range.count <= MAX_RUN_SPLATS\n ) {\n count += range.count; // extend the current run\n leafEnd = i + 1;\n if (leafDistance < distance) distance = leafDistance;\n if (leafInView) inView = true;\n screenImportance = Math.min(screenImportance, this.screenImportance[i] as number);\n } else {\n flush();\n file = range.file;\n level = l;\n offset = range.offset;\n count = range.count;\n leafStart = i;\n leafEnd = i + 1;\n coverageGroup = leafCoverageGroup;\n distance = leafDistance;\n inView = leafInView;\n screenImportance = this.screenImportance[i] as number;\n }\n }\n flush();\n return runs;\n }\n}\n"],"names":["runKey","run","DROPPED","MAX_RUN_SPLATS","THRESHOLD_MARGIN","DWELL_MS","FRUSTUM_MARGIN","FRUSTUM_PENALTY","LodScheduler","manifest","options","__publicField","THREE","n","groups","explicitGroups","i","key","groupIndex","members","lods","min","max","l","cameraLocal","frustum","now","cameraForward","beforeFill","total","level","_a","base","m","visibleCount","leaf","d","visible","depth","lateralSquared","current","finest","effectiveDistance","band","proposed","index","target","order","a","b","ia","ib","fa","fb","group","reduction","changed","nextLevel","_b","_c","candidateCount","first","growth","canPromote","floor","finer","from","to","wanted","leafIndex","levelOf","runs","file","offset","count","leafStart","leafEnd","coverageGroup","distance","inView","screenImportance","flush","range","leafCoverageGroup","leafDistance","leafInView"],"mappings":";;;;AA+CO,SAASA,EAAOC,GAAqB;AAC1C,SAAO,GAAGA,EAAI,IAAI,IAAIA,EAAI,KAAK,IAAIA,EAAI,MAAM,IAAIA,EAAI,KAAK;AAC5D;AAGA,MAAMC,IAAU,IAQVC,IAAiB,OAGjBC,IAAmB,KAEnBC,IAAW,KAEXC,IAAiB,KAOjBC,IAAkB;AA4BjB,MAAMC,EAAkC;AAAA,EA8F7C,YACEC,GACAC,GAeA;AA7GF;AAAA,IAAAC,EAAA;AAEA;AAAA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AAEiB,IAAAA,EAAA;AACA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAQA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,EAAA;AAMA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AAEA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AAEA;AAAA,IAAAA,EAAA;AAMA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,EAAA;AAOA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,EAAA;AAYR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,EAAA,eAAQ;AAAA;AAAA,MAEf,WAAW;AAAA;AAAA,MAEX,QAAQ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