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