@nebula-spatial/viewer 0.4.5 → 0.5.0
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 +62 -5
- package/README.md +98 -51
- package/dist/assets/types.d.ts +40 -11
- package/dist/cad/types.d.ts +4 -8
- package/dist/{index-CxbZ--5C.js → index-D2vtjYht.js} +2648 -2287
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -2
- package/dist/{mjcf-visual-6_RqDf4z.js → mjcf-visual-NkIASi_6.js} +2 -2
- package/dist/mujoco-runtime-7xiBQNJm.js +324 -0
- package/dist/session-DHPMjyl3.js +809 -0
- package/dist/{session-CnlODeFp.js → session-di9BueA_.js} +152 -163
- package/dist/{stage-BPiGudYP.js → stage-D-BewE6x.js} +198 -150
- package/dist/types.d.ts +11 -0
- package/dist/{urdf-session-CuIZOiCF.js → urdf-session-DsE5uC-u.js} +433 -424
- package/dist/usd-session-yEFMGOIp.js +2240 -0
- package/dist/version.d.ts +5 -0
- package/dist/{xacro-DrBtv-gK.js → xacro-D8OfZ2xw.js} +1 -1
- package/openusd/openusd_probe.js +14 -0
- package/openusd/openusd_probe.wasm +0 -0
- package/package.json +5 -4
- package/dist/mujoco-runtime-C29PXDOl.js +0 -258
- package/dist/session-DNyPmQOW.js +0 -795
- package/dist/usd-session-JDfuDgWv.js +0 -1907
|
@@ -0,0 +1,2240 @@
|
|
|
1
|
+
import { Mesh as te, FrontSide as vt, DoubleSide as Pt, MeshPhysicalMaterial as ie, DataTexture as Je, UnsignedByteType as Ze, RGBAFormat as Ke, NoColorSpace as K, Float32BufferAttribute as At, SRGBColorSpace as Qe, RepeatWrapping as q, Color as ut, Texture as lt, MeshStandardMaterial as He, TextureLoader as pt, MirroredRepeatWrapping as ft, ClampToEdgeWrapping as dt, Group as Ee, Vector3 as N, Quaternion as ee, Matrix4 as pe, Box3 as Te, Sphere as Dt, SphereGeometry as Mt, BoxGeometry as Rt, SkinnedMesh as Me, Skeleton as It, AnimationMixer as Ot, LoopRepeat as Tt } from "three";
|
|
2
|
+
import { n as Nt, c as $t, a as Re, b as Lt, d as Ct, p as Gt, S as et } from "./session-DHPMjyl3.js";
|
|
3
|
+
import { ConvexGeometry as Bt } from "three/examples/jsm/geometries/ConvexGeometry.js";
|
|
4
|
+
import { createUSDLoadedModel as Ft, buildUSDScene as kt } from "@openusd-wasm/three-loader";
|
|
5
|
+
import { b as mt } from "./stage-D-BewE6x.js";
|
|
6
|
+
function Vt(e) {
|
|
7
|
+
var s, d;
|
|
8
|
+
const t = e.stage;
|
|
9
|
+
if (!t || !((d = (s = e.pxr) == null ? void 0 : s.Sdf) != null && d.Path)) return;
|
|
10
|
+
const n = /* @__PURE__ */ new Map(), r = (f) => {
|
|
11
|
+
if (!f || f === "/") return "default";
|
|
12
|
+
const p = n.get(f);
|
|
13
|
+
if (p !== void 0) return p;
|
|
14
|
+
const o = new e.pxr.Sdf.Path(f), a = t.GetPrimAtPath(o), i = a.GetAttribute("purpose"), c = e.pxr.Usd.TimeCode.Default();
|
|
15
|
+
let m;
|
|
16
|
+
try {
|
|
17
|
+
i.IsValid() && i.HasAuthoredValue() && (m = String(i.Get(c)));
|
|
18
|
+
} finally {
|
|
19
|
+
c.delete(), i.delete(), a.delete(), o.delete();
|
|
20
|
+
}
|
|
21
|
+
const y = m ?? r(f.slice(0, f.lastIndexOf("/")));
|
|
22
|
+
return n.set(f, y), y;
|
|
23
|
+
};
|
|
24
|
+
e.scene.traverse((f) => {
|
|
25
|
+
var i, c;
|
|
26
|
+
if (!(f instanceof te)) return;
|
|
27
|
+
let p = f, o;
|
|
28
|
+
for (; p && !o; )
|
|
29
|
+
o = (i = p.userData.usd) == null ? void 0 : i.path, p = p.parent;
|
|
30
|
+
if (!o) return;
|
|
31
|
+
const a = r(o) === "guide";
|
|
32
|
+
f.userData.usdPurposeExcluded = a, a ? ((c = f.userData).usdPurposeLayerMask ?? (c.usdPurposeLayerMask = f.layers.mask), f.layers.disableAll()) : f.userData.usdPurposeLayerMask !== void 0 && (f.layers.mask = f.userData.usdPurposeLayerMask, delete f.userData.usdPurposeLayerMask);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const Wt = 67324752, jt = 33639248, zt = 101010256, Ge = 4294967295, Yt = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "webp"]);
|
|
36
|
+
function Ht(e) {
|
|
37
|
+
return e.length > 3 && e[0] === 80 && e[1] === 75;
|
|
38
|
+
}
|
|
39
|
+
async function Xt(e, t = {}) {
|
|
40
|
+
const n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = en(n);
|
|
41
|
+
if (r < 0) throw new Error("Not a zip package: end of central directory not found.");
|
|
42
|
+
const s = n.getUint16(r + 10, !0);
|
|
43
|
+
let d = n.getUint32(r + 16, !0);
|
|
44
|
+
if (s === 65535 || d === Ge) throw new Error("ZIP64 usdz packages are not supported.");
|
|
45
|
+
const f = /* @__PURE__ */ new Map(), p = [];
|
|
46
|
+
for (let o = 0; o < s; o += 1) {
|
|
47
|
+
if (d + 46 > n.byteLength || n.getUint32(d, !0) !== jt)
|
|
48
|
+
throw new Error(`Corrupt zip central directory at entry ${o}.`);
|
|
49
|
+
const a = n.getUint16(d + 10, !0), i = n.getUint32(d + 20, !0), c = n.getUint16(d + 28, !0), m = n.getUint16(d + 30, !0), y = n.getUint16(d + 32, !0), u = n.getUint32(d + 42, !0);
|
|
50
|
+
if (i === Ge || u === Ge)
|
|
51
|
+
throw new Error("ZIP64 usdz packages are not supported.");
|
|
52
|
+
const l = new TextDecoder().decode(e.subarray(d + 46, d + 46 + c));
|
|
53
|
+
d += 46 + c + m + y, !l.endsWith("/") && (t.include && !t.include(l) || p.push(Jt(e, n, u, i, a).then((_) => ({ name: l, data: _ }))));
|
|
54
|
+
}
|
|
55
|
+
for (const { name: o, data: a } of await Promise.all(p)) f.set(o, a);
|
|
56
|
+
return f;
|
|
57
|
+
}
|
|
58
|
+
function qt(e) {
|
|
59
|
+
if (typeof URL > "u" || typeof URL.createObjectURL != "function") return null;
|
|
60
|
+
const t = new Map([...e].filter(([f]) => Yt.has(ht(f))));
|
|
61
|
+
if (t.size === 0) return null;
|
|
62
|
+
const n = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const f of t.keys()) {
|
|
64
|
+
const p = f.split("/").pop() ?? f;
|
|
65
|
+
n.set(p, n.has(p) ? null : f);
|
|
66
|
+
}
|
|
67
|
+
const r = /* @__PURE__ */ new Map(), s = (f) => {
|
|
68
|
+
let p = r.get(f);
|
|
69
|
+
if (!p) {
|
|
70
|
+
const o = t.get(f);
|
|
71
|
+
p = URL.createObjectURL(new Blob([new Uint8Array(o)], { type: Qt(f) })), r.set(f, p);
|
|
72
|
+
}
|
|
73
|
+
return p;
|
|
74
|
+
}, d = (f) => {
|
|
75
|
+
if (!f) return null;
|
|
76
|
+
const p = Kt(Zt(f));
|
|
77
|
+
if (!p) return null;
|
|
78
|
+
if (t.has(p)) return s(p);
|
|
79
|
+
const o = [...t.keys()].filter((c) => c.endsWith(`/${p}`));
|
|
80
|
+
if (o.length === 1) return s(o[0]);
|
|
81
|
+
const a = [...t.keys()].filter((c) => p.endsWith(`/${c}`));
|
|
82
|
+
if (a.length === 1) return s(a[0]);
|
|
83
|
+
const i = n.get(p.split("/").pop() ?? "");
|
|
84
|
+
return i ? s(i) : null;
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
resolve: (f) => d(f.resolvedPath) ?? d(f.path) ?? d(f.url) ?? null,
|
|
88
|
+
dispose: () => {
|
|
89
|
+
for (const f of r.values()) URL.revokeObjectURL(f);
|
|
90
|
+
r.clear();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function Jt(e, t, n, r, s) {
|
|
95
|
+
if (t.getUint32(n, !0) !== Wt) throw new Error("Corrupt zip local file header.");
|
|
96
|
+
const d = t.getUint16(n + 26, !0), f = t.getUint16(n + 28, !0), p = n + 30 + d + f, o = e.subarray(p, p + r);
|
|
97
|
+
if (s === 0) return o.slice();
|
|
98
|
+
if (s !== 8) throw new Error(`Unsupported zip compression method ${s}.`);
|
|
99
|
+
const a = new Blob([new Uint8Array(o)]).stream().pipeThrough(new DecompressionStream("deflate-raw"));
|
|
100
|
+
return new Uint8Array(await new Response(a).arrayBuffer());
|
|
101
|
+
}
|
|
102
|
+
function Zt(e) {
|
|
103
|
+
const t = e.indexOf("[");
|
|
104
|
+
return t >= 0 && e.endsWith("]") ? e.slice(t + 1, -1) : e;
|
|
105
|
+
}
|
|
106
|
+
function Kt(e) {
|
|
107
|
+
const t = [];
|
|
108
|
+
for (const n of e.replaceAll("\\", "/").split("/"))
|
|
109
|
+
!n || n === "." || (n === ".." ? t.pop() : t.push(n));
|
|
110
|
+
return t.join("/");
|
|
111
|
+
}
|
|
112
|
+
function ht(e) {
|
|
113
|
+
const t = e.split(/[?#]/)[0] ?? e, n = t.lastIndexOf(".");
|
|
114
|
+
return n < 0 ? "" : t.slice(n + 1).toLowerCase();
|
|
115
|
+
}
|
|
116
|
+
function Qt(e) {
|
|
117
|
+
switch (ht(e)) {
|
|
118
|
+
case "png":
|
|
119
|
+
return "image/png";
|
|
120
|
+
case "jpg":
|
|
121
|
+
case "jpeg":
|
|
122
|
+
return "image/jpeg";
|
|
123
|
+
case "webp":
|
|
124
|
+
return "image/webp";
|
|
125
|
+
default:
|
|
126
|
+
return "application/octet-stream";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function en(e) {
|
|
130
|
+
const t = Math.max(0, e.byteLength - 65535 - 22);
|
|
131
|
+
for (let n = e.byteLength - 22; n >= t; n -= 1)
|
|
132
|
+
if (e.getUint32(n, !0) === zt) return n;
|
|
133
|
+
return -1;
|
|
134
|
+
}
|
|
135
|
+
const tn = /* @__PURE__ */ new Set(["usd", "usda", "usdc", "usdz"]);
|
|
136
|
+
async function nn(e) {
|
|
137
|
+
const t = await import(
|
|
138
|
+
/* @vite-ignore */
|
|
139
|
+
e.moduleUrl
|
|
140
|
+
), n = t.default ?? t.createOpenUsdProbe, r = await (typeof e.wasmBinary == "function" ? e.wasmBinary() : e.wasmBinary ?? pn(e.wasmUrl)), s = await n({ wasmBinary: r }), d = e.memfsRoot ?? "/asset", f = e.fetchBytes ?? (async (c) => new Uint8Array(await (await fetch(c)).arrayBuffer())), p = (c, m, y) => JSON.parse(s.ccall(c, "string", m, y)), o = /* @__PURE__ */ new Set(), a = sn(s);
|
|
141
|
+
async function i(c, m) {
|
|
142
|
+
const y = new URL(m.sourcePath, "file:///"), u = ln(y.href, y, d), l = /* @__PURE__ */ new Set(), _ = await tt(c);
|
|
143
|
+
Ve(s, u, _, l);
|
|
144
|
+
for (const [T, w] of Object.entries(m.files ?? {}))
|
|
145
|
+
Ve(s, `${d}/${T.replace(/^\/+/, "")}`, await tt(w), l);
|
|
146
|
+
const g = Ht(_) ? await Xt(_, { include: rn }) : null;
|
|
147
|
+
if (!g && m.autoResolveAssets !== !1) {
|
|
148
|
+
const T = m.resolveBytes ?? ((w) => f(w));
|
|
149
|
+
await cn(s, y, d, T, p, l, m.maxFiles ?? 1024, m.maxDepth ?? 8);
|
|
150
|
+
}
|
|
151
|
+
const h = g ? qt(g) : null, S = m.textureResolver || h ? (T) => {
|
|
152
|
+
var w;
|
|
153
|
+
return ((w = m.textureResolver) == null ? void 0 : w.call(m, T)) ?? (h == null ? void 0 : h.resolve(T)) ?? null;
|
|
154
|
+
} : void 0, U = p("usd_probe_stage_open", ["string"], [u]);
|
|
155
|
+
if (!U.ok) throw new Error(U.error ?? `Failed to open ${u}`);
|
|
156
|
+
o.add(U.stageId);
|
|
157
|
+
const P = a.openStage(U.stageId), A = an(s, U.stageId, u), E = Ft(
|
|
158
|
+
A,
|
|
159
|
+
a,
|
|
160
|
+
u,
|
|
161
|
+
{
|
|
162
|
+
sourcePath: m.sourcePath,
|
|
163
|
+
// `convertZUp` and `loadLights` are opt-in here: the viewer normalises USD
|
|
164
|
+
// to world Z-up itself and draws its own studio lighting. `loadTextures`
|
|
165
|
+
// keeps the reference builder's opt-out default, so omitting it loads
|
|
166
|
+
// textures instead of silently rendering untextured materials.
|
|
167
|
+
convertZUp: m.convertZUp ?? !1,
|
|
168
|
+
loadLights: m.loadLights ?? !1,
|
|
169
|
+
loadTextures: m.loadTextures ?? !0,
|
|
170
|
+
...m.textureLoader ? { textureLoader: m.textureLoader } : {},
|
|
171
|
+
...S ? { textureResolver: S } : {}
|
|
172
|
+
},
|
|
173
|
+
P
|
|
174
|
+
), M = E.dispose.bind(E);
|
|
175
|
+
return E.dispose = () => {
|
|
176
|
+
M(), h == null || h.dispose(), o.delete(U.stageId) && p("usd_probe_stage_release", ["number"], [U.stageId]);
|
|
177
|
+
}, E;
|
|
178
|
+
}
|
|
179
|
+
return { runtime: s, pxr: a, parseAsync: i };
|
|
180
|
+
}
|
|
181
|
+
function rn(e) {
|
|
182
|
+
return /\.(?:png|jpe?g|webp)$/i.test(e.split(/[?#]/, 1)[0] ?? e);
|
|
183
|
+
}
|
|
184
|
+
function sn(e) {
|
|
185
|
+
const t = (p, o, a) => JSON.parse(e.ccall(p, "string", o, a));
|
|
186
|
+
class n {
|
|
187
|
+
constructor(o) {
|
|
188
|
+
this.path = o;
|
|
189
|
+
}
|
|
190
|
+
delete() {
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const r = (p, o, a) => {
|
|
194
|
+
const i = t("usd_probe_attribute_value", ["number", "string", "string"], [p, o, a]), c = i.valid === !0;
|
|
195
|
+
return {
|
|
196
|
+
IsValid: () => c,
|
|
197
|
+
Get: () => c ? i.value : null,
|
|
198
|
+
HasAuthoredValue: () => i.authored === !0,
|
|
199
|
+
GetName: () => a,
|
|
200
|
+
GetMetadata: (m) => {
|
|
201
|
+
const y = t("usd_probe_attribute_metadata", ["number", "string", "string", "string"], [p, o, a, m]);
|
|
202
|
+
return y.valid === !0 && y.found === !0 ? y.value ?? null : null;
|
|
203
|
+
},
|
|
204
|
+
// The viewer accepts either plain strings or objects with GetString().
|
|
205
|
+
GetConnections: () => t("usd_probe_attribute_connections", ["number", "string", "string"], [p, o, a]).paths ?? [],
|
|
206
|
+
delete: () => {
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}, s = (p, o) => ({
|
|
210
|
+
__path: o,
|
|
211
|
+
__stageId: p,
|
|
212
|
+
IsValid: () => t("usd_probe_prim_info", ["number", "string"], [p, o]).valid === !0,
|
|
213
|
+
GetName: () => String(o.split("/").pop() ?? ""),
|
|
214
|
+
GetPath: () => new n(o),
|
|
215
|
+
GetTypeName: () => String(t("usd_probe_prim_info", ["number", "string"], [p, o]).typeName ?? ""),
|
|
216
|
+
IsInstance: () => t("usd_probe_prim_info", ["number", "string"], [p, o]).instance === !0,
|
|
217
|
+
GetAttribute: (a) => r(p, o, a),
|
|
218
|
+
GetAttributes: () => (t("usd_probe_prim_attributes", ["number", "string"], [p, o]).names ?? []).map((a) => r(p, o, a)),
|
|
219
|
+
GetChildren: () => (t("usd_probe_prim_children", ["number", "string"], [p, o]).paths ?? []).map((a) => s(p, a)),
|
|
220
|
+
GetMetadata: (a) => {
|
|
221
|
+
const i = t("usd_probe_prim_metadata", ["number", "string", "string"], [p, o, a]);
|
|
222
|
+
return i.valid !== !0 ? null : typeof i.text == "string" ? i.text : i.found === !0 ? i.value : null;
|
|
223
|
+
},
|
|
224
|
+
delete: () => {
|
|
225
|
+
}
|
|
226
|
+
}), d = (p) => ({
|
|
227
|
+
GetPrimAtPath: (o) => s(p, typeof o == "string" ? o : o.path),
|
|
228
|
+
GetPseudoRoot: () => Object.assign(s(p, "/"), {
|
|
229
|
+
// Stage-level metadata (metersPerUnit, upAxis, defaultPrim) is authored on
|
|
230
|
+
// the layer, not composed onto the pseudo-root prim.
|
|
231
|
+
GetMetadata: (o) => {
|
|
232
|
+
const a = t("usd_probe_stage_metadata", ["number", "string"], [p, o]);
|
|
233
|
+
return a.found === !0 ? a.value : null;
|
|
234
|
+
},
|
|
235
|
+
GetName: () => "",
|
|
236
|
+
IsValid: () => !0
|
|
237
|
+
}),
|
|
238
|
+
delete: () => {
|
|
239
|
+
}
|
|
240
|
+
}), { FS: f } = e;
|
|
241
|
+
return {
|
|
242
|
+
FS: {
|
|
243
|
+
createDir: (p) => f.mkdirTree(p),
|
|
244
|
+
writeFile: (p, o) => f.writeFile(p, o),
|
|
245
|
+
exists: (p) => f.analyzePath(p, !0).exists,
|
|
246
|
+
listDir: (p) => f.readdir(p).filter((o) => o !== "." && o !== "..").map((o) => {
|
|
247
|
+
const a = `${p.replace(/\/+$/, "")}/${o}`;
|
|
248
|
+
return { path: a, name: o, isDir: f.isDir(f.stat(a).mode) };
|
|
249
|
+
}),
|
|
250
|
+
deleteFile: (p) => f.unlink(p),
|
|
251
|
+
deleteDir: (p) => f.rmdir(p)
|
|
252
|
+
},
|
|
253
|
+
Sdf: { Path: n },
|
|
254
|
+
Usd: { TimeCode: { Default: () => ({ delete: () => {
|
|
255
|
+
} }) } },
|
|
256
|
+
UsdShade: {
|
|
257
|
+
ComputeBoundMaterialPath: (p) => {
|
|
258
|
+
const o = t("usd_probe_bound_material", ["number", "string"], [p.__stageId, p.__path]);
|
|
259
|
+
return o.found !== !0 ? null : {
|
|
260
|
+
materialPath: String(o.materialPath ?? ""),
|
|
261
|
+
resolvedTargetPath: String(o.resolvedTargetPath ?? ""),
|
|
262
|
+
bindingRelationshipPath: String(o.bindingRelationshipPath ?? "")
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
UsdUtils: {
|
|
267
|
+
ExtractSanitizedExternalReferences: (p) => t("usd_probe_external_references", ["string"], [p]).paths ?? []
|
|
268
|
+
},
|
|
269
|
+
openStage: d
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function an(e, t, n) {
|
|
273
|
+
const r = JSON.parse(e.ccall("usd_probe_scene_data", "string", ["number", "string"], [t, n]));
|
|
274
|
+
if (r.error) throw new Error(r.error);
|
|
275
|
+
const s = r;
|
|
276
|
+
for (const d of s.elements)
|
|
277
|
+
d.geometry = Object.fromEntries(
|
|
278
|
+
Object.entries(d.geometry).map(([f, p]) => [f, on(e, p)])
|
|
279
|
+
);
|
|
280
|
+
return s;
|
|
281
|
+
}
|
|
282
|
+
function on(e, t) {
|
|
283
|
+
if (!t || typeof t != "object") return t ?? null;
|
|
284
|
+
const { ptr: n, length: r, kind: s } = t;
|
|
285
|
+
return typeof n != "number" ? t : r ? (s === "i32" ? new Int32Array(e.HEAP32.buffer, n, r) : new Float32Array(e.HEAPF32.buffer, n, r)).slice() : s === "i32" ? new Int32Array() : new Float32Array();
|
|
286
|
+
}
|
|
287
|
+
async function cn(e, t, n, r, s, d, f, p) {
|
|
288
|
+
const o = [{ url: t, depth: 0, recurse: !0 }], a = /* @__PURE__ */ new Set();
|
|
289
|
+
for (; o.length; ) {
|
|
290
|
+
const i = o.shift();
|
|
291
|
+
if (a.has(i.url.href) || i.depth > p) continue;
|
|
292
|
+
if (a.size >= f) throw new Error(`USD dependency limit exceeded (${f}).`);
|
|
293
|
+
a.add(i.url.href);
|
|
294
|
+
const c = yt(i.url.href, t), m = c ? `${n}/${c}` : n;
|
|
295
|
+
if (d.has(m) || Ve(e, m, await r(i.url, c), d), !i.recurse) continue;
|
|
296
|
+
const y = s("usd_probe_external_references", ["string"], [m]).paths ?? [];
|
|
297
|
+
for (const u of y) {
|
|
298
|
+
if (!u || /^(?:data|blob):/i.test(u)) continue;
|
|
299
|
+
let l;
|
|
300
|
+
try {
|
|
301
|
+
l = new URL(u, i.url);
|
|
302
|
+
} catch {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
o.push({ url: l, depth: i.depth + 1, recurse: un(l.pathname) });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function un(e) {
|
|
310
|
+
var n, r;
|
|
311
|
+
const t = (r = (n = e.split(/[?#]/, 1)[0]) == null ? void 0 : n.split(".").pop()) == null ? void 0 : r.toLowerCase();
|
|
312
|
+
return t != null && tn.has(t);
|
|
313
|
+
}
|
|
314
|
+
function yt(e, t) {
|
|
315
|
+
const n = new URL(e), r = new URL(".", t), s = n.pathname.startsWith(r.pathname) ? n.pathname.slice(r.pathname.length) : n.pathname.replace(/^\/+/, "");
|
|
316
|
+
return decodeURIComponent(s);
|
|
317
|
+
}
|
|
318
|
+
function ln(e, t, n) {
|
|
319
|
+
const r = yt(e, t);
|
|
320
|
+
return r ? `${n}/${r}` : n;
|
|
321
|
+
}
|
|
322
|
+
function Ve(e, t, n, r) {
|
|
323
|
+
r.has(t) || (e.FS.mkdirTree(t.split("/").slice(0, -1).join("/") || "/"), e.FS.writeFile(t, n), r.add(t));
|
|
324
|
+
}
|
|
325
|
+
async function tt(e) {
|
|
326
|
+
return typeof e == "string" ? new TextEncoder().encode(e) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength) : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(await e.arrayBuffer());
|
|
327
|
+
}
|
|
328
|
+
async function pn(e) {
|
|
329
|
+
if (!e) throw new Error("createSingleThreadUsd needs wasmUrl or wasmBinary.");
|
|
330
|
+
return (await fetch(e)).arrayBuffer();
|
|
331
|
+
}
|
|
332
|
+
const fn = "/openusd/";
|
|
333
|
+
function dn(e) {
|
|
334
|
+
const t = (e ?? fn).replace(/\/*$/, "/"), n = typeof document > "u" ? new URL(t, "file:///").href : new URL(t, document.baseURI).href;
|
|
335
|
+
return {
|
|
336
|
+
moduleUrl: new URL("openusd_probe.js", n).href,
|
|
337
|
+
wasmUrl: new URL("openusd_probe.wasm", n).href
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function mn(e) {
|
|
341
|
+
var p, o;
|
|
342
|
+
const t = e.stage, n = e.pxr;
|
|
343
|
+
if (!t || !((p = n == null ? void 0 : n.Sdf) != null && p.Path) || !((o = n == null ? void 0 : n.Usd) != null && o.TimeCode)) return;
|
|
344
|
+
const r = n.Usd.TimeCode.Default(), s = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Set(), f = (a) => {
|
|
345
|
+
let i, c, m;
|
|
346
|
+
try {
|
|
347
|
+
if (i = new n.Sdf.Path(a), c = t.GetPrimAtPath(i), !c.IsValid() || (m = c.GetAttribute("doubleSided"), !m.IsValid() || typeof m.HasAuthoredValue != "function")) return "unknown";
|
|
348
|
+
if (!m.HasAuthoredValue()) return;
|
|
349
|
+
const y = m.Get(r);
|
|
350
|
+
return typeof y == "boolean" ? y : "unknown";
|
|
351
|
+
} catch {
|
|
352
|
+
return "unknown";
|
|
353
|
+
} finally {
|
|
354
|
+
m == null || m.delete(), c == null || c.delete(), i == null || i.delete();
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
try {
|
|
358
|
+
e.scene.traverse((a) => {
|
|
359
|
+
var u;
|
|
360
|
+
if (!(a instanceof te)) return;
|
|
361
|
+
const i = (u = a.userData.usd) == null ? void 0 : u.path;
|
|
362
|
+
if (typeof i != "string") return;
|
|
363
|
+
const c = f(i);
|
|
364
|
+
if (c === "unknown") return;
|
|
365
|
+
const m = c === !1 ? vt : Pt, y = (l) => {
|
|
366
|
+
if (!(l instanceof ie) || l.transmission <= 0 || l.metalness !== 0 || l.side === m) return l;
|
|
367
|
+
let _ = s.get(l);
|
|
368
|
+
_ || (_ = /* @__PURE__ */ new Map(), s.set(l, _));
|
|
369
|
+
let g = _.get(m);
|
|
370
|
+
return g || (g = l.clone(), g.side = m, g.needsUpdate = !0, g.userData.usdGlassSidePolicy = c === !1 ? "authored-false" : c === !0 ? "authored-true" : "viewer-default-double", _.set(m, g)), d.add(l), g;
|
|
371
|
+
};
|
|
372
|
+
if (Array.isArray(a.material)) {
|
|
373
|
+
const l = a.material, _ = l.map(y);
|
|
374
|
+
_.some((g, h) => g !== l[h]) && (a.material = _);
|
|
375
|
+
} else {
|
|
376
|
+
const l = y(a.material);
|
|
377
|
+
l !== a.material && (a.material = l);
|
|
378
|
+
}
|
|
379
|
+
}), e.scene.traverse((a) => {
|
|
380
|
+
if (a instanceof te) for (const i of Array.isArray(a.material) ? a.material : [a.material]) d.delete(i);
|
|
381
|
+
});
|
|
382
|
+
for (const a of d) a.dispose();
|
|
383
|
+
} finally {
|
|
384
|
+
r.delete();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function hn(e, t) {
|
|
388
|
+
if (!e.stage || t.shaders.length) return null;
|
|
389
|
+
const n = e.stage, r = e.pxr, s = r.Usd.TimeCode.Default(), d = (o, a) => {
|
|
390
|
+
const i = new r.Sdf.Path(o), c = n.GetPrimAtPath(i);
|
|
391
|
+
try {
|
|
392
|
+
if (!c.IsValid()) throw new Error("Missing prim");
|
|
393
|
+
return a(c);
|
|
394
|
+
} finally {
|
|
395
|
+
c.delete(), i.delete();
|
|
396
|
+
}
|
|
397
|
+
}, f = (o) => {
|
|
398
|
+
const a = o.GetConnections();
|
|
399
|
+
try {
|
|
400
|
+
return a.map((i) => typeof i == "string" ? i : i.GetString());
|
|
401
|
+
} finally {
|
|
402
|
+
for (const i of a) typeof i != "string" && i.delete();
|
|
403
|
+
}
|
|
404
|
+
}, p = (o, a = /* @__PURE__ */ new Set()) => {
|
|
405
|
+
if (a.has(o) || a.size >= 32) throw new Error("Cyclic material input");
|
|
406
|
+
a.add(o);
|
|
407
|
+
const i = o.lastIndexOf(".");
|
|
408
|
+
if (i < 0 || !o.slice(i + 1).startsWith("inputs:")) throw new Error("Not a constant input");
|
|
409
|
+
return d(o.slice(0, i), (c) => {
|
|
410
|
+
const m = c.GetAttribute(o.slice(i + 1));
|
|
411
|
+
try {
|
|
412
|
+
if (!m.IsValid()) throw new Error("Missing material input");
|
|
413
|
+
const y = f(m);
|
|
414
|
+
if (y.length > 1) throw new Error("Ambiguous material input");
|
|
415
|
+
const u = y.length ? p(y[0], a) : m.Get(s);
|
|
416
|
+
if (u == null) throw new Error("Unauthored material input");
|
|
417
|
+
return u;
|
|
418
|
+
} finally {
|
|
419
|
+
m.delete();
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
try {
|
|
424
|
+
return d(t.path, (o) => {
|
|
425
|
+
if (!o.IsInstance()) return null;
|
|
426
|
+
const a = o.GetAttribute("outputs:surface");
|
|
427
|
+
let i;
|
|
428
|
+
try {
|
|
429
|
+
if (!a.IsValid()) return null;
|
|
430
|
+
i = f(a);
|
|
431
|
+
} finally {
|
|
432
|
+
a.delete();
|
|
433
|
+
}
|
|
434
|
+
if (i.length !== 1 || !i[0].endsWith(".outputs:surface")) return null;
|
|
435
|
+
const c = i[0].slice(0, -16);
|
|
436
|
+
return d(c, (m) => {
|
|
437
|
+
const y = m.GetAttribute("info:id");
|
|
438
|
+
try {
|
|
439
|
+
if (y.Get(s) !== "UsdPreviewSurface") return null;
|
|
440
|
+
} finally {
|
|
441
|
+
y.delete();
|
|
442
|
+
}
|
|
443
|
+
const u = {}, l = m.GetAttributes();
|
|
444
|
+
try {
|
|
445
|
+
for (const g of l) {
|
|
446
|
+
const h = String(g.GetName());
|
|
447
|
+
h.startsWith("inputs:") && (u[h] = p(`${c}.${h}`));
|
|
448
|
+
}
|
|
449
|
+
} finally {
|
|
450
|
+
for (const g of l) g.delete();
|
|
451
|
+
}
|
|
452
|
+
return { ...t, shaders: [{ path: c, id: "UsdPreviewSurface", inputs: u }] };
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
} catch {
|
|
456
|
+
return null;
|
|
457
|
+
} finally {
|
|
458
|
+
s.delete();
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function de(e, t, n = 1, r = 0) {
|
|
462
|
+
var c;
|
|
463
|
+
const s = e.image, d = (s == null ? void 0 : s.naturalWidth) || (s == null ? void 0 : s.width), f = (s == null ? void 0 : s.naturalHeight) || (s == null ? void 0 : s.height);
|
|
464
|
+
if (!Number.isInteger(d) || !Number.isInteger(f) || d <= 0 || f <= 0) throw new Error("Texture has no decoded pixels");
|
|
465
|
+
let p;
|
|
466
|
+
if (e instanceof Je) {
|
|
467
|
+
if (e.type !== Ze || e.format !== Ke || ((c = s.data) == null ? void 0 : c.length) !== d * f * 4) throw new Error("Unsupported scalar pixel format");
|
|
468
|
+
p = s.data;
|
|
469
|
+
} else {
|
|
470
|
+
const m = document.createElement("canvas");
|
|
471
|
+
m.width = d, m.height = f;
|
|
472
|
+
const y = m.getContext("2d", { willReadFrequently: !0 });
|
|
473
|
+
if (!y) throw new Error("Scalar conversion requires a 2D canvas");
|
|
474
|
+
y.drawImage(s, 0, 0), p = y.getImageData(0, 0, d, f).data;
|
|
475
|
+
}
|
|
476
|
+
const o = new Uint8Array(d * f * 4), a = "rgba".indexOf(t);
|
|
477
|
+
for (let m = 0; m < o.length; m += 4) {
|
|
478
|
+
const y = p[m], u = p[m + 1], l = p[m + 2];
|
|
479
|
+
if (t === "grayscale" && (y !== u || u !== l)) throw new Error("Non-grayscale scalar image needs an explicit mono convention");
|
|
480
|
+
const _ = t === "average" ? (y + u + l) / 3 : t === "maximum" ? Math.max(y, u, l) : t === "grayscale" ? y : p[m + a], g = Math.round(255 * Math.min(1, Math.max(0, _ / 255 * n + r)));
|
|
481
|
+
o[m] = o[m + 1] = o[m + 2] = g, o[m + 3] = 255;
|
|
482
|
+
}
|
|
483
|
+
const i = new Je(o, d, f, Ke, Ze);
|
|
484
|
+
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.flipY = e.flipY, i.minFilter = e.minFilter, i.magFilter = e.magFilter, i.anisotropy = e.anisotropy, i.generateMipmaps = e.generateMipmaps, i.colorSpace = K, i.needsUpdate = !0, i;
|
|
485
|
+
}
|
|
486
|
+
function yn(e, t, n, r = [], s = !1) {
|
|
487
|
+
if (e.some((a) => !Number.isInteger(a) || a < 0) || e.reduce((a, i) => a + i, 0) !== t.length || r.some((a) => !Number.isInteger(a) || a < 0 || a >= e.length))
|
|
488
|
+
throw new Error("Invalid authored face topology");
|
|
489
|
+
const d = [], f = [], p = new Set(r);
|
|
490
|
+
let o = 0;
|
|
491
|
+
if (e.forEach((a, i) => {
|
|
492
|
+
if (!p.has(i)) for (let c = 1; c < a - 1; c++)
|
|
493
|
+
d.push(o, o + (s ? c + 1 : c), o + (s ? c : c + 1)), f.push(i);
|
|
494
|
+
o += a;
|
|
495
|
+
}), d.length !== n.length || d.some((a, i) => t[a] !== n[i]))
|
|
496
|
+
throw new Error("Authored polygon/loader corner correspondence unavailable");
|
|
497
|
+
return { corners: d, faces: f };
|
|
498
|
+
}
|
|
499
|
+
function gn(e, t, n) {
|
|
500
|
+
if (t.length !== n || t.some((s) => !Number.isInteger(s) || s < 0 || s >= e.length))
|
|
501
|
+
throw new Error("Invalid faceVarying UV indices");
|
|
502
|
+
const r = t.flatMap((s) => e[s]);
|
|
503
|
+
if (r.length !== n * 2 || !r.every(Number.isFinite)) throw new Error("Invalid UV values");
|
|
504
|
+
return r;
|
|
505
|
+
}
|
|
506
|
+
function _n(e, t) {
|
|
507
|
+
const n = Array(e).fill(0);
|
|
508
|
+
for (const r of t) for (const s of r.faces) {
|
|
509
|
+
if (!Number.isInteger(s) || s < 0 || s >= e || n[s] !== 0)
|
|
510
|
+
throw new Error("Invalid or overlapping material subset faces");
|
|
511
|
+
n[s] = r.slot;
|
|
512
|
+
}
|
|
513
|
+
return n;
|
|
514
|
+
}
|
|
515
|
+
function wn(e, t, n, r) {
|
|
516
|
+
if (!e.stage) return;
|
|
517
|
+
const s = e.stage, d = e.pxr, f = d.Usd.TimeCode.Default(), p = (a, i) => t.warnings.push({
|
|
518
|
+
code: "USD_VISUAL_TOPOLOGY_UNSUPPORTED",
|
|
519
|
+
source: "usd-visual",
|
|
520
|
+
message: `USD ${a} 的部分视觉拓扑未能安全补齐,未确认部分保留 Loader 输出:${String(i)}`
|
|
521
|
+
}), o = (a, i) => {
|
|
522
|
+
const c = a.GetAttribute(i);
|
|
523
|
+
try {
|
|
524
|
+
return c.IsValid() ? c.Get(f) : null;
|
|
525
|
+
} finally {
|
|
526
|
+
c.delete();
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
try {
|
|
530
|
+
for (const a of e.data.elements) {
|
|
531
|
+
const i = e.index.objectsByPath.get(a.path);
|
|
532
|
+
if (!(i instanceof te)) continue;
|
|
533
|
+
const c = new d.Sdf.Path(a.path), m = s.GetPrimAtPath(c);
|
|
534
|
+
let y = [];
|
|
535
|
+
try {
|
|
536
|
+
if (m.GetTypeName() !== "Mesh") continue;
|
|
537
|
+
y = m.GetChildren();
|
|
538
|
+
const u = y.filter((x) => x.GetTypeName() === "GeomSubset" && o(x, "familyName") === "materialBind"), l = m.GetAttribute("primvars:st");
|
|
539
|
+
let _ = null, g = null;
|
|
540
|
+
try {
|
|
541
|
+
n(a.material) && l.IsValid() && l.GetMetadata("interpolation") === "faceVarying" && (g = o(m, "primvars:st:indices"), g && (_ = l.Get(f)));
|
|
542
|
+
} finally {
|
|
543
|
+
l.delete();
|
|
544
|
+
}
|
|
545
|
+
const h = u.length > 0 && !Array.isArray(i.material) && i.geometry.groups.length === 0;
|
|
546
|
+
if (!_ && !h) continue;
|
|
547
|
+
const S = o(m, "faceVertexCounts"), U = o(m, "faceVertexIndices");
|
|
548
|
+
if (!S || !U || i.geometry.index) throw new Error("Authored face topology unavailable");
|
|
549
|
+
const P = yn(
|
|
550
|
+
S,
|
|
551
|
+
U,
|
|
552
|
+
a.geometry.pointIndices ?? [],
|
|
553
|
+
o(m, "holeIndices") ?? [],
|
|
554
|
+
o(m, "orientation") === "leftHanded"
|
|
555
|
+
);
|
|
556
|
+
if (i.geometry.getAttribute("position").count !== P.corners.length)
|
|
557
|
+
throw new Error("Loader geometry corner count mismatch");
|
|
558
|
+
if (_ && g) {
|
|
559
|
+
const x = gn(_, g, U.length), R = P.corners.flatMap((v) => [x[v * 2], x[v * 2 + 1]]), C = i.geometry.getAttribute("uv");
|
|
560
|
+
(!C || C.array.length !== R.length || R.some((v, F) => Math.abs(v - C.array[F]) > 1e-6)) && (i.geometry.setAttribute("uv", new At(R, 2)), a.geometry.uvs = R);
|
|
561
|
+
}
|
|
562
|
+
if (!h) continue;
|
|
563
|
+
const A = u.map((x) => {
|
|
564
|
+
if (o(x, "elementType") !== "face") throw new Error("Non-face material subset");
|
|
565
|
+
const R = d.UsdShade.ComputeBoundMaterialPath(x), C = (R == null ? void 0 : R.resolvedTargetPath) || (R == null ? void 0 : R.materialPath);
|
|
566
|
+
if (!C || !e.index.materialsByPath.has(C)) throw new Error("Unresolved subset material");
|
|
567
|
+
const v = o(x, "indices");
|
|
568
|
+
if (!Array.isArray(v)) throw new Error("Missing subset face indices");
|
|
569
|
+
return { materialPath: C, faces: v };
|
|
570
|
+
}), E = [...new Set(A.map((x) => x.materialPath))], M = _n(S.length, A.map((x) => ({ faces: x.faces, slot: E.indexOf(x.materialPath) + 1 }))), T = P.faces.map((x) => M[x]), w = [i.material];
|
|
571
|
+
try {
|
|
572
|
+
for (const x of E) w.push(r(a, x));
|
|
573
|
+
} catch (x) {
|
|
574
|
+
for (const R of w.slice(1)) R.dispose();
|
|
575
|
+
throw x;
|
|
576
|
+
}
|
|
577
|
+
i.material = w;
|
|
578
|
+
for (let x = 0; x < T.length; ) {
|
|
579
|
+
let R = x + 1;
|
|
580
|
+
for (; R < T.length && T[R] === T[x]; ) R++;
|
|
581
|
+
i.geometry.addGroup(x * 3, (R - x) * 3, T[x]), x = R;
|
|
582
|
+
}
|
|
583
|
+
} catch (u) {
|
|
584
|
+
p(a.path, u);
|
|
585
|
+
} finally {
|
|
586
|
+
for (const u of y) u.delete();
|
|
587
|
+
m.delete(), c.delete();
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
} finally {
|
|
591
|
+
f.delete();
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const Sn = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "webp", "avif", "gif", "bmp"]), Ne = /^(?:UsdPreviewSurface|ND_UsdPreviewSurface_surfaceshader)$/i, bn = /(?:standard.?surface|principled|openpbr|adobe.?standard.?material)/i;
|
|
595
|
+
async function Un(e, t) {
|
|
596
|
+
var o;
|
|
597
|
+
nt(e.scene);
|
|
598
|
+
const n = /* @__PURE__ */ new Set();
|
|
599
|
+
for (const a of e.data.materials) {
|
|
600
|
+
const i = hn(e, a);
|
|
601
|
+
i && (a.shaders = i.shaders, e.index.materialsByPath.set(a.path, a), n.add(a.path));
|
|
602
|
+
}
|
|
603
|
+
const r = (a, i) => {
|
|
604
|
+
const c = e.data.view.prims.find((_) => _.path === a.path);
|
|
605
|
+
if (!c) throw new Error(`Missing view prim: ${a.path}`);
|
|
606
|
+
const m = e.index.materialsByPath.get(i), y = Be(m), u = kt({
|
|
607
|
+
...e.data,
|
|
608
|
+
elements: [{ ...a, material: i }],
|
|
609
|
+
view: { ...e.data.view, prims: [{ ...c, parentPath: null }] },
|
|
610
|
+
animations: [],
|
|
611
|
+
lights: [],
|
|
612
|
+
skels: { ...e.data.skels, bindings: [], skeletons: [], animations: [] }
|
|
613
|
+
}, {
|
|
614
|
+
convertZUp: !1,
|
|
615
|
+
loadLights: !1,
|
|
616
|
+
loadTextures: !y,
|
|
617
|
+
sourcePath: t.sourcePath,
|
|
618
|
+
textureResolver: (_) => {
|
|
619
|
+
for (const g of [_.resolvedPath, _.path, _.url]) {
|
|
620
|
+
if (!g) continue;
|
|
621
|
+
const h = t.files.objectUrlIfPresent(g, t.entryDirectory ?? "");
|
|
622
|
+
if (h) return h;
|
|
623
|
+
}
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
nt(u.scene);
|
|
628
|
+
const l = u.index.objectsByPath.get(a.path);
|
|
629
|
+
if (l.geometry.dispose(), Array.isArray(l.material)) throw new Error("Unexpected scratch material array");
|
|
630
|
+
return l.material;
|
|
631
|
+
}, s = /* @__PURE__ */ new Set();
|
|
632
|
+
for (const a of e.data.elements) {
|
|
633
|
+
const i = e.index.objectsByPath.get(a.path);
|
|
634
|
+
if (!(i instanceof te)) continue;
|
|
635
|
+
const c = (m) => {
|
|
636
|
+
const y = he(m.userData.usdMaterialPath);
|
|
637
|
+
if (!y || !n.has(y) || m.userData.usdSurfaceShaderId) return m;
|
|
638
|
+
const u = r(a, y), l = `Material ${y} has no supported surface shader.`;
|
|
639
|
+
return u.userData.usdInstanceResolvedDiagnostics = [l], u.userData.usdMaterialDiagnostics = Se([
|
|
640
|
+
...Ie(m.userData.usdMaterialDiagnostics),
|
|
641
|
+
...Ie(u.userData.usdMaterialDiagnostics)
|
|
642
|
+
]), s.add(m), u;
|
|
643
|
+
};
|
|
644
|
+
if (Array.isArray(i.material)) {
|
|
645
|
+
const m = i.material.map(c);
|
|
646
|
+
m.some((y, u) => y !== i.material[u]) && (i.material = m);
|
|
647
|
+
} else i.material = c(i.material);
|
|
648
|
+
}
|
|
649
|
+
e.scene.traverse((a) => {
|
|
650
|
+
if (a instanceof te) for (const i of Array.isArray(a.material) ? a.material : [a.material]) s.delete(i);
|
|
651
|
+
});
|
|
652
|
+
for (const a of s) a.dispose();
|
|
653
|
+
wn(e, t.diagnostics, (a) => {
|
|
654
|
+
if (!a) return !0;
|
|
655
|
+
const i = e.index.materialsByPath.get(a), c = i && Be(i);
|
|
656
|
+
return !!c && ve(c) && le(c, /* @__PURE__ */ new Set());
|
|
657
|
+
}, r);
|
|
658
|
+
const d = An(e), f = [];
|
|
659
|
+
for (const [a, i] of d) {
|
|
660
|
+
const c = e.index.materialsByPath.get(a);
|
|
661
|
+
if (!c) continue;
|
|
662
|
+
const m = i[0], y = Se(i.flatMap((w) => Ie(w.userData.usdMaterialDiagnostics))), u = he(m.userData.usdSurfaceShaderId);
|
|
663
|
+
if (u && (Ne.test(u) || bn.test(u))) {
|
|
664
|
+
const w = await Pn(c, i, y, t), x = await vn(c, i, t);
|
|
665
|
+
w.applied.push(...x.applied), w.resources.push(...x.resources);
|
|
666
|
+
const R = x.applied.length ? { applied: [], unsupported: [], bounded: !0 } : Ne.test(u) ? xn(e, c, i, t) : En(c, i, t);
|
|
667
|
+
w.applied.push(...R.applied);
|
|
668
|
+
const C = Se(i.flatMap((v) => Ie(v.userData.usdInstanceResolvedDiagnostics)));
|
|
669
|
+
w.resolved.push(...C), C.length && w.applied.push("instance.surface.constants"), f.push({
|
|
670
|
+
materialPath: a,
|
|
671
|
+
sourceShaderId: u,
|
|
672
|
+
action: w.applied.length ? "augmented" : "preserved",
|
|
673
|
+
fidelity: R.bounded || y.some((v) => !w.resolved.includes(v)) ? "bounded-approximation" : "native",
|
|
674
|
+
appliedInputs: w.applied,
|
|
675
|
+
unsupportedNodes: R.unsupported,
|
|
676
|
+
resources: w.resources,
|
|
677
|
+
loaderDiagnostics: y,
|
|
678
|
+
resolvedLoaderDiagnostics: w.resolved
|
|
679
|
+
});
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
const l = Be(c);
|
|
683
|
+
if (!l) {
|
|
684
|
+
const w = st(e, a), x = c.shaders.map((R) => J(R.inputs["info:mdl:sourceAsset"])).filter(ze);
|
|
685
|
+
for (const R of x) t.diagnostics.droppedFeatures.push({ code: "USD_VISUAL_SHADER_NODE_UNSUPPORTED", source: "usd-visual", message: `USD 材质 ${a} 使用尚未支持的 MDL 材质 ${R};保留现有结果,未生成替代内容。` });
|
|
686
|
+
f.push({
|
|
687
|
+
materialPath: a,
|
|
688
|
+
sourceShaderId: x[0] ?? null,
|
|
689
|
+
action: "fallback",
|
|
690
|
+
fidelity: w ? "authored-fallback" : "default-fallback",
|
|
691
|
+
appliedInputs: [],
|
|
692
|
+
unsupportedNodes: Se(c.shaders.map((R) => R.id).filter(ze)),
|
|
693
|
+
resources: [],
|
|
694
|
+
loaderDiagnostics: y
|
|
695
|
+
});
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
if (Xe(l)) {
|
|
699
|
+
const w = Dn(e, i, l), x = w.applied.length ? await Rn(i, l, w, t) : [];
|
|
700
|
+
w.applied.length && x.push(...await Mn(i, l, w, t)), We(t.diagnostics, a, l, w.applied, w.unsupported, x, w.applied.length ? "augmented" : "fallback"), f.push({
|
|
701
|
+
materialPath: a,
|
|
702
|
+
sourceShaderId: "OmniGlass",
|
|
703
|
+
action: w.applied.length ? "augmented" : "fallback",
|
|
704
|
+
fidelity: "bounded-approximation",
|
|
705
|
+
appliedInputs: w.applied,
|
|
706
|
+
unsupportedNodes: [...w.unsupported],
|
|
707
|
+
resources: x,
|
|
708
|
+
loaderDiagnostics: y
|
|
709
|
+
});
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
const _ = [], g = [], h = /* @__PURE__ */ new Set(), S = Tn(i, l, _);
|
|
713
|
+
let U = !1;
|
|
714
|
+
if (ve(l)) {
|
|
715
|
+
const w = J(I(l, ["diffuse_texture"]));
|
|
716
|
+
if (w) {
|
|
717
|
+
const b = await se(w, t);
|
|
718
|
+
if (g.push(b.report), b.url && le(l, h) && i.every((O) => z(O) && !O.map)) {
|
|
719
|
+
let O = null;
|
|
720
|
+
try {
|
|
721
|
+
O = await (t.createTexture ?? ae)(b.url, Qe);
|
|
722
|
+
} catch (D) {
|
|
723
|
+
if (D instanceof Error && D.name === "AbortError") throw D;
|
|
724
|
+
g[g.length - 1] = { path: w, status: "decode-failed" };
|
|
725
|
+
}
|
|
726
|
+
if (O) {
|
|
727
|
+
for (const D of i)
|
|
728
|
+
z(D) && (D.map = O, D.color.set(16777215), D.needsUpdate = !0, U = !0);
|
|
729
|
+
U ? _.push("diffuse_texture") : O.dispose();
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const x = oe(l, ["enable_ORM_texture"], !1);
|
|
734
|
+
if (x) {
|
|
735
|
+
const b = J(I(l, ["ORM_texture"])), O = $(l, ["reflection_roughness_texture_influence"]) ?? 0, D = $(l, ["metallic_texture_influence"]) ?? 0;
|
|
736
|
+
$(l, ["ao_to_diffuse"]);
|
|
737
|
+
const Z = I(l, ["ORM_texture_colorspace"]);
|
|
738
|
+
if (Z !== void 0 && Z !== "raw") h.add("OmniPBR.ORM_texture_colorspace");
|
|
739
|
+
else if (O || D)
|
|
740
|
+
if (!b) h.add("OmniPBR.ORM_texture_missing");
|
|
741
|
+
else {
|
|
742
|
+
const W = await se(b, t);
|
|
743
|
+
if (g.push(W.report), W.url && le(l, h)) {
|
|
744
|
+
let j = null, H = !1;
|
|
745
|
+
try {
|
|
746
|
+
j = await (t.createTexture ?? ae)(W.url, K), j.colorSpace = K, j.wrapS = q, j.wrapT = q;
|
|
747
|
+
const V = [
|
|
748
|
+
{
|
|
749
|
+
slot: "roughnessMap",
|
|
750
|
+
scalar: "roughness",
|
|
751
|
+
channel: "g",
|
|
752
|
+
influence: O,
|
|
753
|
+
constant: $(l, ["reflection_roughness_constant"]) ?? 0.5
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
slot: "metalnessMap",
|
|
757
|
+
scalar: "metalness",
|
|
758
|
+
channel: "b",
|
|
759
|
+
influence: D,
|
|
760
|
+
constant: $(l, ["metallic_constant"]) ?? 0
|
|
761
|
+
}
|
|
762
|
+
];
|
|
763
|
+
for (const L of V) {
|
|
764
|
+
if (!Number.isFinite(L.influence) || L.influence < 0 || L.influence > 1 || L.constant < 0 || L.constant > 1) {
|
|
765
|
+
h.add(`OmniPBR.${L.scalar}_ORM_range`);
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
const ce = i.filter(z).filter((G) => !G[L.slot]);
|
|
769
|
+
if (ce.length) {
|
|
770
|
+
if (L.influence === 0) {
|
|
771
|
+
for (const G of ce) G[L.scalar] = L.constant;
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
try {
|
|
775
|
+
const G = L.influence === 1 ? j : de(
|
|
776
|
+
j,
|
|
777
|
+
L.channel,
|
|
778
|
+
L.influence,
|
|
779
|
+
L.constant * (1 - L.influence)
|
|
780
|
+
);
|
|
781
|
+
for (const X of ce)
|
|
782
|
+
X[L.slot] = G, X[L.scalar] = 1, X.needsUpdate = !0;
|
|
783
|
+
G === j && (H = !0), _.push(`${L.scalar}.ORM.${L.channel}`, `ORM.${L.scalar}.influence=${L.influence}`), U = !0;
|
|
784
|
+
} catch {
|
|
785
|
+
h.add(`OmniPBR.${L.scalar}_ORM_conversion`);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
U && _.push("ORM_texture");
|
|
790
|
+
} catch (V) {
|
|
791
|
+
if (V instanceof Error && V.name === "AbortError") throw V;
|
|
792
|
+
g[g.length - 1] = { path: b, status: "decode-failed" };
|
|
793
|
+
} finally {
|
|
794
|
+
H || j == null || j.dispose();
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (!x && le(l, h))
|
|
800
|
+
for (const b of [
|
|
801
|
+
{ file: "reflectionroughness_texture", weight: "reflection_roughness_texture_influence", constant: "reflection_roughness_constant", fallback: 0.5, map: "roughnessMap", scalar: "roughness" },
|
|
802
|
+
{ file: "metallic_texture", weight: "metallic_texture_influence", constant: "metallic_constant", fallback: 0, map: "metalnessMap", scalar: "metalness" }
|
|
803
|
+
]) {
|
|
804
|
+
const O = $(l, [b.weight]) ?? 0;
|
|
805
|
+
if (O === 0) continue;
|
|
806
|
+
if (O < 0 || O > 1) {
|
|
807
|
+
h.add(`OmniPBR.${b.weight}`);
|
|
808
|
+
continue;
|
|
809
|
+
}
|
|
810
|
+
const D = J(I(l, [b.file]));
|
|
811
|
+
if (!D) continue;
|
|
812
|
+
const Z = I(l, [`${b.file}_colorspace`]);
|
|
813
|
+
if (Z !== void 0 && Z !== "raw") {
|
|
814
|
+
h.add(`OmniPBR.${b.file}_colorspace`);
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
const W = await se(D, t);
|
|
818
|
+
g.push(W.report);
|
|
819
|
+
const j = i.filter(z).filter((V) => !V[b.map]);
|
|
820
|
+
if (!W.url || !j.length) continue;
|
|
821
|
+
let H = null;
|
|
822
|
+
try {
|
|
823
|
+
H = await (t.createTexture ?? ae)(W.url, K);
|
|
824
|
+
const V = $(l, [b.constant]) ?? b.fallback, L = de(H, "grayscale", O, V * (1 - O));
|
|
825
|
+
L.wrapS = q, L.wrapT = q;
|
|
826
|
+
for (const ce of j)
|
|
827
|
+
ce[b.map] = L, ce[b.scalar] = 1, ce.needsUpdate = !0;
|
|
828
|
+
_.push(b.file), U = !0;
|
|
829
|
+
} catch (V) {
|
|
830
|
+
if (V instanceof Error && V.name === "AbortError") throw V;
|
|
831
|
+
h.add(`OmniPBR.${b.file}_conversion`);
|
|
832
|
+
} finally {
|
|
833
|
+
H == null || H.dispose();
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
const R = oe(l, ["enable_opacity"], !1), C = $(l, ["opacity_threshold"]) ?? 0;
|
|
837
|
+
if (R && C >= 0 && oe(l, ["enable_opacity_texture"], !1) && le(l, h)) {
|
|
838
|
+
const b = J(I(l, ["opacity_texture"])), O = I(l, ["opacity_mode"]) ?? 1, D = O === 0 || O === "mono_alpha" ? "a" : O === 1 || O === "mono_average" ? "average" : O === 3 || O === "mono_maximum" ? "maximum" : null, Z = I(l, ["opacity_texture_colorspace"]);
|
|
839
|
+
if (Z !== void 0 && Z !== "raw") h.add("OmniPBR.opacity_texture_colorspace");
|
|
840
|
+
else if (!D) h.add("OmniPBR.opacity_mode");
|
|
841
|
+
else if (!b) h.add("OmniPBR.opacity_texture_missing");
|
|
842
|
+
else {
|
|
843
|
+
const W = await se(b, t);
|
|
844
|
+
g.push(W.report);
|
|
845
|
+
const j = i.filter(z).filter((V) => !V.alphaMap);
|
|
846
|
+
let H = null;
|
|
847
|
+
if (W.url && j.length) try {
|
|
848
|
+
H = await (t.createTexture ?? ae)(W.url, K);
|
|
849
|
+
const V = de(H, D);
|
|
850
|
+
V.wrapS = q, V.wrapT = q;
|
|
851
|
+
for (const L of j)
|
|
852
|
+
L.alphaMap = V, L.opacity = 1, L.alphaTest = Math.max(0, C), L.transparent = C === 0, L.depthWrite = C > 0, L.needsUpdate = !0;
|
|
853
|
+
_.push("opacity_texture"), U = !0;
|
|
854
|
+
} catch (V) {
|
|
855
|
+
if (V instanceof Error && V.name === "AbortError") throw V;
|
|
856
|
+
g[g.length - 1] = { path: b, status: "decode-failed" };
|
|
857
|
+
} finally {
|
|
858
|
+
H == null || H.dispose();
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
const F = $e(l, ["diffuse_tint"]);
|
|
863
|
+
if (F) {
|
|
864
|
+
for (const b of i)
|
|
865
|
+
z(b) && (b.map ? b.color.copy(F) : b.color.copy($e(l, ["diffuse_color_constant"]) ?? new ut(0.2, 0.2, 0.2)).multiply(F), b.needsUpdate = !0);
|
|
866
|
+
_.push("diffuse_tint"), U = !0;
|
|
867
|
+
}
|
|
868
|
+
const Y = J(I(l, ["normalmap_texture"]));
|
|
869
|
+
if (Y) {
|
|
870
|
+
const b = await se(Y, t);
|
|
871
|
+
g.push(b.report);
|
|
872
|
+
const O = I(l, ["normalmap_texture_colorspace"]), D = $(l, ["bump_factor"]) ?? 1;
|
|
873
|
+
if (O !== void 0 && O !== "raw") h.add("OmniPBR.normalmap_texture_colorspace");
|
|
874
|
+
else if (!Number.isFinite(D) || D < 0) h.add("OmniPBR.bump_factor");
|
|
875
|
+
else if (b.url && le(l, h)) {
|
|
876
|
+
const Z = i.filter(z).filter((W) => !W.normalMap);
|
|
877
|
+
if (Z.length)
|
|
878
|
+
try {
|
|
879
|
+
const W = await (t.createTexture ?? ae)(b.url, K);
|
|
880
|
+
W.colorSpace = K, W.wrapS = q, W.wrapT = q;
|
|
881
|
+
for (const j of Z)
|
|
882
|
+
j.normalMap = W, j.normalScale.set(
|
|
883
|
+
D * (oe(l, ["flip_tangent_u"], !1) ? -1 : 1),
|
|
884
|
+
D * (oe(l, ["flip_tangent_v"], !0) ? -1 : 1)
|
|
885
|
+
), j.needsUpdate = !0;
|
|
886
|
+
_.push("normalmap_texture", "normal.tangent_convention"), U = !0;
|
|
887
|
+
} catch (W) {
|
|
888
|
+
if (W instanceof Error && W.name === "AbortError") throw W;
|
|
889
|
+
g[g.length - 1] = { path: Y, status: "decode-failed" };
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
On(l, h), U = await In(i, l, _, h, g, t) || U;
|
|
894
|
+
}
|
|
895
|
+
const P = k(l, "diffuseColor") ?? k(l, "baseColor");
|
|
896
|
+
let A = !1;
|
|
897
|
+
if (P) {
|
|
898
|
+
const w = me(c, P);
|
|
899
|
+
if (w && _t(w)) {
|
|
900
|
+
const x = $n(w);
|
|
901
|
+
if (x) {
|
|
902
|
+
const R = await se(x.path, t);
|
|
903
|
+
g.push(R.report);
|
|
904
|
+
const C = k(w, "manifold");
|
|
905
|
+
C && h.add(((o = me(c, C)) == null ? void 0 : o.id) ?? C.path);
|
|
906
|
+
const v = Object.keys(w.inputs).filter((b) => !["inputs:filename", "inputs:resultRGB", "inputs:linearize"].includes(b)), F = w.inputs["inputs:linearize"], Y = F === 0 || F === 1;
|
|
907
|
+
if (Y || h.add("PxrTexture.colorSpace"), v.length > 0 && !C && h.add("PxrTexture.controls"), R.url && !C && v.length === 0 && Y && P.outputName === "resultRGB" && i.every((b) => z(b) && !b.map)) {
|
|
908
|
+
let b = null;
|
|
909
|
+
try {
|
|
910
|
+
b = await (t.createTexture ?? ae)(R.url, F === 1 ? Qe : K);
|
|
911
|
+
} catch (O) {
|
|
912
|
+
if (O instanceof Error && O.name === "AbortError") throw O;
|
|
913
|
+
g[g.length - 1] = { path: x.path, status: "decode-failed" };
|
|
914
|
+
}
|
|
915
|
+
if (b) {
|
|
916
|
+
for (const O of i)
|
|
917
|
+
z(O) && (O.map = b, O.color.set(16777215), O.needsUpdate = !0, A = !0);
|
|
918
|
+
A ? _.push("diffuseColor.texture") : b.dispose();
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
} else
|
|
922
|
+
h.add(w.id ?? w.path);
|
|
923
|
+
} else w ? h.add(w.id ?? w.path) : h.add(P.path);
|
|
924
|
+
}
|
|
925
|
+
Nn(c, l, h);
|
|
926
|
+
const E = S || A || U ? "augmented" : "fallback", M = st(e, a), T = E === "augmented" ? "bounded-approximation" : M ? "authored-fallback" : "default-fallback";
|
|
927
|
+
We(t.diagnostics, a, l, _, h, g, E), f.push({
|
|
928
|
+
materialPath: a,
|
|
929
|
+
sourceShaderId: gt(l),
|
|
930
|
+
action: E,
|
|
931
|
+
fidelity: T,
|
|
932
|
+
appliedInputs: Se(_),
|
|
933
|
+
unsupportedNodes: [...h],
|
|
934
|
+
resources: g,
|
|
935
|
+
loaderDiagnostics: y
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
mn(e);
|
|
939
|
+
const p = f.filter((a) => a.loaderDiagnostics.some(
|
|
940
|
+
(i) => {
|
|
941
|
+
var c;
|
|
942
|
+
return !((c = a.resolvedLoaderDiagnostics) != null && c.includes(i)) && !(a.action === "augmented" && i === `Material ${a.materialPath} has no supported surface shader.`);
|
|
943
|
+
}
|
|
944
|
+
));
|
|
945
|
+
return p.length > 0 && t.diagnostics.droppedFeatures.push({
|
|
946
|
+
code: "USD_VISUAL_LOADER_DIAGNOSTIC",
|
|
947
|
+
message: `${p.length} 个 USD 材质仍有尚未被视觉适配层消解的 Loader 限制;具体材质和原始诊断见 visualAdaptation 报告。`,
|
|
948
|
+
source: "usd-visual"
|
|
949
|
+
}), Object.freeze({
|
|
950
|
+
schemaVersion: 1,
|
|
951
|
+
materials: f,
|
|
952
|
+
summary: Object.freeze({
|
|
953
|
+
preserved: f.filter((a) => a.action === "preserved").length,
|
|
954
|
+
augmented: f.filter((a) => a.action === "augmented").length,
|
|
955
|
+
fallback: f.filter((a) => a.action === "fallback").length,
|
|
956
|
+
missingResources: f.flatMap((a) => a.resources).filter((a) => a.status === "missing").length,
|
|
957
|
+
unsupportedResources: f.flatMap((a) => a.resources).filter((a) => a.status === "unsupported-format").length
|
|
958
|
+
})
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
function nt(e) {
|
|
962
|
+
e == null || e.traverse((t) => {
|
|
963
|
+
if (!(t instanceof te)) return;
|
|
964
|
+
const n = Array.isArray(t.material) ? t.material : [t.material];
|
|
965
|
+
for (const r of n)
|
|
966
|
+
for (const s of ["map", "normalMap", "roughnessMap", "metalnessMap", "aoMap", "emissiveMap", "alphaMap", "bumpMap", "displacementMap", "clearcoatMap", "clearcoatNormalMap", "clearcoatRoughnessMap", "iridescenceMap", "iridescenceThicknessMap", "specularColorMap", "specularIntensityMap", "transmissionMap", "thicknessMap", "sheenColorMap", "sheenRoughnessMap"]) {
|
|
967
|
+
const d = r[s];
|
|
968
|
+
d instanceof lt && (d.matrix.identity(), d.matrixAutoUpdate = !1, d.needsUpdate = !0);
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
function xn(e, t, n, r) {
|
|
973
|
+
var y;
|
|
974
|
+
const s = { applied: [], unsupported: [], bounded: !1 }, d = he((y = n[0]) == null ? void 0 : y.userData.usdSurfaceShaderPath), f = t.shaders.filter((u) => Ne.test(u.id ?? "")), p = d ? f.find((u) => u.path === d) : f.length === 1 ? f[0] : void 0;
|
|
975
|
+
if (!p) return s;
|
|
976
|
+
const o = $(p, ["opacity"]), a = I(p, ["opacityMode"]) ?? "transparent", i = $(p, ["opacityThreshold"]) ?? 0, c = (u) => (s.bounded = !0, s.unsupported.push(u), r.diagnostics.droppedFeatures.push({
|
|
977
|
+
code: "USD_VISUAL_PREVIEW_TRANSPARENCY_UNSUPPORTED",
|
|
978
|
+
source: "usd-visual",
|
|
979
|
+
message: `USD 材质 ${t.path} 的 ${u} 未完成透明适配,保留 Loader 输出;未生成替代内容。`
|
|
980
|
+
}), s);
|
|
981
|
+
if (k(p, "opacity") || k(p, "opacityThreshold") || k(p, "opacityMode")) return c("connected opacity/threshold/mode");
|
|
982
|
+
if (i > 0 || a === "presence") {
|
|
983
|
+
if (n.some((l) => !z(l) || l.alphaMap || l.map)) return c("textured coverage/cutout");
|
|
984
|
+
const u = xe(o ?? 1);
|
|
985
|
+
for (const l of n)
|
|
986
|
+
l.opacity = i > 0 ? u >= i ? 1 : 0 : u, l.alphaTest = i > 0 ? 0.5 : 0, l.transparent = i === 0 && u < 1, l.depthWrite = !l.transparent, l instanceof ie && (l.transmission = 0), l.needsUpdate = !0;
|
|
987
|
+
return s.applied.push(i > 0 ? "PreviewSurface.cutout.constant" : "PreviewSurface.presence.constant"), s;
|
|
988
|
+
}
|
|
989
|
+
if (a !== "transparent") return c(`opacityMode=${String(a)}`);
|
|
990
|
+
if (o === null || o >= 1) return s;
|
|
991
|
+
if (!k(p, "metallic") && $(p, ["metallic"]) === 1 && !k(p, "useSpecularWorkflow") && [void 0, !1, 0].includes(I(p, ["useSpecularWorkflow"]))) {
|
|
992
|
+
if (n.some((u) => !z(u) || u.alphaMap || u.map || u.metalnessMap || u.alphaTest > 0)) return c("textured metal transparency");
|
|
993
|
+
for (const u of n)
|
|
994
|
+
z(u) && (u.opacity = 1, u.transparent = !1, u.depthWrite = !0, u.metalness = 1, u instanceof ie && (u.transmission = 0), u.needsUpdate = !0);
|
|
995
|
+
return s.applied.push("PreviewSurface.transparent.pure-metal"), s;
|
|
996
|
+
}
|
|
997
|
+
if (k(p, "metallic") || k(p, "useSpecularWorkflow") || k(p, "ior") || ($(p, ["metallic"]) ?? 0) !== 0 || ![void 0, !1, 0].includes(I(p, ["useSpecularWorkflow"]))) return c("non-dielectric or connected transparency");
|
|
998
|
+
if (n.some((u) => !z(u) || u.alphaMap || u.map || u.metalnessMap || u.alphaTest > 0)) return c("textured or non-standard transparency");
|
|
999
|
+
const m = /* @__PURE__ */ new Map();
|
|
1000
|
+
for (const u of n) {
|
|
1001
|
+
if (!z(u)) continue;
|
|
1002
|
+
const l = u instanceof ie ? u : new ie();
|
|
1003
|
+
l !== u && (He.prototype.copy.call(l, u), l.defines = { STANDARD: "", PHYSICAL: "" }, m.set(u, l)), l.opacity = 1, l.transparent = !1, l.transmission = 1 - xe(o), l.ior = $(p, ["ior"]) ?? 1.5, l.depthWrite = !0, l.needsUpdate = !0;
|
|
1004
|
+
}
|
|
1005
|
+
if (m.size) {
|
|
1006
|
+
e.scene.traverse((u) => {
|
|
1007
|
+
u instanceof te && (u.material = Array.isArray(u.material) ? u.material.map((l) => m.get(l) ?? l) : m.get(u.material) ?? u.material);
|
|
1008
|
+
}), n.forEach((u, l) => {
|
|
1009
|
+
n[l] = m.get(u) ?? u;
|
|
1010
|
+
});
|
|
1011
|
+
for (const u of m.keys()) u.dispose();
|
|
1012
|
+
}
|
|
1013
|
+
return s.applied.push("PreviewSurface.transparent.constant-dielectric"), s.bounded = !0, r.diagnostics.approximations.push({
|
|
1014
|
+
code: "USD_VISUAL_PREVIEW_TRANSMISSION_APPROXIMATION",
|
|
1015
|
+
source: "usd-visual",
|
|
1016
|
+
message: `USD 材质 ${t.path} 的常量介质透明已映射为实时透射;保留表面反射;Three.js 透射与反射共用粗糙度,不等同于 PreviewSurface 的零粗糙度透射。不推断壁厚或体积吸收,不保证多层折射与路径追踪等价。`
|
|
1017
|
+
}), s;
|
|
1018
|
+
}
|
|
1019
|
+
function En(e, t, n) {
|
|
1020
|
+
var i;
|
|
1021
|
+
const r = { applied: [], unsupported: [], bounded: !1 }, s = he((i = t[0]) == null ? void 0 : i.userData.usdSurfaceShaderPath), d = e.shaders.filter((c) => c.id === "ND_standard_surface_surfaceshader"), f = s ? d.find((c) => c.path === s) : d.length === 1 ? d[0] : void 0;
|
|
1022
|
+
if (!f) return r;
|
|
1023
|
+
const p = (c) => {
|
|
1024
|
+
r.bounded = !0, r.unsupported.push(c), n.diagnostics.droppedFeatures.push({
|
|
1025
|
+
code: "USD_VISUAL_MATERIALX_TRANSPARENCY_UNSUPPORTED",
|
|
1026
|
+
source: "usd-visual",
|
|
1027
|
+
message: `USD 材质 ${e.path} 的 MaterialX ${c} 尚未完整适配;不猜测厚度或生成替代内容。`
|
|
1028
|
+
});
|
|
1029
|
+
}, o = I(f, ["opacity"]);
|
|
1030
|
+
if (k(f, "opacity")) p("connected opacity");
|
|
1031
|
+
else if (Array.isArray(o) && o.length === 3 && o.every((c) => typeof c == "number" && Number.isFinite(c)))
|
|
1032
|
+
if (o[0] !== o[1] || o[1] !== o[2]) p("colored opacity");
|
|
1033
|
+
else if (t.some((c) => !z(c) || c.alphaMap || c.map)) p("textured coverage");
|
|
1034
|
+
else {
|
|
1035
|
+
const c = xe(o[0]);
|
|
1036
|
+
for (const m of t)
|
|
1037
|
+
m.opacity = c, m.transparent = c < 1, m.depthWrite = c === 1, m.needsUpdate = !0;
|
|
1038
|
+
r.applied.push("MaterialX.opacity.achromatic-constant");
|
|
1039
|
+
}
|
|
1040
|
+
const a = $(f, ["transmission"]) ?? 0;
|
|
1041
|
+
return k(f, "transmission") && p("connected transmission"), a > 0 && (r.bounded = !0, Array.isArray(o) && o.some((c) => typeof c == "number" && c > 0 && c < 1) && p("fractional coverage + transmission compositing"), oe(f, ["thin_walled"], !1) ? n.diagnostics.approximations.push({
|
|
1042
|
+
code: "USD_VISUAL_MATERIALX_TRANSMISSION_APPROXIMATION",
|
|
1043
|
+
source: "usd-visual",
|
|
1044
|
+
message: `USD 材质 ${e.path} 的 MaterialX 薄壁透射使用 Loader 的实时近似;并非完整 MaterialX 着色器执行。`
|
|
1045
|
+
}) : p("solid transmission / absorption path length")), r;
|
|
1046
|
+
}
|
|
1047
|
+
async function vn(e, t, n) {
|
|
1048
|
+
var E;
|
|
1049
|
+
const r = { applied: [], resources: [] }, s = he((E = t[0]) == null ? void 0 : E.userData.usdSurfaceShaderPath), d = e.shaders.filter((M) => Ne.test(M.id ?? "")), f = s ? d.find((M) => M.path === s) : d.length === 1 ? d[0] : void 0;
|
|
1050
|
+
if (!f || k(f, "opacityThreshold") || k(f, "opacityMode")) return r;
|
|
1051
|
+
const p = $(f, ["opacityThreshold"]) ?? 0;
|
|
1052
|
+
if (p <= 0 && I(f, ["opacityMode"]) !== "presence") return r;
|
|
1053
|
+
const o = k(f, "opacity");
|
|
1054
|
+
if (!(o != null && o.outputName) || !["r", "g", "b", "a"].includes(o.outputName)) return r;
|
|
1055
|
+
const a = me(e, o);
|
|
1056
|
+
if (!a || a.id !== "UsdUVTexture" || I(a, ["sourceColorSpace"]) !== "raw") return r;
|
|
1057
|
+
const i = k(a, "st"), c = i && me(e, i);
|
|
1058
|
+
if (!c || c.id !== "UsdPrimvarReader_float2" || I(c, ["varname"]) !== "st" || t.some((M) => !z(M) || M.map)) return r;
|
|
1059
|
+
const m = "rgba".indexOf(o.outputName), y = (M, T) => {
|
|
1060
|
+
if (k(a, M)) return null;
|
|
1061
|
+
const w = a.inputs[`inputs:${M}`];
|
|
1062
|
+
return w === void 0 ? T : Array.isArray(w) && w.length === 4 && w.every(Number.isFinite) ? w[m] : null;
|
|
1063
|
+
}, u = y("scale", 1), l = y("bias", 0);
|
|
1064
|
+
if (u === null || l === null) return r;
|
|
1065
|
+
const _ = (M) => {
|
|
1066
|
+
const T = I(a, [M]);
|
|
1067
|
+
return T === "repeat" ? q : T === "mirror" ? ft : T === "clamp" ? dt : null;
|
|
1068
|
+
}, g = _("wrapS"), h = _("wrapT"), S = J(I(a, ["file"]));
|
|
1069
|
+
if (!S || g === null || h === null) return r;
|
|
1070
|
+
const U = JSON.stringify([a.path, o.outputName, u, l, g, h, p]);
|
|
1071
|
+
if (t.every((M) => {
|
|
1072
|
+
var T;
|
|
1073
|
+
return z(M) && ((T = M.alphaMap) == null ? void 0 : T.userData.usdCoverageConversionKey) === U;
|
|
1074
|
+
}))
|
|
1075
|
+
return r.applied.push(`PreviewSurface.opacity.texture.${o.outputName}->g`), r.resources.push({ path: S, status: "available" }), r;
|
|
1076
|
+
const P = await se(S, n);
|
|
1077
|
+
r.resources.push(P.report);
|
|
1078
|
+
let A = null;
|
|
1079
|
+
try {
|
|
1080
|
+
if (!P.url) return r;
|
|
1081
|
+
A = await (n.createTexture ?? ae)(P.url, K);
|
|
1082
|
+
const M = de(A, o.outputName, u, l);
|
|
1083
|
+
M.wrapS = g, M.wrapT = h, M.userData.usdCoverageConversionKey = U;
|
|
1084
|
+
for (const T of t)
|
|
1085
|
+
z(T) && (T.alphaMap = M, T.opacity = 1, T.alphaTest = p > 0 ? p : 0, T.transparent = p <= 0, T.depthWrite = p > 0, T instanceof ie && (T.transmission = 0), T.needsUpdate = !0);
|
|
1086
|
+
r.applied.push(`PreviewSurface.opacity.texture.${o.outputName}->g`), n.diagnostics.approximations.push({
|
|
1087
|
+
code: "USD_VISUAL_COVERAGE_TEXTURE_APPROXIMATION",
|
|
1088
|
+
source: "usd-visual",
|
|
1089
|
+
message: `USD 材质 ${e.path} 的透明遮罩已按源通道转换;采用 8 位纹理重排,阈值边缘与过滤结果不保证跨渲染器逐像素一致。`
|
|
1090
|
+
});
|
|
1091
|
+
} catch (M) {
|
|
1092
|
+
if (M instanceof Error && M.name === "AbortError") throw M;
|
|
1093
|
+
r.resources[0] = { path: S, status: "decode-failed" };
|
|
1094
|
+
} finally {
|
|
1095
|
+
A == null || A.dispose();
|
|
1096
|
+
}
|
|
1097
|
+
return r;
|
|
1098
|
+
}
|
|
1099
|
+
async function Pn(e, t, n, r) {
|
|
1100
|
+
var A;
|
|
1101
|
+
const s = { applied: [], resolved: [], resources: [] }, d = he((A = t[0]) == null ? void 0 : A.userData.usdSurfaceShaderPath), f = e.shaders.find((E) => E.path === d) ?? e.shaders.find((E) => E.id === "UsdPreviewSurface");
|
|
1102
|
+
if (!f || f.id !== "UsdPreviewSurface") return s;
|
|
1103
|
+
const p = k(f, "roughness");
|
|
1104
|
+
if (!p || !p.outputName || !["r", "g", "b", "a"].includes(p.outputName)) return s;
|
|
1105
|
+
const o = me(e, p);
|
|
1106
|
+
if (!o || o.id !== "UsdUVTexture") return s;
|
|
1107
|
+
const a = `Texture output ${p.outputName} from ${o.path} cannot be mapped to Three.js roughness without channel repacking.`;
|
|
1108
|
+
if (!n.includes(a) || I(o, ["sourceColorSpace"]) !== "raw") return s;
|
|
1109
|
+
const i = k(o, "st");
|
|
1110
|
+
if (i) {
|
|
1111
|
+
const E = me(e, i);
|
|
1112
|
+
if ((E == null ? void 0 : E.id) !== "UsdPrimvarReader_float2" || I(E, ["varname"]) !== "st") return s;
|
|
1113
|
+
} else if (o.inputs["inputs:st"] !== void 0) return s;
|
|
1114
|
+
const c = "rgba".indexOf(p.outputName);
|
|
1115
|
+
function m(E, M) {
|
|
1116
|
+
if (k(o, E)) return null;
|
|
1117
|
+
const T = o.inputs[`inputs:${E}`];
|
|
1118
|
+
return T === void 0 ? M : Array.isArray(T) && T.length === 4 && T.every(Number.isFinite) ? T[c] : null;
|
|
1119
|
+
}
|
|
1120
|
+
const y = m("scale", 1), u = m("bias", 0);
|
|
1121
|
+
if (y === null || u === null) return s;
|
|
1122
|
+
function l(E) {
|
|
1123
|
+
if (k(o, E)) return null;
|
|
1124
|
+
const M = o.inputs[`inputs:${E}`];
|
|
1125
|
+
return M === "repeat" ? q : M === "mirror" ? ft : M === "clamp" ? dt : null;
|
|
1126
|
+
}
|
|
1127
|
+
const _ = l("wrapS"), g = l("wrapT");
|
|
1128
|
+
if (_ === null || g === null) return s;
|
|
1129
|
+
const h = J(I(o, ["file"]));
|
|
1130
|
+
if (!h) return s;
|
|
1131
|
+
const S = t.filter(z);
|
|
1132
|
+
if (!S.length) return s;
|
|
1133
|
+
if (S.every((E) => {
|
|
1134
|
+
var M;
|
|
1135
|
+
return ((M = E.roughnessMap) == null ? void 0 : M.userData.usdResolvedChannelDiagnostic) === a;
|
|
1136
|
+
}))
|
|
1137
|
+
return s.applied.push(`roughness.texture.${p.outputName}->g`), s.resolved.push(a), s;
|
|
1138
|
+
if (S.some((E) => E.roughnessMap !== null)) return s;
|
|
1139
|
+
const U = await se(h, r);
|
|
1140
|
+
s.resources.push(U.report);
|
|
1141
|
+
let P = null;
|
|
1142
|
+
if (U.url)
|
|
1143
|
+
try {
|
|
1144
|
+
P = await (r.createTexture ?? ae)(U.url, K);
|
|
1145
|
+
const E = de(P, p.outputName, y, u);
|
|
1146
|
+
E.wrapS = _, E.wrapT = g, E.userData.usdResolvedChannelDiagnostic = a;
|
|
1147
|
+
for (const M of S)
|
|
1148
|
+
M.roughnessMap = E, M.roughness = 1, M.needsUpdate = !0;
|
|
1149
|
+
s.applied.push(`roughness.texture.${p.outputName}->g`), s.resolved.push(a);
|
|
1150
|
+
} catch (E) {
|
|
1151
|
+
if (E instanceof Error && E.name === "AbortError") throw E;
|
|
1152
|
+
s.resources[0] = { path: h, status: "decode-failed" };
|
|
1153
|
+
} finally {
|
|
1154
|
+
P == null || P.dispose();
|
|
1155
|
+
}
|
|
1156
|
+
return We(r.diagnostics, e.path, f, [], /* @__PURE__ */ new Set(), s.resources, "preserved"), s;
|
|
1157
|
+
}
|
|
1158
|
+
function An(e) {
|
|
1159
|
+
const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
|
|
1160
|
+
return e.scene.traverse((r) => {
|
|
1161
|
+
if (r instanceof te)
|
|
1162
|
+
for (const s of Array.isArray(r.material) ? r.material : [r.material]) {
|
|
1163
|
+
if (n.has(s)) continue;
|
|
1164
|
+
n.add(s);
|
|
1165
|
+
const d = he(s.userData.usdMaterialPath);
|
|
1166
|
+
if (!d) continue;
|
|
1167
|
+
const f = t.get(d);
|
|
1168
|
+
f ? f.push(s) : t.set(d, [s]);
|
|
1169
|
+
}
|
|
1170
|
+
}), t;
|
|
1171
|
+
}
|
|
1172
|
+
function Be(e) {
|
|
1173
|
+
const t = e.shaders.filter((n) => /^PxrSurface$/i.test(n.id ?? "") || ve(n) || Xe(n));
|
|
1174
|
+
return t.length === 1 ? t[0] : null;
|
|
1175
|
+
}
|
|
1176
|
+
function Xe(e) {
|
|
1177
|
+
var r;
|
|
1178
|
+
const t = J(e.inputs["info:mdl:sourceAsset"]), n = e.inputs["info:mdl:sourceAsset:subIdentifier"];
|
|
1179
|
+
return ((r = t == null ? void 0 : t.replaceAll("\\", "/").split("/").at(-1)) == null ? void 0 : r.toLowerCase()) === "omniglass.mdl" && (n === void 0 || n === "OmniGlass");
|
|
1180
|
+
}
|
|
1181
|
+
function Dn(e, t, n) {
|
|
1182
|
+
const r = { applied: [], unsupported: /* @__PURE__ */ new Set() }, s = /* @__PURE__ */ new Set(["glass_color", "glass_ior", "frosting_roughness", "thin_walled", "reflection_color", "enable_opacity", "cutout_opacity", "opacity_constant", "opacity_threshold"]);
|
|
1183
|
+
for (const [h, S] of Object.entries(n.inputs)) {
|
|
1184
|
+
if (!h.startsWith("inputs:")) continue;
|
|
1185
|
+
const U = h.slice(7);
|
|
1186
|
+
s.has(U) || ["glass_color_texture", "roughness_texture", "normalmap_texture"].includes(U) && !J(S) || r.unsupported.add(`OmniGlass.${U}`);
|
|
1187
|
+
}
|
|
1188
|
+
const d = (h) => (r.unsupported.add(`OmniGlass.${h}`), r);
|
|
1189
|
+
for (const h of s) if (k(n, h)) return d(`${h}.connection`);
|
|
1190
|
+
const f = $(n, ["glass_ior"]) ?? 1.491, p = $(n, ["frosting_roughness"]) ?? 0, o = I(n, ["thin_walled"]) ?? !1, a = I(n, ["glass_color"]) ?? [1, 1, 1], i = I(n, ["reflection_color"]) ?? [1, 1, 1];
|
|
1191
|
+
if (!Array.isArray(i) || i.length !== 3 || !i.every((h) => typeof h == "number" && Number.isFinite(h) && h >= 0 && h <= 1)) return d("reflection_color.range");
|
|
1192
|
+
if (I(n, ["glass_ior"]) !== void 0 && $(n, ["glass_ior"]) === null || f < 1 || f > 2.333) return d("glass_ior.range");
|
|
1193
|
+
if (I(n, ["frosting_roughness"]) !== void 0 && $(n, ["frosting_roughness"]) === null || p < 0 || p > 1) return d("frosting_roughness.range");
|
|
1194
|
+
if (typeof o != "boolean") return d("thin_walled.type");
|
|
1195
|
+
if (!Array.isArray(a) || a.length !== 3 || !a.every((h) => typeof h == "number" && Number.isFinite(h) && h >= 0 && h <= 1)) return d("glass_color.range");
|
|
1196
|
+
if (t.some((h) => !z(h))) return d("non-standard-loader-material");
|
|
1197
|
+
if (t.some((h) => z(h) && (h.map || h.alphaMap || h.roughnessMap || h.metalnessMap))) return d("existing-loader-texture-semantics");
|
|
1198
|
+
o || r.unsupported.add("OmniGlass.solid_volume_absorption"), o && a.some((h) => h !== 1) && r.unsupported.add("OmniGlass.tint_reflection_coupling"), !o && a.some((h) => h !== 1) && r.unsupported.add("OmniGlass.glass_color.volume");
|
|
1199
|
+
const c = I(n, ["enable_opacity"]) ?? !1;
|
|
1200
|
+
if (typeof c != "boolean") return d("enable_opacity.type");
|
|
1201
|
+
const m = $(n, ["cutout_opacity"]), y = $(n, ["opacity_constant"]);
|
|
1202
|
+
if (c && m !== null && y !== null && Math.abs(m - y) > 1e-6) return d("opacity.alias-conflict");
|
|
1203
|
+
for (const h of ["cutout_opacity", "opacity_constant", "opacity_threshold"]) if (c && I(n, [h]) !== void 0 && $(n, [h]) === null) return d(`${h}.type`);
|
|
1204
|
+
const u = c ? m ?? y ?? 1 : 1, l = c ? $(n, ["opacity_threshold"]) ?? 0 : 0;
|
|
1205
|
+
if (u < 0 || u > 1 || l < 0 || l > 1) return d("opacity.range");
|
|
1206
|
+
if (c && (J(I(n, ["opacity_texture"])) || k(n, "opacity_texture"))) return d("opacity_texture");
|
|
1207
|
+
const _ = l > 0 ? u >= l ? 1 : 0 : u, g = /* @__PURE__ */ new Map();
|
|
1208
|
+
for (const h of t) {
|
|
1209
|
+
const S = h instanceof ie ? h : new ie();
|
|
1210
|
+
S !== h && (He.prototype.copy.call(S, h), S.defines = { STANDARD: "", PHYSICAL: "" }, g.set(h, S)), S.color.setRGB(...o ? a : [1, 1, 1]), S.specularColor.setRGB(...i), S.metalness = 0, S.roughness = p, S.ior = f, S.opacity = _, S.transparent = l === 0 && _ < 1, S.alphaTest = l > 0 ? 0.5 : 0, S.transmission = 1, S.thickness = 0, S.depthWrite = !S.transparent, S.attenuationColor.setRGB(1, 1, 1), S.attenuationDistance = 1 / 0, S.needsUpdate = !0;
|
|
1211
|
+
}
|
|
1212
|
+
e.scene.traverse((h) => {
|
|
1213
|
+
h instanceof te && (h.material = Array.isArray(h.material) ? h.material.map((S) => g.get(S) ?? S) : g.get(h.material) ?? h.material);
|
|
1214
|
+
}), t.forEach((h, S) => {
|
|
1215
|
+
t[S] = g.get(h) ?? h;
|
|
1216
|
+
});
|
|
1217
|
+
for (const h of g.keys()) h.dispose();
|
|
1218
|
+
return r.applied.push("OmniGlass.reflection_color.specular-approximation", "OmniGlass.glass_ior", "OmniGlass.frosting_roughness", "OmniGlass.surface_transmission"), c && r.applied.push("OmniGlass.opacity.constant-coverage"), _ > 0 && _ < 1 && r.unsupported.add("OmniGlass.fractional_coverage_transmission_compositing"), o && r.applied.push("OmniGlass.thin_walled", "OmniGlass.glass_color.surface-approximation"), r;
|
|
1219
|
+
}
|
|
1220
|
+
async function Mn(e, t, n, r) {
|
|
1221
|
+
const s = [], d = ["normalmap_texture", "normalmap_texture_colorspace", "bump_factor", "flip_tangent_u", "flip_tangent_v"], f = () => d.forEach((l) => n.unsupported.delete(`OmniGlass.${l}`));
|
|
1222
|
+
if (d.some((l) => k(t, l))) return s;
|
|
1223
|
+
const p = J(I(t, ["normalmap_texture"]));
|
|
1224
|
+
if (!p)
|
|
1225
|
+
return f(), s;
|
|
1226
|
+
const o = $(t, ["bump_factor"]) ?? 1;
|
|
1227
|
+
if (I(t, ["bump_factor"]) !== void 0 && $(t, ["bump_factor"]) === null || o < 0) return s;
|
|
1228
|
+
if (o === 0)
|
|
1229
|
+
return f(), s;
|
|
1230
|
+
const a = I(t, ["flip_tangent_u"]) ?? !1, i = I(t, ["flip_tangent_v"]) ?? !0;
|
|
1231
|
+
if (typeof a != "boolean" || typeof i != "boolean" || I(t, ["normalmap_texture_colorspace"]) !== "raw" || ["project_uvw", "world_or_object", "uv_space_index", "texture_scale", "texture_translate", "texture_rotate"].some((l) => k(t, l)) || !le(t, /* @__PURE__ */ new Set())) return s;
|
|
1232
|
+
const m = e.filter((l) => l instanceof ie);
|
|
1233
|
+
if (!m.length || m.some((l) => l.normalMap))
|
|
1234
|
+
return n.unsupported.add("OmniGlass.existing_normalMap"), s;
|
|
1235
|
+
const y = await se(p, r);
|
|
1236
|
+
if (s.push(y.report), !y.url) return s;
|
|
1237
|
+
let u = null;
|
|
1238
|
+
try {
|
|
1239
|
+
u = await (r.createTexture ?? ae)(y.url, K), u.colorSpace = K, u.wrapS = q, u.wrapT = q, u.channel = 0;
|
|
1240
|
+
for (const l of m)
|
|
1241
|
+
l.normalMap = u, l.normalScale.set(o * (a ? -1 : 1), o * (i ? -1 : 1)), l.needsUpdate = !0;
|
|
1242
|
+
f(), n.applied.push("OmniGlass.normalmap_texture", "OmniGlass.normal.tangent_convention"), u = null;
|
|
1243
|
+
} catch (l) {
|
|
1244
|
+
if (l instanceof Error && l.name === "AbortError") throw l;
|
|
1245
|
+
s[0] = { path: p, status: "decode-failed" };
|
|
1246
|
+
} finally {
|
|
1247
|
+
u == null || u.dispose();
|
|
1248
|
+
}
|
|
1249
|
+
return s;
|
|
1250
|
+
}
|
|
1251
|
+
async function Rn(e, t, n, r) {
|
|
1252
|
+
const s = [], d = J(I(t, ["roughness_texture"]));
|
|
1253
|
+
if (!d) return s;
|
|
1254
|
+
const f = $(t, ["roughness_texture_influence"]) ?? 1;
|
|
1255
|
+
if (k(t, "roughness_texture_influence") || f < 0 || f > 1 || I(t, ["roughness_texture_influence"]) !== void 0 && $(t, ["roughness_texture_influence"]) === null) return s;
|
|
1256
|
+
if (f === 0)
|
|
1257
|
+
return n.unsupported.delete("OmniGlass.roughness_texture"), n.unsupported.delete("OmniGlass.roughness_texture_influence"), s;
|
|
1258
|
+
if (I(t, ["roughness_texture_colorspace"]) !== "raw" || ["project_uvw", "uv_space_index", "texture_scale", "texture_translate", "texture_rotate"].some((c) => k(t, c)) || !le(t, /* @__PURE__ */ new Set())) return s;
|
|
1259
|
+
const a = await se(d, r);
|
|
1260
|
+
if (s.push(a.report), !a.url) return s;
|
|
1261
|
+
let i = null;
|
|
1262
|
+
try {
|
|
1263
|
+
i = await (r.createTexture ?? ae)(a.url, K);
|
|
1264
|
+
const c = $(t, ["frosting_roughness"]) ?? 0, m = de(i, "grayscale", f, c * (1 - f));
|
|
1265
|
+
m.wrapS = q, m.wrapT = q;
|
|
1266
|
+
for (const y of e) y instanceof ie && (y.roughnessMap = m, y.roughness = 1, y.needsUpdate = !0);
|
|
1267
|
+
n.applied.push("OmniGlass.roughness_texture.grayscale-linear-blend");
|
|
1268
|
+
for (const y of ["roughness_texture", "roughness_texture_influence", "roughness_texture_colorspace"]) n.unsupported.delete(`OmniGlass.${y}`);
|
|
1269
|
+
} catch (c) {
|
|
1270
|
+
if (c instanceof Error && c.name === "AbortError") throw c;
|
|
1271
|
+
n.unsupported.add("OmniGlass.roughness_texture.pixel-conversion");
|
|
1272
|
+
} finally {
|
|
1273
|
+
i == null || i.dispose();
|
|
1274
|
+
}
|
|
1275
|
+
return s;
|
|
1276
|
+
}
|
|
1277
|
+
function ve(e) {
|
|
1278
|
+
var n;
|
|
1279
|
+
const t = J(e.inputs["info:mdl:sourceAsset"]);
|
|
1280
|
+
return ((n = t == null ? void 0 : t.replaceAll("\\", "/").split("/").at(-1)) == null ? void 0 : n.toLowerCase()) === "omnipbr.mdl";
|
|
1281
|
+
}
|
|
1282
|
+
function gt(e) {
|
|
1283
|
+
return ve(e) ? "OmniPBR" : Xe(e) ? "OmniGlass" : e.id;
|
|
1284
|
+
}
|
|
1285
|
+
function le(e, t) {
|
|
1286
|
+
const n = rt(e, "texture_scale", [1, 1]), r = rt(e, "texture_translate", [0, 0]), s = $(e, ["texture_rotate"]) ?? 0, d = oe(e, ["project_uvw"], !1), f = $(e, ["uv_space_index"]) ?? 0, p = !d && f === 0 && n[0] === 1 && n[1] === 1 && r[0] === 0 && r[1] === 0 && s === 0;
|
|
1287
|
+
return p || t.add("OmniPBR.uvTransform"), p;
|
|
1288
|
+
}
|
|
1289
|
+
async function In(e, t, n, r, s, d) {
|
|
1290
|
+
const f = () => {
|
|
1291
|
+
for (const y of ["ao_texture", "ao_texture_colorspace", "ao_to_diffuse"]) r.delete(`OmniPBR.${y}`);
|
|
1292
|
+
};
|
|
1293
|
+
if (k(t, "ao_to_diffuse"))
|
|
1294
|
+
return r.add("OmniPBR.ao_to_diffuse.connection"), !1;
|
|
1295
|
+
const p = $(t, ["ao_to_diffuse"]) ?? 0;
|
|
1296
|
+
if (I(t, ["ao_to_diffuse"]) !== void 0 && $(t, ["ao_to_diffuse"]) === null || p < 0 || p > 1)
|
|
1297
|
+
return r.add("OmniPBR.ao_to_diffuse.range"), !1;
|
|
1298
|
+
if (p === 0)
|
|
1299
|
+
return f(), !1;
|
|
1300
|
+
if (k(t, "enable_ORM_texture"))
|
|
1301
|
+
return r.add("OmniPBR.enable_ORM_texture.connection"), !1;
|
|
1302
|
+
const o = oe(t, ["enable_ORM_texture"], !1), a = o ? "ORM_texture" : "ao_texture";
|
|
1303
|
+
if (k(t, a))
|
|
1304
|
+
return r.add(`OmniPBR.${a}.connection`), !1;
|
|
1305
|
+
const i = J(I(t, [a]));
|
|
1306
|
+
if (!i)
|
|
1307
|
+
return f(), !1;
|
|
1308
|
+
if (I(t, [`${a}_colorspace`]) !== "raw")
|
|
1309
|
+
return r.add(`OmniPBR.${a}_colorspace`), !1;
|
|
1310
|
+
if (!le(t, r)) return !1;
|
|
1311
|
+
const c = await se(i, d);
|
|
1312
|
+
if (s.push(c.report), !c.url) return !1;
|
|
1313
|
+
let m = null;
|
|
1314
|
+
try {
|
|
1315
|
+
m = await (d.createTexture ?? ae)(c.url, K);
|
|
1316
|
+
const y = de(m, o ? "r" : "grayscale");
|
|
1317
|
+
y.wrapS = q, y.wrapT = q, y.channel = 0;
|
|
1318
|
+
const u = e.filter(z).filter((l) => !l.aoMap);
|
|
1319
|
+
if (!u.length)
|
|
1320
|
+
return y.dispose(), r.add("OmniPBR.existing_aoMap"), !1;
|
|
1321
|
+
for (const l of u)
|
|
1322
|
+
l.aoMap = y, l.aoMapIntensity = p, l.needsUpdate = !0;
|
|
1323
|
+
return f(), n.push(o ? "OmniPBR.ORM.r.aoMap" : "OmniPBR.ao_texture.aoMap"), d.diagnostics.approximations.push({ code: "USD_VISUAL_AO_LIGHTING_APPROXIMATION", source: "usd-visual", message: `USD 材质 AO 已映射为 Three.js 间接光遮蔽(${t.path});并非 OmniPBR 对漫反射贴图的等价调制。` }), !0;
|
|
1324
|
+
} catch (y) {
|
|
1325
|
+
if (y instanceof Error && y.name === "AbortError") throw y;
|
|
1326
|
+
return r.add(`OmniPBR.${a}.pixel-conversion`), !1;
|
|
1327
|
+
} finally {
|
|
1328
|
+
m == null || m.dispose();
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
function On(e, t) {
|
|
1332
|
+
const n = /* @__PURE__ */ new Set([
|
|
1333
|
+
"inputs:diffuse_color_constant",
|
|
1334
|
+
"inputs:diffuse_texture",
|
|
1335
|
+
"inputs:reflection_roughness_constant",
|
|
1336
|
+
"inputs:metallic_constant",
|
|
1337
|
+
"inputs:opacity_constant",
|
|
1338
|
+
"inputs:enable_opacity",
|
|
1339
|
+
"inputs:enable_emission",
|
|
1340
|
+
"inputs:emissive_color",
|
|
1341
|
+
"inputs:emissive_intensity",
|
|
1342
|
+
"inputs:texture_scale",
|
|
1343
|
+
"inputs:texture_translate",
|
|
1344
|
+
"inputs:texture_rotate",
|
|
1345
|
+
"inputs:project_uvw",
|
|
1346
|
+
"inputs:uv_space_index",
|
|
1347
|
+
"info:mdl:sourceAsset",
|
|
1348
|
+
"inputs:enable_ORM_texture",
|
|
1349
|
+
"inputs:ORM_texture",
|
|
1350
|
+
"inputs:metallic_texture_influence",
|
|
1351
|
+
"inputs:reflection_roughness_texture_influence",
|
|
1352
|
+
"inputs:ao_to_diffuse",
|
|
1353
|
+
"inputs:diffuse_tint",
|
|
1354
|
+
"inputs:normalmap_texture",
|
|
1355
|
+
"inputs:bump_factor",
|
|
1356
|
+
"inputs:flip_tangent_u",
|
|
1357
|
+
"inputs:flip_tangent_v",
|
|
1358
|
+
"inputs:reflectionroughness_texture",
|
|
1359
|
+
"inputs:metallic_texture",
|
|
1360
|
+
"inputs:opacity_texture"
|
|
1361
|
+
]);
|
|
1362
|
+
($(e, ["specular_level"]) ?? 0.5) !== 0.5 && t.add("OmniPBR.specular_level"), n.add("inputs:specular_level");
|
|
1363
|
+
const r = /* @__PURE__ */ new Set(["inputs:opacity_mode", "inputs:opacity_threshold", "inputs:enable_opacity_texture"]);
|
|
1364
|
+
oe(e, ["enable_emission"], !1) && t.add("OmniPBR.emission_radiometric_equivalence");
|
|
1365
|
+
const s = {
|
|
1366
|
+
"inputs:albedo_desaturation": 0,
|
|
1367
|
+
"inputs:albedo_add": 0,
|
|
1368
|
+
"inputs:albedo_brightness": 1,
|
|
1369
|
+
"inputs:world_or_object": !1
|
|
1370
|
+
};
|
|
1371
|
+
for (const d of Object.keys(e.inputs))
|
|
1372
|
+
d in s && e.inputs[d] === s[d] || !n.has(d) && !r.has(d) && t.add(`OmniPBR.${d.replace(/^inputs:/, "")}`);
|
|
1373
|
+
}
|
|
1374
|
+
function Tn(e, t, n) {
|
|
1375
|
+
let r = !1;
|
|
1376
|
+
const s = ve(t), d = $e(t, ["diffuseColor", "baseColor", "base_color", "diffuse_color_constant"]), f = $(t, ["roughness", "specularRoughness", "specular_roughness", "reflection_roughness_constant"]) ?? (s ? 0.5 : null), p = $(t, ["metallic", "metalness", "metallicFactor", "metallic_constant"]) ?? (s ? 0 : null), o = $(t, ["opacity_threshold"]) ?? 0, a = oe(t, ["enable_opacity"], !1) && o >= 0, i = $(t, ["opacity", "presence", "opacity_constant"]) ?? (s ? 1 : null), c = s ? a ? o > 0 ? i >= o ? 1 : 0 : i : 1 : i, m = oe(t, ["enable_emission"], !s), y = m ? $e(t, ["emissiveColor", "emissionColor", "emission_color", "emissive_color"]) : null;
|
|
1377
|
+
for (const u of e)
|
|
1378
|
+
z(u) && (d && (u.color.copy(d), r = !0), f !== null && (u.roughness = xe(f), r = !0), p !== null && (u.metalness = xe(p), r = !0), c !== null && (u.opacity = xe(c), u.transparent = u.opacity < 1, u.depthWrite = u.opacity >= 1, r = !0), s && !m && (u.emissive.setRGB(0, 0, 0), u.emissiveIntensity = 0), y && (u.emissive.copy(y), s && (u.emissiveIntensity = Math.max(0, $(t, ["emissive_intensity"]) ?? 40)), r = !0), r && (u.needsUpdate = !0));
|
|
1379
|
+
return d && n.push("diffuseColor.constant"), f !== null && n.push("roughness.constant"), p !== null && n.push("metalness.constant"), c !== null && n.push("opacity.constant"), y && n.push("emissiveColor.constant"), r;
|
|
1380
|
+
}
|
|
1381
|
+
function Nn(e, t, n) {
|
|
1382
|
+
const r = /* @__PURE__ */ new Set(), s = (d) => {
|
|
1383
|
+
if (r.has(d.path)) return;
|
|
1384
|
+
r.add(d.path);
|
|
1385
|
+
const f = me(e, d);
|
|
1386
|
+
if (!f) {
|
|
1387
|
+
n.add(d.path);
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
if (!_t(f)) {
|
|
1391
|
+
n.add(f.id ?? f.path);
|
|
1392
|
+
for (const [p, o] of Object.entries(f.inputs)) {
|
|
1393
|
+
if (!p.endsWith(".resolvedConnect") && !p.endsWith(".connect")) continue;
|
|
1394
|
+
const a = je(o);
|
|
1395
|
+
a && s(a);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
for (const [d, f] of Object.entries(t.inputs)) {
|
|
1400
|
+
if (!d.endsWith(".resolvedConnect") && !d.endsWith(".connect") || /(?:diffuseColor|baseColor)/i.test(d)) continue;
|
|
1401
|
+
const p = je(f);
|
|
1402
|
+
p && s(p);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
async function se(e, t) {
|
|
1406
|
+
const n = Nt(t.entryDirectory ? `${t.entryDirectory}/${e}` : e);
|
|
1407
|
+
let r = t.files.find(e, t.entryDirectory ?? "") ?? t.files.find(n);
|
|
1408
|
+
if (!r)
|
|
1409
|
+
try {
|
|
1410
|
+
await t.files.ensure(n), r = t.files.find(n) ?? t.files.find(e, t.entryDirectory ?? "");
|
|
1411
|
+
} catch (s) {
|
|
1412
|
+
const d = s == null ? void 0 : s.code;
|
|
1413
|
+
if (s instanceof Error && s.name === "AbortError" || d === "E_ASSET_AUTH") throw s;
|
|
1414
|
+
const f = d === "E_ASSET_RESOURCE_NOT_FOUND" || /\((404|410)\)/.test(String(s));
|
|
1415
|
+
return { report: { path: e, status: f ? "missing" : "unresolved" }, url: null };
|
|
1416
|
+
}
|
|
1417
|
+
return r ? Sn.has(Ln(e)) ? { report: { path: e, status: "available" }, url: t.files.objectUrl(r) } : { report: { path: e, status: "unsupported-format" }, url: null } : { report: { path: e, status: "unresolved" }, url: null };
|
|
1418
|
+
}
|
|
1419
|
+
function We(e, t, n, r, s, d, f) {
|
|
1420
|
+
f === "augmented" && e.approximations.push({
|
|
1421
|
+
code: "USD_VISUAL_MATERIAL_AUGMENTED",
|
|
1422
|
+
message: `USD 材质 ${t}(${gt(n) ?? "renderer-specific shader"})已通过视觉适配层映射资产明确提供的输入:${Se(r).join(", ")}。这是有限范围的材质映射,不保证与原渲染器完全等价;原始 Loader 诊断保留在 visualAdaptation 报告中。`,
|
|
1423
|
+
source: "usd-visual"
|
|
1424
|
+
});
|
|
1425
|
+
for (const o of d)
|
|
1426
|
+
o.status === "missing" && e.warnings.push({
|
|
1427
|
+
code: "USD_VISUAL_RESOURCE_MISSING",
|
|
1428
|
+
message: `USD 材质资源缺失:${o.path}(${t})。未生成替代内容。`,
|
|
1429
|
+
source: "usd-visual"
|
|
1430
|
+
}), o.status === "unsupported-format" && e.droppedFeatures.push({
|
|
1431
|
+
code: "USD_VISUAL_TEXTURE_FORMAT_UNSUPPORTED",
|
|
1432
|
+
message: `USD 材质纹理格式无法由浏览器直接消费:${o.path}(${t})。需要离线确定性转码。`,
|
|
1433
|
+
source: "usd-visual"
|
|
1434
|
+
}), o.status === "decode-failed" && e.warnings.push({
|
|
1435
|
+
code: "USD_VISUAL_TEXTURE_DECODE_FAILED",
|
|
1436
|
+
message: `USD 纹理解码失败:${o.path}(${t})。保留原材质。`,
|
|
1437
|
+
source: "usd-visual"
|
|
1438
|
+
}), o.status === "unresolved" && e.warnings.push({
|
|
1439
|
+
code: "USD_VISUAL_RESOURCE_UNRESOLVED",
|
|
1440
|
+
message: `无法确认 USD 材质资源是否可用:${o.path}(${t})。未生成替代内容。`,
|
|
1441
|
+
source: "usd-visual"
|
|
1442
|
+
});
|
|
1443
|
+
const p = {
|
|
1444
|
+
"OmniGlass.solid_volume_absorption": "实体玻璃目前仅渲染表面透射:缺少可靠的内部光程,未实现体积吸收。未推断或生成壁厚",
|
|
1445
|
+
"OmniGlass.glass_color.volume": "源玻璃颜色用于体积吸收,当前未还原该体积颜色;未用表面染色替代",
|
|
1446
|
+
"OmniGlass.depth": "源 depth 是体积吸收缩放,不能直接当作 Three.js 壁厚或衰减距离;此输入尚未映射",
|
|
1447
|
+
"OmniGlass.fractional_coverage_transmission_compositing": "覆盖率与透射参数已映射,但其组合使用实时合成近似,不保证与 MDL 渲染等价",
|
|
1448
|
+
"OmniGlass.tint_reflection_coupling": "薄壁玻璃颜色已作表面近似,其反射与透射颜色响应不保证与 MDL 等价"
|
|
1449
|
+
};
|
|
1450
|
+
for (const o of s) e.droppedFeatures.push({
|
|
1451
|
+
code: "USD_VISUAL_SHADER_NODE_UNSUPPORTED",
|
|
1452
|
+
message: p[o] ? `USD 材质 ${t}:${p[o]}。` : `USD 材质功能或节点 ${o} 尚未完成浏览器适配(${t})。未生成替代内容。`,
|
|
1453
|
+
source: "usd-visual"
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
function $n(e) {
|
|
1457
|
+
const t = I(e, ["filename", "file"]), n = J(t);
|
|
1458
|
+
return n ? { shader: e, path: n } : null;
|
|
1459
|
+
}
|
|
1460
|
+
function k(e, t) {
|
|
1461
|
+
return je(e.inputs[`inputs:${t}.resolvedConnect`] ?? e.inputs[`inputs:${t}.connect`]);
|
|
1462
|
+
}
|
|
1463
|
+
function je(e) {
|
|
1464
|
+
const t = Array.isArray(e) ? e[0] : e;
|
|
1465
|
+
if (typeof t != "string") return null;
|
|
1466
|
+
const n = /^(.*?)(?:\.outputs:([^/]+))?$/.exec(t);
|
|
1467
|
+
return n ? { path: n[1], outputName: n[2] ?? null } : null;
|
|
1468
|
+
}
|
|
1469
|
+
function me(e, t) {
|
|
1470
|
+
return e.shaders.find((n) => n.path === t.path) ?? null;
|
|
1471
|
+
}
|
|
1472
|
+
function _t(e) {
|
|
1473
|
+
return e.id === "PxrTexture";
|
|
1474
|
+
}
|
|
1475
|
+
function z(e) {
|
|
1476
|
+
return e instanceof He || e instanceof ie;
|
|
1477
|
+
}
|
|
1478
|
+
async function ae(e, t) {
|
|
1479
|
+
const n = await new pt().loadAsync(e);
|
|
1480
|
+
return n.colorSpace = t, n.flipY = !0, n;
|
|
1481
|
+
}
|
|
1482
|
+
function $e(e, t) {
|
|
1483
|
+
const n = I(e, t);
|
|
1484
|
+
if (!Array.isArray(n) || n.length < 3) return null;
|
|
1485
|
+
const r = n.slice(0, 3);
|
|
1486
|
+
return r.every((s) => typeof s == "number" && Number.isFinite(s)) ? new ut(r[0], r[1], r[2]) : null;
|
|
1487
|
+
}
|
|
1488
|
+
function oe(e, t, n) {
|
|
1489
|
+
const r = I(e, t);
|
|
1490
|
+
return typeof r == "boolean" ? r : n;
|
|
1491
|
+
}
|
|
1492
|
+
function rt(e, t, n) {
|
|
1493
|
+
const r = I(e, [t]);
|
|
1494
|
+
return Array.isArray(r) && r.length >= 2 && r.slice(0, 2).every((s) => typeof s == "number" && Number.isFinite(s)) ? [r[0], r[1]] : n;
|
|
1495
|
+
}
|
|
1496
|
+
function $(e, t) {
|
|
1497
|
+
const n = I(e, t), r = typeof n == "number" ? n : Number.NaN;
|
|
1498
|
+
return Number.isFinite(r) ? r : null;
|
|
1499
|
+
}
|
|
1500
|
+
function I(e, t) {
|
|
1501
|
+
for (const n of t) {
|
|
1502
|
+
if (k(e, n)) return;
|
|
1503
|
+
const r = e.inputs[`inputs:${n}`];
|
|
1504
|
+
if (r !== void 0) return r;
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
function J(e) {
|
|
1508
|
+
if (typeof e == "string") return e;
|
|
1509
|
+
if (!e || typeof e != "object") return null;
|
|
1510
|
+
for (const t of ["path", "resolvedPath", "url"]) {
|
|
1511
|
+
const n = e[t];
|
|
1512
|
+
if (typeof n == "string" && n) return n;
|
|
1513
|
+
}
|
|
1514
|
+
return null;
|
|
1515
|
+
}
|
|
1516
|
+
function st(e, t) {
|
|
1517
|
+
return e.data.elements.some((n) => n.material === t && n.geometry.displayColor !== null);
|
|
1518
|
+
}
|
|
1519
|
+
function Ln(e) {
|
|
1520
|
+
var t, n;
|
|
1521
|
+
return ((n = (t = e.split(/[?#]/, 1)[0]) == null ? void 0 : t.split(".").pop()) == null ? void 0 : n.toLowerCase()) ?? "";
|
|
1522
|
+
}
|
|
1523
|
+
function xe(e) {
|
|
1524
|
+
return Math.min(1, Math.max(0, e));
|
|
1525
|
+
}
|
|
1526
|
+
function Ie(e) {
|
|
1527
|
+
return Array.isArray(e) ? e.filter(ze) : [];
|
|
1528
|
+
}
|
|
1529
|
+
function he(e) {
|
|
1530
|
+
return typeof e == "string" && e ? e : null;
|
|
1531
|
+
}
|
|
1532
|
+
function ze(e) {
|
|
1533
|
+
return typeof e == "string" && e.length > 0;
|
|
1534
|
+
}
|
|
1535
|
+
function Se(e) {
|
|
1536
|
+
return [...new Set(e)];
|
|
1537
|
+
}
|
|
1538
|
+
const at = /* @__PURE__ */ new Map();
|
|
1539
|
+
function Cn(e) {
|
|
1540
|
+
const t = e ?? "";
|
|
1541
|
+
let n = at.get(t);
|
|
1542
|
+
return n || (n = nn(dn(e)), at.set(t, n)), n;
|
|
1543
|
+
}
|
|
1544
|
+
async function rr(e, t, n) {
|
|
1545
|
+
var l;
|
|
1546
|
+
const r = n.hasLocalFiles(), s = e.entryPath ?? e.filename ?? "asset.usd", d = r ? s : await Jn(e, s), f = r ? n.getBlob(s) : await Zn(e), p = s.split("/").pop() || "asset.usd", o = s.split("/").slice(0, -1).join("/"), { parseAsync: a } = await Cn(t.options.openUsdBaseUrl), i = Gn(t.requestRender);
|
|
1547
|
+
let c = null, m = null, y = null, u = null;
|
|
1548
|
+
try {
|
|
1549
|
+
if (c = await a(f, {
|
|
1550
|
+
sourcePath: d,
|
|
1551
|
+
fileName: p,
|
|
1552
|
+
files: r ? n.asSourceRecord(o) : void 0,
|
|
1553
|
+
// A local package with a host resolver may still have entries the browser
|
|
1554
|
+
// was not handed, so its references stay resolvable through that resolver.
|
|
1555
|
+
autoResolveAssets: !r || e.hasResourceResolver,
|
|
1556
|
+
// A host resolver owns the mapping from authored identifiers to signed or
|
|
1557
|
+
// rewritten URLs; everything else is fetched from the entry layer's base.
|
|
1558
|
+
resolveBytes: e.hasResourceResolver ? async (v, F) => {
|
|
1559
|
+
const Y = n.find(F, o);
|
|
1560
|
+
return Y ? n.bytes(Y) : (await n.ensure(F), n.bytes(F));
|
|
1561
|
+
} : void 0,
|
|
1562
|
+
textureResolver: r || e.hasResourceResolver ? (v) => {
|
|
1563
|
+
for (const F of [v.resolvedPath, v.path, v.url])
|
|
1564
|
+
if (F) {
|
|
1565
|
+
const Y = n.objectUrlIfPresent(F, o);
|
|
1566
|
+
if (Y) return Y;
|
|
1567
|
+
}
|
|
1568
|
+
return null;
|
|
1569
|
+
} : void 0,
|
|
1570
|
+
textureLoader: i
|
|
1571
|
+
}), t.signal.aborted) throw ke();
|
|
1572
|
+
const _ = qn(c);
|
|
1573
|
+
c.scene.scale.multiplyScalar(_.metersPerUnit), c.data.stage.upAxis.toUpperCase() === "Y" && c.scene.quaternion.setFromAxisAngle(new N(1, 0, 0), Math.PI / 2), c.scene.updateMatrixWorld(!0);
|
|
1574
|
+
const g = c.data.physics.rigidBodies.filter((v) => v.enabled), h = bt(c, g.map((v) => v.path)), S = Lt(), U = await Un(c, {
|
|
1575
|
+
files: n,
|
|
1576
|
+
entryDirectory: o,
|
|
1577
|
+
sourcePath: d,
|
|
1578
|
+
isLocalPackage: r,
|
|
1579
|
+
diagnostics: S
|
|
1580
|
+
});
|
|
1581
|
+
if (t.signal.aborted) throw ke();
|
|
1582
|
+
Vt(c);
|
|
1583
|
+
const P = Fn(S);
|
|
1584
|
+
g.some((v) => v.startsAsleep === !0) && S.droppedFeatures.push({ code: "E_USD_STARTS_ASLEEP", message: "USD startsAsleep 无法在 MuJoCo 初始化阶段保证完全等价,已按正常初始状态加载。", source: "usd-physics" });
|
|
1585
|
+
const A = Ct({
|
|
1586
|
+
id: d,
|
|
1587
|
+
name: d.split("/").pop() ?? d,
|
|
1588
|
+
source: { format: "usd", uri: d },
|
|
1589
|
+
links: g.map((v) => ({ id: v.path, name: v.name, visuals: [], collisions: [] })),
|
|
1590
|
+
joints: h.flatMap((v) => v.body0 && v.body1 ? [{
|
|
1591
|
+
id: v.path,
|
|
1592
|
+
type: v.jointType,
|
|
1593
|
+
parent: v.body0,
|
|
1594
|
+
child: v.body1,
|
|
1595
|
+
origin: { position: v.localPos1.map((F) => F * _.metersPerUnit), rotationRpy: [0, 0, 0] },
|
|
1596
|
+
axis: Ut(v.axis).applyQuaternion(be(v.localRot1 ?? [1, 0, 0, 0])).toArray(),
|
|
1597
|
+
...Number.isFinite(v.lowerLimit) && Number.isFinite(v.upperLimit) ? { limits: {
|
|
1598
|
+
lower: v.lowerLimit * (v.jointType === "revolute" ? Math.PI / 180 : _.metersPerUnit),
|
|
1599
|
+
upper: v.upperLimit * (v.jointType === "revolute" ? Math.PI / 180 : _.metersPerUnit)
|
|
1600
|
+
} } : {}
|
|
1601
|
+
}] : []),
|
|
1602
|
+
diagnostics: S,
|
|
1603
|
+
extension: { rigidBodyCount: g.length, jointCount: h.length, visualAdaptation: U }
|
|
1604
|
+
});
|
|
1605
|
+
if (g.length === 0) {
|
|
1606
|
+
ot(c);
|
|
1607
|
+
const v = it(c, S), F = c.scene, Y = c, b = Bn(F, t.requestRender);
|
|
1608
|
+
return y = { root: F, sync() {
|
|
1609
|
+
}, dispose() {
|
|
1610
|
+
b == null || b.dispose(), Y.dispose();
|
|
1611
|
+
} }, c = null, Fe(A, y, !1, () => {
|
|
1612
|
+
}, void 0, void 0, v, P, b);
|
|
1613
|
+
}
|
|
1614
|
+
let E;
|
|
1615
|
+
try {
|
|
1616
|
+
E = Yn(c, g.map((F) => F.path), _, h), (l = E.massOverrides) != null && l.length && S.approximations.push({ code: "USD_INFERRED_INERTIA", message: "保留显式总质量;惯量按碰撞几何的密度分布推导并同比缩放,重叠体积会重复计入。", source: "usd-physics" });
|
|
1617
|
+
const { MujocoRuntime: v } = await import("./mujoco-runtime-7xiBQNJm.js");
|
|
1618
|
+
m = new v(), await m.initialize(E, t.options.mujocoBaseUrl), t.signal.throwIfAborted();
|
|
1619
|
+
} catch (v) {
|
|
1620
|
+
const F = Gt(v, t.signal, "usd-physics");
|
|
1621
|
+
m == null || m.dispose(), m = null, S.droppedFeatures.push(F), ot(c);
|
|
1622
|
+
const Y = it(c, S), b = c.scene, O = c;
|
|
1623
|
+
return y = { root: b, sync() {
|
|
1624
|
+
}, dispose() {
|
|
1625
|
+
O.dispose();
|
|
1626
|
+
} }, c = null, Fe(A, y, !1, () => {
|
|
1627
|
+
}, void 0, F, Y, P);
|
|
1628
|
+
}
|
|
1629
|
+
const M = u = Wn(c, g.map((v) => v.path), S);
|
|
1630
|
+
if (t.signal.aborted) throw ke();
|
|
1631
|
+
y = new et(m, M);
|
|
1632
|
+
const T = St(c, g.map((v) => v.path), S), w = T ? new et(m, T) : void 0;
|
|
1633
|
+
u = null;
|
|
1634
|
+
const x = c, R = m, C = y;
|
|
1635
|
+
return c = null, m = null, y = null, Fe(A, C, !0, () => {
|
|
1636
|
+
R.dispose(), x.dispose();
|
|
1637
|
+
}, R, void 0, w, P);
|
|
1638
|
+
} catch (_) {
|
|
1639
|
+
throw u && mt(u.root), y == null || y.dispose(), m == null || m.dispose(), c == null || c.dispose(), _;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
function ot(e) {
|
|
1643
|
+
for (const t of e.index.boneHostsBySkeletonPath.values())
|
|
1644
|
+
t.matrix.copy(e.scene.matrixWorld).invert();
|
|
1645
|
+
e.scene.updateMatrixWorld(!0);
|
|
1646
|
+
}
|
|
1647
|
+
function Gn(e) {
|
|
1648
|
+
const n = [];
|
|
1649
|
+
let r = !1;
|
|
1650
|
+
const s = () => {
|
|
1651
|
+
if (r || n.length === 0) return;
|
|
1652
|
+
r = !0;
|
|
1653
|
+
const f = () => {
|
|
1654
|
+
var o;
|
|
1655
|
+
r = !1;
|
|
1656
|
+
let p = 0;
|
|
1657
|
+
for (; n.length; ) {
|
|
1658
|
+
const a = n[0];
|
|
1659
|
+
if (p > 0 && p + a.pixels > 4194304 || ((o = n.shift()) == null || o.apply(), p += a.pixels, p >= 4194304)) break;
|
|
1660
|
+
}
|
|
1661
|
+
n.length && s();
|
|
1662
|
+
};
|
|
1663
|
+
typeof requestAnimationFrame == "function" ? requestAnimationFrame(f) : setTimeout(f, 16);
|
|
1664
|
+
};
|
|
1665
|
+
class d extends pt {
|
|
1666
|
+
load(p, o, a, i) {
|
|
1667
|
+
const c = new lt();
|
|
1668
|
+
return setTimeout(() => {
|
|
1669
|
+
super.load(p, (m) => {
|
|
1670
|
+
var l, _;
|
|
1671
|
+
const y = ((l = m.image) == null ? void 0 : l.width) || 0, u = ((_ = m.image) == null ? void 0 : _.height) || 0;
|
|
1672
|
+
n.push({ pixels: Math.max(1, y * u), apply: () => {
|
|
1673
|
+
c.image = m.image, c.source.needsUpdate = !0, c.needsUpdate = !0, m.dispose(), o == null || o(c), e();
|
|
1674
|
+
} }), s();
|
|
1675
|
+
}, a, i);
|
|
1676
|
+
}, 0), c;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return new d();
|
|
1680
|
+
}
|
|
1681
|
+
function Bn(e, t) {
|
|
1682
|
+
const n = e.animations ?? [];
|
|
1683
|
+
if (n.length === 0) return;
|
|
1684
|
+
const r = new Ot(e), s = n.map((d) => r.clipAction(d));
|
|
1685
|
+
for (const d of s) d.reset().setLoop(Tt, 1 / 0).play();
|
|
1686
|
+
return r.setTime(0), {
|
|
1687
|
+
step(d) {
|
|
1688
|
+
return d > 0 ? (r.update(d), t(), !0) : !1;
|
|
1689
|
+
},
|
|
1690
|
+
reset() {
|
|
1691
|
+
r.setTime(0), t();
|
|
1692
|
+
},
|
|
1693
|
+
dispose() {
|
|
1694
|
+
for (const d of s) d.stop();
|
|
1695
|
+
r.stopAllAction(), r.uncacheRoot(e);
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
function Fn(e) {
|
|
1700
|
+
const t = [
|
|
1701
|
+
"USD_VISUAL_RESOURCE_MISSING",
|
|
1702
|
+
"USD_VISUAL_TEXTURE_FORMAT_UNSUPPORTED",
|
|
1703
|
+
"USD_VISUAL_RESOURCE_UNRESOLVED",
|
|
1704
|
+
"USD_VISUAL_TEXTURE_DECODE_FAILED",
|
|
1705
|
+
"USD_VISUAL_SHADER_NODE_UNSUPPORTED",
|
|
1706
|
+
"USD_VISUAL_LOADER_DIAGNOSTIC",
|
|
1707
|
+
"USD_VISUAL_TOPOLOGY_UNSUPPORTED"
|
|
1708
|
+
], n = [...e.warnings, ...e.droppedFeatures, ...e.approximations];
|
|
1709
|
+
for (const r of t) {
|
|
1710
|
+
const s = n.find((d) => d.code === r);
|
|
1711
|
+
if (s) return s;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
function Fe(e, t, n, r, s, d, f, p, o) {
|
|
1715
|
+
let a = !1;
|
|
1716
|
+
return {
|
|
1717
|
+
asset: e,
|
|
1718
|
+
binding: t,
|
|
1719
|
+
hasPhysics: n,
|
|
1720
|
+
hasAnimation: !!o,
|
|
1721
|
+
runtime: s,
|
|
1722
|
+
fallback: d,
|
|
1723
|
+
visualWarning: p,
|
|
1724
|
+
collision: f,
|
|
1725
|
+
step(i) {
|
|
1726
|
+
if (o) return o.step(i);
|
|
1727
|
+
if (!s) return !1;
|
|
1728
|
+
const c = s.step(i);
|
|
1729
|
+
return c && t.sync(), c;
|
|
1730
|
+
},
|
|
1731
|
+
reset() {
|
|
1732
|
+
if (o) {
|
|
1733
|
+
o.reset();
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
1736
|
+
s == null || s.reset(), t.sync();
|
|
1737
|
+
},
|
|
1738
|
+
dispose() {
|
|
1739
|
+
a || (a = !0, f == null || f.dispose(), t.dispose(), r());
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
const kn = /* @__PURE__ */ new Set([
|
|
1744
|
+
"E_USD_PHYSICS_UNSUPPORTED",
|
|
1745
|
+
"E_USD_UNBAKED_BODY_SCALE",
|
|
1746
|
+
"E_USD_INVALID_JOINT_REFERENCE",
|
|
1747
|
+
"E_USD_UNSUPPORTED_JOINT",
|
|
1748
|
+
"E_USD_MULTIPLE_PARENTS",
|
|
1749
|
+
"E_USD_JOINT_CYCLE",
|
|
1750
|
+
"E_USD_UNSUPPORTED_DRIVE",
|
|
1751
|
+
"E_USD_INVALID_MASS",
|
|
1752
|
+
"E_USD_PARTIAL_INERTIA",
|
|
1753
|
+
"E_USD_MISSING_COLLISION_GEOMETRY",
|
|
1754
|
+
"E_USD_UNREACHABLE_BODIES",
|
|
1755
|
+
"E_USD_MULTIPLE_PHYSICS_SCENES",
|
|
1756
|
+
"E_USD_NONUNIFORM_RADIAL_SCALE",
|
|
1757
|
+
"E_USD_UNSUPPORTED_GEOMETRY",
|
|
1758
|
+
"E_USD_CONSTRAINED_INITIAL_VELOCITY",
|
|
1759
|
+
"E_USD_UNSUPPORTED_APPROXIMATION"
|
|
1760
|
+
]);
|
|
1761
|
+
function sr(e) {
|
|
1762
|
+
const t = Vn(e);
|
|
1763
|
+
return t !== null && kn.has(t);
|
|
1764
|
+
}
|
|
1765
|
+
function Vn(e) {
|
|
1766
|
+
if (!e || typeof e != "object" || !("code" in e)) return null;
|
|
1767
|
+
const t = e.code;
|
|
1768
|
+
return typeof t == "string" ? t : null;
|
|
1769
|
+
}
|
|
1770
|
+
function Wn(e, t, n) {
|
|
1771
|
+
e.scene.updateMatrixWorld(!0);
|
|
1772
|
+
const r = new Ee();
|
|
1773
|
+
r.name = "USD simulation";
|
|
1774
|
+
const s = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
|
|
1775
|
+
for (const u of t) {
|
|
1776
|
+
const l = e.index.objectsByPath.get(u);
|
|
1777
|
+
if (!l) throw B(`USD rigid body node is missing: ${u}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
1778
|
+
const _ = new Ee();
|
|
1779
|
+
_.name = u, r.add(_), s.set(u, _);
|
|
1780
|
+
const g = new N(), h = new ee();
|
|
1781
|
+
l.matrixWorld.decompose(g, h, new N()), d.set(u, new pe().compose(g, h, new N(1, 1, 1)));
|
|
1782
|
+
}
|
|
1783
|
+
const f = jn(e, t, n), p = [], o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), c = (u, l) => {
|
|
1784
|
+
var U;
|
|
1785
|
+
const _ = u.skeleton, g = _.bones.map((P) => P.uuid).join("|");
|
|
1786
|
+
let h = i.get(g), S;
|
|
1787
|
+
if (h)
|
|
1788
|
+
S = _.bones.map((P) => a.get(P.uuid));
|
|
1789
|
+
else {
|
|
1790
|
+
h = new Ee(), h.name = `${u.name || "USD"}_BoneHost`, h.matrixAutoUpdate = !1;
|
|
1791
|
+
const P = (U = _.bones[0]) == null ? void 0 : U.parent;
|
|
1792
|
+
h.matrix.copy(l).multiply((P == null ? void 0 : P.matrixWorld) ?? new pe()), r.add(h), i.set(g, h), S = _.bones.map((A) => {
|
|
1793
|
+
const E = A.clone(!1);
|
|
1794
|
+
return E.matrix.copy(A.matrix), E.matrixAutoUpdate = !1, a.set(A.uuid, E), E;
|
|
1795
|
+
});
|
|
1796
|
+
for (let A = 0; A < S.length; A++) {
|
|
1797
|
+
const E = _.bones[A].parent, M = _.bones.indexOf(E);
|
|
1798
|
+
(M >= 0 ? S[M] : h).add(S[A]);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
return new It(S, _.boneInverses.map((P) => P.clone()));
|
|
1802
|
+
};
|
|
1803
|
+
e.scene.traverse((u) => {
|
|
1804
|
+
var S;
|
|
1805
|
+
if (!(u instanceof te) || u.userData.usdPurposeExcluded) return;
|
|
1806
|
+
let l = u, _, g, h = !0;
|
|
1807
|
+
for (; l; ) {
|
|
1808
|
+
h && (h = l.visible);
|
|
1809
|
+
const U = (S = l.userData.usd) == null ? void 0 : S.path;
|
|
1810
|
+
!g && U && (g = U), !_ && U && s.has(U) && (_ = U), l = l.parent;
|
|
1811
|
+
}
|
|
1812
|
+
!_ && g && (_ = f.get(wt(g))), h && p.push([u, _]);
|
|
1813
|
+
});
|
|
1814
|
+
for (const [u, l] of p) {
|
|
1815
|
+
const _ = l ? d.get(l).clone().invert() : new pe(), g = u instanceof Me ? new Me(u.geometry.clone(), Array.isArray(u.material) ? u.material.map((h) => h.clone()) : u.material.clone()) : u.clone(!1);
|
|
1816
|
+
g.geometry = u.geometry.clone(), g.material = Array.isArray(u.material) ? u.material.map((h) => h.clone()) : u.material.clone(), g instanceof Me && u instanceof Me && (g.bindMode = u.bindMode, g.bindMatrix.copy(u.bindMatrix), g.bindMatrixInverse.copy(u.bindMatrixInverse), g.bind(c(u, _), g.bindMatrix), g.frustumCulled = !1), g.matrix.copy(_).multiply(u.matrixWorld), g.matrix.decompose(g.position, g.quaternion, g.scale), (l ? s.get(l) : r).add(g), o.set(u.uuid, g);
|
|
1817
|
+
}
|
|
1818
|
+
const y = (e.scene.animations ?? []).map((u) => {
|
|
1819
|
+
const l = u.clone();
|
|
1820
|
+
return l.tracks = l.tracks.map((_) => {
|
|
1821
|
+
const g = _.name.split(".", 1)[0], h = o.get(g) ?? a.get(g);
|
|
1822
|
+
return h && (_.name = `${h.uuid}${_.name.slice(g.length)}`), _;
|
|
1823
|
+
}), l;
|
|
1824
|
+
});
|
|
1825
|
+
return { root: r, bindings: s, expectedLinkCount: s.size, animations: y };
|
|
1826
|
+
}
|
|
1827
|
+
function jn(e, t, n) {
|
|
1828
|
+
var o, a;
|
|
1829
|
+
const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), d = e.stage, f = e.pxr;
|
|
1830
|
+
if (!d || !((o = f == null ? void 0 : f.Sdf) != null && o.Path) || !((a = e.data.view) != null && a.prims)) return r;
|
|
1831
|
+
const p = new Set(e.data.view.prims.map((i) => i.path));
|
|
1832
|
+
for (const i of t) {
|
|
1833
|
+
const c = `${i}/Visual/`;
|
|
1834
|
+
for (const m of p) {
|
|
1835
|
+
if (!m.startsWith(c)) continue;
|
|
1836
|
+
const y = d.GetPrimAtPath(new f.Sdf.Path(m));
|
|
1837
|
+
try {
|
|
1838
|
+
const u = y.GetMetadata("references"), l = typeof u == "string" ? u : u == null ? void 0 : u.string;
|
|
1839
|
+
if (l == null) {
|
|
1840
|
+
n == null || n.warnings.push({ code: "USD_VISUAL_REFERENCE_MISSING", message: `刚体视觉节点缺少 reference:${m}`, source: "usd-visual-binding" });
|
|
1841
|
+
continue;
|
|
1842
|
+
}
|
|
1843
|
+
const _ = zn(l);
|
|
1844
|
+
if (!_) {
|
|
1845
|
+
n == null || n.warnings.push({ code: "USD_VISUAL_REFERENCE_UNRESOLVED", message: `无法解析视觉引用元数据:${m}`, source: "usd-visual-binding" });
|
|
1846
|
+
continue;
|
|
1847
|
+
}
|
|
1848
|
+
if (!_.primPath) continue;
|
|
1849
|
+
const g = wt(_.primPath), h = s.get(g);
|
|
1850
|
+
if (h && h.owner !== i)
|
|
1851
|
+
throw B(`USD visual reference maps to multiple rigid bodies: ${_.primPath} -> ${h.owner}, ${i}`, "E_USD_VISUAL_REFERENCE_AMBIGUOUS");
|
|
1852
|
+
s.set(g, { owner: i, target: _.primPath }), r.set(g, i);
|
|
1853
|
+
} finally {
|
|
1854
|
+
y.delete();
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
return r;
|
|
1859
|
+
}
|
|
1860
|
+
function zn(e) {
|
|
1861
|
+
var n, r;
|
|
1862
|
+
const t = e.match(/SdfReference\(([^,]*),\s*(?:(\/[^,\)]+),\s*)?SdfLayerOffset/);
|
|
1863
|
+
return t ? { identifier: ((n = t[1]) == null ? void 0 : n.trim()) ?? "", primPath: ((r = t[2]) == null ? void 0 : r.trim()) ?? null } : null;
|
|
1864
|
+
}
|
|
1865
|
+
function wt(e) {
|
|
1866
|
+
const t = e.replaceAll("\\", "/");
|
|
1867
|
+
for (const n of ["/Geometry/", "/Visual/"]) {
|
|
1868
|
+
const r = t.indexOf(n);
|
|
1869
|
+
if (r >= 0) return t.slice(r + n.length);
|
|
1870
|
+
}
|
|
1871
|
+
return t;
|
|
1872
|
+
}
|
|
1873
|
+
function St(e, t, n) {
|
|
1874
|
+
e.scene.updateMatrixWorld(!0);
|
|
1875
|
+
const r = new Ee();
|
|
1876
|
+
r.name = "USD authored collisions";
|
|
1877
|
+
const s = $t(), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
|
|
1878
|
+
for (const o of t) {
|
|
1879
|
+
const a = e.index.objectsByPath.get(o);
|
|
1880
|
+
if (!a) continue;
|
|
1881
|
+
const i = new N(), c = new ee();
|
|
1882
|
+
a.matrixWorld.decompose(i, c, new N()), f.set(o, new pe().compose(i, c, new N(1, 1, 1)));
|
|
1883
|
+
const m = new Ee();
|
|
1884
|
+
m.name = o, m.position.copy(i), m.quaternion.copy(c), d.set(o, m), r.add(m);
|
|
1885
|
+
}
|
|
1886
|
+
let p = 0;
|
|
1887
|
+
for (const o of e.data.physics.colliders) {
|
|
1888
|
+
if (!o.enabled) continue;
|
|
1889
|
+
const a = e.index.objectsByPath.get(o.path);
|
|
1890
|
+
if (!a) continue;
|
|
1891
|
+
const i = o.bodyPath && d.has(o.bodyPath) ? o.bodyPath : null, c = i ? d.get(i) : r, m = i ? f.get(i) : new pe(), y = [];
|
|
1892
|
+
if (a.traverse((g) => {
|
|
1893
|
+
g instanceof te && y.push(g);
|
|
1894
|
+
}), y.length === 0) continue;
|
|
1895
|
+
const u = String(o.typeName ?? a.type).toLowerCase(), l = u.includes("mesh") ? o.approximation ?? "none" : null;
|
|
1896
|
+
if (l === "convexDecomposition" || l === "meshSimplification") {
|
|
1897
|
+
n == null || n.droppedFeatures.push({
|
|
1898
|
+
code: "E_USD_COLLISION_DEBUG_APPROXIMATION_UNAVAILABLE",
|
|
1899
|
+
message: `USD collider ${o.path} 使用 ${l},但资产未提供可唯一还原的最终代理几何。`,
|
|
1900
|
+
source: "usd-collision-debug"
|
|
1901
|
+
});
|
|
1902
|
+
continue;
|
|
1903
|
+
}
|
|
1904
|
+
if (u.includes("mesh") && l !== "none") {
|
|
1905
|
+
const g = [], h = m.clone().invert();
|
|
1906
|
+
for (const S of y) {
|
|
1907
|
+
const U = h.clone().multiply(S.matrixWorld), P = S.geometry.getAttribute("position");
|
|
1908
|
+
for (let A = 0; A < P.count; A += 1) g.push(new N().fromBufferAttribute(P, A).applyMatrix4(U));
|
|
1909
|
+
}
|
|
1910
|
+
if (g.length >= 4 && l === "convexHull") {
|
|
1911
|
+
const S = new Bt(g), U = Re(S, s, "mesh");
|
|
1912
|
+
S.dispose(), U.name = `Collision:${o.path}`, U.userData.usdColliderPath = o.path, c.add(U), p += 1;
|
|
1913
|
+
} else if (g.length > 0 && l === "boundingSphere") {
|
|
1914
|
+
const U = new Te().setFromPoints(g).getBoundingSphere(new Dt()), P = new Mt(U.radius, 24, 16);
|
|
1915
|
+
P.translate(U.center.x, U.center.y, U.center.z);
|
|
1916
|
+
const A = Re(P, s, "feature");
|
|
1917
|
+
P.dispose(), A.name = `Collision:${o.path}`, A.userData.usdColliderPath = o.path, c.add(A), p += 1;
|
|
1918
|
+
} else if (g.length > 0 && l === "boundingCube") {
|
|
1919
|
+
const S = new Te().setFromPoints(g), U = S.getSize(new N()), P = S.getCenter(new N()), A = new Rt(U.x, U.y, U.z);
|
|
1920
|
+
A.translate(P.x, P.y, P.z);
|
|
1921
|
+
const E = Re(A, s, "feature");
|
|
1922
|
+
A.dispose(), E.name = `Collision:${o.path}`, E.userData.usdColliderPath = o.path, c.add(E), p += 1;
|
|
1923
|
+
} else ["convexHull", "boundingSphere", "boundingCube"].includes(String(l)) || n == null || n.droppedFeatures.push({
|
|
1924
|
+
code: "E_USD_COLLISION_DEBUG_APPROXIMATION_UNAVAILABLE",
|
|
1925
|
+
message: `USD collider ${o.path} 使用未知 approximation=${l}。`,
|
|
1926
|
+
source: "usd-collision-debug"
|
|
1927
|
+
});
|
|
1928
|
+
continue;
|
|
1929
|
+
}
|
|
1930
|
+
const _ = u.includes("mesh") ? "mesh" : "feature";
|
|
1931
|
+
for (const g of y) {
|
|
1932
|
+
const h = Re(g.geometry, s, _);
|
|
1933
|
+
h.name = `Collision:${o.path}`, h.matrixAutoUpdate = !1, h.matrix.copy(m).invert().multiply(g.matrixWorld), h.userData.usdColliderPath = o.path, c.add(h), p += 1;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
if (p === 0) {
|
|
1937
|
+
s.dispose();
|
|
1938
|
+
return;
|
|
1939
|
+
}
|
|
1940
|
+
return { root: r, bindings: d, expectedLinkCount: d.size };
|
|
1941
|
+
}
|
|
1942
|
+
function it(e, t) {
|
|
1943
|
+
const n = St(e, [], t);
|
|
1944
|
+
if (n)
|
|
1945
|
+
return n.root.visible = !1, { root: n.root, sync() {
|
|
1946
|
+
}, dispose() {
|
|
1947
|
+
n.root.removeFromParent(), mt(n.root);
|
|
1948
|
+
} };
|
|
1949
|
+
}
|
|
1950
|
+
function bt(e, t) {
|
|
1951
|
+
e.scene.updateMatrixWorld(!0);
|
|
1952
|
+
const n = new Set(t);
|
|
1953
|
+
return e.data.joints.filter((r) => r.enabled).map((r) => {
|
|
1954
|
+
const s = { ...r };
|
|
1955
|
+
for (const d of [0, 1]) {
|
|
1956
|
+
const f = d === 0 ? "body0" : "body1", p = d === 0 ? "localPos0" : "localPos1", o = d === 0 ? "localRot0" : "localRot1", a = r[f];
|
|
1957
|
+
if (!a) continue;
|
|
1958
|
+
let i = a;
|
|
1959
|
+
for (; i && !e.index.rigidBodiesByPath.has(i); )
|
|
1960
|
+
i = i.slice(0, i.lastIndexOf("/"));
|
|
1961
|
+
if (i && !n.has(i))
|
|
1962
|
+
throw B(`USD joint references an unknown or disabled rigid body: ${r.path} (${a})`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
1963
|
+
const c = e.index.objectsByPath.get(a), m = i ? e.index.objectsByPath.get(i) : e.scene;
|
|
1964
|
+
if (!c || !m)
|
|
1965
|
+
throw B(`USD joint target node is missing: ${r.path} (${a})`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
1966
|
+
if (i === a) continue;
|
|
1967
|
+
const y = m.matrixWorld.clone().invert().multiply(c.matrixWorld), u = new N(), l = new ee(), _ = new N();
|
|
1968
|
+
y.decompose(u, l, _);
|
|
1969
|
+
const g = new pe().compose(u, l, new N(1, 1, 1));
|
|
1970
|
+
if (y.elements.some((S, U) => Math.abs(S - g.elements[U]) > 1e-5))
|
|
1971
|
+
throw B(`USD joint target has unsupported scale or shear: ${r.path} (${a})`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
1972
|
+
s[f] = i || null, s[p] = new N(...r[p]).applyMatrix4(y).toArray();
|
|
1973
|
+
const h = l.multiply(be(r[o] ?? [1, 0, 0, 0])).normalize();
|
|
1974
|
+
s[o] = [h.w, h.x, h.y, h.z];
|
|
1975
|
+
}
|
|
1976
|
+
return s;
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
function Yn(e, t, n, r = bt(e, t)) {
|
|
1980
|
+
e.scene.updateMatrixWorld(!0);
|
|
1981
|
+
const s = [], d = [], f = [], p = [], o = [], a = [], i = [], { metersPerUnit: c, kilogramsPerUnit: m } = n, y = new Map(t.map((w) => {
|
|
1982
|
+
const x = e.index.rigidBodiesByPath.get(w);
|
|
1983
|
+
if (!x) throw B(`USD rigid body metadata is missing: ${w}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
1984
|
+
return [w, x];
|
|
1985
|
+
})), u = /* @__PURE__ */ new Map();
|
|
1986
|
+
for (const w of y.keys()) {
|
|
1987
|
+
const x = e.index.objectsByPath.get(w);
|
|
1988
|
+
if (!x) throw B(`USD rigid body node is missing: ${w}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
1989
|
+
const R = new N(), C = new ee(), v = new N();
|
|
1990
|
+
if (x.matrixWorld.decompose(R, C, v), v.clone().divideScalar(c).toArray().some((Y) => Math.abs(Math.abs(Y) - 1) > 1e-5))
|
|
1991
|
+
throw B(`USD rigid body has unbaked scale: ${w}`, "E_USD_UNBAKED_BODY_SCALE");
|
|
1992
|
+
u.set(w, new pe().compose(R, C, new N(1, 1, 1)));
|
|
1993
|
+
}
|
|
1994
|
+
const l = /* @__PURE__ */ new Map();
|
|
1995
|
+
for (const w of r) {
|
|
1996
|
+
if (!w.body1 || !y.has(w.body1) || w.body0 && !y.has(w.body0))
|
|
1997
|
+
throw B(`USD joint references an unknown rigid body: ${w.path}`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
1998
|
+
if (!["fixed", "revolute", "prismatic"].includes(w.jointType))
|
|
1999
|
+
throw B(`Unsupported USD joint type ${w.jointType}: ${w.path}`, "E_USD_UNSUPPORTED_JOINT");
|
|
2000
|
+
if (l.has(w.body1)) throw B(`USD rigid body has multiple parent joints: ${w.body1}`, "E_USD_MULTIPLE_PARENTS");
|
|
2001
|
+
l.set(w.body1, w), w.body0 && w.collisionEnabled !== !0 && f.push(`<exclude body1="${we(w.body0)}" body2="${we(w.body1)}"/>`);
|
|
2002
|
+
}
|
|
2003
|
+
let _ = 0;
|
|
2004
|
+
const g = /* @__PURE__ */ new Set(), h = (w, x = new pe()) => {
|
|
2005
|
+
var j, H, V, L, ce;
|
|
2006
|
+
if (g.has(w)) throw B(`USD joint graph contains a cycle at ${w}`, "E_USD_JOINT_CYCLE");
|
|
2007
|
+
g.add(w);
|
|
2008
|
+
const R = y.get(w), C = u.get(w), v = x.clone().invert().multiply(C), F = new N(), Y = new ee();
|
|
2009
|
+
v.decompose(F, Y, new N());
|
|
2010
|
+
const b = l.get(w), O = [`<body name="${we(w)}" pos="${Q(F.toArray())}" quat="${Ue(Y)}">`];
|
|
2011
|
+
if (!b && !R.kinematicEnabled && O.push("<freejoint/>"), b && [...R.velocity ?? [], ...R.angularVelocity ?? []].some((G) => G !== 0))
|
|
2012
|
+
throw B(`Constrained USD initial velocity cannot be projected reliably: ${w}`, "E_USD_CONSTRAINED_INITIAL_VELOCITY");
|
|
2013
|
+
if (!b && !R.kinematicEnabled) {
|
|
2014
|
+
const G = new N(...R.velocity ?? [0, 0, 0]).multiplyScalar(c).applyQuaternion(e.scene.quaternion), X = new N(...R.angularVelocity ?? [0, 0, 0]).multiplyScalar(Math.PI / 180).applyQuaternion(e.scene.quaternion).applyQuaternion(new ee().setFromRotationMatrix(C).invert());
|
|
2015
|
+
i.push({ body: w, velocity: [...G.toArray(), ...X.toArray()] });
|
|
2016
|
+
}
|
|
2017
|
+
if (b && b.jointType !== "fixed") {
|
|
2018
|
+
const G = b.jointType === "revolute" ? "hinge" : "slide", X = Ut(b.axis).applyQuaternion(be(b.localRot1 ?? [1, 0, 0, 0])), ne = G === "hinge" ? Math.PI / 180 : c, ye = b.body0 ? x : e.scene.matrixWorld.clone();
|
|
2019
|
+
if (!b.body0) {
|
|
2020
|
+
const re = new N(), _e = new ee();
|
|
2021
|
+
ye.decompose(re, _e, new N()), ye.compose(re, _e, new N(1, 1, 1));
|
|
2022
|
+
}
|
|
2023
|
+
const Le = new ee().setFromRotationMatrix(ye), Pe = new ee().setFromRotationMatrix(C), ge = Le.clone().multiply(be(b.localRot0 ?? [1, 0, 0, 0])).invert().multiply(Pe).multiply(be(b.localRot1 ?? [1, 0, 0, 0]));
|
|
2024
|
+
let fe = 0;
|
|
2025
|
+
if (G === "hinge") {
|
|
2026
|
+
const re = b.axis === "Y" ? ge.y : b.axis === "Z" ? ge.z : ge.x;
|
|
2027
|
+
fe = 2 * Math.atan2(re, ge.w), fe = Math.atan2(Math.sin(fe), Math.cos(fe));
|
|
2028
|
+
} else {
|
|
2029
|
+
const re = new N(...b.localPos0).multiplyScalar(c).applyMatrix4(ye);
|
|
2030
|
+
fe = new N(...b.localPos1).multiplyScalar(c).applyMatrix4(C).sub(re).dot(X.clone().applyQuaternion(Pe));
|
|
2031
|
+
}
|
|
2032
|
+
const qe = Number.isFinite(b.lowerLimit) && Number.isFinite(b.upperLimit) && Math.abs(b.lowerLimit) < 1e20 && Math.abs(b.upperLimit) < 1e20, xt = qe && b.lowerLimit < b.upperLimit, Ae = m * (G === "slide" ? c : c * c), Ce = Oe(e, b.path, `physxJointAxis:${G === "slide" ? "linear" : "angular"}:dynamicFrictionEffort`), Et = typeof Ce == "number" && Number.isFinite(Ce) ? Ce * Ae : 0;
|
|
2033
|
+
O.push(`<joint name="${we(b.path)}" type="${G}" pos="${Q(b.localPos1.map((re) => re * c))}" axis="${Q(X.toArray())}" ref="${fe}" ${xt ? `range="${b.lowerLimit * ne} ${b.upperLimit * ne}"` : 'limited="false"'} frictionloss="${Et}" armature="0.00001"/>`), qe && b.lowerLimit === b.upperLimit && d.push(`<joint joint1="${we(b.path)}" polycoef="${b.lowerLimit * ne - fe} 0 0 0 0"/>`);
|
|
2034
|
+
const ue = b.drive;
|
|
2035
|
+
if (ue && ((ue.stiffness ?? 0) !== 0 || (ue.damping ?? 0) !== 0)) {
|
|
2036
|
+
if (ue.type === "acceleration") throw B(`Unsupported USD acceleration drive: ${b.path}`, "E_USD_UNSUPPORTED_DRIVE");
|
|
2037
|
+
const re = (ue.stiffness ?? 0) * Ae / ne, _e = (ue.damping ?? 0) * Ae / ne, De = ue.maxForce == null ? null : ue.maxForce * Ae;
|
|
2038
|
+
o.push(`<general joint="${we(b.path)}" gainprm="1" biastype="affine" biasprm="0 ${-re} ${-_e}" ${De != null && Number.isFinite(De) ? `forcelimited="true" forcerange="${-De} ${De}"` : ""}/>`), a.push(re * (ue.targetPosition ?? 0) * ne + _e * (ue.targetVelocity ?? 0) * ne);
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
const D = R.mass;
|
|
2042
|
+
if ((D == null ? void 0 : D.mass) != null && (!Number.isFinite(D.mass) || D.mass < 0)) throw B(`USD rigid body mass must be finite and non-negative: ${w}`, "E_USD_INVALID_MASS");
|
|
2043
|
+
let Z = !1;
|
|
2044
|
+
if ((D == null ? void 0 : D.mass) != null && D.mass > 0 && ((j = D.centerOfMass) == null ? void 0 : j.length) === 3 && D.centerOfMass.every(Number.isFinite) && ((H = D.diagonalInertia) == null ? void 0 : H.length) === 3 && D.diagonalInertia.every((G) => Number.isFinite(G) && G > 0) && ((V = D.principalAxes) == null ? void 0 : V.length) === 4 && D.principalAxes.every(Number.isFinite))
|
|
2045
|
+
Z = !0, O.push(`<inertial mass="${D.mass * m}" pos="${Q(D.centerOfMass.map((G) => G * c))}" quat="${Ue(be(D.principalAxes))}" diaginertia="${Q(D.diagonalInertia.map((G) => G * m * c * c))}"/>`);
|
|
2046
|
+
else {
|
|
2047
|
+
if ((L = D == null ? void 0 : D.diagonalInertia) != null && L.some((G) => G > 0))
|
|
2048
|
+
throw B(`USD rigid body has incomplete explicit inertia: ${w}`, "E_USD_PARTIAL_INERTIA");
|
|
2049
|
+
if ((D == null ? void 0 : D.mass) != null && D.mass > 0) {
|
|
2050
|
+
if ((ce = D.centerOfMass) != null && ce.every(Number.isFinite) && D.centerOfMass.some((G) => G !== 0)) throw B(`Custom center of mass requires explicit inertia: ${w}`, "E_USD_PARTIAL_INERTIA");
|
|
2051
|
+
p.push({ body: w, mass: D.mass * m });
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
const W = e.data.physics.colliders.filter((G) => G.enabled && G.bodyPath === w);
|
|
2055
|
+
if (!W.length && !Z) throw B(`USD rigid body has no authored collision geometry: ${w}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
2056
|
+
for (const G of W) {
|
|
2057
|
+
const X = e.data.physics.materials.find((ge) => ge.path === G.material), ne = (D == null ? void 0 : D.density) != null && D.density > 0 ? D.density : X == null ? void 0 : X.density, ye = ne != null && ne > 0 ? ne * m / c ** 3 : 1e3, Le = (X == null ? void 0 : X.dynamicFriction) ?? 0.4, Pe = `density="${ye}" group="3" contype="1" conaffinity="1" friction="${Le} 0.01 0.0002"`;
|
|
2058
|
+
O.push(ct(e, G, w, C, _++, s, Pe));
|
|
2059
|
+
}
|
|
2060
|
+
for (const [G, X] of l) X.body0 === w && O.push(h(G, C));
|
|
2061
|
+
return O.push("</body>"), O.join("");
|
|
2062
|
+
}, S = e.data.physics.colliders.filter((w) => w.enabled && !w.bodyPath), U = S.map((w) => {
|
|
2063
|
+
const x = e.data.physics.materials.find((F) => F.path === w.material), R = (x == null ? void 0 : x.density) != null && x.density > 0 ? x.density * m / c ** 3 : 1e3, C = (x == null ? void 0 : x.dynamicFriction) ?? 0.4, v = `density="${R}" group="3" contype="1" conaffinity="1" friction="${C} 0.01 0.0002"`;
|
|
2064
|
+
return ct(e, w, "", new pe(), _++, s, v);
|
|
2065
|
+
}).join(""), P = Hn(e, t, S) ? `<geom name="__viewer_default_ground__" type="plane" pos="0 0 ${Xn(e, t)}" size="1 1 0.1" group="3" contype="1" conaffinity="1" friction="0.8 0.01 0.0002"/>` : "", E = [...y.keys()].filter((w) => {
|
|
2066
|
+
var x;
|
|
2067
|
+
return !((x = l.get(w)) != null && x.body0);
|
|
2068
|
+
}).map((w) => h(w)).join("");
|
|
2069
|
+
if (g.size !== y.size) throw B("USD joint graph contains unreachable bodies or a cycle.", "E_USD_UNREACHABLE_BODIES");
|
|
2070
|
+
if (e.data.physics.scenes.length > 1) throw B("Multiple USD PhysicsScene prims are not supported.", "E_USD_MULTIPLE_PHYSICS_SCENES");
|
|
2071
|
+
const M = e.data.physics.scenes[0], T = M != null && M.gravityDirection && M.gravityMagnitude != null && M.gravityMagnitude >= 0 ? new N(...M.gravityDirection).normalize().multiplyScalar(M.gravityMagnitude * c).applyQuaternion(e.scene.quaternion) : new N(0, 0, -9.81);
|
|
2072
|
+
return {
|
|
2073
|
+
// Do not inflate contact surfaces across authored clearances. PhysX contactOffset
|
|
2074
|
+
// is not a MuJoCo force-generating margin and must not be copied as one.
|
|
2075
|
+
format: "mjcf",
|
|
2076
|
+
files: /* @__PURE__ */ new Map(),
|
|
2077
|
+
initialControls: a,
|
|
2078
|
+
initialVelocities: i,
|
|
2079
|
+
massOverrides: p,
|
|
2080
|
+
xml: `<mujoco><compiler angle="radian" autolimits="true"/><option integrator="implicitfast" gravity="${Q(T.toArray())}"><flag filterparent="disable"/></option><default><geom margin="0" solref="0.004 1"/></default>${s.length ? `<asset>${s.join("")}</asset>` : ""}<worldbody>${P}${U}${E}</worldbody>${f.length ? `<contact>${f.join("")}</contact>` : ""}${d.length ? `<equality>${d.join("")}</equality>` : ""}${o.length ? `<actuator>${o.join("")}</actuator>` : ""}</mujoco>`
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
function Hn(e, t, n = e.data.physics.colliders.filter((r) => r.enabled && !r.bodyPath)) {
|
|
2084
|
+
if (!t.length || n.some((p) => p.typeName.toLowerCase().includes("plane"))) return !1;
|
|
2085
|
+
const r = Ye(e, e.data.physics.colliders.filter(
|
|
2086
|
+
(p) => p.enabled && p.bodyPath && t.includes(p.bodyPath)
|
|
2087
|
+
));
|
|
2088
|
+
if (r.isEmpty()) return n.length === 0;
|
|
2089
|
+
const s = Math.max(r.max.x - r.min.x, 1e-6), d = Math.max(r.max.y - r.min.y, 1e-6), f = Math.max(s, d, r.max.z - r.min.z) * 0.05;
|
|
2090
|
+
return !n.some((p) => {
|
|
2091
|
+
const o = Ye(e, [p]);
|
|
2092
|
+
if (o.isEmpty()) return !1;
|
|
2093
|
+
const a = o.max.x >= r.min.x && o.min.x <= r.max.x, i = o.max.y >= r.min.y && o.min.y <= r.max.y;
|
|
2094
|
+
return a && i && o.max.z <= r.min.z + f;
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
function Xn(e, t) {
|
|
2098
|
+
const n = Ye(e, e.data.physics.colliders.filter(
|
|
2099
|
+
(s) => s.enabled && s.bodyPath && t.includes(s.bodyPath)
|
|
2100
|
+
)), r = n.isEmpty() ? 0 : n.min.z;
|
|
2101
|
+
return Number.isFinite(r) ? String(r) : "0";
|
|
2102
|
+
}
|
|
2103
|
+
function Ye(e, t) {
|
|
2104
|
+
const n = new Te();
|
|
2105
|
+
for (const r of t) {
|
|
2106
|
+
const s = e.index.objectsByPath.get(r.path);
|
|
2107
|
+
s && n.union(new Te().setFromObject(s));
|
|
2108
|
+
}
|
|
2109
|
+
return n;
|
|
2110
|
+
}
|
|
2111
|
+
function Ut(e) {
|
|
2112
|
+
return e === "Y" ? new N(0, 1, 0) : e === "Z" ? new N(0, 0, 1) : new N(1, 0, 0);
|
|
2113
|
+
}
|
|
2114
|
+
function ct(e, t, n, r, s, d, f) {
|
|
2115
|
+
const p = e.index.objectsByPath.get(t.path);
|
|
2116
|
+
if (!p) throw B(`USD collider node is missing: ${t.path}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
2117
|
+
const o = r.clone().invert().multiply(p.matrixWorld), a = new N(), i = new ee(), c = new N();
|
|
2118
|
+
o.decompose(a, i, c);
|
|
2119
|
+
const m = t.typeName.replace(/^UsdGeom/, "").toLowerCase(), y = (u, l) => {
|
|
2120
|
+
const _ = Oe(e, t.path, u);
|
|
2121
|
+
return typeof _ == "number" ? _ : l;
|
|
2122
|
+
};
|
|
2123
|
+
if (m.includes("cube")) {
|
|
2124
|
+
const u = Math.abs(y("size", 2)) / 2;
|
|
2125
|
+
return `<geom type="box" pos="${Q(a.toArray())}" quat="${Ue(i)}" size="${Q([Math.abs(c.x) * u, Math.abs(c.y) * u, Math.abs(c.z) * u])}" ${f}/>`;
|
|
2126
|
+
}
|
|
2127
|
+
if (m.includes("plane")) {
|
|
2128
|
+
if (n) throw B(`USD plane collider requires a static world owner: ${t.path}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
2129
|
+
const u = String(Oe(e, t.path, "axis") ?? "Z").toUpperCase(), _ = { X: new N(1, 0, 0), Y: new N(0, 1, 0), Z: new N(0, 0, 1) }[u];
|
|
2130
|
+
if (!_) throw B(`Unsupported USD plane axis: ${u}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
2131
|
+
const g = i.clone().multiply(new ee().setFromUnitVectors(new N(0, 0, 1), _));
|
|
2132
|
+
return `<geom type="plane" pos="${Q(a.toArray())}" quat="${Ue(g)}" size="1 1 0.1" ${f}/>`;
|
|
2133
|
+
}
|
|
2134
|
+
if (m.includes("cone"))
|
|
2135
|
+
throw B(`MuJoCo has no analytic cone geom; a validated mesh conversion is required: ${t.path}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
2136
|
+
if (m.includes("sphere")) {
|
|
2137
|
+
const u = [Math.abs(c.x), Math.abs(c.y), Math.abs(c.z)];
|
|
2138
|
+
if (Math.max(...u) - Math.min(...u) > 1e-6) throw B(`USD sphere collider does not support non-uniform scale: ${t.path}`, "E_USD_NONUNIFORM_RADIAL_SCALE");
|
|
2139
|
+
return `<geom type="sphere" pos="${Q(a.toArray())}" quat="${Ue(i)}" size="${u[0] * y("radius", 1)}" ${f}/>`;
|
|
2140
|
+
}
|
|
2141
|
+
if (m.includes("cylinder") || m.includes("capsule")) {
|
|
2142
|
+
const u = String(Oe(e, t.path, "axis") ?? "Z").toUpperCase(), l = { X: 0, Y: 1, Z: 2 }[u];
|
|
2143
|
+
if (l === void 0) throw B(`Unsupported USD collider axis: ${u}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
2144
|
+
const _ = [Math.abs(c.x), Math.abs(c.y), Math.abs(c.z)], g = _.filter((A, E) => E !== l);
|
|
2145
|
+
if (Math.abs(g[0] - g[1]) > 1e-6) throw B(`USD ${t.typeName} collider does not support non-uniform radial scale: ${t.path}`, "E_USD_NONUNIFORM_RADIAL_SCALE");
|
|
2146
|
+
const h = new N(...{ X: [1, 0, 0], Y: [0, 1, 0], Z: [0, 0, 1] }[u]), S = i.clone().multiply(new ee().setFromUnitVectors(new N(0, 0, 1), h)), U = y("radius", 1) * g[0], P = y("height", 2) * _[l] / 2;
|
|
2147
|
+
return `<geom type="${m.includes("capsule") ? "capsule" : "cylinder"}" pos="${Q(a.toArray())}" quat="${Ue(S)}" size="${U} ${P}" ${f}/>`;
|
|
2148
|
+
}
|
|
2149
|
+
if (m.includes("mesh")) {
|
|
2150
|
+
if (t.approximation && !["none", "convexHull"].includes(t.approximation)) throw B(`USD mesh approximation cannot be mapped exactly: ${t.path}`, "E_USD_UNSUPPORTED_APPROXIMATION");
|
|
2151
|
+
const u = [];
|
|
2152
|
+
if (p.traverse((S) => {
|
|
2153
|
+
S instanceof te && u.push(S);
|
|
2154
|
+
}), !u.length) throw B(`USD collider has no mesh geometry: ${t.path}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
2155
|
+
const l = [], _ = [];
|
|
2156
|
+
let g = 0;
|
|
2157
|
+
for (const S of u) {
|
|
2158
|
+
const U = S.geometry.getAttribute("position");
|
|
2159
|
+
for (let A = 0; A < U.count; A++) {
|
|
2160
|
+
const E = new N().fromBufferAttribute(U, A).applyMatrix4(r.clone().invert().multiply(S.matrixWorld));
|
|
2161
|
+
l.push(E.x, E.y, E.z);
|
|
2162
|
+
}
|
|
2163
|
+
const P = S.geometry.index;
|
|
2164
|
+
for (let A = 0; A < (P ? P.count : U.count); A += 3) _.push(g + (P ? P.getX(A) : A), g + (P ? P.getX(A + 1) : A + 1), g + (P ? P.getX(A + 2) : A + 2));
|
|
2165
|
+
g += U.count;
|
|
2166
|
+
}
|
|
2167
|
+
const h = `collision_${s}`;
|
|
2168
|
+
return d.push(`<mesh name="${h}" vertex="${Q(l)}" face="${Q(_)}"/>`), `<geom type="mesh" mesh="${h}" ${f}/>`;
|
|
2169
|
+
}
|
|
2170
|
+
throw B(`Unsupported USD collider geometry: ${t.typeName}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
2171
|
+
}
|
|
2172
|
+
function qn(e) {
|
|
2173
|
+
const t = e.stage.GetPseudoRoot();
|
|
2174
|
+
try {
|
|
2175
|
+
const n = Number(t.GetMetadata("metersPerUnit") ?? 0.01), r = Number(t.GetMetadata("kilogramsPerUnit") ?? 1);
|
|
2176
|
+
if (!Number.isFinite(n) || n <= 0) throw B("USD metersPerUnit must be finite and positive.", "E_USD_INVALID_UNITS");
|
|
2177
|
+
if (!Number.isFinite(r) || r <= 0) throw B("USD kilogramsPerUnit must be finite and positive.", "E_USD_INVALID_UNITS");
|
|
2178
|
+
return { metersPerUnit: n, kilogramsPerUnit: r };
|
|
2179
|
+
} finally {
|
|
2180
|
+
t.delete();
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
function be(e) {
|
|
2184
|
+
const [t = 1, n = 0, r = 0, s = 0] = e;
|
|
2185
|
+
return new ee(n, r, s, t).normalize();
|
|
2186
|
+
}
|
|
2187
|
+
function Q(e) {
|
|
2188
|
+
return e.join(" ");
|
|
2189
|
+
}
|
|
2190
|
+
function Ue(e) {
|
|
2191
|
+
return `${e.w} ${e.x} ${e.y} ${e.z}`;
|
|
2192
|
+
}
|
|
2193
|
+
function Oe(e, t, n) {
|
|
2194
|
+
var o, a;
|
|
2195
|
+
const r = e.stage;
|
|
2196
|
+
if (!r || !((a = (o = e.pxr) == null ? void 0 : o.Sdf) != null && a.Path)) return null;
|
|
2197
|
+
const s = new e.pxr.Sdf.Path(t), d = r.GetPrimAtPath(s), f = d.GetAttribute(n), p = e.pxr.Usd.TimeCode.Default();
|
|
2198
|
+
try {
|
|
2199
|
+
return f.IsValid() ? f.Get(p) : null;
|
|
2200
|
+
} finally {
|
|
2201
|
+
p.delete(), f.delete(), d.delete(), s.delete();
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
async function Jn(e, t) {
|
|
2205
|
+
var n;
|
|
2206
|
+
if (e.url)
|
|
2207
|
+
try {
|
|
2208
|
+
return new URL(e.url, ((n = globalThis.location) == null ? void 0 : n.href) ?? e.baseUrl ?? void 0).href;
|
|
2209
|
+
} catch {
|
|
2210
|
+
return e.url;
|
|
2211
|
+
}
|
|
2212
|
+
return e.resolve(t);
|
|
2213
|
+
}
|
|
2214
|
+
async function Zn(e) {
|
|
2215
|
+
const t = e.url ?? await e.resolve(e.entryPath ?? ""), n = await fetch(t, { signal: e.signal });
|
|
2216
|
+
if (!n.ok) throw B(`USD request failed (${n.status}): ${t}`, n.status === 401 || n.status === 403 ? "E_ASSET_AUTH" : "E_ASSET_FETCH");
|
|
2217
|
+
return n.blob();
|
|
2218
|
+
}
|
|
2219
|
+
function we(e) {
|
|
2220
|
+
return e.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<").replaceAll(">", ">");
|
|
2221
|
+
}
|
|
2222
|
+
function B(e, t) {
|
|
2223
|
+
return Object.assign(new Error(e), { code: t });
|
|
2224
|
+
}
|
|
2225
|
+
function ke() {
|
|
2226
|
+
return Object.assign(new Error("USD load aborted."), { name: "AbortError", code: "E_ABORTED" });
|
|
2227
|
+
}
|
|
2228
|
+
export {
|
|
2229
|
+
jn as buildUsdVisualReferenceOwners,
|
|
2230
|
+
it as compileUsdCollisionOverlay,
|
|
2231
|
+
St as compileUsdCollisionVisual,
|
|
2232
|
+
Yn as compileUsdPhysics,
|
|
2233
|
+
Wn as compileUsdVisual,
|
|
2234
|
+
Fn as firstUsdVisualWarning,
|
|
2235
|
+
sr as isUsdPhysicsFallbackEligible,
|
|
2236
|
+
rr as loadUsdSimulation,
|
|
2237
|
+
zn as parseUsdReferenceMetadata,
|
|
2238
|
+
bt as resolveUsdJoints,
|
|
2239
|
+
Hn as shouldInjectUsdDefaultGround
|
|
2240
|
+
};
|