@needle-tools/gltf-progressive 1.2.1-alpha.1 → 1.2.1-alpha.3
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 -1
- package/README.md +3 -2
- package/gltf-progressive.js +258 -249
- package/gltf-progressive.min.js +4 -4
- package/gltf-progressive.umd.cjs +4 -4
- package/lib/extension.js +13 -6
- package/lib/index.d.ts +3 -3
- package/lib/index.js +8 -8
- package/lib/lods_manager.js +10 -1
- package/lib/plugins/modelviewer.js +0 -7
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var we = (l, e, t) => e in l ?
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
var De = Object.defineProperty;
|
|
2
|
+
var we = (l, e, t) => e in l ? De(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
|
|
3
|
+
var d = (l, e, t) => (we(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { BufferGeometry as ee, Mesh as N, Material as _e, Texture as K, TextureLoader as Oe, Matrix4 as de, Frustum as ve, Sphere as Se, Box3 as he, Vector3 as R } from "three";
|
|
5
|
+
import { GLTFLoader as Te } 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 Ae } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
8
|
+
import { KTX2Loader as Pe } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
9
9
|
let te = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", ue = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
10
10
|
fetch(te + "draco_decoder.js", { method: "head" }).catch((l) => {
|
|
11
11
|
te = "./include/draco/", ue = "./include/ktx2/";
|
|
@@ -17,10 +17,10 @@ function Ye(l) {
|
|
|
17
17
|
ue = l;
|
|
18
18
|
}
|
|
19
19
|
let Y, ae, V;
|
|
20
|
-
function xe(l) {
|
|
21
|
-
Y || (Y = new Oe(), Y.setDecoderPath(te), Y.setDecoderConfig({ type: "js" })), V || (V = new ve(), V.setTranscoderPath(ue)), ae || (ae = _e), l ? V.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
|
|
22
|
-
}
|
|
23
20
|
function me(l) {
|
|
21
|
+
Y || (Y = new Ae(), Y.setDecoderPath(te), Y.setDecoderConfig({ type: "js" })), V || (V = new Pe(), V.setTranscoderPath(ue)), ae || (ae = be), l ? V.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
|
|
22
|
+
}
|
|
23
|
+
function xe(l) {
|
|
24
24
|
l.dracoLoader || l.setDRACOLoader(Y), l.ktx2Loader || l.setKTX2Loader(V), l.meshoptDecoder || l.setMeshoptDecoder(ae);
|
|
25
25
|
}
|
|
26
26
|
function re(l) {
|
|
@@ -45,7 +45,7 @@ function Be() {
|
|
|
45
45
|
}
|
|
46
46
|
const le = Symbol("needle:raycast-mesh");
|
|
47
47
|
function fe(l) {
|
|
48
|
-
return (l == null ? void 0 : l[le]) instanceof
|
|
48
|
+
return (l == null ? void 0 : l[le]) instanceof ee ? l[le] : null;
|
|
49
49
|
}
|
|
50
50
|
function ke(l, e) {
|
|
51
51
|
if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !fe(l)) {
|
|
@@ -57,8 +57,8 @@ function Ve(l = !0) {
|
|
|
57
57
|
if (l) {
|
|
58
58
|
if (X)
|
|
59
59
|
return;
|
|
60
|
-
const e = X =
|
|
61
|
-
|
|
60
|
+
const e = X = N.prototype.raycast;
|
|
61
|
+
N.prototype.raycast = function(t, r) {
|
|
62
62
|
const i = this, o = fe(i);
|
|
63
63
|
let s;
|
|
64
64
|
o && i.isMesh && (s = i.geometry, i.geometry = o), e.call(this, t, r), s && (i.geometry = s);
|
|
@@ -66,20 +66,20 @@ function Ve(l = !0) {
|
|
|
66
66
|
} else {
|
|
67
67
|
if (!X)
|
|
68
68
|
return;
|
|
69
|
-
|
|
69
|
+
N.prototype.raycast = X, X = null;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
let X = null;
|
|
73
73
|
function Re(l) {
|
|
74
|
-
const e = new
|
|
74
|
+
const e = new ee();
|
|
75
75
|
for (const t in l.attributes)
|
|
76
76
|
e.setAttribute(t, l.getAttribute(t));
|
|
77
77
|
return e.setIndex(l.getIndex()), e;
|
|
78
78
|
}
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
79
|
+
const $ = new Array(), E = "NEEDLE_progressive", y = re("debugprogressive"), oe = Symbol("needle-progressive-texture"), H = /* @__PURE__ */ new Map(), ce = /* @__PURE__ */ new Set();
|
|
80
|
+
if (y) {
|
|
81
81
|
let l = function() {
|
|
82
|
-
e += 1, console.log("Toggle LOD level", e,
|
|
82
|
+
e += 1, console.log("Toggle LOD level", e, H), H.forEach((i, o) => {
|
|
83
83
|
for (const s of i.keys) {
|
|
84
84
|
const n = o[s];
|
|
85
85
|
if (n != null) {
|
|
@@ -102,29 +102,32 @@ if (L) {
|
|
|
102
102
|
}
|
|
103
103
|
function ge(l, e, t) {
|
|
104
104
|
var i;
|
|
105
|
-
if (!
|
|
105
|
+
if (!y)
|
|
106
106
|
return;
|
|
107
|
-
|
|
108
|
-
const r =
|
|
107
|
+
H.has(l) || H.set(l, { keys: [], sourceId: t });
|
|
108
|
+
const r = H.get(l);
|
|
109
109
|
((i = r == null ? void 0 : r.keys) == null ? void 0 : i.includes(e)) == !1 && r.keys.push(e);
|
|
110
110
|
}
|
|
111
|
-
const
|
|
111
|
+
const O = class {
|
|
112
112
|
constructor(e, t) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
d(this, "parser");
|
|
114
|
+
d(this, "url");
|
|
115
|
+
d(this, "_isLoadingMesh");
|
|
116
|
+
d(this, "loadMesh", (e) => {
|
|
117
117
|
var r, i;
|
|
118
118
|
if (this._isLoadingMesh)
|
|
119
119
|
return null;
|
|
120
|
-
const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[
|
|
121
|
-
return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((o) =>
|
|
120
|
+
const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[E];
|
|
121
|
+
return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((o) => {
|
|
122
|
+
var s;
|
|
123
|
+
return this._isLoadingMesh = !1, o && O.registerMesh(this.url, t.guid, o, (s = t.lods) == null ? void 0 : s.length, void 0, t), o;
|
|
124
|
+
})) : null;
|
|
122
125
|
});
|
|
123
|
-
|
|
126
|
+
y && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
|
|
124
127
|
}
|
|
125
128
|
/** The name of the extension */
|
|
126
129
|
get name() {
|
|
127
|
-
return
|
|
130
|
+
return E;
|
|
128
131
|
}
|
|
129
132
|
static getMeshLODInformation(e) {
|
|
130
133
|
const t = this.getAssignedLODInformation(e);
|
|
@@ -143,7 +146,7 @@ const w = class {
|
|
|
143
146
|
this.getMaterialMinMaxLODsCount(n, t);
|
|
144
147
|
return e[i] = t, t;
|
|
145
148
|
}
|
|
146
|
-
if (
|
|
149
|
+
if (y === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
|
|
147
150
|
const n = e;
|
|
148
151
|
for (const a of Object.keys(n.uniforms)) {
|
|
149
152
|
const h = n.uniforms[a].value;
|
|
@@ -158,12 +161,12 @@ const w = class {
|
|
|
158
161
|
function s(n, a) {
|
|
159
162
|
const h = r.getAssignedLODInformation(n);
|
|
160
163
|
if (h) {
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
a.min_count = Math.min(a.min_count,
|
|
164
|
-
for (let
|
|
165
|
-
const
|
|
166
|
-
|
|
164
|
+
const c = r.lodInfos.get(h.key);
|
|
165
|
+
if (c && c.lods) {
|
|
166
|
+
a.min_count = Math.min(a.min_count, c.lods.length), a.max_count = Math.max(a.max_count, c.lods.length);
|
|
167
|
+
for (let m = 0; m < c.lods.length; m++) {
|
|
168
|
+
const u = c.lods[m];
|
|
169
|
+
u.width && (a.lods[m] = a.lods[m] || { min_height: 1 / 0, max_height: 0 }, a.lods[m].min_height = Math.min(a.lods[m].min_height, u.height), a.lods[m].max_height = Math.max(a.lods[m].max_height, u.height));
|
|
167
170
|
}
|
|
168
171
|
}
|
|
169
172
|
}
|
|
@@ -222,24 +225,24 @@ const w = class {
|
|
|
222
225
|
var r;
|
|
223
226
|
if (!e)
|
|
224
227
|
return Promise.resolve(null);
|
|
225
|
-
if (e instanceof
|
|
228
|
+
if (e instanceof N || e.isMesh === !0) {
|
|
226
229
|
const i = e.geometry, o = this.getAssignedLODInformation(i);
|
|
227
230
|
if (!o)
|
|
228
231
|
return Promise.resolve(null);
|
|
229
|
-
for (const s of
|
|
232
|
+
for (const s of $)
|
|
230
233
|
(r = s.onBeforeGetLODMesh) == null || r.call(s, e, t);
|
|
231
|
-
return e["LOD:requested level"] = t,
|
|
234
|
+
return e["LOD:requested level"] = t, O.getOrLoadLOD(i, t).then((s) => {
|
|
232
235
|
if (e["LOD:requested level"] === t) {
|
|
233
236
|
if (delete e["LOD:requested level"], Array.isArray(s)) {
|
|
234
237
|
const n = o.index || 0;
|
|
235
238
|
s = s[n];
|
|
236
239
|
}
|
|
237
|
-
s && i != s && s
|
|
240
|
+
s && i != s && ((s == null ? void 0 : s.isBufferGeometry) ? (e.geometry = s, y && ge(e, "geometry", o.url)) : y && console.error("Invalid LOD geometry", s));
|
|
238
241
|
}
|
|
239
242
|
return s;
|
|
240
243
|
}).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
|
|
241
244
|
} else
|
|
242
|
-
|
|
245
|
+
y && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", e);
|
|
243
246
|
return Promise.resolve(null);
|
|
244
247
|
}
|
|
245
248
|
/** Load a different resolution of a texture (if available)
|
|
@@ -252,9 +255,9 @@ const w = class {
|
|
|
252
255
|
static assignTextureLOD(e, t = 0) {
|
|
253
256
|
if (!e)
|
|
254
257
|
return Promise.resolve(null);
|
|
255
|
-
if (e instanceof
|
|
258
|
+
if (e instanceof _e || e.isMaterial === !0) {
|
|
256
259
|
const r = e, i = [], o = new Array();
|
|
257
|
-
if (
|
|
260
|
+
if (y && ce.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
|
|
258
261
|
const s = r;
|
|
259
262
|
for (const n of Object.keys(s.uniforms)) {
|
|
260
263
|
const a = s.uniforms[n].value;
|
|
@@ -274,8 +277,8 @@ const w = class {
|
|
|
274
277
|
return Promise.all(i).then((s) => {
|
|
275
278
|
const n = new Array();
|
|
276
279
|
for (let a = 0; a < s.length; a++) {
|
|
277
|
-
const h = s[a],
|
|
278
|
-
h && h.isTexture === !0 ? n.push({ material: r, slot:
|
|
280
|
+
const h = s[a], c = o[a];
|
|
281
|
+
h && h.isTexture === !0 ? n.push({ material: r, slot: c, texture: h, level: t }) : n.push({ material: r, slot: c, texture: null, level: t });
|
|
279
282
|
}
|
|
280
283
|
return n;
|
|
281
284
|
});
|
|
@@ -287,7 +290,7 @@ const w = class {
|
|
|
287
290
|
return Promise.resolve(null);
|
|
288
291
|
}
|
|
289
292
|
static assignTextureLODForSlot(e, t, r, i) {
|
|
290
|
-
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) :
|
|
293
|
+
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) : O.getOrLoadLOD(e, t).then((o) => {
|
|
291
294
|
if (Array.isArray(o))
|
|
292
295
|
return null;
|
|
293
296
|
if ((o == null ? void 0 : o.isTexture) === !0) {
|
|
@@ -297,158 +300,161 @@ const w = class {
|
|
|
297
300
|
if (s) {
|
|
298
301
|
const n = this.getAssignedLODInformation(s);
|
|
299
302
|
if (n && (n == null ? void 0 : n.level) < t)
|
|
300
|
-
return
|
|
303
|
+
return y === "verbose" && console.warn("Assigned texture level is already higher: ", n.level, t, r, s, o), null;
|
|
301
304
|
}
|
|
302
305
|
r[i] = o;
|
|
303
306
|
}
|
|
304
|
-
if (
|
|
307
|
+
if (y && i && r) {
|
|
305
308
|
const s = this.getAssignedLODInformation(e);
|
|
306
309
|
s && ge(r, i, s.url);
|
|
307
310
|
}
|
|
308
311
|
}
|
|
309
312
|
return o;
|
|
310
313
|
} else
|
|
311
|
-
|
|
314
|
+
y == "verbose" && console.warn("No LOD found for", e, t);
|
|
312
315
|
return null;
|
|
313
316
|
}).catch((o) => (console.error("Error loading LOD", e, o), null));
|
|
314
317
|
}
|
|
315
318
|
afterRoot(e) {
|
|
316
319
|
var t, r;
|
|
317
|
-
return
|
|
320
|
+
return y && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, o) => {
|
|
321
|
+
var s;
|
|
318
322
|
if (i != null && i.extensions) {
|
|
319
|
-
const
|
|
320
|
-
if (
|
|
321
|
-
if (!
|
|
322
|
-
|
|
323
|
+
const n = i == null ? void 0 : i.extensions[E];
|
|
324
|
+
if (n) {
|
|
325
|
+
if (!n.lods) {
|
|
326
|
+
y && console.warn("Texture has no LODs", n);
|
|
323
327
|
return;
|
|
324
328
|
}
|
|
325
|
-
let
|
|
326
|
-
for (const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
329
|
+
let a = !1;
|
|
330
|
+
for (const h of this.parser.associations.keys())
|
|
331
|
+
h.isTexture === !0 && this.parser.associations.get(h).textures === o && (a = !0, O.registerTexture(this.url, h, (s = n.lods) == null ? void 0 : s.length, o, n));
|
|
332
|
+
a || this.parser.getDependency("texture", o).then((h) => {
|
|
333
|
+
var c;
|
|
334
|
+
h && O.registerTexture(this.url, h, (c = n.lods) == null ? void 0 : c.length, o, n);
|
|
330
335
|
});
|
|
331
336
|
}
|
|
332
337
|
}
|
|
333
338
|
}), (r = this.parser.json.meshes) == null || r.forEach((i, o) => {
|
|
334
339
|
if (i != null && i.extensions) {
|
|
335
|
-
const s = i == null ? void 0 : i.extensions[
|
|
340
|
+
const s = i == null ? void 0 : i.extensions[E];
|
|
336
341
|
if (s && s.lods) {
|
|
337
342
|
for (const n of this.parser.associations.keys())
|
|
338
343
|
if (n.isMesh) {
|
|
339
344
|
const a = this.parser.associations.get(n);
|
|
340
|
-
a.meshes === o &&
|
|
345
|
+
a.meshes === o && O.registerMesh(this.url, s.guid, n, s.lods.length, a.primitives, s);
|
|
341
346
|
}
|
|
342
347
|
}
|
|
343
348
|
}
|
|
344
349
|
}), null;
|
|
345
350
|
}
|
|
346
351
|
static async getOrLoadLOD(e, t) {
|
|
347
|
-
var n, a, h,
|
|
348
|
-
const r =
|
|
352
|
+
var n, a, h, c;
|
|
353
|
+
const r = y == "verbose", i = e.userData.LODS;
|
|
349
354
|
if (!i)
|
|
350
355
|
return null;
|
|
351
356
|
const o = i == null ? void 0 : i.key;
|
|
352
357
|
let s;
|
|
353
358
|
if (e.isTexture === !0) {
|
|
354
|
-
const
|
|
355
|
-
|
|
359
|
+
const m = e;
|
|
360
|
+
m.source && m.source[oe] && (s = m.source[oe]);
|
|
356
361
|
}
|
|
357
|
-
if (s || (s =
|
|
362
|
+
if (s || (s = O.lodInfos.get(o)), s) {
|
|
358
363
|
if (t > 0) {
|
|
359
364
|
let p = !1;
|
|
360
365
|
const x = Array.isArray(s.lods);
|
|
361
366
|
if (x && t >= s.lods.length ? p = !0 : x || (p = !0), p)
|
|
362
367
|
return this.lowresCache.get(o);
|
|
363
368
|
}
|
|
364
|
-
const
|
|
365
|
-
if (!
|
|
366
|
-
return
|
|
367
|
-
const
|
|
368
|
-
if (
|
|
369
|
+
const m = Array.isArray(s.lods) ? (n = s.lods[t]) == null ? void 0 : n.path : s.lods;
|
|
370
|
+
if (!m)
|
|
371
|
+
return y && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
|
|
372
|
+
const u = Ce(i.url, m);
|
|
373
|
+
if (u.endsWith(".glb") || u.endsWith(".gltf")) {
|
|
369
374
|
if (!s.guid)
|
|
370
375
|
return console.warn("missing pointer for glb/gltf texture", s), null;
|
|
371
|
-
const p =
|
|
376
|
+
const p = u + "_" + s.guid, x = this.previouslyLoaded.get(p);
|
|
372
377
|
if (x !== void 0) {
|
|
373
378
|
r && console.log(`LOD ${t} was already loading/loaded: ${p}`);
|
|
374
|
-
let
|
|
379
|
+
let _ = await x.catch((A) => (console.error(`Error loading LOD ${t} from ${u}
|
|
375
380
|
`, A), null)), b = !1;
|
|
376
|
-
if (
|
|
377
|
-
return
|
|
381
|
+
if (_ == null || (_ instanceof K && e instanceof K ? (a = _.image) != null && a.data || (h = _.source) != null && h.data ? _ = this.copySettings(e, _) : (b = !0, this.previouslyLoaded.delete(p)) : _ instanceof ee && e instanceof ee && ((c = _.attributes.position) != null && c.array || (b = !0, this.previouslyLoaded.delete(p)))), !b)
|
|
382
|
+
return _;
|
|
378
383
|
}
|
|
379
|
-
const
|
|
380
|
-
const A = new
|
|
381
|
-
|
|
382
|
-
let
|
|
383
|
-
if (
|
|
384
|
-
const g =
|
|
385
|
-
g.hash && (
|
|
384
|
+
const w = s, D = new Promise(async (_, b) => {
|
|
385
|
+
const A = new Te();
|
|
386
|
+
xe(A), y && (await new Promise((g) => setTimeout(g, 1e3)), r && console.warn("Start loading (delayed) " + u, w.guid));
|
|
387
|
+
let J = u;
|
|
388
|
+
if (w && Array.isArray(w.lods)) {
|
|
389
|
+
const g = w.lods[t];
|
|
390
|
+
g.hash && (J += "?v=" + g.hash);
|
|
386
391
|
}
|
|
387
|
-
const
|
|
392
|
+
const k = await A.loadAsync(J).catch((g) => (console.error(`Error loading LOD ${t} from ${u}
|
|
388
393
|
`, g), null));
|
|
389
|
-
if (!
|
|
394
|
+
if (!k)
|
|
390
395
|
return null;
|
|
391
|
-
const U =
|
|
392
|
-
r && console.log("Loading finished " +
|
|
393
|
-
let
|
|
394
|
-
if (
|
|
396
|
+
const U = k.parser;
|
|
397
|
+
r && console.log("Loading finished " + u, w.guid);
|
|
398
|
+
let I = 0;
|
|
399
|
+
if (k.parser.json.textures) {
|
|
395
400
|
let g = !1;
|
|
396
|
-
for (const
|
|
397
|
-
if (
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
401
|
+
for (const f of k.parser.json.textures) {
|
|
402
|
+
if (f != null && f.extensions) {
|
|
403
|
+
const L = f == null ? void 0 : f.extensions[E];
|
|
404
|
+
if (L != null && L.guid && L.guid === w.guid) {
|
|
400
405
|
g = !0;
|
|
401
406
|
break;
|
|
402
407
|
}
|
|
403
408
|
}
|
|
404
|
-
|
|
409
|
+
I++;
|
|
405
410
|
}
|
|
406
411
|
if (g) {
|
|
407
|
-
let
|
|
408
|
-
return
|
|
412
|
+
let f = await U.getDependency("texture", I);
|
|
413
|
+
return f && O.assignLODInformation(i.url, f, o, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + f.name + '"', u, I, f, p), e instanceof K && (f = this.copySettings(e, f)), f && (f.guid = w.guid), _(f);
|
|
409
414
|
} else
|
|
410
|
-
|
|
415
|
+
y && console.warn("Could not find texture with guid", w.guid, k.parser.json);
|
|
411
416
|
}
|
|
412
|
-
if (
|
|
417
|
+
if (I = 0, k.parser.json.meshes) {
|
|
413
418
|
let g = !1;
|
|
414
|
-
for (const
|
|
415
|
-
if (
|
|
416
|
-
const
|
|
417
|
-
if (
|
|
419
|
+
for (const f of k.parser.json.meshes) {
|
|
420
|
+
if (f != null && f.extensions) {
|
|
421
|
+
const L = f == null ? void 0 : f.extensions[E];
|
|
422
|
+
if (L != null && L.guid && L.guid === w.guid) {
|
|
418
423
|
g = !0;
|
|
419
424
|
break;
|
|
420
425
|
}
|
|
421
426
|
}
|
|
422
|
-
|
|
427
|
+
I++;
|
|
423
428
|
}
|
|
424
429
|
if (g) {
|
|
425
|
-
const
|
|
426
|
-
if (r && console.log(`Loaded Mesh "${
|
|
427
|
-
const S =
|
|
428
|
-
return
|
|
430
|
+
const f = await U.getDependency("mesh", I), L = w;
|
|
431
|
+
if (r && console.log(`Loaded Mesh "${f.name}"`, u, I, f, p), f.isMesh === !0) {
|
|
432
|
+
const S = f.geometry;
|
|
433
|
+
return O.assignLODInformation(i.url, S, o, t, void 0, L.density), _(S);
|
|
429
434
|
} else {
|
|
430
435
|
const S = new Array();
|
|
431
|
-
for (let T = 0; T <
|
|
432
|
-
const
|
|
433
|
-
if (
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
+
for (let T = 0; T < f.children.length; T++) {
|
|
437
|
+
const G = f.children[T];
|
|
438
|
+
if (G.isMesh === !0) {
|
|
439
|
+
const F = G.geometry;
|
|
440
|
+
O.assignLODInformation(i.url, F, o, t, T, L.density), S.push(F);
|
|
436
441
|
}
|
|
437
442
|
}
|
|
438
|
-
return
|
|
443
|
+
return _(S);
|
|
439
444
|
}
|
|
440
|
-
}
|
|
445
|
+
} else
|
|
446
|
+
y && console.warn("Could not find mesh with guid", w.guid, k.parser.json);
|
|
441
447
|
}
|
|
442
|
-
return
|
|
448
|
+
return _(null);
|
|
443
449
|
});
|
|
444
450
|
return this.previouslyLoaded.set(p, D), await D;
|
|
445
451
|
} else if (e instanceof K) {
|
|
446
|
-
r && console.log("Load texture from uri: " +
|
|
447
|
-
const x = await new
|
|
448
|
-
return x ? (x.guid = s.guid, x.flipY = !1, x.needsUpdate = !0, x.colorSpace = e.colorSpace, r && console.log(s, x)) :
|
|
452
|
+
r && console.log("Load texture from uri: " + u);
|
|
453
|
+
const x = await new Oe().loadAsync(u);
|
|
454
|
+
return x ? (x.guid = s.guid, x.flipY = !1, x.needsUpdate = !0, x.colorSpace = e.colorSpace, r && console.log(s, x)) : y && console.warn("failed loading", u), x;
|
|
449
455
|
}
|
|
450
456
|
} else
|
|
451
|
-
|
|
457
|
+
y && console.warn(`Can not load LOD ${t}: no LOD info found for "${o}" ${e.name}`, e.type);
|
|
452
458
|
return null;
|
|
453
459
|
}
|
|
454
460
|
static assignLODInformation(e, t, r, i, o, s) {
|
|
@@ -464,85 +470,85 @@ const w = class {
|
|
|
464
470
|
}
|
|
465
471
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
466
472
|
static copySettings(e, t) {
|
|
467
|
-
return t = t.clone(),
|
|
473
|
+
return t = t.clone(), y && console.warn(`Copying texture settings
|
|
468
474
|
`, e.uuid, `
|
|
469
475
|
`, 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;
|
|
470
476
|
}
|
|
471
477
|
};
|
|
472
|
-
let v =
|
|
478
|
+
let v = O;
|
|
473
479
|
/**
|
|
474
480
|
* Register a texture with LOD information
|
|
475
481
|
*/
|
|
476
|
-
|
|
477
|
-
if (
|
|
478
|
-
|
|
482
|
+
d(v, "registerTexture", (e, t, r, i, o) => {
|
|
483
|
+
if (y && console.log("> Progressive: register texture", i, t.name, t.uuid, t, o), !t) {
|
|
484
|
+
y && console.error("gltf-progressive: Register texture without texture");
|
|
479
485
|
return;
|
|
480
486
|
}
|
|
481
487
|
t.source && (t.source[oe] = o);
|
|
482
488
|
const s = o.guid;
|
|
483
|
-
|
|
489
|
+
O.assignLODInformation(e, t, s, r, i, void 0), O.lodInfos.set(s, o), O.lowresCache.set(s, t);
|
|
484
490
|
}), /**
|
|
485
491
|
* Register a mesh with LOD information
|
|
486
492
|
*/
|
|
487
|
-
|
|
493
|
+
d(v, "registerMesh", (e, t, r, i, o, s) => {
|
|
488
494
|
var h;
|
|
489
|
-
|
|
495
|
+
y && console.log("> Progressive: register mesh", o, r.name, s, r.uuid, r);
|
|
490
496
|
const n = r.geometry;
|
|
491
497
|
if (!n) {
|
|
492
|
-
|
|
498
|
+
y && console.warn("gltf-progressive: Register mesh without geometry");
|
|
493
499
|
return;
|
|
494
500
|
}
|
|
495
|
-
n.userData || (n.userData = {}),
|
|
496
|
-
let a =
|
|
497
|
-
a ? a.push(r.geometry) : a = [r.geometry],
|
|
498
|
-
for (const
|
|
499
|
-
(h =
|
|
501
|
+
n.userData || (n.userData = {}), O.assignLODInformation(e, n, t, i, o, s.density), O.lodInfos.set(t, s);
|
|
502
|
+
let a = O.lowresCache.get(t);
|
|
503
|
+
a ? a.push(r.geometry) : a = [r.geometry], O.lowresCache.set(t, a), i > 0 && !fe(r) && ke(r, n);
|
|
504
|
+
for (const c of $)
|
|
505
|
+
(h = c.onRegisteredNewMesh) == null || h.call(c, r, s);
|
|
500
506
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
507
|
+
d(v, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
508
|
+
d(v, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
509
|
+
d(v, "lowresCache", /* @__PURE__ */ new Map());
|
|
504
510
|
class Ee {
|
|
505
511
|
constructor(e, t, r, i, o) {
|
|
506
|
-
|
|
512
|
+
d(this, "url");
|
|
507
513
|
/** the key to lookup the LOD information */
|
|
508
|
-
|
|
509
|
-
|
|
514
|
+
d(this, "key");
|
|
515
|
+
d(this, "level");
|
|
510
516
|
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
511
|
-
|
|
517
|
+
d(this, "index");
|
|
512
518
|
/** the mesh density */
|
|
513
|
-
|
|
519
|
+
d(this, "density");
|
|
514
520
|
this.url = e, this.key = t, this.level = r, i != null && (this.index = i), o != null && (this.density = o);
|
|
515
521
|
}
|
|
516
522
|
}
|
|
517
|
-
const
|
|
523
|
+
const z = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:LODSManager"), ne = Symbol("Needle:LODState"), W = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 }, P = class {
|
|
518
524
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
519
525
|
constructor(e) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
526
|
+
d(this, "renderer");
|
|
527
|
+
d(this, "projectionScreenMatrix", new de());
|
|
528
|
+
d(this, "cameraFrustrum", new ve());
|
|
523
529
|
/**
|
|
524
530
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
525
531
|
* @default 200_000
|
|
526
532
|
*/
|
|
527
|
-
|
|
533
|
+
d(this, "targetTriangleDensity", 2e5);
|
|
528
534
|
/**
|
|
529
535
|
* 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.
|
|
530
536
|
*/
|
|
531
|
-
|
|
537
|
+
d(this, "updateInterval", 0);
|
|
532
538
|
/**
|
|
533
539
|
* If set to true, the LODsManager will not update the LODs.
|
|
534
540
|
*/
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
541
|
+
d(this, "pause", !1);
|
|
542
|
+
d(this, "_frame", 0);
|
|
543
|
+
d(this, "_originalRender");
|
|
538
544
|
// private testIfLODLevelsAreAvailable() {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
545
|
+
d(this, "_sphere", new Se());
|
|
546
|
+
d(this, "_tempBox", new he());
|
|
547
|
+
d(this, "_tempBox2", new he());
|
|
548
|
+
d(this, "tempMatrix", new de());
|
|
549
|
+
d(this, "_tempWorldPosition", new R());
|
|
550
|
+
d(this, "_tempBoxSize", new R());
|
|
551
|
+
d(this, "_tempBox2Size", new R());
|
|
546
552
|
this.renderer = e;
|
|
547
553
|
}
|
|
548
554
|
/** @internal */
|
|
@@ -550,11 +556,11 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
550
556
|
return e[ne];
|
|
551
557
|
}
|
|
552
558
|
static addPlugin(e) {
|
|
553
|
-
|
|
559
|
+
$.push(e);
|
|
554
560
|
}
|
|
555
561
|
static removePlugin(e) {
|
|
556
|
-
const t =
|
|
557
|
-
t >= 0 &&
|
|
562
|
+
const t = $.indexOf(e);
|
|
563
|
+
t >= 0 && $.splice(t, 1);
|
|
558
564
|
}
|
|
559
565
|
/**
|
|
560
566
|
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
@@ -566,7 +572,7 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
566
572
|
}
|
|
567
573
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
568
574
|
get plugins() {
|
|
569
|
-
return
|
|
575
|
+
return $;
|
|
570
576
|
}
|
|
571
577
|
/**
|
|
572
578
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
@@ -577,7 +583,7 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
577
583
|
let e = 0;
|
|
578
584
|
this._originalRender = this.renderer.render;
|
|
579
585
|
const t = this;
|
|
580
|
-
|
|
586
|
+
me(this.renderer), this.renderer.render = function(r, i) {
|
|
581
587
|
t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
|
|
582
588
|
const s = t._frame, n = e++;
|
|
583
589
|
t.onBeforeRender(r, i, n, s), t._originalRender.call(this, r, i), t.onAfterRender(r, i, n, s);
|
|
@@ -595,20 +601,20 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
595
601
|
const o = this.renderer.renderLists.get(e, 0), s = o.opaque;
|
|
596
602
|
let n = !0;
|
|
597
603
|
if (s.length === 1) {
|
|
598
|
-
const
|
|
599
|
-
(
|
|
604
|
+
const c = s[0].material;
|
|
605
|
+
(c.name === "EffectMaterial" || c.name === "CopyShader") && (n = !1);
|
|
600
606
|
}
|
|
601
607
|
if ((t.parent && t.parent.type === "CubeCamera" || r >= 1 && t.type === "OrthographicCamera") && (n = !1), n) {
|
|
602
608
|
if (Ie || this.updateInterval > 0 && i % this.updateInterval != 0)
|
|
603
609
|
return;
|
|
604
610
|
this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
|
|
605
|
-
const
|
|
606
|
-
for (const
|
|
607
|
-
if (
|
|
608
|
-
|
|
611
|
+
const c = this.targetTriangleDensity;
|
|
612
|
+
for (const u of s) {
|
|
613
|
+
if (u.material && (((a = u.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((h = u.geometry) == null ? void 0 : h.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
|
|
614
|
+
z && (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)));
|
|
609
615
|
continue;
|
|
610
616
|
}
|
|
611
|
-
switch (
|
|
617
|
+
switch (u.material.type) {
|
|
612
618
|
case "LineBasicMaterial":
|
|
613
619
|
case "LineDashedMaterial":
|
|
614
620
|
case "PointsMaterial":
|
|
@@ -617,13 +623,13 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
617
623
|
case "MeshDepthMaterial":
|
|
618
624
|
continue;
|
|
619
625
|
}
|
|
620
|
-
const p =
|
|
621
|
-
(p instanceof
|
|
626
|
+
const p = u.object;
|
|
627
|
+
(p instanceof N || p.isMesh) && this.updateLODs(e, t, p, c, i);
|
|
622
628
|
}
|
|
623
|
-
const
|
|
624
|
-
for (const
|
|
625
|
-
const p =
|
|
626
|
-
(p instanceof
|
|
629
|
+
const m = o.transparent;
|
|
630
|
+
for (const u of m) {
|
|
631
|
+
const p = u.object;
|
|
632
|
+
(p instanceof N || p.isMesh) && this.updateLODs(e, t, p, c, i);
|
|
627
633
|
}
|
|
628
634
|
}
|
|
629
635
|
}
|
|
@@ -634,16 +640,16 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
634
640
|
let s = r[ne];
|
|
635
641
|
if (s || (s = new Ge(), r[ne] = s), s.frames++ < 2)
|
|
636
642
|
return;
|
|
637
|
-
for (const
|
|
638
|
-
(a =
|
|
643
|
+
for (const c of $)
|
|
644
|
+
(a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, e, t, r);
|
|
639
645
|
this.calculateLodLevel(t, r, s, i, 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);
|
|
640
646
|
let n = C.texture_lod;
|
|
641
647
|
if (r.material && n >= 0) {
|
|
642
|
-
const
|
|
643
|
-
|
|
648
|
+
const c = r["DEBUG:LOD"];
|
|
649
|
+
c != null && (n = c), this.loadProgressiveTextures(r.material, n);
|
|
644
650
|
}
|
|
645
|
-
for (const
|
|
646
|
-
(h =
|
|
651
|
+
for (const c of $)
|
|
652
|
+
(h = c.onAfterUpdatedLOD) == null || h.call(c, this.renderer, e, t, r, C);
|
|
647
653
|
s.lastLodLevel_Mesh = C.mesh_lod, s.lastLodLevel_Texture = C.texture_lod;
|
|
648
654
|
}
|
|
649
655
|
/** Load progressive textures for the given material
|
|
@@ -683,7 +689,7 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
683
689
|
return this._tempPtInside.set(o, s, r.z).applyMatrix4(t).z < 0;
|
|
684
690
|
}
|
|
685
691
|
calculateLodLevel(e, t, r, i, o) {
|
|
686
|
-
var
|
|
692
|
+
var w;
|
|
687
693
|
if (!t) {
|
|
688
694
|
o.mesh_lod = -1, o.texture_lod = -1;
|
|
689
695
|
return;
|
|
@@ -693,14 +699,14 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
693
699
|
return;
|
|
694
700
|
}
|
|
695
701
|
let n = 10 + 1, a = !1;
|
|
696
|
-
if (
|
|
702
|
+
if (z && t["DEBUG:LOD"] != null)
|
|
697
703
|
return t["DEBUG:LOD"];
|
|
698
|
-
const h = v.getMeshLODInformation(t.geometry),
|
|
699
|
-
if (!
|
|
704
|
+
const h = v.getMeshLODInformation(t.geometry), c = h == null ? void 0 : h.lods, m = c && c.length > 0, u = v.getMaterialMinMaxLODsCount(t.material), p = (u == null ? void 0 : u.min_count) != 1 / 0 && u.min_count > 0 && u.max_count > 0;
|
|
705
|
+
if (!m && !p) {
|
|
700
706
|
o.mesh_lod = 0, o.texture_lod = 0;
|
|
701
707
|
return;
|
|
702
708
|
}
|
|
703
|
-
if (
|
|
709
|
+
if (m || (a = !0, n = 0), !((w = this.cameraFrustrum) != null && w.intersectsObject(t))) {
|
|
704
710
|
o.mesh_lod = 99, o.texture_lod = 99;
|
|
705
711
|
return;
|
|
706
712
|
}
|
|
@@ -724,49 +730,53 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
724
730
|
return;
|
|
725
731
|
}
|
|
726
732
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && D.fov > 70) {
|
|
727
|
-
const g = this._tempBox.min,
|
|
728
|
-
let
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
const Le =
|
|
733
|
+
const g = this._tempBox.min, f = this._tempBox.max;
|
|
734
|
+
let L = g.x, S = g.y, T = f.x, G = f.y;
|
|
735
|
+
const F = 2, se = 1.5, Q = (g.x + f.x) * 0.5, Z = (g.y + f.y) * 0.5;
|
|
736
|
+
L = (L - Q) * F + Q, S = (S - Z) * F + Z, T = (T - Q) * F + Q, G = (G - Z) * F + Z;
|
|
737
|
+
const Le = L < 0 && T > 0 ? 0 : Math.min(Math.abs(g.x), Math.abs(f.x)), Me = S < 0 && G > 0 ? 0 : Math.min(Math.abs(g.y), Math.abs(f.y)), ie = Math.max(Le, Me);
|
|
732
738
|
r.lastCentrality = (se - ie) * (se - ie) * (se - ie);
|
|
733
739
|
} else
|
|
734
740
|
r.lastCentrality = 1;
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
const
|
|
738
|
-
b.copy(x), b.applyMatrix4(t.matrixWorld), b.applyMatrix4(
|
|
739
|
-
const A = b.getSize(this._tempBox2Size),
|
|
740
|
-
if (Math.max(
|
|
741
|
+
const M = this._tempBox.getSize(this._tempBoxSize);
|
|
742
|
+
M.multiplyScalar(0.5), screen.availHeight > 0 && M.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), M.x *= D.aspect;
|
|
743
|
+
const _ = e.matrixWorldInverse, b = this._tempBox2;
|
|
744
|
+
b.copy(x), b.applyMatrix4(t.matrixWorld), b.applyMatrix4(_);
|
|
745
|
+
const A = b.getSize(this._tempBox2Size), J = Math.max(A.x, A.y);
|
|
746
|
+
if (Math.max(M.x, M.y) != 0 && J != 0 && (M.z = A.z / Math.max(A.x, A.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, z && P.debugDrawLine) {
|
|
741
747
|
const g = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
742
748
|
g.invert();
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
const
|
|
746
|
-
|
|
749
|
+
const f = P.corner0, L = P.corner1, S = P.corner2, T = P.corner3;
|
|
750
|
+
f.copy(this._tempBox.min), L.copy(this._tempBox.max), L.x = f.x, S.copy(this._tempBox.max), S.y = f.y, T.copy(this._tempBox.max);
|
|
751
|
+
const G = (f.z + T.z) * 0.5;
|
|
752
|
+
f.z = L.z = S.z = T.z = G, f.applyMatrix4(g), L.applyMatrix4(g), S.applyMatrix4(g), T.applyMatrix4(g), P.debugDrawLine(f, L, 255), P.debugDrawLine(f, S, 255), P.debugDrawLine(L, T, 255), P.debugDrawLine(S, T, 255);
|
|
747
753
|
}
|
|
748
754
|
let U = 999;
|
|
749
|
-
if (
|
|
750
|
-
for (let g = 0; g <
|
|
751
|
-
if (
|
|
755
|
+
if (c && r.lastScreenCoverage > 0) {
|
|
756
|
+
for (let g = 0; g < c.length; g++)
|
|
757
|
+
if (c[g].density / r.lastScreenCoverage < i) {
|
|
752
758
|
U = g;
|
|
753
759
|
break;
|
|
754
760
|
}
|
|
755
761
|
}
|
|
756
762
|
U < n && (n = U, a = !0);
|
|
757
763
|
}
|
|
758
|
-
if (a ? o.mesh_lod = n : o.mesh_lod = r.lastLodLevel_Mesh,
|
|
764
|
+
if (a ? o.mesh_lod = n : o.mesh_lod = r.lastLodLevel_Mesh, z && o.mesh_lod != r.lastLodLevel_Mesh) {
|
|
765
|
+
const M = c == null ? void 0 : c[o.mesh_lod];
|
|
766
|
+
M && console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} → ${o.mesh_lod} (${M.density.toFixed(0)}) - ${t.name}`);
|
|
767
|
+
}
|
|
768
|
+
if (p)
|
|
759
769
|
if (r.lastLodLevel_Texture < 0) {
|
|
760
|
-
if (o.texture_lod =
|
|
761
|
-
const D =
|
|
762
|
-
|
|
770
|
+
if (o.texture_lod = u.max_count - 1, z) {
|
|
771
|
+
const D = u.lods[u.max_count - 1];
|
|
772
|
+
z && console.log(`First Texture LOD ${o.texture_lod} (${D.max_height}px) - ${t.name}`);
|
|
763
773
|
}
|
|
764
774
|
} else {
|
|
765
|
-
const D = r.lastScreenCoverage * 1.5,
|
|
766
|
-
for (let b =
|
|
767
|
-
const A =
|
|
768
|
-
if (!(Be() && A.max_height > 4096) && A.max_height >
|
|
769
|
-
o.texture_lod = b, o.texture_lod < r.lastLodLevel_Texture &&
|
|
775
|
+
const D = r.lastScreenCoverage * 1.5, _ = this.renderer.domElement.clientHeight / window.devicePixelRatio * D;
|
|
776
|
+
for (let b = u.lods.length - 1; b >= 0; b--) {
|
|
777
|
+
const A = u.lods[b];
|
|
778
|
+
if (!(Be() && A.max_height > 4096) && A.max_height > _) {
|
|
779
|
+
o.texture_lod = b, o.texture_lod < r.lastLodLevel_Texture && z && console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} → ${o.texture_lod} (${A.max_height}px: ${(100 * r.lastScreenCoverage).toFixed(2)} % = ${_.toFixed(0)}px) - ${t.name}`);
|
|
770
780
|
break;
|
|
771
781
|
}
|
|
772
782
|
}
|
|
@@ -778,19 +788,19 @@ const N = re("debugprogressive"), Ie = re("noprogressive"), pe = Symbol("Needle:
|
|
|
778
788
|
let B = P;
|
|
779
789
|
/** 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.
|
|
780
790
|
*/
|
|
781
|
-
|
|
791
|
+
d(B, "debugDrawLine"), d(B, "corner0", new R()), d(B, "corner1", new R()), d(B, "corner2", new R()), d(B, "corner3", new R()), d(B, "_tempPtInside", new R());
|
|
782
792
|
class Ge {
|
|
783
793
|
constructor() {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
794
|
+
d(this, "frames", 0);
|
|
795
|
+
d(this, "lastLodLevel_Mesh", -1);
|
|
796
|
+
d(this, "lastLodLevel_Texture", -1);
|
|
797
|
+
d(this, "lastScreenCoverage", 0);
|
|
798
|
+
d(this, "lastScreenspaceVolume", new R());
|
|
799
|
+
d(this, "lastCentrality", 0);
|
|
790
800
|
}
|
|
791
801
|
}
|
|
792
|
-
const ye = Symbol("NEEDLE_mesh_lod"),
|
|
793
|
-
function
|
|
802
|
+
const ye = Symbol("NEEDLE_mesh_lod"), j = Symbol("NEEDLE_texture_lod");
|
|
803
|
+
function $e(l) {
|
|
794
804
|
if (!l)
|
|
795
805
|
return null;
|
|
796
806
|
let e = null, t = null;
|
|
@@ -799,9 +809,8 @@ function Fe(l) {
|
|
|
799
809
|
!e && o != null && (e = l[o].threeRenderer), !t && s != null && (t = l[s]);
|
|
800
810
|
}
|
|
801
811
|
if (e) {
|
|
802
|
-
console.log("Adding Needle LODs to modelviewer");
|
|
803
812
|
const r = B.get(e);
|
|
804
|
-
if (B.addPlugin(new
|
|
813
|
+
if (B.addPlugin(new Fe(l)), r.enable(), t) {
|
|
805
814
|
const i = t.camera || t.traverse((o) => o.type == "PerspectiveCamera")[0];
|
|
806
815
|
i && e.render(t, i);
|
|
807
816
|
}
|
|
@@ -811,10 +820,10 @@ function Fe(l) {
|
|
|
811
820
|
}
|
|
812
821
|
return null;
|
|
813
822
|
}
|
|
814
|
-
class
|
|
823
|
+
class Fe {
|
|
815
824
|
constructor(e) {
|
|
816
|
-
|
|
817
|
-
|
|
825
|
+
d(this, "modelviewer");
|
|
826
|
+
d(this, "_didWarnAboutMissingUrl", !1);
|
|
818
827
|
this.modelviewer = e;
|
|
819
828
|
}
|
|
820
829
|
onBeforeUpdateLOD(e, t, r, i) {
|
|
@@ -828,28 +837,28 @@ class $e {
|
|
|
828
837
|
return e._currentGLTF;
|
|
829
838
|
}
|
|
830
839
|
tryParseTextureLOD(e, t) {
|
|
831
|
-
if (t[
|
|
840
|
+
if (t[j] == !0)
|
|
832
841
|
return;
|
|
833
|
-
t[
|
|
842
|
+
t[j] = !0;
|
|
834
843
|
const r = this.tryGetCurrentGLTF(e), i = this.getUrl();
|
|
835
844
|
if (i && r && t.material) {
|
|
836
845
|
let o = function(n) {
|
|
837
|
-
var h,
|
|
838
|
-
if (n[
|
|
846
|
+
var h, c, m;
|
|
847
|
+
if (n[j] == !0)
|
|
839
848
|
return;
|
|
840
|
-
n[
|
|
849
|
+
n[j] = !0, n.userData && (n.userData.LOD = -1);
|
|
841
850
|
const a = Object.keys(n);
|
|
842
|
-
for (let
|
|
843
|
-
const p = a[
|
|
851
|
+
for (let u = 0; u < a.length; u++) {
|
|
852
|
+
const p = a[u], x = n[p];
|
|
844
853
|
if ((x == null ? void 0 : x.isTexture) === !0) {
|
|
845
|
-
const
|
|
854
|
+
const w = (c = (h = x.userData) == null ? void 0 : h.associations) == null ? void 0 : c.textures, D = r.parser.json.textures[w];
|
|
846
855
|
if (!D) {
|
|
847
|
-
console.warn("Texture data not found for texture index " +
|
|
856
|
+
console.warn("Texture data not found for texture index " + w);
|
|
848
857
|
continue;
|
|
849
858
|
}
|
|
850
|
-
if ((
|
|
851
|
-
const
|
|
852
|
-
|
|
859
|
+
if ((m = D == null ? void 0 : D.extensions) != null && m[E]) {
|
|
860
|
+
const M = D.extensions[E];
|
|
861
|
+
M && i && v.registerTexture(i, x, M.lods.length, w, M);
|
|
853
862
|
}
|
|
854
863
|
}
|
|
855
864
|
}
|
|
@@ -870,29 +879,29 @@ class $e {
|
|
|
870
879
|
const r = this.getUrl();
|
|
871
880
|
if (!r)
|
|
872
881
|
return;
|
|
873
|
-
const i = (s = (o = t.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : s[
|
|
882
|
+
const i = (s = (o = t.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : s[E];
|
|
874
883
|
if (i && r) {
|
|
875
884
|
const n = t.uuid;
|
|
876
885
|
v.registerMesh(r, n, t, 0, i.lods.length, i);
|
|
877
886
|
}
|
|
878
887
|
}
|
|
879
888
|
}
|
|
889
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
890
|
+
$e(document.querySelector("model-viewer"));
|
|
891
|
+
});
|
|
880
892
|
function He(l, e, t, r) {
|
|
881
|
-
|
|
893
|
+
me(e), xe(t), t.register((o) => new v(o, l));
|
|
882
894
|
const i = B.get(e);
|
|
883
895
|
return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
|
|
884
896
|
}
|
|
885
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
886
|
-
Fe(document.querySelector("model-viewer"));
|
|
887
|
-
});
|
|
888
897
|
export {
|
|
889
|
-
|
|
898
|
+
E as EXTENSION_NAME,
|
|
890
899
|
B as LODsManager,
|
|
891
900
|
v as NEEDLE_progressive,
|
|
892
|
-
|
|
893
|
-
|
|
901
|
+
xe as addDracoAndKTX2Loaders,
|
|
902
|
+
me as createLoaders,
|
|
894
903
|
fe as getRaycastMesh,
|
|
895
|
-
|
|
904
|
+
$e as patchModelViewer,
|
|
896
905
|
Xe as setDracoDecoderLocation,
|
|
897
906
|
Ye as setKTX2TranscoderLocation,
|
|
898
907
|
ke as setRaycastMesh,
|