A 3D model pipeline, pushed by Fable 5.2
user
+48:58not that I'm goading you one way or the other, but honestly, if you're using the same hair the project already has, I'm not sure I'm seeing just how adversarial this pass is.
agent
+50:11reasoning
I'm rebuilding the hair from scratch rather than keeping VRoid's weak strands: a high ponytail, a blunt fringe and side locks, made of tapered clumps over a dark cap. I'll judge it from pictures first, since it's the riskiest piece.
Bashcd ~/Projects/lowmarch-fable52 && date +%H:%M:%S && OMP_NUM_THREADS=1 python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && date +%H:%M:%S && OMP_NUM_THREADS=1 python3 - <<'E' import sys,os sys.argv=["x"]; sys.path.insert(0,"tools/whole"); os.environ["LOWMARCH_SITE"]="whole-scratch" import importlib.util s=importlib.util.spec_from_file_location('wb','tools/whole/build.py'); wb=importlib.util.module_from_spec(s); s.loader.exec_module(wb) import numpy as np, vroid_portrait as vp, outfit from cast import CAST c=CAST["wren"] p=vp.Portrait(wb.build.model_path("wren",c), shape=c["shape"], costume=None, pose=vp.BUST_POSE, hair_trim=-1) print({k:np.round(v,3).tolist() if hasattr(v,'tolist') else round(float(v),3) for k,v in p.lm.items()}) fit=outfit.Fit(p.v,p.pose_ref,p.prims,p.roles) hs=fit.head_surface() P=hs.pos[np.unique(hs.tri)] print("head skin", np.round(P.min(0),3), np.round(P.max(0),3)) print("head bone", np.round(fit.bone["J_Bip_C_Head"],3), "neck", np.round(fit.bone["J_Bip_C_Neck"],3)) # ear extents from the face mesh: verts with |x|>0.085 f=[q for q,r in zip(p.prims,p.roles) if r=="face"][0]["pos"] e=f[np.abs(f[:,0])>0.088]; print("ear verts", len(e), np.round(e.min(0),3), np.round(e.max(0),3)) C=np.array([0,1.56,0.02]) for az in (0,45,90,135,180): row=[] for el in (-20,0,20,40,60,80): d=np.array([np.sin(np.radians(az))*np.cos(np.radians(el)), np.sin(np.radians(el)), -np.cos(np.radians(az))*np.cos(np.radians(el))]) row.append(f"{hs.cast(C,d,rmax=0.3,far=True):.3f}") print(az,row) print([r for r in p.roles]) Eresult, 11 lines
19:23:10 {'eyeL': [-0.036, 1.524, -0.111], 'eyeR': [0.037, 1.524, -0.111], 'eye_y': 1.524, 'chin': [-0.0, 1.434, -0.11], 'mouth': [-0.0, 1.468, -0.11], 'nose': [-0.0, 1.492, -0.142], 'span': 0.089, 'gonionL': [-0.053, 1.464, -0.067], 'cheekL': [-0.1, 1.502, -0.015], 'chinsideL': [-0.013, 1.447, -0.115], 'ridgeL': [-0.034, 1.545, -0.12], 'wingL': [-0.003, 1.495, -0.136], 'earL': [-0.082, 1.532, -0.033], 'gonionR': [0.053, 1.464, -0.067], 'cheekR': [0.1, 1.502, -0.015], 'chinsideR': [0.013, 1.447, -0.115], 'ridgeR': [0.034, 1.545, -0.12], 'wingR': [0.003, 1.495, -0.136], 'earR': [0.082, 1.532, -0.033], 'crown': [0.0, 1.656, -0.035], 'occiput': [-0.0, 1.564, 0.063], 'forehead': [-0.0, 1.567, -0.132], 'neck_front': [-0.0, 1.379, -0.087], 'neck_back': [-0.062, 1.372, 0.056]} head skin [-0.101 1.434 -0.142] [0.101 1.656 0.063] head bone [-0. 1.464 -0.039] neck [0. 1.425 0.002] ear verts 190 [-0.101 1.492 -0.036] [ 0.101 1.539 -0.01 ] 0 ['0.154', '0.151', '0.152', '0.135', '0.111', '0.092'] 45 ['0.118', '0.117', '0.118', '0.113', '0.102', '0.089'] 90 ['0.070', '0.071', '0.074', '0.079', '0.082', '0.083'] 135 ['0.047', '0.047', '0.050', '0.056', '0.065', '0.077'] 180 ['0.043', '0.042', '0.044', '0.050', '0.061', '0.075'] ['mouth', 'iris', 'highlight', 'face', 'white', 'brow', 'line', 'line', 'body', 'shadow']Bashcd ~/Projects/lowmarch-fable52 && sed -n 41,58p tools/outfit.py && sed -n 455,530p tools/export_glb.py && sed -n 58,73p tools/hair.py
command
cd ~/Projects/lowmarch-fable52 && sed -n 41,58p tools/outfit.py && sed -n 455,530p tools/export_glb.py && sed -n 58,73p tools/hair.py
result, 108 lines
def piece(name, role, pos, tri, nrm=None, outward_from=None, axis=None): """outward_from: a point (or, with axis, a line) the normals should face away from, so the renderer knows which side is the outside of a one-sided sheet.""" pos = np.asarray(pos, float) tri = np.asarray(tri) nrm = vertex_normals(pos, tri) if nrm is None else nrm if outward_from is not None: d = pos - np.asarray(outward_from, float) if axis is not None: a = np.asarray(axis, float) / np.linalg.norm(axis) d -= np.outer(d @ a, a) if (np.einsum("ij,ij->i", nrm, d) < 0).mean() > 0.5: nrm = -nrm tri = tri[:, ::-1] return dict(mesh="outfit", material=f"OUTFIT_{name}", mi=-1, role=role, pos=pos, nrm=nrm, uv=np.zeros((len(pos), 2)), tri=tri) node_of[i] = len(gnodes) gnodes.append(dict(name=nodes_v[i].get("name"), translation=t.tolist(), rotation=q.tolist(), scale=sc.tolist())) for i in order: kids = [node_of[c] for c in nodes_v[i].get("children", []) if c in joints] if kids: gnodes[node_of[i]]["children"] = kids roots = [node_of[i] for i in order if parent.get(i) not in joints] ibm = np.stack([np.linalg.inv(wref(i)).T for i in order]).astype(np.float32) # column-major skin = dict(joints=[node_of[i] for i in order], inverseBindMatrices=add_acc(ibm.reshape(-1, 16), "MAT4", 5126), skeleton=roots[0]) mesh_nodes = [] for k, (p, role) in enumerate(zip(portrait.prims, portrait.roles)): if role == "skip" or not len(p["tri"]) or p.get("world") or "J" not in p: continue usedv, inv = np.unique(p["tri"], return_inverse=True) pos = (p["pos"][usedv] * FLIP).astype(np.float32) nrm = p["nrm"][usedv] * FLIP nrm = (nrm / np.maximum(np.linalg.norm(nrm, axis=1, keepdims=True), 1e-9)).astype(np.float32) remap = np.array([jidx.get(n, jidx.get("J_Bip_C_Head")) for n in p["jnames"]]) J = remap[p["J"][usedv]].astype(np.uint16) W = p["W"][usedv].astype(np.float32) W /= np.maximum(W.sum(1, keepdims=True), 1e-9) attrs = dict(POSITION=add_acc(pos, "VEC3", 5126, 34962), NORMAL=add_acc(nrm, "VEC3", 5126, 34962), JOINTS_0=add_acc(J, "VEC4", 5123, 34962), WEIGHTS_0=add_acc(W, "VEC4", 5126, 34962)) if "plate" in p: # outline plates (tools/plates.py): border, engraving, gradient attrs["_PLATE"] = add_acc(np.asarray(p["plate"])[usedv].astype(np.float32), "VEC4", 5126, 34962) mat = dict(name=f"{group_of(p, role)}:{role}", doubleSided=True, pbrMetallicRoughness=dict(metallicFactor=0.0, roughnessFactor=0.9)) tone = ROLE_TONE.get(role) extra = getattr(portrait, "paint", None) or {} color = hex_rgb(palette[tone]) if tone in palette else \ hex_rgb(extra[role]) if isinstance(extra.get(role), str) else [0.8, 0.8, 0.8] if role in TEXTURED: src = portrait._hair_v if role == "hair" and getattr(portrait, "_hair_v", None) is not None \ and "_HAIR" in p["material"] else portrait.v raw = src.material_texture(p["mi"]) if p["mi"] >= 0 else None if raw is not None and role == "line": raw = fill_line_specks(raw) if p.get("lid_fill") is not None: # a shut eye's lid (vroid_portrait): its lash solid raw = fill_lid(raw, p["lid_fill"]) if raw is not None and role == "mouth": raw = even_mouth(raw) if raw is not None: attrs["TEXCOORD_0"] = add_acc(p["uv"][usedv].astype(np.float32), "VEC2", 5126, 34962) mat["pbrMetallicRoughness"]["baseColorTexture"] = dict( index=add_texture((id(src), p["mi"], p.get("lid_fill")), raw)) if role == "hair": mat["pbrMetallicRoughness"]["baseColorFactor"] = color + [1.0] if role in ("hair", "line", "brow", "iris", "highlight"): mat["alphaMode"], mat["alphaCutoff"] = "MASK", 0.5 else: mat["pbrMetallicRoughness"]["baseColorFactor"] = color + [1.0] else: mat["pbrMetallicRoughness"]["baseColorFactor"] = color + [1.0] if role in ("metal", "steel", "gold"): mat["pbrMetallicRoughness"].update(metallicFactor=0.6, roughnessFactor=0.35) if p.get("strands"): # kit hair (tools/hair.py): one shared strand texture import hair as _hair attrs["TEXCOORD_0"] = add_acc(np.asarray(p["uv"], np.float32)[usedv], "VEC2", 5126, 34962) mat["pbrMetallicRoughness"]["baseColorTexture"] = dict(index=add_texture(("strands",), _hair.STRANDS)) if "decal" in p: # a design in the piece's own coordinates (tools/plates.py Canvas) uvd = np.asarray(p["uv"], np.float32)[usedv].copy() uvd[:, 1] = 1 - uvd[:, 1] # the canvas draws t up; glTF's texture origin is the top left attrs["TEXCOORD_0"] = add_acc(uvd, "VEC2", 5126, 34962) mat["pbrMetallicRoughness"]["baseColorTexture"] = dict(index=add_texture(("decal", k), p["decal"], limit=1024)) mat["extras"] = dict(decal=True) materials.append(mat) meshes.append(dict(name=group_of(p, role), primitives=[dict(attributes=attrs, indices=add_acc(inv.reshape(-1).astype(np.uint32), "SCALAR", 5125, 34963), material=len(materials) - 1)])) mesh_nodes.append(len(gnodes)) gnodes.append(dict(name=f"{group_of(p, role)}/{p['material']}", mesh=len(meshes) - 1, skin=0, extras=dict(group=group_of(p, role), role=role, material=p["material"]))) # animations for name, keys in (clips or {}).items(): times = np.array([t for t, _ in keys], np.float32) tacc = add_acc(times.reshape(-1, 1), "SCALAR", 5126, minmax=True) def strand_texture(n=256, seed=3): rng = np.random.default_rng(seed) x = np.arange(n) stripes = np.zeros(n) for f, a in ((3, 0.18), (7, 0.12), (17, 0.10), (41, 0.06)): stripes += a * np.sin(2 * np.pi * (f * x / n + rng.random())) stripes += 0.08 * gaussian_filter(rng.standard_normal(n), 1.2, mode="wrap") col = np.clip(0.62 + stripes, 0.25, 0.95) along = 1.0 - 0.10 * np.linspace(0, 1, n)[:, None] # a touch darker toward the tip img = (np.repeat(col[None, :], n, 0) * along * 255).astype(np.uint8) return np.dstack([img, img, img, np.full((n, n), 255, np.uint8)]) STRANDS = strand_texture()Write~/Projects/lowmarch-fable52/tools/whole/hairdo.py
input
~/Projects/lowmarch-fable52/tools/whole/hairdo.py """Hair built from nothing: a cap combed back to a tie, and a few big solid clumps (tools/whole/wren.py). Not VRoid's hair and not the kit's ribbons (tools/hair.py). The style is a drawing decision first: what the head's outline is from the side, where the face is framed, where the eyes are left clear. Then each shape is one solid: cap the scalp's cover, its rows running from the hairline to the tie, so shading can follow the combing; clump a tapered solid along a curve: widest about two fifths along, a point at the tip, a soft ridge down its back so a cel shadow splits it lengthwise, flat underneath. Everything is placed in head coordinates (az degrees round the head, 0 = the face, +90 = her right, 180 = behind; el degrees up from the eye-and-ear level) and in spans of this face (eye line to chin), so the style fits another head without edits. Each vertex carries (0, sway, u across, t along) in `plate` for a renderer: sway is 0 where hair is tied to the head and 1 at a free tip. """ import math import numpy as np from scipy.ndimage import gaussian_filter, map_coordinates import outfit as O def _dir(az, el): a, e = np.radians(az), np.radians(el) return np.stack([np.sin(a) * np.cos(e), np.sin(e), -np.cos(a) * np.cos(e)], -1) def _slerp(d0, d1, t): w = math.acos(float(np.clip(d0 @ d1, -1, 1))) if w < 1e-6: return np.tile(d0, (len(t), 1)) t = np.asarray(t)[:, None] return (np.sin((1 - t) * w) * d0 + np.sin(t * w) * d1) / math.sin(w) def _spline(P, n): """Centripetal Catmull-Rom through points P, resampled to n points evenly along its length.""" P = np.asarray(P, float) Q = np.concatenate([[2 * P[0] - P[1]], P, [2 * P[-1] - P[-2]]]) out = [] for i in range(len(P) - 1): p0, p1, p2, p3 = Q[i:i + 4] t0 = 0.0 t1 = t0 + np.linalg.norm(p1 - p0) ** 0.5 t2 = t1 + np.linalg.norm(p2 - p1) ** 0.5 t3 = t2 + np.linalg.norm(p3 - p2) ** 0.5 for t in np.linspace(t1, t2, 12, endpoint=False): a1 = (t1 - t) / (t1 - t0) * p0 + (t - t0) / (t1 - t0) * p1 a2 = (t2 - t) / (t2 - t1) * p1 + (t - t1) / (t2 - t1) * p2 a3 = (t3 - t) / (t3 - t2) * p2 + (t - t2) / (t3 - t2) * p3 b1 = (t2 - t) / (t2 - t0) * a1 + (t - t0) / (t2 - t0) * a2 b2 = (t3 - t) / (t3 - t1) * a2 + (t - t1) / (t3 - t1) * a3 out.append((t2 - t) / (t2 - t1) * b1 + (t - t1) / (t2 - t1) * b2) out.append(P[-1]) out = np.array(out) s = np.concatenate([[0], np.cumsum(np.linalg.norm(np.diff(out, axis=0), axis=1))]) return np.stack([np.interp(np.linspace(0, s[-1], n), s, out[:, k]) for k in range(3)], 1) class Head: """The skull as a radius field round a centre between the temples, smoothed, with hollows bridged.""" def __init__(self, fit): import vroid_portrait as vp self.lm = lm = vp.landmarks(fit._prims, fit._roles) self.span, self.eye_y = float(lm["span"]), float(lm["eye_y"]) self.C = np.array([0.0, self.eye_y + 0.36 * self.span, (lm["forehead"][2] + lm["occiput"][2]) / 2]) surf = fit.head_surface() self.az = np.arange(-180.0, 180.0, 3.0) self.el = np.arange(-60.0, 90.1, 3.0) R = np.full((len(self.az), len(self.el)), np.nan) for i, a in enumerate(self.az): for j, e in enumerate(self.el): R[i, j] = surf.cast(self.C, _dir(a, e), rmax=0.3, far=True) bad = ~np.isfinite(R) R[bad] = np.nanmedian(R) R = np.maximum(R, gaussian_filter(R, (4, 4), mode=("wrap", "nearest"))) # over the ears, not into them self.R = gaussian_filter(R, (1.5, 1.5), mode=("wrap", "nearest")) def radius(self, d): d = np.atleast_2d(d) az = np.degrees(np.arctan2(d[:, 0], -d[:, 2])) el = np.degrees(np.arcsin(np.clip(d[:, 1], -1, 1))) i = ((az + 180.0) / 3.0) % len(self.az) j = np.clip((el + 60.0) / 3.0, 0, len(self.el) - 1) return map_coordinates(self.R, [i, j], order=1, mode="wrap") def volume(self, d): """How far the hair stands off the skull: least at the hairline, most over the crown and the back.""" d = np.atleast_2d(d) up = np.clip(d[:, 1], 0, 1) back = np.clip(d[:, 2], 0, 1) return 0.011 + 0.011 * up + 0.012 * back * (0.4 + 0.6 * up) def shell(self, d, lift=0.0): d = np.atleast_2d(d) return self.C + d * (self.radius(d) + self.volume(d) + lift)[:, None] def skin(self, d, lift): """A point `lift` off the skin itself (the forehead, the cheek), where no hair volume is wanted.""" d = np.atleast_2d(d) return self.C + d * (self.radius(d) + lift)[:, None] def el_for(self, az, y, lift): """The elevation at which the skin-plus-lift point at `az` is at height y.""" el = 0.0 for _ in range(4): r = float(self.radius(_dir(az, el))[0]) + lift el = math.degrees(math.asin(np.clip((y - self.C[1]) / r, -1, 1))) return el def _mesh(G, role, name, sway, uv_u): """A (n, k, 3) grid of rings, closed round each ring and pinched shut at the tip, as a kit piece.""" n, k = G.shape[:2] idx = np.arange(n * k).reshape(n, k) a, b = idx[:-1], idx[1:] an, bn = np.roll(a, -1, 1), np.roll(b, -1, 1) tri = np.concatenate([np.stack([a, b, an], -1).reshape(-1, 3), np.stack([an, b, bn], -1).reshape(-1, 3)]) pos = G.reshape(-1, 3) c = pos.mean(0) pc = O.piece(name, role, pos, tri, outward_from=None) # rings are wound so normals face out of the solid: check against each ring's own centre ctr = np.repeat(G.mean(1), k, 0) if (np.einsum("ij,ij->i", pc["nrm"], pos - ctr) < 0).mean() > 0.5: pc["tri"] = pc["tri"][:, ::-1] pc["nrm"] = -pc["nrm"] t = np.repeat(np.linspace(0, 1, n), k) pc["plate"] = np.stack([np.zeros(n * k), np.repeat(sway, k), np.tile(uv_u, n), t], 1) del c return pc def clump(name, path, width, out_ref, thick=0.42, widest=0.40, root=0.5, point=1.7, ridge=1.35, k=10, sway=0.0, twist=0.0, role="hair"): """A solid lock along `path` ((n, 3) points, root first). width: metres at its widest. out_ref: (n, 3) vectors or one vector the ridge faces (away from the head). thick: its depth as a share of its width. sway: 0, or the share of free swing at the tip (rising from the root).""" P = np.asarray(path, float) n = len(P) T = np.gradient(P, axis=0) T /= np.linalg.norm(T, axis=1, keepdims=True) ref = np.broadcast_to(np.asarray(out_ref, float), P.shape) N = ref - T * np.einsum("ij,ij->i", ref, T)[:, None] N /= np.maximum(np.linalg.norm(N, axis=1, keepdims=True), 1e-9) Bn = np.cross(T, N) t = np.linspace(0, 1, n) grow = root + (1 - root) * np.clip(t / widest, 0, 1) ** 0.8 taper = (1 - np.clip((t - widest) / (1 - widest), 0, 1) ** point) half = width / 2 * grow * np.maximum(taper, 0.0) half[-1] = 0.0004 tw = np.radians(twist) * t G = np.zeros((n, k, 3)) xs = np.cos(np.linspace(0, np.pi, k // 2 + 1)) # across the back: +1 .. -1 top = (1 - np.abs(xs) ** ridge) under = -0.16 * (1 - xs[1:-1][::-1] ** 2) sx = np.concatenate([xs, xs[1:-1][::-1]])[:k] sy = np.concatenate([top, under])[:k] for i in range(n): ca, sa = math.cos(tw[i]), math.sin(tw[i]) b_, n_ = Bn[i] * ca + N[i] * sa, N[i] * ca - Bn[i] * sa G[i] = P[i] + np.outer(sx * half[i], b_) + np.outer(sy * half[i] * 2 * thick, n_) u = np.concatenate([np.linspace(0, 1, k // 2 + 1), np.linspace(1, 0, k - k // 2 - 1 + 2)[1:-1]])[:k] return _mesh(G, role, name, sway * t ** 1.4, u) def ponytail(fit, cut=(0.25, 0.08, 0.13), tie_role="heraldry"): """A high ponytail with a blunt fringe cut above the eyes and a lock framing each cheek. cut: the fringe's ends over each eye, between the eyes, and at the temples, in spans above the eye line.""" H = Head(fit) C, span = H.C, H.span out = [] # ---- the cap: rows from the hairline round the head to the tie ---------------------------------------------- tie_d = _dir(180.0, 44.0) tie = H.shell(tie_d, 0.004)[0] hl_az = [0, 40, 62, 80, 96, 118, 150, 180] hl_el = [20, 18, 8, -4, -6, -22, -33, -36] U, V = 72, 16 G = np.zeros((U, V, 3)) vs = np.linspace(0, 1, V) for i, az in enumerate(np.linspace(-180, 180, U, endpoint=False)): d0 = _dir(az, float(np.interp(abs(az), hl_az, hl_el))) D = _slerp(d0, tie_d, vs * 0.985) G[i] = H.shell(D, 0.0) G[i, 0] = H.skin(D[:1], 0.004)[0] # the hairline lies on the skin G[i, 1] = (H.skin(D[1:2], 0.004)[0] + H.shell(D[1:2])[0]) / 2 pos, tri = O.closed_grid_mesh(G) cap = O.piece("hair_cap", "hair", pos, tri, outward_from=C) cap["plate"] = np.stack([np.zeros(U * V), np.zeros(U * V), np.repeat(np.linspace(0, 1, U), V), np.tile(vs, U)], 1) out.append(cap) # ---- the fringe: a few clumps of different widths, cut above each eye, one lock between the eyes ------------ over_eye, centre, temple = cut y = lambda h: H.eye_y + h * span fringe = [ # root az, tip az, tip height (spans above the eye line), width (m), sweep (deg of twist) (-3, -6, centre, 0.036, 6), (15, 23, over_eye + 0.02, 0.052, -8), (-17, -27, over_eye, 0.050, 8), (33, 45, temple + 0.02, 0.044, -10), (-35, -47, temple, 0.042, 10), (7, 8, over_eye + 0.07, 0.024, 0), (-10, -15, over_eye + 0.09, 0.022, 0), (25, 34, over_eye + 0.05, 0.022, -4), (-26, -37, over_eye + 0.06, 0.020, 4)] for k, (a0, a1, h, w, tw) in enumerate(fringe): el1 = H.el_for(a1, y(h), 0.012) ctrl = [H.shell(_dir(a0 * 0.6, 74), 0.006)[0], H.shell(_dir(a0, 46), 0.008)[0], H.skin(_dir((a0 + a1) / 2, 22), 0.020)[0], H.skin(_dir(a1 * 0.97, (22 + el1) / 2), 0.017)[0], H.skin(_dir(a1, el1), 0.012)[0]] P = _spline(ctrl, 18) out.append(clump(f"hair_fringe{k}", P, w, P - C, thick=0.34, widest=0.55, root=0.55, point=2.2, twist=tw)) # ---- side locks: from the temple down in front of the ear, past the jaw --------------------------------------- chin = float(H.lm["chin"][1]) for s in (-1, 1): jaw = np.array([s * abs(H.lm["cheekR"][0]) * 0.86, chin + 0.30 * span, H.lm["gonionR"][2] - 0.012]) tip = np.array([s * abs(H.lm["cheekR"][0]) * 0.74, chin - 0.42 * span, H.lm["gonionR"][2] - 0.030]) ctrl = [H.shell(_dir(s * 50, 66), 0.006)[0], H.shell(_dir(s * 62, 36), 0.009)[0], H.skin(_dir(s * 70, 6), 0.022)[0], H.skin(_dir(s * 68, -16), 0.018)[0], jaw, tip] P = _spline(ctrl, 22) out.append(clump(f"hair_side{(s + 1) // 2}", P, 0.040, P - C + np.array([s * 0.05, 0, -0.03]), thick=0.36, widest=0.45, root=0.6, point=1.5, twist=-s * 14, sway=0.25)) tip2 = np.array([s * abs(H.lm["cheekR"][0]) * 0.80, chin + 0.62 * span, H.lm["gonionR"][2] - 0.040]) ctrl = [H.shell(_dir(s * 44, 60), 0.007)[0], H.skin(_dir(s * 56, 24), 0.021)[0], H.skin(_dir(s * 60, 2), 0.017)[0], tip2] P = _spline(ctrl, 16) out.append(clump(f"hair_cheek{(s + 1) // 2}", P, 0.026, P - C + np.array([s * 0.05, 0, -0.03]), thick=0.34, widest=0.5, root=0.6, point=1.6, twist=-s * 8, sway=0.15)) # ---- the tail: big clumps fanned in the side view, each its own arc and length --------------------------------- e_out = tie_d # out of the head at the tie e_up = np.array([0.0, 1.0, 0.0]) - e_out * e_out[1] e_up /= np.linalg.norm(e_up) e_x = np.array([1.0, 0.0, 0.0]) tails = [ # side (m at the tip), reach (how far it carries before falling), length (m), width (m), flick (0.000, 1.00, 0.50, 0.074, 0.05), (0.030, 1.22, 0.44, 0.060, 0.08), (-0.034, 0.80, 0.47, 0.062, 0.03), (0.058, 0.92, 0.36, 0.046, 0.06), (-0.060, 1.10, 0.39, 0.048, 0.07), (0.012, 1.40, 0.30, 0.036, 0.10), (-0.016, 0.62, 0.40, 0.040, 0.02)] for k, (side, reach, L, w, flick) in enumerate(tails): b = tie + e_out * 0.012 + e_x * side * 0.25 ctrl = [b, b + e_out * 0.05 * reach + e_up * 0.030 * reach, b + e_out * 0.11 * reach + e_up * 0.030 * reach + e_x * side * 0.45, b + np.array([side * 0.8, -0.30 * L, 0.0]) + e_out * 0.15 * reach, b + np.array([side, -0.66 * L, 0.0]) + e_out * (0.13 * reach + 0.01), b + np.array([side * 1.1, -L, 0.0]) + e_out * (0.12 * reach + flick)] P = _spline(ctrl, 26) out.append(clump(f"hair_tail{k}", P, w, np.array([0.0, 0.35, 1.0]), thick=0.52, widest=0.38, root=0.42, point=1.5, sway=1.0, twist=side * 260)) # the tie: a band round the tail's root, and two short ribbon ends ring = [tie + e_out * 0.020 + 0.027 * (math.cos(a) * e_x + math.sin(a) * e_up) for a in np.linspace(0, 2 * np.pi, 20)] out.append(O.pipe("hair_tie", tie_role, np.array(ring), r=0.0075, seg=8, closed=True)) for s in (-1, 1): ctrl = [tie + e_out * 0.022 - e_up * 0.020, tie + e_out * 0.05 - e_up * 0.045 + e_x * s * 0.02, tie + e_out * 0.07 + np.array([s * 0.035, -0.10, 0.0])] P = _spline(ctrl, 10) out.append(clump(f"hair_ribbon{(s + 1) // 2}", P, 0.020, np.array([0.0, 0.35, 1.0]), thick=0.12, widest=0.6, root=0.8, point=3.0, sway=0.8, role=tie_role)) for pc in out: fit.bind(pc, rigid="J_Bip_C_Head") pc["group"] = "hair" return outresult, 1 line
File created successfully at: ~/Projects/lowmarch-fable52/tools/whole/hairdo.py (file state is current in your context — no need to Read it back)
user
+51:26and the body structure too, if you need to use blender go for it, I need your absolute best
agent
+53:15reasoning
I'm reshaping her body for the frame (bigger head and eyes, longer legs, slimmer waist and neck, smaller hands) and recutting the armour, with Blender as a fallback if code can't get the proportions right. Her new hair is written, and I'm about to see it for the first time.
Bashcd ~/Projects/lowmarch-fable52 && date +%H:%M:%S && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && date +%H:%M:%S && python3 - <<'E' p="tools/whole/wren.py"; s=open(p).read() R=[("import gear as G\n","import os\n\nimport gear as G\nimport hairdo\n"), (" haircut(fit)\n"," hair = hairdo.ponytail(fit)\n"), (" under = mobs._under(shirt)\n"," if os.environ.get(\"WREN_QUICK\"): # hair and face work: skip the armour (a 10 s build)\n return out + hair\n under = mobs._under(shirt)\n"), (" out += longsword(fit)\n"," out += longsword(fit) + hair\n"), ] for a,b in R: assert a in s, a; s=s.replace(a,b,1) open(p,"w").write(s) p="tools/whole/build.py"; s=open(p).read() old=" CAST[NAME].update(shape=dict(src[\"shape\"], **wren.SHAPE), paint=dict(CAST[NAME][\"paint\"], **wren.PAINT))" new=old+"\n CAST[NAME][\"hair_trim\"] = -1 # the sample's hair is dropped: hers is built (hairdo.py)" assert old in s; open(p,"w").write(s.replace(old,new)) E mkdir -p review/out/wq && cp -r review/out/whole2/site review/out/wq/site 2>/dev/null; (time WREN_QUICK=1 LOWMARCH_SITE=wq WHOLE_DESIGN=wren OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 python3 tools/whole/build.py arm_f_slender wren) 2>&1 | grep -E "Error|Traceback|File|real|wren.glb" | tail -8result, 3 lines
19:26:13 wren.glb 2.5 MB, 14s real 0m14.270s
Bashmkdir -p ~/Projects/lowmarch-fable52/review/out/wq/shots && cd ~/Projects/lowmarch-fable52/review/out/wq/shots && cat > mk.py <<'E'
command
mkdir -p ~/Projects/lowmarch-fable52/review/out/wq/shots && cd ~/Projects/lowmarch-fable52/review/out/wq/shots && cat > mk.py <<'E' import json, subprocess, sys, os from PIL import Image R=os.path.expanduser("~/Projects/lowmarch-fable52") site=sys.argv[1] if len(sys.argv)>1 else R+"/review/out/wq/site" base=json.load(open(R+"/tools/whole/frame.json")); base.pop("key",None) pl=lambda y:{"wren":{"pos":[0,0,0],"yaw":y},"mob_soldier":{"pos":[6,0,0],"yaw":-70}} shots=[("h0",0),("h1",35),("h2",90),("h3",150),("h4",180),("h5",300)] ps=[] for n,yw in shots: s=dict(base,w=560,h=640,scale=1,place=pl(yw),clips={"wren":["ref",0]},size=0.62,centre=[0,1.50,0],pitch=4) json.dump(s,open(n+".json","w")) ps.append(subprocess.Popen([sys.executable,R+"/tools/whole/shoot.py",n+".json",n+".png"],env=dict(os.environ,WHOLE_SITE=site),stdout=subprocess.DEVNULL)) for p in ps: p.wait() W=Image.new("RGB",(560*3,640*2)) for i,(n,_) in enumerate(shots): W.paste(Image.open(n+".png"),(560*(i%3),640*(i//3))) W.save(sys.argv[2] if len(sys.argv)>2 else "hair.png") E python3 mk.pyresult, 1 line
(Bash completed with no output)
Read~/Projects/lowmarch-fable52/review/out/wq/shots/hair.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/wq/shots/hair.png" }result
no output
Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/hairdo.py"; s=open(p).read() R=[(''' hl_az = [0, 40, 62, 80, 96, 118, 150, 180] hl_el = [20, 18, 8, -4, -6, -22, -33, -36]''',''' hl_az = [0, 40, 62, 76, 90, 104, 125, 150, 180] # over the ear's top, then down behind it to the nape hl_el = [20, 18, 8, -12, -1, -16, -36, -45, -47]'''), (''' G[i] = H.shell(D, 0.0) ''',''' comb = 0.0016 * (math.sin(math.radians(az) * 11) + 0.6 * math.sin(math.radians(az) * 23 + 1.0)) * np.sin(np.pi * vs) ** 0.5 G[i] = H.shell(D, 0.0) + D * comb[:, None] # shallow comb marks running to the tie '''), ] for a,b in R: assert a in s, a[:40]; s=s.replace(a,b,1) a=s.index(" e_out = tie_d "); b=s.index(" # the tie: a band round") s=s[:a]+''' e_out = tie_d # out of the head at the tie e_up = np.array([0.0, 1.0, 0.0]) - e_out * e_out[1] e_up /= np.linalg.norm(e_up) e_x = np.array([1.0, 0.0, 0.0]) # each: side (m at the tip), reach (how far behind the head it falls), length (m), width (m), flick at the tip (m). # In the side view the tail is one mass with a few tips at different heights, not a row of equal spikes. tails = [(0.000, 1.00, 0.47, 0.128, 0.035), (0.036, 1.20, 0.40, 0.092, 0.060), (-0.040, 0.84, 0.44, 0.098, 0.020), (0.072, 0.95, 0.33, 0.062, 0.050), (-0.076, 1.06, 0.36, 0.066, 0.060), (0.014, 1.38, 0.26, 0.044, 0.090), (-0.020, 0.68, 0.39, 0.054, 0.000)] f_side = (0.12, 0.3, 0.5, 0.8, 1.0, 1.1) for k, (side, reach, L, w, flick) in enumerate(tails): b = tie + e_out * 0.014 dy = (0.0, 0.024, 0.008, -0.25 * L, -0.62 * L, -L) dz = (0.0, 0.034 * reach, 0.074 * reach, 0.104 * reach, 0.110 * reach, 0.104 * reach + flick) ctrl = [b + np.array([side * f, y_, z_]) for f, y_, z_ in zip(f_side, dy, dz)] P = _spline(ctrl, 26) out.append(clump(f"hair_tail{k}", P, w, np.array([0.0, 0.35, 1.0]), thick=0.50, widest=0.36, root=0.36, point=1.5, sway=1.0, twist=side * 260)) '''+s[b:] open(p,"w").write(s) E (WREN_QUICK=1 LOWMARCH_SITE=wq WHOLE_DESIGN=wren OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 python3 tools/whole/build.py arm_f_slender wren) 2>&1 | grep -E "Error|Traceback|File|wren.glb" | tail -5; cd review/out/wq/shots && python3 mk.pyresult, 1 line
wren.glb 2.5 MB, 10s
Read~/Projects/lowmarch-fable52/review/out/wq/shots/hair.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/wq/shots/hair.png" }result
no output
agent
+55:37reasoning
Her hair is already in a finished style, so I'm tightening the ponytail against her head, then restyling the body and recutting the armour at the waist.
Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/hairdo.py"; s=open(p).read() old=''' dz = (0.0, 0.034 * reach, 0.074 * reach, 0.104 * reach, 0.110 * reach, 0.104 * reach + flick)''' new=''' dz = (0.0, 0.030 * reach, 0.054 * reach, 0.060 * reach, 0.050 * reach, 0.046 * reach + flick) # close down the nape''' assert old in s; open(p,"w").write(s.replace(old,new)) E OMP_NUM_THREADS=1 python3 - <<'E' import sys,os sys.argv=["x"]; sys.path.insert(0,"tools/whole"); os.environ["LOWMARCH_SITE"]="whole-scratch" import importlib.util s=importlib.util.spec_from_file_location('wb','tools/whole/build.py'); wb=importlib.util.module_from_spec(s); s.loader.exec_module(wb) import numpy as np, vroid_portrait as vp, outfit from cast import CAST from plates import TorsoChart c=CAST["wren"] for shape in (c["shape"], dict(c["shape"], head=1.06, neck=0.93, leg_len=1.05, arms=0.95, hands=0.92, eye=1.08, torso=0.97)): p=vp.Portrait(wb.build.model_path("wren",c), shape=shape, costume=None, pose=vp.BUST_POSE, hair_trim=-1) fit=outfit.Fit(p.v,p.pose_ref,p.prims,p.roles) B=fit.bone P=fit.pos[np.unique(fit.tri)] H=P[:,1].max()-P[:,1].min() print("height",round(H,3),"heads",round(H/(P[:,1].max()-p.lm["chin"][1]),2), {k:round(float(B[f"J_Bip_C_{k}"][1]),3) for k in("Hips","Spine","Chest","UpperChest","Neck","Head")}, "knee",round(float(B["J_Bip_L_LowerLeg"][1]),3),"crotch?") Eresult, 2 lines
height 0.357 heads 1.61 {'Hips': 0.913, 'Spine': 0.977, 'Chest': 1.119, 'UpperChest': 1.255, 'Neck': 1.425, 'Head': 1.464} knee 0.482 crotch? height 0.375 heads 1.59 {'Hips': 0.952, 'Spine': 1.017, 'Chest': 1.159, 'UpperChest': 1.295, 'Neck': 1.464, 'Head': 1.503} knee 0.501 crotch?Bashcd ~/Projects/lowmarch-fable52 && python3 - <<'E'
command
cd ~/Projects/lowmarch-fable52 && python3 - <<'E' p="tools/whole/wren.py"; s=open(p).read() R=[('''SHAPE = dict(rest={"Fcl_BRW_Angry": 0.3})''','''SHAPE = dict(head=1.06, eye=1.08, neck=0.93, arms=0.95, hands=0.92, torso=0.97, leg_len=1.05, rest={"Fcl_BRW_Angry": 0.3})'''), (''' y_top, y_bot = float(nk[1]) - 0.062, float(hips[1]) + 0.082''',''' # it ends at the natural waist (well above the hip bone): below it a leather waist, so she has a waist y_top, y_bot = float(nk[1]) - 0.062, float(hips[1]) + 0.150'''), (''' tc = TorsoChart(under, y_bot - 0.07, y_top + 0.05, cz=cz, du=2.5, dv=0.007, smooth=(2.2, 1.8))''',''' tc = TorsoChart(under, float(hips[1]) - 0.01, y_top + 0.05, cz=cz, du=2.5, dv=0.007, smooth=(2.2, 1.8))'''), (''' front, fx = outline_plate("cuirass", "steel", tc, -98, 98, bottom, top, offset=0.015, crown=0.011, flare=ridge,''',''' front, fx = outline_plate("cuirass", "steel", tc, -98, 98, bottom, top, offset=0.012, crown=0.009, flare=ridge,'''), (''' back, bx = outline_plate("cuirass_back", "steel", tc, 98, 262, lambda u: y_bot, btop, offset=0.015, crown=0.007,''',''' back, bx = outline_plate("cuirass_back", "steel", tc, 98, 262, lambda u: y_bot, btop, offset=0.012, crown=0.006,'''), ] for a,b in R: assert a in s, a[:50]; s=s.replace(a,b,1) a=s.index(" ptop = lambda u:"); b=s.index(" plate = merge_surfaces(*[") s=s[:a]+''' # the waist: fitted leather from under the cuirass to the hips, stitched in two rows y_w0, y_w1 = float(hips[1]) + 0.030, y_bot + 0.012 waist_pc, wx = outline_plate("waist", "leather", tc, -180, 180, lambda u: y_w0, lambda u: y_w1, offset=0.0065, thickness=0.003, nu=96, nv=10, roll=0.0022, roll_edges=("bottom",), roll_role="leather", seams=[[(u, y_w0 + f * (y_w1 - y_w0)) for u in range(-180, 181, 12)] for f in (0.36, 0.68)], groove=(0.0030, 0.0012)) for pc, ex, allow, fb in ((front, fx, ("Spine", "Chest", "UpperChest", "Bust"), "J_Bip_C_Chest"), (back, bx, ("Spine", "Chest", "UpperChest", "Bust"), "J_Bip_C_Chest"), (waist_pc, wx, ("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" if pc is not waist_pc else "belt") '''+s[b:] R=[(''' plate = merge_surfaces(*[(p["pos"], p["tri"]) for p in (front, back, plack)])''',''' plate = merge_surfaces(*[(p["pos"], p["tri"]) for p in (front, back, waist_pc)])'''), (''' y_belt = float(hips[1]) + 0.058''',''' y_belt = float(hips[1]) + 0.052'''), ] for a_,b_ in R: assert a_ in s, a_[:50]; s=s.replace(a_,b_,1) open(p,"w").write(s) E grep -n "plack" tools/whole/wren.py | head; (time LOWMARCH_SITE=whole2 WHOLE_DESIGN=wren OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 python3 tools/whole/build.py arm_f_slender wren) 2>&1 | grep -E "Error|Traceback|File|line|real|wren.glb" | tail -8result, 3 lines
6: - a rigid, keeled cuirass with a pointed waist and a plackart, a gold line round it and three teal feathers wren.glb 5.4 MB, 44s real 0m44.193s
agent
+56:51Full build with the new hair, restyled body and waist-cut armour finished in 44 s. Shooting the turnaround to judge it.
Bashcd ~/Projects/lowmarch-fable52/review/out/whole2/shots && R=~/Projects/lowmarch-fable52 && for n in ref_front ref_q ref_side ref_back; do python3 - <<E
command
cd ~/Projects/lowmarch-fable52/review/out/whole2/shots && R=~/Projects/lowmarch-fable52 && for n in ref_front ref_q ref_side ref_back; do python3 - <<E import json s=json.load(open("$n.json")); s["size"]=2.05; s["centre"]=[0,0.97,0]; json.dump(s,open("$n.json","w")) E WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png >/dev/null 2>&1 & done; wait python3 -c " from PIL import Image a=[Image.open(n+'.png') for n in ('ref_front','ref_q','ref_side','ref_back')] W=Image.new('RGB',(640*4,960)); [W.paste(im,(640*i,0)) for i,im in enumerate(a)]; W.save('turn.png')"result, 4 lines
[1] Done WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1 [2] Done WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1 [3]- Done WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1 [4]+ Done WHOLE_SITE=$R/review/out/whole2/site python3 $R/tools/whole/shoot.py $n.json $n.png > /dev/null 2>&1
Read~/Projects/lowmarch-fable52/review/out/whole2/shots/turn.png
input
{ "file_path": "~/Projects/lowmarch-fable52/review/out/whole2/shots/turn.png" }result
no output
Bashdate +%H:%M:%S; ls ~/Projects/lowmarch-fable52/tools/whole/ ~/Projects/lowmarch-fable52/review/out/whole-lens/ ~/Projects/lowmarch-fable52/review/out/whole-clips/ 2>/dev/null | head -40
command
date +%H:%M:%S; ls ~/Projects/lowmarch-fable52/tools/whole/ ~/Projects/lowmarch-fable52/review/out/whole-lens/ ~/Projects/lowmarch-fable52/review/out/whole-clips/ 2>/dev/null | head -40
result, 40 lines
19:31:26 ~/Projects/lowmarch-fable52/review/out/whole-clips/: h.py k.py __pycache__ shape.pkl sheet.py shots shots.sh site t.py ~/Projects/lowmarch-fable52/review/out/whole-lens/: lens_flat1.png lens_flat.png lens_frame_castortho.json lens_frame_flat1.json lens_frame_noflat.json lens_noflat_castortho.png lens_noflat.png mob_soldier.glb model_check.png model_check_soldier.png ortho_ref.png site wren.glb ~/Projects/lowmarch-fable52/tools/whole/: build.py clips2h.py export_model.py frame.json hairdo.py lens_frame.json lens_shot.py notes patch_lens_flattice.py __pycache__ shoot.py wren.py


