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