@needle-tools/gltf-progressive 1.0.0-alpha.11 → 1.0.0-alpha.13
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 +7 -0
- package/examples/modelviewer.html +27 -0
- package/examples/react-three-fiber/.prettierrc +10 -0
- package/examples/react-three-fiber/index.html +26 -0
- package/examples/react-three-fiber/package-lock.json +3587 -0
- package/examples/react-three-fiber/package.json +35 -0
- package/examples/react-three-fiber/tsconfig.json +22 -0
- package/examples/react-three-fiber/vite.config.js +44 -0
- package/examples/threejs/index.html +51 -0
- package/examples/threejs/main.js +76 -0
- package/gltf-progressive.js +189 -179
- package/gltf-progressive.min.js +3 -3
- package/gltf-progressive.umd.cjs +3 -3
- package/lib/extension.js +8 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/lods_manager.js +17 -5
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var le = Object.defineProperty;
|
|
2
2
|
var ue = (l, e, t) => e in l ? le(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
|
|
3
|
-
var
|
|
4
|
-
import { Mesh as q, BufferGeometry as
|
|
3
|
+
var c = (l, e, t) => (ue(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { Mesh as q, BufferGeometry as Y, Material as ce, Texture as I, TextureLoader as fe, Matrix4 as te, Frustum as de, Sphere as ge, Box3 as re, Vector3 as C } from "three";
|
|
5
5
|
import { GLTFLoader as he } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
6
6
|
import { MeshoptDecoder as pe } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
7
7
|
import { DRACOLoader as ye } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
@@ -16,12 +16,12 @@ function _e(l) {
|
|
|
16
16
|
function Be(l) {
|
|
17
17
|
j = l;
|
|
18
18
|
}
|
|
19
|
-
let
|
|
19
|
+
let U, J, W;
|
|
20
20
|
function ne(l) {
|
|
21
|
-
|
|
21
|
+
U || (U = new ye(), U.setDecoderPath(K), U.setDecoderConfig({ type: "js" })), W || (W = new me(), W.setTranscoderPath(j)), J || (J = pe), l ? W.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
|
|
22
22
|
}
|
|
23
23
|
function oe(l) {
|
|
24
|
-
l.dracoLoader || l.setDRACOLoader(
|
|
24
|
+
l.dracoLoader || l.setDRACOLoader(U), l.ktx2Loader || l.setKTX2Loader(W), l.meshoptDecoder || l.setMeshoptDecoder(J);
|
|
25
25
|
}
|
|
26
26
|
function ee(l) {
|
|
27
27
|
const t = new URL(window.location.href).searchParams.get(l);
|
|
@@ -40,18 +40,18 @@ function Le(l, e) {
|
|
|
40
40
|
return e;
|
|
41
41
|
}
|
|
42
42
|
const Q = new Array();
|
|
43
|
-
function
|
|
43
|
+
function ke(l) {
|
|
44
44
|
Q.push(l);
|
|
45
45
|
}
|
|
46
|
-
const
|
|
46
|
+
const R = "NEEDLE_progressive", S = ee("debugprogressive"), V = Symbol("needle-progressive-texture"), z = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Set();
|
|
47
47
|
if (S) {
|
|
48
48
|
let l = function() {
|
|
49
49
|
e += 1, console.log("Toggle LOD level", e, z), z.forEach((i, n) => {
|
|
50
50
|
for (const s of i.keys) {
|
|
51
51
|
const o = n[s];
|
|
52
52
|
if (o.isBufferGeometry === !0) {
|
|
53
|
-
const a = v.getMeshLODInformation(o),
|
|
54
|
-
n["DEBUG:LOD"] = e, v.assignMeshLOD(n,
|
|
53
|
+
const a = v.getMeshLODInformation(o), g = a ? Math.min(e, a.lods.length) : 0;
|
|
54
|
+
n["DEBUG:LOD"] = e, v.assignMeshLOD(n, g), a && (t = Math.max(t, a.lods.length - 1));
|
|
55
55
|
} else if (n.isMaterial === !0) {
|
|
56
56
|
n["DEBUG:LOD"] = e, v.assignTextureLOD(n, e);
|
|
57
57
|
break;
|
|
@@ -75,13 +75,13 @@ function se(l, e, t) {
|
|
|
75
75
|
}
|
|
76
76
|
const M = class {
|
|
77
77
|
constructor(e, t) {
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
c(this, "parser");
|
|
79
|
+
c(this, "url");
|
|
80
80
|
S && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
|
|
81
81
|
}
|
|
82
82
|
/** The name of the extension */
|
|
83
83
|
get name() {
|
|
84
|
-
return
|
|
84
|
+
return R;
|
|
85
85
|
}
|
|
86
86
|
static getMeshLODInformation(e) {
|
|
87
87
|
const t = this.getAssignedLODInformation(e);
|
|
@@ -146,7 +146,7 @@ const M = class {
|
|
|
146
146
|
const o = n.index || 0;
|
|
147
147
|
s = s[o];
|
|
148
148
|
}
|
|
149
|
-
s && i != s && s instanceof
|
|
149
|
+
s && i != s && s instanceof Y && (e.geometry = s, S && se(e, "geometry", n.url));
|
|
150
150
|
}
|
|
151
151
|
return s;
|
|
152
152
|
}).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
|
|
@@ -171,8 +171,8 @@ const M = class {
|
|
|
171
171
|
for (const o of Object.keys(s.uniforms)) {
|
|
172
172
|
const a = s.uniforms[o].value;
|
|
173
173
|
if ((a == null ? void 0 : a.isTexture) === !0) {
|
|
174
|
-
const
|
|
175
|
-
i.push(
|
|
174
|
+
const g = this.assignTextureLODForSlot(a, t, r, o);
|
|
175
|
+
i.push(g), n.push(o);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
} else
|
|
@@ -186,13 +186,13 @@ const M = class {
|
|
|
186
186
|
return Promise.all(i).then((s) => {
|
|
187
187
|
const o = new Array();
|
|
188
188
|
for (let a = 0; a < s.length; a++) {
|
|
189
|
-
const
|
|
190
|
-
|
|
189
|
+
const g = s[a], f = n[a];
|
|
190
|
+
g && g.isTexture === !0 ? o.push({ material: r, slot: f, texture: g, level: t }) : o.push({ material: r, slot: f, texture: null, level: t });
|
|
191
191
|
}
|
|
192
192
|
return o;
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
|
-
if (e instanceof
|
|
195
|
+
if (e instanceof I || e.isTexture === !0) {
|
|
196
196
|
const r = e;
|
|
197
197
|
return this.assignTextureLODForSlot(r, t, null, null);
|
|
198
198
|
}
|
|
@@ -217,7 +217,7 @@ const M = class {
|
|
|
217
217
|
var t, r;
|
|
218
218
|
return S && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, n) => {
|
|
219
219
|
if (i != null && i.extensions) {
|
|
220
|
-
const s = i == null ? void 0 : i.extensions[
|
|
220
|
+
const s = i == null ? void 0 : i.extensions[R];
|
|
221
221
|
if (s) {
|
|
222
222
|
let o = !1;
|
|
223
223
|
for (const a of this.parser.associations.keys())
|
|
@@ -229,7 +229,7 @@ const M = class {
|
|
|
229
229
|
}
|
|
230
230
|
}), (r = this.parser.json.meshes) == null || r.forEach((i, n) => {
|
|
231
231
|
if (i != null && i.extensions) {
|
|
232
|
-
const s = i == null ? void 0 : i.extensions[
|
|
232
|
+
const s = i == null ? void 0 : i.extensions[R];
|
|
233
233
|
if (s && s.lods) {
|
|
234
234
|
for (const o of this.parser.associations.keys())
|
|
235
235
|
if (o.isMesh) {
|
|
@@ -241,87 +241,87 @@ const M = class {
|
|
|
241
241
|
}), null;
|
|
242
242
|
}
|
|
243
243
|
static async getOrLoadLOD(e, t) {
|
|
244
|
-
var o, a,
|
|
244
|
+
var o, a, g;
|
|
245
245
|
const r = S == "verbose", i = e.userData.LODS;
|
|
246
246
|
if (!i)
|
|
247
247
|
return null;
|
|
248
248
|
const n = i == null ? void 0 : i.key;
|
|
249
249
|
let s;
|
|
250
250
|
if (e.isTexture === !0) {
|
|
251
|
-
const
|
|
252
|
-
|
|
251
|
+
const f = e;
|
|
252
|
+
f.source && f.source[V] && (s = f.source[V]);
|
|
253
253
|
}
|
|
254
254
|
if (s || (s = M.lodInfos.get(n)), s) {
|
|
255
255
|
if (t > 0) {
|
|
256
|
-
let
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
256
|
+
let u = !1;
|
|
257
|
+
const h = Array.isArray(s.lods);
|
|
258
|
+
if (h && t >= s.lods.length ? u = !0 : h || (u = !0), u)
|
|
259
259
|
return this.lowresCache.get(n);
|
|
260
260
|
}
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
261
|
+
const f = Array.isArray(s.lods) ? s.lods[t].path : s.lods;
|
|
262
|
+
if (!f)
|
|
263
263
|
return S && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
|
|
264
|
-
const
|
|
265
|
-
if (
|
|
264
|
+
const p = Le(i.url, f);
|
|
265
|
+
if (p.endsWith(".glb") || p.endsWith(".gltf")) {
|
|
266
266
|
if (!s.guid)
|
|
267
267
|
return console.warn("missing pointer for glb/gltf texture", s), null;
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
r && console.log(`LOD ${t} was already loading/loaded: ${
|
|
271
|
-
let
|
|
272
|
-
`,
|
|
273
|
-
if (
|
|
274
|
-
return
|
|
268
|
+
const u = p + "_" + s.guid, h = this.previouslyLoaded.get(u);
|
|
269
|
+
if (h !== void 0) {
|
|
270
|
+
r && console.log(`LOD ${t} was already loading/loaded: ${u}`);
|
|
271
|
+
let x = await h.catch((F) => (console.error(`Error loading LOD ${t} from ${p}
|
|
272
|
+
`, F), null)), k = !1;
|
|
273
|
+
if (x == null || (x instanceof I && e instanceof I ? (o = x.image) != null && o.data || (a = x.source) != null && a.data ? x = this.copySettings(e, x) : (k = !0, this.previouslyLoaded.delete(u)) : x instanceof Y && e instanceof Y && ((g = x.attributes.position) != null && g.array || (k = !0, this.previouslyLoaded.delete(u)))), !k)
|
|
274
|
+
return x;
|
|
275
275
|
}
|
|
276
|
-
const
|
|
277
|
-
const
|
|
278
|
-
oe(
|
|
279
|
-
let
|
|
280
|
-
if (
|
|
281
|
-
const
|
|
282
|
-
|
|
276
|
+
const D = s, A = new Promise(async (x, k) => {
|
|
277
|
+
const F = new he();
|
|
278
|
+
oe(F), S && (await new Promise((m) => setTimeout(m, 1e3)), r && console.warn("Start loading (delayed) " + p, D.guid));
|
|
279
|
+
let L = p;
|
|
280
|
+
if (D && Array.isArray(D.lods)) {
|
|
281
|
+
const m = D.lods[t];
|
|
282
|
+
m.hash && (L += "?v=" + m.hash);
|
|
283
283
|
}
|
|
284
|
-
const
|
|
285
|
-
`,
|
|
286
|
-
if (!
|
|
284
|
+
const y = await F.loadAsync(L).catch((m) => (console.error(`Error loading LOD ${t} from ${p}
|
|
285
|
+
`, m), null));
|
|
286
|
+
if (!y)
|
|
287
287
|
return null;
|
|
288
|
-
const T =
|
|
289
|
-
r && console.log("Loading finished " +
|
|
290
|
-
let
|
|
291
|
-
if (
|
|
292
|
-
let
|
|
293
|
-
for (const d of
|
|
288
|
+
const T = y.parser;
|
|
289
|
+
r && console.log("Loading finished " + p, D.guid);
|
|
290
|
+
let w = 0;
|
|
291
|
+
if (y.parser.json.textures) {
|
|
292
|
+
let m = !1;
|
|
293
|
+
for (const d of y.parser.json.textures) {
|
|
294
294
|
if (d != null && d.extensions) {
|
|
295
|
-
const O = d == null ? void 0 : d.extensions[
|
|
296
|
-
if (O != null && O.guid && O.guid ===
|
|
297
|
-
|
|
295
|
+
const O = d == null ? void 0 : d.extensions[R];
|
|
296
|
+
if (O != null && O.guid && O.guid === D.guid) {
|
|
297
|
+
m = !0;
|
|
298
298
|
break;
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
-
|
|
301
|
+
w++;
|
|
302
302
|
}
|
|
303
|
-
if (
|
|
304
|
-
let d = await T.getDependency("texture",
|
|
305
|
-
return r && console.log('change "' + e.name + '" → "' + d.name + '"',
|
|
303
|
+
if (m) {
|
|
304
|
+
let d = await T.getDependency("texture", w);
|
|
305
|
+
return r && console.log('change "' + e.name + '" → "' + d.name + '"', p, w, d, u), e instanceof I && (d = this.copySettings(e, d)), d && (d.guid = D.guid), x(d);
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
|
-
if (
|
|
309
|
-
let
|
|
310
|
-
for (const d of
|
|
308
|
+
if (w = 0, y.parser.json.meshes) {
|
|
309
|
+
let m = !1;
|
|
310
|
+
for (const d of y.parser.json.meshes) {
|
|
311
311
|
if (d != null && d.extensions) {
|
|
312
|
-
const O = d == null ? void 0 : d.extensions[
|
|
313
|
-
if (O != null && O.guid && O.guid ===
|
|
314
|
-
|
|
312
|
+
const O = d == null ? void 0 : d.extensions[R];
|
|
313
|
+
if (O != null && O.guid && O.guid === D.guid) {
|
|
314
|
+
m = !0;
|
|
315
315
|
break;
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
-
|
|
318
|
+
w++;
|
|
319
319
|
}
|
|
320
|
-
if (
|
|
321
|
-
const d = await T.getDependency("mesh",
|
|
322
|
-
if (r && console.log(`Loaded Mesh "${d.name}"`,
|
|
320
|
+
if (m) {
|
|
321
|
+
const d = await T.getDependency("mesh", w), O = D;
|
|
322
|
+
if (r && console.log(`Loaded Mesh "${d.name}"`, p, w, d, u), d.isMesh === !0) {
|
|
323
323
|
const P = d.geometry;
|
|
324
|
-
return M.assignLODInformation(i.url, P, n, t, void 0, O.density),
|
|
324
|
+
return M.assignLODInformation(i.url, P, n, t, void 0, O.density), x(P);
|
|
325
325
|
} else {
|
|
326
326
|
const P = new Array();
|
|
327
327
|
for (let _ = 0; _ < d.children.length; _++) {
|
|
@@ -331,17 +331,17 @@ const M = class {
|
|
|
331
331
|
M.assignLODInformation(i.url, N, n, t, _, O.density), P.push(N);
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
|
-
return
|
|
334
|
+
return x(P);
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
|
-
return
|
|
338
|
+
return x(null);
|
|
339
339
|
});
|
|
340
|
-
return this.previouslyLoaded.set(
|
|
341
|
-
} else if (e instanceof
|
|
342
|
-
r && console.log("Load texture from uri: " +
|
|
343
|
-
const
|
|
344
|
-
return
|
|
340
|
+
return this.previouslyLoaded.set(u, A), await A;
|
|
341
|
+
} else if (e instanceof I) {
|
|
342
|
+
r && console.log("Load texture from uri: " + p);
|
|
343
|
+
const h = await new fe().loadAsync(p);
|
|
344
|
+
return h ? (h.guid = s.guid, h.flipY = !1, h.needsUpdate = !0, h.colorSpace = e.colorSpace, r && console.log(s, h)) : S && console.warn("failed loading", p), h;
|
|
345
345
|
}
|
|
346
346
|
} else
|
|
347
347
|
S && console.warn(`Can not load LOD ${t}: no LOD info found for "${n}" ${e.name}`, e.type);
|
|
@@ -360,69 +360,69 @@ const M = class {
|
|
|
360
360
|
}
|
|
361
361
|
static copySettings(e, t) {
|
|
362
362
|
const r = this._copiedTextures.get(e);
|
|
363
|
-
return r || (t = t.clone(), this._copiedTextures.set(e, t), t.offset = e.offset, t.repeat = e.repeat, t.colorSpace = e.colorSpace, t);
|
|
363
|
+
return r || (t = t.clone(), this._copiedTextures.set(e, t), 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.generateMipmaps = e.generateMipmaps, t);
|
|
364
364
|
}
|
|
365
365
|
};
|
|
366
366
|
let v = M;
|
|
367
367
|
/**
|
|
368
368
|
* Register a texture with LOD information
|
|
369
369
|
*/
|
|
370
|
-
|
|
371
|
-
S && console.log("> Progressive: register texture", r, t.name, t.uuid, t, i), t.source && (t.source[
|
|
370
|
+
c(v, "registerTexture", (e, t, r, i) => {
|
|
371
|
+
S && console.log("> Progressive: register texture", r, t.name, t.uuid, t, i), t.source && (t.source[V] = i);
|
|
372
372
|
const n = i.guid;
|
|
373
373
|
M.assignLODInformation(e, t, n, 0, 0, void 0), M.lodInfos.set(n, i), M.lowresCache.set(n, t);
|
|
374
374
|
}), /**
|
|
375
375
|
* Register a mesh with LOD information
|
|
376
376
|
*/
|
|
377
|
-
|
|
378
|
-
var
|
|
377
|
+
c(v, "registerMesh", (e, t, r, i, n, s) => {
|
|
378
|
+
var g;
|
|
379
379
|
S && console.log("> Progressive: register mesh", n, r.name, s, r.uuid, r);
|
|
380
380
|
const o = r.geometry;
|
|
381
381
|
o.userData || (o.userData = {}), M.assignLODInformation(e, o, t, i, n, s.density), M.lodInfos.set(t, s);
|
|
382
382
|
let a = M.lowresCache.get(t);
|
|
383
383
|
a ? a.push(r.geometry) : a = [r.geometry], M.lowresCache.set(t, a);
|
|
384
|
-
for (const
|
|
385
|
-
(
|
|
384
|
+
for (const f of Q)
|
|
385
|
+
(g = f.onRegisteredNewMesh) == null || g.call(f, r, s);
|
|
386
386
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
387
|
+
c(v, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
388
|
+
c(v, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
389
|
+
c(v, "lowresCache", /* @__PURE__ */ new Map()), c(v, "_copiedTextures", /* @__PURE__ */ new Map());
|
|
390
390
|
class De {
|
|
391
391
|
constructor(e, t, r, i, n) {
|
|
392
|
-
|
|
392
|
+
c(this, "url");
|
|
393
393
|
/** the key to lookup the LOD information */
|
|
394
|
-
|
|
395
|
-
|
|
394
|
+
c(this, "key");
|
|
395
|
+
c(this, "level");
|
|
396
396
|
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
397
|
-
|
|
397
|
+
c(this, "index");
|
|
398
398
|
/** the mesh density */
|
|
399
|
-
|
|
399
|
+
c(this, "density");
|
|
400
400
|
this.url = e, this.key = t, this.level = r, i != null && (this.index = i), n != null && (this.density = n);
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
const H = ee("debugprogressive"), xe = ee("noprogressive"), b = class {
|
|
404
404
|
constructor(e) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
405
|
+
c(this, "renderer");
|
|
406
|
+
c(this, "projectionScreenMatrix", new te());
|
|
407
|
+
c(this, "cameraFrustrum", new de());
|
|
408
408
|
/**
|
|
409
409
|
* 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.
|
|
410
410
|
*/
|
|
411
|
-
|
|
411
|
+
c(this, "updateInterval", 0);
|
|
412
412
|
/**
|
|
413
413
|
* If set to true, the LODsManager will not update the LODs.
|
|
414
414
|
*/
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
415
|
+
c(this, "pause", !1);
|
|
416
|
+
c(this, "plugins", []);
|
|
417
|
+
c(this, "_frame", 0);
|
|
418
|
+
c(this, "_originalRender");
|
|
419
419
|
// private testIfLODLevelsAreAvailable() {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
420
|
+
c(this, "_sphere", new ge());
|
|
421
|
+
c(this, "_tempBox", new re());
|
|
422
|
+
c(this, "tempMatrix", new te());
|
|
423
|
+
c(this, "_tempWorldPosition", new C());
|
|
424
|
+
c(this, "_tempBoxSize", new C());
|
|
425
|
+
c(this, "_tempBox2Size", new C());
|
|
426
426
|
this.renderer = e;
|
|
427
427
|
}
|
|
428
428
|
/** @internal */
|
|
@@ -451,47 +451,55 @@ const H = ee("debugprogressive"), xe = ee("noprogressive"), b = class {
|
|
|
451
451
|
onBeforeRender(e, t, r, i) {
|
|
452
452
|
}
|
|
453
453
|
onAfterRender(e, t, r, i) {
|
|
454
|
-
var
|
|
455
|
-
if (
|
|
454
|
+
var a, g;
|
|
455
|
+
if (this.pause)
|
|
456
|
+
return;
|
|
457
|
+
const n = this.renderer.renderLists.get(e, 0), s = n.opaque;
|
|
458
|
+
let o = !0;
|
|
459
|
+
if (s.length === 1) {
|
|
460
|
+
const f = s[0].material;
|
|
461
|
+
(f.name === "EffectMaterial" || f.name === "CopyShader") && (o = !1);
|
|
462
|
+
}
|
|
463
|
+
if (o) {
|
|
456
464
|
if (xe || this.updateInterval > 0 && i % this.updateInterval != 0)
|
|
457
465
|
return;
|
|
458
466
|
this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
|
|
459
|
-
const
|
|
460
|
-
for (const
|
|
461
|
-
if (
|
|
462
|
-
H && (
|
|
467
|
+
const f = 1e5;
|
|
468
|
+
for (const u of s) {
|
|
469
|
+
if (u.material && (((a = u.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((g = u.geometry) == null ? void 0 : g.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
|
|
470
|
+
H && (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)));
|
|
463
471
|
continue;
|
|
464
472
|
}
|
|
465
|
-
const
|
|
466
|
-
(
|
|
473
|
+
const h = u.object;
|
|
474
|
+
(h instanceof q || h.isMesh) && this.updateLODs(e, t, h, f);
|
|
467
475
|
}
|
|
468
|
-
const
|
|
469
|
-
for (const
|
|
470
|
-
const
|
|
471
|
-
(
|
|
476
|
+
const p = n.transparent;
|
|
477
|
+
for (const u of p) {
|
|
478
|
+
const h = u.object;
|
|
479
|
+
(h instanceof q || h.isMesh) && this.updateLODs(e, t, h, f);
|
|
472
480
|
}
|
|
473
481
|
}
|
|
474
482
|
}
|
|
475
483
|
/** Update the LOD levels for the renderer. */
|
|
476
484
|
updateLODs(e, t, r, i) {
|
|
477
|
-
var a,
|
|
478
|
-
for (const
|
|
479
|
-
(a =
|
|
485
|
+
var a, g;
|
|
486
|
+
for (const f of this.plugins)
|
|
487
|
+
(a = f.onBeforeUpdateLOD) == null || a.call(f, this.renderer, e, t, r);
|
|
480
488
|
let n = r.userData.LOD_state;
|
|
481
489
|
n || (n = new we(), r.userData.LOD_state = n);
|
|
482
490
|
let s = this.calculateLodLevel(t, r, n, i);
|
|
483
491
|
s = Math.round(s), s >= 0 && this.loadProgressiveMeshes(r, s);
|
|
484
492
|
let o = 0;
|
|
485
493
|
if (r.material) {
|
|
486
|
-
const
|
|
487
|
-
if (
|
|
488
|
-
for (const
|
|
489
|
-
this.loadProgressiveTextures(
|
|
494
|
+
const f = r["DEBUG:LOD"];
|
|
495
|
+
if (f != null && (o = f), Array.isArray(r.material))
|
|
496
|
+
for (const p of r.material)
|
|
497
|
+
this.loadProgressiveTextures(p, o);
|
|
490
498
|
else
|
|
491
499
|
this.loadProgressiveTextures(r.material, o);
|
|
492
500
|
}
|
|
493
|
-
for (const
|
|
494
|
-
(
|
|
501
|
+
for (const f of this.plugins)
|
|
502
|
+
(g = f.onAfterUpdatedLOD) == null || g.call(f, this.renderer, e, t, r, s);
|
|
495
503
|
n.lastLodLevel = s;
|
|
496
504
|
}
|
|
497
505
|
/** Load progressive textures for the given material
|
|
@@ -526,49 +534,49 @@ const H = ee("debugprogressive"), xe = ee("noprogressive"), b = class {
|
|
|
526
534
|
if (e) {
|
|
527
535
|
if (H && t["DEBUG:LOD"] != null)
|
|
528
536
|
return t["DEBUG:LOD"];
|
|
529
|
-
const a = v.getMeshLODInformation(t.geometry),
|
|
530
|
-
if (!
|
|
537
|
+
const a = v.getMeshLODInformation(t.geometry), g = a == null ? void 0 : a.lods;
|
|
538
|
+
if (!g || g.length <= 0 || !((o = this.cameraFrustrum) != null && o.intersectsObject(t)))
|
|
531
539
|
return 99;
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
534
|
-
const
|
|
540
|
+
const f = t.geometry.boundingBox;
|
|
541
|
+
if (f && e.isPerspectiveCamera) {
|
|
542
|
+
const p = e;
|
|
535
543
|
if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
|
|
536
544
|
this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
|
|
537
|
-
const
|
|
538
|
-
if (this._sphere.containsPoint(
|
|
545
|
+
const L = e.getWorldPosition(this._tempWorldPosition);
|
|
546
|
+
if (this._sphere.containsPoint(L))
|
|
539
547
|
return 0;
|
|
540
548
|
}
|
|
541
|
-
if (this._tempBox.copy(
|
|
542
|
-
const
|
|
543
|
-
let T =
|
|
544
|
-
const O = 2, P = 1.5, _ = (
|
|
545
|
-
T = (T - _) * O + _,
|
|
546
|
-
const N = T < 0 &&
|
|
549
|
+
if (this._tempBox.copy(f), this._tempBox.applyMatrix4(t.matrixWorld), this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && p.fov > 70) {
|
|
550
|
+
const L = this._tempBox.min, y = this._tempBox.max;
|
|
551
|
+
let T = L.x, w = L.y, m = y.x, d = y.y;
|
|
552
|
+
const O = 2, P = 1.5, _ = (L.x + y.x) * 0.5, E = (L.y + y.y) * 0.5;
|
|
553
|
+
T = (T - _) * O + _, w = (w - E) * O + E, m = (m - _) * O + _, d = (d - E) * O + E;
|
|
554
|
+
const N = T < 0 && m > 0 ? 0 : Math.min(Math.abs(L.x), Math.abs(y.x)), ae = w < 0 && d > 0 ? 0 : Math.min(Math.abs(L.y), Math.abs(y.y)), X = Math.max(N, ae);
|
|
547
555
|
r.lastCentrality = (P - X) * (P - X) * (P - X);
|
|
548
556
|
} else
|
|
549
557
|
r.lastCentrality = 1;
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
const A =
|
|
555
|
-
if (Math.max(
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
const d = (
|
|
561
|
-
|
|
558
|
+
const u = this._tempBox.getSize(this._tempBoxSize);
|
|
559
|
+
u.multiplyScalar(0.5), screen.availHeight > 0 && u.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), u.x *= p.aspect;
|
|
560
|
+
const h = e.matrixWorldInverse, D = new re();
|
|
561
|
+
D.copy(f), D.applyMatrix4(t.matrixWorld), D.applyMatrix4(h);
|
|
562
|
+
const A = D.getSize(this._tempBox2Size), G = Math.max(A.x, A.y);
|
|
563
|
+
if (Math.max(u.x, u.y) != 0 && G != 0 && (u.z = A.z / Math.max(A.x, A.y) * Math.max(u.x, u.y)), r.lastScreenCoverage = Math.max(u.x, u.y, u.z), r.lastScreenspaceVolume.copy(u), r.lastScreenCoverage *= r.lastCentrality, H && b.debugDrawLine) {
|
|
564
|
+
const L = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
565
|
+
L.invert();
|
|
566
|
+
const y = b.corner0, T = b.corner1, w = b.corner2, m = b.corner3;
|
|
567
|
+
y.copy(this._tempBox.min), T.copy(this._tempBox.max), T.x = y.x, w.copy(this._tempBox.max), w.y = y.y, m.copy(this._tempBox.max);
|
|
568
|
+
const d = (y.z + m.z) * 0.5;
|
|
569
|
+
y.z = T.z = w.z = m.z = d, y.applyMatrix4(L), T.applyMatrix4(L), w.applyMatrix4(L), m.applyMatrix4(L), b.debugDrawLine(y, T, 255), b.debugDrawLine(y, w, 255), b.debugDrawLine(T, m, 255), b.debugDrawLine(w, m, 255);
|
|
562
570
|
}
|
|
563
|
-
let
|
|
564
|
-
if (
|
|
565
|
-
for (let
|
|
566
|
-
if (
|
|
567
|
-
|
|
571
|
+
let k = 999;
|
|
572
|
+
if (g && r.lastScreenCoverage > 0) {
|
|
573
|
+
for (let L = 0; L < g.length; L++)
|
|
574
|
+
if (g[L].density / r.lastScreenCoverage < i) {
|
|
575
|
+
k = L;
|
|
568
576
|
break;
|
|
569
577
|
}
|
|
570
578
|
}
|
|
571
|
-
|
|
579
|
+
k < s && (s = k);
|
|
572
580
|
}
|
|
573
581
|
}
|
|
574
582
|
return s;
|
|
@@ -577,13 +585,13 @@ const H = ee("debugprogressive"), xe = ee("noprogressive"), b = class {
|
|
|
577
585
|
let B = b;
|
|
578
586
|
/** 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.
|
|
579
587
|
*/
|
|
580
|
-
|
|
588
|
+
c(B, "debugDrawLine"), c(B, "corner0", new C()), c(B, "corner1", new C()), c(B, "corner2", new C()), c(B, "corner3", new C());
|
|
581
589
|
class we {
|
|
582
590
|
constructor() {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
591
|
+
c(this, "lastLodLevel", 0);
|
|
592
|
+
c(this, "lastScreenCoverage", 0);
|
|
593
|
+
c(this, "lastScreenspaceVolume", new C());
|
|
594
|
+
c(this, "lastCentrality", 0);
|
|
587
595
|
}
|
|
588
596
|
}
|
|
589
597
|
const ie = Symbol("NEEDLE_mesh_lod"), $ = Symbol("NEEDLE_texture_lod");
|
|
@@ -610,8 +618,8 @@ function Oe(l) {
|
|
|
610
618
|
}
|
|
611
619
|
class Me {
|
|
612
620
|
constructor(e) {
|
|
613
|
-
|
|
614
|
-
|
|
621
|
+
c(this, "modelviewer");
|
|
622
|
+
c(this, "_didWarnAboutMissingUrl", !1);
|
|
615
623
|
this.modelviewer = e;
|
|
616
624
|
}
|
|
617
625
|
onBeforeUpdateLOD(e, t, r, i) {
|
|
@@ -631,18 +639,18 @@ class Me {
|
|
|
631
639
|
const r = this.tryGetCurrentGLTF(e), i = this.getUrl();
|
|
632
640
|
if (i && r && t.material) {
|
|
633
641
|
let n = function(o) {
|
|
634
|
-
var
|
|
642
|
+
var g, f, p;
|
|
635
643
|
if (o[$] == !0)
|
|
636
644
|
return;
|
|
637
645
|
o[$] = !0, o.userData && (o.userData.LOD = -1);
|
|
638
646
|
const a = Object.keys(o);
|
|
639
|
-
for (let
|
|
640
|
-
const
|
|
641
|
-
if ((
|
|
642
|
-
const A = (
|
|
643
|
-
if ((
|
|
644
|
-
const
|
|
645
|
-
|
|
647
|
+
for (let u = 0; u < a.length; u++) {
|
|
648
|
+
const h = a[u], D = o[h];
|
|
649
|
+
if ((D == null ? void 0 : D.isTexture) === !0) {
|
|
650
|
+
const A = (f = (g = D.userData) == null ? void 0 : g.associations) == null ? void 0 : f.textures, G = r.parser.json.textures[A];
|
|
651
|
+
if ((p = G.extensions) != null && p[R]) {
|
|
652
|
+
const x = G.extensions[R];
|
|
653
|
+
x && i && v.registerTexture(i, D, x.lods.length, x);
|
|
646
654
|
}
|
|
647
655
|
}
|
|
648
656
|
}
|
|
@@ -663,14 +671,14 @@ class Me {
|
|
|
663
671
|
const r = this.getUrl();
|
|
664
672
|
if (!r)
|
|
665
673
|
return;
|
|
666
|
-
const i = (s = (n = t.userData) == null ? void 0 : n.gltfExtensions) == null ? void 0 : s[
|
|
674
|
+
const i = (s = (n = t.userData) == null ? void 0 : n.gltfExtensions) == null ? void 0 : s[R];
|
|
667
675
|
if (i && r) {
|
|
668
676
|
const o = t.uuid;
|
|
669
677
|
v.registerMesh(r, o, t, 0, i.lods.length, i);
|
|
670
678
|
}
|
|
671
679
|
}
|
|
672
680
|
}
|
|
673
|
-
function
|
|
681
|
+
function Ce(l, e, t, r) {
|
|
674
682
|
ne(e), oe(t), t.register((n) => new v(n, l));
|
|
675
683
|
const i = new B(e);
|
|
676
684
|
return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
|
|
@@ -679,12 +687,14 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
679
687
|
Oe(document.querySelector("model-viewer"));
|
|
680
688
|
});
|
|
681
689
|
export {
|
|
682
|
-
|
|
690
|
+
R as EXTENSION_NAME,
|
|
683
691
|
B as LODsManager,
|
|
684
692
|
v as NEEDLE_progressive,
|
|
693
|
+
oe as addDracoAndKTX2Loaders,
|
|
694
|
+
ne as createLoaders,
|
|
685
695
|
Oe as patchModelViewer,
|
|
686
|
-
|
|
696
|
+
ke as registerPlugin,
|
|
687
697
|
_e as setDracoDecoderLocation,
|
|
688
698
|
Be as setKTX2TranscoderLocation,
|
|
689
|
-
|
|
699
|
+
Ce as useNeedleProgressive
|
|
690
700
|
};
|