@needle-tools/gltf-progressive 1.2.2-alpha.1 → 1.2.2-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -1
- package/examples/modelviewer-multiple.html +10 -0
- package/examples/modelviewer.html +4 -0
- package/gltf-progressive.js +336 -333
- package/gltf-progressive.min.js +6 -6
- package/gltf-progressive.umd.cjs +6 -6
- package/lib/lods_manager.js +4 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
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 Se = Object.defineProperty;
|
|
2
|
+
var be = (l, e, t) => e in l ? Se(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
|
|
3
|
+
var d = (l, e, t) => (be(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { BufferGeometry as se, Mesh as W, Material as Te, Texture as q, TextureLoader as Ae, Matrix4 as ye, Frustum as Pe, Sphere as Ce, Box3 as me, Vector3 as G } from "three";
|
|
5
|
+
import { GLTFLoader as Re } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
6
|
+
import { MeshoptDecoder as Be } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
7
|
+
import { DRACOLoader as Ee } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
8
|
+
import { KTX2Loader as ke } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
9
|
+
const De = "";
|
|
10
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = De;
|
|
11
|
+
console.debug(`[gltf-progressive] version ${De}`);
|
|
12
|
+
let ie = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", ge = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
13
|
+
fetch(ie + "draco_decoder.js", { method: "head" }).catch((l) => {
|
|
14
|
+
ie = "./include/draco/", ge = "./include/ktx2/";
|
|
15
15
|
});
|
|
16
|
-
function Qe(l) {
|
|
17
|
-
se = l;
|
|
18
|
-
}
|
|
19
16
|
function Ze(l) {
|
|
20
|
-
|
|
17
|
+
ie = l;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Y || (Y = new Be(), Y.setDecoderPath(se), Y.setDecoderConfig({ type: "js" })), H || (H = new Ee(), H.setTranscoderPath(he)), ue || (ue = Re), l ? H.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
|
|
19
|
+
function je(l) {
|
|
20
|
+
ge = l;
|
|
25
21
|
}
|
|
22
|
+
let H, fe, J;
|
|
26
23
|
function we(l) {
|
|
27
|
-
|
|
24
|
+
H || (H = new Ee(), H.setDecoderPath(ie), H.setDecoderConfig({ type: "js" })), J || (J = new ke(), J.setTranscoderPath(ge)), fe || (fe = Be), l ? J.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
|
|
25
|
+
}
|
|
26
|
+
function ve(l) {
|
|
27
|
+
l.dracoLoader || l.setDRACOLoader(H), l.ktx2Loader || l.setKTX2Loader(J), l.meshoptDecoder || l.setMeshoptDecoder(fe);
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
function
|
|
29
|
+
Z("debugprogressive");
|
|
30
|
+
function Z(l) {
|
|
31
31
|
const t = new URL(window.location.href).searchParams.get(l);
|
|
32
32
|
return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function Ie(l, e) {
|
|
35
35
|
if (e === void 0 || e.startsWith("./") || e.startsWith("http") || l === void 0)
|
|
36
36
|
return e;
|
|
37
37
|
const t = l.lastIndexOf("/");
|
|
@@ -43,55 +43,55 @@ function ke(l, e) {
|
|
|
43
43
|
}
|
|
44
44
|
return e;
|
|
45
45
|
}
|
|
46
|
-
let
|
|
47
|
-
function
|
|
48
|
-
return
|
|
46
|
+
let X;
|
|
47
|
+
function Ge() {
|
|
48
|
+
return X !== void 0 || (X = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), Z("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", X)), X;
|
|
49
49
|
}
|
|
50
|
-
const
|
|
51
|
-
function
|
|
52
|
-
return (l == null ? void 0 : l[
|
|
50
|
+
const de = Symbol("needle:raycast-mesh");
|
|
51
|
+
function pe(l) {
|
|
52
|
+
return (l == null ? void 0 : l[de]) instanceof se ? l[de] : null;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !
|
|
56
|
-
const r =
|
|
57
|
-
r.userData = { isRaycastMesh: !0 }, l[
|
|
54
|
+
function Fe(l, e) {
|
|
55
|
+
if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !pe(l)) {
|
|
56
|
+
const r = $e(e);
|
|
57
|
+
r.userData = { isRaycastMesh: !0 }, l[de] = r;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function et(l = !0) {
|
|
61
61
|
if (l) {
|
|
62
|
-
if (
|
|
62
|
+
if (Y)
|
|
63
63
|
return;
|
|
64
|
-
const e =
|
|
65
|
-
|
|
66
|
-
const n = this, i =
|
|
64
|
+
const e = Y = W.prototype.raycast;
|
|
65
|
+
W.prototype.raycast = function(t, r) {
|
|
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
|
-
if (!
|
|
71
|
+
if (!Y)
|
|
72
72
|
return;
|
|
73
|
-
|
|
73
|
+
W.prototype.raycast = Y, Y = null;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
let
|
|
77
|
-
function
|
|
78
|
-
const e = new
|
|
76
|
+
let Y = null;
|
|
77
|
+
function $e(l) {
|
|
78
|
+
const e = new se();
|
|
79
79
|
for (const t in l.attributes)
|
|
80
80
|
e.setAttribute(t, l.getAttribute(t));
|
|
81
81
|
return e.setIndex(l.getIndex()), e;
|
|
82
82
|
}
|
|
83
|
-
const
|
|
83
|
+
const z = new Array(), F = "NEEDLE_progressive", m = Z("debugprogressive"), ae = Symbol("needle-progressive-texture"), Q = /* @__PURE__ */ new Map(), he = /* @__PURE__ */ new Set();
|
|
84
84
|
if (m) {
|
|
85
85
|
let l = function() {
|
|
86
|
-
e += 1, console.log("Toggle LOD level", e,
|
|
86
|
+
e += 1, console.log("Toggle LOD level", e, Q), Q.forEach((n, i) => {
|
|
87
87
|
for (const s of n.keys) {
|
|
88
88
|
const o = i[s];
|
|
89
89
|
if (o != null) {
|
|
90
90
|
if (o.isBufferGeometry === !0) {
|
|
91
|
-
const a =
|
|
92
|
-
i["DEBUG:LOD"] = e,
|
|
91
|
+
const a = _.getMeshLODInformation(o), f = a ? Math.min(e, a.lods.length) : 0;
|
|
92
|
+
i["DEBUG:LOD"] = e, _.assignMeshLOD(i, f), a && (t = Math.max(t, a.lods.length - 1));
|
|
93
93
|
} else if (i.isMaterial === !0) {
|
|
94
|
-
i["DEBUG:LOD"] = e,
|
|
94
|
+
i["DEBUG:LOD"] = e, _.assignTextureLOD(i, e);
|
|
95
95
|
break;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -99,39 +99,39 @@ if (m) {
|
|
|
99
99
|
}), e >= t && (e = -1);
|
|
100
100
|
}, e = -1, t = 2, r = !1;
|
|
101
101
|
window.addEventListener("keyup", (n) => {
|
|
102
|
-
n.key === "p" && l(), n.key === "w" && (r = !r,
|
|
102
|
+
n.key === "p" && l(), n.key === "w" && (r = !r, he && he.forEach((i) => {
|
|
103
103
|
i.name != "BackgroundCubeMaterial" && i.glyphMap == null && "wireframe" in i && (i.wireframe = r);
|
|
104
104
|
}));
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function xe(l, e, t) {
|
|
108
108
|
var n;
|
|
109
109
|
if (!m)
|
|
110
110
|
return;
|
|
111
|
-
|
|
112
|
-
const r =
|
|
111
|
+
Q.has(l) || Q.set(l, { keys: [], sourceId: t });
|
|
112
|
+
const r = Q.get(l);
|
|
113
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 O = class {
|
|
116
116
|
constructor(e, t) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
d(this, "parser");
|
|
118
|
+
d(this, "url");
|
|
119
|
+
d(this, "_isLoadingMesh");
|
|
120
|
+
d(this, "loadMesh", (e) => {
|
|
121
121
|
var r, n;
|
|
122
122
|
if (this._isLoadingMesh)
|
|
123
123
|
return null;
|
|
124
|
-
const t = (n = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : n[
|
|
124
|
+
const t = (n = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : n[F];
|
|
125
125
|
return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((i) => {
|
|
126
126
|
var s;
|
|
127
|
-
return this._isLoadingMesh = !1, i &&
|
|
127
|
+
return this._isLoadingMesh = !1, i && O.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;
|
|
131
131
|
}
|
|
132
132
|
/** The name of the extension */
|
|
133
133
|
get name() {
|
|
134
|
-
return
|
|
134
|
+
return F;
|
|
135
135
|
}
|
|
136
136
|
static getMeshLODInformation(e) {
|
|
137
137
|
const t = this.getAssignedLODInformation(e);
|
|
@@ -153,8 +153,8 @@ const D = class {
|
|
|
153
153
|
if (m === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
|
|
154
154
|
const o = e;
|
|
155
155
|
for (const a of Object.keys(o.uniforms)) {
|
|
156
|
-
const
|
|
157
|
-
(
|
|
156
|
+
const f = o.uniforms[a].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)) {
|
|
@@ -163,14 +163,14 @@ const D = class {
|
|
|
163
163
|
}
|
|
164
164
|
return e[n] = t, t;
|
|
165
165
|
function s(o, a) {
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
const c = r.lodInfos.get(
|
|
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
|
a.min_count = Math.min(a.min_count, c.lods.length), a.max_count = Math.max(a.max_count, c.lods.length);
|
|
171
171
|
for (let x = 0; x < c.lods.length; x++) {
|
|
172
|
-
const
|
|
173
|
-
|
|
172
|
+
const u = c.lods[x];
|
|
173
|
+
u.width && (a.lods[x] = a.lods[x] || { min_height: 1 / 0, max_height: 0 }, a.lods[x].min_height = Math.min(a.lods[x].min_height, u.height), a.lods[x].max_height = Math.max(a.lods[x].max_height, u.height));
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -229,19 +229,19 @@ const D = class {
|
|
|
229
229
|
var r;
|
|
230
230
|
if (!e)
|
|
231
231
|
return Promise.resolve(null);
|
|
232
|
-
if (e instanceof
|
|
232
|
+
if (e instanceof W || e.isMesh === !0) {
|
|
233
233
|
const n = e.geometry, i = this.getAssignedLODInformation(n);
|
|
234
234
|
if (!i)
|
|
235
235
|
return Promise.resolve(null);
|
|
236
|
-
for (const s of
|
|
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, O.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
241
|
const o = i.index || 0;
|
|
242
242
|
s = s[o];
|
|
243
243
|
}
|
|
244
|
-
s && n != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, m &&
|
|
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,15 +259,15 @@ const D = class {
|
|
|
259
259
|
static assignTextureLOD(e, t = 0) {
|
|
260
260
|
if (!e)
|
|
261
261
|
return Promise.resolve(null);
|
|
262
|
-
if (e instanceof
|
|
262
|
+
if (e instanceof Te || e.isMaterial === !0) {
|
|
263
263
|
const r = e, n = [], i = new Array();
|
|
264
|
-
if (m &&
|
|
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
267
|
const a = s.uniforms[o].value;
|
|
268
268
|
if ((a == null ? void 0 : a.isTexture) === !0) {
|
|
269
|
-
const
|
|
270
|
-
n.push(
|
|
269
|
+
const f = this.assignTextureLODForSlot(a, t, r, o);
|
|
270
|
+
n.push(f), i.push(o);
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
} else
|
|
@@ -281,20 +281,20 @@ const D = class {
|
|
|
281
281
|
return Promise.all(n).then((s) => {
|
|
282
282
|
const o = new Array();
|
|
283
283
|
for (let a = 0; a < s.length; a++) {
|
|
284
|
-
const
|
|
285
|
-
|
|
284
|
+
const f = s[a], c = i[a];
|
|
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
|
});
|
|
289
289
|
}
|
|
290
|
-
if (e instanceof
|
|
290
|
+
if (e instanceof q || e.isTexture === !0) {
|
|
291
291
|
const r = e;
|
|
292
292
|
return this.assignTextureLODForSlot(r, t, null, null);
|
|
293
293
|
}
|
|
294
294
|
return Promise.resolve(null);
|
|
295
295
|
}
|
|
296
296
|
static assignTextureLODForSlot(e, t, r, n) {
|
|
297
|
-
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(e) :
|
|
297
|
+
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(e) : O.getOrLoadLOD(e, t).then((i) => {
|
|
298
298
|
if (Array.isArray(i))
|
|
299
299
|
return null;
|
|
300
300
|
if ((i == null ? void 0 : i.isTexture) === !0) {
|
|
@@ -310,7 +310,7 @@ const D = class {
|
|
|
310
310
|
}
|
|
311
311
|
if (m && n && r) {
|
|
312
312
|
const s = this.getAssignedLODInformation(e);
|
|
313
|
-
s &&
|
|
313
|
+
s && xe(r, n, s.url);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
return i;
|
|
@@ -324,36 +324,36 @@ const D = class {
|
|
|
324
324
|
return m && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((n, i) => {
|
|
325
325
|
var s;
|
|
326
326
|
if (n != null && n.extensions) {
|
|
327
|
-
const o = n == null ? void 0 : 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
333
|
let a = !1;
|
|
334
|
-
for (const
|
|
335
|
-
|
|
336
|
-
a || this.parser.getDependency("texture", i).then((
|
|
334
|
+
for (const f of this.parser.associations.keys())
|
|
335
|
+
f.isTexture === !0 && this.parser.associations.get(f).textures === i && (a = !0, O.registerTexture(this.url, f, (s = o.lods) == null ? void 0 : s.length, i, o));
|
|
336
|
+
a || this.parser.getDependency("texture", i).then((f) => {
|
|
337
337
|
var c;
|
|
338
|
-
|
|
338
|
+
f && O.registerTexture(this.url, f, (c = o.lods) == null ? void 0 : c.length, i, o);
|
|
339
339
|
});
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
}), (r = this.parser.json.meshes) == null || r.forEach((n, i) => {
|
|
343
343
|
if (n != null && n.extensions) {
|
|
344
|
-
const s = n == null ? void 0 : 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
348
|
const a = this.parser.associations.get(o);
|
|
349
|
-
a.meshes === i &&
|
|
349
|
+
a.meshes === i && O.registerMesh(this.url, s.guid, o, s.lods.length, a.primitives, s);
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
}), null;
|
|
354
354
|
}
|
|
355
355
|
static async getOrLoadLOD(e, t) {
|
|
356
|
-
var o, a,
|
|
356
|
+
var o, a, f, c;
|
|
357
357
|
const r = m == "verbose", n = e.userData.LODS;
|
|
358
358
|
if (!n)
|
|
359
359
|
return null;
|
|
@@ -361,101 +361,101 @@ const D = class {
|
|
|
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[ae] && (s = x.source[ae]);
|
|
365
365
|
}
|
|
366
|
-
if (s || (s =
|
|
366
|
+
if (s || (s = O.lodInfos.get(i)), s) {
|
|
367
367
|
if (t > 0) {
|
|
368
368
|
let y = !1;
|
|
369
|
-
const
|
|
370
|
-
if (
|
|
369
|
+
const w = Array.isArray(s.lods);
|
|
370
|
+
if (w && t >= s.lods.length ? y = !0 : w || (y = !0), y)
|
|
371
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
|
|
377
|
-
if (
|
|
376
|
+
const u = Ie(n.url, x);
|
|
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
|
-
const y =
|
|
381
|
-
if (
|
|
380
|
+
const y = u + "_" + s.guid, w = this.previouslyLoaded.get(y);
|
|
381
|
+
if (w !== void 0) {
|
|
382
382
|
r && console.log(`LOD ${t} was already loading/loaded: ${y}`);
|
|
383
|
-
let
|
|
384
|
-
`,
|
|
385
|
-
if (
|
|
386
|
-
return
|
|
383
|
+
let p = await w.catch((U) => (console.error(`Error loading LOD ${t} from ${u}
|
|
384
|
+
`, U), null)), M = !1;
|
|
385
|
+
if (p == null || (p instanceof q && e instanceof q ? (a = p.image) != null && a.data || (f = p.source) != null && f.data ? p = this.copySettings(e, p) : (M = !0, this.previouslyLoaded.delete(y)) : p instanceof se && e instanceof se && ((c = p.attributes.position) != null && c.array || (M = !0, this.previouslyLoaded.delete(y)))), !M)
|
|
386
|
+
return p;
|
|
387
387
|
}
|
|
388
|
-
const L = s,
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
let
|
|
388
|
+
const L = s, B = new Promise(async (p, M) => {
|
|
389
|
+
const U = new Re();
|
|
390
|
+
ve(U), m && (await new Promise((S) => setTimeout(S, 1e3)), r && console.warn("Start loading (delayed) " + u, L.guid));
|
|
391
|
+
let E = u;
|
|
392
392
|
if (L && Array.isArray(L.lods)) {
|
|
393
|
-
const
|
|
394
|
-
|
|
393
|
+
const S = L.lods[t];
|
|
394
|
+
S.hash && (E += "?v=" + S.hash);
|
|
395
395
|
}
|
|
396
|
-
const
|
|
397
|
-
`,
|
|
398
|
-
if (!
|
|
396
|
+
const v = await U.loadAsync(E).catch((S) => (console.error(`Error loading LOD ${t} from ${u}
|
|
397
|
+
`, S), null));
|
|
398
|
+
if (!v)
|
|
399
399
|
return null;
|
|
400
|
-
const
|
|
401
|
-
r && console.log("Loading finished " +
|
|
402
|
-
let
|
|
403
|
-
if (
|
|
404
|
-
let
|
|
405
|
-
for (const
|
|
406
|
-
if (
|
|
407
|
-
const
|
|
408
|
-
if (
|
|
409
|
-
|
|
400
|
+
const $ = v.parser;
|
|
401
|
+
r && console.log("Loading finished " + u, L.guid);
|
|
402
|
+
let k = 0;
|
|
403
|
+
if (v.parser.json.textures) {
|
|
404
|
+
let S = !1;
|
|
405
|
+
for (const g of v.parser.json.textures) {
|
|
406
|
+
if (g != null && g.extensions) {
|
|
407
|
+
const h = g == null ? void 0 : g.extensions[F];
|
|
408
|
+
if (h != null && h.guid && h.guid === L.guid) {
|
|
409
|
+
S = !0;
|
|
410
410
|
break;
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
|
-
|
|
413
|
+
k++;
|
|
414
414
|
}
|
|
415
|
-
if (
|
|
416
|
-
let
|
|
417
|
-
return
|
|
415
|
+
if (S) {
|
|
416
|
+
let g = await $.getDependency("texture", k);
|
|
417
|
+
return g && O.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 (
|
|
422
|
-
let
|
|
423
|
-
for (const
|
|
424
|
-
if (
|
|
425
|
-
const
|
|
426
|
-
if (
|
|
427
|
-
|
|
421
|
+
if (k = 0, v.parser.json.meshes) {
|
|
422
|
+
let S = !1;
|
|
423
|
+
for (const g of v.parser.json.meshes) {
|
|
424
|
+
if (g != null && g.extensions) {
|
|
425
|
+
const h = g == null ? void 0 : g.extensions[F];
|
|
426
|
+
if (h != null && h.guid && h.guid === L.guid) {
|
|
427
|
+
S = !0;
|
|
428
428
|
break;
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
-
|
|
431
|
+
k++;
|
|
432
432
|
}
|
|
433
|
-
if (
|
|
434
|
-
const
|
|
435
|
-
if (r && console.log(`Loaded Mesh "${
|
|
436
|
-
const
|
|
437
|
-
return
|
|
433
|
+
if (S) {
|
|
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
|
+
const D = g.geometry;
|
|
437
|
+
return O.assignLODInformation(n.url, D, i, t, void 0, h.density), p(D);
|
|
438
438
|
} else {
|
|
439
|
-
const
|
|
440
|
-
for (let
|
|
441
|
-
const
|
|
442
|
-
if (
|
|
443
|
-
const
|
|
444
|
-
|
|
439
|
+
const D = new Array();
|
|
440
|
+
for (let b = 0; b < g.children.length; b++) {
|
|
441
|
+
const T = g.children[b];
|
|
442
|
+
if (T.isMesh === !0) {
|
|
443
|
+
const A = T.geometry;
|
|
444
|
+
O.assignLODInformation(n.url, A, i, t, b, h.density), D.push(A);
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
|
-
return
|
|
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
|
-
return
|
|
452
|
+
return p(null);
|
|
453
453
|
});
|
|
454
|
-
return this.previouslyLoaded.set(y,
|
|
455
|
-
} else if (e instanceof
|
|
456
|
-
r && console.log("Load texture from uri: " +
|
|
457
|
-
const
|
|
458
|
-
return
|
|
454
|
+
return this.previouslyLoaded.set(y, B), await B;
|
|
455
|
+
} else if (e instanceof q) {
|
|
456
|
+
r && console.log("Load texture from uri: " + u);
|
|
457
|
+
const w = await new Ae().loadAsync(u);
|
|
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
461
|
m && console.warn(`Can not load LOD ${t}: no LOD info found for "${i}" ${e.name}`, e.type);
|
|
@@ -465,7 +465,7 @@ const D = class {
|
|
|
465
465
|
if (!t)
|
|
466
466
|
return;
|
|
467
467
|
t.userData || (t.userData = {});
|
|
468
|
-
const o = new
|
|
468
|
+
const o = new ze(e, r, n, i, s);
|
|
469
469
|
t.userData.LODS = o;
|
|
470
470
|
}
|
|
471
471
|
static getAssignedLODInformation(e) {
|
|
@@ -479,93 +479,93 @@ const D = 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
|
|
482
|
+
let _ = O;
|
|
483
483
|
/**
|
|
484
484
|
* Register a texture with LOD information
|
|
485
485
|
*/
|
|
486
|
-
|
|
486
|
+
d(_, "registerTexture", (e, t, r, n, i) => {
|
|
487
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[
|
|
491
|
+
t.source && (t.source[ae] = i);
|
|
492
492
|
const s = i.guid;
|
|
493
|
-
|
|
493
|
+
O.assignLODInformation(e, t, s, r, n, void 0), O.lodInfos.set(s, i), O.lowresCache.set(s, t);
|
|
494
494
|
}), /**
|
|
495
495
|
* Register a mesh with LOD information
|
|
496
496
|
*/
|
|
497
|
-
|
|
498
|
-
var
|
|
497
|
+
d(_, "registerMesh", (e, t, r, n, i, s) => {
|
|
498
|
+
var f;
|
|
499
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 a =
|
|
507
|
-
a ? a.push(r.geometry) : a = [r.geometry],
|
|
508
|
-
for (const c of
|
|
509
|
-
(
|
|
505
|
+
o.userData || (o.userData = {}), O.assignLODInformation(e, o, t, n, i, s.density), O.lodInfos.set(t, s);
|
|
506
|
+
let a = O.lowresCache.get(t);
|
|
507
|
+
a ? a.push(r.geometry) : a = [r.geometry], O.lowresCache.set(t, a), n > 0 && !pe(r) && Fe(r, o);
|
|
508
|
+
for (const c of z)
|
|
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
|
|
511
|
+
d(_, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
512
|
+
d(_, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
513
|
+
d(_, "lowresCache", /* @__PURE__ */ new Map());
|
|
514
|
+
class ze {
|
|
515
515
|
constructor(e, t, r, n, i) {
|
|
516
|
-
|
|
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
|
-
|
|
523
|
+
d(this, "density");
|
|
524
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
|
|
527
|
+
const N = Z("debugprogressive"), Ue = Z("noprogressive"), le = Symbol("Needle:LODSManager"), ce = Symbol("Needle:LODState"), V = Symbol("Needle:CurrentLOD"), C = { 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 Pe());
|
|
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
|
-
|
|
546
|
+
d(this, "pause", !1);
|
|
547
|
+
d(this, "_frame", 0);
|
|
548
|
+
d(this, "_originalRender");
|
|
549
549
|
// private testIfLODLevelsAreAvailable() {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
550
|
+
d(this, "_sphere", new Ce());
|
|
551
|
+
d(this, "_tempBox", new me());
|
|
552
|
+
d(this, "_tempBox2", new me());
|
|
553
|
+
d(this, "tempMatrix", new ye());
|
|
554
|
+
d(this, "_tempWorldPosition", new G());
|
|
555
|
+
d(this, "_tempBoxSize", new G());
|
|
556
|
+
d(this, "_tempBox2Size", new G());
|
|
557
557
|
this.renderer = e, this.context = { ...t };
|
|
558
558
|
}
|
|
559
559
|
/** @internal */
|
|
560
560
|
static getObjectLODState(e) {
|
|
561
|
-
return e[
|
|
561
|
+
return e[ce];
|
|
562
562
|
}
|
|
563
563
|
static addPlugin(e) {
|
|
564
|
-
|
|
564
|
+
z.push(e);
|
|
565
565
|
}
|
|
566
566
|
static removePlugin(e) {
|
|
567
|
-
const t =
|
|
568
|
-
t >= 0 &&
|
|
567
|
+
const t = z.indexOf(e);
|
|
568
|
+
t >= 0 && z.splice(t, 1);
|
|
569
569
|
}
|
|
570
570
|
/**
|
|
571
571
|
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
@@ -573,17 +573,17 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
573
573
|
* @returns The LODsManager instance.
|
|
574
574
|
*/
|
|
575
575
|
static get(e, t) {
|
|
576
|
-
if (e[
|
|
577
|
-
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[
|
|
576
|
+
if (e[le])
|
|
577
|
+
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[le];
|
|
578
578
|
const r = new P(e, {
|
|
579
579
|
engine: "unknown",
|
|
580
580
|
...t
|
|
581
581
|
});
|
|
582
|
-
return e[
|
|
582
|
+
return e[le] = r, r;
|
|
583
583
|
}
|
|
584
584
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
585
585
|
get plugins() {
|
|
586
|
-
return
|
|
586
|
+
return z;
|
|
587
587
|
}
|
|
588
588
|
/**
|
|
589
589
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
@@ -595,7 +595,7 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
595
595
|
let e = 0;
|
|
596
596
|
this._originalRender = this.renderer.render;
|
|
597
597
|
const t = this;
|
|
598
|
-
|
|
598
|
+
we(this.renderer), this.renderer.render = function(r, n) {
|
|
599
599
|
t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
|
|
600
600
|
const s = t._frame, o = e++;
|
|
601
601
|
t.onBeforeRender(r, n, o, s), t._originalRender.call(this, r, n), t.onAfterRender(r, n, o, s);
|
|
@@ -607,7 +607,7 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
607
607
|
onBeforeRender(e, t, r, n) {
|
|
608
608
|
}
|
|
609
609
|
onAfterRender(e, t, r, n) {
|
|
610
|
-
var a,
|
|
610
|
+
var a, f;
|
|
611
611
|
if (this.pause)
|
|
612
612
|
return;
|
|
613
613
|
const i = this.renderer.renderLists.get(e, 0), s = i.opaque;
|
|
@@ -617,16 +617,16 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
617
617
|
(c.name === "EffectMaterial" || c.name === "CopyShader") && (o = !1);
|
|
618
618
|
}
|
|
619
619
|
if ((t.parent && t.parent.type === "CubeCamera" || r >= 1 && t.type === "OrthographicCamera") && (o = !1), o) {
|
|
620
|
-
if (
|
|
620
|
+
if (Ue || this.updateInterval > 0 && n % this.updateInterval != 0)
|
|
621
621
|
return;
|
|
622
622
|
this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
|
|
623
623
|
const c = this.targetTriangleDensity;
|
|
624
|
-
for (const
|
|
625
|
-
if (
|
|
626
|
-
|
|
624
|
+
for (const u of s) {
|
|
625
|
+
if (u.material && (((a = u.geometry) == null ? void 0 : a.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")) {
|
|
626
|
+
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)));
|
|
627
627
|
continue;
|
|
628
628
|
}
|
|
629
|
-
switch (
|
|
629
|
+
switch (u.material.type) {
|
|
630
630
|
case "LineBasicMaterial":
|
|
631
631
|
case "LineDashedMaterial":
|
|
632
632
|
case "PointsMaterial":
|
|
@@ -635,34 +635,34 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
635
635
|
case "MeshDepthMaterial":
|
|
636
636
|
continue;
|
|
637
637
|
}
|
|
638
|
-
const y =
|
|
639
|
-
(y instanceof
|
|
638
|
+
const y = u.object;
|
|
639
|
+
(y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, n);
|
|
640
640
|
}
|
|
641
641
|
const x = i.transparent;
|
|
642
|
-
for (const
|
|
643
|
-
const y =
|
|
644
|
-
(y instanceof
|
|
642
|
+
for (const u of x) {
|
|
643
|
+
const y = u.object;
|
|
644
|
+
(y instanceof W || y.isMesh) && this.updateLODs(e, t, y, c, n);
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
648
|
/** Update the LOD levels for the renderer. */
|
|
649
649
|
updateLODs(e, t, r, n, i) {
|
|
650
|
-
var a,
|
|
650
|
+
var a, f;
|
|
651
651
|
r.userData || (r.userData = {});
|
|
652
|
-
let s = r[
|
|
653
|
-
if (s || (s = new
|
|
652
|
+
let s = r[ce];
|
|
653
|
+
if (s || (s = new Ne(), r[ce] = s), s.frames++ < 2)
|
|
654
654
|
return;
|
|
655
|
-
for (const c of
|
|
655
|
+
for (const c of z)
|
|
656
656
|
(a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, e, t, r);
|
|
657
|
-
this.calculateLodLevel(t, r, s, n,
|
|
658
|
-
let o =
|
|
657
|
+
this.calculateLodLevel(t, r, s, n, C), C.mesh_lod = Math.round(C.mesh_lod), C.texture_lod = Math.round(C.texture_lod), C.mesh_lod >= 0 && this.loadProgressiveMeshes(r, C.mesh_lod);
|
|
658
|
+
let o = C.texture_lod;
|
|
659
659
|
if (r.material && o >= 0) {
|
|
660
660
|
const c = r["DEBUG:LOD"];
|
|
661
661
|
c != null && (o = c), this.loadProgressiveTextures(r.material, o);
|
|
662
662
|
}
|
|
663
|
-
for (const c of
|
|
664
|
-
(
|
|
665
|
-
s.lastLodLevel_Mesh =
|
|
663
|
+
for (const c of z)
|
|
664
|
+
(f = c.onAfterUpdatedLOD) == null || f.call(c, this.renderer, e, t, r, C);
|
|
665
|
+
s.lastLodLevel_Mesh = C.mesh_lod, s.lastLodLevel_Texture = C.texture_lod;
|
|
666
666
|
}
|
|
667
667
|
/** Load progressive textures for the given material
|
|
668
668
|
* @param material the material to load the textures for
|
|
@@ -678,7 +678,7 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
678
678
|
return;
|
|
679
679
|
}
|
|
680
680
|
let r = !1;
|
|
681
|
-
(e[
|
|
681
|
+
(e[V] === void 0 || t < e[V]) && (r = !0), r && (e[V] = t, _.assignTextureLOD(e, t));
|
|
682
682
|
}
|
|
683
683
|
/** Load progressive meshes for the given mesh
|
|
684
684
|
* @param mesh the mesh to load the LOD for
|
|
@@ -689,10 +689,10 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
689
689
|
loadProgressiveMeshes(e, t) {
|
|
690
690
|
if (!e)
|
|
691
691
|
return Promise.resolve(null);
|
|
692
|
-
if (e[
|
|
693
|
-
e[
|
|
692
|
+
if (e[V] !== t) {
|
|
693
|
+
e[V] = t;
|
|
694
694
|
const r = e.geometry;
|
|
695
|
-
return
|
|
695
|
+
return _.assignMeshLOD(e, t).then((n) => (n && e[V] == t && r != e.geometry, n));
|
|
696
696
|
}
|
|
697
697
|
return Promise.resolve(null);
|
|
698
698
|
}
|
|
@@ -701,7 +701,7 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
701
701
|
return this._tempPtInside.set(i, s, r.z).applyMatrix4(t).z < 0;
|
|
702
702
|
}
|
|
703
703
|
calculateLodLevel(e, t, r, n, i) {
|
|
704
|
-
var
|
|
704
|
+
var B, I;
|
|
705
705
|
if (!t) {
|
|
706
706
|
i.mesh_lod = -1, i.texture_lod = -1;
|
|
707
707
|
return;
|
|
@@ -711,29 +711,29 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
711
711
|
return;
|
|
712
712
|
}
|
|
713
713
|
let o = 10 + 1, a = !1;
|
|
714
|
-
if (
|
|
714
|
+
if (N && t["DEBUG:LOD"] != null)
|
|
715
715
|
return t["DEBUG:LOD"];
|
|
716
|
-
const
|
|
716
|
+
const f = _.getMeshLODInformation(t.geometry), c = f == null ? void 0 : f.lods, x = c && c.length > 0, u = _.getMaterialMinMaxLODsCount(t.material), y = (u == null ? void 0 : u.min_count) != 1 / 0 && u.min_count > 0 && u.max_count > 0;
|
|
717
717
|
if (!x && !y) {
|
|
718
718
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
719
719
|
return;
|
|
720
720
|
}
|
|
721
|
-
if (x || (a = !0, o = 0), !((
|
|
721
|
+
if (x || (a = !0, o = 0), !((B = this.cameraFrustrum) != null && B.intersectsObject(t))) {
|
|
722
722
|
i.mesh_lod = 99, i.texture_lod = 99;
|
|
723
723
|
return;
|
|
724
724
|
}
|
|
725
|
-
const
|
|
725
|
+
const w = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
726
726
|
let L = t.geometry.boundingBox;
|
|
727
727
|
if (t.type === "SkinnedMesh") {
|
|
728
|
-
const
|
|
729
|
-
|
|
728
|
+
const p = t;
|
|
729
|
+
p.boundingBox || p.computeBoundingBox(), L = p.boundingBox;
|
|
730
730
|
}
|
|
731
731
|
if (L && e.isPerspectiveCamera) {
|
|
732
|
-
const
|
|
732
|
+
const p = e;
|
|
733
733
|
if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
|
|
734
734
|
this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
|
|
735
|
-
const
|
|
736
|
-
if (this._sphere.containsPoint(
|
|
735
|
+
const h = e.getWorldPosition(this._tempWorldPosition);
|
|
736
|
+
if (this._sphere.containsPoint(h)) {
|
|
737
737
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
738
738
|
return;
|
|
739
739
|
}
|
|
@@ -742,57 +742,60 @@ const U = Q("debugprogressive"), ze = Q("noprogressive"), ae = Symbol("Needle:LO
|
|
|
742
742
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
743
743
|
return;
|
|
744
744
|
}
|
|
745
|
-
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled &&
|
|
746
|
-
const
|
|
747
|
-
let
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
const
|
|
751
|
-
r.lastCentrality = (
|
|
745
|
+
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && p.fov > 70) {
|
|
746
|
+
const h = this._tempBox.min, D = this._tempBox.max;
|
|
747
|
+
let b = h.x, T = h.y, A = D.x, K = D.y;
|
|
748
|
+
const j = 2, ne = 1.5, ee = (h.x + D.x) * 0.5, te = (h.y + D.y) * 0.5;
|
|
749
|
+
b = (b - ee) * j + ee, T = (T - te) * j + te, A = (A - ee) * j + ee, K = (K - te) * j + te;
|
|
750
|
+
const Oe = b < 0 && A > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(D.x)), _e = T < 0 && K > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(D.y)), oe = Math.max(Oe, _e);
|
|
751
|
+
r.lastCentrality = (ne - oe) * (ne - oe) * (ne - oe);
|
|
752
752
|
} else
|
|
753
753
|
r.lastCentrality = 1;
|
|
754
|
-
const
|
|
755
|
-
|
|
756
|
-
const
|
|
757
|
-
|
|
758
|
-
const
|
|
759
|
-
if (Math.max(
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
const
|
|
765
|
-
|
|
754
|
+
const M = this._tempBox.getSize(this._tempBoxSize);
|
|
755
|
+
M.multiplyScalar(0.5), screen.availHeight > 0 && w > 0 && M.multiplyScalar(w / screen.availHeight), M.x *= p.aspect;
|
|
756
|
+
const U = e.matrixWorldInverse, E = this._tempBox2;
|
|
757
|
+
E.copy(L), E.applyMatrix4(t.matrixWorld), E.applyMatrix4(U);
|
|
758
|
+
const v = E.getSize(this._tempBox2Size), $ = Math.max(v.x, v.y);
|
|
759
|
+
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) {
|
|
760
|
+
const h = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
761
|
+
h.invert();
|
|
762
|
+
const D = P.corner0, b = P.corner1, T = P.corner2, A = P.corner3;
|
|
763
|
+
D.copy(this._tempBox.min), b.copy(this._tempBox.max), b.x = D.x, T.copy(this._tempBox.max), T.y = D.y, A.copy(this._tempBox.max);
|
|
764
|
+
const K = (D.z + A.z) * 0.5;
|
|
765
|
+
D.z = b.z = T.z = A.z = K, D.applyMatrix4(h), b.applyMatrix4(h), T.applyMatrix4(h), A.applyMatrix4(h), P.debugDrawLine(D, b, 255), P.debugDrawLine(D, T, 255), P.debugDrawLine(b, A, 255), P.debugDrawLine(T, A, 255);
|
|
766
766
|
}
|
|
767
|
-
let
|
|
767
|
+
let S = 999;
|
|
768
768
|
if (c && r.lastScreenCoverage > 0) {
|
|
769
|
-
for (let
|
|
770
|
-
if (c[
|
|
771
|
-
|
|
769
|
+
for (let h = 0; h < c.length; h++)
|
|
770
|
+
if (c[h].density / r.lastScreenCoverage < n) {
|
|
771
|
+
S = h;
|
|
772
772
|
break;
|
|
773
773
|
}
|
|
774
774
|
}
|
|
775
|
-
|
|
775
|
+
S < o && (o = S, a = !0);
|
|
776
776
|
}
|
|
777
|
-
if (a ? i.mesh_lod = o : i.mesh_lod = r.lastLodLevel_Mesh,
|
|
778
|
-
const
|
|
779
|
-
|
|
777
|
+
if (a ? i.mesh_lod = o : i.mesh_lod = r.lastLodLevel_Mesh, N && i.mesh_lod != r.lastLodLevel_Mesh) {
|
|
778
|
+
const M = c == null ? void 0 : c[i.mesh_lod];
|
|
779
|
+
M && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${i.mesh_lod} (${M.density.toFixed(0)}) - ${t.name}`);
|
|
780
780
|
}
|
|
781
781
|
if (y)
|
|
782
782
|
if (r.lastLodLevel_Texture < 0) {
|
|
783
|
-
if (i.texture_lod =
|
|
784
|
-
const
|
|
785
|
-
|
|
783
|
+
if (i.texture_lod = u.max_count - 1, N) {
|
|
784
|
+
const p = u.lods[u.max_count - 1];
|
|
785
|
+
N && console.log(`First Texture LOD ${i.texture_lod} (${p.max_height}px) - ${t.name}`);
|
|
786
786
|
}
|
|
787
787
|
} else {
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
788
|
+
const p = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
|
|
789
|
+
let M = r.lastScreenCoverage * 2;
|
|
790
|
+
((I = this.context) == null ? void 0 : I.engine) === "model-viewer" && (M *= 2);
|
|
791
|
+
const E = w / window.devicePixelRatio * M;
|
|
792
|
+
for (let v = u.lods.length - 1; v >= 0; v--) {
|
|
793
|
+
let $ = u.lods[v];
|
|
794
|
+
if (!(Ge() && $.max_height > 4096) && $.max_height > E) {
|
|
795
|
+
if (i.texture_lod = v, i.texture_lod < r.lastLodLevel_Texture) {
|
|
796
|
+
const k = $.max_height;
|
|
797
|
+
N && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${i.texture_lod} = ${k}px
|
|
798
|
+
Screensize: ${E.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${p.toFixed(1)}
|
|
796
799
|
${t.name}`);
|
|
797
800
|
}
|
|
798
801
|
break;
|
|
@@ -803,43 +806,43 @@ ${t.name}`);
|
|
|
803
806
|
i.texture_lod = 0;
|
|
804
807
|
}
|
|
805
808
|
};
|
|
806
|
-
let
|
|
809
|
+
let R = P;
|
|
807
810
|
/** 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.
|
|
808
811
|
*/
|
|
809
|
-
|
|
810
|
-
class
|
|
812
|
+
d(R, "debugDrawLine"), d(R, "corner0", new G()), d(R, "corner1", new G()), d(R, "corner2", new G()), d(R, "corner3", new G()), d(R, "_tempPtInside", new G());
|
|
813
|
+
class Ne {
|
|
811
814
|
constructor() {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
815
|
+
d(this, "frames", 0);
|
|
816
|
+
d(this, "lastLodLevel_Mesh", -1);
|
|
817
|
+
d(this, "lastLodLevel_Texture", -1);
|
|
818
|
+
d(this, "lastScreenCoverage", 0);
|
|
819
|
+
d(this, "lastScreenspaceVolume", new G());
|
|
820
|
+
d(this, "lastCentrality", 0);
|
|
818
821
|
}
|
|
819
822
|
}
|
|
820
|
-
const
|
|
821
|
-
function
|
|
822
|
-
document.removeEventListener("DOMContentLoaded",
|
|
823
|
+
const Le = Symbol("NEEDLE_mesh_lod"), re = Symbol("NEEDLE_texture_lod");
|
|
824
|
+
function Ve() {
|
|
825
|
+
document.removeEventListener("DOMContentLoaded", ue), document.addEventListener("DOMContentLoaded", ue), ue();
|
|
823
826
|
}
|
|
824
|
-
function
|
|
827
|
+
function ue() {
|
|
825
828
|
document.querySelectorAll("model-viewer").forEach((e, t) => {
|
|
826
|
-
|
|
829
|
+
We(e, t);
|
|
827
830
|
});
|
|
828
831
|
}
|
|
829
|
-
const
|
|
830
|
-
function
|
|
831
|
-
if (!l ||
|
|
832
|
+
const Me = /* @__PURE__ */ new WeakSet();
|
|
833
|
+
function We(l, e) {
|
|
834
|
+
if (!l || Me.has(l))
|
|
832
835
|
return null;
|
|
833
|
-
|
|
836
|
+
Me.add(l), console.debug("[gltf-progressive] found model-viewer..." + e);
|
|
834
837
|
let t = null, r = null, n = null;
|
|
835
838
|
for (let i = l; i != null; i = Object.getPrototypeOf(i)) {
|
|
836
|
-
const s = Object.getOwnPropertySymbols(i), o = s.find((c) => c.toString() == "Symbol(renderer)"), a = s.find((c) => c.toString() == "Symbol(scene)"),
|
|
837
|
-
!t && o != null && (t = l[o].threeRenderer), !r && a != null && (r = l[a]), !n &&
|
|
839
|
+
const s = Object.getOwnPropertySymbols(i), o = s.find((c) => c.toString() == "Symbol(renderer)"), a = s.find((c) => c.toString() == "Symbol(scene)"), f = s.find((c) => c.toString() == "Symbol(needsRender)");
|
|
840
|
+
!t && o != null && (t = l[o].threeRenderer), !r && a != null && (r = l[a]), !n && f != null && (n = l[f]);
|
|
838
841
|
}
|
|
839
842
|
if (t && r) {
|
|
840
843
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
841
|
-
const i =
|
|
842
|
-
if (
|
|
844
|
+
const i = R.get(t, { engine: "model-viewer" });
|
|
845
|
+
if (R.addPlugin(new Ke()), i.enable(), r && n) {
|
|
843
846
|
let s = 0, o = setInterval(() => {
|
|
844
847
|
if (s++ > 10) {
|
|
845
848
|
clearInterval(o);
|
|
@@ -854,9 +857,9 @@ function Ve(l, e) {
|
|
|
854
857
|
}
|
|
855
858
|
return null;
|
|
856
859
|
}
|
|
857
|
-
class
|
|
860
|
+
class Ke {
|
|
858
861
|
constructor() {
|
|
859
|
-
|
|
862
|
+
d(this, "_didWarnAboutMissingUrl", !1);
|
|
860
863
|
}
|
|
861
864
|
onBeforeUpdateLOD(e, t, r, n) {
|
|
862
865
|
this.tryParseMeshLOD(t, n), this.tryParseTextureLOD(t, n);
|
|
@@ -874,31 +877,31 @@ class We {
|
|
|
874
877
|
return e.element;
|
|
875
878
|
}
|
|
876
879
|
tryParseTextureLOD(e, t) {
|
|
877
|
-
if (t[
|
|
880
|
+
if (t[re] == !0)
|
|
878
881
|
return;
|
|
879
|
-
t[
|
|
882
|
+
t[re] = !0;
|
|
880
883
|
const r = this.tryGetCurrentGLTF(e), n = this.tryGetCurrentModelViewer(e), i = this.getUrl(n);
|
|
881
884
|
if (i && r && t.material) {
|
|
882
885
|
let s = function(a) {
|
|
883
|
-
var c, x,
|
|
884
|
-
if (a[
|
|
886
|
+
var c, x, u;
|
|
887
|
+
if (a[re] == !0)
|
|
885
888
|
return;
|
|
886
|
-
a[
|
|
887
|
-
const
|
|
888
|
-
for (let y = 0; y <
|
|
889
|
-
const
|
|
889
|
+
a[re] = !0, a.userData && (a.userData.LOD = -1);
|
|
890
|
+
const f = Object.keys(a);
|
|
891
|
+
for (let y = 0; y < f.length; y++) {
|
|
892
|
+
const w = f[y], L = a[w];
|
|
890
893
|
if ((L == null ? void 0 : L.isTexture) === !0) {
|
|
891
|
-
const
|
|
892
|
-
if (
|
|
894
|
+
const B = (x = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : x.textures;
|
|
895
|
+
if (B == null)
|
|
893
896
|
continue;
|
|
894
|
-
const
|
|
895
|
-
if (!
|
|
896
|
-
console.warn("Texture data not found for texture index " +
|
|
897
|
+
const I = r.parser.json.textures[B];
|
|
898
|
+
if (!I) {
|
|
899
|
+
console.warn("Texture data not found for texture index " + B);
|
|
897
900
|
continue;
|
|
898
901
|
}
|
|
899
|
-
if ((
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
+
if ((u = I == null ? void 0 : I.extensions) != null && u[F]) {
|
|
903
|
+
const p = I.extensions[F];
|
|
904
|
+
p && i && _.registerTexture(i, L, p.lods.length, B, p);
|
|
902
905
|
}
|
|
903
906
|
}
|
|
904
907
|
}
|
|
@@ -913,37 +916,37 @@ class We {
|
|
|
913
916
|
}
|
|
914
917
|
tryParseMeshLOD(e, t) {
|
|
915
918
|
var s, o;
|
|
916
|
-
if (t[
|
|
919
|
+
if (t[Le] == !0)
|
|
917
920
|
return;
|
|
918
|
-
t[
|
|
921
|
+
t[Le] = !0;
|
|
919
922
|
const r = this.tryGetCurrentModelViewer(e), n = this.getUrl(r);
|
|
920
923
|
if (!n)
|
|
921
924
|
return;
|
|
922
|
-
const i = (o = (s = t.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : o[
|
|
925
|
+
const i = (o = (s = t.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : o[F];
|
|
923
926
|
if (i && n) {
|
|
924
927
|
const a = t.uuid;
|
|
925
|
-
|
|
928
|
+
_.registerMesh(n, a, t, 0, i.lods.length, i);
|
|
926
929
|
}
|
|
927
930
|
}
|
|
928
931
|
}
|
|
929
|
-
|
|
930
|
-
function
|
|
931
|
-
|
|
932
|
-
const n =
|
|
932
|
+
Ve();
|
|
933
|
+
function tt(l, e, t, r) {
|
|
934
|
+
we(e), ve(t), t.register((i) => new _(i, l));
|
|
935
|
+
const n = R.get(e);
|
|
933
936
|
return (r == null ? void 0 : r.enableLODsManager) !== !1 && n.enable(), n;
|
|
934
937
|
}
|
|
935
938
|
export {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
939
|
+
F as EXTENSION_NAME,
|
|
940
|
+
R as LODsManager,
|
|
941
|
+
_ as NEEDLE_progressive,
|
|
942
|
+
De as VERSION,
|
|
943
|
+
ve as addDracoAndKTX2Loaders,
|
|
944
|
+
we as createLoaders,
|
|
945
|
+
pe as getRaycastMesh,
|
|
946
|
+
Ve as patchModelViewer,
|
|
947
|
+
Ze as setDracoDecoderLocation,
|
|
948
|
+
je as setKTX2TranscoderLocation,
|
|
949
|
+
Fe as setRaycastMesh,
|
|
950
|
+
tt as useNeedleProgressive,
|
|
951
|
+
et as useRaycastMeshes
|
|
949
952
|
};
|