@needle-tools/gltf-progressive 1.2.0-alpha.9 → 1.2.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gltf-progressive.js +323 -325
- package/gltf-progressive.min.js +4 -4
- package/gltf-progressive.umd.cjs +4 -4
- package/lib/extension.js +4 -5
- package/lib/lods_manager.js +11 -12
- package/lib/utils.js +4 -5
- package/package.json +1 -1
package/gltf-progressive.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var c = (l, e, t) => (
|
|
4
|
-
import { MeshoptDecoder as
|
|
5
|
-
import { DRACOLoader as
|
|
6
|
-
import { KTX2Loader as
|
|
7
|
-
import { BufferGeometry as
|
|
8
|
-
import { GLTFLoader as
|
|
9
|
-
let
|
|
10
|
-
fetch(
|
|
11
|
-
|
|
1
|
+
var De = Object.defineProperty;
|
|
2
|
+
var Me = (l, e, t) => e in l ? De(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
|
|
3
|
+
var c = (l, e, t) => (Me(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { MeshoptDecoder as we } from "three/examples/jsm/libs/meshopt_decoder.module.js";
|
|
5
|
+
import { DRACOLoader as Oe } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
6
|
+
import { KTX2Loader as _e } from "three/examples/jsm/loaders/KTX2Loader.js";
|
|
7
|
+
import { BufferGeometry as Q, Mesh as N, Material as ve, Texture as X, TextureLoader as Se, Matrix4 as fe, Frustum as Te, Sphere as be, Box3 as de, Vector3 as E } from "three";
|
|
8
|
+
import { GLTFLoader as Ae } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
9
|
+
let ee = "https://www.gstatic.com/draco/versioned/decoders/1.4.1/", ce = "https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";
|
|
10
|
+
fetch(ee + "draco_decoder.js", { method: "head" }).catch((l) => {
|
|
11
|
+
ee = "./include/draco/", ce = "./include/ktx2/";
|
|
12
12
|
});
|
|
13
|
-
function
|
|
14
|
-
|
|
13
|
+
function qe(l) {
|
|
14
|
+
ee = l;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
16
|
+
function Xe(l) {
|
|
17
|
+
ce = l;
|
|
18
18
|
}
|
|
19
|
-
let
|
|
20
|
-
function
|
|
21
|
-
|
|
19
|
+
let H, oe, J;
|
|
20
|
+
function ye(l) {
|
|
21
|
+
H || (H = new Oe(), H.setDecoderPath(ee), H.setDecoderConfig({ type: "js" })), J || (J = new _e(), J.setTranscoderPath(ce)), oe || (oe = we), l ? J.detectSupport(l) : console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
l.dracoLoader || l.setDRACOLoader(
|
|
23
|
+
function xe(l) {
|
|
24
|
+
l.dracoLoader || l.setDRACOLoader(H), l.ktx2Loader || l.setKTX2Loader(J), l.meshoptDecoder || l.setMeshoptDecoder(oe);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function te(l) {
|
|
27
27
|
const t = new URL(window.location.href).searchParams.get(l);
|
|
28
28
|
return t == null || t === "0" || t === "false" ? !1 : t === "" ? !0 : t;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function Pe(l, e) {
|
|
31
31
|
if (e === void 0 || e.startsWith("./") || e.startsWith("http") || l === void 0)
|
|
32
32
|
return e;
|
|
33
33
|
const t = l.lastIndexOf("/");
|
|
@@ -39,55 +39,55 @@ function Te(l, e) {
|
|
|
39
39
|
}
|
|
40
40
|
return e;
|
|
41
41
|
}
|
|
42
|
-
let
|
|
43
|
-
function
|
|
44
|
-
return
|
|
42
|
+
let Y;
|
|
43
|
+
function Be() {
|
|
44
|
+
return Y !== void 0 || (Y = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), te("debugprogressive") && console.log("isMobileDevice", Y)), Y;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return (
|
|
46
|
+
const ae = Symbol("needle:raycast-mesh");
|
|
47
|
+
function ue(l) {
|
|
48
|
+
return (l == null ? void 0 : l[ae]) instanceof Q ? l[ae] : null;
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !
|
|
52
|
-
const r =
|
|
53
|
-
r.userData = { isRaycastMesh: !0 }, l
|
|
50
|
+
function Ce(l, e) {
|
|
51
|
+
if ((l.type === "Mesh" || l.type === "SkinnedMesh") && !ue(l)) {
|
|
52
|
+
const r = ke(e);
|
|
53
|
+
r.userData = { isRaycastMesh: !0 }, l[ae] = r;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function Ye(l = !0) {
|
|
57
57
|
if (l) {
|
|
58
|
-
if (
|
|
58
|
+
if (V)
|
|
59
59
|
return;
|
|
60
|
-
const e =
|
|
61
|
-
|
|
62
|
-
const i = this, n =
|
|
60
|
+
const e = V = N.prototype.raycast;
|
|
61
|
+
N.prototype.raycast = function(t, r) {
|
|
62
|
+
const i = this, n = ue(i);
|
|
63
63
|
let s;
|
|
64
64
|
n && i.isMesh && (s = i.geometry, i.geometry = n), e.call(this, t, r), s && (i.geometry = s);
|
|
65
65
|
};
|
|
66
66
|
} else {
|
|
67
|
-
if (!
|
|
67
|
+
if (!V)
|
|
68
68
|
return;
|
|
69
|
-
|
|
69
|
+
N.prototype.raycast = V, V = null;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
let
|
|
73
|
-
function
|
|
74
|
-
const e = new
|
|
72
|
+
let V = null;
|
|
73
|
+
function ke(l) {
|
|
74
|
+
const e = new Q();
|
|
75
75
|
for (const t in l.attributes)
|
|
76
76
|
e.setAttribute(t, l.getAttribute(t));
|
|
77
77
|
return e.setIndex(l.getIndex()), e;
|
|
78
78
|
}
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
79
|
+
const $ = new Array(), I = "NEEDLE_progressive", L = te("debugprogressive"), ie = Symbol("needle-progressive-texture"), Z = /* @__PURE__ */ new Map(), le = /* @__PURE__ */ new Set();
|
|
80
|
+
if (L) {
|
|
81
81
|
let l = function() {
|
|
82
|
-
e += 1, console.log("Toggle LOD level", e,
|
|
82
|
+
e += 1, console.log("Toggle LOD level", e, Z), Z.forEach((i, n) => {
|
|
83
83
|
for (const s of i.keys) {
|
|
84
84
|
const o = n[s];
|
|
85
85
|
if (o != null) {
|
|
86
86
|
if (o.isBufferGeometry === !0) {
|
|
87
|
-
const a =
|
|
88
|
-
n["DEBUG:LOD"] = e,
|
|
87
|
+
const a = T.getMeshLODInformation(o), d = a ? Math.min(e, a.lods.length) : 0;
|
|
88
|
+
n["DEBUG:LOD"] = e, T.assignMeshLOD(n, d), a && (t = Math.max(t, a.lods.length - 1));
|
|
89
89
|
} else if (n.isMaterial === !0) {
|
|
90
|
-
n["DEBUG:LOD"] = e,
|
|
90
|
+
n["DEBUG:LOD"] = e, T.assignTextureLOD(n, e);
|
|
91
91
|
break;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -95,20 +95,20 @@ if (M) {
|
|
|
95
95
|
}), e >= t && (e = -1);
|
|
96
96
|
}, e = -1, t = 2, r = !1;
|
|
97
97
|
window.addEventListener("keyup", (i) => {
|
|
98
|
-
i.key === "p" && l(), i.key === "w" && (r = !r,
|
|
98
|
+
i.key === "p" && l(), i.key === "w" && (r = !r, le && le.forEach((n) => {
|
|
99
99
|
n.name != "BackgroundCubeMaterial" && n.glyphMap == null && "wireframe" in n && (n.wireframe = r);
|
|
100
100
|
}));
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function he(l, e, t) {
|
|
104
104
|
var i;
|
|
105
|
-
if (!
|
|
105
|
+
if (!L)
|
|
106
106
|
return;
|
|
107
|
-
|
|
108
|
-
const r =
|
|
107
|
+
Z.has(l) || Z.set(l, { keys: [], sourceId: t });
|
|
108
|
+
const r = Z.get(l);
|
|
109
109
|
((i = r == null ? void 0 : r.keys) == null ? void 0 : i.includes(e)) == !1 && r.keys.push(e);
|
|
110
110
|
}
|
|
111
|
-
const
|
|
111
|
+
const v = class {
|
|
112
112
|
constructor(e, t) {
|
|
113
113
|
c(this, "parser");
|
|
114
114
|
c(this, "url");
|
|
@@ -117,14 +117,14 @@ const _ = class {
|
|
|
117
117
|
var r, i;
|
|
118
118
|
if (this._isLoadingMesh)
|
|
119
119
|
return null;
|
|
120
|
-
const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[
|
|
121
|
-
return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((n) => (this._isLoadingMesh = !1, n &&
|
|
120
|
+
const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[I];
|
|
121
|
+
return t ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", e).then((n) => (this._isLoadingMesh = !1, n && v.registerMesh(this.url, t.guid, n, t.lods.length, void 0, t), n))) : null;
|
|
122
122
|
});
|
|
123
|
-
|
|
123
|
+
L && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
|
|
124
124
|
}
|
|
125
125
|
/** The name of the extension */
|
|
126
126
|
get name() {
|
|
127
|
-
return
|
|
127
|
+
return I;
|
|
128
128
|
}
|
|
129
129
|
static getMeshLODInformation(e) {
|
|
130
130
|
const t = this.getAssignedLODInformation(e);
|
|
@@ -143,11 +143,11 @@ const _ = class {
|
|
|
143
143
|
this.getMaterialMinMaxLODsCount(o, t);
|
|
144
144
|
return e[i] = t, t;
|
|
145
145
|
}
|
|
146
|
-
if (
|
|
146
|
+
if (L === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
|
|
147
147
|
const o = e;
|
|
148
148
|
for (const a of Object.keys(o.uniforms)) {
|
|
149
|
-
const
|
|
150
|
-
(
|
|
149
|
+
const d = o.uniforms[a].value;
|
|
150
|
+
(d == null ? void 0 : d.isTexture) === !0 && s(d, t);
|
|
151
151
|
}
|
|
152
152
|
} else if (e.isMaterial)
|
|
153
153
|
for (const o of Object.keys(e)) {
|
|
@@ -156,14 +156,14 @@ const _ = class {
|
|
|
156
156
|
}
|
|
157
157
|
return e[i] = t, t;
|
|
158
158
|
function s(o, a) {
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
a.min_count = Math.min(a.min_count,
|
|
164
|
-
for (let
|
|
165
|
-
const
|
|
166
|
-
|
|
159
|
+
const d = r.getAssignedLODInformation(o);
|
|
160
|
+
if (d) {
|
|
161
|
+
const f = r.lodInfos.get(d.key);
|
|
162
|
+
if (f && f.lods) {
|
|
163
|
+
a.min_count = Math.min(a.min_count, f.lods.length), a.max_count = Math.max(a.max_count, f.lods.length);
|
|
164
|
+
for (let p = 0; p < f.lods.length; p++) {
|
|
165
|
+
const g = f.lods[p];
|
|
166
|
+
g.width && (a.lods[p] = a.lods[p] || { min_height: 1 / 0, max_height: 0 }, a.lods[p].min_height = Math.min(a.lods[p].min_height, g.height), a.lods[p].max_height = Math.max(a.lods[p].max_height, g.height));
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -196,7 +196,7 @@ const _ = class {
|
|
|
196
196
|
}
|
|
197
197
|
let r, i;
|
|
198
198
|
if (e.isMesh ? r = e.geometry : (e.isBufferGeometry || e.isTexture) && (r = e), r && (n = r == null ? void 0 : r.userData) != null && n.LODS) {
|
|
199
|
-
const s = r.userData.LODS;
|
|
199
|
+
const s = r.userData.LODS();
|
|
200
200
|
if (i = this.lodInfos.get(s.key), t === void 0)
|
|
201
201
|
return i != null;
|
|
202
202
|
if (i)
|
|
@@ -222,24 +222,24 @@ const _ = class {
|
|
|
222
222
|
var r;
|
|
223
223
|
if (!e)
|
|
224
224
|
return Promise.resolve(null);
|
|
225
|
-
if (e instanceof
|
|
225
|
+
if (e instanceof N || e.isMesh === !0) {
|
|
226
226
|
const i = e.geometry, n = this.getAssignedLODInformation(i);
|
|
227
227
|
if (!n)
|
|
228
228
|
return Promise.resolve(null);
|
|
229
|
-
for (const s of
|
|
229
|
+
for (const s of $)
|
|
230
230
|
(r = s.onBeforeGetLODMesh) == null || r.call(s, e, t);
|
|
231
|
-
return e["LOD:requested level"] = t,
|
|
231
|
+
return e["LOD:requested level"] = t, v.getOrLoadLOD(i, t).then((s) => {
|
|
232
232
|
if (e["LOD:requested level"] === t) {
|
|
233
233
|
if (delete e["LOD:requested level"], Array.isArray(s)) {
|
|
234
234
|
const o = n.index || 0;
|
|
235
235
|
s = s[o];
|
|
236
236
|
}
|
|
237
|
-
s && i != s && s instanceof
|
|
237
|
+
s && i != s && s instanceof Q && (e.geometry = s, L && he(e, "geometry", n.url));
|
|
238
238
|
}
|
|
239
239
|
return s;
|
|
240
240
|
}).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
|
|
241
241
|
} else
|
|
242
|
-
|
|
242
|
+
L && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", e);
|
|
243
243
|
return Promise.resolve(null);
|
|
244
244
|
}
|
|
245
245
|
/** Load a different resolution of a texture (if available)
|
|
@@ -252,15 +252,15 @@ const _ = class {
|
|
|
252
252
|
static assignTextureLOD(e, t = 0) {
|
|
253
253
|
if (!e)
|
|
254
254
|
return Promise.resolve(null);
|
|
255
|
-
if (e instanceof
|
|
255
|
+
if (e instanceof ve || e.isMaterial === !0) {
|
|
256
256
|
const r = e, i = [], n = new Array();
|
|
257
|
-
if (
|
|
257
|
+
if (L && le.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
|
|
258
258
|
const s = r;
|
|
259
259
|
for (const o of Object.keys(s.uniforms)) {
|
|
260
260
|
const a = s.uniforms[o].value;
|
|
261
261
|
if ((a == null ? void 0 : a.isTexture) === !0) {
|
|
262
|
-
const
|
|
263
|
-
i.push(
|
|
262
|
+
const d = this.assignTextureLODForSlot(a, t, r, o);
|
|
263
|
+
i.push(d), n.push(o);
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
} else
|
|
@@ -274,20 +274,20 @@ const _ = class {
|
|
|
274
274
|
return Promise.all(i).then((s) => {
|
|
275
275
|
const o = new Array();
|
|
276
276
|
for (let a = 0; a < s.length; a++) {
|
|
277
|
-
const
|
|
278
|
-
|
|
277
|
+
const d = s[a], f = n[a];
|
|
278
|
+
d && d.isTexture === !0 ? o.push({ material: r, slot: f, texture: d, level: t }) : o.push({ material: r, slot: f, texture: null, level: t });
|
|
279
279
|
}
|
|
280
280
|
return o;
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
|
-
if (e instanceof
|
|
283
|
+
if (e instanceof X || e.isTexture === !0) {
|
|
284
284
|
const r = e;
|
|
285
285
|
return this.assignTextureLODForSlot(r, t, null, null);
|
|
286
286
|
}
|
|
287
287
|
return Promise.resolve(null);
|
|
288
288
|
}
|
|
289
289
|
static assignTextureLODForSlot(e, t, r, i) {
|
|
290
|
-
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) :
|
|
290
|
+
return (e == null ? void 0 : e.isTexture) !== !0 ? Promise.resolve(null) : i === "glyphMap" ? Promise.resolve(e) : v.getOrLoadLOD(e, t).then((n) => {
|
|
291
291
|
if (Array.isArray(n))
|
|
292
292
|
return null;
|
|
293
293
|
if ((n == null ? void 0 : n.isTexture) === !0) {
|
|
@@ -297,211 +297,211 @@ const _ = class {
|
|
|
297
297
|
if (s) {
|
|
298
298
|
const o = this.getAssignedLODInformation(s);
|
|
299
299
|
if (o && (o == null ? void 0 : o.level) < t)
|
|
300
|
-
return
|
|
300
|
+
return L === "verbose" && console.warn("Assigned texture level is already higher: ", o.level, t, r, s, n), null;
|
|
301
301
|
}
|
|
302
302
|
r[i] = n;
|
|
303
303
|
}
|
|
304
|
-
if (
|
|
304
|
+
if (L && i && r) {
|
|
305
305
|
const s = this.getAssignedLODInformation(e);
|
|
306
|
-
s &&
|
|
306
|
+
s && he(r, i, s.url);
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
309
|
return n;
|
|
310
310
|
} else
|
|
311
|
-
|
|
311
|
+
L == "verbose" && console.warn("No LOD found for", e, t);
|
|
312
312
|
return null;
|
|
313
313
|
}).catch((n) => (console.error("Error loading LOD", e, n), null));
|
|
314
314
|
}
|
|
315
315
|
afterRoot(e) {
|
|
316
316
|
var t, r;
|
|
317
|
-
return
|
|
317
|
+
return L && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, n) => {
|
|
318
318
|
if (i != null && i.extensions) {
|
|
319
|
-
const s = i == null ? void 0 : i.extensions[
|
|
319
|
+
const s = i == null ? void 0 : i.extensions[I];
|
|
320
320
|
if (s) {
|
|
321
321
|
if (!s.lods) {
|
|
322
|
-
|
|
322
|
+
L && console.warn("Texture has no LODs", s);
|
|
323
323
|
return;
|
|
324
324
|
}
|
|
325
325
|
let o = !1;
|
|
326
326
|
for (const a of this.parser.associations.keys())
|
|
327
|
-
a.isTexture === !0 && this.parser.associations.get(a).textures === n && (o = !0,
|
|
327
|
+
a.isTexture === !0 && this.parser.associations.get(a).textures === n && (o = !0, v.registerTexture(this.url, a, s.lods.length, n, s));
|
|
328
328
|
o || this.parser.getDependency("texture", n).then((a) => {
|
|
329
|
-
a &&
|
|
329
|
+
a && v.registerTexture(this.url, a, s.lods.length, n, s);
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
}), (r = this.parser.json.meshes) == null || r.forEach((i, n) => {
|
|
334
334
|
if (i != null && i.extensions) {
|
|
335
|
-
const s = i == null ? void 0 : i.extensions[
|
|
335
|
+
const s = i == null ? void 0 : i.extensions[I];
|
|
336
336
|
if (s && s.lods) {
|
|
337
337
|
for (const o of this.parser.associations.keys())
|
|
338
338
|
if (o.isMesh) {
|
|
339
339
|
const a = this.parser.associations.get(o);
|
|
340
|
-
a.meshes === n &&
|
|
340
|
+
a.meshes === n && v.registerMesh(this.url, s.guid, o, s.lods.length, a.primitives, s);
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
}), null;
|
|
345
345
|
}
|
|
346
346
|
static async getOrLoadLOD(e, t) {
|
|
347
|
-
var o, a,
|
|
348
|
-
const r =
|
|
347
|
+
var o, a, d, f, p, g;
|
|
348
|
+
const r = L == "verbose", i = (a = (o = e.userData).LODS) == null ? void 0 : a.call(o);
|
|
349
349
|
if (!i)
|
|
350
350
|
return null;
|
|
351
351
|
const n = i == null ? void 0 : i.key;
|
|
352
352
|
let s;
|
|
353
353
|
if (e.isTexture === !0) {
|
|
354
|
-
const
|
|
355
|
-
|
|
354
|
+
const M = e;
|
|
355
|
+
M.source && M.source[ie] && (s = M.source[ie]);
|
|
356
356
|
}
|
|
357
|
-
if (s || (s =
|
|
357
|
+
if (s || (s = v.lodInfos.get(n)), s) {
|
|
358
358
|
if (t > 0) {
|
|
359
359
|
let y = !1;
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
360
|
+
const h = Array.isArray(s.lods);
|
|
361
|
+
if (h && t >= s.lods.length ? y = !0 : h || (y = !0), y)
|
|
362
362
|
return this.lowresCache.get(n);
|
|
363
363
|
}
|
|
364
|
-
const
|
|
365
|
-
if (!
|
|
366
|
-
return
|
|
367
|
-
const
|
|
368
|
-
if (
|
|
364
|
+
const M = Array.isArray(s.lods) ? (d = s.lods[t]) == null ? void 0 : d.path : s.lods;
|
|
365
|
+
if (!M)
|
|
366
|
+
return L && !s["missing:uri"] && (s["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + t, s)), null;
|
|
367
|
+
const D = Pe(i.url, M);
|
|
368
|
+
if (D.endsWith(".glb") || D.endsWith(".gltf")) {
|
|
369
369
|
if (!s.guid)
|
|
370
370
|
return console.warn("missing pointer for glb/gltf texture", s), null;
|
|
371
|
-
const y =
|
|
372
|
-
if (
|
|
371
|
+
const y = D + "_" + s.guid, h = this.previouslyLoaded.get(y);
|
|
372
|
+
if (h !== void 0) {
|
|
373
373
|
r && console.log(`LOD ${t} was already loading/loaded: ${y}`);
|
|
374
|
-
let
|
|
375
|
-
`,
|
|
376
|
-
if (
|
|
377
|
-
return
|
|
374
|
+
let b = await h.catch((G) => (console.error(`Error loading LOD ${t} from ${D}
|
|
375
|
+
`, G), null)), q = !1;
|
|
376
|
+
if (b == null || (b instanceof X && e instanceof X ? (f = b.image) != null && f.data || (p = b.source) != null && p.data ? b = this.copySettings(e, b) : (q = !0, this.previouslyLoaded.delete(y)) : b instanceof Q && e instanceof Q && ((g = b.attributes.position) != null && g.array || (q = !0, this.previouslyLoaded.delete(y)))), !q)
|
|
377
|
+
return b;
|
|
378
378
|
}
|
|
379
|
-
const
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
let
|
|
383
|
-
if (
|
|
384
|
-
const
|
|
385
|
-
|
|
379
|
+
const w = s, P = new Promise(async (b, q) => {
|
|
380
|
+
const G = new Ae();
|
|
381
|
+
xe(G), L && (await new Promise((m) => setTimeout(m, 1e3)), r && console.warn("Start loading (delayed) " + D, w.guid));
|
|
382
|
+
let re = D;
|
|
383
|
+
if (w && Array.isArray(w.lods)) {
|
|
384
|
+
const m = w.lods[t];
|
|
385
|
+
m.hash && (re += "?v=" + m.hash);
|
|
386
386
|
}
|
|
387
|
-
const
|
|
388
|
-
`,
|
|
389
|
-
if (!
|
|
387
|
+
const x = await G.loadAsync(re).catch((m) => (console.error(`Error loading LOD ${t} from ${D}
|
|
388
|
+
`, m), null));
|
|
389
|
+
if (!x)
|
|
390
390
|
return null;
|
|
391
|
-
const
|
|
392
|
-
r && console.log("Loading finished " +
|
|
393
|
-
let
|
|
394
|
-
if (
|
|
395
|
-
let
|
|
396
|
-
for (const u of
|
|
391
|
+
const O = x.parser;
|
|
392
|
+
r && console.log("Loading finished " + D, w.guid);
|
|
393
|
+
let _ = 0;
|
|
394
|
+
if (x.parser.json.textures) {
|
|
395
|
+
let m = !1;
|
|
396
|
+
for (const u of x.parser.json.textures) {
|
|
397
397
|
if (u != null && u.extensions) {
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
400
|
-
|
|
398
|
+
const S = u == null ? void 0 : u.extensions[I];
|
|
399
|
+
if (S != null && S.guid && S.guid === w.guid) {
|
|
400
|
+
m = !0;
|
|
401
401
|
break;
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
|
-
|
|
404
|
+
_++;
|
|
405
405
|
}
|
|
406
|
-
if (
|
|
407
|
-
let u = await
|
|
408
|
-
return u &&
|
|
406
|
+
if (m) {
|
|
407
|
+
let u = await O.getDependency("texture", _);
|
|
408
|
+
return u && v.assignLODInformation(i.url, u, n, t, void 0, void 0), r && console.log('change "' + e.name + '" → "' + u.name + '"', D, _, u, y), e instanceof X && (u = this.copySettings(e, u)), u && (u.guid = w.guid), b(u);
|
|
409
409
|
} else
|
|
410
|
-
|
|
410
|
+
L && console.warn("Could not find texture with guid", w.guid);
|
|
411
411
|
}
|
|
412
|
-
if (
|
|
413
|
-
let
|
|
414
|
-
for (const u of
|
|
412
|
+
if (_ = 0, x.parser.json.meshes) {
|
|
413
|
+
let m = !1;
|
|
414
|
+
for (const u of x.parser.json.meshes) {
|
|
415
415
|
if (u != null && u.extensions) {
|
|
416
|
-
const
|
|
417
|
-
if (
|
|
418
|
-
|
|
416
|
+
const S = u == null ? void 0 : u.extensions[I];
|
|
417
|
+
if (S != null && S.guid && S.guid === w.guid) {
|
|
418
|
+
m = !0;
|
|
419
419
|
break;
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
|
-
|
|
422
|
+
_++;
|
|
423
423
|
}
|
|
424
|
-
if (
|
|
425
|
-
const u = await
|
|
426
|
-
if (r && console.log(`Loaded Mesh "${u.name}"`,
|
|
427
|
-
const
|
|
428
|
-
return
|
|
424
|
+
if (m) {
|
|
425
|
+
const u = await O.getDependency("mesh", _), S = w;
|
|
426
|
+
if (r && console.log(`Loaded Mesh "${u.name}"`, D, _, u, y), u.isMesh === !0) {
|
|
427
|
+
const R = u.geometry;
|
|
428
|
+
return v.assignLODInformation(i.url, R, n, t, void 0, S.density), b(R);
|
|
429
429
|
} else {
|
|
430
|
-
const
|
|
431
|
-
for (let
|
|
432
|
-
const
|
|
433
|
-
if (
|
|
434
|
-
const
|
|
435
|
-
|
|
430
|
+
const R = new Array();
|
|
431
|
+
for (let F = 0; F < u.children.length; F++) {
|
|
432
|
+
const z = u.children[F];
|
|
433
|
+
if (z instanceof N) {
|
|
434
|
+
const U = z.geometry;
|
|
435
|
+
v.assignLODInformation(i.url, U, n, t, F, S.density), R.push(U);
|
|
436
436
|
}
|
|
437
437
|
}
|
|
438
|
-
return
|
|
438
|
+
return b(R);
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
|
-
return
|
|
442
|
+
return b(null);
|
|
443
443
|
});
|
|
444
|
-
return this.previouslyLoaded.set(y,
|
|
445
|
-
} else if (e instanceof
|
|
446
|
-
r && console.log("Load texture from uri: " +
|
|
447
|
-
const
|
|
448
|
-
return
|
|
444
|
+
return this.previouslyLoaded.set(y, P), await P;
|
|
445
|
+
} else if (e instanceof X) {
|
|
446
|
+
r && console.log("Load texture from uri: " + D);
|
|
447
|
+
const h = await new Se().loadAsync(D);
|
|
448
|
+
return h ? (h.guid = s.guid, h.flipY = !1, h.needsUpdate = !0, h.colorSpace = e.colorSpace, r && console.log(s, h)) : L && console.warn("failed loading", D), h;
|
|
449
449
|
}
|
|
450
450
|
} else
|
|
451
|
-
|
|
451
|
+
L && console.warn(`Can not load LOD ${t}: no LOD info found for "${n}" ${e.name}`, e.type);
|
|
452
452
|
return null;
|
|
453
453
|
}
|
|
454
454
|
static assignLODInformation(e, t, r, i, n, s) {
|
|
455
455
|
if (!t)
|
|
456
456
|
return;
|
|
457
457
|
t.userData || (t.userData = {});
|
|
458
|
-
const o = new
|
|
459
|
-
t.userData.LODS =
|
|
458
|
+
const o = new Re(e, r, i, n, s);
|
|
459
|
+
t.userData.LODS = () => o;
|
|
460
460
|
}
|
|
461
461
|
static getAssignedLODInformation(e) {
|
|
462
|
-
var t;
|
|
463
|
-
return ((t = e == null ? void 0 : e.userData) == null ? void 0 : t.LODS) || null;
|
|
462
|
+
var t, r;
|
|
463
|
+
return ((r = (t = e == null ? void 0 : e.userData) == null ? void 0 : t.LODS) == null ? void 0 : r.call(t)) || null;
|
|
464
464
|
}
|
|
465
465
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
466
466
|
static copySettings(e, t) {
|
|
467
|
-
return t = t.clone(),
|
|
467
|
+
return t = t.clone(), L && console.warn(`Copying texture settings
|
|
468
468
|
`, e.uuid, `
|
|
469
469
|
`, t.uuid), t.offset = e.offset, t.repeat = e.repeat, t.colorSpace = e.colorSpace, t.magFilter = e.magFilter, t.minFilter = e.minFilter, t.wrapS = e.wrapS, t.wrapT = e.wrapT, t.flipY = e.flipY, t.anisotropy = e.anisotropy, t.mipmaps || (t.generateMipmaps = e.generateMipmaps), t;
|
|
470
470
|
}
|
|
471
471
|
};
|
|
472
|
-
let
|
|
472
|
+
let T = v;
|
|
473
473
|
/**
|
|
474
474
|
* Register a texture with LOD information
|
|
475
475
|
*/
|
|
476
|
-
c(
|
|
477
|
-
if (
|
|
478
|
-
|
|
476
|
+
c(T, "registerTexture", (e, t, r, i, n) => {
|
|
477
|
+
if (L && console.log("> Progressive: register texture", i, t.name, t.uuid, t, n), !t) {
|
|
478
|
+
L && console.error("gltf-progressive: Register texture without texture");
|
|
479
479
|
return;
|
|
480
480
|
}
|
|
481
|
-
t.source && (t.source[
|
|
481
|
+
t.source && (t.source[ie] = n);
|
|
482
482
|
const s = n.guid;
|
|
483
|
-
|
|
483
|
+
v.assignLODInformation(e, t, s, r, i, void 0), v.lodInfos.set(s, n), v.lowresCache.set(s, t);
|
|
484
484
|
}), /**
|
|
485
485
|
* Register a mesh with LOD information
|
|
486
486
|
*/
|
|
487
|
-
c(
|
|
488
|
-
var
|
|
489
|
-
|
|
487
|
+
c(T, "registerMesh", (e, t, r, i, n, s) => {
|
|
488
|
+
var d;
|
|
489
|
+
L && console.log("> Progressive: register mesh", n, r.name, s, r.uuid, r);
|
|
490
490
|
const o = r.geometry;
|
|
491
491
|
if (!o) {
|
|
492
|
-
|
|
492
|
+
L && console.warn("gltf-progressive: Register mesh without geometry");
|
|
493
493
|
return;
|
|
494
494
|
}
|
|
495
|
-
o.userData || (o.userData = {}),
|
|
496
|
-
let a =
|
|
497
|
-
a ? a.push(r.geometry) : a = [r.geometry],
|
|
498
|
-
for (const
|
|
499
|
-
(
|
|
495
|
+
o.userData || (o.userData = {}), v.assignLODInformation(e, o, t, i, n, s.density), v.lodInfos.set(t, s);
|
|
496
|
+
let a = v.lowresCache.get(t);
|
|
497
|
+
a ? a.push(r.geometry) : a = [r.geometry], v.lowresCache.set(t, a), i > 0 && !ue(r) && Ce(r, o);
|
|
498
|
+
for (const f of $)
|
|
499
|
+
(d = f.onRegisteredNewMesh) == null || d.call(f, r, s);
|
|
500
500
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
501
|
-
c(
|
|
502
|
-
c(
|
|
503
|
-
c(
|
|
504
|
-
class
|
|
501
|
+
c(T, "lodInfos", /* @__PURE__ */ new Map()), /** cache of already loaded mesh lods */
|
|
502
|
+
c(T, "previouslyLoaded", /* @__PURE__ */ new Map()), /** this contains the geometry/textures that were originally loaded */
|
|
503
|
+
c(T, "lowresCache", /* @__PURE__ */ new Map());
|
|
504
|
+
class Re {
|
|
505
505
|
constructor(e, t, r, i, n) {
|
|
506
506
|
c(this, "url");
|
|
507
507
|
/** the key to lookup the LOD information */
|
|
@@ -514,12 +514,12 @@ class Ee {
|
|
|
514
514
|
this.url = e, this.key = t, this.level = r, i != null && (this.index = i), n != null && (this.density = n);
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
|
-
const
|
|
517
|
+
const W = te("debugprogressive"), Ee = te("noprogressive"), ge = Symbol("Needle:LODSManager"), ne = Symbol("Needle:LODState"), K = Symbol("Needle:CurrentLOD"), B = { mesh_lod: -1, texture_lod: -1 }, A = class {
|
|
518
518
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
519
519
|
constructor(e) {
|
|
520
520
|
c(this, "renderer");
|
|
521
|
-
c(this, "projectionScreenMatrix", new
|
|
522
|
-
c(this, "cameraFrustrum", new
|
|
521
|
+
c(this, "projectionScreenMatrix", new fe());
|
|
522
|
+
c(this, "cameraFrustrum", new Te());
|
|
523
523
|
/**
|
|
524
524
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
525
525
|
* @default 200_000
|
|
@@ -536,26 +536,25 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
536
536
|
c(this, "_frame", 0);
|
|
537
537
|
c(this, "_originalRender");
|
|
538
538
|
// private testIfLODLevelsAreAvailable() {
|
|
539
|
-
c(this, "_sphere", new
|
|
540
|
-
c(this, "_tempBox", new
|
|
541
|
-
c(this, "_tempBox2", new
|
|
542
|
-
c(this, "tempMatrix", new
|
|
543
|
-
c(this, "_tempWorldPosition", new
|
|
544
|
-
c(this, "_tempBoxSize", new
|
|
545
|
-
c(this, "_tempBox2Size", new
|
|
539
|
+
c(this, "_sphere", new be());
|
|
540
|
+
c(this, "_tempBox", new de());
|
|
541
|
+
c(this, "_tempBox2", new de());
|
|
542
|
+
c(this, "tempMatrix", new fe());
|
|
543
|
+
c(this, "_tempWorldPosition", new E());
|
|
544
|
+
c(this, "_tempBoxSize", new E());
|
|
545
|
+
c(this, "_tempBox2Size", new E());
|
|
546
546
|
this.renderer = e;
|
|
547
547
|
}
|
|
548
548
|
/** @internal */
|
|
549
549
|
static getObjectLODState(e) {
|
|
550
|
-
|
|
551
|
-
return (t = e.userData) == null ? void 0 : t.LOD_state;
|
|
550
|
+
return e[ne];
|
|
552
551
|
}
|
|
553
552
|
static addPlugin(e) {
|
|
554
|
-
|
|
553
|
+
$.push(e);
|
|
555
554
|
}
|
|
556
555
|
static removePlugin(e) {
|
|
557
|
-
const t =
|
|
558
|
-
t >= 0 &&
|
|
556
|
+
const t = $.indexOf(e);
|
|
557
|
+
t >= 0 && $.splice(t, 1);
|
|
559
558
|
}
|
|
560
559
|
/**
|
|
561
560
|
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
@@ -563,11 +562,11 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
563
562
|
* @returns The LODsManager instance.
|
|
564
563
|
*/
|
|
565
564
|
static get(e) {
|
|
566
|
-
return e[
|
|
565
|
+
return e[ge] ? e[ge] : new A(e);
|
|
567
566
|
}
|
|
568
567
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
569
568
|
get plugins() {
|
|
570
|
-
return
|
|
569
|
+
return $;
|
|
571
570
|
}
|
|
572
571
|
/**
|
|
573
572
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
@@ -578,7 +577,7 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
578
577
|
let e = 0;
|
|
579
578
|
this._originalRender = this.renderer.render;
|
|
580
579
|
const t = this;
|
|
581
|
-
|
|
580
|
+
ye(this.renderer), this.renderer.render = function(r, i) {
|
|
582
581
|
t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
|
|
583
582
|
const s = t._frame, o = e++;
|
|
584
583
|
t.onBeforeRender(r, i, o, s), t._originalRender.call(this, r, i), t.onAfterRender(r, i, o, s);
|
|
@@ -590,26 +589,26 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
590
589
|
onBeforeRender(e, t, r, i) {
|
|
591
590
|
}
|
|
592
591
|
onAfterRender(e, t, r, i) {
|
|
593
|
-
var a,
|
|
592
|
+
var a, d;
|
|
594
593
|
if (this.pause)
|
|
595
594
|
return;
|
|
596
595
|
const n = this.renderer.renderLists.get(e, 0), s = n.opaque;
|
|
597
596
|
let o = !0;
|
|
598
597
|
if (s.length === 1) {
|
|
599
|
-
const
|
|
600
|
-
(
|
|
598
|
+
const f = s[0].material;
|
|
599
|
+
(f.name === "EffectMaterial" || f.name === "CopyShader") && (o = !1);
|
|
601
600
|
}
|
|
602
601
|
if (t.parent && t.parent.type === "CubeCamera" && (o = !1), o) {
|
|
603
|
-
if (
|
|
602
|
+
if (Ee || this.updateInterval > 0 && i % this.updateInterval != 0)
|
|
604
603
|
return;
|
|
605
604
|
this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
|
|
606
|
-
const
|
|
607
|
-
for (const
|
|
608
|
-
if (
|
|
609
|
-
|
|
605
|
+
const f = this.targetTriangleDensity;
|
|
606
|
+
for (const g of s) {
|
|
607
|
+
if (g.material && (((a = g.geometry) == null ? void 0 : a.type) === "BoxGeometry" || ((d = g.geometry) == null ? void 0 : d.type) === "BufferGeometry") && (g.material.name === "SphericalGaussianBlur" || g.material.name == "BackgroundCubeMaterial" || g.material.name === "CubemapFromEquirect" || g.material.name === "EquirectangularToCubeUV")) {
|
|
608
|
+
W && (g.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (g.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", g, g.material.name, g.material.type)));
|
|
610
609
|
continue;
|
|
611
610
|
}
|
|
612
|
-
switch (
|
|
611
|
+
switch (g.material.type) {
|
|
613
612
|
case "LineBasicMaterial":
|
|
614
613
|
case "LineDashedMaterial":
|
|
615
614
|
case "PointsMaterial":
|
|
@@ -618,34 +617,34 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
618
617
|
case "MeshDepthMaterial":
|
|
619
618
|
continue;
|
|
620
619
|
}
|
|
621
|
-
const
|
|
622
|
-
(
|
|
620
|
+
const M = g.object;
|
|
621
|
+
(M instanceof N || M.isMesh) && this.updateLODs(e, t, M, f, i);
|
|
623
622
|
}
|
|
624
|
-
const
|
|
625
|
-
for (const
|
|
626
|
-
const
|
|
627
|
-
(
|
|
623
|
+
const p = n.transparent;
|
|
624
|
+
for (const g of p) {
|
|
625
|
+
const M = g.object;
|
|
626
|
+
(M instanceof N || M.isMesh) && this.updateLODs(e, t, M, f, i);
|
|
628
627
|
}
|
|
629
628
|
}
|
|
630
629
|
}
|
|
631
630
|
/** Update the LOD levels for the renderer. */
|
|
632
631
|
updateLODs(e, t, r, i, n) {
|
|
633
|
-
var a,
|
|
632
|
+
var a, d;
|
|
634
633
|
r.userData || (r.userData = {});
|
|
635
|
-
let s = r
|
|
636
|
-
if (s || (s = new
|
|
634
|
+
let s = r[ne];
|
|
635
|
+
if (s || (s = new Ie(), r[ne] = s), s.frames++ < 2)
|
|
637
636
|
return;
|
|
638
|
-
for (const
|
|
639
|
-
(a =
|
|
640
|
-
this.calculateLodLevel(t, r, s, i,
|
|
641
|
-
let o =
|
|
637
|
+
for (const f of $)
|
|
638
|
+
(a = f.onBeforeUpdateLOD) == null || a.call(f, this.renderer, e, t, r);
|
|
639
|
+
this.calculateLodLevel(t, r, s, i, B), B.mesh_lod = Math.round(B.mesh_lod), B.texture_lod = Math.round(B.texture_lod), B.mesh_lod >= 0 && this.loadProgressiveMeshes(r, B.mesh_lod);
|
|
640
|
+
let o = B.texture_lod;
|
|
642
641
|
if (r.material && o >= 0) {
|
|
643
|
-
const
|
|
644
|
-
|
|
642
|
+
const f = r["DEBUG:LOD"];
|
|
643
|
+
f != null && (o = f), this.loadProgressiveTextures(r.material, o);
|
|
645
644
|
}
|
|
646
|
-
for (const
|
|
647
|
-
(
|
|
648
|
-
s.lastLodLevel_Mesh =
|
|
645
|
+
for (const f of $)
|
|
646
|
+
(d = f.onAfterUpdatedLOD) == null || d.call(f, this.renderer, e, t, r, B);
|
|
647
|
+
s.lastLodLevel_Mesh = B.mesh_lod, s.lastLodLevel_Texture = B.texture_lod;
|
|
649
648
|
}
|
|
650
649
|
/** Load progressive textures for the given material
|
|
651
650
|
* @param material the material to load the textures for
|
|
@@ -656,13 +655,12 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
656
655
|
if (!e)
|
|
657
656
|
return;
|
|
658
657
|
if (Array.isArray(e)) {
|
|
659
|
-
for (const
|
|
660
|
-
this.loadProgressiveTextures(
|
|
658
|
+
for (const i of e)
|
|
659
|
+
this.loadProgressiveTextures(i, t);
|
|
661
660
|
return;
|
|
662
661
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
(r.NEEDLE_LOD == null || t < r.NEEDLE_LOD) && (i = !0), i && (r.NEEDLE_LOD = t, v.assignTextureLOD(e, t));
|
|
662
|
+
let r = !1;
|
|
663
|
+
(e[K] == null || t < e[K]) && (r = !0), r && (e[K] = t, T.assignTextureLOD(e, t));
|
|
666
664
|
}
|
|
667
665
|
/** Load progressive meshes for the given mesh
|
|
668
666
|
* @param mesh the mesh to load the LOD for
|
|
@@ -673,10 +671,10 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
673
671
|
loadProgressiveMeshes(e, t) {
|
|
674
672
|
if (!e)
|
|
675
673
|
return Promise.resolve(null);
|
|
676
|
-
if (e
|
|
677
|
-
e
|
|
674
|
+
if (e[K] !== t) {
|
|
675
|
+
e[K] = t;
|
|
678
676
|
const r = e.geometry;
|
|
679
|
-
return
|
|
677
|
+
return T.assignMeshLOD(e, t).then((i) => (i && e[K] == t && r != e.geometry, i));
|
|
680
678
|
}
|
|
681
679
|
return Promise.resolve(null);
|
|
682
680
|
}
|
|
@@ -685,7 +683,7 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
685
683
|
return this._tempPtInside.set(n, s, r.z).applyMatrix4(t).z < 0;
|
|
686
684
|
}
|
|
687
685
|
calculateLodLevel(e, t, r, i, n) {
|
|
688
|
-
var
|
|
686
|
+
var D;
|
|
689
687
|
if (!t) {
|
|
690
688
|
n.mesh_lod = -1, n.texture_lod = -1;
|
|
691
689
|
return;
|
|
@@ -695,24 +693,24 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
695
693
|
return;
|
|
696
694
|
}
|
|
697
695
|
let o = 10 + 1;
|
|
698
|
-
if (
|
|
696
|
+
if (W && t["DEBUG:LOD"] != null)
|
|
699
697
|
return t["DEBUG:LOD"];
|
|
700
|
-
const a =
|
|
701
|
-
if (!
|
|
698
|
+
const a = T.getMeshLODInformation(t.geometry), d = a == null ? void 0 : a.lods, f = d && d.length > 0, p = T.getMaterialMinMaxLODsCount(t.material), g = (p == null ? void 0 : p.min_count) != 1 / 0 && p.min_count > 0 && p.max_count > 0;
|
|
699
|
+
if (!f && !g) {
|
|
702
700
|
n.mesh_lod = 0, n.texture_lod = 0;
|
|
703
701
|
return;
|
|
704
702
|
}
|
|
705
|
-
if (
|
|
703
|
+
if (f || (o = 0), !((D = this.cameraFrustrum) != null && D.intersectsObject(t))) {
|
|
706
704
|
n.mesh_lod = 99, n.texture_lod = 99;
|
|
707
705
|
return;
|
|
708
706
|
}
|
|
709
|
-
let
|
|
707
|
+
let M = t.geometry.boundingBox;
|
|
710
708
|
if (t.type === "SkinnedMesh") {
|
|
711
|
-
const
|
|
712
|
-
|
|
709
|
+
const y = t;
|
|
710
|
+
y.boundingBox || y.computeBoundingBox(), M = y.boundingBox;
|
|
713
711
|
}
|
|
714
|
-
if (
|
|
715
|
-
const
|
|
712
|
+
if (M && e.isPerspectiveCamera) {
|
|
713
|
+
const y = e;
|
|
716
714
|
if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
|
|
717
715
|
this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
|
|
718
716
|
const x = e.getWorldPosition(this._tempWorldPosition);
|
|
@@ -721,54 +719,54 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
721
719
|
return;
|
|
722
720
|
}
|
|
723
721
|
}
|
|
724
|
-
if (this._tempBox.copy(
|
|
722
|
+
if (this._tempBox.copy(M), t.type === "SkinnedMesh" ? t.parent && this._tempBox.applyMatrix4(t.parent.matrixWorld) : this._tempBox.applyMatrix4(t.matrixWorld), A.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
725
723
|
n.mesh_lod = 0, n.texture_lod = 0;
|
|
726
724
|
return;
|
|
727
725
|
}
|
|
728
|
-
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled &&
|
|
729
|
-
const x = this._tempBox.min,
|
|
730
|
-
let
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
const
|
|
734
|
-
r.lastCentrality = (
|
|
726
|
+
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && y.fov > 70) {
|
|
727
|
+
const x = this._tempBox.min, O = this._tempBox.max;
|
|
728
|
+
let _ = x.x, m = x.y, u = O.x, S = O.y;
|
|
729
|
+
const R = 2, F = 1.5, z = (x.x + O.x) * 0.5, U = (x.y + O.y) * 0.5;
|
|
730
|
+
_ = (_ - z) * R + z, m = (m - U) * R + U, u = (u - z) * R + z, S = (S - U) * R + U;
|
|
731
|
+
const me = _ < 0 && u > 0 ? 0 : Math.min(Math.abs(x.x), Math.abs(O.x)), Le = m < 0 && S > 0 ? 0 : Math.min(Math.abs(x.y), Math.abs(O.y)), se = Math.max(me, Le);
|
|
732
|
+
r.lastCentrality = (F - se) * (F - se) * (F - se);
|
|
735
733
|
} else
|
|
736
734
|
r.lastCentrality = 1;
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
if (Math.max(
|
|
735
|
+
const h = this._tempBox.getSize(this._tempBoxSize);
|
|
736
|
+
h.multiplyScalar(0.5), screen.availHeight > 0 && h.multiplyScalar(this.renderer.domElement.clientHeight / screen.availHeight), h.x *= y.aspect;
|
|
737
|
+
const w = e.matrixWorldInverse, P = this._tempBox2;
|
|
738
|
+
P.copy(M), P.applyMatrix4(t.matrixWorld), P.applyMatrix4(w);
|
|
739
|
+
const k = P.getSize(this._tempBox2Size), b = Math.max(k.x, k.y);
|
|
740
|
+
if (Math.max(h.x, h.y) != 0 && b != 0 && (h.z = k.z / Math.max(k.x, k.y) * Math.max(h.x, h.y)), r.lastScreenCoverage = Math.max(h.x, h.y, h.z), r.lastScreenspaceVolume.copy(h), r.lastScreenCoverage *= r.lastCentrality, W && A.debugDrawLine) {
|
|
743
741
|
const x = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
744
742
|
x.invert();
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
const
|
|
748
|
-
|
|
743
|
+
const O = A.corner0, _ = A.corner1, m = A.corner2, u = A.corner3;
|
|
744
|
+
O.copy(this._tempBox.min), _.copy(this._tempBox.max), _.x = O.x, m.copy(this._tempBox.max), m.y = O.y, u.copy(this._tempBox.max);
|
|
745
|
+
const S = (O.z + u.z) * 0.5;
|
|
746
|
+
O.z = _.z = m.z = u.z = S, O.applyMatrix4(x), _.applyMatrix4(x), m.applyMatrix4(x), u.applyMatrix4(x), A.debugDrawLine(O, _, 255), A.debugDrawLine(O, m, 255), A.debugDrawLine(_, u, 255), A.debugDrawLine(m, u, 255);
|
|
749
747
|
}
|
|
750
|
-
let
|
|
751
|
-
if (
|
|
752
|
-
for (let x = 0; x <
|
|
753
|
-
if (
|
|
754
|
-
|
|
748
|
+
let G = 999;
|
|
749
|
+
if (d && r.lastScreenCoverage > 0) {
|
|
750
|
+
for (let x = 0; x < d.length; x++)
|
|
751
|
+
if (d[x].density / r.lastScreenCoverage < i) {
|
|
752
|
+
G = x;
|
|
755
753
|
break;
|
|
756
754
|
}
|
|
757
755
|
}
|
|
758
|
-
|
|
756
|
+
G < o && (o = G);
|
|
759
757
|
}
|
|
760
|
-
if (n.mesh_lod = o,
|
|
758
|
+
if (n.mesh_lod = o, g)
|
|
761
759
|
if (r.lastLodLevel_Texture < 0) {
|
|
762
|
-
if (n.texture_lod =
|
|
763
|
-
const
|
|
764
|
-
|
|
760
|
+
if (n.texture_lod = p.max_count - 1, W) {
|
|
761
|
+
const y = p.lods[p.max_count - 1];
|
|
762
|
+
W && console.log(`First Texture LOD ${n.texture_lod} (${y.max_height}px) - ${t.name}`);
|
|
765
763
|
}
|
|
766
764
|
} else {
|
|
767
|
-
const
|
|
768
|
-
for (let
|
|
769
|
-
const
|
|
770
|
-
if (!(
|
|
771
|
-
n.texture_lod =
|
|
765
|
+
const y = r.lastScreenCoverage * 1.5, w = this.renderer.domElement.clientHeight / window.devicePixelRatio * y;
|
|
766
|
+
for (let P = p.lods.length - 1; P >= 0; P--) {
|
|
767
|
+
const k = p.lods[P];
|
|
768
|
+
if (!(Be() && k.max_height > 4096) && k.max_height > w) {
|
|
769
|
+
n.texture_lod = P, n.texture_lod < r.lastLodLevel_Texture && W && console.log(`Texture LOD changed ${r.lastLodLevel_Texture} → ${n.texture_lod} (${k.max_height}px: ${(100 * r.lastScreenCoverage).toFixed(2)} % = ${w.toFixed(0)}px) - ${t.name}`);
|
|
772
770
|
break;
|
|
773
771
|
}
|
|
774
772
|
}
|
|
@@ -777,22 +775,22 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
777
775
|
n.texture_lod = 0;
|
|
778
776
|
}
|
|
779
777
|
};
|
|
780
|
-
let
|
|
778
|
+
let C = A;
|
|
781
779
|
/** 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.
|
|
782
780
|
*/
|
|
783
|
-
c(
|
|
784
|
-
class
|
|
781
|
+
c(C, "debugDrawLine"), c(C, "corner0", new E()), c(C, "corner1", new E()), c(C, "corner2", new E()), c(C, "corner3", new E()), c(C, "_tempPtInside", new E());
|
|
782
|
+
class Ie {
|
|
785
783
|
constructor() {
|
|
786
784
|
c(this, "frames", 0);
|
|
787
785
|
c(this, "lastLodLevel_Mesh", -1);
|
|
788
786
|
c(this, "lastLodLevel_Texture", -1);
|
|
789
787
|
c(this, "lastScreenCoverage", 0);
|
|
790
|
-
c(this, "lastScreenspaceVolume", new
|
|
788
|
+
c(this, "lastScreenspaceVolume", new E());
|
|
791
789
|
c(this, "lastCentrality", 0);
|
|
792
790
|
}
|
|
793
791
|
}
|
|
794
|
-
const
|
|
795
|
-
function
|
|
792
|
+
const pe = Symbol("NEEDLE_mesh_lod"), j = Symbol("NEEDLE_texture_lod");
|
|
793
|
+
function Ge(l) {
|
|
796
794
|
if (!l)
|
|
797
795
|
return null;
|
|
798
796
|
let e = null, t = null;
|
|
@@ -802,8 +800,8 @@ function ke(l) {
|
|
|
802
800
|
}
|
|
803
801
|
if (e) {
|
|
804
802
|
console.log("Adding Needle LODs to modelviewer");
|
|
805
|
-
const r =
|
|
806
|
-
if (
|
|
803
|
+
const r = C.get(e);
|
|
804
|
+
if (C.addPlugin(new Fe(l)), r.enable(), t) {
|
|
807
805
|
const i = t.camera || t.traverse((n) => n.type == "PerspectiveCamera")[0];
|
|
808
806
|
i && e.render(t, i);
|
|
809
807
|
}
|
|
@@ -813,7 +811,7 @@ function ke(l) {
|
|
|
813
811
|
}
|
|
814
812
|
return null;
|
|
815
813
|
}
|
|
816
|
-
class
|
|
814
|
+
class Fe {
|
|
817
815
|
constructor(e) {
|
|
818
816
|
c(this, "modelviewer");
|
|
819
817
|
c(this, "_didWarnAboutMissingUrl", !1);
|
|
@@ -830,28 +828,28 @@ class Re {
|
|
|
830
828
|
return e._currentGLTF;
|
|
831
829
|
}
|
|
832
830
|
tryParseTextureLOD(e, t) {
|
|
833
|
-
if (t[
|
|
831
|
+
if (t[j] == !0)
|
|
834
832
|
return;
|
|
835
|
-
t[
|
|
833
|
+
t[j] = !0;
|
|
836
834
|
const r = this.tryGetCurrentGLTF(e), i = this.getUrl();
|
|
837
835
|
if (i && r && t.material) {
|
|
838
836
|
let n = function(o) {
|
|
839
|
-
var
|
|
840
|
-
if (o[
|
|
837
|
+
var d, f, p;
|
|
838
|
+
if (o[j] == !0)
|
|
841
839
|
return;
|
|
842
|
-
o[
|
|
840
|
+
o[j] = !0, o.userData && (o.userData.LOD = -1);
|
|
843
841
|
const a = Object.keys(o);
|
|
844
|
-
for (let
|
|
845
|
-
const
|
|
846
|
-
if ((
|
|
847
|
-
const
|
|
848
|
-
if (!
|
|
849
|
-
console.warn("Texture data not found for texture index " +
|
|
842
|
+
for (let g = 0; g < a.length; g++) {
|
|
843
|
+
const M = a[g], D = o[M];
|
|
844
|
+
if ((D == null ? void 0 : D.isTexture) === !0) {
|
|
845
|
+
const y = (f = (d = D.userData) == null ? void 0 : d.associations) == null ? void 0 : f.textures, h = r.parser.json.textures[y];
|
|
846
|
+
if (!h) {
|
|
847
|
+
console.warn("Texture data not found for texture index " + y);
|
|
850
848
|
continue;
|
|
851
849
|
}
|
|
852
|
-
if ((
|
|
853
|
-
const
|
|
854
|
-
|
|
850
|
+
if ((p = h == null ? void 0 : h.extensions) != null && p[I]) {
|
|
851
|
+
const w = h.extensions[I];
|
|
852
|
+
w && i && T.registerTexture(i, D, w.lods.length, y, w);
|
|
855
853
|
}
|
|
856
854
|
}
|
|
857
855
|
}
|
|
@@ -866,38 +864,38 @@ class Re {
|
|
|
866
864
|
}
|
|
867
865
|
tryParseMeshLOD(e, t) {
|
|
868
866
|
var n, s;
|
|
869
|
-
if (t[
|
|
867
|
+
if (t[pe] == !0)
|
|
870
868
|
return;
|
|
871
|
-
t[
|
|
869
|
+
t[pe] = !0;
|
|
872
870
|
const r = this.getUrl();
|
|
873
871
|
if (!r)
|
|
874
872
|
return;
|
|
875
|
-
const i = (s = (n = t.userData) == null ? void 0 : n.gltfExtensions) == null ? void 0 : s[
|
|
873
|
+
const i = (s = (n = t.userData) == null ? void 0 : n.gltfExtensions) == null ? void 0 : s[I];
|
|
876
874
|
if (i && r) {
|
|
877
875
|
const o = t.uuid;
|
|
878
|
-
|
|
876
|
+
T.registerMesh(r, o, t, 0, i.lods.length, i);
|
|
879
877
|
}
|
|
880
878
|
}
|
|
881
879
|
}
|
|
882
|
-
function
|
|
883
|
-
|
|
884
|
-
const i =
|
|
880
|
+
function Ve(l, e, t, r) {
|
|
881
|
+
ye(e), xe(t), t.register((n) => new T(n, l));
|
|
882
|
+
const i = C.get(e);
|
|
885
883
|
return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
|
|
886
884
|
}
|
|
887
885
|
document.addEventListener("DOMContentLoaded", () => {
|
|
888
|
-
|
|
886
|
+
Ge(document.querySelector("model-viewer"));
|
|
889
887
|
});
|
|
890
888
|
export {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
889
|
+
I as EXTENSION_NAME,
|
|
890
|
+
C as LODsManager,
|
|
891
|
+
T as NEEDLE_progressive,
|
|
892
|
+
xe as addDracoAndKTX2Loaders,
|
|
893
|
+
ye as createLoaders,
|
|
894
|
+
ue as getRaycastMesh,
|
|
895
|
+
Ge as patchModelViewer,
|
|
896
|
+
qe as setDracoDecoderLocation,
|
|
897
|
+
Xe as setKTX2TranscoderLocation,
|
|
898
|
+
Ce as setRaycastMesh,
|
|
899
|
+
Ve as useNeedleProgressive,
|
|
900
|
+
Ye as useRaycastMeshes
|
|
903
901
|
};
|