@voluma/vlam 0.2.3 → 0.3.0
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 +3 -2
- package/dist/budget-governor.d.ts +4 -4
- package/dist/camera-budget-governor.d.ts +11 -11
- package/dist/chunk-cache-budget.d.ts +5 -5
- package/dist/chunk-fetch-scheduler.d.ts +4 -4
- package/dist/chunk-loader-DlNwggfG.js +1859 -0
- package/dist/chunk-loader-DlNwggfG.js.map +1 -0
- package/dist/chunk-loader.d.ts +2 -2
- package/dist/compute-sorter.d.ts +1 -1
- package/dist/effects.d.ts +26 -16
- package/dist/effects.js +199 -165
- package/dist/effects.js.map +1 -1
- package/dist/formats/ksplat/index.d.ts +1 -1
- package/dist/formats/lcc/collision-mesh.d.ts +2 -2
- package/dist/formats/lcc.js +17 -16
- package/dist/formats/lcc.js.map +1 -1
- package/dist/formats/ply/index.d.ts +1 -1
- package/dist/formats/ply/parse-splat-ply.d.ts +2 -2
- package/dist/formats/ply.js +1 -1
- package/dist/formats/ply.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/rad.d.ts +2 -2
- package/dist/formats/rad.js +3 -3
- package/dist/formats/rad.js.map +1 -1
- package/dist/formats/sog/index.d.ts +1 -1
- package/dist/formats/sog/parse-sog.d.ts +4 -4
- package/dist/formats/sog.js.map +1 -1
- package/dist/formats/splat/index.d.ts +1 -1
- package/dist/formats/spz/index.d.ts +1 -1
- package/dist/index.d.ts +16 -25
- package/dist/index.js +253 -9047
- package/dist/index.js.map +1 -1
- package/dist/{load-scene.d.ts → load-splat-data.d.ts} +15 -13
- package/dist/loaders.d.ts +15 -0
- package/dist/loaders.js +26 -0
- package/dist/loaders.js.map +1 -0
- package/dist/loading-wLo8vRbA.js.map +1 -1
- package/dist/loading.d.ts +8 -8
- package/dist/{splat-mesh-types-CTN_duw2.js → lod-scheduler-B0a_uBlv.js} +133 -140
- package/dist/lod-scheduler-B0a_uBlv.js.map +1 -0
- package/dist/lod-scheduler.d.ts +1 -1
- package/dist/lod-source.d.ts +5 -5
- package/dist/{splat-scene.d.ts → merged-splat-mesh.d.ts} +14 -15
- package/dist/orientation.d.ts +7 -7
- package/dist/{ply-header-BwgExCn-.js → ply-header-B9WllbPg.js} +3 -3
- package/dist/{ply-header-BwgExCn-.js.map → ply-header-B9WllbPg.js.map} +1 -1
- package/dist/radix-sorter-R0FCSqKu.js +178 -0
- package/dist/radix-sorter-R0FCSqKu.js.map +1 -0
- package/dist/relighting-CSQF3UcL.js +969 -0
- package/dist/relighting-CSQF3UcL.js.map +1 -0
- package/dist/relighting.d.ts +1 -1
- package/dist/selection.d.ts +13 -0
- package/dist/selection.js +137 -0
- package/dist/selection.js.map +1 -0
- package/dist/source-transform.d.ts +4 -4
- package/dist/{splat-budget-DXew_86c.js → splat-budget-DuVZspPQ.js} +7 -7
- package/dist/{splat-budget-DXew_86c.js.map → splat-budget-DuVZspPQ.js.map} +1 -1
- package/dist/splat-budget.d.ts +1 -1
- package/dist/splat-data-BZM5dhhx.js.map +1 -1
- package/dist/splat-data.d.ts +4 -4
- package/dist/splat-mesh-aQdcWA6v.js +1942 -0
- package/dist/splat-mesh-aQdcWA6v.js.map +1 -0
- package/dist/splat-mesh-material.d.ts +2 -2
- package/dist/splat-mesh-types-BZIko-_9.js +18 -0
- package/dist/splat-mesh-types-BZIko-_9.js.map +1 -0
- package/dist/splat-mesh-types.d.ts +14 -8
- package/dist/splat-mesh.d.ts +4 -4
- package/dist/splat-modifier.d.ts +5 -5
- package/dist/splat-partition.d.ts +1 -1
- package/dist/static-lod-entry.d.ts +12 -0
- package/dist/static-lod-splat-mesh.d.ts +2 -2
- package/dist/{static-lod-worker-D2fyqQZO.js → static-lod-worker-DktKnJkR.js} +46 -46
- package/dist/{static-lod-worker-D2fyqQZO.js.map → static-lod-worker-DktKnJkR.js.map} +1 -1
- package/dist/static-lod.js +148 -0
- package/dist/static-lod.js.map +1 -0
- package/dist/streamed-splat-mesh.d.ts +21 -27
- package/dist/streaming.d.ts +23 -0
- package/dist/streaming.js +2877 -0
- package/dist/streaming.js.map +1 -0
- package/dist/{unified-splat-renderer.d.ts → unified-splat-mesh.d.ts} +10 -10
- package/dist/unified-work-buffer.d.ts +66 -0
- package/dist/unified.d.ts +11 -0
- package/dist/unified.js +738 -0
- package/dist/unified.js.map +1 -0
- package/dist/webgpu-limits-Y3CI_6_6.js +43 -0
- package/dist/webgpu-limits-Y3CI_6_6.js.map +1 -0
- package/dist/webgpu-limits.d.ts +0 -59
- package/dist/work-buffer-gather.d.ts +1 -1
- package/package.json +24 -4
- package/dist/splat-mesh-types-CTN_duw2.js.map +0 -1
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (
|
|
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
4
|
import * as S from "three/webgpu";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return `${b.file}:${b.level}:${b.offset}:${b.count}`;
|
|
5
|
+
function P(p) {
|
|
6
|
+
return `${p.file}:${p.level}:${p.offset}:${p.count}`;
|
|
8
7
|
}
|
|
9
|
-
const L = -1,
|
|
10
|
-
class
|
|
11
|
-
constructor(
|
|
8
|
+
const L = -1, y = 128e3, w = 0.1, T = 500, R = 0.1, D = 3;
|
|
9
|
+
class N {
|
|
10
|
+
constructor(s, i) {
|
|
12
11
|
/** World-unit distance inside which the finest level (0) is used. */
|
|
13
12
|
h(this, "lodBaseDistance");
|
|
14
13
|
/** Distance ratio between successive LOD levels. */
|
|
@@ -97,31 +96,31 @@ class W {
|
|
|
97
96
|
* (`TypedArray#sort` stability is not guaranteed).
|
|
98
97
|
*/
|
|
99
98
|
h(this, "orderScratch");
|
|
100
|
-
if (this.leaves =
|
|
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)
|
|
101
100
|
throw new RangeError("LodScheduler budgetFillFraction must be in (0, 1].");
|
|
102
101
|
if (!(this.budgetFillCap > 0))
|
|
103
102
|
throw new RangeError("LodScheduler budgetFillCap must be positive.");
|
|
104
103
|
if (this.forceFinestWithin !== void 0 && !(this.forceFinestWithin >= 0))
|
|
105
104
|
throw new RangeError("LodScheduler forceFinestWithin must be >= 0.");
|
|
106
|
-
const
|
|
107
|
-
this.minLevel = new Int32Array(
|
|
108
|
-
const l = [],
|
|
109
|
-
for (let n = 0; n <
|
|
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++) {
|
|
110
109
|
const r = this.leaves[n].budgetGroup;
|
|
111
110
|
if (r === void 0) {
|
|
112
111
|
l.push([n]);
|
|
113
112
|
continue;
|
|
114
113
|
}
|
|
115
|
-
let t =
|
|
116
|
-
t === void 0 && (t = l.length,
|
|
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;
|
|
117
116
|
}
|
|
118
117
|
this.budgetGroups = l.map((n) => Uint32Array.from(n));
|
|
119
|
-
for (let n = 0; n <
|
|
118
|
+
for (let n = 0; n < e; n++) {
|
|
120
119
|
const r = this.leaves[n].lods;
|
|
121
|
-
let t = this.coarsest,
|
|
120
|
+
let t = this.coarsest, a = 0;
|
|
122
121
|
for (let o = 0; o < r.length; o++)
|
|
123
|
-
r[o] !== void 0 && (t = Math.min(t, o),
|
|
124
|
-
this.minLevel[n] = t, this.maxLevel[n] =
|
|
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;
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
/**
|
|
@@ -131,73 +130,73 @@ class W {
|
|
|
131
130
|
* @param frustum - View frustum in the mesh's local space.
|
|
132
131
|
* @param now - Monotonic timestamp (ms) for dwell hysteresis.
|
|
133
132
|
*/
|
|
134
|
-
computeDesiredRuns(
|
|
135
|
-
if (this.selectLevels(
|
|
133
|
+
computeDesiredRuns(s, i, e, l) {
|
|
134
|
+
if (this.selectLevels(s, i, e, l), this.forceFinestWhenFits && this.budget >= this.finestTotal()) {
|
|
136
135
|
for (let n = 0; n < this.leaves.length; n++)
|
|
137
136
|
this.resolved[n] = this.minLevel[n];
|
|
138
137
|
return this.stats.desired = this.activeTotal(), this.stats.filled = 0, this.coalesceRuns();
|
|
139
138
|
}
|
|
140
139
|
this.resolved.set(this.level), this.enforceBudget();
|
|
141
|
-
const
|
|
142
|
-
return this.fillBudget(), this.stats.desired = this.activeTotal(), this.stats.filled = this.stats.desired -
|
|
140
|
+
const d = this.activeTotal();
|
|
141
|
+
return this.fillBudget(), this.stats.desired = this.activeTotal(), this.stats.filled = this.stats.desired - d, this.coalesceRuns();
|
|
143
142
|
}
|
|
144
143
|
/** Total active splats implied by the current resolved levels. */
|
|
145
144
|
activeTotal() {
|
|
146
145
|
var i;
|
|
147
|
-
let
|
|
148
|
-
for (let
|
|
149
|
-
const l = this.resolved[
|
|
150
|
-
l !== L && (
|
|
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);
|
|
151
150
|
}
|
|
152
|
-
return
|
|
151
|
+
return s;
|
|
153
152
|
}
|
|
154
153
|
/** Splats if every leaf sat at its finest available level (none dropped). */
|
|
155
154
|
finestTotal() {
|
|
156
155
|
var i;
|
|
157
|
-
let
|
|
158
|
-
for (let
|
|
159
|
-
const l = this.minLevel[
|
|
160
|
-
|
|
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;
|
|
161
160
|
}
|
|
162
|
-
return
|
|
161
|
+
return s;
|
|
163
162
|
}
|
|
164
|
-
selectLevels(
|
|
165
|
-
const { lodBaseDistance:
|
|
163
|
+
selectLevels(s, i, e, l) {
|
|
164
|
+
const { lodBaseDistance: d, lodMultiplier: n } = this;
|
|
166
165
|
this.hasScreenImportance = l !== void 0;
|
|
167
166
|
let r = 0;
|
|
168
167
|
this.stats.leaves = this.leaves.length;
|
|
169
168
|
for (let t = 0; t < this.leaves.length; t++) {
|
|
170
|
-
const
|
|
171
|
-
this.distance[t] = o, this.scratchBox.copy(
|
|
172
|
-
const
|
|
173
|
-
if (this.inFrustum[t] =
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
this.screenImportance[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;
|
|
177
176
|
} else
|
|
178
177
|
this.screenImportance[t] = 0;
|
|
179
178
|
const u = this.level[t];
|
|
180
179
|
if (this.fillPastDistance && this.forceFinestWithin !== void 0 && o <= this.forceFinestWithin) {
|
|
181
|
-
const
|
|
182
|
-
u !==
|
|
180
|
+
const f = this.minLevel[t];
|
|
181
|
+
u !== f && (this.level[t] = f, this.changedAt[t] = e);
|
|
183
182
|
continue;
|
|
184
183
|
}
|
|
185
|
-
const v = !this.frustumAware ||
|
|
184
|
+
const v = !this.frustumAware || c ? o : o * D;
|
|
186
185
|
if (!this.fillPastDistance) {
|
|
187
|
-
const
|
|
186
|
+
const f = this.distanceBandLevel(t, v, d, n);
|
|
188
187
|
if (this.changedAt[t] === 0 && u === this.maxLevel[t]) {
|
|
189
|
-
|
|
188
|
+
f !== u && (this.level[t] = f, this.changedAt[t] = e);
|
|
190
189
|
continue;
|
|
191
190
|
}
|
|
192
|
-
if (
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
(
|
|
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);
|
|
196
195
|
continue;
|
|
197
196
|
}
|
|
198
|
-
const m = this.hysteresisLevel(t, v,
|
|
197
|
+
const m = this.hysteresisLevel(t, v, d, n, u);
|
|
199
198
|
if (m === u) continue;
|
|
200
|
-
(this.changedAt[t] === 0 && u === this.maxLevel[t] ||
|
|
199
|
+
(this.changedAt[t] === 0 && u === this.maxLevel[t] || e - this.changedAt[t] >= T) && (this.level[t] = m, this.changedAt[t] = e);
|
|
201
200
|
}
|
|
202
201
|
this.stats.inFrustum = r;
|
|
203
202
|
}
|
|
@@ -205,186 +204,180 @@ class W {
|
|
|
205
204
|
* Pure distance→level band (independent of the leaf's current level), so a
|
|
206
205
|
* classic LCC cut never has to dwell through intermediate rungs.
|
|
207
206
|
*/
|
|
208
|
-
distanceBandLevel(
|
|
209
|
-
const
|
|
210
|
-
let r =
|
|
211
|
-
for (; r < n && i >
|
|
212
|
-
return this.resolveAvailable(
|
|
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);
|
|
213
212
|
}
|
|
214
213
|
/**
|
|
215
214
|
* Stable level from distance: coarsen only past `threshold·(1 + margin)`,
|
|
216
215
|
* refine only within `threshold·(1 − margin)`. The available-level clamp
|
|
217
216
|
* keeps leaves that lack a level on their nearest coarser one.
|
|
218
217
|
*/
|
|
219
|
-
hysteresisLevel(
|
|
220
|
-
const n = this.minLevel[
|
|
221
|
-
let t = Math.min(r, Math.max(n,
|
|
222
|
-
for (; t < r && i >
|
|
223
|
-
for (; t > n && i <=
|
|
224
|
-
return this.resolveAvailable(
|
|
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);
|
|
225
224
|
}
|
|
226
|
-
resolveAvailable(
|
|
227
|
-
const
|
|
228
|
-
for (let l = i; l <= this.maxLevel[
|
|
229
|
-
for (let l = i - 1; l >= this.minLevel[
|
|
230
|
-
return this.maxLevel[
|
|
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];
|
|
231
230
|
}
|
|
232
231
|
/** Demotes/drops lowest-priority leaves until the total fits the budget. */
|
|
233
232
|
enforceBudget() {
|
|
234
|
-
var
|
|
235
|
-
let
|
|
236
|
-
if (
|
|
233
|
+
var e, l, d;
|
|
234
|
+
let s = this.activeTotal();
|
|
235
|
+
if (s <= this.budget) return;
|
|
237
236
|
const i = this.orderScratch.subarray(0, this.budgetGroups.length);
|
|
238
237
|
for (let n = 0; n < i.length; n++) i[n] = n;
|
|
239
238
|
i.sort((n, r) => {
|
|
240
|
-
const t = this.budgetGroups[n][0],
|
|
239
|
+
const t = this.budgetGroups[n][0], a = this.budgetGroups[r][0];
|
|
241
240
|
if (this.frustumAware) {
|
|
242
|
-
const o = this.inFrustum[t],
|
|
243
|
-
if (o !==
|
|
241
|
+
const o = this.inFrustum[t], c = this.inFrustum[a];
|
|
242
|
+
if (o !== c) return o - c;
|
|
244
243
|
}
|
|
245
|
-
return this.distance[
|
|
244
|
+
return this.distance[a] - this.distance[t] || t - a;
|
|
246
245
|
});
|
|
247
246
|
for (const n of i) {
|
|
248
247
|
const r = this.budgetGroups[n];
|
|
249
|
-
for (;
|
|
250
|
-
let t = 0,
|
|
248
|
+
for (; s > this.budget; ) {
|
|
249
|
+
let t = 0, a = !1;
|
|
251
250
|
for (const o of r) {
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
254
|
-
const u = this.leaves[o].lods, v = this.resolveAvailable(o,
|
|
255
|
-
v !==
|
|
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);
|
|
256
255
|
}
|
|
257
|
-
if (!
|
|
258
|
-
|
|
256
|
+
if (!a) break;
|
|
257
|
+
s -= t;
|
|
259
258
|
}
|
|
260
|
-
if (
|
|
259
|
+
if (s <= this.budget) return;
|
|
261
260
|
}
|
|
262
261
|
for (const n of i) {
|
|
263
|
-
if (
|
|
262
|
+
if (s <= this.budget) return;
|
|
264
263
|
for (const r of this.budgetGroups[n])
|
|
265
|
-
this.resolved[r] !== L && (
|
|
264
|
+
this.resolved[r] !== L && (s -= ((d = this.leaves[r].lods[this.resolved[r]]) == null ? void 0 : d.count) ?? 0, this.resolved[r] = L);
|
|
266
265
|
}
|
|
267
266
|
}
|
|
268
267
|
/**
|
|
269
268
|
* Uses leftover budget to restore detail after {@link enforceBudget}
|
|
270
269
|
* demoted leaves, nearest first, while the total stays under the fill
|
|
271
270
|
* target. By default this may also refine *past* the distance-chosen level
|
|
272
|
-
* when headroom remains (octree /
|
|
271
|
+
* when headroom remains (octree / page-table streams). With
|
|
273
272
|
* {@link fillPastDistance} false (classic LCC), fill never goes finer than
|
|
274
273
|
* each leaf's distance-selected level - so a cell at the L1 band does not
|
|
275
274
|
* fetch L0 only to demote moments later with the camera still.
|
|
276
275
|
*/
|
|
277
276
|
fillBudget() {
|
|
278
|
-
var
|
|
279
|
-
const
|
|
277
|
+
var d, n;
|
|
278
|
+
const s = this.forceFinestWhenFits && this.budget >= this.finestTotal() ? this.budget : Math.min(this.budget, this.budgetFillCap) * this.budgetFillFraction;
|
|
280
279
|
let i = this.activeTotal();
|
|
281
|
-
if (i >=
|
|
282
|
-
let
|
|
280
|
+
if (i >= s) return;
|
|
281
|
+
let e = 0;
|
|
283
282
|
for (let r = 0; r < this.budgetGroups.length; r++) {
|
|
284
283
|
const t = this.budgetGroups[r][0];
|
|
285
|
-
(!this.frustumAware || this.inFrustum[t] === 1) && this.resolved[t] !== L && (this.orderScratch[
|
|
284
|
+
(!this.frustumAware || this.inFrustum[t] === 1) && this.resolved[t] !== L && (this.orderScratch[e++] = r);
|
|
286
285
|
}
|
|
287
|
-
const l = this.orderScratch.subarray(0,
|
|
286
|
+
const l = this.orderScratch.subarray(0, e);
|
|
288
287
|
l.sort((r, t) => {
|
|
289
|
-
const
|
|
290
|
-
return this.distance[
|
|
288
|
+
const a = this.budgetGroups[r][0], o = this.budgetGroups[t][0];
|
|
289
|
+
return this.distance[a] - this.distance[o] || a - o;
|
|
291
290
|
});
|
|
292
291
|
for (const r of l) {
|
|
293
292
|
const t = this.budgetGroups[r];
|
|
294
293
|
for (; ; ) {
|
|
295
|
-
let
|
|
296
|
-
for (const
|
|
297
|
-
const u = this.resolved[
|
|
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];
|
|
298
297
|
if (u <= v) continue;
|
|
299
|
-
const m = this.leaves[
|
|
298
|
+
const m = this.leaves[c];
|
|
300
299
|
let g = u - 1;
|
|
301
300
|
for (; g > v && !m.lods[g]; ) g--;
|
|
302
|
-
g < v || !m.lods[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);
|
|
303
302
|
}
|
|
304
|
-
if (!o || i +
|
|
305
|
-
for (const
|
|
306
|
-
const u = this.resolved[
|
|
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];
|
|
307
306
|
if (u <= v) continue;
|
|
308
|
-
const m = this.leaves[
|
|
307
|
+
const m = this.leaves[c];
|
|
309
308
|
let g = u - 1;
|
|
310
309
|
for (; g > v && !m.lods[g]; ) g--;
|
|
311
|
-
g >= v && m.lods[g] && (this.resolved[
|
|
310
|
+
g >= v && m.lods[g] && (this.resolved[c] = g);
|
|
312
311
|
}
|
|
313
|
-
i +=
|
|
312
|
+
i += a;
|
|
314
313
|
}
|
|
315
314
|
}
|
|
316
315
|
}
|
|
317
316
|
coalesceRuns() {
|
|
318
|
-
return this.buildRuns(0, this.leaves.length, (
|
|
317
|
+
return this.buildRuns(0, this.leaves.length, (s) => this.resolved[s]);
|
|
319
318
|
}
|
|
320
319
|
/**
|
|
321
320
|
* Runs covering [from, to) at each leaf's coarsest available level - used
|
|
322
321
|
* to substitute always-cached coverage while a finer level is fetching.
|
|
323
322
|
*/
|
|
324
|
-
coarsestRunsFor(
|
|
325
|
-
return this.buildRuns(
|
|
323
|
+
coarsestRunsFor(s, i) {
|
|
324
|
+
return this.buildRuns(s, i, (e) => this.maxLevel[e]);
|
|
326
325
|
}
|
|
327
326
|
/**
|
|
328
327
|
* Runs covering [from, to) at `level`, clamped per leaf to an available rung
|
|
329
328
|
* (prefer the requested level, else the next coarser, else the next finer).
|
|
330
329
|
*/
|
|
331
|
-
runsAtLevelFor(
|
|
332
|
-
const l = Math.floor(
|
|
333
|
-
return this.buildRuns(
|
|
330
|
+
runsAtLevelFor(s, i, e) {
|
|
331
|
+
const l = Math.floor(e);
|
|
332
|
+
return this.buildRuns(s, i, (d) => this.clampLeafLevel(d, l));
|
|
334
333
|
}
|
|
335
334
|
/** Prefer `wanted`, else next coarser, else next finer; {@link DROPPED} if none. */
|
|
336
|
-
clampLeafLevel(
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
339
|
-
for (let l = i + 1; l <
|
|
340
|
-
if (
|
|
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;
|
|
341
340
|
for (let l = i - 1; l >= 0; l--)
|
|
342
|
-
if (
|
|
341
|
+
if (e.lods[l]) return l;
|
|
343
342
|
return L;
|
|
344
343
|
}
|
|
345
344
|
/** Coalesces leaves [from, to) at `levelOf(leaf)` into contiguous runs. */
|
|
346
|
-
buildRuns(
|
|
345
|
+
buildRuns(s, i, e) {
|
|
347
346
|
const l = [];
|
|
348
|
-
let
|
|
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;
|
|
349
348
|
const g = () => {
|
|
350
349
|
t > 0 && l.push({
|
|
351
|
-
file:
|
|
350
|
+
file: d,
|
|
352
351
|
level: n,
|
|
353
352
|
offset: r,
|
|
354
353
|
count: t,
|
|
355
|
-
leafStart:
|
|
354
|
+
leafStart: a,
|
|
356
355
|
leafEnd: o,
|
|
357
356
|
distance: u,
|
|
358
357
|
inView: v,
|
|
359
358
|
...this.hasScreenImportance ? { screenImportance: m } : {},
|
|
360
|
-
...
|
|
359
|
+
...c >= 0 ? { coverageGroup: c } : {}
|
|
361
360
|
}), t = 0;
|
|
362
361
|
};
|
|
363
|
-
for (let
|
|
364
|
-
const F =
|
|
362
|
+
for (let f = s; f < i; f++) {
|
|
363
|
+
const F = e(f);
|
|
365
364
|
if (F === L) {
|
|
366
365
|
g();
|
|
367
366
|
continue;
|
|
368
367
|
}
|
|
369
|
-
const
|
|
370
|
-
if (!
|
|
368
|
+
const b = this.leaves[f].lods[F];
|
|
369
|
+
if (!b) {
|
|
371
370
|
g();
|
|
372
371
|
continue;
|
|
373
372
|
}
|
|
374
|
-
const I = this.coverageGroups[
|
|
375
|
-
t > 0 &&
|
|
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]);
|
|
376
375
|
}
|
|
377
376
|
return g(), l;
|
|
378
377
|
}
|
|
379
378
|
}
|
|
380
|
-
const _ = 3;
|
|
381
|
-
function U(b, e = D()) {
|
|
382
|
-
return b ?? (y(e) ? "smooth" : "quality");
|
|
383
|
-
}
|
|
384
379
|
export {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
E as a,
|
|
388
|
-
U as r
|
|
380
|
+
N as L,
|
|
381
|
+
P as r
|
|
389
382
|
};
|
|
390
|
-
//# sourceMappingURL=
|
|
383
|
+
//# sourceMappingURL=lod-scheduler-B0a_uBlv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lod-scheduler-B0a_uBlv.js","sources":["../src/lib/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;AA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A,IAAQQ,EAAM,SAAS/E,KAEvBuE,KAASQ,EAAM,OACfN,IAAU5D,IAAI,GACVoE,IAAeN,MAAUA,IAAWM,IACpCC,MAAYN,IAAS,KACzBC,IAAmB,KAAK,IAAIA,GAAkB,KAAK,iBAAiBhE,CAAC,CAAW,MAEhFiE,EAAA,GACAT,IAAOU,EAAM,MACbpD,IAAQP,GACRkD,IAASS,EAAM,QACfR,IAAQQ,EAAM,OACdP,IAAY3D,GACZ4D,IAAU5D,IAAI,GACd6D,IAAgBM,GAChBL,IAAWM,GACXL,IAASM,GACTL,IAAmB,KAAK,iBAAiBhE,CAAC;AAAA,IAE9C;AACA,WAAAiE,EAAA,GACOV;AAAA,EACT;AACF;"}
|
package/dist/lod-scheduler.d.ts
CHANGED
|
@@ -205,7 +205,7 @@ export declare class LodScheduler implements LodSource {
|
|
|
205
205
|
* Uses leftover budget to restore detail after {@link enforceBudget}
|
|
206
206
|
* demoted leaves, nearest first, while the total stays under the fill
|
|
207
207
|
* target. By default this may also refine *past* the distance-chosen level
|
|
208
|
-
* when headroom remains (octree /
|
|
208
|
+
* when headroom remains (octree / page-table streams). With
|
|
209
209
|
* {@link fillPastDistance} false (classic LCC), fill never goes finer than
|
|
210
210
|
* each leaf's distance-selected level - so a cell at the L1 band does not
|
|
211
211
|
* fetch L0 only to demote moments later with the camera still.
|
package/dist/lod-source.d.ts
CHANGED
|
@@ -106,7 +106,7 @@ export interface CollisionMeshDescriptor {
|
|
|
106
106
|
* Coordinates are source-local, the same frame as {@link StreamedScene.bounds}:
|
|
107
107
|
* {@link StreamedScene.formatTransform} maps them to world.
|
|
108
108
|
*/
|
|
109
|
-
export interface
|
|
109
|
+
export interface SplatCollisionData {
|
|
110
110
|
readonly meshes: readonly CollisionMeshDescriptor[];
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
@@ -155,7 +155,7 @@ export interface StreamedScene {
|
|
|
155
155
|
*/
|
|
156
156
|
readonly formatTransform?: THREE.Matrix4;
|
|
157
157
|
/** Optional collision geometry the format ships; undefined when it has none. */
|
|
158
|
-
readonly collision?:
|
|
158
|
+
readonly collision?: SplatCollisionData;
|
|
159
159
|
/**
|
|
160
160
|
* Optional always-resident environment tile the format ships outside its LOD
|
|
161
161
|
* structure (the `.lcc2` sky) - present only when the dataset carries one.
|
|
@@ -175,13 +175,13 @@ export interface StreamedScene {
|
|
|
175
175
|
/**
|
|
176
176
|
* Splats per chunk file, so a `(file, localIndex)` pair maps to a stable global
|
|
177
177
|
* splat index (`file * chunkSize + local`). Set by `.rad`; the page-table
|
|
178
|
-
* renderer (`foveationMode: '
|
|
178
|
+
* renderer (`foveationMode: 'page-table'`) keys frontier splats by that global.
|
|
179
179
|
*/
|
|
180
180
|
readonly chunkSize?: number;
|
|
181
181
|
/**
|
|
182
182
|
* A chunk the scene builder already fetched and decoded (`.rad` decodes chunk
|
|
183
183
|
* 0 for the scene bounds and the SH codebook). Handing it straight to the
|
|
184
|
-
* renderer saves a second round trip - and in `
|
|
184
|
+
* renderer saves a second round trip - and in `page-table` mode it is what
|
|
185
185
|
* seeds the worker's tree roots, without which the first traversals return an
|
|
186
186
|
* empty frontier and the view stays blank until chunk 0 arrives a second time.
|
|
187
187
|
*/
|
|
@@ -191,7 +191,7 @@ export interface StreamedScene {
|
|
|
191
191
|
};
|
|
192
192
|
/**
|
|
193
193
|
* Source-local xyz subsample of the coarsest overview (`.rad` chunk 0).
|
|
194
|
-
* Survives after
|
|
194
|
+
* Survives after page-table mode transfers chunk-0 buffers to the worker, so
|
|
195
195
|
* a host can estimate terrain height before any later chunk decodes.
|
|
196
196
|
*/
|
|
197
197
|
readonly overviewPositions?: Float32Array;
|