A 3D model pipeline, pushed by GPT-6-Astra
agent (cont.)
+1:23exec_commandsed -n '1110,1268p' tools/outfit.py && sed -n '1,180p' tools/rig.py && rg -n '^def ' tools/gear.py && sed -n '859,903p' review/vroid-02/index.html && sed -n '1330,1378p' review/vroid-02/index.html && sed -n '890,913p' review/vroid-02/index.html
command
sed -n '1110,1268p' tools/outfit.py && sed -n '1,180p' tools/rig.py && rg -n '^def ' tools/gear.py && sed -n '859,903p' review/vroid-02/index.html && sed -n '1330,1378p' review/vroid-02/index.html && sed -n '890,913p' review/vroid-02/index.html
result, 4 lines
Script completed Wall time 0.1 seconds Output: {"chunk_id":"b1360e","wall_time_seconds":0.00000547,"exit_code":0,"original_token_count":7894,"output":"def lord(fit):\n \"\"\"The young lord after the Unicorn Overlord study (their lord: half-plate, hooded scarf, long\n tabard, round shield, one signature colour, almost no gold). Built inside out, the study's\n layering order, so each layer is cast onto the one under it and shows a sliver:\n doublet (dark, so it never reads as skin) + trousers, boots, gloves with gauntlet cuffs\n plate: breastplate, tassets, spaulders, vambraces and greaves, couters and poleyns with wings\n a wide leather belt with a square steel buckle\n tabard front and back (signature crimson, pale heraldic border), cloth\n hooded mantle (crimson) over the shoulders, clasped at the front\n shield on the left forearm, sword in the right hand\n \"\"\"\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]\n out = []\n\n def cuff_plane(side): # sleeves end under the gauntlet cuff\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.035)\n\n def grouped(pcs, g):\n for pc in pcs:\n if pc is not None:\n pc[\"group\"] = g\n return [pc for pc in pcs if pc is not None]\n\n def rolled(name, pc, rims, r=0.0028):\n \"\"\"A rolled steel edge along each rim: what defines plate in the study instead of gold.\"\"\"\n return [inherit(pipe(f\"{name}_roll{k}\", \"metal\", rim, r=r), pc) for k, rim in enumerate(rims)]\n\n # 1-2: the doublet and what's under it\n torso = (\"Spine\", \"Chest\", \"UpperChest\", \"Shoulder\", \"UpperArm\", \"LowerArm\", \"Neck\", \"Hips\")\n doublet = wrap(fit, \"doublet\", \"doublet\", torso, offset=0.008, exclude=(\"UpperLeg\",),\n y_min=hips[1] - 0.03, y_max=nk[1] + 0.012, hems=[cuff_plane(\"L\"), cuff_plane(\"R\")])\n trousers = wrap(fit, \"trousers\", \"leather\", (\"Hips\", \"UpperLeg\", \"LowerLeg\"), offset=0.008,\n y_max=hips[1] + 0.02, subdiv=1)\n boots = wrap(fit, \"boots\", \"boot\", (\"LowerLeg\", \"Foot\", \"ToeBase\"), offset=0.017, y_max=knee - 0.07,\n subdiv=1, hems=[((0, 1, 0), knee - 0.075)])\n gloves = wrap(fit, \"gloves\", \"glove\", (\"Hand\", \"Thumb\", \"Index\", \"Middle\", \"Ring\", \"Little\"),\n offset=0.0028, min_w=0.3, smooth=4) # down over the wrist: no gap under the cuff\n out += grouped([doublet], \"doublet\") + [p for p in (trousers, boots, gloves) if p is not None]\n col, _, _ = collar(fit, \"collar\", \"doublet\", height_back=0.030, height_front=0.018)\n out += grouped([col], \"doublet\")\n body_d = merge_surfaces((doublet[\"pos\"], doublet[\"tri\"]), (fit.pos, fit.tri))\n\n # 4: plate\n cuirass = wrap(fit, \"breastplate\", \"steel\", (\"Spine\", \"Chest\", \"UpperChest\", \"Hips\"), offset=0.014,\n exclude=(\"Shoulder\", \"UpperArm\", \"Neck\", \"UpperLeg\"), y_min=hips[1] + 0.030, y_max=nk[1] - 0.040,\n base=Surface(doublet[\"pos\"], doublet[\"tri\"]), smooth=40,\n hems=[((0, 1, 0), hips[1] + 0.040), ((0, 1, 0), nk[1] - 0.050)])\n keel = np.clip(1 - np.abs(cuirass[\"pos\"][:, 0]) / 0.07, 0, 1) * (cuirass[\"pos\"][:, 2] < B[\"J_Bip_C_Chest\"][2])\n cuirass[\"pos\"] = cuirass[\"pos\"] + cuirass[\"nrm\"] * (0.007 * keel ** 2)[:, None] # a soft central ridge\n cuirass[\"nrm\"] = vertex_normals(cuirass[\"pos\"], cuirass[\"tri\"])\n loops = [cuirass[\"pos\"][L] for L in cuirass[\"loops\"] if len(L) > 12]\n out += grouped([cuirass] + [inherit(pipe(f\"breastplate_roll{k}\", \"metal\", Lp, r=0.0034, closed=True), cuirass)\n for k, Lp in enumerate(loops)], \"plate\")\n plate_body = merge_surfaces((cuirass[\"pos\"], cuirass[\"tri\"]), (doublet[\"pos\"], doublet[\"tri\"]), (fit.pos, fit.tri))\n\n for side in (\"L\", \"R\"):\n sx = -1 if side == \"L\" else 1\n ul, ll, ft = B[f\"J_Bip_{side}_UpperLeg\"], B[f\"J_Bip_{side}_LowerLeg\"], B[f\"J_Bip_{side}_Foot\"]\n ua, la, hd = B[f\"J_Bip_{side}_UpperArm\"], B[f\"J_Bip_{side}_LowerArm\"], B[f\"J_Bip_{side}_Hand\"]\n # tassets: three lames on the front and outside of each thigh, hung from the waist\n thigh = side_of(trousers, side)\n arc = (-125, 20) if side == \"L\" else (-20, 125)\n # tops tuck under the belt (small offset there), lower rims flare out\n tas, rims = limb_lames(fit, f\"tasset_{side}\", \"steel\", thigh, ul + [0, 0.085, 0], ul + (ll - ul) * 0.46,\n ((0.0, 0.40, 0.006, 0.026), (0.33, 0.70, 0.018, 0.026), (0.63, 1.0, 0.016, 0.024)),\n arc=arc, rmax=0.16)\n for k, pc in enumerate(tas):\n fit.bind(pc, blend={\"J_Bip_C_Hips\": 0.55 - 0.2 * k, f\"J_Bip_{side}_UpperLeg\": 0.45 + 0.2 * k})\n out += grouped(tas, \"plate\") + grouped(sum((rolled(f\"tasset_{side}{k}\", pc, [r[1]]) for k, (pc, r) in\n enumerate(zip(tas, rims))), []), \"plate\")\n # greaves over the boots, poleyns with wings at the knee\n shin = side_of(boots, side)\n gv, rims = limb_lames(fit, f\"greave_{side}\", \"steel\", shin, ll, ft, ((0.12, 0.80, 0.008, 0.011),), rmax=0.11)\n fit.bind(gv[0], rigid=f\"J_Bip_{side}_LowerLeg\")\n out += grouped(gv + rolled(f\"greave_{side}\", gv[0], rims[0]), \"plate\")\n leg = merge_surfaces((trousers[\"pos\"], trousers[\"tri\"]), (boots[\"pos\"], boots[\"tri\"]))\n jg, jr = joint_guard(fit, f\"poleyn_{side}\", f\"J_Bip_{side}_LowerLeg\", f\"J_Bip_{side}_Foot\", (0, 0, -1), side,\n side_of(trousers, side), r=0.036, wing=0.060)\n for pc in jg:\n fit.bind(pc, rigid=f\"J_Bip_{side}_LowerLeg\")\n out += grouped(jg + sum((rolled(f\"poleyn_{side}{k}\", pc, [rim]) for k, (pc, rim) in enumerate(zip(jg, jr))), []),\n \"plate\")\n # vambraces and couters with wings\n fore = limb_surface(fit, (f\"{side}_LowerArm\",), side)\n vb, rims = limb_lames(fit, f\"vambrace_{side}\", \"steel\", fore, la, hd, ((0.12, 0.64, 0.017, 0.020),), rmax=0.11)\n fit.bind(vb[0], rigid=f\"J_Bip_{side}_LowerArm\")\n out += grouped(vb + rolled(f\"vambrace_{side}\", vb[0], rims[0]), \"plate\")\n # leather gauntlet cuff over the lower forearm, belled toward the elbow, snug at the wrist\n gc, _ = limb_lames(fit, f\"gauntlet_{side}\", \"glove\", fore, la, hd, ((0.50, 1.05, 0.030, 0.010),), rmax=0.11,\n thickness=0.004)\n fit.bind(gc[0], rigid=f\"J_Bip_{side}_LowerArm\")\n out += grouped(gc, \"gloves\")\n arm = limb_surface(fit, (f\"{side}_LowerArm\", f\"{side}_UpperArm\"), side)\n jg, jr = joint_guard(fit, f\"couter_{side}\", f\"J_Bip_{side}_LowerArm\", f\"J_Bip_{side}_Hand\", (0, 0, 1), side,\n arm, r=0.030, wing=0.056, depth=0.022)\n for pc in jg:\n fit.bind(pc, rigid=f\"J_Bip_{side}_LowerArm\")\n out += grouped(jg + sum((rolled(f\"couter_{side}{k}\", pc, [rim]) for k, (pc, rim) in enumerate(zip(jg, jr))), []),\n \"plate\")\n del leg, arm, ua, sx\n\n # 5: one wide belt over the breastplate's lower edge and the tasset tops, square steel buckle. It is\n # cast onto the plate and trousers only: cast onto the tassets it ballooned out over their rims, and\n # with the body skin in the set it wrapped around the hanging forearms and stuck out once they moved.\n waist = merge_surfaces((cuirass[\"pos\"], cuirass[\"tri\"]), (trousers[\"pos\"], trousers[\"tri\"]))\n b1, front1 = belt(fit, \"belt\", \"leather\", waist, hips[1] + 0.052, height=0.040, offset=0.005)\n out += [b1]\n fx, fy, fz = np.eye(3)\n for k, (dx, dy, hx, hy) in enumerate(((0, 0.013, 0.019, 0.0028), (0, -0.013, 0.019, 0.0028),\n (0.016, 0, 0.0028, 0.016), (-0.016, 0, 0.0028, 0.016))):\n bx = box(f\"buckle{k}\", \"metal\", front1 + [dx, dy, -0.005], (fx, fy, fz), (hx, hy, 0.003))\n out += grouped([fit.bind(bx, rigid=\"J_Bip_C_Hips\")], \"belt\")\n out += grouped([fit.bind(box(\"buckle_tongue\", \"metal\", front1 + [0, 0, -0.006], (fx, fy, fz), (0.0018, 0.012, 0.002)),\n rigid=\"J_Bip_C_Hips\")], \"belt\")\n\n # 6: tabard front (to the ankle) and back (to the knee), cloth, cream border\n plates = [p for p in out if p.get(\"group\") == \"plate\" and \"roll\" not in p[\"material\"]]\n legs = merge_surfaces((trousers[\"pos\"], trousers[\"tri\"]), (boots[\"pos\"], boots[\"tri\"]),\n *[(p[\"pos\"], p[\"tri\"]) for p in plates if \"breastplate\" not in p[\"material\"]])\n under = merge_surfaces((b1[\"pos\"], b1[\"tri\"]), (cuirass[\"pos\"], cuirass[\"tri\"]), (trousers[\"pos\"], trousers[\"tri\"]))\n ytop = hips[1] + 0.040\n for nm, deg, hw, length in ((\"tabard\", 0, 0.105, ytop - 0.17), (\"tabard_back\", 180, 0.12, ytop - knee + 0.02)):\n tb, grid = panel(fit, nm, \"signature\", under, legs, ytop, deg, hw, length)\n tb[\"group\"] = \"tabard\"\n out.append(tb)\n for tn, line, w in ((f\"{nm}_hem\", grid[:, -1], 0.016), (f\"{nm}_edge0\", grid[0], 0.012),\n (f\"{nm}_edge1\", grid[-1], 0.012)):\n out += grouped([inherit(ribbon(tn, \"heraldry\", line, width=w, lift=0.0015, normals=near_normals(tb, line)), tb)],\n \"tabard\")\n\n # spaulders over doublet and breastplate (before the mantle, which lies over them)\n for side in (\"L\", \"R\"):\n sp, rims = pauldron(fit, f\"spaulder_{side}\", \"steel\", plate_body, side=side,\n lames=((0, 56, 0.026, 0.034), (47, 73, 0.024, 0.032), (65, 91, 0.022, 0.030),\n (83, 108, 0.020, 0.028)), spread=108)\n out += grouped(sp, \"plate\") + grouped(sum((rolled(f\"spaulder_{side}{k}\", pc, [rim]) for k, (pc, rim) in\n enumerate(zip(sp, rims))), []), \"plate\")\n\n # 7: the hooded mantle over all of it\n rolls = [p for p in out if p[\"material\"].startswith(\"OUTFIT_breastplate_roll\")]\n shoulders = merge_surfaces((cuirass[\"pos\"], cuirass[\"tri\"]), *[(p[\"pos\"], p[\"tri\"]) for p in rolls],\n (doublet[\"pos\"], doublet[\"tri\"]), (col[\"pos\"], col[\"tri\"]), (fit.pos, fit.tri))\n mt, mgrid, hood = mantle(fit, \"mantle\", \"signature\", shoulders)\n out += grouped([mt, hood], \"mantle\")\n for k, edge in enumerate((mgrid[0], mgrid[-1])):\n out += grouped([fit.bind(ball(f\"mantle_clasp{k}\", \"gold\", edge[0] + (edge[0] - nk) * 0.03, 0.011,\n squash=(1, 1, 0.55)), rigid=\"J_Bip_C_UpperChest\")], \"mantle\")\n\n out += shield(fit, \"shield\", \"L\")\n out += sword(fit, \"R\", hilt=\"metal\")\n return [p for p in out if p is not None]\n\n\nCOSTUMES = {\"lord\": lord, \"lord_tunic\": lord_tunic, \"knight_dress\": knight_dress,\n # a benchmark, NOT FOR THE GAME (tools/saber_study.py)\n\"\"\"Small rig tools for authoring poses on a VRoid skeleton: rotate a bone in world space, two-bone\nleg and arm IK, aiming a held prop (the sword) at a direction, and gripping a sword so its blade\nruns through a given point.\n\nPoses here are the same dicts as tools/poses.py (bone name -> 3x3 or 4x4 adjustment in the bone's\nown frame). Everything is solved in model space (VRoid: the character faces -z, y up).\n\"\"\"\nimport numpy as np\n\nfrom poses import as4\n\n\ndef rot_between(a, b):\n a = np.asarray(a, float) / np.linalg.norm(a)\n b = np.asarray(b, float) / np.linalg.norm(b)\n v, c = np.cross(a, b), float(np.dot(a, b))\n if c < -0.999999:\n axis = np.cross(a, [1, 0, 0]) if abs(a[0]) < 0.9 else np.cross(a, [0, 1, 0])\n axis /= np.linalg.norm(axis)\n return 2 * np.outer(axis, axis) - np.eye(3)\n vx = np.array([[0, -v[2], v[1]], [v[2], 0, -v[0]], [-v[1], v[0], 0]])\n return np.eye(3) + vx + vx @ vx / (1 + c)\n\n\nclass Rig:\n def __init__(self, vrm, shape=None, ortho=False):\n \"\"\"ortho: rotate bones through the parent's pure rotation (exact with scaled bones, see\n rotate_world). Off by default so clips authored before it (Aldric's, frozen) stay identical.\"\"\"\n import vroid_portrait as vp\n self.v = vrm\n self.shape = dict(vp.NEUTRAL, **(shape or {}))\n self.names = vrm.nodes_by_name()\n self._bp = vp.bone_pose\n self.ortho = ortho\n self._par = vrm.parents()\n\n def world(self, pose):\n return self.v.node_world(self._bp(self.v, self.shape, pose))\n\n def pos(self, pose, bone):\n return self.world(pose)[self.names[bone]][:3, 3]\n\n def rotate_world(self, pose, bone, R):\n \"\"\"Pre-multiply the bone's world rotation by R (about its joint) by editing its local pose.\n With proportion scales on the skeleton the bone's world matrix is not a rotation; the\n default (legacy) form then leaks shear into the pose and an iterated solve can diverge.\n ortho mode conjugates by the pure rotation of the frame the adjustment lives in.\"\"\"\n W = self.world(pose)\n i = self.names[bone]\n cur = W[i][:3, :3]\n adj_old = as4(pose.get(bone, np.eye(3)))\n if self.ortho:\n par = self._par.get(i)\n base = (W[par] if par is not None else np.eye(4)) @ self.v.local_matrix(i, None)\n u, _, vt = np.linalg.svd(base[:3, :3])\n Q = u @ vt # nearest rotation\n out = dict(pose)\n a = adj_old.copy()\n a[:3, :3] = Q.T @ R @ Q @ adj_old[:3, :3]\n out[bone] = a\n return out\n base = cur @ np.linalg.inv(adj_old[:3, :3]) # world rotation without this bone's adjustment\n new_rot = np.linalg.inv(base) @ (R @ cur)\n out = dict(pose)\n a = adj_old.copy()\n a[:3, :3] = new_rot\n out[bone] = a\n return out\n\n def leg_ik(self, pose, side, target, pole=(0, 0, -1)):\n \"\"\"Bend the leg so the ankle lands on `target`, knee toward `pole` (forward).\"\"\"\n up, lo, ft = f\"J_Bip_{side}_UpperLeg\", f\"J_Bip_{side}_LowerLeg\", f\"J_Bip_{side}_Foot\"\n H, K, A = self.pos(pose, up), self.pos(pose, lo), self.pos(pose, ft)\n l1, l2 = np.linalg.norm(K - H), np.linalg.norm(A - K)\n T = np.asarray(target, float)\n d = np.clip(np.linalg.norm(T - H), 1e-4, l1 + l2 - 1e-4)\n u = (T - H) / np.linalg.norm(T - H)\n w = np.asarray(pole, float) - u * np.dot(pole, u)\n w /= np.linalg.norm(w)\n ca = np.clip((l1 * l1 + d * d - l2 * l2) / (2 * l1 * d), -1, 1)\n K2 = H + l1 * (ca * u + np.sqrt(1 - ca * ca) * w)\n pose = self.rotate_world(pose, up, rot_between(K - H, K2 - H))\n K, A = self.pos(pose, lo), self.pos(pose, ft)\n return self.rotate_world(pose, lo, rot_between(A - K, H + u * d - K))\n\n def plant_feet(self, pose, reference):\n \"\"\"Keep both ankles where they are in `reference` (feet stay on the ground while the hips move).\"\"\"\n for side in \"LR\":\n pose = self.leg_ik(pose, side, self.pos(reference, f\"J_Bip_{side}_Foot\"))\n return pose\n\n def aim(self, pose, bone, local_dir, target_dir):\n \"\"\"Turn `bone` so its local direction (e.g. the sword blade, hand -z) points along target_dir.\"\"\"\n W = self.world(pose)[self.names[bone]][:3, :3]\n cur = W @ np.asarray(local_dir, float)\n return self.rotate_world(pose, bone, rot_between(cur, target_dir))\n\n def arm_ik(self, pose, side, target, pole):\n \"\"\"Bend the arm so the wrist lands on `target`, elbow toward `pole`.\"\"\"\n up, lo, hd = f\"J_Bip_{side}_UpperArm\", f\"J_Bip_{side}_LowerArm\", f\"J_Bip_{side}_Hand\"\n S, E, W = self.pos(pose, up), self.pos(pose, lo), self.pos(pose, hd)\n l1, l2 = np.linalg.norm(E - S), np.linalg.norm(W - E)\n T = np.asarray(target, float)\n d = np.clip(np.linalg.norm(T - S), abs(l1 - l2) + 1e-3, l1 + l2 - 1e-4)\n u = (T - S) / np.linalg.norm(T - S)\n w = np.asarray(pole, float) - u * np.dot(pole, u)\n w /= np.linalg.norm(w)\n ca = np.clip((l1 * l1 + d * d - l2 * l2) / (2 * l1 * d), -1, 1)\n E2 = S + l1 * (ca * u + np.sqrt(1 - ca * ca) * w)\n pose = self.rotate_world(pose, up, rot_between(E - S, E2 - S))\n E, W = self.pos(pose, lo), self.pos(pose, hd)\n return self.rotate_world(pose, lo, rot_between(W - E, S + u * d - E))\n\n def held(self, pose, bone, ref_pose, point):\n \"\"\"Where a point attached to `bone` (given in the reference pose, model space) is in `pose`.\"\"\"\n i = self.names[bone]\n M = self.world(pose)[i] @ np.linalg.inv(self.world(ref_pose)[i])\n return M[:3, :3] @ np.asarray(point, float) + M[:3, 3]\n\n def grip(self, pose, side, ref_pose, fist_ref, fist_target, blade_dir, pole, local_blade=(0, 0, -1), iters=14):\n \"\"\"Put the fist (a point on the hand, from the reference pose) on `fist_target` with the hand's\n `local_blade` axis along `blade_dir`. An analytic arm IK gets close (elbow toward `pole`);\n then cyclic corrections that measure the real fist after every step (aim the hand, swing\n the forearm, swing the upper arm) finish it, which converges even when proportion scales\n shear the arm and the analytic solve alone undershoots.\"\"\"\n hd, lo, up = f\"J_Bip_{side}_Hand\", f\"J_Bip_{side}_LowerArm\", f\"J_Bip_{side}_UpperArm\"\n T = np.asarray(fist_target, float)\n D = np.asarray(blade_dir, float) / np.linalg.norm(blade_dir)\n wrist = T - (self.held(pose, hd, ref_pose, fist_ref) - self.pos(pose, hd))\n pose = self.arm_ik(pose, side, wrist, pole)\n for _ in range(iters):\n for _ in range(2):\n M = self.world(pose)[self.names[hd]][:3, :3]\n pose = self.rotate_world(pose, hd, rot_between(M @ np.asarray(local_blade, float), D))\n for bone in (lo, up):\n j = self.pos(pose, bone)\n f = self.held(pose, hd, ref_pose, fist_ref)\n if np.linalg.norm(f - j) > 1e-4 and np.linalg.norm(T - j) > 1e-4:\n pose = self.rotate_world(pose, bone, rot_between(f - j, T - j))\n miss = np.linalg.norm(T - self.held(pose, hd, ref_pose, fist_ref))\n M = self.world(pose)[self.names[hd]][:3, :3]\n bd = M @ np.asarray(local_blade, float)\n if miss < 2e-3 and np.dot(bd / np.linalg.norm(bd), D) > 0.9995:\n break\n for _ in range(2): # the blade direction is what reads; finish on it\n M = self.world(pose)[self.names[hd]][:3, :3]\n pose = self.rotate_world(pose, hd, rot_between(M @ np.asarray(local_blade, float), D))\n return pose\n\n\ndef grip_points(vrm, shape, ref_pose, fingers=(\"Index\", \"Middle\", \"Ring\", \"Little\")):\n \"\"\"Where each fist closes: the centre of the hole the curled fingers make (poses.fist), in model\n space in `ref_pose` (the hand doesn't move when the fingers curl, so a weapon built there and bound\n to the hand sits in the fist whenever the fingers are curled). Each finger's joints and fingertip\n (the last segment again, bent by its own joint) are fitted with a circle in the plane across the\n hole (the hand's local z runs through it, palm to fingertips in x and y); the hole's centre is the\n mean of the fingers' circle centres. A fixed offset from the wrist, tuned on one hand, missed on\n larger or differently made hands (the shaft ran over the knuckles, the fingers closed under it).\n Returns {side: dict(point, axis, radius)}: radius is the finger-centreline circle's (the shaft's\n radius plus a finger's half-thickness fits).\"\"\"\n import vroid_portrait as vp\n import poses as P\n sh = dict(vp.NEUTRAL, **(shape or {}))\n names = vrm.nodes_by_name()\n out = {}\n for side in \"LR\":\n sx = 1.0 if side == \"R\" else -1.0\n W = vrm.node_world(vp.bone_pose(vrm, sh, P.merge(ref_pose, P.fist(side))))\n H = W[names[f\"J_Bip_{side}_Hand\"]]\n R = H[:3, :3] / np.linalg.norm(H[:3, :3], axis=0)\n o, e1, e2, ax = H[:3, 3], R[:, 0] * sx, R[:, 1], R[:, 2]\n cs, axial, rads = [], [], []\n for f in fingers:\n ks = [names.get(f\"J_Bip_{side}_{f}{k}\") for k in (1, 2, 3)]\n if any(k is None for k in ks):\n continue\n js = [W[k][:3, 3] for k in ks]\n M3 = W[ks[2]][:3, :3] / np.linalg.norm(W[ks[2]][:3, :3], axis=0)\n pts = js + [js[2] + M3 @ np.array([sx, 0.0, 0.0]) * 0.85 * np.linalg.norm(js[2] - js[1])]\n Q = np.array([[(p - o) @ e1, (p - o) @ e2] for p in pts])\n44:def shape(build=\"average\", face=\"plain\", **extra):\n57:def _bind(fit, pcs, bone):\n63:def _group(pcs, g):\n70:def helmet(fit, kind=\"kettle\", role=\"steel\", lift=0.030, name=\"helmet\", rivets=True, trim_role=None):\n124:def coif(fit, role=\"mail\", name=\"coif\", lift=0.017, face=True):\n140:def hood(fit, role=\"cloth\", name=\"hood\", lift=0.022, peak=0.03):\n151:def mail_pattern(w, h, ring_px=7, hem=None):\n164:def quilted(fit, under, name=\"gambeson\", role=\"padding\", y_neck=None, y_hem=None, flare=0.08, split=10.0,\n215:def mail_shirt(fit, under, name=\"hauberk\", role=\"mail\", y_top=None, y_hem=None, sleeve=0.55, flare=0.05):\n249:def riveted_vest(fit, under, name=\"brigandine\", role=\"leather\", rivet_role=\"steel\", y_top=None, y_bottom=None):\n273:def shield(fit, shape=\"heater\", side=\"L\", role=\"signature\", face_role=\"heraldry\", width=0.46, height=0.62,\n311:def _hand_frame(fit, hand=\"R\"):\n323:def spear(fit, length=2.0, grip=0.55, head=0.26, hand=\"R\", shaft_role=\"wood\", name=\"spear\"):\n337:def axe(fit, haft=0.85, blade=0.24, double=False, hand=\"R\", shaft_role=\"wood\", name=\"axe\", grip=0.18):\n356:def dagger(fit, blade=0.24, hand=\"R\", name=\"dagger\"):\n367:def staff(fit, length=1.65, hand=\"R\", wood=\"wood\", head_role=\"gold\", name=\"staff\", grip=0.75):\n382:def bow(fit, length=1.25, hand=\"L\", name=\"bow\", wood=\"wood\"):\n403:def quiver(fit, name=\"quiver\", role=\"leather\"):\n421:def robe(fit, under, name=\"robe\", role=\"signature\", trim=0.012, y_hem=None, flare=0.16, split=0.0, sleeve_flare=0.07):\n457:def witch_hat(fit, name=\"hat\", role=\"signature\", band_role=\"gold\", height=0.32, brim=0.12, lift=0.034):\n484:def puff(fit, side, role=\"signature\", size=1.0, name=None, piping=None, gather=0.48, cap=None, under=None):\n637:def _limb_frame(fit, side, Q, limb=\"arm\"):\n663:def _let_out(fit, pc, limb, knots, prof, ease, folds=6, toward=0.72, behind=0.15, fold_amp=(0.18, 0.22),\n687:def _tuck(fit, pc, covers, limb, gap=0.003, both=False, span=None):\n728:def loose_sleeves(fit, shirt, ease=0.030, cuff=0.70, folds=6):\n740:def tuck_sleeves(fit, shirt, cuff_pcs, gap=0.003):\n745:def _leg_s(fit, y):\n753:def flare_boots(fit, boots, y_top, ease=0.010):\n761:def breeches(fit, trousers, boots, y_hem, y_boot, ease=0.040, folds=7):\n775:def slim_under(fit, trousers, y_hem, pull=0.018, ramp=0.05):\n796:def breastplate(fit, under, role=\"steel\", name=\"breastplate\", y_top=None, y_bottom=None, plackart=True, keel=0.008,\n832:def scale_pattern(w=256, h=128, cols=8):\n847:def skirt_cone(fit, under, y_top, y_hem, flare, cz=None, clear=None, gap=0.012, side=0.0):\n898:def scale_skirt(fit, under, y_top, y_hem, role=\"mail\", name=\"fauld\", flare=0.05, split=0.0, share=0.55, clear=None,\n913:def pleated_skirt(fit, under, y_top, y_hem, role=\"signature\", name=\"skirt_pleats\", flare=0.09, pleats=26, depth=0.012,\n926:def cuffs(fit, role=\"glove\", name=\"cuff\", length=0.38, flare=0.030, lift=0.010):\n944:def round_shield(fit, side=\"L\", radius=0.24, wood=\"wood\", rim=\"steel\", name=\"shield\"):\n969:def halberd(fit, length=2.1, grip=0.80, hand=\"R\", name=\"halberd\"):\nfunction paintMaterial(V, role, map, index, infoRole = role, decal = false) {\n const Rl = V.roles[role] || { mode: \"flat\", color: \"#ff00ff\" }, P = (V.paint || {})[role];\n const u = { uKind: { value: 9 }, uBase: { value: new THREE.Color(0.8, 0.8, 0.8) }, uKey: { value: KEY.clone() },\n uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 },\n uInfo: { value: new THREE.Vector4(roleId(infoRole) / 255, (index % 256) / 255, Math.floor(index / 256) / 255, 1) },\n uEye: { value: V.roles.iris.colors.map(hex) }, uFlat: { value: new THREE.Color() }, uSkinRef: { value: new THREE.Vector3(0.965, 0.878, 0.80) },\n uGold: { value: hex((V.paint && V.paint.gold && V.paint.gold.base) || \"#b08b3f\") },\n uAmbient: { value: new THREE.Vector3(1, 1, 1) }, uKeyCol: { value: new THREE.Vector3(1, 1, 1) }, uRimCol: { value: new THREE.Vector3() },\n uGrain: { value: 0.05 }, uFaceTex: { value: 0 }, uDecal: { value: decal ? 1 : 0 }, uBand: { value: null },\n uSkinTone: { value: new THREE.Vector3(1, 1, 1) }, uShadeOnly: { value: 0 },\n uSkinRamp: { value: 0 }, uSkinL: { value: new THREE.Color() }, uSkinS: { value: new THREE.Color() }, uSkinC: { value: new THREE.Color() },\n tCastInfo: { value: null }, tCastDepth: { value: null }, uCastRes: { value: new THREE.Vector2(1, 1) }, uCastOn: { value: 0 },\n uCastNear: { value: 0.1 }, uCastFar: { value: 40 }, uCastPpm: { value: 1 },\n uMotif: { value: hex((V.paint && V.paint.motif && V.paint.motif.base) || \"#3a44a0\") }, uLift: { value: 0 } };\n if (P) { u.uKind.value = KIND[P.kind] ?? 0; if (P.base) u.uBase.value = hex(P.base); if (P.grain != null) u.uGrain.value = P.grain; }\n else if (Rl.bands) { u.uKind.value = Rl.world ? 6 : 0; u.uBase.value = hex(Rl.bands[Math.min(1, Rl.bands.length - 1)][1]); }\n if (P && P.kind === \"world\") { u.uKey.value = new THREE.Vector3(...V.sun); u.uGrain.value = 0.12; }\n if (P && P.shade) u.uShadeOnly.value = 1; // shadow cards: skin, always in its shade tone\n if (P && P.kind === \"skin\" && P.ramp) { // a designed ramp: lit, shade, deep shade\n u.uSkinRamp.value = 1; u.uSkinL.value = hex(P.ramp[0]); u.uSkinS.value = hex(P.ramp[1]); u.uSkinC.value = hex(P.ramp[2]);\n }\n if (P && P.kind === \"skin\" && P.base) { // skin tone: the base colour against the default light skin\n const c = hex(P.base); u.uSkinTone.value.set(c.r / 0.973, c.g / 0.882, c.b / 0.835);\n }\n if (role === \"face\" && map) u.uFaceTex.value = 1;\n if (role === \"hair\" && map) u.uAlpha.value = 1;\n if (role === \"iris\") { u.uKind.value = 7; u.uAlpha.value = 1; }\n else if (role === \"white\" || role === \"highlight\") { u.uKind.value = map ? 8 : 9; if (map) u.uAlpha.value = 1; u.uFlat.value = hex(Rl.color || \"#ffffff\"); }\n else if (!P && Rl.mode === \"flat\") { u.uKind.value = 9; u.uFlat.value = hex(Rl.color); if (map) u.uAlpha.value = role === \"line\" ? 2 : 1; }\n if (role === \"brow\") u.uLift.value = BROW_LIFT;\n if (role === \"mouth\" && map) u.uKind.value = 10;\n u.uBand.value = u.uGold.value.clone();\n const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide,\n extensions: { derivatives: true } });\n // meshes without plate data or a cloth edge read zeros, not whatever another program left in that slot\n m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] };\n return m;\n}\n\n// ---- models ------------------------------------------------------------------------------------------------------\nconst loader = new GLTFLoader();\nconst chars = new Map(); // name -> loaded character\nlet ground = null;\nconst stage = new THREE.Group(); // the duel: both fighters stand on it; the turn slider rotates it\nscene.add(stage);\n\nasync function setView(view, clip) {\n const changed = view !== state.view;\n state.view = view;\n document.querySelectorAll(\"[data-view]\").forEach(b => b.setAttribute(\"aria-pressed\", String(b.dataset.view === view)));\n buildWho();\n statusEl.hidden = false; statusEl.textContent = view === \"duel\" ? \"Loading both fighters…\" : \"Loading the model…\";\n try {\n const cs = await Promise.all(activeNames().map(loadCharacter));\n const g = view !== \"bust\" && !ROW_VIEW() ? await loadGround() : null; // a row of models stands on nothing\n for (const c of chars.values()) { c.turn.removeFromParent(); scene.remove(c.world); }\n if (ground) scene.remove(ground.root);\n if (g) scene.add(g.root);\n const v = CAM_VIEW(), lead = cs[0].info;\n paint.mat.uniforms.uGap.value = lead.depth_gap;\n stage.rotation.y = 0;\n for (const c of cs) {\n scene.add(c.world);\n c.turn.rotation.set(0, 0, 0);\n if (view === \"lineup\") {\n const i = LINEUP.order.indexOf(c.name);\n stage.add(c.turn);\n c.turn.position.set(lineupX(i), 0, 0); c.holder.position.set(0, 0, 0);\n } else if (view === \"compare\") { // placed by layoutCompare, once all are in\n stage.add(c.turn); c.holder.position.set(0, 0, 0);\n } else if (view === \"duel\") {\n const pl = CAM.duel.place[c.name];\n stage.add(c.turn);\n c.turn.position.set(...pl.pos); c.turn.rotation.y = THREE.MathUtils.degToRad(pl.yaw); c.holder.position.set(0, 0, 0);\n } else {\n scene.add(c.turn);\n c.turn.position.set(v.pivot[0], 0, v.pivot[2]); c.holder.position.set(-v.pivot[0], 0, -v.pivot[2]);\n }\n }\n statusEl.hidden = true;\n if (view === \"compare\") layoutCompare();\n buildParts(); applyMaterials(); size(); matchCamera();\n setYaw(changed || view === \"duel\" ? VIEW_YAW[view] : state.yaw);\n const want = clip || (view === \"duel\" ? \"clash\" : (CLIP_VIEW[state.clip] === \"battle\" ? state.clip : \"idle\"));\n if (view === \"duel\") setClip(\"clash\", SHEET ? null : \"idle\"); else if (view === \"battle\") setClip(want);\n else if (view === \"lineup\") setClip(clip && CLIP_VIEW[clip] === \"battle\" ? clip : \"idle\"); else setClip(\"idle\");\n animate(0);\n scene.updateMatrixWorld(true); cs.forEach(c => c.cloths.forEach(cl => { cl.reset(false); cl.write(); }));\n } catch (e) { console.error(e); statusEl.textContent = \"The model didn't load.\"; }\n}\n\n// ---- rendering -------------------------------------------------------------------------------------------------------\nfunction applySkin(meshes) {\n // the picked tone on every skin material (face, body, shadow cards); the built tone is kept to go back to\n u.uBand.value = u.uGold.value.clone();\n const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide,\n extensions: { derivatives: true } });\n // meshes without plate data or a cloth edge read zeros, not whatever another program left in that slot\n m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] };\n return m;\n}\n\n// ---- models ------------------------------------------------------------------------------------------------------\nconst loader = new GLTFLoader();\nconst chars = new Map(); // name -> loaded character\nlet ground = null;\nconst stage = new THREE.Group(); // the duel: both fighters stand on it; the turn slider rotates it\nscene.add(stage);\n// the lineup: every enemy model standing in a row (camera.json's lineup), each turning in place\nconst LINEUP = CAM.lineup || { order: [], spacing: 0.9 };\nconst ROW_VIEW = () => state.view === \"lineup\" || state.view === \"compare\"; // several models in a row, each turning in place\nconst CAM_VIEW = () => state.view === \"duel\" || ROW_VIEW() ? CAM.duel.cam : charDef(state.who).cams[state.view];\nconst activeNames = () => state.view === \"duel\" ? [CAM.duel.order.player, CAM.duel.order.opponent]\n : state.view === \"lineup\" ? LINEUP.order : state.view === \"compare\" ? state.compare : [state.who];\nconst active = () => activeNames().map(n => chars.get(n)).filter(Boolean);\n\nasync function parseGlb(file) {\n const j = await (await fetch(file)).json();\n"}exec_commandcat tools/terrain.py && sed -n '796,832p' tools/gear.py && sed -n '164,215p' tools/gear.py && sed -n '445,474p' tools/outfit.py && sed -n '630,655p' review/vroid-02/index.html (+1 more)
command
cat tools/terrain.py && sed -n '796,832p' tools/gear.py && sed -n '164,215p' tools/gear.py && sed -n '445,474p' tools/outfit.py && sed -n '630,655p' review/vroid-02/index.html node - <<'JS' const {chromium}=require('~/context/sortie-node_modules/playwright'); console.log(chromium.executablePath()); JSresult, 4 lines
Script completed Wall time 0.1 seconds Output: {"chunk_id":"f2fbf0","wall_time_seconds":0.000004581,"exit_code":0,"original_token_count":3232,"output":"\"\"\"Battle-scene terrain built in code: the ground a unit stands on in the side-view battle.\n\nPieces use the same primitive dicts as outfit.py, with `world=True` so the renderer keeps them\nfixed while the character turns. Model coordinates: metres, y up, ground at y = 0.\n\"\"\"\nimport math\n\nimport numpy as np\n\nfrom outfit import grid_mesh, piece, ball\n\n\ndef _noise(x, z, seed):\n rng = np.random.default_rng(seed)\n out = np.zeros_like(x)\n for k in range(5):\n fx, fz, ph = rng.uniform(1.5, 6.0), rng.uniform(1.5, 6.0), rng.uniform(0, 2 * math.pi, 2)\n out += np.sin(x * fx + ph[0]) * np.cos(z * fz + ph[1]) / (k + 1)\n return out\n\n\ndef plains(width=4.2, depth=1.8, thick=0.25, seed=3, tufts=26, stones=5):\n \"\"\"A raised plains platform: grassy top with gentle bumps, an earth bank on the sides, grass\n tufts and a few stones.\"\"\"\n out = []\n nx, nz = 60, 26\n xs = np.linspace(-width / 2, width / 2, nx)\n zs = np.linspace(-depth / 2, depth / 2, nz)\n X, Z = np.meshgrid(xs, zs, indexing=\"ij\")\n Y = 0.012 * _noise(X, Z, seed) - 0.004\n # keep it flat where the unit stands\n Y *= np.clip(np.hypot(X / 0.5, Z / 0.4) - 0.6, 0, 1)\n top = np.stack([X, Y, Z], -1)\n pos, tri = grid_mesh(top)\n out.append(piece(\"ground\", \"grass\", pos, tri, outward_from=[0, -5, 0]))\n # earth bank on the four sides\n def bank(edge, name):\n lo = edge.copy()\n lo[:, 1] = -thick\n lo[:, 0] *= 1.02\n lo[:, 2] *= 1.02\n P = np.stack([edge, lo], 1)\n p_, t_ = grid_mesh(P)\n return piece(name, \"dirt\", p_, t_, outward_from=[0, -thick / 2, 0])\n out.append(bank(top[:, 0], \"bank_back\"))\n out.append(bank(top[:, -1], \"bank_front\"))\n out.append(bank(top[0, :], \"bank_left\"))\n out.append(bank(top[-1, :], \"bank_right\"))\n rng = np.random.default_rng(seed + 1)\n for i in range(tufts):\n x, z = rng.uniform(-width / 2 * 0.95, width / 2 * 0.95), rng.uniform(-depth / 2 * 0.9, depth / 2 * 0.9)\n if abs(x) < 0.45 and abs(z) < 0.35:\n continue\n h = rng.uniform(0.04, 0.09)\n blades = []\n for b in range(5):\n a = rng.uniform(0, 2 * math.pi)\n lean = np.array([math.cos(a), 0, math.sin(a)]) * rng.uniform(0.01, 0.03)\n base = np.array([x, 0.0, z]) + lean * 0.4\n tip = base + np.array([0, h, 0]) + lean\n w = np.array([-math.sin(a), 0, math.cos(a)]) * 0.007\n blades.append(np.array([base - w, base + w, tip]))\n pos = np.concatenate(blades)\n tri = np.arange(len(pos)).reshape(-1, 3)\n out.append(piece(f\"tuft{i}\", \"grass\", pos, tri, outward_from=[x, -1, z]))\n for i in range(stones):\n x, z = rng.uniform(-width / 2 * 0.9, width / 2 * 0.9), rng.uniform(-depth / 2 * 0.8, depth / 2 * 0.8)\n if abs(x) < 0.5 and abs(z) < 0.4:\n continue\n r = rng.uniform(0.04, 0.09)\n out.append(ball(f\"stone{i}\", \"stone\", [x, r * 0.35, z], r, squash=(1.0, 0.55, 0.8)))\n for p in out:\n p[\"world\"] = True\n return out\n\n\nTERRAIN = {\"plains\": plains}\ndef breastplate(fit, under, role=\"steel\", name=\"breastplate\", y_top=None, y_bottom=None, plackart=True, keel=0.008,\n back=True, arm=54.0):\n \"\"\"A breastplate (and backplate) as outline plates: a scooped neckline, armholes cut away at the\n sides, a slight point at the waist, a central ridge, rolled edges; a plackart over the belly.\n arm: where the armhole's scoop begins (degrees round the torso from the front); larger keeps the\n plate's full width up to the armpits instead of a bib over the middle of the chest.\"\"\"\n B = fit.bone\n nk, hips = B[\"J_Bip_C_Neck\"], B[\"J_Bip_C_Hips\"]\n y_top = nk[1] - 0.05 if y_top is None else y_top\n y_bottom = hips[1] + 0.03 if y_bottom is None else y_bottom\n cz = float(hips[2])\n tc = TorsoChart(under, y_bottom - 0.04, y_top + 0.04, cz=cz, du=2.5, dv=0.007)\n span = y_top - y_bottom\n top = lambda u: y_top - 0.035 * max(0.0, 1 - abs(u) / 34) ** 1.4 - 0.11 * span * max(0.0, (abs(u) - arm) / 42) ** 1.3\n bottom = lambda u: y_bottom - 0.018 * max(0.0, 1 - abs(u) / 40) ** 1.5\n ridge = lambda u, v, s, t: keel * math.exp(-(u / 9.0) ** 2) * math.sin(math.pi * min(1.0, t * 1.15))\n front, fx = outline_plate(name, role, tc, -96, 96, bottom, top, offset=0.014, crown=0.010, flare=ridge, thickness=0.004,\n nu=72, nv=26, roll=0.0034, roll_edges=(\"top\", \"bottom\"))\n fit.bind(front, allow=(\"Spine\", \"Chest\", \"UpperChest\", \"Bust\", \"Hips\"), fallback=\"J_Bip_C_Chest\")\n out = [front] + [O.inherit(p, front) for p in fx]\n if back:\n btop = lambda u: y_top - 0.01 - 0.11 * span * max(0.0, (abs(((u % 360) - 180)) - (arm - 4)) / 44) ** 1.3\n bk, bx = outline_plate(f\"{name}_back\", role, tc, 96, 264, lambda u: y_bottom, btop, offset=0.014, crown=0.006,\n thickness=0.004, nu=60, nv=22, roll=0.0034, roll_edges=(\"top\", \"bottom\"))\n fit.bind(bk, allow=(\"Spine\", \"Chest\", \"UpperChest\", \"Bust\", \"Hips\"), fallback=\"J_Bip_C_Chest\")\n out += [bk] + [O.inherit(p, bk) for p in bx]\n if plackart: # over the belly, its top rounded up to a point\n ptop = lambda u: y_bottom + 0.36 * span - 0.10 * span * (abs(u) / 50) ** 1.6\n pl, px = outline_plate(f\"{name}_plackart\", role, tc, -50, 50, bottom, ptop, offset=0.020, crown=0.008, flare=ridge,\n thickness=0.004, nu=40, nv=12, roll=0.0034, roll_edges=(\"top\",),\n rivets=(0.05, 0.010, 0.0035), rivet_role=role)\n fit.bind(pl, allow=(\"Spine\", \"Chest\", \"Hips\"), fallback=\"J_Bip_C_Spine\")\n out += [pl] + [O.inherit(p, pl) for p in px]\n return _group(out, \"plate\")\n\n\ndef scale_pattern(w=256, h=128, cols=8):\ndef quilted(fit, under, name=\"gambeson\", role=\"padding\", y_neck=None, y_hem=None, flare=0.08, split=10.0,\n stitch=16.0, sleeves=True, sleeve_end=0.92):\n \"\"\"A padded coat quilted in vertical channels (each channel puffs between stitched seams): a body\n from the neck to `y_hem` (below the hips it becomes a skirt over a cone, split at the front), and\n sleeves quilted along the arm. `under`: the Surface it sits on (the shirt).\"\"\"\n B = fit.bone\n nk, hips = B[\"J_Bip_C_Neck\"], B[\"J_Bip_C_Hips\"]\n y_neck = nk[1] - 0.03 if y_neck is None else y_neck\n y_hem = hips[1] - 0.22 if y_hem is None else y_hem\n cz = float(hips[2])\n y_waist = hips[1] + 0.06\n tc = TorsoChart(under, y_waist - 0.04, y_neck + 0.03, cz=cz, du=3.0, dv=0.008)\n out = []\n us = np.arange(-180 + stitch, 180, stitch)\n seams = [[(u, y_waist), (u, y_neck)] for u in us]\n\n def neck_top(u): # lower at the front: a round neckline\n return y_neck - 0.035 * max(0.0, 1 - abs(u) / 70) ** 1.5\n body, _ = outline_plate(name, role, tc, -178, 178, lambda u: y_waist, neck_top, offset=0.008, thickness=0.006,\n nu=120, nv=26, roll=0.004, roll_edges=(\"top\",), seams=seams, groove=(0.004, 0.004),\n panel_crown=0.006, decal_px=700)\n fit.bind(body, allow=(\"Spine\", \"Chest\", \"UpperChest\", \"Bust\", \"Hips\", \"Neck\", \"Shoulder\"), fallback=\"J_Bip_C_Chest\")\n out.append(body)\n # the skirt: a cone from the waist down, split at the front\n r0 = lambda u: float(tc.radius(u, y_waist)) + 0.010\n r0m = float(np.mean([r0(u) for u in range(-180, 180, 15)]))\n cone = ConeChart(lambda u, v: np.vectorize(r0)(u) + flare * np.clip((y_waist - v) / (y_waist - y_hem), 0, 1.2) ** 1.2,\n cz=cz)\n sk_seams = [[(u, y_hem), (u, y_waist)] for u in us if abs(u) > split + 4]\n skirt, _ = outline_plate(f\"{name}_skirt\", role, cone, split, 360 - split, lambda u: y_hem, lambda u: y_waist + 0.012,\n offset=0.002, thickness=0.006, nu=110, nv=18, roll=0.004, roll_edges=(\"bottom\", \"left\", \"right\"),\n seams=[[((u % 360), a), ((u % 360), b)] for (u, a), (_, b) in sk_seams],\n groove=(0.004, 0.004), panel_crown=0.006, decal_px=600)\n fit.bind(skirt, allow=(\"Hips\", \"UpperLeg\"), fallback=\"J_Bip_C_Hips\")\n stiffen(skirt, fit, share=0.55)\n out.append(skirt)\n if sleeves:\n for side in (\"L\", \"R\"):\n for seg, (a, b, v0, v1) in enumerate(((f\"J_Bip_{side}_UpperArm\", f\"J_Bip_{side}_LowerArm\", -0.05, 1.02),\n (f\"J_Bip_{side}_LowerArm\", f\"J_Bip_{side}_Hand\", -0.02, sleeve_end))):\n arm = O.limb_surface(fit, (a.replace(\"J_Bip_\", \"\"), b.replace(\"J_Bip_\", \"\")), side)\n lc = LimbChart(arm, B[a], B[b], front=(0, 0, -1))\n sl_seams = [[(u, v0), (u, v1)] for u in range(-150, 180, 30)]\n sl, _ = outline_plate(f\"{name}_sleeve_{side}{seg}\", role, lc, -180, 180, lambda u, v1=v1: v1,\n lambda u, v0=v0: v0, offset=0.010, thickness=0.005, nu=48, nv=14, roll=0,\n seams=sl_seams, groove=(0.005, 0.003), panel_crown=0.004, decal_px=700)\n fit.bind(sl, allow=(a.replace(\"J_Bip_\", \"\"), b.replace(\"J_Bip_\", \"\")), fallback=a)\n out.append(sl)\n return _group(out, \"padding\")\n\n\ndef mail_shirt(fit, under, name=\"hauberk\", role=\"mail\", y_top=None, y_hem=None, sleeve=0.55, flare=0.05):\ndef cape(fit, name, role, under, length=1.0, phi=0.55, seg=44, rows=18, top_clear=0.003,\n clear=(0.010, 0.045), folds=7, fold_depth=0.010):\n \"\"\"A cape whose top edge lies on the tunic around the base of the neck, clasped at the\n collarbones, then settled by the cloth solve so it rests on the shoulders and falls clear.\"\"\"\n nk = fit.bone[\"J_Bip_C_Neck\"]\n ph = np.linspace(-phi, phi, seg) * math.pi # 0 = straight back\n rad = np.stack([np.sin(ph), np.zeros_like(ph), np.cos(ph)], 1)\n top = []\n for a, d in zip(ph, rad):\n front = (1 - math.cos(a)) / 2\n o = np.array([nk[0], nk[1] - 0.013 - 0.032 * front, nk[2]]) # under the collar, down to the clasps\n r = under.cast(o, d, rmax=0.3, far=True)\n top.append(o + d * ((0.08 if np.isnan(r) else r) + top_clear))\n top = np.array(top)\n P = np.zeros((seg, rows, 3))\n for j, t in enumerate(np.linspace(0, 1, rows)):\n P[:, j] = top + rad * (0.10 * min(1.0, t * 4)) + np.array([0, -length * t, 0])\n pinned = np.zeros((seg, rows), bool)\n pinned[:, 0] = True\n P = drape(P, under, clear[0] + (clear[1] - clear[0]) * np.linspace(0, 1, rows), pinned)\n for j, t in enumerate(np.linspace(0, 1, rows)):\n P[:, j] += rad * (fold_depth * t * np.sin(ph * folds * 2 + 0.5))[:, None]\n pos, tri = grid_mesh(P)\n pc = piece(name, role, pos, tri, outward_from=nk + [0, -0.3, 0], axis=[0, 1, 0])\n fit.bind(pc, allow=(\"Spine\", \"Chest\", \"UpperChest\", \"Neck\", \"Shoulder\"), fallback=\"J_Bip_C_UpperChest\")\n pc[\"grid\"] = (seg, rows) # the viewer simulates it as cloth: top row pinned\n return pc, P\n\n\ndef tails(fit, name, role, under, y_top, length=0.36, front_gap=60, seg=40, rows=12, clear=(0.012, 0.030)):\nconst targets = { rt: null, rtInfo: null, key: \"\" };\nfunction targetsFor(w, h) {\n const key = `${w}x${h}`;\n if (targets.key === key) return;\n [targets.rt, targets.rtInfo].forEach(t => t && t.dispose());\n const o = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter };\n targets.rt = new THREE.WebGLRenderTarget(w, h, o);\n targets.rtInfo = new THREE.WebGLRenderTarget(w, h, { ...o, depthTexture: new THREE.DepthTexture(w, h) });\n targets.key = key;\n}\n\n// ---- cloth -------------------------------------------------------------------------------------------------------\n// The skinned cape/tails stay hidden and provide the pinned row (they follow the animated body);\n// a plain display mesh in world space shows the simulated cloth. Colliders ride the bones.\nconst _v = new THREE.Vector3(), _a = new THREE.Vector3(), _ab = new THREE.Vector3(), _cp = new THREE.Vector3();\nconst _A = new THREE.Vector3(), _B = new THREE.Vector3();\nclass Cloth {\n constructor(skinned, U, V, trims, capsules, bone, closed = false, hemOnly = false) {\n this.skinned = skinned; this.U = U; this.V = V; this.trims = trims; this.closed = closed; this.hemOnly = hemOnly;\n this.n = skinned.geometry.attributes.position.count;\n this.caps = capsules.map(c => ({ a: bone(c.bones[0]), b: bone(c.bones[1]), r: c.r + 0.006 })).filter(c => c.a && c.b);\n this.x = new Float32Array(this.n * 3); this.prev = new Float32Array(this.n * 3);\n const idx = (i, j) => i * V + j, links = [], bends = [], edge = new Float32Array(this.n);\n for (let i = 0; i < U; i++) for (let j = 0; j < V; j++) {\n // a closed cloth (a skirt) wraps around: the last column links back to the first\n if (i + 1 < U || closed) links.push([idx(i, j), idx((i + 1) % U, j)]);\n"}{"chunk_id":"634a5d","wall_time_seconds":0.00000483,"exit_code":1,"original_token_count":273,"output":"node:internal/modules/cjs/loader:1386\n throw err;\n ^\n\nError: Cannot find module 'playwright-core'\nRequire stack:\n- ~/context/sortie-node_modules/playwright/index.js\n- ~/work/lowmarch/[stdin]\n at Function._resolveFilename (node:internal/modules/cjs/loader:1383:15)\n at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)\n at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22)\n at Function._load (node:internal/modules/cjs/loader:1192:37)\n at TracingChannel.traceSync (node:diagnostics_channel:328:14)\n at wrapModuleLoad (node:internal/modules/cjs/loader:237:24)\n at Module.require (node:internal/modules/cjs/loader:1463:12)\n at require (node:internal/modules/helpers:147:16)\n at Object.<anonymous> (~/context/sortie-node_modules/playwright/index.js:17:18)\n at Module._compile (node:internal/modules/cjs/loader:1706:14) {\n code: 'MODULE_NOT_FOUND',\n requireStack: [\n '~/context/sortie-node_modules/playwright/index.js',\n '~/work/lowmarch/[stdin]'\n ]\n}\n\nNode.js v22.21.1\n"}exec_commandNODE_PATH=~/context/sortie-node_modules node - <<'JS' (+1 more)
command
NODE_PATH=~/context/sortie-node_modules node - <<'JS' const {chromium}=require('playwright'); console.log(chromium.executablePath()); (async()=>{const b=await chromium.launch({headless:true,args:['--no-sandbox']});console.log('browser ready');await b.close()})() JS sed -n '550,568p' review/vroid-02/index.html && rg -n 'GRADE|KEY =|BROW_LIFT|vNormal|vN|shin|sheen' review/vroid-02/index.html | head -30 && sed -n '68,112p' tools/export_glb.pyresult, 4 lines
Script completed Wall time 0.9 seconds Output: {"chunk_id":"1ce78c","wall_time_seconds":0.694315485,"exit_code":0,"original_token_count":18,"output":"/opt/ms-playwright/chromium-1248/chrome-linux64/chrome\nbrowser ready\n"}{"chunk_id":"fd2a4a","wall_time_seconds":0.00000402,"exit_code":0,"original_token_count":897,"output":" vec4 ni = texture2D(tInfo, q);\n if (ni.a > 0.5) { best = ni; bq = q; }\n }\n }\n if (best.a > 0.5) {\n int r = rid(best);\n if (r >= 4 && r <= 7) { gl_FragColor = vec4(0.0); return; }\n gl_FragColor = vec4(ink(texture2D(tColor, bq).rgb), 1.0); return;\n }\n gl_FragColor = vec4(0.0); return;\n }\n vec3 col = texture2D(tColor, uv).rgb; int r0 = rid(inf); float p0 = pid(inf); float z0 = z(uv);\n bool feature = r0 >= 4 && r0 <= 9;\n if (r0 == 9) { // the open mouth's rim: a lip line where it meets the face\n for (int k = 0; k < 8; k++) {\n float a = float(k) * 0.785398;\n vec2 q = uv + vec2(cos(a), sin(a)) * uSil * 0.9 * px;\n vec4 ni = texture2D(tInfo, q);\n if (ni.a > 0.5 && rid(ni) == 1) { col = mix(ink(texture2D(tColor, q).rgb), vec3(0.30, 0.10, 0.12), 0.4); break; }\n318: varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate;\n321: vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate;\n373: varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate;\n423: vec3 n = normalize(vN); if (!gl_FrontFacing) n = -n;\n851:const KEY = new THREE.Vector3(-0.45, 0.55, 0.70).normalize();\n853:const GRADE = { battle: { ambient: [0.84, 0.87, 0.98], key: [1.05, 1.0, 0.92], rim: [0.38, 0.34, 0.26] },\n857:const BROW_LIFT = 0.04;\n888: if (role === \"brow\") u.uLift.value = BROW_LIFT;\n1403: const G = GRADE[state.view === \"bust\" ? \"bust\" : \"battle\"]; // stage grade, shared by the characters and the stage\ndef export(portrait, palette, path, max_tex=512, only_world=False):\n \"\"\"portrait: vroid_portrait.Portrait. palette: full char -> hex map. only_world: export just\n the scenery (the character goes out skinned through export_skinned).\"\"\"\n bin_ = bytearray()\n views, accessors, meshes, nodes, materials, textures, images = [], [], [], [], [], [], []\n tex_index = {}\n\n def add_view(data, target=None):\n while len(bin_) % 4:\n bin_.append(0)\n off = len(bin_)\n bin_.extend(data)\n v = dict(buffer=0, byteOffset=off, byteLength=len(data))\n if target:\n v[\"target\"] = target\n views.append(v)\n return len(views) - 1\n\n def add_acc(arr, kind, comp, target):\n arr = np.ascontiguousarray(arr)\n vi = add_view(arr.tobytes(), target)\n a = dict(bufferView=vi, componentType=comp, count=int(arr.shape[0]), type=kind)\n if kind == \"VEC3\" and comp == 5126:\n a[\"min\"] = arr.min(0).tolist()\n a[\"max\"] = arr.max(0).tolist()\n accessors.append(a)\n return len(accessors) - 1\n\n def add_texture(key, rgba):\n if key in tex_index:\n return tex_index[key]\n im = Image.fromarray(rgba)\n if max(im.size) > max_tex:\n k = max_tex / max(im.size)\n im = im.resize((max(1, int(im.width * k)), max(1, int(im.height * k))), Image.LANCZOS)\n b = io.BytesIO()\n im.save(b, \"PNG\", optimize=True)\n vi = add_view(b.getvalue())\n images.append(dict(bufferView=vi, mimeType=\"image/png\"))\n textures.append(dict(source=len(images) - 1, sampler=0))\n tex_index[key] = len(textures) - 1\n return tex_index[key]\n\n for k, (p, role) in enumerate(zip(portrait.prims, portrait.roles)):\n if role == \"skip\" or not len(p[\"tri\"]) or (only_world and not p.get(\"world\")):\n"}