@needle-tools/engine 4.7.2-next.37cf642 → 4.7.2-next.d24ebbc
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/dist/{gltf-progressive-BiLgh4_q.js → gltf-progressive-CNdBjvz6.js} +398 -412
- package/dist/gltf-progressive-C_oN6wCA.umd.cjs +8 -0
- package/dist/gltf-progressive-MgWOszRl.min.js +8 -0
- package/dist/{needle-engine.bundle-CaBnooYY.min.js → needle-engine.bundle-CGXifNgp.min.js} +5 -5
- package/dist/{needle-engine.bundle-DuNhdVQQ.js → needle-engine.bundle-CHfSBXXT.js} +19 -22
- package/dist/{needle-engine.bundle-BECP5XKQ.umd.cjs → needle-engine.bundle-Dcn5L5IY.umd.cjs} +6 -6
- package/dist/needle-engine.js +3 -3
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_input.js +0 -3
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.js +11 -14
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine-components/Skybox.js +1 -1
- package/lib/engine-components/Skybox.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/engine_input.ts +1 -8
- package/src/engine/webcomponents/needle-engine.ts +13 -15
- package/src/engine-components/Skybox.ts +1 -1
- package/dist/gltf-progressive-Cyd060gj.umd.cjs +0 -8
- package/dist/gltf-progressive-Q-uNWnqA.min.js +0 -8
|
@@ -1,106 +1,106 @@
|
|
|
1
1
|
var He = Object.defineProperty;
|
|
2
|
-
var Ee = (
|
|
3
|
-
throw TypeError(
|
|
2
|
+
var Ee = (n) => {
|
|
3
|
+
throw TypeError(n);
|
|
4
4
|
};
|
|
5
|
-
var je = (
|
|
6
|
-
var d = (
|
|
7
|
-
var p = (
|
|
8
|
-
import { BufferGeometry as
|
|
5
|
+
var je = (n, t, e) => t in n ? He(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
6
|
+
var d = (n, t, e) => je(n, typeof t != "symbol" ? t + "" : t, e), Ge = (n, t, e) => t.has(n) || Ee("Cannot " + e);
|
|
7
|
+
var p = (n, t, e) => (Ge(n, t, "read from private field"), e ? e.call(n) : t.get(n)), j = (n, t, e) => t.has(n) ? Ee("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, e), N = (n, t, e, s) => (Ge(n, t, "write to private field"), s ? s.call(n, e) : t.set(n, e), e);
|
|
8
|
+
import { BufferGeometry as me, Mesh as te, Texture as oe, TextureLoader as Je, Matrix4 as Be, Clock as Qe, MeshStandardMaterial as Ze, Sphere as et, Box3 as Ie, Vector3 as q } from "./three-DrqIzZTH.js";
|
|
9
9
|
import { DRACOLoader as tt, KTX2Loader as st, MeshoptDecoder as rt, GLTFLoader as Ce } from "./three-examples-B50TT3Iu.js";
|
|
10
10
|
const it = "";
|
|
11
11
|
globalThis.GLTF_PROGRESSIVE_VERSION = it;
|
|
12
12
|
console.debug("[gltf-progressive] version -");
|
|
13
13
|
let V = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", se = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
14
|
-
const
|
|
14
|
+
const ot = V, nt = se, Fe = new URL(V + "draco_decoder.js");
|
|
15
15
|
Fe.searchParams.append("range", "true");
|
|
16
16
|
fetch(Fe, {
|
|
17
17
|
method: "GET",
|
|
18
18
|
headers: {
|
|
19
19
|
Range: "bytes=0-1"
|
|
20
20
|
}
|
|
21
|
-
}).catch((
|
|
22
|
-
console.debug(`Failed to fetch remote Draco decoder from ${V} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), V ===
|
|
21
|
+
}).catch((n) => {
|
|
22
|
+
console.debug(`Failed to fetch remote Draco decoder from ${V} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), V === ot && at("./include/draco/"), se === nt && lt("./include/ktx2/");
|
|
23
23
|
}).finally(() => {
|
|
24
24
|
Ue();
|
|
25
25
|
});
|
|
26
|
-
function at(
|
|
27
|
-
V =
|
|
26
|
+
function at(n) {
|
|
27
|
+
V = n, G && G[Te] != V ? (console.debug("Updating Draco decoder path to " + n), G[Te] = V, G.setDecoderPath(V), G.preload()) : console.debug("Setting Draco decoder path to " + n);
|
|
28
28
|
}
|
|
29
|
-
function lt(
|
|
30
|
-
se =
|
|
29
|
+
function lt(n) {
|
|
30
|
+
se = n, $ && $.transcoderPath != se ? (console.debug("Updating KTX2 transcoder path to " + n), $.setTranscoderPath(se), $.init()) : console.debug("Setting KTX2 transcoder path to " + n);
|
|
31
31
|
}
|
|
32
|
-
const
|
|
32
|
+
const Te = Symbol("dracoDecoderPath");
|
|
33
33
|
let G, Le, $;
|
|
34
34
|
function Ue() {
|
|
35
|
-
G || (G = new tt(), G[
|
|
35
|
+
G || (G = new tt(), G[Te] = V, G.setDecoderPath(V), G.setDecoderConfig({ type: "js" }), G.preload()), $ || ($ = new st(), $.setTranscoderPath(se), $.init()), Le || (Le = rt);
|
|
36
36
|
}
|
|
37
|
-
function Ne(
|
|
38
|
-
return Ue(),
|
|
37
|
+
function Ne(n) {
|
|
38
|
+
return Ue(), n ? $.detectSupport(n) : n !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: G, ktx2Loader: $, meshoptDecoder: Le };
|
|
39
39
|
}
|
|
40
|
-
function ze(
|
|
41
|
-
|
|
40
|
+
function ze(n) {
|
|
41
|
+
n.dracoLoader || n.setDRACOLoader(G), n.ktx2Loader || n.setKTX2Loader($), n.meshoptDecoder || n.setMeshoptDecoder(Le);
|
|
42
42
|
}
|
|
43
|
-
const
|
|
44
|
-
function Ve(
|
|
45
|
-
let e =
|
|
46
|
-
e ? e = Object.assign(e, t) : e = t,
|
|
43
|
+
const Pe = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
function Ve(n, t) {
|
|
45
|
+
let e = Pe.get(n);
|
|
46
|
+
e ? e = Object.assign(e, t) : e = t, Pe.set(n, e);
|
|
47
47
|
}
|
|
48
48
|
const Me = Ce.prototype.load;
|
|
49
|
-
function dt(...
|
|
50
|
-
const t =
|
|
51
|
-
let e =
|
|
49
|
+
function dt(...n) {
|
|
50
|
+
const t = Pe.get(this);
|
|
51
|
+
let e = n[0];
|
|
52
52
|
const s = new URL(e, window.location.href);
|
|
53
53
|
if (s.hostname.endsWith("needle.tools")) {
|
|
54
|
-
const
|
|
55
|
-
|
|
54
|
+
const i = (t == null ? void 0 : t.progressive) !== void 0 ? t.progressive : !0, r = t != null && t.usecase ? t.usecase : "default";
|
|
55
|
+
i ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${r}` : this.requestHeader.Accept = `*/*;usecase=${r}`, e = s.toString();
|
|
56
56
|
}
|
|
57
|
-
return
|
|
57
|
+
return n[0] = e, Me == null ? void 0 : Me.call(this, ...n);
|
|
58
58
|
}
|
|
59
59
|
Ce.prototype.load = dt;
|
|
60
60
|
de("debugprogressive");
|
|
61
|
-
function de(
|
|
61
|
+
function de(n) {
|
|
62
62
|
if (typeof window > "u") return !1;
|
|
63
|
-
const e = new URL(window.location.href).searchParams.get(
|
|
63
|
+
const e = new URL(window.location.href).searchParams.get(n);
|
|
64
64
|
return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
|
|
65
65
|
}
|
|
66
|
-
function ut(
|
|
67
|
-
if (t === void 0 || t.startsWith("./") || t.startsWith("http") ||
|
|
66
|
+
function ut(n, t) {
|
|
67
|
+
if (t === void 0 || t.startsWith("./") || t.startsWith("http") || n === void 0)
|
|
68
68
|
return t;
|
|
69
|
-
const e =
|
|
69
|
+
const e = n.lastIndexOf("/");
|
|
70
70
|
if (e >= 0) {
|
|
71
|
-
const s =
|
|
71
|
+
const s = n.substring(0, e + 1);
|
|
72
72
|
for (; s.endsWith("/") && t.startsWith("/"); ) t = t.substring(1);
|
|
73
73
|
return s + t;
|
|
74
74
|
}
|
|
75
75
|
return t;
|
|
76
76
|
}
|
|
77
|
-
let
|
|
77
|
+
let ne;
|
|
78
78
|
function ct() {
|
|
79
|
-
return
|
|
79
|
+
return ne !== void 0 || (ne = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), de("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", ne)), ne;
|
|
80
80
|
}
|
|
81
81
|
function ft() {
|
|
82
82
|
if (typeof window > "u") return !1;
|
|
83
|
-
const
|
|
84
|
-
return
|
|
83
|
+
const n = new URL(window.location.href), t = n.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(n.hostname);
|
|
84
|
+
return n.hostname === "127.0.0.1" || t;
|
|
85
85
|
}
|
|
86
86
|
const ht = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
|
|
87
|
-
function ue(
|
|
88
|
-
return (
|
|
87
|
+
function ue(n) {
|
|
88
|
+
return (n == null ? void 0 : n[Ae]) instanceof me ? n[Ae] : null;
|
|
89
89
|
}
|
|
90
|
-
function gt(
|
|
91
|
-
if ((
|
|
92
|
-
const s =
|
|
93
|
-
s.userData = { isRaycastMesh: !0 },
|
|
90
|
+
function gt(n, t) {
|
|
91
|
+
if ((n.type === "Mesh" || n.type === "SkinnedMesh") && !ue(n)) {
|
|
92
|
+
const s = yt(t);
|
|
93
|
+
s.userData = { isRaycastMesh: !0 }, n[Ae] = s;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
function pt(
|
|
97
|
-
if (
|
|
96
|
+
function pt(n = !0) {
|
|
97
|
+
if (n) {
|
|
98
98
|
if (ae) return;
|
|
99
99
|
const t = ae = te.prototype.raycast;
|
|
100
100
|
te.prototype.raycast = function(e, s) {
|
|
101
|
-
const
|
|
102
|
-
let
|
|
103
|
-
|
|
101
|
+
const o = this, i = ue(o);
|
|
102
|
+
let r;
|
|
103
|
+
i && o.isMesh && (r = o.geometry, o.geometry = i), t.call(this, e, s), r && (o.geometry = r);
|
|
104
104
|
};
|
|
105
105
|
} else {
|
|
106
106
|
if (!ae) return;
|
|
@@ -108,46 +108,46 @@ function pt(o = !0) {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
let ae = null;
|
|
111
|
-
function
|
|
112
|
-
const t = new
|
|
113
|
-
for (const e in
|
|
114
|
-
t.setAttribute(e,
|
|
115
|
-
return t.setIndex(
|
|
111
|
+
function yt(n) {
|
|
112
|
+
const t = new me();
|
|
113
|
+
for (const e in n.attributes)
|
|
114
|
+
t.setAttribute(e, n.getAttribute(e));
|
|
115
|
+
return t.setIndex(n.getIndex()), t;
|
|
116
116
|
}
|
|
117
|
-
const Q = new Array(),
|
|
117
|
+
const Q = new Array(), w = de("debugprogressive");
|
|
118
118
|
let pe, ee = -1;
|
|
119
|
-
if (
|
|
120
|
-
let
|
|
119
|
+
if (w) {
|
|
120
|
+
let n = function() {
|
|
121
121
|
ee += 1, ee >= t && (ee = -1), console.log(`Toggle LOD level [${ee}]`);
|
|
122
122
|
}, t = 6;
|
|
123
123
|
window.addEventListener("keyup", (e) => {
|
|
124
|
-
e.key === "p" &&
|
|
124
|
+
e.key === "p" && n(), e.key === "w" && (pe = !pe, console.log(`Toggle wireframe [${pe}]`));
|
|
125
125
|
const s = parseInt(e.key);
|
|
126
126
|
!isNaN(s) && s >= 0 && (ee = s, console.log(`Set LOD level to [${ee}]`));
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
function We(
|
|
130
|
-
if (
|
|
131
|
-
if (Array.isArray(
|
|
132
|
-
for (const t of
|
|
129
|
+
function We(n) {
|
|
130
|
+
if (w)
|
|
131
|
+
if (Array.isArray(n))
|
|
132
|
+
for (const t of n)
|
|
133
133
|
We(t);
|
|
134
|
-
else
|
|
134
|
+
else n && "wireframe" in n && (n.wireframe = pe === !0);
|
|
135
135
|
}
|
|
136
|
-
const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"),
|
|
136
|
+
const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), x = class x {
|
|
137
137
|
constructor(t, e) {
|
|
138
138
|
d(this, "parser");
|
|
139
139
|
d(this, "url");
|
|
140
140
|
d(this, "_isLoadingMesh");
|
|
141
141
|
d(this, "loadMesh", (t) => {
|
|
142
|
-
var s,
|
|
142
|
+
var s, o;
|
|
143
143
|
if (this._isLoadingMesh) return null;
|
|
144
|
-
const e = (
|
|
145
|
-
return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((
|
|
146
|
-
var
|
|
147
|
-
return this._isLoadingMesh = !1,
|
|
144
|
+
const e = (o = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : o[K];
|
|
145
|
+
return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((i) => {
|
|
146
|
+
var r;
|
|
147
|
+
return this._isLoadingMesh = !1, i && x.registerMesh(this.url, e.guid, i, (r = e.lods) == null ? void 0 : r.length, 0, e), i;
|
|
148
148
|
})) : null;
|
|
149
149
|
});
|
|
150
|
-
|
|
150
|
+
w && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
|
|
151
151
|
}
|
|
152
152
|
/** The name of the extension */
|
|
153
153
|
get name() {
|
|
@@ -163,8 +163,8 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
163
163
|
return e ?? -1;
|
|
164
164
|
}
|
|
165
165
|
static getMaterialMinMaxLODsCount(t, e) {
|
|
166
|
-
const s = this,
|
|
167
|
-
if (
|
|
166
|
+
const s = this, o = "LODS:minmax", i = t[o];
|
|
167
|
+
if (i != null) return i;
|
|
168
168
|
if (e || (e = {
|
|
169
169
|
min_count: 1 / 0,
|
|
170
170
|
max_count: 0,
|
|
@@ -172,21 +172,21 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
172
172
|
}), Array.isArray(t)) {
|
|
173
173
|
for (const a of t)
|
|
174
174
|
this.getMaterialMinMaxLODsCount(a, e);
|
|
175
|
-
return t[
|
|
175
|
+
return t[o] = e, e;
|
|
176
176
|
}
|
|
177
|
-
if (
|
|
177
|
+
if (w === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
|
|
178
178
|
const a = t;
|
|
179
179
|
for (const l of Object.keys(a.uniforms)) {
|
|
180
180
|
const c = a.uniforms[l].value;
|
|
181
|
-
(c == null ? void 0 : c.isTexture) === !0 &&
|
|
181
|
+
(c == null ? void 0 : c.isTexture) === !0 && r(c, e);
|
|
182
182
|
}
|
|
183
183
|
} else if (t.isMaterial)
|
|
184
184
|
for (const a of Object.keys(t)) {
|
|
185
185
|
const l = t[a];
|
|
186
|
-
(l == null ? void 0 : l.isTexture) === !0 &&
|
|
186
|
+
(l == null ? void 0 : l.isTexture) === !0 && r(l, e);
|
|
187
187
|
}
|
|
188
|
-
return t[
|
|
189
|
-
function
|
|
188
|
+
return t[o] = e, e;
|
|
189
|
+
function r(a, l) {
|
|
190
190
|
const c = s.getAssignedLODInformation(a);
|
|
191
191
|
if (c) {
|
|
192
192
|
const u = s.lodInfos.get(c.key);
|
|
@@ -206,30 +206,30 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
206
206
|
* @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
|
|
207
207
|
*/
|
|
208
208
|
static hasLODLevelAvailable(t, e) {
|
|
209
|
-
var
|
|
209
|
+
var i;
|
|
210
210
|
if (Array.isArray(t)) {
|
|
211
|
-
for (const
|
|
212
|
-
if (this.hasLODLevelAvailable(
|
|
211
|
+
for (const r of t)
|
|
212
|
+
if (this.hasLODLevelAvailable(r, e)) return !0;
|
|
213
213
|
return !1;
|
|
214
214
|
}
|
|
215
215
|
if (t.isMaterial === !0) {
|
|
216
|
-
for (const
|
|
217
|
-
const a = t[
|
|
216
|
+
for (const r of Object.keys(t)) {
|
|
217
|
+
const a = t[r];
|
|
218
218
|
if (a && a.isTexture && this.hasLODLevelAvailable(a, e))
|
|
219
219
|
return !0;
|
|
220
220
|
}
|
|
221
221
|
return !1;
|
|
222
222
|
} else if (t.isGroup === !0) {
|
|
223
|
-
for (const
|
|
224
|
-
if (
|
|
223
|
+
for (const r of t.children)
|
|
224
|
+
if (r.isMesh === !0 && this.hasLODLevelAvailable(r, e))
|
|
225
225
|
return !0;
|
|
226
226
|
}
|
|
227
|
-
let s,
|
|
228
|
-
if (t.isMesh ? s = t.geometry : (t.isBufferGeometry || t.isTexture) && (s = t), s && (
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
231
|
-
if (
|
|
232
|
-
return Array.isArray(
|
|
227
|
+
let s, o;
|
|
228
|
+
if (t.isMesh ? s = t.geometry : (t.isBufferGeometry || t.isTexture) && (s = t), s && (i = s == null ? void 0 : s.userData) != null && i.LODS) {
|
|
229
|
+
const r = s.userData.LODS;
|
|
230
|
+
if (o = this.lodInfos.get(r.key), e === void 0) return o != null;
|
|
231
|
+
if (o)
|
|
232
|
+
return Array.isArray(o.lods) ? e < o.lods.length : e === 0;
|
|
233
233
|
}
|
|
234
234
|
return !1;
|
|
235
235
|
}
|
|
@@ -251,19 +251,19 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
251
251
|
var s;
|
|
252
252
|
if (!t) return Promise.resolve(null);
|
|
253
253
|
if (t instanceof te || t.isMesh === !0) {
|
|
254
|
-
const
|
|
255
|
-
if (!
|
|
254
|
+
const o = t.geometry, i = this.getAssignedLODInformation(o);
|
|
255
|
+
if (!i)
|
|
256
256
|
return Promise.resolve(null);
|
|
257
|
-
for (const
|
|
258
|
-
(s =
|
|
259
|
-
return t["LOD:requested level"] = e,
|
|
260
|
-
if (Array.isArray(
|
|
261
|
-
const a =
|
|
262
|
-
|
|
257
|
+
for (const r of Q)
|
|
258
|
+
(s = r.onBeforeGetLODMesh) == null || s.call(r, t, e);
|
|
259
|
+
return t["LOD:requested level"] = e, x.getOrLoadLOD(o, e).then((r) => {
|
|
260
|
+
if (Array.isArray(r)) {
|
|
261
|
+
const a = i.index || 0;
|
|
262
|
+
r = r[a];
|
|
263
263
|
}
|
|
264
|
-
return t["LOD:requested level"] === e && (delete t["LOD:requested level"],
|
|
265
|
-
}).catch((
|
|
266
|
-
} else
|
|
264
|
+
return t["LOD:requested level"] === e && (delete t["LOD:requested level"], r && o != r && ((r == null ? void 0 : r.isBufferGeometry) ? t.geometry = r : w && console.error("Invalid LOD geometry", r))), r;
|
|
265
|
+
}).catch((r) => (console.error("Error loading mesh LOD", t, r), null));
|
|
266
|
+
} else w && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
|
|
267
267
|
return Promise.resolve(null);
|
|
268
268
|
}
|
|
269
269
|
static assignTextureLOD(t, e = 0) {
|
|
@@ -271,103 +271,103 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
271
271
|
if (t.isMesh === !0) {
|
|
272
272
|
const s = t;
|
|
273
273
|
if (Array.isArray(s.material)) {
|
|
274
|
-
const
|
|
275
|
-
for (const
|
|
276
|
-
const
|
|
277
|
-
|
|
274
|
+
const o = new Array();
|
|
275
|
+
for (const i of s.material) {
|
|
276
|
+
const r = this.assignTextureLOD(i, e);
|
|
277
|
+
o.push(r);
|
|
278
278
|
}
|
|
279
|
-
return Promise.all(
|
|
280
|
-
const
|
|
281
|
-
for (const a of
|
|
282
|
-
Array.isArray(a) &&
|
|
283
|
-
return
|
|
279
|
+
return Promise.all(o).then((i) => {
|
|
280
|
+
const r = new Array();
|
|
281
|
+
for (const a of i)
|
|
282
|
+
Array.isArray(a) && r.push(...a);
|
|
283
|
+
return r;
|
|
284
284
|
});
|
|
285
285
|
} else
|
|
286
286
|
return this.assignTextureLOD(s.material, e);
|
|
287
287
|
}
|
|
288
288
|
if (t.isMaterial === !0) {
|
|
289
|
-
const s = t,
|
|
289
|
+
const s = t, o = [], i = new Array();
|
|
290
290
|
if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
|
|
291
|
-
const
|
|
292
|
-
for (const a of Object.keys(
|
|
293
|
-
const l =
|
|
291
|
+
const r = s;
|
|
292
|
+
for (const a of Object.keys(r.uniforms)) {
|
|
293
|
+
const l = r.uniforms[a].value;
|
|
294
294
|
if ((l == null ? void 0 : l.isTexture) === !0) {
|
|
295
|
-
const c = this.assignTextureLODForSlot(l, e, s, a).then((u) => (u &&
|
|
296
|
-
|
|
295
|
+
const c = this.assignTextureLODForSlot(l, e, s, a).then((u) => (u && r.uniforms[a].value != u && (r.uniforms[a].value = u, r.uniformsNeedUpdate = !0), u));
|
|
296
|
+
o.push(c), i.push(a);
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
} else
|
|
300
|
-
for (const
|
|
301
|
-
const a = s[
|
|
300
|
+
for (const r of Object.keys(s)) {
|
|
301
|
+
const a = s[r];
|
|
302
302
|
if ((a == null ? void 0 : a.isTexture) === !0) {
|
|
303
|
-
const l = this.assignTextureLODForSlot(a, e, s,
|
|
304
|
-
|
|
303
|
+
const l = this.assignTextureLODForSlot(a, e, s, r);
|
|
304
|
+
o.push(l), i.push(r);
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
return Promise.all(
|
|
307
|
+
return Promise.all(o).then((r) => {
|
|
308
308
|
const a = new Array();
|
|
309
|
-
for (let l = 0; l <
|
|
310
|
-
const c =
|
|
309
|
+
for (let l = 0; l < r.length; l++) {
|
|
310
|
+
const c = r[l], u = i[l];
|
|
311
311
|
c && c.isTexture === !0 ? a.push({ material: s, slot: u, texture: c, level: e }) : a.push({ material: s, slot: u, texture: null, level: e });
|
|
312
312
|
}
|
|
313
313
|
return a;
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
|
-
if (t instanceof
|
|
316
|
+
if (t instanceof oe || t.isTexture === !0) {
|
|
317
317
|
const s = t;
|
|
318
318
|
return this.assignTextureLODForSlot(s, e, null, null);
|
|
319
319
|
}
|
|
320
320
|
return Promise.resolve(null);
|
|
321
321
|
}
|
|
322
|
-
static assignTextureLODForSlot(t, e, s,
|
|
323
|
-
return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) :
|
|
324
|
-
if (Array.isArray(
|
|
325
|
-
if ((
|
|
326
|
-
if (
|
|
327
|
-
const
|
|
328
|
-
if (
|
|
329
|
-
const a = this.getAssignedLODInformation(
|
|
322
|
+
static assignTextureLODForSlot(t, e, s, o) {
|
|
323
|
+
return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : o === "glyphMap" ? Promise.resolve(t) : x.getOrLoadLOD(t, e).then((i) => {
|
|
324
|
+
if (Array.isArray(i)) return null;
|
|
325
|
+
if ((i == null ? void 0 : i.isTexture) === !0) {
|
|
326
|
+
if (i != t && s && o) {
|
|
327
|
+
const r = s[o];
|
|
328
|
+
if (r && !w) {
|
|
329
|
+
const a = this.getAssignedLODInformation(r);
|
|
330
330
|
if (a && (a == null ? void 0 : a.level) < e)
|
|
331
|
-
return
|
|
331
|
+
return w === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, r, i), null;
|
|
332
332
|
}
|
|
333
|
-
s[
|
|
333
|
+
s[o] = i;
|
|
334
334
|
}
|
|
335
|
-
return
|
|
336
|
-
} else
|
|
335
|
+
return i;
|
|
336
|
+
} else w == "verbose" && console.warn("No LOD found for", t, e);
|
|
337
337
|
return null;
|
|
338
|
-
}).catch((
|
|
338
|
+
}).catch((i) => (console.error("Error loading LOD", t, i), null));
|
|
339
339
|
}
|
|
340
340
|
afterRoot(t) {
|
|
341
341
|
var e, s;
|
|
342
|
-
return
|
|
343
|
-
var
|
|
344
|
-
if (
|
|
345
|
-
const a =
|
|
342
|
+
return w && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((o, i) => {
|
|
343
|
+
var r;
|
|
344
|
+
if (o != null && o.extensions) {
|
|
345
|
+
const a = o == null ? void 0 : o.extensions[K];
|
|
346
346
|
if (a) {
|
|
347
347
|
if (!a.lods) {
|
|
348
|
-
|
|
348
|
+
w && console.warn("Texture has no LODs", a);
|
|
349
349
|
return;
|
|
350
350
|
}
|
|
351
351
|
let l = !1;
|
|
352
352
|
for (const c of this.parser.associations.keys())
|
|
353
353
|
if (c.isTexture === !0) {
|
|
354
354
|
const u = this.parser.associations.get(c);
|
|
355
|
-
(u == null ? void 0 : u.textures) ===
|
|
355
|
+
(u == null ? void 0 : u.textures) === i && (l = !0, x.registerTexture(this.url, c, (r = a.lods) == null ? void 0 : r.length, i, a));
|
|
356
356
|
}
|
|
357
|
-
l || this.parser.getDependency("texture",
|
|
357
|
+
l || this.parser.getDependency("texture", i).then((c) => {
|
|
358
358
|
var u;
|
|
359
|
-
c &&
|
|
359
|
+
c && x.registerTexture(this.url, c, (u = a.lods) == null ? void 0 : u.length, i, a);
|
|
360
360
|
});
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
|
-
}), (s = this.parser.json.meshes) == null || s.forEach((
|
|
364
|
-
if (
|
|
365
|
-
const
|
|
366
|
-
if (
|
|
363
|
+
}), (s = this.parser.json.meshes) == null || s.forEach((o, i) => {
|
|
364
|
+
if (o != null && o.extensions) {
|
|
365
|
+
const r = o == null ? void 0 : o.extensions[K];
|
|
366
|
+
if (r && r.lods) {
|
|
367
367
|
for (const a of this.parser.associations.keys())
|
|
368
368
|
if (a.isMesh) {
|
|
369
369
|
const l = this.parser.associations.get(a);
|
|
370
|
-
(l == null ? void 0 : l.meshes) ===
|
|
370
|
+
(l == null ? void 0 : l.meshes) === i && x.registerMesh(this.url, r.guid, a, r.lods.length, l.primitives, r);
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
}
|
|
@@ -375,57 +375,57 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
375
375
|
}
|
|
376
376
|
static async getOrLoadLOD(t, e) {
|
|
377
377
|
var a, l, c, u;
|
|
378
|
-
const s =
|
|
379
|
-
if (!
|
|
378
|
+
const s = w == "verbose", o = t.userData.LODS;
|
|
379
|
+
if (!o)
|
|
380
380
|
return null;
|
|
381
|
-
const
|
|
382
|
-
let
|
|
381
|
+
const i = o == null ? void 0 : o.key;
|
|
382
|
+
let r;
|
|
383
383
|
if (t.isTexture === !0) {
|
|
384
384
|
const h = t;
|
|
385
|
-
h.source && h.source[Oe] && (
|
|
385
|
+
h.source && h.source[Oe] && (r = h.source[Oe]);
|
|
386
386
|
}
|
|
387
|
-
if (
|
|
387
|
+
if (r || (r = x.lodInfos.get(i)), r) {
|
|
388
388
|
if (e > 0) {
|
|
389
|
-
let
|
|
390
|
-
const b = Array.isArray(
|
|
391
|
-
if (b && e >=
|
|
392
|
-
return this.lowresCache.get(
|
|
389
|
+
let D = !1;
|
|
390
|
+
const b = Array.isArray(r.lods);
|
|
391
|
+
if (b && e >= r.lods.length ? D = !0 : b || (D = !0), D)
|
|
392
|
+
return this.lowresCache.get(i);
|
|
393
393
|
}
|
|
394
|
-
const h = Array.isArray(
|
|
394
|
+
const h = Array.isArray(r.lods) ? (a = r.lods[e]) == null ? void 0 : a.path : r.lods;
|
|
395
395
|
if (!h)
|
|
396
|
-
return
|
|
397
|
-
const g = ut(
|
|
396
|
+
return w && !r["missing:uri"] && (r["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, r)), null;
|
|
397
|
+
const g = ut(o.url, h);
|
|
398
398
|
if (g.endsWith(".glb") || g.endsWith(".gltf")) {
|
|
399
|
-
if (!
|
|
400
|
-
return console.warn("missing pointer for glb/gltf texture",
|
|
401
|
-
const
|
|
399
|
+
if (!r.guid)
|
|
400
|
+
return console.warn("missing pointer for glb/gltf texture", r), null;
|
|
401
|
+
const D = g + "_" + r.guid, b = this.previouslyLoaded.get(D);
|
|
402
402
|
if (b !== void 0) {
|
|
403
|
-
s && console.log(`LOD ${e} was already loading/loaded: ${
|
|
404
|
-
let
|
|
405
|
-
`,
|
|
406
|
-
if (
|
|
407
|
-
return
|
|
403
|
+
s && console.log(`LOD ${e} was already loading/loaded: ${D}`);
|
|
404
|
+
let _ = await b.catch((y) => (console.error(`Error loading LOD ${e} from ${g}
|
|
405
|
+
`, y), null)), O = !1;
|
|
406
|
+
if (_ == null || (_ instanceof oe && t instanceof oe ? (l = _.image) != null && l.data || (c = _.source) != null && c.data ? _ = this.copySettings(t, _) : (O = !0, this.previouslyLoaded.delete(D)) : _ instanceof me && t instanceof me && ((u = _.attributes.position) != null && u.array || (O = !0, this.previouslyLoaded.delete(D)))), !O)
|
|
407
|
+
return _;
|
|
408
408
|
}
|
|
409
|
-
const
|
|
410
|
-
const
|
|
411
|
-
ze(
|
|
409
|
+
const v = r, F = new Promise(async (_, O) => {
|
|
410
|
+
const y = new Ce();
|
|
411
|
+
ze(y), w && (await new Promise((S) => setTimeout(S, 1e3)), s && console.warn("Start loading (delayed) " + g, v.guid));
|
|
412
412
|
let X = g;
|
|
413
|
-
if (
|
|
414
|
-
const S =
|
|
413
|
+
if (v && Array.isArray(v.lods)) {
|
|
414
|
+
const S = v.lods[e];
|
|
415
415
|
S.hash && (X += "?v=" + S.hash);
|
|
416
416
|
}
|
|
417
|
-
const
|
|
417
|
+
const P = await y.loadAsync(X).catch((S) => (console.error(`Error loading LOD ${e} from ${g}
|
|
418
418
|
`, S), null));
|
|
419
|
-
if (!
|
|
420
|
-
const I =
|
|
421
|
-
s && console.log("Loading finished " + g,
|
|
419
|
+
if (!P) return null;
|
|
420
|
+
const I = P.parser;
|
|
421
|
+
s && console.log("Loading finished " + g, v.guid);
|
|
422
422
|
let B = 0;
|
|
423
|
-
if (
|
|
423
|
+
if (P.parser.json.textures) {
|
|
424
424
|
let S = !1;
|
|
425
|
-
for (const f of
|
|
425
|
+
for (const f of P.parser.json.textures) {
|
|
426
426
|
if (f != null && f.extensions) {
|
|
427
|
-
const
|
|
428
|
-
if (
|
|
427
|
+
const T = f == null ? void 0 : f.extensions[K];
|
|
428
|
+
if (T != null && T.guid && T.guid === v.guid) {
|
|
429
429
|
S = !0;
|
|
430
430
|
break;
|
|
431
431
|
}
|
|
@@ -434,15 +434,15 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
434
434
|
}
|
|
435
435
|
if (S) {
|
|
436
436
|
let f = await I.getDependency("texture", B);
|
|
437
|
-
return f &&
|
|
438
|
-
} else
|
|
437
|
+
return f && x.assignLODInformation(o.url, f, i, e, void 0), s && console.log('change "' + t.name + '" → "' + f.name + '"', g, B, f, D), t instanceof oe && (f = this.copySettings(t, f)), f && (f.guid = v.guid), _(f);
|
|
438
|
+
} else w && console.warn("Could not find texture with guid", v.guid, P.parser.json);
|
|
439
439
|
}
|
|
440
|
-
if (B = 0,
|
|
440
|
+
if (B = 0, P.parser.json.meshes) {
|
|
441
441
|
let S = !1;
|
|
442
|
-
for (const f of
|
|
442
|
+
for (const f of P.parser.json.meshes) {
|
|
443
443
|
if (f != null && f.extensions) {
|
|
444
|
-
const
|
|
445
|
-
if (
|
|
444
|
+
const T = f == null ? void 0 : f.extensions[K];
|
|
445
|
+
if (T != null && T.guid && T.guid === v.guid) {
|
|
446
446
|
S = !0;
|
|
447
447
|
break;
|
|
448
448
|
}
|
|
@@ -451,39 +451,39 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
451
451
|
}
|
|
452
452
|
if (S) {
|
|
453
453
|
const f = await I.getDependency("mesh", B);
|
|
454
|
-
if (s && console.log(`Loaded Mesh "${f.name}"`, g, B, f,
|
|
455
|
-
const
|
|
456
|
-
return
|
|
454
|
+
if (s && console.log(`Loaded Mesh "${f.name}"`, g, B, f, D), f.isMesh === !0) {
|
|
455
|
+
const T = f.geometry;
|
|
456
|
+
return x.assignLODInformation(o.url, T, i, e, 0), _(T);
|
|
457
457
|
} else {
|
|
458
|
-
const
|
|
459
|
-
for (let
|
|
460
|
-
const M = f.children[
|
|
458
|
+
const T = new Array();
|
|
459
|
+
for (let L = 0; L < f.children.length; L++) {
|
|
460
|
+
const M = f.children[L];
|
|
461
461
|
if (M.isMesh === !0) {
|
|
462
462
|
const A = M.geometry;
|
|
463
|
-
|
|
463
|
+
x.assignLODInformation(o.url, A, i, e, L), T.push(A);
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
|
-
return
|
|
466
|
+
return _(T);
|
|
467
467
|
}
|
|
468
|
-
} else
|
|
468
|
+
} else w && console.warn("Could not find mesh with guid", v.guid, P.parser.json);
|
|
469
469
|
}
|
|
470
|
-
return
|
|
470
|
+
return _(null);
|
|
471
471
|
});
|
|
472
|
-
return this.previouslyLoaded.set(
|
|
473
|
-
} else if (t instanceof
|
|
472
|
+
return this.previouslyLoaded.set(D, F), await F;
|
|
473
|
+
} else if (t instanceof oe) {
|
|
474
474
|
s && console.log("Load texture from uri: " + g);
|
|
475
475
|
const b = await new Je().loadAsync(g);
|
|
476
|
-
return b ? (b.guid =
|
|
476
|
+
return b ? (b.guid = r.guid, b.flipY = !1, b.needsUpdate = !0, b.colorSpace = t.colorSpace, s && console.log(r, b)) : w && console.warn("failed loading", g), b;
|
|
477
477
|
}
|
|
478
478
|
} else
|
|
479
|
-
|
|
479
|
+
w && console.warn(`Can not load LOD ${e}: no LOD info found for "${i}" ${t.name}`, t.type);
|
|
480
480
|
return null;
|
|
481
481
|
}
|
|
482
|
-
static assignLODInformation(t, e, s,
|
|
482
|
+
static assignLODInformation(t, e, s, o, i) {
|
|
483
483
|
if (!e) return;
|
|
484
484
|
e.userData || (e.userData = {});
|
|
485
|
-
const
|
|
486
|
-
e.userData.LODS =
|
|
485
|
+
const r = new mt(t, s, o, i);
|
|
486
|
+
e.userData.LODS = r;
|
|
487
487
|
}
|
|
488
488
|
static getAssignedLODInformation(t) {
|
|
489
489
|
var e;
|
|
@@ -491,7 +491,7 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
491
491
|
}
|
|
492
492
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
493
493
|
static copySettings(t, e) {
|
|
494
|
-
return e ? (
|
|
494
|
+
return e ? (w && console.warn(`Copy texture settings
|
|
495
495
|
`, t.uuid, `
|
|
496
496
|
`, 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;
|
|
497
497
|
}
|
|
@@ -499,46 +499,46 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
499
499
|
/**
|
|
500
500
|
* Register a texture with LOD information
|
|
501
501
|
*/
|
|
502
|
-
d(
|
|
503
|
-
if (
|
|
504
|
-
|
|
502
|
+
d(x, "registerTexture", (t, e, s, o, i) => {
|
|
503
|
+
if (w && console.log("> Progressive: register texture", o, e.name, e.uuid, e, i), !e) {
|
|
504
|
+
w && console.error("gltf-progressive: Register texture without texture");
|
|
505
505
|
return;
|
|
506
506
|
}
|
|
507
|
-
e.source && (e.source[Oe] =
|
|
508
|
-
const
|
|
509
|
-
|
|
507
|
+
e.source && (e.source[Oe] = i);
|
|
508
|
+
const r = i.guid;
|
|
509
|
+
x.assignLODInformation(t, e, r, s, o), x.lodInfos.set(r, i), x.lowresCache.set(r, e);
|
|
510
510
|
}), /**
|
|
511
511
|
* Register a mesh with LOD information
|
|
512
512
|
*/
|
|
513
|
-
d(
|
|
513
|
+
d(x, "registerMesh", (t, e, s, o, i, r) => {
|
|
514
514
|
var c;
|
|
515
515
|
const a = s.geometry;
|
|
516
516
|
if (!a) {
|
|
517
|
-
|
|
517
|
+
w && console.warn("gltf-progressive: Register mesh without geometry");
|
|
518
518
|
return;
|
|
519
519
|
}
|
|
520
|
-
a.userData || (a.userData = {}),
|
|
521
|
-
let l =
|
|
522
|
-
l ? l.push(s.geometry) : l = [s.geometry],
|
|
520
|
+
a.userData || (a.userData = {}), w && console.log("> Progressive: register mesh " + s.name, { index: i, uuid: s.uuid }, r, s), x.assignLODInformation(t, a, e, o, i), x.lodInfos.set(e, r);
|
|
521
|
+
let l = x.lowresCache.get(e);
|
|
522
|
+
l ? l.push(s.geometry) : l = [s.geometry], x.lowresCache.set(e, l), o > 0 && !ue(s) && gt(s, a);
|
|
523
523
|
for (const u of Q)
|
|
524
|
-
(c = u.onRegisteredNewMesh) == null || c.call(u, s,
|
|
524
|
+
(c = u.onRegisteredNewMesh) == null || c.call(u, s, r);
|
|
525
525
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
526
|
-
d(
|
|
527
|
-
d(
|
|
528
|
-
d(
|
|
529
|
-
let z =
|
|
530
|
-
class
|
|
531
|
-
constructor(t, e, s,
|
|
526
|
+
d(x, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
527
|
+
d(x, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
528
|
+
d(x, "lowresCache", /* @__PURE__ */ new Map());
|
|
529
|
+
let z = x;
|
|
530
|
+
class mt {
|
|
531
|
+
constructor(t, e, s, o) {
|
|
532
532
|
d(this, "url");
|
|
533
533
|
/** the key to lookup the LOD information */
|
|
534
534
|
d(this, "key");
|
|
535
535
|
d(this, "level");
|
|
536
536
|
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
537
537
|
d(this, "index");
|
|
538
|
-
this.url = t, this.key = e, this.level = s,
|
|
538
|
+
this.url = t, this.key = e, this.level = s, o != null && (this.index = o);
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
|
-
class
|
|
541
|
+
class ye {
|
|
542
542
|
constructor(t, e) {
|
|
543
543
|
d(this, "frame_start");
|
|
544
544
|
d(this, "frame_capture_end");
|
|
@@ -550,18 +550,16 @@ class me {
|
|
|
550
550
|
d(this, "_resolvedCount", 0);
|
|
551
551
|
/** These promises are currently being awaited */
|
|
552
552
|
d(this, "_awaiting", []);
|
|
553
|
-
d(this, "_maxPromisesPerObject", 1);
|
|
554
553
|
d(this, "_currentFrame", 0);
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
this._resolve = i;
|
|
554
|
+
var i;
|
|
555
|
+
const s = t === 0 ? 2 : 1, o = Math.max(e.frames ?? s, s);
|
|
556
|
+
this.frame_start = t, this.frame_capture_end = t + o, this.ready = new Promise((r) => {
|
|
557
|
+
this._resolve = r;
|
|
560
558
|
}), this.ready.finally(() => {
|
|
561
559
|
this._resolved = !0, this._awaiting.length = 0;
|
|
562
|
-
}), this._signal = e.signal, (
|
|
560
|
+
}), this._signal = e.signal, (i = this._signal) == null || i.addEventListener("abort", () => {
|
|
563
561
|
this.resolveNow();
|
|
564
|
-
})
|
|
562
|
+
});
|
|
565
563
|
}
|
|
566
564
|
/**
|
|
567
565
|
* The number of promises that have been added to this group so far.
|
|
@@ -579,26 +577,14 @@ class me {
|
|
|
579
577
|
var e;
|
|
580
578
|
this._currentFrame = t, ((e = this._signal) != null && e.aborted || this._currentFrame > this.frame_capture_end && this._awaiting.length === 0) && this.resolveNow();
|
|
581
579
|
}
|
|
582
|
-
add(t, e
|
|
580
|
+
add(t, e) {
|
|
583
581
|
if (this._resolved) {
|
|
584
|
-
|
|
582
|
+
console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
|
|
585
583
|
return;
|
|
586
584
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
let n = this._seen.get(e);
|
|
591
|
-
if (n >= this._maxPromisesPerObject) {
|
|
592
|
-
y && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
this._seen.set(e, n + 1);
|
|
596
|
-
} else
|
|
597
|
-
this._seen.set(e, 1);
|
|
598
|
-
this._awaiting.push(s), this._addedCount++, s.finally(() => {
|
|
599
|
-
this._resolvedCount++, this._awaiting.splice(this._awaiting.indexOf(s), 1);
|
|
600
|
-
});
|
|
601
|
-
}
|
|
585
|
+
this._currentFrame > this.frame_capture_end || (this._awaiting.push(e), this._addedCount++, e.finally(() => {
|
|
586
|
+
this._resolvedCount++, this._awaiting.splice(this._awaiting.indexOf(e), 1);
|
|
587
|
+
}));
|
|
602
588
|
}
|
|
603
589
|
resolveNow() {
|
|
604
590
|
var t, e;
|
|
@@ -609,14 +595,14 @@ class me {
|
|
|
609
595
|
});
|
|
610
596
|
}
|
|
611
597
|
}
|
|
612
|
-
d(
|
|
613
|
-
|
|
614
|
-
|
|
598
|
+
d(ye, "addPromise", (t, e, s) => {
|
|
599
|
+
s.forEach((o) => {
|
|
600
|
+
o.add(t, e);
|
|
615
601
|
});
|
|
616
602
|
});
|
|
617
603
|
const k = de("debugprogressive"), Lt = de("noprogressive"), be = Symbol("Needle:LODSManager"), Se = Symbol("Needle:LODState"), J = Symbol("Needle:CurrentLOD"), C = { mesh_lod: -1, texture_lod: -1 };
|
|
618
|
-
var
|
|
619
|
-
let xe = (
|
|
604
|
+
var m, E, Y, we, Z, re, ve, H;
|
|
605
|
+
let xe = (m = class {
|
|
620
606
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
621
607
|
constructor(t, e) {
|
|
622
608
|
d(this, "renderer");
|
|
@@ -657,7 +643,7 @@ let xe = (L = class {
|
|
|
657
643
|
j(this, we, new Qe());
|
|
658
644
|
j(this, Z, 0);
|
|
659
645
|
j(this, re, 0);
|
|
660
|
-
j(this,
|
|
646
|
+
j(this, ve, 0);
|
|
661
647
|
j(this, H, 0);
|
|
662
648
|
d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
|
|
663
649
|
// private testIfLODLevelsAreAvailable() {
|
|
@@ -689,7 +675,7 @@ let xe = (L = class {
|
|
|
689
675
|
static get(t, e) {
|
|
690
676
|
if (t[be])
|
|
691
677
|
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[be];
|
|
692
|
-
const s = new
|
|
678
|
+
const s = new m(t, {
|
|
693
679
|
engine: "unknown",
|
|
694
680
|
...e
|
|
695
681
|
});
|
|
@@ -703,13 +689,13 @@ let xe = (L = class {
|
|
|
703
689
|
* Call to await LODs loading during the next render cycle.
|
|
704
690
|
*/
|
|
705
691
|
awaitLoading(t) {
|
|
706
|
-
const e = this._promiseGroupIds++, s = new
|
|
692
|
+
const e = this._promiseGroupIds++, s = new ye(p(this, Z), { ...t });
|
|
707
693
|
this._newPromiseGroups.push(s);
|
|
708
|
-
const
|
|
694
|
+
const o = performance.now();
|
|
709
695
|
return s.ready.finally(() => {
|
|
710
|
-
const
|
|
711
|
-
|
|
712
|
-
start:
|
|
696
|
+
const i = this._newPromiseGroups.indexOf(s);
|
|
697
|
+
i >= 0 && (this._newPromiseGroups.splice(i, 1), ft() && performance.measure("LODsManager:awaitLoading", {
|
|
698
|
+
start: o,
|
|
713
699
|
detail: { id: e, name: t == null ? void 0 : t.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
|
|
714
700
|
}));
|
|
715
701
|
}), s.ready;
|
|
@@ -737,11 +723,11 @@ let xe = (L = class {
|
|
|
737
723
|
let t = 0;
|
|
738
724
|
N(this, Y, this.renderer.render);
|
|
739
725
|
const e = this;
|
|
740
|
-
Ne(this.renderer), this.renderer.render = function(s,
|
|
741
|
-
const
|
|
742
|
-
(
|
|
743
|
-
const
|
|
744
|
-
p(e, Y).call(this, s,
|
|
726
|
+
Ne(this.renderer), this.renderer.render = function(s, o) {
|
|
727
|
+
const i = e.renderer.getRenderTarget();
|
|
728
|
+
(i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (t = 0, N(e, Z, p(e, Z) + 1), N(e, re, p(e, we).getDelta()), N(e, ve, p(e, ve) + p(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / p(e, re)), N(e, H, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), k && p(e, Z) % 200 === 0 && console.log("FPS", Math.round(p(e, H)), "Interval:", p(e, E)));
|
|
729
|
+
const r = t++;
|
|
730
|
+
p(e, Y).call(this, s, o), e.onAfterRender(s, o, r);
|
|
745
731
|
};
|
|
746
732
|
}
|
|
747
733
|
disable() {
|
|
@@ -752,13 +738,13 @@ let xe = (L = class {
|
|
|
752
738
|
}
|
|
753
739
|
onAfterRender(t, e, s) {
|
|
754
740
|
if (this.pause) return;
|
|
755
|
-
const
|
|
756
|
-
let
|
|
757
|
-
if (
|
|
758
|
-
const a =
|
|
759
|
-
(a.name === "EffectMaterial" || a.name === "CopyShader") && (
|
|
741
|
+
const i = this.renderer.renderLists.get(t, 0).opaque;
|
|
742
|
+
let r = !0;
|
|
743
|
+
if (i.length === 1) {
|
|
744
|
+
const a = i[0].material;
|
|
745
|
+
(a.name === "EffectMaterial" || a.name === "CopyShader") && (r = !1);
|
|
760
746
|
}
|
|
761
|
-
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (
|
|
747
|
+
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (r = !1), r) {
|
|
762
748
|
if (Lt || (this.updateInterval === "auto" ? p(this, H) < 40 && p(this, E) < 10 ? (N(this, E, p(this, E) + 1), k && console.warn("↓ Reducing LOD updates", p(this, E), p(this, H).toFixed(0))) : p(this, H) >= 60 && p(this, E) > 1 && (N(this, E, p(this, E) - 1), k && console.warn("↑ Increasing LOD updates", p(this, E), p(this, H).toFixed(0))) : N(this, E, this.updateInterval), p(this, E) > 0 && p(this, Z) % p(this, E) != 0))
|
|
763
749
|
return;
|
|
764
750
|
this.internalUpdate(t, e), this._postprocessPromiseGroups();
|
|
@@ -769,10 +755,10 @@ let xe = (L = class {
|
|
|
769
755
|
*/
|
|
770
756
|
internalUpdate(t, e) {
|
|
771
757
|
var l, c;
|
|
772
|
-
const s = this.renderer.renderLists.get(t, 0),
|
|
758
|
+
const s = this.renderer.renderLists.get(t, 0), o = s.opaque;
|
|
773
759
|
this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
|
|
774
|
-
const
|
|
775
|
-
for (const u of
|
|
760
|
+
const i = this.targetTriangleDensity;
|
|
761
|
+
for (const u of o) {
|
|
776
762
|
if (u.material && (((l = u.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((c = u.geometry) == null ? void 0 : c.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
|
|
777
763
|
k && (u.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (u.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", u, u.material.name, u.material.type)));
|
|
778
764
|
continue;
|
|
@@ -788,37 +774,37 @@ let xe = (L = class {
|
|
|
788
774
|
}
|
|
789
775
|
if (k === "color" && u.material && !u.object.progressive_debug_color) {
|
|
790
776
|
u.object.progressive_debug_color = !0;
|
|
791
|
-
const g = Math.random() * 16777215,
|
|
792
|
-
u.object.material =
|
|
777
|
+
const g = Math.random() * 16777215, D = new Ze({ color: g });
|
|
778
|
+
u.object.material = D;
|
|
793
779
|
}
|
|
794
780
|
const h = u.object;
|
|
795
|
-
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h,
|
|
781
|
+
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
|
|
796
782
|
}
|
|
797
|
-
const
|
|
798
|
-
for (const u of
|
|
783
|
+
const r = s.transparent;
|
|
784
|
+
for (const u of r) {
|
|
799
785
|
const h = u.object;
|
|
800
|
-
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h,
|
|
786
|
+
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
|
|
801
787
|
}
|
|
802
788
|
const a = s.transmissive;
|
|
803
789
|
for (const u of a) {
|
|
804
790
|
const h = u.object;
|
|
805
|
-
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h,
|
|
791
|
+
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, i);
|
|
806
792
|
}
|
|
807
793
|
}
|
|
808
794
|
/** Update the LOD levels for the renderer. */
|
|
809
|
-
updateLODs(t, e, s,
|
|
795
|
+
updateLODs(t, e, s, o) {
|
|
810
796
|
var a, l;
|
|
811
797
|
s.userData || (s.userData = {});
|
|
812
|
-
let
|
|
813
|
-
if (
|
|
798
|
+
let i = s[Se];
|
|
799
|
+
if (i || (i = new xt(), s[Se] = i), i.frames++ < 2)
|
|
814
800
|
return;
|
|
815
801
|
for (const c of Q)
|
|
816
802
|
(a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, t, e, s);
|
|
817
|
-
const
|
|
818
|
-
|
|
803
|
+
const r = m.overrideGlobalLodLevel !== void 0 ? m.overrideGlobalLodLevel : ee;
|
|
804
|
+
r >= 0 ? (C.mesh_lod = r, C.texture_lod = r) : (this.calculateLodLevel(e, s, i, o, C), C.mesh_lod = Math.round(C.mesh_lod), C.texture_lod = Math.round(C.texture_lod)), C.mesh_lod >= 0 && this.loadProgressiveMeshes(s, C.mesh_lod), s.material && C.texture_lod >= 0 && this.loadProgressiveTextures(s.material, C.texture_lod), w && s.material && !s.isGizmo && We(s.material);
|
|
819
805
|
for (const c of Q)
|
|
820
806
|
(l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, C);
|
|
821
|
-
|
|
807
|
+
i.lastLodLevel_Mesh = C.mesh_lod, i.lastLodLevel_Texture = C.texture_lod;
|
|
822
808
|
}
|
|
823
809
|
/** Load progressive textures for the given material
|
|
824
810
|
* @param material the material to load the textures for
|
|
@@ -828,19 +814,19 @@ let xe = (L = class {
|
|
|
828
814
|
loadProgressiveTextures(t, e) {
|
|
829
815
|
if (!t) return;
|
|
830
816
|
if (Array.isArray(t)) {
|
|
831
|
-
for (const
|
|
832
|
-
this.loadProgressiveTextures(
|
|
817
|
+
for (const i of t)
|
|
818
|
+
this.loadProgressiveTextures(i, e);
|
|
833
819
|
return;
|
|
834
820
|
}
|
|
835
821
|
let s = !1;
|
|
836
822
|
(t[J] === void 0 || e < t[J]) && (s = !0);
|
|
837
|
-
const
|
|
838
|
-
if (
|
|
823
|
+
const o = t["DEBUG:LOD"];
|
|
824
|
+
if (o != null && (s = t[J] != o, e = o), s) {
|
|
839
825
|
t[J] = e;
|
|
840
|
-
const
|
|
826
|
+
const i = z.assignTextureLOD(t, e).then((r) => {
|
|
841
827
|
this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
|
|
842
828
|
});
|
|
843
|
-
|
|
829
|
+
ye.addPromise("texture", i, this._newPromiseGroups);
|
|
844
830
|
}
|
|
845
831
|
}
|
|
846
832
|
/** Load progressive meshes for the given mesh
|
|
@@ -852,120 +838,120 @@ let xe = (L = class {
|
|
|
852
838
|
loadProgressiveMeshes(t, e) {
|
|
853
839
|
if (!t) return Promise.resolve(null);
|
|
854
840
|
let s = t[J] !== e;
|
|
855
|
-
const
|
|
856
|
-
if (
|
|
841
|
+
const o = t["DEBUG:LOD"];
|
|
842
|
+
if (o != null && (s = t[J] != o, e = o), s) {
|
|
857
843
|
t[J] = e;
|
|
858
|
-
const
|
|
859
|
-
return
|
|
844
|
+
const i = t.geometry, r = z.assignMeshLOD(t, e).then((a) => (a && t[J] == e && i != t.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: e, object: t })), a));
|
|
845
|
+
return ye.addPromise("mesh", r, this._newPromiseGroups), r;
|
|
860
846
|
}
|
|
861
847
|
return Promise.resolve(null);
|
|
862
848
|
}
|
|
863
849
|
static isInside(t, e) {
|
|
864
|
-
const s = t.min,
|
|
865
|
-
return this._tempPtInside.set(
|
|
850
|
+
const s = t.min, o = t.max, i = (s.x + o.x) * 0.5, r = (s.y + o.y) * 0.5;
|
|
851
|
+
return this._tempPtInside.set(i, r, s.z).applyMatrix4(e).z < 0;
|
|
866
852
|
}
|
|
867
|
-
calculateLodLevel(t, e, s,
|
|
868
|
-
var F, W,
|
|
853
|
+
calculateLodLevel(t, e, s, o, i) {
|
|
854
|
+
var F, W, _;
|
|
869
855
|
if (!e) {
|
|
870
|
-
|
|
856
|
+
i.mesh_lod = -1, i.texture_lod = -1;
|
|
871
857
|
return;
|
|
872
858
|
}
|
|
873
859
|
if (!t) {
|
|
874
|
-
|
|
860
|
+
i.mesh_lod = -1, i.texture_lod = -1;
|
|
875
861
|
return;
|
|
876
862
|
}
|
|
877
863
|
let a = 10 + 1, l = !1;
|
|
878
864
|
if (k && e["DEBUG:LOD"] != null)
|
|
879
865
|
return e["DEBUG:LOD"];
|
|
880
|
-
const c = (F = z.getMeshLODExtension(e.geometry)) == null ? void 0 : F.lods, u = z.getPrimitiveIndex(e.geometry), h = c && c.length > 0, g = z.getMaterialMinMaxLODsCount(e.material),
|
|
881
|
-
if (!h && !
|
|
882
|
-
|
|
866
|
+
const c = (F = z.getMeshLODExtension(e.geometry)) == null ? void 0 : F.lods, u = z.getPrimitiveIndex(e.geometry), h = c && c.length > 0, g = z.getMaterialMinMaxLODsCount(e.material), D = (g == null ? void 0 : g.min_count) != 1 / 0 && g.min_count > 0 && g.max_count > 0;
|
|
867
|
+
if (!h && !D) {
|
|
868
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
883
869
|
return;
|
|
884
870
|
}
|
|
885
871
|
h || (l = !0, a = 0);
|
|
886
872
|
const b = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
887
|
-
let
|
|
873
|
+
let v = e.geometry.boundingBox;
|
|
888
874
|
if (e.type === "SkinnedMesh") {
|
|
889
875
|
const O = e;
|
|
890
876
|
if (!O.boundingBox)
|
|
891
877
|
O.computeBoundingBox();
|
|
892
878
|
else if (this.skinnedMeshAutoUpdateBoundsInterval > 0 && s.frames % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
|
|
893
|
-
const
|
|
894
|
-
|
|
879
|
+
const y = ue(O), X = O.geometry;
|
|
880
|
+
y && (O.geometry = y), O.computeBoundingBox(), O.geometry = X;
|
|
895
881
|
}
|
|
896
|
-
|
|
882
|
+
v = O.boundingBox;
|
|
897
883
|
}
|
|
898
|
-
if (
|
|
884
|
+
if (v) {
|
|
899
885
|
const O = t;
|
|
900
886
|
if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
|
|
901
887
|
this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
|
|
902
|
-
const
|
|
903
|
-
if (this._sphere.containsPoint(
|
|
904
|
-
|
|
888
|
+
const L = t.getWorldPosition(this._tempWorldPosition);
|
|
889
|
+
if (this._sphere.containsPoint(L)) {
|
|
890
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
905
891
|
return;
|
|
906
892
|
}
|
|
907
893
|
}
|
|
908
|
-
if (this._tempBox.copy(
|
|
909
|
-
|
|
894
|
+
if (this._tempBox.copy(v), this._tempBox.applyMatrix4(e.matrixWorld), O.isPerspectiveCamera && m.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
895
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
910
896
|
return;
|
|
911
897
|
}
|
|
912
898
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && O.isPerspectiveCamera && O.fov > 70) {
|
|
913
|
-
const
|
|
914
|
-
let A =
|
|
915
|
-
const ce = 2,
|
|
899
|
+
const L = this._tempBox.min, M = this._tempBox.max;
|
|
900
|
+
let A = L.x, R = L.y, U = M.x, ie = M.y;
|
|
901
|
+
const ce = 2, De = 1.5, fe = (L.x + M.x) * 0.5, he = (L.y + M.y) * 0.5;
|
|
916
902
|
A = (A - fe) * ce + fe, R = (R - he) * ce + he, U = (U - fe) * ce + fe, ie = (ie - he) * ce + he;
|
|
917
|
-
const Ke = A < 0 && U > 0 ? 0 : Math.min(Math.abs(
|
|
918
|
-
s.lastCentrality = (
|
|
903
|
+
const Ke = A < 0 && U > 0 ? 0 : Math.min(Math.abs(L.x), Math.abs(M.x)), Ye = R < 0 && ie > 0 ? 0 : Math.min(Math.abs(L.y), Math.abs(M.y)), _e = Math.max(Ke, Ye);
|
|
904
|
+
s.lastCentrality = (De - _e) * (De - _e) * (De - _e);
|
|
919
905
|
} else
|
|
920
906
|
s.lastCentrality = 1;
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
const X = t.matrixWorldInverse,
|
|
924
|
-
|
|
925
|
-
const I =
|
|
926
|
-
if (Math.max(
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
const M =
|
|
907
|
+
const y = this._tempBox.getSize(this._tempBoxSize);
|
|
908
|
+
y.multiplyScalar(0.5), screen.availHeight > 0 && b > 0 && y.multiplyScalar(b / screen.availHeight), t.isPerspectiveCamera ? y.x *= t.aspect : t.isOrthographicCamera;
|
|
909
|
+
const X = t.matrixWorldInverse, P = this._tempBox2;
|
|
910
|
+
P.copy(v), P.applyMatrix4(e.matrixWorld), P.applyMatrix4(X);
|
|
911
|
+
const I = P.getSize(this._tempBox2Size), B = Math.max(I.x, I.y);
|
|
912
|
+
if (Math.max(y.x, y.y) != 0 && B != 0 && (y.z = I.z / Math.max(I.x, I.y) * Math.max(y.x, y.y)), s.lastScreenCoverage = Math.max(y.x, y.y, y.z), s.lastScreenspaceVolume.copy(y), s.lastScreenCoverage *= s.lastCentrality, k && m.debugDrawLine) {
|
|
913
|
+
const L = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
914
|
+
L.invert();
|
|
915
|
+
const M = m.corner0, A = m.corner1, R = m.corner2, U = m.corner3;
|
|
930
916
|
M.copy(this._tempBox.min), A.copy(this._tempBox.max), A.x = M.x, R.copy(this._tempBox.max), R.y = M.y, U.copy(this._tempBox.max);
|
|
931
917
|
const ie = (M.z + U.z) * 0.5;
|
|
932
|
-
M.z = A.z = R.z = U.z = ie, M.applyMatrix4(
|
|
918
|
+
M.z = A.z = R.z = U.z = ie, M.applyMatrix4(L), A.applyMatrix4(L), R.applyMatrix4(L), U.applyMatrix4(L), m.debugDrawLine(M, A, 255), m.debugDrawLine(M, R, 255), m.debugDrawLine(A, U, 255), m.debugDrawLine(R, U, 255);
|
|
933
919
|
}
|
|
934
920
|
let f = 999;
|
|
935
921
|
if (c && s.lastScreenCoverage > 0)
|
|
936
|
-
for (let
|
|
937
|
-
const M = c[
|
|
938
|
-
if ((((W = M.densities) == null ? void 0 : W[u]) || M.density || 1e-5) / s.lastScreenCoverage <
|
|
939
|
-
f =
|
|
922
|
+
for (let L = 0; L < c.length; L++) {
|
|
923
|
+
const M = c[L];
|
|
924
|
+
if ((((W = M.densities) == null ? void 0 : W[u]) || M.density || 1e-5) / s.lastScreenCoverage < o) {
|
|
925
|
+
f = L;
|
|
940
926
|
break;
|
|
941
927
|
}
|
|
942
928
|
}
|
|
943
929
|
f < a && (a = f, l = !0);
|
|
944
930
|
}
|
|
945
|
-
if (l ?
|
|
946
|
-
const
|
|
947
|
-
|
|
931
|
+
if (l ? i.mesh_lod = a : i.mesh_lod = s.lastLodLevel_Mesh, k && i.mesh_lod != s.lastLodLevel_Mesh) {
|
|
932
|
+
const y = c == null ? void 0 : c[i.mesh_lod];
|
|
933
|
+
y && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${i.mesh_lod} (${y.density.toFixed(0)}) - ${e.name}`);
|
|
948
934
|
}
|
|
949
|
-
if (
|
|
935
|
+
if (D) {
|
|
950
936
|
const O = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
951
937
|
if (s.lastLodLevel_Texture < 0) {
|
|
952
|
-
if (
|
|
953
|
-
const
|
|
954
|
-
k && console.log(`First Texture LOD ${
|
|
938
|
+
if (i.texture_lod = g.max_count - 1, k) {
|
|
939
|
+
const y = g.lods[g.max_count - 1];
|
|
940
|
+
k && console.log(`First Texture LOD ${i.texture_lod} (${y.max_height}px) - ${e.name}`);
|
|
955
941
|
}
|
|
956
942
|
} else {
|
|
957
|
-
const
|
|
943
|
+
const y = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
958
944
|
let X = s.lastScreenCoverage * 4;
|
|
959
|
-
((
|
|
945
|
+
((_ = this.context) == null ? void 0 : _.engine) === "model-viewer" && (X *= 1.5);
|
|
960
946
|
const I = b / window.devicePixelRatio * X;
|
|
961
947
|
let B = !1;
|
|
962
948
|
for (let S = g.lods.length - 1; S >= 0; S--) {
|
|
963
949
|
const f = g.lods[S];
|
|
964
950
|
if (!(O && f.max_height >= 2048) && !(ct() && f.max_height > 4096) && (f.max_height > I || !B && S === 0)) {
|
|
965
|
-
if (B = !0,
|
|
966
|
-
const
|
|
967
|
-
k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${
|
|
968
|
-
Screensize: ${I.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${
|
|
951
|
+
if (B = !0, i.texture_lod = S, i.texture_lod < s.lastLodLevel_Texture) {
|
|
952
|
+
const T = f.max_height;
|
|
953
|
+
k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${T}px
|
|
954
|
+
Screensize: ${I.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${y.toFixed(1)}
|
|
969
955
|
${e.name}`);
|
|
970
956
|
}
|
|
971
957
|
break;
|
|
@@ -973,15 +959,15 @@ ${e.name}`);
|
|
|
973
959
|
}
|
|
974
960
|
}
|
|
975
961
|
} else
|
|
976
|
-
|
|
962
|
+
i.texture_lod = 0;
|
|
977
963
|
}
|
|
978
|
-
}, E = new WeakMap(), Y = new WeakMap(), we = new WeakMap(), Z = new WeakMap(), re = new WeakMap(),
|
|
964
|
+
}, E = new WeakMap(), Y = new WeakMap(), we = new WeakMap(), Z = new WeakMap(), re = new WeakMap(), ve = new WeakMap(), H = new WeakMap(), /**
|
|
979
965
|
* Assign a function to draw debug lines for the LODs. This function will be called with the start and end position of the line and the color of the line when the `debugprogressive` query parameter is set.
|
|
980
966
|
*/
|
|
981
|
-
d(
|
|
967
|
+
d(m, "debugDrawLine"), /**
|
|
982
968
|
* Force override the LOD level for all objects in the scene
|
|
983
969
|
*/
|
|
984
|
-
d(
|
|
970
|
+
d(m, "overrideGlobalLodLevel"), d(m, "corner0", new q()), d(m, "corner1", new q()), d(m, "corner2", new q()), d(m, "corner3", new q()), d(m, "_tempPtInside", new q()), m);
|
|
985
971
|
class xt {
|
|
986
972
|
constructor() {
|
|
987
973
|
d(this, "frames", 0);
|
|
@@ -995,8 +981,8 @@ class xt {
|
|
|
995
981
|
const Re = Symbol("NEEDLE_mesh_lod"), ge = Symbol("NEEDLE_texture_lod");
|
|
996
982
|
let le = null;
|
|
997
983
|
function Xe() {
|
|
998
|
-
const
|
|
999
|
-
|
|
984
|
+
const n = wt();
|
|
985
|
+
n && (n.mapURLs(function(t) {
|
|
1000
986
|
return ke(), t;
|
|
1001
987
|
}), ke(), le == null || le.disconnect(), le = new MutationObserver((t) => {
|
|
1002
988
|
t.forEach((e) => {
|
|
@@ -1008,8 +994,8 @@ function Xe() {
|
|
|
1008
994
|
}
|
|
1009
995
|
function wt() {
|
|
1010
996
|
if (typeof customElements > "u") return null;
|
|
1011
|
-
const
|
|
1012
|
-
return
|
|
997
|
+
const n = customElements.get("model-viewer");
|
|
998
|
+
return n || (customElements.whenDefined("model-viewer").then(() => {
|
|
1013
999
|
console.debug("[gltf-progressive] model-viewer defined"), Xe();
|
|
1014
1000
|
}), null);
|
|
1015
1001
|
}
|
|
@@ -1020,49 +1006,49 @@ function ke() {
|
|
|
1020
1006
|
});
|
|
1021
1007
|
}
|
|
1022
1008
|
const $e = /* @__PURE__ */ new WeakSet();
|
|
1023
|
-
let
|
|
1024
|
-
function qe(
|
|
1025
|
-
if (!
|
|
1009
|
+
let vt = 0;
|
|
1010
|
+
function qe(n) {
|
|
1011
|
+
if (!n || $e.has(n))
|
|
1026
1012
|
return null;
|
|
1027
|
-
$e.add(
|
|
1028
|
-
`,
|
|
1013
|
+
$e.add(n), console.debug("[gltf-progressive] found new model-viewer..." + ++vt + `
|
|
1014
|
+
`, n.getAttribute("src"));
|
|
1029
1015
|
let t = null, e = null, s = null;
|
|
1030
|
-
for (let
|
|
1031
|
-
const
|
|
1032
|
-
!t &&
|
|
1016
|
+
for (let o = n; o != null; o = Object.getPrototypeOf(o)) {
|
|
1017
|
+
const i = Object.getOwnPropertySymbols(o), r = i.find((c) => c.toString() == "Symbol(renderer)"), a = i.find((c) => c.toString() == "Symbol(scene)"), l = i.find((c) => c.toString() == "Symbol(needsRender)");
|
|
1018
|
+
!t && r != null && (t = n[r].threeRenderer), !e && a != null && (e = n[a]), !s && l != null && (s = n[l]);
|
|
1033
1019
|
}
|
|
1034
1020
|
if (t && e) {
|
|
1035
|
-
let
|
|
1021
|
+
let o = function() {
|
|
1036
1022
|
if (s) {
|
|
1037
|
-
let
|
|
1038
|
-
if (
|
|
1023
|
+
let r = 0, a = setInterval(() => {
|
|
1024
|
+
if (r++ > 5) {
|
|
1039
1025
|
clearInterval(a);
|
|
1040
1026
|
return;
|
|
1041
1027
|
}
|
|
1042
|
-
s == null || s.call(
|
|
1028
|
+
s == null || s.call(n);
|
|
1043
1029
|
}, 300);
|
|
1044
1030
|
}
|
|
1045
1031
|
};
|
|
1046
1032
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
1047
|
-
const
|
|
1048
|
-
return xe.addPlugin(new
|
|
1049
|
-
s == null || s.call(
|
|
1050
|
-
}),
|
|
1051
|
-
|
|
1052
|
-
}),
|
|
1053
|
-
|
|
1033
|
+
const i = xe.get(t, { engine: "model-viewer" });
|
|
1034
|
+
return xe.addPlugin(new Dt()), i.enable(), i.addEventListener("changed", () => {
|
|
1035
|
+
s == null || s.call(n);
|
|
1036
|
+
}), n.addEventListener("model-visibility", (r) => {
|
|
1037
|
+
r.detail.visible && (s == null || s.call(n));
|
|
1038
|
+
}), n.addEventListener("load", () => {
|
|
1039
|
+
o();
|
|
1054
1040
|
}), () => {
|
|
1055
|
-
|
|
1041
|
+
i.disable();
|
|
1056
1042
|
};
|
|
1057
1043
|
}
|
|
1058
1044
|
return null;
|
|
1059
1045
|
}
|
|
1060
|
-
class
|
|
1046
|
+
class Dt {
|
|
1061
1047
|
constructor() {
|
|
1062
1048
|
d(this, "_didWarnAboutMissingUrl", !1);
|
|
1063
1049
|
}
|
|
1064
|
-
onBeforeUpdateLOD(t, e, s,
|
|
1065
|
-
this.tryParseMeshLOD(e,
|
|
1050
|
+
onBeforeUpdateLOD(t, e, s, o) {
|
|
1051
|
+
this.tryParseMeshLOD(e, o), this.tryParseTextureLOD(e, o);
|
|
1066
1052
|
}
|
|
1067
1053
|
getUrl(t) {
|
|
1068
1054
|
if (!t)
|
|
@@ -1079,17 +1065,17 @@ class vt {
|
|
|
1079
1065
|
tryParseTextureLOD(t, e) {
|
|
1080
1066
|
if (e[ge] == !0) return;
|
|
1081
1067
|
e[ge] = !0;
|
|
1082
|
-
const s = this.tryGetCurrentGLTF(t),
|
|
1083
|
-
if (
|
|
1084
|
-
let
|
|
1068
|
+
const s = this.tryGetCurrentGLTF(t), o = this.tryGetCurrentModelViewer(t), i = this.getUrl(o);
|
|
1069
|
+
if (i && s && e.material) {
|
|
1070
|
+
let r = function(l) {
|
|
1085
1071
|
var u, h, g;
|
|
1086
1072
|
if (l[ge] == !0) return;
|
|
1087
1073
|
l[ge] = !0, l.userData && (l.userData.LOD = -1);
|
|
1088
1074
|
const c = Object.keys(l);
|
|
1089
|
-
for (let
|
|
1090
|
-
const b = c[
|
|
1091
|
-
if ((
|
|
1092
|
-
const F = (h = (u =
|
|
1075
|
+
for (let D = 0; D < c.length; D++) {
|
|
1076
|
+
const b = c[D], v = l[b];
|
|
1077
|
+
if ((v == null ? void 0 : v.isTexture) === !0) {
|
|
1078
|
+
const F = (h = (u = v.userData) == null ? void 0 : u.associations) == null ? void 0 : h.textures;
|
|
1093
1079
|
if (F == null) continue;
|
|
1094
1080
|
const W = s.parser.json.textures[F];
|
|
1095
1081
|
if (!W) {
|
|
@@ -1097,44 +1083,44 @@ class vt {
|
|
|
1097
1083
|
continue;
|
|
1098
1084
|
}
|
|
1099
1085
|
if ((g = W == null ? void 0 : W.extensions) != null && g[K]) {
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1086
|
+
const _ = W.extensions[K];
|
|
1087
|
+
_ && i && z.registerTexture(i, v, _.lods.length, F, _);
|
|
1102
1088
|
}
|
|
1103
1089
|
}
|
|
1104
1090
|
}
|
|
1105
1091
|
};
|
|
1106
1092
|
const a = e.material;
|
|
1107
|
-
if (Array.isArray(a)) for (const l of a)
|
|
1108
|
-
else
|
|
1093
|
+
if (Array.isArray(a)) for (const l of a) r(l);
|
|
1094
|
+
else r(a);
|
|
1109
1095
|
}
|
|
1110
1096
|
}
|
|
1111
1097
|
tryParseMeshLOD(t, e) {
|
|
1112
|
-
var
|
|
1098
|
+
var r, a;
|
|
1113
1099
|
if (e[Re] == !0) return;
|
|
1114
1100
|
e[Re] = !0;
|
|
1115
|
-
const s = this.tryGetCurrentModelViewer(t),
|
|
1116
|
-
if (!
|
|
1101
|
+
const s = this.tryGetCurrentModelViewer(t), o = this.getUrl(s);
|
|
1102
|
+
if (!o)
|
|
1117
1103
|
return;
|
|
1118
|
-
const
|
|
1119
|
-
if (
|
|
1104
|
+
const i = (a = (r = e.userData) == null ? void 0 : r.gltfExtensions) == null ? void 0 : a[K];
|
|
1105
|
+
if (i && o) {
|
|
1120
1106
|
const l = e.uuid;
|
|
1121
|
-
z.registerMesh(
|
|
1107
|
+
z.registerMesh(o, l, e, 0, i.lods.length, i);
|
|
1122
1108
|
}
|
|
1123
1109
|
}
|
|
1124
1110
|
}
|
|
1125
|
-
function
|
|
1111
|
+
function _t(n, t, e, s) {
|
|
1126
1112
|
Ne(t), ze(e), Ve(e, {
|
|
1127
1113
|
progressive: !0,
|
|
1128
1114
|
...s == null ? void 0 : s.hints
|
|
1129
|
-
}), e.register((
|
|
1130
|
-
const
|
|
1131
|
-
return (s == null ? void 0 : s.enableLODsManager) !== !1 &&
|
|
1115
|
+
}), e.register((i) => new z(i, n));
|
|
1116
|
+
const o = xe.get(t);
|
|
1117
|
+
return (s == null ? void 0 : s.enableLODsManager) !== !1 && o.enable(), o;
|
|
1132
1118
|
}
|
|
1133
1119
|
Xe();
|
|
1134
1120
|
if (!ht) {
|
|
1135
|
-
const
|
|
1121
|
+
const n = {
|
|
1136
1122
|
gltfProgressive: {
|
|
1137
|
-
useNeedleProgressive:
|
|
1123
|
+
useNeedleProgressive: _t,
|
|
1138
1124
|
LODsManager: xe,
|
|
1139
1125
|
configureLoader: Ve,
|
|
1140
1126
|
getRaycastMesh: ue,
|
|
@@ -1142,10 +1128,10 @@ if (!ht) {
|
|
|
1142
1128
|
}
|
|
1143
1129
|
};
|
|
1144
1130
|
if (!globalThis.Needle)
|
|
1145
|
-
globalThis.Needle =
|
|
1131
|
+
globalThis.Needle = n;
|
|
1146
1132
|
else
|
|
1147
|
-
for (const t in
|
|
1148
|
-
globalThis.Needle[t] =
|
|
1133
|
+
for (const t in n)
|
|
1134
|
+
globalThis.Needle[t] = n[t];
|
|
1149
1135
|
}
|
|
1150
1136
|
export {
|
|
1151
1137
|
xe as LODsManager,
|