/** * Init script (before any page script): every three.js AnimationMixer assigns `_accuIndex` as an own property in its * constructor, so an Object.prototype setter sees each one in any bundle, minified or not (the same trick browser.ts * uses for scenes and renderers). */ export declare const MIXER_HOOK = "(() => {\n if (globalThis.__vqaMixers) return;\n const list = []; globalThis.__vqaMixers = list;\n try {\n Object.defineProperty(Object.prototype, '_accuIndex', {\n configurable: true, enumerable: false,\n set(v) {\n try { Object.defineProperty(this, '_accuIndex', { value: v, writable: true, configurable: true, enumerable: true }); } catch (e) {}\n try { if (this && typeof this.clipAction === 'function' && typeof this.setTime === 'function' && !list.includes(this)) list.push(this); } catch (e) {}\n },\n get() { return undefined; },\n });\n } catch (e) {}\n})();"; export declare const INSTALL_AVATAR_PREVIEW_PROBE = "(() => {\n const G = globalThis;\n if (G.__vqaAp) return true;\n const A = {};\n const H = () => G.__vqa || {};\n /** The drawn avatar: the main scene's largest set of skinned meshes on a skeleton with a pelvis. */\n A.locate = () => {\n const scenes = [];\n if (H().scene) scenes.push(H().scene);\n for (const s of H().scenes || []) if (!scenes.includes(s)) scenes.push(s);\n for (const s of scenes) {\n const sk = [];\n try { s.traverse((o) => { if (o.isSkinnedMesh && o.skeleton && o.geometry && o.geometry.attributes && o.geometry.attributes.position) sk.push(o); }); } catch (e) { continue; }\n if (!sk.some((m) => m.skeleton.bones.some((b) => b.name === 'pelvis'))) continue;\n const bone = sk[0].skeleton.bones.find((b) => !(b.parent && b.parent.isBone)) || sk[0].skeleton.bones[0];\n let root = bone.parent || bone;\n while (root.parent && !root.parent.isScene && root.parent.children.length === 1) root = root.parent;\n return { scene: s, meshes: sk, root };\n }\n return null;\n };\n A.state = () => {\n const L = A.locate();\n const mixers = (G.__vqaMixers || []).filter((m) => L && A.drives(m, L));\n const acts = mixers.flatMap((m) => (m._actions || []).filter((a) => a && a.enabled !== false && a._clip));\n // The clip the viewer is PLAYING (the walk); idle/run actions are bound but not running.\n const running = acts.filter((a) => (a.isRunning ? a.isRunning() : true) && (a.getEffectiveWeight ? a.getEffectiveWeight() > 0 : true));\n const dur = running.length ? Math.max(...running.map((a) => a._clip.duration || 0)) : 0;\n const mount = typeof document !== 'undefined' ? document.querySelector('[data-avatar-dynamics-chains]') : null;\n return { found: !!L, meshes: L ? L.meshes.length : 0, verts: L ? L.meshes.reduce((s, m) => s + m.geometry.attributes.position.count, 0) : 0,\n mixers: mixers.length, allMixers: (G.__vqaMixers || []).length, actions: acts.map((a) => ({ clip: a._clip.name, duration: a._clip.duration, weight: a.getEffectiveWeight ? a.getEffectiveWeight() : null, running: a.isRunning ? a.isRunning() : null })),\n clip: running.length ? running[0]._clip.name : null, duration: dur, dynamicsChains: mount ? Number(mount.getAttribute('data-avatar-dynamics-chains')) : null, frames: H().frames || 0 };\n };\n /** A mixer drives the avatar when its root is the avatar, one of its ancestors, or one of its bones/meshes. */\n A.drives = (m, L) => {\n const r = m._root || (m.getRoot && m.getRoot()); if (!r) return false;\n for (let p = L.meshes[0]; p; p = p.parent) if (p === r) return true;\n let inside = false; try { L.root.traverse((o) => { if (o === r) inside = true; }); } catch (e) {}\n return inside;\n };\n A.mixers = () => { const L = A.locate(); return L ? (G.__vqaMixers || []).filter((m) => A.drives(m, L)) : []; };\n /** Hold the clip at t seconds (the page keeps rendering and the dynamics keep stepping on the held pose). */\n A.hold = (t) => { const ms = A.mixers(); for (const m of ms) { m.timeScale = 1; m.setTime(t); m.timeScale = 0; } return ms.length; };\n A.resume = () => { for (const m of A.mixers()) m.timeScale = 1; return true; };\n A.basis = () => {\n const L = A.locate(); const r = L.root; r.updateMatrixWorld(true);\n const V = r.position.constructor, Q = r.quaternion.constructor;\n const q = r.getWorldQuaternion(new Q()); const f = new V(0, 0, 1).applyQuaternion(q); f.y = 0;\n if (f.length() < 1e-6) f.set(0, 0, 1); f.normalize();\n const up = new V(0, 1, 0); const l = new V().crossVectors(up, f).normalize();\n return { o: r.getWorldPosition(new V()), f, l, up, V, L };\n };\n A.toWorld = (p, B) => { B = B || A.basis(); return new B.V(B.o.x + B.l.x * p[0] + B.f.x * p[2], B.o.y + p[1], B.o.z + B.l.z * p[0] + B.f.z * p[2]); };\n const b64 = (ta) => { const u8 = new Uint8Array(ta.buffer, ta.byteOffset, ta.byteLength); let s = ''; for (let i = 0; i < u8.length; i += 0x8000) s += String.fromCharCode.apply(null, u8.subarray(i, i + 0x8000)); return btoa(s); };\n /** The meshes to read: every visible skinned mesh, one entry per distinct position buffer (a face mesh that shares\n * the body's buffer contributes only its triangles). */\n A.layout = () => {\n const L = A.locate(); const vis = (o) => { for (let p = o; p; p = p.parent) { if (p.visible === false) return false; if (p === L.scene) break; } return true; };\n const all = L.meshes.filter(vis);\n const hosts = []; const hostOf = new Map();\n for (const o of all) { const arr = o.geometry.attributes.position.array; const h = hosts.find((x) => x.geometry.attributes.position.array === arr); if (h) hostOf.set(o, h); else { hosts.push(o); hostOf.set(o, o); } }\n const offs = new Map(); let nv = 0; for (const h of hosts) { offs.set(h, nv); nv += h.geometry.attributes.position.count; }\n return { L, all, hosts, hostOf, offs, nv };\n };\n /** Rest (bind-pose) geometry, topology, skin weights and the skeleton's bind pose, once. */\n A.rest = () => {\n const Y = A.layout(); const { L, all, hosts, hostOf, offs, nv } = Y;\n const V = L.root.position.constructor; const M4 = L.root.matrixWorld.constructor;\n const names = []; const ix = new Map(); const id = (b) => { if (!ix.has(b)) { ix.set(b, names.length); names.push(b.name); } return ix.get(b); };\n const rest = new Float32Array(nv * 3); const si = new Uint16Array(nv * 4); const sw = new Float32Array(nv * 4); const v = new V();\n for (const h of hosts) {\n const o = offs.get(h); const g = h.geometry; const pos = g.attributes.position; const S = g.attributes.skinIndex, W = g.attributes.skinWeight;\n for (let i = 0; i < pos.count; i++) {\n v.fromBufferAttribute(pos, i).applyMatrix4(h.bindMatrix); rest[(o + i) * 3] = v.x; rest[(o + i) * 3 + 1] = v.y; rest[(o + i) * 3 + 2] = v.z;\n for (let k = 0; k < 4; k++) { const w = W ? W.getComponent(i, k) : 0; sw[(o + i) * 4 + k] = w; si[(o + i) * 4 + k] = S ? id(h.skeleton.bones[S.getComponent(i, k)] || h.skeleton.bones[0]) : 0; }\n }\n }\n const idx = [];\n for (const m of all) {\n const h = hostOf.get(m); const o = offs.get(h); const g = m.geometry; const n = g.attributes.position.count;\n const ii = g.index ? g.index.array : null; const len = ii ? ii.length : n;\n const groups = g.groups && g.groups.length ? g.groups : [{ start: 0, count: len }];\n for (const gr of groups) for (let t = gr.start; t + 2 < Math.min(len, gr.start + gr.count); t += 3) {\n const a = ii ? ii[t] : t, b = ii ? ii[t + 1] : t + 1, c = ii ? ii[t + 2] : t + 2;\n if (a !== b && b !== c && a !== c) idx.push(a + o, b + o, c + o);\n }\n }\n const bind = new Array(names.length).fill(null);\n for (const h of hosts) h.skeleton.bones.forEach((b, i) => { const k = ix.get(b); if (k !== undefined && !bind[k]) bind[k] = Array.from(new M4().copy(h.skeleton.boneInverses[i]).invert().premultiply(h.bindMatrix).elements); });\n L.root.traverse((o) => { if (o.isBone) id(o); });\n const parents = names.map(() => -1); for (const [b, i] of ix) if (b.parent && ix.has(b.parent)) parents[i] = ix.get(b.parent);\n A.__bones = [...ix.keys()];\n const meshesInfo = all.map((m) => ({ name: m.name, verts: m.geometry.attributes.position.count, shared: hostOf.get(m) !== m }));\n // Nodes the avatar's VRM node constraints drive (the GLB's `helixConstraints` extras, which the loader keeps in userData):\n // a robot arm that copies the body's arm is a limb that follows its source, not an accessory standing off the torso.\n const cn = new Set();\n const scan = (o) => { try { const c = o && o.userData && o.userData.helixConstraints; if (c && Array.isArray(c.constraints)) for (const e of c.constraints) if (e && typeof e.node === 'string') cn.add(e.node); } catch (e) {} };\n for (let p = L.root; p; p = p.parent) scan(p);\n try { L.scene.traverse(scan); } catch (e) {}\n return { nv, nt: idx.length / 3, meshes: meshesInfo, boneNames: names, parents, bind, rest: b64(rest), index: b64(new Uint32Array(idx)), skinIndex: b64(si), skinWeight: b64(sw), constraintNodes: [...cn].slice(0, 256) };\n };\n /** Posed vertices (body frame) and every bone's world matrix (body frame), at the pose currently drawn. */\n A.posed = () => {\n const Y = A.layout(); const { L, hosts, offs, nv } = Y; const B = A.basis(); const V = B.V; const v = new V();\n L.scene.updateMatrixWorld(true);\n const out = new Float32Array(nv * 3);\n for (const h of hosts) {\n h.skeleton.update(); const o = offs.get(h); const e = h.matrixWorld.elements; const n = h.geometry.attributes.position.count;\n for (let i = 0; i < n; i++) {\n h.getVertexPosition(i, v);\n const wx = e[0] * v.x + e[4] * v.y + e[8] * v.z + e[12], wy = e[1] * v.x + e[5] * v.y + e[9] * v.z + e[13], wz = e[2] * v.x + e[6] * v.y + e[10] * v.z + e[14];\n const dx = wx - B.o.x, dy = wy - B.o.y, dz = wz - B.o.z;\n out[(o + i) * 3] = dx * B.l.x + dz * B.l.z; out[(o + i) * 3 + 1] = dy; out[(o + i) * 3 + 2] = dx * B.f.x + dz * B.f.z;\n }\n }\n // body-frame matrix: columns l, up, f, origin o (world = Mb * body) -> body = Mb^-1 * world\n const M4 = L.root.matrixWorld.constructor;\n const Mb = new M4().set(B.l.x, 0, B.f.x, B.o.x, B.l.y, 1, B.f.y, B.o.y, B.l.z, 0, B.f.z, B.o.z, 0, 0, 0, 1); const inv = Mb.clone().invert();\n const bones = (A.__bones || []).map((b) => Array.from(new M4().multiplyMatrices(inv, b.matrixWorld).elements));\n return { positions: b64(out), bones };\n };\n /** Pin the drawn camera to a body-frame pose, re-applied every frame (after the page's OrbitControls). */\n A.setCam = (c) => {\n const cam = H().main; if (!cam) return false;\n if (!cam.__vqaApPinned) {\n const orig = cam.updateMatrixWorld.bind(cam);\n cam.updateMatrixWorld = function (force) {\n const o = G.__vqaApCam;\n if (o) {\n try {\n const B = A.basis(); this.position.copy(A.toWorld(o.pos, B)); this.up.set(0, 1, 0); this.lookAt(A.toWorld(o.target, B));\n if (o.fov && this.fov !== o.fov) { this.fov = o.fov; this.updateProjectionMatrix(); }\n if (o.near && this.near !== o.near) { this.near = o.near; this.updateProjectionMatrix(); }\n } catch (e) { /* never break the render */ }\n }\n return orig(force);\n };\n cam.__vqaApPinned = { fov: cam.fov, near: cam.near };\n }\n G.__vqaApCam = c; return { aspect: cam.aspect || null, fov: cam.fov || null };\n };\n A.aspect = () => { const cam = H().main; return cam ? { aspect: cam.aspect || null, fov: cam.fov || null } : null; };\n /** Mark the drawn canvas so the harness can screenshot exactly it. */\n A.markCanvas = () => {\n const draws = [...((H().draws) || new Map()).values()].filter((d) => d.camera === H().main && d.canvas);\n const c = draws.length ? draws[0].canvas : (typeof document !== 'undefined' ? document.querySelector('canvas') : null);\n if (!c) return null; c.setAttribute('data-vqa-preview-canvas', '1'); const r = c.getBoundingClientRect(); return { w: r.width, h: r.height };\n };\n A.frames = (n) => new Promise((res) => { const f0 = H().frames || 0; let k = 0; const tick = () => { if (++k >= n) res((H().frames || 0) - f0); else requestAnimationFrame(tick); }; requestAnimationFrame(tick); });\n G.__vqaAp = A;\n return true;\n})()";