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