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