export declare const INSTALL_AVATAR_PROBE = "(() => {\n const G = globalThis;\n if (G.__vqaAv) return true;\n const A = {};\n A.mp = () => G.__assetGym.mp;\n A.model = () => A.mp().local.model;\n A.V = () => A.model().position.constructor;\n A.Q = () => A.model().quaternion.constructor;\n A.camera = () => A.mp().local.services.camera.camera;\n A.visible = (o, root) => { for (let p = o; p; p = p.parent) { if (p.visible === false) return false; if (p === root) break; } return true; };\n A.bone = (name) => { let r = null; A.model().traverse((o) => { if (!r && o.isBone && o.name === name) r = o; }); return r; };\n /** Body frame: engine forward = the model's local +Z, flattened to the ground. */\n A.basis = () => {\n const m = A.model(); m.updateMatrixWorld(true);\n const V = A.V(), Q = A.Q();\n const q = m.getWorldQuaternion(new Q());\n const f = new V(0, 0, 1).applyQuaternion(q); f.y = 0;\n if (f.length() < 1e-6) f.set(0, 0, 1);\n f.normalize();\n const up = new V(0, 1, 0);\n const l = new V().crossVectors(up, f).normalize();\n const o = m.getWorldPosition(new V());\n return { o, f, l, up };\n };\n A.toBody = (w, B) => { B = B || A.basis(); const V = A.V(); const d = new V(w.x - B.o.x, w.y - B.o.y, w.z - B.o.z); return [d.dot(B.l), d.y, d.dot(B.f)]; };\n A.toWorld = (p, B) => { B = B || A.basis(); const V = A.V(); return new 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 A.bonesBody = (names) => {\n const out = {}; const B = A.basis(); const V = A.V();\n for (const n of names) { const b = A.bone(n); if (b) out[n] = A.toBody(b.getWorldPosition(new V()), B).map((v) => Math.round(v * 10000) / 10000); }\n return out;\n };\n /** Drawn vertices of the model in BODY frame (skinned vertices are posed), at most ~maxN, flat. */\n A.points = (maxN) => {\n const m = A.model(); m.updateMatrixWorld(true);\n const B = A.basis(); const V = A.V(); const tmp = new V();\n const meshes = [];\n let total = 0;\n m.traverse((o) => {\n if (!o.isMesh || !o.geometry || !o.geometry.attributes || !o.geometry.attributes.position) return;\n if (!A.visible(o, m)) return;\n const ms = Array.isArray(o.material) ? o.material : [o.material];\n if (ms.every((x) => !x || x.visible === false || (x.transparent && (x.opacity ?? 1) < 0.02) || x.colorWrite === false)) return;\n meshes.push(o); total += o.geometry.attributes.position.count;\n });\n const step = Math.max(1, Math.floor(total / (maxN || 60000)));\n const out = [];\n for (const o of meshes) {\n if (o.isSkinnedMesh && o.skeleton) o.skeleton.update();\n const pos = o.geometry.attributes.position; const e = o.matrixWorld.elements;\n const skinned = o.isSkinnedMesh && typeof o.getVertexPosition === 'function';\n for (let i = 0; i < pos.count; i += step) {\n let x, y, z;\n if (skinned) { o.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 + y + z)) continue;\n const wx = e[0] * x + e[4] * y + e[8] * z + e[12], wy = e[1] * x + e[5] * y + e[9] * z + e[13], wz = e[2] * x + e[6] * y + e[10] * z + e[14];\n const dx = wx - B.o.x, dy = wy - B.o.y, dz = wz - B.o.z;\n out.push(dx * B.l.x + dz * B.l.z, dy, dx * B.f.x + dz * B.f.z);\n }\n }\n return out;\n };\n /** What the avatar is made of, for the facts block: meshes by LOD, skeleton size, materials. */\n A.describe = () => {\n const m = A.model(); const out = { root: m.name, skinned: [], bones: 0, lod: null, helixBodyHeight: m.userData && m.userData.helixBodyHeight || null, helixFace: !!(m.userData && m.userData.helixFace) };\n m.traverse((o) => {\n if (o.isBone) out.bones++;\n if (o.isSkinnedMesh) {\n const ms = Array.isArray(o.material) ? o.material : [o.material]; const mt = ms[0] || {};\n out.skinned.push({ name: o.name, verts: o.geometry.attributes.position.count, visible: A.visible(o, m), bones: o.skeleton ? o.skeleton.bones.length : 0,\n material: { type: mt.type, name: mt.name, map: !!mt.map, normalMap: !!mt.normalMap, emissiveMap: !!mt.emissiveMap, color: mt.color && mt.color.getHexString && mt.color.getHexString() } });\n }\n });\n const lod = m.getObjectByName('character-lod'); if (lod && lod.getCurrentLevel) out.lod = lod.getCurrentLevel();\n return out;\n };\n /** Pin the render camera to a body-frame pose, re-applied every frame so the follow cam cannot fight it. */\n A.setCam = (c) => {\n const cam = A.camera(); if (!cam) return false;\n if (!cam.__vqaPinned) {\n const orig = cam.updateMatrixWorld.bind(cam);\n cam.updateMatrixWorld = function (force) {\n // A frozen stride (A.freeze) is re-applied here, after the engine's mixer has posed the bones for this frame and\n // before the renderer skins the meshes, so the pinned camera sees the held pose while the engine keeps running.\n if (G.__vqaFrozen) { try { A.applyFrozen(); } catch (e) { /* never break the render */ } }\n const o = G.__vqaCam;\n if (o) {\n const B = A.basis();\n this.position.copy(A.toWorld(o.pos, B));\n this.up.set(0, 1, 0);\n 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 }\n return orig(force);\n };\n cam.__vqaPinned = { fov: cam.fov, near: cam.near };\n }\n G.__vqaCam = c; return true;\n };\n A.clearCam = () => { G.__vqaCam = null; const cam = A.camera(); if (cam && cam.__vqaPinned) { cam.fov = cam.__vqaPinned.fov; cam.near = cam.__vqaPinned.near; cam.updateProjectionMatrix(); } return true; };\n A.stats = () => G.__vqaStats(A.model());\n A.materialsOf = () => {\n const m = A.model(); const mats = new Set();\n m.traverse((o) => { if (o.isMesh) for (const mt of (Array.isArray(o.material) ? o.material : [o.material])) if (mt) mats.add(mt); });\n return mats;\n };\n /** Every drawn primitive's material: does it exist, which maps it samples and whether each decoded, how much it emits\n * without an emissive map, and how many triangles it covers. The ground truth for the material asserts. */\n A.materials = () => {\n const m = A.model(); const rows = []; let tris = 0;\n const SLOTS = ['map', 'normalMap', 'emissiveMap', 'roughnessMap', 'metalnessMap', 'aoMap', 'alphaMap'];\n const decoded = (t) => {\n if (!t) return null;\n const img = t.image; const mips = t.mipmaps;\n if (t.isCompressedTexture || (mips && mips.length && mips[0] && mips[0].data)) return !!(mips && mips.length && mips[0] && mips[0].data && mips[0].data.length) || !!(img && img.width > 0);\n if (img && (img.width > 0 || img.videoWidth > 0 || (img.data && img.data.length))) return true;\n return false;\n };\n m.traverse((o) => {\n if (!o.isMesh || !o.geometry || !A.visible(o, m)) return;\n const g = o.geometry; const pos = g.attributes && g.attributes.position; if (!pos) return;\n const n = Math.floor((g.index ? g.index.count : pos.count) / 3);\n const groups = Array.isArray(o.material) && g.groups && g.groups.length ? g.groups : null;\n const ms = Array.isArray(o.material) ? o.material : [o.material];\n ms.forEach((mt, i) => {\n const t = groups ? Math.floor((groups.filter((gr) => gr.materialIndex === i).reduce((s, gr) => s + Math.min(gr.count, (g.index ? g.index.count : pos.count)), 0)) / 3) : (i === 0 ? n : 0);\n tris += t;\n if (!mt) { rows.push({ mesh: o.name || o.uuid.slice(0, 8), material: null, tris: t, missing: true }); return; }\n if (mt.visible === false || mt.colorWrite === false || (mt.transparent && (mt.opacity ?? 1) < 0.02)) { tris -= t; return; }\n const maps = {}; for (const k of SLOTS) { const d = decoded(mt[k]); if (d !== null) maps[k] = d; }\n const e = mt.emissive ? Math.max(mt.emissive.r, mt.emissive.g, mt.emissive.b) * (mt.emissiveIntensity ?? 1) : 0;\n rows.push({ mesh: o.name || o.uuid.slice(0, 8), material: mt.name || mt.type, type: mt.type, tris: t, maps, emissive: Math.round(e * 1000) / 1000,\n color: mt.color && mt.color.getHexString ? mt.color.getHexString() : null, metalness: mt.metalness ?? null, unlit: mt.type === 'MeshBasicMaterial' });\n });\n });\n return { tris, rows };\n };\n /** Re-shade the avatar for one diagnostic frame, then restore it exactly. 'albedo': unlit base colour (base colour x map\n * routed through emission, no lighting); 'mask': flat magenta on EVERY drawn material, whatever its class, to find the\n * avatar's pixels; 'restore': the original. */\n A.shade = (mode) => {\n let n = 0;\n for (const mt of A.materialsOf()) {\n if (mode === 'restore') {\n // Undo in the order they were applied: the flat mask pass (if any) sat on top of the albedo pass.\n const F = mt.__vqaFlat;\n if (F) { A.flatRestore(mt, F); delete mt.__vqaFlat; mt.needsUpdate = true; n++; }\n const S = mt.__vqaSaved;\n if (S) {\n for (const k of Object.keys(S.props)) mt[k] = S.props[k];\n if (mt.color && S.color) mt.color.copy(S.color); if (mt.emissive && S.emissive) mt.emissive.copy(S.emissive);\n delete mt.__vqaSaved; mt.needsUpdate = true; n++;\n }\n continue;\n }\n if (mode === 'mask') { if (!mt.__vqaFlat) { mt.__vqaFlat = A.flatSave(mt); A.flatApply(mt); mt.needsUpdate = true; n++; } continue; }\n if (!mt.emissive || !mt.color) continue; // not a lit standard material (unlit/basic): leave it as drawn\n if (!mt.__vqaSaved) mt.__vqaSaved = { props: { map: mt.map, emissiveMap: mt.emissiveMap, emissiveIntensity: mt.emissiveIntensity, metalness: mt.metalness, roughness: mt.roughness, envMapIntensity: mt.envMapIntensity, toneMapped: mt.toneMapped }, color: mt.color.clone(), emissive: mt.emissive.clone() };\n const S = mt.__vqaSaved;\n mt.color.setRGB(0, 0, 0); mt.metalness = 0; mt.roughness = 1; mt.envMapIntensity = 0; mt.emissiveIntensity = 1; mt.toneMapped = false;\n mt.emissive.copy(S.color); mt.emissiveMap = S.props.map || null;\n mt.needsUpdate = true; n++;\n }\n return n;\n };\n // The mask pass makes a material flat by what it IS, not by which class it is: a material's own enumerable fields carry\n // everything it can add to a pixel besides base colour and emission (a toon avatar's rim, matcap, shade colour and outline\n // colour live in plain Color/Texture fields; a physical one's sheen, clearcoat, transmission and specular in numbers).\n // Every colour goes black, every texture but the base map and alpha map goes away, those numbers go to zero, and the one\n // thing left to draw is magenta: the emissive colour of a lit material, the colour of an unlit one.\n const FLAT_ZERO = ['specularIntensity', 'clearcoat', 'sheen', 'transmission', 'iridescence', 'anisotropy', 'metalness', 'envMapIntensity', 'reflectivity', 'rimLightingMixFactor', 'matcapFactor'];\n A.flatSave = (mt) => {\n const colors = {}, tex = {}, num = {}; const unlit = !mt.emissive;\n for (const k of Object.keys(mt)) {\n const v = mt[k]; if (!v || k.charAt(0) === '_') continue;\n if (v.isColor) colors[k] = v.clone(); else if (v.isTexture) tex[k] = v;\n }\n for (const k of FLAT_ZERO.concat(['roughness', 'emissiveIntensity', 'toneMapped', 'fog'])) if (typeof mt[k] === 'number' || typeof mt[k] === 'boolean') num[k] = mt[k];\n return { colors, tex, num, unlit };\n };\n A.flatApply = (mt) => {\n const F = mt.__vqaFlat; const cutout = (mt.alphaTest || 0) > 0 || mt.transparent === true || !!mt.alphaMap;\n for (const k of Object.keys(F.colors)) mt[k].setRGB(0, 0, 0);\n for (const k of Object.keys(F.tex)) if (k !== 'map' && k !== 'alphaMap') mt[k] = null;\n if (F.unlit) { if (mt.color) mt.color.setRGB(1, 0, 1); if (!cutout && mt.map) mt.map = null; } else { if (mt.emissive) mt.emissive.setRGB(1, 0, 1); }\n for (const k of FLAT_ZERO) if (k in F.num && k !== 'envMapIntensity') mt[k] = 0;\n if ('roughness' in F.num) mt.roughness = 1; if ('envMapIntensity' in F.num) mt.envMapIntensity = 0;\n if ('emissiveIntensity' in F.num) mt.emissiveIntensity = 1; mt.toneMapped = false; if ('fog' in F.num) mt.fog = false;\n };\n A.flatRestore = (mt, F) => {\n for (const k of Object.keys(F.colors)) if (mt[k] && mt[k].copy) mt[k].copy(F.colors[k]);\n for (const k of Object.keys(F.tex)) mt[k] = F.tex[k];\n for (const k of Object.keys(F.num)) mt[k] = F.num[k];\n // map was nulled on an opaque unlit material: it is in F.tex, restored above.\n };\n // ------------------------------------------------------------------------------------------------ rig (walk) probes\n const LIMBS = [['thigh_l', 'calf_l'], ['calf_l', 'foot_l'], ['foot_l', 'ball_l'], ['thigh_r', 'calf_r'], ['calf_r', 'foot_r'], ['foot_r', 'ball_r'],\n ['upperarm_l', 'lowerarm_l'], ['lowerarm_l', 'hand_l'], ['upperarm_r', 'lowerarm_r'], ['lowerarm_r', 'hand_r']];\n /** Per limb bone: its BIND-pose local rotation (from the skin's inverse bind matrices, i.e. the pose the mesh was\n * weighted in) and its own axis (towards its child, in its bind frame). */\n A.rigInit = () => {\n const m = A.model(); const V = A.V(), Q = A.Q();\n let skel = null; m.traverse((o) => { if (!skel && o.isSkinnedMesh && o.skeleton && A.visible(o, m)) skel = o.skeleton; });\n if (!skel) { A.__rig = []; return { limbs: 0, names: [], bones: 0 }; }\n const M4 = m.matrixWorld.constructor;\n const bindWorld = new Map(); skel.bones.forEach((b, i) => bindWorld.set(b, new M4().copy(skel.boneInverses[i]).invert()));\n const rig = [];\n for (const [bn, cn] of LIMBS) {\n const b = skel.bones.find((x) => x.name === bn); const c = skel.bones.find((x) => x.name === cn);\n if (!b || !c) continue;\n const bw = bindWorld.get(b); const pw = b.parent && bindWorld.get(b.parent);\n const local = pw ? new M4().copy(pw).invert().multiply(bw) : bw.clone();\n const q = new Q(); local.decompose(new V(), q, new V());\n const cp = new V(); new M4().copy(bw).invert().multiply(bindWorld.get(c)).decompose(cp, new Q(), new V());\n if (cp.length() < 1e-6) continue;\n rig.push({ name: bn, bone: b, bindQ: q, axis: cp.normalize() });\n }\n A.__rig = rig;\n return { limbs: rig.length, names: rig.map((r) => r.name), bones: skel.bones.length };\n };\n /** Each limb bone's twist about its own axis away from its bind pose (deg, 0..180), and the direction each knee bends\n * (deg from the body's forward, measured only when the leg is bent by more than 3 cm). */\n A.rigSample = () => {\n const out = { twist: {}, knee: {} }; const V = A.V();\n for (const r of A.__rig || []) {\n const qr = r.bindQ.clone().invert().multiply(r.bone.quaternion);\n const d = qr.x * r.axis.x + qr.y * r.axis.y + qr.z * r.axis.z;\n out.twist[r.name] = Math.round(2 * Math.atan2(Math.abs(d), Math.abs(qr.w)) * 1800 / Math.PI) / 10;\n }\n const B = A.basis(); const at = (n) => { const b = A.bone(n); return b ? A.toBody(b.getWorldPosition(new V()), B) : null; };\n for (const s of ['l', 'r']) {\n const h = at('thigh_' + s), k = at('calf_' + s), a = at('foot_' + s);\n if (!h || !k || !a) continue;\n const ha = [a[0] - h[0], a[1] - h[1], a[2] - h[2]]; const L2 = ha[0] ** 2 + ha[1] ** 2 + ha[2] ** 2 || 1;\n const t = ((k[0] - h[0]) * ha[0] + (k[1] - h[1]) * ha[1] + (k[2] - h[2]) * ha[2]) / L2;\n const bend = [k[0] - (h[0] + ha[0] * t), k[1] - (h[1] + ha[1] * t), k[2] - (h[2] + ha[2] * t)];\n const horiz = Math.hypot(bend[0], bend[2]);\n out.knee[s] = { bendCm: Math.round(Math.hypot(bend[0], bend[1], bend[2]) * 1000) / 10, deg: horiz > 1e-4 ? Math.round(Math.acos(Math.max(-1, Math.min(1, bend[2] / horiz))) * 1800 / Math.PI) / 10 : null };\n }\n return out;\n };\n /** Sample up to maxTris triangles of every visible skinned mesh and remember their BIND (rest) areas and edge lengths. */\n A.skinInit = (maxTris) => {\n const m = A.model(); const meshes = [];\n m.traverse((o) => { if (o.isSkinnedMesh && typeof o.getVertexPosition === 'function' && A.visible(o, m) && o.geometry && o.geometry.attributes && o.geometry.attributes.position) meshes.push(o); });\n let total = 0; for (const o of meshes) total += Math.floor((o.geometry.index ? o.geometry.index.count : o.geometry.attributes.position.count) / 3);\n const step = Math.max(1, Math.floor(total / (maxTris || 20000)));\n const V = A.V(); const tris = [];\n for (const o of meshes) {\n const g = o.geometry; const pos = g.attributes.position; const idx = g.index ? g.index.array : null; const n = Math.floor((idx ? idx.length : pos.count) / 3);\n for (let t = 0; t < n; t += step) {\n const a = idx ? idx[t * 3] : t * 3, b = idx ? idx[t * 3 + 1] : t * 3 + 1, c = idx ? idx[t * 3 + 2] : t * 3 + 2;\n const pa = new V().fromBufferAttribute(pos, a), pb = new V().fromBufferAttribute(pos, b), pc = new V().fromBufferAttribute(pos, c);\n const area = new V().subVectors(pb, pa).cross(new V().subVectors(pc, pa)).length() / 2;\n if (!(area > 1e-10)) continue;\n tris.push({ o, a, b, c, area, e: [pa.distanceTo(pb), pb.distanceTo(pc), pc.distanceTo(pa)] });\n }\n }\n A.__tris = tris;\n return { meshes: meshes.length, sampled: tris.length, step };\n };\n /** Posed vs bind triangles: area-weighted shares of collapsed (< 15 % of rest area), stretched (> 4x) and\n * edge-stretched (an edge > 3x its rest length) triangles, normalised by the median so a uniform scale cancels. */\n A.skinSample = () => {\n const tris = A.__tris || []; if (!tris.length) return null;\n const V = A.V(); const cache = new Map(); const m = A.model(); m.updateMatrixWorld(true);\n const seen = new Set(); for (const t of tris) if (!seen.has(t.o)) { seen.add(t.o); if (t.o.skeleton) t.o.skeleton.update(); }\n const P = (o, i) => { let mm = cache.get(o); if (!mm) { mm = new Map(); cache.set(o, mm); } let v = mm.get(i); if (!v) { v = new V(); o.getVertexPosition(i, v); mm.set(i, v); } return v; };\n const rows = []; let total = 0; let bad = 0;\n for (const t of tris) {\n const pa = P(t.o, t.a), pb = P(t.o, t.b), pc = P(t.o, t.c);\n const area = new V().subVectors(pb, pa).cross(new V().subVectors(pc, pa)).length() / 2;\n if (!Number.isFinite(area)) { bad += t.area; total += t.area; continue; }\n const es = Math.max(pa.distanceTo(pb) / (t.e[0] || 1e-9), pb.distanceTo(pc) / (t.e[1] || 1e-9), pc.distanceTo(pa) / (t.e[2] || 1e-9));\n rows.push([area / t.area, es, t.area]); total += t.area;\n }\n const sorted = rows.map((r) => r[0]).sort((x, y) => x - y); const med = sorted[Math.floor(sorted.length / 2)] || 1; const sm = Math.sqrt(med);\n let collapsed = 0, stretched = 0, edge = 0;\n for (const [ar, es, w] of rows) { const r = ar / med; if (r < 0.15) collapsed += w; if (r > 4) stretched += w; if (es / sm > 3) edge += w; }\n const f = (v) => Math.round((v / (total || 1)) * 100000) / 100000;\n return { median: Math.round(med * 10000) / 10000, collapsed: f(collapsed + bad), stretched: f(stretched), edgeStretched: f(edge) };\n };\n /** Hold the current pose for rendering while the engine keeps animating underneath (re-applied before every render). */\n A.freeze = () => { const snap = []; A.model().traverse((o) => { if (o.isBone) snap.push([o, o.position.clone(), o.quaternion.clone(), o.scale.clone()]); }); G.__vqaFrozen = snap; return snap.length; };\n A.unfreeze = () => { G.__vqaFrozen = null; return true; };\n A.applyFrozen = () => { const s = G.__vqaFrozen; if (!s) return; for (const [b, p, q, sc] of s) { b.position.copy(p); b.quaternion.copy(q); b.scale.copy(sc); } A.model().updateMatrixWorld(true); };\n A.position = () => A.model().position.toArray();\n G.__vqaAv = A;\n return true;\n})()";