@needle-tools/gltf-progressive 1.2.2-alpha.3 → 1.2.2-alpha.4
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 +1 -0
- package/examples/modelviewer-multiple.html +24 -12
- package/gltf-progressive.js +377 -359
- package/gltf-progressive.min.js +7 -6
- package/gltf-progressive.umd.cjs +6 -5
- package/lib/index.js +3 -3
- package/lib/plugins/modelviewer.js +41 -6
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { BufferGeometry as
|
|
5
|
-
import { GLTFLoader as
|
|
6
|
-
import { MeshoptDecoder as
|
|
7
|
-
import { DRACOLoader as
|
|
8
|
-
import { KTX2Loader as
|
|
9
|
-
const
|
|
10
|
-
globalThis.GLTF_PROGRESSIVE_VERSION =
|
|
11
|
-
console.debug(`[gltf-progressive] version ${
|
|
12
|
-
let
|
|
13
|
-
fetch(
|
|
14
|
-
|
|
1
|
+
var Ae = Object.defineProperty;
|
|
2
|
+
var Pe = (a, e, t) => e in a ? Ae(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var d = (a, e, t) => (Pe(a, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { BufferGeometry as ie, Mesh as W, Material as Ee, Texture as q, TextureLoader as Ce, Matrix4 as ye, Frustum as Be, Sphere as Re, Box3 as me, Vector3 as G } from "three";
|
|
5
|
+
import { GLTFLoader as ke } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
6
|
+
import { MeshoptDecoder as Ie } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
7
|
+
import { DRACOLoader as Ge } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
8
|
+
import { KTX2Loader as Fe } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
9
|
+
const we = "";
|
|
10
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = we;
|
|
11
|
+
console.debug(`[gltf-progressive] version ${we}`);
|
|
12
|
+
let ne = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", ge = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
13
|
+
fetch(ne + "draco_decoder.js", { method: "head" }).catch((a) => {
|
|
14
|
+
ne = "./include/draco/", ge = "./include/ktx2/";
|
|
15
15
|
});
|
|
16
|
-
function
|
|
17
|
-
|
|
16
|
+
function tt(a) {
|
|
17
|
+
ne = a;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
ge =
|
|
19
|
+
function rt(a) {
|
|
20
|
+
ge = a;
|
|
21
21
|
}
|
|
22
|
-
let
|
|
23
|
-
function
|
|
24
|
-
|
|
22
|
+
let J, fe, Q;
|
|
23
|
+
function ve(a) {
|
|
24
|
+
J || (J = new Ge(), J.setDecoderPath(ne), J.setDecoderConfig({ type: "js" })), Q || (Q = new Fe(), Q.setTranscoderPath(ge)), fe || (fe = Ie), a ? Q.detectSupport(a) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
|
|
25
25
|
}
|
|
26
|
-
function _e(
|
|
27
|
-
|
|
26
|
+
function _e(a) {
|
|
27
|
+
a.dracoLoader || a.setDRACOLoader(J), a.ktx2Loader || a.setKTX2Loader(Q), a.meshoptDecoder || a.setMeshoptDecoder(fe);
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
const t = new URL(window.location.href).searchParams.get(
|
|
29
|
+
j("debugprogressive");
|
|
30
|
+
function j(a) {
|
|
31
|
+
const t = new URL(window.location.href).searchParams.get(a);
|
|
32
32
|
return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
if (e === void 0 || e.startsWith("./") || e.startsWith("http") ||
|
|
34
|
+
function $e(a, e) {
|
|
35
|
+
if (e === void 0 || e.startsWith("./") || e.startsWith("http") || a === void 0)
|
|
36
36
|
return e;
|
|
37
|
-
const t =
|
|
37
|
+
const t = a.lastIndexOf("/");
|
|
38
38
|
if (t >= 0) {
|
|
39
|
-
const r =
|
|
39
|
+
const r = a.substring(0, t + 1);
|
|
40
40
|
for (; r.endsWith("/") && e.startsWith("/"); )
|
|
41
41
|
e = e.substring(1);
|
|
42
42
|
return r + e;
|
|
@@ -44,28 +44,28 @@ function Ie(l, e) {
|
|
|
44
44
|
return e;
|
|
45
45
|
}
|
|
46
46
|
let X;
|
|
47
|
-
function
|
|
48
|
-
return X !== void 0 || (X = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),
|
|
47
|
+
function ze() {
|
|
48
|
+
return X !== void 0 || (X = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), j("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", X)), X;
|
|
49
49
|
}
|
|
50
50
|
const de = Symbol("needle:raycast-mesh");
|
|
51
|
-
function pe(
|
|
52
|
-
return (
|
|
51
|
+
function pe(a) {
|
|
52
|
+
return (a == null ? void 0 : a[de]) instanceof ie ? a[de] : null;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
if ((
|
|
56
|
-
const r =
|
|
57
|
-
r.userData = { isRaycastMesh: !0 },
|
|
54
|
+
function Ve(a, e) {
|
|
55
|
+
if ((a.type === "Mesh" || a.type === "SkinnedMesh") && !pe(a)) {
|
|
56
|
+
const r = Ne(e);
|
|
57
|
+
r.userData = { isRaycastMesh: !0 }, a[de] = r;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
if (
|
|
60
|
+
function st(a = !0) {
|
|
61
|
+
if (a) {
|
|
62
62
|
if (Y)
|
|
63
63
|
return;
|
|
64
64
|
const e = Y = W.prototype.raycast;
|
|
65
65
|
W.prototype.raycast = function(t, r) {
|
|
66
|
-
const
|
|
66
|
+
const n = this, i = pe(n);
|
|
67
67
|
let s;
|
|
68
|
-
|
|
68
|
+
i && n.isMesh && (s = n.geometry, n.geometry = i), e.call(this, t, r), s && (n.geometry = s);
|
|
69
69
|
};
|
|
70
70
|
} else {
|
|
71
71
|
if (!Y)
|
|
@@ -74,57 +74,57 @@ function et(l = !0) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
let Y = null;
|
|
77
|
-
function
|
|
78
|
-
const e = new
|
|
79
|
-
for (const t in
|
|
80
|
-
e.setAttribute(t,
|
|
81
|
-
return e.setIndex(
|
|
77
|
+
function Ne(a) {
|
|
78
|
+
const e = new ie();
|
|
79
|
+
for (const t in a.attributes)
|
|
80
|
+
e.setAttribute(t, a.getAttribute(t));
|
|
81
|
+
return e.setIndex(a.getIndex()), e;
|
|
82
82
|
}
|
|
83
|
-
const z = new Array(), F = "NEEDLE_progressive", m =
|
|
83
|
+
const z = new Array(), F = "NEEDLE_progressive", m = j("debugprogressive"), le = Symbol("needle-progressive-texture"), Z = /* @__PURE__ */ new Map(), he = /* @__PURE__ */ new Set();
|
|
84
84
|
if (m) {
|
|
85
|
-
let
|
|
86
|
-
e += 1, console.log("Toggle LOD level", e,
|
|
87
|
-
for (const s of
|
|
88
|
-
const o =
|
|
85
|
+
let a = function() {
|
|
86
|
+
e += 1, console.log("Toggle LOD level", e, Z), Z.forEach((n, i) => {
|
|
87
|
+
for (const s of n.keys) {
|
|
88
|
+
const o = i[s];
|
|
89
89
|
if (o != null) {
|
|
90
90
|
if (o.isBufferGeometry === !0) {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
} else if (
|
|
94
|
-
|
|
91
|
+
const l = O.getMeshLODInformation(o), f = l ? Math.min(e, l.lods.length) : 0;
|
|
92
|
+
i["DEBUG:LOD"] = e, O.assignMeshLOD(i, f), l && (t = Math.max(t, l.lods.length - 1));
|
|
93
|
+
} else if (i.isMaterial === !0) {
|
|
94
|
+
i["DEBUG:LOD"] = e, O.assignTextureLOD(i, e);
|
|
95
95
|
break;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}), e >= t && (e = -1);
|
|
100
100
|
}, e = -1, t = 2, r = !1;
|
|
101
|
-
window.addEventListener("keyup", (
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
window.addEventListener("keyup", (n) => {
|
|
102
|
+
n.key === "p" && a(), n.key === "w" && (r = !r, he && he.forEach((i) => {
|
|
103
|
+
i.name != "BackgroundCubeMaterial" && i.glyphMap == null && "wireframe" in i && (i.wireframe = r);
|
|
104
104
|
}));
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
-
function xe(
|
|
108
|
-
var
|
|
107
|
+
function xe(a, e, t) {
|
|
108
|
+
var n;
|
|
109
109
|
if (!m)
|
|
110
110
|
return;
|
|
111
|
-
|
|
112
|
-
const r =
|
|
113
|
-
((
|
|
111
|
+
Z.has(a) || Z.set(a, { keys: [], sourceId: t });
|
|
112
|
+
const r = Z.get(a);
|
|
113
|
+
((n = r == null ? void 0 : r.keys) == null ? void 0 : n.includes(e)) == !1 && r.keys.push(e);
|
|
114
114
|
}
|
|
115
|
-
const
|
|
115
|
+
const _ = class {
|
|
116
116
|
constructor(e, t) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var r,
|
|
117
|
+
d(this, "parser");
|
|
118
|
+
d(this, "url");
|
|
119
|
+
d(this, "_isLoadingMesh");
|
|
120
|
+
d(this, "loadMesh", (e) => {
|
|
121
|
+
var r, n;
|
|
122
122
|
if (this._isLoadingMesh)
|
|
123
123
|
return null;
|
|
124
|
-
const t = (
|
|
125
|
-
return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((
|
|
124
|
+
const t = (n = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : n[F];
|
|
125
|
+
return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((i) => {
|
|
126
126
|
var s;
|
|
127
|
-
return this._isLoadingMesh = !1,
|
|
127
|
+
return this._isLoadingMesh = !1, i && _.registerMesh(this.url, t.guid, i, (s = t.lods) == null ? void 0 : s.length, void 0, t), i;
|
|
128
128
|
})) : null;
|
|
129
129
|
});
|
|
130
130
|
m && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
|
|
@@ -138,9 +138,9 @@ const v = class {
|
|
|
138
138
|
return t != null && t.key ? this.lodInfos.get(t.key) : null;
|
|
139
139
|
}
|
|
140
140
|
static getMaterialMinMaxLODsCount(e, t) {
|
|
141
|
-
const r = this,
|
|
142
|
-
if (
|
|
143
|
-
return
|
|
141
|
+
const r = this, n = "LODS:minmax", i = e[n];
|
|
142
|
+
if (i != null)
|
|
143
|
+
return i;
|
|
144
144
|
if (t || (t = {
|
|
145
145
|
min_count: 1 / 0,
|
|
146
146
|
max_count: 0,
|
|
@@ -148,29 +148,29 @@ const v = class {
|
|
|
148
148
|
}), Array.isArray(e)) {
|
|
149
149
|
for (const o of e)
|
|
150
150
|
this.getMaterialMinMaxLODsCount(o, t);
|
|
151
|
-
return e[
|
|
151
|
+
return e[n] = t, t;
|
|
152
152
|
}
|
|
153
153
|
if (m === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
|
|
154
154
|
const o = e;
|
|
155
|
-
for (const
|
|
156
|
-
const
|
|
157
|
-
(
|
|
155
|
+
for (const l of Object.keys(o.uniforms)) {
|
|
156
|
+
const f = o.uniforms[l].value;
|
|
157
|
+
(f == null ? void 0 : f.isTexture) === !0 && s(f, t);
|
|
158
158
|
}
|
|
159
159
|
} else if (e.isMaterial)
|
|
160
160
|
for (const o of Object.keys(e)) {
|
|
161
|
-
const
|
|
162
|
-
(
|
|
161
|
+
const l = e[o];
|
|
162
|
+
(l == null ? void 0 : l.isTexture) === !0 && s(l, t);
|
|
163
163
|
}
|
|
164
|
-
return e[
|
|
165
|
-
function s(o,
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
const c = r.lodInfos.get(
|
|
164
|
+
return e[n] = t, t;
|
|
165
|
+
function s(o, l) {
|
|
166
|
+
const f = r.getAssignedLODInformation(o);
|
|
167
|
+
if (f) {
|
|
168
|
+
const c = r.lodInfos.get(f.key);
|
|
169
169
|
if (c && c.lods) {
|
|
170
|
-
|
|
170
|
+
l.min_count = Math.min(l.min_count, c.lods.length), l.max_count = Math.max(l.max_count, c.lods.length);
|
|
171
171
|
for (let x = 0; x < c.lods.length; x++) {
|
|
172
172
|
const u = c.lods[x];
|
|
173
|
-
u.width && (
|
|
173
|
+
u.width && (l.lods[x] = l.lods[x] || { min_height: 1 / 0, max_height: 0 }, l.lods[x].min_height = Math.min(l.lods[x].min_height, u.height), l.lods[x].max_height = Math.max(l.lods[x].max_height, u.height));
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -182,7 +182,7 @@ const v = class {
|
|
|
182
182
|
* @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
|
|
183
183
|
*/
|
|
184
184
|
static hasLODLevelAvailable(e, t) {
|
|
185
|
-
var
|
|
185
|
+
var i;
|
|
186
186
|
if (Array.isArray(e)) {
|
|
187
187
|
for (const s of e)
|
|
188
188
|
if (this.hasLODLevelAvailable(s, t))
|
|
@@ -201,13 +201,13 @@ const v = class {
|
|
|
201
201
|
if (s.isMesh === !0 && this.hasLODLevelAvailable(s, t))
|
|
202
202
|
return !0;
|
|
203
203
|
}
|
|
204
|
-
let r,
|
|
205
|
-
if (e.isMesh ? r = e.geometry : (e.isBufferGeometry || e.isTexture) && (r = e), r && (
|
|
204
|
+
let r, n;
|
|
205
|
+
if (e.isMesh ? r = e.geometry : (e.isBufferGeometry || e.isTexture) && (r = e), r && (i = r == null ? void 0 : r.userData) != null && i.LODS) {
|
|
206
206
|
const s = r.userData.LODS;
|
|
207
|
-
if (
|
|
208
|
-
return
|
|
209
|
-
if (
|
|
210
|
-
return Array.isArray(
|
|
207
|
+
if (n = this.lodInfos.get(s.key), t === void 0)
|
|
208
|
+
return n != null;
|
|
209
|
+
if (n)
|
|
210
|
+
return Array.isArray(n.lods) ? t < n.lods.length : t === 0;
|
|
211
211
|
}
|
|
212
212
|
return !1;
|
|
213
213
|
}
|
|
@@ -230,18 +230,18 @@ const v = class {
|
|
|
230
230
|
if (!e)
|
|
231
231
|
return Promise.resolve(null);
|
|
232
232
|
if (e instanceof W || e.isMesh === !0) {
|
|
233
|
-
const
|
|
234
|
-
if (!
|
|
233
|
+
const n = e.geometry, i = this.getAssignedLODInformation(n);
|
|
234
|
+
if (!i)
|
|
235
235
|
return Promise.resolve(null);
|
|
236
236
|
for (const s of z)
|
|
237
237
|
(r = s.onBeforeGetLODMesh) == null || r.call(s, e, t);
|
|
238
|
-
return e["LOD:requested level"] = t,
|
|
238
|
+
return e["LOD:requested level"] = t, _.getOrLoadLOD(n, t).then((s) => {
|
|
239
239
|
if (e["LOD:requested level"] === t) {
|
|
240
240
|
if (delete e["LOD:requested level"], Array.isArray(s)) {
|
|
241
|
-
const o =
|
|
241
|
+
const o = i.index || 0;
|
|
242
242
|
s = s[o];
|
|
243
243
|
}
|
|
244
|
-
s &&
|
|
244
|
+
s && n != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, m && xe(e, "geometry", i.url)) : m && console.error("Invalid LOD geometry", s));
|
|
245
245
|
}
|
|
246
246
|
return s;
|
|
247
247
|
}).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
|
|
@@ -259,30 +259,30 @@ const v = class {
|
|
|
259
259
|
static assignTextureLOD(e, t = 0) {
|
|
260
260
|
if (!e)
|
|
261
261
|
return Promise.resolve(null);
|
|
262
|
-
if (e instanceof
|
|
263
|
-
const r = e,
|
|
262
|
+
if (e instanceof Ee || e.isMaterial === !0) {
|
|
263
|
+
const r = e, n = [], i = new Array();
|
|
264
264
|
if (m && he.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
|
|
265
265
|
const s = r;
|
|
266
266
|
for (const o of Object.keys(s.uniforms)) {
|
|
267
|
-
const
|
|
268
|
-
if ((
|
|
269
|
-
const
|
|
270
|
-
|
|
267
|
+
const l = s.uniforms[o].value;
|
|
268
|
+
if ((l == null ? void 0 : l.isTexture) === !0) {
|
|
269
|
+
const f = this.assignTextureLODForSlot(l, t, r, o);
|
|
270
|
+
n.push(f), i.push(o);
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
} else
|
|
274
274
|
for (const s of Object.keys(r)) {
|
|
275
275
|
const o = r[s];
|
|
276
276
|
if ((o == null ? void 0 : o.isTexture) === !0) {
|
|
277
|
-
const
|
|
278
|
-
|
|
277
|
+
const l = this.assignTextureLODForSlot(o, t, r, s);
|
|
278
|
+
n.push(l), i.push(s);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
return Promise.all(
|
|
281
|
+
return Promise.all(n).then((s) => {
|
|
282
282
|
const o = new Array();
|
|
283
|
-
for (let
|
|
284
|
-
const
|
|
285
|
-
|
|
283
|
+
for (let l = 0; l < s.length; l++) {
|
|
284
|
+
const f = s[l], c = i[l];
|
|
285
|
+
f && f.isTexture === !0 ? o.push({ material: r, slot: c, texture: f, level: t }) : o.push({ material: r, slot: c, texture: null, level: t });
|
|
286
286
|
}
|
|
287
287
|
return o;
|
|
288
288
|
});
|
|
@@ -293,116 +293,116 @@ const v = class {
|
|
|
293
293
|
}
|
|
294
294
|
return Promise.resolve(null);
|
|
295
295
|
}
|
|
296
|
-
static assignTextureLODForSlot(e, t, r,
|
|
297
|
-
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) :
|
|
298
|
-
if (Array.isArray(
|
|
296
|
+
static assignTextureLODForSlot(e, t, r, n) {
|
|
297
|
+
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(e) : _.getOrLoadLOD(e, t).then((i) => {
|
|
298
|
+
if (Array.isArray(i))
|
|
299
299
|
return null;
|
|
300
|
-
if ((
|
|
301
|
-
if (
|
|
302
|
-
if (r &&
|
|
303
|
-
const s = r[
|
|
300
|
+
if ((i == null ? void 0 : i.isTexture) === !0) {
|
|
301
|
+
if (i != e) {
|
|
302
|
+
if (r && n) {
|
|
303
|
+
const s = r[n];
|
|
304
304
|
if (s) {
|
|
305
305
|
const o = this.getAssignedLODInformation(s);
|
|
306
306
|
if (o && (o == null ? void 0 : o.level) < t)
|
|
307
|
-
return m === "verbose" && console.warn("Assigned texture level is already higher: ", o.level, t, r, s,
|
|
307
|
+
return m === "verbose" && console.warn("Assigned texture level is already higher: ", o.level, t, r, s, i), null;
|
|
308
308
|
}
|
|
309
|
-
r[
|
|
309
|
+
r[n] = i;
|
|
310
310
|
}
|
|
311
|
-
if (m &&
|
|
311
|
+
if (m && n && r) {
|
|
312
312
|
const s = this.getAssignedLODInformation(e);
|
|
313
|
-
s && xe(r,
|
|
313
|
+
s && xe(r, n, s.url);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
-
return
|
|
316
|
+
return i;
|
|
317
317
|
} else
|
|
318
318
|
m == "verbose" && console.warn("No LOD found for", e, t);
|
|
319
319
|
return null;
|
|
320
|
-
}).catch((
|
|
320
|
+
}).catch((i) => (console.error("Error loading LOD", e, i), null));
|
|
321
321
|
}
|
|
322
322
|
afterRoot(e) {
|
|
323
323
|
var t, r;
|
|
324
|
-
return m && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((
|
|
324
|
+
return m && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((n, i) => {
|
|
325
325
|
var s;
|
|
326
|
-
if (
|
|
327
|
-
const o =
|
|
326
|
+
if (n != null && n.extensions) {
|
|
327
|
+
const o = n == null ? void 0 : n.extensions[F];
|
|
328
328
|
if (o) {
|
|
329
329
|
if (!o.lods) {
|
|
330
330
|
m && console.warn("Texture has no LODs", o);
|
|
331
331
|
return;
|
|
332
332
|
}
|
|
333
|
-
let
|
|
334
|
-
for (const
|
|
335
|
-
|
|
336
|
-
|
|
333
|
+
let l = !1;
|
|
334
|
+
for (const f of this.parser.associations.keys())
|
|
335
|
+
f.isTexture === !0 && this.parser.associations.get(f).textures === i && (l = !0, _.registerTexture(this.url, f, (s = o.lods) == null ? void 0 : s.length, i, o));
|
|
336
|
+
l || this.parser.getDependency("texture", i).then((f) => {
|
|
337
337
|
var c;
|
|
338
|
-
|
|
338
|
+
f && _.registerTexture(this.url, f, (c = o.lods) == null ? void 0 : c.length, i, o);
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
|
-
}), (r = this.parser.json.meshes) == null || r.forEach((
|
|
343
|
-
if (
|
|
344
|
-
const s =
|
|
342
|
+
}), (r = this.parser.json.meshes) == null || r.forEach((n, i) => {
|
|
343
|
+
if (n != null && n.extensions) {
|
|
344
|
+
const s = n == null ? void 0 : n.extensions[F];
|
|
345
345
|
if (s && s.lods) {
|
|
346
346
|
for (const o of this.parser.associations.keys())
|
|
347
347
|
if (o.isMesh) {
|
|
348
|
-
const
|
|
349
|
-
|
|
348
|
+
const l = this.parser.associations.get(o);
|
|
349
|
+
l.meshes === i && _.registerMesh(this.url, s.guid, o, s.lods.length, l.primitives, s);
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
}), null;
|
|
354
354
|
}
|
|
355
355
|
static async getOrLoadLOD(e, t) {
|
|
356
|
-
var o,
|
|
357
|
-
const r = m == "verbose",
|
|
358
|
-
if (!
|
|
356
|
+
var o, l, f, c;
|
|
357
|
+
const r = m == "verbose", n = e.userData.LODS;
|
|
358
|
+
if (!n)
|
|
359
359
|
return null;
|
|
360
|
-
const
|
|
360
|
+
const i = n == null ? void 0 : n.key;
|
|
361
361
|
let s;
|
|
362
362
|
if (e.isTexture === !0) {
|
|
363
363
|
const x = e;
|
|
364
|
-
x.source && x.source[
|
|
364
|
+
x.source && x.source[le] && (s = x.source[le]);
|
|
365
365
|
}
|
|
366
|
-
if (s || (s =
|
|
366
|
+
if (s || (s = _.lodInfos.get(i)), s) {
|
|
367
367
|
if (t > 0) {
|
|
368
368
|
let y = !1;
|
|
369
369
|
const w = Array.isArray(s.lods);
|
|
370
370
|
if (w && t >= s.lods.length ? y = !0 : w || (y = !0), y)
|
|
371
|
-
return this.lowresCache.get(
|
|
371
|
+
return this.lowresCache.get(i);
|
|
372
372
|
}
|
|
373
373
|
const x = Array.isArray(s.lods) ? (o = s.lods[t]) == null ? void 0 : o.path : s.lods;
|
|
374
374
|
if (!x)
|
|
375
375
|
return m && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
|
|
376
|
-
const u =
|
|
376
|
+
const u = $e(n.url, x);
|
|
377
377
|
if (u.endsWith(".glb") || u.endsWith(".gltf")) {
|
|
378
378
|
if (!s.guid)
|
|
379
379
|
return console.warn("missing pointer for glb/gltf texture", s), null;
|
|
380
380
|
const y = u + "_" + s.guid, w = this.previouslyLoaded.get(y);
|
|
381
381
|
if (w !== void 0) {
|
|
382
382
|
r && console.log(`LOD ${t} was already loading/loaded: ${y}`);
|
|
383
|
-
let p = await w.catch((
|
|
384
|
-
`,
|
|
385
|
-
if (p == null || (p instanceof q && e instanceof q ? (
|
|
383
|
+
let p = await w.catch((V) => (console.error(`Error loading LOD ${t} from ${u}
|
|
384
|
+
`, V), null)), M = !1;
|
|
385
|
+
if (p == null || (p instanceof q && e instanceof q ? (l = p.image) != null && l.data || (f = p.source) != null && f.data ? p = this.copySettings(e, p) : (M = !0, this.previouslyLoaded.delete(y)) : p instanceof ie && e instanceof ie && ((c = p.attributes.position) != null && c.array || (M = !0, this.previouslyLoaded.delete(y)))), !M)
|
|
386
386
|
return p;
|
|
387
387
|
}
|
|
388
388
|
const L = s, B = new Promise(async (p, M) => {
|
|
389
|
-
const
|
|
390
|
-
_e(
|
|
391
|
-
let
|
|
389
|
+
const V = new ke();
|
|
390
|
+
_e(V), m && (await new Promise((S) => setTimeout(S, 1e3)), r && console.warn("Start loading (delayed) " + u, L.guid));
|
|
391
|
+
let R = u;
|
|
392
392
|
if (L && Array.isArray(L.lods)) {
|
|
393
393
|
const S = L.lods[t];
|
|
394
|
-
S.hash && (
|
|
394
|
+
S.hash && (R += "?v=" + S.hash);
|
|
395
395
|
}
|
|
396
|
-
const
|
|
396
|
+
const v = await V.loadAsync(R).catch((S) => (console.error(`Error loading LOD ${t} from ${u}
|
|
397
397
|
`, S), null));
|
|
398
|
-
if (!
|
|
398
|
+
if (!v)
|
|
399
399
|
return null;
|
|
400
|
-
const $ =
|
|
400
|
+
const $ = v.parser;
|
|
401
401
|
r && console.log("Loading finished " + u, L.guid);
|
|
402
|
-
let
|
|
403
|
-
if (
|
|
402
|
+
let k = 0;
|
|
403
|
+
if (v.parser.json.textures) {
|
|
404
404
|
let S = !1;
|
|
405
|
-
for (const g of
|
|
405
|
+
for (const g of v.parser.json.textures) {
|
|
406
406
|
if (g != null && g.extensions) {
|
|
407
407
|
const h = g == null ? void 0 : g.extensions[F];
|
|
408
408
|
if (h != null && h.guid && h.guid === L.guid) {
|
|
@@ -410,17 +410,17 @@ const v = class {
|
|
|
410
410
|
break;
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
|
-
|
|
413
|
+
k++;
|
|
414
414
|
}
|
|
415
415
|
if (S) {
|
|
416
|
-
let g = await $.getDependency("texture",
|
|
417
|
-
return g &&
|
|
416
|
+
let g = await $.getDependency("texture", k);
|
|
417
|
+
return g && _.assignLODInformation(n.url, g, i, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + g.name + '"', u, k, g, y), e instanceof q && (g = this.copySettings(e, g)), g && (g.guid = L.guid), p(g);
|
|
418
418
|
} else
|
|
419
|
-
m && console.warn("Could not find texture with guid", L.guid,
|
|
419
|
+
m && console.warn("Could not find texture with guid", L.guid, v.parser.json);
|
|
420
420
|
}
|
|
421
|
-
if (
|
|
421
|
+
if (k = 0, v.parser.json.meshes) {
|
|
422
422
|
let S = !1;
|
|
423
|
-
for (const g of
|
|
423
|
+
for (const g of v.parser.json.meshes) {
|
|
424
424
|
if (g != null && g.extensions) {
|
|
425
425
|
const h = g == null ? void 0 : g.extensions[F];
|
|
426
426
|
if (h != null && h.guid && h.guid === L.guid) {
|
|
@@ -428,44 +428,44 @@ const v = class {
|
|
|
428
428
|
break;
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
-
|
|
431
|
+
k++;
|
|
432
432
|
}
|
|
433
433
|
if (S) {
|
|
434
|
-
const g = await $.getDependency("mesh",
|
|
435
|
-
if (r && console.log(`Loaded Mesh "${g.name}"`, u,
|
|
434
|
+
const g = await $.getDependency("mesh", k), h = L;
|
|
435
|
+
if (r && console.log(`Loaded Mesh "${g.name}"`, u, k, g, y), g.isMesh === !0) {
|
|
436
436
|
const D = g.geometry;
|
|
437
|
-
return
|
|
437
|
+
return _.assignLODInformation(n.url, D, i, t, void 0, h.density), p(D);
|
|
438
438
|
} else {
|
|
439
439
|
const D = new Array();
|
|
440
440
|
for (let b = 0; b < g.children.length; b++) {
|
|
441
441
|
const T = g.children[b];
|
|
442
442
|
if (T.isMesh === !0) {
|
|
443
443
|
const A = T.geometry;
|
|
444
|
-
|
|
444
|
+
_.assignLODInformation(n.url, A, i, t, b, h.density), D.push(A);
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
447
|
return p(D);
|
|
448
448
|
}
|
|
449
449
|
} else
|
|
450
|
-
m && console.warn("Could not find mesh with guid", L.guid,
|
|
450
|
+
m && console.warn("Could not find mesh with guid", L.guid, v.parser.json);
|
|
451
451
|
}
|
|
452
452
|
return p(null);
|
|
453
453
|
});
|
|
454
454
|
return this.previouslyLoaded.set(y, B), await B;
|
|
455
455
|
} else if (e instanceof q) {
|
|
456
456
|
r && console.log("Load texture from uri: " + u);
|
|
457
|
-
const w = await new
|
|
457
|
+
const w = await new Ce().loadAsync(u);
|
|
458
458
|
return w ? (w.guid = s.guid, w.flipY = !1, w.needsUpdate = !0, w.colorSpace = e.colorSpace, r && console.log(s, w)) : m && console.warn("failed loading", u), w;
|
|
459
459
|
}
|
|
460
460
|
} else
|
|
461
|
-
m && console.warn(`Can not load LOD ${t}: no LOD info found for "${
|
|
461
|
+
m && console.warn(`Can not load LOD ${t}: no LOD info found for "${i}" ${e.name}`, e.type);
|
|
462
462
|
return null;
|
|
463
463
|
}
|
|
464
|
-
static assignLODInformation(e, t, r,
|
|
464
|
+
static assignLODInformation(e, t, r, n, i, s) {
|
|
465
465
|
if (!t)
|
|
466
466
|
return;
|
|
467
467
|
t.userData || (t.userData = {});
|
|
468
|
-
const o = new
|
|
468
|
+
const o = new Ue(e, r, n, i, s);
|
|
469
469
|
t.userData.LODS = o;
|
|
470
470
|
}
|
|
471
471
|
static getAssignedLODInformation(e) {
|
|
@@ -479,87 +479,87 @@ const v = class {
|
|
|
479
479
|
`, 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;
|
|
480
480
|
}
|
|
481
481
|
};
|
|
482
|
-
let O =
|
|
482
|
+
let O = _;
|
|
483
483
|
/**
|
|
484
484
|
* Register a texture with LOD information
|
|
485
485
|
*/
|
|
486
|
-
|
|
487
|
-
if (m && console.log("> Progressive: register texture",
|
|
486
|
+
d(O, "registerTexture", (e, t, r, n, i) => {
|
|
487
|
+
if (m && console.log("> Progressive: register texture", n, t.name, t.uuid, t, i), !t) {
|
|
488
488
|
m && console.error("gltf-progressive: Register texture without texture");
|
|
489
489
|
return;
|
|
490
490
|
}
|
|
491
|
-
t.source && (t.source[
|
|
492
|
-
const s =
|
|
493
|
-
|
|
491
|
+
t.source && (t.source[le] = i);
|
|
492
|
+
const s = i.guid;
|
|
493
|
+
_.assignLODInformation(e, t, s, r, n, void 0), _.lodInfos.set(s, i), _.lowresCache.set(s, t);
|
|
494
494
|
}), /**
|
|
495
495
|
* Register a mesh with LOD information
|
|
496
496
|
*/
|
|
497
|
-
|
|
498
|
-
var
|
|
499
|
-
m && console.log("> Progressive: register mesh",
|
|
497
|
+
d(O, "registerMesh", (e, t, r, n, i, s) => {
|
|
498
|
+
var f;
|
|
499
|
+
m && console.log("> Progressive: register mesh", i, r.name, s, r.uuid, r);
|
|
500
500
|
const o = r.geometry;
|
|
501
501
|
if (!o) {
|
|
502
502
|
m && console.warn("gltf-progressive: Register mesh without geometry");
|
|
503
503
|
return;
|
|
504
504
|
}
|
|
505
|
-
o.userData || (o.userData = {}),
|
|
506
|
-
let
|
|
507
|
-
|
|
505
|
+
o.userData || (o.userData = {}), _.assignLODInformation(e, o, t, n, i, s.density), _.lodInfos.set(t, s);
|
|
506
|
+
let l = _.lowresCache.get(t);
|
|
507
|
+
l ? l.push(r.geometry) : l = [r.geometry], _.lowresCache.set(t, l), n > 0 && !pe(r) && Ve(r, o);
|
|
508
508
|
for (const c of z)
|
|
509
|
-
(
|
|
509
|
+
(f = c.onRegisteredNewMesh) == null || f.call(c, r, s);
|
|
510
510
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
class
|
|
515
|
-
constructor(e, t, r,
|
|
516
|
-
|
|
511
|
+
d(O, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
512
|
+
d(O, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
513
|
+
d(O, "lowresCache", /* @__PURE__ */ new Map());
|
|
514
|
+
class Ue {
|
|
515
|
+
constructor(e, t, r, n, i) {
|
|
516
|
+
d(this, "url");
|
|
517
517
|
/** the key to lookup the LOD information */
|
|
518
|
-
|
|
519
|
-
|
|
518
|
+
d(this, "key");
|
|
519
|
+
d(this, "level");
|
|
520
520
|
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
521
|
-
|
|
521
|
+
d(this, "index");
|
|
522
522
|
/** the mesh density */
|
|
523
|
-
|
|
524
|
-
this.url = e, this.key = t, this.level = r,
|
|
523
|
+
d(this, "density");
|
|
524
|
+
this.url = e, this.key = t, this.level = r, n != null && (this.index = n), i != null && (this.density = i);
|
|
525
525
|
}
|
|
526
526
|
}
|
|
527
|
-
const N =
|
|
527
|
+
const N = j("debugprogressive"), We = j("noprogressive"), ce = Symbol("Needle:LODSManager"), ue = Symbol("Needle:LODState"), U = Symbol("Needle:CurrentLOD"), E = { mesh_lod: -1, texture_lod: -1 }, P = class {
|
|
528
528
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
529
529
|
constructor(e, t) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
530
|
+
d(this, "context");
|
|
531
|
+
d(this, "renderer");
|
|
532
|
+
d(this, "projectionScreenMatrix", new ye());
|
|
533
|
+
d(this, "cameraFrustrum", new Be());
|
|
534
534
|
/**
|
|
535
535
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
536
536
|
* @default 200_000
|
|
537
537
|
*/
|
|
538
|
-
|
|
538
|
+
d(this, "targetTriangleDensity", 2e5);
|
|
539
539
|
/**
|
|
540
540
|
* The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 1, the LODs will be updated every second frame, etc.
|
|
541
541
|
*/
|
|
542
|
-
|
|
542
|
+
d(this, "updateInterval", 0);
|
|
543
543
|
/**
|
|
544
544
|
* If set to true, the LODsManager will not update the LODs.
|
|
545
545
|
*/
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
546
|
+
d(this, "pause", !1);
|
|
547
|
+
d(this, "_lodchangedlisteners", []);
|
|
548
|
+
d(this, "_frame", 0);
|
|
549
|
+
d(this, "_originalRender");
|
|
550
550
|
// private testIfLODLevelsAreAvailable() {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
551
|
+
d(this, "_sphere", new Re());
|
|
552
|
+
d(this, "_tempBox", new me());
|
|
553
|
+
d(this, "_tempBox2", new me());
|
|
554
|
+
d(this, "tempMatrix", new ye());
|
|
555
|
+
d(this, "_tempWorldPosition", new G());
|
|
556
|
+
d(this, "_tempBoxSize", new G());
|
|
557
|
+
d(this, "_tempBox2Size", new G());
|
|
558
558
|
this.renderer = e, this.context = { ...t };
|
|
559
559
|
}
|
|
560
560
|
/** @internal */
|
|
561
561
|
static getObjectLODState(e) {
|
|
562
|
-
return e[
|
|
562
|
+
return e[ue];
|
|
563
563
|
}
|
|
564
564
|
static addPlugin(e) {
|
|
565
565
|
z.push(e);
|
|
@@ -574,13 +574,13 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
|
|
|
574
574
|
* @returns The LODsManager instance.
|
|
575
575
|
*/
|
|
576
576
|
static get(e, t) {
|
|
577
|
-
if (e[
|
|
578
|
-
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[
|
|
577
|
+
if (e[ce])
|
|
578
|
+
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[ce];
|
|
579
579
|
const r = new P(e, {
|
|
580
580
|
engine: "unknown",
|
|
581
581
|
...t
|
|
582
582
|
});
|
|
583
|
-
return e[
|
|
583
|
+
return e[ce] = r, r;
|
|
584
584
|
}
|
|
585
585
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
586
586
|
get plugins() {
|
|
@@ -599,34 +599,34 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
|
|
|
599
599
|
let e = 0;
|
|
600
600
|
this._originalRender = this.renderer.render;
|
|
601
601
|
const t = this;
|
|
602
|
-
|
|
602
|
+
ve(this.renderer), this.renderer.render = function(r, n) {
|
|
603
603
|
t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
|
|
604
604
|
const s = t._frame, o = e++;
|
|
605
|
-
t.onBeforeRender(r,
|
|
605
|
+
t.onBeforeRender(r, n, o, s), t._originalRender.call(this, r, n), t.onAfterRender(r, n, o, s);
|
|
606
606
|
};
|
|
607
607
|
}
|
|
608
608
|
disable() {
|
|
609
609
|
this._originalRender && (this.renderer.render = this._originalRender, this._originalRender = void 0);
|
|
610
610
|
}
|
|
611
|
-
onBeforeRender(e, t, r,
|
|
611
|
+
onBeforeRender(e, t, r, n) {
|
|
612
612
|
}
|
|
613
|
-
onAfterRender(e, t, r,
|
|
614
|
-
var
|
|
613
|
+
onAfterRender(e, t, r, n) {
|
|
614
|
+
var l, f;
|
|
615
615
|
if (this.pause)
|
|
616
616
|
return;
|
|
617
|
-
const
|
|
617
|
+
const i = this.renderer.renderLists.get(e, 0), s = i.opaque;
|
|
618
618
|
let o = !0;
|
|
619
619
|
if (s.length === 1) {
|
|
620
620
|
const c = s[0].material;
|
|
621
621
|
(c.name === "EffectMaterial" || c.name === "CopyShader") && (o = !1);
|
|
622
622
|
}
|
|
623
623
|
if ((t.parent && t.parent.type === "CubeCamera" || r >= 1 && t.type === "OrthographicCamera") && (o = !1), o) {
|
|
624
|
-
if (
|
|
624
|
+
if (We || this.updateInterval > 0 && n % this.updateInterval != 0)
|
|
625
625
|
return;
|
|
626
626
|
this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
|
|
627
627
|
const c = this.targetTriangleDensity;
|
|
628
628
|
for (const u of s) {
|
|
629
|
-
if (u.material && (((
|
|
629
|
+
if (u.material && (((l = u.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((f = u.geometry) == null ? void 0 : f.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
|
|
630
630
|
N && (u.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (u.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", u, u.material.name, u.material.type)));
|
|
631
631
|
continue;
|
|
632
632
|
}
|
|
@@ -640,33 +640,33 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
|
|
|
640
640
|
continue;
|
|
641
641
|
}
|
|
642
642
|
const y = u.object;
|
|
643
|
-
(y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c,
|
|
643
|
+
(y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, n);
|
|
644
644
|
}
|
|
645
|
-
const x =
|
|
645
|
+
const x = i.transparent;
|
|
646
646
|
for (const u of x) {
|
|
647
647
|
const y = u.object;
|
|
648
|
-
(y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c,
|
|
648
|
+
(y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, n);
|
|
649
649
|
}
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
652
|
/** Update the LOD levels for the renderer. */
|
|
653
|
-
updateLODs(e, t, r,
|
|
654
|
-
var
|
|
653
|
+
updateLODs(e, t, r, n, i) {
|
|
654
|
+
var l, f;
|
|
655
655
|
r.userData || (r.userData = {});
|
|
656
|
-
let s = r[
|
|
657
|
-
if (s || (s = new
|
|
656
|
+
let s = r[ue];
|
|
657
|
+
if (s || (s = new Ke(), r[ue] = s), s.frames++ < 2)
|
|
658
658
|
return;
|
|
659
659
|
for (const c of z)
|
|
660
|
-
(
|
|
661
|
-
this.calculateLodLevel(t, r, s,
|
|
662
|
-
let o =
|
|
660
|
+
(l = c.onBeforeUpdateLOD) == null || l.call(c, this.renderer, e, t, r);
|
|
661
|
+
this.calculateLodLevel(t, r, s, n, E), E.mesh_lod = Math.round(E.mesh_lod), E.texture_lod = Math.round(E.texture_lod), E.mesh_lod >= 0 && this.loadProgressiveMeshes(r, E.mesh_lod);
|
|
662
|
+
let o = E.texture_lod;
|
|
663
663
|
if (r.material && o >= 0) {
|
|
664
664
|
const c = r["DEBUG:LOD"];
|
|
665
665
|
c != null && (o = c), this.loadProgressiveTextures(r.material, o);
|
|
666
666
|
}
|
|
667
667
|
for (const c of z)
|
|
668
|
-
(
|
|
669
|
-
s.lastLodLevel_Mesh =
|
|
668
|
+
(f = c.onAfterUpdatedLOD) == null || f.call(c, this.renderer, e, t, r, E);
|
|
669
|
+
s.lastLodLevel_Mesh = E.mesh_lod, s.lastLodLevel_Texture = E.texture_lod;
|
|
670
670
|
}
|
|
671
671
|
/** Load progressive textures for the given material
|
|
672
672
|
* @param material the material to load the textures for
|
|
@@ -677,13 +677,13 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
|
|
|
677
677
|
if (!e)
|
|
678
678
|
return;
|
|
679
679
|
if (Array.isArray(e)) {
|
|
680
|
-
for (const
|
|
681
|
-
this.loadProgressiveTextures(
|
|
680
|
+
for (const n of e)
|
|
681
|
+
this.loadProgressiveTextures(n, t);
|
|
682
682
|
return;
|
|
683
683
|
}
|
|
684
684
|
let r = !1;
|
|
685
|
-
(e[
|
|
686
|
-
this._lodchangedlisteners.forEach((
|
|
685
|
+
(e[U] === void 0 || t < e[U]) && (r = !0), r && (e[U] = t, O.assignTextureLOD(e, t).then((n) => {
|
|
686
|
+
this._lodchangedlisteners.forEach((i) => i({ type: "texture", level: t, object: e }));
|
|
687
687
|
}));
|
|
688
688
|
}
|
|
689
689
|
/** Load progressive meshes for the given mesh
|
|
@@ -695,37 +695,37 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
|
|
|
695
695
|
loadProgressiveMeshes(e, t) {
|
|
696
696
|
if (!e)
|
|
697
697
|
return Promise.resolve(null);
|
|
698
|
-
if (e[
|
|
699
|
-
e[
|
|
698
|
+
if (e[U] !== t) {
|
|
699
|
+
e[U] = t;
|
|
700
700
|
const r = e.geometry;
|
|
701
|
-
return O.assignMeshLOD(e, t).then((
|
|
701
|
+
return O.assignMeshLOD(e, t).then((n) => (n && e[U] == t && r != e.geometry && this._lodchangedlisteners.forEach((i) => i({ type: "mesh", level: t, object: e })), n));
|
|
702
702
|
}
|
|
703
703
|
return Promise.resolve(null);
|
|
704
704
|
}
|
|
705
705
|
static isInside(e, t) {
|
|
706
|
-
const r = e.min,
|
|
707
|
-
return this._tempPtInside.set(
|
|
706
|
+
const r = e.min, n = e.max, i = (r.x + n.x) * 0.5, s = (r.y + n.y) * 0.5;
|
|
707
|
+
return this._tempPtInside.set(i, s, r.z).applyMatrix4(t).z < 0;
|
|
708
708
|
}
|
|
709
|
-
calculateLodLevel(e, t, r,
|
|
709
|
+
calculateLodLevel(e, t, r, n, i) {
|
|
710
710
|
var B, I;
|
|
711
711
|
if (!t) {
|
|
712
|
-
|
|
712
|
+
i.mesh_lod = -1, i.texture_lod = -1;
|
|
713
713
|
return;
|
|
714
714
|
}
|
|
715
715
|
if (!e) {
|
|
716
|
-
|
|
716
|
+
i.mesh_lod = -1, i.texture_lod = -1;
|
|
717
717
|
return;
|
|
718
718
|
}
|
|
719
|
-
let o = 10 + 1,
|
|
719
|
+
let o = 10 + 1, l = !1;
|
|
720
720
|
if (N && t["DEBUG:LOD"] != null)
|
|
721
721
|
return t["DEBUG:LOD"];
|
|
722
|
-
const
|
|
722
|
+
const f = O.getMeshLODInformation(t.geometry), c = f == null ? void 0 : f.lods, x = c && c.length > 0, u = O.getMaterialMinMaxLODsCount(t.material), y = (u == null ? void 0 : u.min_count) != 1 / 0 && u.min_count > 0 && u.max_count > 0;
|
|
723
723
|
if (!x && !y) {
|
|
724
|
-
|
|
724
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
725
725
|
return;
|
|
726
726
|
}
|
|
727
|
-
if (x || (
|
|
728
|
-
|
|
727
|
+
if (x || (l = !0, o = 0), !((B = this.cameraFrustrum) != null && B.intersectsObject(t))) {
|
|
728
|
+
i.mesh_lod = 99, i.texture_lod = 99;
|
|
729
729
|
return;
|
|
730
730
|
}
|
|
731
731
|
const w = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
@@ -740,29 +740,29 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
|
|
|
740
740
|
this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
|
|
741
741
|
const h = e.getWorldPosition(this._tempWorldPosition);
|
|
742
742
|
if (this._sphere.containsPoint(h)) {
|
|
743
|
-
|
|
743
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
744
744
|
return;
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
747
|
if (this._tempBox.copy(L), this._tempBox.applyMatrix4(t.matrixWorld), P.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
748
|
-
|
|
748
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
749
749
|
return;
|
|
750
750
|
}
|
|
751
751
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && p.fov > 70) {
|
|
752
752
|
const h = this._tempBox.min, D = this._tempBox.max;
|
|
753
753
|
let b = h.x, T = h.y, A = D.x, K = D.y;
|
|
754
|
-
const
|
|
755
|
-
b = (b -
|
|
756
|
-
const
|
|
757
|
-
r.lastCentrality = (
|
|
754
|
+
const ee = 2, oe = 1.5, te = (h.x + D.x) * 0.5, re = (h.y + D.y) * 0.5;
|
|
755
|
+
b = (b - te) * ee + te, T = (T - re) * ee + re, A = (A - te) * ee + te, K = (K - re) * ee + re;
|
|
756
|
+
const be = b < 0 && A > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(D.x)), Te = T < 0 && K > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(D.y)), ae = Math.max(be, Te);
|
|
757
|
+
r.lastCentrality = (oe - ae) * (oe - ae) * (oe - ae);
|
|
758
758
|
} else
|
|
759
759
|
r.lastCentrality = 1;
|
|
760
760
|
const M = this._tempBox.getSize(this._tempBoxSize);
|
|
761
761
|
M.multiplyScalar(0.5), screen.availHeight > 0 && w > 0 && M.multiplyScalar(w / screen.availHeight), M.x *= p.aspect;
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
const
|
|
765
|
-
if (Math.max(M.x, M.y) != 0 && $ != 0 && (M.z =
|
|
762
|
+
const V = e.matrixWorldInverse, R = this._tempBox2;
|
|
763
|
+
R.copy(L), R.applyMatrix4(t.matrixWorld), R.applyMatrix4(V);
|
|
764
|
+
const v = R.getSize(this._tempBox2Size), $ = Math.max(v.x, v.y);
|
|
765
|
+
if (Math.max(M.x, M.y) != 0 && $ != 0 && (M.z = v.z / Math.max(v.x, v.y) * Math.max(M.x, M.y)), r.lastScreenCoverage = Math.max(M.x, M.y, M.z), r.lastScreenspaceVolume.copy(M), r.lastScreenCoverage *= r.lastCentrality, N && P.debugDrawLine) {
|
|
766
766
|
const h = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
767
767
|
h.invert();
|
|
768
768
|
const D = P.corner0, b = P.corner1, T = P.corner2, A = P.corner3;
|
|
@@ -773,35 +773,35 @@ const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LO
|
|
|
773
773
|
let S = 999;
|
|
774
774
|
if (c && r.lastScreenCoverage > 0) {
|
|
775
775
|
for (let h = 0; h < c.length; h++)
|
|
776
|
-
if (c[h].density / r.lastScreenCoverage <
|
|
776
|
+
if (c[h].density / r.lastScreenCoverage < n) {
|
|
777
777
|
S = h;
|
|
778
778
|
break;
|
|
779
779
|
}
|
|
780
780
|
}
|
|
781
|
-
S < o && (o = S,
|
|
781
|
+
S < o && (o = S, l = !0);
|
|
782
782
|
}
|
|
783
|
-
if (
|
|
784
|
-
const M = c == null ? void 0 : c[
|
|
785
|
-
M && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${
|
|
783
|
+
if (l ? i.mesh_lod = o : i.mesh_lod = r.lastLodLevel_Mesh, N && i.mesh_lod != r.lastLodLevel_Mesh) {
|
|
784
|
+
const M = c == null ? void 0 : c[i.mesh_lod];
|
|
785
|
+
M && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${i.mesh_lod} (${M.density.toFixed(0)}) - ${t.name}`);
|
|
786
786
|
}
|
|
787
787
|
if (y)
|
|
788
788
|
if (r.lastLodLevel_Texture < 0) {
|
|
789
|
-
if (
|
|
789
|
+
if (i.texture_lod = u.max_count - 1, N) {
|
|
790
790
|
const p = u.lods[u.max_count - 1];
|
|
791
|
-
N && console.log(`First Texture LOD ${
|
|
791
|
+
N && console.log(`First Texture LOD ${i.texture_lod} (${p.max_height}px) - ${t.name}`);
|
|
792
792
|
}
|
|
793
793
|
} else {
|
|
794
794
|
const p = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
|
|
795
795
|
let M = r.lastScreenCoverage * 2;
|
|
796
796
|
((I = this.context) == null ? void 0 : I.engine) === "model-viewer" && (M *= 2);
|
|
797
|
-
const
|
|
798
|
-
for (let
|
|
799
|
-
let $ = u.lods[
|
|
800
|
-
if (!(
|
|
801
|
-
if (
|
|
802
|
-
const
|
|
803
|
-
N && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${
|
|
804
|
-
Screensize: ${
|
|
797
|
+
const R = w / window.devicePixelRatio * M;
|
|
798
|
+
for (let v = u.lods.length - 1; v >= 0; v--) {
|
|
799
|
+
let $ = u.lods[v];
|
|
800
|
+
if (!(ze() && $.max_height > 4096) && $.max_height > R) {
|
|
801
|
+
if (i.texture_lod = v, i.texture_lod < r.lastLodLevel_Texture) {
|
|
802
|
+
const k = $.max_height;
|
|
803
|
+
N && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${i.texture_lod} = ${k}px
|
|
804
|
+
Screensize: ${R.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
|
|
805
805
|
${t.name}`);
|
|
806
806
|
}
|
|
807
807
|
break;
|
|
@@ -809,74 +809,92 @@ ${t.name}`);
|
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
811
|
else
|
|
812
|
-
|
|
812
|
+
i.texture_lod = 0;
|
|
813
813
|
}
|
|
814
814
|
};
|
|
815
|
-
let
|
|
815
|
+
let C = P;
|
|
816
816
|
/** 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.
|
|
817
817
|
*/
|
|
818
|
-
|
|
819
|
-
class
|
|
818
|
+
d(C, "debugDrawLine"), d(C, "corner0", new G()), d(C, "corner1", new G()), d(C, "corner2", new G()), d(C, "corner3", new G()), d(C, "_tempPtInside", new G());
|
|
819
|
+
class Ke {
|
|
820
820
|
constructor() {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
821
|
+
d(this, "frames", 0);
|
|
822
|
+
d(this, "lastLodLevel_Mesh", -1);
|
|
823
|
+
d(this, "lastLodLevel_Texture", -1);
|
|
824
|
+
d(this, "lastScreenCoverage", 0);
|
|
825
|
+
d(this, "lastScreenspaceVolume", new G());
|
|
826
|
+
d(this, "lastCentrality", 0);
|
|
827
827
|
}
|
|
828
828
|
}
|
|
829
|
-
const Le = Symbol("NEEDLE_mesh_lod"),
|
|
830
|
-
|
|
831
|
-
|
|
829
|
+
const Le = Symbol("NEEDLE_mesh_lod"), se = Symbol("NEEDLE_texture_lod");
|
|
830
|
+
let H = null;
|
|
831
|
+
function Oe() {
|
|
832
|
+
const a = qe();
|
|
833
|
+
a && (a.mapURLs(function(e) {
|
|
834
|
+
return Me(), e;
|
|
835
|
+
}), Me(), H == null || H.disconnect(), H = new MutationObserver((e) => {
|
|
836
|
+
e.forEach((t) => {
|
|
837
|
+
t.addedNodes.forEach((r) => {
|
|
838
|
+
r instanceof HTMLElement && r.tagName.toLowerCase() === "model-viewer" && Se(r);
|
|
839
|
+
});
|
|
840
|
+
});
|
|
841
|
+
}), H.observe(document, { childList: !0, subtree: !0 }));
|
|
842
|
+
}
|
|
843
|
+
function qe() {
|
|
844
|
+
const a = customElements.get("model-viewer");
|
|
845
|
+
return a || (customElements.whenDefined("model-viewer").then(() => {
|
|
846
|
+
console.debug("[gltf-progressive] model-viewer defined"), Oe();
|
|
847
|
+
}), null);
|
|
832
848
|
}
|
|
833
|
-
function
|
|
834
|
-
document.querySelectorAll("model-viewer").forEach((e
|
|
835
|
-
|
|
849
|
+
function Me() {
|
|
850
|
+
document.querySelectorAll("model-viewer").forEach((e) => {
|
|
851
|
+
Se(e);
|
|
836
852
|
});
|
|
837
853
|
}
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
854
|
+
const De = /* @__PURE__ */ new WeakSet();
|
|
855
|
+
let Xe = 0;
|
|
856
|
+
function Se(a) {
|
|
857
|
+
if (!a || De.has(a))
|
|
841
858
|
return null;
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
859
|
+
De.add(a), console.debug("[gltf-progressive] found new model-viewer..." + ++Xe + `
|
|
860
|
+
`, a.getAttribute("src"));
|
|
861
|
+
let e = null, t = null, r = null;
|
|
862
|
+
for (let n = a; n != null; n = Object.getPrototypeOf(n)) {
|
|
863
|
+
const i = Object.getOwnPropertySymbols(n), s = i.find((f) => f.toString() == "Symbol(renderer)"), o = i.find((f) => f.toString() == "Symbol(scene)"), l = i.find((f) => f.toString() == "Symbol(needsRender)");
|
|
864
|
+
!e && s != null && (e = a[s].threeRenderer), !t && o != null && (t = a[o]), !r && l != null && (r = a[l]);
|
|
865
|
+
}
|
|
866
|
+
if (e && t) {
|
|
849
867
|
let n = function() {
|
|
850
|
-
if (
|
|
851
|
-
let
|
|
852
|
-
if (
|
|
853
|
-
clearInterval(
|
|
868
|
+
if (r) {
|
|
869
|
+
let s = 0, o = setInterval(() => {
|
|
870
|
+
if (s++ > 5) {
|
|
871
|
+
clearInterval(o);
|
|
854
872
|
return;
|
|
855
873
|
}
|
|
856
|
-
|
|
874
|
+
r == null || r.call(a);
|
|
857
875
|
}, 300);
|
|
858
876
|
}
|
|
859
877
|
};
|
|
860
878
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
861
|
-
const
|
|
862
|
-
return
|
|
863
|
-
|
|
864
|
-
}),
|
|
865
|
-
|
|
866
|
-
}),
|
|
879
|
+
const i = C.get(e, { engine: "model-viewer" });
|
|
880
|
+
return C.addPlugin(new Ye()), i.enable(), i.addEventListener("changed", () => {
|
|
881
|
+
r == null || r.call(a);
|
|
882
|
+
}), a.addEventListener("model-visibility", (s) => {
|
|
883
|
+
s.detail.visible && (r == null || r.call(a));
|
|
884
|
+
}), a.addEventListener("load", () => {
|
|
867
885
|
n();
|
|
868
886
|
}), () => {
|
|
869
|
-
|
|
887
|
+
i.disable();
|
|
870
888
|
};
|
|
871
889
|
}
|
|
872
890
|
return null;
|
|
873
891
|
}
|
|
874
|
-
class
|
|
892
|
+
class Ye {
|
|
875
893
|
constructor() {
|
|
876
|
-
|
|
894
|
+
d(this, "_didWarnAboutMissingUrl", !1);
|
|
877
895
|
}
|
|
878
|
-
onBeforeUpdateLOD(e, t, r,
|
|
879
|
-
this.tryParseMeshLOD(t,
|
|
896
|
+
onBeforeUpdateLOD(e, t, r, n) {
|
|
897
|
+
this.tryParseMeshLOD(t, n), this.tryParseTextureLOD(t, n);
|
|
880
898
|
}
|
|
881
899
|
getUrl(e) {
|
|
882
900
|
if (!e)
|
|
@@ -891,19 +909,19 @@ class Ke {
|
|
|
891
909
|
return e.element;
|
|
892
910
|
}
|
|
893
911
|
tryParseTextureLOD(e, t) {
|
|
894
|
-
if (t[
|
|
912
|
+
if (t[se] == !0)
|
|
895
913
|
return;
|
|
896
|
-
t[
|
|
897
|
-
const r = this.tryGetCurrentGLTF(e),
|
|
898
|
-
if (
|
|
899
|
-
let s = function(
|
|
914
|
+
t[se] = !0;
|
|
915
|
+
const r = this.tryGetCurrentGLTF(e), n = this.tryGetCurrentModelViewer(e), i = this.getUrl(n);
|
|
916
|
+
if (i && r && t.material) {
|
|
917
|
+
let s = function(l) {
|
|
900
918
|
var c, x, u;
|
|
901
|
-
if (
|
|
919
|
+
if (l[se] == !0)
|
|
902
920
|
return;
|
|
903
|
-
|
|
904
|
-
const
|
|
905
|
-
for (let y = 0; y <
|
|
906
|
-
const w =
|
|
921
|
+
l[se] = !0, l.userData && (l.userData.LOD = -1);
|
|
922
|
+
const f = Object.keys(l);
|
|
923
|
+
for (let y = 0; y < f.length; y++) {
|
|
924
|
+
const w = f[y], L = l[w];
|
|
907
925
|
if ((L == null ? void 0 : L.isTexture) === !0) {
|
|
908
926
|
const B = (x = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : x.textures;
|
|
909
927
|
if (B == null)
|
|
@@ -915,15 +933,15 @@ class Ke {
|
|
|
915
933
|
}
|
|
916
934
|
if ((u = I == null ? void 0 : I.extensions) != null && u[F]) {
|
|
917
935
|
const p = I.extensions[F];
|
|
918
|
-
p &&
|
|
936
|
+
p && i && O.registerTexture(i, L, p.lods.length, B, p);
|
|
919
937
|
}
|
|
920
938
|
}
|
|
921
939
|
}
|
|
922
940
|
};
|
|
923
941
|
const o = t.material;
|
|
924
942
|
if (Array.isArray(o))
|
|
925
|
-
for (const
|
|
926
|
-
s(
|
|
943
|
+
for (const l of o)
|
|
944
|
+
s(l);
|
|
927
945
|
else
|
|
928
946
|
s(o);
|
|
929
947
|
}
|
|
@@ -933,34 +951,34 @@ class Ke {
|
|
|
933
951
|
if (t[Le] == !0)
|
|
934
952
|
return;
|
|
935
953
|
t[Le] = !0;
|
|
936
|
-
const r = this.tryGetCurrentModelViewer(e),
|
|
937
|
-
if (!
|
|
954
|
+
const r = this.tryGetCurrentModelViewer(e), n = this.getUrl(r);
|
|
955
|
+
if (!n)
|
|
938
956
|
return;
|
|
939
|
-
const
|
|
940
|
-
if (
|
|
941
|
-
const
|
|
942
|
-
O.registerMesh(
|
|
957
|
+
const i = (o = (s = t.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : o[F];
|
|
958
|
+
if (i && n) {
|
|
959
|
+
const l = t.uuid;
|
|
960
|
+
O.registerMesh(n, l, t, 0, i.lods.length, i);
|
|
943
961
|
}
|
|
944
962
|
}
|
|
945
963
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
|
|
964
|
+
function it(a, e, t, r) {
|
|
965
|
+
ve(e), _e(t), t.register((i) => new O(i, a));
|
|
966
|
+
const n = C.get(e);
|
|
967
|
+
return (r == null ? void 0 : r.enableLODsManager) !== !1 && n.enable(), n;
|
|
951
968
|
}
|
|
969
|
+
Oe();
|
|
952
970
|
export {
|
|
953
971
|
F as EXTENSION_NAME,
|
|
954
|
-
|
|
972
|
+
C as LODsManager,
|
|
955
973
|
O as NEEDLE_progressive,
|
|
956
|
-
|
|
974
|
+
we as VERSION,
|
|
957
975
|
_e as addDracoAndKTX2Loaders,
|
|
958
|
-
|
|
976
|
+
ve as createLoaders,
|
|
959
977
|
pe as getRaycastMesh,
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
978
|
+
Oe as patchModelViewer,
|
|
979
|
+
tt as setDracoDecoderLocation,
|
|
980
|
+
rt as setKTX2TranscoderLocation,
|
|
981
|
+
Ve as setRaycastMesh,
|
|
982
|
+
it as useNeedleProgressive,
|
|
983
|
+
st as useRaycastMeshes
|
|
966
984
|
};
|