@needle-tools/engine 4.7.3-next.65e7878 → 4.7.3-next.ec2c716
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/{gltf-progressive-CCddD-3B.js → gltf-progressive-Bgh1c4Fd.js} +430 -365
- package/dist/gltf-progressive-D6f5talj.min.js +8 -0
- package/dist/gltf-progressive-otA_hxSA.umd.cjs +8 -0
- package/dist/{needle-engine.bundle-C6yScKUU.umd.cjs → needle-engine.bundle-CSWNTmt9.umd.cjs} +8 -8
- package/dist/{needle-engine.bundle-BCAZfCyl.min.js → needle-engine.bundle-Uxct1AXJ.min.js} +7 -7
- package/dist/{needle-engine.bundle-B0QYYufM.js → needle-engine.bundle-jF8XuQ81.js} +37 -11
- 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-TkXiVrjY.min.js → postprocessing-BzY0H7ry.min.js} +8 -8
- package/dist/{postprocessing-CNCT892s.umd.cjs → postprocessing-Dw2OCMp4.umd.cjs} +8 -8
- package/dist/{postprocessing-qvgDnYKK.js → postprocessing-vKBVFpSz.js} +9 -9
- package/lib/engine/engine_lods.js +1 -1
- package/lib/engine/engine_lods.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +19 -1
- package/lib/engine-components/OrbitControls.js +30 -1
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/postprocessing/Volume.d.ts +3 -1
- package/lib/engine-components/postprocessing/Volume.js +2 -0
- package/lib/engine-components/postprocessing/Volume.js.map +1 -1
- package/package.json +2 -2
- package/plugins/vite/logger.client.js +68 -30
- package/plugins/vite/logger.js +5 -5
- package/src/engine/engine_lods.ts +3 -3
- package/src/engine-components/OrbitControls.ts +34 -2
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -1
- package/src/engine-components/postprocessing/Volume.ts +2 -1
- package/dist/gltf-progressive-BCZdu3Gc.min.js +0 -8
- package/dist/gltf-progressive-C6QbvrB4.umd.cjs +0 -8
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Qe = Object.defineProperty;
|
|
2
2
|
var Ee = (o) => {
|
|
3
3
|
throw TypeError(o);
|
|
4
4
|
};
|
|
5
|
-
var je = (o, t, e) => t in o ?
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
import { BufferGeometry as ye, Mesh as te, Texture as ne, TextureLoader as Je, Matrix4 as
|
|
9
|
-
import { DRACOLoader as
|
|
10
|
-
const
|
|
11
|
-
globalThis.GLTF_PROGRESSIVE_VERSION =
|
|
5
|
+
var je = (o, t, e) => t in o ? Qe(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
6
|
+
var u = (o, t, e) => je(o, typeof t != "symbol" ? t + "" : t, e), $e = (o, t, e) => t.has(o) || Ee("Cannot " + e);
|
|
7
|
+
var x = (o, t, e) => ($e(o, t, "read from private field"), e ? e.call(o) : t.get(o)), Y = (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), U = (o, t, e, s) => ($e(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 Ie, Clock as Ze, MeshStandardMaterial as et, Sphere as tt, Box3 as Ge, Vector3 as V } from "./three-DrqIzZTH.js";
|
|
9
|
+
import { DRACOLoader as st, KTX2Loader as rt, MeshoptDecoder as it, GLTFLoader as Ce } from "./three-examples-tvuhV8Ne.js";
|
|
10
|
+
const nt = "";
|
|
11
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = nt;
|
|
12
12
|
console.debug("[gltf-progressive] version -");
|
|
13
|
-
let
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
fetch(
|
|
13
|
+
let q = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", se = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
14
|
+
const ot = q, at = se, Ne = new URL(q + "draco_decoder.js");
|
|
15
|
+
Ne.searchParams.append("range", "true");
|
|
16
|
+
fetch(Ne, {
|
|
17
17
|
method: "GET",
|
|
18
18
|
headers: {
|
|
19
19
|
Range: "bytes=0-1"
|
|
20
20
|
}
|
|
21
21
|
}).catch((o) => {
|
|
22
|
-
console.debug(`Failed to fetch remote Draco decoder from ${
|
|
22
|
+
console.debug(`Failed to fetch remote Draco decoder from ${q} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), q === ot && lt("./include/draco/"), se === at && ut("./include/ktx2/");
|
|
23
23
|
}).finally(() => {
|
|
24
24
|
Ue();
|
|
25
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
26
|
function lt(o) {
|
|
30
|
-
|
|
27
|
+
q = o, G && G[Pe] != q ? (console.debug("Updating Draco decoder path to " + o), G[Pe] = q, G.setDecoderPath(q), G.preload()) : console.debug("Setting Draco decoder path to " + o);
|
|
28
|
+
}
|
|
29
|
+
function ut(o) {
|
|
30
|
+
se = o, R && R.transcoderPath != se ? (console.debug("Updating KTX2 transcoder path to " + o), R.setTranscoderPath(se), R.init()) : console.debug("Setting KTX2 transcoder path to " + o);
|
|
31
31
|
}
|
|
32
32
|
const Pe = Symbol("dracoDecoderPath");
|
|
33
|
-
let G, Le,
|
|
33
|
+
let G, Le, R;
|
|
34
34
|
function Ue() {
|
|
35
|
-
G || (G = new
|
|
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 };
|
|
35
|
+
G || (G = new st(), G[Pe] = q, G.setDecoderPath(q), G.setDecoderConfig({ type: "js" }), G.preload()), R || (R = new rt(), R.setTranscoderPath(se), R.init()), Le || (Le = it);
|
|
39
36
|
}
|
|
40
37
|
function ze(o) {
|
|
41
|
-
o
|
|
38
|
+
return Ue(), o ? R.detectSupport(o) : o !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: G, ktx2Loader: R, meshoptDecoder: Le };
|
|
39
|
+
}
|
|
40
|
+
function qe(o) {
|
|
41
|
+
o.dracoLoader || o.setDRACOLoader(G), o.ktx2Loader || o.setKTX2Loader(R), o.meshoptDecoder || o.setMeshoptDecoder(Le);
|
|
42
42
|
}
|
|
43
43
|
const Te = /* @__PURE__ */ new WeakMap();
|
|
44
44
|
function Ve(o, t) {
|
|
45
45
|
let e = Te.get(o);
|
|
46
46
|
e ? e = Object.assign(e, t) : e = t, Te.set(o, e);
|
|
47
47
|
}
|
|
48
|
-
const
|
|
48
|
+
const ve = Ce.prototype.load;
|
|
49
49
|
function dt(...o) {
|
|
50
50
|
const t = Te.get(this);
|
|
51
51
|
let e = o[0];
|
|
@@ -54,16 +54,16 @@ function dt(...o) {
|
|
|
54
54
|
const r = (t == null ? void 0 : t.progressive) !== void 0 ? t.progressive : !0, i = t != null && t.usecase ? t.usecase : "default";
|
|
55
55
|
r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${i}` : this.requestHeader.Accept = `*/*;usecase=${i}`, e = s.toString();
|
|
56
56
|
}
|
|
57
|
-
return o[0] = e,
|
|
57
|
+
return o[0] = e, ve == null ? void 0 : ve.call(this, ...o);
|
|
58
58
|
}
|
|
59
59
|
Ce.prototype.load = dt;
|
|
60
|
-
|
|
61
|
-
function
|
|
60
|
+
ue("debugprogressive");
|
|
61
|
+
function ue(o) {
|
|
62
62
|
if (typeof window > "u") return !1;
|
|
63
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
|
|
66
|
+
function ct(o, t) {
|
|
67
67
|
if (t === void 0 || t.startsWith("./") || t.startsWith("http") || o === void 0)
|
|
68
68
|
return t;
|
|
69
69
|
const e = o.lastIndexOf("/");
|
|
@@ -75,30 +75,64 @@ function ut(o, t) {
|
|
|
75
75
|
return t;
|
|
76
76
|
}
|
|
77
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
78
|
function ft() {
|
|
79
|
+
return oe !== void 0 || (oe = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), ue("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", oe)), oe;
|
|
80
|
+
}
|
|
81
|
+
function Be() {
|
|
82
82
|
if (typeof window > "u") return !1;
|
|
83
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
84
|
return o.hostname === "127.0.0.1" || t;
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
class ht {
|
|
87
|
+
constructor(t = 100, e = {}) {
|
|
88
|
+
u(this, "_running", /* @__PURE__ */ new Map());
|
|
89
|
+
u(this, "_queue", []);
|
|
90
|
+
u(this, "debug", !1);
|
|
91
|
+
u(this, "tick", () => {
|
|
92
|
+
this.internalUpdate(), setTimeout(this.tick, 10);
|
|
93
|
+
});
|
|
94
|
+
this.maxConcurrent = t, this.debug = e.debug ?? !1, window.requestAnimationFrame(this.tick);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Request a slot for a promise with a specific key. This function returns a promise with a `use` method that can be called to add the promise to the queue.
|
|
98
|
+
*/
|
|
99
|
+
slot(t) {
|
|
100
|
+
return this.debug && console.debug(`[PromiseQueue]: Requesting slot for key ${t}, running: ${this._running.size}, waiting: ${this._queue.length}`), new Promise((e) => {
|
|
101
|
+
this._queue.push({ key: t, resolve: e });
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
add(t, e) {
|
|
105
|
+
this._running.has(t) || (this._running.set(t, e), e.finally(() => {
|
|
106
|
+
this._running.delete(t), this.debug && console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${t})`);
|
|
107
|
+
}), this.debug && console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${t})`));
|
|
108
|
+
}
|
|
109
|
+
internalUpdate() {
|
|
110
|
+
const t = this.maxConcurrent - this._running.size;
|
|
111
|
+
for (let e = 0; e < t && this._queue.length > 0; e++) {
|
|
112
|
+
this.debug && console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);
|
|
113
|
+
const { key: s, resolve: n } = this._queue.shift();
|
|
114
|
+
n({
|
|
115
|
+
use: (r) => this.add(s, r)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const gt = typeof window > "u" && typeof document > "u", Ae = Symbol("needle:raycast-mesh");
|
|
121
|
+
function de(o) {
|
|
88
122
|
return (o == null ? void 0 : o[Ae]) instanceof ye ? o[Ae] : null;
|
|
89
123
|
}
|
|
90
|
-
function
|
|
91
|
-
if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !
|
|
92
|
-
const s =
|
|
124
|
+
function pt(o, t) {
|
|
125
|
+
if ((o.type === "Mesh" || o.type === "SkinnedMesh") && !de(o)) {
|
|
126
|
+
const s = yt(t);
|
|
93
127
|
s.userData = { isRaycastMesh: !0 }, o[Ae] = s;
|
|
94
128
|
}
|
|
95
129
|
}
|
|
96
|
-
function
|
|
130
|
+
function mt(o = !0) {
|
|
97
131
|
if (o) {
|
|
98
132
|
if (ae) return;
|
|
99
133
|
const t = ae = te.prototype.raycast;
|
|
100
134
|
te.prototype.raycast = function(e, s) {
|
|
101
|
-
const n = this, r =
|
|
135
|
+
const n = this, r = de(n);
|
|
102
136
|
let i;
|
|
103
137
|
r && n.isMesh && (i = n.geometry, n.geometry = r), t.call(this, e, s), i && (n.geometry = i);
|
|
104
138
|
};
|
|
@@ -108,15 +142,15 @@ function pt(o = !0) {
|
|
|
108
142
|
}
|
|
109
143
|
}
|
|
110
144
|
let ae = null;
|
|
111
|
-
function
|
|
145
|
+
function yt(o) {
|
|
112
146
|
const t = new ye();
|
|
113
147
|
for (const e in o.attributes)
|
|
114
148
|
t.setAttribute(e, o.getAttribute(e));
|
|
115
149
|
return t.setIndex(o.getIndex()), t;
|
|
116
150
|
}
|
|
117
|
-
const Q = new Array(),
|
|
151
|
+
const Q = new Array(), L = ue("debugprogressive");
|
|
118
152
|
let pe, ee = -1;
|
|
119
|
-
if (
|
|
153
|
+
if (L) {
|
|
120
154
|
let o = function() {
|
|
121
155
|
ee += 1, ee >= t && (ee = -1), console.log(`Toggle LOD level [${ee}]`);
|
|
122
156
|
}, t = 6;
|
|
@@ -127,31 +161,31 @@ if (y) {
|
|
|
127
161
|
});
|
|
128
162
|
}
|
|
129
163
|
function We(o) {
|
|
130
|
-
if (
|
|
164
|
+
if (L)
|
|
131
165
|
if (Array.isArray(o))
|
|
132
166
|
for (const t of o)
|
|
133
167
|
We(t);
|
|
134
168
|
else o && "wireframe" in o && (o.wireframe = pe === !0);
|
|
135
169
|
}
|
|
136
|
-
const
|
|
170
|
+
const W = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), _ = class _ {
|
|
137
171
|
constructor(t, e) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
172
|
+
u(this, "parser");
|
|
173
|
+
u(this, "url");
|
|
174
|
+
u(this, "_isLoadingMesh");
|
|
175
|
+
u(this, "loadMesh", (t) => {
|
|
142
176
|
var s, n;
|
|
143
177
|
if (this._isLoadingMesh) return null;
|
|
144
|
-
const e = (n = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : n[
|
|
178
|
+
const e = (n = (s = this.parser.json.meshes[t]) == null ? void 0 : s.extensions) == null ? void 0 : n[W];
|
|
145
179
|
return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((r) => {
|
|
146
180
|
var i;
|
|
147
|
-
return this._isLoadingMesh = !1, r &&
|
|
181
|
+
return this._isLoadingMesh = !1, r && _.registerMesh(this.url, e.guid, r, (i = e.lods) == null ? void 0 : i.length, 0, e), r;
|
|
148
182
|
})) : null;
|
|
149
183
|
});
|
|
150
|
-
|
|
184
|
+
L && console.log("Progressive extension registered for", e), this.parser = t, this.url = e;
|
|
151
185
|
}
|
|
152
186
|
/** The name of the extension */
|
|
153
187
|
get name() {
|
|
154
|
-
return
|
|
188
|
+
return W;
|
|
155
189
|
}
|
|
156
190
|
static getMeshLODExtension(t) {
|
|
157
191
|
const e = this.getAssignedLODInformation(t);
|
|
@@ -174,7 +208,7 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
174
208
|
this.getMaterialMinMaxLODsCount(a, e);
|
|
175
209
|
return t[n] = e, e;
|
|
176
210
|
}
|
|
177
|
-
if (
|
|
211
|
+
if (L === "verbose" && console.log("getMaterialMinMaxLODsCount", t), t.type === "ShaderMaterial" || t.type === "RawShaderMaterial") {
|
|
178
212
|
const a = t;
|
|
179
213
|
for (const l of Object.keys(a.uniforms)) {
|
|
180
214
|
const c = a.uniforms[l].value;
|
|
@@ -189,12 +223,12 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
189
223
|
function i(a, l) {
|
|
190
224
|
const c = s.getAssignedLODInformation(a);
|
|
191
225
|
if (c) {
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
194
|
-
l.min_count = Math.min(l.min_count,
|
|
195
|
-
for (let h = 0; h <
|
|
196
|
-
const
|
|
197
|
-
|
|
226
|
+
const d = s.lodInfos.get(c.key);
|
|
227
|
+
if (d && d.lods) {
|
|
228
|
+
l.min_count = Math.min(l.min_count, d.lods.length), l.max_count = Math.max(l.max_count, d.lods.length);
|
|
229
|
+
for (let h = 0; h < d.lods.length; h++) {
|
|
230
|
+
const f = d.lods[h];
|
|
231
|
+
f.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, f.height), l.lods[h].max_height = Math.max(l.lods[h].max_height, f.height));
|
|
198
232
|
}
|
|
199
233
|
}
|
|
200
234
|
}
|
|
@@ -256,14 +290,14 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
256
290
|
return Promise.resolve(null);
|
|
257
291
|
for (const i of Q)
|
|
258
292
|
(s = i.onBeforeGetLODMesh) == null || s.call(i, t, e);
|
|
259
|
-
return t["LOD:requested level"] = e,
|
|
293
|
+
return t["LOD:requested level"] = e, _.getOrLoadLOD(n, e).then((i) => {
|
|
260
294
|
if (Array.isArray(i)) {
|
|
261
295
|
const a = r.index || 0;
|
|
262
296
|
i = i[a];
|
|
263
297
|
}
|
|
264
|
-
return t["LOD:requested level"] === e && (delete t["LOD:requested level"], i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? t.geometry = i :
|
|
298
|
+
return t["LOD:requested level"] === e && (delete t["LOD:requested level"], i && n != i && ((i == null ? void 0 : i.isBufferGeometry) ? t.geometry = i : L && console.error("Invalid LOD geometry", i))), i;
|
|
265
299
|
}).catch((i) => (console.error("Error loading mesh LOD", t, i), null));
|
|
266
|
-
} else
|
|
300
|
+
} else L && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", t);
|
|
267
301
|
return Promise.resolve(null);
|
|
268
302
|
}
|
|
269
303
|
static assignTextureLOD(t, e = 0) {
|
|
@@ -292,7 +326,7 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
292
326
|
for (const a of Object.keys(i.uniforms)) {
|
|
293
327
|
const l = i.uniforms[a].value;
|
|
294
328
|
if ((l == null ? void 0 : l.isTexture) === !0) {
|
|
295
|
-
const c = this.assignTextureLODForSlot(l, e, s, a).then((
|
|
329
|
+
const c = this.assignTextureLODForSlot(l, e, s, a).then((d) => (d && i.uniforms[a].value != d && (i.uniforms[a].value = d, i.uniformsNeedUpdate = !0), d));
|
|
296
330
|
n.push(c), r.push(a);
|
|
297
331
|
}
|
|
298
332
|
}
|
|
@@ -307,8 +341,8 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
307
341
|
return Promise.all(n).then((i) => {
|
|
308
342
|
const a = new Array();
|
|
309
343
|
for (let l = 0; l < i.length; l++) {
|
|
310
|
-
const c = i[l],
|
|
311
|
-
c && c.isTexture === !0 ? a.push({ material: s, slot:
|
|
344
|
+
const c = i[l], d = r[l];
|
|
345
|
+
c && c.isTexture === !0 ? a.push({ material: s, slot: d, texture: c, level: e }) : a.push({ material: s, slot: d, texture: null, level: e });
|
|
312
346
|
}
|
|
313
347
|
return a;
|
|
314
348
|
});
|
|
@@ -320,178 +354,197 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
320
354
|
return Promise.resolve(null);
|
|
321
355
|
}
|
|
322
356
|
static assignTextureLODForSlot(t, e, s, n) {
|
|
323
|
-
return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) :
|
|
324
|
-
if (Array.isArray(r))
|
|
357
|
+
return (t == null ? void 0 : t.isTexture) !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) : _.getOrLoadLOD(t, e).then((r) => {
|
|
358
|
+
if (Array.isArray(r))
|
|
359
|
+
return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen", r), null;
|
|
325
360
|
if ((r == null ? void 0 : r.isTexture) === !0) {
|
|
326
361
|
if (r != t && s && n) {
|
|
327
362
|
const i = s[n];
|
|
328
|
-
if (i && !
|
|
363
|
+
if (i && !L) {
|
|
329
364
|
const a = this.getAssignedLODInformation(i);
|
|
330
365
|
if (a && (a == null ? void 0 : a.level) < e)
|
|
331
|
-
return
|
|
366
|
+
return L === "verbose" && console.warn("Assigned texture level is already higher: ", a.level, e, s, i, r), null;
|
|
332
367
|
}
|
|
333
368
|
s[n] = r;
|
|
334
369
|
}
|
|
335
370
|
return r;
|
|
336
|
-
} else
|
|
371
|
+
} else L == "verbose" && console.warn("No LOD found for", t, e);
|
|
337
372
|
return null;
|
|
338
373
|
}).catch((r) => (console.error("Error loading LOD", t, r), null));
|
|
339
374
|
}
|
|
375
|
+
// private _isLoadingTexture;
|
|
376
|
+
// loadTexture = (textureIndex: number) => {
|
|
377
|
+
// if (this._isLoadingTexture) return null;
|
|
378
|
+
// const ext = this.parser.json.textures[textureIndex]?.extensions?.[EXTENSION_NAME] as NEEDLE_ext_progressive_texture;
|
|
379
|
+
// if (!ext) return null;
|
|
380
|
+
// this._isLoadingTexture = true;
|
|
381
|
+
// return this.parser.getDependency("texture", textureIndex).then(tex => {
|
|
382
|
+
// this._isLoadingTexture = false;
|
|
383
|
+
// if (tex) {
|
|
384
|
+
// NEEDLE_progressive.registerTexture(this.url, tex as Texture, ext.lods?.length, textureIndex, ext);
|
|
385
|
+
// }
|
|
386
|
+
// return tex;
|
|
387
|
+
// });
|
|
388
|
+
// }
|
|
340
389
|
afterRoot(t) {
|
|
341
390
|
var e, s;
|
|
342
|
-
return
|
|
391
|
+
return L && console.log("AFTER", this.url, t), (e = this.parser.json.textures) == null || e.forEach((n, r) => {
|
|
343
392
|
var i;
|
|
344
393
|
if (n != null && n.extensions) {
|
|
345
|
-
const a = n == null ? void 0 : n.extensions[
|
|
394
|
+
const a = n == null ? void 0 : n.extensions[W];
|
|
346
395
|
if (a) {
|
|
347
396
|
if (!a.lods) {
|
|
348
|
-
|
|
397
|
+
L && console.warn("Texture has no LODs", a);
|
|
349
398
|
return;
|
|
350
399
|
}
|
|
351
400
|
let l = !1;
|
|
352
401
|
for (const c of this.parser.associations.keys())
|
|
353
402
|
if (c.isTexture === !0) {
|
|
354
|
-
const
|
|
355
|
-
(
|
|
403
|
+
const d = this.parser.associations.get(c);
|
|
404
|
+
(d == null ? void 0 : d.textures) === r && (l = !0, _.registerTexture(this.url, c, (i = a.lods) == null ? void 0 : i.length, r, a));
|
|
356
405
|
}
|
|
357
406
|
l || this.parser.getDependency("texture", r).then((c) => {
|
|
358
|
-
var
|
|
359
|
-
c &&
|
|
407
|
+
var d;
|
|
408
|
+
c && _.registerTexture(this.url, c, (d = a.lods) == null ? void 0 : d.length, r, a);
|
|
360
409
|
});
|
|
361
410
|
}
|
|
362
411
|
}
|
|
363
412
|
}), (s = this.parser.json.meshes) == null || s.forEach((n, r) => {
|
|
364
413
|
if (n != null && n.extensions) {
|
|
365
|
-
const i = n == null ? void 0 : n.extensions[
|
|
414
|
+
const i = n == null ? void 0 : n.extensions[W];
|
|
366
415
|
if (i && i.lods) {
|
|
367
416
|
for (const a of this.parser.associations.keys())
|
|
368
417
|
if (a.isMesh) {
|
|
369
418
|
const l = this.parser.associations.get(a);
|
|
370
|
-
(l == null ? void 0 : l.meshes) === r &&
|
|
419
|
+
(l == null ? void 0 : l.meshes) === r && _.registerMesh(this.url, i.guid, a, i.lods.length, l.primitives, i);
|
|
371
420
|
}
|
|
372
421
|
}
|
|
373
422
|
}
|
|
374
423
|
}), null;
|
|
375
424
|
}
|
|
376
425
|
static async getOrLoadLOD(t, e) {
|
|
377
|
-
var a, l, c,
|
|
378
|
-
const s =
|
|
426
|
+
var a, l, c, d;
|
|
427
|
+
const s = L == "verbose", n = this.getAssignedLODInformation(t);
|
|
379
428
|
if (!n)
|
|
380
|
-
return null;
|
|
429
|
+
return L && console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`, t), null;
|
|
381
430
|
const r = n == null ? void 0 : n.key;
|
|
382
431
|
let i;
|
|
383
432
|
if (t.isTexture === !0) {
|
|
384
433
|
const h = t;
|
|
385
434
|
h.source && h.source[Oe] && (i = h.source[Oe]);
|
|
386
435
|
}
|
|
387
|
-
if (i || (i =
|
|
436
|
+
if (i || (i = _.lodInfos.get(r)), i) {
|
|
388
437
|
if (e > 0) {
|
|
389
|
-
let
|
|
390
|
-
const
|
|
391
|
-
if (
|
|
438
|
+
let D = !1;
|
|
439
|
+
const v = Array.isArray(i.lods);
|
|
440
|
+
if (v && e >= i.lods.length ? D = !0 : v || (D = !0), D)
|
|
392
441
|
return this.lowresCache.get(r);
|
|
393
442
|
}
|
|
394
443
|
const h = Array.isArray(i.lods) ? (a = i.lods[e]) == null ? void 0 : a.path : i.lods;
|
|
395
444
|
if (!h)
|
|
396
|
-
return
|
|
397
|
-
const
|
|
398
|
-
if (
|
|
445
|
+
return L && !i["missing:uri"] && (i["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, i)), null;
|
|
446
|
+
const f = ct(n.url, h);
|
|
447
|
+
if (f.endsWith(".glb") || f.endsWith(".gltf")) {
|
|
399
448
|
if (!i.guid)
|
|
400
449
|
return console.warn("missing pointer for glb/gltf texture", i), null;
|
|
401
|
-
const
|
|
402
|
-
if (
|
|
403
|
-
s && console.log(`LOD ${e} was already loading/loaded: ${
|
|
404
|
-
let
|
|
405
|
-
`,
|
|
406
|
-
if (
|
|
407
|
-
return
|
|
450
|
+
const D = f + "_" + i.guid, v = this.previouslyLoaded.get(D);
|
|
451
|
+
if (v !== void 0) {
|
|
452
|
+
s && console.log(`LOD ${e} was already loading/loaded: ${D}`);
|
|
453
|
+
let g = await v.catch((A) => (console.error(`Error loading LOD ${e} from ${f}
|
|
454
|
+
`, A), null)), w = !1;
|
|
455
|
+
if (g == null || (g instanceof ne && t instanceof ne ? (l = g.image) != null && l.data || (c = g.source) != null && c.data ? g = this.copySettings(t, g) : (w = !0, this.previouslyLoaded.delete(D)) : g instanceof ye && t instanceof ye && ((d = g.attributes.position) != null && d.array || (w = !0, this.previouslyLoaded.delete(D)))), !w)
|
|
456
|
+
return g;
|
|
408
457
|
}
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
458
|
+
const P = await this.queue.slot(f);
|
|
459
|
+
if (!P.use)
|
|
460
|
+
return L && console.log(`LOD ${e} was aborted: ${f}`), null;
|
|
461
|
+
const b = i, B = new Promise(async (g, w) => {
|
|
462
|
+
const A = new Ce();
|
|
463
|
+
qe(A), L && (await new Promise((O) => setTimeout(O, 1e3)), s && console.warn("Start loading (delayed) " + f, b.guid));
|
|
464
|
+
let F = f;
|
|
465
|
+
if (b && Array.isArray(b.lods)) {
|
|
466
|
+
const O = b.lods[e];
|
|
467
|
+
O.hash && (F += "?v=" + O.hash);
|
|
416
468
|
}
|
|
417
|
-
const
|
|
418
|
-
`,
|
|
419
|
-
if (!
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
469
|
+
const S = await A.loadAsync(F).catch((O) => (console.error(`Error loading LOD ${e} from ${f}
|
|
470
|
+
`, O), g(null)));
|
|
471
|
+
if (!S)
|
|
472
|
+
return g(null);
|
|
473
|
+
const Z = S.parser;
|
|
474
|
+
s && console.log("Loading finished " + f, b.guid);
|
|
475
|
+
let C = 0;
|
|
476
|
+
if (S.parser.json.textures) {
|
|
477
|
+
let O = !1;
|
|
478
|
+
for (const m of S.parser.json.textures) {
|
|
479
|
+
if (m != null && m.extensions) {
|
|
480
|
+
const p = m == null ? void 0 : m.extensions[W];
|
|
481
|
+
if (p != null && p.guid && p.guid === b.guid) {
|
|
482
|
+
O = !0;
|
|
430
483
|
break;
|
|
431
484
|
}
|
|
432
485
|
}
|
|
433
|
-
|
|
486
|
+
C++;
|
|
434
487
|
}
|
|
435
|
-
if (
|
|
436
|
-
let
|
|
437
|
-
return
|
|
438
|
-
} else
|
|
488
|
+
if (O) {
|
|
489
|
+
let m = await Z.getDependency("texture", C);
|
|
490
|
+
return m && _.assignLODInformation(n.url, m, r, e, void 0), s && console.log('change "' + t.name + '" → "' + m.name + '"', f, C, m, D), t instanceof ne && (m = this.copySettings(t, m)), m && (m.guid = b.guid), g(m);
|
|
491
|
+
} else L && console.warn("Could not find texture with guid", b.guid, S.parser.json);
|
|
439
492
|
}
|
|
440
|
-
if (
|
|
441
|
-
let
|
|
442
|
-
for (const
|
|
443
|
-
if (
|
|
444
|
-
const
|
|
445
|
-
if (
|
|
446
|
-
|
|
493
|
+
if (C = 0, S.parser.json.meshes) {
|
|
494
|
+
let O = !1;
|
|
495
|
+
for (const m of S.parser.json.meshes) {
|
|
496
|
+
if (m != null && m.extensions) {
|
|
497
|
+
const p = m == null ? void 0 : m.extensions[W];
|
|
498
|
+
if (p != null && p.guid && p.guid === b.guid) {
|
|
499
|
+
O = !0;
|
|
447
500
|
break;
|
|
448
501
|
}
|
|
449
502
|
}
|
|
450
|
-
|
|
503
|
+
C++;
|
|
451
504
|
}
|
|
452
|
-
if (
|
|
453
|
-
const
|
|
454
|
-
if (s && console.log(`Loaded Mesh "${
|
|
455
|
-
const
|
|
456
|
-
return
|
|
505
|
+
if (O) {
|
|
506
|
+
const m = await Z.getDependency("mesh", C);
|
|
507
|
+
if (s && console.log(`Loaded Mesh "${m.name}"`, f, C, m, D), m.isMesh === !0) {
|
|
508
|
+
const p = m.geometry;
|
|
509
|
+
return _.assignLODInformation(n.url, p, r, e, 0), g(p);
|
|
457
510
|
} else {
|
|
458
|
-
const
|
|
459
|
-
for (let
|
|
460
|
-
const
|
|
461
|
-
if (
|
|
462
|
-
const
|
|
463
|
-
|
|
511
|
+
const p = new Array();
|
|
512
|
+
for (let M = 0; M < m.children.length; M++) {
|
|
513
|
+
const E = m.children[M];
|
|
514
|
+
if (E.isMesh === !0) {
|
|
515
|
+
const T = E.geometry;
|
|
516
|
+
_.assignLODInformation(n.url, T, r, e, M), p.push(T);
|
|
464
517
|
}
|
|
465
518
|
}
|
|
466
|
-
return
|
|
519
|
+
return g(p);
|
|
467
520
|
}
|
|
468
|
-
} else
|
|
521
|
+
} else L && console.warn("Could not find mesh with guid", b.guid, S.parser.json);
|
|
469
522
|
}
|
|
470
|
-
return
|
|
523
|
+
return g(null);
|
|
471
524
|
});
|
|
472
|
-
return this.previouslyLoaded.set(
|
|
525
|
+
return this.previouslyLoaded.set(D, B), P.use(B), await B;
|
|
473
526
|
} else if (t instanceof ne) {
|
|
474
|
-
s && console.log("Load texture from uri: " +
|
|
475
|
-
const
|
|
476
|
-
return
|
|
527
|
+
s && console.log("Load texture from uri: " + f);
|
|
528
|
+
const v = await new Je().loadAsync(f);
|
|
529
|
+
return v ? (v.guid = i.guid, v.flipY = !1, v.needsUpdate = !0, v.colorSpace = t.colorSpace, s && console.log(i, v)) : L && console.warn("failed loading", f), v;
|
|
477
530
|
}
|
|
478
531
|
} else
|
|
479
|
-
|
|
532
|
+
L && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type);
|
|
480
533
|
return null;
|
|
481
534
|
}
|
|
482
535
|
static assignLODInformation(t, e, s, n, r) {
|
|
483
536
|
if (!e) return;
|
|
484
537
|
e.userData || (e.userData = {});
|
|
485
|
-
const i = new
|
|
486
|
-
e.userData.LODS = i;
|
|
538
|
+
const i = new Lt(t, s, n, r);
|
|
539
|
+
e.userData.LODS = i, "source" in e && typeof e.source == "object" && (e.source.LODS = i);
|
|
487
540
|
}
|
|
488
541
|
static getAssignedLODInformation(t) {
|
|
489
|
-
var e;
|
|
490
|
-
return (
|
|
542
|
+
var e, s;
|
|
543
|
+
return t ? (e = t.userData) != null && e.LODS ? t.userData.LODS : "source" in t && ((s = t.source) != null && s.LODS) ? t.source.LODS : null : null;
|
|
491
544
|
}
|
|
492
545
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
493
546
|
static copySettings(t, e) {
|
|
494
|
-
return e ? (
|
|
547
|
+
return e ? (L && console.warn(`Copy texture settings
|
|
495
548
|
`, t.uuid, `
|
|
496
549
|
`, 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
550
|
}
|
|
@@ -499,60 +552,65 @@ const K = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), w = c
|
|
|
499
552
|
/**
|
|
500
553
|
* Register a texture with LOD information
|
|
501
554
|
*/
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
555
|
+
u(_, "registerTexture", (t, e, s, n, r) => {
|
|
556
|
+
var a, l, c, d, h, f, D, v;
|
|
557
|
+
if (!e) {
|
|
558
|
+
L && console.error("gltf-progressive: Called register texture without texture");
|
|
505
559
|
return;
|
|
506
560
|
}
|
|
561
|
+
if (L) {
|
|
562
|
+
const P = ((a = e.image) == null ? void 0 : a.width) || ((c = (l = e.source) == null ? void 0 : l.data) == null ? void 0 : c.width) || 0, b = ((d = e.image) == null ? void 0 : d.height) || ((f = (h = e.source) == null ? void 0 : h.data) == null ? void 0 : f.height) || 0;
|
|
563
|
+
console.log(`> Progressive: register texture[${n}] "${e.name || e.uuid}", Current: ${P}x${b}, Max: ${(D = r.lods[0]) == null ? void 0 : D.width}x${(v = r.lods[0]) == null ? void 0 : v.height}, uuid: ${e.uuid}`, r, e);
|
|
564
|
+
}
|
|
507
565
|
e.source && (e.source[Oe] = r);
|
|
508
566
|
const i = r.guid;
|
|
509
|
-
|
|
567
|
+
_.assignLODInformation(t, e, i, s, n), _.lodInfos.set(i, r), _.lowresCache.set(i, e);
|
|
510
568
|
}), /**
|
|
511
569
|
* Register a mesh with LOD information
|
|
512
570
|
*/
|
|
513
|
-
|
|
571
|
+
u(_, "registerMesh", (t, e, s, n, r, i) => {
|
|
514
572
|
var c;
|
|
515
573
|
const a = s.geometry;
|
|
516
574
|
if (!a) {
|
|
517
|
-
|
|
575
|
+
L && console.warn("gltf-progressive: Register mesh without geometry");
|
|
518
576
|
return;
|
|
519
577
|
}
|
|
520
|
-
a.userData || (a.userData = {}),
|
|
521
|
-
let l =
|
|
522
|
-
l ? l.push(s.geometry) : l = [s.geometry],
|
|
523
|
-
for (const
|
|
524
|
-
(c =
|
|
578
|
+
a.userData || (a.userData = {}), L && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, i, s), _.assignLODInformation(t, a, e, n, r), _.lodInfos.set(e, i);
|
|
579
|
+
let l = _.lowresCache.get(e);
|
|
580
|
+
l ? l.push(s.geometry) : l = [s.geometry], _.lowresCache.set(e, l), n > 0 && !de(s) && pt(s, a);
|
|
581
|
+
for (const d of Q)
|
|
582
|
+
(c = d.onRegisteredNewMesh) == null || c.call(d, s, i);
|
|
525
583
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
let z =
|
|
530
|
-
class
|
|
584
|
+
u(_, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
585
|
+
u(_, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
586
|
+
u(_, "lowresCache", /* @__PURE__ */ new Map()), u(_, "queue", new ht(100, { debug: L != !1 }));
|
|
587
|
+
let z = _;
|
|
588
|
+
class Lt {
|
|
531
589
|
constructor(t, e, s, n) {
|
|
532
|
-
|
|
590
|
+
u(this, "url");
|
|
533
591
|
/** the key to lookup the LOD information */
|
|
534
|
-
|
|
535
|
-
|
|
592
|
+
u(this, "key");
|
|
593
|
+
u(this, "level");
|
|
536
594
|
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
537
|
-
|
|
595
|
+
u(this, "index");
|
|
538
596
|
this.url = t, this.key = e, this.level = s, n != null && (this.index = n);
|
|
539
597
|
}
|
|
540
598
|
}
|
|
541
599
|
class me {
|
|
542
600
|
constructor(t, e) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
601
|
+
u(this, "frame_start");
|
|
602
|
+
u(this, "frame_capture_end");
|
|
603
|
+
u(this, "ready");
|
|
604
|
+
u(this, "_resolve");
|
|
605
|
+
u(this, "_signal");
|
|
606
|
+
u(this, "_resolved", !1);
|
|
607
|
+
u(this, "_addedCount", 0);
|
|
608
|
+
u(this, "_resolvedCount", 0);
|
|
551
609
|
/** These promises are currently being awaited */
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
610
|
+
u(this, "_awaiting", []);
|
|
611
|
+
u(this, "_maxPromisesPerObject", 1);
|
|
612
|
+
u(this, "_currentFrame", 0);
|
|
613
|
+
u(this, "_seen", /* @__PURE__ */ new WeakMap());
|
|
556
614
|
var r;
|
|
557
615
|
const n = Math.max(e.frames ?? 2, 2);
|
|
558
616
|
this.frame_start = t, this.frame_capture_end = t + n, this.ready = new Promise((i) => {
|
|
@@ -581,7 +639,7 @@ class me {
|
|
|
581
639
|
}
|
|
582
640
|
add(t, e, s) {
|
|
583
641
|
if (this._resolved) {
|
|
584
|
-
|
|
642
|
+
L && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
|
|
585
643
|
return;
|
|
586
644
|
}
|
|
587
645
|
if (!(this._currentFrame > this.frame_capture_end)) {
|
|
@@ -589,7 +647,7 @@ class me {
|
|
|
589
647
|
if (this._seen.has(e)) {
|
|
590
648
|
let n = this._seen.get(e);
|
|
591
649
|
if (n >= this._maxPromisesPerObject) {
|
|
592
|
-
|
|
650
|
+
L && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
|
|
593
651
|
return;
|
|
594
652
|
}
|
|
595
653
|
this._seen.set(e, n + 1);
|
|
@@ -609,65 +667,65 @@ class me {
|
|
|
609
667
|
});
|
|
610
668
|
}
|
|
611
669
|
}
|
|
612
|
-
|
|
670
|
+
u(me, "addPromise", (t, e, s, n) => {
|
|
613
671
|
n.forEach((r) => {
|
|
614
672
|
r.add(t, e, s);
|
|
615
673
|
});
|
|
616
674
|
});
|
|
617
|
-
const k =
|
|
618
|
-
var
|
|
619
|
-
let xe = (
|
|
675
|
+
const k = ue("debugprogressive"), xt = ue("noprogressive"), be = Symbol("Needle:LODSManager"), Se = Symbol("Needle:LODState"), H = Symbol("Needle:CurrentLOD"), $ = { mesh_lod: -1, texture_lod: -1 };
|
|
676
|
+
var y, I, X, we, j, re, _e, K;
|
|
677
|
+
let xe = (y = class {
|
|
620
678
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
621
679
|
constructor(t, e) {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
680
|
+
u(this, "renderer");
|
|
681
|
+
u(this, "context");
|
|
682
|
+
u(this, "projectionScreenMatrix", new Ie());
|
|
625
683
|
/**
|
|
626
684
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
627
685
|
* @default 200_000
|
|
628
686
|
*/
|
|
629
|
-
|
|
687
|
+
u(this, "targetTriangleDensity", 2e5);
|
|
630
688
|
/**
|
|
631
689
|
* The interval in frames to automatically update the bounds of skinned meshes.
|
|
632
690
|
* Set to 0 or a negative value to disable automatic bounds updates.
|
|
633
691
|
* @default 30
|
|
634
692
|
*/
|
|
635
|
-
|
|
693
|
+
u(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
|
|
636
694
|
/**
|
|
637
695
|
* 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
696
|
* @default "auto"
|
|
639
697
|
*/
|
|
640
|
-
|
|
641
|
-
|
|
698
|
+
u(this, "updateInterval", "auto");
|
|
699
|
+
Y(this, I, 1);
|
|
642
700
|
/**
|
|
643
701
|
* If set to true, the LODsManager will not update the LODs.
|
|
644
702
|
* @default false
|
|
645
703
|
*/
|
|
646
|
-
|
|
704
|
+
u(this, "pause", !1);
|
|
647
705
|
/**
|
|
648
706
|
* 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
707
|
* Otherwise the LODs will be updated automatically when the renderer renders the scene.
|
|
650
708
|
* @default false
|
|
651
709
|
*/
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
710
|
+
u(this, "manual", !1);
|
|
711
|
+
u(this, "_newPromiseGroups", []);
|
|
712
|
+
u(this, "_promiseGroupIds", 0);
|
|
713
|
+
u(this, "_lodchangedlisteners", []);
|
|
714
|
+
Y(this, X);
|
|
715
|
+
Y(this, we, new Ze());
|
|
716
|
+
Y(this, j, 0);
|
|
717
|
+
Y(this, re, 0);
|
|
718
|
+
Y(this, _e, 0);
|
|
719
|
+
Y(this, K, 0);
|
|
720
|
+
u(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
|
|
663
721
|
// private testIfLODLevelsAreAvailable() {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
722
|
+
u(this, "_sphere", new tt());
|
|
723
|
+
u(this, "_tempBox", new Ge());
|
|
724
|
+
u(this, "_tempBox2", new Ge());
|
|
725
|
+
u(this, "tempMatrix", new Ie());
|
|
726
|
+
u(this, "_tempWorldPosition", new V());
|
|
727
|
+
u(this, "_tempBoxSize", new V());
|
|
728
|
+
u(this, "_tempBox2Size", new V());
|
|
671
729
|
this.renderer = t, this.context = { ...e };
|
|
672
730
|
}
|
|
673
731
|
/** @internal */
|
|
@@ -689,7 +747,7 @@ let xe = (L = class {
|
|
|
689
747
|
static get(t, e) {
|
|
690
748
|
if (t[be])
|
|
691
749
|
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[be];
|
|
692
|
-
const s = new
|
|
750
|
+
const s = new y(t, {
|
|
693
751
|
engine: "unknown",
|
|
694
752
|
...e
|
|
695
753
|
});
|
|
@@ -703,12 +761,12 @@ let xe = (L = class {
|
|
|
703
761
|
* Call to await LODs loading during the next render cycle.
|
|
704
762
|
*/
|
|
705
763
|
awaitLoading(t) {
|
|
706
|
-
const e = this._promiseGroupIds++, s = new me(
|
|
764
|
+
const e = this._promiseGroupIds++, s = new me(x(this, j), { ...t });
|
|
707
765
|
this._newPromiseGroups.push(s);
|
|
708
766
|
const n = performance.now();
|
|
709
767
|
return s.ready.finally(() => {
|
|
710
768
|
const r = this._newPromiseGroups.indexOf(s);
|
|
711
|
-
r >= 0 && (this._newPromiseGroups.splice(r, 1),
|
|
769
|
+
r >= 0 && (this._newPromiseGroups.splice(r, 1), Be() && performance.measure("LODsManager:awaitLoading", {
|
|
712
770
|
start: n,
|
|
713
771
|
detail: { id: e, name: t == null ? void 0 : t.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
|
|
714
772
|
}));
|
|
@@ -717,7 +775,7 @@ let xe = (L = class {
|
|
|
717
775
|
_postprocessPromiseGroups() {
|
|
718
776
|
if (this._newPromiseGroups.length !== 0)
|
|
719
777
|
for (let t = this._newPromiseGroups.length - 1; t >= 0; t--)
|
|
720
|
-
this._newPromiseGroups[t].update(
|
|
778
|
+
this._newPromiseGroups[t].update(x(this, j));
|
|
721
779
|
}
|
|
722
780
|
addEventListener(t, e) {
|
|
723
781
|
t === "changed" && this._lodchangedlisteners.push(e);
|
|
@@ -732,20 +790,20 @@ let xe = (L = class {
|
|
|
732
790
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
733
791
|
*/
|
|
734
792
|
enable() {
|
|
735
|
-
if (
|
|
793
|
+
if (x(this, X)) return;
|
|
736
794
|
console.debug("[gltf-progressive] Enabling LODsManager for renderer");
|
|
737
795
|
let t = 0;
|
|
738
|
-
|
|
796
|
+
U(this, X, this.renderer.render);
|
|
739
797
|
const e = this;
|
|
740
|
-
|
|
798
|
+
ze(this.renderer), this.renderer.render = function(s, n) {
|
|
741
799
|
const r = e.renderer.getRenderTarget();
|
|
742
|
-
(r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0,
|
|
800
|
+
(r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, U(e, j, x(e, j) + 1), U(e, re, x(e, we).getDelta()), U(e, _e, x(e, _e) + x(e, re)), e._fpsBuffer.shift(), e._fpsBuffer.push(1 / x(e, re)), U(e, K, e._fpsBuffer.reduce((a, l) => a + l) / e._fpsBuffer.length), k && x(e, j) % 200 === 0 && console.log("FPS", Math.round(x(e, K)), "Interval:", x(e, I)));
|
|
743
801
|
const i = t++;
|
|
744
|
-
|
|
802
|
+
x(e, X).call(this, s, n), e.onAfterRender(s, n, i);
|
|
745
803
|
};
|
|
746
804
|
}
|
|
747
805
|
disable() {
|
|
748
|
-
|
|
806
|
+
x(this, X) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = x(this, X), U(this, X, void 0));
|
|
749
807
|
}
|
|
750
808
|
update(t, e) {
|
|
751
809
|
this.internalUpdate(t, e);
|
|
@@ -759,7 +817,7 @@ let xe = (L = class {
|
|
|
759
817
|
(a.name === "EffectMaterial" || a.name === "CopyShader") && (i = !1);
|
|
760
818
|
}
|
|
761
819
|
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (i = !1), i) {
|
|
762
|
-
if (
|
|
820
|
+
if (xt || (this.updateInterval === "auto" ? x(this, K) < 40 && x(this, I) < 10 ? (U(this, I, x(this, I) + 1), k && console.warn("↓ Reducing LOD updates", x(this, I), x(this, K).toFixed(0))) : x(this, K) >= 60 && x(this, I) > 1 && (U(this, I, x(this, I) - 1), k && console.warn("↑ Increasing LOD updates", x(this, I), x(this, K).toFixed(0))) : U(this, I, this.updateInterval), x(this, I) > 0 && x(this, j) % x(this, I) != 0))
|
|
763
821
|
return;
|
|
764
822
|
this.internalUpdate(t, e), this._postprocessPromiseGroups();
|
|
765
823
|
}
|
|
@@ -772,12 +830,12 @@ let xe = (L = class {
|
|
|
772
830
|
const s = this.renderer.renderLists.get(t, 0), n = s.opaque;
|
|
773
831
|
this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix, e.matrixWorldInverse);
|
|
774
832
|
const r = this.targetTriangleDensity;
|
|
775
|
-
for (const
|
|
776
|
-
if (
|
|
777
|
-
k && (
|
|
833
|
+
for (const d of n) {
|
|
834
|
+
if (d.material && (((l = d.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((c = d.geometry) == null ? void 0 : c.type) === "BufferGeometry") && (d.material.name === "SphericalGaussianBlur" || d.material.name == "BackgroundCubeMaterial" || d.material.name === "CubemapFromEquirect" || d.material.name === "EquirectangularToCubeUV")) {
|
|
835
|
+
k && (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", d, d.material.name, d.material.type)));
|
|
778
836
|
continue;
|
|
779
837
|
}
|
|
780
|
-
switch (
|
|
838
|
+
switch (d.material.type) {
|
|
781
839
|
case "LineBasicMaterial":
|
|
782
840
|
case "LineDashedMaterial":
|
|
783
841
|
case "PointsMaterial":
|
|
@@ -786,22 +844,22 @@ let xe = (L = class {
|
|
|
786
844
|
case "MeshDepthMaterial":
|
|
787
845
|
continue;
|
|
788
846
|
}
|
|
789
|
-
if (k === "color" &&
|
|
790
|
-
|
|
791
|
-
const
|
|
792
|
-
|
|
847
|
+
if (k === "color" && d.material && !d.object.progressive_debug_color) {
|
|
848
|
+
d.object.progressive_debug_color = !0;
|
|
849
|
+
const f = Math.random() * 16777215, D = new et({ color: f });
|
|
850
|
+
d.object.material = D;
|
|
793
851
|
}
|
|
794
|
-
const h =
|
|
852
|
+
const h = d.object;
|
|
795
853
|
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
|
|
796
854
|
}
|
|
797
855
|
const i = s.transparent;
|
|
798
|
-
for (const
|
|
799
|
-
const h =
|
|
856
|
+
for (const d of i) {
|
|
857
|
+
const h = d.object;
|
|
800
858
|
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
|
|
801
859
|
}
|
|
802
860
|
const a = s.transmissive;
|
|
803
|
-
for (const
|
|
804
|
-
const h =
|
|
861
|
+
for (const d of a) {
|
|
862
|
+
const h = d.object;
|
|
805
863
|
(h instanceof te || h.isMesh) && this.updateLODs(t, e, h, r);
|
|
806
864
|
}
|
|
807
865
|
}
|
|
@@ -810,15 +868,15 @@ let xe = (L = class {
|
|
|
810
868
|
var a, l;
|
|
811
869
|
s.userData || (s.userData = {});
|
|
812
870
|
let r = s[Se];
|
|
813
|
-
if (r || (r = new
|
|
871
|
+
if (r || (r = new wt(), s[Se] = r), r.frames++ < 2)
|
|
814
872
|
return;
|
|
815
873
|
for (const c of Q)
|
|
816
874
|
(a = c.onBeforeUpdateLOD) == null || a.call(c, this.renderer, t, e, s);
|
|
817
|
-
const i =
|
|
818
|
-
i >= 0 ? (
|
|
875
|
+
const i = y.overrideGlobalLodLevel !== void 0 ? y.overrideGlobalLodLevel : ee;
|
|
876
|
+
i >= 0 ? ($.mesh_lod = i, $.texture_lod = i) : (this.calculateLodLevel(e, s, r, n, $), $.mesh_lod = Math.round($.mesh_lod), $.texture_lod = Math.round($.texture_lod)), $.mesh_lod >= 0 && this.loadProgressiveMeshes(s, $.mesh_lod), s.material && $.texture_lod >= 0 && this.loadProgressiveTextures(s.material, $.texture_lod), L && s.material && !s.isGizmo && We(s.material);
|
|
819
877
|
for (const c of Q)
|
|
820
|
-
(l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s,
|
|
821
|
-
r.lastLodLevel_Mesh =
|
|
878
|
+
(l = c.onAfterUpdatedLOD) == null || l.call(c, this.renderer, t, e, s, $);
|
|
879
|
+
r.lastLodLevel_Mesh = $.mesh_lod, r.lastLodLevel_Texture = $.texture_lod;
|
|
822
880
|
}
|
|
823
881
|
/** Load progressive textures for the given material
|
|
824
882
|
* @param material the material to load the textures for
|
|
@@ -833,10 +891,10 @@ let xe = (L = class {
|
|
|
833
891
|
return;
|
|
834
892
|
}
|
|
835
893
|
let s = !1;
|
|
836
|
-
(t[
|
|
894
|
+
(t[H] === void 0 || e < t[H]) && (s = !0);
|
|
837
895
|
const n = t["DEBUG:LOD"];
|
|
838
|
-
if (n != null && (s = t[
|
|
839
|
-
t[
|
|
896
|
+
if (n != null && (s = t[H] != n, e = n), s) {
|
|
897
|
+
t[H] = e;
|
|
840
898
|
const r = z.assignTextureLOD(t, e).then((i) => {
|
|
841
899
|
this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
|
|
842
900
|
});
|
|
@@ -851,11 +909,11 @@ let xe = (L = class {
|
|
|
851
909
|
*/
|
|
852
910
|
loadProgressiveMeshes(t, e) {
|
|
853
911
|
if (!t) return Promise.resolve(null);
|
|
854
|
-
let s = t[
|
|
912
|
+
let s = t[H] !== e;
|
|
855
913
|
const n = t["DEBUG:LOD"];
|
|
856
|
-
if (n != null && (s = t[
|
|
857
|
-
t[
|
|
858
|
-
const r = t.geometry, i = z.assignMeshLOD(t, e).then((a) => (a && t[
|
|
914
|
+
if (n != null && (s = t[H] != n, e = n), s) {
|
|
915
|
+
t[H] = e;
|
|
916
|
+
const r = t.geometry, i = z.assignMeshLOD(t, e).then((a) => (a && t[H] == e && r != t.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: e, object: t })), a));
|
|
859
917
|
return me.addPromise("mesh", t, i, this._newPromiseGroups), i;
|
|
860
918
|
}
|
|
861
919
|
return Promise.resolve(null);
|
|
@@ -865,7 +923,7 @@ let xe = (L = class {
|
|
|
865
923
|
return this._tempPtInside.set(r, i, s.z).applyMatrix4(e).z < 0;
|
|
866
924
|
}
|
|
867
925
|
calculateLodLevel(t, e, s, n, r) {
|
|
868
|
-
var
|
|
926
|
+
var b, B, J;
|
|
869
927
|
if (!e) {
|
|
870
928
|
r.mesh_lod = -1, r.texture_lod = -1;
|
|
871
929
|
return;
|
|
@@ -877,95 +935,102 @@ let xe = (L = class {
|
|
|
877
935
|
let a = 10 + 1, l = !1;
|
|
878
936
|
if (k && e["DEBUG:LOD"] != null)
|
|
879
937
|
return e["DEBUG:LOD"];
|
|
880
|
-
const c = (
|
|
881
|
-
if (!h && !
|
|
938
|
+
const c = (b = z.getMeshLODExtension(e.geometry)) == null ? void 0 : b.lods, d = z.getPrimitiveIndex(e.geometry), h = c && c.length > 0, f = z.getMaterialMinMaxLODsCount(e.material), D = (f == null ? void 0 : f.min_count) != 1 / 0 && f.min_count > 0 && f.max_count > 0;
|
|
939
|
+
if (!h && !D) {
|
|
882
940
|
r.mesh_lod = 0, r.texture_lod = 0;
|
|
883
941
|
return;
|
|
884
942
|
}
|
|
885
943
|
h || (l = !0, a = 0);
|
|
886
|
-
const
|
|
887
|
-
let
|
|
944
|
+
const v = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
945
|
+
let P = e.geometry.boundingBox;
|
|
888
946
|
if (e.type === "SkinnedMesh") {
|
|
889
|
-
const
|
|
890
|
-
if (!
|
|
891
|
-
|
|
892
|
-
else if (this.skinnedMeshAutoUpdateBoundsInterval > 0
|
|
893
|
-
|
|
894
|
-
|
|
947
|
+
const g = e;
|
|
948
|
+
if (!g.boundingBox)
|
|
949
|
+
g.computeBoundingBox();
|
|
950
|
+
else if (this.skinnedMeshAutoUpdateBoundsInterval > 0) {
|
|
951
|
+
if (!g[y.$skinnedMeshBoundsOffset]) {
|
|
952
|
+
const A = y.skinnedMeshBoundsFrameOffsetCounter++;
|
|
953
|
+
g[y.$skinnedMeshBoundsOffset] = A;
|
|
954
|
+
}
|
|
955
|
+
const w = g[y.$skinnedMeshBoundsOffset];
|
|
956
|
+
if ((s.frames + w) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
|
|
957
|
+
const A = de(g), F = g.geometry;
|
|
958
|
+
A && (g.geometry = A), g.computeBoundingBox(), g.geometry = F;
|
|
959
|
+
}
|
|
895
960
|
}
|
|
896
|
-
|
|
961
|
+
P = g.boundingBox;
|
|
897
962
|
}
|
|
898
|
-
if (
|
|
899
|
-
const
|
|
963
|
+
if (P) {
|
|
964
|
+
const g = t;
|
|
900
965
|
if (e.geometry.attributes.color && e.geometry.attributes.color.count < 100 && e.geometry.boundingSphere) {
|
|
901
966
|
this._sphere.copy(e.geometry.boundingSphere), this._sphere.applyMatrix4(e.matrixWorld);
|
|
902
|
-
const
|
|
903
|
-
if (this._sphere.containsPoint(
|
|
967
|
+
const p = t.getWorldPosition(this._tempWorldPosition);
|
|
968
|
+
if (this._sphere.containsPoint(p)) {
|
|
904
969
|
r.mesh_lod = 0, r.texture_lod = 0;
|
|
905
970
|
return;
|
|
906
971
|
}
|
|
907
972
|
}
|
|
908
|
-
if (this._tempBox.copy(
|
|
973
|
+
if (this._tempBox.copy(P), this._tempBox.applyMatrix4(e.matrixWorld), g.isPerspectiveCamera && y.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
909
974
|
r.mesh_lod = 0, r.texture_lod = 0;
|
|
910
975
|
return;
|
|
911
976
|
}
|
|
912
|
-
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled &&
|
|
913
|
-
const
|
|
914
|
-
let
|
|
915
|
-
const ce = 2,
|
|
916
|
-
|
|
917
|
-
const
|
|
918
|
-
s.lastCentrality = (
|
|
977
|
+
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && g.isPerspectiveCamera && g.fov > 70) {
|
|
978
|
+
const p = this._tempBox.min, M = this._tempBox.max;
|
|
979
|
+
let E = p.x, T = p.y, N = M.x, ie = M.y;
|
|
980
|
+
const ce = 2, De = 1.5, fe = (p.x + M.x) * 0.5, he = (p.y + M.y) * 0.5;
|
|
981
|
+
E = (E - fe) * ce + fe, T = (T - he) * ce + he, N = (N - fe) * ce + fe, ie = (ie - he) * ce + he;
|
|
982
|
+
const Ye = E < 0 && N > 0 ? 0 : Math.min(Math.abs(p.x), Math.abs(M.x)), He = T < 0 && ie > 0 ? 0 : Math.min(Math.abs(p.y), Math.abs(M.y)), Me = Math.max(Ye, He);
|
|
983
|
+
s.lastCentrality = (De - Me) * (De - Me) * (De - Me);
|
|
919
984
|
} else
|
|
920
985
|
s.lastCentrality = 1;
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
const
|
|
926
|
-
if (Math.max(
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
const M =
|
|
930
|
-
M.copy(this._tempBox.min),
|
|
931
|
-
const ie = (M.z +
|
|
932
|
-
M.z =
|
|
986
|
+
const w = this._tempBox.getSize(this._tempBoxSize);
|
|
987
|
+
w.multiplyScalar(0.5), screen.availHeight > 0 && v > 0 && w.multiplyScalar(v / screen.availHeight), t.isPerspectiveCamera ? w.x *= t.aspect : t.isOrthographicCamera;
|
|
988
|
+
const A = t.matrixWorldInverse, F = this._tempBox2;
|
|
989
|
+
F.copy(P), F.applyMatrix4(e.matrixWorld), F.applyMatrix4(A);
|
|
990
|
+
const S = F.getSize(this._tempBox2Size), Z = Math.max(S.x, S.y);
|
|
991
|
+
if (Math.max(w.x, w.y) != 0 && Z != 0 && (w.z = S.z / Math.max(S.x, S.y) * Math.max(w.x, w.y)), s.lastScreenCoverage = Math.max(w.x, w.y, w.z), s.lastScreenspaceVolume.copy(w), s.lastScreenCoverage *= s.lastCentrality, k && y.debugDrawLine) {
|
|
992
|
+
const p = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
993
|
+
p.invert();
|
|
994
|
+
const M = y.corner0, E = y.corner1, T = y.corner2, N = y.corner3;
|
|
995
|
+
M.copy(this._tempBox.min), E.copy(this._tempBox.max), E.x = M.x, T.copy(this._tempBox.max), T.y = M.y, N.copy(this._tempBox.max);
|
|
996
|
+
const ie = (M.z + N.z) * 0.5;
|
|
997
|
+
M.z = E.z = T.z = N.z = ie, M.applyMatrix4(p), E.applyMatrix4(p), T.applyMatrix4(p), N.applyMatrix4(p), y.debugDrawLine(M, E, 255), y.debugDrawLine(M, T, 255), y.debugDrawLine(E, N, 255), y.debugDrawLine(T, N, 255);
|
|
933
998
|
}
|
|
934
|
-
let
|
|
999
|
+
let O = 999;
|
|
935
1000
|
if (c && s.lastScreenCoverage > 0)
|
|
936
|
-
for (let
|
|
937
|
-
const M = c[
|
|
938
|
-
if ((
|
|
939
|
-
|
|
1001
|
+
for (let p = 0; p < c.length; p++) {
|
|
1002
|
+
const M = c[p], T = (((B = M.densities) == null ? void 0 : B[d]) || M.density || 1e-5) / s.lastScreenCoverage;
|
|
1003
|
+
if (d > 0 && Be() && !M.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), T < n) {
|
|
1004
|
+
O = p;
|
|
940
1005
|
break;
|
|
941
1006
|
}
|
|
942
1007
|
}
|
|
943
|
-
|
|
1008
|
+
O < a && (a = O, l = !0);
|
|
944
1009
|
}
|
|
945
1010
|
if (l ? r.mesh_lod = a : r.mesh_lod = s.lastLodLevel_Mesh, k && r.mesh_lod != s.lastLodLevel_Mesh) {
|
|
946
|
-
const
|
|
947
|
-
|
|
1011
|
+
const w = c == null ? void 0 : c[r.mesh_lod];
|
|
1012
|
+
w && console.log(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (${w.density.toFixed(0)}) - ${e.name}`);
|
|
948
1013
|
}
|
|
949
|
-
if (
|
|
950
|
-
const
|
|
1014
|
+
if (D) {
|
|
1015
|
+
const g = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
951
1016
|
if (s.lastLodLevel_Texture < 0) {
|
|
952
|
-
if (r.texture_lod =
|
|
953
|
-
const
|
|
954
|
-
k && console.log(`First Texture LOD ${r.texture_lod} (${
|
|
1017
|
+
if (r.texture_lod = f.max_count - 1, k) {
|
|
1018
|
+
const w = f.lods[f.max_count - 1];
|
|
1019
|
+
k && console.log(`First Texture LOD ${r.texture_lod} (${w.max_height}px) - ${e.name}`);
|
|
955
1020
|
}
|
|
956
1021
|
} else {
|
|
957
|
-
const
|
|
958
|
-
let
|
|
959
|
-
((
|
|
960
|
-
const
|
|
961
|
-
let
|
|
962
|
-
for (let
|
|
963
|
-
const
|
|
964
|
-
if (!(
|
|
965
|
-
if (
|
|
966
|
-
const
|
|
967
|
-
k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${
|
|
968
|
-
Screensize: ${
|
|
1022
|
+
const w = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
1023
|
+
let A = s.lastScreenCoverage * 4;
|
|
1024
|
+
((J = this.context) == null ? void 0 : J.engine) === "model-viewer" && (A *= 1.5);
|
|
1025
|
+
const S = v / window.devicePixelRatio * A;
|
|
1026
|
+
let Z = !1;
|
|
1027
|
+
for (let C = f.lods.length - 1; C >= 0; C--) {
|
|
1028
|
+
const O = f.lods[C];
|
|
1029
|
+
if (!(g && O.max_height >= 2048) && !(ft() && O.max_height > 4096) && (O.max_height > S || !Z && C === 0)) {
|
|
1030
|
+
if (Z = !0, r.texture_lod = C, r.texture_lod < s.lastLodLevel_Texture) {
|
|
1031
|
+
const m = O.max_height;
|
|
1032
|
+
k && console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${m}px
|
|
1033
|
+
Screensize: ${S.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${w.toFixed(1)}
|
|
969
1034
|
${e.name}`);
|
|
970
1035
|
}
|
|
971
1036
|
break;
|
|
@@ -975,56 +1040,56 @@ ${e.name}`);
|
|
|
975
1040
|
} else
|
|
976
1041
|
r.texture_lod = 0;
|
|
977
1042
|
}
|
|
978
|
-
},
|
|
1043
|
+
}, I = new WeakMap(), X = new WeakMap(), we = new WeakMap(), j = new WeakMap(), re = new WeakMap(), _e = new WeakMap(), K = new WeakMap(), /**
|
|
979
1044
|
* 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
1045
|
*/
|
|
981
|
-
|
|
1046
|
+
u(y, "debugDrawLine"), /**
|
|
982
1047
|
* Force override the LOD level for all objects in the scene
|
|
983
1048
|
*/
|
|
984
|
-
|
|
985
|
-
class
|
|
1049
|
+
u(y, "overrideGlobalLodLevel"), u(y, "corner0", new V()), u(y, "corner1", new V()), u(y, "corner2", new V()), u(y, "corner3", new V()), u(y, "_tempPtInside", new V()), u(y, "skinnedMeshBoundsFrameOffsetCounter", 0), u(y, "$skinnedMeshBoundsOffset", Symbol("gltf-progressive-skinnedMeshBoundsOffset")), y);
|
|
1050
|
+
class wt {
|
|
986
1051
|
constructor() {
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1052
|
+
u(this, "frames", 0);
|
|
1053
|
+
u(this, "lastLodLevel_Mesh", -1);
|
|
1054
|
+
u(this, "lastLodLevel_Texture", -1);
|
|
1055
|
+
u(this, "lastScreenCoverage", 0);
|
|
1056
|
+
u(this, "lastScreenspaceVolume", new V());
|
|
1057
|
+
u(this, "lastCentrality", 0);
|
|
993
1058
|
}
|
|
994
1059
|
}
|
|
995
|
-
const
|
|
1060
|
+
const ke = Symbol("NEEDLE_mesh_lod"), ge = Symbol("NEEDLE_texture_lod");
|
|
996
1061
|
let le = null;
|
|
997
1062
|
function Xe() {
|
|
998
|
-
const o =
|
|
1063
|
+
const o = _t();
|
|
999
1064
|
o && (o.mapURLs(function(t) {
|
|
1000
|
-
return
|
|
1001
|
-
}),
|
|
1065
|
+
return Re(), t;
|
|
1066
|
+
}), Re(), le == null || le.disconnect(), le = new MutationObserver((t) => {
|
|
1002
1067
|
t.forEach((e) => {
|
|
1003
1068
|
e.addedNodes.forEach((s) => {
|
|
1004
|
-
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" &&
|
|
1069
|
+
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Ke(s);
|
|
1005
1070
|
});
|
|
1006
1071
|
});
|
|
1007
1072
|
}), le.observe(document, { childList: !0, subtree: !0 }));
|
|
1008
1073
|
}
|
|
1009
|
-
function
|
|
1074
|
+
function _t() {
|
|
1010
1075
|
if (typeof customElements > "u") return null;
|
|
1011
1076
|
const o = customElements.get("model-viewer");
|
|
1012
1077
|
return o || (customElements.whenDefined("model-viewer").then(() => {
|
|
1013
1078
|
console.debug("[gltf-progressive] model-viewer defined"), Xe();
|
|
1014
1079
|
}), null);
|
|
1015
1080
|
}
|
|
1016
|
-
function
|
|
1081
|
+
function Re() {
|
|
1017
1082
|
if (typeof document > "u") return;
|
|
1018
1083
|
document.querySelectorAll("model-viewer").forEach((t) => {
|
|
1019
|
-
|
|
1084
|
+
Ke(t);
|
|
1020
1085
|
});
|
|
1021
1086
|
}
|
|
1022
|
-
const
|
|
1023
|
-
let
|
|
1024
|
-
function
|
|
1025
|
-
if (!o ||
|
|
1087
|
+
const Fe = /* @__PURE__ */ new WeakSet();
|
|
1088
|
+
let Dt = 0;
|
|
1089
|
+
function Ke(o) {
|
|
1090
|
+
if (!o || Fe.has(o))
|
|
1026
1091
|
return null;
|
|
1027
|
-
|
|
1092
|
+
Fe.add(o), console.debug("[gltf-progressive] found new model-viewer..." + ++Dt + `
|
|
1028
1093
|
`, o.getAttribute("src"));
|
|
1029
1094
|
let t = null, e = null, s = null;
|
|
1030
1095
|
for (let n = o; n != null; n = Object.getPrototypeOf(n)) {
|
|
@@ -1045,7 +1110,7 @@ function qe(o) {
|
|
|
1045
1110
|
};
|
|
1046
1111
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
1047
1112
|
const r = xe.get(t, { engine: "model-viewer" });
|
|
1048
|
-
return xe.addPlugin(new
|
|
1113
|
+
return xe.addPlugin(new Mt()), r.enable(), r.addEventListener("changed", () => {
|
|
1049
1114
|
s == null || s.call(o);
|
|
1050
1115
|
}), o.addEventListener("model-visibility", (i) => {
|
|
1051
1116
|
i.detail.visible && (s == null || s.call(o));
|
|
@@ -1057,9 +1122,9 @@ function qe(o) {
|
|
|
1057
1122
|
}
|
|
1058
1123
|
return null;
|
|
1059
1124
|
}
|
|
1060
|
-
class
|
|
1125
|
+
class Mt {
|
|
1061
1126
|
constructor() {
|
|
1062
|
-
|
|
1127
|
+
u(this, "_didWarnAboutMissingUrl", !1);
|
|
1063
1128
|
}
|
|
1064
1129
|
onBeforeUpdateLOD(t, e, s, n) {
|
|
1065
1130
|
this.tryParseMeshLOD(e, n), this.tryParseTextureLOD(e, n);
|
|
@@ -1082,23 +1147,23 @@ class vt {
|
|
|
1082
1147
|
const s = this.tryGetCurrentGLTF(t), n = this.tryGetCurrentModelViewer(t), r = this.getUrl(n);
|
|
1083
1148
|
if (r && s && e.material) {
|
|
1084
1149
|
let i = function(l) {
|
|
1085
|
-
var
|
|
1150
|
+
var d, h, f;
|
|
1086
1151
|
if (l[ge] == !0) return;
|
|
1087
1152
|
l[ge] = !0, l.userData && (l.userData.LOD = -1);
|
|
1088
1153
|
const c = Object.keys(l);
|
|
1089
|
-
for (let
|
|
1090
|
-
const
|
|
1091
|
-
if ((
|
|
1092
|
-
const
|
|
1093
|
-
if (
|
|
1094
|
-
const
|
|
1095
|
-
if (!
|
|
1096
|
-
console.warn("Texture data not found for texture index " +
|
|
1154
|
+
for (let D = 0; D < c.length; D++) {
|
|
1155
|
+
const v = c[D], P = l[v];
|
|
1156
|
+
if ((P == null ? void 0 : P.isTexture) === !0) {
|
|
1157
|
+
const b = (h = (d = P.userData) == null ? void 0 : d.associations) == null ? void 0 : h.textures;
|
|
1158
|
+
if (b == null) continue;
|
|
1159
|
+
const B = s.parser.json.textures[b];
|
|
1160
|
+
if (!B) {
|
|
1161
|
+
console.warn("Texture data not found for texture index " + b);
|
|
1097
1162
|
continue;
|
|
1098
1163
|
}
|
|
1099
|
-
if ((
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1164
|
+
if ((f = B == null ? void 0 : B.extensions) != null && f[W]) {
|
|
1165
|
+
const J = B.extensions[W];
|
|
1166
|
+
J && r && z.registerTexture(r, P, J.lods.length, b, J);
|
|
1102
1167
|
}
|
|
1103
1168
|
}
|
|
1104
1169
|
}
|
|
@@ -1110,20 +1175,20 @@ class vt {
|
|
|
1110
1175
|
}
|
|
1111
1176
|
tryParseMeshLOD(t, e) {
|
|
1112
1177
|
var i, a;
|
|
1113
|
-
if (e[
|
|
1114
|
-
e[
|
|
1178
|
+
if (e[ke] == !0) return;
|
|
1179
|
+
e[ke] = !0;
|
|
1115
1180
|
const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
|
|
1116
1181
|
if (!n)
|
|
1117
1182
|
return;
|
|
1118
|
-
const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[
|
|
1183
|
+
const r = (a = (i = e.userData) == null ? void 0 : i.gltfExtensions) == null ? void 0 : a[W];
|
|
1119
1184
|
if (r && n) {
|
|
1120
1185
|
const l = e.uuid;
|
|
1121
1186
|
z.registerMesh(n, l, e, 0, r.lods.length, r);
|
|
1122
1187
|
}
|
|
1123
1188
|
}
|
|
1124
1189
|
}
|
|
1125
|
-
function
|
|
1126
|
-
|
|
1190
|
+
function vt(o, t, e, s) {
|
|
1191
|
+
ze(t), qe(e), Ve(e, {
|
|
1127
1192
|
progressive: !0,
|
|
1128
1193
|
...s == null ? void 0 : s.hints
|
|
1129
1194
|
}), e.register((r) => new z(r, o));
|
|
@@ -1131,14 +1196,14 @@ function Dt(o, t, e, s) {
|
|
|
1131
1196
|
return (s == null ? void 0 : s.enableLODsManager) !== !1 && n.enable(), n;
|
|
1132
1197
|
}
|
|
1133
1198
|
Xe();
|
|
1134
|
-
if (!
|
|
1199
|
+
if (!gt) {
|
|
1135
1200
|
const o = {
|
|
1136
1201
|
gltfProgressive: {
|
|
1137
|
-
useNeedleProgressive:
|
|
1202
|
+
useNeedleProgressive: vt,
|
|
1138
1203
|
LODsManager: xe,
|
|
1139
1204
|
configureLoader: Ve,
|
|
1140
|
-
getRaycastMesh:
|
|
1141
|
-
useRaycastMeshes:
|
|
1205
|
+
getRaycastMesh: de,
|
|
1206
|
+
useRaycastMeshes: mt
|
|
1142
1207
|
}
|
|
1143
1208
|
};
|
|
1144
1209
|
if (!globalThis.Needle)
|
|
@@ -1150,10 +1215,10 @@ if (!ht) {
|
|
|
1150
1215
|
export {
|
|
1151
1216
|
xe as LODsManager,
|
|
1152
1217
|
z as NEEDLE_progressive,
|
|
1153
|
-
|
|
1218
|
+
qe as addDracoAndKTX2Loaders,
|
|
1154
1219
|
Ve as configureLoader,
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1220
|
+
ze as createLoaders,
|
|
1221
|
+
de as getRaycastMesh,
|
|
1222
|
+
lt as setDracoDecoderLocation,
|
|
1223
|
+
ut as setKTX2TranscoderLocation
|
|
1159
1224
|
};
|