@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/README.md +2 -2
- package/dist/core/index.d.ts +1 -1
- package/dist/formats/lcc.js +276 -277
- package/dist/formats/lcc.js.map +1 -1
- package/dist/formats/rad/index.d.ts +1 -1
- package/dist/formats/rad/parse-rad.d.ts +1 -1
- package/dist/formats/rad.js.map +1 -1
- package/dist/lod-scheduler-ChoZyEeq.js +466 -0
- package/dist/lod-scheduler-ChoZyEeq.js.map +1 -0
- package/dist/streaming/lod-scheduler.d.ts +32 -0
- package/dist/streaming/lod-source.d.ts +15 -9
- package/dist/streaming/streamed-splat-mesh.d.ts +38 -22
- package/dist/streaming.js +950 -918
- package/dist/streaming.js.map +1 -1
- package/package.json +1 -1
- package/dist/lod-scheduler-B0a_uBlv.js +0 -383
- package/dist/lod-scheduler-B0a_uBlv.js.map +0 -1
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
var y = Object.defineProperty;
|
|
2
|
+
var G = (F, e, i) => e in F ? y(F, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : F[e] = i;
|
|
3
|
+
var d = (F, e, i) => G(F, typeof e != "symbol" ? e + "" : e, i);
|
|
4
|
+
import * as A from "three/webgpu";
|
|
5
|
+
function M(F) {
|
|
6
|
+
return `${F.file}:${F.level}:${F.offset}:${F.count}`;
|
|
7
|
+
}
|
|
8
|
+
const I = -1, P = 128e3, S = 0.1, w = 500, N = 0.1, B = 3;
|
|
9
|
+
class R {
|
|
10
|
+
constructor(e, i) {
|
|
11
|
+
/** World-unit distance inside which the finest level (0) is used. */
|
|
12
|
+
d(this, "lodBaseDistance");
|
|
13
|
+
/** Distance ratio between successive LOD levels. */
|
|
14
|
+
d(this, "lodMultiplier");
|
|
15
|
+
/** Maximum active splats; the desired set is demoted to fit. */
|
|
16
|
+
d(this, "budget");
|
|
17
|
+
d(this, "leaves");
|
|
18
|
+
d(this, "coarsest");
|
|
19
|
+
/** Per leaf: lowest/highest LOD level that has data. */
|
|
20
|
+
d(this, "minLevel");
|
|
21
|
+
d(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
|
+
d(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
|
+
d(this, "resolved");
|
|
36
|
+
/** Per leaf: timestamp of the last distance-level change, for dwell. */
|
|
37
|
+
d(this, "changedAt");
|
|
38
|
+
d(this, "distance");
|
|
39
|
+
d(this, "inFrustum");
|
|
40
|
+
/** Leaves that must move through the budget cut together. */
|
|
41
|
+
d(this, "budgetGroups");
|
|
42
|
+
/** Per-leaf physical coverage group, when the manifest defines one. */
|
|
43
|
+
d(this, "coverageGroups");
|
|
44
|
+
/** Whether view-frustum membership affects distance and fill priority. */
|
|
45
|
+
d(this, "frustumAware");
|
|
46
|
+
/** Fraction of the usable budget that optional refinement may consume. */
|
|
47
|
+
d(this, "budgetFillFraction");
|
|
48
|
+
/** Absolute cap on optional refinement; distance-selected detail may exceed it. */
|
|
49
|
+
d(this, "budgetFillCap");
|
|
50
|
+
/** Whether a budget that holds every finest leaf forces a full-finest cut. */
|
|
51
|
+
d(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
|
+
d(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
|
+
d(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
|
+
d(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
|
+
d(this, "scratchBox", new A.Box3());
|
|
86
|
+
d(this, "scratchSize", new A.Vector3());
|
|
87
|
+
d(this, "scratchCenter", new A.Vector3());
|
|
88
|
+
d(this, "screenImportance");
|
|
89
|
+
/** Whether the last selection pass received a camera-forward vector. */
|
|
90
|
+
d(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
|
+
d(this, "orderScratch");
|
|
99
|
+
if (this.leaves = e.leaves, this.coarsest = e.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 s = this.leaves.length;
|
|
106
|
+
this.minLevel = new Int32Array(s), this.maxLevel = new Int32Array(s), this.level = new Int32Array(s).fill(this.coarsest), this.resolved = new Int32Array(s).fill(this.coarsest), this.changedAt = new Float64Array(s), this.distance = new Float64Array(s), this.inFrustum = new Uint8Array(s), this.screenImportance = new Float32Array(s), this.orderScratch = new Uint32Array(s), this.coverageGroups = new Int32Array(s).fill(-1);
|
|
107
|
+
const n = [], a = /* @__PURE__ */ new Map();
|
|
108
|
+
for (let l = 0; l < s; l++) {
|
|
109
|
+
const o = this.leaves[l].budgetGroup;
|
|
110
|
+
if (o === void 0) {
|
|
111
|
+
n.push([l]);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
let t = a.get(o);
|
|
115
|
+
t === void 0 && (t = n.length, a.set(o, t), n.push([])), n[t].push(l), this.coverageGroups[l] = o;
|
|
116
|
+
}
|
|
117
|
+
this.budgetGroups = n.map((l) => Uint32Array.from(l));
|
|
118
|
+
for (let l = 0; l < s; l++) {
|
|
119
|
+
const o = this.leaves[l].lods;
|
|
120
|
+
let t = this.coarsest, u = 0;
|
|
121
|
+
for (let r = 0; r < o.length; r++)
|
|
122
|
+
o[r] !== void 0 && (t = Math.min(t, r), u = Math.max(u, r));
|
|
123
|
+
this.minLevel[l] = t, this.maxLevel[l] = u, this.level[l] = u;
|
|
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(e, i, s, n) {
|
|
134
|
+
if (this.selectLevels(e, i, s, n), this.forceFinestWhenFits && this.budget >= this.finestTotal()) {
|
|
135
|
+
for (let l = 0; l < this.leaves.length; l++)
|
|
136
|
+
this.resolved[l] = this.minLevel[l];
|
|
137
|
+
return this.stats.desired = this.activeTotal(), this.stats.filled = 0, this.coalesceRuns();
|
|
138
|
+
}
|
|
139
|
+
this.resolved.set(this.level), this.enforceBudget();
|
|
140
|
+
const a = this.activeTotal();
|
|
141
|
+
return this.fillBudget(), this.stats.desired = this.activeTotal(), this.stats.filled = this.stats.desired - a, this.coalesceRuns();
|
|
142
|
+
}
|
|
143
|
+
/** Total active splats implied by the current resolved levels. */
|
|
144
|
+
activeTotal() {
|
|
145
|
+
var i;
|
|
146
|
+
let e = 0;
|
|
147
|
+
for (let s = 0; s < this.leaves.length; s++) {
|
|
148
|
+
const n = this.resolved[s];
|
|
149
|
+
n !== I && (e += ((i = this.leaves[s].lods[n]) == null ? void 0 : i.count) ?? 0);
|
|
150
|
+
}
|
|
151
|
+
return e;
|
|
152
|
+
}
|
|
153
|
+
/** Splats if every leaf sat at its finest available level (none dropped). */
|
|
154
|
+
finestTotal() {
|
|
155
|
+
var i;
|
|
156
|
+
let e = 0;
|
|
157
|
+
for (let s = 0; s < this.leaves.length; s++) {
|
|
158
|
+
const n = this.minLevel[s];
|
|
159
|
+
e += ((i = this.leaves[s].lods[n]) == null ? void 0 : i.count) ?? 0;
|
|
160
|
+
}
|
|
161
|
+
return e;
|
|
162
|
+
}
|
|
163
|
+
selectLevels(e, i, s, n) {
|
|
164
|
+
const { lodBaseDistance: a, lodMultiplier: l } = this;
|
|
165
|
+
this.hasScreenImportance = n !== void 0;
|
|
166
|
+
let o = 0;
|
|
167
|
+
this.stats.leaves = this.leaves.length;
|
|
168
|
+
for (let t = 0; t < this.leaves.length; t++) {
|
|
169
|
+
const u = this.leaves[t], r = u.bounds.distanceToPoint(e);
|
|
170
|
+
this.distance[t] = r;
|
|
171
|
+
const h = this.leafIntersectsFrustum(i, t);
|
|
172
|
+
if (this.inFrustum[t] = h ? 1 : 0, h && o++, n)
|
|
173
|
+
if (!(r === 0 || this.boxPokesForward(u.bounds, e, n)))
|
|
174
|
+
this.screenImportance[t] = Number.POSITIVE_INFINITY;
|
|
175
|
+
else if (r <= this.lodBaseDistance)
|
|
176
|
+
this.screenImportance[t] = -1 + r / (this.lodBaseDistance + 1);
|
|
177
|
+
else {
|
|
178
|
+
u.bounds.clampPoint(e, this.scratchCenter).sub(e);
|
|
179
|
+
const b = this.scratchCenter.dot(n), p = Math.max(0, this.scratchCenter.lengthSq() - b * b);
|
|
180
|
+
this.screenImportance[t] = b > 0 ? Math.sqrt(p) / Math.max(b, 0.25) : Number.POSITIVE_INFINITY;
|
|
181
|
+
}
|
|
182
|
+
else
|
|
183
|
+
this.screenImportance[t] = 0;
|
|
184
|
+
const c = this.level[t];
|
|
185
|
+
if (this.fillPastDistance && this.forceFinestWithin !== void 0 && r <= this.forceFinestWithin) {
|
|
186
|
+
const m = this.minLevel[t];
|
|
187
|
+
c !== m && (this.level[t] = m, this.changedAt[t] = s);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const f = !this.frustumAware || h ? r : r * B;
|
|
191
|
+
if (!this.fillPastDistance) {
|
|
192
|
+
const m = this.distanceBandLevel(t, f, a, l);
|
|
193
|
+
if (this.changedAt[t] === 0 && c === this.maxLevel[t]) {
|
|
194
|
+
m !== c && (this.level[t] = m, this.changedAt[t] = s);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (m === c) continue;
|
|
198
|
+
const p = this.hysteresisLevel(t, f, a, l, c);
|
|
199
|
+
if (p === c) continue;
|
|
200
|
+
(p > c || s - this.changedAt[t] >= w) && (this.level[t] = p, this.changedAt[t] = s);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const g = this.hysteresisLevel(t, f, a, l, c);
|
|
204
|
+
if (g === c) continue;
|
|
205
|
+
(this.changedAt[t] === 0 && c === this.maxLevel[t] || s - this.changedAt[t] >= w) && (this.level[t] = g, this.changedAt[t] = s);
|
|
206
|
+
}
|
|
207
|
+
this.stats.inFrustum = o;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Pure distance→level band (independent of the leaf's current level), so a
|
|
211
|
+
* classic LCC cut never has to dwell through intermediate rungs.
|
|
212
|
+
*/
|
|
213
|
+
distanceBandLevel(e, i, s, n) {
|
|
214
|
+
const a = this.minLevel[e], l = this.maxLevel[e];
|
|
215
|
+
let o = a;
|
|
216
|
+
for (; o < l && i > s * n ** o * (1 + S); ) o++;
|
|
217
|
+
return this.resolveAvailable(e, o);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Stable level from distance: coarsen only past `threshold·(1 + margin)`,
|
|
221
|
+
* refine only within `threshold·(1 − margin)`. The available-level clamp
|
|
222
|
+
* keeps leaves that lack a level on their nearest coarser one.
|
|
223
|
+
*/
|
|
224
|
+
hysteresisLevel(e, i, s, n, a) {
|
|
225
|
+
const l = this.minLevel[e], o = this.maxLevel[e];
|
|
226
|
+
let t = Math.min(o, Math.max(l, a));
|
|
227
|
+
for (; t < o && i > s * n ** t * (1 + S); ) t++;
|
|
228
|
+
for (; t > l && i <= s * n ** (t - 1) * (1 - S); ) t--;
|
|
229
|
+
return this.resolveAvailable(e, t);
|
|
230
|
+
}
|
|
231
|
+
resolveAvailable(e, i) {
|
|
232
|
+
const s = this.leaves[e].lods;
|
|
233
|
+
for (let n = i; n <= this.maxLevel[e]; n++) if (s[n]) return n;
|
|
234
|
+
for (let n = i - 1; n >= this.minLevel[e]; n--) if (s[n]) return n;
|
|
235
|
+
return this.maxLevel[e];
|
|
236
|
+
}
|
|
237
|
+
/** Demotes/drops lowest-priority leaves until the total fits the budget. */
|
|
238
|
+
enforceBudget() {
|
|
239
|
+
var s, n, a;
|
|
240
|
+
let e = this.activeTotal();
|
|
241
|
+
if (e <= this.budget) return;
|
|
242
|
+
const i = this.orderScratch.subarray(0, this.budgetGroups.length);
|
|
243
|
+
for (let l = 0; l < i.length; l++) i[l] = l;
|
|
244
|
+
i.sort((l, o) => {
|
|
245
|
+
const t = this.budgetGroups[l][0], u = this.budgetGroups[o][0];
|
|
246
|
+
if (this.frustumAware) {
|
|
247
|
+
const r = this.inFrustum[t], h = this.inFrustum[u];
|
|
248
|
+
if (r !== h) return r - h;
|
|
249
|
+
}
|
|
250
|
+
return this.distance[u] - this.distance[t] || t - u;
|
|
251
|
+
});
|
|
252
|
+
for (const l of i) {
|
|
253
|
+
const o = this.budgetGroups[l];
|
|
254
|
+
for (; e > this.budget; ) {
|
|
255
|
+
let t = 0, u = !1;
|
|
256
|
+
for (const r of o) {
|
|
257
|
+
const h = this.resolved[r];
|
|
258
|
+
if (h >= this.maxLevel[r]) continue;
|
|
259
|
+
const c = this.leaves[r].lods, f = this.resolveAvailable(r, h + 1);
|
|
260
|
+
f !== h && (t += (((s = c[h]) == null ? void 0 : s.count) ?? 0) - (((n = c[f]) == null ? void 0 : n.count) ?? 0), this.resolved[r] = f, u = !0);
|
|
261
|
+
}
|
|
262
|
+
if (!u) break;
|
|
263
|
+
e -= t;
|
|
264
|
+
}
|
|
265
|
+
if (e <= this.budget) return;
|
|
266
|
+
}
|
|
267
|
+
for (const l of i) {
|
|
268
|
+
if (e <= this.budget) return;
|
|
269
|
+
for (const o of this.budgetGroups[l])
|
|
270
|
+
this.resolved[o] !== I && (e -= ((a = this.leaves[o].lods[this.resolved[o]]) == null ? void 0 : a.count) ?? 0, this.resolved[o] = I);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Uses leftover budget to restore detail after {@link enforceBudget}
|
|
275
|
+
* demoted leaves, nearest first, while the total stays under the fill
|
|
276
|
+
* target. By default this may also refine *past* the distance-chosen level
|
|
277
|
+
* when headroom remains (octree / page-table streams). With
|
|
278
|
+
* {@link fillPastDistance} false (classic LCC), fill never goes finer than
|
|
279
|
+
* each leaf's distance-selected level - so a cell at the L1 band does not
|
|
280
|
+
* fetch L0 only to demote moments later with the camera still.
|
|
281
|
+
*/
|
|
282
|
+
fillBudget() {
|
|
283
|
+
var a, l;
|
|
284
|
+
const e = this.forceFinestWhenFits && this.budget >= this.finestTotal() ? this.budget : Math.min(this.budget, this.budgetFillCap) * this.budgetFillFraction;
|
|
285
|
+
let i = this.activeTotal();
|
|
286
|
+
if (i >= e) return;
|
|
287
|
+
let s = 0;
|
|
288
|
+
for (let o = 0; o < this.budgetGroups.length; o++) {
|
|
289
|
+
const t = this.budgetGroups[o][0];
|
|
290
|
+
(!this.frustumAware || this.inFrustum[t] === 1) && this.resolved[t] !== I && (this.orderScratch[s++] = o);
|
|
291
|
+
}
|
|
292
|
+
const n = this.orderScratch.subarray(0, s);
|
|
293
|
+
n.sort((o, t) => {
|
|
294
|
+
const u = this.budgetGroups[o][0], r = this.budgetGroups[t][0];
|
|
295
|
+
return this.distance[u] - this.distance[r] || u - r;
|
|
296
|
+
});
|
|
297
|
+
for (const o of n) {
|
|
298
|
+
const t = this.budgetGroups[o];
|
|
299
|
+
for (; ; ) {
|
|
300
|
+
let u = 0, r = !1;
|
|
301
|
+
for (const h of t) {
|
|
302
|
+
const c = this.resolved[h], f = this.fillPastDistance ? this.minLevel[h] : this.level[h];
|
|
303
|
+
if (c <= f) continue;
|
|
304
|
+
const g = this.leaves[h];
|
|
305
|
+
let v = c - 1;
|
|
306
|
+
for (; v > f && !g.lods[v]; ) v--;
|
|
307
|
+
v < f || !g.lods[v] || (u += (((a = g.lods[v]) == null ? void 0 : a.count) ?? 0) - (((l = g.lods[c]) == null ? void 0 : l.count) ?? 0), r = !0);
|
|
308
|
+
}
|
|
309
|
+
if (!r || i + u > e) break;
|
|
310
|
+
for (const h of t) {
|
|
311
|
+
const c = this.resolved[h], f = this.fillPastDistance ? this.minLevel[h] : this.level[h];
|
|
312
|
+
if (c <= f) continue;
|
|
313
|
+
const g = this.leaves[h];
|
|
314
|
+
let v = c - 1;
|
|
315
|
+
for (; v > f && !g.lods[v]; ) v--;
|
|
316
|
+
v >= f && g.lods[v] && (this.resolved[h] = v);
|
|
317
|
+
}
|
|
318
|
+
i += u;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
coalesceRuns() {
|
|
323
|
+
return this.buildRuns(0, this.leaves.length, (e) => this.resolved[e]);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Runs covering [from, to) at each leaf's coarsest available level - used
|
|
327
|
+
* to substitute always-cached coverage while a finer level is fetching.
|
|
328
|
+
*/
|
|
329
|
+
coarsestRunsFor(e, i) {
|
|
330
|
+
return this.buildRuns(e, i, (s) => this.maxLevel[s]);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Covering runs for physical coverage groups currently in the camera frustum
|
|
334
|
+
* (or containing the camera). Classic LCC cells that split into sub-leaves
|
|
335
|
+
* share a group, so one in-view slice holds the whole cell. Leaves without a
|
|
336
|
+
* coverage group (Streamed SOG, the environment tile) are ignored. An empty
|
|
337
|
+
* frustum falls back to the nearest group so a skyward start still paints
|
|
338
|
+
* something.
|
|
339
|
+
*
|
|
340
|
+
* Classic cells tile X/Y and span the full scene Z. An AABB frustum test
|
|
341
|
+
* (especially with {@link FRUSTUM_MARGIN} on that diagonal) then hits the
|
|
342
|
+
* whole grid from any indoor pose. Unpadded intersection plus an AABB vs
|
|
343
|
+
* forward half-space test (support vertex along `cameraForward`) keeps the
|
|
344
|
+
* hold to cells that poke in front of the camera, including a neighbour
|
|
345
|
+
* whose centre sits behind the look. Cells within `lodBaseDistance` that
|
|
346
|
+
* poke forward are held even when the unpadded frustum misses — a 30 m
|
|
347
|
+
* PentHouse column 5 m away can fill the frame while the look is 60° off
|
|
348
|
+
* its face.
|
|
349
|
+
*
|
|
350
|
+
* Nearby groups (`distance ≤ lodBaseDistance · lodMultiplier`) freeze at
|
|
351
|
+
* finest+1 (L1 when L0 exists). Farther in-view groups freeze at coarsest.
|
|
352
|
+
* Startup never waits for L0.
|
|
353
|
+
*/
|
|
354
|
+
coverageRunsFor(e, i, s) {
|
|
355
|
+
const n = this.leaves.length, a = /* @__PURE__ */ new Set();
|
|
356
|
+
let l = -1, o = Number.POSITIVE_INFINITY;
|
|
357
|
+
for (let h = 0; h < n; h++) {
|
|
358
|
+
const c = this.coverageGroups[h];
|
|
359
|
+
if (c < 0) continue;
|
|
360
|
+
const f = this.leaves[h], g = f.bounds.distanceToPoint(e);
|
|
361
|
+
if (g < o && (o = g, l = h), g === 0) {
|
|
362
|
+
a.add(c);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
!(g <= this.lodBaseDistance) && !i.intersectsBox(f.bounds) || s && !this.boxPokesForward(f.bounds, e, s) || a.add(c);
|
|
366
|
+
}
|
|
367
|
+
if (a.size === 0) {
|
|
368
|
+
if (l < 0) return [];
|
|
369
|
+
a.add(this.coverageGroups[l]);
|
|
370
|
+
}
|
|
371
|
+
const t = this.lodBaseDistance * this.lodMultiplier, u = [];
|
|
372
|
+
let r = 0;
|
|
373
|
+
for (; r < n; ) {
|
|
374
|
+
const h = this.coverageGroups[r];
|
|
375
|
+
if (h < 0 || !a.has(h)) {
|
|
376
|
+
r++;
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
let c = r + 1;
|
|
380
|
+
for (; c < n && this.coverageGroups[c] === h; ) c++;
|
|
381
|
+
let f = Number.POSITIVE_INFINITY, g = this.minLevel[r];
|
|
382
|
+
for (let v = r; v < c; v++) {
|
|
383
|
+
const m = this.leaves[v].bounds.distanceToPoint(e);
|
|
384
|
+
m < f && (f = m);
|
|
385
|
+
const b = this.minLevel[v];
|
|
386
|
+
b < g && (g = b);
|
|
387
|
+
}
|
|
388
|
+
f <= t ? u.push(...this.runsAtLevelFor(r, c, g + 1)) : u.push(...this.coarsestRunsFor(r, c)), r = c;
|
|
389
|
+
}
|
|
390
|
+
return u;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* True when any point of `box` sits strictly in front of the camera plane
|
|
394
|
+
* (`origin` + `forward`). Uses the AABB support vertex along `forward`, so a
|
|
395
|
+
* cell that straddles the camera still counts if it pokes into the view.
|
|
396
|
+
*/
|
|
397
|
+
boxPokesForward(e, i, s) {
|
|
398
|
+
const n = s.x >= 0 ? e.max.x : e.min.x, a = s.y >= 0 ? e.max.y : e.min.y, l = s.z >= 0 ? e.max.z : e.min.z;
|
|
399
|
+
return (n - i.x) * s.x + (a - i.y) * s.y + (l - i.z) * s.z > 0;
|
|
400
|
+
}
|
|
401
|
+
/** Leaf AABB expanded by {@link FRUSTUM_MARGIN}, written into scratch. */
|
|
402
|
+
expandLeafBox(e) {
|
|
403
|
+
const i = this.leaves[e];
|
|
404
|
+
return this.scratchBox.copy(i.bounds), i.bounds.getSize(this.scratchSize), this.scratchBox.expandByScalar(this.scratchSize.length() * N), this.scratchBox;
|
|
405
|
+
}
|
|
406
|
+
leafIntersectsFrustum(e, i) {
|
|
407
|
+
return e.intersectsBox(this.expandLeafBox(i));
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Runs covering [from, to) at `level`, clamped per leaf to an available rung
|
|
411
|
+
* (prefer the requested level, else the next coarser, else the next finer).
|
|
412
|
+
*/
|
|
413
|
+
runsAtLevelFor(e, i, s) {
|
|
414
|
+
const n = Math.floor(s);
|
|
415
|
+
return this.buildRuns(e, i, (a) => this.clampLeafLevel(a, n));
|
|
416
|
+
}
|
|
417
|
+
/** Prefer `wanted`, else next coarser, else next finer; {@link DROPPED} if none. */
|
|
418
|
+
clampLeafLevel(e, i) {
|
|
419
|
+
const s = this.leaves[e];
|
|
420
|
+
if (s.lods[i]) return i;
|
|
421
|
+
for (let n = i + 1; n < s.lods.length; n++)
|
|
422
|
+
if (s.lods[n]) return n;
|
|
423
|
+
for (let n = i - 1; n >= 0; n--)
|
|
424
|
+
if (s.lods[n]) return n;
|
|
425
|
+
return I;
|
|
426
|
+
}
|
|
427
|
+
/** Coalesces leaves [from, to) at `levelOf(leaf)` into contiguous runs. */
|
|
428
|
+
buildRuns(e, i, s) {
|
|
429
|
+
const n = [];
|
|
430
|
+
let a = -1, l = -1, o = 0, t = 0, u = -1, r = -1, h = -1, c = Number.POSITIVE_INFINITY, f = !1, g = Number.POSITIVE_INFINITY;
|
|
431
|
+
const v = () => {
|
|
432
|
+
t > 0 && n.push({
|
|
433
|
+
file: a,
|
|
434
|
+
level: l,
|
|
435
|
+
offset: o,
|
|
436
|
+
count: t,
|
|
437
|
+
leafStart: u,
|
|
438
|
+
leafEnd: r,
|
|
439
|
+
distance: c,
|
|
440
|
+
inView: f,
|
|
441
|
+
...this.hasScreenImportance ? { screenImportance: g } : {},
|
|
442
|
+
...h >= 0 ? { coverageGroup: h } : {}
|
|
443
|
+
}), t = 0;
|
|
444
|
+
};
|
|
445
|
+
for (let m = e; m < i; m++) {
|
|
446
|
+
const b = s(m);
|
|
447
|
+
if (b === I) {
|
|
448
|
+
v();
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
const p = this.leaves[m].lods[b];
|
|
452
|
+
if (!p) {
|
|
453
|
+
v();
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
const L = this.coverageGroups[m], x = this.distance[m], T = this.inFrustum[m] === 1;
|
|
457
|
+
t > 0 && p.file === a && b === l && L === h && p.offset === o + t && t + p.count <= P ? (t += p.count, r = m + 1, x < c && (c = x), T && (f = !0), g = Math.min(g, this.screenImportance[m])) : (v(), a = p.file, l = b, o = p.offset, t = p.count, u = m, r = m + 1, h = L, c = x, f = T, g = this.screenImportance[m]);
|
|
458
|
+
}
|
|
459
|
+
return v(), n;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
export {
|
|
463
|
+
R as L,
|
|
464
|
+
M as r
|
|
465
|
+
};
|
|
466
|
+
//# sourceMappingURL=lod-scheduler-ChoZyEeq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lod-scheduler-ChoZyEeq.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 const visible = this.leafIntersectsFrustum(frustum, i);\n this.inFrustum[i] = visible ? 1 : 0;\n if (visible) visibleCount++;\n\n // Fetch-only. Distance still chooses LOD. Near-band cells (inside\n // lodBaseDistance and in front) rank by distance so a 30 m neighbour\n // 5 m away is not starved by a far cell whose centre sits on the look\n // axis. Farther cells keep the closest-point angular metric.\n if (cameraForward) {\n const inFront = d === 0 || this.boxPokesForward(leaf.bounds, cameraLocal, cameraForward);\n if (!inFront) {\n this.screenImportance[i] = Number.POSITIVE_INFINITY;\n } else if (d <= this.lodBaseDistance) {\n this.screenImportance[i] = -1 + d / (this.lodBaseDistance + 1);\n } else {\n leaf.bounds.clampPoint(cameraLocal, 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\n ? Math.sqrt(lateralSquared) / Math.max(depth, 0.25)\n : Number.POSITIVE_INFINITY;\n }\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 * Covering runs for physical coverage groups currently in the camera frustum\n * (or containing the camera). Classic LCC cells that split into sub-leaves\n * share a group, so one in-view slice holds the whole cell. Leaves without a\n * coverage group (Streamed SOG, the environment tile) are ignored. An empty\n * frustum falls back to the nearest group so a skyward start still paints\n * something.\n *\n * Classic cells tile X/Y and span the full scene Z. An AABB frustum test\n * (especially with {@link FRUSTUM_MARGIN} on that diagonal) then hits the\n * whole grid from any indoor pose. Unpadded intersection plus an AABB vs\n * forward half-space test (support vertex along `cameraForward`) keeps the\n * hold to cells that poke in front of the camera, including a neighbour\n * whose centre sits behind the look. Cells within `lodBaseDistance` that\n * poke forward are held even when the unpadded frustum misses — a 30 m\n * PentHouse column 5 m away can fill the frame while the look is 60° off\n * its face.\n *\n * Nearby groups (`distance ≤ lodBaseDistance · lodMultiplier`) freeze at\n * finest+1 (L1 when L0 exists). Farther in-view groups freeze at coarsest.\n * Startup never waits for L0.\n */\n coverageRunsFor(\n cameraLocal: THREE.Vector3,\n frustum: THREE.Frustum,\n cameraForward?: THREE.Vector3,\n ): LodRun[] {\n const n = this.leaves.length;\n const picked = new Set<number>();\n let nearestLeaf = -1;\n let nearestDist = Number.POSITIVE_INFINITY;\n for (let i = 0; i < n; i++) {\n const group = this.coverageGroups[i] as number;\n if (group < 0) continue;\n const leaf = this.leaves[i] as LodLeaf;\n const d = leaf.bounds.distanceToPoint(cameraLocal);\n if (d < nearestDist) {\n nearestDist = d;\n nearestLeaf = i;\n }\n // Camera-inside is load-bearing: HiRes tiles often fail the frustum test\n // when most of the cell sits behind the camera looking out.\n if (d === 0) {\n picked.add(group);\n continue;\n }\n // 30 m classic cells: the camera can stand 5 m from a neighbour that\n // fills the frame while the unpadded frustum misses the AABB (look 60°+\n // off the face). Still hold that neighbour when it pokes forward.\n const near = d <= this.lodBaseDistance;\n if (!near && !frustum.intersectsBox(leaf.bounds)) continue;\n if (cameraForward && !this.boxPokesForward(leaf.bounds, cameraLocal, cameraForward)) {\n continue;\n }\n picked.add(group);\n }\n if (picked.size === 0) {\n if (nearestLeaf < 0) return [];\n picked.add(this.coverageGroups[nearestLeaf] as number);\n }\n const nearHorizon = this.lodBaseDistance * this.lodMultiplier;\n const runs: LodRun[] = [];\n let i = 0;\n while (i < n) {\n const group = this.coverageGroups[i] as number;\n if (group < 0 || !picked.has(group)) {\n i++;\n continue;\n }\n let end = i + 1;\n while (end < n && (this.coverageGroups[end] as number) === group) end++;\n let groupDist = Number.POSITIVE_INFINITY;\n let groupFinest = this.minLevel[i] as number;\n for (let j = i; j < end; j++) {\n const d = (this.leaves[j] as LodLeaf).bounds.distanceToPoint(cameraLocal);\n if (d < groupDist) groupDist = d;\n const finest = this.minLevel[j] as number;\n if (finest < groupFinest) groupFinest = finest;\n }\n if (groupDist <= nearHorizon) {\n runs.push(...this.runsAtLevelFor(i, end, groupFinest + 1));\n } else {\n runs.push(...this.coarsestRunsFor(i, end));\n }\n i = end;\n }\n return runs;\n }\n\n /**\n * True when any point of `box` sits strictly in front of the camera plane\n * (`origin` + `forward`). Uses the AABB support vertex along `forward`, so a\n * cell that straddles the camera still counts if it pokes into the view.\n */\n private boxPokesForward(box: THREE.Box3, origin: THREE.Vector3, forward: THREE.Vector3): boolean {\n const x = forward.x >= 0 ? box.max.x : box.min.x;\n const y = forward.y >= 0 ? box.max.y : box.min.y;\n const z = forward.z >= 0 ? box.max.z : box.min.z;\n return (x - origin.x) * forward.x + (y - origin.y) * forward.y + (z - origin.z) * forward.z > 0;\n }\n\n /** Leaf AABB expanded by {@link FRUSTUM_MARGIN}, written into scratch. */\n private expandLeafBox(index: number): THREE.Box3 {\n const leaf = this.leaves[index] as LodLeaf;\n this.scratchBox.copy(leaf.bounds);\n leaf.bounds.getSize(this.scratchSize);\n this.scratchBox.expandByScalar(this.scratchSize.length() * FRUSTUM_MARGIN);\n return this.scratchBox;\n }\n\n private leafIntersectsFrustum(frustum: THREE.Frustum, index: number): boolean {\n return frustum.intersectsBox(this.expandLeafBox(index));\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","picked","nearestLeaf","nearestDist","nearHorizon","runs","end","groupDist","groupFinest","j","box","origin","forward","x","y","z","wanted","leafIndex","levelOf","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,EA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ACF;AACA,YAAMC,IAAS,KAAK,OAAOhF,CAAC,EAAc,KAAKO,CAAC;AAChD,UAAI,CAACyE,GAAO;AACV,QAAAD,EAAA;AACA;AAAA,MACF;AACA,YAAME,IAAoB,KAAK,eAAejF,CAAC,GACzCkF,IAAe,KAAK,SAASlF,CAAC,GAC9BmF,IAAc,KAAK,UAAUnF,CAAC,MAAiB;AACrD,MACEwE,IAAQ,KACRQ,EAAM,SAASV,KACf/D,MAAMO,KACNmE,MAAsBN,KACtBK,EAAM,WAAWT,IAASC,KAC1BA,IAAQQ,EAAM,SAAS7F,KAEvBqF,KAASQ,EAAM,OACfN,IAAU1E,IAAI,GACVkF,IAAeN,MAAUA,IAAWM,IACpCC,MAAYN,IAAS,KACzBC,IAAmB,KAAK,IAAIA,GAAkB,KAAK,iBAAiB9E,CAAC,CAAW,MAEhF+E,EAAA,GACAT,IAAOU,EAAM,MACblE,IAAQP,GACRgE,IAASS,EAAM,QACfR,IAAQQ,EAAM,OACdP,IAAYzE,GACZ0E,IAAU1E,IAAI,GACd2E,IAAgBM,GAChBL,IAAWM,GACXL,IAASM,GACTL,IAAmB,KAAK,iBAAiB9E,CAAC;AAAA,IAE9C;AACA,WAAA+E,EAAA,GACOvB;AAAA,EACT;AACF;"}
|
|
@@ -217,6 +217,38 @@ export declare class LodScheduler implements LodSource {
|
|
|
217
217
|
* to substitute always-cached coverage while a finer level is fetching.
|
|
218
218
|
*/
|
|
219
219
|
coarsestRunsFor(from: number, to: number): LodRun[];
|
|
220
|
+
/**
|
|
221
|
+
* Covering runs for physical coverage groups currently in the camera frustum
|
|
222
|
+
* (or containing the camera). Classic LCC cells that split into sub-leaves
|
|
223
|
+
* share a group, so one in-view slice holds the whole cell. Leaves without a
|
|
224
|
+
* coverage group (Streamed SOG, the environment tile) are ignored. An empty
|
|
225
|
+
* frustum falls back to the nearest group so a skyward start still paints
|
|
226
|
+
* something.
|
|
227
|
+
*
|
|
228
|
+
* Classic cells tile X/Y and span the full scene Z. An AABB frustum test
|
|
229
|
+
* (especially with {@link FRUSTUM_MARGIN} on that diagonal) then hits the
|
|
230
|
+
* whole grid from any indoor pose. Unpadded intersection plus an AABB vs
|
|
231
|
+
* forward half-space test (support vertex along `cameraForward`) keeps the
|
|
232
|
+
* hold to cells that poke in front of the camera, including a neighbour
|
|
233
|
+
* whose centre sits behind the look. Cells within `lodBaseDistance` that
|
|
234
|
+
* poke forward are held even when the unpadded frustum misses — a 30 m
|
|
235
|
+
* PentHouse column 5 m away can fill the frame while the look is 60° off
|
|
236
|
+
* its face.
|
|
237
|
+
*
|
|
238
|
+
* Nearby groups (`distance ≤ lodBaseDistance · lodMultiplier`) freeze at
|
|
239
|
+
* finest+1 (L1 when L0 exists). Farther in-view groups freeze at coarsest.
|
|
240
|
+
* Startup never waits for L0.
|
|
241
|
+
*/
|
|
242
|
+
coverageRunsFor(cameraLocal: THREE.Vector3, frustum: THREE.Frustum, cameraForward?: THREE.Vector3): LodRun[];
|
|
243
|
+
/**
|
|
244
|
+
* True when any point of `box` sits strictly in front of the camera plane
|
|
245
|
+
* (`origin` + `forward`). Uses the AABB support vertex along `forward`, so a
|
|
246
|
+
* cell that straddles the camera still counts if it pokes into the view.
|
|
247
|
+
*/
|
|
248
|
+
private boxPokesForward;
|
|
249
|
+
/** Leaf AABB expanded by {@link FRUSTUM_MARGIN}, written into scratch. */
|
|
250
|
+
private expandLeafBox;
|
|
251
|
+
private leafIntersectsFrustum;
|
|
220
252
|
/**
|
|
221
253
|
* Runs covering [from, to) at `level`, clamped per leaf to an available rung
|
|
222
254
|
* (prefer the requested level, else the next coarser, else the next finer).
|