# render/modelkit/wheel.py: one repeating section of the face (half a window, half a slot) laid out in quads,
# then turned round the rim; render/rim_iter.py draws each build's section (units_face.png)
def split_face_unit(p, r_rim=None):
"""Half a split spoke group's share of the face (split: 1, with a hub recess; the Method 705's): from the middle
of a group's slot (90 deg, a mirror line) to the middle of the next window (90 + 180 / spokes), between the
recess's edge ring (hub_cols columns per lug half unit, so the two meet: hub_cols * 2 * bolts round) and the rim.
The half slot and half window each get a ring of quads; between them the narrow spoke; band_unit lays it out."""
n_g = int(p["spokes"])
th0, th1 = math.radians(90), math.radians(90) + math.pi / n_g
N_j = _recess_cols(p) * 2 * int(p["bolts"])
assert N_j % (2 * n_g) == 0, ("rim cage: the recess's edge ring can't be shared by the face's units", N_j, n_g)
r_hub, r_out = p["hub_d"] / 2, p["face_r"]
span = lambda f: r_hub + (r_out - r_hub) * f
a0, a1 = span(p["window_r"][0]), span(p["window_r"][1])
s0, s1 = span(p["slot_r"][0]), span(p["slot_r"][1])
wa, sa = p.get("window_w_at") or [0.0, 0.0], p.get("slot_w_at") or [0.0, 0.0]
rc_s = p.get("slot_rc", 1.0) # each end at most round (half its own width): a tapered slot's narrow end
spoly, _ = arched_outline(th0, s0, s1, p["slot_w_in"] / 2, p["slot_w_out"] / 2, x0=sa[0], x1=sa[1],
rc_in=min(rc_s, p["slot_w_in"] / 2 * 0.98), rc_out=min(rc_s, p["slot_w_out"] / 2 * 0.98))
rc_w = min(p.get("window_rc_in") or p["window_rc"], p["window_w_in"] / 2 * 0.98) # a pointed end: at most round
wpoly, _ = arched_outline(th1, a0, a1, p["window_w_in"] / 2, p["window_w_out"] / 2, x0=wa[0], x1=wa[1],
rc_in=rc_w, rc_out=min(p["window_rc"], p["window_w_out"] / 2 * 0.98))
# the ring of quads round each hole: 5 mm, or less where a hole runs close to the band's outer arc (at least half
# the gap stays for the band's row)
off = max(0.0015, min(0.005, 0.45 * ((r_rim or r_out) - max(a1, s1))))
A = dict(window_half(spoly, +1), off=off)
B = dict(window_half(wpoly, -1), off=off)
m = band_unit(th0, th1, p["recess_face_r"], r_rim or r_out, A, B, n_in=N_j // (2 * n_g))
m.sink = {i: 0.0 for i in range(len(m.P))}
m.crease_e = []
_ccw(m)
m.relax()
m.loops["seat"] = []
m.loops["rim"] = m.loops["out"]
m.loops["W"] = m.loops["A"] + m.loops["B"]
m.rimN = m.n_out
m.n_units = 2 * n_g
m.a0 = a0
return m
def draw_unit(U, path, S=1000):
P = np.array(U.P)
lo, hi = P.min(0), P.max(0)
sc = (S - 40) / max(hi - lo)
W, H = int((hi - lo)[0] * sc) + 40, int((hi - lo)[1] * sc) + 40
im = Image.new("RGB", (W, H), "white")
g = ImageDraw.Draw(im)
T = lambda q: (20 + (q[0] - lo[0]) * sc, H - 20 - (q[1] - lo[1]) * sc)
bad = {tuple(sorted(f)) for f in U.F if lint.lint_layout(P, [f])}
for f in U.F:
g.polygon([T(P[i]) for i in f], outline=(0, 0, 0), fill=(255, 150, 150) if tuple(sorted(f)) in bad else None)
for i, j in getattr(U, "crease_e", []):
g.line([T(P[i]), T(P[j])], fill=(220, 0, 0), width=3)
for key, c in (("A", (0, 0, 255)), ("B", (0, 160, 0)), ("seat", (0, 0, 255)), ("W", (0, 160, 0))):
L = U.loops.get(key)
if L:
g.line([T(P[i]) for i in L], fill=c, width=3)
im.save(path)
# render/rim_iter.py and render/model_test.py: every build's topology checked
def evenness(m, A, jump=2.0):
"""How even the cage's quads are: their sizes (square root of area) across the whole cage (5th to 95th
percentile), and each quad that is more than `jump` times the size of a neighbour, grouped by feature (worst
first). Tate, 2026-10-26: 'make sure all quads are the same size and evenly spread'."""
V = np.asarray(m.v, float)
F = [f for f in m.f if len(f) == 4]
size = []
for f in F:
P = V[list(f)]
size.append(math.sqrt(0.5 * np.linalg.norm(np.cross(P[2] - P[0], P[3] - P[1]))))
size = np.array(size)
e2f = {}
for k, f in enumerate(F):
for t in range(4):
e2f.setdefault((min(f[t], f[(t + 1) % 4]), max(f[t], f[(t + 1) % 4])), []).append(k)
worst = np.ones(len(F))
for ks in e2f.values():
if len(ks) == 2:
a, b = ks
r = max(size[a], size[b]) / max(min(size[a], size[b]), 1e-9)
worst[a] = max(worst[a], r); worst[b] = max(worst[b], r)
lo, hi = np.percentile(size, [5, 95]) * 1000
out = [f"quads: {len(F)}, sizes {lo:.1f}-{hi:.1f} mm (5th-95th), median {np.median(size) * 1000:.1f}"]
groups = {}
for k in np.nonzero(worst > jump)[0]:
c = V[list(F[k])].mean(0)
groups.setdefault(classify(A, {"object": m.name, "at": list(c)}, None), []).append(worst[k])
for g, rs in sorted(groups.items(), key=lambda kv: -max(kv[1]))[:8]:
out.append(f"uneven x{len(rs):<4} {g:<30} neighbours up to {max(rs):.1f}x the size")
if not groups:
out.append(f"even: no quad over {jump:g}x a neighbour")
return out
def topology_summary(model, include):
tot = {k: 0 for k in ("faces", "quads", "tris", "ngons", "non_manifold_edges", "boundary_edges", "flipped_edges", "loose_verts", "degenerate_faces", "poles", "verts")}
worst = []
for name, t in model.info["objects"].items():
if include and not any(fnmatch.fnmatchcase(name, p) for p in include):
continue
for k in tot:
tot[k] += t[k]
bad = {k: t[k] for k in ("tris", "ngons", "non_manifold_edges", "flipped_edges", "loose_verts", "degenerate_faces") if t[k]}
if bad:
worst.append((name, bad))
tot["quad_ratio"] = round(tot["quads"] / max(tot["faces"], 1), 4)
tot["pole_per_kvert"] = round(1000 * tot["poles"] / max(tot["verts"], 1), 1)
tot["pass"] = tot["tris"] == 0 and tot["ngons"] == 0 and tot["non_manifold_edges"] == 0 and tot["flipped_edges"] == 0 and tot["loose_verts"] == 0 and tot["degenerate_faces"] == 0
tot["problems"] = worst[:12]
# the designed (base) meshes: their own topology, and how they'll hold up rendered finely
des = model.info.get("designed", {})
if des:
dq = {k: sum(d[k] for d in des.values()) for k in ("faces", "quads", "tris", "ngons", "non_manifold_edges", "flipped_edges")}
facet = max(des.items(), key=lambda kv: kv[1]["facet_max_deg"])
thin = min(des.items(), key=lambda kv: kv[1]["min_angle_deg"])
warp = max(des.items(), key=lambda kv: kv[1]["warp_p99"])
tot["designed"] = dict(dq, facet_max_deg=facet[1]["facet_max_deg"], facet_worst=facet[0],
facet_p99_deg=max(d["facet_p99_deg"] for d in des.values()),
min_angle_deg=thin[1]["min_angle_deg"], min_angle_worst=thin[0],
min_angle_p1_deg=min(d["min_angle_p1_deg"] for d in des.values()),
warp_p99=warp[1]["warp_p99"], warp_worst=warp[0])
D = tot["designed"]
D["fine_pass"] = D["facet_max_deg"] <= FACET_MAX and D["min_angle_p1_deg"] >= MIN_ANGLE_P1 and D["warp_p99"] <= WARP_P99
D["pass"] = D["tris"] == 0 and D["ngons"] == 0 and D["non_manifold_edges"] == 0 and D["flipped_edges"] == 0
tot["pass"] = tot["pass"] and D["pass"] and D["fine_pass"]
return tot
# render/photo_fit.py: the holes traced from the maker's face-on photo, then their outlines fitted
# Fits a rim's window and slot shapes to the maker's face-on photo, by numbers rather than by eye: the holes are
# traced (the barrel shows bright through them against the dark face), each traced point is taken back through the
# photo's solved camera onto the face's front surface (its dish: a point further back reads smaller), the holes are
# folded onto one window and one slot by the face's symmetry, and the outline numbers (ends' radii, widths, corner
# radii) are fitted by least squares to every traced point.
#
def trace(path, cx, cy, rho0, rho1, bright_only=False):
"""The holes in the face's annulus (rho0..rho1 px): their boundary pixels, per hole. Where the photo is cut out
(the holes transparent) that's the mask; else they're what isn't the face's grey. bright_only: only
what's brighter than the face (where the shading along the spokes' sides, darker, would join the holes up)."""
im = np.asarray(Image.open(path).convert("RGBA")).astype(float)
lum = 0.3 * im[..., 0] + 0.59 * im[..., 1] + 0.11 * im[..., 2]
h, w = lum.shape
yy, xx = np.mgrid[0:h, 0:w]
rho = np.hypot(xx - cx, yy - cy)
ann = (rho > rho0) & (rho < rho1) & (im[..., 3] > 128)
# the face itself is the commonest grey in the annulus (matte, evenly lit); a hole is anything else, the bright
# barrel behind it or the dark shadow inside it
vals = lum[ann]
hist, edges = np.histogram(vals, 64)
k = int(np.argmax(hist))
mode = 0.5 * (edges[k] + edges[k + 1])
lo, hi = 0.55 * mode, 1.45 * mode
thr = (lo, hi)
bright = ann & ((lum > hi) | ((lum < lo) & (not bright_only)))
cut = (rho > rho0) & (rho < rho1) & (im[..., 3] < 128) # a cut-out photo: the holes are transparent, the
if cut.sum() > 0.02 * ann.sum(): # background showing through them (the Method 312's)
bright = cut
bright = ndimage.binary_opening(bright, iterations=2)
bright = ndimage.binary_fill_holes(ndimage.binary_closing(bright, iterations=2))
lab, n = ndimage.label(bright)
sizes = ndimage.sum(bright, lab, range(1, n + 1))
holes = []
for k in np.argsort(-sizes):
if sizes[k] < 0.15 * sizes.max():
break
reg = ndimage.binary_fill_holes(lab == k + 1) # its outline only (not the wall's band inside it)
edge = reg & ~ndimage.binary_erosion(reg)
ys, xs = np.nonzero(edge)
holes.append(np.stack([xs, ys], 1).astype(float))
return holes, thr
def fit_hole(XY, start, fixed):
"""Least squares: the outline's numbers (a0, a1, h0, h1, rc_in, rc_out) from the folded traced points."""
keys = ["a0", "a1", "h0", "h1", "rc_in", "rc_out"]
x_init = np.array([start[k] for k in keys])
def res(x):
d = dict(zip(keys, x))
bad = np.full(len(XY) + len(keys), 0.01)
if d["rc_in"] < 0.0006 or d["rc_out"] < 0.0006 or d["h0"] < 0.003 or d["h1"] < 0.003 or d["a1"] < d["a0"] + 0.01:
return bad
try:
P = outline(d["a0"], d["a1"], d["h0"], d["h1"], fixed["x0"], fixed["x1"], d["rc_in"], d["rc_out"])
except Exception:
return bad
P = P[P[:, 1] >= -1e-9] # the outline's folded half
# a weak pull toward the spec's numbers: a number the photo shows (its outline traced there) moves to fit,
# one it doesn't (a hole's end in shadow) stays where it was rather than drifting
prior = 0.05 * (x - x_init) * math.sqrt(len(XY) / 6)
return np.concatenate([wheel._dist_to_polyline(XY, P), prior])
sol = optimize.least_squares(res, x_init, x_scale=0.003, diff_step=1e-3, loss="soft_l1", f_scale=0.0005)
d = dict(zip(keys, sol.x))
r = res(sol.x)[:len(XY)]
return d, float(np.sqrt(np.mean(r ** 2))), float(np.percentile(r, 95))
# render/photo_depth.py: how deep each part of the face sits, read off the three-quarter photo
# Reads depths off the maker's 3/4 photo: how far below the front lip each circular feature of the face lies (the
# hub's face, a recess's chamfer, its shelves and floor, the cap). Long-lens product shots are near orthographic, so
# every circle round the wheel's axis shows as an ellipse of the same tilt and shape: its size says its radius, and
# how far its centre sits along the axis's line in the picture says its depth. The front lip's outer edge (radius and
# depth known from the published numbers) is fitted first and sets the scale and tilt; then for each feature of known
# radius, the depth whose ellipse runs along the photo's strongest edges.
def score(r, z, sign):
"""How strongly the photo has an edge along the circle of radius r at depth z: the brightness gradient across
the ellipse (along its normal, so edges crossing it don't count), the best three quarters (some is hidden)."""
sz = s * D / (D + z_lip - z) # deeper circles are further from the camera: smaller
cc = c + sign * sz * (z - z_lip) * sin_al * u
t = np.linspace(0, 2 * math.pi, 720, endpoint=False)
ca, sa = math.cos(th), math.sin(th)
A_, B_ = sz * r, sz * r * cos_al
E = np.stack([cc[0] + A_ * np.cos(t) * ca - B_ * np.sin(t) * sa, cc[1] + A_ * np.cos(t) * sa + B_ * np.sin(t) * ca], 1)
N = np.stack([B_ * np.cos(t) * ca - A_ * np.sin(t) * sa, B_ * np.cos(t) * sa + A_ * np.sin(t) * ca], 1)
N /= np.linalg.norm(N, axis=1, keepdims=True)
ok = (E[:, 0] >= 0) & (E[:, 0] < lum.shape[1] - 1) & (E[:, 1] >= 0) & (E[:, 1] < lum.shape[0] - 1)
if ok.sum() <= 50:
return 0.0
vx = ndimage.map_coordinates(gx, [E[ok, 1], E[ok, 0]], order=1)
vy = ndimage.map_coordinates(gy, [E[ok, 1], E[ok, 0]], order=1)
v = np.abs(vx * N[ok, 0] + vy * N[ok, 1])
return float(np.mean(np.sort(v)[len(v) // 4:]))
# method-705, gen 28, the last generation: what changed since gen 19
# every straight run of the barrel's section down to the rings its shape
# needs: the 50 mm cap gone, and a run's end ring gone too where that end is a
# creased corner (99 rings in gen-26, 67 now)
face_art_r 125 mm -> 212 mm # reference: art.json face.radius_mm: out past the valve's counterbore
valve_face_r 203 mm -> 200.5 mm # reference: face.png: the counterbore's centre about 200-204 mm out at
valve_cb_d 13 mm -> 12 mm # reference: face.png: about 17 mm across; 12 fits the band's flat betwe
# the final render (Blender, Cycles): gen 28 painted gloss black and lit as a studio product shot
# gloss black (Tate: "make it gloss"): the model's own materials kept whole, the cap's printed logo, the face's
# ambient occlusion and the roughness and metal masks that make the cast lettering read; the gloss is a clear coat on top
for m in bpy.data.materials:
nt=m.node_tree
if not nt or m.name not in ('Rim.textures','Cap.textures'): continue
b=next(n for n in nt.nodes if n.type=='BSDF_PRINCIPLED')
b.inputs['Coat Weight'].default_value=1.0
b.inputs['Coat Roughness'].default_value=0.03
b.inputs['Coat IOR'].default_value=1.5
# lights: big soft key upper left, fill right, rim from behind
def area(name,loc,size,power):
l=bpy.data.lights.new(name,'AREA'); l.size=size; l.energy=power
o=bpy.data.objects.new(name,l); sc.collection.objects.link(o); o.location=loc
o.rotation_euler=(ctr-o.location).to_track_quat('-Z','Y').to_euler(); return o
area('key',ctr+(axis*1.2+side*-1.1+up*1.3).normalized()*R*6,R*4,R*R*850)
area('fill',ctr+(axis*1.0+side*1.3+up*0.2).normalized()*R*6,R*5,R*R*110)
area('rim',ctr+(-axis*0.6+side*0.9+up*1.2).normalized()*R*5,R*2,R*R*1000)
area('top',ctr+(up*1.0+axis*0.3).normalized()*R*5,R*6,R*R*140)
area('front',ctr+(axis*1.0+up*1.25+side*-0.35).normalized()*R*4.5,R*2.6,R*R*300)
w=bpy.data.worlds.new('w'); sc.world=w; w.use_nodes=True
bg=w.node_tree.nodes.get('Background'); bg.inputs[0].default_value=(0.06,0.06,0.065,1); bg.inputs[1].default_value=1.0