@needle-tools/gltf-progressive 3.1.0 → 3.1.1-next.80f25bb
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 +4 -0
- package/README.md +79 -39
- package/gltf-progressive.js +983 -779
- package/gltf-progressive.min.js +8 -8
- package/gltf-progressive.umd.cjs +8 -8
- package/lib/extension.d.ts +3 -0
- package/lib/extension.js +96 -14
- package/lib/loaders.d.ts +8 -0
- package/lib/loaders.js +33 -22
- package/lib/lods.manager.js +24 -11
- package/lib/utils.internal.d.ts +4 -5
- package/lib/utils.internal.js +2 -2
- package/lib/version.js +1 -1
- package/lib/worker/loader.mainthread.d.ts +46 -0
- package/lib/worker/loader.mainthread.js +201 -0
- package/package.json +2 -2
package/gltf-progressive.js
CHANGED
|
@@ -1,249 +1,410 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
if (!
|
|
5
|
-
throw TypeError("Cannot " +
|
|
1
|
+
var st = Object.defineProperty;
|
|
2
|
+
var it = (n, e, t) => e in n ? st(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var c = (n, e, t) => (it(n, typeof e != "symbol" ? e + "" : e, t), t), Xe = (n, e, t) => {
|
|
4
|
+
if (!e.has(n))
|
|
5
|
+
throw TypeError("Cannot " + t);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
if (
|
|
7
|
+
var L = (n, e, t) => (Xe(n, e, "read from private field"), t ? t.call(n) : e.get(n)), q = (n, e, t) => {
|
|
8
|
+
if (e.has(n))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
import { BufferGeometry as
|
|
13
|
-
import { GLTFLoader as
|
|
14
|
-
import { MeshoptDecoder as
|
|
15
|
-
import { DRACOLoader as
|
|
16
|
-
import { KTX2Loader as
|
|
17
|
-
const
|
|
18
|
-
globalThis.GLTF_PROGRESSIVE_VERSION =
|
|
10
|
+
e instanceof WeakSet ? e.add(n) : e.set(n, t);
|
|
11
|
+
}, E = (n, e, t, s) => (Xe(n, e, "write to private field"), s ? s.call(n, t) : e.set(n, t), t);
|
|
12
|
+
import { BufferGeometry as he, Mesh as oe, Box3 as Be, Vector3 as N, Sphere as Ye, CompressedTexture as rt, Texture as se, Matrix3 as ot, InterleavedBuffer as nt, InterleavedBufferAttribute as at, BufferAttribute as lt, TextureLoader as gt, Matrix4 as Ke, Clock as ct, MeshStandardMaterial as dt } from "three";
|
|
13
|
+
import { GLTFLoader as We } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
14
|
+
import { MeshoptDecoder as ut } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
15
|
+
import { DRACOLoader as ft } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
16
|
+
import { KTX2Loader as ht } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
17
|
+
const mt = "";
|
|
18
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = mt;
|
|
19
19
|
console.debug("[gltf-progressive] version -");
|
|
20
|
-
let
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
fetch(
|
|
20
|
+
let H = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", ne = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
21
|
+
const pt = H, It = ne, Fe = new URL(H + "draco_decoder.js");
|
|
22
|
+
Fe.searchParams.append("range", "true");
|
|
23
|
+
fetch(Fe, {
|
|
24
24
|
method: "GET",
|
|
25
25
|
headers: {
|
|
26
26
|
Range: "bytes=0-1"
|
|
27
27
|
}
|
|
28
|
-
}).catch((
|
|
29
|
-
console.debug(`Failed to fetch remote Draco decoder from ${
|
|
28
|
+
}).catch((n) => {
|
|
29
|
+
console.debug(`Failed to fetch remote Draco decoder from ${H} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), H === pt && yt("./include/draco/"), ne === It && At("./include/ktx2/");
|
|
30
30
|
}).finally(() => {
|
|
31
|
-
|
|
31
|
+
Ue();
|
|
32
32
|
});
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const Ct = () => ({
|
|
34
|
+
dracoDecoderPath: H,
|
|
35
|
+
ktx2TranscoderPath: ne
|
|
36
|
+
});
|
|
37
|
+
function yt(n) {
|
|
38
|
+
H = n, K && K[ke] != H ? (console.debug("Updating Draco decoder path to " + n), K[ke] = H, K.setDecoderPath(H), K.preload()) : console.debug("Setting Draco decoder path to " + n);
|
|
35
39
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
40
|
+
function At(n) {
|
|
41
|
+
ne = n, Y && Y.transcoderPath != ne ? (console.debug("Updating KTX2 transcoder path to " + n), Y.setTranscoderPath(ne), Y.init()) : console.debug("Setting KTX2 transcoder path to " + n);
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
function Fe() {
|
|
42
|
-
I || (I = new tt(), I[Pe] = V, I.setDecoderPath(V), I.setDecoderConfig({ type: "js" }), I.preload()), U || (U = new st(), U.setTranscoderPath(re), U.init()), Le || (Le = et);
|
|
43
|
+
function Te(n) {
|
|
44
|
+
return Ue(), n ? Y.detectSupport(n) : n !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: K, ktx2Loader: Y, meshoptDecoder: xe };
|
|
43
45
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
+
function Ee(n) {
|
|
47
|
+
n.dracoLoader || n.setDRACOLoader(K), n.ktx2Loader || n.setKTX2Loader(Y), n.meshoptDecoder || n.setMeshoptDecoder(xe);
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const ke = Symbol("dracoDecoderPath");
|
|
50
|
+
let K, xe, Y;
|
|
51
|
+
function Ue() {
|
|
52
|
+
K || (K = new ft(), K[ke] = H, K.setDecoderPath(H), K.setDecoderConfig({ type: "js" }), K.preload()), Y || (Y = new ht(), Y.setTranscoderPath(ne), Y.init()), xe || (xe = ut);
|
|
49
53
|
}
|
|
50
|
-
const
|
|
51
|
-
function
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
+
const Ve = /* @__PURE__ */ new WeakMap();
|
|
55
|
+
function Je(n, e) {
|
|
56
|
+
let t = Ve.get(n);
|
|
57
|
+
t ? t = Object.assign(t, e) : t = e, Ve.set(n, t);
|
|
54
58
|
}
|
|
55
|
-
const
|
|
56
|
-
function
|
|
57
|
-
const
|
|
58
|
-
let
|
|
59
|
-
const s = new URL(
|
|
59
|
+
const Me = We.prototype.load;
|
|
60
|
+
function wt(...n) {
|
|
61
|
+
const e = Ve.get(this);
|
|
62
|
+
let t = n[0];
|
|
63
|
+
const s = new URL(t, window.location.href);
|
|
60
64
|
if (s.hostname.endsWith("needle.tools")) {
|
|
61
|
-
const
|
|
62
|
-
|
|
65
|
+
const i = (e == null ? void 0 : e.progressive) !== void 0 ? e.progressive : !0, o = e != null && e.usecase ? e.usecase : "default";
|
|
66
|
+
i ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${o}` : this.requestHeader.Accept = `*/*;usecase=${o}`, t = s.toString();
|
|
63
67
|
}
|
|
64
|
-
return
|
|
68
|
+
return n[0] = t, Me == null ? void 0 : Me.call(this, ...n);
|
|
65
69
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
function
|
|
70
|
+
We.prototype.load = wt;
|
|
71
|
+
ae("debugprogressive");
|
|
72
|
+
function ae(n) {
|
|
69
73
|
if (typeof window > "u")
|
|
70
74
|
return !1;
|
|
71
|
-
const
|
|
72
|
-
return
|
|
75
|
+
const t = new URL(window.location.href).searchParams.get(n);
|
|
76
|
+
return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
|
|
73
77
|
}
|
|
74
|
-
function
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
const s =
|
|
80
|
-
for (; s.endsWith("/") &&
|
|
81
|
-
|
|
82
|
-
return s +
|
|
83
|
-
}
|
|
84
|
-
return
|
|
78
|
+
function bt(n, e) {
|
|
79
|
+
if (e === void 0 || e.startsWith("./") || e.startsWith("http") || n === void 0)
|
|
80
|
+
return e;
|
|
81
|
+
const t = n.lastIndexOf("/");
|
|
82
|
+
if (t >= 0) {
|
|
83
|
+
const s = n.substring(0, t + 1);
|
|
84
|
+
for (; s.endsWith("/") && e.startsWith("/"); )
|
|
85
|
+
e = e.substring(1);
|
|
86
|
+
return s + e;
|
|
87
|
+
}
|
|
88
|
+
return e;
|
|
85
89
|
}
|
|
86
|
-
let
|
|
87
|
-
function
|
|
88
|
-
return
|
|
90
|
+
let ce;
|
|
91
|
+
function $e() {
|
|
92
|
+
return ce !== void 0 || (ce = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), ae("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", ce)), ce;
|
|
89
93
|
}
|
|
90
|
-
function
|
|
94
|
+
function Pe() {
|
|
91
95
|
if (typeof window > "u")
|
|
92
96
|
return !1;
|
|
93
|
-
const
|
|
94
|
-
return
|
|
97
|
+
const n = new URL(window.location.href), e = n.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(n.hostname);
|
|
98
|
+
return n.hostname === "127.0.0.1" || e;
|
|
95
99
|
}
|
|
96
|
-
class
|
|
97
|
-
constructor(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
class xt {
|
|
101
|
+
constructor(e = 100, t = {}) {
|
|
102
|
+
c(this, "_running", /* @__PURE__ */ new Map());
|
|
103
|
+
c(this, "_queue", []);
|
|
104
|
+
c(this, "debug", !1);
|
|
105
|
+
c(this, "tick", () => {
|
|
102
106
|
this.internalUpdate(), setTimeout(this.tick, 10);
|
|
103
107
|
});
|
|
104
|
-
this.maxConcurrent =
|
|
108
|
+
this.maxConcurrent = e, this.debug = t.debug ?? !1, window.requestAnimationFrame(this.tick);
|
|
105
109
|
}
|
|
106
110
|
/**
|
|
107
111
|
* 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.
|
|
108
112
|
*/
|
|
109
|
-
slot(
|
|
110
|
-
return this.debug && console.debug(`[PromiseQueue]: Requesting slot for key ${
|
|
111
|
-
this._queue.push({ key:
|
|
113
|
+
slot(e) {
|
|
114
|
+
return this.debug && console.debug(`[PromiseQueue]: Requesting slot for key ${e}, running: ${this._running.size}, waiting: ${this._queue.length}`), new Promise((t) => {
|
|
115
|
+
this._queue.push({ key: e, resolve: t });
|
|
112
116
|
});
|
|
113
117
|
}
|
|
114
|
-
add(
|
|
115
|
-
this._running.has(
|
|
116
|
-
this._running.delete(
|
|
117
|
-
}), this.debug && console.debug(`[PromiseQueue]:
|
|
118
|
+
add(e, t) {
|
|
119
|
+
this._running.has(e) || (this._running.set(e, t), t.finally(() => {
|
|
120
|
+
this._running.delete(e), this.debug && console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${e})`);
|
|
121
|
+
}), this.debug && console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${e})`));
|
|
118
122
|
}
|
|
119
123
|
internalUpdate() {
|
|
120
|
-
const
|
|
121
|
-
for (let
|
|
124
|
+
const e = this.maxConcurrent - this._running.size;
|
|
125
|
+
for (let t = 0; t < e && this._queue.length > 0; t++) {
|
|
122
126
|
this.debug && console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);
|
|
123
|
-
const { key: s, resolve:
|
|
124
|
-
|
|
125
|
-
use: (
|
|
127
|
+
const { key: s, resolve: r } = this._queue.shift();
|
|
128
|
+
r({
|
|
129
|
+
use: (i) => this.add(s, i)
|
|
126
130
|
});
|
|
127
131
|
}
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
|
-
const
|
|
131
|
-
function
|
|
132
|
-
return (
|
|
134
|
+
const Lt = typeof window > "u" && typeof document > "u", Oe = Symbol("needle:raycast-mesh");
|
|
135
|
+
function me(n) {
|
|
136
|
+
return (n == null ? void 0 : n[Oe]) instanceof he ? n[Oe] : null;
|
|
133
137
|
}
|
|
134
|
-
function
|
|
135
|
-
if ((
|
|
136
|
-
const s =
|
|
137
|
-
s.userData = { isRaycastMesh: !0 },
|
|
138
|
+
function vt(n, e) {
|
|
139
|
+
if ((n.type === "Mesh" || n.type === "SkinnedMesh") && !me(n)) {
|
|
140
|
+
const s = Zt(e);
|
|
141
|
+
s.userData = { isRaycastMesh: !0 }, n[Oe] = s;
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
|
-
function
|
|
141
|
-
if (
|
|
142
|
-
if (
|
|
144
|
+
function Gt(n = !0) {
|
|
145
|
+
if (n) {
|
|
146
|
+
if (de)
|
|
143
147
|
return;
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
let
|
|
148
|
-
|
|
148
|
+
const e = de = oe.prototype.raycast;
|
|
149
|
+
oe.prototype.raycast = function(t, s) {
|
|
150
|
+
const r = this, i = me(r);
|
|
151
|
+
let o;
|
|
152
|
+
i && r.isMesh && (o = r.geometry, r.geometry = i), e.call(this, t, s), o && (r.geometry = o);
|
|
149
153
|
};
|
|
150
154
|
} else {
|
|
151
|
-
if (!
|
|
155
|
+
if (!de)
|
|
152
156
|
return;
|
|
153
|
-
|
|
157
|
+
oe.prototype.raycast = de, de = null;
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
|
-
let
|
|
157
|
-
function
|
|
158
|
-
const
|
|
159
|
-
for (const
|
|
160
|
-
|
|
161
|
-
return
|
|
160
|
+
let de = null;
|
|
161
|
+
function Zt(n) {
|
|
162
|
+
const e = new he();
|
|
163
|
+
for (const t in n.attributes)
|
|
164
|
+
e.setAttribute(t, n.getAttribute(t));
|
|
165
|
+
return e.setIndex(n.getIndex()), e;
|
|
162
166
|
}
|
|
163
|
-
const j = new Array(),
|
|
164
|
-
let
|
|
165
|
-
if (
|
|
166
|
-
let
|
|
167
|
-
|
|
168
|
-
},
|
|
169
|
-
window.addEventListener("keyup", (
|
|
170
|
-
|
|
171
|
-
const s = parseInt(
|
|
172
|
-
!isNaN(s) && s >= 0 && (
|
|
167
|
+
const j = new Array(), C = ae("debugprogressive");
|
|
168
|
+
let Ae, ie = -1;
|
|
169
|
+
if (C) {
|
|
170
|
+
let n = function() {
|
|
171
|
+
ie += 1, ie >= e && (ie = -1), console.log(`Toggle LOD level [${ie}]`);
|
|
172
|
+
}, e = 6;
|
|
173
|
+
window.addEventListener("keyup", (t) => {
|
|
174
|
+
t.key === "p" && n(), t.key === "w" && (Ae = !Ae, console.log(`Toggle wireframe [${Ae}]`));
|
|
175
|
+
const s = parseInt(t.key);
|
|
176
|
+
!isNaN(s) && s >= 0 && (ie = s, console.log(`Set LOD level to [${ie}]`));
|
|
173
177
|
});
|
|
174
178
|
}
|
|
175
|
-
function qe(
|
|
176
|
-
if (
|
|
177
|
-
if (Array.isArray(
|
|
178
|
-
for (const
|
|
179
|
-
qe(
|
|
179
|
+
function qe(n) {
|
|
180
|
+
if (C)
|
|
181
|
+
if (Array.isArray(n))
|
|
182
|
+
for (const e of n)
|
|
183
|
+
qe(e);
|
|
180
184
|
else
|
|
181
|
-
|
|
185
|
+
n && "wireframe" in n && (n.wireframe = Ae === !0);
|
|
186
|
+
}
|
|
187
|
+
const ue = new Array();
|
|
188
|
+
let Mt = 0;
|
|
189
|
+
const _t = $e() ? 2 : 10;
|
|
190
|
+
function St(n) {
|
|
191
|
+
if (ue.length < _t) {
|
|
192
|
+
const s = ue.length;
|
|
193
|
+
C && console.warn(`[Worker] Creating new worker #${s}`);
|
|
194
|
+
const r = we.createWorker(n || {});
|
|
195
|
+
return ue.push(r), r;
|
|
196
|
+
}
|
|
197
|
+
const e = Mt++ % ue.length;
|
|
198
|
+
return ue[e];
|
|
199
|
+
}
|
|
200
|
+
const re = class {
|
|
201
|
+
constructor(e, t) {
|
|
202
|
+
c(this, "_running", []);
|
|
203
|
+
c(this, "_webglRenderer", null);
|
|
204
|
+
c(this, "_debug", !1);
|
|
205
|
+
this.worker = e, this._debug = t.debug ?? !1, e.onmessage = (s) => {
|
|
206
|
+
const r = s.data;
|
|
207
|
+
switch (this._debug && console.log("[Worker] EVENT", r), r.type) {
|
|
208
|
+
case "loaded-gltf":
|
|
209
|
+
for (const i of this._running)
|
|
210
|
+
if (i.url === r.result.url) {
|
|
211
|
+
Dt(r.result), i.resolve(r.result);
|
|
212
|
+
const o = i.url;
|
|
213
|
+
o.startsWith("blob:") && URL.revokeObjectURL(o);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}, e.onerror = (s) => {
|
|
217
|
+
console.error("[Worker] Error in gltf-progressive worker:", s);
|
|
218
|
+
}, e.postMessage({
|
|
219
|
+
type: "init"
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
static async createWorker(e) {
|
|
223
|
+
if (!re.workerUrl && (re.workerUrl = await Promise.resolve().then(() => Nt).then((r) => (r.default || r).toString()), !re.workerUrl))
|
|
224
|
+
throw new Error("Failed to load GLTFLoaderWorker worker URL");
|
|
225
|
+
const t = new Worker(new URL(re.workerUrl, import.meta.url), {
|
|
226
|
+
type: "module"
|
|
227
|
+
});
|
|
228
|
+
return new re(t, e);
|
|
229
|
+
}
|
|
230
|
+
async load(e, t) {
|
|
231
|
+
const s = Ct();
|
|
232
|
+
let r = t == null ? void 0 : t.renderer;
|
|
233
|
+
r || (this._webglRenderer ?? (this._webglRenderer = (async () => {
|
|
234
|
+
const { WebGLRenderer: g } = await import("three");
|
|
235
|
+
return new g();
|
|
236
|
+
})()), r = await this._webglRenderer);
|
|
237
|
+
const a = Te(r).ktx2Loader.workerConfig;
|
|
238
|
+
e instanceof URL ? e = e.toString() : e.startsWith("file:") ? e = URL.createObjectURL(new Blob([e])) : !e.startsWith("blob:") && !e.startsWith("http:") && !e.startsWith("https:") && (e = new URL(e, window.location.href).toString());
|
|
239
|
+
const l = {
|
|
240
|
+
type: "load",
|
|
241
|
+
url: e,
|
|
242
|
+
dracoDecoderPath: s.dracoDecoderPath,
|
|
243
|
+
ktx2TranscoderPath: s.ktx2TranscoderPath,
|
|
244
|
+
ktx2LoaderConfig: a
|
|
245
|
+
};
|
|
246
|
+
return this._debug && console.debug("[Worker] Sending load request", l), this.worker.postMessage(l), new Promise((g) => {
|
|
247
|
+
this._running.push({
|
|
248
|
+
url: e.toString(),
|
|
249
|
+
resolve: g
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
let we = re;
|
|
255
|
+
c(we, "workerUrl", null);
|
|
256
|
+
function Dt(n) {
|
|
257
|
+
var e, t, s, r, i, o, a, l, g, u, p, w, y, G, b, k;
|
|
258
|
+
for (const v of n.geometries) {
|
|
259
|
+
const d = v.geometry, x = new he();
|
|
260
|
+
if (x.name = d.name || "", d.index) {
|
|
261
|
+
const f = d.index;
|
|
262
|
+
x.setIndex(_e(f));
|
|
263
|
+
}
|
|
264
|
+
for (const f in d.attributes) {
|
|
265
|
+
const A = d.attributes[f], _ = _e(A);
|
|
266
|
+
x.setAttribute(f, _);
|
|
267
|
+
}
|
|
268
|
+
if (d.morphAttributes)
|
|
269
|
+
for (const f in d.morphAttributes) {
|
|
270
|
+
const _ = d.morphAttributes[f].map((P) => _e(P));
|
|
271
|
+
x.morphAttributes[f] = _;
|
|
272
|
+
}
|
|
273
|
+
if (x.morphTargetsRelative = d.morphTargetsRelative ?? !1, x.boundingBox = new Be(), x.boundingBox.min = new N(
|
|
274
|
+
(e = d.boundingBox) == null ? void 0 : e.min.x,
|
|
275
|
+
(t = d.boundingBox) == null ? void 0 : t.min.y,
|
|
276
|
+
(s = d.boundingBox) == null ? void 0 : s.min.z
|
|
277
|
+
), x.boundingBox.max = new N(
|
|
278
|
+
(r = d.boundingBox) == null ? void 0 : r.max.x,
|
|
279
|
+
(i = d.boundingBox) == null ? void 0 : i.max.y,
|
|
280
|
+
(o = d.boundingBox) == null ? void 0 : o.max.z
|
|
281
|
+
), x.boundingSphere = new Ye(
|
|
282
|
+
new N(
|
|
283
|
+
(a = d.boundingSphere) == null ? void 0 : a.center.x,
|
|
284
|
+
(l = d.boundingSphere) == null ? void 0 : l.center.y,
|
|
285
|
+
(g = d.boundingSphere) == null ? void 0 : g.center.z
|
|
286
|
+
),
|
|
287
|
+
(u = d.boundingSphere) == null ? void 0 : u.radius
|
|
288
|
+
), d.groups)
|
|
289
|
+
for (const f of d.groups)
|
|
290
|
+
x.addGroup(f.start, f.count, f.materialIndex);
|
|
291
|
+
d.userData && (x.userData = d.userData), v.geometry = x;
|
|
292
|
+
}
|
|
293
|
+
for (const v of n.textures) {
|
|
294
|
+
const d = v.texture;
|
|
295
|
+
let x = null;
|
|
296
|
+
if (d.isCompressedTexture) {
|
|
297
|
+
const f = d.mipmaps, A = ((p = d.image) == null ? void 0 : p.width) || ((y = (w = d.source) == null ? void 0 : w.data) == null ? void 0 : y.width) || -1, _ = ((G = d.image) == null ? void 0 : G.height) || ((k = (b = d.source) == null ? void 0 : b.data) == null ? void 0 : k.height) || -1;
|
|
298
|
+
x = new rt(
|
|
299
|
+
f,
|
|
300
|
+
A,
|
|
301
|
+
_,
|
|
302
|
+
d.format,
|
|
303
|
+
d.type,
|
|
304
|
+
d.mapping,
|
|
305
|
+
d.wrapS,
|
|
306
|
+
d.wrapT,
|
|
307
|
+
d.magFilter,
|
|
308
|
+
d.minFilter,
|
|
309
|
+
d.anisotropy,
|
|
310
|
+
d.colorSpace
|
|
311
|
+
);
|
|
312
|
+
} else
|
|
313
|
+
x = new se(
|
|
314
|
+
d.image,
|
|
315
|
+
d.mapping,
|
|
316
|
+
d.wrapS,
|
|
317
|
+
d.wrapT,
|
|
318
|
+
d.magFilter,
|
|
319
|
+
d.minFilter,
|
|
320
|
+
d.format,
|
|
321
|
+
d.type,
|
|
322
|
+
d.anisotropy,
|
|
323
|
+
d.colorSpace
|
|
324
|
+
), x.mipmaps = d.mipmaps, x.channel = d.channel, x.source.data = d.source.data, x.flipY = d.flipY, x.premultiplyAlpha = d.premultiplyAlpha, x.unpackAlignment = d.unpackAlignment, x.matrix = new ot(...d.matrix.elements);
|
|
325
|
+
if (!x) {
|
|
326
|
+
console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
v.texture = x;
|
|
330
|
+
}
|
|
331
|
+
return n;
|
|
182
332
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
333
|
+
function _e(n) {
|
|
334
|
+
let e = n;
|
|
335
|
+
if ("isInterleavedBufferAttribute" in n && n.isInterleavedBufferAttribute) {
|
|
336
|
+
const t = n.data, s = t.array, r = new nt(s, t.stride);
|
|
337
|
+
e = new at(r, n.itemSize, s.byteOffset, n.normalized), e.offset = n.offset;
|
|
338
|
+
} else
|
|
339
|
+
"isBufferAttribute" in n && n.isBufferAttribute && (e = new lt(n.array, n.itemSize, n.normalized), e.usage = n.usage, e.gpuType = n.gpuType, e.updateRanges = n.updateRanges);
|
|
340
|
+
return e;
|
|
341
|
+
}
|
|
342
|
+
const Rt = ae("gltf-progressive-worker"), Bt = ae("gltf-progressive-reduce-mipmaps"), Se = Symbol("needle-progressive-texture"), U = "NEEDLE_progressive", M = class {
|
|
343
|
+
constructor(e, t) {
|
|
344
|
+
c(this, "parser");
|
|
345
|
+
c(this, "url");
|
|
346
|
+
c(this, "_isLoadingMesh");
|
|
347
|
+
c(this, "loadMesh", (e) => {
|
|
348
|
+
var s, r;
|
|
190
349
|
if (this._isLoadingMesh)
|
|
191
350
|
return null;
|
|
192
|
-
const
|
|
193
|
-
return
|
|
194
|
-
var
|
|
195
|
-
return this._isLoadingMesh = !1,
|
|
351
|
+
const t = (r = (s = this.parser.json.meshes[e]) == null ? void 0 : s.extensions) == null ? void 0 : r[U];
|
|
352
|
+
return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((i) => {
|
|
353
|
+
var o;
|
|
354
|
+
return this._isLoadingMesh = !1, i && M.registerMesh(this.url, t.guid, i, (o = t.lods) == null ? void 0 : o.length, 0, t), i;
|
|
196
355
|
})) : null;
|
|
197
356
|
});
|
|
198
|
-
|
|
357
|
+
C && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
|
|
199
358
|
}
|
|
200
359
|
/** The name of the extension */
|
|
201
360
|
get name() {
|
|
202
|
-
return
|
|
361
|
+
return U;
|
|
203
362
|
}
|
|
204
|
-
static getMeshLODExtension(
|
|
205
|
-
const
|
|
206
|
-
return
|
|
363
|
+
static getMeshLODExtension(e) {
|
|
364
|
+
const t = this.getAssignedLODInformation(e);
|
|
365
|
+
return t != null && t.key ? this.lodInfos.get(t.key) : null;
|
|
207
366
|
}
|
|
208
|
-
static getPrimitiveIndex(
|
|
367
|
+
static getPrimitiveIndex(e) {
|
|
209
368
|
var s;
|
|
210
|
-
const
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
static getMaterialMinMaxLODsCount(
|
|
214
|
-
const s = this,
|
|
215
|
-
if (
|
|
216
|
-
return
|
|
217
|
-
if (
|
|
369
|
+
const t = (s = this.getAssignedLODInformation(e)) == null ? void 0 : s.index;
|
|
370
|
+
return t ?? -1;
|
|
371
|
+
}
|
|
372
|
+
static getMaterialMinMaxLODsCount(e, t) {
|
|
373
|
+
const s = this, r = "LODS:minmax", i = e[r];
|
|
374
|
+
if (i != null)
|
|
375
|
+
return i;
|
|
376
|
+
if (t || (t = {
|
|
218
377
|
min_count: 1 / 0,
|
|
219
378
|
max_count: 0,
|
|
220
379
|
lods: []
|
|
221
|
-
}), Array.isArray(
|
|
222
|
-
for (const a of
|
|
223
|
-
this.getMaterialMinMaxLODsCount(a,
|
|
224
|
-
return
|
|
380
|
+
}), Array.isArray(e)) {
|
|
381
|
+
for (const a of e)
|
|
382
|
+
this.getMaterialMinMaxLODsCount(a, t);
|
|
383
|
+
return e[r] = t, t;
|
|
225
384
|
}
|
|
226
|
-
if (
|
|
227
|
-
const a =
|
|
385
|
+
if (C === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
|
|
386
|
+
const a = e;
|
|
228
387
|
for (const l of Object.keys(a.uniforms)) {
|
|
229
|
-
const
|
|
230
|
-
(
|
|
388
|
+
const g = a.uniforms[l].value;
|
|
389
|
+
(g == null ? void 0 : g.isTexture) === !0 && o(g, t);
|
|
231
390
|
}
|
|
232
|
-
} else if (
|
|
233
|
-
for (const a of Object.keys(
|
|
234
|
-
const l =
|
|
235
|
-
(l == null ? void 0 : l.isTexture) === !0 &&
|
|
391
|
+
} else if (e.isMaterial)
|
|
392
|
+
for (const a of Object.keys(e)) {
|
|
393
|
+
const l = e[a];
|
|
394
|
+
(l == null ? void 0 : l.isTexture) === !0 && o(l, t);
|
|
236
395
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
396
|
+
else
|
|
397
|
+
C && console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${e.type}`);
|
|
398
|
+
return e[r] = t, t;
|
|
399
|
+
function o(a, l) {
|
|
400
|
+
const g = s.getAssignedLODInformation(a);
|
|
401
|
+
if (g) {
|
|
402
|
+
const u = s.lodInfos.get(g.key);
|
|
403
|
+
if (u && u.lods) {
|
|
404
|
+
l.min_count = Math.min(l.min_count, u.lods.length), l.max_count = Math.max(l.max_count, u.lods.length);
|
|
405
|
+
for (let p = 0; p < u.lods.length; p++) {
|
|
406
|
+
const w = u.lods[p];
|
|
407
|
+
w.width && (l.lods[p] = l.lods[p] || { min_height: 1 / 0, max_height: 0 }, l.lods[p].min_height = Math.min(l.lods[p].min_height, w.height), l.lods[p].max_height = Math.max(l.lods[p].max_height, w.height));
|
|
247
408
|
}
|
|
248
409
|
}
|
|
249
410
|
}
|
|
@@ -254,33 +415,33 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), D = c
|
|
|
254
415
|
* @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
|
|
255
416
|
* @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
|
|
256
417
|
*/
|
|
257
|
-
static hasLODLevelAvailable(
|
|
258
|
-
var
|
|
259
|
-
if (Array.isArray(
|
|
260
|
-
for (const
|
|
261
|
-
if (this.hasLODLevelAvailable(
|
|
418
|
+
static hasLODLevelAvailable(e, t) {
|
|
419
|
+
var i;
|
|
420
|
+
if (Array.isArray(e)) {
|
|
421
|
+
for (const o of e)
|
|
422
|
+
if (this.hasLODLevelAvailable(o, t))
|
|
262
423
|
return !0;
|
|
263
424
|
return !1;
|
|
264
425
|
}
|
|
265
|
-
if (
|
|
266
|
-
for (const
|
|
267
|
-
const a =
|
|
268
|
-
if (a && a.isTexture && this.hasLODLevelAvailable(a,
|
|
426
|
+
if (e.isMaterial === !0) {
|
|
427
|
+
for (const o of Object.keys(e)) {
|
|
428
|
+
const a = e[o];
|
|
429
|
+
if (a && a.isTexture && this.hasLODLevelAvailable(a, t))
|
|
269
430
|
return !0;
|
|
270
431
|
}
|
|
271
432
|
return !1;
|
|
272
|
-
} else if (
|
|
273
|
-
for (const
|
|
274
|
-
if (
|
|
433
|
+
} else if (e.isGroup === !0) {
|
|
434
|
+
for (const o of e.children)
|
|
435
|
+
if (o.isMesh === !0 && this.hasLODLevelAvailable(o, t))
|
|
275
436
|
return !0;
|
|
276
437
|
}
|
|
277
|
-
let s,
|
|
278
|
-
if (
|
|
279
|
-
const
|
|
280
|
-
if (
|
|
281
|
-
return
|
|
282
|
-
if (
|
|
283
|
-
return Array.isArray(
|
|
438
|
+
let s, r;
|
|
439
|
+
if (e.isMesh ? s = e.geometry : (e.isBufferGeometry || e.isTexture) && (s = e), s && (i = s == null ? void 0 : s.userData) != null && i.LODS) {
|
|
440
|
+
const o = s.userData.LODS;
|
|
441
|
+
if (r = this.lodInfos.get(o.key), t === void 0)
|
|
442
|
+
return r != null;
|
|
443
|
+
if (r)
|
|
444
|
+
return Array.isArray(r.lods) ? t < r.lods.length : t === 0;
|
|
284
445
|
}
|
|
285
446
|
return !1;
|
|
286
447
|
}
|
|
@@ -298,333 +459,373 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), D = c
|
|
|
298
459
|
* });
|
|
299
460
|
* ```
|
|
300
461
|
*/
|
|
301
|
-
static assignMeshLOD(
|
|
462
|
+
static assignMeshLOD(e, t) {
|
|
302
463
|
var s;
|
|
303
|
-
if (!
|
|
464
|
+
if (!e)
|
|
304
465
|
return Promise.resolve(null);
|
|
305
|
-
if (
|
|
306
|
-
const
|
|
307
|
-
if (!
|
|
466
|
+
if (e instanceof oe || e.isMesh === !0) {
|
|
467
|
+
const r = e.geometry, i = this.getAssignedLODInformation(r);
|
|
468
|
+
if (!i)
|
|
308
469
|
return Promise.resolve(null);
|
|
309
|
-
for (const
|
|
310
|
-
(s =
|
|
311
|
-
return
|
|
312
|
-
if (Array.isArray(
|
|
313
|
-
const a =
|
|
314
|
-
|
|
470
|
+
for (const o of j)
|
|
471
|
+
(s = o.onBeforeGetLODMesh) == null || s.call(o, e, t);
|
|
472
|
+
return e["LOD:requested level"] = t, M.getOrLoadLOD(r, t).then((o) => {
|
|
473
|
+
if (Array.isArray(o)) {
|
|
474
|
+
const a = i.index || 0;
|
|
475
|
+
o = o[a];
|
|
315
476
|
}
|
|
316
|
-
return
|
|
317
|
-
}).catch((
|
|
477
|
+
return e["LOD:requested level"] === t && (delete e["LOD:requested level"], o && r != o && ((o == null ? void 0 : o.isBufferGeometry) ? e.geometry = o : C && console.error("Invalid LOD geometry", o))), o;
|
|
478
|
+
}).catch((o) => (console.error("Error loading mesh LOD", e, o), null));
|
|
318
479
|
} else
|
|
319
|
-
|
|
480
|
+
C && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", e);
|
|
320
481
|
return Promise.resolve(null);
|
|
321
482
|
}
|
|
322
|
-
static assignTextureLOD(
|
|
323
|
-
if (!
|
|
483
|
+
static assignTextureLOD(e, t = 0) {
|
|
484
|
+
if (!e)
|
|
324
485
|
return Promise.resolve(null);
|
|
325
|
-
if (
|
|
326
|
-
const s =
|
|
486
|
+
if (e.isMesh === !0) {
|
|
487
|
+
const s = e;
|
|
327
488
|
if (Array.isArray(s.material)) {
|
|
328
|
-
const
|
|
329
|
-
for (const
|
|
330
|
-
const
|
|
331
|
-
|
|
489
|
+
const r = new Array();
|
|
490
|
+
for (const i of s.material) {
|
|
491
|
+
const o = this.assignTextureLOD(i, t);
|
|
492
|
+
r.push(o);
|
|
332
493
|
}
|
|
333
|
-
return Promise.all(
|
|
334
|
-
const
|
|
335
|
-
for (const a of
|
|
336
|
-
Array.isArray(a) &&
|
|
337
|
-
return
|
|
494
|
+
return Promise.all(r).then((i) => {
|
|
495
|
+
const o = new Array();
|
|
496
|
+
for (const a of i)
|
|
497
|
+
Array.isArray(a) && o.push(...a);
|
|
498
|
+
return o;
|
|
338
499
|
});
|
|
339
500
|
} else
|
|
340
|
-
return this.assignTextureLOD(s.material,
|
|
501
|
+
return this.assignTextureLOD(s.material, t);
|
|
341
502
|
}
|
|
342
|
-
if (
|
|
343
|
-
const s =
|
|
503
|
+
if (e.isMaterial === !0) {
|
|
504
|
+
const s = e, r = [], i = new Array();
|
|
344
505
|
if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
|
|
345
|
-
const
|
|
346
|
-
for (const a of Object.keys(
|
|
347
|
-
const l =
|
|
506
|
+
const o = s;
|
|
507
|
+
for (const a of Object.keys(o.uniforms)) {
|
|
508
|
+
const l = o.uniforms[a].value;
|
|
348
509
|
if ((l == null ? void 0 : l.isTexture) === !0) {
|
|
349
|
-
const
|
|
350
|
-
|
|
510
|
+
const g = this.assignTextureLODForSlot(l, t, s, a).then((u) => (u && o.uniforms[a].value != u && (o.uniforms[a].value = u, o.uniformsNeedUpdate = !0), u));
|
|
511
|
+
r.push(g), i.push(a);
|
|
351
512
|
}
|
|
352
513
|
}
|
|
353
514
|
} else
|
|
354
|
-
for (const
|
|
355
|
-
const a = s[
|
|
515
|
+
for (const o of Object.keys(s)) {
|
|
516
|
+
const a = s[o];
|
|
356
517
|
if ((a == null ? void 0 : a.isTexture) === !0) {
|
|
357
|
-
const l = this.assignTextureLODForSlot(a,
|
|
358
|
-
|
|
518
|
+
const l = this.assignTextureLODForSlot(a, t, s, o);
|
|
519
|
+
r.push(l), i.push(o);
|
|
359
520
|
}
|
|
360
521
|
}
|
|
361
|
-
return Promise.all(
|
|
522
|
+
return Promise.all(r).then((o) => {
|
|
362
523
|
const a = new Array();
|
|
363
|
-
for (let l = 0; l <
|
|
364
|
-
const
|
|
365
|
-
|
|
524
|
+
for (let l = 0; l < o.length; l++) {
|
|
525
|
+
const g = o[l], u = i[l];
|
|
526
|
+
g && g.isTexture === !0 ? a.push({ material: s, slot: u, texture: g, level: t }) : a.push({ material: s, slot: u, texture: null, level: t });
|
|
366
527
|
}
|
|
367
528
|
return a;
|
|
368
529
|
});
|
|
369
530
|
}
|
|
370
|
-
if (
|
|
371
|
-
const s =
|
|
372
|
-
return this.assignTextureLODForSlot(s,
|
|
531
|
+
if (e instanceof se || e.isTexture === !0) {
|
|
532
|
+
const s = e;
|
|
533
|
+
return this.assignTextureLODForSlot(s, t, null, null);
|
|
373
534
|
}
|
|
374
535
|
return Promise.resolve(null);
|
|
375
536
|
}
|
|
376
|
-
static assignTextureLODForSlot(
|
|
377
|
-
return (
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
537
|
+
static assignTextureLODForSlot(e, t, s, r) {
|
|
538
|
+
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : r === "glyphMap" ? Promise.resolve(e) : M.getOrLoadLOD(e, t).then((i) => {
|
|
539
|
+
var o, a;
|
|
540
|
+
if (Array.isArray(i))
|
|
541
|
+
return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."), null;
|
|
542
|
+
if ((i == null ? void 0 : i.isTexture) === !0) {
|
|
543
|
+
if (i != e && s && r) {
|
|
544
|
+
const l = s[r];
|
|
545
|
+
if (l && !C) {
|
|
546
|
+
const g = this.getAssignedLODInformation(l);
|
|
547
|
+
if (g && (g == null ? void 0 : g.level) < t)
|
|
548
|
+
return C === "verbose" && console.warn("Assigned texture level is already higher: ", g.level, t, s, l, i), null;
|
|
549
|
+
}
|
|
550
|
+
if (Bt && i.mipmaps) {
|
|
551
|
+
const g = i.mipmaps.length;
|
|
552
|
+
i.mipmaps.length = Math.min(i.mipmaps.length, 3), g !== i.mipmaps.length && C && console.debug(`Reduced mipmap count from ${g} to ${i.mipmaps.length} for ${i.uuid}: ${(o = i.image) == null ? void 0 : o.width}x${(a = i.image) == null ? void 0 : a.height}.`);
|
|
387
553
|
}
|
|
388
|
-
s[
|
|
554
|
+
s[r] = i;
|
|
389
555
|
}
|
|
390
|
-
return
|
|
556
|
+
return i;
|
|
391
557
|
} else
|
|
392
|
-
|
|
558
|
+
C == "verbose" && console.warn("No LOD found for", e, t);
|
|
393
559
|
return null;
|
|
394
|
-
}).catch((
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
560
|
+
}).catch((i) => (console.error("Error loading LOD", e, i), null));
|
|
561
|
+
}
|
|
562
|
+
// private _isLoadingTexture;
|
|
563
|
+
// loadTexture = (textureIndex: number) => {
|
|
564
|
+
// if (this._isLoadingTexture) return null;
|
|
565
|
+
// const ext = this.parser.json.textures[textureIndex]?.extensions?.[EXTENSION_NAME] as NEEDLE_ext_progressive_texture;
|
|
566
|
+
// if (!ext) return null;
|
|
567
|
+
// this._isLoadingTexture = true;
|
|
568
|
+
// return this.parser.getDependency("texture", textureIndex).then(tex => {
|
|
569
|
+
// this._isLoadingTexture = false;
|
|
570
|
+
// if (tex) {
|
|
571
|
+
// NEEDLE_progressive.registerTexture(this.url, tex as Texture, ext.lods?.length, textureIndex, ext);
|
|
572
|
+
// }
|
|
573
|
+
// return tex;
|
|
574
|
+
// });
|
|
575
|
+
// }
|
|
576
|
+
afterRoot(e) {
|
|
577
|
+
var t, s;
|
|
578
|
+
return C && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((r, i) => {
|
|
579
|
+
var o;
|
|
580
|
+
if (r != null && r.extensions) {
|
|
581
|
+
const a = r == null ? void 0 : r.extensions[U];
|
|
402
582
|
if (a) {
|
|
403
583
|
if (!a.lods) {
|
|
404
|
-
|
|
584
|
+
C && console.warn("Texture has no LODs", a);
|
|
405
585
|
return;
|
|
406
586
|
}
|
|
407
587
|
let l = !1;
|
|
408
|
-
for (const
|
|
409
|
-
if (
|
|
410
|
-
const
|
|
411
|
-
(
|
|
588
|
+
for (const g of this.parser.associations.keys())
|
|
589
|
+
if (g.isTexture === !0) {
|
|
590
|
+
const u = this.parser.associations.get(g);
|
|
591
|
+
(u == null ? void 0 : u.textures) === i && (l = !0, M.registerTexture(this.url, g, (o = a.lods) == null ? void 0 : o.length, i, a));
|
|
412
592
|
}
|
|
413
|
-
l || this.parser.getDependency("texture",
|
|
414
|
-
var
|
|
415
|
-
|
|
593
|
+
l || this.parser.getDependency("texture", i).then((g) => {
|
|
594
|
+
var u;
|
|
595
|
+
g && M.registerTexture(this.url, g, (u = a.lods) == null ? void 0 : u.length, i, a);
|
|
416
596
|
});
|
|
417
597
|
}
|
|
418
598
|
}
|
|
419
|
-
}), (s = this.parser.json.meshes) == null || s.forEach((
|
|
420
|
-
if (
|
|
421
|
-
const
|
|
422
|
-
if (
|
|
599
|
+
}), (s = this.parser.json.meshes) == null || s.forEach((r, i) => {
|
|
600
|
+
if (r != null && r.extensions) {
|
|
601
|
+
const o = r == null ? void 0 : r.extensions[U];
|
|
602
|
+
if (o && o.lods) {
|
|
423
603
|
for (const a of this.parser.associations.keys())
|
|
424
604
|
if (a.isMesh) {
|
|
425
605
|
const l = this.parser.associations.get(a);
|
|
426
|
-
(l == null ? void 0 : l.meshes) ===
|
|
606
|
+
(l == null ? void 0 : l.meshes) === i && M.registerMesh(this.url, o.guid, a, o.lods.length, l.primitives, o);
|
|
427
607
|
}
|
|
428
608
|
}
|
|
429
609
|
}
|
|
430
610
|
}), null;
|
|
431
611
|
}
|
|
432
|
-
static async getOrLoadLOD(
|
|
433
|
-
var
|
|
434
|
-
const s =
|
|
435
|
-
if (!
|
|
436
|
-
return null;
|
|
437
|
-
const
|
|
438
|
-
let
|
|
439
|
-
if (
|
|
440
|
-
const
|
|
441
|
-
|
|
612
|
+
static async getOrLoadLOD(e, t) {
|
|
613
|
+
var l, g, u, p;
|
|
614
|
+
const s = C == "verbose", r = this.getAssignedLODInformation(e);
|
|
615
|
+
if (!r)
|
|
616
|
+
return C && console.warn(`[gltf-progressive] No LOD information found: ${e.name}, uuid: ${e.uuid}, type: ${e.type}`, e), null;
|
|
617
|
+
const i = r == null ? void 0 : r.key;
|
|
618
|
+
let o;
|
|
619
|
+
if (e.isTexture === !0) {
|
|
620
|
+
const w = e;
|
|
621
|
+
w.source && w.source[Se] && (o = w.source[Se]);
|
|
442
622
|
}
|
|
443
|
-
if (
|
|
444
|
-
if (
|
|
445
|
-
let
|
|
446
|
-
const
|
|
447
|
-
if (
|
|
448
|
-
return this.lowresCache.get(
|
|
623
|
+
if (o || (o = M.lodInfos.get(i)), o) {
|
|
624
|
+
if (t > 0) {
|
|
625
|
+
let G = !1;
|
|
626
|
+
const b = Array.isArray(o.lods);
|
|
627
|
+
if (b && t >= o.lods.length ? G = !0 : b || (G = !0), G)
|
|
628
|
+
return this.lowresCache.get(i);
|
|
449
629
|
}
|
|
450
|
-
const
|
|
451
|
-
if (!
|
|
452
|
-
return
|
|
453
|
-
const
|
|
454
|
-
if (
|
|
455
|
-
if (!
|
|
456
|
-
return console.warn("missing pointer for glb/gltf texture",
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
459
|
-
s && console.log(`LOD ${
|
|
460
|
-
let
|
|
461
|
-
`,
|
|
462
|
-
if (
|
|
463
|
-
return
|
|
630
|
+
const w = Array.isArray(o.lods) ? (l = o.lods[t]) == null ? void 0 : l.path : o.lods;
|
|
631
|
+
if (!w)
|
|
632
|
+
return C && !o["missing:uri"] && (o["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, o)), null;
|
|
633
|
+
const y = bt(r.url, w);
|
|
634
|
+
if (y.endsWith(".glb") || y.endsWith(".gltf")) {
|
|
635
|
+
if (!o.guid)
|
|
636
|
+
return console.warn("missing pointer for glb/gltf texture", o), null;
|
|
637
|
+
const G = y + "_" + o.guid, b = await this.queue.slot(y), k = this.previouslyLoaded.get(G);
|
|
638
|
+
if (k !== void 0) {
|
|
639
|
+
s && console.log(`LOD ${t} was already loading/loaded: ${G}`);
|
|
640
|
+
let f = await k.catch((_) => (console.error(`Error loading LOD ${t} from ${y}
|
|
641
|
+
`, _), null)), A = !1;
|
|
642
|
+
if (f == null || (f instanceof se && e instanceof se ? (g = f.image) != null && g.data || (u = f.source) != null && u.data ? f = this.copySettings(e, f) : (A = !0, this.previouslyLoaded.delete(G)) : f instanceof he && e instanceof he && ((p = f.attributes.position) != null && p.array || (A = !0, this.previouslyLoaded.delete(G)))), !A)
|
|
643
|
+
return f;
|
|
464
644
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
645
|
+
if (!b.use)
|
|
646
|
+
return C && console.log(`LOD ${t} was aborted: ${y}`), null;
|
|
647
|
+
const v = o, d = new Promise(async (f, A) => {
|
|
648
|
+
if (Rt) {
|
|
649
|
+
const m = await (await St({})).load(y);
|
|
650
|
+
if (m.textures.length > 0)
|
|
651
|
+
for (const h of m.textures) {
|
|
652
|
+
let I = h.texture;
|
|
653
|
+
return M.assignLODInformation(r.url, I, i, t, void 0), e instanceof se && (I = this.copySettings(e, I)), I && (I.guid = v.guid), f(I);
|
|
654
|
+
}
|
|
655
|
+
if (m.geometries.length > 0) {
|
|
656
|
+
const h = new Array();
|
|
657
|
+
for (const I of m.geometries) {
|
|
658
|
+
const B = I.geometry;
|
|
659
|
+
M.assignLODInformation(r.url, B, i, t, I.primitiveIndex), h.push(B);
|
|
660
|
+
}
|
|
661
|
+
return f(h);
|
|
662
|
+
}
|
|
663
|
+
return f(null);
|
|
664
|
+
}
|
|
665
|
+
const _ = new We();
|
|
666
|
+
Ee(_), C && (await new Promise((Z) => setTimeout(Z, 1e3)), s && console.warn("Start loading (delayed) " + y, v.guid));
|
|
667
|
+
let P = y;
|
|
668
|
+
if (v && Array.isArray(v.lods)) {
|
|
669
|
+
const Z = v.lods[t];
|
|
670
|
+
Z.hash && (P += "?v=" + Z.hash);
|
|
475
671
|
}
|
|
476
|
-
const
|
|
477
|
-
`,
|
|
478
|
-
if (!
|
|
479
|
-
return
|
|
480
|
-
const
|
|
481
|
-
s && console.log("Loading finished " +
|
|
482
|
-
let
|
|
483
|
-
if (
|
|
484
|
-
let
|
|
485
|
-
for (const m of
|
|
672
|
+
const R = await _.loadAsync(P).catch((Z) => (console.error(`Error loading LOD ${t} from ${y}
|
|
673
|
+
`, Z), f(null)));
|
|
674
|
+
if (!R)
|
|
675
|
+
return f(null);
|
|
676
|
+
const te = R.parser;
|
|
677
|
+
s && console.log("Loading finished " + y, v.guid);
|
|
678
|
+
let W = 0;
|
|
679
|
+
if (R.parser.json.textures) {
|
|
680
|
+
let Z = !1;
|
|
681
|
+
for (const m of R.parser.json.textures) {
|
|
486
682
|
if (m != null && m.extensions) {
|
|
487
|
-
const
|
|
488
|
-
if (
|
|
489
|
-
|
|
683
|
+
const h = m == null ? void 0 : m.extensions[U];
|
|
684
|
+
if (h != null && h.guid && h.guid === v.guid) {
|
|
685
|
+
Z = !0;
|
|
490
686
|
break;
|
|
491
687
|
}
|
|
492
688
|
}
|
|
493
|
-
|
|
689
|
+
W++;
|
|
494
690
|
}
|
|
495
|
-
if (
|
|
496
|
-
let m = await
|
|
497
|
-
return m &&
|
|
691
|
+
if (Z) {
|
|
692
|
+
let m = await te.getDependency("texture", W);
|
|
693
|
+
return m && M.assignLODInformation(r.url, m, i, t, void 0), s && console.log('change "' + e.name + '" → "' + m.name + '"', y, W, m, G), e instanceof se && (m = this.copySettings(e, m)), m && (m.guid = v.guid), f(m);
|
|
498
694
|
} else
|
|
499
|
-
|
|
695
|
+
C && console.warn("Could not find texture with guid", v.guid, R.parser.json);
|
|
500
696
|
}
|
|
501
|
-
if (
|
|
502
|
-
let
|
|
503
|
-
for (const m of
|
|
697
|
+
if (W = 0, R.parser.json.meshes) {
|
|
698
|
+
let Z = !1;
|
|
699
|
+
for (const m of R.parser.json.meshes) {
|
|
504
700
|
if (m != null && m.extensions) {
|
|
505
|
-
const
|
|
506
|
-
if (
|
|
507
|
-
|
|
701
|
+
const h = m == null ? void 0 : m.extensions[U];
|
|
702
|
+
if (h != null && h.guid && h.guid === v.guid) {
|
|
703
|
+
Z = !0;
|
|
508
704
|
break;
|
|
509
705
|
}
|
|
510
706
|
}
|
|
511
|
-
|
|
707
|
+
W++;
|
|
512
708
|
}
|
|
513
|
-
if (
|
|
514
|
-
const m = await
|
|
515
|
-
if (s && console.log(`Loaded Mesh "${m.name}"`,
|
|
516
|
-
const
|
|
517
|
-
return
|
|
709
|
+
if (Z) {
|
|
710
|
+
const m = await te.getDependency("mesh", W);
|
|
711
|
+
if (s && console.log(`Loaded Mesh "${m.name}"`, y, W, m, G), m.isMesh === !0) {
|
|
712
|
+
const h = m.geometry;
|
|
713
|
+
return M.assignLODInformation(r.url, h, i, t, 0), f(h);
|
|
518
714
|
} else {
|
|
519
|
-
const
|
|
520
|
-
for (let
|
|
521
|
-
const
|
|
522
|
-
if (
|
|
523
|
-
const
|
|
524
|
-
|
|
715
|
+
const h = new Array();
|
|
716
|
+
for (let I = 0; I < m.children.length; I++) {
|
|
717
|
+
const B = m.children[I];
|
|
718
|
+
if (B.isMesh === !0) {
|
|
719
|
+
const V = B.geometry;
|
|
720
|
+
M.assignLODInformation(r.url, V, i, t, I), h.push(V);
|
|
525
721
|
}
|
|
526
722
|
}
|
|
527
|
-
return h
|
|
723
|
+
return f(h);
|
|
528
724
|
}
|
|
529
725
|
} else
|
|
530
|
-
|
|
726
|
+
C && console.warn("Could not find mesh with guid", v.guid, R.parser.json);
|
|
531
727
|
}
|
|
532
|
-
return
|
|
728
|
+
return f(null);
|
|
533
729
|
});
|
|
534
|
-
return this.previouslyLoaded.set(
|
|
535
|
-
} else if (
|
|
536
|
-
s && console.log("Load texture from uri: " +
|
|
537
|
-
const
|
|
538
|
-
return
|
|
730
|
+
return this.previouslyLoaded.set(G, d), b.use(d), await d;
|
|
731
|
+
} else if (e instanceof se) {
|
|
732
|
+
s && console.log("Load texture from uri: " + y);
|
|
733
|
+
const b = await new gt().loadAsync(y);
|
|
734
|
+
return b ? (b.guid = o.guid, b.flipY = !1, b.needsUpdate = !0, b.colorSpace = e.colorSpace, s && console.log(o, b)) : C && console.warn("failed loading", y), b;
|
|
539
735
|
}
|
|
540
736
|
} else
|
|
541
|
-
|
|
737
|
+
C && console.warn(`Can not load LOD ${t}: no LOD info found for "${i}" ${e.name}`, e.type);
|
|
542
738
|
return null;
|
|
543
739
|
}
|
|
544
|
-
static assignLODInformation(
|
|
545
|
-
if (!
|
|
740
|
+
static assignLODInformation(e, t, s, r, i) {
|
|
741
|
+
if (!t)
|
|
546
742
|
return;
|
|
547
|
-
|
|
548
|
-
const
|
|
549
|
-
|
|
743
|
+
t.userData || (t.userData = {});
|
|
744
|
+
const o = new kt(e, s, r, i);
|
|
745
|
+
t.userData.LODS = o, "source" in t && typeof t.source == "object" && (t.source.LODS = o);
|
|
550
746
|
}
|
|
551
|
-
static getAssignedLODInformation(
|
|
552
|
-
var
|
|
553
|
-
return
|
|
747
|
+
static getAssignedLODInformation(e) {
|
|
748
|
+
var t, s;
|
|
749
|
+
return e ? (t = e.userData) != null && t.LODS ? e.userData.LODS : "source" in e && ((s = e.source) != null && s.LODS) ? e.source.LODS : null : null;
|
|
554
750
|
}
|
|
555
751
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
556
|
-
static copySettings(
|
|
557
|
-
return
|
|
558
|
-
`,
|
|
559
|
-
`,
|
|
752
|
+
static copySettings(e, t) {
|
|
753
|
+
return t ? (C === "verbose" && console.debug(`Copy texture settings
|
|
754
|
+
`, e.uuid, `
|
|
755
|
+
`, t.uuid), t = t.clone(), t.offset = e.offset, t.repeat = e.repeat, t.colorSpace = e.colorSpace, t.magFilter = e.magFilter, t.minFilter = e.minFilter, t.wrapS = e.wrapS, t.wrapT = e.wrapT, t.flipY = e.flipY, t.anisotropy = e.anisotropy, t.mipmaps || (t.generateMipmaps = e.generateMipmaps), t) : e;
|
|
560
756
|
}
|
|
561
757
|
};
|
|
562
|
-
let
|
|
758
|
+
let D = M;
|
|
563
759
|
/**
|
|
564
760
|
* Register a texture with LOD information
|
|
565
761
|
*/
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
762
|
+
c(D, "registerTexture", (e, t, s, r, i) => {
|
|
763
|
+
var a, l, g, u, p, w, y, G;
|
|
764
|
+
if (!t) {
|
|
765
|
+
C && console.error("gltf-progressive: Called register texture without texture");
|
|
569
766
|
return;
|
|
570
767
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
768
|
+
if (C) {
|
|
769
|
+
const b = ((a = t.image) == null ? void 0 : a.width) || ((g = (l = t.source) == null ? void 0 : l.data) == null ? void 0 : g.width) || 0, k = ((u = t.image) == null ? void 0 : u.height) || ((w = (p = t.source) == null ? void 0 : p.data) == null ? void 0 : w.height) || 0;
|
|
770
|
+
console.log(`> Progressive: register texture[${r}] "${t.name || t.uuid}", Current: ${b}x${k}, Max: ${(y = i.lods[0]) == null ? void 0 : y.width}x${(G = i.lods[0]) == null ? void 0 : G.height}, uuid: ${t.uuid}`, i, t);
|
|
771
|
+
}
|
|
772
|
+
t.source && (t.source[Se] = i);
|
|
773
|
+
const o = i.guid;
|
|
774
|
+
M.assignLODInformation(e, t, o, s, r), M.lodInfos.set(o, i), M.lowresCache.set(o, t);
|
|
574
775
|
}), /**
|
|
575
776
|
* Register a mesh with LOD information
|
|
576
777
|
*/
|
|
577
|
-
|
|
578
|
-
var
|
|
778
|
+
c(D, "registerMesh", (e, t, s, r, i, o) => {
|
|
779
|
+
var g;
|
|
579
780
|
const a = s.geometry;
|
|
580
781
|
if (!a) {
|
|
581
|
-
|
|
782
|
+
C && console.warn("gltf-progressive: Register mesh without geometry");
|
|
582
783
|
return;
|
|
583
784
|
}
|
|
584
|
-
a.userData || (a.userData = {}),
|
|
585
|
-
let l =
|
|
586
|
-
l ? l.push(s.geometry) : l = [s.geometry],
|
|
587
|
-
for (const
|
|
588
|
-
(
|
|
785
|
+
a.userData || (a.userData = {}), C && console.log("> Progressive: register mesh " + s.name, { index: i, uuid: s.uuid }, o, s), M.assignLODInformation(e, a, t, r, i), M.lodInfos.set(t, o);
|
|
786
|
+
let l = M.lowresCache.get(t);
|
|
787
|
+
l ? l.push(s.geometry) : l = [s.geometry], M.lowresCache.set(t, l), r > 0 && !me(s) && vt(s, a);
|
|
788
|
+
for (const u of j)
|
|
789
|
+
(g = u.onRegisteredNewMesh) == null || g.call(u, s, o);
|
|
589
790
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
class
|
|
594
|
-
constructor(
|
|
595
|
-
|
|
791
|
+
c(D, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
792
|
+
c(D, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
793
|
+
c(D, "lowresCache", /* @__PURE__ */ new Map()), c(D, "workers", []), c(D, "_workersIndex", 0), c(D, "maxConcurrent", 50), c(D, "queue", new xt(M.maxConcurrent, { debug: C != !1 }));
|
|
794
|
+
class kt {
|
|
795
|
+
constructor(e, t, s, r) {
|
|
796
|
+
c(this, "url");
|
|
596
797
|
/** the key to lookup the LOD information */
|
|
597
|
-
|
|
598
|
-
|
|
798
|
+
c(this, "key");
|
|
799
|
+
c(this, "level");
|
|
599
800
|
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
600
|
-
|
|
601
|
-
this.url =
|
|
801
|
+
c(this, "index");
|
|
802
|
+
this.url = e, this.key = t, this.level = s, r != null && (this.index = r);
|
|
602
803
|
}
|
|
603
804
|
}
|
|
604
|
-
class
|
|
605
|
-
constructor(
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
805
|
+
class be {
|
|
806
|
+
constructor(e, t) {
|
|
807
|
+
c(this, "frame_start");
|
|
808
|
+
c(this, "frame_capture_end");
|
|
809
|
+
c(this, "ready");
|
|
810
|
+
c(this, "_resolve");
|
|
811
|
+
c(this, "_signal");
|
|
812
|
+
c(this, "_resolved", !1);
|
|
813
|
+
c(this, "_addedCount", 0);
|
|
814
|
+
c(this, "_resolvedCount", 0);
|
|
614
815
|
/** These promises are currently being awaited */
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
var
|
|
620
|
-
const
|
|
621
|
-
this.frame_start =
|
|
622
|
-
this._resolve =
|
|
816
|
+
c(this, "_awaiting", []);
|
|
817
|
+
c(this, "_maxPromisesPerObject", 1);
|
|
818
|
+
c(this, "_currentFrame", 0);
|
|
819
|
+
c(this, "_seen", /* @__PURE__ */ new WeakMap());
|
|
820
|
+
var i;
|
|
821
|
+
const r = Math.max(t.frames ?? 2, 2);
|
|
822
|
+
this.frame_start = e, this.frame_capture_end = e + r, this.ready = new Promise((o) => {
|
|
823
|
+
this._resolve = o;
|
|
623
824
|
}), this.ready.finally(() => {
|
|
624
825
|
this._resolved = !0, this._awaiting.length = 0;
|
|
625
|
-
}), this._signal =
|
|
826
|
+
}), this._signal = t.signal, (i = this._signal) == null || i.addEventListener("abort", () => {
|
|
626
827
|
this.resolveNow();
|
|
627
|
-
}), this._maxPromisesPerObject = Math.max(1,
|
|
828
|
+
}), this._maxPromisesPerObject = Math.max(1, t.maxPromisesPerObject ?? 1);
|
|
628
829
|
}
|
|
629
830
|
/**
|
|
630
831
|
* The number of promises that have been added to this group so far.
|
|
@@ -638,125 +839,125 @@ class ye {
|
|
|
638
839
|
get currentlyAwaiting() {
|
|
639
840
|
return this._awaiting.length;
|
|
640
841
|
}
|
|
641
|
-
update(
|
|
642
|
-
var
|
|
643
|
-
this._currentFrame =
|
|
842
|
+
update(e) {
|
|
843
|
+
var t;
|
|
844
|
+
this._currentFrame = e, ((t = this._signal) != null && t.aborted || this._currentFrame > this.frame_capture_end && this._awaiting.length === 0) && this.resolveNow();
|
|
644
845
|
}
|
|
645
|
-
add(
|
|
846
|
+
add(e, t, s) {
|
|
646
847
|
if (this._resolved) {
|
|
647
|
-
|
|
848
|
+
C && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
|
|
648
849
|
return;
|
|
649
850
|
}
|
|
650
851
|
if (!(this._currentFrame > this.frame_capture_end)) {
|
|
651
852
|
if (this._maxPromisesPerObject >= 1)
|
|
652
|
-
if (this._seen.has(
|
|
653
|
-
let
|
|
654
|
-
if (
|
|
655
|
-
|
|
853
|
+
if (this._seen.has(t)) {
|
|
854
|
+
let r = this._seen.get(t);
|
|
855
|
+
if (r >= this._maxPromisesPerObject) {
|
|
856
|
+
C && console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");
|
|
656
857
|
return;
|
|
657
858
|
}
|
|
658
|
-
this._seen.set(
|
|
859
|
+
this._seen.set(t, r + 1);
|
|
659
860
|
} else
|
|
660
|
-
this._seen.set(
|
|
861
|
+
this._seen.set(t, 1);
|
|
661
862
|
this._awaiting.push(s), this._addedCount++, s.finally(() => {
|
|
662
863
|
this._resolvedCount++, this._awaiting.splice(this._awaiting.indexOf(s), 1);
|
|
663
864
|
});
|
|
664
865
|
}
|
|
665
866
|
}
|
|
666
867
|
resolveNow() {
|
|
667
|
-
var
|
|
668
|
-
this._resolved || (
|
|
868
|
+
var e, t;
|
|
869
|
+
this._resolved || (t = this._resolve) == null || t.call(this, {
|
|
669
870
|
awaited_count: this._addedCount,
|
|
670
871
|
resolved_count: this._resolvedCount,
|
|
671
|
-
cancelled: ((
|
|
872
|
+
cancelled: ((e = this._signal) == null ? void 0 : e.aborted) ?? !1
|
|
672
873
|
});
|
|
673
874
|
}
|
|
674
875
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
876
|
+
c(be, "addPromise", (e, t, s, r) => {
|
|
877
|
+
r.forEach((i) => {
|
|
878
|
+
i.add(e, t, s);
|
|
678
879
|
});
|
|
679
880
|
});
|
|
680
|
-
const
|
|
681
|
-
var
|
|
682
|
-
const
|
|
881
|
+
const z = ae("debugprogressive"), Vt = ae("noprogressive"), De = Symbol("Needle:LODSManager"), Re = Symbol("Needle:LODState"), Q = Symbol("Needle:CurrentLOD"), T = { mesh_lod: -1, texture_lod: -1 };
|
|
882
|
+
var X, J, Le, ee, le, ve, $;
|
|
883
|
+
const S = class {
|
|
683
884
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
684
|
-
constructor(
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
885
|
+
constructor(e, t) {
|
|
886
|
+
c(this, "renderer");
|
|
887
|
+
c(this, "context");
|
|
888
|
+
c(this, "projectionScreenMatrix", new Ke());
|
|
688
889
|
/**
|
|
689
890
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
690
891
|
* @default 200_000
|
|
691
892
|
*/
|
|
692
|
-
|
|
893
|
+
c(this, "targetTriangleDensity", 2e5);
|
|
693
894
|
/**
|
|
694
895
|
* The interval in frames to automatically update the bounds of skinned meshes.
|
|
695
896
|
* Set to 0 or a negative value to disable automatic bounds updates.
|
|
696
897
|
* @default 30
|
|
697
898
|
*/
|
|
698
|
-
|
|
899
|
+
c(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
|
|
699
900
|
/**
|
|
700
901
|
* 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.
|
|
701
902
|
* @default "auto"
|
|
702
903
|
*/
|
|
703
|
-
|
|
704
|
-
|
|
904
|
+
c(this, "updateInterval", "auto");
|
|
905
|
+
q(this, X, 1);
|
|
705
906
|
/**
|
|
706
907
|
* If set to true, the LODsManager will not update the LODs.
|
|
707
908
|
* @default false
|
|
708
909
|
*/
|
|
709
|
-
|
|
910
|
+
c(this, "pause", !1);
|
|
710
911
|
/**
|
|
711
912
|
* When set to true the LODsManager will not update the LODs. This can be used to manually update the LODs using the `update` method.
|
|
712
913
|
* Otherwise the LODs will be updated automatically when the renderer renders the scene.
|
|
713
914
|
* @default false
|
|
714
915
|
*/
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
916
|
+
c(this, "manual", !1);
|
|
917
|
+
c(this, "_newPromiseGroups", []);
|
|
918
|
+
c(this, "_promiseGroupIds", 0);
|
|
919
|
+
c(this, "_lodchangedlisteners", []);
|
|
920
|
+
q(this, J, void 0);
|
|
921
|
+
q(this, Le, new ct());
|
|
922
|
+
q(this, ee, 0);
|
|
923
|
+
q(this, le, 0);
|
|
924
|
+
q(this, ve, 0);
|
|
925
|
+
q(this, $, 0);
|
|
926
|
+
c(this, "_fpsBuffer", [60, 60, 60, 60, 60]);
|
|
726
927
|
// private testIfLODLevelsAreAvailable() {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
this.renderer =
|
|
928
|
+
c(this, "_sphere", new Ye());
|
|
929
|
+
c(this, "_tempBox", new Be());
|
|
930
|
+
c(this, "_tempBox2", new Be());
|
|
931
|
+
c(this, "tempMatrix", new Ke());
|
|
932
|
+
c(this, "_tempWorldPosition", new N());
|
|
933
|
+
c(this, "_tempBoxSize", new N());
|
|
934
|
+
c(this, "_tempBox2Size", new N());
|
|
935
|
+
this.renderer = e, this.context = { ...t };
|
|
735
936
|
}
|
|
736
937
|
/** @internal */
|
|
737
|
-
static getObjectLODState(
|
|
738
|
-
return
|
|
938
|
+
static getObjectLODState(e) {
|
|
939
|
+
return e[Re];
|
|
739
940
|
}
|
|
740
|
-
static addPlugin(
|
|
741
|
-
j.push(
|
|
941
|
+
static addPlugin(e) {
|
|
942
|
+
j.push(e);
|
|
742
943
|
}
|
|
743
|
-
static removePlugin(
|
|
744
|
-
const
|
|
745
|
-
|
|
944
|
+
static removePlugin(e) {
|
|
945
|
+
const t = j.indexOf(e);
|
|
946
|
+
t >= 0 && j.splice(t, 1);
|
|
746
947
|
}
|
|
747
948
|
/**
|
|
748
949
|
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
749
950
|
* @param renderer The renderer to get the LODsManager for.
|
|
750
951
|
* @returns The LODsManager instance.
|
|
751
952
|
*/
|
|
752
|
-
static get(
|
|
753
|
-
if (
|
|
754
|
-
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),
|
|
755
|
-
const s = new
|
|
953
|
+
static get(e, t) {
|
|
954
|
+
if (e[De])
|
|
955
|
+
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), e[De];
|
|
956
|
+
const s = new S(e, {
|
|
756
957
|
engine: "unknown",
|
|
757
|
-
...
|
|
958
|
+
...t
|
|
758
959
|
});
|
|
759
|
-
return
|
|
960
|
+
return e[De] = s, s;
|
|
760
961
|
}
|
|
761
962
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
762
963
|
get plugins() {
|
|
@@ -765,29 +966,29 @@ const O = class {
|
|
|
765
966
|
/**
|
|
766
967
|
* Call to await LODs loading during the next render cycle.
|
|
767
968
|
*/
|
|
768
|
-
awaitLoading(
|
|
769
|
-
const
|
|
969
|
+
awaitLoading(e) {
|
|
970
|
+
const t = this._promiseGroupIds++, s = new be(L(this, ee), { ...e });
|
|
770
971
|
this._newPromiseGroups.push(s);
|
|
771
|
-
const
|
|
972
|
+
const r = performance.now();
|
|
772
973
|
return s.ready.finally(() => {
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
start:
|
|
776
|
-
detail: { id:
|
|
974
|
+
const i = this._newPromiseGroups.indexOf(s);
|
|
975
|
+
i >= 0 && (this._newPromiseGroups.splice(i, 1), Pe() && performance.measure("LODsManager:awaitLoading", {
|
|
976
|
+
start: r,
|
|
977
|
+
detail: { id: t, name: e == null ? void 0 : e.name, awaited: s.awaitedCount, resolved: s.resolvedCount }
|
|
777
978
|
}));
|
|
778
979
|
}), s.ready;
|
|
779
980
|
}
|
|
780
981
|
_postprocessPromiseGroups() {
|
|
781
982
|
if (this._newPromiseGroups.length !== 0)
|
|
782
|
-
for (let
|
|
783
|
-
this._newPromiseGroups[
|
|
983
|
+
for (let e = this._newPromiseGroups.length - 1; e >= 0; e--)
|
|
984
|
+
this._newPromiseGroups[e].update(L(this, ee));
|
|
784
985
|
}
|
|
785
|
-
addEventListener(
|
|
786
|
-
|
|
986
|
+
addEventListener(e, t) {
|
|
987
|
+
e === "changed" && this._lodchangedlisteners.push(t);
|
|
787
988
|
}
|
|
788
|
-
removeEventListener(
|
|
789
|
-
if (
|
|
790
|
-
const s = this._lodchangedlisteners.indexOf(
|
|
989
|
+
removeEventListener(e, t) {
|
|
990
|
+
if (e === "changed") {
|
|
991
|
+
const s = this._lodchangedlisteners.indexOf(t);
|
|
791
992
|
s >= 0 && this._lodchangedlisteners.splice(s, 1);
|
|
792
993
|
}
|
|
793
994
|
}
|
|
@@ -795,54 +996,54 @@ const O = class {
|
|
|
795
996
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
796
997
|
*/
|
|
797
998
|
enable() {
|
|
798
|
-
if (
|
|
999
|
+
if (L(this, J))
|
|
799
1000
|
return;
|
|
800
1001
|
console.debug("[gltf-progressive] Enabling LODsManager for renderer");
|
|
801
|
-
let
|
|
802
|
-
|
|
803
|
-
const
|
|
804
|
-
|
|
805
|
-
const
|
|
806
|
-
(
|
|
807
|
-
const
|
|
808
|
-
|
|
1002
|
+
let e = 0;
|
|
1003
|
+
E(this, J, this.renderer.render);
|
|
1004
|
+
const t = this;
|
|
1005
|
+
Te(this.renderer), this.renderer.render = function(s, r) {
|
|
1006
|
+
const i = t.renderer.getRenderTarget();
|
|
1007
|
+
(i == null || "isXRRenderTarget" in i && i.isXRRenderTarget) && (e = 0, E(t, ee, L(t, ee) + 1), E(t, le, L(t, Le).getDelta()), E(t, ve, L(t, ve) + L(t, le)), t._fpsBuffer.shift(), t._fpsBuffer.push(1 / L(t, le)), E(t, $, t._fpsBuffer.reduce((a, l) => a + l) / t._fpsBuffer.length), z && L(t, ee) % 200 === 0 && console.log("FPS", Math.round(L(t, $)), "Interval:", L(t, X)));
|
|
1008
|
+
const o = e++;
|
|
1009
|
+
L(t, J).call(this, s, r), t.onAfterRender(s, r, o);
|
|
809
1010
|
};
|
|
810
1011
|
}
|
|
811
1012
|
disable() {
|
|
812
|
-
|
|
1013
|
+
L(this, J) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = L(this, J), E(this, J, void 0));
|
|
813
1014
|
}
|
|
814
|
-
update(
|
|
815
|
-
this.internalUpdate(
|
|
1015
|
+
update(e, t) {
|
|
1016
|
+
this.internalUpdate(e, t);
|
|
816
1017
|
}
|
|
817
|
-
onAfterRender(
|
|
1018
|
+
onAfterRender(e, t, s) {
|
|
818
1019
|
if (this.pause)
|
|
819
1020
|
return;
|
|
820
|
-
const
|
|
821
|
-
let
|
|
822
|
-
if (
|
|
823
|
-
const a =
|
|
824
|
-
(a.name === "EffectMaterial" || a.name === "CopyShader") && (
|
|
1021
|
+
const i = this.renderer.renderLists.get(e, 0).opaque;
|
|
1022
|
+
let o = !0;
|
|
1023
|
+
if (i.length === 1) {
|
|
1024
|
+
const a = i[0].material;
|
|
1025
|
+
(a.name === "EffectMaterial" || a.name === "CopyShader") && (o = !1);
|
|
825
1026
|
}
|
|
826
|
-
if ((
|
|
827
|
-
if (
|
|
1027
|
+
if ((t.parent && t.parent.type === "CubeCamera" || s >= 1 && t.type === "OrthographicCamera") && (o = !1), o) {
|
|
1028
|
+
if (Vt || (this.updateInterval === "auto" ? L(this, $) < 40 && L(this, X) < 10 ? (E(this, X, L(this, X) + 1), z && console.warn("↓ Reducing LOD updates", L(this, X), L(this, $).toFixed(0))) : L(this, $) >= 60 && L(this, X) > 1 && (E(this, X, L(this, X) - 1), z && console.warn("↑ Increasing LOD updates", L(this, X), L(this, $).toFixed(0))) : E(this, X, this.updateInterval), L(this, X) > 0 && L(this, ee) % L(this, X) != 0))
|
|
828
1029
|
return;
|
|
829
|
-
this.internalUpdate(
|
|
1030
|
+
this.internalUpdate(e, t), this._postprocessPromiseGroups();
|
|
830
1031
|
}
|
|
831
1032
|
}
|
|
832
1033
|
/**
|
|
833
1034
|
* Update LODs in a scene
|
|
834
1035
|
*/
|
|
835
|
-
internalUpdate(
|
|
836
|
-
var l,
|
|
837
|
-
const s = this.renderer.renderLists.get(
|
|
838
|
-
this.projectionScreenMatrix.multiplyMatrices(
|
|
839
|
-
const
|
|
840
|
-
for (const
|
|
841
|
-
if (
|
|
842
|
-
|
|
1036
|
+
internalUpdate(e, t) {
|
|
1037
|
+
var l, g;
|
|
1038
|
+
const s = this.renderer.renderLists.get(e, 0), r = s.opaque;
|
|
1039
|
+
this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse);
|
|
1040
|
+
const i = this.targetTriangleDensity;
|
|
1041
|
+
for (const u of r) {
|
|
1042
|
+
if (u.material && (((l = u.geometry) == null ? void 0 : l.type) === "BoxGeometry" || ((g = u.geometry) == null ? void 0 : g.type) === "BufferGeometry") && (u.material.name === "SphericalGaussianBlur" || u.material.name == "BackgroundCubeMaterial" || u.material.name === "CubemapFromEquirect" || u.material.name === "EquirectangularToCubeUV")) {
|
|
1043
|
+
z && (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)));
|
|
843
1044
|
continue;
|
|
844
1045
|
}
|
|
845
|
-
switch (
|
|
1046
|
+
switch (u.material.type) {
|
|
846
1047
|
case "LineBasicMaterial":
|
|
847
1048
|
case "LineDashedMaterial":
|
|
848
1049
|
case "PointsMaterial":
|
|
@@ -851,62 +1052,60 @@ const O = class {
|
|
|
851
1052
|
case "MeshDepthMaterial":
|
|
852
1053
|
continue;
|
|
853
1054
|
}
|
|
854
|
-
if (
|
|
855
|
-
|
|
856
|
-
const
|
|
857
|
-
|
|
1055
|
+
if (z === "color" && u.material && !u.object.progressive_debug_color) {
|
|
1056
|
+
u.object.progressive_debug_color = !0;
|
|
1057
|
+
const w = Math.random() * 16777215, y = new dt({ color: w });
|
|
1058
|
+
u.object.material = y;
|
|
858
1059
|
}
|
|
859
|
-
const p =
|
|
860
|
-
(p instanceof
|
|
1060
|
+
const p = u.object;
|
|
1061
|
+
(p instanceof oe || p.isMesh) && this.updateLODs(e, t, p, i);
|
|
861
1062
|
}
|
|
862
|
-
const
|
|
863
|
-
for (const
|
|
864
|
-
const p =
|
|
865
|
-
(p instanceof
|
|
1063
|
+
const o = s.transparent;
|
|
1064
|
+
for (const u of o) {
|
|
1065
|
+
const p = u.object;
|
|
1066
|
+
(p instanceof oe || p.isMesh) && this.updateLODs(e, t, p, i);
|
|
866
1067
|
}
|
|
867
1068
|
const a = s.transmissive;
|
|
868
|
-
for (const
|
|
869
|
-
const p =
|
|
870
|
-
(p instanceof
|
|
1069
|
+
for (const u of a) {
|
|
1070
|
+
const p = u.object;
|
|
1071
|
+
(p instanceof oe || p.isMesh) && this.updateLODs(e, t, p, i);
|
|
871
1072
|
}
|
|
872
1073
|
}
|
|
873
1074
|
/** Update the LOD levels for the renderer. */
|
|
874
|
-
updateLODs(
|
|
1075
|
+
updateLODs(e, t, s, r) {
|
|
875
1076
|
var a, l;
|
|
876
1077
|
s.userData || (s.userData = {});
|
|
877
|
-
let
|
|
878
|
-
if (
|
|
1078
|
+
let i = s[Re];
|
|
1079
|
+
if (i || (i = new Ot(), s[Re] = i), i.frames++ < 2)
|
|
879
1080
|
return;
|
|
880
|
-
for (const
|
|
881
|
-
(a =
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
for (const
|
|
885
|
-
(l =
|
|
886
|
-
|
|
1081
|
+
for (const g of j)
|
|
1082
|
+
(a = g.onBeforeUpdateLOD) == null || a.call(g, this.renderer, e, t, s);
|
|
1083
|
+
const o = S.overrideGlobalLodLevel !== void 0 ? S.overrideGlobalLodLevel : ie;
|
|
1084
|
+
o >= 0 ? (T.mesh_lod = o, T.texture_lod = o) : (this.calculateLodLevel(t, s, i, r, T), T.mesh_lod = Math.round(T.mesh_lod), T.texture_lod = Math.round(T.texture_lod)), T.mesh_lod >= 0 && this.loadProgressiveMeshes(s, T.mesh_lod), s.material && T.texture_lod >= 0 && this.loadProgressiveTextures(s.material, T.texture_lod, o), C && s.material && !s.isGizmo && qe(s.material);
|
|
1085
|
+
for (const g of j)
|
|
1086
|
+
(l = g.onAfterUpdatedLOD) == null || l.call(g, this.renderer, e, t, s, T);
|
|
1087
|
+
i.lastLodLevel_Mesh = T.mesh_lod, i.lastLodLevel_Texture = T.texture_lod;
|
|
887
1088
|
}
|
|
888
1089
|
/** Load progressive textures for the given material
|
|
889
1090
|
* @param material the material to load the textures for
|
|
890
1091
|
* @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
|
|
891
1092
|
* @returns Promise with true if the LOD was loaded, false if not
|
|
892
1093
|
*/
|
|
893
|
-
loadProgressiveTextures(t,
|
|
894
|
-
if (!
|
|
1094
|
+
loadProgressiveTextures(e, t, s) {
|
|
1095
|
+
if (!e)
|
|
895
1096
|
return;
|
|
896
|
-
if (Array.isArray(
|
|
897
|
-
for (const
|
|
898
|
-
this.loadProgressiveTextures(
|
|
1097
|
+
if (Array.isArray(e)) {
|
|
1098
|
+
for (const i of e)
|
|
1099
|
+
this.loadProgressiveTextures(i, t);
|
|
899
1100
|
return;
|
|
900
1101
|
}
|
|
901
|
-
let
|
|
902
|
-
(
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
const r = P.assignTextureLOD(t, e).then((i) => {
|
|
907
|
-
this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: e, object: t }));
|
|
1102
|
+
let r = !1;
|
|
1103
|
+
if ((e[Q] === void 0 || t < e[Q]) && (r = !0), s !== void 0 && s >= 0 && (r = e[Q] != s, t = s), r) {
|
|
1104
|
+
e[Q] = t;
|
|
1105
|
+
const i = D.assignTextureLOD(e, t).then((o) => {
|
|
1106
|
+
this._lodchangedlisteners.forEach((a) => a({ type: "texture", level: t, object: e }));
|
|
908
1107
|
});
|
|
909
|
-
|
|
1108
|
+
be.addPromise("texture", e, i, this._newPromiseGroups);
|
|
910
1109
|
}
|
|
911
1110
|
}
|
|
912
1111
|
/** Load progressive meshes for the given mesh
|
|
@@ -915,336 +1114,341 @@ const O = class {
|
|
|
915
1114
|
* @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
|
|
916
1115
|
* @returns Promise with true if the LOD was loaded, false if not
|
|
917
1116
|
*/
|
|
918
|
-
loadProgressiveMeshes(
|
|
919
|
-
if (!
|
|
1117
|
+
loadProgressiveMeshes(e, t) {
|
|
1118
|
+
if (!e)
|
|
920
1119
|
return Promise.resolve(null);
|
|
921
|
-
let s =
|
|
922
|
-
const
|
|
923
|
-
if (
|
|
924
|
-
|
|
925
|
-
const
|
|
926
|
-
return
|
|
1120
|
+
let s = e[Q] !== t;
|
|
1121
|
+
const r = e["DEBUG:LOD"];
|
|
1122
|
+
if (r != null && (s = e[Q] != r, t = r), s) {
|
|
1123
|
+
e[Q] = t;
|
|
1124
|
+
const i = e.geometry, o = D.assignMeshLOD(e, t).then((a) => (a && e[Q] == t && i != e.geometry && this._lodchangedlisteners.forEach((l) => l({ type: "mesh", level: t, object: e })), a));
|
|
1125
|
+
return be.addPromise("mesh", e, o, this._newPromiseGroups), o;
|
|
927
1126
|
}
|
|
928
1127
|
return Promise.resolve(null);
|
|
929
1128
|
}
|
|
930
|
-
static isInside(
|
|
931
|
-
const s =
|
|
932
|
-
return this._tempPtInside.set(
|
|
1129
|
+
static isInside(e, t) {
|
|
1130
|
+
const s = e.min, r = e.max, i = (s.x + r.x) * 0.5, o = (s.y + r.y) * 0.5;
|
|
1131
|
+
return this._tempPtInside.set(i, o, s.z).applyMatrix4(t).z < 0;
|
|
933
1132
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1133
|
+
// #region calculateLodLevel
|
|
1134
|
+
calculateLodLevel(e, t, s, r, i) {
|
|
1135
|
+
var k, v, d, x;
|
|
1136
|
+
if (!t) {
|
|
1137
|
+
i.mesh_lod = -1, i.texture_lod = -1;
|
|
938
1138
|
return;
|
|
939
1139
|
}
|
|
940
|
-
if (!
|
|
941
|
-
|
|
1140
|
+
if (!e) {
|
|
1141
|
+
i.mesh_lod = -1, i.texture_lod = -1;
|
|
942
1142
|
return;
|
|
943
1143
|
}
|
|
944
1144
|
let a = 10 + 1, l = !1;
|
|
945
|
-
if (
|
|
946
|
-
return
|
|
947
|
-
const
|
|
948
|
-
if (!p && !
|
|
949
|
-
|
|
1145
|
+
if (z && t["DEBUG:LOD"] != null)
|
|
1146
|
+
return t["DEBUG:LOD"];
|
|
1147
|
+
const g = (k = D.getMeshLODExtension(t.geometry)) == null ? void 0 : k.lods, u = D.getPrimitiveIndex(t.geometry), p = g && g.length > 0, w = D.getMaterialMinMaxLODsCount(t.material), y = w.min_count !== 1 / 0 && w.min_count >= 0 && w.max_count >= 0;
|
|
1148
|
+
if (!p && !y) {
|
|
1149
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
950
1150
|
return;
|
|
951
1151
|
}
|
|
952
1152
|
p || (l = !0, a = 0);
|
|
953
|
-
const
|
|
954
|
-
let
|
|
955
|
-
if (
|
|
956
|
-
const
|
|
957
|
-
if (!
|
|
958
|
-
|
|
1153
|
+
const G = this.renderer.domElement.clientHeight || this.renderer.domElement.height;
|
|
1154
|
+
let b = t.geometry.boundingBox;
|
|
1155
|
+
if (t.type === "SkinnedMesh") {
|
|
1156
|
+
const f = t;
|
|
1157
|
+
if (!f.boundingBox)
|
|
1158
|
+
f.computeBoundingBox();
|
|
959
1159
|
else if (this.skinnedMeshAutoUpdateBoundsInterval > 0) {
|
|
960
|
-
if (!
|
|
961
|
-
const
|
|
962
|
-
|
|
1160
|
+
if (!f[S.$skinnedMeshBoundsOffset]) {
|
|
1161
|
+
const _ = S.skinnedMeshBoundsFrameOffsetCounter++;
|
|
1162
|
+
f[S.$skinnedMeshBoundsOffset] = _;
|
|
963
1163
|
}
|
|
964
|
-
const
|
|
965
|
-
if ((s.frames +
|
|
966
|
-
const
|
|
967
|
-
|
|
1164
|
+
const A = f[S.$skinnedMeshBoundsOffset];
|
|
1165
|
+
if ((s.frames + A) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
|
|
1166
|
+
const _ = me(f), P = f.geometry;
|
|
1167
|
+
_ && (f.geometry = _), f.computeBoundingBox(), f.geometry = P;
|
|
968
1168
|
}
|
|
969
1169
|
}
|
|
970
|
-
|
|
1170
|
+
b = f.boundingBox;
|
|
971
1171
|
}
|
|
972
|
-
if (
|
|
973
|
-
const
|
|
974
|
-
if (
|
|
975
|
-
this._sphere.copy(
|
|
976
|
-
const
|
|
977
|
-
if (this._sphere.containsPoint(
|
|
978
|
-
|
|
1172
|
+
if (b) {
|
|
1173
|
+
const f = e;
|
|
1174
|
+
if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
|
|
1175
|
+
this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
|
|
1176
|
+
const h = e.getWorldPosition(this._tempWorldPosition);
|
|
1177
|
+
if (this._sphere.containsPoint(h)) {
|
|
1178
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
979
1179
|
return;
|
|
980
1180
|
}
|
|
981
1181
|
}
|
|
982
|
-
if (this._tempBox.copy(
|
|
983
|
-
|
|
1182
|
+
if (this._tempBox.copy(b), this._tempBox.applyMatrix4(t.matrixWorld), f.isPerspectiveCamera && S.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
1183
|
+
i.mesh_lod = 0, i.texture_lod = 0;
|
|
984
1184
|
return;
|
|
985
1185
|
}
|
|
986
|
-
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled &&
|
|
987
|
-
const
|
|
988
|
-
let
|
|
989
|
-
const
|
|
990
|
-
|
|
991
|
-
const
|
|
992
|
-
s.lastCentrality = (
|
|
1186
|
+
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && f.isPerspectiveCamera && f.fov > 70) {
|
|
1187
|
+
const h = this._tempBox.min, I = this._tempBox.max;
|
|
1188
|
+
let B = h.x, V = h.y, F = I.x, ge = I.y;
|
|
1189
|
+
const pe = 2, Ge = 1.5, Ie = (h.x + I.x) * 0.5, Ce = (h.y + I.y) * 0.5;
|
|
1190
|
+
B = (B - Ie) * pe + Ie, V = (V - Ce) * pe + Ce, F = (F - Ie) * pe + Ie, ge = (ge - Ce) * pe + Ce;
|
|
1191
|
+
const et = B < 0 && F > 0 ? 0 : Math.min(Math.abs(h.x), Math.abs(I.x)), tt = V < 0 && ge > 0 ? 0 : Math.min(Math.abs(h.y), Math.abs(I.y)), Ze = Math.max(et, tt);
|
|
1192
|
+
s.lastCentrality = (Ge - Ze) * (Ge - Ze) * (Ge - Ze);
|
|
993
1193
|
} else
|
|
994
1194
|
s.lastCentrality = 1;
|
|
995
|
-
const
|
|
996
|
-
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
const
|
|
1000
|
-
if (Math.max(
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1195
|
+
const A = this._tempBox.getSize(this._tempBoxSize);
|
|
1196
|
+
A.multiplyScalar(0.5), screen.availHeight > 0 && G > 0 && A.multiplyScalar(G / screen.availHeight), e.isPerspectiveCamera ? A.x *= e.aspect : e.isOrthographicCamera;
|
|
1197
|
+
const _ = e.matrixWorldInverse, P = this._tempBox2;
|
|
1198
|
+
P.copy(b), P.applyMatrix4(t.matrixWorld), P.applyMatrix4(_);
|
|
1199
|
+
const R = P.getSize(this._tempBox2Size), te = Math.max(R.x, R.y);
|
|
1200
|
+
if (Math.max(A.x, A.y) != 0 && te != 0 && (A.z = R.z / Math.max(R.x, R.y) * Math.max(A.x, A.y)), s.lastScreenCoverage = Math.max(A.x, A.y, A.z), s.lastScreenspaceVolume.copy(A), s.lastScreenCoverage *= s.lastCentrality, z && S.debugDrawLine) {
|
|
1201
|
+
const h = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
1202
|
+
h.invert();
|
|
1203
|
+
const I = S.corner0, B = S.corner1, V = S.corner2, F = S.corner3;
|
|
1204
|
+
I.copy(this._tempBox.min), B.copy(this._tempBox.max), B.x = I.x, V.copy(this._tempBox.max), V.y = I.y, F.copy(this._tempBox.max);
|
|
1205
|
+
const ge = (I.z + F.z) * 0.5;
|
|
1206
|
+
I.z = B.z = V.z = F.z = ge, I.applyMatrix4(h), B.applyMatrix4(h), V.applyMatrix4(h), F.applyMatrix4(h), S.debugDrawLine(I, B, 255), S.debugDrawLine(I, V, 255), S.debugDrawLine(B, F, 255), S.debugDrawLine(V, F, 255);
|
|
1007
1207
|
}
|
|
1008
|
-
let
|
|
1009
|
-
if (
|
|
1010
|
-
for (let
|
|
1011
|
-
const
|
|
1012
|
-
if ((
|
|
1013
|
-
|
|
1208
|
+
let Z = 999;
|
|
1209
|
+
if (g && s.lastScreenCoverage > 0)
|
|
1210
|
+
for (let h = 0; h < g.length; h++) {
|
|
1211
|
+
const I = g[h], V = (((v = I.densities) == null ? void 0 : v[u]) || I.density || 1e-5) / s.lastScreenCoverage;
|
|
1212
|
+
if (u > 0 && Pe() && !I.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.")), V < r) {
|
|
1213
|
+
Z = h;
|
|
1014
1214
|
break;
|
|
1015
1215
|
}
|
|
1016
1216
|
}
|
|
1017
|
-
|
|
1217
|
+
Z < a && (a = Z, l = !0);
|
|
1018
1218
|
}
|
|
1019
|
-
if (l ?
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1219
|
+
if (l ? i.mesh_lod = a : i.mesh_lod = s.lastLodLevel_Mesh, z && i.mesh_lod != s.lastLodLevel_Mesh) {
|
|
1220
|
+
const A = g == null ? void 0 : g[i.mesh_lod];
|
|
1221
|
+
A && console.debug(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${i.mesh_lod} (density: ${(d = A.densities) == null ? void 0 : d[u].toFixed(0)}) | ${t.name}`);
|
|
1022
1222
|
}
|
|
1023
|
-
if (
|
|
1024
|
-
const
|
|
1223
|
+
if (y) {
|
|
1224
|
+
const f = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
1025
1225
|
if (s.lastLodLevel_Texture < 0) {
|
|
1026
|
-
if (
|
|
1027
|
-
const
|
|
1028
|
-
|
|
1226
|
+
if (i.texture_lod = w.max_count - 1, z) {
|
|
1227
|
+
const A = w.lods[w.max_count - 1];
|
|
1228
|
+
z && console.log(`First Texture LOD ${i.texture_lod} (${A.max_height}px) - ${t.name}`);
|
|
1029
1229
|
}
|
|
1030
1230
|
} else {
|
|
1031
|
-
const
|
|
1032
|
-
let
|
|
1033
|
-
((
|
|
1034
|
-
const
|
|
1035
|
-
let
|
|
1036
|
-
for (let
|
|
1037
|
-
const
|
|
1038
|
-
if (!(
|
|
1039
|
-
if (
|
|
1040
|
-
const m =
|
|
1041
|
-
|
|
1042
|
-
Screensize: ${
|
|
1043
|
-
${
|
|
1231
|
+
const A = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
1232
|
+
let _ = s.lastScreenCoverage * 4;
|
|
1233
|
+
((x = this.context) == null ? void 0 : x.engine) === "model-viewer" && (_ *= 1.5);
|
|
1234
|
+
const R = G / window.devicePixelRatio * _;
|
|
1235
|
+
let te = !1;
|
|
1236
|
+
for (let W = w.lods.length - 1; W >= 0; W--) {
|
|
1237
|
+
const Z = w.lods[W];
|
|
1238
|
+
if (!(f && Z.max_height >= 2048) && !($e() && Z.max_height > 4096) && (Z.max_height > R || !te && W === 0)) {
|
|
1239
|
+
if (te = !0, i.texture_lod = W, z && i.texture_lod < s.lastLodLevel_Texture) {
|
|
1240
|
+
const m = Z.max_height;
|
|
1241
|
+
console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${i.texture_lod} = ${m}px
|
|
1242
|
+
Screensize: ${R.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${A.toFixed(1)}
|
|
1243
|
+
${t.name}`);
|
|
1044
1244
|
}
|
|
1045
1245
|
break;
|
|
1046
1246
|
}
|
|
1047
1247
|
}
|
|
1048
1248
|
}
|
|
1049
1249
|
} else
|
|
1050
|
-
|
|
1250
|
+
i.texture_lod = 0;
|
|
1051
1251
|
}
|
|
1052
1252
|
};
|
|
1053
|
-
let
|
|
1054
|
-
|
|
1253
|
+
let O = S;
|
|
1254
|
+
X = new WeakMap(), J = new WeakMap(), Le = new WeakMap(), ee = new WeakMap(), le = new WeakMap(), ve = new WeakMap(), $ = new WeakMap(), /**
|
|
1055
1255
|
* 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.
|
|
1056
1256
|
*/
|
|
1057
|
-
|
|
1257
|
+
c(O, "debugDrawLine"), /**
|
|
1058
1258
|
* Force override the LOD level for all objects in the scene
|
|
1059
1259
|
*/
|
|
1060
|
-
|
|
1061
|
-
class
|
|
1260
|
+
c(O, "overrideGlobalLodLevel"), c(O, "corner0", new N()), c(O, "corner1", new N()), c(O, "corner2", new N()), c(O, "corner3", new N()), c(O, "_tempPtInside", new N()), c(O, "skinnedMeshBoundsFrameOffsetCounter", 0), c(O, "$skinnedMeshBoundsOffset", Symbol("gltf-progressive-skinnedMeshBoundsOffset"));
|
|
1261
|
+
class Ot {
|
|
1062
1262
|
constructor() {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1263
|
+
c(this, "frames", 0);
|
|
1264
|
+
c(this, "lastLodLevel_Mesh", -1);
|
|
1265
|
+
c(this, "lastLodLevel_Texture", -1);
|
|
1266
|
+
c(this, "lastScreenCoverage", 0);
|
|
1267
|
+
c(this, "lastScreenspaceVolume", new N());
|
|
1268
|
+
c(this, "lastCentrality", 0);
|
|
1069
1269
|
}
|
|
1070
1270
|
}
|
|
1071
|
-
const
|
|
1072
|
-
let
|
|
1073
|
-
function
|
|
1074
|
-
const
|
|
1075
|
-
|
|
1076
|
-
return
|
|
1077
|
-
}),
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" &&
|
|
1271
|
+
const Ne = Symbol("NEEDLE_mesh_lod"), ye = Symbol("NEEDLE_texture_lod");
|
|
1272
|
+
let fe = null;
|
|
1273
|
+
function Qe() {
|
|
1274
|
+
const n = Wt();
|
|
1275
|
+
n && (n.mapURLs(function(e) {
|
|
1276
|
+
return ze(), e;
|
|
1277
|
+
}), ze(), fe == null || fe.disconnect(), fe = new MutationObserver((e) => {
|
|
1278
|
+
e.forEach((t) => {
|
|
1279
|
+
t.addedNodes.forEach((s) => {
|
|
1280
|
+
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && je(s);
|
|
1081
1281
|
});
|
|
1082
1282
|
});
|
|
1083
|
-
}),
|
|
1283
|
+
}), fe.observe(document, { childList: !0, subtree: !0 }));
|
|
1084
1284
|
}
|
|
1085
|
-
function
|
|
1285
|
+
function Wt() {
|
|
1086
1286
|
if (typeof customElements > "u")
|
|
1087
1287
|
return null;
|
|
1088
|
-
const
|
|
1089
|
-
return
|
|
1090
|
-
console.debug("[gltf-progressive] model-viewer defined"),
|
|
1288
|
+
const n = customElements.get("model-viewer");
|
|
1289
|
+
return n || (customElements.whenDefined("model-viewer").then(() => {
|
|
1290
|
+
console.debug("[gltf-progressive] model-viewer defined"), Qe();
|
|
1091
1291
|
}), null);
|
|
1092
1292
|
}
|
|
1093
|
-
function
|
|
1293
|
+
function ze() {
|
|
1094
1294
|
if (typeof document > "u")
|
|
1095
1295
|
return;
|
|
1096
|
-
document.querySelectorAll("model-viewer").forEach((
|
|
1097
|
-
|
|
1296
|
+
document.querySelectorAll("model-viewer").forEach((e) => {
|
|
1297
|
+
je(e);
|
|
1098
1298
|
});
|
|
1099
1299
|
}
|
|
1100
|
-
const
|
|
1101
|
-
let
|
|
1102
|
-
function
|
|
1103
|
-
if (!
|
|
1300
|
+
const He = /* @__PURE__ */ new WeakSet();
|
|
1301
|
+
let Tt = 0;
|
|
1302
|
+
function je(n) {
|
|
1303
|
+
if (!n || He.has(n))
|
|
1104
1304
|
return null;
|
|
1105
|
-
|
|
1106
|
-
`,
|
|
1107
|
-
let
|
|
1108
|
-
for (let
|
|
1109
|
-
const
|
|
1110
|
-
!
|
|
1111
|
-
}
|
|
1112
|
-
if (
|
|
1113
|
-
let
|
|
1305
|
+
He.add(n), console.debug("[gltf-progressive] found new model-viewer..." + ++Tt + `
|
|
1306
|
+
`, n.getAttribute("src"));
|
|
1307
|
+
let e = null, t = null, s = null;
|
|
1308
|
+
for (let r = n; r != null; r = Object.getPrototypeOf(r)) {
|
|
1309
|
+
const i = Object.getOwnPropertySymbols(r), o = i.find((g) => g.toString() == "Symbol(renderer)"), a = i.find((g) => g.toString() == "Symbol(scene)"), l = i.find((g) => g.toString() == "Symbol(needsRender)");
|
|
1310
|
+
!e && o != null && (e = n[o].threeRenderer), !t && a != null && (t = n[a]), !s && l != null && (s = n[l]);
|
|
1311
|
+
}
|
|
1312
|
+
if (e && t) {
|
|
1313
|
+
let r = function() {
|
|
1114
1314
|
if (s) {
|
|
1115
|
-
let
|
|
1116
|
-
if (
|
|
1315
|
+
let o = 0, a = setInterval(() => {
|
|
1316
|
+
if (o++ > 5) {
|
|
1117
1317
|
clearInterval(a);
|
|
1118
1318
|
return;
|
|
1119
1319
|
}
|
|
1120
|
-
s == null || s.call(
|
|
1320
|
+
s == null || s.call(n);
|
|
1121
1321
|
}, 300);
|
|
1122
1322
|
}
|
|
1123
1323
|
};
|
|
1124
1324
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
1125
|
-
const
|
|
1126
|
-
return
|
|
1127
|
-
s == null || s.call(
|
|
1128
|
-
}),
|
|
1129
|
-
|
|
1130
|
-
}),
|
|
1131
|
-
|
|
1325
|
+
const i = O.get(e, { engine: "model-viewer" });
|
|
1326
|
+
return O.addPlugin(new Xt()), i.enable(), i.addEventListener("changed", () => {
|
|
1327
|
+
s == null || s.call(n);
|
|
1328
|
+
}), n.addEventListener("model-visibility", (o) => {
|
|
1329
|
+
o.detail.visible && (s == null || s.call(n));
|
|
1330
|
+
}), n.addEventListener("load", () => {
|
|
1331
|
+
r();
|
|
1132
1332
|
}), () => {
|
|
1133
|
-
|
|
1333
|
+
i.disable();
|
|
1134
1334
|
};
|
|
1135
1335
|
}
|
|
1136
1336
|
return null;
|
|
1137
1337
|
}
|
|
1138
|
-
class
|
|
1338
|
+
class Xt {
|
|
1139
1339
|
constructor() {
|
|
1140
|
-
|
|
1340
|
+
c(this, "_didWarnAboutMissingUrl", !1);
|
|
1141
1341
|
}
|
|
1142
|
-
onBeforeUpdateLOD(
|
|
1143
|
-
this.tryParseMeshLOD(
|
|
1342
|
+
onBeforeUpdateLOD(e, t, s, r) {
|
|
1343
|
+
this.tryParseMeshLOD(t, r), this.tryParseTextureLOD(t, r);
|
|
1144
1344
|
}
|
|
1145
|
-
getUrl(
|
|
1146
|
-
if (!
|
|
1345
|
+
getUrl(e) {
|
|
1346
|
+
if (!e)
|
|
1147
1347
|
return null;
|
|
1148
|
-
let
|
|
1149
|
-
return
|
|
1348
|
+
let t = e.getAttribute("src");
|
|
1349
|
+
return t || (t = e.src), t || (this._didWarnAboutMissingUrl || console.warn("No url found in modelviewer", e), this._didWarnAboutMissingUrl = !0), t;
|
|
1150
1350
|
}
|
|
1151
|
-
tryGetCurrentGLTF(
|
|
1152
|
-
return
|
|
1351
|
+
tryGetCurrentGLTF(e) {
|
|
1352
|
+
return e._currentGLTF;
|
|
1153
1353
|
}
|
|
1154
|
-
tryGetCurrentModelViewer(
|
|
1155
|
-
return
|
|
1354
|
+
tryGetCurrentModelViewer(e) {
|
|
1355
|
+
return e.element;
|
|
1156
1356
|
}
|
|
1157
|
-
tryParseTextureLOD(
|
|
1158
|
-
if (
|
|
1357
|
+
tryParseTextureLOD(e, t) {
|
|
1358
|
+
if (t[ye] == !0)
|
|
1159
1359
|
return;
|
|
1160
|
-
|
|
1161
|
-
const s = this.tryGetCurrentGLTF(
|
|
1162
|
-
if (
|
|
1163
|
-
let
|
|
1164
|
-
var
|
|
1165
|
-
if (l[
|
|
1360
|
+
t[ye] = !0;
|
|
1361
|
+
const s = this.tryGetCurrentGLTF(e), r = this.tryGetCurrentModelViewer(e), i = this.getUrl(r);
|
|
1362
|
+
if (i && s && t.material) {
|
|
1363
|
+
let o = function(l) {
|
|
1364
|
+
var u, p, w;
|
|
1365
|
+
if (l[ye] == !0)
|
|
1166
1366
|
return;
|
|
1167
|
-
l[
|
|
1168
|
-
const
|
|
1169
|
-
for (let
|
|
1170
|
-
const
|
|
1171
|
-
if ((
|
|
1172
|
-
const
|
|
1173
|
-
if (
|
|
1367
|
+
l[ye] = !0, l.userData && (l.userData.LOD = -1);
|
|
1368
|
+
const g = Object.keys(l);
|
|
1369
|
+
for (let y = 0; y < g.length; y++) {
|
|
1370
|
+
const G = g[y], b = l[G];
|
|
1371
|
+
if ((b == null ? void 0 : b.isTexture) === !0) {
|
|
1372
|
+
const k = (p = (u = b.userData) == null ? void 0 : u.associations) == null ? void 0 : p.textures;
|
|
1373
|
+
if (k == null)
|
|
1174
1374
|
continue;
|
|
1175
|
-
const
|
|
1176
|
-
if (!
|
|
1177
|
-
console.warn("Texture data not found for texture index " +
|
|
1375
|
+
const v = s.parser.json.textures[k];
|
|
1376
|
+
if (!v) {
|
|
1377
|
+
console.warn("Texture data not found for texture index " + k);
|
|
1178
1378
|
continue;
|
|
1179
1379
|
}
|
|
1180
|
-
if ((
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1380
|
+
if ((w = v == null ? void 0 : v.extensions) != null && w[U]) {
|
|
1381
|
+
const d = v.extensions[U];
|
|
1382
|
+
d && i && D.registerTexture(i, b, d.lods.length, k, d);
|
|
1183
1383
|
}
|
|
1184
1384
|
}
|
|
1185
1385
|
}
|
|
1186
1386
|
};
|
|
1187
|
-
const a =
|
|
1387
|
+
const a = t.material;
|
|
1188
1388
|
if (Array.isArray(a))
|
|
1189
1389
|
for (const l of a)
|
|
1190
|
-
|
|
1390
|
+
o(l);
|
|
1191
1391
|
else
|
|
1192
|
-
|
|
1392
|
+
o(a);
|
|
1193
1393
|
}
|
|
1194
1394
|
}
|
|
1195
|
-
tryParseMeshLOD(
|
|
1196
|
-
var
|
|
1197
|
-
if (
|
|
1395
|
+
tryParseMeshLOD(e, t) {
|
|
1396
|
+
var o, a;
|
|
1397
|
+
if (t[Ne] == !0)
|
|
1198
1398
|
return;
|
|
1199
|
-
|
|
1200
|
-
const s = this.tryGetCurrentModelViewer(
|
|
1201
|
-
if (!
|
|
1399
|
+
t[Ne] = !0;
|
|
1400
|
+
const s = this.tryGetCurrentModelViewer(e), r = this.getUrl(s);
|
|
1401
|
+
if (!r)
|
|
1202
1402
|
return;
|
|
1203
|
-
const
|
|
1204
|
-
if (
|
|
1205
|
-
const l =
|
|
1206
|
-
|
|
1403
|
+
const i = (a = (o = t.userData) == null ? void 0 : o.gltfExtensions) == null ? void 0 : a[U];
|
|
1404
|
+
if (i && r) {
|
|
1405
|
+
const l = t.uuid;
|
|
1406
|
+
D.registerMesh(r, l, t, 0, i.lods.length, i);
|
|
1207
1407
|
}
|
|
1208
1408
|
}
|
|
1209
1409
|
}
|
|
1210
|
-
function
|
|
1211
|
-
|
|
1410
|
+
function Kt(n, e, t, s) {
|
|
1411
|
+
Te(e), Ee(t), Je(t, {
|
|
1212
1412
|
progressive: !0,
|
|
1213
1413
|
...s == null ? void 0 : s.hints
|
|
1214
|
-
}),
|
|
1215
|
-
const
|
|
1216
|
-
return (s == null ? void 0 : s.enableLODsManager) !== !1 &&
|
|
1414
|
+
}), t.register((i) => new D(i, n));
|
|
1415
|
+
const r = O.get(e);
|
|
1416
|
+
return (s == null ? void 0 : s.enableLODsManager) !== !1 && r.enable(), r;
|
|
1217
1417
|
}
|
|
1218
|
-
|
|
1219
|
-
if (!
|
|
1220
|
-
const
|
|
1418
|
+
Qe();
|
|
1419
|
+
if (!Lt) {
|
|
1420
|
+
const n = {
|
|
1221
1421
|
gltfProgressive: {
|
|
1222
|
-
useNeedleProgressive:
|
|
1223
|
-
LODsManager:
|
|
1224
|
-
configureLoader:
|
|
1225
|
-
getRaycastMesh:
|
|
1226
|
-
useRaycastMeshes:
|
|
1422
|
+
useNeedleProgressive: Kt,
|
|
1423
|
+
LODsManager: O,
|
|
1424
|
+
configureLoader: Je,
|
|
1425
|
+
getRaycastMesh: me,
|
|
1426
|
+
useRaycastMeshes: Gt
|
|
1227
1427
|
}
|
|
1228
1428
|
};
|
|
1229
1429
|
if (!globalThis.Needle)
|
|
1230
|
-
globalThis.Needle =
|
|
1430
|
+
globalThis.Needle = n;
|
|
1231
1431
|
else
|
|
1232
|
-
for (const
|
|
1233
|
-
globalThis.Needle[
|
|
1432
|
+
for (const e in n)
|
|
1433
|
+
globalThis.Needle[e] = n[e];
|
|
1234
1434
|
}
|
|
1435
|
+
const Pt = "data:application/javascript;base64,Ly8gaW1wb3J0IHsgR0xURkxvYWRlciB9IGZyb20gImh0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9ucG0vdGhyZWVAMC4xNzkuMS9leGFtcGxlcy9qc20vbG9hZGVycy9HTFRGTG9hZGVyLmpzIjsKCi8qKiBAdHMtaWdub3JlICovCmltcG9ydCB7IEdMVEZMb2FkZXIgfSBmcm9tICJodHRwczovL2VzbS5zaC90aHJlZUAwLjE2OC4wL2V4YW1wbGVzL2pzbS9sb2FkZXJzL0dMVEZMb2FkZXIuanMiOwovKiogQHRzLWlnbm9yZSAqLwppbXBvcnQgeyBNZXNob3B0RGVjb2RlciB9IGZyb20gJ2h0dHBzOi8vZXNtLnNoL3RocmVlQDAuMTY4LjAvZXhhbXBsZXMvanNtL2xpYnMvbWVzaG9wdF9kZWNvZGVyLm1vZHVsZS5qcyc7Ci8qKiBAdHMtaWdub3JlICovCmltcG9ydCB7IERSQUNPTG9hZGVyIH0gZnJvbSAnaHR0cHM6Ly9lc20uc2gvdGhyZWVAMC4xNjguMC9leGFtcGxlcy9qc20vbG9hZGVycy9EUkFDT0xvYWRlci5qcyc7Ci8qKiBAdHMtaWdub3JlICovCmltcG9ydCB7IEtUWDJMb2FkZXIgfSBmcm9tICdodHRwczovL2VzbS5zaC90aHJlZUAwLjE2OC4wL2V4YW1wbGVzL2pzbS9sb2FkZXJzL0tUWDJMb2FkZXIuanMnOwoKCmxldCBkZWJ1ZyA9IGZhbHNlOwoKCi8qKiAKICogQHR5cGVkZWYge2ltcG9ydCgiLi9sb2FkZXIubWFpbnRocmVhZCIpLkdMVEZMb2FkZXJXb3JrZXJfTWVzc2FnZX0gR0xURkxvYWRlcldvcmtlcl9NZXNzYWdlIAogKiovCgpzZWxmLm9ubWVzc2FnZSA9IChtc2cpID0+IHsKICAgIC8qKiBAdHlwZSB7R0xURkxvYWRlcldvcmtlcl9NZXNzYWdlfSAqLwogICAgY29uc3QgcmVxdWVzdCA9IG1zZy5kYXRhOwoKICAgIHN3aXRjaCAocmVxdWVzdC50eXBlKSB7CiAgICAgICAgY2FzZSAiaW5pdCI6CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgImxvYWQiOgogICAgICAgICAgICBsb2FkR0xURihyZXF1ZXN0KTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgY29uc29sZS5lcnJvcigiW1dvcmtlcl0gVW5rbm93biBtZXNzYWdlIHR5cGU6IiwgcmVxdWVzdC50eXBlKTsKICAgICAgICAgICAgYnJlYWs7CiAgICB9Cn07CgpzZWxmLm9uZXJyb3IgPSAoZXJyb3IpID0+IHsKICAgIGNvbnNvbGUuZXJyb3IoIltXb3JrZXJdIEVycm9yOiIsIGVycm9yKTsKfTsKCi8qKgogKiBAcGFyYW0ge0dMVEZMb2FkZXJXb3JrZXJfTWVzc2FnZX0gZGF0YQogKi8KZnVuY3Rpb24gcG9zdE1lc3NhZ2UoZGF0YSkgewogICAgc2VsZi5wb3N0TWVzc2FnZShkYXRhKTsKfQoKLyoqIEB0eXBlIHtHTFRGTG9hZGVyIHwgbnVsbH0gKi8KbGV0IGxvYWRlciA9IG51bGw7CgovKiogQHR5cGUge0RSQUNPTG9hZGVyIHwgbnVsbH0gKi8KbGV0IGRyYWNvTG9hZGVyID0gbnVsbDsKCi8qKiBAdHlwZSB7S1RYMkxvYWRlciB8IG51bGwgfSAqLwpsZXQga3R4MkxvYWRlciA9IG51bGw7CgovKioKICogQHBhcmFtIHtHTFRGTG9hZGVyV29ya2VyX01lc3NhZ2UgJiB7IHR5cGU6ICJsb2FkIn19IHJlcQogKi8KYXN5bmMgZnVuY3Rpb24gbG9hZEdMVEYocmVxKSB7CiAgICBpZihkZWJ1ZykgY29uc29sZS5kZWJ1ZygiW1dvcmtlcl0gTG9hZGluZyBHTFRGIGZyb20gVVJMOiIsIHJlcS5kcmFjb0RlY29kZXJQYXRoKTsKCiAgICBsb2FkZXIgPz89IG5ldyBHTFRGTG9hZGVyKCk7CgogICAgbG9hZGVyLnNldE1lc2hvcHREZWNvZGVyKE1lc2hvcHREZWNvZGVyKTsKCiAgICBkcmFjb0xvYWRlciA/Pz0gbmV3IERSQUNPTG9hZGVyKCk7CiAgICBkcmFjb0xvYWRlci5zZXREZWNvZGVyQ29uZmlnKHsgdHlwZTogJ2pzJyB9KTsKICAgIGRyYWNvTG9hZGVyLnNldERlY29kZXJQYXRoKHJlcS5kcmFjb0RlY29kZXJQYXRoKTsKICAgIGxvYWRlci5zZXREUkFDT0xvYWRlcihkcmFjb0xvYWRlcik7CgogICAga3R4MkxvYWRlciA/Pz0gbmV3IEtUWDJMb2FkZXIoKTsKICAgIGt0eDJMb2FkZXIud29ya2VyQ29uZmlnID0gcmVxLmt0eDJMb2FkZXJDb25maWc7CiAgICBrdHgyTG9hZGVyLnNldFRyYW5zY29kZXJQYXRoKHJlcS5rdHgyVHJhbnNjb2RlclBhdGgpOwogICAgbG9hZGVyLnNldEtUWDJMb2FkZXIoa3R4MkxvYWRlcik7CgoKICAgIGxvYWRlci5sb2FkKHJlcS51cmwsIGdsdGYgPT4gewogICAgICAgIGlmKGRlYnVnKSBjb25zb2xlLmxvZygiTG9hZGVkIiwgcmVxLnVybCwgZ2x0Zik7CgogICAgICAgIC8qKiBAdHlwZSB7R0xURkxvYWRlcldvcmtlcl9NZXNzYWdlICYgeyB0eXBlOiAibG9hZGVkLWdsdGYifX0gKi8KICAgICAgICBjb25zdCBkYXRhID0gewogICAgICAgICAgICB0eXBlOiAibG9hZGVkLWdsdGYiLAogICAgICAgICAgICByZXN1bHQ6IHsKICAgICAgICAgICAgICAgIHVybDogcmVxLnVybCwKICAgICAgICAgICAgICAgIGdlb21ldHJpZXM6IFtdLAogICAgICAgICAgICAgICAgdGV4dHVyZXM6IFtdLAogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbGxlY3REYXRhKGdsdGYsIGRhdGEpOwogICAgICAgIHBvc3RNZXNzYWdlKGRhdGEpOwogICAgfSk7Cn0KCgovKiogCiAqIEBwYXJhbSB7aW1wb3J0KCJ0aHJlZS9leGFtcGxlcy9qc20vbG9hZGVycy9HTFRGTG9hZGVyIikuR0xURn0gZ2x0ZiAKICogQHBhcmFtIHtHTFRGTG9hZGVyV29ya2VyX01lc3NhZ2UgJiB7IHR5cGU6ICJsb2FkZWQtZ2x0ZiJ9fSBkYXRhCiAqKi8KZnVuY3Rpb24gY29sbGVjdERhdGEoZ2x0ZiwgZGF0YSkgewoKICAgIGNvbnN0IHsgcmVzdWx0IH0gPSBkYXRhOwoKICAgIGZvciAoY29uc3Qga2V5IG9mIGdsdGYucGFyc2VyLmFzc29jaWF0aW9ucy5rZXlzKCkpIHsKICAgICAgICBjb25zdCBjYWNoZSA9IGdsdGYucGFyc2VyLmFzc29jaWF0aW9ucy5nZXQoa2V5KTsKCiAgICAgICAgaWYgKCFjYWNoZSkgewogICAgICAgICAgICBpZihkZWJ1ZykgY29uc29sZS53YXJuKCJbV29ya2VyXSBObyBjYWNoZSBmb3VuZCBmb3Iga2V5OiIsIGtleSk7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KCiAgICAgICAgaWYgKCJpc1RleHR1cmUiIGluIGtleSAmJiBrZXkuaXNUZXh0dXJlKSB7CiAgICAgICAgICAgIGNvbnN0IHRleHR1cmUgPSAvKiogQHR5cGUge2ltcG9ydCgidGhyZWUiKS5UZXh0dXJlfSAqLyAoIC8qKiBAdHlwZSB7dW5rbm93bn0gKi8gKGtleSkpOwogICAgICAgICAgICBjb25zdCBnbHRmX3RleHR1cmUgPSBnbHRmLnBhcnNlci5qc29uLnRleHR1cmVzW2NhY2hlLnRleHR1cmVzID8/IC0xXTsKICAgICAgICAgICAgcmVzdWx0LnRleHR1cmVzLnB1c2goewogICAgICAgICAgICAgICAgdGV4dHVyZTogdGV4dHVyZSwKICAgICAgICAgICAgICAgIHRleHR1cmVJbmRleDogY2FjaGUudGV4dHVyZXMgPz8gLTEsCiAgICAgICAgICAgICAgICBleHRlbnNpb25zOiBnbHRmX3RleHR1cmU/LmV4dGVuc2lvbnMgPz8ge30sCiAgICAgICAgICAgIH0pCiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKCJpc01lc2giIGluIGtleSAmJiBrZXkuaXNNZXNoKSB7CiAgICAgICAgICAgIGNvbnN0IG1lc2ggPSAvKiogQHR5cGUge2ltcG9ydCgidGhyZWUiKS5NZXNofSAqLyAoIC8qKiBAdHlwZSB7dW5rbm93bn0gKi8gKGtleSkpOwogICAgICAgICAgICBjb25zdCBtZXNoSW5kZXggPSBjYWNoZS5tZXNoZXMgPz8gLTE7CiAgICAgICAgICAgIGNvbnN0IHByaW1pdGl2ZUluZGV4ID0gY2FjaGUucHJpbWl0aXZlcyA/PyAtMTsKICAgICAgICAgICAgY29uc3QgZ2x0Zl9tZXNoID0gZ2x0Zi5wYXJzZXIuanNvbi5tZXNoZXNbbWVzaEluZGV4XTsKICAgICAgICAgICAgcmVzdWx0Lmdlb21ldHJpZXMucHVzaCh7CiAgICAgICAgICAgICAgICBnZW9tZXRyeTogbWVzaC5nZW9tZXRyeSwKICAgICAgICAgICAgICAgIG1lc2hJbmRleDogbWVzaEluZGV4LAogICAgICAgICAgICAgICAgcHJpbWl0aXZlSW5kZXg6IHByaW1pdGl2ZUluZGV4LAogICAgICAgICAgICAgICAgZXh0ZW5zaW9uczogZ2x0Zl9tZXNoPy5leHRlbnNpb25zID8/IHt9LAogICAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoImlzTWF0ZXJpYWwiIGluIGtleSAmJiBrZXkuaXNNYXRlcmlhbCkgewogICAgICAgICAgICAvLyBOb3RoaW5nIHdlIG5lZWQgdG8gZG8gaGVyZQogICAgICAgIH0KICAgIH0KfQoKLy8gZnVuY3Rpb24gdHJhdmVyc2VBbmREZWxldGVGdW5jdGlvbnMoZ2x0ZikgewovLyAgICAgY29uc3QgdGV4dHVyZXMgPSBbXTsKLy8gICAgIGdsdGYudHJhdmVyc2UoKGNoaWxkKSA9PiB7Ci8vICAgICAgICAgaWYgKGNoaWxkLmlzTWVzaCkgewovLyAgICAgICAgICAgICBnZW9tZXRyaWVzLnB1c2goY2hpbGQuZ2VvbWV0cnkpOwovLyAgICAgICAgICAgICBpZiAoY2hpbGQubWF0ZXJpYWwpIHsKLy8gICAgICAgICAgICAgICAgIGlmIChjaGlsZC5tYXRlcmlhbC5tYXApIHsKLy8gICAgICAgICAgICAgICAgICAgICB0ZXh0dXJlcy5wdXNoKGNoaWxkLm1hdGVyaWFsLm1hcCk7Ci8vICAgICAgICAgICAgICAgICB9Ci8vICAgICAgICAgICAgIH0KLy8gICAgICAgICB9Ci8vICAgICB9KTsKLy8gICAgIHJldHVybiB7Ci8vICAgICAgICAgZ2VvbWV0cmllczogZ2VvbWV0cmllcywKLy8gICAgICAgICB0ZXh0dXJlczogdGV4dHVyZXMsCi8vICAgICB9Ci8vIH0KCi8vIGZ1bmN0aW9uIHRyYXZlcnNlQW5kRGVsZXRlRnVuY3Rpb25zKG9iaiwgc2VlbiA9IG5ldyBXZWFrU2V0KCkpIHsKLy8gICAgIGlmIChzZWVuLmhhcyhvYmopKSByZXR1cm47Ci8vICAgICBzZWVuLmFkZChvYmopOwoKLy8gICAgIGZvciAoY29uc3Qga2V5IGluIG9iaikgewovLyAgICAgICAgIGlmICh0eXBlb2Ygb2JqW2tleV0gPT09ICJmdW5jdGlvbiIpIHsKLy8gICAgICAgICAgICAgZGVsZXRlIG9ialtrZXldOwovLyAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIG9ialtrZXldID09PSAib2JqZWN0IiAmJiBvYmpba2V5XSAhPT0gbnVsbCkgewovLyAgICAgICAgICAgICB0cmF2ZXJzZUFuZERlbGV0ZUZ1bmN0aW9ucyhvYmpba2V5XSwgc2Vlbik7Ci8vICAgICAgICAgfQovLyAgICAgfQovLyAgICAgcmV0dXJuIG9iajsKLy8gfQ==", Nt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1436
|
+
__proto__: null,
|
|
1437
|
+
default: Pt
|
|
1438
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1235
1439
|
export {
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1440
|
+
U as EXTENSION_NAME,
|
|
1441
|
+
O as LODsManager,
|
|
1442
|
+
D as NEEDLE_progressive,
|
|
1443
|
+
mt as VERSION,
|
|
1444
|
+
Ee as addDracoAndKTX2Loaders,
|
|
1445
|
+
Je as configureLoader,
|
|
1446
|
+
Te as createLoaders,
|
|
1447
|
+
me as getRaycastMesh,
|
|
1448
|
+
Qe as patchModelViewer,
|
|
1449
|
+
vt as registerRaycastMesh,
|
|
1450
|
+
yt as setDracoDecoderLocation,
|
|
1451
|
+
At as setKTX2TranscoderLocation,
|
|
1452
|
+
Kt as useNeedleProgressive,
|
|
1453
|
+
Gt as useRaycastMeshes
|
|
1250
1454
|
};
|