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