A 3D model pipeline, pushed by Gemini 4 Argon
agent
+23:19reasoning
The code appears to be defining and applying armor components, specifically a breastplate. The wrap function is used, suggesting a process of fitting a "steel" breastplate to various body regions, possibly with an offset. Examining the exclude argument within the call indicates certain body parts are being explicitly omitted from this fitting process. This points to a potential area for customization of armor fitting.
The current breastplate fitting is flawed because the missing refloor argument allows the top hem to sink into the bodice. An alternative is to leverage the existing gear.breastplate function, which might offer a better solution, potentially with added refinement parameters. Investigating gear.breastplate to determine its suitability is essential.
The current implementation's use of stiffen to bind the breastplate directly to the chest explains why the armor doesn't deform realistically during arm movement, preventing the bodice from poking through. The core of the problem lies in the skin weights assigned to the breastplate during the wrap() process, which directly copies skin weights from the body mesh. This includes weights for the shoulder and upper arm, causing the armor to deform with arm movements, even when it should be rigid. The next step is to test modifying the armor skinning to be more independent.
run_command{"CommandLine":"grep -rn \"stiffen\\|drop_skin\\|without\" tools/","WaitMsBeforeAsync":5000,"toolSummary":"Search for stiffen and drop_skin in tools/"}
input
{ "CommandLine": "grep -rn \"stiffen\\|drop_skin\\|without\" tools/", "WaitMsBeforeAsync": 5000, "toolSummary": "Search for stiffen and drop_skin in tools/" }result, 41 lines
Command exited with code 0. Command output: tools/vecpix.py:4:with palette ROLE characters, rasterised at SSx without anti-aliasing, then tools/mobs.py:69: fit.drop_skin = lambda p: ((p["pos"][:, 1] > lo + 0.015) & (p["pos"][:, 1] < hi - 0.015) tools/mobs.py:79: return Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) tools/mobs.py:199: under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) tools/mobs.py:244: shirt["tri"] = O.without(shirt, ("UpperArm", "LowerArm", "Hand"))[1] tools/mobs.py:246: under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) tools/mobs.py:264: under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) tools/mobs.py:283: under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) tools/mobs.py:304: under = Surface(*O.without(shirt, ("Shoulder", "UpperArm", "LowerArm", "Hand"))) tools/outfit.py:11: gloves): seams welded, smoothed without shrinking, every vertex set at an offset tools/outfit.py:230:def without(pc, bones, max_w=0.3): tools/outfit.py:232: without its sleeves. Casting a waist ring onto a garment with its sleeves in it catches the tools/outfit.py:990: # the waist ring is cast onto the bodice without its sleeves: with them, the hanging arms beside tools/outfit.py:992: waist = merge_surfaces(without(bodice, ("Shoulder", "UpperArm", "LowerArm", "Hand")), (tights["pos"], tights["tri"])) tools/makehuman.py:669: if "lid_line" in c: # a base without lash cards: the lid's edge, inner to outer tools/rig.py:62: base = cur @ np.linalg.inv(adj_old[:3, :3]) # world rotation without this bone's adjustment grep: tools/__pycache__/outfit.cpython-310.pyc: binary file matches grep: tools/__pycache__/gear.cpython-310.pyc: binary file matches grep: tools/__pycache__/vroid_portrait.cpython-310.pyc: binary file matches grep: tools/__pycache__/plates.cpython-310.pyc: binary file matches grep: tools/__pycache__/vecpix.cpython-310.pyc: binary file matches tools/saber_study.py:16:from plates import TorsoChart, LimbChart, ConeChart, outline_plate, stiffen, flat_piece, taper tools/saber_study.py:83: torso_only = O.without(bodice, ("Shoulder", "UpperArm", "LowerArm", "Hand")) tools/saber_study.py:96: # ---- the chest chart (the bodice without its sleeves) -------------------------------------- tools/saber_study.py:241: stiffen(pet, fit, share=0.65) tools/session/rows.py:10: index_noref.html the same without it, for publishing: docs/study.md keeps references off published pages until the tools/plates.py:398:def stiffen(pc, fit, bone="J_Bip_C_Hips", share=0.6): tools/proportions.py:151: # the torso's triangles without arm skin, cut across exactly (a band of vertices catches only tools/heads.py:357: while st: # say where its last bone points (without tools/vroid_portrait.py:1000: if getattr(fit, "drop_skin", None) is not None: # a costume may hide the skin it covers tools/vroid_portrait.py:1001: p["tri"] = p["tri"][~fit.drop_skin(p)[p["tri"]].all(1)] tools/vroid_portrait.py:1087: """The view's camera (self.camera, which the live viewer uses) without rendering.""" tools/gear.py:14:from plates import TorsoChart, LimbChart, ConeChart, outline_plate, stiffen, flat_piece, taper, Canvas tools/gear.py:198: stiffen(skirt, fit, share=0.55) tools/gear.py:237: stiffen(skirt, fit, share=0.5) tools/gear.py:442: stiffen(skirt, fit, share=0.6) tools/gear.py:909: stiffen(pc, fit, share=share) tools/gear.py:922: stiffen(pc, fit, share=0.5)read_file{"EndLine":95,"Path":"~/work/lowmarch/tools/mobs.py","StartLine":55}
input
{ "EndLine": 95, "Path": "~/work/lowmarch/tools/mobs.py", "StartLine": 55 }result, 42 lines
Showing lines 55-95 of 311 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)."""read_file{"EndLine":135,"Path":"~/work/lowmarch/tools/saber_study.py","StartLine":75}
input
{ "EndLine": 135, "Path": "~/work/lowmarch/tools/saber_study.py", "StartLine": 75 }result, 62 lines
Showing lines 75-135 of 541 75: bodice = O.wrap(fit, "bodice", "signature", torso, offset=0.006, exclude=("UpperLeg",), 76: y_min=hips[1] + 0.02, y_max=nk[1] + 0.012, hems=[cuff_plane("L"), cuff_plane("R")]) 77: tights = O.wrap(fit, "tights", "doublet", ("Hips", "UpperLeg", "LowerLeg"), offset=0.004, y_max=hips[1] + 0.03, subdiv=1) 78: boots = O.wrap(fit, "boots", "metal", ("LowerLeg", "Foot"), offset=0.012, y_max=knee - 0.10, exclude=("ToeBase",), 79: subdiv=1, hems=[((0, 1, 0), knee - 0.105)]) 80: gloves = O.wrap(fit, "gloves", "glove", ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), 81: offset=0.0035, min_w=0.3, smooth=4) 82: out += _grouped([bodice], "dress") + _grouped([tights], "trousers") + _grouped([boots], "boots") + _grouped([gloves], "gloves") 83: torso_only = O.without(bodice, ("Shoulder", "UpperArm", "LowerArm", "Hand")) 84: chest = Surface(*torso_only) 85: 86: # ---- collar: a close stand collar, gold band along its top, gold line down the front ---------- 87: col, rim, fronts = O.collar(fit, "collar", "signature", height_back=0.040, height_front=0.034, gap_deg=6, 88: clear=(0.008, 0.012)) 89: band = rim - np.array([0, 0.0042, 0]) 90: out += _grouped([col, O.inherit(O.ribbon("collar_band", "gold", band, width=0.0075, lift=0.0012, 91: normals=O.near_normals(col, band)), col)], "dress") 92: for k, edge in enumerate(fronts): 93: out += _grouped([O.inherit(O.ribbon(f"collar_front{k}", "gold", edge, width=0.0035, lift=0.0012, 94: normals=O.near_normals(col, edge)), col)], "dress") 95: 96: # ---- the chest chart (the bodice without its sleeves) -------------------------------------- 97: tc = TorsoChart(chest, y(0.36), y(0.14), cz=cz, du=2.0, dv=0.006, smooth=(1.6, 1.4)) 98: 99: # back: two short gold strips from the collar base, down and outward (a Lambda) 100: for s in (-1, 1): 101: pts = tc.point(np.array([180 + s * 6, 180 + s * 26]), np.array([y(0.165), y(0.215)]), off=0.002) 102: out += _grouped(_bind_strip(fit, pts, s, tc, y), "dress") 103: 104: # ---- cuirass: domed panels between grooves, studs at the junctions, painted blue motifs ------- 105: yb, yv, ybust = y(0.303), y(0.280), y(0.246) 106: 107: def front_top(u): 108: a = abs(u) 109: if a <= 34: 110: return y(0.197) 111: if a <= 80: 112: return y(0.197) + (y(0.226) - y(0.197)) * ((a - 34) / 46) ** 1.3 113: return y(0.226) + (y(0.236) - y(0.226)) * min(1.0, (a - 80) / 18) 114: 115: seams, studs = [], [] 116: for s in (-1, 1): 117: seams += [[(s * 34, y(0.199)), (s * 60, ybust), (s * 38, y(0.262)), (s * 14, y(0.274)), (0, yv)], 118: [(s * 60, ybust), (s * 99, ybust)], 119: [(s * 31, y(0.267)), (s * 52, y(0.288)), (s * 60, yb - 0.004)]] 120: studs += [(s * 60, ybust), (s * 31, y(0.267)), (s * 60, yb + 0.012)] 121: seams.append([(0, yv), (0, yb - 0.004)]) 122: motif = [] 123: # bust panel: a curl glyph with a dot, a stem down to the V, a fan of six blades rising from it 124: motif += [curl(tc, 0, y(0.213), 0.0075, turns=1.1), ("dot", (0, y(0.205)), 0.0023, "paint"), 125: stroke(tc, 0, y(0.219), [(0, 0), (0, -(y(0.219) - y(0.276)))], width=0.0016)] 126: for s in (-1, 1): 127: for ang, L in ((20, 0.056), (40, 0.072), (60, 0.086)): 128: motif.append(leaf(tc, 0, y(0.277), s * ang, L, 0.016)) 129: for ang, L in ((22, 0.034), (46, 0.040), (70, 0.036)): # the abdomen panels: small fans up and out 130: motif.append(leaf(tc, s * 14, y(0.301), s * ang, L, 0.010)) 131: front, fx = outline_plate("cuirass", "steel", tc, -99, 99, lambda u: yb, front_top, offset=0.011, crown=0.004, 132: thickness=0.003, nu=110, nv=44, roll=0.0022, roll_edges=("top",), roll_role="steel", 133: seams=seams, groove=(0.0060, 0.0022), panel_crown=0.0035, studs=studs, stud_r=0.0038, 134: decal=motif, decal_px=1600) 135: back_top = lambda u: y(0.190) + (y(0.236) - y(0.190)) * (abs(((u % 360) - 180)) / 82) ** 1.6read_file{"EndLine":175,"Path":"~/work/lowmarch/tools/saber_study.py","StartLine":135}
input
{ "EndLine": 175, "Path": "~/work/lowmarch/tools/saber_study.py", "StartLine": 135 }result, 42 lines
Showing lines 135-175 of 541 135: back_top = lambda u: y(0.190) + (y(0.236) - y(0.190)) * (abs(((u % 360) - 180)) / 82) ** 1.6 136: bseams = [[(129, ybust), (180, y(0.262)), (231, ybust)], [(99, y(0.283)), (261, y(0.283))]] 137: back, bx = outline_plate("backplate", "steel", tc, 99, 261, lambda u: yb, back_top, offset=0.011, crown=0.004, 138: thickness=0.003, nu=80, nv=36, roll=0.0022, roll_edges=("top",), roll_role="steel", 139: seams=bseams, groove=(0.0035, 0.0018), panel_crown=0.003, 140: studs=[(129, ybust), (231, ybust)], stud_r=0.0038, decal_px=1200) 141: # the gorget: a separate plate over the collar's foot, stepping out from the chest 142: gmotif = [curl(tc, -2.0, y(0.178), 0.0060, turns=1.0), curl(tc, 2.0, y(0.181), 0.0060, turns=1.0, flip=-1)] 143: for s in (-1, 1): 144: gmotif += [leaf(tc, s * 9, y(0.188), s * 50, 0.028, 0.0062), leaf(tc, s * 13, y(0.192), s * 68, 0.030, 0.0062)] 145: gorget, gx = outline_plate("gorget", "steel", tc, -38, 38, 146: lambda u: y(0.201) - 0.007 * (1 - (u / 38) ** 2), 147: lambda u: y(0.170) - 0.008 * max(0.0, (abs(u) - 28) / 10) ** 2, 148: offset=0.023, crown=0.003, thickness=0.003, nu=48, nv=18, roll=0.0022, 149: roll_edges=("top", "bottom"), roll_role="steel", 150: studs=[(-33, y(0.197)), (33, y(0.197))], stud_r=0.0036, decal=gmotif, decal_px=1800) 151: for pc in (front, back, gorget): 152: fit.bind(pc, allow=("Spine", "Chest", "UpperChest", "Bust"), fallback="J_Bip_C_Chest") 153: for pc in fx: 154: O.inherit(pc, front) 155: for pc in bx: 156: O.inherit(pc, back) 157: for pc in gx: 158: O.inherit(pc, gorget) 159: gorget["W"][:] = 0 160: gorget["J"][:, 0] = fit.jnames.index("J_Bip_C_UpperChest") 161: gorget["W"][:, 0] = 1.0 162: for pc in gx: 163: O.inherit(pc, gorget) 164: out += _grouped([front, back, gorget] + fx + bx + gx, "plate") 165: 166: # ---- belt: near-black leather at the natural waist, laced at the front ----------------------- 167: belt, bfront = O.belt(fit, "belt", "leather", chest, y(0.311), height=0.034, offset=0.004, thickness=0.005) 168: out += _grouped([belt], "belt") 169: lace = [] 170: ex, ey_ = np.array([1.0, 0, 0]), np.array([0, 1.0, 0]) 171: c0 = bfront + np.array([0, 0, -0.006]) 172: eye = {(sx, k): c0 + ex * sx * 0.011 + ey_ * (0.011 - 0.016 * k) for sx in (-1, 1) for k in range(3)} 173: for k in range(2): 174: for sx in (-1, 1): 175: a, b = eye[(sx, k)], eye[(-sx, k + 1)]read_file{"EndLine":260,"Path":"~/work/lowmarch/tools/gear.py","StartLine":160}
input
{ "EndLine": 260, "Path": "~/work/lowmarch/tools/gear.py", "StartLine": 160 }result, 102 lines
Showing lines 160-260 of 984 160: return cv.array() 161: 162: 163: # ---- the torso: quilted coats, mail, riveted vests ------------------------------------------------------- 164: def quilted(fit, under, name="gambeson", role="padding", y_neck=None, y_hem=None, flare=0.08, split=10.0, 165: stitch=16.0, sleeves=True, sleeve_end=0.92): 166: """A padded coat quilted in vertical channels (each channel puffs between stitched seams): a body 167: from the neck to `y_hem` (below the hips it becomes a skirt over a cone, split at the front), and 168: sleeves quilted along the arm. `under`: the Surface it sits on (the shirt).""" 169: B = fit.bone 170: nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] 171: y_neck = nk[1] - 0.03 if y_neck is None else y_neck 172: y_hem = hips[1] - 0.22 if y_hem is None else y_hem 173: cz = float(hips[2]) 174: y_waist = hips[1] + 0.06 175: tc = TorsoChart(under, y_waist - 0.04, y_neck + 0.03, cz=cz, du=3.0, dv=0.008) 176: out = [] 177: us = np.arange(-180 + stitch, 180, stitch) 178: seams = [[(u, y_waist), (u, y_neck)] for u in us] 179: 180: def neck_top(u): # lower at the front: a round neckline 181: return y_neck - 0.035 * max(0.0, 1 - abs(u) / 70) ** 1.5 182: body, _ = outline_plate(name, role, tc, -178, 178, lambda u: y_waist, neck_top, offset=0.008, thickness=0.006, 183: nu=120, nv=26, roll=0.004, roll_edges=("top",), seams=seams, groove=(0.004, 0.004), 184: panel_crown=0.006, decal_px=700) 185: fit.bind(body, allow=("Spine", "Chest", "UpperChest", "Bust", "Hips", "Neck", "Shoulder"), fallback="J_Bip_C_Chest") 186: out.append(body) 187: # the skirt: a cone from the waist down, split at the front 188: r0 = lambda u: float(tc.radius(u, y_waist)) + 0.010 189: r0m = float(np.mean([r0(u) for u in range(-180, 180, 15)])) 190: cone = ConeChart(lambda u, v: np.vectorize(r0)(u) + flare * np.clip((y_waist - v) / (y_waist - y_hem), 0, 1.2) ** 1.2, 191: cz=cz) 192: sk_seams = [[(u, y_hem), (u, y_waist)] for u in us if abs(u) > split + 4] 193: skirt, _ = outline_plate(f"{name}_skirt", role, cone, split, 360 - split, lambda u: y_hem, lambda u: y_waist + 0.012, 194: offset=0.002, thickness=0.006, nu=110, nv=18, roll=0.004, roll_edges=("bottom", "left", "right"), 195: seams=[[((u % 360), a), ((u % 360), b)] for (u, a), (_, b) in sk_seams], 196: groove=(0.004, 0.004), panel_crown=0.006, decal_px=600) 197: fit.bind(skirt, allow=("Hips", "UpperLeg"), fallback="J_Bip_C_Hips") 198: stiffen(skirt, fit, share=0.55) 199: out.append(skirt) 200: if sleeves: 201: for side in ("L", "R"): 202: for seg, (a, b, v0, v1) in enumerate(((f"J_Bip_{side}_UpperArm", f"J_Bip_{side}_LowerArm", -0.05, 1.02), 203: (f"J_Bip_{side}_LowerArm", f"J_Bip_{side}_Hand", -0.02, sleeve_end))): 204: arm = O.limb_surface(fit, (a.replace("J_Bip_", ""), b.replace("J_Bip_", "")), side) 205: lc = LimbChart(arm, B[a], B[b], front=(0, 0, -1)) 206: sl_seams = [[(u, v0), (u, v1)] for u in range(-150, 180, 30)] 207: sl, _ = outline_plate(f"{name}_sleeve_{side}{seg}", role, lc, -180, 180, lambda u, v1=v1: v1, 208: lambda u, v0=v0: v0, offset=0.010, thickness=0.005, nu=48, nv=14, roll=0, 209: seams=sl_seams, groove=(0.005, 0.003), panel_crown=0.004, decal_px=700) 210: fit.bind(sl, allow=(a.replace("J_Bip_", ""), b.replace("J_Bip_", "")), fallback=a) 211: out.append(sl) 212: return _group(out, "padding") 213: 214: 215: def mail_shirt(fit, under, name="hauberk", role="mail", y_top=None, y_hem=None, sleeve=0.55, flare=0.05): 216: """A mail shirt over the coat: body to `y_hem`, short sleeves, rings painted as a decal, the hem 217: scalloped into a ragged edge.""" 218: B = fit.bone 219: nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] 220: y_top = nk[1] - 0.05 if y_top is None else y_top 221: y_hem = hips[1] - 0.12 if y_hem is None else y_hem 222: cz = float(hips[2]) 223: y_waist = hips[1] + 0.06 224: tc = TorsoChart(under, y_waist - 0.04, y_top + 0.03, cz=cz, du=3.0, dv=0.008) 225: rings = (mail_pattern(256, 128), 0.12) # one tile of rings covers 12 cm 226: body, _ = outline_plate(name, role, tc, -178, 178, lambda u: y_waist, lambda u: y_top - 0.02 * max(0, 1 - abs(u) / 60), 227: offset=0.006, thickness=0.004, nu=96, nv=20, roll=0, pattern=rings) 228: out = [body] 229: r0 = lambda u: float(tc.radius(u, y_waist)) + 0.010 230: cone = ConeChart(lambda u, v: np.vectorize(r0)(u) + flare * np.clip((y_waist - v) / (y_waist - y_hem), 0, 1.2), cz=cz) 231: hem = lambda u: y_hem + 0.006 * abs(math.sin(math.radians(u) * 18)) # small scallops: a ragged mail edge 232: skirt, _ = outline_plate(f"{name}_skirt", role, cone, -178, 178, hem, lambda u: y_waist + 0.01, offset=0.004, 233: thickness=0.004, nu=120, nv=10, roll=0, pattern=rings) 234: out.append(skirt) 235: fit.bind(body, allow=("Spine", "Chest", "UpperChest", "Bust", "Hips", "Neck", "Shoulder"), fallback="J_Bip_C_Chest") 236: fit.bind(skirt, allow=("Hips", "UpperLeg"), fallback="J_Bip_C_Hips") 237: stiffen(skirt, fit, share=0.5) 238: for side in ("L", "R"): 239: a, b = f"J_Bip_{side}_UpperArm", f"J_Bip_{side}_LowerArm" 240: arm = O.limb_surface(fit, (f"{side}_UpperArm",), side) 241: lc = LimbChart(arm, B[a], B[b], front=(0, 0, -1)) 242: sl, _ = outline_plate(f"{name}_sleeve_{side}", role, lc, -180, 180, lambda u: sleeve, lambda u: -0.08, 243: offset=0.018, thickness=0.004, nu=40, nv=8, roll=0, pattern=rings) 244: fit.bind(sl, allow=(f"{side}_UpperArm", f"{side}_Shoulder"), fallback=a) 245: out.append(sl) 246: return _group(out, "mail") 247: 248: 249: def riveted_vest(fit, under, name="brigandine", role="leather", rivet_role="steel", y_top=None, y_bottom=None): 250: """A coat of plates: cloth-covered plates held by rows of rivets, front and back, open at the sides.""" 251: B = fit.bone 252: nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] 253: y_top = nk[1] - 0.06 if y_top is None else y_top 254: y_bottom = hips[1] + 0.02 if y_bottom is None else y_bottom 255: cz = float(hips[2]) 256: tc = TorsoChart(under, y_bottom - 0.03, y_top + 0.03, cz=cz, du=3.0, dv=0.008) 257: out = [] 258: for nm, (u0, u1) in (("front", (-70, 70)), ("back", (110, 250))): 259: rows = [[(u, y_bottom + 0.02), (u, y_top - 0.02)] for u in np.arange(u0 + 14, u1 - 6, 14)] 260: top = (lambda u: y_top - 0.05 * max(0.0, 1 - abs(u) / 40)) if nm == "front" else (lambda u: y_top)read_file{"EndLine":360,"Path":"~/work/lowmarch/tools/gear.py","StartLine":280}
input
{ "EndLine": 360, "Path": "~/work/lowmarch/tools/gear.py", "StartLine": 280 }result, 82 lines
Showing lines 280-360 of 984 280: lat -= ax * (lat @ ax) 281: lat /= np.linalg.norm(lat) 282: up = -ax 283: fw = np.cross(lat, up) 284: if shape == "heater": 285: t = np.linspace(0, 1, 13) 286: right = [(width / 2 * (1 - t_ ** 2.2), -height * 0.25 - height * 0.75 * t_) for t_ in t] 287: outline = [(-width / 2, height * 0.25), (width / 2, height * 0.25)] + right[1:] + [(-x, y) for x, y in right[::-1][1:-1]] 288: elif shape == "tower": 289: outline = [(-width / 2, height / 2), (width / 2, height / 2), (width / 2, -height / 2), (-width / 2, -height / 2)] 290: else: # kite 291: a = np.linspace(0, np.pi, 12) 292: top = [(width / 2 * math.cos(x), height * 0.22 + width / 2 * 0.6 * math.sin(x)) for x in a] 293: outline = top + [(-width / 2 * 0.9, height * 0.0), (0.0, -height * 0.78), (width / 2 * 0.9, height * 0.0)] 294: centre = E + ax * np.linalg.norm(H - E) * 0.5 + lat * 0.07 295: deco = emblem or [] 296: pc = flat_piece(name, role, outline, centre, fw, up, thickness=0.012, decal=deco, px=1200) 297: # curve round the long axis (the face bulges out) 298: P = pc["pos"] 299: x = (P - centre) @ fw 300: P += lat[None] * (-(x ** 2) / (2 * curve))[:, None] 301: pc["nrm"] = O.vertex_normals(P, pc["tri"]) 302: rim = O.pipe(f"{name}_rim", "steel", np.array([centre + fw * px_ + up * py_ + lat * (-(px_ ** 2) / (2 * curve) + 0.007) 303: for px_, py_ in outline]), r=0.006, seg=6, closed=True) 304: boss, _ = O.dome(f"{name}_boss", "steel", centre + lat * 0.007, lat, up, 0.035, 0.022, rows=6) 305: out = [pc, rim, boss] 306: _bind(fit, out, f"J_Bip_{side}_LowerArm") 307: return _group(out, "shield") 308: 309: 310: # ---- weapons (held like the sword: along the right hand's -z) ------------------------------------------------ 311: def _hand_frame(fit, hand="R"): 312: M = fit.world[f"J_Bip_{hand}_Hand"] 313: R, o = M[:3, :3], M[:3, 3] 314: R = R / np.linalg.norm(R, axis=0) 315: sx = 1 if hand == "R" else -1 316: g = getattr(fit, "grip", None) # the fist's measured hole (rig.grip_points) 317: fist = g[hand]["point"] if g else o + R @ np.array([sx * 0.045, -0.018, 0.0]) 318: fwd = R @ np.array([0, 0, -1.0]) 319: side = R @ np.array([sx * 1.0, 0, 0]) 320: return fist, fwd, side, np.cross(fwd, side), R 321: 322: 323: def spear(fit, length=2.0, grip=0.55, head=0.26, hand="R", shaft_role="wood", name="spear"): 324: """A spear held a little behind its middle: an ash shaft, a leaf blade with a socket, a butt cap.""" 325: fist, fwd, side, flat, _ = _hand_frame(fit, hand) 326: start = fist - fwd * grip 327: out = [O.tube(f"{name}_shaft", shaft_role, start, fwd, length, 0.0135)] 328: tip0 = start + fwd * length 329: out.append(O.tube(f"{name}_socket", "steel", tip0 - fwd * 0.06, fwd, 0.08, 0.016, 0.012)) 330: leaf = [(0.0, 0.0), (0.024, head * 0.30), (0.018, head * 0.65), (0.0, head), (-0.018, head * 0.65), (-0.024, head * 0.30)] 331: out.append(flat_piece(f"{name}_head", "steel", leaf, tip0 + fwd * 0.015, side, fwd, thickness=0.006)) 332: out.append(O.ball(f"{name}_butt", "steel", start - fwd * 0.01, 0.016, squash=(1, 1, 1.6))) 333: _bind(fit, out, f"J_Bip_{hand}_Hand") 334: return _group(out, "weapon") 335: 336: 337: def axe(fit, haft=0.85, blade=0.24, double=False, hand="R", shaft_role="wood", name="axe", grip=0.18): 338: """An axe: a haft with a bearded crescent blade (two for a great axe), a langet and a pommel.""" 339: fist, fwd, side, flat, _ = _hand_frame(fit, hand) 340: start = fist - fwd * grip 341: out = [O.tube(f"{name}_haft", shaft_role, start, fwd, haft, 0.016, 0.018)] 342: top = start + fwd * (haft - 0.02) 343: a = np.linspace(-1, 1, 15) 344: edge = [(blade * (0.72 + 0.28 * math.cos(x * 1.25)), blade * 0.62 * x) for x in a] 345: beard = [(blade * 0.30, -blade * 0.62), (0.03, -blade * 0.16), (0.03, blade * 0.12), (blade * 0.30, blade * 0.58)] 346: cres = [(0.02, -0.05)] + [p_ for p_ in beard[:1]] + edge + [beard[-1]] + [(0.02, 0.05)] 347: for k, sg in enumerate((1, -1) if double else (1,)): 348: pts = [(sg * x, y) for x, y in cres] 349: out.append(flat_piece(f"{name}_blade{k}", "steel", pts, top, side, fwd, thickness=0.009)) 350: out.append(O.box(f"{name}_eye", "steel", top, (side, flat, fwd), (0.026, 0.022, 0.06))) 351: out.append(O.ball(f"{name}_pommel", "steel", start, 0.022, squash=(1, 1, 0.8))) 352: _bind(fit, out, f"J_Bip_{hand}_Hand") 353: return _group(out, "weapon") 354: 355: 356: def dagger(fit, blade=0.24, hand="R", name="dagger"): 357: fist, fwd, side, flat, _ = _hand_frame(fit, hand) 358: out = [O.tube(f"{name}_grip", "leather", fist - fwd * 0.06, fwd, 0.11, 0.011)] 359: g = fist + fwd * 0.055 360: out.append(O.box(f"{name}_guard", "steel", g, (side, flat, fwd), (0.040, 0.008, 0.007)))read_file{"EndLine":700,"Path":"~/work/lowmarch/tools/gear.py","StartLine":600}
input
{ "EndLine": 700, "Path": "~/work/lowmarch/tools/gear.py", "StartLine": 600 }result, 102 lines
Showing lines 600-700 of 984 600: for pc_ in under or []: 601: Q = pc_["pos"] - c 602: loc = np.stack([Q @ outw, Q @ up, Q @ fwd], 1) 603: span = (loc[:, 1] < ext["up"]) & (loc[:, 1] > -ext["down"] * 0.95) 604: arm = (np.array([f"{side}_UpperArm" in n or f"{side}_Shoulder" in n for n in pc_["jnames"]])[pc_["J"]] 605: * pc_["W"]).sum(1) > 0.3 606: sel = span & arm 607: if not sel.any(): 608: continue 609: qs = surf_many(loc[sel]) 610: lim = np.linalg.norm(qs, axis=1) - 0.005 611: dist = np.linalg.norm(loc[sel], axis=1) 612: over = dist > lim 613: idx = np.nonzero(sel)[0][over] 614: scale = (lim[over] / np.maximum(dist[over], 1e-9))[:, None] 615: pc_["pos"][idx] = c + (pc_["pos"][idx] - c) * scale 616: pc_["nrm"] = O.vertex_normals(pc_["pos"], pc_["tri"]) 617: piping = piping or "leather" 618: m_ = measure(cg0) # again, now the sleeve is tucked in 619: if m_[0] is not None: 620: cg, r_band, band_r = m_ 621: band = np.array([cg + up * ext["down"] * 0.04 + (outw * math.cos(f) + fwd * math.sin(f)) 622: * ((band_r(math.atan2(math.sin(f), math.cos(f))) if band_r else r_band) + 0.002) 623: for f in np.linspace(0, 2 * np.pi, 33)]) 624: bd = O.pipe(f"{pc['material'][7:]}_band", piping, band, r=0.0055, seg=8, closed=True) 625: fit.bind(bd, rigid=f"J_Bip_{side}_UpperArm") # it rides the sleeve, not the puff's shoulder blend 626: bd["group"] = pc.get("group") 627: out.append(bd) 628: elif piping: 629: band = np.array([surf((math.cos(f), -0.55, math.sin(f))) for f in np.linspace(0, 2 * np.pi, 33)]) 630: out.append(O.inherit(O.pipe(f"{pc['material'][7:]}_band", piping, band, r=0.004 * k, seg=6, closed=True), pc)) 631: return _group(out, "doublet") 632: 633: 634: LIMBS = {"arm": ("UpperArm", "LowerArm", "Hand"), "leg": ("UpperLeg", "LowerLeg", "Foot")} 635: 636: 637: def _limb_frame(fit, side, Q, limb="arm"): 638: """Points Q against one limb in the reference pose: the distance along it from the top joint (upper 639: segment 0..1, lower 1..2), the unit radial direction off the bone, its radius, its angle round the 640: limb (0 outward, +90 forward, 180 toward the body or the other leg), and the upper segment's length.""" 641: B = fit.bone 642: j0, j1, j2 = (B[f"J_Bip_{side}_{n}"] for n in LIMBS[limb]) 643: L1, L2 = float(np.linalg.norm(j1 - j0)), float(np.linalg.norm(j2 - j1)) 644: d1, d2 = (j1 - j0) / L1, (j2 - j1) / L2 645: lower = (Q - j1) @ d2 > 0 646: t = np.where(lower, np.clip((Q - j1) @ d2, 0, L2), np.clip((Q - j0) @ d1, -0.3 * L1, L1)) 647: ax = np.where(lower[:, None], d2, d1) 648: foot = np.where(lower[:, None], j1 + t[:, None] * d2, j0 + t[:, None] * d1) 649: R = Q - foot 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):read_file{"EndLine":984,"Path":"~/work/lowmarch/tools/gear.py","StartLine":800}
input
{ "EndLine": 984, "Path": "~/work/lowmarch/tools/gear.py", "StartLine": 800 }result, 186 lines
Showing lines 800-984 of 984 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")