@nebula-spatial/viewer 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/FBX-MATERIAL-CONVERSION.md +97 -0
- package/README.md +152 -9
- package/dist/assets/types.d.ts +21 -0
- package/dist/{index-C9CW-EyW.js → index-D-o1ODOX.js} +2084 -1452
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/inspection/types.d.ts +99 -0
- package/dist/mjcf-visual-M1lmyjvw.js +63 -0
- package/dist/mujoco-runtime-C29PXDOl.js +258 -0
- package/dist/plugins.d.ts +5 -1
- package/dist/session-Cz6qHYMc.js +676 -0
- package/dist/session-c7xBLA4J.js +964 -0
- package/dist/{stage-D-Q_zul6.js → stage-D113SHD8.js} +140 -120
- package/dist/types.d.ts +2 -0
- package/dist/ui/types.d.ts +2 -0
- package/dist/urdf-session-AP-cMuwd.js +3001 -0
- package/dist/usd-session-CmSdkRw9.js +1192 -0
- package/package.json +4 -2
- package/dist/mujoco-runtime-s85kwjo7.js +0 -208
- package/dist/session-B-qVl3Yy.js +0 -761
- package/dist/session-B2SfkK9o.js +0 -266
- package/dist/usd-session-DCuV_H-Y.js +0 -538
|
@@ -0,0 +1,1192 @@
|
|
|
1
|
+
import { n as ot, c as rt, a as ie, b as it, d as at, p as ct, S as Te } from "./session-Cz6qHYMc.js";
|
|
2
|
+
import { DataTexture as Oe, UnsignedByteType as Me, RGBAFormat as Ce, NoColorSpace as De, Mesh as ne, Float32BufferAttribute as lt, SRGBColorSpace as Le, MeshStandardMaterial as ut, MeshPhysicalMaterial as pt, TextureLoader as dt, RepeatWrapping as ft, MirroredRepeatWrapping as ht, ClampToEdgeWrapping as mt, Color as yt, Group as le, Vector3 as I, Quaternion as V, Matrix4 as H, Box3 as ue, Sphere as St, SphereGeometry as gt, BoxGeometry as _t } from "three";
|
|
3
|
+
import { ConvexGeometry as Ut } from "three/examples/jsm/geometries/ConvexGeometry.js";
|
|
4
|
+
import { buildUSDScene as wt, USDLoader as Et } from "@openusd-wasm/three-loader";
|
|
5
|
+
import { PXR as bt } from "@openusd-wasm/pxr";
|
|
6
|
+
import { d as Ye } from "./stage-D113SHD8.js";
|
|
7
|
+
function Dt(e) {
|
|
8
|
+
if (!e) return;
|
|
9
|
+
if (typeof window > "u") return { baseURL: e };
|
|
10
|
+
const t = new URL(e, document.baseURI).href, n = new URL("openusd_pxr_wasm.js", t.endsWith("/") ? t : `${t}/`);
|
|
11
|
+
if (n.origin === window.location.origin) return { baseURL: t };
|
|
12
|
+
const s = new Blob([`import ${JSON.stringify(n.href)};
|
|
13
|
+
`], { type: "text/javascript" });
|
|
14
|
+
return {
|
|
15
|
+
baseURL: t,
|
|
16
|
+
// pxr 0.0.13 sets mainScriptUrlOrBlob itself; its public preRun hook runs
|
|
17
|
+
// before OpenUSD initializes and lazily spawns its pthread workers.
|
|
18
|
+
preRun: [(o) => {
|
|
19
|
+
o.mainScriptUrlOrBlob = s;
|
|
20
|
+
}]
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function xt(e, t, n = 1, s = 0) {
|
|
24
|
+
var h;
|
|
25
|
+
const o = e.image, p = (o == null ? void 0 : o.naturalWidth) || (o == null ? void 0 : o.width), i = (o == null ? void 0 : o.naturalHeight) || (o == null ? void 0 : o.height);
|
|
26
|
+
if (!Number.isInteger(p) || !Number.isInteger(i) || p <= 0 || i <= 0) throw new Error("Texture has no decoded pixels");
|
|
27
|
+
let a;
|
|
28
|
+
if (e instanceof Oe) {
|
|
29
|
+
if (e.type !== Me || e.format !== Ce || ((h = o.data) == null ? void 0 : h.length) !== p * i * 4) throw new Error("Unsupported scalar pixel format");
|
|
30
|
+
a = o.data;
|
|
31
|
+
} else {
|
|
32
|
+
const l = document.createElement("canvas");
|
|
33
|
+
l.width = p, l.height = i;
|
|
34
|
+
const y = l.getContext("2d", { willReadFrequently: !0 });
|
|
35
|
+
if (!y) throw new Error("Scalar conversion requires a 2D canvas");
|
|
36
|
+
y.drawImage(o, 0, 0), a = y.getImageData(0, 0, p, i).data;
|
|
37
|
+
}
|
|
38
|
+
const r = new Uint8Array(p * i * 4), u = "rgba".indexOf(t);
|
|
39
|
+
for (let l = 0; l < r.length; l += 4) {
|
|
40
|
+
const y = Math.round(255 * Math.min(1, Math.max(0, a[l + u] / 255 * n + s)));
|
|
41
|
+
r[l] = r[l + 1] = r[l + 2] = y, r[l + 3] = 255;
|
|
42
|
+
}
|
|
43
|
+
const c = new Oe(r, p, i, Ce, Me);
|
|
44
|
+
return c.wrapS = e.wrapS, c.wrapT = e.wrapT, c.offset.copy(e.offset), c.repeat.copy(e.repeat), c.center.copy(e.center), c.rotation = e.rotation, c.matrix.copy(e.matrix), c.matrixAutoUpdate = e.matrixAutoUpdate, c.channel = e.channel, c.flipY = e.flipY, c.minFilter = e.minFilter, c.magFilter = e.magFilter, c.anisotropy = e.anisotropy, c.generateMipmaps = e.generateMipmaps, c.colorSpace = De, c.needsUpdate = !0, c;
|
|
45
|
+
}
|
|
46
|
+
function vt(e, t, n, s = [], o = !1) {
|
|
47
|
+
if (e.some((u) => !Number.isInteger(u) || u < 0) || e.reduce((u, c) => u + c, 0) !== t.length || s.some((u) => !Number.isInteger(u) || u < 0 || u >= e.length))
|
|
48
|
+
throw new Error("Invalid authored face topology");
|
|
49
|
+
const p = [], i = [], a = new Set(s);
|
|
50
|
+
let r = 0;
|
|
51
|
+
if (e.forEach((u, c) => {
|
|
52
|
+
if (!a.has(c)) for (let h = 1; h < u - 1; h++)
|
|
53
|
+
p.push(r, r + (o ? h + 1 : h), r + (o ? h : h + 1)), i.push(c);
|
|
54
|
+
r += u;
|
|
55
|
+
}), p.length !== n.length || p.some((u, c) => t[u] !== n[c]))
|
|
56
|
+
throw new Error("Authored polygon/loader corner correspondence unavailable");
|
|
57
|
+
return { corners: p, faces: i };
|
|
58
|
+
}
|
|
59
|
+
function At(e, t, n) {
|
|
60
|
+
if (t.length !== n || t.some((o) => !Number.isInteger(o) || o < 0 || o >= e.length))
|
|
61
|
+
throw new Error("Invalid faceVarying UV indices");
|
|
62
|
+
const s = t.flatMap((o) => e[o]);
|
|
63
|
+
if (s.length !== n * 2 || !s.every(Number.isFinite)) throw new Error("Invalid UV values");
|
|
64
|
+
return s;
|
|
65
|
+
}
|
|
66
|
+
function Pt(e, t) {
|
|
67
|
+
const n = Array(e).fill(0);
|
|
68
|
+
for (const s of t) for (const o of s.faces) {
|
|
69
|
+
if (!Number.isInteger(o) || o < 0 || o >= e || n[o] !== 0)
|
|
70
|
+
throw new Error("Invalid or overlapping material subset faces");
|
|
71
|
+
n[o] = s.slot;
|
|
72
|
+
}
|
|
73
|
+
return n;
|
|
74
|
+
}
|
|
75
|
+
function It(e, t, n, s) {
|
|
76
|
+
if (!e.stage) return;
|
|
77
|
+
const o = e.stage, p = e.pxr, i = p.Usd.TimeCode.Default(), a = (u, c) => t.warnings.push({
|
|
78
|
+
code: "USD_VISUAL_TOPOLOGY_UNSUPPORTED",
|
|
79
|
+
source: "usd-visual",
|
|
80
|
+
message: `USD ${u} 的部分视觉拓扑未能安全补齐,未确认部分保留 Loader 输出:${String(c)}`
|
|
81
|
+
}), r = (u, c) => {
|
|
82
|
+
const h = u.GetAttribute(c);
|
|
83
|
+
try {
|
|
84
|
+
return h.IsValid() ? h.Get(i) : null;
|
|
85
|
+
} finally {
|
|
86
|
+
h.delete();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
try {
|
|
90
|
+
for (const u of e.data.elements) {
|
|
91
|
+
const c = e.index.objectsByPath.get(u.path);
|
|
92
|
+
if (!(c instanceof ne)) continue;
|
|
93
|
+
const h = new p.Sdf.Path(u.path), l = o.GetPrimAtPath(h);
|
|
94
|
+
let y = [];
|
|
95
|
+
try {
|
|
96
|
+
if (l.GetTypeName() !== "Mesh") continue;
|
|
97
|
+
y = l.GetChildren();
|
|
98
|
+
const m = y.filter((g) => g.GetTypeName() === "GeomSubset" && r(g, "familyName") === "materialBind"), S = l.GetAttribute("primvars:st");
|
|
99
|
+
let N = null, U = null;
|
|
100
|
+
try {
|
|
101
|
+
n(u.material) && S.IsValid() && S.GetMetadata("interpolation") === "faceVarying" && (U = r(l, "primvars:st:indices"), U && (N = S.Get(i)));
|
|
102
|
+
} finally {
|
|
103
|
+
S.delete();
|
|
104
|
+
}
|
|
105
|
+
const E = m.length > 0 && !Array.isArray(c.material) && c.geometry.groups.length === 0;
|
|
106
|
+
if (!N && !E) continue;
|
|
107
|
+
const b = r(l, "faceVertexCounts"), w = r(l, "faceVertexIndices");
|
|
108
|
+
if (!b || !w || c.geometry.index) throw new Error("Authored face topology unavailable");
|
|
109
|
+
const P = vt(
|
|
110
|
+
b,
|
|
111
|
+
w,
|
|
112
|
+
u.geometry.pointIndices ?? [],
|
|
113
|
+
r(l, "holeIndices") ?? [],
|
|
114
|
+
r(l, "orientation") === "leftHanded"
|
|
115
|
+
);
|
|
116
|
+
if (c.geometry.getAttribute("position").count !== P.corners.length)
|
|
117
|
+
throw new Error("Loader geometry corner count mismatch");
|
|
118
|
+
if (N && U) {
|
|
119
|
+
const g = At(N, U, w.length), A = P.corners.flatMap((M) => [g[M * 2], g[M * 2 + 1]]), C = c.geometry.getAttribute("uv");
|
|
120
|
+
(!C || C.array.length !== A.length || A.some((M, _) => Math.abs(M - C.array[_]) > 1e-6)) && (c.geometry.setAttribute("uv", new lt(A, 2)), u.geometry.uvs = A);
|
|
121
|
+
}
|
|
122
|
+
if (!E) continue;
|
|
123
|
+
const x = m.map((g) => {
|
|
124
|
+
if (r(g, "elementType") !== "face") throw new Error("Non-face material subset");
|
|
125
|
+
const A = p.UsdShade.ComputeBoundMaterialPath(g), C = (A == null ? void 0 : A.resolvedTargetPath) || (A == null ? void 0 : A.materialPath);
|
|
126
|
+
if (!C || !e.index.materialsByPath.has(C)) throw new Error("Unresolved subset material");
|
|
127
|
+
const M = r(g, "indices");
|
|
128
|
+
if (!Array.isArray(M)) throw new Error("Missing subset face indices");
|
|
129
|
+
return { materialPath: C, faces: M };
|
|
130
|
+
}), f = [...new Set(x.map((g) => g.materialPath))], v = Pt(b.length, x.map((g) => ({ faces: g.faces, slot: f.indexOf(g.materialPath) + 1 }))), O = P.faces.map((g) => v[g]), d = [c.material];
|
|
131
|
+
try {
|
|
132
|
+
for (const g of f) d.push(s(u, g));
|
|
133
|
+
} catch (g) {
|
|
134
|
+
for (const A of d.slice(1)) A.dispose();
|
|
135
|
+
throw g;
|
|
136
|
+
}
|
|
137
|
+
c.material = d;
|
|
138
|
+
for (let g = 0; g < O.length; ) {
|
|
139
|
+
let A = g + 1;
|
|
140
|
+
for (; A < O.length && O[A] === O[g]; ) A++;
|
|
141
|
+
c.geometry.addGroup(g * 3, (A - g) * 3, O[g]), g = A;
|
|
142
|
+
}
|
|
143
|
+
} catch (m) {
|
|
144
|
+
a(u.path, m);
|
|
145
|
+
} finally {
|
|
146
|
+
for (const m of y) m.delete();
|
|
147
|
+
l.delete(), h.delete();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} finally {
|
|
151
|
+
i.delete();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const Rt = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "webp", "avif", "gif", "bmp"]), Nt = /^(?:UsdPreviewSurface|ND_UsdPreviewSurface_surfaceshader)$/i, $t = /(?:standard.?surface|principled|openpbr|adobe.?standard.?material)/i;
|
|
155
|
+
async function Tt(e, t) {
|
|
156
|
+
var p;
|
|
157
|
+
It(e, t.diagnostics, (i) => {
|
|
158
|
+
if (!i) return !0;
|
|
159
|
+
const a = e.index.materialsByPath.get(i), r = a && ye(a);
|
|
160
|
+
return !!r && pe(r) && Fe(r, /* @__PURE__ */ new Set());
|
|
161
|
+
}, (i, a) => {
|
|
162
|
+
const r = e.data.view.prims.find((y) => y.path === i.path);
|
|
163
|
+
if (!r) throw new Error(`Missing view prim: ${i.path}`);
|
|
164
|
+
const u = e.index.materialsByPath.get(a), c = ye(u), l = wt({
|
|
165
|
+
...e.data,
|
|
166
|
+
elements: [{ ...i, material: a }],
|
|
167
|
+
view: { ...e.data.view, prims: [{ ...r, parentPath: null }] },
|
|
168
|
+
animations: [],
|
|
169
|
+
lights: [],
|
|
170
|
+
skels: { ...e.data.skels, bindings: [], skeletons: [], animations: [] }
|
|
171
|
+
}, {
|
|
172
|
+
convertZUp: !1,
|
|
173
|
+
loadLights: !1,
|
|
174
|
+
loadTextures: !c,
|
|
175
|
+
sourcePath: t.sourcePath,
|
|
176
|
+
textureResolver: (y) => {
|
|
177
|
+
for (const m of [y.resolvedPath, y.path, y.url]) {
|
|
178
|
+
if (!m) continue;
|
|
179
|
+
const S = t.files.objectUrlIfPresent(m, t.entryDirectory ?? "");
|
|
180
|
+
if (S) return S;
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}).index.objectsByPath.get(i.path);
|
|
185
|
+
if (l.geometry.dispose(), Array.isArray(l.material)) throw new Error("Unexpected scratch material array");
|
|
186
|
+
return l.material;
|
|
187
|
+
});
|
|
188
|
+
const n = Mt(e), s = [];
|
|
189
|
+
for (const [i, a] of n) {
|
|
190
|
+
const r = e.index.materialsByPath.get(i);
|
|
191
|
+
if (!r) continue;
|
|
192
|
+
const u = a[0], c = ae(a.flatMap((f) => jt(f.userData.usdMaterialDiagnostics))), h = xe(u.userData.usdSurfaceShaderId);
|
|
193
|
+
if (h && (Nt.test(h) || $t.test(h))) {
|
|
194
|
+
const f = await Ot(r, a, c, t);
|
|
195
|
+
s.push({
|
|
196
|
+
materialPath: i,
|
|
197
|
+
sourceShaderId: h,
|
|
198
|
+
action: f.applied.length ? "augmented" : "preserved",
|
|
199
|
+
fidelity: c.some((v) => !f.resolved.includes(v)) ? "bounded-approximation" : "native",
|
|
200
|
+
appliedInputs: f.applied,
|
|
201
|
+
unsupportedNodes: [],
|
|
202
|
+
resources: f.resources,
|
|
203
|
+
loaderDiagnostics: c,
|
|
204
|
+
resolvedLoaderDiagnostics: f.resolved
|
|
205
|
+
});
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const l = ye(r);
|
|
209
|
+
if (!l) {
|
|
210
|
+
const f = je(e, i);
|
|
211
|
+
s.push({
|
|
212
|
+
materialPath: i,
|
|
213
|
+
sourceShaderId: null,
|
|
214
|
+
action: "fallback",
|
|
215
|
+
fidelity: f ? "authored-fallback" : "default-fallback",
|
|
216
|
+
appliedInputs: [],
|
|
217
|
+
unsupportedNodes: ae(r.shaders.map((v) => v.id).filter(Je)),
|
|
218
|
+
resources: [],
|
|
219
|
+
loaderDiagnostics: c
|
|
220
|
+
});
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const y = [], m = [], S = /* @__PURE__ */ new Set(), N = Lt(a, l, y);
|
|
224
|
+
let U = !1;
|
|
225
|
+
if (pe(l)) {
|
|
226
|
+
const f = de(Y(l, ["diffuse_texture"]));
|
|
227
|
+
if (f) {
|
|
228
|
+
const v = await Ue(f, t);
|
|
229
|
+
if (m.push(v.report), v.url && Fe(l, S) && a.every((O) => Q(O) && !O.map)) {
|
|
230
|
+
let O = null;
|
|
231
|
+
try {
|
|
232
|
+
O = await (t.createTexture ?? Ee)(v.url, Le);
|
|
233
|
+
} catch (d) {
|
|
234
|
+
if (d instanceof Error && d.name === "AbortError") throw d;
|
|
235
|
+
m[m.length - 1] = { path: f, status: "decode-failed" };
|
|
236
|
+
}
|
|
237
|
+
if (O) {
|
|
238
|
+
for (const d of a)
|
|
239
|
+
Q(d) && (d.map = O, d.color.set(16777215), d.needsUpdate = !0, U = !0);
|
|
240
|
+
U ? y.push("diffuse_texture") : O.dispose();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
Ct(l, S);
|
|
245
|
+
}
|
|
246
|
+
const E = q(l, "diffuseColor") ?? q(l, "baseColor");
|
|
247
|
+
let b = !1;
|
|
248
|
+
if (E) {
|
|
249
|
+
const f = te(r, E);
|
|
250
|
+
if (f && He(f)) {
|
|
251
|
+
const v = Bt(f);
|
|
252
|
+
if (v) {
|
|
253
|
+
const O = await Ue(v.path, t);
|
|
254
|
+
m.push(O.report);
|
|
255
|
+
const d = q(f, "manifold");
|
|
256
|
+
d && S.add(((p = te(r, d)) == null ? void 0 : p.id) ?? d.path);
|
|
257
|
+
const g = Object.keys(f.inputs).filter((M) => !["inputs:filename", "inputs:resultRGB", "inputs:linearize"].includes(M)), A = f.inputs["inputs:linearize"], C = A === 0 || A === 1;
|
|
258
|
+
if (C || S.add("PxrTexture.colorSpace"), g.length > 0 && !d && S.add("PxrTexture.controls"), O.url && !d && g.length === 0 && C && E.outputName === "resultRGB" && a.every((M) => Q(M) && !M.map)) {
|
|
259
|
+
let M = null;
|
|
260
|
+
try {
|
|
261
|
+
M = await (t.createTexture ?? Ee)(O.url, A === 1 ? Le : De);
|
|
262
|
+
} catch (_) {
|
|
263
|
+
if (_ instanceof Error && _.name === "AbortError") throw _;
|
|
264
|
+
m[m.length - 1] = { path: v.path, status: "decode-failed" };
|
|
265
|
+
}
|
|
266
|
+
if (M) {
|
|
267
|
+
for (const _ of a)
|
|
268
|
+
Q(_) && (_.map = M, _.color.set(16777215), _.needsUpdate = !0, b = !0);
|
|
269
|
+
b ? y.push("diffuseColor.texture") : M.dispose();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
} else
|
|
273
|
+
S.add(f.id ?? f.path);
|
|
274
|
+
} else f ? S.add(f.id ?? f.path) : S.add(E.path);
|
|
275
|
+
}
|
|
276
|
+
Ft(r, l, S);
|
|
277
|
+
const w = N || b || U ? "augmented" : "fallback", P = je(e, i), x = w === "augmented" ? "bounded-approximation" : P ? "authored-fallback" : "default-fallback";
|
|
278
|
+
qe(t.diagnostics, i, l, y, S, m, w), s.push({
|
|
279
|
+
materialPath: i,
|
|
280
|
+
sourceShaderId: We(l),
|
|
281
|
+
action: w,
|
|
282
|
+
fidelity: x,
|
|
283
|
+
appliedInputs: ae(y),
|
|
284
|
+
unsupportedNodes: [...S],
|
|
285
|
+
resources: m,
|
|
286
|
+
loaderDiagnostics: c
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
const o = s.filter((i) => i.loaderDiagnostics.some(
|
|
290
|
+
(a) => {
|
|
291
|
+
var r;
|
|
292
|
+
return !((r = i.resolvedLoaderDiagnostics) != null && r.includes(a)) && !(i.action === "augmented" && a === `Material ${i.materialPath} has no supported surface shader.`);
|
|
293
|
+
}
|
|
294
|
+
));
|
|
295
|
+
return o.length > 0 && t.diagnostics.droppedFeatures.push({
|
|
296
|
+
code: "USD_VISUAL_LOADER_DIAGNOSTIC",
|
|
297
|
+
message: `${o.length} 个 USD 材质仍有尚未被视觉适配层消解的 Loader 限制;具体材质和原始诊断见 visualAdaptation 报告。`,
|
|
298
|
+
source: "usd-visual"
|
|
299
|
+
}), Object.freeze({
|
|
300
|
+
schemaVersion: 1,
|
|
301
|
+
materials: s,
|
|
302
|
+
summary: Object.freeze({
|
|
303
|
+
preserved: s.filter((i) => i.action === "preserved").length,
|
|
304
|
+
augmented: s.filter((i) => i.action === "augmented").length,
|
|
305
|
+
fallback: s.filter((i) => i.action === "fallback").length,
|
|
306
|
+
missingResources: s.flatMap((i) => i.resources).filter((i) => i.status === "missing").length,
|
|
307
|
+
unsupportedResources: s.flatMap((i) => i.resources).filter((i) => i.status === "unsupported-format").length
|
|
308
|
+
})
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
async function Ot(e, t, n, s) {
|
|
312
|
+
var x;
|
|
313
|
+
const o = { applied: [], resolved: [], resources: [] }, p = xe((x = t[0]) == null ? void 0 : x.userData.usdSurfaceShaderPath), i = e.shaders.find((f) => f.path === p) ?? e.shaders.find((f) => f.id === "UsdPreviewSurface");
|
|
314
|
+
if (!i || i.id !== "UsdPreviewSurface") return o;
|
|
315
|
+
const a = q(i, "roughness");
|
|
316
|
+
if (!a || !a.outputName || !["r", "g", "b", "a"].includes(a.outputName)) return o;
|
|
317
|
+
const r = te(e, a);
|
|
318
|
+
if (!r || r.id !== "UsdUVTexture") return o;
|
|
319
|
+
const u = `Texture output ${a.outputName} from ${r.path} cannot be mapped to Three.js roughness without channel repacking.`;
|
|
320
|
+
if (!n.includes(u) || Y(r, ["sourceColorSpace"]) !== "raw") return o;
|
|
321
|
+
const c = q(r, "st");
|
|
322
|
+
if (c) {
|
|
323
|
+
const f = te(e, c);
|
|
324
|
+
if ((f == null ? void 0 : f.id) !== "UsdPrimvarReader_float2" || Y(f, ["varname"]) !== "st") return o;
|
|
325
|
+
} else if (r.inputs["inputs:st"] !== void 0) return o;
|
|
326
|
+
const h = "rgba".indexOf(a.outputName);
|
|
327
|
+
function l(f, v) {
|
|
328
|
+
if (q(r, f)) return null;
|
|
329
|
+
const O = r.inputs[`inputs:${f}`];
|
|
330
|
+
return O === void 0 ? v : Array.isArray(O) && O.length === 4 && O.every(Number.isFinite) ? O[h] : null;
|
|
331
|
+
}
|
|
332
|
+
const y = l("scale", 1), m = l("bias", 0);
|
|
333
|
+
if (y === null || m === null) return o;
|
|
334
|
+
function S(f) {
|
|
335
|
+
if (q(r, f)) return null;
|
|
336
|
+
const v = r.inputs[`inputs:${f}`];
|
|
337
|
+
return v === "repeat" ? ft : v === "mirror" ? ht : v === "clamp" ? mt : null;
|
|
338
|
+
}
|
|
339
|
+
const N = S("wrapS"), U = S("wrapT");
|
|
340
|
+
if (N === null || U === null) return o;
|
|
341
|
+
const E = de(Y(r, ["file"]));
|
|
342
|
+
if (!E) return o;
|
|
343
|
+
const b = t.filter(Q);
|
|
344
|
+
if (!b.length) return o;
|
|
345
|
+
if (b.every((f) => {
|
|
346
|
+
var v;
|
|
347
|
+
return ((v = f.roughnessMap) == null ? void 0 : v.userData.usdResolvedChannelDiagnostic) === u;
|
|
348
|
+
}))
|
|
349
|
+
return o.applied.push(`roughness.texture.${a.outputName}->g`), o.resolved.push(u), o;
|
|
350
|
+
if (b.some((f) => f.roughnessMap !== null)) return o;
|
|
351
|
+
const w = await Ue(E, s);
|
|
352
|
+
o.resources.push(w.report);
|
|
353
|
+
let P = null;
|
|
354
|
+
if (w.url)
|
|
355
|
+
try {
|
|
356
|
+
P = await (s.createTexture ?? Ee)(w.url, De);
|
|
357
|
+
const f = xt(P, a.outputName, y, m);
|
|
358
|
+
f.wrapS = N, f.wrapT = U, f.userData.usdResolvedChannelDiagnostic = u;
|
|
359
|
+
for (const v of b)
|
|
360
|
+
v.roughnessMap = f, v.roughness = 1, v.needsUpdate = !0;
|
|
361
|
+
o.applied.push(`roughness.texture.${a.outputName}->g`), o.resolved.push(u);
|
|
362
|
+
} catch (f) {
|
|
363
|
+
if (f instanceof Error && f.name === "AbortError") throw f;
|
|
364
|
+
o.resources[0] = { path: E, status: "decode-failed" };
|
|
365
|
+
} finally {
|
|
366
|
+
P == null || P.dispose();
|
|
367
|
+
}
|
|
368
|
+
return qe(s.diagnostics, e.path, i, [], /* @__PURE__ */ new Set(), o.resources, "preserved"), o;
|
|
369
|
+
}
|
|
370
|
+
function Mt(e) {
|
|
371
|
+
const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
|
|
372
|
+
return e.scene.traverse((s) => {
|
|
373
|
+
if (s instanceof ne)
|
|
374
|
+
for (const o of Array.isArray(s.material) ? s.material : [s.material]) {
|
|
375
|
+
if (n.has(o)) continue;
|
|
376
|
+
n.add(o);
|
|
377
|
+
const p = xe(o.userData.usdMaterialPath);
|
|
378
|
+
if (!p) continue;
|
|
379
|
+
const i = t.get(p);
|
|
380
|
+
i ? i.push(o) : t.set(p, [o]);
|
|
381
|
+
}
|
|
382
|
+
}), t;
|
|
383
|
+
}
|
|
384
|
+
function ye(e) {
|
|
385
|
+
const t = e.shaders.filter((n) => /^PxrSurface$/i.test(n.id ?? "") || pe(n));
|
|
386
|
+
return t.length === 1 ? t[0] : null;
|
|
387
|
+
}
|
|
388
|
+
function pe(e) {
|
|
389
|
+
var n;
|
|
390
|
+
const t = de(e.inputs["info:mdl:sourceAsset"]);
|
|
391
|
+
return ((n = t == null ? void 0 : t.replaceAll("\\", "/").split("/").at(-1)) == null ? void 0 : n.toLowerCase()) === "omnipbr.mdl";
|
|
392
|
+
}
|
|
393
|
+
function We(e) {
|
|
394
|
+
return pe(e) ? "OmniPBR" : e.id;
|
|
395
|
+
}
|
|
396
|
+
function Fe(e, t) {
|
|
397
|
+
const n = Ve(e, "texture_scale", [1, 1]), s = Ve(e, "texture_translate", [0, 0]), o = ee(e, ["texture_rotate"]) ?? 0, p = Xe(e, ["project_uvw"], !1), i = ee(e, ["uv_space_index"]) ?? 0, a = !p && i === 0 && n[0] === 1 && n[1] === 1 && s[0] === 0 && s[1] === 0 && o === 0;
|
|
398
|
+
return a || t.add("OmniPBR.uvTransform"), a;
|
|
399
|
+
}
|
|
400
|
+
function Ct(e, t) {
|
|
401
|
+
const n = /* @__PURE__ */ new Set([
|
|
402
|
+
"inputs:diffuse_color_constant",
|
|
403
|
+
"inputs:diffuse_texture",
|
|
404
|
+
"inputs:reflection_roughness_constant",
|
|
405
|
+
"inputs:metallic_constant",
|
|
406
|
+
"inputs:opacity_constant",
|
|
407
|
+
"inputs:enable_opacity",
|
|
408
|
+
"inputs:enable_emission",
|
|
409
|
+
"inputs:emissive_color",
|
|
410
|
+
"inputs:emissive_intensity",
|
|
411
|
+
"inputs:texture_scale",
|
|
412
|
+
"inputs:texture_translate",
|
|
413
|
+
"inputs:texture_rotate",
|
|
414
|
+
"inputs:project_uvw",
|
|
415
|
+
"inputs:uv_space_index",
|
|
416
|
+
"info:mdl:sourceAsset"
|
|
417
|
+
]), s = /* @__PURE__ */ new Set(["inputs:opacity_mode", "inputs:opacity_threshold", "inputs:enable_opacity_texture"]);
|
|
418
|
+
for (const o of Object.keys(e.inputs))
|
|
419
|
+
!n.has(o) && !s.has(o) && t.add(`OmniPBR.${o.replace(/^inputs:/, "")}`);
|
|
420
|
+
}
|
|
421
|
+
function Lt(e, t, n) {
|
|
422
|
+
let s = !1;
|
|
423
|
+
const o = Be(t, ["diffuseColor", "baseColor", "base_color", "diffuse_color_constant"]), p = ee(t, ["roughness", "specularRoughness", "specular_roughness", "reflection_roughness_constant"]), i = ee(t, ["metallic", "metalness", "metallicFactor", "metallic_constant"]), a = ee(t, ["opacity", "presence", "opacity_constant"]), u = Xe(t, ["enable_emission"], !0) ? Be(t, ["emissiveColor", "emissionColor", "emission_color", "emissive_color"]) : null;
|
|
424
|
+
for (const c of e)
|
|
425
|
+
Q(c) && (o && (c.color.copy(o), s = !0), p !== null && (c.roughness = Se(p), s = !0), i !== null && (c.metalness = Se(i), s = !0), a !== null && (c.opacity = Se(a), c.transparent = c.opacity < 1, c.depthWrite = c.opacity >= 1, s = !0), u && (c.emissive.copy(u), s = !0), s && (c.needsUpdate = !0));
|
|
426
|
+
return o && n.push("diffuseColor.constant"), p !== null && n.push("roughness.constant"), i !== null && n.push("metalness.constant"), a !== null && n.push("opacity.constant"), u && n.push("emissiveColor.constant"), s;
|
|
427
|
+
}
|
|
428
|
+
function Ft(e, t, n) {
|
|
429
|
+
const s = /* @__PURE__ */ new Set(), o = (p) => {
|
|
430
|
+
if (s.has(p.path)) return;
|
|
431
|
+
s.add(p.path);
|
|
432
|
+
const i = te(e, p);
|
|
433
|
+
if (!i) {
|
|
434
|
+
n.add(p.path);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (!He(i)) {
|
|
438
|
+
n.add(i.id ?? i.path);
|
|
439
|
+
for (const [a, r] of Object.entries(i.inputs)) {
|
|
440
|
+
if (!a.endsWith(".resolvedConnect") && !a.endsWith(".connect")) continue;
|
|
441
|
+
const u = we(r);
|
|
442
|
+
u && o(u);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
for (const [p, i] of Object.entries(t.inputs)) {
|
|
447
|
+
if (!p.endsWith(".resolvedConnect") && !p.endsWith(".connect") || /(?:diffuseColor|baseColor)/i.test(p)) continue;
|
|
448
|
+
const a = we(i);
|
|
449
|
+
a && o(a);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
async function Ue(e, t) {
|
|
453
|
+
const n = ot(t.entryDirectory ? `${t.entryDirectory}/${e}` : e);
|
|
454
|
+
let s = t.files.find(e, t.entryDirectory ?? "") ?? t.files.find(n);
|
|
455
|
+
if (!s)
|
|
456
|
+
try {
|
|
457
|
+
await t.files.ensure(n), s = t.files.find(n) ?? t.files.find(e, t.entryDirectory ?? "");
|
|
458
|
+
} catch (o) {
|
|
459
|
+
const p = o == null ? void 0 : o.code;
|
|
460
|
+
if (o instanceof Error && o.name === "AbortError" || p === "E_ASSET_AUTH") throw o;
|
|
461
|
+
const i = p === "E_ASSET_RESOURCE_NOT_FOUND" || /\((404|410)\)/.test(String(o));
|
|
462
|
+
return { report: { path: e, status: i ? "missing" : "unresolved" }, url: null };
|
|
463
|
+
}
|
|
464
|
+
return s ? Rt.has(Vt(e)) ? { report: { path: e, status: "available" }, url: t.files.objectUrl(s) } : { report: { path: e, status: "unsupported-format" }, url: null } : { report: { path: e, status: "unresolved" }, url: null };
|
|
465
|
+
}
|
|
466
|
+
function qe(e, t, n, s, o, p, i) {
|
|
467
|
+
i === "augmented" && e.approximations.push({
|
|
468
|
+
code: "USD_VISUAL_MATERIAL_AUGMENTED",
|
|
469
|
+
message: `USD 材质 ${t}(${We(n) ?? "renderer-specific shader"})已通过视觉适配层映射资产明确提供的输入:${ae(s).join(", ")}。这是有限范围的材质映射,不保证与原渲染器完全等价;原始 Loader 诊断保留在 visualAdaptation 报告中。`,
|
|
470
|
+
source: "usd-visual"
|
|
471
|
+
});
|
|
472
|
+
for (const a of p)
|
|
473
|
+
a.status === "missing" && e.warnings.push({
|
|
474
|
+
code: "USD_VISUAL_RESOURCE_MISSING",
|
|
475
|
+
message: `USD 材质资源缺失:${a.path}(${t})。未生成替代内容。`,
|
|
476
|
+
source: "usd-visual"
|
|
477
|
+
}), a.status === "unsupported-format" && e.droppedFeatures.push({
|
|
478
|
+
code: "USD_VISUAL_TEXTURE_FORMAT_UNSUPPORTED",
|
|
479
|
+
message: `USD 材质纹理格式无法由浏览器直接消费:${a.path}(${t})。需要离线确定性转码。`,
|
|
480
|
+
source: "usd-visual"
|
|
481
|
+
}), a.status === "decode-failed" && e.warnings.push({
|
|
482
|
+
code: "USD_VISUAL_TEXTURE_DECODE_FAILED",
|
|
483
|
+
message: `USD 纹理解码失败:${a.path}(${t})。保留原材质。`,
|
|
484
|
+
source: "usd-visual"
|
|
485
|
+
}), a.status === "unresolved" && e.warnings.push({
|
|
486
|
+
code: "USD_VISUAL_RESOURCE_UNRESOLVED",
|
|
487
|
+
message: `无法确认 USD 材质资源是否可用:${a.path}(${t})。未生成替代内容。`,
|
|
488
|
+
source: "usd-visual"
|
|
489
|
+
});
|
|
490
|
+
for (const a of o) e.droppedFeatures.push({
|
|
491
|
+
code: "USD_VISUAL_SHADER_NODE_UNSUPPORTED",
|
|
492
|
+
message: `USD 材质节点 ${a} 无法映射为浏览器材质(${t})。未生成替代内容。`,
|
|
493
|
+
source: "usd-visual"
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
function Bt(e) {
|
|
497
|
+
const t = Y(e, ["filename", "file"]), n = de(t);
|
|
498
|
+
return n ? { shader: e, path: n } : null;
|
|
499
|
+
}
|
|
500
|
+
function q(e, t) {
|
|
501
|
+
return we(e.inputs[`inputs:${t}.resolvedConnect`] ?? e.inputs[`inputs:${t}.connect`]);
|
|
502
|
+
}
|
|
503
|
+
function we(e) {
|
|
504
|
+
const t = Array.isArray(e) ? e[0] : e;
|
|
505
|
+
if (typeof t != "string") return null;
|
|
506
|
+
const n = /^(.*?)(?:\.outputs:([^/]+))?$/.exec(t);
|
|
507
|
+
return n ? { path: n[1], outputName: n[2] ?? null } : null;
|
|
508
|
+
}
|
|
509
|
+
function te(e, t) {
|
|
510
|
+
return e.shaders.find((n) => n.path === t.path) ?? null;
|
|
511
|
+
}
|
|
512
|
+
function He(e) {
|
|
513
|
+
return e.id === "PxrTexture";
|
|
514
|
+
}
|
|
515
|
+
function Q(e) {
|
|
516
|
+
return e instanceof ut || e instanceof pt;
|
|
517
|
+
}
|
|
518
|
+
async function Ee(e, t) {
|
|
519
|
+
const n = await new dt().loadAsync(e);
|
|
520
|
+
return n.colorSpace = t, n.flipY = !0, n;
|
|
521
|
+
}
|
|
522
|
+
function Be(e, t) {
|
|
523
|
+
const n = Y(e, t);
|
|
524
|
+
if (!Array.isArray(n) || n.length < 3) return null;
|
|
525
|
+
const s = n.slice(0, 3);
|
|
526
|
+
return s.every((o) => typeof o == "number" && Number.isFinite(o)) ? new yt(s[0], s[1], s[2]) : null;
|
|
527
|
+
}
|
|
528
|
+
function Xe(e, t, n) {
|
|
529
|
+
const s = Y(e, t);
|
|
530
|
+
return typeof s == "boolean" ? s : n;
|
|
531
|
+
}
|
|
532
|
+
function Ve(e, t, n) {
|
|
533
|
+
const s = Y(e, [t]);
|
|
534
|
+
return Array.isArray(s) && s.length >= 2 && s.slice(0, 2).every((o) => typeof o == "number" && Number.isFinite(o)) ? [s[0], s[1]] : n;
|
|
535
|
+
}
|
|
536
|
+
function ee(e, t) {
|
|
537
|
+
const n = Y(e, t), s = typeof n == "number" ? n : Number.NaN;
|
|
538
|
+
return Number.isFinite(s) ? s : null;
|
|
539
|
+
}
|
|
540
|
+
function Y(e, t) {
|
|
541
|
+
for (const n of t) {
|
|
542
|
+
if (q(e, n)) return;
|
|
543
|
+
const s = e.inputs[`inputs:${n}`];
|
|
544
|
+
if (s !== void 0) return s;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function de(e) {
|
|
548
|
+
if (typeof e == "string") return e;
|
|
549
|
+
if (!e || typeof e != "object") return null;
|
|
550
|
+
for (const t of ["path", "resolvedPath", "url"]) {
|
|
551
|
+
const n = e[t];
|
|
552
|
+
if (typeof n == "string" && n) return n;
|
|
553
|
+
}
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
function je(e, t) {
|
|
557
|
+
return e.data.elements.some((n) => n.material === t && n.geometry.displayColor !== null);
|
|
558
|
+
}
|
|
559
|
+
function Vt(e) {
|
|
560
|
+
var t, n;
|
|
561
|
+
return ((n = (t = e.split(/[?#]/, 1)[0]) == null ? void 0 : t.split(".").pop()) == null ? void 0 : n.toLowerCase()) ?? "";
|
|
562
|
+
}
|
|
563
|
+
function Se(e) {
|
|
564
|
+
return Math.min(1, Math.max(0, e));
|
|
565
|
+
}
|
|
566
|
+
function jt(e) {
|
|
567
|
+
return Array.isArray(e) ? e.filter(Je) : [];
|
|
568
|
+
}
|
|
569
|
+
function xe(e) {
|
|
570
|
+
return typeof e == "string" && e ? e : null;
|
|
571
|
+
}
|
|
572
|
+
function Je(e) {
|
|
573
|
+
return typeof e == "string" && e.length > 0;
|
|
574
|
+
}
|
|
575
|
+
function ae(e) {
|
|
576
|
+
return [...new Set(e)];
|
|
577
|
+
}
|
|
578
|
+
async function dn(e, t, n) {
|
|
579
|
+
var N;
|
|
580
|
+
Jt();
|
|
581
|
+
const s = n.hasLocalFiles(), o = e.entryPath ?? e.filename ?? "asset.usd", p = s ? o : await Qt(e, o), i = s ? n.getBlob(o) : await Zt(e), a = o.split("/").pop() || "asset.usd", r = o.split("/").slice(0, -1).join("/"), u = Dt(t.options.openUsdBaseUrl), c = e.hasResourceResolver && !s ? await new bt().load(u) : void 0;
|
|
582
|
+
c && await nn(c, e, i, a, n);
|
|
583
|
+
const h = new Et({
|
|
584
|
+
convertZUp: !1,
|
|
585
|
+
loadLights: !1,
|
|
586
|
+
preserveStage: !0,
|
|
587
|
+
...c ? { pxr: c } : u ? { pxrOptions: u } : {}
|
|
588
|
+
});
|
|
589
|
+
let l = null, y = null, m = null, S = null;
|
|
590
|
+
try {
|
|
591
|
+
if (l = await h.parseAsync(i, {
|
|
592
|
+
sourcePath: p,
|
|
593
|
+
fileName: a,
|
|
594
|
+
files: s || e.hasResourceResolver ? n.asSourceRecord(r) : void 0,
|
|
595
|
+
// A local package is the complete browser-visible file set. Resolving it
|
|
596
|
+
// through fetch would both hide missing uploads and accept SPA fallback
|
|
597
|
+
// responses as binary USD layers.
|
|
598
|
+
autoResolveAssets: !s && !e.hasResourceResolver,
|
|
599
|
+
// USD layer references are authoritative; disable directory guessing because SPA fallback pages may be returned as HTTP 200.
|
|
600
|
+
assetSearchRoots: [],
|
|
601
|
+
textureResolver: s || e.hasResourceResolver ? (_) => {
|
|
602
|
+
for (const L of [_.resolvedPath, _.path, _.url])
|
|
603
|
+
if (L) {
|
|
604
|
+
const D = n.objectUrlIfPresent(L, r);
|
|
605
|
+
if (D) return D;
|
|
606
|
+
}
|
|
607
|
+
return null;
|
|
608
|
+
} : void 0,
|
|
609
|
+
preserveStage: !0
|
|
610
|
+
}), t.signal.aborted) throw _e();
|
|
611
|
+
const U = Xt(l);
|
|
612
|
+
l.scene.scale.multiplyScalar(U.metersPerUnit), l.data.stage.upAxis.toUpperCase() === "Y" && l.scene.quaternion.setFromAxisAngle(new I(1, 0, 0), Math.PI / 2), l.scene.updateMatrixWorld(!0);
|
|
613
|
+
const E = l.data.physics.rigidBodies.filter((_) => _.enabled), b = Ze(l, E.map((_) => _.path)), w = it(), P = await Tt(l, {
|
|
614
|
+
files: n,
|
|
615
|
+
entryDirectory: r,
|
|
616
|
+
sourcePath: p,
|
|
617
|
+
isLocalPackage: s,
|
|
618
|
+
diagnostics: w
|
|
619
|
+
});
|
|
620
|
+
if (t.signal.aborted) throw _e();
|
|
621
|
+
const x = Gt(w);
|
|
622
|
+
E.some((_) => _.startsAsleep === !0) && w.droppedFeatures.push({ code: "E_USD_STARTS_ASLEEP", message: "USD startsAsleep 无法在 MuJoCo 初始化阶段保证完全等价,已按正常初始状态加载。", source: "usd-physics" });
|
|
623
|
+
const f = at({
|
|
624
|
+
id: p,
|
|
625
|
+
name: p.split("/").pop() ?? p,
|
|
626
|
+
source: { format: "usd", uri: p },
|
|
627
|
+
links: E.map((_) => ({ id: _.path, name: _.name, visuals: [], collisions: [] })),
|
|
628
|
+
joints: b.flatMap((_) => _.body0 && _.body1 ? [{
|
|
629
|
+
id: _.path,
|
|
630
|
+
type: _.jointType,
|
|
631
|
+
parent: _.body0,
|
|
632
|
+
child: _.body1,
|
|
633
|
+
origin: { position: _.localPos1.map((L) => L * U.metersPerUnit), rotationRpy: [0, 0, 0] },
|
|
634
|
+
axis: Ke(_.axis).applyQuaternion(Z(_.localRot1 ?? [1, 0, 0, 0])).toArray(),
|
|
635
|
+
...Number.isFinite(_.lowerLimit) && Number.isFinite(_.upperLimit) ? { limits: {
|
|
636
|
+
lower: _.lowerLimit * (_.jointType === "revolute" ? Math.PI / 180 : U.metersPerUnit),
|
|
637
|
+
upper: _.upperLimit * (_.jointType === "revolute" ? Math.PI / 180 : U.metersPerUnit)
|
|
638
|
+
} } : {}
|
|
639
|
+
}] : []),
|
|
640
|
+
diagnostics: w,
|
|
641
|
+
extension: { rigidBodyCount: E.length, jointCount: b.length, visualAdaptation: P }
|
|
642
|
+
});
|
|
643
|
+
if (E.length === 0) {
|
|
644
|
+
const _ = Ge(l, w), L = l.scene, D = l;
|
|
645
|
+
return m = { root: L, sync() {
|
|
646
|
+
}, dispose() {
|
|
647
|
+
D.dispose();
|
|
648
|
+
} }, l = null, ge(f, m, !1, () => {
|
|
649
|
+
}, void 0, void 0, _, x);
|
|
650
|
+
}
|
|
651
|
+
let v;
|
|
652
|
+
try {
|
|
653
|
+
v = Wt(l, E.map((L) => L.path), U, b), (N = v.massOverrides) != null && N.length && w.approximations.push({ code: "USD_INFERRED_INERTIA", message: "保留显式总质量;惯量按碰撞几何的密度分布推导并同比缩放,重叠体积会重复计入。", source: "usd-physics" });
|
|
654
|
+
const { MujocoRuntime: _ } = await import("./mujoco-runtime-C29PXDOl.js");
|
|
655
|
+
y = new _(), await y.initialize(v, t.options.mujocoBaseUrl), t.signal.throwIfAborted();
|
|
656
|
+
} catch (_) {
|
|
657
|
+
const L = ct(_, t.signal, "usd-physics");
|
|
658
|
+
y == null || y.dispose(), y = null, w.droppedFeatures.push(L);
|
|
659
|
+
const D = Ge(l, w), k = l.scene, $ = l;
|
|
660
|
+
return m = { root: k, sync() {
|
|
661
|
+
}, dispose() {
|
|
662
|
+
$.dispose();
|
|
663
|
+
} }, l = null, ge(f, m, !1, () => {
|
|
664
|
+
}, void 0, L, D, x);
|
|
665
|
+
}
|
|
666
|
+
const O = S = Yt(l, E.map((_) => _.path));
|
|
667
|
+
if (t.signal.aborted) throw _e();
|
|
668
|
+
m = new Te(y, O);
|
|
669
|
+
const d = Qe(l, E.map((_) => _.path), w), g = d ? new Te(y, d) : void 0;
|
|
670
|
+
S = null;
|
|
671
|
+
const A = l, C = y, M = m;
|
|
672
|
+
return l = null, y = null, m = null, ge(f, M, !0, () => {
|
|
673
|
+
C.dispose(), A.dispose();
|
|
674
|
+
}, C, void 0, g, x);
|
|
675
|
+
} catch (U) {
|
|
676
|
+
throw S && Ye(S.root), m == null || m.dispose(), y == null || y.dispose(), l == null || l.dispose(), U;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function Gt(e) {
|
|
680
|
+
const t = [
|
|
681
|
+
"USD_VISUAL_RESOURCE_MISSING",
|
|
682
|
+
"USD_VISUAL_TEXTURE_FORMAT_UNSUPPORTED",
|
|
683
|
+
"USD_VISUAL_RESOURCE_UNRESOLVED",
|
|
684
|
+
"USD_VISUAL_TEXTURE_DECODE_FAILED",
|
|
685
|
+
"USD_VISUAL_SHADER_NODE_UNSUPPORTED",
|
|
686
|
+
"USD_VISUAL_LOADER_DIAGNOSTIC",
|
|
687
|
+
"USD_VISUAL_TOPOLOGY_UNSUPPORTED"
|
|
688
|
+
], n = [...e.warnings, ...e.droppedFeatures, ...e.approximations];
|
|
689
|
+
for (const s of t) {
|
|
690
|
+
const o = n.find((p) => p.code === s);
|
|
691
|
+
if (o) return o;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
function ge(e, t, n, s, o, p, i, a) {
|
|
695
|
+
let r = !1;
|
|
696
|
+
return {
|
|
697
|
+
asset: e,
|
|
698
|
+
binding: t,
|
|
699
|
+
hasPhysics: n,
|
|
700
|
+
runtime: o,
|
|
701
|
+
fallback: p,
|
|
702
|
+
visualWarning: a,
|
|
703
|
+
collision: i,
|
|
704
|
+
step(u) {
|
|
705
|
+
if (!o) return !1;
|
|
706
|
+
const c = o.step(u);
|
|
707
|
+
return c && t.sync(), c;
|
|
708
|
+
},
|
|
709
|
+
reset() {
|
|
710
|
+
o == null || o.reset(), t.sync();
|
|
711
|
+
},
|
|
712
|
+
dispose() {
|
|
713
|
+
r || (r = !0, i == null || i.dispose(), t.dispose(), s());
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
const kt = /* @__PURE__ */ new Set([
|
|
718
|
+
"E_USD_PHYSICS_UNSUPPORTED",
|
|
719
|
+
"E_USD_UNBAKED_BODY_SCALE",
|
|
720
|
+
"E_USD_INVALID_JOINT_REFERENCE",
|
|
721
|
+
"E_USD_UNSUPPORTED_JOINT",
|
|
722
|
+
"E_USD_MULTIPLE_PARENTS",
|
|
723
|
+
"E_USD_JOINT_CYCLE",
|
|
724
|
+
"E_USD_UNSUPPORTED_DRIVE",
|
|
725
|
+
"E_USD_INVALID_MASS",
|
|
726
|
+
"E_USD_PARTIAL_INERTIA",
|
|
727
|
+
"E_USD_MISSING_COLLISION_GEOMETRY",
|
|
728
|
+
"E_USD_UNREACHABLE_BODIES",
|
|
729
|
+
"E_USD_MULTIPLE_PHYSICS_SCENES",
|
|
730
|
+
"E_USD_NONUNIFORM_RADIAL_SCALE",
|
|
731
|
+
"E_USD_UNSUPPORTED_GEOMETRY",
|
|
732
|
+
"E_USD_CONSTRAINED_INITIAL_VELOCITY",
|
|
733
|
+
"E_USD_UNSUPPORTED_APPROXIMATION"
|
|
734
|
+
]);
|
|
735
|
+
function fn(e) {
|
|
736
|
+
const t = zt(e);
|
|
737
|
+
return t !== null && kt.has(t);
|
|
738
|
+
}
|
|
739
|
+
function zt(e) {
|
|
740
|
+
if (!e || typeof e != "object" || !("code" in e)) return null;
|
|
741
|
+
const t = e.code;
|
|
742
|
+
return typeof t == "string" ? t : null;
|
|
743
|
+
}
|
|
744
|
+
function Yt(e, t) {
|
|
745
|
+
e.scene.updateMatrixWorld(!0);
|
|
746
|
+
const n = new le();
|
|
747
|
+
n.name = "USD simulation";
|
|
748
|
+
const s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
|
|
749
|
+
for (const i of t) {
|
|
750
|
+
const a = e.index.objectsByPath.get(i);
|
|
751
|
+
if (!a) throw R(`USD rigid body node is missing: ${i}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
752
|
+
const r = new le();
|
|
753
|
+
r.name = i, n.add(r), s.set(i, r);
|
|
754
|
+
const u = new I(), c = new V();
|
|
755
|
+
a.matrixWorld.decompose(u, c, new I()), o.set(i, new H().compose(u, c, new I(1, 1, 1)));
|
|
756
|
+
}
|
|
757
|
+
const p = [];
|
|
758
|
+
e.scene.traverse((i) => {
|
|
759
|
+
var c;
|
|
760
|
+
if (!(i instanceof ne)) return;
|
|
761
|
+
let a = i, r, u = !0;
|
|
762
|
+
for (; a; ) {
|
|
763
|
+
u && (u = a.visible);
|
|
764
|
+
const h = (c = a.userData.usd) == null ? void 0 : c.path;
|
|
765
|
+
!r && h && s.has(h) && (r = h), a = a.parent;
|
|
766
|
+
}
|
|
767
|
+
u && p.push([i, r]);
|
|
768
|
+
});
|
|
769
|
+
for (const [i, a] of p) {
|
|
770
|
+
const r = i.clone(!1);
|
|
771
|
+
r.geometry = i.geometry.clone(), r.material = Array.isArray(i.material) ? i.material.map((u) => u.clone()) : i.material.clone(), r.matrix.copy(a ? o.get(a) : new H()).invert().multiply(i.matrixWorld), r.matrix.decompose(r.position, r.quaternion, r.scale), (a ? s.get(a) : n).add(r);
|
|
772
|
+
}
|
|
773
|
+
return { root: n, bindings: s, expectedLinkCount: s.size };
|
|
774
|
+
}
|
|
775
|
+
function Qe(e, t, n) {
|
|
776
|
+
e.scene.updateMatrixWorld(!0);
|
|
777
|
+
const s = new le();
|
|
778
|
+
s.name = "USD authored collisions";
|
|
779
|
+
const o = rt(), p = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
|
|
780
|
+
for (const r of t) {
|
|
781
|
+
const u = e.index.objectsByPath.get(r);
|
|
782
|
+
if (!u) continue;
|
|
783
|
+
const c = new I(), h = new V();
|
|
784
|
+
u.matrixWorld.decompose(c, h, new I()), i.set(r, new H().compose(c, h, new I(1, 1, 1)));
|
|
785
|
+
const l = new le();
|
|
786
|
+
l.name = r, l.position.copy(c), l.quaternion.copy(h), p.set(r, l), s.add(l);
|
|
787
|
+
}
|
|
788
|
+
let a = 0;
|
|
789
|
+
for (const r of e.data.physics.colliders) {
|
|
790
|
+
if (!r.enabled) continue;
|
|
791
|
+
const u = e.index.objectsByPath.get(r.path);
|
|
792
|
+
if (!u) continue;
|
|
793
|
+
const c = r.bodyPath && p.has(r.bodyPath) ? r.bodyPath : null, h = c ? p.get(c) : s, l = c ? i.get(c) : new H(), y = [];
|
|
794
|
+
if (u.traverse((U) => {
|
|
795
|
+
U instanceof ne && y.push(U);
|
|
796
|
+
}), y.length === 0) continue;
|
|
797
|
+
const m = String(r.typeName ?? u.type).toLowerCase(), S = m.includes("mesh") ? r.approximation ?? "none" : null;
|
|
798
|
+
if (S === "convexDecomposition" || S === "meshSimplification") {
|
|
799
|
+
n == null || n.droppedFeatures.push({
|
|
800
|
+
code: "E_USD_COLLISION_DEBUG_APPROXIMATION_UNAVAILABLE",
|
|
801
|
+
message: `USD collider ${r.path} 使用 ${S},但资产未提供可唯一还原的最终代理几何。`,
|
|
802
|
+
source: "usd-collision-debug"
|
|
803
|
+
});
|
|
804
|
+
continue;
|
|
805
|
+
}
|
|
806
|
+
if (m.includes("mesh") && S !== "none") {
|
|
807
|
+
const U = [], E = l.clone().invert();
|
|
808
|
+
for (const b of y) {
|
|
809
|
+
const w = E.clone().multiply(b.matrixWorld), P = b.geometry.getAttribute("position");
|
|
810
|
+
for (let x = 0; x < P.count; x += 1) U.push(new I().fromBufferAttribute(P, x).applyMatrix4(w));
|
|
811
|
+
}
|
|
812
|
+
if (U.length >= 4 && S === "convexHull") {
|
|
813
|
+
const b = new Ut(U), w = ie(b, o, "mesh");
|
|
814
|
+
b.dispose(), w.name = `Collision:${r.path}`, w.userData.usdColliderPath = r.path, h.add(w), a += 1;
|
|
815
|
+
} else if (U.length > 0 && S === "boundingSphere") {
|
|
816
|
+
const w = new ue().setFromPoints(U).getBoundingSphere(new St()), P = new gt(w.radius, 24, 16);
|
|
817
|
+
P.translate(w.center.x, w.center.y, w.center.z);
|
|
818
|
+
const x = ie(P, o, "feature");
|
|
819
|
+
P.dispose(), x.name = `Collision:${r.path}`, x.userData.usdColliderPath = r.path, h.add(x), a += 1;
|
|
820
|
+
} else if (U.length > 0 && S === "boundingCube") {
|
|
821
|
+
const b = new ue().setFromPoints(U), w = b.getSize(new I()), P = b.getCenter(new I()), x = new _t(w.x, w.y, w.z);
|
|
822
|
+
x.translate(P.x, P.y, P.z);
|
|
823
|
+
const f = ie(x, o, "feature");
|
|
824
|
+
x.dispose(), f.name = `Collision:${r.path}`, f.userData.usdColliderPath = r.path, h.add(f), a += 1;
|
|
825
|
+
} else ["convexHull", "boundingSphere", "boundingCube"].includes(String(S)) || n == null || n.droppedFeatures.push({
|
|
826
|
+
code: "E_USD_COLLISION_DEBUG_APPROXIMATION_UNAVAILABLE",
|
|
827
|
+
message: `USD collider ${r.path} 使用未知 approximation=${S}。`,
|
|
828
|
+
source: "usd-collision-debug"
|
|
829
|
+
});
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
const N = m.includes("mesh") ? "mesh" : "feature";
|
|
833
|
+
for (const U of y) {
|
|
834
|
+
const E = ie(U.geometry, o, N);
|
|
835
|
+
E.name = `Collision:${r.path}`, E.matrixAutoUpdate = !1, E.matrix.copy(l).invert().multiply(U.matrixWorld), E.userData.usdColliderPath = r.path, h.add(E), a += 1;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (a === 0) {
|
|
839
|
+
o.dispose();
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
return { root: s, bindings: p, expectedLinkCount: p.size };
|
|
843
|
+
}
|
|
844
|
+
function Ge(e, t) {
|
|
845
|
+
const n = Qe(e, [], t);
|
|
846
|
+
if (n)
|
|
847
|
+
return n.root.visible = !1, { root: n.root, sync() {
|
|
848
|
+
}, dispose() {
|
|
849
|
+
n.root.removeFromParent(), Ye(n.root);
|
|
850
|
+
} };
|
|
851
|
+
}
|
|
852
|
+
function Ze(e, t) {
|
|
853
|
+
e.scene.updateMatrixWorld(!0);
|
|
854
|
+
const n = new Set(t);
|
|
855
|
+
return e.data.joints.filter((s) => s.enabled).map((s) => {
|
|
856
|
+
const o = { ...s };
|
|
857
|
+
for (const p of [0, 1]) {
|
|
858
|
+
const i = p === 0 ? "body0" : "body1", a = p === 0 ? "localPos0" : "localPos1", r = p === 0 ? "localRot0" : "localRot1", u = s[i];
|
|
859
|
+
if (!u) continue;
|
|
860
|
+
let c = u;
|
|
861
|
+
for (; c && !e.index.rigidBodiesByPath.has(c); )
|
|
862
|
+
c = c.slice(0, c.lastIndexOf("/"));
|
|
863
|
+
if (!c || !n.has(c))
|
|
864
|
+
throw R(`USD joint references an unknown or disabled rigid body: ${s.path} (${u})`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
865
|
+
if (c === u) continue;
|
|
866
|
+
const h = e.index.objectsByPath.get(u), l = e.index.objectsByPath.get(c);
|
|
867
|
+
if (!h || !l)
|
|
868
|
+
throw R(`USD joint target node is missing: ${s.path} (${u})`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
869
|
+
const y = l.matrixWorld.clone().invert().multiply(h.matrixWorld), m = new I(), S = new V(), N = new I();
|
|
870
|
+
y.decompose(m, S, N);
|
|
871
|
+
const U = new H().compose(m, S, new I(1, 1, 1));
|
|
872
|
+
if (y.elements.some((b, w) => Math.abs(b - U.elements[w]) > 1e-5))
|
|
873
|
+
throw R(`USD joint target has unsupported scale or shear: ${s.path} (${u})`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
874
|
+
o[i] = c, o[a] = new I(...s[a]).applyMatrix4(y).toArray();
|
|
875
|
+
const E = S.multiply(Z(s[r] ?? [1, 0, 0, 0])).normalize();
|
|
876
|
+
o[r] = [E.w, E.x, E.y, E.z];
|
|
877
|
+
}
|
|
878
|
+
return o;
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
function Wt(e, t, n, s = Ze(e, t)) {
|
|
882
|
+
e.scene.updateMatrixWorld(!0);
|
|
883
|
+
const o = [], p = [], i = [], a = [], r = [], u = [], c = [], { metersPerUnit: h, kilogramsPerUnit: l } = n, y = new Map(t.map((d) => {
|
|
884
|
+
const g = e.index.rigidBodiesByPath.get(d);
|
|
885
|
+
if (!g) throw R(`USD rigid body metadata is missing: ${d}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
886
|
+
return [d, g];
|
|
887
|
+
})), m = /* @__PURE__ */ new Map();
|
|
888
|
+
for (const d of y.keys()) {
|
|
889
|
+
const g = e.index.objectsByPath.get(d);
|
|
890
|
+
if (!g) throw R(`USD rigid body node is missing: ${d}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
891
|
+
const A = new I(), C = new V(), M = new I();
|
|
892
|
+
if (g.matrixWorld.decompose(A, C, M), M.clone().divideScalar(h).toArray().some((L) => Math.abs(Math.abs(L) - 1) > 1e-5))
|
|
893
|
+
throw R(`USD rigid body has unbaked scale: ${d}`, "E_USD_UNBAKED_BODY_SCALE");
|
|
894
|
+
m.set(d, new H().compose(A, C, new I(1, 1, 1)));
|
|
895
|
+
}
|
|
896
|
+
const S = /* @__PURE__ */ new Map();
|
|
897
|
+
for (const d of s) {
|
|
898
|
+
if (!d.body1 || !y.has(d.body1) || d.body0 && !y.has(d.body0))
|
|
899
|
+
throw R(`USD joint references an unknown rigid body: ${d.path}`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
900
|
+
if (!["fixed", "revolute", "prismatic"].includes(d.jointType))
|
|
901
|
+
throw R(`Unsupported USD joint type ${d.jointType}: ${d.path}`, "E_USD_UNSUPPORTED_JOINT");
|
|
902
|
+
if (S.has(d.body1)) throw R(`USD rigid body has multiple parent joints: ${d.body1}`, "E_USD_MULTIPLE_PARENTS");
|
|
903
|
+
S.set(d.body1, d), d.body0 && d.collisionEnabled !== !0 && i.push(`<exclude body1="${J(d.body0)}" body2="${J(d.body1)}"/>`);
|
|
904
|
+
}
|
|
905
|
+
let N = 0;
|
|
906
|
+
const U = /* @__PURE__ */ new Set(), E = (d, g = new H()) => {
|
|
907
|
+
var Ae, Pe, Ie, Re, Ne;
|
|
908
|
+
if (U.has(d)) throw R(`USD joint graph contains a cycle at ${d}`, "E_USD_JOINT_CYCLE");
|
|
909
|
+
U.add(d);
|
|
910
|
+
const A = y.get(d), C = m.get(d), M = g.clone().invert().multiply(C), _ = new I(), L = new V();
|
|
911
|
+
M.decompose(_, L, new I());
|
|
912
|
+
const D = S.get(d), k = [`<body name="${J(d)}" pos="${B(_.toArray())}" quat="${K(L)}">`];
|
|
913
|
+
if (!D && !A.kinematicEnabled && k.push("<freejoint/>"), D && [...A.velocity ?? [], ...A.angularVelocity ?? []].some((T) => T !== 0))
|
|
914
|
+
throw R(`Constrained USD initial velocity cannot be projected reliably: ${d}`, "E_USD_CONSTRAINED_INITIAL_VELOCITY");
|
|
915
|
+
if (!D && !A.kinematicEnabled) {
|
|
916
|
+
const T = new I(...A.velocity ?? [0, 0, 0]).multiplyScalar(h).applyQuaternion(e.scene.quaternion), F = new I(...A.angularVelocity ?? [0, 0, 0]).multiplyScalar(Math.PI / 180).applyQuaternion(e.scene.quaternion).applyQuaternion(new V().setFromRotationMatrix(C).invert());
|
|
917
|
+
c.push({ body: d, velocity: [...T.toArray(), ...F.toArray()] });
|
|
918
|
+
}
|
|
919
|
+
if (D && D.jointType !== "fixed") {
|
|
920
|
+
const T = D.jointType === "revolute" ? "hinge" : "slide", F = Ke(D.axis).applyQuaternion(Z(D.localRot1 ?? [1, 0, 0, 0])), j = T === "hinge" ? Math.PI / 180 : h, fe = new V().setFromRotationMatrix(g), se = new V().setFromRotationMatrix(C), X = fe.clone().multiply(Z(D.localRot0 ?? [1, 0, 0, 0])).invert().multiply(se).multiply(Z(D.localRot1 ?? [1, 0, 0, 0]));
|
|
921
|
+
let z = 0;
|
|
922
|
+
if (T === "hinge") {
|
|
923
|
+
const W = D.axis === "Y" ? X.y : D.axis === "Z" ? X.z : X.x;
|
|
924
|
+
z = 2 * Math.atan2(W, X.w), z = Math.atan2(Math.sin(z), Math.cos(z));
|
|
925
|
+
} else {
|
|
926
|
+
const W = new I(...D.localPos0).multiplyScalar(h).applyMatrix4(g);
|
|
927
|
+
z = new I(...D.localPos1).multiplyScalar(h).applyMatrix4(C).sub(W).dot(F.clone().applyQuaternion(se));
|
|
928
|
+
}
|
|
929
|
+
const $e = Number.isFinite(D.lowerLimit) && Number.isFinite(D.upperLimit) && Math.abs(D.lowerLimit) < 1e20 && Math.abs(D.upperLimit) < 1e20, nt = $e && D.lowerLimit < D.upperLimit, oe = l * (T === "slide" ? h : h * h), he = ce(e, D.path, `physxJointAxis:${T === "slide" ? "linear" : "angular"}:dynamicFrictionEffort`), st = typeof he == "number" && Number.isFinite(he) ? he * oe : 0;
|
|
930
|
+
k.push(`<joint name="${J(D.path)}" type="${T}" pos="${B(D.localPos1.map((W) => W * h))}" axis="${B(F.toArray())}" ref="${z}" ${nt ? `range="${D.lowerLimit * j} ${D.upperLimit * j}"` : 'limited="false"'} frictionloss="${st}" armature="0.00001"/>`), $e && D.lowerLimit === D.upperLimit && p.push(`<joint joint1="${J(D.path)}" polycoef="${D.lowerLimit * j - z} 0 0 0 0"/>`);
|
|
931
|
+
const G = D.drive;
|
|
932
|
+
if (G && ((G.stiffness ?? 0) !== 0 || (G.damping ?? 0) !== 0)) {
|
|
933
|
+
if (G.type === "acceleration") throw R(`Unsupported USD acceleration drive: ${D.path}`, "E_USD_UNSUPPORTED_DRIVE");
|
|
934
|
+
const W = (G.stiffness ?? 0) * oe / j, me = (G.damping ?? 0) * oe / j, re = G.maxForce == null ? null : G.maxForce * oe;
|
|
935
|
+
r.push(`<general joint="${J(D.path)}" gainprm="1" biastype="affine" biasprm="0 ${-W} ${-me}" ${re != null && Number.isFinite(re) ? `forcelimited="true" forcerange="${-re} ${re}"` : ""}/>`), u.push(W * (G.targetPosition ?? 0) * j + me * (G.targetVelocity ?? 0) * j);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
const $ = A.mass;
|
|
939
|
+
if (($ == null ? void 0 : $.mass) != null && (!Number.isFinite($.mass) || $.mass < 0)) throw R(`USD rigid body mass must be finite and non-negative: ${d}`, "E_USD_INVALID_MASS");
|
|
940
|
+
if (($ == null ? void 0 : $.mass) != null && $.mass > 0 && ((Ae = $.centerOfMass) != null && Ae.every(Number.isFinite)) && ((Pe = $.diagonalInertia) != null && Pe.every((T) => Number.isFinite(T) && T > 0)) && ((Ie = $.principalAxes) != null && Ie.every(Number.isFinite)))
|
|
941
|
+
k.push(`<inertial mass="${$.mass * l}" pos="${B($.centerOfMass.map((T) => T * h))}" quat="${K(Z($.principalAxes))}" diaginertia="${B($.diagonalInertia.map((T) => T * l * h * h))}"/>`);
|
|
942
|
+
else {
|
|
943
|
+
if ((Re = $ == null ? void 0 : $.diagonalInertia) != null && Re.some((T) => T > 0))
|
|
944
|
+
throw R(`USD rigid body has incomplete explicit inertia: ${d}`, "E_USD_PARTIAL_INERTIA");
|
|
945
|
+
if (($ == null ? void 0 : $.mass) != null && $.mass > 0) {
|
|
946
|
+
if ((Ne = $.centerOfMass) != null && Ne.every(Number.isFinite) && $.centerOfMass.some((T) => T !== 0)) throw R(`Custom center of mass requires explicit inertia: ${d}`, "E_USD_PARTIAL_INERTIA");
|
|
947
|
+
a.push({ body: d, mass: $.mass * l });
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
const ve = e.data.physics.colliders.filter((T) => T.enabled && T.bodyPath === d);
|
|
951
|
+
if (!ve.length) throw R(`USD rigid body has no authored collision geometry: ${d}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
952
|
+
for (const T of ve) {
|
|
953
|
+
const F = e.data.physics.materials.find((z) => z.path === T.material), j = ($ == null ? void 0 : $.density) != null && $.density > 0 ? $.density : F == null ? void 0 : F.density, fe = j != null && j > 0 ? j * l / h ** 3 : 1e3, se = (F == null ? void 0 : F.dynamicFriction) ?? 0.4, X = `density="${fe}" group="3" contype="1" conaffinity="1" friction="${se} 0.01 0.0002"`;
|
|
954
|
+
k.push(ke(e, T, d, C, N++, o, X));
|
|
955
|
+
}
|
|
956
|
+
for (const [T, F] of S) F.body0 === d && k.push(E(T, C));
|
|
957
|
+
return k.push("</body>"), k.join("");
|
|
958
|
+
}, b = e.data.physics.colliders.filter((d) => d.enabled && !d.bodyPath), w = b.map((d) => {
|
|
959
|
+
const g = e.data.physics.materials.find((_) => _.path === d.material), A = (g == null ? void 0 : g.density) != null && g.density > 0 ? g.density * l / h ** 3 : 1e3, C = (g == null ? void 0 : g.dynamicFriction) ?? 0.4, M = `density="${A}" group="3" contype="1" conaffinity="1" friction="${C} 0.01 0.0002"`;
|
|
960
|
+
return ke(e, d, "", new H(), N++, o, M);
|
|
961
|
+
}).join(""), P = qt(e, t, b) ? `<geom name="__viewer_default_ground__" type="plane" pos="0 0 ${Ht(e, t)}" size="1 1 0.1" group="3" contype="1" conaffinity="1" friction="0.8 0.01 0.0002"/>` : "", f = [...y.keys()].filter((d) => {
|
|
962
|
+
var g;
|
|
963
|
+
return !((g = S.get(d)) != null && g.body0);
|
|
964
|
+
}).map((d) => E(d)).join("");
|
|
965
|
+
if (U.size !== y.size) throw R("USD joint graph contains unreachable bodies or a cycle.", "E_USD_UNREACHABLE_BODIES");
|
|
966
|
+
if (e.data.physics.scenes.length > 1) throw R("Multiple USD PhysicsScene prims are not supported.", "E_USD_MULTIPLE_PHYSICS_SCENES");
|
|
967
|
+
const v = e.data.physics.scenes[0], O = v != null && v.gravityDirection && v.gravityMagnitude != null && v.gravityMagnitude >= 0 ? new I(...v.gravityDirection).normalize().multiplyScalar(v.gravityMagnitude * h).applyQuaternion(e.scene.quaternion) : new I(0, 0, -9.81);
|
|
968
|
+
return {
|
|
969
|
+
format: "mjcf",
|
|
970
|
+
files: /* @__PURE__ */ new Map(),
|
|
971
|
+
initialControls: u,
|
|
972
|
+
initialVelocities: c,
|
|
973
|
+
massOverrides: a,
|
|
974
|
+
xml: `<mujoco><compiler angle="radian" autolimits="true"/><option integrator="implicitfast" gravity="${B(O.toArray())}"><flag filterparent="disable"/></option><default><geom margin="0.0015" solref="0.004 1"/></default>${o.length ? `<asset>${o.join("")}</asset>` : ""}<worldbody>${P}${w}${f}</worldbody>${i.length ? `<contact>${i.join("")}</contact>` : ""}${p.length ? `<equality>${p.join("")}</equality>` : ""}${r.length ? `<actuator>${r.join("")}</actuator>` : ""}</mujoco>`
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
function qt(e, t, n = e.data.physics.colliders.filter((s) => s.enabled && !s.bodyPath)) {
|
|
978
|
+
if (!t.length || n.some((a) => a.typeName.toLowerCase().includes("plane"))) return !1;
|
|
979
|
+
const s = be(e, e.data.physics.colliders.filter(
|
|
980
|
+
(a) => a.enabled && a.bodyPath && t.includes(a.bodyPath)
|
|
981
|
+
));
|
|
982
|
+
if (s.isEmpty()) return n.length === 0;
|
|
983
|
+
const o = Math.max(s.max.x - s.min.x, 1e-6), p = Math.max(s.max.y - s.min.y, 1e-6), i = Math.max(o, p, s.max.z - s.min.z) * 0.05;
|
|
984
|
+
return !n.some((a) => {
|
|
985
|
+
const r = be(e, [a]);
|
|
986
|
+
if (r.isEmpty()) return !1;
|
|
987
|
+
const u = r.max.x >= s.min.x && r.min.x <= s.max.x, c = r.max.y >= s.min.y && r.min.y <= s.max.y;
|
|
988
|
+
return u && c && r.max.z <= s.min.z + i;
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
function Ht(e, t) {
|
|
992
|
+
const n = be(e, e.data.physics.colliders.filter(
|
|
993
|
+
(o) => o.enabled && o.bodyPath && t.includes(o.bodyPath)
|
|
994
|
+
)), s = n.isEmpty() ? 0 : n.min.z;
|
|
995
|
+
return Number.isFinite(s) ? String(s) : "0";
|
|
996
|
+
}
|
|
997
|
+
function be(e, t) {
|
|
998
|
+
const n = new ue();
|
|
999
|
+
for (const s of t) {
|
|
1000
|
+
const o = e.index.objectsByPath.get(s.path);
|
|
1001
|
+
o && n.union(new ue().setFromObject(o));
|
|
1002
|
+
}
|
|
1003
|
+
return n;
|
|
1004
|
+
}
|
|
1005
|
+
function Ke(e) {
|
|
1006
|
+
return e === "Y" ? new I(0, 1, 0) : e === "Z" ? new I(0, 0, 1) : new I(1, 0, 0);
|
|
1007
|
+
}
|
|
1008
|
+
function ke(e, t, n, s, o, p, i) {
|
|
1009
|
+
const a = e.index.objectsByPath.get(t.path);
|
|
1010
|
+
if (!a) throw R(`USD collider node is missing: ${t.path}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
1011
|
+
const r = s.clone().invert().multiply(a.matrixWorld), u = new I(), c = new V(), h = new I();
|
|
1012
|
+
r.decompose(u, c, h);
|
|
1013
|
+
const l = t.typeName.replace(/^UsdGeom/, "").toLowerCase(), y = (m, S) => {
|
|
1014
|
+
const N = ce(e, t.path, m);
|
|
1015
|
+
return typeof N == "number" ? N : S;
|
|
1016
|
+
};
|
|
1017
|
+
if (l.includes("cube")) {
|
|
1018
|
+
const m = Math.abs(y("size", 2)) / 2;
|
|
1019
|
+
return `<geom type="box" pos="${B(u.toArray())}" quat="${K(c)}" size="${B([Math.abs(h.x) * m, Math.abs(h.y) * m, Math.abs(h.z) * m])}" ${i}/>`;
|
|
1020
|
+
}
|
|
1021
|
+
if (l.includes("plane")) {
|
|
1022
|
+
if (n) throw R(`USD plane collider requires a static world owner: ${t.path}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
1023
|
+
const m = String(ce(e, t.path, "axis") ?? "Z").toUpperCase(), N = { X: new I(1, 0, 0), Y: new I(0, 1, 0), Z: new I(0, 0, 1) }[m];
|
|
1024
|
+
if (!N) throw R(`Unsupported USD plane axis: ${m}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
1025
|
+
const U = c.clone().multiply(new V().setFromUnitVectors(new I(0, 0, 1), N));
|
|
1026
|
+
return `<geom type="plane" pos="${B(u.toArray())}" quat="${K(U)}" size="1 1 0.1" ${i}/>`;
|
|
1027
|
+
}
|
|
1028
|
+
if (l.includes("cone"))
|
|
1029
|
+
throw R(`MuJoCo has no analytic cone geom; a validated mesh conversion is required: ${t.path}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
1030
|
+
if (l.includes("sphere")) {
|
|
1031
|
+
const m = [Math.abs(h.x), Math.abs(h.y), Math.abs(h.z)];
|
|
1032
|
+
if (Math.max(...m) - Math.min(...m) > 1e-6) throw R(`USD sphere collider does not support non-uniform scale: ${t.path}`, "E_USD_NONUNIFORM_RADIAL_SCALE");
|
|
1033
|
+
return `<geom type="sphere" pos="${B(u.toArray())}" quat="${K(c)}" size="${m[0] * y("radius", 1)}" ${i}/>`;
|
|
1034
|
+
}
|
|
1035
|
+
if (l.includes("cylinder") || l.includes("capsule")) {
|
|
1036
|
+
const m = String(ce(e, t.path, "axis") ?? "Z").toUpperCase(), S = { X: 0, Y: 1, Z: 2 }[m];
|
|
1037
|
+
if (S === void 0) throw R(`Unsupported USD collider axis: ${m}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
1038
|
+
const N = [Math.abs(h.x), Math.abs(h.y), Math.abs(h.z)], U = N.filter((x, f) => f !== S);
|
|
1039
|
+
if (Math.abs(U[0] - U[1]) > 1e-6) throw R(`USD ${t.typeName} collider does not support non-uniform radial scale: ${t.path}`, "E_USD_NONUNIFORM_RADIAL_SCALE");
|
|
1040
|
+
const E = new I(...{ X: [1, 0, 0], Y: [0, 1, 0], Z: [0, 0, 1] }[m]), b = c.clone().multiply(new V().setFromUnitVectors(new I(0, 0, 1), E)), w = y("radius", 1) * U[0], P = y("height", 2) * N[S] / 2;
|
|
1041
|
+
return `<geom type="${l.includes("capsule") ? "capsule" : "cylinder"}" pos="${B(u.toArray())}" quat="${K(b)}" size="${w} ${P}" ${i}/>`;
|
|
1042
|
+
}
|
|
1043
|
+
if (l.includes("mesh")) {
|
|
1044
|
+
if (t.approximation && !["none", "convexHull"].includes(t.approximation)) throw R(`USD mesh approximation cannot be mapped exactly: ${t.path}`, "E_USD_UNSUPPORTED_APPROXIMATION");
|
|
1045
|
+
const m = [];
|
|
1046
|
+
if (a.traverse((b) => {
|
|
1047
|
+
b instanceof ne && m.push(b);
|
|
1048
|
+
}), !m.length) throw R(`USD collider has no mesh geometry: ${t.path}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
1049
|
+
const S = [], N = [];
|
|
1050
|
+
let U = 0;
|
|
1051
|
+
for (const b of m) {
|
|
1052
|
+
const w = b.geometry.getAttribute("position");
|
|
1053
|
+
for (let x = 0; x < w.count; x++) {
|
|
1054
|
+
const f = new I().fromBufferAttribute(w, x).applyMatrix4(s.clone().invert().multiply(b.matrixWorld));
|
|
1055
|
+
S.push(f.x, f.y, f.z);
|
|
1056
|
+
}
|
|
1057
|
+
const P = b.geometry.index;
|
|
1058
|
+
for (let x = 0; x < (P ? P.count : w.count); x += 3) N.push(U + (P ? P.getX(x) : x), U + (P ? P.getX(x + 1) : x + 1), U + (P ? P.getX(x + 2) : x + 2));
|
|
1059
|
+
U += w.count;
|
|
1060
|
+
}
|
|
1061
|
+
const E = `collision_${o}`;
|
|
1062
|
+
return p.push(`<mesh name="${E}" vertex="${B(S)}" face="${B(N)}"/>`), `<geom type="mesh" mesh="${E}" ${i}/>`;
|
|
1063
|
+
}
|
|
1064
|
+
throw R(`Unsupported USD collider geometry: ${t.typeName}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
1065
|
+
}
|
|
1066
|
+
function Xt(e) {
|
|
1067
|
+
const t = e.stage.GetPseudoRoot();
|
|
1068
|
+
try {
|
|
1069
|
+
const n = Number(t.GetMetadata("metersPerUnit") ?? 0.01), s = Number(t.GetMetadata("kilogramsPerUnit") ?? 1);
|
|
1070
|
+
if (!Number.isFinite(n) || n <= 0) throw R("USD metersPerUnit must be finite and positive.", "E_USD_INVALID_UNITS");
|
|
1071
|
+
if (!Number.isFinite(s) || s <= 0) throw R("USD kilogramsPerUnit must be finite and positive.", "E_USD_INVALID_UNITS");
|
|
1072
|
+
return { metersPerUnit: n, kilogramsPerUnit: s };
|
|
1073
|
+
} finally {
|
|
1074
|
+
t.delete();
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
function Z(e) {
|
|
1078
|
+
const [t = 1, n = 0, s = 0, o = 0] = e;
|
|
1079
|
+
return new V(n, s, o, t).normalize();
|
|
1080
|
+
}
|
|
1081
|
+
function B(e) {
|
|
1082
|
+
return e.join(" ");
|
|
1083
|
+
}
|
|
1084
|
+
function K(e) {
|
|
1085
|
+
return `${e.w} ${e.x} ${e.y} ${e.z}`;
|
|
1086
|
+
}
|
|
1087
|
+
function ce(e, t, n) {
|
|
1088
|
+
var r, u;
|
|
1089
|
+
const s = e.stage;
|
|
1090
|
+
if (!s || !((u = (r = e.pxr) == null ? void 0 : r.Sdf) != null && u.Path)) return null;
|
|
1091
|
+
const o = new e.pxr.Sdf.Path(t), p = s.GetPrimAtPath(o), i = p.GetAttribute(n), a = e.pxr.Usd.TimeCode.Default();
|
|
1092
|
+
try {
|
|
1093
|
+
return i.IsValid() ? i.Get(a) : null;
|
|
1094
|
+
} finally {
|
|
1095
|
+
a.delete(), i.delete(), p.delete(), o.delete();
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
function Jt() {
|
|
1099
|
+
if (!globalThis.isSecureContext) throw R("OpenUSD requires a secure context.", "E_USD_SECURE_CONTEXT_REQUIRED");
|
|
1100
|
+
if (!globalThis.crossOriginIsolated) throw R("OpenUSD requires COOP/COEP cross-origin isolation.", "E_USD_CROSS_ORIGIN_ISOLATION_REQUIRED");
|
|
1101
|
+
}
|
|
1102
|
+
async function Qt(e, t) {
|
|
1103
|
+
var n;
|
|
1104
|
+
if (e.url)
|
|
1105
|
+
try {
|
|
1106
|
+
return new URL(e.url, ((n = globalThis.location) == null ? void 0 : n.href) ?? e.baseUrl ?? void 0).href;
|
|
1107
|
+
} catch {
|
|
1108
|
+
return e.url;
|
|
1109
|
+
}
|
|
1110
|
+
return e.resolve(t);
|
|
1111
|
+
}
|
|
1112
|
+
async function Zt(e) {
|
|
1113
|
+
const t = e.url ?? await e.resolve(e.entryPath ?? ""), n = await fetch(t, { signal: e.signal });
|
|
1114
|
+
if (!n.ok) throw R(`USD request failed (${n.status}): ${t}`, n.status === 401 || n.status === 403 ? "E_ASSET_AUTH" : "E_ASSET_FETCH");
|
|
1115
|
+
return n.blob();
|
|
1116
|
+
}
|
|
1117
|
+
const Kt = /* @__PURE__ */ new Set(["usd", "usda", "usdc"]), ze = 1024, en = 8;
|
|
1118
|
+
let tn = 0;
|
|
1119
|
+
async function nn(e, t, n, s, o) {
|
|
1120
|
+
const p = `/tmp/viewer-usd-resolver/${++tn}`;
|
|
1121
|
+
e.FS.createDir(p);
|
|
1122
|
+
const i = [{ path: et(s), blob: n, depth: 0 }], a = /* @__PURE__ */ new Set();
|
|
1123
|
+
try {
|
|
1124
|
+
for (; i.length > 0; ) {
|
|
1125
|
+
t.signal.throwIfAborted();
|
|
1126
|
+
const r = i.shift();
|
|
1127
|
+
if (a.has(r.path) || r.depth > en) continue;
|
|
1128
|
+
if (a.size >= ze) throw R(`USD dependency limit exceeded (${ze}).`, "E_ASSET_RESOURCE_LIMIT");
|
|
1129
|
+
a.add(r.path);
|
|
1130
|
+
const u = `${p}/${r.path}`;
|
|
1131
|
+
e.FS.createDir(u.split("/").slice(0, -1).join("/")), e.FS.writeFile(u, new Uint8Array(await r.blob.arrayBuffer()));
|
|
1132
|
+
const c = e.UsdUtils.ExtractSanitizedExternalReferences(u);
|
|
1133
|
+
for (const h of c) {
|
|
1134
|
+
const l = sn(r.path, h);
|
|
1135
|
+
if (!l || a.has(l)) continue;
|
|
1136
|
+
const y = await t.resolve(l), m = await fetch(y, { signal: t.signal });
|
|
1137
|
+
if (!m.ok) {
|
|
1138
|
+
const N = m.status === 401 || m.status === 403 ? "E_ASSET_AUTH" : "E_ASSET_FETCH";
|
|
1139
|
+
throw R(`USD dependency request failed (${m.status}): ${l}`, N);
|
|
1140
|
+
}
|
|
1141
|
+
const S = await m.blob();
|
|
1142
|
+
o.put(l, S), Kt.has(on(l)) && i.push({ path: l, blob: S, depth: r.depth + 1 });
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
} finally {
|
|
1146
|
+
tt(e, p);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
function sn(e, t) {
|
|
1150
|
+
if (!t || /^(?:data|blob):/i.test(t)) return null;
|
|
1151
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(t) || t.startsWith("/")) return t;
|
|
1152
|
+
const n = e.split("/").slice(0, -1).join("/");
|
|
1153
|
+
return et(n ? `${n}/${t}` : t);
|
|
1154
|
+
}
|
|
1155
|
+
function et(e) {
|
|
1156
|
+
const t = [];
|
|
1157
|
+
for (const n of e.replaceAll("\\", "/").split("/"))
|
|
1158
|
+
!n || n === "." || (n === ".." ? t.pop() : t.push(n));
|
|
1159
|
+
return t.join("/");
|
|
1160
|
+
}
|
|
1161
|
+
function on(e) {
|
|
1162
|
+
var t, n;
|
|
1163
|
+
return ((n = (t = e.split(/[?#]/, 1)[0]) == null ? void 0 : t.split(".").pop()) == null ? void 0 : n.toLowerCase()) ?? "";
|
|
1164
|
+
}
|
|
1165
|
+
function tt(e, t) {
|
|
1166
|
+
if (e.FS.exists(t)) {
|
|
1167
|
+
for (const n of e.FS.listDir(t))
|
|
1168
|
+
n.isDir ? tt(e, n.path) : e.FS.deleteFile(n.path);
|
|
1169
|
+
e.FS.deleteDir(t);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function J(e) {
|
|
1173
|
+
return e.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<").replaceAll(">", ">");
|
|
1174
|
+
}
|
|
1175
|
+
function R(e, t) {
|
|
1176
|
+
return Object.assign(new Error(e), { code: t });
|
|
1177
|
+
}
|
|
1178
|
+
function _e() {
|
|
1179
|
+
return Object.assign(new Error("USD load aborted."), { name: "AbortError", code: "E_ABORTED" });
|
|
1180
|
+
}
|
|
1181
|
+
export {
|
|
1182
|
+
Ge as compileUsdCollisionOverlay,
|
|
1183
|
+
Qe as compileUsdCollisionVisual,
|
|
1184
|
+
Wt as compileUsdPhysics,
|
|
1185
|
+
Yt as compileUsdVisual,
|
|
1186
|
+
Gt as firstUsdVisualWarning,
|
|
1187
|
+
fn as isUsdPhysicsFallbackEligible,
|
|
1188
|
+
dn as loadUsdSimulation,
|
|
1189
|
+
Ze as resolveUsdJoints,
|
|
1190
|
+
nn as resolveUsdResourcePackage,
|
|
1191
|
+
qt as shouldInjectUsdDefaultGround
|
|
1192
|
+
};
|