@nebula-spatial/viewer 0.5.3 → 0.5.5
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 +58 -0
- package/README.md +97 -56
- package/USD-VISUAL-MATERIAL-SUPPORT.md +29 -2
- package/dist/assets/types.d.ts +3 -0
- package/dist/{index-DmGuwbBM.js → index-bTlVsOHA.js} +918 -797
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -8
- package/dist/{mjcf-visual-CFXIhVyT.js → mjcf-visual-zWaLqVqd.js} +7 -7
- package/dist/mujoco-runtime-DTxVmIzc.js +349 -0
- package/dist/session-CZghJvw6.js +883 -0
- package/dist/{session-BzIziNzg.js → session-DVCZX72J.js} +79 -75
- package/dist/stage-DGMYxyAS.js +597 -0
- package/dist/ui/types.d.ts +1 -0
- package/dist/{urdf-session-BleSrYNu.js → urdf-session-CF8xOenk.js} +737 -731
- package/dist/usd-session-DkwOFmds.js +4254 -0
- package/dist/version.d.ts +1 -1
- package/dist/{xacro-D1hcJ9kB.js → xacro-DidnrxXF.js} +1 -1
- package/openusd/openusd_probe.js +1 -1
- package/openusd/openusd_probe.wasm +0 -0
- package/package.json +1 -1
- package/dist/mujoco-runtime-7xiBQNJm.js +0 -324
- package/dist/session-Boljcc3d.js +0 -844
- package/dist/stage-C7B1_qJ0.js +0 -502
- package/dist/usd-session-DFbFB8bP.js +0 -2392
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { DataTexture as N, LinearMipmapLinearFilter as re, LinearFilter as se, LoadingManager as oe, Loader as ae, Texture as C, TextureLoader as ie, LinearSRGBColorSpace as
|
|
1
|
+
import { DataTexture as N, LinearMipmapLinearFilter as re, LinearFilter as se, LoadingManager as oe, Loader as ae, Texture as C, TextureLoader as ie, LinearSRGBColorSpace as V, SRGBColorSpace as le, RGBAFormat as K, UnsignedByteType as J, NoColorSpace as ce, Mesh as ue, MeshPhysicalMaterial as Z, MeshPhongMaterial as k, MeshLambertMaterial as fe, Color as _, Group as pe, Box3 as de, Vector3 as he } from "three";
|
|
2
2
|
import { DRACOLoader as me } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
3
3
|
import { GLTFLoader as ge } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
4
|
+
import { D as ye } from "./index-bTlVsOHA.js";
|
|
5
|
+
import { d as Y, a as q, S as we, b as j } from "./stage-DGMYxyAS.js";
|
|
6
|
+
import { TGALoader as be } from "three/examples/jsm/loaders/TGALoader.js";
|
|
7
|
+
import { FBXLoader as xe } from "three/examples/jsm/loaders/FBXLoader.js";
|
|
8
|
+
import { unzlibSync as Ee } from "three/examples/jsm/libs/fflate.module.js";
|
|
9
|
+
const Me = 16 * 1024 * 1024;
|
|
9
10
|
function Q(e, t) {
|
|
10
|
-
if (!e || !t || e * t >
|
|
11
|
+
if (!e || !t || e * t > Me) throw new Error("Invalid or oversized image dimensions (maximum 16M pixels).");
|
|
11
12
|
}
|
|
12
13
|
function B(e, t, n) {
|
|
13
14
|
if (t < 0 || n < 0 || t + n > e.length) throw new Error("Truncated image payload.");
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
+
function ve(e) {
|
|
16
17
|
const t = new Uint8Array(e);
|
|
17
18
|
B(t, 0, 18);
|
|
18
19
|
const n = new DataView(e), s = t[2], r = t[16], c = n.getUint16(12, !0), i = n.getUint16(14, !0);
|
|
@@ -32,13 +33,13 @@ function Me(e) {
|
|
|
32
33
|
B(t, f, d), f += d, o += l;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
return { data: new
|
|
36
|
+
return { data: new be().parse(e).data, width: c, height: i };
|
|
36
37
|
}
|
|
37
38
|
function z(e) {
|
|
38
39
|
const t = e >>> 11 & 31, n = e >>> 5 & 63, s = e & 31;
|
|
39
40
|
return [t << 3 | t >>> 2, n << 2 | n >>> 4, s << 3 | s >>> 2, 255];
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
+
function Se(e) {
|
|
42
43
|
const t = new Uint8Array(e);
|
|
43
44
|
B(t, 0, 128);
|
|
44
45
|
const n = new DataView(e), s = (l) => n.getUint32(l, !0);
|
|
@@ -83,13 +84,13 @@ function ve(e) {
|
|
|
83
84
|
}
|
|
84
85
|
return { data: g, width: r, height: c };
|
|
85
86
|
}
|
|
86
|
-
function
|
|
87
|
-
const n = t === "tga" ?
|
|
87
|
+
function Te(e, t) {
|
|
88
|
+
const n = t === "tga" ? ve(e) : Se(e), s = new Uint8Array(n.data.length), r = n.width * 4;
|
|
88
89
|
for (let i = 0; i < n.height; i++) s.set(n.data.subarray(i * r, (i + 1) * r), (n.height - 1 - i) * r);
|
|
89
90
|
const c = new N(s, n.width, n.height);
|
|
90
91
|
return c.flipY = !1, c.generateMipmaps = !0, c.minFilter = re, c.magFilter = se, c.needsUpdate = !0, c;
|
|
91
92
|
}
|
|
92
|
-
async function
|
|
93
|
+
async function Ae(e, t, n) {
|
|
93
94
|
t.signal.throwIfAborted();
|
|
94
95
|
const s = new AbortController(), r = s.signal, c = () => s.abort(t.signal.reason);
|
|
95
96
|
t.signal.addEventListener("abort", c, { once: !0 });
|
|
@@ -145,7 +146,7 @@ async function Te(e, t, n) {
|
|
|
145
146
|
r.throwIfAborted();
|
|
146
147
|
let x;
|
|
147
148
|
try {
|
|
148
|
-
x =
|
|
149
|
+
x = Te(v, this.binaryFormat);
|
|
149
150
|
} catch (T) {
|
|
150
151
|
throw new Error(`FBX texture decode failed (${this.binaryFormat}): ${u}: ${String(T)}`, { cause: T });
|
|
151
152
|
}
|
|
@@ -175,10 +176,10 @@ async function Te(e, t, n) {
|
|
|
175
176
|
o.addHandler(/\.tga$/i, new l("tga")), o.addHandler(/\.dds$/i, new l("dds")), o.addHandler(/.*/, new l());
|
|
176
177
|
let d;
|
|
177
178
|
try {
|
|
178
|
-
return d = new
|
|
179
|
+
return d = new xe(o).parse(e, ""), await Promise.all(f), t.signal.throwIfAborted(), { root: d, textures: h, textureFailures: y };
|
|
179
180
|
} catch (w) {
|
|
180
181
|
if (s.abort(w), await Promise.allSettled(f), d) {
|
|
181
|
-
const { disposeModelResources: u } = await import("./stage-
|
|
182
|
+
const { disposeModelResources: u } = await import("./stage-DGMYxyAS.js").then((E) => E.r);
|
|
182
183
|
u(d, h);
|
|
183
184
|
} else for (const u of h) u.dispose();
|
|
184
185
|
throw w;
|
|
@@ -187,35 +188,35 @@ async function Te(e, t, n) {
|
|
|
187
188
|
for (const w of g) URL.revokeObjectURL(w);
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
|
-
const P = "Kaydara FBX Binary \0",
|
|
191
|
-
function
|
|
191
|
+
const P = "Kaydara FBX Binary \0", Fe = /(?:^|[\r\n])\s*P:\s*"UpAxis"\s*,\s*"int"\s*,\s*"Integer"\s*,\s*""\s*,\s*(-?\d+)/i, Re = /(?:^|[\r\n])\s*P:\s*"UpAxisSign"\s*,\s*"int"\s*,\s*"Integer"\s*,\s*""\s*,\s*(-?\d+)/i;
|
|
192
|
+
function Ue(e) {
|
|
192
193
|
try {
|
|
193
|
-
const t = new Uint8Array(e), n =
|
|
194
|
+
const t = new Uint8Array(e), n = Ie(t) ? Oe(e) : De(new TextDecoder().decode(t));
|
|
194
195
|
return !n || n.sign !== 1 ? null : n.axis === 1 ? "y" : n.axis === 2 ? "z" : null;
|
|
195
196
|
} catch {
|
|
196
197
|
return null;
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
|
-
function
|
|
200
|
+
function Ie(e) {
|
|
200
201
|
if (e.byteLength < P.length) return !1;
|
|
201
202
|
for (let t = 0; t < P.length; t += 1)
|
|
202
203
|
if (e[t] !== P.charCodeAt(t)) return !1;
|
|
203
204
|
return !0;
|
|
204
205
|
}
|
|
205
|
-
function
|
|
206
|
+
function De(e) {
|
|
206
207
|
var r, c;
|
|
207
|
-
const t = Number.parseInt(((r =
|
|
208
|
+
const t = Number.parseInt(((r = Fe.exec(e)) == null ? void 0 : r[1]) ?? "", 10);
|
|
208
209
|
if (!Number.isInteger(t)) return null;
|
|
209
|
-
const n = (c =
|
|
210
|
+
const n = (c = Re.exec(e)) == null ? void 0 : c[1], s = n === void 0 ? 1 : Number.parseInt(n, 10);
|
|
210
211
|
return Number.isInteger(s) ? { axis: t, sign: s } : null;
|
|
211
212
|
}
|
|
212
|
-
function
|
|
213
|
+
function Oe(e) {
|
|
213
214
|
const t = new DataView(e);
|
|
214
215
|
if (t.byteLength < 27) return null;
|
|
215
216
|
const n = t.getUint32(23, !0) >= 7500;
|
|
216
217
|
let s = 27;
|
|
217
218
|
for (; s < t.byteLength; ) {
|
|
218
|
-
const r =
|
|
219
|
+
const r = X(t, s, n, !1);
|
|
219
220
|
if (!r) break;
|
|
220
221
|
if (r.name === "GlobalSettings") return ee(t, r.childrenOffset, r.endOffset, n);
|
|
221
222
|
s = r.endOffset;
|
|
@@ -225,7 +226,7 @@ function De(e) {
|
|
|
225
226
|
function ee(e, t, n, s) {
|
|
226
227
|
let r = t, c = null, i = 1;
|
|
227
228
|
for (; r < n; ) {
|
|
228
|
-
const f =
|
|
229
|
+
const f = X(e, r, s, !0);
|
|
229
230
|
if (!f) break;
|
|
230
231
|
if (f.name === "P") {
|
|
231
232
|
const [h, , , , g] = f.properties;
|
|
@@ -239,7 +240,7 @@ function ee(e, t, n, s) {
|
|
|
239
240
|
}
|
|
240
241
|
return c === null ? null : { axis: c, sign: i };
|
|
241
242
|
}
|
|
242
|
-
function
|
|
243
|
+
function X(e, t, n, s) {
|
|
243
244
|
const r = n ? 25 : 13;
|
|
244
245
|
if (t + r > e.byteLength) return null;
|
|
245
246
|
const c = $(e, t, n), i = $(e, t + (n ? 8 : 4), n), f = $(e, t + (n ? 16 : 8), n), h = e.getUint8(t + (n ? 24 : 12));
|
|
@@ -250,7 +251,7 @@ function _(e, t, n, s) {
|
|
|
250
251
|
if (s) {
|
|
251
252
|
let d = y;
|
|
252
253
|
for (let w = 0; w < i; w += 1) {
|
|
253
|
-
const u =
|
|
254
|
+
const u = Be(e, d);
|
|
254
255
|
if (l.push(u.value), d = u.nextOffset, d > o) return null;
|
|
255
256
|
}
|
|
256
257
|
}
|
|
@@ -262,7 +263,7 @@ function $(e, t, n) {
|
|
|
262
263
|
if (s > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error("FBX offset exceeds the safe integer range.");
|
|
263
264
|
return Number(s);
|
|
264
265
|
}
|
|
265
|
-
function
|
|
266
|
+
function Be(e, t) {
|
|
266
267
|
const n = String.fromCharCode(e.getUint8(t));
|
|
267
268
|
switch (n) {
|
|
268
269
|
case "Y":
|
|
@@ -296,9 +297,9 @@ function Oe(e, t) {
|
|
|
296
297
|
}
|
|
297
298
|
}
|
|
298
299
|
const L = /* @__PURE__ */ new Set(["Definitions", "ObjectType", "PropertyTemplate", "Objects", "Material", "Properties70", "Connections", "Texture", "Video", "Geometry", "LayerElementUV", "LayeredTexture", "BlendModes", "Alphas"]), te = /* @__PURE__ */ new Set(["P", "C", "RelativeFilename", "FileName", "Filename", "ShadingModel", "UVSet", "Scaling", "Translation", "Rotation", "RotationPivot", "ScalingPivot", "Name", "UV", "a"]);
|
|
299
|
-
function
|
|
300
|
+
function _e(e) {
|
|
300
301
|
var U, M, b, I, A, S;
|
|
301
|
-
const t = new Uint8Array(e), s = new TextDecoder().decode(t.subarray(0, 21)) === "Kaydara FBX Binary \0" ? Xe(e) :
|
|
302
|
+
const t = new Uint8Array(e), s = new TextDecoder().decode(t.subarray(0, 21)) === "Kaydara FBX Binary \0" ? Xe(e) : Ce(new TextDecoder().decode(t)), r = (m) => {
|
|
302
303
|
var v;
|
|
303
304
|
return new Map(
|
|
304
305
|
(((v = m == null ? void 0 : m.children.find((x) => x.name === "Properties70")) == null ? void 0 : v.children) ?? []).filter((x) => x.name === "P" && typeof x.values[0] == "string").map((x) => [x.values[0], x.values.slice(4)])
|
|
@@ -380,12 +381,12 @@ function Xe(e) {
|
|
|
380
381
|
const f = [];
|
|
381
382
|
let h = r;
|
|
382
383
|
for (; h < c; ) {
|
|
383
|
-
const g =
|
|
384
|
+
const g = X(t, h, n, !1);
|
|
384
385
|
if (!g) break;
|
|
385
386
|
if (g.endOffset > c) throw new Error("FBX child extends past its parent.");
|
|
386
387
|
if (L.has(g.name) || te.has(g.name)) {
|
|
387
|
-
const y =
|
|
388
|
-
f.push({ name: y.name, values: ["BlendModes", "Alphas"].includes(y.name) ?
|
|
388
|
+
const y = X(t, h, n, g.name !== "UV");
|
|
389
|
+
f.push({ name: y.name, values: ["BlendModes", "Alphas"].includes(y.name) ? Le(t, h, n, y.childrenOffset) : [...y.properties], children: L.has(y.name) ? s(y.childrenOffset, y.endOffset, i + 1) : [] });
|
|
389
390
|
}
|
|
390
391
|
h = g.endOffset;
|
|
391
392
|
}
|
|
@@ -393,7 +394,7 @@ function Xe(e) {
|
|
|
393
394
|
};
|
|
394
395
|
return s(27, t.byteLength, 0);
|
|
395
396
|
}
|
|
396
|
-
function
|
|
397
|
+
function Ce(e) {
|
|
397
398
|
const t = /"(?:\\.|[^"\\])*"|;[^\r\n]*|\r?\n|[^\S\r\n]+|[{}:,]|[^\s{}:,;]+/g;
|
|
398
399
|
let n = null;
|
|
399
400
|
const s = () => {
|
|
@@ -455,24 +456,24 @@ function _e(e) {
|
|
|
455
456
|
};
|
|
456
457
|
return c(0);
|
|
457
458
|
}
|
|
458
|
-
function
|
|
459
|
+
function Le(e, t, n, s) {
|
|
459
460
|
const r = n ? 25 : 13;
|
|
460
461
|
let c = t + r + e.getUint8(t + r - 1);
|
|
461
462
|
if (c === s) return [];
|
|
462
463
|
const i = String.fromCharCode(e.getUint8(c));
|
|
463
|
-
if (!["i", "d", "f"].includes(i)) return [...
|
|
464
|
+
if (!["i", "d", "f"].includes(i)) return [...X(e, t, n, !0).properties];
|
|
464
465
|
if (c + 13 > s) throw new Error("Truncated FBX layered array header.");
|
|
465
466
|
const f = e.getUint32(c + 1, !0), h = e.getUint32(c + 5, !0), g = e.getUint32(c + 9, !0), y = i === "d" ? 8 : 4;
|
|
466
467
|
if (f > 4096 || c + 13 + g !== s || ![0, 1].includes(h)) throw new Error("Invalid FBX layered array bounds.");
|
|
467
|
-
const o = new Uint8Array(e.buffer, e.byteOffset + c + 13, g), a = h === 1 ?
|
|
468
|
+
const o = new Uint8Array(e.buffer, e.byteOffset + c + 13, g), a = h === 1 ? Ee(o, { out: new Uint8Array(f * y) }) : o;
|
|
468
469
|
if (a.length !== f * y) throw new Error("Invalid FBX layered array size.");
|
|
469
470
|
const l = new DataView(a.buffer, a.byteOffset, a.byteLength);
|
|
470
471
|
return Array.from({ length: f }, (d, w) => i === "i" ? l.getInt32(w * y, !0) : i === "d" ? l.getFloat64(w * y, !0) : l.getFloat32(w * y, !0));
|
|
471
472
|
}
|
|
472
|
-
const H = (e) => e <= 0.04045 ? e / 12.92 : ((e + 0.055) / 1.055) ** 2.4,
|
|
473
|
+
const H = (e) => e <= 0.04045 ? e / 12.92 : ((e + 0.055) / 1.055) ** 2.4, Ne = (e) => e <= 31308e-7 ? e * 12.92 : 1.055 * e ** (1 / 2.4) - 0.055, Pe = /* @__PURE__ */ new Set([0, 1, 2, 4, 5]), $e = 4 * 1024 * 1024;
|
|
473
474
|
function W(e) {
|
|
474
475
|
const t = e.image, n = (t == null ? void 0 : t.naturalWidth) || (t == null ? void 0 : t.width), s = (t == null ? void 0 : t.naturalHeight) || (t == null ? void 0 : t.height);
|
|
475
|
-
if (!n || !s || n * s >
|
|
476
|
+
if (!n || !s || n * s > $e) throw new Error("missing image or image exceeds 4M pixels");
|
|
476
477
|
let r;
|
|
477
478
|
if (t.data) {
|
|
478
479
|
if (e.format !== K || e.type !== J || !(t.data instanceof Uint8Array) || t.data.length !== n * s * 4) throw new Error("require RGBA8 source");
|
|
@@ -488,10 +489,10 @@ function W(e) {
|
|
|
488
489
|
for (let i = 0; i < s; i++) for (let f = 0; f < n * 4; f++) c[(e.flipY ? s - i - 1 : i) * n * 4 + f] = r[i * n * 4 + f];
|
|
489
490
|
return { data: c, width: n, height: s };
|
|
490
491
|
}
|
|
491
|
-
function
|
|
492
|
+
function Ge(e, t, n) {
|
|
492
493
|
if (e.issues.some((o) => o.code !== "LAYERED_TEXTURE_NOT_COMPOSITED")) throw new Error("incompatible layer graph or coordinates");
|
|
493
494
|
if (e.layers.length < 1 || e.layers.length > 8) throw new Error("require 1–8 layers");
|
|
494
|
-
if (!e.layers.every((o) => o.blendMode !== null &&
|
|
495
|
+
if (!e.layers.every((o) => o.blendMode !== null && Pe.has(o.blendMode))) throw new Error("unsupported blend mode");
|
|
495
496
|
const s = e.layers.map((o) => {
|
|
496
497
|
const a = [...n].find((l) => l.ID === o.textureId);
|
|
497
498
|
if (!a) throw new Error(`missing decoded texture ${o.textureId}`);
|
|
@@ -516,21 +517,21 @@ function $e(e, t, n) {
|
|
|
516
517
|
const i = W(r), f = i.width * i.height;
|
|
517
518
|
if (e.layers[0].alpha !== 1 || i.data.some((o, a) => a % 4 === 3 && o !== 255)) throw new Error("base layer must be fully opaque with weight 1");
|
|
518
519
|
const h = new Float32Array(f * 3);
|
|
519
|
-
for (let o = 0; o < f; o++) for (let a = 0; a < 3; a++) h[o * 3 + a] = r.colorSpace ===
|
|
520
|
+
for (let o = 0; o < f; o++) for (let a = 0; a < 3; a++) h[o * 3 + a] = r.colorSpace === V ? i.data[o * 4 + a] / 255 : H(i.data[o * 4 + a] / 255);
|
|
520
521
|
for (let o = 1; o < s.length; o++) {
|
|
521
522
|
const a = s[o], l = W(a), d = e.layers[o];
|
|
522
523
|
if (l.width !== i.width || l.height !== i.height) throw new Error("layer dimensions differ");
|
|
523
524
|
for (let w = 0; w < f; w++) {
|
|
524
525
|
const u = d.alpha * l.data[w * 4 + 3] / 255;
|
|
525
526
|
for (let E = 0; E < 3; E++) {
|
|
526
|
-
const U = h[w * 3 + E], M = l.data[w * 4 + E] / 255, b = a.colorSpace ===
|
|
527
|
+
const U = h[w * 3 + E], M = l.data[w * 4 + E] / 255, b = a.colorSpace === V ? M : H(M), I = d.blendMode === 1 ? Math.min(1, U + b) : d.blendMode === 2 ? U * b : b;
|
|
527
528
|
h[w * 3 + E] = U + (I - U) * u;
|
|
528
529
|
}
|
|
529
530
|
}
|
|
530
531
|
}
|
|
531
532
|
const g = new Uint8Array(f * 4);
|
|
532
533
|
for (let o = 0; o < f; o++) g[o * 4 + 3] = 255;
|
|
533
|
-
for (let o = 0; o < f; o++) for (let a = 0; a < 3; a++) g[o * 4 + a] = Math.round(255 * Math.min(1, Math.max(0,
|
|
534
|
+
for (let o = 0; o < f; o++) for (let a = 0; a < 3; a++) g[o * 4 + a] = Math.round(255 * Math.min(1, Math.max(0, Ne(h[o * 3 + a]))));
|
|
534
535
|
const y = new N(g, i.width, i.height);
|
|
535
536
|
return y.colorSpace = le, y.generateMipmaps = r.generateMipmaps, y.wrapS = r.wrapS, y.wrapT = r.wrapT, y.minFilter = r.minFilter, y.magFilter = r.magFilter, y.anisotropy = r.anisotropy, y.offset.copy(r.offset), y.repeat.copy(r.repeat), y.center.copy(r.center), y.rotation = r.rotation, y.matrix.copy(r.matrix), y.matrixAutoUpdate = r.matrixAutoUpdate, y.channel = r.channel, y.mapping = r.mapping, y.userData.fbxLayerBaseId = e.layers[0].textureId, y.needsUpdate = !0, y;
|
|
536
537
|
}
|
|
@@ -567,7 +568,7 @@ function Ve(e, t) {
|
|
|
567
568
|
})).size > 1 && c("LAYERED_TEXTURE_COORDINATES_DIFFER", "UV sets or transforms differ; direct pixel blending is unsafe"), [{ id: s.id, role: n.role, layers: s.textureIds.map((a, l) => ({ textureId: a, blendMode: s.blendModes[l] ?? null, alpha: s.alphas[l] ?? null })), issues: r }];
|
|
568
569
|
});
|
|
569
570
|
}
|
|
570
|
-
const
|
|
571
|
+
const ke = {
|
|
571
572
|
DiffuseColor: "map",
|
|
572
573
|
"Maya|TEX_color_map": "map",
|
|
573
574
|
NormalMap: "normalMap",
|
|
@@ -584,11 +585,11 @@ const Ge = {
|
|
|
584
585
|
TransparentColor: "alphaMap",
|
|
585
586
|
TransparencyFactor: "alphaMap"
|
|
586
587
|
};
|
|
587
|
-
function
|
|
588
|
+
function Ye(e, t, n, s, r, c) {
|
|
588
589
|
var a;
|
|
589
590
|
const i = (a = s.modelUvSets) == null ? void 0 : a.get(e.ID ?? NaN), f = [], h = [], g = /* @__PURE__ */ new Set();
|
|
590
591
|
for (const l of n.textureConnections) {
|
|
591
|
-
const d =
|
|
592
|
+
const d = ke[l.role], w = d ? t[d] : void 0, u = s.textures.get(l.id) ?? (w instanceof C ? s.textures.get(w.userData.fbxLayerBaseId) : void 0);
|
|
592
593
|
if (!d || !u || g.has(d)) continue;
|
|
593
594
|
g.add(d);
|
|
594
595
|
const E = t[d];
|
|
@@ -638,20 +639,20 @@ function ke(e, t, n, s, r, c) {
|
|
|
638
639
|
}
|
|
639
640
|
return y.needsUpdate = !0, y;
|
|
640
641
|
}
|
|
641
|
-
function
|
|
642
|
+
function qe(e, t) {
|
|
642
643
|
return Math.min(1, Math.max(0, e));
|
|
643
644
|
}
|
|
644
|
-
function
|
|
645
|
+
function je(e, t, n, s, r = "r", c = !1) {
|
|
645
646
|
if (!Number.isInteger(t) || !Number.isInteger(n) || t <= 0 || n <= 0 || e.length !== t * n * 4)
|
|
646
647
|
throw new Error("Invalid FBX scalar RGBA dimensions.");
|
|
647
648
|
const i = new Uint8Array(e.length), f = { r: 0, g: 1, b: 2, a: 3 }[r];
|
|
648
649
|
for (let h = 0; h < n; h++) for (let g = 0; g < t; g++) {
|
|
649
|
-
const y = (h * t + g) * 4, o = ((c ? n - h - 1 : h) * t + g) * 4, a = Math.round(255 *
|
|
650
|
+
const y = (h * t + g) * 4, o = ((c ? n - h - 1 : h) * t + g) * 4, a = Math.round(255 * qe(e[y + f] / 255));
|
|
650
651
|
i.fill(a, o, o + 4);
|
|
651
652
|
}
|
|
652
653
|
return i;
|
|
653
654
|
}
|
|
654
|
-
function
|
|
655
|
+
function ze(e, t) {
|
|
655
656
|
const n = e.image;
|
|
656
657
|
if (!n) throw new Error("FBX scalar texture has no decoded image.");
|
|
657
658
|
const s = n.naturalWidth || n.width, r = n.naturalHeight || n.height;
|
|
@@ -668,17 +669,17 @@ function je(e, t) {
|
|
|
668
669
|
if (!h) throw new Error("FBX scalar texture conversion requires a 2D canvas.");
|
|
669
670
|
h.drawImage(n, 0, 0), c = h.getImageData(0, 0, s, r).data;
|
|
670
671
|
}
|
|
671
|
-
const i = new N(
|
|
672
|
+
const i = new N(je(c, s, r, t, "r", e.flipY), s, r);
|
|
672
673
|
return i.wrapS = e.wrapS, i.wrapT = e.wrapT, i.offset.copy(e.offset), i.repeat.copy(e.repeat), i.center.copy(e.center), i.rotation = e.rotation, i.matrix.copy(e.matrix), i.matrixAutoUpdate = e.matrixAutoUpdate, i.channel = e.channel, i.magFilter = e.magFilter, i.minFilter = e.minFilter, i.generateMipmaps = e.generateMipmaps, i.anisotropy = e.anisotropy, i.colorSpace = ce, i.needsUpdate = !0, i;
|
|
673
674
|
}
|
|
674
|
-
function
|
|
675
|
+
function He(e, t, n) {
|
|
675
676
|
const s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set(), h = [];
|
|
676
677
|
try {
|
|
677
678
|
e.traverse((a) => {
|
|
678
679
|
if (!(a instanceof ue)) return;
|
|
679
680
|
const l = t == null ? void 0 : t.modelMaterials.get(a.ID ?? NaN), d = (u) => l ? t == null ? void 0 : t.materials.get(l[u]) : void 0, w = (u, E) => {
|
|
680
|
-
const U = d(E), M =
|
|
681
|
-
return M instanceof Z && U && t ?
|
|
681
|
+
const U = d(E), M = We(u, s, U, n, t, r, c);
|
|
682
|
+
return M instanceof Z && U && t ? Ye(a, M, U, t, (b) => i.add(b), (b) => f.add(b)) : M;
|
|
682
683
|
};
|
|
683
684
|
h.push({ mesh: a, material: Array.isArray(a.material) ? a.material.map(w) : w(a.material, 0) });
|
|
684
685
|
});
|
|
@@ -701,7 +702,7 @@ function ze(e, t, n) {
|
|
|
701
702
|
const o = [...g].flatMap((a) => a.userData.fbxConversionReport ? [a.userData.fbxConversionReport] : []);
|
|
702
703
|
return e.userData.fbxConversionReports = o, o;
|
|
703
704
|
}
|
|
704
|
-
function
|
|
705
|
+
function We(e, t, n, s, r, c = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map()) {
|
|
705
706
|
var x, T, D;
|
|
706
707
|
const f = t.get(e);
|
|
707
708
|
if (f) return f;
|
|
@@ -713,21 +714,21 @@ function He(e, t, n, s, r, c = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ ne
|
|
|
713
714
|
return typeof R == "number" && Number.isFinite(R) ? R : F;
|
|
714
715
|
}, y = (p, F) => {
|
|
715
716
|
const R = n == null ? void 0 : n.values.get(p);
|
|
716
|
-
return R && R.length >= 3 && R.slice(0, 3).every((O) => typeof O == "number" && Number.isFinite(O)) ? new
|
|
717
|
+
return R && R.length >= 3 && R.slice(0, 3).every((O) => typeof O == "number" && Number.isFinite(O)) ? new _().setRGB(R[0], R[1], R[2]) : F.clone();
|
|
717
718
|
}, o = (p) => Math.min(1, Math.max(0, p)), a = o(g("SpecularFactor", 0.25) * 2), l = Math.sqrt(0.08 * a), d = (1 + l) / (1 - l);
|
|
718
719
|
let w = e.opacity;
|
|
719
720
|
if (n && (w = 1 - g("TransparencyFactor", 0), w === 0 || w === 1)) {
|
|
720
721
|
const p = (x = n.ownValues.get("Opacity")) == null ? void 0 : x[0];
|
|
721
|
-
w = typeof p == "number" && Number.isFinite(p) ? p : 1 - y("TransparentColor", new
|
|
722
|
+
w = typeof p == "number" && Number.isFinite(p) ? p : 1 - y("TransparentColor", new _(0)).r;
|
|
722
723
|
}
|
|
723
724
|
const u = new Z({
|
|
724
725
|
name: e.name,
|
|
725
726
|
// FBX diffuse textures supply the base color (as in Blender's importer),
|
|
726
727
|
// not an additional tint. Multiplying the atlas by DiffuseColor can turn
|
|
727
728
|
// blue atlas regions black when the material's constant color is red.
|
|
728
|
-
color: e.map ? new
|
|
729
|
+
color: e.map ? new _(16777215) : y("DiffuseColor", n ? new _(1, 1, 1) : e.color),
|
|
729
730
|
map: e.map,
|
|
730
|
-
emissive: e.emissiveMap ? new
|
|
731
|
+
emissive: e.emissiveMap ? new _(16777215) : y("EmissiveColor", n ? new _(0) : e.emissive),
|
|
731
732
|
emissiveMap: e.emissiveMap,
|
|
732
733
|
emissiveIntensity: g("EmissiveFactor", n ? 1 : e.emissiveIntensity),
|
|
733
734
|
normalMap: e.normalMap,
|
|
@@ -760,13 +761,13 @@ function He(e, t, n, s, r, c = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ ne
|
|
|
760
761
|
t.set(e, u);
|
|
761
762
|
const E = (p) => {
|
|
762
763
|
let F = c.get(p);
|
|
763
|
-
return F || (F =
|
|
764
|
+
return F || (F = ze(p, "identity"), c.set(p, F)), F;
|
|
764
765
|
}, U = n && r ? Ve(n, r) : [], M = [];
|
|
765
766
|
for (const p of U)
|
|
766
767
|
if (!(!["DiffuseColor", "EmissiveColor"].includes(p.role) || !r || !s) && n.textureConnections.filter((F) => F.role === p.role).length === 1)
|
|
767
768
|
try {
|
|
768
769
|
let F = i.get(p.id);
|
|
769
|
-
F || (F =
|
|
770
|
+
F || (F = Ge(p, r, s), i.set(p.id, F)), p.role === "DiffuseColor" ? (u.map = F, u.color.setRGB(1, 1, 1)) : (u.emissiveMap = F, u.emissive.setRGB(1, 1, 1)), p.issues = [], M.push(p.id);
|
|
770
771
|
} catch (F) {
|
|
771
772
|
p.issues.push({ status: "unsupported", code: "LAYERED_TEXTURE_BAKE_REJECTED", source: `layered:${p.id}:${F instanceof Error ? F.message : String(F)}`, target: p.role });
|
|
772
773
|
}
|
|
@@ -847,7 +848,7 @@ function He(e, t, n, s, r, c = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ ne
|
|
|
847
848
|
};
|
|
848
849
|
return u.userData.fbxConversionReport = v, u.visible = e.visible, u.toneMapped = e.toneMapped, u.clippingPlanes = e.clippingPlanes, u.clipIntersection = e.clipIntersection, u.clipShadows = e.clipShadows, u.polygonOffset = e.polygonOffset, u.polygonOffsetFactor = e.polygonOffsetFactor, u.polygonOffsetUnits = e.polygonOffsetUnits, u.dithering = e.dithering, u.needsUpdate = !0, t.set(e, u), u;
|
|
849
850
|
}
|
|
850
|
-
function
|
|
851
|
+
function ot(e, t) {
|
|
851
852
|
let n = !1, s = null, r = null, c = "z", i, f = null, h;
|
|
852
853
|
const g = () => {
|
|
853
854
|
n = !0;
|
|
@@ -855,16 +856,16 @@ function rt(e, t) {
|
|
|
855
856
|
c = t.options.upAxis ?? Y(t.format);
|
|
856
857
|
let o = null;
|
|
857
858
|
try {
|
|
858
|
-
if (n || t.signal.aborted) throw
|
|
859
|
+
if (n || t.signal.aborted) throw G();
|
|
859
860
|
const a = e.url ?? await e.resolve(e.entryPath ?? "");
|
|
860
861
|
if (o = new pe(), o.name = "viewer-model-root", t.format === "fbx") {
|
|
861
862
|
const d = await fetch(a, { signal: t.signal });
|
|
862
863
|
if (!d.ok) throw new Error(`FBX request failed: ${d.status} ${d.statusText}`);
|
|
863
864
|
const w = await d.arrayBuffer();
|
|
864
|
-
c = t.options.upAxis ??
|
|
865
|
-
const u =
|
|
865
|
+
c = t.options.upAxis ?? Ue(w) ?? Y(t.format);
|
|
866
|
+
const u = _e(w), E = await Ae(w, e, u);
|
|
866
867
|
h = E.textures, o.add(E.root);
|
|
867
|
-
const M =
|
|
868
|
+
const M = He(o, u, h).flatMap((I) => I.issues.filter((A) => A.status === "unsupported" || A.code === "TEXTURE_ROTATION_PROFILE" || A.code === "LAYERED_TEXTURE_BAKED").map((A) => `${I.materialName || I.materialId || "material"}: ${A.source}`));
|
|
868
869
|
M.length && (f = {
|
|
869
870
|
code: "W_FBX_MATERIAL_APPROXIMATED",
|
|
870
871
|
stage: "material-conversion",
|
|
@@ -883,15 +884,15 @@ function rt(e, t) {
|
|
|
883
884
|
const u = await w.loadAsync(a), E = u.scenes.filter((U) => U !== u.scene);
|
|
884
885
|
if (o.add(u.scene), n || t.signal.aborted) {
|
|
885
886
|
for (const U of E) o.add(U);
|
|
886
|
-
throw
|
|
887
|
+
throw G();
|
|
887
888
|
}
|
|
888
889
|
} finally {
|
|
889
890
|
d.dispose();
|
|
890
891
|
}
|
|
891
892
|
}
|
|
892
|
-
if (n || t.signal.aborted) throw
|
|
893
|
-
q(o, c),
|
|
894
|
-
const l = new
|
|
893
|
+
if (n || t.signal.aborted) throw G();
|
|
894
|
+
q(o, c), Ke(o);
|
|
895
|
+
const l = new we(o, t.options.simulationTheme, void 0, "model");
|
|
895
896
|
s = o, r = l, o = null;
|
|
896
897
|
} finally {
|
|
897
898
|
o && (j(o, h), h = void 0);
|
|
@@ -930,6 +931,9 @@ function rt(e, t) {
|
|
|
930
931
|
getGroundVisible() {
|
|
931
932
|
return (r == null ? void 0 : r.getGroundVisible()) ?? !0;
|
|
932
933
|
},
|
|
934
|
+
getGroundGridScale() {
|
|
935
|
+
return (r == null ? void 0 : r.getGroundGridScale()) ?? ye;
|
|
936
|
+
},
|
|
933
937
|
setUpAxis(o) {
|
|
934
938
|
if (n || !s || !r || !q(s, o)) return;
|
|
935
939
|
c = o, r.reseatGround();
|
|
@@ -945,16 +949,16 @@ function rt(e, t) {
|
|
|
945
949
|
}
|
|
946
950
|
};
|
|
947
951
|
}
|
|
948
|
-
function
|
|
952
|
+
function Ke(e) {
|
|
949
953
|
e.updateMatrixWorld(!0);
|
|
950
954
|
const t = new de().setFromObject(e);
|
|
951
955
|
if (t.isEmpty()) throw new Error("模型不包含可显示的几何内容。");
|
|
952
956
|
const n = t.getSize(new he()), s = Math.max(n.x, n.y, n.z);
|
|
953
957
|
if (!Number.isFinite(s) || s <= 0) throw new Error("模型尺寸无效。");
|
|
954
958
|
}
|
|
955
|
-
function
|
|
959
|
+
function G() {
|
|
956
960
|
return Object.assign(new Error("Model load aborted."), { name: "AbortError", code: "E_ABORTED" });
|
|
957
961
|
}
|
|
958
962
|
export {
|
|
959
|
-
|
|
963
|
+
ot as createModelSession
|
|
960
964
|
};
|