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