agent

+21:07
reasoning

`): Observed that the "clean as built" state is consistent across keyframes for both subjects. This suggests a stable, initial visual state. Proceeding to design and render the target visual, the "One Visual."

The target visual must be a self-contained HTML page with a single visual asset. The current goal is to generate a painted game frame. Identified that a 1920x1080 resolution is suitable for the lowmarch-argon.png image and WebGL painted shader.

The initial plan was a single painted game frame, but the existing HTML structure already provides a 3D battle stage and bust portrait cut-ins. This suggests the "One Visual" should incorporate these existing elements within the 1920x1080 resolution. The frame can then use the existing battle stage duel between two figures and add in-frame bust portraits, which were already present.

The "One Visual" now encompasses a full 1920x1080 PNG image, rendered by a WebGL painted shader. This shader utilizes the .glb models to display full-body clashes alongside portrait cut-ins of the character faces. This rendering process is executed via a headless Chromium driver with the existing HTML battle stage as a base. Will now test the rendering and inspect the output to fine-tune camera framing.

The rendering process will be modified to include a parameter for the target visual, such as "?shot=argon". This will trigger the use of the WebGL renderer within the existing HTML structure to create a full 1920x1080 painted scene. This scene incorporates loaded 3D models posed for a "clash" view on the stage, along with specified camera framing. Then, the renderer will output the full image for output.

The WebGL shader in the HTML will render the dressed models, full-body, in the main frame. The goal is a clash with blades crossing nearly, capes and skirts draping, and shadows grounded on the turf, using the ~/out/lowmarch-argon.png image. Simultaneously, the two corner bust portraits will represent the characters at a portrait scale. These portraits will focus on the head with adjustments to the camera position and size. The final step is exporting the composite image.

  • read_file{"EndLine":1598,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":1500}

    input

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

    result, 100 lines

    Showing lines 1500-1598 of 1737
    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:

agent

+21:45
reasoning

The runSheet("argon") function call within review/vroid-02/index.html triggers specific actions based on the kind variable. If kind equals "argon", the process involves setting a view, applying materials, and adjusting pixel ratio before creating a canvas element. The exact relationship between these steps is the focus.

Creating a canvas element with dimensions 1920x1080 and setting up a 2D rendering context. A sky gradient is painted on the context. The duel stage is rendered with specified settings for size, yaw angle, poses, and frame, and then drawn onto the canvas.

Two in-engine bust portrait cut-in cards are then drawn on the canvas, each with specific dimensions, positions, and associated character settings. These card renderings involve switching views, hiding certain elements, applying materials, and rendering.

  • edit_file{"Path":"~/work/lowmarch/review/vroid-02/index.html","Replacement":"async function runSheet(kind) {\n document.body.classList.add(\"sheet\");\n if (kind === \"argon\") {\n await setView(\"duel\");\n applyMaterials();\n R.setPixelRatio(1);\n const W = 1920, H = 1080, cv = document.createElement(\"canvas\");\n cv.width = W; cv.height = H;\n const ctx = cv.getContext(\"2d\");\n const bg = ctx.createLinearGradient(0, 0, 0, H);\n bg.addColorStop(0, \"#12101c\"); bg.addColorStop(0.58, \"#1e1a2e\"); bg.addColorStop(1, \"#14121f\");\n ctx.fillStyle = bg; ctx.fillRect(0, 0, W, H);\n R.setSize(W, H, false);\n setYaw(14);\n state.hidden = new Set(); applyMaterials();\n holdPose(\"clash\", 0);\n settleCloth();\n frameAt(new THREE.Vector3(0, 0.90, 0), 2.10, W, H, 8);\n render();\n ctx.drawImage(R.domElement, 0, 0, W, H);\n const pw = 340, ph = 380, pad = 28, py = H - ph - pad;\n for (const [who, yaw, px, accent, tag, sub] of [\n [\"aldric\", 32, pad, \"#b08b3f\", \"ALDRIC · LORD\", \"arm_m_heroic cage + plates.py / outfit.py\"],\n [\"elaine\", 328, W - pw - pad, \"#5b7fd6\", \"ELAINE · KNIGHT\", \"arm_f_slender cage + draped VRoid hair\"]\n ]) {\n state.who = who;\n await setView(\"bust\");\n state.hidden = new Set([\"sword\", \"weapon\"]); applyMaterials();\n setYaw(yaw);\n holdPose(\"ref\", 0);\n settleCloth();\n R.setSize(pw, ph, false);\n const hd = active()[0].root.getObjectByName(\"J_Bip_C_Head\").getWorldPosition(new THREE.Vector3());\n frameAt(new THREE.Vector3(hd.x, hd.y + 0.01, hd.z), 0.43, pw, ph, 4);\n render();\n ctx.save();\n ctx.fillStyle = \"rgba(16, 14, 24, 0.88)\";\n ctx.fillRect(px, py, pw, ph);\n ctx.beginPath(); ctx.rect(px + 2, py + 2, pw - 4, ph - 52); ctx.clip();\n ctx.drawImage(R.domElement, px, py - 10, pw, ph);\n ctx.restore();\n ctx.fillStyle = \"rgba(14, 12, 20, 0.94)\";\n ctx.fillRect(px, py + ph - 50, pw, 50);\n ctx.strokeStyle = accent; ctx.lineWidth = 2;\n ctx.strokeRect(px + 1, py + 1, pw - 2, ph - 2);\n ctx.beginPath(); ctx.moveTo(px, py + ph - 50); ctx.lineTo(px + pw, py + ph - 50); ctx.stroke();\n ctx.fillStyle = \"#f0ede6\"; ctx.font = \"600 14px system-ui, sans-serif\";\n ctx.fillText(tag, px + 14, py + ph - 28);\n ctx.fillStyle = \"#a5a0b8\"; ctx.font = \"12px ui-monospace, monospace\";\n ctx.fillText(sub, px + 14, py + ph - 11);\n }\n $(\"sheetOut\").textContent = cv.toDataURL(\"image/png\");\n document.title = \"sheet ready\";\n return;\n }\n const lineup = kind === \"lineup\", duel = kind === \"duel\" || lineup;","Target":"async function runSheet(kind) {\n document.body.classList.add(\"sheet\");\n const lineup = kind === \"lineup\", duel = kind === \"duel\" || lineup;"}

    input

    {
      "Path": "~/work/lowmarch/review/vroid-02/index.html",
      "Replacement": "async function runSheet(kind) {\n  document.body.classList.add(\"sheet\");\n  if (kind === \"argon\") {\n    await setView(\"duel\");\n    applyMaterials();\n    R.setPixelRatio(1);\n    const W = 1920, H = 1080, cv = document.createElement(\"canvas\");\n    cv.width = W; cv.height = H;\n    const ctx = cv.getContext(\"2d\");\n    const bg = ctx.createLinearGradient(0, 0, 0, H);\n    bg.addColorStop(0, \"#12101c\"); bg.addColorStop(0.58, \"#1e1a2e\"); bg.addColorStop(1, \"#14121f\");\n    ctx.fillStyle = bg; ctx.fillRect(0, 0, W, H);\n    R.setSize(W, H, false);\n    setYaw(14);\n    state.hidden = new Set(); applyMaterials();\n    holdPose(\"clash\", 0);\n    settleCloth();\n    frameAt(new THREE.Vector3(0, 0.90, 0), 2.10, W, H, 8);\n    render();\n    ctx.drawImage(R.domElement, 0, 0, W, H);\n    const pw = 340, ph = 380, pad = 28, py = H - ph - pad;\n    for (const [who, yaw, px, accent, tag, sub] of [\n      [\"aldric\", 32, pad, \"#b08b3f\", \"ALDRIC · LORD\", \"arm_m_heroic cage + plates.py / outfit.py\"],\n      [\"elaine\", 328, W - pw - pad, \"#5b7fd6\", \"ELAINE · KNIGHT\", \"arm_f_slender cage + draped VRoid hair\"]\n    ]) {\n      state.who = who;\n      await setView(\"bust\");\n      state.hidden = new Set([\"sword\", \"weapon\"]); applyMaterials();\n      setYaw(yaw);\n      holdPose(\"ref\", 0);\n      settleCloth();\n      R.setSize(pw, ph, false);\n      const hd = active()[0].root.getObjectByName(\"J_Bip_C_Head\").getWorldPosition(new THREE.Vector3());\n      frameAt(new THREE.Vector3(hd.x, hd.y + 0.01, hd.z), 0.43, pw, ph, 4);\n      render();\n      ctx.save();\n      ctx.fillStyle = \"rgba(16, 14, 24, 0.88)\";\n      ctx.fillRect(px, py, pw, ph);\n      ctx.beginPath(); ctx.rect(px + 2, py + 2, pw - 4, ph - 52); ctx.clip();\n      ctx.drawImage(R.domElement, px, py - 10, pw, ph);\n      ctx.restore();\n      ctx.fillStyle = \"rgba(14, 12, 20, 0.94)\";\n      ctx.fillRect(px, py + ph - 50, pw, 50);\n      ctx.strokeStyle = accent; ctx.lineWidth = 2;\n      ctx.strokeRect(px + 1, py + 1, pw - 2, ph - 2);\n      ctx.beginPath(); ctx.moveTo(px, py + ph - 50); ctx.lineTo(px + pw, py + ph - 50); ctx.stroke();\n      ctx.fillStyle = \"#f0ede6\"; ctx.font = \"600 14px system-ui, sans-serif\";\n      ctx.fillText(tag, px + 14, py + ph - 28);\n      ctx.fillStyle = \"#a5a0b8\"; ctx.font = \"12px ui-monospace, monospace\";\n      ctx.fillText(sub, px + 14, py + ph - 11);\n    }\n    $(\"sheetOut\").textContent = cv.toDataURL(\"image/png\");\n    document.title = \"sheet ready\";\n    return;\n  }\n  const lineup = kind === \"lineup\", duel = kind === \"duel\" || lineup;",
      "Target": "async function runSheet(kind) {\n  document.body.classList.add(\"sheet\");\n  const lineup = kind === \"lineup\", duel = kind === \"duel\" || lineup;"
    }

    result, 1 line

    Made 1 replacement in ~/work/lowmarch/review/vroid-02/index.html starting at line 1510 (+53/-0 lines).

agent

+22:14
reasoning

Attempting to copy the HTML file to the output directory. Next, the Python script will be executed with the "argon" argument, presumably to process data. Finally, the generated image file will be copied to the specified destination, completing the data processing pipeline.

  • run_command{"CommandLine":"cp review/vroid-02/index.html review/out/vroid-02/site/index.html && mkdir -p ~/out && /usr/bin/time -f \"wall=%Es\" python3 review/vroid-02/sheets.py argon && cp review/out/vroid-02/site/sheet-argon.png ~/out/lowmarch-argon.png","WaitMsBeforeAsync":10000,"toolSummary":"Render the painted game frame via headless Chromium"}error

    input

    {
      "CommandLine": "cp review/vroid-02/index.html review/out/vroid-02/site/index.html && mkdir -p ~/out && /usr/bin/time -f \"wall=%Es\" python3 review/vroid-02/sheets.py argon && cp review/out/vroid-02/site/sheet-argon.png ~/out/lowmarch-argon.png",
      "WaitMsBeforeAsync": 10000,
      "toolSummary": "Render the painted game frame via headless Chromium"
    }

    result, error, 6 lines

    Command exited with code 1.
    
    Command output:
    argon: ~/work/lowmarch/review/out/vroid-02/site/sheet_argon.png (6s)
    wall=0:06.08s
    cp: cannot stat 'review/out/vroid-02/site/sheet-argon.png': No such file or directory
  • run_command{"CommandLine":"cp review/out/vroid-02/site/sheet_argon.png ~/out/lowmarch-argon.png","WaitMsBeforeAsync":5000,"toolSummary":"Copy sheet_argon.png to ~/out/lowmarch-argon.png"}

    input

    {
      "CommandLine": "cp review/out/vroid-02/site/sheet_argon.png ~/out/lowmarch-argon.png",
      "WaitMsBeforeAsync": 5000,
      "toolSummary": "Copy sheet_argon.png to ~/out/lowmarch-argon.png"
    }

    result, 3 lines

    Command exited with code 0.
    
    No output from the command.
  • read_file{"Path":"~/out/lowmarch-argon.png"}

    input

    {
      "Path": "~/out/lowmarch-argon.png"
    }

    result, 1 line

    Showing binary file of type image/png
    step_196_media_0.jpg
    step_196_media_0.jpg

agent

+22:40
reasoning

The rendered image ~/out/lowmarch-argon.png reveals a critical visual element: Elaine's presence. This visual confirmation is a significant development, suggesting the core image generation process is functioning as intended.

The initial model shows the steel breastplate of the cuirass compressing the bust, leading to cloth poking through. This likely occurred because the wrap function smoothed the breastplate, shrinking it. The gear.breastplate function constructs a more rigid breastplate that should resolve the penetration issue by sitting outside the bodice, as it does not rely on smoothing.

The raised arm in the duel pose is causing the mantle to stretch and clip with the breastplate. The tabard also presents a problem; it's going between the legs when it should be draped over the front leg. Reviewing the cloth simulation reveals that closed skirts handle collision differently than open cloth panels, where the reset function might be introducing an unwanted initial condition.

The tabard's collision behavior appears linked to its initial position and the reset function, with forward positioning before settling resulting in proper draping. The clean rendering of the bust portraits suggests the head model, including hair and shoulder elements, is correctly integrated with the character mesh and collision systems. Observed face yaw angles in the portraits reveal a minor directional offset, suggesting a potential camera angle adjustment is needed for consistent character facing.

Adjusting the camera yaw for Aldric and Elaine to face each other inward is the next step to improve the portrait cut-ins. The initial configuration shows both characters looking away from the center; this should resolve with the yaw swap. The original wrap function caused the bodice to penetrate the breastplate on the arm_f_slender model, so reviewing the tools/outfit.py file to understand the wrap function is necessary to determine if the gear.breastplate fix has been correctly incorporated.

  • read_file{"EndLine":275,"Path":"~/work/lowmarch/tools/outfit.py","StartLine":215}

    input

    {
      "EndLine": 275,
      "Path": "~/work/lowmarch/tools/outfit.py",
      "StartLine": 215
    }

    result, 62 lines

    Showing lines 215-275 of 1282
    215:     def bind(self, pc, allow=None, fallback=None, rigid=None, blend=None, surface=None):
    216:         """Attach skin weights to a piece: copied from the body under it (optionally limited to
    217:         some bones), or rigid on one bone / a fixed blend."""
    218:         if pc is None:
    219:             return None
    220:         n = len(pc["pos"])
    221:         if rigid or blend:
    222:             pc["J"], pc["W"] = rigid_weights(n, self.jnames, rigid, blend)
    223:         else:
    224:             pc["J"], pc["W"] = transfer_weights(pc["pos"], None, self.J, self.W, surface=surface or self.surf,
    225:                                                 allow=allow, jnames=self.jnames, fallback=fallback)
    226:         pc["jnames"] = self.jnames
    227:         return pc
    228: 
    229: 
    230: def without(pc, bones, max_w=0.3):
    231:     """A piece's triangles away from some bones, as (pos, tri) for merge_surfaces: a bodice's torso
    232:     without its sleeves. Casting a waist ring onto a garment with its sleeves in it catches the
    233:     hanging arms at the sides (the reference pose has the arms down beside the hips)."""
    234:     hit = np.array([any(b in n for b in bones) for n in pc["jnames"]])
    235:     w = (hit[pc["J"]] * pc["W"]).sum(1)
    236:     return pc["pos"], pc["tri"][(w[pc["tri"]] < max_w).all(1)]
    237: 
    238: 
    239: def inherit(child, parent):
    240:     """Trim and hardware take the weights of the nearest vertex of the piece they sit on."""
    241:     _, i = cKDTree(parent["pos"]).query(child["pos"])
    242:     child["J"], child["W"], child["jnames"] = parent["J"][i], parent["W"][i], parent["jnames"]
    243:     return child
    244: 
    245: 
    246: def near_normals(pc, pts):
    247:     return pc["nrm"][cKDTree(pc["pos"]).query(pts)[1]]
    248: 
    249: 
    250: # ---- garments ------------------------------------------------------------------------
    251: def wrap(fit, name, role, bones, offset, min_w=0.5, exclude=(), y_min=None, y_max=None, subdiv=0,
    252:          base=None, hems=(), smooth=15, cut=None, refloor=False, clamp=False):
    253:     """A garment shrink-wrapped onto the body region that follows `bones`. cut: (normal, d), keep only
    254:     the skin below that plane (n.p < d, give or take a centimetre; pair it with a hem on the same plane).
    255:     refloor: after the hems, push out whatever a hem pulled into the skin (a hem moves its edge straight
    256:     along the plane's normal, which sinks it into a sloping hip; off by default so finished costumes
    257:     don't drift). clamp: every vertex past a hem's plane goes onto it, not just the edge's (pass y_min
    258:     and y_max a few centimetres past the hems: large skin triangles crossing a hem line otherwise leave
    259:     notches as deep as a triangle)."""
    260:     T = fit.tris_for(bones, min_w, exclude, y_min, y_max)
    261:     if cut is not None:
    262:         n_ = np.asarray(cut[0], float) / np.linalg.norm(cut[0])
    263:         T = T[(fit.pos[T] @ n_).max(1) < cut[1] + 0.01]
    264:     if not len(T):
    265:         return None
    266:     pos, tri, used = compact(fit.pos, T)
    267:     levels = []
    268:     for _ in range(subdiv):
    269:         pos, tri, par = subdivide(pos, tri, with_parents=True)
    270:         levels.append(par)
    271:     out = shrink_wrap(pos, tri, base or fit.surf, offset, smooth=smooth)
    272:     for n, d in hems:
    273:         out = flatten_hem(out, tri, n, d)
    274:         if clamp:
    275:             n_ = np.asarray(n, float) / np.linalg.norm(n)
  • read_file{"EndLine":310,"Path":"~/work/lowmarch/tools/outfit.py","StartLine":270}

    input

    {
      "EndLine": 310,
      "Path": "~/work/lowmarch/tools/outfit.py",
      "StartLine": 270
    }

    result, 42 lines

    Showing lines 270-310 of 1282
    270:         levels.append(par)
    271:     out = shrink_wrap(pos, tri, base or fit.surf, offset, smooth=smooth)
    272:     for n, d in hems:
    273:         out = flatten_hem(out, tri, n, d)
    274:         if clamp:
    275:             n_ = np.asarray(n, float) / np.linalg.norm(n)
    276:             over = out @ n_ - d
    277:             out = out - np.outer(np.maximum(over, 0.0), n_)
    278:     if refloor and hems:
    279:         surf = base or fit.surf
    280:         d2, cp2, ti2 = surf.query(out)
    281:         low = d2 < offset * 0.75
    282:         out[low] = cp2[low] + surf.fn[ti2[low]] * offset * 0.75
    283:     pc = piece(name, role, out, tri)
    284:     # weights come from the exact skin each vertex grew from: copying from the nearest skin instead
    285:     # let the inside of one boot pick up the other leg's bones
    286:     pc["J"], pc["W"] = blend_weights(fit.J[used], fit.W[used], int(fit.J.max()) + 1, levels)
    287:     pc["jnames"] = fit.jnames
    288:     if getattr(fit, "cloth_hull", False):             # a body with muscle relief: sleeves span the hollows
    289:         hw = lambda b: (np.array([b == n for n in fit.jnames])[pc["J"]] * pc["W"]).sum(1)
    290:         axes = []
    291:         for sd in ("L", "R"):
    292:             for b0, b1 in (("UpperArm", "LowerArm"), ("LowerArm", "Hand"), ("UpperLeg", "LowerLeg"), ("LowerLeg", "Foot"),
    293:                            ("Foot", "ToeBase")):                  # (boots over the foot: no toes showing)
    294:                 n0, n1 = f"J_Bip_{sd}_{b0}", f"J_Bip_{sd}_{b1}"
    295:                 if n0 in fit.bone and n1 in fit.bone:
    296:                     m = hw(n0) + (hw(n1) if b0 == "Foot" else 0.0)    # the foot's segment takes the toes too
    297:                     axes.append((m >= 0.6, fit.bone[n0], fit.bone[n1], b0 == "Foot"))
    298:         pc["pos"] = limb_hull(pc["pos"], tri, axes)
    299:         pc["nrm"] = vertex_normals(pc["pos"], tri)
    300:     pc["loops"] = boundary_loops(tri)
    301:     return pc
    302: 
    303: 
    304: def loop_trim(name, role, garment, pick, width=0.008, lift=0.0015):
    305:     """Trim along one of a garment's open edges: the loop that scores highest under `pick`."""
    306:     loops = garment.get("loops") or []
    307:     if not loops:
    308:         return None
    309:     best = max(loops, key=lambda L: pick(garment["pos"][L]))
    310:     return inherit(ribbon(name, role, garment["pos"][best], width, lift, normals=garment["nrm"][best], closed=True), garment)