/** * Collects every three.js AnimationMixer the page creates (its constructor assigns `_actionsByClip`), the same * Object.prototype-setter trick browser.ts uses for scenes and cameras. Installed as an extra init script. */ export declare const MIXER_HOOK = "(() => {\n if (globalThis.__vqeMixers) return;\n const list = []; globalThis.__vqeMixers = list;\n try {\n Object.defineProperty(Object.prototype, '_actionsByClip', {\n configurable: true, enumerable: false,\n set(v) {\n try { Object.defineProperty(this, '_actionsByClip', { value: v, writable: true, configurable: true, enumerable: true }); } catch (e) {}\n if (this && typeof this.clipAction === 'function' && !list.includes(this)) list.push(this);\n },\n get() { return undefined; },\n });\n } catch (e) {}\n})();"; /** * Installs `globalThis.__vqe` in the frame. Requires INSTALL_SCENE_STATS (commonAsserts.ts) and INSTALL_VIEWER_PAGE * (viewerPage.ts) to be installed first. */ export declare const INSTALL_EMOTE_PAGE = "globalThis.__vqe = (function () {\n const r4 = (v) => Math.round(v * 10000) / 10000;\n const fresh = () => ({ mixer: null, action: null, root: null, meshes: [], restPts: null, restBox: null, restHeight: 0, ptsAt0: null, duration: 0 });\n /** One state per performer: 'main' (the viewer's body) and 'partner' (the companion body of a two-person emote). */\n const T = {};\n let S = fresh();\n function use(key) { if (!T[key]) return false; S = T[key]; return true; }\n const scene = () => (globalThis.__vqa && globalThis.__vqa.scene) || null;\n const chainVisible = (o) => { for (let p = o; p; p = p.parent) if (p.visible === false) return false; return true; };\n const isUnder = (o, root) => { for (let p = o; p; p = p.parent) if (p === root) return true; return false; };\n\n /** Every mixer's actions, for the facts. */\n function inventory() {\n const out = [];\n for (const m of (globalThis.__vqeMixers || [])) {\n const root = m.getRoot && m.getRoot();\n let skinned = 0; if (root && root.traverse) root.traverse((o) => { if (o.isSkinnedMesh) skinned++; });\n const acts = [];\n for (const a of (m._actions || [])) {\n const c = a.getClip();\n acts.push({ name: c.name, duration: r4(c.duration), tracks: c.tracks.length, weight: r4(a.getEffectiveWeight()), enabled: a.enabled, paused: a.paused, running: a.isRunning(), time: r4(a.time), loop: a.loop });\n }\n out.push({ root: root ? (root.name || root.type) : null, skinned, timeScale: m.timeScale, actions: acts });\n }\n return out;\n }\n\n /**\n * Find the action playing the pinned clip: same duration (\u00B10.05 s) and, when several match, the same name, then the\n * most tracks. Remembers the mixer, the action and the avatar root it drives.\n */\n function locate(name, duration, key, notMixer) {\n let best = null;\n const taken = new Set(Object.values(T).map((t) => t.mixer));\n for (const m of (globalThis.__vqeMixers || [])) {\n if (taken.has(m) && !(T[key] && T[key].mixer === m)) continue;\n for (const a of (m._actions || [])) {\n const c = a.getClip();\n if (Math.abs(c.duration - duration) > 0.05) continue;\n const score = (c.name === name ? 1000 : 0) + c.tracks.length;\n if (!best || score > best.score) best = { m, a, score };\n }\n }\n if (!best) return null;\n key = key || 'main';\n S = T[key] = fresh();\n S.duration = best.a.getClip().duration;\n S.mixer = best.m; S.action = best.a; S.root = best.m.getRoot();\n S.meshes = []; S.root.traverse((o) => { if (o.isSkinnedMesh && o.geometry) S.meshes.push(o); });\n return { clip: best.a.getClip().name, duration: r4(best.a.getClip().duration), tracks: best.a.getClip().tracks.length, skinnedMeshes: S.meshes.length, root: S.root.name || S.root.type };\n }\n\n /** How many of the clip's tracks resolved to a node of the avatar (an unresolved track animates nothing). */\n function binding() {\n const a = S.action; if (!a) return null;\n const clip = a.getClip();\n const pms = a._propertyBindings || [];\n let bound = 0; const unbound = [];\n for (let i = 0; i < pms.length; i++) {\n const b = pms[i] && pms[i].binding;\n if (b && b.node) bound++; else if (unbound.length < 12) unbound.push(clip.tracks[i] ? clip.tracks[i].name : String(i));\n }\n // Track data must be finite: a NaN/Infinity key explodes the skin the moment it is sampled.\n let nonFinite = 0; let quatOff = 0; let maxPos = 0;\n for (const t of clip.tracks) {\n const v = t.values; let bad = false;\n for (let i = 0; i < v.length; i++) { if (!Number.isFinite(v[i])) { bad = true; break; } }\n if (bad) { nonFinite++; continue; }\n if (/\\.quaternion$/.test(t.name)) {\n for (let i = 0; i + 3 < v.length; i += 4) { const l = Math.hypot(v[i], v[i + 1], v[i + 2], v[i + 3]); if (Math.abs(l - 1) > 0.05) { quatOff++; break; } }\n } else if (/\\.position$/.test(t.name)) {\n for (let i = 0; i < v.length; i++) maxPos = Math.max(maxPos, Math.abs(v[i]));\n }\n }\n return { tracks: clip.tracks.length, bindings: pms.length, bound, unbound, nonFiniteTracks: nonFinite, unnormalisedQuatTracks: quatOff, maxPositionKey: r4(maxPos) };\n }\n\n const meshRef = (m) => {\n const g = m.geometry; const pos = g.attributes.position; const idx = g.index ? g.index.array : null;\n const n = idx ? idx.length : pos.count;\n const start = (g.drawRange && g.drawRange.start) || 0;\n const count = Math.min(n - start, (g.drawRange && Number.isFinite(g.drawRange.count)) ? g.drawRange.count : n);\n const used = new Set();\n if (idx) { for (let k = start; k < start + count; k++) used.add(idx[k]); } else { for (let k = start; k < start + count; k++) used.add(k); }\n return { m, pos, used: [...used].sort((a, b) => a - b) };\n };\n\n /** Fixed-index sample of the drawn vertices (world space). skinned=true applies the CURRENT pose; false = bind pose. */\n function samplePoints(maxPoints, skinned) {\n const refs = S.meshes.filter(chainVisible).map(meshRef);\n let total = 0; for (const r of refs) total += r.used.length;\n const step = Math.max(1, Math.ceil(total / maxPoints));\n const out = []; let nonFinite = 0;\n for (const { m, pos, used } of refs) {\n const e = m.matrixWorld.elements;\n const tmp = new (m.position.constructor)();\n for (let j = 0; j < used.length; j += step) {\n const i = used[j];\n let x, y, z;\n if (skinned) { m.getVertexPosition(i, tmp); x = tmp.x; y = tmp.y; z = tmp.z; } else { x = pos.getX(i); y = pos.getY(i); z = pos.getZ(i); }\n if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z)) { nonFinite++; out.push(NaN, NaN, NaN); continue; }\n out.push(e[0] * x + e[4] * y + e[8] * z + e[12], e[1] * x + e[5] * y + e[9] * z + e[13], e[2] * x + e[6] * y + e[10] * z + e[14]);\n }\n }\n return { pts: out, nonFinite };\n }\n const boxOf = (pts) => {\n const mn = [Infinity, Infinity, Infinity], mx = [-Infinity, -Infinity, -Infinity];\n for (let i = 0; i + 2 < pts.length; i += 3) for (let k = 0; k < 3; k++) { const v = pts[i + k]; if (!Number.isFinite(v)) continue; if (v < mn[k]) mn[k] = v; if (v > mx[k]) mx[k] = v; }\n if (mn[0] > mx[0]) return null;\n return { min: mn.map(r4), max: mx.map(r4), size: mx.map((v, k) => r4(v - mn[k])) };\n };\n\n /** The avatar's own bind pose: bounds of the geometry as authored, the reference every pose is judged against. */\n function rest() {\n const s = scene(); if (s) s.updateMatrixWorld(true);\n const { pts } = samplePoints(5000, false);\n S.restPts = pts; S.restBox = boxOf(pts);\n S.restHeight = S.restBox ? Math.max(S.restBox.size[1], 1e-6) : 0;\n return { box: S.restBox, height: S.restHeight, skeletonBones: (S.meshes[0] && S.meshes[0].skeleton ? S.meshes[0].skeleton.bones.length : 0) };\n }\n\n /** Freeze the page's clock: every mixer stops; on each performer only the pinned clip's action stays on, paused at its own time. */\n function freeze() {\n for (const m of (globalThis.__vqeMixers || [])) m.timeScale = 0;\n for (const key of Object.keys(T)) {\n const m = T[key].mixer, a = T[key].action;\n for (const o of (m._actions || [])) { if (o !== a) { o.enabled = false; } }\n a.enabled = true; a.setEffectiveWeight(1); a.setEffectiveTimeScale(1); a.paused = true;\n }\n return Object.keys(T);\n }\n\n /** Seek every performer to the same FRACTION of its own clip (no measuring): what a frame shows. */\n function seekAll(f) {\n for (const key of Object.keys(T)) { const t = T[key]; t.action.time = f * t.duration; t.mixer.update(0); }\n const s = scene(); if (s) s.updateMatrixWorld(true);\n for (const key of Object.keys(T)) for (const mesh of T[key].meshes) if (mesh.skeleton) mesh.skeleton.update();\n return true;\n }\n\n /** Bone names of the performer's skeleton. */\n function boneNames() { const out = []; for (const m of S.meshes) if (m.skeleton) for (const b of m.skeleton.bones) if (b && b.name && !out.includes(b.name)) out.push(b.name); return out; }\n\n /** Rotation (degrees) of bone skinning transform i against bind: angle of bindMatrixInverse * (bone.matrixWorld * boneInverse) * bindMatrix. */\n function skinAngles() {\n const out = []; const s = scene(); if (s) s.updateMatrixWorld(true);\n for (const m of S.meshes) {\n const sk = m.skeleton; if (!sk) continue;\n const M4 = m.matrixWorld.constructor; const Q = m.quaternion.constructor; const V = m.position.constructor;\n const bi = m.bindMatrixInverse, bm = m.bindMatrix;\n const q = new Q(), p = new V(), sc = new V(); const t = new M4();\n for (let i = 0; i < sk.bones.length; i++) {\n const bone = sk.bones[i]; if (!bone || !sk.boneInverses[i]) continue;\n t.multiplyMatrices(bone.matrixWorld, sk.boneInverses[i]); t.premultiply(bi); t.multiply(bm);\n t.decompose(p, q, sc);\n const w = Math.min(1, Math.abs(q.w));\n const ang = 2 * Math.acos(w) * 180 / Math.PI;\n out.push({ bone: bone.name, deg: Number.isFinite(ang) ? ang : NaN, move: Math.hypot(p.x, p.y, p.z) });\n }\n }\n return out;\n }\n\n /** Seek the clip to t seconds and measure the avatar as drawn. */\n function poseAt(t) {\n const m = S.mixer, a = S.action; if (!m || !a) return null;\n a.time = t; m.update(0);\n const s = scene(); if (s) s.updateMatrixWorld(true);\n for (const mesh of S.meshes) if (mesh.skeleton) { mesh.skeleton.update(); }\n const { pts, nonFinite } = samplePoints(5000, true);\n const box = boxOf(pts);\n let maxMove = 0; let sumMove = 0; let nMove = 0;\n if (S.ptsAt0 && S.ptsAt0.length === pts.length) {\n for (let i = 0; i + 2 < pts.length; i += 3) {\n const d = Math.hypot(pts[i] - S.ptsAt0[i], pts[i + 1] - S.ptsAt0[i + 1], pts[i + 2] - S.ptsAt0[i + 2]);\n if (Number.isFinite(d)) { if (d > maxMove) maxMove = d; sumMove += d; nMove++; }\n }\n }\n // Farthest drawn vertex from the avatar's own hips-height centre: an exploded skin throws vertices metres away.\n const cx = S.restBox ? (S.restBox.min[0] + S.restBox.max[0]) / 2 : 0, cz = S.restBox ? (S.restBox.min[2] + S.restBox.max[2]) / 2 : 0;\n let far = 0; for (let i = 0; i + 2 < pts.length; i += 3) { const d = Math.hypot(pts[i] - cx, pts[i + 2] - cz); if (Number.isFinite(d) && d > far) far = d; }\n // Vertex-versus-rest displacement (bind pose) \u2014 how far the pose is from the T/A-pose it started as.\n let restDisp = 0; let restSum = 0; let restN = 0;\n if (S.restPts && S.restPts.length === pts.length) {\n for (let i = 0; i + 2 < pts.length; i += 3) {\n const d = Math.hypot(pts[i] - S.restPts[i], pts[i + 1] - S.restPts[i + 1], pts[i + 2] - S.restPts[i + 2]);\n if (Number.isFinite(d)) { if (d > restDisp) restDisp = d; restSum += d; restN++; }\n }\n }\n const angs = skinAngles().map((x) => x.deg).filter(Number.isFinite).sort((x, y) => x - y);\n const q = (f) => angs.length ? angs[Math.min(angs.length - 1, Math.floor(f * angs.length))] : 0;\n return { t: r4(t), box, nonFinite, maxMoveFromStart: r4(maxMove), meanMoveFromStart: r4(nMove ? sumMove / nMove : 0),\n maxFromRest: r4(restDisp), meanFromRest: r4(restN ? restSum / restN : 0), farHorizontal: r4(far),\n bones: angs.length, angleP50: r4(q(0.5)), angleP90: r4(q(0.9)), angleMax: r4(angs.length ? angs[angs.length - 1] : 0) };\n }\n\n /** Remember the pose at t = 0 as the reference for \"how far has it moved\". */\n function mark0() { const p = poseAt(0); S.ptsAt0 = samplePoints(5000, true).pts; return p; }\n\n /** Skinned-mesh stats of the avatar as it stands now (materials, textures, drawn bounds) for the shared asserts. */\n function avatarStats() {\n const s = scene(); if (s) s.updateMatrixWorld(true);\n const list = S.meshes.filter(chainVisible);\n const fake = { updateMatrixWorld() {}, traverse(cb) { for (const m of list) cb(m); } };\n return globalThis.__vqaStats(fake);\n }\n\n /** The page's own \"clip could not be applied\" banner and \"animation unavailable\" states. */\n function pageNotices() {\n const t = (document.body && document.body.innerText) || '';\n return { shownStatic: /Shown static/i.test(t), unavailable: /Animation unavailable/i.test(t), loading: /Loading animation/i.test(t) };\n }\n\n return { inventory, locate, use, boneNames, seekAll, binding, rest, freeze, poseAt, mark0, avatarStats, pageNotices,\n meshCount: () => S.meshes.length, root: () => (S.root ? (S.root.name || S.root.type) : null) };\n})();";