A 3D model pipeline, pushed by GPT-6.2-Astra

agent (cont.)

+1:06
  • exec_commandcat tools/mobs.py | head -310 && rg -n 'costume|COSTUMES' tools/outfit.py | tail -15 (+2 more)

    command

    cat tools/mobs.py | head -310 && rg -n 'costume|COSTUMES' tools/outfit.py | tail -15
    
    sed -n '175,276p' tools/export_glb.py && sed -n '197,269p;918,944p;1388,1432p' review/vroid-02/index.html
    
    ls ~/.local/share/lowmarch/vroid/lowmarch_bodies/cage | tail -80
    python3 -c 'import numpy,PIL; print(numpy.__version__,PIL.__version__)'
    cat ~/context/sortie-node_modules/three/package.json | head -12
    rg -n 'def path_for|CACHE|def bone_pose' tools/{cage,vroid_portrait}.py
    sed -n '1,182p' tools/export_glb.py

    result, 720 lines

    Script completed
    Wall time 0.3 seconds
    Output:
    Warning: truncated output (original token count: 10435)
    Total output lines: 744
    
    """Common enemy units: one costume per class, built from gear.py on any base body. Generic but detailed:
    layered padding, mail and plate, riveted straps, an army colour on the cloth and shields (portrait
    guide, lesson 15). Pair each with a build and a face from gear.BUILDS / gear.FACES in the cast.
    """
    import numpy as np
    
    import outfit as O
    import gear as G
    from fitting import Surface, merge_surfaces
    from vrm import bone_weight
    
    
    def _base(fit, shirt="padding", legs="cloth", boots="boot", gloves="glove", knee=None, shirt_subdiv=0, boot_top=None):
        """Under layers every class shares: a shirt with sleeves to the wrist, trousers, boots to below
        the knee (or to boot_top: above the knee, they take the thigh too), gloves. Returns the pieces and
        the shirt (what coats are fitted over)."""
        B = fit.bone
        nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"]
        knee = B["J_Bip_L_LowerLeg"][1] if knee is None else knee
    
        def cuff(side):
            a, h = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"]
            n = (h - a) / np.linalg.norm(h - a)
            return n, n @ (h - n * 0.02)
        torso = ("Spine", "Chest", "UpperChest", "Bust", "Shoulder", "UpperArm", "LowerArm", "Neck", "Hips")
        # the neckline: a straight hem, lower at the throat than at the back of the neck (a level cut of
        # whole triangles left a saw-tooth edge, and a big trapezius showed above it)
        nh = np.array([0.0, 1.0, -0.3]) / np.linalg.norm([0.0, 1.0, -0.3])
        neckline = (nh, float(nh @ (nk + np.array([0.0, 0.012, 0.0]))))
        s = O.wrap(fit, "shirt", shirt, torso, offset=0.006, exclude=("UpperLeg",), y_min=hips[1] - 0.04,
                   y_max=nk[1] + 0.05, cut=neckline, hems=[cuff("L"), cuff("R"), neckline], subdiv=shirt_subdiv)
        t = O.wrap(fit, "trousers", legs, ("Hips", "UpperLeg", "LowerLeg"), offset=0.007, y_max=hips[1] + 0.02, subdiv=1)
        top = knee - 0.07 if boot_top is None else boot_top
        b = O.wrap(fit, "boots", boots, ("LowerLeg", "Foot", "ToeBase") + (("UpperLeg",) if top > knee else ()), offset=0.015,
                   y_max=top, subdiv=1, hems=[((0, 1, 0), top - 0.005)])
        g = O.wrap(fit, "gloves", gloves, ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), offset=0.003, min_w=0.3, smooth=4)
        out = [p for p in (s, t, b, g) if p is not None]
        for p, grp in zip(out, ("doublet", "trousers", "boots", "gloves")):
            p["group"] = grp
        return out, s, t, b
    
    
    def underwear(fit, band=False):
        """Plain shorts (and a chest band with band=True) for inspecting bare bodies (the armory page, built
        in the T-pose): hips to mid-thigh, close to the skin."""
        B = fit.bone
        hips, knee = B["J_Bip_C_Hips"][1], B["J_Bip_L_LowerLeg"][1]
        lo, hi = (hips + knee) / 2 + 0.03, hips + 0.07
        # all the skin between the hems but the arms' (they hang there in the fitting pose): taking only skin
        # weighted to the hips, legs and spine left holes where MakeHuman weights it to the chest or elsewhere
        out = [O.wrap(fit, "shorts", "cloth", ("J_",), offset=0.004, y_min=lo - 0.04, y_max=hi + 0.04, subdiv=1,
                      exclude=("Shoulder", "Arm", "Hand", "Thumb", "Index", "Middle", "Ring", "Little"),
                      hems=[((0, 1, 0), hi - 0.005), ((0, -1, 0), -(lo + 0.005))], refloor=True, clamp=True)]
        if band:
            ch, uc = B["J_Bip_C_Chest"][1], B["J_Bip_C_UpperChest"][1]
            blo, bhi = ch - 0.01, uc + 0.06
            # like the shorts: triangles past the hems taken and clamped onto them (dropping them notched the
            # top edge into steps on broad backs), every bone but the arms'
            out.append(O.wrap(fit, "band", "cloth", ("J_",), offset=0.004, y_min=blo - 0.03, y_max=bhi + 0.03, subdiv=1,
                              exclude=("Shoulder", "Arm", "Hand", "Thumb", "Index", "Middle", "Ring", "Little"),
                              hems=[((0, 1, 0), bhi - 0.005), ((0, -1, 0), -(blo + 0.005))], refloor=True, clamp=True))
        out = [p for p in out if p is not None]
        for p in out:
            p["group"] = "underwear"
        fit.keep_skin = ("J_",)                          # bare everywhere else: keep all the skin (VRoid 2 weights some to J_Sec_ bones)
        # but not the skin well inside the shorts: on fitted bodies (tools/fit.py) it came through the waistband.
        # Never the arms', which hang beside the hips in the fitting pose
        arms = ("Shoulder", "Arm", "Hand", "Thumb", "Index", "Middle", "Ring", "Little")
        fit.drop_skin = lambda p: ((p["pos"][:, 1] > lo + 0.015) & (p["pos"][:, 1] < hi - 0.015)
                                   & (bone_weight(p, arms) < 0.05))
        return out
    
    
    def underwear_f(fit):
        return underwear(fit, band=True)
    
    
    def _under(shirt):
        return Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand")))
    
    
    def _surf(pcs, *names, prefix=False):
        sel = [p for p in pcs if (p["material"].startswith(tuple("OUTFIT_" + n for n in names)) if prefix
                                  else p["material"] in tuple("OUTFIT_" + n for n in names))]
        return merge_surfaces(*[(p["pos"], p["tri"]) for p in sel])
    
    
    def soldier(fit, legs="breeches"):
        """Halberd infantry, after the study's Soldier: a kettle hat, a doublet in the army colour with
        full sleeves bagging into gauntlets that reach almost to the elbow, a short breastplate with a
        plackart (full width to the armpits), a fauld of round scales to mid-thigh, a belt, a halberd
        held in both hands (the cast's polearm stance, tools/clips.py). No puff or band on the upper arm:
        the study's soldiers have neither, and on a real arm a puff read as a bicep.
        legs: "breeches" (baggy, bagging over calf boots: the study's men) or "tights" (with boots to
        above the knee: the study's women)."""
        B = fit.bone
        hips = B["J_Bip_C_Hips"]
        knee = B["J_Bip_L_LowerLeg"][1]
        gauntlet = 0.70                                         # of the forearm, from the wrist
        y_hem = hips[1] - 0.20                                  # the fauld's
        boot_top = knee + 0.08 if legs == "tights" else knee - 0.07
        out, shirt, trousers, boots = _base(fit, shirt="signature", legs="cloth", boots="boot", shirt_subdiv=1,
                                            boot_top=boot_top)
        G.loose_sleeves(fit, shirt, cuff=gauntlet)
        if legs == "breeches":
            G.breeches(fit, trousers, boots, y_hem, boot_top - 0.005)
        else:
            G.flare_boots(fit, boots, boot_top - 0.005, ease=0.008)
        under = _under(shirt)
        out += G.breastplate(fit, under, arm=64.0)
        plate = _surf(out, "breastplate", prefix=True)
        # the guard's wide stance: the fauld follows the thighs closely and clears the seat
        out += G.scale_skirt(fit, under, hips[1] + 0.06, y_hem, role="mail", share=0.15,
                             clear=Surface(trousers["pos"], trousers["tri"]))
        G.slim_under(fit, trousers, y_hem)                      # and what it hides can't come through it
        belt, front = O.belt(fit, "belt", "leather", plate, hips[1] + 0.05, height=0.034, offset=0.004)
        out.append(belt)
        cuffs = G.cuffs(fit, length=gauntlet, flare=0.034)
        G.tuck_sleeves(fit, shirt, cuffs)
        out += cuffs
        out += G.coif(fit, role="padding")
        out += G.helmet(fit, "kettle")
        out += G.halberd(fit, grip=0.50)                         # the rear hand near the butt, as the study holds it
        return out
    
    
    def soldier_f(fit):
        """The soldier as the study draws its women: tights and boots to above the knee."""
        return soldier(fit, legs="tights")
    
    
    def fighter(fit):
        """Sword and round shield, after the study's Fighter: a kettle hat worn low, a quilted gambeson with
        full sleeves, a breastplate, lamed spaulders, a knife-pleated skirt in the army colour, greaves, a
        wooden round shield, an arming sword."""
        B = fit.bone
        hips = B["J_Bip_C_Hips"]
        knee = B["J_Bip_L_LowerLeg"][1]
        out, shirt, trousers, boots = _base(fit, shirt="padding", legs="cloth", boots="boot")
        under = _under(shirt)
        out += G.quilted(fit, under, role="padding", y_hem=hips[1] - 0.02, flare=0.02, sleeve_end=0.95)
        gam = _surf(out, "gambeson", "gambeson_skirt")
        out += G.pleated_skirt(fit, gam, hips[1] + 0.05, hips[1] - 0.30, role="signature")
        out += G.breastplate(fit, gam)
        plate_body = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate", "padding")], (fit.pos, fit.tri))
        for side in ("L", "R"):
            sp, rims = O.pauldron(fit, f"spaulder_{side}", "steel", plate_body, side=side,
                                  lames=((0, 56, 0.024, 0.032), (47, 73, 0.022, 0.030), (65, 91, 0.020, 0.028)), spread=105)
            out += G._group(sp + [O.inherit(O.pipe(f"spaulder_{side}_roll{k}", "steel", r_, r=0.0028), pc)
                                  for k, (pc, r_) in enumerate(zip(sp, rims))], "plate")
            ll, ft = B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"]
            top = (knee - 0.085 - ll[1]) / (ft[1] - ll[1])
            gv, rims = O.limb_lames(fit, f"greave_{side}", "steel", O.side_of(boots, side), ll, ft, ((top, 0.80, 0.008, 0.011),),
                                    rmax=0.11)
            fit.bind(gv[0], rigid=f"J_Bip_{side}_LowerLeg")
            out += G._group(gv + [O.inherit(O.pipe(f"greave_{side}_roll{k}", "steel", r_, r=0.0028), gv[0])
                                  for k, r_ in enumerate(rims[0])], "plate")
        belt, front = O.belt(fit, "belt", "leather", _surf(out, "breastplate", prefix=True), hips[1] + 0.05, height=0.036,
                             offset=0.004)
        out.append(belt)
        out += G.cuffs(fit, length=0.32)
        out += G.coif(fit, role="padding")
        out += G.helmet(fit, "kettle", lift=0.032)
        out += G.round_shield(fit)
        out += O.sword(fit, "R", blade_len=0.70, hilt="metal")
        return out
    
    
    def housecarl(fit):
        """An axeman in mail, after the study's Housecarl: a nasal helm over a mail coif, a mail hauberk to
        mid-thigh over the gambeson, a short cape in the army colour, a wide belt, big cuffs, a long axe."""
        B = fit.bone
        hips = B["J_Bip_C_Hips"]
        out, shirt, trousers, boots = _base(fit, shirt="padding", legs="cloth", boots="boot")
        under = _under(shirt)
        out += G.quilted(fit, under, role="padding", y_hem=hips[1] - 0.26, sleeve_end=0.95)
        gam = _surf(out, "gambeson", "gambeson_skirt")
        out += G.mail_shirt(fit, gam, y_hem=hips[1] - 0.16)
        mail = _surf(out, "hauberk", prefix=True)
        belt, front = O.belt(fit, "belt", "leather", mail, hips[1] + 0.04, height=0.05, offset=0.006)
        out.append(belt)
        body = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("mail", "padding")], (fit.pos, fit.tri))
        mt, grid, hood = O.mantle(fit, "cape", "signature", body)
        out += G._group([mt], "mantle")
        out += G.cuffs(fit, length=0.34, flare=0.036)
        out += G.coif(fit, role="mail")
        out += G.helmet(fit, "nasal")
        out += G.axe(fit, haft=1.30, blade=0.26, grip=0.60)
        return out
    
    
    def hoplite(fit):
        """Heavy infantry: a close helm, plate over mail (riveted coat of plates, spaulders, greaves), a
        tabard in the army colour, a tall tower shield and a spear."""
        B = fit.bone
        hips, nk = B["J_Bip_C_Hips"], B["J_Bip_C_Neck"]
        knee = B["J_Bip_L_LowerLeg"][1]
        out, shirt, trousers, boots = _base(fit, shirt="padding", legs="cloth", boots="boot")
        under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand")))
        out += G.quilted(fit, under, role="padding", y_hem=hips[1] - 0.20, sleeve_end=0.95)
        gam = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p["material"] in ("OUTFIT_gambeson", "OUTFIT_gambeson_skirt")])
        out += G.mail_shirt(fit, gam, y_hem=hips[1] - 0.20)
        mail = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p["material"].startswith("OUTFIT_hauberk")])
        out += G.riveted_vest(fit, mail, role="signature", rivet_role="steel")
        plate_body = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate", "mail", "padding")],
                                    (fit.pos, fit.tri))
        for side in ("L", "R"):
            sp, rims = O.pauldron(fit, f"spaulder_{side}", "steel", plate_body, side=side,
                                  lames=((0, 56, 0.024, 0.032), (47, 73, 0.022, 0.030), (65, 91, 0.020, 0.028)), spread=110)
            out += sp + [O.inherit(O.pipe(f"spaulder_{side}_roll{k}", "steel", r_, r=0.0028), pc) for k, (pc, r_) in enumerate(zip(sp, rims))]
            ll, ft = B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"]
            top = (knee - 0.085 - ll[1]) / (ft[1] - ll[1])
            gv, rims = O.limb_lames(fit, f"greave_{side}", "steel", O.side_of(boots, side), ll, ft, ((top, 0.80, 0.008, 0.011),),
                                    rmax=0.11)
            fit.bind(gv[0], rigid=f"J_Bip_{side}_LowerLeg")
            out += gv + [O.inherit(O.pipe(f"greave_{side}_roll{k}", "steel", r_, r=0.0028), gv[0]) for k, r_ in enumerate(rims[0])]
        for p in out:
            if p["material"].startswith(("OUTFIT_spaulder", "OUTFIT_greave")):
                p["group"] = "plate"
        belt, front = O.belt(fit, "belt", "leather", merge_surfaces(*[(p["pos"], p["tri"]) for p in out
                                                                       if p["material"].startswith("OUTFIT_brigandine_front")
                                                                       or p["material"] == "OUTFIT_hauberk"]),
                             hips[1] + 0.03, height=0.04, offset=0.008)
        out.append(belt)
        over = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate", "mail")], (fit.pos, fit.tri))
        mt, grid, hood = O.mantle(fit, "capelet", "signature", over)
        out += G._group([mt, hood], "mantle")
        out += G.cuffs(fit, role="steel", length=0.36, flare=0.026)
        out += G.coif(fit, role="mail")
        out += G.helmet(fit, "close")
        emblem = [("poly", [(-0.09, 0.22), (0.09, 0.22), (0.09, -0.04), (0.0, -0.18), (-0.09, -0.04)], "paint"),
                  ("line", [(-0.13, 0.31), (0.13, 0.31)], 0.012, "paint")]
        out += G.shield(fit, "heater", role="steel", width=0.56, height=0.92, curve=0.45, emblem=emblem)
        out += G.spear(fit, length=2.2)
        return out
    
    
    def berserker(fit):
        """A huge axeman: bare arms, a fur mantle over a leather harness, wide belt, a two-bitted great axe."""
        B = fit.bone
        hips = B["J_Bip_C_Hips"]
        out, shirt, trousers, boots = _base(fit, shirt="leather", legs="cloth", boots="fur")
        # a sleeveless jerkin: the shirt's arms come off and the arms stay bare
        shirt["tri"] = O.without(shirt, ("UpperArm", "LowerArm", "Hand"))[1]
        fit.keep_skin = ("UpperArm", "LowerArm", "Shoulder")
        under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand")))
        out += G.riveted_vest(fit, under, role="leather", rivet_role="steel")
        shoulders = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate",)], (shirt["pos"], shirt["tri"]),
                                   (fit.pos, fit.tri))
        mt, grid, hood = O.mantle(fit, "mantle", "fur", shoulders)
        out += [mt]
        belt, front = O.belt(fit, "belt", "leather", under, hips[1] + 0.04, height=0.06, offset=0.016)
        out.append(belt)
        out += G.axe(fit, haft=1.15, blade=0.30, double=True, grip=0.45)
        return out
    
    
    def hunter(fit):
        """A woodland archer: a cloth hood and short cape, a leather jerkin over a linen shirt, a bow in the
        lowered hand, a quiver on the back."""
        B = fit.bone
        hips = B["J_Bip_C_Hips"]
        out, shirt, trousers, boots = _base(fit, shirt="linen", legs="cloth", boots="boot")
        under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand")))
        out += G.riveted_vest(fit, under, name="jerkin", role="leather", rivet_role="leather", y_bottom=hips[1] - 0.06)
        belt, front = O.belt(fit, "belt", "leather", under, hips[1] + 0.03, height=0.03, offset=0.020)
        out.append(belt)
        body = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") == "plate"], (shirt["pos"], shirt["tri"]),
                              (fit.pos, fit.tri))
        mt, grid, _ = O.mantle(fit, "cape", "signature", body)
        out.append(mt)
        out += G.hood(fit, role="signature", lift=0.022)
        out += G.bow(fit)
        out += G.quiver(fit)
        return out
    
    
    def thief(fit):
        """A light skirmisher: a scarf over the lower face, a short leather jerkin, a sash, a dagger."""
        B = fit.bone
        hips = B["J_Bip_C_Hips"]
        out, shirt, trousers, boots = _base(fit, shirt="cloth", legs="cloth", boots="boot")
        under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand")))
        out += G.riveted_vest(fit, under, name="jerkin", role="leather", rivet_role="steel", y_bottom=hips[1] - 0.02)
        sash, front = O.belt(fit, "sash", "signature", under, hips[1] + 0.05, height=0.05, offset=0.022, tilt=0.02)
        out.append(sash)
        # no hood: her own bob shows (a hood over it either bulged or let it through); the scarf masks her face
        ch = __import__("hair").head_chart(fit)               # a scarf over the nose and mouth
        from plates import outline_plate
        scarf, _ = outline_plate("scarf", "cloth", ch, -100, 100, lambda u: 150.0, lambda u: 104.0 - 6 * (abs(u) / 100) ** 2,
                                 offset=0.012, thickness=0.004, nu=40, nv=10, roll=0)
        fit.bind(scarf, rigid="J_Bip_C_Head")
        scarf["group"] = "hood"
        out.append(scarf)
        out += G.dagger(fit)
        return out
    
    
    def witch(fit):
        """A caster: a long robe with bell sleeves and a gold border, a sash, a tall pointed hat, a staff."""
        B = fit.bone
        hips = B["J_Bip_C_Hips"]
        out, shirt, trousers, boots = _base(fit, shirt="cloth", legs="cloth", boots="boot")
        under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand")))
        out += G.robe(fit, under, role="signature", split=14.0)
        rob = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p["material"] == "OUTFIT_robe"])
        sash, front = O.belt(fit, "sash", "gold", rob, hips[1] + 0.06, height=0.03, offset=0.006)
        out.append(sash)
        out += G.witch_hat(fit)
        out += G.staff(fit)
    1:"""Fantasy costume pieces, generated in code and fitted onto a VRoid body.
    19:A costume is a function of a Fit (body + bones in the reference pose) returning a list of pieces.
    164:    """What a costume is built against: the body skin (welded, measurable) and the bones, all in
    256:    along the plane's normal, which sinks it into a sloping hip; off by default so finished costumes
    1033:# ---- costumes -------------------------------------------------------------------------
    1035:    """The first lord costume, head to toe: tunic, tails, belt, trousers, boots, gloves, a standing collar,
    1267:COSTUMES = {"lord": lord, "lord_tunic": lord_tunic, "knight_dress": knight_dress,
    1272:    COSTUMES[f"mob_{_cls}"] = (lambda c: lambda fit: getattr(__import__("mobs"), c)(fit))(_cls)
    
    Warning: truncated output (original token count: 4016)
    Total output lines: 247
    
             "OUTFIT_tails": (("OUTFIT_tails_hem",), "gold", LEGS),
             "OUTFIT_tabard": (("OUTFIT_tabard_hem", "OUTFIT_tabard_edge0", "OUTFIT_tabard_edge1"), "heraldry", LEGS),
             "OUTFIT_tabard_back": (("OUTFIT_tabard_back_hem", "OUTFIT_tabard_back_edge0", "OUTFIT_tabard_back_edge1"),
                                    "heraldry", LEGS),
             "OUTFIT_skirt": (("OUTFIT_skirt_hem",), "heraldry", LEGS)}
    CLOTH_HEM_ONLY = {"OUTFIT_skirt"}            # border band on the hem row only (its waist has a gold trim)
    
    
    def scene_info(portrait, palette):
        """Everything the browser's pixel renderer and cloth solver need besides the meshes: palette
        bands per role, the lights, body colliders, cloth grids and the mouth curve (model space,
        turned to face +z like the GLB)."""
        import vroid_portrait as vp
        from vrm import bone_weight
        hexp = lambda c: palette[c]
        bands = lambda tbl: [[thr if thr > -5 else -9, hexp(c)] for thr, c in tbl]
        roles = {"face": dict(mode="bands", bands=bands(vp.SKIN_BANDS)),
                 "body": dict(mode="bands", bands=bands(vp.SKIN_BANDS), cap=hexp("4")),
                 "shadow": dict(mode="flat", color=hexp("3")),
                 "hair":…435 tokens truncated…                         edges="hem" if p["material"] in CLOTH_HEM_ONLY else "all")
        curve = None
        if getattr(portrait, "mouth_curve", None) is not None:
            face = [p for p, r in zip(portrait.prims, portrait.roles) if r == "face"]
            allp = np.concatenate([p["pos"] for p in face])
            alln = np.concatenate([p["nrm"] for p in face])
            from scipy.spatial import cKDTree
            _, i = cKDTree(allp).query(portrait.mouth_curve)
            curve = ((portrait.mouth_curve + alln[i] * 0.0015) * FLIP).tolist()
        marks = None
        if getattr(portrait, "marks", None):
            m = next(iter(portrait.marks.values()))
            img = Image.fromarray(np.where(m == 1, 128, 0).astype(np.uint8), "L")     # nose mark only; the mouth is a line
            b = io.BytesIO()
            img.save(b, "PNG", optimize=True)
            import base64
            marks = base64.b64encode(b.getvalue()).decode()
        # painted renderer: a material kind and one base colour per role; the shader builds the ramp
        pc = dict(signature="#7d1e2c", doublet="#2a2d3d", heraldry="#dfe2e8", leather="#5f3e2b", boot="#4a3326", glove="#5f3e2b",
                  steel="#a6adbb", gold="#b08b3f", hair=hexp("C"), trim="#b08b3f")
        pc.update(getattr(portrait, "paint", None) or {})
        skin = dict(kind="skin", base=pc.get("skin") or "#f8e1d5")                       # light skin unless a tone is set
        skin["ramp"] = skin_ramp(skin["base"])                                              # its lit, shade and deep shade
        paint = {"face": dict(skin), "body": dict(skin), "shadow": dict(skin, shade=True),   # shadow cards: skin in shade
                 "hair": dict(kind="hair", base=pc["hair"]),
                 "coat": dict(kind="cloth", base=pc["signature"]), "cape": dict(kind="cloth", base=pc["signature"]),
                 "signature": dict(kind="cloth", base=pc["signature"]), "doublet": dict(kind="cloth", base=pc["doublet"]),
                 "cloth": dict(kind="cloth", base=pc["doublet"]), "heraldry": dict(kind="cloth", base=pc["heraldry"]),
                 "leather": dict(kind="leather", base=pc["leather"]), "boot": dict(kind="leather", base=pc["boot"]),
                 "glove": dict(kind="leather", base=pc["glove"]), "metal": dict(kind="steel", base=pc["steel"]),
                 "steel": dict(kind="steel", base=pc["steel"]), "gold": dict(kind="gold", base=pc["gold"]),
                 "grass": dict(kind="world", base="#5a7a3a"), "dirt": dict(kind="world", base="#6a4a32"),
                 "stone": dict(kind="world", base="#7c7a86"),
                 "motif": dict(kind="cloth", base=pc.get("motif", "#3a44a0"))}       # decal paint on steel (tools/plates.py)
        for role, val in pc.items():                             # extra roles a cast entry names (cloth unless it says)
            if role not in paint and isinstance(val, str) and val.startswith("#"):
                paint[role] = dict(kind="cloth", base=val)
            elif role not in paint and isinstance(val, dict) and "base" in val:
                paint[role] = dict(kind=val.get("kind", "cloth"), base=val["base"])
        for role, g in (pc.get("grain…1016 tokens truncated…den: new Set(),
                    cloth: true, wind: false, playing: false, stepped: false, clip: "clash", pose: "out", compare: [], motion: "still",
                    physics: true };
    const charDef = name => CAM.characters.find(c => c.name === name);
    // a workshop page (camera.json "page"): its own title and notes, and no duel
    const PAGE = CAM.page || null;
    const NO_DUEL = PAGE?.duel === false;
    if (PAGE) {
      document.title = `${PAGE.title} · Lowmarch`;
      document.querySelector(".brand .eyebrow").textContent = PAGE.eyebrow || "Lowmarch";
      document.querySelector(".brand h1").textContent = PAGE.title;
      if (PAGE.notes) document.querySelector("#panel section ul").innerHTML = PAGE.notes;
    }
    // the armory: bodies compared side by side (the Compare view) in three poses, instead of clips and a lineup

    320 more lines not shown.