A 3D model pipeline, pushed by Gemini 4 Argon
agent (cont.)
+3:56read_file{"EndLine":1737,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":1201}
input
{ "EndLine": 1737, "Path": "~/work/lowmarch/review/vroid-02/index.html", "StartLine": 1201 }result, 538 lines
Showing lines 1201-1737 of 1737 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); 1300: }); 1301: if (state.compare.length < MAX_COMPARE) 1302: wrap.appendChild(groupedSelect("Add a model…", state.compare, n => { state.compare = [...state.compare, n]; compareChanged(); })); 1303: box.appendChild(wrap); 1304: return; 1305: } 1306: if (CAM.characters.some(c => c.group)) { // a long roster in groups (camera.json "group"): one dropdown 1307: const sel = document.createElement("select"); 1308: sel.className = "btn"; sel.setAttribute("aria-label", "Character"); 1309: const order = [...new Set(CAM.characters.map(c => c.group || "Other"))]; 1310: order.forEach(g => { 1311: const og = document.createElement("optgroup"); og.label = g; 1312: CAM.characters.filter(c => (c.group || "Other") === g).forEach(c => { 1313: const o = document.createElement("option"); o.value = c.name; o.textContent = c.label; 1314: o.selected = state.who === c.name; og.appendChild(o); 1315: }); 1316: sel.appendChild(og); 1317: }); 1318: sel.addEventListener("change", () => { state.who = sel.value; setView(state.view === "duel" ? "battle" : state.view); }); 1319: box.appendChild(sel); 1320: return; 1321: } 1322: CAM.characters.forEach(c => { 1323: const b = document.createElement("button"); 1324: b.type = "button"; b.className = "btn"; b.textContent = c.label; 1325: b.setAttribute("aria-pressed", String((state.view === "battle" || state.view === "bust") && state.who === c.name)); 1326: b.addEventListener("click", () => { state.who = c.name; setView(state.view === "duel" ? "battle" : state.view); }); 1327: box.appendChild(b); 1328: }); 1329: } 1330: 1331: async function setView(view, clip) { 1332: const changed = view !== state.view; 1333: state.view = view; 1334: document.querySelectorAll("[data-view]").forEach(b => b.setAttribute("aria-pressed", String(b.dataset.view === view))); 1335: buildWho(); 1336: statusEl.hidden = false; statusEl.textContent = view === "duel" ? "Loading both fighters…" : "Loading the model…"; 1337: try { 1338: const cs = await Promise.all(activeNames().map(loadCharacter)); 1339: const g = view !== "bust" && !ROW_VIEW() ? await loadGround() : null; // a row of models stands on nothing 1340: for (const c of chars.values()) { c.turn.removeFromParent(); scene.remove(c.world); } 1341: if (ground) scene.remove(ground.root); 1342: if (g) scene.add(g.root); 1343: const v = CAM_VIEW(), lead = cs[0].info; 1344: paint.mat.uniforms.uGap.value = lead.depth_gap; 1345: stage.rotation.y = 0; 1346: for (const c of cs) { 1347: scene.add(c.world); 1348: c.turn.rotation.set(0, 0, 0); 1349: if (view === "lineup") { 1350: const i = LINEUP.order.indexOf(c.name); 1351: stage.add(c.turn); 1352: c.turn.position.set(lineupX(i), 0, 0); c.holder.position.set(0, 0, 0); 1353: } else if (view === "compare") { // placed by layoutCompare, once all are in 1354: stage.add(c.turn); c.holder.position.set(0, 0, 0); 1355: } else if (view === "duel") { 1356: const pl = CAM.duel.place[c.name]; 1357: stage.add(c.turn); 1358: c.turn.position.set(...pl.pos); c.turn.rotation.y = THREE.MathUtils.degToRad(pl.yaw); c.holder.position.set(0, 0, 0); 1359: } else { 1360: scene.add(c.turn); 1361: c.turn.position.set(v.pivot[0], 0, v.pivot[2]); c.holder.position.set(-v.pivot[0], 0, -v.pivot[2]); 1362: } 1363: } 1364: statusEl.hidden = true; 1365: if (view === "compare") layoutCompare(); 1366: buildParts(); applyMaterials(); size(); matchCamera(); 1367: setYaw(changed || view === "duel" ? VIEW_YAW[view] : state.yaw); 1368: const want = clip || (view === "duel" ? "clash" : (CLIP_VIEW[state.clip] === "battle" ? state.clip : "idle")); 1369: if (view === "duel") setClip("clash", SHEET ? null : "idle"); else if (view === "battle") setClip(want); 1370: else if (view === "lineup") setClip(clip && CLIP_VIEW[clip] === "battle" ? clip : "idle"); else setClip("idle"); 1371: animate(0); 1372: scene.updateMatrixWorld(true); cs.forEach(c => c.cloths.forEach(cl => { cl.reset(false); cl.write(); })); 1373: } catch (e) { console.error(e); statusEl.textContent = "The model didn't load."; } 1374: } 1375: 1376: // ---- rendering ------------------------------------------------------------------------------------------------------- 1377: function applySkin(meshes) { 1378: // the picked tone on every skin material (face, body, shadow cards); the built tone is kept to go back to 1379: const tone = state.skin && PAGE && PAGE.skins ? PAGE.skins.find(s => s.name === state.skin) : null; 1380: for (const o of meshes) { 1381: const m = o.userData.mats && o.userData.mats.painted, u = m && m.uniforms; 1382: if (!u || !u.uSkinRamp || u.uKind.value !== 1) continue; 1383: if (!o.userData.builtSkin) o.userData.builtSkin = [u.uSkinRamp.value, u.uSkinL.value.clone(), u.uSkinS.value.clone(), u.uSkinC.value.clone()]; 1384: if (tone) { u.uSkinRamp.value = 1; u.uSkinL.value.copy(hex(tone.ramp[0])); u.uSkinS.value.copy(hex(tone.ramp[1])); u.uSkinC.value.copy(hex(tone.ramp[2])); } 1385: else { const b = o.userData.builtSkin; u.uSkinRamp.value = b[0]; u.uSkinL.value.copy(b[1]); u.uSkinS.value.copy(b[2]); u.uSkinC.value.copy(b[3]); } 1386: } 1387: } 1388: function render() { 1389: const meshes = allMeshes(), cs = active(); 1390: applySkin(meshes); 1391: const cloths = cs.flatMap(c => c.cloths); 1392: if (state.mode === "3d") { 1393: meshes.forEach(o => o.material = o.userData.mat3d); 1394: cloths.forEach(c => c.lines3d.visible = trimsShown(c)); 1395: sun.position.copy(camera.position).add(new THREE.Vector3(-3, 4, 0)); sun.target.position.copy(ctl.target); sun.target.updateMatrixWorld(); 1396: R.setRenderTarget(null); R.setClearColor(0x191626, 1); R.clear(); R.render(scene, camera); R.setClearColor(0x000000, 0); 1397: return; 1398: } 1399: const buf = R.getDrawingBufferSize(new THREE.Vector2()); 1400: targetsFor(buf.x, buf.y); 1401: cloths.forEach(c => c.lines3d.visible = false); 1402: meshes.forEach(o => { o.material = o.userData.mats.painted; o.material.uniforms.uPass.value = 0; }); 1403: const G = GRADE[state.view === "bust" ? "bust" : "battle"]; // stage grade, shared by the characters and the stage 1404: for (const o of meshes) { const mu = o.material.uniforms; mu.uAmbient.value.set(...G.ambient); mu.uKeyCol.value.set(...G.key); mu.uRimCol.value.set(...G.rim); } 1405: // the info pass (roles, ids, depth) first: the colour pass reads it for cast shadows 1406: meshes.forEach(o => { // unbound while it is drawn: reading it now would be a feedback loop 1407: const mu = o.material.uniforms; mu.uPass.value = 1; mu.uCastOn.value = 0; mu.tCastInfo.value = null; mu.tCastDepth.value = null; 1408: }); 1409: R.setRenderTarget(targets.rtInfo); R.clear(); R.render(scene, camera); 1410: const ppmBuf = buf.y / (camera.top - camera.bottom) * camera.zoom; 1411: for (const o of meshes) { 1412: const mu = o.material.uniforms; 1413: mu.uPass.value = 0; mu.uCastOn.value = 1; mu.tCastInfo.value = targets.rtInfo.texture; mu.tCastDepth.value = targets.rtInfo.depthTexture; 1414: mu.uCastRes.value.set(buf.x, buf.y); mu.uCastNear.value = camera.near; mu.uCastFar.value = camera.far; mu.uCastPpm.value = ppmBuf; 1415: } 1416: R.setRenderTarget(targets.rt); R.clear(); R.render(scene, camera); 1417: const u = paint.mat.uniforms; 1418: u.tColor.value = targets.rt.texture; u.tInfo.value = targets.rtInfo.texture; u.tDepth.value = targets.rtInfo.depthTexture; 1419: u.uRes.value.set(buf.x, buf.y); u.uNear.value = camera.near; u.uFar.value = camera.far; 1420: // line weight follows the figure's size on screen (study: ~0.4% of its height) 1421: const ppm = buf.y / (camera.top - camera.bottom) * camera.zoom, dpr = R.getPixelRatio(); 1422: u.uSil.value = THREE.MathUtils.clamp(1.75 * ppm * 0.0042, dpr, 2.6 * dpr); 1423: u.uInner.value = Math.max(dpr * 0.75, u.uSil.value * 0.55); 1424: u.uPpm.value = ppm; 1425: R.setRenderTarget(null); R.clear(); R.render(paint.scene, compCam); 1426: } 1427: 1428: // ---- check sheets ---------------------------------------------------------------------------------------------------- 1429: // ?sheet=<name> poses one character through every check view; ?sheet=duel shows the bind. Each tile 1430: // is posed, its cloth settled at that angle, rendered by the same painted renderer as the page, and 1431: // drawn into one image, which lands in #sheetOut as a PNG data URL (a headless browser reads it). 1432: const ARMS_YAWS = [0, 45, 90, 135, 180, 270]; 1433: const CHAR_ROWS = [ 1434: // arms down, as character design sheets are drawn: the row to compare against references 1435: { label: "Reference pose", tiles: [0, 30, 90, 180, 270, 330].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 0, hide: ["sword", "weapon"], label: `${y}°` })) }, 1436: { label: "Head", tiles: [0, 30, 90, 150, 180, 270].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.03, 1437: size: 0.42, hide: ["sword", "weapon"], label: `${y}°` })) }, 1438: { label: "Arms out", tiles: ARMS_YAWS.map(y => ({ clip: "apose", t: 0, yaw: y, label: `${y}°` })) }, 1439: { label: "Idle", tiles: ARMS_YAWS.map(y => ({ clip: "idle", t: 0, yaw: y, label: `${y}°` })) }, 1440: // the idle loop through time from one side (the camera holds still: the body's rise and sink shows) 1441: { label: "Idle loop", tiles: [0, 0.4, 0.8, 1.0, 1.3, 1.6].map(t => ({ clip: "idle", t, yaw: 300, label: `${t.toFixed(1)} s` })) }, 1442: { label: "Attack", tiles: [[0.32, "wind-up"], [0.56, "slash"], [0.68, "follow-through"]].flatMap(([t, n]) => 1443: [60, 300].map(y => ({ clip: "attack", t, yaw: y, label: `${n}, ${y}°` }))) }, 1444: { label: "Close-ups", tiles: [ 1445: { clip: "apose", t: 0, yaw: 0, focus: "J_Bip_C_Hips", dy: 0.10, size: 0.62, label: "waist, front" }, 1446: { clip: "apose", t: 0, yaw: 90, focus: "J_Bip_C_Hips", dy: 0.10, size: 0.62, label: "waist, side" }, 1447: { clip: "apose", t: 0, yaw: 180, focus: "J_Bip_C_Hips", dy: 0.10, size: 0.62, label: "waist, back" }, 1448: { clip: "idle", t: 0, yaw: 60, focus: "J_Bip_R_Hand", dy: 0, size: 0.45, label: "right wrist" }, 1449: { clip: "idle", t: 0, yaw: 300, focus: "J_Bip_L_Hand", dy: 0, size: 0.45, label: "left wrist" }, 1450: { clip: "idle", t: 0, yaw: 30, focus: "J_Bip_L_Foot", dy: 0.02, size: 0.5, label: "feet" }] }, 1451: // where a head meets its neck (grafted heads): from below the jaw, the side and behind, and mid-attack 1452: // when the head turns on the neck 1453: { label: "Neck and collar", tiles: [ 1454: ...[[0, -10, "front, from below"], [60, -10, "three-quarter"], [120, -4, "behind the ear"], [180, 0, "nape"]].map(([y, p, n]) => 1455: ({ clip: "ref", t: 0, yaw: y, pitch: p, focus: "J_Bip_C_Neck", dy: 0.03, size: 0.30, hide: ["sword", "weapon"], label: n })), 1456: { clip: "attack", t: 0.32, yaw: 60, focus: "J_Bip_C_Neck", dy: 0.03, size: 0.34, label: "wind-up, 60°" }, 1457: { clip: "attack", t: 0.56, yaw: 300, focus: "J_Bip_C_Neck", dy: 0.03, size: 0.34, label: "slash, 300°" }] }, 1458: ]; 1459: // the armory (bodies, heads and hair to assemble from): the T-pose round, the head close, the joins 1460: const ARMORY_ROWS = [ 1461: { label: "T-pose", tiles: [0, 45, 90, 135, 180, 270].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 0, label: `${y}°` })) }, 1462: { label: "Head", tiles: [0, 30, 90, 150, 180, 270].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.03, 1463: size: 0.42, label: `${y}°` })) }, 1464: { label: "Joins", tiles: [ 1465: ...[[0, -10, "neck, front"], [120, -4, "neck, behind the ear"]].map(([y, p, n]) => 1466: ({ clip: "ref", t: 0, yaw: y, pitch: p, focus: "J_Bip_C_Neck", dy: 0.03, size: 0.30, label: n })), 1467: { clip: "ref", t: 0, yaw: 0, focus: "J_Bip_L_UpperArm", dy: 0, size: 0.40, label: "shoulder, front" }, 1468: { clip: "ref", t: 0, yaw: 180, focus: "J_Bip_C_Hips", dy: -0.12, size: 0.55, label: "hips and thighs, back" }, 1469: { clip: "ref", t: 0, yaw: 0, focus: "J_Bip_C_Hips", dy: -0.12, size: 0.55, label: "hips and thighs, front" }, 1470: { clip: "ref", t: 0, yaw: 30, focus: "J_Bip_L_Foot", dy: 0.02, size: 0.5, label: "feet" }] }, 1471: ]; 1472: const DUEL_YAWS = [0, 40, 90, 320]; 1473: const LINEUP_ROWS = [ 1474: { label: "Lineup", tiles: [0, 30].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 0, hide: ["sword", "weapon"], label: `${y}°, reference pose` })) }, 1475: { label: "Lineup", tiles: [90, 180].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 0, hide: ["sword", "weapon"], label: `${y}°, reference pose` })) }, 1476: { label: "Lineup", tiles: [20, 300].map(y => ({ clip: "idle", t: 0, yaw: y, label: `${y}°, idle` })) }, 1477: // faces with helmets and hoods off: the face structures underneath, one close-up each 1478: { label: "Faces (helmets and hoods off)", tw: 300, th: 340, tiles: LINEUP.order.map((n, i) => ({ clip: "ref", t: 0, yaw: 20, 1479: pitch: 0, hide: ["sword", "weapon", "helmet", "hood", "shield"], focusChar: i, size: 0.40, 1480: label: (charDef(n) || {}).label || n })) }, 1481: { label: "Faces (helmets on)", tw: 300, th: 340, tiles: LINEUP.order.map((n, i) => ({ clip: "ref", t: 0, yaw: 20, 1482: pitch: 0, hide: ["sword", "weapon", "shield"], focusChar: i, size: 0.40, label: (charDef(n) || {}).label || n })) }, 1483: ]; 1484: const DUEL_ROWS = [0, 0.8, 1.6].map(t => ({ label: `Clash ${t.toFixed(1)} s`, tiles: DUEL_YAWS.map(y => ({ clip: "clash", t, yaw: y, label: `${y}°` })) })) 1485: .concat([{ label: "The bind, close", tiles: [0, 90, 180, 300].map(y => ({ clip: "clash", t: 0, yaw: y, focusBind: true, size: 0.95, label: `${y}°` })) }]); 1486: 1487: function holdPose(clip, t) { 1488: for (const c of active()) { 1489: if (c.skeleton) c.skeleton.pose(); 1490: c.mixer.stopAllAction(); c.blend = null; c.clip = clip; 1491: if (clip === "ref") continue; // the reference (bind) pose itself 1492: const a = c.actions[clip] || c.actions.idle; 1493: a.reset(); a.setEffectiveWeight(1); a.play(); a.time = t; c.mixer.update(0); 1494: } 1495: scene.updateMatrixWorld(true); 1496: } 1497: function settleCloth() { 1498: const cs = active(); 1499: cs.forEach(c => c.cloths.forEach(cl => cl.reset(false))); 1500: for (let s = 0; s < 150; s++) cs.forEach(c => c.cloths.forEach(cl => cl.step(1 / 120, s / 120))); 1501: cs.forEach(c => c.cloths.forEach(cl => cl.write())); 1502: } 1503: function frameAt(centre, h, tw, th, pitch) { 1504: const w = h * tw / th, a = THREE.MathUtils.degToRad(pitch); 1505: camera.left = -w / 2; camera.right = w / 2; camera.top = h / 2; camera.bottom = -h / 2; camera.zoom = 1; 1506: camera.updateProjectionMatrix(); 1507: camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(15)); 1508: camera.up.set(0, 1, 0); camera.lookAt(centre); ctl.target.copy(centre); 1509: } 1510: async function runSheet(kind) { 1511: document.body.classList.add("sheet"); 1512: const lineup = kind === "lineup", duel = kind === "duel" || lineup; 1513: if (!duel) state.who = kind; 1514: if (params.get("mode") === "3d") state.mode = "3d"; // ?mode=3d: the plain 3D renderer (tells a geometry fault from a shading one) 1515: await setView(lineup ? "lineup" : duel ? "duel" : "battle"); 1516: if ((!duel || lineup) && ground) { scene.remove(ground.root); } 1517: applyMaterials(); 1518: // ?rows=0,3 keeps some rows, ?scale=3 renders them larger (for side-by-sides against a reference) 1519: const keep = (params.get("rows") || "").split(",").filter(Boolean).map(Number); 1520: const scale = Math.max(1, Math.min(4, +(params.get("scale") || 1))); 1521: const rows = (lineup ? LINEUP_ROWS : duel ? DUEL_ROWS : PAGE && PAGE.armory ? ARMORY_ROWS : [...CHAR_ROWS]) 1522: .filter((r, i) => !keep.length || keep.includes(i)); 1523: if (!duel && !keep.length) { 1524: try { 1525: const chk = (await (await fetch("checks.json")).json())[kind]; 1526: const seen = new Set(), tiles = []; 1527: for (const it of chk.through) { 1528: const [limb] = it.hits[0], key = `${it.clip}@${it.t}`; 1529: if (seen.has(key) || tiles.length >= 6) continue; 1530: seen.add(key); 1531: for (const y of [60, 300]) tiles.push({ clip: it.clip, t: it.t, yaw: y, focus: `J_Bip_${limb.slice(0, 2)}LowerArm`, dy: 0, size: 0.75, 1532: label: `${it.clip} ${it.t} s, ${y}°` }); 1533: } 1534: // garments through plate: a close-up framed on the plate (two angles), reference pose first 1535: for (const it of (chk.layers ? chk.layers.items : [])) { 1536: const [, plate] = it.hits[0], key = `${it.clip}@${it.t}:${plate}`; 1537: if (seen.has(key) || tiles.length >= 10) continue; 1538: seen.add(key); 1539: const clip = it.clip === "reference pose" ? "ref" : it.clip; 1540: for (const y of [30, 330]) tiles.push({ clip, t: it.t, yaw: y, focusMesh: `OUTFIT_${plate}`, size: 0.5, 1541: label: `${plate}, ${it.clip === "reference pose" ? "as built" : it.clip + " " + it.t + " s"}, ${y}°` }); 1542: } 1543: if (tiles.length) rows.push({ label: "Flagged by the checks", tiles: tiles.slice(0, 6) }); 1544: if (tiles.length > 6) rows.push({ label: "Flagged by the checks (more)", tiles: tiles.slice(6, 12) }); 1545: } catch (e) { /* no checks: no row */ } 1546: } 1547: // the lineup's tiles shrink to stay under WebGL's largest drawing size (8192 here): past it they came out black 1548: const lw0 = Math.round(FIGURE.lineup.w / 2.5 * 480), lk = Math.min(1, 8000 / (lw0 * scale)), lw = Math.round(lw0 * lk); 1549: const tw = (lineup ? lw : duel ? 520 : 300) * scale, th = (duel ? 420 : lineup ? Math.round(520 * lk) : 520) * scale, 1550: lab = 22, rowHead = 30, gap = 6; 1551: const rw = r => (r.tw || tw / scale) * scale, rh = r => (r.th || th / scale) * scale; 1552: const cv = document.createElement("canvas"); 1553: cv.width = Math.max(...rows.map(r => r.tiles.length * (rw(r) + gap))) + gap; 1554: cv.height = rows.reduce((a, r) => a + rowHead + rh(r) + lab + gap, 0) + gap; 1555: const ctx = cv.getContext("2d"); 1556: ctx.fillStyle = "#100e18"; ctx.fillRect(0, 0, cv.width, cv.height); 1557: R.setPixelRatio(1); 1558: let y0 = gap; 1559: for (const row of rows) { 1560: const tw_ = rw(row), th_ = rh(row); 1561: R.setSize(tw_, th_, false); 1562: ctx.fillStyle = "#e9e6f2"; ctx.font = "bold 18px sans-serif"; 1563: ctx.fillText(`${lineup ? "Enemies" : duel ? "Duel" : charDef(kind).label} · ${row.label}`, gap + 2, y0 + 21); 1564: y0 += rowHead; 1565: row.tiles.forEach((tile, k) => { 1566: setYaw(tile.yaw); 1567: state.hidden = new Set(tile.hide || []); applyMaterials(); 1568: holdPose(tile.clip, tile.t); 1569: settleCloth(); 1570: let centre, h = tile.size || (lineup ? 2.5 : duel ? 2.3 : 2.05), pitch = tile.pitch ?? 8; 1571: if (tile.focusBind) { 1572: const hs = active().map(c => c.root.getObjectByName("J_Bip_R_Hand").getWorldPosition(new THREE.Vector3())); 1573: centre = hs[0].clone().add(hs[1]).multiplyScalar(0.5).add(new THREE.Vector3(0, 0.12, 0)); pitch = 4; 1574: } else if (tile.focusChar != null) { // one unit's head in the lineup 1575: centre = active()[tile.focusChar].root.getObjectByName("J_Bip_C_Head").getWorldPosition(new THREE.Vector3()); 1576: centre.y += 0.05; pitch = tile.pitch ?? 0; 1577: } else if (tile.focusMesh) { 1578: const m = active()[0].meshes.find(o => o.userData.material === tile.focusMesh); 1579: centre = m ? new THREE.Box3().setFromObject(m, true).getCenter(new THREE.Vector3()) : new THREE.Vector3(0, 1, 0); pitch = 4; 1580: } else if (tile.focus) { 1581: centre = active()[0].root.getObjectByName(tile.focus).getWorldPosition(new THREE.Vector3()); centre.y += tile.dy; pitch = tile.pitch ?? 4; 1582: } else { 1583: // follow the hips across the ground (a lunge steps out of a fixed frame) 1584: const p = duel ? new THREE.Vector3(0, 0, 0) : active()[0].root.getObjectByName("J_Bip_C_Hips").getWorldPosition(new THREE.Vector3()); 1585: centre = new THREE.Vector3(p.x, h / 2 - 0.06, p.z); 1586: } 1587: frameAt(centre, h, tw_, th_, pitch); 1588: render(); 1589: const x = gap + k * (tw_ + gap); 1590: ctx.drawImage(R.domElement, x, y0, tw_, th_); 1591: ctx.fillStyle = "#9c98b5"; ctx.font = "14px sans-serif"; ctx.fillText(tile.label, x + 4, y0 + th_ + 16); 1592: }); 1593: y0 += th_ + lab + gap; 1594: } 1595: $("sheetOut").textContent = cv.toDataURL("image/png"); 1596: document.title = "sheet ready"; 1597: } 1598: 1599: // ---- panel: checks and sheets ------------------------------------------------------------------------------------------138 more lines not shown.