@needle-tools/gltf-progressive 1.2.0-alpha.8 → 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/CHANGELOG.md +1 -1
- package/gltf-progressive.js +329 -329
- package/gltf-progressive.min.js +4 -4
- package/gltf-progressive.umd.cjs +4 -4
- package/lib/extension.js +12 -6
- 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,74 +39,76 @@ 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
|
-
if (o
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
if (o != null) {
|
|
86
|
+
if (o.isBufferGeometry === !0) {
|
|
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
|
+
} else if (n.isMaterial === !0) {
|
|
90
|
+
n["DEBUG:LOD"] = e, T.assignTextureLOD(n, e);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
}), e >= t && (e = -1);
|
|
94
96
|
}, e = -1, t = 2, r = !1;
|
|
95
97
|
window.addEventListener("keyup", (i) => {
|
|
96
|
-
i.key === "p" && l(), i.key === "w" && (r = !r,
|
|
97
|
-
n.name != "BackgroundCubeMaterial" && "wireframe" in n && (n.wireframe = r);
|
|
98
|
+
i.key === "p" && l(), i.key === "w" && (r = !r, le && le.forEach((n) => {
|
|
99
|
+
n.name != "BackgroundCubeMaterial" && n.glyphMap == null && "wireframe" in n && (n.wireframe = r);
|
|
98
100
|
}));
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
|
-
function
|
|
103
|
+
function he(l, e, t) {
|
|
102
104
|
var i;
|
|
103
|
-
if (!
|
|
105
|
+
if (!L)
|
|
104
106
|
return;
|
|
105
|
-
|
|
106
|
-
const r =
|
|
107
|
+
Z.has(l) || Z.set(l, { keys: [], sourceId: t });
|
|
108
|
+
const r = Z.get(l);
|
|
107
109
|
((i = r == null ? void 0 : r.keys) == null ? void 0 : i.includes(e)) == !1 && r.keys.push(e);
|
|
108
110
|
}
|
|
109
|
-
const
|
|
111
|
+
const v = class {
|
|
110
112
|
constructor(e, t) {
|
|
111
113
|
c(this, "parser");
|
|
112
114
|
c(this, "url");
|
|
@@ -115,14 +117,14 @@ const _ = class {
|
|
|
115
117
|
var r, i;
|
|
116
118
|
if (this._isLoadingMesh)
|
|
117
119
|
return null;
|
|
118
|
-
const t = (i = (r = this.parser.json.meshes[e]) == null ? void 0 : r.extensions) == null ? void 0 : i[
|
|
119
|
-
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;
|
|
120
122
|
});
|
|
121
|
-
|
|
123
|
+
L && console.log("Progressive extension registered for", t), this.parser = e, this.url = t;
|
|
122
124
|
}
|
|
123
125
|
/** The name of the extension */
|
|
124
126
|
get name() {
|
|
125
|
-
return
|
|
127
|
+
return I;
|
|
126
128
|
}
|
|
127
129
|
static getMeshLODInformation(e) {
|
|
128
130
|
const t = this.getAssignedLODInformation(e);
|
|
@@ -141,11 +143,11 @@ const _ = class {
|
|
|
141
143
|
this.getMaterialMinMaxLODsCount(o, t);
|
|
142
144
|
return e[i] = t, t;
|
|
143
145
|
}
|
|
144
|
-
if (
|
|
146
|
+
if (L === "verbose" && console.log("getMaterialMinMaxLODsCount", e), e.type === "ShaderMaterial" || e.type === "RawShaderMaterial") {
|
|
145
147
|
const o = e;
|
|
146
148
|
for (const a of Object.keys(o.uniforms)) {
|
|
147
|
-
const
|
|
148
|
-
(
|
|
149
|
+
const d = o.uniforms[a].value;
|
|
150
|
+
(d == null ? void 0 : d.isTexture) === !0 && s(d, t);
|
|
149
151
|
}
|
|
150
152
|
} else if (e.isMaterial)
|
|
151
153
|
for (const o of Object.keys(e)) {
|
|
@@ -154,14 +156,14 @@ const _ = class {
|
|
|
154
156
|
}
|
|
155
157
|
return e[i] = t, t;
|
|
156
158
|
function s(o, a) {
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
161
|
-
a.min_count = Math.min(a.min_count,
|
|
162
|
-
for (let
|
|
163
|
-
const
|
|
164
|
-
|
|
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));
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
169
|
}
|
|
@@ -194,7 +196,7 @@ const _ = class {
|
|
|
194
196
|
}
|
|
195
197
|
let r, i;
|
|
196
198
|
if (e.isMesh ? r = e.geometry : (e.isBufferGeometry || e.isTexture) && (r = e), r && (n = r == null ? void 0 : r.userData) != null && n.LODS) {
|
|
197
|
-
const s = r.userData.LODS;
|
|
199
|
+
const s = r.userData.LODS();
|
|
198
200
|
if (i = this.lodInfos.get(s.key), t === void 0)
|
|
199
201
|
return i != null;
|
|
200
202
|
if (i)
|
|
@@ -220,24 +222,24 @@ const _ = class {
|
|
|
220
222
|
var r;
|
|
221
223
|
if (!e)
|
|
222
224
|
return Promise.resolve(null);
|
|
223
|
-
if (e instanceof
|
|
225
|
+
if (e instanceof N || e.isMesh === !0) {
|
|
224
226
|
const i = e.geometry, n = this.getAssignedLODInformation(i);
|
|
225
227
|
if (!n)
|
|
226
228
|
return Promise.resolve(null);
|
|
227
|
-
for (const s of
|
|
229
|
+
for (const s of $)
|
|
228
230
|
(r = s.onBeforeGetLODMesh) == null || r.call(s, e, t);
|
|
229
|
-
return e["LOD:requested level"] = t,
|
|
231
|
+
return e["LOD:requested level"] = t, v.getOrLoadLOD(i, t).then((s) => {
|
|
230
232
|
if (e["LOD:requested level"] === t) {
|
|
231
233
|
if (delete e["LOD:requested level"], Array.isArray(s)) {
|
|
232
234
|
const o = n.index || 0;
|
|
233
235
|
s = s[o];
|
|
234
236
|
}
|
|
235
|
-
s && i != s && s instanceof
|
|
237
|
+
s && i != s && s instanceof Q && (e.geometry = s, L && he(e, "geometry", n.url));
|
|
236
238
|
}
|
|
237
239
|
return s;
|
|
238
240
|
}).catch((s) => (console.error("Error loading mesh LOD", e, s), null));
|
|
239
241
|
} else
|
|
240
|
-
|
|
242
|
+
L && console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh", e);
|
|
241
243
|
return Promise.resolve(null);
|
|
242
244
|
}
|
|
243
245
|
/** Load a different resolution of a texture (if available)
|
|
@@ -250,15 +252,15 @@ const _ = class {
|
|
|
250
252
|
static assignTextureLOD(e, t = 0) {
|
|
251
253
|
if (!e)
|
|
252
254
|
return Promise.resolve(null);
|
|
253
|
-
if (e instanceof
|
|
255
|
+
if (e instanceof ve || e.isMaterial === !0) {
|
|
254
256
|
const r = e, i = [], n = new Array();
|
|
255
|
-
if (
|
|
257
|
+
if (L && le.add(r), r.uniforms && r.isRawShaderMaterial || r.isShaderMaterial === !0) {
|
|
256
258
|
const s = r;
|
|
257
259
|
for (const o of Object.keys(s.uniforms)) {
|
|
258
260
|
const a = s.uniforms[o].value;
|
|
259
261
|
if ((a == null ? void 0 : a.isTexture) === !0) {
|
|
260
|
-
const
|
|
261
|
-
i.push(
|
|
262
|
+
const d = this.assignTextureLODForSlot(a, t, r, o);
|
|
263
|
+
i.push(d), n.push(o);
|
|
262
264
|
}
|
|
263
265
|
}
|
|
264
266
|
} else
|
|
@@ -272,20 +274,20 @@ const _ = class {
|
|
|
272
274
|
return Promise.all(i).then((s) => {
|
|
273
275
|
const o = new Array();
|
|
274
276
|
for (let a = 0; a < s.length; a++) {
|
|
275
|
-
const
|
|
276
|
-
|
|
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 });
|
|
277
279
|
}
|
|
278
280
|
return o;
|
|
279
281
|
});
|
|
280
282
|
}
|
|
281
|
-
if (e instanceof
|
|
283
|
+
if (e instanceof X || e.isTexture === !0) {
|
|
282
284
|
const r = e;
|
|
283
285
|
return this.assignTextureLODForSlot(r, t, null, null);
|
|
284
286
|
}
|
|
285
287
|
return Promise.resolve(null);
|
|
286
288
|
}
|
|
287
289
|
static assignTextureLODForSlot(e, t, r, i) {
|
|
288
|
-
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) => {
|
|
289
291
|
if (Array.isArray(n))
|
|
290
292
|
return null;
|
|
291
293
|
if ((n == null ? void 0 : n.isTexture) === !0) {
|
|
@@ -295,211 +297,211 @@ const _ = class {
|
|
|
295
297
|
if (s) {
|
|
296
298
|
const o = this.getAssignedLODInformation(s);
|
|
297
299
|
if (o && (o == null ? void 0 : o.level) < t)
|
|
298
|
-
return
|
|
300
|
+
return L === "verbose" && console.warn("Assigned texture level is already higher: ", o.level, t, r, s, n), null;
|
|
299
301
|
}
|
|
300
302
|
r[i] = n;
|
|
301
303
|
}
|
|
302
|
-
if (
|
|
304
|
+
if (L && i && r) {
|
|
303
305
|
const s = this.getAssignedLODInformation(e);
|
|
304
|
-
s &&
|
|
306
|
+
s && he(r, i, s.url);
|
|
305
307
|
}
|
|
306
308
|
}
|
|
307
309
|
return n;
|
|
308
310
|
} else
|
|
309
|
-
|
|
311
|
+
L == "verbose" && console.warn("No LOD found for", e, t);
|
|
310
312
|
return null;
|
|
311
313
|
}).catch((n) => (console.error("Error loading LOD", e, n), null));
|
|
312
314
|
}
|
|
313
315
|
afterRoot(e) {
|
|
314
316
|
var t, r;
|
|
315
|
-
return
|
|
317
|
+
return L && console.log("AFTER", this.url, e), (t = this.parser.json.textures) == null || t.forEach((i, n) => {
|
|
316
318
|
if (i != null && i.extensions) {
|
|
317
|
-
const s = i == null ? void 0 : i.extensions[
|
|
319
|
+
const s = i == null ? void 0 : i.extensions[I];
|
|
318
320
|
if (s) {
|
|
319
321
|
if (!s.lods) {
|
|
320
|
-
|
|
322
|
+
L && console.warn("Texture has no LODs", s);
|
|
321
323
|
return;
|
|
322
324
|
}
|
|
323
325
|
let o = !1;
|
|
324
326
|
for (const a of this.parser.associations.keys())
|
|
325
|
-
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));
|
|
326
328
|
o || this.parser.getDependency("texture", n).then((a) => {
|
|
327
|
-
a &&
|
|
329
|
+
a && v.registerTexture(this.url, a, s.lods.length, n, s);
|
|
328
330
|
});
|
|
329
331
|
}
|
|
330
332
|
}
|
|
331
333
|
}), (r = this.parser.json.meshes) == null || r.forEach((i, n) => {
|
|
332
334
|
if (i != null && i.extensions) {
|
|
333
|
-
const s = i == null ? void 0 : i.extensions[
|
|
335
|
+
const s = i == null ? void 0 : i.extensions[I];
|
|
334
336
|
if (s && s.lods) {
|
|
335
337
|
for (const o of this.parser.associations.keys())
|
|
336
338
|
if (o.isMesh) {
|
|
337
339
|
const a = this.parser.associations.get(o);
|
|
338
|
-
a.meshes === n &&
|
|
340
|
+
a.meshes === n && v.registerMesh(this.url, s.guid, o, s.lods.length, a.primitives, s);
|
|
339
341
|
}
|
|
340
342
|
}
|
|
341
343
|
}
|
|
342
344
|
}), null;
|
|
343
345
|
}
|
|
344
346
|
static async getOrLoadLOD(e, t) {
|
|
345
|
-
var o, a,
|
|
346
|
-
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);
|
|
347
349
|
if (!i)
|
|
348
350
|
return null;
|
|
349
351
|
const n = i == null ? void 0 : i.key;
|
|
350
352
|
let s;
|
|
351
353
|
if (e.isTexture === !0) {
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
+
const M = e;
|
|
355
|
+
M.source && M.source[ie] && (s = M.source[ie]);
|
|
354
356
|
}
|
|
355
|
-
if (s || (s =
|
|
357
|
+
if (s || (s = v.lodInfos.get(n)), s) {
|
|
356
358
|
if (t > 0) {
|
|
357
359
|
let y = !1;
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
360
|
+
const h = Array.isArray(s.lods);
|
|
361
|
+
if (h && t >= s.lods.length ? y = !0 : h || (y = !0), y)
|
|
360
362
|
return this.lowresCache.get(n);
|
|
361
363
|
}
|
|
362
|
-
const
|
|
363
|
-
if (!
|
|
364
|
-
return
|
|
365
|
-
const
|
|
366
|
-
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")) {
|
|
367
369
|
if (!s.guid)
|
|
368
370
|
return console.warn("missing pointer for glb/gltf texture", s), null;
|
|
369
|
-
const y =
|
|
370
|
-
if (
|
|
371
|
+
const y = D + "_" + s.guid, h = this.previouslyLoaded.get(y);
|
|
372
|
+
if (h !== void 0) {
|
|
371
373
|
r && console.log(`LOD ${t} was already loading/loaded: ${y}`);
|
|
372
|
-
let
|
|
373
|
-
`,
|
|
374
|
-
if (
|
|
375
|
-
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;
|
|
376
378
|
}
|
|
377
|
-
const
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
let
|
|
381
|
-
if (
|
|
382
|
-
const
|
|
383
|
-
|
|
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);
|
|
384
386
|
}
|
|
385
|
-
const
|
|
386
|
-
`,
|
|
387
|
-
if (!
|
|
387
|
+
const x = await G.loadAsync(re).catch((m) => (console.error(`Error loading LOD ${t} from ${D}
|
|
388
|
+
`, m), null));
|
|
389
|
+
if (!x)
|
|
388
390
|
return null;
|
|
389
|
-
const
|
|
390
|
-
r && console.log("Loading finished " +
|
|
391
|
-
let
|
|
392
|
-
if (
|
|
393
|
-
let
|
|
394
|
-
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) {
|
|
395
397
|
if (u != null && u.extensions) {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
|
|
398
|
+
const S = u == null ? void 0 : u.extensions[I];
|
|
399
|
+
if (S != null && S.guid && S.guid === w.guid) {
|
|
400
|
+
m = !0;
|
|
399
401
|
break;
|
|
400
402
|
}
|
|
401
403
|
}
|
|
402
|
-
|
|
404
|
+
_++;
|
|
403
405
|
}
|
|
404
|
-
if (
|
|
405
|
-
let u = await
|
|
406
|
-
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);
|
|
407
409
|
} else
|
|
408
|
-
|
|
410
|
+
L && console.warn("Could not find texture with guid", w.guid);
|
|
409
411
|
}
|
|
410
|
-
if (
|
|
411
|
-
let
|
|
412
|
-
for (const u of
|
|
412
|
+
if (_ = 0, x.parser.json.meshes) {
|
|
413
|
+
let m = !1;
|
|
414
|
+
for (const u of x.parser.json.meshes) {
|
|
413
415
|
if (u != null && u.extensions) {
|
|
414
|
-
const
|
|
415
|
-
if (
|
|
416
|
-
|
|
416
|
+
const S = u == null ? void 0 : u.extensions[I];
|
|
417
|
+
if (S != null && S.guid && S.guid === w.guid) {
|
|
418
|
+
m = !0;
|
|
417
419
|
break;
|
|
418
420
|
}
|
|
419
421
|
}
|
|
420
|
-
|
|
422
|
+
_++;
|
|
421
423
|
}
|
|
422
|
-
if (
|
|
423
|
-
const u = await
|
|
424
|
-
if (r && console.log(`Loaded Mesh "${u.name}"`,
|
|
425
|
-
const
|
|
426
|
-
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);
|
|
427
429
|
} else {
|
|
428
|
-
const
|
|
429
|
-
for (let
|
|
430
|
-
const
|
|
431
|
-
if (
|
|
432
|
-
const
|
|
433
|
-
|
|
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);
|
|
434
436
|
}
|
|
435
437
|
}
|
|
436
|
-
return
|
|
438
|
+
return b(R);
|
|
437
439
|
}
|
|
438
440
|
}
|
|
439
441
|
}
|
|
440
|
-
return
|
|
442
|
+
return b(null);
|
|
441
443
|
});
|
|
442
|
-
return this.previouslyLoaded.set(y,
|
|
443
|
-
} else if (e instanceof
|
|
444
|
-
r && console.log("Load texture from uri: " +
|
|
445
|
-
const
|
|
446
|
-
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;
|
|
447
449
|
}
|
|
448
450
|
} else
|
|
449
|
-
|
|
451
|
+
L && console.warn(`Can not load LOD ${t}: no LOD info found for "${n}" ${e.name}`, e.type);
|
|
450
452
|
return null;
|
|
451
453
|
}
|
|
452
454
|
static assignLODInformation(e, t, r, i, n, s) {
|
|
453
455
|
if (!t)
|
|
454
456
|
return;
|
|
455
457
|
t.userData || (t.userData = {});
|
|
456
|
-
const o = new
|
|
457
|
-
t.userData.LODS =
|
|
458
|
+
const o = new Re(e, r, i, n, s);
|
|
459
|
+
t.userData.LODS = () => o;
|
|
458
460
|
}
|
|
459
461
|
static getAssignedLODInformation(e) {
|
|
460
|
-
var t;
|
|
461
|
-
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;
|
|
462
464
|
}
|
|
463
465
|
// private static readonly _copiedTextures: WeakMap<Texture, Texture> = new Map();
|
|
464
466
|
static copySettings(e, t) {
|
|
465
|
-
return t = t.clone(),
|
|
467
|
+
return t = t.clone(), L && console.warn(`Copying texture settings
|
|
466
468
|
`, e.uuid, `
|
|
467
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;
|
|
468
470
|
}
|
|
469
471
|
};
|
|
470
|
-
let
|
|
472
|
+
let T = v;
|
|
471
473
|
/**
|
|
472
474
|
* Register a texture with LOD information
|
|
473
475
|
*/
|
|
474
|
-
c(
|
|
475
|
-
if (
|
|
476
|
-
|
|
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");
|
|
477
479
|
return;
|
|
478
480
|
}
|
|
479
|
-
t.source && (t.source[
|
|
481
|
+
t.source && (t.source[ie] = n);
|
|
480
482
|
const s = n.guid;
|
|
481
|
-
|
|
483
|
+
v.assignLODInformation(e, t, s, r, i, void 0), v.lodInfos.set(s, n), v.lowresCache.set(s, t);
|
|
482
484
|
}), /**
|
|
483
485
|
* Register a mesh with LOD information
|
|
484
486
|
*/
|
|
485
|
-
c(
|
|
486
|
-
var
|
|
487
|
-
|
|
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);
|
|
488
490
|
const o = r.geometry;
|
|
489
491
|
if (!o) {
|
|
490
|
-
|
|
492
|
+
L && console.warn("gltf-progressive: Register mesh without geometry");
|
|
491
493
|
return;
|
|
492
494
|
}
|
|
493
|
-
o.userData || (o.userData = {}),
|
|
494
|
-
let a =
|
|
495
|
-
a ? a.push(r.geometry) : a = [r.geometry],
|
|
496
|
-
for (const
|
|
497
|
-
(
|
|
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);
|
|
498
500
|
}), /** A map of key = asset uuid and value = LOD information */
|
|
499
|
-
c(
|
|
500
|
-
c(
|
|
501
|
-
c(
|
|
502
|
-
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 {
|
|
503
505
|
constructor(e, t, r, i, n) {
|
|
504
506
|
c(this, "url");
|
|
505
507
|
/** the key to lookup the LOD information */
|
|
@@ -512,12 +514,12 @@ class Ee {
|
|
|
512
514
|
this.url = e, this.key = t, this.level = r, i != null && (this.index = i), n != null && (this.density = n);
|
|
513
515
|
}
|
|
514
516
|
}
|
|
515
|
-
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 {
|
|
516
518
|
// readonly plugins: NEEDLE_progressive_plugin[] = [];
|
|
517
519
|
constructor(e) {
|
|
518
520
|
c(this, "renderer");
|
|
519
|
-
c(this, "projectionScreenMatrix", new
|
|
520
|
-
c(this, "cameraFrustrum", new
|
|
521
|
+
c(this, "projectionScreenMatrix", new fe());
|
|
522
|
+
c(this, "cameraFrustrum", new Te());
|
|
521
523
|
/**
|
|
522
524
|
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
523
525
|
* @default 200_000
|
|
@@ -534,26 +536,25 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
534
536
|
c(this, "_frame", 0);
|
|
535
537
|
c(this, "_originalRender");
|
|
536
538
|
// private testIfLODLevelsAreAvailable() {
|
|
537
|
-
c(this, "_sphere", new
|
|
538
|
-
c(this, "_tempBox", new
|
|
539
|
-
c(this, "_tempBox2", new
|
|
540
|
-
c(this, "tempMatrix", new
|
|
541
|
-
c(this, "_tempWorldPosition", new
|
|
542
|
-
c(this, "_tempBoxSize", new
|
|
543
|
-
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());
|
|
544
546
|
this.renderer = e;
|
|
545
547
|
}
|
|
546
548
|
/** @internal */
|
|
547
549
|
static getObjectLODState(e) {
|
|
548
|
-
|
|
549
|
-
return (t = e.userData) == null ? void 0 : t.LOD_state;
|
|
550
|
+
return e[ne];
|
|
550
551
|
}
|
|
551
552
|
static addPlugin(e) {
|
|
552
|
-
|
|
553
|
+
$.push(e);
|
|
553
554
|
}
|
|
554
555
|
static removePlugin(e) {
|
|
555
|
-
const t =
|
|
556
|
-
t >= 0 &&
|
|
556
|
+
const t = $.indexOf(e);
|
|
557
|
+
t >= 0 && $.splice(t, 1);
|
|
557
558
|
}
|
|
558
559
|
/**
|
|
559
560
|
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
@@ -561,11 +562,11 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
561
562
|
* @returns The LODsManager instance.
|
|
562
563
|
*/
|
|
563
564
|
static get(e) {
|
|
564
|
-
return e[
|
|
565
|
+
return e[ge] ? e[ge] : new A(e);
|
|
565
566
|
}
|
|
566
567
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
567
568
|
get plugins() {
|
|
568
|
-
return
|
|
569
|
+
return $;
|
|
569
570
|
}
|
|
570
571
|
/**
|
|
571
572
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
@@ -576,7 +577,7 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
576
577
|
let e = 0;
|
|
577
578
|
this._originalRender = this.renderer.render;
|
|
578
579
|
const t = this;
|
|
579
|
-
|
|
580
|
+
ye(this.renderer), this.renderer.render = function(r, i) {
|
|
580
581
|
t.renderer.getRenderTarget() == null && (e = 0, t._frame += 1);
|
|
581
582
|
const s = t._frame, o = e++;
|
|
582
583
|
t.onBeforeRender(r, i, o, s), t._originalRender.call(this, r, i), t.onAfterRender(r, i, o, s);
|
|
@@ -588,26 +589,26 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
588
589
|
onBeforeRender(e, t, r, i) {
|
|
589
590
|
}
|
|
590
591
|
onAfterRender(e, t, r, i) {
|
|
591
|
-
var a,
|
|
592
|
+
var a, d;
|
|
592
593
|
if (this.pause)
|
|
593
594
|
return;
|
|
594
595
|
const n = this.renderer.renderLists.get(e, 0), s = n.opaque;
|
|
595
596
|
let o = !0;
|
|
596
597
|
if (s.length === 1) {
|
|
597
|
-
const
|
|
598
|
-
(
|
|
598
|
+
const f = s[0].material;
|
|
599
|
+
(f.name === "EffectMaterial" || f.name === "CopyShader") && (o = !1);
|
|
599
600
|
}
|
|
600
601
|
if (t.parent && t.parent.type === "CubeCamera" && (o = !1), o) {
|
|
601
|
-
if (
|
|
602
|
+
if (Ee || this.updateInterval > 0 && i % this.updateInterval != 0)
|
|
602
603
|
return;
|
|
603
604
|
this.projectionScreenMatrix.multiplyMatrices(t.projectionMatrix, t.matrixWorldInverse), this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
|
|
604
|
-
const
|
|
605
|
-
for (const
|
|
606
|
-
if (
|
|
607
|
-
|
|
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)));
|
|
608
609
|
continue;
|
|
609
610
|
}
|
|
610
|
-
switch (
|
|
611
|
+
switch (g.material.type) {
|
|
611
612
|
case "LineBasicMaterial":
|
|
612
613
|
case "LineDashedMaterial":
|
|
613
614
|
case "PointsMaterial":
|
|
@@ -616,34 +617,34 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
616
617
|
case "MeshDepthMaterial":
|
|
617
618
|
continue;
|
|
618
619
|
}
|
|
619
|
-
const
|
|
620
|
-
(
|
|
620
|
+
const M = g.object;
|
|
621
|
+
(M instanceof N || M.isMesh) && this.updateLODs(e, t, M, f, i);
|
|
621
622
|
}
|
|
622
|
-
const
|
|
623
|
-
for (const
|
|
624
|
-
const
|
|
625
|
-
(
|
|
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);
|
|
626
627
|
}
|
|
627
628
|
}
|
|
628
629
|
}
|
|
629
630
|
/** Update the LOD levels for the renderer. */
|
|
630
631
|
updateLODs(e, t, r, i, n) {
|
|
631
|
-
var a,
|
|
632
|
+
var a, d;
|
|
632
633
|
r.userData || (r.userData = {});
|
|
633
|
-
let s = r
|
|
634
|
-
if (s || (s = new
|
|
634
|
+
let s = r[ne];
|
|
635
|
+
if (s || (s = new Ie(), r[ne] = s), s.frames++ < 2)
|
|
635
636
|
return;
|
|
636
|
-
for (const
|
|
637
|
-
(a =
|
|
638
|
-
this.calculateLodLevel(t, r, s, i,
|
|
639
|
-
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;
|
|
640
641
|
if (r.material && o >= 0) {
|
|
641
|
-
const
|
|
642
|
-
|
|
642
|
+
const f = r["DEBUG:LOD"];
|
|
643
|
+
f != null && (o = f), this.loadProgressiveTextures(r.material, o);
|
|
643
644
|
}
|
|
644
|
-
for (const
|
|
645
|
-
(
|
|
646
|
-
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;
|
|
647
648
|
}
|
|
648
649
|
/** Load progressive textures for the given material
|
|
649
650
|
* @param material the material to load the textures for
|
|
@@ -654,13 +655,12 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
654
655
|
if (!e)
|
|
655
656
|
return;
|
|
656
657
|
if (Array.isArray(e)) {
|
|
657
|
-
for (const
|
|
658
|
-
this.loadProgressiveTextures(
|
|
658
|
+
for (const i of e)
|
|
659
|
+
this.loadProgressiveTextures(i, t);
|
|
659
660
|
return;
|
|
660
661
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
(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));
|
|
664
664
|
}
|
|
665
665
|
/** Load progressive meshes for the given mesh
|
|
666
666
|
* @param mesh the mesh to load the LOD for
|
|
@@ -671,10 +671,10 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
671
671
|
loadProgressiveMeshes(e, t) {
|
|
672
672
|
if (!e)
|
|
673
673
|
return Promise.resolve(null);
|
|
674
|
-
if (e
|
|
675
|
-
e
|
|
674
|
+
if (e[K] !== t) {
|
|
675
|
+
e[K] = t;
|
|
676
676
|
const r = e.geometry;
|
|
677
|
-
return
|
|
677
|
+
return T.assignMeshLOD(e, t).then((i) => (i && e[K] == t && r != e.geometry, i));
|
|
678
678
|
}
|
|
679
679
|
return Promise.resolve(null);
|
|
680
680
|
}
|
|
@@ -683,7 +683,7 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
683
683
|
return this._tempPtInside.set(n, s, r.z).applyMatrix4(t).z < 0;
|
|
684
684
|
}
|
|
685
685
|
calculateLodLevel(e, t, r, i, n) {
|
|
686
|
-
var
|
|
686
|
+
var D;
|
|
687
687
|
if (!t) {
|
|
688
688
|
n.mesh_lod = -1, n.texture_lod = -1;
|
|
689
689
|
return;
|
|
@@ -693,24 +693,24 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
693
693
|
return;
|
|
694
694
|
}
|
|
695
695
|
let o = 10 + 1;
|
|
696
|
-
if (
|
|
696
|
+
if (W && t["DEBUG:LOD"] != null)
|
|
697
697
|
return t["DEBUG:LOD"];
|
|
698
|
-
const a =
|
|
699
|
-
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) {
|
|
700
700
|
n.mesh_lod = 0, n.texture_lod = 0;
|
|
701
701
|
return;
|
|
702
702
|
}
|
|
703
|
-
if (
|
|
703
|
+
if (f || (o = 0), !((D = this.cameraFrustrum) != null && D.intersectsObject(t))) {
|
|
704
704
|
n.mesh_lod = 99, n.texture_lod = 99;
|
|
705
705
|
return;
|
|
706
706
|
}
|
|
707
|
-
let
|
|
707
|
+
let M = t.geometry.boundingBox;
|
|
708
708
|
if (t.type === "SkinnedMesh") {
|
|
709
|
-
const
|
|
710
|
-
|
|
709
|
+
const y = t;
|
|
710
|
+
y.boundingBox || y.computeBoundingBox(), M = y.boundingBox;
|
|
711
711
|
}
|
|
712
|
-
if (
|
|
713
|
-
const
|
|
712
|
+
if (M && e.isPerspectiveCamera) {
|
|
713
|
+
const y = e;
|
|
714
714
|
if (t.geometry.attributes.color && t.geometry.attributes.color.count < 100 && t.geometry.boundingSphere) {
|
|
715
715
|
this._sphere.copy(t.geometry.boundingSphere), this._sphere.applyMatrix4(t.matrixWorld);
|
|
716
716
|
const x = e.getWorldPosition(this._tempWorldPosition);
|
|
@@ -719,54 +719,54 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
719
719
|
return;
|
|
720
720
|
}
|
|
721
721
|
}
|
|
722
|
-
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)) {
|
|
723
723
|
n.mesh_lod = 0, n.texture_lod = 0;
|
|
724
724
|
return;
|
|
725
725
|
}
|
|
726
|
-
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled &&
|
|
727
|
-
const x = this._tempBox.min,
|
|
728
|
-
let
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
const
|
|
732
|
-
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);
|
|
733
733
|
} else
|
|
734
734
|
r.lastCentrality = 1;
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
const
|
|
740
|
-
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) {
|
|
741
741
|
const x = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
742
742
|
x.invert();
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
const
|
|
746
|
-
|
|
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);
|
|
747
747
|
}
|
|
748
|
-
let
|
|
749
|
-
if (
|
|
750
|
-
for (let x = 0; x <
|
|
751
|
-
if (
|
|
752
|
-
|
|
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;
|
|
753
753
|
break;
|
|
754
754
|
}
|
|
755
755
|
}
|
|
756
|
-
|
|
756
|
+
G < o && (o = G);
|
|
757
757
|
}
|
|
758
|
-
if (n.mesh_lod = o,
|
|
758
|
+
if (n.mesh_lod = o, g)
|
|
759
759
|
if (r.lastLodLevel_Texture < 0) {
|
|
760
|
-
if (n.texture_lod =
|
|
761
|
-
const
|
|
762
|
-
|
|
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}`);
|
|
763
763
|
}
|
|
764
764
|
} else {
|
|
765
|
-
const
|
|
766
|
-
for (let
|
|
767
|
-
const
|
|
768
|
-
if (!(
|
|
769
|
-
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}`);
|
|
770
770
|
break;
|
|
771
771
|
}
|
|
772
772
|
}
|
|
@@ -775,22 +775,22 @@ const U = j("debugprogressive"), Be = j("noprogressive"), fe = Symbol("Needle:LO
|
|
|
775
775
|
n.texture_lod = 0;
|
|
776
776
|
}
|
|
777
777
|
};
|
|
778
|
-
let
|
|
778
|
+
let C = A;
|
|
779
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.
|
|
780
780
|
*/
|
|
781
|
-
c(
|
|
782
|
-
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 {
|
|
783
783
|
constructor() {
|
|
784
784
|
c(this, "frames", 0);
|
|
785
785
|
c(this, "lastLodLevel_Mesh", -1);
|
|
786
786
|
c(this, "lastLodLevel_Texture", -1);
|
|
787
787
|
c(this, "lastScreenCoverage", 0);
|
|
788
|
-
c(this, "lastScreenspaceVolume", new
|
|
788
|
+
c(this, "lastScreenspaceVolume", new E());
|
|
789
789
|
c(this, "lastCentrality", 0);
|
|
790
790
|
}
|
|
791
791
|
}
|
|
792
|
-
const
|
|
793
|
-
function
|
|
792
|
+
const pe = Symbol("NEEDLE_mesh_lod"), j = Symbol("NEEDLE_texture_lod");
|
|
793
|
+
function Ge(l) {
|
|
794
794
|
if (!l)
|
|
795
795
|
return null;
|
|
796
796
|
let e = null, t = null;
|
|
@@ -800,8 +800,8 @@ function ke(l) {
|
|
|
800
800
|
}
|
|
801
801
|
if (e) {
|
|
802
802
|
console.log("Adding Needle LODs to modelviewer");
|
|
803
|
-
const r =
|
|
804
|
-
if (
|
|
803
|
+
const r = C.get(e);
|
|
804
|
+
if (C.addPlugin(new Fe(l)), r.enable(), t) {
|
|
805
805
|
const i = t.camera || t.traverse((n) => n.type == "PerspectiveCamera")[0];
|
|
806
806
|
i && e.render(t, i);
|
|
807
807
|
}
|
|
@@ -811,7 +811,7 @@ function ke(l) {
|
|
|
811
811
|
}
|
|
812
812
|
return null;
|
|
813
813
|
}
|
|
814
|
-
class
|
|
814
|
+
class Fe {
|
|
815
815
|
constructor(e) {
|
|
816
816
|
c(this, "modelviewer");
|
|
817
817
|
c(this, "_didWarnAboutMissingUrl", !1);
|
|
@@ -828,28 +828,28 @@ class Re {
|
|
|
828
828
|
return e._currentGLTF;
|
|
829
829
|
}
|
|
830
830
|
tryParseTextureLOD(e, t) {
|
|
831
|
-
if (t[
|
|
831
|
+
if (t[j] == !0)
|
|
832
832
|
return;
|
|
833
|
-
t[
|
|
833
|
+
t[j] = !0;
|
|
834
834
|
const r = this.tryGetCurrentGLTF(e), i = this.getUrl();
|
|
835
835
|
if (i && r && t.material) {
|
|
836
836
|
let n = function(o) {
|
|
837
|
-
var
|
|
838
|
-
if (o[
|
|
837
|
+
var d, f, p;
|
|
838
|
+
if (o[j] == !0)
|
|
839
839
|
return;
|
|
840
|
-
o[
|
|
840
|
+
o[j] = !0, o.userData && (o.userData.LOD = -1);
|
|
841
841
|
const a = Object.keys(o);
|
|
842
|
-
for (let
|
|
843
|
-
const
|
|
844
|
-
if ((
|
|
845
|
-
const
|
|
846
|
-
if (!
|
|
847
|
-
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);
|
|
848
848
|
continue;
|
|
849
849
|
}
|
|
850
|
-
if ((
|
|
851
|
-
const
|
|
852
|
-
|
|
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);
|
|
853
853
|
}
|
|
854
854
|
}
|
|
855
855
|
}
|
|
@@ -864,38 +864,38 @@ class Re {
|
|
|
864
864
|
}
|
|
865
865
|
tryParseMeshLOD(e, t) {
|
|
866
866
|
var n, s;
|
|
867
|
-
if (t[
|
|
867
|
+
if (t[pe] == !0)
|
|
868
868
|
return;
|
|
869
|
-
t[
|
|
869
|
+
t[pe] = !0;
|
|
870
870
|
const r = this.getUrl();
|
|
871
871
|
if (!r)
|
|
872
872
|
return;
|
|
873
|
-
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];
|
|
874
874
|
if (i && r) {
|
|
875
875
|
const o = t.uuid;
|
|
876
|
-
|
|
876
|
+
T.registerMesh(r, o, t, 0, i.lods.length, i);
|
|
877
877
|
}
|
|
878
878
|
}
|
|
879
879
|
}
|
|
880
|
-
function
|
|
881
|
-
|
|
882
|
-
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);
|
|
883
883
|
return (r == null ? void 0 : r.enableLODsManager) !== !1 && i.enable(), i;
|
|
884
884
|
}
|
|
885
885
|
document.addEventListener("DOMContentLoaded", () => {
|
|
886
|
-
|
|
886
|
+
Ge(document.querySelector("model-viewer"));
|
|
887
887
|
});
|
|
888
888
|
export {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
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
|
|
901
901
|
};
|