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