@needle-tools/gltf-progressive 1.2.15 → 2.0.0-alpha
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 +253 -232
- package/gltf-progressive.min.js +7 -7
- package/gltf-progressive.umd.cjs +7 -7
- package/lib/index.d.ts +12 -4
- package/lib/index.js +6 -3
- package/lib/loaders.d.ts +8 -0
- package/lib/loaders.js +33 -0
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,53 +1,70 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var d = (
|
|
4
|
-
if (!t.has(
|
|
1
|
+
var Ve = Object.defineProperty;
|
|
2
|
+
var Ne = (o, t, e) => t in o ? Ve(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
|
+
var d = (o, t, e) => (Ne(o, typeof t != "symbol" ? t + "" : t, e), e), Te = (o, t, e) => {
|
|
4
|
+
if (!t.has(o))
|
|
5
5
|
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var m = (
|
|
8
|
-
if (t.has(
|
|
7
|
+
var m = (o, t, e) => (Te(o, t, "read from private field"), e ? e.call(o) : t.get(o)), K = (o, t, e) => {
|
|
8
|
+
if (t.has(o))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
-
t instanceof WeakSet ? t.add(
|
|
11
|
-
}, U = (
|
|
12
|
-
import { BufferGeometry as ge, Mesh as H, Material as
|
|
13
|
-
import { GLTFLoader as
|
|
14
|
-
import { MeshoptDecoder as
|
|
15
|
-
import { DRACOLoader as
|
|
16
|
-
import { KTX2Loader as
|
|
17
|
-
const
|
|
18
|
-
globalThis.GLTF_PROGRESSIVE_VERSION =
|
|
19
|
-
console.debug(`[gltf-progressive] version ${
|
|
10
|
+
t instanceof WeakSet ? t.add(o) : t.set(o, e);
|
|
11
|
+
}, U = (o, t, e, s) => (Te(o, t, "write to private field"), s ? s.call(o, e) : t.set(o, e), e);
|
|
12
|
+
import { BufferGeometry as ge, Mesh as H, Material as We, Texture as se, TextureLoader as qe, Matrix4 as Ae, Clock as Xe, MeshStandardMaterial as Ke, Sphere as Ye, Box3 as Ee, Vector3 as z } from "three";
|
|
13
|
+
import { GLTFLoader as be } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
14
|
+
import { MeshoptDecoder as He } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
15
|
+
import { DRACOLoader as Je } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
16
|
+
import { KTX2Loader as Qe } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
17
|
+
const Ie = "";
|
|
18
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = Ie;
|
|
19
|
+
console.debug(`[gltf-progressive] version ${Ie}`);
|
|
20
20
|
let j = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", ae = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
21
|
-
const
|
|
22
|
-
fetch(j + "draco_decoder.js", { method: "head" }).catch((
|
|
23
|
-
j ===
|
|
21
|
+
const Ze = j, je = ae;
|
|
22
|
+
fetch(j + "draco_decoder.js", { method: "head" }).catch((o) => {
|
|
23
|
+
j === Ze && (j = "./include/draco/"), ae === je && (ae = "./include/ktx2/");
|
|
24
24
|
});
|
|
25
|
-
function
|
|
26
|
-
j =
|
|
25
|
+
function xt(o) {
|
|
26
|
+
j = o;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
ae =
|
|
28
|
+
function Lt(o) {
|
|
29
|
+
ae = o;
|
|
30
30
|
}
|
|
31
31
|
let Q, he, Z;
|
|
32
|
-
function
|
|
33
|
-
return Q || (Q = new
|
|
32
|
+
function Re(o) {
|
|
33
|
+
return Q || (Q = new Je(), Q.setDecoderPath(j), Q.setDecoderConfig({ type: "js" })), Z || (Z = new Qe(), Z.setTranscoderPath(ae)), he || (he = He), o ? Z.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: Q, ktx2Loader: Z, meshoptDecoder: he };
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
35
|
+
function Ge(o) {
|
|
36
|
+
o.dracoLoader || o.setDRACOLoader(Q), o.ktx2Loader || o.setKTX2Loader(Z), o.meshoptDecoder || o.setMeshoptDecoder(he);
|
|
37
37
|
}
|
|
38
|
+
const Oe = /* @__PURE__ */ new WeakMap();
|
|
39
|
+
function et(o, t) {
|
|
40
|
+
let e = Oe.get(o);
|
|
41
|
+
e ? e = Object.assign(e, t) : e = t, Oe.set(o, e);
|
|
42
|
+
}
|
|
43
|
+
const Me = be.prototype.load;
|
|
44
|
+
function tt(...o) {
|
|
45
|
+
const t = Oe.get(this);
|
|
46
|
+
let e = o[0];
|
|
47
|
+
const s = new URL(e, window.location.href);
|
|
48
|
+
if (s.hostname.endsWith("needle.tools")) {
|
|
49
|
+
const r = t ? t.progressive : !0, i = t ? t.usecase : "default";
|
|
50
|
+
r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${i}` : this.requestHeader.Accept = `*/*;usecase=${i}`, e = s.toString();
|
|
51
|
+
}
|
|
52
|
+
return o[0] = e, Me == null ? void 0 : Me.call(this, ...o);
|
|
53
|
+
}
|
|
54
|
+
be.prototype.load = tt;
|
|
38
55
|
le("debugprogressive");
|
|
39
|
-
function le(
|
|
56
|
+
function le(o) {
|
|
40
57
|
if (typeof window > "u")
|
|
41
58
|
return !1;
|
|
42
|
-
const e = new URL(window.location.href).searchParams.get(
|
|
59
|
+
const e = new URL(window.location.href).searchParams.get(o);
|
|
43
60
|
return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
|
|
44
61
|
}
|
|
45
|
-
function
|
|
46
|
-
if (t === void 0 || t.startsWith("./") || t.startsWith("http") ||
|
|
62
|
+
function st(o, t) {
|
|
63
|
+
if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
|
|
47
64
|
return t;
|
|
48
|
-
const e =
|
|
65
|
+
const e = o.lastIndexOf("/");
|
|
49
66
|
if (e >= 0) {
|
|
50
|
-
const s =
|
|
67
|
+
const s = o.substring(0, e + 1);
|
|
51
68
|
for (; s.endsWith("/") && t.startsWith("/"); )
|
|
52
69
|
t = t.substring(1);
|
|
53
70
|
return s + t;
|
|
@@ -55,21 +72,21 @@ function Ze(a, t) {
|
|
|
55
72
|
return t;
|
|
56
73
|
}
|
|
57
74
|
let re;
|
|
58
|
-
function
|
|
75
|
+
function rt() {
|
|
59
76
|
return re !== void 0 || (re = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), le("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", re)), re;
|
|
60
77
|
}
|
|
61
|
-
const
|
|
62
|
-
function me(
|
|
63
|
-
return (
|
|
78
|
+
const _e = Symbol("needle:raycast-mesh");
|
|
79
|
+
function me(o) {
|
|
80
|
+
return (o == null ? void 0 : o[_e]) instanceof ge ? o[_e] : null;
|
|
64
81
|
}
|
|
65
|
-
function
|
|
66
|
-
if ((
|
|
67
|
-
const s =
|
|
68
|
-
s.userData = { isRaycastMesh: !0 },
|
|
82
|
+
function it(o, t) {
|
|
83
|
+
if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !me(o)) {
|
|
84
|
+
const s = nt(t);
|
|
85
|
+
s.userData = { isRaycastMesh: !0 }, o[_e] = s;
|
|
69
86
|
}
|
|
70
87
|
}
|
|
71
|
-
function
|
|
72
|
-
if (
|
|
88
|
+
function Mt(o = !0) {
|
|
89
|
+
if (o) {
|
|
73
90
|
if (ie)
|
|
74
91
|
return;
|
|
75
92
|
const t = ie = H.prototype.raycast;
|
|
@@ -85,21 +102,21 @@ function yt(a = !0) {
|
|
|
85
102
|
}
|
|
86
103
|
}
|
|
87
104
|
let ie = null;
|
|
88
|
-
function
|
|
105
|
+
function nt(o) {
|
|
89
106
|
const t = new ge();
|
|
90
|
-
for (const e in
|
|
91
|
-
t.setAttribute(e,
|
|
92
|
-
return t.setIndex(
|
|
107
|
+
for (const e in o.attributes)
|
|
108
|
+
t.setAttribute(e, o.getAttribute(e));
|
|
109
|
+
return t.setIndex(o.getIndex()), t;
|
|
93
110
|
}
|
|
94
|
-
const Y = new Array(), V = "NEEDLE_progressive", x = le("debugprogressive"),
|
|
111
|
+
const Y = new Array(), V = "NEEDLE_progressive", x = le("debugprogressive"), De = Symbol("needle-progressive-texture"), oe = /* @__PURE__ */ new Map(), Se = /* @__PURE__ */ new Set();
|
|
95
112
|
if (x) {
|
|
96
|
-
let
|
|
113
|
+
let o = function() {
|
|
97
114
|
t += 1, console.log("Toggle LOD level", t, oe), oe.forEach((n, r) => {
|
|
98
115
|
for (const i of n.keys) {
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
if (
|
|
102
|
-
const l = _.getMeshLODInformation(
|
|
116
|
+
const a = r[i];
|
|
117
|
+
if (a != null) {
|
|
118
|
+
if (a.isBufferGeometry === !0) {
|
|
119
|
+
const l = _.getMeshLODInformation(a), u = l ? Math.min(t, l.lods.length) : 0;
|
|
103
120
|
r["DEBUG:LOD"] = t, _.assignMeshLOD(r, u), l && (e = Math.max(e, l.lods.length - 1));
|
|
104
121
|
} else if (r.isMaterial === !0) {
|
|
105
122
|
r["DEBUG:LOD"] = t, _.assignTextureLOD(r, t);
|
|
@@ -110,17 +127,17 @@ if (x) {
|
|
|
110
127
|
}), t >= e && (t = -1);
|
|
111
128
|
}, t = -1, e = 2, s = !1;
|
|
112
129
|
window.addEventListener("keyup", (n) => {
|
|
113
|
-
n.key === "p" &&
|
|
130
|
+
n.key === "p" && o(), n.key === "w" && (s = !s, Se && Se.forEach((r) => {
|
|
114
131
|
r.name != "BackgroundCubeMaterial" && r.glyphMap == null && "wireframe" in r && (r.wireframe = s);
|
|
115
132
|
}));
|
|
116
133
|
});
|
|
117
134
|
}
|
|
118
|
-
function
|
|
135
|
+
function Pe(o, t, e) {
|
|
119
136
|
var n;
|
|
120
137
|
if (!x)
|
|
121
138
|
return;
|
|
122
|
-
oe.has(
|
|
123
|
-
const s = oe.get(
|
|
139
|
+
oe.has(o) || oe.set(o, { keys: [], sourceId: e });
|
|
140
|
+
const s = oe.get(o);
|
|
124
141
|
((n = s == null ? void 0 : s.keys) == null ? void 0 : n.includes(t)) == !1 && s.keys.push(t);
|
|
125
142
|
}
|
|
126
143
|
const v = class {
|
|
@@ -157,24 +174,24 @@ const v = class {
|
|
|
157
174
|
max_count: 0,
|
|
158
175
|
lods: []
|
|
159
176
|
}), Array.isArray(t)) {
|
|
160
|
-
for (const
|
|
161
|
-
this.getMaterialMinMaxLODsCount(
|
|
177
|
+
for (const a of t)
|
|
178
|
+
this.getMaterialMinMaxLODsCount(a, e);
|
|
162
179
|
return t[n] = e, e;
|
|
163
180
|
}
|
|
164
181
|
if (x === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
|
|
165
|
-
const
|
|
166
|
-
for (const l of Object.keys(
|
|
167
|
-
const u =
|
|
182
|
+
const a = t;
|
|
183
|
+
for (const l of Object.keys(a.uniforms)) {
|
|
184
|
+
const u = a.uniforms[l].value;
|
|
168
185
|
(u == null ? void 0 : u.isTexture) === !0 && i(u, e);
|
|
169
186
|
}
|
|
170
187
|
} else if (t.isMaterial)
|
|
171
|
-
for (const
|
|
172
|
-
const l = t[
|
|
188
|
+
for (const a of Object.keys(t)) {
|
|
189
|
+
const l = t[a];
|
|
173
190
|
(l == null ? void 0 : l.isTexture) === !0 && i(l, e);
|
|
174
191
|
}
|
|
175
192
|
return t[n] = e, e;
|
|
176
|
-
function i(
|
|
177
|
-
const u = s.getAssignedLODInformation(
|
|
193
|
+
function i(a, l) {
|
|
194
|
+
const u = s.getAssignedLODInformation(a);
|
|
178
195
|
if (u) {
|
|
179
196
|
const c = s.lodInfos.get(u.key);
|
|
180
197
|
if (c && c.lods) {
|
|
@@ -202,8 +219,8 @@ const v = class {
|
|
|
202
219
|
}
|
|
203
220
|
if (t.isMaterial === !0) {
|
|
204
221
|
for (const i of Object.keys(t)) {
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
222
|
+
const a = t[i];
|
|
223
|
+
if (a && a.isTexture && this.hasLODLevelAvailable(a, e))
|
|
207
224
|
return !0;
|
|
208
225
|
}
|
|
209
226
|
return !1;
|
|
@@ -249,10 +266,10 @@ const v = class {
|
|
|
249
266
|
return t["LOD:requested level"] = e, v.getOrLoadLOD(n, e).then((i) => {
|
|
250
267
|
if (t["LOD:requested level"] === e) {
|
|
251
268
|
if (delete t["LOD:requested level"], Array.isArray(i)) {
|
|
252
|
-
const
|
|
253
|
-
i = i[
|
|
269
|
+
const a = r.index || 0;
|
|
270
|
+
i = i[a];
|
|
254
271
|
}
|
|
255
|
-
i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? (t.geometry = i, x &&
|
|
272
|
+
i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? (t.geometry = i, x && Pe(t, "geometry", r.url)) : x && console.error("Invalid LOD geometry", i));
|
|
256
273
|
}
|
|
257
274
|
return i;
|
|
258
275
|
}).catch((i) => (console.error("Error loading mesh LOD", t, i), null));
|
|
@@ -273,39 +290,39 @@ const v = class {
|
|
|
273
290
|
}
|
|
274
291
|
return Promise.all(n).then((r) => {
|
|
275
292
|
const i = new Array();
|
|
276
|
-
for (const
|
|
277
|
-
Array.isArray(
|
|
293
|
+
for (const a of r)
|
|
294
|
+
Array.isArray(a) && i.push(...a);
|
|
278
295
|
return i;
|
|
279
296
|
});
|
|
280
297
|
} else
|
|
281
298
|
return this.assignTextureLOD(s.material, e);
|
|
282
299
|
}
|
|
283
|
-
if (t instanceof
|
|
300
|
+
if (t instanceof We || t.isMaterial === !0) {
|
|
284
301
|
const s = t, n = [], r = new Array();
|
|
285
|
-
if (x &&
|
|
302
|
+
if (x && Se.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
|
|
286
303
|
const i = s;
|
|
287
|
-
for (const
|
|
288
|
-
const l = i.uniforms[
|
|
304
|
+
for (const a of Object.keys(i.uniforms)) {
|
|
305
|
+
const l = i.uniforms[a].value;
|
|
289
306
|
if ((l == null ? void 0 : l.isTexture) === !0) {
|
|
290
|
-
const u = this.assignTextureLODForSlot(l, e, s,
|
|
291
|
-
n.push(u), r.push(
|
|
307
|
+
const u = this.assignTextureLODForSlot(l, e, s, a).then((c) => (c && i.uniforms[a].value != c && (i.uniforms[a].value = c, i.uniformsNeedUpdate = !0), c));
|
|
308
|
+
n.push(u), r.push(a);
|
|
292
309
|
}
|
|
293
310
|
}
|
|
294
311
|
} else
|
|
295
312
|
for (const i of Object.keys(s)) {
|
|
296
|
-
const
|
|
297
|
-
if ((
|
|
298
|
-
const l = this.assignTextureLODForSlot(
|
|
313
|
+
const a = s[i];
|
|
314
|
+
if ((a == null ? void 0 : a.isTexture) === !0) {
|
|
315
|
+
const l = this.assignTextureLODForSlot(a, e, s, i);
|
|
299
316
|
n.push(l), r.push(i);
|
|
300
317
|
}
|
|
301
318
|
}
|
|
302
319
|
return Promise.all(n).then((i) => {
|
|
303
|
-
const
|
|
320
|
+
const a = new Array();
|
|
304
321
|
for (let l = 0; l < i.length; l++) {
|
|
305
322
|
const u = i[l], c = r[l];
|
|
306
|
-
u && u.isTexture === !0 ?
|
|
323
|
+
u && u.isTexture === !0 ? a.push({ material: s, slot: c, texture: u, level: e }) : a.push({ material: s, slot: c, texture: null, level: e });
|
|
307
324
|
}
|
|
308
|
-
return
|
|
325
|
+
return a;
|
|
309
326
|
});
|
|
310
327
|
}
|
|
311
328
|
if (t instanceof se || t.isTexture === !0) {
|
|
@@ -323,15 +340,15 @@ const v = class {
|
|
|
323
340
|
if (s && n) {
|
|
324
341
|
const i = s[n];
|
|
325
342
|
if (i) {
|
|
326
|
-
const
|
|
327
|
-
if (
|
|
328
|
-
return x === "verbose" && console.warn("Assigned texture level is already higher: ",
|
|
343
|
+
const a = this.getAssignedLODInformation(i);
|
|
344
|
+
if (a && (a == null ? void 0 : a.level) < e)
|
|
345
|
+
return x === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
|
|
329
346
|
}
|
|
330
347
|
s[n] = r;
|
|
331
348
|
}
|
|
332
349
|
if (x && n && s) {
|
|
333
350
|
const i = this.getAssignedLODInformation(t);
|
|
334
|
-
i &&
|
|
351
|
+
i && Pe(s, n, i.url);
|
|
335
352
|
}
|
|
336
353
|
}
|
|
337
354
|
return r;
|
|
@@ -345,21 +362,21 @@ const v = class {
|
|
|
345
362
|
return x && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, r) => {
|
|
346
363
|
var i;
|
|
347
364
|
if (n != null && n.extensions) {
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
if (!
|
|
351
|
-
x && console.warn("Texture has no LODs",
|
|
365
|
+
const a = n == null ? void 0 : n.extensions[V];
|
|
366
|
+
if (a) {
|
|
367
|
+
if (!a.lods) {
|
|
368
|
+
x && console.warn("Texture has no LODs", a);
|
|
352
369
|
return;
|
|
353
370
|
}
|
|
354
371
|
let l = !1;
|
|
355
372
|
for (const u of this.parser.associations.keys())
|
|
356
373
|
if (u.isTexture === !0) {
|
|
357
374
|
const c = this.parser.associations.get(u);
|
|
358
|
-
(c == null ? void 0 : c.textures) === r && (l = !0, v.registerTexture(this.url, u, (i =
|
|
375
|
+
(c == null ? void 0 : c.textures) === r && (l = !0, v.registerTexture(this.url, u, (i = a.lods) == null ? void 0 : i.length, r, a));
|
|
359
376
|
}
|
|
360
377
|
l || this.parser.getDependency("texture", r).then((u) => {
|
|
361
378
|
var c;
|
|
362
|
-
u && v.registerTexture(this.url, u, (c =
|
|
379
|
+
u && v.registerTexture(this.url, u, (c = a.lods) == null ? void 0 : c.length, r, a);
|
|
363
380
|
});
|
|
364
381
|
}
|
|
365
382
|
}
|
|
@@ -367,17 +384,17 @@ const v = class {
|
|
|
367
384
|
if (n != null && n.extensions) {
|
|
368
385
|
const i = n == null ? void 0 : n.extensions[V];
|
|
369
386
|
if (i && i.lods) {
|
|
370
|
-
for (const
|
|
371
|
-
if (
|
|
372
|
-
const l = this.parser.associations.get(
|
|
373
|
-
(l == null ? void 0 : l.meshes) === r && v.registerMesh(this.url, i.guid,
|
|
387
|
+
for (const a of this.parser.associations.keys())
|
|
388
|
+
if (a.isMesh) {
|
|
389
|
+
const l = this.parser.associations.get(a);
|
|
390
|
+
(l == null ? void 0 : l.meshes) === r && v.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
|
|
374
391
|
}
|
|
375
392
|
}
|
|
376
393
|
}
|
|
377
394
|
}), null;
|
|
378
395
|
}
|
|
379
396
|
static async getOrLoadLOD(t, e) {
|
|
380
|
-
var
|
|
397
|
+
var a, l, u, c;
|
|
381
398
|
const s = x == "verbose", n = t.userData.LODS;
|
|
382
399
|
if (!n)
|
|
383
400
|
return null;
|
|
@@ -385,7 +402,7 @@ const v = class {
|
|
|
385
402
|
let i;
|
|
386
403
|
if (t.isTexture === !0) {
|
|
387
404
|
const g = t;
|
|
388
|
-
g.source && g.source[
|
|
405
|
+
g.source && g.source[De] && (i = g.source[De]);
|
|
389
406
|
}
|
|
390
407
|
if (i || (i = v.lodInfos.get(r)), i) {
|
|
391
408
|
if (e > 0) {
|
|
@@ -394,34 +411,34 @@ const v = class {
|
|
|
394
411
|
if (w && e >= i.lods.length ? M = !0 : w || (M = !0), M)
|
|
395
412
|
return this.lowresCache.get(r);
|
|
396
413
|
}
|
|
397
|
-
const g = Array.isArray(i.lods) ? (
|
|
414
|
+
const g = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
|
|
398
415
|
if (!g)
|
|
399
416
|
return x && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, i)), null;
|
|
400
|
-
const p =
|
|
417
|
+
const p = st(n.url, g);
|
|
401
418
|
if (p.endsWith(".glb") || p.endsWith(".gltf")) {
|
|
402
419
|
if (!i.guid)
|
|
403
420
|
return console.warn("missing pointer for glb/gltf texture", i), null;
|
|
404
421
|
const M = p + "_" + i.guid, w = this.previouslyLoaded.get(M);
|
|
405
422
|
if (w !== void 0) {
|
|
406
423
|
s && console.log(`LOD ${e} was already loading/loaded: ${M}`);
|
|
407
|
-
let h = await w.catch((
|
|
408
|
-
`,
|
|
424
|
+
let h = await w.catch((F) => (console.error(`Error loading LOD ${e} from ${p}
|
|
425
|
+
`, F), null)), B = !1;
|
|
409
426
|
if (h == null || (h instanceof se && t instanceof se ? (l = h.image) != null && l.data || (u = h.source) != null && u.data ? h = this.copySettings(t, h) : (B = !0, this.previouslyLoaded.delete(M)) : h instanceof ge && t instanceof ge && ((c = h.attributes.position) != null && c.array || (B = !0, this.previouslyLoaded.delete(M)))), !B)
|
|
410
427
|
return h;
|
|
411
428
|
}
|
|
412
|
-
const L = i,
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
let
|
|
429
|
+
const L = i, $ = new Promise(async (h, B) => {
|
|
430
|
+
const F = new be();
|
|
431
|
+
Ge(F), x && (await new Promise((A) => setTimeout(A, 1e3)), s && console.warn("Start loading (delayed) " + p, L.guid));
|
|
432
|
+
let k = p;
|
|
416
433
|
if (L && Array.isArray(L.lods)) {
|
|
417
434
|
const A = L.lods[e];
|
|
418
|
-
A.hash && (
|
|
435
|
+
A.hash && (k += "?v=" + A.hash);
|
|
419
436
|
}
|
|
420
|
-
const S = await
|
|
437
|
+
const S = await F.loadAsync(k).catch((A) => (console.error(`Error loading LOD ${e} from ${p}
|
|
421
438
|
`, A), null));
|
|
422
439
|
if (!S)
|
|
423
440
|
return null;
|
|
424
|
-
const
|
|
441
|
+
const q = S.parser;
|
|
425
442
|
s && console.log("Loading finished " + p, L.guid);
|
|
426
443
|
let T = 0;
|
|
427
444
|
if (S.parser.json.textures) {
|
|
@@ -437,7 +454,7 @@ const v = class {
|
|
|
437
454
|
T++;
|
|
438
455
|
}
|
|
439
456
|
if (A) {
|
|
440
|
-
let f = await
|
|
457
|
+
let f = await q.getDependency("texture", T);
|
|
441
458
|
return f && v.assignLODInformation(n.url, f, r, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', p, T, f, M), t instanceof se && (f = this.copySettings(t, f)), f && (f.guid = L.guid), h(f);
|
|
442
459
|
} else
|
|
443
460
|
x && console.warn("Could not find texture with guid", L.guid, S.parser.json);
|
|
@@ -455,7 +472,7 @@ const v = class {
|
|
|
455
472
|
T++;
|
|
456
473
|
}
|
|
457
474
|
if (A) {
|
|
458
|
-
const f = await
|
|
475
|
+
const f = await q.getDependency("mesh", T), y = L;
|
|
459
476
|
if (s && console.log(`Loaded Mesh "${f.name}"`, p, T, f, M), f.isMesh === !0) {
|
|
460
477
|
const O = f.geometry;
|
|
461
478
|
return v.assignLODInformation(n.url, O, r, e, void 0, y.density), h(O);
|
|
@@ -464,8 +481,8 @@ const v = class {
|
|
|
464
481
|
for (let b = 0; b < f.children.length; b++) {
|
|
465
482
|
const E = f.children[b];
|
|
466
483
|
if (E.isMesh === !0) {
|
|
467
|
-
const
|
|
468
|
-
v.assignLODInformation(n.url,
|
|
484
|
+
const X = E.geometry;
|
|
485
|
+
v.assignLODInformation(n.url, X, r, e, b, y.density), O.push(X);
|
|
469
486
|
}
|
|
470
487
|
}
|
|
471
488
|
return h(O);
|
|
@@ -475,10 +492,10 @@ const v = class {
|
|
|
475
492
|
}
|
|
476
493
|
return h(null);
|
|
477
494
|
});
|
|
478
|
-
return this.previouslyLoaded.set(M,
|
|
495
|
+
return this.previouslyLoaded.set(M, $), await $;
|
|
479
496
|
} else if (t instanceof se) {
|
|
480
497
|
s && console.log("Load texture from uri: " + p);
|
|
481
|
-
const w = await new
|
|
498
|
+
const w = await new qe().loadAsync(p);
|
|
482
499
|
return w ? (w.guid = i.guid, w.flipY = !1, w.needsUpdate = !0, w.colorSpace = t.colorSpace, s && console.log(i, w)) : x && console.warn("failed loading", p), w;
|
|
483
500
|
}
|
|
484
501
|
} else
|
|
@@ -489,8 +506,8 @@ const v = class {
|
|
|
489
506
|
if (!e)
|
|
490
507
|
return;
|
|
491
508
|
e.userData || (e.userData = {});
|
|
492
|
-
const
|
|
493
|
-
e.userData.LODS =
|
|
509
|
+
const a = new ot(t, s, n, r, i);
|
|
510
|
+
e.userData.LODS = a;
|
|
494
511
|
}
|
|
495
512
|
static getAssignedLODInformation(t) {
|
|
496
513
|
var e;
|
|
@@ -512,7 +529,7 @@ d(_, "registerTexture", (t, e, s, n, r) => {
|
|
|
512
529
|
x && console.error("gltf-progressive: Register texture without texture");
|
|
513
530
|
return;
|
|
514
531
|
}
|
|
515
|
-
e.source && (e.source[
|
|
532
|
+
e.source && (e.source[De] = r);
|
|
516
533
|
const i = r.guid;
|
|
517
534
|
v.assignLODInformation(t, e, i, s, n, void 0), v.lodInfos.set(i, r), v.lowresCache.set(i, e);
|
|
518
535
|
}), /**
|
|
@@ -521,21 +538,21 @@ d(_, "registerTexture", (t, e, s, n, r) => {
|
|
|
521
538
|
d(_, "registerMesh", (t, e, s, n, r, i) => {
|
|
522
539
|
var u;
|
|
523
540
|
x && console.log("> Progressive: register mesh", r, s.name, i, s.uuid, s);
|
|
524
|
-
const
|
|
525
|
-
if (!
|
|
541
|
+
const a = s.geometry;
|
|
542
|
+
if (!a) {
|
|
526
543
|
x && console.warn("gltf-progressive: Register mesh without geometry");
|
|
527
544
|
return;
|
|
528
545
|
}
|
|
529
|
-
|
|
546
|
+
a.userData || (a.userData = {}), v.assignLODInformation(t, a, e, n, r, i.density), v.lodInfos.set(e, i);
|
|
530
547
|
let l = v.lowresCache.get(e);
|
|
531
|
-
l ? l.push(s.geometry) : l = [s.geometry], v.lowresCache.set(e, l), n > 0 && !me(s) &&
|
|
548
|
+
l ? l.push(s.geometry) : l = [s.geometry], v.lowresCache.set(e, l), n > 0 && !me(s) && it(s, a);
|
|
532
549
|
for (const c of Y)
|
|
533
550
|
(u = c.onRegisteredNewMesh) == null || u.call(c, s, i);
|
|
534
551
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
535
552
|
d(_, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
536
553
|
d(_, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
537
554
|
d(_, "lowresCache", /* @__PURE__ */ new Map());
|
|
538
|
-
class
|
|
555
|
+
class ot {
|
|
539
556
|
constructor(t, e, s, n, r) {
|
|
540
557
|
d(this, "url");
|
|
541
558
|
/** the key to lookup the LOD information */
|
|
@@ -548,14 +565,14 @@ class st {
|
|
|
548
565
|
this.url = t, this.key = e, this.level = s, n != null && (this.index = n), r != null && (this.density = r);
|
|
549
566
|
}
|
|
550
567
|
}
|
|
551
|
-
const
|
|
568
|
+
const I = le("debugprogressive"), at = le("noprogressive"), we = Symbol("Needle:LODSManager"), ve = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 };
|
|
552
569
|
var C, N, pe, ee, te, ye, W;
|
|
553
570
|
const P = class {
|
|
554
571
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
555
572
|
constructor(t, e) {
|
|
556
573
|
d(this, "context");
|
|
557
574
|
d(this, "renderer");
|
|
558
|
-
d(this, "projectionScreenMatrix", new
|
|
575
|
+
d(this, "projectionScreenMatrix", new Ae());
|
|
559
576
|
/**
|
|
560
577
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
561
578
|
* @default 200_000
|
|
@@ -580,17 +597,17 @@ const P = class {
|
|
|
580
597
|
d(this, "manual", !1);
|
|
581
598
|
d(this, "_lodchangedlisteners", []);
|
|
582
599
|
K(this, N, void 0);
|
|
583
|
-
K(this, pe, new
|
|
600
|
+
K(this, pe, new Xe());
|
|
584
601
|
K(this, ee, 0);
|
|
585
602
|
K(this, te, 0);
|
|
586
603
|
K(this, ye, 0);
|
|
587
604
|
K(this, W, 0);
|
|
588
605
|
d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
|
|
589
606
|
// private testIfLODLevelsAreAvailable() {
|
|
590
|
-
d(this, "_sphere", new
|
|
591
|
-
d(this, "_tempBox", new
|
|
592
|
-
d(this, "_tempBox2", new
|
|
593
|
-
d(this, "tempMatrix", new
|
|
607
|
+
d(this, "_sphere", new Ye());
|
|
608
|
+
d(this, "_tempBox", new Ee());
|
|
609
|
+
d(this, "_tempBox2", new Ee());
|
|
610
|
+
d(this, "tempMatrix", new Ae());
|
|
594
611
|
d(this, "_tempWorldPosition", new z());
|
|
595
612
|
d(this, "_tempBoxSize", new z());
|
|
596
613
|
d(this, "_tempBox2Size", new z());
|
|
@@ -598,7 +615,7 @@ const P = class {
|
|
|
598
615
|
}
|
|
599
616
|
/** @internal */
|
|
600
617
|
static getObjectLODState(t) {
|
|
601
|
-
return t[
|
|
618
|
+
return t[ve];
|
|
602
619
|
}
|
|
603
620
|
static addPlugin(t) {
|
|
604
621
|
Y.push(t);
|
|
@@ -613,13 +630,13 @@ const P = class {
|
|
|
613
630
|
* @returns The LODsManager instance.
|
|
614
631
|
*/
|
|
615
632
|
static get(t, e) {
|
|
616
|
-
if (t[
|
|
617
|
-
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[
|
|
633
|
+
if (t[we])
|
|
634
|
+
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[we];
|
|
618
635
|
const s = new P(t, {
|
|
619
636
|
engine: "unknown",
|
|
620
637
|
...e
|
|
621
638
|
});
|
|
622
|
-
return t[
|
|
639
|
+
return t[we] = s, s;
|
|
623
640
|
}
|
|
624
641
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
625
642
|
get plugins() {
|
|
@@ -644,9 +661,9 @@ const P = class {
|
|
|
644
661
|
let t = 0;
|
|
645
662
|
U(this, N, this.renderer.render);
|
|
646
663
|
const e = this;
|
|
647
|
-
|
|
664
|
+
Re(this.renderer), this.renderer.render = function(s, n) {
|
|
648
665
|
const r = e.renderer.getRenderTarget();
|
|
649
|
-
(r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, U(e, ee, m(e, ee) + 1), U(e, te, m(e, pe).getDelta()), U(e, ye, m(e, ye) + m(e, te)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / m(e, te)), U(e, W, e._fpsBuffer.reduce((
|
|
666
|
+
(r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, U(e, ee, m(e, ee) + 1), U(e, te, m(e, pe).getDelta()), U(e, ye, m(e, ye) + m(e, te)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / m(e, te)), U(e, W, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), I && m(e, ee) % 200 === 0 && console.log("FPS", Math.round(m(e, W)), "Interval:", m(e, C)));
|
|
650
667
|
const i = t++;
|
|
651
668
|
m(e, N).call(this, s, n), e.onAfterRender(s, n, i);
|
|
652
669
|
};
|
|
@@ -663,11 +680,11 @@ const P = class {
|
|
|
663
680
|
const r = this.renderer.renderLists.get(t, 0).opaque;
|
|
664
681
|
let i = !0;
|
|
665
682
|
if (r.length === 1) {
|
|
666
|
-
const
|
|
667
|
-
(
|
|
683
|
+
const a = r[0].material;
|
|
684
|
+
(a.name === "EffectMaterial" || a.name === "CopyShader") && (i = !1);
|
|
668
685
|
}
|
|
669
686
|
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
|
|
670
|
-
if (
|
|
687
|
+
if (at || (this.updateInterval === "auto" ? m(this, W) < 40 && m(this, C) < 10 ? (U(this, C, m(this, C) + 1), I && console.warn("↓ Reducing LOD updates", m(this, C), m(this, W).toFixed(0))) : m(this, W) >= 60 && m(this, C) > 1 && (U(this, C, m(this, C) - 1), I && console.warn("↑ Increasing LOD updates", m(this, C), m(this, W).toFixed(0))) : U(this, C, this.updateInterval), m(this, C) > 0 && m(this, ee) % m(this, C) != 0))
|
|
671
688
|
return;
|
|
672
689
|
this.internalUpdate(t, e);
|
|
673
690
|
}
|
|
@@ -682,7 +699,7 @@ const P = class {
|
|
|
682
699
|
const r = this.targetTriangleDensity;
|
|
683
700
|
for (const c of n) {
|
|
684
701
|
if (c.material && (((l = c.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((u = c.geometry) == null ? void 0 : u.type) === "BufferGeometry") && (c.material.name === "SphericalGaussianBlur" || c.material.name == "BackgroundCubeMaterial" || c.material.name === "CubemapFromEquirect" || c.material.name === "EquirectangularToCubeUV")) {
|
|
685
|
-
|
|
702
|
+
I && (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (c.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", c, c.material.name, c.material.type)));
|
|
686
703
|
continue;
|
|
687
704
|
}
|
|
688
705
|
switch (c.material.type) {
|
|
@@ -694,9 +711,9 @@ const P = class {
|
|
|
694
711
|
case "MeshDepthMaterial":
|
|
695
712
|
continue;
|
|
696
713
|
}
|
|
697
|
-
if (
|
|
714
|
+
if (I === "color" && c.material && !c.object.progressive_debug_color) {
|
|
698
715
|
c.object.progressive_debug_color = !0;
|
|
699
|
-
const p = Math.random() * 16777215, M = new
|
|
716
|
+
const p = Math.random() * 16777215, M = new Ke({ color: p });
|
|
700
717
|
c.object.material = M;
|
|
701
718
|
}
|
|
702
719
|
const g = c.object;
|
|
@@ -707,21 +724,21 @@ const P = class {
|
|
|
707
724
|
const g = c.object;
|
|
708
725
|
(g instanceof H || g.isMesh) && this.updateLODs(t, e, g, r);
|
|
709
726
|
}
|
|
710
|
-
const
|
|
711
|
-
for (const c of
|
|
727
|
+
const a = s.transmissive;
|
|
728
|
+
for (const c of a) {
|
|
712
729
|
const g = c.object;
|
|
713
730
|
(g instanceof H || g.isMesh) && this.updateLODs(t, e, g, r);
|
|
714
731
|
}
|
|
715
732
|
}
|
|
716
733
|
/** Update the LOD levels for the renderer. */
|
|
717
734
|
updateLODs(t, e, s, n) {
|
|
718
|
-
var
|
|
735
|
+
var a, l;
|
|
719
736
|
s.userData || (s.userData = {});
|
|
720
|
-
let r = s[
|
|
721
|
-
if (r || (r = new
|
|
737
|
+
let r = s[ve];
|
|
738
|
+
if (r || (r = new lt(), s[ve] = r), r.frames++ < 2)
|
|
722
739
|
return;
|
|
723
740
|
for (const u of Y)
|
|
724
|
-
(
|
|
741
|
+
(a = u.onBeforeUpdateLOD) == null || a.call(u, this.renderer, t, e, s);
|
|
725
742
|
this.calculateLodLevel(e, s, r, n, 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);
|
|
726
743
|
let i = R.texture_lod;
|
|
727
744
|
if (s.material && i >= 0) {
|
|
@@ -771,7 +788,7 @@ const P = class {
|
|
|
771
788
|
return this._tempPtInside.set(r, i, s.z).applyMatrix4(e).z < 0;
|
|
772
789
|
}
|
|
773
790
|
calculateLodLevel(t, e, s, n, r) {
|
|
774
|
-
var
|
|
791
|
+
var $;
|
|
775
792
|
if (!e) {
|
|
776
793
|
r.mesh_lod = -1, r.texture_lod = -1;
|
|
777
794
|
return;
|
|
@@ -780,15 +797,15 @@ const P = class {
|
|
|
780
797
|
r.mesh_lod = -1, r.texture_lod = -1;
|
|
781
798
|
return;
|
|
782
799
|
}
|
|
783
|
-
let
|
|
784
|
-
if (
|
|
800
|
+
let a = 10 + 1, l = !1;
|
|
801
|
+
if (I && e["DEBUG:LOD"] != null)
|
|
785
802
|
return e["DEBUG:LOD"];
|
|
786
803
|
const u = _.getMeshLODInformation(e.geometry), c = u == null ? void 0 : u.lods, g = c && c.length > 0, p = _.getMaterialMinMaxLODsCount(e.material), M = (p == null ? void 0 : p.min_count) != 1 / 0 && p.min_count > 0 && p.max_count > 0;
|
|
787
804
|
if (!g && !M) {
|
|
788
805
|
r.mesh_lod = 0, r.texture_lod = 0;
|
|
789
806
|
return;
|
|
790
807
|
}
|
|
791
|
-
g || (l = !0,
|
|
808
|
+
g || (l = !0, a = 0);
|
|
792
809
|
const w = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
793
810
|
let L = e.geometry.boundingBox;
|
|
794
811
|
if (e.type === "SkinnedMesh") {
|
|
@@ -817,25 +834,25 @@ const P = class {
|
|
|
817
834
|
}
|
|
818
835
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && D.fov > 70) {
|
|
819
836
|
const f = this._tempBox.min, y = this._tempBox.max;
|
|
820
|
-
let O = f.x, b = f.y, E = y.x,
|
|
837
|
+
let O = f.x, b = f.y, E = y.x, X = y.y;
|
|
821
838
|
const ce = 2, xe = 1.5, ue = (f.x + y.x) * 0.5, fe = (f.y + y.y) * 0.5;
|
|
822
|
-
O = (O - ue) * ce + ue, b = (b - fe) * ce + fe, E = (E - ue) * ce + ue,
|
|
823
|
-
const
|
|
839
|
+
O = (O - ue) * ce + ue, b = (b - fe) * ce + fe, E = (E - ue) * ce + ue, X = (X - fe) * ce + fe;
|
|
840
|
+
const Ue = O < 0 && E > 0 ? 0 : Math.min(Math.abs(f.x), Math.abs(y.x)), ze = b < 0 && X > 0 ? 0 : Math.min(Math.abs(f.y), Math.abs(y.y)), Le = Math.max(Ue, ze);
|
|
824
841
|
s.lastCentrality = (xe - Le) * (xe - Le) * (xe - Le);
|
|
825
842
|
} else
|
|
826
843
|
s.lastCentrality = 1;
|
|
827
844
|
const h = this._tempBox.getSize(this._tempBoxSize);
|
|
828
845
|
h.multiplyScalar(0.5), screen.availHeight > 0 && w > 0 && h.multiplyScalar(w / screen.availHeight), h.x *= D.aspect;
|
|
829
|
-
const B = t.matrixWorldInverse,
|
|
830
|
-
|
|
831
|
-
const
|
|
832
|
-
if (Math.max(h.x, h.y) != 0 && S != 0 && (h.z =
|
|
846
|
+
const B = t.matrixWorldInverse, F = this._tempBox2;
|
|
847
|
+
F.copy(L), F.applyMatrix4(e.matrixWorld), F.applyMatrix4(B);
|
|
848
|
+
const k = F.getSize(this._tempBox2Size), S = Math.max(k.x, k.y);
|
|
849
|
+
if (Math.max(h.x, h.y) != 0 && S != 0 && (h.z = k.z / Math.max(k.x, k.y) * Math.max(h.x, h.y)), s.lastScreenCoverage = Math.max(h.x, h.y, h.z), s.lastScreenspaceVolume.copy(h), s.lastScreenCoverage *= s.lastCentrality, I && P.debugDrawLine) {
|
|
833
850
|
const f = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
834
851
|
f.invert();
|
|
835
852
|
const y = P.corner0, O = P.corner1, b = P.corner2, E = P.corner3;
|
|
836
853
|
y.copy(this._tempBox.min), O.copy(this._tempBox.max), O.x = y.x, b.copy(this._tempBox.max), b.y = y.y, E.copy(this._tempBox.max);
|
|
837
|
-
const
|
|
838
|
-
y.z = O.z = b.z = E.z =
|
|
854
|
+
const X = (y.z + E.z) * 0.5;
|
|
855
|
+
y.z = O.z = b.z = E.z = X, y.applyMatrix4(f), O.applyMatrix4(f), b.applyMatrix4(f), E.applyMatrix4(f), P.debugDrawLine(y, O, 255), P.debugDrawLine(y, b, 255), P.debugDrawLine(O, E, 255), P.debugDrawLine(b, E, 255);
|
|
839
856
|
}
|
|
840
857
|
let T = 999;
|
|
841
858
|
if (c && s.lastScreenCoverage > 0) {
|
|
@@ -845,31 +862,31 @@ const P = class {
|
|
|
845
862
|
break;
|
|
846
863
|
}
|
|
847
864
|
}
|
|
848
|
-
T <
|
|
865
|
+
T < a && (a = T, l = !0);
|
|
849
866
|
}
|
|
850
|
-
if (l ? r.mesh_lod =
|
|
867
|
+
if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, I && r.mesh_lod != s.lastLodLevel_Mesh) {
|
|
851
868
|
const h = c == null ? void 0 : c[r.mesh_lod];
|
|
852
869
|
h && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${h.density.toFixed(0)}) - ${e.name}`);
|
|
853
870
|
}
|
|
854
871
|
if (M) {
|
|
855
872
|
const D = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
856
873
|
if (s.lastLodLevel_Texture < 0) {
|
|
857
|
-
if (r.texture_lod = p.max_count - 1,
|
|
874
|
+
if (r.texture_lod = p.max_count - 1, I) {
|
|
858
875
|
const h = p.lods[p.max_count - 1];
|
|
859
|
-
|
|
876
|
+
I && console.log(`First Texture LOD ${r.texture_lod} (${h.max_height}px) - ${e.name}`);
|
|
860
877
|
}
|
|
861
878
|
} else {
|
|
862
879
|
const h = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
863
880
|
let B = s.lastScreenCoverage * 2;
|
|
864
|
-
((
|
|
865
|
-
const
|
|
881
|
+
(($ = this.context) == null ? void 0 : $.engine) === "model-viewer" && (B *= 2);
|
|
882
|
+
const k = w / window.devicePixelRatio * B;
|
|
866
883
|
for (let S = p.lods.length - 1; S >= 0; S--) {
|
|
867
|
-
let
|
|
868
|
-
if (!(D &&
|
|
884
|
+
let q = p.lods[S];
|
|
885
|
+
if (!(D && q.max_height >= 2048) && !(rt() && q.max_height > 4096) && q.max_height > k) {
|
|
869
886
|
if (r.texture_lod = S, r.texture_lod < s.lastLodLevel_Texture) {
|
|
870
|
-
const T =
|
|
871
|
-
|
|
872
|
-
Screensize: ${
|
|
887
|
+
const T = q.max_height;
|
|
888
|
+
I && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${T}px
|
|
889
|
+
Screensize: ${k.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${h.toFixed(1)}
|
|
873
890
|
${e.name}`);
|
|
874
891
|
}
|
|
875
892
|
break;
|
|
@@ -884,7 +901,7 @@ let G = P;
|
|
|
884
901
|
C = new WeakMap(), N = new WeakMap(), pe = new WeakMap(), ee = new WeakMap(), te = new WeakMap(), ye = new WeakMap(), W = new WeakMap(), /** 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.
|
|
885
902
|
*/
|
|
886
903
|
d(G, "debugDrawLine"), d(G, "corner0", new z()), d(G, "corner1", new z()), d(G, "corner2", new z()), d(G, "corner3", new z()), d(G, "_tempPtInside", new z());
|
|
887
|
-
class
|
|
904
|
+
class lt {
|
|
888
905
|
constructor() {
|
|
889
906
|
d(this, "frames", 0);
|
|
890
907
|
d(this, "lastLodLevel_Mesh", -1);
|
|
@@ -894,66 +911,66 @@ class it {
|
|
|
894
911
|
d(this, "lastCentrality", 0);
|
|
895
912
|
}
|
|
896
913
|
}
|
|
897
|
-
const
|
|
914
|
+
const Ce = Symbol("NEEDLE_mesh_lod"), de = Symbol("NEEDLE_texture_lod");
|
|
898
915
|
let ne = null;
|
|
899
|
-
function
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
return
|
|
903
|
-
}),
|
|
916
|
+
function $e() {
|
|
917
|
+
const o = ct();
|
|
918
|
+
o && (o.mapURLs(function(t) {
|
|
919
|
+
return Be(), t;
|
|
920
|
+
}), Be(), ne == null || ne.disconnect(), ne = new MutationObserver((t) => {
|
|
904
921
|
t.forEach((e) => {
|
|
905
922
|
e.addedNodes.forEach((s) => {
|
|
906
|
-
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" &&
|
|
923
|
+
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Fe(s);
|
|
907
924
|
});
|
|
908
925
|
});
|
|
909
926
|
}), ne.observe(document, { childList: !0, subtree: !0 }));
|
|
910
927
|
}
|
|
911
|
-
function
|
|
928
|
+
function ct() {
|
|
912
929
|
if (typeof customElements > "u")
|
|
913
930
|
return null;
|
|
914
|
-
const
|
|
915
|
-
return
|
|
916
|
-
console.debug("[gltf-progressive] model-viewer defined"),
|
|
931
|
+
const o = customElements.get("model-viewer");
|
|
932
|
+
return o || (customElements.whenDefined("model-viewer").then(() => {
|
|
933
|
+
console.debug("[gltf-progressive] model-viewer defined"), $e();
|
|
917
934
|
}), null);
|
|
918
935
|
}
|
|
919
|
-
function
|
|
936
|
+
function Be() {
|
|
920
937
|
if (typeof document > "u")
|
|
921
938
|
return;
|
|
922
939
|
document.querySelectorAll("model-viewer").forEach((t) => {
|
|
923
|
-
|
|
940
|
+
Fe(t);
|
|
924
941
|
});
|
|
925
942
|
}
|
|
926
|
-
const
|
|
927
|
-
let
|
|
928
|
-
function
|
|
929
|
-
if (!
|
|
943
|
+
const ke = /* @__PURE__ */ new WeakSet();
|
|
944
|
+
let ut = 0;
|
|
945
|
+
function Fe(o) {
|
|
946
|
+
if (!o || ke.has(o))
|
|
930
947
|
return null;
|
|
931
|
-
|
|
932
|
-
`,
|
|
948
|
+
ke.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++ut + `
|
|
949
|
+
`, o.getAttribute("src"));
|
|
933
950
|
let t = null, e = null, s = null;
|
|
934
|
-
for (let n =
|
|
935
|
-
const r = Object.getOwnPropertySymbols(n), i = r.find((u) => u.toString() == "Symbol(renderer)"),
|
|
936
|
-
!t && i != null && (t =
|
|
951
|
+
for (let n = o; n != null; n = Object.getPrototypeOf(n)) {
|
|
952
|
+
const r = Object.getOwnPropertySymbols(n), i = r.find((u) => u.toString() == "Symbol(renderer)"), a = r.find((u) => u.toString() == "Symbol(scene)"), l = r.find((u) => u.toString() == "Symbol(needsRender)");
|
|
953
|
+
!t && i != null && (t = o[i].threeRenderer), !e && a != null && (e = o[a]), !s && l != null && (s = o[l]);
|
|
937
954
|
}
|
|
938
955
|
if (t && e) {
|
|
939
956
|
let n = function() {
|
|
940
957
|
if (s) {
|
|
941
|
-
let i = 0,
|
|
958
|
+
let i = 0, a = setInterval(() => {
|
|
942
959
|
if (i++ > 5) {
|
|
943
|
-
clearInterval(
|
|
960
|
+
clearInterval(a);
|
|
944
961
|
return;
|
|
945
962
|
}
|
|
946
|
-
s == null || s.call(
|
|
963
|
+
s == null || s.call(o);
|
|
947
964
|
}, 300);
|
|
948
965
|
}
|
|
949
966
|
};
|
|
950
967
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
951
968
|
const r = G.get(t, { engine: "model-viewer" });
|
|
952
|
-
return G.addPlugin(new
|
|
953
|
-
s == null || s.call(
|
|
954
|
-
}),
|
|
955
|
-
i.detail.visible && (s == null || s.call(
|
|
956
|
-
}),
|
|
969
|
+
return G.addPlugin(new ft()), r.enable(), r.addEventListener("changed", () => {
|
|
970
|
+
s == null || s.call(o);
|
|
971
|
+
}), o.addEventListener("model-visibility", (i) => {
|
|
972
|
+
i.detail.visible && (s == null || s.call(o));
|
|
973
|
+
}), o.addEventListener("load", () => {
|
|
957
974
|
n();
|
|
958
975
|
}), () => {
|
|
959
976
|
r.disable();
|
|
@@ -961,7 +978,7 @@ function Re(a) {
|
|
|
961
978
|
}
|
|
962
979
|
return null;
|
|
963
980
|
}
|
|
964
|
-
class
|
|
981
|
+
class ft {
|
|
965
982
|
constructor() {
|
|
966
983
|
d(this, "_didWarnAboutMissingUrl", !1);
|
|
967
984
|
}
|
|
@@ -995,62 +1012,66 @@ class at {
|
|
|
995
1012
|
for (let M = 0; M < u.length; M++) {
|
|
996
1013
|
const w = u[M], L = l[w];
|
|
997
1014
|
if ((L == null ? void 0 : L.isTexture) === !0) {
|
|
998
|
-
const
|
|
999
|
-
if (
|
|
1015
|
+
const $ = (g = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : g.textures;
|
|
1016
|
+
if ($ == null)
|
|
1000
1017
|
continue;
|
|
1001
|
-
const D = s.parser.json.textures[
|
|
1018
|
+
const D = s.parser.json.textures[$];
|
|
1002
1019
|
if (!D) {
|
|
1003
|
-
console.warn("Texture data not found for texture index " +
|
|
1020
|
+
console.warn("Texture data not found for texture index " + $);
|
|
1004
1021
|
continue;
|
|
1005
1022
|
}
|
|
1006
1023
|
if ((p = D == null ? void 0 : D.extensions) != null && p[V]) {
|
|
1007
1024
|
const h = D.extensions[V];
|
|
1008
|
-
h && r && _.registerTexture(r, L, h.lods.length,
|
|
1025
|
+
h && r && _.registerTexture(r, L, h.lods.length, $, h);
|
|
1009
1026
|
}
|
|
1010
1027
|
}
|
|
1011
1028
|
}
|
|
1012
1029
|
};
|
|
1013
|
-
const
|
|
1014
|
-
if (Array.isArray(
|
|
1015
|
-
for (const l of
|
|
1030
|
+
const a = e.material;
|
|
1031
|
+
if (Array.isArray(a))
|
|
1032
|
+
for (const l of a)
|
|
1016
1033
|
i(l);
|
|
1017
1034
|
else
|
|
1018
|
-
i(
|
|
1035
|
+
i(a);
|
|
1019
1036
|
}
|
|
1020
1037
|
}
|
|
1021
1038
|
tryParseMeshLOD(t, e) {
|
|
1022
|
-
var i,
|
|
1023
|
-
if (e[
|
|
1039
|
+
var i, a;
|
|
1040
|
+
if (e[Ce] == !0)
|
|
1024
1041
|
return;
|
|
1025
|
-
e[
|
|
1042
|
+
e[Ce] = !0;
|
|
1026
1043
|
const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
|
|
1027
1044
|
if (!n)
|
|
1028
1045
|
return;
|
|
1029
|
-
const r = (
|
|
1046
|
+
const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[V];
|
|
1030
1047
|
if (r && n) {
|
|
1031
1048
|
const l = e.uuid;
|
|
1032
1049
|
_.registerMesh(n, l, e, 0, r.lods.length, r);
|
|
1033
1050
|
}
|
|
1034
1051
|
}
|
|
1035
1052
|
}
|
|
1036
|
-
function
|
|
1037
|
-
|
|
1053
|
+
function Dt(o, t, e, s) {
|
|
1054
|
+
Re(t), Ge(e), et(e, {
|
|
1055
|
+
progressive: !0,
|
|
1056
|
+
...s == null ? void 0 : s.hints
|
|
1057
|
+
}), e.register((r) => new _(r, o));
|
|
1038
1058
|
const n = G.get(t);
|
|
1039
1059
|
return (s == null ? void 0 : s.enableLODsManager) !== !1 && n.enable(), n;
|
|
1040
1060
|
}
|
|
1041
|
-
|
|
1061
|
+
$e();
|
|
1042
1062
|
export {
|
|
1043
1063
|
V as EXTENSION_NAME,
|
|
1044
1064
|
G as LODsManager,
|
|
1045
1065
|
_ as NEEDLE_progressive,
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1066
|
+
Ie as VERSION,
|
|
1067
|
+
Ge as addDracoAndKTX2Loaders,
|
|
1068
|
+
et as configureLoader,
|
|
1069
|
+
Re as createLoaders,
|
|
1049
1070
|
me as getRaycastMesh,
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1071
|
+
$e as patchModelViewer,
|
|
1072
|
+
it as registerRaycastMesh,
|
|
1073
|
+
xt as setDracoDecoderLocation,
|
|
1074
|
+
Lt as setKTX2TranscoderLocation,
|
|
1075
|
+
Dt as useNeedleProgressive,
|
|
1076
|
+
Mt as useRaycastMeshes
|
|
1056
1077
|
};
|