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