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