A 3D model pipeline, pushed by Gemini 4 Argon
agent (cont.)
+3:56read_file{"EndLine":1272,"Path":"~/work/lowmarch/tools/outfit.py","StartLine":800}
input
{ "EndLine": 1272, "Path": "~/work/lowmarch/tools/outfit.py", "StartLine": 800 }result, 474 lines
Showing lines 800-1272 of 1272 800: chev = [(-0.48, -0.62), (0.10, -0.02), (-0.48, 0.58)] if side == "L" else [(-0.48, 0.62), (0.10, 0.02), (-0.48, -0.58)] 801: line = [] 802: for (u0, v0), (u1, v1) in zip(chev[:-1], chev[1:]): 803: for t in np.linspace(0, 1, 12, endpoint=False): 804: line.append((u0 + (u1 - u0) * t, v0 + (v1 - v0) * t)) 805: line.append(chev[-1]) 806: pts = np.array([surf(u, v) for u, v in line]) 807: nr = np.array([nrm_at(u, v) for u, v in line]) 808: device = ribbon(f"{name}_device", "heraldry", pts, width=radius * 0.24, lift=0.0, normals=nr) 809: rim = pipe(f"{name}_rim", "steel", outer[:-1, -1], r=0.0065, seg=8, closed=True) 810: bs, _ = dome(f"{name}_boss", "steel", centre + lat * (depth - 0.004), lat, up, boss, 0.026, rows=7) 811: out = [face, device, rim, bs] 812: for pc in out: 813: fit.bind(pc, rigid=f"J_Bip_{side}_LowerArm") 814: pc["group"] = "shield" 815: return out 816: 817: 818: # ---- dress, hairdo ------------------------------------------------------------------------- 819: def closed_grid_mesh(P): 820: """(U, V, 3) grid whose U direction wraps around (a skirt) -> (pos, tri).""" 821: U, V = P.shape[:2] 822: idx = np.arange(U * V).reshape(U, V) 823: a, b = idx[:, :-1], np.roll(idx, -1, 0)[:, :-1] 824: c, d = np.roll(idx, -1, 0)[:, 1:], idx[:, 1:] 825: tri = np.concatenate([np.stack([a, b, c], -1).reshape(-1, 3), np.stack([a, c, d], -1).reshape(-1, 3)]) 826: return P.reshape(-1, 3), tri 827: 828: 829: def skirt(fit, name, role, under, collide, y_top, length, flare=0.26, seg=56, rows=20, folds=9, fold_depth=0.012, 830: clear=(0.004, 0.02)): 831: """A full skirt: a closed ring at the waist cast onto `under`, belling out to the hem, settled 832: by the cloth solve against the legs. Simulated in the viewer as closed cloth (no seam).""" 833: cz = fit.bone["J_Bip_C_Hips"][2] 834: o = np.array([0.0, y_top, cz]) 835: ang = np.linspace(0, 2 * math.pi, seg, endpoint=False) 836: rad = np.stack([np.sin(ang), np.zeros_like(ang), np.cos(ang)], 1) 837: top = [] 838: for d in rad: 839: r = under.cast(o, d, rmax=0.3, far=True) 840: top.append(o + d * ((0.13 if np.isnan(r) else r) + clear[0])) 841: top = np.array(top) 842: P = np.zeros((seg, rows, 3)) 843: for j, t in enumerate(np.linspace(0, 1, rows)): 844: bell = flare * (1 - (1 - t) ** 1.6) # flares fast below the hips, then falls 845: wave = fold_depth * t * np.sin(ang * folds + 0.4) 846: P[:, j] = top + rad * (bell + wave)[:, None] + np.array([0, -length * t, 0]) 847: pinned = np.zeros((seg, rows), bool) 848: pinned[:, 0] = True 849: P = drape(P, collide, clear[0] + (clear[1] - clear[0]) * np.linspace(0, 1, rows), pinned, steps=60, closed=True) 850: pos, tri = closed_grid_mesh(P) 851: pc = piece(name, role, pos, tri, outward_from=o, axis=[0, 1, 0]) 852: fit.bind(pc, allow=("Hips", "UpperLeg"), fallback="J_Bip_C_Hips") 853: pc["grid"] = (seg, rows) 854: pc["closed"] = True 855: return pc, P 856: 857: 858: def updo(fit, hair_role="hair", ribbon_role="signature"): 859: """A braided bun at the back of the head, a ribbon tied on it, and one cowlick strand rising 860: from the crown. Offsets are measured on the female sample head and follow the head's scale.""" 861: H = fit.world["J_Bip_C_Head"] 862: hs = float(np.linalg.norm(H[:3, 0])) 863: h = H[:3, 3] 864: at = lambda x, y, z: h + hs * np.array([x, y, z]) 865: out = [] 866: c = at(0.0, 0.118, 0.142) 867: out.append(ball("bun", hair_role, c, 0.046 * hs, seg=20, rows=12, squash=(1.0, 0.86, 0.72))) 868: # the braid wound around the bun: two strands twisting around a ring 869: ring_r, n = 0.050 * hs, 96 870: th = np.linspace(0, 2 * math.pi, n, endpoint=False) 871: for k, ph in enumerate((0.0, math.pi)): 872: tw = th * 7 + ph 873: rr = ring_r + 0.008 * hs * np.cos(tw) 874: zz = 0.008 * hs * np.sin(tw) 875: pts = c + np.stack([rr * np.cos(th), rr * np.sin(th) * 0.86, -0.012 * hs + zz], 1) 876: out.append(pipe(f"braid{k}", hair_role, pts, r=0.0085 * hs, seg=7, closed=True)) 877: # ribbon: two loops and a knot on top of the bun 878: knot = c + hs * np.array([0.0, 0.040, -0.004]) 879: out.append(ball("ribbon_knot", ribbon_role, knot, 0.011 * hs, seg=10, rows=7)) 880: for sx in (-1, 1): 881: out.append(ball(f"ribbon_loop{(sx + 1) // 2}", ribbon_role, knot + hs * np.array([sx * 0.030, 0.006, 0.004]), 882: 0.022 * hs, seg=12, rows=8, squash=(1.0, 0.55, 0.32))) 883: # the cowlick: a tapered strand rising from the crown and curling forward 884: t = np.linspace(0, 1, 20) 885: pts = np.stack([0.003 * np.sin(t * 3), 0.236 + 0.062 * np.sin(t * 2.2), -0.004 - 0.050 * t - 0.012 * np.sin(t * 5)], 1) 886: pts = h + hs * pts 887: st = pipe("cowlick", hair_role, pts, r=0.013 * hs, seg=10) 888: sp = st["pos"].reshape(len(t), 11, 3) 889: off = sp - pts[:, None] 890: off[..., 0] *= 0.35 # a flat lock, not a round stalk 891: sp[:] = pts[:, None] + off * (1 - 0.9 * t ** 0.8)[:, None, None] 892: st["pos"] = sp.reshape(-1, 3) 893: out.append(st) 894: for pc in out: 895: fit.bind(pc, rigid="J_Bip_C_Head") 896: pc["group"] = "hair" 897: return out 898: 899: 900: def sabaton(fit, name, side, role="metal", pad=0.010, ridges=3, seg=26, rows=14): 901: """A steel shoe over the whole foot (hides the base model's toes), built as a shoe last from 902: the foot's measurements: sole outline rounded at heel and toe and widest at the ball, top 903: rising from a rounded toe over the instep to the ankle at the heel. Lame ridges follow its 904: cross-section over the instep. Rides the foot bone. 905: (A squashed ellipsoid read as a triangular hoof; a shell projected onto the foot's convex 906: hull creased on the hull's facets.)""" 907: w = fit.weight((f"{side}_Foot", f"{side}_ToeBase")) 908: P = fit.pos[w > 0.5] 909: P = P[(P[:, 0] < 0.01) if side == "L" else (P[:, 0] > -0.01)] 910: lo, hi = P.min(0), P.max(0) 911: sole = lo[1] - 0.003 912: ankle = fit.bone[f"J_Bip_{side}_Foot"][1] 913: z_heel, z_toe = hi[2] + pad, lo[2] - pad # the foot points -z 914: width = (hi[0] - lo[0]) + 2 * pad 915: S = np.linspace(0, 1, seg) 916: # centreline: the foot's middle at each station, smoothed 917: cx = np.array([np.median(P[np.abs(P[:, 2] - (z_heel + t * (z_toe - z_heel))) < 0.02, 0]) 918: 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]) 919: cx = np.convolve(np.pad(cx, 3, mode="edge"), np.ones(7) / 7, "valid") 920: ends = np.sin(np.pi * np.clip(S, 0, 1)) ** 0.42 # rounds the heel and the toe 921: half_w = width / 2 * ends * (0.80 + 0.20 * np.sin(np.pi * np.clip(S * 1.2, 0, 1))) # widest at the ball 922: 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 923: tall = np.maximum(tall * np.sin(np.pi * np.clip(S, 0, 1)) ** 0.22, 0.004) 924: phi = np.linspace(0, np.pi, rows) 925: G = np.zeros((seg, rows, 3)) 926: for i, t in enumerate(S): 927: z = z_heel + t * (z_toe - z_heel) 928: G[i] = np.stack([cx[i] + half_w[i] * np.cos(phi), sole + tall[i] * np.sin(phi), np.full(rows, z)], 1) 929: pos, tri = grid_mesh(G) 930: c = np.array([(lo[0] + hi[0]) / 2, sole, (z_heel + z_toe) / 2]) 931: pc = piece(name, role, pos, tri, outward_from=c - [0, 0.05, 0]) 932: out = [pc] 933: for k, t in enumerate(np.linspace(0.50, 0.74, ridges)): # lames over the instep 934: i = int(round(t * (seg - 1))) 935: 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 936: out.append(pipe(f"{name}_ridge{k}", role, ring, r=0.0024)) 937: for q_ in out: 938: fit.bind(q_, rigid=f"J_Bip_{side}_Foot") 939: return out 940: 941: 942: def knight_dress(fit): 943: """A blonde knight-princess: a long blue dress with a white petticoat edge, a fitted steel 944: breastplate, small spaulders, steel gauntlets and armoured boots, a two-handed sword with a 945: gold hilt, and her hair up in a braided bun with a ribbon.""" 946: B = fit.bone 947: nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] 948: knee = B["J_Bip_L_LowerLeg"][1] 949: out = [] 950: 951: def grouped(pcs, g): 952: for pc in pcs: 953: if pc is not None: 954: pc["group"] = g 955: return [pc for pc in pcs if pc is not None] 956: 957: def rolled(name, pc, rims, r=0.0024, role="metal"): 958: return [inherit(pipe(f"{name}_roll{k}", role, rim, r=r), pc) for k, rim in enumerate(rims)] 959: 960: def cuff_plane(side): 961: a, hd = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] 962: n = (hd - a) / np.linalg.norm(hd - a) 963: return n, n @ (hd - n * 0.035) 964: 965: torso = ("Spine", "Chest", "UpperChest", "Bust", "Shoulder", "UpperArm", "LowerArm", "Neck", "Hips") 966: bodice = wrap(fit, "bodice", "signature", torso, offset=0.006, exclude=("UpperLeg",), 967: y_min=hips[1] + 0.02, y_max=nk[1] + 0.012, hems=[cuff_plane("L"), cuff_plane("R")]) 968: tights = wrap(fit, "tights", "doublet", ("Hips", "UpperLeg", "LowerLeg"), offset=0.004, y_max=hips[1] + 0.03, subdiv=1) 969: boots = wrap(fit, "boots", "metal", ("LowerLeg", "Foot"), offset=0.014, y_max=knee - 0.06, exclude=("ToeBase",), 970: subdiv=1, hems=[((0, 1, 0), knee - 0.065)]) 971: gloves = wrap(fit, "gloves", "metal", ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), 972: offset=0.0035, min_w=0.3, smooth=4) 973: out += grouped([bodice], "dress") + grouped([tights], "trousers") + grouped([boots], "boots") + grouped([gloves], "gloves") 974: out += grouped(sabaton(fit, "sabaton_L", "L") + sabaton(fit, "sabaton_R", "R"), "boots") 975: col, rim, _ = collar(fit, "collar", "signature", height_back=0.034, height_front=0.022) 976: out += grouped([col, inherit(pipe("collar_trim", "gold", rim, r=0.0022), col)], "dress") 977: 978: # steel breastplate, fitted, ending at the natural waist; gold line along the neckline 979: cuirass = wrap(fit, "breastplate", "steel", ("Spine", "Chest", "UpperChest", "Bust"), offset=0.010, # the female 980: # base weights the chest to its own Bust bones: leave them out and the plate has two holes 981: exclude=("Shoulder", "UpperArm", "Neck"), y_min=hips[1] + 0.085, y_max=nk[1] - 0.065, 982: base=Surface(bodice["pos"], bodice["tri"]), smooth=70, # a rigid shell, not a moulded bust 983: hems=[((0, 1, 0), hips[1] + 0.095), ((0, 1, 0), nk[1] - 0.075)]) 984: loops = sorted([cuirass["pos"][L] for L in cuirass["loops"] if len(L) > 12], key=lambda Lp: -Lp[:, 1].mean()) 985: out += grouped([cuirass] + [inherit(pipe(f"breastplate_roll{k}", "gold" if k == 0 else "metal", Lp, r=0.003, 986: closed=True), cuirass) for k, Lp in enumerate(loops)], "plate") 987: 988: # the skirt from the waist to the ankle, white petticoat edge (the viewer's border band) 989: legs = merge_surfaces((tights["pos"], tights["tri"]), (boots["pos"], boots["tri"])) 990: # the waist ring is cast onto the bodice without its sleeves: with them, the hanging arms beside 991: # the hips held the ring out at the sides, a shelf the user saw once the arms moved 992: waist = merge_surfaces(without(bodice, ("Shoulder", "UpperArm", "LowerArm", "Hand")), (tights["pos"], tights["tri"])) 993: ytop = hips[1] + 0.08 994: sk, grid = skirt(fit, "skirt", "signature", waist, legs, ytop, ytop - 0.24, flare=0.17) # hem above the ankle 995: sk["group"] = "dress" 996: out.append(sk) 997: out += grouped([inherit(ribbon("skirt_hem", "heraldry", np.concatenate([grid[:, -1], grid[:1, -1]]), width=0.03, 998: lift=0.0015, normals=near_normals(sk, np.concatenate([grid[:, -1], grid[:1, -1]]))), sk)], 999: "dress") 1000: out += grouped([inherit(pipe("waist_trim", "gold", grid[:, 0], r=0.0035, closed=True), sk)], "dress") 1001: 1002: plate_body = merge_surfaces((cuirass["pos"], cuirass["tri"]), (bodice["pos"], bodice["tri"]), (fit.pos, fit.tri)) 1003: for side in ("L", "R"): 1004: ll, ft = B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"] 1005: la, hd = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] 1006: sp, rims = pauldron(fit, f"spaulder_{side}", "steel", plate_body, side=side, 1007: lames=((0, 54, 0.016, 0.022), (46, 76, 0.014, 0.020)), spread=105) 1008: out += grouped(sp, "plate") + grouped(sum((rolled(f"spaulder_{side}{k}", pc, [r_]) for k, (pc, r_) in 1009: enumerate(zip(sp, rims))), []), "plate") 1010: fore = limb_surface(fit, (f"{side}_LowerArm",), side) 1011: vb, rims = limb_lames(fit, f"vambrace_{side}", "steel", fore, la, hd, ((0.10, 0.97, 0.014, 0.017),), rmax=0.11) 1012: fit.bind(vb[0], rigid=f"J_Bip_{side}_LowerArm") 1013: out += grouped(vb + rolled(f"vambrace_{side}", vb[0], rims[0]), "plate") 1014: arm = limb_surface(fit, (f"{side}_LowerArm", f"{side}_UpperArm"), side) 1015: jg, jr = joint_guard(fit, f"couter_{side}", f"J_Bip_{side}_LowerArm", f"J_Bip_{side}_Hand", (0, 0, 1), side, 1016: arm, r=0.026, wing=0.042, depth=0.018) 1017: for pc in jg: 1018: fit.bind(pc, rigid=f"J_Bip_{side}_LowerArm") 1019: out += grouped(jg, "plate") 1020: shin = side_of(boots, side) 1021: # the greave starts below the boot's top: above it the casts find no boot and the knee bulges past it 1022: top = (knee - 0.075 - ll[1]) / (ft[1] - ll[1]) 1023: gv, rims = limb_lames(fit, f"greave_{side}", "steel", shin, ll, ft, ((top, 0.80, 0.006, 0.009),), rmax=0.11) 1024: fit.bind(gv[0], rigid=f"J_Bip_{side}_LowerLeg") 1025: out += grouped(gv + rolled(f"greave_{side}", gv[0], rims[0]), "plate") 1026: 1027: import hair 1028: out += [pc for pc in updo(fit) if pc["material"] != "OUTFIT_cowlick"] + hair.elaine(fit) 1029: out += sword(fit, "R", blade_len=0.84, blade_w=0.046, grip_len=0.21, hilt="gold", grip="signature") 1030: return [p for p in out if p is not None] 1031: 1032: 1033: # ---- costumes ------------------------------------------------------------------------- 1034: def lord_tunic(fit): 1035: """The first lord costume, head to toe: tunic, tails, belt, trousers, boots, gloves, a standing collar, 1036: shoulder plates on the near (left) shoulder over a cape clasped at the collarbones, gold trim, 1037: and a sword in the right hand.""" 1038: B = fit.bone 1039: nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] 1040: knee = B["J_Bip_L_LowerLeg"][1] 1041: out = [] 1042: 1043: def cuff_plane(side): 1044: a, h = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] 1045: n = (h - a) / np.linalg.norm(h - a) 1046: return n, n @ (h - n * 0.025) 1047: 1048: torso = ("Spine", "Chest", "UpperChest", "Shoulder", "UpperArm", "LowerArm", "Neck", "Hips") 1049: tunic = wrap(fit, "tunic", "coat", torso, offset=0.009, exclude=("UpperLeg",), 1050: y_min=hips[1] - 0.03, y_max=nk[1] + 0.012, hems=[cuff_plane("L"), cuff_plane("R")]) 1051: trousers = wrap(fit, "trousers", "leather", ("Hips", "UpperLeg", "LowerLeg"), offset=0.008, 1052: y_max=hips[1] + 0.02, subdiv=1) 1053: boots = wrap(fit, "boots", "boot", ("LowerLeg", "Foot", "ToeBase"), offset=0.017, y_max=knee - 0.07, 1054: subdiv=1, hems=[((0, 1, 0), knee - 0.075)]) 1055: gloves = wrap(fit, "gloves", "glove", ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), 1056: offset=0.0028, min_w=0.6, smooth=4) 1057: out += [p for p in (tunic, trousers, boots, gloves) if p is not None] 1058: under = merge_surfaces((tunic["pos"], tunic["tri"]), (fit.pos, fit.tri)) 1059: 1060: for side in ("L", "R"): 1061: hand, shin = B[f"J_Bip_{side}_Hand"], B[f"J_Bip_{side}_LowerLeg"] 1062: out.append(loop_trim(f"cuff_trim_{side}", "gold", tunic, lambda P, h=hand: -np.linalg.norm(P.mean(0) - h), width=0.010)) 1063: out.append(loop_trim(f"boot_trim_{side}", "leather", boots, lambda P, f=shin: -np.linalg.norm(P.mean(0) - f), 1064: width=0.016, lift=0.003)) 1065: pl = slice_line(tunic, 0, 0.0, keep=lambda p: p[2] < hips[2] - 0.02 and hips[1] + 0.06 < p[1] < nk[1] - 0.02) 1066: if len(pl) > 3: 1067: out.append(inherit(ribbon("placket", "gold", pl, width=0.009, lift=0.0015, normals=near_normals(tunic, pl)), tunic)) 1068: 1069: # waist first: belt over the tunic, tails tucked under it 1070: b, buckle = belt(fit, "belt", "leather", under, hips[1] + 0.035) 1071: out.append(b) 1072: out.append(fit.bind(box("buckle", "gold", buckle + [0, 0, -0.006], ((1, 0, 0), (0, 1, 0), (0, 0, 1)), 1073: (0.02, 0.021, 0.004)), rigid="J_Bip_C_Hips")) 1074: # the tails settle against the hips and legs only: colliding with the hanging sleeves held them out 1075: hip_skin = fit.tris_for(("Hips", "UpperLeg", "Spine"), min_w=0.5) 1076: legs = merge_surfaces((trousers["pos"], trousers["tri"]), (fit.pos, hip_skin)) 1077: tl, tgrid = tails(fit, "tails", "coat", legs, y_top=hips[1] + 0.025) 1078: out.append(tl) 1079: out.append(inherit(ribbon("tails_hem", "gold", tgrid[:, -1], width=0.011, lift=0.002, 1080: normals=near_normals(tl, tgrid[:, -1])), tl)) 1081: 1082: # cape first, then the plates over it 1083: behind = merge_surfaces((tunic["pos"], tunic["tri"]), (tl["pos"], tl["tri"]), (b["pos"], b["tri"]), (fit.pos, fit.tri)) 1084: cp, grid = cape(fit, "cape", "cape", behind) 1085: out.append(cp) 1086: for nm, line, w in (("cape_trim", grid[:, 0], 0.009), ("cape_hem", grid[:, -1], 0.012), 1087: ("cape_edge0", grid[0], 0.009), ("cape_edge1", grid[-1], 0.009)): 1088: out.append(inherit(ribbon(nm, "gold", line, width=w, lift=0.002, normals=near_normals(cp, line)), cp)) 1089: for k, edge in enumerate((grid[0], grid[-1])): 1090: out.append(fit.bind(ball(f"clasp{k}", "gold", edge[0] + (edge[0] - nk) * 0.04, 0.012, squash=(1, 1, 0.5)), 1091: rigid="J_Bip_C_UpperChest")) 1092: over = merge_surfaces((tunic["pos"], tunic["tri"]), (cp["pos"], cp["tri"])) 1093: plates, rims = pauldron(fit, "pauldron", "metal", over, side="L") 1094: out += plates 1095: for k, (pc, rim) in enumerate(zip(plates, rims)): 1096: out.append(inherit(ribbon(f"pauldron_trim{k}", "gold", rim, width=0.006, lift=0.001, 1097: normals=near_normals(pc, rim)), pc)) 1098: 1099: col, rim, fronts = collar(fit, "collar", "coat") 1100: out.append(col) 1101: out.append(inherit(ribbon("collar_trim", "gold", rim, width=0.007, lift=0.001, normals=near_normals(col, rim)), col)) 1102: for k, edge in enumerate(fronts): 1103: out.append(inherit(ribbon(f"collar_edge{k}", "gold", edge, width=0.006, lift=0.001, 1104: normals=near_normals(col, edge)), col)) 1105: 1106: out += sword(fit, "R") 1107: return [p for p in out if p is not None] 1108: 1109: 1110: def lord(fit): 1111: """The young lord after the Unicorn Overlord study (their lord: half-plate, hooded scarf, long 1112: tabard, round shield, one signature colour, almost no gold). Built inside out, the study's 1113: layering order, so each layer is cast onto the one under it and shows a sliver: 1114: doublet (dark, so it never reads as skin) + trousers, boots, gloves with gauntlet cuffs 1115: plate: breastplate, tassets, spaulders, vambraces and greaves, couters and poleyns with wings 1116: a wide leather belt with a square steel buckle 1117: tabard front and back (signature crimson, pale heraldic border), cloth 1118: hooded mantle (crimson) over the shoulders, clasped at the front 1119: shield on the left forearm, sword in the right hand 1120: """ 1121: B = fit.bone 1122: nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] 1123: knee = B["J_Bip_L_LowerLeg"][1] 1124: out = [] 1125: 1126: def cuff_plane(side): # sleeves end under the gauntlet cuff 1127: a, h = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] 1128: n = (h - a) / np.linalg.norm(h - a) 1129: return n, n @ (h - n * 0.035) 1130: 1131: def grouped(pcs, g): 1132: for pc in pcs: 1133: if pc is not None: 1134: pc["group"] = g 1135: return [pc for pc in pcs if pc is not None] 1136: 1137: def rolled(name, pc, rims, r=0.0028): 1138: """A rolled steel edge along each rim: what defines plate in the study instead of gold.""" 1139: return [inherit(pipe(f"{name}_roll{k}", "metal", rim, r=r), pc) for k, rim in enumerate(rims)] 1140: 1141: # 1-2: the doublet and what's under it 1142: torso = ("Spine", "Chest", "UpperChest", "Shoulder", "UpperArm", "LowerArm", "Neck", "Hips") 1143: doublet = wrap(fit, "doublet", "doublet", torso, offset=0.008, exclude=("UpperLeg",), 1144: y_min=hips[1] - 0.03, y_max=nk[1] + 0.012, hems=[cuff_plane("L"), cuff_plane("R")]) 1145: trousers = wrap(fit, "trousers", "leather", ("Hips", "UpperLeg", "LowerLeg"), offset=0.008, 1146: y_max=hips[1] + 0.02, subdiv=1) 1147: boots = wrap(fit, "boots", "boot", ("LowerLeg", "Foot", "ToeBase"), offset=0.017, y_max=knee - 0.07, 1148: subdiv=1, hems=[((0, 1, 0), knee - 0.075)]) 1149: gloves = wrap(fit, "gloves", "glove", ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), 1150: offset=0.0028, min_w=0.3, smooth=4) # down over the wrist: no gap under the cuff 1151: out += grouped([doublet], "doublet") + [p for p in (trousers, boots, gloves) if p is not None] 1152: col, _, _ = collar(fit, "collar", "doublet", height_back=0.030, height_front=0.018) 1153: out += grouped([col], "doublet") 1154: body_d = merge_surfaces((doublet["pos"], doublet["tri"]), (fit.pos, fit.tri)) 1155: 1156: # 4: plate 1157: cuirass = wrap(fit, "breastplate", "steel", ("Spine", "Chest", "UpperChest", "Hips"), offset=0.014, 1158: exclude=("Shoulder", "UpperArm", "Neck", "UpperLeg"), y_min=hips[1] + 0.030, y_max=nk[1] - 0.040, 1159: base=Surface(doublet["pos"], doublet["tri"]), smooth=40, 1160: hems=[((0, 1, 0), hips[1] + 0.040), ((0, 1, 0), nk[1] - 0.050)]) 1161: keel = np.clip(1 - np.abs(cuirass["pos"][:, 0]) / 0.07, 0, 1) * (cuirass["pos"][:, 2] < B["J_Bip_C_Chest"][2]) 1162: cuirass["pos"] = cuirass["pos"] + cuirass["nrm"] * (0.007 * keel ** 2)[:, None] # a soft central ridge 1163: cuirass["nrm"] = vertex_normals(cuirass["pos"], cuirass["tri"]) 1164: loops = [cuirass["pos"][L] for L in cuirass["loops"] if len(L) > 12] 1165: out += grouped([cuirass] + [inherit(pipe(f"breastplate_roll{k}", "metal", Lp, r=0.0034, closed=True), cuirass) 1166: for k, Lp in enumerate(loops)], "plate") 1167: plate_body = merge_surfaces((cuirass["pos"], cuirass["tri"]), (doublet["pos"], doublet["tri"]), (fit.pos, fit.tri)) 1168: 1169: for side in ("L", "R"): 1170: sx = -1 if side == "L" else 1 1171: ul, ll, ft = B[f"J_Bip_{side}_UpperLeg"], B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"] 1172: ua, la, hd = B[f"J_Bip_{side}_UpperArm"], B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] 1173: # tassets: three lames on the front and outside of each thigh, hung from the waist 1174: thigh = side_of(trousers, side) 1175: arc = (-125, 20) if side == "L" else (-20, 125) 1176: # tops tuck under the belt (small offset there), lower rims flare out 1177: tas, rims = limb_lames(fit, f"tasset_{side}", "steel", thigh, ul + [0, 0.085, 0], ul + (ll - ul) * 0.46, 1178: ((0.0, 0.40, 0.006, 0.026), (0.33, 0.70, 0.018, 0.026), (0.63, 1.0, 0.016, 0.024)), 1179: arc=arc, rmax=0.16) 1180: for k, pc in enumerate(tas): 1181: fit.bind(pc, blend={"J_Bip_C_Hips": 0.55 - 0.2 * k, f"J_Bip_{side}_UpperLeg": 0.45 + 0.2 * k}) 1182: out += grouped(tas, "plate") + grouped(sum((rolled(f"tasset_{side}{k}", pc, [r[1]]) for k, (pc, r) in 1183: enumerate(zip(tas, rims))), []), "plate") 1184: # greaves over the boots, poleyns with wings at the knee 1185: shin = side_of(boots, side) 1186: gv, rims = limb_lames(fit, f"greave_{side}", "steel", shin, ll, ft, ((0.12, 0.80, 0.008, 0.011),), rmax=0.11) 1187: fit.bind(gv[0], rigid=f"J_Bip_{side}_LowerLeg") 1188: out += grouped(gv + rolled(f"greave_{side}", gv[0], rims[0]), "plate") 1189: leg = merge_surfaces((trousers["pos"], trousers["tri"]), (boots["pos"], boots["tri"])) 1190: jg, jr = joint_guard(fit, f"poleyn_{side}", f"J_Bip_{side}_LowerLeg", f"J_Bip_{side}_Foot", (0, 0, -1), side, 1191: side_of(trousers, side), r=0.036, wing=0.060) 1192: for pc in jg: 1193: fit.bind(pc, rigid=f"J_Bip_{side}_LowerLeg") 1194: out += grouped(jg + sum((rolled(f"poleyn_{side}{k}", pc, [rim]) for k, (pc, rim) in enumerate(zip(jg, jr))), []), 1195: "plate") 1196: # vambraces and couters with wings 1197: fore = limb_surface(fit, (f"{side}_LowerArm",), side) 1198: vb, rims = limb_lames(fit, f"vambrace_{side}", "steel", fore, la, hd, ((0.12, 0.64, 0.017, 0.020),), rmax=0.11)74 more lines not shown.