agent

+44:10
reasoning

The script's hardcoded center and radius values for the skull appear incorrect compared to the real-world measurements. This mismatch likely causes the misalignment. Adjusting these parameters is needed to correct the skull's placement within the simulation.

The center calculation needs verification; the current values position the skull incorrectly based on visual inspection of the mesh. A ray-casting approach using Blender's BVHTree on the sculpted head mesh seems like a more accurate method to determine correct skull placement. This approach will utilize the face and head vertices, excluding the ears, to perform ray intersection calculations.

Initial calculations for the "anime ribbon lock" were flawed; the code needed modification to ensure the inner face is flush with the skull surface, and the outer ridge points outwards. Re-evaluating the scalp dome path for the Valkyrie crown using a (u, v, lift) grid and hairline function is necessary. The hairpin and nape calculations require attention to ensure proper alignment.

Determining the placement for the high-parted curtain bangs involves mapping their path across the forehead, ensuring visibility of the eyebrows. The design needs to sweep down past the temples to frame the cheekbones. The asymmetric wisp requires a delicate 3D placement that ends above the brow ridge.

The Valkyrie Coronet Braid's placement along the crown needs verification, specifically the interlocking sinusoidal diamond-strand plaits. The placement of the flowing battle mane requires careful attention to the root and cascade along the occiput, nape, and down the back, ensuring it clears the backplate. The "Swe" hairstyle also requires examination.

The noble lion mane's eyebrow placement is defined at u = -42.5°..+42.5°, v = 79.4°..93.0°. A full skull-raycast scalp base will be used instead of the old bowl cap, starting at v = 50° in front. Seven swept-back noble lion locks will be rooted along the front/temple hairline, lifting up to form a pompadour and sweeping back over the crown. Temple sideburns and layered nape locks will also be added. The Python script requires updating with the BVHTree skull-chart.

  • read_file{"EndLine":260,"Path":"~/work/lowmarch/tools/blender_sculpt_lead.py","StartLine":190}

    input

    {
      "EndLine": 260,
      "Path": "~/work/lowmarch/tools/blender_sculpt_lead.py",
      "StartLine": 190
    }

    result, 72 lines

    Showing lines 190-260 of 593
    190: 
    191:     # Lock skull/neck boundary vertices on the face mesh so it never separates from Body_00_SKIN
    192:     f_bm = bmesh.new()
    193:     f_verts = [f_bm.verts.new(Pf[i]) for i in range(len(Pf))]
    194:     f_bm.verts.ensure_lookup_table()
    195:     for pr, m in zip(f_prims, mat_names):
    196:         if "Face_00_SKIN" in m:
    197:             for a, b, c in v.accessor(pr["indices"]).reshape(-1, 3):
    198:                 if a != b and b != c and a != c:
    199:                     try:
    200:                         f_bm.faces.new((f_verts[a], f_verts[b], f_verts[c]))
    201:                     except ValueError:
    202:                         pass
    203:     f_bound = np.array([v_.is_boundary for v_ in f_bm.verts], dtype=bool)
    204:     f_bm.free()
    205: 
    206:     # Smooth interior weight (0 on boundary and back of skull)
    207:     front_mask = np.clip((-Pf[:, 2] - (-0.055)) / 0.035, 0.0, 1.0)
    208:     interior = (~f_bound).astype(np.float64) * front_mask
    209: 
    210:     if sex == "f":
    211:         # Sharper Valkyrie jawline taper + defined chin tip + arched expressive brows
    212:         jaw_band = np.exp(-0.5 * ((Pf[:, 1] - (chin_y + 0.28 * span)) / (0.22 * span)) ** 2) * interior
    213:         Pf[:, 0] *= (1.0 - 0.045 * jaw_band)
    214:         # Slight forward nose bridge & chin tip refinement
    215:         nose_y = chin_y + 0.58 * span
    216:         nose_w = np.exp(-0.5 * ((Pf[:, 1] - nose_y) / (0.12 * span)) ** 2) * np.exp(-0.5 * (Pf[:, 0] / 0.012) ** 2) * interior
    217:         Pf[:, 2] -= 0.0022 * nose_w
    218:         # Heroic brow arch: lift outer half of brow and upper lash
    219:         if len(brow_rows):
    220:             bx = np.abs(Pf[brow_rows, 0])
    221:             arch = np.clip((bx - 0.018) / 0.035, 0.0, 1.0)
    222:             Pf[brow_rows, 1] += 0.0022 * (1.0 - 0.3 * arch)
    223:             Pf[brow_rows, 2] -= 0.0008
    224:     else:
    225:         # Strongly defined lord brow & cheekbones
    226:         jaw_band = np.exp(-0.5 * ((Pf[:, 1] - (chin_y + 0.30 * span)) / (0.22 * span)) ** 2) * interior
    227:         Pf[:, 0] *= (1.0 + 0.025 * jaw_band)
    228: 
    229:     _, Nf_s = blender_recalc_normals(Pf, all_ftri, smooth_passes=0)
    230:     Nf_out = np.where(interior[:, None] > 0.1, Nf_s, Nf.astype(np.float32))
    231:     Nf_out /= np.maximum(np.linalg.norm(Nf_out, axis=1, keepdims=True), 1e-9)
    232:     _put(j, binb, f_at["POSITION"], Pf.astype(np.float32))
    233:     _put(j, binb, f_at["NORMAL"], Nf_out.astype(np.float32))
    234: 
    235:     landmarks = dict(
    236:         eye_y=eye_y,
    237:         chin_y=chin_y,
    238:         span=span,
    239:         crown_y=float(P[w_head > 0.5, 1].max()),
    240:         head_pos=B["J_Bip_C_Head"].tolist(),
    241:         neck_pos=B["J_Bip_C_Neck"].tolist(),
    242:         uchest_pos=B["J_Bip_C_UpperChest"].tolist(),
    243:         chest_pos=B["J_Bip_C_Chest"].tolist(),
    244:     )
    245:     return j, binb, landmarks
    246: 
    247: 
    248: def build_diamond_lock(pts, widths, thicks, u_range=(0.05, 0.95), nu=7, nv=28):
    249:     """Build a sculpted anime hair lock in Blender using cubic Catmull-Rom interpolation and a
    250:     lenticular/diamond cross-section with a crisp central ridge normal.
    251: 
    252:     pts: (K, 3) control points from root to tip
    253:     widths: (K,) half-widths in metres
    254:     thicks: (K,) half-thicknesses in metres
    255:     Returns (pos, nrm, uv, tri) as numpy arrays.
    256:     """
    257:     pts = np.asarray(pts, dtype=np.float64)
    258:     widths = np.asarray(widths, dtype=np.float64)
    259:     thicks = np.asarray(thicks, dtype=np.float64)
    260:     K = len(pts)
  • read_file{"EndLine":560,"Path":"~/work/lowmarch/tools/blender_sculpt_lead.py","StartLine":340}

    input

    {
      "EndLine": 560,
      "Path": "~/work/lowmarch/tools/blender_sculpt_lead.py",
      "StartLine": 340
    }

    result, 222 lines

    Showing lines 340-560 of 593
    340: def build_elaine_valkyrie_hair(lm):
    341:     """Build Elaine's custom anime Valkyrie hairstyle in Blender:
    342:     1. Smooth cranial dome cap + side-parted temple-framing curtain bangs (eyebrows 100% clear!).
    343:     2. Twisted Imperial Valkyrie Crown Braid (coronet plait) around the skull with a crimson/gold clasp.
    344:     3. 20 layered flowing diamond-section back and shoulder locks cascading over the pauldrons.
    345:     """
    346:     eye_y = lm["eye_y"]
    347:     chin_y = lm["chin_y"]
    348:     span = lm["span"]
    349:     crown_y = eye_y + 1.08 * span
    350:     cz = -0.018
    351: 
    352:     locks = []
    353: 
    354:     def add_lock(pts, w, th, u0=0.08, u1=0.92, nu=8, nv=26):
    355:         locks.append(build_diamond_lock(pts, w, th, (u0, u1), nu=nu, nv=nv))
    356: 
    357:     # ---- 1. Cranial Crown Cap Locks (radiating from the off-center crown part at x=-0.014) ----
    358:     # Parted Curtain Bangs: sweep Left and Right ABOVE the brow line (eye_y + 0.34*span) so brows read clearly!
    359:     brow_top = eye_y + 0.34 * span
    360: 
    361:     # Left-side swept curtain bangs (3 overlapping locks sweeping from part x=-0.015 toward left temple -x)
    362:     add_lock([
    363:         [-0.014, crown_y - 0.005, cz - 0.055],
    364:         [-0.042, brow_top + 0.025, cz - 0.085],
    365:         [-0.068, eye_y + 0.008, cz - 0.072],
    366:         [-0.078, chin_y + 0.040, cz - 0.045],
    367:         [-0.070, chin_y - 0.008, cz - 0.032],
    368:     ], [0.022, 0.028, 0.024, 0.016, 0.004], [0.009, 0.011, 0.009, 0.007, 0.002])
    369: 
    370:     add_lock([
    371:         [-0.018, crown_y - 0.002, cz - 0.040],
    372:         [-0.058, brow_top + 0.020, cz - 0.074],
    373:         [-0.082, eye_y - 0.002, cz - 0.052],
    374:         [-0.086, chin_y + 0.022, cz - 0.028],
    375:     ], [0.024, 0.028, 0.022, 0.005], [0.010, 0.011, 0.008, 0.003])
    376: 
    377:     # Delicate high forehead wisp (stops above the glabella between the brows so expression is unobstructed)
    378:     add_lock([
    379:         [-0.010, crown_y - 0.006, cz - 0.058],
    380:         [-0.004, brow_top + 0.028, cz - 0.089],
    381:         [0.006, brow_top + 0.006, cz - 0.091],
    382:     ], [0.012, 0.013, 0.003], [0.006, 0.007, 0.002], nv=18)
    383: 
    384:     # Right-side swept curtain bangs (4 layered locks sweeping across high forehead to right temple +x)
    385:     add_lock([
    386:         [-0.008, crown_y - 0.004, cz - 0.056],
    387:         [0.032, brow_top + 0.028, cz - 0.086],
    388:         [0.064, eye_y + 0.012, cz - 0.074],
    389:         [0.078, chin_y + 0.042, cz - 0.046],
    390:         [0.071, chin_y - 0.006, cz - 0.034],
    391:     ], [0.024, 0.030, 0.025, 0.016, 0.004], [0.009, 0.011, 0.009, 0.007, 0.002])
    392: 
    393:     add_lock([
    394:         [0.005, crown_y - 0.001, cz - 0.044],
    395:         [0.054, brow_top + 0.022, cz - 0.076],
    396:         [0.082, eye_y + 0.002, cz - 0.054],
    397:         [0.086, chin_y + 0.024, cz - 0.028],
    398:     ], [0.025, 0.029, 0.022, 0.005], [0.010, 0.011, 0.008, 0.003])
    399: 
    400:     # ---- 2. Twin Forward Shoulder Locks (draping in front of the pauldrons over the clavicles) ----
    401:     for sx in (-1.0, 1.0):
    402:         add_lock([
    403:             [sx * 0.068, eye_y + 0.015, cz - 0.010],
    404:             [sx * 0.086, chin_y + 0.010, cz - 0.022],
    405:             [sx * 0.095, chin_y - 0.055, cz - 0.048],
    406:             [sx * 0.088, chin_y - 0.135, cz - 0.076],
    407:             [sx * 0.076, chin_y - 0.205, cz - 0.084],
    408:         ], [0.022, 0.024, 0.022, 0.016, 0.004], [0.010, 0.011, 0.010, 0.008, 0.003], nv=30)
    409: 
    410:     # ---- 3. Cranial Dome Shell (smooth wide locks covering the top and sides of the skull) ----
    411:     for deg in np.linspace(-155, 155, 13):
    412:         if -38 < deg < 38:
    413:             continue
    414:         rad = math.radians(deg)
    415:         sx, sz = math.sin(rad), -math.cos(rad)
    416:         add_lock([
    417:             [0.012 * sx, crown_y + 0.004, cz + 0.012 * sz],
    418:             [0.068 * sx, crown_y - 0.018, cz + 0.068 * sz],
    419:             [0.096 * sx, eye_y + 0.018, cz + 0.094 * sz],
    420:             [0.094 * sx, chin_y + 0.018, cz + 0.088 * sz],
    421:         ], [0.024, 0.036, 0.038, 0.026], [0.010, 0.013, 0.013, 0.009], nv=22)
    422: 
    423:     # ---- 4. Twisted Valkyrie Coronet Braid (two interwoven sinusoidal strands around the crown) ----
    424:     braid_n = 44
    425:     ang_b = np.radians(np.linspace(-125, 125, braid_n))
    426:     for strand in (-1.0, 1.0):
    427:         b_pts = []
    428:         b_w = []
    429:         b_th = []
    430:         for k, a in enumerate(ang_b):
    431:             u = k / (braid_n - 1)
    432:             wave = strand * 0.0065 * math.sin(u * 13.0 * math.pi)
    433:             r_out = 0.097 + 0.0045 * math.cos(u * 13.0 * math.pi)
    434:             by = eye_y + 0.048 + 0.022 * math.cos(a * 0.7) + wave
    435:             bx = r_out * math.sin(a)
    436:             bz = cz - 0.005 - r_out * math.cos(a) * 0.88
    437:             b_pts.append([bx, by, bz])
    438:             b_w.append(0.016)
    439:             b_th.append(0.011)
    440:         add_lock(b_pts, b_w, b_th, nu=8, nv=48)
    441: 
    442:     # ---- 5. Voluminous Multi-Tiered Flowing Valkyrie Back-Mane (15 sculpted locks fanning over the back) ----
    443:     # Tier A: Upper volume cascade from the nape knot
    444:     for i, deg in enumerate(np.linspace(-62, 62, 9)):
    445:         rad = math.radians(deg)
    446:         sx = math.sin(rad)
    447:         splay = 1.0 + 0.35 * abs(sx)
    448:         add_lock([
    449:             [0.055 * sx, eye_y + 0.005, cz + 0.082],
    450:             [0.085 * sx, chin_y - 0.015, cz + 0.112],
    451:             [0.125 * sx * splay, chin_y - 0.120, cz + 0.148],
    452:             [0.155 * sx * splay, chin_y - 0.245, cz + 0.168 - 0.015 * abs(sx)],
    453:             [0.170 * sx * splay, chin_y - 0.355 + 0.025 * (i % 2), cz + 0.175],
    454:         ], [0.028, 0.034, 0.036, 0.024, 0.004], [0.011, 0.013, 0.013, 0.009, 0.003], nv=32)
    455: 
    456:     # Tier B: Outer flared wing-locks sweeping behind the pauldrons
    457:     for sx in (-1.0, 1.0):
    458:         for k, (lat, drop, z_push) in enumerate(((0.14, 0.28, 0.12), (0.19, 0.33, 0.10), (0.22, 0.24, 0.07))):
    459:             add_lock([
    460:                 [sx * 0.075, eye_y - 0.005, cz + 0.065],
    461:                 [sx * 0.115, chin_y - 0.035, cz + 0.095],
    462:                 [sx * (lat + 0.02), chin_y - 0.135, cz + z_push],
    463:                 [sx * (lat + 0.045), chin_y - drop, cz + z_push + 0.015],
    464:             ], [0.024, 0.028, 0.024, 0.004], [0.010, 0.012, 0.010, 0.003], nv=28)
    465: 
    466:     # Combine all locks into one hair mesh
    467:     all_p, all_n, all_uv, all_t = [], [], [], []
    468:     off = 0
    469:     for p, n, u, t in locks:
    470:         all_p.append(p)
    471:         all_n.append(n)
    472:         all_uv.append(u)
    473:         all_t.append(t + off)
    474:         off += len(p)
    475: 
    476:     pos = np.concatenate(all_p, axis=0)
    477:     nrm = np.concatenate(all_n, axis=0)
    478:     uv = np.concatenate(all_uv, axis=0)
    479:     tri = np.concatenate(all_t, axis=0)
    480:     return dict(pos=pos, nrm=nrm, uv=uv, tri=tri)
    481: 
    482: 
    483: def build_aldric_noble_hair(lm):
    484:     """Build Aldric's custom swept-back nobleman's layered mane in Blender (brow-clearing swept front
    485:     locks, layered temple wings, and a tousled heroic nape cascade)."""
    486:     eye_y = lm["eye_y"]
    487:     chin_y = lm["chin_y"]
    488:     span = lm["span"]
    489:     crown_y = eye_y + 1.10 * span
    490:     cz = -0.022
    491:     brow_top = eye_y + 0.33 * span
    492: 
    493:     locks = []
    494: 
    495:     def add_lock(pts, w, th, nu=8, nv=24):
    496:         locks.append(build_diamond_lock(pts, w, th, (0.08, 0.92), nu=nu, nv=nv))
    497: 
    498:     # Swept-back lion's-mane front locks (parted left, exposing the fierce brow ridge)
    499:     add_lock([
    500:         [-0.022, crown_y + 0.004, cz - 0.045],
    501:         [-0.052, brow_top + 0.030, cz - 0.086],
    502:         [-0.076, eye_y + 0.015, cz - 0.072],
    503:         [-0.084, chin_y + 0.048, cz - 0.042],
    504:     ], [0.024, 0.028, 0.022, 0.004], [0.010, 0.012, 0.009, 0.003])
    505: 
    506:     add_lock([
    507:         [-0.010, crown_y + 0.008, cz - 0.050],
    508:         [0.018, brow_top + 0.036, cz - 0.092],
    509:         [0.048, brow_top + 0.016, cz - 0.088],
    510:         [0.068, eye_y + 0.004, cz - 0.068],
    511:     ], [0.022, 0.026, 0.020, 0.004], [0.010, 0.011, 0.009, 0.003])
    512: 
    513:     add_lock([
    514:         [0.012, crown_y + 0.005, cz - 0.042],
    515:         [0.056, brow_top + 0.026, cz - 0.078],
    516:         [0.082, eye_y + 0.008, cz - 0.056],
    517:         [0.088, chin_y + 0.040, cz - 0.030],
    518:     ], [0.024, 0.028, 0.022, 0.004], [0.010, 0.011, 0.009, 0.003])
    519: 
    520:     # Crown and side locks swept backward with heroic flare
    521:     for deg in np.linspace(-165, 165, 15):
    522:         if -32 < deg < 32:
    523:             continue
    524:         rad = math.radians(deg)
    525:         sx, sz = math.sin(rad), -math.cos(rad)
    526:         back = max(0.0, sz)
    527:         add_lock([
    528:             [0.015 * sx, crown_y + 0.008, cz + 0.015 * sz],
    529:             [0.074 * sx, crown_y - 0.012, cz + 0.074 * sz],
    530:             [0.102 * sx, eye_y + 0.018, cz + 0.098 * sz + 0.012 * back],
    531:             [0.106 * sx, chin_y + 0.012 - 0.035 * back, cz + 0.096 * sz + 0.028 * back],
    532:             [0.098 * sx, chin_y - 0.025 - 0.055 * back, cz + 0.088 * sz + 0.042 * back],
    533:         ], [0.024, 0.036, 0.036, 0.024, 0.004], [0.010, 0.013, 0.013, 0.009, 0.003], nv=24)
    534: 
    535:     all_p, all_n, all_uv, all_t = [], [], [], []
    536:     off = 0
    537:     for p, n, u, t in locks:
    538:         all_p.append(p)
    539:         all_n.append(n)
    540:         all_uv.append(u)
    541:         all_t.append(t + off)
    542:         off += len(p)
    543: 
    544:     return dict(
    545:         pos=np.concatenate(all_p, axis=0),
    546:         nrm=np.concatenate(all_n, axis=0),
    547:         uv=np.concatenate(all_uv, axis=0),
    548:         tri=np.concatenate(all_t, axis=0),
    549:     )
    550: 
    551: 
    552: def save_vrm(path, j, binb):
    553:     js = json.dumps(j, separators=(",", ":")).encode()
    554:     js += b" " * ((4 - len(js) % 4) % 4)
    555:     while len(binb) % 4:
    556:         binb.append(0)
    557:     data = struct.pack("<4sII", b"glTF", 2, 12 + 8 + len(js) + 8 + len(binb))
    558:     data += struct.pack("<I4s", len(js), b"JSON") + js + struct.pack("<I4s", len(binb), b"BIN\x00") + bytes(binb)
    559:     os.makedirs(os.path.dirname(path), exist_ok=True)
    560:     open(path, "wb").write(data)

agent

+44:52
reasoning

Initial hypothesis: update the sculpting script to extract the skull surface data. This involves identifying the sculpted head mesh data within a specified region, excluding ear geometry, and creating a skull chart within the 3D environment.

  • edit_file{"Path":"~/work/lowmarch/tools/blender_sculpt_lead.py","Replacement":"import bpy\nimport bmesh\nfrom mathutils import Vector, Matrix\nfrom mathutils.bvhtree import BVHTree\nimport numpy as np","Target":"import bpy\nimport bmesh\nfrom mathutils import Vector, Matrix\nimport numpy as np"}

    input

    {
      "Path": "~/work/lowmarch/tools/blender_sculpt_lead.py",
      "Replacement": "import bpy\nimport bmesh\nfrom mathutils import Vector, Matrix\nfrom mathutils.bvhtree import BVHTree\nimport numpy as np",
      "Target": "import bpy\nimport bmesh\nfrom mathutils import Vector, Matrix\nimport numpy as np"
    }

    result, 1 line

    Made 1 replacement in ~/work/lowmarch/tools/blender_sculpt_lead.py starting at line 23 (+1/-0 lines).

agent

+45:03
reasoning

Applying the BlenderSkullChart to the specified functions within the relevant file. This change aims to improve the efficiency of the sculpting process. The implementation leverages Blender's internal data structures for faster processing.

  • edit_file{"Path":"~/work/lowmarch/tools/blender_sculpt_lead.py","Replacement":" # Build sculpted skull surface (Face_00_SKIN + head portion of Body_00_SKIN) for BVHTree raycasting\n face_skin_tris = [v.accessor(pr[\"indices\"]).reshape(-1, 3) for pr, m in zip(f_prims, mat_names) if \"Face_00_SKIN\" in m]\n ft_skin = np.concatenate(face_skin_tris, axis=0)\n used_f = np.unique(ft_skin)\n head_mask = w_head > 0.5\n bt_head = b_tri[head_mask[b_tri].all(1)]\n skull_pos = np.vstack([Pf, P])\n skull_tri = np.vstack([ft_skin, bt_head + len(Pf)])\n used_all = np.unique(skull_pos[skull_tri].reshape(-1, 3), axis=0)\n centre = ( skull_pos[np.unique(skull_tri)].min(0) + skull_pos[np.unique(skull_tri)].max(0) ) / 2.0\n ear_x = min(0.086, 0.835 * float(skull_pos[np.unique(skull_tri), 0].max() - centre[0]))\n tri_cx = skull_pos[skull_tri].mean(1)[:, 0]\n skull_tri_no_ears = skull_tri[np.abs(tri_cx - centre[0]) < ear_x]\n chart = BlenderSkullChart(skull_pos, skull_tri_no_ears, centre)\n\n landmarks = dict(\n eye_y=eye_y,\n chin_y=chin_y,\n span=span,\n crown_y=float(P[w_head > 0.5, 1].max()),\n centre=centre.tolist(),\n head_pos=B[\"J_Bip_C_Head\"].tolist(),\n neck_pos=B[\"J_Bip_C_Neck\"].tolist(),\n uchest_pos=B[\"J_Bip_C_UpperChest\"].tolist(),\n chest_pos=B[\"J_Bip_C_Chest\"].tolist(),\n )\n return j, binb, landmarks, chart\n\n\nclass BlenderSkullChart:\n \"\"\"Spherical skull chart in Blender using mathutils.bvhtree.BVHTree raycasting.\"\"\"\n def __init__(self, pos, tri, centre, du=4.0, dv=3.0, v_max=150.0):\n self.c = np.asarray(centre, dtype=np.float64)\n self.du, self.dv = du, dv\n self.us = np.arange(-180.0, 180.0, du)\n self.vs = np.arange(0.0, v_max + dv * 0.5, dv)\n verts = [Vector(p.tolist()) for p in pos]\n polys = [tuple(int(x) for x in t) for t in tri if t[0] != t[1] and t[1] != t[2] and t[0] != t[2]]\n bvh = BVHTree.FromPolygons(verts, polys)\n R = np.full((len(self.us), len(self.vs)), np.nan, dtype=np.float64)\n orig = Vector(self.c.tolist())\n for i, u in enumerate(self.us):\n ur = math.radians(u)\n su, cu = math.sin(ur), math.cos(ur)\n for j, v in enumerate(self.vs):\n vr = math.radians(v)\n sv, cv = math.sin(vr), math.cos(vr)\n d = Vector((sv * su, cv, -sv * cu))\n # Cast outward and take farthest hit up to 0.30 m\n best_d = np.nan\n cur_o = orig\n total_d = 0.0\n for _ in range(4):\n loc, _, _, dist = bvh.ray_cast(cur_o, d, 0.30 - total_d)\n if loc is None:\n break\n total_d += dist + 1e-4\n best_d = total_d\n cur_o = orig + d * total_d\n R[i, j] = best_d\n # Fill NaNs along columns/rows and smooth with separable Gaussian kernel\n for j in range(R.shape[1]):\n col = R[:, j]\n if np.isnan(col).all():\n R[:, j] = R[:, max(0, j - 1)] if j > 0 else 0.095\n elif np.isnan(col).any():\n ok = ~np.isnan(col)\n R[:, j] = np.interp(np.arange(len(col)), np.nonzero(ok)[0], col[ok])\n k = np.array([0.15, 0.25, 0.20, 0.25, 0.15])\n R_pad = np.pad(R, ((2, 2), (0, 0)), mode=\"wrap\")\n R = sum(k[m] * R_pad[m:m + len(self.us)] for m in range(5))\n R_pad2 = np.pad(R, ((0, 0), (2, 2)), mode=\"edge\")\n self.R = sum(k[m] * R_pad2[:, m:m + len(self.vs)] for m in range(5))\n\n def radius(self, u, v):\n u_w = ((float(u) + 180.0) % 360.0) - 180.0\n fi = (u_w - (-180.0)) / self.du\n fj = np.clip(float(v) / self.dv, 0.0, len(self.vs) - 1.001)\n i0 = int(math.floor(fi)) % len(self.us)\n i1 = (i0 + 1) % len(self.us)\n wi = fi - math.floor(fi)\n j0 = int(math.floor(fj))\n j1 = min(j0 + 1, len(self.vs) - 1)\n wj = fj - j0\n return ((1 - wi) * (1 - wj) * self.R[i0, j0] + wi * (1 - wj) * self.R[i1, j0]\n + (1 - wi) * wj * self.R[i0, j1] + wi * wj * self.R[i1, j1])\n\n def point(self, u, v, off=0.0):\n ur, vr = math.radians(float(u)), math.radians(float(v))\n d = np.array([math.sin(vr) * math.sin(ur), math.cos(vr), -math.sin(vr) * math.cos(ur)], dtype=np.float64)\n return self.c + d * (self.radius(u, v) + off)\n\n\ndef build_scalp_cap(chart, hairline_fn, lift=0.008, crown=0.008, nu=72, nv=26):\n \"\"\"Build the smooth cranial base volume over the sculpted skull chart in Blender.\"\"\"\n U = np.linspace(-180.0, 180.0, nu, endpoint=False)\n P_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n N_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n UV_grid = np.zeros((nu, nv, 2), dtype=np.float64)\n for i, u in enumerate(U):\n vmax = hairline_fn(u)\n for j, s in enumerate(np.linspace(0.0, 1.0, nv)):\n v = vmax * s\n p = chart.point(u, v, off=lift + crown * (1.0 - s) ** 2)\n P_grid[i, j] = p\n n = p - chart.c\n n /= max(np.linalg.norm(n), 1e-9)\n N_grid[i, j] = n\n UV_grid[i, j] = (i / nu * 6.0, s)\n tris = []\n idx = lambda i_, j_: (i_ % nu) * nv + j_\n for i in range(nu):\n for j in range(nv - 1):\n a, b, c, d = idx(i, j), idx(i + 1, j), idx(i + 1, j + 1), idx(i, j + 1)\n tris.append((a, b, c))\n tris.append((a, c, d))\n return (\n P_grid.reshape(-1, 3).astype(np.float32),\n N_grid.reshape(-1, 3).astype(np.float32),\n UV_grid.reshape(-1, 2).astype(np.float32),\n np.array(tris, dtype=np.int32),\n )\n\n\ndef build_diamond_lock(pts, widths, thicks, centre, u_range=(0.05, 0.95), nu=8, nv=28, flat_to=None):\n \"\"\"Build a sculpted anime hair lock in Blender using cubic Catmull-Rom interpolation and a\n lenticular/diamond cross-section with a crisp central ridge normal.\n \"\"\"\n pts = np.asarray(pts, dtype=np.float64)\n widths = np.asarray(widths, dtype=np.float64)\n thicks = np.asarray(thicks, dtype=np.float64)\n K = len(pts)\n t_ctrl = np.linspace(0.0, 1.0, K)\n t_eval = np.linspace(0.0, 1.0, nv)\n\n C = np.zeros((nv, 3), dtype=np.float64)\n tangents = np.gradient(pts, t_ctrl, axis=0)\n for j, t in enumerate(t_eval):\n idx = min(K - 2, max(0, int(np.searchsorted(t_ctrl, t) - 1)))\n t0, t1 = t_ctrl[idx], t_ctrl[idx + 1]\n h = max(t1 - t0, 1e-9)\n s = (t - t0) / h\n h00 = 2 * s ** 3 - 3 * s ** 2 + 1\n h10 = s ** 3 - 2 * s ** 2 + s\n h01 = -2 * s ** 3 + 3 * s ** 2\n h11 = s ** 3 - s ** 2\n C[j] = h00 * pts[idx] + h10 * h * tangents[idx] + h01 * pts[idx + 1] + h11 * h * tangents[idx + 1]\n\n W = np.interp(t_eval, t_ctrl, widths) * np.sin(np.pi * np.clip(0.08 + 0.92 * (1.0 - t_eval ** 1.65), 0.0, 1.0))\n Th = np.interp(t_eval, t_ctrl, thicks) * (1.0 - 0.80 * t_eval ** 1.5)\n\n T = np.gradient(C, axis=0)\n T /= np.maximum(np.linalg.norm(T, axis=1, keepdims=True), 1e-9)\n\n N = np.zeros_like(C)\n B_vec = np.zeros_like(C)\n for j in range(nv):\n ref = np.asarray(flat_to, dtype=np.float64) if flat_to is not None else np.array([centre[0], min(C[j, 1], centre[1]), centre[2]])\n out = C[j] - ref\n if np.linalg.norm(out) < 1e-4:\n out = np.array([0.0, 0.0, -1.0])\n out = out - T[j] * (out @ T[j])\n if np.linalg.norm(out) < 1e-5:\n out = np.array([0.0, 1.0, 0.0]) - T[j] * T[j, 1]\n out /= np.linalg.norm(out)\n if j > 0 and (out @ N[j - 1]) < 0:\n out = -out\n N[j] = out\n b = np.cross(T[j], out)\n b /= np.maximum(np.linalg.norm(b), 1e-9)\n B_vec[j] = b\n\n angles = np.linspace(0, 2 * np.pi, nu, endpoint=False)\n P_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n N_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n UV_grid = np.zeros((nu, nv, 2), dtype=np.float64)\n\n for i, a in enumerate(angles):\n ca, sa = math.cos(a), math.sin(a)\n ridge = np.sign(ca) * (abs(ca) ** 0.72)\n side = sa\n for j in range(nv):\n P_grid[i, j] = C[j] + B_vec[j] * (side * W[j]) + N[j] * (ridge * Th[j])\n n_dir = N[j] * (1.25 * ca) + B_vec[j] * (0.65 * sa)\n n_dir /= max(np.linalg.norm(n_dir), 1e-9)\n N_grid[i, j] = n_dir\n u_val = u_range[0] + (u_range[1] - u_range[0]) * (0.5 + 0.5 * side)\n UV_grid[i, j] = (u_val, t_eval[j])\n\n tris = []\n idx = lambda i_, j_: (i_ % nu) * nv + j_\n for i in range(nu):\n for j in range(nv - 1):\n a, b, c, d = idx(i, j), idx(i + 1, j), idx(i + 1, j + 1), idx(i, j + 1)\n tris.append((a, b, c))\n tris.append((a, c, d))\n\n pos = P_grid.reshape(-1, 3).astype(np.float32)\n nrm = N_grid.reshape(-1, 3).astype(np.float32)\n uv = UV_grid.reshape(-1, 2).astype(np.float32)\n tri = np.array(tris, dtype=np.int32)\n return pos, nrm, uv, tri\n\n\ndef build_elaine_valkyrie_hair(chart, lm):\n \"\"\"Build Elaine's custom anime Valkyrie hairstyle in Blender on the raycast skull chart:\n 1. Smooth skull-fitted cranial dome cap (leaving forehead & eyebrows 100% uncovered).\n 2. High-parted temple-framing curtain bangs (sweeping above v=72 deg so eyebrows at v=80..94 are 100% clear!).\n 3. Long temple & clavicle-framing locks draping in front of the pauldrons.\n 4. Twisted Imperial Valkyrie Coronet Braid across the crown + twin Valkyrie crown crest strands.\n 5. 18 layered diamond-section flowing Valkyrie battle-mane locks cascading behind the shoulders.\n \"\"\"\n locks = []\n # 1. Skull cap (forehead hairline at v=50 deg, well above the eyebrows at v=80..94 deg!)\n hl = lambda u: float(np.interp(abs(u), [0, 38, 56, 74, 92, 115, 140, 180], [50, 54, 72, 98, 108, 116, 136, 146]))\n locks.append(build_scalp_cap(chart, hl, lift=0.008, crown=0.009))\n\n def add_uv_lock(uv_pts, w, th, nu=8, nv=28, flat_to=None):\n pts = [chart.point(p[0], p[1], off=p[2]) if len(p) == 3 else np.array(p[1:], dtype=np.float64) for p in uv_pts]\n locks.append(build_diamond_lock(pts, w, th, chart.c, nu=nu, nv=nv, flat_to=flat_to))\n\n part = -22.0 # Left-side Valkyrie part\n # 2. High-parted Curtain Bangs: sweep across upper forehead (v=32..68, staying ABOVE v=76 over |u|<43)\n # Right-sweeping primary curtain lock\n add_uv_lock(\n [(part + 2, 28, 0.011), (-2, 46, 0.016), (22, 58, 0.018), (44, 72, 0.018), (56, 92, 0.016), (60, 110, 0.013)],\n [0.016, 0.024, 0.026, 0.022, 0.014, 0.003],\n [0.007, 0.010, 0.011, 0.009, 0.007, 0.002],\n )\n # Right-sweeping upper layered lock\n add_uv_lock(\n [(part + 10, 24, 0.012), (14, 42, 0.017), (38, 56, 0.018), (54, 76, 0.017), (64, 98, 0.014)],\n [0.015, 0.022, 0.024, 0.018, 0.003],\n [0.007, 0.009, 0.010, 0.008, 0.002],\n )\n # Left-sweeping primary curtain lock (leaves left eyebrow u=-43..-14, v=80..94 completely open!)\n add_uv_lock(\n [(part - 2, 28, 0.011), (part - 14, 48, 0.016), (-44, 68, 0.018), (-56, 88, 0.017), (-60, 108, 0.013)],\n [0.016, 0.023, 0.025, 0.017, 0.003],\n [0.007, 0.010, 0.010, 0.008, 0.002],\n )\n # Delicate high forehead Valkyrie center wisp (ends at v=64, well above the v=80 brow arch!)\n add_uv_lock(\n [(part, 30, 0.012), (-10, 48, 0.017), (-2, 63, 0.016)],\n [0.009, 0.011, 0.002],\n [0.005, 0.006, 0.002],\n nv=18,\n )\n\n # 3. Long Temple & Clavicle Framing Locks (draping down in front of the shoulders)\n for s in (-1.0, 1.0):\n p_jaw = chart.point(s * 64, 134, off=0.016)\n add_uv_lock(\n [\n (s * 48, 30, 0.010),\n (s * 64, 68, 0.015),\n (s * 68, 104, 0.016),\n (s * 64, 134, 0.016),\n (\"xyz\", p_jaw[0] + s * 0.008, p_jaw[1] - 0.065, p_jaw[2] - 0.018),\n (\"xyz\", p_jaw[0] + s * 0.002, p_jaw[1] - 0.135, p_jaw[2] - 0.028),\n ],\n [0.014, 0.022, 0.023, 0.020, 0.014, 0.003],\n [0.007, 0.009, 0.010, 0.009, 0.007, 0.002],\n nv=32,\n )\n # Ear-guard secondary side lock\n add_uv_lock(\n [(s * 78, 38, 0.009), (s * 94, 72, 0.014), (s * 102, 106, 0.014), (s * 106, 128, 0.011)],\n [0.015, 0.023, 0.021, 0.004],\n [0.007, 0.009, 0.009, 0.003],\n )\n\n # 4. Twisted Imperial Valkyrie Coronet Braid across the crown (u=-120..+120, v=34)\n braid_u = np.linspace(-120.0, 120.0, 37)\n for strand in (-1.0, 1.0):\n b_pts = []\n for k, u in enumerate(braid_u):\n phase = (k / (len(braid_u) - 1)) * 12.0 * math.pi\n v_w = 34.0 + 3.5 * strand * math.sin(phase)\n lift_w = 0.015 + 0.004 * strand * math.cos(phase)\n b_pts.append((u, v_w, lift_w))\n add_uv_lock(b_pts, [0.013] * len(b_pts), [0.009] * len(b_pts), nv=44)\n\n # Valkyrie Crown Crest (twin dynamic ahoge strands rising from the crown)\n r0 = chart.point(-8, 12, off=0.012)\n add_uv_lock(\n [\n (\"xyz\", *r0),\n (\"xyz\", *(r0 + np.array([-0.006, 0.028, 0.004]))),\n (\"xyz\", *(r0 + np.array([0.004, 0.048, -0.016]))),\n (\"xyz\", *(r0 + np.array([0.014, 0.038, -0.042]))),\n ],\n [0.010, 0.012, 0.008, 0.002],\n [0.004, 0.005, 0.004, 0.001],\n nv=22,\n flat_to=chart.c + np.array([-1.0, 0.0, 0.0]),\n )\n\n # 5. Voluminous Multi-Tiered Valkyrie Flowing Battle-Mane (cascading from crown past nape & shoulders)\n for i, u in enumerate(np.linspace(112.0, 248.0, 11)):\n side = (u - 180.0) / 68.0 # -1..+1\n p_nape = chart.point(u, 138.0, off=0.018)\n drop = 0.19 - 0.03 * abs(side) + 0.018 * (i % 2)\n add_uv_lock(\n [\n (u, 26.0, 0.009),\n (u, 64.0, 0.016),\n (u, 102.0, 0.018),\n (u, 138.0, 0.018),\n (\"xyz\", p_nape[0] * 1.18, p_nape[1] - drop * 0.52, p_nape[2] + 0.028),\n (\"xyz\", p_nape[0] * 1.32, p_nape[1] - drop, p_nape[2] + 0.046),\n ],\n [0.016, 0.026, 0.030, 0.028, 0.020, 0.004],\n [0.007, 0.010, 0.011, 0.011, 0.008, 0.002],\n nv=32,\n )\n # Upper crown volume locks (overlapping the braid and cascading to the mid-nape)\n for u in np.linspace(124.0, 236.0, 7):\n p_nape = chart.point(u, 132.0, off=0.024)\n add_uv_lock(\n [\n (u, 38.0, 0.016),\n (u, 82.0, 0.024),\n (u, 128.0, 0.025),\n (\"xyz\", p_nape[0] * 1.12, p_nape[1] - 0.11, p_nape[2] + 0.024),\n ],\n [0.018, 0.028, 0.026, 0.004],\n [0.008, 0.011, 0.010, 0.003],\n nv=26,\n )\n\n all_p, all_n, all_uv, all_t = [], [], [], []\n off = 0\n for p, n, u, t in locks:\n all_p.append(p)\n all_n.append(n)\n all_uv.append(u)\n all_t.append(t + off)\n off += len(p)\n\n return dict(\n pos=np.concatenate(all_p, axis=0),\n nrm=np.concatenate(all_n, axis=0),\n uv=np.concatenate(all_uv, axis=0),\n tri=np.concatenate(all_t, axis=0),\n )\n\n\ndef build_aldric_noble_hair(chart, lm):\n \"\"\"Build Aldric's custom swept-back nobleman's lion mane in Blender on the raycast skull chart\n (leaving his furrowed brows at v=79..93 100% unobstructed while giving him dramatic swept-back locks).\"\"\"\n locks = []\n hl = lambda u: float(np.interp(abs(u), [0, 45, 75, 105, 135, 180], [52, 56, 82, 104, 126, 138]))\n locks.append(build_scalp_cap(chart, hl, lift=0.008, crown=0.007))\n\n def add_uv_lock(uv_pts, w, th, nu=8, nv=24):\n pts = [chart.point(p[0], p[1], off=p[2]) if len(p) == 3 else np.array(p[1:], dtype=np.float64) for p in uv_pts]\n locks.append(build_diamond_lock(pts, w, th, chart.c, nu=nu, nv=nv))\n\n # 1. Swept-back noble lion front locks (rooted at v=50..56 above forehead, sweeping UP and BACK to crown)\n for u0, u1 in ((-36, -48), (-18, -26), (0, -6), (18, 26), (36, 48)):\n add_uv_lock(\n [(u0, 54, 0.008), ((u0 + u1) * 0.5, 36, 0.018), (u1, 16, 0.017), (u1 * 1.15, 6, 0.012)],\n [0.016, 0.024, 0.022, 0.005],\n [0.007, 0.011, 0.010, 0.003],\n )\n # 2. Temple wing locks framing the cheekbones (above and outside the brows |u|>46)\n for s in (-1.0, 1.0):\n add_uv_lock(\n [(s * 44, 46, 0.010), (s * 58, 66, 0.015), (s * 68, 92, 0.015), (s * 72, 114, 0.011)],\n [0.015, 0.022, 0.018, 0.004],\n [0.007, 0.010, 0.008, 0.002],\n )\n add_uv_lock(\n [(s * 66, 42, 0.010), (s * 84, 72, 0.015), (s * 96, 104, 0.014), (s * 102, 126, 0.010)],\n [0.016, 0.024, 0.020, 0.004],\n [0.007, 0.010, 0.009, 0.003],\n )\n # 3. Layered nape mane locks\n for u in np.linspace(112.0, 248.0, 9):\n add_uv_lock(\n [(u, 28, 0.009), (u, 68, 0.015), (u, 108, 0.016), (u, 140, 0.014)],\n [0.016, 0.026, 0.026, 0.005],\n [0.007, 0.010, 0.010, 0.003],\n )\n\n all_p, all_n, all_uv, all_t = [], [], [], []\n off = 0\n for p, n, u, t in locks:\n all_p.append(p)\n all_n.append(n)\n all_uv.append(u)\n all_t.append(t + off)\n off += len(p)\n\n return dict(\n pos=np.concatenate(all_p, axis=0),\n nrm=np.concatenate(all_n, axis=0),\n uv=np.concatenate(all_uv, axis=0),\n tri=np.concatenate(all_t, axis=0),\n )","Target":" landmarks = dict(\n eye_y=eye_y,\n chin_y=chin_y,\n span=span,\n crown_y=float(P[w_head > 0.5, 1].max()),\n head_pos=B[\"J_Bip_C_Head\"].tolist(),\n neck_pos=B[\"J_Bip_C_Neck\"].tolist(),\n uchest_pos=B[\"J_Bip_C_UpperChest\"].tolist(),\n chest_pos=B[\"J_Bip_C_Chest\"].tolist(),\n )\n return j, binb, landmarks\n\n\ndef build_diamond_lock(pts, widths, thicks, u_range=(0.05, 0.95), nu=7, nv=28):\n \"\"\"Build a sculpted anime hair lock in Blender using cubic Catmull-Rom interpolation and a\n lenticular/diamond cross-section with a crisp central ridge normal.\n\n pts: (K, 3) control points from root to tip\n widths: (K,) half-widths in metres\n thicks: (K,) half-thicknesses in metres\n Returns (pos, nrm, uv, tri) as numpy arrays.\n \"\"\"\n pts = np.asarray(pts, dtype=np.float64)\n widths = np.asarray(widths, dtype=np.float64)\n thicks = np.asarray(thicks, dtype=np.float64)\n K = len(pts)\n t_ctrl = np.linspace(0.0, 1.0, K)\n t_eval = np.linspace(0.0, 1.0, nv)\n\n # Smooth spline evaluation via cubic polynomial / Akima-like Hermite interpolation\n C = np.zeros((nv, 3), dtype=np.float64)\n tangents = np.gradient(pts, t_ctrl, axis=0)\n for j, t in enumerate(t_eval):\n idx = min(K - 2, max(0, int(np.searchsorted(t_ctrl, t) - 1)))\n t0, t1 = t_ctrl[idx], t_ctrl[idx + 1]\n h = max(t1 - t0, 1e-9)\n s = (t - t0) / h\n h00 = 2 * s ** 3 - 3 * s ** 2 + 1\n h10 = s ** 3 - 2 * s ** 2 + s\n h01 = -2 * s ** 3 + 3 * s ** 2\n h11 = s ** 3 - s ** 2\n C[j] = h00 * pts[idx] + h10 * h * tangents[idx] + h01 * pts[idx + 1] + h11 * h * tangents[idx + 1]\n\n W = np.interp(t_eval, t_ctrl, widths) * np.sin(np.pi * np.clip(0.06 + 0.94 * (1.0 - t_eval ** 1.65), 0.0, 1.0))\n Th = np.interp(t_eval, t_ctrl, thicks) * (1.0 - 0.82 * t_eval ** 1.5)\n\n # Parallel-transport frame along C, with outward normal pointing away from the skull axis (0, y, -0.01)\n T = np.gradient(C, axis=0)\n T /= np.maximum(np.linalg.norm(T, axis=1, keepdims=True), 1e-9)\n\n skull_c = np.array([0.0, C[0, 1] - 0.04, -0.01])\n N = np.zeros_like(C)\n B_vec = np.zeros_like(C)\n for j in range(nv):\n out = C[j] - np.array([0.0, C[j, 1], -0.015])\n if np.linalg.norm(out) < 1e-4:\n out = np.array([0.0, 0.0, -1.0])\n out = out - T[j] * (out @ T[j])\n if np.linalg.norm(out) < 1e-5:\n out = np.array([0.0, 1.0, 0.0]) - T[j] * T[j, 1]\n out /= np.linalg.norm(out)\n if j > 0 and (out @ N[j - 1]) < 0:\n out = -out\n N[j] = out\n b = np.cross(T[j], out)\n b /= np.maximum(np.linalg.norm(b), 1e-9)\n B_vec[j] = b\n\n # Cross-section profile: closed 8-point diamond/lenticular loop (outer ridge -> edges -> inner face)\n # Using a closed cross-section ensures locks look solid from every camera angle!\n angles = np.linspace(0, 2 * np.pi, nu, endpoint=False)\n P_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n N_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n UV_grid = np.zeros((nu, nv, 2), dtype=np.float64)\n\n for i, a in enumerate(angles):\n # Sharp anime ridge on the outer face (cos(a) > 0)\n ca, sa = math.cos(a), math.sin(a)\n ridge = np.sign(ca) * (abs(ca) ** 0.72)\n side = sa\n for j in range(nv):\n P_grid[i, j] = C[j] + B_vec[j] * (side * W[j]) + N[j] * (ridge * Th[j])\n # Normal tilted away from ridge center so cel shader catches crisp longitudinal strand bands\n n_dir = N[j] * (1.25 * ca) + B_vec[j] * (0.65 * sa)\n n_dir /= max(np.linalg.norm(n_dir), 1e-9)\n N_grid[i, j] = n_dir\n u_val = u_range[0] + (u_range[1] - u_range[0]) * (0.5 + 0.5 * side)\n UV_grid[i, j] = (u_val, t_eval[j])\n\n # Triangulate closed tube + tip cap\n tris = []\n idx = lambda i_, j_: (i_ % nu) * nv + j_\n for i in range(nu):\n for j in range(nv - 1):\n a, b, c, d = idx(i, j), idx(i + 1, j), idx(i + 1, j + 1), idx(i, j + 1)\n tris.append((a, b, c))\n tris.append((a, c, d))\n\n pos = P_grid.reshape(-1, 3).astype(np.float32)\n nrm = N_grid.reshape(-1, 3).astype(np.float32)\n uv = UV_grid.reshape(-1, 2).astype(np.float32)\n tri = np.array(tris, dtype=np.int32)\n return pos, nrm, uv, tri\n\n\ndef build_elaine_valkyrie_hair(lm):\n \"\"\"Build Elaine's custom anime Valkyrie hairstyle in Blender:\n 1. Smooth cranial dome cap + side-parted temple-framing curtain bangs (eyebrows 100% clear!).\n 2. Twisted Imperial Valkyrie Crown Braid (coronet plait) around the skull with a crimson/gold clasp.\n 3. 20 layered flowing diamond-section back and shoulder locks cascading over the pauldrons.\n \"\"\"\n eye_y = lm[\"eye_y\"]\n chin_y = lm[\"chin_y\"]\n span = lm[\"span\"]\n crown_y = eye_y + 1.08 * span\n cz = -0.018\n\n locks = []\n\n def add_lock(pts, w, th, u0=0.08, u1=0.92, nu=8, nv=26):\n locks.append(build_diamond_lock(pts, w, th, (u0, u1), nu=nu, nv=nv))\n\n # ---- 1. Cranial Crown Cap Locks (radiating from the off-center crown part at x=-0.014) ----\n # Parted Curtain Bangs: sweep Left and Right ABOVE the brow line (eye_y + 0.34*span) so brows read clearly!\n brow_top = eye_y + 0.34 * span\n\n # Left-side swept curtain bangs (3 overlapping locks sweeping from part x=-0.015 toward left temple -x)\n add_lock([\n [-0.014, crown_y - 0.005, cz - 0.055],\n [-0.042, brow_top + 0.025, cz - 0.085],\n [-0.068, eye_y + 0.008, cz - 0.072],\n [-0.078, chin_y + 0.040, cz - 0.045],\n [-0.070, chin_y - 0.008, cz - 0.032],\n ], [0.022, 0.028, 0.024, 0.016, 0.004], [0.009, 0.011, 0.009, 0.007, 0.002])\n\n add_lock([\n [-0.018, crown_y - 0.002, cz - 0.040],\n [-0.058, brow_top + 0.020, cz - 0.074],\n [-0.082, eye_y - 0.002, cz - 0.052],\n [-0.086, chin_y + 0.022, cz - 0.028],\n ], [0.024, 0.028, 0.022, 0.005], [0.010, 0.011, 0.008, 0.003])\n\n # Delicate high forehead wisp (stops above the glabella between the brows so expression is unobstructed)\n add_lock([\n [-0.010, crown_y - 0.006, cz - 0.058],\n [-0.004, brow_top + 0.028, cz - 0.089],\n [0.006, brow_top + 0.006, cz - 0.091],\n ], [0.012, 0.013, 0.003], [0.006, 0.007, 0.002], nv=18)\n\n # Right-side swept curtain bangs (4 layered locks sweeping across high forehead to right temple +x)\n add_lock([\n [-0.008, crown_y - 0.004, cz - 0.056],\n [0.032, brow_top + 0.028, cz - 0.086],\n [0.064, eye_y + 0.012, cz - 0.074],\n [0.078, chin_y + 0.042, cz - 0.046],\n [0.071, chin_y - 0.006, cz - 0.034],\n ], [0.024, 0.030, 0.025, 0.016, 0.004], [0.009, 0.011, 0.009, 0.007, 0.002])\n\n add_lock([\n [0.005, crown_y - 0.001, cz - 0.044],\n [0.054, brow_top + 0.022, cz - 0.076],\n [0.082, eye_y + 0.002, cz - 0.054],\n [0.086, chin_y + 0.024, cz - 0.028],\n ], [0.025, 0.029, 0.022, 0.005], [0.010, 0.011, 0.008, 0.003])\n\n # ---- 2. Twin Forward Shoulder Locks (draping in front of the pauldrons over the clavicles) ----\n for sx in (-1.0, 1.0):\n add_lock([\n [sx * 0.068, eye_y + 0.015, cz - 0.010],\n [sx * 0.086, chin_y + 0.010, cz - 0.022],\n [sx * 0.095, chin_y - 0.055, cz - 0.048],\n [sx * 0.088, chin_y - 0.135, cz - 0.076],\n [sx * 0.076, chin_y - 0.205, cz - 0.084],\n ], [0.022, 0.024, 0.022, 0.016, 0.004], [0.010, 0.011, 0.010, 0.008, 0.003], nv=30)\n\n # ---- 3. Cranial Dome Shell (smooth wide locks covering the top and sides of the skull) ----\n for deg in np.linspace(-155, 155, 13):\n if -38 < deg < 38:\n continue\n rad = math.radians(deg)\n sx, sz = math.sin(rad), -math.cos(rad)\n add_lock([\n [0.012 * sx, crown_y + 0.004, cz + 0.012 * sz],\n [0.068 * sx, crown_y - 0.018, cz + 0.068 * sz],\n [0.096 * sx, eye_y + 0.018, cz + 0.094 * sz],\n [0.094 * sx, chin_y + 0.018, cz + 0.088 * sz],\n ], [0.024, 0.036, 0.038, 0.026], [0.010, 0.013, 0.013, 0.009], nv=22)\n\n # ---- 4. Twisted Valkyrie Coronet Braid (two interwoven sinusoidal strands around the crown) ----\n braid_n = 44\n ang_b = np.radians(np.linspace(-125, 125, braid_n))\n for strand in (-1.0, 1.0):\n b_pts = []\n b_w = []\n b_th = []\n for k, a in enumerate(ang_b):\n u = k / (braid_n - 1)\n wave = strand * 0.0065 * math.sin(u * 13.0 * math.pi)\n r_out = 0.097 + 0.0045 * math.cos(u * 13.0 * math.pi)\n by = eye_y + 0.048 + 0.022 * math.cos(a * 0.7) + wave\n bx = r_out * math.sin(a)\n bz = cz - 0.005 - r_out * math.cos(a) * 0.88\n b_pts.append([bx, by, bz])\n b_w.append(0.016)\n b_th.append(0.011)\n add_lock(b_pts, b_w, b_th, nu=8, nv=48)\n\n # ---- 5. Voluminous Multi-Tiered Flowing Valkyrie Back-Mane (15 sculpted locks fanning over the back) ----\n # Tier A: Upper volume cascade from the nape knot\n for i, deg in enumerate(np.linspace(-62, 62, 9)):\n rad = math.radians(deg)\n sx = math.sin(rad)\n splay = 1.0 + 0.35 * abs(sx)\n add_lock([\n [0.055 * sx, eye_y + 0.005, cz + 0.082],\n [0.085 * sx, chin_y - 0.015, cz + 0.112],\n [0.125 * sx * splay, chin_y - 0.120, cz + 0.148],\n [0.155 * sx * splay, chin_y - 0.245, cz + 0.168 - 0.015 * abs(sx)],\n [0.170 * sx * splay, chin_y - 0.355 + 0.025 * (i % 2), cz + 0.175],\n ], [0.028, 0.034, 0.036, 0.024, 0.004], [0.011, 0.013, 0.013, 0.009, 0.003], nv=32)\n\n # Tier B: Outer flared wing-locks sweeping behind the pauldrons\n for sx in (-1.0, 1.0):\n for k, (lat, drop, z_push) in enumerate(((0.14, 0.28, 0.12), (0.19, 0.33, 0.10), (0.22, 0.24, 0.07))):\n add_lock([\n [sx * 0.075, eye_y - 0.005, cz + 0.065],\n [sx * 0.115, chin_y - 0.035, cz + 0.095],\n [sx * (lat + 0.02), chin_y - 0.135, cz + z_push],\n [sx * (lat + 0.045), chin_y - drop, cz + z_push + 0.015],\n ], [0.024, 0.028, 0.024, 0.004], [0.010, 0.012, 0.010, 0.003], nv=28)\n\n # Combine all locks into one hair mesh\n all_p, all_n, all_uv, all_t = [], [], [], []\n off = 0\n for p, n, u, t in locks:\n all_p.append(p)\n all_n.append(n)\n all_uv.append(u)\n all_t.append(t + off)\n off += len(p)\n\n pos = np.concatenate(all_p, axis=0)\n nrm = np.concatenate(all_n, axis=0)\n uv = np.concatenate(all_uv, axis=0)\n tri = np.concatenate(all_t, axis=0)\n return dict(pos=pos, nrm=nrm, uv=uv, tri=tri)\n\n\ndef build_aldric_noble_hair(lm):\n \"\"\"Build Aldric's custom swept-back nobleman's layered mane in Blender (brow-clearing swept front\n locks, layered temple wings, and a tousled heroic nape cascade).\"\"\"\n eye_y = lm[\"eye_y\"]\n chin_y = lm[\"chin_y\"]\n span = lm[\"span\"]\n crown_y = eye_y + 1.10 * span\n cz = -0.022\n brow_top = eye_y + 0.33 * span\n\n locks = []\n\n def add_lock(pts, w, th, nu=8, nv=24):\n locks.append(build_diamond_lock(pts, w, th, (0.08, 0.92), nu=nu, nv=nv))\n\n # Swept-back lion's-mane front locks (parted left, exposing the fierce brow ridge)\n add_lock([\n [-0.022, crown_y + 0.004, cz - 0.045],\n [-0.052, brow_top + 0.030, cz - 0.086],\n [-0.076, eye_y + 0.015, cz - 0.072],\n [-0.084, chin_y + 0.048, cz - 0.042],\n ], [0.024, 0.028, 0.022, 0.004], [0.010, 0.012, 0.009, 0.003])\n\n add_lock([\n [-0.010, crown_y + 0.008, cz - 0.050],\n [0.018, brow_top + 0.036, cz - 0.092],\n [0.048, brow_top + 0.016, cz - 0.088],\n [0.068, eye_y + 0.004, cz - 0.068],\n ], [0.022, 0.026, 0.020, 0.004], [0.010, 0.011, 0.009, 0.003])\n\n add_lock([\n [0.012, crown_y + 0.005, cz - 0.042],\n [0.056, brow_top + 0.026, cz - 0.078],\n [0.082, eye_y + 0.008, cz - 0.056],\n [0.088, chin_y + 0.040, cz - 0.030],\n ], [0.024, 0.028, 0.022, 0.004], [0.010, 0.011, 0.009, 0.003])\n\n # Crown and side locks swept backward with heroic flare\n for deg in np.linspace(-165, 165, 15):\n if -32 < deg < 32:\n continue\n rad = math.radians(deg)\n sx, sz = math.sin(rad), -math.cos(rad)\n back = max(0.0, sz)\n add_lock([\n [0.015 * sx, crown_y + 0.008, cz + 0.015 * sz],\n [0.074 * sx, crown_y - 0.012, cz + 0.074 * sz],\n [0.102 * sx, eye_y + 0.018, cz + 0.098 * sz + 0.012 * back],\n [0.106 * sx, chin_y + 0.012 - 0.035 * back, cz + 0.096 * sz + 0.028 * back],\n [0.098 * sx, chin_y - 0.025 - 0.055 * back, cz + 0.088 * sz + 0.042 * back],\n ], [0.024, 0.036, 0.036, 0.024, 0.004], [0.010, 0.013, 0.013, 0.009, 0.003], nv=24)\n\n all_p, all_n, all_uv, all_t = [], [], [], []\n off = 0\n for p, n, u, t in locks:\n all_p.append(p)\n all_n.append(n)\n all_uv.append(u)\n all_t.append(t + off)\n off += len(p)\n\n return dict(\n pos=np.concatenate(all_p, axis=0),\n nrm=np.concatenate(all_n, axis=0),\n uv=np.concatenate(all_uv, axis=0),\n tri=np.concatenate(all_t, axis=0),\n )"}

    input

    {
      "Path": "~/work/lowmarch/tools/blender_sculpt_lead.py",
      "Replacement": "    # Build sculpted skull surface (Face_00_SKIN + head portion of Body_00_SKIN) for BVHTree raycasting\n    face_skin_tris = [v.accessor(pr[\"indices\"]).reshape(-1, 3) for pr, m in zip(f_prims, mat_names) if \"Face_00_SKIN\" in m]\n    ft_skin = np.concatenate(face_skin_tris, axis=0)\n    used_f = np.unique(ft_skin)\n    head_mask = w_head > 0.5\n    bt_head = b_tri[head_mask[b_tri].all(1)]\n    skull_pos = np.vstack([Pf, P])\n    skull_tri = np.vstack([ft_skin, bt_head + len(Pf)])\n    used_all = np.unique(skull_pos[skull_tri].reshape(-1, 3), axis=0)\n    centre = ( skull_pos[np.unique(skull_tri)].min(0) + skull_pos[np.unique(skull_tri)].max(0) ) / 2.0\n    ear_x = min(0.086, 0.835 * float(skull_pos[np.unique(skull_tri), 0].max() - centre[0]))\n    tri_cx = skull_pos[skull_tri].mean(1)[:, 0]\n    skull_tri_no_ears = skull_tri[np.abs(tri_cx - centre[0]) < ear_x]\n    chart = BlenderSkullChart(skull_pos, skull_tri_no_ears, centre)\n\n    landmarks = dict(\n        eye_y=eye_y,\n        chin_y=chin_y,\n        span=span,\n        crown_y=float(P[w_head > 0.5, 1].max()),\n        centre=centre.tolist(),\n        head_pos=B[\"J_Bip_C_Head\"].tolist(),\n        neck_pos=B[\"J_Bip_C_Neck\"].tolist(),\n        uchest_pos=B[\"J_Bip_C_UpperChest\"].tolist(),\n        chest_pos=B[\"J_Bip_C_Chest\"].tolist(),\n    )\n    return j, binb, landmarks, chart\n\n\nclass BlenderSkullChart:\n    \"\"\"Spherical skull chart in Blender using mathutils.bvhtree.BVHTree raycasting.\"\"\"\n    def __init__(self, pos, tri, centre, du=4.0, dv=3.0, v_max=150.0):\n        self.c = np.asarray(centre, dtype=np.float64)\n        self.du, self.dv = du, dv\n        self.us = np.arange(-180.0, 180.0, du)\n        self.vs = np.arange(0.0, v_max + dv * 0.5, dv)\n        verts = [Vector(p.tolist()) for p in pos]\n        polys = [tuple(int(x) for x in t) for t in tri if t[0] != t[1] and t[1] != t[2] and t[0] != t[2]]\n        bvh = BVHTree.FromPolygons(verts, polys)\n        R = np.full((len(self.us), len(self.vs)), np.nan, dtype=np.float64)\n        orig = Vector(self.c.tolist())\n        for i, u in enumerate(self.us):\n            ur = math.radians(u)\n            su, cu = math.sin(ur), math.cos(ur)\n            for j, v in enumerate(self.vs):\n                vr = math.radians(v)\n                sv, cv = math.sin(vr), math.cos(vr)\n                d = Vector((sv * su, cv, -sv * cu))\n                # Cast outward and take farthest hit up to 0.30 m\n                best_d = np.nan\n                cur_o = orig\n                total_d = 0.0\n                for _ in range(4):\n                    loc, _, _, dist = bvh.ray_cast(cur_o, d, 0.30 - total_d)\n                    if loc is None:\n                        break\n                    total_d += dist + 1e-4\n                    best_d = total_d\n                    cur_o = orig + d * total_d\n                R[i, j] = best_d\n        # Fill NaNs along columns/rows and smooth with separable Gaussian kernel\n        for j in range(R.shape[1]):\n            col = R[:, j]\n            if np.isnan(col).all():\n                R[:, j] = R[:, max(0, j - 1)] if j > 0 else 0.095\n            elif np.isnan(col).any():\n                ok = ~np.isnan(col)\n                R[:, j] = np.interp(np.arange(len(col)), np.nonzero(ok)[0], col[ok])\n        k = np.array([0.15, 0.25, 0.20, 0.25, 0.15])\n        R_pad = np.pad(R, ((2, 2), (0, 0)), mode=\"wrap\")\n        R = sum(k[m] * R_pad[m:m + len(self.us)] for m in range(5))\n        R_pad2 = np.pad(R, ((0, 0), (2, 2)), mode=\"edge\")\n        self.R = sum(k[m] * R_pad2[:, m:m + len(self.vs)] for m in range(5))\n\n    def radius(self, u, v):\n        u_w = ((float(u) + 180.0) % 360.0) - 180.0\n        fi = (u_w - (-180.0)) / self.du\n        fj = np.clip(float(v) / self.dv, 0.0, len(self.vs) - 1.001)\n        i0 = int(math.floor(fi)) % len(self.us)\n        i1 = (i0 + 1) % len(self.us)\n        wi = fi - math.floor(fi)\n        j0 = int(math.floor(fj))\n        j1 = min(j0 + 1, len(self.vs) - 1)\n        wj = fj - j0\n        return ((1 - wi) * (1 - wj) * self.R[i0, j0] + wi * (1 - wj) * self.R[i1, j0]\n                + (1 - wi) * wj * self.R[i0, j1] + wi * wj * self.R[i1, j1])\n\n    def point(self, u, v, off=0.0):\n        ur, vr = math.radians(float(u)), math.radians(float(v))\n        d = np.array([math.sin(vr) * math.sin(ur), math.cos(vr), -math.sin(vr) * math.cos(ur)], dtype=np.float64)\n        return self.c + d * (self.radius(u, v) + off)\n\n\ndef build_scalp_cap(chart, hairline_fn, lift=0.008, crown=0.008, nu=72, nv=26):\n    \"\"\"Build the smooth cranial base volume over the sculpted skull chart in Blender.\"\"\"\n    U = np.linspace(-180.0, 180.0, nu, endpoint=False)\n    P_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n    N_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n    UV_grid = np.zeros((nu, nv, 2), dtype=np.float64)\n    for i, u in enumerate(U):\n        vmax = hairline_fn(u)\n        for j, s in enumerate(np.linspace(0.0, 1.0, nv)):\n            v = vmax * s\n            p = chart.point(u, v, off=lift + crown * (1.0 - s) ** 2)\n            P_grid[i, j] = p\n            n = p - chart.c\n            n /= max(np.linalg.norm(n), 1e-9)\n            N_grid[i, j] = n\n            UV_grid[i, j] = (i / nu * 6.0, s)\n    tris = []\n    idx = lambda i_, j_: (i_ % nu) * nv + j_\n    for i in range(nu):\n        for j in range(nv - 1):\n            a, b, c, d = idx(i, j), idx(i + 1, j), idx(i + 1, j + 1), idx(i, j + 1)\n            tris.append((a, b, c))\n            tris.append((a, c, d))\n    return (\n        P_grid.reshape(-1, 3).astype(np.float32),\n        N_grid.reshape(-1, 3).astype(np.float32),\n        UV_grid.reshape(-1, 2).astype(np.float32),\n        np.array(tris, dtype=np.int32),\n    )\n\n\ndef build_diamond_lock(pts, widths, thicks, centre, u_range=(0.05, 0.95), nu=8, nv=28, flat_to=None):\n    \"\"\"Build a sculpted anime hair lock in Blender using cubic Catmull-Rom interpolation and a\n    lenticular/diamond cross-section with a crisp central ridge normal.\n    \"\"\"\n    pts = np.asarray(pts, dtype=np.float64)\n    widths = np.asarray(widths, dtype=np.float64)\n    thicks = np.asarray(thicks, dtype=np.float64)\n    K = len(pts)\n    t_ctrl = np.linspace(0.0, 1.0, K)\n    t_eval = np.linspace(0.0, 1.0, nv)\n\n    C = np.zeros((nv, 3), dtype=np.float64)\n    tangents = np.gradient(pts, t_ctrl, axis=0)\n    for j, t in enumerate(t_eval):\n        idx = min(K - 2, max(0, int(np.searchsorted(t_ctrl, t) - 1)))\n        t0, t1 = t_ctrl[idx], t_ctrl[idx + 1]\n        h = max(t1 - t0, 1e-9)\n        s = (t - t0) / h\n        h00 = 2 * s ** 3 - 3 * s ** 2 + 1\n        h10 = s ** 3 - 2 * s ** 2 + s\n        h01 = -2 * s ** 3 + 3 * s ** 2\n        h11 = s ** 3 - s ** 2\n        C[j] = h00 * pts[idx] + h10 * h * tangents[idx] + h01 * pts[idx + 1] + h11 * h * tangents[idx + 1]\n\n    W = np.interp(t_eval, t_ctrl, widths) * np.sin(np.pi * np.clip(0.08 + 0.92 * (1.0 - t_eval ** 1.65), 0.0, 1.0))\n    Th = np.interp(t_eval, t_ctrl, thicks) * (1.0 - 0.80 * t_eval ** 1.5)\n\n    T = np.gradient(C, axis=0)\n    T /= np.maximum(np.linalg.norm(T, axis=1, keepdims=True), 1e-9)\n\n    N = np.zeros_like(C)\n    B_vec = np.zeros_like(C)\n    for j in range(nv):\n        ref = np.asarray(flat_to, dtype=np.float64) if flat_to is not None else np.array([centre[0], min(C[j, 1], centre[1]), centre[2]])\n        out = C[j] - ref\n        if np.linalg.norm(out) < 1e-4:\n            out = np.array([0.0, 0.0, -1.0])\n        out = out - T[j] * (out @ T[j])\n        if np.linalg.norm(out) < 1e-5:\n            out = np.array([0.0, 1.0, 0.0]) - T[j] * T[j, 1]\n        out /= np.linalg.norm(out)\n        if j > 0 and (out @ N[j - 1]) < 0:\n            out = -out\n        N[j] = out\n        b = np.cross(T[j], out)\n        b /= np.maximum(np.linalg.norm(b), 1e-9)\n        B_vec[j] = b\n\n    angles = np.linspace(0, 2 * np.pi, nu, endpoint=False)\n    P_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n    N_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n    UV_grid = np.zeros((nu, nv, 2), dtype=np.float64)\n\n    for i, a in enumerate(angles):\n        ca, sa = math.cos(a), math.sin(a)\n        ridge = np.sign(ca) * (abs(ca) ** 0.72)\n        side = sa\n        for j in range(nv):\n            P_grid[i, j] = C[j] + B_vec[j] * (side * W[j]) + N[j] * (ridge * Th[j])\n            n_dir = N[j] * (1.25 * ca) + B_vec[j] * (0.65 * sa)\n            n_dir /= max(np.linalg.norm(n_dir), 1e-9)\n            N_grid[i, j] = n_dir\n            u_val = u_range[0] + (u_range[1] - u_range[0]) * (0.5 + 0.5 * side)\n            UV_grid[i, j] = (u_val, t_eval[j])\n\n    tris = []\n    idx = lambda i_, j_: (i_ % nu) * nv + j_\n    for i in range(nu):\n        for j in range(nv - 1):\n            a, b, c, d = idx(i, j), idx(i + 1, j), idx(i + 1, j + 1), idx(i, j + 1)\n            tris.append((a, b, c))\n            tris.append((a, c, d))\n\n    pos = P_grid.reshape(-1, 3).astype(np.float32)\n    nrm = N_grid.reshape(-1, 3).astype(np.float32)\n    uv = UV_grid.reshape(-1, 2).astype(np.float32)\n    tri = np.array(tris, dtype=np.int32)\n    return pos, nrm, uv, tri\n\n\ndef build_elaine_valkyrie_hair(chart, lm):\n    \"\"\"Build Elaine's custom anime Valkyrie hairstyle in Blender on the raycast skull chart:\n    1. Smooth skull-fitted cranial dome cap (leaving forehead & eyebrows 100% uncovered).\n    2. High-parted temple-framing curtain bangs (sweeping above v=72 deg so eyebrows at v=80..94 are 100% clear!).\n    3. Long temple & clavicle-framing locks draping in front of the pauldrons.\n    4. Twisted Imperial Valkyrie Coronet Braid across the crown + twin Valkyrie crown crest strands.\n    5. 18 layered diamond-section flowing Valkyrie battle-mane locks cascading behind the shoulders.\n    \"\"\"\n    locks = []\n    # 1. Skull cap (forehead hairline at v=50 deg, well above the eyebrows at v=80..94 deg!)\n    hl = lambda u: float(np.interp(abs(u), [0, 38, 56, 74, 92, 115, 140, 180], [50, 54, 72, 98, 108, 116, 136, 146]))\n    locks.append(build_scalp_cap(chart, hl, lift=0.008, crown=0.009))\n\n    def add_uv_lock(uv_pts, w, th, nu=8, nv=28, flat_to=None):\n        pts = [chart.point(p[0], p[1], off=p[2]) if len(p) == 3 else np.array(p[1:], dtype=np.float64) for p in uv_pts]\n        locks.append(build_diamond_lock(pts, w, th, chart.c, nu=nu, nv=nv, flat_to=flat_to))\n\n    part = -22.0  # Left-side Valkyrie part\n    # 2. High-parted Curtain Bangs: sweep across upper forehead (v=32..68, staying ABOVE v=76 over |u|<43)\n    # Right-sweeping primary curtain lock\n    add_uv_lock(\n        [(part + 2, 28, 0.011), (-2, 46, 0.016), (22, 58, 0.018), (44, 72, 0.018), (56, 92, 0.016), (60, 110, 0.013)],\n        [0.016, 0.024, 0.026, 0.022, 0.014, 0.003],\n        [0.007, 0.010, 0.011, 0.009, 0.007, 0.002],\n    )\n    # Right-sweeping upper layered lock\n    add_uv_lock(\n        [(part + 10, 24, 0.012), (14, 42, 0.017), (38, 56, 0.018), (54, 76, 0.017), (64, 98, 0.014)],\n        [0.015, 0.022, 0.024, 0.018, 0.003],\n        [0.007, 0.009, 0.010, 0.008, 0.002],\n    )\n    # Left-sweeping primary curtain lock (leaves left eyebrow u=-43..-14, v=80..94 completely open!)\n    add_uv_lock(\n        [(part - 2, 28, 0.011), (part - 14, 48, 0.016), (-44, 68, 0.018), (-56, 88, 0.017), (-60, 108, 0.013)],\n        [0.016, 0.023, 0.025, 0.017, 0.003],\n        [0.007, 0.010, 0.010, 0.008, 0.002],\n    )\n    # Delicate high forehead Valkyrie center wisp (ends at v=64, well above the v=80 brow arch!)\n    add_uv_lock(\n        [(part, 30, 0.012), (-10, 48, 0.017), (-2, 63, 0.016)],\n        [0.009, 0.011, 0.002],\n        [0.005, 0.006, 0.002],\n        nv=18,\n    )\n\n    # 3. Long Temple & Clavicle Framing Locks (draping down in front of the shoulders)\n    for s in (-1.0, 1.0):\n        p_jaw = chart.point(s * 64, 134, off=0.016)\n        add_uv_lock(\n            [\n                (s * 48, 30, 0.010),\n                (s * 64, 68, 0.015),\n                (s * 68, 104, 0.016),\n                (s * 64, 134, 0.016),\n                (\"xyz\", p_jaw[0] + s * 0.008, p_jaw[1] - 0.065, p_jaw[2] - 0.018),\n                (\"xyz\", p_jaw[0] + s * 0.002, p_jaw[1] - 0.135, p_jaw[2] - 0.028),\n            ],\n            [0.014, 0.022, 0.023, 0.020, 0.014, 0.003],\n            [0.007, 0.009, 0.010, 0.009, 0.007, 0.002],\n            nv=32,\n        )\n        # Ear-guard secondary side lock\n        add_uv_lock(\n            [(s * 78, 38, 0.009), (s * 94, 72, 0.014), (s * 102, 106, 0.014), (s * 106, 128, 0.011)],\n            [0.015, 0.023, 0.021, 0.004],\n            [0.007, 0.009, 0.009, 0.003],\n        )\n\n    # 4. Twisted Imperial Valkyrie Coronet Braid across the crown (u=-120..+120, v=34)\n    braid_u = np.linspace(-120.0, 120.0, 37)\n    for strand in (-1.0, 1.0):\n        b_pts = []\n        for k, u in enumerate(braid_u):\n            phase = (k / (len(braid_u) - 1)) * 12.0 * math.pi\n            v_w = 34.0 + 3.5 * strand * math.sin(phase)\n            lift_w = 0.015 + 0.004 * strand * math.cos(phase)\n            b_pts.append((u, v_w, lift_w))\n        add_uv_lock(b_pts, [0.013] * len(b_pts), [0.009] * len(b_pts), nv=44)\n\n    # Valkyrie Crown Crest (twin dynamic ahoge strands rising from the crown)\n    r0 = chart.point(-8, 12, off=0.012)\n    add_uv_lock(\n        [\n            (\"xyz\", *r0),\n            (\"xyz\", *(r0 + np.array([-0.006, 0.028, 0.004]))),\n            (\"xyz\", *(r0 + np.array([0.004, 0.048, -0.016]))),\n            (\"xyz\", *(r0 + np.array([0.014, 0.038, -0.042]))),\n        ],\n        [0.010, 0.012, 0.008, 0.002],\n        [0.004, 0.005, 0.004, 0.001],\n        nv=22,\n        flat_to=chart.c + np.array([-1.0, 0.0, 0.0]),\n    )\n\n    # 5. Voluminous Multi-Tiered Valkyrie Flowing Battle-Mane (cascading from crown past nape & shoulders)\n    for i, u in enumerate(np.linspace(112.0, 248.0, 11)):\n        side = (u - 180.0) / 68.0  # -1..+1\n        p_nape = chart.point(u, 138.0, off=0.018)\n        drop = 0.19 - 0.03 * abs(side) + 0.018 * (i % 2)\n        add_uv_lock(\n            [\n                (u, 26.0, 0.009),\n                (u, 64.0, 0.016),\n                (u, 102.0, 0.018),\n                (u, 138.0, 0.018),\n                (\"xyz\", p_nape[0] * 1.18, p_nape[1] - drop * 0.52, p_nape[2] + 0.028),\n                (\"xyz\", p_nape[0] * 1.32, p_nape[1] - drop, p_nape[2] + 0.046),\n            ],\n            [0.016, 0.026, 0.030, 0.028, 0.020, 0.004],\n            [0.007, 0.010, 0.011, 0.011, 0.008, 0.002],\n            nv=32,\n        )\n    # Upper crown volume locks (overlapping the braid and cascading to the mid-nape)\n    for u in np.linspace(124.0, 236.0, 7):\n        p_nape = chart.point(u, 132.0, off=0.024)\n        add_uv_lock(\n            [\n                (u, 38.0, 0.016),\n                (u, 82.0, 0.024),\n                (u, 128.0, 0.025),\n                (\"xyz\", p_nape[0] * 1.12, p_nape[1] - 0.11, p_nape[2] + 0.024),\n            ],\n            [0.018, 0.028, 0.026, 0.004],\n            [0.008, 0.011, 0.010, 0.003],\n            nv=26,\n        )\n\n    all_p, all_n, all_uv, all_t = [], [], [], []\n    off = 0\n    for p, n, u, t in locks:\n        all_p.append(p)\n        all_n.append(n)\n        all_uv.append(u)\n        all_t.append(t + off)\n        off += len(p)\n\n    return dict(\n        pos=np.concatenate(all_p, axis=0),\n        nrm=np.concatenate(all_n, axis=0),\n        uv=np.concatenate(all_uv, axis=0),\n        tri=np.concatenate(all_t, axis=0),\n    )\n\n\ndef build_aldric_noble_hair(chart, lm):\n    \"\"\"Build Aldric's custom swept-back nobleman's lion mane in Blender on the raycast skull chart\n    (leaving his furrowed brows at v=79..93 100% unobstructed while giving him dramatic swept-back locks).\"\"\"\n    locks = []\n    hl = lambda u: float(np.interp(abs(u), [0, 45, 75, 105, 135, 180], [52, 56, 82, 104, 126, 138]))\n    locks.append(build_scalp_cap(chart, hl, lift=0.008, crown=0.007))\n\n    def add_uv_lock(uv_pts, w, th, nu=8, nv=24):\n        pts = [chart.point(p[0], p[1], off=p[2]) if len(p) == 3 else np.array(p[1:], dtype=np.float64) for p in uv_pts]\n        locks.append(build_diamond_lock(pts, w, th, chart.c, nu=nu, nv=nv))\n\n    # 1. Swept-back noble lion front locks (rooted at v=50..56 above forehead, sweeping UP and BACK to crown)\n    for u0, u1 in ((-36, -48), (-18, -26), (0, -6), (18, 26), (36, 48)):\n        add_uv_lock(\n            [(u0, 54, 0.008), ((u0 + u1) * 0.5, 36, 0.018), (u1, 16, 0.017), (u1 * 1.15, 6, 0.012)],\n            [0.016, 0.024, 0.022, 0.005],\n            [0.007, 0.011, 0.010, 0.003],\n        )\n    # 2. Temple wing locks framing the cheekbones (above and outside the brows |u|>46)\n    for s in (-1.0, 1.0):\n        add_uv_lock(\n            [(s * 44, 46, 0.010), (s * 58, 66, 0.015), (s * 68, 92, 0.015), (s * 72, 114, 0.011)],\n            [0.015, 0.022, 0.018, 0.004],\n            [0.007, 0.010, 0.008, 0.002],\n        )\n        add_uv_lock(\n            [(s * 66, 42, 0.010), (s * 84, 72, 0.015), (s * 96, 104, 0.014), (s * 102, 126, 0.010)],\n            [0.016, 0.024, 0.020, 0.004],\n            [0.007, 0.010, 0.009, 0.003],\n        )\n    # 3. Layered nape mane locks\n    for u in np.linspace(112.0, 248.0, 9):\n        add_uv_lock(\n            [(u, 28, 0.009), (u, 68, 0.015), (u, 108, 0.016), (u, 140, 0.014)],\n            [0.016, 0.026, 0.026, 0.005],\n            [0.007, 0.010, 0.010, 0.003],\n        )\n\n    all_p, all_n, all_uv, all_t = [], [], [], []\n    off = 0\n    for p, n, u, t in locks:\n        all_p.append(p)\n        all_n.append(n)\n        all_uv.append(u)\n        all_t.append(t + off)\n        off += len(p)\n\n    return dict(\n        pos=np.concatenate(all_p, axis=0),\n        nrm=np.concatenate(all_n, axis=0),\n        uv=np.concatenate(all_uv, axis=0),\n        tri=np.concatenate(all_t, axis=0),\n    )",
      "Target": "    landmarks = dict(\n        eye_y=eye_y,\n        chin_y=chin_y,\n        span=span,\n        crown_y=float(P[w_head > 0.5, 1].max()),\n        head_pos=B[\"J_Bip_C_Head\"].tolist(),\n        neck_pos=B[\"J_Bip_C_Neck\"].tolist(),\n        uchest_pos=B[\"J_Bip_C_UpperChest\"].tolist(),\n        chest_pos=B[\"J_Bip_C_Chest\"].tolist(),\n    )\n    return j, binb, landmarks\n\n\ndef build_diamond_lock(pts, widths, thicks, u_range=(0.05, 0.95), nu=7, nv=28):\n    \"\"\"Build a sculpted anime hair lock in Blender using cubic Catmull-Rom interpolation and a\n    lenticular/diamond cross-section with a crisp central ridge normal.\n\n    pts: (K, 3) control points from root to tip\n    widths: (K,) half-widths in metres\n    thicks: (K,) half-thicknesses in metres\n    Returns (pos, nrm, uv, tri) as numpy arrays.\n    \"\"\"\n    pts = np.asarray(pts, dtype=np.float64)\n    widths = np.asarray(widths, dtype=np.float64)\n    thicks = np.asarray(thicks, dtype=np.float64)\n    K = len(pts)\n    t_ctrl = np.linspace(0.0, 1.0, K)\n    t_eval = np.linspace(0.0, 1.0, nv)\n\n    # Smooth spline evaluation via cubic polynomial / Akima-like Hermite interpolation\n    C = np.zeros((nv, 3), dtype=np.float64)\n    tangents = np.gradient(pts, t_ctrl, axis=0)\n    for j, t in enumerate(t_eval):\n        idx = min(K - 2, max(0, int(np.searchsorted(t_ctrl, t) - 1)))\n        t0, t1 = t_ctrl[idx], t_ctrl[idx + 1]\n        h = max(t1 - t0, 1e-9)\n        s = (t - t0) / h\n        h00 = 2 * s ** 3 - 3 * s ** 2 + 1\n        h10 = s ** 3 - 2 * s ** 2 + s\n        h01 = -2 * s ** 3 + 3 * s ** 2\n        h11 = s ** 3 - s ** 2\n        C[j] = h00 * pts[idx] + h10 * h * tangents[idx] + h01 * pts[idx + 1] + h11 * h * tangents[idx + 1]\n\n    W = np.interp(t_eval, t_ctrl, widths) * np.sin(np.pi * np.clip(0.06 + 0.94 * (1.0 - t_eval ** 1.65), 0.0, 1.0))\n    Th = np.interp(t_eval, t_ctrl, thicks) * (1.0 - 0.82 * t_eval ** 1.5)\n\n    # Parallel-transport frame along C, with outward normal pointing away from the skull axis (0, y, -0.01)\n    T = np.gradient(C, axis=0)\n    T /= np.maximum(np.linalg.norm(T, axis=1, keepdims=True), 1e-9)\n\n    skull_c = np.array([0.0, C[0, 1] - 0.04, -0.01])\n    N = np.zeros_like(C)\n    B_vec = np.zeros_like(C)\n    for j in range(nv):\n        out = C[j] - np.array([0.0, C[j, 1], -0.015])\n        if np.linalg.norm(out) < 1e-4:\n            out = np.array([0.0, 0.0, -1.0])\n        out = out - T[j] * (out @ T[j])\n        if np.linalg.norm(out) < 1e-5:\n            out = np.array([0.0, 1.0, 0.0]) - T[j] * T[j, 1]\n        out /= np.linalg.norm(out)\n        if j > 0 and (out @ N[j - 1]) < 0:\n            out = -out\n        N[j] = out\n        b = np.cross(T[j], out)\n        b /= np.maximum(np.linalg.norm(b), 1e-9)\n        B_vec[j] = b\n\n    # Cross-section profile: closed 8-point diamond/lenticular loop (outer ridge -> edges -> inner face)\n    # Using a closed cross-section ensures locks look solid from every camera angle!\n    angles = np.linspace(0, 2 * np.pi, nu, endpoint=False)\n    P_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n    N_grid = np.zeros((nu, nv, 3), dtype=np.float64)\n    UV_grid = np.zeros((nu, nv, 2), dtype=np.float64)\n\n    for i, a in enumerate(angles):\n        # Sharp anime ridge on the outer face (cos(a) > 0)\n        ca, sa = math.cos(a), math.sin(a)\n        ridge = np.sign(ca) * (abs(ca) ** 0.72)\n        side = sa\n        for j in range(nv):\n            P_grid[i, j] = C[j] + B_vec[j] * (side * W[j]) + N[j] * (ridge * Th[j])\n            # Normal tilted away from ridge center so cel shader catches crisp longitudinal strand bands\n            n_dir = N[j] * (1.25 * ca) + B_vec[j] * (0.65 * sa)\n            n_dir /= max(np.linalg.norm(n_dir), 1e-9)\n            N_grid[i, j] = n_dir\n            u_val = u_range[0] + (u_range[1] - u_range[0]) * (0.5 + 0.5 * side)\n            UV_grid[i, j] = (u_val, t_eval[j])\n\n    # Triangulate closed tube + tip cap\n    tris = []\n    idx = lambda i_, j_: (i_ % nu) * nv + j_\n    for i in range(nu):\n        for j in range(nv - 1):\n            a, b, c, d = idx(i, j), idx(i + 1, j), idx(i + 1, j + 1), idx(i, j + 1)\n            tris.append((a, b, c))\n            tris.append((a, c, d))\n\n    pos = P_grid.reshape(-1, 3).astype(np.float32)\n    nrm = N_grid.reshape(-1, 3).astype(np.float32)\n    uv = UV_grid.reshape(-1, 2).astype(np.float32)\n    tri = np.array(tris, dtype=np.int32)\n    return pos, nrm, uv, tri\n\n\ndef build_elaine_valkyrie_hair(lm):\n    \"\"\"Build Elaine's custom anime Valkyrie hairstyle in Blender:\n    1. Smooth cranial dome cap + side-parted temple-framing curtain bangs (eyebrows 100% clear!).\n    2. Twisted Imperial Valkyrie Crown Braid (coronet plait) around the skull with a crimson/gold clasp.\n    3. 20 layered flowing diamond-section back and shoulder locks cascading over the pauldrons.\n    \"\"\"\n    eye_y = lm[\"eye_y\"]\n    chin_y = lm[\"chin_y\"]\n    span = lm[\"span\"]\n    crown_y = eye_y + 1.08 * span\n    cz = -0.018\n\n    locks = []\n\n    def add_lock(pts, w, th, u0=0.08, u1=0.92, nu=8, nv=26):\n        locks.append(build_diamond_lock(pts, w, th, (u0, u1), nu=nu, nv=nv))\n\n    # ---- 1. Cranial Crown Cap Locks (radiating from the off-center crown part at x=-0.014) ----\n    # Parted Curtain Bangs: sweep Left and Right ABOVE the brow line (eye_y + 0.34*span) so brows read clearly!\n    brow_top = eye_y + 0.34 * span\n\n    # Left-side swept curtain bangs (3 overlapping locks sweeping from part x=-0.015 toward left temple -x)\n    add_lock([\n        [-0.014, crown_y - 0.005, cz - 0.055],\n        [-0.042, brow_top + 0.025, cz - 0.085],\n        [-0.068, eye_y + 0.008, cz - 0.072],\n        [-0.078, chin_y + 0.040, cz - 0.045],\n        [-0.070, chin_y - 0.008, cz - 0.032],\n    ], [0.022, 0.028, 0.024, 0.016, 0.004], [0.009, 0.011, 0.009, 0.007, 0.002])\n\n    add_lock([\n        [-0.018, crown_y - 0.002, cz - 0.040],\n        [-0.058, brow_top + 0.020, cz - 0.074],\n        [-0.082, eye_y - 0.002, cz - 0.052],\n        [-0.086, chin_y + 0.022, cz - 0.028],\n    ], [0.024, 0.028, 0.022, 0.005], [0.010, 0.011, 0.008, 0.003])\n\n    # Delicate high forehead wisp (stops above the glabella between the brows so expression is unobstructed)\n    add_lock([\n        [-0.010, crown_y - 0.006, cz - 0.058],\n        [-0.004, brow_top + 0.028, cz - 0.089],\n        [0.006, brow_top + 0.006, cz - 0.091],\n    ], [0.012, 0.013, 0.003], [0.006, 0.007, 0.002], nv=18)\n\n    # Right-side swept curtain bangs (4 layered locks sweeping across high forehead to right temple +x)\n    add_lock([\n        [-0.008, crown_y - 0.004, cz - 0.056],\n        [0.032, brow_top + 0.028, cz - 0.086],\n        [0.064, eye_y + 0.012, cz - 0.074],\n        [0.078, chin_y + 0.042, cz - 0.046],\n        [0.071, chin_y - 0.006, cz - 0.034],\n    ], [0.024, 0.030, 0.025, 0.016, 0.004], [0.009, 0.011, 0.009, 0.007, 0.002])\n\n    add_lock([\n        [0.005, crown_y - 0.001, cz - 0.044],\n        [0.054, brow_top + 0.022, cz - 0.076],\n        [0.082, eye_y + 0.002, cz - 0.054],\n        [0.086, chin_y + 0.024, cz - 0.028],\n    ], [0.025, 0.029, 0.022, 0.005], [0.010, 0.011, 0.008, 0.003])\n\n    # ---- 2. Twin Forward Shoulder Locks (draping in front of the pauldrons over the clavicles) ----\n    for sx in (-1.0, 1.0):\n        add_lock([\n            [sx * 0.068, eye_y + 0.015, cz - 0.010],\n            [sx * 0.086, chin_y + 0.010, cz - 0.022],\n            [sx * 0.095, chin_y - 0.055, cz - 0.048],\n            [sx * 0.088, chin_y - 0.135, cz - 0.076],\n            [sx * 0.076, chin_y - 0.205, cz - 0.084],\n        ], [0.022, 0.024, 0.022, 0.016, 0.004], [0.010, 0.011, 0.010, 0.008, 0.003], nv=30)\n\n    # ---- 3. Cranial Dome Shell (smooth wide locks covering the top and sides of the skull) ----\n    for deg in np.linspace(-155, 155, 13):\n        if -38 < deg < 38:\n            continue\n        rad = math.radians(deg)\n        sx, sz = math.sin(rad), -math.cos(rad)\n        add_lock([\n            [0.012 * sx, crown_y + 0.004, cz + 0.012 * sz],\n            [0.068 * sx, crown_y - 0.018, cz + 0.068 * sz],\n            [0.096 * sx, eye_y + 0.018, cz + 0.094 * sz],\n            [0.094 * sx, chin_y + 0.018, cz + 0.088 * sz],\n        ], [0.024, 0.036, 0.038, 0.026], [0.010, 0.013, 0.013, 0.009], nv=22)\n\n    # ---- 4. Twisted Valkyrie Coronet Braid (two interwoven sinusoidal strands around the crown) ----\n    braid_n = 44\n    ang_b = np.radians(np.linspace(-125, 125, braid_n))\n    for strand in (-1.0, 1.0):\n        b_pts = []\n        b_w = []\n        b_th = []\n        for k, a in enumerate(ang_b):\n            u = k / (braid_n - 1)\n            wave = strand * 0.0065 * math.sin(u * 13.0 * math.pi)\n            r_out = 0.097 + 0.0045 * math.cos(u * 13.0 * math.pi)\n            by = eye_y + 0.048 + 0.022 * math.cos(a * 0.7) + wave\n            bx = r_out * math.sin(a)\n            bz = cz - 0.005 - r_out * math.cos(a) * 0.88\n            b_pts.append([bx, by, bz])\n            b_w.append(0.016)\n            b_th.append(0.011)\n        add_lock(b_pts, b_w, b_th, nu=8, nv=48)\n\n    # ---- 5. Voluminous Multi-Tiered Flowing Valkyrie Back-Mane (15 sculpted locks fanning over the back) ----\n    # Tier A: Upper volume cascade from the nape knot\n    for i, deg in enumerate(np.linspace(-62, 62, 9)):\n        rad = math.radians(deg)\n        sx = math.sin(rad)\n        splay = 1.0 + 0.35 * abs(sx)\n        add_lock([\n            [0.055 * sx, eye_y + 0.005, cz + 0.082],\n            [0.085 * sx, chin_y - 0.015, cz + 0.112],\n            [0.125 * sx * splay, chin_y - 0.120, cz + 0.148],\n            [0.155 * sx * splay, chin_y - 0.245, cz + 0.168 - 0.015 * abs(sx)],\n            [0.170 * sx * splay, chin_y - 0.355 + 0.025 * (i % 2), cz + 0.175],\n        ], [0.028, 0.034, 0.036, 0.024, 0.004], [0.011, 0.013, 0.013, 0.009, 0.003], nv=32)\n\n    # Tier B: Outer flared wing-locks sweeping behind the pauldrons\n    for sx in (-1.0, 1.0):\n        for k, (lat, drop, z_push) in enumerate(((0.14, 0.28, 0.12), (0.19, 0.33, 0.10), (0.22, 0.24, 0.07))):\n            add_lock([\n                [sx * 0.075, eye_y - 0.005, cz + 0.065],\n                [sx * 0.115, chin_y - 0.035, cz + 0.095],\n                [sx * (lat + 0.02), chin_y - 0.135, cz + z_push],\n                [sx * (lat + 0.045), chin_y - drop, cz + z_push + 0.015],\n            ], [0.024, 0.028, 0.024, 0.004], [0.010, 0.012, 0.010, 0.003], nv=28)\n\n    # Combine all locks into one hair mesh\n    all_p, all_n, all_uv, all_t = [], [], [], []\n    off = 0\n    for p, n, u, t in locks:\n        all_p.append(p)\n        all_n.append(n)\n        all_uv.append(u)\n        all_t.append(t + off)\n        off += len(p)\n\n    pos = np.concatenate(all_p, axis=0)\n    nrm = np.concatenate(all_n, axis=0)\n    uv = np.concatenate(all_uv, axis=0)\n    tri = np.concatenate(all_t, axis=0)\n    return dict(pos=pos, nrm=nrm, uv=uv, tri=tri)\n\n\ndef build_aldric_noble_hair(lm):\n    \"\"\"Build Aldric's custom swept-back nobleman's layered mane in Blender (brow-clearing swept front\n    locks, layered temple wings, and a tousled heroic nape cascade).\"\"\"\n    eye_y = lm[\"eye_y\"]\n    chin_y = lm[\"chin_y\"]\n    span = lm[\"span\"]\n    crown_y = eye_y + 1.10 * span\n    cz = -0.022\n    brow_top = eye_y + 0.33 * span\n\n    locks = []\n\n    def add_lock(pts, w, th, nu=8, nv=24):\n        locks.append(build_diamond_lock(pts, w, th, (0.08, 0.92), nu=nu, nv=nv))\n\n    # Swept-back lion's-mane front locks (parted left, exposing the fierce brow ridge)\n    add_lock([\n        [-0.022, crown_y + 0.004, cz - 0.045],\n        [-0.052, brow_top + 0.030, cz - 0.086],\n        [-0.076, eye_y + 0.015, cz - 0.072],\n        [-0.084, chin_y + 0.048, cz - 0.042],\n    ], [0.024, 0.028, 0.022, 0.004], [0.010, 0.012, 0.009, 0.003])\n\n    add_lock([\n        [-0.010, crown_y + 0.008, cz - 0.050],\n        [0.018, brow_top + 0.036, cz - 0.092],\n        [0.048, brow_top + 0.016, cz - 0.088],\n        [0.068, eye_y + 0.004, cz - 0.068],\n    ], [0.022, 0.026, 0.020, 0.004], [0.010, 0.011, 0.009, 0.003])\n\n    add_lock([\n        [0.012, crown_y + 0.005, cz - 0.042],\n        [0.056, brow_top + 0.026, cz - 0.078],\n        [0.082, eye_y + 0.008, cz - 0.056],\n        [0.088, chin_y + 0.040, cz - 0.030],\n    ], [0.024, 0.028, 0.022, 0.004], [0.010, 0.011, 0.009, 0.003])\n\n    # Crown and side locks swept backward with heroic flare\n    for deg in np.linspace(-165, 165, 15):\n        if -32 < deg < 32:\n            continue\n        rad = math.radians(deg)\n        sx, sz = math.sin(rad), -math.cos(rad)\n        back = max(0.0, sz)\n        add_lock([\n            [0.015 * sx, crown_y + 0.008, cz + 0.015 * sz],\n            [0.074 * sx, crown_y - 0.012, cz + 0.074 * sz],\n            [0.102 * sx, eye_y + 0.018, cz + 0.098 * sz + 0.012 * back],\n            [0.106 * sx, chin_y + 0.012 - 0.035 * back, cz + 0.096 * sz + 0.028 * back],\n            [0.098 * sx, chin_y - 0.025 - 0.055 * back, cz + 0.088 * sz + 0.042 * back],\n        ], [0.024, 0.036, 0.036, 0.024, 0.004], [0.010, 0.013, 0.013, 0.009, 0.003], nv=24)\n\n    all_p, all_n, all_uv, all_t = [], [], [], []\n    off = 0\n    for p, n, u, t in locks:\n        all_p.append(p)\n        all_n.append(n)\n        all_uv.append(u)\n        all_t.append(t + off)\n        off += len(p)\n\n    return dict(\n        pos=np.concatenate(all_p, axis=0),\n        nrm=np.concatenate(all_n, axis=0),\n        uv=np.concatenate(all_uv, axis=0),\n        tri=np.concatenate(all_t, axis=0),\n    )"
    }

    result, 1 line

    Made 1 replacement in ~/work/lowmarch/tools/blender_sculpt_lead.py starting at line 236 (+299/-213 lines).

agent

+47:10
reasoning

Modifying the main() function within the specified script, I'll update the calls to the hair-building functions to include the chart and landmark data. This ensures the correct data is passed to the hair-building functions for the specified characters.

  • edit_file{"Path":"~/work/lowmarch/tools/blender_sculpt_lead.py","Replacement":" # 1. Elaine: sculpt from arm_f_strong (1.81 m athletic Valkyrie stature)\n p_elaine_src = os.path.expanduser(\"~/.local/share/lowmarch/vroid/lowmarch_bodies/cage/arm_f_strong_4ad9ea3b57cd9a77.vrm\")\n v_e = VRM(p_elaine_src)\n j_e, bin_e, lm_e, chart_e = sculpt_body_and_face(v_e, sex=\"f\")\n vrm_e_out = os.path.join(OUT_DIR, \"elaine_argon_sculpt.vrm\")\n sz_e = save_vrm(vrm_e_out, j_e, bin_e)\n hair_e = build_elaine_valkyrie_hair(chart_e, lm_e)\n hair_e_out = os.path.join(OUT_DIR, \"elaine_argon_hair.npz\")\n np.savez_compressed(hair_e_out, **hair_e)\n print(f\"Elaine sculpt VRM: {vrm_e_out} ({sz_e / 1e6:.2f} MB), custom hair: {len(hair_e['pos'])} verts, {len(hair_e['tri'])} tris\")\n\n # 2. Aldric: sculpt from arm_m_heroic (1.88 m heroic lord stature)\n p_aldric_src = os.path.expanduser(\"~/.local/share/lowmarch/vroid/lowmarch_bodies/cage/arm_m_heroic_460837128ce488ff.vrm\")\n v_a = VRM(p_aldric_src)\n j_a, bin_a, lm_a, chart_a = sculpt_body_and_face(v_a, sex=\"m\")\n vrm_a_out = os.path.join(OUT_DIR, \"aldric_argon_sculpt.vrm\")\n sz_a = save_vrm(vrm_a_out, j_a, bin_a)\n hair_a = build_aldric_noble_hair(chart_a, lm_a)","Target":" # 1. Elaine: sculpt from arm_f_strong (1.81 m athletic Valkyrie stature)\n p_elaine_src = os.path.expanduser(\"~/.local/share/lowmarch/vroid/lowmarch_bodies/cage/arm_f_strong_4ad9ea3b57cd9a77.vrm\")\n v_e = VRM(p_elaine_src)\n j_e, bin_e, lm_e = sculpt_body_and_face(v_e, sex=\"f\")\n vrm_e_out = os.path.join(OUT_DIR, \"elaine_argon_sculpt.vrm\")\n sz_e = save_vrm(vrm_e_out, j_e, bin_e)\n hair_e = build_elaine_valkyrie_hair(lm_e)\n hair_e_out = os.path.join(OUT_DIR, \"elaine_argon_hair.npz\")\n np.savez_compressed(hair_e_out, **hair_e)\n print(f\"Elaine sculpt VRM: {vrm_e_out} ({sz_e / 1e6:.2f} MB), custom hair: {len(hair_e['pos'])} verts, {len(hair_e['tri'])} tris\")\n\n # 2. Aldric: sculpt from arm_m_heroic (1.88 m heroic lord stature)\n p_aldric_src = os.path.expanduser(\"~/.local/share/lowmarch/vroid/lowmarch_bodies/cage/arm_m_heroic_460837128ce488ff.vrm\")\n v_a = VRM(p_aldric_src)\n j_a, bin_a, lm_a = sculpt_body_and_face(v_a, sex=\"m\")\n vrm_a_out = os.path.join(OUT_DIR, \"aldric_argon_sculpt.vrm\")\n sz_a = save_vrm(vrm_a_out, j_a, bin_a)\n hair_a = build_aldric_noble_hair(lm_a)"}

    input

    {
      "Path": "~/work/lowmarch/tools/blender_sculpt_lead.py",
      "Replacement": "    # 1. Elaine: sculpt from arm_f_strong (1.81 m athletic Valkyrie stature)\n    p_elaine_src = os.path.expanduser(\"~/.local/share/lowmarch/vroid/lowmarch_bodies/cage/arm_f_strong_4ad9ea3b57cd9a77.vrm\")\n    v_e = VRM(p_elaine_src)\n    j_e, bin_e, lm_e, chart_e = sculpt_body_and_face(v_e, sex=\"f\")\n    vrm_e_out = os.path.join(OUT_DIR, \"elaine_argon_sculpt.vrm\")\n    sz_e = save_vrm(vrm_e_out, j_e, bin_e)\n    hair_e = build_elaine_valkyrie_hair(chart_e, lm_e)\n    hair_e_out = os.path.join(OUT_DIR, \"elaine_argon_hair.npz\")\n    np.savez_compressed(hair_e_out, **hair_e)\n    print(f\"Elaine sculpt VRM: {vrm_e_out} ({sz_e / 1e6:.2f} MB), custom hair: {len(hair_e['pos'])} verts, {len(hair_e['tri'])} tris\")\n\n    # 2. Aldric: sculpt from arm_m_heroic (1.88 m heroic lord stature)\n    p_aldric_src = os.path.expanduser(\"~/.local/share/lowmarch/vroid/lowmarch_bodies/cage/arm_m_heroic_460837128ce488ff.vrm\")\n    v_a = VRM(p_aldric_src)\n    j_a, bin_a, lm_a, chart_a = sculpt_body_and_face(v_a, sex=\"m\")\n    vrm_a_out = os.path.join(OUT_DIR, \"aldric_argon_sculpt.vrm\")\n    sz_a = save_vrm(vrm_a_out, j_a, bin_a)\n    hair_a = build_aldric_noble_hair(chart_a, lm_a)",
      "Target": "    # 1. Elaine: sculpt from arm_f_strong (1.81 m athletic Valkyrie stature)\n    p_elaine_src = os.path.expanduser(\"~/.local/share/lowmarch/vroid/lowmarch_bodies/cage/arm_f_strong_4ad9ea3b57cd9a77.vrm\")\n    v_e = VRM(p_elaine_src)\n    j_e, bin_e, lm_e = sculpt_body_and_face(v_e, sex=\"f\")\n    vrm_e_out = os.path.join(OUT_DIR, \"elaine_argon_sculpt.vrm\")\n    sz_e = save_vrm(vrm_e_out, j_e, bin_e)\n    hair_e = build_elaine_valkyrie_hair(lm_e)\n    hair_e_out = os.path.join(OUT_DIR, \"elaine_argon_hair.npz\")\n    np.savez_compressed(hair_e_out, **hair_e)\n    print(f\"Elaine sculpt VRM: {vrm_e_out} ({sz_e / 1e6:.2f} MB), custom hair: {len(hair_e['pos'])} verts, {len(hair_e['tri'])} tris\")\n\n    # 2. Aldric: sculpt from arm_m_heroic (1.88 m heroic lord stature)\n    p_aldric_src = os.path.expanduser(\"~/.local/share/lowmarch/vroid/lowmarch_bodies/cage/arm_m_heroic_460837128ce488ff.vrm\")\n    v_a = VRM(p_aldric_src)\n    j_a, bin_a, lm_a = sculpt_body_and_face(v_a, sex=\"m\")\n    vrm_a_out = os.path.join(OUT_DIR, \"aldric_argon_sculpt.vrm\")\n    sz_a = save_vrm(vrm_a_out, j_a, bin_a)\n    hair_a = build_aldric_noble_hair(lm_a)"
    }

    result, 1 line

    Made 1 replacement in ~/work/lowmarch/tools/blender_sculpt_lead.py starting at line 655 (+4/-4 lines).
  • run_command{"CommandLine":"/usr/bin/time -f \"wall=%Es\" blender -b --python tools/blender_sculpt_lead.py","WaitMsBeforeAsync":10000,"toolSummary":"Run Blender 5.2.3 BVHTree skull-raycast hair and body sculptor"}

    input

    {
      "CommandLine": "/usr/bin/time -f \"wall=%Es\" blender -b --python tools/blender_sculpt_lead.py",
      "WaitMsBeforeAsync": 10000,
      "toolSummary": "Run Blender 5.2.3 BVHTree skull-raycast hair and body sculptor"
    }

    result, 19 lines

    Command exited with code 0.
    
    Command output:
    Blender 5.2.3 LTS (hash e13b728c6880 built 2026-10-22 01:35:05)
    00:00.258  system.path      | WARNING Could not get a list of mounted file-systems
    Traceback (most recent call last):
      File "~/work/lowmarch/tools/blender_sculpt_lead.py", line 680, in <module>
        main()
        ~~~~^^
      File "~/work/lowmarch/tools/blender_sculpt_lead.py", line 658, in main
        j_e, bin_e, lm_e, chart_e = sculpt_body_and_face(v_e, sex="f")
                                    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
      File "~/work/lowmarch/tools/blender_sculpt_lead.py", line 241, in sculpt_body_and_face
        bt_head = b_tri[head_mask[b_tri].all(1)]
                  ^^^^^
    NameError: name 'b_tri' is not defined
    
    Blender quit
    wall=0:02.73s
  • edit_file{"Path":"~/work/lowmarch/tools/blender_sculpt_lead.py","Replacement":" head_mask = w_head > 0.5\n bt_head = tri[head_mask[tri].all(1)]","Target":" head_mask = w_head > 0.5\n bt_head = b_tri[head_mask[b_tri].all(1)]"}

    input

    {
      "Path": "~/work/lowmarch/tools/blender_sculpt_lead.py",
      "Replacement": "    head_mask = w_head > 0.5\n    bt_head = tri[head_mask[tri].all(1)]",
      "Target": "    head_mask = w_head > 0.5\n    bt_head = b_tri[head_mask[b_tri].all(1)]"
    }

    result, 1 line

    Made 1 replacement in ~/work/lowmarch/tools/blender_sculpt_lead.py starting at line 240 (+1/-1 lines).
  • run_command{"CommandLine":"/usr/bin/time -f \"wall=%Es\" blender -b --python tools/blender_sculpt_lead.py","WaitMsBeforeAsync":10000,"toolSummary":"Run Blender 5.2.3 BVHTree skull-raycast hair and body sculptor"}

    input

    {
      "CommandLine": "/usr/bin/time -f \"wall=%Es\" blender -b --python tools/blender_sculpt_lead.py",
      "WaitMsBeforeAsync": 10000,
      "toolSummary": "Run Blender 5.2.3 BVHTree skull-raycast hair and body sculptor"
    }

    result, 11 lines

    Command exited with code 0.
    
    Command output:
    Blender 5.2.3 LTS (hash e13b728c6880 built 2026-10-22 01:35:05)
    00:00.093  system.path      | WARNING Could not get a list of mounted file-systems
    Elaine sculpt VRM: ~/work/lowmarch/review/out/vroid-02/cache/elaine_argon_sculpt.vrm (20.40 MB), custom hair: 8800 verts, 16992 tris
    Aldric sculpt VRM: ~/work/lowmarch/review/out/vroid-02/cache/aldric_argon_sculpt.vrm (20.38 MB), custom hair: 5328 verts, 10224 tris
    Blender 5.2.3 sculpt + hair build finished in 0.88s
    
    Blender quit
    wall=0:01.88s