@needle-tools/engine 4.1.0-beta → 4.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/components.needle.json +1 -1
- package/dist/gltf-progressive.js +103 -102
- package/dist/gltf-progressive.light.js +103 -102
- package/dist/gltf-progressive.light.min.js +6 -6
- package/dist/gltf-progressive.light.umd.cjs +6 -6
- package/dist/gltf-progressive.min.js +6 -6
- package/dist/gltf-progressive.umd.cjs +6 -6
- package/dist/needle-engine.bundle.js +7820 -7561
- package/dist/needle-engine.bundle.light.js +7773 -7514
- package/dist/needle-engine.bundle.light.min.js +131 -132
- package/dist/needle-engine.bundle.light.umd.cjs +134 -135
- package/dist/needle-engine.bundle.min.js +131 -132
- package/dist/needle-engine.bundle.umd.cjs +134 -135
- package/dist/needle-engine.js +596 -590
- package/dist/needle-engine.light.js +596 -590
- package/dist/needle-engine.light.min.js +1 -1
- package/dist/needle-engine.light.umd.cjs +1 -1
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/three-examples.js +26 -26
- package/dist/three-examples.light.js +26 -26
- package/dist/three-examples.light.min.js +1 -1
- package/dist/three-examples.light.umd.cjs +1 -1
- package/dist/three-examples.min.js +1 -1
- package/dist/three-examples.umd.cjs +1 -1
- package/dist/vendor.js +0 -2
- package/dist/vendor.light.js +0 -2
- package/dist/vendor.light.min.js +2 -2
- package/dist/vendor.light.umd.cjs +2 -2
- package/dist/vendor.min.js +2 -2
- package/dist/vendor.umd.cjs +2 -2
- package/lib/engine/engine.d.ts +4 -0
- package/lib/engine/engine.js +12 -0
- package/lib/engine/engine.js.map +1 -0
- package/lib/engine/engine_web_api.d.ts +12 -0
- package/lib/engine/engine_web_api.js +113 -0
- package/lib/engine/engine_web_api.js.map +1 -0
- package/lib/engine/xr/NeedleXRSession.js +3 -0
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine-components/FlyControls.d.ts +10 -0
- package/lib/engine-components/FlyControls.js +29 -0
- package/lib/engine-components/FlyControls.js.map +1 -0
- package/lib/engine-components/GroundProjection.d.ts +1 -1
- package/lib/engine-components/GroundProjection.js +39 -32
- package/lib/engine-components/GroundProjection.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +8 -0
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/RigidBody.js +10 -4
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.d.ts +2 -2
- package/lib/engine-components/SpatialTrigger.js +4 -4
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +7 -1
- package/lib/engine-components/TransformGizmo.js +39 -32
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/VideoPlayer.js +0 -1
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/particlesystem/ParticleSystemModules.js +1 -1
- package/lib/engine-components/particlesystem/ParticleSystemModules.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +2 -0
- package/lib/engine-components/postprocessing/Effects/Sharpening.js +15 -6
- package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.d.ts +4 -0
- package/lib/engine-components/webxr/WebXRImageTracking.js +14 -4
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/lib/engine-components/webxr/WebXRRig.d.ts +11 -1
- package/lib/engine-components/webxr/WebXRRig.js +13 -1
- package/lib/engine-components/webxr/WebXRRig.js.map +1 -1
- package/lib/needle-engine.js +5 -5
- package/lib/needle-engine.js.map +1 -1
- package/package.json +3 -3
- package/src/engine/codegen/register_types.ts +2 -2
- package/src/engine/xr/NeedleXRSession.ts +3 -0
- package/src/engine-components/GroundProjection.ts +46 -38
- package/src/engine-components/OrbitControls.ts +8 -0
- package/src/engine-components/RigidBody.ts +11 -5
- package/src/engine-components/SpatialTrigger.ts +6 -6
- package/src/engine-components/TransformGizmo.ts +41 -33
- package/src/engine-components/VideoPlayer.ts +0 -1
- package/src/engine-components/particlesystem/ParticleSystemModules.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Sharpening.ts +16 -7
- package/src/engine-components/webxr/WebXRImageTracking.ts +18 -4
- package/src/engine-components/webxr/WebXRRig.ts +15 -2
- package/src/needle-engine.ts +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as he, M as H, a as We, T as j, b as ze, V as
|
|
1
|
+
import { B as he, M as H, a as We, T as j, b as ze, V as F, c as Se, S as Ve, d as be, e as qe, C as Ke } from "./three.light.js";
|
|
2
2
|
import { D as Xe, K as Ye, G as Oe, M as He } from "./three-examples.light.js";
|
|
3
3
|
const Pe = "";
|
|
4
4
|
globalThis.GLTF_PROGRESSIVE_VERSION = Pe;
|
|
@@ -104,7 +104,7 @@ function nt(t) {
|
|
|
104
104
|
e.setAttribute(s, t.getAttribute(s));
|
|
105
105
|
return e.setIndex(t.getIndex()), e;
|
|
106
106
|
}
|
|
107
|
-
const q = new Array(),
|
|
107
|
+
const q = new Array(), $ = "NEEDLE_progressive", y = oe("debugprogressive"), _e = Symbol("needle-progressive-texture"), ie = /* @__PURE__ */ new Map(), we = /* @__PURE__ */ new Set();
|
|
108
108
|
if (y) {
|
|
109
109
|
let t = function() {
|
|
110
110
|
e += 1, console.log("Toggle LOD level", e, ie), ie.forEach((i, r) => {
|
|
@@ -112,10 +112,10 @@ if (y) {
|
|
|
112
112
|
const a = r[o];
|
|
113
113
|
if (a != null) {
|
|
114
114
|
if (a.isBufferGeometry === !0) {
|
|
115
|
-
const c =
|
|
116
|
-
r["DEBUG:LOD"] = e,
|
|
115
|
+
const c = b.getMeshLODInformation(a), l = c ? Math.min(e, c.lods.length) : 0;
|
|
116
|
+
r["DEBUG:LOD"] = e, b.assignMeshLOD(r, l), c && (s = Math.max(s, c.lods.length - 1));
|
|
117
117
|
} else if (r.isMaterial === !0) {
|
|
118
|
-
r["DEBUG:LOD"] = e,
|
|
118
|
+
r["DEBUG:LOD"] = e, b.assignTextureLOD(r, e);
|
|
119
119
|
break;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
@@ -142,7 +142,7 @@ const D = class {
|
|
|
142
142
|
var i, r;
|
|
143
143
|
if (this._isLoadingMesh)
|
|
144
144
|
return null;
|
|
145
|
-
const n = (r = (i = this.parser.json.meshes[s]) == null ? void 0 : i.extensions) == null ? void 0 : r[
|
|
145
|
+
const n = (r = (i = this.parser.json.meshes[s]) == null ? void 0 : i.extensions) == null ? void 0 : r[$];
|
|
146
146
|
return n ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", s).then((o) => {
|
|
147
147
|
var a;
|
|
148
148
|
return this._isLoadingMesh = !1, o && D.registerMesh(this.url, n.guid, o, (a = n.lods) == null ? void 0 : a.length, void 0, n), o;
|
|
@@ -151,7 +151,7 @@ const D = class {
|
|
|
151
151
|
}
|
|
152
152
|
/** The name of the extension */
|
|
153
153
|
get name() {
|
|
154
|
-
return
|
|
154
|
+
return $;
|
|
155
155
|
}
|
|
156
156
|
static getMeshLODInformation(t) {
|
|
157
157
|
const e = this.getAssignedLODInformation(t);
|
|
@@ -351,7 +351,7 @@ const D = class {
|
|
|
351
351
|
return y && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, i) => {
|
|
352
352
|
var r;
|
|
353
353
|
if (n != null && n.extensions) {
|
|
354
|
-
const o = n == null ? void 0 : n.extensions[
|
|
354
|
+
const o = n == null ? void 0 : n.extensions[$];
|
|
355
355
|
if (o) {
|
|
356
356
|
if (!o.lods) {
|
|
357
357
|
y && console.warn("Texture has no LODs", o);
|
|
@@ -371,7 +371,7 @@ const D = class {
|
|
|
371
371
|
}
|
|
372
372
|
}), (s = this.parser.json.meshes) == null || s.forEach((n, i) => {
|
|
373
373
|
if (n != null && n.extensions) {
|
|
374
|
-
const r = n == null ? void 0 : n.extensions[
|
|
374
|
+
const r = n == null ? void 0 : n.extensions[$];
|
|
375
375
|
if (r && r.lods) {
|
|
376
376
|
for (const o of this.parser.associations.keys())
|
|
377
377
|
if (o.isMesh) {
|
|
@@ -411,73 +411,73 @@ const D = class {
|
|
|
411
411
|
if (L !== void 0) {
|
|
412
412
|
s && console.log(`LOD ${e} was already loading/loaded: ${m}`);
|
|
413
413
|
let f = await L.catch((I) => (console.error(`Error loading LOD ${e} from ${h}
|
|
414
|
-
`, I), null)),
|
|
415
|
-
if (f == null || (f instanceof j && t instanceof j ? (a = f.image) != null && a.data || (c = f.source) != null && c.data ? f = this.copySettings(t, f) : (
|
|
414
|
+
`, I), null)), v = !1;
|
|
415
|
+
if (f == null || (f instanceof j && t instanceof j ? (a = f.image) != null && a.data || (c = f.source) != null && c.data ? f = this.copySettings(t, f) : (v = !0, this.previouslyLoaded.delete(m)) : f instanceof he && t instanceof he && ((l = f.attributes.position) != null && l.array || (v = !0, this.previouslyLoaded.delete(m)))), !v)
|
|
416
416
|
return f;
|
|
417
417
|
}
|
|
418
|
-
const M = r, P = new Promise(async (f,
|
|
418
|
+
const M = r, P = new Promise(async (f, v) => {
|
|
419
419
|
const I = new Oe();
|
|
420
|
-
Re(I), y && (await new Promise((
|
|
420
|
+
Re(I), y && (await new Promise((O) => setTimeout(O, 1e3)), s && console.warn("Start loading (delayed) " + h, M.guid));
|
|
421
421
|
let k = h;
|
|
422
422
|
if (M && Array.isArray(M.lods)) {
|
|
423
|
-
const
|
|
424
|
-
|
|
423
|
+
const O = M.lods[e];
|
|
424
|
+
O.hash && (k += "?v=" + O.hash);
|
|
425
425
|
}
|
|
426
|
-
const
|
|
427
|
-
`,
|
|
428
|
-
if (!
|
|
426
|
+
const T = await I.loadAsync(k).catch((O) => (console.error(`Error loading LOD ${e} from ${h}
|
|
427
|
+
`, O), null));
|
|
428
|
+
if (!T)
|
|
429
429
|
return null;
|
|
430
|
-
const
|
|
430
|
+
const G = T.parser;
|
|
431
431
|
s && console.log("Loading finished " + h, M.guid);
|
|
432
|
-
let
|
|
433
|
-
if (
|
|
434
|
-
let
|
|
435
|
-
for (const u of
|
|
432
|
+
let w = 0;
|
|
433
|
+
if (T.parser.json.textures) {
|
|
434
|
+
let O = !1;
|
|
435
|
+
for (const u of T.parser.json.textures) {
|
|
436
436
|
if (u != null && u.extensions) {
|
|
437
|
-
const g = u == null ? void 0 : u.extensions[
|
|
437
|
+
const g = u == null ? void 0 : u.extensions[$];
|
|
438
438
|
if (g != null && g.guid && g.guid === M.guid) {
|
|
439
|
-
|
|
439
|
+
O = !0;
|
|
440
440
|
break;
|
|
441
441
|
}
|
|
442
442
|
}
|
|
443
|
-
|
|
443
|
+
w++;
|
|
444
444
|
}
|
|
445
|
-
if (
|
|
446
|
-
let u = await
|
|
447
|
-
return u && D.assignLODInformation(n.url, u, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + u.name + '"', h,
|
|
445
|
+
if (O) {
|
|
446
|
+
let u = await G.getDependency("texture", w);
|
|
447
|
+
return u && D.assignLODInformation(n.url, u, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + u.name + '"', h, w, u, m), t instanceof j && (u = this.copySettings(t, u)), u && (u.guid = M.guid), f(u);
|
|
448
448
|
} else
|
|
449
|
-
y && console.warn("Could not find texture with guid", M.guid,
|
|
449
|
+
y && console.warn("Could not find texture with guid", M.guid, T.parser.json);
|
|
450
450
|
}
|
|
451
|
-
if (
|
|
452
|
-
let
|
|
453
|
-
for (const u of
|
|
451
|
+
if (w = 0, T.parser.json.meshes) {
|
|
452
|
+
let O = !1;
|
|
453
|
+
for (const u of T.parser.json.meshes) {
|
|
454
454
|
if (u != null && u.extensions) {
|
|
455
|
-
const g = u == null ? void 0 : u.extensions[
|
|
455
|
+
const g = u == null ? void 0 : u.extensions[$];
|
|
456
456
|
if (g != null && g.guid && g.guid === M.guid) {
|
|
457
|
-
|
|
457
|
+
O = !0;
|
|
458
458
|
break;
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
|
-
|
|
461
|
+
w++;
|
|
462
462
|
}
|
|
463
|
-
if (
|
|
464
|
-
const u = await
|
|
465
|
-
if (s && console.log(`Loaded Mesh "${u.name}"`, h,
|
|
463
|
+
if (O) {
|
|
464
|
+
const u = await G.getDependency("mesh", w), g = M;
|
|
465
|
+
if (s && console.log(`Loaded Mesh "${u.name}"`, h, w, u, m), u.isMesh === !0) {
|
|
466
466
|
const _ = u.geometry;
|
|
467
467
|
return D.assignLODInformation(n.url, _, i, e, void 0, g.density), f(_);
|
|
468
468
|
} else {
|
|
469
469
|
const _ = new Array();
|
|
470
|
-
for (let
|
|
471
|
-
const A = u.children[
|
|
470
|
+
for (let S = 0; S < u.children.length; S++) {
|
|
471
|
+
const A = u.children[S];
|
|
472
472
|
if (A.isMesh === !0) {
|
|
473
473
|
const W = A.geometry;
|
|
474
|
-
D.assignLODInformation(n.url, W, i, e,
|
|
474
|
+
D.assignLODInformation(n.url, W, i, e, S, g.density), _.push(W);
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
return f(_);
|
|
478
478
|
}
|
|
479
479
|
} else
|
|
480
|
-
y && console.warn("Could not find mesh with guid", M.guid,
|
|
480
|
+
y && console.warn("Could not find mesh with guid", M.guid, T.parser.json);
|
|
481
481
|
}
|
|
482
482
|
return f(null);
|
|
483
483
|
});
|
|
@@ -509,8 +509,8 @@ const D = class {
|
|
|
509
509
|
`, 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;
|
|
510
510
|
}
|
|
511
511
|
};
|
|
512
|
-
let
|
|
513
|
-
|
|
512
|
+
let b = D;
|
|
513
|
+
b.registerTexture = (t, e, s, n, i) => {
|
|
514
514
|
if (y && console.log("> Progressive: register texture", n, e.name, e.uuid, e, i), !e) {
|
|
515
515
|
y && console.error("gltf-progressive: Register texture without texture");
|
|
516
516
|
return;
|
|
@@ -519,7 +519,7 @@ S.registerTexture = (t, e, s, n, i) => {
|
|
|
519
519
|
const r = i.guid;
|
|
520
520
|
D.assignLODInformation(t, e, r, s, n, void 0), D.lodInfos.set(r, i), D.lowresCache.set(r, e);
|
|
521
521
|
};
|
|
522
|
-
|
|
522
|
+
b.registerMesh = (t, e, s, n, i, r) => {
|
|
523
523
|
var c;
|
|
524
524
|
y && console.log("> Progressive: register mesh", i, s.name, r, s.uuid, s);
|
|
525
525
|
const o = s.geometry;
|
|
@@ -533,9 +533,9 @@ S.registerMesh = (t, e, s, n, i, r) => {
|
|
|
533
533
|
for (const l of q)
|
|
534
534
|
(c = l.onRegisteredNewMesh) == null || c.call(l, s, r);
|
|
535
535
|
};
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
536
|
+
b.lodInfos = /* @__PURE__ */ new Map();
|
|
537
|
+
b.previouslyLoaded = /* @__PURE__ */ new Map();
|
|
538
|
+
b.lowresCache = /* @__PURE__ */ new Map();
|
|
539
539
|
class ot {
|
|
540
540
|
constructor(e, s, n, i, r) {
|
|
541
541
|
this.url = e, this.key = s, this.level = n, i != null && (this.index = i), r != null && (this.density = r);
|
|
@@ -548,11 +548,11 @@ var Ge = (t, e, s) => {
|
|
|
548
548
|
if (e.has(t))
|
|
549
549
|
throw TypeError("Cannot add the same private member more than once");
|
|
550
550
|
e instanceof WeakSet ? e.add(t) : e.set(t, s);
|
|
551
|
-
},
|
|
551
|
+
}, N = (t, e, s, n) => (Ge(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), E, z, ve, Q, re, de, V;
|
|
552
552
|
const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:LODSManager"), xe = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), R = { mesh_lod: -1, texture_lod: -1 }, C = class {
|
|
553
553
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
554
554
|
constructor(t, e) {
|
|
555
|
-
this.projectionScreenMatrix = new Se(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", K(this,
|
|
555
|
+
this.projectionScreenMatrix = new Se(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", K(this, E, 1), this.pause = !1, this.manual = !1, this._lodchangedlisteners = [], K(this, z, void 0), K(this, ve, new Ke()), K(this, Q, 0), K(this, re, 0), K(this, de, 0), K(this, V, 0), this._fpsBuffer = [60, 60, 60, 60, 60], this._sphere = new Ve(), this._tempBox = new be(), this._tempBox2 = new be(), this.tempMatrix = new Se(), this._tempWorldPosition = new F(), this._tempBoxSize = new F(), this._tempBox2Size = new F(), this.renderer = t, this.context = { ...e };
|
|
556
556
|
}
|
|
557
557
|
/** @internal */
|
|
558
558
|
static getObjectLODState(t) {
|
|
@@ -600,17 +600,17 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
|
|
|
600
600
|
return;
|
|
601
601
|
console.debug("[gltf-progressive] Enabling LODsManager for renderer");
|
|
602
602
|
let t = 0;
|
|
603
|
-
|
|
603
|
+
N(this, z, this.renderer.render);
|
|
604
604
|
const e = this;
|
|
605
605
|
Be(this.renderer), this.renderer.render = function(s, n) {
|
|
606
606
|
const i = e.renderer.getRenderTarget();
|
|
607
|
-
(i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0,
|
|
607
|
+
(i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, N(e, Q, p(e, Q) + 1), N(e, re, p(e, ve).getDelta()), N(e, de, p(e, de) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, V, e._fpsBuffer.reduce((o, a) => o + a) / e._fpsBuffer.length), B && p(e, Q) % 200 === 0 && console.log("FPS", Math.round(p(e, V)), "Interval:", p(e, E)));
|
|
608
608
|
const r = t++;
|
|
609
609
|
p(e, z).call(this, s, n), e.onAfterRender(s, n, r);
|
|
610
610
|
};
|
|
611
611
|
}
|
|
612
612
|
disable() {
|
|
613
|
-
p(this, z) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = p(this, z),
|
|
613
|
+
p(this, z) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = p(this, z), N(this, z, void 0));
|
|
614
614
|
}
|
|
615
615
|
update(t, e) {
|
|
616
616
|
this.internalUpdate(t, e);
|
|
@@ -625,7 +625,7 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
|
|
|
625
625
|
(o.name === "EffectMaterial" || o.name === "CopyShader") && (r = !1);
|
|
626
626
|
}
|
|
627
627
|
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (r = !1), r) {
|
|
628
|
-
if (at || (this.updateInterval === "auto" ? p(this, V) < 40 && p(this,
|
|
628
|
+
if (at || (this.updateInterval === "auto" ? p(this, V) < 40 && p(this, E) < 10 ? (N(this, E, p(this, E) + 1), B && console.warn("↓ Reducing LOD updates", p(this, E), p(this, V).toFixed(0))) : p(this, V) >= 60 && p(this, E) > 1 && (N(this, E, p(this, E) - 1), B && console.warn("↑ Increasing LOD updates", p(this, E), p(this, V).toFixed(0))) : N(this, E, this.updateInterval), p(this, E) > 0 && p(this, Q) % p(this, E) != 0))
|
|
629
629
|
return;
|
|
630
630
|
this.internalUpdate(t, e);
|
|
631
631
|
}
|
|
@@ -704,7 +704,7 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
|
|
|
704
704
|
return;
|
|
705
705
|
}
|
|
706
706
|
let s = !1;
|
|
707
|
-
(t[J] === void 0 || e < t[J]) && (s = !0), s && (t[J] = e,
|
|
707
|
+
(t[J] === void 0 || e < t[J]) && (s = !0), s && (t[J] = e, b.assignTextureLOD(t, e).then((n) => {
|
|
708
708
|
this._lodchangedlisteners.forEach((i) => i({ type: "texture", level: e, object: t }));
|
|
709
709
|
}));
|
|
710
710
|
}
|
|
@@ -720,7 +720,7 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
|
|
|
720
720
|
if (t[J] !== e) {
|
|
721
721
|
t[J] = e;
|
|
722
722
|
const s = t.geometry;
|
|
723
|
-
return
|
|
723
|
+
return b.assignMeshLOD(t, e).then((n) => (n && t[J] == e && s != t.geometry && this._lodchangedlisteners.forEach((i) => i({ type: "mesh", level: e, object: t })), n));
|
|
724
724
|
}
|
|
725
725
|
return Promise.resolve(null);
|
|
726
726
|
}
|
|
@@ -741,7 +741,7 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
|
|
|
741
741
|
let o = 10 + 1, a = !1;
|
|
742
742
|
if (B && e["DEBUG:LOD"] != null)
|
|
743
743
|
return e["DEBUG:LOD"];
|
|
744
|
-
const c =
|
|
744
|
+
const c = b.getMeshLODInformation(e.geometry), l = c == null ? void 0 : c.lods, d = l && l.length > 0, h = b.getMaterialMinMaxLODsCount(e.material), m = (h == null ? void 0 : h.min_count) != 1 / 0 && h.min_count > 0 && h.max_count > 0;
|
|
745
745
|
if (!d && !m) {
|
|
746
746
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
747
747
|
return;
|
|
@@ -754,8 +754,8 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
|
|
|
754
754
|
if (!x.boundingBox)
|
|
755
755
|
x.computeBoundingBox();
|
|
756
756
|
else if (s.frames % 30 === 0) {
|
|
757
|
-
const f = ae(x),
|
|
758
|
-
f && (x.geometry = f), x.computeBoundingBox(), x.geometry =
|
|
757
|
+
const f = ae(x), v = x.geometry;
|
|
758
|
+
f && (x.geometry = f), x.computeBoundingBox(), x.geometry = v;
|
|
759
759
|
}
|
|
760
760
|
M = x.boundingBox;
|
|
761
761
|
}
|
|
@@ -775,35 +775,35 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
|
|
|
775
775
|
}
|
|
776
776
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && x.fov > 70) {
|
|
777
777
|
const u = this._tempBox.min, g = this._tempBox.max;
|
|
778
|
-
let _ = u.x,
|
|
778
|
+
let _ = u.x, S = u.y, A = g.x, W = g.y;
|
|
779
779
|
const le = 2, pe = 1.5, ce = (u.x + g.x) * 0.5, ue = (u.y + g.y) * 0.5;
|
|
780
|
-
_ = (_ - ce) * le + ce,
|
|
781
|
-
const Fe = _ < 0 && A > 0 ? 0 : Math.min(Math.abs(u.x), Math.abs(g.x)), Ue =
|
|
780
|
+
_ = (_ - ce) * le + ce, S = (S - ue) * le + ue, A = (A - ce) * le + ce, W = (W - ue) * le + ue;
|
|
781
|
+
const Fe = _ < 0 && A > 0 ? 0 : Math.min(Math.abs(u.x), Math.abs(g.x)), Ue = S < 0 && W > 0 ? 0 : Math.min(Math.abs(u.y), Math.abs(g.y)), ye = Math.max(Fe, Ue);
|
|
782
782
|
s.lastCentrality = (pe - ye) * (pe - ye) * (pe - ye);
|
|
783
783
|
} else
|
|
784
784
|
s.lastCentrality = 1;
|
|
785
785
|
const f = this._tempBox.getSize(this._tempBoxSize);
|
|
786
786
|
f.multiplyScalar(0.5), screen.availHeight > 0 && L > 0 && f.multiplyScalar(L / screen.availHeight), f.x *= x.aspect;
|
|
787
|
-
const
|
|
788
|
-
I.copy(M), I.applyMatrix4(e.matrixWorld), I.applyMatrix4(
|
|
789
|
-
const k = I.getSize(this._tempBox2Size),
|
|
790
|
-
if (Math.max(f.x, f.y) != 0 &&
|
|
787
|
+
const v = t.matrixWorldInverse, I = this._tempBox2;
|
|
788
|
+
I.copy(M), I.applyMatrix4(e.matrixWorld), I.applyMatrix4(v);
|
|
789
|
+
const k = I.getSize(this._tempBox2Size), T = Math.max(k.x, k.y);
|
|
790
|
+
if (Math.max(f.x, f.y) != 0 && T != 0 && (f.z = k.z / Math.max(k.x, k.y) * Math.max(f.x, f.y)), s.lastScreenCoverage = Math.max(f.x, f.y, f.z), s.lastScreenspaceVolume.copy(f), s.lastScreenCoverage *= s.lastCentrality, B && C.debugDrawLine) {
|
|
791
791
|
const u = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
792
792
|
u.invert();
|
|
793
|
-
const g = C.corner0, _ = C.corner1,
|
|
794
|
-
g.copy(this._tempBox.min), _.copy(this._tempBox.max), _.x = g.x,
|
|
793
|
+
const g = C.corner0, _ = C.corner1, S = C.corner2, A = C.corner3;
|
|
794
|
+
g.copy(this._tempBox.min), _.copy(this._tempBox.max), _.x = g.x, S.copy(this._tempBox.max), S.y = g.y, A.copy(this._tempBox.max);
|
|
795
795
|
const W = (g.z + A.z) * 0.5;
|
|
796
|
-
g.z = _.z =
|
|
796
|
+
g.z = _.z = S.z = A.z = W, g.applyMatrix4(u), _.applyMatrix4(u), S.applyMatrix4(u), A.applyMatrix4(u), C.debugDrawLine(g, _, 255), C.debugDrawLine(g, S, 255), C.debugDrawLine(_, A, 255), C.debugDrawLine(S, A, 255);
|
|
797
797
|
}
|
|
798
|
-
let
|
|
798
|
+
let w = 999;
|
|
799
799
|
if (l && s.lastScreenCoverage > 0) {
|
|
800
800
|
for (let u = 0; u < l.length; u++)
|
|
801
801
|
if (l[u].density / s.lastScreenCoverage < n) {
|
|
802
|
-
|
|
802
|
+
w = u;
|
|
803
803
|
break;
|
|
804
804
|
}
|
|
805
805
|
}
|
|
806
|
-
|
|
806
|
+
w < o && (o = w, a = !0);
|
|
807
807
|
}
|
|
808
808
|
if (a ? i.mesh_lod = o : i.mesh_lod = s.lastLodLevel_Mesh, B && i.mesh_lod != s.lastLodLevel_Mesh) {
|
|
809
809
|
const f = l == null ? void 0 : l[i.mesh_lod];
|
|
@@ -818,15 +818,16 @@ const B = oe("debugprogressive"), at = oe("noprogressive"), me = Symbol("Needle:
|
|
|
818
818
|
}
|
|
819
819
|
} else {
|
|
820
820
|
const f = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
821
|
-
let
|
|
822
|
-
((P = this.context) == null ? void 0 : P.engine) === "model-viewer" && (
|
|
823
|
-
const k = L / window.devicePixelRatio *
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
821
|
+
let v = s.lastScreenCoverage * 4;
|
|
822
|
+
((P = this.context) == null ? void 0 : P.engine) === "model-viewer" && (v *= 1.5);
|
|
823
|
+
const k = L / window.devicePixelRatio * v;
|
|
824
|
+
let T = !1;
|
|
825
|
+
for (let G = h.lods.length - 1; G >= 0; G--) {
|
|
826
|
+
let w = h.lods[G];
|
|
827
|
+
if (!(x && w.max_height >= 2048) && !(tt() && w.max_height > 4096) && (w.max_height > k || !T && G === 0)) {
|
|
828
|
+
if (T = !0, i.texture_lod = G, i.texture_lod < s.lastLodLevel_Texture) {
|
|
829
|
+
const O = w.max_height;
|
|
830
|
+
B && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${O}px
|
|
830
831
|
Screensize: ${k.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${f.toFixed(1)}
|
|
831
832
|
${e.name}`);
|
|
832
833
|
}
|
|
@@ -838,22 +839,22 @@ ${e.name}`);
|
|
|
838
839
|
i.texture_lod = 0;
|
|
839
840
|
}
|
|
840
841
|
};
|
|
841
|
-
let
|
|
842
|
-
|
|
842
|
+
let U = C;
|
|
843
|
+
E = /* @__PURE__ */ new WeakMap();
|
|
843
844
|
z = /* @__PURE__ */ new WeakMap();
|
|
844
845
|
ve = /* @__PURE__ */ new WeakMap();
|
|
845
846
|
Q = /* @__PURE__ */ new WeakMap();
|
|
846
847
|
re = /* @__PURE__ */ new WeakMap();
|
|
847
848
|
de = /* @__PURE__ */ new WeakMap();
|
|
848
849
|
V = /* @__PURE__ */ new WeakMap();
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
850
|
+
U.corner0 = new F();
|
|
851
|
+
U.corner1 = new F();
|
|
852
|
+
U.corner2 = new F();
|
|
853
|
+
U.corner3 = new F();
|
|
854
|
+
U._tempPtInside = new F();
|
|
854
855
|
class lt {
|
|
855
856
|
constructor() {
|
|
856
|
-
this.frames = 0, this.lastLodLevel_Mesh = -1, this.lastLodLevel_Texture = -1, this.lastScreenCoverage = 0, this.lastScreenspaceVolume = new
|
|
857
|
+
this.frames = 0, this.lastLodLevel_Mesh = -1, this.lastLodLevel_Texture = -1, this.lastScreenCoverage = 0, this.lastScreenspaceVolume = new F(), this.lastCentrality = 0;
|
|
857
858
|
}
|
|
858
859
|
}
|
|
859
860
|
const Te = Symbol("NEEDLE_mesh_lod"), fe = Symbol("NEEDLE_texture_lod");
|
|
@@ -910,8 +911,8 @@ function $e(t) {
|
|
|
910
911
|
}
|
|
911
912
|
};
|
|
912
913
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
913
|
-
const r =
|
|
914
|
-
return
|
|
914
|
+
const r = U.get(e, { engine: "model-viewer" });
|
|
915
|
+
return U.addPlugin(new ft()), r.enable(), r.addEventListener("changed", () => {
|
|
915
916
|
n == null || n.call(t);
|
|
916
917
|
}), t.addEventListener("model-visibility", (o) => {
|
|
917
918
|
o.detail.visible && (n == null || n.call(t));
|
|
@@ -965,9 +966,9 @@ class ft {
|
|
|
965
966
|
console.warn("Texture data not found for texture index " + x);
|
|
966
967
|
continue;
|
|
967
968
|
}
|
|
968
|
-
if ((m = f == null ? void 0 : f.extensions) != null && m[
|
|
969
|
-
const
|
|
970
|
-
|
|
969
|
+
if ((m = f == null ? void 0 : f.extensions) != null && m[$]) {
|
|
970
|
+
const v = f.extensions[$];
|
|
971
|
+
v && r && b.registerTexture(r, P, v.lods.length, x, v);
|
|
971
972
|
}
|
|
972
973
|
}
|
|
973
974
|
}
|
|
@@ -988,10 +989,10 @@ class ft {
|
|
|
988
989
|
const n = this.tryGetCurrentModelViewer(e), i = this.getUrl(n);
|
|
989
990
|
if (!i)
|
|
990
991
|
return;
|
|
991
|
-
const r = (a = (o = s.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : a[
|
|
992
|
+
const r = (a = (o = s.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : a[$];
|
|
992
993
|
if (r && i) {
|
|
993
994
|
const c = s.uuid;
|
|
994
|
-
|
|
995
|
+
b.registerMesh(i, c, s, 0, r.lods.length, r);
|
|
995
996
|
}
|
|
996
997
|
}
|
|
997
998
|
}
|
|
@@ -999,8 +1000,8 @@ function dt(t, e, s, n) {
|
|
|
999
1000
|
Be(e), Re(s), Ie(s, {
|
|
1000
1001
|
progressive: !0,
|
|
1001
1002
|
...n == null ? void 0 : n.hints
|
|
1002
|
-
}), s.register((r) => new
|
|
1003
|
-
const i =
|
|
1003
|
+
}), s.register((r) => new b(r, t));
|
|
1004
|
+
const i = U.get(e);
|
|
1004
1005
|
return (n == null ? void 0 : n.enableLODsManager) !== !1 && i.enable(), i;
|
|
1005
1006
|
}
|
|
1006
1007
|
Ne();
|
|
@@ -1008,7 +1009,7 @@ if (!st) {
|
|
|
1008
1009
|
const t = {
|
|
1009
1010
|
gltfProgressive: {
|
|
1010
1011
|
useNeedleProgressive: dt,
|
|
1011
|
-
LODsManager:
|
|
1012
|
+
LODsManager: U,
|
|
1012
1013
|
configureLoader: Ie,
|
|
1013
1014
|
getRaycastMesh: ae,
|
|
1014
1015
|
useRaycastMeshes: it
|
|
@@ -1021,8 +1022,8 @@ if (!st) {
|
|
|
1021
1022
|
globalThis.Needle[e] = t[e];
|
|
1022
1023
|
}
|
|
1023
1024
|
export {
|
|
1024
|
-
|
|
1025
|
-
|
|
1025
|
+
U as L,
|
|
1026
|
+
b as N,
|
|
1026
1027
|
Re as a,
|
|
1027
1028
|
Ie as b,
|
|
1028
1029
|
Be as c,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{B as le,M as z,a as Ge,T as Z,b as Ne,V as R,c as Oe,S as $e,d as be,e as Ue,C as Fe}from"./three.light.min.js";import{D as ze,K as Ve,G as ge,M as qe}from"./three-examples.light.min.js";const Se="";globalThis.GLTF_PROGRESSIVE_VERSION=Se,console.debug(`[gltf-progressive] version ${Se}`);let K="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",ee="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const He=K,Xe=ee,Ke=new URL(K+"draco_decoder.js");fetch(Ke,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{K===He&&(K="./include/draco/"),ee===Xe&&(ee="./include/ktx2/")}).finally(()=>{Te()});function Ye(t){K=t}function Je(t){ee=t}let V,ae,q;function Te(){V||(V=new ze,V.setDecoderPath(K),V.setDecoderConfig({type:"js"}),V.preload()),q||(q=new Ve,q.setTranscoderPath(ee),q.init()),ae||(ae=qe)}function me(t){return Te(),t?q.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:V,ktx2Loader:q,meshoptDecoder:ae}}function pe(t){t.dracoLoader||t.setDRACOLoader(V),t.ktx2Loader||t.setKTX2Loader(q),t.meshoptDecoder||t.setMeshoptDecoder(ae)}const ve=new WeakMap;function ye(t,e){let r=ve.get(t);r?r=Object.assign(r,e):r=e,ve.set(t,r)}const Ee=ge.prototype.load;function Qe(...t){const e=ve.get(this);let r=t[0];const n=new URL(r,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,r=n.toString()}return t[0]=r,Ee?.call(this,...t)}ge.prototype.load=Qe,te("debugprogressive");function te(t){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(t);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const r=t.lastIndexOf("/");if(r>=0){const n=t.substring(0,r+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let ue;function et(){return ue!==void 0||(ue=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),te("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",ue)),ue}const tt=typeof window>"u"&&typeof document>"u",xe=Symbol("needle:raycast-mesh");function Y(t){return t?.[xe]instanceof le?t[xe]:null}function rt(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!Y(t)){const r=ot(e);r.userData={isRaycastMesh:!0},t[xe]=r}}function st(t=!0){if(t){if(re)return;const e=re=z.prototype.raycast;z.prototype.raycast=function(r,n){const s=this,o=Y(s);let i;o&&s.isMesh&&(i=s.geometry,s.geometry=o),e.call(this,r,n),i&&(s.geometry=i)}}else{if(!re)return;z.prototype.raycast=re,re=null}}let re=null;function ot(t){const e=new le;for(const r in t.attributes)e.setAttribute(r,t.getAttribute(r));return e.setIndex(t.getIndex()),e}const N=new Array,j="NEEDLE_progressive",v=te("debugprogressive"),Le=Symbol("needle-progressive-texture"),se=new Map,Me=new Set;if(v){let t=function(){e+=1,console.log("Toggle LOD level",e,se),se.forEach((s,o)=>{for(const i of s.keys){const a=o[i];if(a!=null){if(a.isBufferGeometry===!0){const u=b.getMeshLODInformation(a),l=u?Math.min(e,u.lods.length):0;o["DEBUG:LOD"]=e,b.assignMeshLOD(o,l),u&&(r=Math.max(r,u.lods.length-1))}else if(o.isMaterial===!0){o["DEBUG:LOD"]=e,b.assignTextureLOD(o,e);break}}}}),e>=r&&(e=-1)},e=-1,r=2,n=!1;window.addEventListener("keyup",s=>{s.key==="p"&&t(),s.key==="w"&&(n=!n,Me&&Me.forEach(o=>{o.name!="BackgroundCubeMaterial"&&o.glyphMap==null&&"wireframe"in o&&(o.wireframe=n)}))})}function Ae(t,e,r){var n;if(!v)return;se.has(t)||se.set(t,{keys:[],sourceId:r});const s=se.get(t);((n=s?.keys)==null?void 0:n.includes(e))==!1&&s.keys.push(e)}const w=class{constructor(t,e){this.loadMesh=r=>{var n,s;if(this._isLoadingMesh)return null;const o=(s=(n=this.parser.json.meshes[r])==null?void 0:n.extensions)==null?void 0:s[j];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",r).then(i=>{var a;return this._isLoadingMesh=!1,i&&w.registerMesh(this.url,o.guid,i,(a=o.lods)==null?void 0:a.length,void 0,o),i})):null},v&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return j}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const r=this,n="LODS:minmax",s=t[n];if(s!=null)return s;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const i of t)this.getMaterialMinMaxLODsCount(i,e);return t[n]=e,e}if(v==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const i=t;for(const a of Object.keys(i.uniforms)){const u=i.uniforms[a].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const i of Object.keys(t)){const a=t[i];a?.isTexture===!0&&o(a,e)}return t[n]=e,e;function o(i,a){const u=r.getAssignedLODInformation(i);if(u){const l=r.lodInfos.get(u.key);if(l&&l.lods){a.min_count=Math.min(a.min_count,l.lods.length),a.max_count=Math.max(a.max_count,l.lods.length);for(let h=0;h<l.lods.length;h++){const f=l.lods[h];f.width&&(a.lods[h]=a.lods[h]||{min_height:1/0,max_height:0},a.lods[h].min_height=Math.min(a.lods[h].min_height,f.height),a.lods[h].max_height=Math.max(a.lods[h].max_height,f.height))}}}}}static hasLODLevelAvailable(t,e){var r;if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const i=t[o];if(i&&i.isTexture&&this.hasLODLevelAvailable(i,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let n,s;if(t.isMesh?n=t.geometry:(t.isBufferGeometry||t.isTexture)&&(n=t),n&&(r=n?.userData)!=null&&r.LODS){const o=n.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){var r;if(!t)return Promise.resolve(null);if(t instanceof z||t.isMesh===!0){const n=t.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const o of N)(r=o.onBeforeGetLODMesh)==null||r.call(o,t,e);return t["LOD:requested level"]=e,w.getOrLoadLOD(n,e).then(o=>{if(Array.isArray(o)){const i=s.index||0;o=o[i]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&n!=o&&(o?.isBufferGeometry?(t.geometry=o,v&&Ae(t,"geometry",s.url)):v&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else v&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const o=this.assignTextureLOD(s,e);n.push(o)}return Promise.all(n).then(s=>{const o=new Array;for(const i of s)Array.isArray(i)&&o.push(...i);return o})}else return this.assignTextureLOD(r.material,e)}if(t instanceof Ge||t.isMaterial===!0){const r=t,n=[],s=new Array;if(v&&Me.add(r),r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const o=r;for(const i of Object.keys(o.uniforms)){const a=o.uniforms[i].value;if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,e,r,i).then(l=>(l&&o.uniforms[i].value!=l&&(o.uniforms[i].value=l,o.uniformsNeedUpdate=!0),l));n.push(u),s.push(i)}}}else for(const o of Object.keys(r)){const i=r[o];if(i?.isTexture===!0){const a=this.assignTextureLODForSlot(i,e,r,o);n.push(a),s.push(o)}}return Promise.all(n).then(o=>{const i=new Array;for(let a=0;a<o.length;a++){const u=o[a],l=s[a];u&&u.isTexture===!0?i.push({material:r,slot:l,texture:u,level:e}):i.push({material:r,slot:l,texture:null,level:e})}return i})}if(t instanceof Z||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,r,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):w.getOrLoadLOD(t,e).then(s=>{if(Array.isArray(s))return null;if(s?.isTexture===!0){if(s!=t){if(r&&n){const o=r[n];if(o){const i=this.getAssignedLODInformation(o);if(i&&i?.level<e)return v==="verbose"&&console.warn("Assigned texture level is already higher: ",i.level,e,r,o,s),null}r[n]=s}if(v&&n&&r){const o=this.getAssignedLODInformation(t);o&&Ae(r,n,o.url)}}return s}else v=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(s=>(console.error("Error loading LOD",t,s),null))}afterRoot(t){var e,r;return v&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((n,s)=>{var o;if(n!=null&&n.extensions){const i=n?.extensions[j];if(i){if(!i.lods){v&&console.warn("Texture has no LODs",i);return}let a=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const l=this.parser.associations.get(u);l?.textures===s&&(a=!0,w.registerTexture(this.url,u,(o=i.lods)==null?void 0:o.length,s,i))}a||this.parser.getDependency("texture",s).then(u=>{var l;u&&w.registerTexture(this.url,u,(l=i.lods)==null?void 0:l.length,s,i)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const o=n?.extensions[j];if(o&&o.lods){for(const i of this.parser.associations.keys())if(i.isMesh){const a=this.parser.associations.get(i);a?.meshes===s&&w.registerMesh(this.url,o.guid,i,o.lods.length,a.primitives,o)}}}}),null}static async getOrLoadLOD(t,e){var r,n,s,o;const i=v=="verbose",a=t.userData.LODS;if(!a)return null;const u=a?.key;let l;if(t.isTexture===!0){const h=t;h.source&&h.source[Le]&&(l=h.source[Le])}if(l||(l=w.lodInfos.get(u)),l){if(e>0){let m=!1;const E=Array.isArray(l.lods);if(E&&e>=l.lods.length?m=!0:E||(m=!0),m)return this.lowresCache.get(u)}const h=Array.isArray(l.lods)?(r=l.lods[e])==null?void 0:r.path:l.lods;if(!h)return v&&!l["missing:uri"]&&(l["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,l)),null;const f=Ze(a.url,h);if(f.endsWith(".glb")||f.endsWith(".gltf")){if(!l.guid)return console.warn("missing pointer for glb/gltf texture",l),null;const m=f+"_"+l.guid,E=this.previouslyLoaded.get(m);if(E!==void 0){i&&console.log(`LOD ${e} was already loading/loaded: ${m}`);let c=await E.catch(_=>(console.error(`Error loading LOD ${e} from ${f}
|
|
2
|
-
`,_),null)),D=!1;if(c==null||(c instanceof Z&&t instanceof Z?(n=c.image)!=null&&n.data||(s=c.source)!=null&&s.data?c=this.copySettings(t,c):(D=!0,this.previouslyLoaded.delete(
|
|
3
|
-
`,
|
|
1
|
+
import{B as le,M as z,a as We,T as Z,b as Ne,V as j,c as Oe,S as $e,d as be,e as Ue,C as Fe}from"./three.light.min.js";import{D as ze,K as Ve,G as ge,M as qe}from"./three-examples.light.min.js";const Se="";globalThis.GLTF_PROGRESSIVE_VERSION=Se,console.debug(`[gltf-progressive] version ${Se}`);let K="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",ee="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const He=K,Xe=ee,Ke=new URL(K+"draco_decoder.js");fetch(Ke,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(t=>{K===He&&(K="./include/draco/"),ee===Xe&&(ee="./include/ktx2/")}).finally(()=>{Te()});function Ye(t){K=t}function Je(t){ee=t}let V,ae,q;function Te(){V||(V=new ze,V.setDecoderPath(K),V.setDecoderConfig({type:"js"}),V.preload()),q||(q=new Ve,q.setTranscoderPath(ee),q.init()),ae||(ae=qe)}function me(t){return Te(),t?q.detectSupport(t):t!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:V,ktx2Loader:q,meshoptDecoder:ae}}function pe(t){t.dracoLoader||t.setDRACOLoader(V),t.ktx2Loader||t.setKTX2Loader(q),t.meshoptDecoder||t.setMeshoptDecoder(ae)}const ve=new WeakMap;function ye(t,e){let r=ve.get(t);r?r=Object.assign(r,e):r=e,ve.set(t,r)}const Ae=ge.prototype.load;function Qe(...t){const e=ve.get(this);let r=t[0];const n=new URL(r,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,o=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${o}`:this.requestHeader.Accept=`*/*;usecase=${o}`,r=n.toString()}return t[0]=r,Ae?.call(this,...t)}ge.prototype.load=Qe,te("debugprogressive");function te(t){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(t);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function Ze(t,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||t===void 0)return e;const r=t.lastIndexOf("/");if(r>=0){const n=t.substring(0,r+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let ue;function et(){return ue!==void 0||(ue=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),te("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",ue)),ue}const tt=typeof window>"u"&&typeof document>"u",xe=Symbol("needle:raycast-mesh");function Y(t){return t?.[xe]instanceof le?t[xe]:null}function rt(t,e){if((t.type==="Mesh"||t.type==="SkinnedMesh")&&!Y(t)){const r=ot(e);r.userData={isRaycastMesh:!0},t[xe]=r}}function st(t=!0){if(t){if(re)return;const e=re=z.prototype.raycast;z.prototype.raycast=function(r,n){const s=this,o=Y(s);let i;o&&s.isMesh&&(i=s.geometry,s.geometry=o),e.call(this,r,n),i&&(s.geometry=i)}}else{if(!re)return;z.prototype.raycast=re,re=null}}let re=null;function ot(t){const e=new le;for(const r in t.attributes)e.setAttribute(r,t.getAttribute(r));return e.setIndex(t.getIndex()),e}const N=new Array,G="NEEDLE_progressive",v=te("debugprogressive"),Le=Symbol("needle-progressive-texture"),se=new Map,Me=new Set;if(v){let t=function(){e+=1,console.log("Toggle LOD level",e,se),se.forEach((s,o)=>{for(const i of s.keys){const a=o[i];if(a!=null){if(a.isBufferGeometry===!0){const u=S.getMeshLODInformation(a),l=u?Math.min(e,u.lods.length):0;o["DEBUG:LOD"]=e,S.assignMeshLOD(o,l),u&&(r=Math.max(r,u.lods.length-1))}else if(o.isMaterial===!0){o["DEBUG:LOD"]=e,S.assignTextureLOD(o,e);break}}}}),e>=r&&(e=-1)},e=-1,r=2,n=!1;window.addEventListener("keyup",s=>{s.key==="p"&&t(),s.key==="w"&&(n=!n,Me&&Me.forEach(o=>{o.name!="BackgroundCubeMaterial"&&o.glyphMap==null&&"wireframe"in o&&(o.wireframe=n)}))})}function Ee(t,e,r){var n;if(!v)return;se.has(t)||se.set(t,{keys:[],sourceId:r});const s=se.get(t);((n=s?.keys)==null?void 0:n.includes(e))==!1&&s.keys.push(e)}const w=class{constructor(t,e){this.loadMesh=r=>{var n,s;if(this._isLoadingMesh)return null;const o=(s=(n=this.parser.json.meshes[r])==null?void 0:n.extensions)==null?void 0:s[G];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",r).then(i=>{var a;return this._isLoadingMesh=!1,i&&w.registerMesh(this.url,o.guid,i,(a=o.lods)==null?void 0:a.length,void 0,o),i})):null},v&&console.log("Progressive extension registered for",e),this.parser=t,this.url=e}get name(){return G}static getMeshLODInformation(t){const e=this.getAssignedLODInformation(t);return e!=null&&e.key?this.lodInfos.get(e.key):null}static getMaterialMinMaxLODsCount(t,e){const r=this,n="LODS:minmax",s=t[n];if(s!=null)return s;if(e||(e={min_count:1/0,max_count:0,lods:[]}),Array.isArray(t)){for(const i of t)this.getMaterialMinMaxLODsCount(i,e);return t[n]=e,e}if(v==="verbose"&&console.log("getMaterialMinMaxLODsCount",t),t.type==="ShaderMaterial"||t.type==="RawShaderMaterial"){const i=t;for(const a of Object.keys(i.uniforms)){const u=i.uniforms[a].value;u?.isTexture===!0&&o(u,e)}}else if(t.isMaterial)for(const i of Object.keys(t)){const a=t[i];a?.isTexture===!0&&o(a,e)}return t[n]=e,e;function o(i,a){const u=r.getAssignedLODInformation(i);if(u){const l=r.lodInfos.get(u.key);if(l&&l.lods){a.min_count=Math.min(a.min_count,l.lods.length),a.max_count=Math.max(a.max_count,l.lods.length);for(let h=0;h<l.lods.length;h++){const f=l.lods[h];f.width&&(a.lods[h]=a.lods[h]||{min_height:1/0,max_height:0},a.lods[h].min_height=Math.min(a.lods[h].min_height,f.height),a.lods[h].max_height=Math.max(a.lods[h].max_height,f.height))}}}}}static hasLODLevelAvailable(t,e){var r;if(Array.isArray(t)){for(const o of t)if(this.hasLODLevelAvailable(o,e))return!0;return!1}if(t.isMaterial===!0){for(const o of Object.keys(t)){const i=t[o];if(i&&i.isTexture&&this.hasLODLevelAvailable(i,e))return!0}return!1}else if(t.isGroup===!0){for(const o of t.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,e))return!0}let n,s;if(t.isMesh?n=t.geometry:(t.isBufferGeometry||t.isTexture)&&(n=t),n&&(r=n?.userData)!=null&&r.LODS){const o=n.userData.LODS;if(s=this.lodInfos.get(o.key),e===void 0)return s!=null;if(s)return Array.isArray(s.lods)?e<s.lods.length:e===0}return!1}static assignMeshLOD(t,e){var r;if(!t)return Promise.resolve(null);if(t instanceof z||t.isMesh===!0){const n=t.geometry,s=this.getAssignedLODInformation(n);if(!s)return Promise.resolve(null);for(const o of N)(r=o.onBeforeGetLODMesh)==null||r.call(o,t,e);return t["LOD:requested level"]=e,w.getOrLoadLOD(n,e).then(o=>{if(Array.isArray(o)){const i=s.index||0;o=o[i]}return t["LOD:requested level"]===e&&(delete t["LOD:requested level"],o&&n!=o&&(o?.isBufferGeometry?(t.geometry=o,v&&Ee(t,"geometry",s.url)):v&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",t,o),null))}else v&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",t);return Promise.resolve(null)}static assignTextureLOD(t,e=0){if(!t)return Promise.resolve(null);if(t.isMesh===!0){const r=t;if(Array.isArray(r.material)){const n=new Array;for(const s of r.material){const o=this.assignTextureLOD(s,e);n.push(o)}return Promise.all(n).then(s=>{const o=new Array;for(const i of s)Array.isArray(i)&&o.push(...i);return o})}else return this.assignTextureLOD(r.material,e)}if(t instanceof We||t.isMaterial===!0){const r=t,n=[],s=new Array;if(v&&Me.add(r),r.uniforms&&(r.isRawShaderMaterial||r.isShaderMaterial===!0)){const o=r;for(const i of Object.keys(o.uniforms)){const a=o.uniforms[i].value;if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,e,r,i).then(l=>(l&&o.uniforms[i].value!=l&&(o.uniforms[i].value=l,o.uniformsNeedUpdate=!0),l));n.push(u),s.push(i)}}}else for(const o of Object.keys(r)){const i=r[o];if(i?.isTexture===!0){const a=this.assignTextureLODForSlot(i,e,r,o);n.push(a),s.push(o)}}return Promise.all(n).then(o=>{const i=new Array;for(let a=0;a<o.length;a++){const u=o[a],l=s[a];u&&u.isTexture===!0?i.push({material:r,slot:l,texture:u,level:e}):i.push({material:r,slot:l,texture:null,level:e})}return i})}if(t instanceof Z||t.isTexture===!0){const r=t;return this.assignTextureLODForSlot(r,e,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(t,e,r,n){return t?.isTexture!==!0?Promise.resolve(null):n==="glyphMap"?Promise.resolve(t):w.getOrLoadLOD(t,e).then(s=>{if(Array.isArray(s))return null;if(s?.isTexture===!0){if(s!=t){if(r&&n){const o=r[n];if(o){const i=this.getAssignedLODInformation(o);if(i&&i?.level<e)return v==="verbose"&&console.warn("Assigned texture level is already higher: ",i.level,e,r,o,s),null}r[n]=s}if(v&&n&&r){const o=this.getAssignedLODInformation(t);o&&Ee(r,n,o.url)}}return s}else v=="verbose"&&console.warn("No LOD found for",t,e);return null}).catch(s=>(console.error("Error loading LOD",t,s),null))}afterRoot(t){var e,r;return v&&console.log("AFTER",this.url,t),(e=this.parser.json.textures)==null||e.forEach((n,s)=>{var o;if(n!=null&&n.extensions){const i=n?.extensions[G];if(i){if(!i.lods){v&&console.warn("Texture has no LODs",i);return}let a=!1;for(const u of this.parser.associations.keys())if(u.isTexture===!0){const l=this.parser.associations.get(u);l?.textures===s&&(a=!0,w.registerTexture(this.url,u,(o=i.lods)==null?void 0:o.length,s,i))}a||this.parser.getDependency("texture",s).then(u=>{var l;u&&w.registerTexture(this.url,u,(l=i.lods)==null?void 0:l.length,s,i)})}}}),(r=this.parser.json.meshes)==null||r.forEach((n,s)=>{if(n!=null&&n.extensions){const o=n?.extensions[G];if(o&&o.lods){for(const i of this.parser.associations.keys())if(i.isMesh){const a=this.parser.associations.get(i);a?.meshes===s&&w.registerMesh(this.url,o.guid,i,o.lods.length,a.primitives,o)}}}}),null}static async getOrLoadLOD(t,e){var r,n,s,o;const i=v=="verbose",a=t.userData.LODS;if(!a)return null;const u=a?.key;let l;if(t.isTexture===!0){const h=t;h.source&&h.source[Le]&&(l=h.source[Le])}if(l||(l=w.lodInfos.get(u)),l){if(e>0){let p=!1;const A=Array.isArray(l.lods);if(A&&e>=l.lods.length?p=!0:A||(p=!0),p)return this.lowresCache.get(u)}const h=Array.isArray(l.lods)?(r=l.lods[e])==null?void 0:r.path:l.lods;if(!h)return v&&!l["missing:uri"]&&(l["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+e,l)),null;const f=Ze(a.url,h);if(f.endsWith(".glb")||f.endsWith(".gltf")){if(!l.guid)return console.warn("missing pointer for glb/gltf texture",l),null;const p=f+"_"+l.guid,A=this.previouslyLoaded.get(p);if(A!==void 0){i&&console.log(`LOD ${e} was already loading/loaded: ${p}`);let c=await A.catch(_=>(console.error(`Error loading LOD ${e} from ${f}
|
|
2
|
+
`,_),null)),D=!1;if(c==null||(c instanceof Z&&t instanceof Z?(n=c.image)!=null&&n.data||(s=c.source)!=null&&s.data?c=this.copySettings(t,c):(D=!0,this.previouslyLoaded.delete(p)):c instanceof le&&t instanceof le&&((o=c.attributes.position)!=null&&o.array||(D=!0,this.previouslyLoaded.delete(p)))),!D)return c}const M=l,x=new Promise(async(c,D)=>{const _=new ge;pe(_),v&&(await new Promise(m=>setTimeout(m,1e3)),i&&console.warn("Start loading (delayed) "+f,M.guid));let P=f;if(M&&Array.isArray(M.lods)){const m=M.lods[e];m.hash&&(P+="?v="+m.hash)}const O=await _.loadAsync(P).catch(m=>(console.error(`Error loading LOD ${e} from ${f}
|
|
3
|
+
`,m),null));if(!O)return null;const I=O.parser;i&&console.log("Loading finished "+f,M.guid);let g=0;if(O.parser.json.textures){let m=!1;for(const d of O.parser.json.textures){if(d!=null&&d.extensions){const L=d?.extensions[G];if(L!=null&&L.guid&&L.guid===M.guid){m=!0;break}}g++}if(m){let d=await I.getDependency("texture",g);return d&&w.assignLODInformation(a.url,d,u,e,void 0,void 0),i&&console.log('change "'+t.name+'" \u2192 "'+d.name+'"',f,g,d,p),t instanceof Z&&(d=this.copySettings(t,d)),d&&(d.guid=M.guid),c(d)}else v&&console.warn("Could not find texture with guid",M.guid,O.parser.json)}if(g=0,O.parser.json.meshes){let m=!1;for(const d of O.parser.json.meshes){if(d!=null&&d.extensions){const L=d?.extensions[G];if(L!=null&&L.guid&&L.guid===M.guid){m=!0;break}}g++}if(m){const d=await I.getDependency("mesh",g),L=M;if(i&&console.log(`Loaded Mesh "${d.name}"`,f,g,d,p),d.isMesh===!0){const b=d.geometry;return w.assignLODInformation(a.url,b,u,e,void 0,L.density),c(b)}else{const b=new Array;for(let C=0;C<d.children.length;C++){const F=d.children[C];if(F.isMesh===!0){const X=F.geometry;w.assignLODInformation(a.url,X,u,e,C,L.density),b.push(X)}}return c(b)}}else v&&console.warn("Could not find mesh with guid",M.guid,O.parser.json)}return c(null)});return this.previouslyLoaded.set(p,x),await x}else if(t instanceof Z){i&&console.log("Load texture from uri: "+f);const p=await new Ne().loadAsync(f);return p?(p.guid=l.guid,p.flipY=!1,p.needsUpdate=!0,p.colorSpace=t.colorSpace,i&&console.log(l,p)):v&&console.warn("failed loading",f),p}}else v&&console.warn(`Can not load LOD ${e}: no LOD info found for "${u}" ${t.name}`,t.type);return null}static assignLODInformation(t,e,r,n,s,o){if(!e)return;e.userData||(e.userData={});const i=new nt(t,r,n,s,o);e.userData.LODS=i}static getAssignedLODInformation(t){var e;return((e=t?.userData)==null?void 0:e.LODS)||null}static copySettings(t,e){return e=e.clone(),v&&console.warn(`Copying texture settings
|
|
4
4
|
`,t.uuid,`
|
|
5
|
-
`,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}};let b=w;b.registerTexture=(t,e,r,n,s)=>{if(v&&console.log("> Progressive: register texture",n,e.name,e.uuid,e,s),!e){v&&console.error("gltf-progressive: Register texture without texture");return}e.source&&(e.source[Le]=s);const o=s.guid;w.assignLODInformation(t,e,o,r,n,void 0),w.lodInfos.set(o,s),w.lowresCache.set(o,e)},b.registerMesh=(t,e,r,n,s,o)=>{var i;v&&console.log("> Progressive: register mesh",s,r.name,o,r.uuid,r);const a=r.geometry;if(!a){v&&console.warn("gltf-progressive: Register mesh without geometry");return}a.userData||(a.userData={}),w.assignLODInformation(t,a,e,n,s,o.density),w.lodInfos.set(e,o);let u=w.lowresCache.get(e);u?u.push(r.geometry):u=[r.geometry],w.lowresCache.set(e,u),n>0&&!Y(r)&&rt(r,a);for(const l of N)(i=l.onRegisteredNewMesh)==null||i.call(l,r,o)},b.lodInfos=new Map,b.previouslyLoaded=new Map,b.lowresCache=new Map;class nt{constructor(e,r,n,s,o){this.url=e,this.key=r,this.level=n,s!=null&&(this.index=s),o!=null&&(this.density=o)}}var Pe=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)},y=(t,e,r)=>(Pe(t,e,"read from private field"),r?r.call(t):e.get(t)),H=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},W=(t,e,r,n)=>(Pe(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),T,$,we,J,oe,ce,U;const I=te("debugprogressive"),it=te("noprogressive"),De=Symbol("Needle:LODSManager"),_e=Symbol("Needle:LODState"),Q=Symbol("Needle:CurrentLOD"),B={mesh_lod:-1,texture_lod:-1},P=class{constructor(t,e){this.projectionScreenMatrix=new Oe,this.targetTriangleDensity=2e5,this.updateInterval="auto",H(this,T,1),this.pause=!1,this.manual=!1,this._lodchangedlisteners=[],H(this,$,void 0),H(this,we,new Fe),H(this,J,0),H(this,oe,0),H(this,ce,0),H(this,U,0),this._fpsBuffer=[60,60,60,60,60],this._sphere=new $e,this._tempBox=new be,this._tempBox2=new be,this.tempMatrix=new Oe,this._tempWorldPosition=new R,this._tempBoxSize=new R,this._tempBox2Size=new R,this.renderer=t,this.context={...e}}static getObjectLODState(t){return t[_e]}static addPlugin(t){N.push(t)}static removePlugin(t){const e=N.indexOf(t);e>=0&&N.splice(e,1)}static get(t,e){if(t[De])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),t[De];const r=new P(t,{engine:"unknown",...e});return t[De]=r,r}get plugins(){return N}addEventListener(t,e){t==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(t,e){if(t==="changed"){const r=this._lodchangedlisteners.indexOf(e);r>=0&&this._lodchangedlisteners.splice(r,1)}}enable(){if(y(this,$))return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let t=0;W(this,$,this.renderer.render);const e=this;me(this.renderer),this.renderer.render=function(r,n){const s=e.renderer.getRenderTarget();(s==null||"isXRRenderTarget"in s&&s.isXRRenderTarget)&&(t=0,W(e,J,y(e,J)+1),W(e,oe,y(e,we).getDelta()),W(e,ce,y(e,ce)+y(e,oe)),e._fpsBuffer.shift(),e._fpsBuffer.push(1/y(e,oe)),W(e,U,e._fpsBuffer.reduce((i,a)=>i+a)/e._fpsBuffer.length),I&&y(e,J)%200===0&&console.log("FPS",Math.round(y(e,U)),"Interval:",y(e,T)));const o=t++;y(e,$).call(this,r,n),e.onAfterRender(r,n,o)}}disable(){y(this,$)&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=y(this,$),W(this,$,void 0))}update(t,e){this.internalUpdate(t,e)}onAfterRender(t,e,r){if(this.pause)return;const n=this.renderer.renderLists.get(t,0).opaque;let s=!0;if(n.length===1){const o=n[0].material;(o.name==="EffectMaterial"||o.name==="CopyShader")&&(s=!1)}if((e.parent&&e.parent.type==="CubeCamera"||r>=1&&e.type==="OrthographicCamera")&&(s=!1),s){if(it||(this.updateInterval==="auto"?y(this,U)<40&&y(this,T)<10?(W(this,T,y(this,T)+1),I&&console.warn("\u2193 Reducing LOD updates",y(this,T),y(this,U).toFixed(0))):y(this,U)>=60&&y(this,T)>1&&(W(this,T,y(this,T)-1),I&&console.warn("\u2191 Increasing LOD updates",y(this,T),y(this,U).toFixed(0))):W(this,T,this.updateInterval),y(this,T)>0&&y(this,J)%y(this,T)!=0))return;this.internalUpdate(t,e)}}internalUpdate(t,e){var r,n;const s=this.renderer.renderLists.get(t,0),o=s.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const i=this.targetTriangleDensity;for(const l of o){if(l.material&&(((r=l.geometry)==null?void 0:r.type)==="BoxGeometry"||((n=l.geometry)==null?void 0:n.type)==="BufferGeometry")&&(l.material.name==="SphericalGaussianBlur"||l.material.name=="BackgroundCubeMaterial"||l.material.name==="CubemapFromEquirect"||l.material.name==="EquirectangularToCubeUV")){I&&(l.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(l.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",l,l.material.name,l.material.type)));continue}switch(l.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(I==="color"&&l.material&&!l.object.progressive_debug_color){l.object.progressive_debug_color=!0;const f=Math.random()*16777215,m=new Ue({color:f});l.object.material=m}const h=l.object;(h instanceof z||h.isMesh)&&this.updateLODs(t,e,h,i)}const a=s.transparent;for(const l of a){const h=l.object;(h instanceof z||h.isMesh)&&this.updateLODs(t,e,h,i)}const u=s.transmissive;for(const l of u){const h=l.object;(h instanceof z||h.isMesh)&&this.updateLODs(t,e,h,i)}}updateLODs(t,e,r,n){var s,o;r.userData||(r.userData={});let i=r[_e];if(i||(i=new lt,r[_e]=i),i.frames++<2)return;for(const u of N)(s=u.onBeforeUpdateLOD)==null||s.call(u,this.renderer,t,e,r);this.calculateLodLevel(e,r,i,n,B),B.mesh_lod=Math.round(B.mesh_lod),B.texture_lod=Math.round(B.texture_lod),B.mesh_lod>=0&&this.loadProgressiveMeshes(r,B.mesh_lod);let a=B.texture_lod;if(r.material&&a>=0){const u=r["DEBUG:LOD"];u!=null&&(a=u),this.loadProgressiveTextures(r.material,a)}for(const u of N)(o=u.onAfterUpdatedLOD)==null||o.call(u,this.renderer,t,e,r,B);i.lastLodLevel_Mesh=B.mesh_lod,i.lastLodLevel_Texture=B.texture_lod}loadProgressiveTextures(t,e){if(!t)return;if(Array.isArray(t)){for(const n of t)this.loadProgressiveTextures(n,e);return}let r=!1;(t[Q]===void 0||e<t[Q])&&(r=!0),r&&(t[Q]=e,b.assignTextureLOD(t,e).then(n=>{this._lodchangedlisteners.forEach(s=>s({type:"texture",level:e,object:t}))}))}loadProgressiveMeshes(t,e){if(!t)return Promise.resolve(null);if(t[Q]!==e){t[Q]=e;const r=t.geometry;return b.assignMeshLOD(t,e).then(n=>(n&&t[Q]==e&&r!=t.geometry&&this._lodchangedlisteners.forEach(s=>s({type:"mesh",level:e,object:t})),n))}return Promise.resolve(null)}static isInside(t,e){const r=t.min,n=t.max,s=(r.x+n.x)*.5,o=(r.y+n.y)*.5;return this._tempPtInside.set(s,o,r.z).applyMatrix4(e).z<0}calculateLodLevel(t,e,r,n,s){var o;if(!e){s.mesh_lod=-1,s.texture_lod=-1;return}if(!t){s.mesh_lod=-1,s.texture_lod=-1;return}let i=10+1,a=!1;if(I&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const u=b.getMeshLODInformation(e.geometry),l=u?.lods,h=l&&l.length>0,f=b.getMaterialMinMaxLODsCount(e.material),m=f?.min_count!=1/0&&f.min_count>0&&f.max_count>0;if(!h&&!m){s.mesh_lod=0,s.texture_lod=0;return}h||(a=!0,i=0);const E=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let M=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const x=e;if(!x.boundingBox)x.computeBoundingBox();else if(r.frames%30===0){const c=Y(x),D=x.geometry;c&&(x.geometry=c),x.computeBoundingBox(),x.geometry=D}M=x.boundingBox}if(M&&t.isPerspectiveCamera){const x=t;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const p=t.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(p)){s.mesh_lod=0,s.texture_lod=0;return}}if(this._tempBox.copy(M),this._tempBox.applyMatrix4(e.matrixWorld),P.isInside(this._tempBox,this.projectionScreenMatrix)){s.mesh_lod=0,s.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&x.fov>70){const p=this._tempBox.min,g=this._tempBox.max;let d=p.x,L=p.y,O=g.x,k=g.y;const F=2,X=1.5,ne=(p.x+g.x)*.5,ie=(p.y+g.y)*.5;d=(d-ne)*F+ne,L=(L-ie)*F+ie,O=(O-ne)*F+ne,k=(k-ie)*F+ie;const je=d<0&&O>0?0:Math.min(Math.abs(p.x),Math.abs(g.x)),We=L<0&&k>0?0:Math.min(Math.abs(p.y),Math.abs(g.y)),fe=Math.max(je,We);r.lastCentrality=(X-fe)*(X-fe)*(X-fe)}else r.lastCentrality=1;const c=this._tempBox.getSize(this._tempBoxSize);c.multiplyScalar(.5),screen.availHeight>0&&E>0&&c.multiplyScalar(E/screen.availHeight),c.x*=x.aspect;const D=t.matrixWorldInverse,_=this._tempBox2;_.copy(M),_.applyMatrix4(e.matrixWorld),_.applyMatrix4(D);const A=_.getSize(this._tempBox2Size),S=Math.max(A.x,A.y);if(Math.max(c.x,c.y)!=0&&S!=0&&(c.z=A.z/Math.max(A.x,A.y)*Math.max(c.x,c.y)),r.lastScreenCoverage=Math.max(c.x,c.y,c.z),r.lastScreenspaceVolume.copy(c),r.lastScreenCoverage*=r.lastCentrality,I&&P.debugDrawLine){const p=this.tempMatrix.copy(this.projectionScreenMatrix);p.invert();const g=P.corner0,d=P.corner1,L=P.corner2,O=P.corner3;g.copy(this._tempBox.min),d.copy(this._tempBox.max),d.x=g.x,L.copy(this._tempBox.max),L.y=g.y,O.copy(this._tempBox.max);const k=(g.z+O.z)*.5;g.z=d.z=L.z=O.z=k,g.applyMatrix4(p),d.applyMatrix4(p),L.applyMatrix4(p),O.applyMatrix4(p),P.debugDrawLine(g,d,255),P.debugDrawLine(g,L,255),P.debugDrawLine(d,O,255),P.debugDrawLine(L,O,255)}let G=999;if(l&&r.lastScreenCoverage>0){for(let p=0;p<l.length;p++)if(l[p].density/r.lastScreenCoverage<n){G=p;break}}G<i&&(i=G,a=!0)}if(a?s.mesh_lod=i:s.mesh_lod=r.lastLodLevel_Mesh,I&&s.mesh_lod!=r.lastLodLevel_Mesh){const x=l?.[s.mesh_lod];x&&console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} \u2192 ${s.mesh_lod} (${x.density.toFixed(0)}) - ${e.name}`)}if(m){const x="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(r.lastLodLevel_Texture<0){if(s.texture_lod=f.max_count-1,I){const c=f.lods[f.max_count-1];I&&console.log(`First Texture LOD ${s.texture_lod} (${c.max_height}px) - ${e.name}`)}}else{const c=r.lastScreenspaceVolume.x+r.lastScreenspaceVolume.y+r.lastScreenspaceVolume.z;let D=r.lastScreenCoverage*4;((o=this.context)==null?void 0:o.engine)==="model-viewer"&&(D*=1.5);const _=E/window.devicePixelRatio*D;for(let A=f.lods.length-1;A>=0;A--){let S=f.lods[A];if(!(x&&S.max_height>=2048)&&!(et()&&S.max_height>4096)&&S.max_height>_){if(s.texture_lod=A,s.texture_lod<r.lastLodLevel_Texture){const G=S.max_height;I&&console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} \u2192 ${s.texture_lod} = ${G}px
|
|
5
|
+
`,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}};let S=w;S.registerTexture=(t,e,r,n,s)=>{if(v&&console.log("> Progressive: register texture",n,e.name,e.uuid,e,s),!e){v&&console.error("gltf-progressive: Register texture without texture");return}e.source&&(e.source[Le]=s);const o=s.guid;w.assignLODInformation(t,e,o,r,n,void 0),w.lodInfos.set(o,s),w.lowresCache.set(o,e)},S.registerMesh=(t,e,r,n,s,o)=>{var i;v&&console.log("> Progressive: register mesh",s,r.name,o,r.uuid,r);const a=r.geometry;if(!a){v&&console.warn("gltf-progressive: Register mesh without geometry");return}a.userData||(a.userData={}),w.assignLODInformation(t,a,e,n,s,o.density),w.lodInfos.set(e,o);let u=w.lowresCache.get(e);u?u.push(r.geometry):u=[r.geometry],w.lowresCache.set(e,u),n>0&&!Y(r)&&rt(r,a);for(const l of N)(i=l.onRegisteredNewMesh)==null||i.call(l,r,o)},S.lodInfos=new Map,S.previouslyLoaded=new Map,S.lowresCache=new Map;class nt{constructor(e,r,n,s,o){this.url=e,this.key=r,this.level=n,s!=null&&(this.index=s),o!=null&&(this.density=o)}}var Pe=(t,e,r)=>{if(!e.has(t))throw TypeError("Cannot "+r)},y=(t,e,r)=>(Pe(t,e,"read from private field"),r?r.call(t):e.get(t)),H=(t,e,r)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,r)},W=(t,e,r,n)=>(Pe(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),T,$,we,J,oe,ce,U;const B=te("debugprogressive"),it=te("noprogressive"),De=Symbol("Needle:LODSManager"),_e=Symbol("Needle:LODState"),Q=Symbol("Needle:CurrentLOD"),k={mesh_lod:-1,texture_lod:-1},E=class{constructor(t,e){this.projectionScreenMatrix=new Oe,this.targetTriangleDensity=2e5,this.updateInterval="auto",H(this,T,1),this.pause=!1,this.manual=!1,this._lodchangedlisteners=[],H(this,$,void 0),H(this,we,new Fe),H(this,J,0),H(this,oe,0),H(this,ce,0),H(this,U,0),this._fpsBuffer=[60,60,60,60,60],this._sphere=new $e,this._tempBox=new be,this._tempBox2=new be,this.tempMatrix=new Oe,this._tempWorldPosition=new j,this._tempBoxSize=new j,this._tempBox2Size=new j,this.renderer=t,this.context={...e}}static getObjectLODState(t){return t[_e]}static addPlugin(t){N.push(t)}static removePlugin(t){const e=N.indexOf(t);e>=0&&N.splice(e,1)}static get(t,e){if(t[De])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),t[De];const r=new E(t,{engine:"unknown",...e});return t[De]=r,r}get plugins(){return N}addEventListener(t,e){t==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(t,e){if(t==="changed"){const r=this._lodchangedlisteners.indexOf(e);r>=0&&this._lodchangedlisteners.splice(r,1)}}enable(){if(y(this,$))return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let t=0;W(this,$,this.renderer.render);const e=this;me(this.renderer),this.renderer.render=function(r,n){const s=e.renderer.getRenderTarget();(s==null||"isXRRenderTarget"in s&&s.isXRRenderTarget)&&(t=0,W(e,J,y(e,J)+1),W(e,oe,y(e,we).getDelta()),W(e,ce,y(e,ce)+y(e,oe)),e._fpsBuffer.shift(),e._fpsBuffer.push(1/y(e,oe)),W(e,U,e._fpsBuffer.reduce((i,a)=>i+a)/e._fpsBuffer.length),B&&y(e,J)%200===0&&console.log("FPS",Math.round(y(e,U)),"Interval:",y(e,T)));const o=t++;y(e,$).call(this,r,n),e.onAfterRender(r,n,o)}}disable(){y(this,$)&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=y(this,$),W(this,$,void 0))}update(t,e){this.internalUpdate(t,e)}onAfterRender(t,e,r){if(this.pause)return;const n=this.renderer.renderLists.get(t,0).opaque;let s=!0;if(n.length===1){const o=n[0].material;(o.name==="EffectMaterial"||o.name==="CopyShader")&&(s=!1)}if((e.parent&&e.parent.type==="CubeCamera"||r>=1&&e.type==="OrthographicCamera")&&(s=!1),s){if(it||(this.updateInterval==="auto"?y(this,U)<40&&y(this,T)<10?(W(this,T,y(this,T)+1),B&&console.warn("\u2193 Reducing LOD updates",y(this,T),y(this,U).toFixed(0))):y(this,U)>=60&&y(this,T)>1&&(W(this,T,y(this,T)-1),B&&console.warn("\u2191 Increasing LOD updates",y(this,T),y(this,U).toFixed(0))):W(this,T,this.updateInterval),y(this,T)>0&&y(this,J)%y(this,T)!=0))return;this.internalUpdate(t,e)}}internalUpdate(t,e){var r,n;const s=this.renderer.renderLists.get(t,0),o=s.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const i=this.targetTriangleDensity;for(const l of o){if(l.material&&(((r=l.geometry)==null?void 0:r.type)==="BoxGeometry"||((n=l.geometry)==null?void 0:n.type)==="BufferGeometry")&&(l.material.name==="SphericalGaussianBlur"||l.material.name=="BackgroundCubeMaterial"||l.material.name==="CubemapFromEquirect"||l.material.name==="EquirectangularToCubeUV")){B&&(l.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(l.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",l,l.material.name,l.material.type)));continue}switch(l.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(B==="color"&&l.material&&!l.object.progressive_debug_color){l.object.progressive_debug_color=!0;const f=Math.random()*16777215,p=new Ue({color:f});l.object.material=p}const h=l.object;(h instanceof z||h.isMesh)&&this.updateLODs(t,e,h,i)}const a=s.transparent;for(const l of a){const h=l.object;(h instanceof z||h.isMesh)&&this.updateLODs(t,e,h,i)}const u=s.transmissive;for(const l of u){const h=l.object;(h instanceof z||h.isMesh)&&this.updateLODs(t,e,h,i)}}updateLODs(t,e,r,n){var s,o;r.userData||(r.userData={});let i=r[_e];if(i||(i=new lt,r[_e]=i),i.frames++<2)return;for(const u of N)(s=u.onBeforeUpdateLOD)==null||s.call(u,this.renderer,t,e,r);this.calculateLodLevel(e,r,i,n,k),k.mesh_lod=Math.round(k.mesh_lod),k.texture_lod=Math.round(k.texture_lod),k.mesh_lod>=0&&this.loadProgressiveMeshes(r,k.mesh_lod);let a=k.texture_lod;if(r.material&&a>=0){const u=r["DEBUG:LOD"];u!=null&&(a=u),this.loadProgressiveTextures(r.material,a)}for(const u of N)(o=u.onAfterUpdatedLOD)==null||o.call(u,this.renderer,t,e,r,k);i.lastLodLevel_Mesh=k.mesh_lod,i.lastLodLevel_Texture=k.texture_lod}loadProgressiveTextures(t,e){if(!t)return;if(Array.isArray(t)){for(const n of t)this.loadProgressiveTextures(n,e);return}let r=!1;(t[Q]===void 0||e<t[Q])&&(r=!0),r&&(t[Q]=e,S.assignTextureLOD(t,e).then(n=>{this._lodchangedlisteners.forEach(s=>s({type:"texture",level:e,object:t}))}))}loadProgressiveMeshes(t,e){if(!t)return Promise.resolve(null);if(t[Q]!==e){t[Q]=e;const r=t.geometry;return S.assignMeshLOD(t,e).then(n=>(n&&t[Q]==e&&r!=t.geometry&&this._lodchangedlisteners.forEach(s=>s({type:"mesh",level:e,object:t})),n))}return Promise.resolve(null)}static isInside(t,e){const r=t.min,n=t.max,s=(r.x+n.x)*.5,o=(r.y+n.y)*.5;return this._tempPtInside.set(s,o,r.z).applyMatrix4(e).z<0}calculateLodLevel(t,e,r,n,s){var o;if(!e){s.mesh_lod=-1,s.texture_lod=-1;return}if(!t){s.mesh_lod=-1,s.texture_lod=-1;return}let i=10+1,a=!1;if(B&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const u=S.getMeshLODInformation(e.geometry),l=u?.lods,h=l&&l.length>0,f=S.getMaterialMinMaxLODsCount(e.material),p=f?.min_count!=1/0&&f.min_count>0&&f.max_count>0;if(!h&&!p){s.mesh_lod=0,s.texture_lod=0;return}h||(a=!0,i=0);const A=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let M=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const x=e;if(!x.boundingBox)x.computeBoundingBox();else if(r.frames%30===0){const c=Y(x),D=x.geometry;c&&(x.geometry=c),x.computeBoundingBox(),x.geometry=D}M=x.boundingBox}if(M&&t.isPerspectiveCamera){const x=t;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const g=t.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(g)){s.mesh_lod=0,s.texture_lod=0;return}}if(this._tempBox.copy(M),this._tempBox.applyMatrix4(e.matrixWorld),E.isInside(this._tempBox,this.projectionScreenMatrix)){s.mesh_lod=0,s.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&x.fov>70){const g=this._tempBox.min,m=this._tempBox.max;let d=g.x,L=g.y,b=m.x,C=m.y;const F=2,X=1.5,ne=(g.x+m.x)*.5,ie=(g.y+m.y)*.5;d=(d-ne)*F+ne,L=(L-ie)*F+ie,b=(b-ne)*F+ne,C=(C-ie)*F+ie;const je=d<0&&b>0?0:Math.min(Math.abs(g.x),Math.abs(m.x)),Ge=L<0&&C>0?0:Math.min(Math.abs(g.y),Math.abs(m.y)),fe=Math.max(je,Ge);r.lastCentrality=(X-fe)*(X-fe)*(X-fe)}else r.lastCentrality=1;const c=this._tempBox.getSize(this._tempBoxSize);c.multiplyScalar(.5),screen.availHeight>0&&A>0&&c.multiplyScalar(A/screen.availHeight),c.x*=x.aspect;const D=t.matrixWorldInverse,_=this._tempBox2;_.copy(M),_.applyMatrix4(e.matrixWorld),_.applyMatrix4(D);const P=_.getSize(this._tempBox2Size),O=Math.max(P.x,P.y);if(Math.max(c.x,c.y)!=0&&O!=0&&(c.z=P.z/Math.max(P.x,P.y)*Math.max(c.x,c.y)),r.lastScreenCoverage=Math.max(c.x,c.y,c.z),r.lastScreenspaceVolume.copy(c),r.lastScreenCoverage*=r.lastCentrality,B&&E.debugDrawLine){const g=this.tempMatrix.copy(this.projectionScreenMatrix);g.invert();const m=E.corner0,d=E.corner1,L=E.corner2,b=E.corner3;m.copy(this._tempBox.min),d.copy(this._tempBox.max),d.x=m.x,L.copy(this._tempBox.max),L.y=m.y,b.copy(this._tempBox.max);const C=(m.z+b.z)*.5;m.z=d.z=L.z=b.z=C,m.applyMatrix4(g),d.applyMatrix4(g),L.applyMatrix4(g),b.applyMatrix4(g),E.debugDrawLine(m,d,255),E.debugDrawLine(m,L,255),E.debugDrawLine(d,b,255),E.debugDrawLine(L,b,255)}let I=999;if(l&&r.lastScreenCoverage>0){for(let g=0;g<l.length;g++)if(l[g].density/r.lastScreenCoverage<n){I=g;break}}I<i&&(i=I,a=!0)}if(a?s.mesh_lod=i:s.mesh_lod=r.lastLodLevel_Mesh,B&&s.mesh_lod!=r.lastLodLevel_Mesh){const x=l?.[s.mesh_lod];x&&console.log(`Mesh LOD changed: ${r.lastLodLevel_Mesh} \u2192 ${s.mesh_lod} (${x.density.toFixed(0)}) - ${e.name}`)}if(p){const x="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(r.lastLodLevel_Texture<0){if(s.texture_lod=f.max_count-1,B){const c=f.lods[f.max_count-1];B&&console.log(`First Texture LOD ${s.texture_lod} (${c.max_height}px) - ${e.name}`)}}else{const c=r.lastScreenspaceVolume.x+r.lastScreenspaceVolume.y+r.lastScreenspaceVolume.z;let D=r.lastScreenCoverage*4;((o=this.context)==null?void 0:o.engine)==="model-viewer"&&(D*=1.5);const _=A/window.devicePixelRatio*D;let P=!1;for(let O=f.lods.length-1;O>=0;O--){let I=f.lods[O];if(!(x&&I.max_height>=2048)&&!(et()&&I.max_height>4096)&&(I.max_height>_||!P&&O===0)){if(P=!0,s.texture_lod=O,s.texture_lod<r.lastLodLevel_Texture){const g=I.max_height;B&&console.log(`Texture LOD changed: ${r.lastLodLevel_Texture} \u2192 ${s.texture_lod} = ${g}px
|
|
6
6
|
Screensize: ${_.toFixed(0)}px, Coverage: ${(100*r.lastScreenCoverage).toFixed(2)}%, Volume ${c.toFixed(1)}
|
|
7
|
-
${e.name}`)}break}}}}else s.texture_lod=0}};let
|
|
8
|
-
`,t.getAttribute("src"));let e=null,r=null,n=null;for(let s=t;s!=null;s=Object.getPrototypeOf(s)){const o=Object.getOwnPropertySymbols(s),i=o.find(l=>l.toString()=="Symbol(renderer)"),a=o.find(l=>l.toString()=="Symbol(scene)"),u=o.find(l=>l.toString()=="Symbol(needsRender)");!e&&i!=null&&(e=t[i].threeRenderer),!r&&a!=null&&(r=t[a]),!n&&u!=null&&(n=t[u])}if(e&&r){let s=function(){if(n){let i=0,a=setInterval(()=>{if(i++>5){clearInterval(a);return}n?.call(t)},300)}};console.debug("[gltf-progressive] setup model-viewer");const o=
|
|
7
|
+
${e.name}`)}break}}}}else s.texture_lod=0}};let R=E;T=new WeakMap,$=new WeakMap,we=new WeakMap,J=new WeakMap,oe=new WeakMap,ce=new WeakMap,U=new WeakMap,R.corner0=new j,R.corner1=new j,R.corner2=new j,R.corner3=new j,R._tempPtInside=new j;class lt{constructor(){this.frames=0,this.lastLodLevel_Mesh=-1,this.lastLodLevel_Texture=-1,this.lastScreenCoverage=0,this.lastScreenspaceVolume=new j,this.lastCentrality=0}}const Ie=Symbol("NEEDLE_mesh_lod"),de=Symbol("NEEDLE_texture_lod");let he=null;function Be(){const t=at();t&&(t.mapURLs(function(e){return ke(),e}),ke(),he?.disconnect(),he=new MutationObserver(e=>{e.forEach(r=>{r.addedNodes.forEach(n=>{n instanceof HTMLElement&&n.tagName.toLowerCase()==="model-viewer"&&Re(n)})})}),he.observe(document,{childList:!0,subtree:!0}))}function at(){return typeof customElements>"u"?null:customElements.get("model-viewer")||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Be()}),null)}function ke(){typeof document>"u"||document.querySelectorAll("model-viewer").forEach(t=>{Re(t)})}const Ce=new WeakSet;let ut=0;function Re(t){if(!t||Ce.has(t))return null;Ce.add(t),console.debug("[gltf-progressive] found new model-viewer..."+ ++ut+`
|
|
8
|
+
`,t.getAttribute("src"));let e=null,r=null,n=null;for(let s=t;s!=null;s=Object.getPrototypeOf(s)){const o=Object.getOwnPropertySymbols(s),i=o.find(l=>l.toString()=="Symbol(renderer)"),a=o.find(l=>l.toString()=="Symbol(scene)"),u=o.find(l=>l.toString()=="Symbol(needsRender)");!e&&i!=null&&(e=t[i].threeRenderer),!r&&a!=null&&(r=t[a]),!n&&u!=null&&(n=t[u])}if(e&&r){let s=function(){if(n){let i=0,a=setInterval(()=>{if(i++>5){clearInterval(a);return}n?.call(t)},300)}};console.debug("[gltf-progressive] setup model-viewer");const o=R.get(e,{engine:"model-viewer"});return R.addPlugin(new ct),o.enable(),o.addEventListener("changed",()=>{n?.call(t)}),t.addEventListener("model-visibility",i=>{i.detail.visible&&n?.call(t)}),t.addEventListener("load",()=>{s()}),()=>{o.disable()}}return null}class ct{constructor(){this._didWarnAboutMissingUrl=!1}onBeforeUpdateLOD(e,r,n,s){this.tryParseMeshLOD(r,s),this.tryParseTextureLOD(r,s)}getUrl(e){if(!e)return null;let r=e.getAttribute("src");return r||(r=e.src),r||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",e),this._didWarnAboutMissingUrl=!0),r}tryGetCurrentGLTF(e){return e._currentGLTF}tryGetCurrentModelViewer(e){return e.element}tryParseTextureLOD(e,r){if(r[de]==!0)return;r[de]=!0;const n=this.tryGetCurrentGLTF(e),s=this.tryGetCurrentModelViewer(e),o=this.getUrl(s);if(o&&n&&r.material){let i=function(u){var l,h,f;if(u[de]==!0)return;u[de]=!0,u.userData&&(u.userData.LOD=-1);const p=Object.keys(u);for(let A=0;A<p.length;A++){const M=p[A],x=u[M];if(x?.isTexture===!0){const c=(h=(l=x.userData)==null?void 0:l.associations)==null?void 0:h.textures;if(c==null)continue;const D=n.parser.json.textures[c];if(!D){console.warn("Texture data not found for texture index "+c);continue}if((f=D?.extensions)!=null&&f[G]){const _=D.extensions[G];_&&o&&S.registerTexture(o,x,_.lods.length,c,_)}}}};const a=r.material;if(Array.isArray(a))for(const u of a)i(u);else i(a)}}tryParseMeshLOD(e,r){var n,s;if(r[Ie]==!0)return;r[Ie]=!0;const o=this.tryGetCurrentModelViewer(e),i=this.getUrl(o);if(!i)return;const a=(s=(n=r.userData)==null?void 0:n.gltfExtensions)==null?void 0:s[G];if(a&&i){const u=r.uuid;S.registerMesh(i,u,r,0,a.lods.length,a)}}}function dt(t,e,r,n){me(e),pe(r),ye(r,{progressive:!0,...n?.hints}),r.register(o=>new S(o,t));const s=R.get(e);return n?.enableLODsManager!==!1&&s.enable(),s}if(Be(),!tt){const t={gltfProgressive:{useNeedleProgressive:dt,LODsManager:R,configureLoader:ye,getRaycastMesh:Y,useRaycastMeshes:st}};if(!globalThis.Needle)globalThis.Needle=t;else for(const e in t)globalThis.Needle[e]=t[e]}export{R as L,S as N,pe as a,ye as b,me as c,Je as d,Y as g,Ye as s};
|