agent (cont.)

+5:23
  • read_file{"EndLine":1737,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":901}

    input

    {
      "EndLine": 1737,
      "Path": "~/work/lowmarch/review/vroid-02/index.html",
      "StartLine": 901
    }

    result, 681 lines

    Partial read (lines 901-1700 of 1737). Showing bytes 0-46080 of 54011 in this line range, truncated at the 46080-byte limit. To read the rest of this line range, call this tool again with the same StartLine and EndLine and ByteOffset=46080.
    901: let ground = null;
    902: const stage = new THREE.Group();  // the duel: both fighters stand on it; the turn slider rotates it
    903: scene.add(stage);
    904: // the lineup: every enemy model standing in a row (camera.json's lineup), each turning in place
    905: const LINEUP = CAM.lineup || { order: [], spacing: 0.9 };
    906: const ROW_VIEW = () => state.view === "lineup" || state.view === "compare";     // several models in a row, each turning in place
    907: const CAM_VIEW = () => state.view === "duel" || ROW_VIEW() ? CAM.duel.cam : charDef(state.who).cams[state.view];
    908: const activeNames = () => state.view === "duel" ? [CAM.duel.order.player, CAM.duel.order.opponent]
    909:                         : state.view === "lineup" ? LINEUP.order : state.view === "compare" ? state.compare : [state.who];
    910: const active = () => activeNames().map(n => chars.get(n)).filter(Boolean);
    911: 
    912: async function parseGlb(file) {
    913:   const j = await (await fetch(file)).json();
    914:   const bin = Uint8Array.from(atob(j.glb), c => c.charCodeAt(0));
    915:   return await new Promise((ok, bad) => loader.parse(bin.buffer, "", ok, bad));
    916: }
    917: let meshIndex = 1;
    918: function prepMesh(o, V, opts = {}) {
    919:   const m0 = o.material, role = o.userData.role || "body", raw = rawTex(m0.map);
    920:   const infoRole = role === "hair" && opts.hairB ? "hair_b" : role === "shadow" ? "body" : role;
    921:   const decal = !!(m0.userData && m0.userData.decal);              // the map is a design mask, not a colour
    922:   const base = { map: decal ? null : (m0.map || null), color: m0.color.clone(), side: THREE.DoubleSide, alphaTest: m0.alphaTest || 0 };
    923:   const clay = new THREE.MeshStandardMaterial({ ...base, roughness: 0.85, metalness: m0.metalness || 0 });
    924:   const toon = new THREE.MeshToonMaterial({ ...base, gradientMap: gradient });
    925:   if (role === "hair" && m0.map && V.paint && V.paint.hair) {
    926:     // the VRoid sample's hair texture carries its own colour (dark on some samples): in 3D use the
    927:     // character's hair colour, with the texture's light and dark only for strand detail
    928:     for (const m of [clay, toon]) {
    929:       m.color = hex(V.paint.hair.base);
    930:       m.onBeforeCompile = sh => { sh.fragmentShader = sh.fragmentShader.replace("#include <map_fragment>",
    931:         `#ifdef USE_MAP
    932:           vec4 texel_ = texture2D(map, vMapUv);
    933:           diffuseColor.rgb *= mix(1.0, clamp(dot(texel_.rgb, vec3(0.3333)) / 0.5, 0.45, 1.35), 0.6);
    934:           diffuseColor.a *= texel_.a;
    935:         #endif`); };
    936:       m.customProgramCacheKey = () => "hairlum";
    937:     }
    938:   }
    939:   o.userData.mats = { clay, toon, painted: paintMaterial(V, role, raw, meshIndex, infoRole, decal) };
    940:   meshIndex++;
    941:   o.userData.group = o.userData.group || "body";
    942:   o.userData.role = role;
    943:   o.frustumCulled = false;
    944: }
    945: 
    946: async function loadCharacter(name) {
    947:   if (chars.has(name)) return chars.get(name);
    948:   const def = charDef(name), V = def.info, ci = CAM.characters.indexOf(def);
    949:   const gltf = await parseGlb(`${name}.glb.json`);
    950:   const turn = new THREE.Group(), holder = new THREE.Group();
    951:   turn.add(holder); holder.add(gltf.scene);
    952:   const meshes = [];
    953:   gltf.scene.traverse(o => { if (o.isMesh) { prepMesh(o, V, { hairB: ci > 0 }); meshes.push(o); } });
    954:   gltf.scene.updateMatrixWorld(true);
    955:   const bone = n => gltf.scene.getObjectByName(n);
    956:   const cloths = [], world = new THREE.Group();
    957:   for (const [cname, info] of Object.entries(V.cloth || {})) {
    958:     const skinned = meshes.find(m => m.userData.material === cname);
    959:     if (!skinned) continue;
    960:     const trims = meshes.filter(m => info.trims.includes(m.userData.material));
    961:     const caps = V.capsules.filter(c => !info.collide || info.collide.some(k => c.bones[0].includes(k)));
    962:     const cl = info.closed ? new SkirtRig(skinned, info.u, info.v, trims, caps, bone, info.edges === "hem")
    963:                            : new Cloth(skinned, info.u, info.v, trims, caps, bone, false, info.edges === "hem");
    964:     const band = info.band || "gold", BR = V.roles[band] || V.roles.gold;
    965:     const gold = hex(BR.bands ? BR.bands[Math.min(1, BR.bands.length - 1)][1] : BR.color);
    966:     const PB = (V.paint || {})[band];
    967:     if (PB && PB.base) skinned.userData.mats.painted.uniforms.uBand.value = hex(PB.base);   // gold stays gold for decals
    968:     cl.lines3d = new THREE.LineSegments(cl.lines.geometry, new THREE.LineBasicMaterial({ color: gold }));
    969:     cl.lines3d.frustumCulled = false;
    970:     world.add(cl.display, cl.lines3d);
    971:     cloths.push(cl);
    972:   }
    973:   const mixer = new THREE.AnimationMixer(gltf.scene);
    974:   const actions = Object.fromEntries(gltf.animations.map(c => [c.name, mixer.clipAction(c)]));
    975:   const skeleton = meshes.find(m => m.isSkinnedMesh)?.skeleton;
    976:   const c = { name, info: V, turn, holder, root: gltf.scene, meshes, cloths, world, mixer, actions, skeleton,
    977:               clip: "idle", t: 0, groups: [...new Set(meshes.map(m => m.userData.group))] };
    978:   c.springs = makeSprings(c, V.springs);
    979:   chars.set(name, c);
    980:   return c;
    981: }
    982: 
    983: async function loadGround() {
    984:   if (ground) return ground;
    985:   const V = CAM.characters[0].info, gltf = await parseGlb("plains.glb.json"), meshes = [];
    986:   gltf.scene.traverse(o => { if (o.isMesh) { prepMesh(o, V); meshes.push(o); } });
    987:   ground = { root: gltf.scene, meshes };
    988:   return ground;
    989: }
    990: 
    991: const allMeshes = () => [...active().flatMap(c => [...c.meshes, ...c.cloths.map(cl => cl.display)]),
    992:                          ...(ground && ground.root.parent && state.view !== "bust" ? ground.meshes : [])];
    993: const isSimTrim = o => state.cloth && active().some(c => c.cloths.some(cl => cl.trims.includes(o) || cl.skinned === o));
    994: function applyMaterials() {
    995:   allMeshes().forEach(o => {
    996:     const mat = state.toon ? o.userData.mats.toon : o.userData.mats.clay;
    997:     const x = state.xray && COSTUME.has(o.userData.group);
    998:     mat.transparent = x; mat.opacity = x ? 0.28 : 1; mat.depthWrite = !x; mat.needsUpdate = true;
    999:     o.userData.mat3d = mat;
    1000:     const isDisplay = o.userData.cloth;
    1001:     o.visible = !state.hidden.has(o.userData.group) && (isDisplay ? state.cloth : !isSimTrim(o));
    1002:   });
    1003: }
    1004: const trimsShown = c => state.cloth && !state.hidden.has("trim") && !state.hidden.has(c.skinned.userData.group);
    1005: 
    1006: // ---- animation ------------------------------------------------------------------------------------------------------
    1007: // A clip only carries the bones it moves away from the reference pose, so each one starts from the
    1008: // reference pose (otherwise "arms out" would keep the idle's legs).
    1009: const CLIP_VIEW = { clash: "duel", idle: "battle", attack: "battle", apose: "battle" };
    1010: const lineupX = i => (i - (LINEUP.order.length - 1) / 2) * LINEUP.spacing;
    1011: function setClip(name, blendFrom = null) {
    1012:   for (const c of active()) {
    1013:     const n = c.actions[name] ? name : "idle";
    1014:     if (!blendFrom) c.skeleton && c.skeleton.pose();
    1015:     c.clip = n; c.t = 0;
    1016:     Object.entries(c.actions).forEach(([k, a]) => { if (k === n) { a.reset(); a.setEffectiveWeight(1); a.play(); } else a.stop(); });
    1017:     // ease in from another clip: legs stepping out gradually push the cloth (a long skirt) instead of
    1018:     // jumping through it
    1019:     c.blend = blendFrom && c.actions[blendFrom] ? { from: blendFrom, t: 0, dur: 0.8 } : null;
    1020:   }
    1021:   state.clip = name;
    1022:   document.querySelectorAll("[data-clip]").forEach(b => b.setAttribute("aria-pressed", String(b.dataset.clip === name && state.view !== "bust")));
    1023: }
    1024: function animate(dt) {
    1025:   for (const c of active()) {
    1026:     if (ARMORY_PAGE && !SHEET) { c.mixer.stopAllAction(); c.skeleton && c.skeleton.pose(); applyPose(c); applyMotion(c, dt); continue; }
    1027:     if (state.view === "bust") { c.mixer.stopAllAction(); c.skeleton && c.skeleton.pose(); continue; }
    1028:     const a = c.actions[c.clip]; if (!a) continue;
    1029:     if (!a.isRunning()) a.play();
    1030:     const dur = a.getClip().duration;
    1031:     c.t += dt;
    1032:     if (c.clip === "attack" && c.t > dur + 0.25) { setClip("idle"); return animate(0); }
    1033:     const t = state.stepped ? Math.floor(c.t * 12) / 12 : c.t;
    1034:     a.time = c.clip === "attack" ? Math.min(t, dur) : t % dur;       // the others loop
    1035:     if (c.blend) {
    1036:       c.blend.t += dt;
    1037:       const w = Math.min(1, c.blend.t / c.blend.dur), b = c.actions[c.blend.from];
    1038:       if (!b.isRunning()) b.play();
    1039:       b.time = t % b.getClip().duration; b.setEffectiveWeight(1 - w); a.setEffectiveWeight(w);
    1040:       if (w >= 1) { b.stop(); a.setEffectiveWeight(1); c.blend = null; }
    1041:     }
    1042:     c.mixer.update(0);
    1043:   }
    1044: }
    1045: 
    1046: // ---- the armory's poses and its side-by-side comparison --------------------------------------------------------------
    1047: // From the reference (bind) pose, which is the T-pose: each upper arm (and for "up" the collarbone) turns about the
    1048: // body's front axis. Which way lowers an arm is read from where its hand points, so no bone's rest angle is assumed.
    1049: const POSES = { up: { arm: -78, shoulder: -14 }, out: { arm: 0, shoulder: 0 }, down: { arm: 74, shoulder: 0 } };
    1050: const v3 = () => new THREE.Vector3(), q4 = () => new THREE.Quaternion();
    1051: function armSide(c, side) {                          // +1 when the arm points along the model's +x
    1052:   if (!c.armSide) {
    1053:     c.skeleton && c.skeleton.pose(); c.root.updateMatrixWorld(true);
    1054:     const inv = c.root.matrixWorld.clone().invert(), at = n => c.root.getObjectByName(n)?.getWorldPosition(v3()).applyMatrix4(inv);
    1055:     c.armSide = Object.fromEntries(["L", "R"].map(s => { const a = at(`J_Bip_${s}_UpperArm`), h = at(`J_Bip_${s}_Hand`);
    1056:       return [s, a && h ? Math.sign(h.x - a.x) || 1 : 1]; }));
    1057:   }
    1058:   return c.armSide[side];
    1059: }
    1060: function turnBone(c, name, deg) {                    // about the model's front axis, at the bone's own joint
    1061:   const b = c.root.getObjectByName(name);
    1062:   if (!b || !deg) return;
    1063:   const axis = new THREE.Vector3(0, 0, 1).applyQuaternion(c.root.getWorldQuaternion(q4()))
    1064:     .applyQuaternion(b.parent.getWorldQuaternion(q4()).invert());
    1065:   b.quaternion.premultiply(q4().setFromAxisAngle(axis, THREE.MathUtils.degToRad(deg)));
    1066:   b.updateMatrixWorld(true);
    1067: }
    1068: function applyPose(c) {
    1069:   const p = POSES[state.pose] || POSES.out;
    1070:   if (!p.arm && !p.shoulder) return;
    1071:   c.root.updateMatrixWorld(true);
    1072:   for (const s of ["L", "R"]) {
    1073:     const k = -armSide(c, s);                        // turning +x toward +y raises it: lowering is the other way
    1074:     turnBone(c, `J_Bip_${s}_Shoulder`, k * p.shoulder);
    1075:     turnBone(c, `J_Bip_${s}_UpperArm`, k * p.arm);
    1076:   }
    1077: }
    1078: // ---- motion and spring bones ----------------------------------------------------------------------------------------
    1079: // The armory's bodies stand still; Bounce bobs the hips as a jog's footfalls do and Twist turns the upper body side
    1080: // to side, so the spring bones (VRoid's breasts, on the women) show how they move
    1081: function applyMotion(c, dt) {
    1082:   c.motionT = (c.motionT || 0) + dt;
    1083:   const t = c.motionT;
    1084:   if (state.motion === "bounce") {
    1085:     const hips = c.root.getObjectByName("J_Bip_C_Hips");
    1086:     if (hips) { hips.position.y += 0.035 * Math.abs(Math.sin(Math.PI * 2.4 * t)); hips.updateMatrixWorld(true); }
    1087:   } else if (state.motion === "twist") {
    1088:     const spine = c.root.getObjectByName("J_Bip_C_Spine");
    1089:     if (spine) {
    1090:       const axis = new THREE.Vector3(0, 1, 0).applyQuaternion(spine.parent.getWorldQuaternion(q4()).invert());
    1091:       spine.quaternion.premultiply(q4().setFromAxisAngle(axis, THREE.MathUtils.degToRad(22) * Math.sin(2 * Math.PI * 0.9 * t)));
    1092:       spine.updateMatrixWorld(true);
    1093:     }
    1094:   }
    1095: }
    1096: // VRM 0.x spring bones as UniVRM runs them: each joint's tail keeps its momentum (less the drag), is pulled back
    1097: // toward where the pose holds it (stiffness) and down (gravity), and stays its length from the joint; the bone
    1098: // then turns to point at it. A bone with no child gets a tail 7 cm on along its own line (UniVRM's rule)
    1099: function makeSprings(c, groups) {
    1100:   const joints = [];
    1101:   if (!groups || !groups.length) return joints;
    1102:   c.skeleton && c.skeleton.pose(); c.root.updateMatrixWorld(true);
    1103:   for (const g of groups) {             // collision spheres: a bone, an offset in its frame (turned as the export
    1104:     g.spheres = (g.colliders || []).map(s => ({ bone: c.root.getObjectByName(s.bone),       // turns the model)
    1105:       offset: new THREE.Vector3(-s.offset[0], s.offset[1], -s.offset[2]), radius: s.radius })).filter(s => s.bone);
    1106:   }
    1107:   for (const g of groups) for (const rootName of g.bones) {
    1108:     const root = c.root.getObjectByName(rootName);
    1109:     if (!root) continue;
    1110:     root.traverse(b => {
    1111:       if (!b.isBone) return;
    1112:       const child = b.children.find(k => k.isBone);
    1113:       const head = b.getWorldPosition(v3());
    1114:       const tailW = child ? child.getWorldPosition(v3())
    1115:         : head.clone().add(head.clone().sub(b.parent.getWorldPosition(v3())).normalize().multiplyScalar(0.07));
    1116:       const tailL = b.worldToLocal(tailW.clone());
    1117:       joints.push({ b, rest: b.quaternion.clone(), axis: tailL.clone().normalize(), tailL, len: head.distanceTo(tailW),
    1118:                     g, grav: new THREE.Vector3(...(g.gravity_dir || [0, -1, 0])).normalize(), cur: null, prev: null, at: null });
    1119:     });
    1120:   }
    1121:   return joints;
    1122: }
    1123: function stepSprings(c, dt) {
    1124:   const head = v3(), pq = q4(), m = q4();
    1125:   if (!c.springsSettled) {                 // the first frames: hair settles under its springs before it can be seen
    1126:     c.springsSettled = true;               // swinging in from its modelled shape (the probe ignores these)
    1127:     for (let s = 0; s < 120; s++) stepSprings(c, 1 / 120);
    1128:     c.springMax = 0;
    1129:   }
    1130:   for (const j of c.springs) {
    1131:     const b = j.b;
    1132:     b.quaternion.copy(j.rest); b.updateMatrixWorld(true);
    1133:     b.getWorldPosition(head);
    1134:     b.parent.getWorldQuaternion(pq);
    1135:     // first frame, or the body jumped (a new layout): start at rest
    1136:     if (!j.cur || j.at.distanceTo(head) > 0.25) { j.cur = b.localToWorld(j.tailL.clone()); j.prev = j.cur.clone(); }
    1137:     j.at = head.clone();
    1138:     const restDir = j.axis.clone().applyQuaternion(pq.clone().multiply(j.rest));
    1139:     const next = j.cur.clone().add(j.cur.clone().sub(j.prev).multiplyScalar(1 - j.g.drag))
    1140:       .addScaledVector(restDir, j.g.stiffness * dt).addScaledVector(j.grav, j.g.gravity * dt);
    1141:     next.sub(head).setLength(j.len).add(head);
    1142:     for (const s of j.g.spheres || []) {      // out of each collision sphere (the tail's own radius added)
    1143:       const cp = s.bone.localToWorld(s.offset.clone()), r = s.radius + (j.g.radius || 0), d = next.distanceTo(cp);
    1144:       if (d < r) next.sub(cp).setLength(r).add(cp).sub(head).setLength(j.len).add(head);
    1145:     }
    1146:     j.prev.copy(j.cur); j.cur.copy(next);
    1147:     const to = next.clone().sub(head).applyQuaternion(m.copy(pq).multiply(j.rest).invert()).normalize();
    1148:     b.quaternion.copy(j.rest).multiply(q4().setFromUnitVectors(j.axis, to));
    1149:     b.updateMatrixWorld(true);
    1150:     c.springMax = Math.max(c.springMax || 0, THREE.MathUtils.radToDeg(2 * Math.acos(Math.min(1, Math.abs(b.quaternion.dot(j.rest))))));
    1151:   }
    1152: }
    1153: // side by side: each model gets room to turn in place in the current pose (its posed skin's reach round its own
    1154: // axis), and the frame fits the row and the tallest reach (raised hands)
    1155: const COMPARE = { frame: { w: 2.0, top: 1.6, bottom: -1.3 }, room: [] };
    1156: function layoutCompare() {
    1157:   const cs = active(), gap = 0.15, rooms = [], p = v3(), m4 = new THREE.Matrix4();
    1158:   let top = 0;
    1159:   for (const c of cs) {
    1160:     c.skeleton && c.skeleton.pose(); applyPose(c); c.root.updateMatrixWorld(true); c.skeleton && c.skeleton.update();
    1161:     const inv = c.root.matrixWorld.clone().invert();
    1162:     let r = 0;
    1163:     for (const m of c.meshes) {
    1164:       const pos = m.geometry.attributes.position, step = Math.max(1, Math.floor(pos.count / 6000));
    1165:       m4.multiplyMatrices(inv, m.matrixWorld);
    1166:       for (let i = 0; i < pos.count; i += step) {
    1167:         m.getVertexPosition(i, p).applyMatrix4(m4);
    1168:         r = Math.max(r, Math.hypot(p.x, p.z)); top = Math.max(top, p.y);
    1169:       }
    1170:     }
    1171:     rooms.push(r + 0.04);
    1172:   }
    1173:   const total = rooms.reduce((a, r) => a + 2 * r + gap, -gap);
    1174:   let x = -total / 2;
    1175:   cs.forEach((c, i) => { c.turn.position.set(x + rooms[i], 0, 0); x += 2 * rooms[i] + gap; });
    1176:   COMPARE.room = rooms;
    1177:   COMPARE.frame = { w: Math.max(2.0, total + 0.2), top: Math.max(1.0, top - 1.0 + 0.1), bottom: -1.32 };
    1178: }
    1179: function placeTags() {                               // the names under the feet
    1180:   const box = $("tags");
    1181:   if (state.view !== "compare" || SHEET) { if (box.childElementCount) box.textContent = ""; return; }
    1182:   const cs = active();
    1183:   if (box.childElementCount !== cs.length) { box.textContent = ""; cs.forEach(() => box.appendChild(document.createElement("span"))); }
    1184:   const W = stageEl.clientWidth, H = stageEl.clientHeight, mpp = (camera.right - camera.left) / camera.zoom / Math.max(1, W);
    1185:   cs.forEach((c, i) => {
    1186:     const el = box.children[i], label = charDef(c.name).label;
    1187:     if (el.textContent !== label) el.textContent = label;
    1188:     const p = c.turn.getWorldPosition(v3()); p.y = -0.03; p.project(camera);
    1189:     el.style.left = `${(p.x + 1) / 2 * W}px`; el.style.top = `${(1 - p.y) / 2 * H + 6}px`;
    1190:     el.style.maxWidth = `${Math.max(70, 2 * (COMPARE.room[i] || 0.5) / mpp - 10)}px`;
    1191:   });
    1192: }
    1193: function compareChanged() {                          // the comparison is in the link, to share it
    1194:   const u = new URL(location.href);
    1195:   u.searchParams.set("view", "compare"); u.searchParams.set("compare", state.compare.join(",")); u.searchParams.set("pose", state.pose);
    1196:   try { history.replaceState(null, "", u); } catch (e) { /* a sandboxed page may refuse: the view still changes */ }
    1197:   setView("compare");
    1198: }
    1199: 
    1200: // ---- sizing and camera ---------------------------------------------------------------------------------------------
    1201: // The game camera's frame (its pixel size, scale and pivot) is fitted into the window between the two
    1202: // bars, then the window's extra width or height is shown around it.
    1203: function insets() {
    1204:   if (SHEET) return { top: 0, bottom: 0 };
    1205:   const k = state.view === "compare" ? 1.0 : 0.8;     // compare's bar is tall (the picker): raised hands mustn't hide under it
    1206:   return { top: document.querySelector(".hud.top").offsetHeight * k, bottom: document.querySelector(".hud.bottom").offsetHeight * 0.8 };
    1207: }
    1208: let frameRef = null;              // the game frame, metres from the orbit target
    1209: function fitFrustum() {
    1210:   if (!frameRef) return;
    1211:   const W = stageEl.clientWidth || 1, H = stageEl.clientHeight || 1, ins = insets();
    1212:   const f = frameRef, fw = (f.right - f.left) * 1.04, fh = (f.top - f.bottom) * 1.04;
    1213:   const s = Math.max(fw / W, fh / Math.max(60, H - ins.top - ins.bottom));     // metres per pixel
    1214:   const cx = (f.left + f.right) / 2, cy = (f.top + f.bottom) / 2;
    1215:   const top = cy + (H / 2 + (ins.top - ins.bottom) / 2) * s;     // the frame's centre sits midway between the bars
    1216:   camera.left = cx - W * s / 2; camera.right = cx + W * s / 2; camera.top = top; camera.bottom = top - H * s;
    1217:   camera.updateProjectionMatrix();
    1218: }
    1219: function size() {
    1220:   const w = stageEl.clientWidth, h = stageEl.clientHeight;
    1221:   if (!SHEET) { R.setPixelRatio(Math.min(2, window.devicePixelRatio || 1)); R.setSize(w, h, false); }
    1222:   fitFrustum();
    1223: }
    1224: // The default framing: the portrait keeps the game's bust crop; battle and duel frame the figures
    1225: // (head to feet, both fighters) rather than the whole ground strip, so they fill the window.
    1226: const FIGURE = { duel: { w: 2.9, top: 1.28, bottom: -1.18 }, battle: { w: 1.5, top: 1.24, bottom: -1.14 },
    1227:                  get lineup() { return { w: Math.max(2.0, LINEUP.order.length * LINEUP.spacing + 0.4), top: 1.60, bottom: -1.16 }; },
    1228:                  get compare() { return COMPARE.frame; } };
    1229: function matchCamera() {
    1230:   // orbit around the middle of the body (the feet in battle would send zooms into the ground)
    1231:   const v = CAM_VIEW(), ppm = v.px_per_m, p = v.pivot, a = THREE.MathUtils.degToRad(v.pitch);
    1232:   const lift = state.view === "bust" ? 0.0 : 1.0;
    1233:   const target = new THREE.Vector3(p[0], p[1] + lift, p[2]);
    1234:   const tx = v.pivot_px[0], ty = v.pivot_px[1] - lift * Math.cos(a) * ppm, F = FIGURE[state.view];
    1235:   frameRef = F ? { left: -F.w / 2, right: F.w / 2, top: F.top, bottom: F.bottom }
    1236:                : { left: -tx / ppm, right: (v.w - tx) / ppm, top: ty / ppm, bottom: -(v.h - ty) / ppm };
    1237:   camera.zoom = 1; fitFrustum();
    1238:   camera.position.copy(target).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(15));
    1239:   camera.up.set(0, 1, 0); camera.lookAt(target);
    1240:   ctl.target.copy(target); ctl.update();
    1241:   freeLook = false;
    1242: }
    1243: // double-click: orbit around the spot under the cursor
    1244: const ray = new THREE.Raycaster();
    1245: function focusAt(e) {
    1246:   const rect = R.domElement.getBoundingClientRect();
    1247:   const ndc = new THREE.Vector2(((e.clientX - rect.left) / rect.width) * 2 - 1, -((e.clientY - rect.top) / rect.height) * 2 + 1);
    1248:   ray.setFromCamera(ndc, camera);
    1249:   const hit = ray.intersectObjects(allMeshes().filter(o => o.visible), false)[0];
    1250:   if (!hit) return;
    1251:   const shift = hit.point.clone().sub(ctl.target);
    1252:   ctl.target.add(shift); camera.position.add(shift); ctl.update();
    1253:   freeLook = true;
    1254: }
    1255: function setYaw(y) {
    1256:   state.yaw = ((y % 360) + 360) % 360;
    1257:   $("yaw").value = Math.round(state.yaw); $("yawOut").textContent = `${Math.round(state.yaw)}°`;
    1258:   const r = -THREE.MathUtils.degToRad(state.yaw);
    1259:   if (state.view === "duel") stage.rotation.y = r;
    1260:   else if (ROW_VIEW()) active().forEach(c => c.turn.rotation.y = r);
    1261:   else { const c = chars.get(state.who); if (c) c.turn.rotation.y = r; }
    1262: }
    1263: 
    1264: // ---- controls --------------------------------------------------------------------------------------------------------
    1265: function buildParts() {
    1266:   const box = $("parts"); box.innerHTML = "";
    1267:   const groups = [...new Set(active().flatMap(c => c.groups)), ...(state.view !== "bust" ? ["terrain"] : [])];
    1268:   groups.forEach(g => {
    1269:     const l = document.createElement("label"); l.className = "chip";
    1270:     l.innerHTML = `<input type="checkbox" ${state.hidden.has(g) ? "" : "checked"}> ${GROUP_LABELS[g] || g}`;
    1271:     l.querySelector("input").addEventListener("change", e => { e.target.checked ? state.hidden.delete(g) : state.hidden.add(g); applyMaterials(); });
    1272:     box.appendChild(l);
    1273:   });
    1274: }
    1275: function groupedSelect(label, skip, onPick) {      // every model in its group, as one dropdown
    1276:   const sel = document.createElement("select");
    1277:   sel.className = "btn"; sel.setAttribute("aria-label", label);
    1278:   const first = document.createElement("option"); first.value = ""; first.textContent = label; sel.appendChild(first);
    1279:   [...new Set(CAM.characters.map(c => c.group || "Other"))].forEach(g => {
    1280:     const og = document.createElement("optgroup"); og.label = g;
    1281:     CAM.characters.filter(c => (c.group || "Other") === g && !skip.includes(c.name)).forEach(c => {
    1282:       const o = document.createElement("option"); o.value = c.name; o.textContent = c.label; og.appendChild(o);
    1283:     });
    1284:     if (og.children.length) sel.appendChild(og);
    1285:   });
    1286:   sel.addEventListener("change", () => sel.value && onPick(sel.value));
    1287:   return sel;
    1288: }
    1289: function buildWho() {
    1290:   const box = $("who"); box.innerHTML = "";
    1291:   if (state.view === "compare") {                     // the models being compared, left to right, and one to add
    1292:     const wrap = document.createElement("span"); wrap.className = "pick";
    1293:     state.compare.forEach(n => {
    1294:       const b = document.createElement("button"), label = charDef(n).label;
    1295:       b.type = "button"; b.className = "btn"; b.disabled = state.compare.length <= 1;
    1296:       b.setAttribute("aria-label", `Remove ${label} from the comparison`); b.title = "Remove from the comparison";
    1297:       b.append(label, Object.assign(document.createElement("b"), { textContent: "✕" }));
    1298:       b.addEventListener("click", () => { state.compare = state.compare.filter(x => x !== n); compareChanged(); });
    1299:       wrap.appendChild(b);

    281 more lines not shown.

agent

+5:32
reasoning

Reading through the remaining files to understand the tool's complete capabilities and the dependencies between modules. The goal is to build a full picture of the tool's functionalities by understanding the interconnections of different parts of the codebase. This helps in identifying how different components are used and where potential issues might arise during usage.