@needle-tools/engine 4.2.2 → 4.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/gltf-progressive.js +258 -257
- package/dist/gltf-progressive.light.js +258 -257
- package/dist/gltf-progressive.light.min.js +7 -7
- package/dist/gltf-progressive.light.umd.cjs +7 -7
- package/dist/gltf-progressive.min.js +7 -7
- package/dist/gltf-progressive.umd.cjs +7 -7
- package/dist/needle-engine.bundle.js +3455 -3426
- package/dist/needle-engine.bundle.light.js +3449 -3420
- package/dist/needle-engine.bundle.light.min.js +106 -106
- package/dist/needle-engine.bundle.light.umd.cjs +103 -103
- package/dist/needle-engine.bundle.min.js +106 -106
- package/dist/needle-engine.bundle.umd.cjs +101 -101
- package/dist/needle-engine.d.ts +9 -9
- package/dist/needle-engine.light.d.ts +9 -9
- package/lib/engine/engine_context.d.ts +1 -0
- package/lib/engine/engine_context.js +7 -3
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_loaders.js +6 -12
- package/lib/engine/engine_loaders.js.map +1 -1
- package/lib/engine/engine_physics_rapier.js +1 -1
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +9 -2
- package/lib/engine-components/OrbitControls.js +62 -19
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ui/InputField.d.ts +1 -0
- package/lib/engine-components/ui/InputField.js +11 -0
- package/lib/engine-components/ui/InputField.js.map +1 -1
- package/package.json +2 -2
- package/plugins/types/userconfig.d.ts +2 -2
- package/plugins/vite/pwa.js +33 -22
- package/src/engine/codegen/register_types.ts +2 -2
- package/src/engine/engine_context.ts +7 -3
- package/src/engine/engine_loaders.ts +6 -10
- package/src/engine/engine_physics_rapier.ts +1 -1
- package/src/engine-components/OrbitControls.ts +71 -21
- package/src/engine-components/ui/InputField.ts +9 -0
|
@@ -1,43 +1,44 @@
|
|
|
1
|
-
import { B as he, M as
|
|
2
|
-
import { D as
|
|
3
|
-
const
|
|
4
|
-
globalThis.GLTF_PROGRESSIVE_VERSION =
|
|
5
|
-
console.debug(
|
|
6
|
-
let
|
|
7
|
-
const
|
|
8
|
-
fetch(
|
|
1
|
+
import { B as he, M as Q, T as ee, a as We, V as z, b as be, S as ze, c as Te, d as Ve, C as Ke } from "./three.light.js";
|
|
2
|
+
import { D as Xe, K as qe, G as Se, M as Ye } from "./three-examples.light.js";
|
|
3
|
+
const He = "";
|
|
4
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = He;
|
|
5
|
+
console.debug("[gltf-progressive] version -");
|
|
6
|
+
let N = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", j = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
7
|
+
const Je = N, Qe = j, Ze = new URL(N + "draco_decoder.js");
|
|
8
|
+
fetch(Ze, {
|
|
9
9
|
method: "GET",
|
|
10
10
|
headers: {
|
|
11
11
|
Range: "bytes=0-1"
|
|
12
12
|
}
|
|
13
13
|
}).catch((t) => {
|
|
14
|
-
|
|
14
|
+
console.debug(`Failed to fetch remote Draco decoder from ${N} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), N === Je && je("./include/draco/"), j === Qe && et("./include/ktx2/");
|
|
15
15
|
}).finally(() => {
|
|
16
16
|
ke();
|
|
17
17
|
});
|
|
18
|
-
function
|
|
19
|
-
|
|
18
|
+
function je(t) {
|
|
19
|
+
N = t, A && A[De] != N ? (console.debug("Updating Draco decoder path to " + t), A[De] = N, A.setDecoderPath(N), A.preload()) : console.debug("Setting Draco decoder path to " + t);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
21
|
+
function et(t) {
|
|
22
|
+
j = t, G && G.transcoderPath != j ? (console.debug("Updating KTX2 transcoder path to " + t), G.setTranscoderPath(j), G.init()) : console.debug("Setting KTX2 transcoder path to " + t);
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const De = Symbol("dracoDecoderPath");
|
|
25
|
+
let A, ge, G;
|
|
25
26
|
function ke() {
|
|
26
|
-
|
|
27
|
+
A || (A = new Xe(), A[De] = N, A.setDecoderPath(N), A.setDecoderConfig({ type: "js" }), A.preload()), G || (G = new qe(), G.setTranscoderPath(j), G.init()), ge || (ge = Ye);
|
|
27
28
|
}
|
|
28
29
|
function Be(t) {
|
|
29
|
-
return ke(), t ?
|
|
30
|
+
return ke(), t ? G.detectSupport(t) : t !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: A, ktx2Loader: G, meshoptDecoder: ge };
|
|
30
31
|
}
|
|
31
32
|
function Re(t) {
|
|
32
|
-
t.dracoLoader || t.setDRACOLoader(
|
|
33
|
+
t.dracoLoader || t.setDRACOLoader(A), t.ktx2Loader || t.setKTX2Loader(G), t.meshoptDecoder || t.setMeshoptDecoder(ge);
|
|
33
34
|
}
|
|
34
35
|
const Me = /* @__PURE__ */ new WeakMap();
|
|
35
36
|
function Ie(t, e) {
|
|
36
37
|
let s = Me.get(t);
|
|
37
38
|
s ? s = Object.assign(s, e) : s = e, Me.set(t, s);
|
|
38
39
|
}
|
|
39
|
-
const Le =
|
|
40
|
-
function
|
|
40
|
+
const Le = Se.prototype.load;
|
|
41
|
+
function tt(...t) {
|
|
41
42
|
const e = Me.get(this);
|
|
42
43
|
let s = t[0];
|
|
43
44
|
const n = new URL(s, window.location.href);
|
|
@@ -47,7 +48,7 @@ function Ze(...t) {
|
|
|
47
48
|
}
|
|
48
49
|
return t[0] = s, Le == null ? void 0 : Le.call(this, ...t);
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
+
Se.prototype.load = tt;
|
|
51
52
|
oe("debugprogressive");
|
|
52
53
|
function oe(t) {
|
|
53
54
|
if (typeof window > "u")
|
|
@@ -55,7 +56,7 @@ function oe(t) {
|
|
|
55
56
|
const s = new URL(window.location.href).searchParams.get(t);
|
|
56
57
|
return s == null || s === "0" || s === "false" ? !1 : s === "" ? !0 : s;
|
|
57
58
|
}
|
|
58
|
-
function
|
|
59
|
+
function st(t, e) {
|
|
59
60
|
if (e === void 0 || e.startsWith("./") || e.startsWith("http") || t === void 0)
|
|
60
61
|
return e;
|
|
61
62
|
const s = t.lastIndexOf("/");
|
|
@@ -67,52 +68,52 @@ function je(t, e) {
|
|
|
67
68
|
}
|
|
68
69
|
return e;
|
|
69
70
|
}
|
|
70
|
-
let
|
|
71
|
-
function
|
|
72
|
-
return
|
|
71
|
+
let te;
|
|
72
|
+
function rt() {
|
|
73
|
+
return te !== void 0 || (te = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), oe("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", te)), te;
|
|
73
74
|
}
|
|
74
|
-
const
|
|
75
|
+
const it = typeof window > "u" && typeof document > "u", _e = Symbol("needle:raycast-mesh");
|
|
75
76
|
function ae(t) {
|
|
76
|
-
return (t == null ? void 0 : t[
|
|
77
|
+
return (t == null ? void 0 : t[_e]) instanceof he ? t[_e] : null;
|
|
77
78
|
}
|
|
78
|
-
function
|
|
79
|
+
function nt(t, e) {
|
|
79
80
|
if ((t.type === "Mesh" || t.type === "SkinnedMesh") && !ae(t)) {
|
|
80
|
-
const n =
|
|
81
|
-
n.userData = { isRaycastMesh: !0 }, t[
|
|
81
|
+
const n = at(e);
|
|
82
|
+
n.userData = { isRaycastMesh: !0 }, t[_e] = n;
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
|
-
function
|
|
85
|
+
function ot(t = !0) {
|
|
85
86
|
if (t) {
|
|
86
|
-
if (
|
|
87
|
+
if (se)
|
|
87
88
|
return;
|
|
88
|
-
const e =
|
|
89
|
-
|
|
89
|
+
const e = se = Q.prototype.raycast;
|
|
90
|
+
Q.prototype.raycast = function(s, n) {
|
|
90
91
|
const i = this, r = ae(i);
|
|
91
92
|
let o;
|
|
92
93
|
r && i.isMesh && (o = i.geometry, i.geometry = r), e.call(this, s, n), o && (i.geometry = o);
|
|
93
94
|
};
|
|
94
95
|
} else {
|
|
95
|
-
if (!
|
|
96
|
+
if (!se)
|
|
96
97
|
return;
|
|
97
|
-
|
|
98
|
+
Q.prototype.raycast = se, se = null;
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
let
|
|
101
|
-
function
|
|
101
|
+
let se = null;
|
|
102
|
+
function at(t) {
|
|
102
103
|
const e = new he();
|
|
103
104
|
for (const s in t.attributes)
|
|
104
105
|
e.setAttribute(s, t.getAttribute(s));
|
|
105
106
|
return e.setIndex(t.getIndex()), e;
|
|
106
107
|
}
|
|
107
|
-
const
|
|
108
|
+
const H = new Array(), W = "NEEDLE_progressive", p = oe("debugprogressive"), ve = Symbol("needle-progressive-texture"), ne = /* @__PURE__ */ new Map(), we = /* @__PURE__ */ new Set();
|
|
108
109
|
if (p) {
|
|
109
110
|
let t = function() {
|
|
110
|
-
e += 1, console.log("Toggle LOD level", e,
|
|
111
|
+
e += 1, console.log("Toggle LOD level", e, ne), ne.forEach((i, r) => {
|
|
111
112
|
for (const o of i.keys) {
|
|
112
113
|
const a = r[o];
|
|
113
114
|
if (a != null)
|
|
114
115
|
if (a.isBufferGeometry === !0) {
|
|
115
|
-
const c =
|
|
116
|
+
const c = P.getMeshLODInformation(a), l = c ? Math.min(e, c.lods.length) : 0;
|
|
116
117
|
r["DEBUG:LOD"] = l, c && (s = Math.max(s, c.lods.length - 1));
|
|
117
118
|
} else
|
|
118
119
|
r.isMaterial === !0 && (r["DEBUG:LOD"] = e);
|
|
@@ -120,7 +121,7 @@ if (p) {
|
|
|
120
121
|
}), e >= s && (e = -1);
|
|
121
122
|
}, e = -1, s = 2, n = !1;
|
|
122
123
|
window.addEventListener("keyup", (i) => {
|
|
123
|
-
i.key === "p" && t(), i.key === "w" && (n = !n,
|
|
124
|
+
i.key === "p" && t(), i.key === "w" && (n = !n, we && we.forEach((r) => {
|
|
124
125
|
r.name != "BackgroundCubeMaterial" && r.glyphMap == null && "wireframe" in r && (r.wireframe = n);
|
|
125
126
|
}));
|
|
126
127
|
});
|
|
@@ -129,26 +130,26 @@ function Ee(t, e, s) {
|
|
|
129
130
|
var i;
|
|
130
131
|
if (!p)
|
|
131
132
|
return;
|
|
132
|
-
|
|
133
|
-
const n =
|
|
133
|
+
ne.has(t) || ne.set(t, { keys: [], sourceId: s });
|
|
134
|
+
const n = ne.get(t);
|
|
134
135
|
((i = n == null ? void 0 : n.keys) == null ? void 0 : i.includes(e)) == !1 && n.keys.push(e);
|
|
135
136
|
}
|
|
136
|
-
const
|
|
137
|
+
const M = class {
|
|
137
138
|
constructor(t, e) {
|
|
138
139
|
this.loadMesh = (s) => {
|
|
139
140
|
var i, r;
|
|
140
141
|
if (this._isLoadingMesh)
|
|
141
142
|
return null;
|
|
142
|
-
const n = (r = (i = this.parser.json.meshes[s]) == null ? void 0 : i.extensions) == null ? void 0 : r[
|
|
143
|
+
const n = (r = (i = this.parser.json.meshes[s]) == null ? void 0 : i.extensions) == null ? void 0 : r[W];
|
|
143
144
|
return n ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", s).then((o) => {
|
|
144
145
|
var a;
|
|
145
|
-
return this._isLoadingMesh = !1, o &&
|
|
146
|
+
return this._isLoadingMesh = !1, o && M.registerMesh(this.url, n.guid, o, (a = n.lods) == null ? void 0 : a.length, void 0, n), o;
|
|
146
147
|
})) : null;
|
|
147
148
|
}, p && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
|
|
148
149
|
}
|
|
149
150
|
/** The name of the extension */
|
|
150
151
|
get name() {
|
|
151
|
-
return
|
|
152
|
+
return W;
|
|
152
153
|
}
|
|
153
154
|
static getMeshLODInformation(t) {
|
|
154
155
|
const e = this.getAssignedLODInformation(t);
|
|
@@ -246,13 +247,13 @@ const D = class {
|
|
|
246
247
|
var s;
|
|
247
248
|
if (!t)
|
|
248
249
|
return Promise.resolve(null);
|
|
249
|
-
if (t instanceof
|
|
250
|
+
if (t instanceof Q || t.isMesh === !0) {
|
|
250
251
|
const n = t.geometry, i = this.getAssignedLODInformation(n);
|
|
251
252
|
if (!i)
|
|
252
253
|
return Promise.resolve(null);
|
|
253
|
-
for (const r of
|
|
254
|
+
for (const r of H)
|
|
254
255
|
(s = r.onBeforeGetLODMesh) == null || s.call(r, t, e);
|
|
255
|
-
return t["LOD:requested level"] = e,
|
|
256
|
+
return t["LOD:requested level"] = e, M.getOrLoadLOD(n, e).then((r) => {
|
|
256
257
|
if (Array.isArray(r)) {
|
|
257
258
|
const o = i.index || 0;
|
|
258
259
|
r = r[o];
|
|
@@ -285,7 +286,7 @@ const D = class {
|
|
|
285
286
|
}
|
|
286
287
|
if (t.isMaterial === !0) {
|
|
287
288
|
const s = t, n = [], i = new Array();
|
|
288
|
-
if (p &&
|
|
289
|
+
if (p && we.add(s), s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
|
|
289
290
|
const r = s;
|
|
290
291
|
for (const o of Object.keys(r.uniforms)) {
|
|
291
292
|
const a = r.uniforms[o].value;
|
|
@@ -311,14 +312,14 @@ const D = class {
|
|
|
311
312
|
return o;
|
|
312
313
|
});
|
|
313
314
|
}
|
|
314
|
-
if (t instanceof
|
|
315
|
+
if (t instanceof ee || t.isTexture === !0) {
|
|
315
316
|
const s = t;
|
|
316
317
|
return this.assignTextureLODForSlot(s, e, null, null);
|
|
317
318
|
}
|
|
318
319
|
return Promise.resolve(null);
|
|
319
320
|
}
|
|
320
321
|
static assignTextureLODForSlot(t, e, s, n) {
|
|
321
|
-
return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) :
|
|
322
|
+
return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) : M.getOrLoadLOD(t, e).then((i) => {
|
|
322
323
|
if (Array.isArray(i))
|
|
323
324
|
return null;
|
|
324
325
|
if ((i == null ? void 0 : i.isTexture) === !0) {
|
|
@@ -348,7 +349,7 @@ const D = class {
|
|
|
348
349
|
return p && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, i) => {
|
|
349
350
|
var r;
|
|
350
351
|
if (n != null && n.extensions) {
|
|
351
|
-
const o = n == null ? void 0 : n.extensions[
|
|
352
|
+
const o = n == null ? void 0 : n.extensions[W];
|
|
352
353
|
if (o) {
|
|
353
354
|
if (!o.lods) {
|
|
354
355
|
p && console.warn("Texture has no LODs", o);
|
|
@@ -358,22 +359,22 @@ const D = class {
|
|
|
358
359
|
for (const c of this.parser.associations.keys())
|
|
359
360
|
if (c.isTexture === !0) {
|
|
360
361
|
const l = this.parser.associations.get(c);
|
|
361
|
-
(l == null ? void 0 : l.textures) === i && (a = !0,
|
|
362
|
+
(l == null ? void 0 : l.textures) === i && (a = !0, M.registerTexture(this.url, c, (r = o.lods) == null ? void 0 : r.length, i, o));
|
|
362
363
|
}
|
|
363
364
|
a || this.parser.getDependency("texture", i).then((c) => {
|
|
364
365
|
var l;
|
|
365
|
-
c &&
|
|
366
|
+
c && M.registerTexture(this.url, c, (l = o.lods) == null ? void 0 : l.length, i, o);
|
|
366
367
|
});
|
|
367
368
|
}
|
|
368
369
|
}
|
|
369
370
|
}), (s = this.parser.json.meshes) == null || s.forEach((n, i) => {
|
|
370
371
|
if (n != null && n.extensions) {
|
|
371
|
-
const r = n == null ? void 0 : n.extensions[
|
|
372
|
+
const r = n == null ? void 0 : n.extensions[W];
|
|
372
373
|
if (r && r.lods) {
|
|
373
374
|
for (const o of this.parser.associations.keys())
|
|
374
375
|
if (o.isMesh) {
|
|
375
376
|
const a = this.parser.associations.get(o);
|
|
376
|
-
(a == null ? void 0 : a.meshes) === i &&
|
|
377
|
+
(a == null ? void 0 : a.meshes) === i && M.registerMesh(this.url, r.guid, o, r.lods.length, a.primitives, r);
|
|
377
378
|
}
|
|
378
379
|
}
|
|
379
380
|
}
|
|
@@ -388,9 +389,9 @@ const D = class {
|
|
|
388
389
|
let r;
|
|
389
390
|
if (t.isTexture === !0) {
|
|
390
391
|
const d = t;
|
|
391
|
-
d.source && d.source[
|
|
392
|
+
d.source && d.source[ve] && (r = d.source[ve]);
|
|
392
393
|
}
|
|
393
|
-
if (r || (r =
|
|
394
|
+
if (r || (r = M.lodInfos.get(i)), r) {
|
|
394
395
|
if (e > 0) {
|
|
395
396
|
let x = !1;
|
|
396
397
|
const L = Array.isArray(r.lods);
|
|
@@ -400,39 +401,39 @@ const D = class {
|
|
|
400
401
|
const d = Array.isArray(r.lods) ? (o = r.lods[e]) == null ? void 0 : o.path : r.lods;
|
|
401
402
|
if (!d)
|
|
402
403
|
return p && !r["missing:uri"] && (r["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, r)), null;
|
|
403
|
-
const h =
|
|
404
|
+
const h = st(n.url, d);
|
|
404
405
|
if (h.endsWith(".glb") || h.endsWith(".gltf")) {
|
|
405
406
|
if (!r.guid)
|
|
406
407
|
return console.warn("missing pointer for glb/gltf texture", r), null;
|
|
407
408
|
const x = h + "_" + r.guid, L = this.previouslyLoaded.get(x);
|
|
408
409
|
if (L !== void 0) {
|
|
409
410
|
s && console.log(`LOD ${e} was already loading/loaded: ${x}`);
|
|
410
|
-
let
|
|
411
|
-
`,
|
|
412
|
-
if (
|
|
413
|
-
return
|
|
411
|
+
let u = await L.catch(($) => (console.error(`Error loading LOD ${e} from ${h}
|
|
412
|
+
`, $), null)), w = !1;
|
|
413
|
+
if (u == null || (u instanceof ee && t instanceof ee ? (a = u.image) != null && a.data || (c = u.source) != null && c.data ? u = this.copySettings(t, u) : (w = !0, this.previouslyLoaded.delete(x)) : u instanceof he && t instanceof he && ((l = u.attributes.position) != null && l.array || (w = !0, this.previouslyLoaded.delete(x)))), !w)
|
|
414
|
+
return u;
|
|
414
415
|
}
|
|
415
|
-
const
|
|
416
|
-
const
|
|
417
|
-
Re(
|
|
418
|
-
let
|
|
419
|
-
if (
|
|
420
|
-
const O =
|
|
421
|
-
O.hash && (
|
|
416
|
+
const D = r, k = new Promise(async (u, w) => {
|
|
417
|
+
const $ = new Se();
|
|
418
|
+
Re($), p && (await new Promise((O) => setTimeout(O, 1e3)), s && console.warn("Start loading (delayed) " + h, D.guid));
|
|
419
|
+
let B = h;
|
|
420
|
+
if (D && Array.isArray(D.lods)) {
|
|
421
|
+
const O = D.lods[e];
|
|
422
|
+
O.hash && (B += "?v=" + O.hash);
|
|
422
423
|
}
|
|
423
|
-
const
|
|
424
|
+
const T = await $.loadAsync(B).catch((O) => (console.error(`Error loading LOD ${e} from ${h}
|
|
424
425
|
`, O), null));
|
|
425
|
-
if (!
|
|
426
|
+
if (!T)
|
|
426
427
|
return null;
|
|
427
|
-
const
|
|
428
|
-
s && console.log("Loading finished " + h,
|
|
428
|
+
const U = T.parser;
|
|
429
|
+
s && console.log("Loading finished " + h, D.guid);
|
|
429
430
|
let v = 0;
|
|
430
|
-
if (
|
|
431
|
+
if (T.parser.json.textures) {
|
|
431
432
|
let O = !1;
|
|
432
|
-
for (const
|
|
433
|
-
if (
|
|
434
|
-
const g =
|
|
435
|
-
if (g != null && g.guid && g.guid ===
|
|
433
|
+
for (const f of T.parser.json.textures) {
|
|
434
|
+
if (f != null && f.extensions) {
|
|
435
|
+
const g = f == null ? void 0 : f.extensions[W];
|
|
436
|
+
if (g != null && g.guid && g.guid === D.guid) {
|
|
436
437
|
O = !0;
|
|
437
438
|
break;
|
|
438
439
|
}
|
|
@@ -440,17 +441,17 @@ const D = class {
|
|
|
440
441
|
v++;
|
|
441
442
|
}
|
|
442
443
|
if (O) {
|
|
443
|
-
let
|
|
444
|
-
return
|
|
444
|
+
let f = await U.getDependency("texture", v);
|
|
445
|
+
return f && M.assignLODInformation(n.url, f, i, e, void 0, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', h, v, f, x), t instanceof ee && (f = this.copySettings(t, f)), f && (f.guid = D.guid), u(f);
|
|
445
446
|
} else
|
|
446
|
-
p && console.warn("Could not find texture with guid",
|
|
447
|
+
p && console.warn("Could not find texture with guid", D.guid, T.parser.json);
|
|
447
448
|
}
|
|
448
|
-
if (v = 0,
|
|
449
|
+
if (v = 0, T.parser.json.meshes) {
|
|
449
450
|
let O = !1;
|
|
450
|
-
for (const
|
|
451
|
-
if (
|
|
452
|
-
const g =
|
|
453
|
-
if (g != null && g.guid && g.guid ===
|
|
451
|
+
for (const f of T.parser.json.meshes) {
|
|
452
|
+
if (f != null && f.extensions) {
|
|
453
|
+
const g = f == null ? void 0 : f.extensions[W];
|
|
454
|
+
if (g != null && g.guid && g.guid === D.guid) {
|
|
454
455
|
O = !0;
|
|
455
456
|
break;
|
|
456
457
|
}
|
|
@@ -458,28 +459,28 @@ const D = class {
|
|
|
458
459
|
v++;
|
|
459
460
|
}
|
|
460
461
|
if (O) {
|
|
461
|
-
const
|
|
462
|
-
if (s && console.log(`Loaded Mesh "${
|
|
463
|
-
const _ =
|
|
464
|
-
return
|
|
462
|
+
const f = await U.getDependency("mesh", v), g = D;
|
|
463
|
+
if (s && console.log(`Loaded Mesh "${f.name}"`, h, v, f, x), f.isMesh === !0) {
|
|
464
|
+
const _ = f.geometry;
|
|
465
|
+
return M.assignLODInformation(n.url, _, i, e, void 0, g.density), u(_);
|
|
465
466
|
} else {
|
|
466
467
|
const _ = new Array();
|
|
467
|
-
for (let S = 0; S <
|
|
468
|
-
const
|
|
469
|
-
if (
|
|
470
|
-
const
|
|
471
|
-
|
|
468
|
+
for (let S = 0; S < f.children.length; S++) {
|
|
469
|
+
const E = f.children[S];
|
|
470
|
+
if (E.isMesh === !0) {
|
|
471
|
+
const K = E.geometry;
|
|
472
|
+
M.assignLODInformation(n.url, K, i, e, S, g.density), _.push(K);
|
|
472
473
|
}
|
|
473
474
|
}
|
|
474
|
-
return
|
|
475
|
+
return u(_);
|
|
475
476
|
}
|
|
476
477
|
} else
|
|
477
|
-
p && console.warn("Could not find mesh with guid",
|
|
478
|
+
p && console.warn("Could not find mesh with guid", D.guid, T.parser.json);
|
|
478
479
|
}
|
|
479
|
-
return
|
|
480
|
+
return u(null);
|
|
480
481
|
});
|
|
481
|
-
return this.previouslyLoaded.set(x,
|
|
482
|
-
} else if (t instanceof
|
|
482
|
+
return this.previouslyLoaded.set(x, k), await k;
|
|
483
|
+
} else if (t instanceof ee) {
|
|
483
484
|
s && console.log("Load texture from uri: " + h);
|
|
484
485
|
const L = await new We().loadAsync(h);
|
|
485
486
|
return L ? (L.guid = r.guid, L.flipY = !1, L.needsUpdate = !0, L.colorSpace = t.colorSpace, s && console.log(r, L)) : p && console.warn("failed loading", h), L;
|
|
@@ -492,7 +493,7 @@ const D = class {
|
|
|
492
493
|
if (!e)
|
|
493
494
|
return;
|
|
494
495
|
e.userData || (e.userData = {});
|
|
495
|
-
const o = new
|
|
496
|
+
const o = new lt(t, s, n, i, r);
|
|
496
497
|
e.userData.LODS = o;
|
|
497
498
|
}
|
|
498
499
|
static getAssignedLODInformation(t) {
|
|
@@ -501,22 +502,22 @@ const D = class {
|
|
|
501
502
|
}
|
|
502
503
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
503
504
|
static copySettings(t, e) {
|
|
504
|
-
return p && console.warn(`Copy texture settings
|
|
505
|
+
return e ? (p && console.warn(`Copy texture settings
|
|
505
506
|
`, t.uuid, `
|
|
506
|
-
`, e.uuid), e = e.clone(), 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;
|
|
507
|
+
`, e.uuid), e = e.clone(), 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) : t;
|
|
507
508
|
}
|
|
508
509
|
};
|
|
509
|
-
let
|
|
510
|
-
|
|
510
|
+
let P = M;
|
|
511
|
+
P.registerTexture = (t, e, s, n, i) => {
|
|
511
512
|
if (p && console.log("> Progressive: register texture", n, e.name, e.uuid, e, i), !e) {
|
|
512
513
|
p && console.error("gltf-progressive: Register texture without texture");
|
|
513
514
|
return;
|
|
514
515
|
}
|
|
515
|
-
e.source && (e.source[
|
|
516
|
+
e.source && (e.source[ve] = i);
|
|
516
517
|
const r = i.guid;
|
|
517
|
-
|
|
518
|
+
M.assignLODInformation(t, e, r, s, n, void 0), M.lodInfos.set(r, i), M.lowresCache.set(r, e);
|
|
518
519
|
};
|
|
519
|
-
|
|
520
|
+
P.registerMesh = (t, e, s, n, i, r) => {
|
|
520
521
|
var c;
|
|
521
522
|
p && console.log("> Progressive: register mesh", i, s.name, r, s.uuid, s);
|
|
522
523
|
const o = s.geometry;
|
|
@@ -524,16 +525,16 @@ A.registerMesh = (t, e, s, n, i, r) => {
|
|
|
524
525
|
p && console.warn("gltf-progressive: Register mesh without geometry");
|
|
525
526
|
return;
|
|
526
527
|
}
|
|
527
|
-
o.userData || (o.userData = {}),
|
|
528
|
-
let a =
|
|
529
|
-
a ? a.push(s.geometry) : a = [s.geometry],
|
|
530
|
-
for (const l of
|
|
528
|
+
o.userData || (o.userData = {}), M.assignLODInformation(t, o, e, n, i, r.density), M.lodInfos.set(e, r);
|
|
529
|
+
let a = M.lowresCache.get(e);
|
|
530
|
+
a ? a.push(s.geometry) : a = [s.geometry], M.lowresCache.set(e, a), n > 0 && !ae(s) && nt(s, o);
|
|
531
|
+
for (const l of H)
|
|
531
532
|
(c = l.onRegisteredNewMesh) == null || c.call(l, s, r);
|
|
532
533
|
};
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
class
|
|
534
|
+
P.lodInfos = /* @__PURE__ */ new Map();
|
|
535
|
+
P.previouslyLoaded = /* @__PURE__ */ new Map();
|
|
536
|
+
P.lowresCache = /* @__PURE__ */ new Map();
|
|
537
|
+
class lt {
|
|
537
538
|
constructor(e, s, n, i, r) {
|
|
538
539
|
this.url = e, this.key = s, this.level = n, i != null && (this.index = i), r != null && (this.density = r);
|
|
539
540
|
}
|
|
@@ -541,26 +542,26 @@ class nt {
|
|
|
541
542
|
var Ge = (t, e, s) => {
|
|
542
543
|
if (!e.has(t))
|
|
543
544
|
throw TypeError("Cannot " + s);
|
|
544
|
-
}, y = (t, e, s) => (Ge(t, e, "read from private field"), s ? s.call(t) : e.get(t)),
|
|
545
|
+
}, y = (t, e, s) => (Ge(t, e, "read from private field"), s ? s.call(t) : e.get(t)), J = (t, e, s) => {
|
|
545
546
|
if (e.has(t))
|
|
546
547
|
throw TypeError("Cannot add the same private member more than once");
|
|
547
548
|
e instanceof WeakSet ? e.add(t) : e.set(t, s);
|
|
548
|
-
},
|
|
549
|
-
const
|
|
549
|
+
}, F = (t, e, s, n) => (Ge(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s), b, q, Oe, Z, ie, de, Y;
|
|
550
|
+
const R = oe("debugprogressive"), ct = oe("noprogressive"), me = Symbol("Needle:LODSManager"), xe = Symbol("Needle:LODState"), X = Symbol("Needle:CurrentLOD"), I = { mesh_lod: -1, texture_lod: -1 }, C = class {
|
|
550
551
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
551
552
|
constructor(t, e) {
|
|
552
|
-
this.projectionScreenMatrix = new
|
|
553
|
+
this.projectionScreenMatrix = new be(), this.targetTriangleDensity = 2e5, this.updateInterval = "auto", J(this, b, 1), this.pause = !1, this.manual = !1, this._lodchangedlisteners = [], J(this, q, void 0), J(this, Oe, new Ke()), J(this, Z, 0), J(this, ie, 0), J(this, de, 0), J(this, Y, 0), this._fpsBuffer = [60, 60, 60, 60, 60], this._sphere = new ze(), this._tempBox = new Te(), this._tempBox2 = new Te(), this.tempMatrix = new be(), this._tempWorldPosition = new z(), this._tempBoxSize = new z(), this._tempBox2Size = new z(), this.renderer = t, this.context = { ...e };
|
|
553
554
|
}
|
|
554
555
|
/** @internal */
|
|
555
556
|
static getObjectLODState(t) {
|
|
556
557
|
return t[xe];
|
|
557
558
|
}
|
|
558
559
|
static addPlugin(t) {
|
|
559
|
-
|
|
560
|
+
H.push(t);
|
|
560
561
|
}
|
|
561
562
|
static removePlugin(t) {
|
|
562
|
-
const e =
|
|
563
|
-
e >= 0 &&
|
|
563
|
+
const e = H.indexOf(t);
|
|
564
|
+
e >= 0 && H.splice(e, 1);
|
|
564
565
|
}
|
|
565
566
|
/**
|
|
566
567
|
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
@@ -578,7 +579,7 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
578
579
|
}
|
|
579
580
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
580
581
|
get plugins() {
|
|
581
|
-
return
|
|
582
|
+
return H;
|
|
582
583
|
}
|
|
583
584
|
addEventListener(t, e) {
|
|
584
585
|
t === "changed" && this._lodchangedlisteners.push(e);
|
|
@@ -593,21 +594,21 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
593
594
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
594
595
|
*/
|
|
595
596
|
enable() {
|
|
596
|
-
if (y(this,
|
|
597
|
+
if (y(this, q))
|
|
597
598
|
return;
|
|
598
599
|
console.debug("[gltf-progressive] Enabling LODsManager for renderer");
|
|
599
600
|
let t = 0;
|
|
600
|
-
|
|
601
|
+
F(this, q, this.renderer.render);
|
|
601
602
|
const e = this;
|
|
602
603
|
Be(this.renderer), this.renderer.render = function(s, n) {
|
|
603
604
|
const i = e.renderer.getRenderTarget();
|
|
604
|
-
(i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0,
|
|
605
|
+
(i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, F(e, Z, y(e, Z) + 1), F(e, ie, y(e, Oe).getDelta()), F(e, de, y(e, de) + y(e, ie)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / y(e, ie)), F(e, Y, e._fpsBuffer.reduce((o, a) => o + a) / e._fpsBuffer.length), R && y(e, Z) % 200 === 0 && console.log("FPS", Math.round(y(e, Y)), "Interval:", y(e, b)));
|
|
605
606
|
const r = t++;
|
|
606
|
-
y(e,
|
|
607
|
+
y(e, q).call(this, s, n), e.onAfterRender(s, n, r);
|
|
607
608
|
};
|
|
608
609
|
}
|
|
609
610
|
disable() {
|
|
610
|
-
y(this,
|
|
611
|
+
y(this, q) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = y(this, q), F(this, q, void 0));
|
|
611
612
|
}
|
|
612
613
|
update(t, e) {
|
|
613
614
|
this.internalUpdate(t, e);
|
|
@@ -622,7 +623,7 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
622
623
|
(o.name === "EffectMaterial" || o.name === "CopyShader") && (r = !1);
|
|
623
624
|
}
|
|
624
625
|
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (r = !1), r) {
|
|
625
|
-
if (
|
|
626
|
+
if (ct || (this.updateInterval === "auto" ? y(this, Y) < 40 && y(this, b) < 10 ? (F(this, b, y(this, b) + 1), R && console.warn("↓ Reducing LOD updates", y(this, b), y(this, Y).toFixed(0))) : y(this, Y) >= 60 && y(this, b) > 1 && (F(this, b, y(this, b) - 1), R && console.warn("↑ Increasing LOD updates", y(this, b), y(this, Y).toFixed(0))) : F(this, b, this.updateInterval), y(this, b) > 0 && y(this, Z) % y(this, b) != 0))
|
|
626
627
|
return;
|
|
627
628
|
this.internalUpdate(t, e);
|
|
628
629
|
}
|
|
@@ -637,7 +638,7 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
637
638
|
const i = this.targetTriangleDensity;
|
|
638
639
|
for (const l of n) {
|
|
639
640
|
if (l.material && (((a = l.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((c = l.geometry) == null ? void 0 : c.type) === "BufferGeometry") && (l.material.name === "SphericalGaussianBlur" || l.material.name == "BackgroundCubeMaterial" || l.material.name === "CubemapFromEquirect" || l.material.name === "EquirectangularToCubeUV")) {
|
|
640
|
-
|
|
641
|
+
R && (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)));
|
|
641
642
|
continue;
|
|
642
643
|
}
|
|
643
644
|
switch (l.material.type) {
|
|
@@ -649,23 +650,23 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
649
650
|
case "MeshDepthMaterial":
|
|
650
651
|
continue;
|
|
651
652
|
}
|
|
652
|
-
if (
|
|
653
|
+
if (R === "color" && l.material && !l.object.progressive_debug_color) {
|
|
653
654
|
l.object.progressive_debug_color = !0;
|
|
654
655
|
const h = Math.random() * 16777215, x = new Ve({ color: h });
|
|
655
656
|
l.object.material = x;
|
|
656
657
|
}
|
|
657
658
|
const d = l.object;
|
|
658
|
-
(d instanceof
|
|
659
|
+
(d instanceof Q || d.isMesh) && this.updateLODs(t, e, d, i);
|
|
659
660
|
}
|
|
660
661
|
const r = s.transparent;
|
|
661
662
|
for (const l of r) {
|
|
662
663
|
const d = l.object;
|
|
663
|
-
(d instanceof
|
|
664
|
+
(d instanceof Q || d.isMesh) && this.updateLODs(t, e, d, i);
|
|
664
665
|
}
|
|
665
666
|
const o = s.transmissive;
|
|
666
667
|
for (const l of o) {
|
|
667
668
|
const d = l.object;
|
|
668
|
-
(d instanceof
|
|
669
|
+
(d instanceof Q || d.isMesh) && this.updateLODs(t, e, d, i);
|
|
669
670
|
}
|
|
670
671
|
}
|
|
671
672
|
/** Update the LOD levels for the renderer. */
|
|
@@ -673,16 +674,16 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
673
674
|
var o, a;
|
|
674
675
|
s.userData || (s.userData = {});
|
|
675
676
|
let i = s[xe];
|
|
676
|
-
if (i || (i = new
|
|
677
|
+
if (i || (i = new ft(), s[xe] = i), i.frames++ < 2)
|
|
677
678
|
return;
|
|
678
|
-
for (const c of
|
|
679
|
+
for (const c of H)
|
|
679
680
|
(o = c.onBeforeUpdateLOD) == null || o.call(c, this.renderer, t, e, s);
|
|
680
|
-
this.calculateLodLevel(e, s, i, n,
|
|
681
|
-
let r =
|
|
681
|
+
this.calculateLodLevel(e, s, i, n, I), I.mesh_lod = Math.round(I.mesh_lod), I.texture_lod = Math.round(I.texture_lod), I.mesh_lod >= 0 && this.loadProgressiveMeshes(s, I.mesh_lod);
|
|
682
|
+
let r = I.texture_lod;
|
|
682
683
|
s.material && r >= 0 && this.loadProgressiveTextures(s.material, r);
|
|
683
|
-
for (const c of
|
|
684
|
-
(a = c.onAfterUpdatedLOD) == null || a.call(c, this.renderer, t, e, s,
|
|
685
|
-
i.lastLodLevel_Mesh =
|
|
684
|
+
for (const c of H)
|
|
685
|
+
(a = c.onAfterUpdatedLOD) == null || a.call(c, this.renderer, t, e, s, I);
|
|
686
|
+
i.lastLodLevel_Mesh = I.mesh_lod, i.lastLodLevel_Texture = I.texture_lod;
|
|
686
687
|
}
|
|
687
688
|
/** Load progressive textures for the given material
|
|
688
689
|
* @param material the material to load the textures for
|
|
@@ -698,9 +699,9 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
698
699
|
return;
|
|
699
700
|
}
|
|
700
701
|
let s = !1;
|
|
701
|
-
(t[
|
|
702
|
+
(t[X] === void 0 || e < t[X]) && (s = !0);
|
|
702
703
|
const n = t["DEBUG:LOD"];
|
|
703
|
-
n != null && (s = t[
|
|
704
|
+
n != null && (s = t[X] != n, e = n), s && (t[X] = e, P.assignTextureLOD(t, e).then((i) => {
|
|
704
705
|
this._lodchangedlisteners.forEach((r) => r({ type: "texture", level: e, object: t }));
|
|
705
706
|
}));
|
|
706
707
|
}
|
|
@@ -713,12 +714,12 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
713
714
|
loadProgressiveMeshes(t, e) {
|
|
714
715
|
if (!t)
|
|
715
716
|
return Promise.resolve(null);
|
|
716
|
-
let s = t[
|
|
717
|
+
let s = t[X] !== e;
|
|
717
718
|
const n = t["DEBUG:LOD"];
|
|
718
|
-
if (n != null && (s = t[
|
|
719
|
-
t[
|
|
719
|
+
if (n != null && (s = t[X] != n, e = n), s) {
|
|
720
|
+
t[X] = e;
|
|
720
721
|
const i = t.geometry;
|
|
721
|
-
return
|
|
722
|
+
return P.assignMeshLOD(t, e).then((r) => (r && t[X] == e && i != t.geometry && this._lodchangedlisteners.forEach((o) => o({ type: "mesh", level: e, object: t })), r));
|
|
722
723
|
}
|
|
723
724
|
return Promise.resolve(null);
|
|
724
725
|
}
|
|
@@ -727,7 +728,7 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
727
728
|
return this._tempPtInside.set(i, r, s.z).applyMatrix4(e).z < 0;
|
|
728
729
|
}
|
|
729
730
|
calculateLodLevel(t, e, s, n, i) {
|
|
730
|
-
var
|
|
731
|
+
var k;
|
|
731
732
|
if (!e) {
|
|
732
733
|
i.mesh_lod = -1, i.texture_lod = -1;
|
|
733
734
|
return;
|
|
@@ -737,96 +738,96 @@ const B = oe("debugprogressive"), ot = oe("noprogressive"), me = Symbol("Needle:
|
|
|
737
738
|
return;
|
|
738
739
|
}
|
|
739
740
|
let o = 10 + 1, a = !1;
|
|
740
|
-
if (
|
|
741
|
+
if (R && e["DEBUG:LOD"] != null)
|
|
741
742
|
return e["DEBUG:LOD"];
|
|
742
|
-
const c =
|
|
743
|
+
const c = P.getMeshLODInformation(e.geometry), l = c == null ? void 0 : c.lods, d = l && l.length > 0, h = P.getMaterialMinMaxLODsCount(e.material), x = (h == null ? void 0 : h.min_count) != 1 / 0 && h.min_count > 0 && h.max_count > 0;
|
|
743
744
|
if (!d && !x) {
|
|
744
745
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
745
746
|
return;
|
|
746
747
|
}
|
|
747
748
|
d || (a = !0, o = 0);
|
|
748
749
|
const L = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
749
|
-
let
|
|
750
|
+
let D = e.geometry.boundingBox;
|
|
750
751
|
if (e.type === "SkinnedMesh") {
|
|
751
752
|
const m = e;
|
|
752
753
|
if (!m.boundingBox)
|
|
753
754
|
m.computeBoundingBox();
|
|
754
755
|
else if (s.frames % 30 === 0) {
|
|
755
|
-
const
|
|
756
|
-
|
|
756
|
+
const u = ae(m), w = m.geometry;
|
|
757
|
+
u && (m.geometry = u), m.computeBoundingBox(), m.geometry = w;
|
|
757
758
|
}
|
|
758
|
-
|
|
759
|
+
D = m.boundingBox;
|
|
759
760
|
}
|
|
760
|
-
if (
|
|
761
|
+
if (D) {
|
|
761
762
|
const m = t;
|
|
762
763
|
if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
|
|
763
764
|
this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
|
|
764
|
-
const
|
|
765
|
-
if (this._sphere.containsPoint(
|
|
765
|
+
const f = t.getWorldPosition(this._tempWorldPosition);
|
|
766
|
+
if (this._sphere.containsPoint(f)) {
|
|
766
767
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
767
768
|
return;
|
|
768
769
|
}
|
|
769
770
|
}
|
|
770
|
-
if (this._tempBox.copy(
|
|
771
|
+
if (this._tempBox.copy(D), this._tempBox.applyMatrix4(e.matrixWorld), m.isPerspectiveCamera && C.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
771
772
|
i.mesh_lod = 0, i.texture_lod = 0;
|
|
772
773
|
return;
|
|
773
774
|
}
|
|
774
775
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && m.isPerspectiveCamera && m.fov > 70) {
|
|
775
|
-
const
|
|
776
|
-
let _ =
|
|
777
|
-
const le = 2, pe = 1.5, ce = (
|
|
778
|
-
_ = (_ - ce) * le + ce, S = (S -
|
|
779
|
-
const
|
|
776
|
+
const f = this._tempBox.min, g = this._tempBox.max;
|
|
777
|
+
let _ = f.x, S = f.y, E = g.x, K = g.y;
|
|
778
|
+
const le = 2, pe = 1.5, ce = (f.x + g.x) * 0.5, fe = (f.y + g.y) * 0.5;
|
|
779
|
+
_ = (_ - ce) * le + ce, S = (S - fe) * le + fe, E = (E - ce) * le + ce, K = (K - fe) * le + fe;
|
|
780
|
+
const Ue = _ < 0 && E > 0 ? 0 : Math.min(Math.abs(f.x), Math.abs(g.x)), Fe = S < 0 && K > 0 ? 0 : Math.min(Math.abs(f.y), Math.abs(g.y)), ye = Math.max(Ue, Fe);
|
|
780
781
|
s.lastCentrality = (pe - ye) * (pe - ye) * (pe - ye);
|
|
781
782
|
} else
|
|
782
783
|
s.lastCentrality = 1;
|
|
783
|
-
const
|
|
784
|
-
|
|
785
|
-
const w = t.matrixWorldInverse,
|
|
786
|
-
|
|
787
|
-
const
|
|
788
|
-
if (Math.max(
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
const g = C.corner0, _ = C.corner1, S = C.corner2,
|
|
792
|
-
g.copy(this._tempBox.min), _.copy(this._tempBox.max), _.x = g.x, S.copy(this._tempBox.max), S.y = g.y,
|
|
793
|
-
const
|
|
794
|
-
g.z = _.z = S.z =
|
|
784
|
+
const u = this._tempBox.getSize(this._tempBoxSize);
|
|
785
|
+
u.multiplyScalar(0.5), screen.availHeight > 0 && L > 0 && u.multiplyScalar(L / screen.availHeight), t.isPerspectiveCamera ? u.x *= t.aspect : t.isOrthographicCamera;
|
|
786
|
+
const w = t.matrixWorldInverse, $ = this._tempBox2;
|
|
787
|
+
$.copy(D), $.applyMatrix4(e.matrixWorld), $.applyMatrix4(w);
|
|
788
|
+
const B = $.getSize(this._tempBox2Size), T = Math.max(B.x, B.y);
|
|
789
|
+
if (Math.max(u.x, u.y) != 0 && T != 0 && (u.z = B.z / Math.max(B.x, B.y) * Math.max(u.x, u.y)), s.lastScreenCoverage = Math.max(u.x, u.y, u.z), s.lastScreenspaceVolume.copy(u), s.lastScreenCoverage *= s.lastCentrality, R && C.debugDrawLine) {
|
|
790
|
+
const f = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
791
|
+
f.invert();
|
|
792
|
+
const g = C.corner0, _ = C.corner1, S = C.corner2, E = C.corner3;
|
|
793
|
+
g.copy(this._tempBox.min), _.copy(this._tempBox.max), _.x = g.x, S.copy(this._tempBox.max), S.y = g.y, E.copy(this._tempBox.max);
|
|
794
|
+
const K = (g.z + E.z) * 0.5;
|
|
795
|
+
g.z = _.z = S.z = E.z = K, g.applyMatrix4(f), _.applyMatrix4(f), S.applyMatrix4(f), E.applyMatrix4(f), C.debugDrawLine(g, _, 255), C.debugDrawLine(g, S, 255), C.debugDrawLine(_, E, 255), C.debugDrawLine(S, E, 255);
|
|
795
796
|
}
|
|
796
797
|
let v = 999;
|
|
797
798
|
if (l && s.lastScreenCoverage > 0) {
|
|
798
|
-
for (let
|
|
799
|
-
if (l[
|
|
800
|
-
v =
|
|
799
|
+
for (let f = 0; f < l.length; f++)
|
|
800
|
+
if (l[f].density / s.lastScreenCoverage < n) {
|
|
801
|
+
v = f;
|
|
801
802
|
break;
|
|
802
803
|
}
|
|
803
804
|
}
|
|
804
805
|
v < o && (o = v, a = !0);
|
|
805
806
|
}
|
|
806
|
-
if (a ? i.mesh_lod = o : i.mesh_lod = s.lastLodLevel_Mesh,
|
|
807
|
-
const
|
|
808
|
-
|
|
807
|
+
if (a ? i.mesh_lod = o : i.mesh_lod = s.lastLodLevel_Mesh, R && i.mesh_lod != s.lastLodLevel_Mesh) {
|
|
808
|
+
const u = l == null ? void 0 : l[i.mesh_lod];
|
|
809
|
+
u && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${i.mesh_lod} (${u.density.toFixed(0)}) - ${e.name}`);
|
|
809
810
|
}
|
|
810
811
|
if (x) {
|
|
811
812
|
const m = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
812
813
|
if (s.lastLodLevel_Texture < 0) {
|
|
813
|
-
if (i.texture_lod = h.max_count - 1,
|
|
814
|
-
const
|
|
815
|
-
|
|
814
|
+
if (i.texture_lod = h.max_count - 1, R) {
|
|
815
|
+
const u = h.lods[h.max_count - 1];
|
|
816
|
+
R && console.log(`First Texture LOD ${i.texture_lod} (${u.max_height}px) - ${e.name}`);
|
|
816
817
|
}
|
|
817
818
|
} else {
|
|
818
|
-
const
|
|
819
|
+
const u = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
819
820
|
let w = s.lastScreenCoverage * 4;
|
|
820
|
-
((
|
|
821
|
-
const
|
|
822
|
-
let
|
|
823
|
-
for (let
|
|
824
|
-
let v = h.lods[
|
|
825
|
-
if (!(m && v.max_height >= 2048) && !(
|
|
826
|
-
if (
|
|
821
|
+
((k = this.context) == null ? void 0 : k.engine) === "model-viewer" && (w *= 1.5);
|
|
822
|
+
const B = L / window.devicePixelRatio * w;
|
|
823
|
+
let T = !1;
|
|
824
|
+
for (let U = h.lods.length - 1; U >= 0; U--) {
|
|
825
|
+
let v = h.lods[U];
|
|
826
|
+
if (!(m && v.max_height >= 2048) && !(rt() && v.max_height > 4096) && (v.max_height > B || !T && U === 0)) {
|
|
827
|
+
if (T = !0, i.texture_lod = U, i.texture_lod < s.lastLodLevel_Texture) {
|
|
827
828
|
const O = v.max_height;
|
|
828
|
-
|
|
829
|
-
Screensize: ${
|
|
829
|
+
R && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${O}px
|
|
830
|
+
Screensize: ${B.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${u.toFixed(1)}
|
|
830
831
|
${e.name}`);
|
|
831
832
|
}
|
|
832
833
|
break;
|
|
@@ -837,59 +838,59 @@ ${e.name}`);
|
|
|
837
838
|
i.texture_lod = 0;
|
|
838
839
|
}
|
|
839
840
|
};
|
|
840
|
-
let
|
|
841
|
+
let V = C;
|
|
841
842
|
b = /* @__PURE__ */ new WeakMap();
|
|
842
|
-
V = /* @__PURE__ */ new WeakMap();
|
|
843
|
-
we = /* @__PURE__ */ new WeakMap();
|
|
844
|
-
Q = /* @__PURE__ */ new WeakMap();
|
|
845
|
-
re = /* @__PURE__ */ new WeakMap();
|
|
846
|
-
de = /* @__PURE__ */ new WeakMap();
|
|
847
843
|
q = /* @__PURE__ */ new WeakMap();
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
844
|
+
Oe = /* @__PURE__ */ new WeakMap();
|
|
845
|
+
Z = /* @__PURE__ */ new WeakMap();
|
|
846
|
+
ie = /* @__PURE__ */ new WeakMap();
|
|
847
|
+
de = /* @__PURE__ */ new WeakMap();
|
|
848
|
+
Y = /* @__PURE__ */ new WeakMap();
|
|
849
|
+
V.corner0 = new z();
|
|
850
|
+
V.corner1 = new z();
|
|
851
|
+
V.corner2 = new z();
|
|
852
|
+
V.corner3 = new z();
|
|
853
|
+
V._tempPtInside = new z();
|
|
854
|
+
class ft {
|
|
854
855
|
constructor() {
|
|
855
|
-
this.frames = 0, this.lastLodLevel_Mesh = -1, this.lastLodLevel_Texture = -1, this.lastScreenCoverage = 0, this.lastScreenspaceVolume = new
|
|
856
|
+
this.frames = 0, this.lastLodLevel_Mesh = -1, this.lastLodLevel_Texture = -1, this.lastScreenCoverage = 0, this.lastScreenspaceVolume = new z(), this.lastCentrality = 0;
|
|
856
857
|
}
|
|
857
858
|
}
|
|
858
|
-
const
|
|
859
|
-
let
|
|
860
|
-
function
|
|
861
|
-
const t =
|
|
859
|
+
const Ae = Symbol("NEEDLE_mesh_lod"), ue = Symbol("NEEDLE_texture_lod");
|
|
860
|
+
let re = null;
|
|
861
|
+
function $e() {
|
|
862
|
+
const t = ut();
|
|
862
863
|
t && (t.mapURLs(function(e) {
|
|
863
|
-
return
|
|
864
|
-
}),
|
|
864
|
+
return Pe(), e;
|
|
865
|
+
}), Pe(), re == null || re.disconnect(), re = new MutationObserver((e) => {
|
|
865
866
|
e.forEach((s) => {
|
|
866
867
|
s.addedNodes.forEach((n) => {
|
|
867
|
-
n instanceof HTMLElement && n.tagName.toLowerCase() === "model-viewer" &&
|
|
868
|
+
n instanceof HTMLElement && n.tagName.toLowerCase() === "model-viewer" && Ne(n);
|
|
868
869
|
});
|
|
869
870
|
});
|
|
870
|
-
}),
|
|
871
|
+
}), re.observe(document, { childList: !0, subtree: !0 }));
|
|
871
872
|
}
|
|
872
|
-
function
|
|
873
|
+
function ut() {
|
|
873
874
|
if (typeof customElements > "u")
|
|
874
875
|
return null;
|
|
875
876
|
const t = customElements.get("model-viewer");
|
|
876
877
|
return t || (customElements.whenDefined("model-viewer").then(() => {
|
|
877
|
-
console.debug("[gltf-progressive] model-viewer defined"),
|
|
878
|
+
console.debug("[gltf-progressive] model-viewer defined"), $e();
|
|
878
879
|
}), null);
|
|
879
880
|
}
|
|
880
|
-
function
|
|
881
|
+
function Pe() {
|
|
881
882
|
if (typeof document > "u")
|
|
882
883
|
return;
|
|
883
884
|
document.querySelectorAll("model-viewer").forEach((e) => {
|
|
884
|
-
|
|
885
|
+
Ne(e);
|
|
885
886
|
});
|
|
886
887
|
}
|
|
887
888
|
const Ce = /* @__PURE__ */ new WeakSet();
|
|
888
|
-
let
|
|
889
|
-
function
|
|
889
|
+
let dt = 0;
|
|
890
|
+
function Ne(t) {
|
|
890
891
|
if (!t || Ce.has(t))
|
|
891
892
|
return null;
|
|
892
|
-
Ce.add(t), console.debug("[gltf-progressive] found new model-viewer..." + ++
|
|
893
|
+
Ce.add(t), console.debug("[gltf-progressive] found new model-viewer..." + ++dt + `
|
|
893
894
|
`, t.getAttribute("src"));
|
|
894
895
|
let e = null, s = null, n = null;
|
|
895
896
|
for (let i = t; i != null; i = Object.getPrototypeOf(i)) {
|
|
@@ -909,8 +910,8 @@ function $e(t) {
|
|
|
909
910
|
}
|
|
910
911
|
};
|
|
911
912
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
912
|
-
const r =
|
|
913
|
-
return
|
|
913
|
+
const r = V.get(e, { engine: "model-viewer" });
|
|
914
|
+
return V.addPlugin(new ht()), r.enable(), r.addEventListener("changed", () => {
|
|
914
915
|
n == null || n.call(t);
|
|
915
916
|
}), t.addEventListener("model-visibility", (o) => {
|
|
916
917
|
o.detail.visible && (n == null || n.call(t));
|
|
@@ -922,7 +923,7 @@ function $e(t) {
|
|
|
922
923
|
}
|
|
923
924
|
return null;
|
|
924
925
|
}
|
|
925
|
-
class
|
|
926
|
+
class ht {
|
|
926
927
|
constructor() {
|
|
927
928
|
this._didWarnAboutMissingUrl = !1;
|
|
928
929
|
}
|
|
@@ -942,31 +943,31 @@ class ut {
|
|
|
942
943
|
return e.element;
|
|
943
944
|
}
|
|
944
945
|
tryParseTextureLOD(e, s) {
|
|
945
|
-
if (s[
|
|
946
|
+
if (s[ue] == !0)
|
|
946
947
|
return;
|
|
947
|
-
s[
|
|
948
|
+
s[ue] = !0;
|
|
948
949
|
const n = this.tryGetCurrentGLTF(e), i = this.tryGetCurrentModelViewer(e), r = this.getUrl(i);
|
|
949
950
|
if (r && n && s.material) {
|
|
950
951
|
let o = function(c) {
|
|
951
952
|
var d, h, x;
|
|
952
|
-
if (c[
|
|
953
|
+
if (c[ue] == !0)
|
|
953
954
|
return;
|
|
954
|
-
c[
|
|
955
|
+
c[ue] = !0, c.userData && (c.userData.LOD = -1);
|
|
955
956
|
const l = Object.keys(c);
|
|
956
957
|
for (let L = 0; L < l.length; L++) {
|
|
957
|
-
const
|
|
958
|
-
if ((
|
|
959
|
-
const m = (h = (d =
|
|
958
|
+
const D = l[L], k = c[D];
|
|
959
|
+
if ((k == null ? void 0 : k.isTexture) === !0) {
|
|
960
|
+
const m = (h = (d = k.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
|
|
960
961
|
if (m == null)
|
|
961
962
|
continue;
|
|
962
|
-
const
|
|
963
|
-
if (!
|
|
963
|
+
const u = n.parser.json.textures[m];
|
|
964
|
+
if (!u) {
|
|
964
965
|
console.warn("Texture data not found for texture index " + m);
|
|
965
966
|
continue;
|
|
966
967
|
}
|
|
967
|
-
if ((x =
|
|
968
|
-
const w =
|
|
969
|
-
w && r &&
|
|
968
|
+
if ((x = u == null ? void 0 : u.extensions) != null && x[W]) {
|
|
969
|
+
const w = u.extensions[W];
|
|
970
|
+
w && r && P.registerTexture(r, k, w.lods.length, m, w);
|
|
970
971
|
}
|
|
971
972
|
}
|
|
972
973
|
}
|
|
@@ -981,36 +982,36 @@ class ut {
|
|
|
981
982
|
}
|
|
982
983
|
tryParseMeshLOD(e, s) {
|
|
983
984
|
var o, a;
|
|
984
|
-
if (s[
|
|
985
|
+
if (s[Ae] == !0)
|
|
985
986
|
return;
|
|
986
|
-
s[
|
|
987
|
+
s[Ae] = !0;
|
|
987
988
|
const n = this.tryGetCurrentModelViewer(e), i = this.getUrl(n);
|
|
988
989
|
if (!i)
|
|
989
990
|
return;
|
|
990
|
-
const r = (a = (o = s.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : a[
|
|
991
|
+
const r = (a = (o = s.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : a[W];
|
|
991
992
|
if (r && i) {
|
|
992
993
|
const c = s.uuid;
|
|
993
|
-
|
|
994
|
+
P.registerMesh(i, c, s, 0, r.lods.length, r);
|
|
994
995
|
}
|
|
995
996
|
}
|
|
996
997
|
}
|
|
997
|
-
function
|
|
998
|
+
function gt(t, e, s, n) {
|
|
998
999
|
Be(e), Re(s), Ie(s, {
|
|
999
1000
|
progressive: !0,
|
|
1000
1001
|
...n == null ? void 0 : n.hints
|
|
1001
|
-
}), s.register((r) => new
|
|
1002
|
-
const i =
|
|
1002
|
+
}), s.register((r) => new P(r, t));
|
|
1003
|
+
const i = V.get(e);
|
|
1003
1004
|
return (n == null ? void 0 : n.enableLODsManager) !== !1 && i.enable(), i;
|
|
1004
1005
|
}
|
|
1005
|
-
|
|
1006
|
-
if (!
|
|
1006
|
+
$e();
|
|
1007
|
+
if (!it) {
|
|
1007
1008
|
const t = {
|
|
1008
1009
|
gltfProgressive: {
|
|
1009
|
-
useNeedleProgressive:
|
|
1010
|
-
LODsManager:
|
|
1010
|
+
useNeedleProgressive: gt,
|
|
1011
|
+
LODsManager: V,
|
|
1011
1012
|
configureLoader: Ie,
|
|
1012
1013
|
getRaycastMesh: ae,
|
|
1013
|
-
useRaycastMeshes:
|
|
1014
|
+
useRaycastMeshes: ot
|
|
1014
1015
|
}
|
|
1015
1016
|
};
|
|
1016
1017
|
if (!globalThis.Needle)
|
|
@@ -1020,12 +1021,12 @@ if (!tt) {
|
|
|
1020
1021
|
globalThis.Needle[e] = t[e];
|
|
1021
1022
|
}
|
|
1022
1023
|
export {
|
|
1023
|
-
|
|
1024
|
-
|
|
1024
|
+
V as L,
|
|
1025
|
+
P as N,
|
|
1025
1026
|
Re as a,
|
|
1026
1027
|
Ie as b,
|
|
1027
1028
|
Be as c,
|
|
1028
|
-
|
|
1029
|
+
et as d,
|
|
1029
1030
|
ae as g,
|
|
1030
|
-
|
|
1031
|
+
je as s
|
|
1031
1032
|
};
|