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