@needle-tools/engine 4.7.2-next.6f2cd71 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/gltf-progressive-BCZdu3Gc.min.js +8 -0
- package/dist/gltf-progressive-C6QbvrB4.umd.cjs +8 -0
- package/dist/gltf-progressive-CCddD-3B.js +1159 -0
- package/dist/{needle-engine.bundle-B-NoV0t_.min.js → needle-engine.bundle-CnzaSk8v.min.js} +126 -125
- package/dist/{needle-engine.bundle-CFi0ugBx.js → needle-engine.bundle-DALjvqho.js} +3696 -3588
- package/dist/{needle-engine.bundle-BMnlxDfi.umd.cjs → needle-engine.bundle-RNpCdQTu.umd.cjs} +109 -108
- package/dist/needle-engine.d.ts +21 -0
- package/dist/needle-engine.js +3 -3
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-CjW23fio.umd.cjs → postprocessing-CNCT892s.umd.cjs} +1 -1
- package/dist/{postprocessing-xYQWCHFu.min.js → postprocessing-TkXiVrjY.min.js} +1 -1
- package/dist/{postprocessing-DYLNOL3W.js → postprocessing-qvgDnYKK.js} +1 -1
- package/dist/{three-examples-DaDLBuy6.min.js → three-examples-BMOhDaYR.min.js} +17 -17
- package/dist/{three-examples-X3OadjXB.umd.cjs → three-examples-DUcCNw9s.umd.cjs} +17 -17
- package/dist/{three-examples-B50TT3Iu.js → three-examples-tvuhV8Ne.js} +688 -688
- package/lib/engine/engine_context.js +1 -2
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_create_objects.js +24 -1
- package/lib/engine/engine_create_objects.js.map +1 -1
- package/lib/engine/engine_input.js +3 -0
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_lods.d.ts +1 -1
- package/lib/engine/engine_lods.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +13 -1
- package/lib/engine/engine_physics.js +15 -7
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_tonemapping.js +1 -0
- package/lib/engine/engine_tonemapping.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.d.ts +0 -1
- package/lib/engine/webcomponents/needle-engine.js +62 -3
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +45 -0
- package/lib/engine-components/OrbitControls.js +54 -9
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/Skybox.js +24 -5
- package/lib/engine-components/Skybox.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.js +9 -10
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/package.json +4 -4
- package/plugins/common/logger.js +34 -16
- package/plugins/vite/logger.client.js +55 -22
- package/src/engine/engine_context.ts +0 -2
- package/src/engine/engine_create_objects.ts +24 -1
- package/src/engine/engine_input.ts +8 -1
- package/src/engine/engine_lods.ts +1 -2
- package/src/engine/engine_physics.ts +26 -8
- package/src/engine/engine_tonemapping.ts +1 -0
- package/src/engine/webcomponents/needle-engine.ts +71 -5
- package/src/engine-components/OrbitControls.ts +78 -14
- package/src/engine-components/Skybox.ts +25 -7
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +1 -1
- package/src/engine-components/ui/EventSystem.ts +8 -9
- package/dist/gltf-progressive-B9o1T8Vr.umd.cjs +0 -8
- package/dist/gltf-progressive-DO0SisAM.js +0 -1052
- package/dist/gltf-progressive-DQF10PJE.min.js +0 -8
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
var He = Object.defineProperty;
|
|
2
|
+
var Ee = (o) => {
|
|
3
|
+
throw TypeError(o);
|
|
4
|
+
};
|
|
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
|
+
import { DRACOLoader as tt, KTX2Loader as st, MeshoptDecoder as rt, GLTFLoader as Ce } from "./three-examples-tvuhV8Ne.js";
|
|
10
|
+
const it = "";
|
|
11
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = it;
|
|
12
|
+
console.debug("[gltf-progressive] version -");
|
|
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 nt = V, ot = se, Fe = new URL(V + "draco_decoder.js");
|
|
15
|
+
Fe.searchParams.append("range", "true");
|
|
16
|
+
fetch(Fe, {
|
|
17
|
+
method: "GET",
|
|
18
|
+
headers: {
|
|
19
|
+
Range: "bytes=0-1"
|
|
20
|
+
}
|
|
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
|
+
}).finally(() => {
|
|
24
|
+
Ue();
|
|
25
|
+
});
|
|
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
|
+
}
|
|
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
|
+
}
|
|
32
|
+
const Pe = Symbol("dracoDecoderPath");
|
|
33
|
+
let G, Le, $;
|
|
34
|
+
function Ue() {
|
|
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
|
+
}
|
|
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
|
+
}
|
|
40
|
+
function ze(o) {
|
|
41
|
+
o.dracoLoader || o.setDRACOLoader(G), o.ktx2Loader || o.setKTX2Loader($), o.meshoptDecoder || o.setMeshoptDecoder(Le);
|
|
42
|
+
}
|
|
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
|
+
}
|
|
48
|
+
const Me = Ce.prototype.load;
|
|
49
|
+
function dt(...o) {
|
|
50
|
+
const t = Te.get(this);
|
|
51
|
+
let e = o[0];
|
|
52
|
+
const s = new URL(e, window.location.href);
|
|
53
|
+
if (s.hostname.endsWith("needle.tools")) {
|
|
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
|
+
}
|
|
57
|
+
return o[0] = e, Me == null ? void 0 : Me.call(this, ...o);
|
|
58
|
+
}
|
|
59
|
+
Ce.prototype.load = dt;
|
|
60
|
+
de("debugprogressive");
|
|
61
|
+
function de(o) {
|
|
62
|
+
if (typeof window > "u") return !1;
|
|
63
|
+
const e = new URL(window.location.href).searchParams.get(o);
|
|
64
|
+
return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
|
|
65
|
+
}
|
|
66
|
+
function ut(o, t) {
|
|
67
|
+
if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
|
|
68
|
+
return t;
|
|
69
|
+
const e = o.lastIndexOf("/");
|
|
70
|
+
if (e >= 0) {
|
|
71
|
+
const s = o.substring(0, e + 1);
|
|
72
|
+
for (; s.endsWith("/") && t.startsWith("/"); ) t = t.substring(1);
|
|
73
|
+
return s + t;
|
|
74
|
+
}
|
|
75
|
+
return t;
|
|
76
|
+
}
|
|
77
|
+
let oe;
|
|
78
|
+
function ct() {
|
|
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
|
+
}
|
|
81
|
+
function ft() {
|
|
82
|
+
if (typeof window > "u") return !1;
|
|
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
|
+
}
|
|
86
|
+
const ht = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
|
|
87
|
+
function ue(o) {
|
|
88
|
+
return (o == null ? void 0 : o[Ae]) instanceof ye ? o[Ae] : null;
|
|
89
|
+
}
|
|
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
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function pt(o = !0) {
|
|
97
|
+
if (o) {
|
|
98
|
+
if (ae) return;
|
|
99
|
+
const t = ae = te.prototype.raycast;
|
|
100
|
+
te.prototype.raycast = function(e, s) {
|
|
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
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
if (!ae) return;
|
|
107
|
+
te.prototype.raycast = ae, ae = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
let ae = null;
|
|
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
|
+
}
|
|
117
|
+
const Q = new Array(), y = de("debugprogressive");
|
|
118
|
+
let pe, ee = -1;
|
|
119
|
+
if (y) {
|
|
120
|
+
let o = function() {
|
|
121
|
+
ee += 1, ee >= t && (ee = -1), console.log(`Toggle LOD level [${ee}]`);
|
|
122
|
+
}, t = 6;
|
|
123
|
+
window.addEventListener("keyup", (e) => {
|
|
124
|
+
e.key === "p" && o(), e.key === "w" && (pe = !pe, console.log(`Toggle wireframe [${pe}]`));
|
|
125
|
+
const s = parseInt(e.key);
|
|
126
|
+
!isNaN(s) && s >= 0 && (ee = s, console.log(`Set LOD level to [${ee}]`));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function We(o) {
|
|
130
|
+
if (y)
|
|
131
|
+
if (Array.isArray(o))
|
|
132
|
+
for (const t of o)
|
|
133
|
+
We(t);
|
|
134
|
+
else o && "wireframe" in o && (o.wireframe = pe === !0);
|
|
135
|
+
}
|
|
136
|
+
const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = class w {
|
|
137
|
+
constructor(t, e) {
|
|
138
|
+
d(this, "parser");
|
|
139
|
+
d(this, "url");
|
|
140
|
+
d(this, "_isLoadingMesh");
|
|
141
|
+
d(this, "loadMesh", (t) => {
|
|
142
|
+
var s, n;
|
|
143
|
+
if (this._isLoadingMesh) return null;
|
|
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
|
+
})) : null;
|
|
149
|
+
});
|
|
150
|
+
y && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
|
|
151
|
+
}
|
|
152
|
+
/** The name of the extension */
|
|
153
|
+
get name() {
|
|
154
|
+
return K;
|
|
155
|
+
}
|
|
156
|
+
static getMeshLODExtension(t) {
|
|
157
|
+
const e = this.getAssignedLODInformation(t);
|
|
158
|
+
return e != null && e.key ? this.lodInfos.get(e.key) : null;
|
|
159
|
+
}
|
|
160
|
+
static getPrimitiveIndex(t) {
|
|
161
|
+
var s;
|
|
162
|
+
const e = (s = this.getAssignedLODInformation(t)) == null ? void 0 : s.index;
|
|
163
|
+
return e ?? -1;
|
|
164
|
+
}
|
|
165
|
+
static getMaterialMinMaxLODsCount(t, e) {
|
|
166
|
+
const s = this, n = "LODS:minmax", r = t[n];
|
|
167
|
+
if (r != null) return r;
|
|
168
|
+
if (e || (e = {
|
|
169
|
+
min_count: 1 / 0,
|
|
170
|
+
max_count: 0,
|
|
171
|
+
lods: []
|
|
172
|
+
}), Array.isArray(t)) {
|
|
173
|
+
for (const a of t)
|
|
174
|
+
this.getMaterialMinMaxLODsCount(a, e);
|
|
175
|
+
return t[n] = e, e;
|
|
176
|
+
}
|
|
177
|
+
if (y === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
|
|
178
|
+
const a = t;
|
|
179
|
+
for (const l of Object.keys(a.uniforms)) {
|
|
180
|
+
const c = a.uniforms[l].value;
|
|
181
|
+
(c == null ? void 0 : c.isTexture) === !0 && i(c, e);
|
|
182
|
+
}
|
|
183
|
+
} else if (t.isMaterial)
|
|
184
|
+
for (const a of Object.keys(t)) {
|
|
185
|
+
const l = t[a];
|
|
186
|
+
(l == null ? void 0 : l.isTexture) === !0 && i(l, e);
|
|
187
|
+
}
|
|
188
|
+
return t[n] = e, e;
|
|
189
|
+
function i(a, l) {
|
|
190
|
+
const c = s.getAssignedLODInformation(a);
|
|
191
|
+
if (c) {
|
|
192
|
+
const u = s.lodInfos.get(c.key);
|
|
193
|
+
if (u && u.lods) {
|
|
194
|
+
l.min_count = Math.min(l.min_count, u.lods.length), l.max_count = Math.max(l.max_count, u.lods.length);
|
|
195
|
+
for (let h = 0; h < u.lods.length; h++) {
|
|
196
|
+
const g = u.lods[h];
|
|
197
|
+
g.width && (l.lods[h] = l.lods[h] || { min_height: 1 / 0, max_height: 0 }, l.lods[h].min_height = Math.min(l.lods[h].min_height, g.height), l.lods[h].max_height = Math.max(l.lods[h].max_height, g.height));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/** Check if a LOD level is available for a mesh or a texture
|
|
204
|
+
* @param obj the mesh or texture to check
|
|
205
|
+
* @param level the level of detail to check for (0 is the highest resolution). If undefined, the function checks if any LOD level is available
|
|
206
|
+
* @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
|
|
207
|
+
*/
|
|
208
|
+
static hasLODLevelAvailable(t, e) {
|
|
209
|
+
var r;
|
|
210
|
+
if (Array.isArray(t)) {
|
|
211
|
+
for (const i of t)
|
|
212
|
+
if (this.hasLODLevelAvailable(i, e)) return !0;
|
|
213
|
+
return !1;
|
|
214
|
+
}
|
|
215
|
+
if (t.isMaterial === !0) {
|
|
216
|
+
for (const i of Object.keys(t)) {
|
|
217
|
+
const a = t[i];
|
|
218
|
+
if (a && a.isTexture && this.hasLODLevelAvailable(a, e))
|
|
219
|
+
return !0;
|
|
220
|
+
}
|
|
221
|
+
return !1;
|
|
222
|
+
} else if (t.isGroup === !0) {
|
|
223
|
+
for (const i of t.children)
|
|
224
|
+
if (i.isMesh === !0 && this.hasLODLevelAvailable(i, e))
|
|
225
|
+
return !0;
|
|
226
|
+
}
|
|
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
|
+
}
|
|
234
|
+
return !1;
|
|
235
|
+
}
|
|
236
|
+
/** Load a different resolution of a mesh (if available)
|
|
237
|
+
* @param context the context
|
|
238
|
+
* @param source the sourceid of the file from which the mesh is loaded (this is usually the component's sourceId)
|
|
239
|
+
* @param mesh the mesh to load the LOD for
|
|
240
|
+
* @param level the level of detail to load (0 is the highest resolution)
|
|
241
|
+
* @returns a promise that resolves to the mesh with the requested LOD level
|
|
242
|
+
* @example
|
|
243
|
+
* ```javascript
|
|
244
|
+
* const mesh = this.gameObject as Mesh;
|
|
245
|
+
* NEEDLE_progressive.assignMeshLOD(context, sourceId, mesh, 1).then(mesh => {
|
|
246
|
+
* console.log("Mesh with LOD level 1 loaded", mesh);
|
|
247
|
+
* });
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
static assignMeshLOD(t, e) {
|
|
251
|
+
var s;
|
|
252
|
+
if (!t) return Promise.resolve(null);
|
|
253
|
+
if (t instanceof te || t.isMesh === !0) {
|
|
254
|
+
const n = t.geometry, r = this.getAssignedLODInformation(n);
|
|
255
|
+
if (!r)
|
|
256
|
+
return Promise.resolve(null);
|
|
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
|
+
}
|
|
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
|
+
return Promise.resolve(null);
|
|
268
|
+
}
|
|
269
|
+
static assignTextureLOD(t, e = 0) {
|
|
270
|
+
if (!t) return Promise.resolve(null);
|
|
271
|
+
if (t.isMesh === !0) {
|
|
272
|
+
const s = t;
|
|
273
|
+
if (Array.isArray(s.material)) {
|
|
274
|
+
const n = new Array();
|
|
275
|
+
for (const r of s.material) {
|
|
276
|
+
const i = this.assignTextureLOD(r, e);
|
|
277
|
+
n.push(i);
|
|
278
|
+
}
|
|
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
|
+
});
|
|
285
|
+
} else
|
|
286
|
+
return this.assignTextureLOD(s.material, e);
|
|
287
|
+
}
|
|
288
|
+
if (t.isMaterial === !0) {
|
|
289
|
+
const s = t, n = [], r = new Array();
|
|
290
|
+
if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
|
|
291
|
+
const i = s;
|
|
292
|
+
for (const a of Object.keys(i.uniforms)) {
|
|
293
|
+
const l = i.uniforms[a].value;
|
|
294
|
+
if ((l == null ? void 0 : l.isTexture) === !0) {
|
|
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
|
+
}
|
|
298
|
+
}
|
|
299
|
+
} else
|
|
300
|
+
for (const i of Object.keys(s)) {
|
|
301
|
+
const a = s[i];
|
|
302
|
+
if ((a == null ? void 0 : a.isTexture) === !0) {
|
|
303
|
+
const l = this.assignTextureLODForSlot(a, e, s, i);
|
|
304
|
+
n.push(l), r.push(i);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return Promise.all(n).then((i) => {
|
|
308
|
+
const a = new Array();
|
|
309
|
+
for (let l = 0; l < i.length; l++) {
|
|
310
|
+
const c = i[l], u = r[l];
|
|
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
|
+
}
|
|
313
|
+
return a;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
if (t instanceof ne || t.isTexture === !0) {
|
|
317
|
+
const s = t;
|
|
318
|
+
return this.assignTextureLODForSlot(s, e, null, null);
|
|
319
|
+
}
|
|
320
|
+
return Promise.resolve(null);
|
|
321
|
+
}
|
|
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
|
+
if (a && (a == null ? void 0 : a.level) < e)
|
|
331
|
+
return y === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
|
|
332
|
+
}
|
|
333
|
+
s[n] = r;
|
|
334
|
+
}
|
|
335
|
+
return r;
|
|
336
|
+
} else y == "verbose" && console.warn("No LOD found for", t, e);
|
|
337
|
+
return null;
|
|
338
|
+
}).catch((r) => (console.error("Error loading LOD", t, r), null));
|
|
339
|
+
}
|
|
340
|
+
afterRoot(t) {
|
|
341
|
+
var e, s;
|
|
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
|
+
if (a) {
|
|
347
|
+
if (!a.lods) {
|
|
348
|
+
y && console.warn("Texture has no LODs", a);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
let l = !1;
|
|
352
|
+
for (const c of this.parser.associations.keys())
|
|
353
|
+
if (c.isTexture === !0) {
|
|
354
|
+
const u = this.parser.associations.get(c);
|
|
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
|
+
}
|
|
357
|
+
l || this.parser.getDependency("texture", r).then((c) => {
|
|
358
|
+
var u;
|
|
359
|
+
c && w.registerTexture(this.url, c, (u = a.lods) == null ? void 0 : u.length, r, a);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
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
|
+
for (const a of this.parser.associations.keys())
|
|
368
|
+
if (a.isMesh) {
|
|
369
|
+
const l = this.parser.associations.get(a);
|
|
370
|
+
(l == null ? void 0 : l.meshes) === r && w.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}), null;
|
|
375
|
+
}
|
|
376
|
+
static async getOrLoadLOD(t, e) {
|
|
377
|
+
var a, l, c, u;
|
|
378
|
+
const s = y == "verbose", n = t.userData.LODS;
|
|
379
|
+
if (!n)
|
|
380
|
+
return null;
|
|
381
|
+
const r = n == null ? void 0 : n.key;
|
|
382
|
+
let i;
|
|
383
|
+
if (t.isTexture === !0) {
|
|
384
|
+
const h = t;
|
|
385
|
+
h.source && h.source[Oe] && (i = h.source[Oe]);
|
|
386
|
+
}
|
|
387
|
+
if (i || (i = w.lodInfos.get(r)), i) {
|
|
388
|
+
if (e > 0) {
|
|
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
|
+
}
|
|
394
|
+
const h = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
|
|
395
|
+
if (!h)
|
|
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
|
+
if (g.endsWith(".glb") || g.endsWith(".gltf")) {
|
|
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
|
+
if (b !== void 0) {
|
|
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
|
+
}
|
|
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
|
+
let X = g;
|
|
413
|
+
if (_ && Array.isArray(_.lods)) {
|
|
414
|
+
const S = _.lods[e];
|
|
415
|
+
S.hash && (X += "?v=" + S.hash);
|
|
416
|
+
}
|
|
417
|
+
const T = await m.loadAsync(X).catch((S) => (console.error(`Error loading LOD ${e} from ${g}
|
|
418
|
+
`, S), null));
|
|
419
|
+
if (!T) return null;
|
|
420
|
+
const I = T.parser;
|
|
421
|
+
s && console.log("Loading finished " + g, _.guid);
|
|
422
|
+
let B = 0;
|
|
423
|
+
if (T.parser.json.textures) {
|
|
424
|
+
let S = !1;
|
|
425
|
+
for (const f of T.parser.json.textures) {
|
|
426
|
+
if (f != null && f.extensions) {
|
|
427
|
+
const P = f == null ? void 0 : f.extensions[K];
|
|
428
|
+
if (P != null && P.guid && P.guid === _.guid) {
|
|
429
|
+
S = !0;
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
B++;
|
|
434
|
+
}
|
|
435
|
+
if (S) {
|
|
436
|
+
let f = await I.getDependency("texture", B);
|
|
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
|
+
}
|
|
440
|
+
if (B = 0, T.parser.json.meshes) {
|
|
441
|
+
let S = !1;
|
|
442
|
+
for (const f of T.parser.json.meshes) {
|
|
443
|
+
if (f != null && f.extensions) {
|
|
444
|
+
const P = f == null ? void 0 : f.extensions[K];
|
|
445
|
+
if (P != null && P.guid && P.guid === _.guid) {
|
|
446
|
+
S = !0;
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
B++;
|
|
451
|
+
}
|
|
452
|
+
if (S) {
|
|
453
|
+
const f = await I.getDependency("mesh", B);
|
|
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
|
+
} else {
|
|
458
|
+
const P = new Array();
|
|
459
|
+
for (let x = 0; x < f.children.length; x++) {
|
|
460
|
+
const M = f.children[x];
|
|
461
|
+
if (M.isMesh === !0) {
|
|
462
|
+
const A = M.geometry;
|
|
463
|
+
w.assignLODInformation(n.url, A, r, e, x), P.push(A);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return D(P);
|
|
467
|
+
}
|
|
468
|
+
} else y && console.warn("Could not find mesh with guid", _.guid, T.parser.json);
|
|
469
|
+
}
|
|
470
|
+
return D(null);
|
|
471
|
+
});
|
|
472
|
+
return this.previouslyLoaded.set(v, F), await F;
|
|
473
|
+
} else if (t instanceof ne) {
|
|
474
|
+
s && console.log("Load texture from uri: " + g);
|
|
475
|
+
const b = await new Je().loadAsync(g);
|
|
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
|
+
}
|
|
478
|
+
} else
|
|
479
|
+
y && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type);
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
static assignLODInformation(t, e, s, n, r) {
|
|
483
|
+
if (!e) return;
|
|
484
|
+
e.userData || (e.userData = {});
|
|
485
|
+
const i = new yt(t, s, n, r);
|
|
486
|
+
e.userData.LODS = i;
|
|
487
|
+
}
|
|
488
|
+
static getAssignedLODInformation(t) {
|
|
489
|
+
var e;
|
|
490
|
+
return ((e = t == null ? void 0 : t.userData) == null ? void 0 : e.LODS) || null;
|
|
491
|
+
}
|
|
492
|
+
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
493
|
+
static copySettings(t, e) {
|
|
494
|
+
return e ? (y && console.warn(`Copy texture settings
|
|
495
|
+
`, t.uuid, `
|
|
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
|
+
}
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Register a texture with LOD information
|
|
501
|
+
*/
|
|
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
|
+
return;
|
|
506
|
+
}
|
|
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
|
+
}), /**
|
|
511
|
+
* Register a mesh with LOD information
|
|
512
|
+
*/
|
|
513
|
+
d(w, "registerMesh", (t, e, s, n, r, i) => {
|
|
514
|
+
var c;
|
|
515
|
+
const a = s.geometry;
|
|
516
|
+
if (!a) {
|
|
517
|
+
y && console.warn("gltf-progressive: Register mesh without geometry");
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
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
|
+
for (const u of Q)
|
|
524
|
+
(c = u.onRegisteredNewMesh) == null || c.call(u, s, i);
|
|
525
|
+
}), /** A map of key = asset uuid and value = LOD information */
|
|
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
|
+
d(this, "url");
|
|
533
|
+
/** the key to lookup the LOD information */
|
|
534
|
+
d(this, "key");
|
|
535
|
+
d(this, "level");
|
|
536
|
+
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
537
|
+
d(this, "index");
|
|
538
|
+
this.url = t, this.key = e, this.level = s, n != null && (this.index = n);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
class me {
|
|
542
|
+
constructor(t, e) {
|
|
543
|
+
d(this, "frame_start");
|
|
544
|
+
d(this, "frame_capture_end");
|
|
545
|
+
d(this, "ready");
|
|
546
|
+
d(this, "_resolve");
|
|
547
|
+
d(this, "_signal");
|
|
548
|
+
d(this, "_resolved", !1);
|
|
549
|
+
d(this, "_addedCount", 0);
|
|
550
|
+
d(this, "_resolvedCount", 0);
|
|
551
|
+
/** These promises are currently being awaited */
|
|
552
|
+
d(this, "_awaiting", []);
|
|
553
|
+
d(this, "_maxPromisesPerObject", 1);
|
|
554
|
+
d(this, "_currentFrame", 0);
|
|
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;
|
|
560
|
+
}), this.ready.finally(() => {
|
|
561
|
+
this._resolved = !0, this._awaiting.length = 0;
|
|
562
|
+
}), this._signal = e.signal, (r = this._signal) == null || r.addEventListener("abort", () => {
|
|
563
|
+
this.resolveNow();
|
|
564
|
+
}), this._maxPromisesPerObject = Math.max(1, e.maxPromisesPerObject ?? 1);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* The number of promises that have been added to this group so far.
|
|
568
|
+
*/
|
|
569
|
+
get awaitedCount() {
|
|
570
|
+
return this._addedCount;
|
|
571
|
+
}
|
|
572
|
+
get resolvedCount() {
|
|
573
|
+
return this._resolvedCount;
|
|
574
|
+
}
|
|
575
|
+
get currentlyAwaiting() {
|
|
576
|
+
return this._awaiting.length;
|
|
577
|
+
}
|
|
578
|
+
update(t) {
|
|
579
|
+
var e;
|
|
580
|
+
this._currentFrame = t, ((e = this._signal) != null && e.aborted || this._currentFrame > this.frame_capture_end && this._awaiting.length === 0) && this.resolveNow();
|
|
581
|
+
}
|
|
582
|
+
add(t, e, s) {
|
|
583
|
+
if (this._resolved) {
|
|
584
|
+
y && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
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
|
+
}
|
|
602
|
+
}
|
|
603
|
+
resolveNow() {
|
|
604
|
+
var t, e;
|
|
605
|
+
this._resolved || (e = this._resolve) == null || e.call(this, {
|
|
606
|
+
awaited_count: this._addedCount,
|
|
607
|
+
resolved_count: this._resolvedCount,
|
|
608
|
+
cancelled: ((t = this._signal) == null ? void 0 : t.aborted) ?? !1
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
d(me, "addPromise", (t, e, s, n) => {
|
|
613
|
+
n.forEach((r) => {
|
|
614
|
+
r.add(t, e, s);
|
|
615
|
+
});
|
|
616
|
+
});
|
|
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 };
|
|
618
|
+
var L, E, Y, we, Z, re, _e, H;
|
|
619
|
+
let xe = (L = class {
|
|
620
|
+
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
621
|
+
constructor(t, e) {
|
|
622
|
+
d(this, "renderer");
|
|
623
|
+
d(this, "context");
|
|
624
|
+
d(this, "projectionScreenMatrix", new Be());
|
|
625
|
+
/**
|
|
626
|
+
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
627
|
+
* @default 200_000
|
|
628
|
+
*/
|
|
629
|
+
d(this, "targetTriangleDensity", 2e5);
|
|
630
|
+
/**
|
|
631
|
+
* The interval in frames to automatically update the bounds of skinned meshes.
|
|
632
|
+
* Set to 0 or a negative value to disable automatic bounds updates.
|
|
633
|
+
* @default 30
|
|
634
|
+
*/
|
|
635
|
+
d(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
|
|
636
|
+
/**
|
|
637
|
+
* The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 2, the LODs will be updated every second frame, etc.
|
|
638
|
+
* @default "auto"
|
|
639
|
+
*/
|
|
640
|
+
d(this, "updateInterval", "auto");
|
|
641
|
+
j(this, E, 1);
|
|
642
|
+
/**
|
|
643
|
+
* If set to true, the LODsManager will not update the LODs.
|
|
644
|
+
* @default false
|
|
645
|
+
*/
|
|
646
|
+
d(this, "pause", !1);
|
|
647
|
+
/**
|
|
648
|
+
* When set to true the LODsManager will not update the LODs. This can be used to manually update the LODs using the `update` method.
|
|
649
|
+
* Otherwise the LODs will be updated automatically when the renderer renders the scene.
|
|
650
|
+
* @default false
|
|
651
|
+
*/
|
|
652
|
+
d(this, "manual", !1);
|
|
653
|
+
d(this, "_newPromiseGroups", []);
|
|
654
|
+
d(this, "_promiseGroupIds", 0);
|
|
655
|
+
d(this, "_lodchangedlisteners", []);
|
|
656
|
+
j(this, Y);
|
|
657
|
+
j(this, we, new Qe());
|
|
658
|
+
j(this, Z, 0);
|
|
659
|
+
j(this, re, 0);
|
|
660
|
+
j(this, _e, 0);
|
|
661
|
+
j(this, H, 0);
|
|
662
|
+
d(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
|
|
663
|
+
// private testIfLODLevelsAreAvailable() {
|
|
664
|
+
d(this, "_sphere", new et());
|
|
665
|
+
d(this, "_tempBox", new Ie());
|
|
666
|
+
d(this, "_tempBox2", new Ie());
|
|
667
|
+
d(this, "tempMatrix", new Be());
|
|
668
|
+
d(this, "_tempWorldPosition", new q());
|
|
669
|
+
d(this, "_tempBoxSize", new q());
|
|
670
|
+
d(this, "_tempBox2Size", new q());
|
|
671
|
+
this.renderer = t, this.context = { ...e };
|
|
672
|
+
}
|
|
673
|
+
/** @internal */
|
|
674
|
+
static getObjectLODState(t) {
|
|
675
|
+
return t[Se];
|
|
676
|
+
}
|
|
677
|
+
static addPlugin(t) {
|
|
678
|
+
Q.push(t);
|
|
679
|
+
}
|
|
680
|
+
static removePlugin(t) {
|
|
681
|
+
const e = Q.indexOf(t);
|
|
682
|
+
e >= 0 && Q.splice(e, 1);
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
686
|
+
* @param renderer The renderer to get the LODsManager for.
|
|
687
|
+
* @returns The LODsManager instance.
|
|
688
|
+
*/
|
|
689
|
+
static get(t, e) {
|
|
690
|
+
if (t[be])
|
|
691
|
+
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[be];
|
|
692
|
+
const s = new L(t, {
|
|
693
|
+
engine: "unknown",
|
|
694
|
+
...e
|
|
695
|
+
});
|
|
696
|
+
return t[be] = s, s;
|
|
697
|
+
}
|
|
698
|
+
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
699
|
+
get plugins() {
|
|
700
|
+
return Q;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Call to await LODs loading during the next render cycle.
|
|
704
|
+
*/
|
|
705
|
+
awaitLoading(t) {
|
|
706
|
+
const e = this._promiseGroupIds++, s = new me(p(this, Z), { ...t });
|
|
707
|
+
this._newPromiseGroups.push(s);
|
|
708
|
+
const n = performance.now();
|
|
709
|
+
return s.ready.finally(() => {
|
|
710
|
+
const r = this._newPromiseGroups.indexOf(s);
|
|
711
|
+
r >= 0 && (this._newPromiseGroups.splice(r, 1), ft() && performance.measure("LODsManager:awaitLoading", {
|
|
712
|
+
start: n,
|
|
713
|
+
detail: { id: e, name: t == null ? void 0 : t.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
|
|
714
|
+
}));
|
|
715
|
+
}), s.ready;
|
|
716
|
+
}
|
|
717
|
+
_postprocessPromiseGroups() {
|
|
718
|
+
if (this._newPromiseGroups.length !== 0)
|
|
719
|
+
for (let t = this._newPromiseGroups.length - 1; t >= 0; t--)
|
|
720
|
+
this._newPromiseGroups[t].update(p(this, Z));
|
|
721
|
+
}
|
|
722
|
+
addEventListener(t, e) {
|
|
723
|
+
t === "changed" && this._lodchangedlisteners.push(e);
|
|
724
|
+
}
|
|
725
|
+
removeEventListener(t, e) {
|
|
726
|
+
if (t === "changed") {
|
|
727
|
+
const s = this._lodchangedlisteners.indexOf(e);
|
|
728
|
+
s >= 0 && this._lodchangedlisteners.splice(s, 1);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
733
|
+
*/
|
|
734
|
+
enable() {
|
|
735
|
+
if (p(this, Y)) return;
|
|
736
|
+
console.debug("[gltf-progressive] Enabling LODsManager for renderer");
|
|
737
|
+
let t = 0;
|
|
738
|
+
N(this, Y, this.renderer.render);
|
|
739
|
+
const e = this;
|
|
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);
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
disable() {
|
|
748
|
+
p(this, Y) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = p(this, Y), N(this, Y, void 0));
|
|
749
|
+
}
|
|
750
|
+
update(t, e) {
|
|
751
|
+
this.internalUpdate(t, e);
|
|
752
|
+
}
|
|
753
|
+
onAfterRender(t, e, s) {
|
|
754
|
+
if (this.pause) return;
|
|
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);
|
|
760
|
+
}
|
|
761
|
+
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
|
|
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))
|
|
763
|
+
return;
|
|
764
|
+
this.internalUpdate(t, e), this._postprocessPromiseGroups();
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Update LODs in a scene
|
|
769
|
+
*/
|
|
770
|
+
internalUpdate(t, e) {
|
|
771
|
+
var l, c;
|
|
772
|
+
const s = this.renderer.renderLists.get(t, 0), n = s.opaque;
|
|
773
|
+
this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
|
|
774
|
+
const r = this.targetTriangleDensity;
|
|
775
|
+
for (const u of n) {
|
|
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")) {
|
|
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)));
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
switch (u.material.type) {
|
|
781
|
+
case "LineBasicMaterial":
|
|
782
|
+
case "LineDashedMaterial":
|
|
783
|
+
case "PointsMaterial":
|
|
784
|
+
case "ShadowMaterial":
|
|
785
|
+
case "MeshDistanceMaterial":
|
|
786
|
+
case "MeshDepthMaterial":
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
if (k === "color" && u.material && !u.object.progressive_debug_color) {
|
|
790
|
+
u.object.progressive_debug_color = !0;
|
|
791
|
+
const g = Math.random() * 16777215, v = new Ze({ color: g });
|
|
792
|
+
u.object.material = v;
|
|
793
|
+
}
|
|
794
|
+
const h = u.object;
|
|
795
|
+
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
|
|
796
|
+
}
|
|
797
|
+
const i = s.transparent;
|
|
798
|
+
for (const u of i) {
|
|
799
|
+
const h = u.object;
|
|
800
|
+
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
|
|
801
|
+
}
|
|
802
|
+
const a = s.transmissive;
|
|
803
|
+
for (const u of a) {
|
|
804
|
+
const h = u.object;
|
|
805
|
+
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
/** Update the LOD levels for the renderer. */
|
|
809
|
+
updateLODs(t, e, s, n) {
|
|
810
|
+
var a, l;
|
|
811
|
+
s.userData || (s.userData = {});
|
|
812
|
+
let r = s[Se];
|
|
813
|
+
if (r || (r = new xt(), s[Se] = r), r.frames++ < 2)
|
|
814
|
+
return;
|
|
815
|
+
for (const c of Q)
|
|
816
|
+
(a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, t, e, s);
|
|
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);
|
|
819
|
+
for (const c of Q)
|
|
820
|
+
(l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, C);
|
|
821
|
+
r.lastLodLevel_Mesh = C.mesh_lod, r.lastLodLevel_Texture = C.texture_lod;
|
|
822
|
+
}
|
|
823
|
+
/** Load progressive textures for the given material
|
|
824
|
+
* @param material the material to load the textures for
|
|
825
|
+
* @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
|
|
826
|
+
* @returns Promise with true if the LOD was loaded, false if not
|
|
827
|
+
*/
|
|
828
|
+
loadProgressiveTextures(t, e) {
|
|
829
|
+
if (!t) return;
|
|
830
|
+
if (Array.isArray(t)) {
|
|
831
|
+
for (const r of t)
|
|
832
|
+
this.loadProgressiveTextures(r, e);
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
let s = !1;
|
|
836
|
+
(t[J] === void 0 || e < t[J]) && (s = !0);
|
|
837
|
+
const n = t["DEBUG:LOD"];
|
|
838
|
+
if (n != null && (s = t[J] != n, e = n), s) {
|
|
839
|
+
t[J] = e;
|
|
840
|
+
const r = z.assignTextureLOD(t, e).then((i) => {
|
|
841
|
+
this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
|
|
842
|
+
});
|
|
843
|
+
me.addPromise("texture", t, r, this._newPromiseGroups);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
/** Load progressive meshes for the given mesh
|
|
847
|
+
* @param mesh the mesh to load the LOD for
|
|
848
|
+
* @param index the index of the mesh if it's part of a group
|
|
849
|
+
* @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
|
|
850
|
+
* @returns Promise with true if the LOD was loaded, false if not
|
|
851
|
+
*/
|
|
852
|
+
loadProgressiveMeshes(t, e) {
|
|
853
|
+
if (!t) return Promise.resolve(null);
|
|
854
|
+
let s = t[J] !== e;
|
|
855
|
+
const n = t["DEBUG:LOD"];
|
|
856
|
+
if (n != null && (s = t[J] != n, e = n), s) {
|
|
857
|
+
t[J] = e;
|
|
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;
|
|
860
|
+
}
|
|
861
|
+
return Promise.resolve(null);
|
|
862
|
+
}
|
|
863
|
+
static isInside(t, e) {
|
|
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;
|
|
866
|
+
}
|
|
867
|
+
calculateLodLevel(t, e, s, n, r) {
|
|
868
|
+
var F, W, D;
|
|
869
|
+
if (!e) {
|
|
870
|
+
r.mesh_lod = -1, r.texture_lod = -1;
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
if (!t) {
|
|
874
|
+
r.mesh_lod = -1, r.texture_lod = -1;
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
let a = 10 + 1, l = !1;
|
|
878
|
+
if (k && e["DEBUG:LOD"] != null)
|
|
879
|
+
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), 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;
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
h || (l = !0, a = 0);
|
|
886
|
+
const b = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
887
|
+
let _ = e.geometry.boundingBox;
|
|
888
|
+
if (e.type === "SkinnedMesh") {
|
|
889
|
+
const O = e;
|
|
890
|
+
if (!O.boundingBox)
|
|
891
|
+
O.computeBoundingBox();
|
|
892
|
+
else if (this.skinnedMeshAutoUpdateBoundsInterval > 0 && s.frames % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
|
|
893
|
+
const m = ue(O), X = O.geometry;
|
|
894
|
+
m && (O.geometry = m), O.computeBoundingBox(), O.geometry = X;
|
|
895
|
+
}
|
|
896
|
+
_ = O.boundingBox;
|
|
897
|
+
}
|
|
898
|
+
if (_) {
|
|
899
|
+
const O = t;
|
|
900
|
+
if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
|
|
901
|
+
this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
|
|
902
|
+
const x = t.getWorldPosition(this._tempWorldPosition);
|
|
903
|
+
if (this._sphere.containsPoint(x)) {
|
|
904
|
+
r.mesh_lod = 0, r.texture_lod = 0;
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
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;
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && O.isPerspectiveCamera && O.fov > 70) {
|
|
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;
|
|
916
|
+
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(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);
|
|
919
|
+
} else
|
|
920
|
+
s.lastCentrality = 1;
|
|
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;
|
|
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);
|
|
931
|
+
const ie = (M.z + U.z) * 0.5;
|
|
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);
|
|
933
|
+
}
|
|
934
|
+
let f = 999;
|
|
935
|
+
if (c && s.lastScreenCoverage > 0)
|
|
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;
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
f < a && (a = f, l = !0);
|
|
944
|
+
}
|
|
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}`);
|
|
948
|
+
}
|
|
949
|
+
if (v) {
|
|
950
|
+
const O = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
951
|
+
if (s.lastLodLevel_Texture < 0) {
|
|
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}`);
|
|
955
|
+
}
|
|
956
|
+
} else {
|
|
957
|
+
const m = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
958
|
+
let X = s.lastScreenCoverage * 4;
|
|
959
|
+
((D = this.context) == null ? void 0 : D.engine) === "model-viewer" && (X *= 1.5);
|
|
960
|
+
const I = b / window.devicePixelRatio * X;
|
|
961
|
+
let B = !1;
|
|
962
|
+
for (let S = g.lods.length - 1; S >= 0; S--) {
|
|
963
|
+
const f = g.lods[S];
|
|
964
|
+
if (!(O && f.max_height >= 2048) && !(ct() && f.max_height > 4096) && (f.max_height > I || !B && S === 0)) {
|
|
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)}
|
|
969
|
+
${e.name}`);
|
|
970
|
+
}
|
|
971
|
+
break;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
} else
|
|
976
|
+
r.texture_lod = 0;
|
|
977
|
+
}
|
|
978
|
+
}, E = new WeakMap(), Y = new WeakMap(), we = new WeakMap(), Z = new WeakMap(), re = new WeakMap(), _e = new WeakMap(), H = new WeakMap(), /**
|
|
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.
|
|
980
|
+
*/
|
|
981
|
+
d(L, "debugDrawLine"), /**
|
|
982
|
+
* Force override the LOD level for all objects in the scene
|
|
983
|
+
*/
|
|
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);
|
|
985
|
+
class xt {
|
|
986
|
+
constructor() {
|
|
987
|
+
d(this, "frames", 0);
|
|
988
|
+
d(this, "lastLodLevel_Mesh", -1);
|
|
989
|
+
d(this, "lastLodLevel_Texture", -1);
|
|
990
|
+
d(this, "lastScreenCoverage", 0);
|
|
991
|
+
d(this, "lastScreenspaceVolume", new q());
|
|
992
|
+
d(this, "lastCentrality", 0);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
const Re = Symbol("NEEDLE_mesh_lod"), ge = Symbol("NEEDLE_texture_lod");
|
|
996
|
+
let le = null;
|
|
997
|
+
function Xe() {
|
|
998
|
+
const o = wt();
|
|
999
|
+
o && (o.mapURLs(function(t) {
|
|
1000
|
+
return ke(), t;
|
|
1001
|
+
}), ke(), le == null || le.disconnect(), le = new MutationObserver((t) => {
|
|
1002
|
+
t.forEach((e) => {
|
|
1003
|
+
e.addedNodes.forEach((s) => {
|
|
1004
|
+
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && qe(s);
|
|
1005
|
+
});
|
|
1006
|
+
});
|
|
1007
|
+
}), le.observe(document, { childList: !0, subtree: !0 }));
|
|
1008
|
+
}
|
|
1009
|
+
function wt() {
|
|
1010
|
+
if (typeof customElements > "u") return null;
|
|
1011
|
+
const o = customElements.get("model-viewer");
|
|
1012
|
+
return o || (customElements.whenDefined("model-viewer").then(() => {
|
|
1013
|
+
console.debug("[gltf-progressive] model-viewer defined"), Xe();
|
|
1014
|
+
}), null);
|
|
1015
|
+
}
|
|
1016
|
+
function ke() {
|
|
1017
|
+
if (typeof document > "u") return;
|
|
1018
|
+
document.querySelectorAll("model-viewer").forEach((t) => {
|
|
1019
|
+
qe(t);
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
const $e = /* @__PURE__ */ new WeakSet();
|
|
1023
|
+
let _t = 0;
|
|
1024
|
+
function qe(o) {
|
|
1025
|
+
if (!o || $e.has(o))
|
|
1026
|
+
return null;
|
|
1027
|
+
$e.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++_t + `
|
|
1028
|
+
`, o.getAttribute("src"));
|
|
1029
|
+
let t = null, e = null, s = null;
|
|
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]);
|
|
1033
|
+
}
|
|
1034
|
+
if (t && e) {
|
|
1035
|
+
let n = function() {
|
|
1036
|
+
if (s) {
|
|
1037
|
+
let i = 0, a = setInterval(() => {
|
|
1038
|
+
if (i++ > 5) {
|
|
1039
|
+
clearInterval(a);
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
s == null || s.call(o);
|
|
1043
|
+
}, 300);
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
console.debug("[gltf-progressive] setup model-viewer");
|
|
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();
|
|
1054
|
+
}), () => {
|
|
1055
|
+
r.disable();
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
class vt {
|
|
1061
|
+
constructor() {
|
|
1062
|
+
d(this, "_didWarnAboutMissingUrl", !1);
|
|
1063
|
+
}
|
|
1064
|
+
onBeforeUpdateLOD(t, e, s, n) {
|
|
1065
|
+
this.tryParseMeshLOD(e, n), this.tryParseTextureLOD(e, n);
|
|
1066
|
+
}
|
|
1067
|
+
getUrl(t) {
|
|
1068
|
+
if (!t)
|
|
1069
|
+
return null;
|
|
1070
|
+
let e = t.getAttribute("src");
|
|
1071
|
+
return e || (e = t.src), e || (this._didWarnAboutMissingUrl || console.warn("No url found in modelviewer", t), this._didWarnAboutMissingUrl = !0), e;
|
|
1072
|
+
}
|
|
1073
|
+
tryGetCurrentGLTF(t) {
|
|
1074
|
+
return t._currentGLTF;
|
|
1075
|
+
}
|
|
1076
|
+
tryGetCurrentModelViewer(t) {
|
|
1077
|
+
return t.element;
|
|
1078
|
+
}
|
|
1079
|
+
tryParseTextureLOD(t, e) {
|
|
1080
|
+
if (e[ge] == !0) return;
|
|
1081
|
+
e[ge] = !0;
|
|
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) {
|
|
1085
|
+
var u, h, g;
|
|
1086
|
+
if (l[ge] == !0) return;
|
|
1087
|
+
l[ge] = !0, l.userData && (l.userData.LOD = -1);
|
|
1088
|
+
const c = Object.keys(l);
|
|
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;
|
|
1093
|
+
if (F == null) continue;
|
|
1094
|
+
const W = s.parser.json.textures[F];
|
|
1095
|
+
if (!W) {
|
|
1096
|
+
console.warn("Texture data not found for texture index " + F);
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
if ((g = W == null ? void 0 : W.extensions) != null && g[K]) {
|
|
1100
|
+
const D = W.extensions[K];
|
|
1101
|
+
D && r && z.registerTexture(r, _, D.lods.length, F, D);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1106
|
+
const a = e.material;
|
|
1107
|
+
if (Array.isArray(a)) for (const l of a) i(l);
|
|
1108
|
+
else i(a);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
tryParseMeshLOD(t, e) {
|
|
1112
|
+
var i, a;
|
|
1113
|
+
if (e[Re] == !0) return;
|
|
1114
|
+
e[Re] = !0;
|
|
1115
|
+
const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
|
|
1116
|
+
if (!n)
|
|
1117
|
+
return;
|
|
1118
|
+
const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[K];
|
|
1119
|
+
if (r && n) {
|
|
1120
|
+
const l = e.uuid;
|
|
1121
|
+
z.registerMesh(n, l, e, 0, r.lods.length, r);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
function Dt(o, t, e, s) {
|
|
1126
|
+
Ne(t), ze(e), Ve(e, {
|
|
1127
|
+
progressive: !0,
|
|
1128
|
+
...s == null ? void 0 : s.hints
|
|
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;
|
|
1132
|
+
}
|
|
1133
|
+
Xe();
|
|
1134
|
+
if (!ht) {
|
|
1135
|
+
const o = {
|
|
1136
|
+
gltfProgressive: {
|
|
1137
|
+
useNeedleProgressive: Dt,
|
|
1138
|
+
LODsManager: xe,
|
|
1139
|
+
configureLoader: Ve,
|
|
1140
|
+
getRaycastMesh: ue,
|
|
1141
|
+
useRaycastMeshes: pt
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
if (!globalThis.Needle)
|
|
1145
|
+
globalThis.Needle = o;
|
|
1146
|
+
else
|
|
1147
|
+
for (const t in o)
|
|
1148
|
+
globalThis.Needle[t] = o[t];
|
|
1149
|
+
}
|
|
1150
|
+
export {
|
|
1151
|
+
xe as LODsManager,
|
|
1152
|
+
z as NEEDLE_progressive,
|
|
1153
|
+
ze as addDracoAndKTX2Loaders,
|
|
1154
|
+
Ve as configureLoader,
|
|
1155
|
+
Ne as createLoaders,
|
|
1156
|
+
ue as getRaycastMesh,
|
|
1157
|
+
at as setDracoDecoderLocation,
|
|
1158
|
+
lt as setKTX2TranscoderLocation
|
|
1159
|
+
};
|