@needle-tools/engine 4.8.8 → 4.8.9-next.5e888f7
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 +10 -0
- package/README.md +50 -45
- package/components.needle.json +1 -1
- package/dist/gltf-progressive-DWiyqrwB.umd.cjs +8 -0
- package/dist/gltf-progressive-DhE1A6hX.min.js +8 -0
- package/dist/{gltf-progressive-BcHT3Nyo.js → gltf-progressive-egsMzRdv.js} +384 -369
- package/dist/{needle-engine.bundle-CK8rTkFm.umd.cjs → needle-engine.bundle-B8QgMEWj.umd.cjs} +145 -145
- package/dist/{needle-engine.bundle-C071tpzX.js → needle-engine.bundle-CBk4h0tH.js} +8352 -8106
- package/dist/{needle-engine.bundle--H5L0liy.min.js → needle-engine.bundle-CF7LvCm4.min.js} +148 -148
- package/dist/needle-engine.d.ts +7 -0
- package/dist/needle-engine.js +305 -301
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-Ywv5oKkX.min.js → postprocessing-B_FzkwDz.min.js} +1 -1
- package/dist/{postprocessing-ORx-0eCx.js → postprocessing-DP1U_BpT.js} +2 -2
- package/dist/{postprocessing-CVb_x9YY.umd.cjs → postprocessing-DTX5VXrj.umd.cjs} +1 -1
- package/dist/{three-Dceyffus.umd.cjs → three-BK56xWDs.umd.cjs} +24 -24
- package/dist/{three-BRSLmpyi.js → three-CsHK73Zc.js} +1 -0
- package/dist/{three-CsmWHVn7.min.js → three-TNFQHSFa.min.js} +25 -25
- package/dist/{three-examples-BX_Sktc9.min.js → three-examples-Bph291U2.min.js} +1 -1
- package/dist/{three-examples-CNexix3E.js → three-examples-BvMpKSun.js} +1 -1
- package/dist/{three-examples-DWxXVnws.umd.cjs → three-examples-C9WfZu-X.umd.cjs} +1 -1
- package/dist/{three-mesh-ui-gqAXlGNB.js → three-mesh-ui-CN6aRT7i.js} +1 -1
- package/dist/{three-mesh-ui-Cdh2iW8b.umd.cjs → three-mesh-ui-DnxkZWNA.umd.cjs} +1 -1
- package/dist/{three-mesh-ui-Bwy12Qvg.min.js → three-mesh-ui-n_qS2BM-.min.js} +1 -1
- package/dist/{vendor-xfQ8tKF3.umd.cjs → vendor-8le8g4MS.umd.cjs} +1 -1
- package/dist/{vendor-Z4SPrTcP.js → vendor-Msb9AgYE.js} +1 -1
- package/dist/{vendor-C43vobGc.min.js → vendor-yDFiCnCw.min.js} +1 -1
- package/lib/engine/codegen/register_types.js +4 -0
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/engine_addressables.js +2 -0
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_animation.js +4 -4
- package/lib/engine/engine_animation.js.map +1 -1
- package/lib/engine/engine_assetdatabase.js +6 -6
- package/lib/engine/engine_assetdatabase.js.map +1 -1
- package/lib/engine/engine_camera.d.ts +15 -2
- package/lib/engine/engine_camera.js +9 -2
- package/lib/engine/engine_camera.js.map +1 -1
- package/lib/engine/engine_context.d.ts +8 -2
- package/lib/engine/engine_context.js +21 -3
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_create_objects.d.ts +3 -3
- package/lib/engine/engine_create_objects.js +5 -4
- package/lib/engine/engine_create_objects.js.map +1 -1
- package/lib/engine/engine_gameobject.js +2 -2
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +11 -11
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_loaders.callbacks.d.ts +1 -0
- package/lib/engine/engine_loaders.callbacks.js +1 -0
- package/lib/engine/engine_loaders.callbacks.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_lighting_settings.js +5 -2
- package/lib/engine/extensions/NEEDLE_lighting_settings.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_lightmaps.js +1 -1
- package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
- package/lib/engine/js-extensions/Object3D.d.ts +1 -1
- package/lib/engine/js-extensions/Vector.d.ts +5 -0
- package/lib/engine/js-extensions/Vector.js.map +1 -1
- package/lib/engine/js-extensions/index.d.ts +2 -1
- package/lib/engine/js-extensions/index.js +1 -1
- package/lib/engine/js-extensions/index.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.d.ts +2 -2
- package/lib/engine/webcomponents/needle-engine.js +11 -18
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +2 -0
- package/lib/engine-components/Camera.js +5 -1
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/ContactShadows.d.ts +12 -2
- package/lib/engine-components/ContactShadows.js +24 -4
- package/lib/engine-components/ContactShadows.js.map +1 -1
- package/lib/engine-components/DropListener.d.ts +4 -3
- package/lib/engine-components/DropListener.js +4 -3
- package/lib/engine-components/DropListener.js.map +1 -1
- package/lib/engine-components/NestedGltf.d.ts +9 -4
- package/lib/engine-components/NestedGltf.js +32 -26
- package/lib/engine-components/NestedGltf.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +29 -6
- package/lib/engine-components/OrbitControls.js +45 -9
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/Renderer.js +2 -1
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/Skybox.js +8 -9
- package/lib/engine-components/Skybox.js.map +1 -1
- package/lib/engine-components/api.d.ts +2 -0
- package/lib/engine-components/api.js +1 -0
- package/lib/engine-components/api.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +3 -0
- package/lib/engine-components/codegen/components.js +3 -0
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/behavior/Behaviour.d.ts +1 -1
- package/lib/engine-components/splines/Spline.d.ts +58 -0
- package/lib/engine-components/splines/Spline.js +270 -0
- package/lib/engine-components/splines/Spline.js.map +1 -0
- package/lib/engine-components/splines/SplineUtils.d.ts +12 -0
- package/lib/engine-components/splines/SplineUtils.js +33 -0
- package/lib/engine-components/splines/SplineUtils.js.map +1 -0
- package/lib/engine-components/splines/SplineWalker.d.ts +47 -0
- package/lib/engine-components/splines/SplineWalker.js +113 -0
- package/lib/engine-components/splines/SplineWalker.js.map +1 -0
- package/lib/engine-components/splines/index.d.ts +3 -0
- package/lib/engine-components/splines/index.js +4 -0
- package/lib/engine-components/splines/index.js.map +1 -0
- package/package.json +4 -4
- package/plugins/common/files.js +6 -3
- package/plugins/vite/alias.js +3 -2
- package/plugins/vite/editor-connection.js +4 -4
- package/src/engine/codegen/register_types.ts +4 -0
- package/src/engine/engine_addressables.ts +2 -0
- package/src/engine/engine_animation.ts +4 -4
- package/src/engine/engine_assetdatabase.ts +7 -7
- package/src/engine/engine_camera.ts +15 -3
- package/src/engine/engine_context.ts +22 -4
- package/src/engine/engine_create_objects.ts +8 -7
- package/src/engine/engine_gameobject.ts +2 -2
- package/src/engine/engine_gltf_builtin_components.ts +12 -11
- package/src/engine/engine_loaders.callbacks.ts +1 -0
- package/src/engine/extensions/NEEDLE_lighting_settings.ts +5 -2
- package/src/engine/extensions/NEEDLE_lightmaps.ts +1 -1
- package/src/engine/js-extensions/Vector.ts +6 -0
- package/src/engine/js-extensions/index.ts +3 -2
- package/src/engine/webcomponents/needle-engine.ts +10 -17
- package/src/engine-components/Camera.ts +7 -1
- package/src/engine-components/ContactShadows.ts +27 -6
- package/src/engine-components/DropListener.ts +4 -3
- package/src/engine-components/NestedGltf.ts +33 -24
- package/src/engine-components/OrbitControls.ts +67 -21
- package/src/engine-components/Renderer.ts +2 -1
- package/src/engine-components/Skybox.ts +9 -10
- package/src/engine-components/api.ts +3 -1
- package/src/engine-components/codegen/components.ts +3 -0
- package/src/engine-components/splines/Spline.ts +284 -0
- package/src/engine-components/splines/SplineUtils.ts +32 -0
- package/src/engine-components/splines/SplineWalker.ts +106 -0
- package/src/engine-components/splines/index.ts +3 -0
- package/dist/gltf-progressive-CH3Q4H06.umd.cjs +0 -8
- package/dist/gltf-progressive-DR6HqF_h.min.js +0 -8
|
@@ -1,96 +1,92 @@
|
|
|
1
|
-
import { BufferGeometry as
|
|
2
|
-
import { DRACOLoader as
|
|
3
|
-
const
|
|
4
|
-
globalThis.GLTF_PROGRESSIVE_VERSION =
|
|
5
|
-
console.debug(
|
|
6
|
-
let
|
|
7
|
-
const Ye =
|
|
8
|
-
|
|
9
|
-
fetch(
|
|
1
|
+
import { BufferGeometry as J, Mesh as q, Box3 as ge, Vector3 as A, Sphere as Oe, CompressedTexture as Ge, Texture as E, Matrix3 as Fe, InterleavedBuffer as We, InterleavedBufferAttribute as Ue, BufferAttribute as ze, TextureLoader as Ee, Matrix4 as _e, Clock as Ne, MeshStandardMaterial as qe } from "./three-CsHK73Zc.js";
|
|
2
|
+
import { DRACOLoader as Ve, KTX2Loader as Xe, MeshoptDecoder as je, GLTFLoader as xe } from "./three-examples-BvMpKSun.js";
|
|
3
|
+
const Ke = "";
|
|
4
|
+
globalThis.GLTF_PROGRESSIVE_VERSION = Ke;
|
|
5
|
+
console.debug("[gltf-progressive] version -");
|
|
6
|
+
let C = "https://www.gstatic.com/draco/versioned/decoders/1.5.7/", V = "https://cdn.needle.tools/static/three/0.179.1/basis2/";
|
|
7
|
+
const Ye = C, He = V, Se = new URL(C + "draco_decoder.js");
|
|
8
|
+
Se.searchParams.append("range", "true");
|
|
9
|
+
fetch(Se, {
|
|
10
10
|
method: "GET",
|
|
11
11
|
headers: {
|
|
12
12
|
Range: "bytes=0-1"
|
|
13
13
|
}
|
|
14
|
-
}).catch((
|
|
15
|
-
console.debug(`Failed to fetch remote Draco decoder from ${
|
|
14
|
+
}).catch((i) => {
|
|
15
|
+
console.debug(`Failed to fetch remote Draco decoder from ${C} (offline: ${typeof navigator < "u" ? navigator.onLine : "unknown"})`), C === Ye && Je("./include/draco/"), V === He && Ze("./include/ktx2/");
|
|
16
16
|
}).finally(() => {
|
|
17
|
-
|
|
17
|
+
Pe();
|
|
18
18
|
});
|
|
19
19
|
const Qe = () => ({
|
|
20
|
-
dracoDecoderPath:
|
|
20
|
+
dracoDecoderPath: C,
|
|
21
21
|
ktx2TranscoderPath: V
|
|
22
22
|
});
|
|
23
|
-
function Je(
|
|
24
|
-
|
|
23
|
+
function Je(i) {
|
|
24
|
+
C = i, P && P[pe] != C ? (console.debug("Updating Draco decoder path to " + i), P[pe] = C, P.setDecoderPath(C), P.preload()) : console.debug("Setting Draco decoder path to " + i);
|
|
25
25
|
}
|
|
26
|
-
function Ze(
|
|
27
|
-
V =
|
|
26
|
+
function Ze(i) {
|
|
27
|
+
V = i, R && R.transcoderPath != V ? (console.debug("Updating KTX2 transcoder path to " + i), R.setTranscoderPath(V), R.init()) : console.debug("Setting KTX2 transcoder path to " + i);
|
|
28
28
|
}
|
|
29
|
-
function we(
|
|
30
|
-
return
|
|
29
|
+
function we(i) {
|
|
30
|
+
return Pe(), i ? R.detectSupport(i) : i !== null && console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"), { dracoLoader: P, ktx2Loader: R, meshoptDecoder: ne };
|
|
31
31
|
}
|
|
32
|
-
function Te(
|
|
33
|
-
|
|
32
|
+
function Te(i) {
|
|
33
|
+
i.dracoLoader || i.setDRACOLoader(P), i.ktx2Loader || i.setKTX2Loader(R), i.meshoptDecoder || i.setMeshoptDecoder(ne);
|
|
34
34
|
}
|
|
35
35
|
const pe = Symbol("dracoDecoderPath");
|
|
36
|
-
let
|
|
37
|
-
function
|
|
38
|
-
|
|
36
|
+
let P, ne, R;
|
|
37
|
+
function Pe() {
|
|
38
|
+
P || (P = new Ve(), P[pe] = C, P.setDecoderPath(C), P.setDecoderConfig({ type: "js" }), P.preload()), R || (R = new Xe(), R.setTranscoderPath(V), R.init()), ne || (ne = je);
|
|
39
39
|
}
|
|
40
40
|
const me = /* @__PURE__ */ new WeakMap();
|
|
41
|
-
function
|
|
42
|
-
let e = me.get(
|
|
43
|
-
e ? e = Object.assign(e, t) : e = t, me.set(
|
|
41
|
+
function Ae(i, t) {
|
|
42
|
+
let e = me.get(i);
|
|
43
|
+
e ? e = Object.assign(e, t) : e = t, me.set(i, e);
|
|
44
44
|
}
|
|
45
45
|
const et = xe.prototype.load;
|
|
46
|
-
function tt(...
|
|
46
|
+
function tt(...i) {
|
|
47
47
|
const t = me.get(this);
|
|
48
|
-
let e =
|
|
48
|
+
let e = i[0];
|
|
49
49
|
const s = new URL(e, window.location.href);
|
|
50
50
|
if (s.hostname.endsWith("needle.tools")) {
|
|
51
|
-
const r = t?.progressive !== void 0 ? t.progressive : !0,
|
|
52
|
-
r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${
|
|
51
|
+
const r = t?.progressive !== void 0 ? t.progressive : !0, o = t?.usecase ? t.usecase : "default";
|
|
52
|
+
r ? this.requestHeader.Accept = `*/*;progressive=allowed;usecase=${o}` : this.requestHeader.Accept = `*/*;usecase=${o}`, e = s.toString();
|
|
53
53
|
}
|
|
54
|
-
return
|
|
54
|
+
return i[0] = e, et?.call(this, ...i);
|
|
55
55
|
}
|
|
56
56
|
xe.prototype.load = tt;
|
|
57
57
|
X("debugprogressive");
|
|
58
|
-
function X(
|
|
59
|
-
if (typeof window > "u")
|
|
60
|
-
|
|
61
|
-
const e = new URL(window.location.href).searchParams.get(o);
|
|
58
|
+
function X(i) {
|
|
59
|
+
if (typeof window > "u") return !1;
|
|
60
|
+
const e = new URL(window.location.href).searchParams.get(i);
|
|
62
61
|
return e == null || e === "0" || e === "false" ? !1 : e === "" ? !0 : e;
|
|
63
62
|
}
|
|
64
|
-
function st(
|
|
65
|
-
if (t === void 0 || t.startsWith("./") || t.startsWith("http") ||
|
|
63
|
+
function st(i, t) {
|
|
64
|
+
if (t === void 0 || i === void 0 || t.startsWith("./") || t.startsWith("http") || t.startsWith("data:") || t.startsWith("blob:"))
|
|
66
65
|
return t;
|
|
67
|
-
const e =
|
|
66
|
+
const e = i.lastIndexOf("/");
|
|
68
67
|
if (e >= 0) {
|
|
69
|
-
const s =
|
|
70
|
-
for (; s.endsWith("/") && t.startsWith("/"); )
|
|
71
|
-
t = t.substring(1);
|
|
68
|
+
const s = i.substring(0, e + 1);
|
|
69
|
+
for (; s.endsWith("/") && t.startsWith("/"); ) t = t.substring(1);
|
|
72
70
|
return s + t;
|
|
73
71
|
}
|
|
74
72
|
return t;
|
|
75
73
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return j !== void 0 || (j = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), X("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", j)), j;
|
|
74
|
+
function Ie() {
|
|
75
|
+
return K !== void 0 || (K = /iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent), X("debugprogressive") && console.log("[glTF Progressive]: isMobileDevice", K)), K;
|
|
79
76
|
}
|
|
77
|
+
let K;
|
|
80
78
|
function Me() {
|
|
81
|
-
if (typeof window > "u")
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return o.hostname === "127.0.0.1" || t;
|
|
79
|
+
if (typeof window > "u") return !1;
|
|
80
|
+
const i = new URL(window.location.href), t = i.hostname === "localhost" || /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(i.hostname);
|
|
81
|
+
return i.hostname === "127.0.0.1" || t;
|
|
85
82
|
}
|
|
86
83
|
class rt {
|
|
87
|
-
maxConcurrent;
|
|
88
|
-
_running = /* @__PURE__ */ new Map();
|
|
89
|
-
_queue = [];
|
|
90
|
-
debug = !1;
|
|
91
84
|
constructor(t = 100, e = {}) {
|
|
92
85
|
this.maxConcurrent = t, this.debug = e.debug ?? !1, window.requestAnimationFrame(this.tick);
|
|
93
86
|
}
|
|
87
|
+
_running = /* @__PURE__ */ new Map();
|
|
88
|
+
_queue = [];
|
|
89
|
+
debug = !1;
|
|
94
90
|
tick = () => {
|
|
95
91
|
this.internalUpdate(), setTimeout(this.tick, 10);
|
|
96
92
|
};
|
|
@@ -119,72 +115,87 @@ class rt {
|
|
|
119
115
|
}
|
|
120
116
|
}
|
|
121
117
|
const nt = typeof window > "u" && typeof document > "u", ye = Symbol("needle:raycast-mesh");
|
|
122
|
-
function
|
|
123
|
-
return
|
|
118
|
+
function Z(i) {
|
|
119
|
+
return i?.[ye] instanceof J ? i[ye] : null;
|
|
124
120
|
}
|
|
125
|
-
function
|
|
126
|
-
if ((
|
|
121
|
+
function ot(i, t) {
|
|
122
|
+
if ((i.type === "Mesh" || i.type === "SkinnedMesh") && !Z(i)) {
|
|
127
123
|
const s = at(t);
|
|
128
|
-
s.userData = { isRaycastMesh: !0 },
|
|
124
|
+
s.userData = { isRaycastMesh: !0 }, i[ye] = s;
|
|
129
125
|
}
|
|
130
126
|
}
|
|
131
|
-
function
|
|
132
|
-
if (
|
|
133
|
-
if (Y)
|
|
134
|
-
return;
|
|
127
|
+
function it(i = !0) {
|
|
128
|
+
if (i) {
|
|
129
|
+
if (Y) return;
|
|
135
130
|
const t = Y = q.prototype.raycast;
|
|
136
131
|
q.prototype.raycast = function(e, s) {
|
|
137
|
-
const n = this, r =
|
|
138
|
-
let
|
|
139
|
-
r && n.isMesh && (
|
|
132
|
+
const n = this, r = Z(n);
|
|
133
|
+
let o;
|
|
134
|
+
r && n.isMesh && (o = n.geometry, n.geometry = r), t.call(this, e, s), o && (n.geometry = o);
|
|
140
135
|
};
|
|
141
136
|
} else {
|
|
142
|
-
if (!Y)
|
|
143
|
-
return;
|
|
137
|
+
if (!Y) return;
|
|
144
138
|
q.prototype.raycast = Y, Y = null;
|
|
145
139
|
}
|
|
146
140
|
}
|
|
147
141
|
let Y = null;
|
|
148
|
-
function at(
|
|
149
|
-
const t = new
|
|
150
|
-
for (const e in
|
|
151
|
-
t.setAttribute(e,
|
|
152
|
-
return t.setIndex(
|
|
142
|
+
function at(i) {
|
|
143
|
+
const t = new J();
|
|
144
|
+
for (const e in i.attributes)
|
|
145
|
+
t.setAttribute(e, i.getAttribute(e));
|
|
146
|
+
return t.setIndex(i.getIndex()), t;
|
|
153
147
|
}
|
|
154
|
-
const
|
|
155
|
-
let
|
|
148
|
+
const U = new Array(), g = X("debugprogressive");
|
|
149
|
+
let Q, N = -1;
|
|
156
150
|
if (g) {
|
|
157
|
-
let
|
|
158
|
-
N += 1, N >=
|
|
159
|
-
},
|
|
151
|
+
let i = function() {
|
|
152
|
+
N += 1, N >= t && (N = -1), console.log(`Toggle LOD level [${N}]`);
|
|
153
|
+
}, t = 6;
|
|
160
154
|
window.addEventListener("keyup", (e) => {
|
|
161
|
-
e.key === "p" &&
|
|
155
|
+
e.key === "p" && i(), e.key === "w" && (Q = !Q, console.log(`Toggle wireframe [${Q}]`));
|
|
162
156
|
const s = parseInt(e.key);
|
|
163
157
|
!isNaN(s) && s >= 0 && (N = s, console.log(`Set LOD level to [${N}]`));
|
|
164
158
|
});
|
|
165
159
|
}
|
|
166
|
-
function ke(
|
|
167
|
-
if (g)
|
|
168
|
-
if (Array.isArray(
|
|
169
|
-
for (const t of
|
|
160
|
+
function ke(i) {
|
|
161
|
+
if (g && Q !== void 0)
|
|
162
|
+
if (Array.isArray(i))
|
|
163
|
+
for (const t of i)
|
|
170
164
|
ke(t);
|
|
171
|
-
else
|
|
165
|
+
else i && "wireframe" in i && (i.wireframe = Q === !0);
|
|
172
166
|
}
|
|
173
167
|
const H = new Array();
|
|
174
168
|
let lt = 0;
|
|
175
|
-
const ut =
|
|
176
|
-
function dt(
|
|
169
|
+
const ut = Ie() ? 2 : 10;
|
|
170
|
+
function dt(i) {
|
|
177
171
|
if (H.length < ut) {
|
|
178
172
|
const s = H.length;
|
|
179
173
|
g && console.warn(`[Worker] Creating new worker #${s}`);
|
|
180
|
-
const n = Le.createWorker(
|
|
174
|
+
const n = Le.createWorker(i || {});
|
|
181
175
|
return H.push(n), n;
|
|
182
176
|
}
|
|
183
177
|
const t = lt++ % H.length;
|
|
184
178
|
return H[t];
|
|
185
179
|
}
|
|
186
180
|
class Le {
|
|
187
|
-
|
|
181
|
+
constructor(t, e) {
|
|
182
|
+
this.worker = t, this._debug = e.debug ?? !1, t.onmessage = (s) => {
|
|
183
|
+
const n = s.data;
|
|
184
|
+
switch (this._debug && console.log("[Worker] EVENT", n), n.type) {
|
|
185
|
+
case "loaded-gltf":
|
|
186
|
+
for (const r of this._running)
|
|
187
|
+
if (r.url === n.result.url) {
|
|
188
|
+
ct(n.result), r.resolve(n.result);
|
|
189
|
+
const o = r.url;
|
|
190
|
+
o.startsWith("blob:") && URL.revokeObjectURL(o);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}, t.onerror = (s) => {
|
|
194
|
+
console.error("[Worker] Error in gltf-progressive worker:", s);
|
|
195
|
+
}, t.postMessage({
|
|
196
|
+
type: "init"
|
|
197
|
+
});
|
|
198
|
+
}
|
|
188
199
|
static async createWorker(t) {
|
|
189
200
|
const e = new Worker(URL.createObjectURL(new Blob(["import '" + `${new URL('./loader.worker-CiTwpNPW.js', import.meta.url).toString()}` + "';"], { type: 'text/javascript' })), {
|
|
190
201
|
type: "module"
|
|
@@ -197,7 +208,7 @@ class Le {
|
|
|
197
208
|
const s = Qe();
|
|
198
209
|
let n = e?.renderer;
|
|
199
210
|
n || (this._webglRenderer ??= (async () => {
|
|
200
|
-
const { WebGLRenderer: u } = await import("./three-
|
|
211
|
+
const { WebGLRenderer: u } = await import("./three-CsHK73Zc.js").then((d) => d.THREE);
|
|
201
212
|
return new u();
|
|
202
213
|
})(), n = await this._webglRenderer);
|
|
203
214
|
const l = we(n).ktx2Loader.workerConfig;
|
|
@@ -217,68 +228,89 @@ class Le {
|
|
|
217
228
|
});
|
|
218
229
|
}
|
|
219
230
|
_debug = !1;
|
|
220
|
-
constructor(t, e) {
|
|
221
|
-
this.worker = t, this._debug = e.debug ?? !1, t.onmessage = (s) => {
|
|
222
|
-
const n = s.data;
|
|
223
|
-
switch (this._debug && console.log("[Worker] EVENT", n), n.type) {
|
|
224
|
-
case "loaded-gltf":
|
|
225
|
-
for (const r of this._running)
|
|
226
|
-
if (r.url === n.result.url) {
|
|
227
|
-
ct(n.result), r.resolve(n.result);
|
|
228
|
-
const i = r.url;
|
|
229
|
-
i.startsWith("blob:") && URL.revokeObjectURL(i);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}, t.onerror = (s) => {
|
|
233
|
-
console.error("[Worker] Error in gltf-progressive worker:", s);
|
|
234
|
-
}, t.postMessage({
|
|
235
|
-
type: "init"
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
231
|
}
|
|
239
|
-
function ct(
|
|
240
|
-
for (const t of
|
|
241
|
-
const e = t.geometry, s = new
|
|
232
|
+
function ct(i) {
|
|
233
|
+
for (const t of i.geometries) {
|
|
234
|
+
const e = t.geometry, s = new J();
|
|
242
235
|
if (s.name = e.name || "", e.index) {
|
|
243
236
|
const n = e.index;
|
|
244
237
|
s.setIndex(le(n));
|
|
245
238
|
}
|
|
246
239
|
for (const n in e.attributes) {
|
|
247
|
-
const r = e.attributes[n],
|
|
248
|
-
s.setAttribute(n,
|
|
240
|
+
const r = e.attributes[n], o = le(r);
|
|
241
|
+
s.setAttribute(n, o);
|
|
249
242
|
}
|
|
250
243
|
if (e.morphAttributes)
|
|
251
244
|
for (const n in e.morphAttributes) {
|
|
252
|
-
const
|
|
253
|
-
s.morphAttributes[n] =
|
|
245
|
+
const o = e.morphAttributes[n].map((l) => le(l));
|
|
246
|
+
s.morphAttributes[n] = o;
|
|
254
247
|
}
|
|
255
|
-
if (s.morphTargetsRelative = e.morphTargetsRelative ?? !1, s.boundingBox = new ge(), s.boundingBox.min = new A(
|
|
248
|
+
if (s.morphTargetsRelative = e.morphTargetsRelative ?? !1, s.boundingBox = new ge(), s.boundingBox.min = new A(
|
|
249
|
+
e.boundingBox?.min.x,
|
|
250
|
+
e.boundingBox?.min.y,
|
|
251
|
+
e.boundingBox?.min.z
|
|
252
|
+
), s.boundingBox.max = new A(
|
|
253
|
+
e.boundingBox?.max.x,
|
|
254
|
+
e.boundingBox?.max.y,
|
|
255
|
+
e.boundingBox?.max.z
|
|
256
|
+
), s.boundingSphere = new Oe(
|
|
257
|
+
new A(
|
|
258
|
+
e.boundingSphere?.center.x,
|
|
259
|
+
e.boundingSphere?.center.y,
|
|
260
|
+
e.boundingSphere?.center.z
|
|
261
|
+
),
|
|
262
|
+
e.boundingSphere?.radius
|
|
263
|
+
), e.groups)
|
|
256
264
|
for (const n of e.groups)
|
|
257
265
|
s.addGroup(n.start, n.count, n.materialIndex);
|
|
258
266
|
e.userData && (s.userData = e.userData), t.geometry = s;
|
|
259
267
|
}
|
|
260
|
-
for (const t of
|
|
268
|
+
for (const t of i.textures) {
|
|
261
269
|
const e = t.texture;
|
|
262
270
|
let s = null;
|
|
263
271
|
if (e.isCompressedTexture) {
|
|
264
|
-
const n = e.mipmaps, r = e.image?.width || e.source?.data?.width || -1,
|
|
265
|
-
s = new
|
|
272
|
+
const n = e.mipmaps, r = e.image?.width || e.source?.data?.width || -1, o = e.image?.height || e.source?.data?.height || -1;
|
|
273
|
+
s = new Ge(
|
|
274
|
+
n,
|
|
275
|
+
r,
|
|
276
|
+
o,
|
|
277
|
+
e.format,
|
|
278
|
+
e.type,
|
|
279
|
+
e.mapping,
|
|
280
|
+
e.wrapS,
|
|
281
|
+
e.wrapT,
|
|
282
|
+
e.magFilter,
|
|
283
|
+
e.minFilter,
|
|
284
|
+
e.anisotropy,
|
|
285
|
+
e.colorSpace
|
|
286
|
+
);
|
|
266
287
|
} else
|
|
267
|
-
s = new E(
|
|
288
|
+
s = new E(
|
|
289
|
+
e.image,
|
|
290
|
+
e.mapping,
|
|
291
|
+
e.wrapS,
|
|
292
|
+
e.wrapT,
|
|
293
|
+
e.magFilter,
|
|
294
|
+
e.minFilter,
|
|
295
|
+
e.format,
|
|
296
|
+
e.type,
|
|
297
|
+
e.anisotropy,
|
|
298
|
+
e.colorSpace
|
|
299
|
+
), s.mipmaps = e.mipmaps, s.channel = e.channel, s.source.data = e.source.data, s.flipY = e.flipY, s.premultiplyAlpha = e.premultiplyAlpha, s.unpackAlignment = e.unpackAlignment, s.matrix = new Fe(...e.matrix.elements);
|
|
268
300
|
if (!s) {
|
|
269
301
|
console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");
|
|
270
302
|
continue;
|
|
271
303
|
}
|
|
272
304
|
t.texture = s;
|
|
273
305
|
}
|
|
274
|
-
return
|
|
306
|
+
return i;
|
|
275
307
|
}
|
|
276
|
-
function le(
|
|
277
|
-
let t =
|
|
278
|
-
if ("isInterleavedBufferAttribute" in
|
|
279
|
-
const e =
|
|
280
|
-
t = new
|
|
281
|
-
} else "isBufferAttribute" in
|
|
308
|
+
function le(i) {
|
|
309
|
+
let t = i;
|
|
310
|
+
if ("isInterleavedBufferAttribute" in i && i.isInterleavedBufferAttribute) {
|
|
311
|
+
const e = i.data, s = e.array, n = new We(s, e.stride);
|
|
312
|
+
t = new Ue(n, i.itemSize, s.byteOffset, i.normalized), t.offset = i.offset;
|
|
313
|
+
} else "isBufferAttribute" in i && i.isBufferAttribute && (t = new ze(i.array, i.itemSize, i.normalized), t.usage = i.usage, t.gpuType = i.gpuType, t.updateRanges = i.updateRanges);
|
|
282
314
|
return t;
|
|
283
315
|
}
|
|
284
316
|
const ft = X("gltf-progressive-worker"), ht = X("gltf-progressive-reduce-mipmaps"), ue = Symbol("needle-progressive-texture"), F = "NEEDLE_progressive";
|
|
@@ -287,6 +319,7 @@ class y {
|
|
|
287
319
|
get name() {
|
|
288
320
|
return F;
|
|
289
321
|
}
|
|
322
|
+
// #region PUBLIC API
|
|
290
323
|
static getMeshLODExtension(t) {
|
|
291
324
|
const e = this.getAssignedLODInformation(t);
|
|
292
325
|
return e?.key ? this.lodInfos.get(e.key) : null;
|
|
@@ -297,8 +330,7 @@ class y {
|
|
|
297
330
|
}
|
|
298
331
|
static getMaterialMinMaxLODsCount(t, e) {
|
|
299
332
|
const s = this, n = "LODS:minmax", r = t[n];
|
|
300
|
-
if (r != null)
|
|
301
|
-
return r;
|
|
333
|
+
if (r != null) return r;
|
|
302
334
|
if (e || (e = {
|
|
303
335
|
min_count: 1 / 0,
|
|
304
336
|
max_count: 0,
|
|
@@ -312,17 +344,17 @@ class y {
|
|
|
312
344
|
const l = t;
|
|
313
345
|
for (const a of Object.keys(l.uniforms)) {
|
|
314
346
|
const u = l.uniforms[a].value;
|
|
315
|
-
u?.isTexture === !0 &&
|
|
347
|
+
u?.isTexture === !0 && o(u, e);
|
|
316
348
|
}
|
|
317
349
|
} else if (t.isMaterial)
|
|
318
350
|
for (const l of Object.keys(t)) {
|
|
319
351
|
const a = t[l];
|
|
320
|
-
a?.isTexture === !0 &&
|
|
352
|
+
a?.isTexture === !0 && o(a, e);
|
|
321
353
|
}
|
|
322
354
|
else
|
|
323
355
|
g && console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${t.type}`);
|
|
324
356
|
return t[n] = e, e;
|
|
325
|
-
function
|
|
357
|
+
function o(l, a) {
|
|
326
358
|
const u = s.getAssignedLODInformation(l);
|
|
327
359
|
if (u) {
|
|
328
360
|
const d = s.lodInfos.get(u.key);
|
|
@@ -344,14 +376,13 @@ class y {
|
|
|
344
376
|
static hasLODLevelAvailable(t, e) {
|
|
345
377
|
if (Array.isArray(t)) {
|
|
346
378
|
for (const r of t)
|
|
347
|
-
if (this.hasLODLevelAvailable(r, e))
|
|
348
|
-
return !0;
|
|
379
|
+
if (this.hasLODLevelAvailable(r, e)) return !0;
|
|
349
380
|
return !1;
|
|
350
381
|
}
|
|
351
382
|
if (t.isMaterial === !0) {
|
|
352
383
|
for (const r of Object.keys(t)) {
|
|
353
|
-
const
|
|
354
|
-
if (
|
|
384
|
+
const o = t[r];
|
|
385
|
+
if (o && o.isTexture && this.hasLODLevelAvailable(o, e))
|
|
355
386
|
return !0;
|
|
356
387
|
}
|
|
357
388
|
return !1;
|
|
@@ -363,8 +394,7 @@ class y {
|
|
|
363
394
|
let s, n;
|
|
364
395
|
if (t.isMesh ? s = t.geometry : (t.isBufferGeometry || t.isTexture) && (s = t), s && s?.userData?.LODS) {
|
|
365
396
|
const r = s.userData.LODS;
|
|
366
|
-
if (n = this.lodInfos.get(r.key), e === void 0)
|
|
367
|
-
return n != null;
|
|
397
|
+
if (n = this.lodInfos.get(r.key), e === void 0) return n != null;
|
|
368
398
|
if (n)
|
|
369
399
|
return Array.isArray(n.lods) ? e < n.lods.length : e === 0;
|
|
370
400
|
}
|
|
@@ -385,18 +415,17 @@ class y {
|
|
|
385
415
|
* ```
|
|
386
416
|
*/
|
|
387
417
|
static assignMeshLOD(t, e) {
|
|
388
|
-
if (!t)
|
|
389
|
-
return Promise.resolve(null);
|
|
418
|
+
if (!t) return Promise.resolve(null);
|
|
390
419
|
if (t instanceof q || t.isMesh === !0) {
|
|
391
420
|
const s = t.geometry, n = this.getAssignedLODInformation(s);
|
|
392
421
|
if (!n)
|
|
393
422
|
return Promise.resolve(null);
|
|
394
|
-
for (const r of
|
|
423
|
+
for (const r of U)
|
|
395
424
|
r.onBeforeGetLODMesh?.(t, e);
|
|
396
425
|
return t["LOD:requested level"] = e, y.getOrLoadLOD(s, e).then((r) => {
|
|
397
426
|
if (Array.isArray(r)) {
|
|
398
|
-
const
|
|
399
|
-
r = r[
|
|
427
|
+
const o = n.index || 0;
|
|
428
|
+
r = r[o];
|
|
400
429
|
}
|
|
401
430
|
return t["LOD:requested level"] === e && (delete t["LOD:requested level"], r && s != r && (r?.isBufferGeometry ? t.geometry = r : g && console.error("Invalid LOD geometry", r))), r;
|
|
402
431
|
}).catch((r) => (console.error("Error loading mesh LOD", t, r), null));
|
|
@@ -404,21 +433,20 @@ class y {
|
|
|
404
433
|
return Promise.resolve(null);
|
|
405
434
|
}
|
|
406
435
|
static assignTextureLOD(t, e = 0) {
|
|
407
|
-
if (!t)
|
|
408
|
-
return Promise.resolve(null);
|
|
436
|
+
if (!t) return Promise.resolve(null);
|
|
409
437
|
if (t.isMesh === !0) {
|
|
410
438
|
const s = t;
|
|
411
439
|
if (Array.isArray(s.material)) {
|
|
412
440
|
const n = new Array();
|
|
413
441
|
for (const r of s.material) {
|
|
414
|
-
const
|
|
415
|
-
n.push(
|
|
442
|
+
const o = this.assignTextureLOD(r, e);
|
|
443
|
+
n.push(o);
|
|
416
444
|
}
|
|
417
445
|
return Promise.all(n).then((r) => {
|
|
418
|
-
const
|
|
446
|
+
const o = new Array();
|
|
419
447
|
for (const l of r)
|
|
420
|
-
Array.isArray(l) &&
|
|
421
|
-
return
|
|
448
|
+
Array.isArray(l) && o.push(...l);
|
|
449
|
+
return o;
|
|
422
450
|
});
|
|
423
451
|
} else
|
|
424
452
|
return this.assignTextureLOD(s.material, e);
|
|
@@ -426,26 +454,26 @@ class y {
|
|
|
426
454
|
if (t.isMaterial === !0) {
|
|
427
455
|
const s = t, n = [], r = new Array();
|
|
428
456
|
if (s.uniforms && (s.isRawShaderMaterial || s.isShaderMaterial === !0)) {
|
|
429
|
-
const
|
|
430
|
-
for (const l of Object.keys(
|
|
431
|
-
const a =
|
|
457
|
+
const o = s;
|
|
458
|
+
for (const l of Object.keys(o.uniforms)) {
|
|
459
|
+
const a = o.uniforms[l].value;
|
|
432
460
|
if (a?.isTexture === !0) {
|
|
433
|
-
const u = this.assignTextureLODForSlot(a, e, s, l).then((d) => (d &&
|
|
461
|
+
const u = this.assignTextureLODForSlot(a, e, s, l).then((d) => (d && o.uniforms[l].value != d && (o.uniforms[l].value = d, o.uniformsNeedUpdate = !0), d));
|
|
434
462
|
n.push(u), r.push(l);
|
|
435
463
|
}
|
|
436
464
|
}
|
|
437
465
|
} else
|
|
438
|
-
for (const
|
|
439
|
-
const l = s[
|
|
466
|
+
for (const o of Object.keys(s)) {
|
|
467
|
+
const l = s[o];
|
|
440
468
|
if (l?.isTexture === !0) {
|
|
441
|
-
const a = this.assignTextureLODForSlot(l, e, s,
|
|
442
|
-
n.push(a), r.push(
|
|
469
|
+
const a = this.assignTextureLODForSlot(l, e, s, o);
|
|
470
|
+
n.push(a), r.push(o);
|
|
443
471
|
}
|
|
444
472
|
}
|
|
445
|
-
return Promise.all(n).then((
|
|
473
|
+
return Promise.all(n).then((o) => {
|
|
446
474
|
const l = new Array();
|
|
447
|
-
for (let a = 0; a <
|
|
448
|
-
const u =
|
|
475
|
+
for (let a = 0; a < o.length; a++) {
|
|
476
|
+
const u = o[a], d = r[a];
|
|
449
477
|
u && u.isTexture === !0 ? l.push({ material: s, slot: d, texture: u, level: e }) : l.push({ material: s, slot: d, texture: null, level: e });
|
|
450
478
|
}
|
|
451
479
|
return l;
|
|
@@ -457,17 +485,18 @@ class y {
|
|
|
457
485
|
}
|
|
458
486
|
return Promise.resolve(null);
|
|
459
487
|
}
|
|
488
|
+
// #region INTERNAL
|
|
460
489
|
static assignTextureLODForSlot(t, e, s, n) {
|
|
461
490
|
return t?.isTexture !== !0 ? Promise.resolve(null) : n === "glyphMap" ? Promise.resolve(t) : y.getOrLoadLOD(t, e).then((r) => {
|
|
462
491
|
if (Array.isArray(r))
|
|
463
492
|
return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."), null;
|
|
464
493
|
if (r?.isTexture === !0) {
|
|
465
494
|
if (r != t && s && n) {
|
|
466
|
-
const
|
|
467
|
-
if (
|
|
468
|
-
const l = this.getAssignedLODInformation(
|
|
495
|
+
const o = s[n];
|
|
496
|
+
if (o && !g) {
|
|
497
|
+
const l = this.getAssignedLODInformation(o);
|
|
469
498
|
if (l && l?.level < e)
|
|
470
|
-
return g === "verbose" && console.warn("Assigned texture level is already higher: ", l.level, e, s,
|
|
499
|
+
return g === "verbose" && console.warn("Assigned texture level is already higher: ", l.level, e, s, o, r), null;
|
|
471
500
|
}
|
|
472
501
|
if (ht && r.mipmaps) {
|
|
473
502
|
const l = r.mipmaps.length;
|
|
@@ -488,8 +517,7 @@ class y {
|
|
|
488
517
|
}
|
|
489
518
|
_isLoadingMesh;
|
|
490
519
|
loadMesh = (t) => {
|
|
491
|
-
if (this._isLoadingMesh)
|
|
492
|
-
return null;
|
|
520
|
+
if (this._isLoadingMesh) return null;
|
|
493
521
|
const e = this.parser.json.meshes[t]?.extensions?.[F];
|
|
494
522
|
return e ? (this._isLoadingMesh = !0, this.parser.getDependency("mesh", t).then((s) => (this._isLoadingMesh = !1, s && y.registerMesh(this.url, e.guid, s, e.lods?.length, 0, e), s))) : null;
|
|
495
523
|
};
|
|
@@ -517,10 +545,10 @@ class y {
|
|
|
517
545
|
return;
|
|
518
546
|
}
|
|
519
547
|
let r = !1;
|
|
520
|
-
for (const
|
|
521
|
-
|
|
522
|
-
r || this.parser.getDependency("texture", s).then((
|
|
523
|
-
|
|
548
|
+
for (const o of this.parser.associations.keys())
|
|
549
|
+
o.isTexture === !0 && this.parser.associations.get(o)?.textures === s && (r = !0, y.registerTexture(this.url, o, n.lods?.length, s, n));
|
|
550
|
+
r || this.parser.getDependency("texture", s).then((o) => {
|
|
551
|
+
o && y.registerTexture(this.url, o, n.lods?.length, s, n);
|
|
524
552
|
});
|
|
525
553
|
}
|
|
526
554
|
}
|
|
@@ -530,8 +558,8 @@ class y {
|
|
|
530
558
|
if (n && n.lods) {
|
|
531
559
|
for (const r of this.parser.associations.keys())
|
|
532
560
|
if (r.isMesh) {
|
|
533
|
-
const
|
|
534
|
-
|
|
561
|
+
const o = this.parser.associations.get(r);
|
|
562
|
+
o?.meshes === s && y.registerMesh(this.url, n.guid, r, n.lods.length, o.primitives, n);
|
|
535
563
|
}
|
|
536
564
|
}
|
|
537
565
|
}
|
|
@@ -542,31 +570,31 @@ class y {
|
|
|
542
570
|
*/
|
|
543
571
|
static registerTexture = (t, e, s, n, r) => {
|
|
544
572
|
if (!e) {
|
|
545
|
-
g && console.error("gltf-progressive: Called register texture without texture");
|
|
573
|
+
g && console.error("!! gltf-progressive: Called register texture without texture");
|
|
546
574
|
return;
|
|
547
575
|
}
|
|
548
576
|
if (g) {
|
|
549
577
|
const l = e.image?.width || e.source?.data?.width || 0, a = e.image?.height || e.source?.data?.height || 0;
|
|
550
|
-
console.log(`>
|
|
578
|
+
console.log(`> gltf-progressive: register texture[${n}] "${e.name || e.uuid}", Current: ${l}x${a}, Max: ${r.lods[0]?.width}x${r.lods[0]?.height}, uuid: ${e.uuid}`, r, e);
|
|
551
579
|
}
|
|
552
580
|
e.source && (e.source[ue] = r);
|
|
553
|
-
const
|
|
554
|
-
y.assignLODInformation(t, e,
|
|
581
|
+
const o = r.guid;
|
|
582
|
+
y.assignLODInformation(t, e, o, s, n), y.lodInfos.set(o, r), y.lowresCache.set(o, e);
|
|
555
583
|
};
|
|
556
584
|
/**
|
|
557
585
|
* Register a mesh with LOD information
|
|
558
586
|
*/
|
|
559
|
-
static registerMesh = (t, e, s, n, r,
|
|
587
|
+
static registerMesh = (t, e, s, n, r, o) => {
|
|
560
588
|
const l = s.geometry;
|
|
561
589
|
if (!l) {
|
|
562
590
|
g && console.warn("gltf-progressive: Register mesh without geometry");
|
|
563
591
|
return;
|
|
564
592
|
}
|
|
565
|
-
l.userData || (l.userData = {}), g && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid },
|
|
593
|
+
l.userData || (l.userData = {}), g && console.log("> Progressive: register mesh " + s.name, { index: r, uuid: s.uuid }, o, s), y.assignLODInformation(t, l, e, n, r), y.lodInfos.set(e, o);
|
|
566
594
|
let a = y.lowresCache.get(e);
|
|
567
|
-
a ? a.push(s.geometry) : a = [s.geometry], y.lowresCache.set(e, a), n > 0 && !
|
|
568
|
-
for (const u of
|
|
569
|
-
u.onRegisteredNewMesh?.(s,
|
|
595
|
+
a ? a.push(s.geometry) : a = [s.geometry], y.lowresCache.set(e, a), n > 0 && !Z(s) && ot(s, l);
|
|
596
|
+
for (const u of U)
|
|
597
|
+
u.onRegisteredNewMesh?.(s, o);
|
|
570
598
|
};
|
|
571
599
|
/** A map of key = asset uuid and value = LOD information */
|
|
572
600
|
static lodInfos = /* @__PURE__ */ new Map();
|
|
@@ -581,36 +609,38 @@ class y {
|
|
|
581
609
|
if (!n)
|
|
582
610
|
return g && console.warn(`[gltf-progressive] No LOD information found: ${t.name}, uuid: ${t.uuid}, type: ${t.type}`, t), null;
|
|
583
611
|
const r = n?.key;
|
|
584
|
-
let
|
|
612
|
+
let o;
|
|
585
613
|
if (t.isTexture === !0) {
|
|
586
614
|
const a = t;
|
|
587
|
-
a.source && a.source[ue] && (
|
|
615
|
+
a.source && a.source[ue] && (o = a.source[ue]);
|
|
588
616
|
}
|
|
589
|
-
if (
|
|
617
|
+
if (o || (o = y.lodInfos.get(r)), !o)
|
|
618
|
+
g && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type, y.lodInfos);
|
|
619
|
+
else {
|
|
590
620
|
if (e > 0) {
|
|
591
621
|
let d = !1;
|
|
592
|
-
const p = Array.isArray(
|
|
593
|
-
if (p && e >=
|
|
622
|
+
const p = Array.isArray(o.lods);
|
|
623
|
+
if (p && e >= o.lods.length ? d = !0 : p || (d = !0), d)
|
|
594
624
|
return this.lowresCache.get(r);
|
|
595
625
|
}
|
|
596
|
-
const a = Array.isArray(
|
|
626
|
+
const a = Array.isArray(o.lods) ? o.lods[e]?.path : o.lods;
|
|
597
627
|
if (!a)
|
|
598
|
-
return g && !
|
|
628
|
+
return g && !o["missing:uri"] && (o["missing:uri"] = !0, console.warn("Missing uri for progressive asset for LOD " + e, o)), null;
|
|
599
629
|
const u = st(n.url, a);
|
|
600
630
|
if (u.endsWith(".glb") || u.endsWith(".gltf")) {
|
|
601
|
-
if (!
|
|
602
|
-
return console.warn("missing pointer for glb/gltf texture",
|
|
603
|
-
const d = u + "_" +
|
|
631
|
+
if (!o.guid)
|
|
632
|
+
return console.warn("missing pointer for glb/gltf texture", o), null;
|
|
633
|
+
const d = u + "_" + o.guid, p = await this.queue.slot(u), L = this.previouslyLoaded.get(d);
|
|
604
634
|
if (L !== void 0) {
|
|
605
635
|
s && console.log(`LOD ${e} was already loading/loaded: ${d}`);
|
|
606
|
-
let c = await L.catch((
|
|
607
|
-
`,
|
|
608
|
-
if (c == null || (c instanceof E && t instanceof E ? c.image?.data || c.source?.data ? c = this.copySettings(t, c) : (x = !0, this.previouslyLoaded.delete(d)) : c instanceof
|
|
636
|
+
let c = await L.catch((O) => (console.error(`Error loading LOD ${e} from ${u}
|
|
637
|
+
`, O), null)), x = !1;
|
|
638
|
+
if (c == null || (c instanceof E && t instanceof E ? c.image?.data || c.source?.data ? c = this.copySettings(t, c) : (x = !0, this.previouslyLoaded.delete(d)) : c instanceof J && t instanceof J && (c.attributes.position?.array || (x = !0, this.previouslyLoaded.delete(d)))), !x)
|
|
609
639
|
return c;
|
|
610
640
|
}
|
|
611
641
|
if (!p.use)
|
|
612
642
|
return g && console.log(`LOD ${e} was aborted: ${u}`), null;
|
|
613
|
-
const _ =
|
|
643
|
+
const _ = o, I = new Promise(async (c, x) => {
|
|
614
644
|
if (ft) {
|
|
615
645
|
const m = await (await dt({})).load(u);
|
|
616
646
|
if (m.textures.length > 0)
|
|
@@ -621,21 +651,21 @@ class y {
|
|
|
621
651
|
if (m.geometries.length > 0) {
|
|
622
652
|
const f = new Array();
|
|
623
653
|
for (const h of m.geometries) {
|
|
624
|
-
const
|
|
625
|
-
y.assignLODInformation(n.url,
|
|
654
|
+
const v = h.geometry;
|
|
655
|
+
y.assignLODInformation(n.url, v, r, e, h.primitiveIndex), f.push(v);
|
|
626
656
|
}
|
|
627
657
|
return c(f);
|
|
628
658
|
}
|
|
629
659
|
return c(null);
|
|
630
660
|
}
|
|
631
|
-
const
|
|
632
|
-
Te(
|
|
661
|
+
const O = new xe();
|
|
662
|
+
Te(O), g && (await new Promise((w) => setTimeout(w, 1e3)), s && console.warn("Start loading (delayed) " + u, _.guid));
|
|
633
663
|
let B = u;
|
|
634
664
|
if (_ && Array.isArray(_.lods)) {
|
|
635
665
|
const w = _.lods[e];
|
|
636
666
|
w.hash && (B += "?v=" + w.hash);
|
|
637
667
|
}
|
|
638
|
-
const M = await
|
|
668
|
+
const M = await O.loadAsync(B).catch((w) => (console.error(`Error loading LOD ${e} from ${u}
|
|
639
669
|
`, w), c(null)));
|
|
640
670
|
if (!M)
|
|
641
671
|
return c(null);
|
|
@@ -679,10 +709,10 @@ class y {
|
|
|
679
709
|
} else {
|
|
680
710
|
const f = new Array();
|
|
681
711
|
for (let h = 0; h < m.children.length; h++) {
|
|
682
|
-
const
|
|
683
|
-
if (
|
|
684
|
-
const
|
|
685
|
-
y.assignLODInformation(n.url,
|
|
712
|
+
const v = m.children[h];
|
|
713
|
+
if (v.isMesh === !0) {
|
|
714
|
+
const b = v.geometry;
|
|
715
|
+
y.assignLODInformation(n.url, b, r, e, h), f.push(b);
|
|
686
716
|
}
|
|
687
717
|
}
|
|
688
718
|
return c(f);
|
|
@@ -694,21 +724,19 @@ class y {
|
|
|
694
724
|
return this.previouslyLoaded.set(d, I), p.use(I), await I;
|
|
695
725
|
} else if (t instanceof E) {
|
|
696
726
|
s && console.log("Load texture from uri: " + u);
|
|
697
|
-
const p = await new
|
|
698
|
-
return p ? (p.guid =
|
|
727
|
+
const p = await new Ee().loadAsync(u);
|
|
728
|
+
return p ? (p.guid = o.guid, p.flipY = !1, p.needsUpdate = !0, p.colorSpace = t.colorSpace, s && console.log(o, p)) : g && console.warn("failed loading", u), p;
|
|
699
729
|
}
|
|
700
|
-
}
|
|
701
|
-
g && console.warn(`Can not load LOD ${e}: no LOD info found for "${r}" ${t.name}`, t.type);
|
|
730
|
+
}
|
|
702
731
|
return null;
|
|
703
732
|
}
|
|
704
733
|
static maxConcurrent = 50;
|
|
705
734
|
static queue = new rt(y.maxConcurrent, { debug: g != !1 });
|
|
706
735
|
static assignLODInformation(t, e, s, n, r) {
|
|
707
|
-
if (!e)
|
|
708
|
-
return;
|
|
736
|
+
if (!e) return;
|
|
709
737
|
e.userData || (e.userData = {});
|
|
710
|
-
const
|
|
711
|
-
e.userData.LODS =
|
|
738
|
+
const o = new gt(t, s, n, r);
|
|
739
|
+
e.userData.LODS = o, "source" in e && typeof e.source == "object" && (e.source.LODS = o);
|
|
712
740
|
}
|
|
713
741
|
static getAssignedLODInformation(t) {
|
|
714
742
|
return t ? t.userData?.LODS ? t.userData.LODS : "source" in t && t.source?.LODS ? t.source.LODS : null : null;
|
|
@@ -807,9 +835,9 @@ class de {
|
|
|
807
835
|
});
|
|
808
836
|
}
|
|
809
837
|
}
|
|
810
|
-
const
|
|
811
|
-
let
|
|
812
|
-
/**
|
|
838
|
+
const k = X("debugprogressive"), pt = X("noprogressive"), ce = Symbol("Needle:LODSManager"), fe = Symbol("Needle:LODState"), W = Symbol("Needle:CurrentLOD"), T = { mesh_lod: -1, texture_lod: -1 };
|
|
839
|
+
let oe = class D {
|
|
840
|
+
/**
|
|
813
841
|
* 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.
|
|
814
842
|
*/
|
|
815
843
|
static debugDrawLine;
|
|
@@ -818,21 +846,21 @@ let ie = class b {
|
|
|
818
846
|
return t[fe];
|
|
819
847
|
}
|
|
820
848
|
static addPlugin(t) {
|
|
821
|
-
|
|
849
|
+
U.push(t);
|
|
822
850
|
}
|
|
823
851
|
static removePlugin(t) {
|
|
824
|
-
const e =
|
|
825
|
-
e >= 0 &&
|
|
852
|
+
const e = U.indexOf(t);
|
|
853
|
+
e >= 0 && U.splice(e, 1);
|
|
826
854
|
}
|
|
827
855
|
/**
|
|
828
|
-
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
856
|
+
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
829
857
|
* @param renderer The renderer to get the LODsManager for.
|
|
830
858
|
* @returns The LODsManager instance.
|
|
831
859
|
*/
|
|
832
860
|
static get(t, e) {
|
|
833
861
|
if (t[ce])
|
|
834
862
|
return console.debug("[gltf-progressive] LODsManager already exists for this renderer"), t[ce];
|
|
835
|
-
const s = new
|
|
863
|
+
const s = new D(t, {
|
|
836
864
|
engine: "unknown",
|
|
837
865
|
...e
|
|
838
866
|
});
|
|
@@ -843,7 +871,7 @@ let ie = class b {
|
|
|
843
871
|
projectionScreenMatrix = new _e();
|
|
844
872
|
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
845
873
|
get plugins() {
|
|
846
|
-
return
|
|
874
|
+
return U;
|
|
847
875
|
}
|
|
848
876
|
/**
|
|
849
877
|
* Force override the LOD level for all objects (meshes + textures) rendered in the scene
|
|
@@ -851,13 +879,13 @@ let ie = class b {
|
|
|
851
879
|
*/
|
|
852
880
|
overrideLodLevel = void 0;
|
|
853
881
|
/**
|
|
854
|
-
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
882
|
+
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
855
883
|
* @default 200_000
|
|
856
884
|
*/
|
|
857
885
|
targetTriangleDensity = 2e5;
|
|
858
886
|
/**
|
|
859
|
-
* The interval in frames to automatically update the bounds of skinned meshes.
|
|
860
|
-
* Set to 0 or a negative value to disable automatic bounds updates.
|
|
887
|
+
* The interval in frames to automatically update the bounds of skinned meshes.
|
|
888
|
+
* Set to 0 or a negative value to disable automatic bounds updates.
|
|
861
889
|
* @default 30
|
|
862
890
|
*/
|
|
863
891
|
skinnedMeshAutoUpdateBoundsInterval = 30;
|
|
@@ -873,7 +901,7 @@ let ie = class b {
|
|
|
873
901
|
*/
|
|
874
902
|
pause = !1;
|
|
875
903
|
/**
|
|
876
|
-
* When set to true the LODsManager will not update the LODs. This can be used to manually update the LODs using the `update` method.
|
|
904
|
+
* When set to true the LODsManager will not update the LODs. This can be used to manually update the LODs using the `update` method.
|
|
877
905
|
* Otherwise the LODs will be updated automatically when the renderer renders the scene.
|
|
878
906
|
* @default false
|
|
879
907
|
*/
|
|
@@ -915,27 +943,26 @@ let ie = class b {
|
|
|
915
943
|
this.renderer = t, this.context = { ...e };
|
|
916
944
|
}
|
|
917
945
|
#t;
|
|
918
|
-
#
|
|
946
|
+
#o = new Ne();
|
|
919
947
|
#r = 0;
|
|
920
948
|
#n = 0;
|
|
921
|
-
#
|
|
949
|
+
#i = 0;
|
|
922
950
|
#s = 0;
|
|
923
951
|
_fpsBuffer = [60, 60, 60, 60, 60];
|
|
924
952
|
/**
|
|
925
953
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
926
954
|
*/
|
|
927
955
|
enable() {
|
|
928
|
-
if (this.#t)
|
|
929
|
-
return;
|
|
956
|
+
if (this.#t) return;
|
|
930
957
|
console.debug("[gltf-progressive] Enabling LODsManager for renderer");
|
|
931
958
|
let t = 0;
|
|
932
959
|
this.#t = this.renderer.render;
|
|
933
960
|
const e = this;
|
|
934
961
|
we(this.renderer), this.renderer.render = function(s, n) {
|
|
935
962
|
const r = e.renderer.getRenderTarget();
|
|
936
|
-
(r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, e.#r += 1, e.#n = e.#
|
|
937
|
-
const
|
|
938
|
-
e.#t.call(this, s, n), e.onAfterRender(s, n,
|
|
963
|
+
(r == null || "isXRRenderTarget" in r && r.isXRRenderTarget) && (t = 0, e.#r += 1, e.#n = e.#o.getDelta(), e.#i += e.#n, e._fpsBuffer.shift(), e._fpsBuffer.push(1 / e.#n), e.#s = e._fpsBuffer.reduce((l, a) => l + a) / e._fpsBuffer.length, k && e.#r % 200 === 0 && console.log("FPS", Math.round(e.#s), "Interval:", e.#e));
|
|
964
|
+
const o = t++;
|
|
965
|
+
e.#t.call(this, s, n), e.onAfterRender(s, n, o);
|
|
939
966
|
};
|
|
940
967
|
}
|
|
941
968
|
disable() {
|
|
@@ -945,16 +972,15 @@ let ie = class b {
|
|
|
945
972
|
this.internalUpdate(t, e);
|
|
946
973
|
}
|
|
947
974
|
onAfterRender(t, e, s) {
|
|
948
|
-
if (this.pause)
|
|
949
|
-
return;
|
|
975
|
+
if (this.pause) return;
|
|
950
976
|
const r = this.renderer.renderLists.get(t, 0).opaque;
|
|
951
|
-
let
|
|
977
|
+
let o = !0;
|
|
952
978
|
if (r.length === 1) {
|
|
953
979
|
const l = r[0].material;
|
|
954
|
-
(l.name === "EffectMaterial" || l.name === "CopyShader") && (
|
|
980
|
+
(l.name === "EffectMaterial" || l.name === "CopyShader") && (o = !1);
|
|
955
981
|
}
|
|
956
|
-
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (
|
|
957
|
-
if (pt || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1,
|
|
982
|
+
if ((e.parent && e.parent.type === "CubeCamera" || s >= 1 && e.type === "OrthographicCamera") && (o = !1), o) {
|
|
983
|
+
if (pt || (this.updateInterval === "auto" ? this.#s < 40 && this.#e < 10 ? (this.#e += 1, k && console.warn("↓ Reducing LOD updates", this.#e, this.#s.toFixed(0))) : this.#s >= 60 && this.#e > 1 && (this.#e -= 1, k && console.warn("↑ Increasing LOD updates", this.#e, this.#s.toFixed(0))) : this.#e = this.updateInterval, this.#e > 0 && this.#r % this.#e != 0))
|
|
958
984
|
return;
|
|
959
985
|
this.internalUpdate(t, e), this._postprocessPromiseGroups();
|
|
960
986
|
}
|
|
@@ -968,7 +994,7 @@ let ie = class b {
|
|
|
968
994
|
const r = this.targetTriangleDensity;
|
|
969
995
|
for (const a of n) {
|
|
970
996
|
if (a.material && (a.geometry?.type === "BoxGeometry" || a.geometry?.type === "BufferGeometry") && (a.material.name === "SphericalGaussianBlur" || a.material.name == "BackgroundCubeMaterial" || a.material.name === "CubemapFromEquirect" || a.material.name === "EquirectangularToCubeUV")) {
|
|
971
|
-
|
|
997
|
+
k && (a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] || (a.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = !0, console.warn("Ignoring skybox or BLIT object", a, a.material.name, a.material.type)));
|
|
972
998
|
continue;
|
|
973
999
|
}
|
|
974
1000
|
switch (a.material.type) {
|
|
@@ -980,16 +1006,16 @@ let ie = class b {
|
|
|
980
1006
|
case "MeshDepthMaterial":
|
|
981
1007
|
continue;
|
|
982
1008
|
}
|
|
983
|
-
if (
|
|
1009
|
+
if (k === "color" && a.material && !a.object.progressive_debug_color) {
|
|
984
1010
|
a.object.progressive_debug_color = !0;
|
|
985
|
-
const d = Math.random() * 16777215, p = new
|
|
1011
|
+
const d = Math.random() * 16777215, p = new qe({ color: d });
|
|
986
1012
|
a.object.material = p;
|
|
987
1013
|
}
|
|
988
1014
|
const u = a.object;
|
|
989
1015
|
(u instanceof q || u.isMesh) && this.updateLODs(t, e, u, r);
|
|
990
1016
|
}
|
|
991
|
-
const
|
|
992
|
-
for (const a of
|
|
1017
|
+
const o = s.transparent;
|
|
1018
|
+
for (const a of o) {
|
|
993
1019
|
const u = a.object;
|
|
994
1020
|
(u instanceof q || u.isMesh) && this.updateLODs(t, e, u, r);
|
|
995
1021
|
}
|
|
@@ -1005,13 +1031,13 @@ let ie = class b {
|
|
|
1005
1031
|
let r = s[fe];
|
|
1006
1032
|
if (r || (r = new mt(), s[fe] = r), r.frames++ < 2)
|
|
1007
1033
|
return;
|
|
1008
|
-
for (const l of
|
|
1034
|
+
for (const l of U)
|
|
1009
1035
|
l.onBeforeUpdateLOD?.(this.renderer, t, e, s);
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1012
|
-
for (const l of
|
|
1013
|
-
l.onAfterUpdatedLOD?.(this.renderer, t, e, s,
|
|
1014
|
-
r.lastLodLevel_Mesh =
|
|
1036
|
+
const o = this.overrideLodLevel !== void 0 ? this.overrideLodLevel : N;
|
|
1037
|
+
o >= 0 ? (T.mesh_lod = o, T.texture_lod = o) : (this.calculateLodLevel(e, s, r, n, T), T.mesh_lod = Math.round(T.mesh_lod), T.texture_lod = Math.round(T.texture_lod)), T.mesh_lod >= 0 && this.loadProgressiveMeshes(s, T.mesh_lod), s.material && T.texture_lod >= 0 && this.loadProgressiveTextures(s.material, T.texture_lod, o), g && s.material && !s.isGizmo && ke(s.material);
|
|
1038
|
+
for (const l of U)
|
|
1039
|
+
l.onAfterUpdatedLOD?.(this.renderer, t, e, s, T);
|
|
1040
|
+
r.lastLodLevel_Mesh = T.mesh_lod, r.lastLodLevel_Texture = T.texture_lod;
|
|
1015
1041
|
}
|
|
1016
1042
|
/** Load progressive textures for the given material
|
|
1017
1043
|
* @param material the material to load the textures for
|
|
@@ -1019,17 +1045,16 @@ let ie = class b {
|
|
|
1019
1045
|
* @returns Promise with true if the LOD was loaded, false if not
|
|
1020
1046
|
*/
|
|
1021
1047
|
loadProgressiveTextures(t, e, s) {
|
|
1022
|
-
if (!t)
|
|
1023
|
-
return;
|
|
1048
|
+
if (!t) return;
|
|
1024
1049
|
if (Array.isArray(t)) {
|
|
1025
1050
|
for (const r of t)
|
|
1026
1051
|
this.loadProgressiveTextures(r, e);
|
|
1027
1052
|
return;
|
|
1028
1053
|
}
|
|
1029
1054
|
let n = !1;
|
|
1030
|
-
if ((t[
|
|
1031
|
-
t[
|
|
1032
|
-
const r = y.assignTextureLOD(t, e).then((
|
|
1055
|
+
if ((t[W] === void 0 || e < t[W]) && (n = !0), s !== void 0 && s >= 0 && (n = t[W] != s, e = s), n) {
|
|
1056
|
+
t[W] = e;
|
|
1057
|
+
const r = y.assignTextureLOD(t, e).then((o) => {
|
|
1033
1058
|
this._lodchangedlisteners.forEach((l) => l({ type: "texture", level: e, object: t }));
|
|
1034
1059
|
});
|
|
1035
1060
|
de.addPromise("texture", t, r, this._newPromiseGroups);
|
|
@@ -1042,19 +1067,18 @@ let ie = class b {
|
|
|
1042
1067
|
* @returns Promise with true if the LOD was loaded, false if not
|
|
1043
1068
|
*/
|
|
1044
1069
|
loadProgressiveMeshes(t, e) {
|
|
1045
|
-
if (!t)
|
|
1046
|
-
|
|
1047
|
-
let s = t[U] !== e;
|
|
1070
|
+
if (!t) return Promise.resolve(null);
|
|
1071
|
+
let s = t[W] !== e;
|
|
1048
1072
|
const n = t["DEBUG:LOD"];
|
|
1049
|
-
if (n != null && (s = t[
|
|
1050
|
-
t[
|
|
1051
|
-
const r = t.geometry,
|
|
1052
|
-
return de.addPromise("mesh", t,
|
|
1073
|
+
if (n != null && (s = t[W] != n, e = n), s) {
|
|
1074
|
+
t[W] = e;
|
|
1075
|
+
const r = t.geometry, o = y.assignMeshLOD(t, e).then((l) => (l && t[W] == e && r != t.geometry && this._lodchangedlisteners.forEach((a) => a({ type: "mesh", level: e, object: t })), l));
|
|
1076
|
+
return de.addPromise("mesh", t, o, this._newPromiseGroups), o;
|
|
1053
1077
|
}
|
|
1054
1078
|
return Promise.resolve(null);
|
|
1055
1079
|
}
|
|
1056
1080
|
// private testIfLODLevelsAreAvailable() {
|
|
1057
|
-
_sphere = new
|
|
1081
|
+
_sphere = new Oe();
|
|
1058
1082
|
_tempBox = new ge();
|
|
1059
1083
|
_tempBox2 = new ge();
|
|
1060
1084
|
tempMatrix = new _e();
|
|
@@ -1067,8 +1091,8 @@ let ie = class b {
|
|
|
1067
1091
|
static corner3 = new A();
|
|
1068
1092
|
static _tempPtInside = new A();
|
|
1069
1093
|
static isInside(t, e) {
|
|
1070
|
-
const s = t.min, n = t.max, r = (s.x + n.x) * 0.5,
|
|
1071
|
-
return this._tempPtInside.set(r,
|
|
1094
|
+
const s = t.min, n = t.max, r = (s.x + n.x) * 0.5, o = (s.y + n.y) * 0.5;
|
|
1095
|
+
return this._tempPtInside.set(r, o, s.z).applyMatrix4(e).z < 0;
|
|
1072
1096
|
}
|
|
1073
1097
|
static skinnedMeshBoundsFrameOffsetCounter = 0;
|
|
1074
1098
|
static $skinnedMeshBoundsOffset = Symbol("gltf-progressive-skinnedMeshBoundsOffset");
|
|
@@ -1083,7 +1107,7 @@ let ie = class b {
|
|
|
1083
1107
|
return;
|
|
1084
1108
|
}
|
|
1085
1109
|
let l = 10 + 1, a = !1;
|
|
1086
|
-
if (
|
|
1110
|
+
if (k && e["DEBUG:LOD"] != null)
|
|
1087
1111
|
return e["DEBUG:LOD"];
|
|
1088
1112
|
const u = y.getMeshLODExtension(e.geometry)?.lods, d = y.getPrimitiveIndex(e.geometry), p = u && u.length > 0, L = y.getMaterialMinMaxLODsCount(e.material), _ = L.min_count !== 1 / 0 && L.min_count >= 0 && L.max_count >= 0;
|
|
1089
1113
|
if (!p && !_) {
|
|
@@ -1098,14 +1122,14 @@ let ie = class b {
|
|
|
1098
1122
|
if (!c.boundingBox)
|
|
1099
1123
|
c.computeBoundingBox();
|
|
1100
1124
|
else if (this.skinnedMeshAutoUpdateBoundsInterval > 0) {
|
|
1101
|
-
if (!c[
|
|
1102
|
-
const
|
|
1103
|
-
c[
|
|
1125
|
+
if (!c[D.$skinnedMeshBoundsOffset]) {
|
|
1126
|
+
const O = D.skinnedMeshBoundsFrameOffsetCounter++;
|
|
1127
|
+
c[D.$skinnedMeshBoundsOffset] = O;
|
|
1104
1128
|
}
|
|
1105
|
-
const x = c[
|
|
1129
|
+
const x = c[D.$skinnedMeshBoundsOffset];
|
|
1106
1130
|
if ((s.frames + x) % this.skinnedMeshAutoUpdateBoundsInterval === 0) {
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1131
|
+
const O = Z(c), B = c.geometry;
|
|
1132
|
+
O && (c.geometry = O), c.computeBoundingBox(), c.geometry = B;
|
|
1109
1133
|
}
|
|
1110
1134
|
}
|
|
1111
1135
|
G = c.boundingBox;
|
|
@@ -1120,64 +1144,64 @@ let ie = class b {
|
|
|
1120
1144
|
return;
|
|
1121
1145
|
}
|
|
1122
1146
|
}
|
|
1123
|
-
if (this._tempBox.copy(G), this._tempBox.applyMatrix4(e.matrixWorld), c.isPerspectiveCamera &&
|
|
1147
|
+
if (this._tempBox.copy(G), this._tempBox.applyMatrix4(e.matrixWorld), c.isPerspectiveCamera && D.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
1124
1148
|
r.mesh_lod = 0, r.texture_lod = 0;
|
|
1125
1149
|
return;
|
|
1126
1150
|
}
|
|
1127
1151
|
if (this._tempBox.applyMatrix4(this.projectionScreenMatrix), this.renderer.xr.enabled && c.isPerspectiveCamera && c.fov > 70) {
|
|
1128
1152
|
const f = this._tempBox.min, h = this._tempBox.max;
|
|
1129
|
-
let
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1132
|
-
const
|
|
1133
|
-
s.lastCentrality = (
|
|
1153
|
+
let v = f.x, b = f.y, $ = h.x, j = h.y;
|
|
1154
|
+
const ee = 2, ie = 1.5, te = (f.x + h.x) * 0.5, se = (f.y + h.y) * 0.5;
|
|
1155
|
+
v = (v - te) * ee + te, b = (b - se) * ee + se, $ = ($ - te) * ee + te, j = (j - se) * ee + se;
|
|
1156
|
+
const Be = v < 0 && $ > 0 ? 0 : Math.min(Math.abs(f.x), Math.abs(h.x)), $e = b < 0 && j > 0 ? 0 : Math.min(Math.abs(f.y), Math.abs(h.y)), ae = Math.max(Be, $e);
|
|
1157
|
+
s.lastCentrality = (ie - ae) * (ie - ae) * (ie - ae);
|
|
1134
1158
|
} else
|
|
1135
1159
|
s.lastCentrality = 1;
|
|
1136
1160
|
const x = this._tempBox.getSize(this._tempBoxSize);
|
|
1137
1161
|
x.multiplyScalar(0.5), screen.availHeight > 0 && I > 0 && x.multiplyScalar(I / screen.availHeight), t.isPerspectiveCamera ? x.x *= t.aspect : t.isOrthographicCamera;
|
|
1138
|
-
const
|
|
1139
|
-
B.copy(G), B.applyMatrix4(e.matrixWorld), B.applyMatrix4(
|
|
1162
|
+
const O = t.matrixWorldInverse, B = this._tempBox2;
|
|
1163
|
+
B.copy(G), B.applyMatrix4(e.matrixWorld), B.applyMatrix4(O);
|
|
1140
1164
|
const M = B.getSize(this._tempBox2Size), z = Math.max(M.x, M.y);
|
|
1141
|
-
if (Math.max(x.x, x.y) != 0 && z != 0 && (x.z = M.z / Math.max(M.x, M.y) * Math.max(x.x, x.y)), s.lastScreenCoverage = Math.max(x.x, x.y, x.z), s.lastScreenspaceVolume.copy(x), s.lastScreenCoverage *= s.lastCentrality,
|
|
1165
|
+
if (Math.max(x.x, x.y) != 0 && z != 0 && (x.z = M.z / Math.max(M.x, M.y) * Math.max(x.x, x.y)), s.lastScreenCoverage = Math.max(x.x, x.y, x.z), s.lastScreenspaceVolume.copy(x), s.lastScreenCoverage *= s.lastCentrality, k && D.debugDrawLine) {
|
|
1142
1166
|
const f = this.tempMatrix.copy(this.projectionScreenMatrix);
|
|
1143
1167
|
f.invert();
|
|
1144
|
-
const h =
|
|
1145
|
-
h.copy(this._tempBox.min),
|
|
1146
|
-
const
|
|
1147
|
-
h.z =
|
|
1168
|
+
const h = D.corner0, v = D.corner1, b = D.corner2, $ = D.corner3;
|
|
1169
|
+
h.copy(this._tempBox.min), v.copy(this._tempBox.max), v.x = h.x, b.copy(this._tempBox.max), b.y = h.y, $.copy(this._tempBox.max);
|
|
1170
|
+
const j = (h.z + $.z) * 0.5;
|
|
1171
|
+
h.z = v.z = b.z = $.z = j, h.applyMatrix4(f), v.applyMatrix4(f), b.applyMatrix4(f), $.applyMatrix4(f), D.debugDrawLine(h, v, 255), D.debugDrawLine(h, b, 255), D.debugDrawLine(v, $, 255), D.debugDrawLine(b, $, 255);
|
|
1148
1172
|
}
|
|
1149
1173
|
let w = 999;
|
|
1150
1174
|
if (u && s.lastScreenCoverage > 0)
|
|
1151
1175
|
for (let f = 0; f < u.length; f++) {
|
|
1152
|
-
const h = u[f],
|
|
1153
|
-
if (d > 0 && Me() && !h.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),
|
|
1176
|
+
const h = u[f], b = (h.densities?.[d] || h.density || 1e-5) / s.lastScreenCoverage;
|
|
1177
|
+
if (d > 0 && Me() && !h.densities && !globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] && (window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"] = !0, console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")), b < n) {
|
|
1154
1178
|
w = f;
|
|
1155
1179
|
break;
|
|
1156
1180
|
}
|
|
1157
1181
|
}
|
|
1158
1182
|
w < l && (l = w, a = !0);
|
|
1159
1183
|
}
|
|
1160
|
-
if (a ? r.mesh_lod = l : r.mesh_lod = s.lastLodLevel_Mesh,
|
|
1184
|
+
if (a ? r.mesh_lod = l : r.mesh_lod = s.lastLodLevel_Mesh, k && r.mesh_lod != s.lastLodLevel_Mesh) {
|
|
1161
1185
|
const x = u?.[r.mesh_lod];
|
|
1162
1186
|
x && console.debug(`Mesh LOD changed: ${s.lastLodLevel_Mesh} → ${r.mesh_lod} (density: ${x.densities?.[d].toFixed(0)}) | ${e.name}`);
|
|
1163
1187
|
}
|
|
1164
1188
|
if (_) {
|
|
1165
1189
|
const c = "saveData" in globalThis.navigator && globalThis.navigator.saveData === !0;
|
|
1166
1190
|
if (s.lastLodLevel_Texture < 0) {
|
|
1167
|
-
if (r.texture_lod = L.max_count - 1,
|
|
1191
|
+
if (r.texture_lod = L.max_count - 1, k) {
|
|
1168
1192
|
const x = L.lods[L.max_count - 1];
|
|
1169
|
-
|
|
1193
|
+
k && console.log(`First Texture LOD ${r.texture_lod} (${x.max_height}px) - ${e.name}`);
|
|
1170
1194
|
}
|
|
1171
1195
|
} else {
|
|
1172
1196
|
const x = s.lastScreenspaceVolume.x + s.lastScreenspaceVolume.y + s.lastScreenspaceVolume.z;
|
|
1173
|
-
let
|
|
1174
|
-
this.context?.engine === "model-viewer" && (
|
|
1175
|
-
const M = I / window.devicePixelRatio *
|
|
1197
|
+
let O = s.lastScreenCoverage * 4;
|
|
1198
|
+
this.context?.engine === "model-viewer" && (O *= 1.5);
|
|
1199
|
+
const M = I / window.devicePixelRatio * O;
|
|
1176
1200
|
let z = !1;
|
|
1177
1201
|
for (let S = L.lods.length - 1; S >= 0; S--) {
|
|
1178
1202
|
const w = L.lods[S];
|
|
1179
|
-
if (!(c && w.max_height >= 2048) && !(
|
|
1180
|
-
if (z = !0, r.texture_lod = S,
|
|
1203
|
+
if (!(c && w.max_height >= 2048) && !(Ie() && w.max_height > 4096) && (w.max_height > M || !z && S === 0)) {
|
|
1204
|
+
if (z = !0, r.texture_lod = S, k && r.texture_lod < s.lastLodLevel_Texture) {
|
|
1181
1205
|
const m = w.max_height;
|
|
1182
1206
|
console.log(`Texture LOD changed: ${s.lastLodLevel_Texture} → ${r.texture_lod} = ${m}px
|
|
1183
1207
|
Screensize: ${M.toFixed(0)}px, Coverage: ${(100 * s.lastScreenCoverage).toFixed(2)}%, Volume ${x.toFixed(1)}
|
|
@@ -1199,69 +1223,67 @@ class mt {
|
|
|
1199
1223
|
lastScreenspaceVolume = new A();
|
|
1200
1224
|
lastCentrality = 0;
|
|
1201
1225
|
}
|
|
1202
|
-
const
|
|
1226
|
+
const ve = Symbol("NEEDLE_mesh_lod"), re = Symbol("NEEDLE_texture_lod");
|
|
1203
1227
|
let he = null;
|
|
1204
|
-
function
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
return
|
|
1208
|
-
}),
|
|
1228
|
+
function Ce() {
|
|
1229
|
+
const i = yt();
|
|
1230
|
+
i && (i.mapURLs(function(t) {
|
|
1231
|
+
return De(), t;
|
|
1232
|
+
}), De(), he?.disconnect(), he = new MutationObserver((t) => {
|
|
1209
1233
|
t.forEach((e) => {
|
|
1210
1234
|
e.addedNodes.forEach((s) => {
|
|
1211
|
-
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" &&
|
|
1235
|
+
s instanceof HTMLElement && s.tagName.toLowerCase() === "model-viewer" && Re(s);
|
|
1212
1236
|
});
|
|
1213
1237
|
});
|
|
1214
1238
|
}), he.observe(document, { childList: !0, subtree: !0 }));
|
|
1215
1239
|
}
|
|
1216
1240
|
function yt() {
|
|
1217
|
-
if (typeof customElements > "u")
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
console.debug("[gltf-progressive] model-viewer defined"), Re();
|
|
1241
|
+
if (typeof customElements > "u") return null;
|
|
1242
|
+
const i = customElements.get("model-viewer");
|
|
1243
|
+
return i || (customElements.whenDefined("model-viewer").then(() => {
|
|
1244
|
+
console.debug("[gltf-progressive] model-viewer defined"), Ce();
|
|
1222
1245
|
}), null);
|
|
1223
1246
|
}
|
|
1224
|
-
function
|
|
1225
|
-
if (typeof document > "u")
|
|
1226
|
-
return;
|
|
1247
|
+
function De() {
|
|
1248
|
+
if (typeof document > "u") return;
|
|
1227
1249
|
document.querySelectorAll("model-viewer").forEach((t) => {
|
|
1228
|
-
|
|
1250
|
+
Re(t);
|
|
1229
1251
|
});
|
|
1230
1252
|
}
|
|
1231
|
-
const
|
|
1253
|
+
const be = /* @__PURE__ */ new WeakSet();
|
|
1232
1254
|
let xt = 0;
|
|
1233
|
-
function
|
|
1234
|
-
if (!
|
|
1255
|
+
function Re(i) {
|
|
1256
|
+
if (!i || be.has(i))
|
|
1235
1257
|
return null;
|
|
1236
|
-
|
|
1237
|
-
`,
|
|
1258
|
+
be.add(i), console.debug("[gltf-progressive] found new model-viewer..." + ++xt + `
|
|
1259
|
+
`, i.getAttribute("src"));
|
|
1238
1260
|
let t = null, e = null, s = null;
|
|
1239
|
-
for (let n =
|
|
1240
|
-
const r = Object.getOwnPropertySymbols(n),
|
|
1241
|
-
!t &&
|
|
1261
|
+
for (let n = i; n != null; n = Object.getPrototypeOf(n)) {
|
|
1262
|
+
const r = Object.getOwnPropertySymbols(n), o = r.find((u) => u.toString() == "Symbol(renderer)"), l = r.find((u) => u.toString() == "Symbol(scene)"), a = r.find((u) => u.toString() == "Symbol(needsRender)");
|
|
1263
|
+
!t && o != null && (t = i[o].threeRenderer), !e && l != null && (e = i[l]), !s && a != null && (s = i[a]);
|
|
1242
1264
|
}
|
|
1243
1265
|
if (t && e) {
|
|
1244
|
-
let
|
|
1266
|
+
let n = function() {
|
|
1245
1267
|
if (s) {
|
|
1246
|
-
let
|
|
1247
|
-
if (
|
|
1268
|
+
let o = 0, l = setInterval(() => {
|
|
1269
|
+
if (o++ > 5) {
|
|
1248
1270
|
clearInterval(l);
|
|
1249
1271
|
return;
|
|
1250
1272
|
}
|
|
1251
|
-
s?.call(
|
|
1273
|
+
s?.call(i);
|
|
1252
1274
|
}, 300);
|
|
1253
1275
|
}
|
|
1254
1276
|
};
|
|
1255
1277
|
console.debug("[gltf-progressive] setup model-viewer");
|
|
1256
|
-
const
|
|
1257
|
-
return
|
|
1258
|
-
s?.call(
|
|
1259
|
-
}),
|
|
1260
|
-
|
|
1261
|
-
}),
|
|
1262
|
-
|
|
1278
|
+
const r = oe.get(t, { engine: "model-viewer" });
|
|
1279
|
+
return oe.addPlugin(new wt()), r.enable(), r.addEventListener("changed", () => {
|
|
1280
|
+
s?.call(i);
|
|
1281
|
+
}), i.addEventListener("model-visibility", (o) => {
|
|
1282
|
+
o.detail.visible && s?.call(i);
|
|
1283
|
+
}), i.addEventListener("load", () => {
|
|
1284
|
+
n();
|
|
1263
1285
|
}), () => {
|
|
1264
|
-
|
|
1286
|
+
r.disable();
|
|
1265
1287
|
};
|
|
1266
1288
|
}
|
|
1267
1289
|
return null;
|
|
@@ -1284,22 +1306,19 @@ class wt {
|
|
|
1284
1306
|
return t.element;
|
|
1285
1307
|
}
|
|
1286
1308
|
tryParseTextureLOD(t, e) {
|
|
1287
|
-
if (e[
|
|
1288
|
-
|
|
1289
|
-
e[se] = !0;
|
|
1309
|
+
if (e[re] == !0) return;
|
|
1310
|
+
e[re] = !0;
|
|
1290
1311
|
const s = this.tryGetCurrentGLTF(t), n = this.tryGetCurrentModelViewer(t), r = this.getUrl(n);
|
|
1291
1312
|
if (r && s && e.material) {
|
|
1292
|
-
let
|
|
1293
|
-
if (a[
|
|
1294
|
-
|
|
1295
|
-
a[se] = !0, a.userData && (a.userData.LOD = -1);
|
|
1313
|
+
let o = function(a) {
|
|
1314
|
+
if (a[re] == !0) return;
|
|
1315
|
+
a[re] = !0, a.userData && (a.userData.LOD = -1);
|
|
1296
1316
|
const u = Object.keys(a);
|
|
1297
1317
|
for (let d = 0; d < u.length; d++) {
|
|
1298
1318
|
const p = u[d], L = a[p];
|
|
1299
1319
|
if (L?.isTexture === !0) {
|
|
1300
1320
|
const _ = L.userData?.associations?.textures;
|
|
1301
|
-
if (_ == null)
|
|
1302
|
-
continue;
|
|
1321
|
+
if (_ == null) continue;
|
|
1303
1322
|
const I = s.parser.json.textures[_];
|
|
1304
1323
|
if (!I) {
|
|
1305
1324
|
console.warn("Texture data not found for texture index " + _);
|
|
@@ -1312,74 +1331,70 @@ class wt {
|
|
|
1312
1331
|
}
|
|
1313
1332
|
}
|
|
1314
1333
|
};
|
|
1315
|
-
const
|
|
1316
|
-
if (Array.isArray(
|
|
1317
|
-
|
|
1318
|
-
l(a);
|
|
1319
|
-
else
|
|
1320
|
-
l(i);
|
|
1334
|
+
const l = e.material;
|
|
1335
|
+
if (Array.isArray(l)) for (const a of l) o(a);
|
|
1336
|
+
else o(l);
|
|
1321
1337
|
}
|
|
1322
1338
|
}
|
|
1323
1339
|
tryParseMeshLOD(t, e) {
|
|
1324
|
-
if (e[
|
|
1325
|
-
|
|
1326
|
-
e[De] = !0;
|
|
1340
|
+
if (e[ve] == !0) return;
|
|
1341
|
+
e[ve] = !0;
|
|
1327
1342
|
const s = this.tryGetCurrentModelViewer(t), n = this.getUrl(s);
|
|
1328
1343
|
if (!n)
|
|
1329
1344
|
return;
|
|
1330
1345
|
const r = e.userData?.gltfExtensions?.[F];
|
|
1331
1346
|
if (r && n) {
|
|
1332
|
-
const
|
|
1333
|
-
y.registerMesh(n,
|
|
1347
|
+
const o = e.uuid;
|
|
1348
|
+
y.registerMesh(n, o, e, 0, r.lods.length, r);
|
|
1334
1349
|
}
|
|
1335
1350
|
}
|
|
1336
1351
|
}
|
|
1337
|
-
function Lt(...
|
|
1352
|
+
function Lt(...i) {
|
|
1338
1353
|
let t, e, s, n;
|
|
1339
|
-
switch (
|
|
1354
|
+
switch (i.length) {
|
|
1340
1355
|
case 2:
|
|
1341
|
-
[s, e] =
|
|
1356
|
+
[s, e] = i, n = {};
|
|
1342
1357
|
break;
|
|
1343
1358
|
case 3:
|
|
1344
|
-
[s, e, n] =
|
|
1359
|
+
[s, e, n] = i;
|
|
1345
1360
|
break;
|
|
1346
1361
|
case 4:
|
|
1347
|
-
[t, e, s, n] =
|
|
1362
|
+
[t, e, s, n] = i;
|
|
1348
1363
|
break;
|
|
1349
1364
|
default:
|
|
1350
1365
|
throw new Error("Invalid arguments");
|
|
1351
1366
|
}
|
|
1352
|
-
we(e), Te(s),
|
|
1367
|
+
we(e), Te(s), Ae(s, {
|
|
1353
1368
|
progressive: !0,
|
|
1354
1369
|
...n?.hints
|
|
1355
|
-
}), s.register((
|
|
1356
|
-
const r =
|
|
1370
|
+
}), s.register((o) => new y(o));
|
|
1371
|
+
const r = oe.get(e);
|
|
1357
1372
|
return n?.enableLODsManager !== !1 && r.enable(), r;
|
|
1358
1373
|
}
|
|
1359
|
-
|
|
1374
|
+
Ce();
|
|
1360
1375
|
if (!nt) {
|
|
1361
|
-
const
|
|
1376
|
+
const i = {
|
|
1362
1377
|
gltfProgressive: {
|
|
1363
1378
|
useNeedleProgressive: Lt,
|
|
1364
|
-
LODsManager:
|
|
1365
|
-
configureLoader:
|
|
1366
|
-
getRaycastMesh:
|
|
1367
|
-
useRaycastMeshes:
|
|
1379
|
+
LODsManager: oe,
|
|
1380
|
+
configureLoader: Ae,
|
|
1381
|
+
getRaycastMesh: Z,
|
|
1382
|
+
useRaycastMeshes: it
|
|
1368
1383
|
}
|
|
1369
1384
|
};
|
|
1370
1385
|
if (!globalThis.Needle)
|
|
1371
|
-
globalThis.Needle =
|
|
1386
|
+
globalThis.Needle = i;
|
|
1372
1387
|
else
|
|
1373
|
-
for (const t in
|
|
1374
|
-
globalThis.Needle[t] =
|
|
1388
|
+
for (const t in i)
|
|
1389
|
+
globalThis.Needle[t] = i[t];
|
|
1375
1390
|
}
|
|
1376
1391
|
export {
|
|
1377
|
-
|
|
1392
|
+
oe as LODsManager,
|
|
1378
1393
|
y as NEEDLE_progressive,
|
|
1379
1394
|
Te as addDracoAndKTX2Loaders,
|
|
1380
|
-
|
|
1395
|
+
Ae as configureLoader,
|
|
1381
1396
|
we as createLoaders,
|
|
1382
|
-
|
|
1397
|
+
Z as getRaycastMesh,
|
|
1383
1398
|
Je as setDracoDecoderLocation,
|
|
1384
1399
|
Ze as setKTX2TranscoderLocation
|
|
1385
1400
|
};
|