A 3D model pipeline, pushed by GPT-6.2-Astra
agent (cont.)
+0:50exec_commandls -la ~/context (+3 more)
command
ls -la ~/context ls ~/.local/share/lowmarch/vroid/lowmarch_bodies | head -80 ls -la ~/.cache which chromium chromium-browser node python3 blender ls ~/context/sortie-node_modules | rg 'playwright|three' ls -la ~/.cache/ms-playwright || true rg --files ~/context /usr/share /opt -g 'three.module*.js' -g 'GLTFLoader.js' -g 'OrbitControls.js' -g 'chrome-headless-shell' -g chrome -g chromium 2>/dev/null | head -100 sed -n '1,227p' review/vroid-02/build.py && sed -n '905,1049p' tools/vroid_portrait.py sed -n '270,335p;850,1007p;1388,1486p;1687,1725p' review/vroid-02/index.html cat tools/shots/arm_shoot.py && rg -n 'def (mage|archer|soldier|bandit)|COSTUMES|def .*costume' tools/mobs.py
result, 664 lines
Script completed Wall time 0.2 seconds Output: Warning: truncated output (original token count: 10479) Total output lines: 686 total 56 drwx------ 4 runner runner 4096 Nov 17 22:44 . drwx------ 6 runner runner 4096 Nov 17 22:43 .. -rw------- 1 runner runner 3763 Nov 17 22:43 brief-lowmarch-full.md -rw------- 1 runner runner 35192 Nov 17 22:43 lowmarch.md drwx------ 2 runner runner 4096 Nov 17 22:43 reflect drwx------ 61 runner runner 4096 Oct 24 21:58 sortie-node_modules base_fem.vrm base_masc.vrm brute.vroid cage heads mass vroid_broad_v2.vrm vroid_brute.vrm vroid_stocky2.vrm vroid_stocky_v2.vrm ls: cannot access '~/.cache': No such file or directory /usr/bin/chromium-browser /opt/node/bin/node /usr/bin/python3 ~/.local/bin/blender playwright playwright-core three ls: cannot access '~/.cache/ms-playwright': No such file or directory /opt/ms-playwright/chromium-1200/chrome-linux64/chrome ~/context/sortie-node_modules/three/examples/jsm/loaders/GLTFLoader.js ~/context/sortie-node_modules/three/examples/jsm/controls/OrbitControls.js /opt/ms-playwright/chromium_headless_shell-1248/chrome-headless-shell-linux64/chrome-headless-shell /opt/ms-playwright/chromium_headless_shell-1200/chrome-headless-shell-linux64/chrome-headless-shell /opt/ms-playwright/chromium-1208/chrome-linux64/chrome ~/context/sortie-node_modules/three/build/three.module.js /opt/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell /opt/ms-playwright/chromium-1248/chrome-linux64/chrome Warning: truncated output (original token count: 5478) Total output lines: 372 """Build the model-viewer review page for the cast on stage, and their duel. python3 review/vroid-02/build.py every character, the ground and the page python3 review/vroid-02/build.py elaine just Elaine (the others stay as last built) Writes to review/out/vroid-02/site/: <name>.glb.json each character, skinned, in the reference (bust) pose, with animation clips: idle, attack, clash (the two-character sword bind) and apose (arms out, for checking a costume where hanging arms would hide it). Artifact hosting serves .json but not .glb, so the model is base64-wrapped. plains.glb.json the battle ground (static) camera.json per character: the cameras for both views plus what the live renderer needs (palette roles, lights, colliders, cloth grids); the duel's stage camera and where each fighter stands checks.json per character: the automatic checks (tools/checks.py) over every keyframe: arms through the body, and garments showing through plate and review/out/vroid-02/geom/<name>.npz (every piece as built), which tools/regress.py compares with the last published version (snapshot.py) after each build. then copies index.html next to them. The duel's poses are cached (they take about a minute to solve) and re-solved when the rig, the duel or the cast entries change. """ import base64 import hashlib import json import os import pickle import shutil import sys from concurrent.futures import ProcessPoolExecutor import numpy as np HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(os.path.dirname(HERE)) sys.path[:0] = [os.path.join(ROOT, "tools"), os.path.join(ROOT, "art", "cast"), HERE] import vroid_portrait as vp # noqa: E402 import poses as P # noqa: E402 import terrain # noqa: E402 import export_glb # noqa: E402 import clips # noqa: E402 import duel # noqa: E402 import checks # noqa: E402 from duel_check import chars_for # noqa: E402 from cast import CAST # noqa: E402 VROID = os.environ.get("LOWMARCH_VROID", os.path.expanduser("~/.local/share/lowmarch/vroid")) # which review page: the cast viewer (vroid-02), or a workshop page on a smaller roster (its own artifact) SITE = os.environ.get("LOWMARCH_SITE", "vroid-02") WORKSHOPS = { "mh-workshop": dict( title="Body workshop", eyebrow="Lowmarch · MakeHuman bodies, VRoid heads", roster=["mob_mh_youth", "mob_mh_veteran", "mob_mh_brute", "mob_mh_f_youth", "mob_mh_f_veteran", "mob_mh_f_strong"], notes=os.path.join(HERE, "mh_workshop_notes.html")), # the armory: bodies to assemble characters from, T-posed and bare (no clips, no checks): VRoid's base shaped by # MakeHuman references (art/cast/cast.py ARMORY), which are built but never shown "armory": dict( title="Armory", eyebrow="Lowmarch · VRoid bodies shaped by MakeHuman, T-posed for inspection", roster=[n for n in CAST if n.startswith("arm_")], armory=True, notes=os.path.join(HERE, "armory_notes.html")), "base-spike": dict( title="Base spike", eyebrow="Lowmarch · which base model: MakeHuman, VRoid heads, Quaternius", roster=[n for n in CAST if n.startswith("spk_")], notes=os.path.join(HERE, "base_spike_notes.html")), } WORKSHOP_ONLY = {n for w in WORKSHOPS.values() for n in w["roster"]} - {"mob_mh_youth", "mob_mh_veteran", "mob_mh_brute"} OUT = os.path.join(ROOT, "review", "out", SITE, "site") CACHE = os.path.join(ROOT, "review", "out", "vroid-02", "cache") GEOM = os.path.join(ROOT, "review", "out", "vroid-02", "geom") # per-piece geometry of the last build ORDER = {"player": "aldric", "opponent": "elaine"} # the armory's skin picker (cast.SKINS): people light to deep, then fantasy SKIN_PICKER = [("People", [("porcelain", "Porcelain"), ("ivory", "Ivory"), ("peach", "Peach"), ("sand", "Sand"), ("honey", "Honey"), ("olive_mid", "Olive"), ("amber", "Amber"), ("caramel", "Caramel"), ("chestnut", "Chestnut"), ("umber", "Umber"), ("mahogany", "Mahogany"), ("ebony", "Ebony")]), ("Fantasy", [("drow_ash", "Dark elf, ash"), ("drow_slate", "Dark elf, slate"), ("ashen", "Ashen"), ("orc", "Orc"), ("orc_deep", "Orc, deep"), ("sea", "Sea"), ("infernal", "Infernal")])] LABELS = {"aldric": "Aldric", "elaine": "Elaine", "saber": "Saber (study)"} # saber: a benchmark, not for the game MOBS = [k for k in CAST if k.startswith("mob_") and k not in WORKSHOP_ONLY] # common enemies: built, stood in the lineup # MakeHuman-based units stand first, next to the VRoid soldier they are compared with MOBS = sorted(MOBS, key=lambda k: (0 if k == "mob_soldier" else 1 if CAST[k].get("mh") else 2)) LABELS.update({k: CAST[k].get("label", k[4:].title()) for k in MOBS}) if SITE in WORKSHOPS: # a workshop page: only its roster, in its order, no duel MOBS = list(WORKSHOPS[SITE]["roster"]) LABELS = {k: CAST[k].get("label", k[4:].title()) for k in MOBS} # arms raised 35 degrees from the T-pose: shows the waist, the sides and the armpits APOSE = P.merge(P.BUST, {"J_Bip_L_UpperArm": P.rot((0, 0, 1), -37), "J_Bip_R_UpperArm": P.rot((0, 0, 1), 37), "J_Bip_L_Shoulder": P.rot((0, 0, 1), -6), "J_Bip_R_Shoulder": P.rot((0, 0, 1), 6)}) def costume_of(c): """The cast entry's costume, plus kit hair (hair_style) and facial hair (beard: a style, or (style, length)) if it has them.""" import outfit import hair base = outfit.COSTUMES[c.get("costume") or "lord"] extra = [] if c.get("hair_style"): extra.append(lambda fit: getattr(hair, c["hair_style"])(fit)) if c.get("beard"): style, length = (c["beard"], 0.0) if isinstance(c["beard"], str) else c["beard"] extra.append(lambda fit: hair.beard(fit, style, length=length)) if not extra: return base return lambda fit: base(fit) + [pc for f in extra for pc in f(fit)] def model_path(name, c): """A VRoid model under LOWMARCH_VROID, or a converted MakeHuman or Quaternius body, or a reshaped VRoid one (tools/makehuman.py, tools/quaternius.py, tools/mass.py, tools/cage.py, run first with `python3 -I`: they read downloaded data).""" if c.get("mass"): import mass p = mass.path_for(name, c["mass"]) if not os.path.exists(p): raise SystemExit(f"{name}: no massed VRoid body; run python3 -I tools/mass.py first") return p if c.get("cage"): import cage p = cage.path_for(name, c["cage"]) if not os.path.exists(p): raise SystemExit(f"{name}: no cage body; run python3 -I tools/cage.py first") return p if c.get("qt"): import quaternius p = quaternius.path_for(name, c["qt"]) if not os.path.exists(p): raise SystemExit(f"{name}: no converted Quaternius body; run python3 -I tools/quaternius.py first") return p if not c.get("mh"): return os.path.join(VROID, c["model"]) import makehuman p = makehuman.path_for(name, c["mh"]) if not os.path.exists(p): raise SystemExit(f"{name}: no converted MakeHuman body; run python3 -I tools/makehuman.py first") return p def arm_room(name, c, need=0.006, most=16): """The smallest outward arm angle (degrees, shape["arm_out"]) at which the hanging arms clear the body by `need` in the reference pose and the idle: broad bodies otherwise sink their arms into their sides. MakeHuman bodies only for now (the VRoid cast was posed by hand).""" import checks from vrm import VRM v = VRM(model_path(name, c)) limbs = [f"{s}_{a}" for s in "LR" for a in ("UpperArm", "LowerArm")] for deg in range(0, most + 1, 2): b = checks.Body(v, dict(c["shape"], arm_out=float(deg))) if min(b.worst(pose, limbs) for pose in (P.BUST, P.BATTLE_IDLE)) >= need: return float(deg) return float(most) ARMORY = bool(WORKSHOPS.get(SITE, {}).get("armory")) # T-posed and bare: the reference pose is the T-pose def portrait(name, view): c = CAST[name] if (c.get("mh") or c.get("qt") or c.get("mass") or c.get("cage")) and "arm_out" not in c["shape"] and not ARMORY: c["shape"]["arm_out"] = arm_room(name, c) return vp.Portrait(model_path(name, c), shape=c["shape"], hair_from=os.path.join(VROID, c["hair"]) if c.get("hair") else None, costume=costume_of(c), pose={} if ARMORY else vp.BUST_POSE, hair_trim=c.get("hair_trim"), world=terrain.plains() if view == "battle" else None), c def springs(v): """The model's spring bones (VRM 0.x secondaryAnimation: VRoid's women's base has its breasts', a hairstyle its hair's, tools/heads.py): each group's root bones, settings and collision spheres (on a bone, offset in its own frame, before the export's turn), for the viewer's physics.""" sa = v.j.get("extensions", {}).get("VRM", {}).get("secondaryAnimation", {}) nodes = v.j["nodes"] spheres = [[dict(bone=nodes[cg["node"]]["name"], offset=[c["offset"]["x"], c["offset"]["y"], c["offset"]["z"]], radius=c["radius"]) for c in cg.get("colliders", [])] for cg in sa.get("colliderGroups", [])] out = [] for g in sa.get("boneGroups", []): gd = g.get("gravityDir", {"x": 0, "y": -1, "z": 0}) out.append(dict(bones=[nodes[b]["name"] for b in g["bones"]], stiffness=g.get("stiffiness", 1.0), gravity=g.get("gravityPower", 0.0), gravity_dir=[gd["x"], gd["y"], gd["z"]], drag=g.get("dragForce", 0.4), radius=g.get("hitRadius", 0.02), comment=g.get("comment", ""), colliders=[c for k in g.get("colliderGroups", []) if k < len(spheres) for c in spheres[k]])) return out def wrap_json(path): json.dump({"glb": base64.b64encode(open(path, "rb").read()).decode()}, open(path + ".json", "w")) os.remove(path) def character(args): """The rigged character (reference pose) with its clips, its cameras, the live renderer's data and its checks.""" name, clash = args p, c = portrait(name, "bust") p.paint = c.get("paint") pal = dict(vp.PALETTE, **c["colors"]) cam_bust, cam_battle = p.frame("bust"), p.frame("battle") if ARMORY: # nothing moves: every clip holds the T-pose cl = {k: [(0.0, {}), (1.0, {})] for k in ("idle", "attack", "apose")} else: cl = clips.clips(p.v, c["shape"], c.get("stance", "sword")) if clash: cl["clash"] = clash cl["ap…78 tokens truncated…t(name=name, size=size, cams=dict(bust=cam_bust, battle=cam_battle), info=dict(export_glb.scene_info(p, pal), springs=springs(p.v)), checks=proportion_checks(name, c)) body = checks.Body(p.v, c["shape"]) keyed = {k: v for k, v in cl.items() if k != "apose"} head, bad, touch = checks.report(name, keyed, body) layers = checks.layer_report(name, keyed, checks.Layers(p, body)) return dict(name=name, size=size, cams=dict(bust=cam_bust, battle=cam_battle), info=export_glb.scene_info(p, pal), checks=dict(summary=head, through=bad, touching=touch, layers=layers)) def save_geometry(name, p): """Every piece's vertices as built (reference pose), for tools/regress.py to compare builds.""" os.makedirs(GEOM, exist_ok=True) arrays, seen = {}, {} for q in p.prims: key = q["material"] seen[key] = seen.get(key, 0) + 1 if seen[key] > 1: key = f"{key}#{seen[key]}" arrays[key] = q["pos"][np.unique(q["tri"])].astype(np.float32) if len(q["tri"]) else q["pos"].astype(np.float32) class Portrait: def __init__(self, path, morphs=None, pose=BUST_POSE, shape=None, hair_from=None, costume=None, mouth="curve", world=None, ref_pose=BUST_POSE, hair_trim=None): """mouth: how the closed mouth is drawn. 'texture' = VRoid's painted lip line, thickened; 'texture+lip' = that plus a lower-lip shade; 'drawn' = an FE8-style mouth between the projected mouth corners; 'none' = geometry only (the line disappears when closed).""" self.mouth = mouth self.v = VRM(path) sh = dict(NEUTRAL, **(shape or {})) mo = dict(sh["rest"]) for k_, w_ in (morphs or {}).items(): mo[k_] = min(1.0, mo.get(k_, 0.0) + w_) if sh["fangs"] < 1.0: # some faces' teeth have fangs (sample V's); 0 files them away mo["Fcl_HA_Short"] = max(mo.get("Fcl_HA_Short", 0.0), 1.0 - sh["fangs"]) # everything is built in the reference pose (arms down), then posed through the skeleton target_pose = bone_pose(self.v, sh, pose) pose = bone_pose(self.v, sh, ref_pose) mo, self.mouth_hold = hold_mouth(self.v, mo, pose) closure = eye_closure(mo) lines = None if max(closure.values()) > 0.05 or sh["lash"] != 1.0: # the eyeline open, and how far a shut eye must close eyes = {k_: w_ for k_, w_ in mo.items() if "EYE_" not in k_ and "ALL_" not in k_} now = self.v.primitives(mo, pose) ln = [i_ for i_, p_ in enumerate(now) if "FaceEyeline" in p_["material"]] if ln: prs = [self.v.primitives(eyes, pose)[ln[0]], now[ln[0]], self.v.primitives(dict(eyes, Fcl_EYE_Close=1.0), pose)[ln[0]]] eye = eye_lines(prs[0]) # the character's one lash size: set on the open lash, which every closed lid is moved from lines = (ln[0], lash_size(prs[0]["pos"].copy(), prs[0]["uv"], eye, sh["lash"]), eye, now) further = lid_gap(prs[1]["pos"], prs[2]["pos"], prs[0]["pos"], lines[2], prs[0]["uv"], prs[0]["tri"], self.v.material_texture(prs[0]["mi"])) mo = hide_closed_irises(mo, further if lines else None) self.pose_now = target_pose self.pose_ref = pose self.shape = sh self.prims = self.v.primitives(mo, pose) if lines: # a closing lid is the model's own open lash, moved k_, P_open, eye, now = lines p_ = self.prims[k_] keep_lash_weight(p_, P_open, p_["uv"], eye, closure) lash_size(p_["pos"], p_["uv"], {s_: v_ for s_, v_ in eye.items() if closure[s_] <= 0.05}, sh["lash"]) keep_lash_fan(self.prims, now, k_, eye, closure) for side, (up, others, edge, _) in eye.items(): # a shut eye is one closed lid: if closure[side] < 0.9: continue if others: # its lower line goes, p_["tri"] = p_["tri"][~np.isin(p_["tri"], np.concatenate(others)).all(1)] m = np.isin(p_["tri"], up).all(1) # and its lash is drawn solid (export_glb.fill_lid): self.prims.append(dict(p_, tri=p_["tri"][m], lid_fill=float(p_["uv"][edge, 1].max()))) p_["tri"] = p_["tri"][~m] # the open lash's pale streaks and hollows read as # shine beside an eye, but split a lid over skin if hair_from: # swap in another model's hair hv = VRM(hair_from) hp = hv.primitives(None, ref_pose) hroles = [role_of(p["material"]) for p in hp] src = landmarks(hp, hroles) dst = landmarks(self.prims, [role_of(p["material"]) for p in self.prims]) k = (abs(dst["eyeR"][0] - dst["eyeL"][0]) / abs(src["eyeR"][0] - src["eyeL"][0]) + (dst["eye_y"] - dst["chin"][1]) / (src["eye_y"] - src["chin"][1])) / 2 c_src = (src["eyeL"] + src["eyeR"]) / 2 c_dst = (dst["eyeL"] + dst["eyeR"]) / 2 hair = [p for p in hp if "_HAIR" in p["material"]] for p in hair: p["pos"] = c_dst + (p["pos"] - c_src) * k n_ = len(p["pos"]) # rides our head bone from here on p["J"], p["W"], p["jnames"] = np.zeros((n_, 4), np.int64), np.tile([1.0, 0, 0, 0], (n_, 1)), ["J_Bip_C_Head"] self.prims = [p for p in self.prims if "_HAIR" not in p["material"]] + hair self._hair_v = hv if hair_trim: # drop hair pieces reaching past |x| = hair_trim (e.g. twin tails) self.prims = [p for p in self.prims if "_HAIR" not in p["material"] or np.abs(p["pos"][np.unique(p["tri"]), 0]).max() <= hair_trim] self.roles = [p.get("role") or role_of(p["material"]) for p in self.prims] for side, c in eye_closure(mo).items(): # a shut eye shows no white (it can poke between the lids) if c < 0.9: continue for p, r in zip(self.prims, self.roles): if r == "white" and len(p["tri"]): cx = p["pos"][p["tri"]].mean(1)[:, 0] p["tri"] = p["tri"][(cx < 0) != (side == "L")] self.lm = landmarks(self.prims, self.roles) if costume: # replace VRoid's clothes with ours import outfit fit = outfit.Fit(self.v, pose, self.prims, self.roles) import rig fit.grip = rig.grip_points(self.v, sh, ref_pose) # where each fist closes (weapons sit there) keep_ = [k for k, r in enumerate(self.roles) if r != "cloth"] self.prims = [self.prims[k] for k in keep_] self.roles = [self.roles[k] for k in keep_] costume = outfit.COSTUMES[costume] if isinstance(costume, str) else costume fit.keep_skin = () # a costume may leave skin bare (fit.keep_skin = bones) for pc in costume(fit): self.prims.append(pc) self.roles.append(pc["role"]) # body skin below the neck is always under clothes in a bust; drop it so it can't poke through cy = self.lm["chin"][1] from vrm import bone_weight for p, r i…479 tokens truncated… if pose is not target_pose and any(not np.allclose(pose.get(k_, np.eye(4)), target_pose.get(k_, np.eye(4))) for k_ in set(pose) | set(target_pose)): repose(self.v, [p for p in self.prims if not p.get("world")], pose, target_pose) names = self.v.nodes_by_name() Wn = self.v.node_world() self.eye = (Wn[names["J_Adj_L_FaceEye"]][:3, 3] + Wn[names["J_Adj_R_FaceEye"]][:3, 3]) / 2 self.chin_y = self.lm["chin"][1] self.tex = {} for k, p in enumerate(self.prims): if self.roles[k] in ("line", "brow", "iris", "highlight", "white", "hair", "mouth"): src = self._hair_v if (hair_from and "_HAIR" in p["material"]) else self.v t = src.material_texture(p["mi"]) if t is not None and self.roles[k] == "line": # VRoid's upper lid is a thick graded band over the iris; keep its dark core only t = t.copy() t[..., 3] = np.where(t[..., :3].mean(-1) < LID_CORE, t[..., 3], 0) if t is not None: self.tex[k] = t # painted face marks (lip line, nose) from the face texture, grown so they survive the vote Warning: truncated output (original token count: 6128) Total output lines: 362 const og = document.createElement("optgroup"); og.label = g; PAGE.skins.filter(s => s.group === g).forEach(s => og.append(new Option(s.label, s.name))); sel.append(og); } if (PAGE.skins.some(s => s.name === params.get("skin"))) state.skin = params.get("skin"); // ?skin=<tone> sel.value = state.skin || ""; sel.hidden = false; sel.addEventListener("change", () => { state.skin = sel.value; }); } if (["still", "bounce", "twist"].includes(params.get("motion"))) state.motion = params.get("motion"); state.compare = (params.get("compare") || "").split(",").filter(n => charDef(n)).slice(0, MAX_COMPARE); if (!state.compare.length) state.compare = CAM.characters.slice(0, 2).map(c => c.name); if (["up", "out", "down"].includes(params.get("pose"))) state.pose = params.get("pose"); }264 more lines not shown.