@needle-tools/gltf-progressive 1.2.3-alpha.2 → 1.2.3-beta
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 +6 -0
- package/gltf-progressive.js +310 -304
- package/gltf-progressive.min.js +7 -7
- package/gltf-progressive.umd.cjs +7 -7
- package/lib/lods_manager.js +12 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
var ze = Object.defineProperty;
|
|
2
2
|
var Ve = (a, t, e) => t in a ? ze(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
|
-
var
|
|
3
|
+
var f = (a, t, e) => (Ve(a, typeof t != "symbol" ? t + "" : t, e), e), Se = (a, t, e) => {
|
|
4
4
|
if (!t.has(a))
|
|
5
5
|
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
7
|
+
var x = (a, t, e) => (Se(a, t, "read from private field"), e ? e.call(a) : t.get(a)), X = (a, t, e) => {
|
|
8
8
|
if (t.has(a))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
10
|
t instanceof WeakSet ? t.add(a) : t.set(a, e);
|
|
11
|
-
},
|
|
12
|
-
import { BufferGeometry as de, Mesh as
|
|
11
|
+
}, F = (a, t, e, r) => (Se(a, t, "write to private field"), r ? r.call(a, e) : t.set(a, e), e);
|
|
12
|
+
import { BufferGeometry as de, Mesh as H, Material as Ne, Texture as ee, TextureLoader as Ue, Matrix4 as be, Frustum as We, Clock as Ke, MeshStandardMaterial as qe, Sphere as Xe, Box3 as Te, Vector3 as N } from "three";
|
|
13
13
|
import { GLTFLoader as Ye } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
14
14
|
import { MeshoptDecoder as He } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
15
15
|
import { DRACOLoader as Je } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
@@ -69,8 +69,8 @@ function yt(a = !0) {
|
|
|
69
69
|
if (a) {
|
|
70
70
|
if (re)
|
|
71
71
|
return;
|
|
72
|
-
const t = re =
|
|
73
|
-
|
|
72
|
+
const t = re = H.prototype.raycast;
|
|
73
|
+
H.prototype.raycast = function(e, r) {
|
|
74
74
|
const o = this, i = Oe(o);
|
|
75
75
|
let s;
|
|
76
76
|
i && o.isMesh && (s = o.geometry, o.geometry = i), t.call(this, e, r), s && (o.geometry = s);
|
|
@@ -78,7 +78,7 @@ function yt(a = !0) {
|
|
|
78
78
|
} else {
|
|
79
79
|
if (!re)
|
|
80
80
|
return;
|
|
81
|
-
|
|
81
|
+
H.prototype.raycast = re, re = null;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
let re = null;
|
|
@@ -88,18 +88,18 @@ function tt(a) {
|
|
|
88
88
|
t.setAttribute(e, a.getAttribute(e));
|
|
89
89
|
return t.setIndex(a.getIndex()), t;
|
|
90
90
|
}
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
91
|
+
const Y = new Array(), U = "NEEDLE_progressive", M = ae("debugprogressive"), xe = Symbol("needle-progressive-texture"), ne = /* @__PURE__ */ new Map(), ve = /* @__PURE__ */ new Set();
|
|
92
|
+
if (M) {
|
|
93
93
|
let a = function() {
|
|
94
94
|
t += 1, console.log("Toggle LOD level", t, ne), ne.forEach((o, i) => {
|
|
95
95
|
for (const s of o.keys) {
|
|
96
96
|
const n = i[s];
|
|
97
97
|
if (n != null) {
|
|
98
98
|
if (n.isBufferGeometry === !0) {
|
|
99
|
-
const l =
|
|
100
|
-
i["DEBUG:LOD"] = t,
|
|
99
|
+
const l = b.getMeshLODInformation(n), u = l ? Math.min(t, l.lods.length) : 0;
|
|
100
|
+
i["DEBUG:LOD"] = t, b.assignMeshLOD(i, u), l && (e = Math.max(e, l.lods.length - 1));
|
|
101
101
|
} else if (i.isMaterial === !0) {
|
|
102
|
-
i["DEBUG:LOD"] = t,
|
|
102
|
+
i["DEBUG:LOD"] = t, b.assignTextureLOD(i, t);
|
|
103
103
|
break;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -114,32 +114,32 @@ if (L) {
|
|
|
114
114
|
}
|
|
115
115
|
function Ae(a, t, e) {
|
|
116
116
|
var o;
|
|
117
|
-
if (!
|
|
117
|
+
if (!M)
|
|
118
118
|
return;
|
|
119
119
|
ne.has(a) || ne.set(a, { keys: [], sourceId: e });
|
|
120
120
|
const r = ne.get(a);
|
|
121
121
|
((o = r == null ? void 0 : r.keys) == null ? void 0 : o.includes(t)) == !1 && r.keys.push(t);
|
|
122
122
|
}
|
|
123
|
-
const
|
|
123
|
+
const _ = class {
|
|
124
124
|
constructor(t, e) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
f(this, "parser");
|
|
126
|
+
f(this, "url");
|
|
127
|
+
f(this, "_isLoadingMesh");
|
|
128
|
+
f(this, "loadMesh", (t) => {
|
|
129
129
|
var r, o;
|
|
130
130
|
if (this._isLoadingMesh)
|
|
131
131
|
return null;
|
|
132
|
-
const e = (o = (r = this.parser.json.meshes[t]) == null ? void 0 : r.extensions) == null ? void 0 : o[
|
|
132
|
+
const e = (o = (r = this.parser.json.meshes[t]) == null ? void 0 : r.extensions) == null ? void 0 : o[U];
|
|
133
133
|
return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((i) => {
|
|
134
134
|
var s;
|
|
135
|
-
return this._isLoadingMesh = !1, i &&
|
|
135
|
+
return this._isLoadingMesh = !1, i && _.registerMesh(this.url, e.guid, i, (s = e.lods) == null ? void 0 : s.length, void 0, e), i;
|
|
136
136
|
})) : null;
|
|
137
137
|
});
|
|
138
|
-
|
|
138
|
+
M && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
|
|
139
139
|
}
|
|
140
140
|
/** The name of the extension */
|
|
141
141
|
get name() {
|
|
142
|
-
return
|
|
142
|
+
return U;
|
|
143
143
|
}
|
|
144
144
|
static getMeshLODInformation(t) {
|
|
145
145
|
const e = this.getAssignedLODInformation(t);
|
|
@@ -158,11 +158,11 @@ const O = class {
|
|
|
158
158
|
this.getMaterialMinMaxLODsCount(n, e);
|
|
159
159
|
return t[o] = e, e;
|
|
160
160
|
}
|
|
161
|
-
if (
|
|
161
|
+
if (M === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
|
|
162
162
|
const n = t;
|
|
163
163
|
for (const l of Object.keys(n.uniforms)) {
|
|
164
|
-
const
|
|
165
|
-
(
|
|
164
|
+
const u = n.uniforms[l].value;
|
|
165
|
+
(u == null ? void 0 : u.isTexture) === !0 && s(u, e);
|
|
166
166
|
}
|
|
167
167
|
} else if (t.isMaterial)
|
|
168
168
|
for (const n of Object.keys(t)) {
|
|
@@ -171,14 +171,14 @@ const O = class {
|
|
|
171
171
|
}
|
|
172
172
|
return t[o] = e, e;
|
|
173
173
|
function s(n, l) {
|
|
174
|
-
const
|
|
175
|
-
if (
|
|
176
|
-
const c = r.lodInfos.get(
|
|
174
|
+
const u = r.getAssignedLODInformation(n);
|
|
175
|
+
if (u) {
|
|
176
|
+
const c = r.lodInfos.get(u.key);
|
|
177
177
|
if (c && c.lods) {
|
|
178
178
|
l.min_count = Math.min(l.min_count, c.lods.length), l.max_count = Math.max(l.max_count, c.lods.length);
|
|
179
|
-
for (let
|
|
180
|
-
const
|
|
181
|
-
|
|
179
|
+
for (let D = 0; D < c.lods.length; D++) {
|
|
180
|
+
const h = c.lods[D];
|
|
181
|
+
h.width && (l.lods[D] = l.lods[D] || { min_height: 1 / 0, max_height: 0 }, l.lods[D].min_height = Math.min(l.lods[D].min_height, h.height), l.lods[D].max_height = Math.max(l.lods[D].max_height, h.height));
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
}
|
|
@@ -237,24 +237,24 @@ const O = class {
|
|
|
237
237
|
var r;
|
|
238
238
|
if (!t)
|
|
239
239
|
return Promise.resolve(null);
|
|
240
|
-
if (t instanceof
|
|
240
|
+
if (t instanceof H || t.isMesh === !0) {
|
|
241
241
|
const o = t.geometry, i = this.getAssignedLODInformation(o);
|
|
242
242
|
if (!i)
|
|
243
243
|
return Promise.resolve(null);
|
|
244
|
-
for (const s of
|
|
244
|
+
for (const s of Y)
|
|
245
245
|
(r = s.onBeforeGetLODMesh) == null || r.call(s, t, e);
|
|
246
|
-
return t["LOD:requested level"] = e,
|
|
246
|
+
return t["LOD:requested level"] = e, _.getOrLoadLOD(o, e).then((s) => {
|
|
247
247
|
if (t["LOD:requested level"] === e) {
|
|
248
248
|
if (delete t["LOD:requested level"], Array.isArray(s)) {
|
|
249
249
|
const n = i.index || 0;
|
|
250
250
|
s = s[n];
|
|
251
251
|
}
|
|
252
|
-
s && o != s && ((s == null ? void 0 : s.isBufferGeometry) ? (t.geometry = s,
|
|
252
|
+
s && o != s && ((s == null ? void 0 : s.isBufferGeometry) ? (t.geometry = s, M && Ae(t, "geometry", i.url)) : M && console.error("Invalid LOD geometry", s));
|
|
253
253
|
}
|
|
254
254
|
return s;
|
|
255
255
|
}).catch((s) => (console.error("Error loading mesh LOD", t, s), null));
|
|
256
256
|
} else
|
|
257
|
-
|
|
257
|
+
M && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
|
|
258
258
|
return Promise.resolve(null);
|
|
259
259
|
}
|
|
260
260
|
/** Load a different resolution of a texture (if available)
|
|
@@ -269,13 +269,13 @@ const O = class {
|
|
|
269
269
|
return Promise.resolve(null);
|
|
270
270
|
if (t instanceof Ne || t.isMaterial === !0) {
|
|
271
271
|
const r = t, o = [], i = new Array();
|
|
272
|
-
if (
|
|
272
|
+
if (M && ve.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
|
|
273
273
|
const s = r;
|
|
274
274
|
for (const n of Object.keys(s.uniforms)) {
|
|
275
275
|
const l = s.uniforms[n].value;
|
|
276
276
|
if ((l == null ? void 0 : l.isTexture) === !0) {
|
|
277
|
-
const
|
|
278
|
-
o.push(
|
|
277
|
+
const u = this.assignTextureLODForSlot(l, e, r, n);
|
|
278
|
+
o.push(u), i.push(n);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
} else
|
|
@@ -289,8 +289,8 @@ const O = class {
|
|
|
289
289
|
return Promise.all(o).then((s) => {
|
|
290
290
|
const n = new Array();
|
|
291
291
|
for (let l = 0; l < s.length; l++) {
|
|
292
|
-
const
|
|
293
|
-
|
|
292
|
+
const u = s[l], c = i[l];
|
|
293
|
+
u && u.isTexture === !0 ? n.push({ material: r, slot: c, texture: u, level: e }) : n.push({ material: r, slot: c, texture: null, level: e });
|
|
294
294
|
}
|
|
295
295
|
return n;
|
|
296
296
|
});
|
|
@@ -302,7 +302,7 @@ const O = class {
|
|
|
302
302
|
return Promise.resolve(null);
|
|
303
303
|
}
|
|
304
304
|
static assignTextureLODForSlot(t, e, r, o) {
|
|
305
|
-
return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : o === "glyphMap" ? Promise.resolve(t) :
|
|
305
|
+
return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : o === "glyphMap" ? Promise.resolve(t) : _.getOrLoadLOD(t, e).then((i) => {
|
|
306
306
|
if (Array.isArray(i))
|
|
307
307
|
return null;
|
|
308
308
|
if ((i == null ? void 0 : i.isTexture) === !0) {
|
|
@@ -312,164 +312,164 @@ const O = class {
|
|
|
312
312
|
if (s) {
|
|
313
313
|
const n = this.getAssignedLODInformation(s);
|
|
314
314
|
if (n && (n == null ? void 0 : n.level) < e)
|
|
315
|
-
return
|
|
315
|
+
return M === "verbose" && console.warn("Assigned texture level is already higher: ", n.level, e, r, s, i), null;
|
|
316
316
|
}
|
|
317
317
|
r[o] = i;
|
|
318
318
|
}
|
|
319
|
-
if (
|
|
319
|
+
if (M && o && r) {
|
|
320
320
|
const s = this.getAssignedLODInformation(t);
|
|
321
321
|
s && Ae(r, o, s.url);
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
return i;
|
|
325
325
|
} else
|
|
326
|
-
|
|
326
|
+
M == "verbose" && console.warn("No LOD found for", t, e);
|
|
327
327
|
return null;
|
|
328
328
|
}).catch((i) => (console.error("Error loading LOD", t, i), null));
|
|
329
329
|
}
|
|
330
330
|
afterRoot(t) {
|
|
331
331
|
var e, r;
|
|
332
|
-
return
|
|
332
|
+
return M && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((o, i) => {
|
|
333
333
|
var s;
|
|
334
334
|
if (o != null && o.extensions) {
|
|
335
|
-
const n = o == null ? void 0 : o.extensions[
|
|
335
|
+
const n = o == null ? void 0 : o.extensions[U];
|
|
336
336
|
if (n) {
|
|
337
337
|
if (!n.lods) {
|
|
338
|
-
|
|
338
|
+
M && console.warn("Texture has no LODs", n);
|
|
339
339
|
return;
|
|
340
340
|
}
|
|
341
341
|
let l = !1;
|
|
342
|
-
for (const
|
|
343
|
-
if (
|
|
344
|
-
const c = this.parser.associations.get(
|
|
345
|
-
(c == null ? void 0 : c.textures) === i && (l = !0,
|
|
342
|
+
for (const u of this.parser.associations.keys())
|
|
343
|
+
if (u.isTexture === !0) {
|
|
344
|
+
const c = this.parser.associations.get(u);
|
|
345
|
+
(c == null ? void 0 : c.textures) === i && (l = !0, _.registerTexture(this.url, u, (s = n.lods) == null ? void 0 : s.length, i, n));
|
|
346
346
|
}
|
|
347
|
-
l || this.parser.getDependency("texture", i).then((
|
|
347
|
+
l || this.parser.getDependency("texture", i).then((u) => {
|
|
348
348
|
var c;
|
|
349
|
-
|
|
349
|
+
u && _.registerTexture(this.url, u, (c = n.lods) == null ? void 0 : c.length, i, n);
|
|
350
350
|
});
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
}), (r = this.parser.json.meshes) == null || r.forEach((o, i) => {
|
|
354
354
|
if (o != null && o.extensions) {
|
|
355
|
-
const s = o == null ? void 0 : o.extensions[
|
|
355
|
+
const s = o == null ? void 0 : o.extensions[U];
|
|
356
356
|
if (s && s.lods) {
|
|
357
357
|
for (const n of this.parser.associations.keys())
|
|
358
358
|
if (n.isMesh) {
|
|
359
359
|
const l = this.parser.associations.get(n);
|
|
360
|
-
(l == null ? void 0 : l.meshes) === i &&
|
|
360
|
+
(l == null ? void 0 : l.meshes) === i && _.registerMesh(this.url, s.guid, n, s.lods.length, l.primitives, s);
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
}), null;
|
|
365
365
|
}
|
|
366
366
|
static async getOrLoadLOD(t, e) {
|
|
367
|
-
var n, l,
|
|
368
|
-
const r =
|
|
367
|
+
var n, l, u, c;
|
|
368
|
+
const r = M == "verbose", o = t.userData.LODS;
|
|
369
369
|
if (!o)
|
|
370
370
|
return null;
|
|
371
371
|
const i = o == null ? void 0 : o.key;
|
|
372
372
|
let s;
|
|
373
373
|
if (t.isTexture === !0) {
|
|
374
|
-
const
|
|
375
|
-
|
|
374
|
+
const D = t;
|
|
375
|
+
D.source && D.source[xe] && (s = D.source[xe]);
|
|
376
376
|
}
|
|
377
|
-
if (s || (s =
|
|
377
|
+
if (s || (s = _.lodInfos.get(i)), s) {
|
|
378
378
|
if (e > 0) {
|
|
379
|
-
let
|
|
380
|
-
const
|
|
381
|
-
if (
|
|
379
|
+
let d = !1;
|
|
380
|
+
const p = Array.isArray(s.lods);
|
|
381
|
+
if (p && e >= s.lods.length ? d = !0 : p || (d = !0), d)
|
|
382
382
|
return this.lowresCache.get(i);
|
|
383
383
|
}
|
|
384
|
-
const
|
|
385
|
-
if (!
|
|
386
|
-
return
|
|
387
|
-
const
|
|
388
|
-
if (
|
|
384
|
+
const D = Array.isArray(s.lods) ? (n = s.lods[e]) == null ? void 0 : n.path : s.lods;
|
|
385
|
+
if (!D)
|
|
386
|
+
return M && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, s)), null;
|
|
387
|
+
const h = Ze(o.url, D);
|
|
388
|
+
if (h.endsWith(".glb") || h.endsWith(".gltf")) {
|
|
389
389
|
if (!s.guid)
|
|
390
390
|
return console.warn("missing pointer for glb/gltf texture", s), null;
|
|
391
|
-
const
|
|
392
|
-
if (
|
|
393
|
-
r && console.log(`LOD ${e} was already loading/loaded: ${
|
|
394
|
-
let
|
|
395
|
-
`,
|
|
396
|
-
if (
|
|
397
|
-
return
|
|
391
|
+
const d = h + "_" + s.guid, p = this.previouslyLoaded.get(d);
|
|
392
|
+
if (p !== void 0) {
|
|
393
|
+
r && console.log(`LOD ${e} was already loading/loaded: ${d}`);
|
|
394
|
+
let m = await p.catch((z) => (console.error(`Error loading LOD ${e} from ${h}
|
|
395
|
+
`, z), null)), w = !1;
|
|
396
|
+
if (m == null || (m instanceof ee && t instanceof ee ? (l = m.image) != null && l.data || (u = m.source) != null && u.data ? m = this.copySettings(t, m) : (w = !0, this.previouslyLoaded.delete(d)) : m instanceof de && t instanceof de && ((c = m.attributes.position) != null && c.array || (w = !0, this.previouslyLoaded.delete(d)))), !w)
|
|
397
|
+
return m;
|
|
398
398
|
}
|
|
399
|
-
const
|
|
400
|
-
const
|
|
401
|
-
Ie(
|
|
402
|
-
let
|
|
403
|
-
if (
|
|
404
|
-
const
|
|
405
|
-
|
|
399
|
+
const L = s, k = new Promise(async (m, w) => {
|
|
400
|
+
const z = new Ye();
|
|
401
|
+
Ie(z), M && (await new Promise((O) => setTimeout(O, 1e3)), r && console.warn("Start loading (delayed) " + h, L.guid));
|
|
402
|
+
let q = h;
|
|
403
|
+
if (L && Array.isArray(L.lods)) {
|
|
404
|
+
const O = L.lods[e];
|
|
405
|
+
O.hash && (q += "?v=" + O.hash);
|
|
406
406
|
}
|
|
407
|
-
const
|
|
408
|
-
`,
|
|
409
|
-
if (!
|
|
407
|
+
const S = await z.loadAsync(q).catch((O) => (console.error(`Error loading LOD ${e} from ${h}
|
|
408
|
+
`, O), null));
|
|
409
|
+
if (!S)
|
|
410
410
|
return null;
|
|
411
|
-
const
|
|
412
|
-
r && console.log("Loading finished " +
|
|
413
|
-
let
|
|
414
|
-
if (
|
|
415
|
-
let
|
|
416
|
-
for (const
|
|
417
|
-
if (
|
|
418
|
-
const
|
|
419
|
-
if (
|
|
420
|
-
|
|
411
|
+
const V = S.parser;
|
|
412
|
+
r && console.log("Loading finished " + h, L.guid);
|
|
413
|
+
let A = 0;
|
|
414
|
+
if (S.parser.json.textures) {
|
|
415
|
+
let O = !1;
|
|
416
|
+
for (const y of S.parser.json.textures) {
|
|
417
|
+
if (y != null && y.extensions) {
|
|
418
|
+
const g = y == null ? void 0 : y.extensions[U];
|
|
419
|
+
if (g != null && g.guid && g.guid === L.guid) {
|
|
420
|
+
O = !0;
|
|
421
421
|
break;
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
|
-
|
|
424
|
+
A++;
|
|
425
425
|
}
|
|
426
|
-
if (
|
|
427
|
-
let
|
|
428
|
-
return
|
|
426
|
+
if (O) {
|
|
427
|
+
let y = await V.getDependency("texture", A);
|
|
428
|
+
return y && _.assignLODInformation(o.url, y, i, e, void 0, void 0), r && console.log('change "' + t.name + '" → "' + y.name + '"', h, A, y, d), t instanceof ee && (y = this.copySettings(t, y)), y && (y.guid = L.guid), m(y);
|
|
429
429
|
} else
|
|
430
|
-
|
|
430
|
+
M && console.warn("Could not find texture with guid", L.guid, S.parser.json);
|
|
431
431
|
}
|
|
432
|
-
if (
|
|
433
|
-
let
|
|
434
|
-
for (const
|
|
435
|
-
if (
|
|
436
|
-
const
|
|
437
|
-
if (
|
|
438
|
-
|
|
432
|
+
if (A = 0, S.parser.json.meshes) {
|
|
433
|
+
let O = !1;
|
|
434
|
+
for (const y of S.parser.json.meshes) {
|
|
435
|
+
if (y != null && y.extensions) {
|
|
436
|
+
const g = y == null ? void 0 : y.extensions[U];
|
|
437
|
+
if (g != null && g.guid && g.guid === L.guid) {
|
|
438
|
+
O = !0;
|
|
439
439
|
break;
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
|
-
|
|
442
|
+
A++;
|
|
443
443
|
}
|
|
444
|
-
if (
|
|
445
|
-
const
|
|
446
|
-
if (r && console.log(`Loaded Mesh "${
|
|
447
|
-
const
|
|
448
|
-
return
|
|
444
|
+
if (O) {
|
|
445
|
+
const y = await V.getDependency("mesh", A), g = L;
|
|
446
|
+
if (r && console.log(`Loaded Mesh "${y.name}"`, h, A, y, d), y.isMesh === !0) {
|
|
447
|
+
const v = y.geometry;
|
|
448
|
+
return _.assignLODInformation(o.url, v, i, e, void 0, g.density), m(v);
|
|
449
449
|
} else {
|
|
450
|
-
const
|
|
451
|
-
for (let T = 0; T <
|
|
452
|
-
const
|
|
453
|
-
if (
|
|
454
|
-
const
|
|
455
|
-
|
|
450
|
+
const v = new Array();
|
|
451
|
+
for (let T = 0; T < y.children.length; T++) {
|
|
452
|
+
const P = y.children[T];
|
|
453
|
+
if (P.isMesh === !0) {
|
|
454
|
+
const E = P.geometry;
|
|
455
|
+
_.assignLODInformation(o.url, E, i, e, T, g.density), v.push(E);
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
-
return
|
|
458
|
+
return m(v);
|
|
459
459
|
}
|
|
460
460
|
} else
|
|
461
|
-
|
|
461
|
+
M && console.warn("Could not find mesh with guid", L.guid, S.parser.json);
|
|
462
462
|
}
|
|
463
|
-
return
|
|
463
|
+
return m(null);
|
|
464
464
|
});
|
|
465
|
-
return this.previouslyLoaded.set(
|
|
465
|
+
return this.previouslyLoaded.set(d, k), await k;
|
|
466
466
|
} else if (t instanceof ee) {
|
|
467
|
-
r && console.log("Load texture from uri: " +
|
|
468
|
-
const
|
|
469
|
-
return
|
|
467
|
+
r && console.log("Load texture from uri: " + h);
|
|
468
|
+
const p = await new Ue().loadAsync(h);
|
|
469
|
+
return p ? (p.guid = s.guid, p.flipY = !1, p.needsUpdate = !0, p.colorSpace = t.colorSpace, r && console.log(s, p)) : M && console.warn("failed loading", h), p;
|
|
470
470
|
}
|
|
471
471
|
} else
|
|
472
|
-
|
|
472
|
+
M && console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`, t.type);
|
|
473
473
|
return null;
|
|
474
474
|
}
|
|
475
475
|
static assignLODInformation(t, e, r, o, i, s) {
|
|
@@ -485,95 +485,95 @@ const O = class {
|
|
|
485
485
|
}
|
|
486
486
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
487
487
|
static copySettings(t, e) {
|
|
488
|
-
return e = e.clone(),
|
|
488
|
+
return e = e.clone(), M && console.warn(`Copying texture settings
|
|
489
489
|
`, t.uuid, `
|
|
490
490
|
`, e.uuid), e.offset = t.offset, e.repeat = t.repeat, e.colorSpace = t.colorSpace, e.magFilter = t.magFilter, e.minFilter = t.minFilter, e.wrapS = t.wrapS, e.wrapT = t.wrapT, e.flipY = t.flipY, e.anisotropy = t.anisotropy, e.mipmaps || (e.generateMipmaps = t.generateMipmaps), e;
|
|
491
491
|
}
|
|
492
492
|
};
|
|
493
|
-
let
|
|
493
|
+
let b = _;
|
|
494
494
|
/**
|
|
495
495
|
* Register a texture with LOD information
|
|
496
496
|
*/
|
|
497
|
-
|
|
498
|
-
if (
|
|
499
|
-
|
|
497
|
+
f(b, "registerTexture", (t, e, r, o, i) => {
|
|
498
|
+
if (M && console.log("> Progressive: register texture", o, e.name, e.uuid, e, i), !e) {
|
|
499
|
+
M && console.error("gltf-progressive: Register texture without texture");
|
|
500
500
|
return;
|
|
501
501
|
}
|
|
502
502
|
e.source && (e.source[xe] = i);
|
|
503
503
|
const s = i.guid;
|
|
504
|
-
|
|
504
|
+
_.assignLODInformation(t, e, s, r, o, void 0), _.lodInfos.set(s, i), _.lowresCache.set(s, e);
|
|
505
505
|
}), /**
|
|
506
506
|
* Register a mesh with LOD information
|
|
507
507
|
*/
|
|
508
|
-
|
|
509
|
-
var
|
|
510
|
-
|
|
508
|
+
f(b, "registerMesh", (t, e, r, o, i, s) => {
|
|
509
|
+
var u;
|
|
510
|
+
M && console.log("> Progressive: register mesh", i, r.name, s, r.uuid, r);
|
|
511
511
|
const n = r.geometry;
|
|
512
512
|
if (!n) {
|
|
513
|
-
|
|
513
|
+
M && console.warn("gltf-progressive: Register mesh without geometry");
|
|
514
514
|
return;
|
|
515
515
|
}
|
|
516
|
-
n.userData || (n.userData = {}),
|
|
517
|
-
let l =
|
|
518
|
-
l ? l.push(r.geometry) : l = [r.geometry],
|
|
519
|
-
for (const c of
|
|
520
|
-
(
|
|
516
|
+
n.userData || (n.userData = {}), _.assignLODInformation(t, n, e, o, i, s.density), _.lodInfos.set(e, s);
|
|
517
|
+
let l = _.lowresCache.get(e);
|
|
518
|
+
l ? l.push(r.geometry) : l = [r.geometry], _.lowresCache.set(e, l), o > 0 && !Oe(r) && et(r, n);
|
|
519
|
+
for (const c of Y)
|
|
520
|
+
(u = c.onRegisteredNewMesh) == null || u.call(c, r, s);
|
|
521
521
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
522
|
+
f(b, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
523
|
+
f(b, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
524
|
+
f(b, "lowresCache", /* @__PURE__ */ new Map());
|
|
525
525
|
class rt {
|
|
526
526
|
constructor(t, e, r, o, i) {
|
|
527
|
-
|
|
527
|
+
f(this, "url");
|
|
528
528
|
/** the key to lookup the LOD information */
|
|
529
|
-
|
|
530
|
-
|
|
529
|
+
f(this, "key");
|
|
530
|
+
f(this, "level");
|
|
531
531
|
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
532
|
-
|
|
532
|
+
f(this, "index");
|
|
533
533
|
/** the mesh density */
|
|
534
|
-
|
|
534
|
+
f(this, "density");
|
|
535
535
|
this.url = t, this.key = e, this.level = r, o != null && (this.index = o), i != null && (this.density = i);
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
|
-
const
|
|
539
|
-
var
|
|
540
|
-
const
|
|
538
|
+
const I = ae("debugprogressive"), st = ae("noprogressive"), Le = Symbol("Needle:LODSManager"), Me = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 };
|
|
539
|
+
var B, W, ge, Q, Z, pe, K;
|
|
540
|
+
const C = class {
|
|
541
541
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
542
542
|
constructor(t, e) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
543
|
+
f(this, "context");
|
|
544
|
+
f(this, "renderer");
|
|
545
|
+
f(this, "projectionScreenMatrix", new be());
|
|
546
|
+
f(this, "cameraFrustrum", new We());
|
|
547
547
|
/**
|
|
548
548
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
549
549
|
* @default 200_000
|
|
550
550
|
*/
|
|
551
|
-
|
|
551
|
+
f(this, "targetTriangleDensity", 2e5);
|
|
552
552
|
/**
|
|
553
553
|
* The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 2, the LODs will be updated every second frame, etc.
|
|
554
554
|
*/
|
|
555
|
-
|
|
556
|
-
|
|
555
|
+
f(this, "updateInterval", "auto");
|
|
556
|
+
X(this, B, 1);
|
|
557
557
|
/**
|
|
558
558
|
* If set to true, the LODsManager will not update the LODs.
|
|
559
559
|
*/
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
560
|
+
f(this, "pause", !1);
|
|
561
|
+
f(this, "_lodchangedlisteners", []);
|
|
562
|
+
X(this, W, void 0);
|
|
563
|
+
X(this, ge, new Ke());
|
|
564
|
+
X(this, Q, 0);
|
|
565
|
+
X(this, Z, 0);
|
|
566
|
+
X(this, pe, 0);
|
|
567
|
+
X(this, K, 0);
|
|
568
|
+
f(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
|
|
569
569
|
// private testIfLODLevelsAreAvailable() {
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
570
|
+
f(this, "_sphere", new Xe());
|
|
571
|
+
f(this, "_tempBox", new Te());
|
|
572
|
+
f(this, "_tempBox2", new Te());
|
|
573
|
+
f(this, "tempMatrix", new be());
|
|
574
|
+
f(this, "_tempWorldPosition", new N());
|
|
575
|
+
f(this, "_tempBoxSize", new N());
|
|
576
|
+
f(this, "_tempBox2Size", new N());
|
|
577
577
|
this.renderer = t, this.context = { ...e };
|
|
578
578
|
}
|
|
579
579
|
/** @internal */
|
|
@@ -581,11 +581,11 @@ const E = class {
|
|
|
581
581
|
return t[Me];
|
|
582
582
|
}
|
|
583
583
|
static addPlugin(t) {
|
|
584
|
-
|
|
584
|
+
Y.push(t);
|
|
585
585
|
}
|
|
586
586
|
static removePlugin(t) {
|
|
587
|
-
const e =
|
|
588
|
-
e >= 0 &&
|
|
587
|
+
const e = Y.indexOf(t);
|
|
588
|
+
e >= 0 && Y.splice(e, 1);
|
|
589
589
|
}
|
|
590
590
|
/**
|
|
591
591
|
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
@@ -595,7 +595,7 @@ const E = class {
|
|
|
595
595
|
static get(t, e) {
|
|
596
596
|
if (t[Le])
|
|
597
597
|
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[Le];
|
|
598
|
-
const r = new
|
|
598
|
+
const r = new C(t, {
|
|
599
599
|
engine: "unknown",
|
|
600
600
|
...e
|
|
601
601
|
});
|
|
@@ -603,7 +603,7 @@ const E = class {
|
|
|
603
603
|
}
|
|
604
604
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
605
605
|
get plugins() {
|
|
606
|
-
return
|
|
606
|
+
return Y;
|
|
607
607
|
}
|
|
608
608
|
addEventListener(t, e) {
|
|
609
609
|
t === "changed" && this._lodchangedlisteners.push(e);
|
|
@@ -612,25 +612,25 @@ const E = class {
|
|
|
612
612
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
613
613
|
*/
|
|
614
614
|
enable() {
|
|
615
|
-
if (
|
|
615
|
+
if (x(this, W))
|
|
616
616
|
return;
|
|
617
617
|
console.debug("[gltf-progressive] Enabling LODsManager for renderer");
|
|
618
618
|
let t = 0;
|
|
619
|
-
|
|
619
|
+
F(this, W, this.renderer.render);
|
|
620
620
|
const e = this;
|
|
621
621
|
ke(this.renderer), this.renderer.render = function(r, o) {
|
|
622
|
-
e.renderer.getRenderTarget() == null && (t = 0,
|
|
623
|
-
const s =
|
|
624
|
-
e.onBeforeRender(r, o, n, s),
|
|
622
|
+
e.renderer.getRenderTarget() == null && (t = 0, F(e, Q, x(e, Q) + 1), F(e, Z, x(e, ge).getDelta()), F(e, pe, x(e, pe) + x(e, Z)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / x(e, Z)), F(e, K, e._fpsBuffer.reduce((l, u) => l + u) / e._fpsBuffer.length), I && x(e, Q) % 30 === 0 && console.log("FPS", Math.round(x(e, K)), "Interval:", x(e, B)));
|
|
623
|
+
const s = x(e, Q), n = t++;
|
|
624
|
+
e.onBeforeRender(r, o, n, s), x(e, W).call(this, r, o), e.onAfterRender(r, o, n, s);
|
|
625
625
|
};
|
|
626
626
|
}
|
|
627
627
|
disable() {
|
|
628
|
-
|
|
628
|
+
x(this, W) && (this.renderer.render = x(this, W), F(this, W, void 0));
|
|
629
629
|
}
|
|
630
630
|
onBeforeRender(t, e, r, o) {
|
|
631
631
|
}
|
|
632
632
|
onAfterRender(t, e, r, o) {
|
|
633
|
-
var l,
|
|
633
|
+
var l, u;
|
|
634
634
|
if (this.pause)
|
|
635
635
|
return;
|
|
636
636
|
const i = this.renderer.renderLists.get(t, 0), s = i.opaque;
|
|
@@ -640,16 +640,16 @@ const E = class {
|
|
|
640
640
|
(c.name === "EffectMaterial" || c.name === "CopyShader") && (n = !1);
|
|
641
641
|
}
|
|
642
642
|
if ((e.parent && e.parent.type === "CubeCamera" || r >= 1 && e.type === "OrthographicCamera") && (n = !1), n) {
|
|
643
|
-
if (st || (this.updateInterval === "auto" ?
|
|
643
|
+
if (st || (this.updateInterval === "auto" ? x(this, K) < 40 && x(this, B) < 10 ? (F(this, B, x(this, B) + 1), I && console.warn("↓ Reducing LOD updates", x(this, B), x(this, K).toFixed(0))) : x(this, K) >= 60 && x(this, B) > 1 && (F(this, B, x(this, B) - 1), I && console.warn("↑ Increasing LOD updates", x(this, B), x(this, K).toFixed(0))) : F(this, B, this.updateInterval), x(this, B) > 0 && o % x(this, B) != 0))
|
|
644
644
|
return;
|
|
645
645
|
this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
|
|
646
646
|
const c = this.targetTriangleDensity;
|
|
647
|
-
for (const
|
|
648
|
-
if (
|
|
649
|
-
|
|
647
|
+
for (const d of s) {
|
|
648
|
+
if (d.material && (((l = d.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((u = d.geometry) == null ? void 0 : u.type) === "BufferGeometry") && (d.material.name === "SphericalGaussianBlur" || d.material.name == "BackgroundCubeMaterial" || d.material.name === "CubemapFromEquirect" || d.material.name === "EquirectangularToCubeUV")) {
|
|
649
|
+
I && (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", d, d.material.name, d.material.type)));
|
|
650
650
|
continue;
|
|
651
651
|
}
|
|
652
|
-
switch (
|
|
652
|
+
switch (d.material.type) {
|
|
653
653
|
case "LineBasicMaterial":
|
|
654
654
|
case "LineDashedMaterial":
|
|
655
655
|
case "PointsMaterial":
|
|
@@ -658,39 +658,44 @@ const E = class {
|
|
|
658
658
|
case "MeshDepthMaterial":
|
|
659
659
|
continue;
|
|
660
660
|
}
|
|
661
|
-
if (
|
|
662
|
-
|
|
663
|
-
const
|
|
664
|
-
|
|
661
|
+
if (I === "color" && d.material && !d.object.progressive_debug_color) {
|
|
662
|
+
d.object.progressive_debug_color = !0;
|
|
663
|
+
const L = Math.random() * 16777215, k = new qe({ color: L });
|
|
664
|
+
d.object.material = k;
|
|
665
665
|
}
|
|
666
|
-
const
|
|
667
|
-
(
|
|
666
|
+
const p = d.object;
|
|
667
|
+
(p instanceof H || p.isMesh) && this.updateLODs(t, e, p, c, o);
|
|
668
668
|
}
|
|
669
|
-
const
|
|
670
|
-
for (const
|
|
671
|
-
const
|
|
672
|
-
(
|
|
669
|
+
const D = i.transparent;
|
|
670
|
+
for (const d of D) {
|
|
671
|
+
const p = d.object;
|
|
672
|
+
(p instanceof H || p.isMesh) && this.updateLODs(t, e, p, c, o);
|
|
673
|
+
}
|
|
674
|
+
const h = i.transmissive;
|
|
675
|
+
for (const d of h) {
|
|
676
|
+
const p = d.object;
|
|
677
|
+
(p instanceof H || p.isMesh) && this.updateLODs(t, e, p, c, o);
|
|
673
678
|
}
|
|
674
679
|
}
|
|
675
680
|
}
|
|
676
681
|
/** Update the LOD levels for the renderer. */
|
|
677
682
|
updateLODs(t, e, r, o, i) {
|
|
678
|
-
var l,
|
|
683
|
+
var l, u;
|
|
679
684
|
r.userData || (r.userData = {});
|
|
680
685
|
let s = r[Me];
|
|
681
686
|
if (s || (s = new it(), r[Me] = s), s.frames++ < 2)
|
|
682
687
|
return;
|
|
683
|
-
for (const c of
|
|
688
|
+
for (const c of Y)
|
|
684
689
|
(l = c.onBeforeUpdateLOD) == null || l.call(c, this.renderer, t, e, r);
|
|
685
|
-
this.calculateLodLevel(e, r, s, o,
|
|
686
|
-
let n =
|
|
690
|
+
this.calculateLodLevel(e, r, s, o, R), R.mesh_lod = Math.round(R.mesh_lod), R.texture_lod = Math.round(R.texture_lod), R.mesh_lod >= 0 && this.loadProgressiveMeshes(r, R.mesh_lod);
|
|
691
|
+
let n = R.texture_lod;
|
|
687
692
|
if (r.material && n >= 0) {
|
|
688
693
|
const c = r["DEBUG:LOD"];
|
|
689
694
|
c != null && (n = c), this.loadProgressiveTextures(r.material, n);
|
|
690
695
|
}
|
|
691
|
-
for (const c of
|
|
692
|
-
(
|
|
693
|
-
s.lastLodLevel_Mesh =
|
|
696
|
+
for (const c of Y)
|
|
697
|
+
(u = c.onAfterUpdatedLOD) == null || u.call(c, this.renderer, t, e, r, R);
|
|
698
|
+
s.lastLodLevel_Mesh = R.mesh_lod, s.lastLodLevel_Texture = R.texture_lod;
|
|
694
699
|
}
|
|
695
700
|
/** Load progressive textures for the given material
|
|
696
701
|
* @param material the material to load the textures for
|
|
@@ -706,7 +711,7 @@ const E = class {
|
|
|
706
711
|
return;
|
|
707
712
|
}
|
|
708
713
|
let r = !1;
|
|
709
|
-
(t[
|
|
714
|
+
(t[J] === void 0 || e < t[J]) && (r = !0), r && (t[J] = e, b.assignTextureLOD(t, e).then((o) => {
|
|
710
715
|
this._lodchangedlisteners.forEach((i) => i({ type: "texture", level: e, object: t }));
|
|
711
716
|
}));
|
|
712
717
|
}
|
|
@@ -719,10 +724,10 @@ const E = class {
|
|
|
719
724
|
loadProgressiveMeshes(t, e) {
|
|
720
725
|
if (!t)
|
|
721
726
|
return Promise.resolve(null);
|
|
722
|
-
if (t[
|
|
723
|
-
t[
|
|
727
|
+
if (t[J] !== e) {
|
|
728
|
+
t[J] = e;
|
|
724
729
|
const r = t.geometry;
|
|
725
|
-
return
|
|
730
|
+
return b.assignMeshLOD(t, e).then((o) => (o && t[J] == e && r != t.geometry && this._lodchangedlisteners.forEach((i) => i({ type: "mesh", level: e, object: t })), o));
|
|
726
731
|
}
|
|
727
732
|
return Promise.resolve(null);
|
|
728
733
|
}
|
|
@@ -731,7 +736,7 @@ const E = class {
|
|
|
731
736
|
return this._tempPtInside.set(i, s, r.z).applyMatrix4(e).z < 0;
|
|
732
737
|
}
|
|
733
738
|
calculateLodLevel(t, e, r, o, i) {
|
|
734
|
-
var
|
|
739
|
+
var k, $;
|
|
735
740
|
if (!e) {
|
|
736
741
|
i.mesh_lod = -1, i.texture_lod = -1;
|
|
737
742
|
return;
|
|
@@ -741,113 +746,114 @@ const E = class {
|
|
|
741
746
|
return;
|
|
742
747
|
}
|
|
743
748
|
let n = 10 + 1, l = !1;
|
|
744
|
-
if (
|
|
749
|
+
if (I && e["DEBUG:LOD"] != null)
|
|
745
750
|
return e["DEBUG:LOD"];
|
|
746
|
-
const
|
|
747
|
-
if (!
|
|
751
|
+
const u = b.getMeshLODInformation(e.geometry), c = u == null ? void 0 : u.lods, D = c && c.length > 0, h = b.getMaterialMinMaxLODsCount(e.material), d = (h == null ? void 0 : h.min_count) != 1 / 0 && h.min_count > 0 && h.max_count > 0;
|
|
752
|
+
if (!D && !d) {
|
|
748
753
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
749
754
|
return;
|
|
750
755
|
}
|
|
751
|
-
if (
|
|
756
|
+
if (D || (l = !0, n = 0), !((k = this.cameraFrustrum) != null && k.intersectsObject(e))) {
|
|
752
757
|
i.mesh_lod = 99, i.texture_lod = 99;
|
|
753
758
|
return;
|
|
754
759
|
}
|
|
755
|
-
const
|
|
756
|
-
let
|
|
760
|
+
const p = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
761
|
+
let L = e.geometry.boundingBox;
|
|
757
762
|
if (e.type === "SkinnedMesh") {
|
|
758
|
-
const
|
|
759
|
-
|
|
763
|
+
const m = e;
|
|
764
|
+
m.boundingBox || m.computeBoundingBox(), L = m.boundingBox;
|
|
760
765
|
}
|
|
761
|
-
if (
|
|
762
|
-
const
|
|
766
|
+
if (L && t.isPerspectiveCamera) {
|
|
767
|
+
const m = t;
|
|
763
768
|
if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
|
|
764
769
|
this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
|
|
765
|
-
const
|
|
766
|
-
if (this._sphere.containsPoint(
|
|
770
|
+
const g = t.getWorldPosition(this._tempWorldPosition);
|
|
771
|
+
if (this._sphere.containsPoint(g)) {
|
|
767
772
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
768
773
|
return;
|
|
769
774
|
}
|
|
770
775
|
}
|
|
771
|
-
if (this._tempBox.copy(
|
|
776
|
+
if (this._tempBox.copy(L), this._tempBox.applyMatrix4(e.matrixWorld), C.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
772
777
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
773
778
|
return;
|
|
774
779
|
}
|
|
775
|
-
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled &&
|
|
776
|
-
const
|
|
777
|
-
let T =
|
|
778
|
-
const le = 2, ye = 1.5, ce = (
|
|
779
|
-
T = (T - ce) * le + ce,
|
|
780
|
-
const Fe = T < 0 &&
|
|
780
|
+
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && m.fov > 70) {
|
|
781
|
+
const g = this._tempBox.min, v = this._tempBox.max;
|
|
782
|
+
let T = g.x, P = g.y, E = v.x, j = v.y;
|
|
783
|
+
const le = 2, ye = 1.5, ce = (g.x + v.x) * 0.5, ue = (g.y + v.y) * 0.5;
|
|
784
|
+
T = (T - ce) * le + ce, P = (P - ue) * le + ue, E = (E - ce) * le + ce, j = (j - ue) * le + ue;
|
|
785
|
+
const Fe = T < 0 && E > 0 ? 0 : Math.min(Math.abs(g.x), Math.abs(v.x)), $e = P < 0 && j > 0 ? 0 : Math.min(Math.abs(g.y), Math.abs(v.y)), me = Math.max(Fe, $e);
|
|
781
786
|
r.lastCentrality = (ye - me) * (ye - me) * (ye - me);
|
|
782
787
|
} else
|
|
783
788
|
r.lastCentrality = 1;
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
const
|
|
789
|
-
if (Math.max(
|
|
790
|
-
const
|
|
791
|
-
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
const j = (
|
|
795
|
-
|
|
789
|
+
const w = this._tempBox.getSize(this._tempBoxSize);
|
|
790
|
+
w.multiplyScalar(0.5), screen.availHeight > 0 && p > 0 && w.multiplyScalar(p / screen.availHeight), w.x *= m.aspect;
|
|
791
|
+
const z = t.matrixWorldInverse, q = this._tempBox2;
|
|
792
|
+
q.copy(L), q.applyMatrix4(e.matrixWorld), q.applyMatrix4(z);
|
|
793
|
+
const S = q.getSize(this._tempBox2Size), V = Math.max(S.x, S.y);
|
|
794
|
+
if (Math.max(w.x, w.y) != 0 && V != 0 && (w.z = S.z / Math.max(S.x, S.y) * Math.max(w.x, w.y)), r.lastScreenCoverage = Math.max(w.x, w.y, w.z), r.lastScreenspaceVolume.copy(w), r.lastScreenCoverage *= r.lastCentrality, I && C.debugDrawLine) {
|
|
795
|
+
const g = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
796
|
+
g.invert();
|
|
797
|
+
const v = C.corner0, T = C.corner1, P = C.corner2, E = C.corner3;
|
|
798
|
+
v.copy(this._tempBox.min), T.copy(this._tempBox.max), T.x = v.x, P.copy(this._tempBox.max), P.y = v.y, E.copy(this._tempBox.max);
|
|
799
|
+
const j = (v.z + E.z) * 0.5;
|
|
800
|
+
v.z = T.z = P.z = E.z = j, v.applyMatrix4(g), T.applyMatrix4(g), P.applyMatrix4(g), E.applyMatrix4(g), C.debugDrawLine(v, T, 255), C.debugDrawLine(v, P, 255), C.debugDrawLine(T, E, 255), C.debugDrawLine(P, E, 255);
|
|
796
801
|
}
|
|
797
|
-
let
|
|
802
|
+
let O = 999;
|
|
798
803
|
if (c && r.lastScreenCoverage > 0) {
|
|
799
|
-
for (let
|
|
800
|
-
if (c[
|
|
801
|
-
|
|
804
|
+
for (let g = 0; g < c.length; g++)
|
|
805
|
+
if (c[g].density / r.lastScreenCoverage < o) {
|
|
806
|
+
O = g;
|
|
802
807
|
break;
|
|
803
808
|
}
|
|
804
809
|
}
|
|
805
|
-
|
|
810
|
+
O < n && (n = O, l = !0);
|
|
806
811
|
}
|
|
807
|
-
if (l ? i.mesh_lod = n : i.mesh_lod = r.lastLodLevel_Mesh,
|
|
808
|
-
const
|
|
809
|
-
|
|
812
|
+
if (l ? i.mesh_lod = n : i.mesh_lod = r.lastLodLevel_Mesh, I && i.mesh_lod != r.lastLodLevel_Mesh) {
|
|
813
|
+
const w = c == null ? void 0 : c[i.mesh_lod];
|
|
814
|
+
w && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${i.mesh_lod} (${w.density.toFixed(0)}) - ${e.name}`);
|
|
810
815
|
}
|
|
811
|
-
if (
|
|
816
|
+
if (d) {
|
|
817
|
+
const m = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
812
818
|
if (r.lastLodLevel_Texture < 0) {
|
|
813
|
-
if (i.texture_lod =
|
|
814
|
-
const
|
|
815
|
-
|
|
819
|
+
if (i.texture_lod = h.max_count - 1, I) {
|
|
820
|
+
const w = h.lods[h.max_count - 1];
|
|
821
|
+
I && console.log(`First Texture LOD ${i.texture_lod} (${w.max_height}px) - ${e.name}`);
|
|
816
822
|
}
|
|
817
823
|
} else {
|
|
818
|
-
const
|
|
819
|
-
let
|
|
820
|
-
((
|
|
821
|
-
const
|
|
822
|
-
for (let
|
|
823
|
-
let
|
|
824
|
-
if (!(je() &&
|
|
825
|
-
if (i.texture_lod =
|
|
826
|
-
const
|
|
827
|
-
|
|
828
|
-
Screensize: ${
|
|
824
|
+
const w = r.lastScreenspaceVolume.x + r.lastScreenspaceVolume.y + r.lastScreenspaceVolume.z;
|
|
825
|
+
let z = r.lastScreenCoverage * 2;
|
|
826
|
+
(($ = this.context) == null ? void 0 : $.engine) === "model-viewer" && (z *= 2);
|
|
827
|
+
const S = p / window.devicePixelRatio * z;
|
|
828
|
+
for (let V = h.lods.length - 1; V >= 0; V--) {
|
|
829
|
+
let A = h.lods[V];
|
|
830
|
+
if (!(m && A.max_height >= 2048) && !(je() && A.max_height > 4096) && A.max_height > S) {
|
|
831
|
+
if (i.texture_lod = V, i.texture_lod < r.lastLodLevel_Texture) {
|
|
832
|
+
const O = A.max_height;
|
|
833
|
+
I && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${i.texture_lod} = ${O}px
|
|
834
|
+
Screensize: ${S.toFixed(0)}px, Coverage: ${(100 * r.lastScreenCoverage).toFixed(2)}%, Volume ${w.toFixed(1)}
|
|
829
835
|
${e.name}`);
|
|
830
836
|
}
|
|
831
837
|
break;
|
|
832
838
|
}
|
|
833
839
|
}
|
|
834
840
|
}
|
|
835
|
-
else
|
|
841
|
+
} else
|
|
836
842
|
i.texture_lod = 0;
|
|
837
843
|
}
|
|
838
844
|
};
|
|
839
|
-
let
|
|
840
|
-
|
|
845
|
+
let G = C;
|
|
846
|
+
B = new WeakMap(), W = new WeakMap(), ge = new WeakMap(), Q = new WeakMap(), Z = new WeakMap(), pe = new WeakMap(), K = new WeakMap(), /** Assign a function to draw debug lines for the LODs. This function will be called with the start and end position of the line and the color of the line when the `debugprogressive` query parameter is set.
|
|
841
847
|
*/
|
|
842
|
-
|
|
848
|
+
f(G, "debugDrawLine"), f(G, "corner0", new N()), f(G, "corner1", new N()), f(G, "corner2", new N()), f(G, "corner3", new N()), f(G, "_tempPtInside", new N());
|
|
843
849
|
class it {
|
|
844
850
|
constructor() {
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
+
f(this, "frames", 0);
|
|
852
|
+
f(this, "lastLodLevel_Mesh", -1);
|
|
853
|
+
f(this, "lastLodLevel_Texture", -1);
|
|
854
|
+
f(this, "lastScreenCoverage", 0);
|
|
855
|
+
f(this, "lastScreenspaceVolume", new N());
|
|
856
|
+
f(this, "lastCentrality", 0);
|
|
851
857
|
}
|
|
852
858
|
}
|
|
853
859
|
const Pe = Symbol("NEEDLE_mesh_lod"), fe = Symbol("NEEDLE_texture_lod");
|
|
@@ -884,7 +890,7 @@ function Ge(a) {
|
|
|
884
890
|
`, a.getAttribute("src"));
|
|
885
891
|
let t = null, e = null, r = null;
|
|
886
892
|
for (let o = a; o != null; o = Object.getPrototypeOf(o)) {
|
|
887
|
-
const i = Object.getOwnPropertySymbols(o), s = i.find((
|
|
893
|
+
const i = Object.getOwnPropertySymbols(o), s = i.find((u) => u.toString() == "Symbol(renderer)"), n = i.find((u) => u.toString() == "Symbol(scene)"), l = i.find((u) => u.toString() == "Symbol(needsRender)");
|
|
888
894
|
!t && s != null && (t = a[s].threeRenderer), !e && n != null && (e = a[n]), !r && l != null && (r = a[l]);
|
|
889
895
|
}
|
|
890
896
|
if (t && e) {
|
|
@@ -900,8 +906,8 @@ function Ge(a) {
|
|
|
900
906
|
}
|
|
901
907
|
};
|
|
902
908
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
903
|
-
const i =
|
|
904
|
-
return
|
|
909
|
+
const i = G.get(t, { engine: "model-viewer" });
|
|
910
|
+
return G.addPlugin(new at()), i.enable(), i.addEventListener("changed", () => {
|
|
905
911
|
r == null || r.call(a);
|
|
906
912
|
}), a.addEventListener("model-visibility", (s) => {
|
|
907
913
|
s.detail.visible && (r == null || r.call(a));
|
|
@@ -915,7 +921,7 @@ function Ge(a) {
|
|
|
915
921
|
}
|
|
916
922
|
class at {
|
|
917
923
|
constructor() {
|
|
918
|
-
|
|
924
|
+
f(this, "_didWarnAboutMissingUrl", !1);
|
|
919
925
|
}
|
|
920
926
|
onBeforeUpdateLOD(t, e, r, o) {
|
|
921
927
|
this.tryParseMeshLOD(e, o), this.tryParseTextureLOD(e, o);
|
|
@@ -939,25 +945,25 @@ class at {
|
|
|
939
945
|
const r = this.tryGetCurrentGLTF(t), o = this.tryGetCurrentModelViewer(t), i = this.getUrl(o);
|
|
940
946
|
if (i && r && e.material) {
|
|
941
947
|
let s = function(l) {
|
|
942
|
-
var c,
|
|
948
|
+
var c, D, h;
|
|
943
949
|
if (l[fe] == !0)
|
|
944
950
|
return;
|
|
945
951
|
l[fe] = !0, l.userData && (l.userData.LOD = -1);
|
|
946
|
-
const
|
|
947
|
-
for (let
|
|
948
|
-
const
|
|
949
|
-
if ((
|
|
950
|
-
const
|
|
951
|
-
if (
|
|
952
|
+
const u = Object.keys(l);
|
|
953
|
+
for (let d = 0; d < u.length; d++) {
|
|
954
|
+
const p = u[d], L = l[p];
|
|
955
|
+
if ((L == null ? void 0 : L.isTexture) === !0) {
|
|
956
|
+
const k = (D = (c = L.userData) == null ? void 0 : c.associations) == null ? void 0 : D.textures;
|
|
957
|
+
if (k == null)
|
|
952
958
|
continue;
|
|
953
|
-
const
|
|
954
|
-
if (
|
|
955
|
-
console.warn("Texture data not found for texture index " +
|
|
959
|
+
const $ = r.parser.json.textures[k];
|
|
960
|
+
if (!$) {
|
|
961
|
+
console.warn("Texture data not found for texture index " + k);
|
|
956
962
|
continue;
|
|
957
963
|
}
|
|
958
|
-
if ((
|
|
959
|
-
const
|
|
960
|
-
|
|
964
|
+
if ((h = $ == null ? void 0 : $.extensions) != null && h[U]) {
|
|
965
|
+
const m = $.extensions[U];
|
|
966
|
+
m && i && b.registerTexture(i, L, m.lods.length, k, m);
|
|
961
967
|
}
|
|
962
968
|
}
|
|
963
969
|
}
|
|
@@ -978,23 +984,23 @@ class at {
|
|
|
978
984
|
const r = this.tryGetCurrentModelViewer(t), o = this.getUrl(r);
|
|
979
985
|
if (!o)
|
|
980
986
|
return;
|
|
981
|
-
const i = (n = (s = e.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : n[
|
|
987
|
+
const i = (n = (s = e.userData) == null ? void 0 : s.gltfExtensions) == null ? void 0 : n[U];
|
|
982
988
|
if (i && o) {
|
|
983
989
|
const l = e.uuid;
|
|
984
|
-
|
|
990
|
+
b.registerMesh(o, l, e, 0, i.lods.length, i);
|
|
985
991
|
}
|
|
986
992
|
}
|
|
987
993
|
}
|
|
988
994
|
function mt(a, t, e, r) {
|
|
989
|
-
ke(t), Ie(e), e.register((i) => new
|
|
990
|
-
const o =
|
|
995
|
+
ke(t), Ie(e), e.register((i) => new b(i, a));
|
|
996
|
+
const o = G.get(t);
|
|
991
997
|
return (r == null ? void 0 : r.enableLODsManager) !== !1 && o.enable(), o;
|
|
992
998
|
}
|
|
993
999
|
Re();
|
|
994
1000
|
export {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1001
|
+
U as EXTENSION_NAME,
|
|
1002
|
+
G as LODsManager,
|
|
1003
|
+
b as NEEDLE_progressive,
|
|
998
1004
|
Be as VERSION,
|
|
999
1005
|
Ie as addDracoAndKTX2Loaders,
|
|
1000
1006
|
ke as createLoaders,
|