UNPKG

@spatialwalk/avatarkit

Version:

SPAvatar SDK - 3D Gaussian Splatting Avatar Rendering SDK

1,372 lines 227 kB
var tn = Object.defineProperty; var rn = (r, e, t) => e in r ? tn(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var d = (r, e, t) => rn(r, typeof e != "symbol" ? e + "" : e, t); class nn { /** * 构造函数(内部使用) * @param id 数字人 ID * @param characterMeta 角色元数据 * @param resources 资源数据 */ constructor(e, t, n) { d(this, "id"); d(this, "characterMeta"); d(this, "resources"); this.id = e, this.characterMeta = t, this.resources = n; } /** * 获取角色元数据(内部使用) * @internal */ getCharacterMeta() { return this.characterMeta; } /** * 获取资源数据(内部使用) * @internal */ getResources() { return this.resources; } } var an = /* @__PURE__ */ ((r) => (r.CAMERA = "camera", r.ANIMATION_IDLE = "frameIdle", r.ANIMATION_MONO = "frameMono", r.AUDIO_MONO = "audioMono", r.MODEL_SHAPE = "shape", r.MODEL_GS = "gsStandard", r))(an || {}); function Oa(r) { var e, t, n, a, i, s, l, o, p, c, u, m, w, v, y, b, P; return { camera: ((t = (e = r.camera) == null ? void 0 : e.resource) == null ? void 0 : t.remote) || null, frameIdle: ((i = (a = (n = r.animations) == null ? void 0 : n.frameIdle) == null ? void 0 : a.resource) == null ? void 0 : i.remote) || null, frameMono: ((o = (l = (s = r.animations) == null ? void 0 : s.frameMono) == null ? void 0 : l.resource) == null ? void 0 : o.remote) || null, audioMono: ((u = (c = (p = r.animations) == null ? void 0 : p.audioMono) == null ? void 0 : c.resource) == null ? void 0 : u.remote) || null, shape: ((v = (w = (m = r.models) == null ? void 0 : m.shape) == null ? void 0 : w.resource) == null ? void 0 : v.remote) || null, gsStandard: ((P = (b = (y = r.models) == null ? void 0 : y.gsStandard) == null ? void 0 : b.resource) == null ? void 0 : P.remote) || null }; } function Na(r) { var e, t, n, a, i, s; return !!((n = (t = (e = r.animations) == null ? void 0 : e.frameMono) == null ? void 0 : t.resource) != null && n.remote && ((s = (i = (a = r.animations) == null ? void 0 : a.audioMono) == null ? void 0 : i.resource) != null && s.remote)); } function Ua(r) { var e, t, n, a, i, s; try { const l = JSON.parse(r); return !!((n = (t = (e = l == null ? void 0 : l.animations) == null ? void 0 : e.frameMono) == null ? void 0 : t.resource) != null && n.remote && ((s = (i = (a = l == null ? void 0 : l.animations) == null ? void 0 : a.audioMono) == null ? void 0 : i.resource) != null && s.remote)); } catch { return !1; } } var le = /* @__PURE__ */ ((r) => (r.cn = "cn", r.us = "us", r.test = "test", r))(le || {}), he = /* @__PURE__ */ ((r) => (r.downloading = "downloading", r.completed = "completed", r.failed = "failed", r))(he || {}), be = /* @__PURE__ */ ((r) => (r.disconnected = "disconnected", r.connecting = "connecting", r.connected = "connected", r.failed = "failed", r))(be || {}), T = /* @__PURE__ */ ((r) => (r.idle = "idle", r.active = "active", r.playing = "playing", r.paused = "paused", r))(T || {}); class oe extends Error { constructor(e, t) { super(e), this.code = t, this.name = "SPAvatarError"; } } var Me = /* @__PURE__ */ ((r) => (r.network = "network", r.external = "external", r))(Me || {}); function sn() { return typeof window > "u" ? !1 : new URLSearchParams(window.location.search).get("debug") === "1"; } function on() { return sn(); } const x = { // Dynamic debug mode check (includes URL parameter) get debug() { return on(); }, camera: { position: [-0.02, -0.013, 1.5], target: [0, 0, 0], fov: 22, near: 0.01, far: 100 }, animation: { fps: 25 // 动画帧率(从 CharacterMeta 加载动画资源) }, audio: { sampleRate: 16e3 // 音频采样率(后端要求 16kHz) }, // FLAME 全局模板资源 CDN // 这些资源是所有角色共享的基础模板 flame: { cdnBaseUrl: "https://cdn.spatialwalk.top/public", resources: { flameModel: "model.pb", flameTemplate: "fm/template.pb", teethPb: "fm/teeth.pb", teethNpz: "teeth.npz" } } }; function zt(r) { var e; return { translation: r.translation || [0, 0, 0], rotation: r.rotation || [0, 0, 0], neck_pose: r.neckPose || [0, 0, 0], jaw_pose: r.jawPose || [0, 0, 0], eyes_pose: r.eyePose || [0, 0, 0, 0, 0, 0], eyelid: r.eyeLid || [0, 0], expr_params: r.expression || [], shape_params: [], // Realtime doesn't provide shape params, use default has_eyelid: (((e = r.eyeLid) == null ? void 0 : e.length) || 0) > 0 }; } function ht(r) { return { translation: r.translation || [0, 0, 0], rotation: r.rotation || [0, 0, 0], neckPose: r.neck_pose || [0, 0, 0], jawPose: r.jaw_pose || [0, 0, 0], eyePose: r.eyes_pose || [0, 0, 0, 0, 0, 0], eyeLid: r.eyelid || [0, 0], expression: r.expr_params || [] }; } var $t = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function ln(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } var qt = { exports: {} }, Ne = { exports: {} }, ft; function cn() { return ft || (ft = 1, function(r, e) { (function(t, n) { r.exports = n(); })($t, function() { function t(y) { return !isNaN(parseFloat(y)) && isFinite(y); } function n(y) { return y.charAt(0).toUpperCase() + y.substring(1); } function a(y) { return function() { return this[y]; }; } var i = ["isConstructor", "isEval", "isNative", "isToplevel"], s = ["columnNumber", "lineNumber"], l = ["fileName", "functionName", "source"], o = ["args"], p = ["evalOrigin"], c = i.concat(s, l, o, p); function u(y) { if (y) for (var b = 0; b < c.length; b++) y[c[b]] !== void 0 && this["set" + n(c[b])](y[c[b]]); } u.prototype = { getArgs: function() { return this.args; }, setArgs: function(y) { if (Object.prototype.toString.call(y) !== "[object Array]") throw new TypeError("Args must be an Array"); this.args = y; }, getEvalOrigin: function() { return this.evalOrigin; }, setEvalOrigin: function(y) { if (y instanceof u) this.evalOrigin = y; else if (y instanceof Object) this.evalOrigin = new u(y); else throw new TypeError("Eval Origin must be an Object or StackFrame"); }, toString: function() { var y = this.getFileName() || "", b = this.getLineNumber() || "", P = this.getColumnNumber() || "", L = this.getFunctionName() || ""; return this.getIsEval() ? y ? "[eval] (" + y + ":" + b + ":" + P + ")" : "[eval]:" + b + ":" + P : L ? L + " (" + y + ":" + b + ":" + P + ")" : y + ":" + b + ":" + P; } }, u.fromString = function(b) { var P = b.indexOf("("), L = b.lastIndexOf(")"), _ = b.substring(0, P), Y = b.substring(P + 1, L).split(","), G = b.substring(L + 1); if (G.indexOf("@") === 0) var U = /@(.+?)(?::(\d+))?(?::(\d+))?$/.exec(G, ""), W = U[1], Z = U[2], X = U[3]; return new u({ functionName: _, args: Y || void 0, fileName: W, lineNumber: Z || void 0, columnNumber: X || void 0 }); }; for (var m = 0; m < i.length; m++) u.prototype["get" + n(i[m])] = a(i[m]), u.prototype["set" + n(i[m])] = /* @__PURE__ */ function(y) { return function(b) { this[y] = !!b; }; }(i[m]); for (var w = 0; w < s.length; w++) u.prototype["get" + n(s[w])] = a(s[w]), u.prototype["set" + n(s[w])] = /* @__PURE__ */ function(y) { return function(b) { if (!t(b)) throw new TypeError(y + " must be a Number"); this[y] = Number(b); }; }(s[w]); for (var v = 0; v < l.length; v++) u.prototype["get" + n(l[v])] = a(l[v]), u.prototype["set" + n(l[v])] = /* @__PURE__ */ function(y) { return function(b) { this[y] = String(b); }; }(l[v]); return u; }); }(Ne)), Ne.exports; } (function(r, e) { (function(t, n) { r.exports = n(cn()); })($t, function(n) { var a = /(^|@)\S+:\d+/, i = /^\s*at .*(\S+:\d+|\(native\))/m, s = /^(eval@)?(\[native code])?$/; return { /** * Given an Error object, extract the most information from it. * * @param {Error} error object * @return {Array} of StackFrames */ parse: function(o) { if (typeof o.stacktrace < "u" || typeof o["opera#sourceloc"] < "u") return this.parseOpera(o); if (o.stack && o.stack.match(i)) return this.parseV8OrIE(o); if (o.stack) return this.parseFFOrSafari(o); throw new Error("Cannot parse given Error object"); }, // Separate line and column numbers from a string of the form: (URI:Line:Column) extractLocation: function(o) { if (o.indexOf(":") === -1) return [o]; var p = /(.+?)(?::(\d+))?(?::(\d+))?$/, c = p.exec(o.replace(/[()]/g, "")); return [c[1], c[2] || void 0, c[3] || void 0]; }, parseV8OrIE: function(o) { var p = o.stack.split(` `).filter(function(c) { return !!c.match(i); }, this); return p.map(function(c) { c.indexOf("(eval ") > -1 && (c = c.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "")); var u = c.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, ""), m = u.match(/ (\(.+\)$)/); u = m ? u.replace(m[0], "") : u; var w = this.extractLocation(m ? m[1] : u), v = m && u || void 0, y = ["eval", "<anonymous>"].indexOf(w[0]) > -1 ? void 0 : w[0]; return new n({ functionName: v, fileName: y, lineNumber: w[1], columnNumber: w[2], source: c }); }, this); }, parseFFOrSafari: function(o) { var p = o.stack.split(` `).filter(function(c) { return !c.match(s); }, this); return p.map(function(c) { if (c.indexOf(" > eval") > -1 && (c = c.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1")), c.indexOf("@") === -1 && c.indexOf(":") === -1) return new n({ functionName: c }); var u = /((.*".+"[^@]*)?[^@]*)(?:@)/, m = c.match(u), w = m && m[1] ? m[1] : void 0, v = this.extractLocation(c.replace(u, "")); return new n({ functionName: w, fileName: v[0], lineNumber: v[1], columnNumber: v[2], source: c }); }, this); }, parseOpera: function(o) { return !o.stacktrace || o.message.indexOf(` `) > -1 && o.message.split(` `).length > o.stacktrace.split(` `).length ? this.parseOpera9(o) : o.stack ? this.parseOpera11(o) : this.parseOpera10(o); }, parseOpera9: function(o) { for (var p = /Line (\d+).*script (?:in )?(\S+)/i, c = o.message.split(` `), u = [], m = 2, w = c.length; m < w; m += 2) { var v = p.exec(c[m]); v && u.push(new n({ fileName: v[2], lineNumber: v[1], source: c[m] })); } return u; }, parseOpera10: function(o) { for (var p = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i, c = o.stacktrace.split(` `), u = [], m = 0, w = c.length; m < w; m += 2) { var v = p.exec(c[m]); v && u.push( new n({ functionName: v[3] || void 0, fileName: v[2], lineNumber: v[1], source: c[m] }) ); } return u; }, // Opera 10.65+ Error.stack very similar to FF/Safari parseOpera11: function(o) { var p = o.stack.split(` `).filter(function(c) { return !!c.match(a) && !c.match(/^Error created at/); }, this); return p.map(function(c) { var u = c.split("@"), m = this.extractLocation(u.pop()), w = u.shift() || "", v = w.replace(/<anonymous function(: (\w+))?>/, "$2").replace(/\([^)]*\)/g, "") || void 0, y; w.match(/\(([^)]*)\)/) && (y = w.replace(/^[^(]+\(([^)]*)\)$/, "$1")); var b = y === void 0 || y === "[arguments not available]" ? void 0 : y.split(","); return new n({ functionName: v, args: b, fileName: m[0], lineNumber: m[1], columnNumber: m[2], source: c }); }, this); } }; }); })(qt); var dn = qt.exports; const un = /* @__PURE__ */ ln(dn); let mt = () => { var r = (() => { var e = Object.defineProperty, t = Object.getOwnPropertyDescriptor, n = Object.getOwnPropertyNames, a = Object.prototype.hasOwnProperty, i = (f, g) => { for (var A in g) e(f, A, { get: g[A], enumerable: !0 }); }, s = (f, g, A, C) => { if (g && typeof g == "object" || typeof g == "function") for (let E of n(g)) !a.call(f, E) && E !== A && e(f, E, { get: () => g[E], enumerable: !(C = t(g, E)) || C.enumerable }); return f; }, l = (f) => s(e({}, "__esModule", { value: !0 }), f), o = {}; i(o, { default: () => Qr }); var p = (f) => Array.isArray(f), c = (f) => typeof f == "function", u = (f) => f.length === 0, m = (f) => typeof f == "number", w = (f) => typeof f == "object" && f !== null, v = (f) => f instanceof RegExp, y = (f) => typeof f == "string", b = (f) => f === void 0, P = (f) => { const g = /* @__PURE__ */ new Map(); return (A) => { const C = g.get(A); if (C) return C; const E = f(A); return g.set(A, E), E; }; }, L = (f, g, A = {}) => { const C = { cache: {}, input: f, index: 0, indexMax: 0, options: A, output: [] }; if (z(g)(C) && C.index === f.length) return C.output; throw new Error(`Failed to parse at index ${C.indexMax}`); }, _ = (f, g) => p(f) ? Y(f, g) : y(f) ? U(f, g) : G(f, g), Y = (f, g) => { const A = {}; for (const C of f) { if (C.length !== 1) throw new Error(`Invalid character: "${C}"`); const E = C.charCodeAt(0); A[E] = !0; } return (C) => { const E = C.index, I = C.input; for (; C.index < I.length && I.charCodeAt(C.index) in A; ) C.index += 1; const R = C.index; if (R > E) { if (!b(g) && !C.options.silent) { const q = C.input.slice(E, R), j = c(g) ? g(q, I, String(E)) : g; b(j) || C.output.push(j); } C.indexMax = Math.max(C.indexMax, C.index); } return !0; }; }, G = (f, g) => { const A = f.source, C = f.flags.replace(/y|$/, "y"), E = new RegExp(A, C); return ne((I) => { E.lastIndex = I.index; const R = E.exec(I.input); if (R) { if (!b(g) && !I.options.silent) { const q = c(g) ? g(...R, I.input, String(I.index)) : g; b(q) || I.output.push(q); } return I.index += R[0].length, I.indexMax = Math.max(I.indexMax, I.index), !0; } else return !1; }); }, U = (f, g) => (A) => { if (A.input.startsWith(f, A.index)) { if (!b(g) && !A.options.silent) { const C = c(g) ? g(f, A.input, String(A.index)) : g; b(C) || A.output.push(C); } return A.index += f.length, A.indexMax = Math.max(A.indexMax, A.index), !0; } else return !1; }, W = (f, g, A, C) => { const E = z(f); return ne(ue(ye((I) => { let R = 0; for (; R < A; ) { const q = I.index; if (!E(I) || (R += 1, I.index === q)) break; } return R >= g; }))); }, Z = (f, g) => W(f, 0, 1), X = (f, g) => W(f, 0, 1 / 0), re = (f, g) => { const A = f.map(z); return ne(ue(ye((C) => { for (let E = 0, I = A.length; E < I; E++) if (!A[E](C)) return !1; return !0; }))); }, V = (f, g) => { const A = f.map(z); return ne(ue((C) => { for (let E = 0, I = A.length; E < I; E++) if (A[E](C)) return !0; return !1; })); }, ye = (f, g = !1) => { const A = z(f); return (C) => { const E = C.index, I = C.output.length, R = A(C); return (!R || g) && (C.index = E, C.output.length !== I && (C.output.length = I)), R; }; }, ue = (f, g) => z(f), ne = /* @__PURE__ */ (() => { let f = 0; return (g) => { const A = z(g), C = f += 1; return (E) => { var lt; var I; if (E.options.memoization === !1) return A(E); const R = E.index, q = (I = E.cache)[C] || (I[C] = /* @__PURE__ */ new Map()), j = q.get(R); if (j === !1) return !1; if (m(j)) return E.index = j, !0; if (j) return E.index = j.index, (lt = j.output) != null && lt.length && E.output.push(...j.output), !0; { const ct = E.output.length; if (A(E)) { const dt = E.index, ut = E.output.length; if (ut > ct) { const en = E.output.slice(ct, ut); q.set(R, { index: dt, output: en }); } else q.set(R, dt); return !0; } else return q.set(R, !1), !1; } }; }; })(), B = (f) => { let g; return (A) => (g || (g = z(f())), g(A)); }, z = P((f) => { if (c(f)) return u(f) ? B(f) : f; if (y(f) || v(f)) return _(f); if (p(f)) return re(f); if (w(f)) return V(Object.values(f)); throw new Error("Invalid rule"); }), ae = "abcdefghijklmnopqrstuvwxyz", Te = (f) => { let g = ""; for (; f > 0; ) { const A = (f - 1) % 26; g = ae[A] + g, f = Math.floor((f - 1) / 26); } return g; }, H = (f) => { let g = 0; for (let A = 0, C = f.length; A < C; A++) g = g * 26 + ae.indexOf(f[A]) + 1; return g; }, Be = (f, g) => { if (g < f) return Be(g, f); const A = []; for (; f <= g; ) A.push(f++); return A; }, ir = (f, g, A) => Be(f, g).map((C) => String(C).padStart(A, "0")), Qe = (f, g) => Be(H(f), H(g)).map(Te), J = (f) => f, et = (f) => sr((g) => L(g, f, { memoization: !1 }).join("")), sr = (f) => { const g = {}; return (A) => g[A] ?? (g[A] = f(A)); }, or = _(/^\*\*\/\*$/, ".*"), lr = _(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (f, g, A) => `.*${g ? "" : "(?:^|/)"}${A.replaceAll(".", "\\.")}`), cr = _(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (f, g, A, C) => `.*${g ? "" : "(?:^|/)"}${A.replaceAll(".", "\\.")}(?:${C.replaceAll(",", "|").replaceAll(".", "\\.")})`), De = _(/\\./, J), dr = _(/[$.*+?^(){}[\]\|]/, (f) => `\\${f}`), ur = _(/./, J), hr = _(/^(?:!!)*!(.*)$/, (f, g) => `(?!^${ot(g)}$).*?`), fr = _(/^(!!)+/, ""), mr = V([hr, fr]), pr = _(/\/(\*\*\/)+/, "(?:/.+/|/)"), gr = _(/^(\*\*\/)+/, "(?:^|.*/)"), wr = _(/\/(\*\*)$/, "(?:/.*|$)"), vr = _(/\*\*/, ".*"), tt = V([pr, gr, wr, vr]), yr = _(/\*\/(?!\*\*\/)/, "[^/]*/"), Ar = _(/\*/, "[^/]*"), rt = V([yr, Ar]), nt = _("?", "[^/]"), Sr = _("[", J), br = _("]", J), Cr = _(/[!^]/, "^/"), _r = _(/[a-z]-[a-z]|[0-9]-[0-9]/i, J), Er = _(/[$.*+?^(){}[\|]/, (f) => `\\${f}`), Pr = _(/[^\]]/, J), Ir = V([De, Er, _r, Pr]), at = re([Sr, Z(Cr), X(Ir), br]), xr = _("{", "(?:"), kr = _("}", ")"), Mr = _(/(\d+)\.\.(\d+)/, (f, g, A) => ir(+g, +A, Math.min(g.length, A.length)).join("|")), Fr = _(/([a-z]+)\.\.([a-z]+)/, (f, g, A) => Qe(g, A).join("|")), Rr = _(/([A-Z]+)\.\.([A-Z]+)/, (f, g, A) => Qe(g.toLowerCase(), A.toLowerCase()).join("|").toUpperCase()), Lr = V([Mr, Fr, Rr]), it = re([xr, Lr, kr]), Tr = _("{", "(?:"), Br = _("}", ")"), Dr = _(",", "|"), Or = _(/[$.*+?^(){[\]\|]/, (f) => `\\${f}`), Nr = _(/[^}]/, J), Ur = B(() => st), Vr = V([tt, rt, nt, at, it, Ur, De, Or, Dr, Nr]), st = re([Tr, X(Vr), Br]), zr = X(V([or, lr, cr, mr, tt, rt, nt, at, it, st, De, dr, ur])), $r = zr, qr = et($r), ot = qr, Gr = _(/\\./, J), Wr = _(/./, J), Hr = _(/\*\*\*+/, "*"), jr = _(/([^/{[(!])\*\*/, (f, g) => `${g}*`), Kr = _(/(^|.)\*\*(?=[^*/)\]}])/, (f, g) => `${g}*`), Xr = X(V([Gr, Hr, jr, Kr, Wr])), Jr = Xr, Yr = et(Jr), Zr = Yr, Oe = (f, g) => { const A = Array.isArray(f) ? f : [f]; if (!A.length) return !1; const C = A.map(Oe.compile), E = A.every((R) => /(\/(?:\*\*)?|\[\/\])$/.test(R)), I = g.replace(/[\\\/]+/g, "/").replace(/\/$/, E ? "/" : ""); return C.some((R) => R.test(I)); }; Oe.compile = (f) => new RegExp(`^${ot(Zr(f))}$`, "s"); var Qr = Oe; return l(o); })(); return r.default || r; }, Ue; const hn = (r, e) => (Ue || (Ue = mt(), mt = null), Ue(r, e)), fn = /^[A-Za-z]:\//; function ce(r = "") { return r && r.replace(/\\/g, "/").replace(fn, (e) => e.toUpperCase()); } const mn = /^[/\\]{2}/, pn = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, Gt = /^[A-Za-z]:$/, pt = /^\/([A-Za-z]:)?$/, gn = /.(\.[^./]+|\.)$/, wn = /^[/\\]|^[a-zA-Z]:[/\\]/, vn = "/", Xe = function(r) { if (r.length === 0) return "."; r = ce(r); const e = r.match(mn), t = ve(r), n = r[r.length - 1] === "/"; return r = Je(r, !t), r.length === 0 ? t ? "/" : n ? "./" : "." : (n && (r += "/"), Gt.test(r) && (r += "/"), e ? t ? `//${r}` : `//./${r}` : t && !ve(r) ? `/${r}` : r); }, yn = function(...r) { let e = ""; for (const t of r) if (t) if (e.length > 0) { const n = e[e.length - 1] === "/", a = t[0] === "/"; n && a ? e += t.slice(1) : e += n || a ? t : `/${t}`; } else e += t; return Xe(e); }; function An() { return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/"; } const Fe = function(...r) { r = r.map((n) => ce(n)); let e = "", t = !1; for (let n = r.length - 1; n >= -1 && !t; n--) { const a = n >= 0 ? r[n] : An(); !a || a.length === 0 || (e = `${a}/${e}`, t = ve(a)); } return e = Je(e, !t), t && !ve(e) ? `/${e}` : e.length > 0 ? e : "."; }; function Je(r, e) { let t = "", n = 0, a = -1, i = 0, s = null; for (let l = 0; l <= r.length; ++l) { if (l < r.length) s = r[l]; else { if (s === "/") break; s = "/"; } if (s === "/") { if (!(a === l - 1 || i === 1)) if (i === 2) { if (t.length < 2 || n !== 2 || t[t.length - 1] !== "." || t[t.length - 2] !== ".") { if (t.length > 2) { const o = t.lastIndexOf("/"); o === -1 ? (t = "", n = 0) : (t = t.slice(0, o), n = t.length - 1 - t.lastIndexOf("/")), a = l, i = 0; continue; } else if (t.length > 0) { t = "", n = 0, a = l, i = 0; continue; } } e && (t += t.length > 0 ? "/.." : "..", n = 2); } else t.length > 0 ? t += `/${r.slice(a + 1, l)}` : t = r.slice(a + 1, l), n = l - a - 1; a = l, i = 0; } else s === "." && i !== -1 ? ++i : i = -1; } return t; } const ve = function(r) { return pn.test(r); }, Sn = function(r) { return ce(r); }, Wt = function(r) { if (r === "..") return ""; const e = gn.exec(ce(r)); return e && e[1] || ""; }, bn = function(r, e) { const t = Fe(r).replace(pt, "$1").split("/"), n = Fe(e).replace(pt, "$1").split("/"); if (n[0][1] === ":" && t[0][1] === ":" && t[0] !== n[0]) return n.join("/"); const a = [...t]; for (const i of a) { if (n[0] !== i) break; t.shift(), n.shift(); } return [...t.map(() => ".."), ...n].join("/"); }, Ht = function(r) { const e = ce(r).replace(/\/$/, "").split("/").slice(0, -1); return e.length === 1 && Gt.test(e[0]) && (e[0] += "/"), e.join("/") || (ve(r) ? "/" : "."); }, Cn = function(r) { const e = r.ext ? r.ext.startsWith(".") ? r.ext : `.${r.ext}` : "", t = [r.root, r.dir, r.base ?? (r.name ?? "") + e].filter( Boolean ); return ce( r.root ? Fe(...t) : t.join("/") ); }, jt = function(r, e) { const t = ce(r).split("/"); let n = ""; for (let a = t.length - 1; a >= 0; a--) { const i = t[a]; if (i) { n = i; break; } } return e && n.endsWith(e) ? n.slice(0, -e.length) : n; }, _n = function(r) { var a, i; const e = ((i = (a = wn.exec(r)) == null ? void 0 : a[0]) == null ? void 0 : i.replace(/\\/g, "/")) || "", t = jt(r), n = Wt(t); return { root: e, dir: Ht(r), base: t, ext: n, name: t.slice(0, t.length - n.length) }; }, En = (r, e) => hn(e, Xe(r)), gt = { __proto__: null, basename: jt, dirname: Ht, extname: Wt, format: Cn, isAbsolute: ve, join: yn, matchesGlob: En, normalize: Xe, normalizeString: Je, parse: _n, relative: bn, resolve: Fe, sep: vn, toNamespacedPath: Sn }, Pn = /* @__PURE__ */ (() => { var r; return ((r = globalThis.process) == null ? void 0 : r.platform) === "win32" ? ";" : ":"; })(), In = { posix: void 0, win32: void 0 }, Kt = (r = Pn) => new Proxy(gt, { get(e, t) { return t === "delimiter" ? r : t === "posix" ? We : t === "win32" ? xn : In[t] || gt[t]; } }), We = /* @__PURE__ */ Kt(":"), xn = /* @__PURE__ */ Kt(";"); var M = /* @__PURE__ */ ((r) => (r[r.Error = 0] = "Error", r[r.Warning = 1] = "Warning", r[r.Log = 2] = "Log", r[r.Verbose = 3] = "Verbose", r[r.Debug = 4] = "Debug", r))(M || {}), k = /* @__PURE__ */ ((r) => (r.Error = "error", r.Warning = "warn", r.Log = "log", r.Verbose = "verbose", r.Debug = "debug", r))(k || {}), te = /* @__PURE__ */ ((r) => (r.JSON = "json", r.Pretty = "pretty", r))(te || {}); const kn = !0; function F(r, e, t = r) { return (n) => { const a = `${n}`, i = a.indexOf(e, r.length); return ~i ? r + Xt(a, e, t, i) + e : r + a + e; }; } function Xt(r, e, t, n) { const a = r.substring(0, n) + t, i = r.substring(n + e.length), s = i.indexOf(e); return ~s ? a + Xt(i, e, t, s) : a + i; } function Mn(r = kn) { return { isColorSupported: r, reset: r ? (e) => `\x1B[0m${e}\x1B[0m` : String, bold: r ? F("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m") : String, dim: r ? F("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m") : String, italic: r ? F("\x1B[3m", "\x1B[23m") : String, underline: r ? F("\x1B[4m", "\x1B[24m") : String, inverse: r ? F("\x1B[7m", "\x1B[27m") : String, hidden: r ? F("\x1B[8m", "\x1B[28m") : String, strikethrough: r ? F("\x1B[9m", "\x1B[29m") : String, black: r ? F("\x1B[30m", "\x1B[39m") : String, red: r ? F("\x1B[31m", "\x1B[39m") : String, green: r ? F("\x1B[32m", "\x1B[39m") : String, yellow: r ? F("\x1B[33m", "\x1B[39m") : String, blue: r ? F("\x1B[34m", "\x1B[39m") : String, magenta: r ? F("\x1B[35m", "\x1B[39m") : String, cyan: r ? F("\x1B[36m", "\x1B[39m") : String, white: r ? F("\x1B[37m", "\x1B[39m") : String, gray: r ? F("\x1B[90m", "\x1B[39m") : String, bgBlack: r ? F("\x1B[40m", "\x1B[49m") : String, bgRed: r ? F("\x1B[41m", "\x1B[49m") : String, bgGreen: r ? F("\x1B[42m", "\x1B[49m") : String, bgYellow: r ? F("\x1B[43m", "\x1B[49m") : String, bgBlue: r ? F("\x1B[44m", "\x1B[49m") : String, bgMagenta: r ? F("\x1B[45m", "\x1B[49m") : String, bgCyan: r ? F("\x1B[46m", "\x1B[49m") : String, bgWhite: r ? F("\x1B[47m", "\x1B[49m") : String }; } const D = Mn(), He = { [k.Error]: M.Error, [k.Warning]: M.Warning, [k.Log]: M.Log, [k.Verbose]: M.Verbose, [k.Debug]: M.Debug }, Fn = { [M.Error]: k.Error, [M.Warning]: k.Warning, [M.Log]: k.Log, [M.Verbose]: k.Verbose, [M.Debug]: k.Debug }, wt = [ k.Error, k.Warning, k.Log, k.Verbose, k.Debug ], Rn = { [M.Error]: D.red, [M.Warning]: D.yellow, [M.Log]: D.blue, [M.Verbose]: D.cyan, [M.Debug]: D.green }, Re = [ M.Error, M.Warning, M.Log, M.Verbose, M.Debug ], vt = [te.JSON, te.Pretty]; function Ln(r) { return r.stack == null ? [] : r.stack.split(` `).map((e) => e.trim()).slice(1).filter((e) => !!/^at (.*)( \(.*:(\d+):(\d+)\))|at (.*)(:(\d+):(\d+))/i.exec(e)).map((e) => { const t = /at (.*)( \((.*):(\d+):(\d+)\))|at (.*)(:(\d+):(\d+))/i.exec(e); return t ? typeof t[1] < "u" && typeof t[2] < "u" && typeof t[3] < "u" && typeof t[4] < "u" && typeof t[5] < "u" ? { invalid: !1, function: t[1] ?? "", file: t[3] ?? "", line: Number.parseInt(t[4] ?? "0"), column: Number.parseInt(t[5] ?? "0") } : typeof t[6] < "u" && typeof t[7] < "u" && typeof t[8] < "u" && typeof t[9] < "u" ? { invalid: !1, function: t[6] ?? "", file: t[7] ?? "", line: Number.parseInt(t[8] ?? "0"), column: Number.parseInt(t[9] ?? "0") } : { invalid: !0 } : { invalid: !0 }; }); } function Jt(r) { return r == null ? !1 : r instanceof Error; } function Yt(r, e, t, n, a) { let i = { context: "" }; typeof t < "u" && t !== null && (i = { ...t }), typeof e < "u" && e !== null && (i.context = e); const s = /* @__PURE__ */ new Date(); return { "@timestamp": s.getTime(), "@localetime": a ? a(s) : s.toISOString(), level: r, fields: i, message: n }; } function Tn(r, e, t, n, a, i) { const s = Yt(r, e, t, n, i); return typeof a < "u" && a !== null && (s.errored = !0, s.error = { stack: a }), s; } function yt(r) { let e = ""; switch (typeof r) { case "number": e = D.yellow(r); break; case "object": e = D.green(JSON.stringify(r)); break; case "boolean": e = D.yellow(String(r)); break; case "undefined": e = D.gray("undefined"); break; default: e = String(r); break; } return e; } function Ie(r) { const e = []; e.push(r["@localetime"]), e.push( Rn[He[r.level]]( `[${r.level}]` ) ); let t = ""; r.fields.isNestSystemModule != null && (t = D.magenta(`[${r.fields.nestSystemModule}]`), delete r.fields.isNestSystemModule, delete r.fields.nestSystemModule), r.fields.context != null && (t = D.magenta(`[${r.fields.context}]`), delete r.fields.context), t.length > 0 && e.push(t), "module" in r.fields && r.fields.module != null && (e.push(D.magenta(`[${r.fields.module}]`)), delete r.fields.module), e.push(r.message); const n = Object.entries(r.fields); n.length > 0 && e.push(" {"); for (const [i, s] of n) { let l = s; if (Jt(s)) { if (s.message && (l = yt(s.message)), l || (l = ""), s.cause != null) try { l += JSON.stringify(s.cause); } catch { l += String(s.cause); } } else l = yt(s); e.push(`${D.gray(i)}${D.gray("=")}${l}`); } n.length > 0 && e.push("}"); let a = e.join(" "); return r.errored != null && r.errored && r.error && r.error.stack != null && r.error.stack && (a += ` ${r.error.stack}`), a; } function Bn(r) { return r >= M.Debug; } function Dn(r) { return r >= M.Verbose; } function On(r) { return r >= M.Log; } function Nn(r) { return r >= M.Warning; } function Un(r) { return r >= M.Error; } function Zt() { return typeof window < "u"; } function Vn() { return !Zt() && je() === te.Pretty; } function zn(r, e) { return Vn() ? `\x1B]8;;file://${r}\x1B\\${e}\x1B]8;;\x1B\\` : e; } const Ee = { configured: !1, logLevel: M.Debug, format: te.JSON, timeFormatter: (r) => r.toISOString() }; function At() { return Ee.logLevel; } function $n(r) { if (Re.includes(r)) Ee.logLevel = r; else throw new Error( `log level ${r} is not available. available log levels are: ${Re.join( ", " )}` ); Ee.configured = !0; } function je() { return Ee.format; } function qn() { return Ee.timeFormatter; } function Qt(r) { const e = { fields: {}, context: r, logLevel: M.Debug, format: te.JSON, shouldUseGlobalConfig: !1, errorProcessor: (c) => c, timeFormatter: (c) => c.toISOString(), useGlobalConfig: () => (e.shouldUseGlobalConfig = !0, e.format = je(), e.logLevel = At(), e.child()), child: (c) => { const u = Qt(e.context); return c != null ? u.fields = { ...e.fields, ...c } : u.fields = e.fields, u.fields != null && "context" in u.fields ? u.context = u.fields.context : u.context = e.context, u.logLevel = e.logLevel, u.format = e.format, u.shouldUseGlobalConfig = e.shouldUseGlobalConfig, u; }, withContext: (c) => { const u = e.child(); return u.context = c, u; }, withLogLevel: (c) => { const u = e.child(); if (Re.includes(c)) u.logLevel = c, u.shouldUseGlobalConfig = !1, u.debug( `setting log level to ${Fn[c]} (${c})` ); else throw new Error( `log level ${c} is not available. available log levels are: ${Re.join( ", " )}` ); return u; }, withLogLevelString: (c) => { const u = e.child(); if (wt.includes(c)) u.logLevel = He[c], u.shouldUseGlobalConfig = !1, u.debug( `setting log level to ${c} (${He[c]})` ); else throw new Error( `log level ${c} is not available. available log levels are: ${wt.join( ", " )}` ); return u; }, withFormat: (c) => { const u = e.child(); if (vt.includes(c)) u.format = c, u.shouldUseGlobalConfig = !1, u.debug(`setting format to ${c}`); else throw new Error( `format ${c} is not available. available formats are: ${vt.join( ", " )}` ); return u; }, withFields: (c) => typeof c > "u" || c === null ? e.child({}) : e.child(c), withField(c, u) { if (typeof c > "u" || c === null) throw new Error("key is required"); return e.child({ [c]: u }); }, withError: (c) => { if (c = e.errorProcessor(c), !Jt(c)) return e.withField("error", String(c)); let u = e; if (u = u.withField("error", c.message), c.stack != null && (u = u.withField("stack", c.stack)), c.cause != null) try { u = u.withField("cause", JSON.stringify(c.cause)); } catch { u = u.withField("cause", String(c.cause)); } return u; }, withCallStack(c) { const u = Ln(c).slice(2).filter((m) => !m.invalid); return u.length === 0 ? e : e.child({ function: u[0].function, file: `${u[0].file}:${u[0].line}:${u[0].column}`, line: u[0].line, column: u[0].column }); }, // Placeholder implementations, will be overridden below debug: () => { }, verbose: () => { }, log: () => { }, error: () => { }, errorWithError: () => { }, warn: () => { }, // TODO: remove in next major release withTimeFormat: (c) => e.child(), withTimeFormatter: (c) => { const u = e.child(); return u.timeFormatter = c, u; }, withErrorProcessor: (c) => { const u = e.child(); return u.errorProcessor = c, u; } }, t = () => e.shouldUseGlobalConfig ? At() : e.logLevel, n = () => e.shouldUseGlobalConfig ? je() : e.format, a = () => e.shouldUseGlobalConfig ? qn() : e.timeFormatter ?? ((c) => c.toISOString()), i = (c) => c != null && c.length > 0 ? Object.keys(e.fields).length > 0 ? [e.fields, ...c] : c : e.fields, s = (c, u, m) => { const w = n(); if (Zt() && w === te.Pretty) { c.fields = Object.fromEntries( Object.entries(c.fields).filter(([b, P]) => { if (b === "isNestSystemModule" || b === "nestSystemModule" || b === "context") return [b, P]; }) ); const y = m ?? e.fields; Array.isArray(y) && y.length > 0 ? console[u](Ie(c), ...y) : Object.keys(y).length > 0 ? console[u](Ie(c), y) : console[u](Ie(c)); return; } const v = w === te.Pretty ? Ie(c) : JSON.stringify(c); console[u](v); }, l = { [k.Debug]: Bn, [k.Verbose]: Dn, [k.Log]: On, [k.Warning]: Nn }, o = { [k.Debug]: "debug", [k.Verbose]: "log", [k.Log]: "log", [k.Warning]: "warn" }, p = (c, u, m) => { const w = t(), v = l[c]; if (!v(w)) return; const y = i(m), b = Yt( c, e.context, y, u, a() ); s(b, o[c], y); }; return e.debug = (c, ...u) => { p(k.Debug, c, u); }, e.verbose = (c, ...u) => { p(k.Verbose, c, u); }, e.log = (c, ...u) => { p(k.Log, c, u); }, e.warn = (c, ...u) => { p(k.Warning, c, u); }, e.error = (c, u, ...m) => { const w = t(); if (!Un(w)) return; const v = i(m), y = Tn( k.Error, e.context, v, c, u, a() ); s(y, "error", v); }, e.errorWithError = (c, u, ...m) => e.withError(u).error(c, void 0, ...m), e; } function Gn(r) { var i; const t = un.parse(new Error())[1], n = ((i = t.fileName) == null ? void 0 : i.replace("async", "").trim()) ?? "", a = We.join(...n.split(We.sep).slice(-2)); return r = r ?? `${a}:${t.lineNumber}`, Qt(zn(n, r)); } const Wn = (r) => Gn(r).useGlobalConfig(); let Q = []; const St = 100; async function Hn() { if (Q.length === 0) return; const r = [...Q]; Q = []; try { await jn(); } catch (e) { h.warn("[CLS] Failed to flush logs:", e instanceof Error ? e.message : String(e)), Q.unshift(...r), Q.length > St && (Q = Q.slice(0, St)); } } async function jn(r) { } function Kn() { Q.length > 0 && Hn(), h.log("[CLS] Cleaned up"); } $n(M.Warning); const h = Wn("Web").withErrorProcessor((r) => r).useGlobalConfig(), O = { config: null, promise: null }; async function Xn(r) { return O.promise ? (await O.promise, O.config || {}) : O.config ? O.config : (O.promise = (async () => { try { const t = typeof window < "u" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") ? `/api/config/sdk?version=${r}` : `https://config.spatialwalk.top/sdk?version=${r}`; h.log(`[SdkConfigLoader] Fetching SDK config from: ${t}`); const n = await fetch(t, { method: "GET", headers: { "Content-Type": "application/json" } }); if (!n.ok) throw new Error(`HTTP ${n.status} ${n.statusText}`); const a = await n.json(); if (!a.endpoints) throw new Error("Invalid config response: missing endpoints"); const i = {}; a.endpoints.cn && (i[le.cn] = `https://${a.endpoints.cn}`), a.endpoints.us && (i[le.us] = `https://${a.endpoints.us}`), a.endpoints.test && (i[le.test] = `https://${a.endpoints.test}`), O.config = i, h.log("[SdkConfigLoader] SDK config fetched successfully:", i); } catch { O.config = {}; } finally { O.promise = null; } })(), await O.promise, O.config || {}); } function Jn() { O.config = null, O.promise = null; } class Yn { constructor(e) { d(this, "module"); d(this, "allocatedPointers"); d(this, "structPointers"); this.module = e, this.allocatedPointers = /* @__PURE__ */ new Set(), this.structPointers = /* @__PURE__ */ new Map(); } /** * 分配 WASM 内存并复制数据 - 纯 API 方式 */ allocateAndCopy(e) { const t = e.byteLength, n = this.module._malloc(t); if (!n) throw new Error(`Failed to allocate ${t} bytes in WASM memory`); const a = new Uint8Array(e); return this.module.writeArrayToMemory(a, n), this.allocatedPointers.add(n), { ptr: n, size: t }; } /** * 创建 AvatarTemplateConfig 结构体 */ createTemplateConfig(e) { const n = this.module._malloc(40); if (!n) throw new Error("Failed to allocate AvatarTemplateConfig structure"); if (!e.flameModel || e.flameModel.byteLength === 0) throw new Error("flameModel is missing or empty!"); if (!e.flameTemplate || e.flameTemplate.byteLength === 0) throw new Error("flameTemplate is missing or empty!"); if (!e.teethPb || e.teethPb.byteLength === 0) throw new Error("teethPb is missing or empty!"); if (!e.teethNpz || e.teethNpz.byteLength === 0) throw new Error("teethNpz is missing or empty!"); const a = this.allocateAndCopy(e.flameModel), i = this.allocateAndCopy(e.flameTemplate), s = this.allocateAndCopy(e.teethPb), l = this.allocateAndCopy(e.teethNpz); let o = 0; return this.module.setValue(n + o, a.ptr, "i32"), o += 4, this.module.setValue(n + o, a.size, "i32"), o += 4, this.module.setValue(n + o, i.ptr, "i32"), o += 4, this.module.setValue(n + o, i.size, "i32"), o += 4, this.module.setValue(n + o, s.ptr, "i32"), o += 4, this.module.setValue(n + o, s.size, "i32"), o += 4, this.module.setValue(n + o, l.ptr, "i32"), o += 4, this.module.setValue(n + o, l.size, "i32"), o += 4, this.module.setValue(n + o, 0, "i32"), o += 4, this.module.setValue(n + o, 0, "i32"), o += 4, this.structPointers.set("template_config", n), n; } /** * 创建 AvatarCharacterData 结构体 - 新版 Emscripten 方式 */ createCharacterData(e, t, n) { const i = this.module._malloc(16); if (!i) throw new Error("Failed to allocate AvatarCharacterData structure"); const s = this.allocateAndCopy(e), l = this.allocateAndCopy(t); let o = 0; this.module.setValue(i + o, s.ptr, "i32"), o += 4, this.module.setValue(i + o, s.size, "i32"), o += 4, this.module.setValue(i + o, l.ptr, "i32"), o += 4, this.module.setValue(i + o, l.size, "i32"), o += 4; const p = n ? `character_data_${n}` : "character_data"; return this.structPointers.set(p, i), { dataPtr: i, shapePtr: s.ptr, plyPtr: l.ptr }; } /** * 读取 AvatarFlameParams 结构体数据 * Used to extract current animation frame parameters from WASM memory */ readFlameParams(e) { let t = 0; const n = []; for (let m = 0; m < 300; m++) n.push(this.module.getValue(e + t, "float")), t += 4; const a = []; for (let m = 0; m < 100; m++) a.push(this.module.getValue(e + t, "float")), t += 4; const i = []; for (let m = 0; m < 3; m++) i.push(this.module.getValue(e + t, "float")), t += 4; const s = []; for (let m = 0; m < 3; m++) s.push(this.module.getValue(e + t, "float")), t += 4; const l = []; for (let m = 0; m < 3; m++) l.push(this.module.getValue(e + t, "float")), t += 4; const o = []; for (let m = 0; m < 3; m++) o.push(this.module.getValue(e + t, "float")), t += 4; const p = []; for (let m = 0; m < 6; m++) p.push(this.module.getValue(e + t, "float")), t += 4; const c = []; for (let m = 0; m < 2; m++) c.push(this.module.getValue(e + t, "float")), t += 4; const u = this.module.getValue(e + t, "i32") !== 0; return { shape_params: n, expr_params: a, rotation: i, translation: s, neck_pose: l, jaw_pose: o, eyes_pose: p, eyelid: c, has_eyelid: u }; } /** * 创建 AvatarFlameParams 结构体 - 新版 Emscripten 方式 */ createFlameParams(e) { var i, s, l, o, p, c, u, m; const n = this.module._malloc(1684); if (!n) throw new Error("Failed to allocate AvatarFlameParams structure"); let a = 0; for (let w = 0; w < 300; w++) { const v = ((i = e.shape_params) == null ? void 0 : i[w]) || 0; this.module.setValue(n + a, v, "float"), a += 4; } for (let w = 0; w < 100; w++) { const v = ((s = e.expr_params) == null ? void 0 : s[w]) || 0; this.module.setValue(n + a, v, "float"), a += 4; } for (let w = 0; w < 3; w++) { const v = ((l = e.rotation) == null ? void 0 : l[w]) || 0; this.module.setValue(n + a, v, "float"), a += 4; } for (let w = 0; w < 3; w++) { const v = ((o = e.translation) == null ? void 0 : o[w]) || 0; this.module.setValue(n + a, v, "float"), a += 4; } for (let w = 0; w < 3; w++) { const v = ((p = e.neck_pose) == null ? void 0 : p[w]) || 0; this.module.setValue(n + a, v, "float"), a += 4; } for (let w = 0; w < 3; w++) { const v = ((c = e.jaw_pose) == null ? void 0 : c[w]) || 0; this.module.setValue(n + a, v, "float"), a += 4; } for (let w = 0; w < 6; w++) { const v = ((u = e.eyes_pose) == null ? void 0 : u[w]) || 0; this.module.setValue(n + a, v, "float"), a += 4; } for (let w = 0; w < 2; w++) { const v = ((m = e.eyelid) == null ? void 0 : m[w]) || 0; this.module.setValue(n + a, v, "float"), a += 4; } return this.module.setValue(n + a, e.has_eyelid ? 1 : 0, "i32"), a += 4, n; } /** * 读取 AvatarSplatPointFlatArray 结构体数据(预计算协方差) * * 结构体布局: * - AvatarSplatPointFlat* points (0-3, 32位指针) * - uint32_t point_count (4-7) * - float compute_time_ms (8-11) * * 每个点布局 (52 bytes): * - position[3] (12 bytes) * - color[4] (16 bytes, RGBA) * - covariance[6] (24 bytes, 预计算好的协方差矩阵上三角) * * ⚠️ 使用 getValue 逐个读取,避免动态内存的 HEAPF32 detachment 问题 */ readSplatPointFlatArray(e) { if (!e) throw new Error("Invalid array pointer"); const t = this.module.getValue(e, "i32"), n = this.module.getValue(e + 4, "i32"); if (n === 0 || !t) return null; const i = n * 13, s = t / 4, l = new Float32Array(i); return l.set(this.module.HEAPF32.subarray(s, s + i)), l; } /** * 读取AvatarMeshData结构体数据 */ readMeshData(e) { const t = this.module.getValue(e + 0, "*"), n = this.module.getValue(e + 4, "i32"), a = this.module.getValue(e + 8, "*"), i = this.module.getValue(e + 12, "i32"), s = this.module.getValue(e + 16, "float"), l = this.module.getValue(e + 20, "*"), o = this.module.getValue(e + 24, "i32"), p = new Float32Array(n * 3); if (t && n > 0) for (let m = 0; m < n * 3; m++) p[m] = this.module.getValue(t + m * 4, "float"); const c = new Uint32Array(i * 3); if (a && i > 0) for (let m = 0; m < i * 3; m++) c[m] = this.module.getValue(a + m * 4, "i32"); let u = null; if (l && o > 0) { u = new Float32Array(o * 3); for (let m = 0; m < o * 3; m++) u[m] = this.module.getValue(l + m * 4, "float"); } return { vertices: p, vertexCount: n, faces: c, faceCount: i, landmarks: u, landmarkCount: o, computeTime: s }; } /** * 释放指定指针的内存 */ free(e) { e && this.allocatedPointers.has(e) && (this.module._free(e), this.allocatedPointers.delete(e)); } /** * 释放结构体内存 */ freeStruct(e) { const t = this.structPointers.get(e); t && (this.module._free(t), this.structPointers.delete(e)); } /** * 清理所有分配的内存 */ cleanup() { for (const e of this.allocatedPointers) this.module._free(e); this.allocatedPointers.clear(); for (const [, e] of this.structPointers) this.module._free(e); this.structPointers.clear(); } /** * 获取内存使用统计 */ getMemoryStats() { return { allocatedPointers: this.allocatedPointers.size, structPointers: this.structPointers.size, totalAllocatedMB: Math.round(this.allocatedPointers.size * 1024 / 1024) }; } } class Zn { constructor(e = {}) { // 配置 d(this, "options"); d(this, "wasmConfig"); // 核心组件 // eslint-disable-next-line ts/no-explicit-any d(this, "wasmModule"); d(this, "memoryManager"); // Avatar Core handles d(this, "coreHandle"); // Support multiple character handles (key: characterId, value: handle) d(this, "characterHandles", /* @__PURE__ */ new Map()); // Animation handles per character (key: characterId, value: { handle, totalFrames }) d(this, "animationHandles", /* @__PURE__ */ new Map()); // Legacy single character support (deprecated, kept for backward compatibility) d(this, "characterHandle"); d(this, "animationHandle"); d(this, "totalFrames"); // 状态管理 d(this, "isInitialized"); d(this, "isCharacterLoaded"); // C API 函数包装 // eslint-disable-next-line ts/no-explicit-any d(this, "api"); // 性能监控 d(this, "performanceMetrics"); d(this, "wasmTime", 0); // 最近一次 WASM 计算耗时 // 错误码映射 d(this, "errorCodes"); // 模型信息 d(this, "flameInfo"); d(this, "characterInfo"); this.options = { logLevel: "basic", enableValidation: !0, enablePerformanceMetrics: !0, retryCount: 3, baseAssetsPath: "/", modelFolder: "3dgs", wasmPath: "./wasm/avatar_core_wasm.wasm", ...e }, this.wasmConfig = e.wasmConfig || { baseUrl: void 0 }, this.wasmModule = null, this.memoryManager = null, this.coreHandle = null, this.characterHandle = null, this.animationHandle = null, this.totalFrames = null, this.isInitialized = !1, this.isCharacterLoaded = !1, this.api = {}, this.performanceMetrics = { initTime: 0, loadTime: 0, computeFrames: 0, totalComputeTime: 0, averageComputeTime: 0 }, this.errorCodes = { 0: "AVATAR_SUCCESS", 1: "AVATAR_ERROR_INVALID_PARAMETER", 2: "AVATAR_ERROR_MEMORY_ALLOCATION", 3: "AVATAR_ERROR_INVALID_DATA_FORMAT", 4: "AVATAR_ERROR_CHARACTER_NOT_FOUND", 5: "AVATAR_ERROR_ANIMATION_NOT_FOUND", 6: "AVATAR_ERROR_COMPUTATION_FAILED" }; } /** * 加载 WASM 模块并设置 API * 每次都创建全新的 WASM 实例,确保 C++ 内存是干净的 * * 注意:这里使用动态 import() 导入 WASM 模块。 * Vite 在构建时会自动为 WASM 文件和 JS glue 代码添加 hash(如 avatar_core_wasm-CxWuw7eS.wasm), * 确保浏览器缓存与版本一致,不会有缓存问题。 * * Hash 的作用机制: * - WASM 文件内容变化 → hash 自动变化 → URL 变化 → 浏览器拉取新版本 * - WASM 文件内容不变 → hash 保持不变 → URL 不变 → 浏览器使用缓存 * - Emscripten 生成的 JS 内部会使用 hard-coded 的 hash 路径加载 .wasm 文件 */ async loadWASMModule() { try { const { default: e } = await import("./avatar_core_wasm-BPIbbUx_.js"); this.wasmConfig && Object.keys(this.wasmConfig).length > 0 ? this.wasmModule = await e(this.wasmConfig) : this.wasmModule = await e(), this.validateWASMModule(), this.memoryManager = new Yn(this.wasmModule), this.setupCAPIFunctions(), h.log("✅ Created new WASM instance with clean C++ memory"); } catch (e) { const t =