A 3D model pipeline, pushed by Gemini 4 Carbon
agent
+6:09reasoning
The VRM cache location and FFmpeg installation are confirmed. A short Python script will be run in read-only mode to verify accessibility.
run_command{"CommandLine":"python3 -c '\nimport os, sys\nsys.path[:0] = [\"tools\", \"art/cast\"]\nimport cage\nfrom cast import CAST\nfor n, c in CAST.items():\n if c.get(\"cage\"):\n p = cage.path_for(n, c[\"cage\"])\n print(n, os.path.exists(p), os.path.basename(p), c[\"cage\"].get(\"face\"))\n'","WaitMsBeforeAsync":5000,"toolSummary":"Verify cached cage VRM paths"}
input
{ "CommandLine": "python3 -c '\nimport os, sys\nsys.path[:0] = [\"tools\", \"art/cast\"]\nimport cage\nfrom cast import CAST\nfor n, c in CAST.items():\n if c.get(\"cage\"):\n p = cage.path_for(n, c[\"cage\"])\n print(n, os.path.exists(p), os.path.basename(p), c[\"cage\"].get(\"face\"))\n'", "WaitMsBeforeAsync": 5000, "toolSummary": "Verify cached cage VRM paths" }result, 17 lines
Command exited with code 0. Command output: arm_m_lean True arm_m_lean_6d1b48afc22965f9.vrm {'sample': [['avatarsample_z', 1]], 'sculpt': {}, 'archetype': 'young', 'hair': 'avatarsample_z'} arm_m_average True arm_m_average_6f6884896471a8ed.vrm {'sample': [['avatarsample_p', 0.5], ['avatarsample_z', 0.5]], 'sculpt': {}, 'archetype': 'generic', 'hair': 'avatarsample_l'} arm_m_strong True arm_m_strong_1714075df4c9b0da.vrm {'sample': [['avatarsample_c', 0.6], ['avatarsample_t', 0.4]], 'sculpt': {}, 'archetype': 'adult', 'hair': 'avatarsample_c'} arm_m_heroic True arm_m_heroic_460837128ce488ff.vrm {'sample': [['avatarsample_r', 0.6], ['avatarsample_v', 0.4]], 'sculpt': {}, 'archetype': 'adult', 'hair': 'avatarsample_r'} arm_m_heavy True arm_m_heavy_61c379ab0d79c76e.vrm {'sample': [['avatarsample_x', 1]], 'sculpt': {'cheek': 0.4}, 'archetype': 'heavy', 'hair': 'avatarsample_x'} arm_m_brute True arm_m_brute_d6a4ae0a1db64d43.vrm {'sample': [['avatarsample_t', 0.6], ['avatarsample_x', 0.4]], 'sculpt': {'jaw': 0.8, 'brow_ridge': 0.8}, 'archetype': 'heavy', 'hair': 'avatarsample_t'} arm_m_old True arm_m_old_e39f53e38a212de0.vrm {'sample': [['avatarsample_v', 0.6], ['avatarsample_t', 0.4]], 'sculpt': {'brow_ridge': 0.8, 'nose': 0.6}, 'archetype': 'adult', 'hair': 'avatarsample_n'} arm_m_youth True arm_m_youth_4886f9ff964f76b2.vrm {'sample': [['avatarsample_z', 0.4], ['avatarsample_g', 0.6]], 'sculpt': {}, 'archetype': 'young', 'hair': 'avatarsample_g'} arm_f_slender True arm_f_slender_81550a78f4ae4dbd.vrm {'sample': [['avatarsample_j', 1]], 'sculpt': {}, 'archetype': 'young', 'hair': 'avatarsample_j'} arm_f_average True arm_f_average_b9b0f674fce164bc.vrm {'sample': [['avatarsample_a', 1]], 'sculpt': {}, 'archetype': 'generic', 'hair': 'avatarsample_a'} arm_f_strong True arm_f_strong_4ad9ea3b57cd9a77.vrm {'sample': [['avatarsample_u', 1]], 'sculpt': {}, 'archetype': 'adult', 'hair': 'avatarsample_s'} arm_f_sexy True arm_f_sexy_b57cd468f043318f.vrm {'sample': [['avatarsample_q', 1]], 'sculpt': {}, 'archetype': 'adult', 'hair': 'avatarsample_u'} arm_f_heavy True arm_f_heavy_8dca016280de6c0a.vrm {'sample': [['avatarsample_s', 0.6], ['avatarsample_e', 0.4]], 'sculpt': {'cheek': 0.4}, 'archetype': 'generic', 'hair': 'avatarsample_y'} arm_f_old True arm_f_old_1f5654d9a1dcb56c.vrm {'sample': [['avatarsample_m', 1]], 'sculpt': {}, 'archetype': 'adult', 'hair': 'avatarsample_w'}read_file{"EndLine":250,"Path":"~/work/lowmarch/tools/mobs.py","StartLine":1}
input
{ "EndLine": 250, "Path": "~/work/lowmarch/tools/mobs.py", "StartLine": 1 }result, 251 lines
Showing lines 1-250 of 311 1: """Common enemy units: one costume per class, built from gear.py on any base body. Generic but detailed: 2: layered padding, mail and plate, riveted straps, an army colour on the cloth and shields (portrait 3: guide, lesson 15). Pair each with a build and a face from gear.BUILDS / gear.FACES in the cast. 4: """ 5: import numpy as np 6: 7: import outfit as O 8: import gear as G 9: from fitting import Surface, merge_surfaces 10: from vrm import bone_weight 11: 12: 13: def _base(fit, shirt="padding", legs="cloth", boots="boot", gloves="glove", knee=None, shirt_subdiv=0, boot_top=None): 14: """Under layers every class shares: a shirt with sleeves to the wrist, trousers, boots to below 15: the knee (or to boot_top: above the knee, they take the thigh too), gloves. Returns the pieces and 16: the shirt (what coats are fitted over).""" 17: B = fit.bone 18: nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] 19: knee = B["J_Bip_L_LowerLeg"][1] if knee is None else knee 20: 21: def cuff(side): 22: a, h = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] 23: n = (h - a) / np.linalg.norm(h - a) 24: return n, n @ (h - n * 0.02) 25: torso = ("Spine", "Chest", "UpperChest", "Bust", "Shoulder", "UpperArm", "LowerArm", "Neck", "Hips") 26: # the neckline: a straight hem, lower at the throat than at the back of the neck (a level cut of 27: # whole triangles left a saw-tooth edge, and a big trapezius showed above it) 28: nh = np.array([0.0, 1.0, -0.3]) / np.linalg.norm([0.0, 1.0, -0.3]) 29: neckline = (nh, float(nh @ (nk + np.array([0.0, 0.012, 0.0])))) 30: s = O.wrap(fit, "shirt", shirt, torso, offset=0.006, exclude=("UpperLeg",), y_min=hips[1] - 0.04, 31: y_max=nk[1] + 0.05, cut=neckline, hems=[cuff("L"), cuff("R"), neckline], subdiv=shirt_subdiv) 32: t = O.wrap(fit, "trousers", legs, ("Hips", "UpperLeg", "LowerLeg"), offset=0.007, y_max=hips[1] + 0.02, subdiv=1) 33: top = knee - 0.07 if boot_top is None else boot_top 34: b = O.wrap(fit, "boots", boots, ("LowerLeg", "Foot", "ToeBase") + (("UpperLeg",) if top > knee else ()), offset=0.015, 35: y_max=top, subdiv=1, hems=[((0, 1, 0), top - 0.005)]) 36: g = O.wrap(fit, "gloves", gloves, ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), offset=0.003, min_w=0.3, smooth=4) 37: out = [p for p in (s, t, b, g) if p is not None] 38: for p, grp in zip(out, ("doublet", "trousers", "boots", "gloves")): 39: p["group"] = grp 40: return out, s, t, b 41: 42: 43: def underwear(fit, band=False): 44: """Plain shorts (and a chest band with band=True) for inspecting bare bodies (the armory page, built 45: in the T-pose): hips to mid-thigh, close to the skin.""" 46: B = fit.bone 47: hips, knee = B["J_Bip_C_Hips"][1], B["J_Bip_L_LowerLeg"][1] 48: lo, hi = (hips + knee) / 2 + 0.03, hips + 0.07 49: # all the skin between the hems but the arms' (they hang there in the fitting pose): taking only skin 50: # weighted to the hips, legs and spine left holes where MakeHuman weights it to the chest or elsewhere 51: out = [O.wrap(fit, "shorts", "cloth", ("J_",), offset=0.004, y_min=lo - 0.04, y_max=hi + 0.04, subdiv=1, 52: exclude=("Shoulder", "Arm", "Hand", "Thumb", "Index", "Middle", "Ring", "Little"), 53: hems=[((0, 1, 0), hi - 0.005), ((0, -1, 0), -(lo + 0.005))], refloor=True, clamp=True)] 54: if band: 55: ch, uc = B["J_Bip_C_Chest"][1], B["J_Bip_C_UpperChest"][1] 56: blo, bhi = ch - 0.01, uc + 0.06 57: # like the shorts: triangles past the hems taken and clamped onto them (dropping them notched the 58: # top edge into steps on broad backs), every bone but the arms' 59: out.append(O.wrap(fit, "band", "cloth", ("J_",), offset=0.004, y_min=blo - 0.03, y_max=bhi + 0.03, subdiv=1, 60: exclude=("Shoulder", "Arm", "Hand", "Thumb", "Index", "Middle", "Ring", "Little"), 61: hems=[((0, 1, 0), bhi - 0.005), ((0, -1, 0), -(blo + 0.005))], refloor=True, clamp=True)) 62: out = [p for p in out if p is not None] 63: for p in out: 64: p["group"] = "underwear" 65: fit.keep_skin = ("J_",) # bare everywhere else: keep all the skin (VRoid 2 weights some to J_Sec_ bones) 66: # but not the skin well inside the shorts: on fitted bodies (tools/fit.py) it came through the waistband. 67: # Never the arms', which hang beside the hips in the fitting pose 68: arms = ("Shoulder", "Arm", "Hand", "Thumb", "Index", "Middle", "Ring", "Little") 69: fit.drop_skin = lambda p: ((p["pos"][:, 1] > lo + 0.015) & (p["pos"][:, 1] < hi - 0.015) 70: & (bone_weight(p, arms) < 0.05)) 71: return out 72: 73: 74: def underwear_f(fit): 75: return underwear(fit, band=True) 76: 77: 78: def _under(shirt): 79: return Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) 80: 81: 82: def _surf(pcs, *names, prefix=False): 83: sel = [p for p in pcs if (p["material"].startswith(tuple("OUTFIT_" + n for n in names)) if prefix 84: else p["material"] in tuple("OUTFIT_" + n for n in names))] 85: return merge_surfaces(*[(p["pos"], p["tri"]) for p in sel]) 86: 87: 88: def soldier(fit, legs="breeches"): 89: """Halberd infantry, after the study's Soldier: a kettle hat, a doublet in the army colour with 90: full sleeves bagging into gauntlets that reach almost to the elbow, a short breastplate with a 91: plackart (full width to the armpits), a fauld of round scales to mid-thigh, a belt, a halberd 92: held in both hands (the cast's polearm stance, tools/clips.py). No puff or band on the upper arm: 93: the study's soldiers have neither, and on a real arm a puff read as a bicep. 94: legs: "breeches" (baggy, bagging over calf boots: the study's men) or "tights" (with boots to 95: above the knee: the study's women).""" 96: B = fit.bone 97: hips = B["J_Bip_C_Hips"] 98: knee = B["J_Bip_L_LowerLeg"][1] 99: gauntlet = 0.70 # of the forearm, from the wrist 100: y_hem = hips[1] - 0.20 # the fauld's 101: boot_top = knee + 0.08 if legs == "tights" else knee - 0.07 102: out, shirt, trousers, boots = _base(fit, shirt="signature", legs="cloth", boots="boot", shirt_subdiv=1, 103: boot_top=boot_top) 104: G.loose_sleeves(fit, shirt, cuff=gauntlet) 105: if legs == "breeches": 106: G.breeches(fit, trousers, boots, y_hem, boot_top - 0.005) 107: else: 108: G.flare_boots(fit, boots, boot_top - 0.005, ease=0.008) 109: under = _under(shirt) 110: out += G.breastplate(fit, under, arm=64.0) 111: plate = _surf(out, "breastplate", prefix=True) 112: # the guard's wide stance: the fauld follows the thighs closely and clears the seat 113: out += G.scale_skirt(fit, under, hips[1] + 0.06, y_hem, role="mail", share=0.15, 114: clear=Surface(trousers["pos"], trousers["tri"])) 115: G.slim_under(fit, trousers, y_hem) # and what it hides can't come through it 116: belt, front = O.belt(fit, "belt", "leather", plate, hips[1] + 0.05, height=0.034, offset=0.004) 117: out.append(belt) 118: cuffs = G.cuffs(fit, length=gauntlet, flare=0.034) 119: G.tuck_sleeves(fit, shirt, cuffs) 120: out += cuffs 121: out += G.coif(fit, role="padding") 122: out += G.helmet(fit, "kettle") 123: out += G.halberd(fit, grip=0.50) # the rear hand near the butt, as the study holds it 124: return out 125: 126: 127: def soldier_f(fit): 128: """The soldier as the study draws its women: tights and boots to above the knee.""" 129: return soldier(fit, legs="tights") 130: 131: 132: def fighter(fit): 133: """Sword and round shield, after the study's Fighter: a kettle hat worn low, a quilted gambeson with 134: full sleeves, a breastplate, lamed spaulders, a knife-pleated skirt in the army colour, greaves, a 135: wooden round shield, an arming sword.""" 136: B = fit.bone 137: hips = B["J_Bip_C_Hips"] 138: knee = B["J_Bip_L_LowerLeg"][1] 139: out, shirt, trousers, boots = _base(fit, shirt="padding", legs="cloth", boots="boot") 140: under = _under(shirt) 141: out += G.quilted(fit, under, role="padding", y_hem=hips[1] - 0.02, flare=0.02, sleeve_end=0.95) 142: gam = _surf(out, "gambeson", "gambeson_skirt") 143: out += G.pleated_skirt(fit, gam, hips[1] + 0.05, hips[1] - 0.30, role="signature") 144: out += G.breastplate(fit, gam) 145: plate_body = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate", "padding")], (fit.pos, fit.tri)) 146: for side in ("L", "R"): 147: sp, rims = O.pauldron(fit, f"spaulder_{side}", "steel", plate_body, side=side, 148: lames=((0, 56, 0.024, 0.032), (47, 73, 0.022, 0.030), (65, 91, 0.020, 0.028)), spread=105) 149: out += G._group(sp + [O.inherit(O.pipe(f"spaulder_{side}_roll{k}", "steel", r_, r=0.0028), pc) 150: for k, (pc, r_) in enumerate(zip(sp, rims))], "plate") 151: ll, ft = B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"] 152: top = (knee - 0.085 - ll[1]) / (ft[1] - ll[1]) 153: gv, rims = O.limb_lames(fit, f"greave_{side}", "steel", O.side_of(boots, side), ll, ft, ((top, 0.80, 0.008, 0.011),), 154: rmax=0.11) 155: fit.bind(gv[0], rigid=f"J_Bip_{side}_LowerLeg") 156: out += G._group(gv + [O.inherit(O.pipe(f"greave_{side}_roll{k}", "steel", r_, r=0.0028), gv[0]) 157: for k, r_ in enumerate(rims[0])], "plate") 158: belt, front = O.belt(fit, "belt", "leather", _surf(out, "breastplate", prefix=True), hips[1] + 0.05, height=0.036, 159: offset=0.004) 160: out.append(belt) 161: out += G.cuffs(fit, length=0.32) 162: out += G.coif(fit, role="padding") 163: out += G.helmet(fit, "kettle", lift=0.032) 164: out += G.round_shield(fit) 165: out += O.sword(fit, "R", blade_len=0.70, hilt="metal") 166: return out 167: 168: 169: def housecarl(fit): 170: """An axeman in mail, after the study's Housecarl: a nasal helm over a mail coif, a mail hauberk to 171: mid-thigh over the gambeson, a short cape in the army colour, a wide belt, big cuffs, a long axe.""" 172: B = fit.bone 173: hips = B["J_Bip_C_Hips"] 174: out, shirt, trousers, boots = _base(fit, shirt="padding", legs="cloth", boots="boot") 175: under = _under(shirt) 176: out += G.quilted(fit, under, role="padding", y_hem=hips[1] - 0.26, sleeve_end=0.95) 177: gam = _surf(out, "gambeson", "gambeson_skirt") 178: out += G.mail_shirt(fit, gam, y_hem=hips[1] - 0.16) 179: mail = _surf(out, "hauberk", prefix=True) 180: belt, front = O.belt(fit, "belt", "leather", mail, hips[1] + 0.04, height=0.05, offset=0.006) 181: out.append(belt) 182: body = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("mail", "padding")], (fit.pos, fit.tri)) 183: mt, grid, hood = O.mantle(fit, "cape", "signature", body) 184: out += G._group([mt], "mantle") 185: out += G.cuffs(fit, length=0.34, flare=0.036) 186: out += G.coif(fit, role="mail") 187: out += G.helmet(fit, "nasal") 188: out += G.axe(fit, haft=1.30, blade=0.26, grip=0.60) 189: return out 190: 191: 192: def hoplite(fit): 193: """Heavy infantry: a close helm, plate over mail (riveted coat of plates, spaulders, greaves), a 194: tabard in the army colour, a tall tower shield and a spear.""" 195: B = fit.bone 196: hips, nk = B["J_Bip_C_Hips"], B["J_Bip_C_Neck"] 197: knee = B["J_Bip_L_LowerLeg"][1] 198: out, shirt, trousers, boots = _base(fit, shirt="padding", legs="cloth", boots="boot") 199: under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) 200: out += G.quilted(fit, under, role="padding", y_hem=hips[1] - 0.20, sleeve_end=0.95) 201: gam = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p["material"] in ("OUTFIT_gambeson", "OUTFIT_gambeson_skirt")]) 202: out += G.mail_shirt(fit, gam, y_hem=hips[1] - 0.20) 203: mail = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p["material"].startswith("OUTFIT_hauberk")]) 204: out += G.riveted_vest(fit, mail, role="signature", rivet_role="steel") 205: plate_body = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate", "mail", "padding")], 206: (fit.pos, fit.tri)) 207: for side in ("L", "R"): 208: sp, rims = O.pauldron(fit, f"spaulder_{side}", "steel", plate_body, side=side, 209: lames=((0, 56, 0.024, 0.032), (47, 73, 0.022, 0.030), (65, 91, 0.020, 0.028)), spread=110) 210: 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))] 211: ll, ft = B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"] 212: top = (knee - 0.085 - ll[1]) / (ft[1] - ll[1]) 213: gv, rims = O.limb_lames(fit, f"greave_{side}", "steel", O.side_of(boots, side), ll, ft, ((top, 0.80, 0.008, 0.011),), 214: rmax=0.11) 215: fit.bind(gv[0], rigid=f"J_Bip_{side}_LowerLeg") 216: 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])] 217: for p in out: 218: if p["material"].startswith(("OUTFIT_spaulder", "OUTFIT_greave")): 219: p["group"] = "plate" 220: belt, front = O.belt(fit, "belt", "leather", merge_surfaces(*[(p["pos"], p["tri"]) for p in out 221: if p["material"].startswith("OUTFIT_brigandine_front") 222: or p["material"] == "OUTFIT_hauberk"]), 223: hips[1] + 0.03, height=0.04, offset=0.008) 224: out.append(belt) 225: over = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate", "mail")], (fit.pos, fit.tri)) 226: mt, grid, hood = O.mantle(fit, "capelet", "signature", over) 227: out += G._group([mt, hood], "mantle") 228: out += G.cuffs(fit, role="steel", length=0.36, flare=0.026) 229: out += G.coif(fit, role="mail") 230: out += G.helmet(fit, "close") 231: emblem = [("poly", [(-0.09, 0.22), (0.09, 0.22), (0.09, -0.04), (0.0, -0.18), (-0.09, -0.04)], "paint"), 232: ("line", [(-0.13, 0.31), (0.13, 0.31)], 0.012, "paint")] 233: out += G.shield(fit, "heater", role="steel", width=0.56, height=0.92, curve=0.45, emblem=emblem) 234: out += G.spear(fit, length=2.2) 235: return out 236: 237: 238: def berserker(fit): 239: """A huge axeman: bare arms, a fur mantle over a leather harness, wide belt, a two-bitted great axe.""" 240: B = fit.bone 241: hips = B["J_Bip_C_Hips"] 242: out, shirt, trousers, boots = _base(fit, shirt="leather", legs="cloth", boots="fur") 243: # a sleeveless jerkin: the shirt's arms come off and the arms stay bare 244: shirt["tri"] = O.without(shirt, ("UpperArm", "LowerArm", "Hand"))[1] 245: fit.keep_skin = ("UpperArm", "LowerArm", "Shoulder") 246: under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) 247: out += G.riveted_vest(fit, under, role="leather", rivet_role="steel") 248: shoulders = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate",)], (shirt["pos"], shirt["tri"]), 249: (fit.pos, fit.tri)) 250: mt, grid, hood = O.mantle(fit, "mantle", "fur", shoulders)read_file{"EndLine":984,"Path":"~/work/lowmarch/tools/gear.py","StartLine":650}
input
{ "EndLine": 984, "Path": "~/work/lowmarch/tools/gear.py", "StartLine": 650 }result, 336 lines
Showing lines 650-984 of 984 650: R -= ax * (R * ax).sum(1, keepdims=True) 651: r = np.linalg.norm(R, axis=1) 652: u = R / np.maximum(r, 1e-9)[:, None] 653: s = np.where(lower, 1 + t / L2, t / L1) 654: sx = 1.0 if side == "R" else -1.0 655: o = np.array([sx, 0, 0])[None] - ax * ax[:, :1] * sx 656: o /= np.linalg.norm(o, axis=1, keepdims=True) 657: f = np.cross(ax, o) 658: f = np.where((f[:, 2] > 0)[:, None], -f, f) # forward is -z 659: phi = np.arctan2((u * f).sum(1), (u * o).sum(1)) 660: return s, u, r, phi, L1 661: 662: 663: def _let_out(fit, pc, limb, knots, prof, ease, folds=6, toward=0.72, behind=0.15, fold_amp=(0.18, 0.22), 664: fold_from=0.6, size=0.26): 665: """Let a wrapped garment out round a limb, both sides: radially off the bone by ease x prof (a 666: profile over the distance along the limb, see _limb_frame), less toward the body, a little more 667: behind, with `folds` soft folds that turn down the limb and deepen past `fold_from`. Weighted by 668: each point's share of the limb's two bones, so it fades into the body. Scaled by the upper segment's 669: length against `size`. Changes `pc` in place.""" 670: P = pc["pos"] 671: for side in ("L", "R"): 672: hit = np.array([n in tuple(f"J_Bip_{side}_{b}" for b in LIMBS[limb][:2]) for n in pc["jnames"]]) 673: w = (hit[pc["J"]] * pc["W"]).sum(1) 674: sel = np.nonzero(w > 0.02)[0] 675: if not len(sel): 676: continue 677: s, u, r, phi, L1 = _limb_frame(fit, side, P[sel], limb) 678: k = min(1.15, max(0.85, L1 / size)) 679: base = ease * k * np.interp(s, knots, prof) 680: dirw = 1.0 - toward * np.clip(-np.cos(phi), 0, 1) ** 1.5 + behind * np.clip(-np.sin(phi), 0, 1) 681: fold = np.sin(folds * phi + 0.9 * s) * (fold_amp[0] + fold_amp[1] * np.clip((s - fold_from) / 0.7, 0, 1)) 682: P[sel] += u * (base * dirw * (1 + fold) * np.clip(w[sel], 0, 1))[:, None] 683: pc["nrm"] = O.vertex_normals(P, pc["tri"]) 684: return pc 685: 686: 687: def _tuck(fit, pc, covers, limb, gap=0.003, both=False, span=None): 688: """Draw a garment inside what covers it on a limb (a gauntlet, a boot): any of it within a cover's 689: span that reaches past the cover's inner face (by angle round the limb and distance along it) is 690: pulled in under it. covers: pieces named for their side (cuff_L), or, with both=True, pieces over 691: both limbs (the boots), split by their skin weights. span: only the cover's points this far along 692: the limb (a boot's foot is not the leg's business).""" 693: P = pc["pos"] 694: for side in ("L", "R"): 695: if both: 696: hit = lambda c: np.array([f"_{side}_" in n for n in c["jnames"]]) 697: pts = [c["pos"][(hit(c)[c["J"]] * c["W"]).sum(1) > 0.5] for c in covers] 698: else: 699: pts = [c["pos"] for c in covers if c["material"].endswith(f"_{side}")] 700: if not pts or not sum(len(q) for q in pts): 701: continue 702: cs, _, cr, cphi, _ = _limb_frame(fit, side, np.concatenate(pts), limb) 703: if span is not None: 704: keep = (cs > span[0]) & (cs < span[1]) 705: cs, cr, cphi = cs[keep], cr[keep], cphi[keep] 706: sb = np.linspace(cs.min(), cs.max(), 14) 707: pb = np.linspace(-np.pi, np.pi, 25) 708: cen = (pb[:-1] + pb[1:]) / 2 709: i_s = np.clip(np.digitize(cs, sb) - 1, 0, len(sb) - 2) 710: i_p = np.clip(np.digitize(cphi, pb) - 1, 0, len(pb) - 2) 711: grid = np.full((len(sb) - 1, len(pb) - 1), np.inf) 712: np.minimum.at(grid, (i_s, i_p), cr) # the cover's inner face 713: for a in range(grid.shape[0]): # fill gaps round the limb 714: ok = np.isfinite(grid[a]) 715: grid[a] = np.interp(cen, cen[ok], grid[a][ok], period=2 * np.pi) if ok.any() else np.inf 716: hit = np.array([n in tuple(f"J_Bip_{side}_{b}" for b in LIMBS[limb][1:]) for n in pc["jnames"]]) 717: sel = np.nonzero((hit[pc["J"]] * pc["W"]).sum(1) > 0.3)[0] 718: s, u, r, phi, _ = _limb_frame(fit, side, P[sel], limb) 719: a = np.clip(np.digitize(s, sb) - 1, 0, len(sb) - 2) 720: b = np.clip(np.digitize(phi, pb) - 1, 0, len(pb) - 2) 721: lim = grid[a, b] - gap 722: over = (s > sb[0]) & (s < sb[-1]) & (r > lim) 723: P[sel[over]] -= u[over] * (r[over] - lim[over])[:, None] 724: pc["nrm"] = O.vertex_normals(P, pc["tri"]) 725: return pc 726: 727: 728: def loose_sleeves(fit, shirt, ease=0.030, cuff=0.70, folds=6): 729: """Full sleeves after the Unicorn Overlord study: the shirt's own sleeves let out, little at the 730: shoulder and fullest round the elbow and above the gauntlet (the opposite of a bicep's shape, so 731: the arm never reads as muscle), with soft folds down the arm that deepen where the sleeve bags 732: into the cuff. Less on the side toward the body (the hanging arm's room), more behind. 733: cuff: the gauntlet's length as a share of the forearm (cuffs()); below its top the sleeve goes 734: back to the arm, and tuck_sleeves() then draws it inside. Changes `shirt` in place.""" 735: s_c = 2.0 - cuff # the gauntlet's top on the arm 736: return _let_out(fit, shirt, "arm", [-0.3, 0.0, 0.35, 0.75, 1.0, s_c - 0.14, s_c - 0.02, s_c + 0.10, 2.2], 737: [0.0, 0.10, 0.32, 0.72, 0.92, 1.0, 1.0, 0.0, 0.0], ease, folds) 738: 739: 740: def tuck_sleeves(fit, shirt, cuff_pcs, gap=0.003): 741: """Draw a sleeve inside its gauntlet (see _tuck).""" 742: return _tuck(fit, shirt, cuff_pcs, "arm", gap) 743: 744: 745: def _leg_s(fit, y): 746: """A height on the (left) leg as _limb_frame's distance along it: 0 at the hip joint, 1 at the knee, 747: 2 at the ankle (the reference pose stands straight).""" 748: B = fit.bone 749: h, k, a = (float(B[f"J_Bip_L_{n}"][1]) for n in LIMBS["leg"]) 750: return (h - y) / (h - k) if y > k else 1 + (k - y) / (k - a) 751: 752: 753: def flare_boots(fit, boots, y_top, ease=0.010): 754: """Boot tops that stand a little off the leg (leather, not a stocking), easing back over a third of 755: the shin. Changes `boots` in place.""" 756: s_b = _leg_s(fit, y_top) 757: return _let_out(fit, boots, "leg", [s_b - 0.05, s_b + 0.01, s_b + 0.30, 2.2], [1.0, 1.0, 0.0, 0.0], ease, folds=5, 758: toward=0.5, behind=0.0, fold_amp=(0.12, 0.0), size=0.42) 759: 760: 761: def breeches(fit, trousers, boots, y_hem, y_boot, ease=0.040, folds=7): 762: """Baggy breeches after the study's soldiers: the trousers let out below the fauld's hem (y_hem), 763: fullest just above the boot top (y_boot) where they bag over it, less on the inner thigh, with 764: folds down the leg; the boots' tops flare a little, and the breeches are drawn inside them. 765: Changes `trousers` and `boots` in place.""" 766: s_f, s_b = _leg_s(fit, y_hem), _leg_s(fit, y_boot) 767: flare_boots(fit, boots, y_boot) 768: _let_out(fit, trousers, "leg", [-0.3, s_f - 0.02, s_f + 0.16, 0.85, s_b - 0.12, s_b - 0.02, s_b + 0.10, 2.2], 769: [0.0, 0.12, 0.6, 0.92, 1.0, 1.0, 0.0, 0.0], ease, folds, toward=0.6, behind=0.1, fold_amp=(0.15, 0.25), 770: fold_from=0.5, size=0.42) 771: _tuck(fit, trousers, [boots], "leg", gap=0.004, both=True, span=(1.0, 1.95)) 772: return trousers, boots 773: 774: 775: def slim_under(fit, trousers, y_hem, pull=0.018, ramp=0.05): 776: """Trousers drawn in toward the thigh bones where a skirt hides them (above y_hem, easing back to 777: full width over `ramp` above the hem). A stiff skirt follows the hips more than the thighs, and in 778: a wide stance or a lunge the thighs swing out through it; slimmer under it, they clear it. The 779: skin under the trousers is culled, so nothing else shows. Changes `trousers` in place.""" 780: P = trousers["pos"] 781: for side in ("L", "R"): 782: hit = np.array([n == f"J_Bip_{side}_UpperLeg" for n in trousers["jnames"]]) 783: w = (hit[trousers["J"]] * trousers["W"]).sum(1) 784: sel = np.nonzero(w > 0.05)[0] 785: if not len(sel): 786: continue 787: _, u, r, _, _ = _limb_frame(fit, side, P[sel], "leg") 788: k = np.clip((P[sel, 1] - y_hem) / ramp, 0, 1) 789: k = k * k * (3 - 2 * k) 790: d = np.minimum(pull * k * np.clip(w[sel], 0, 1), np.maximum(r - 0.03, 0)) 791: P[sel] -= u * d[:, None] 792: trousers["nrm"] = O.vertex_normals(P, trousers["tri"]) 793: return trousers 794: 795: 796: def breastplate(fit, under, role="steel", name="breastplate", y_top=None, y_bottom=None, plackart=True, keel=0.008, 797: back=True, arm=54.0): 798: """A breastplate (and backplate) as outline plates: a scooped neckline, armholes cut away at the 799: sides, a slight point at the waist, a central ridge, rolled edges; a plackart over the belly. 800: arm: where the armhole's scoop begins (degrees round the torso from the front); larger keeps the 801: plate's full width up to the armpits instead of a bib over the middle of the chest.""" 802: B = fit.bone 803: nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] 804: y_top = nk[1] - 0.05 if y_top is None else y_top 805: y_bottom = hips[1] + 0.03 if y_bottom is None else y_bottom 806: cz = float(hips[2]) 807: tc = TorsoChart(under, y_bottom - 0.04, y_top + 0.04, cz=cz, du=2.5, dv=0.007) 808: span = y_top - y_bottom 809: top = lambda u: y_top - 0.035 * max(0.0, 1 - abs(u) / 34) ** 1.4 - 0.11 * span * max(0.0, (abs(u) - arm) / 42) ** 1.3 810: bottom = lambda u: y_bottom - 0.018 * max(0.0, 1 - abs(u) / 40) ** 1.5 811: ridge = lambda u, v, s, t: keel * math.exp(-(u / 9.0) ** 2) * math.sin(math.pi * min(1.0, t * 1.15)) 812: front, fx = outline_plate(name, role, tc, -96, 96, bottom, top, offset=0.014, crown=0.010, flare=ridge, thickness=0.004, 813: nu=72, nv=26, roll=0.0034, roll_edges=("top", "bottom")) 814: fit.bind(front, allow=("Spine", "Chest", "UpperChest", "Bust", "Hips"), fallback="J_Bip_C_Chest") 815: out = [front] + [O.inherit(p, front) for p in fx] 816: if back: 817: btop = lambda u: y_top - 0.01 - 0.11 * span * max(0.0, (abs(((u % 360) - 180)) - (arm - 4)) / 44) ** 1.3 818: bk, bx = outline_plate(f"{name}_back", role, tc, 96, 264, lambda u: y_bottom, btop, offset=0.014, crown=0.006, 819: thickness=0.004, nu=60, nv=22, roll=0.0034, roll_edges=("top", "bottom")) 820: fit.bind(bk, allow=("Spine", "Chest", "UpperChest", "Bust", "Hips"), fallback="J_Bip_C_Chest") 821: out += [bk] + [O.inherit(p, bk) for p in bx] 822: if plackart: # over the belly, its top rounded up to a point 823: ptop = lambda u: y_bottom + 0.36 * span - 0.10 * span * (abs(u) / 50) ** 1.6 824: pl, px = outline_plate(f"{name}_plackart", role, tc, -50, 50, bottom, ptop, offset=0.020, crown=0.008, flare=ridge, 825: thickness=0.004, nu=40, nv=12, roll=0.0034, roll_edges=("top",), 826: rivets=(0.05, 0.010, 0.0035), rivet_role=role) 827: fit.bind(pl, allow=("Spine", "Chest", "Hips"), fallback="J_Bip_C_Spine") 828: out += [pl] + [O.inherit(p, pl) for p in px] 829: return _group(out, "plate") 830: 831: 832: def scale_pattern(w=256, h=128, cols=8): 833: """Overlapping round scales (a fauld), rows offset: each scale's lower edge as a dark arc.""" 834: cv = Canvas(w, h, ss=2) 835: sw = w / cols 836: rows = int(h / (sw * 0.55)) + 2 837: for j in range(rows): 838: yy = j * sw * 0.55 839: for i in range(cols + 1): 840: xx = i * sw + (j % 2) * sw / 2 841: th = np.linspace(math.pi * 1.05, math.pi * 1.95, 12) 842: pts = [((xx + sw / 2 * math.cos(t)) / w, 1 - (yy - sw * 0.45 * math.sin(t)) / h) for t in th] 843: cv.line(np.array(pts), 1.6, "groove") 844: return cv.array() 845: 846: 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 862: need = np.nan_to_num(lc.radius(us[:, None], vs[None, :]), nan=0.0) + gap + side * np.sin(np.radians(us))[:, None] ** 2 863: top_c = float(clear.pos[np.unique(clear.tri), 1].max()) 864: need[:, vs > top_c] = 0.0 # the chart fills rows above what it measured: not there 865: need = np.maximum(need, cone(us[:, None], vs[None, :])) 866: # hanging from the waist: the tightest outline that starts at the waist and clears everything below 867: # (the upper concave hull down each line of the skirt); a skirt that stepped straight out to the seat 868: # stood off the back like a shelf 869: d = y_top - vs 870: for i in range(len(us)): 871: hull = [0] 872: for j in range(1, len(vs)): 873: while len(hull) >= 2: 874: a, b = hull[-2], hull[-1] 875: if (need[i, b] - need[i, a]) * (d[j] - d[a]) <= (need[i, j] - need[i, a]) * (d[b] - d[a]): 876: hull.pop() 877: else: 878: break 879: hull.append(j) 880: need[i] = np.interp(d, d[hull], need[i, hull]) 881: need = np.maximum.accumulate(need, axis=1) # never narrowing going down 882: need = (np.roll(need, 1, 0) + 2 * need + np.roll(need, -1, 0)) / 4 883: 884: def r(u, v): 885: u, v = np.broadcast_arrays(np.asarray(u, float), np.asarray(v, float)) 886: iu = ((u + 180.0) / 3.0) % len(us) 887: i0 = np.floor(iu).astype(int) % len(us) 888: f = iu - np.floor(iu) 889: jv = np.clip((y_top - v) / 0.01, 0, len(vs) - 1) 890: j0 = np.clip(np.floor(jv).astype(int), 0, len(vs) - 2) 891: g = jv - j0 892: n = ((need[i0, j0] * (1 - g) + need[i0, j0 + 1] * g) * (1 - f) 893: + (need[(i0 + 1) % len(us), j0] * (1 - g) + need[(i0 + 1) % len(us), j0 + 1] * g) * f) 894: return np.maximum(cone(u, v), n) 895: return ConeChart(r, cz=cz) 896: 897: 898: def scale_skirt(fit, under, y_top, y_hem, role="mail", name="fauld", flare=0.05, split=0.0, share=0.55, clear=None, 899: side=0.0): 900: """A fauld of round scales on a cone from y_top to y_hem. share: how much of it stays with the hips 901: rather than the thighs (a wide stance needs it lower, or a forward thigh comes through the front). 902: clear: what it must stand outside of (the trousers; see skirt_cone).""" 903: cone = skirt_cone(fit, under, y_top, y_hem, flare, clear=clear, side=side) 904: u0, u1 = (split, 360 - split) if split else (-180, 180) # closed at the back (179 left a slit) 905: hem = lambda u: y_hem + 0.008 * abs(math.sin(math.radians(u) * 22)) # the scales' scalloped edge 906: pc, _ = outline_plate(name, role, cone, u0, u1, hem, lambda u: y_top, offset=0.0, thickness=0.004, nu=120, nv=12, 907: roll=0, pattern=(scale_pattern(), 0.34)) 908: fit.bind(pc, allow=("Hips", "UpperLeg"), fallback="J_Bip_C_Hips") 909: stiffen(pc, fit, share=share) 910: return _group([pc], "mail") 911: 912: 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: 926: def cuffs(fit, role="glove", name="cuff", length=0.38, flare=0.030, lift=0.010): 927: """Big flared gauntlet cuffs over the lower forearm (oversized, as the study's units wear them).""" 928: B = fit.bone 929: out = [] 930: for side in ("L", "R"): 931: la, hd = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] 932: fore = O.limb_surface(fit, (f"{side}_LowerArm",), side) 933: lc = LimbChart(fore, la, hd, front=(0, 0, -1)) 934: pc, ex = outline_plate(f"{name}_{side}", role, lc, -180, 180, lambda u: 1.04, lambda u: 1.0 - length, offset=lift, 935: flare=lambda u, v, s, t: flare * t ** 1.5, thickness=0.005, nu=40, nv=10, roll=0.004, 936: roll_edges=("top",)) 937: fit.bind(pc, rigid=f"J_Bip_{side}_LowerArm") 938: for p in ex: 939: fit.bind(p, rigid=f"J_Bip_{side}_LowerArm") 940: out += [pc] + ex 941: return _group(out, "gloves") 942: 943: 944: def round_shield(fit, side="L", radius=0.24, wood="wood", rim="steel", name="shield"): 945: """A round wooden shield: planks (grooves), an iron rim and boss, strapped to the forearm.""" 946: E, H = fit.bone[f"J_Bip_{side}_LowerArm"], fit.bone[f"J_Bip_{side}_Hand"] 947: ax = (H - E) / np.linalg.norm(H - E) 948: lat = np.array([-1.0 if side == "L" else 1.0, 0, 0.0]) 949: lat -= ax * (lat @ ax) 950: lat /= np.linalg.norm(lat) 951: up, fw = -ax, np.cross(lat, -ax) 952: centre = E + ax * np.linalg.norm(H - E) * 0.5 + lat * 0.07 953: a = np.linspace(0, 2 * np.pi, 40, endpoint=False) 954: outline = [(radius * math.cos(x), radius * math.sin(x)) for x in a] 955: planks = [("line", [(x, -radius), (x, radius)], 0.0025, "groove") for x in np.linspace(-radius, radius, 7)[1:-1]] 956: face = flat_piece(name, wood, outline, centre, fw, up, thickness=0.014, decal=planks, px=900) 957: P = face["pos"] 958: d2 = ((P - centre) @ fw) ** 2 + ((P - centre) @ up) ** 2 959: P += lat[None] * (0.03 * (1 - d2 / radius ** 2))[:, None] # a shallow dome 960: face["nrm"] = O.vertex_normals(P, face["tri"]) 961: ring = np.array([centre + fw * x + up * y + lat * 0.008 for x, y in outline]) 962: out = [face, O.pipe(f"{name}_rim", rim, ring, r=0.008, seg=6, closed=True)] 963: boss, _ = O.dome(f"{name}_boss", rim, centre + lat * 0.036, lat, up, 0.05, 0.03, rows=6) 964: out.append(boss) 965: _bind(fit, out, f"J_Bip_{side}_LowerArm") 966: return _group(out, "shield") 967: 968: 969: def halberd(fit, length=2.1, grip=0.80, hand="R", name="halberd"): 970: """A halberd: a long haft, an axe blade with a back hook, a spike, langets and a butt.""" 971: fist, fwd, side, flat, _ = _hand_frame(fit, hand) 972: start = fist - fwd * grip 973: out = [O.tube(f"{name}_haft", "wood", start, fwd, length, 0.014)] 974: top = start + fwd * length 975: blade = [(0.02, -0.10), (0.15, -0.13), (0.17, -0.02), (0.15, 0.09), (0.02, 0.05)] 976: hook = [(-0.02, -0.06), (-0.10, -0.04), (-0.12, 0.02), (-0.02, 0.01)] 977: spike = [(0.0, 0.0), (0.016, 0.03), (0.0, 0.26), (-0.016, 0.03)] 978: out.append(flat_piece(f"{name}_blade", "steel", blade, top - fwd * 0.08, side, fwd, thickness=0.007)) 979: out.append(flat_piece(f"{name}_hook", "steel", hook, top - fwd * 0.08, side, fwd, thickness=0.007)) 980: out.append(flat_piece(f"{name}_spike", "steel", spike, top - fwd * 0.02, side, fwd, thickness=0.008)) 981: out.append(O.tube(f"{name}_langet", "steel", top - fwd * 0.30, fwd, 0.30, 0.017)) 982: out.append(O.ball(f"{name}_butt", "steel", start - fwd * 0.012, 0.017, squash=(1, 1, 1.6))) 983: _bind(fit, out, f"J_Bip_{hand}_Hand") 984: return _group(out, "weapon")