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