@needle-tools/gltf-progressive 3.6.1 → 3.6.2
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/CHANGELOG.md +3 -0
- package/gltf-progressive.js +188 -181
- package/gltf-progressive.min.js +8 -8
- package/gltf-progressive.umd.cjs +8 -8
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/loaders.d.ts +2 -0
- package/lib/loaders.js +17 -4
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,64 +1,70 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { RedFormat as
|
|
1
|
+
import * as je from "three";
|
|
2
|
+
import { RedFormat as Ke, RedIntegerFormat as Ye, RGFormat as He, RGIntegerFormat as Qe, RGBFormat as Je, RGBAFormat as Ze, RGBAIntegerFormat as et, BufferGeometry as Y, Mesh as H, Box3 as ce, Vector3 as A, Sphere as Ge, CompressedTexture as tt, Texture as W, Matrix3 as st, InterleavedBuffer as rt, InterleavedBufferAttribute as nt, BufferAttribute as it, TextureLoader as ot, Color as Be, Matrix4 as qe } from "three";
|
|
3
3
|
import { GLTFLoader as Me } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4
|
-
import { MeshoptDecoder as
|
|
5
|
-
import { DRACOLoader as
|
|
6
|
-
import { KTX2Loader as
|
|
7
|
-
const
|
|
8
|
-
globalThis.GLTF_PROGRESSIVE_VERSION =
|
|
4
|
+
import { MeshoptDecoder as at } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
5
|
+
import { DRACOLoader as lt } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
6
|
+
import { KTX2Loader as ut } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
7
|
+
const ct = "";
|
|
8
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = ct;
|
|
9
9
|
console.debug("[gltf-progressive] version -");
|
|
10
|
-
let
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
fetch(
|
|
10
|
+
let q = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", Q = "https://cdn.needle.tools/static/three/0.179.1/basis2/";
|
|
11
|
+
const ft = q, dt = Q, We = new URL(q + "draco_decoder.js");
|
|
12
|
+
We.searchParams.append("range", "true");
|
|
13
|
+
fetch(We, {
|
|
14
14
|
method: "GET",
|
|
15
15
|
headers: {
|
|
16
16
|
Range: "bytes=0-1"
|
|
17
17
|
}
|
|
18
18
|
}).catch((i) => {
|
|
19
|
-
console.debug(`Failed to fetch remote Draco decoder from ${
|
|
19
|
+
console.debug(`Failed to fetch remote Draco decoder from ${q} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), q === ft && gt("./include/draco/"), Q === dt && pt("./include/ktx2/");
|
|
20
20
|
}).finally(() => {
|
|
21
|
-
|
|
21
|
+
be && Te();
|
|
22
22
|
});
|
|
23
|
-
const
|
|
24
|
-
dracoDecoderPath:
|
|
23
|
+
const ht = () => ({
|
|
24
|
+
dracoDecoderPath: q,
|
|
25
25
|
ktx2TranscoderPath: Q
|
|
26
26
|
});
|
|
27
|
-
function ht(i) {
|
|
28
|
-
B = i, C && C[xe] != B ? (console.debug("Updating Draco decoder path to " + i), C[xe] = B, C.setDecoderPath(B), C.preload()) : console.debug("Setting Draco decoder path to " + i);
|
|
29
|
-
}
|
|
30
27
|
function gt(i) {
|
|
31
|
-
|
|
28
|
+
q = i, C && C[xe] != q ? (console.debug("Updating Draco decoder path to " + i), C[xe] = q, C.setDecoderPath(q), C.preload()) : console.debug("Setting Draco decoder path to " + i);
|
|
29
|
+
}
|
|
30
|
+
function pt(i) {
|
|
31
|
+
Q = i, B && B.transcoderPath != Q ? (console.debug("Updating KTX2 transcoder path to " + i), B.setTranscoderPath(Q), B.init()) : console.debug("Setting KTX2 transcoder path to " + i);
|
|
32
32
|
}
|
|
33
33
|
function _e(i) {
|
|
34
|
-
|
|
34
|
+
be = !0;
|
|
35
|
+
const t = Te();
|
|
36
|
+
return i ? t.ktx2Loader.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), t;
|
|
37
|
+
}
|
|
38
|
+
function es() {
|
|
39
|
+
be = !1, C?.dispose(), B?.dispose(), C = void 0, B = void 0;
|
|
35
40
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
41
|
+
function Fe(i) {
|
|
42
|
+
const { dracoLoader: t, ktx2Loader: e, meshoptDecoder: s } = Te();
|
|
43
|
+
i.dracoLoader || i.setDRACOLoader(t), i.ktx2Loader || i.setKTX2Loader(e), i.meshoptDecoder || i.setMeshoptDecoder(s);
|
|
38
44
|
}
|
|
39
45
|
const xe = /* @__PURE__ */ Symbol("dracoDecoderPath");
|
|
40
|
-
let C,
|
|
41
|
-
function
|
|
42
|
-
C || (C = new
|
|
46
|
+
let be = !0, C, fe, B;
|
|
47
|
+
function Te() {
|
|
48
|
+
return C || (C = new lt(), C[xe] = q, C.setDecoderPath(q), C.setDecoderConfig({ type: "js" }), C.preload()), B || (B = new ut(), B.setTranscoderPath(Q), B.init()), fe || (fe = at), { dracoLoader: C, ktx2Loader: B, meshoptDecoder: fe };
|
|
43
49
|
}
|
|
44
|
-
const
|
|
45
|
-
function
|
|
46
|
-
let e =
|
|
47
|
-
e ? e = Object.assign(e, t) : e = t,
|
|
50
|
+
const Le = /* @__PURE__ */ new WeakMap();
|
|
51
|
+
function Ue(i, t) {
|
|
52
|
+
let e = Le.get(i);
|
|
53
|
+
e ? e = Object.assign(e, t) : e = t, Le.set(i, e);
|
|
48
54
|
}
|
|
49
|
-
const
|
|
50
|
-
function
|
|
51
|
-
const t =
|
|
55
|
+
const mt = Me.prototype.load;
|
|
56
|
+
function yt(...i) {
|
|
57
|
+
const t = Le.get(this);
|
|
52
58
|
let e = i[0];
|
|
53
|
-
const s =
|
|
59
|
+
const s = xt(e);
|
|
54
60
|
if (s?.hostname.endsWith("needle.tools")) {
|
|
55
61
|
const n = t?.progressive !== void 0 ? t.progressive : !0, o = t?.usecase ? t.usecase : "default";
|
|
56
62
|
n ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${o}` : this.requestHeader.Accept = `*/*;usecase=${o}`, e = s.toString();
|
|
57
63
|
}
|
|
58
|
-
return i[0] = e,
|
|
64
|
+
return i[0] = e, mt?.call(this, ...i);
|
|
59
65
|
}
|
|
60
|
-
Me.prototype.load =
|
|
61
|
-
function
|
|
66
|
+
Me.prototype.load = yt;
|
|
67
|
+
function xt(i) {
|
|
62
68
|
try {
|
|
63
69
|
if (i instanceof URL)
|
|
64
70
|
return i;
|
|
@@ -68,19 +74,19 @@ function yt(i) {
|
|
|
68
74
|
return null;
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
|
-
function
|
|
77
|
+
function Re(i) {
|
|
72
78
|
return i != null && i.data != null;
|
|
73
79
|
}
|
|
74
|
-
function
|
|
80
|
+
function we(i) {
|
|
75
81
|
const t = i.source?.data;
|
|
76
82
|
return t != null && typeof t == "object" ? t : null;
|
|
77
83
|
}
|
|
78
|
-
function
|
|
84
|
+
function Lt(i) {
|
|
79
85
|
const t = i.image;
|
|
80
86
|
return t != null && typeof t == "object" ? t : null;
|
|
81
87
|
}
|
|
82
88
|
function ve(i) {
|
|
83
|
-
const t =
|
|
89
|
+
const t = Lt(i), e = we(i);
|
|
84
90
|
return {
|
|
85
91
|
width: t?.width || e?.width || 0,
|
|
86
92
|
height: t?.height || e?.height || 0
|
|
@@ -104,19 +110,19 @@ function wt(i, t) {
|
|
|
104
110
|
}
|
|
105
111
|
return t;
|
|
106
112
|
}
|
|
107
|
-
function
|
|
113
|
+
function Oe() {
|
|
108
114
|
if (se !== void 0) return se;
|
|
109
115
|
const i = globalThis.navigator?.userAgent || "";
|
|
110
116
|
return se = /iPhone|iPad|iPod|Android|IEMobile/i.test(i), X("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", se), se;
|
|
111
117
|
}
|
|
112
118
|
let se;
|
|
113
|
-
function
|
|
119
|
+
function ze() {
|
|
114
120
|
const i = globalThis.location?.href;
|
|
115
121
|
if (!i) return !1;
|
|
116
122
|
const t = new URL(i), e = t.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(t.hostname);
|
|
117
123
|
return t.hostname === "127.0.0.1" || e;
|
|
118
124
|
}
|
|
119
|
-
class
|
|
125
|
+
class vt {
|
|
120
126
|
constructor(t, e = {}) {
|
|
121
127
|
this.maxConcurrent = t, this.debug = e.debug ?? !1, typeof globalThis.requestAnimationFrame == "function" ? globalThis.requestAnimationFrame(this.tick) : setTimeout(this.tick, 0);
|
|
122
128
|
}
|
|
@@ -150,29 +156,29 @@ class Lt {
|
|
|
150
156
|
}
|
|
151
157
|
}
|
|
152
158
|
}
|
|
153
|
-
function
|
|
154
|
-
const t = i.image, e = t?.width ?? 0, s = t?.height ?? 0, r = t?.depth ?? 1, n = Math.floor(Math.log2(Math.max(e, s, r))) + 1, o =
|
|
159
|
+
function Dt(i) {
|
|
160
|
+
const t = i.image, e = t?.width ?? 0, s = t?.height ?? 0, r = t?.depth ?? 1, n = Math.floor(Math.log2(Math.max(e, s, r))) + 1, o = Mt(i);
|
|
155
161
|
return e * s * r * o * (1 - Math.pow(0.25, n)) / (1 - 0.25);
|
|
156
162
|
}
|
|
157
|
-
function
|
|
163
|
+
function Mt(i) {
|
|
158
164
|
let t = 4;
|
|
159
165
|
const e = i.format;
|
|
160
|
-
e ===
|
|
166
|
+
e === Ke || e === Ye ? t = 1 : e === He || e === Qe ? t = 2 : e === Je || e === 1029 ? t = 3 : (e === Ze || e === et) && (t = 4);
|
|
161
167
|
let s = 1;
|
|
162
168
|
const r = i.type;
|
|
163
169
|
return r === 1009 || r === 1010 ? s = 1 : r === 1011 || r === 1012 ? s = 2 : r === 1013 || r === 1014 || r === 1015 ? s = 4 : r === 1016 && (s = 2), t * s;
|
|
164
170
|
}
|
|
165
|
-
const
|
|
171
|
+
const _t = typeof window > "u" && typeof document > "u", De = /* @__PURE__ */ Symbol("needle:raycast-mesh");
|
|
166
172
|
function ae(i) {
|
|
167
173
|
return i?.[De] instanceof Y ? i[De] : null;
|
|
168
174
|
}
|
|
169
|
-
function
|
|
175
|
+
function bt(i, t) {
|
|
170
176
|
if ((i.type === "Mesh" || i.type === "SkinnedMesh") && !ae(i)) {
|
|
171
|
-
const s =
|
|
177
|
+
const s = Ot(t);
|
|
172
178
|
s.userData = { isRaycastMesh: !0 }, i[De] = s;
|
|
173
179
|
}
|
|
174
180
|
}
|
|
175
|
-
function
|
|
181
|
+
function Tt(i = !0) {
|
|
176
182
|
if (i) {
|
|
177
183
|
if (re) return;
|
|
178
184
|
const t = re = H.prototype.raycast;
|
|
@@ -187,7 +193,7 @@ function bt(i = !0) {
|
|
|
187
193
|
}
|
|
188
194
|
}
|
|
189
195
|
let re = null;
|
|
190
|
-
function
|
|
196
|
+
function Ot(i) {
|
|
191
197
|
const t = new Y();
|
|
192
198
|
for (const e in i.attributes)
|
|
193
199
|
t.setAttribute(e, i.getAttribute(e));
|
|
@@ -206,27 +212,27 @@ if (g && typeof window < "u") {
|
|
|
206
212
|
!isNaN(s) && s >= 0 && (K = s, console.log(`Set LOD level to [${K}]`));
|
|
207
213
|
});
|
|
208
214
|
}
|
|
209
|
-
function
|
|
215
|
+
function Ee(i) {
|
|
210
216
|
if (g && oe !== void 0)
|
|
211
217
|
if (Array.isArray(i))
|
|
212
218
|
for (const t of i)
|
|
213
|
-
|
|
219
|
+
Ee(t);
|
|
214
220
|
else i && "wireframe" in i && (i.wireframe = oe === !0);
|
|
215
221
|
}
|
|
216
222
|
const ne = new Array();
|
|
217
|
-
let
|
|
218
|
-
const
|
|
219
|
-
function
|
|
220
|
-
if (ne.length <
|
|
223
|
+
let St = 0;
|
|
224
|
+
const Rt = Oe() ? 2 : 10;
|
|
225
|
+
function Ct(i) {
|
|
226
|
+
if (ne.length < Rt) {
|
|
221
227
|
const s = ne.length;
|
|
222
228
|
g && console.warn(`[Worker] Creating new worker #${s}`);
|
|
223
|
-
const r =
|
|
229
|
+
const r = Se.createWorker(i || {});
|
|
224
230
|
return ne.push(r), r;
|
|
225
231
|
}
|
|
226
|
-
const t =
|
|
232
|
+
const t = St++ % ne.length;
|
|
227
233
|
return ne[t];
|
|
228
234
|
}
|
|
229
|
-
class
|
|
235
|
+
class Se {
|
|
230
236
|
constructor(t, e) {
|
|
231
237
|
this.worker = t, this._debug = e.debug ?? !1, t.onmessage = (s) => {
|
|
232
238
|
const r = s.data;
|
|
@@ -234,7 +240,7 @@ class Te {
|
|
|
234
240
|
case "loaded-gltf":
|
|
235
241
|
for (const n of this._running)
|
|
236
242
|
if (n.url === r.result.url) {
|
|
237
|
-
|
|
243
|
+
Pt(r.result), n.resolve(r.result);
|
|
238
244
|
const o = n.url;
|
|
239
245
|
o.startsWith("blob:") && URL.revokeObjectURL(o);
|
|
240
246
|
}
|
|
@@ -253,12 +259,12 @@ class Te {
|
|
|
253
259
|
), {
|
|
254
260
|
type: "module"
|
|
255
261
|
});
|
|
256
|
-
return new
|
|
262
|
+
return new Se(e, t);
|
|
257
263
|
}
|
|
258
264
|
_running = [];
|
|
259
265
|
_webglRenderer = null;
|
|
260
266
|
async load(t, e) {
|
|
261
|
-
const s =
|
|
267
|
+
const s = ht();
|
|
262
268
|
let r = e?.renderer;
|
|
263
269
|
r || (this._webglRenderer ??= (async () => {
|
|
264
270
|
const { WebGLRenderer: u } = await import("three");
|
|
@@ -289,7 +295,7 @@ class Te {
|
|
|
289
295
|
}
|
|
290
296
|
_debug = !1;
|
|
291
297
|
}
|
|
292
|
-
function
|
|
298
|
+
function Pt(i) {
|
|
293
299
|
for (const t of i.geometries) {
|
|
294
300
|
const e = t.geometry, s = new Y();
|
|
295
301
|
if (s.name = e.name || "", e.index) {
|
|
@@ -305,7 +311,7 @@ function Ct(i) {
|
|
|
305
311
|
const o = e.morphAttributes[r].map((l) => de(l));
|
|
306
312
|
s.morphAttributes[r] = o;
|
|
307
313
|
}
|
|
308
|
-
if (s.morphTargetsRelative = e.morphTargetsRelative ?? !1, s.boundingBox = new
|
|
314
|
+
if (s.morphTargetsRelative = e.morphTargetsRelative ?? !1, s.boundingBox = new ce(), s.boundingBox.min = new A(
|
|
309
315
|
e.boundingBox?.min.x,
|
|
310
316
|
e.boundingBox?.min.y,
|
|
311
317
|
e.boundingBox?.min.z
|
|
@@ -313,7 +319,7 @@ function Ct(i) {
|
|
|
313
319
|
e.boundingBox?.max.x,
|
|
314
320
|
e.boundingBox?.max.y,
|
|
315
321
|
e.boundingBox?.max.z
|
|
316
|
-
), s.boundingSphere = new
|
|
322
|
+
), s.boundingSphere = new Ge(
|
|
317
323
|
new A(
|
|
318
324
|
e.boundingSphere?.center.x,
|
|
319
325
|
e.boundingSphere?.center.y,
|
|
@@ -330,7 +336,7 @@ function Ct(i) {
|
|
|
330
336
|
let s = null;
|
|
331
337
|
if (e.isCompressedTexture) {
|
|
332
338
|
const r = e.mipmaps, { width: n, height: o } = ve(e);
|
|
333
|
-
s = new
|
|
339
|
+
s = new tt(
|
|
334
340
|
r,
|
|
335
341
|
n,
|
|
336
342
|
o,
|
|
@@ -356,7 +362,7 @@ function Ct(i) {
|
|
|
356
362
|
e.type,
|
|
357
363
|
e.anisotropy,
|
|
358
364
|
e.colorSpace
|
|
359
|
-
), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new
|
|
365
|
+
), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new st(...e.matrix.elements);
|
|
360
366
|
if (!s) {
|
|
361
367
|
console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");
|
|
362
368
|
continue;
|
|
@@ -368,12 +374,12 @@ function Ct(i) {
|
|
|
368
374
|
function de(i) {
|
|
369
375
|
let t = i;
|
|
370
376
|
if ("isInterleavedBufferAttribute" in i && i.isInterleavedBufferAttribute) {
|
|
371
|
-
const e = i.data, s = e.array, r = new
|
|
372
|
-
t = new
|
|
373
|
-
} else "isBufferAttribute" in i && i.isBufferAttribute && (t = new
|
|
377
|
+
const e = i.data, s = e.array, r = new rt(s, e.stride);
|
|
378
|
+
t = new nt(r, i.itemSize, s.byteOffset, i.normalized), t.offset = i.offset;
|
|
379
|
+
} else "isBufferAttribute" in i && i.isBufferAttribute && (t = new it(i.array, i.itemSize, i.normalized), t.usage = i.usage, t.gpuType = i.gpuType, t.updateRanges = i.updateRanges);
|
|
374
380
|
return t;
|
|
375
381
|
}
|
|
376
|
-
const
|
|
382
|
+
const kt = X("gltf-progressive-worker");
|
|
377
383
|
X("gltf-progressive-reduce-mipmaps");
|
|
378
384
|
const ie = X("gltf-progressive-gc"), he = /* @__PURE__ */ Symbol("needle-progressive-texture"), z = "NEEDLE_progressive";
|
|
379
385
|
class p {
|
|
@@ -809,7 +815,7 @@ class p {
|
|
|
809
815
|
}
|
|
810
816
|
l.userData || (l.userData = {}), g && console.log("> Progressive: register mesh " + s.name, { index: n, uuid: s.uuid }, o, s), p.assignLODInformation(t, l, e, r, n), p.lodInfos.set(e, o);
|
|
811
817
|
let u = p.lowresCache.get(e)?.deref();
|
|
812
|
-
u ? u.push(s.geometry) : u = [s.geometry], p.lowresCache.set(e, new WeakRef(u)), r > 0 && !ae(s) &&
|
|
818
|
+
u ? u.push(s.geometry) : u = [s.geometry], p.lowresCache.set(e, new WeakRef(u)), r > 0 && !ae(s) && bt(s, l);
|
|
813
819
|
for (const d of U)
|
|
814
820
|
d.onRegisteredNewMesh?.(s, o);
|
|
815
821
|
};
|
|
@@ -912,7 +918,7 @@ ${t}`), e instanceof WeakRef && (e.deref() || (p.cache.delete(t), (g || ie) && c
|
|
|
912
918
|
let { width: a, height: u } = ve(t);
|
|
913
919
|
const d = a && u ? `${a}x${u}` : "N/A";
|
|
914
920
|
let c = "N/A";
|
|
915
|
-
a && u && (c = `~${(
|
|
921
|
+
a && u && (c = `~${(Dt(t) / (1024 * 1024)).toFixed(2)} MB`), console.log(`${o} — ${t.name} ${d} (${c}), refCount: ${s} → ${l}
|
|
916
922
|
${e}`);
|
|
917
923
|
}
|
|
918
924
|
}
|
|
@@ -939,8 +945,8 @@ ${e}`);
|
|
|
939
945
|
if (h && e >= a.lods.length ? f = !0 : h || (f = !0), f) {
|
|
940
946
|
const D = this.lowresCache.get(l);
|
|
941
947
|
if (D) {
|
|
942
|
-
const
|
|
943
|
-
if (
|
|
948
|
+
const L = D.deref();
|
|
949
|
+
if (L) return L;
|
|
944
950
|
this.lowresCache.delete(l), g && console.log(`[gltf-progressive] Lowres cache entry was GC'd: ${l}`);
|
|
945
951
|
}
|
|
946
952
|
return null;
|
|
@@ -962,9 +968,9 @@ ${e}`);
|
|
|
962
968
|
if (r !== this.cacheGeneration) return null;
|
|
963
969
|
if (s?.isCurrent?.() === !1)
|
|
964
970
|
return n && console.log(`Skipping stale LOD ${e} request after queue: ${c}`), null;
|
|
965
|
-
const
|
|
971
|
+
const L = await this.tryResolveLODCacheEntry(this.cache.get(f), f, c, t, e, n);
|
|
966
972
|
if (r !== this.cacheGeneration) return null;
|
|
967
|
-
if (
|
|
973
|
+
if (L.found) return L.value;
|
|
968
974
|
const x = this.cache.get(f);
|
|
969
975
|
if (x !== void 0) {
|
|
970
976
|
const y = await this.tryResolveLODCacheEntry(x, f, c, t, e, n);
|
|
@@ -973,13 +979,13 @@ ${e}`);
|
|
|
973
979
|
}
|
|
974
980
|
if (!D.use)
|
|
975
981
|
return g && console.log(`LOD ${e} was aborted: ${c}`), null;
|
|
976
|
-
const
|
|
977
|
-
if (
|
|
978
|
-
const m = await (await
|
|
982
|
+
const w = a, M = new Promise(async (y, O) => {
|
|
983
|
+
if (kt) {
|
|
984
|
+
const m = await (await Ct({})).load(c);
|
|
979
985
|
if (m.textures.length > 0)
|
|
980
986
|
for (const v of m.textures) {
|
|
981
987
|
let S = v.texture;
|
|
982
|
-
return p.assignLODInformation(o.url, S, l, e, void 0), t instanceof W && (S = this.copySettings(t, S)), S && (S.guid =
|
|
988
|
+
return p.assignLODInformation(o.url, S, l, e, void 0), t instanceof W && (S = this.copySettings(t, S)), S && (S.guid = w.guid), y(S);
|
|
983
989
|
}
|
|
984
990
|
if (m.geometries.length > 0) {
|
|
985
991
|
const v = new Array();
|
|
@@ -992,10 +998,10 @@ ${e}`);
|
|
|
992
998
|
return y(null);
|
|
993
999
|
}
|
|
994
1000
|
const I = new Me();
|
|
995
|
-
|
|
1001
|
+
Fe(I), g && (await new Promise((b) => setTimeout(b, 1e3)), n && console.warn("Start loading (delayed) " + c, w.guid));
|
|
996
1002
|
let P = c;
|
|
997
|
-
if (
|
|
998
|
-
const b =
|
|
1003
|
+
if (w && Array.isArray(w.lods)) {
|
|
1004
|
+
const b = w.lods[e];
|
|
999
1005
|
b.hash && (P += "?v=" + b.hash);
|
|
1000
1006
|
}
|
|
1001
1007
|
const _ = await I.loadAsync(P).catch((b) => (console.error(`Error loading LOD ${e} from ${c}
|
|
@@ -1003,14 +1009,14 @@ ${e}`);
|
|
|
1003
1009
|
if (!_)
|
|
1004
1010
|
return y(null);
|
|
1005
1011
|
const E = _.parser;
|
|
1006
|
-
n && console.log("Loading finished " + c,
|
|
1012
|
+
n && console.log("Loading finished " + c, w.guid);
|
|
1007
1013
|
let k = 0;
|
|
1008
1014
|
if (_.parser.json.textures) {
|
|
1009
1015
|
let b = !1;
|
|
1010
1016
|
for (const m of _.parser.json.textures) {
|
|
1011
1017
|
if (m?.extensions) {
|
|
1012
1018
|
const v = m?.extensions[z];
|
|
1013
|
-
if (v?.guid && v.guid ===
|
|
1019
|
+
if (v?.guid && v.guid === w.guid) {
|
|
1014
1020
|
b = !0;
|
|
1015
1021
|
break;
|
|
1016
1022
|
}
|
|
@@ -1019,15 +1025,15 @@ ${e}`);
|
|
|
1019
1025
|
}
|
|
1020
1026
|
if (b) {
|
|
1021
1027
|
let m = await E.getDependency("texture", k);
|
|
1022
|
-
return m && p.assignLODInformation(o.url, m, l, e, void 0), n && console.log('change "' + t.name + '" → "' + m.name + '"', c, k, m, f), t instanceof W && (m = this.copySettings(t, m)), m && (m.guid =
|
|
1023
|
-
} else g && console.warn("Could not find texture with guid",
|
|
1028
|
+
return m && p.assignLODInformation(o.url, m, l, e, void 0), n && console.log('change "' + t.name + '" → "' + m.name + '"', c, k, m, f), t instanceof W && (m = this.copySettings(t, m)), m && (m.guid = w.guid), y(m);
|
|
1029
|
+
} else g && console.warn("Could not find texture with guid", w.guid, _.parser.json);
|
|
1024
1030
|
}
|
|
1025
1031
|
if (k = 0, _.parser.json.meshes) {
|
|
1026
1032
|
let b = !1;
|
|
1027
1033
|
for (const m of _.parser.json.meshes) {
|
|
1028
1034
|
if (m?.extensions) {
|
|
1029
1035
|
const v = m?.extensions[z];
|
|
1030
|
-
if (v?.guid && v.guid ===
|
|
1036
|
+
if (v?.guid && v.guid === w.guid) {
|
|
1031
1037
|
b = !0;
|
|
1032
1038
|
break;
|
|
1033
1039
|
}
|
|
@@ -1050,7 +1056,7 @@ ${e}`);
|
|
|
1050
1056
|
}
|
|
1051
1057
|
return y(v);
|
|
1052
1058
|
}
|
|
1053
|
-
} else g && console.warn("Could not find mesh with guid",
|
|
1059
|
+
} else g && console.warn("Could not find mesh with guid", w.guid, _.parser.json);
|
|
1054
1060
|
}
|
|
1055
1061
|
return y(null);
|
|
1056
1062
|
});
|
|
@@ -1061,7 +1067,7 @@ ${e}`);
|
|
|
1061
1067
|
if (s?.isCurrent?.() === !1)
|
|
1062
1068
|
return n && console.log(`Skipping stale texture LOD ${e} request: ${c}`), null;
|
|
1063
1069
|
n && console.log("Load texture from uri: " + c);
|
|
1064
|
-
const h = await new
|
|
1070
|
+
const h = await new ot().loadAsync(c);
|
|
1065
1071
|
return r !== this.cacheGeneration || s?.isCurrent?.() === !1 ? (h?.dispose(), null) : (h ? (h.guid = a.guid, h.flipY = !1, h.needsUpdate = !0, h.colorSpace = t.colorSpace, n && console.log(a, h)) : g && console.warn("failed loading", c), h);
|
|
1066
1072
|
}
|
|
1067
1073
|
}
|
|
@@ -1074,7 +1080,7 @@ ${e}`);
|
|
|
1074
1080
|
const u = t.deref();
|
|
1075
1081
|
if (u) {
|
|
1076
1082
|
let d = u, c = !1;
|
|
1077
|
-
if (d instanceof W && r instanceof W ?
|
|
1083
|
+
if (d instanceof W && r instanceof W ? Re(d.image) || we(d) ? d = this.copySettings(r, d) : c = !0 : d instanceof Y && r instanceof Y && (d.attributes.position?.array || (c = !0)), !c)
|
|
1078
1084
|
return { found: !0, value: d };
|
|
1079
1085
|
}
|
|
1080
1086
|
return this.cache.delete(e), g && console.log(`[gltf-progressive] Re-loading GC'd/disposed resource: ${e}`), { found: !1 };
|
|
@@ -1083,16 +1089,16 @@ ${e}`);
|
|
|
1083
1089
|
`, u), null));
|
|
1084
1090
|
if (this.disposedRequests.has(t)) return { found: !0, value: null };
|
|
1085
1091
|
let a = !1;
|
|
1086
|
-
return l == null || (l instanceof W && r instanceof W ?
|
|
1092
|
+
return l == null || (l instanceof W && r instanceof W ? Re(l.image) || we(l) ? l = this.copySettings(r, l) : (a = !0, this.cache.delete(e)) : l instanceof Y && r instanceof Y && (l.attributes.position?.array || (a = !0, this.cache.delete(e)))), a ? { found: !1 } : { found: !0, value: l };
|
|
1087
1093
|
}
|
|
1088
1094
|
static _queue;
|
|
1089
1095
|
static get queue() {
|
|
1090
|
-
return this._queue ??= new
|
|
1096
|
+
return this._queue ??= new vt(Oe() ? 20 : 50, { debug: g != !1 });
|
|
1091
1097
|
}
|
|
1092
1098
|
static assignLODInformation(t, e, s, r, n) {
|
|
1093
1099
|
if (!e) return;
|
|
1094
1100
|
e.userData || (e.userData = {});
|
|
1095
|
-
const o = new
|
|
1101
|
+
const o = new At(t, s, r, n);
|
|
1096
1102
|
e.userData.LODS = o, "source" in e && typeof e.source == "object" && (e.source.LODS = o);
|
|
1097
1103
|
}
|
|
1098
1104
|
static getAssignedLODInformation(t) {
|
|
@@ -1105,7 +1111,7 @@ ${e}`);
|
|
|
1105
1111
|
`, 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;
|
|
1106
1112
|
}
|
|
1107
1113
|
}
|
|
1108
|
-
class
|
|
1114
|
+
class At {
|
|
1109
1115
|
url;
|
|
1110
1116
|
/** the key to lookup the LOD information */
|
|
1111
1117
|
key;
|
|
@@ -1192,7 +1198,7 @@ class le {
|
|
|
1192
1198
|
});
|
|
1193
1199
|
}
|
|
1194
1200
|
}
|
|
1195
|
-
const $ = X("debugprogressive"),
|
|
1201
|
+
const $ = X("debugprogressive"), It = $ === "colors", $t = X("noprogressive"), ge = /* @__PURE__ */ Symbol("Needle:LODSManager"), pe = /* @__PURE__ */ Symbol("Needle:LODState"), N = /* @__PURE__ */ Symbol("Needle:CurrentLOD"), Ce = je, R = { mesh_lod: -1, texture_lod: -1 }, Gt = new Be(), Pe = [
|
|
1196
1202
|
3526751,
|
|
1197
1203
|
11065402,
|
|
1198
1204
|
15978811,
|
|
@@ -1226,16 +1232,16 @@ const $ = X("debugprogressive"), At = $ === "colors", It = X("noprogressive"), g
|
|
|
1226
1232
|
5083278,
|
|
1227
1233
|
5592405
|
|
1228
1234
|
];
|
|
1229
|
-
function
|
|
1230
|
-
const i =
|
|
1235
|
+
function Bt() {
|
|
1236
|
+
const i = Ce.Timer || Ce.Clock;
|
|
1231
1237
|
return new i();
|
|
1232
1238
|
}
|
|
1233
|
-
const me = new
|
|
1234
|
-
function
|
|
1239
|
+
const me = new ce(), V = new ce(), ke = new ce(), qt = new A(), Wt = new A(), Ft = new qe(), F = new A(), Z = new A(), ee = new A(), te = new A();
|
|
1240
|
+
function Ut(i, t) {
|
|
1235
1241
|
const e = i.min, s = i.max, r = (e.x + s.x) * 0.5, n = (e.y + s.y) * 0.5;
|
|
1236
1242
|
return F.set(r, n, e.z).applyMatrix4(t).z < 0;
|
|
1237
1243
|
}
|
|
1238
|
-
function
|
|
1244
|
+
function zt(i) {
|
|
1239
1245
|
const {
|
|
1240
1246
|
geometry: t,
|
|
1241
1247
|
matrixWorld: e,
|
|
@@ -1257,7 +1263,7 @@ function Ut(i) {
|
|
|
1257
1263
|
h.level = l, h.primitiveIndex = f, h.screenCoverage = 0, h.screenspaceVolume.set(0, 0, 0), h.centrality = 1;
|
|
1258
1264
|
let D = i.boundingBox ?? t.boundingBox;
|
|
1259
1265
|
if (D || (t.computeBoundingBox(), D = t.boundingBox), !D) return h;
|
|
1260
|
-
if (me.copy(D).applyMatrix4(e), s.isPerspectiveCamera &&
|
|
1266
|
+
if (me.copy(D).applyMatrix4(e), s.isPerspectiveCamera && Ut(me, r))
|
|
1261
1267
|
return h.level = 0, h.screenCoverage = 1 / 0, h.screenspaceVolume.set(1 / 0, 1 / 0, 1 / 0), h;
|
|
1262
1268
|
if (V.copy(me).applyMatrix4(r), a && s.isPerspectiveCamera && s.fov > 70) {
|
|
1263
1269
|
const y = V.min, O = V.max;
|
|
@@ -1267,14 +1273,14 @@ function Ut(i) {
|
|
|
1267
1273
|
const S = I < 0 && _ > 0 ? 0 : Math.min(Math.abs(y.x), Math.abs(O.x)), j = P < 0 && E > 0 ? 0 : Math.min(Math.abs(y.y), Math.abs(O.y)), J = Math.max(S, j);
|
|
1268
1274
|
h.centrality = (b - J) * (b - J) * (b - J);
|
|
1269
1275
|
}
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1272
|
-
const x =
|
|
1273
|
-
|
|
1274
|
-
const T = Math.max(
|
|
1275
|
-
if (h.screenCoverage = T, h.screenspaceVolume.copy(
|
|
1276
|
+
const L = V.getSize(qt);
|
|
1277
|
+
L.multiplyScalar(0.5), globalThis.screen?.availHeight > 0 && o > 0 && L.multiplyScalar(o / globalThis.screen.availHeight), s.isPerspectiveCamera && (L.x *= s.aspect), ke.copy(D).applyMatrix4(e).applyMatrix4(s.matrixWorldInverse);
|
|
1278
|
+
const x = ke.getSize(Wt), w = Math.max(L.x, L.y), M = Math.max(x.x, x.y);
|
|
1279
|
+
w !== 0 && M !== 0 && (L.z = x.z / M * w);
|
|
1280
|
+
const T = Math.max(L.x, L.y, L.z) * h.centrality;
|
|
1281
|
+
if (h.screenCoverage = T, h.screenspaceVolume.copy(L), T <= 0) return h;
|
|
1276
1282
|
if (u) {
|
|
1277
|
-
const y =
|
|
1283
|
+
const y = Ft.copy(r);
|
|
1278
1284
|
y.invert(), F.copy(V.min), Z.copy(V.max), Z.x = F.x, ee.copy(V.max), ee.y = F.y, te.copy(V.max);
|
|
1279
1285
|
const O = (F.z + te.z) * 0.5;
|
|
1280
1286
|
F.z = Z.z = ee.z = te.z = O, F.applyMatrix4(y), Z.applyMatrix4(y), ee.applyMatrix4(y), te.applyMatrix4(y), u(F, Z, 255), u(F, ee, 255), u(Z, te, 255), u(ee, te, 255);
|
|
@@ -1282,7 +1288,7 @@ function Ut(i) {
|
|
|
1282
1288
|
if (c?.length)
|
|
1283
1289
|
for (let y = 0; y < c.length; y++) {
|
|
1284
1290
|
const O = c[y], I = O.densities?.[f] || O.density || 1e-5;
|
|
1285
|
-
if (f > 0 && d &&
|
|
1291
|
+
if (f > 0 && d && ze() && !O.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (globalThis["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.")), I / T < n) {
|
|
1286
1292
|
h.level = y;
|
|
1287
1293
|
break;
|
|
1288
1294
|
}
|
|
@@ -1325,7 +1331,7 @@ class G {
|
|
|
1325
1331
|
}
|
|
1326
1332
|
renderer;
|
|
1327
1333
|
context;
|
|
1328
|
-
projectionScreenMatrix = new
|
|
1334
|
+
projectionScreenMatrix = new qe();
|
|
1329
1335
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
1330
1336
|
get plugins() {
|
|
1331
1337
|
return U;
|
|
@@ -1398,7 +1404,7 @@ class G {
|
|
|
1398
1404
|
const r = performance.now();
|
|
1399
1405
|
return s.ready.finally(() => {
|
|
1400
1406
|
const n = this._newPromiseGroups.indexOf(s);
|
|
1401
|
-
n >= 0 && (this._newPromiseGroups.splice(n, 1),
|
|
1407
|
+
n >= 0 && (this._newPromiseGroups.splice(n, 1), ze() && performance.measure("LODsManager:awaitLoading", {
|
|
1402
1408
|
start: r,
|
|
1403
1409
|
detail: { id: e, name: t?.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
|
|
1404
1410
|
}));
|
|
@@ -1458,7 +1464,7 @@ class G {
|
|
|
1458
1464
|
#n = 0;
|
|
1459
1465
|
#o = 0;
|
|
1460
1466
|
#s = 0;
|
|
1461
|
-
#i =
|
|
1467
|
+
#i = Bt();
|
|
1462
1468
|
_fpsBuffer = [60, 60, 60, 60, 60];
|
|
1463
1469
|
/**
|
|
1464
1470
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
@@ -1508,7 +1514,7 @@ class G {
|
|
|
1508
1514
|
(l.name === "EffectMaterial" || l.name === "CopyShader") && (o = !1);
|
|
1509
1515
|
}
|
|
1510
1516
|
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (o = !1), o) {
|
|
1511
|
-
if (
|
|
1517
|
+
if ($t || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1, $ && console.warn("↓ Reducing LOD updates", this.#e, this.#s.toFixed(0))) : this.#s >= 60 && this.#e > 1 && (this.#e -= 1, $ && console.warn("↑ Increasing LOD updates", this.#e, this.#s.toFixed(0))) : this.#e = this.updateInterval, this.#e > 0 && this.#r % this.#e != 0))
|
|
1512
1518
|
return;
|
|
1513
1519
|
this.internalUpdate(t, e), this._postprocessPromiseGroups();
|
|
1514
1520
|
}
|
|
@@ -1573,12 +1579,12 @@ class G {
|
|
|
1573
1579
|
updateLODs(t, e, s, r) {
|
|
1574
1580
|
s.userData || (s.userData = {});
|
|
1575
1581
|
let n = s[pe];
|
|
1576
|
-
if (n || (n = new
|
|
1582
|
+
if (n || (n = new Et(), s[pe] = n), n.frames++ < 2)
|
|
1577
1583
|
return;
|
|
1578
1584
|
for (const l of U)
|
|
1579
1585
|
l.onBeforeUpdateLOD?.(this.renderer, t, e, s);
|
|
1580
1586
|
const o = this.overrideLodLevel !== void 0 ? this.overrideLodLevel : K;
|
|
1581
|
-
o >= 0 ? (R.mesh_lod = o, R.texture_lod = o) : (this.calculateLodLevel(e, s, n, r, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod)), R.mesh_lod >= 0 && this.loadProgressiveMeshes(s, R.mesh_lod), s.material && R.texture_lod >= 0 && this.loadProgressiveTextures(s.material, R.texture_lod, o), g && s.material && !s.isGizmo &&
|
|
1587
|
+
o >= 0 ? (R.mesh_lod = o, R.texture_lod = o) : (this.calculateLodLevel(e, s, n, r, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod)), R.mesh_lod >= 0 && this.loadProgressiveMeshes(s, R.mesh_lod), s.material && R.texture_lod >= 0 && this.loadProgressiveTextures(s.material, R.texture_lod, o), g && s.material && !s.isGizmo && Ee(s.material), It && s.material && !s.isGizmo && !s.isBatchedMesh && Ne(s.material, R.mesh_lod);
|
|
1582
1588
|
for (const l of U)
|
|
1583
1589
|
l.onAfterUpdatedLOD?.(this.renderer, t, e, s, R);
|
|
1584
1590
|
n.lastLodLevel_Mesh = R.mesh_lod, n.lastLodLevel_Texture = R.texture_lod;
|
|
@@ -1624,7 +1630,7 @@ class G {
|
|
|
1624
1630
|
return Promise.resolve(null);
|
|
1625
1631
|
}
|
|
1626
1632
|
// private testIfLODLevelsAreAvailable() {
|
|
1627
|
-
_sphere = new
|
|
1633
|
+
_sphere = new Ge();
|
|
1628
1634
|
_tempWorldPosition = new A();
|
|
1629
1635
|
static skinnedMeshBoundsFrameOffsetCounter = 0;
|
|
1630
1636
|
static $skinnedMeshBoundsOffset = /* @__PURE__ */ Symbol("gltf-progressive-skinnedMeshBoundsOffset");
|
|
@@ -1648,7 +1654,7 @@ class G {
|
|
|
1648
1654
|
}
|
|
1649
1655
|
c || (a = !0, l = 0);
|
|
1650
1656
|
const D = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
1651
|
-
let
|
|
1657
|
+
let L = e.geometry.boundingBox;
|
|
1652
1658
|
if (e.type === "SkinnedMesh") {
|
|
1653
1659
|
const x = e;
|
|
1654
1660
|
if (!x.boundingBox)
|
|
@@ -1658,15 +1664,15 @@ class G {
|
|
|
1658
1664
|
const M = G.skinnedMeshBoundsFrameOffsetCounter++;
|
|
1659
1665
|
x[G.$skinnedMeshBoundsOffset] = M;
|
|
1660
1666
|
}
|
|
1661
|
-
const
|
|
1662
|
-
if ((s.frames +
|
|
1667
|
+
const w = x[G.$skinnedMeshBoundsOffset];
|
|
1668
|
+
if ((s.frames + w) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
|
|
1663
1669
|
const M = ae(x), T = x.geometry;
|
|
1664
1670
|
M && (x.geometry = M), x.computeBoundingBox(), x.geometry = T;
|
|
1665
1671
|
}
|
|
1666
1672
|
}
|
|
1667
|
-
|
|
1673
|
+
L = x.boundingBox;
|
|
1668
1674
|
}
|
|
1669
|
-
if (
|
|
1675
|
+
if (L) {
|
|
1670
1676
|
if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
|
|
1671
1677
|
this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
|
|
1672
1678
|
const M = t.getWorldPosition(this._tempWorldPosition);
|
|
@@ -1675,7 +1681,7 @@ class G {
|
|
|
1675
1681
|
return;
|
|
1676
1682
|
}
|
|
1677
1683
|
}
|
|
1678
|
-
const x =
|
|
1684
|
+
const x = zt({
|
|
1679
1685
|
geometry: e.geometry,
|
|
1680
1686
|
matrixWorld: e.matrixWorld,
|
|
1681
1687
|
camera: t,
|
|
@@ -1683,7 +1689,7 @@ class G {
|
|
|
1683
1689
|
desiredDensity: r,
|
|
1684
1690
|
canvasHeight: D,
|
|
1685
1691
|
currentLevel: s.lastLodLevel_Mesh,
|
|
1686
|
-
boundingBox:
|
|
1692
|
+
boundingBox: L,
|
|
1687
1693
|
xrEnabled: this.renderer.xr.enabled,
|
|
1688
1694
|
debugDrawLine: $ ? G.debugDrawLine : void 0,
|
|
1689
1695
|
warnMissingPrimitiveDensities: !0
|
|
@@ -1695,29 +1701,29 @@ class G {
|
|
|
1695
1701
|
x.level >= 0 && x.level < l && (l = x.level, a = !0);
|
|
1696
1702
|
}
|
|
1697
1703
|
if (a ? n.mesh_lod = l : n.mesh_lod = s.lastLodLevel_Mesh, $ && n.mesh_lod != s.lastLodLevel_Mesh) {
|
|
1698
|
-
const
|
|
1699
|
-
|
|
1704
|
+
const w = u?.[n.mesh_lod];
|
|
1705
|
+
w && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${n.mesh_lod} (density: ${w.densities?.[d].toFixed(0)}) | ${e.name}`);
|
|
1700
1706
|
}
|
|
1701
1707
|
if (h) {
|
|
1702
1708
|
const x = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
1703
1709
|
if (s.lastLodLevel_Texture < 0) {
|
|
1704
1710
|
if (n.texture_lod = f.max_count - 1, $) {
|
|
1705
|
-
const
|
|
1706
|
-
$ && console.log(`First Texture LOD ${n.texture_lod} (${
|
|
1711
|
+
const w = f.lods[f.max_count - 1];
|
|
1712
|
+
$ && console.log(`First Texture LOD ${n.texture_lod} (${w.max_height}px) - ${e.name}`);
|
|
1707
1713
|
}
|
|
1708
1714
|
} else {
|
|
1709
|
-
const
|
|
1715
|
+
const w = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
1710
1716
|
let M = s.lastScreenCoverage * 4;
|
|
1711
1717
|
this.context?.engine === "model-viewer" && (M *= 1.5);
|
|
1712
1718
|
const T = this.renderer.getPixelRatio?.() || globalThis.devicePixelRatio || 1, O = D / T * M;
|
|
1713
1719
|
let I = !1;
|
|
1714
1720
|
for (let P = f.lods.length - 1; P >= 0; P--) {
|
|
1715
1721
|
const _ = f.lods[P];
|
|
1716
|
-
if (!(x && _.max_height >= 2048) && !(
|
|
1722
|
+
if (!(x && _.max_height >= 2048) && !(Oe() && _.max_height > 4096) && (_.max_height > O || !I && P === 0)) {
|
|
1717
1723
|
if (I = !0, n.texture_lod = P, $ && n.texture_lod < s.lastLodLevel_Texture) {
|
|
1718
1724
|
const E = _.max_height;
|
|
1719
1725
|
console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${n.texture_lod} = ${E}px
|
|
1720
|
-
Screensize: ${O.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${
|
|
1726
|
+
Screensize: ${O.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${w.toFixed(1)}
|
|
1721
1727
|
${e.name}`);
|
|
1722
1728
|
}
|
|
1723
1729
|
break;
|
|
@@ -1728,7 +1734,7 @@ ${e.name}`);
|
|
|
1728
1734
|
n.texture_lod = 0;
|
|
1729
1735
|
}
|
|
1730
1736
|
}
|
|
1731
|
-
class
|
|
1737
|
+
class Et {
|
|
1732
1738
|
frames = 0;
|
|
1733
1739
|
lastLodLevel_Mesh = -1;
|
|
1734
1740
|
lastLodLevel_Texture = -1;
|
|
@@ -1736,53 +1742,53 @@ class zt {
|
|
|
1736
1742
|
lastScreenspaceVolume = new A();
|
|
1737
1743
|
lastCentrality = 0;
|
|
1738
1744
|
}
|
|
1739
|
-
function
|
|
1745
|
+
function Ne(i, t) {
|
|
1740
1746
|
if (!(t < 0)) {
|
|
1741
1747
|
if (Array.isArray(i)) {
|
|
1742
1748
|
for (const e of i)
|
|
1743
|
-
|
|
1749
|
+
Ne(e, t);
|
|
1744
1750
|
return;
|
|
1745
1751
|
}
|
|
1746
|
-
"color" in i && i.color instanceof
|
|
1752
|
+
"color" in i && i.color instanceof Be && (i.color.copy(Nt(t, Gt)), i.needsUpdate = !0);
|
|
1747
1753
|
}
|
|
1748
1754
|
}
|
|
1749
|
-
function
|
|
1750
|
-
const e = Math.max(0, Math.min(
|
|
1751
|
-
return t.setHex(
|
|
1755
|
+
function Nt(i, t) {
|
|
1756
|
+
const e = Math.max(0, Math.min(Pe.length - 1, Math.floor(i)));
|
|
1757
|
+
return t.setHex(Pe[e]);
|
|
1752
1758
|
}
|
|
1753
|
-
const
|
|
1759
|
+
const Ae = /* @__PURE__ */ Symbol("NEEDLE_mesh_lod"), ue = /* @__PURE__ */ Symbol("NEEDLE_texture_lod");
|
|
1754
1760
|
let ye = null;
|
|
1755
|
-
function
|
|
1756
|
-
const i =
|
|
1761
|
+
function Ve() {
|
|
1762
|
+
const i = Vt();
|
|
1757
1763
|
i && (i.mapURLs(function(t) {
|
|
1758
|
-
return
|
|
1759
|
-
}),
|
|
1764
|
+
return Ie(), t;
|
|
1765
|
+
}), Ie(), ye?.disconnect(), ye = new MutationObserver((t) => {
|
|
1760
1766
|
t.forEach((e) => {
|
|
1761
1767
|
e.addedNodes.forEach((s) => {
|
|
1762
|
-
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" &&
|
|
1768
|
+
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Xe(s);
|
|
1763
1769
|
});
|
|
1764
1770
|
});
|
|
1765
1771
|
}), ye.observe(document, { childList: !0, subtree: !0 }));
|
|
1766
1772
|
}
|
|
1767
|
-
function
|
|
1773
|
+
function Vt() {
|
|
1768
1774
|
if (typeof customElements > "u") return null;
|
|
1769
1775
|
const i = customElements.get("model-viewer");
|
|
1770
1776
|
return i || (customElements.whenDefined("model-viewer").then(() => {
|
|
1771
|
-
console.debug("[gltf-progressive] model-viewer defined"),
|
|
1777
|
+
console.debug("[gltf-progressive] model-viewer defined"), Ve();
|
|
1772
1778
|
}), null);
|
|
1773
1779
|
}
|
|
1774
|
-
function
|
|
1780
|
+
function Ie() {
|
|
1775
1781
|
if (typeof document > "u") return;
|
|
1776
1782
|
document.querySelectorAll("model-viewer").forEach((t) => {
|
|
1777
|
-
|
|
1783
|
+
Xe(t);
|
|
1778
1784
|
});
|
|
1779
1785
|
}
|
|
1780
|
-
const
|
|
1781
|
-
let
|
|
1782
|
-
function
|
|
1783
|
-
if (!i ||
|
|
1786
|
+
const $e = /* @__PURE__ */ new WeakSet();
|
|
1787
|
+
let Xt = 0;
|
|
1788
|
+
function Xe(i) {
|
|
1789
|
+
if (!i || $e.has(i))
|
|
1784
1790
|
return null;
|
|
1785
|
-
|
|
1791
|
+
$e.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++Xt + `
|
|
1786
1792
|
`, i.getAttribute("src"));
|
|
1787
1793
|
let t = null, e = null, s = null;
|
|
1788
1794
|
for (let r = i; r != null; r = Object.getPrototypeOf(r)) {
|
|
@@ -1804,7 +1810,7 @@ function Ve(i) {
|
|
|
1804
1810
|
};
|
|
1805
1811
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
1806
1812
|
const n = G.get(t, { engine: "model-viewer" });
|
|
1807
|
-
return G.addPlugin(new
|
|
1813
|
+
return G.addPlugin(new jt()), n.enable(), n.addEventListener("changed", () => {
|
|
1808
1814
|
s?.call(i);
|
|
1809
1815
|
}), i.addEventListener("model-visibility", (o) => {
|
|
1810
1816
|
o.detail.visible && s?.call(i);
|
|
@@ -1816,7 +1822,7 @@ function Ve(i) {
|
|
|
1816
1822
|
}
|
|
1817
1823
|
return null;
|
|
1818
1824
|
}
|
|
1819
|
-
class
|
|
1825
|
+
class jt {
|
|
1820
1826
|
_didWarnAboutMissingUrl = !1;
|
|
1821
1827
|
onBeforeUpdateLOD(t, e, s, r) {
|
|
1822
1828
|
this.tryParseMeshLOD(e, r), this.tryParseTextureLOD(e, r);
|
|
@@ -1853,8 +1859,8 @@ class Xt {
|
|
|
1853
1859
|
continue;
|
|
1854
1860
|
}
|
|
1855
1861
|
if (D?.extensions?.[z]) {
|
|
1856
|
-
const
|
|
1857
|
-
|
|
1862
|
+
const L = D.extensions[z];
|
|
1863
|
+
L && n && p.registerTexture(n, f, L.lods.length, h, L);
|
|
1858
1864
|
}
|
|
1859
1865
|
}
|
|
1860
1866
|
}
|
|
@@ -1865,8 +1871,8 @@ class Xt {
|
|
|
1865
1871
|
}
|
|
1866
1872
|
}
|
|
1867
1873
|
tryParseMeshLOD(t, e) {
|
|
1868
|
-
if (e[
|
|
1869
|
-
e[
|
|
1874
|
+
if (e[Ae] == !0) return;
|
|
1875
|
+
e[Ae] = !0;
|
|
1870
1876
|
const s = this.tryGetCurrentModelViewer(t), r = this.getUrl(s);
|
|
1871
1877
|
if (!r)
|
|
1872
1878
|
return;
|
|
@@ -1877,7 +1883,7 @@ class Xt {
|
|
|
1877
1883
|
}
|
|
1878
1884
|
}
|
|
1879
1885
|
}
|
|
1880
|
-
function
|
|
1886
|
+
function Kt(...i) {
|
|
1881
1887
|
let t, e, s, r;
|
|
1882
1888
|
switch (i.length) {
|
|
1883
1889
|
case 2:
|
|
@@ -1892,22 +1898,22 @@ function jt(...i) {
|
|
|
1892
1898
|
default:
|
|
1893
1899
|
throw new Error("Invalid arguments");
|
|
1894
1900
|
}
|
|
1895
|
-
_e(e),
|
|
1901
|
+
_e(e), Fe(s), Ue(s, {
|
|
1896
1902
|
progressive: !0,
|
|
1897
1903
|
...r?.hints
|
|
1898
1904
|
}), s.register((o) => new p(o));
|
|
1899
1905
|
const n = G.get(e);
|
|
1900
1906
|
return r?.enableLODsManager !== !1 && n.enable(), n;
|
|
1901
1907
|
}
|
|
1902
|
-
|
|
1903
|
-
if (!
|
|
1908
|
+
Ve();
|
|
1909
|
+
if (!_t) {
|
|
1904
1910
|
const i = {
|
|
1905
1911
|
gltfProgressive: {
|
|
1906
|
-
useNeedleProgressive:
|
|
1912
|
+
useNeedleProgressive: Kt,
|
|
1907
1913
|
LODsManager: G,
|
|
1908
|
-
configureLoader:
|
|
1914
|
+
configureLoader: Ue,
|
|
1909
1915
|
getRaycastMesh: ae,
|
|
1910
|
-
useRaycastMeshes:
|
|
1916
|
+
useRaycastMeshes: Tt
|
|
1911
1917
|
}
|
|
1912
1918
|
};
|
|
1913
1919
|
if (!globalThis.Needle)
|
|
@@ -1920,18 +1926,19 @@ export {
|
|
|
1920
1926
|
z as EXTENSION_NAME,
|
|
1921
1927
|
G as LODsManager,
|
|
1922
1928
|
p as NEEDLE_progressive,
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1929
|
+
ct as VERSION,
|
|
1930
|
+
Fe as addDracoAndKTX2Loaders,
|
|
1931
|
+
zt as calculateMeshLODLevel,
|
|
1932
|
+
Ue as configureLoader,
|
|
1927
1933
|
_e as createLoaders,
|
|
1928
|
-
|
|
1934
|
+
es as disposeLoaders,
|
|
1935
|
+
Nt as getLODColor,
|
|
1929
1936
|
ae as getRaycastMesh,
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
+
Pe as lodDebugColors,
|
|
1938
|
+
Ve as patchModelViewer,
|
|
1939
|
+
bt as registerRaycastMesh,
|
|
1940
|
+
gt as setDracoDecoderLocation,
|
|
1941
|
+
pt as setKTX2TranscoderLocation,
|
|
1942
|
+
Kt as useNeedleProgressive,
|
|
1943
|
+
Tt as useRaycastMeshes
|
|
1937
1944
|
};
|