agent (cont.)

+10:26
  • read_file{"Path":"~/work/sortie/kit/lab/board_tourney.py"}

    input

    {
      "Path": "~/work/sortie/kit/lab/board_tourney.py"
    }

    result, 357 lines

    Showing lines 1-356 of 356
    1: """Tilt (line D), tourney harness: the jousting armour of the references (docs/study-atelier.md), built
    2: lopsided on purpose.
    3: 
    4: The left side, the side that meets the lance, carries the weight: a grandguard over the left breast
    5: and pauldron, an upstanding volant guard beside the helm, a broad pasguard over the left elbow. The
    6: right side is the sword arm: a small pauldron with a round besagew at the armpit, a lance rest
    7: hooked on the right breast. A frog mouth helm, its crown jutting over the sight. Smooth plates, roped
    8: gold on the big pieces only. Asymmetry gives the strongest silhouette of the four and the clearest
    9: sense of a job, at the cost of the mirror rule every other maker keeps.
    10: 
    11: Grades by plate count (plates(J, P, g)): the light a grandguard over the breast alone, both pauldrons
    12: without lames, no volant or pasguard, a plain helm, the core block. The medium the board's line knight.
    13: The heavy three lames under the great pauldron and two under the small one, a taller volant, a manifer
    14: over the left forearm, tassets of three, add-ons over the cuisses and greaves, wings on both knees.
    15: The lance on every grade.
    16: """
    17: import math
    18: 
    19: import frame_std
    20: from knightkit import Sheet, addon, band, bead, by, cap, curve, horn, joint_covers, lames, lin, put, put2, rim, rivets, smooth, spline, tent
    21: from lib import clip, copy, mirror_x
    22: from makers import atelier
    23: from makers.atelier import bearing_at, lr
    24: from makers.shell import subtract
    25: 
    26: breast_r = curve([.98, 1.3, 1.5, 1.52, 1.45, 1.3, 1.12])
    27: 
    28: 
    29: def cuirass(u, z, grow=0.0, z0=12.15, z1=15.05):
    30:     r = breast_r(min(max((z - z0) / (z1 - z0), 0), 1)) + grow
    31:     a = math.radians(u)
    32:     return (r * 1.08 * math.cos(a), -.15 + r * math.sin(a), z)
    33: 
    34: 
    35: def right(P, name, bm, role, joint, bevel=.012):
    36:     """A right side only part, authored on the left and mirrored."""
    37:     P.solid(name, mirror_x(bm), role, joint, bevel=bevel)
    38:     bm.free()
    39: 
    40: 
    41: def chest(P, J, g):
    42:     T, C = J["torso"], J["cockpit"]
    43:     if g == "light":
    44:         C = T  # the light's cockpit is the core block: its breast does not open
    45:     z0 = 12.15
    46:     top = lambda u: 15.05 - .32 * tent(u, -90, 48) - .5 * smooth(abs(u + 90), 58, 80)
    47:     s = Sheet(lambda u, v: cuirass(u, z0 + (top(u) - z0) * v), lin(-172, -8, 30), lin(0, 1, 14), .14,
    48:               disp=lambda u, v: .06 * tent(u, -90, 10), inside=(0, 0, 13.6))
    49:     bm = s.bm()
    50:     # the hatch: the breast's middle between two seams, clear of the grandguard
    51:     hatch = clip(copy(bm), x=(-.72, .64), y=(-60, -.9), z=(12.86, 16))
    52:     bm = subtract(bm, frame_std.box(-.75, .67, -3, -.9, 12.82, 16))
    53:     P.solid("breast", bm, "main", T, bevel=.012)
    54:     P.solid("hatch", hatch, "main", C, bevel=.01)
    55:     neck = s.edge("v1", out=.02)
    56:     rim(P, "breast_rim", [p for p in neck if p.x < -.78], .06, T)
    57:     rim(P, "hatch_rim", [p for p in neck if -.7 < p.x < .62], .06, C)
    58:     # the grandguard: bolted over the left breast and up over the left shoulder, ivory, roped gold
    59:     big = g == "heavy"  # the castellan's grandguard is the one hero piece: bigger, standing further off, bolted
    60:     gtop = lambda u: 15.1 + (.85 if big else .55) * smooth(u, -70, -10)
    61:     gbot = lambda u: (12.7 if big else 13.15) - .5 * smooth(u, -60, -10)
    62:     gg = Sheet(lambda u, v: cuirass(u, gbot(u) + (gtop(u) - gbot(u)) * v, .42 if big else .3), lin(-70 if big else -66, 14 if big else 8, 18),
    63:                lin(0, 1, 10), .16 if big else .14, disp=lambda u, v: .07 * tent(u, -40, 9), inside=(0, 0, 13.8))
    64:     P.solid("grandguard", gg.bm(), "accent", T, bevel=.012)
    65:     edge = gg.edge("u0", out=.02)[::-1] + gg.edge("v0", out=.02) + gg.edge("u1", out=.02)
    66:     rim(P, "grandguard_rim", edge, .08, T, rope=1.0)
    67:     bolts = ((-55, 14.6), (-20, 14.0), (-50, 13.4)) + (((-62, 13.0), (-10, 15.2), (-30, 13.2)) if big else ())
    68:     P.solid("grandguard_bolts", _bolts([cuirass(u, z, .58 if big else .46) for u, z in bolts]), "metal", T, bevel=0)
    69:     # the volant: a guard standing up beside the helm on the left, taller on the castellan
    70:     if g != "light":
    71:         vh = by(g, 0, 16.35, 16.85)
    72:         v = band((0, .1), 14.9, lambda u: vh - .55 * smooth(abs(u + 10), 12, 46), [1.18, 1.2, 1.3], lin(-56, 40, 16), nv=8, kx=1.0, t=.14)
    73:         put(P, "volant", v, "accent", T)
    74:         rim(P, "volant_rim", v.edge("v1", out=.02), .07, T, rope=1.0)
    75:     # the lance rest on the right breast: a bracket and a hook
    76:     lr_ = merge_parts(frame_std.box(.82, 1.18, -1.86, -1.56, 13.1, 13.4),
    77:                       horn([(1.0, -1.82, 13.25), (1.0, -2.25, 13.32), (1.0, -2.5, 13.6), (1.0, -2.46, 13.9)], .14, n=8, power=.6))
    78:     right(P, "lance_rest", lr_, "metal", T)
    79:     bearing_at("chest", (-.9, -1.6, 14.3), (0, -1, 0), T, .7)
    80:     back = band((0, .15), 12.2, lambda u: 15.0 - .35 * smooth(u, 55, 80), [1.0, 1.4, 1.55, 1.5, 1.3], lin(14, 82, 10), nv=10, kx=1.04, ky=.92, t=.14)
    81:     put(P, "backplate", back, "main", T, T)
    82:     for i in range(by(g, 1, 1, 2)):
    83:         gor = band((0, .05), 14.82 + .3 * i, 15.3 + .3 * i, [1.12 - .1 * i, 1.04 - .1 * i, .94 - .1 * i], lin(-170, -10, 24), nv=4, kx=1.05, t=.1)
    84:         put(P, f"gorget{i}", gor, "main", T)
    85: 
    86: 
    87: def merge_parts(*bms):
    88:     from lib import merge
    89:     return merge(*bms)
    90: 
    91: 
    92: def _bolts(pts):
    93:     from knightkit import rivets
    94:     return rivets([(p, (p[0], p[1] + .15, 0)) for p in pts], r=.1)
    95: 
    96: 
    97: def waist(P, J, g):
    98:     W = J["waist"]
    99:     if g == "light":
    100:         return
    101:     s = band((0, -.12), 11.4, 12.3, [.94, .84, .9], lin(-168, -12, 24), nv=5, kx=1.08, t=.14)
    102:     put(P, "fauld_w", s, "main", W)
    103:     rim(P, "fauld_w_rim", s.edge("v0", out=.01), .05, W)
    104: 
    105: 
    106: def pelvis(P, J, g):
    107:     Pv = J["pelvis"]
    108:     f = band((0, 0), 10.52, 11.22, [1.42, 1.32, 1.18], lin(-172, -8, 28), nv=4, kx=1.06, ky=.84, t=.14)
    109:     put(P, "fauld", f, "main", Pv)
    110:     rim(P, "fauld_rim", f.edge("v0", out=.01), .06, Pv)
    111:     P.solid("crotch", atelier.sheet([(-.5, 10.6), (.5, 10.6), (.42, 10.1), (.14, 9.66), (-.14, 9.66), (-.42, 10.1)],
    112:                                     [(-1.02, 10.6), (-.38, 10.6), (-.38, 9.66), (-.8, 9.66)], None), "main", Pv)
    113:     tb = by(g, 9.75, 9.15, 9.6)
    114:     t = band((1.12, -.12), lambda u: tb + .25 * (1 - tent(u, -95, 70)), 10.7, lambda u, v: 1.12 - .12 * v + .05 * math.sin(math.pi * v),
    115:              lin(-162, -28, 20), nv=8, t=.16)
    116:     put(P, "tasset", t, "main", Pv, Pv)
    117:     rim(P, "tasset_rim", t.edge("v0", out=.015), .06, Pv, Pv)
    118:     if g != "light":
    119:         lames(P, "tasset_lame", (1.12, -.12), by(g, 0, 9.4, 9.95), by(g, 0, 1, 3), .5, .42, 1.04, -.03, lin(-160, -30, 18), Pv, Pv, "main",
    120:               by(g, 0, "main", "trim"))
    121:     c = band((0, 0), 9.8, 10.95, [1.42, 1.32, 1.24], lin(10, 88, 12), nv=4, ky=.92, t=.14)
    122:     put(P, "culet", c, "main", Pv, Pv)
    123: 
    124: 
    125: def _dome(c, prof, us, t=.14, dip=0.0):
    126:     sp = spline(prof)
    127: 
    128:     def f(u, v):
    129:         r, z = sp(v)
    130:         a = math.radians(u)
    131:         return (c[0] + r * math.cos(a), c[1] + r * .92 * math.sin(a), z - dip * max(0.0, math.cos(a)) * v * v)
    132:     return Sheet(f, us, lin(0, 1, 12), t, inside=(c[0], c[1], 14.0))
    133: 
    134: 
    135: def shoulder(P, J, g):
    136:     SL, SR = lr(J, "shoulder")
    137:     heavy = g == "heavy"
    138:     # left: a great dome and one broad lame under it
    139:     c = (2.36, .02)
    140:     d = _dome(c, [(.42, 15.18), (.92, 15.06), (1.2, 14.78), (1.36, 14.36), (1.42, 13.96)], lin(-140, 140, 40), dip=.3)
    141:     put(P, "pauldron_great", d, "main", SL)
    142:     rim(P, "pauldron_great_rim", d.edge("v1", out=.02), .08, SL, rope=1.0)
    143:     if g != "light":
    144:         dip = lambda u: .3 * max(0.0, math.cos(math.radians(u)))
    145:         lames(P, "pauldron_great_lame", c, 14.1, by(g, 0, 1, 3), .56, .42, 1.48, -.04, lin(-120, 120, 30), SL, None, "main", "trim", ky=.92,
    146:               flare=.06, dip=dip)
    147:     P.solid("pauldron_landing.L", band(c, 14.96, 15.14, .52, lin(-180, 180, 24), nv=1, t=.5).bm(), "main", SL, bevel=.01)
    148:     # the grandguard carries on over the great pauldron's front: one ivory reinforcement, breast to shoulder
    149:     sp = spline([(.62, 15.2), (1.04, 15.12), (1.32, 14.84), (1.48, 14.42), (1.54, 13.9)])
    150: 
    151:     def gf(u, v):
    152:         r, z = sp(v)
    153:         a = math.radians(u)
    154:         return (c[0] + r * math.cos(a), c[1] + r * .92 * math.sin(a), z - .3 * max(0.0, math.cos(a)) * v * v)
    155:     if g != "light":
    156:         gc = Sheet(gf, lin(-160, -40, 24), lin(0, 1, 10), .14, inside=(c[0], c[1], 14.0))
    157:         put(P, "grandguard_cop", gc, "accent", SL)
    158:         rim(P, "grandguard_cop_rim", gc.edge("u1", out=.02)[::-1] + gc.edge("v1", out=.02)[::-1], .08, SL, rope=1.0)
    159:     # right: a small dome and the besagew, a round plate hung over the armpit
    160:     d = _dome(c, [(.42, 15.16), (.78, 15.04), (.96, 14.8), (1.04, 14.46), (1.06, 14.2)], lin(-136, 136, 36))
    161:     right(P, "pauldron_small", d.bm(), "main", SR)
    162:     right(P, "pauldron_small_rim", bead(d.edge("v1", out=.02), .06), "trim", SR, bevel=0)
    163:     right(P, "pauldron_landing.R", band(c, 14.96, 15.14, .52, lin(-180, 180, 24), nv=1, t=.5).bm(), "main", SR, bevel=.01)
    164:     if heavy:
    165:         for i in range(2):
    166:             ls = band(c, 13.62 - .38 * i, 14.12 - .38 * i, [1.12 - .03 * i, 1.09 - .03 * i, 1.04 - .03 * i], lin(-120, 120, 26), nv=3, ky=.92, t=.12)
    167:             right(P, f"pauldron_small_lame{i}", ls.bm(), "main", SR)
    168:             right(P, f"pauldron_small_lame_rim{i}", bead(ls.edge("v0", out=.015), .055), "trim", SR, bevel=0)
    169:     bes = Sheet(cap((1.86, -1.0, 13.6), (-.2, -1, 0), (.62, .62, .18)), lin(0, 360, 28), lin(0, 88, 6), .1, wrap=True, inside=(1.86, -.7, 13.6))
    170:     right(P, "besagew", bes.bm(), "accent", SR)
    171:     right(P, "besagew_rim", bead(bes.edge("v1", out=.01), .06, closed=True), "trim", SR, bevel=0)
    172:     right(P, "besagew_spike", horn([(1.86, -1.16, 13.6), (1.82, -1.6, 13.6)], .14, n=8), "trim", SR, bevel=0)
    173:     bearing_at("shoulder.L", (3.75, 0, 14.3), (1, 0, -.3), SL, .5)
    174:     bearing_at("shoulder.R", (-3.4, 0, 14.4), (-1, 0, -.3), SR, .5)
    175: 
    176: 
    177: def upperarm(P, J, g):
    178:     UA = lr(J, "upperarm")
    179:     if g == "light":
    180:         return
    181:     if g == "heavy":
    182:         lames(P, "rerebrace_lame", (2.45, 0), 13.55, 2, .36, .3, .64, -.03, lin(-150, 150, 26), *UA, "main", "main")
    183:     s = band((2.45, 0), 12.4, 13.5, [.56, .54, .5], lin(-150, 150, 26), nv=5, t=.14)
    184:     put(P, "rerebrace", s, "main", *UA)
    185: 
    186: 
    187: def forearm(P, J, g):
    188:     FL, FR = lr(J, "forearm")
    189:     s = band((2.5, 0), 9.86, 11.5, [.58, .52, .46], lin(-165, 165, 40), nv=8, kx=.92, t=.14)
    190:     put(P, "vambrace", s, "main", FL, FR)
    191:     rim(P, "vambrace_rim", s.edge("v0", out=.015), .055, FL, FR)
    192:     cop = Sheet(cap((2.5, .18, 11.95), (.35, 1, 0), (.62, .58, .46)), lin(0, 360, 24), lin(0, 84, 8), .12, wrap=True, inside=(2.5, 0, 11.95))
    193:     put(P, "couter", cop, "main", FL, FR)
    194:     if g == "light":
    195:         return
    196:     if g == "heavy":
    197:         # the manifer: a reinforcing plate over the left forearm, ivory like the grandguard
    198:         addon(P, "manifer", (2.5, 0), lambda v: .66 - .06 * v, lin(-150, -40, 12), 9.95, 11.3, .3, FL, None, "accent", kx=.92, rope=1.0)
    199:     # the pasguard: a broad shell standing off the outside of the left elbow, ridged, roped
    200:     pg = Sheet(cap((2.86, .12, 12.25), (1, .1, .25), (1.06, .92, .3)), lin(0, 360, 36), lin(0, 84, 9), .12, wrap=True,
    201:                disp=lambda u, v: .06 * (tent(u, 0, 14) + tent(u, 180, 14)) * smooth(v, 10, 30), inside=(2.4, .12, 12.2))
    202:     P.solid("pasguard", pg.bm(), "main", FL, bevel=.012)
    203:     P.solid("pasguard_rim", bead(pg.edge("v1", out=.02), .07, rope=1.0, closed=True), "trim", FL, bevel=0)
    204: 
    205: 
    206: def thigh(P, J, g):
    207:     TH = lr(J, "thigh")
    208:     s = band((1.16, -.05), 6.75, 9.7, [.72, .8, .86, .86], lin(-162, -18, 24), nv=8, t=.2, disp=lambda u, v: .05 * tent(u, -90, 12))
    209:     put(P, "cuisse", s, "main", *TH)
    210:     if g == "light":
    211:         return
    212:     b = band((1.16, -.05), 7.0, 9.5, [.72, .8, .84], lin(28, 152, 16), nv=6, t=.18)
    213:     put(P, "cuisse_back", b, "main", *TH)
    214:     if g == "heavy":
    215:         addon(P, "cuisse_plate", (1.16, -.05), lambda v: .98 + .04 * v, lin(-140, -40, 14), 7.5, 9.45, .5, *TH, "main", rope=1.0)
    216: 
    217: 
    218: GC = (1.2, .02)
    219: 
    220: 
    221: def shin(P, J, g):
    222:     SH = lr(J, "shin")
    223:     heavy = g == "heavy"
    224:     cop = Sheet(cap((1.2, -.34, 6.12), (0, -1, 0), (.64, .64, .38)), lin(0, 360, 24), lin(0, 86, 8), .14, wrap=True, inside=(1.2, 0, 6.12))
    225:     put(P, "poleyn", cop, "main", *SH)
    226:     rim(P, "poleyn_rim", cop.edge("v1", out=.01), .06, *SH, closed=True)
    227:     if g != "light":
    228:         for nm, c, ax, rr in (("o", (1.9, -.2, 6.1), (1, -.2, 0), (.6, .54, .16)), ("i", (.58, -.2, 6.1), (-1, -.2, 0), (.42, .38, .12)))[:by(g, 0, 1, 2)]:
    229:             wing = Sheet(cap(c, ax, rr), lin(0, 360, 28), lin(0, 86, 6), .06, wrap=True, inside=(1.2, -.2, 6.1))
    230:             put(P, f"poleyn_wing_{nm}", wing, "main", *SH)
    231:             if heavy:
    232:                 rim(P, f"poleyn_wing_rim_{nm}", wing.edge("v1", out=.01), .045, *SH, closed=True)
    233:     gr = band(GC, 1.75, 5.5, [1.06, .86, .7, .66, .66, .6, .55], lin(-174, -6, 32), nv=14, ky=1.12, t=.16,
    234:               disp=lambda u, v: .06 * tent(u, -90, 12) * (1 - smooth(v, .9, 1)))
    235:     put(P, "greave", gr, "main", *SH)
    236:     rim(P, "greave_rim", gr.edge("v0", out=.02), .07, *SH)
    237:     if g != "light":
    238:         for i, (za, zb, ra, rb) in enumerate([(6.95, 6.6, .66, .72), (5.62, 5.3, .7, .66), (7.25, 6.9, .64, .7), (5.36, 5.04, .72, .68)][:by(g, 0, 2, 4)]):
    239:             pl = band((1.2, -.16), zb, za, [rb, ra], lin(-158, -22, 18), nv=3, ky=1.05, t=.12)
    240:             put(P, f"poleyn_lame{i}", pl, "main", *SH)
    241:             rim(P, f"poleyn_lame_rim{i}", pl.edge("v0", out=.01), .045, *SH, role="main")
    242:     if heavy:
    243:         addon(P, "greave_plate", GC, lambda v: [1.1, .94, .8, .74, .74][min(int(v * 4.999), 4)] + .02, lin(-122, -58, 12), 2.4, 5.1, .7, *SH,
    244:               "main", ky=1.12, rope=1.0)
    245:     calf = band(GC, 1.95, 5.35, [1.0, .82, .66, .74, .82, .66], by(g, lin(40, 140, 14), lin(12, 168, 20), lin(12, 168, 20)), nv=12, ky=1.12,
    246:                 t=by(g, .1, .14, .14))
    247:     put(P, "greave_calf", calf, "main", *SH)
    248:     for side, j, sx in (("L", SH[0], 1), ("R", SH[1], -1)):
    249:         bearing_at(f"shin.{side}", (1.2 * sx, GC[1] - .8, 4.0), (0, -1, 0), j, .4)
    250: 
    251: 
    252: def tilt_helm(g):
    253:     """The Tilt's own helm in place of the atelier's: a frog mouth great helm in one form. A keeled bevor
    254:     drawn forward into a prow, a gold lip on it, the sight a dark slot between the lip and a crown set back
    255:     above it, a comb down the crown, breaths on the right cheek, studs where it bolts to the breast. The
    256:     light wears it plain, the medium with a crest, the castellan with a taller crest and a brow plate."""
    257:     def make(P, J):
    258:         import lib
    259:         H = J["head"]
    260:         wrap = lambda u: (u + 270) % 360 - 180  # the angle from the front
    261:         # the bevor: front and sides, widening upward to the lip
    262:         bev = band((0, -.05), 15.72, lambda u: 16.36 - .1 * smooth(abs(wrap(u)), 60, 110), [.64, .72, .84], lin(-215, 35, 40), nv=6, ky=1.12,
    263:                    t=.12, disp=lambda u, v: .24 * tent(wrap(u), 0, 34) * smooth(v, 0, .7))
    264:         P.solid("helm_bevor", bev.bm(), "main", H, bevel=.012)
    265:         lib.solid(f"{P.n}_helm_lip", bead(bev.edge("v1", out=.02), .045), "trim", H)
    266:         # the crown: a barrel set back from the lip, down to the nape behind, a flat domed top, a gold brace
    267:         # from the sight over the top to the nape
    268:         z0 = lambda u: 16.42 - .62 * smooth(abs(wrap(u)), 70, 120)
    269:         rb = curve([.7, .73, .74, .72])
    270: 
    271:         def cf(u, v):
    272:             a = math.radians(u)
    273:             if v <= .7:
    274:                 z, r = z0(u) + (17.02 - z0(u)) * v / .7, rb(v / .7)
    275:             else:
    276:                 q = (v - .7) / .3 * math.pi / 2
    277:                 z, r = 17.02 + .16 * math.sin(q), .72 * math.cos(q) + .001
    278:             return (r * math.cos(a), .12 + r * 1.1 * math.sin(a), z)
    279:         crown = Sheet(cf, lin(-180, 180, 48)[:-1], lin(0, 1, 14), .12, wrap=True, inside=(0, .12, 16.7))
    280:         P.solid("head_helmet", crown.bm(), "main", H, bevel=.012)
    281:         lib.solid(f"{P.n}_helm_crown_rim", bead(crown.edge("v0", out=.02), .045, closed=True), "trim", H)
    282:         for u in (-90, 90):
    283:             k = [i for i, x in enumerate(crown.us) if abs(x - u) < 1e-6][0]
    284:             lib.solid(f"{P.n}_helm_brace{u}", bead([crown.point(k, j, .03) for j in range(len(crown.vs))], .07), "trim", H)
    285:         # the sight: a narrow dark slot, lit deep inside
    286:         sl = band((0, .12), 16.37, 16.41, .5, lin(-130, -50, 14), nv=1, ky=1.1, t=.04)
    287:         lib.solid(f"{P.n}_helm_sight", sl.bm(), "glow_eye", H, outline=False)
    288:         # breaths on the right cheek, studs at the bevor's foot
    289:         import frame_std
    290:         from lib import merge
    291:         P.solid("helm_breaths", merge(*[frame_std.box(-.86, -.7, -.62 + .1 * k, -.56 + .1 * k, 15.88, 16.18) for k in range(4)]), "joint", H, bevel=0)
    292:         P.solid("helm_studs", rivets([((x, -1.02 + .5 * abs(x), 15.84), (x, -1, 0)) for x in (-.24, .24)], r=.08), "metal", H, bevel=0)
    293:         # the crest: none on the light, a raked blade on the medium, taller with a brow plate on the castellan
    294:         if g == "light":
    295:             return
    296:         c = by(g, 0, 0.0, .5)
    297:         lead = [(-.55, 17.25), (-.3, 17.75 + c * .5), (.1, 18.2 + c), (.5, 18.35 + c)]
    298:         tail = [(.75, 18.15 + c), (.82, 17.6 + c * .4), (.62, 17.3)]
    299:         P.solid("helm_crest", atelier.sheet(atelier.rect(-.07, .07, 17.0, 19.5), lead + tail, None), "accent", H, bevel=.015)
    300:         edge = [(y - .06, z + .06) for y, z in lead] + [(y + .06, z - .07) for y, z in reversed(lead)]
    301:         lib.solid(f"{P.n}_helm_crest_edge", atelier.sheet(atelier.rect(-.085, .085, 17.0, 19.5), edge, None), "trim", H, bevel=.008)
    302:         if g == "heavy":
    303:             bp = band((0, .1), 16.55, 16.95, [.8, .78], lin(-150, -30, 20), nv=3, ky=1.08, t=.1)
    304:             P.solid("helm_brow", bp.bm(), "accent", H, bevel=.012)
    305:             lib.solid(f"{P.n}_helm_brow_rim", bead(bp.edge("v0", out=.02), .05, rope=1.0), "trim", H)
    306:             P.solid("helm_brow_studs", rivets([(bp.point(i, 2, .02), bp.N[i][2]) for i in (3, 10, 17)], r=.06), "metal", H, bevel=0)
    307:     return make
    308: 
    309: 
    310: def lance(P, J):
    311:     """The jousting lance, upright in the right hand: a grip, a vamplate over the hand, a long fluted cone."""
    312:     from lib import circle, loft
    313:     HR = J["hand", "R"]
    314:     x, y = -2.36, -.02
    315:     P.solid("lance_butt", loft([(5.6, circle(.12, 12, x, y)), (9.5, circle(.14, 12, x, y))]), "frame", HR, bevel=0)
    316:     P.solid("lance_vamplate", loft([(9.55, circle(.2, 20, x, y)), (9.9, circle(.86, 20, x, y)), (10.02, circle(.82, 20, x, y)),
    317:                                     (10.1, circle(.34, 20, x, y))]), "accent", HR, bevel=0)
    318:     P.solid("lance_vamplate_rim", bead([(x + .86 * math.cos(a), y + .86 * math.sin(a), 9.94) for a in lin(0, 2 * math.pi, 40)[:-1]], .05, closed=True),
    319:             "trim", HR, bevel=0)
    320:     P.solid("lance", loft([(10.05, circle(.34, 16, x, y)), (14.0, circle(.24, 16, x, y)), (18.6, circle(.06, 16, x, y)), (19.4, circle(.01, 16, x, y))]),
    321:             "main", HR, bevel=0)
    322:     P.solid("lance_ring", loft([(12.3, circle(.3, 16, x, y)), (12.5, circle(.3, 16, x, y))]), "trim", HR, bevel=0)
    323: 
    324: 
    325: def back(P, J, g):
    326:     """A smooth shell over the pack, its rim roped; the castellan's broader, its tanks plated over."""
    327:     from knightkit import back_layers
    328:     if g == "light":
    329:         return
    330:     B = J["backpack"]
    331:     k = by(g, 0, 0.0, .45)
    332:     sh = band((0, 1.5), 12.8 - k * .3, 14.55, [1.2 + k, 1.25 + k, 1.2 + k], lin(52, 128, 20), nv=6, kx=.88, t=.12)
    333:     put(P, "pack_shell", sh, "main", B)
    334:     rim(P, "pack_shell_rim", sh.edge("u0", out=.02)[::-1] + sh.edge("v0", out=.02) + sh.edge("u1", out=.02), .06, B, rope=1.0)
    335:     back_layers(P, J, g, "main")
    336: 
    337: 
    338: def plates(J, P, g="medium"):
    339:     from knightkit import helm, sabaton, shoulder_root
    340:     helm(P, J, g, tilt_helm(g), base=False)
    341:     chest(P, J, g)
    342:     waist(P, J, g)
    343:     pelvis(P, J, g)
    344:     shoulder(P, J, g)
    345:     shoulder_root(P, J)
    346:     upperarm(P, J, g)
    347:     forearm(P, J, g)
    348:     thigh(P, J, g)
    349:     shin(P, J, g)
    350:     lance(P, J)
    351:     sab = by(g, ((.55, -1.2), (-1.0, -3.2)), ((.55, -.6), (-.45, -1.6), (-1.45, -3.2)), ((.55, -.3), (-.2, -1.0), (-.85, -1.7), (-1.55, -2.4), (-2.25, -3.2)))
    352:     sabaton(P, J, lames=sab, point=.8, rims="front")
    353:     atelier.backpack(P, J, g)
    354:     back(P, J, g)
    355:     atelier.binder(P, J, g)
    356:     joint_covers(P, J, g, style="quilt", fauld="mail")
  • run_command{"CommandLine":"grep -rn \"bearing\" src/ kit/","WaitMsBeforeAsync":5000,"toolSummary":"Search bearing anchor usage"}

    input

    {
      "CommandLine": "grep -rn \"bearing\" src/ kit/",
      "WaitMsBeforeAsync": 5000,
      "toolSummary": "Search bearing anchor usage"
    }

    result, 46 lines

    Command exited with code 0.
    
    Command output:
    src/view/viewer.ts:25:/** An emblem at every bearing anchor of a model: the anchor's position, its direction into the plate, its size. */
    src/view/viewer.ts:26:function bearingDecals(root: THREE.Object3D, color: string): DecalSpec[] {
    src/view/viewer.ts:30:    if (!o.name.startsWith('bearing') || !o.visible) return;
    src/view/viewer.ts:100:    // ?bearings=1 puts a test emblem on every bearing anchor (bearing.*), in the palette's trim colour
    src/view/viewer.ts:101:    if (q.has('bearings')) applyDecals(root, bearingDecals(root, PALETTES[(q.get('palette') ?? 'merc') as PaletteName].trim.color));
    src/sim/aliens.test.ts:89:    // it goes round: the bearing keeps changing
    src/hud/threat.test.ts:9:  it('sit on the margin rectangle along their bearing', () => {
    src/hud/threat.test.ts:16:  it('pull in toward the centre to clear a panel, on the same bearing', () => {
    kit/makers/shell.py:160:def bearing(name, face, u, v, d, parent, size, lean=None):
    kit/makers/shell.py:165:    return empty(f"bearing.{name}", at, parent, dir=gltf_dir(-face.w), size=size)
    kit/makers/atelier.py:132:def bearing_at(name, at, normal, parent, size):
    kit/makers/atelier.py:134:    return empty(f"bearing.{name}", Vector(at) + n * .02, parent, dir=gltf_dir(-n), size=size)
    kit/makers/atelier.py:234:    bearing_at("chest", (.95, -.5 - r[1] * math.sqrt(max(0, 1 - (.95 / r[0]) ** 2)), 14.35), (0, -1, 0), T, .9)
    kit/makers/atelier.py:304:        bearing_at("tabard", (0, -1.36, 9.7), (0, -1, 0), Pv, .6)
    kit/makers/atelier.py:338:        bearing_at(f"shoulder.{side}", (xb * sx, 0, (ROOF + zf) / 2), (sx, 0, -(rx1 - rx0) / (ROOF - zf)), j, .5)
    kit/makers/atelier.py:399:    bearing_at("shield", rot("Z", SHIELD_CANT, about=(x0, 0, at[2])) @ b, rot("Z", SHIELD_CANT).to_3x3() @ Vector((1, 0, 0)), F, 1.6)
    kit/makers/atelier.py:457:        bearing_at(f"shin.{side}", (1.2 * sx, GREAVE_C[1] - .7 - G - .06, 4.3), (0, -1, 0), j, .4)
    kit/makers/atelier.py:509:    bearing_at("back", (0, 1.5 + depth + .06, 13.65), (0, 1, 0), B, 1.0)
    kit/makers/atelier.py:532:    bearing_at("back", (0, 1.78 + .88, 14.4), (0, 1, 0), C, 1.0)
    kit/makers/pattern.py:32:right and a neck guard behind with a vent slot. Bearing anchors (bearing.*) sit on the left
    kit/makers/pattern.py:110:def bearing_at(name, at, normal, parent, size):
    kit/makers/pattern.py:112:    return empty(f"bearing.{name}", Vector(at) + n * .02, parent, dir=gltf_dir(-n), size=size)
    kit/makers/pattern.py:214:    bearing_at("chest", (1.2, y, 14.3), (0, -1, k), T, .42)
    kit/makers/pattern.py:301:        bearing_at(f"shoulder.{side}", (x * sx, .2, 14.16), (sx, 0, -k), j, .5)
    kit/makers/pattern.py:442:        bearing_at(f"shin.{side}", (1.24 * sx, y, 5.1), (0, -1, k), j, .4)
    kit/lab/board_tourney.py:23:from makers.atelier import bearing_at, lr
    kit/lab/board_tourney.py:79:    bearing_at("chest", (-.9, -1.6, 14.3), (0, -1, 0), T, .7)
    kit/lab/board_tourney.py:173:    bearing_at("shoulder.L", (3.75, 0, 14.3), (1, 0, -.3), SL, .5)
    kit/lab/board_tourney.py:174:    bearing_at("shoulder.R", (-3.4, 0, 14.4), (-1, 0, -.3), SR, .5)
    kit/lab/board_tourney.py:249:        bearing_at(f"shin.{side}", (1.2 * sx, GC[1] - .8, 4.0), (0, -1, 0), j, .4)
    kit/lab/board_heraldic.py:28:from makers.atelier import bearing_at, by, lr
    kit/lab/board_heraldic.py:75:    bearing_at("chest", (.8, -1.75 - k, 14.4), (0, -1, 0), T, .8)
    kit/lab/board_heraldic.py:165:        bearing_at(f"shoulder.{side}", ((PC[0] + R) * sx, 0, zc), (sx, 0, 0), j, .7)
    kit/lab/board_heraldic.py:212:    bearing_at("shield", turn @ Vector((xs + .55, 0, 11.2)), turn.to_3x3() @ Vector((1, 0, 0)), F, 1.6)
    kit/lab/board_heraldic.py:243:        bearing_at(f"shin.{side}", (1.2 * sx, GC[1] - .85, 4.0), (0, -1, 0), j, .4)
    kit/lab/board_plate.py:19:from makers.atelier import bearing_at, lr
    kit/lab/board_plate.py:75:    bearing_at("chest", (.95, -1.62, 14.2), (0, -1, 0), T, .8)
    kit/lab/board_plate.py:173:        bearing_at(f"shoulder.{side}", ((PC[0] + 1.18) * sx, 0, 14.4), (sx, 0, -.3), j, .5)
    kit/lab/board_plate.py:266:        bearing_at(f"shin.{side}", (1.2 * sx, GC[1] - .8, 4.0), (0, -1, 0), j, .4)
    kit/lab/board_sleek.py:20:from makers.atelier import bearing_at, lr
    kit/lab/board_sleek.py:48:    bearing_at("chest", (1.0, -1.55, 14.3), (0, -1, 0), T, .8)
    kit/lab/board_sleek.py:160:        bearing_at(f"shoulder.{side}", (3.8 * sx, .1, 14.2), (sx, 0, 0), j, .5)
    kit/lab/board_sleek.py:266:        bearing_at(f"shin.{side}", (1.2 * sx, GC[1] - .85, 4.0), (0, -1, 0), j, .4)
  • read_file{"EndLine":60,"Path":"~/work/sortie/src/view/viewer.ts","StartLine":1}

    input

    {
      "EndLine": 60,
      "Path": "~/work/sortie/src/view/viewer.ts",
      "StartLine": 1
    }

    result, 61 lines

    Showing lines 1-60 of 143
    1: import * as THREE from 'three';
    2: import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
    3: import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
    4: import { model, type ModelName } from '../render/assets';
    5: import { MechRig, POSES, type PoseName } from '../render/mech';
    6: import type { PaletteName } from '../render/palette';
    7: import { Pipeline } from '../render/pipeline';
    8: import { addSpaceLight, createBackdrop, followSun, spaceEnvironment } from '../render/space';
    9: import { STRIKER_DECALS, applyDecals, type DecalSpec } from '../render/decals';
    10: import { PALETTES } from '../render/palette';
    11: import { look, setLook } from '../render/look';
    12: import { treatEyes, type EyeMode } from '../render/eyes';
    13: import { fitShip } from '../render/ship';
    14: import type { FrameClassId } from '../sim/frames';
    15: 
    16: /**
    17:  * Model viewer for review shots, in the game's own renderer:
    18:  *   /?view=striker&yaw=35&pitch=8&dist=34&pose=flight&weapon=rifle&palette=automaton
    19:  *   /?view=lineup  (the frame in each palette, side by side)
    20:  *   /?view=ship&bays=light,heavy&frame=light  (bay fits and shuttle clamps)
    21:  *   /?view=light&pose=launch&weapon=rifle  (light and heavy frames and their variants pose like the striker)
    22:  */
    23: const FRAMES: string[] = ['striker_a', 'striker_b', 'light', 'light_line', 'light_lancer', 'heavy', 'heavy_B', 'heavy_C'];
    24: 
    25: /** An emblem at every bearing anchor of a model: the anchor's position, its direction into the plate, its size. */
    26: function bearingDecals(root: THREE.Object3D, color: string): DecalSpec[] {
    27:   root.updateMatrixWorld(true);
    28:   const out: DecalSpec[] = [];
    29:   root.traverse((o) => {
    30:     if (!o.name.startsWith('bearing') || !o.visible) return;
    31:     const at = root.worldToLocal(o.getWorldPosition(new THREE.Vector3()));
    32:     const dir = o.userData.dir as [number, number, number] | undefined;
    33:     const size = Number(o.userData.size ?? 0.5);
    34:     if (dir) out.push({ kind: 'emblem', at: [at.x, at.y, at.z], dir, size: [size, size], color });
    35:   });
    36:   return out;
    37: }
    38: 
    39: export async function startViewer(canvas: HTMLCanvasElement, q: URLSearchParams) {
    40:   setLook(q.get('look'));
    41:   await document.fonts.ready;
    42:   const scene = new THREE.Scene();
    43:   const camera = new THREE.PerspectiveCamera(Number(q.get('fov') ?? 35), 1, 0.5, 2e5);
    44:   // ?bg=studio: a plain grey ground, an even room light and little bloom, for judging shape
    45:   const studio = q.get('bg') === 'studio';
    46:   const backdrop = createBackdrop();
    47:   const pipe = new Pipeline(canvas, scene, camera, studio ? null : backdrop);
    48:   const sun = addSpaceLight(scene);
    49:   if (studio) {
    50:     scene.background = new THREE.Color('#3a3e45');
    51:     const pmrem = new THREE.PMREMGenerator(pipe.renderer);
    52:     scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
    53:     pipe.bloom.strength = Number(q.get('bloom') ?? 0.12);
    54:   } else scene.environment = spaceEnvironment(pipe.renderer, backdrop);
    55:   scene.environmentIntensity = Number(q.get('env') ?? (studio ? 0.6 : 0.8) * look().fill);
    56:   const name = q.get('view') as ModelName | 'lineup';
    57:   const target = new THREE.Vector3();
    58:   const pose = (q.get('pose') ?? 'stand') as PoseName;
    59:   const weapon = q.get('weapon') as ModelName | null;
    60:
  • read_file{"EndLine":250,"Path":"~/work/sortie/kit/ship.py","StartLine":1}

    input

    {
      "EndLine": 250,
      "Path": "~/work/sortie/kit/ship.py",
      "StartLine": 1
    }

    result, 251 lines

    Showing lines 1-250 of 362
    1: """The mercenary ship: every merc flies this medium class (about 235 m). Bow is -Y.
    2: 
    3: Inside the lower hull, a hangar (two mech bays) opens forward into the launch tube, which runs to a
    4: door at the bow. The hull is one solid with the hangar and tube cut out, so the cavity walls are the
    5: interior walls. Markers for the game:
    6:   launch.start  where a mech stands on the shuttle      launch.end  where the shuttle stops
    7:   shuttle       the catapult sled (moves along -Y)      door.L/R    bow door halves (slide out along X)
    8:   bay.1, bay.2  hangar bays                             light.N     point lights (color, intensity)
    9:   signal.red/green  launch lamps                        nozzle.ship.N  engine exits
    10: 
    11: Bays and the shuttle fit every frame class (docs/sizes.md). Each bay carries three gantry fits and the
    12: game shows one per bay (ShipRig.configure):
    13:   gantry.N.light  two cradles side by side with boarding platforms at the core block, decks parked high
    14:   gantry.N.std    the striker fit: work decks at 8 and 15.5 m
    15:   gantry.N.heavy  the reinforced bay: jacketed and braced posts, clamp arms, decks at 11 and 21 m
    16: Standing points: bay.N.light.a, bay.N.light.b, bay.N.std, bay.N.heavy (extras: cls, platforms).
    17: The shuttle carries clamps.std, clamps.light (a raised sled) and clamps.heavy (outriggers), with a
    18: launch.start.<cls> marker for each (launch.start is the striker's).
    19: """
    20: from mathutils import Matrix, Vector
    21: 
    22: from lib import boolean, cylinder, empty, loft, merge, mirror_x, nozzle, octo, piston, prism, solid, transform
    23: from mech import gltf_dir, place
    24: 
    25: TUBE_W, TUBE_H = 9.0, 26.0          # half width, height
    26: TUBE_Y0, TUBE_Y1 = -16.0, -122.0    # hangar end, bow end
    27: HANGAR = dict(x=24.0, y0=-16.0, y1=34.0, h=30.0)
    28: 
    29: # lower hull stations: (y, width, height, chamfer, z centre)
    30: LOWER = [(-120, 24, 32, 6, 13), (-60, 30, 36, 7, 13), (-22, 58, 44, 8, 14), (60, 58, 44, 8, 14), (96, 48, 40, 9, 16)]
    31: 
    32: 
    33: def section(stations, y, grow=0.0):
    34:     for (y0, *a), (y1, *b) in zip(stations, stations[1:]):
    35:         if y0 <= y <= y1:
    36:             t = (y - y0) / (y1 - y0)
    37:             w, h, c, z = (p + (q - p) * t for p, q in zip(a, b))
    38:             return octo(w + grow, h + grow, c, y=z)
    39:     raise ValueError(y)
    40: 
    41: 
    42: def box(x0, x1, y0, y1, z0, z1):
    43:     return loft([(z0, [(x0, y0), (x1, y0), (x1, y1), (x0, y1)]), (z1, [(x0, y0), (x1, y0), (x1, y1), (x0, y1)])])
    44: 
    45: 
    46: BAYS = ((1, 16.0), (2, -16.0))
    47: BAY_Y, BAY_HW, BAY_Y0, BAY_Y1 = 10.0, 6.0, 3.0, 17.0   # bay centre, half width, front and back (12 by 14 m)
    48: GANTRY_H = 26.0
    49: # work platform heights per class, m: the striker's are the original decks
    50: DECKS = {"light": (4.4,), "standard": (8.0, 15.5), "heavy": (11.0, 21.0)}
    51: LIGHT_DX = 3.0     # light cradles either side of the bay centre
    52: HEAVY_Y = 9.2      # a heavy stands a little forward, clear of its deeper back deck
    53: STOW = 22.5        # where the work decks park when the bay is fitted for light frames
    54: 
    55: 
    56: def beam(p0, p1, w=.5, h=None):
    57:     """A square beam from p0 to p1."""
    58:     h = w if h is None else h
    59:     p0, p1 = Vector(p0), Vector(p1)
    60:     axis = p1 - p0
    61:     m = Matrix.Translation(p0) @ Vector((0, 0, 1)).rotation_difference(axis.normalized()).to_matrix().to_4x4()
    62:     r = [(-w / 2, -h / 2), (w / 2, -h / 2), (w / 2, h / 2), (-w / 2, h / 2)]
    63:     return transform(loft([(0, r), (axis.length, r)]), m)
    64: 
    65: 
    66: def corners(bx):
    67:     return [(px, py) for px in (bx - BAY_HW, bx + BAY_HW) for py in (BAY_Y0, BAY_Y1)]
    68: 
    69: 
    70: def racks(bx, r):
    71:     """Lift racks on the posts' inner faces: the work decks ride them to the height a class needs."""
    72:     out = []
    73:     for px, py in corners(bx):
    74:         sy = 1 if py == BAY_Y0 else -1
    75:         ys = sorted((py + r * sy, py + (r + .14) * sy))
    76:         out.append(box(px - .22, px + .22, ys[0], ys[1], .6, GANTRY_H - .4))
    77:     return out
    78: 
    79: 
    80: def carriages(bx, r, zs):
    81:     """The deck carriages, a collar round each post at each deck."""
    82:     k = r + .22
    83:     return [box(px - k, px + k, py - k, py + k, z - .6, z + .5) for px, py in corners(bx) for z in zs]
    84: 
    85: 
    86: def level(bx, z, back=2.4, side=1.6, out=.5, sides=True, wide=0.0):
    87:     """One work level: a back deck behind the frame and a side deck along each post line, railed."""
    88:     x0, x1, y0, y1 = bx - BAY_HW, bx + BAY_HW, BAY_Y0, BAY_Y1
    89:     decks = [box(x0 - wide, x1 + wide, y1 - back, y1, z, z + .4)]
    90:     rails = [box(x0, x1, y1 - back - .1, y1 - back + .1, z + 1.1, z + 1.25)]
    91:     if sides:
    92:         decks += [box(x0 - out, x0 + side, y0, y1, z, z + .4), box(x1 - side, x1 + out, y0, y1, z, z + .4)]
    93:         rails += [box(x0 + side - .1, x0 + side + .1, y0, y1, z + 1.1, z + 1.25),
    94:                   box(x1 - side - .1, x1 - side + .1, y0, y1, z + 1.1, z + 1.25)]
    95:     return decks, rails
    96: 
    97: 
    98: def fit_std(root, b, bx):
    99:     g = empty(f"gantry.{b}.std", (bx, BAY_Y, 0), root, cls="standard", platforms=list(DECKS["standard"]))
    100:     decks, rails = [], []
    101:     for z in DECKS["standard"]:
    102:         d, r = level(bx, z)
    103:         decks += d
    104:         rails += r
    105:     solid(f"gantry_decks.{b}", merge(*decks), "hull_dark", g, 0.05)
    106:     solid(f"gantry_rails.{b}", merge(*rails), "hazard", g)
    107:     solid(f"gantry_lifts.{b}", merge(*racks(bx, .5), *carriages(bx, .5, DECKS["standard"])), "metal", g, 0.03)
    108:     empty(f"bay.{b}.std", (bx, BAY_Y, .2), root, cls="standard", platforms=list(DECKS["standard"]))
    109: 
    110: 
    111: def fit_light(root, b, bx):
    112:     """Two cradles side by side. A light frame's pilot boards the core block on its back, so each
    113:     cradle has a platform tongue at the block's underside, off a walkway along the back of the bay
    114:     with stairs down behind it. The striker decks park up under the gantry top."""
    115:     g = empty(f"gantry.{b}.light", (bx, BAY_Y, 0), root, cls="light", platforms=list(DECKS["light"]))
    116:     x0, x1, y1 = bx - BAY_HW, bx + BAY_HW, BAY_Y1
    117:     z = DECKS["light"][0]
    118:     decks, rails = level(bx, STOW)
    119:     walk = [box(x0 - .5, x1 + .5, y1 - 2.4, y1, z - .3, z)]
    120:     rails += [box(x0, bx - .9, y1 - .15, y1, z + 1.0, z + 1.15), box(bx + .9, x1, y1 - .15, y1, z + 1.0, z + 1.15)]
    121:     plates, metal, frame, hazard = [], [], [], []
    122:     for sx, tag in ((1, "a"), (-1, "b")):
    123:         cx = bx + LIGHT_DX * sx
    124:         # foot plate with heel stops
    125:         plates.append(box(cx - 1.8, cx + 1.8, 7.4, 12.6, .2, .5))
    126:         hazard.append(box(cx - 1.8, cx + 1.8, 7.3, 7.6, .2, .56))
    127:         metal += [box(cx + .6 * k - .35, cx + .6 * k + .35, BAY_Y + .75, BAY_Y + 1.15, .5, .85) for k in (1, -1)]
    128:         # back frame: two posts, a top bar and a back rest reaching under the core block
    129:         frame += [box(cx + 1.6 * k - .25, cx + 1.6 * k + .25, 12.9, 13.4, .5, 7.2) for k in (1, -1)]
    130:         frame += [box(cx - 1.85, cx + 1.85, 12.9, 13.4, 6.8, 7.3), box(cx - 1.85, cx + 1.85, 12.95, 13.35, 3.2, 3.7)]
    131:         metal += [box(cx - .2, cx + .2, 11.6, 12.95, 3.3, 3.6), box(cx - .7, cx + .7, 11.3, 11.6, 3.0, 3.9)]
    132:         # boarding tongue at the block, off the walkway
    133:         walk.append(box(cx - 1.1, cx + 1.1, 11.4, y1 - 2.4, z - .3, z))
    134:         hazard.append(box(cx - 1.1, cx + 1.1, 11.3, 11.5, z - .32, z + .02))
    135:         rails += [box(cx + 1.0 * k - .07, cx + 1.0 * k + .07, 11.6, y1 - 2.4, z + 1.0, z + 1.15) for k in (1, -1)]
    136:         frame += [box(cx + 1.0 * k - .06, cx + 1.0 * k + .06, 11.6 + .9 * i, 11.72 + .9 * i, z, z + 1.0) for k in (1, -1)
    137:                   for i in range(4)]
    138:         empty(f"bay.{b}.light.{tag}", (cx, BAY_Y, .5), root, cls="light", platforms=[z], board=z)
    139:     # stairs down behind the walkway
    140:     steps = int(z / .4)
    141:     stairs = [box(bx - .8, bx + .8, y1 + i * .45, y1 + (i + 1) * .45, 0, z - (i + 1) * .4) for i in range(steps - 1)]
    142:     rails += [beam((bx + .8 * k, y1, z + 1.0), (bx + .8 * k, y1 + (steps - 1) * .45, 1.4), .1) for k in (1, -1)]
    143:     solid(f"gantry_decks.{b}l", merge(*decks, *walk, *stairs), "hull_dark", g, 0.05)
    144:     solid(f"gantry_rails.{b}l", merge(*rails), "hazard", g)
    145:     # carriages: the parked decks up top, and the walkway on the back posts
    146:     lifts = carriages(bx, .5, (STOW,)) + [c for c, (_, py) in zip(carriages(bx, .5, (z,)), corners(bx)) if py == y1]
    147:     solid(f"gantry_lifts.{b}l", merge(*racks(bx, .5), *lifts, *metal), "metal", g, 0.03)
    148:     solid(f"cradle_frames.{b}", merge(*frame), "frame", g, 0.04)
    149:     solid(f"cradle_plates.{b}", merge(*plates), "deck", g, 0.04)
    150:     solid(f"cradle_hazard.{b}", merge(*hazard), "hazard", g)
    151: 
    152: 
    153: def fit_heavy(root, b, bx):
    154:     """The reinforced bay: the posts get armoured jackets on footings and braces on the back and outer
    155:     faces, the floor a thick plate with heel clamps, the decks move up to suit 24 m and the back deck
    156:     widens. A heavy's shoulders fill the bay, so the upper level is the back deck alone and two clamp
    157:     arms off the back posts hold the torso."""
    158:     g = empty(f"gantry.{b}.heavy", (bx, BAY_Y, 0), root, cls="heavy", platforms=list(DECKS["heavy"]))
    159:     x0, x1, y0, y1 = bx - BAY_HW, bx + BAY_HW, BAY_Y0, BAY_Y1
    160:     xo = x1 if bx > 0 else x0          # the outer wall side, the inner side stays open to the lane
    161:     r = .95
    162:     jackets = [box(px - r, px + r, py - r, py + r, 0, GANTRY_H) for px, py in corners(bx)]
    163:     feet = [box(px - 1.5, px + 1.5, py - 1.5, py + 1.5, 0, 1.3) for px, py in corners(bx)]
    164:     braces = []
    165:     for za, zb in ((1.3, 10.6), (11.4, 20.6)):
    166:         braces += [beam((x0 + r, y1, za), (x1 - r, y1, zb), .55), beam((x1 - r, y1, za), (x0 + r, y1, zb), .55),
    167:                    beam((xo, y0 + r, za), (xo, y1 - r, zb), .55), beam((xo, y1 - r, za), (xo, y0 + r, zb), .55)]
    168:     lo, hi = DECKS["heavy"]
    169:     d1, r1 = level(bx, lo, back=3.2, side=.6, out=1.9)
    170:     d2, r2 = level(bx, hi, back=3.8, sides=False, wide=r + .3)
    171:     # clamp arms from the back posts to the torso flanks, each on a strut
    172:     arms, pistons = [], []
    173:     for k in (1, -1):
    174:         px = bx + (BAY_HW - r) * k
    175:         tip = Vector((bx + 3.0 * k, HEAVY_Y + 2.6, 16.8))
    176:         arms += [beam((px, y1 - r, 17.6), tip, .7, .9),
    177:                  box(tip.x - .5, tip.x + .5, tip.y - .7, tip.y + .2, tip.z - .8, tip.z + .8)]
    178:         pistons.append(piston((px, y1 - r, 13.5), (bx + 4.4 * k, (y1 + HEAVY_Y) / 2 + 1.2, 17.1), .3))
    179:     # floor plate and heel clamps
    180:     plate = [box(x0 - .4, x1 + .4, y0 - .4, y1 + .4, .2, .6)]
    181:     hazard = [box(x0 - .4, x1 + .4, y0 - .7, y0 - .3, .2, .64)]
    182:     clamps = []
    183:     for k in (1, -1):
    184:         fx = bx + 2.6 * k
    185:         clamps += [box(fx - 1.5, fx + 1.5, HEAVY_Y + 1.7, HEAVY_Y + 2.6, .6, 1.7),
    186:                    box(fx + 1.75 * k - .25, fx + 1.75 * k + .25, HEAVY_Y - 2.2, HEAVY_Y + 1.7, .6, 1.2)]
    187:     solid(f"gantry_jackets.{b}", merge(*jackets, *feet, *braces, *arms), "frame", g, 0.08)
    188:     solid(f"gantry_decks.{b}h", merge(*d1, *d2, *plate), "hull_dark", g, 0.05)
    189:     solid(f"gantry_rails.{b}h", merge(*r1, *r2, *hazard), "hazard", g)
    190:     solid(f"gantry_lifts.{b}h", merge(*racks(bx, r), *carriages(bx, r, DECKS["heavy"]), *clamps, *pistons), "metal", g, 0.03)
    191:     empty(f"bay.{b}.heavy", (bx, HEAVY_Y, .6), root, cls="heavy", platforms=list(DECKS["heavy"]))
    192: 
    193: 
    194: def build_bay(root, b, bx):
    195:     """A hangar bay: the shared posts and gantry top, then a gantry fit per class."""
    196:     x0, x1, y0, y1 = bx - BAY_HW, bx + BAY_HW, BAY_Y0, BAY_Y1
    197:     empty(f"bay.{b}", (bx, BAY_Y, .2), root, classes=["light", "standard", "heavy"])
    198:     solid(f"gantry_posts.{b}", merge(*[box(px - .5, px + .5, py - .5, py + .5, 0, GANTRY_H) for px, py in corners(bx)]),
    199:           "frame", root, 0.08)
    200:     solid(f"gantry_top.{b}", box(x0 - .5, x1 + .5, y0 - .5, y1 + .5, GANTRY_H, GANTRY_H + 1), "hull_dark", root, 0.05)
    201:     fit_light(root, b, bx)
    202:     fit_std(root, b, bx)
    203:     fit_heavy(root, b, bx)
    204: 
    205: 
    206: def build_ship():
    207:     root = empty("ship", (0, 0, 0), ship="merc_medium")
    208: 
    209:     # ---- hull ----
    210:     hull = solid("hull_lower", loft([(y, octo(w, h, c, y=z)) for y, w, h, c, z in LOWER], axis="y"), "hull", root)
    211:     # two cuts: one merged cutter of overlapping boxes isn't a clean volume and the boolean drops it
    212:     boolean(hull, box(-TUBE_W, TUBE_W, TUBE_Y1 - 4, TUBE_Y0 + 1, 0, TUBE_H), "DIFFERENCE", role="interior")
    213:     boolean(hull, box(-HANGAR["x"], HANGAR["x"], HANGAR["y0"], HANGAR["y1"], 0, HANGAR["h"]), "DIFFERENCE", role="interior")
    214:     solid("hull_upper", loft([(-52, octo(26, 18, 5, y=40)), (-20, octo(40, 26, 7, y=44)), (88, octo(40, 26, 7, y=44)),
    215:                               (110, octo(30, 22, 6, y=42))], axis="y"), "hull", root, 0.4)
    216:     solid("spine", loft([(-46, octo(10, 4, 1.5, y=58)), (84, octo(12, 4, 1.5, y=58))], axis="y"), "hull_dark", root, 0.2)
    217:     solid("bridge", loft([(54, octo(22, 30, 5, y=48)), (66, octo(18, 24, 5, y=49)), (71, octo(13, 17, 4, y=50))]),
    218:           "hull", root, 0.3)
    219:     solid("bridge_glass", prism([(-8, 63.6), (8, 63.6), (7.4, 65.6), (-7.4, 65.6)], 36.2, 37.6, "xz"), "screen", root,
    220:           outline=False)
    221:     solid("bridge_mast", prism([(46, 70), (54, 70), (52, 80), (49, 80)], -.4, .4, "yz"), "hull_dark", root, 0.1)
    222:     for y in (-72, -34):
    223:         band = solid(f"band{y}", loft([(y - 1.5, section(LOWER, y - 1.5, 0.9)), (y + 1.5, section(LOWER, y + 1.5, 0.9))],
    224:                                       axis="y"), "accent", root, 0.2)
    225:         # the bands are solid slabs; keep them out of the launch tube
    226:         boolean(band, box(-TUBE_W, TUBE_W, y - 3, y + 3, 0, TUBE_H), "DIFFERENCE")
    227:     solid("stern", loft([(92, octo(50, 42, 9, y=18)), (116, octo(44, 38, 9, y=20))], axis="y"), "hull_dark", root, 0.4)
    228:     for i, (x, z, r) in enumerate(((0, 22, 7.5), (15, 12, 5.0), (-15, 12, 5.0))):
    229:         bell, glow = nozzle(r, r * 1.3)
    230:         solid(f"engine{i}", place(bell, (x, 116, z), (0, 1, 0)), "hull_dark", root, smooth=True)
    231:         solid(f"engine{i}.glow", place(glow, (x, 116, z), (0, 1, 0)), "glow_thruster", root, outline=False)
    232:         empty(f"nozzle.ship.{i}", (x, 116 + r * 1.3, z), root, dir=gltf_dir((0, 1, 0)), radius=r)
    233: 
    234:     sponson = loft([(-34, octo(9, 13, 3, x=34, y=20)), (-14, octo(13, 19, 4, x=35, y=20)), (78, octo(13, 19, 4, x=35, y=22)),
    235:                     (96, octo(9, 13, 3, x=34, y=22))], axis="y")
    236:     sponson_r = mirror_x(sponson)
    237:     solid("sponson.L", sponson, "hull", root, 0.3)
    238:     solid("sponson.R", sponson_r, "hull", root, 0.3)
    239:     for i, y in enumerate((8, 30, 52)):
    240:         fin = box(41, 58, y, y + 14, 20.6, 21.4)
    241:         solid(f"radiator.L{i}", fin, "hull_dark", root, 0.1)
    242:         solid(f"radiator.R{i}", mirror_x(box(41, 58, y, y + 14, 20.6, 21.4)), "hull_dark", root, 0.1)
    243:     for i, (y, z, up) in enumerate(((-30, 57, 1), (70, 57, 1), (20, -8, -1))):
    244:         base = cylinder(3.2, z, z + 2 * up, 10, at=(0, y))
    245:         solid(f"turret{i}", base, "hull_dark", root, smooth=True)
    246:         head = loft([(z + 2 * up, octo(4, 5, 1)), (z + 4.2 * up, octo(3.4, 4.2, .9))])
    247:         solid(f"turret_head{i}", transform(head, Matrix.Translation((0, y, 0))), "hull", root, 0.1)
    248:         for bx in (-.8, .8):
    249:             solid(f"turret_gun{i}{bx}", cylinder(.35, y - 2, y - 8, 8, axis="y", at=(bx, z + 3.2 * up)), "frame",
    250:                   root, smooth=True)
  • read_file{"EndLine":362,"Path":"~/work/sortie/kit/ship.py","StartLine":251}

    input

    {
      "EndLine": 362,
      "Path": "~/work/sortie/kit/ship.py",
      "StartLine": 251
    }

    result, 113 lines

    Showing lines 251-362 of 362
    251:     for s, sx, role in (("L", 1, "lamp_red"), ("R", -1, "lamp_green")):
    252:         solid(f"nav.{s}", box(41.5 * sx - .6, 41.5 * sx + .6, -12, -10, 20, 22), role, root, outline=False)
    253: 
    254:     # ---- bow: tube mouth frame and doors ----
    255:     mouth = merge(box(-TUBE_W - 2, -TUBE_W, TUBE_Y1 - 2.5, TUBE_Y1 + 1.5, -1, TUBE_H + 1),
    256:                   box(TUBE_W, TUBE_W + 2, TUBE_Y1 - 2.5, TUBE_Y1 + 1.5, -1, TUBE_H + 1),
    257:                   box(-TUBE_W - 2, TUBE_W + 2, TUBE_Y1 - 2.5, TUBE_Y1 + 1.5, TUBE_H, TUBE_H + 2))
    258:     solid("mouth_frame", mouth, "hull_dark", root, 0.15)
    259:     solid("mouth_hazard", merge(box(-TUBE_W - 2.05, -TUBE_W - .4, TUBE_Y1 - 2.6, TUBE_Y1 - 1.6, -1, TUBE_H + 1),
    260:                                 box(TUBE_W + .4, TUBE_W + 2.05, TUBE_Y1 - 2.6, TUBE_Y1 - 1.6, -1, TUBE_H + 1)),
    261:           "hazard", root)
    262:     for s, sx in (("L", 1), ("R", -1)):
    263:         d = empty(f"door.{s}", (0, TUBE_Y1 + 6, 0), root, slide=gltf_dir((sx, 0, 0)))
    264:         x0, x1 = sorted((0, (TUBE_W + .5) * sx))
    265:         solid(f"door_panel.{s}", box(x0, x1, TUBE_Y1 + 5.4, TUBE_Y1 + 6.6, -.1, TUBE_H + .1), "hull_dark", d, 0.08)
    266:         xs = sorted((.0, 1.2 * sx))
    267:         solid(f"door_edge.{s}", box(xs[0], xs[1], TUBE_Y1 + 5.2, TUBE_Y1 + 5.4, -.1, TUBE_H + .1), "hazard", d)
    268: 
    269:     # ---- launch tube interior ----
    270:     solid("tube_deck", box(-TUBE_W, TUBE_W, TUBE_Y1 + 1, TUBE_Y0, 0, .25), "deck", root)
    271:     solid("tube_rails", merge(box(-1.0, -.6, TUBE_Y1 + 4, TUBE_Y0, .25, .55), box(.6, 1.0, TUBE_Y1 + 4, TUBE_Y0, .25, .55)),
    272:           "metal", root)
    273:     solid("tube_edges", merge(box(-TUBE_W, -TUBE_W + .8, TUBE_Y1 + 1, TUBE_Y0, .25, .35),
    274:                               box(TUBE_W - .8, TUBE_W, TUBE_Y1 + 1, TUBE_Y0, .25, .35)), "hazard", root)
    275:     ribs, lights, strips = [], [], []
    276:     y = TUBE_Y0 - 6
    277:     while y > TUBE_Y1 + 4:
    278:         ribs += [box(-TUBE_W, -TUBE_W + .8, y - .6, y + .6, 0, TUBE_H), box(TUBE_W - .8, TUBE_W, y - .6, y + .6, 0, TUBE_H),
    279:                  box(-TUBE_W, TUBE_W, y - .6, y + .6, TUBE_H - 1.0, TUBE_H)]
    280:         lights += [box(-7.3, -6.7, y - 3.6, y - 2.4, .25, .4), box(6.7, 7.3, y - 3.6, y - 2.4, .25, .4)]
    281:         y -= 8
    282:     for x in (-TUBE_W + .02, TUBE_W - .32):
    283:         strips.append(box(x, x + .3, TUBE_Y1 + 4, TUBE_Y0, 13.0, 13.4))
    284:     solid("tube_ribs", merge(*ribs), "hull_dark", root, 0.08)
    285:     solid("tube_lights", merge(*lights), "light", root, outline=False)
    286:     solid("tube_strips", merge(*strips), "light", root, outline=False)
    287:     for s, sx, role in (("red", -1, "lamp_red"), ("green", 1, "lamp_green")):
    288:         sig = empty(f"signal.{s}", (2.2 * sx, TUBE_Y0 - 8, TUBE_H - 2.2), root)
    289:         solid(f"signal_{s}", box(2.2 * sx - .9, 2.2 * sx + .9, TUBE_Y0 - 8.6, TUBE_Y0 - 7.4, TUBE_H - 3, TUBE_H - 1.4),
    290:               role, sig, outline=False)
    291:     solid("signal_box", box(-4, 4, TUBE_Y0 - 7.2, TUBE_Y0 - 6.4, TUBE_H - 3.6, TUBE_H - .8), "hull_dark", root, 0.05)
    292: 
    293:     # ---- catapult shuttle ----
    294:     start = Vector((0, TUBE_Y0 - 6, .55))
    295:     sh = empty("shuttle", start, root)
    296:     solid("shuttle_body", box(-2.6, 2.6, start.y - 4, start.y + 3.2, .3, 1.1), "frame", sh, 0.1)
    297:     solid("shuttle_hazard", box(-2.7, 2.7, start.y - 4.3, start.y - 3.8, .35, 1.05), "hazard", sh)
    298:     # foot clamps per class: the game shows the set for the frame on the shuttle (ShipRig.configure)
    299:     std = empty("clamps.std", start, sh, cls="standard")
    300:     for sx in (1, -1):
    301:         solid(f"clamp{sx}", box(1.25 * sx - 1.3, 1.25 * sx + 1.3, start.y - 2.4, start.y + 1.6, 1.1, 1.5), "metal", std, 0.06)
    302:         solid(f"clamp_lip{sx}", box(1.25 * sx - 1.3, 1.25 * sx + 1.3, start.y - 2.9, start.y - 2.5, 1.1, 1.9),
    303:               "accent", std, 0.04)
    304:     empty("launch.start", (0, start.y, 1.5), root)
    305:     empty("launch.start.std", (0, start.y, 1.5), root, cls="standard")
    306:     # light frames: a raised sled on the striker clamps with a small clamp pair and a heel bar, so a
    307:     # 6 m frame stands clear of the big clamp lips
    308:     lt = empty("clamps.light", start, sh, cls="light")
    309:     top = 2.3
    310:     solid("sled_body", box(-1.6, 1.6, start.y - 2.6, start.y + 1.9, 1.5, top - .25), "frame", lt, 0.06)
    311:     solid("sled_legs", merge(*[box(x - .35, x + .35, y - .35, y + .35, 1.1, 1.5) for x in (-1.2, 1.2)
    312:                                for y in (start.y - 2.0, start.y + 1.3)]), "frame", lt, 0.03)
    313:     solid("sled_hazard", box(-1.65, 1.65, start.y - 2.75, start.y - 2.45, 1.55, top - .3), "hazard", lt)
    314:     for sx in (1, -1):
    315:         solid(f"sled_clamp{sx}", box(.55 * sx - .45, .55 * sx + .45, start.y - 1.0, start.y + .7, top - .25, top),
    316:               "metal", lt, 0.03)
    317:         solid(f"sled_lip{sx}", box(.55 * sx - .45, .55 * sx + .45, start.y - 1.25, start.y - 1.0, top - .25, top + .3),
    318:               "accent", lt, 0.02)
    319:     solid("sled_heel_bar", box(-1.2, 1.2, start.y + .9, start.y + 1.3, top - .25, top + .45), "metal", lt, 0.03)
    320:     empty("launch.start.light", (0, start.y, top), root, cls="light")
    321:     # heavy frames: wide feet, so outriggers widen the shuttle and the clamps grow, with heel braces
    322:     hv = empty("clamps.heavy", start, sh, cls="heavy")
    323:     solid("outriggers", merge(box(-4.0, -2.4, start.y - 3.4, start.y + 2.6, .35, 1.0),
    324:                               box(2.4, 4.0, start.y - 3.4, start.y + 2.6, .35, 1.0)), "frame", hv, 0.06)
    325:     for sx in (1, -1):
    326:         x0, x1 = sorted((.25 * sx, 3.8 * sx))
    327:         solid(f"heavy_clamp{sx}", box(x0, x1, start.y - 2.9, start.y + 2.2, 1.1, 1.7), "metal", hv, 0.06)
    328:         solid(f"heavy_lip{sx}", box(x0, x1, start.y - 3.5, start.y - 2.9, 1.1, 2.5), "accent", hv, 0.05)
    329:         solid(f"heavy_heel{sx}", box(x0 + .3, x1 - .3, start.y + 1.6, start.y + 2.2, 1.7, 2.6), "metal", hv, 0.04)
    330:     solid("heavy_hazard", merge(box(-4.05, -2.4, start.y - 3.5, start.y - 3.2, .4, 1.05),
    331:                                 box(2.4, 4.05, start.y - 3.5, start.y - 3.2, .4, 1.05)), "hazard", hv)
    332:     empty("launch.start.heavy", (0, start.y, 1.7), root, cls="heavy")
    333:     empty("launch.end", (0, TUBE_Y1 + 10, 1.5), root)
    334:     empty("exit", (0, TUBE_Y1 - 4, TUBE_H / 2), root)
    335: 
    336:     # ---- hangar ----
    337:     hx, hy0, hy1, hh = HANGAR["x"], HANGAR["y0"], HANGAR["y1"], HANGAR["h"]
    338:     solid("hangar_deck", box(-hx, hx, hy0, hy1, 0, .2), "deck", root)
    339:     solid("hangar_lane", merge(box(-TUBE_W, -TUBE_W + .6, hy0, hy1 - 6, .2, .3), box(TUBE_W - .6, TUBE_W, hy0, hy1 - 6, .2, .3)),
    340:           "hazard", root)
    341:     for b, bx in BAYS:
    342:         build_bay(root, b, bx)
    343:     crane = [box(-hx + 1, hx - 1, 24, 26, 27.5, 28.6), box(-hx + 1, hx - 1, -6, -4, 27.5, 28.6),
    344:              box(-3, 3, -6, 26, 26.6, 27.5)]
    345:     solid("crane", merge(*crane), "hull_dark", root, 0.06)
    346:     crates = [(-20, -10, 0, 5, 3.5, 4, "accent"), (-20, -4.5, 0, 5, 3.5, 3, "hull_dark"), (19, -10, 0, 6, 4, 4.5, "trim"),
    347:               (19.5, -10, 4.5, 4, 3, 3, "hull_dark"), (-21, 26, 0, 4, 6, 5, "accent"), (20, 27, 0, 5, 5, 3, "hull_dark")]
    348:     for i, (cx, cy, cz, w, d, h, role) in enumerate(crates):
    349:         solid(f"crate{i}", box(cx - w / 2, cx + w / 2, cy - d / 2, cy + d / 2, cz, cz + h), role, root, 0.08)
    350:     panels = []
    351:     for px in (-14, 0, 14):
    352:         for py in (-8, 6, 20):
    353:             panels.append(box(px - 3, px + 3, py - 1, py + 1, hh - .3, hh))
    354:     solid("ceiling_lights", merge(*panels), "light", root, outline=False)
    355:     solid("back_wall_ribs", merge(*[box(x - .6, x + .6, hy1 - 1, hy1, 0, hh) for x in (-18, -9, 9, 18)]), "hull_dark",
    356:           root, 0.05)
    357: 
    358:     for i, (p, col, power) in enumerate((((0, 6, 26), (1.0, .96, .9), 1.0), ((14, 10, 22), (1.0, .96, .9), .7),
    359:                                          ((-14, 10, 22), (1.0, .96, .9), .7), ((0, -40, 22), (.85, .95, 1.0), .7),
    360:                                          ((0, -80, 22), (.85, .95, 1.0), .7))):
    361:         empty(f"light.{i}", p, root, color=list(col), power=power)
    362:     return root