A 3D model pipeline, pushed by GPT-6-Astra
agent (cont.)
+21:14exec_commandsed -n '155,250p' tools/vroid_portrait.py; sed -n '906,1045p' tools/vroid_portrait.py; sed -n '1,110p' tools/outfit.py; sed -n '163,250p' tools/outfit.py; sed -n '460,660p' tools/export_glb.py (+1 more)
command
sed -n '155,250p' tools/vroid_portrait.py; sed -n '906,1045p' tools/vroid_portrait.py; sed -n '1,110p' tools/outfit.py; sed -n '163,250p' tools/outfit.py; sed -n '460,660p' tools/export_glb.py mkdir -p review/astra-finish review/out/astra-finish/site; cp ~/out/index.html review/astra-finish/first-pass.html; cp ~/out/warden.png ~/out/warden-before.png; cp ~/.local/share/lowmarch/trials/face-shading-2026-10-30/scripts/patch_lens_flattice.py review/astra-finish/patch_lens_flattice.py; cat > review/astra-finish/timing.json <<'EOF' {"started":"2026-11-15T03:34:07Z","steps":[],"note":"Wall time includes inspection, design, coding and render iterations; subprocess times logged separately."} EOF ls ~/.local/opt/blender-5.2.3-linux-x64/blender; sed -n '1,170p' tools/mobs.py; rg -n 'strands|baseColorFactor|paint' tools/export_glb.pyresult, 8 lines
Script completed Wall time 0.2 seconds Output: Warning: truncated output (original token count: 11319) Total output lines: 2 {"chunk_id":"60e733","wall_time_seconds":0.00000572,"exit_code":0,"original_token_count":7774,"output":"\n\n# Archetype shape controls, in three layers (0 / 1 / {} = unchanged):\n# 1. proportions through the skeleton: bone scales, the way VRoid varies builds\n# 2. face sculpting: anatomical points move, anchors (eyes, ears, skull, neck) hold still, and a\n# smooth RBF field fills in between\n# 3. resting expression: VRoid's own shapes (hooded eyes, stern brows) held at a low weight\nNEUTRAL = dict(head=1.0, neck=1.0, chest=1.0, height=1.0,\n shoulders=1.0, arms=1.0, torso=1.0, legs=1.0, leg_len=1.0, hands=1.0, shoulder_w=0.0,\n face_len=0.0, jaw=0.0, chin_w=0.0, chin_len=0.0, cheek=0.0, brow_ridge=0.0,\n nose=0.0, nose_w=0.0,\n eye=1.0, eye_tilt=0.0, iris=1.0, lash=1.0, mouth=1.0, arm_out=0.0, age_lines=0.0, blush=1.0, curl=0.0,\n face_normals=1.0, hair_normals=0.0, shadow_cards=1.0, fangs=1.0, rest={})\n# hair is reshaped with the face: beards (built on the face before the face is sculpted) and side locks\n# must follow a wider jaw or a longer chin, or the skin comes through them\nSCULPT_ROLES = (\"face\", \"body\", \"mouth\", \"brow\", \"line\", \"white\", \"iris\", \"highlight\", \"hair\")\n\n\ndef bone_pose(v, sh, base_pose):\n \"\"\"Pose dict (bone -> 3x3) = base rotations combined with proportion scales. Each scaled bone\n resets its children to scale 1 except the head, whose children (hair bones) grow with it.\"\"\"\n # Body proportions (all 1.0 = VRoid's): shoulders lengthens the clavicles (wider shoulders), arms\n # and legs thicken the limbs, torso broadens the waist-to-chest, leg_len lengthens thigh and shin\n # (the hips are lifted to keep the feet on the ground), hands scales the hands.\n a, lg, t = sh[\"arms\"], sh[\"legs\"], sh[\"torso\"]\n spec = {\"J_Bip_C_Head\": ((sh[\"head\"],) * 3, True),\n \"J_Bip_C_Neck\": ((sh[\"neck\"], 1.0, sh[\"neck\"]), False),\n \"J_Bip_C_UpperChest\": ((sh[\"chest\"], 1.0, 1 + (sh[\"chest\"] - 1) * 0.6), False),\n \"J_Bip_C_Spine\": ((1 + (t - 1) * 0.7, 1.0, 1 + (t - 1) * 0.5), False),\n \"J_Bip_C_Chest\": ((t, 1.0, 1 + (t - 1) * 0.7), False)}\n for side in \"LR\":\n spec[f\"J_Bip_{side}_Shoulder\"] = ((sh[\"shoulders\"], 1.0, 1.0), False)\n for b in (\"UpperArm\", \"LowerArm\"):\n spec[f\"J_Bip_{side}_{b}\"] = ((1.0, a, a), False) # arm bones run along x\n for b in (\"UpperLeg\", \"LowerLeg\"):\n spec[f\"J_Bip_{side}_{b}\"] = ((lg, sh[\"leg_len\"], lg), False) # leg bones run along y\n spec[f\"J_Bip_{side}_Hand\"] = ((sh[\"hands\"],) * 3, True)\n spec = {k: v for k, v in spec.items() if not np.allclose(v[0], 1.0)}\n nodes = v.j[\"nodes\"]\n parent = {c: i for i, n in enumerate(nodes) for c in n.get(\"children\", [])}\n own = {}\n\n def own_of(i):\n if i in own:\n return own[i]\n nm = nodes[i].get(\"name\")\n if nm in spec:\n own[i] = np.array(spec[nm][0], float)\n elif i in parent and nodes[parent[i]].get(\"name\") in spec and spec[nodes[parent[i]][\"name\"]][1]:\n own[i] = own_of(parent[i])\n elif i in parent and (own_of(parent[i]) != 1).any() and nodes[parent[i]].get(\"name\") not in spec:\n own[i] = own_of(parent[i]) # inherited chain (below the head)\n else:\n own[i] = np.ones(3)\n return own[i]\n\n def as4(r):\n r = np.asarray(r, float)\n if r.shape == (4, 4):\n return r\n m = np.eye(4)\n m[:3, :3] = r\n return m\n pose = {k: as4(r) for k, r in base_pose.items()}\n for i, n in enumerate(nodes):\n nm = n.get(\"name\")\n if not nm:\n continue\n mine = own_of(i)\n par = own_of(parent[i]) if i in parent else np.ones(3)\n adj = mine / par\n if np.allclose(adj, 1):\n continue\n pose[nm] = pose.get(nm, np.eye(4)) @ np.diag(list(adj) + [1.0])\n if sh[\"shoulder_w\"]: # wider shoulders by moving the arm joints out (no shear, unlike\n for side, sx in ((\"L\", -1.0), (\"R\", 1.0)): # `shoulders`, which scales the clavicle and skews a turned arm)\n mv = np.eye(4)\n mv[0, 3] = sx * sh[\"shoulder_w\"]\n nm = f\"J_Bip_{side}_UpperArm\"\n pose[nm] = mv @ pose.get(nm, np.eye(4))\n if sh.get(\"curl\"): # relaxed hands (degrees per finger joint) wherever the pose\n for side, sg in ((\"L\", 1.0), (\"R\", -1.0)): # leaves the fingers alone: an open hand reads as a paddle\n for f in (\"Index\", \"Middle\", \"Ring\", \"Little\"):\n for j, kf in ((1, 0.6), (2, 1.0), (3, 0.8)):\n nm = f\"J_Bip_{side}_{f}{j}\"\n if nm in base_pose:\n continue\n a = np.radians(sg * sh[\"curl\"] * kf * (1.0 + 0.12 * (\"Index\", \"Middle\", \"Ring\", \"Little\").index(f)))\n r = np.eye(4)\n r[:2, :2] = [[np.cos(a), -np.sin(a)], [np.sin(a), np.cos(a)]]\n pose[nm] = pose.get(nm, np.eye(4)) @ r\n if sh.get(\"arm_out\"): # arms held further from the body (degrees): a broad torso\n for side, sg in ((\"L\", -1.0), (\"R\", 1.0)): # needs room for hanging arms\n a = np.radians(sg * sh[\"arm_out\"])\n r = np.eye(4)\n r[:2, :2] = [[np.cos(a), -np.sin(a)], [np.sin(a), np.cos(a)]]\n def __init__(self, path, morphs=None, pose=BUST_POSE, shape=None, hair_from=None, costume=None,\n mouth=\"curve\", world=None, ref_pose=BUST_POSE, hair_trim=None):\n \"\"\"mouth: how the closed mouth is drawn. 'texture' = VRoid's painted lip line, thickened;\n 'texture+lip' = that plus a lower-lip shade; 'drawn' = an FE8-style mouth between the\n projected mouth corners; 'none' = geometry only (the line disappears when closed).\"\"\"\n self.mouth = mouth\n self.v = VRM(path)\n sh = dict(NEUTRAL, **(shape or {}))\n mo = dict(sh[\"rest\"])\n for k_, w_ in (morphs or {}).items():\n mo[k_] = min(1.0, mo.get(k_, 0.0) + w_)\n if sh[\"fangs\"] < 1.0: # some faces' teeth have fangs (sample V's); 0 files them away\n mo[\"Fcl_HA_Short\"] = max(mo.get(\"Fcl_HA_Short\", 0.0), 1.0 - sh[\"fangs\"])\n # everything is built in the reference pose (arms down), then posed through the skeleton\n target_pose = bone_pose(self.v, sh, pose)\n pose = bone_pose(self.v, sh, ref_pose)\n mo, self.mouth_hold = hold_mouth(self.v, mo, pose)\n closure = eye_closure(mo)\n lines = None\n if max(closure.values()) > 0.05 or sh[\"lash\"] != 1.0: # the eyeline open, and how far a shut eye must close\n eyes = {k_: w_ for k_, w_ in mo.items() if \"EYE_\" not in k_ and \"ALL_\" not in k_}\n now = self.v.primitives(mo, pose)\n ln = [i_ for i_, p_ in enumerate(now) if \"FaceEyeline\" in p_[\"material\"]]\n if ln:\n prs = [self.v.primitives(eyes, pose)[ln[0]], now[ln[0]],\n self.v.primitives(dict(eyes, Fcl_EYE_Close=1.0), pose)[ln[0]]]\n eye = eye_lines(prs[0])\n # the character's one lash size: set on the open lash, which every closed lid is moved from\n lines = (ln[0], lash_size(prs[0][\"pos\"].copy(), prs[0][\"uv\"], eye, sh[\"lash\"]), eye, now)\n further = lid_gap(prs[1][\"pos\"], prs[2][\"pos\"], prs[0][\"pos\"], lines[2], prs[0][\"uv\"], prs[0][\"tri\"],\n self.v.material_texture(prs[0][\"mi\"]))\n mo = hide_closed_irises(mo, further if lines else None)\n self.pose_now = target_pose\n self.pose_ref = pose\n self.shape = sh\n self.prims = self.v.primitives(mo, pose)\n if lines: # a closing lid is the model's own open lash, moved\n k_, P_open, eye, now = lines\n p_ = self.prims[k_]\n keep_lash_weight(p_, P_open, p_[\"uv\"], eye, closure)\n lash_size(p_[\"pos\"], p_[\"uv\"], {s_: v_ for s_, v_ in eye.items() if closure[s_] <= 0.05}, sh[\"lash\"])\n keep_lash_fan(self.prims, now, k_, eye, closure)\n for side, (up, others, edge, _) in eye.items(): # a shut eye is one closed lid:\n if closure[side] < 0.9:\n continue\n if others: # its lower line goes,\n p_[\"tri\"] = p_[\"tri\"][~np.isin(p_[\"tri\"], np.concatenate(others)).all(1)]\n m = np.isin(p_[\"tri\"], up).all(1) # and its lash is drawn solid (export_glb.fill_lid):\n self.prims.append(dict(p_, tri=p_[\"tri\"][m], lid_fill=float(p_[\"uv\"][edge, 1].max())))\n p_[\"tri\"] = p_[\"tri\"][~m] # the open lash's pale streaks and hollows read as\n # shine beside an eye, but split a lid over skin\n if hair_from: # swap in another model's hair\n hv = VRM(hair_from)\n hp = hv.primitives(None, ref_pose)\n hroles = [role_of(p[\"material\"]) for p in hp]\n src = landmarks(hp, hroles)\n dst = landmarks(self.prims, [role_of(p[\"material\"]) for p in self.prims])\n k = (abs(dst[\"eyeR\"][0] - dst[\"eyeL\"][0]) / abs(src[\"eyeR\"][0] - src[\"eyeL\"][0])\n + (dst[\"eye_y\"] - dst[\"chin\"][1]) / (src[\"eye_y\"] - src[\"chin\"][1])) / 2\n c_src = (src[\"eyeL\"] + src[\"eyeR\"]) / 2\n c_dst = (dst[\"eyeL\"] + dst[\"eyeR\"]) / 2\n hair = [p for p in hp if \"_HAIR\" in p[\"material\"]]\n for p in hair:\n p[\"pos\"] = c_dst + (p[\"pos\"] - c_src) * k\n n_ = len(p[\"pos\"]) # rides our head bone from here on\n 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\"]\n self.prims = [p for p in self.prims if \"_HAIR\" not in p[\"material\"]] + hair\n self._hair_v = hv\n if hair_trim: # drop hair pieces reaching past |x| = hair_trim (e.g. twin tails)\n self.prims = [p for p in self.prims if \"_HAIR\" not in p[\"material\"]\n or np.abs(p[\"pos\"][np.unique(p[\"tri\"]), 0]).max() <= hair_trim]\n self.roles = [p.get(\"role\") or role_of(p[\"material\"]) for p in self.prims]\n for side, c in eye_closure(mo).items(): # a shut eye shows no white (it can poke between the lids)\n if c < 0.9:\n continue\n for p, r in zip(self.prims, self.roles):\n if r == \"white\" and len(p[\"tri\"]):\n cx = p[\"pos\"][p[\"tri\"]].mean(1)[:, 0]\n p[\"tri\"] = p[\"tri\"][(cx < 0) != (side == \"L\")]\n self.lm = landmarks(self.prims, self.roles)\n if costume: # replace VRoid's clothes with ours\n import outfit\n fit = outfit.Fit(self.v, pose, self.prims, self.roles)\n import rig\n fit.grip = rig.grip_points(self.v, sh, ref_pose) # where each fist closes (weapons sit there)\n keep_ = [k for k, r in enumerate(self.roles) if r != \"cloth\"]\n self.prims = [self.prims[k] for k in keep_]\n self.roles = [self.roles[k] for k in keep_]\n costume = outfit.COSTUMES[costume] if isinstance(costume, str) else costume\n fit.keep_skin = () # a costume may leave skin bare (fit.keep_skin = bones)\n for pc in costume(fit):\n self.prims.append(pc)\n self.roles.append(pc[\"role\"])\n # body skin below the neck is always under clothes in a bust; drop it so it can't poke through\n cy = self.lm[\"chin\"][1]\n from vrm import bone_weight\n for p, r in zip(self.prims, self.roles):\n if r != \"body\":\n continue\n if costume: # keep head, neck and upper chest (the throat shows in the collar opening)\n wv = bone_weight(p, (\"Head\", \"Neck\", \"UpperChest\") + tuple(getattr(fit, \"keep_skin\", ())))\n p[\"tri\"] = p[\"tri\"][(wv[p[\"tri\"]] >= 0.5).all(1)]\n if getattr(fit, \"drop_skin\", None) is not None: # a costume may hide the skin it covers\n p[\"tri\"] = p[\"tri\"][~fit.drop_skin(p)[p[\"tri\"]].all(1)]\n else:\n T = p[\"pos\"][p[\"tri\"]]\n head = T[:, :, 1].min(1) > cy - 0.02\n neck = (T[:, :, 1].min(1) > cy - 0.14) & (np.abs(T[:, :, 0]).max(1) < 0.055)\n p[\"tri\"] = p[\"tri\"][head | neck]\n for pc in world or []: # scenery: does not turn with the character\n self.prims.append(pc)\n self.roles.append(pc[\"role\"])\n # framing uses the unshaped face at the base head size, so head-size changes still show\n self.span = (self.lm[\"eye_y\"] - self.lm[\"chin\"][1]) / sh[\"head\"]\n reshape(self.prims, self.roles, self.lm, sh)\n strip_blush(self.prims, self.roles, self.v, sh[\"blush\"])\n face_lines(self.prims, self.roles, self.v, sh[\"age_lines\"])\n lm_now = landmarks(self.prims, self.roles) # after the sculpt\n names, Wn = self.v.nodes_by_name(), self.v.node_world(pose)\n neck = (Wn[names[\"J_Bip_C_Neck\"]][:3, 3], Wn[names[\"J_Bip_C_Head\"]][:3, 3]) \\\n if \"J_Bip_C_Neck\" in names and \"J_Bip_C_Head\" in names else None\n face_normals(self.prims, self.roles, lm_now, sh[\"face_normals\"], sh[\"hair_normals\"], neck=neck)\n for pc, rl in shadow_cards(self.prims, self.roles, lm_now, sh[\"shadow_cards\"], neck):\n self.prims.append(pc)\n self.roles.append(rl)\n if pose is not target_pose and any(not np.allclose(pose.get(k_, np.eye(4)), target_pose.get(k_, np.eye(4)))\n for k_ in set(pose) | set(target_pose)):\n repose(self.v, [p for p in self.prims if not p.get(\"world\")], pose, target_pose)\n names = self.v.nodes_by_name()\n Wn = self.v.node_world()\n self.eye = (Wn[names[\"J_Adj_L_FaceEye\"]][:3, 3] + Wn[names[\"J_Adj_R_FaceEye\"]][:3, 3]) / 2\n self.chin_y = self.lm[\"chin\"][1]\n self.tex = {}\n for k, p in enumerate(self.prims):\n if self.roles[k] in (\"line\", \"brow\", \"iris\", \"highlight\", \"white\", \"hair\", \"mouth\"):\n src = self._hair_v if (hair_from and \"_HAIR\" in p[\"material\"]) else self.v\n t = src.material_texture(p[\"mi\"])\n if t is not None and self.roles[k] == \"line\":\n # VRoid's upper lid is a thick graded band over the iris; keep its dark core only\n t = t.copy()\n\"\"\"Fantasy costume pieces, generated in code and fitted onto a VRoid body.\n\nCoordinates are the model's (metres, y up, the character faces -z, its left is -x). Pieces are\nbuilt once in the reference pose (the bust pose, arms down) and carry skin weights (J, W, jnames)\nso the renderer can pose them with the body through the skeleton: soft layers copy the weights of\nthe body under them, hard parts ride one bone.\n\nKinds of piece (see docs/portrait-guide.md lesson 07 for the measurements behind the offsets):\n\n wrap a garment shrink-wrapped onto a body region chosen by bones (tunic, trousers, boots,\n gloves): seams welded, smoothed without shrinking, every vertex set at an offset\n collar a standing collar fitted to the neck by ray casts, rising toward the back\n pauldron three overlapping lames whose shape comes from ray casts to what they cover\n drape cloth (cape, tunic tails) settled by a small cloth simulation against the body\n belt a band around the waist on top of the tunic\n trim a band along a piece's edge (gold trim, piping), lifted off its surface\n props sword and hardware built from boxes, tubes and balls\n\nA costume is a function of a Fit (body + bones in the reference pose) returning a list of pieces.\n\"\"\"\nimport math\nimport os\n\nimport numpy as np\nfrom scipy.spatial import cKDTree\n\nfrom fitting import (Surface, merge_surfaces, weld, compact, subdivide, shrink_wrap, flatten_hem, limb_hull,\n boundary_loops, vertex_normals, transfer_weights, rigid_weights, blend_weights, taubin)\n\n\n# ---- mesh helpers --------------------------------------------------------------\ndef grid_mesh(P):\n \"\"\"P: (U, V, 3) grid of points -> (pos, tri).\"\"\"\n U, V = P.shape[:2]\n idx = np.arange(U * V).reshape(U, V)\n a, b, c, d = idx[:-1, :-1], idx[1:, :-1], idx[1:, 1:], idx[:-1, 1:]\n tri = np.concatenate([np.stack([a, b, c], -1).reshape(-1, 3), np.stack([a, c, d], -1).reshape(-1, 3)])\n return P.reshape(-1, 3), tri\n\n\ndef piece(name, role, pos, tri, nrm=None, outward_from=None, axis=None):\n \"\"\"outward_from: a point (or, with axis, a line) the normals should face away from, so the\n renderer knows which side is the outside of a one-sided sheet.\"\"\"\n pos = np.asarray(pos, float)\n tri = np.asarray(tri)\n nrm = vertex_normals(pos, tri) if nrm is None else nrm\n if outward_from is not None:\n d = pos - np.asarray(outward_from, float)\n if axis is not None:\n a = np.asarray(axis, float) / np.linalg.norm(axis)\n d -= np.outer(d @ a, a)\n if (np.einsum(\"ij,ij->i\", nrm, d) < 0).mean() > 0.5:\n nrm = -nrm\n tri = tri[:, ::-1]\n return dict(mesh=\"outfit\", material=f\"OUTFIT_{name}\", mi=-1, role=role, pos=pos,\n nrm=nrm, uv=np.zeros((len(pos), 2)), tri=tri)\n\n\ndef thick_grid(P, thickness, outward_from, axis=None):\n \"\"\"A grid sheet given real thickness: outer face, inner face, and the four edges closed, so\n rims read as solid and the inside never shows.\"\"\"\n pos, tri = grid_mesh(P)\n n = vertex_normals(pos, tri)\n d = pos - np.asarray(outward_from, float)\n if axis is not None:\n a = np.asarray(axis, float) / np.linalg.norm(axis)\n d -= np.outer(d @ a, a)\n if (np.einsum(\"ij,ij->i\", n, d) < 0).mean() > 0.5:\n n, tri = -n, tri[:, ::-1]\n U, V = P.shape[:2]\n inner = (pos - n * thickness).reshape(U, V, 3)\n outer = pos.reshape(U, V, 3)\n mid = outer.reshape(-1, 3).mean(0)\n allp, allt, off = [], [], 0\n parts = [(outer, tri, None), (inner, tri[:, ::-1], None)]\n for edge in (lambda G: G[:, 0], lambda G: G[:, -1], lambda G: G[0, :], lambda G: G[-1, :]):\n strip = np.stack([edge(outer), edge(inner)], 1)\n p_, t_ = grid_mesh(strip)\n nn = vertex_normals(p_, t_)\n if (np.einsum(\"ij,ij->i\", nn, p_ - mid) < 0).mean() > 0.5:\n t_ = t_[:, ::-1]\n parts.append((strip, t_, True))\n for G, t_, _ in parts:\n allp.append(G.reshape(-1, 3))\n allt.append(t_ + off)\n off += G.shape[0] * G.shape[1]\n return np.concatenate(allp), np.concatenate(allt), outer\n\n\ndef frame_axes(a, hint=(0, 1, 0)):\n a = np.asarray(a, float) / np.linalg.norm(a)\n b = np.cross(a, hint)\n if np.linalg.norm(b) < 1e-6:\n b = np.cross(a, (1, 0, 0))\n b /= np.linalg.norm(b)\n return a, b, np.cross(a, b…1319 tokens truncated…eleton=roots[0])\n mesh_nodes = []\n for k, (p, role) in enumerate(zip(portrait.prims, portrait.roles)):\n if role == \"skip\" or not len(p[\"tri\"]) or p.get(\"world\") or \"J\" not in p:\n continue\n usedv, inv = np.unique(p[\"tri\"], return_inverse=True)\n pos = (p[\"pos\"][usedv] * FLIP).astype(np.float32)\n nrm = p[\"nrm\"][usedv] * FLIP\n nrm = (nrm / np.maximum(np.linalg.norm(nrm, axis=1, keepdims=True), 1e-9)).astype(np.float32)\n remap = np.array([jidx.get(n, jidx.get(\"J_Bip_C_Head\")) for n in p[\"jnames\"]])\n J = remap[p[\"J\"][usedv]].astype(np.uint16)\n W = p[\"W\"][usedv].astype(np.float32)\n W /= np.maximum(W.sum(1, keepdims=True), 1e-9)\n attrs = dict(POSITION=add_acc(pos, \"VEC3\", 5126, 34962), NORMAL=add_acc(nrm, \"VEC3\", 5126, 34962),\n JOINTS_0=add_acc(J, \"VEC4\", 5123, 34962), WEIGHTS_0=add_acc(W, \"VEC4\", 5126, 34962))\n if \"plate\" in p: # outline plates (tools/plates.py): border, engraving, gradient\n attrs[\"_PLATE\"] = add_acc(np.asarray(p[\"plate\"])[usedv].astype(np.float32), \"VEC4\", 5126, 34962)\n mat = dict(name=f\"{group_of(p, role)}:{role}\", doubleSided=True,\n pbrMetallicRoughness=dict(metallicFactor=0.0, roughnessFactor=0.9))\n tone = ROLE_TONE.get(role)\n extra = getattr(portrait, \"paint\", None) or {}\n color = hex_rgb(palette[tone]) if tone in palette else \\\n hex_rgb(extra[role]) if isinstance(extra.get(role), str) else [0.8, 0.8, 0.8]\n if role in TEXTURED:\n src = portrait._hair_v if role == \"hair\" and getattr(portrait, \"_hair_v\", None) is not None \\\n and \"_HAIR\" in p[\"material\"] else portrait.v\n raw = src.material_texture(p[\"mi\"]) if p[\"mi\"] >= 0 else None\n if raw is not None and role == \"line\":\n raw = fill_line_specks(raw)\n if p.get(\"lid_fill\") is not None: # a shut eye's lid (vroid_portrait): its lash solid\n raw = fill_lid(raw, p[\"lid_fill\"])\n if raw is not None and role == \"mouth\":\n raw = even_mouth(raw)\n if raw is not None:\n attrs[\"TEXCOORD_0\"] = add_acc(p[\"uv\"][usedv].astype(np.float32), \"VEC2\", 5126, 34962)\n mat[\"pbrMetallicRoughness\"][\"baseColorTexture\"] = dict(\n index=add_texture((id(src), p[\"mi\"], p.get(\"lid_fill\")), raw))\n if role == \"hair\":\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n if role in (\"hair\", \"line\", \"brow\", \"iris\", \"highlight\"):\n mat[\"alphaMode\"], mat[\"alphaCutoff\"] = \"MASK\", 0.5\n else:\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n else:\n mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n if role in (\"metal\", \"steel\", \"gold\"):\n mat[\"pbrMetallicRoughness\"].update(metallicFactor=0.6, roughnessFactor=0.35)\n if p.get(\"strands\"): # kit hair (tools/hair.py): one shared strand texture\n import hair as _hair\n attrs[\"TEXCOORD_0\"] = add_acc(np.asarray(p[\"uv\"], np.float32)[usedv], \"VEC2\", 5126, 34962)\n mat[\"pbrMetallicRoughness\"][\"baseColorTexture\"] = dict(index=add_texture((\"strands\",), _hair.STRANDS))\n if \"decal\" in p: # a design in the piece's own coordinates (tools/plates.py Canvas)\n uvd = np.asarray(p[\"uv\"], np.float32)[usedv].copy()\n uvd[:, 1] = 1 - uvd[:, 1] # the canvas draws t up; glTF's texture origin is the top left\n attrs[\"TEXCOORD_0\"] = add_acc(uvd, \"VEC2\", 5126, 34962)\n mat[\"pbrMetallicRoughness\"][\"baseColorTexture\"] = dict(index=add_texture((\"decal\", k), p[\"decal\"], limit=1024))\n mat[\"extras\"] = dict(decal=True)\n materials.append(mat)\n meshes.append(dict(name=group_of(p, role), primitives=[dict(attributes=attrs,\n indices=add_acc(inv.reshape(-1).astype(np.uint32), \"SCALAR\", 5125, 34963), material=len(materials) - 1)]))\n mesh_nodes.append(len(gnodes))\n gnodes.append(dict(name=f\"{group_of(p, role)}/{p['material']}\", mesh=len(meshes) - 1, skin=0,\n extras=dict(group=group_of(p, role), role=role, material=p[\"material\"])))\n # animations\n for name, keys in (clips or {}).items():\n times = np.array([t for t, _ in keys], np.float32)\n tacc = add_acc(times.reshape(-1, 1), \"SCALAR\", 5126, minmax=True)\n samplers, channels = [], []\n for i in order:\n mats = [F4 @ v.local_matrix(i, vp.bone_pose(v, portrait.shape, pose)) @ F4 for _, pose in keys]\n trs = [_trs(m) for m in mats]\n T = np.array([a for a, _, _ in trs], np.float32)\n Q = np.array([b for _, b, _ in trs], np.float32)\n for k in range(1, len(Q)): # keep quaternions on one hemisphere\n if np.dot(Q[k], Q[k - 1]) < 0:\n Q[k] = -Q[k]\n t0, q0, _ = _trs(local_ref[i])\n if np.dot(Q[0], q0) < 0:\n q0 = -q0\n # a channel whenever the clip leaves the reference pose, even if it then holds still\n if np.abs(Q - q0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(Q, \"VEC4\", 5126), interpolation=\"LINEAR\"))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"rotation\")))\n if np.abs(T - t0).max() > 1e-5:\n samplers.append(dict(input=tacc, output=add_acc(T, \"VEC3\", 5126), interpolation=\"LINEAR\"))\n channels.append(dict(sampler=len(samplers) - 1, target=dict(node=node_of[i], path=\"translation\")))\n anims.append(dict(name=name, samplers=samplers, channels=channels))\n root = len(gnodes)\n gnodes.append(dict(name=\"character\", children=roots + mesh_nodes))\n gltf = dict(asset=dict(version=\"2.0\", generator=\"lowmarch export_skinned\"), scene=0, scenes=[dict(nodes=[root])],\n nodes=gnodes, meshes=meshes, materials=materials, skins=[skin], accessors=accessors, bufferViews=views,\n buffers=[dict(byteLength=len(bin_))], samplers=[dict(magFilter=9729, minFilter=9987)])\n if textures:\n gltf.update(textures=textures, images=images)\n if anims:\n gltf[\"animations\"] = anims\n js = json.dumps(gltf, separators=(\",\", \":\")).encode()\n js += b\" \" * ((4 - len(js) % 4) % 4)\n while len(bin_) % 4:\n bin_.append(0)\n out = struct.pack(\"<4sII\", b\"glTF\", 2, 12 + 8 + len(js) + 8 + len(bin_))\n out += struct.pack(\"<I4s\", len(js), b\"JSON\") + js + struct.pack(\"<I4s\", len(bin_), b\"BIN\\x00\") + bytes(bin_)\n open(path, \"wb\").write(out)\n return len(out)\n"} {"chunk_id":"1e66f7","wall_time_seconds":0.00000447,"exit_code":0,"original_token_count":3027,"output":"~/.local/opt/blender-5.2.3-linux-x64/blender\n\"\"\"Common enemy units: one costume per class, built from gear.py on any base body. Generic but detailed:\nlayered padding, mail and plate, riveted straps, an army colour on the cloth and shields (portrait\nguide, lesson 15). Pair each with a build and a face from gear.BUILDS / gear.FACES in the cast.\n\"\"\"\nimport numpy as np\n\nimport outfit as O\nimport gear as G\nfrom fitting import Surface, merge_surfaces\nfrom vrm import bone_weight\n\n\ndef _base(fit, shirt=\"padding\", legs=\"cloth\", boots=\"boot\", gloves=\"glove\", knee=None, shirt_subdiv=0, boot_top=None):\n \"\"\"Under layers every class shares: a shirt with sleeves to the wrist, trousers, boots to below\n the knee (or to boot_top: above the knee, they take the thigh too), gloves. Returns the pieces and\n the shirt (what coats are fitted over).\"\"\"\n B = fit.bone\n nk, hips = B[\"J_Bip_C_Neck\"], B[\"J_Bip_C_Hips\"]\n knee = B[\"J_Bip_L_LowerLeg\"][1] if knee is None else knee\n\n def cuff(side):\n a, h = B[f\"J_Bip_{side}_LowerArm\"], B[f\"J_Bip_{side}_Hand\"]\n n = (h - a) / np.linalg.norm(h - a)\n return n, n @ (h - n * 0.02)\n torso = (\"Spine\", \"Chest\", \"UpperChest\", \"Bust\", \"Shoulder\", \"UpperArm\", \"LowerArm\", \"Neck\", \"Hips\")\n # the neckline: a straight hem, lower at the throat than at the back of the neck (a level cut of\n # whole triangles left a saw-tooth edge, and a big trapezius showed above it)\n nh = np.array([0.0, 1.0, -0.3]) / np.linalg.norm([0.0, 1.0, -0.3])\n neckline = (nh, float(nh @ (nk + np.array([0.0, 0.012, 0.0]))))\n s = O.wrap(fit, \"shirt\", shirt, torso, offset=0.006, exclude=(\"UpperLeg\",), y_min=hips[1] - 0.04,\n y_max=nk[1] + 0.05, cut=neckline, hems=[cuff(\"L\"), cuff(\"R\"), neckline], subdiv=shirt_subdiv)\n t = O.wrap(fit, \"trousers\", legs, (\"Hips\", \"UpperLeg\", \"LowerLeg\"), offset=0.007, y_max=hips[1] + 0.02, subdiv=1)\n top = knee - 0.07 if boot_top is None else boot_top\n b = O.wrap(fit, \"boots\", boots, (\"LowerLeg\", \"Foot\", \"ToeBase\") + ((\"UpperLeg\",) if top > knee else ()), offset=0.015,\n y_max=top, subdiv=1, hems=[((0, 1, 0), top - 0.005)])\n g = O.wrap(fit, \"gloves\", gloves, (\"Hand\", \"Thumb\", \"Index\", \"Middle\", \"Ring\", \"Little\"), offset=0.003, min_w=0.3, smooth=4)\n out = [p for p in (s, t, b, g) if p is not None]\n for p, grp in zip(out, (\"doublet\", \"trousers\", \"boots\", \"gloves\")):\n p[\"group\"] = grp\n return out, s, t, b\n\n\ndef underwear(fit, band=False):\n \"\"\"Plain shorts (and a chest band with band=True) for inspecting bare bodies (the armory page, built\n in the T-pose): hips to mid-thigh, close to the skin.\"\"\"\n B = fit.bone\n hips, knee = B[\"J_Bip_C_Hips\"][1], B[\"J_Bip_L_LowerLeg\"][1]\n lo, hi = (hips + knee) / 2 + 0.03, hips + 0.07\n # all the skin between the hems but the arms' (they hang there in the fitting pose): taking only skin\n # weighted to the hips, legs and spine left holes where MakeHuman weights it to the chest or elsewhere\n out = [O.wrap(fit, \"shorts\", \"cloth\", (\"J_\",), offset=0.004, y_min=lo - 0.04, y_max=hi + 0.04, subdiv=1,\n exclude=(\"Shoulder\", \"Arm\", \"Hand\", \"Thumb\", \"Index\", \"Middle\", \"Ring\", \"Little\"),\n hems=[((0, 1, 0), hi - 0.005), ((0, -1, 0), -(lo + 0.005))], refloor=True, clamp=True)]\n if band:\n ch, uc = B[\"J_Bip_C_Chest\"][1], B[\"J_Bip_C_UpperChest\"][1]\n blo, bhi = ch - 0.01, uc + 0.06\n # like the shorts: triangles past the hems taken and clamped onto them (dropping them notched the\n # top edge into steps on broad backs), every bone but the arms'\n out.append(O.wrap(fit, \"band\", \"cloth\", (\"J_\",), offset=0.004, y_min=blo - 0.03, y_max=bhi + 0.03, subdiv=1,\n exclude=(\"Shoulder\", \"Arm\", \"Hand\", \"Thumb\", \"Index\", \"Middle\", \"Ring\", \"Little\"),\n hems=[((0, 1, 0), bhi - 0.005), ((0, -1, 0), -(blo + 0.005))], refloor=True, clamp=True))\n out = [p for p in out if p is not None]\n for p in out:\n p[\"group\"] = \"underwear\"\n fit.keep_skin = (\"J_\",) # bare everywhere else: keep all the skin (VRoid 2 weights some to J_Sec_ bones)\n # but not the skin well inside the shorts: on fitted bodies (tools/fit.py) it came through the waistband.\n # Never the arms', which hang beside the hips in the fitting pose\n arms = (\"Shoulder\", \"Arm\", \"Hand\", \"Thumb\", \"Index\", \"Middle\", \"Ring\", \"Little\")\n fit.drop_skin = lambda p: ((p[\"pos\"][:, 1] > lo + 0.015) & (p[\"pos\"][:, 1] < hi - 0.015)\n & (bone_weight(p, arms) < 0.05))\n return out\n\n\ndef underwear_f(fit):\n return underwear(fit, band=True)\n\n\ndef _under(shirt):\n return Surface(*O.without(shirt, (\"Shoulder\", \"UpperArm\", \"LowerArm\", \"Hand\")))\n\n\ndef _surf(pcs, *names, prefix=False):\n sel = [p for p in pcs if (p[\"material\"].startswith(tuple(\"OUTFIT_\" + n for n in names)) if prefix\n else p[\"material\"] in tuple(\"OUTFIT_\" + n for n in names))]\n return merge_surfaces(*[(p[\"pos\"], p[\"tri\"]) for p in sel])\n\n\ndef soldier(fit, legs=\"breeches\"):\n \"\"\"Halberd infantry, after the study's Soldier: a kettle hat, a doublet in the army colour with\n full sleeves bagging into gauntlets that reach almost to the elbow, a short breastplate with a\n plackart (full width to the armpits), a fauld of round scales to mid-thigh, a belt, a halberd\n held in both hands (the cast's polearm stance, tools/clips.py). No puff or band on the upper arm:\n the study's soldiers have neither, and on a real arm a puff read as a bicep.\n legs: \"breeches\" (baggy, bagging over calf boots: the study's men) or \"tights\" (with boots to\n above the knee: the study's women).\"\"\"\n B = fit.bone\n hips = B[\"J_Bip_C_Hips\"]\n knee = B[\"J_Bip_L_LowerLeg\"][1]\n gauntlet = 0.70 # of the forearm, from the wrist\n y_hem = hips[1] - 0.20 # the fauld's\n boot_top = knee + 0.08 if legs == \"tights\" else knee - 0.07\n out, shirt, trousers, boots = _base(fit, shirt=\"signature\", legs=\"cloth\", boots=\"boot\", shirt_subdiv=1,\n boot_top=boot_top)\n G.loose_sleeves(fit, shirt, cuff=gauntlet)\n if legs == \"breeches\":\n G.breeches(fit, trousers, boots, y_hem, boot_top - 0.005)\n else:\n G.flare_boots(fit, boots, boot_top - 0.005, ease=0.008)\n under = _under(shirt)\n out += G.breastplate(fit, under, arm=64.0)\n plate = _surf(out, \"breastplate\", prefix=True)\n # the guard's wide stance: the fauld follows the thighs closely and clears the seat\n out += G.scale_skirt(fit, under, hips[1] + 0.06, y_hem, role=\"mail\", share=0.15,\n clear=Surface(trousers[\"pos\"], trousers[\"tri\"]))\n G.slim_under(fit, trousers, y_hem) # and what it hides can't come through it\n belt, front = O.belt(fit, \"belt\", \"leather\", plate, hips[1] + 0.05, height=0.034, offset=0.004)\n out.append(belt)\n cuffs = G.cuffs(fit, length=gauntlet, flare=0.034)\n G.tuck_sleeves(fit, shirt, cuffs)\n out += cuffs\n out += G.coif(fit, role=\"padding\")\n out += G.helmet(fit, \"kettle\")\n out += G.halberd(fit, grip=0.50) # the rear hand near the butt, as the study holds it\n return out\n\n\ndef soldier_f(fit):\n \"\"\"The soldier as the study draws its women: tights and boots to above the knee.\"\"\"\n return soldier(fit, legs=\"tights\")\n\n\ndef fighter(fit):\n \"\"\"Sword and round shield, after the study's Fighter: a kettle hat worn low, a quilted gambeson with\n full sleeves, a breastplate, lamed spaulders, a knife-pleated skirt in the army colour, greaves, a\n wooden round shield, an arming sword.\"\"\"\n B = fit.bone\n hips = B[\"J_Bip_C_Hips\"]\n knee = B[\"J_Bip_L_LowerLeg\"][1]\n out, shirt, trousers, boots = _base(fit, shirt=\"padding\", legs=\"cloth\", boots=\"boot\")\n under = _under(shirt)\n out += G.quilted(fit, under, role=\"padding\", y_hem=hips[1] - 0.02, flare=0.02, sleeve_end=0.95)\n gam = _surf(out, \"gambeson\", \"gambeson_skirt\")\n out += G.pleated_skirt(fit, gam, hips[1] + 0.05, hips[1] - 0.30, role=\"signature\")\n out += G.breastplate(fit, gam)\n plate_body = merge_surfaces(*[(p[\"pos\"], p[\"tri\"]) for p in out if p.get(\"group\") in (\"plate\", \"padding\")], (fit.pos, fit.tri))\n for side in (\"L\", \"R\"):\n sp, rims = O.pauldron(fit, f\"spaulder_{side}\", \"steel\", plate_body, side=side,\n lames=((0, 56, 0.024, 0.032), (47, 73, 0.022, 0.030), (65, 91, 0.020, 0.028)), spread=105)\n out += G._group(sp + [O.inherit(O.pipe(f\"spaulder_{side}_roll{k}\", \"steel\", r_, r=0.0028), pc)\n for k, (pc, r_) in enumerate(zip(sp, rims))], \"plate\")\n ll, ft = B[f\"J_Bip_{side}_LowerLeg\"], B[f\"J_Bip_{side}_Foot\"]\n top = (knee - 0.085 - ll[1]) / (ft[1] - ll[1])\n gv, rims = O.limb_lames(fit, f\"greave_{side}\", \"steel\", O.side_of(boots, side), ll, ft, ((top, 0.80, 0.008, 0.011),),\n rmax=0.11)\n fit.bind(gv[0], rigid=f\"J_Bip_{side}_LowerLeg\")\n out += G._group(gv + [O.inherit(O.pipe(f\"greave_{side}_roll{k}\", \"steel\", r_, r=0.0028), gv[0])\n for k, r_ in enumerate(rims[0])], \"plate\")\n belt, front = O.belt(fit, \"belt\", \"leather\", _surf(out, \"breastplate\", prefix=True), hips[1] + 0.05, height=0.036,\n offset=0.004)\n out.append(belt)\n out += G.cuffs(fit, length=0.32)\n out += G.coif(fit, role=\"padding\")\n out += G.helmet(fit, \"kettle\", lift=0.032)\n out += G.round_shield(fit)\n out += O.sword(fit, \"R\", blade_len=0.70, hilt=\"metal\")\n return out\n\n\ndef housecarl(fit):\n \"\"\"An axeman in mail, after the study's Housecarl: a nasal helm over a mail coif, a mail hauberk to\n134: if role == \"hair\": # strands are grey in the texture: tint them\n135: mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n140: mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n242: # painted renderer: a material kind and one base colour per role; the shader builds the ramp\n245: pc.update(getattr(portrait, \"paint\", None) or {})\n248: paint = {\"face\": dict(skin), \"body\": dict(skin), \"shadow\": dict(skin, shade=True), # shadow cards: skin in shade\n258: \"motif\": dict(kind=\"cloth\", base=pc.get(\"motif\", \"#3a44a0\"))} # decal paint on steel (tools/plates.py)\n260: if role not in paint and isinstance(val, str) and val.startswith(\"#\"):\n261: paint[role] = dict(kind=\"cloth\", base=val)\n262: elif role not in paint and isinstance(val, dict) and \"base\" in val:\n263: paint[role] = dict(kind=val.get(\"kind\", \"cloth\"), base=val[\"base\"])\n265: if role in paint:\n266: paint[role][\"grain\"] = g\n268: paint=paint,\n303: \"\"\"A line texture's specks filled: pale or clear texels enclosed by the painted (dark, opaque) line, up to `most`\n304: texels a speck, take the line's colour. VRoid paints small highlights inside its lash lines; the painted\n351:# what the painted renderer's split (index.html, material kind 10) was tuned on: the inside, the tongue, the teeth\n358: teeth (90th percentile of their least channel: white, where the tongue's light is pink) are measured, every texel placed between them, and painted\n368: if g_tg - g_in < 0.03 or l_th - l_in < 0.05: # no tongue or teeth to tell apart: as painted\n484: extra = getattr(portrait, \"paint\", None) or {}\n502: mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n506: mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n508: mat[\"pbrMetallicRoughness\"][\"baseColorFactor\"] = color + [1.0]\n511: if p.get(\"strands\"): # kit hair (tools/hair.py): one shared strand texture\n514: mat[\"pbrMetallicRoughness\"][\"baseColorTexture\"] = dict(index=add_texture((\"strands\",), _hair.STRANDS))\n"}exec_commandsed -n '163,240p' tools/outfit.py; sed -n '1040,1070p' tools/vroid_portrait.py; sed -n '240,267p' tools/export_glb.py; rg -n '^def spear' tools/gear.py; sed -n '1510,1565p' tools/gear.py; rg -n 'const camera|let camera|function render|function frameAt' review/vroid-02/index.html (+1 more)
command
sed -n '163,240p' tools/outfit.py; sed -n '1040,1070p' tools/vroid_portrait.py; sed -n '240,267p' tools/export_glb.py; rg -n '^def spear' tools/gear.py; sed -n '1510,1565p' tools/gear.py; rg -n 'const camera|let camera|function render|function frameAt' review/vroid-02/index.html python3 - <<'PY' import sys,pickle,numpy as np sys.path[:0]=['tools','art/cast','review/astra'] p=pickle.load(open('review/out/astra/site/portrait.pkl','rb')) from rig import Rig import poses as P r=Rig(p.v,p.shape) print(p.shape) for n in ['Hips','Spine','Chest','UpperChest','Neck','Head','L_UpperArm','L_LowerArm','L_Hand','L_UpperLeg','L_LowerLeg','L_Foot']: n='J_Bip_'+('C_'+n if '_' not in n else n) print(n,r.pos(P.BUST,n)) for pc,ro in zip(p.prims,p.roles): if ro=='face': v=pc['pos'][np.unique(pc['tri'])];print('FACE',v.min(0),v.max(0)) PYresult, 4 lines
Script completed Wall time 0.7 seconds Output: {"chunk_id":"eb0d0f","wall_time_seconds":0.00000372,"exit_code":0,"original_token_count":2055,"output":"class Fit:\n \"\"\"What a costume is built against: the body skin (welded, measurable) and the bones, all in\n the reference pose, plus the skin weights so pieces can be bound to the skeleton.\"\"\"\n\n def __init__(self, vrm, pose, prims, roles):\n self._prims, self._roles = prims, roles\n W = vrm.node_world(pose)\n names = vrm.nodes_by_name()\n self.world = {k: W[i].copy() for k, i in names.items() if k}\n self.bone = {k: m[:3, 3].copy() for k, m in self.world.items()}\n skin = [p for p, r in zip(prims, roles) if r == \"body\"]\n self.body = skin[0]\n self.pos = self.body[\"pos\"]\n self.J, self.W, self.jnames = self.body[\"J\"], self.body[\"W\"], self.body[\"jnames\"]\n self.tri = weld(self.pos, np.concatenate([p[\"tri\"] for p in skin]))\n self.surf = Surface(self.pos, self.tri)\n self.skin = self.pos[np.unique(self.tri)]\n # MakeHuman bodies (tools/makehuman.py) have real muscle relief; VRoid's limbs are smooth tubes\n self.cloth_hull = vrm.j.get(\"asset\", {}).get(\"generator\", \"\").startswith(\"lowmarch makehuman\") \\\n and not os.environ.get(\"LOWMARCH_NO_HULL\")\n\n def head_surface(self):\n \"\"\"The head's skin (face and scalp), for charts over the skull (tools/hair.py).\"\"\"\n from vrm import bone_weight\n pos, tri, off = [], [], 0\n for p, r in zip(self._prims, self._roles):\n if r in (\"face\", \"body\") and \"J\" in p and len(p[\"tri\"]):\n w = bone_weight(p, (\"Head\",))\n T = p[\"tri\"][(w[p[\"tri\"]] > 0.5).all(1)]\n if len(T):\n pos.append(p[\"pos\"])\n tri.append(T + off)\n off += len(p[\"pos\"])\n return Surface(np.concatenate(pos), np.concatenate(tri))\n\n def weight(self, bones):\n hit = np.array([any(b in n for b in bones) for n in self.jnames])\n return (hit[self.J] * self.W).sum(1)\n\n def tris_for(self, bones, min_w=0.5, exclude=(), y_min=None, y_max=None):\n w = self.weight(bones)\n if exclude:\n w = w - self.weight(exclude)\n T = self.tri[(w[self.tri] >= min_w).all(1)]\n tp = self.pos[T]\n sel = np.ones(len(T), bool)\n if y_min is not None:\n sel &= tp[:, :, 1].min(1) > y_min\n if y_max is not None:\n sel &= tp[:, :, 1].max(1) < y_max\n return T[sel]\n\n def bind(self, pc, allow=None, fallback=None, rigid=None, blend=None, surface=None):\n \"\"\"Attach skin weights to a piece: copied from the body under it (optionally limited to\n some bones), or rigid on one bone / a fixed blend.\"\"\"\n if pc is None:\n return None\n n = len(pc[\"pos\"])\n if rigid or blend:\n pc[\"J\"], pc[\"W\"] = rigid_weights(n, self.jnames, rigid, blend)\n else:\n pc[\"J\"], pc[\"W\"] = transfer_weights(pc[\"pos\"], None, self.J, self.W, surface=surface or self.surf,\n allow=allow, jnames=self.jnames, fallback=fallback)\n pc[\"jnames\"] = self.jnames\n return pc\n\n\ndef without(pc, bones, max_w=0.3):\n \"\"\"A piece's triangles away from some bones, as (pos, tri) for merge_surfaces: a bodice's torso\n without its sleeves. Casting a waist ring onto a garment with its sleeves in it catches the\n hanging arms at the sides (the reference pose has the arms down beside the hips).\"\"\"\n hit = np.array([any(b in n for b in bones) for n in pc[\"jnames\"]])\n w = (hit[pc[\"J\"]] * pc[\"W\"]).sum(1)\n return pc[\"pos\"], pc[\"tri\"][(w[pc[\"tri\"]] < max_w).all(1)]\n\n\ndef inherit(child, parent):\n \"\"\"Trim and hardware take the weights of the nearest vertex of the piece they sit on.\"\"\"\n if self.roles[k] in (\"line\", \"brow\", \"iris\", \"highlight\", \"white\", \"hair\", \"mouth\"):\n src = self._hair_v if (hair_from and \"_HAIR\" in p[\"material\"]) else self.v\n t = src.material_texture(p[\"mi\"])\n if t is not None and self.roles[k] == \"line\":\n # VRoid's upper lid is a thick graded band over the iris; keep its dark core only\n t = t.copy()\n t[..., 3] = np.where(t[..., :3].mean(-1) < LID_CORE, t[..., 3], 0)\n if t is not None:\n self.tex[k] = t\n # painted face marks (lip line, nose) from the face texture, grown so they survive the vote\n from scipy.ndimage import binary_dilation, label\n self.marks = {}\n self.mouth_pts = None\n self.mouth_curve = None\n for k, p in enumerate(self.prims):\n if self.roles[k] != \"face\":\n continue\n t = self.v.material_texture(p[\"mi\"])\n if t is None:\n continue\n th, tw = t.shape[:2]\n vv, uu = np.mgrid[0:th, 0:tw]\n vv, uu = (vv + 0.5) / th, (uu + 0.5) / tw\n win = ((uu > MARK_WINDOW[\"u\"][0]) & (uu < MARK_WINDOW[\"u\"][1])\n & (vv > MARK_WINDOW[\"v\"][0]) & (vv < MARK_WINDOW[\"v\"][1]))\n raw = (t[..., :3].mean(-1) / 255 < FACE_MARK) & (t[..., 3] > 0) & win\n grown = binary_dilation(raw, iterations=MARK_GROW) & win\n # 2 = mouth (dark line), 1 = nose mark (one tone softer)\n self.marks[k] = np.where(grown, np.where(vv >= MARK_WINDOW[\"nose_below\"], 2, 1), 0).astype(np.uint8)\n if self.mouth_pts is None and raw.any():\n lab, n = label(raw)\n import base64\n marks = base64.b64encode(b.getvalue()).decode()\n # painted renderer: a material kind and one base colour per role; the shader builds the ramp\n pc = dict(signature=\"#7d1e2c\", doublet=\"#2a2d3d\", heraldry=\"#dfe2e8\", leather=\"#5f3e2b\", boot=\"#4a3326\", glove=\"#5f3e2b\",\n steel=\"#a6adbb\", gold=\"#b08b3f\", hair=hexp(\"C\"), trim=\"#b08b3f\")\n pc.update(getattr(portrait, \"paint\", None) or {})\n skin = dict(kind=\"skin\", base=pc.get(\"skin\") or \"#f8e1d5\") # light skin unless a tone is set\n skin[\"ramp\"] = skin_ramp(skin[\"base\"]) # its lit, shade and deep shade\n paint = {\"face\": dict(skin), \"body\": dict(skin), \"shadow\": dict(skin, shade=True), # shadow cards: skin in shade\n \"hair\": dict(kind=\"hair\", base=pc[\"hair\"]),\n \"coat\": dict(kind=\"cloth\", base=pc[\"signature\"]), \"cape\": dict(kind=\"cloth\", base=pc[\"signature\"]),\n \"signature\": dict(kind=\"cloth\", base=pc[\"signature\"]), \"doublet\": dict(kind=\"cloth\", base=pc[\"doublet\"]),\n \"cloth\": dict(kind=\"cloth\", base=pc[\"doublet\"]), \"heraldry\": dict(kind=\"cloth\", base=pc[\"heraldry\"]),\n \"leather\": dict(kind=\"leather\", base=pc[\"leather\"]), \"boot\": dict(kind=\"leather\", base=pc[\"boot\"]),\n \"glove\": dict(kind=\"leather\", base=pc[\"glove\"]), \"metal\": dict(kind=\"steel\", base=pc[\"steel\"]),\n \"steel\": dict(kind=\"steel\", base=pc[\"steel\"]), \"gold\": dict(kind=\"gold\", base=pc[\"gold\"]),\n \"grass\": dict(kind=\"world\", base=\"#5a7a3a\"), \"dirt\": dict(kind=\"world\", base=\"#6a4a32\"),\n \"stone\": dict(kind=\"world\", base=\"#7c7a86\"),\n \"motif\": dict(kind=\"cloth\", base=pc.get(\"motif\", \"#3a44a0\"))} # decal paint on steel (tools/plates.py)\n for role, val in pc.items(): # extra roles a cast entry names (cloth unless it says)\n if role not in paint and isinstance(val, str) and val.startswith(\"#\"):\n paint[role] = dict(kind=\"cloth\", base=val)\n elif role not in paint and isinstance(val, dict) and \"base\" in val:\n paint[role] = dict(kind=val.get(\"kind\", \"cloth\"), base=val[\"base\"])\n for role, g in (pc.get(\"grain\") or {}).items(): # optional per-role brush grain (big flat cloth mottles)\n if role in paint:\n paint[role][\"grain\"] = g\n return dict(roles=roles, light=vp.LIGHT.tolist(), sun=vp.SUN.tolist(), capsules=caps, cloth=cloth, face_marks=marks,\n323:def spear(fit, length=2.0, grip=0.55, head=0.26, hand=\"R\", shaft_role=\"wood\", name=\"spear\"):\n306:const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 40);\n1388:function render() {\n1503:function frameAt(centre, h, tw, th, pitch) {\n"}{"chunk_id":"14a9c0","wall_time_seconds":0.389619806,"exit_code":0,"original_token_count":331,"output":"{'head': 1.0, 'neck': 1.0, 'chest': 1.0, 'height': 1.0, 'shoulders': 1.0, 'arms': 1.0, 'torso': 1.0, 'legs': 1.0, 'leg_len': 1.0, 'hands': 1.0, 'shoulder_w': 0.0, 'face_len': 0.0, 'jaw': 0.0, 'chin_w': 0.0, 'chin_len': 0.0, 'cheek': 0.0, 'brow_ridge': 0.0, 'nose': 0.0, 'nose_w': 0.0, 'eye': 1.0, 'eye_tilt': 0.0, 'iris': 1.0, 'lash': 1.0, 'mouth': 1.0, 'arm_out': 4, 'age_lines': 0.0, 'blush': 1.0, 'curl': 0.0, 'face_normals': 1.0, 'hair_normals': 0.0, 'shadow_cards': 1.0, 'fangs': 1.0, 'rest': {'Fcl_BRW_Angry': 0.2, 'Fcl_EYE_Close': 0.08}}\nJ_Bip_C_Hips [ 0. 1.01229657 -0.02366985]\nJ_Bip_C_Spine [-1.35752076e-17 1.08344994e+00 -3.81632374e-02]\nJ_Bip_C_Chest [-6.51445871e-17 1.24002841e+00 -4.55018564e-02]\nJ_Bip_C_UpperChest [-6.26113665e-17 1.39073237e+00 -3.49403882e-02]\nJ_Bip_C_Neck [-8.41441181e-20 1.57775328e+00 -1.60468767e-03]\nJ_Bip_C_Head [-8.41441181e-20 1.63831037e+00 -4.44252360e-02]\nJ_Bip_L_UpperArm [-0.15418136 1.48277013 -0.02616038]\nJ_Bip_L_LowerArm [-0.23825458 1.18957196 -0.02616038]\nJ_Bip_L_Hand [-0.31224983 0.93151984 -0.02616038]\nJ_Bip_L_UpperLeg [-0.10274552 0.99909561 -0.01734307]\nJ_Bip_L_LowerLeg [-0.10303307 0.5317987 -0.04787857]\nJ_Bip_L_Foot [-0.10274552 0.11133792 -0.01734307]\nFACE [-0.10965985 1.60259109 -0.15846731] [ 0.10965994 1.83909815 -0.01330793]\n"}