@needle-tools/gltf-progressive 3.4.0-next.a30adb3 → 3.4.0-next.dbcee85
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/gltf-progressive.js +338 -337
- package/gltf-progressive.min.js +8 -7
- package/gltf-progressive.umd.cjs +8 -7
- package/lib/extension.d.ts +1 -1
- package/lib/extension.js +26 -23
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BufferGeometry as E, Mesh as V, Box3 as he, Vector3 as C, Sphere as De, CompressedTexture as Be, Texture as F, Matrix3 as Ge, InterleavedBuffer as Fe, InterleavedBufferAttribute as We, BufferAttribute as Ue, TextureLoader as ze, Matrix4 as
|
|
1
|
+
import { BufferGeometry as E, Mesh as V, Box3 as he, Vector3 as C, Sphere as De, CompressedTexture as Be, Texture as F, Matrix3 as Ge, InterleavedBuffer as Fe, InterleavedBufferAttribute as We, BufferAttribute as Ue, TextureLoader as ze, Matrix4 as _e, Clock as Ne, MeshStandardMaterial as qe } from "three";
|
|
2
2
|
import { GLTFLoader as ye } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
3
3
|
import { MeshoptDecoder as Ee } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
4
4
|
import { DRACOLoader as Ve } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
@@ -14,7 +14,7 @@ fetch(Oe, {
|
|
|
14
14
|
headers: {
|
|
15
15
|
Range: "bytes=0-1"
|
|
16
16
|
}
|
|
17
|
-
}).catch((
|
|
17
|
+
}).catch((i) => {
|
|
18
18
|
console.debug(`Failed to fetch remote Draco decoder from ${R} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), R === Ye && Qe("./include/draco/"), X === Ke && Je("./include/ktx2/");
|
|
19
19
|
}).finally(() => {
|
|
20
20
|
Pe();
|
|
@@ -23,17 +23,17 @@ const He = () => ({
|
|
|
23
23
|
dracoDecoderPath: R,
|
|
24
24
|
ktx2TranscoderPath: X
|
|
25
25
|
});
|
|
26
|
-
function Qe(
|
|
27
|
-
R =
|
|
26
|
+
function Qe(i) {
|
|
27
|
+
R = i, A && A[ge] != R ? (console.debug("Updating Draco decoder path to " + i), A[ge] = R, A.setDecoderPath(R), A.preload()) : console.debug("Setting Draco decoder path to " + i);
|
|
28
28
|
}
|
|
29
|
-
function Je(
|
|
30
|
-
X =
|
|
29
|
+
function Je(i) {
|
|
30
|
+
X = i, $ && $.transcoderPath != X ? (console.debug("Updating KTX2 transcoder path to " + i), $.setTranscoderPath(X), $.init()) : console.debug("Setting KTX2 transcoder path to " + i);
|
|
31
31
|
}
|
|
32
|
-
function xe(
|
|
33
|
-
return Pe(),
|
|
32
|
+
function xe(i) {
|
|
33
|
+
return Pe(), i ? $.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: A, ktx2Loader: $, meshoptDecoder: oe };
|
|
34
34
|
}
|
|
35
|
-
function Se(
|
|
36
|
-
|
|
35
|
+
function Se(i) {
|
|
36
|
+
i.dracoLoader || i.setDRACOLoader(A), i.ktx2Loader || i.setKTX2Loader($), i.meshoptDecoder || i.setMeshoptDecoder(oe);
|
|
37
37
|
}
|
|
38
38
|
const ge = /* @__PURE__ */ Symbol("dracoDecoderPath");
|
|
39
39
|
let A, oe, $;
|
|
@@ -41,34 +41,34 @@ function Pe() {
|
|
|
41
41
|
A || (A = new Ve(), A[ge] = R, A.setDecoderPath(R), A.setDecoderConfig({ type: "js" }), A.preload()), $ || ($ = new Xe(), $.setTranscoderPath(X), $.init()), oe || (oe = Ee);
|
|
42
42
|
}
|
|
43
43
|
const pe = /* @__PURE__ */ new WeakMap();
|
|
44
|
-
function Te(
|
|
45
|
-
let e = pe.get(
|
|
46
|
-
e ? e = Object.assign(e, t) : e = t, pe.set(
|
|
44
|
+
function Te(i, t) {
|
|
45
|
+
let e = pe.get(i);
|
|
46
|
+
e ? e = Object.assign(e, t) : e = t, pe.set(i, e);
|
|
47
47
|
}
|
|
48
48
|
const Ze = ye.prototype.load;
|
|
49
|
-
function et(...
|
|
49
|
+
function et(...i) {
|
|
50
50
|
const t = pe.get(this);
|
|
51
|
-
let e =
|
|
51
|
+
let e = i[0];
|
|
52
52
|
const s = new URL(e, window.location.href);
|
|
53
53
|
if (s.hostname.endsWith("needle.tools")) {
|
|
54
|
-
const r = t?.progressive !== void 0 ? t.progressive : !0,
|
|
55
|
-
r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${
|
|
54
|
+
const r = t?.progressive !== void 0 ? t.progressive : !0, n = t?.usecase ? t.usecase : "default";
|
|
55
|
+
r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${n}` : this.requestHeader.Accept = `*/*;usecase=${n}`, e = s.toString();
|
|
56
56
|
}
|
|
57
|
-
return
|
|
57
|
+
return i[0] = e, Ze?.call(this, ...i);
|
|
58
58
|
}
|
|
59
59
|
ye.prototype.load = et;
|
|
60
60
|
j("debugprogressive");
|
|
61
|
-
function j(
|
|
61
|
+
function j(i) {
|
|
62
62
|
if (typeof window > "u") return !1;
|
|
63
|
-
const e = new URL(window.location.href).searchParams.get(
|
|
63
|
+
const e = new URL(window.location.href).searchParams.get(i);
|
|
64
64
|
return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
|
|
65
65
|
}
|
|
66
|
-
function tt(
|
|
67
|
-
if (t === void 0 ||
|
|
66
|
+
function tt(i, t) {
|
|
67
|
+
if (t === void 0 || i === void 0 || t.startsWith("./") || t.startsWith("http") || t.startsWith("data:") || t.startsWith("blob:"))
|
|
68
68
|
return t;
|
|
69
|
-
const e =
|
|
69
|
+
const e = i.lastIndexOf("/");
|
|
70
70
|
if (e >= 0) {
|
|
71
|
-
const s =
|
|
71
|
+
const s = i.substring(0, e + 1);
|
|
72
72
|
for (; s.endsWith("/") && t.startsWith("/"); ) t = t.substring(1);
|
|
73
73
|
return s + t;
|
|
74
74
|
}
|
|
@@ -78,10 +78,10 @@ function Ae() {
|
|
|
78
78
|
return K !== void 0 || (K = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), j("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", K)), K;
|
|
79
79
|
}
|
|
80
80
|
let K;
|
|
81
|
-
function
|
|
81
|
+
function Le() {
|
|
82
82
|
if (typeof window > "u") return !1;
|
|
83
|
-
const
|
|
84
|
-
return
|
|
83
|
+
const i = new URL(window.location.href), t = i.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(i.hostname);
|
|
84
|
+
return i.hostname === "127.0.0.1" || t;
|
|
85
85
|
}
|
|
86
86
|
class st {
|
|
87
87
|
constructor(t = 100, e = {}) {
|
|
@@ -118,23 +118,23 @@ class st {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
const rt = typeof window > "u" && typeof document > "u", me = /* @__PURE__ */ Symbol("needle:raycast-mesh");
|
|
121
|
-
function Z(
|
|
122
|
-
return
|
|
121
|
+
function Z(i) {
|
|
122
|
+
return i?.[me] instanceof E ? i[me] : null;
|
|
123
123
|
}
|
|
124
|
-
function ot(
|
|
125
|
-
if ((
|
|
126
|
-
const s =
|
|
127
|
-
s.userData = { isRaycastMesh: !0 },
|
|
124
|
+
function ot(i, t) {
|
|
125
|
+
if ((i.type === "Mesh" || i.type === "SkinnedMesh") && !Z(i)) {
|
|
126
|
+
const s = it(t);
|
|
127
|
+
s.userData = { isRaycastMesh: !0 }, i[me] = s;
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
function
|
|
131
|
-
if (
|
|
130
|
+
function nt(i = !0) {
|
|
131
|
+
if (i) {
|
|
132
132
|
if (H) return;
|
|
133
133
|
const t = H = V.prototype.raycast;
|
|
134
134
|
V.prototype.raycast = function(e, s) {
|
|
135
135
|
const o = this, r = Z(o);
|
|
136
|
-
let
|
|
137
|
-
r && o.isMesh && (
|
|
136
|
+
let n;
|
|
137
|
+
r && o.isMesh && (n = o.geometry, o.geometry = r), t.call(this, e, s), n && (o.geometry = n);
|
|
138
138
|
};
|
|
139
139
|
} else {
|
|
140
140
|
if (!H) return;
|
|
@@ -142,39 +142,39 @@ function it(n = !0) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
let H = null;
|
|
145
|
-
function
|
|
145
|
+
function it(i) {
|
|
146
146
|
const t = new E();
|
|
147
|
-
for (const e in
|
|
148
|
-
t.setAttribute(e,
|
|
149
|
-
return t.setIndex(
|
|
147
|
+
for (const e in i.attributes)
|
|
148
|
+
t.setAttribute(e, i.getAttribute(e));
|
|
149
|
+
return t.setIndex(i.getIndex()), t;
|
|
150
150
|
}
|
|
151
|
-
const z = new Array(),
|
|
151
|
+
const z = new Array(), h = j("debugprogressive");
|
|
152
152
|
let J, q = -1;
|
|
153
|
-
if (
|
|
154
|
-
let
|
|
153
|
+
if (h) {
|
|
154
|
+
let i = function() {
|
|
155
155
|
q += 1, q >= t && (q = -1), console.log(`Toggle LOD level [${q}]`);
|
|
156
156
|
}, t = 6;
|
|
157
157
|
window.addEventListener("keyup", (e) => {
|
|
158
|
-
e.key === "p" &&
|
|
158
|
+
e.key === "p" && i(), e.key === "w" && (J = !J, console.log(`Toggle wireframe [${J}]`));
|
|
159
159
|
const s = parseInt(e.key);
|
|
160
160
|
!isNaN(s) && s >= 0 && (q = s, console.log(`Set LOD level to [${q}]`));
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
-
function Ce(
|
|
164
|
-
if (
|
|
165
|
-
if (Array.isArray(
|
|
166
|
-
for (const t of
|
|
163
|
+
function Ce(i) {
|
|
164
|
+
if (h && J !== void 0)
|
|
165
|
+
if (Array.isArray(i))
|
|
166
|
+
for (const t of i)
|
|
167
167
|
Ce(t);
|
|
168
|
-
else
|
|
168
|
+
else i && "wireframe" in i && (i.wireframe = J === !0);
|
|
169
169
|
}
|
|
170
170
|
const Q = new Array();
|
|
171
171
|
let at = 0;
|
|
172
172
|
const lt = Ae() ? 2 : 10;
|
|
173
|
-
function
|
|
173
|
+
function ut(i) {
|
|
174
174
|
if (Q.length < lt) {
|
|
175
175
|
const s = Q.length;
|
|
176
|
-
|
|
177
|
-
const o = we.createWorker(
|
|
176
|
+
h && console.warn(`[Worker] Creating new worker #${s}`);
|
|
177
|
+
const o = we.createWorker(i || {});
|
|
178
178
|
return Q.push(o), o;
|
|
179
179
|
}
|
|
180
180
|
const t = at++ % Q.length;
|
|
@@ -188,9 +188,9 @@ class we {
|
|
|
188
188
|
case "loaded-gltf":
|
|
189
189
|
for (const r of this._running)
|
|
190
190
|
if (r.url === o.result.url) {
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
|
|
191
|
+
dt(o.result), r.resolve(o.result);
|
|
192
|
+
const n = r.url;
|
|
193
|
+
n.startsWith("blob:") && URL.revokeObjectURL(n);
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
}, t.onerror = (s) => {
|
|
@@ -215,8 +215,8 @@ class we {
|
|
|
215
215
|
const s = He();
|
|
216
216
|
let o = e?.renderer;
|
|
217
217
|
o || (this._webglRenderer ??= (async () => {
|
|
218
|
-
const { WebGLRenderer:
|
|
219
|
-
return new
|
|
218
|
+
const { WebGLRenderer: u } = await import("three");
|
|
219
|
+
return new u();
|
|
220
220
|
})(), o = await this._webglRenderer);
|
|
221
221
|
const l = xe(o).ktx2Loader.workerConfig;
|
|
222
222
|
t instanceof URL ? t = t.toString() : t.startsWith("file:") ? t = URL.createObjectURL(new Blob([t])) : !t.startsWith("blob:") && !t.startsWith("http:") && !t.startsWith("https:") && (t = new URL(t, window.location.href).toString());
|
|
@@ -227,30 +227,30 @@ class we {
|
|
|
227
227
|
ktx2TranscoderPath: s.ktx2TranscoderPath,
|
|
228
228
|
ktx2LoaderConfig: l
|
|
229
229
|
};
|
|
230
|
-
return this._debug && console.debug("[Worker] Sending load request", a), this.worker.postMessage(a), new Promise((
|
|
230
|
+
return this._debug && console.debug("[Worker] Sending load request", a), this.worker.postMessage(a), new Promise((u) => {
|
|
231
231
|
this._running.push({
|
|
232
232
|
url: t.toString(),
|
|
233
|
-
resolve:
|
|
233
|
+
resolve: u
|
|
234
234
|
});
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
_debug = !1;
|
|
238
238
|
}
|
|
239
|
-
function
|
|
240
|
-
for (const t of
|
|
239
|
+
function dt(i) {
|
|
240
|
+
for (const t of i.geometries) {
|
|
241
241
|
const e = t.geometry, s = new E();
|
|
242
242
|
if (s.name = e.name || "", e.index) {
|
|
243
243
|
const o = e.index;
|
|
244
244
|
s.setIndex(ae(o));
|
|
245
245
|
}
|
|
246
246
|
for (const o in e.attributes) {
|
|
247
|
-
const r = e.attributes[o],
|
|
248
|
-
s.setAttribute(o,
|
|
247
|
+
const r = e.attributes[o], n = ae(r);
|
|
248
|
+
s.setAttribute(o, n);
|
|
249
249
|
}
|
|
250
250
|
if (e.morphAttributes)
|
|
251
251
|
for (const o in e.morphAttributes) {
|
|
252
|
-
const
|
|
253
|
-
s.morphAttributes[o] =
|
|
252
|
+
const n = e.morphAttributes[o].map((l) => ae(l));
|
|
253
|
+
s.morphAttributes[o] = n;
|
|
254
254
|
}
|
|
255
255
|
if (s.morphTargetsRelative = e.morphTargetsRelative ?? !1, s.boundingBox = new he(), s.boundingBox.min = new C(
|
|
256
256
|
e.boundingBox?.min.x,
|
|
@@ -272,15 +272,15 @@ function ut(n) {
|
|
|
272
272
|
s.addGroup(o.start, o.count, o.materialIndex);
|
|
273
273
|
e.userData && (s.userData = e.userData), t.geometry = s;
|
|
274
274
|
}
|
|
275
|
-
for (const t of
|
|
275
|
+
for (const t of i.textures) {
|
|
276
276
|
const e = t.texture;
|
|
277
277
|
let s = null;
|
|
278
278
|
if (e.isCompressedTexture) {
|
|
279
|
-
const o = e.mipmaps, r = e.image?.width || e.source?.data?.width || -1,
|
|
279
|
+
const o = e.mipmaps, r = e.image?.width || e.source?.data?.width || -1, n = e.image?.height || e.source?.data?.height || -1;
|
|
280
280
|
s = new Be(
|
|
281
281
|
o,
|
|
282
282
|
r,
|
|
283
|
-
|
|
283
|
+
n,
|
|
284
284
|
e.format,
|
|
285
285
|
e.type,
|
|
286
286
|
e.mapping,
|
|
@@ -310,14 +310,14 @@ function ut(n) {
|
|
|
310
310
|
}
|
|
311
311
|
t.texture = s;
|
|
312
312
|
}
|
|
313
|
-
return
|
|
313
|
+
return i;
|
|
314
314
|
}
|
|
315
|
-
function ae(
|
|
316
|
-
let t =
|
|
317
|
-
if ("isInterleavedBufferAttribute" in
|
|
318
|
-
const e =
|
|
319
|
-
t = new We(o,
|
|
320
|
-
} else "isBufferAttribute" in
|
|
315
|
+
function ae(i) {
|
|
316
|
+
let t = i;
|
|
317
|
+
if ("isInterleavedBufferAttribute" in i && i.isInterleavedBufferAttribute) {
|
|
318
|
+
const e = i.data, s = e.array, o = new Fe(s, e.stride);
|
|
319
|
+
t = new We(o, i.itemSize, s.byteOffset, i.normalized), t.offset = i.offset;
|
|
320
|
+
} else "isBufferAttribute" in i && i.isBufferAttribute && (t = new Ue(i.array, i.itemSize, i.normalized), t.usage = i.usage, t.gpuType = i.gpuType, t.updateRanges = i.updateRanges);
|
|
321
321
|
return t;
|
|
322
322
|
}
|
|
323
323
|
const ct = j("gltf-progressive-worker"), ft = j("gltf-progressive-reduce-mipmaps"), le = /* @__PURE__ */ Symbol("needle-progressive-texture"), W = "NEEDLE_progressive";
|
|
@@ -347,28 +347,28 @@ class m {
|
|
|
347
347
|
this.getMaterialMinMaxLODsCount(l, e);
|
|
348
348
|
return t[o] = e, e;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (h === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
|
|
351
351
|
const l = t;
|
|
352
352
|
for (const a of Object.keys(l.uniforms)) {
|
|
353
|
-
const
|
|
354
|
-
|
|
353
|
+
const u = l.uniforms[a].value;
|
|
354
|
+
u?.isTexture === !0 && n(u, e);
|
|
355
355
|
}
|
|
356
356
|
} else if (t.isMaterial)
|
|
357
357
|
for (const l of Object.keys(t)) {
|
|
358
358
|
const a = t[l];
|
|
359
|
-
a?.isTexture === !0 &&
|
|
359
|
+
a?.isTexture === !0 && n(a, e);
|
|
360
360
|
}
|
|
361
361
|
else
|
|
362
|
-
|
|
362
|
+
h && console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${t.type}`);
|
|
363
363
|
return t[o] = e, e;
|
|
364
|
-
function
|
|
365
|
-
const
|
|
366
|
-
if (
|
|
367
|
-
const
|
|
368
|
-
if (
|
|
369
|
-
a.min_count = Math.min(a.min_count,
|
|
370
|
-
for (let y = 0; y <
|
|
371
|
-
const w =
|
|
364
|
+
function n(l, a) {
|
|
365
|
+
const u = s.getAssignedLODInformation(l);
|
|
366
|
+
if (u) {
|
|
367
|
+
const d = s.lodInfos.get(u.key);
|
|
368
|
+
if (d && d.lods) {
|
|
369
|
+
a.min_count = Math.min(a.min_count, d.lods.length), a.max_count = Math.max(a.max_count, d.lods.length);
|
|
370
|
+
for (let y = 0; y < d.lods.length; y++) {
|
|
371
|
+
const w = d.lods[y];
|
|
372
372
|
w.width && (a.lods[y] = a.lods[y] || { min_height: 1 / 0, max_height: 0 }, a.lods[y].min_height = Math.min(a.lods[y].min_height, w.height), a.lods[y].max_height = Math.max(a.lods[y].max_height, w.height));
|
|
373
373
|
}
|
|
374
374
|
}
|
|
@@ -388,8 +388,8 @@ class m {
|
|
|
388
388
|
}
|
|
389
389
|
if (t.isMaterial === !0) {
|
|
390
390
|
for (const r of Object.keys(t)) {
|
|
391
|
-
const
|
|
392
|
-
if (
|
|
391
|
+
const n = t[r];
|
|
392
|
+
if (n && n.isTexture && this.hasLODLevelAvailable(n, e))
|
|
393
393
|
return !0;
|
|
394
394
|
}
|
|
395
395
|
return !1;
|
|
@@ -431,12 +431,12 @@ class m {
|
|
|
431
431
|
r.onBeforeGetLODMesh?.(t, e);
|
|
432
432
|
return t["LOD:requested level"] = e, m.getOrLoadLOD(s, e).then((r) => {
|
|
433
433
|
if (Array.isArray(r)) {
|
|
434
|
-
const
|
|
435
|
-
r = r[
|
|
434
|
+
const n = o.index || 0;
|
|
435
|
+
r = r[n];
|
|
436
436
|
}
|
|
437
|
-
return t["LOD:requested level"] === e && (delete t["LOD:requested level"], r && s != r && (r?.isBufferGeometry ? t.geometry = r :
|
|
437
|
+
return t["LOD:requested level"] === e && (delete t["LOD:requested level"], r && s != r && (r?.isBufferGeometry ? t.geometry = r : h && console.error("Invalid LOD geometry", r))), r;
|
|
438
438
|
}).catch((r) => (console.error("Error loading mesh LOD", t, r), null));
|
|
439
|
-
} else
|
|
439
|
+
} else h && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
|
|
440
440
|
return Promise.resolve(null);
|
|
441
441
|
}
|
|
442
442
|
static assignTextureLOD(t, e = 0) {
|
|
@@ -446,14 +446,14 @@ class m {
|
|
|
446
446
|
if (Array.isArray(s.material)) {
|
|
447
447
|
const o = new Array();
|
|
448
448
|
for (const r of s.material) {
|
|
449
|
-
const
|
|
450
|
-
o.push(
|
|
449
|
+
const n = this.assignTextureLOD(r, e);
|
|
450
|
+
o.push(n);
|
|
451
451
|
}
|
|
452
452
|
return Promise.all(o).then((r) => {
|
|
453
|
-
const
|
|
453
|
+
const n = new Array();
|
|
454
454
|
for (const l of r)
|
|
455
|
-
Array.isArray(l) &&
|
|
456
|
-
return
|
|
455
|
+
Array.isArray(l) && n.push(...l);
|
|
456
|
+
return n;
|
|
457
457
|
});
|
|
458
458
|
} else
|
|
459
459
|
return this.assignTextureLOD(s.material, e);
|
|
@@ -461,27 +461,27 @@ class m {
|
|
|
461
461
|
if (t.isMaterial === !0) {
|
|
462
462
|
const s = t, o = [], r = new Array();
|
|
463
463
|
if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
|
|
464
|
-
const
|
|
465
|
-
for (const l of Object.keys(
|
|
466
|
-
const a =
|
|
464
|
+
const n = s;
|
|
465
|
+
for (const l of Object.keys(n.uniforms)) {
|
|
466
|
+
const a = n.uniforms[l].value;
|
|
467
467
|
if (a?.isTexture === !0) {
|
|
468
|
-
const
|
|
469
|
-
o.push(
|
|
468
|
+
const u = this.assignTextureLODForSlot(a, e, s, l).then((d) => (d && n.uniforms[l].value != d && (n.uniforms[l].value = d, n.uniformsNeedUpdate = !0), d));
|
|
469
|
+
o.push(u), r.push(l);
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
472
|
} else
|
|
473
|
-
for (const
|
|
474
|
-
const l = s[
|
|
473
|
+
for (const n of Object.keys(s)) {
|
|
474
|
+
const l = s[n];
|
|
475
475
|
if (l?.isTexture === !0) {
|
|
476
|
-
const a = this.assignTextureLODForSlot(l, e, s,
|
|
477
|
-
o.push(a), r.push(
|
|
476
|
+
const a = this.assignTextureLODForSlot(l, e, s, n);
|
|
477
|
+
o.push(a), r.push(n);
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
|
-
return Promise.all(o).then((
|
|
480
|
+
return Promise.all(o).then((n) => {
|
|
481
481
|
const l = new Array();
|
|
482
|
-
for (let a = 0; a <
|
|
483
|
-
const
|
|
484
|
-
|
|
482
|
+
for (let a = 0; a < n.length; a++) {
|
|
483
|
+
const u = n[a], d = r[a];
|
|
484
|
+
u && u.isTexture === !0 ? l.push({ material: s, slot: d, texture: u, level: e }) : l.push({ material: s, slot: d, texture: null, level: e });
|
|
485
485
|
}
|
|
486
486
|
return l;
|
|
487
487
|
});
|
|
@@ -499,20 +499,20 @@ class m {
|
|
|
499
499
|
return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."), null;
|
|
500
500
|
if (r?.isTexture === !0) {
|
|
501
501
|
if (r != t && s && o) {
|
|
502
|
-
const
|
|
503
|
-
if (
|
|
504
|
-
const l = this.getAssignedLODInformation(
|
|
502
|
+
const n = s[o];
|
|
503
|
+
if (n && !h) {
|
|
504
|
+
const l = this.getAssignedLODInformation(n);
|
|
505
505
|
if (l && l?.level < e)
|
|
506
|
-
return
|
|
506
|
+
return h === "verbose" && console.warn("Assigned texture level is already higher: ", l.level, e, s, n, r), null;
|
|
507
507
|
}
|
|
508
508
|
if (ft && r.mipmaps) {
|
|
509
509
|
const l = r.mipmaps.length;
|
|
510
|
-
r.mipmaps.length = Math.min(r.mipmaps.length, 3), l !== r.mipmaps.length &&
|
|
510
|
+
r.mipmaps.length = Math.min(r.mipmaps.length, 3), l !== r.mipmaps.length && h && console.debug(`Reduced mipmap count from ${l} to ${r.mipmaps.length} for ${r.uuid}: ${r.image?.width}x${r.image?.height}.`);
|
|
511
511
|
}
|
|
512
512
|
s[o] = r;
|
|
513
513
|
}
|
|
514
514
|
return r;
|
|
515
|
-
} else
|
|
515
|
+
} else h == "verbose" && console.warn("No LOD found for", t, e);
|
|
516
516
|
return null;
|
|
517
517
|
}).catch((r) => (console.error("Error loading LOD", t, r), null));
|
|
518
518
|
}
|
|
@@ -520,7 +520,7 @@ class m {
|
|
|
520
520
|
url;
|
|
521
521
|
constructor(t) {
|
|
522
522
|
const e = t.options.path;
|
|
523
|
-
|
|
523
|
+
h && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
|
|
524
524
|
}
|
|
525
525
|
_isLoadingMesh;
|
|
526
526
|
loadMesh = (t) => {
|
|
@@ -543,19 +543,19 @@ class m {
|
|
|
543
543
|
// });
|
|
544
544
|
// }
|
|
545
545
|
afterRoot(t) {
|
|
546
|
-
return
|
|
546
|
+
return h && console.log("AFTER", this.url, t), this.parser.json.textures?.forEach((e, s) => {
|
|
547
547
|
if (e?.extensions) {
|
|
548
548
|
const o = e?.extensions[W];
|
|
549
549
|
if (o) {
|
|
550
550
|
if (!o.lods) {
|
|
551
|
-
|
|
551
|
+
h && console.warn("Texture has no LODs", o);
|
|
552
552
|
return;
|
|
553
553
|
}
|
|
554
554
|
let r = !1;
|
|
555
|
-
for (const
|
|
556
|
-
|
|
557
|
-
r || this.parser.getDependency("texture", s).then((
|
|
558
|
-
|
|
555
|
+
for (const n of this.parser.associations.keys())
|
|
556
|
+
n.isTexture === !0 && this.parser.associations.get(n)?.textures === s && (r = !0, m.registerTexture(this.url, n, o.lods?.length, s, o));
|
|
557
|
+
r || this.parser.getDependency("texture", s).then((n) => {
|
|
558
|
+
n && m.registerTexture(this.url, n, o.lods?.length, s, o);
|
|
559
559
|
});
|
|
560
560
|
}
|
|
561
561
|
}
|
|
@@ -565,8 +565,8 @@ class m {
|
|
|
565
565
|
if (o && o.lods) {
|
|
566
566
|
for (const r of this.parser.associations.keys())
|
|
567
567
|
if (r.isMesh) {
|
|
568
|
-
const
|
|
569
|
-
|
|
568
|
+
const n = this.parser.associations.get(r);
|
|
569
|
+
n?.meshes === s && m.registerMesh(this.url, o.guid, r, o.lods.length, n.primitives, o);
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
572
|
}
|
|
@@ -577,31 +577,31 @@ class m {
|
|
|
577
577
|
*/
|
|
578
578
|
static registerTexture = (t, e, s, o, r) => {
|
|
579
579
|
if (!e) {
|
|
580
|
-
|
|
580
|
+
h && console.error("!! gltf-progressive: Called register texture without texture");
|
|
581
581
|
return;
|
|
582
582
|
}
|
|
583
|
-
if (
|
|
583
|
+
if (h) {
|
|
584
584
|
const l = e.image?.width || e.source?.data?.width || 0, a = e.image?.height || e.source?.data?.height || 0;
|
|
585
585
|
console.log(`> gltf-progressive: register texture[${o}] "${e.name || e.uuid}", Current: ${l}x${a}, Max: ${r.lods[0]?.width}x${r.lods[0]?.height}, uuid: ${e.uuid}`, r, e);
|
|
586
586
|
}
|
|
587
587
|
e.source && (e.source[le] = r);
|
|
588
|
-
const
|
|
589
|
-
m.assignLODInformation(t, e,
|
|
588
|
+
const n = r.guid;
|
|
589
|
+
m.assignLODInformation(t, e, n, s, o), m.lodInfos.set(n, r), m.lowresCache.set(n, new WeakRef(e));
|
|
590
590
|
};
|
|
591
591
|
/**
|
|
592
592
|
* Register a mesh with LOD information
|
|
593
593
|
*/
|
|
594
|
-
static registerMesh = (t, e, s, o, r,
|
|
594
|
+
static registerMesh = (t, e, s, o, r, n) => {
|
|
595
595
|
const l = s.geometry;
|
|
596
596
|
if (!l) {
|
|
597
|
-
|
|
597
|
+
h && console.warn("gltf-progressive: Register mesh without geometry");
|
|
598
598
|
return;
|
|
599
599
|
}
|
|
600
|
-
l.userData || (l.userData = {}),
|
|
601
|
-
let
|
|
602
|
-
|
|
603
|
-
for (const
|
|
604
|
-
|
|
600
|
+
l.userData || (l.userData = {}), h && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, n, s), m.assignLODInformation(t, l, e, o, r), m.lodInfos.set(e, n);
|
|
601
|
+
let u = m.lowresCache.get(e)?.deref();
|
|
602
|
+
u ? u.push(s.geometry) : u = [s.geometry], m.lowresCache.set(e, new WeakRef(u)), o > 0 && !Z(s) && ot(s, l);
|
|
603
|
+
for (const d of z)
|
|
604
|
+
d.onRegisteredNewMesh?.(s, n);
|
|
605
605
|
};
|
|
606
606
|
/**
|
|
607
607
|
* Dispose cached resources to free memory.
|
|
@@ -623,8 +623,8 @@ class m {
|
|
|
623
623
|
}
|
|
624
624
|
this.lowresCache.delete(t);
|
|
625
625
|
}
|
|
626
|
-
for (const [s, o] of this.
|
|
627
|
-
s.includes(t) && (this._disposeCacheEntry(o), this.
|
|
626
|
+
for (const [s, o] of this.cache)
|
|
627
|
+
s.includes(t) && (this._disposeCacheEntry(o), this.cache.delete(s));
|
|
628
628
|
} else {
|
|
629
629
|
this.lodInfos.clear();
|
|
630
630
|
for (const [, e] of this.lowresCache) {
|
|
@@ -637,9 +637,9 @@ class m {
|
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
639
|
this.lowresCache.clear();
|
|
640
|
-
for (const [, e] of this.
|
|
640
|
+
for (const [, e] of this.cache)
|
|
641
641
|
this._disposeCacheEntry(e);
|
|
642
|
-
this.
|
|
642
|
+
this.cache.clear();
|
|
643
643
|
}
|
|
644
644
|
}
|
|
645
645
|
/** Dispose a single cache entry's three.js resource(s) to free GPU memory. */
|
|
@@ -656,7 +656,7 @@ class m {
|
|
|
656
656
|
/** A map of key = asset uuid and value = LOD information */
|
|
657
657
|
static lodInfos = /* @__PURE__ */ new Map();
|
|
658
658
|
/** cache of already loaded mesh lods. Uses WeakRef for single resources to allow garbage collection when unused. */
|
|
659
|
-
static
|
|
659
|
+
static cache = /* @__PURE__ */ new Map();
|
|
660
660
|
/** this contains the geometry/textures that were originally loaded. Uses WeakRef to allow garbage collection when unused. */
|
|
661
661
|
static lowresCache = /* @__PURE__ */ new Map();
|
|
662
662
|
/**
|
|
@@ -665,168 +665,169 @@ class m {
|
|
|
665
665
|
* The held value is the cache key string used in `previouslyLoaded`.
|
|
666
666
|
*/
|
|
667
667
|
static _resourceRegistry = new FinalizationRegistry((t) => {
|
|
668
|
-
const e = m.
|
|
669
|
-
|
|
668
|
+
const e = m.cache.get(t);
|
|
669
|
+
h && console.debug(`[gltf-progressive] Resource GC'd
|
|
670
|
+
${t}`), e instanceof WeakRef && (e.deref() || (m.cache.delete(t), h && console.log(`[gltf-progressive] Cache entry auto-cleaned (GC'd): ${t}`)));
|
|
670
671
|
});
|
|
671
672
|
static workers = [];
|
|
672
673
|
static _workersIndex = 0;
|
|
673
674
|
static async getOrLoadLOD(t, e) {
|
|
674
|
-
const s =
|
|
675
|
+
const s = h == "verbose", o = this.getAssignedLODInformation(t);
|
|
675
676
|
if (!o)
|
|
676
|
-
return
|
|
677
|
+
return h && console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`, t), null;
|
|
677
678
|
const r = o?.key;
|
|
678
|
-
let
|
|
679
|
+
let n;
|
|
679
680
|
if (t.isTexture === !0) {
|
|
680
681
|
const a = t;
|
|
681
|
-
a.source && a.source[le] && (
|
|
682
|
+
a.source && a.source[le] && (n = a.source[le]);
|
|
682
683
|
}
|
|
683
|
-
if (
|
|
684
|
-
|
|
684
|
+
if (n || (n = m.lodInfos.get(r)), !n)
|
|
685
|
+
h && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type, m.lodInfos);
|
|
685
686
|
else {
|
|
686
687
|
if (e > 0) {
|
|
687
|
-
let
|
|
688
|
-
const y = Array.isArray(
|
|
689
|
-
if (y && e >=
|
|
688
|
+
let d = !1;
|
|
689
|
+
const y = Array.isArray(n.lods);
|
|
690
|
+
if (y && e >= n.lods.length ? d = !0 : y || (d = !0), d) {
|
|
690
691
|
const w = this.lowresCache.get(r);
|
|
691
692
|
if (w) {
|
|
692
|
-
const
|
|
693
|
-
if (
|
|
694
|
-
this.lowresCache.delete(r),
|
|
693
|
+
const _ = w.deref();
|
|
694
|
+
if (_) return _;
|
|
695
|
+
this.lowresCache.delete(r), h && console.log(`[gltf-progressive] Lowres cache entry was GC'd: ${r}`);
|
|
695
696
|
}
|
|
696
697
|
return null;
|
|
697
698
|
}
|
|
698
699
|
}
|
|
699
|
-
const a = Array.isArray(
|
|
700
|
+
const a = Array.isArray(n.lods) ? n.lods[e]?.path : n.lods;
|
|
700
701
|
if (!a)
|
|
701
|
-
return
|
|
702
|
-
const
|
|
703
|
-
if (
|
|
704
|
-
if (!
|
|
705
|
-
return console.warn("missing pointer for glb/gltf texture",
|
|
706
|
-
const
|
|
702
|
+
return h && !n["missing:uri"] && (n["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, n)), null;
|
|
703
|
+
const u = tt(o.url, a);
|
|
704
|
+
if (u.endsWith(".glb") || u.endsWith(".gltf")) {
|
|
705
|
+
if (!n.guid)
|
|
706
|
+
return console.warn("missing pointer for glb/gltf texture", n), null;
|
|
707
|
+
const d = u + "_" + n.guid, y = await this.queue.slot(u), w = this.cache.get(d);
|
|
707
708
|
if (w !== void 0)
|
|
708
|
-
if (s && console.log(`LOD ${e} was already loading/loaded: ${
|
|
709
|
+
if (s && console.log(`LOD ${e} was already loading/loaded: ${d}`), w instanceof WeakRef) {
|
|
709
710
|
const c = w.deref();
|
|
710
711
|
if (c) {
|
|
711
|
-
let
|
|
712
|
-
if (
|
|
713
|
-
return
|
|
712
|
+
let g = c, b = !1;
|
|
713
|
+
if (g instanceof F && t instanceof F ? g.image?.data || g.source?.data ? g = this.copySettings(t, g) : b = !0 : g instanceof E && t instanceof E && (g.attributes.position?.array || (b = !0)), !b)
|
|
714
|
+
return g;
|
|
714
715
|
}
|
|
715
|
-
this.
|
|
716
|
+
this.cache.delete(d), h && console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${d}`);
|
|
716
717
|
} else {
|
|
717
|
-
let c = await w.catch((b) => (console.error(`Error loading LOD ${e} from ${
|
|
718
|
-
`, b), null)),
|
|
719
|
-
if (c == null || (c instanceof F && t instanceof F ? c.image?.data || c.source?.data ? c = this.copySettings(t, c) : (
|
|
718
|
+
let c = await w.catch((b) => (console.error(`Error loading LOD ${e} from ${u}
|
|
719
|
+
`, b), null)), g = !1;
|
|
720
|
+
if (c == null || (c instanceof F && t instanceof F ? c.image?.data || c.source?.data ? c = this.copySettings(t, c) : (g = !0, this.cache.delete(d)) : c instanceof E && t instanceof E && (c.attributes.position?.array || (g = !0, this.cache.delete(d)))), !g)
|
|
720
721
|
return c;
|
|
721
722
|
}
|
|
722
723
|
if (!y.use)
|
|
723
|
-
return
|
|
724
|
-
const
|
|
724
|
+
return h && console.log(`LOD ${e} was aborted: ${u}`), null;
|
|
725
|
+
const _ = n, I = new Promise(async (c, g) => {
|
|
725
726
|
if (ct) {
|
|
726
|
-
const x = await (await
|
|
727
|
+
const x = await (await ut({})).load(u);
|
|
727
728
|
if (x.textures.length > 0)
|
|
728
729
|
for (const f of x.textures) {
|
|
729
730
|
let p = f.texture;
|
|
730
|
-
return m.assignLODInformation(o.url, p, r, e, void 0), t instanceof F && (p = this.copySettings(t, p)), p && (p.guid =
|
|
731
|
+
return m.assignLODInformation(o.url, p, r, e, void 0), t instanceof F && (p = this.copySettings(t, p)), p && (p.guid = _.guid), c(p);
|
|
731
732
|
}
|
|
732
733
|
if (x.geometries.length > 0) {
|
|
733
734
|
const f = new Array();
|
|
734
735
|
for (const p of x.geometries) {
|
|
735
|
-
const
|
|
736
|
-
m.assignLODInformation(o.url,
|
|
736
|
+
const O = p.geometry;
|
|
737
|
+
m.assignLODInformation(o.url, O, r, e, p.primitiveIndex), f.push(O);
|
|
737
738
|
}
|
|
738
739
|
return c(f);
|
|
739
740
|
}
|
|
740
741
|
return c(null);
|
|
741
742
|
}
|
|
742
743
|
const b = new ye();
|
|
743
|
-
Se(b),
|
|
744
|
-
let B =
|
|
745
|
-
if (
|
|
746
|
-
const
|
|
747
|
-
|
|
744
|
+
Se(b), h && (await new Promise((L) => setTimeout(L, 1e3)), s && console.warn("Start loading (delayed) " + u, _.guid));
|
|
745
|
+
let B = u;
|
|
746
|
+
if (_ && Array.isArray(_.lods)) {
|
|
747
|
+
const L = _.lods[e];
|
|
748
|
+
L.hash && (B += "?v=" + L.hash);
|
|
748
749
|
}
|
|
749
|
-
const
|
|
750
|
-
`,
|
|
751
|
-
if (!
|
|
750
|
+
const D = await b.loadAsync(B).catch((L) => (console.error(`Error loading LOD ${e} from ${u}
|
|
751
|
+
`, L), c(null)));
|
|
752
|
+
if (!D)
|
|
752
753
|
return c(null);
|
|
753
|
-
const N =
|
|
754
|
-
s && console.log("Loading finished " +
|
|
754
|
+
const N = D.parser;
|
|
755
|
+
s && console.log("Loading finished " + u, _.guid);
|
|
755
756
|
let P = 0;
|
|
756
|
-
if (
|
|
757
|
-
let
|
|
758
|
-
for (const x of
|
|
757
|
+
if (D.parser.json.textures) {
|
|
758
|
+
let L = !1;
|
|
759
|
+
for (const x of D.parser.json.textures) {
|
|
759
760
|
if (x?.extensions) {
|
|
760
761
|
const f = x?.extensions[W];
|
|
761
|
-
if (f?.guid && f.guid ===
|
|
762
|
-
|
|
762
|
+
if (f?.guid && f.guid === _.guid) {
|
|
763
|
+
L = !0;
|
|
763
764
|
break;
|
|
764
765
|
}
|
|
765
766
|
}
|
|
766
767
|
P++;
|
|
767
768
|
}
|
|
768
|
-
if (
|
|
769
|
+
if (L) {
|
|
769
770
|
let x = await N.getDependency("texture", P);
|
|
770
|
-
return x && m.assignLODInformation(o.url, x, r, e, void 0), s && console.log('change "' + t.name + '" → "' + x.name + '"',
|
|
771
|
-
} else
|
|
771
|
+
return x && m.assignLODInformation(o.url, x, r, e, void 0), s && console.log('change "' + t.name + '" → "' + x.name + '"', u, P, x, d), t instanceof F && (x = this.copySettings(t, x)), x && (x.guid = _.guid), c(x);
|
|
772
|
+
} else h && console.warn("Could not find texture with guid", _.guid, D.parser.json);
|
|
772
773
|
}
|
|
773
|
-
if (P = 0,
|
|
774
|
-
let
|
|
775
|
-
for (const x of
|
|
774
|
+
if (P = 0, D.parser.json.meshes) {
|
|
775
|
+
let L = !1;
|
|
776
|
+
for (const x of D.parser.json.meshes) {
|
|
776
777
|
if (x?.extensions) {
|
|
777
778
|
const f = x?.extensions[W];
|
|
778
|
-
if (f?.guid && f.guid ===
|
|
779
|
-
|
|
779
|
+
if (f?.guid && f.guid === _.guid) {
|
|
780
|
+
L = !0;
|
|
780
781
|
break;
|
|
781
782
|
}
|
|
782
783
|
}
|
|
783
784
|
P++;
|
|
784
785
|
}
|
|
785
|
-
if (
|
|
786
|
+
if (L) {
|
|
786
787
|
const x = await N.getDependency("mesh", P);
|
|
787
|
-
if (s && console.log(`Loaded Mesh "${x.name}"`,
|
|
788
|
+
if (s && console.log(`Loaded Mesh "${x.name}"`, u, P, x, d), x.isMesh === !0) {
|
|
788
789
|
const f = x.geometry;
|
|
789
790
|
return m.assignLODInformation(o.url, f, r, e, 0), c(f);
|
|
790
791
|
} else {
|
|
791
792
|
const f = new Array();
|
|
792
793
|
for (let p = 0; p < x.children.length; p++) {
|
|
793
|
-
const
|
|
794
|
-
if (
|
|
795
|
-
const S =
|
|
794
|
+
const O = x.children[p];
|
|
795
|
+
if (O.isMesh === !0) {
|
|
796
|
+
const S = O.geometry;
|
|
796
797
|
m.assignLODInformation(o.url, S, r, e, p), f.push(S);
|
|
797
798
|
}
|
|
798
799
|
}
|
|
799
800
|
return c(f);
|
|
800
801
|
}
|
|
801
|
-
} else
|
|
802
|
+
} else h && console.warn("Could not find mesh with guid", _.guid, D.parser.json);
|
|
802
803
|
}
|
|
803
804
|
return c(null);
|
|
804
805
|
});
|
|
805
|
-
this.
|
|
806
|
-
const
|
|
807
|
-
return
|
|
806
|
+
this.cache.set(d, I), y.use(I);
|
|
807
|
+
const M = await I;
|
|
808
|
+
return M != null ? M instanceof F ? (this.cache.set(d, new WeakRef(M)), m._resourceRegistry.register(M, d)) : Array.isArray(M) ? this.cache.set(d, Promise.resolve(M)) : this.cache.set(d, Promise.resolve(M)) : this.cache.set(d, Promise.resolve(null)), M;
|
|
808
809
|
} else if (t instanceof F) {
|
|
809
|
-
s && console.log("Load texture from uri: " +
|
|
810
|
-
const y = await new ze().loadAsync(
|
|
811
|
-
return y ? (y.guid =
|
|
810
|
+
s && console.log("Load texture from uri: " + u);
|
|
811
|
+
const y = await new ze().loadAsync(u);
|
|
812
|
+
return y ? (y.guid = n.guid, y.flipY = !1, y.needsUpdate = !0, y.colorSpace = t.colorSpace, s && console.log(n, y)) : h && console.warn("failed loading", u), y;
|
|
812
813
|
}
|
|
813
814
|
}
|
|
814
815
|
return null;
|
|
815
816
|
}
|
|
816
817
|
static maxConcurrent = 50;
|
|
817
|
-
static queue = new st(m.maxConcurrent, { debug:
|
|
818
|
+
static queue = new st(m.maxConcurrent, { debug: h != !1 });
|
|
818
819
|
static assignLODInformation(t, e, s, o, r) {
|
|
819
820
|
if (!e) return;
|
|
820
821
|
e.userData || (e.userData = {});
|
|
821
|
-
const
|
|
822
|
-
e.userData.LODS =
|
|
822
|
+
const n = new ht(t, s, o, r);
|
|
823
|
+
e.userData.LODS = n, "source" in e && typeof e.source == "object" && (e.source.LODS = n);
|
|
823
824
|
}
|
|
824
825
|
static getAssignedLODInformation(t) {
|
|
825
826
|
return t ? t.userData?.LODS ? t.userData.LODS : "source" in t && t.source?.LODS ? t.source.LODS : null : null;
|
|
826
827
|
}
|
|
827
828
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
828
829
|
static copySettings(t, e) {
|
|
829
|
-
return e ? (
|
|
830
|
+
return e ? (h === "verbose" && console.debug(`Copy texture settings
|
|
830
831
|
`, t.uuid, `
|
|
831
832
|
`, e.uuid), e = e.clone(), e.offset = t.offset, e.repeat = t.repeat, e.colorSpace = t.colorSpace, e.magFilter = t.magFilter, e.minFilter = t.minFilter, e.wrapS = t.wrapS, e.wrapT = t.wrapT, e.flipY = t.flipY, e.anisotropy = t.anisotropy, e.mipmaps || (e.generateMipmaps = t.generateMipmaps), e) : t;
|
|
832
833
|
}
|
|
@@ -842,7 +843,7 @@ class ht {
|
|
|
842
843
|
this.url = t, this.key = e, this.level = s, o != null && (this.index = o);
|
|
843
844
|
}
|
|
844
845
|
}
|
|
845
|
-
class
|
|
846
|
+
class ue {
|
|
846
847
|
static addPromise = (t, e, s, o) => {
|
|
847
848
|
o.forEach((r) => {
|
|
848
849
|
r.add(t, e, s);
|
|
@@ -891,7 +892,7 @@ class de {
|
|
|
891
892
|
_seen = /* @__PURE__ */ new WeakMap();
|
|
892
893
|
add(t, e, s) {
|
|
893
894
|
if (this._resolved) {
|
|
894
|
-
|
|
895
|
+
h && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
|
|
895
896
|
return;
|
|
896
897
|
}
|
|
897
898
|
if (!(this._frame_start !== void 0 && this._currentFrame > this._frame_start + this._frames_to_capture)) {
|
|
@@ -899,7 +900,7 @@ class de {
|
|
|
899
900
|
if (this._seen.has(e)) {
|
|
900
901
|
let o = this._seen.get(e);
|
|
901
902
|
if (o >= this._maxPromisesPerObject) {
|
|
902
|
-
|
|
903
|
+
h && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
|
|
903
904
|
return;
|
|
904
905
|
}
|
|
905
906
|
this._seen.set(e, o + 1);
|
|
@@ -918,7 +919,7 @@ class de {
|
|
|
918
919
|
});
|
|
919
920
|
}
|
|
920
921
|
}
|
|
921
|
-
const k = j("debugprogressive"), gt = j("noprogressive"),
|
|
922
|
+
const k = j("debugprogressive"), gt = j("noprogressive"), de = /* @__PURE__ */ Symbol("Needle:LODSManager"), ce = /* @__PURE__ */ Symbol("Needle:LODState"), U = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), T = { mesh_lod: -1, texture_lod: -1 };
|
|
922
923
|
class v {
|
|
923
924
|
/**
|
|
924
925
|
* Assign a function to draw debug lines for the LODs. This function will be called with the start and end position of the line and the color of the line when the `debugprogressive` query parameter is set.
|
|
@@ -941,17 +942,17 @@ class v {
|
|
|
941
942
|
* @returns The LODsManager instance.
|
|
942
943
|
*/
|
|
943
944
|
static get(t, e) {
|
|
944
|
-
if (t[
|
|
945
|
-
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[
|
|
945
|
+
if (t[de])
|
|
946
|
+
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[de];
|
|
946
947
|
const s = new v(t, {
|
|
947
948
|
engine: "unknown",
|
|
948
949
|
...e
|
|
949
950
|
});
|
|
950
|
-
return t[
|
|
951
|
+
return t[de] = s, s;
|
|
951
952
|
}
|
|
952
953
|
renderer;
|
|
953
954
|
context;
|
|
954
|
-
projectionScreenMatrix = new
|
|
955
|
+
projectionScreenMatrix = new _e();
|
|
955
956
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
956
957
|
get plugins() {
|
|
957
958
|
return z;
|
|
@@ -995,12 +996,12 @@ class v {
|
|
|
995
996
|
* Call to await LODs loading during the next render cycle.
|
|
996
997
|
*/
|
|
997
998
|
awaitLoading(t) {
|
|
998
|
-
const e = this._promiseGroupIds++, s = new
|
|
999
|
+
const e = this._promiseGroupIds++, s = new ue(this.#r, { ...t });
|
|
999
1000
|
this._newPromiseGroups.push(s);
|
|
1000
1001
|
const o = performance.now();
|
|
1001
1002
|
return s.ready.finally(() => {
|
|
1002
1003
|
const r = this._newPromiseGroups.indexOf(s);
|
|
1003
|
-
r >= 0 && (this._newPromiseGroups.splice(r, 1),
|
|
1004
|
+
r >= 0 && (this._newPromiseGroups.splice(r, 1), Le() && performance.measure("LODsManager:awaitLoading", {
|
|
1004
1005
|
start: o,
|
|
1005
1006
|
detail: { id: e, name: t?.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
|
|
1006
1007
|
}));
|
|
@@ -1026,10 +1027,10 @@ class v {
|
|
|
1026
1027
|
this.renderer = t, this.context = { ...e };
|
|
1027
1028
|
}
|
|
1028
1029
|
#t;
|
|
1029
|
-
#
|
|
1030
|
+
#n = new Ne();
|
|
1030
1031
|
#r = 0;
|
|
1031
1032
|
#o = 0;
|
|
1032
|
-
#
|
|
1033
|
+
#i = 0;
|
|
1033
1034
|
#s = 0;
|
|
1034
1035
|
_fpsBuffer = [60, 60, 60, 60, 60];
|
|
1035
1036
|
/**
|
|
@@ -1043,9 +1044,9 @@ class v {
|
|
|
1043
1044
|
const e = this;
|
|
1044
1045
|
xe(this.renderer), this.renderer.render = function(s, o) {
|
|
1045
1046
|
const r = e.renderer.getRenderTarget();
|
|
1046
|
-
(r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, e.#r += 1, e.#o = e.#
|
|
1047
|
-
const
|
|
1048
|
-
e.#t.call(this, s, o), e.onAfterRender(s, o,
|
|
1047
|
+
(r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, e.#r += 1, e.#o = e.#n.getDelta(), e.#i += e.#o, e._fpsBuffer.shift(), e._fpsBuffer.push(1 / e.#o), e.#s = e._fpsBuffer.reduce((l, a) => l + a) / e._fpsBuffer.length, k && e.#r % 200 === 0 && console.log("FPS", Math.round(e.#s), "Interval:", e.#e));
|
|
1048
|
+
const n = t++;
|
|
1049
|
+
e.#t.call(this, s, o), e.onAfterRender(s, o, n);
|
|
1049
1050
|
};
|
|
1050
1051
|
}
|
|
1051
1052
|
disable() {
|
|
@@ -1057,12 +1058,12 @@ class v {
|
|
|
1057
1058
|
onAfterRender(t, e, s) {
|
|
1058
1059
|
if (this.pause) return;
|
|
1059
1060
|
const r = this.renderer.renderLists.get(t, 0).opaque;
|
|
1060
|
-
let
|
|
1061
|
+
let n = !0;
|
|
1061
1062
|
if (r.length === 1) {
|
|
1062
1063
|
const l = r[0].material;
|
|
1063
|
-
(l.name === "EffectMaterial" || l.name === "CopyShader") && (
|
|
1064
|
+
(l.name === "EffectMaterial" || l.name === "CopyShader") && (n = !1);
|
|
1064
1065
|
}
|
|
1065
|
-
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (
|
|
1066
|
+
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (n = !1), n) {
|
|
1066
1067
|
if (gt || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1, k && console.warn("↓ Reducing LOD updates", this.#e, this.#s.toFixed(0))) : this.#s >= 60 && this.#e > 1 && (this.#e -= 1, k && console.warn("↑ Increasing LOD updates", this.#e, this.#s.toFixed(0))) : this.#e = this.updateInterval, this.#e > 0 && this.#r % this.#e != 0))
|
|
1067
1068
|
return;
|
|
1068
1069
|
this.internalUpdate(t, e), this._postprocessPromiseGroups();
|
|
@@ -1091,21 +1092,21 @@ class v {
|
|
|
1091
1092
|
}
|
|
1092
1093
|
if (k === "color" && a.material && !a.object.progressive_debug_color) {
|
|
1093
1094
|
a.object.progressive_debug_color = !0;
|
|
1094
|
-
const
|
|
1095
|
+
const d = Math.random() * 16777215, y = new qe({ color: d });
|
|
1095
1096
|
a.object.material = y;
|
|
1096
1097
|
}
|
|
1097
|
-
const
|
|
1098
|
-
(
|
|
1098
|
+
const u = a.object;
|
|
1099
|
+
(u instanceof V || u.isMesh) && this.updateLODs(t, e, u, r);
|
|
1099
1100
|
}
|
|
1100
|
-
const
|
|
1101
|
-
for (const a of
|
|
1102
|
-
const
|
|
1103
|
-
(
|
|
1101
|
+
const n = s.transparent;
|
|
1102
|
+
for (const a of n) {
|
|
1103
|
+
const u = a.object;
|
|
1104
|
+
(u instanceof V || u.isMesh) && this.updateLODs(t, e, u, r);
|
|
1104
1105
|
}
|
|
1105
1106
|
const l = s.transmissive;
|
|
1106
1107
|
for (const a of l) {
|
|
1107
|
-
const
|
|
1108
|
-
(
|
|
1108
|
+
const u = a.object;
|
|
1109
|
+
(u instanceof V || u.isMesh) && this.updateLODs(t, e, u, r);
|
|
1109
1110
|
}
|
|
1110
1111
|
}
|
|
1111
1112
|
/** Update the LOD levels for the renderer. */
|
|
@@ -1116,8 +1117,8 @@ class v {
|
|
|
1116
1117
|
return;
|
|
1117
1118
|
for (const l of z)
|
|
1118
1119
|
l.onBeforeUpdateLOD?.(this.renderer, t, e, s);
|
|
1119
|
-
const
|
|
1120
|
-
|
|
1120
|
+
const n = this.overrideLodLevel !== void 0 ? this.overrideLodLevel : q;
|
|
1121
|
+
n >= 0 ? (T.mesh_lod = n, T.texture_lod = n) : (this.calculateLodLevel(e, s, r, o, T), T.mesh_lod = Math.round(T.mesh_lod), T.texture_lod = Math.round(T.texture_lod)), T.mesh_lod >= 0 && this.loadProgressiveMeshes(s, T.mesh_lod), s.material && T.texture_lod >= 0 && this.loadProgressiveTextures(s.material, T.texture_lod, n), h && s.material && !s.isGizmo && Ce(s.material);
|
|
1121
1122
|
for (const l of z)
|
|
1122
1123
|
l.onAfterUpdatedLOD?.(this.renderer, t, e, s, T);
|
|
1123
1124
|
r.lastLodLevel_Mesh = T.mesh_lod, r.lastLodLevel_Texture = T.texture_lod;
|
|
@@ -1137,10 +1138,10 @@ class v {
|
|
|
1137
1138
|
let o = !1;
|
|
1138
1139
|
if ((t[U] === void 0 || e < t[U]) && (o = !0), s !== void 0 && s >= 0 && (o = t[U] != s, e = s), o) {
|
|
1139
1140
|
t[U] = e;
|
|
1140
|
-
const r = m.assignTextureLOD(t, e).then((
|
|
1141
|
+
const r = m.assignTextureLOD(t, e).then((n) => {
|
|
1141
1142
|
this._lodchangedlisteners.forEach((l) => l({ type: "texture", level: e, object: t }));
|
|
1142
1143
|
});
|
|
1143
|
-
|
|
1144
|
+
ue.addPromise("texture", t, r, this._newPromiseGroups);
|
|
1144
1145
|
}
|
|
1145
1146
|
}
|
|
1146
1147
|
/** Load progressive meshes for the given mesh
|
|
@@ -1155,8 +1156,8 @@ class v {
|
|
|
1155
1156
|
const o = t["DEBUG:LOD"];
|
|
1156
1157
|
if (o != null && (s = t[U] != o, e = o), s) {
|
|
1157
1158
|
t[U] = e;
|
|
1158
|
-
const r = t.geometry,
|
|
1159
|
-
return
|
|
1159
|
+
const r = t.geometry, n = m.assignMeshLOD(t, e).then((l) => (l && t[U] == e && r != t.geometry && this._lodchangedlisteners.forEach((a) => a({ type: "mesh", level: e, object: t })), l));
|
|
1160
|
+
return ue.addPromise("mesh", t, n, this._newPromiseGroups), n;
|
|
1160
1161
|
}
|
|
1161
1162
|
return Promise.resolve(null);
|
|
1162
1163
|
}
|
|
@@ -1164,7 +1165,7 @@ class v {
|
|
|
1164
1165
|
_sphere = new De();
|
|
1165
1166
|
_tempBox = new he();
|
|
1166
1167
|
_tempBox2 = new he();
|
|
1167
|
-
tempMatrix = new
|
|
1168
|
+
tempMatrix = new _e();
|
|
1168
1169
|
_tempWorldPosition = new C();
|
|
1169
1170
|
_tempBoxSize = new C();
|
|
1170
1171
|
_tempBox2Size = new C();
|
|
@@ -1174,8 +1175,8 @@ class v {
|
|
|
1174
1175
|
static corner3 = new C();
|
|
1175
1176
|
static _tempPtInside = new C();
|
|
1176
1177
|
static isInside(t, e) {
|
|
1177
|
-
const s = t.min, o = t.max, r = (s.x + o.x) * 0.5,
|
|
1178
|
-
return this._tempPtInside.set(r,
|
|
1178
|
+
const s = t.min, o = t.max, r = (s.x + o.x) * 0.5, n = (s.y + o.y) * 0.5;
|
|
1179
|
+
return this._tempPtInside.set(r, n, s.z).applyMatrix4(e).z < 0;
|
|
1179
1180
|
}
|
|
1180
1181
|
static skinnedMeshBoundsFrameOffsetCounter = 0;
|
|
1181
1182
|
static $skinnedMeshBoundsOffset = /* @__PURE__ */ Symbol("gltf-progressive-skinnedMeshBoundsOffset");
|
|
@@ -1192,14 +1193,14 @@ class v {
|
|
|
1192
1193
|
let l = 10 + 1, a = !1;
|
|
1193
1194
|
if (k && e["DEBUG:LOD"] != null)
|
|
1194
1195
|
return e["DEBUG:LOD"];
|
|
1195
|
-
const
|
|
1196
|
-
if (!y && !
|
|
1196
|
+
const u = m.getMeshLODExtension(e.geometry)?.lods, d = m.getPrimitiveIndex(e.geometry), y = u && u.length > 0, w = m.getMaterialMinMaxLODsCount(e.material), _ = w.min_count !== 1 / 0 && w.min_count >= 0 && w.max_count >= 0;
|
|
1197
|
+
if (!y && !_) {
|
|
1197
1198
|
r.mesh_lod = 0, r.texture_lod = 0;
|
|
1198
1199
|
return;
|
|
1199
1200
|
}
|
|
1200
1201
|
y || (a = !0, l = 0);
|
|
1201
1202
|
const I = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
1202
|
-
let
|
|
1203
|
+
let M = e.geometry.boundingBox;
|
|
1203
1204
|
if (e.type === "SkinnedMesh") {
|
|
1204
1205
|
const c = e;
|
|
1205
1206
|
if (!c.boundingBox)
|
|
@@ -1209,15 +1210,15 @@ class v {
|
|
|
1209
1210
|
const b = v.skinnedMeshBoundsFrameOffsetCounter++;
|
|
1210
1211
|
c[v.$skinnedMeshBoundsOffset] = b;
|
|
1211
1212
|
}
|
|
1212
|
-
const
|
|
1213
|
-
if ((s.frames +
|
|
1213
|
+
const g = c[v.$skinnedMeshBoundsOffset];
|
|
1214
|
+
if ((s.frames + g) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
|
|
1214
1215
|
const b = Z(c), B = c.geometry;
|
|
1215
1216
|
b && (c.geometry = b), c.computeBoundingBox(), c.geometry = B;
|
|
1216
1217
|
}
|
|
1217
1218
|
}
|
|
1218
|
-
|
|
1219
|
+
M = c.boundingBox;
|
|
1219
1220
|
}
|
|
1220
|
-
if (
|
|
1221
|
+
if (M) {
|
|
1221
1222
|
const c = t;
|
|
1222
1223
|
if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
|
|
1223
1224
|
this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
|
|
@@ -1227,67 +1228,67 @@ class v {
|
|
|
1227
1228
|
return;
|
|
1228
1229
|
}
|
|
1229
1230
|
}
|
|
1230
|
-
if (this._tempBox.copy(
|
|
1231
|
+
if (this._tempBox.copy(M), this._tempBox.applyMatrix4(e.matrixWorld), c.isPerspectiveCamera && v.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
1231
1232
|
r.mesh_lod = 0, r.texture_lod = 0;
|
|
1232
1233
|
return;
|
|
1233
1234
|
}
|
|
1234
1235
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && c.isPerspectiveCamera && c.fov > 70) {
|
|
1235
1236
|
const f = this._tempBox.min, p = this._tempBox.max;
|
|
1236
|
-
let
|
|
1237
|
-
const ee = 2,
|
|
1238
|
-
|
|
1239
|
-
const Re =
|
|
1240
|
-
s.lastCentrality = (
|
|
1237
|
+
let O = f.x, S = f.y, G = p.x, Y = p.y;
|
|
1238
|
+
const ee = 2, ne = 1.5, te = (f.x + p.x) * 0.5, se = (f.y + p.y) * 0.5;
|
|
1239
|
+
O = (O - te) * ee + te, S = (S - se) * ee + se, G = (G - te) * ee + te, Y = (Y - se) * ee + se;
|
|
1240
|
+
const Re = O < 0 && G > 0 ? 0 : Math.min(Math.abs(f.x), Math.abs(p.x)), $e = S < 0 && Y > 0 ? 0 : Math.min(Math.abs(f.y), Math.abs(p.y)), ie = Math.max(Re, $e);
|
|
1241
|
+
s.lastCentrality = (ne - ie) * (ne - ie) * (ne - ie);
|
|
1241
1242
|
} else
|
|
1242
1243
|
s.lastCentrality = 1;
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1244
|
+
const g = this._tempBox.getSize(this._tempBoxSize);
|
|
1245
|
+
g.multiplyScalar(0.5), screen.availHeight > 0 && I > 0 && g.multiplyScalar(I / screen.availHeight), t.isPerspectiveCamera ? g.x *= t.aspect : t.isOrthographicCamera;
|
|
1245
1246
|
const b = t.matrixWorldInverse, B = this._tempBox2;
|
|
1246
|
-
B.copy(
|
|
1247
|
-
const
|
|
1248
|
-
if (Math.max(
|
|
1247
|
+
B.copy(M), B.applyMatrix4(e.matrixWorld), B.applyMatrix4(b);
|
|
1248
|
+
const D = B.getSize(this._tempBox2Size), N = Math.max(D.x, D.y);
|
|
1249
|
+
if (Math.max(g.x, g.y) != 0 && N != 0 && (g.z = D.z / Math.max(D.x, D.y) * Math.max(g.x, g.y)), s.lastScreenCoverage = Math.max(g.x, g.y, g.z), s.lastScreenspaceVolume.copy(g), s.lastScreenCoverage *= s.lastCentrality, k && v.debugDrawLine) {
|
|
1249
1250
|
const f = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
1250
1251
|
f.invert();
|
|
1251
|
-
const p = v.corner0,
|
|
1252
|
-
p.copy(this._tempBox.min),
|
|
1252
|
+
const p = v.corner0, O = v.corner1, S = v.corner2, G = v.corner3;
|
|
1253
|
+
p.copy(this._tempBox.min), O.copy(this._tempBox.max), O.x = p.x, S.copy(this._tempBox.max), S.y = p.y, G.copy(this._tempBox.max);
|
|
1253
1254
|
const Y = (p.z + G.z) * 0.5;
|
|
1254
|
-
p.z =
|
|
1255
|
+
p.z = O.z = S.z = G.z = Y, p.applyMatrix4(f), O.applyMatrix4(f), S.applyMatrix4(f), G.applyMatrix4(f), v.debugDrawLine(p, O, 255), v.debugDrawLine(p, S, 255), v.debugDrawLine(O, G, 255), v.debugDrawLine(S, G, 255);
|
|
1255
1256
|
}
|
|
1256
|
-
let
|
|
1257
|
-
if (
|
|
1258
|
-
for (let f = 0; f <
|
|
1259
|
-
const p =
|
|
1260
|
-
if (
|
|
1261
|
-
|
|
1257
|
+
let L = 999;
|
|
1258
|
+
if (u && s.lastScreenCoverage > 0)
|
|
1259
|
+
for (let f = 0; f < u.length; f++) {
|
|
1260
|
+
const p = u[f], S = (p.densities?.[d] || p.density || 1e-5) / s.lastScreenCoverage;
|
|
1261
|
+
if (d > 0 && Le() && !p.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), S < o) {
|
|
1262
|
+
L = f;
|
|
1262
1263
|
break;
|
|
1263
1264
|
}
|
|
1264
1265
|
}
|
|
1265
|
-
|
|
1266
|
+
L < l && (l = L, a = !0);
|
|
1266
1267
|
}
|
|
1267
1268
|
if (a ? r.mesh_lod = l : r.mesh_lod = s.lastLodLevel_Mesh, k && r.mesh_lod != s.lastLodLevel_Mesh) {
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1269
|
+
const g = u?.[r.mesh_lod];
|
|
1270
|
+
g && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (density: ${g.densities?.[d].toFixed(0)}) | ${e.name}`);
|
|
1270
1271
|
}
|
|
1271
|
-
if (
|
|
1272
|
+
if (_) {
|
|
1272
1273
|
const c = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
1273
1274
|
if (s.lastLodLevel_Texture < 0) {
|
|
1274
1275
|
if (r.texture_lod = w.max_count - 1, k) {
|
|
1275
|
-
const
|
|
1276
|
-
k && console.log(`First Texture LOD ${r.texture_lod} (${
|
|
1276
|
+
const g = w.lods[w.max_count - 1];
|
|
1277
|
+
k && console.log(`First Texture LOD ${r.texture_lod} (${g.max_height}px) - ${e.name}`);
|
|
1277
1278
|
}
|
|
1278
1279
|
} else {
|
|
1279
|
-
const
|
|
1280
|
+
const g = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
1280
1281
|
let b = s.lastScreenCoverage * 4;
|
|
1281
1282
|
this.context?.engine === "model-viewer" && (b *= 1.5);
|
|
1282
|
-
const
|
|
1283
|
+
const D = I / window.devicePixelRatio * b;
|
|
1283
1284
|
let N = !1;
|
|
1284
1285
|
for (let P = w.lods.length - 1; P >= 0; P--) {
|
|
1285
|
-
const
|
|
1286
|
-
if (!(c &&
|
|
1286
|
+
const L = w.lods[P];
|
|
1287
|
+
if (!(c && L.max_height >= 2048) && !(Ae() && L.max_height > 4096) && (L.max_height > D || !N && P === 0)) {
|
|
1287
1288
|
if (N = !0, r.texture_lod = P, k && r.texture_lod < s.lastLodLevel_Texture) {
|
|
1288
|
-
const x =
|
|
1289
|
+
const x = L.max_height;
|
|
1289
1290
|
console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${x}px
|
|
1290
|
-
Screensize: ${
|
|
1291
|
+
Screensize: ${D.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${g.toFixed(1)}
|
|
1291
1292
|
${e.name}`);
|
|
1292
1293
|
}
|
|
1293
1294
|
break;
|
|
@@ -1309,8 +1310,8 @@ class pt {
|
|
|
1309
1310
|
const ve = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), re = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
|
|
1310
1311
|
let fe = null;
|
|
1311
1312
|
function Ie() {
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1313
|
+
const i = mt();
|
|
1314
|
+
i && (i.mapURLs(function(t) {
|
|
1314
1315
|
return be(), t;
|
|
1315
1316
|
}), be(), fe?.disconnect(), fe = new MutationObserver((t) => {
|
|
1316
1317
|
t.forEach((e) => {
|
|
@@ -1322,8 +1323,8 @@ function Ie() {
|
|
|
1322
1323
|
}
|
|
1323
1324
|
function mt() {
|
|
1324
1325
|
if (typeof customElements > "u") return null;
|
|
1325
|
-
const
|
|
1326
|
-
return
|
|
1326
|
+
const i = customElements.get("model-viewer");
|
|
1327
|
+
return i || (customElements.whenDefined("model-viewer").then(() => {
|
|
1327
1328
|
console.debug("[gltf-progressive] model-viewer defined"), Ie();
|
|
1328
1329
|
}), null);
|
|
1329
1330
|
}
|
|
@@ -1335,35 +1336,35 @@ function be() {
|
|
|
1335
1336
|
}
|
|
1336
1337
|
const Me = /* @__PURE__ */ new WeakSet();
|
|
1337
1338
|
let yt = 0;
|
|
1338
|
-
function ke(
|
|
1339
|
-
if (!
|
|
1339
|
+
function ke(i) {
|
|
1340
|
+
if (!i || Me.has(i))
|
|
1340
1341
|
return null;
|
|
1341
|
-
Me.add(
|
|
1342
|
-
`,
|
|
1342
|
+
Me.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++yt + `
|
|
1343
|
+
`, i.getAttribute("src"));
|
|
1343
1344
|
let t = null, e = null, s = null;
|
|
1344
|
-
for (let o =
|
|
1345
|
-
const r = Object.getOwnPropertySymbols(o),
|
|
1346
|
-
!t &&
|
|
1345
|
+
for (let o = i; o != null; o = Object.getPrototypeOf(o)) {
|
|
1346
|
+
const r = Object.getOwnPropertySymbols(o), n = r.find((u) => u.toString() == "Symbol(renderer)"), l = r.find((u) => u.toString() == "Symbol(scene)"), a = r.find((u) => u.toString() == "Symbol(needsRender)");
|
|
1347
|
+
!t && n != null && (t = i[n].threeRenderer), !e && l != null && (e = i[l]), !s && a != null && (s = i[a]);
|
|
1347
1348
|
}
|
|
1348
1349
|
if (t && e) {
|
|
1349
1350
|
let o = function() {
|
|
1350
1351
|
if (s) {
|
|
1351
|
-
let
|
|
1352
|
-
if (
|
|
1352
|
+
let n = 0, l = setInterval(() => {
|
|
1353
|
+
if (n++ > 5) {
|
|
1353
1354
|
clearInterval(l);
|
|
1354
1355
|
return;
|
|
1355
1356
|
}
|
|
1356
|
-
s?.call(
|
|
1357
|
+
s?.call(i);
|
|
1357
1358
|
}, 300);
|
|
1358
1359
|
}
|
|
1359
1360
|
};
|
|
1360
1361
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
1361
1362
|
const r = v.get(t, { engine: "model-viewer" });
|
|
1362
1363
|
return v.addPlugin(new xt()), r.enable(), r.addEventListener("changed", () => {
|
|
1363
|
-
s?.call(
|
|
1364
|
-
}),
|
|
1365
|
-
|
|
1366
|
-
}),
|
|
1364
|
+
s?.call(i);
|
|
1365
|
+
}), i.addEventListener("model-visibility", (n) => {
|
|
1366
|
+
n.detail.visible && s?.call(i);
|
|
1367
|
+
}), i.addEventListener("load", () => {
|
|
1367
1368
|
o();
|
|
1368
1369
|
}), () => {
|
|
1369
1370
|
r.disable();
|
|
@@ -1393,30 +1394,30 @@ class xt {
|
|
|
1393
1394
|
e[re] = !0;
|
|
1394
1395
|
const s = this.tryGetCurrentGLTF(t), o = this.tryGetCurrentModelViewer(t), r = this.getUrl(o);
|
|
1395
1396
|
if (r && s && e.material) {
|
|
1396
|
-
let
|
|
1397
|
+
let n = function(a) {
|
|
1397
1398
|
if (a[re] == !0) return;
|
|
1398
1399
|
a[re] = !0, a.userData && (a.userData.LOD = -1);
|
|
1399
|
-
const
|
|
1400
|
-
for (let
|
|
1401
|
-
const y = d
|
|
1400
|
+
const u = Object.keys(a);
|
|
1401
|
+
for (let d = 0; d < u.length; d++) {
|
|
1402
|
+
const y = u[d], w = a[y];
|
|
1402
1403
|
if (w?.isTexture === !0) {
|
|
1403
|
-
const
|
|
1404
|
-
if (
|
|
1405
|
-
const I = s.parser.json.textures[
|
|
1404
|
+
const _ = w.userData?.associations?.textures;
|
|
1405
|
+
if (_ == null) continue;
|
|
1406
|
+
const I = s.parser.json.textures[_];
|
|
1406
1407
|
if (!I) {
|
|
1407
|
-
console.warn("Texture data not found for texture index " +
|
|
1408
|
+
console.warn("Texture data not found for texture index " + _);
|
|
1408
1409
|
continue;
|
|
1409
1410
|
}
|
|
1410
1411
|
if (I?.extensions?.[W]) {
|
|
1411
|
-
const
|
|
1412
|
-
|
|
1412
|
+
const M = I.extensions[W];
|
|
1413
|
+
M && r && m.registerTexture(r, w, M.lods.length, _, M);
|
|
1413
1414
|
}
|
|
1414
1415
|
}
|
|
1415
1416
|
}
|
|
1416
1417
|
};
|
|
1417
1418
|
const l = e.material;
|
|
1418
|
-
if (Array.isArray(l)) for (const a of l)
|
|
1419
|
-
else
|
|
1419
|
+
if (Array.isArray(l)) for (const a of l) n(a);
|
|
1420
|
+
else n(l);
|
|
1420
1421
|
}
|
|
1421
1422
|
}
|
|
1422
1423
|
tryParseMeshLOD(t, e) {
|
|
@@ -1427,22 +1428,22 @@ class xt {
|
|
|
1427
1428
|
return;
|
|
1428
1429
|
const r = e.userData?.gltfExtensions?.[W];
|
|
1429
1430
|
if (r && o) {
|
|
1430
|
-
const
|
|
1431
|
-
m.registerMesh(o,
|
|
1431
|
+
const n = e.uuid;
|
|
1432
|
+
m.registerMesh(o, n, e, 0, r.lods.length, r);
|
|
1432
1433
|
}
|
|
1433
1434
|
}
|
|
1434
1435
|
}
|
|
1435
|
-
function wt(...
|
|
1436
|
+
function wt(...i) {
|
|
1436
1437
|
let t, e, s, o;
|
|
1437
|
-
switch (
|
|
1438
|
+
switch (i.length) {
|
|
1438
1439
|
case 2:
|
|
1439
|
-
[s, e] =
|
|
1440
|
+
[s, e] = i, o = {};
|
|
1440
1441
|
break;
|
|
1441
1442
|
case 3:
|
|
1442
|
-
[s, e, o] =
|
|
1443
|
+
[s, e, o] = i;
|
|
1443
1444
|
break;
|
|
1444
1445
|
case 4:
|
|
1445
|
-
[t, e, s, o] =
|
|
1446
|
+
[t, e, s, o] = i;
|
|
1446
1447
|
break;
|
|
1447
1448
|
default:
|
|
1448
1449
|
throw new Error("Invalid arguments");
|
|
@@ -1450,26 +1451,26 @@ function wt(...n) {
|
|
|
1450
1451
|
xe(e), Se(s), Te(s, {
|
|
1451
1452
|
progressive: !0,
|
|
1452
1453
|
...o?.hints
|
|
1453
|
-
}), s.register((
|
|
1454
|
+
}), s.register((n) => new m(n));
|
|
1454
1455
|
const r = v.get(e);
|
|
1455
1456
|
return o?.enableLODsManager !== !1 && r.enable(), r;
|
|
1456
1457
|
}
|
|
1457
1458
|
Ie();
|
|
1458
1459
|
if (!rt) {
|
|
1459
|
-
const
|
|
1460
|
+
const i = {
|
|
1460
1461
|
gltfProgressive: {
|
|
1461
1462
|
useNeedleProgressive: wt,
|
|
1462
1463
|
LODsManager: v,
|
|
1463
1464
|
configureLoader: Te,
|
|
1464
1465
|
getRaycastMesh: Z,
|
|
1465
|
-
useRaycastMeshes:
|
|
1466
|
+
useRaycastMeshes: nt
|
|
1466
1467
|
}
|
|
1467
1468
|
};
|
|
1468
1469
|
if (!globalThis.Needle)
|
|
1469
|
-
globalThis.Needle =
|
|
1470
|
+
globalThis.Needle = i;
|
|
1470
1471
|
else
|
|
1471
|
-
for (const t in
|
|
1472
|
-
globalThis.Needle[t] =
|
|
1472
|
+
for (const t in i)
|
|
1473
|
+
globalThis.Needle[t] = i[t];
|
|
1473
1474
|
}
|
|
1474
1475
|
export {
|
|
1475
1476
|
W as EXTENSION_NAME,
|
|
@@ -1485,5 +1486,5 @@ export {
|
|
|
1485
1486
|
Qe as setDracoDecoderLocation,
|
|
1486
1487
|
Je as setKTX2TranscoderLocation,
|
|
1487
1488
|
wt as useNeedleProgressive,
|
|
1488
|
-
|
|
1489
|
+
nt as useRaycastMeshes
|
|
1489
1490
|
};
|