mech experiments round 7: a per-crop match score, loft rings fitted to traced outlines, Seraph's hip turned across the mech

compare.py scores each traced part: the overlap of its hand-traced mask (concepts.json masks) with the part's
mask at the matched camera (part_bench, or the hero view past its neighbours), at the best common size and shift.
fit.py places a shell's rings from the crop's outline and a side outline (wrap, arch); the pauldron, chest and
thigh are fitted shells of planar facets 0.4 m and more across, with walls of 0.13 to 0.16 m and no folded face.
The hip's drum is the slew ring between a narrow pelvis and the thigh; the thigh plate straddles the hip axis.
The hero camera's eye is the concept's horizon (2.4 m); hero-view crops are benched from its direction.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 15:28:56 +01:00
commit 0681b6e6d3
7 changed files with 1577 additions and 154 deletions

View file

@ -13,8 +13,23 @@ with `quick`). Writes, under MECH_OUT/compare/:
<name>_proportions.png the concept's rear and hero views with their marked skeleton (concepts.json) drawn on,
each beside the build's same view with its own joints projected on (<name>_skeleton.json,
from mechlib.field_views), and skeleton.table() of each pair: joint heights, spans and
segment lengths in figure heights"""
segment lengths in figure heights
<name>_match.png per scored part (concepts.json "masks"): the crop with its hand-traced mask drawn on | that
part built alone at the matched camera | the two masks over each other (concept red, ours
blue), with the match score; the scores go to <name>_scores.json, and a
<name>_scores_before.json beside it is printed next to them
<name>_hip.png the concept's hero-view hips beside the same region of our hero render
The match score of a part is the overlap (intersection over union) of two masks: the part's outline traced by hand on
the concept crop, and the same part of the build rendered as a mask at the camera matched to that crop (part_bench.py's
<part>_mask.png: the hero camera's direction onto the part for a crop of the hero view, the inset's own side for an
inset; or, for a "hero" source, mechlib.field_views' <name>_vis_<part>.png, what the hero view shows of the part past
its neighbours). The two are laid over each other at the best of one size and one shift (best_overlap): the score
judges shape, turn and proportion at that camera, not where the part stands in the frame or how far the camera was.
A part whose crop it fills, or that runs off its crop, has no outline to trace and no score ("unscored").
MECH_MATCH_ONLY: only the match sheet and scores, from what part_bench.py has rendered."""
import json, os, sys
import numpy as np
import skeleton
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
@ -108,7 +123,137 @@ def overlay(a, b, h, pad=30):
return both, inter / max(union, 1), a.width / a.height, b.width / b.height
def best_overlap(a, b, n=220):
"""Two masks (L images) at their best common size and place: a is set to n px on its longer side, b resized over
0.7 to 1.4 of the size that gives it a's area and shifted about a's centre of area. Returns (overlap, a's canvas,
b's canvas at the best fit) as arrays of bool. A coarse grid, then a fine one about its best."""
a, b = trimmed(a), trimmed(b)
k = n / max(a.size)
a = np.asarray(a.resize((max(1, round(a.width * k)), max(1, round(a.height * k))), Image.LANCZOS)) > 127
pad = n
A = np.zeros((a.shape[0] + 2 * pad, a.shape[1] + 2 * pad), bool)
A[pad:pad + a.shape[0], pad:pad + a.shape[1]] = a
ys, xs = np.nonzero(A)
cy, cx, area = ys.mean(), xs.mean(), len(ys)
b_area = (np.asarray(b) > 127).sum()
base = (area / max(b_area, 1)) ** 0.5
def placed(scale, dx, dy):
w, h = max(1, round(b.width * base * scale)), max(1, round(b.height * base * scale))
m = np.asarray(b.resize((w, h), Image.LANCZOS)) > 127
my, mx = np.nonzero(m)
y0, x0 = round(cy - my.mean() + dy), round(cx - mx.mean() + dx)
B = np.zeros_like(A)
ya, xa = max(y0, 0), max(x0, 0)
yb, xb = min(y0 + h, B.shape[0]), min(x0 + w, B.shape[1])
if ya < yb and xa < xb:
B[ya:yb, xa:xb] = m[ya - y0:yb - y0, xa - x0:xb - x0]
return B
def score(B):
return (A & B).sum() / max((A | B).sum(), 1)
best = (-1.0, 1.0, 0, 0)
for scale in np.arange(0.7, 1.41, 0.05):
for dx in range(-40, 41, 8):
for dy in range(-40, 41, 8):
best = max(best, (score(placed(scale, dx, dy)), scale, dx, dy))
_, s0, x0, y0 = best
for scale in np.arange(s0 - 0.04, s0 + 0.041, 0.02):
for dx in range(x0 - 6, x0 + 7, 2):
for dy in range(y0 - 6, y0 + 7, 2):
best = max(best, (score(placed(scale, dx, dy)), scale, dx, dy))
B = placed(*best[1:])
return float(best[0]), A, B
def traced(polygons, box, kk, zoom=4):
"""Polygons in sheet units as a mask of the crop `box`, `zoom` times the sheet's pixels."""
x0, y0, x1, y1 = box
m = Image.new("L", (int((x1 - x0) * kk * zoom), int((y1 - y0) * kk * zoom)), 0)
for poly in polygons:
ImageDraw.Draw(m).polygon([((x - x0) * kk * zoom, (y - y0) * kk * zoom) for x, y in poly], fill=255)
return m
def two_masks(A, B, h):
"""best_overlap's canvases as a picture: concept only red, ours only blue, both dark, cut to what is drawn."""
rgb = np.full(A.shape + (3,), 255, np.uint8)
rgb[A & ~B], rgb[B & ~A], rgb[A & B] = (230, 60, 60), (60, 90, 230), (50, 50, 50)
ys, xs = np.nonzero(A | B)
img = Image.fromarray(rgb).crop((xs.min() - 8, ys.min() - 8, xs.max() + 8, ys.max() + 8))
return fit(img, h)
def match_sheet(hero):
"""The match score of every traced part whose mask the build has rendered, the <name>_match sheet, and (given
the hero render) the hip sheet."""
if "masks" not in spec:
return
mk = spec["masks"]
km = sheet.width / mk["unit"]
before_path = dst / f"{name}_scores_before.json"
before = json.loads(before_path.read_text(encoding="utf-8")) if before_path.exists() else {}
scores, cells = {}, []
sil_path = src / f"{name}_sil_hero.png"
sil = Image.open(sil_path).split()[-1] if sil_path.exists() else None
figure_px = sil.getbbox()[3] - sil.getbbox()[1] if sil else 0 # our figure's height in the hero mask's pixels
concept_px = (spec["skeleton"]["views"]["hero"]["ground"] - spec["skeleton"]["views"]["hero"]["top"]) * sheet.width / spec["skeleton"]["unit"]
for tag, part in mk["parts"].items():
path = src / "parts" / f"{tag}_mask.png" if part["source"] == "bench" else src / f"{name}_vis_{tag}.png"
if not path.exists():
continue
ours_mask = Image.open(path).split()[-1].point(lambda v: 255 if v > 96 else 0)
if not ours_mask.getbbox():
print(f"MATCH {name} {tag}: our mask is empty")
continue
concept_mask = traced(part["polygons"], part["crop"], km)
iou, A, B = best_overlap(concept_mask, ours_mask)
scores[tag] = {"overlap": round(iou, 3)}
text = f"overlap {iou:.2f}"
if part["source"] == "hero": # how much of the figure the part shows: area over figure height squared
shown_c = (np.asarray(concept_mask) > 127).sum() / (4 * 4) / concept_px ** 2
shown_o = (np.asarray(ours_mask) > 127).sum() / (figure_px * ours_mask.height / sil.height) ** 2
scores[tag].update(shown_concept=round(float(shown_c), 4), shown_ours=round(float(shown_o), 4))
text += f"; shown {shown_c:.4f} vs ours {shown_o:.4f} H2"
if tag in before:
text += f" (before {before[tag]['overlap']:.2f}" + (f", shown {before[tag]['shown_ours']:.4f}" if "shown_ours" in before[tag] else "") + ")"
print(f"MATCH {name} {tag}: {text}")
shown = sheet.crop(tuple(int(v * km) for v in part["crop"])).resize(concept_mask.size, Image.LANCZOS)
for poly in part["polygons"]:
ImageDraw.Draw(shown).line([((x - part["crop"][0]) * km * 4, (y - part["crop"][1]) * km * 4) for x, y in poly + poly[:1]], fill=(255, 40, 40), width=3)
render = src / "parts" / f"{tag}.png"
ours_img = Image.open(render) if part["source"] == "bench" and render.exists() else Image.merge("RGB", (ours_mask.point(lambda v: 255 - v),) * 3).crop(ours_mask.getbbox())
cells.append(row([label(fit(shown, 520), f"concept: {part.get('label', tag)}, traced"), label(fit(ours_img, 520), "ours: " + tag), label(two_masks(A, B, 520), text)], 520))
if cells:
(dst / f"{name}_scores.json").write_text(json.dumps(scores, indent=1), encoding="utf-8")
half = (len(cells) + 1) // 2
cols = [stack(cells[:half]), stack(cells[half:])] if len(cells) > 3 else [stack(cells)]
canvas = Image.new("RGB", (sum(c.width for c in cols) + 8 * (len(cols) - 1), max(c.height for c in cols)), (24, 24, 24))
x = 0
for c in cols:
canvas.paste(c, (x, 0))
x += c.width + 8
canvas.save(dst / f"{name}_match.png")
canvas.resize((2400, max(1, round(canvas.height * 2400 / canvas.width))), Image.LANCZOS).save(dst / f"{name}_match_small.jpg", quality=88)
sk_file = src / f"{name}_skeleton.json"
if hero is not None and "hip_exposed" in mk["parts"] and sk_file.exists(): # the hips: the concept's hero view beside the same region of ours
box = mk["parts"]["hip_exposed"]["crop"]
cj = spec["skeleton"]["views"]["hero"]["joints"]
ku = sheet.width / spec["skeleton"]["unit"]
cc = ((cj["hip_l"][0] + cj["hip_r"][0]) / 2 * ku, (cj["hip_l"][1] + cj["hip_r"][1]) / 2 * ku)
ov = json.loads(sk_file.read_text(encoding="utf-8"))["views"]["hero"]
up = hero.width / ov["size"][0]
oc = ((ov["joints"]["hip_l"][0] + ov["joints"]["hip_r"][0]) / 2 * up, (ov["joints"]["hip_l"][1] + ov["joints"]["hip_r"][1]) / 2 * up)
zoom = figure_px * up / concept_px
ours_box = tuple(round(oc[i % 2] + (box[i] * km - cc[i % 2]) * zoom) for i in range(4))
sheet_hip = row([label(fit(sheet.crop(tuple(int(v * km) for v in box)), 900), "concept, hero view: the hips"), label(fit(hero.crop(ours_box), 900), "ours, hero view, the same region about the hip axis")], 900)
sheet_hip.save(dst / f"{name}_hip.png")
H = 1100
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)
hero, rear = Image.open(src / f"{stem}_hero.png"), Image.open(src / f"{stem}_hero_rear.png")
row([crop(spec["hero"]), hero, crop(spec["rear"]), rear], H).save(dst / f"{name}_vs_concept.png")
@ -131,6 +276,8 @@ if "icon" in spec:
print(f"SILHOUETTE {name} front icon: overlap {iou:.3f}, width/height concept {ar_c:.3f} ours {ar_o:.3f}")
row(panels, H).save(dst / f"{name}_silhouette.png")
match_sheet(hero)
rows = []
for tag, box in spec["joints"].items():
path = src / f"{stem}_joint_{tag}.png"

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,169 @@
"""Loft rings placed from traced outlines, for brokkr_kitbash.shell sheets. Plain Python; no Blender, no Pillow.
A plate's two outlines live in concepts.json[<mech>]["outlines"][<plate>]:
"front" the plate's outline traced on the concept sheet, in the sheet's pixels at "unit" width
"origin" the pixel where the plate's own origin stands in that crop
"view" [azimuth, elevation] of the crop's camera in the plate's frame, degrees, as part_bench's VIEWS give them
(azimuth positive: the camera stands round to the mech's left; elevation negative: it looks up)
"side" the plate's outline from its side, [[y, z], ...] in metres in the plate's frame. No sheet draws a side
view: it is read off the three-quarter and rear views, and says so here. It carries the depth the front
outline cannot.
Pixels become metres by the figure's height in the hero view (concepts.json "skeleton"): one scale for the sheet.
A view point (u to the image's right, v up, metres from the origin) and a depth y give back a point of the plate:
back(). Two fitters use it:
wrap() a plate round the front of a limb or a trunk: a ring per height; the outline's width there, less what of
the flank the camera's azimuth shows, is the plate's width; the side outline gives its front and its back
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
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
"""
import json
import math
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
def _cuts(polygon, axis, at):
"""Where a closed polygon crosses the line (coordinate `axis` = at): the other coordinate at each crossing, sorted."""
out = []
for p, q in zip(polygon, polygon[1:] + polygon[:1]):
a, b = p[axis], q[axis]
if (a - at) * (b - at) < 0 or (a == at and b != at):
t = (at - a) / (b - a)
out.append(p[1 - axis] + t * (q[1 - axis] - p[1 - axis]))
return sorted(out)
class Outline:
"""A closed polygon in two coordinates (u, v): its extent across a line, clamped to its own bounds so a station
a hair past an end still reads the end."""
def __init__(self, points):
self.points = [tuple(p) for p in points]
self.lo = (min(p[0] for p in points), min(p[1] for p in points))
self.hi = (max(p[0] for p in points), max(p[1] for p in points))
def span(self, axis, at):
"""(least, greatest) of the other coordinate where coordinate `axis` is `at`."""
eps = 1e-4 * (self.hi[axis] - self.lo[axis])
at = min(max(at, self.lo[axis] + eps), self.hi[axis] - eps)
cuts = _cuts(self.points, axis, at)
return cuts[0], cuts[-1]
def left(self, v):
return self.span(1, v)[0]
def right(self, v):
return self.span(1, v)[1]
def bottom(self, u):
return self.span(0, u)[0]
def top(self, u):
return self.span(0, u)[1]
def load(mech, plate):
"""(front Outline in view metres, side Outline in (y, z) metres, azimuth, elevation) of a plate."""
spec = json.loads((HERE / "concepts.json").read_text(encoding="utf-8"))[mech]
hero = spec["skeleton"]["views"]["hero"]
doc = spec["outlines"]
scale = spec["skeleton"]["height_m"] / (hero["ground"] - hero["top"]) * spec["skeleton"]["unit"] / doc["unit"]
o = doc["plates"][plate]
ox, oy = o["origin"]
front = Outline([((x - ox) * scale, (oy - y) * scale) for x, y in o["front"]])
return front, Outline(o["side"]), o["view"][0], o["view"][1]
def seen(p, az, el):
"""A point of the plate in the view: (u, v)."""
a, e = math.radians(az), math.radians(el)
x, y, z = p
return -x * math.cos(a) - y * math.sin(a), x * math.sin(a) * math.sin(e) - y * math.cos(a) * math.sin(e) + z * math.cos(e)
def back(u, v, y, az, el):
"""The plate's point at depth y that the view shows at (u, v)."""
a, e = math.radians(az), math.radians(el)
x = -(u + y * math.sin(a)) / math.cos(a)
z = (v - x * math.sin(a) * math.sin(e) + y * math.cos(a) * math.sin(e)) / math.cos(e)
return [x, y, z]
def wrap(front, side, az, el, stations, flat=0.55, chamfer=0.25, flare=0.0, least=0.2):
"""Rings for half of a plate that wraps a front, to be mirrored about x = 0: per station z, four points: the
middle, the end of the flat front (`flat` of the half-width), the corner (back by `chamfer` of the depth), the
flank's rear edge (out by `flare`). The half-width is the outline's width at that height as the camera sees it,
less the flank the azimuth shows, halved. A station is a height, or (height, a factor on the fitted width), or
(height, factor, the height to read the outline at): an end ring reads a little inside the outline's end, where
a traced outline still has its width."""
a, e = math.radians(az), math.radians(el)
rings = []
for station in stations:
z, k, read = (tuple(station) + (None,))[:3] if isinstance(station, (tuple, list)) else (station, 1.0, None)
yb, yf = side.span(1, z)
depth = yf - yb
v = -yf * math.cos(a) * math.sin(e) + (z if read is None else read) * math.cos(e)
uL, uR = front.span(1, v)
hw = max(least, k * ((uR - uL) - depth * abs(math.sin(a))) / (2 * math.cos(a)))
rings.append([[0.0, yf, z], [flat * hw, yf, z], [hw, yf - chamfer * depth, z], [hw + flare, yb, z]])
return rings
def arch(front, side, az, el, columns, stations, y_section=0.0, plan=None):
"""Rings for a cap, one per station y (fore to aft or aft to fore, as given). `columns` name the section's
points on the front outline, inboard to outboard and down: ("top", u) the outline's upper edge at u, ("out", v)
its outboard edge at height v, ("in", v) its inboard edge, or ("at", u, v) a point of the view. The section
stands at y_section; at each station it is carried between the side outline's bottom and top there, and its
widths taken by plan[k] (default 1)."""
outboard_right = seen((-1, 0, 0), az, el)[0] > 0
section = []
for column in columns:
kind = column[0]
if kind == "top":
u, v = column[1], front.top(column[1])
elif kind == "at":
u, v = column[1], column[2]
else:
v = column[1]
u = front.right(v) if (kind == "out") == outboard_right else front.left(v)
section.append(back(u, v, y_section, az, el))
z_lo, z_hi = min(p[2] for p in section), max(p[2] for p in section)
s_lo, s_hi = side.span(0, y_section)
rings = []
for k, y in enumerate(stations):
lo, hi = side.span(0, y)
lo, hi = z_lo + (lo - s_lo), z_hi + (hi - s_hi) # the side outline moves the section's foot and its crown
sx = plan[k] if plan else 1.0
rings.append([[p[0] * sx, y, lo + (p[2] - z_lo) * (hi - lo) / (z_hi - z_lo)] for p in section])
return rings
def creased(rings, soft_rim=0.5, hard=1.0, skip_columns=(), skip_rings=()):
"""Crease runs that make every facet of a loft planar: each inner ring and each inner column a hard edge, the
run of a column between the last two rings at either end softer (`soft_rim`), since a hard crease beside the rim
is where a thick wall folds first."""
n, m = len(rings), len(rings[0])
runs = [{"ring": i, "from": 0, "to": m - 1, "weight": hard} for i in range(1, n - 1) if i not in skip_rings]
for j in range(1, m - 1):
if j in skip_columns:
continue
if n > 3 and soft_rim != hard:
runs += [{"column": j, "from": 0, "to": 1, "weight": soft_rim}, {"column": j, "from": 1, "to": n - 2, "weight": hard}, {"column": j, "from": n - 2, "to": n - 1, "weight": soft_rim}]
else:
runs.append({"column": j, "from": 0, "to": n - 1, "weight": hard})
return runs
if __name__ == "__main__":
front, side, az, el = load(sys.argv[1], sys.argv[2])
print(f"{sys.argv[2]}: view az {az} el {el}; front u {front.lo[0]:.2f} to {front.hi[0]:.2f}, v {front.lo[1]:.2f} to {front.hi[1]:.2f}; side y {side.lo[0]:.2f} to {side.hi[0]:.2f}, z {side.lo[1]:.2f} to {side.hi[1]:.2f}")
for k in range(10):
v = front.lo[1] + (k + 0.5) * (front.hi[1] - front.lo[1]) / 10
print(f" v {v:6.2f}: u {front.left(v):6.2f} to {front.right(v):6.2f}, width {front.right(v) - front.left(v):.2f}")

View file

@ -1901,6 +1901,24 @@ def silhouette(rig, cam, radius, azimuth, elevation, path, size, margin=0.95, le
o.hide_render = False
def part_mask(rig, cam, radius, azimuth, elevation, path, size, keep, occluded=False, **view):
"""silhouette() of some objects only: `keep` is a test on an object's name. With `occluded` the others stay in
the view as holdouts, so the mask is what of the part the view shows past its neighbours; without, they are
hidden and the mask is the part's whole outline. compare.py scores it against the crop's traced mask."""
meshes = [o for o in bpy.context.scene.objects if o.type == "MESH" and not o.get("stage") and not o.hide_render]
others = [o for o in meshes if not keep(o.name)]
if len(others) == len(meshes):
raise SystemExit(f"part_mask {path}: no object is kept")
for o in others:
if occluded:
o.is_holdout = True
else:
o.hide_render = True
silhouette(rig, cam, radius, azimuth, elevation, path, size, **view)
for o in others:
o.is_holdout, o.hide_render = False, False
def closeup(rig, cam, target, span, azimuth, elevation, path, size=(1000, 1000), lens=70.0):
"""shot() at one place: the rig moved to a world point, the frame fitted to a sphere of radius `span` round it."""
keep = rig.location.copy()
@ -1920,13 +1938,15 @@ def project(cam, points, size):
return out
def field_views(name, t0, hero=(30.0, 3.0), rear=(180.0, 6.0), hero_size=(2000, 2400), samples=96, turns=(), closeups=(), joints=None, hero_cam=None, rear_cam=None):
def field_views(name, t0, hero=(30.0, 3.0), rear=(180.0, 6.0), hero_size=(2000, 2400), samples=96, turns=(), closeups=(), joints=None, hero_cam=None, rear_cam=None, masks=None):
"""The finale. Under MECH_QUICK: hero and rear at 24 samples and 1000 px. Else the .blend, hero and rear
at `samples`, and any `turns` azimuths. `closeups` are (tag, object, point in its frame, span, azimuth,
elevation): joint close-ups, <name>_joint_<tag>.png. Always: silhouette masks of the hero, rear and straight-front views
(<name>_sil_hero.png, _sil_rear.png, _sil_front.png), for compare.py. `hero_cam` and `rear_cam` are shot()'s
lens, eye and margin for those views. `joints` (joint_points()) are written, projected into the hero and rear masks' pixels, to
<name>_skeleton.json for the proportions sheet."""
<name>_skeleton.json for the proportions sheet. `masks` is {tag: a test on an object's name}: part_mask() of those
objects in the hero view, at the hero render's size, occluded by the rest.
MECH_SKELETON_ONLY stops after the masks; MECH_HERO_ONLY after the hero render."""
quick = os.environ.get("MECH_QUICK")
out = Path(os.environ["MECH_OUT"]) / name
assert out.is_absolute()
@ -1943,12 +1963,16 @@ def field_views(name, t0, hero=(30.0, 3.0), rear=(180.0, 6.0), hero_size=(2000,
views[tag] = {"size": [1000, 1200], "joints": project(cam, joints, (1000, 1200))}
if joints:
(out / f"{name}_skeleton.json").write_text(json.dumps({"views": views, "world": {k: [round(c, 3) for c in v] for k, v in joints.items()}}, indent=1), encoding="utf-8")
for tag, keep in (masks or {}).items(): # what the hero view shows of a part, past its neighbours: <name>_vis_<tag>.png
part_mask(rig, cam, radius, hero[0], hero[1], out / f"{name}_vis_{tag}.png", size, keep, occluded=True, **cams["hero"])
if os.environ.get("MECH_SKELETON_ONLY"):
return
if not quick:
bpy.ops.wm.save_as_mainfile(filepath=str(out / f"{name}.blend"))
stem = "q" if quick else name
shot(rig, cam, radius, hero[0], hero[1], out / f"{stem}_hero.png", size, **cams["hero"])
if os.environ.get("MECH_HERO_ONLY"):
return
shot(rig, cam, radius, rear[0], rear[1], out / f"{stem}_hero_rear.png", size, **cams["rear"])
update()
for tag, obj, local, span, az, el in closeups:

View file

@ -1,6 +1,8 @@
"""Builds components alone and renders each from its concept inset's side.
MECH_PARTS: comma-separated names from <MECH_SET>_parts.PARTS (default all); MECH_SET: the mech (default seraph).
Writes MECH_OUT/<mech>/parts/<name>.png, 800 px, for compare.py's components sheet."""
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
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
@ -19,6 +21,7 @@ for name in names:
t0 = time.time()
for obj in list(bpy.data.objects):
bpy.data.objects.remove(obj, do_unlink=True)
M.FOLDED.clear()
az, el, margin, pitch = lib.VIEWS[name]
host = bpy.data.objects.new("Bench", None)
bpy.context.scene.collection.objects.link(host)
@ -28,7 +31,16 @@ for name in names:
build.done()
M.update()
rig, cam, centre, radius = M.stage_field(int(os.environ.get("MECH_SAMPLES", "32")))
M.shot(rig, cam, radius, az, el, out / f"{name}.png", (800, 800), margin=margin, lens=85.0)
lens = getattr(lib, "LENS", {}).get(name, 85.0)
if name in getattr(lib, "MASKS", {}): # the scored outline: the armor the crop's mask traces, alone, at the same camera
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)
if os.environ.get("MECH_FOLDS"):
try:
M.shells_sound()
except SystemExit as stop:
print("UNSOUND", name, stop)
if name in getattr(lib, "FRAMES", {}): # a second view, from underneath: the frame the plate stands on
faz, fel, fmargin, hidden = lib.FRAMES[name]
for other in hidden:

View file

@ -1,4 +1,4 @@
"""SERAPH, round 5: the operator's concept sheet (images/30.webp) assembled from its components on its skeleton.
"""SERAPH, round 7: the operator's concept sheet (images/30.webp) assembled from its components on its skeleton.
Each component is built to its inset or region of the sheet in seraph_parts.py and checked alone by part_bench.py
(compare.py's components sheet sets each beside its crop); this file lays the biped on the solved skeleton and seats
the components on it. What is not a matched component is said so where it is built."""
@ -18,7 +18,7 @@ UP, DOWN, FRONT, BACK = (0, 0, 1), (0, 0, -1), (0, 1, 0), (0, -1, 0)
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.2, 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",
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,
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),
@ -47,20 +47,21 @@ 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
for side, sx in (("L", -1), ("R", 1)):
put(f"Pauldron{side}", SP.pauldron, core, T((sx * (sh_x + 0.15), 0.0, sh_z - 0.25)) @ (MIR if sx > 0 else Matrix.Identity(4)), arm=False)
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))
# --- pelvis: the hip bearings facing forward under their lames. The dark hull and the codpiece are not matched components -
# --- pelvis: the hip bearings on its sides, their axis across the mech, under their lames; the thigh plates stand in
# front of them (below). The dark hull and the codpiece are not matched components ---------------------------------------
leg_x = 0.5 * CFG["pelvis"]["span"] + CFG["hip_h"] + 0.5 * LINKS[0][1]
ph = M.Plates("Pelvis.hull", pel, mat="gunmetal", thickness=0.05, chamfer=0.03, standoff=0.0, bolt_r=0.02)
ph.block(F((0, 0, -1.25), UP, FRONT), (0.8, 1.1), 1.9, corner=0.2, top=(1.5, 1.1))
ph.block(F((0, 0, -1.25), UP, FRONT), (0.6, 1.1), 1.9, corner=0.2, top=(1.2, 1.1))
ph.finish()
cod = M.Shields("Codpiece", pel, mat=P, t=0.09, crown=0.07, standoff=0.1)
cod.plate(F((0, 0.78, -0.45), (0, 1, -0.2), UP), 1.7, [(0, 0.26), (0.1, 0.45), (0.55, 0.62), (0.9, 0.54), (1, 0.36)], bend=1.6, ridge=0.08)
cod.plate(F((0, -0.7, -0.3), (0, -1, -0.15), UP), 1.4, [(0, 0.26), (0.1, 0.45), (0.55, 0.6), (0.9, 0.52), (1, 0.36)], bend=1.6)
cod.plate(F((0, 0.78, -0.45), (0, 1, -0.2), UP), 1.7, [(0, 0.2), (0.1, 0.32), (0.55, 0.42), (0.9, 0.38), (1, 0.26)], bend=1.6, ridge=0.08) # 0.8 m across, as the hero view has it: the hip drums show beside it
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 * (leg_x - 0.25), 0.62, 0.0)) @ (Matrix.Identity(4) if sx > 0 else MIR) @ Matrix.Scale(0.8, 4), shield=False)
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
# --- 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():
@ -79,7 +80,8 @@ for side, leg in legs.items():
sx = -1 if side == "L" else 1
thigh, shin = leg["links"]
(L, w, d), (L2, w2, d2) = LINKS
put(f"Thigh{side}", SP.thigh, thigh, M.seat(thigh, (0, 0.0, 0.5 * L + 0.1), outboard=-1, side=sx, scale=0.92))
out = M.local_dir(thigh, (sx, 0, 0)) * 0.2 # and stands outboard, its inner edge at the bearing: the drum shows between it and the codpiece
put(f"Thigh{side}", SP.thigh, thigh, M.seat(thigh, (out.x, out.y, 0.12), outboard=-1, side=sx)) # the plate straddles the hip axis, as the hero view has it: 0.9 m of it stands above
put(f"Knee{side}", SP.knee, thigh, M.seat(thigh, (0, 0, L), outboard=-1, side=sx), full=False)
put(f"Shin{side}", SP.shin, shin, M.seat(shin, (0, 0.0, 0.5 * L2 + 0.12), scale=0.92))
foot = leg["foot"]
@ -100,4 +102,5 @@ lo, hi = M.bounds()
print("HEIGHT", round(hi.z - lo.z, 2), "WIDTH", round(hi.x - lo.x, 2), "RAMS", {k: len(v["rams"]) for k, v in legs.items()})
M.report_skeleton("seraph", body)
M.field_views("seraph", t0, hero=(18.0, 3.0), rear=(180.0, 2.0), turns=(90,), samples=64, hero_size=(1600, 1920), joints=M.joint_points(body),
hero_cam=dict(lens=30.0, eye=1.4, margin=0.7), rear_cam=dict(lens=70.0, eye=2.0, margin=0.76))
hero_cam=dict(lens=45.0, eye=2.4, margin=0.72), rear_cam=dict(lens=70.0, eye=2.0, margin=0.76),
masks={"hip_exposed": lambda name: name.startswith("Hip") and name.endswith((".gunmetal", ".machine")) or ".HipSlew" in name})

View file

@ -7,6 +7,7 @@ The pauldron, chest and thigh plates are brokkr_kitbash.shell sheets (M.shell_ac
they are objects on the host, not geometry in the Build."""
import math
from mathutils import Matrix, Vector
import fit
import mechlib as M
F, T = M.frame_at, Matrix.Translation
@ -16,11 +17,19 @@ RZ = lambda deg: Matrix.Rotation(math.radians(deg), 4, "Z")
ALONG_Y = F((0, 0, 0), (0, 1, 0), (0, 0, 1)) # a frame whose z is the host's y: lathes and prisms that run forward
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": (14, 0, 0.7, 0), "knee": (90, 0, 0.8, 0), "foot": (-40, 9, 0.85, 0),
"chest": (18, 3, 0.8, 0), "pauldron": (38, -4, 0.85, 0), "thigh": (18, -5, 0.85, 0), "shin": (18, 0, 0.9, 0)}
GROUND = {"foot": 0.8} # the bench stands these on the ground: the origin's height
"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)}
# 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
# is the inset's own: it gives the part's detail. Where a part stands and what covers it is the full-figure views'.
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")
"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.khaki", "pauldron.gunmetal"))} # (azimuth, elevation, margin, objects hidden): a second bench view, from inboard and below, of the frame a plate stands on
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
def amber():
@ -198,35 +207,32 @@ def cooling(b):
d.box(T((s * 0.2, 0.1, 0.0)), (0.06, 0.4, 3.0))
def hip(b, shield=True):
"""HIP JOINT. Origin at the bearing's centre; its axis is y, toward the front. One ringed bearing (a dark rim, a
bright race, a dished face, a notched hub) in a housing ribbed round its upper half; the thigh's shield laps its
outer side, a big clipped plate with a small plate on its outer edge and a second plate below; over it the
pelvis's lames, three blocks in a row, and the codpiece's edge inboard. Drawn as the left hip: outboard is -x."""
b.to_host = MIRROR # drawn as the left hip; the sheet shows the right
def hip(b, length=0.6):
"""HIP JOINT, the mech's left: outboard is -x; origin at the bearing's centre, midway between the pelvis's side
and the thigh, `length` apart. Its axis is x, across the mech, as the rear and hero views stand it: the inset
turns the bearing's face to its own camera, and gives only what the bearing is made of. A ribbed drum round the
axis: a bolted collar on the pelvis, a dark housing of ring ribs, a bright race at its outboard end where the
thigh turns on it; over it the pelvis's lames, two blocks in a row. The inset's ringed face (rim, race, dished
face, notched hub) is not drawn: no full-figure view shows a face there. In the assembly the thigh's front
plate stands outboard of this and the codpiece inboard: the drum shows between them."""
k, d = b["khaki"], b["gunmetal"]
face = ALONG_Y
d.lathe(face @ T((0, 0, -0.5)), [(0.74, 0), (0.74, 0.42), (0.66, 0.5), (0.5, 0.5)], 48)
ringed_disc(b["gunmetal"], face, 0.56, 0.2)
d.box(T((0.02, 0.22, 0.0)) @ RY(35), (0.05, 0.03, 0.14))
for j in range(11): # the ribbed housing
a = math.radians(-10 + 20 * j)
d.box(RY(-math.degrees(a)) @ T((0.84, -0.22, 0)), (0.3, 0.6, 0.2))
d.lathe(face @ T((0, 0, -0.6)), [(0.9, 0), (0.9, 0.5), (0.6, 0.5)], 40)
if not shield:
return hip_lames(k)
plate = F((-1.25, 0.3, -0.35), (-0.3, 1, 0.05), (0, 0, 1)) # the thigh's shield
k.prism(plate, [(0.9, -1.25), (0.62, 0.3), (0.2, 0.95), (-0.55, 1.05), (-0.9, 0.5), (-0.9, -1.25)][::-1], 0.16, 0.05, 0.94)
k.prism(plate @ T((0.72, 0.5, -0.02)), [(0.26, -0.5), (0.26, 0.2), (0.0, 0.52), (-0.22, 0.4), (-0.22, -0.5)][::-1], 0.26, 0.04, 0.9) # the small plate on its outer edge
k.prism(F((0.15, 0.28, -1.15), (0.25, 1, 0), (0, 0, 1)), [(-0.5, -0.5), (0.4, -0.5), (0.5, 0.3), (0.1, 0.55), (-0.5, 0.2)], 0.14, 0.04, 0.94) # the plate below
hip_lames(k)
def hip_lames(k):
for j, (x, w) in enumerate(((-0.55, 0.6), (0.08, 0.62), (0.7, 0.5))): # the pelvis's lames
k.hull([(x - 0.5 * w, -0.3, 0.92), (x + 0.5 * w, -0.3, 0.92), (x - 0.5 * w, 0.3, 0.86 - 0.04 * j), (x + 0.5 * w, 0.3, 0.86 - 0.04 * j),
(x - 0.5 * w + 0.04, -0.3, 1.3), (x + 0.5 * w - 0.04, -0.3, 1.3), (x - 0.5 * w + 0.04, 0.22, 1.28), (x + 0.5 * w - 0.04, 0.22, 1.28)])
k.hull([(0.95, 0.5, 0.75), (1.4, 0.4, 0.8), (0.95, 0.6, -1.0), (1.3, 0.5, -1.2), (0.95, 0.1, 0.75), (1.4, 0.1, -1.0)]) # the codpiece's edge
axis = F((0.5 * length, 0, 0), (-1, 0, 0), (0, 0, 1)) # a lathe's z runs outboard from the pelvis's side
ribs = max(2, round((length - 0.19) / 0.12))
pitch = (length - 0.19) / ribs
profile, x = [(0.5, 0), (0.64, 0), (0.64, 0.1)], 0.1 # the collar on the pelvis
for j in range(ribs):
profile += [(0.56, x), (0.56, x + 0.42 * pitch), (0.62, x + 0.42 * pitch), (0.62, x + pitch)]
x += pitch
d.lathe(axis, profile + [(0.66, x), (0.66, x + 0.09), (0.5, x + 0.09)], 48)
b["machine"].lathe(axis @ T((0, 0, x + 0.02)), [(0.66, 0), (0.675, 0), (0.675, 0.05), (0.66, 0.05)], 48) # the race, where the thigh turns on it
for j in range(8): # the collar's bolts
a = math.radians(45 * j + 22)
d.cylinder(axis @ T((0.59 * math.cos(a), 0.59 * math.sin(a), 0.1)), 0.035, 0.08, 6)
w = 0.5 * length + 0.1
for j, x0 in enumerate((0.5 * w - 0.05, -0.5 * w - 0.05)): # the pelvis's lames, stepping down outboard
z0 = 0.72 - 0.06 * j
k.hull([(x0 - 0.5 * w + 0.015, -0.45, z0), (x0 + 0.5 * w - 0.015, -0.45, z0), (x0 - 0.5 * w + 0.015, 0.62, z0 - 0.08), (x0 + 0.5 * w - 0.015, 0.62, z0 - 0.08),
(x0 - 0.5 * w + 0.04, -0.45, z0 + 0.3), (x0 + 0.5 * w - 0.04, -0.45, z0 + 0.3), (x0 - 0.5 * w + 0.04, 0.5, z0 + 0.26), (x0 + 0.5 * w - 0.04, 0.5, z0 + 0.26)])
def knee(b, full=True):
@ -307,50 +313,43 @@ def block_sheet(front, back):
def chest(b):
"""CHEST PLATES. Origin at the middle of the chest; the plates' lower edge is z = -0.5. One breast shell,
mirrored: a flat centre panel with clipped lower corners (the number goes on it) between two creases, a pectoral
facet each side turning back to the flank at a second crease, a brow line across where the upper facets lean
back to the collar. 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 two-tier sternum block hung below; under that
the dark abdomen column with three stacked lames and a ribbed hose each side."""
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 two-tier sternum block hung below; under that the dark
abdomen column with three stacked lames and a ribbed hose each side."""
k, d = b["khaki"], b["gunmetal"]
breast = {"mirror": True, "flip": True, "rings": [
[[0, 1.25, -0.5], [0.36, 1.25, -0.5], [1.1, 0.9, -0.47], [1.56, 0.6, -0.45], [1.7, -0.45, -0.45]],
[[0, 1.3, -0.28], [0.5, 1.3, -0.28], [1.14, 0.94, -0.28], [1.6, 0.62, -0.28], [1.72, -0.45, -0.28]],
[[0, 1.3, 0.15], [0.52, 1.3, 0.15], [1.16, 0.95, 0.15], [1.63, 0.62, 0.15], [1.73, -0.45, 0.15]],
[[0, 0.5, 0.92], [0.56, 0.5, 0.92], [1.08, 0.36, 0.9], [1.58, 0.14, 0.82], [1.7, -0.45, 0.82]],
[[0, -0.55, 0.98], [0.58, -0.55, 0.98], [1.1, -0.55, 0.95], [1.6, -0.52, 0.88], [1.72, -0.62, 0.85]]],
"creases": [{"column": 1, "from": 0, "to": 3, "weight": 1.0}, {"column": 3, "from": 0, "to": 3, "weight": 1.0}, {"ring": 2, "from": 0, "to": 4, "weight": 1.0},
{"ring": 3, "from": 0, "to": 4, "weight": 0.8}, {"column": 2, "from": 0, "to": 3, "weight": 0.6}, {"ring": 1, "from": 0, "to": 1, "weight": 0.6}]}
front, side, az, el = fit.load("seraph", "chest.breast")
rings = fit.wrap(front, side, az, el, [(-0.5, 1.5, -0.36), (-0.1, 1.12), 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)}
name = b.name + ".breast"
M.shell_action(name, breast, b, "khaki", thickness=0.026, levels=2, bevel=0.012) # its first face folds at 0.035, and the cuts leave open edges from 0.032
M.shell_action(name, breast, b, "khaki", thickness=0.14, levels=1, bevel=0.014)
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.018", "origin": [-0.34, 2.9, 2.55], **upper},
{"name": name + ".slot_b", "part": "box", "params": "width=0.2; height=0.3; depth=0.018", "origin": [-0.08, 2.9, 2.55], **upper},
{"name": name + ".slot_c", "part": "slot", "params": "width=0.36; height=0.07; depth=0.016", "origin": [0.3, 2.8, 2.45], **upper},
{"name": name + ".break", "part": "slab", "params": "gap=0.022; length=0.84; depth=0.016", "origin": [0, 3, -0.2], "direction": [0, -1, 0], "up": [1, 0, 0]},
{"name": name + ".seam", "part": "slab", "params": "gap=0.02; length=0.74; depth=0.016", "origin": [1.62, 3, -0.02], "direction": [-0.4, -1, 0], "up": [0.3, 0, 1]},
{"name": name + ".mark", "part": "cyl", "params": "r=0.075; depth=0.012", "origin": [2.2, 3, -0.16], "direction": [-0.4, -1, 0]},
{"name": name + ".flank", "part": "slab", "params": "gap=0.02; length=0.7; depth=0.016", "origin": [-3, 0.2, 0.0], "direction": [1, 0, 0], "up": [0, 0, 1]},
{"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.3], "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]
block = b.name + ".pectoral" # the left pectoral block
M.shell_action(block, block_sheet([[(-0.66, 1.62, -0.26), (-1.5, 1.2, -0.3)], [(-0.68, 1.5, 0.5), (-1.5, 1.1, 0.46)]],
[[(-0.6, 1.1, -0.36), (-1.66, 0.56, -0.4)], [(-0.62, 0.9, 0.62), (-1.66, 0.4, 0.56)]]), b, "khaki", thickness=0.08, levels=2, bevel=0.012)
M.cuts_action(block, [{"name": block + ".panel", "part": "box", "params": "width=0.2; height=0.34; depth=0.03", "origin": [-1.28, 3, 0.12], "direction": [0, -1, 0]},
{"name": block + ".line", "part": "slab", "params": "gap=0.02; length=0.5; depth=0.025", "origin": [-0.9, 3, 0.12], "direction": [0, -1, 0], "up": [0, 0, 1]}])
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)
for j in range(5):
k.box(T((-0.44 + 0.22 * j, 1.2, -0.58)), (0.13, 0.12, 0.14))
d.box(T((0, 1.12, -0.58)), (1.1, 0.1, 0.12))
k.box(T((-0.44 + 0.22 * j, yf - 0.1, -0.58)), (0.13, 0.12, 0.14))
d.box(T((0, yf - 0.18, -0.58)), (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.7, z1]], [[0, y0, z0], [x0, y0, z0], [x0, 0.7, z0]]], "creases": [{"column": 1, "from": 0, "to": 1, "weight": 1.0}]}
M.shell_action(b.name + ".sternum", sternum(0.42, 1.22, -0.5, 0.36, 1.16, -0.95), b, "khaki", thickness=0.075, levels=2, bevel=0.012)
M.shell_action(b.name + ".sternum_low", sternum(0.3, 1.12, -0.95, 0.24, 1.04, -1.22), b, "khaki", thickness=0.08, levels=1, bevel=0.012)
[[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.42, yf - 0.08, -0.5, 0.36, yf - 0.14, -0.82), b, "khaki", thickness=0.12, levels=1, bevel=0.012)
M.shell_action(b.name + ".sternum_low", sternum(0.3, yf - 0.18, -0.82, 0.24, yf - 0.26, -1.0), b, "khaki", thickness=0.1, levels=1, bevel=0.012)
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
lame = {"mirror": True, "flip": True, "rings": [[[0, 0.86 - 0.05 * j, z - 0.24], [0.32 - 0.03 * j, 0.86 - 0.05 * j, z - 0.24], [0.32 - 0.03 * j, 0.6, z - 0.26]],
[[0, 0.92 - 0.05 * j, z + 0.02], [0.36 - 0.03 * j, 0.92 - 0.05 * j, z + 0.02], [0.36 - 0.03 * j, 0.6, z]]],
lame = {"mirror": True, "flip": True, "rings": [[[0, 0.86 - 0.05 * j, z - 0.24], [0.32 - 0.03 * j, 0.86 - 0.05 * j, z - 0.24], [0.32 - 0.03 * j, 0.5, z - 0.26]],
[[0, 0.92 - 0.05 * j, z + 0.02], [0.36 - 0.03 * j, 0.92 - 0.05 * j, z + 0.02], [0.36 - 0.03 * j, 0.5, z]]],
"creases": [{"column": 1, "from": 0, "to": 1, "weight": 1.0}]}
M.shell_action(f"{b.name}.lame{j}", lame, b, "khaki", thickness=0.06, levels=1, bevel=0.01)
for s in (-1, 1):
@ -358,101 +357,81 @@ def chest(b):
corrugated(d, [(s * 1.25, 0.5, -0.5), (s * 1.1, 0.62, -1.1), (s * 0.7, 0.5, -1.9)], 0.09)
def pauldron(b, arm=True):
"""SHOULDER PAULDRON, the mech's left: outboard is -x; origin at the shoulder's pivot. One cap shell: a crown
along a fore-and-aft ridge and a steep outer face, two facets of one sheet creased at the shoulder line, a brow
facet fore and aft; its lower edge stepped into tabs by notches cut through the rim; two panel lines and a slot
down the outer face. A raised band over the shoulder line and a ridge plate on the crown, each a small shell. In
front, the emblem's shield: a six-sided plate of its own, bent down its middle, wrapping the front corner. Under
the cap its frame: three ribs with lightening holes and posts. Under that the upper arm."""
k, d = b["khaki"], b["gunmetal"]
across = ((0.55, 1.15), (-0.35, 1.52), (-1.2, 1.15), (-1.55, 0.35), (-1.68, -0.4)) # inboard edge, crown ridge, shoulder line, outer face, lower edge
def ring(y, sx, sz):
return [[x * sx, y, 0.2 + (z - 0.2) * sz] for x, z in across]
fore = [[0.5, 1.12, 0.85], [-0.33, 1.2, 1.1], [-1.1, 1.15, 0.9], [-1.46, 1.08, 0.3], [-1.6, 1.0, -0.32]] # the brow facets: the crown turns down, the outer face turns in
aft = [[0.5, -1.4, 0.8], [-0.33, -1.5, 1.05], [-1.1, -1.45, 0.85], [-1.45, -1.38, 0.3], [-1.58, -1.3, -0.3]]
cap = {"rings": [fore, ring(0.95, 1.0, 0.96), ring(0.3, 1.0, 1.0), ring(-0.4, 1.0, 1.0), ring(-1.05, 1.0, 0.95), aft],
"creases": [{"column": 2, "from": 0, "to": 5, "weight": 1.0}, {"ring": 1, "from": 0, "to": 4, "weight": 1.0}, {"ring": 4, "from": 0, "to": 4, "weight": 0.8},
{"column": 1, "from": 1, "to": 4, "weight": 0.5}, {"column": 3, "from": 1, "to": 3, "weight": 0.4}]}
def pauldron(b, arm=False):
"""SHOULDER PAULDRON, the mech's left: outboard is -x; origin at the shoulder's pivot, which is the cap's inboard
edge. One cap shell, a dome of planar facets: its section (inboard edge, crown, shoulder line, outer face,
lower rim) is the crop's traced outline, and a side outline lowers it to a brow fore and aft (fit.arch). Facets
0.5 m and more across carry a 0.16 m wall. Its lower rim is stepped into a tab by a notch; a panel line and a
slot down the outer face. In front, the emblem's shield: a six-sided plate of its own hung before the shoulder,
its outline the crop's, bent down its middle. Under the cap its frame: three ribs with lightening holes."""
front, side, az, el = fit.load("seraph", "pauldron.cap")
rings = fit.arch(front, side, az, el, [("in", 0.45), ("top", 0.32), ("top", 1.02), ("out", 0.25), ("out", -0.52)], [1.1, 0.7, 0.0, -0.7, -1.1], plan=[0.9, 0.98, 1.0, 0.98, 0.9])
cap = {"rings": rings, "creases": fit.creased(rings)}
name = b.name + ".cap"
M.shell_action(name, cap, b, "khaki", thickness=0.025, levels=2, bevel=0.012) # its first face folds at 0.033, and the cuts leave open edges from 0.0301
side = {"direction": [1, 0, 0], "up": [0, 0, 1]}
M.shell_action(name, cap, b, "khaki", thickness=0.16, levels=1, bevel=0.016)
side_ray = {"direction": [1, 0, 0], "up": [0, 0, 1]}
M.cuts_action(name, [
{"name": name + ".line_a", "part": "slab", "params": "gap=0.024; length=0.95; depth=0.016", "origin": [-3, 0.32, 0.42], **side},
{"name": name + ".line_b", "part": "slab", "params": "gap=0.024; length=0.95; depth=0.016", "origin": [-3, 0.14, 0.42], **side},
{"name": name + ".slot", "part": "box", "params": "width=0.16; height=0.42; depth=0.02", "origin": [-3, 0.66, 0.72], **side},
{"name": name + ".aft", "part": "slab", "params": "gap=0.024; length=1.2; depth=0.016", "origin": [-3, -0.62, 0.3], **side},
{"name": name + ".notch_a", "part": "box", "params": "width=0.34; height=0.3; depth=0.3", "origin": [-3, 0.12, -0.3], **side}, # through the rim: what is left between is a tab
{"name": name + ".notch_b", "part": "box", "params": "width=0.3; height=0.3; depth=0.3", "origin": [-3, -0.78, -0.3], **side},
{"name": name + ".crown", "part": "slab", "params": "gap=0.022; length=1.5; depth=0.016", "origin": [-0.72, -0.1, 3], "direction": [0, 0, -1], "up": [0, 1, 0]},
{"name": name + ".line_a", "part": "slab", "params": "gap=0.03; length=0.8; depth=0.03", "origin": [-4, 0.3, -0.05], **side_ray},
{"name": name + ".slot", "part": "box", "params": "width=0.16; height=0.4; depth=0.05", "origin": [-4, -0.2, 0.1], **side_ray},
{"name": name + ".notch", "part": "box", "params": "width=0.5; height=0.3; depth=0.5", "origin": [-4, 0.28, -0.6], **side_ray}, # through the rim: what is left beside it is a tab
])
M.ribs_action(name, [{"origin": [0, y, 0], "normal": [0, 1, 0]} for y in (0.6, -0.05, -0.7)], standoff=0.03, depth=0.14, thickness=0.03, holes=0.34, posts=0.45, post_r=0.022)
band = [[[-1.11, y, 1.244 * s], [-1.242, y, 1.192 * s], [-1.294, y, 1.06 * s]] for y, s in ((0.92, 0.985), (0.3, 1.0), (-0.4, 1.0), (-1.02, 0.975))]
M.shell_action(b.name + ".band", {"rings": band, "creases": [{"column": 1, "from": 0, "to": 3, "weight": 1.0}]}, b, "khaki", thickness=0.05, levels=2, bevel=0.008)
M.shell_action(b.name + ".ridge", {"flip": True, "rings": [[[0.352, y, 1.307], [-0.143, y, 1.511]] for y in (-0.6, 0.2)]}, b, "khaki", thickness=0.07, levels=1, bevel=0.01)
rows = (((-0.25, -0.6), (0.2, -0.76), (0.62, -0.66)), ((-0.72, -0.3), (0.15, -0.32), (1.0, -0.3)), ((-0.75, 0.35), (0.15, 0.38), (1.05, 0.42)), ((-0.5, 0.62), (0.15, 0.74), (0.82, 0.84)))
shield = {"rings": [[[-0.45 - u, 1.4 - 0.1 * v + (0.07, 0.14, -0.3)[j], 0.3 + v] for j, (u, v) in enumerate(row)] for row in rows], # u runs outboard, v up
"creases": [{"column": 1, "from": 0, "to": 3, "weight": 0.9}, {"ring": 1, "from": 0, "to": 2, "weight": 0.5}, {"ring": 2, "from": 0, "to": 2, "weight": 0.5}]}
M.ribs_action(name, [{"origin": [0, y, 0], "normal": [0, 1, 0]} for y in (0.45, -0.05, -0.55)], standoff=0.03, depth=0.14, thickness=0.03, holes=0.34, posts=0.45, post_r=0.022)
front, side, az, el = fit.load("seraph", "pauldron.shield")
y0 = 1.2
at = lambda px, py, dy=0.0: fit.back((px - 500) * front_scale, (120 - py) * front_scale, y0 + dy, az, el) # noqa: E731 a pixel of the crop, at the shield's depth
front_scale = 9.8 / 758
rows = [[(500, 155), (530, 171), (563, 163)], [(492, 135), (532, 137), (568, 138)], [(490, 112), (528, 112), (556, 112)], [(500, 90), (524, 90), (545, 90)]]
shield = {"rings": [[at(px, py, (0.0, 0.07, -0.12)[j]) for j, (px, py) in enumerate(row)] for row in rows],
"creases": [{"column": 1, "from": 0, "to": 3, "weight": 0.9}]}
plate = b.name + ".shield"
M.shell_action(plate, shield, b, "khaki", thickness=0.08, levels=3, bevel=0.012)
M.cuts_action(plate, [{"name": plate + ".bracket", "part": "slot", "params": "width=0.3; height=0.06; depth=0.03", "origin": [-0.62, 3, -0.2], "direction": [0, -1, 0]},
{"name": plate + ".bolt", "part": "cyl", "params": "r=0.05; depth=0.03", "origin": [-1.05, 3, 0.02], "direction": [0, -1, 0]}])
M.shell_action(plate, shield, b, "khaki", thickness=0.14, levels=2, bevel=0.016)
M.cuts_action(plate, [{"name": plate + ".bracket", "part": "slot", "params": "width=0.3; height=0.06; depth=0.04", "origin": [-0.42, 4, -0.95], "direction": [0, -1, 0]},
{"name": plate + ".bolt", "part": "cyl", "params": "r=0.05; depth=0.04", "origin": [-0.75, 4, -0.5], "direction": [0, -1, 0]}])
d = b["gunmetal"]
d.box(T((-0.5, 0.95, -0.45)), (0.5, 0.4, 0.3)) # the shield's bracket to the frame
if arm:
upper_arm(b, Matrix.Translation((-0.55, 0, 0)))
def upper_arm(b, at=Matrix.Identity(4)):
"""The upper arm under a pauldron, hanging along -z from the shoulder's pivot: what the cap covers, two boxed
tiers, a pair of ringed elbow discs and a ribbed strip between them."""
tiers, a ringed elbow disc on each side and a ribbed strip down the front between them."""
k, d = b["khaki"], b["gunmetal"]
d.box(at @ T((0.05, -0.1, 0.1)), (1.2, 1.4, 1.0))
k.hull([(x, y, z) for x in (-0.45, 0.45) for y in (-0.5, 0.42) for z in (-0.5,)] + [(x, y, -1.15) for x in (-0.4, 0.4) for y in (-0.46, 0.4)], at)
k.hull([(x, y, -1.2) for x in (-0.37, 0.37) for y in (-0.44, 0.38)] + [(x, y, -1.75) for x in (-0.33, 0.33) for y in (-0.4, 0.34)], at)
d.box(at @ T((0, 0.0, -2.0)), (0.6, 0.6, 0.6))
for x in (-0.31, 0.31):
ringed_disc(d, at @ F((x, 0.3, -2.1), (0, 1, 0), (0, 0, 1)), 0.3, 0.14)
for x in (-1, 1): # the elbow's discs stand on its sides: its axis runs across the arm, as the hero view has it
ringed_disc(d, at @ F((x * 0.3, 0.0, -2.1), (x, 0, 0), (0, 0, 1)), 0.3, 0.14)
track(d, at @ Vector((0, 0.36, -1.72)), at @ Vector((0, 0.36, -2.5)), 0.3, 6, 0.1, (0, 1, 0))
def thigh(b):
"""THIGH PLATE, the mech's left thigh from the front: outboard is -x; origin at the plate's middle, z up. One
tall front shell, mirrored: a flat front between two creases, a facet each side turning back along the leg, broad
above and stepping in at a creased ledge to a tongue below, its top edge chamfered. Over its upper part a second
shell whose lower edge drops in a centre tab; a third on the tongue; down the outboard side a strip plate turned
back along the leg; the girder behind."""
d = b["gunmetal"]
main = {"mirror": True, "flip": True, "rings": [
[[0, 0.7, -1.3], [0.3, 0.7, -1.3], [0.5, 0.58, -1.3], [0.54, 0.2, -1.3]],
[[0, 0.72, -0.55], [0.34, 0.72, -0.55], [0.56, 0.6, -0.55], [0.6, 0.2, -0.55]],
[[0, 0.74, -0.3], [0.45, 0.74, -0.3], [0.74, 0.6, -0.3], [0.8, 0.2, -0.3]],
[[0, 0.74, 1.05], [0.45, 0.74, 1.05], [0.78, 0.6, 1.05], [0.84, 0.2, 1.05]],
[[0, 0.62, 1.3], [0.38, 0.62, 1.3], [0.62, 0.5, 1.3], [0.68, 0.2, 1.3]]],
"creases": [{"column": 1, "from": 0, "to": 4, "weight": 0.9}, {"column": 2, "from": 0, "to": 4, "weight": 1.0},
{"ring": 1, "from": 0, "to": 3, "weight": 1.0}, {"ring": 2, "from": 0, "to": 3, "weight": 1.0}, {"ring": 3, "from": 0, "to": 3, "weight": 1.0}]}
tall front shell, mirrored, its rings placed by fit.wrap from the crop's traced outline: a flat front between
two creases, a facet each side turning back along the leg, its top edge leaning back; a 0.13 m wall. Over its
lower part a second shell, the lapped plate with its centre notch; down the outboard side a strip plate turned
back along the leg. It straddles the hip's axis: the hip stands 0.1 m above its middle."""
front, side, az, el = fit.load("seraph", "thigh.plate")
rings = fit.wrap(front, side, az, el, [(-1.03, 1.0, -0.88), -0.5, 0.05, 0.7, (1.03, 1.0, 0.7)], flat=0.5, chamfer=0.3, flare=0.03)
main = {"mirror": True, "flip": True, "rings": rings, "creases": fit.creased(rings)}
name = b.name + ".plate"
M.shell_action(name, main, b, "khaki", thickness=0.09, levels=2, bevel=0.012)
M.cuts_action(name, [{"name": name + ".flank_a", "part": "slab", "params": "gap=0.022; length=0.9; depth=0.03", "origin": [-3, 0.42, 0.4], "direction": [1, 0, 0], "up": [0, 0, 1]},
{"name": name + ".flank_b", "part": "slab", "params": "gap=0.022; length=0.9; depth=0.03", "origin": [3, 0.42, 0.4], "direction": [-1, 0, 0], "up": [0, 0, 1]}])
upper = {"mirror": True, "flip": True, "rings": [ # its lower edge is ring 0: the centre tab is drawn in it
[[0, 0.81, -0.36], [0.22, 0.81, -0.36], [0.29, 0.81, -0.08], [0.67, 0.7, -0.08]],
[[0, 0.81, 0.2], [0.22, 0.81, 0.2], [0.29, 0.81, 0.2], [0.68, 0.7, 0.2]],
[[0, 0.81, 1.06], [0.22, 0.81, 1.06], [0.29, 0.81, 1.06], [0.7, 0.7, 1.06]],
[[0, 0.72, 1.22], [0.2, 0.72, 1.22], [0.27, 0.72, 1.22], [0.54, 0.64, 1.22]]],
"creases": [{"ring": 2, "from": 0, "to": 3, "weight": 1.0}, {"column": 2, "from": 0, "to": 3, "weight": 0.35}]}
over = b.name + ".upper"
M.shell_action(over, upper, b, "khaki", thickness=0.06, levels=3, bevel=0.012)
M.cuts_action(over, [{"name": over + ".tab", "part": "slab", "params": "gap=0.02; length=0.44; depth=0.025", "origin": [0, 3, -0.04], "direction": [0, -1, 0], "up": [1, 0, 0]}])
tongue = {"mirror": True, "flip": True, "rings": [[[0, 0.775, -1.22], [0.24, 0.775, -1.22], [0.4, 0.69, -1.22]], [[0, 0.79, -0.64], [0.27, 0.79, -0.64], [0.44, 0.7, -0.64]]],
"creases": [{"column": 1, "from": 0, "to": 1, "weight": 0.9}]}
M.shell_action(b.name + ".tongue", tongue, b, "khaki", thickness=0.06, levels=2, bevel=0.01)
strip = {"rings": [[[-0.88, 0.6, -0.42], [-1.02, 0.2, -0.7], [-1.04, -0.5, -0.6]], [[-0.88, 0.6, 0.3], [-1.03, 0.2, 0.3], [-1.05, -0.5, 0.3]], [[-0.86, 0.6, 1.05], [-1.0, 0.2, 1.0], [-1.02, -0.5, 0.9]]],
"creases": [{"column": 1, "from": 0, "to": 2, "weight": 1.0}]}
M.shell_action(name, main, b, "khaki", thickness=0.13, levels=1, bevel=0.014)
yf = rings[1][0][1]
M.cuts_action(name, [{"name": name + ".line", "part": "slab", "params": "gap=0.025; length=0.5; depth=0.03", "origin": [0, 3, 0.32], "direction": [0, -1, 0], "up": [1, 0, 0]},
{"name": name + ".flank_a", "part": "slab", "params": "gap=0.025; length=0.8; depth=0.03", "origin": [-3, 0.4, 0.3], "direction": [1, 0, 0], "up": [0, 0, 1]}])
hw = rings[1][1][0]
lower = {"mirror": True, "flip": True, "rings": [[[0, yf + 0.1, -0.98], [hw + 0.02, yf + 0.1, -0.98], [hw + 0.14, yf - 0.12, -0.98]],
[[0, yf + 0.1, -0.45], [hw + 0.02, yf + 0.1, -0.45], [hw + 0.14, yf - 0.12, -0.45]]],
"creases": [{"column": 1, "from": 0, "to": 1, "weight": 1.0}]}
over = b.name + ".lower"
M.shell_action(over, lower, b, "khaki", thickness=0.09, levels=1, bevel=0.012)
M.cuts_action(over, [{"name": over + ".tab", "part": "box", "params": "width=0.3; height=0.24; depth=0.3", "origin": [0, 3, -0.52], "direction": [0, -1, 0]}])
edge_x = rings[2][3][0]
strip = {"rings": [[[-edge_x - 0.03, yf - 0.22, z0], [-edge_x - 0.06, yf - 0.62, z1]] for z0, z1 in ((-0.5, -0.6), (0.9, 0.8))]}
edge = b.name + ".strip"
M.shell_action(edge, strip, b, "khaki", thickness=0.1, levels=3, bevel=0.012)
M.cuts_action(edge, [{"name": f"{edge}.bolt{j}", "part": "cyl", "params": "r=0.045; depth=0.03", "origin": [-3, -0.15, z], "direction": [1, 0, 0]} for j, z in enumerate((0.6, -0.2))])
d.box(T((0, 0.05, 0)), (0.9, 0.9, 2.9))
M.shell_action(edge, strip, b, "khaki", thickness=0.1, levels=1, bevel=0.012)
M.cuts_action(edge, [{"name": f"{edge}.bolt{j}", "part": "cyl", "params": "r=0.045; depth=0.03", "origin": [-3, yf - 0.4, z], "direction": [1, 0, 0]} for j, z in enumerate((0.55, -0.2))])
def shin(b):