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