A 3D model pipeline, pushed by Gemini 4 Carbon
agent
+1:11:15reasoning
The code appears to be concatenating two lists of data, hair_pcs and armour_pcs, but then converting the combined list to a NumPy array with dtype=object. This is unexpected because the lists have different types of data. This could be a source of the error.
The NumPy array creation using dtype=object from a mixed list of tuples warrants close examination; this pattern is prone to shape inconsistencies that manifest as errors in newer NumPy versions. Specifically, constructing the array directly from a heterogeneous list of tuples may trigger broadcasting attempts. Manual assignment to a pre-allocated object array is a reliable workaround. Analyzing data structures, the content of hair_pcs consists of different items such as "hair_cuff" and "hair_ribbon" which is very likely the cause.
Examining tools/blender_sculpt_cast.py revealed a potential mismatch in bone axis conventions between the VRM model and Blender. Specifically, the "hips_z" coordinate is mapped incorrectly, which might lead to erroneous bone transformations during export. Further investigation into how Portrait.prims stores vertex data is necessary to confirm if vertices are in the reference pose or the posed battle stance, which is a critical detail for rigging.
read_file{"EndLine":230,"Path":"~/work/lowmarch/tools/battle_slice.py","StartLine":1}
input
{ "EndLine": 230, "Path": "~/work/lowmarch/tools/battle_slice.py", "StartLine": 1 }result, 231 lines
Showing lines 1-230 of 686 1: """Build and shoot one composed tactics battle frame on MakeHuman-caged VRoid bodies. 2: 3: Uses the project's cached caged bodies (arm_f_strong, arm_m_strong), parametric armour and 4: garment kits (outfit.py, plates.py, gear.py, hair.py), IK stances (rig.py, clips.py, duel.py), 5: terrain (terrain.py), and painted WebGL renderer (review/slice/index.html). 6: 7: python3 tools/battle_slice.py [--png ~/out/battle_frame.png] 8: """ 9: import argparse 10: import base64 11: import json 12: import math 13: import os 14: import re 15: import socket 16: import subprocess 17: import sys 18: import time 19: 20: import numpy as np 21: 22: HERE = os.path.dirname(os.path.abspath(__file__)) 23: ROOT = os.path.dirname(HERE) 24: sys.path[:0] = [HERE, os.path.join(ROOT, "art", "cast")] 25: 26: import cage # noqa: E402 27: import checks # noqa: E402 28: import duel # noqa: E402 29: import export_glb # noqa: E402 30: import gear as G # noqa: E402 31: import hair as H # noqa: E402 32: import mobs # noqa: E402 33: import outfit as O # noqa: E402 34: import poses as P # noqa: E402 35: import terrain # noqa: E402 36: import vroid_portrait as vp # noqa: E402 37: from cast import CAST # noqa: E402 38: from fitting import Surface, merge_surfaces # noqa: E402 39: from plates import LimbChart, flat_piece, outline_plate # noqa: E402 40: from rig import Rig, grip_points # noqa: E402 41: 42: SLICE_HTML = os.path.join(ROOT, "review", "slice", "index.html") 43: OUT_DIR = os.path.join(ROOT, "review", "out", "slice") 44: LOCAL_THREE = "~/context/sortie-node_modules/three" 45: 46: 47: def cached_cage_vrm(name): 48: """Resolve a pre-built caged VRM strictly read-only.""" 49: p = cage.path_for(name, CAST[name]["cage"]) 50: if not os.path.exists(p): 51: raise SystemExit(f"Missing cached cage body: {p}") 52: return p 53: 54: 55: def arm_room(v, shape, need=0.008, most=16): 56: limbs = [f"{s}_{a}" for s in "LR" for a in ("UpperArm", "LowerArm")] 57: for deg in range(0, most + 1, 2): 58: b = checks.Body(v, dict(shape, arm_out=float(deg))) 59: if min(b.worst(pose, limbs) for pose in (P.BUST, P.BATTLE_IDLE)) >= need: 60: return float(deg) 61: return float(most) 62: 63: 64: def add_scalp_cap(fit, hairline_front=52.0): 65: """Dark inner hair under-cap 2 mm off the skull so parted or warped VRoid hair never shows pale scalp.""" 66: ch = H.head_chart(fit) 67: hl = lambda u: float(np.interp(abs(u), [0, 38, 68, 105, 145, 180], 68: [hairline_front, hairline_front + 6, 82, 118, 134, 140])) 69: pc = H.cap("scalp_cap", ch, hl, lift=0.0022, crown=0.0010, nu=64, nv=20, role="hair_cap") 70: fit.bind(pc, rigid="J_Bip_C_Head") 71: pc["group"] = "hair" 72: return pc 73: 74: 75: def knightly_longsword(fit, hand="R", blade_len=0.86, blade_w=0.044, grip_len=0.17): 76: """Arming/bastard sword with curved crossguard quillons, faceted wheel pommel, and fuller.""" 77: fist, fwd, side, flat, _ = G._hand_frame(fit, hand) 78: out = [ 79: O.tube("grip", "leather", fist - fwd * grip_len * 0.56, fwd, grip_len, 0.0135), 80: O.ball("pommel", "gold", fist - fwd * (grip_len * 0.56 + 0.018), 0.022, squash=(1.0, 0.58, 1.0)), 81: O.ball("pommel_boss", "steel", fist - fwd * (grip_len * 0.56 + 0.018), 0.013, squash=(1.0, 0.78, 1.0)), 82: ] 83: guard_c = fist + fwd * (grip_len * 0.44 + 0.008) 84: ts = np.linspace(-1.0, 1.0, 17) 85: q_pts = np.array([guard_c + side * (0.088 * x) + fwd * (0.014 * x * x) for x in ts]) 86: out.append(O.pipe("guard", "gold", q_pts, r=0.0068, seg=8)) 87: for sx in (-1.0, 1.0): 88: out.append(O.ball(f"quillon_{1 if sx > 0 else 0}", "gold", 89: guard_c + side * (0.090 * sx) + fwd * 0.015, 0.009)) 90: 91: base = guard_c + fwd * 0.008 92: rows = 14 93: P_grid = np.zeros((5, rows, 3)) 94: for j, t in enumerate(np.linspace(0, 1, rows)): 95: taper = 1.0 if t < 0.80 else max(0.0, (1.0 - t) / 0.20) ** 0.85 96: w = blade_w / 2 * (1.0 - 0.18 * t) * taper 97: th = 0.0048 * taper 98: c = base + fwd * blade_len * t 99: P_grid[:, j] = [c + side * w, c + flat * th, c - side * w, c - flat * th, c + side * w] 100: pos, tri = O.grid_mesh(P_grid) 101: out.append(O.piece("blade", "steel", pos, tri, outward_from=base + fwd * blade_len / 2, axis=fwd)) 102: for sg in (-1.0, 1.0): 103: out.append(O.ribbon( 104: f"fuller_{1 if sg > 0 else 0}", "metal", 105: [base + fwd * blade_len * t + flat * (sg * 0.0049) for t in np.linspace(0.03, 0.68, 10)], 106: width=blade_w * 0.16, lift=0.0004, normals=np.tile(flat * sg, (10, 1)) 107: )) 108: for pc in out: 109: fit.bind(pc, rigid=f"J_Bip_{hand}_Hand") 110: pc["group"] = "sword" 111: return out 112: 113: 114: def crescent_poleaxe(fit, length=1.96, grip=0.54, hand="R", name="poleaxe"): 115: """Bearded crescent halberd/poleaxe with honed edge bevel, back fluke, spear tip, brass collars, and tassel.""" 116: fist, fwd, side, flat, _ = G._hand_frame(fit, hand) 117: start = fist - fwd * grip 118: out = [O.tube(f"{name}_haft", "wood", start, fwd, length, 0.015)] 119: top = start + fwd * length 120: 121: # Bearded crescent axe blade 122: a = np.linspace(-1.0, 1.0, 17) 123: edge = [(0.19 * (0.76 + 0.24 * math.cos(x * 1.15)), -0.05 + 0.15 * x) for x in a] 124: cres = [ 125: (0.018, -0.09), 126: (0.075, -0.19), 127: ] + edge + [ 128: (0.065, 0.10), 129: (0.018, 0.045), 130: ] 131: bevel_line = [(0.165 * (0.76 + 0.24 * math.cos(x * 1.15)), -0.05 + 0.14 * x) for x in a] 132: deco = [("line", bevel_line, 0.0035, "groove")] 133: out.append(flat_piece(f"{name}_blade", "steel", cres, top - fwd * 0.11, side, fwd, thickness=0.008, decal=deco)) 134: 135: # Curved rear fluke hook 136: hook = [(-0.018, -0.06), (-0.095, -0.095), (-0.135, -0.045), (-0.090, 0.015), (-0.018, 0.025)] 137: out.append(flat_piece(f"{name}_fluke", "steel", hook, top - fwd * 0.11, side, fwd, thickness=0.007)) 138: 139: # Tapered diamond spear spike 140: spike = [(0.0, -0.01), (0.024, 0.045), (0.014, 0.16), (0.0, 0.29), (-0.014, 0.16), (-0.024, 0.045)] 141: out.append(flat_piece(f"{name}_spike", "steel", spike, top - fwd * 0.02, side, fwd, thickness=0.008)) 142: 143: # Steel langet socket + brass collar rings + crimson tassel 144: out.append(O.tube(f"{name}_socket", "steel", top - fwd * 0.30, fwd, 0.29, 0.018)) 145: for k, off in enumerate((0.02, 0.29)): 146: c_ring = top - fwd * off 147: ang = np.linspace(0, 2 * math.pi, 18, endpoint=False) 148: ring = np.array([c_ring + (side * math.cos(th) + flat * math.sin(th)) * 0.020 for th in ang]) 149: out.append(O.pipe(f"{name}_collar{k}", "gold", ring, r=0.0038, seg=6, closed=True)) 150: 151: tassel_root = top - fwd * 0.30 - side * 0.018 152: t_pts = np.array([tassel_root + np.array([0.0, -0.032 * s, 0.008 * s]) - side * (0.018 * s) 153: for s in np.linspace(0, 1, 7)]) 154: out.append(O.pipe(f"{name}_tassel", "signature", t_pts, r=0.0075, seg=6)) 155: out.append(O.ball(f"{name}_butt", "steel", start - fwd * 0.012, 0.019, squash=(1, 1, 1.5))) 156: G._bind(fit, out, f"J_Bip_{hand}_Hand") 157: return G._group(out, "weapon") 158: 159: 160: def cloak_clasps(fit, under, role="gold", cord_role="gold", y_off=-0.036, x_deg=34.0): 161: """Pair of domed collarbone cloak-clasps with a draped chest cord between them.""" 162: nk = fit.bone["J_Bip_C_Neck"] 163: pts = [] 164: out = [] 165: for k, sgn in enumerate((-1.0, 1.0)): 166: a = math.radians(sgn * x_deg) 167: d = np.array([math.sin(a), 0.0, -math.cos(a)]) 168: o = np.array([nk[0], nk[1] + y_off, nk[2]]) 169: r = under.cast(o, d, rmax=0.26, far=True) 170: p = o + d * ((0.09 if np.isnan(r) else r) + 0.008) 171: pts.append(p) 172: cl = O.ball(f"clasp_{k}", role, p, 0.014, seg=12, rows=7, squash=(1.0, 1.0, 0.55)) 173: fit.bind(cl, rigid="J_Bip_C_UpperChest") 174: cl["group"] = "trim" 175: out.append(cl) 176: ts = np.linspace(0, 1, 15) 177: cord = [] 178: for t in ts: 179: q = pts[0] * (1 - t) + pts[1] * t + np.array([0.0, -0.022 * math.sin(math.pi * t), -0.010 * math.sin(math.pi * t)]) 180: cord.append(q) 181: cp = O.pipe("clasp_cord", cord_role, np.array(cord), r=0.0032, seg=6) 182: fit.bind(cp, rigid="J_Bip_C_UpperChest") 183: cp["group"] = "trim" 184: out.append(cp) 185: return out 186: 187: 188: def tuck_boot_feet(fit, boots_pc, inset=0.008): 189: """Pull wrapped boot toe/foot vertices slightly inward so the rounded boot last covers them cleanly.""" 190: B = fit.bone 191: y_cut = min(B["J_Bip_L_Foot"][1], B["J_Bip_R_Foot"][1]) + 0.015 192: pos = boots_pc["pos"] 193: sel = pos[:, 1] < y_cut 194: if not np.any(sel): 195: return 196: for side in ("L", "R"): 197: ft = B[f"J_Bip_{side}_Foot"] 198: side_mask = sel & ((pos[:, 0] < 0) if side == "L" else (pos[:, 0] >= 0)) 199: if not np.any(side_mask): 200: continue 201: d = pos[side_mask] - np.array([ft[0], y_cut - 0.03, ft[2] - 0.04]) 202: n = np.linalg.norm(d, axis=1, keepdims=True) 203: pos[side_mask] -= d / np.maximum(n, 1e-6) * inset 204: boots_pc["nrm"] = O.vertex_normals(boots_pc["pos"], boots_pc["tri"]) 205: 206: 207: def strapped_heater_shield(fit, rig_guard, guard_pose, yaw_deg=32.0, width=0.35, height=0.49, curve=0.44): 208: """Curved heater shield kinematically aligned to stand upright in 3/4 guard with arm tucked behind it.""" 209: names = rig_guard.v.nodes_by_name() 210: i_la = names["J_Bip_L_LowerArm"] 211: i_hd = names["J_Bip_L_Hand"] 212: Wg = rig_guard.world(guard_pose) 213: Mg = Wg[i_la] 214: Eg = Mg[:3, 3] 215: Hg = Wg[i_hd][:3, 3] 216: 217: F3 = np.diag([-1.0, 1.0, -1.0]) 218: a = math.radians(-yaw_deg) 219: Ry_inv = np.array([[math.cos(a), 0.0, math.sin(a)], [0.0, 1.0, 0.0], [-math.sin(a), 0.0, math.cos(a)]]) 220: cam_to_vrm = lambda v: F3 @ (Ry_inv @ (np.asarray(v, float) / np.linalg.norm(v))) 221: 222: out_g = cam_to_vrm([0.52, 0.06, 0.85]) 223: up_g = cam_to_vrm([-0.06, 0.99, -0.03]) 224: up_g -= out_g * (up_g @ out_g) 225: up_g /= np.linalg.norm(up_g) 226: fw_g = np.cross(out_g, up_g) 227: centre_g = Eg * 0.25 + Hg * 0.75 + out_g * 0.195 + fw_g * 0.025 228: 229: M_rest = fit.world["J_Bip_L_LowerArm"] 230: T_g2r = M_rest @ np.linalg.inv(Mg)read_file{"EndLine":160,"Path":"~/work/lowmarch/tools/outfit.py","StartLine":1}
input
{ "EndLine": 160, "Path": "~/work/lowmarch/tools/outfit.py", "StartLine": 1 }result, 161 lines
Showing lines 1-160 of 1272 1: """Fantasy costume pieces, generated in code and fitted onto a VRoid body. 2: 3: Coordinates are the model's (metres, y up, the character faces -z, its left is -x). Pieces are 4: built once in the reference pose (the bust pose, arms down) and carry skin weights (J, W, jnames) 5: so the renderer can pose them with the body through the skeleton: soft layers copy the weights of 6: the body under them, hard parts ride one bone. 7: 8: Kinds of piece (see docs/portrait-guide.md lesson 07 for the measurements behind the offsets): 9: 10: wrap a garment shrink-wrapped onto a body region chosen by bones (tunic, trousers, boots, 11: gloves): seams welded, smoothed without shrinking, every vertex set at an offset 12: collar a standing collar fitted to the neck by ray casts, rising toward the back 13: pauldron three overlapping lames whose shape comes from ray casts to what they cover 14: drape cloth (cape, tunic tails) settled by a small cloth simulation against the body 15: belt a band around the waist on top of the tunic 16: trim a band along a piece's edge (gold trim, piping), lifted off its surface 17: props sword and hardware built from boxes, tubes and balls 18: 19: A costume is a function of a Fit (body + bones in the reference pose) returning a list of pieces. 20: """ 21: import math 22: import os 23: 24: import numpy as np 25: from scipy.spatial import cKDTree 26: 27: from fitting import (Surface, merge_surfaces, weld, compact, subdivide, shrink_wrap, flatten_hem, limb_hull, 28: boundary_loops, vertex_normals, transfer_weights, rigid_weights, blend_weights, taubin) 29: 30: 31: # ---- mesh helpers -------------------------------------------------------------- 32: def grid_mesh(P): 33: """P: (U, V, 3) grid of points -> (pos, tri).""" 34: U, V = P.shape[:2] 35: idx = np.arange(U * V).reshape(U, V) 36: a, b, c, d = idx[:-1, :-1], idx[1:, :-1], idx[1:, 1:], idx[:-1, 1:] 37: tri = np.concatenate([np.stack([a, b, c], -1).reshape(-1, 3), np.stack([a, c, d], -1).reshape(-1, 3)]) 38: return P.reshape(-1, 3), tri 39: 40: 41: def piece(name, role, pos, tri, nrm=None, outward_from=None, axis=None): 42: """outward_from: a point (or, with axis, a line) the normals should face away from, so the 43: renderer knows which side is the outside of a one-sided sheet.""" 44: pos = np.asarray(pos, float) 45: tri = np.asarray(tri) 46: nrm = vertex_normals(pos, tri) if nrm is None else nrm 47: if outward_from is not None: 48: d = pos - np.asarray(outward_from, float) 49: if axis is not None: 50: a = np.asarray(axis, float) / np.linalg.norm(axis) 51: d -= np.outer(d @ a, a) 52: if (np.einsum("ij,ij->i", nrm, d) < 0).mean() > 0.5: 53: nrm = -nrm 54: tri = tri[:, ::-1] 55: return dict(mesh="outfit", material=f"OUTFIT_{name}", mi=-1, role=role, pos=pos, 56: nrm=nrm, uv=np.zeros((len(pos), 2)), tri=tri) 57: 58: 59: def thick_grid(P, thickness, outward_from, axis=None): 60: """A grid sheet given real thickness: outer face, inner face, and the four edges closed, so 61: rims read as solid and the inside never shows.""" 62: pos, tri = grid_mesh(P) 63: n = vertex_normals(pos, tri) 64: d = pos - np.asarray(outward_from, float) 65: if axis is not None: 66: a = np.asarray(axis, float) / np.linalg.norm(axis) 67: d -= np.outer(d @ a, a) 68: if (np.einsum("ij,ij->i", n, d) < 0).mean() > 0.5: 69: n, tri = -n, tri[:, ::-1] 70: U, V = P.shape[:2] 71: inner = (pos - n * thickness).reshape(U, V, 3) 72: outer = pos.reshape(U, V, 3) 73: mid = outer.reshape(-1, 3).mean(0) 74: allp, allt, off = [], [], 0 75: parts = [(outer, tri, None), (inner, tri[:, ::-1], None)] 76: for edge in (lambda G: G[:, 0], lambda G: G[:, -1], lambda G: G[0, :], lambda G: G[-1, :]): 77: strip = np.stack([edge(outer), edge(inner)], 1) 78: p_, t_ = grid_mesh(strip) 79: nn = vertex_normals(p_, t_) 80: if (np.einsum("ij,ij->i", nn, p_ - mid) < 0).mean() > 0.5: 81: t_ = t_[:, ::-1] 82: parts.append((strip, t_, True)) 83: for G, t_, _ in parts: 84: allp.append(G.reshape(-1, 3)) 85: allt.append(t_ + off) 86: off += G.shape[0] * G.shape[1] 87: return np.concatenate(allp), np.concatenate(allt), outer 88: 89: 90: def frame_axes(a, hint=(0, 1, 0)): 91: a = np.asarray(a, float) / np.linalg.norm(a) 92: b = np.cross(a, hint) 93: if np.linalg.norm(b) < 1e-6: 94: b = np.cross(a, (1, 0, 0)) 95: b /= np.linalg.norm(b) 96: return a, b, np.cross(a, b) 97: 98: 99: def box(name, role, centre, axes, half): 100: c = np.asarray(centre, float) 101: ax = [np.asarray(v, float) * h for v, h in zip(axes, half)] 102: corners = np.array([c + sx * ax[0] + sy * ax[1] + sz * ax[2] 103: for sx in (-1, 1) for sy in (-1, 1) for sz in (-1, 1)]) 104: quads = [(0, 1, 3, 2), (4, 6, 7, 5), (0, 4, 5, 1), (2, 3, 7, 6), (0, 2, 6, 4), (1, 5, 7, 3)] 105: pos, tri = [], [] 106: for q in quads: 107: base = len(pos) 108: pos += [corners[i] for i in q] 109: tri += [(base, base + 1, base + 2), (base, base + 2, base + 3)] 110: return piece(name, role, np.array(pos), np.array(tri), outward_from=c) 111: 112: 113: def tube(name, role, start, axis, length, r0, r1=None, seg=16, rows=2): 114: r1 = r0 if r1 is None else r1 115: a, b, c = frame_axes(axis) 116: ang = np.linspace(0, 2 * math.pi, seg, endpoint=False) 117: P = np.zeros((seg + 1, rows, 3)) 118: for j, t in enumerate(np.linspace(0, 1, rows)): 119: r = r0 + (r1 - r0) * t 120: ring = np.asarray(start) + a * length * t + (np.outer(np.cos(ang), b) + np.outer(np.sin(ang), c)) * r 121: P[:seg, j] = ring 122: P[seg, j] = ring[0] 123: pos, tri = grid_mesh(P) 124: return piece(name, role, pos, tri, outward_from=np.asarray(start) + a * length / 2, axis=a) 125: 126: 127: def ball(name, role, centre, r, seg=14, rows=8, squash=(1, 1, 1)): 128: th = np.linspace(0, math.pi, rows) 129: ph = np.linspace(0, 2 * math.pi, seg + 1) 130: P = np.zeros((seg + 1, rows, 3)) 131: for j, t in enumerate(th): 132: P[:, j, 0] = np.sin(t) * np.cos(ph) * r * squash[0] 133: P[:, j, 1] = np.cos(t) * r * squash[1] 134: P[:, j, 2] = np.sin(t) * np.sin(ph) * r * squash[2] 135: P += np.asarray(centre) 136: pos, tri = grid_mesh(P) 137: return piece(name, role, pos, tri, outward_from=centre) 138: 139: 140: def ribbon(name, role, curve, width=0.006, lift=0.002, normals=None, away=None, closed=False): 141: """A band along a 3D polyline, lifted off a surface. normals: the surface normal at each 142: point (the band lies flat on it); otherwise it faces away from `away`.""" 143: C = np.asarray(curve, float) 144: N = None if normals is None else np.asarray(normals, float) 145: if closed: 146: C = np.concatenate([C, C[:1]]) 147: N = None if N is None else np.concatenate([N, N[:1]]) 148: t = np.gradient(C, axis=0) 149: t /= np.maximum(np.linalg.norm(t, axis=1, keepdims=True), 1e-9) 150: nrm = N if N is not None else C - np.asarray(away if away is not None else C.mean(0)) 151: nrm = nrm - t * np.einsum("ij,ij->i", nrm, t)[:, None] 152: nrm /= np.maximum(np.linalg.norm(nrm, axis=1, keepdims=True), 1e-9) 153: side = np.cross(t, nrm) 154: P = np.stack([C - side * width / 2 + nrm * lift, C + side * width / 2 + nrm * lift], 1) 155: pos, tri = grid_mesh(P) 156: vn = np.repeat(nrm, 2, axis=0) 157: if (vertex_normals(pos, tri) * vn).sum(1).mean() < 0: 158: tri = tri[:, ::-1] 159: return piece(name, role, pos, tri, nrm=vn) 160:
agent
+1:11:31reasoning
The code sections highlight potential issues. Specifically, the handling of frames and transformations within the battle_slice.py tool warrants further investigation. The Portrait.prims data structure, storing elements in REST pose, requires analysis to determine how this affects the strapped_heater_shield.
The hand grip frame, obtained in the rest pose, allows constructing the right-hand elements directly in the rest pose, ensuring proper binding to the hand bone across animations. Similarly, the shield's position in the guard pose, then transformed back to the rest pose, can be correctly integrated into the rest pose, ensuring correct animation.
read_file{"EndLine":60,"Path":"~/work/lowmarch/tools/gear.py","StartLine":1}
input
{ "EndLine": 60, "Path": "~/work/lowmarch/tools/gear.py", "StartLine": 1 }result, 61 lines
Showing lines 1-60 of 984 1: """Gear for generic units (the enemy soldiers): helmets, hoods and coifs, quilted coats, mail, 2: riveted vests, shields and weapons, built on the plate kit (plates.py) and the head chart (hair.py). 3: Each function returns pieces bound to the skeleton; a class costume (mobs.py) combines them. 4: 5: Builds and faces for generic units are presets of the body's shape controls (BUILDS, FACES), so the 6: same costume dresses a slim young soldier or a huge brute. 7: """ 8: import math 9: 10: import numpy as np 11: 12: import outfit as O 13: from fitting import Surface 14: from plates import TorsoChart, LimbChart, ConeChart, outline_plate, stiffen, flat_piece, taper, Canvas 15: from hair import head_chart 16: 17: # ---- builds and faces: presets of vroid_portrait's shape controls ------------------------------------ 18: BUILDS = { 19: "slim": dict(chest=0.95, torso=0.94, arms=0.94, legs=0.94, neck=0.95), 20: "average": dict(), 21: "athletic": dict(chest=1.06, arms=1.07, legs=1.04, neck=1.08, shoulder_w=0.010), 22: "stocky": dict(chest=1.18, torso=1.24, arms=1.18, legs=1.16, neck=1.28, shoulder_w=0.018, leg_len=0.95, height=0.97), 23: "huge": dict(chest=1.34, torso=1.32, arms=1.40, legs=1.32, neck=1.55, hands=1.22, shoulder_w=0.042, height=1.12, 24: head=0.92), 25: } 26: FACES = { # 3D-strength values (the sculpt moves anatomical points by millimetres per unit) 27: "bare": dict(), # no sculpt here: the head is sculpted in its own file (tools/heads.py, the armory) 28: "young": dict(face_len=-0.04, jaw=-0.4, chin_len=-0.5, eye=1.04), 29: "plain": dict(face_len=0.05, jaw=0.6, brow_ridge=0.6, eye=0.95, rest={"Fcl_BRW_Angry": 0.3}), 30: "veteran": dict(face_len=0.14, jaw=1.4, chin_w=1.2, chin_len=1.0, cheek=-1.0, brow_ridge=1.6, nose=1.4, eye=0.88, 31: age_lines=0.8, iris=0.82, blush=0.0, mouth=1.1, 32: rest={"Fcl_EYE_Angry": 0.6, "Fcl_EYE_Close": 0.12, "Fcl_EYE_Joy": 0.22, "Fcl_BRW_Angry": 0.65, 33: "Fcl_MTH_Down": 0.35}), 34: "brute": dict(face_len=0.10, jaw=2.6, chin_w=2.2, chin_len=0.8, cheek=1.2, brow_ridge=2.4, nose=0.8, nose_w=2.2, 35: eye=0.86, mouth=1.25, rest={"Fcl_EYE_Close": 0.28, "Fcl_BRW_Angry": 0.75}), 36: "gaunt": dict(face_len=0.18, jaw=0.3, chin_len=1.2, cheek=-1.6, nose=1.8, eye=0.88, 37: rest={"Fcl_BRW_Angry": 0.5, "Fcl_EYE_Close": 0.25}), 38: "round": dict(face_len=-0.03, jaw=1.0, chin_w=1.2, cheek=1.6, eye=0.93, mouth=1.08), 39: "soft": dict(face_len=0.02, jaw=-0.2, cheek=0.4, eye=1.0), 40: "stern": dict(face_len=0.07, jaw=0.6, chin_len=0.5, brow_ridge=0.8, eye=0.92, rest={"Fcl_BRW_Angry": 0.55}), 41: } 42: 43: 44: def shape(build="average", face="plain", **extra): 45: """A shape dict for the cast: a build and a face combined (later keys win).""" 46: out = dict(BUILDS[build]) 47: f = dict(FACES[face]) 48: extra = dict(extra) 49: rest = {**out.pop("rest", {}), **f.pop("rest", {}), **extra.pop("rest", {})} 50: out.update(f) 51: out.update(extra) 52: if rest: 53: out["rest"] = rest 54: return out 55: 56: 57: def _bind(fit, pcs, bone): 58: for pc in pcs: 59: fit.bind(pc, rigid=bone) 60: return pcsread_file{"EndLine":450,"Path":"~/work/lowmarch/tools/battle_slice.py","StartLine":231}
input
{ "EndLine": 450, "Path": "~/work/lowmarch/tools/battle_slice.py", "StartLine": 231 }result, 221 lines
Showing lines 231-450 of 686 231: R_g2r = T_g2r[:3, :3] 232: R_g2r = R_g2r / np.linalg.norm(R_g2r, axis=0) 233: 234: centre = (T_g2r @ np.append(centre_g, 1.0))[:3] 235: lat = R_g2r @ out_g 236: up = R_g2r @ up_g 237: fw = np.cross(lat, up) 238: 239: t = np.linspace(0, 1, 13) 240: right = [(width / 2 * (1 - t_ ** 2.2), -height * 0.25 - height * 0.75 * t_) for t_ in t] 241: outline = [(-width / 2, height * 0.25), (width / 2, height * 0.25)] + right[1:] + [(-x, y) for x, y in right[::-1][1:-1]] 242: emblem = [ 243: ("poly", [(-0.11, 0.06), (0.0, 0.16), (0.11, 0.06), (0.11, 0.01), (0.0, 0.11), (-0.11, 0.01)], "gold"), 244: ("poly", [(-0.042, -0.01), (0.042, -0.01), (0.0, -0.17)], "gold"), 245: ] 246: pc = flat_piece("heater", "signature", outline, centre, fw, up, thickness=0.012, decal=emblem, px=1200) 247: P_pos = pc["pos"] 248: x = (P_pos - centre) @ fw 249: P_pos += lat[None] * (-(x ** 2) / (2 * curve))[:, None] 250: pc["nrm"] = O.vertex_normals(P_pos, pc["tri"]) 251: rim = O.pipe( 252: "heater_rim", "gold", 253: np.array([centre + fw * px_ + up * py_ + lat * (-(px_ ** 2) / (2 * curve) + 0.007) for px_, py_ in outline]), 254: r=0.0055, seg=6, closed=True 255: ) 256: boss, _ = O.dome("heater_boss", "steel", centre + up * 0.02 + lat * 0.008, lat, up, 0.032, 0.020, rows=6) 257: enarme = O.tube("heater_enarme", "leather", centre - lat * 0.035 - up * 0.06, up, 0.14, 0.009) 258: out = [pc, rim, boss, enarme] 259: G._bind(fit, out, "J_Bip_L_LowerArm") 260: return G._group(out, "shield") 261: 262: 263: def vanguard_captain(fit, rig_guard=None, guard_pose=None): 264: """Original Lowmarch vanguard officer costume fitted to arm_f_strong.""" 265: B = fit.bone 266: hips, nk = B["J_Bip_C_Hips"], B["J_Bip_C_Neck"] 267: knee = B["J_Bip_L_LowerLeg"][1] 268: cuff_len = 0.56 269: boot_top = knee + 0.055 270: y_waist = hips[1] + 0.055 271: y_skirt = hips[1] - 0.25 272: 273: out, shirt, trousers, boots = mobs._base( 274: fit, shirt="signature", legs="doublet", boots="boot", gloves="glove", 275: shirt_subdiv=0, boot_top=boot_top 276: ) 277: G.loose_sleeves(fit, shirt, ease=0.028, cuff=cuff_len, folds=6) 278: G.flare_boots(fit, boots, boot_top - 0.005, ease=0.010) 279: tuck_boot_feet(fit, boots, inset=0.009) 280: 281: # Clean cavalier boot-lasts outside the tucked boot feet so zero toes or seams ever show 282: for side in ("L", "R"): 283: sabs = O.sabaton(fit, f"sabaton_{side}", side, role="boot", pad=0.020, ridges=0) 284: out += G._group(sabs, "boots") 285: 286: under = mobs._under(shirt) 287: skirt_pcs = G.pleated_skirt( 288: fit, under, y_waist, y_skirt, role="signature", name="battle_skirt", 289: flare=0.098, pleats=24, depth=0.011, split=20.0 290: ) 291: for sp in skirt_pcs: 292: if "plate" in sp: 293: sp["plate"][:, 2] = 0.009 294: out += skirt_pcs 295: G.slim_under(fit, trousers, y_skirt) 296: 297: # Sculpted steel cuirass + plackart with antique-gold border 298: bp = G.breastplate(fit, under, role="steel", arm=62.0, keel=0.009) 299: for pc in bp: 300: if "plate" in pc: 301: pc["plate"][:, 2] = 0.0075 302: out += bp 303: 304: # Standing indigo officer collar with gold rim 305: col_pc, col_top, _ = O.collar(fit, "collar", "signature", height_back=0.042, height_front=0.026, gap_deg=54) 306: col_trim = O.inherit(O.pipe("collar_trim", "gold", col_top, r=0.0025, seg=6), col_pc) 307: col_pc["group"] = col_trim["group"] = "collar" 308: out += [col_pc, col_trim] 309: 310: # Fuller 3-lame steel spaulders + smooth LimbChart shin greaves with gold borders 311: plate_surf = merge_surfaces(*[(p["pos"], p["tri"]) for p in out if p.get("group") == "plate"], (fit.pos, fit.tri)) 312: for side in ("L", "R"): 313: sp, rims = O.pauldron( 314: fit, f"spaulder_{side}", "steel", plate_surf, side=side, 315: lames=((0, 56, 0.022, 0.030), (47, 74, 0.020, 0.027), (66, 92, 0.018, 0.024)), spread=116 316: ) 317: out += G._group( 318: sp + [O.inherit(O.pipe(f"spaulder_{side}_roll{k}", "gold" if k == 0 else "steel", r_, r=0.0026), pc) 319: for k, (pc, r_) in enumerate(zip(sp, rims))], 320: "plate" 321: ) 322: ll, ft = B[f"J_Bip_{side}_LowerLeg"], B[f"J_Bip_{side}_Foot"] 323: lc = LimbChart(O.side_of(boots, side), ll, ft, front=(0, 0, -1), smooth=(1.6, 1.5)) 324: gv, gx = outline_plate( 325: f"greave_{side}", "steel", lc, -108, 108, 326: lambda u: 0.80 - 0.04 * (abs(u) / 108) ** 1.5, 327: lambda u: 0.16 + 0.05 * max(0.0, 1.0 - (u / 45.0) ** 2), 328: offset=0.008, crown=0.004, thickness=0.004, nu=40, nv=16, 329: trim=0.0055, roll=0.0026, roll_edges=("top", "bottom") 330: ) 331: fit.bind(gv, rigid=f"J_Bip_{side}_LowerLeg") 332: out += G._group([gv] + [O.inherit(q, gv) for q in gx], "plate") 333: 334: # Waist belt + gold buckle 335: belt_over = mobs._surf(out, "breastplate", prefix=True) 336: belt_pc, front_pt = O.belt(fit, "belt", "leather", belt_over, hips[1] + 0.048, height=0.036, offset=0.005) 337: buckle = fit.bind(O.box("buckle", "gold", front_pt + np.array([0, 0, -0.005]), 338: ([1, 0, 0], [0, 1, 0], [0, 0, 1]), (0.025, 0.025, 0.006)), rigid="J_Bip_C_Hips") 339: buckle["group"] = "belt" 340: out += [belt_pc, buckle] 341: 342: cuff_pcs = G.cuffs(fit, role="glove", length=cuff_len, flare=0.028) 343: G.tuck_sleeves(fit, shirt, cuff_pcs) 344: out += cuff_pcs 345: 346: # Flowing indigo officer cloak clasped at collarbones 347: cape_under = merge_surfaces( 348: *[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate", "doublet", "collar")], 349: (fit.pos, fit.tri) 350: ) 351: cape_pc, _ = O.cape(fit, "cape", "signature", cape_under, length=0.96, phi=0.52, seg=44, rows=18, 352: top_clear=0.008, clear=(0.018, 0.055)) 353: cape_pc["group"] = "cape" 354: out.append(cape_pc) 355: out += cloak_clasps(fit, cape_under, role="gold", cord_role="gold", y_off=-0.038, x_deg=35.0) 356: 357: # Upright strapped heater shield aligned to Valen's guard pose 358: out += strapped_heater_shield(fit, rig_guard, guard_pose, yaw_deg=32.0) 359: 360: out += knightly_longsword(fit, "R") 361: out.append(add_scalp_cap(fit, hairline_front=54.0)) 362: return out 363: 364: 365: def heavy_housecarl(fit): 366: """Original Lowmarch heavy housecarl costume fitted to arm_m_strong (unhelmeted so face/hair read).""" 367: B = fit.bone 368: hips = B["J_Bip_C_Hips"] 369: knee = B["J_Bip_L_LowerLeg"][1] 370: boot_top = knee - 0.075 371: y_gambeson = hips[1] - 0.24 372: y_mail = hips[1] - 0.15 373: 374: out, shirt, trousers, boots = mobs._base( 375: fit, shirt="padding", legs="doublet", boots="boot", gloves="glove", boot_top=boot_top 376: ) 377: G.breeches(fit, trousers, boots, y_gambeson, boot_top - 0.005, ease=0.040) 378: tuck_boot_feet(fit, boots, inset=0.009) 379: for side in ("L", "R"): 380: lasts = O.sabaton(fit, f"boot_last_{side}", side, role="boot", pad=0.020, ridges=0) 381: out += G._group(lasts, "boots") 382: 383: under = mobs._under(shirt) 384: out += G.quilted(fit, under, role="padding", y_hem=y_gambeson, sleeve_end=0.92) 385: gam = mobs._surf(out, "gambeson", "gambeson_skirt") 386: out += G.mail_shirt(fit, gam, role="mail", y_hem=y_mail, sleeve=0.52) 387: mail = mobs._surf(out, "hauberk", prefix=True) 388: out += G.riveted_vest(fit, mail, role="leather", rivet_role="steel") 389: 390: # Exact torso pieces only (never sleeves) + spine/hips skinning so the belt rides cleanly at the waist 391: vest_torso = mobs._surf(out, "brigandine_front", "brigandine_back", "hauberk", "hauberk_skirt", "gambeson") 392: belt_pc, front_pt = O.belt(fit, "belt", "boot", vest_torso, hips[1] + 0.006, height=0.044, offset=0.016) 393: fit.bind(belt_pc, allow=("Spine", "Chest", "Hips"), fallback="J_Bip_C_Hips") 394: buckle = O.box("buckle", "gold", front_pt + np.array([0, 0, -0.009]), 395: ([1, 0, 0], [0, 1, 0], [0, 0, 1]), (0.032, 0.032, 0.008)) 396: fit.bind(buckle, allow=("Spine", "Chest", "Hips"), fallback="J_Bip_C_Hips") 397: buckle["group"] = "belt" 398: out += [belt_pc, buckle] 399: 400: # Draped oxblood battle cloak pinned cleanly behind the shoulders (zero collarbone pokethrough) 401: cape_under = merge_surfaces( 402: *[(p["pos"], p["tri"]) for p in out if p.get("group") in ("plate", "mail", "padding")], 403: (fit.pos, fit.tri) 404: ) 405: cape_pc, _ = O.cape(fit, "cape", "signature", cape_under, length=0.94, phi=0.36, seg=40, rows=18, 406: top_clear=0.022, clear=(0.025, 0.062)) 407: cape_pc["group"] = "cape" 408: out.append(cape_pc) 409: 410: out += G.cuffs(fit, role="glove", length=0.35, flare=0.032) 411: out += crescent_poleaxe(fit, length=1.96, grip=0.54, hand="R") 412: out.append(add_scalp_cap(fit, hairline_front=50.0)) 413: return out 414: 415: 416: def vanguard_pose(vrm, shape): 417: """Grounded fencing guard for Valen: sword poised forward, left arm braced outward behind the heater shield.""" 418: rig = Rig(vrm, shape, ortho=True) 419: body = checks.Body(vrm, shape) 420: f = {s: g["point"] for s, g in grip_points(vrm, shape, P.BUST).items()} 421: ref = dict(ref_pose=P.BUST, fist_R=f["R"], fist_L=f["L"]) 422: 423: base = P.merge(P.BATTLE_IDLE, P.fist("L", curl=(72, 84, 60), thumb=36), { 424: "J_Bip_C_Hips": P.move(0, -0.055, -0.02, P.rot((0, 1, 0), -10.0) @ P.rot((1, 0, 0), -4.5)), 425: "J_Bip_C_Spine": P.rot((0, 1, 0), -8.0) @ P.rot((1, 0, 0), -3.0), 426: "J_Bip_C_Chest": P.rot((0, 1, 0), -6.0) @ P.rot((1, 0, 0), -2.0), 427: "J_Bip_C_Neck": P.rot((0, 1, 0), 11.0) @ P.rot((1, 0, 0), 3.0), 428: "J_Bip_C_Head": P.rot((0, 1, 0), 10.0) @ P.rot((1, 0, 0), 2.5), 429: }) 430: foot = {s: rig.pos(P.BATTLE_IDLE, f"J_Bip_{s}_Foot") for s in "LR"} 431: pose = rig.leg_ik(base, "L", foot["L"] + np.array([-0.06, 0.0, -0.17]), pole=(0, 0, -1)) 432: pose = rig.leg_ik(pose, "R", foot["R"] + np.array([0.07, 0.0, 0.14]), pole=(0, -0.2, -1)) 433: 434: sh_r = rig.pos(pose, "J_Bip_R_UpperArm") 435: fist_r = sh_r + np.array([0.09, -0.34, -0.22]) 436: blade_dir = np.array([-0.24, 0.48, -0.84]) 437: pose = duel.clear_grip(rig, body, pose, "R", ref, fist_r, blade_dir, (0.7, -0.9, 0.35)) 438: 439: sh_l = rig.pos(pose, "J_Bip_L_UpperArm") 440: pose = rig.arm_ik(pose, "L", sh_l + np.array([-0.27, -0.22, 0.05]), pole=(-0.6, -0.9, 0.5)) 441: return [(0.0, pose), (1.0, pose)] 442: 443: 444: def housecarl_pose(vrm, shape): 445: """Two-handed poleaxe guard for Korin: wide planted stance, head angled cleanly toward opponent.""" 446: rig = Rig(vrm, shape, ortho=True) 447: body = checks.Body(vrm, shape) 448: f = {s: g["point"] for s, g in grip_points(vrm, shape, P.BUST).items()} 449: ref = dict(ref_pose=P.BUST, fist_R=f["R"], fist_L=f["L"]) 450: