Seraph round 8: canted hips splay the legs; chest and head are one shell whose centre creases carry the operator's two chest lines; flow lines traced off her markup and scored for sweep and edge direction

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 16:40:48 +01:00
commit 3b61f637b6
7 changed files with 1305 additions and 85 deletions

View file

@ -32,7 +32,7 @@ import json, os, sys
import numpy as np
import skeleton
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
from PIL import Image, ImageDraw, ImageFilter, ImageFont
name, quick = sys.argv[1], len(sys.argv) > 2
here = Path(__file__).resolve().parent
@ -250,7 +250,89 @@ def match_sheet(hero):
sheet_hip.save(dst / f"{name}_hip.png")
# --- flow lines: the operator's strokes on the hero view, and the same lines on the build ---------------------------
def resampled(points, n=60):
"""A polyline at n points evenly spaced along its length."""
p = np.asarray(points, float)
d = np.concatenate([[0], np.cumsum(np.hypot(*np.diff(p, axis=0).T))])
t = np.linspace(0, d[-1], n)
return np.stack([np.interp(t, d, p[:, 0]), np.interp(t, d, p[:, 1])], 1)
def edge_along(img, points, half):
"""How far the picture's edges run along a line: of the gradient energy within `half` pixels either side of the
line, the share that lies across it (an edge along the line has its gradient across it). 0.5 is texture with no
direction; a plate edge or crease that follows the line the whole way is near 1; steps and edges that cross it
pull it under 0.5. Returns (share over the whole line, share per tenth of its length)."""
g = np.asarray(img.convert("L").filter(ImageFilter.GaussianBlur(max(1.0, half / 5))), float)
gy, gx = np.gradient(g)
p = resampled(points, max(20, int(np.hypot(*np.diff(np.asarray(points, float), axis=0).T).sum())))
tan = np.gradient(p, axis=0)
tan /= np.maximum(np.hypot(tan[:, 0], tan[:, 1])[:, None], 1e-9)
nor = np.stack([-tan[:, 1], tan[:, 0]], 1)
across, total = np.zeros(len(p)), np.zeros(len(p))
for off in range(-half, half + 1):
q = np.rint(p + nor * off).astype(int)
ok = (q[:, 0] >= 0) & (q[:, 0] < g.shape[1]) & (q[:, 1] >= 0) & (q[:, 1] < g.shape[0])
x, y = q[ok, 0], q[ok, 1]
across[ok] += (gx[y, x] * nor[ok, 0] + gy[y, x] * nor[ok, 1]) ** 2
total[ok] += gx[y, x] ** 2 + gy[y, x] ** 2
tenths = [float(a.sum() / max(t.sum(), 1e-9)) for a, t in zip(np.array_split(across, 10), np.array_split(total, 10))]
return float(across.sum() / max(total.sum(), 1e-9)), tenths
def sweep(a, b):
"""How alike two lines run, each in its own picture: the mean cosine of the angle between their directions at
the same fraction of their lengths (1: the same sweep; a straight line against one that zigzags scores low)."""
ta, tb = np.gradient(resampled(a), axis=0), np.gradient(resampled(b), axis=0)
ta /= np.hypot(ta[:, 0], ta[:, 1])[:, None]
tb /= np.hypot(tb[:, 0], tb[:, 1])[:, None]
return float(np.abs((ta * tb).sum(1)).mean())
def drawn(img, lines, width=5):
img = img.convert("RGB")
d = ImageDraw.Draw(img)
for pts in lines:
d.line([tuple(q) for q in resampled(pts, 80)], fill=(255, 30, 20), width=width, joint="curve")
return img
def chest_head_sheet():
"""<name>_chest_head.png: the concept's chest and head beside the chest built alone at the matched camera, the
operator's two chest lines drawn on the concept and the shell's own crease runs (part_bench's chest_lines.json)
on ours; under them the same pair bare. Returns the two lines' scores."""
path = src / "parts" / "chest_lines.json"
if "flow" not in spec or not path.exists():
return {}
kf = sheet.width / spec["flow"]["unit"]
box = [v * sheet.width / spec["components"]["unit"] for v in spec["components"]["crops"]["chest"]]
zoom = 4
concept = sheet.crop(tuple(int(v) for v in box)).resize((int(box[2] - box[0]) * zoom, int(box[3] - box[1]) * zoom), Image.LANCZOS)
ours = Image.open(src / "parts" / "chest.png").convert("RGB")
built = json.loads(path.read_text(encoding="utf-8"))
out, c_lines, o_lines = {}, [], []
for tag in ("chest_r", "chest_l"):
c = [((x * kf - box[0]) * zoom, (y * kf - box[1]) * zoom) for x, y in spec["flow"]["lines"][tag]["points"]]
o = built[tag]
ec, _ = edge_along(concept, c, max(3, concept.height // 90))
eo, tenths = edge_along(ours, o, max(3, ours.height // 90))
out[tag] = {"sweep": round(sweep(c, o), 3), "edge_ours": round(eo, 3), "edge_concept": round(ec, 3), "edge_ours_least_tenth": round(min(tenths), 3)}
print(f"FLOW {name} {tag} (chest alone): sweep {out[tag]['sweep']:.2f}; edges along the line, ours {eo:.2f} (least tenth {min(tenths):.2f}), concept {ec:.2f}")
c_lines.append(c)
o_lines.append(o)
text = "; ".join(f"{t}: sweep {v['sweep']:.2f}, edge {v['edge_ours']:.2f} (concept {v['edge_concept']:.2f})" for t, v in out.items())
top = row([label(fit(drawn(concept, c_lines, 7), 900), "concept: chest and head, the operator's two lines"), label(fit(drawn(ours, o_lines), 900), "ours, the chest shell alone: its crease runs. " + text)], 900)
bottom = row([label(fit(concept, 900), "concept"), label(fit(ours, 900), "ours")], 900)
stack([top, bottom]).save(dst / f"{name}_chest_head.png")
return out
H = 1100
if os.environ.get("MECH_CHEST_ONLY"):
chest_head_sheet()
sys.exit(0)
if os.environ.get("MECH_MATCH_ONLY"): # the scores of what part_bench has rendered, without a build of the whole mech
match_sheet(None)
sys.exit(0)

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,8 @@ back(). Two fitters use it:
arch() a cap over a joint: a ring per station fore and aft; the outline's upper and outer edge, sampled where the
caller names its corners, is the cap's section at its middle; the side outline lowers and shortens that
section toward the cap's two ends
band() two of the operator's flow lines as the half-width of a plate's centre panel at a view height: where the
plate's two crease columns stand
Each returns rings of [x, y, z] for a sheet. The match score (compare.py) judges the result at the same camera.
python fit.py <mech> <plate> prints the outline's extent in metres and its width at ten heights
@ -81,6 +83,33 @@ def load(mech, plate):
return front, Outline(o["side"]), o["view"][0], o["view"][1]
def band(mech, a, b, plate):
"""Two flow lines (concepts.json "flow": the operator's strokes on the hero view) as a band on a plate: a function
of t, the fraction of the lines' height from their lower end (0) to their upper (1), giving half the distance
between the lines there, in metres across the plate (the view's width over the cosine of the plate's azimuth).
A plate whose two crease columns stand this far either side of its middle, t taken along the plate's own height
in the view, carries the two lines. The hero view is close and wide, so heights are matched by fraction."""
spec = json.loads((HERE / "concepts.json").read_text(encoding="utf-8"))[mech]
hero = spec["skeleton"]["views"]["hero"]
flow, o = spec["flow"], spec["outlines"]["plates"][plate]
scale = spec["skeleton"]["height_m"] / (hero["ground"] - hero["top"]) * spec["skeleton"]["unit"] / flow["unit"]
def x_at(points, y):
points = sorted(points, key=lambda p: p[1])
y = min(max(y, points[0][1]), points[-1][1])
for p, q in zip(points, points[1:]):
if p[1] <= y <= q[1]:
return p[0] + (y - p[1]) / max(q[1] - p[1], 1e-9) * (q[0] - p[0])
pa, pb = flow["lines"][a]["points"], flow["lines"][b]["points"]
lo, hi = max(min(p[1] for p in pa), min(p[1] for p in pb)), min(max(p[1] for p in pa), max(p[1] for p in pb))
cos = math.cos(math.radians(o["view"][0]))
def half(t):
y = hi + min(max(t, 0.0), 1.0) * (lo - hi)
return abs(x_at(pb, y) - x_at(pa, y)) * scale / 2 / cos
return half
def seen(p, az, el):
"""A point of the plate in the view: (u, v)."""
a, e = math.radians(az), math.radians(el)

View file

@ -1740,14 +1740,20 @@ def biped(cfg):
a shin and a levelled foot with rams across knee and ankle, then waist slew, chassis and arms as humanoid().
cfg: pelvis (saddle params), hip_h, links [(length, width, depth) thigh, shin], leg_aims {side: (thigh dir,
shin dir)} in the world, pin_r, bore, foot (width, length, drop), foot_part, waist_h, chassis, twist, arm,
aims, guns. The right leg's knee is re-solved (brokkr_kitbash.reach) so both soles stand on one plane."""
aims, guns; a leg's "hip_frame" is the slew ring's seat in the pelvis's frame, z out along the hip's axis; hip_cant: degrees the hip's axis is canted, its outboard end up, so the leg stands splayed (canted_hip).
The right leg's knee is re-solved (brokkr_kitbash.reach) so both soles stand on one plane."""
sad = place("saddle", "Pelvis", **cfg["pelvis"])
r, pin, legs = cfg["pelvis"]["ring_r"], cfg["pin_r"], {}
(l1, w1, d1), (l2, w2, d2) = cfg["links"]
fw, fl, fd = cfg["foot"]
for side in ("L", "R"):
tag, sock = f"Leg{side}", "hip_l" if side == "L" else "hip_r"
slew = attach(place("slew_ring", f"{tag}.HipSlew", mat="machine", r=r, height=cfg["hip_h"], bolts=20, teeth=64), "base", sad, sock, 0 if side == "L" else 180)
slew = place("slew_ring", f"{tag}.HipSlew", mat="machine", r=r, height=cfg["hip_h"], bolts=20, teeth=64)
if cfg.get("hip_cant"):
hip_frame = canted_hip(tag, sad, sock, slew, r, cfg["hip_cant"], -1 if side == "L" else 1)
else:
attach(slew, "base", sad, sock, 0 if side == "L" else 180)
hip_frame = frame_at(local_sockets(sad)[sock].translation, (-1 if side == "L" else 1, 0, 0), (0, 0, 1))
th = attach(place("thigh", f"{tag}.Thigh", length=l1, width=w1, depth=d1, pin_r=pin, ring_r=r), sock, slew, "top")
aim_roll(th, (0, 0, 1), cfg["leg_aims"][side][0])
sh = attach(place("link", f"{tag}.Shin", length=l2, width=w2, depth=d2, pin_r=pin), "tongue", th, "clevis")
@ -1768,13 +1774,32 @@ def biped(cfg):
rams = hinge_drive(f"{tag}.Knee", th, sh, cfg["bore"], cfg.get("knee", "ram"), sx)
if cross is None:
rams += hinge_drive(f"{tag}.Ankle", sh, ft, 0.7 * cfg["bore"], cfg.get("ankle_drive", "ram"), sx)
legs[side] = {"slew": slew, "links": [th, sh], "foot": ft, "cross": cross, "sole_z": (ft.matrix_world @ Vector((0, 0, fd))).z, "rams": rams}
legs[side] = {"slew": slew, "hip_frame": hip_frame, "links": [th, sh], "foot": ft, "cross": cross, "sole_z": (ft.matrix_world @ Vector((0, 0, fd))).z, "rams": rams}
ring = cfg["pelvis"]["top_r"]
waist = attach(place("slew_ring", "Waist", mat="machine", r=ring, height=cfg["waist_h"], bolts=30, teeth=90), "base", sad, "top")
core = attach(place("chassis", "Core", ring_r=ring, **cfg["chassis"]), "bottom", waist, "top", cfg.get("twist", 0.0))
return dict(pelvis=sad, legs=legs, waist=waist, core=core, arms=arms_on(core, cfg))
def canted_hip(tag, saddle, sock, slew, r, cant, sx):
"""CANTED HIP: the leg's splay, fixed. The hip's slew ring stands on a wedge collar on the pelvis's side face, its
axis tipped `cant` degrees, outboard end up, so the thigh, which hangs square to that axis, leans outboard by
the same angle at every pitch. Still one axis a hip: there is no abduction joint, and a stride swings the foot in
a plane tilted by the cant. The ring's lower edge stays on the face; the wedge fills what opens above it. The
ring is seated loose (the kit's flange sockets face along an axis)."""
c, rf = math.radians(cant), 1.3 * r
face = local_sockets(saddle)[sock].translation
normal = Vector((sx * math.cos(c), 0, math.sin(c)))
centre = face + Vector((sx * rf * math.sin(c), 0, 0))
frame = frame_at(centre, normal, (0, 0, 1))
seat_loose(slew, "base", saddle, frame, 0 if sx < 0 else 180)
ring = [frame @ Vector((rf * math.cos(a), rf * math.sin(a), 0)) for a in (math.tau * k / 32 for k in range(32))]
wedge = Geo()
wedge.hull(ring + [Vector((face.x, p.y, p.z)) for p in ring])
wedge.to_object(f"{tag}.HipWedge", "machine", saddle)
return frame
# --- joint designs: one axis each, each a helper -------------------------------------------------------------------
TWIN = {sfx: {kind: {"front": tuple(n + sfx for n in v["front"]), "back": tuple(n + sfx for n in v["back"])} for kind, v in SIDE_SOCKETS.items() if kind in ("link", "thigh", "talon", "foot", "trident")}
@ -2026,14 +2051,16 @@ def joint_points(body):
return out
def lay(sk, cfg, hull_top, depth, elbow_y, splay=1.0):
def lay(sk, cfg, hull_top, depth, elbow_y, splay=1.0, cant=False):
"""A biped() cfg laid on a solved skeleton (skeleton.solve): link lengths, the feet's drop, the pelvis's span
and height, the chassis's width, height and shoulder line, the upper arm's length and the leg and upper-arm
aims are derived; widths, radii and the pose in depth stay the caller's. `hull_top` is the chassis's top in
metres (the skeleton's height is the figure's, radiators and all). `depth` is {side: (knee, ankle)}: how far
each stands in front of the hip axis; the links take the left leg's lengths and the right is re-solved by
biped(). `elbow_y` is {side: the elbow's depth}. The legs have no splay joint, so they stand between the hip's
half-span (`splay` 0) and the mean of the hip's, knee's and ankle's (`splay` 1). Returns cfg, changed."""
half-span (`splay` 0) and the mean of the hip's, knee's and ankle's (`splay` 1). With `cant` they stand splayed on
canted hips instead (canted_hip): the cant is the lean of the line through the skeleton's knee and ankle, and the
hip stands where that line meets the hip's height. Returns cfg, changed."""
J = sk["joints"]
hip, knee, ankle, sh, el, waist = (Vector(J[k]) for k in ("hip", "knee", "ankle", "shoulder", "elbow", "waist"))
(_, w1, d1), (_, w2, d2) = cfg["links"]
@ -2042,6 +2069,12 @@ def lay(sk, cfg, hull_top, depth, elbow_y, splay=1.0):
cfg["foot"] = (cfg["foot"][0], cfg["foot"][1], ankle.y)
cfg["leg_aims"] = {side: ((0, k, knee.y - hip.y), (0, a - k, ankle.y - knee.y)) for side, (k, a) in depth.items()}
leg_x = hip.x + splay * ((hip.x + knee.x + ankle.x) / 3 - hip.x)
if cant:
lean = (ankle.x - knee.x) / (knee.y - ankle.y)
cfg["hip_cant"] = math.degrees(math.atan(lean))
leg_x = knee.x - lean * (hip.y - knee.y)
k = 1 / math.cos(math.atan(lean)) # a leaning link is longer for the same drop
cfg["links"] = [(length * k, w, d) for length, w, d in cfg["links"]]
cfg["pelvis"].update(span=2 * (leg_x - cfg["hip_h"] - 0.5 * w1), height=2 * (waist.y - hip.y))
ch, arm = cfg["chassis"], cfg["arm"]
ch["height"] = hull_top - waist.y - cfg["waist_h"]
@ -2130,20 +2163,24 @@ def sleeve_hinge(name, yoke, r, sleeve=(0.6, 0.6), ribs=5, mat="gunmetal"):
return g.to_object(name, mat, yoke, 40.0)
def recessed_rams(tag, shin, foot, bore, x, z_top, heel, lift=None):
def recessed_rams(tag, shin, foot, bore, x, z_top, heel, lift=None, on=None):
"""RECESSED RAMS, a lower leg: two rams side by side down the back of the shin, each from a lug high on the
shin's back (z_top along it, `x` either side of the centre plane) to a lug on the foot's heel (`heel`: (back
of the ankle pin, below it) in the foot's frame), driving the ankle. The armor's cheeks stand further back
than the rams, which is the recess (the caller's blocks). Lugs are seated loose; the rams are kit rams, closed
on the heel lugs. Returns the rams that fitted."""
on the heel lugs. `on` is what carries the heel lugs in place of the foot: a cross ankle's spider, whose pitch
pin is parallel to the shin's when the leg stands splayed and the foot rolls level under it (`heel` is then in
the spider's frame, from its pitch pin). Returns the rams that fitted."""
d = float(json.loads(shin["kit_params"])["depth"])
foot = on or foot
fy, fz = (1 if local_dir(foot, (0, 1, 0)).y > 0 else -1), (1 if local_dir(foot, (0, 0, -1)).z > 0 else -1)
lift = lift or 2.6 * bore
rams = []
for k, s in enumerate((-1, 1)):
la = seat_loose(place("lug", f"{tag}.RamLugA{k}", mat="machine", pin_r=bore / 2, height=lift, width=2.6 * bore), "mount", shin, frame_at((s * x, -0.5 * d, z_top), (0, -1, 0), (0, 0, 1)))
lb = place("lug", f"{tag}.RamLugB{k}", mat="machine", pin_r=bore / 2, height=lift, width=2.6 * bore)
for roll in (0.0, 180.0):
seat_loose(lb, "mount", foot, frame_at((s * x, -heel[0], heel[1]), (0, -0.35, -1), (0, 1, 0)), roll)
seat_loose(lb, "mount", foot, frame_at((s * x, -heel[0] * fy, heel[1] * fz), (0, -0.35 * fy, -fz), (0, fy, 0)), roll)
if sockets(la)["pivot"].col[2].xyz.dot(sockets(lb)["pivot"].col[2].xyz) > 0:
break
ram = ram_between(f"{tag}.RecessRam{k}", la, lb, bore, body_fraction=0.62)
@ -2253,7 +2290,8 @@ class Build:
for mat, geo in self.geos.items():
if self.to_host is not None:
bmesh.ops.transform(geo.bm, matrix=Matrix(self.to_host), verts=geo.bm.verts[:])
obj = geo.to_object(f"{self.name}.{mat}", mat, self.host, 22.0 if mat in self.ARMOR else 38.0)
tag, mat = mat.split(":")[-1], mat.split(":")[0] # b["khaki:collar"]: khaki, an object of its own named <part>.collar
obj = geo.to_object(f"{self.name}.{tag}", mat, self.host, 22.0 if mat in self.ARMOR else 38.0)
if mat in self.ARMOR and bevel:
mod = obj.modifiers.new("Bevel", "BEVEL")
mod.width, mod.segments, mod.limit_method, mod.angle_limit = bevel, 1, "ANGLE", math.radians(18)

View file

@ -3,11 +3,11 @@ MECH_PARTS: comma-separated names from <MECH_SET>_parts.PARTS (default all); MEC
Writes MECH_OUT/<mech>/parts/<name>.png, 800 px, for compare.py's components sheet, and for a part in the set's
MASKS, <name>_mask.png: its scored objects' outline at the same camera, for compare.py's match score.
MECH_MASK_ONLY: masks only. MECH_FOLDS: mechlib.shells_sound() on each part (folds and open edges stop the bench)."""
import importlib, math, os, sys, time
import importlib, json, math, os, sys, time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import mechlib as M
from mathutils import Matrix
from mathutils import Matrix, Vector
import bpy
M.setup()
@ -36,6 +36,10 @@ for name in names:
M.part_mask(rig, cam, radius, az, el, out / f"{name}_mask.png", (800, 800), lib.MASKS[name], margin=margin, lens=lens)
if not os.environ.get("MECH_MASK_ONLY"):
M.shot(rig, cam, radius, az, el, out / f"{name}.png", (800, 800), margin=margin, lens=lens)
lines = getattr(lib, "LINES", {}).get(name)
if lines: # the flow lines the part carries, as built, in this view's pixels
drawn = {line: [M.project(cam, {"p": host.matrix_world @ Vector(p)}, (800, 800))["p"] for p in points] for line, points in lines.items()}
(out / f"{name}_lines.json").write_text(json.dumps(drawn), encoding="utf-8")
if os.environ.get("MECH_FOLDS"):
try:
M.shells_sound()

View file

@ -19,12 +19,12 @@ P = "khaki"
SK = skeleton.solve("seraph")
CROSS = 0.36
CFG = dict(pelvis=dict(span=1.4, ring_r=0.5, top_r=0.55, depth=1.1, height=1.5), hip_h=0.6, links=[(2.2, 0.8, 0.85), (2.4, 0.8, 0.8)], pin_r=0.12, bore=0.11, foot=(1.5, 2.2, 0.8), foot_part="trident",
knee="none", ankle="cross", ankle_drive="none", cross_drop=CROSS, elbow="none", waist_h=0.14, twist=-6,
knee="none", ankle="cross", ankle_drive="none", cross_drop=CROSS, elbow="none", waist_h=0.14, twist=-12,
chassis=dict(width=3.0, depth=1.5, height=3.0, top_r=0.24, side_r=0.45, shoulder=0.66),
arm=dict(pin_r=0.11, yoke=(0.6, 0.6), twist_r=0.3, upper=1.5, elbow=(0.5, 0.5), fore=1.0),
aims={"L": ((0, 1, 0.05), None, (-0.05, 0.4, -1)), "R": ((0, 1, 0.25), None, (0.1, 1, -0.6))},
guns={"L": (0.26, 1.5), "R": (0.32, 3.4)})
M.lay(SK, CFG, hull_top=9.25, depth={"L": (0.55, -0.1), "R": (0.15, -0.25)}, elbow_y={"L": 0.1, "R": 0.45}, splay=0.6)
M.lay(SK, CFG, hull_top=8.9, depth={"L": (0.55, -0.1), "R": (0.15, -0.25)}, elbow_y={"L": 0.1, "R": 0.45}, cant=True)
CFG["foot"] = (CFG["foot"][0], CFG["foot"][1], CFG["foot"][2] - CROSS)
FOOT, LINKS = CFG["foot"], CFG["links"]
body = M.biped(CFG)
@ -42,10 +42,9 @@ def put(name, fn, host, to_host, **kw):
# --- torso: chest plates, the cockpit in its gorget, the cooling assemblies ----------------------------------------------
put("Chest", SP.chest, core, T((0, 0.0, CH - 1.05)))
put("Cockpit", SP.cockpit, core, T((0, 0.05, CH + 0.3)) @ Matrix.Scale(0.82, 4))
put("Cooling", SP.cooling, core, T((0, -1.0, CH - 1.0)))
sh_x, sh_z = 0.5 * CFG["chassis"]["width"] + 0.47 * CFG["chassis"]["side_r"] + CFG["arm"]["yoke"][0], CFG["chassis"]["shoulder"] * CH
put("Chest", SP.chest, core, T((0, 0.0, sh_z + 0.09))) # one shell, breast to cowl: the head is the chest's own top, the frame's roof stands under its slope
put("Cooling", SP.cooling, core, T((0, -1.0, sh_z + 0.14)))
for side, sx in (("L", -1), ("R", 1)):
put(f"Pauldron{side}", SP.pauldron, core, T((sx * sh_x, 0.0, sh_z)) @ (MIR if sx > 0 else Matrix.Identity(4))) # the cap's inboard edge stands at the shoulder's pivot
put("Battery", SP.battery, core, T((sh_x - 0.2, 1.45, sh_z + 0.05)) @ Matrix.Scale(0.7, 4))
@ -61,7 +60,8 @@ cod.plate(F((0, 0.78, -0.45), (0, 1, -0.2), UP), 1.7, [(0, 0.2), (0.1, 0.32), (0
cod.plate(F((0, -0.7, -0.3), (0, -1, -0.15), UP), 1.4, [(0, 0.2), (0.1, 0.32), (0.55, 0.42), (0.9, 0.38), (1, 0.26)], bend=1.6)
cod.finish()
for side, sx in (("L", -1), ("R", 1)):
put(f"Hip{side}", SP.hip, pel, T((sx * (0.5 * CFG["pelvis"]["span"] + 0.5 * CFG["hip_h"]), 0.0, 0.0)) @ (MIR if sx > 0 else Matrix.Identity(4)), length=CFG["hip_h"]) # the drum is the hip's slew ring dressed: 0.6 m of it between a narrow pelvis and the thigh, as the rear view has it
along = Matrix(((0, -sx, 0, 0), (0, 0, 1, 0), (-1, 0, 0, 0), (0, 0, 0, 1))) # the drum's own x (inboard) down the hip frame's z, its z up
put(f"Hip{side}", SP.hip, pel, legs[side]["hip_frame"] @ T((0, 0, 0.5 * CFG["hip_h"])) @ along, length=CFG["hip_h"]) # the drum is the hip's slew ring dressed: 0.6 m of it between a narrow pelvis and the thigh, as the rear view has it
# --- arms: the upper arm's tiers, a sleeve hinge, the cannon on the right forearm and the emitter on the left -------------
for side, arm in arms.items():
@ -87,7 +87,7 @@ for side, leg in legs.items():
foot = leg["foot"]
k = (FOOT[2] + CROSS) / 0.8
put(f"Foot{side}", SP.foot, foot, M.seat(foot, (0, 0, -CROSS), outboard=1, side=sx, scale=k))
leg["rams"] = M.recessed_rams(f"Leg{side}", shin, foot, 0.11, 0.2, 0.5, (0.5, 0.0))
leg["rams"] = M.recessed_rams(f"Leg{side}", shin, foot, 0.11, 0.2, 0.5, (0.5, 0.0), on=leg["cross"])
lo, _ = M.bounds()
pel.location.z -= lo.z

View file

@ -19,7 +19,7 @@ ALONG_Y = F((0, 0, 0), (0, 1, 0), (0, 0, 1)) # a frame whose z is
VIEWS = {"cockpit": (0, 20, 0.52, 0), "battery": (24, 2, 0.78, 0), "cannon": (-20, 2, 0.6, -20), "emitter": (-32, 0, 0.66, -32),
"cooling": (174, 3, 0.8, 0), "hip": (15, -11, 0.8, 0), "knee": (90, 0, 0.8, 0), "foot": (-40, 9, 0.85, 0),
"chest": (20, -19, 0.8, 0), "pauldron": (8, -21, 0.85, 0), "thigh": (14, -7, 0.85, 14), "shin": (14, 2, 0.9, -15)}
"chest": (30, -19, 0.8, 0), "pauldron": (8, -21, 0.85, 0), "thigh": (14, -7, 0.85, 14), "shin": (14, 2, 0.9, -15)}
# The last four are crops of the hero view, so their camera is the hero camera's direction onto that part of the
# assembled build (seraph.py: 18 degrees round to the left, 17 m off, its eye 2.4 m up, so it looks up 19 degrees at
# the chest and 21 at the left pauldron), and their pitch is the lean of the limb the part rides. An inset's camera
@ -27,7 +27,7 @@ VIEWS = {"cockpit": (0, 20, 0.52, 0), "battery": (24, 2, 0.78, 0), "cannon": (-2
LENS = {"chest": 200.0, "pauldron": 200.0, "thigh": 200.0, "shin": 200.0} # the hero camera's distance, on a part alone
GROUND = {"foot": 0.8, "chest": 12.0, "pauldron": 12.0, "thigh": 8.0} # the bench's height for a part: the foot stands on the ground; a part seen from below is held clear of it
ARMOR = lambda name: not name.endswith((".gunmetal", ".machine", ".rubber", ".ribs", ".amber", ".glow_blue")) # noqa: E731
MASKS = {"pauldron": ARMOR, "chest": lambda name: ARMOR(name) and ".lame" not in name, "thigh": ARMOR, "shin": ARMOR, # what a crop's traced mask outlines (concepts.json "masks")
MASKS = {"pauldron": ARMOR, "chest": lambda name: name.endswith(".breast"), "thigh": ARMOR, "shin": ARMOR, # what a crop's traced mask outlines (concepts.json "masks")
"knee": lambda name: True, "foot": lambda name: True}
MIRROR = Matrix.Diagonal((-1.0, 1.0, 1.0, 1.0))
FRAMES = {"pauldron": (-118, -14, 0.6, ("pauldron.gunmetal", "pauldron.shield"))} # (azimuth, elevation, margin, objects hidden): a second bench view, from inboard and below, of the frame a plate stands on
@ -56,33 +56,9 @@ def track(g, a, b, width, n, t, normal):
def cockpit(b):
"""COCKPIT / SENSOR CLUSTER. Origin at the neck. A low, broad faceted helm (a flat crown panel, three brow facets,
a facet down each side), under the brow a wide dark face with two slanted amber eyes, a jaw block and cables, set
down into the chest's gorget: a plate rising to each shoulder and a front plate carrying a small framed hatch."""
k = b["khaki"]
k.hull([(0.36, 0.2, 0.78), (0.42, -0.5, 0.74), (0.44, 0.9, 0.36), (0.94, 0.52, 0.3), (1.04, -0.3, 0.32), (0.52, -0.95, 0.34),
(0.44, 0.88, 0.16), (0.94, 0.5, 0.1), (1.04, -0.3, 0.0), (0.54, -0.96, 0.0), (0.96, 0.2, 0.0)], mirror=True)
k.prism(T((0, -0.14, 0.765)) @ RX(-3.3), [(-0.3, -0.3), (0.3, -0.3), (0.26, 0.3), (-0.26, 0.3)], 0.025, 0.012) # the crown's panel
k.prism(F((0, 0.56, 0.585), (0, 0.42, 0.7), (0, 1, 0)), [(-0.3, -0.22), (0.3, -0.22), (0.36, 0.26), (-0.36, 0.26)], 0.02, 0.01) # the brow's centre panel
for s in (-1, 1): # cheek guards beside the face
k.hull([(s * 0.78, 0.62, 0.2), (s * 1.0, 0.36, 0.16), (s * 0.84, 0.66, -0.4), (s * 1.04, 0.36, -0.44), (s * 1.0, 0.0, 0.1), (s * 1.04, 0.0, -0.44)])
d = b["gunmetal"]
d.hull([(0.72, 0.6, 0.26), (0.72, 0.1, 0.26), (0.66, 0.7, -0.1), (0.7, 0.1, -0.5), (0.4, 0.78, -0.5)], mirror=True) # the face
d.box(T((0, 0.84, -0.26)), (0.26, 0.18, 0.4)) # the jaw block
d.box(T((0, 0.9, -0.1)), (0.36, 0.08, 0.07))
for s in (-1, 1):
d.box(T((s * 0.42, 0.76, -0.32)) @ RZ(-18 * s), (0.24, 0.14, 0.24))
for j in range(3):
d.rod((s * (0.17 + 0.08 * j), 0.82, -0.08), (s * (0.28 + 0.11 * j), 0.74, -0.5), 0.025, 8)
b[amber()].box(T((s * 0.34, 0.69, 0.06)) @ RY(14 * s), (0.3, 0.03, 0.05)) # the eyes
for s in (-1, 1): # the gorget: a plate rising to each shoulder
k.hull([(s * 1.1, 1.05, -0.46), (s * 2.3, 0.8, 0.1), (s * 2.3, -0.7, 0.3), (s * 1.16, -0.7, 0.1), (s * 1.08, 0.3, -0.2),
(s * 1.1, 1.05, -1.1), (s * 2.3, 0.8, -1.1), (s * 2.3, -0.7, -1.1), (s * 1.16, -0.7, -1.1)])
k.hull([(1.1, 1.05, -0.5), (0.7, 1.42, -0.62), (1.1, 1.05, -1.2), (0.7, 1.5, -1.2), (1.1, 0.6, -0.5)], mirror=True) # the front plate
hatch = F((0, 1.455, -0.86), (0, 1, 0.14), (0, 0, 1))
k.prism(hatch, M.rect(0.44, 0.38, 0.03), 0.035, 0.012)
d.box(hatch @ T((0, 0.09, 0.04)), (0.26, 0.07, 0.03))
k.prism(hatch @ T((0, -0.03, 0.035)), M.rect(0.32, 0.15, 0.02), 0.02, 0.008)
"""COCKPIT / SENSOR CLUSTER, as the inset frames it: the chest's cowl and the face in its recess, without the
breast below (chest(b, torso=False))."""
chest(b, torso=False)
def battery(b):
@ -312,39 +288,83 @@ def block_sheet(front, back):
*({"point": [i, j], "weight": 1.0} for i in (1, 2) for j in (1, 2))]} # a closed loop of creases rounds into a disc unless its corners are pinned
def chest(b):
"""CHEST PLATES. Origin at the middle of the chest; the plates' lower edge is z = -0.7. One breast shell,
mirrored, its rings placed by fit.wrap from the crop's traced outline and a side outline (concepts.json
"outlines"): a flat centre panel between two creases, a pectoral facet each side, a flank, a brow line where
the upper facets lean back to the collar. Every facet is planar and 0.4 m or more across, so the wall is 0.14 m.
Cut into it: two slots in the upper facet, a break under the number, a seam and a ring mark on the right
pectoral. On the mech's left a boxed pectoral block standing proud, a shell of its own with a recessed panel.
A row of five vent teeth under the front edge; a sternum block hung below; under that the dark
abdomen column with three stacked lames and a ribbed hose each side."""
LINES = {} # per component, the flow lines it carries as built: {line: [[x, y, z], ...]} in the component's frame (part_bench and seraph.py project them)
def chest(b, torso=True):
"""CHEST AND HEAD, one hunched shell. Origin 0.09 m above the shoulders' axis, on the centre plane; the breast's
lower edge is z = -0.7, the cowl's crown z = 1.78. One brokkr_kitbash.shell, mirrored: rings from the sternum up
the breast's front (placed by fit.wrap from the crop's traced outline), back up the upper slope to the rim of the
cockpit's recess, across a shelf, up the cowl's face, which overhangs it, and over a low dome to the back of the
head. The centre panel's two creases run the whole way, sternum to crown, and stand on the operator's two chest
lines (fit.band, images/33.webp): LINES["chest"] holds them as built. Every facet is planar. Cut into it: the
cockpit's slit through the cowl's face, a hatch on the upper slope, a break under the number, a ring mark. In
the slit a dark face with two slanted amber eyes. Either side a collar plate rising to the shoulder with a
sensor box on it (objects of their own: the crop's traced mask is the shell). On the mech's left a boxed
pectoral block standing proud; five vent teeth under the front edge; a sternum block; the dark abdomen column
with three lames and a ribbed hose each side. `torso` False: the cowl, shelf and face alone (the cockpit inset)."""
k, d = b["khaki"], b["gunmetal"]
front, side, az, el = fit.load("seraph", "chest.breast")
rings = fit.wrap(front, side, az, el, [(-0.7, 1.25, -0.4), (-0.1, 1.1), 0.32, (0.95, 0.85, 0.88)], flat=0.42, chamfer=0.3, flare=0.06)
breast = {"mirror": True, "flip": True, "rings": rings, "creases": fit.creased(rings)}
rings = fit.wrap(front, side, az, el, [(-0.7, 1.25, -0.4), (-0.3, 1.15), 0.1, 0.45, (0.75, 0.94), (0.95, 0.8, 0.88)], flat=0.42, chamfer=0.3, flare=0.06)
if not torso:
rings = rings[4:]
# the cowl: (z, the centre's y, the corner's x and y, the side's rear x and y)
for z, yc, cx, cy, fx, fy in ((1.2, 0.47, 0.7, 0.47, 0.84, -0.4), (1.6, 0.1, 0.56, 0.02, 0.7, -0.5), (1.76, -0.4, 0.46, -0.45, 0.58, -0.75), (1.68, -0.95, 0.44, -0.98, 0.57, -1.05)):
rings.append([[0.0, yc, z], [0.3, yc, z], [cx, cy, z], [fx, fy, z]])
half = fit.band("seraph", "chest_r", "chest_l", "chest.breast")
v = [fit.seen(ring[0], az, el)[1] for ring in rings]
crown = max(range(len(v)), key=lambda i: v[i])
for i, ring in enumerate(rings): # the crease column stands on the two lines, which run from 0.2 to 0.92 of the shell's height in the view; the panel stands 0.07 m proud of the facet beside it
t = (v[min(i, crown)] - v[0]) / (v[crown] - v[0]) if torso else 0.6 + 0.4 * min(i, crown) / max(crown, 1)
ring[1][0] = half((t - 0.2) / 0.72)
out = Vector(ring[2]) - Vector(ring[1])
proud = 0.09 * min(1.0, (len(rings) - 5 - i) / 2) # the panel's step dies out at the recess's rim
ring.insert(2, list(Vector(ring[1]) + out.normalized() * 0.14 + Vector((0, -proud, 0)) if proud > 0 else Vector(ring[1]) + out * (0.3 if proud == 0 else 0.5)))
LINES[b.name.lower() if b.name.lower() in ("chest", "cockpit") else "chest"] = {"chest_r": [list(r[1]) for r in rings[:-2]], "chest_l": [[-r[1][0], r[1][1], r[1][2]] for r in rings[:-2]]}
import os
if os.environ.get("MECH_RINGS"):
lo, hi = (int(q) for q in os.environ["MECH_RINGS"].split(":"))
rings = rings[lo:hi]
if os.environ.get("MECH_NOSTEP"):
rings = [r[:2] + r[3:] for r in rings]
shell = {"mirror": True, "flip": True, "rings": rings, "creases": fit.creased(rings, skip_rings=tuple(len(rings) - int(q) for q in os.environ.get('MECH_SKIP', '2').split(',')))} # the shelf and the crown are left round: a hard ring there folds the wall
name = b.name + ".breast"
M.shell_action(name, breast, b, "khaki", thickness=0.14, levels=1, bevel=0.014)
import os
M.shell_action(name, shell, b, "khaki", thickness=float(os.environ.get("MECH_T", 0.07)), levels=1, bevel=0.014)
cuts = [{"name": name + ".slit", "part": "box", "params": "width=1.04; height=0.16; depth=0.05", "origin": [0, 3, 1.08], "direction": [0, -1, 0]}] # a recess in the cowl's face; the visor stands in it
if torso:
cuts += [{"name": name + ".hatch", "part": "box", "params": "width=0.3; height=0.22; depth=0.03", "origin": [0, 3, 0.7], "direction": [0, -1, 0]},
{"name": name + ".break", "part": "slab", "params": "gap=0.025; length=0.36; depth=0.03", "origin": [0, 3, -0.4], "direction": [0, -1, 0], "up": [1, 0, 0]},
{"name": name + ".mark", "part": "cyl", "params": "r=0.075; depth=0.025", "origin": [0.62, 3, 0.05], "direction": [0, -1, 0]}]
import os
cuts = [c for c in cuts if c['name'].split('.')[-1] not in os.environ.get('MECH_NOCUT', '').split(',')]
M.cuts_action(name, cuts) if cuts else None
visor = F((0, 0.5, 1.08), (0, 1, 0.32), (0, 0, 1)) # the dark visor in the recess, two slanted amber eyes on it
d.box(visor @ T((0, 0, -0.03)), (1.0, 0.2, 0.06))
for s in (-1, 1):
b[amber()].box(visor @ T((s * 0.26, 0, 0.0)) @ RZ(-10 * s), (0.3, 0.05, 0.02))
if not torso:
return
collar = b["khaki:collar"]
collar.hull([(0.52, -0.9, 0.7), (0.4, -1.25, 0.7), (0.5, -0.9, 1.62), (0.36, -1.2, 1.5)], mirror=True) # the nape: the cowl is open behind
for s in (-1, 1): # a collar plate rising to each shoulder, a sensor box on it
collar.hull([(s * 0.84, 0.4, 1.02), (s * 1.75, 0.3, 1.18), (s * 1.75, -0.7, 1.26), (s * 0.84, -0.72, 1.12),
(s * 0.84, 0.62, 0.6), (s * 1.9, 0.42, 0.62), (s * 1.9, -0.75, 0.62), (s * 0.84, -0.75, 0.6)])
collar.hull([(s * (1.42 + dx), -0.3 + dy, 1.2 + dz) for dx, dy, dz in ((-0.22, -0.26, -0.15), (0.22, -0.26, -0.15), (-0.22, 0.26, -0.15), (0.22, 0.26, -0.15), (-0.2, -0.24, 0.6), (0.2, -0.24, 0.6), (-0.2, 0.2, 0.55), (0.2, 0.2, 0.55))])
d.box(T((s * 1.42, -0.07, 1.52)), (0.26, 0.06, 0.26))
yf = rings[1][0][1]
upper = {"direction": [0, -1.0, -1.0]}
M.cuts_action(name, [
{"name": name + ".slot_a", "part": "box", "params": "width=0.2; height=0.3; depth=0.03", "origin": [-0.34, 2.9, 2.55], **upper},
{"name": name + ".slot_b", "part": "box", "params": "width=0.2; height=0.3; depth=0.03", "origin": [-0.08, 2.9, 2.55], **upper},
{"name": name + ".break", "part": "slab", "params": "gap=0.025; length=0.7; depth=0.03", "origin": [0, 3, -0.4], "direction": [0, -1, 0], "up": [1, 0, 0]},
{"name": name + ".mark", "part": "cyl", "params": "r=0.075; depth=0.025", "origin": [0.3, 3, 0.05], "direction": [0, -1, 0]},
])
hw = rings[1][1][0]
hw = rings[1][3][0]
block = b.name + ".pectoral" # the left pectoral block
M.shell_action(block, block_sheet([[(-hw - 0.08, yf + 0.16, -0.3), (-hw - 0.7, yf - 0.2, -0.32)], [(-hw - 0.1, yf + 0.1, 0.26), (-hw - 0.7, yf - 0.26, 0.24)]],
[[(-hw, yf - 0.2, -0.42), (-hw - 0.86, yf - 0.7, -0.44)], [(-hw - 0.02, yf - 0.3, 0.38), (-hw - 0.86, yf - 0.8, 0.36)]]), b, "khaki", thickness=0.08, levels=1, bevel=0.012)
y0 = rings[0][0][1]
for j in range(5):
k.box(T((-0.44 + 0.22 * j, yf - 0.1, -0.78)), (0.13, 0.12, 0.14))
d.box(T((0, yf - 0.18, -0.78)), (1.1, 0.1, 0.12))
sternum = lambda x0, y0, z0, x1, y1, z1: {"mirror": True, "flip": True, "rings": [ # noqa: E731 a hung block: a front face and a flank each side
[[0, y1, z1], [x1, y1, z1], [x1, 0.5, z1]], [[0, y0, z0], [x0, y0, z0], [x0, 0.5, z0]]], "creases": [{"column": 1, "from": 0, "to": 1, "weight": 1.0}]}
M.shell_action(b.name + ".sternum", sternum(0.5, yf - 0.1, -0.7, 0.4, yf - 0.2, -1.1), b, "khaki", thickness=0.12, levels=1, bevel=0.012)
k.box(T((-0.44 + 0.22 * j, y0 - 0.1, -0.78)), (0.13, 0.12, 0.14))
d.box(T((0, y0 - 0.18, -0.78)), (1.1, 0.1, 0.12))
sternum = lambda x0, y_0, z0, x1, y1, z1: {"mirror": True, "flip": True, "rings": [ # noqa: E731 a hung block: a front face and a flank each side
[[0, y1, z1], [x1, y1, z1], [x1, 0.5, z1]], [[0, y_0, z0], [x0, y_0, z0], [x0, 0.5, z0]]], "creases": [{"column": 1, "from": 0, "to": 1, "weight": 1.0}]}
w0 = rings[0][1][0]
M.shell_action(b.name + ".sternum", sternum(w0 + 0.2, y0 - 0.1, -0.7, w0 + 0.12, y0 - 0.2, -1.12), b, "khaki", thickness=0.12, levels=1, bevel=0.012) # its edges carry the centre panel's creases on down
d.hull([(0.6, -0.5, -0.4), (0.6, 0.75, -0.4), (0.45, -0.4, -2.3), (0.45, 0.6, -2.3)], mirror=True) # the abdomen column
for j in range(3):
z = -1.36 - 0.3 * j