A 3D model pipeline, pushed by Fable 5.2
agent (cont.)
+38:42Bashcd ~/Projects/lowmarch-fable52 && sed -n 14,46p tools/mobs.py; sed -n 355,396p tools/outfit.py; sed -n 595,625p tools/outfit.py; sed -n 680,715p tools/outfit.py; sed -n 138,176p tools/plates.py; sed -n 517,551p tools/outfit.py
command
cd ~/Projects/lowmarch-fable52 && sed -n 14,46p tools/mobs.py; sed -n 355,396p tools/outfit.py; sed -n 595,625p tools/outfit.py; sed -n 680,715p tools/outfit.py; sed -n 138,176p tools/plates.py; sed -n 517,551p tools/outfit.py
result, 216 lines
"""Under layers every class shares: a shirt with sleeves to the wrist, trousers, boots to below the knee (or to boot_top: above the knee, they take the thigh too), gloves. Returns the pieces and the shirt (what coats are fitted over).""" B = fit.bone nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] knee = B["J_Bip_L_LowerLeg"][1] if knee is None else knee def cuff(side): a, h = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] n = (h - a) / np.linalg.norm(h - a) return n, n @ (h - n * 0.02) torso = ("Spine", "Chest", "UpperChest", "Bust", "Shoulder", "UpperArm", "LowerArm", "Neck", "Hips") # the neckline: a straight hem, lower at the throat than at the back of the neck (a level cut of # whole triangles left a saw-tooth edge, and a big trapezius showed above it) nh = np.array([0.0, 1.0, -0.3]) / np.linalg.norm([0.0, 1.0, -0.3]) neckline = (nh, float(nh @ (nk + np.array([0.0, 0.012, 0.0])))) s = O.wrap(fit, "shirt", shirt, torso, offset=0.006, exclude=("UpperLeg",), y_min=hips[1] - 0.04, y_max=nk[1] + 0.05, cut=neckline, hems=[cuff("L"), cuff("R"), neckline], subdiv=shirt_subdiv) t = O.wrap(fit, "trousers", legs, ("Hips", "UpperLeg", "LowerLeg"), offset=0.007, y_max=hips[1] + 0.02, subdiv=1) top = knee - 0.07 if boot_top is None else boot_top b = O.wrap(fit, "boots", boots, ("LowerLeg", "Foot", "ToeBase") + (("UpperLeg",) if top > knee else ()), offset=0.015, y_max=top, subdiv=1, hems=[((0, 1, 0), top - 0.005)]) g = O.wrap(fit, "gloves", gloves, ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), offset=0.003, min_w=0.3, smooth=4) out = [p for p in (s, t, b, g) if p is not None] for p, grp in zip(out, ("doublet", "trousers", "boots", "gloves")): p["group"] = grp return out, s, t, b def underwear(fit, band=False): """Plain shorts (and a chest band with band=True) for inspecting bare bodies (the armory page, built in the T-pose): hips to mid-thigh, close to the skin.""" B = fit.bone def pauldron(fit, name, role, over, side="L", lames=((0, 62, 0.012, 0.016), (55, 78, 0.010, 0.013), (72, 92, 0.008, 0.011)), spread=135, thickness=0.004, seg=30, rows=7): """Overlapping lames over the shoulder. Each lame's shape comes from ray casts out of the deltoid to the surface it covers (`over`: the tunic, plus the cape if it runs under), plus an offset that grows toward the rim. Lower lames tuck under the one above. Open on the neck side.""" sh = fit.bone[f"J_Bip_{side}_UpperArm"] el = fit.bone[f"J_Bip_{side}_LowerArm"] down = (el - sh) / np.linalg.norm(el - sh) up = -down sx = -1 if side == "L" else 1 outw = np.array([sx, 0, 0.0]) - down * (np.array([sx, 0, 0.0]) @ down) outw /= np.linalg.norm(outw) fwd = np.cross(down, outw) fwd = -fwd if fwd[2] > 0 else fwd C = sh + down * 0.015 pole = up * math.cos(math.radians(28)) + outw * math.sin(math.radians(28)) pole /= np.linalg.norm(pole) e1 = fwd - pole * (fwd @ pole) e1 /= np.linalg.norm(e1) e2 = np.cross(pole, e1) e2 = -e2 if e2 @ outw < 0 else e2 ph = np.linspace(-math.radians(spread), math.radians(spread), seg) pieces, rims = [], [] for k, (t0, t1, o0, o1) in enumerate(lames): G = np.zeros((seg, rows, 3)) for j, th in enumerate(np.radians(np.linspace(t0, t1, rows))): for i, p in enumerate(ph): d = pole * math.cos(th) + math.sin(th) * (e2 * math.cos(p) + e1 * math.sin(p)) r = over.cast(C, d, rmax=0.25, far=True) r = 0.06 if np.isnan(r) else r G[i, j] = C + d * (r + o0 + (o1 - o0) * j / (rows - 1)) pos, tri, outer = thick_grid(G, thickness, outward_from=C) pc = piece(f"{name}{k}", role, pos, tri) if k == 0: fit.bind(pc, blend={f"J_Bip_{side}_UpperArm": 0.7, f"J_Bip_{side}_Shoulder": 0.3}) else: fit.bind(pc, rigid=f"J_Bip_{side}_UpperArm") pieces.append(pc) rims.append(outer[:, -1]) return pieces, rims def limb_lames(fit, name, role, over, top, bottom, lames, arc=(-180, 180), front=(0, 0, -1), thickness=0.0035, seg=30, rows=5, rmax=0.13): """Bands of plate around a limb: each lame covers fractions (s0, s1) of the segment top->bottom and sits off `over` (ray cast out of the bone axis) by an offset that grows toward its lower rim. Lames are stacked like roof tiles: the upper one's rim sits outside the next one's top. arc: degrees around the limb that the plate covers (0 = front, + toward the character's right).""" top, bottom = np.asarray(top, float), np.asarray(bottom, float) ax = bottom - top L = np.linalg.norm(ax) ax /= L f = np.asarray(front, float) - ax * (np.asarray(front, float) @ ax) f /= np.linalg.norm(f) sd = np.cross(ax, f) ph = np.radians(np.linspace(arc[0], arc[1], seg)) out, rims = [], [] for k, (s0, s1, o0, o1) in enumerate(lames): rows = max(rows, int(L * (s1 - s0) / 0.015) + 1) # sparse rows let the limb bulge through between them G = np.zeros((seg, rows, 3)) for j, t in enumerate(np.linspace(s0, s1, rows)): o = top + ax * L * t D = np.outer(np.cos(ph), f) + np.outer(np.sin(ph), sd) r = np.array([over.cast(o, d, rmax=rmax, far=True) for d in D]) r = np.where(np.isnan(r), np.nanmedian(r) if np.isfinite(r).any() else 0.05, r) r = np.convolve(np.pad(r, 2, mode="wrap" if arc[1] - arc[0] >= 359 else "edge"), np.ones(5) / 5, "valid") G[:, j] = o + D * (r + o0 + (o1 - o0) * j / (rows - 1))[:, None] pos, tri, outer = thick_grid(G, thickness, outward_from=top, axis=ax) out.append(piece(f"{name}{k}" if len(lames) > 1 else name, role, pos, tri)) rims.append((outer[:, 0], outer[:, -1])) return out, rims def panel(fit, name, role, under, collide, y_top, centre_deg, half_width, length, seg=14, rows=22, clear=(0.006, 0.020), steps=70): """A hanging cloth panel (tabard front or back) pinned along a belt line: its top row follows `under` across `half_width` metres either side of `centre_deg` (0 = front), then it settles against `collide` (legs, tassets, greaves).""" cz = fit.bone["J_Bip_C_Hips"][2] o = np.array([0.0, y_top, cz]) r0 = under.cast(o, np.array([math.sin(math.radians(centre_deg)), 0, -math.cos(math.radians(centre_deg))]), rmax=0.3, far=True) r0 = 0.15 if np.isnan(r0) else r0 half = half_width / max(r0, 0.05) ang = math.radians(centre_deg) + np.linspace(-half, half, seg) rad = np.stack([np.sin(ang), np.zeros_like(ang), -np.cos(ang)], 1) top = [] for d in rad: r = under.cast(o, d, rmax=0.3, far=True) top.append(o + d * ((r0 if np.isnan(r) else r) + clear[0])) top = np.array(top) flat = top.copy() # a panel hangs flat, not wrapped around the body mid = top[seg // 2] out_dir = rad[seg // 2] flat -= np.outer((top - mid) @ out_dir, out_dir) * 0.6 P = np.zeros((seg, rows, 3)) for j, t in enumerate(np.linspace(0, 1, rows)): P[:, j] = flat + out_dir * 0.03 * min(1.0, t * 3) + np.array([0, -length * t, 0]) P[:, 0] = top pinned = np.zeros((seg, rows), bool) pinned[:, 0] = True P = drape(P, collide, clear[0] + (clear[1] - clear[0]) * np.linspace(0, 1, rows), pinned, steps=steps) pos, tri = grid_mesh(P) pc = piece(name, role, pos, tri, outward_from=o, axis=[0, 1, 0]) fit.bind(pc, allow=("Hips", "UpperLeg"), fallback="J_Bip_C_Hips") pc["grid"] = (seg, rows) return pc, P class LimbChart(_Chart): """u = degrees round the bone from a to b (0 = toward `front`, +90 = toward front x axis, i.e. the right-handed turn about the bone), v = fraction along it (0 at a, 1 at b; -0.2..1.2 covered).""" def __init__(self, over, a, b, front=(0, 0, -1), du=6.0, dv=0.025, smooth=(1.2, 1.2), shell=True, rmax=0.14, v_range=(-0.2, 1.2)): self.a, self.b = np.asarray(a, float), np.asarray(b, float) ax = self.b - self.a self.L = float(np.linalg.norm(ax)) self.ax = ax / self.L f = np.asarray(front, float) - self.ax * (np.asarray(front, float) @ self.ax) self.f = f / np.linalg.norm(f) self.s = np.cross(self.ax, self.f) self.wrap = True self.u0, self.du, self.v0, self.dv, self.ev = -180.0, du, v_range[0], dv, dv * 0.5 us = np.arange(-180.0, 180.0, du) vs = np.arange(v_range[0], v_range[1] + dv * 0.5, dv) R = np.full((len(us), len(vs)), np.nan) for i, u in enumerate(us): ur = math.radians(u) d = self.f * math.cos(ur) + self.s * math.sin(ur) for j, v in enumerate(vs): R[i, j] = over.cast(self.a + self.ax * self.L * v, d, rmax=rmax, far=True) self._setup(R, smooth, shell, True) def ray(self, u, v): u, v = np.broadcast_arrays(np.asarray(u, float), np.asarray(v, float)) ur = np.radians(u) d = np.cos(ur)[..., None] * self.f + np.sin(ur)[..., None] * self.s o = self.a + self.ax * (self.L * v)[..., None] return o, d def metric(self, u, v): return np.stack([np.radians(u) * self.radius(u, v), np.asarray(v, float) * self.L + 0 * np.asarray(u, float)], -1) def centre(self, v): return self.a + self.ax * self.L * v def sword(fit, hand="R", blade_len=0.80, blade_w=0.042, grip_len=0.15, hilt="gold", grip="leather"): """A one-handed sword held in the fist. In the hand's frame the fingers run along +x (right hand), the palm faces -y and the fist's hole runs front-back (z): the blade leaves the thumb side, pointing forward. Rigid on the hand bone.""" M = fit.world[f"J_Bip_{hand}_Hand"] R, o = M[:3, :3], M[:3, 3] R = R / np.linalg.norm(R, axis=0) # the hand bone may be scaled (body proportions) sx = 1 if hand == "R" else -1 fist = o + R @ np.array([sx * 0.045, -0.018, 0.0]) fwd = R @ np.array([0, 0, -1.0]) side = R @ np.array([sx * 1.0, 0, 0]) flat = np.cross(fwd, side) out = [tube("grip", grip, fist - fwd * grip_len * 0.55, fwd, grip_len, 0.0135), ball("pommel", hilt, fist - fwd * (grip_len * 0.55 + 0.012), 0.02)] guard_c = fist + fwd * (grip_len * 0.45 + 0.008) out.append(box("guard", hilt, guard_c, (side, flat, fwd), (0.095, 0.014, 0.012))) base = guard_c + fwd * 0.012 rows = 12 P = np.zeros((5, rows, 3)) for j, t in enumerate(np.linspace(0, 1, rows)): taper = 1.0 if t < 0.82 else max(0.0, (1 - t) / 0.18) w = blade_w / 2 * (1 - 0.15 * t) * taper th = 0.0045 * taper c = base + fwd * blade_len * t P[:, j] = [c + side * w, c + flat * th, c - side * w, c - flat * th, c + side * w] pos, tri = grid_mesh(P) out.append(piece("blade", "steel", pos, tri, outward_from=base + fwd * blade_len / 2, axis=fwd)) out.append(ribbon("fuller", "metal", [base + fwd * blade_len * t + flat * 0.0047 for t in np.linspace(0.04, 0.7, 10)], width=blade_w * 0.18, lift=0.0005, normals=np.tile(flat, (10, 1)))) for pc in out: fit.bind(pc, rigid=f"J_Bip_{hand}_Hand") return out # ---- plate kit (Unicorn Overlord study, docs/study.md): lames, shells, caps with fan wings ------Bashcd ~/Projects/lowmarch-fable52 && sed -n 183,270p tools/export_glb.py; sed -n 8,13p tools/mobs.py; sed -n 26,46p tools/export_glb.py
command
cd ~/Projects/lowmarch-fable52 && sed -n 183,270p tools/export_glb.py; sed -n 8,13p tools/mobs.py; sed -n 26,46p tools/export_glb.py
result, 113 lines
def scene_info(portrait, palette): """Everything the browser's pixel renderer and cloth solver need besides the meshes: palette bands per role, the lights, body colliders, cloth grids and the mouth curve (model space, turned to face +z like the GLB).""" import vroid_portrait as vp from vrm import bone_weight hexp = lambda c: palette[c] bands = lambda tbl: [[thr if thr > -5 else -9, hexp(c)] for thr, c in tbl] roles = {"face": dict(mode="bands", bands=bands(vp.SKIN_BANDS)), "body": dict(mode="bands", bands=bands(vp.SKIN_BANDS), cap=hexp("4")), "shadow": dict(mode="flat", color=hexp("3")), "hair": dict(mode="bands", bands=bands(vp.HAIR_BANDS)), "cloth": dict(mode="bands", bands=bands(vp.CLOTH_BANDS)), "line": dict(mode="flat", color=hexp("o")), "brow": dict(mode="flat", color=hexp("A")), "mouth": dict(mode="flat", color=hexp("1")), "white": dict(mode="flat", color=hexp("w")), "highlight": dict(mode="flat", color=hexp("w")), "iris": dict(mode="iris", colors=[hexp("r"), hexp("s"), hexp("t")], cuts=[0.25, 0.5])} for r, tbl in vp.MATERIALS.items(): roles[r] = dict(mode="bands", bands=bands(tbl), world=r in vp.WORLD_ROLES) names = portrait.v.nodes_by_name() W = portrait.v.node_world(portrait.pose_now) body = [p for p, r in zip(portrait.prims, portrait.roles) if r == "body"][0] caps = [] for a, b in CAPSULES: if a not in names or b not in names: continue A, B = W[names[a]][:3, 3], W[names[b]][:3, 3] wv = bone_weight(body, (a,)) pts = body["pos"][wv > 0.5] if len(pts) < 8: continue ab = B - A t = np.clip(((pts - A) @ ab) / (ab @ ab), 0, 1) d = np.linalg.norm(pts - (A + t[:, None] * ab), axis=1) caps.append(dict(a=(A * FLIP).tolist(), b=(B * FLIP).tolist(), r=float(np.percentile(d, 70) + 0.012), bones=[a, b])) cloth = {} for p in portrait.prims: if p["material"] in CLOTH and "grid" in p: trims, band, collide = CLOTH[p["material"]] cloth[p["material"]] = dict(u=int(p["grid"][0]), v=int(p["grid"][1]), trims=list(trims), band=band, collide=list(collide) if collide else None, closed=bool(p.get("closed")), edges="hem" if p["material"] in CLOTH_HEM_ONLY else "all") curve = None if getattr(portrait, "mouth_curve", None) is not None: face = [p for p, r in zip(portrait.prims, portrait.roles) if r == "face"] allp = np.concatenate([p["pos"] for p in face]) alln = np.concatenate([p["nrm"] for p in face]) from scipy.spatial import cKDTree _, i = cKDTree(allp).query(portrait.mouth_curve) curve = ((portrait.mouth_curve + alln[i] * 0.0015) * FLIP).tolist() marks = None if getattr(portrait, "marks", None): m = next(iter(portrait.marks.values())) img = Image.fromarray(np.where(m == 1, 128, 0).astype(np.uint8), "L") # nose mark only; the mouth is a line b = io.BytesIO() img.save(b, "PNG", optimize=True) import base64 marks = base64.b64encode(b.getvalue()).decode() # painted renderer: a material kind and one base colour per role; the shader builds the ramp pc = dict(signature="#7d1e2c", doublet="#2a2d3d", heraldry="#dfe2e8", leather="#5f3e2b", boot="#4a3326", glove="#5f3e2b", steel="#a6adbb", gold="#b08b3f", hair=hexp("C"), trim="#b08b3f") pc.update(getattr(portrait, "paint", None) or {}) skin = dict(kind="skin", base=pc.get("skin") or "#f8e1d5") # light skin unless a tone is set skin["ramp"] = skin_ramp(skin["base"]) # its lit, shade and deep shade paint = {"face": dict(skin), "body": dict(skin), "shadow": dict(skin, shade=True), # shadow cards: skin in shade "hair": dict(kind="hair", base=pc["hair"]), "coat": dict(kind="cloth", base=pc["signature"]), "cape": dict(kind="cloth", base=pc["signature"]), "signature": dict(kind="cloth", base=pc["signature"]), "doublet": dict(kind="cloth", base=pc["doublet"]), "cloth": dict(kind="cloth", base=pc["doublet"]), "heraldry": dict(kind="cloth", base=pc["heraldry"]), "leather": dict(kind="leather", base=pc["leather"]), "boot": dict(kind="leather", base=pc["boot"]), "glove": dict(kind="leather", base=pc["glove"]), "metal": dict(kind="steel", base=pc["steel"]), "steel": dict(kind="steel", base=pc["steel"]), "gold": dict(kind="gold", base=pc["gold"]), "grass": dict(kind="world", base="#5a7a3a"), "dirt": dict(kind="world", base="#6a4a32"), "stone": dict(kind="world", base="#7c7a86"), "motif": dict(kind="cloth", base=pc.get("motif", "#3a44a0"))} # decal paint on steel (tools/plates.py) for role, val in pc.items(): # extra roles a cast entry names (cloth unless it says) if role not in paint and isinstance(val, str) and val.startswith("#"): paint[role] = dict(kind="cloth", base=val) elif role not in paint and isinstance(val, dict) and "base" in val: paint[role] = dict(kind=val.get("kind", "cloth"), base=val["base"]) for role, g in (pc.get("grain") or {}).items(): # optional per-role brush grain (big flat cloth mottles) if role in paint: paint[role]["grain"] = g return dict(roles=roles, light=vp.LIGHT.tolist(), sun=vp.SUN.tolist(), capsules=caps, cloth=cloth, face_marks=marks, paint=paint, mouth_curve=curve, mouth_bone="J_Bip_C_Head", ink=dict(o=hexp("o"), skin=hexp("1"), hair=hexp("A")), skin=[hexp(c) for c in "12345"], depth_gap=0.012) import gear as G from fitting import Surface, merge_surfaces from vrm import bone_weight def _base(fit, shirt="padding", legs="cloth", boots="boot", gloves="glove", knee=None, shirt_subdiv=0, boot_top=None): def group_of(p, role): if p.get("world"): return "terrain" if p.get("group"): return p["group"] if role in ("face", "body", "shadow", "iris", "white", "highlight", "line", "brow", "mouth"): return "body" if role == "hair": return "hair" name = p["material"].replace("OUTFIT_", "") for key in ("trim", "edge", "hem", "placket", "buckle", "clasp"): if key in name: return "trim" for key in ("pauldron", "cape", "collar", "tunic", "tails", "belt", "trousers", "boots", "gloves"): if name.startswith(key): return key if name in ("blade", "guard", "grip", "pommel", "fuller"): return "sword" return "costume"Bashcd ~/Projects/lowmarch-fable52 && grep -n "^CLOTH\|^CLOTH_HEM_ONLY\|^CAPSULES" -A12 tools/export_glb.py | head -50; grep -n "MATERIALS = \|WORLD_ROLES" -A3 tools/vroid_portrait.py | head -30; sed -n 474,516p tools/outfit.py
command
cd ~/Projects/lowmarch-fable52 && grep -n "^CLOTH\|^CLOTH_HEM_ONLY\|^CAPSULES" -A12 tools/export_glb.py | head -50; grep -n "MATERIALS = \|WORLD_ROLES" -A3 tools/vroid_portrait.py | head -30; sed -n 474,516p tools/outfit.py
result, 88 lines
165:CAPSULES = [("J_Bip_C_Hips", "J_Bip_C_Spine"), ("J_Bip_C_Spine", "J_Bip_C_Chest"), 166- ("J_Bip_C_Chest", "J_Bip_C_UpperChest"), ("J_Bip_C_UpperChest", "J_Bip_C_Neck"), 167- ("J_Bip_C_Neck", "J_Bip_C_Head")] + \ 168- [(f"J_Bip_{s}_{a}", f"J_Bip_{s}_{b}") for s in "LR" for a, b in 169- (("UpperArm", "LowerArm"), ("LowerArm", "Hand"), ("UpperLeg", "LowerLeg"), ("LowerLeg", "Foot"))] 170-# simulated cloth: piece -> (its static trims, hidden while the cloth simulates; the role whose colour 171-# the simulated border band takes; the bones whose colliders it meets, None for all). Panels hanging 172-# from the belt meet the legs only: the hip collider's round end pushes them out behind. 173-LEGS = ("UpperLeg", "LowerLeg") 174:CLOTH = {"OUTFIT_cape": (("OUTFIT_cape_trim", "OUTFIT_cape_hem", "OUTFIT_cape_edge0", "OUTFIT_cape_edge1"), "gold", None), 175- "OUTFIT_tails": (("OUTFIT_tails_hem",), "gold", LEGS), 176- "OUTFIT_tabard": (("OUTFIT_tabard_hem", "OUTFIT_tabard_edge0", "OUTFIT_tabard_edge1"), "heraldry", LEGS), 177- "OUTFIT_tabard_back": (("OUTFIT_tabard_back_hem", "OUTFIT_tabard_back_edge0", "OUTFIT_tabard_back_edge1"), 178- "heraldry", LEGS), 179- "OUTFIT_skirt": (("OUTFIT_skirt_hem",), "heraldry", LEGS)} 180:CLOTH_HEM_ONLY = {"OUTFIT_skirt"} # border band on the hem row only (its waist has a gold trim) 181- 182- 183-def scene_info(portrait, palette): 184- """Everything the browser's pixel renderer and cloth solver need besides the meshes: palette 185- bands per role, the lights, body colliders, cloth grids and the mouth curve (model space, 186- turned to face +z like the GLB).""" 187- import vroid_portrait as vp 188- from vrm import bone_weight 189- hexp = lambda c: palette[c] 190- bands = lambda tbl: [[thr if thr > -5 else -9, hexp(c)] for thr, c in tbl] 191- roles = {"face": dict(mode="bands", bands=bands(vp.SKIN_BANDS)), 192- "body": dict(mode="bands", bands=bands(vp.SKIN_BANDS), cap=hexp("4")), 59:MATERIALS = {"coat": CLOTH_BANDS, 60- "signature": CLOTH_BANDS, # the character's one colour (tabard, mantle, shield) 61- "doublet": [(0.85, "T"), (0.6, "S"), (0.35, "R"), (-9, "Q")], 62- "heraldry": [(0.85, "O"), (0.6, "N"), (0.35, "J"), (-9, "F")], -- 73:WORLD_ROLES = ("grass", "dirt", "stone") 74-DARKER = {c: tbl[min(i + 1, len(tbl) - 1)][1] for tbl in MATERIALS.values() for i, (_, c) in enumerate(tbl)} 75-FLIP = np.array([-1.0, 1.0, -1.0]) # VRoid faces -z; we want the face toward +z (the viewer) 76- -- 1256: world = np.isin(rol, WORLD_ROLES) 1257- for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): 1258- def nb(a, fill): 1259- o = np.full_like(a, fill) -- 1274: rule[world & np.isin(r1, WORLD_ROLES) & (r1 != rol)] = "o" 1275- rule[skin & skin1] = "1" 1276- rule[hair0 & skin1] = "o" 1277- rule[hair0 & hair1 & (p1 != prim)] = "A" def tails(fit, name, role, under, y_top, length=0.36, front_gap=60, seg=40, rows=12, clear=(0.012, 0.030)): """Tunic tails from under the belt, open at the front, settled against the legs.""" ang = np.radians(np.linspace(-(180 - front_gap / 2), 180 - front_gap / 2, seg)) cz = fit.bone["J_Bip_C_Hips"][2] rad = np.stack([np.sin(ang), np.zeros_like(ang), np.cos(ang)], 1) top = [] for d in rad: o = np.array([0.0, y_top, cz]) r = under.cast(o, d, rmax=0.25, far=True) top.append(o + d * ((0.14 if np.isnan(r) else r) + clear[0])) top = np.array(top) P = np.zeros((seg, rows, 3)) for j, t in enumerate(np.linspace(0, 1, rows)): P[:, j] = top + rad * (0.01 * t) + np.array([0, -length * t, 0]) pinned = np.zeros((seg, rows), bool) pinned[:, 0] = True P = drape(P, under, clear[0] + (clear[1] - clear[0]) * np.linspace(0, 1, rows), pinned, steps=60) pos, tri = grid_mesh(P) pc = piece(name, role, pos, tri, outward_from=[0, y_top, cz], axis=[0, 1, 0]) fit.bind(pc, allow=("Hips", "UpperLeg"), fallback="J_Bip_C_Hips") pc["grid"] = (seg, rows) return pc, P def belt(fit, name, role, over, y, height=0.034, offset=0.006, thickness=0.005, seg=56, tilt=0.0): """A band around the waist cast onto `over`. tilt: metres higher on the character's right hip than the left (a slung second belt).""" cz = fit.bone["J_Bip_C_Hips"][2] ang = np.linspace(-math.pi, math.pi, seg) P = np.zeros((seg, 2, 3)) for i, a in enumerate(ang): d = np.array([math.sin(a), 0, math.cos(a)]) for j, dy in enumerate((height / 2, -height / 2)): o = np.array([0.0, y + dy + tilt * math.sin(a), cz]) r = over.cast(o, d, rmax=0.4, far=True) P[i, j] = o + d * ((0.15 if np.isnan(r) else r) + offset) pos, tri, outer = thick_grid(P, thickness, outward_from=[0, y, cz], axis=[0, 1, 0]) pc = fit.bind(piece(name, role, pos, tri), rigid="J_Bip_C_Hips") front = outer[np.argmin(np.abs(np.abs(ang) - math.pi))].mean(0) pc["group"] = "belt" return pc, frontBashcd ~/Projects/lowmarch-fable52 && sed -n 1121,1266p tools/outfit.py
command
cd ~/Projects/lowmarch-fable52 && sed -n 1121,1266p tools/outfit.py
result, 144 lines
B = fit.bone nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] knee = B["J_Bip_L_LowerLeg"][1] out = [] def cuff_plane(side): # sleeves end under the gauntlet cuff a, h = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] n = (h - a) / np.linalg.norm(h - a) return n, n @ (h - n * 0.035) def grouped(pcs, g): for pc in pcs: if pc is not None: pc["group"] = g return [pc for pc in pcs if pc is not None] def rolled(name, pc, rims, r=0.0028): """A rolled steel edge along each rim: what defines plate in the study instead of gold.""" return [inherit(pipe(f"{name}_roll{k}", "metal", rim, r=r), pc) for k, rim in enumerate(rims)] # 1-2: the doublet and what's under it torso = ("Spine", "Chest", "UpperChest", "Shoulder", "UpperArm", "LowerArm", "Neck", "Hips") doublet = wrap(fit, "doublet", "doublet", torso, offset=0.008, exclude=("UpperLeg",), y_min=hips[1] - 0.03, y_max=nk[1] + 0.012, hems=[cuff_plane("L"), cuff_plane("R")]) trousers = wrap(fit, "trousers", "leather", ("Hips", "UpperLeg", "LowerLeg"), offset=0.008, y_max=hips[1] + 0.02, subdiv=1) boots = wrap(fit, "boots", "boot", ("LowerLeg", "Foot", "ToeBase"), offset=0.017, y_max=knee - 0.07, subdiv=1, hems=[((0, 1, 0), knee - 0.075)]) gloves = wrap(fit, "gloves", "glove", ("Hand", "Thumb", "Index", "Middle", "Ring", "Little"), offset=0.0028, min_w=0.3, smooth=4) # down over the wrist: no gap under the cuff out += grouped([doublet], "doublet") + [p for p in (trousers, boots, gloves) if p is not None] col, _, _ = collar(fit, "collar", "doublet", height_back=0.030, height_front=0.018) out += grouped([col], "doublet") body_d = merge_surfaces((doublet["pos"], doublet["tri"]), (fit.pos, fit.tri)) # 4: plate cuirass = wrap(fit, "breastplate", "steel", ("Spine", "Chest", "UpperChest", "Hips"), offset=0.014, exclude=("Shoulder", "UpperArm", "Neck", "UpperLeg"), y_min=hips[1] + 0.030, y_max=nk[1] - 0.040, base=Surface(doublet["pos"], doublet["tri"]), smooth=40, hems=[((0, 1, 0), hips[1] + 0.040), ((0, 1, 0), nk[1] - 0.050)]) keel = np.clip(1 - np.abs(cuirass["pos"][:, 0]) / 0.07, 0, 1) * (cuirass["pos"][:, 2] < B["J_Bip_C_Chest"][2]) cuirass["pos"] = cuirass["pos"] + cuirass["nrm"] * (0.007 * keel ** 2)[:, None] # a soft central ridge cuirass["nrm"] = vertex_normals(cuirass["pos"], cuirass["tri"]) loops = [cuirass["pos"][L] for L in cuirass["loops"] if len(L) > 12] out += grouped([cuirass] + [inherit(pipe(f"breastplate_roll{k}", "metal", Lp, r=0.0034, closed=True), cuirass) for k, Lp in enumerate(loops)], "plate") plate_body = merge_surfaces((cuirass["pos"], cuirass["tri"]), (doublet["pos"], doublet["tri"]), (fit.pos, fit.tri)) for side in ("L", "R"): sx = -1 if side == "L" else 1 ul, ll, ft = B[f"J_Bip_{side}_UpperLeg"], B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"] ua, la, hd = B[f"J_Bip_{side}_UpperArm"], B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] # tassets: three lames on the front and outside of each thigh, hung from the waist thigh = side_of(trousers, side) arc = (-125, 20) if side == "L" else (-20, 125) # tops tuck under the belt (small offset there), lower rims flare out tas, rims = limb_lames(fit, f"tasset_{side}", "steel", thigh, ul + [0, 0.085, 0], ul + (ll - ul) * 0.46, ((0.0, 0.40, 0.006, 0.026), (0.33, 0.70, 0.018, 0.026), (0.63, 1.0, 0.016, 0.024)), arc=arc, rmax=0.16) for k, pc in enumerate(tas): fit.bind(pc, blend={"J_Bip_C_Hips": 0.55 - 0.2 * k, f"J_Bip_{side}_UpperLeg": 0.45 + 0.2 * k}) out += grouped(tas, "plate") + grouped(sum((rolled(f"tasset_{side}{k}", pc, [r[1]]) for k, (pc, r) in enumerate(zip(tas, rims))), []), "plate") # greaves over the boots, poleyns with wings at the knee shin = side_of(boots, side) gv, rims = limb_lames(fit, f"greave_{side}", "steel", shin, ll, ft, ((0.12, 0.80, 0.008, 0.011),), rmax=0.11) fit.bind(gv[0], rigid=f"J_Bip_{side}_LowerLeg") out += grouped(gv + rolled(f"greave_{side}", gv[0], rims[0]), "plate") leg = merge_surfaces((trousers["pos"], trousers["tri"]), (boots["pos"], boots["tri"])) jg, jr = joint_guard(fit, f"poleyn_{side}", f"J_Bip_{side}_LowerLeg", f"J_Bip_{side}_Foot", (0, 0, -1), side, side_of(trousers, side), r=0.036, wing=0.060) for pc in jg: fit.bind(pc, rigid=f"J_Bip_{side}_LowerLeg") out += grouped(jg + sum((rolled(f"poleyn_{side}{k}", pc, [rim]) for k, (pc, rim) in enumerate(zip(jg, jr))), []), "plate") # vambraces and couters with wings fore = limb_surface(fit, (f"{side}_LowerArm",), side) vb, rims = limb_lames(fit, f"vambrace_{side}", "steel", fore, la, hd, ((0.12, 0.64, 0.017, 0.020),), rmax=0.11) fit.bind(vb[0], rigid=f"J_Bip_{side}_LowerArm") out += grouped(vb + rolled(f"vambrace_{side}", vb[0], rims[0]), "plate") # leather gauntlet cuff over the lower forearm, belled toward the elbow, snug at the wrist gc, _ = limb_lames(fit, f"gauntlet_{side}", "glove", fore, la, hd, ((0.50, 1.05, 0.030, 0.010),), rmax=0.11, thickness=0.004) fit.bind(gc[0], rigid=f"J_Bip_{side}_LowerArm") out += grouped(gc, "gloves") arm = limb_surface(fit, (f"{side}_LowerArm", f"{side}_UpperArm"), side) jg, jr = joint_guard(fit, f"couter_{side}", f"J_Bip_{side}_LowerArm", f"J_Bip_{side}_Hand", (0, 0, 1), side, arm, r=0.030, wing=0.056, depth=0.022) for pc in jg: fit.bind(pc, rigid=f"J_Bip_{side}_LowerArm") out += grouped(jg + sum((rolled(f"couter_{side}{k}", pc, [rim]) for k, (pc, rim) in enumerate(zip(jg, jr))), []), "plate") del leg, arm, ua, sx # 5: one wide belt over the breastplate's lower edge and the tasset tops, square steel buckle. It is # cast onto the plate and trousers only: cast onto the tassets it ballooned out over their rims, and # with the body skin in the set it wrapped around the hanging forearms and stuck out once they moved. waist = merge_surfaces((cuirass["pos"], cuirass["tri"]), (trousers["pos"], trousers["tri"])) b1, front1 = belt(fit, "belt", "leather", waist, hips[1] + 0.052, height=0.040, offset=0.005) out += [b1] fx, fy, fz = np.eye(3) for k, (dx, dy, hx, hy) in enumerate(((0, 0.013, 0.019, 0.0028), (0, -0.013, 0.019, 0.0028), (0.016, 0, 0.0028, 0.016), (-0.016, 0, 0.0028, 0.016))): bx = box(f"buckle{k}", "metal", front1 + [dx, dy, -0.005], (fx, fy, fz), (hx, hy, 0.003)) out += grouped([fit.bind(bx, rigid="J_Bip_C_Hips")], "belt") out += grouped([fit.bind(box("buckle_tongue", "metal", front1 + [0, 0, -0.006], (fx, fy, fz), (0.0018, 0.012, 0.002)), rigid="J_Bip_C_Hips")], "belt") # 6: tabard front (to the ankle) and back (to the knee), cloth, cream border plates = [p for p in out if p.get("group") == "plate" and "roll" not in p["material"]] legs = merge_surfaces((trousers["pos"], trousers["tri"]), (boots["pos"], boots["tri"]), *[(p["pos"], p["tri"]) for p in plates if "breastplate" not in p["material"]]) under = merge_surfaces((b1["pos"], b1["tri"]), (cuirass["pos"], cuirass["tri"]), (trousers["pos"], trousers["tri"])) ytop = hips[1] + 0.040 for nm, deg, hw, length in (("tabard", 0, 0.105, ytop - 0.17), ("tabard_back", 180, 0.12, ytop - knee + 0.02)): tb, grid = panel(fit, nm, "signature", under, legs, ytop, deg, hw, length) tb["group"] = "tabard" out.append(tb) for tn, line, w in ((f"{nm}_hem", grid[:, -1], 0.016), (f"{nm}_edge0", grid[0], 0.012), (f"{nm}_edge1", grid[-1], 0.012)): out += grouped([inherit(ribbon(tn, "heraldry", line, width=w, lift=0.0015, normals=near_normals(tb, line)), tb)], "tabard") # spaulders over doublet and breastplate (before the mantle, which lies over them) for side in ("L", "R"): sp, rims = pauldron(fit, f"spaulder_{side}", "steel", plate_body, side=side, lames=((0, 56, 0.026, 0.034), (47, 73, 0.024, 0.032), (65, 91, 0.022, 0.030), (83, 108, 0.020, 0.028)), spread=108) out += grouped(sp, "plate") + grouped(sum((rolled(f"spaulder_{side}{k}", pc, [rim]) for k, (pc, rim) in enumerate(zip(sp, rims))), []), "plate") # 7: the hooded mantle over all of it rolls = [p for p in out if p["material"].startswith("OUTFIT_breastplate_roll")] shoulders = merge_surfaces((cuirass["pos"], cuirass["tri"]), *[(p["pos"], p["tri"]) for p in rolls], (doublet["pos"], doublet["tri"]), (col["pos"], col["tri"]), (fit.pos, fit.tri)) mt, mgrid, hood = mantle(fit, "mantle", "signature", shoulders) out += grouped([mt, hood], "mantle") for k, edge in enumerate((mgrid[0], mgrid[-1])): out += grouped([fit.bind(ball(f"mantle_clasp{k}", "gold", edge[0] + (edge[0] - nk) * 0.03, 0.011, squash=(1, 1, 0.55)), rigid="J_Bip_C_UpperChest")], "mantle") out += shield(fit, "shield", "L") out += sword(fit, "R", hilt="metal") return [p for p in out if p is not None]Write~/Projects/lowmarch-fable52/tools/whole/wren.py
input
~/Projects/lowmarch-fable52/tools/whole/wren.py """Wren: a border knight, designed for the side-view battle frame (tools/whole/build.py, WHOLE_DESIGN=wren). The design, big shapes first: - one large pauldron on the lead (left) shoulder and a small spaulder on the right: an uneven outline that tells her front from her back at game size; - a rigid, keeled cuirass with a pointed waist and a plackart, a gold line round it and three teal feathers painted on the right breast (her mark); - a teal surcoat split into a short front panel and a long back tail, cream hems, over dark hose and tall boots, so a lunge shows legs instead of opening a skirt; - a cream stand collar under the face, to set the head off the armour; - steel on the forearms, knees and shins, tassets on the thighs, a scabbard on the left hip; - a longsword with a grip for two hands. The fringe is cut above the eyes (haircut): at game size the eyes are the face. Everything is built from the kit (tools/outfit.py, gear.py, plates.py, mobs.py); nothing here is fitted to one body by hand, so it should dress the other armory women too (not tried). """ import math import numpy as np import gear as G import mobs import outfit as O from fitting import Surface, merge_surfaces from plates import TorsoChart, outline_plate # her colours: one cloth hue, cream, warm steel, a little gold PAINT = dict(signature="#1d5b5e", doublet="#23262e", heraldry="#efe6d2", leather="#6a4630", boot="#4b3426", glove="#5a3d2b", steel="#c6c9cf", gold="#c29a4a", motif="#1d5b5e", skin="#f4d3bd", grain=dict(signature=0.015)) # proportion and face changes on the armory body (vroid_portrait NEUTRAL keys); set from the frame, not from rules SHAPE = dict(rest={"Fcl_BRW_Angry": 0.3}) def _grouped(pcs, g): for pc in pcs: if pc is not None: pc["group"] = g return [pc for pc in pcs if pc is not None] def haircut(fit, knee=1.0, over_eye=0.058, centre=0.094, outer=0.080, eye_x=None): """Cut the fringe above the eyes. The sample's fringe ends at the middle of the eye, so at game size the face reads as a pale shape with no eyes. Each fringe vertex keeps its root and is drawn up toward it: a depth d below the fringe's root line becomes D (1 - exp(-d / D)), which never passes D. D is smallest over each eye, larger between them (a centre lock) and at the temples, and the side locks beyond the temples are left alone. Sizes are in head-heights of this face (eye line to chin = `span`), so another face gets the same cut.""" lm = _landmarks(fit) span, eye_y = lm["span"], lm["eye_y"] ex = abs(lm["eyeR"][0]) if eye_x is None else eye_x z_face = lm["eyeL"][2] y_root = eye_y + knee * span # above this the hair is untouched for p, r in zip(fit._prims, fit._roles): if r != "hair": continue P = p["pos"] ax = np.abs(P[:, 0]) # how deep the fringe may hang at this x: shortest over the eye, a lock between the eyes, longer at the temple D = span * (over_eye + (centre - over_eye) * np.exp(-(ax / (0.30 * ex)) ** 2) + (outer - over_eye) * np.clip((ax - ex) / (0.7 * ex), 0, 1) ** 2) d = np.maximum(y_root - P[:, 1], 0.0) cut = y_root - D * (1 - np.exp(-d / D)) wx = 1 - np.clip((ax - 1.55 * ex) / (0.35 * ex), 0, 1) # fades out before the side locks wz = np.clip((z_face + 0.035 - P[:, 2]) / 0.02, 0, 1) # only hair in front of the face w = (wx * wx * (3 - 2 * wx)) * (wz * wz * (3 - 2 * wz)) P[:, 1] = P[:, 1] + (cut - P[:, 1]) * w p["nrm"] = O.vertex_normals(P, p["tri"]) if p.get("nrm") is None else p["nrm"] def _landmarks(fit): import vroid_portrait as vp return vp.landmarks(fit._prims, fit._roles) def _feather(chart, u0, v0, ang, length, width, ch="paint"): """A feather blade from (u0, v0) at `ang` degrees from straight up (+ toward +u), sizes in metres.""" a = math.radians(ang) al, ac = np.array([math.sin(a), math.cos(a)]), np.array([math.cos(a), -math.sin(a)]) t = np.linspace(0, 1, 16) w = width / 2 * np.sqrt(t + 0.05) * (1 - t) ** 0.7 * 1.7 pts = [tuple(al * length * ti + ac * wi) for ti, wi in zip(t, w)] + \ [tuple(al * length * ti - ac * wi * 0.45) for ti, wi in zip(t[::-1], w[::-1])] r = float(chart.radius(u0, v0)) return ("poly", [(u0 + math.degrees(dx / r), v0 + dy) for dx, dy in pts], ch) def longsword(fit, hand="R", blade_len=0.93, blade_w=0.046, grip_len=0.25, guard=0.105): """A longsword: the right fist sits just under the guard and the grip runs on behind it for the left hand (the fists 10 cm apart, tools/whole/clips2h.py). Frame as outfit.sword: the blade leaves the thumb side along the hand's -z. Rigid on the hand.""" M = fit.world[f"J_Bip_{hand}_Hand"] R, o = M[:3, :3], M[:3, 3] R = R / np.linalg.norm(R, axis=0) sx = 1 if hand == "R" else -1 fist = o + R @ np.array([sx * 0.045, -0.018, 0.0]) fwd = R @ np.array([0, 0, -1.0]) side = R @ np.array([sx * 1.0, 0, 0]) flat = np.cross(fwd, side) ahead = 0.052 # grip in front of the fist's middle, up to the guard out = [O.tube("grip", "leather", fist - fwd * (grip_len - ahead), fwd, grip_len, 0.0125, 0.0140), O.ball("pommel", "gold", fist - fwd * (grip_len - ahead + 0.014), 0.021, squash=(1, 1, 0.8))] guard_c = fist + fwd * (ahead + 0.008) out.append(O.box("guard", "gold", guard_c, (side, flat, fwd), (guard, 0.012, 0.010))) for s in (-1, 1): # the guard's ends turn toward the blade out.append(O.ball(f"guard_tip{(s + 1) // 2}", "gold", guard_c + side * s * guard + fwd * 0.006, 0.014, squash=(0.8, 0.8, 1.2))) base = guard_c + fwd * 0.010 rows = 14 P = np.zeros((5, rows, 3)) for j, t in enumerate(np.linspace(0, 1, rows)): taper = 1.0 if t < 0.84 else max(0.0, (1 - t) / 0.16) w = blade_w / 2 * (1 - 0.22 * t) * taper th = 0.0048 * (1 - 0.3 * t) * taper c = base + fwd * blade_len * t P[:, j] = [c + side * w, c + flat * th, c - side * w, c - flat * th, c + side * w] pos, tri = O.grid_mesh(P) out.append(O.piece("blade", "steel", pos, tri, outward_from=base + fwd * blade_len / 2, axis=fwd)) out.append(O.ribbon("fuller", "metal", [base + fwd * blade_len * t + flat * 0.0050 for t in np.linspace(0.03, 0.62, 10)], width=blade_w * 0.16, lift=0.0005, normals=np.tile(flat, (10, 1)))) for pc in out: fit.bind(pc, rigid=f"J_Bip_{hand}_Hand") return out def build(fit): B = fit.bone nk, hips = B["J_Bip_C_Neck"], B["J_Bip_C_Hips"] knee = float(B["J_Bip_L_LowerLeg"][1]) cz = float(hips[2]) haircut(fit) def rolled(name, pc, rims, r=0.0026, role="metal"): return [O.inherit(O.pipe(f"{name}_roll{k}", role, rim, r=r), pc) for k, rim in enumerate(rims)] # ---- under layers: the surcoat's body and sleeves, dark hose, tall boots, leather gloves ------------------- boot_top = knee - 0.045 out, shirt, hose, boots = mobs._base(fit, shirt="signature", legs="doublet", boots="boot", gloves="glove", shirt_subdiv=1, boot_top=boot_top) G.loose_sleeves(fit, shirt, ease=0.022, cuff=0.60) G.flare_boots(fit, boots, boot_top - 0.005, ease=0.009) under = mobs._under(shirt) col, rim, _ = O.collar(fit, "collar", "heraldry", height_back=0.040, height_front=0.026, gap_deg=34) out += _grouped([col, O.inherit(O.pipe("collar_trim", "gold", rim, r=0.0020), col)], "doublet") # ---- cuirass: one rigid keeled shell, pointed at the waist, a gold line round it, her feathers --------------- y_top, y_bot = float(nk[1]) - 0.062, float(hips[1]) + 0.082 span = y_top - y_bot tc = TorsoChart(under, y_bot - 0.07, y_top + 0.05, cz=cz, du=2.5, dv=0.007, smooth=(2.2, 1.8)) arm = 60.0 top = lambda u: y_top - 0.034 * max(0.0, 1 - abs(u) / 32) ** 1.4 - 0.12 * span * max(0.0, (abs(u) - arm) / 40) ** 1.3 bottom = lambda u: y_bot - 0.034 * max(0.0, 1 - abs(u) / 34) ** 1.4 ridge = lambda u, v, s, t: 0.010 * math.exp(-(u / 8.0) ** 2) * math.sin(math.pi * min(1.0, t * 1.15)) yf = y_bot + 0.56 * span # the feathers' root, on her right breast motif = [_feather(tc, 30, yf, a, L, w) for a, L, w in ((-64, 0.085, 0.026), (-38, 0.072, 0.024), (-12, 0.056, 0.021))] front, fx = outline_plate("cuirass", "steel", tc, -98, 98, bottom, top, offset=0.015, crown=0.011, flare=ridge, thickness=0.004, nu=84, nv=30, trim=0.0045, roll=0.0030, roll_edges=("top", "bottom"), roll_role="gold", decal=motif, decal_px=1400) btop = lambda u: y_top - 0.012 - 0.12 * span * max(0.0, (abs(((u % 360) - 180)) - (arm - 4)) / 44) ** 1.3 back, bx = outline_plate("cuirass_back", "steel", tc, 98, 262, lambda u: y_bot, btop, offset=0.015, crown=0.007, thickness=0.004, nu=60, nv=22, roll=0.0030, roll_edges=("top", "bottom")) ptop = lambda u: y_bot + 0.34 * span - 0.12 * span * (abs(u) / 52) ** 1.7 plack, px = outline_plate("cuirass_plackart", "steel", tc, -52, 52, bottom, ptop, offset=0.021, crown=0.008, flare=ridge, thickness=0.004, nu=44, nv=12, roll=0.0030, roll_edges=("top",), rivets=(0.045, 0.010, 0.0032), rivet_role="gold") for pc, ex, allow, fb in ((front, fx, ("Spine", "Chest", "UpperChest", "Bust", "Hips"), "J_Bip_C_Chest"), (back, bx, ("Spine", "Chest", "UpperChest", "Bust", "Hips"), "J_Bip_C_Chest"), (plack, px, ("Spine", "Chest", "Hips"), "J_Bip_C_Spine")): fit.bind(pc, allow=allow, fallback=fb) out += _grouped([pc] + [O.inherit(p, pc) for p in ex], "plate") plate = merge_surfaces(*[(p["pos"], p["tri"]) for p in (front, back, plack)]) plate_body = merge_surfaces((front["pos"], front["tri"]), (back["pos"], back["tri"]), (shirt["pos"], shirt["tri"]), (fit.pos, fit.tri)) # ---- limbs: tassets, poleyns and greaves; vambraces and couters ------------------------------------------- for side in ("L", "R"): ul, ll, ft = B[f"J_Bip_{side}_UpperLeg"], B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"] la, hd = B[f"J_Bip_{side}_LowerArm"], B[f"J_Bip_{side}_Hand"] thigh = O.side_of(hose, side) arc = (-135, 12) if side == "L" else (-12, 135) tas, rims = O.limb_lames(fit, f"tasset_{side}", "steel", thigh, ul + [0, 0.080, 0], ul + (ll - ul) * 0.50, ((0.0, 0.42, 0.007, 0.024), (0.35, 0.72, 0.017, 0.025), (0.65, 1.0, 0.016, 0.026)), arc=arc, rmax=0.16) for k, pc in enumerate(tas): fit.bind(pc, blend={"J_Bip_C_Hips": 0.55 - 0.2 * k, f"J_Bip_{side}_UpperLeg": 0.45 + 0.2 * k}) out += _grouped(tas, "plate") + _grouped(sum((rolled(f"tasset_{side}{k}", pc, [r[1]], role="gold" if k == 2 else "metal") for k, (pc, r) in enumerate(zip(tas, rims))), []), "plate") shin = O.side_of(boots, side) gv, rims = O.limb_lames(fit, f"greave_{side}", "steel", shin, ll, ft, ((0.10, 0.78, 0.008, 0.011),), arc=(-115, 115), rmax=0.11) fit.bind(gv[0], rigid=f"J_Bip_{side}_LowerLeg") out += _grouped(gv + rolled(f"greave_{side}", gv[0], rims[0]), "plate") legs_side = merge_surfaces((thigh[0], thigh[1]), (shin[0], shin[1])) jg, jr = O.joint_guard(fit, f"poleyn_{side}", f"J_Bip_{side}_LowerLeg", f"J_Bip_{side}_Foot", (0, 0, -1), side, legs_side, r=0.040, wing=0.058) for pc in jg: fit.bind(pc, rigid=f"J_Bip_{side}_LowerLeg") out += _grouped(jg + sum((rolled(f"poleyn_{side}{k}", pc, [rm]) for k, (pc, rm) in enumerate(zip(jg, jr))), []), "plate") fore = O.limb_surface(fit, (f"{side}_LowerArm",), side) sleeve = O.side_of(shirt, side) vb, rims = O.limb_lames(fit, f"vambrace_{side}", "steel", merge_surfaces(fore, sleeve), la, hd, ((0.16, 0.92, 0.012, 0.014),), rmax=0.11) fit.bind(vb[0], rigid=f"J_Bip_{side}_LowerArm") out += _grouped(vb + rolled(f"vambrace_{side}", vb[0], rims[0], role="gold"), "plate") arm_s = merge_surfaces(O.limb_surface(fit, (f"{side}_LowerArm", f"{side}_UpperArm"), side), sleeve) jg, jr = O.joint_guard(fit, f"couter_{side}", f"J_Bip_{side}_LowerArm", f"J_Bip_{side}_Hand", (0, 0, 1), side, arm_s, r=0.030, wing=0.050, depth=0.021) for pc in jg: fit.bind(pc, rigid=f"J_Bip_{side}_LowerArm") out += _grouped(jg + sum((rolled(f"couter_{side}{k}", pc, [rm]) for k, (pc, rm) in enumerate(zip(jg, jr))), []), "plate") # ---- shoulders: the big pauldron on the lead side, a small spaulder on the sword side ------------------------ for side, lames, spread in (("L", ((0, 58, 0.030, 0.040), (49, 77, 0.028, 0.037), (69, 97, 0.025, 0.034), (89, 112, 0.022, 0.030)), 120), ("R", ((0, 52, 0.020, 0.027), (44, 72, 0.018, 0.024)), 102)): sp, rims = O.pauldron(fit, f"spaulder_{side}", "steel", plate_body, side=side, lames=lames, spread=spread) out += _grouped(sp, "plate") + _grouped(sum((rolled(f"spaulder_{side}{k}", pc, [rm], r=0.0030, role="gold" if (side == "L" and k == 0) else "metal") for k, (pc, rm) in enumerate(zip(sp, rims))), []), "plate") # ---- belt, buckle, scabbard --------------------------------------------------------------------------------- waist = merge_surfaces(plate, (hose["pos"], hose["tri"])) y_belt = float(hips[1]) + 0.058 belt, bfront = O.belt(fit, "belt", "leather", waist, y_belt, height=0.036, offset=0.005) out.append(belt) ex, ey, ez = np.eye(3) for k, (dx, dy, hx, hy) in enumerate(((0, 0.014, 0.020, 0.003), (0, -0.014, 0.020, 0.003), (0.017, 0, 0.003, 0.017), (-0.017, 0, 0.003, 0.017))): out += _grouped([fit.bind(O.box(f"buckle{k}", "gold", bfront + [dx, dy, -0.005], (ex, ey, ez), (hx, hy, 0.003)), rigid="J_Bip_C_Hips")], "belt") sdir = np.array([-0.06, -0.80, 0.60]) sdir /= np.linalg.norm(sdir) s0 = np.array([-0.150, y_belt - 0.02, cz - 0.02]) - sdir * 0.05 scab = [O.tube("scabbard", "leather", s0, sdir, 0.86, 0.024, 0.014), O.tube("scabbard_locket", "gold", s0 - sdir * 0.004, sdir, 0.05, 0.0265, 0.0255), O.tube("scabbard_chape", "gold", s0 + sdir * 0.80, sdir, 0.07, 0.0165, 0.011)] for pc in scab: pc["pos"][:, 0] = s0[0] + (pc["pos"][:, 0] - s0[0]) * 0.55 # a flat sheath, not a pipe pc["nrm"] = O.vertex_normals(pc["pos"], pc["tri"]) fit.bind(pc, rigid="J_Bip_C_Hips") out += _grouped(scab, "belt") # ---- the surcoat's skirts: a short front panel between the tassets, a long tail behind, cream hems ----------- plates = [p for p in out if p.get("group") == "plate" and "roll" not in p["material"] and "cuirass" not in p["material"]] legs = merge_surfaces((hose["pos"], hose["tri"]), (boots["pos"], boots["tri"]), *[(p["pos"], p["tri"]) for p in plates]) hang = merge_surfaces((belt["pos"], belt["tri"]), plate, (hose["pos"], hose["tri"])) ytop = y_belt - 0.012 for nm, deg, hw, length in (("tabard", 0, 0.085, ytop - (knee + 0.10)), ("tabard_back", 180, 0.135, ytop - (knee - 0.17))): tb, grid = O.panel(fit, nm, "signature", hang, legs, ytop, deg, hw, length) tb["group"] = "tabard" out.append(tb) for tn, line, w in ((f"{nm}_hem", grid[:, -1], 0.020), (f"{nm}_edge0", grid[0], 0.010), (f"{nm}_edge1", grid[-1], 0.010)): out += _grouped([O.inherit(O.ribbon(tn, "heraldry", line, width=w, lift=0.0015, normals=O.near_normals(tb, line)), tb)], "tabard") out += longsword(fit) return [p for p in out if p is not None]result, 1 line
File created successfully at: ~/Projects/lowmarch-fable52/tools/whole/wren.py (file state is current in your context — no need to Read it back)