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