@nebula-spatial/viewer 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +97 -56
- package/USD-VISUAL-MATERIAL-SUPPORT.md +29 -2
- package/dist/assets/types.d.ts +3 -0
- package/dist/{index-DmGuwbBM.js → index-bTlVsOHA.js} +918 -797
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -8
- package/dist/{mjcf-visual-CFXIhVyT.js → mjcf-visual-zWaLqVqd.js} +7 -7
- package/dist/mujoco-runtime-DTxVmIzc.js +349 -0
- package/dist/session-CZghJvw6.js +883 -0
- package/dist/{session-BzIziNzg.js → session-DVCZX72J.js} +79 -75
- package/dist/stage-DGMYxyAS.js +597 -0
- package/dist/ui/types.d.ts +1 -0
- package/dist/{urdf-session-BleSrYNu.js → urdf-session-CF8xOenk.js} +737 -731
- package/dist/usd-session-DkwOFmds.js +4254 -0
- package/dist/version.d.ts +1 -1
- package/dist/{xacro-D1hcJ9kB.js → xacro-DidnrxXF.js} +1 -1
- package/openusd/openusd_probe.js +1 -1
- package/openusd/openusd_probe.wasm +0 -0
- package/package.json +1 -1
- package/dist/mujoco-runtime-7xiBQNJm.js +0 -324
- package/dist/session-Boljcc3d.js +0 -844
- package/dist/stage-C7B1_qJ0.js +0 -502
- package/dist/usd-session-DFbFB8bP.js +0 -2392
|
@@ -0,0 +1,4254 @@
|
|
|
1
|
+
import { Mesh as me, FrontSide as $n, DoubleSide as Nn, MeshPhysicalMaterial as K, DataTexture as Tt, UnsignedByteType as $t, RGBAFormat as Nt, NoColorSpace as oe, Color as nt, Float32BufferAttribute as Bn, SRGBColorSpace as ht, RepeatWrapping as te, Texture as Pt, MeshStandardMaterial as Ot, TextureLoader as rn, MirroredRepeatWrapping as on, ClampToEdgeWrapping as an, Group as je, Vector3 as j, Quaternion as de, Matrix4 as Oe, Box3 as tt, Sphere as Ln, SphereGeometry as kn, BoxGeometry as Fn, SkinnedMesh as Ye, Skeleton as Gn, AnimationMixer as Vn, LoopRepeat as zn } from "three";
|
|
2
|
+
import { n as Qe, c as Bt, a as Lt, b as Ge, d as jn, p as Wn, S as kt, C as Ft, e as Xn } from "./session-CZghJvw6.js";
|
|
3
|
+
import { ConvexGeometry as Kn } from "three/examples/jsm/geometries/ConvexGeometry.js";
|
|
4
|
+
import { createUSDLoadedModel as Hn, buildUSDScene as qn } from "@openusd-wasm/three-loader";
|
|
5
|
+
import { f as Yn, g as Jn, c as Zn, h as Qn, j as es, d as ts } from "./index-bTlVsOHA.js";
|
|
6
|
+
import { b as un } from "./stage-DGMYxyAS.js";
|
|
7
|
+
const ns = /* @__PURE__ */ new Set(["default", "render"]);
|
|
8
|
+
function ss(e) {
|
|
9
|
+
var r, o;
|
|
10
|
+
const t = e.stage;
|
|
11
|
+
if (!t || !((o = (r = e.pxr) == null ? void 0 : r.Sdf) != null && o.Path)) return;
|
|
12
|
+
const n = /* @__PURE__ */ new Map(), s = (a) => {
|
|
13
|
+
if (!a || a === "/") return "default";
|
|
14
|
+
const c = n.get(a);
|
|
15
|
+
if (c !== void 0) return c;
|
|
16
|
+
const i = new e.pxr.Sdf.Path(a), l = t.GetPrimAtPath(i), h = l.GetAttribute("purpose"), u = e.pxr.Usd.TimeCode.Default();
|
|
17
|
+
let d;
|
|
18
|
+
try {
|
|
19
|
+
h.IsValid() && h.HasAuthoredValue() && (d = String(h.Get(u)));
|
|
20
|
+
} finally {
|
|
21
|
+
u.delete(), h.delete(), l.delete(), i.delete();
|
|
22
|
+
}
|
|
23
|
+
const p = d ?? s(a.slice(0, a.lastIndexOf("/")));
|
|
24
|
+
return n.set(a, p), p;
|
|
25
|
+
};
|
|
26
|
+
e.scene.traverse((a) => {
|
|
27
|
+
var h, u;
|
|
28
|
+
if (!(a instanceof me)) return;
|
|
29
|
+
let c = a, i;
|
|
30
|
+
for (; c && !i; )
|
|
31
|
+
i = (h = c.userData.usd) == null ? void 0 : h.path, c = c.parent;
|
|
32
|
+
if (!i) return;
|
|
33
|
+
const l = !ns.has(s(i));
|
|
34
|
+
a.userData.usdPurposeExcluded = l, l ? ((u = a.userData).usdPurposeLayerMask ?? (u.usdPurposeLayerMask = a.layers.mask), a.layers.disableAll()) : a.userData.usdPurposeLayerMask !== void 0 && (a.layers.mask = a.userData.usdPurposeLayerMask, delete a.userData.usdPurposeLayerMask);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function Rt(e, t) {
|
|
38
|
+
return /^https?:$/.test(t.protocol) && e.origin === t.origin && !e.username && !e.password && e.pathname.startsWith(new URL(".", t).pathname);
|
|
39
|
+
}
|
|
40
|
+
function cn(e, t, n) {
|
|
41
|
+
const s = [];
|
|
42
|
+
try {
|
|
43
|
+
for (const r of e) for (const o of r.shaders) for (const a of Object.values(o.inputs)) {
|
|
44
|
+
if (!a || typeof a != "object" || Array.isArray(a)) continue;
|
|
45
|
+
const c = a, i = [c.path, c.url, c.resolvedPath].find((h) => typeof h == "string" && h);
|
|
46
|
+
if (!i || /^(?:data|blob):/i.test(i) || /\.mdl(?:[?#].*)?$/i.test(i) || t(i)) continue;
|
|
47
|
+
const l = {};
|
|
48
|
+
for (const h of ["path", "resolvedPath", "url"])
|
|
49
|
+
h in c && (l[h] = c[h], delete c[h]);
|
|
50
|
+
s.push({ asset: c, values: l });
|
|
51
|
+
}
|
|
52
|
+
return n();
|
|
53
|
+
} finally {
|
|
54
|
+
for (const { asset: r, values: o } of s) Object.assign(r, o);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const rs = 67324752, os = 33639248, as = 101010256, it = 4294967295, is = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "webp"]);
|
|
58
|
+
function us(e) {
|
|
59
|
+
return e.length > 3 && e[0] === 80 && e[1] === 75;
|
|
60
|
+
}
|
|
61
|
+
async function cs(e, t = {}) {
|
|
62
|
+
const n = new DataView(e.buffer, e.byteOffset, e.byteLength), s = ms(n);
|
|
63
|
+
if (s < 0) throw new Error("Not a zip package: end of central directory not found.");
|
|
64
|
+
const r = n.getUint16(s + 10, !0);
|
|
65
|
+
let o = n.getUint32(s + 16, !0);
|
|
66
|
+
if (r === 65535 || o === it) throw new Error("ZIP64 usdz packages are not supported.");
|
|
67
|
+
const a = /* @__PURE__ */ new Map(), c = [];
|
|
68
|
+
for (let i = 0; i < r; i += 1) {
|
|
69
|
+
if (o + 46 > n.byteLength || n.getUint32(o, !0) !== os)
|
|
70
|
+
throw new Error(`Corrupt zip central directory at entry ${i}.`);
|
|
71
|
+
const l = n.getUint16(o + 10, !0), h = n.getUint32(o + 20, !0), u = n.getUint16(o + 28, !0), d = n.getUint16(o + 30, !0), p = n.getUint16(o + 32, !0), f = n.getUint32(o + 42, !0);
|
|
72
|
+
if (h === it || f === it)
|
|
73
|
+
throw new Error("ZIP64 usdz packages are not supported.");
|
|
74
|
+
const _ = new TextDecoder().decode(e.subarray(o + 46, o + 46 + u));
|
|
75
|
+
o += 46 + u + d + p, !_.endsWith("/") && (t.include && !t.include(_) || c.push(ps(e, n, f, h, l).then((w) => ({ name: _, data: w }))));
|
|
76
|
+
}
|
|
77
|
+
for (const { name: i, data: l } of await Promise.all(c)) a.set(i, l);
|
|
78
|
+
return a;
|
|
79
|
+
}
|
|
80
|
+
function ls(e) {
|
|
81
|
+
if (typeof URL > "u" || typeof URL.createObjectURL != "function") return null;
|
|
82
|
+
const t = new Map([...e].filter(([a]) => is.has(ln(a))));
|
|
83
|
+
if (t.size === 0) return null;
|
|
84
|
+
const n = /* @__PURE__ */ new Map();
|
|
85
|
+
for (const a of t.keys()) {
|
|
86
|
+
const c = a.split("/").pop() ?? a;
|
|
87
|
+
n.set(c, n.has(c) ? null : a);
|
|
88
|
+
}
|
|
89
|
+
const s = /* @__PURE__ */ new Map(), r = (a) => {
|
|
90
|
+
let c = s.get(a);
|
|
91
|
+
if (!c) {
|
|
92
|
+
const i = t.get(a);
|
|
93
|
+
c = URL.createObjectURL(new Blob([new Uint8Array(i)], { type: hs(a) })), s.set(a, c);
|
|
94
|
+
}
|
|
95
|
+
return c;
|
|
96
|
+
}, o = (a) => {
|
|
97
|
+
if (!a) return null;
|
|
98
|
+
const c = ds(fs(a));
|
|
99
|
+
if (!c) return null;
|
|
100
|
+
if (t.has(c)) return r(c);
|
|
101
|
+
const i = [...t.keys()].filter((u) => u.endsWith(`/${c}`));
|
|
102
|
+
if (i.length === 1) return r(i[0]);
|
|
103
|
+
const l = [...t.keys()].filter((u) => c.endsWith(`/${u}`));
|
|
104
|
+
if (l.length === 1) return r(l[0]);
|
|
105
|
+
const h = n.get(c.split("/").pop() ?? "");
|
|
106
|
+
return h ? r(h) : null;
|
|
107
|
+
};
|
|
108
|
+
for (const a of t.keys()) r(a);
|
|
109
|
+
return {
|
|
110
|
+
urls: s,
|
|
111
|
+
resolve: (a) => o(a.resolvedPath) ?? o(a.path) ?? o(a.url) ?? null,
|
|
112
|
+
dispose: () => {
|
|
113
|
+
for (const a of s.values()) URL.revokeObjectURL(a);
|
|
114
|
+
s.clear();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async function ps(e, t, n, s, r) {
|
|
119
|
+
if (t.getUint32(n, !0) !== rs) throw new Error("Corrupt zip local file header.");
|
|
120
|
+
const o = t.getUint16(n + 26, !0), a = t.getUint16(n + 28, !0), c = n + 30 + o + a, i = e.subarray(c, c + s);
|
|
121
|
+
if (r === 0) return i.slice();
|
|
122
|
+
if (r !== 8) throw new Error(`Unsupported zip compression method ${r}.`);
|
|
123
|
+
const l = new Blob([new Uint8Array(i)]).stream().pipeThrough(new DecompressionStream("deflate-raw"));
|
|
124
|
+
return new Uint8Array(await new Response(l).arrayBuffer());
|
|
125
|
+
}
|
|
126
|
+
function fs(e) {
|
|
127
|
+
const t = e.indexOf("[");
|
|
128
|
+
return t >= 0 && e.endsWith("]") ? e.slice(t + 1, -1) : e;
|
|
129
|
+
}
|
|
130
|
+
function ds(e) {
|
|
131
|
+
const t = [];
|
|
132
|
+
for (const n of e.replaceAll("\\", "/").split("/"))
|
|
133
|
+
!n || n === "." || (n === ".." ? t.pop() : t.push(n));
|
|
134
|
+
return t.join("/");
|
|
135
|
+
}
|
|
136
|
+
function ln(e) {
|
|
137
|
+
const t = e.split(/[?#]/)[0] ?? e, n = t.lastIndexOf(".");
|
|
138
|
+
return n < 0 ? "" : t.slice(n + 1).toLowerCase();
|
|
139
|
+
}
|
|
140
|
+
function hs(e) {
|
|
141
|
+
switch (ln(e)) {
|
|
142
|
+
case "png":
|
|
143
|
+
return "image/png";
|
|
144
|
+
case "jpg":
|
|
145
|
+
case "jpeg":
|
|
146
|
+
return "image/jpeg";
|
|
147
|
+
case "webp":
|
|
148
|
+
return "image/webp";
|
|
149
|
+
default:
|
|
150
|
+
return "application/octet-stream";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function ms(e) {
|
|
154
|
+
const t = Math.max(0, e.byteLength - 65535 - 22);
|
|
155
|
+
for (let n = e.byteLength - 22; n >= t; n -= 1)
|
|
156
|
+
if (e.getUint32(n, !0) === as) return n;
|
|
157
|
+
return -1;
|
|
158
|
+
}
|
|
159
|
+
const _s = /* @__PURE__ */ new Set(["usd", "usda", "usdc", "usdz"]);
|
|
160
|
+
async function gs(e) {
|
|
161
|
+
const t = await import(
|
|
162
|
+
/* @vite-ignore */
|
|
163
|
+
e.moduleUrl
|
|
164
|
+
), n = t.default ?? t.createOpenUsdProbe, s = await (typeof e.wasmBinary == "function" ? e.wasmBinary() : e.wasmBinary ?? Ps(e.wasmUrl)), r = await n({ wasmBinary: s }), o = e.memfsRoot ?? "/asset", a = e.fetchBytes ?? (async (d) => {
|
|
165
|
+
const p = await fetch(d);
|
|
166
|
+
if (!p.ok) throw Object.assign(new Error(`USD resource request failed (${p.status}): ${d}`), {
|
|
167
|
+
code: p.status === 401 || p.status === 403 ? "E_ASSET_AUTH" : "E_ASSET_FETCH"
|
|
168
|
+
});
|
|
169
|
+
const f = new Uint8Array(await p.arrayBuffer()), _ = Yn(p.headers.get("content-type"), f);
|
|
170
|
+
if (_) throw Jn(`USD resource is not usable (${_}): ${d}`, Zn);
|
|
171
|
+
return f;
|
|
172
|
+
}), c = (d, p, f) => JSON.parse(r.ccall(d, "string", p, f)), i = /* @__PURE__ */ new Set(), l = Gt(r);
|
|
173
|
+
let h = 0;
|
|
174
|
+
async function u(d, p) {
|
|
175
|
+
const f = new URL(p.sourcePath, "file:///"), _ = `${o}/load-${++h}`, w = We(f.href, _), g = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map();
|
|
176
|
+
let S, v = null;
|
|
177
|
+
const m = () => {
|
|
178
|
+
S !== void 0 && i.delete(S) && c("usd_probe_stage_release", ["number"], [S]), v == null || v.dispose(), pn(r.FS, _);
|
|
179
|
+
};
|
|
180
|
+
try {
|
|
181
|
+
const x = await Vt(d);
|
|
182
|
+
gt(r, w, x, g), b.set(w, mt(x));
|
|
183
|
+
for (const [k, D] of Object.entries(p.files ?? {})) {
|
|
184
|
+
const L = We(new URL(k, f).href, _), E = await Vt(D);
|
|
185
|
+
g.has(L) || b.set(L, mt(E)), gt(r, L, E, g);
|
|
186
|
+
}
|
|
187
|
+
const R = new Set(g), A = p.externalReferenceMode ?? "complete", P = us(x) ? await cs(x, { include: ys }) : null;
|
|
188
|
+
let C = {};
|
|
189
|
+
if (!P && p.autoResolveAssets !== !1) {
|
|
190
|
+
const k = p.resolveBytes ?? ((D) => a(D));
|
|
191
|
+
C = await Ss(
|
|
192
|
+
r,
|
|
193
|
+
f,
|
|
194
|
+
_,
|
|
195
|
+
k,
|
|
196
|
+
c,
|
|
197
|
+
g,
|
|
198
|
+
y,
|
|
199
|
+
b,
|
|
200
|
+
p.maxFiles ?? 1024,
|
|
201
|
+
p.maxDepth ?? 8,
|
|
202
|
+
p.maxConcurrency ?? 1,
|
|
203
|
+
A,
|
|
204
|
+
R,
|
|
205
|
+
p.onReferenceSkipped,
|
|
206
|
+
p.onResourceFailed
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
v = P ? ls(P) : null;
|
|
210
|
+
const F = p.textureResolver || v ? (k) => {
|
|
211
|
+
var D;
|
|
212
|
+
return ((D = p.textureResolver) == null ? void 0 : D.call(p, k)) ?? (v == null ? void 0 : v.resolve(k)) ?? null;
|
|
213
|
+
} : void 0, I = Object.keys(C).length > 0;
|
|
214
|
+
if (I && typeof r._usd_probe_stage_open_mapped != "function")
|
|
215
|
+
throw Object.assign(new Error("USD dependency mapping requires the matching packaged openusd_probe.js and .wasm runtime."), { code: "E_USD_RUNTIME_VERSION" });
|
|
216
|
+
const O = I ? c("usd_probe_stage_open_mapped", ["string", "string"], [w, JSON.stringify(C)]) : c("usd_probe_stage_open", ["string"], [w]);
|
|
217
|
+
if (!O.ok) throw new Error(O.error ?? `Failed to open ${w}`);
|
|
218
|
+
S = O.stageId, i.add(O.stageId);
|
|
219
|
+
const V = Gt(r, y), q = V.openStage(O.stageId), U = ws(r, O.stageId, w);
|
|
220
|
+
_t(U.materials, y), _t(U.lights, y);
|
|
221
|
+
const X = P ? void 0 : p.isTextureAllowed ?? (A === "package" ? (k) => {
|
|
222
|
+
const D = new URL(k, f);
|
|
223
|
+
return R.has(We(D.href, _)) || Rt(D, f);
|
|
224
|
+
} : void 0), T = () => Hn(
|
|
225
|
+
U,
|
|
226
|
+
V,
|
|
227
|
+
w,
|
|
228
|
+
{
|
|
229
|
+
sourcePath: p.sourcePath,
|
|
230
|
+
// `convertZUp` and `loadLights` are opt-in here: the viewer normalises USD
|
|
231
|
+
// to world Z-up itself and draws its own studio lighting. `loadTextures`
|
|
232
|
+
// keeps the reference builder's opt-out default, so omitting it loads
|
|
233
|
+
// textures instead of silently rendering untextured materials.
|
|
234
|
+
convertZUp: p.convertZUp ?? !1,
|
|
235
|
+
loadLights: p.loadLights ?? !1,
|
|
236
|
+
loadTextures: p.loadTextures ?? !0,
|
|
237
|
+
...p.textureLoader ? { textureLoader: p.textureLoader } : {},
|
|
238
|
+
...F ? { textureResolver: F } : {}
|
|
239
|
+
},
|
|
240
|
+
q,
|
|
241
|
+
{
|
|
242
|
+
// Keep package texture identities on the model so the visual adapter
|
|
243
|
+
// can resolve textures referenced by unsupported-but-known MDL nodes.
|
|
244
|
+
usdzTextureURLs: (v == null ? void 0 : v.urls) ?? /* @__PURE__ */ new Map(),
|
|
245
|
+
autoTextureURLs: /* @__PURE__ */ new Map()
|
|
246
|
+
}
|
|
247
|
+
), J = X ? cn(U.materials, X, T) : T(), se = J.dispose.bind(J);
|
|
248
|
+
let M = !1;
|
|
249
|
+
return J.dispose = () => {
|
|
250
|
+
M || (M = !0, se(), m());
|
|
251
|
+
}, J;
|
|
252
|
+
} catch (x) {
|
|
253
|
+
throw m(), x;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return { runtime: r, pxr: l, parseAsync: u };
|
|
257
|
+
}
|
|
258
|
+
function ys(e) {
|
|
259
|
+
return /\.(?:png|jpe?g|webp)$/i.test(e.split(/[?#]/, 1)[0] ?? e);
|
|
260
|
+
}
|
|
261
|
+
function Gt(e, t = /* @__PURE__ */ new Map()) {
|
|
262
|
+
const n = (i, l, h) => JSON.parse(e.ccall(i, "string", l, h));
|
|
263
|
+
class s {
|
|
264
|
+
constructor(l) {
|
|
265
|
+
this.path = l;
|
|
266
|
+
}
|
|
267
|
+
delete() {
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const r = (i, l, h) => {
|
|
271
|
+
const u = n("usd_probe_attribute_value", ["number", "string", "string"], [i, l, h]), d = u.valid === !0;
|
|
272
|
+
return {
|
|
273
|
+
IsValid: () => d,
|
|
274
|
+
Get: () => d ? typeof u.value == "string" ? t.get(u.value) ?? u.value : u.value : null,
|
|
275
|
+
HasAuthoredValue: () => u.authored === !0,
|
|
276
|
+
GetName: () => h,
|
|
277
|
+
GetMetadata: (p) => {
|
|
278
|
+
const f = n("usd_probe_attribute_metadata", ["number", "string", "string", "string"], [i, l, h, p]);
|
|
279
|
+
return f.valid === !0 && f.found === !0 ? f.value ?? null : null;
|
|
280
|
+
},
|
|
281
|
+
// The viewer accepts either plain strings or objects with GetString().
|
|
282
|
+
GetConnections: () => n("usd_probe_attribute_connections", ["number", "string", "string"], [i, l, h]).paths ?? [],
|
|
283
|
+
delete: () => {
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}, o = (i, l) => ({
|
|
287
|
+
__path: l,
|
|
288
|
+
__stageId: i,
|
|
289
|
+
IsValid: () => n("usd_probe_prim_info", ["number", "string"], [i, l]).valid === !0,
|
|
290
|
+
GetName: () => String(l.split("/").pop() ?? ""),
|
|
291
|
+
GetPath: () => new s(l),
|
|
292
|
+
GetTypeName: () => String(n("usd_probe_prim_info", ["number", "string"], [i, l]).typeName ?? ""),
|
|
293
|
+
IsInstance: () => n("usd_probe_prim_info", ["number", "string"], [i, l]).instance === !0,
|
|
294
|
+
GetAttribute: (h) => r(i, l, h),
|
|
295
|
+
GetAttributes: () => (n("usd_probe_prim_attributes", ["number", "string"], [i, l]).names ?? []).map((h) => r(i, l, h)),
|
|
296
|
+
GetChildren: () => (n("usd_probe_prim_children", ["number", "string"], [i, l]).paths ?? []).map((h) => o(i, h)),
|
|
297
|
+
GetMetadata: (h) => {
|
|
298
|
+
const u = n("usd_probe_prim_metadata", ["number", "string", "string"], [i, l, h]);
|
|
299
|
+
return u.valid !== !0 ? null : typeof u.text == "string" ? u.text : u.found === !0 ? u.value : null;
|
|
300
|
+
},
|
|
301
|
+
delete: () => {
|
|
302
|
+
}
|
|
303
|
+
}), a = (i) => ({
|
|
304
|
+
GetPrimAtPath: (l) => o(i, typeof l == "string" ? l : l.path),
|
|
305
|
+
GetPseudoRoot: () => Object.assign(o(i, "/"), {
|
|
306
|
+
// Stage-level metadata (metersPerUnit, upAxis, defaultPrim) is authored on
|
|
307
|
+
// the layer, not composed onto the pseudo-root prim.
|
|
308
|
+
GetMetadata: (l) => {
|
|
309
|
+
const h = n("usd_probe_stage_metadata", ["number", "string"], [i, l]);
|
|
310
|
+
return h.found === !0 ? h.value : null;
|
|
311
|
+
},
|
|
312
|
+
GetName: () => "",
|
|
313
|
+
IsValid: () => !0
|
|
314
|
+
}),
|
|
315
|
+
delete: () => {
|
|
316
|
+
}
|
|
317
|
+
}), { FS: c } = e;
|
|
318
|
+
return {
|
|
319
|
+
FS: {
|
|
320
|
+
createDir: (i) => c.mkdirTree(i),
|
|
321
|
+
writeFile: (i, l) => c.writeFile(i, l),
|
|
322
|
+
exists: (i) => c.analyzePath(i, !0).exists,
|
|
323
|
+
listDir: (i) => c.readdir(i).filter((l) => l !== "." && l !== "..").map((l) => {
|
|
324
|
+
const h = `${i.replace(/\/+$/, "")}/${l}`;
|
|
325
|
+
return { path: h, name: l, isDir: c.isDir(c.stat(h).mode) };
|
|
326
|
+
}),
|
|
327
|
+
deleteFile: (i) => c.unlink(i),
|
|
328
|
+
deleteDir: (i) => c.rmdir(i)
|
|
329
|
+
},
|
|
330
|
+
Sdf: { Path: s },
|
|
331
|
+
Usd: { TimeCode: { Default: () => ({ delete: () => {
|
|
332
|
+
} }) } },
|
|
333
|
+
UsdShade: {
|
|
334
|
+
ComputeBoundMaterialPath: (i) => {
|
|
335
|
+
const l = n("usd_probe_bound_material", ["number", "string"], [i.__stageId, i.__path]);
|
|
336
|
+
return l.found !== !0 ? null : {
|
|
337
|
+
materialPath: String(l.materialPath ?? ""),
|
|
338
|
+
resolvedTargetPath: String(l.resolvedTargetPath ?? ""),
|
|
339
|
+
bindingRelationshipPath: String(l.bindingRelationshipPath ?? "")
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
UsdUtils: {
|
|
344
|
+
ExtractSanitizedExternalReferences: (i) => n("usd_probe_external_references", ["string"], [i]).paths ?? []
|
|
345
|
+
},
|
|
346
|
+
openStage: a
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function ws(e, t, n) {
|
|
350
|
+
const s = JSON.parse(e.ccall("usd_probe_scene_data", "string", ["number", "string"], [t, n]));
|
|
351
|
+
if (s.error) throw new Error(s.error);
|
|
352
|
+
const r = s;
|
|
353
|
+
for (const o of r.elements)
|
|
354
|
+
o.geometry = Object.fromEntries(
|
|
355
|
+
Object.entries(o.geometry).map(([a, c]) => [a, bs(e, c)])
|
|
356
|
+
);
|
|
357
|
+
return r;
|
|
358
|
+
}
|
|
359
|
+
function bs(e, t) {
|
|
360
|
+
if (!t || typeof t != "object") return t ?? null;
|
|
361
|
+
const { ptr: n, length: s, kind: r } = t;
|
|
362
|
+
return typeof n != "number" ? t : s ? (r === "i32" ? new Int32Array(e.HEAP32.buffer, n, s) : new Float32Array(e.HEAPF32.buffer, n, s)).slice() : r === "i32" ? new Int32Array() : new Float32Array();
|
|
363
|
+
}
|
|
364
|
+
async function Ss(e, t, n, s, r, o, a, c, i, l, h, u, d, p, f) {
|
|
365
|
+
const _ = {};
|
|
366
|
+
let w = [
|
|
367
|
+
{ url: t, depth: 0, recurse: !0, absolute: !1 }
|
|
368
|
+
];
|
|
369
|
+
const g = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Set();
|
|
370
|
+
for (; w.length; ) {
|
|
371
|
+
const y = w;
|
|
372
|
+
w = [];
|
|
373
|
+
const S = [];
|
|
374
|
+
for (const m of y) {
|
|
375
|
+
const x = m.absolute ? m.url.href : ut(m.url.href, t);
|
|
376
|
+
if (!g.has(x)) {
|
|
377
|
+
if (m.depth > l) throw new Error(`USD dependency depth limit exceeded (${l}): ${x}`);
|
|
378
|
+
if (g.size >= i) throw new Error(`USD dependency limit exceeded (${i}).`);
|
|
379
|
+
g.add(x), S.push({ item: m, identifier: x });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
w = (await vs(
|
|
383
|
+
S,
|
|
384
|
+
Math.max(1, h),
|
|
385
|
+
async ({ item: m, identifier: x }) => {
|
|
386
|
+
const R = We(m.url.href, n);
|
|
387
|
+
if (!o.has(R) || m.absolute && !d.has(R)) {
|
|
388
|
+
let C;
|
|
389
|
+
try {
|
|
390
|
+
C = await s(m.url, x);
|
|
391
|
+
} catch (F) {
|
|
392
|
+
if (!m.owner || !Qn(x) || !es(F)) throw F;
|
|
393
|
+
const I = `${n}/__unavailable__/${encodeURIComponent(x)}`;
|
|
394
|
+
return _[m.owner.path][m.owner.reference] = I, a.set(I, x), f == null || f(x, F), [];
|
|
395
|
+
}
|
|
396
|
+
c.set(R, mt(C)), gt(e, R, C, o);
|
|
397
|
+
}
|
|
398
|
+
if (a.set(R, x), !m.recurse) return [];
|
|
399
|
+
if (_[R] ?? (_[R] = {}), c.get(R) === !1) return [];
|
|
400
|
+
const A = r("usd_probe_external_references", ["string"], [R]).paths ?? [], P = [];
|
|
401
|
+
for (const C of A) {
|
|
402
|
+
if (!C || /^(?:data|blob):/i.test(C) || /\.mdl(?:[?#].*)?$/i.test(C)) continue;
|
|
403
|
+
let F;
|
|
404
|
+
try {
|
|
405
|
+
F = new URL(C, m.url);
|
|
406
|
+
} catch {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
const I = /^(?:[a-z][a-z\d+.-]*:|\/)/i.test(C), O = We(F.href, n), V = m.absolute || I;
|
|
410
|
+
if (u === "package" && !d.has(O) && !Rt(F, t)) {
|
|
411
|
+
const U = V ? F.href : ut(F.href, t), X = `${n}/__skipped__/${encodeURIComponent(U)}`;
|
|
412
|
+
_[R][C] = X, a.set(X, U), b.has(U) || (b.add(U), p == null || p(U));
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
_[R][C] = O;
|
|
416
|
+
const q = V ? F.href : ut(F.href, t);
|
|
417
|
+
g.has(q) || P.push({
|
|
418
|
+
url: F,
|
|
419
|
+
depth: m.depth + 1,
|
|
420
|
+
recurse: Us(F.pathname),
|
|
421
|
+
absolute: V,
|
|
422
|
+
owner: { path: R, reference: C }
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
return P;
|
|
426
|
+
}
|
|
427
|
+
)).flat();
|
|
428
|
+
}
|
|
429
|
+
return _;
|
|
430
|
+
}
|
|
431
|
+
async function vs(e, t, n) {
|
|
432
|
+
const s = new Array(e.length);
|
|
433
|
+
let r = 0;
|
|
434
|
+
const o = Array.from({ length: Math.min(t, e.length) }, async () => {
|
|
435
|
+
for (; r < e.length; ) {
|
|
436
|
+
const a = r++;
|
|
437
|
+
s[a] = await n(e[a]);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
return await Promise.all(o), s;
|
|
441
|
+
}
|
|
442
|
+
function Us(e) {
|
|
443
|
+
var n, s;
|
|
444
|
+
const t = (s = (n = e.split(/[?#]/, 1)[0]) == null ? void 0 : n.split(".").pop()) == null ? void 0 : s.toLowerCase();
|
|
445
|
+
return t != null && _s.has(t);
|
|
446
|
+
}
|
|
447
|
+
function mt(e) {
|
|
448
|
+
let t = e[0] === 239 && e[1] === 187 && e[2] === 191 ? 3 : 0;
|
|
449
|
+
for (; t < e.length && t < 64 && /\s/.test(String.fromCharCode(e[t])); ) t += 1;
|
|
450
|
+
return !(e[t] === 35 && e[t + 1] === 117 && e[t + 2] === 115 && e[t + 3] === 100 && e[t + 4] === 97) || e.includes(64);
|
|
451
|
+
}
|
|
452
|
+
function ut(e, t) {
|
|
453
|
+
const n = new URL(e);
|
|
454
|
+
if (n.protocol !== t.protocol || n.host !== t.host) return n.href;
|
|
455
|
+
const s = new URL(".", t).pathname.split("/").filter(Boolean), r = n.pathname.split("/").filter(Boolean);
|
|
456
|
+
let o = 0;
|
|
457
|
+
for (; o < s.length && s[o] === r[o]; ) o++;
|
|
458
|
+
const a = [...s.slice(o).map(() => ".."), ...r.slice(o)].join("/");
|
|
459
|
+
return decodeURIComponent(a) + n.search + n.hash;
|
|
460
|
+
}
|
|
461
|
+
function We(e, t) {
|
|
462
|
+
const n = new URL(e), s = encodeURIComponent(`${n.protocol}//${n.host}`);
|
|
463
|
+
let r = n.pathname.split("/").map((o) => decodeURIComponent(o).replaceAll("/", "%2F").replaceAll("\\", "%5C")).join("/");
|
|
464
|
+
if (n.search || n.hash) {
|
|
465
|
+
const o = r.lastIndexOf("."), a = o > r.lastIndexOf("/") ? o : r.length;
|
|
466
|
+
r = `${r.slice(0, a)}.__url_${encodeURIComponent(n.search + n.hash)}${r.slice(a)}`;
|
|
467
|
+
}
|
|
468
|
+
return `${t}/${s}${r}`;
|
|
469
|
+
}
|
|
470
|
+
function _t(e, t) {
|
|
471
|
+
if (!e || typeof e != "object" || ArrayBuffer.isView(e)) return;
|
|
472
|
+
const n = e;
|
|
473
|
+
if (typeof n.path == "string" && typeof n.resolvedPath == "string") {
|
|
474
|
+
for (const s of ["path", "resolvedPath"]) {
|
|
475
|
+
const r = n[s];
|
|
476
|
+
n[s] = t.get(r) ?? r;
|
|
477
|
+
}
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
for (const s of Object.values(e)) _t(s, t);
|
|
481
|
+
}
|
|
482
|
+
function pn(e, t) {
|
|
483
|
+
if (e.analyzePath(t).exists) {
|
|
484
|
+
for (const n of e.readdir(t)) {
|
|
485
|
+
if (n === "." || n === "..") continue;
|
|
486
|
+
const s = `${t}/${n}`;
|
|
487
|
+
e.isDir(e.stat(s).mode) ? pn(e, s) : e.unlink(s);
|
|
488
|
+
}
|
|
489
|
+
e.rmdir(t);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function gt(e, t, n, s) {
|
|
493
|
+
s.has(t) || (e.FS.mkdirTree(t.split("/").slice(0, -1).join("/") || "/"), e.FS.writeFile(t, n), s.add(t));
|
|
494
|
+
}
|
|
495
|
+
async function Vt(e) {
|
|
496
|
+
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());
|
|
497
|
+
}
|
|
498
|
+
async function Ps(e) {
|
|
499
|
+
if (!e) throw new Error("createSingleThreadUsd needs wasmUrl or wasmBinary.");
|
|
500
|
+
return (await fetch(e)).arrayBuffer();
|
|
501
|
+
}
|
|
502
|
+
const Os = "/openusd/";
|
|
503
|
+
function Rs(e) {
|
|
504
|
+
const t = (e ?? Os).replace(/\/*$/, "/"), n = typeof document > "u" ? new URL(t, "file:///").href : new URL(t, document.baseURI).href;
|
|
505
|
+
return {
|
|
506
|
+
moduleUrl: new URL("openusd_probe.js", n).href,
|
|
507
|
+
wasmUrl: new URL("openusd_probe.wasm", n).href
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function Is(e) {
|
|
511
|
+
var c, i;
|
|
512
|
+
const t = e.stage, n = e.pxr;
|
|
513
|
+
if (!t || !((c = n == null ? void 0 : n.Sdf) != null && c.Path) || !((i = n == null ? void 0 : n.Usd) != null && i.TimeCode)) return;
|
|
514
|
+
const s = n.Usd.TimeCode.Default(), r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), a = (l) => {
|
|
515
|
+
let h, u, d;
|
|
516
|
+
try {
|
|
517
|
+
if (h = new n.Sdf.Path(l), u = t.GetPrimAtPath(h), !u.IsValid() || (d = u.GetAttribute("doubleSided"), !d.IsValid() || typeof d.HasAuthoredValue != "function")) return "unknown";
|
|
518
|
+
if (!d.HasAuthoredValue()) return;
|
|
519
|
+
const p = d.Get(s);
|
|
520
|
+
return typeof p == "boolean" ? p : "unknown";
|
|
521
|
+
} catch {
|
|
522
|
+
return "unknown";
|
|
523
|
+
} finally {
|
|
524
|
+
d == null || d.delete(), u == null || u.delete(), h == null || h.delete();
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
try {
|
|
528
|
+
e.scene.traverse((l) => {
|
|
529
|
+
var f;
|
|
530
|
+
if (!(l instanceof me)) return;
|
|
531
|
+
const h = (f = l.userData.usd) == null ? void 0 : f.path;
|
|
532
|
+
if (typeof h != "string") return;
|
|
533
|
+
const u = a(h);
|
|
534
|
+
if (u === "unknown") return;
|
|
535
|
+
const d = u === !1 ? $n : Nn, p = (_) => {
|
|
536
|
+
if (!(_ instanceof K) || _.transmission <= 0 || _.metalness !== 0 || _.side === d) return _;
|
|
537
|
+
let w = r.get(_);
|
|
538
|
+
w || (w = /* @__PURE__ */ new Map(), r.set(_, w));
|
|
539
|
+
let g = w.get(d);
|
|
540
|
+
return g || (g = _.clone(), g.side = d, g.needsUpdate = !0, g.userData.usdGlassSidePolicy = u === !1 ? "authored-false" : u === !0 ? "authored-true" : "viewer-default-double", w.set(d, g)), o.add(_), g;
|
|
541
|
+
};
|
|
542
|
+
if (Array.isArray(l.material)) {
|
|
543
|
+
const _ = l.material, w = _.map(p);
|
|
544
|
+
w.some((g, b) => g !== _[b]) && (l.material = w);
|
|
545
|
+
} else {
|
|
546
|
+
const _ = p(l.material);
|
|
547
|
+
_ !== l.material && (l.material = _);
|
|
548
|
+
}
|
|
549
|
+
}), e.scene.traverse((l) => {
|
|
550
|
+
if (l instanceof me) for (const h of Array.isArray(l.material) ? l.material : [l.material]) o.delete(h);
|
|
551
|
+
});
|
|
552
|
+
for (const l of o) l.dispose();
|
|
553
|
+
} finally {
|
|
554
|
+
s.delete();
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
function As(e, t) {
|
|
558
|
+
if (!e.stage || t.shaders.length) return null;
|
|
559
|
+
const n = e.stage, s = e.pxr, r = s.Usd.TimeCode.Default(), o = (i, l) => {
|
|
560
|
+
const h = new s.Sdf.Path(i), u = n.GetPrimAtPath(h);
|
|
561
|
+
try {
|
|
562
|
+
if (!u.IsValid()) throw new Error("Missing prim");
|
|
563
|
+
return l(u);
|
|
564
|
+
} finally {
|
|
565
|
+
u.delete(), h.delete();
|
|
566
|
+
}
|
|
567
|
+
}, a = (i) => {
|
|
568
|
+
const l = i.GetConnections();
|
|
569
|
+
try {
|
|
570
|
+
return l.map((h) => typeof h == "string" ? h : h.GetString());
|
|
571
|
+
} finally {
|
|
572
|
+
for (const h of l) typeof h != "string" && h.delete();
|
|
573
|
+
}
|
|
574
|
+
}, c = (i, l = /* @__PURE__ */ new Set()) => {
|
|
575
|
+
if (l.has(i) || l.size >= 32) throw new Error("Cyclic material input");
|
|
576
|
+
l.add(i);
|
|
577
|
+
const h = i.lastIndexOf(".");
|
|
578
|
+
if (h < 0 || !i.slice(h + 1).startsWith("inputs:")) throw new Error("Not a constant input");
|
|
579
|
+
return o(i.slice(0, h), (u) => {
|
|
580
|
+
const d = u.GetAttribute(i.slice(h + 1));
|
|
581
|
+
try {
|
|
582
|
+
if (!d.IsValid()) throw new Error("Missing material input");
|
|
583
|
+
const p = a(d);
|
|
584
|
+
if (p.length > 1) throw new Error("Ambiguous material input");
|
|
585
|
+
const f = p.length ? c(p[0], l) : d.Get(r);
|
|
586
|
+
if (f == null) throw new Error("Unauthored material input");
|
|
587
|
+
return f;
|
|
588
|
+
} finally {
|
|
589
|
+
d.delete();
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
};
|
|
593
|
+
try {
|
|
594
|
+
return o(t.path, (i) => {
|
|
595
|
+
if (!i.IsInstance()) return null;
|
|
596
|
+
const l = i.GetAttribute("outputs:surface");
|
|
597
|
+
let h;
|
|
598
|
+
try {
|
|
599
|
+
if (!l.IsValid()) return null;
|
|
600
|
+
h = a(l);
|
|
601
|
+
} finally {
|
|
602
|
+
l.delete();
|
|
603
|
+
}
|
|
604
|
+
if (h.length !== 1 || !h[0].endsWith(".outputs:surface")) return null;
|
|
605
|
+
const u = h[0].slice(0, -16);
|
|
606
|
+
return o(u, (d) => {
|
|
607
|
+
const p = d.GetAttribute("info:id");
|
|
608
|
+
try {
|
|
609
|
+
if (p.Get(r) !== "UsdPreviewSurface") return null;
|
|
610
|
+
} finally {
|
|
611
|
+
p.delete();
|
|
612
|
+
}
|
|
613
|
+
const f = {}, _ = d.GetAttributes();
|
|
614
|
+
try {
|
|
615
|
+
for (const g of _) {
|
|
616
|
+
const b = String(g.GetName());
|
|
617
|
+
b.startsWith("inputs:") && (f[b] = c(`${u}.${b}`));
|
|
618
|
+
}
|
|
619
|
+
} finally {
|
|
620
|
+
for (const g of _) g.delete();
|
|
621
|
+
}
|
|
622
|
+
return { ...t, shaders: [{ path: u, id: "UsdPreviewSurface", inputs: f }] };
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
} catch {
|
|
626
|
+
return null;
|
|
627
|
+
} finally {
|
|
628
|
+
r.delete();
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function Ae(e, t, n = 1, s = 0, r = "rgb") {
|
|
632
|
+
var d;
|
|
633
|
+
const o = e.image, a = (o == null ? void 0 : o.naturalWidth) || (o == null ? void 0 : o.width), c = (o == null ? void 0 : o.naturalHeight) || (o == null ? void 0 : o.height);
|
|
634
|
+
if (!Number.isInteger(a) || !Number.isInteger(c) || a <= 0 || c <= 0) throw new Error("Texture has no decoded pixels");
|
|
635
|
+
let i;
|
|
636
|
+
if (e instanceof Tt) {
|
|
637
|
+
if (e.type !== $t || e.format !== Nt || ((d = o.data) == null ? void 0 : d.length) !== a * c * 4) throw new Error("Unsupported scalar pixel format");
|
|
638
|
+
i = o.data;
|
|
639
|
+
} else {
|
|
640
|
+
const p = document.createElement("canvas");
|
|
641
|
+
p.width = a, p.height = c;
|
|
642
|
+
const f = p.getContext("2d", { willReadFrequently: !0 });
|
|
643
|
+
if (!f) throw new Error("Scalar conversion requires a 2D canvas");
|
|
644
|
+
f.drawImage(o, 0, 0), i = f.getImageData(0, 0, a, c).data;
|
|
645
|
+
}
|
|
646
|
+
const l = new Uint8Array(a * c * 4), h = "rgba".indexOf(t);
|
|
647
|
+
for (let p = 0; p < l.length; p += 4) {
|
|
648
|
+
const f = i[p], _ = i[p + 1], w = i[p + 2];
|
|
649
|
+
if (t === "grayscale" && (f !== _ || _ !== w)) throw new Error("Non-grayscale scalar image needs an explicit mono convention");
|
|
650
|
+
const g = t === "average" ? (f + _ + w) / 3 : t === "luminance" ? 0.2126 * f + 0.7152 * _ + 0.0722 * w : t === "maximum" ? Math.max(f, _, w) : t === "grayscale" ? f : i[p + h], b = Math.round(255 * Math.min(1, Math.max(0, g / 255 * n + s)));
|
|
651
|
+
l[p] = l[p + 1] = l[p + 2] = b, l[p + 3] = r === "a" ? b : 255;
|
|
652
|
+
}
|
|
653
|
+
const u = new Tt(l, a, c, Nt, $t);
|
|
654
|
+
return u.wrapS = e.wrapS, u.wrapT = e.wrapT, u.offset.copy(e.offset), u.repeat.copy(e.repeat), u.center.copy(e.center), u.rotation = e.rotation, u.matrix.copy(e.matrix), u.matrixAutoUpdate = e.matrixAutoUpdate, u.channel = e.channel, u.flipY = e.flipY, u.minFilter = e.minFilter, u.magFilter = e.magFilter, u.anisotropy = e.anisotropy, u.generateMipmaps = e.generateMipmaps, u.colorSpace = oe, u.needsUpdate = !0, u;
|
|
655
|
+
}
|
|
656
|
+
const Ms = [1, 1, 1, 1], xs = [0, 0, 0, 0];
|
|
657
|
+
function zt(e, t) {
|
|
658
|
+
const n = [], s = e.shaders.map((o) => ({
|
|
659
|
+
path: o.path,
|
|
660
|
+
id: o.id,
|
|
661
|
+
inputs: Object.freeze({ ...o.inputs }),
|
|
662
|
+
connections: fn(o)
|
|
663
|
+
})), r = t ? Cs(e, t, n) : [];
|
|
664
|
+
return Object.freeze({
|
|
665
|
+
schemaVersion: 1,
|
|
666
|
+
materialPath: e.path,
|
|
667
|
+
surfacePath: (t == null ? void 0 : t.path) ?? null,
|
|
668
|
+
surfaceShaderId: (t == null ? void 0 : t.id) ?? null,
|
|
669
|
+
dialect: Ds(t),
|
|
670
|
+
workflow: Es(e, t),
|
|
671
|
+
materialInputs: Object.freeze({ ...e.inputs }),
|
|
672
|
+
alpha: Ts(e, t),
|
|
673
|
+
nodes: Object.freeze(s),
|
|
674
|
+
textures: Object.freeze(r),
|
|
675
|
+
issues: Object.freeze(n),
|
|
676
|
+
program: null
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
function we(e) {
|
|
680
|
+
const t = Array.isArray(e) ? e[0] : e;
|
|
681
|
+
if (typeof t != "string" || t.length === 0) return null;
|
|
682
|
+
const n = /^(.*?)(?:\.outputs:([^/]+))?$/.exec(t);
|
|
683
|
+
return n != null && n[1] ? { path: n[1], outputName: n[2] ?? null } : null;
|
|
684
|
+
}
|
|
685
|
+
function fn(e) {
|
|
686
|
+
const t = /* @__PURE__ */ new Map(), n = (s, r) => {
|
|
687
|
+
const o = r ? ".resolvedConnect" : ".connect";
|
|
688
|
+
if (!s.endsWith(o)) return;
|
|
689
|
+
const a = s.slice(0, -o.length);
|
|
690
|
+
if (r)
|
|
691
|
+
t.delete(a);
|
|
692
|
+
else if (t.has(a))
|
|
693
|
+
return;
|
|
694
|
+
const c = we(e.inputs[s]);
|
|
695
|
+
c && t.set(a, {
|
|
696
|
+
inputName: a.replace(/^inputs:/, ""),
|
|
697
|
+
sourcePath: c.path,
|
|
698
|
+
outputName: c.outputName
|
|
699
|
+
});
|
|
700
|
+
};
|
|
701
|
+
for (const s of Object.keys(e.inputs)) n(s, !0);
|
|
702
|
+
for (const s of Object.keys(e.inputs)) n(s, !1);
|
|
703
|
+
return Object.freeze([...t.values()]);
|
|
704
|
+
}
|
|
705
|
+
function Cs(e, t, n) {
|
|
706
|
+
const s = [];
|
|
707
|
+
for (const r of fn(t)) {
|
|
708
|
+
let o = r.sourcePath, a = r.outputName;
|
|
709
|
+
const c = dn(e, o);
|
|
710
|
+
if (c) {
|
|
711
|
+
const f = e.inputs[`inputs:${c}.resolvedConnect`] ?? e.inputs[`inputs:${c}.connect`], _ = we(f);
|
|
712
|
+
if (_)
|
|
713
|
+
o = _.path, a = _.outputName;
|
|
714
|
+
else if (e.inputs[`inputs:${c}`] !== void 0)
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
const i = e.shaders.find((f) => f.path === o);
|
|
718
|
+
if (!i) {
|
|
719
|
+
n.push({
|
|
720
|
+
code: "DANGLING_CONNECTION",
|
|
721
|
+
sourcePath: o,
|
|
722
|
+
message: `材质 ${e.path} 的输入 ${r.inputName} 指向不存在的 shader ${o}。`
|
|
723
|
+
});
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
const l = Gs(r.inputName), h = Bs(i) ?? (l === "normal" ? be(ve(i, ["texture"])) : null);
|
|
727
|
+
if (!h) {
|
|
728
|
+
_n(i) ? n.push({
|
|
729
|
+
code: "MISSING_TEXTURE_ASSET",
|
|
730
|
+
sourcePath: i.path,
|
|
731
|
+
message: `材质 ${e.path} 的纹理 ${i.path} 没有可解析的资源路径。`
|
|
732
|
+
}) : n.push({
|
|
733
|
+
code: "UNSUPPORTED_SURFACE_NODE",
|
|
734
|
+
sourcePath: i.path,
|
|
735
|
+
message: `材质 ${e.path} 的输入 ${r.inputName} 连接到尚未求值的节点 ${i.id ?? i.path}。`
|
|
736
|
+
});
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
const u = Fs(a);
|
|
740
|
+
if (!u) {
|
|
741
|
+
n.push({
|
|
742
|
+
code: "UNKNOWN_TEXTURE_OUTPUT",
|
|
743
|
+
sourcePath: i.path,
|
|
744
|
+
message: `材质 ${e.path} 的纹理 ${i.path} 使用未知输出 ${a ?? "<null>"}。`
|
|
745
|
+
});
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
const d = jt(i, "scale", Ms), p = jt(i, "bias", xs);
|
|
749
|
+
s.push(Object.freeze({
|
|
750
|
+
surfaceInput: r.inputName,
|
|
751
|
+
shaderPath: i.path,
|
|
752
|
+
path: h,
|
|
753
|
+
sourceChannel: u,
|
|
754
|
+
semantic: l,
|
|
755
|
+
sourceColorSpace: Ws(i, l),
|
|
756
|
+
scale: d,
|
|
757
|
+
bias: p,
|
|
758
|
+
uvSet: Ls(e, i),
|
|
759
|
+
uvTransform: ks(e, i, n),
|
|
760
|
+
wrapS: Wt(i, "wrapS", "wrap_s"),
|
|
761
|
+
wrapT: Wt(i, "wrapT", "wrap_t"),
|
|
762
|
+
fallback: zs(i, ["fallback", "value"]),
|
|
763
|
+
...Xs(i)
|
|
764
|
+
}));
|
|
765
|
+
}
|
|
766
|
+
return s;
|
|
767
|
+
}
|
|
768
|
+
function dn(e, t) {
|
|
769
|
+
const n = /^(.*)\.inputs:([^/.]+)$/.exec(t);
|
|
770
|
+
return (n == null ? void 0 : n[1]) === e.path && n[2] ? n[2] : null;
|
|
771
|
+
}
|
|
772
|
+
function Ds(e) {
|
|
773
|
+
var o;
|
|
774
|
+
if (!e) return "unknown";
|
|
775
|
+
const t = e.id ?? "";
|
|
776
|
+
if (/^(?:UsdPreviewSurface|ND_UsdPreviewSurface_surfaceshader)$/i.test(t)) return "usd-preview";
|
|
777
|
+
if (/open.?pbr/i.test(t)) return "openpbr";
|
|
778
|
+
if (/standard.?surface/i.test(t) && /mtlx|ND_/i.test(t) || /standard.?surface/i.test(t)) return "materialx-standard-surface";
|
|
779
|
+
if (/PxrSurface/i.test(t)) return "pxr-surface";
|
|
780
|
+
const n = be(e.inputs["info:mdl:sourceAsset"]), s = (o = n == null ? void 0 : n.split(/[\\/]/).at(-1)) == null ? void 0 : o.toLowerCase(), r = Fe(e, "info:mdl:sourceAsset:subIdentifier");
|
|
781
|
+
return s === "omnipbr.mdl" ? "omnipbr" : gn(e) ? "omni-pbr-base" : s === "omniglass.mdl" ? "omniglass" : s === "omnisurfacebase.mdl" || (r == null ? void 0 : r.toLowerCase()) === "omnisurfacebase" ? "omni-surface-base" : At(e) ? "gltf-material" : "unknown";
|
|
782
|
+
}
|
|
783
|
+
function Es(e, t) {
|
|
784
|
+
return t ? At(t) ? "metallic" : js(t) ? "specular" : gn(t) ? "metallic" : /UsdPreviewSurface/i.test(t.id ?? "") ? Ie(e, t, ["useSpecularWorkflow"]).value === !0 ? "specular" : "metallic" : "unknown" : "unknown";
|
|
785
|
+
}
|
|
786
|
+
function Ts(e, t) {
|
|
787
|
+
if (!t) return Object.freeze({ mode: "opaque", cutoff: 0, opacityMode: null });
|
|
788
|
+
if (At(t)) return $s(e, t);
|
|
789
|
+
if (Ns(t) && !mn(t, "enable_opacity", !1))
|
|
790
|
+
return Object.freeze({ mode: "opaque", cutoff: 0, opacityMode: null });
|
|
791
|
+
const n = yt(Ie(
|
|
792
|
+
e,
|
|
793
|
+
t,
|
|
794
|
+
["opacityThreshold", "opacity_threshold", "geometry_opacity_threshold", "alphaCutoff"]
|
|
795
|
+
).value) ?? 0, s = Ie(e, t, ["opacityMode"]).value, r = s === "presence" ? "presence" : s === "transparent" ? "transparent" : null;
|
|
796
|
+
if (n > 0)
|
|
797
|
+
return Object.freeze({ mode: "mask", cutoff: wt(n), opacityMode: r });
|
|
798
|
+
const a = Vs(Ie(
|
|
799
|
+
e,
|
|
800
|
+
t,
|
|
801
|
+
["opacity", "presence", "geometry_opacity", "opacity_constant"]
|
|
802
|
+
).value).some((i) => i < 1), c = ["opacity", "presence", "geometry_opacity", "opacity_constant"].some((i) => Ie(e, t, [i]).connection !== null);
|
|
803
|
+
return Object.freeze({
|
|
804
|
+
mode: a || c ? "blend" : "opaque",
|
|
805
|
+
cutoff: 0,
|
|
806
|
+
opacityMode: r
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function $s(e, t) {
|
|
810
|
+
const n = Ie(e, t, ["alpha_mode"]).value, s = n === 1 || n === "mask" ? "mask" : n === 2 || n === "blend" ? "blend" : "opaque";
|
|
811
|
+
if (s === "mask") {
|
|
812
|
+
const r = yt(Ie(
|
|
813
|
+
e,
|
|
814
|
+
t,
|
|
815
|
+
["alpha_cutoff"]
|
|
816
|
+
).value) ?? 0.5;
|
|
817
|
+
return Object.freeze({ mode: s, cutoff: wt(r), opacityMode: null, opacity: null });
|
|
818
|
+
}
|
|
819
|
+
if (s === "blend") {
|
|
820
|
+
const r = yt(Ie(
|
|
821
|
+
e,
|
|
822
|
+
t,
|
|
823
|
+
["base_alpha"]
|
|
824
|
+
).value) ?? 1;
|
|
825
|
+
return Object.freeze({
|
|
826
|
+
mode: s,
|
|
827
|
+
cutoff: 0,
|
|
828
|
+
opacityMode: "transparent",
|
|
829
|
+
opacity: wt(r)
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
return Object.freeze({ mode: s, cutoff: 0, opacityMode: null, opacity: null });
|
|
833
|
+
}
|
|
834
|
+
function Ns(e) {
|
|
835
|
+
var n, s;
|
|
836
|
+
const t = (s = (n = be(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : n.split(/[\\/]/).at(-1)) == null ? void 0 : s.toLowerCase();
|
|
837
|
+
return t === "omnipbr.mdl" || t === "omnipbrbase.mdl" || t === "omniglass.mdl";
|
|
838
|
+
}
|
|
839
|
+
function Bs(e) {
|
|
840
|
+
return _n(e) ? be(ve(e, ["file", "filename", "texture"])) : null;
|
|
841
|
+
}
|
|
842
|
+
function Ls(e, t) {
|
|
843
|
+
if (st(t)) {
|
|
844
|
+
const r = Le(t, ["tex_coord_index"]);
|
|
845
|
+
return r !== null && Number.isInteger(r) && r >= 0 ? `texcoord${r}` : null;
|
|
846
|
+
}
|
|
847
|
+
const n = we(t.inputs["inputs:st.resolvedConnect"] ?? t.inputs["inputs:st.connect"]);
|
|
848
|
+
if (!n) return null;
|
|
849
|
+
let s = e.shaders.find((r) => r.path === n.path);
|
|
850
|
+
if (s && /^(?:UsdTransform2d|ND_transform2d_vector2)$/i.test(s.id ?? "")) {
|
|
851
|
+
const r = we(
|
|
852
|
+
s.inputs["inputs:in.resolvedConnect"] ?? s.inputs["inputs:in.connect"]
|
|
853
|
+
);
|
|
854
|
+
s = r ? e.shaders.find((o) => o.path === r.path) : void 0;
|
|
855
|
+
}
|
|
856
|
+
return s ? hn(s, ["varname"]) : null;
|
|
857
|
+
}
|
|
858
|
+
function ks(e, t, n) {
|
|
859
|
+
if (st(t)) {
|
|
860
|
+
const o = Je(t, "scale", [1, 1]), a = Le(t, ["rotation"]) ?? 0, c = Je(t, "offset", [0, 0]);
|
|
861
|
+
return o[0] === 1 && o[1] === 1 && a === 0 && c[0] === 0 && c[1] === 0 ? null : Object.freeze({
|
|
862
|
+
sourcePath: t.path,
|
|
863
|
+
scale: o,
|
|
864
|
+
rotation: a * 180 / Math.PI,
|
|
865
|
+
translation: c
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
const s = we(t.inputs["inputs:st.resolvedConnect"] ?? t.inputs["inputs:st.connect"]);
|
|
869
|
+
if (!s) return null;
|
|
870
|
+
const r = e.shaders.find((o) => o.path === s.path);
|
|
871
|
+
return !r || /^UsdPrimvarReader_float2$/i.test(r.id ?? "") ? null : /^(?:UsdTransform2d|ND_transform2d_vector2)$/i.test(r.id ?? "") ? Object.freeze({
|
|
872
|
+
sourcePath: r.path,
|
|
873
|
+
scale: Je(r, "scale", [1, 1]),
|
|
874
|
+
rotation: Le(r, ["rotation"]) ?? 0,
|
|
875
|
+
translation: Je(r, "translation", [0, 0])
|
|
876
|
+
}) : (n.push({
|
|
877
|
+
code: "TEXTURE_UV_UNSUPPORTED",
|
|
878
|
+
sourcePath: r.path,
|
|
879
|
+
message: `材质纹理 ${t.path} 的 UV 上游 ${r.id ?? r.path} 尚未映射。`
|
|
880
|
+
}), null);
|
|
881
|
+
}
|
|
882
|
+
function Fs(e) {
|
|
883
|
+
return !e || /^(?:out|result)$/i.test(e) ? "rgb" : /^(?:mono|resultMono)$/i.test(e) ? "mono" : /^(?:tint|resultTint)$/i.test(e) ? "rgb" : /^(?:r|resultR)$/i.test(e) ? "r" : /^(?:g|resultG)$/i.test(e) ? "g" : /^(?:b|resultB)$/i.test(e) ? "b" : /^(?:a|resultA|alpha)$/i.test(e) ? "a" : /^(?:rgb|resultRGB)$/i.test(e) ? "rgb" : null;
|
|
884
|
+
}
|
|
885
|
+
function Gs(e) {
|
|
886
|
+
return /(?:roughness|metalness|metallic|occlusion|opacity|transmission|thickness)$/i.test(e) ? "scalar" : /(?:^|\.)(?:normal|normal_texture|normalmap_texture|normalCamera|geometry_normal)$/i.test(e) ? "normal" : /(?:diffuse|base.?color|emission|emissive|sheen|fuzz|specular.?color|coat.?color)/i.test(e) ? "color" : "scalar";
|
|
887
|
+
}
|
|
888
|
+
function ve(e, t) {
|
|
889
|
+
for (const n of t) {
|
|
890
|
+
const s = e.inputs[`inputs:${n}`];
|
|
891
|
+
if (s !== void 0) return s;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function Ie(e, t, n) {
|
|
895
|
+
for (const s of n) {
|
|
896
|
+
const r = we(
|
|
897
|
+
t.inputs[`inputs:${s}.resolvedConnect`] ?? t.inputs[`inputs:${s}.connect`]
|
|
898
|
+
);
|
|
899
|
+
if (r) {
|
|
900
|
+
const a = dn(e, r.path);
|
|
901
|
+
if (!a) return { value: void 0, connection: r };
|
|
902
|
+
const c = we(
|
|
903
|
+
e.inputs[`inputs:${a}.resolvedConnect`] ?? e.inputs[`inputs:${a}.connect`]
|
|
904
|
+
);
|
|
905
|
+
return c ? { value: void 0, connection: c } : {
|
|
906
|
+
value: e.inputs[`inputs:${a}`],
|
|
907
|
+
connection: null
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
const o = t.inputs[`inputs:${s}`];
|
|
911
|
+
if (o !== void 0) return { value: o, connection: null };
|
|
912
|
+
}
|
|
913
|
+
return { value: void 0, connection: null };
|
|
914
|
+
}
|
|
915
|
+
function yt(e) {
|
|
916
|
+
return typeof e == "number" && Number.isFinite(e) ? e : null;
|
|
917
|
+
}
|
|
918
|
+
function Vs(e) {
|
|
919
|
+
return typeof e == "number" && Number.isFinite(e) ? [e] : Array.isArray(e) ? e.every((t) => typeof t == "number" && Number.isFinite(t)) ? e : [] : [];
|
|
920
|
+
}
|
|
921
|
+
function hn(e, t) {
|
|
922
|
+
const n = ve(e, t);
|
|
923
|
+
return typeof n == "string" && n.length > 0 ? n : null;
|
|
924
|
+
}
|
|
925
|
+
function mn(e, t, n) {
|
|
926
|
+
const s = ve(e, [t]);
|
|
927
|
+
return typeof s == "boolean" ? s : n;
|
|
928
|
+
}
|
|
929
|
+
function jt(e, t, n) {
|
|
930
|
+
const s = ve(e, [t]);
|
|
931
|
+
return !Array.isArray(s) || s.length !== 4 ? n : s.every((r) => typeof r == "number" && Number.isFinite(r)) ? Object.freeze([...s]) : n;
|
|
932
|
+
}
|
|
933
|
+
function Je(e, t, n) {
|
|
934
|
+
const s = ve(e, [t]);
|
|
935
|
+
return Array.isArray(s) && s.length >= 2 && typeof s[0] == "number" && Number.isFinite(s[0]) && typeof s[1] == "number" && Number.isFinite(s[1]) ? Object.freeze([s[0], s[1]]) : n;
|
|
936
|
+
}
|
|
937
|
+
function zs(e, t) {
|
|
938
|
+
const n = ve(e, t);
|
|
939
|
+
return Array.isArray(n) && n.every((s) => typeof s == "number" && Number.isFinite(s)) ? Object.freeze([...n]) : null;
|
|
940
|
+
}
|
|
941
|
+
function Le(e, t) {
|
|
942
|
+
const n = ve(e, t);
|
|
943
|
+
return typeof n == "number" && Number.isFinite(n) ? n : null;
|
|
944
|
+
}
|
|
945
|
+
function wt(e) {
|
|
946
|
+
return Math.min(1, Math.max(0, e));
|
|
947
|
+
}
|
|
948
|
+
function _n(e) {
|
|
949
|
+
return /^(?:UsdUVTexture|PxrTexture|normalmap_texture)$/i.test(yn(e)) || st(e) || It(e);
|
|
950
|
+
}
|
|
951
|
+
function It(e) {
|
|
952
|
+
var s, r, o;
|
|
953
|
+
const t = (s = be(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : s.replaceAll("\\", "/"), n = (r = Fe(e, "info:mdl:sourceAsset:subIdentifier")) == null ? void 0 : r.toLowerCase();
|
|
954
|
+
return ((o = t == null ? void 0 : t.split("/").at(-1)) == null ? void 0 : o.toLowerCase()) === "core_definitions.mdl" && (n === "file_texture" || ve(e, ["texture"]) !== void 0);
|
|
955
|
+
}
|
|
956
|
+
function st(e) {
|
|
957
|
+
var s;
|
|
958
|
+
const t = yn(e);
|
|
959
|
+
if (/^(?:gltf_texture_lookup|gltf_normal_texture_lookup)$/i.test(t)) return !0;
|
|
960
|
+
const n = (s = be(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : s.replaceAll("\\", "/");
|
|
961
|
+
return /(?:^|\/)gltf\/pbr\.mdl$/i.test(n ?? "") ? be(e.inputs["inputs:texture"]) !== null && (e.inputs["inputs:tex_coord_index"] !== void 0 || e.inputs["inputs:wrap_s"] !== void 0 || e.inputs["inputs:wrap_t"] !== void 0) : !1;
|
|
962
|
+
}
|
|
963
|
+
function At(e) {
|
|
964
|
+
var s, r;
|
|
965
|
+
const t = (s = be(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : s.replaceAll("\\", "/");
|
|
966
|
+
if (!/(?:^|\/)gltf\/pbr\.mdl$/i.test(t ?? "")) return !1;
|
|
967
|
+
const n = (r = Fe(e, "info:mdl:sourceAsset:subIdentifier")) == null ? void 0 : r.toLowerCase();
|
|
968
|
+
return n ? n === "gltf_material" : [
|
|
969
|
+
"inputs:base_color_factor",
|
|
970
|
+
"inputs:metallic_factor",
|
|
971
|
+
"inputs:roughness_factor",
|
|
972
|
+
"inputs:alpha_mode",
|
|
973
|
+
"inputs:base_alpha",
|
|
974
|
+
"inputs:base_color_texture.connect",
|
|
975
|
+
"inputs:normal_texture.connect"
|
|
976
|
+
].some((o) => e.inputs[o] !== void 0);
|
|
977
|
+
}
|
|
978
|
+
function js(e) {
|
|
979
|
+
var n;
|
|
980
|
+
const t = (n = be(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : n.replaceAll("\\", "/");
|
|
981
|
+
return /(?:^|\/)OmniSurface\/OmniSurfaceBase\.mdl$/i.test(t ?? "") || (Fe(e, "info:mdl:sourceAsset:subIdentifier") ?? "").toLowerCase() === "omnisurfacebase";
|
|
982
|
+
}
|
|
983
|
+
function gn(e) {
|
|
984
|
+
var s, r, o;
|
|
985
|
+
const t = (s = be(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : s.replaceAll("\\", "/"), n = (r = Fe(e, "info:mdl:sourceAsset:subIdentifier")) == null ? void 0 : r.toLowerCase();
|
|
986
|
+
return ((o = t == null ? void 0 : t.split("/").at(-1)) == null ? void 0 : o.toLowerCase()) !== "omnipbrbase.mdl" ? !1 : n ? n === "omnipbrbase" : [
|
|
987
|
+
"inputs:diffuse_reflection_color",
|
|
988
|
+
"inputs:geometry_opacity",
|
|
989
|
+
"inputs:specular_level",
|
|
990
|
+
"inputs:enable_coat",
|
|
991
|
+
"inputs:specular_reflection_roughness"
|
|
992
|
+
].some((a) => e.inputs[a] !== void 0 || e.inputs[`${a}.connect`] !== void 0 || e.inputs[`${a}.resolvedConnect`] !== void 0);
|
|
993
|
+
}
|
|
994
|
+
function yn(e) {
|
|
995
|
+
return Fe(e, "info:mdl:sourceAsset:subIdentifier") ?? e.id ?? "";
|
|
996
|
+
}
|
|
997
|
+
function Ws(e, t) {
|
|
998
|
+
const n = hn(e, ["sourceColorSpace", "fileColorSpace"]);
|
|
999
|
+
return n && n.toLowerCase() !== "auto" ? n : t === "normal" ? "raw" : It(e) || st(e) || (n == null ? void 0 : n.toLowerCase()) === "auto" ? t === "color" ? "sRGB" : "raw" : null;
|
|
1000
|
+
}
|
|
1001
|
+
function Xs(e) {
|
|
1002
|
+
return It(e) ? {
|
|
1003
|
+
monoSource: Le(e, ["mono_source"]),
|
|
1004
|
+
brightness: Le(e, ["brightness"]) ?? 1,
|
|
1005
|
+
contrast: Le(e, ["contrast"]) ?? 1,
|
|
1006
|
+
invert: mn(e, "invert", !1)
|
|
1007
|
+
} : {};
|
|
1008
|
+
}
|
|
1009
|
+
function Wt(e, t, n) {
|
|
1010
|
+
const s = ve(e, [t, n]);
|
|
1011
|
+
return typeof s == "string" && s.length > 0 ? s : s === 10497 ? "repeat" : s === 33648 ? "mirror" : s === 33071 ? "clamp" : null;
|
|
1012
|
+
}
|
|
1013
|
+
function Fe(e, t) {
|
|
1014
|
+
const n = e.inputs[t];
|
|
1015
|
+
return typeof n == "string" && n.length > 0 ? n : null;
|
|
1016
|
+
}
|
|
1017
|
+
function be(e) {
|
|
1018
|
+
if (typeof e == "string") return e;
|
|
1019
|
+
if (!e || typeof e != "object") return null;
|
|
1020
|
+
for (const t of ["path", "resolvedPath", "url"]) {
|
|
1021
|
+
const n = e[t];
|
|
1022
|
+
if (typeof n == "string" && n.length > 0) return n;
|
|
1023
|
+
}
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
function Ks(e, t, n) {
|
|
1027
|
+
const s = [], r = [], o = [];
|
|
1028
|
+
let a = !1;
|
|
1029
|
+
const c = [], i = {}, l = (E) => E.some((B) => xe(e, n, B) !== null || Me(e, n, B) !== void 0), h = (E) => {
|
|
1030
|
+
for (const B of E) {
|
|
1031
|
+
if (xe(e, t, B)) return;
|
|
1032
|
+
const $ = Me(e, t, B);
|
|
1033
|
+
if ($ !== void 0) return $;
|
|
1034
|
+
}
|
|
1035
|
+
}, u = (E) => Xt(h(E)), d = (E) => Kt(h(E)), p = (E, B) => {
|
|
1036
|
+
c.push({ code: E, message: B });
|
|
1037
|
+
}, f = (E) => Kt(Me(e, n, E)), _ = (E) => Xt(Me(e, n, E)), w = u(["base_weight"]), g = d(["base_color", "baseColor"]), b = f(["diffuseColor", "baseColor", "base_color"]);
|
|
1038
|
+
l(["diffuseColor", "baseColor", "base_color"]) && o.push("openpbr:base_color", "openpbr:baseColor", "openpbr:diffuseColor"), n && b ? (i.color = b, s.push("PreviewSurface.base_color.dual-basic")) : l(["diffuseColor", "baseColor", "base_color"]) || (g ? w !== null && w !== 1 ? w < 0 ? r.push("OpenPBR.base_weight.range") : (i.color = g.multiplyScalar(w), s.push("OpenPBR.base_color.base_weight"), p(
|
|
1039
|
+
"USD_VISUAL_OPENPBR_BASE_WEIGHT_APPROXIMATION",
|
|
1040
|
+
"OpenPBR base_weight 已乘入基础颜色;未表达独立基础漫反射层与底层混合。"
|
|
1041
|
+
)) : (i.color = g, s.push("OpenPBR.base_color")) : w !== null && w < 1 && r.push("OpenPBR.base_weight.without-base-color"));
|
|
1042
|
+
const y = u(["base_metalness", "metalness"]), S = _(["metallic", "metalness"]);
|
|
1043
|
+
l(["metallic", "metalness"]) && o.push("openpbr:base_metalness", "openpbr:metalness", "openpbr:metallic"), n && S !== null && l(["metallic", "metalness"]) ? S >= 0 && S <= 1 ? (i.metalness = S, s.push("PreviewSurface.metalness.dual-basic")) : r.push("PreviewSurface.metallic.range") : y !== null && !l(["metallic", "metalness"]) && (y < 0 || y > 1 ? r.push("OpenPBR.base_metalness.range") : (i.metalness = y, s.push("OpenPBR.base_metalness")));
|
|
1044
|
+
const v = u(["specular_roughness", "roughness"]), m = _(["roughness"]);
|
|
1045
|
+
l(["roughness"]) && o.push("openpbr:specular_roughness", "openpbr:roughness"), n && m !== null && l(["roughness"]) ? m >= 0 && m <= 1 ? (i.roughness = m, s.push("PreviewSurface.roughness.dual-basic")) : r.push("PreviewSurface.roughness.range") : v !== null && !l(["roughness"]) && (v < 0 || v > 1 ? r.push("OpenPBR.specular_roughness.range") : (i.roughness = v, s.push("OpenPBR.specular_roughness"))), u(["base_diffuse_roughness"]) !== null && r.push("OpenPBR.base_diffuse_roughness");
|
|
1046
|
+
const R = u(["specular_ior"]);
|
|
1047
|
+
R !== null && (R < 1 || R > 2.333333 ? r.push("OpenPBR.specular_ior.range") : (y ?? 0) >= 1 ? r.push("OpenPBR.specular_ior.pure-metal") : (i.ior = R, s.push("OpenPBR.specular_ior")));
|
|
1048
|
+
const A = d(["emission_color", "emissiveColor"]);
|
|
1049
|
+
A && (i.emissive = A, s.push("OpenPBR.emission_color"));
|
|
1050
|
+
const P = u(["emission_luminance"]);
|
|
1051
|
+
P !== null && (P < 0 ? r.push("OpenPBR.emission_luminance.range") : (i.emissiveIntensity = P, s.push("OpenPBR.emission_luminance"), p(
|
|
1052
|
+
"USD_VISUAL_OPENPBR_EMISSION_APPROXIMATION",
|
|
1053
|
+
"OpenPBR emission_luminance 已映射为 emissiveIntensity;未声明 nit 到实时曝光单位的严格换算。"
|
|
1054
|
+
)));
|
|
1055
|
+
const C = u(["specular_weight"]);
|
|
1056
|
+
C !== null && (C < 0 || C > 1 ? r.push("OpenPBR.specular_weight.range") : (i.specularIntensity = C, s.push("OpenPBR.specular_weight"), p(
|
|
1057
|
+
"USD_VISUAL_OPENPBR_SPECULAR_APPROXIMATION",
|
|
1058
|
+
"OpenPBR specular_weight 已映射为 specularIntensity;不等于 OpenPBR 完整电介质反射模型。"
|
|
1059
|
+
)));
|
|
1060
|
+
const F = d(["specular_color"]);
|
|
1061
|
+
F && (i.specularColor = F, s.push("OpenPBR.specular_color"), p(
|
|
1062
|
+
"USD_VISUAL_OPENPBR_SPECULAR_APPROXIMATION",
|
|
1063
|
+
"OpenPBR specular_color 已映射为 Three.js specularColor;不表达彩色金属边缘和完整分层反射。"
|
|
1064
|
+
));
|
|
1065
|
+
const I = u(["geometry_opacity"]), O = u(["transmission_weight", "transmission"]);
|
|
1066
|
+
I !== null && (I < 0 || I > 1) && r.push("OpenPBR.geometry_opacity.range"), O !== null && (O < 0 || O > 1) && r.push("OpenPBR.transmission_weight.range");
|
|
1067
|
+
const V = l(["opacity", "presence"]), q = I !== null && I > 0 && I < 1 && O !== null && O > 0, U = O !== null || ["transmission_weight", "transmission", "transmissionWeight"].some((E) => xe(e, t, E) !== null);
|
|
1068
|
+
I !== null && I >= 0 && I <= 1 && !V && (i.opacity = I, s.push("OpenPBR.geometry_opacity"), q && (i.transmission = 0, a = !0, o.push("openpbr:transmission_weight", "openpbr:transmission", "openpbr:transmissionWeight"), r.push("OpenPBR.fractional-opacity-with-transmission"))), O !== null && O >= 0 && O <= 1 && !V && !q ? (i.transmission = O, O > 0 && (i.opacity = 1), s.push("OpenPBR.transmission_weight"), p(
|
|
1069
|
+
"USD_VISUAL_OPENPBR_TRANSMISSION_APPROXIMATION",
|
|
1070
|
+
"OpenPBR transmission_weight 已映射为实时透射;不表达彩色体积吸收、散射或完整薄壁/实体介质分层。"
|
|
1071
|
+
)) : V && U && (i.transmission = 0, a = !0, o.push("openpbr:transmission_weight", "openpbr:transmission", "openpbr:transmissionWeight"), r.push("OpenPBR.transmission-suppressed-by-preview-coverage"));
|
|
1072
|
+
const X = qs(h(["geometry_thin_walled"]));
|
|
1073
|
+
X === !0 ? (i.thickness = 0, s.push("OpenPBR.geometry_thin_walled")) : X === !1 && (O ?? 0) > 0 && r.push("OpenPBR.solid-transmission-without-thickness");
|
|
1074
|
+
const T = u(["coat_weight", "clearcoat"]);
|
|
1075
|
+
T !== null && (T < 0 || T > 1 ? r.push("OpenPBR.coat_weight.range") : (i.clearcoat = T, s.push("OpenPBR.coat_weight"), T === 0 && (i.clearcoatRoughness = 0)));
|
|
1076
|
+
const J = u(["coat_roughness"]);
|
|
1077
|
+
J !== null && (J < 0 || J > 1 ? r.push("OpenPBR.coat_roughness.range") : (T ?? 1) > 0 && (i.clearcoatRoughness = J, s.push("OpenPBR.coat_roughness")));
|
|
1078
|
+
for (const E of ["coat_color", "coat_ior", "coat_darkening", "coat_roughness_anisotropy"])
|
|
1079
|
+
Me(e, t, E) !== void 0 && r.push(`OpenPBR.${E}`);
|
|
1080
|
+
const se = u(["fuzz_weight"]), M = d(["fuzz_color", "sheenColor", "sheen_color"]), k = u(["fuzz_roughness", "sheenRoughness", "sheen_roughness"]);
|
|
1081
|
+
se !== null && (se < 0 || se > 1) && r.push("OpenPBR.fuzz_weight.range"), M ? (i.sheenColor = M, i.sheen = se ?? 1, s.push("OpenPBR.fuzz_color")) : (se ?? 0) > 0 && r.push("OpenPBR.fuzz-weight-without-color"), k !== null && (k < 0 || k > 1 ? r.push("OpenPBR.fuzz_roughness.range") : (i.sheenRoughness = k, s.push("OpenPBR.fuzz_roughness"))), (se !== null || M || k !== null) && p(
|
|
1082
|
+
"USD_VISUAL_OPENPBR_FUZZ_APPROXIMATION",
|
|
1083
|
+
"OpenPBR fuzz 已映射为 Three.js sheen;两者微表面模型不等价。"
|
|
1084
|
+
);
|
|
1085
|
+
const D = u(["specular_roughness_anisotropy", "anisotropy"]);
|
|
1086
|
+
D !== null && (D < 0 || D > 1 ? r.push("OpenPBR.specular_roughness_anisotropy.range") : (i.anisotropy = D, s.push("OpenPBR.specular_roughness_anisotropy"), p(
|
|
1087
|
+
"USD_VISUAL_OPENPBR_ANISOTROPY_APPROXIMATION",
|
|
1088
|
+
"OpenPBR 各向异性已映射到 Three.js anisotropy;依赖切线方向且不保证 BRDF 等价。"
|
|
1089
|
+
)));
|
|
1090
|
+
const L = u(["anisotropy_rotation"]);
|
|
1091
|
+
L !== null && (i.anisotropyRotation = L, s.push("OpenPBR.anisotropy_rotation"));
|
|
1092
|
+
for (const E of [
|
|
1093
|
+
"transmission_color",
|
|
1094
|
+
"transmission_depth",
|
|
1095
|
+
"transmission_scatter",
|
|
1096
|
+
"transmission_scatter_anisotropy",
|
|
1097
|
+
"subsurface_weight",
|
|
1098
|
+
"subsurface_color",
|
|
1099
|
+
"subsurface_radius",
|
|
1100
|
+
"subsurface_radius_scale",
|
|
1101
|
+
"subsurface_scatter_anisotropy",
|
|
1102
|
+
"thin_film_weight",
|
|
1103
|
+
"thin_film_thickness",
|
|
1104
|
+
"thin_film_ior"
|
|
1105
|
+
])
|
|
1106
|
+
(xe(e, t, E) || Me(e, t, E) !== void 0) && r.push(`OpenPBR.${E}`);
|
|
1107
|
+
for (const E of ["geometry_normal", "geometry_coat_normal", "geometry_tangent", "geometry_coat_tangent"])
|
|
1108
|
+
(xe(e, t, E) || Me(e, t, E) !== void 0) && r.push(`OpenPBR.${E}`);
|
|
1109
|
+
for (const E of [
|
|
1110
|
+
"geometry_opacity",
|
|
1111
|
+
"specular_ior",
|
|
1112
|
+
"emission_luminance",
|
|
1113
|
+
"fuzz_weight",
|
|
1114
|
+
"anisotropy_rotation",
|
|
1115
|
+
"geometry_thin_walled",
|
|
1116
|
+
"base_weight"
|
|
1117
|
+
])
|
|
1118
|
+
xe(e, t, E) && r.push(`OpenPBR.${E}.connection`);
|
|
1119
|
+
return {
|
|
1120
|
+
fields: i,
|
|
1121
|
+
applied: Object.freeze([...new Set(s)]),
|
|
1122
|
+
unsupported: Object.freeze([...new Set(r)]),
|
|
1123
|
+
suppressedInputs: Object.freeze([...new Set(o)]),
|
|
1124
|
+
clearTransmissionMap: a,
|
|
1125
|
+
approximations: Object.freeze(c),
|
|
1126
|
+
needsPhysical: Object.keys(i).some((E) => [
|
|
1127
|
+
"ior",
|
|
1128
|
+
"clearcoat",
|
|
1129
|
+
"clearcoatRoughness",
|
|
1130
|
+
"transmission",
|
|
1131
|
+
"thickness",
|
|
1132
|
+
"sheen",
|
|
1133
|
+
"sheenColor",
|
|
1134
|
+
"sheenRoughness",
|
|
1135
|
+
"anisotropy",
|
|
1136
|
+
"anisotropyRotation",
|
|
1137
|
+
"specularIntensity",
|
|
1138
|
+
"specularColor"
|
|
1139
|
+
].includes(E))
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
function Hs(e, t) {
|
|
1143
|
+
for (const n of e) {
|
|
1144
|
+
const s = t.fields;
|
|
1145
|
+
s.color && n.color.copy(s.color), s.roughness !== void 0 && (n.roughness = s.roughness), s.metalness !== void 0 && (n.metalness = s.metalness), s.emissive && n.emissive.copy(s.emissive), s.emissiveIntensity !== void 0 && (n.emissiveIntensity = s.emissiveIntensity), s.opacity !== void 0 && (n.opacity = s.opacity, n.transparent = s.opacity < 1, n.depthWrite = s.opacity >= 1), n instanceof K && (s.ior !== void 0 && (n.ior = s.ior), s.clearcoat !== void 0 && (n.clearcoat = s.clearcoat), s.clearcoatRoughness !== void 0 && (n.clearcoatRoughness = s.clearcoatRoughness), s.transmission !== void 0 && (n.transmission = s.transmission, s.transmission > 0 && (n.opacity = 1, n.transparent = !1, n.depthWrite = !0)), t.clearTransmissionMap && (n.transmissionMap = null), s.thickness !== void 0 && (n.thickness = s.thickness), s.sheen !== void 0 && (n.sheen = s.sheen), s.sheenColor && n.sheenColor.copy(s.sheenColor), s.sheenRoughness !== void 0 && (n.sheenRoughness = s.sheenRoughness), s.anisotropy !== void 0 && (n.anisotropy = s.anisotropy), s.anisotropyRotation !== void 0 && (n.anisotropyRotation = s.anisotropyRotation), s.specularIntensity !== void 0 && (n.specularIntensity = s.specularIntensity), s.specularColor && n.specularColor.copy(s.specularColor)), n.needsUpdate = !0;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
function xe(e, t, n) {
|
|
1149
|
+
if (!t) return null;
|
|
1150
|
+
const s = t.inputs[`inputs:${n}.resolvedConnect`] ?? t.inputs[`inputs:${n}.connect`], r = we(s);
|
|
1151
|
+
if (!r) return null;
|
|
1152
|
+
const o = wn(e, r.path);
|
|
1153
|
+
return o ? we(
|
|
1154
|
+
e.inputs[`inputs:${o}.resolvedConnect`] ?? e.inputs[`inputs:${o}.connect`]
|
|
1155
|
+
) : r;
|
|
1156
|
+
}
|
|
1157
|
+
function Me(e, t, n) {
|
|
1158
|
+
if (t)
|
|
1159
|
+
for (const s of typeof n == "string" ? [n] : n) {
|
|
1160
|
+
const r = t.inputs[`inputs:${s}.resolvedConnect`] ?? t.inputs[`inputs:${s}.connect`], o = we(r);
|
|
1161
|
+
if (o) {
|
|
1162
|
+
const c = wn(e, o.path);
|
|
1163
|
+
return !c || xe(e, t, s) ? void 0 : e.inputs[`inputs:${c}`];
|
|
1164
|
+
}
|
|
1165
|
+
const a = t.inputs[`inputs:${s}`];
|
|
1166
|
+
if (a !== void 0) return a;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
function wn(e, t) {
|
|
1170
|
+
const n = /^(.*)\.inputs:([^/.]+)$/.exec(t);
|
|
1171
|
+
return (n == null ? void 0 : n[1]) === e.path && n[2] ? n[2] : null;
|
|
1172
|
+
}
|
|
1173
|
+
function Xt(e) {
|
|
1174
|
+
return typeof e == "number" && Number.isFinite(e) ? e : null;
|
|
1175
|
+
}
|
|
1176
|
+
function Kt(e) {
|
|
1177
|
+
return !Array.isArray(e) || e.length < 3 ? null : e.slice(0, 3).every((t) => typeof t == "number" && Number.isFinite(t)) ? new nt(e[0], e[1], e[2]) : null;
|
|
1178
|
+
}
|
|
1179
|
+
function qs(e) {
|
|
1180
|
+
return typeof e == "boolean" ? e : null;
|
|
1181
|
+
}
|
|
1182
|
+
function Ys(e, t, n, s = [], r = !1) {
|
|
1183
|
+
if (e.some((l) => !Number.isInteger(l) || l < 0) || e.reduce((l, h) => l + h, 0) !== t.length || s.some((l) => !Number.isInteger(l) || l < 0 || l >= e.length))
|
|
1184
|
+
throw new Error("Invalid authored face topology");
|
|
1185
|
+
const o = [], a = [], c = new Set(s);
|
|
1186
|
+
let i = 0;
|
|
1187
|
+
if (e.forEach((l, h) => {
|
|
1188
|
+
if (!c.has(h)) for (let u = 1; u < l - 1; u++)
|
|
1189
|
+
o.push(i, i + (r ? u + 1 : u), i + (r ? u : u + 1)), a.push(h);
|
|
1190
|
+
i += l;
|
|
1191
|
+
}), o.length !== n.length || o.some((l, h) => t[l] !== n[h]))
|
|
1192
|
+
throw new Error("Authored polygon/loader corner correspondence unavailable");
|
|
1193
|
+
return { corners: o, faces: a };
|
|
1194
|
+
}
|
|
1195
|
+
function Js(e, t, n) {
|
|
1196
|
+
if (t.length !== n || t.some((r) => !Number.isInteger(r) || r < 0 || r >= e.length))
|
|
1197
|
+
throw new Error("Invalid faceVarying UV indices");
|
|
1198
|
+
const s = t.flatMap((r) => e[r]);
|
|
1199
|
+
if (s.length !== n * 2 || !s.every(Number.isFinite)) throw new Error("Invalid UV values");
|
|
1200
|
+
return s;
|
|
1201
|
+
}
|
|
1202
|
+
function Zs(e, t) {
|
|
1203
|
+
const n = Array(e).fill(0);
|
|
1204
|
+
for (const s of t) for (const r of s.faces) {
|
|
1205
|
+
if (!Number.isInteger(r) || r < 0 || r >= e || n[r] !== 0)
|
|
1206
|
+
throw new Error("Invalid or overlapping material subset faces");
|
|
1207
|
+
n[r] = s.slot;
|
|
1208
|
+
}
|
|
1209
|
+
return n;
|
|
1210
|
+
}
|
|
1211
|
+
function Qs(e, t, n, s) {
|
|
1212
|
+
if (!e.stage) return;
|
|
1213
|
+
const r = e.stage, o = e.pxr, a = o.Usd.TimeCode.Default(), c = (h, u) => t.warnings.push({
|
|
1214
|
+
code: "USD_VISUAL_TOPOLOGY_UNSUPPORTED",
|
|
1215
|
+
source: "usd-visual",
|
|
1216
|
+
message: `USD ${h} 的部分视觉拓扑未能安全补齐,未确认部分保留 Loader 输出:${String(u)}`
|
|
1217
|
+
}), i = /* @__PURE__ */ new Set(), l = (h, u) => {
|
|
1218
|
+
const d = h.GetAttribute(u);
|
|
1219
|
+
try {
|
|
1220
|
+
return d.IsValid() ? d.Get(a) : null;
|
|
1221
|
+
} finally {
|
|
1222
|
+
d.delete();
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
try {
|
|
1226
|
+
for (const h of e.data.elements) {
|
|
1227
|
+
const u = e.index.objectsByPath.get(h.path);
|
|
1228
|
+
if (!(u instanceof me) || !er(u)) continue;
|
|
1229
|
+
const d = new o.Sdf.Path(h.path), p = r.GetPrimAtPath(d);
|
|
1230
|
+
let f = [];
|
|
1231
|
+
try {
|
|
1232
|
+
if (p.GetTypeName() !== "Mesh") continue;
|
|
1233
|
+
f = p.GetChildren();
|
|
1234
|
+
const _ = f.filter((I) => I.GetTypeName() === "GeomSubset" && l(I, "familyName") === "materialBind"), w = p.GetAttribute("primvars:st");
|
|
1235
|
+
let g = null, b = null;
|
|
1236
|
+
try {
|
|
1237
|
+
n(h.material) && w.IsValid() && w.GetMetadata("interpolation") === "faceVarying" && (b = l(p, "primvars:st:indices"), b && (g = w.Get(a)));
|
|
1238
|
+
} finally {
|
|
1239
|
+
w.delete();
|
|
1240
|
+
}
|
|
1241
|
+
const y = _.length > 0 && !Array.isArray(u.material) && u.geometry.groups.length === 0;
|
|
1242
|
+
if (!g && !y) continue;
|
|
1243
|
+
const S = l(p, "faceVertexCounts"), v = l(p, "faceVertexIndices");
|
|
1244
|
+
if (!S || !v || u.geometry.index) throw new Error("Authored face topology unavailable");
|
|
1245
|
+
const m = Ys(
|
|
1246
|
+
S,
|
|
1247
|
+
v,
|
|
1248
|
+
h.geometry.pointIndices ?? [],
|
|
1249
|
+
l(p, "holeIndices") ?? [],
|
|
1250
|
+
l(p, "orientation") === "leftHanded"
|
|
1251
|
+
);
|
|
1252
|
+
if (u.geometry.getAttribute("position").count !== m.corners.length)
|
|
1253
|
+
throw new Error("Loader geometry corner count mismatch");
|
|
1254
|
+
if (g && b) {
|
|
1255
|
+
const I = Js(g, b, v.length), O = m.corners.flatMap((q) => [I[q * 2], I[q * 2 + 1]]), V = u.geometry.getAttribute("uv");
|
|
1256
|
+
(!V || V.array.length !== O.length || O.some((q, U) => Math.abs(q - V.array[U]) > 1e-6)) && (u.geometry.setAttribute("uv", new Bn(O, 2)), h.geometry.uvs = O);
|
|
1257
|
+
}
|
|
1258
|
+
if (!y) continue;
|
|
1259
|
+
const x = _.map((I) => {
|
|
1260
|
+
if (l(I, "elementType") !== "face") throw new Error("Non-face material subset");
|
|
1261
|
+
const O = o.UsdShade.ComputeBoundMaterialPath(I), V = (O == null ? void 0 : O.resolvedTargetPath) || (O == null ? void 0 : O.materialPath);
|
|
1262
|
+
if (!V || !e.index.materialsByPath.has(V)) throw new Error("Unresolved subset material");
|
|
1263
|
+
const q = l(I, "indices");
|
|
1264
|
+
if (!Array.isArray(q)) throw new Error("Missing subset face indices");
|
|
1265
|
+
return { materialPath: V, faces: q };
|
|
1266
|
+
}), R = [...new Set(x.map((I) => I.materialPath))], A = Zs(S.length, x.map((I) => ({ faces: I.faces, slot: R.indexOf(I.materialPath) + 1 })));
|
|
1267
|
+
let P = m.faces.map((I) => A[I]);
|
|
1268
|
+
const C = [u.material];
|
|
1269
|
+
try {
|
|
1270
|
+
for (const I of R) C.push(s(h, I));
|
|
1271
|
+
} catch (I) {
|
|
1272
|
+
for (const O of C.slice(1))
|
|
1273
|
+
i.has(O) || O.dispose();
|
|
1274
|
+
throw I;
|
|
1275
|
+
}
|
|
1276
|
+
const F = [...new Set(P)].sort((I, O) => I - O);
|
|
1277
|
+
if (F.includes(0))
|
|
1278
|
+
u.material = C;
|
|
1279
|
+
else {
|
|
1280
|
+
const I = new Map(F.map((O, V) => [O, V]));
|
|
1281
|
+
u.material = F.map((O) => C[O]), P = P.map((O) => I.get(O));
|
|
1282
|
+
}
|
|
1283
|
+
for (const I of C) i.add(I);
|
|
1284
|
+
for (let I = 0; I < P.length; ) {
|
|
1285
|
+
let O = I + 1;
|
|
1286
|
+
for (; O < P.length && P[O] === P[I]; ) O++;
|
|
1287
|
+
u.geometry.addGroup(I * 3, (O - I) * 3, P[I]), I = O;
|
|
1288
|
+
}
|
|
1289
|
+
} catch (_) {
|
|
1290
|
+
c(h.path, _);
|
|
1291
|
+
} finally {
|
|
1292
|
+
for (const _ of f) _.delete();
|
|
1293
|
+
p.delete(), d.delete();
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
} finally {
|
|
1297
|
+
a.delete();
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
function er(e) {
|
|
1301
|
+
let t = e;
|
|
1302
|
+
for (; t; ) {
|
|
1303
|
+
if (!t.visible || t.userData.usdPurposeExcluded) return !1;
|
|
1304
|
+
t = t.parent;
|
|
1305
|
+
}
|
|
1306
|
+
return !0;
|
|
1307
|
+
}
|
|
1308
|
+
const tr = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "webp", "avif", "gif", "bmp"]), De = /^(?:UsdPreviewSurface|ND_UsdPreviewSurface_surfaceshader)$/i, bn = /(?:standard.?surface|principled|open.?pbr|adobe.?standard.?material)/i;
|
|
1309
|
+
async function nr(e, t) {
|
|
1310
|
+
var u;
|
|
1311
|
+
Ht(e.scene);
|
|
1312
|
+
const n = Ir(e), s = /* @__PURE__ */ new Set();
|
|
1313
|
+
for (const d of e.data.materials) {
|
|
1314
|
+
const p = As(e, d);
|
|
1315
|
+
p && (d.shaders = p.shaders, e.index.materialsByPath.set(d.path, d), s.add(d.path));
|
|
1316
|
+
}
|
|
1317
|
+
const r = /* @__PURE__ */ new Map(), o = (d, p) => {
|
|
1318
|
+
const f = r.get(p);
|
|
1319
|
+
if (f) return f;
|
|
1320
|
+
const _ = e.data.view.prims.find((v) => v.path === d.path);
|
|
1321
|
+
if (!_) throw new Error(`Missing view prim: ${d.path}`);
|
|
1322
|
+
const w = e.index.materialsByPath.get(p), g = bt(w, n.get(p)), b = () => qn({
|
|
1323
|
+
...e.data,
|
|
1324
|
+
elements: [{ ...d, material: p }],
|
|
1325
|
+
view: { ...e.data.view, prims: [{ ..._, parentPath: null }] },
|
|
1326
|
+
animations: [],
|
|
1327
|
+
lights: [],
|
|
1328
|
+
skels: { ...e.data.skels, bindings: [], skeletons: [], animations: [] }
|
|
1329
|
+
}, {
|
|
1330
|
+
convertZUp: !1,
|
|
1331
|
+
loadLights: !1,
|
|
1332
|
+
loadTextures: !g,
|
|
1333
|
+
sourcePath: t.sourcePath,
|
|
1334
|
+
textureResolver: (v) => {
|
|
1335
|
+
for (const m of [v.resolvedPath, v.path, v.url]) {
|
|
1336
|
+
if (!m) continue;
|
|
1337
|
+
const x = t.files.objectUrlIfPresent(m, t.entryDirectory ?? "");
|
|
1338
|
+
if (x) return x;
|
|
1339
|
+
}
|
|
1340
|
+
return null;
|
|
1341
|
+
}
|
|
1342
|
+
}), y = t.isTextureAllowed ? cn(e.data.materials, (v) => t.isTextureAllowed(v) && !!t.files.objectUrlIfPresent(v, t.entryDirectory ?? ""), b) : b();
|
|
1343
|
+
Ht(y.scene);
|
|
1344
|
+
const S = y.index.objectsByPath.get(d.path);
|
|
1345
|
+
if (S.geometry.dispose(), Array.isArray(S.material)) throw new Error("Unexpected scratch material array");
|
|
1346
|
+
return r.set(p, S.material), S.material;
|
|
1347
|
+
}, a = /* @__PURE__ */ new Set();
|
|
1348
|
+
for (const d of e.data.elements) {
|
|
1349
|
+
const p = e.index.objectsByPath.get(d.path);
|
|
1350
|
+
if (!(p instanceof me)) continue;
|
|
1351
|
+
const f = (_) => {
|
|
1352
|
+
const w = pe(_.userData.usdMaterialPath);
|
|
1353
|
+
if (!w || !s.has(w) || _.userData.usdSurfaceShaderId) return _;
|
|
1354
|
+
const g = o(d, w), b = `Material ${w} has no supported surface shader.`;
|
|
1355
|
+
return g.userData.usdInstanceResolvedDiagnostics = [b], g.userData.usdMaterialDiagnostics = ie([
|
|
1356
|
+
...Ze(_.userData.usdMaterialDiagnostics),
|
|
1357
|
+
...Ze(g.userData.usdMaterialDiagnostics)
|
|
1358
|
+
]), a.add(_), g;
|
|
1359
|
+
};
|
|
1360
|
+
if (Array.isArray(p.material)) {
|
|
1361
|
+
const _ = p.material.map(f);
|
|
1362
|
+
_.some((w, g) => w !== p.material[g]) && (p.material = _);
|
|
1363
|
+
} else p.material = f(p.material);
|
|
1364
|
+
}
|
|
1365
|
+
e.scene.traverse((d) => {
|
|
1366
|
+
if (d instanceof me) for (const p of Array.isArray(d.material) ? d.material : [d.material]) a.delete(p);
|
|
1367
|
+
});
|
|
1368
|
+
for (const d of a) d.dispose();
|
|
1369
|
+
Qs(e, t.diagnostics, (d) => {
|
|
1370
|
+
if (!d) return !0;
|
|
1371
|
+
const p = e.index.materialsByPath.get(d);
|
|
1372
|
+
if (!p || !zr(p)) return !1;
|
|
1373
|
+
const f = p && bt(p, n.get(d));
|
|
1374
|
+
return !!f && Xe(f) && Ue(f, /* @__PURE__ */ new Set());
|
|
1375
|
+
}, o);
|
|
1376
|
+
const c = Ur(e), i = [], l = /* @__PURE__ */ new Set();
|
|
1377
|
+
for (const [d, p] of c) {
|
|
1378
|
+
const f = e.index.materialsByPath.get(d);
|
|
1379
|
+
if (!f) continue;
|
|
1380
|
+
const _ = p[0], w = n.get(d), g = zt(f, qt(f, _, w));
|
|
1381
|
+
for (const U of p) U.userData.usdMaterialIR = g;
|
|
1382
|
+
const b = g.issues.map((U) => `${U.code}:${U.sourcePath}`), y = ie(p.flatMap((U) => Ze(U.userData.usdMaterialDiagnostics))), S = pe(_.userData.usdSurfaceShaderId), v = S ?? g.surfaceShaderId;
|
|
1383
|
+
if (v && (De.test(v) || bn.test(v))) {
|
|
1384
|
+
const U = Yt(f, p, Pr), X = Yt(f, p, Or), T = !!(U && X) && Rr(f, p[0], S, U, X), J = U && (T || !X || De.test(v)) ? U : null, se = X && (T || !U || vn(v)) ? X : null, M = se ? Ks(f, se, J) : null, k = se ? zt(f, se) : null, D = k && k.surfacePath !== g.surfacePath ? [g, k] : [g];
|
|
1385
|
+
if ((M != null && M.needsPhysical || br(k)) && ke(e, p), M) {
|
|
1386
|
+
Hs(
|
|
1387
|
+
p.filter(W),
|
|
1388
|
+
M
|
|
1389
|
+
);
|
|
1390
|
+
for (const re of M.approximations)
|
|
1391
|
+
t.diagnostics.approximations.push({
|
|
1392
|
+
code: re.code,
|
|
1393
|
+
source: "usd-visual",
|
|
1394
|
+
message: `${d}: ${re.message}`
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
const L = J ? ur(e, f, J, p) : { applied: [], unsupported: [] }, E = await rt(
|
|
1398
|
+
D,
|
|
1399
|
+
p,
|
|
1400
|
+
new Set((M == null ? void 0 : M.suppressedInputs) ?? []),
|
|
1401
|
+
t,
|
|
1402
|
+
l
|
|
1403
|
+
), B = await ir(
|
|
1404
|
+
g,
|
|
1405
|
+
p,
|
|
1406
|
+
t,
|
|
1407
|
+
l
|
|
1408
|
+
), $ = await gr(
|
|
1409
|
+
D,
|
|
1410
|
+
p,
|
|
1411
|
+
y,
|
|
1412
|
+
new Set((M == null ? void 0 : M.suppressedInputs) ?? []),
|
|
1413
|
+
t,
|
|
1414
|
+
l
|
|
1415
|
+
), H = await _r(f, p, t);
|
|
1416
|
+
$.applied.push(...H.applied), $.resources.push(...H.resources);
|
|
1417
|
+
const ne = H.applied.length ? { applied: [], unsupported: [], bounded: !0 } : J ? hr(e, f, p, t) : se ? { applied: [], unsupported: [], bounded: !!(M != null && M.unsupported.length) } : mr(f, p, t);
|
|
1418
|
+
$.applied.push(...ne.applied), $.applied.push(...E.applied), $.resolved.push(...E.resolved);
|
|
1419
|
+
const Z = /* @__PURE__ */ new Set([...E.resolvedInputs, ...$.resolvedInputs]);
|
|
1420
|
+
for (const re of B.resolvedInputs) Z.add(re);
|
|
1421
|
+
H.resolvedInputs.length && Z.add("opacity"), $.unsupported.push(...E.unsupported), $.resources.push(...E.resources), $.applied.push(...B.applied), $.unsupported.push(...B.unsupported), $.resources.push(...B.resources);
|
|
1422
|
+
const z = ie(p.flatMap((re) => Ze(re.userData.usdInstanceResolvedDiagnostics)));
|
|
1423
|
+
$.resolved.push(...z), z.length && $.applied.push("instance.surface.constants"), $.applied.push(...(M == null ? void 0 : M.applied) ?? []), $.unsupported.push(...(M == null ? void 0 : M.unsupported) ?? []), $.applied.push(...L.applied), $.unsupported.push(...L.unsupported), J && $.resolved.push(...cr(
|
|
1424
|
+
f,
|
|
1425
|
+
J,
|
|
1426
|
+
Z
|
|
1427
|
+
));
|
|
1428
|
+
const ue = ie([...$.unsupported, ...ne.unsupported]);
|
|
1429
|
+
Rn(t.diagnostics, d, $.resources), dr(
|
|
1430
|
+
t.diagnostics,
|
|
1431
|
+
d,
|
|
1432
|
+
[...g.issues, ...(k == null ? void 0 : k.issues) ?? []],
|
|
1433
|
+
ue
|
|
1434
|
+
), i.push({
|
|
1435
|
+
materialPath: d,
|
|
1436
|
+
sourceShaderId: v,
|
|
1437
|
+
dialect: g.dialect,
|
|
1438
|
+
irIssues: b,
|
|
1439
|
+
action: $.applied.length ? "augmented" : "preserved",
|
|
1440
|
+
fidelity: ne.bounded || M != null && M.unsupported.length || ue.length > 0 || g.issues.length > 0 || y.some((re) => !$.resolved.includes(re)) ? "bounded-approximation" : "native",
|
|
1441
|
+
appliedInputs: $.applied,
|
|
1442
|
+
unsupportedNodes: ue,
|
|
1443
|
+
resources: $.resources,
|
|
1444
|
+
loaderDiagnostics: y,
|
|
1445
|
+
resolvedLoaderDiagnostics: $.resolved
|
|
1446
|
+
});
|
|
1447
|
+
continue;
|
|
1448
|
+
}
|
|
1449
|
+
const m = qt(f, _, w);
|
|
1450
|
+
if (!m) {
|
|
1451
|
+
const U = St(e, d), X = f.shaders.map((T) => ae(T.inputs["info:mdl:sourceAsset"])).filter(vt);
|
|
1452
|
+
for (const T of X) t.diagnostics.droppedFeatures.push({ code: "USD_VISUAL_SHADER_NODE_UNSUPPORTED", source: "usd-visual", message: `USD 材质 ${d} 使用尚未支持的 MDL 材质 ${T};保留现有结果,未生成替代内容。` });
|
|
1453
|
+
i.push({
|
|
1454
|
+
materialPath: d,
|
|
1455
|
+
sourceShaderId: X[0] ?? null,
|
|
1456
|
+
dialect: g.dialect,
|
|
1457
|
+
irIssues: b,
|
|
1458
|
+
action: "fallback",
|
|
1459
|
+
fidelity: U ? "authored-fallback" : "default-fallback",
|
|
1460
|
+
appliedInputs: [],
|
|
1461
|
+
unsupportedNodes: ie(f.shaders.map((T) => T.id).filter(vt)),
|
|
1462
|
+
resources: [],
|
|
1463
|
+
loaderDiagnostics: y
|
|
1464
|
+
});
|
|
1465
|
+
continue;
|
|
1466
|
+
}
|
|
1467
|
+
if (Dt(m)) {
|
|
1468
|
+
const U = await Cr(
|
|
1469
|
+
m,
|
|
1470
|
+
g,
|
|
1471
|
+
p,
|
|
1472
|
+
t,
|
|
1473
|
+
l
|
|
1474
|
+
);
|
|
1475
|
+
Ve(
|
|
1476
|
+
t.diagnostics,
|
|
1477
|
+
d,
|
|
1478
|
+
m,
|
|
1479
|
+
U.applied,
|
|
1480
|
+
new Set(U.unsupported),
|
|
1481
|
+
U.resources,
|
|
1482
|
+
U.applied.length ? "augmented" : "fallback"
|
|
1483
|
+
), i.push({
|
|
1484
|
+
materialPath: d,
|
|
1485
|
+
sourceShaderId: "gltf_material",
|
|
1486
|
+
dialect: g.dialect,
|
|
1487
|
+
irIssues: b,
|
|
1488
|
+
action: U.applied.length ? "augmented" : "fallback",
|
|
1489
|
+
fidelity: U.applied.length ? "bounded-approximation" : lt(e, d),
|
|
1490
|
+
appliedInputs: ie(U.applied),
|
|
1491
|
+
unsupportedNodes: ie(U.unsupported),
|
|
1492
|
+
resources: U.resources,
|
|
1493
|
+
loaderDiagnostics: y
|
|
1494
|
+
});
|
|
1495
|
+
continue;
|
|
1496
|
+
}
|
|
1497
|
+
if (Ct(m)) {
|
|
1498
|
+
const U = await Er(
|
|
1499
|
+
e,
|
|
1500
|
+
m,
|
|
1501
|
+
g,
|
|
1502
|
+
p,
|
|
1503
|
+
t,
|
|
1504
|
+
l
|
|
1505
|
+
);
|
|
1506
|
+
Ve(
|
|
1507
|
+
t.diagnostics,
|
|
1508
|
+
d,
|
|
1509
|
+
m,
|
|
1510
|
+
U.applied,
|
|
1511
|
+
new Set(U.unsupported),
|
|
1512
|
+
U.resources,
|
|
1513
|
+
U.applied.length ? "augmented" : "fallback"
|
|
1514
|
+
), i.push({
|
|
1515
|
+
materialPath: d,
|
|
1516
|
+
sourceShaderId: "OmniPBRBase",
|
|
1517
|
+
dialect: g.dialect,
|
|
1518
|
+
irIssues: b,
|
|
1519
|
+
action: U.applied.length ? "augmented" : "fallback",
|
|
1520
|
+
fidelity: U.applied.length ? "bounded-approximation" : lt(e, d),
|
|
1521
|
+
appliedInputs: ie(U.applied),
|
|
1522
|
+
unsupportedNodes: ie(U.unsupported),
|
|
1523
|
+
resources: U.resources,
|
|
1524
|
+
loaderDiagnostics: y
|
|
1525
|
+
});
|
|
1526
|
+
continue;
|
|
1527
|
+
}
|
|
1528
|
+
if (Et(m)) {
|
|
1529
|
+
const U = await Nr(
|
|
1530
|
+
e,
|
|
1531
|
+
m,
|
|
1532
|
+
g,
|
|
1533
|
+
p,
|
|
1534
|
+
t,
|
|
1535
|
+
l
|
|
1536
|
+
);
|
|
1537
|
+
Ve(
|
|
1538
|
+
t.diagnostics,
|
|
1539
|
+
d,
|
|
1540
|
+
m,
|
|
1541
|
+
U.applied,
|
|
1542
|
+
new Set(U.unsupported),
|
|
1543
|
+
U.resources,
|
|
1544
|
+
U.applied.length ? "augmented" : "fallback"
|
|
1545
|
+
), i.push({
|
|
1546
|
+
materialPath: d,
|
|
1547
|
+
sourceShaderId: "OmniSurfaceBase",
|
|
1548
|
+
dialect: g.dialect,
|
|
1549
|
+
irIssues: b,
|
|
1550
|
+
action: U.applied.length ? "augmented" : "fallback",
|
|
1551
|
+
fidelity: U.applied.length ? "bounded-approximation" : lt(e, d),
|
|
1552
|
+
appliedInputs: ie(U.applied),
|
|
1553
|
+
unsupportedNodes: ie(U.unsupported),
|
|
1554
|
+
resources: U.resources,
|
|
1555
|
+
loaderDiagnostics: y
|
|
1556
|
+
});
|
|
1557
|
+
continue;
|
|
1558
|
+
}
|
|
1559
|
+
if (xt(m)) {
|
|
1560
|
+
const U = Ar(e, p, m), X = U.applied.length ? await xr(p, m, U, t) : [];
|
|
1561
|
+
U.applied.length && X.push(...await Mr(p, m, U, t)), Ve(t.diagnostics, d, m, U.applied, U.unsupported, X, U.applied.length ? "augmented" : "fallback"), i.push({
|
|
1562
|
+
materialPath: d,
|
|
1563
|
+
sourceShaderId: "OmniGlass",
|
|
1564
|
+
action: U.applied.length ? "augmented" : "fallback",
|
|
1565
|
+
dialect: g.dialect,
|
|
1566
|
+
irIssues: b,
|
|
1567
|
+
fidelity: "bounded-approximation",
|
|
1568
|
+
appliedInputs: U.applied,
|
|
1569
|
+
unsupportedNodes: [...U.unsupported],
|
|
1570
|
+
resources: X,
|
|
1571
|
+
loaderDiagnostics: y
|
|
1572
|
+
});
|
|
1573
|
+
continue;
|
|
1574
|
+
}
|
|
1575
|
+
const x = [], R = [], A = /* @__PURE__ */ new Set(), P = kr(p, m, x);
|
|
1576
|
+
let C = !1;
|
|
1577
|
+
if (Xe(m)) {
|
|
1578
|
+
const U = ae(G(m, ["diffuse_texture"]));
|
|
1579
|
+
if (U) {
|
|
1580
|
+
const D = await ce(U, t);
|
|
1581
|
+
if (R.push(D.report), D.url && Ue(m, A) && p.every((L) => W(L) && !L.map)) {
|
|
1582
|
+
let L = null;
|
|
1583
|
+
try {
|
|
1584
|
+
L = await (t.createTexture ?? le)(D.url, ht);
|
|
1585
|
+
} catch (E) {
|
|
1586
|
+
if (E instanceof Error && E.name === "AbortError") throw E;
|
|
1587
|
+
R[R.length - 1] = { path: U, status: "decode-failed" };
|
|
1588
|
+
}
|
|
1589
|
+
if (L) {
|
|
1590
|
+
for (const E of p)
|
|
1591
|
+
W(E) && (E.map = L, E.color.set(16777215), E.needsUpdate = !0, C = !0);
|
|
1592
|
+
C ? x.push("diffuse_texture") : L.dispose();
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
const X = ge(m, ["enable_ORM_texture"], !1);
|
|
1597
|
+
if (X) {
|
|
1598
|
+
const D = ae(G(m, ["ORM_texture"])), L = N(m, ["reflection_roughness_texture_influence"]) ?? 0, E = N(m, ["metallic_texture_influence"]) ?? 0;
|
|
1599
|
+
N(m, ["ao_to_diffuse"]);
|
|
1600
|
+
const B = G(m, ["ORM_texture_colorspace"]);
|
|
1601
|
+
if (B !== void 0 && B !== "raw") A.add("OmniPBR.ORM_texture_colorspace");
|
|
1602
|
+
else if (L || E)
|
|
1603
|
+
if (!D) A.add("OmniPBR.ORM_texture_missing");
|
|
1604
|
+
else {
|
|
1605
|
+
const $ = await ce(D, t);
|
|
1606
|
+
if (R.push($.report), $.url && Ue(m, A)) {
|
|
1607
|
+
let H = null, ne = !1;
|
|
1608
|
+
try {
|
|
1609
|
+
H = await (t.createTexture ?? le)($.url, oe), H.colorSpace = oe, H.wrapS = te, H.wrapT = te;
|
|
1610
|
+
const Z = [
|
|
1611
|
+
{
|
|
1612
|
+
slot: "roughnessMap",
|
|
1613
|
+
scalar: "roughness",
|
|
1614
|
+
channel: "g",
|
|
1615
|
+
influence: L,
|
|
1616
|
+
constant: N(m, ["reflection_roughness_constant"]) ?? 0.5
|
|
1617
|
+
},
|
|
1618
|
+
{
|
|
1619
|
+
slot: "metalnessMap",
|
|
1620
|
+
scalar: "metalness",
|
|
1621
|
+
channel: "b",
|
|
1622
|
+
influence: E,
|
|
1623
|
+
constant: N(m, ["metallic_constant"]) ?? 0
|
|
1624
|
+
}
|
|
1625
|
+
];
|
|
1626
|
+
for (const z of Z) {
|
|
1627
|
+
if (!Number.isFinite(z.influence) || z.influence < 0 || z.influence > 1 || z.constant < 0 || z.constant > 1) {
|
|
1628
|
+
A.add(`OmniPBR.${z.scalar}_ORM_range`);
|
|
1629
|
+
continue;
|
|
1630
|
+
}
|
|
1631
|
+
const ue = p.filter(W).filter((re) => !re[z.slot]);
|
|
1632
|
+
if (ue.length) {
|
|
1633
|
+
if (z.influence === 0) {
|
|
1634
|
+
for (const re of ue) re[z.scalar] = z.constant;
|
|
1635
|
+
continue;
|
|
1636
|
+
}
|
|
1637
|
+
try {
|
|
1638
|
+
const re = z.influence === 1 ? H : Ae(
|
|
1639
|
+
H,
|
|
1640
|
+
z.channel,
|
|
1641
|
+
z.influence,
|
|
1642
|
+
z.constant * (1 - z.influence)
|
|
1643
|
+
);
|
|
1644
|
+
for (const Ee of ue)
|
|
1645
|
+
Ee[z.slot] = re, Ee[z.scalar] = 1, Ee.needsUpdate = !0;
|
|
1646
|
+
re === H && (ne = !0), x.push(`${z.scalar}.ORM.${z.channel}`, `ORM.${z.scalar}.influence=${z.influence}`), C = !0;
|
|
1647
|
+
} catch {
|
|
1648
|
+
A.add(`OmniPBR.${z.scalar}_ORM_conversion`);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
C && x.push("ORM_texture");
|
|
1653
|
+
} catch (Z) {
|
|
1654
|
+
if (Z instanceof Error && Z.name === "AbortError") throw Z;
|
|
1655
|
+
R[R.length - 1] = { path: D, status: "decode-failed" };
|
|
1656
|
+
} finally {
|
|
1657
|
+
ne || H == null || H.dispose();
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
if (!X && Ue(m, A))
|
|
1663
|
+
for (const D of [
|
|
1664
|
+
{ file: "reflectionroughness_texture", weight: "reflection_roughness_texture_influence", constant: "reflection_roughness_constant", fallback: 0.5, map: "roughnessMap", scalar: "roughness" },
|
|
1665
|
+
{ file: "metallic_texture", weight: "metallic_texture_influence", constant: "metallic_constant", fallback: 0, map: "metalnessMap", scalar: "metalness" }
|
|
1666
|
+
]) {
|
|
1667
|
+
const L = N(m, [D.weight]) ?? 0;
|
|
1668
|
+
if (L === 0) continue;
|
|
1669
|
+
if (L < 0 || L > 1) {
|
|
1670
|
+
A.add(`OmniPBR.${D.weight}`);
|
|
1671
|
+
continue;
|
|
1672
|
+
}
|
|
1673
|
+
const E = ae(G(m, [D.file]));
|
|
1674
|
+
if (!E) continue;
|
|
1675
|
+
const B = G(m, [`${D.file}_colorspace`]);
|
|
1676
|
+
if (B !== void 0 && B !== "raw") {
|
|
1677
|
+
A.add(`OmniPBR.${D.file}_colorspace`);
|
|
1678
|
+
continue;
|
|
1679
|
+
}
|
|
1680
|
+
const $ = await ce(E, t);
|
|
1681
|
+
R.push($.report);
|
|
1682
|
+
const H = p.filter(W).filter((Z) => !Z[D.map]);
|
|
1683
|
+
if (!$.url || !H.length) continue;
|
|
1684
|
+
let ne = null;
|
|
1685
|
+
try {
|
|
1686
|
+
ne = await (t.createTexture ?? le)($.url, oe);
|
|
1687
|
+
const Z = N(m, [D.constant]) ?? D.fallback, z = Ae(ne, "grayscale", L, Z * (1 - L));
|
|
1688
|
+
z.wrapS = te, z.wrapT = te;
|
|
1689
|
+
for (const ue of H)
|
|
1690
|
+
ue[D.map] = z, ue[D.scalar] = 1, ue.needsUpdate = !0;
|
|
1691
|
+
x.push(D.file), C = !0;
|
|
1692
|
+
} catch (Z) {
|
|
1693
|
+
if (Z instanceof Error && Z.name === "AbortError") throw Z;
|
|
1694
|
+
A.add(`OmniPBR.${D.file}_conversion`);
|
|
1695
|
+
} finally {
|
|
1696
|
+
ne == null || ne.dispose();
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
const T = ge(m, ["enable_opacity"], !1), J = N(m, ["opacity_threshold"]) ?? 0;
|
|
1700
|
+
if (T && J >= 0 && ge(m, ["enable_opacity_texture"], !1) && Ue(m, A)) {
|
|
1701
|
+
const D = ae(G(m, ["opacity_texture"])), L = G(m, ["opacity_mode"]) ?? 1, E = L === 0 || L === "mono_alpha" ? "a" : L === 1 || L === "mono_average" ? "average" : L === 3 || L === "mono_maximum" ? "maximum" : null, B = G(m, ["opacity_texture_colorspace"]);
|
|
1702
|
+
if (B !== void 0 && B !== "raw") A.add("OmniPBR.opacity_texture_colorspace");
|
|
1703
|
+
else if (!E) A.add("OmniPBR.opacity_mode");
|
|
1704
|
+
else if (!D) A.add("OmniPBR.opacity_texture_missing");
|
|
1705
|
+
else {
|
|
1706
|
+
const $ = await ce(D, t);
|
|
1707
|
+
R.push($.report);
|
|
1708
|
+
const H = p.filter(W).filter((Z) => !Z.alphaMap);
|
|
1709
|
+
let ne = null;
|
|
1710
|
+
if ($.url && H.length) try {
|
|
1711
|
+
ne = await (t.createTexture ?? le)($.url, oe);
|
|
1712
|
+
const Z = Ae(ne, E);
|
|
1713
|
+
Z.wrapS = te, Z.wrapT = te;
|
|
1714
|
+
for (const z of H)
|
|
1715
|
+
z.alphaMap = Z, z.opacity = 1, z.alphaTest = Math.max(0, J), z.transparent = J === 0, z.depthWrite = J > 0, z.needsUpdate = !0;
|
|
1716
|
+
x.push("opacity_texture"), C = !0;
|
|
1717
|
+
} catch (Z) {
|
|
1718
|
+
if (Z instanceof Error && Z.name === "AbortError") throw Z;
|
|
1719
|
+
R[R.length - 1] = { path: D, status: "decode-failed" };
|
|
1720
|
+
} finally {
|
|
1721
|
+
ne == null || ne.dispose();
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
const M = he(m, ["diffuse_tint"]);
|
|
1726
|
+
if (M) {
|
|
1727
|
+
for (const D of p)
|
|
1728
|
+
W(D) && (D.map ? D.color.copy(M) : D.color.copy(he(m, ["diffuse_color_constant"]) ?? new nt(0.2, 0.2, 0.2)).multiply(M), D.needsUpdate = !0);
|
|
1729
|
+
x.push("diffuse_tint"), C = !0;
|
|
1730
|
+
}
|
|
1731
|
+
const k = ae(G(m, ["normalmap_texture"]));
|
|
1732
|
+
if (k) {
|
|
1733
|
+
const D = await ce(k, t);
|
|
1734
|
+
R.push(D.report);
|
|
1735
|
+
const L = G(m, ["normalmap_texture_colorspace"]), E = N(m, ["bump_factor"]) ?? 1;
|
|
1736
|
+
if (L !== void 0 && L !== "raw") A.add("OmniPBR.normalmap_texture_colorspace");
|
|
1737
|
+
else if (!Number.isFinite(E) || E < 0) A.add("OmniPBR.bump_factor");
|
|
1738
|
+
else if (D.url && Ue(m, A)) {
|
|
1739
|
+
const B = p.filter(W).filter(($) => !$.normalMap);
|
|
1740
|
+
if (B.length)
|
|
1741
|
+
try {
|
|
1742
|
+
const $ = await (t.createTexture ?? le)(D.url, oe);
|
|
1743
|
+
$.colorSpace = oe, $.wrapS = te, $.wrapT = te;
|
|
1744
|
+
for (const H of B)
|
|
1745
|
+
H.normalMap = $, H.normalScale.set(
|
|
1746
|
+
E * (ge(m, ["flip_tangent_u"], !1) ? -1 : 1),
|
|
1747
|
+
E * (ge(m, ["flip_tangent_v"], !0) ? -1 : 1)
|
|
1748
|
+
), H.needsUpdate = !0;
|
|
1749
|
+
x.push("normalmap_texture", "normal.tangent_convention"), C = !0;
|
|
1750
|
+
} catch ($) {
|
|
1751
|
+
if ($ instanceof Error && $.name === "AbortError") throw $;
|
|
1752
|
+
R[R.length - 1] = { path: k, status: "decode-failed" };
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
Lr(m, A), C = await Br(p, m, x, A, R, t) || C;
|
|
1757
|
+
}
|
|
1758
|
+
const F = ee(m, "diffuseColor") ?? ee(m, "baseColor");
|
|
1759
|
+
let I = !1;
|
|
1760
|
+
if (F) {
|
|
1761
|
+
const U = Ke(f, F);
|
|
1762
|
+
if (U && An(U)) {
|
|
1763
|
+
const X = Vr(U);
|
|
1764
|
+
if (X) {
|
|
1765
|
+
const T = await ce(X.path, t);
|
|
1766
|
+
R.push(T.report);
|
|
1767
|
+
const J = ee(U, "manifold");
|
|
1768
|
+
J && A.add(((u = Ke(f, J)) == null ? void 0 : u.id) ?? J.path);
|
|
1769
|
+
const se = Object.keys(U.inputs).filter((D) => !["inputs:filename", "inputs:resultRGB", "inputs:linearize"].includes(D)), M = U.inputs["inputs:linearize"], k = M === 0 || M === 1;
|
|
1770
|
+
if (k || A.add("PxrTexture.colorSpace"), se.length > 0 && !J && A.add("PxrTexture.controls"), T.url && !J && se.length === 0 && k && F.outputName === "resultRGB" && p.every((D) => W(D) && !D.map)) {
|
|
1771
|
+
let D = null;
|
|
1772
|
+
try {
|
|
1773
|
+
D = await (t.createTexture ?? le)(T.url, M === 1 ? ht : oe);
|
|
1774
|
+
} catch (L) {
|
|
1775
|
+
if (L instanceof Error && L.name === "AbortError") throw L;
|
|
1776
|
+
R[R.length - 1] = { path: X.path, status: "decode-failed" };
|
|
1777
|
+
}
|
|
1778
|
+
if (D) {
|
|
1779
|
+
for (const L of p)
|
|
1780
|
+
W(L) && (L.map = D, L.color.set(16777215), L.needsUpdate = !0, I = !0);
|
|
1781
|
+
I ? x.push("diffuseColor.texture") : D.dispose();
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
} else
|
|
1785
|
+
A.add(U.id ?? U.path);
|
|
1786
|
+
} else U ? A.add(U.id ?? U.path) : A.add(F.path);
|
|
1787
|
+
}
|
|
1788
|
+
Fr(f, m, A);
|
|
1789
|
+
const O = P || I || C ? "augmented" : "fallback", V = St(e, d), q = O === "augmented" ? "bounded-approximation" : V ? "authored-fallback" : "default-fallback";
|
|
1790
|
+
Ve(t.diagnostics, d, m, x, A, R, O), i.push({
|
|
1791
|
+
materialPath: d,
|
|
1792
|
+
sourceShaderId: On(m),
|
|
1793
|
+
dialect: g.dialect,
|
|
1794
|
+
irIssues: b,
|
|
1795
|
+
action: O,
|
|
1796
|
+
fidelity: q,
|
|
1797
|
+
appliedInputs: ie(x),
|
|
1798
|
+
unsupportedNodes: [...A],
|
|
1799
|
+
resources: R,
|
|
1800
|
+
loaderDiagnostics: y
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
Is(e), wr(e.scene, l);
|
|
1804
|
+
const h = i.filter((d) => d.loaderDiagnostics.some(
|
|
1805
|
+
(p) => {
|
|
1806
|
+
var f;
|
|
1807
|
+
return !((f = d.resolvedLoaderDiagnostics) != null && f.includes(p)) && !(d.action === "augmented" && p === `Material ${d.materialPath} has no supported surface shader.`);
|
|
1808
|
+
}
|
|
1809
|
+
));
|
|
1810
|
+
return h.length > 0 && t.diagnostics.droppedFeatures.push({
|
|
1811
|
+
code: "USD_VISUAL_LOADER_DIAGNOSTIC",
|
|
1812
|
+
message: `${h.length} 个 USD 材质仍有尚未被视觉适配层消解的 Loader 限制;具体材质和原始诊断见 visualAdaptation 报告。`,
|
|
1813
|
+
source: "usd-visual"
|
|
1814
|
+
}), Object.freeze({
|
|
1815
|
+
schemaVersion: 1,
|
|
1816
|
+
materials: i,
|
|
1817
|
+
summary: Object.freeze({
|
|
1818
|
+
preserved: i.filter((d) => d.action === "preserved").length,
|
|
1819
|
+
augmented: i.filter((d) => d.action === "augmented").length,
|
|
1820
|
+
fallback: i.filter((d) => d.action === "fallback").length,
|
|
1821
|
+
missingResources: i.flatMap((d) => d.resources).filter((d) => d.status === "missing").length,
|
|
1822
|
+
unsupportedResources: i.flatMap((d) => d.resources).filter((d) => d.status === "unsupported-format").length
|
|
1823
|
+
})
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
function Ht(e) {
|
|
1827
|
+
e == null || e.traverse((t) => {
|
|
1828
|
+
if (!(t instanceof me)) return;
|
|
1829
|
+
const n = Array.isArray(t.material) ? t.material : [t.material];
|
|
1830
|
+
for (const s of n)
|
|
1831
|
+
for (const r of ["map", "normalMap", "roughnessMap", "metalnessMap", "aoMap", "emissiveMap", "alphaMap", "bumpMap", "displacementMap", "clearcoatMap", "clearcoatNormalMap", "clearcoatRoughnessMap", "iridescenceMap", "iridescenceThicknessMap", "specularColorMap", "specularIntensityMap", "transmissionMap", "thicknessMap", "sheenColorMap", "sheenRoughnessMap"]) {
|
|
1832
|
+
const o = s[r];
|
|
1833
|
+
o instanceof Pt && (o.userData.usdScalarConversionKey || o.userData.usdCoverageConversionKey || o.userData.usdColorConversionKey || o.userData.usdNormalConversionKey || (o.matrix.identity(), o.matrixAutoUpdate = !1, o.needsUpdate = !0));
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
const sr = [
|
|
1838
|
+
{
|
|
1839
|
+
reportName: "baseColor",
|
|
1840
|
+
sources: [
|
|
1841
|
+
{ dialect: "usd-preview", inputNames: ["diffuseColor", "baseColor", "base_color"] },
|
|
1842
|
+
{ dialect: "openpbr", inputNames: ["base_color", "baseColor"] },
|
|
1843
|
+
{ dialect: "materialx-standard-surface", inputNames: ["base_color", "baseColor", "diffuseColor"] },
|
|
1844
|
+
{ dialect: "omni-pbr-base", inputNames: ["diffuse_reflection_color"] },
|
|
1845
|
+
{ dialect: "omni-surface-base", inputNames: ["diffuse_reflection_color"] },
|
|
1846
|
+
{ dialect: "gltf-material", inputNames: ["base_color_texture"] }
|
|
1847
|
+
],
|
|
1848
|
+
targetMap: "map"
|
|
1849
|
+
},
|
|
1850
|
+
{
|
|
1851
|
+
reportName: "emissiveColor",
|
|
1852
|
+
sources: [
|
|
1853
|
+
{ dialect: "usd-preview", inputNames: ["emissiveColor", "emission_color"] },
|
|
1854
|
+
{ dialect: "openpbr", inputNames: ["emission_color", "emissiveColor"] },
|
|
1855
|
+
{ dialect: "materialx-standard-surface", inputNames: ["emission_color", "emissiveColor"] }
|
|
1856
|
+
],
|
|
1857
|
+
targetMap: "emissiveMap"
|
|
1858
|
+
}
|
|
1859
|
+
];
|
|
1860
|
+
async function rt(e, t, n, s, r) {
|
|
1861
|
+
const o = {
|
|
1862
|
+
applied: [],
|
|
1863
|
+
resolved: [],
|
|
1864
|
+
resolvedInputs: [],
|
|
1865
|
+
unsupported: [],
|
|
1866
|
+
resources: []
|
|
1867
|
+
};
|
|
1868
|
+
for (const a of sr)
|
|
1869
|
+
for (const c of e) {
|
|
1870
|
+
const i = a.sources.find((u) => u.dialect === c.dialect), l = i && c.textures.find((u) => u.semantic === "color" && i.inputNames.includes(u.surfaceInput) && !n.has(`${c.dialect}:${u.surfaceInput}`));
|
|
1871
|
+
if (!l) continue;
|
|
1872
|
+
const h = await rr(c, a, l, t, s, r);
|
|
1873
|
+
o.applied.push(...h.applied), o.resolved.push(...h.resolved), o.resolvedInputs.push(...h.resolvedInputs), o.unsupported.push(...h.unsupported), o.resources.push(...h.resources);
|
|
1874
|
+
break;
|
|
1875
|
+
}
|
|
1876
|
+
return o;
|
|
1877
|
+
}
|
|
1878
|
+
async function rr(e, t, n, s, r, o) {
|
|
1879
|
+
var b;
|
|
1880
|
+
const a = {
|
|
1881
|
+
applied: [],
|
|
1882
|
+
resolved: [],
|
|
1883
|
+
resolvedInputs: [],
|
|
1884
|
+
unsupported: [],
|
|
1885
|
+
resources: []
|
|
1886
|
+
}, c = (y) => (a.unsupported.push(`${e.dialect}.${n.surfaceInput}.${y}`), a), i = s.filter(W);
|
|
1887
|
+
if (!i.length) return c("standard-material-required");
|
|
1888
|
+
const l = i.map((y) => or(y, t));
|
|
1889
|
+
if (l.some((y) => (y == null ? void 0 : y.userData.usdTextureOwner) === "foreign"))
|
|
1890
|
+
return c("existing-foreign-map");
|
|
1891
|
+
if (e.dialect === "gltf-material" && n.surfaceInput === "base_color_texture" && !["texcoord0", "st"].includes((n.uvSet ?? "texcoord0").toLowerCase()))
|
|
1892
|
+
return c(`uv=${n.uvSet ?? "unknown"}`);
|
|
1893
|
+
const h = JSON.stringify([
|
|
1894
|
+
"usd-color-v1",
|
|
1895
|
+
e.materialPath,
|
|
1896
|
+
t.reportName,
|
|
1897
|
+
n.shaderPath,
|
|
1898
|
+
n.path,
|
|
1899
|
+
n.sourceColorSpace,
|
|
1900
|
+
n.sourceChannel,
|
|
1901
|
+
n.wrapS,
|
|
1902
|
+
n.wrapT,
|
|
1903
|
+
n.uvSet ?? "st",
|
|
1904
|
+
n.uvTransform
|
|
1905
|
+
]);
|
|
1906
|
+
if (l.every((y) => (y == null ? void 0 : y.userData.usdColorConversionKey) === h))
|
|
1907
|
+
return a.applied.push(`${t.reportName}.texture.rgb`), a.resolvedInputs.push(n.surfaceInput), a;
|
|
1908
|
+
if (l.every((y) => y !== null) && l.every((y) => !y.userData.usdColorConversionKey))
|
|
1909
|
+
return a.resolvedInputs.push(n.surfaceInput), a;
|
|
1910
|
+
if (Mt([e])) return c("multiple-uv-sets");
|
|
1911
|
+
let u = !1;
|
|
1912
|
+
const d = (y) => {
|
|
1913
|
+
a.unsupported.push(`${e.dialect}.${n.surfaceInput}.${y}`), u = !0;
|
|
1914
|
+
};
|
|
1915
|
+
n.sourceChannel !== "rgb" && d("color-channel-not-rgb"), ((b = n.sourceColorSpace) == null ? void 0 : b.toLowerCase()) !== "srgb" && d(`color-space=${n.sourceColorSpace ?? "auto"}`), (n.scale.slice(0, 3).some((y) => y !== 1) || n.bias.slice(0, 3).some((y) => y !== 0)) && d("color-affine-scale-bias");
|
|
1916
|
+
const p = n.wrapS === null ? te : Se(n.wrapS), f = n.wrapT === null ? te : Se(n.wrapT);
|
|
1917
|
+
if ((p === null || f === null) && d("unsupported-wrap"), u || p === null || f === null) return a;
|
|
1918
|
+
const _ = i.filter((y, S) => {
|
|
1919
|
+
const v = l[S];
|
|
1920
|
+
return !v || v.userData.usdColorConversionKey;
|
|
1921
|
+
});
|
|
1922
|
+
if (!_.length) return a;
|
|
1923
|
+
const w = await ce(n.path, r);
|
|
1924
|
+
if (a.resources.push(w.report), !w.url) return a;
|
|
1925
|
+
let g = null;
|
|
1926
|
+
try {
|
|
1927
|
+
g = await (r.createTexture ?? le)(w.url, ht), g.wrapS = p, g.wrapT = f, g.channel = 0, ot(g, n.uvTransform), g.userData.usdColorConversionKey = h, g.userData.usdTextureOwner = "adapter-derived";
|
|
1928
|
+
for (const y of l)
|
|
1929
|
+
y != null && y.userData.usdColorConversionKey && o.add(y);
|
|
1930
|
+
for (const y of _) ar(y, t, g);
|
|
1931
|
+
a.applied.push(`${t.reportName}.texture.rgb`), a.resolvedInputs.push(n.surfaceInput);
|
|
1932
|
+
} catch (y) {
|
|
1933
|
+
if (y instanceof Error && y.name === "AbortError") throw y;
|
|
1934
|
+
a.resources[a.resources.length - 1] = {
|
|
1935
|
+
path: n.path,
|
|
1936
|
+
status: "decode-failed"
|
|
1937
|
+
};
|
|
1938
|
+
}
|
|
1939
|
+
return a;
|
|
1940
|
+
}
|
|
1941
|
+
function or(e, t) {
|
|
1942
|
+
return t.targetMap === "map" ? e.map : e.emissiveMap;
|
|
1943
|
+
}
|
|
1944
|
+
function ar(e, t, n) {
|
|
1945
|
+
t.targetMap === "map" ? (e.map = n, e.color.set(16777215)) : (e.emissiveMap = n, e.emissive.set(16777215)), e.needsUpdate = !0;
|
|
1946
|
+
}
|
|
1947
|
+
async function ir(e, t, n, s) {
|
|
1948
|
+
var _;
|
|
1949
|
+
const r = { applied: [], resolvedInputs: [], unsupported: [], resources: [] };
|
|
1950
|
+
if (e.dialect !== "usd-preview") return r;
|
|
1951
|
+
const o = e.textures.find((w) => w.surfaceInput === "normal" && w.semantic === "normal");
|
|
1952
|
+
if (!o) return r;
|
|
1953
|
+
const a = (w) => (r.unsupported.push(`usd-preview.normal.${w}`), r);
|
|
1954
|
+
if (o.sourceChannel !== "rgb") return a("color-channel-not-rgb");
|
|
1955
|
+
if (((_ = o.sourceColorSpace) == null ? void 0 : _.toLowerCase()) !== "raw")
|
|
1956
|
+
return a(`color-space=${o.sourceColorSpace ?? "auto"}`);
|
|
1957
|
+
if (![2, 2, 2].every((w, g) => o.scale[g] === w && o.bias[g] === -1)) return a("non-canonical-normal-scale-bias");
|
|
1958
|
+
if (Mt([e])) return a("multiple-uv-sets");
|
|
1959
|
+
const i = o.wrapS === null ? te : Se(o.wrapS), l = o.wrapT === null ? te : Se(o.wrapT);
|
|
1960
|
+
if (i === null || l === null) return a("unsupported-wrap");
|
|
1961
|
+
const h = t.filter(W);
|
|
1962
|
+
if (!h.length) return a("standard-material-required");
|
|
1963
|
+
const u = h.map((w) => w.normalMap);
|
|
1964
|
+
if (u.some((w) => w && w.userData.usdTextureOwner === "foreign"))
|
|
1965
|
+
return a("existing-foreign-map");
|
|
1966
|
+
const d = JSON.stringify([
|
|
1967
|
+
"usd-preview-normal-v1",
|
|
1968
|
+
e.materialPath,
|
|
1969
|
+
o.shaderPath,
|
|
1970
|
+
o.path,
|
|
1971
|
+
i,
|
|
1972
|
+
l,
|
|
1973
|
+
o.uvSet ?? "st",
|
|
1974
|
+
o.uvTransform
|
|
1975
|
+
]);
|
|
1976
|
+
if (u.every((w) => (w == null ? void 0 : w.userData.usdNormalConversionKey) === d))
|
|
1977
|
+
return r.applied.push("PreviewSurface.normal.texture"), r.resolvedInputs.push("normal"), r.resources.push({ path: o.path, status: "available" }), r;
|
|
1978
|
+
if (u.every((w) => w !== null) && u.every((w) => !w.userData.usdNormalConversionKey))
|
|
1979
|
+
return r.resolvedInputs.push("normal"), r;
|
|
1980
|
+
if (u.some((w) => w && !w.userData.usdNormalConversionKey))
|
|
1981
|
+
return a("existing-map-owner-unknown");
|
|
1982
|
+
const p = await ce(o.path, n);
|
|
1983
|
+
if (r.resources.push(p.report), !p.url) return r;
|
|
1984
|
+
let f = null;
|
|
1985
|
+
try {
|
|
1986
|
+
f = await (n.createTexture ?? le)(p.url, oe), f.colorSpace = oe, f.wrapS = i, f.wrapT = l, f.channel = 0, ot(f, o.uvTransform), f.userData.usdNormalConversionKey = d, f.userData.usdTextureOwner = "adapter-derived";
|
|
1987
|
+
for (const w of u)
|
|
1988
|
+
w != null && w.userData.usdNormalConversionKey && s.add(w);
|
|
1989
|
+
for (const w of h)
|
|
1990
|
+
w.normalMap = f, w.normalScale.set(1, 1), w.needsUpdate = !0;
|
|
1991
|
+
r.applied.push("PreviewSurface.normal.texture"), r.resolvedInputs.push("normal"), f = null;
|
|
1992
|
+
} catch (w) {
|
|
1993
|
+
if (w instanceof Error && w.name === "AbortError") throw w;
|
|
1994
|
+
r.resources[r.resources.length - 1] = {
|
|
1995
|
+
path: o.path,
|
|
1996
|
+
status: "decode-failed"
|
|
1997
|
+
};
|
|
1998
|
+
} finally {
|
|
1999
|
+
f == null || f.dispose();
|
|
2000
|
+
}
|
|
2001
|
+
return r;
|
|
2002
|
+
}
|
|
2003
|
+
function ot(e, t) {
|
|
2004
|
+
if (!t) return;
|
|
2005
|
+
const n = t.rotation * Math.PI / 180, s = Math.cos(n), r = Math.sin(n);
|
|
2006
|
+
e.matrix.set(
|
|
2007
|
+
s * t.scale[0],
|
|
2008
|
+
-r * t.scale[1],
|
|
2009
|
+
t.translation[0],
|
|
2010
|
+
r * t.scale[0],
|
|
2011
|
+
s * t.scale[1],
|
|
2012
|
+
t.translation[1],
|
|
2013
|
+
0,
|
|
2014
|
+
0,
|
|
2015
|
+
1
|
|
2016
|
+
), e.matrixAutoUpdate = !1, e.needsUpdate = !0;
|
|
2017
|
+
}
|
|
2018
|
+
function ur(e, t, n, s) {
|
|
2019
|
+
const r = [], o = [], a = Zt(t, n, ["diffuseColor", "baseColor", "base_color"]), c = ze(t, n, ["roughness", "specular_roughness"]), i = ze(t, n, ["metallic", "metalness", "base_metalness"]), l = ze(t, n, ["ior", "specular_ior"]), h = ze(t, n, ["clearcoat", "coat_weight"]), u = ze(t, n, ["clearcoatRoughness", "coat_roughness"]), d = Zt(t, n, ["emissiveColor", "emission_color"]);
|
|
2020
|
+
jr(t, n, ["useSpecularWorkflow"]) === !0 && o.push("PreviewSurface.specularWorkflow"), (l !== null || h !== null || u !== null) && ke(e, s);
|
|
2021
|
+
for (const f of s)
|
|
2022
|
+
W(f) && (a && f.color.copy(a), c !== null && (f.roughness = Q(c)), i !== null && (f.metalness = Q(i)), d && f.emissive.copy(d), f instanceof K && (l !== null && l > 0 && (f.ior = l), h !== null && (f.clearcoat = Q(h)), u !== null && (f.clearcoatRoughness = Q(u))), f.needsUpdate = !0);
|
|
2023
|
+
return a && r.push("PreviewSurface.diffuseColor.constant"), c !== null && r.push("PreviewSurface.roughness.constant"), i !== null && r.push("PreviewSurface.metallic.constant"), l !== null && r.push("PreviewSurface.ior.constant"), h !== null && r.push("PreviewSurface.clearcoat.constant"), u !== null && r.push("PreviewSurface.clearcoatRoughness.constant"), d && r.push("PreviewSurface.emissiveColor.constant"), { applied: r, unsupported: o };
|
|
2024
|
+
}
|
|
2025
|
+
function cr(e, t, n) {
|
|
2026
|
+
const s = /* @__PURE__ */ new Set();
|
|
2027
|
+
for (const r of Object.keys(t.inputs)) {
|
|
2028
|
+
if (!r.endsWith(".connect") || r.endsWith(".resolvedConnect")) continue;
|
|
2029
|
+
const o = Re(t.inputs[r]);
|
|
2030
|
+
if (!o) continue;
|
|
2031
|
+
const a = In(e, o.path);
|
|
2032
|
+
!a || !lr(
|
|
2033
|
+
e,
|
|
2034
|
+
a,
|
|
2035
|
+
n
|
|
2036
|
+
) || s.add(`Connection references missing shader ${o.path}.`);
|
|
2037
|
+
}
|
|
2038
|
+
return [...s];
|
|
2039
|
+
}
|
|
2040
|
+
function lr(e, t, n) {
|
|
2041
|
+
const s = pr(t);
|
|
2042
|
+
if (!s.some((o) => e.inputs[`inputs:${o}.resolvedConnect`] !== void 0 || e.inputs[`inputs:${o}.connect`] !== void 0)) {
|
|
2043
|
+
const o = s.map((a) => e.inputs[`inputs:${a}`]).find((a) => a !== void 0);
|
|
2044
|
+
if (o !== void 0) return fr(t, o);
|
|
2045
|
+
}
|
|
2046
|
+
return s.some((o) => n.has(o));
|
|
2047
|
+
}
|
|
2048
|
+
function pr(e) {
|
|
2049
|
+
return e === "baseColor" || e === "base_color" ? [e, "diffuseColor"] : e === "specular_roughness" ? [e, "roughness"] : e === "base_metalness" || e === "metalness" ? [e, "metallic"] : e === "coat_weight" ? [e, "clearcoat"] : e === "coat_roughness" ? [e, "clearcoatRoughness"] : e === "emission_color" ? [e, "emissiveColor"] : e === "ambientOcclusion" ? [e, "occlusion"] : [e];
|
|
2050
|
+
}
|
|
2051
|
+
function fr(e, t) {
|
|
2052
|
+
return e === "useSpecularWorkflow" ? typeof t == "boolean" : e === "opacityMode" ? t === "transparent" || t === "presence" : /^(?:diffuseColor|baseColor|base_color|emissiveColor|emission_color)$/.test(e) ? Array.isArray(t) && t.length >= 3 && t.slice(0, 3).every((s) => typeof s == "number" && Number.isFinite(s)) : (/* @__PURE__ */ new Set([
|
|
2053
|
+
"roughness",
|
|
2054
|
+
"specular_roughness",
|
|
2055
|
+
"metallic",
|
|
2056
|
+
"metalness",
|
|
2057
|
+
"base_metalness",
|
|
2058
|
+
"ior",
|
|
2059
|
+
"clearcoat",
|
|
2060
|
+
"coat_weight",
|
|
2061
|
+
"clearcoatRoughness",
|
|
2062
|
+
"coat_roughness",
|
|
2063
|
+
"opacity",
|
|
2064
|
+
"opacityThreshold"
|
|
2065
|
+
])).has(e) && typeof t == "number" && Number.isFinite(t);
|
|
2066
|
+
}
|
|
2067
|
+
function dr(e, t, n, s) {
|
|
2068
|
+
for (const r of n) {
|
|
2069
|
+
const o = `USD 材质 ${t} 的 ${r.code}:${r.message}`;
|
|
2070
|
+
e.droppedFeatures.some((a) => a.code === "USD_VISUAL_MATERIAL_IR_ISSUE" && a.message === o) || e.droppedFeatures.push({
|
|
2071
|
+
code: "USD_VISUAL_MATERIAL_IR_ISSUE",
|
|
2072
|
+
message: o,
|
|
2073
|
+
source: "usd-visual"
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
for (const r of ie(s)) {
|
|
2077
|
+
const o = `USD 材质 ${t} 的 ${r} 尚未完成浏览器适配;保留来源与 gap,不生成猜测内容。`;
|
|
2078
|
+
e.droppedFeatures.some((a) => a.code === "USD_VISUAL_SHADER_NODE_UNSUPPORTED" && a.message === o) || e.droppedFeatures.push({
|
|
2079
|
+
code: "USD_VISUAL_SHADER_NODE_UNSUPPORTED",
|
|
2080
|
+
message: o,
|
|
2081
|
+
source: "usd-visual"
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
function hr(e, t, n, s) {
|
|
2086
|
+
var y;
|
|
2087
|
+
const r = { applied: [], unsupported: [], bounded: !1 }, o = pe((y = n[0]) == null ? void 0 : y.userData.usdSurfaceShaderPath), a = t.shaders.filter((S) => De.test(S.id ?? "")), c = o ? a.find((S) => S.path === o) : a.length === 1 ? a[0] : void 0;
|
|
2088
|
+
if (!c) return r;
|
|
2089
|
+
const i = Pe(t, c, ["opacity"]), l = Pe(t, c, ["opacityMode"]), h = Pe(t, c, ["opacityThreshold"]), u = typeof i.value == "number" && Number.isFinite(i.value) ? i.value : null, d = typeof l.value == "string" ? l.value : "transparent", p = typeof h.value == "number" && Number.isFinite(h.value) ? h.value : 0, f = (S) => (r.bounded = !0, r.unsupported.push(S), r);
|
|
2090
|
+
if (i.connection || h.connection || l.connection) return f("connected opacity/threshold/mode");
|
|
2091
|
+
if (p > 0 || d === "presence") {
|
|
2092
|
+
if (n.some((v) => !W(v) || v.alphaMap || v.map)) return f("textured coverage/cutout");
|
|
2093
|
+
const S = Q(u ?? 1);
|
|
2094
|
+
for (const v of n)
|
|
2095
|
+
v.opacity = p > 0 ? S >= p ? 1 : 0 : S, v.alphaTest = p > 0 ? 0.5 : 0, v.transparent = p === 0 && S < 1, v.depthWrite = !v.transparent, v instanceof K && (v.transmission = 0), v.needsUpdate = !0;
|
|
2096
|
+
return r.applied.push(p > 0 ? "PreviewSurface.cutout.constant" : "PreviewSurface.presence.constant"), r;
|
|
2097
|
+
}
|
|
2098
|
+
if (d !== "transparent") return f(`opacityMode=${String(d)}`);
|
|
2099
|
+
if (u === null && Object.hasOwn(c.inputs, "inputs:opacity") && c.inputs["inputs:opacity"] === null) {
|
|
2100
|
+
for (const S of n)
|
|
2101
|
+
W(S) && (S.opacity = 1, S.transparent = !!S.alphaMap, S.depthWrite = !S.transparent, S.needsUpdate = !0);
|
|
2102
|
+
return r.applied.push("PreviewSurface.opacity.default"), r;
|
|
2103
|
+
}
|
|
2104
|
+
if (u === null || u >= 1) return r;
|
|
2105
|
+
const w = Pe(t, c, ["metallic"]), g = Pe(t, c, ["useSpecularWorkflow"]);
|
|
2106
|
+
if (!w.connection && w.value === 1 && !g.connection && [void 0, !1, 0].includes(g.value)) {
|
|
2107
|
+
if (n.some((S) => !W(S) || S.alphaMap || S.map || S.metalnessMap || S.alphaTest > 0)) return f("textured metal transparency");
|
|
2108
|
+
for (const S of n)
|
|
2109
|
+
W(S) && (S.opacity = 1, S.transparent = !1, S.depthWrite = !0, S.metalness = 1, S instanceof K && (S.transmission = 0), S.needsUpdate = !0);
|
|
2110
|
+
return r.applied.push("PreviewSurface.transparent.pure-metal"), r;
|
|
2111
|
+
}
|
|
2112
|
+
const b = Pe(t, c, ["ior"]);
|
|
2113
|
+
if (w.connection || g.connection || b.connection || (typeof w.value == "number" ? w.value : 0) !== 0 || ![void 0, !1, 0].includes(g.value)) return f("non-dielectric or connected transparency");
|
|
2114
|
+
if (n.some((S) => !W(S) || S.alphaMap || S.map || S.metalnessMap || S.alphaTest > 0)) return f("textured or non-standard transparency");
|
|
2115
|
+
ke(e, n);
|
|
2116
|
+
for (const S of n)
|
|
2117
|
+
S instanceof K && (S.opacity = 1, S.transparent = !1, S.transmission = 1 - Q(u), S.ior = typeof b.value == "number" && Number.isFinite(b.value) ? b.value : 1.5, S.depthWrite = !0, S.needsUpdate = !0);
|
|
2118
|
+
return r.applied.push("PreviewSurface.transparent.constant-dielectric"), r.bounded = !0, s.diagnostics.approximations.push({
|
|
2119
|
+
code: "USD_VISUAL_PREVIEW_TRANSMISSION_APPROXIMATION",
|
|
2120
|
+
source: "usd-visual",
|
|
2121
|
+
message: `USD 材质 ${t.path} 的常量介质透明已映射为实时透射;保留表面反射;Three.js 透射与反射共用粗糙度,不等同于 PreviewSurface 的零粗糙度透射。不推断壁厚或体积吸收,不保证多层折射与路径追踪等价。`
|
|
2122
|
+
}), r;
|
|
2123
|
+
}
|
|
2124
|
+
function mr(e, t, n) {
|
|
2125
|
+
var h;
|
|
2126
|
+
const s = { applied: [], unsupported: [], bounded: !1 }, r = pe((h = t[0]) == null ? void 0 : h.userData.usdSurfaceShaderPath), o = e.shaders.filter((u) => u.id === "ND_standard_surface_surfaceshader"), a = r ? o.find((u) => u.path === r) : o.length === 1 ? o[0] : void 0;
|
|
2127
|
+
if (!a) return s;
|
|
2128
|
+
const c = (u) => {
|
|
2129
|
+
s.bounded = !0, s.unsupported.push(u);
|
|
2130
|
+
}, i = G(a, ["opacity"]);
|
|
2131
|
+
if (ee(a, "opacity")) c("connected opacity");
|
|
2132
|
+
else if (Array.isArray(i) && i.length === 3 && i.every((u) => typeof u == "number" && Number.isFinite(u)))
|
|
2133
|
+
if (i[0] !== i[1] || i[1] !== i[2]) c("colored opacity");
|
|
2134
|
+
else if (t.some((u) => !W(u) || u.alphaMap || u.map)) c("textured coverage");
|
|
2135
|
+
else {
|
|
2136
|
+
const u = Q(i[0]);
|
|
2137
|
+
for (const d of t)
|
|
2138
|
+
d.opacity = u, d.transparent = u < 1, d.depthWrite = u === 1, d.needsUpdate = !0;
|
|
2139
|
+
s.applied.push("MaterialX.opacity.achromatic-constant");
|
|
2140
|
+
}
|
|
2141
|
+
const l = N(a, ["transmission"]) ?? 0;
|
|
2142
|
+
return ee(a, "transmission") && c("connected transmission"), l > 0 && (s.bounded = !0, Array.isArray(i) && i.some((u) => typeof u == "number" && u > 0 && u < 1) && c("fractional coverage + transmission compositing"), ge(a, ["thin_walled"], !1) ? n.diagnostics.approximations.push({
|
|
2143
|
+
code: "USD_VISUAL_MATERIALX_TRANSMISSION_APPROXIMATION",
|
|
2144
|
+
source: "usd-visual",
|
|
2145
|
+
message: `USD 材质 ${e.path} 的 MaterialX 薄壁透射使用 Loader 的实时近似;并非完整 MaterialX 着色器执行。`
|
|
2146
|
+
}) : c("solid transmission / absorption path length")), s;
|
|
2147
|
+
}
|
|
2148
|
+
async function _r(e, t, n) {
|
|
2149
|
+
var R;
|
|
2150
|
+
const s = {
|
|
2151
|
+
applied: [],
|
|
2152
|
+
resolvedInputs: [],
|
|
2153
|
+
resources: []
|
|
2154
|
+
}, r = pe((R = t[0]) == null ? void 0 : R.userData.usdSurfaceShaderPath), o = e.shaders.filter((A) => De.test(A.id ?? "")), a = r ? o.find((A) => A.path === r) : o.length === 1 ? o[0] : void 0;
|
|
2155
|
+
if (!a || ee(a, "opacityThreshold") || ee(a, "opacityMode")) return s;
|
|
2156
|
+
const c = N(a, ["opacityThreshold"]) ?? 0, i = G(a, ["opacityMode"]);
|
|
2157
|
+
if (i !== void 0 && i !== "transparent" && i !== "presence") return s;
|
|
2158
|
+
const l = ee(a, "opacity");
|
|
2159
|
+
if (!(l != null && l.outputName) || !["r", "g", "b", "a"].includes(l.outputName)) return s;
|
|
2160
|
+
const h = Ke(e, l);
|
|
2161
|
+
if (!h || h.id !== "UsdUVTexture" || G(h, ["sourceColorSpace"]) !== "raw") return s;
|
|
2162
|
+
const u = ee(h, "st"), d = u && Ke(e, u);
|
|
2163
|
+
if (!d || d.id !== "UsdPrimvarReader_float2" || G(d, ["varname"]) !== "st" || t.some((A) => !W(A) || A.map)) return s;
|
|
2164
|
+
const p = "rgba".indexOf(l.outputName), f = (A, P) => {
|
|
2165
|
+
if (ee(h, A)) return null;
|
|
2166
|
+
const C = h.inputs[`inputs:${A}`];
|
|
2167
|
+
return C === void 0 ? P : Array.isArray(C) && C.length === 4 && C.every(Number.isFinite) ? C[p] : null;
|
|
2168
|
+
}, _ = f("scale", 1), w = f("bias", 0);
|
|
2169
|
+
if (_ === null || w === null) return s;
|
|
2170
|
+
const g = (A) => {
|
|
2171
|
+
const P = G(h, [A]);
|
|
2172
|
+
return P === "repeat" ? te : P === "mirror" ? on : P === "clamp" ? an : null;
|
|
2173
|
+
}, b = g("wrapS"), y = g("wrapT"), S = ae(G(h, ["file"]));
|
|
2174
|
+
if (!S || b === null || y === null) return s;
|
|
2175
|
+
const v = JSON.stringify([h.path, l.outputName, _, w, b, y, c]);
|
|
2176
|
+
if (t.every((A) => {
|
|
2177
|
+
var P;
|
|
2178
|
+
return W(A) && ((P = A.alphaMap) == null ? void 0 : P.userData.usdCoverageConversionKey) === v;
|
|
2179
|
+
}))
|
|
2180
|
+
return s.applied.push(`PreviewSurface.opacity.texture.${l.outputName}->g`), s.resolvedInputs.push("opacity"), s.resources.push({ path: S, status: "available" }), s;
|
|
2181
|
+
const m = await ce(S, n);
|
|
2182
|
+
s.resources.push(m.report);
|
|
2183
|
+
let x = null;
|
|
2184
|
+
try {
|
|
2185
|
+
if (!m.url) return s;
|
|
2186
|
+
x = await (n.createTexture ?? le)(m.url, oe);
|
|
2187
|
+
const A = Ae(x, l.outputName, _, w);
|
|
2188
|
+
A.wrapS = b, A.wrapT = y, A.userData.usdCoverageConversionKey = v;
|
|
2189
|
+
for (const P of t)
|
|
2190
|
+
W(P) && (P.alphaMap = A, P.opacity = 1, P.alphaTest = c > 0 ? c : 0, P.transparent = c <= 0, P.depthWrite = c > 0, P instanceof K && (P.transmission = 0), P.needsUpdate = !0);
|
|
2191
|
+
s.applied.push(`PreviewSurface.opacity.texture.${l.outputName}->g`), n.diagnostics.approximations.push({
|
|
2192
|
+
code: "USD_VISUAL_COVERAGE_TEXTURE_APPROXIMATION",
|
|
2193
|
+
source: "usd-visual",
|
|
2194
|
+
message: `USD 材质 ${e.path} 的透明遮罩已按源通道转换;采用 8 位纹理重排,阈值边缘与过滤结果不保证跨渲染器逐像素一致。`
|
|
2195
|
+
});
|
|
2196
|
+
} catch (A) {
|
|
2197
|
+
if (A instanceof Error && A.name === "AbortError") throw A;
|
|
2198
|
+
s.resources[0] = { path: S, status: "decode-failed" };
|
|
2199
|
+
} finally {
|
|
2200
|
+
x == null || x.dispose();
|
|
2201
|
+
}
|
|
2202
|
+
return s;
|
|
2203
|
+
}
|
|
2204
|
+
const Sn = [
|
|
2205
|
+
{
|
|
2206
|
+
reportName: "roughness",
|
|
2207
|
+
sources: [
|
|
2208
|
+
{ dialect: "usd-preview", inputNames: ["roughness"] },
|
|
2209
|
+
{ dialect: "openpbr", inputNames: ["specular_roughness"] },
|
|
2210
|
+
{ dialect: "materialx-standard-surface", inputNames: ["specular_roughness", "roughness"] }
|
|
2211
|
+
],
|
|
2212
|
+
targetMap: "roughnessMap",
|
|
2213
|
+
targetValue: "roughness",
|
|
2214
|
+
targetChannel: "g",
|
|
2215
|
+
physicalOnly: !1
|
|
2216
|
+
},
|
|
2217
|
+
{
|
|
2218
|
+
reportName: "metalness",
|
|
2219
|
+
sources: [
|
|
2220
|
+
{ dialect: "usd-preview", inputNames: ["metallic"] },
|
|
2221
|
+
{ dialect: "openpbr", inputNames: ["base_metalness", "metalness"] },
|
|
2222
|
+
{ dialect: "materialx-standard-surface", inputNames: ["base_metalness", "metalness"] }
|
|
2223
|
+
],
|
|
2224
|
+
targetMap: "metalnessMap",
|
|
2225
|
+
targetValue: "metalness",
|
|
2226
|
+
targetChannel: "b",
|
|
2227
|
+
physicalOnly: !1
|
|
2228
|
+
},
|
|
2229
|
+
{
|
|
2230
|
+
reportName: "occlusion",
|
|
2231
|
+
sources: [
|
|
2232
|
+
{ dialect: "usd-preview", inputNames: ["occlusion", "ambientOcclusion"] },
|
|
2233
|
+
{ dialect: "openpbr", inputNames: ["occlusion", "ambientOcclusion"] },
|
|
2234
|
+
{ dialect: "materialx-standard-surface", inputNames: ["occlusion", "ambientOcclusion"] }
|
|
2235
|
+
],
|
|
2236
|
+
targetMap: "aoMap",
|
|
2237
|
+
targetValue: "aoMapIntensity",
|
|
2238
|
+
targetChannel: "r",
|
|
2239
|
+
physicalOnly: !1,
|
|
2240
|
+
aoApproximation: !0
|
|
2241
|
+
},
|
|
2242
|
+
{
|
|
2243
|
+
reportName: "clearcoat",
|
|
2244
|
+
sources: [
|
|
2245
|
+
{ dialect: "openpbr", inputNames: ["coat_weight", "clearcoat", "coat"] },
|
|
2246
|
+
{ dialect: "materialx-standard-surface", inputNames: ["coat", "coat_weight", "clearcoat"] }
|
|
2247
|
+
],
|
|
2248
|
+
targetMap: "clearcoatMap",
|
|
2249
|
+
targetValue: "clearcoat",
|
|
2250
|
+
targetChannel: "r",
|
|
2251
|
+
physicalOnly: !0
|
|
2252
|
+
},
|
|
2253
|
+
{
|
|
2254
|
+
reportName: "clearcoatRoughness",
|
|
2255
|
+
sources: [
|
|
2256
|
+
{ dialect: "openpbr", inputNames: ["coat_roughness", "clearcoatRoughness", "coatRoughness"] },
|
|
2257
|
+
{ dialect: "materialx-standard-surface", inputNames: ["coat_roughness", "clearcoatRoughness", "coatRoughness"] }
|
|
2258
|
+
],
|
|
2259
|
+
targetMap: "clearcoatRoughnessMap",
|
|
2260
|
+
targetValue: "clearcoatRoughness",
|
|
2261
|
+
targetChannel: "g",
|
|
2262
|
+
physicalOnly: !0
|
|
2263
|
+
},
|
|
2264
|
+
{
|
|
2265
|
+
reportName: "transmission",
|
|
2266
|
+
sources: [
|
|
2267
|
+
{ dialect: "openpbr", inputNames: ["transmission_weight", "transmission", "transmissionWeight"] },
|
|
2268
|
+
{ dialect: "materialx-standard-surface", inputNames: ["transmission", "transmission_weight", "transmissionWeight"] }
|
|
2269
|
+
],
|
|
2270
|
+
targetMap: "transmissionMap",
|
|
2271
|
+
targetValue: "transmission",
|
|
2272
|
+
targetChannel: "r",
|
|
2273
|
+
physicalOnly: !0
|
|
2274
|
+
},
|
|
2275
|
+
{
|
|
2276
|
+
reportName: "thickness",
|
|
2277
|
+
sources: [
|
|
2278
|
+
{ dialect: "openpbr", inputNames: ["thickness"] },
|
|
2279
|
+
{ dialect: "materialx-standard-surface", inputNames: ["thickness"] }
|
|
2280
|
+
],
|
|
2281
|
+
targetMap: "thicknessMap",
|
|
2282
|
+
targetValue: "thickness",
|
|
2283
|
+
targetChannel: "g",
|
|
2284
|
+
physicalOnly: !0
|
|
2285
|
+
},
|
|
2286
|
+
{
|
|
2287
|
+
reportName: "sheenRoughness",
|
|
2288
|
+
sources: [
|
|
2289
|
+
{ dialect: "openpbr", inputNames: ["fuzz_roughness", "sheen_roughness", "sheenRoughness"] },
|
|
2290
|
+
{ dialect: "materialx-standard-surface", inputNames: ["sheen_roughness", "sheenRoughness"] }
|
|
2291
|
+
],
|
|
2292
|
+
targetMap: "sheenRoughnessMap",
|
|
2293
|
+
targetValue: "sheenRoughness",
|
|
2294
|
+
targetChannel: "a",
|
|
2295
|
+
physicalOnly: !0
|
|
2296
|
+
}
|
|
2297
|
+
];
|
|
2298
|
+
async function gr(e, t, n, s, r, o) {
|
|
2299
|
+
const a = {
|
|
2300
|
+
applied: [],
|
|
2301
|
+
resolved: [],
|
|
2302
|
+
resolvedInputs: [],
|
|
2303
|
+
unsupported: [],
|
|
2304
|
+
resources: []
|
|
2305
|
+
}, c = Mt(e);
|
|
2306
|
+
for (const i of e)
|
|
2307
|
+
for (const l of Sn) {
|
|
2308
|
+
const h = l.sources.find((p) => p.dialect === i.dialect);
|
|
2309
|
+
if (!h) continue;
|
|
2310
|
+
let u;
|
|
2311
|
+
for (const p of h.inputNames)
|
|
2312
|
+
if (!s.has(`${i.dialect}:${p}`) && (u = i.textures.find((f) => f.surfaceInput === p), u))
|
|
2313
|
+
break;
|
|
2314
|
+
if (!u) continue;
|
|
2315
|
+
const d = await yr(
|
|
2316
|
+
i,
|
|
2317
|
+
l,
|
|
2318
|
+
u,
|
|
2319
|
+
t,
|
|
2320
|
+
n,
|
|
2321
|
+
c,
|
|
2322
|
+
r,
|
|
2323
|
+
o
|
|
2324
|
+
);
|
|
2325
|
+
a.applied.push(...d.applied), a.resolved.push(...d.resolved), a.resolvedInputs.push(...d.resolvedInputs), a.unsupported.push(...d.unsupported), a.resources.push(...d.resources);
|
|
2326
|
+
}
|
|
2327
|
+
return a;
|
|
2328
|
+
}
|
|
2329
|
+
async function yr(e, t, n, s, r, o, a, c) {
|
|
2330
|
+
var v;
|
|
2331
|
+
const i = {
|
|
2332
|
+
applied: [],
|
|
2333
|
+
resolved: [],
|
|
2334
|
+
resolvedInputs: [],
|
|
2335
|
+
unsupported: [],
|
|
2336
|
+
resources: []
|
|
2337
|
+
}, l = (m) => (i.unsupported.push(`${e.dialect}.${t.reportName}.${m}`), i);
|
|
2338
|
+
if (o) return l("multiple-uv-sets");
|
|
2339
|
+
if (((v = n.sourceColorSpace) == null ? void 0 : v.toLowerCase()) !== "raw") return l("non-raw-color-space");
|
|
2340
|
+
if (n.sourceChannel === "rgb" || n.sourceChannel === "mono")
|
|
2341
|
+
return l("missing-source-channel");
|
|
2342
|
+
const h = Se(n.wrapS), u = Se(n.wrapT);
|
|
2343
|
+
if (h === null || u === null) return l("unsupported-wrap");
|
|
2344
|
+
const d = "rgba".indexOf(n.sourceChannel), p = n.scale[d], f = n.bias[d], _ = p === 1 && f === 0, w = s.filter(W).filter((m) => !t.physicalOnly || m instanceof K);
|
|
2345
|
+
if (!w.length) return l("physical-material-required");
|
|
2346
|
+
const g = w.map((m) => Sr(m, t));
|
|
2347
|
+
if (g.some((m) => (m == null ? void 0 : m.userData.usdTextureOwner) === "foreign"))
|
|
2348
|
+
return l("existing-foreign-map");
|
|
2349
|
+
const b = JSON.stringify([
|
|
2350
|
+
"usd-scalar-v2",
|
|
2351
|
+
e.materialPath,
|
|
2352
|
+
t.reportName,
|
|
2353
|
+
n.shaderPath,
|
|
2354
|
+
n.path,
|
|
2355
|
+
n.sourceColorSpace,
|
|
2356
|
+
n.sourceChannel,
|
|
2357
|
+
t.targetChannel,
|
|
2358
|
+
p,
|
|
2359
|
+
f,
|
|
2360
|
+
h,
|
|
2361
|
+
u,
|
|
2362
|
+
n.uvSet ?? "st",
|
|
2363
|
+
n.uvTransform
|
|
2364
|
+
]);
|
|
2365
|
+
if (g.every((m) => (m == null ? void 0 : m.userData.usdScalarConversionKey) === b)) {
|
|
2366
|
+
i.applied.push(`${t.reportName}.texture.${n.sourceChannel}->${t.targetChannel}`), i.resolvedInputs.push(n.surfaceInput);
|
|
2367
|
+
const m = ct(r, n, t.reportName);
|
|
2368
|
+
return m && i.resolved.push(m), i;
|
|
2369
|
+
}
|
|
2370
|
+
if (!_ || n.sourceChannel !== t.targetChannel) {
|
|
2371
|
+
const m = ct(r, n, t.reportName) !== null;
|
|
2372
|
+
if (g.some((R) => R !== null && !R.userData.usdScalarConversionKey && !m)) return l("existing-map-owner-unknown");
|
|
2373
|
+
} else if (g.some((m) => m !== null) && g.every((m) => m !== null))
|
|
2374
|
+
return i.resolvedInputs.push(n.surfaceInput), i;
|
|
2375
|
+
const y = await ce(n.path, a);
|
|
2376
|
+
if (i.resources.push(y.report), !y.url) return i;
|
|
2377
|
+
let S = null;
|
|
2378
|
+
try {
|
|
2379
|
+
S = await (a.createTexture ?? le)(y.url, oe);
|
|
2380
|
+
const m = Ae(
|
|
2381
|
+
S,
|
|
2382
|
+
n.sourceChannel,
|
|
2383
|
+
p,
|
|
2384
|
+
f,
|
|
2385
|
+
t.targetChannel === "a" ? "a" : "rgb"
|
|
2386
|
+
);
|
|
2387
|
+
m.wrapS = h, m.wrapT = u, ot(m, n.uvTransform), m.channel = 0, m.userData.usdScalarConversionKey = b, m.userData.usdTextureOwner = "adapter-derived";
|
|
2388
|
+
for (const R of g)
|
|
2389
|
+
R != null && R.userData.usdScalarConversionKey && c.add(R);
|
|
2390
|
+
for (const R of w) vr(R, t, m);
|
|
2391
|
+
i.applied.push(`${t.reportName}.texture.${n.sourceChannel}->${t.targetChannel}`), i.resolvedInputs.push(n.surfaceInput), t.aoApproximation && a.diagnostics.approximations.push({
|
|
2392
|
+
code: "USD_VISUAL_AO_LIGHTING_APPROXIMATION",
|
|
2393
|
+
source: "usd-visual",
|
|
2394
|
+
message: `USD 材质 ${e.materialPath} 的 AO 已映射为 Three.js 间接光遮蔽;并非源材质对漫反射或直接光的等价调制。`
|
|
2395
|
+
});
|
|
2396
|
+
const x = ct(r, n, t.reportName);
|
|
2397
|
+
x && i.resolved.push(x);
|
|
2398
|
+
} catch (m) {
|
|
2399
|
+
if (m instanceof Error && m.name === "AbortError") throw m;
|
|
2400
|
+
i.resources[i.resources.length - 1] = { path: n.path, status: "decode-failed" };
|
|
2401
|
+
} finally {
|
|
2402
|
+
S == null || S.dispose();
|
|
2403
|
+
}
|
|
2404
|
+
return i;
|
|
2405
|
+
}
|
|
2406
|
+
function wr(e, t) {
|
|
2407
|
+
if (!t.size) return;
|
|
2408
|
+
const n = /* @__PURE__ */ new Set();
|
|
2409
|
+
e.traverse((s) => {
|
|
2410
|
+
if (!s || !("material" in s)) return;
|
|
2411
|
+
const r = s.material;
|
|
2412
|
+
for (const o of Array.isArray(r) ? r : [r])
|
|
2413
|
+
if (o)
|
|
2414
|
+
for (const a of Object.values(o))
|
|
2415
|
+
a instanceof Pt && n.add(a);
|
|
2416
|
+
});
|
|
2417
|
+
for (const s of t)
|
|
2418
|
+
s.userData.usdTextureOwner !== "adapter-derived" || n.has(s) || s.dispose();
|
|
2419
|
+
}
|
|
2420
|
+
function Mt(e) {
|
|
2421
|
+
return new Set(e.flatMap((t) => t.textures.map((n) => (n.uvSet ?? "st").toLowerCase()))).size > 1;
|
|
2422
|
+
}
|
|
2423
|
+
function br(e) {
|
|
2424
|
+
if (!e || e.dialect !== "openpbr") return !1;
|
|
2425
|
+
const t = new Set(Sn.filter((n) => n.physicalOnly).flatMap((n) => n.sources.filter((s) => s.dialect === "openpbr").flatMap((s) => s.inputNames)));
|
|
2426
|
+
return e.textures.some((n) => t.has(n.surfaceInput));
|
|
2427
|
+
}
|
|
2428
|
+
function Se(e) {
|
|
2429
|
+
const t = e == null ? void 0 : e.toLowerCase();
|
|
2430
|
+
return t ? t === "repeat" || t === "periodic" ? te : t === "mirror" || t === "mirroredrepeat" ? on : t === "clamp" ? an : null : null;
|
|
2431
|
+
}
|
|
2432
|
+
function Sr(e, t) {
|
|
2433
|
+
switch (t.targetMap) {
|
|
2434
|
+
case "roughnessMap":
|
|
2435
|
+
return e.roughnessMap;
|
|
2436
|
+
case "metalnessMap":
|
|
2437
|
+
return e.metalnessMap;
|
|
2438
|
+
case "aoMap":
|
|
2439
|
+
return e.aoMap;
|
|
2440
|
+
case "clearcoatMap":
|
|
2441
|
+
return e instanceof K ? e.clearcoatMap : null;
|
|
2442
|
+
case "clearcoatRoughnessMap":
|
|
2443
|
+
return e instanceof K ? e.clearcoatRoughnessMap : null;
|
|
2444
|
+
case "transmissionMap":
|
|
2445
|
+
return e instanceof K ? e.transmissionMap : null;
|
|
2446
|
+
case "thicknessMap":
|
|
2447
|
+
return e instanceof K ? e.thicknessMap : null;
|
|
2448
|
+
case "sheenRoughnessMap":
|
|
2449
|
+
return e instanceof K ? e.sheenRoughnessMap : null;
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
function vr(e, t, n) {
|
|
2453
|
+
switch (t.targetMap) {
|
|
2454
|
+
case "roughnessMap":
|
|
2455
|
+
e.roughnessMap = n;
|
|
2456
|
+
break;
|
|
2457
|
+
case "metalnessMap":
|
|
2458
|
+
e.metalnessMap = n;
|
|
2459
|
+
break;
|
|
2460
|
+
case "aoMap":
|
|
2461
|
+
e.aoMap = n;
|
|
2462
|
+
break;
|
|
2463
|
+
case "clearcoatMap":
|
|
2464
|
+
if (e instanceof K) e.clearcoatMap = n;
|
|
2465
|
+
else return;
|
|
2466
|
+
break;
|
|
2467
|
+
case "clearcoatRoughnessMap":
|
|
2468
|
+
if (e instanceof K) e.clearcoatRoughnessMap = n;
|
|
2469
|
+
else return;
|
|
2470
|
+
break;
|
|
2471
|
+
case "transmissionMap":
|
|
2472
|
+
if (e instanceof K) e.transmissionMap = n;
|
|
2473
|
+
else return;
|
|
2474
|
+
break;
|
|
2475
|
+
case "thicknessMap":
|
|
2476
|
+
if (e instanceof K) e.thicknessMap = n;
|
|
2477
|
+
else return;
|
|
2478
|
+
break;
|
|
2479
|
+
case "sheenRoughnessMap":
|
|
2480
|
+
if (e instanceof K) e.sheenRoughnessMap = n;
|
|
2481
|
+
else return;
|
|
2482
|
+
break;
|
|
2483
|
+
}
|
|
2484
|
+
switch (t.targetValue) {
|
|
2485
|
+
case "roughness":
|
|
2486
|
+
e.roughness = 1;
|
|
2487
|
+
break;
|
|
2488
|
+
case "metalness":
|
|
2489
|
+
e.metalness = 1;
|
|
2490
|
+
break;
|
|
2491
|
+
case "aoMapIntensity":
|
|
2492
|
+
e.aoMapIntensity = 1;
|
|
2493
|
+
break;
|
|
2494
|
+
case "clearcoat":
|
|
2495
|
+
e instanceof K && (e.clearcoat = 1);
|
|
2496
|
+
break;
|
|
2497
|
+
case "clearcoatRoughness":
|
|
2498
|
+
e instanceof K && (e.clearcoatRoughness = 1);
|
|
2499
|
+
break;
|
|
2500
|
+
case "transmission":
|
|
2501
|
+
e instanceof K && (e.transmission = 1);
|
|
2502
|
+
break;
|
|
2503
|
+
case "thickness":
|
|
2504
|
+
e instanceof K && (e.thickness = 1);
|
|
2505
|
+
break;
|
|
2506
|
+
case "sheenRoughness":
|
|
2507
|
+
e instanceof K && (e.sheenRoughness = 1);
|
|
2508
|
+
break;
|
|
2509
|
+
}
|
|
2510
|
+
e.needsUpdate = !0;
|
|
2511
|
+
}
|
|
2512
|
+
function ct(e, t, n) {
|
|
2513
|
+
return e.find((s) => s.includes(`from ${t.shaderPath}`) && s.includes(`Three.js ${n}`)) ?? e.find((s) => s.startsWith(`Texture scale/bias on ${t.shaderPath}`)) ?? null;
|
|
2514
|
+
}
|
|
2515
|
+
function Ur(e) {
|
|
2516
|
+
const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
|
|
2517
|
+
return e.scene.traverse((s) => {
|
|
2518
|
+
if (!(s instanceof me)) return;
|
|
2519
|
+
let r = s.visible && !s.userData.usdPurposeExcluded, o = s.parent;
|
|
2520
|
+
for (; r && o; )
|
|
2521
|
+
r = o.visible && !o.userData.usdPurposeExcluded, o = o.parent;
|
|
2522
|
+
if (!(!r || s.userData.usdPurposeExcluded))
|
|
2523
|
+
for (const a of Array.isArray(s.material) ? s.material : [s.material]) {
|
|
2524
|
+
if (n.has(a)) continue;
|
|
2525
|
+
n.add(a);
|
|
2526
|
+
const c = pe(a.userData.usdMaterialPath);
|
|
2527
|
+
if (!c) continue;
|
|
2528
|
+
const i = t.get(c);
|
|
2529
|
+
i ? i.push(a) : t.set(c, [a]);
|
|
2530
|
+
}
|
|
2531
|
+
}), t;
|
|
2532
|
+
}
|
|
2533
|
+
function bt(e, t) {
|
|
2534
|
+
const n = t ? e.shaders.find((r) => r.path === t) : void 0;
|
|
2535
|
+
if (n) return n;
|
|
2536
|
+
const s = e.shaders.filter((r) => /^PxrSurface$/i.test(r.id ?? "") || Xe(r) || Ct(r) || xt(r) || Dt(r) || Et(r));
|
|
2537
|
+
return s.length === 1 ? s[0] : null;
|
|
2538
|
+
}
|
|
2539
|
+
function qt(e, t, n) {
|
|
2540
|
+
if (n) {
|
|
2541
|
+
const a = e.shaders.find((c) => c.path === n);
|
|
2542
|
+
if (a) return a;
|
|
2543
|
+
}
|
|
2544
|
+
const s = pe(t.userData.usdSurfaceShaderPath);
|
|
2545
|
+
if (s) {
|
|
2546
|
+
const a = e.shaders.find((c) => c.path === s);
|
|
2547
|
+
if (a) return a;
|
|
2548
|
+
}
|
|
2549
|
+
const r = bt(e);
|
|
2550
|
+
if (r) return r;
|
|
2551
|
+
const o = e.shaders.filter((a) => De.test(a.id ?? "") || bn.test(a.id ?? ""));
|
|
2552
|
+
return o.length === 1 ? o[0] : null;
|
|
2553
|
+
}
|
|
2554
|
+
function Pr(e) {
|
|
2555
|
+
return De.test(e.id ?? "");
|
|
2556
|
+
}
|
|
2557
|
+
function Or(e) {
|
|
2558
|
+
return /open.?pbr/i.test(e.id ?? "");
|
|
2559
|
+
}
|
|
2560
|
+
function vn(e) {
|
|
2561
|
+
return /open.?pbr/i.test(e);
|
|
2562
|
+
}
|
|
2563
|
+
function Yt(e, t, n) {
|
|
2564
|
+
var o;
|
|
2565
|
+
const s = pe((o = t[0]) == null ? void 0 : o.userData.usdSurfaceShaderPath);
|
|
2566
|
+
if (s) {
|
|
2567
|
+
const a = e.shaders.find((c) => c.path === s);
|
|
2568
|
+
if (a && n(a)) return a;
|
|
2569
|
+
}
|
|
2570
|
+
const r = e.shaders.filter(n);
|
|
2571
|
+
return r.length === 1 ? r[0] : null;
|
|
2572
|
+
}
|
|
2573
|
+
function Rr(e, t, n, s, r) {
|
|
2574
|
+
const o = Un(e), a = pe(t.userData.usdSurfaceShaderPath), c = (i, l) => o.has(i.path) || a === i.path || l;
|
|
2575
|
+
return c(s, De.test(n ?? "")) && c(r, vn(n ?? ""));
|
|
2576
|
+
}
|
|
2577
|
+
function Un(e) {
|
|
2578
|
+
const t = /* @__PURE__ */ new Set(), n = (s) => {
|
|
2579
|
+
for (const [r, o] of Object.entries(s)) {
|
|
2580
|
+
if (!/surface/i.test(r) || !/(?:connect|outputs)/i.test(r)) continue;
|
|
2581
|
+
const a = Re(o);
|
|
2582
|
+
a && t.add(a.path);
|
|
2583
|
+
}
|
|
2584
|
+
};
|
|
2585
|
+
n(e.inputs);
|
|
2586
|
+
for (const s of e.shaders) n(s.inputs);
|
|
2587
|
+
return t;
|
|
2588
|
+
}
|
|
2589
|
+
function Ir(e) {
|
|
2590
|
+
var s, r, o, a, c;
|
|
2591
|
+
const t = /* @__PURE__ */ new Map(), n = e.stage;
|
|
2592
|
+
for (const i of e.data.materials) {
|
|
2593
|
+
const l = Un(i);
|
|
2594
|
+
if (l.size === 1) {
|
|
2595
|
+
t.set(i.path, [...l][0]);
|
|
2596
|
+
continue;
|
|
2597
|
+
}
|
|
2598
|
+
if (!(n != null && n.GetPrimAtPath)) continue;
|
|
2599
|
+
const h = n.GetPrimAtPath(i.path);
|
|
2600
|
+
if (h != null && h.GetAttribute) {
|
|
2601
|
+
for (const u of ["outputs:mdl:surface", "outputs:surface", "surface"]) {
|
|
2602
|
+
const d = h.GetAttribute(u);
|
|
2603
|
+
if (!((s = d == null ? void 0 : d.IsValid) != null && s.call(d))) {
|
|
2604
|
+
(r = d == null ? void 0 : d.delete) == null || r.call(d);
|
|
2605
|
+
continue;
|
|
2606
|
+
}
|
|
2607
|
+
try {
|
|
2608
|
+
for (const p of ((o = d.GetConnections) == null ? void 0 : o.call(d)) ?? []) {
|
|
2609
|
+
const f = typeof p == "string" ? p : p.path, _ = Re(f);
|
|
2610
|
+
if (_) {
|
|
2611
|
+
t.set(i.path, _.path);
|
|
2612
|
+
break;
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
} finally {
|
|
2616
|
+
(a = d.delete) == null || a.call(d);
|
|
2617
|
+
}
|
|
2618
|
+
if (t.has(i.path)) break;
|
|
2619
|
+
}
|
|
2620
|
+
(c = h.delete) == null || c.call(h);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
return t;
|
|
2624
|
+
}
|
|
2625
|
+
function ke(e, t) {
|
|
2626
|
+
const n = /* @__PURE__ */ new Map();
|
|
2627
|
+
for (const s of t) {
|
|
2628
|
+
if (!W(s) || s instanceof K) continue;
|
|
2629
|
+
const r = new K();
|
|
2630
|
+
Ot.prototype.copy.call(r, s), r.defines = { STANDARD: "", PHYSICAL: "" }, n.set(s, r);
|
|
2631
|
+
}
|
|
2632
|
+
if (!n.size) return t.filter((s) => s instanceof K);
|
|
2633
|
+
e.scene.traverse((s) => {
|
|
2634
|
+
s instanceof me && (s.material = Array.isArray(s.material) ? s.material.map((r) => n.get(r) ?? r) : n.get(s.material) ?? s.material);
|
|
2635
|
+
}), t.forEach((s, r) => {
|
|
2636
|
+
t[r] = n.get(s) ?? s;
|
|
2637
|
+
});
|
|
2638
|
+
for (const s of n.keys()) s.dispose();
|
|
2639
|
+
return t.filter((s) => s instanceof K);
|
|
2640
|
+
}
|
|
2641
|
+
function xt(e) {
|
|
2642
|
+
var s;
|
|
2643
|
+
const t = ae(e.inputs["info:mdl:sourceAsset"]), n = e.inputs["info:mdl:sourceAsset:subIdentifier"];
|
|
2644
|
+
return ((s = t == null ? void 0 : t.replaceAll("\\", "/").split("/").at(-1)) == null ? void 0 : s.toLowerCase()) === "omniglass.mdl" && (n === void 0 || n === "OmniGlass");
|
|
2645
|
+
}
|
|
2646
|
+
function Ar(e, t, n) {
|
|
2647
|
+
const s = { applied: [], unsupported: /* @__PURE__ */ new Set() }, r = /* @__PURE__ */ new Set(["glass_color", "glass_ior", "frosting_roughness", "thin_walled", "reflection_color", "enable_opacity", "cutout_opacity", "opacity_constant", "opacity_threshold"]);
|
|
2648
|
+
for (const [b, y] of Object.entries(n.inputs)) {
|
|
2649
|
+
if (!b.startsWith("inputs:")) continue;
|
|
2650
|
+
const S = b.slice(7);
|
|
2651
|
+
r.has(S) || ["glass_color_texture", "roughness_texture", "normalmap_texture"].includes(S) && !ae(y) || s.unsupported.add(`OmniGlass.${S}`);
|
|
2652
|
+
}
|
|
2653
|
+
const o = (b) => (s.unsupported.add(`OmniGlass.${b}`), s);
|
|
2654
|
+
for (const b of r) if (ee(n, b)) return o(`${b}.connection`);
|
|
2655
|
+
const a = N(n, ["glass_ior"]) ?? 1.491, c = N(n, ["frosting_roughness"]) ?? 0, i = G(n, ["thin_walled"]) ?? !1, l = G(n, ["glass_color"]) ?? [1, 1, 1], h = G(n, ["reflection_color"]) ?? [1, 1, 1];
|
|
2656
|
+
if (!Array.isArray(h) || h.length !== 3 || !h.every((b) => typeof b == "number" && Number.isFinite(b) && b >= 0 && b <= 1)) return o("reflection_color.range");
|
|
2657
|
+
if (G(n, ["glass_ior"]) !== void 0 && N(n, ["glass_ior"]) === null || a < 1 || a > 2.333) return o("glass_ior.range");
|
|
2658
|
+
if (G(n, ["frosting_roughness"]) !== void 0 && N(n, ["frosting_roughness"]) === null || c < 0 || c > 1) return o("frosting_roughness.range");
|
|
2659
|
+
if (typeof i != "boolean") return o("thin_walled.type");
|
|
2660
|
+
if (!Array.isArray(l) || l.length !== 3 || !l.every((b) => typeof b == "number" && Number.isFinite(b) && b >= 0 && b <= 1)) return o("glass_color.range");
|
|
2661
|
+
if (t.some((b) => !W(b))) return o("non-standard-loader-material");
|
|
2662
|
+
if (t.some((b) => W(b) && (b.map || b.alphaMap || b.roughnessMap || b.metalnessMap))) return o("existing-loader-texture-semantics");
|
|
2663
|
+
i || s.unsupported.add("OmniGlass.solid_volume_absorption"), i && l.some((b) => b !== 1) && s.unsupported.add("OmniGlass.tint_reflection_coupling"), !i && l.some((b) => b !== 1) && s.unsupported.add("OmniGlass.glass_color.volume");
|
|
2664
|
+
const u = G(n, ["enable_opacity"]) ?? !1;
|
|
2665
|
+
if (typeof u != "boolean") return o("enable_opacity.type");
|
|
2666
|
+
const d = N(n, ["cutout_opacity"]), p = N(n, ["opacity_constant"]);
|
|
2667
|
+
if (u && d !== null && p !== null && Math.abs(d - p) > 1e-6) return o("opacity.alias-conflict");
|
|
2668
|
+
for (const b of ["cutout_opacity", "opacity_constant", "opacity_threshold"]) if (u && G(n, [b]) !== void 0 && N(n, [b]) === null) return o(`${b}.type`);
|
|
2669
|
+
const f = u ? d ?? p ?? 1 : 1, _ = u ? N(n, ["opacity_threshold"]) ?? 0 : 0;
|
|
2670
|
+
if (f < 0 || f > 1 || _ < 0 || _ > 1) return o("opacity.range");
|
|
2671
|
+
if (u && (ae(G(n, ["opacity_texture"])) || ee(n, "opacity_texture"))) return o("opacity_texture");
|
|
2672
|
+
const w = _ > 0 ? f >= _ ? 1 : 0 : f, g = /* @__PURE__ */ new Map();
|
|
2673
|
+
for (const b of t) {
|
|
2674
|
+
const y = b instanceof K ? b : new K();
|
|
2675
|
+
y !== b && (Ot.prototype.copy.call(y, b), y.defines = { STANDARD: "", PHYSICAL: "" }, g.set(b, y)), y.color.setRGB(...i ? l : [1, 1, 1]), y.specularColor.setRGB(...h), y.metalness = 0, y.roughness = c, y.ior = a, y.opacity = w, y.transparent = _ === 0 && w < 1, y.alphaTest = _ > 0 ? 0.5 : 0, y.transmission = 1, y.thickness = 0, y.depthWrite = !y.transparent, y.attenuationColor.setRGB(1, 1, 1), y.attenuationDistance = 1 / 0, y.needsUpdate = !0;
|
|
2676
|
+
}
|
|
2677
|
+
e.scene.traverse((b) => {
|
|
2678
|
+
b instanceof me && (b.material = Array.isArray(b.material) ? b.material.map((y) => g.get(y) ?? y) : g.get(b.material) ?? b.material);
|
|
2679
|
+
}), t.forEach((b, y) => {
|
|
2680
|
+
t[y] = g.get(b) ?? b;
|
|
2681
|
+
});
|
|
2682
|
+
for (const b of g.keys()) b.dispose();
|
|
2683
|
+
return s.applied.push("OmniGlass.reflection_color.specular-approximation", "OmniGlass.glass_ior", "OmniGlass.frosting_roughness", "OmniGlass.surface_transmission"), u && s.applied.push("OmniGlass.opacity.constant-coverage"), w > 0 && w < 1 && s.unsupported.add("OmniGlass.fractional_coverage_transmission_compositing"), i && s.applied.push("OmniGlass.thin_walled", "OmniGlass.glass_color.surface-approximation"), s;
|
|
2684
|
+
}
|
|
2685
|
+
async function Mr(e, t, n, s) {
|
|
2686
|
+
const r = [], o = ["normalmap_texture", "normalmap_texture_colorspace", "bump_factor", "flip_tangent_u", "flip_tangent_v"], a = () => o.forEach((_) => n.unsupported.delete(`OmniGlass.${_}`));
|
|
2687
|
+
if (o.some((_) => ee(t, _))) return r;
|
|
2688
|
+
const c = ae(G(t, ["normalmap_texture"]));
|
|
2689
|
+
if (!c)
|
|
2690
|
+
return a(), r;
|
|
2691
|
+
const i = N(t, ["bump_factor"]) ?? 1;
|
|
2692
|
+
if (G(t, ["bump_factor"]) !== void 0 && N(t, ["bump_factor"]) === null || i < 0) return r;
|
|
2693
|
+
if (i === 0)
|
|
2694
|
+
return a(), r;
|
|
2695
|
+
const l = G(t, ["flip_tangent_u"]) ?? !1, h = G(t, ["flip_tangent_v"]) ?? !0;
|
|
2696
|
+
if (typeof l != "boolean" || typeof h != "boolean" || G(t, ["normalmap_texture_colorspace"]) !== "raw" || ["project_uvw", "world_or_object", "uv_space_index", "texture_scale", "texture_translate", "texture_rotate"].some((_) => ee(t, _)) || !Ue(t, /* @__PURE__ */ new Set())) return r;
|
|
2697
|
+
const d = e.filter((_) => _ instanceof K);
|
|
2698
|
+
if (!d.length || d.some((_) => _.normalMap))
|
|
2699
|
+
return n.unsupported.add("OmniGlass.existing_normalMap"), r;
|
|
2700
|
+
const p = await ce(c, s);
|
|
2701
|
+
if (r.push(p.report), !p.url) return r;
|
|
2702
|
+
let f = null;
|
|
2703
|
+
try {
|
|
2704
|
+
f = await (s.createTexture ?? le)(p.url, oe), f.colorSpace = oe, f.wrapS = te, f.wrapT = te, f.channel = 0;
|
|
2705
|
+
for (const _ of d)
|
|
2706
|
+
_.normalMap = f, _.normalScale.set(i * (l ? -1 : 1), i * (h ? -1 : 1)), _.needsUpdate = !0;
|
|
2707
|
+
a(), n.applied.push("OmniGlass.normalmap_texture", "OmniGlass.normal.tangent_convention"), f = null;
|
|
2708
|
+
} catch (_) {
|
|
2709
|
+
if (_ instanceof Error && _.name === "AbortError") throw _;
|
|
2710
|
+
r[0] = { path: c, status: "decode-failed" };
|
|
2711
|
+
} finally {
|
|
2712
|
+
f == null || f.dispose();
|
|
2713
|
+
}
|
|
2714
|
+
return r;
|
|
2715
|
+
}
|
|
2716
|
+
async function xr(e, t, n, s) {
|
|
2717
|
+
const r = [], o = ae(G(t, ["roughness_texture"]));
|
|
2718
|
+
if (!o) return r;
|
|
2719
|
+
const a = N(t, ["roughness_texture_influence"]) ?? 1;
|
|
2720
|
+
if (ee(t, "roughness_texture_influence") || a < 0 || a > 1 || G(t, ["roughness_texture_influence"]) !== void 0 && N(t, ["roughness_texture_influence"]) === null) return r;
|
|
2721
|
+
if (a === 0)
|
|
2722
|
+
return n.unsupported.delete("OmniGlass.roughness_texture"), n.unsupported.delete("OmniGlass.roughness_texture_influence"), r;
|
|
2723
|
+
if (G(t, ["roughness_texture_colorspace"]) !== "raw" || ["project_uvw", "uv_space_index", "texture_scale", "texture_translate", "texture_rotate"].some((u) => ee(t, u)) || !Ue(t, /* @__PURE__ */ new Set())) return r;
|
|
2724
|
+
const l = await ce(o, s);
|
|
2725
|
+
if (r.push(l.report), !l.url) return r;
|
|
2726
|
+
let h = null;
|
|
2727
|
+
try {
|
|
2728
|
+
h = await (s.createTexture ?? le)(l.url, oe);
|
|
2729
|
+
const u = N(t, ["frosting_roughness"]) ?? 0, d = Ae(h, "grayscale", a, u * (1 - a));
|
|
2730
|
+
d.wrapS = te, d.wrapT = te;
|
|
2731
|
+
for (const p of e) p instanceof K && (p.roughnessMap = d, p.roughness = 1, p.needsUpdate = !0);
|
|
2732
|
+
n.applied.push("OmniGlass.roughness_texture.grayscale-linear-blend");
|
|
2733
|
+
for (const p of ["roughness_texture", "roughness_texture_influence", "roughness_texture_colorspace"]) n.unsupported.delete(`OmniGlass.${p}`);
|
|
2734
|
+
} catch (u) {
|
|
2735
|
+
if (u instanceof Error && u.name === "AbortError") throw u;
|
|
2736
|
+
n.unsupported.add("OmniGlass.roughness_texture.pixel-conversion");
|
|
2737
|
+
} finally {
|
|
2738
|
+
h == null || h.dispose();
|
|
2739
|
+
}
|
|
2740
|
+
return r;
|
|
2741
|
+
}
|
|
2742
|
+
function Xe(e) {
|
|
2743
|
+
var n;
|
|
2744
|
+
const t = ae(e.inputs["info:mdl:sourceAsset"]);
|
|
2745
|
+
return ((n = t == null ? void 0 : t.replaceAll("\\", "/").split("/").at(-1)) == null ? void 0 : n.toLowerCase()) === "omnipbr.mdl";
|
|
2746
|
+
}
|
|
2747
|
+
function Ct(e) {
|
|
2748
|
+
var s, r;
|
|
2749
|
+
const t = (s = ae(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : s.replaceAll("\\", "/"), n = pe(e.inputs["info:mdl:sourceAsset:subIdentifier"]);
|
|
2750
|
+
return ((r = t == null ? void 0 : t.split("/").at(-1)) == null ? void 0 : r.toLowerCase()) !== "omnipbrbase.mdl" ? !1 : n ? n.toLowerCase() === "omnipbrbase" : [
|
|
2751
|
+
"inputs:diffuse_reflection_color",
|
|
2752
|
+
"inputs:geometry_opacity",
|
|
2753
|
+
"inputs:specular_level",
|
|
2754
|
+
"inputs:enable_coat",
|
|
2755
|
+
"inputs:specular_reflection_roughness"
|
|
2756
|
+
].some((o) => e.inputs[o] !== void 0 || e.inputs[`${o}.connect`] !== void 0 || e.inputs[`${o}.resolvedConnect`] !== void 0);
|
|
2757
|
+
}
|
|
2758
|
+
function Dt(e) {
|
|
2759
|
+
var s;
|
|
2760
|
+
const t = (s = ae(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : s.replaceAll("\\", "/"), n = pe(e.inputs["info:mdl:sourceAsset:subIdentifier"]);
|
|
2761
|
+
return /(?:^|\/)gltf\/pbr\.mdl$/i.test(t ?? "") ? n !== null ? n.toLowerCase() === "gltf_material" : [
|
|
2762
|
+
"inputs:base_color_factor",
|
|
2763
|
+
"inputs:metallic_factor",
|
|
2764
|
+
"inputs:roughness_factor",
|
|
2765
|
+
"inputs:alpha_mode",
|
|
2766
|
+
"inputs:base_alpha",
|
|
2767
|
+
"inputs:base_color_texture.connect",
|
|
2768
|
+
"inputs:normal_texture.connect"
|
|
2769
|
+
].some((r) => e.inputs[r] !== void 0) : !1;
|
|
2770
|
+
}
|
|
2771
|
+
function Et(e) {
|
|
2772
|
+
var s, r;
|
|
2773
|
+
const t = (s = ae(e.inputs["info:mdl:sourceAsset"])) == null ? void 0 : s.replaceAll("\\", "/"), n = pe(e.inputs["info:mdl:sourceAsset:subIdentifier"]);
|
|
2774
|
+
return ((r = t == null ? void 0 : t.split("/").at(-1)) == null ? void 0 : r.toLowerCase()) === "omnisurfacebase.mdl" || (n == null ? void 0 : n.toLowerCase()) === "omnisurfacebase";
|
|
2775
|
+
}
|
|
2776
|
+
async function Cr(e, t, n, s, r) {
|
|
2777
|
+
const o = [], a = [], c = [], i = he(e, ["base_color_factor"]), l = N(e, ["metallic_factor"]), h = N(e, ["roughness_factor"]), u = Wr(G(e, ["alpha_mode"])), d = Q(N(e, ["base_alpha"]) ?? 1), p = Q(N(e, ["alpha_cutoff"]) ?? 0.5);
|
|
2778
|
+
i && o.push("gltf_material.base_color_factor"), l !== null && o.push("gltf_material.metallic_factor"), h !== null && o.push("gltf_material.roughness_factor"), o.push(`gltf_material.alpha_mode.${u}`), u === "blend" && o.push("gltf_material.base_alpha"), u === "mask" && o.push("gltf_material.alpha_cutoff");
|
|
2779
|
+
for (const y of n.filter(W))
|
|
2780
|
+
i && y.color.copy(i), l !== null && (y.metalness = Q(l)), h !== null && (y.roughness = Q(h)), y.alphaTest = u === "mask" ? p : 0, y.opacity = u === "blend" ? d : 1, y.transparent = u === "blend", y.depthWrite = u !== "blend", y.needsUpdate = !0;
|
|
2781
|
+
if (ee(e, "base_color_texture")) {
|
|
2782
|
+
const y = await rt(
|
|
2783
|
+
[t],
|
|
2784
|
+
n,
|
|
2785
|
+
/* @__PURE__ */ new Set(),
|
|
2786
|
+
s,
|
|
2787
|
+
r
|
|
2788
|
+
);
|
|
2789
|
+
if (o.push(...y.applied), a.push(...y.unsupported), c.push(...y.resources), i) for (const S of n.filter(W)) S.color.copy(i);
|
|
2790
|
+
}
|
|
2791
|
+
if (ee(e, "normal_texture")) {
|
|
2792
|
+
const y = await Dr(
|
|
2793
|
+
t,
|
|
2794
|
+
e,
|
|
2795
|
+
n,
|
|
2796
|
+
s,
|
|
2797
|
+
r
|
|
2798
|
+
);
|
|
2799
|
+
o.push(...y.applied), a.push(...y.unsupported), c.push(...y.resources);
|
|
2800
|
+
}
|
|
2801
|
+
const w = /* @__PURE__ */ new Set(["base_color_texture", "normal_texture"]);
|
|
2802
|
+
for (const [y, S] of Object.entries(e.inputs)) {
|
|
2803
|
+
if (!y.endsWith(".resolvedConnect") && !y.endsWith(".connect")) continue;
|
|
2804
|
+
const v = y.replace(/^inputs:/, "").replace(/\.(?:resolvedConnect|connect)$/, "");
|
|
2805
|
+
if (w.has(v)) continue;
|
|
2806
|
+
const m = Re(S);
|
|
2807
|
+
a.push(`gltf_material.${v}${m ? `:${m.path}` : ""}`);
|
|
2808
|
+
}
|
|
2809
|
+
const g = he(e, ["emissive_factor"]);
|
|
2810
|
+
g && g.getHex() !== 0 && a.push("gltf_material.emissive_factor");
|
|
2811
|
+
const b = /* @__PURE__ */ new Set([
|
|
2812
|
+
"base_color_factor",
|
|
2813
|
+
"base_alpha",
|
|
2814
|
+
"alpha_mode",
|
|
2815
|
+
"alpha_cutoff",
|
|
2816
|
+
"metallic_factor",
|
|
2817
|
+
"roughness_factor",
|
|
2818
|
+
"emissive_strength",
|
|
2819
|
+
"base_color_texture",
|
|
2820
|
+
"normal_texture"
|
|
2821
|
+
]);
|
|
2822
|
+
for (const y of Object.keys(e.inputs)) {
|
|
2823
|
+
if (!y.startsWith("inputs:")) continue;
|
|
2824
|
+
const S = y.slice(7).replace(/\.(?:resolvedConnect|connect)$/, "");
|
|
2825
|
+
b.has(S) || a.push(`gltf_material.${S}`);
|
|
2826
|
+
}
|
|
2827
|
+
return { applied: ie(o), unsupported: ie(a), resources: c };
|
|
2828
|
+
}
|
|
2829
|
+
async function Dr(e, t, n, s, r) {
|
|
2830
|
+
var w;
|
|
2831
|
+
const o = { applied: [], unsupported: [], resources: [] }, a = e.textures.find((g) => g.surfaceInput === "normal_texture" && g.semantic === "normal");
|
|
2832
|
+
if (!a)
|
|
2833
|
+
return o.unsupported.push("gltf_material.normal_texture.unresolved-texture"), o;
|
|
2834
|
+
const c = (a.uvSet ?? "texcoord0").toLowerCase();
|
|
2835
|
+
if (c !== "texcoord0" && c !== "st")
|
|
2836
|
+
return o.unsupported.push(`gltf_material.normal_texture.uv=${c}`), o;
|
|
2837
|
+
if (((w = a.sourceColorSpace) == null ? void 0 : w.toLowerCase()) !== "raw")
|
|
2838
|
+
return o.unsupported.push(`gltf_material.normal_texture.color-space=${a.sourceColorSpace ?? "auto"}`), o;
|
|
2839
|
+
const i = a.wrapS === null ? te : Se(a.wrapS), l = a.wrapT === null ? te : Se(a.wrapT);
|
|
2840
|
+
if (i === null || l === null)
|
|
2841
|
+
return o.unsupported.push("gltf_material.normal_texture.unsupported-wrap"), o;
|
|
2842
|
+
const h = N(t, ["normal_scale", "normalScale"]) ?? 1;
|
|
2843
|
+
if (!Number.isFinite(h) || h < 0)
|
|
2844
|
+
return o.unsupported.push("gltf_material.normal_scale"), o;
|
|
2845
|
+
const u = n.filter(W);
|
|
2846
|
+
if (!u.length)
|
|
2847
|
+
return o.unsupported.push("gltf_material.normal_texture.standard-material-required"), o;
|
|
2848
|
+
const d = u.map((g) => g.normalMap);
|
|
2849
|
+
if (d.some((g) => g && g.userData.usdTextureOwner === "foreign"))
|
|
2850
|
+
return o.unsupported.push("gltf_material.normal_texture.existing-foreign-map"), o;
|
|
2851
|
+
const p = JSON.stringify([
|
|
2852
|
+
"gltf-normal-v1",
|
|
2853
|
+
e.materialPath,
|
|
2854
|
+
a.shaderPath,
|
|
2855
|
+
a.path,
|
|
2856
|
+
a.wrapS,
|
|
2857
|
+
a.wrapT,
|
|
2858
|
+
a.uvSet,
|
|
2859
|
+
a.uvTransform,
|
|
2860
|
+
h
|
|
2861
|
+
]);
|
|
2862
|
+
if (d.every((g) => (g == null ? void 0 : g.userData.usdNormalConversionKey) === p))
|
|
2863
|
+
return o.applied.push("gltf_material.normal_texture"), o.resources.push({ path: a.path, status: "available" }), o;
|
|
2864
|
+
if (d.some((g) => g && !g.userData.usdNormalConversionKey))
|
|
2865
|
+
return o.unsupported.push("gltf_material.normal_texture.existing-map-owner-unknown"), o;
|
|
2866
|
+
const f = await ce(a.path, s);
|
|
2867
|
+
if (o.resources.push(f.report), !f.url) return o;
|
|
2868
|
+
let _ = null;
|
|
2869
|
+
try {
|
|
2870
|
+
_ = await (s.createTexture ?? le)(f.url, oe), _.colorSpace = oe, _.wrapS = i, _.wrapT = l, _.channel = 0, _.userData.usdNormalConversionKey = p, _.userData.usdTextureOwner = "adapter-derived", ot(_, a.uvTransform);
|
|
2871
|
+
for (const g of d)
|
|
2872
|
+
g != null && g.userData.usdNormalConversionKey && r.add(g);
|
|
2873
|
+
for (const g of u)
|
|
2874
|
+
g.normalMap = _, g.normalScale.set(h, h), g.needsUpdate = !0;
|
|
2875
|
+
o.applied.push("gltf_material.normal_texture"), _ = null;
|
|
2876
|
+
} catch (g) {
|
|
2877
|
+
if (g instanceof Error && g.name === "AbortError") throw g;
|
|
2878
|
+
o.resources[o.resources.length - 1] = {
|
|
2879
|
+
path: a.path,
|
|
2880
|
+
status: "decode-failed"
|
|
2881
|
+
};
|
|
2882
|
+
} finally {
|
|
2883
|
+
_ == null || _.dispose();
|
|
2884
|
+
}
|
|
2885
|
+
return o;
|
|
2886
|
+
}
|
|
2887
|
+
async function Er(e, t, n, s, r, o) {
|
|
2888
|
+
const a = [], c = [], i = [], l = n.textures.find((O) => O.surfaceInput === "diffuse_reflection_color" && O.semantic === "color" && O.sourceChannel === "rgb"), h = n.textures.find((O) => O.surfaceInput === "geometry_opacity" && O.sourceChannel === "mono"), u = he(t, ["diffuse_reflection_color"]), d = he(t, ["diffuse_tint"]), p = N(t, ["diffuse_reflection_weight"]), f = N(t, ["specular_reflection_roughness"]), _ = N(t, ["metalness"]), w = N(t, ["specular_level"]), g = he(t, ["specular_reflection_color"]), b = Ce(t, "enable_opacity", !1), y = N(t, ["geometry_opacity_threshold", "opacity_threshold"]) ?? 0, S = N(t, ["coat_weight"]) ?? 0, v = N(t, ["coat_roughness"]), m = N(t, ["coat_ior"]), R = Ce(t, "enable_emission", !1) ? he(t, ["emission_color", "emissive_color"]) : null, A = N(t, ["emission_intensity", "emissive_intensity"]), P = ee(t, "geometry_opacity");
|
|
2889
|
+
ee(t, "diffuse_reflection_color") && !l && c.push("OmniPBRBase.diffuse_reflection_color.unresolved-texture"), ee(t, "geometry_opacity_threshold") ? c.push("OmniPBRBase.geometry_opacity_threshold.connection") : (!Number.isFinite(y) || y < 0 || y > 1) && c.push("OmniPBRBase.geometry_opacity_threshold.range"), b && P && !h && c.push("OmniPBRBase.geometry_opacity.unresolved-texture"), w !== null && w !== 0.5 && (ke(e, s), a.push("OmniPBRBase.specular_level.approximation"), r.diagnostics.approximations.push({
|
|
2890
|
+
code: "USD_VISUAL_OMNIPBRBASE_SPECULAR_APPROXIMATION",
|
|
2891
|
+
source: "usd-visual",
|
|
2892
|
+
message: `USD 材质 ${t.path} 的 OmniPBRBase specular_level 已按 Three.js specularIntensity 有界近似,不等同于原 MDL 介电反射瓣。`
|
|
2893
|
+
})), S > 0 && (ke(e, s), m !== null && c.push("OmniPBRBase.coat_ior"));
|
|
2894
|
+
for (const O of s.filter(W))
|
|
2895
|
+
f !== null && (O.roughness = Q(f)), _ !== null && (O.metalness = Q(_)), g && O instanceof K && O.specularColor.copy(g), w !== null && O instanceof K && (O.specularIntensity = Q(w)), O instanceof K && (O.clearcoat = Q(S), v !== null && (O.clearcoatRoughness = Q(v))), u && !l && O.color.copy(u), p !== null && (!l && u && O.color.multiplyScalar(Q(p)), p !== 1 && a.push("OmniPBRBase.diffuse_reflection_weight")), R ? (O.emissive.copy(R), O.emissiveIntensity = Math.max(0, A ?? 1)) : (O.emissive.setRGB(0, 0, 0), O.emissiveIntensity = 0), O.needsUpdate = !0;
|
|
2896
|
+
if (f !== null && a.push("OmniPBRBase.specular_reflection_roughness"), _ !== null && a.push("OmniPBRBase.metalness"), g && a.push("OmniPBRBase.specular_reflection_color"), S > 0 && a.push("OmniPBRBase.coat_weight"), v !== null && S > 0 && a.push("OmniPBRBase.coat_roughness"), R && a.push("OmniPBRBase.emission_color"), l) {
|
|
2897
|
+
const O = await rt(
|
|
2898
|
+
[n],
|
|
2899
|
+
s,
|
|
2900
|
+
/* @__PURE__ */ new Set(),
|
|
2901
|
+
r,
|
|
2902
|
+
o
|
|
2903
|
+
);
|
|
2904
|
+
if (a.push(...O.applied), c.push(...O.unsupported), i.push(...O.resources), d) {
|
|
2905
|
+
for (const V of s.filter(W)) V.color.multiply(d);
|
|
2906
|
+
a.push("OmniPBRBase.diffuse_tint");
|
|
2907
|
+
}
|
|
2908
|
+
if (p !== null)
|
|
2909
|
+
for (const V of s.filter(W))
|
|
2910
|
+
V.color.multiplyScalar(Q(p));
|
|
2911
|
+
} else if (u && (a.push("OmniPBRBase.diffuse_reflection_color.constant"), d)) {
|
|
2912
|
+
for (const O of s.filter(W)) O.color.multiply(d);
|
|
2913
|
+
a.push("OmniPBRBase.diffuse_tint");
|
|
2914
|
+
}
|
|
2915
|
+
if (b) {
|
|
2916
|
+
if (h) {
|
|
2917
|
+
const O = await Tr(
|
|
2918
|
+
n,
|
|
2919
|
+
h,
|
|
2920
|
+
s,
|
|
2921
|
+
y,
|
|
2922
|
+
r,
|
|
2923
|
+
o
|
|
2924
|
+
);
|
|
2925
|
+
a.push(...O.applied), c.push(...O.unsupported), i.push(...O.resources);
|
|
2926
|
+
} else if (!P) {
|
|
2927
|
+
const O = Q(N(t, ["geometry_opacity"]) ?? 1), V = y > 0 ? O >= y ? 1 : 0 : O;
|
|
2928
|
+
for (const q of s.filter(W))
|
|
2929
|
+
q.opacity = V, q.alphaTest = y, q.transparent = y === 0 && V < 1, q.depthWrite = !q.transparent, q instanceof K && (q.transmission = 0), q.needsUpdate = !0;
|
|
2930
|
+
a.push("OmniPBRBase.geometry_opacity.constant");
|
|
2931
|
+
}
|
|
2932
|
+
} else if (!Ce(t, "enable_opacity", !1))
|
|
2933
|
+
for (const O of s.filter(W))
|
|
2934
|
+
O.opacity = 1, O.transparent = !1, O.alphaTest = 0, O.depthWrite = !0, O.needsUpdate = !0;
|
|
2935
|
+
const C = ee(t, "geometry_normal");
|
|
2936
|
+
if (C) {
|
|
2937
|
+
const O = await Pn(
|
|
2938
|
+
e,
|
|
2939
|
+
t,
|
|
2940
|
+
C,
|
|
2941
|
+
s,
|
|
2942
|
+
r,
|
|
2943
|
+
o,
|
|
2944
|
+
"OmniPBRBase"
|
|
2945
|
+
);
|
|
2946
|
+
a.push(...O.applied), c.push(...O.unsupported), i.push(...O.resources);
|
|
2947
|
+
}
|
|
2948
|
+
const F = /* @__PURE__ */ new Set([
|
|
2949
|
+
"diffuse_reflection_color",
|
|
2950
|
+
"diffuse_tint",
|
|
2951
|
+
"diffuse_reflection_weight",
|
|
2952
|
+
"specular_reflection_roughness",
|
|
2953
|
+
"specular_reflection_color",
|
|
2954
|
+
"specular_level",
|
|
2955
|
+
"metalness",
|
|
2956
|
+
"enable_opacity",
|
|
2957
|
+
"geometry_opacity",
|
|
2958
|
+
"geometry_opacity_threshold",
|
|
2959
|
+
"opacity_threshold",
|
|
2960
|
+
"geometry_normal",
|
|
2961
|
+
"coat_weight",
|
|
2962
|
+
"coat_roughness",
|
|
2963
|
+
"coat_ior",
|
|
2964
|
+
"enable_coat",
|
|
2965
|
+
"enable_emission",
|
|
2966
|
+
"emission_color",
|
|
2967
|
+
"emissive_color",
|
|
2968
|
+
"emission_intensity",
|
|
2969
|
+
"emissive_intensity",
|
|
2970
|
+
"texture_scale",
|
|
2971
|
+
"texture_translate",
|
|
2972
|
+
"texture_rotate",
|
|
2973
|
+
"project_uvw",
|
|
2974
|
+
"uv_space_index"
|
|
2975
|
+
]), I = {
|
|
2976
|
+
enable_coat: !1,
|
|
2977
|
+
enable_emission: !1,
|
|
2978
|
+
emission_intensity: 0,
|
|
2979
|
+
emissive_intensity: 0
|
|
2980
|
+
};
|
|
2981
|
+
for (const O of Object.keys(t.inputs)) {
|
|
2982
|
+
if (!O.startsWith("inputs:")) continue;
|
|
2983
|
+
const V = O.slice(7).replace(/\.(?:resolvedConnect|connect)$/, "");
|
|
2984
|
+
F.has(V) || V in I && t.inputs[O] === I[V] || c.push(`OmniPBRBase.${V}`);
|
|
2985
|
+
}
|
|
2986
|
+
return Ce(t, "enable_coat", !1) && c.push("OmniPBRBase.enable_coat"), { applied: ie(a), unsupported: ie(c), resources: i };
|
|
2987
|
+
}
|
|
2988
|
+
async function Tr(e, t, n, s, r, o) {
|
|
2989
|
+
var S;
|
|
2990
|
+
const a = { applied: [], unsupported: [], resources: [] }, c = $r(t.monoSource);
|
|
2991
|
+
if (!c)
|
|
2992
|
+
return a.unsupported.push(`OmniPBRBase.geometry_opacity.mono_source=${t.monoSource ?? "unknown"}`), a;
|
|
2993
|
+
if (((S = t.sourceColorSpace) == null ? void 0 : S.toLowerCase()) !== "raw")
|
|
2994
|
+
return a.unsupported.push(`OmniPBRBase.geometry_opacity.color-space=${t.sourceColorSpace ?? "auto"}`), a;
|
|
2995
|
+
const i = n.filter(W);
|
|
2996
|
+
if (!i.length)
|
|
2997
|
+
return a.unsupported.push("OmniPBRBase.geometry_opacity.standard-material-required"), a;
|
|
2998
|
+
const l = i.map((v) => v.alphaMap);
|
|
2999
|
+
if (l.some((v) => (v == null ? void 0 : v.userData.usdTextureOwner) === "foreign" || v && !v.userData.usdCoverageConversionKey))
|
|
3000
|
+
return a.unsupported.push("OmniPBRBase.geometry_opacity.existing-map-owner-unknown"), a;
|
|
3001
|
+
const h = Jt(t.brightness, 1), u = Jt(t.contrast, 1), d = t.invert === !0, p = (d ? -1 : 1) * h * u, f = d ? 1 - 0.5 * h * (1 - u) : 0.5 * h * (1 - u), _ = t.wrapS === null ? te : Se(t.wrapS), w = t.wrapT === null ? te : Se(t.wrapT);
|
|
3002
|
+
if (_ === null || w === null)
|
|
3003
|
+
return a.unsupported.push("OmniPBRBase.geometry_opacity.unsupported-wrap"), a;
|
|
3004
|
+
const g = JSON.stringify([
|
|
3005
|
+
"usd-file-texture-mono-v1",
|
|
3006
|
+
e.materialPath,
|
|
3007
|
+
t.shaderPath,
|
|
3008
|
+
t.path,
|
|
3009
|
+
c,
|
|
3010
|
+
p,
|
|
3011
|
+
f,
|
|
3012
|
+
_,
|
|
3013
|
+
w,
|
|
3014
|
+
s
|
|
3015
|
+
]);
|
|
3016
|
+
if (l.every((v) => (v == null ? void 0 : v.userData.usdCoverageConversionKey) === g))
|
|
3017
|
+
return a.applied.push(`OmniPBRBase.geometry_opacity.mono.${c}`), a.resources.push({ path: t.path, status: "available" }), a;
|
|
3018
|
+
const b = await ce(t.path, r);
|
|
3019
|
+
if (a.resources.push(b.report), !b.url) return a;
|
|
3020
|
+
let y = null;
|
|
3021
|
+
try {
|
|
3022
|
+
y = await (r.createTexture ?? le)(b.url, oe);
|
|
3023
|
+
const v = Ae(y, c, p, f);
|
|
3024
|
+
v.wrapS = _, v.wrapT = w, v.channel = 0, v.userData.usdCoverageConversionKey = g, v.userData.usdTextureOwner = "adapter-derived";
|
|
3025
|
+
for (const m of l)
|
|
3026
|
+
m != null && m.userData.usdCoverageConversionKey && o.add(m);
|
|
3027
|
+
for (const m of i)
|
|
3028
|
+
m.alphaMap = v, m.opacity = 1, m.alphaTest = s, m.transparent = s === 0, m.depthWrite = s > 0, m instanceof K && (m.transmission = 0), m.needsUpdate = !0;
|
|
3029
|
+
a.applied.push(`OmniPBRBase.geometry_opacity.mono.${c}`), r.diagnostics.approximations.push({
|
|
3030
|
+
code: "USD_VISUAL_OMNIPBRBASE_FILE_TEXTURE_APPROXIMATION",
|
|
3031
|
+
source: "usd-visual",
|
|
3032
|
+
message: `USD 材质 ${e.materialPath} 的 core_definitions::file_texture.mono 已按 mono_source、brightness、contrast、invert 做 8 位通道重排;过滤边缘和阈值结果不保证与 MDL 渲染逐像素一致。`
|
|
3033
|
+
});
|
|
3034
|
+
} catch (v) {
|
|
3035
|
+
if (v instanceof Error && v.name === "AbortError") throw v;
|
|
3036
|
+
a.resources[a.resources.length - 1] = { path: t.path, status: "decode-failed" };
|
|
3037
|
+
} finally {
|
|
3038
|
+
y == null || y.dispose();
|
|
3039
|
+
}
|
|
3040
|
+
return a;
|
|
3041
|
+
}
|
|
3042
|
+
function $r(e) {
|
|
3043
|
+
return e === 0 ? "a" : e === 1 || e === null || e === void 0 ? "average" : e === 2 ? "luminance" : e === 3 ? "maximum" : null;
|
|
3044
|
+
}
|
|
3045
|
+
function Jt(e, t) {
|
|
3046
|
+
return typeof e == "number" && Number.isFinite(e) ? e : t;
|
|
3047
|
+
}
|
|
3048
|
+
async function Nr(e, t, n, s, r, o) {
|
|
3049
|
+
const a = [], c = [], i = [], l = Ce(t, "enable_specular_transmission", !1), h = Q(N(t, ["specular_transmission_weight"]) ?? 0), u = he(t, ["specular_transmission_color"]), d = he(t, ["diffuse_reflection_color"]), p = Q(N(t, ["diffuse_reflection_weight"]) ?? 1), f = N(t, ["specular_reflection_ior"]), _ = N(t, ["specular_reflection_roughness"]), w = N(t, ["specular_reflection_weight"]), g = he(t, ["specular_reflection_color"]), b = N(t, ["metalness"]), y = Q(N(t, ["coat_weight"]) ?? 0), S = N(t, ["coat_roughness"]), v = N(t, ["coat_ior"]), m = N(t, ["diffuse_reflection_roughness"]), x = Ce(t, "enable_thin_film", !1), R = Ce(t, "enable_diffuse_transmission", !1), A = N(t, ["subsurface_weight"]) ?? 0;
|
|
3050
|
+
ke(e, s);
|
|
3051
|
+
for (const I of s.filter(
|
|
3052
|
+
(O) => O instanceof K
|
|
3053
|
+
))
|
|
3054
|
+
I.metalness = 0, _ !== null && (I.roughness = Q(_)), b !== null && (I.metalness = Q(b)), f !== null && f > 0 && (I.ior = f), w !== null && (I.specularIntensity = Q(w)), g && I.specularColor.copy(g), y > 0 && (I.clearcoat = y, S !== null && (I.clearcoatRoughness = Q(S))), l && h > 0 ? (I.transmission = h, I.thickness = 0, I.opacity = 1, I.transparent = !1, I.depthWrite = !0, u && (I.color.copy(u), I.attenuationColor.copy(u), I.attenuationDistance = 1 / 0)) : (I.transmission = 0, d && I.color.copy(d).multiplyScalar(p)), I.needsUpdate = !0;
|
|
3055
|
+
l && a.push("OmniSurfaceBase.enable_specular_transmission"), h > 0 && a.push("OmniSurfaceBase.specular_transmission_weight"), u && l && (a.push(
|
|
3056
|
+
"OmniSurfaceBase.specular_transmission_color.surface-tint",
|
|
3057
|
+
"OmniSurfaceBase.specular_transmission_color.attenuation"
|
|
3058
|
+
), r.diagnostics.approximations.push({
|
|
3059
|
+
code: "USD_VISUAL_OMNISURFACE_TRANSMISSION_APPROXIMATION",
|
|
3060
|
+
source: "usd-visual",
|
|
3061
|
+
message: `USD 材质 ${t.path} 的 OmniSurfaceBase 透射颜色已映射为 Three.js 表面颜色与 attenuationColor;不推断壁厚、内部光程或体积吸收,不保证与 MDL 透射瓣等价。`
|
|
3062
|
+
})), p === 0 ? a.push("OmniSurfaceBase.diffuse_reflection_weight") : p !== 1 && (a.push("OmniSurfaceBase.diffuse_reflection_weight"), c.push("OmniSurfaceBase.diffuse_reflection_weight.partial")), f !== null && a.push("OmniSurfaceBase.specular_reflection_ior"), _ !== null && a.push("OmniSurfaceBase.specular_reflection_roughness"), w !== null && a.push("OmniSurfaceBase.specular_reflection_weight"), g && a.push("OmniSurfaceBase.specular_reflection_color"), b !== null && a.push("OmniSurfaceBase.metalness"), y > 0 && a.push("OmniSurfaceBase.coat_weight"), y > 0 && S !== null && a.push("OmniSurfaceBase.coat_roughness"), y > 0 && v !== null && c.push("OmniSurfaceBase.coat_ior"), m !== null && m !== 0 && c.push("OmniSurfaceBase.diffuse_reflection_roughness"), x && c.push("OmniSurfaceBase.enable_thin_film"), R && c.push("OmniSurfaceBase.enable_diffuse_transmission"), A > 0 && c.push("OmniSurfaceBase.subsurface_weight");
|
|
3063
|
+
const P = await rt(
|
|
3064
|
+
[n],
|
|
3065
|
+
s,
|
|
3066
|
+
/* @__PURE__ */ new Set(),
|
|
3067
|
+
r,
|
|
3068
|
+
o
|
|
3069
|
+
);
|
|
3070
|
+
a.push(...P.applied), c.push(...P.unsupported), i.push(...P.resources);
|
|
3071
|
+
const C = ee(t, "geometry_normal");
|
|
3072
|
+
if (C) {
|
|
3073
|
+
const I = await Pn(
|
|
3074
|
+
e,
|
|
3075
|
+
t,
|
|
3076
|
+
C,
|
|
3077
|
+
s,
|
|
3078
|
+
r,
|
|
3079
|
+
o
|
|
3080
|
+
);
|
|
3081
|
+
a.push(...I.applied), c.push(...I.unsupported), i.push(...I.resources);
|
|
3082
|
+
}
|
|
3083
|
+
const F = /* @__PURE__ */ new Set([
|
|
3084
|
+
"diffuse_reflection_weight",
|
|
3085
|
+
"diffuse_reflection_color",
|
|
3086
|
+
"diffuse_reflection_roughness",
|
|
3087
|
+
"metalness",
|
|
3088
|
+
"enable_specular_transmission",
|
|
3089
|
+
"specular_transmission_weight",
|
|
3090
|
+
"specular_transmission_color",
|
|
3091
|
+
"specular_transmission_dispersion_abbe",
|
|
3092
|
+
"specular_transmission_scatter_anisotropy",
|
|
3093
|
+
"specular_transmission_scattering_color",
|
|
3094
|
+
"specular_reflection_ior",
|
|
3095
|
+
"specular_reflection_roughness",
|
|
3096
|
+
"specular_reflection_weight",
|
|
3097
|
+
"specular_reflection_color",
|
|
3098
|
+
"coat_weight",
|
|
3099
|
+
"coat_roughness",
|
|
3100
|
+
"coat_ior",
|
|
3101
|
+
"enable_thin_film",
|
|
3102
|
+
"enable_diffuse_transmission",
|
|
3103
|
+
"subsurface_weight",
|
|
3104
|
+
"subsurface_scale",
|
|
3105
|
+
"subsurface_anisotropy",
|
|
3106
|
+
"subsurface_scattering_color",
|
|
3107
|
+
"subsurface_scattering_colors_preset",
|
|
3108
|
+
"subsurface_transmission_color",
|
|
3109
|
+
"geometry_normal"
|
|
3110
|
+
]);
|
|
3111
|
+
for (const I of Object.keys(t.inputs)) {
|
|
3112
|
+
if (!I.startsWith("inputs:")) continue;
|
|
3113
|
+
const O = I.slice(7).replace(/\.(?:resolvedConnect|connect)$/, "");
|
|
3114
|
+
F.has(O) || c.push(`OmniSurfaceBase.${O}`);
|
|
3115
|
+
}
|
|
3116
|
+
return { applied: ie(a), unsupported: ie(c), resources: i };
|
|
3117
|
+
}
|
|
3118
|
+
async function Pn(e, t, n, s, r, o, a = "OmniSurfaceBase") {
|
|
3119
|
+
var b, y, S, v;
|
|
3120
|
+
const c = { applied: [], unsupported: [], resources: [] }, i = (y = e.index.materialsByPath.get(
|
|
3121
|
+
pe((b = s[0]) == null ? void 0 : b.userData.usdMaterialPath) ?? ""
|
|
3122
|
+
)) == null ? void 0 : y.shaders.find((m) => m.path === n.path);
|
|
3123
|
+
if (!i)
|
|
3124
|
+
return c.unsupported.push(`${a}.geometry_normal.unresolved:${n.path}`), c;
|
|
3125
|
+
const l = pe(i.inputs["info:mdl:sourceAsset:subIdentifier"]) ?? i.id, h = (S = ae(i.inputs["info:mdl:sourceAsset"])) == null ? void 0 : S.replaceAll("\\", "/");
|
|
3126
|
+
if (!(/^(?:normalmap_texture|gltf_normal_texture_lookup)$/i.test(l ?? "") || l === null && ((v = h == null ? void 0 : h.split("/").at(-1)) == null ? void 0 : v.toLowerCase()) === "core_definitions.mdl"))
|
|
3127
|
+
return c.unsupported.push(`${a}.geometry_normal.${l ?? i.path}`), c;
|
|
3128
|
+
const d = ae(G(i, ["texture", "file"]));
|
|
3129
|
+
if (!d)
|
|
3130
|
+
return c.unsupported.push(`${a}.geometry_normal.missing-texture:${i.path}`), c;
|
|
3131
|
+
const p = s.filter(W);
|
|
3132
|
+
if (!p.length)
|
|
3133
|
+
return c.unsupported.push(`${a}.geometry_normal.standard-material-required`), c;
|
|
3134
|
+
const f = p.map((m) => m.normalMap);
|
|
3135
|
+
if (f.some((m) => m && m.userData.usdTextureOwner === "foreign"))
|
|
3136
|
+
return c.unsupported.push(`${a}.geometry_normal.existing-foreign-map`), c;
|
|
3137
|
+
const _ = JSON.stringify([
|
|
3138
|
+
"omnisurface-normal-v1",
|
|
3139
|
+
t.path,
|
|
3140
|
+
i.path,
|
|
3141
|
+
d
|
|
3142
|
+
]);
|
|
3143
|
+
if (f.every((m) => (m == null ? void 0 : m.userData.usdNormalConversionKey) === _))
|
|
3144
|
+
return c.applied.push(`${a}.geometry_normal`), c.resources.push({ path: d, status: "available" }), c;
|
|
3145
|
+
if (f.some((m) => m && !m.userData.usdNormalConversionKey))
|
|
3146
|
+
return c.unsupported.push(`${a}.geometry_normal.existing-map-owner-unknown`), c;
|
|
3147
|
+
const w = await ce(d, r);
|
|
3148
|
+
if (c.resources.push(w.report), !w.url) return c;
|
|
3149
|
+
let g = null;
|
|
3150
|
+
try {
|
|
3151
|
+
g = await (r.createTexture ?? le)(w.url, oe), g.colorSpace = oe, g.wrapS = te, g.wrapT = te, g.channel = 0, g.userData.usdNormalConversionKey = _, g.userData.usdTextureOwner = "adapter-derived";
|
|
3152
|
+
for (const m of f)
|
|
3153
|
+
m != null && m.userData.usdNormalConversionKey && o.add(m);
|
|
3154
|
+
for (const m of p)
|
|
3155
|
+
m.normalMap = g, m.normalScale.set(1, 1), m.needsUpdate = !0;
|
|
3156
|
+
c.applied.push(`${a}.geometry_normal`), g = null;
|
|
3157
|
+
} catch (m) {
|
|
3158
|
+
if (m instanceof Error && m.name === "AbortError") throw m;
|
|
3159
|
+
c.resources[c.resources.length - 1] = { path: d, status: "decode-failed" };
|
|
3160
|
+
} finally {
|
|
3161
|
+
g == null || g.dispose();
|
|
3162
|
+
}
|
|
3163
|
+
return c;
|
|
3164
|
+
}
|
|
3165
|
+
function On(e) {
|
|
3166
|
+
return Xe(e) ? "OmniPBR" : Ct(e) ? "OmniPBRBase" : xt(e) ? "OmniGlass" : Dt(e) ? "gltf_material" : Et(e) ? "OmniSurfaceBase" : e.id;
|
|
3167
|
+
}
|
|
3168
|
+
function Ue(e, t) {
|
|
3169
|
+
const n = Qt(e, "texture_scale", [1, 1]), s = Qt(e, "texture_translate", [0, 0]), r = N(e, ["texture_rotate"]) ?? 0, o = ge(e, ["project_uvw"], !1), a = N(e, ["uv_space_index"]) ?? 0, c = !o && a === 0 && n[0] === 1 && n[1] === 1 && s[0] === 0 && s[1] === 0 && r === 0;
|
|
3170
|
+
return c || t.add("OmniPBR.uvTransform"), c;
|
|
3171
|
+
}
|
|
3172
|
+
async function Br(e, t, n, s, r, o) {
|
|
3173
|
+
const a = () => {
|
|
3174
|
+
for (const p of ["ao_texture", "ao_texture_colorspace", "ao_to_diffuse"]) s.delete(`OmniPBR.${p}`);
|
|
3175
|
+
};
|
|
3176
|
+
if (ee(t, "ao_to_diffuse"))
|
|
3177
|
+
return s.add("OmniPBR.ao_to_diffuse.connection"), !1;
|
|
3178
|
+
const c = N(t, ["ao_to_diffuse"]) ?? 0;
|
|
3179
|
+
if (G(t, ["ao_to_diffuse"]) !== void 0 && N(t, ["ao_to_diffuse"]) === null || c < 0 || c > 1)
|
|
3180
|
+
return s.add("OmniPBR.ao_to_diffuse.range"), !1;
|
|
3181
|
+
if (c === 0)
|
|
3182
|
+
return a(), !1;
|
|
3183
|
+
if (ee(t, "enable_ORM_texture"))
|
|
3184
|
+
return s.add("OmniPBR.enable_ORM_texture.connection"), !1;
|
|
3185
|
+
const i = ge(t, ["enable_ORM_texture"], !1), l = i ? "ORM_texture" : "ao_texture";
|
|
3186
|
+
if (ee(t, l))
|
|
3187
|
+
return s.add(`OmniPBR.${l}.connection`), !1;
|
|
3188
|
+
const h = ae(G(t, [l]));
|
|
3189
|
+
if (!h)
|
|
3190
|
+
return a(), !1;
|
|
3191
|
+
if (G(t, [`${l}_colorspace`]) !== "raw")
|
|
3192
|
+
return s.add(`OmniPBR.${l}_colorspace`), !1;
|
|
3193
|
+
if (!Ue(t, s)) return !1;
|
|
3194
|
+
const u = await ce(h, o);
|
|
3195
|
+
if (r.push(u.report), !u.url) return !1;
|
|
3196
|
+
let d = null;
|
|
3197
|
+
try {
|
|
3198
|
+
d = await (o.createTexture ?? le)(u.url, oe);
|
|
3199
|
+
const p = Ae(d, i ? "r" : "grayscale");
|
|
3200
|
+
p.wrapS = te, p.wrapT = te, p.channel = 0;
|
|
3201
|
+
const f = e.filter(W).filter((_) => !_.aoMap);
|
|
3202
|
+
if (!f.length)
|
|
3203
|
+
return p.dispose(), s.add("OmniPBR.existing_aoMap"), !1;
|
|
3204
|
+
for (const _ of f)
|
|
3205
|
+
_.aoMap = p, _.aoMapIntensity = c, _.needsUpdate = !0;
|
|
3206
|
+
return a(), n.push(i ? "OmniPBR.ORM.r.aoMap" : "OmniPBR.ao_texture.aoMap"), o.diagnostics.approximations.push({ code: "USD_VISUAL_AO_LIGHTING_APPROXIMATION", source: "usd-visual", message: `USD 材质 AO 已映射为 Three.js 间接光遮蔽(${t.path});并非 OmniPBR 对漫反射贴图的等价调制。` }), !0;
|
|
3207
|
+
} catch (p) {
|
|
3208
|
+
if (p instanceof Error && p.name === "AbortError") throw p;
|
|
3209
|
+
return s.add(`OmniPBR.${l}.pixel-conversion`), !1;
|
|
3210
|
+
} finally {
|
|
3211
|
+
d == null || d.dispose();
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
function Lr(e, t) {
|
|
3215
|
+
const n = /* @__PURE__ */ new Set([
|
|
3216
|
+
"inputs:diffuse_color_constant",
|
|
3217
|
+
"inputs:diffuse_texture",
|
|
3218
|
+
"inputs:reflection_roughness_constant",
|
|
3219
|
+
"inputs:metallic_constant",
|
|
3220
|
+
"inputs:opacity_constant",
|
|
3221
|
+
"inputs:enable_opacity",
|
|
3222
|
+
"inputs:enable_emission",
|
|
3223
|
+
"inputs:emissive_color",
|
|
3224
|
+
"inputs:emissive_intensity",
|
|
3225
|
+
"inputs:texture_scale",
|
|
3226
|
+
"inputs:texture_translate",
|
|
3227
|
+
"inputs:texture_rotate",
|
|
3228
|
+
"inputs:project_uvw",
|
|
3229
|
+
"inputs:uv_space_index",
|
|
3230
|
+
"info:mdl:sourceAsset",
|
|
3231
|
+
"inputs:enable_ORM_texture",
|
|
3232
|
+
"inputs:ORM_texture",
|
|
3233
|
+
"inputs:metallic_texture_influence",
|
|
3234
|
+
"inputs:reflection_roughness_texture_influence",
|
|
3235
|
+
"inputs:ao_to_diffuse",
|
|
3236
|
+
"inputs:diffuse_tint",
|
|
3237
|
+
"inputs:normalmap_texture",
|
|
3238
|
+
"inputs:bump_factor",
|
|
3239
|
+
"inputs:flip_tangent_u",
|
|
3240
|
+
"inputs:flip_tangent_v",
|
|
3241
|
+
"inputs:reflectionroughness_texture",
|
|
3242
|
+
"inputs:metallic_texture",
|
|
3243
|
+
"inputs:opacity_texture"
|
|
3244
|
+
]);
|
|
3245
|
+
(N(e, ["specular_level"]) ?? 0.5) !== 0.5 && t.add("OmniPBR.specular_level"), n.add("inputs:specular_level");
|
|
3246
|
+
const s = /* @__PURE__ */ new Set(["inputs:opacity_mode", "inputs:opacity_threshold", "inputs:enable_opacity_texture"]);
|
|
3247
|
+
ge(e, ["enable_emission"], !1) && t.add("OmniPBR.emission_radiometric_equivalence");
|
|
3248
|
+
const r = {
|
|
3249
|
+
"inputs:albedo_desaturation": 0,
|
|
3250
|
+
"inputs:albedo_add": 0,
|
|
3251
|
+
"inputs:albedo_brightness": 1,
|
|
3252
|
+
"inputs:world_or_object": !1
|
|
3253
|
+
};
|
|
3254
|
+
for (const o of Object.keys(e.inputs))
|
|
3255
|
+
o in r && e.inputs[o] === r[o] || !n.has(o) && !s.has(o) && t.add(`OmniPBR.${o.replace(/^inputs:/, "")}`);
|
|
3256
|
+
}
|
|
3257
|
+
function kr(e, t, n) {
|
|
3258
|
+
let s = !1;
|
|
3259
|
+
const r = Xe(t), o = he(t, ["diffuseColor", "baseColor", "base_color", "diffuse_color_constant"]), a = N(t, ["roughness", "specularRoughness", "specular_roughness", "reflection_roughness_constant"]) ?? (r ? 0.5 : null), c = N(t, ["metallic", "metalness", "metallicFactor", "metallic_constant"]) ?? (r ? 0 : null), i = N(t, ["opacity_threshold"]) ?? 0, l = ge(t, ["enable_opacity"], !1) && i >= 0, h = N(t, ["opacity", "presence", "opacity_constant"]) ?? (r ? 1 : null), u = r ? l ? i > 0 ? h >= i ? 1 : 0 : h : 1 : h, d = ge(t, ["enable_emission"], !r), p = d ? he(t, ["emissiveColor", "emissionColor", "emission_color", "emissive_color"]) : null;
|
|
3260
|
+
for (const f of e)
|
|
3261
|
+
W(f) && (o && (f.color.copy(o), s = !0), a !== null && (f.roughness = Q(a), s = !0), c !== null && (f.metalness = Q(c), s = !0), u !== null && (f.opacity = Q(u), f.transparent = f.opacity < 1, f.depthWrite = f.opacity >= 1, s = !0), r && !d && (f.emissive.setRGB(0, 0, 0), f.emissiveIntensity = 0), p && (f.emissive.copy(p), r && (f.emissiveIntensity = Math.max(0, N(t, ["emissive_intensity"]) ?? 40)), s = !0), s && (f.needsUpdate = !0));
|
|
3262
|
+
return o && n.push("diffuseColor.constant"), a !== null && n.push("roughness.constant"), c !== null && n.push("metalness.constant"), u !== null && n.push("opacity.constant"), p && n.push("emissiveColor.constant"), s;
|
|
3263
|
+
}
|
|
3264
|
+
function Fr(e, t, n) {
|
|
3265
|
+
const s = /* @__PURE__ */ new Set(), r = (o) => {
|
|
3266
|
+
if (s.has(o.path)) return;
|
|
3267
|
+
s.add(o.path);
|
|
3268
|
+
const a = Ke(e, o);
|
|
3269
|
+
if (!a) {
|
|
3270
|
+
n.add(o.path);
|
|
3271
|
+
return;
|
|
3272
|
+
}
|
|
3273
|
+
if (!An(a)) {
|
|
3274
|
+
n.add(a.id ?? a.path);
|
|
3275
|
+
for (const [c, i] of Object.entries(a.inputs)) {
|
|
3276
|
+
if (!c.endsWith(".resolvedConnect") && !c.endsWith(".connect")) continue;
|
|
3277
|
+
const l = Re(i);
|
|
3278
|
+
l && r(l);
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
};
|
|
3282
|
+
for (const [o, a] of Object.entries(t.inputs)) {
|
|
3283
|
+
if (!o.endsWith(".resolvedConnect") && !o.endsWith(".connect") || /(?:diffuseColor|baseColor)/i.test(o)) continue;
|
|
3284
|
+
const c = Re(a);
|
|
3285
|
+
c && r(c);
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
async function ce(e, t) {
|
|
3289
|
+
const n = Gr(e, t.packageTextureURLs);
|
|
3290
|
+
if (n) return { report: { path: e, status: "available" }, url: n };
|
|
3291
|
+
if (t.isTextureAllowed && !t.isTextureAllowed(e)) return { report: { path: e, status: "unresolved" }, url: null };
|
|
3292
|
+
const s = Qe(t.entryDirectory ? `${t.entryDirectory}/${e}` : e);
|
|
3293
|
+
let r = t.files.find(e, t.entryDirectory ?? "") ?? t.files.find(s);
|
|
3294
|
+
if (!r)
|
|
3295
|
+
try {
|
|
3296
|
+
await t.files.ensure(s), r = t.files.find(s) ?? t.files.find(e, t.entryDirectory ?? "");
|
|
3297
|
+
} catch (o) {
|
|
3298
|
+
const a = o == null ? void 0 : o.code;
|
|
3299
|
+
if (o instanceof Error && o.name === "AbortError" || a === "E_ASSET_AUTH") throw o;
|
|
3300
|
+
const c = a === "E_ASSET_RESOURCE_NOT_FOUND" || /\((404|410)\)/.test(String(o));
|
|
3301
|
+
return { report: { path: e, status: c ? "missing" : "unresolved" }, url: null };
|
|
3302
|
+
}
|
|
3303
|
+
return r ? tr.has(Xr(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 };
|
|
3304
|
+
}
|
|
3305
|
+
function Gr(e, t) {
|
|
3306
|
+
if (!(t != null && t.size)) return null;
|
|
3307
|
+
const n = /\[([^\]]+)\]/.exec(e), s = Qe((n == null ? void 0 : n[1]) ?? e), r = t.get(s);
|
|
3308
|
+
if (r) return r;
|
|
3309
|
+
const o = [...t].find(([l]) => l.toLowerCase() === s.toLowerCase());
|
|
3310
|
+
if (o) return o[1];
|
|
3311
|
+
const a = [...t].filter(([l]) => {
|
|
3312
|
+
const h = Qe(l);
|
|
3313
|
+
return h.endsWith(`/${s}`) || s.endsWith(`/${h}`);
|
|
3314
|
+
});
|
|
3315
|
+
if (a.length === 1) return a[0][1];
|
|
3316
|
+
const c = s.split("/").pop();
|
|
3317
|
+
if (!c) return null;
|
|
3318
|
+
const i = [...t].filter(([l]) => Qe(l).split("/").pop() === c);
|
|
3319
|
+
return i.length === 1 ? i[0][1] : null;
|
|
3320
|
+
}
|
|
3321
|
+
function Ve(e, t, n, s, r, o, a) {
|
|
3322
|
+
a === "augmented" && e.approximations.push({
|
|
3323
|
+
code: "USD_VISUAL_MATERIAL_AUGMENTED",
|
|
3324
|
+
message: `USD 材质 ${t}(${On(n) ?? "renderer-specific shader"})已通过视觉适配层映射资产明确提供的输入:${ie(s).join(", ")}。这是有限范围的材质映射,不保证与原渲染器完全等价;原始 Loader 诊断保留在 visualAdaptation 报告中。`,
|
|
3325
|
+
source: "usd-visual"
|
|
3326
|
+
}), Rn(e, t, o);
|
|
3327
|
+
const c = {
|
|
3328
|
+
"OmniGlass.solid_volume_absorption": "实体玻璃目前仅渲染表面透射:缺少可靠的内部光程,未实现体积吸收。未推断或生成壁厚",
|
|
3329
|
+
"OmniGlass.glass_color.volume": "源玻璃颜色用于体积吸收,当前未还原该体积颜色;未用表面染色替代",
|
|
3330
|
+
"OmniGlass.depth": "源 depth 是体积吸收缩放,不能直接当作 Three.js 壁厚或衰减距离;此输入尚未映射",
|
|
3331
|
+
"OmniGlass.fractional_coverage_transmission_compositing": "覆盖率与透射参数已映射,但其组合使用实时合成近似,不保证与 MDL 渲染等价",
|
|
3332
|
+
"OmniGlass.tint_reflection_coupling": "薄壁玻璃颜色已作表面近似,其反射与透射颜色响应不保证与 MDL 等价"
|
|
3333
|
+
};
|
|
3334
|
+
for (const i of r) e.droppedFeatures.push({
|
|
3335
|
+
code: "USD_VISUAL_SHADER_NODE_UNSUPPORTED",
|
|
3336
|
+
message: c[i] ? `USD 材质 ${t}:${c[i]}。` : `USD 材质功能或节点 ${i} 尚未完成浏览器适配(${t})。未生成替代内容。`,
|
|
3337
|
+
source: "usd-visual"
|
|
3338
|
+
});
|
|
3339
|
+
}
|
|
3340
|
+
function Rn(e, t, n) {
|
|
3341
|
+
for (const s of n) {
|
|
3342
|
+
const r = (o, a, c) => {
|
|
3343
|
+
o.some((i) => i.code === a && i.message === c) || o.push({ code: a, message: c, source: "usd-visual" });
|
|
3344
|
+
};
|
|
3345
|
+
s.status === "missing" && r(
|
|
3346
|
+
e.warnings,
|
|
3347
|
+
"USD_VISUAL_RESOURCE_MISSING",
|
|
3348
|
+
`USD 材质资源缺失:${s.path}(${t})。未生成替代内容。`
|
|
3349
|
+
), s.status === "unsupported-format" && r(
|
|
3350
|
+
e.droppedFeatures,
|
|
3351
|
+
"USD_VISUAL_TEXTURE_FORMAT_UNSUPPORTED",
|
|
3352
|
+
`USD 材质纹理格式无法由浏览器直接消费:${s.path}(${t})。需要离线确定性转码。`
|
|
3353
|
+
), s.status === "decode-failed" && r(
|
|
3354
|
+
e.warnings,
|
|
3355
|
+
"USD_VISUAL_TEXTURE_DECODE_FAILED",
|
|
3356
|
+
`USD 纹理解码失败:${s.path}(${t})。保留原材质。`
|
|
3357
|
+
), s.status === "unresolved" && r(
|
|
3358
|
+
e.warnings,
|
|
3359
|
+
"USD_VISUAL_RESOURCE_UNRESOLVED",
|
|
3360
|
+
`无法确认 USD 材质资源是否可用:${s.path}(${t})。未生成替代内容。`
|
|
3361
|
+
);
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
function Vr(e) {
|
|
3365
|
+
const t = G(e, ["filename", "file"]), n = ae(t);
|
|
3366
|
+
return n ? { shader: e, path: n } : null;
|
|
3367
|
+
}
|
|
3368
|
+
function zr(e) {
|
|
3369
|
+
return e.shaders.some((t) => Object.entries(t.inputs).some(
|
|
3370
|
+
([n, s]) => n.startsWith("inputs:") && /(?:texture|filename|file)/i.test(n) && !!ae(s)
|
|
3371
|
+
));
|
|
3372
|
+
}
|
|
3373
|
+
function ee(e, t) {
|
|
3374
|
+
return Re(e.inputs[`inputs:${t}.resolvedConnect`] ?? e.inputs[`inputs:${t}.connect`]);
|
|
3375
|
+
}
|
|
3376
|
+
function Pe(e, t, n) {
|
|
3377
|
+
for (const s of n) {
|
|
3378
|
+
const r = t.inputs[`inputs:${s}.resolvedConnect`] ?? t.inputs[`inputs:${s}.connect`], o = Re(r);
|
|
3379
|
+
if (o) {
|
|
3380
|
+
const c = In(e, o.path);
|
|
3381
|
+
if (!c) return { value: void 0, connection: o, materialInput: null };
|
|
3382
|
+
const i = e.inputs[`inputs:${c}.resolvedConnect`] ?? e.inputs[`inputs:${c}.connect`], l = Re(i);
|
|
3383
|
+
return l ? { value: void 0, connection: l, materialInput: c } : {
|
|
3384
|
+
value: e.inputs[`inputs:${c}`],
|
|
3385
|
+
connection: null,
|
|
3386
|
+
materialInput: c
|
|
3387
|
+
};
|
|
3388
|
+
}
|
|
3389
|
+
const a = t.inputs[`inputs:${s}`];
|
|
3390
|
+
if (a !== void 0) return { value: a, connection: null, materialInput: null };
|
|
3391
|
+
}
|
|
3392
|
+
return { value: void 0, connection: null, materialInput: null };
|
|
3393
|
+
}
|
|
3394
|
+
function In(e, t) {
|
|
3395
|
+
const n = /^(.*)\.inputs:([^/.]+)$/.exec(t);
|
|
3396
|
+
return (n == null ? void 0 : n[1]) === e.path && n[2] ? n[2] : null;
|
|
3397
|
+
}
|
|
3398
|
+
function ze(e, t, n) {
|
|
3399
|
+
const s = Pe(e, t, n).value;
|
|
3400
|
+
return typeof s == "number" && Number.isFinite(s) ? s : null;
|
|
3401
|
+
}
|
|
3402
|
+
function jr(e, t, n) {
|
|
3403
|
+
const s = Pe(e, t, n).value;
|
|
3404
|
+
return typeof s == "boolean" ? s : null;
|
|
3405
|
+
}
|
|
3406
|
+
function Zt(e, t, n) {
|
|
3407
|
+
const s = Pe(e, t, n).value;
|
|
3408
|
+
if (!Array.isArray(s) || s.length < 3) return null;
|
|
3409
|
+
const r = s.slice(0, 3);
|
|
3410
|
+
return r.every((o) => typeof o == "number" && Number.isFinite(o)) ? new nt(r[0], r[1], r[2]) : null;
|
|
3411
|
+
}
|
|
3412
|
+
function Re(e) {
|
|
3413
|
+
const t = Array.isArray(e) ? e[0] : e;
|
|
3414
|
+
if (typeof t != "string") return null;
|
|
3415
|
+
const n = /^(.*?)(?:\.outputs:([^/]+))?$/.exec(t);
|
|
3416
|
+
return n ? { path: n[1], outputName: n[2] ?? null } : null;
|
|
3417
|
+
}
|
|
3418
|
+
function Ke(e, t) {
|
|
3419
|
+
return e.shaders.find((n) => n.path === t.path) ?? null;
|
|
3420
|
+
}
|
|
3421
|
+
function An(e) {
|
|
3422
|
+
return e.id === "PxrTexture";
|
|
3423
|
+
}
|
|
3424
|
+
function W(e) {
|
|
3425
|
+
return e instanceof Ot || e instanceof K;
|
|
3426
|
+
}
|
|
3427
|
+
async function le(e, t) {
|
|
3428
|
+
const n = await new rn().loadAsync(e);
|
|
3429
|
+
return n.colorSpace = t, n.flipY = !0, n;
|
|
3430
|
+
}
|
|
3431
|
+
function he(e, t) {
|
|
3432
|
+
const n = G(e, t);
|
|
3433
|
+
if (!Array.isArray(n) || n.length < 3) return null;
|
|
3434
|
+
const s = n.slice(0, 3);
|
|
3435
|
+
return s.every((r) => typeof r == "number" && Number.isFinite(r)) ? new nt(s[0], s[1], s[2]) : null;
|
|
3436
|
+
}
|
|
3437
|
+
function ge(e, t, n) {
|
|
3438
|
+
const s = G(e, t);
|
|
3439
|
+
return typeof s == "boolean" ? s : n;
|
|
3440
|
+
}
|
|
3441
|
+
function Ce(e, t, n) {
|
|
3442
|
+
const s = G(e, [t]);
|
|
3443
|
+
if (typeof s == "boolean") return s;
|
|
3444
|
+
if (typeof s == "number" && Number.isFinite(s)) return s !== 0;
|
|
3445
|
+
if (typeof s == "string") {
|
|
3446
|
+
if (s.toLowerCase() === "true") return !0;
|
|
3447
|
+
if (s.toLowerCase() === "false") return !1;
|
|
3448
|
+
}
|
|
3449
|
+
return n;
|
|
3450
|
+
}
|
|
3451
|
+
function Wr(e) {
|
|
3452
|
+
return e === 1 || e === "mask" ? "mask" : e === 2 || e === "blend" ? "blend" : "opaque";
|
|
3453
|
+
}
|
|
3454
|
+
function Qt(e, t, n) {
|
|
3455
|
+
const s = G(e, [t]);
|
|
3456
|
+
return Array.isArray(s) && s.length >= 2 && s.slice(0, 2).every((r) => typeof r == "number" && Number.isFinite(r)) ? [s[0], s[1]] : n;
|
|
3457
|
+
}
|
|
3458
|
+
function N(e, t) {
|
|
3459
|
+
const n = G(e, t), s = typeof n == "number" ? n : Number.NaN;
|
|
3460
|
+
return Number.isFinite(s) ? s : null;
|
|
3461
|
+
}
|
|
3462
|
+
function G(e, t) {
|
|
3463
|
+
for (const n of t) {
|
|
3464
|
+
if (ee(e, n)) return;
|
|
3465
|
+
const s = e.inputs[`inputs:${n}`];
|
|
3466
|
+
if (s !== void 0) return s;
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
function ae(e) {
|
|
3470
|
+
if (typeof e == "string") return e;
|
|
3471
|
+
if (!e || typeof e != "object") return null;
|
|
3472
|
+
for (const t of ["path", "resolvedPath", "url"]) {
|
|
3473
|
+
const n = e[t];
|
|
3474
|
+
if (typeof n == "string" && n) return n;
|
|
3475
|
+
}
|
|
3476
|
+
return null;
|
|
3477
|
+
}
|
|
3478
|
+
function St(e, t) {
|
|
3479
|
+
return e.data.elements.some((n) => n.material === t && n.geometry.displayColor !== null);
|
|
3480
|
+
}
|
|
3481
|
+
function lt(e, t) {
|
|
3482
|
+
return St(e, t) ? "authored-fallback" : "default-fallback";
|
|
3483
|
+
}
|
|
3484
|
+
function Xr(e) {
|
|
3485
|
+
var t, n;
|
|
3486
|
+
return ((n = (t = e.split(/[?#]/, 1)[0]) == null ? void 0 : t.split(".").pop()) == null ? void 0 : n.toLowerCase()) ?? "";
|
|
3487
|
+
}
|
|
3488
|
+
function Q(e) {
|
|
3489
|
+
return Math.min(1, Math.max(0, e));
|
|
3490
|
+
}
|
|
3491
|
+
function Ze(e) {
|
|
3492
|
+
return Array.isArray(e) ? e.filter(vt) : [];
|
|
3493
|
+
}
|
|
3494
|
+
function pe(e) {
|
|
3495
|
+
return typeof e == "string" && e ? e : null;
|
|
3496
|
+
}
|
|
3497
|
+
function vt(e) {
|
|
3498
|
+
return typeof e == "string" && e.length > 0;
|
|
3499
|
+
}
|
|
3500
|
+
function ie(e) {
|
|
3501
|
+
return [...new Set(e)];
|
|
3502
|
+
}
|
|
3503
|
+
const en = /* @__PURE__ */ new Map();
|
|
3504
|
+
function Kr(e) {
|
|
3505
|
+
const t = e ?? "";
|
|
3506
|
+
let n = en.get(t);
|
|
3507
|
+
return n || (n = gs(Rs(e)), en.set(t, n)), n;
|
|
3508
|
+
}
|
|
3509
|
+
async function mo(e, t, n) {
|
|
3510
|
+
var x;
|
|
3511
|
+
const s = n.hasLocalFiles(), r = e.entryPath ?? e.filename ?? "asset.usd", o = s ? r : await ao(e, r), a = s ? n.getBlob(r) : await io(e), c = r.split("/").pop() || "asset.usd", i = r.split("/").slice(0, -1).join("/"), l = t.options.usdExternalReferenceMode ?? "package", h = new URL(o, "file:///"), u = Xn(), d = /* @__PURE__ */ new Set(), p = (R) => {
|
|
3512
|
+
d.has(R) || (d.add(R), u.warnings.push({ code: "USD_EXTERNAL_REFERENCE_SKIPPED", message: `资产包模式已跳过包外 USD 资源:${R}。包内内容继续加载;完整模式可尝试加载该资源。`, source: "usd-resources" }));
|
|
3513
|
+
}, f = (R) => {
|
|
3514
|
+
if (n.find(R, r) || l === "complete") return !0;
|
|
3515
|
+
const A = !s && Rt(new URL(R, h), h);
|
|
3516
|
+
return A || p(R), A;
|
|
3517
|
+
}, _ = /* @__PURE__ */ new Set(), w = (R, A) => {
|
|
3518
|
+
if (_.has(R)) return;
|
|
3519
|
+
_.add(R);
|
|
3520
|
+
const P = ts(A);
|
|
3521
|
+
u.warnings.push({
|
|
3522
|
+
code: P === "invalid" ? "USD_VISUAL_RESOURCE_INVALID" : P === "unavailable" ? "USD_VISUAL_RESOURCE_UNAVAILABLE" : "USD_VISUAL_RESOURCE_MISSING",
|
|
3523
|
+
message: `USD 视觉资源不可用:${R}`,
|
|
3524
|
+
source: "usd-resources"
|
|
3525
|
+
});
|
|
3526
|
+
}, { parseAsync: g } = await Kr(t.options.openUsdBaseUrl), b = Hr(t.requestRender);
|
|
3527
|
+
let y = null, S = null, v = null, m = null;
|
|
3528
|
+
try {
|
|
3529
|
+
if (y = await g(a, {
|
|
3530
|
+
sourcePath: o,
|
|
3531
|
+
fileName: c,
|
|
3532
|
+
files: s ? n.asSourceRecord(i, !0) : void 0,
|
|
3533
|
+
// The viewer default is the package boundary, not the source kind:
|
|
3534
|
+
// package-local layers/textures are discovered for both File and URL
|
|
3535
|
+
// inputs, while package-external references are filtered before reading.
|
|
3536
|
+
// Complete mode discovers all references. If the host supplied a
|
|
3537
|
+
// resolver, files.ensure() remains the only path to external bytes and
|
|
3538
|
+
// therefore the resolver remains authoritative; without one it falls
|
|
3539
|
+
// through to the source base URL and direct browser fetch.
|
|
3540
|
+
autoResolveAssets: !0,
|
|
3541
|
+
maxConcurrency: 4,
|
|
3542
|
+
externalReferenceMode: l,
|
|
3543
|
+
onReferenceSkipped: p,
|
|
3544
|
+
onResourceFailed: w,
|
|
3545
|
+
isTextureAllowed: (M) => f(M) && !!n.find(M, r),
|
|
3546
|
+
resolveBytes: async (M, k) => {
|
|
3547
|
+
const D = n.find(k, r);
|
|
3548
|
+
return D ? n.bytes(D) : (await n.ensure(k), n.bytes(k));
|
|
3549
|
+
},
|
|
3550
|
+
textureResolver: (M) => {
|
|
3551
|
+
for (const k of [M.resolvedPath, M.path, M.url]) {
|
|
3552
|
+
if (!k) continue;
|
|
3553
|
+
const D = n.objectUrlIfPresent(k, i);
|
|
3554
|
+
if (D) return D;
|
|
3555
|
+
}
|
|
3556
|
+
return null;
|
|
3557
|
+
},
|
|
3558
|
+
textureLoader: b
|
|
3559
|
+
}), t.signal.aborted) throw dt();
|
|
3560
|
+
const R = oo(y);
|
|
3561
|
+
y.scene.scale.multiplyScalar(R.metersPerUnit), y.data.stage.upAxis.toUpperCase() === "Y" && y.scene.quaternion.setFromAxisAngle(new j(1, 0, 0), Math.PI / 2), y.scene.updateMatrixWorld(!0);
|
|
3562
|
+
const A = y.data.physics.rigidBodies.filter((M) => M.enabled), P = Cn(y, A.map((M) => M.path));
|
|
3563
|
+
ss(y);
|
|
3564
|
+
const C = await nr(y, {
|
|
3565
|
+
files: n,
|
|
3566
|
+
entryDirectory: i,
|
|
3567
|
+
sourcePath: o,
|
|
3568
|
+
isLocalPackage: s,
|
|
3569
|
+
diagnostics: u,
|
|
3570
|
+
isTextureAllowed: t.format === "usdz" ? void 0 : f,
|
|
3571
|
+
packageTextureURLs: y.resources.usdzTextureURLs
|
|
3572
|
+
});
|
|
3573
|
+
if (t.signal.aborted) throw dt();
|
|
3574
|
+
const F = Yr(u);
|
|
3575
|
+
A.some((M) => M.startsAsleep === !0) && u.droppedFeatures.push({ code: "E_USD_STARTS_ASLEEP", message: "USD startsAsleep 无法在 MuJoCo 初始化阶段保证完全等价,已按正常初始状态加载。", source: "usd-physics" });
|
|
3576
|
+
const I = jn({
|
|
3577
|
+
id: o,
|
|
3578
|
+
name: o.split("/").pop() ?? o,
|
|
3579
|
+
source: { format: "usd", uri: o },
|
|
3580
|
+
links: A.map((M) => ({ id: M.path, name: M.name, visuals: [], collisions: [] })),
|
|
3581
|
+
joints: P.flatMap((M) => M.body0 && M.body1 ? [{
|
|
3582
|
+
id: M.path,
|
|
3583
|
+
type: M.jointType,
|
|
3584
|
+
parent: M.body0,
|
|
3585
|
+
child: M.body1,
|
|
3586
|
+
origin: { position: M.localPos1.map((k) => k * R.metersPerUnit), rotationRpy: [0, 0, 0] },
|
|
3587
|
+
axis: Dn(M.axis).applyQuaternion(Ne(M.localRot1 ?? [1, 0, 0, 0])).toArray(),
|
|
3588
|
+
...Number.isFinite(M.lowerLimit) && Number.isFinite(M.upperLimit) ? { limits: {
|
|
3589
|
+
lower: M.lowerLimit * (M.jointType === "revolute" ? Math.PI / 180 : R.metersPerUnit),
|
|
3590
|
+
upper: M.upperLimit * (M.jointType === "revolute" ? Math.PI / 180 : R.metersPerUnit)
|
|
3591
|
+
} } : {}
|
|
3592
|
+
}] : []),
|
|
3593
|
+
diagnostics: u,
|
|
3594
|
+
extension: { rigidBodyCount: A.length, jointCount: P.length, visualAdaptation: C }
|
|
3595
|
+
});
|
|
3596
|
+
if (A.length === 0) {
|
|
3597
|
+
tn(y);
|
|
3598
|
+
const M = y.scene, k = y;
|
|
3599
|
+
let D;
|
|
3600
|
+
const L = ft(k) ? () => (D ?? (D = nn(k, u)), D) : void 0, E = qr(M, t.requestRender);
|
|
3601
|
+
return v = { root: M, sync() {
|
|
3602
|
+
}, dispose() {
|
|
3603
|
+
E == null || E.dispose(), k.dispose();
|
|
3604
|
+
} }, y = null, pt(I, v, !1, () => D == null ? void 0 : D.dispose(), void 0, void 0, void 0, F, E, L);
|
|
3605
|
+
}
|
|
3606
|
+
let O;
|
|
3607
|
+
try {
|
|
3608
|
+
O = no(y, A.map((k) => k.path), R, P), (x = O.massOverrides) != null && x.length && u.approximations.push({ code: "USD_INFERRED_INERTIA", message: "保留显式总质量;惯量按碰撞几何的密度分布推导并同比缩放,重叠体积会重复计入。", source: "usd-physics" });
|
|
3609
|
+
const { MujocoRuntime: M } = await import("./mujoco-runtime-DTxVmIzc.js");
|
|
3610
|
+
S = new M(), await S.initialize(O, t.options.mujocoBaseUrl), t.signal.throwIfAborted();
|
|
3611
|
+
} catch (M) {
|
|
3612
|
+
const k = Wn(M, t.signal, "usd-physics");
|
|
3613
|
+
S == null || S.dispose(), S = null, u.droppedFeatures.push(k), tn(y);
|
|
3614
|
+
const D = y.scene, L = y;
|
|
3615
|
+
let E;
|
|
3616
|
+
const B = ft(L) ? () => (E ?? (E = nn(L, u)), E) : void 0;
|
|
3617
|
+
return v = { root: D, sync() {
|
|
3618
|
+
}, dispose() {
|
|
3619
|
+
L.dispose();
|
|
3620
|
+
} }, y = null, pt(I, v, !1, () => E == null ? void 0 : E.dispose(), void 0, k, void 0, F, void 0, B);
|
|
3621
|
+
}
|
|
3622
|
+
const V = m = Qr(y, A.map((M) => M.path), u);
|
|
3623
|
+
if (t.signal.aborted) throw dt();
|
|
3624
|
+
v = new kt(S, V), m = null;
|
|
3625
|
+
const q = y, U = S, X = v;
|
|
3626
|
+
let T;
|
|
3627
|
+
const J = A.map((M) => M.path), se = ft(q) ? () => {
|
|
3628
|
+
if (!T) {
|
|
3629
|
+
const M = xn(q, J, u);
|
|
3630
|
+
T = M ? new kt(U, M) : void 0;
|
|
3631
|
+
}
|
|
3632
|
+
return T;
|
|
3633
|
+
} : void 0;
|
|
3634
|
+
return y = null, S = null, v = null, pt(I, X, !0, () => {
|
|
3635
|
+
T == null || T.dispose(), U.dispose(), q.dispose();
|
|
3636
|
+
}, U, void 0, void 0, F, void 0, se);
|
|
3637
|
+
} catch (R) {
|
|
3638
|
+
throw m && un(m.root), v == null || v.dispose(), S == null || S.dispose(), y == null || y.dispose(), R;
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
function tn(e) {
|
|
3642
|
+
for (const t of e.index.boneHostsBySkeletonPath.values())
|
|
3643
|
+
t.matrix.copy(e.scene.matrixWorld).invert();
|
|
3644
|
+
e.scene.updateMatrixWorld(!0);
|
|
3645
|
+
}
|
|
3646
|
+
function Hr(e) {
|
|
3647
|
+
const n = [];
|
|
3648
|
+
let s = !1;
|
|
3649
|
+
const r = () => {
|
|
3650
|
+
if (s || n.length === 0) return;
|
|
3651
|
+
s = !0;
|
|
3652
|
+
const a = () => {
|
|
3653
|
+
var i;
|
|
3654
|
+
s = !1;
|
|
3655
|
+
let c = 0;
|
|
3656
|
+
for (; n.length; ) {
|
|
3657
|
+
const l = n[0];
|
|
3658
|
+
if (c > 0 && c + l.pixels > 4194304 || ((i = n.shift()) == null || i.apply(), c += l.pixels, c >= 4194304)) break;
|
|
3659
|
+
}
|
|
3660
|
+
n.length && r();
|
|
3661
|
+
};
|
|
3662
|
+
typeof requestAnimationFrame == "function" ? requestAnimationFrame(a) : setTimeout(a, 16);
|
|
3663
|
+
};
|
|
3664
|
+
class o extends rn {
|
|
3665
|
+
load(c, i, l, h) {
|
|
3666
|
+
const u = new Pt();
|
|
3667
|
+
return setTimeout(() => {
|
|
3668
|
+
super.load(c, (d) => {
|
|
3669
|
+
var _, w;
|
|
3670
|
+
const p = ((_ = d.image) == null ? void 0 : _.width) || 0, f = ((w = d.image) == null ? void 0 : w.height) || 0;
|
|
3671
|
+
n.push({ pixels: Math.max(1, p * f), apply: () => {
|
|
3672
|
+
u.image = d.image, u.source.needsUpdate = !0, u.needsUpdate = !0, d.dispose(), i == null || i(u), e();
|
|
3673
|
+
} }), r();
|
|
3674
|
+
}, l, h);
|
|
3675
|
+
}, 0), u;
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
return new o();
|
|
3679
|
+
}
|
|
3680
|
+
function qr(e, t) {
|
|
3681
|
+
const n = e.animations ?? [];
|
|
3682
|
+
if (n.length === 0) return;
|
|
3683
|
+
const s = new Vn(e), r = n.map((o) => s.clipAction(o));
|
|
3684
|
+
for (const o of r) o.reset().setLoop(zn, 1 / 0).play();
|
|
3685
|
+
return s.setTime(0), {
|
|
3686
|
+
step(o) {
|
|
3687
|
+
return o > 0 ? (s.update(o), t(), !0) : !1;
|
|
3688
|
+
},
|
|
3689
|
+
reset() {
|
|
3690
|
+
s.setTime(0), t();
|
|
3691
|
+
},
|
|
3692
|
+
dispose() {
|
|
3693
|
+
for (const o of r) o.stop();
|
|
3694
|
+
s.stopAllAction(), s.uncacheRoot(e);
|
|
3695
|
+
}
|
|
3696
|
+
};
|
|
3697
|
+
}
|
|
3698
|
+
function Yr(e) {
|
|
3699
|
+
const t = [
|
|
3700
|
+
"USD_VISUAL_RESOURCE_MISSING",
|
|
3701
|
+
"USD_VISUAL_RESOURCE_INVALID",
|
|
3702
|
+
"USD_VISUAL_RESOURCE_UNAVAILABLE",
|
|
3703
|
+
"USD_VISUAL_TEXTURE_FORMAT_UNSUPPORTED",
|
|
3704
|
+
"USD_VISUAL_RESOURCE_UNRESOLVED",
|
|
3705
|
+
"USD_VISUAL_TEXTURE_DECODE_FAILED",
|
|
3706
|
+
"USD_VISUAL_MATERIAL_IR_ISSUE",
|
|
3707
|
+
"USD_VISUAL_SHADER_NODE_UNSUPPORTED",
|
|
3708
|
+
"USD_VISUAL_LOADER_DIAGNOSTIC",
|
|
3709
|
+
"USD_VISUAL_TOPOLOGY_UNSUPPORTED",
|
|
3710
|
+
"USD_EXTERNAL_REFERENCE_SKIPPED"
|
|
3711
|
+
], n = [...e.warnings, ...e.droppedFeatures, ...e.approximations];
|
|
3712
|
+
for (const s of t) {
|
|
3713
|
+
const r = n.find((o) => o.code === s);
|
|
3714
|
+
if (r) return r;
|
|
3715
|
+
}
|
|
3716
|
+
}
|
|
3717
|
+
function pt(e, t, n, s, r, o, a, c, i, l) {
|
|
3718
|
+
let h = !1;
|
|
3719
|
+
return {
|
|
3720
|
+
asset: e,
|
|
3721
|
+
binding: t,
|
|
3722
|
+
hasPhysics: n,
|
|
3723
|
+
hasAnimation: !!i,
|
|
3724
|
+
runtime: r,
|
|
3725
|
+
fallback: o,
|
|
3726
|
+
visualWarning: c,
|
|
3727
|
+
collision: a,
|
|
3728
|
+
createCollision: l,
|
|
3729
|
+
step(u) {
|
|
3730
|
+
if (i) return i.step(u);
|
|
3731
|
+
if (!r) return !1;
|
|
3732
|
+
const d = r.step(u);
|
|
3733
|
+
return d && t.sync(), d;
|
|
3734
|
+
},
|
|
3735
|
+
reset() {
|
|
3736
|
+
if (i) {
|
|
3737
|
+
i.reset();
|
|
3738
|
+
return;
|
|
3739
|
+
}
|
|
3740
|
+
r == null || r.reset(), t.sync();
|
|
3741
|
+
},
|
|
3742
|
+
dispose() {
|
|
3743
|
+
h || (h = !0, t.dispose(), s());
|
|
3744
|
+
}
|
|
3745
|
+
};
|
|
3746
|
+
}
|
|
3747
|
+
const Jr = /* @__PURE__ */ new Set([
|
|
3748
|
+
"E_USD_PHYSICS_UNSUPPORTED",
|
|
3749
|
+
"E_USD_UNBAKED_BODY_SCALE",
|
|
3750
|
+
"E_USD_INVALID_JOINT_REFERENCE",
|
|
3751
|
+
"E_USD_UNSUPPORTED_JOINT",
|
|
3752
|
+
"E_USD_MULTIPLE_PARENTS",
|
|
3753
|
+
"E_USD_JOINT_CYCLE",
|
|
3754
|
+
"E_USD_UNSUPPORTED_DRIVE",
|
|
3755
|
+
"E_USD_INVALID_MASS",
|
|
3756
|
+
"E_USD_PARTIAL_INERTIA",
|
|
3757
|
+
"E_USD_MISSING_COLLISION_GEOMETRY",
|
|
3758
|
+
"E_USD_UNREACHABLE_BODIES",
|
|
3759
|
+
"E_USD_MULTIPLE_PHYSICS_SCENES",
|
|
3760
|
+
"E_USD_NONUNIFORM_RADIAL_SCALE",
|
|
3761
|
+
"E_USD_UNSUPPORTED_GEOMETRY",
|
|
3762
|
+
"E_USD_CONSTRAINED_INITIAL_VELOCITY",
|
|
3763
|
+
"E_USD_UNSUPPORTED_APPROXIMATION"
|
|
3764
|
+
]);
|
|
3765
|
+
function _o(e) {
|
|
3766
|
+
const t = Zr(e);
|
|
3767
|
+
return t !== null && Jr.has(t);
|
|
3768
|
+
}
|
|
3769
|
+
function Zr(e) {
|
|
3770
|
+
if (!e || typeof e != "object" || !("code" in e)) return null;
|
|
3771
|
+
const t = e.code;
|
|
3772
|
+
return typeof t == "string" ? t : null;
|
|
3773
|
+
}
|
|
3774
|
+
function Qr(e, t, n) {
|
|
3775
|
+
e.scene.updateMatrixWorld(!0);
|
|
3776
|
+
const s = new je();
|
|
3777
|
+
s.name = "USD simulation";
|
|
3778
|
+
const r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
|
|
3779
|
+
for (const f of t) {
|
|
3780
|
+
const _ = e.index.objectsByPath.get(f);
|
|
3781
|
+
if (!_) throw Y(`USD rigid body node is missing: ${f}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
3782
|
+
const w = new je();
|
|
3783
|
+
w.name = f, s.add(w), r.set(f, w);
|
|
3784
|
+
const g = new j(), b = new de();
|
|
3785
|
+
_.matrixWorld.decompose(g, b, new j()), o.set(f, new Oe().compose(g, b, new j(1, 1, 1)));
|
|
3786
|
+
}
|
|
3787
|
+
const a = eo(e, t, n), c = [], i = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), u = (f, _) => {
|
|
3788
|
+
var S;
|
|
3789
|
+
const w = f.skeleton, g = w.bones.map((v) => v.uuid).join("|");
|
|
3790
|
+
let b = h.get(g), y;
|
|
3791
|
+
if (b)
|
|
3792
|
+
y = w.bones.map((v) => l.get(v.uuid));
|
|
3793
|
+
else {
|
|
3794
|
+
b = new je(), b.name = `${f.name || "USD"}_BoneHost`, b.matrixAutoUpdate = !1;
|
|
3795
|
+
const v = (S = w.bones[0]) == null ? void 0 : S.parent;
|
|
3796
|
+
b.matrix.copy(_).multiply((v == null ? void 0 : v.matrixWorld) ?? new Oe()), s.add(b), h.set(g, b), y = w.bones.map((m) => {
|
|
3797
|
+
const x = m.clone(!1);
|
|
3798
|
+
return x.matrix.copy(m.matrix), x.matrixAutoUpdate = !1, l.set(m.uuid, x), x;
|
|
3799
|
+
});
|
|
3800
|
+
for (let m = 0; m < y.length; m++) {
|
|
3801
|
+
const x = w.bones[m].parent, R = w.bones.indexOf(x);
|
|
3802
|
+
(R >= 0 ? y[R] : b).add(y[m]);
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
return new Gn(y, w.boneInverses.map((v) => v.clone()));
|
|
3806
|
+
};
|
|
3807
|
+
e.scene.traverse((f) => {
|
|
3808
|
+
var y;
|
|
3809
|
+
if (!(f instanceof me) || f.userData.usdPurposeExcluded) return;
|
|
3810
|
+
let _ = f, w, g, b = !0;
|
|
3811
|
+
for (; _; ) {
|
|
3812
|
+
b && (b = _.visible);
|
|
3813
|
+
const S = (y = _.userData.usd) == null ? void 0 : y.path;
|
|
3814
|
+
!g && S && (g = S), !w && S && r.has(S) && (w = S), _ = _.parent;
|
|
3815
|
+
}
|
|
3816
|
+
!w && g && (w = a.get(Mn(g))), b && c.push([f, w]);
|
|
3817
|
+
});
|
|
3818
|
+
for (const [f, _] of c) {
|
|
3819
|
+
const w = _ ? o.get(_).clone().invert() : new Oe(), g = f instanceof Ye ? new Ye(f.geometry.clone(), Array.isArray(f.material) ? f.material.map((b) => b.clone()) : f.material.clone()) : f.clone(!1);
|
|
3820
|
+
g.geometry = f.geometry.clone(), g.material = Array.isArray(f.material) ? f.material.map((b) => b.clone()) : f.material.clone(), g instanceof Ye && f instanceof Ye && (g.bindMode = f.bindMode, g.bindMatrix.copy(f.bindMatrix), g.bindMatrixInverse.copy(f.bindMatrixInverse), g.bind(u(f, w), g.bindMatrix), g.frustumCulled = !1), g.matrix.copy(w).multiply(f.matrixWorld), g.matrix.decompose(g.position, g.quaternion, g.scale), (_ ? r.get(_) : s).add(g), i.set(f.uuid, g);
|
|
3821
|
+
}
|
|
3822
|
+
const p = (e.scene.animations ?? []).map((f) => {
|
|
3823
|
+
const _ = f.clone();
|
|
3824
|
+
return _.tracks = _.tracks.map((w) => {
|
|
3825
|
+
const g = w.name.split(".", 1)[0], b = i.get(g) ?? l.get(g);
|
|
3826
|
+
return b && (w.name = `${b.uuid}${w.name.slice(g.length)}`), w;
|
|
3827
|
+
}), _;
|
|
3828
|
+
});
|
|
3829
|
+
return { root: s, bindings: r, expectedLinkCount: r.size, animations: p };
|
|
3830
|
+
}
|
|
3831
|
+
function eo(e, t, n) {
|
|
3832
|
+
var i, l;
|
|
3833
|
+
const s = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), o = e.stage, a = e.pxr;
|
|
3834
|
+
if (!o || !((i = a == null ? void 0 : a.Sdf) != null && i.Path) || !((l = e.data.view) != null && l.prims)) return s;
|
|
3835
|
+
const c = new Set(e.data.view.prims.map((h) => h.path));
|
|
3836
|
+
for (const h of t) {
|
|
3837
|
+
const u = `${h}/Visual/`;
|
|
3838
|
+
for (const d of c) {
|
|
3839
|
+
if (!d.startsWith(u)) continue;
|
|
3840
|
+
const p = o.GetPrimAtPath(new a.Sdf.Path(d));
|
|
3841
|
+
try {
|
|
3842
|
+
const f = p.GetMetadata("references"), _ = typeof f == "string" ? f : f == null ? void 0 : f.string;
|
|
3843
|
+
if (_ == null) {
|
|
3844
|
+
n == null || n.warnings.push({ code: "USD_VISUAL_REFERENCE_MISSING", message: `刚体视觉节点缺少 reference:${d}`, source: "usd-visual-binding" });
|
|
3845
|
+
continue;
|
|
3846
|
+
}
|
|
3847
|
+
const w = to(_);
|
|
3848
|
+
if (!w) {
|
|
3849
|
+
n == null || n.warnings.push({ code: "USD_VISUAL_REFERENCE_UNRESOLVED", message: `无法解析视觉引用元数据:${d}`, source: "usd-visual-binding" });
|
|
3850
|
+
continue;
|
|
3851
|
+
}
|
|
3852
|
+
if (!w.primPath) continue;
|
|
3853
|
+
const g = Mn(w.primPath), b = r.get(g);
|
|
3854
|
+
if (b && b.owner !== h)
|
|
3855
|
+
throw Y(`USD visual reference maps to multiple rigid bodies: ${w.primPath} -> ${b.owner}, ${h}`, "E_USD_VISUAL_REFERENCE_AMBIGUOUS");
|
|
3856
|
+
r.set(g, { owner: h, target: w.primPath }), s.set(g, h);
|
|
3857
|
+
} finally {
|
|
3858
|
+
p.delete();
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
return s;
|
|
3863
|
+
}
|
|
3864
|
+
function to(e) {
|
|
3865
|
+
var n, s;
|
|
3866
|
+
const t = e.match(/SdfReference\(([^,]*),\s*(?:(\/[^,\)]+),\s*)?SdfLayerOffset/);
|
|
3867
|
+
return t ? { identifier: ((n = t[1]) == null ? void 0 : n.trim()) ?? "", primPath: ((s = t[2]) == null ? void 0 : s.trim()) ?? null } : null;
|
|
3868
|
+
}
|
|
3869
|
+
function Mn(e) {
|
|
3870
|
+
const t = e.replaceAll("\\", "/");
|
|
3871
|
+
for (const n of ["/Geometry/", "/Visual/"]) {
|
|
3872
|
+
const s = t.indexOf(n);
|
|
3873
|
+
if (s >= 0) return t.slice(s + n.length);
|
|
3874
|
+
}
|
|
3875
|
+
return t;
|
|
3876
|
+
}
|
|
3877
|
+
function ft(e) {
|
|
3878
|
+
return e.data.physics.colliders.some((t) => t.enabled && e.index.objectsByPath.has(t.path));
|
|
3879
|
+
}
|
|
3880
|
+
function xn(e, t, n) {
|
|
3881
|
+
e.scene.updateMatrixWorld(!0);
|
|
3882
|
+
const s = new je();
|
|
3883
|
+
s.name = "USD authored collisions";
|
|
3884
|
+
const r = Bt(), o = Lt(), a = Bt(Ft), c = Lt(Ft), i = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
|
|
3885
|
+
for (const u of t) {
|
|
3886
|
+
const d = e.index.objectsByPath.get(u);
|
|
3887
|
+
if (!d) continue;
|
|
3888
|
+
const p = new j(), f = new de();
|
|
3889
|
+
d.matrixWorld.decompose(p, f, new j()), l.set(u, new Oe().compose(p, f, new j(1, 1, 1)));
|
|
3890
|
+
const _ = new je();
|
|
3891
|
+
_.name = u, _.position.copy(p), _.quaternion.copy(f), i.set(u, _), s.add(_);
|
|
3892
|
+
}
|
|
3893
|
+
let h = 0;
|
|
3894
|
+
for (const u of e.data.physics.colliders) {
|
|
3895
|
+
if (!u.enabled) continue;
|
|
3896
|
+
const d = e.index.objectsByPath.get(u.path);
|
|
3897
|
+
if (!d) continue;
|
|
3898
|
+
const p = u.bodyPath && i.has(u.bodyPath) ? u.bodyPath : null, f = p ? i.get(p) : s, _ = p ? l.get(p) : new Oe(), w = [];
|
|
3899
|
+
if (d.traverse((v) => {
|
|
3900
|
+
v instanceof me && w.push(v);
|
|
3901
|
+
}), w.length === 0) continue;
|
|
3902
|
+
const g = String(u.typeName ?? d.type).toLowerCase(), b = g.includes("mesh") ? u.approximation ?? "none" : null;
|
|
3903
|
+
if (b && !["none", "convexHull", "boundingSphere", "boundingCube"].includes(b)) {
|
|
3904
|
+
n == null || n.droppedFeatures.push({
|
|
3905
|
+
code: "E_USD_COLLISION_DEBUG_APPROXIMATION_UNAVAILABLE",
|
|
3906
|
+
message: `USD collider ${u.path} 使用 ${b},最终求解器代理无法从 OpenUSD 唯一还原;已用橙黄色显示作者提供的 collision source mesh 近似预览。`,
|
|
3907
|
+
source: "usd-collision-debug"
|
|
3908
|
+
});
|
|
3909
|
+
const v = _.clone().invert();
|
|
3910
|
+
for (const m of w) {
|
|
3911
|
+
const x = Ge(
|
|
3912
|
+
m.geometry,
|
|
3913
|
+
a,
|
|
3914
|
+
"feature",
|
|
3915
|
+
c
|
|
3916
|
+
);
|
|
3917
|
+
x.name = `Collision approximation:${u.path}`, x.matrixAutoUpdate = !1, x.matrix.copy(v).multiply(m.matrixWorld), x.userData.usdColliderPath = u.path, x.userData.usdColliderApproximation = b, x.userData.usdCollisionDebugSource = "authored-collision-mesh", f.add(x), h += 1;
|
|
3918
|
+
}
|
|
3919
|
+
continue;
|
|
3920
|
+
}
|
|
3921
|
+
if (g.includes("mesh") && b !== "none") {
|
|
3922
|
+
const v = [], m = _.clone().invert();
|
|
3923
|
+
for (const x of w) {
|
|
3924
|
+
const R = m.clone().multiply(x.matrixWorld), A = x.geometry.getAttribute("position");
|
|
3925
|
+
for (let P = 0; P < A.count; P += 1) v.push(new j().fromBufferAttribute(A, P).applyMatrix4(R));
|
|
3926
|
+
}
|
|
3927
|
+
if (v.length >= 4 && b === "convexHull") {
|
|
3928
|
+
const x = new Kn(v), R = Ge(x, r, "mesh", o);
|
|
3929
|
+
x.dispose(), R.name = `Collision:${u.path}`, R.userData.usdColliderPath = u.path, R.userData.usdColliderApproximation = b, f.add(R), h += 1;
|
|
3930
|
+
} else if (v.length > 0 && b === "boundingSphere") {
|
|
3931
|
+
const R = new tt().setFromPoints(v).getBoundingSphere(new Ln()), A = new kn(R.radius, 24, 16);
|
|
3932
|
+
A.translate(R.center.x, R.center.y, R.center.z);
|
|
3933
|
+
const P = Ge(A, r, "feature", o);
|
|
3934
|
+
A.dispose(), P.name = `Collision:${u.path}`, P.userData.usdColliderPath = u.path, P.userData.usdColliderApproximation = b, f.add(P), h += 1;
|
|
3935
|
+
} else if (v.length > 0 && b === "boundingCube") {
|
|
3936
|
+
const x = new tt().setFromPoints(v), R = x.getSize(new j()), A = x.getCenter(new j()), P = new Fn(R.x, R.y, R.z);
|
|
3937
|
+
P.translate(A.x, A.y, A.z);
|
|
3938
|
+
const C = Ge(P, r, "feature", o);
|
|
3939
|
+
P.dispose(), C.name = `Collision:${u.path}`, C.userData.usdColliderPath = u.path, C.userData.usdColliderApproximation = b, f.add(C), h += 1;
|
|
3940
|
+
}
|
|
3941
|
+
continue;
|
|
3942
|
+
}
|
|
3943
|
+
const S = g.includes("mesh") ? "mesh" : "feature";
|
|
3944
|
+
for (const v of w) {
|
|
3945
|
+
const m = Ge(v.geometry, r, S, o);
|
|
3946
|
+
m.name = `Collision:${u.path}`, m.matrixAutoUpdate = !1, m.matrix.copy(_).invert().multiply(v.matrixWorld), m.userData.usdColliderPath = u.path, b && (m.userData.usdColliderApproximation = b), f.add(m), h += 1;
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3949
|
+
if (h === 0) {
|
|
3950
|
+
r.dispose(), o.dispose(), a.dispose(), c.dispose();
|
|
3951
|
+
return;
|
|
3952
|
+
}
|
|
3953
|
+
return { root: s, bindings: i, expectedLinkCount: i.size };
|
|
3954
|
+
}
|
|
3955
|
+
function nn(e, t) {
|
|
3956
|
+
const n = xn(e, [], t);
|
|
3957
|
+
if (n)
|
|
3958
|
+
return n.root.visible = !1, { root: n.root, sync() {
|
|
3959
|
+
}, dispose() {
|
|
3960
|
+
n.root.removeFromParent(), un(n.root);
|
|
3961
|
+
} };
|
|
3962
|
+
}
|
|
3963
|
+
function Cn(e, t) {
|
|
3964
|
+
e.scene.updateMatrixWorld(!0);
|
|
3965
|
+
const n = new Set(t);
|
|
3966
|
+
return e.data.joints.filter((s) => s.enabled).map((s) => {
|
|
3967
|
+
const r = { ...s };
|
|
3968
|
+
for (const o of [0, 1]) {
|
|
3969
|
+
const a = o === 0 ? "body0" : "body1", c = o === 0 ? "localPos0" : "localPos1", i = o === 0 ? "localRot0" : "localRot1", l = s[a];
|
|
3970
|
+
if (!l) continue;
|
|
3971
|
+
let h = l;
|
|
3972
|
+
for (; h && !e.index.rigidBodiesByPath.has(h); )
|
|
3973
|
+
h = h.slice(0, h.lastIndexOf("/"));
|
|
3974
|
+
if (h && !n.has(h))
|
|
3975
|
+
throw Y(`USD joint references an unknown or disabled rigid body: ${s.path} (${l})`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
3976
|
+
const u = e.index.objectsByPath.get(l), d = h ? e.index.objectsByPath.get(h) : e.scene;
|
|
3977
|
+
if (!u || !d)
|
|
3978
|
+
throw Y(`USD joint target node is missing: ${s.path} (${l})`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
3979
|
+
if (h === l) continue;
|
|
3980
|
+
const p = d.matrixWorld.clone().invert().multiply(u.matrixWorld), f = new j(), _ = new de(), w = new j();
|
|
3981
|
+
p.decompose(f, _, w);
|
|
3982
|
+
const g = new Oe().compose(f, _, new j(1, 1, 1));
|
|
3983
|
+
if (p.elements.some((y, S) => Math.abs(y - g.elements[S]) > 1e-5))
|
|
3984
|
+
throw Y(`USD joint target has unsupported scale or shear: ${s.path} (${l})`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
3985
|
+
r[a] = h || null, r[c] = new j(...s[c]).applyMatrix4(p).toArray();
|
|
3986
|
+
const b = _.multiply(Ne(s[i] ?? [1, 0, 0, 0])).normalize();
|
|
3987
|
+
r[i] = [b.w, b.x, b.y, b.z];
|
|
3988
|
+
}
|
|
3989
|
+
return r;
|
|
3990
|
+
});
|
|
3991
|
+
}
|
|
3992
|
+
function no(e, t, n, s = Cn(e, t)) {
|
|
3993
|
+
e.scene.updateMatrixWorld(!0);
|
|
3994
|
+
const r = [], o = [], a = [], c = [], i = [], l = [], h = [], { metersPerUnit: u, kilogramsPerUnit: d } = n, p = new Map(t.map((P) => {
|
|
3995
|
+
const C = e.index.rigidBodiesByPath.get(P);
|
|
3996
|
+
if (!C) throw Y(`USD rigid body metadata is missing: ${P}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
3997
|
+
return [P, C];
|
|
3998
|
+
})), f = /* @__PURE__ */ new Map();
|
|
3999
|
+
for (const P of p.keys()) {
|
|
4000
|
+
const C = e.index.objectsByPath.get(P);
|
|
4001
|
+
if (!C) throw Y(`USD rigid body node is missing: ${P}`, "E_USD_PHYSICS_UNSUPPORTED");
|
|
4002
|
+
const F = new j(), I = new de(), O = new j();
|
|
4003
|
+
if (C.matrixWorld.decompose(F, I, O), O.clone().divideScalar(u).toArray().some((q) => Math.abs(Math.abs(q) - 1) > 1e-5))
|
|
4004
|
+
throw Y(`USD rigid body has unbaked scale: ${P}`, "E_USD_UNBAKED_BODY_SCALE");
|
|
4005
|
+
f.set(P, new Oe().compose(F, I, new j(1, 1, 1)));
|
|
4006
|
+
}
|
|
4007
|
+
const _ = /* @__PURE__ */ new Map();
|
|
4008
|
+
for (const P of s) {
|
|
4009
|
+
if (!P.body1 || !p.has(P.body1) || P.body0 && !p.has(P.body0))
|
|
4010
|
+
throw Y(`USD joint references an unknown rigid body: ${P.path}`, "E_USD_INVALID_JOINT_REFERENCE");
|
|
4011
|
+
if (!["fixed", "revolute", "prismatic"].includes(P.jointType))
|
|
4012
|
+
throw Y(`Unsupported USD joint type ${P.jointType}: ${P.path}`, "E_USD_UNSUPPORTED_JOINT");
|
|
4013
|
+
if (_.has(P.body1)) throw Y(`USD rigid body has multiple parent joints: ${P.body1}`, "E_USD_MULTIPLE_PARENTS");
|
|
4014
|
+
_.set(P.body1, P), P.body0 && P.collisionEnabled !== !0 && a.push(`<exclude body1="${$e(P.body0)}" body2="${$e(P.body1)}"/>`);
|
|
4015
|
+
}
|
|
4016
|
+
let w = 0;
|
|
4017
|
+
const g = /* @__PURE__ */ new Set(), b = (P, C = new Oe()) => {
|
|
4018
|
+
var M, k, D, L, E;
|
|
4019
|
+
if (g.has(P)) throw Y(`USD joint graph contains a cycle at ${P}`, "E_USD_JOINT_CYCLE");
|
|
4020
|
+
g.add(P);
|
|
4021
|
+
const F = p.get(P), I = f.get(P), O = C.clone().invert().multiply(I), V = new j(), q = new de();
|
|
4022
|
+
O.decompose(V, q, new j());
|
|
4023
|
+
const U = _.get(P), X = [`<body name="${$e(P)}" pos="${fe(V.toArray())}" quat="${Be(q)}">`];
|
|
4024
|
+
if (!U && !F.kinematicEnabled && X.push("<freejoint/>"), U && [...F.velocity ?? [], ...F.angularVelocity ?? []].some((B) => B !== 0))
|
|
4025
|
+
throw Y(`Constrained USD initial velocity cannot be projected reliably: ${P}`, "E_USD_CONSTRAINED_INITIAL_VELOCITY");
|
|
4026
|
+
if (!U && !F.kinematicEnabled) {
|
|
4027
|
+
const B = new j(...F.velocity ?? [0, 0, 0]).multiplyScalar(u).applyQuaternion(e.scene.quaternion), $ = new j(...F.angularVelocity ?? [0, 0, 0]).multiplyScalar(Math.PI / 180).applyQuaternion(e.scene.quaternion).applyQuaternion(new de().setFromRotationMatrix(I).invert());
|
|
4028
|
+
h.push({ body: P, velocity: [...B.toArray(), ...$.toArray()] });
|
|
4029
|
+
}
|
|
4030
|
+
if (U && U.jointType !== "fixed") {
|
|
4031
|
+
const B = U.jointType === "revolute" ? "hinge" : "slide", $ = Dn(U.axis).applyQuaternion(Ne(U.localRot1 ?? [1, 0, 0, 0])), H = B === "hinge" ? Math.PI / 180 : u, ne = U.body0 ? C : e.scene.matrixWorld.clone();
|
|
4032
|
+
if (!U.body0) {
|
|
4033
|
+
const _e = new j(), Te = new de();
|
|
4034
|
+
ne.decompose(_e, Te, new j()), ne.compose(_e, Te, new j(1, 1, 1));
|
|
4035
|
+
}
|
|
4036
|
+
const Z = new de().setFromRotationMatrix(ne), z = new de().setFromRotationMatrix(I), ue = Z.clone().multiply(Ne(U.localRot0 ?? [1, 0, 0, 0])).invert().multiply(z).multiply(Ne(U.localRot1 ?? [1, 0, 0, 0]));
|
|
4037
|
+
let re = 0;
|
|
4038
|
+
if (B === "hinge") {
|
|
4039
|
+
const _e = U.axis === "Y" ? ue.y : U.axis === "Z" ? ue.z : ue.x;
|
|
4040
|
+
re = 2 * Math.atan2(_e, ue.w), re = Math.atan2(Math.sin(re), Math.cos(re));
|
|
4041
|
+
} else {
|
|
4042
|
+
const _e = new j(...U.localPos0).multiplyScalar(u).applyMatrix4(ne);
|
|
4043
|
+
re = new j(...U.localPos1).multiplyScalar(u).applyMatrix4(I).sub(_e).dot($.clone().applyQuaternion(z));
|
|
4044
|
+
}
|
|
4045
|
+
const Ee = Number.isFinite(U.lowerLimit) && Number.isFinite(U.upperLimit) && Math.abs(U.lowerLimit) < 1e20 && Math.abs(U.upperLimit) < 1e20, En = Ee && U.lowerLimit < U.upperLimit, He = d * (B === "slide" ? u : u * u), at = et(e, U.path, `physxJointAxis:${B === "slide" ? "linear" : "angular"}:dynamicFrictionEffort`), Tn = typeof at == "number" && Number.isFinite(at) ? at * He : 0;
|
|
4046
|
+
X.push(`<joint name="${$e(U.path)}" type="${B}" pos="${fe(U.localPos1.map((_e) => _e * u))}" axis="${fe($.toArray())}" ref="${re}" ${En ? `range="${U.lowerLimit * H} ${U.upperLimit * H}"` : 'limited="false"'} frictionloss="${Tn}" armature="0.00001"/>`), Ee && U.lowerLimit === U.upperLimit && o.push(`<joint joint1="${$e(U.path)}" polycoef="${U.lowerLimit * H - re} 0 0 0 0"/>`);
|
|
4047
|
+
const ye = U.drive;
|
|
4048
|
+
if (ye && ((ye.stiffness ?? 0) !== 0 || (ye.damping ?? 0) !== 0)) {
|
|
4049
|
+
if (ye.type === "acceleration") throw Y(`Unsupported USD acceleration drive: ${U.path}`, "E_USD_UNSUPPORTED_DRIVE");
|
|
4050
|
+
const _e = (ye.stiffness ?? 0) * He / H, Te = (ye.damping ?? 0) * He / H, qe = ye.maxForce == null ? null : ye.maxForce * He;
|
|
4051
|
+
i.push(`<general joint="${$e(U.path)}" gainprm="1" biastype="affine" biasprm="0 ${-_e} ${-Te}" ${qe != null && Number.isFinite(qe) ? `forcelimited="true" forcerange="${-qe} ${qe}"` : ""}/>`), l.push(_e * (ye.targetPosition ?? 0) * H + Te * (ye.targetVelocity ?? 0) * H);
|
|
4052
|
+
}
|
|
4053
|
+
}
|
|
4054
|
+
const T = F.mass;
|
|
4055
|
+
if ((T == null ? void 0 : T.mass) != null && (!Number.isFinite(T.mass) || T.mass < 0)) throw Y(`USD rigid body mass must be finite and non-negative: ${P}`, "E_USD_INVALID_MASS");
|
|
4056
|
+
let J = !1;
|
|
4057
|
+
if ((T == null ? void 0 : T.mass) != null && T.mass > 0 && ((M = T.centerOfMass) == null ? void 0 : M.length) === 3 && T.centerOfMass.every(Number.isFinite) && ((k = T.diagonalInertia) == null ? void 0 : k.length) === 3 && T.diagonalInertia.every((B) => Number.isFinite(B) && B > 0) && ((D = T.principalAxes) == null ? void 0 : D.length) === 4 && T.principalAxes.every(Number.isFinite))
|
|
4058
|
+
J = !0, X.push(`<inertial mass="${T.mass * d}" pos="${fe(T.centerOfMass.map((B) => B * u))}" quat="${Be(Ne(T.principalAxes))}" diaginertia="${fe(T.diagonalInertia.map((B) => B * d * u * u))}"/>`);
|
|
4059
|
+
else {
|
|
4060
|
+
if ((L = T == null ? void 0 : T.diagonalInertia) != null && L.some((B) => B > 0))
|
|
4061
|
+
throw Y(`USD rigid body has incomplete explicit inertia: ${P}`, "E_USD_PARTIAL_INERTIA");
|
|
4062
|
+
if ((T == null ? void 0 : T.mass) != null && T.mass > 0) {
|
|
4063
|
+
if ((E = T.centerOfMass) != null && E.every(Number.isFinite) && T.centerOfMass.some((B) => B !== 0)) throw Y(`Custom center of mass requires explicit inertia: ${P}`, "E_USD_PARTIAL_INERTIA");
|
|
4064
|
+
c.push({ body: P, mass: T.mass * d });
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
4067
|
+
const se = e.data.physics.colliders.filter((B) => B.enabled && B.bodyPath === P);
|
|
4068
|
+
if (!se.length && !J) throw Y(`USD rigid body has no authored collision geometry: ${P}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
4069
|
+
for (const B of se) {
|
|
4070
|
+
const $ = e.data.physics.materials.find((ue) => ue.path === B.material), H = (T == null ? void 0 : T.density) != null && T.density > 0 ? T.density : $ == null ? void 0 : $.density, ne = H != null && H > 0 ? H * d / u ** 3 : 1e3, Z = ($ == null ? void 0 : $.dynamicFriction) ?? 0.4, z = `density="${ne}" group="3" contype="1" conaffinity="1" friction="${Z} 0.01 0.0002"`;
|
|
4071
|
+
X.push(sn(e, B, P, I, w++, r, z));
|
|
4072
|
+
}
|
|
4073
|
+
for (const [B, $] of _) $.body0 === P && X.push(b(B, I));
|
|
4074
|
+
return X.push("</body>"), X.join("");
|
|
4075
|
+
}, y = e.data.physics.colliders.filter((P) => P.enabled && !P.bodyPath), S = y.map((P) => {
|
|
4076
|
+
const C = e.data.physics.materials.find((V) => V.path === P.material), F = (C == null ? void 0 : C.density) != null && C.density > 0 ? C.density * d / u ** 3 : 1e3, I = (C == null ? void 0 : C.dynamicFriction) ?? 0.4, O = `density="${F}" group="3" contype="1" conaffinity="1" friction="${I} 0.01 0.0002"`;
|
|
4077
|
+
return sn(e, P, "", new Oe(), w++, r, O);
|
|
4078
|
+
}).join(""), v = so(e, t, y) ? `<geom name="__viewer_default_ground__" type="plane" pos="0 0 ${ro(e, t)}" size="1 1 0.1" group="3" contype="1" conaffinity="1" friction="0.8 0.01 0.0002"/>` : "", x = [...p.keys()].filter((P) => {
|
|
4079
|
+
var C;
|
|
4080
|
+
return !((C = _.get(P)) != null && C.body0);
|
|
4081
|
+
}).map((P) => b(P)).join("");
|
|
4082
|
+
if (g.size !== p.size) throw Y("USD joint graph contains unreachable bodies or a cycle.", "E_USD_UNREACHABLE_BODIES");
|
|
4083
|
+
if (e.data.physics.scenes.length > 1) throw Y("Multiple USD PhysicsScene prims are not supported.", "E_USD_MULTIPLE_PHYSICS_SCENES");
|
|
4084
|
+
const R = e.data.physics.scenes[0], A = R != null && R.gravityDirection && R.gravityMagnitude != null && R.gravityMagnitude >= 0 ? new j(...R.gravityDirection).normalize().multiplyScalar(R.gravityMagnitude * u).applyQuaternion(e.scene.quaternion) : new j(0, 0, -9.81);
|
|
4085
|
+
return {
|
|
4086
|
+
// Do not inflate contact surfaces across authored clearances. PhysX contactOffset
|
|
4087
|
+
// is not a MuJoCo force-generating margin and must not be copied as one.
|
|
4088
|
+
format: "mjcf",
|
|
4089
|
+
files: /* @__PURE__ */ new Map(),
|
|
4090
|
+
initialControls: l,
|
|
4091
|
+
initialVelocities: h,
|
|
4092
|
+
massOverrides: c,
|
|
4093
|
+
xml: `<mujoco><compiler angle="radian" autolimits="true"/><option integrator="implicitfast" gravity="${fe(A.toArray())}"><flag filterparent="disable"/></option><default><geom margin="0" solref="0.004 1"/></default>${r.length ? `<asset>${r.join("")}</asset>` : ""}<worldbody>${v}${S}${x}</worldbody>${a.length ? `<contact>${a.join("")}</contact>` : ""}${o.length ? `<equality>${o.join("")}</equality>` : ""}${i.length ? `<actuator>${i.join("")}</actuator>` : ""}</mujoco>`
|
|
4094
|
+
};
|
|
4095
|
+
}
|
|
4096
|
+
function so(e, t, n = e.data.physics.colliders.filter((s) => s.enabled && !s.bodyPath)) {
|
|
4097
|
+
if (!t.length || n.some((c) => c.typeName.toLowerCase().includes("plane"))) return !1;
|
|
4098
|
+
const s = Ut(e, e.data.physics.colliders.filter(
|
|
4099
|
+
(c) => c.enabled && c.bodyPath && t.includes(c.bodyPath)
|
|
4100
|
+
));
|
|
4101
|
+
if (s.isEmpty()) return n.length === 0;
|
|
4102
|
+
const r = Math.max(s.max.x - s.min.x, 1e-6), o = Math.max(s.max.y - s.min.y, 1e-6), a = Math.max(r, o, s.max.z - s.min.z) * 0.05;
|
|
4103
|
+
return !n.some((c) => {
|
|
4104
|
+
const i = Ut(e, [c]);
|
|
4105
|
+
if (i.isEmpty()) return !1;
|
|
4106
|
+
const l = i.max.x >= s.min.x && i.min.x <= s.max.x, h = i.max.y >= s.min.y && i.min.y <= s.max.y;
|
|
4107
|
+
return l && h && i.max.z <= s.min.z + a;
|
|
4108
|
+
});
|
|
4109
|
+
}
|
|
4110
|
+
function ro(e, t) {
|
|
4111
|
+
const n = Ut(e, e.data.physics.colliders.filter(
|
|
4112
|
+
(r) => r.enabled && r.bodyPath && t.includes(r.bodyPath)
|
|
4113
|
+
)), s = n.isEmpty() ? 0 : n.min.z;
|
|
4114
|
+
return Number.isFinite(s) ? String(s) : "0";
|
|
4115
|
+
}
|
|
4116
|
+
function Ut(e, t) {
|
|
4117
|
+
const n = new tt();
|
|
4118
|
+
for (const s of t) {
|
|
4119
|
+
const r = e.index.objectsByPath.get(s.path);
|
|
4120
|
+
r && n.union(new tt().setFromObject(r));
|
|
4121
|
+
}
|
|
4122
|
+
return n;
|
|
4123
|
+
}
|
|
4124
|
+
function Dn(e) {
|
|
4125
|
+
return e === "Y" ? new j(0, 1, 0) : e === "Z" ? new j(0, 0, 1) : new j(1, 0, 0);
|
|
4126
|
+
}
|
|
4127
|
+
function sn(e, t, n, s, r, o, a) {
|
|
4128
|
+
const c = e.index.objectsByPath.get(t.path);
|
|
4129
|
+
if (!c) throw Y(`USD collider node is missing: ${t.path}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
4130
|
+
const i = s.clone().invert().multiply(c.matrixWorld), l = new j(), h = new de(), u = new j();
|
|
4131
|
+
i.decompose(l, h, u);
|
|
4132
|
+
const d = t.typeName.replace(/^UsdGeom/, "").toLowerCase(), p = (f, _) => {
|
|
4133
|
+
const w = et(e, t.path, f);
|
|
4134
|
+
return typeof w == "number" ? w : _;
|
|
4135
|
+
};
|
|
4136
|
+
if (d.includes("cube")) {
|
|
4137
|
+
const f = Math.abs(p("size", 2)) / 2;
|
|
4138
|
+
return `<geom type="box" pos="${fe(l.toArray())}" quat="${Be(h)}" size="${fe([Math.abs(u.x) * f, Math.abs(u.y) * f, Math.abs(u.z) * f])}" ${a}/>`;
|
|
4139
|
+
}
|
|
4140
|
+
if (d.includes("plane")) {
|
|
4141
|
+
if (n) throw Y(`USD plane collider requires a static world owner: ${t.path}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
4142
|
+
const f = String(et(e, t.path, "axis") ?? "Z").toUpperCase(), w = { X: new j(1, 0, 0), Y: new j(0, 1, 0), Z: new j(0, 0, 1) }[f];
|
|
4143
|
+
if (!w) throw Y(`Unsupported USD plane axis: ${f}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
4144
|
+
const g = h.clone().multiply(new de().setFromUnitVectors(new j(0, 0, 1), w));
|
|
4145
|
+
return `<geom type="plane" pos="${fe(l.toArray())}" quat="${Be(g)}" size="1 1 0.1" ${a}/>`;
|
|
4146
|
+
}
|
|
4147
|
+
if (d.includes("cone"))
|
|
4148
|
+
throw Y(`MuJoCo has no analytic cone geom; a validated mesh conversion is required: ${t.path}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
4149
|
+
if (d.includes("sphere")) {
|
|
4150
|
+
const f = [Math.abs(u.x), Math.abs(u.y), Math.abs(u.z)];
|
|
4151
|
+
if (Math.max(...f) - Math.min(...f) > 1e-6) throw Y(`USD sphere collider does not support non-uniform scale: ${t.path}`, "E_USD_NONUNIFORM_RADIAL_SCALE");
|
|
4152
|
+
return `<geom type="sphere" pos="${fe(l.toArray())}" quat="${Be(h)}" size="${f[0] * p("radius", 1)}" ${a}/>`;
|
|
4153
|
+
}
|
|
4154
|
+
if (d.includes("cylinder") || d.includes("capsule")) {
|
|
4155
|
+
const f = String(et(e, t.path, "axis") ?? "Z").toUpperCase(), _ = { X: 0, Y: 1, Z: 2 }[f];
|
|
4156
|
+
if (_ === void 0) throw Y(`Unsupported USD collider axis: ${f}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
4157
|
+
const w = [Math.abs(u.x), Math.abs(u.y), Math.abs(u.z)], g = w.filter((m, x) => x !== _);
|
|
4158
|
+
if (Math.abs(g[0] - g[1]) > 1e-6) throw Y(`USD ${t.typeName} collider does not support non-uniform radial scale: ${t.path}`, "E_USD_NONUNIFORM_RADIAL_SCALE");
|
|
4159
|
+
const b = new j(...{ X: [1, 0, 0], Y: [0, 1, 0], Z: [0, 0, 1] }[f]), y = h.clone().multiply(new de().setFromUnitVectors(new j(0, 0, 1), b)), S = p("radius", 1) * g[0], v = p("height", 2) * w[_] / 2;
|
|
4160
|
+
return `<geom type="${d.includes("capsule") ? "capsule" : "cylinder"}" pos="${fe(l.toArray())}" quat="${Be(y)}" size="${S} ${v}" ${a}/>`;
|
|
4161
|
+
}
|
|
4162
|
+
if (d.includes("mesh")) {
|
|
4163
|
+
if (t.approximation && !["none", "convexHull"].includes(t.approximation)) throw Y(`USD mesh approximation cannot be mapped exactly: ${t.path}`, "E_USD_UNSUPPORTED_APPROXIMATION");
|
|
4164
|
+
const f = [];
|
|
4165
|
+
if (c.traverse((y) => {
|
|
4166
|
+
y instanceof me && f.push(y);
|
|
4167
|
+
}), !f.length) throw Y(`USD collider has no mesh geometry: ${t.path}`, "E_USD_MISSING_COLLISION_GEOMETRY");
|
|
4168
|
+
const _ = [], w = [];
|
|
4169
|
+
let g = 0;
|
|
4170
|
+
for (const y of f) {
|
|
4171
|
+
const S = y.geometry.getAttribute("position");
|
|
4172
|
+
for (let m = 0; m < S.count; m++) {
|
|
4173
|
+
const x = new j().fromBufferAttribute(S, m).applyMatrix4(s.clone().invert().multiply(y.matrixWorld));
|
|
4174
|
+
_.push(x.x, x.y, x.z);
|
|
4175
|
+
}
|
|
4176
|
+
const v = y.geometry.index;
|
|
4177
|
+
for (let m = 0; m < (v ? v.count : S.count); m += 3) w.push(g + (v ? v.getX(m) : m), g + (v ? v.getX(m + 1) : m + 1), g + (v ? v.getX(m + 2) : m + 2));
|
|
4178
|
+
g += S.count;
|
|
4179
|
+
}
|
|
4180
|
+
const b = `collision_${r}`;
|
|
4181
|
+
return o.push(`<mesh name="${b}" vertex="${fe(_)}" face="${fe(w)}"/>`), `<geom type="mesh" mesh="${b}" ${a}/>`;
|
|
4182
|
+
}
|
|
4183
|
+
throw Y(`Unsupported USD collider geometry: ${t.typeName}`, "E_USD_UNSUPPORTED_GEOMETRY");
|
|
4184
|
+
}
|
|
4185
|
+
function oo(e) {
|
|
4186
|
+
const t = e.stage.GetPseudoRoot();
|
|
4187
|
+
try {
|
|
4188
|
+
const n = Number(t.GetMetadata("metersPerUnit") ?? 0.01), s = Number(t.GetMetadata("kilogramsPerUnit") ?? 1);
|
|
4189
|
+
if (!Number.isFinite(n) || n <= 0) throw Y("USD metersPerUnit must be finite and positive.", "E_USD_INVALID_UNITS");
|
|
4190
|
+
if (!Number.isFinite(s) || s <= 0) throw Y("USD kilogramsPerUnit must be finite and positive.", "E_USD_INVALID_UNITS");
|
|
4191
|
+
return { metersPerUnit: n, kilogramsPerUnit: s };
|
|
4192
|
+
} finally {
|
|
4193
|
+
t.delete();
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
function Ne(e) {
|
|
4197
|
+
const [t = 1, n = 0, s = 0, r = 0] = e;
|
|
4198
|
+
return new de(n, s, r, t).normalize();
|
|
4199
|
+
}
|
|
4200
|
+
function fe(e) {
|
|
4201
|
+
return e.join(" ");
|
|
4202
|
+
}
|
|
4203
|
+
function Be(e) {
|
|
4204
|
+
return `${e.w} ${e.x} ${e.y} ${e.z}`;
|
|
4205
|
+
}
|
|
4206
|
+
function et(e, t, n) {
|
|
4207
|
+
var i, l;
|
|
4208
|
+
const s = e.stage;
|
|
4209
|
+
if (!s || !((l = (i = e.pxr) == null ? void 0 : i.Sdf) != null && l.Path)) return null;
|
|
4210
|
+
const r = new e.pxr.Sdf.Path(t), o = s.GetPrimAtPath(r), a = o.GetAttribute(n), c = e.pxr.Usd.TimeCode.Default();
|
|
4211
|
+
try {
|
|
4212
|
+
return a.IsValid() ? a.Get(c) : null;
|
|
4213
|
+
} finally {
|
|
4214
|
+
c.delete(), a.delete(), o.delete(), r.delete();
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4217
|
+
async function ao(e, t) {
|
|
4218
|
+
var n;
|
|
4219
|
+
if (e.url)
|
|
4220
|
+
try {
|
|
4221
|
+
return new URL(e.url, ((n = globalThis.location) == null ? void 0 : n.href) ?? e.baseUrl ?? void 0).href;
|
|
4222
|
+
} catch {
|
|
4223
|
+
return e.url;
|
|
4224
|
+
}
|
|
4225
|
+
return e.resolve(t);
|
|
4226
|
+
}
|
|
4227
|
+
async function io(e) {
|
|
4228
|
+
const t = e.url ?? await e.resolve(e.entryPath ?? ""), n = await fetch(t, { signal: e.signal });
|
|
4229
|
+
if (!n.ok) throw Y(`USD request failed (${n.status}): ${t}`, n.status === 401 || n.status === 403 ? "E_ASSET_AUTH" : "E_ASSET_FETCH");
|
|
4230
|
+
return n.blob();
|
|
4231
|
+
}
|
|
4232
|
+
function $e(e) {
|
|
4233
|
+
return e.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<").replaceAll(">", ">");
|
|
4234
|
+
}
|
|
4235
|
+
function Y(e, t) {
|
|
4236
|
+
return Object.assign(new Error(e), { code: t });
|
|
4237
|
+
}
|
|
4238
|
+
function dt() {
|
|
4239
|
+
return Object.assign(new Error("USD load aborted."), { name: "AbortError", code: "E_ABORTED" });
|
|
4240
|
+
}
|
|
4241
|
+
export {
|
|
4242
|
+
eo as buildUsdVisualReferenceOwners,
|
|
4243
|
+
nn as compileUsdCollisionOverlay,
|
|
4244
|
+
xn as compileUsdCollisionVisual,
|
|
4245
|
+
no as compileUsdPhysics,
|
|
4246
|
+
Qr as compileUsdVisual,
|
|
4247
|
+
Yr as firstUsdVisualWarning,
|
|
4248
|
+
ft as hasUsdCollisionGeometry,
|
|
4249
|
+
_o as isUsdPhysicsFallbackEligible,
|
|
4250
|
+
mo as loadUsdSimulation,
|
|
4251
|
+
to as parseUsdReferenceMetadata,
|
|
4252
|
+
Cn as resolveUsdJoints,
|
|
4253
|
+
so as shouldInjectUsdDefaultGround
|
|
4254
|
+
};
|