A 3D model pipeline, pushed by Fable 5.2

user

+40:16

just providing more steering information here. you're here as an adversarial agent intending to prove that you can do much, much better than the prior model who was working on this project. pull all the stops out and do whatever's necessary to break free of what plagues the current project, show me your best work. not just using the tools and following that project's footsteps, the point is a radical improvement that only you could do, compared to where this project has already tread.

agent

+41:40
reasoning

I'm going past the kit with two approaches: her own design, whose first build is running now, and my own perspective cel renderer built for the exported model's light, hair and face.

  • Bashcd ~/Projects/lowmarch-fable52 && date +%H:%M:%S && python3 - <<'E'

    command

    cd ~/Projects/lowmarch-fable52 && date +%H:%M:%S && python3 - <<'E'
    p="tools/whole/build.py"; s=open(p).read()
    old='''# her stance:'''
    new='''# her design: "kit" is Elaine's dress as the old kit builds it (the first frame); "wren" is tools/whole/wren.py
    DESIGN = os.environ.get("WHOLE_DESIGN", "kit")
    if DESIGN == "wren":
        import wren
        outfit.COSTUMES["whole_knight"] = wren.build
        CAST[NAME].update(shape=dict(src["shape"], **wren.SHAPE), paint=dict(CAST[NAME]["paint"], **wren.PAINT))
    # her stance:'''
    assert old in s; s=s.replace(old,new,1); open(p,"w").write(s)
    E
    cp -r review/out/whole review/out/whole2 && (time LOWMARCH_SITE=whole2 WHOLE_DESIGN=wren OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 python3 tools/whole/build.py arm_f_slender wren) 2>&1 | tail -25

    result, 17 lines

    19:14:36
    Traceback (most recent call last):
      File "~/Projects/lowmarch-fable52/tools/whole/build.py", line 127, in <module>
        r = build.character((n, None))
      File "~/Projects/lowmarch-fable52/review/vroid-02/build.py", line 192, in character
        p, c = portrait(name, "bust")
      File "~/Projects/lowmarch-fable52/review/vroid-02/build.py", line 159, in portrait
        return vp.Portrait(model_path(name, c), shape=c["shape"],
      File "~/Projects/lowmarch-fable52/tools/vroid_portrait.py", line 996, in __init__
        for pc in costume(fit):
      File "~/Projects/lowmarch-fable52/tools/whole/wren.py", line 193, in build
        legs_side = merge_surfaces((thigh[0], thigh[1]), (shin[0], shin[1]))
    TypeError: 'Surface' object is not subscriptable
    
    real	0m17.202s
    user	0m16.397s
    sys	0m0.502s
  • Bashcd ~/Projects/lowmarch-fable52 && grep -n "^def merge_surfaces" -A8 tools/fitting.py | head -12; sed -n 579,594p tools/outfit.py; python3 - <<'E'

    command

    cd ~/Projects/lowmarch-fable52 && grep -n "^def merge_surfaces" -A8 tools/fitting.py | head -12; sed -n 579,594p tools/outfit.py; python3 - <<'E'
    p="tools/whole/wren.py"; s=open(p).read()
    R=[("legs_side = merge_surfaces((thigh[0], thigh[1]), (shin[0], shin[1]))","legs_side = merge_surfaces(_pt(thigh), _pt(shin))"),
       ("merge_surfaces(fore, sleeve), la, hd,","merge_surfaces(_pt(fore), _pt(sleeve)), la, hd,"),
       ("arm_s = merge_surfaces(O.limb_surface(fit, (f\"{side}_LowerArm\", f\"{side}_UpperArm\"), side), sleeve)",
        "arm_s = merge_surfaces(_pt(O.limb_surface(fit, (f\"{side}_LowerArm\", f\"{side}_UpperArm\"), side)), _pt(sleeve))"),
       ("waist = merge_surfaces(plate, (hose[\"pos\"], hose[\"tri\"]))","waist = merge_surfaces(_pt(plate), (hose[\"pos\"], hose[\"tri\"]))"),
       ("hang = merge_surfaces((belt[\"pos\"], belt[\"tri\"]), plate, (hose[\"pos\"], hose[\"tri\"]))","hang = merge_surfaces((belt[\"pos\"], belt[\"tri\"]), _pt(plate), (hose[\"pos\"], hose[\"tri\"]))"),
       ("def _landmarks(fit):","def _pt(surf):\n    return surf.pos, surf.tri\n\n\ndef _landmarks(fit):")]
    for a,b in R:
        assert a in s, a[:50]; s=s.replace(a,b)
    open(p,"w").write(s)
    E
    (time LOWMARCH_SITE=whole2 WHOLE_DESIGN=wren OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 python3 tools/whole/build.py arm_f_slender wren) 2>&1 | tail -12

    result, 34 lines

    86:def merge_surfaces(*meshes):
    87-    pos, tri, off = [], [], 0
    88-    for p, t in meshes:
    89-        pos.append(p)
    90-        tri.append(np.asarray(t) + off)
    91-        off += len(p)
    92-    return Surface(np.concatenate(pos), np.concatenate(tri))
    93-
    94-
    def limb_surface(fit, bones, side=None):
        """The skin of one limb (bones matched by name), optionally only one side of the body, so ray
        casts out of a bone can't reach the torso or the other limb."""
        T = fit.tris_for(bones, min_w=0.35)
        if side:
            cx = fit.pos[T][:, :, 0].mean(1)
            T = T[cx < 0.01] if side == "L" else T[cx > -0.01]
        return Surface(fit.pos, T)
    
    
    def side_of(pc, side):
        """A piece's triangles on one side of the body (the character's left is -x)."""
        cx = pc["pos"][pc["tri"]][:, :, 0].mean(1)
        return Surface(pc["pos"], pc["tri"][cx < 0.0] if side == "L" else pc["tri"][cx > 0.0])
    
    
    wren.glb 6.8 MB, 58s
      wren: 10 keyframes checked; 2 with an arm through the body, 7 with an arm resting on it
        ! wren, attack at 0.68 s: right upper arm 2.7 cm inside the body
        ! wren, attack at 1.05 s: right upper arm 2.7 cm inside the body
    -> ~/Projects/lowmarch-fable52/review/out/whole2/site  97s
    
    real	1m37.544s
    user	1m25.953s
    sys	0m4.531s

agent

+43:51

Her new design built on the first full run (97 s). Shooting it now to see the costume, the haircut and the armour.

  • Bashcd ~/Projects/lowmarch-fable52 && mkdir -p review/out/whole2/shots && cd review/out/whole2/shots && python3 - <<'E'

    command

    cd ~/Projects/lowmarch-fable52 && mkdir -p review/out/whole2/shots && cd review/out/whole2/shots && python3 - <<'E'
    import json
    base=json.load(open("~/Projects/lowmarch-fable52/tools/whole/frame.json"))
    def sp(name, **kw):
        s=dict(base, w=960, h=540, scale=1); s.pop("key",None); s.update(kw); json.dump(s, open(name+".json","w"))
    pl=lambda y:{"wren":{"pos":[0,0,0],"yaw":y},"mob_soldier":{"pos":[6,0,0],"yaw":-70}}
    sp("ref_front", place=pl(0), clips={"wren":["ref",0]}, size=1.95, centre=[0,0.92,0], w=640, h=960)
    sp("ref_q", place=pl(40), clips={"wren":["ref",0]}, size=1.95, centre=[0,0.92,0], w=640, h=960)
    sp("ref_side", place=pl(90), clips={"wren":["ref",0]}, size=1.95, centre=[0,0.92,0], w=640, h=960)
    sp("ref_back", place=pl(200), clips={"wren":["ref",0]}, size=1.95, centre=[0,0.92,0], w=640, h=960)
    sp("head_f", place=pl(0), clips={"wren":["ref",0]}, size=0.5, centre=[0,1.50,0], w=640, h=640)
    sp("head_q", place=pl(40), clips={"wren":["ref",0]}, size=0.5, centre=[0,1.50,0], w=640, h=640)
    E
    for n in ref_front ref_q ref_side ref_back head_f head_q; do WHOLE_SITE=../site python3 ../../../../tools/whole/shoot.py $n.json $n.png >/dev/null & done; wait
    python3 -c "
    from PIL import Image
    a=[Image.open(n+'.png') for n in ('ref_front','ref_q','ref_side','ref_back')]
    W=Image.new('RGB',(640*4,960)); [W.paste(im,(640*i,0)) for i,im in enumerate(a)]; W.save('turn.png')
    b=[Image.open(n+'.png') for n in ('head_f','head_q')]
    W=Image.new('RGB',(1280,640)); [W.paste(im,(640*i,0)) for i,im in enumerate(b)]; W.save('heads.png')"; ls

    result, 24 lines

    FAILED 
    [1]   Exit 1                  WHOLE_SITE=../site python3 ../../../../tools/whole/shoot.py $n.json $n.png > /dev/null
    FAILED 
    FAILED 
    FAILED 
    [2]   Exit 1                  WHOLE_SITE=../site python3 ../../../../tools/whole/shoot.py $n.json $n.png > /dev/null
    [5]-  Exit 1                  WHOLE_SITE=../site python3 ../../../../tools/whole/shoot.py $n.json $n.png > /dev/null
    [6]+  Exit 1                  WHOLE_SITE=../site python3 ../../../../tools/whole/shoot.py $n.json $n.png > /dev/null
    FAILED 
    [3]-  Exit 1                  WHOLE_SITE=../site python3 ../../../../tools/whole/shoot.py $n.json $n.png > /dev/null
    FAILED 
    [4]+  Exit 1                  WHOLE_SITE=../site python3 ../../../../tools/whole/shoot.py $n.json $n.png > /dev/null
    Traceback (most recent call last):
      File "<string>", line 3, in <module>
      File "<string>", line 3, in <listcomp>
      File "[redacted: private path]/PIL/Image.py", line 3465, in open
        fp = builtins.open(filename, "rb")
    FileNotFoundError: [Errno 2] No such file or directory: 'ref_front.png'
    head_f.json
    head_q.json
    ref_back.json
    ref_front.json
    ref_q.json
    ref_side.json
  • Bashcd ~/Projects/lowmarch-fable52/review/out/whole2/shots && R=~/Projects/lowmarch-fable52 && for n in ref_front ref_q ref_side ref_back head_f head_q; do WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png >/dev/null & done; wait

    command

    cd ~/Projects/lowmarch-fable52/review/out/whole2/shots && R=~/Projects/lowmarch-fable52 && for n in ref_front ref_q ref_side ref_back head_f head_q; do WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png >/dev/null & done; wait
    python3 -c "
    from PIL import Image
    a=[Image.open(n+'.png') for n in ('ref_front','ref_q','ref_side','ref_back')]
    W=Image.new('RGB',(640*4,960)); [W.paste(im,(640*i,0)) for i,im in enumerate(a)]; W.save('turn.png')
    b=[Image.open(n+'.png') for n in ('head_f','head_q')]
    W=Image.new('RGB',(1280,640)); [W.paste(im,(640*i,0)) for i,im in enumerate(b)]; W.save('heads.png')"; ls *.png

    result, 14 lines

    [1]   Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null
    [5]-  Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null
    [6]+  Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null
    [2]   Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null
    [3]-  Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null
    [4]+  Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null
    head_f.png
    head_q.png
    heads.png
    ref_back.png
    ref_front.png
    ref_q.png
    ref_side.png
    turn.png
  • Read~/Projects/lowmarch-fable52/review/out/whole2/shots/turn.png

    input

    {
      "file_path": "~/Projects/lowmarch-fable52/review/out/whole2/shots/turn.png"
    }

    result

    no output

    turn.jpg
    turn.jpg
  • Read~/Projects/lowmarch-fable52/review/out/whole2/shots/heads.png

    input

    {
      "file_path": "~/Projects/lowmarch-fable52/review/out/whole2/shots/heads.png"
    }

    result

    no output

    heads.png
    heads.png
  • Bashcd ~/Projects/lowmarch-fable52 && sed -n 900,941p tools/outfit.py; sed -n 661,679p tools/outfit.py; grep -n "def pleated_skirt" -A12 tools/gear.py; grep -n "def skirt_cone" -A14 tools/gear.py | head -40

    command

    cd ~/Projects/lowmarch-fable52 && sed -n 900,941p tools/outfit.py; sed -n 661,679p tools/outfit.py; grep -n "def pleated_skirt" -A12 tools/gear.py; grep -n "def skirt_cone" -A14 tools/gear.py | head -40

    result, 89 lines

    def sabaton(fit, name, side, role="metal", pad=0.010, ridges=3, seg=26, rows=14):
        """A steel shoe over the whole foot (hides the base model's toes), built as a shoe last from
        the foot's measurements: sole outline rounded at heel and toe and widest at the ball, top
        rising from a rounded toe over the instep to the ankle at the heel. Lame ridges follow its
        cross-section over the instep. Rides the foot bone.
        (A squashed ellipsoid read as a triangular hoof; a shell projected onto the foot's convex
        hull creased on the hull's facets.)"""
        w = fit.weight((f"{side}_Foot", f"{side}_ToeBase"))
        P = fit.pos[w > 0.5]
        P = P[(P[:, 0] < 0.01) if side == "L" else (P[:, 0] > -0.01)]
        lo, hi = P.min(0), P.max(0)
        sole = lo[1] - 0.003
        ankle = fit.bone[f"J_Bip_{side}_Foot"][1]
        z_heel, z_toe = hi[2] + pad, lo[2] - pad                  # the foot points -z
        width = (hi[0] - lo[0]) + 2 * pad
        S = np.linspace(0, 1, seg)
        # centreline: the foot's middle at each station, smoothed
        cx = np.array([np.median(P[np.abs(P[:, 2] - (z_heel + t * (z_toe - z_heel))) < 0.02, 0])
                       if (np.abs(P[:, 2] - (z_heel + t * (z_toe - z_heel))) < 0.02).any() else (lo[0] + hi[0]) / 2 for t in S])
        cx = np.convolve(np.pad(cx, 3, mode="edge"), np.ones(7) / 7, "valid")
        ends = np.sin(np.pi * np.clip(S, 0, 1)) ** 0.42                 # rounds the heel and the toe
        half_w = width / 2 * ends * (0.80 + 0.20 * np.sin(np.pi * np.clip(S * 1.2, 0, 1)))   # widest at the ball
        tall = (ankle + 0.02 - sole) * (1 - 0.62 * np.clip((S - 0.25) / 0.6, 0, 1) ** 0.8)   # ankle at the heel, low toe
        tall = np.maximum(tall * np.sin(np.pi * np.clip(S, 0, 1)) ** 0.22, 0.004)
        phi = np.linspace(0, np.pi, rows)
        G = np.zeros((seg, rows, 3))
        for i, t in enumerate(S):
            z = z_heel + t * (z_toe - z_heel)
            G[i] = np.stack([cx[i] + half_w[i] * np.cos(phi), sole + tall[i] * np.sin(phi), np.full(rows, z)], 1)
        pos, tri = grid_mesh(G)
        c = np.array([(lo[0] + hi[0]) / 2, sole, (z_heel + z_toe) / 2])
        pc = piece(name, role, pos, tri, outward_from=c - [0, 0.05, 0])
        out = [pc]
        for k, t in enumerate(np.linspace(0.50, 0.74, ridges)):            # lames over the instep
            i = int(round(t * (seg - 1)))
            ring = G[i, 1:-1] + np.stack([np.cos(phi[1:-1]), np.sin(phi[1:-1]) * 1.0, np.zeros(rows - 2)], 1) * 0.0018
            out.append(pipe(f"{name}_ridge{k}", role, ring, r=0.0024))
        for q_ in out:
            fit.bind(q_, rigid=f"J_Bip_{side}_Foot")
        return out
    
    
    def joint_guard(fit, name, joint, child, toward, side, over, r=0.034, wing=0.062, depth=0.020):
        """Couter or poleyn: a domed cap over the point of the joint plus a fan wing on its outer
        side (study: about 1.5x the joint's width). Rides the lower bone."""
        J, C = fit.bone[joint], fit.bone[child]
        ax = (C - J) / np.linalg.norm(C - J)
        tw = np.asarray(toward, float) - ax * (np.asarray(toward, float) @ ax)
        tw /= np.linalg.norm(tw)
        lat = np.array([-1.0 if side == "L" else 1.0, 0, 0])
        lat -= ax * (lat @ ax) + tw * (lat @ tw)
        lat /= np.linalg.norm(lat)
        reach = over.cast(J, tw, rmax=0.15, far=True)
        reach = 0.045 if np.isnan(reach) else reach
        side_r = over.cast(J, lat, rmax=0.15, far=True)
        side_r = 0.045 if np.isnan(side_r) else side_r
        cap, cap_rim = dome(f"{name}_cap", "steel", J + tw * (reach - depth * 0.35), tw, -ax, r, depth)
        wg, wing_rim = fan(f"{name}_wing", "steel", J + lat * (side_r + 0.010) + tw * reach * 0.35, tw, ax, lat, wing)
        return [cap, wg], [cap_rim, wing_rim]
    
    
    913:def pleated_skirt(fit, under, y_top, y_hem, role="signature", name="skirt_pleats", flare=0.09, pleats=26, depth=0.012,
    914-                  split=0.0):
    915-    cone = skirt_cone(fit, under, y_top, y_hem, flare)
    916-    u0, u1 = (split, 360 - split) if split else (-179, 179)
    917-    tri = lambda u: abs(((u * pleats / 360.0) % 1.0) * 2 - 1)               # a triangle wave: knife pleats
    918-    fl = lambda u, v, s, t: depth * (1 - t) ** 0.6 * (tri(u) - 0.5)
    919-    pc, _ = outline_plate(name, role, cone, u0, u1, lambda u: y_hem, lambda u: y_top, offset=0.002, flare=fl,
    920-                          thickness=0.004, nu=pleats * 8, nv=14, roll=0, trim=0.0)
    921-    fit.bind(pc, allow=("Hips", "UpperLeg"), fallback="J_Bip_C_Hips")
    922-    stiffen(pc, fit, share=0.5)
    923-    return _group([pc], "dress")
    924-
    925-
    847:def skirt_cone(fit, under, y_top, y_hem, flare, cz=None, clear=None, gap=0.012, side=0.0):
    848-    """A skirt's cone: the waist's radius at y_top, flaring by `flare` down to y_hem. clear: a Surface
    849-    it must also stand outside of below its top (the seat and thighs: sized from the waist alone, a
    850-    seat that sits further out than the waist showed through the back), never narrowing going down,
    851-    by `gap`, plus `side` more at the hips' sides (where a wide stance swings the thighs out)."""
    852-    B = fit.bone
    853-    cz = float(B["J_Bip_C_Hips"][2]) if cz is None else cz
    854-    tc = TorsoChart(under, y_top - 0.05, y_top + 0.03, cz=cz, du=3.0, dv=0.01)
    855-    r0 = lambda u: float(tc.radius(u, y_top)) + 0.012
    856-    cone = lambda u, v: np.vectorize(r0)(u) + flare * np.clip((y_top - v) / (y_top - y_hem), 0, 1.3) ** 1.2
    857-    if clear is None:
    858-        return ConeChart(cone, cz=cz)
    859-    lc = TorsoChart(clear, y_hem - 0.03, y_top, cz=cz, du=3.0, dv=0.01)
    860-    us = np.arange(-180.0, 180.0, 3.0)
    861-    vs = np.arange(y_top, y_hem - 0.031, -0.01)                  # top down

agent

+45:40
reasoning

The costume now reads as a finished design. Next I'll fix the too-high fringe, the toes showing through the boots, the crumpling knee guards, and the overlong scabbard.

  • Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'

    command

    cd ~/Projects/lowmarch-fable52 && python3 - <<'E'
    p="tools/whole/wren.py"; s=open(p).read()
    a=s.index("def haircut("); b=s.index("def _pt(surf):")
    s=s[:a]+'''def haircut(fit, root=1.0, over_eye=0.25, centre=0.08, temple=0.13, sharp=70.0):
        """Cut the fringe above the eyes. The sample's fringe ends at the middle of the eye, so at game size the face
        reads as a pale shape with no eyes. Each fringe vertex's depth below the fringe's root line is held to the depth
        of the cut at its x (a soft minimum, so the hair above the cut is untouched and the ends come out blunt, as
        scissors leave them). The cut is highest over each eye, drops to a lock between the eyes and again at the
        temples, and the side locks beyond the temples are left alone.
        Heights are in spans of this face (eye line to chin) above the eye line, so another face gets the same cut."""
        lm = _landmarks(fit)
        span, eye_y = lm["span"], lm["eye_y"]
        ex = abs(lm["eyeR"][0])
        z_face = lm["eyeL"][2]
        y_root = eye_y + root * span                        # above this the hair is untouched
        for p, r in zip(fit._prims, fit._roles):
            if r != "hair":
                continue
            P = p["pos"]
            ax = np.abs(P[:, 0])
            h = (over_eye + (centre - over_eye) * np.exp(-(ax / (0.28 * ex)) ** 2)
                 + (temple - over_eye) * np.clip((ax - 1.05 * ex) / (0.6 * ex), 0, 1) ** 2)
            T = y_root - (eye_y + h * span)                 # how deep the fringe may hang at this x
            d = np.maximum(y_root - P[:, 1], 0.0)
            d2 = -np.logaddexp(-d * sharp, -T * sharp) / sharp
            wx = 1 - np.clip((ax - 1.60 * ex) / (0.35 * ex), 0, 1)            # fades out before the side locks
            wz = np.clip((z_face + 0.035 - P[:, 2]) / 0.02, 0, 1)             # only hair in front of the face
            w = (wx * wx * (3 - 2 * wx)) * (wz * wz * (3 - 2 * wz)) * (d > 0)
            P[:, 1] = P[:, 1] + ((y_root - d2) - P[:, 1]) * w
    
    
    '''+s[b:]
    # own base layers, shoes
    old=s[s.index("    boot_top = knee - 0.045\n"):s.index("    under = mobs._under(shirt)")]
    new='''    boot_top = knee - 0.045
    
        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")
        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]))))
        shirt = O.wrap(fit, "shirt", "signature", 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=1)
        hose = O.wrap(fit, "trousers", "doublet", ("Hips", "UpperLeg", "LowerLeg"), offset=0.006, y_max=hips[1] + 0.02, subdiv=1)
        # the boots stop at the ankle's foot: the base has toes, so the shoe is a last built over them (outfit.sabaton)
        boots = O.wrap(fit, "boots", "boot", ("LowerLeg", "Foot"), offset=0.014, y_max=boot_top, exclude=("ToeBase",),
                       subdiv=1, hems=[((0, 1, 0), boot_top - 0.005)])
        gloves = O.wrap(fit, "gloves", "glove", ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), offset=0.003,
                        min_w=0.3, smooth=4)
        out = _grouped([shirt], "doublet") + _grouped([hose], "trousers") + _grouped([boots], "boots") + _grouped([gloves], "gloves")
        out += _grouped(O.sabaton(fit, "shoe_L", "L", role="boot", pad=0.013, ridges=0)
                        + O.sabaton(fit, "shoe_R", "R", role="boot", pad=0.013, ridges=0), "boots")
        G.loose_sleeves(fit, shirt, ease=0.022, cuff=0.60)
        G.flare_boots(fit, boots, boot_top - 0.005, ease=0.009)
    '''
    s=s.replace(old,new)
    R=[('''                               legs_side, r=0.040, wing=0.058)''','''                               thigh, r=0.040, wing=0.046)'''),
       ('''        legs_side = merge_surfaces(_pt(thigh), _pt(shin))\n''',''),
       ('''    sdir = np.array([-0.06, -0.80, 0.60])''','''    sdir = np.array([-0.05, -0.92, 0.38])'''),
       ('''    scab = [O.tube("scabbard", "leather", s0, sdir, 0.86, 0.024, 0.014),''','''    scab = [O.tube("scabbard", "leather", s0, sdir, 0.80, 0.024, 0.014),'''),
       ('''            O.tube("scabbard_chape", "gold", s0 + sdir * 0.80, sdir, 0.07, 0.0165, 0.011)]''','''            O.tube("scabbard_chape", "gold", s0 + sdir * 0.74, sdir, 0.07, 0.0165, 0.011)]'''),
       ('''(("tabard", 0, 0.085, ytop - (knee + 0.10)), ("tabard_back", 180, 0.135, ytop - (knee - 0.17)))''','''(("tabard", 0, 0.105, ytop - (knee + 0.21)), ("tabard_back", 180, 0.135, ytop - (knee - 0.17)))'''),
      ]
    for a_,b_ in R:
        assert a_ in s, a_[:60]; s=s.replace(a_,b_)
    open(p,"w").write(s)
    p="tools/whole/build.py"; s=open(p).read()
    old='''    build.scenery(NAME)\n'''
    new='''    if not os.path.exists(f"{build.OUT}/plains.glb.json") or os.environ.get("WHOLE_GROUND"):
            build.scenery(NAME)                             # dresses her again (the kit builds terrain with a character)
    '''
    assert old in s; open(p,"w").write(s.replace(old,new))
    E
    grep -n "import mobs" tools/whole/wren.py; (time LOWMARCH_SITE=whole2 WHOLE_DESIGN=wren OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 python3 tools/whole/build.py arm_f_slender wren) 2>&1 | grep -E "Error|error|real|wren.glb|line" | head; cd review/out/whole2/shots && R=~/Projects/lowmarch-fable52 && for n in ref_front ref_q ref_side ref_back head_f head_q; do WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png >/dev/null 2>&1 & done; wait
    python3 -c "
    from PIL import Image
    a=[Image.open(n+'.png') for n in ('ref_front','ref_q','ref_side','ref_back')]
    W=Image.new('RGB',(640*4,960)); [W.paste(im,(640*i,0)) for i,im in enumerate(a)]; W.save('turn.png')
    b=[Image.open(n+'.png') for n in ('head_f','head_q')]
    W=Image.new('RGB',(1280,640)); [W.paste(im,(640*i,0)) for i,im in enumerate(b)]; W.save('heads.png')"

    result, 9 lines

    23:import mobs
    wren.glb 6.6 MB, 48s
    real	0m48.598s
    [1]   Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1
    [2]   Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1
    [3]   Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1
    [4]   Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1
    [5]-  Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1
    [6]+  Done                    WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1

user

+47:15

mind telling me how you're deviating now? just so I can tell early if you're just going by the usual route

agent

+47:40
reasoning

For the last 25 minutes I've kept to the project's route, but the next step is a deviation: my own cel renderer with authored lighting and a real background, while keeping the VRoid body and fitted armour plates. If you'd rather I swap VRoid hair for hair I build myself or move modelling into Blender, say so now; otherwise I'm continuing with the plan.

  • Read~/Projects/lowmarch-fable52/review/out/whole2/shots/turn.png

    input

    {
      "file_path": "~/Projects/lowmarch-fable52/review/out/whole2/shots/turn.png"
    }

    result

    no output

    turn_2.jpg
    turn_2.jpg
  • Read~/Projects/lowmarch-fable52/review/out/whole2/shots/heads.png

    input

    {
      "file_path": "~/Projects/lowmarch-fable52/review/out/whole2/shots/heads.png"
    }

    result

    no output

    heads_2.png
    heads_2.png
  • Bashcd ~/Projects/lowmarch-fable52 && date +%H:%M:%S && sed -n 856,900p review/vroid-02/index.html && sed -n 912,990p review/vroid-02/index.html

    command

    cd ~/Projects/lowmarch-fable52 && date +%H:%M:%S && sed -n 856,900p review/vroid-02/index.html && sed -n 912,990p review/vroid-02/index.html

    result, 124 lines

    19:20:42
    // forehead and much less than the head is deep, so a brow still hides behind the skull when the head turns away.
    const BROW_LIFT = 0.04;
    const KIND = { cloth: 0, skin: 1, hair: 2, steel: 3, gold: 4, leather: 5, world: 6 };
    function paintMaterial(V, role, map, index, infoRole = role, decal = false) {
      const Rl = V.roles[role] || { mode: "flat", color: "#ff00ff" }, P = (V.paint || {})[role];
      const u = { uKind: { value: 9 }, uBase: { value: new THREE.Color(0.8, 0.8, 0.8) }, uKey: { value: KEY.clone() },
        uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 },
        uInfo: { value: new THREE.Vector4(roleId(infoRole) / 255, (index % 256) / 255, Math.floor(index / 256) / 255, 1) },
        uEye: { value: V.roles.iris.colors.map(hex) }, uFlat: { value: new THREE.Color() }, uSkinRef: { value: new THREE.Vector3(0.965, 0.878, 0.80) },
        uGold: { value: hex((V.paint && V.paint.gold && V.paint.gold.base) || "#b08b3f") },
        uAmbient: { value: new THREE.Vector3(1, 1, 1) }, uKeyCol: { value: new THREE.Vector3(1, 1, 1) }, uRimCol: { value: new THREE.Vector3() },
        uGrain: { value: 0.05 }, uFaceTex: { value: 0 }, uDecal: { value: decal ? 1 : 0 }, uBand: { value: null },
        uSkinTone: { value: new THREE.Vector3(1, 1, 1) }, uShadeOnly: { value: 0 },
        uSkinRamp: { value: 0 }, uSkinL: { value: new THREE.Color() }, uSkinS: { value: new THREE.Color() }, uSkinC: { value: new THREE.Color() },
        tCastInfo: { value: null }, tCastDepth: { value: null }, uCastRes: { value: new THREE.Vector2(1, 1) }, uCastOn: { value: 0 },
        uCastNear: { value: 0.1 }, uCastFar: { value: 40 }, uCastPpm: { value: 1 },
        uMotif: { value: hex((V.paint && V.paint.motif && V.paint.motif.base) || "#3a44a0") }, uLift: { value: 0 } };
      if (P) { u.uKind.value = KIND[P.kind] ?? 0; if (P.base) u.uBase.value = hex(P.base); if (P.grain != null) u.uGrain.value = P.grain; }
      else if (Rl.bands) { u.uKind.value = Rl.world ? 6 : 0; u.uBase.value = hex(Rl.bands[Math.min(1, Rl.bands.length - 1)][1]); }
      if (P && P.kind === "world") { u.uKey.value = new THREE.Vector3(...V.sun); u.uGrain.value = 0.12; }
      if (P && P.shade) u.uShadeOnly.value = 1;         // shadow cards: skin, always in its shade tone
      if (P && P.kind === "skin" && P.ramp) {           // a designed ramp: lit, shade, deep shade
        u.uSkinRamp.value = 1; u.uSkinL.value = hex(P.ramp[0]); u.uSkinS.value = hex(P.ramp[1]); u.uSkinC.value = hex(P.ramp[2]);
      }
      if (P && P.kind === "skin" && P.base) {           // skin tone: the base colour against the default light skin
        const c = hex(P.base); u.uSkinTone.value.set(c.r / 0.973, c.g / 0.882, c.b / 0.835);
      }
      if (role === "face" && map) u.uFaceTex.value = 1;
      if (role === "hair" && map) u.uAlpha.value = 1;
      if (role === "iris") { u.uKind.value = 7; u.uAlpha.value = 1; }
      else if (role === "white" || role === "highlight") { u.uKind.value = map ? 8 : 9; if (map) u.uAlpha.value = 1; u.uFlat.value = hex(Rl.color || "#ffffff"); }
      else if (!P && Rl.mode === "flat") { u.uKind.value = 9; u.uFlat.value = hex(Rl.color); if (map) u.uAlpha.value = role === "line" ? 2 : 1; }
      if (role === "brow") u.uLift.value = BROW_LIFT;
      if (role === "mouth" && map) u.uKind.value = 10;
      u.uBand.value = u.uGold.value.clone();
      const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide,
                                           extensions: { derivatives: true } });
      // meshes without plate data or a cloth edge read zeros, not whatever another program left in that slot
      m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] };
      return m;
    }
    
    // ---- models ------------------------------------------------------------------------------------------------------
    const loader = new GLTFLoader();
    const chars = new Map();          // name -> loaded character
    async function parseGlb(file) {
      const j = await (await fetch(file)).json();
      const bin = Uint8Array.from(atob(j.glb), c => c.charCodeAt(0));
      return await new Promise((ok, bad) => loader.parse(bin.buffer, "", ok, bad));
    }
    let meshIndex = 1;
    function prepMesh(o, V, opts = {}) {
      const m0 = o.material, role = o.userData.role || "body", raw = rawTex(m0.map);
      const infoRole = role === "hair" && opts.hairB ? "hair_b" : role === "shadow" ? "body" : role;
      const decal = !!(m0.userData && m0.userData.decal);              // the map is a design mask, not a colour
      const base = { map: decal ? null : (m0.map || null), color: m0.color.clone(), side: THREE.DoubleSide, alphaTest: m0.alphaTest || 0 };
      const clay = new THREE.MeshStandardMaterial({ ...base, roughness: 0.85, metalness: m0.metalness || 0 });
      const toon = new THREE.MeshToonMaterial({ ...base, gradientMap: gradient });
      if (role === "hair" && m0.map && V.paint && V.paint.hair) {
        // the VRoid sample's hair texture carries its own colour (dark on some samples): in 3D use the
        // character's hair colour, with the texture's light and dark only for strand detail
        for (const m of [clay, toon]) {
          m.color = hex(V.paint.hair.base);
          m.onBeforeCompile = sh => { sh.fragmentShader = sh.fragmentShader.replace("#include <map_fragment>",
            `#ifdef USE_MAP
              vec4 texel_ = texture2D(map, vMapUv);
              diffuseColor.rgb *= mix(1.0, clamp(dot(texel_.rgb, vec3(0.3333)) / 0.5, 0.45, 1.35), 0.6);
              diffuseColor.a *= texel_.a;
            #endif`); };
          m.customProgramCacheKey = () => "hairlum";
        }
      }
      o.userData.mats = { clay, toon, painted: paintMaterial(V, role, raw, meshIndex, infoRole, decal) };
      meshIndex++;
      o.userData.group = o.userData.group || "body";
      o.userData.role = role;
      o.frustumCulled = false;
    }
    
    async function loadCharacter(name) {
      if (chars.has(name)) return chars.get(name);
      const def = charDef(name), V = def.info, ci = CAM.characters.indexOf(def);
      const gltf = await parseGlb(`${name}.glb.json`);
      const turn = new THREE.Group(), holder = new THREE.Group();
      turn.add(holder); holder.add(gltf.scene);
      const meshes = [];
      gltf.scene.traverse(o => { if (o.isMesh) { prepMesh(o, V, { hairB: ci > 0 }); meshes.push(o); } });
      gltf.scene.updateMatrixWorld(true);
      const bone = n => gltf.scene.getObjectByName(n);
      const cloths = [], world = new THREE.Group();
      for (const [cname, info] of Object.entries(V.cloth || {})) {
        const skinned = meshes.find(m => m.userData.material === cname);
        if (!skinned) continue;
        const trims = meshes.filter(m => info.trims.includes(m.userData.material));
        const caps = V.capsules.filter(c => !info.collide || info.collide.some(k => c.bones[0].includes(k)));
        const cl = info.closed ? new SkirtRig(skinned, info.u, info.v, trims, caps, bone, info.edges === "hem")
                               : new Cloth(skinned, info.u, info.v, trims, caps, bone, false, info.edges === "hem");
        const band = info.band || "gold", BR = V.roles[band] || V.roles.gold;
        const gold = hex(BR.bands ? BR.bands[Math.min(1, BR.bands.length - 1)][1] : BR.color);
        const PB = (V.paint || {})[band];
        if (PB && PB.base) skinned.userData.mats.painted.uniforms.uBand.value = hex(PB.base);   // gold stays gold for decals
        cl.lines3d = new THREE.LineSegments(cl.lines.geometry, new THREE.LineBasicMaterial({ color: gold }));
        cl.lines3d.frustumCulled = false;
        world.add(cl.display, cl.lines3d);
        cloths.push(cl);
      }
      const mixer = new THREE.AnimationMixer(gltf.scene);
      const actions = Object.fromEntries(gltf.animations.map(c => [c.name, mixer.clipAction(c)]));
      const skeleton = meshes.find(m => m.isSkinnedMesh)?.skeleton;
      const c = { name, info: V, turn, holder, root: gltf.scene, meshes, cloths, world, mixer, actions, skeleton,
                  clip: "idle", t: 0, groups: [...new Set(meshes.map(m => m.userData.group))] };
      c.springs = makeSprings(c, V.springs);
      chars.set(name, c);
      return c;
    }
    
    async function loadGround() {
      if (ground) return ground;
      const V = CAM.characters[0].info, gltf = await parseGlb("plains.glb.json"), meshes = [];
      gltf.scene.traverse(o => { if (o.isMesh) { prepMesh(o, V); meshes.push(o); } });
      ground = { root: gltf.scene, meshes };
      return ground;
    }
  • Bashcd ~/Projects/lowmarch-fable52 && sed -n 318,346p review/vroid-02/index.html && sed -n 372,412p review/vroid-02/index.html && sed -n 425,440p review/vroid-02/index.html && sed -n 476,530p review/vroid-02/index.html

    command

    cd ~/Projects/lowmarch-fable52 && sed -n 318,346p review/vroid-02/index.html && sed -n 372,412p review/vroid-02/index.html && sed -n 425,440p review/vroid-02/index.html && sed -n 476,530p review/vroid-02/index.html

    result, 141 lines

      varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate;
      void main() {
        ${SKIN_BODY}
        vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate;
        vec4 mv = modelViewMatrix * vec4(transformed, 1.0); vView = -mv.xyz;
        mv.z += uLift;                                              // brows: drawn over the bangs (depth lift toward the camera)
        gl_Position = projectionMatrix * mv;
      }`;
    const HSV = `
      vec3 rgb2hsv(vec3 c) {
        vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
        vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
        vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
        float d = q.x - min(q.w, q.y);
        return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + 1e-10)), d / (q.x + 1e-10), q.x);
      }
      vec3 hsv2rgb(vec3 c) {
        vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
        vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
        return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
      }`;
    // painted renderer, after the Unicorn Overlord study: tight terminators, hue-shifted ramps built from
    // one base colour per material, hard reflection bands on steel, strand highlights on hair, a stage
    // grade and a back rim
    const PAINT_FS = `
      uniform int uKind; uniform vec3 uBase; uniform vec3 uKey; uniform sampler2D uMap; uniform int uAlpha;
      uniform int uPass; uniform vec4 uInfo; uniform vec3 uEye[3]; uniform vec3 uFlat; uniform vec3 uSkinRef;
      uniform vec3 uGold; uniform vec3 uAmbient; uniform vec3 uKeyCol; uniform vec3 uRimCol; uniform float uGrain;
      uniform int uFaceTex; uniform int uDecal; uniform vec3 uMotif; uniform vec3 uBand; uniform vec3 uSkinTone; uniform int uShadeOnly;
      }
      varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate;
      ${HSV}
      float hash(vec3 p) { p = fract(p * 0.3183099 + 0.1); p *= 17.0; return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); }
      float vnoise(vec3 x) {
        vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f);
        return mix(mix(mix(hash(i), hash(i + vec3(1,0,0)), f.x), mix(hash(i + vec3(0,1,0)), hash(i + vec3(1,1,0)), f.x), f.y),
                   mix(mix(hash(i + vec3(0,0,1)), hash(i + vec3(1,0,1)), f.x), mix(hash(i + vec3(0,1,1)), hash(i + vec3(1,1,1)), f.x), f.y), f.z);
      }
      float toward(float h, float target, float amt) { float d = target - h; d -= floor(d + 0.5); return fract(h + clamp(d, -amt, amt)); }
      vec3 tone(vec3 base, float hue, float amt, float sMul, float vMul) {
        vec3 h = rgb2hsv(base);
        return hsv2rgb(vec3(toward(h.x, hue, amt), clamp(h.y * sMul, 0.0, 1.0), clamp(h.z * vMul, 0.0, 1.0)));
      }
      float st(float x, float t) { return smoothstep(t - 0.03, t + 0.03, x); }
      // Steel and gold. Hard reflection bands (dark below the horizon, a dark core under a white streak)
      // read well where the surface turns fast: rims, tubes, lames. On a broad plate the reflection
      // barely changes, so a band there fills the whole plate (the blotches): bands fade by how sharply
      // the surface curves (normal change per metre on screen), and broad plates get a soft tone that
      // lightens up each outline plate (hgt: height in the plate 0..1, or -1 without plate data).
      vec3 metal(bool gold, vec3 base, vec3 n, vec3 v, float lit, float hgt) {
        vec3 r = reflect(-v, n);
        float ry = r.y + (vnoise(vObj * vec3(3.0, 14.0, 3.0)) - 0.5) * 0.14;   // jitter the bands along their length, not into blobs
        float curv = length(fwidth(n)) / max(length(fwidth(vView)), 1e-5);
        float sharp = smoothstep(5.0, 14.0, curv);
        // a shaped plate's domes (over the bust, a crowned panel) turn the bands into closed rings: plates
        // keep only a little of them and take a crisp highlight toward the light instead
        if (hgt >= 0.0) sharp *= 0.25; else sharp = max(sharp, 0.3);
        vec3 s0, s1, s2, s3;
        if (!gold) { s0 = tone(base, 0.68, 0.10, 2.4, 0.32); s1 = tone(base, 0.68, 0.06, 1.7, 0.76);
                     s2 = tone(base, 0.12, 0.0, 0.8, 0.88); s3 = vec3(0.97, 0.96, 0.92); }
        else { s0 = vec3(0.30, 0.20, 0.30); s1 = tone(base, 0.20, 0.03, 1.0, 0.72); s2 = base; s3 = tone(base, 0.16, 0.03, 0.5, 1.5); }
        vec3 hard = mix(s0, s1, st(ry, -0.42));                          // facing down: dark
        hard = mix(hard, s2, st(ry, -0.08));                             // facing us: the plate's own grey
        hard = mix(hard, s0, st(ry, 0.36));                              // dark core under the streak
        hard = mix(hard, s3, st(ry, 0.47));                              // the white streak
        hard = mix(hard, s2 * 1.06, st(ry, 0.70));
        float k = smoothstep(-0.55, 0.30, r.y);                          // broad: darker toward the ground (no jitter:
        if (hgt >= 0.0) k = clamp(k * 0.45 + hgt * 0.80 - 0.18, 0.0, 1.0);   // on a flat plate it streaks)
        else k = clamp(k * 0.6 + n.y * 0.35 + 0.05, 0.0, 1.0);           // without plate data: lighter facing up
        vec3 soft = mix(s1 * 0.9, s2, k);
        float lit = dot(n, uKey) * 0.5 + 0.5;
        if (uShadeOnly == 1) lit = min(lit, 0.37);                        // shadow cards only ever darken skin, to a soft shade
        else if (uCastOn == 1 && uKind == 1 && int(uInfo.x * 255.0 + 0.5) == 2 && castShadow() > 0.5)
          lit = min(lit, 0.37);                                           // body skin under the jaw's or the hair's shadow
        float g1 = vnoise(vObj * 40.0), g2 = vnoise(vObj * 150.0);
        vec3 col;
        if (uKind == 0 || uKind == 5 || uKind == 6) {                    // cloth, leather, ground
          vec3 hb = rgb2hsv(uBase);
          bool cool = hb.x > 0.42 && hb.x < 0.86;
          float sh = uKind == 5 ? 0.93 : (cool ? 0.70 : 0.96);
          float li = cool ? 0.52 : 0.13;
          vec3 c0 = tone(uBase, sh, 0.09, 1.12, 0.40), c1 = tone(uBase, sh, 0.05, 1.08, 0.64);
          vec3 c3 = tone(uBase, li, 0.03, 0.80, 1.20);
          float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.22 : 0.0);  // ground: a flat top sits at the base colour
          col = mix(c0, c1, st(l, 0.30)); col = mix(col, uBase, st(l, 0.50)); col = mix(col, c3, st(l, 0.91));
          if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0);       // mottled leather
          }
        } else if (uKind == 7) {                                           // iris
          float l = dot(tex.rgb, vec3(1.0 / 3.0));
          col = l < 0.3 ? mix(uEye[0], uEye[1], l / 0.3) : mix(uEye[1], uEye[2], clamp((l - 0.3) / 0.6, 0.0, 1.0));
        } else if (uKind == 8) { col = tex.rgb; }
        else if (uKind == 10) {                                            // the open mouth: VRoid's map read as three parts,
          float lum = dot(tex.rgb, vec3(1.0 / 3.0));                       // teeth (white), tongue (its light pink) and the
          col = mix(vec3(0.36, 0.11, 0.14), vec3(0.78, 0.38, 0.42), smoothstep(0.53, 0.58, tex.g));   // dark inside
          col = mix(col, vec3(0.98, 0.96, 0.95), smoothstep(0.80, 0.86, lum));
        }
        else { col = uFlat; }
        if (vPlate.x > 0.5 && vPlate.z > 0.0 && uKind != 3 && uKind != 4) {   // a cloth outline piece's gold border,
          float e = vPlate.y, w = vPlate.z, aa = fwidth(e) * 1.2 + 1e-5;       // and a fine gold line inside it
          float band = 1.0 - smoothstep(w - aa, w, e);
          float l1 = 1.0 - smoothstep(0.0006, 0.0006 + aa, abs(e - (w + 0.0040)));
          col = mix(col, metal(true, uGold, n, v, lit, -1.0), max(band, l1 * 0.9));
        }
        if (uDecal == 1) {                                                 // a design in the piece's own coordinates:
          vec3 dm = tex.rgb;                                               // R paint, G groove, B gold inlay
          float pm = smoothstep(0.3, 0.7, dm.r), gm = smoothstep(0.3, 0.7, dm.g), au = smoothstep(0.3, 0.7, dm.b);
          if (au > 0.0) col = mix(col, metal(true, uGold, n, v, lit, -1.0), au);
          if (pm > 0.0) {
            vec3 pc = mix(tone(uMotif, 0.70, 0.05, 1.10, 0.62), uMotif, st(lit, 0.42));
            col = mix(col, mix(pc, tone(uMotif, 0.56, 0.03, 0.8, 1.25), st(lit, 0.92)), pm);
          }
          if (gm > 0.0) col = mix(col, col * 0.30, gm);
        }
        if (vEdge > 0.5) {                                                 // the cloth's border band
          vec3 gd = tone(uBand, 0.20, 0.03, 1.0, 0.72);
          col = mix(gd, uBand, st(lit, 0.45)); col = mix(col, tone(uBand, 0.16, 0.03, 0.5, 1.45), st(lit, 0.85));
        }
        if (uKind <= 6) {
          vec3 grade = mix(uAmbient, uKeyCol, st(lit, 0.55));
          col *= uKind == 1 && uSkinRamp == 1 ? mix(vec3(1.0), grade, 0.3) : grade;   // a designed skin ramp takes less of it
          float fr = pow(1.0 - max(dot(n, v), 0.0), 4.0);
          float back = clamp(dot(n, normalize(vec3(0.55, 0.45, -0.35))), 0.0, 1.0);
          col += uRimCol * fr * smoothstep(0.1, 0.5, back);
          if (uKind != 1) col *= 1.0 + (g2 - 0.5) * 0.06;
        }
        gl_FragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
      }`;
    const PAINT_COMP = `
      uniform sampler2D tColor; uniform sampler2D tInfo; uniform sampler2D tDepth; uniform vec2 uRes;
      uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm;
      ${HSV}
      float z(vec2 p) { return uNear + texture2D(tDepth, p).x * (uFar - uNear); }
      int rid(vec4 i) { return int(i.r * 255.0 + 0.5); }
      float pid(vec4 i) { return floor(i.g * 255.0 + 0.5) + floor(i.b * 255.0 + 0.5) * 256.0; }
      vec3 ink(vec3 c) { vec3 h = rgb2hsv(c); return hsv2rgb(vec3(h.x, clamp(h.y, 0.20, 0.45), 0.19)); }
      // How far (px) the mouth's opening runs from this pixel in direction d (2 px steps, up to 128 px).
      float mouthRun(vec2 uv, vec2 d) {
        float n = 0.0;
        for (int s = 1; s <= 64; s++) { vec4 a = texture2D(tInfo, uv + d * float(2 * s)); if (a.a < 0.5 || rid(a) != 9) break; n += 2.0; }
        return n;
      }
  • Bashcd ~/Projects/lowmarch-fable52 && sed -n 296,318p review/vroid-02/index.html; grep -n "userData.role\|userData.decal\|extras" tools/export_glb.py | head -20; grep -n "_plate\|\"edge\"\|_EDGE\|_PLATE" tools/export_glb.py | head

    command

    cd ~/Projects/lowmarch-fable52 && sed -n 296,318p review/vroid-02/index.html; grep -n "userData.role\|userData.decal\|extras" tools/export_glb.py | head -20; grep -n "_plate\|\"edge\"\|_EDGE\|_PLATE" tools/export_glb.py | head

    result, 28 lines

      const d = new Uint8Array([70, 70, 70, 255, 140, 140, 140, 255, 205, 205, 205, 255, 255, 255, 255, 255]);
      const t = new THREE.DataTexture(d, 4, 1, THREE.RGBAFormat); t.minFilter = t.magFilter = THREE.NearestFilter; t.needsUpdate = true; return t;
    })();
    const white = (() => { const t = new THREE.DataTexture(new Uint8Array([255, 255, 255, 255]), 1, 1, THREE.RGBAFormat); t.needsUpdate = true; return t; })();
    
    // ---- scene and camera -----------------------------------------------------------------------------------------------
    const scene = new THREE.Scene();
    const hemi = new THREE.HemisphereLight(0xfff6ee, 0x3a3450, 1.35);
    const sun = new THREE.DirectionalLight(0xffffff, 1.6);
    scene.add(hemi, sun);
    const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 40);
    
    // ---- shaders --------------------------------------------------------------------------------------------------------
    const SKIN_HEAD = `#include <common>
      #include <skinning_pars_vertex>`;
    const SKIN_BODY = `#include <beginnormal_vertex>
        #include <skinbase_vertex>
        #include <skinnormal_vertex>
        #include <begin_vertex>
        #include <skinning_vertex>`;
    const PAINT_VS = `${SKIN_HEAD}
      attribute float edge; attribute vec4 _plate; uniform float uLift;
      varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate;
    147:                          extras=dict(group=group_of(p, role), role=role, world=bool(p.get("world")), material=p["material"])))
    520:            mat["extras"] = dict(decal=True)
    526:                           extras=dict(group=group_of(p, role), role=role, material=p["material"])))
    36:    for key in ("trim", "edge", "hem", "placket", "buckle", "clasp"):
    480:            attrs["_PLATE"] = add_acc(np.asarray(p["plate"])[usedv].astype(np.float32), "VEC4", 5126, 34962)

agent

+49:10

Writing the new renderer now. One more read of how the old page handles eyes, lashes and face textures so my shader gets those right.

  • Bashcd ~/Projects/lowmarch-fable52 && sed -n 412,476p review/vroid-02/index.html; grep -n "const hex\b\|function hex\|const rawTex\|function rawTex" -A6 review/vroid-02/index.html | head -24; grep -n "lid_fill\|fill_lid\|even_mouth\|fill_line" tools/export_glb.py | head

    command

    cd ~/Projects/lowmarch-fable52 && sed -n 412,476p review/vroid-02/index.html; grep -n "const hex\b\|function hex\|const rawTex\|function rawTex" -A6 review/vroid-02/index.html | head -24; grep -n "lid_fill\|fill_lid\|even_mouth\|fill_line" tools/export_glb.py | head

    result, 84 lines

        vec3 soft = mix(s1 * 0.9, s2, k);
        float hl = dot(n, normalize(uKey + v));                          // the key's highlight, a hard-edged shape
        if (hgt >= 0.0) soft = mix(soft, mix(s2, s3, 0.6), st(hl, 0.955) * smoothstep(0.45, 0.8, hgt));   // the upper part only
        vec3 col = mix(soft, hard, sharp);
        return mix(col * 0.72 + s0 * 0.28, col, st(lit, 0.30));
      }
      void main() {
        vec4 tex = texture2D(uMap, vUv);
        if (uAlpha == 1 && tex.a < 0.5) discard;
        if (uAlpha == 2 && (tex.a < 0.5 || dot(tex.rgb, vec3(1.0 / 3.0)) >= 0.42)) discard;
        if (uPass == 1) { gl_FragColor = uInfo; return; }
        vec3 n = normalize(vN); if (!gl_FrontFacing) n = -n;
        vec3 v = normalize(vView);
        float lit = dot(n, uKey) * 0.5 + 0.5;
        if (uShadeOnly == 1) lit = min(lit, 0.37);                        // shadow cards only ever darken skin, to a soft shade
        else if (uCastOn == 1 && uKind == 1 && int(uInfo.x * 255.0 + 0.5) == 2 && castShadow() > 0.5)
          lit = min(lit, 0.37);                                           // body skin under the jaw's or the hair's shadow
        float g1 = vnoise(vObj * 40.0), g2 = vnoise(vObj * 150.0);
        vec3 col;
        if (uKind == 0 || uKind == 5 || uKind == 6) {                    // cloth, leather, ground
          vec3 hb = rgb2hsv(uBase);
          bool cool = hb.x > 0.42 && hb.x < 0.86;
          float sh = uKind == 5 ? 0.93 : (cool ? 0.70 : 0.96);
          float li = cool ? 0.52 : 0.13;
          vec3 c0 = tone(uBase, sh, 0.09, 1.12, 0.40), c1 = tone(uBase, sh, 0.05, 1.08, 0.64);
          vec3 c3 = tone(uBase, li, 0.03, 0.80, 1.20);
          float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.22 : 0.0);  // ground: a flat top sits at the base colour
          col = mix(c0, c1, st(l, 0.30)); col = mix(col, uBase, st(l, 0.50)); col = mix(col, c3, st(l, 0.91));
          if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0);       // mottled leather
        } else if (uKind == 1) {                                           // skin: pale, nearly unshaded from the front
          vec3 sL = vec3(0.973, 0.882, 0.835), sS = vec3(0.776, 0.659, 0.608), sC = vec3(0.451, 0.322, 0.310);
          if (uSkinRamp == 1) { sL = uSkinL; sS = uSkinS; sC = uSkinC; }   // the character's tone, designed per tone
          col = mix(sC, sS, st(lit, 0.20)); col = mix(col, sL, st(lit, 0.38));
          if (uFaceTex == 1) col *= clamp(tex.rgb / uSkinRef, 0.55, 1.05);
          if (uFaceTex == 1 && vUv.x > 0.38 && vUv.x < 0.62 && vUv.y > 0.68 && vUv.y < 0.84) {
            // the closed mouth: VRoid paints a 2-texel line that the clamp above leaves faint; ink it and widen it
            // (the darkest of a few taps), so it follows the mouth's shape keys as a drawn line
            float d = 0.0, sl = dot(uSkinRef, vec3(1.0 / 3.0));
            for (int k = -2; k <= 2; k++) for (int j = -1; j <= 1; j++) {
              vec3 t = texture2D(uMap, vUv + vec2(float(j) * 1.2, float(k) * 0.8) / 512.0).rgb;
              d = max(d, 1.0 - dot(t, vec3(1.0 / 3.0)) / sl);
            }
            float taper = 1.0 - 0.55 * smoothstep(0.035, 0.065, abs(vUv.x - 0.5));   // a brush stroke: lighter at the corners
            col = mix(col, vec3(0.42, 0.22, 0.22), smoothstep(0.10, 0.22, d) * taper);
          }
          if (uSkinRamp == 0) col *= uSkinTone;                            // older builds: one tint over the light skin
        } else if (uKind == 2) {                                           // hair: four even bands, hard strand highlights
          float strand = dot(tex.rgb, vec3(1.0 / 3.0));
          vec3 c0 = tone(uBase, 0.72, 0.07, 1.10, 0.45), c1 = tone(uBase, 0.72, 0.035, 1.05, 0.68);
          vec3 c2 = tone(uBase, 0.56, 0.02, 0.92, 1.10), c3 = tone(uBase, 0.56, 0.03, 0.55, 1.42);
          float l = lit + (strand - 0.6) * 0.12;
          col = mix(c0, c1, st(l, 0.40)); col = mix(col, uBase, st(l, 0.56)); col = mix(col, c2, st(l, 0.84));
          float sp = dot(n, normalize(uKey + v)) + (strand - 0.6) * 0.18;
          col = mix(col, c3, st(sp, 0.90) * (1.0 - st(sp, 0.985)));
        } else if (uKind == 3 || uKind == 4) {                             // steel, gold
          bool plate = vPlate.x > 0.5;
          float e = vPlate.y, w = vPlate.z;
          bool gilt = uKind == 4 || (plate && w > 0.0 && e < w);            // an outline plate's gold border
          col = metal(gilt, gilt && uKind == 3 ? uGold : uBase, n, v, lit, plate ? vPlate.w : -1.0);
          if (plate && w > 0.0) {                                           // engraved lines: one inside the border, one on its seam
            float aa = fwidth(e) * 1.2 + 1e-5;
            float l1 = 1.0 - smoothstep(0.0010, 0.0010 + aa, abs(e - (w + 0.0050)));
            float l2 = 1.0 - smoothstep(0.0006, 0.0006 + aa, abs(e - w));
            col = mix(col, col * 0.42, max(l1, l2 * 0.8));
          }
    290:const hex = h => {                                     // raw palette value, no colour-space conversion
    291-  const n = parseInt(h.slice(1), 16);
    292-  return new THREE.Color().setRGB((n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255, THREE.LinearSRGBColorSpace);
    293-};
    294:const rawTex = t => { if (!t) return null; const c = t.clone(); c.colorSpace = THREE.NoColorSpace; c.needsUpdate = true; return c; };
    295-const gradient = (() => {
    296-  const d = new Uint8Array([70, 70, 70, 255, 140, 140, 140, 255, 205, 205, 205, 255, 255, 255, 255, 255]);
    297-  const t = new THREE.DataTexture(d, 4, 1, THREE.RGBAFormat); t.minFilter = t.magFilter = THREE.NearestFilter; t.needsUpdate = true; return t;
    298-})();
    299-const white = (() => { const t = new THREE.DataTexture(new Uint8Array([255, 255, 255, 255]), 1, 1, THREE.RGBAFormat); t.needsUpdate = true; return t; })();
    300-
    302:def fill_line_specks(rgba, most=400):
    319:def fill_lid(rgba, v_edge, close=3):
    355:def even_mouth(rgba):
    492:                raw = fill_line_specks(raw)
    493:                if p.get("lid_fill") is not None:          # a shut eye's lid (vroid_portrait): its lash solid
    494:                    raw = fill_lid(raw, p["lid_fill"])
    496:                raw = even_mouth(raw)
    500:                    index=add_texture((id(src), p["mi"], p.get("lid_fill")), raw))