@needle-tools/gltf-progressive 3.1.0-next.f550970 → 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 +966 -781
- 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 +62 -9
- package/lib/loaders.d.ts +8 -0
- package/lib/loaders.js +33 -22
- package/lib/lods.manager.js +20 -11
- package/lib/utils.internal.d.ts +4 -5
- 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 +1 -1
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 L = (
|
|
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
|
|
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
22
|
Fe.searchParams.append("range", "true");
|
|
23
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 Ne() {
|
|
42
|
-
k || (k = new st(), k[Pe] = q, k.setDecoderPath(q), k.setDecoderConfig({ type: "js" }), k.preload()), N || (N = new rt(), N.setTranscoderPath(re), N.init()), xe || (xe = tt);
|
|
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 Me =
|
|
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]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${
|
|
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"), O = 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,100 +459,105 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), O = 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((
|
|
560
|
+
}).catch((i) => (console.error("Error loading LOD", e, i), null));
|
|
395
561
|
}
|
|
396
562
|
// private _isLoadingTexture;
|
|
397
563
|
// loadTexture = (textureIndex: number) => {
|
|
@@ -407,243 +573,259 @@ const X = "NEEDLE_progressive", Oe = Symbol("needle-progressive-texture"), O = c
|
|
|
407
573
|
// return tex;
|
|
408
574
|
// });
|
|
409
575
|
// }
|
|
410
|
-
afterRoot(
|
|
411
|
-
var
|
|
412
|
-
return
|
|
413
|
-
var
|
|
414
|
-
if (
|
|
415
|
-
const a =
|
|
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];
|
|
416
582
|
if (a) {
|
|
417
583
|
if (!a.lods) {
|
|
418
|
-
|
|
584
|
+
C && console.warn("Texture has no LODs", a);
|
|
419
585
|
return;
|
|
420
586
|
}
|
|
421
587
|
let l = !1;
|
|
422
|
-
for (const
|
|
423
|
-
if (
|
|
424
|
-
const
|
|
425
|
-
(
|
|
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));
|
|
426
592
|
}
|
|
427
|
-
l || this.parser.getDependency("texture",
|
|
428
|
-
var
|
|
429
|
-
|
|
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);
|
|
430
596
|
});
|
|
431
597
|
}
|
|
432
598
|
}
|
|
433
|
-
}), (s = this.parser.json.meshes) == null || s.forEach((
|
|
434
|
-
if (
|
|
435
|
-
const
|
|
436
|
-
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) {
|
|
437
603
|
for (const a of this.parser.associations.keys())
|
|
438
604
|
if (a.isMesh) {
|
|
439
605
|
const l = this.parser.associations.get(a);
|
|
440
|
-
(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);
|
|
441
607
|
}
|
|
442
608
|
}
|
|
443
609
|
}
|
|
444
610
|
}), null;
|
|
445
611
|
}
|
|
446
|
-
static async getOrLoadLOD(
|
|
447
|
-
var
|
|
448
|
-
const s =
|
|
449
|
-
if (!
|
|
450
|
-
return
|
|
451
|
-
const
|
|
452
|
-
let
|
|
453
|
-
if (
|
|
454
|
-
const
|
|
455
|
-
|
|
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]);
|
|
456
622
|
}
|
|
457
|
-
if (
|
|
458
|
-
if (
|
|
459
|
-
let
|
|
460
|
-
const
|
|
461
|
-
if (
|
|
462
|
-
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);
|
|
463
629
|
}
|
|
464
|
-
const
|
|
465
|
-
if (!
|
|
466
|
-
return
|
|
467
|
-
const
|
|
468
|
-
if (
|
|
469
|
-
if (!
|
|
470
|
-
return console.warn("missing pointer for glb/gltf texture",
|
|
471
|
-
const
|
|
472
|
-
if (
|
|
473
|
-
s && console.log(`LOD ${
|
|
474
|
-
let
|
|
475
|
-
`,
|
|
476
|
-
if (
|
|
477
|
-
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;
|
|
478
644
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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);
|
|
489
671
|
}
|
|
490
|
-
const
|
|
491
|
-
`,
|
|
492
|
-
if (!
|
|
493
|
-
return
|
|
494
|
-
const
|
|
495
|
-
s && console.log("Loading finished " +
|
|
496
|
-
let
|
|
497
|
-
if (
|
|
498
|
-
let
|
|
499
|
-
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) {
|
|
500
682
|
if (m != null && m.extensions) {
|
|
501
|
-
const
|
|
502
|
-
if (
|
|
503
|
-
|
|
683
|
+
const h = m == null ? void 0 : m.extensions[U];
|
|
684
|
+
if (h != null && h.guid && h.guid === v.guid) {
|
|
685
|
+
Z = !0;
|
|
504
686
|
break;
|
|
505
687
|
}
|
|
506
688
|
}
|
|
507
|
-
|
|
689
|
+
W++;
|
|
508
690
|
}
|
|
509
|
-
if (
|
|
510
|
-
let m = await
|
|
511
|
-
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);
|
|
512
694
|
} else
|
|
513
|
-
|
|
695
|
+
C && console.warn("Could not find texture with guid", v.guid, R.parser.json);
|
|
514
696
|
}
|
|
515
|
-
if (
|
|
516
|
-
let
|
|
517
|
-
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) {
|
|
518
700
|
if (m != null && m.extensions) {
|
|
519
|
-
const
|
|
520
|
-
if (
|
|
521
|
-
|
|
701
|
+
const h = m == null ? void 0 : m.extensions[U];
|
|
702
|
+
if (h != null && h.guid && h.guid === v.guid) {
|
|
703
|
+
Z = !0;
|
|
522
704
|
break;
|
|
523
705
|
}
|
|
524
706
|
}
|
|
525
|
-
|
|
707
|
+
W++;
|
|
526
708
|
}
|
|
527
|
-
if (
|
|
528
|
-
const m = await
|
|
529
|
-
if (s && console.log(`Loaded Mesh "${m.name}"`,
|
|
530
|
-
const
|
|
531
|
-
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);
|
|
532
714
|
} else {
|
|
533
|
-
const
|
|
534
|
-
for (let
|
|
535
|
-
const
|
|
536
|
-
if (
|
|
537
|
-
const
|
|
538
|
-
|
|
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);
|
|
539
721
|
}
|
|
540
722
|
}
|
|
541
|
-
return
|
|
723
|
+
return f(h);
|
|
542
724
|
}
|
|
543
725
|
} else
|
|
544
|
-
|
|
726
|
+
C && console.warn("Could not find mesh with guid", v.guid, R.parser.json);
|
|
545
727
|
}
|
|
546
|
-
return
|
|
728
|
+
return f(null);
|
|
547
729
|
});
|
|
548
|
-
return this.previouslyLoaded.set(
|
|
549
|
-
} else if (
|
|
550
|
-
s && console.log("Load texture from uri: " +
|
|
551
|
-
const
|
|
552
|
-
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;
|
|
553
735
|
}
|
|
554
736
|
} else
|
|
555
|
-
|
|
737
|
+
C && console.warn(`Can not load LOD ${t}: no LOD info found for "${i}" ${e.name}`, e.type);
|
|
556
738
|
return null;
|
|
557
739
|
}
|
|
558
|
-
static assignLODInformation(
|
|
559
|
-
if (!
|
|
740
|
+
static assignLODInformation(e, t, s, r, i) {
|
|
741
|
+
if (!t)
|
|
560
742
|
return;
|
|
561
|
-
|
|
562
|
-
const
|
|
563
|
-
|
|
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);
|
|
564
746
|
}
|
|
565
|
-
static getAssignedLODInformation(
|
|
566
|
-
var
|
|
567
|
-
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;
|
|
568
750
|
}
|
|
569
751
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
570
|
-
static copySettings(
|
|
571
|
-
return
|
|
572
|
-
`,
|
|
573
|
-
`,
|
|
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;
|
|
574
756
|
}
|
|
575
757
|
};
|
|
576
|
-
let
|
|
758
|
+
let D = M;
|
|
577
759
|
/**
|
|
578
760
|
* Register a texture with LOD information
|
|
579
761
|
*/
|
|
580
|
-
|
|
581
|
-
var a, l,
|
|
582
|
-
if (!
|
|
583
|
-
|
|
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");
|
|
584
766
|
return;
|
|
585
767
|
}
|
|
586
|
-
if (
|
|
587
|
-
const
|
|
588
|
-
console.log(`> Progressive: register texture[${
|
|
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);
|
|
589
771
|
}
|
|
590
|
-
|
|
591
|
-
const
|
|
592
|
-
|
|
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);
|
|
593
775
|
}), /**
|
|
594
776
|
* Register a mesh with LOD information
|
|
595
777
|
*/
|
|
596
|
-
|
|
597
|
-
var
|
|
778
|
+
c(D, "registerMesh", (e, t, s, r, i, o) => {
|
|
779
|
+
var g;
|
|
598
780
|
const a = s.geometry;
|
|
599
781
|
if (!a) {
|
|
600
|
-
|
|
782
|
+
C && console.warn("gltf-progressive: Register mesh without geometry");
|
|
601
783
|
return;
|
|
602
784
|
}
|
|
603
|
-
a.userData || (a.userData = {}),
|
|
604
|
-
let l =
|
|
605
|
-
l ? l.push(s.geometry) : l = [s.geometry],
|
|
606
|
-
for (const
|
|
607
|
-
(
|
|
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);
|
|
608
790
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
class
|
|
613
|
-
constructor(
|
|
614
|
-
|
|
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");
|
|
615
797
|
/** the key to lookup the LOD information */
|
|
616
|
-
|
|
617
|
-
|
|
798
|
+
c(this, "key");
|
|
799
|
+
c(this, "level");
|
|
618
800
|
/** For multi objects (e.g. a group of meshes) this is the index of the object */
|
|
619
|
-
|
|
620
|
-
this.url =
|
|
801
|
+
c(this, "index");
|
|
802
|
+
this.url = e, this.key = t, this.level = s, r != null && (this.index = r);
|
|
621
803
|
}
|
|
622
804
|
}
|
|
623
|
-
class
|
|
624
|
-
constructor(
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
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);
|
|
633
815
|
/** These promises are currently being awaited */
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
var
|
|
639
|
-
const
|
|
640
|
-
this.frame_start =
|
|
641
|
-
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;
|
|
642
824
|
}), this.ready.finally(() => {
|
|
643
825
|
this._resolved = !0, this._awaiting.length = 0;
|
|
644
|
-
}), this._signal =
|
|
826
|
+
}), this._signal = t.signal, (i = this._signal) == null || i.addEventListener("abort", () => {
|
|
645
827
|
this.resolveNow();
|
|
646
|
-
}), this._maxPromisesPerObject = Math.max(1,
|
|
828
|
+
}), this._maxPromisesPerObject = Math.max(1, t.maxPromisesPerObject ?? 1);
|
|
647
829
|
}
|
|
648
830
|
/**
|
|
649
831
|
* The number of promises that have been added to this group so far.
|
|
@@ -657,125 +839,125 @@ class ye {
|
|
|
657
839
|
get currentlyAwaiting() {
|
|
658
840
|
return this._awaiting.length;
|
|
659
841
|
}
|
|
660
|
-
update(
|
|
661
|
-
var
|
|
662
|
-
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();
|
|
663
845
|
}
|
|
664
|
-
add(
|
|
846
|
+
add(e, t, s) {
|
|
665
847
|
if (this._resolved) {
|
|
666
|
-
|
|
848
|
+
C && console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");
|
|
667
849
|
return;
|
|
668
850
|
}
|
|
669
851
|
if (!(this._currentFrame > this.frame_capture_end)) {
|
|
670
852
|
if (this._maxPromisesPerObject >= 1)
|
|
671
|
-
if (this._seen.has(
|
|
672
|
-
let
|
|
673
|
-
if (
|
|
674
|
-
|
|
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.");
|
|
675
857
|
return;
|
|
676
858
|
}
|
|
677
|
-
this._seen.set(
|
|
859
|
+
this._seen.set(t, r + 1);
|
|
678
860
|
} else
|
|
679
|
-
this._seen.set(
|
|
861
|
+
this._seen.set(t, 1);
|
|
680
862
|
this._awaiting.push(s), this._addedCount++, s.finally(() => {
|
|
681
863
|
this._resolvedCount++, this._awaiting.splice(this._awaiting.indexOf(s), 1);
|
|
682
864
|
});
|
|
683
865
|
}
|
|
684
866
|
}
|
|
685
867
|
resolveNow() {
|
|
686
|
-
var
|
|
687
|
-
this._resolved || (
|
|
868
|
+
var e, t;
|
|
869
|
+
this._resolved || (t = this._resolve) == null || t.call(this, {
|
|
688
870
|
awaited_count: this._addedCount,
|
|
689
871
|
resolved_count: this._resolvedCount,
|
|
690
|
-
cancelled: ((
|
|
872
|
+
cancelled: ((e = this._signal) == null ? void 0 : e.aborted) ?? !1
|
|
691
873
|
});
|
|
692
874
|
}
|
|
693
875
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
876
|
+
c(be, "addPromise", (e, t, s, r) => {
|
|
877
|
+
r.forEach((i) => {
|
|
878
|
+
i.add(e, t, s);
|
|
697
879
|
});
|
|
698
880
|
});
|
|
699
|
-
const
|
|
700
|
-
var
|
|
701
|
-
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 {
|
|
702
884
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
703
|
-
constructor(
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
885
|
+
constructor(e, t) {
|
|
886
|
+
c(this, "renderer");
|
|
887
|
+
c(this, "context");
|
|
888
|
+
c(this, "projectionScreenMatrix", new Ke());
|
|
707
889
|
/**
|
|
708
890
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
709
891
|
* @default 200_000
|
|
710
892
|
*/
|
|
711
|
-
|
|
893
|
+
c(this, "targetTriangleDensity", 2e5);
|
|
712
894
|
/**
|
|
713
895
|
* The interval in frames to automatically update the bounds of skinned meshes.
|
|
714
896
|
* Set to 0 or a negative value to disable automatic bounds updates.
|
|
715
897
|
* @default 30
|
|
716
898
|
*/
|
|
717
|
-
|
|
899
|
+
c(this, "skinnedMeshAutoUpdateBoundsInterval", 30);
|
|
718
900
|
/**
|
|
719
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.
|
|
720
902
|
* @default "auto"
|
|
721
903
|
*/
|
|
722
|
-
|
|
723
|
-
|
|
904
|
+
c(this, "updateInterval", "auto");
|
|
905
|
+
q(this, X, 1);
|
|
724
906
|
/**
|
|
725
907
|
* If set to true, the LODsManager will not update the LODs.
|
|
726
908
|
* @default false
|
|
727
909
|
*/
|
|
728
|
-
|
|
910
|
+
c(this, "pause", !1);
|
|
729
911
|
/**
|
|
730
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.
|
|
731
913
|
* Otherwise the LODs will be updated automatically when the renderer renders the scene.
|
|
732
914
|
* @default false
|
|
733
915
|
*/
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
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]);
|
|
745
927
|
// private testIfLODLevelsAreAvailable() {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
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 };
|
|
754
936
|
}
|
|
755
937
|
/** @internal */
|
|
756
|
-
static getObjectLODState(
|
|
757
|
-
return
|
|
938
|
+
static getObjectLODState(e) {
|
|
939
|
+
return e[Re];
|
|
758
940
|
}
|
|
759
|
-
static addPlugin(
|
|
760
|
-
j.push(
|
|
941
|
+
static addPlugin(e) {
|
|
942
|
+
j.push(e);
|
|
761
943
|
}
|
|
762
|
-
static removePlugin(
|
|
763
|
-
const
|
|
764
|
-
|
|
944
|
+
static removePlugin(e) {
|
|
945
|
+
const t = j.indexOf(e);
|
|
946
|
+
t >= 0 && j.splice(t, 1);
|
|
765
947
|
}
|
|
766
948
|
/**
|
|
767
949
|
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
768
950
|
* @param renderer The renderer to get the LODsManager for.
|
|
769
951
|
* @returns The LODsManager instance.
|
|
770
952
|
*/
|
|
771
|
-
static get(
|
|
772
|
-
if (
|
|
773
|
-
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),
|
|
774
|
-
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, {
|
|
775
957
|
engine: "unknown",
|
|
776
|
-
...
|
|
958
|
+
...t
|
|
777
959
|
});
|
|
778
|
-
return
|
|
960
|
+
return e[De] = s, s;
|
|
779
961
|
}
|
|
780
962
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
781
963
|
get plugins() {
|
|
@@ -784,29 +966,29 @@ const b = class {
|
|
|
784
966
|
/**
|
|
785
967
|
* Call to await LODs loading during the next render cycle.
|
|
786
968
|
*/
|
|
787
|
-
awaitLoading(
|
|
788
|
-
const
|
|
969
|
+
awaitLoading(e) {
|
|
970
|
+
const t = this._promiseGroupIds++, s = new be(L(this, ee), { ...e });
|
|
789
971
|
this._newPromiseGroups.push(s);
|
|
790
|
-
const
|
|
972
|
+
const r = performance.now();
|
|
791
973
|
return s.ready.finally(() => {
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
start:
|
|
795
|
-
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 }
|
|
796
978
|
}));
|
|
797
979
|
}), s.ready;
|
|
798
980
|
}
|
|
799
981
|
_postprocessPromiseGroups() {
|
|
800
982
|
if (this._newPromiseGroups.length !== 0)
|
|
801
|
-
for (let
|
|
802
|
-
this._newPromiseGroups[
|
|
983
|
+
for (let e = this._newPromiseGroups.length - 1; e >= 0; e--)
|
|
984
|
+
this._newPromiseGroups[e].update(L(this, ee));
|
|
803
985
|
}
|
|
804
|
-
addEventListener(
|
|
805
|
-
|
|
986
|
+
addEventListener(e, t) {
|
|
987
|
+
e === "changed" && this._lodchangedlisteners.push(t);
|
|
806
988
|
}
|
|
807
|
-
removeEventListener(
|
|
808
|
-
if (
|
|
809
|
-
const s = this._lodchangedlisteners.indexOf(
|
|
989
|
+
removeEventListener(e, t) {
|
|
990
|
+
if (e === "changed") {
|
|
991
|
+
const s = this._lodchangedlisteners.indexOf(t);
|
|
810
992
|
s >= 0 && this._lodchangedlisteners.splice(s, 1);
|
|
811
993
|
}
|
|
812
994
|
}
|
|
@@ -814,54 +996,54 @@ const b = class {
|
|
|
814
996
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
815
997
|
*/
|
|
816
998
|
enable() {
|
|
817
|
-
if (L(this,
|
|
999
|
+
if (L(this, J))
|
|
818
1000
|
return;
|
|
819
1001
|
console.debug("[gltf-progressive] Enabling LODsManager for renderer");
|
|
820
|
-
let
|
|
821
|
-
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
const
|
|
825
|
-
(
|
|
826
|
-
const
|
|
827
|
-
L(
|
|
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);
|
|
828
1010
|
};
|
|
829
1011
|
}
|
|
830
1012
|
disable() {
|
|
831
|
-
L(this,
|
|
1013
|
+
L(this, J) && (console.debug("[gltf-progressive] Disabling LODsManager for renderer"), this.renderer.render = L(this, J), E(this, J, void 0));
|
|
832
1014
|
}
|
|
833
|
-
update(
|
|
834
|
-
this.internalUpdate(
|
|
1015
|
+
update(e, t) {
|
|
1016
|
+
this.internalUpdate(e, t);
|
|
835
1017
|
}
|
|
836
|
-
onAfterRender(
|
|
1018
|
+
onAfterRender(e, t, s) {
|
|
837
1019
|
if (this.pause)
|
|
838
1020
|
return;
|
|
839
|
-
const
|
|
840
|
-
let
|
|
841
|
-
if (
|
|
842
|
-
const a =
|
|
843
|
-
(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);
|
|
844
1026
|
}
|
|
845
|
-
if ((
|
|
846
|
-
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))
|
|
847
1029
|
return;
|
|
848
|
-
this.internalUpdate(
|
|
1030
|
+
this.internalUpdate(e, t), this._postprocessPromiseGroups();
|
|
849
1031
|
}
|
|
850
1032
|
}
|
|
851
1033
|
/**
|
|
852
1034
|
* Update LODs in a scene
|
|
853
1035
|
*/
|
|
854
|
-
internalUpdate(
|
|
855
|
-
var l,
|
|
856
|
-
const s = this.renderer.renderLists.get(
|
|
857
|
-
this.projectionScreenMatrix.multiplyMatrices(
|
|
858
|
-
const
|
|
859
|
-
for (const
|
|
860
|
-
if (
|
|
861
|
-
|
|
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)));
|
|
862
1044
|
continue;
|
|
863
1045
|
}
|
|
864
|
-
switch (
|
|
1046
|
+
switch (u.material.type) {
|
|
865
1047
|
case "LineBasicMaterial":
|
|
866
1048
|
case "LineDashedMaterial":
|
|
867
1049
|
case "PointsMaterial":
|
|
@@ -870,62 +1052,60 @@ const b = class {
|
|
|
870
1052
|
case "MeshDepthMaterial":
|
|
871
1053
|
continue;
|
|
872
1054
|
}
|
|
873
|
-
if (
|
|
874
|
-
|
|
875
|
-
const
|
|
876
|
-
|
|
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;
|
|
877
1059
|
}
|
|
878
|
-
const
|
|
879
|
-
(
|
|
1060
|
+
const p = u.object;
|
|
1061
|
+
(p instanceof oe || p.isMesh) && this.updateLODs(e, t, p, i);
|
|
880
1062
|
}
|
|
881
|
-
const
|
|
882
|
-
for (const
|
|
883
|
-
const
|
|
884
|
-
(
|
|
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);
|
|
885
1067
|
}
|
|
886
1068
|
const a = s.transmissive;
|
|
887
|
-
for (const
|
|
888
|
-
const
|
|
889
|
-
(
|
|
1069
|
+
for (const u of a) {
|
|
1070
|
+
const p = u.object;
|
|
1071
|
+
(p instanceof oe || p.isMesh) && this.updateLODs(e, t, p, i);
|
|
890
1072
|
}
|
|
891
1073
|
}
|
|
892
1074
|
/** Update the LOD levels for the renderer. */
|
|
893
|
-
updateLODs(
|
|
1075
|
+
updateLODs(e, t, s, r) {
|
|
894
1076
|
var a, l;
|
|
895
1077
|
s.userData || (s.userData = {});
|
|
896
|
-
let
|
|
897
|
-
if (
|
|
1078
|
+
let i = s[Re];
|
|
1079
|
+
if (i || (i = new Ot(), s[Re] = i), i.frames++ < 2)
|
|
898
1080
|
return;
|
|
899
|
-
for (const
|
|
900
|
-
(a =
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
for (const
|
|
904
|
-
(l =
|
|
905
|
-
|
|
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;
|
|
906
1088
|
}
|
|
907
1089
|
/** Load progressive textures for the given material
|
|
908
1090
|
* @param material the material to load the textures for
|
|
909
1091
|
* @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
|
|
910
1092
|
* @returns Promise with true if the LOD was loaded, false if not
|
|
911
1093
|
*/
|
|
912
|
-
loadProgressiveTextures(t,
|
|
913
|
-
if (!
|
|
1094
|
+
loadProgressiveTextures(e, t, s) {
|
|
1095
|
+
if (!e)
|
|
914
1096
|
return;
|
|
915
|
-
if (Array.isArray(
|
|
916
|
-
for (const
|
|
917
|
-
this.loadProgressiveTextures(
|
|
1097
|
+
if (Array.isArray(e)) {
|
|
1098
|
+
for (const i of e)
|
|
1099
|
+
this.loadProgressiveTextures(i, t);
|
|
918
1100
|
return;
|
|
919
1101
|
}
|
|
920
|
-
let
|
|
921
|
-
(
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
const r = T.assignTextureLOD(t, e).then((i) => {
|
|
926
|
-
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 }));
|
|
927
1107
|
});
|
|
928
|
-
|
|
1108
|
+
be.addPromise("texture", e, i, this._newPromiseGroups);
|
|
929
1109
|
}
|
|
930
1110
|
}
|
|
931
1111
|
/** Load progressive meshes for the given mesh
|
|
@@ -934,336 +1114,341 @@ const b = class {
|
|
|
934
1114
|
* @param level the LOD level to load. Level 0 is the best quality, higher levels are lower quality
|
|
935
1115
|
* @returns Promise with true if the LOD was loaded, false if not
|
|
936
1116
|
*/
|
|
937
|
-
loadProgressiveMeshes(
|
|
938
|
-
if (!
|
|
1117
|
+
loadProgressiveMeshes(e, t) {
|
|
1118
|
+
if (!e)
|
|
939
1119
|
return Promise.resolve(null);
|
|
940
|
-
let s =
|
|
941
|
-
const
|
|
942
|
-
if (
|
|
943
|
-
|
|
944
|
-
const
|
|
945
|
-
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;
|
|
946
1126
|
}
|
|
947
1127
|
return Promise.resolve(null);
|
|
948
1128
|
}
|
|
949
|
-
static isInside(
|
|
950
|
-
const s =
|
|
951
|
-
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;
|
|
952
1132
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
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;
|
|
957
1138
|
return;
|
|
958
1139
|
}
|
|
959
|
-
if (!
|
|
960
|
-
|
|
1140
|
+
if (!e) {
|
|
1141
|
+
i.mesh_lod = -1, i.texture_lod = -1;
|
|
961
1142
|
return;
|
|
962
1143
|
}
|
|
963
1144
|
let a = 10 + 1, l = !1;
|
|
964
|
-
if (
|
|
965
|
-
return
|
|
966
|
-
const
|
|
967
|
-
if (!
|
|
968
|
-
|
|
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;
|
|
969
1150
|
return;
|
|
970
1151
|
}
|
|
971
|
-
|
|
972
|
-
const
|
|
973
|
-
let
|
|
974
|
-
if (
|
|
975
|
-
const
|
|
976
|
-
if (!
|
|
977
|
-
|
|
1152
|
+
p || (l = !0, a = 0);
|
|
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();
|
|
978
1159
|
else if (this.skinnedMeshAutoUpdateBoundsInterval > 0) {
|
|
979
|
-
if (!
|
|
980
|
-
const
|
|
981
|
-
|
|
1160
|
+
if (!f[S.$skinnedMeshBoundsOffset]) {
|
|
1161
|
+
const _ = S.skinnedMeshBoundsFrameOffsetCounter++;
|
|
1162
|
+
f[S.$skinnedMeshBoundsOffset] = _;
|
|
982
1163
|
}
|
|
983
|
-
const
|
|
984
|
-
if ((s.frames +
|
|
985
|
-
const
|
|
986
|
-
|
|
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;
|
|
987
1168
|
}
|
|
988
1169
|
}
|
|
989
|
-
|
|
1170
|
+
b = f.boundingBox;
|
|
990
1171
|
}
|
|
991
|
-
if (
|
|
992
|
-
const
|
|
993
|
-
if (
|
|
994
|
-
this._sphere.copy(
|
|
995
|
-
const
|
|
996
|
-
if (this._sphere.containsPoint(
|
|
997
|
-
|
|
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;
|
|
998
1179
|
return;
|
|
999
1180
|
}
|
|
1000
1181
|
}
|
|
1001
|
-
if (this._tempBox.copy(
|
|
1002
|
-
|
|
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;
|
|
1003
1184
|
return;
|
|
1004
1185
|
}
|
|
1005
|
-
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled &&
|
|
1006
|
-
const
|
|
1007
|
-
let
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
const
|
|
1011
|
-
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);
|
|
1012
1193
|
} else
|
|
1013
1194
|
s.lastCentrality = 1;
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
const
|
|
1019
|
-
if (Math.max(
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
const
|
|
1025
|
-
|
|
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);
|
|
1026
1207
|
}
|
|
1027
|
-
let
|
|
1028
|
-
if (
|
|
1029
|
-
for (let
|
|
1030
|
-
const
|
|
1031
|
-
if (
|
|
1032
|
-
|
|
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;
|
|
1033
1214
|
break;
|
|
1034
1215
|
}
|
|
1035
1216
|
}
|
|
1036
|
-
|
|
1217
|
+
Z < a && (a = Z, l = !0);
|
|
1037
1218
|
}
|
|
1038
|
-
if (l ?
|
|
1039
|
-
const
|
|
1040
|
-
|
|
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}`);
|
|
1041
1222
|
}
|
|
1042
|
-
if (
|
|
1043
|
-
const
|
|
1223
|
+
if (y) {
|
|
1224
|
+
const f = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
1044
1225
|
if (s.lastLodLevel_Texture < 0) {
|
|
1045
|
-
if (
|
|
1046
|
-
const
|
|
1047
|
-
|
|
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}`);
|
|
1048
1229
|
}
|
|
1049
1230
|
} else {
|
|
1050
|
-
const
|
|
1051
|
-
let
|
|
1052
|
-
((
|
|
1053
|
-
const
|
|
1054
|
-
let
|
|
1055
|
-
for (let
|
|
1056
|
-
const
|
|
1057
|
-
if (!(
|
|
1058
|
-
if (
|
|
1059
|
-
const m =
|
|
1060
|
-
|
|
1061
|
-
Screensize: ${
|
|
1062
|
-
${
|
|
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}`);
|
|
1063
1244
|
}
|
|
1064
1245
|
break;
|
|
1065
1246
|
}
|
|
1066
1247
|
}
|
|
1067
1248
|
}
|
|
1068
1249
|
} else
|
|
1069
|
-
|
|
1250
|
+
i.texture_lod = 0;
|
|
1070
1251
|
}
|
|
1071
1252
|
};
|
|
1072
|
-
let
|
|
1073
|
-
|
|
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(), /**
|
|
1074
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.
|
|
1075
1256
|
*/
|
|
1076
|
-
|
|
1257
|
+
c(O, "debugDrawLine"), /**
|
|
1077
1258
|
* Force override the LOD level for all objects in the scene
|
|
1078
1259
|
*/
|
|
1079
|
-
|
|
1080
|
-
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 {
|
|
1081
1262
|
constructor() {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
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);
|
|
1088
1269
|
}
|
|
1089
1270
|
}
|
|
1090
|
-
const
|
|
1091
|
-
let
|
|
1092
|
-
function
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1095
|
-
return
|
|
1096
|
-
}),
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
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);
|
|
1100
1281
|
});
|
|
1101
1282
|
});
|
|
1102
|
-
}),
|
|
1283
|
+
}), fe.observe(document, { childList: !0, subtree: !0 }));
|
|
1103
1284
|
}
|
|
1104
|
-
function
|
|
1285
|
+
function Wt() {
|
|
1105
1286
|
if (typeof customElements > "u")
|
|
1106
1287
|
return null;
|
|
1107
|
-
const
|
|
1108
|
-
return
|
|
1109
|
-
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();
|
|
1110
1291
|
}), null);
|
|
1111
1292
|
}
|
|
1112
|
-
function
|
|
1293
|
+
function ze() {
|
|
1113
1294
|
if (typeof document > "u")
|
|
1114
1295
|
return;
|
|
1115
|
-
document.querySelectorAll("model-viewer").forEach((
|
|
1116
|
-
|
|
1296
|
+
document.querySelectorAll("model-viewer").forEach((e) => {
|
|
1297
|
+
je(e);
|
|
1117
1298
|
});
|
|
1118
1299
|
}
|
|
1119
|
-
const
|
|
1120
|
-
let
|
|
1121
|
-
function
|
|
1122
|
-
if (!
|
|
1300
|
+
const He = /* @__PURE__ */ new WeakSet();
|
|
1301
|
+
let Tt = 0;
|
|
1302
|
+
function je(n) {
|
|
1303
|
+
if (!n || He.has(n))
|
|
1123
1304
|
return null;
|
|
1124
|
-
|
|
1125
|
-
`,
|
|
1126
|
-
let
|
|
1127
|
-
for (let
|
|
1128
|
-
const
|
|
1129
|
-
!
|
|
1130
|
-
}
|
|
1131
|
-
if (
|
|
1132
|
-
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() {
|
|
1133
1314
|
if (s) {
|
|
1134
|
-
let
|
|
1135
|
-
if (
|
|
1315
|
+
let o = 0, a = setInterval(() => {
|
|
1316
|
+
if (o++ > 5) {
|
|
1136
1317
|
clearInterval(a);
|
|
1137
1318
|
return;
|
|
1138
1319
|
}
|
|
1139
|
-
s == null || s.call(
|
|
1320
|
+
s == null || s.call(n);
|
|
1140
1321
|
}, 300);
|
|
1141
1322
|
}
|
|
1142
1323
|
};
|
|
1143
1324
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
1144
|
-
const
|
|
1145
|
-
return
|
|
1146
|
-
s == null || s.call(
|
|
1147
|
-
}),
|
|
1148
|
-
|
|
1149
|
-
}),
|
|
1150
|
-
|
|
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();
|
|
1151
1332
|
}), () => {
|
|
1152
|
-
|
|
1333
|
+
i.disable();
|
|
1153
1334
|
};
|
|
1154
1335
|
}
|
|
1155
1336
|
return null;
|
|
1156
1337
|
}
|
|
1157
|
-
class
|
|
1338
|
+
class Xt {
|
|
1158
1339
|
constructor() {
|
|
1159
|
-
|
|
1340
|
+
c(this, "_didWarnAboutMissingUrl", !1);
|
|
1160
1341
|
}
|
|
1161
|
-
onBeforeUpdateLOD(
|
|
1162
|
-
this.tryParseMeshLOD(
|
|
1342
|
+
onBeforeUpdateLOD(e, t, s, r) {
|
|
1343
|
+
this.tryParseMeshLOD(t, r), this.tryParseTextureLOD(t, r);
|
|
1163
1344
|
}
|
|
1164
|
-
getUrl(
|
|
1165
|
-
if (!
|
|
1345
|
+
getUrl(e) {
|
|
1346
|
+
if (!e)
|
|
1166
1347
|
return null;
|
|
1167
|
-
let
|
|
1168
|
-
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;
|
|
1169
1350
|
}
|
|
1170
|
-
tryGetCurrentGLTF(
|
|
1171
|
-
return
|
|
1351
|
+
tryGetCurrentGLTF(e) {
|
|
1352
|
+
return e._currentGLTF;
|
|
1172
1353
|
}
|
|
1173
|
-
tryGetCurrentModelViewer(
|
|
1174
|
-
return
|
|
1354
|
+
tryGetCurrentModelViewer(e) {
|
|
1355
|
+
return e.element;
|
|
1175
1356
|
}
|
|
1176
|
-
tryParseTextureLOD(
|
|
1177
|
-
if (
|
|
1357
|
+
tryParseTextureLOD(e, t) {
|
|
1358
|
+
if (t[ye] == !0)
|
|
1178
1359
|
return;
|
|
1179
|
-
|
|
1180
|
-
const s = this.tryGetCurrentGLTF(
|
|
1181
|
-
if (
|
|
1182
|
-
let
|
|
1183
|
-
var
|
|
1184
|
-
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)
|
|
1185
1366
|
return;
|
|
1186
|
-
l[
|
|
1187
|
-
const
|
|
1188
|
-
for (let
|
|
1189
|
-
const
|
|
1190
|
-
if ((
|
|
1191
|
-
const
|
|
1192
|
-
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)
|
|
1193
1374
|
continue;
|
|
1194
|
-
const
|
|
1195
|
-
if (!
|
|
1196
|
-
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);
|
|
1197
1378
|
continue;
|
|
1198
1379
|
}
|
|
1199
|
-
if ((
|
|
1200
|
-
const
|
|
1201
|
-
|
|
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);
|
|
1202
1383
|
}
|
|
1203
1384
|
}
|
|
1204
1385
|
}
|
|
1205
1386
|
};
|
|
1206
|
-
const a =
|
|
1387
|
+
const a = t.material;
|
|
1207
1388
|
if (Array.isArray(a))
|
|
1208
1389
|
for (const l of a)
|
|
1209
|
-
|
|
1390
|
+
o(l);
|
|
1210
1391
|
else
|
|
1211
|
-
|
|
1392
|
+
o(a);
|
|
1212
1393
|
}
|
|
1213
1394
|
}
|
|
1214
|
-
tryParseMeshLOD(
|
|
1215
|
-
var
|
|
1216
|
-
if (
|
|
1395
|
+
tryParseMeshLOD(e, t) {
|
|
1396
|
+
var o, a;
|
|
1397
|
+
if (t[Ne] == !0)
|
|
1217
1398
|
return;
|
|
1218
|
-
|
|
1219
|
-
const s = this.tryGetCurrentModelViewer(
|
|
1220
|
-
if (!
|
|
1399
|
+
t[Ne] = !0;
|
|
1400
|
+
const s = this.tryGetCurrentModelViewer(e), r = this.getUrl(s);
|
|
1401
|
+
if (!r)
|
|
1221
1402
|
return;
|
|
1222
|
-
const
|
|
1223
|
-
if (
|
|
1224
|
-
const l =
|
|
1225
|
-
|
|
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);
|
|
1226
1407
|
}
|
|
1227
1408
|
}
|
|
1228
1409
|
}
|
|
1229
|
-
function
|
|
1230
|
-
|
|
1410
|
+
function Kt(n, e, t, s) {
|
|
1411
|
+
Te(e), Ee(t), Je(t, {
|
|
1231
1412
|
progressive: !0,
|
|
1232
1413
|
...s == null ? void 0 : s.hints
|
|
1233
|
-
}),
|
|
1234
|
-
const
|
|
1235
|
-
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;
|
|
1236
1417
|
}
|
|
1237
|
-
|
|
1238
|
-
if (!
|
|
1239
|
-
const
|
|
1418
|
+
Qe();
|
|
1419
|
+
if (!Lt) {
|
|
1420
|
+
const n = {
|
|
1240
1421
|
gltfProgressive: {
|
|
1241
|
-
useNeedleProgressive:
|
|
1242
|
-
LODsManager:
|
|
1243
|
-
configureLoader:
|
|
1244
|
-
getRaycastMesh:
|
|
1245
|
-
useRaycastMeshes:
|
|
1422
|
+
useNeedleProgressive: Kt,
|
|
1423
|
+
LODsManager: O,
|
|
1424
|
+
configureLoader: Je,
|
|
1425
|
+
getRaycastMesh: me,
|
|
1426
|
+
useRaycastMeshes: Gt
|
|
1246
1427
|
}
|
|
1247
1428
|
};
|
|
1248
1429
|
if (!globalThis.Needle)
|
|
1249
|
-
globalThis.Needle =
|
|
1430
|
+
globalThis.Needle = n;
|
|
1250
1431
|
else
|
|
1251
|
-
for (const
|
|
1252
|
-
globalThis.Needle[
|
|
1432
|
+
for (const e in n)
|
|
1433
|
+
globalThis.Needle[e] = n[e];
|
|
1253
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" }));
|
|
1254
1439
|
export {
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
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
|
|
1269
1454
|
};
|