diff --git a/surfaces/blender/experiments/mechs/paladin.py b/surfaces/blender/experiments/mechs/paladin.py new file mode 100644 index 0000000..25b54b5 --- /dev/null +++ b/surfaces/blender/experiments/mechs/paladin.py @@ -0,0 +1,147 @@ +"""PALADIN: concept sheet images/27.webp, built on the method of Seraph's clean rebuild and the walker's: the +character line first, then mass as solids checked against the silhouettes, then plates. + +The character line is the chest's belt (paladin_form.BELT): the knuckle where the glacis under the turret breaks to +the hull's upright band, a chevron in plan with the amber lamp at its stem, carried outboard by the pauldrons' +knuckles and repeated above by the turret's visor band. + +PALADIN_STAGE: line (the hull, the turret and the pauldrons alone, plated: the belt and nothing else), volume (the +whole figure as solids, no plate), full (default). MECH_QUICK renders by Workbench. Writes under MECH_OUT/paladin/: +_.png and _sil_.png for the hero, rear and side views at the solved cameras +(paladin_cameras.json: the sheet's own pixels), _character.png (the hero camera cropped to the belt), +_edges_hero.json (mechlib.built_edges), _turn_*.png, component close-ups (full), paladin_report.json. + +The skeleton is paladin_form.JOINTS: every part is built on those points, so the cameras are solved from them before +anything is built (python paladin_form.py solve). The legs and arms are not kit parts: the joints are drawn as the +sheet draws them (hip drums, the library's kneecap on its bisector ring, ankle discs, the library's waist slew +ring), but nothing here turns on a kit socket, and brokkr_kitbash's joint records have nothing to read.""" +import json, math, os, sys, time +from pathlib import Path +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import mechlib as M +import massing as MS +import paladin_form as PF +import paladin_body as PB +from mathutils import Matrix, Vector +import bpy + +t0 = time.time() +M.setup() +M.material("lamp_amber", (0.02, 0.02, 0.02), 0.0, 0.2, emission=((1.0, 0.5, 0.05), 12.0)) +F, T = M.frame_at, Matrix.Translation +STAGES = ("line", "volume", "full") +STAGE = os.environ.get("PALADIN_STAGE", "full") +AT = STAGES.index(STAGE) +QUICK = bool(os.environ.get("MECH_QUICK")) +OUT = Path(os.environ["MECH_OUT"]) / "paladin" +assert OUT.is_absolute() +OUT.mkdir(parents=True, exist_ok=True) +FR = T(PF.WAIST) +PLATED = STAGE != "volume" + +# --- the character line first: the hull, the turret, the pauldrons ------------------------------------------------------ +torso = PB.torso_mass(FR) +turret = PB.turret_mass(FR) +pauldrons = {sx: PB.pauldron_mass(FR, sx) for sx in (-1, 1)} +slot = PB.visor_cut(FR) +PB.torso_plates(torso, plates=PLATED) +PB.turret_plates(turret, [slot], plates=PLATED) +for sx, pm in pauldrons.items(): + PB.pauldron_plates(pm, sx, plates=PLATED) +if PLATED: + MS.carve(turret, [slot]) + PB.visor(FR) + PB.hatch(FR) +print("line s", round(time.time() - t0, 1), flush=True) + +if AT >= 1: + import jointlib as J + import joints + import weapons_missile, weapons_rotary, weapons_sensor + PB.mast(FR) + PB.exchangers(FR) + PB.abdomen(FR) + for sx in (-1, 1): + PB.shoulder(FR, sx) + PB.upper_arm(sx) + PB.hip(sx) + PB.thigh(sx, plates=PLATED) + PB.knee(sx) + PB.shin(sx, plates=PLATED) + PB.foot(sx) + PB.pelvis() + rig = J.Rig("Waist", T((0, PF.WAIST[1] - 0.1, PF.WAIST[2] - 0.35)), -50.0, 50.0) + joints.slew_waist(rig, 0.0, r=0.8, torso=(1.3, 1.0, 0.3)) + rig.done() + PB.forearm_left(plates=PLATED) + PB.put("Gatling", PB.aim(PF.JOINTS["elbow_r"], PF.JOINTS["muzzle_r"]), weapons_rotary.paladin_gatling, size="M") + PB.put("Battery", FR @ T((3.1, 0.45, 3.62)), weapons_missile.paladin_battery, size="M", cols=6, rows=4) + PB.put("EW", FR @ T((-3.1, 0.25, 2.95)), weapons_sensor.paladin_ew_module, size="M", dome=False, optic=False) + b = PB.put("EWLow", FR @ T((-3.1, 1.45, 2.55))) # the EW inset's lower case, forward on the pauldron's roof + b["khaki"].prism(T((0, -0.5, -0.3)) @ M.frame_at((0, 0, 0), (0, 1, 0), (0, 0, 1)), M.rect(1.35, 0.62, 0.1), 1.0, 0.05) + b["gunmetal"].box(T((0, 0.5, -0.3)), (1.1, 0.04, 0.42)) + for x in (-0.36, 0.0, 0.36): + b["glass"].box(T((x, 0.525, -0.3)), (0.26, 0.02, 0.26)) + b.done() + print("volume s", round(time.time() - t0, 1), flush=True) + +if AT >= 2: + wy, wz = PF.WAIST[1], PF.WAIST[2] + PB.mark("Mark07.band", "07", (1.15 + 1.8, wy + 1.47 + 2.4, wz + 1.5), (-0.61, -0.79, 0.0), 0.36) + PB.mark("Mark07.pauldron", "07", (2.95, 6.0, wz + PF.PAULDRON_AT[2] + 0.55), (0, -1, 0), 0.42) + PB.mark("Mark07.thigh", "07", (-1.85, 6.0, 4.9), (0, -1, 0), 0.42) + PB.mark("Mark7.band", "7", (-1.15 - 1.8, wy + 1.47 + 2.4, wz + 1.5), (0.61, -0.79, 0.0), 0.34) + PB.triangle("Tri.thigh", (1.85, 6.0, 4.9), (0, -1, 0), 0.5) + PB.triangle("Tri.shin", (-1.8, 6.0, 2.5), (0, -1, 0), 0.34) + PB.triangle("Tri.pauldron", (-2.95, 6.0, wz + PF.PAULDRON_AT[2] + 0.5), (0, -1, 0), 0.4) + +M.update() +lo, hi = M.bounds() +print("HEIGHT", round(hi.z - lo.z, 2), "LOW", round(lo.z, 2), "WIDTH", round(hi.x - lo.x, 2), "DEPTH", round(lo.y, 2), round(hi.y, 2), "stage", STAGE, "frozen", len(PB.FROZEN), "build s", round(time.time() - t0, 1), flush=True) +M.tops() + +# --- the solved cameras, the views, the edges --------------------------------------------------------------------------- +import camsolve +cams = PF.cameras() +report = {"stage": STAGE, "height": round(hi.z - lo.z, 2), "width": round(hi.x - lo.x, 2), "frozen": len(PB.FROZEN), "cameras": {}} +for tag, cam in cams.items(): + report["cameras"][tag] = {k: cam[k] for k in ("rms", "left_out", "lens", "lens_range", "azimuth", "elevation", "distance", "model", "worst")} + report["cameras"][tag]["projected"] = {k: [float(c) for c in camsolve.project(cam, [PF.world(k)])[0]] for k in PF.VIEWS[tag]["marks"]} +rig, cam, centre, radius = M.stage_field(8 if QUICK else int(os.environ.get("MECH_SAMPLES", 48))) +scene = bpy.context.scene +K = 3 +PARTS_ONLY = bool(os.environ.get("PALADIN_PARTS_ONLY")) # the turns and close-ups alone: a rerun after the GPU ran out under them +for tag in ([] if PARTS_ONLY else cams): + box = cams[tag]["box"] + w = int(box[2] - box[0]) * K + M.silhouette(rig, cam, radius, 0, 0, OUT / f"{STAGE}_sil_{tag}.png", (w, 0), solved=cams[tag]) + if QUICK: + M.preview(rig, cam, cams[tag], OUT / f"{STAGE}_{tag}.png", w) + else: + M.shot(rig, cam, radius, 0, 0, OUT / f"{STAGE}_{tag}.png", (w, w), solved=cams[tag]) +CHARACTER = [20, 0, 352, 200] +if PARTS_ONLY: + pass +elif QUICK: + M.preview(rig, cam, cams["hero"], OUT / f"{STAGE}_character.png", 1328, CHARACTER) +else: + M.shot(rig, cam, radius, 0, 0, OUT / f"{STAGE}_character.png", (1328, 800), solved=cams["hero"], box=CHARACTER) +if PLATED and not PARTS_ONLY and not os.environ.get("PALADIN_NO_EDGES"): + armour = lambda name: not name.endswith((".machine", ".steel", ".rubber", ".glass", ".glow", ".glow_blue", ".lamp_amber")) and not name.startswith(("Mark", "Tri.")) # noqa: E731 + (OUT / f"{STAGE}_edges_hero.json").write_text(json.dumps(M.built_edges(cams["hero"], keep=armour)), encoding="utf-8") + print("edges s", round(time.time() - t0, 1), flush=True) +for az in (() if PARTS_ONLY else (35, 90, 180) if not QUICK else (35, 180)): + M.shot(rig, cam, radius, az, 6.0, OUT / f"{STAGE}_turn_{az:03d}.png", (900, 900) if QUICK else (1100, 1100), margin=0.8, lens=85.0) +if STAGE == "full": + wz = PF.WAIST[2] + # the sheet's insets, each from about where the inset looks: (name, target, span, azimuth, elevation) + wy = PF.WAIST[1] + shots = [("cockpit", (0, wy + 1.2, wz + 2.3), 4.2, -25, 8), ("battery", (2.95, wy + 0.6, wz + 3.5), 4.0, 28, -6), ("ew", (-2.9, wy + 0.6, wz + 3.2), 4.0, -30, 4), ("exchangers", (0, wy - 2.0, wz + 2.0), 5.6, 180, 0), + ("gatling", tuple((Vector(PF.JOINTS["elbow_r"]) + Vector(PF.JOINTS["muzzle_r"])) / 2), 4.8, 40, 6), ("hand", PF.JOINTS["wrist_l"], 3.6, -40, 4), + ("pelvis", (0, 0.8, 5.5), 4.2, 0, 0), ("knee", PF.JOINTS["knee_l"], 3.6, -55, 4), ("foot", (-1.85, 0.6, 0.6), 4.2, -40, 14)] + for name, target, span, az, el in shots: + M.closeup(rig, cam, Vector(target), 0.42 * span, az, el, OUT / f"part_{name}.png", (700, 620)) + bpy.ops.wm.save_as_mainfile(filepath=str(OUT / "paladin.blend")) +if not PARTS_ONLY: + (OUT / f"paladin_report_{STAGE}.json").write_text(json.dumps(report, indent=1), encoding="utf-8") +print("total s", round(time.time() - t0, 1)) diff --git a/surfaces/blender/experiments/mechs/paladin_body.py b/surfaces/blender/experiments/mechs/paladin_body.py new file mode 100644 index 0000000..1013a1c --- /dev/null +++ b/surfaces/blender/experiments/mechs/paladin_body.py @@ -0,0 +1,618 @@ +"""PALADIN's parts (concept sheet images/27.webp), over massing.py, mechlib.Build and the joints and weapons +libraries. Runs inside Blender. Every armoured part is a faceted solid first (mass(): a convex hull of the form's +points) and plates after (armour(): massing.plate per plate, each frozen by brokkr_kitbash.freeze once its cuts are +in, the solid drawn back under them as the dark core). + +Tools here, each used by more than one part: + mass(name, points, frame) a faceted closed solid: the convex hull of points, coplanar triangles merged + armour(prefix, solid, specs) plates off a solid [(name, keep, proud, wall, bevel)], frozen; the solid becomes the core + limb(a, b) a frame at a, z up the link from b to a, y forward, x to the mech's right + sided(points, sx) points written with x outboard, for a side + mark(...) / triangle(...) a stencil seated on whatever a ray hits + +Parts, in the order paladin.py builds them (the character line first): torso_mass, turret_mass, pauldron_mass; +torso_plates, turret_plates, visor, pauldron_plates; mast, shoulder, exchangers, abdomen, pelvis, hip, thigh, knee, +shin, foot, upper_arm, forearm_left. +""" +import math + +import bmesh +import bpy +from mathutils import Matrix, Vector + +import mechlib as M +import massing as MS +import paladin_form as PF + +F, T = M.frame_at, Matrix.Translation +CORE = "gunmetal" +P = "khaki" +UP, FRONT = (0, 0, 1), (0, 1, 0) +FROZEN = [] + + +def band(axis, lo=None, hi=None): + """Half-spaces keeping lo <= axis <= hi (either may be None).""" + out = [] + if hi is not None: + out.append(MS.half(axis, 1, hi)) + if lo is not None: + out.append(MS.half(axis, -1, lo)) + return out + + +def out(sx, lo=None, hi=None): + """Half-spaces on the outboard coordinate u = sx * x.""" + keep = [] + if hi is not None: + keep.append(((sx, 0.0, 0.0), hi)) + if lo is not None: + keep.append(((-sx, 0.0, 0.0), -lo)) + return keep + + +def sided(points, sx): + return [(sx * u, y, z) for u, y, z in points] + + +def both(points): + seen, res = set(), [] + for x, y, z in points: + for q in ((x, y, z), (-x, y, z)): + key = tuple(round(c, 5) for c in q) + if key not in seen: + seen.add(key) + res.append(q) + return res + + +def mass(name, points, frame, mat=P): + bm = bmesh.new() + verts = [bm.verts.new(p) for p in points] + got = bmesh.ops.convex_hull(bm, input=verts) + junk = list({v for v in got["geom_interior"] + got["geom_unused"] if isinstance(v, bmesh.types.BMVert)}) + if junk: + bmesh.ops.delete(bm, geom=junk, context="VERTS") + bmesh.ops.dissolve_limit(bm, angle_limit=math.radians(1.0), verts=bm.verts[:], edges=bm.edges[:]) + bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) + obj = MS._object(name, bm, mat, frame) + for p in obj.data.polygons: + p.use_smooth = False + return obj + + +def freeze(obj): + """brokkr_kitbash.freeze: the plate's evaluated mesh becomes its mesh, so the assembly stops re-evaluating it.""" + if not obj.modifiers: + return + try: + if "FINISHED" in bpy.ops.brokkr_kitbash.freeze(object_name=obj.name): + FROZEN.append(obj.name) + except RuntimeError as e: + print(f"FREEZE {obj.name} refused: {str(e).strip()[:160]}", flush=True) + + +def facets(solid, pick): + """The solid's faces whose normal pick() takes, as a surface of its own: a plate cut from it ends on the solid's + own creases, so a character line that is a crease of the mass is a plate's edge, whatever its slope.""" + bm = bmesh.new() + bm.from_mesh(solid.data) + bmesh.ops.delete(bm, geom=[f for f in bm.faces if not pick(f.normal)], context="FACES") + obj = MS._object(solid.name + ".facets", bm, P, solid.matrix_world) + return obj + + +def armour(prefix, solid, specs, cutters=(), inset=0.05, plates=True): + """Plates off a solid, then the solid drawn in as the core. Without `plates` the solid stays as it is: the + volume stage.""" + made = [] + if not plates: + return made + for name, keep, proud, wall, bevel, *pick in specs: + src = facets(solid, pick[0]) if pick else solid + obj = MS.plate(f"{prefix}.{name}", src, keep, proud=proud, wall=wall, cutters=cutters, bevel=bevel) + if pick: + bpy.data.objects.remove(src, do_unlink=True) + if obj is not None: + freeze(obj) + made.append(obj) + for v in solid.data.vertices: + v.co -= v.normal * inset + M.assign(solid, CORE) + solid.name = f"{prefix}.core" + return made + + +def limb(a, b): + a, b = Vector(a), Vector(b) + z = (a - b).normalized() + x = (Vector((1, 0, 0)) - z * z.x).normalized() + y = z.cross(x) + m = Matrix((x, y, z)).transposed().to_4x4() + m.translation = a + return m + + +def put(name, to, fn=None, **kw): + """A Build at a frame in the world; fn(build, **kw) draws into it, or the caller does and calls done().""" + b = M.Build(name, None, to) + if fn is None: + return b + fn(b, **kw) + return b.done() + + +def mark(name, text, origin, direction, height, up=UP): + """A stencil on whatever the ray from origin along direction hits first (the world).""" + M.update() + dg = bpy.context.evaluated_depsgraph_get() + d = Vector(direction).normalized() + hit, at, normal, _, obj, _ = bpy.context.scene.ray_cast(dg, Vector(origin), d) + if not hit: + print(f"MARK {name}: the ray hits nothing", flush=True) + return None + inv = obj.matrix_world.inverted() + frame = inv @ F(at + normal * 0.004, normal, up) + return M.stencil_text(name, obj, frame, text, height) + + +def triangle(name, origin, direction, size, up=UP): + """The sheet's hollow triangle mark, point down, seated like mark().""" + M.update() + dg = bpy.context.evaluated_depsgraph_get() + hit, at, normal, _, obj, _ = bpy.context.scene.ray_cast(dg, Vector(origin), Vector(direction).normalized()) + if not hit: + return None + g = M.Geo() + frame = F(at + normal * 0.004, normal, up) + yv = (frame.to_3x3() @ Vector((0, 1, 0))) + flip = -1.0 if yv.z > 0 else 1.0 # point down + pts = [(-0.5 * size, -0.45 * size * flip), (0.5 * size, -0.45 * size * flip), (0.0, 0.5 * size * flip)] + t = 0.09 * size + for i in range(3): + a, b = Vector(pts[i]), Vector(pts[(i + 1) % 3]) + g.box(frame @ T(((a.x + b.x) / 2, (a.y + b.y) / 2, 0.0)) @ Matrix.Rotation(math.atan2(b.y - a.y, b.x - a.x), 4, "Z"), ((b - a).length + t, t, 0.004)) + return g.to_object(name, "stencil") + + +# --- the character line: torso, turret, pauldrons as solids ---------------------------------------------------------- + +def _ring(points, z): + return [(x, y, z) for x, y in points] + + +def _inset(points, by): + res = [] + for x, y in points: + r = math.hypot(x, y) + k = max(0.0, 1.0 - by / r) if r > 1e-6 else 1.0 + res.append((x * k, y * k)) + return res + + +def torso_mass(frame, mat=P): + """The hull above the waist: the belt (the knuckle), the band under it leaning in to its foot, the glacis over + it rising to the turret's deck, the keel under the band.""" + pts = list(PF.BELT) + list(PF.FOOT_RING) + _ring(PF.DECK, PF.DECK_Z) + for z, ring in PF.KEEL: + pts += _ring(ring, z) + return mass("Torso.mass", both(pts), frame, mat) + + +GLACIS = lambda n: 0.25 < n.z <= 0.98 # noqa: E731 the hull's facets by where they face +DECK = lambda n: n.z > 0.98 # noqa: E731 +BANDF = lambda n: -0.35 <= n.z <= 0.25 # noqa: E731 +KEELF = lambda n: n.z < -0.35 # noqa: E731 + + +def turret_mass(frame, mat=P): + t = PF.TURRET + h, f, r, c, H = t["half"], t["front"], t["rear"], t["clip"], t["height"] + plan = [(0.0, f), (h - c, f), (h, f - c), (h, -r + c), (h - c, -r), (0.0, -r)] + k = t["crown"] + pts = _ring(_inset(plan, 0.1), 0.0) + _ring(plan, 0.2 * H) + _ring(plan, 0.62 * H) + _ring([(x * k, y * k - 0.1) for x, y in plan], H) + return mass("Turret.mass", both(pts), frame @ T(t["at"]), mat) + + +def pauldron_profile(): + p = PF.PAULDRON + return [(-p["crown"][0], p["crown"][1]), (-0.1, p["crown"][1] + 0.05), (-p["knuckle"][0], p["knuckle"][1]), (-p["foot"][0], p["foot"][1]), (-p["inner_foot"][0], p["inner_foot"][1]), (-1.0, 0.2)] + + +def pauldron_frame(frame, sx): + at = PF.PAULDRON_AT + return frame @ T((-sx * at[0], at[1], at[2])) + + +def pauldron_mass(frame, sx, mat=P): + """A pauldron: the profile (outboard, up) drawn fore and aft, the ends drawn in. Its knuckle stands outboard at + the belt's height; the roof falls to it from the crown, the skirt is cut back under it.""" + p, prof = PF.PAULDRON, pauldron_profile() + hy, nose = p["half_y"], p["nose"] + pts = [] + for y, k in ((hy, 0.8), (hy - nose, 1.0), (-hy + nose, 1.0), (-hy, 0.8)): + pts += [(u * k, y, z * k + (0.1 if k < 1 else 0.0)) for u, z in prof] + return mass(f"Pauldron{'L' if sx < 0 else 'R'}.mass", sided(pts, sx), pauldron_frame(frame, sx), mat) + + +def torso_plates(solid, cutters=(), plates=True): + """The hull's plates, cut along the hull's own creases (facets): the glacis plates stand furthest proud and end + on the belt, the band's plates stand under it, so the knuckle is a step; the stem between the band's halves + carries the lamp.""" + cx, cy = PF.BELT[2][0], PF.BELT[2][1] + specs = [("Stem", band("x", -0.43, 0.43) + band("y", 1.2), 0.14, 0.16, 0.04, BANDF), + ("GlacisC", band("x", -0.45, 0.45) + band("y", 0.4), 0.10, 0.12, 0.04, GLACIS), + ("Deck", [], 0.04, 0.08, 0.03, DECK), + ("GlacisBack", band("x", -1.2, 1.2) + band("y", None, -0.6), 0.10, 0.1, 0.04, GLACIS), + ("BandBack", band("x", -1.25, 1.25) + band("y", None, -0.8), 0.05, 0.1, 0.04, BANDF) +] # the keel takes no plate: under the band the hull is the dark core, as the hero view has it + for sx, s in ((1, "R"), (-1, "L")): + specs += [("Glacis" + s, out(sx, 0.49) + band("y", 0.3), 0.17, 0.14, 0.05, GLACIS), + ("GlacisSide" + s, out(sx, 0.49) + band("y", -0.56, 0.26), 0.13, 0.12, 0.04, GLACIS), + ("GlacisRear" + s, out(sx, 1.24) + band("y", None, -0.6), 0.10, 0.1, 0.04, GLACIS), + ("Band" + s, out(sx, 0.47) + band("y", cy + 0.02), 0.07, 0.14, 0.05, BANDF), + ("Cheek" + s, out(sx, 1.0) + band("y", 0.28, cy - 0.02), 0.11, 0.14, 0.05, BANDF), + ("Flank" + s, out(sx, 1.0) + band("y", -0.52, 0.24), 0.05, 0.12, 0.04, BANDF), + ("Quarter" + s, out(sx, 1.29) + band("y", None, -0.56), 0.08, 0.12, 0.04, BANDF)] + return armour("Torso", solid, specs, cutters, plates=plates) + + +def visor_cut(frame): + t = PF.TURRET + return MS.slab("Visor.cut", (0.0, t["front"] - 0.05, 0.41 * t["height"]), (2 * t["half"] - 0.7, 0.8, 0.3 * t["height"]), frame @ T(t["at"])) + + +def turret_plates(solid, cutters=(), plates=True): + H, h = PF.TURRET["height"], PF.TURRET["half"] + specs = [("Crown", band("z", 0.6 * H), 0.10, 0.12, 0.04), + ("Brow", band("z", 0.22 * H, 0.6 * H - 0.02) + band("y", 0.2), 0.07, 0.14, 0.04), + ("Rear", band("z", 0.22 * H, 0.6 * H - 0.02) + band("y", None, 0.16), 0.04, 0.1, 0.03), + ("Jaw", band("z", None, 0.22 * H - 0.02), 0.03, 0.1, 0.03)] + return armour("Turret", solid, specs, cutters, plates=plates) + + +def visor(frame): + """COCKPIT & SENSOR ARRAY inset: in the slot across the turret's brow, a dark sill, a glass strip in the + middle, two red lenses a side, a pale lamp at each end.""" + t = PF.TURRET + b = put("Visor", frame @ T(t["at"])) + z, y, H = 0.41 * t["height"], t["front"] - 0.2, t["height"] + b["gunmetal"].box(T((0, y - 0.1, z)), (2 * t["half"] - 0.6, 0.3, 0.3 * H)) + b["glass"].box(T((0, y + 0.06, z)), (0.72, 0.04, 0.2 * H)) + b["glow_blue"].box(T((0, y + 0.075, z + 0.02)), (0.3, 0.02, 0.08 * H)) + for s in (-1, 1): + for i, x in enumerate((0.52, 0.76)): + b["machine"].cylinder(F((s * x, y + 0.05, z), FRONT), 0.085, 0.06, 16) + b["glow"].cylinder(F((s * x, y + 0.085, z), FRONT), 0.05, 0.02, 12) + b["glass"].cylinder(F((s * 0.98, y + 0.03, z), FRONT), 0.07, 0.05, 12) + return b.done() + + +def pauldron_plates(solid, sx, cutters=(), plates=True): + p = PF.PAULDRON + yb = p["half_y"] - p["nose"] + kz = p["knuckle"][1] + specs = [("Roof", band("z", kz + 0.02) + band("y", -yb + 0.03, yb - 0.03) + out(sx, -0.6), 0.14, 0.16, 0.05), + ("Inner", band("y", -yb + 0.03, yb - 0.03) + out(sx, None, -0.64), 0.03, 0.1, 0.03), + ("Skirt", band("z", None, kz - 0.03) + band("y", -yb + 0.03, yb - 0.03) + out(sx, -0.6), 0.05, 0.14, 0.04), + ("FrontUp", band("y", yb + 0.02) + band("z", kz + 0.12), 0.16, 0.16, 0.05), + ("FrontLow", band("y", yb + 0.02) + band("z", None, kz + 0.08), 0.08, 0.16, 0.05), + ("RearUp", band("y", None, -yb - 0.02) + band("z", kz + 0.12), 0.12, 0.14, 0.04), + ("RearLow", band("y", None, -yb - 0.02) + band("z", None, kz + 0.08), 0.06, 0.14, 0.04)] + return armour(f"Pauldron{'L' if sx < 0 else 'R'}", solid, specs, cutters, plates=plates) + + +# --- the rest of the upper body ---------------------------------------------------------------------------------------- + +def hatch(frame): + """COCKPIT & SENSOR ARRAY inset: the dark block on the glacis's middle, from under the turret down to the stem, + a grille in its nose; and the amber lamp on the stem.""" + b = put("Hatch", frame) + (y0, z0), (y1, z1) = (PF.DECK[0][1] - 0.05, PF.DECK_Z + 0.02), (PF.BELT[0][1] - 0.45, PF.BELT[0][2] + 0.42) + b["gunmetal"].hull([(0.36, y0, z0), (0.36, y0, z0 + 0.2), (0.4, y1, z1), (0.36, y1 - 0.1, z1 + 0.3), (0.3, y1 + 0.16, z1 - 0.06), (0.3, y1 + 0.1, z1 + 0.2)], mirror=True) + for i in range(4): + b["machine"].box(T((0, y1 + 0.15, z1 + 0.0 + 0.05 * i)) @ Matrix.Rotation(math.radians(-25), 4, "X"), (0.5, 0.03, 0.02)) + lamp = (0.0, PF.BELT[0][1] - 0.05, PF.BELT[0][2] - 0.2) + b["gunmetal"].box(T(lamp), (0.4, 0.3, 0.16)) + b["lamp_amber"].box(T((lamp[0], lamp[1] + 0.155, lamp[2])), (0.3, 0.02, 0.08)) + return b.done() + + +def mast(frame): + """Hero view and the EW inset's background: on the turret's roof a low sensor deck, a black radome ball to + the mech's right, a hooded optic head to its left, whip antennas behind.""" + t = PF.TURRET + b = put("Mast", frame @ T(t["at"]) @ T((0, -0.25, t["height"] + 0.06))) + k, d = b["khaki"], b["gunmetal"] + k.prism(T((0, 0, 0)), M.rect(1.5, 0.8, 0.12), 0.22, 0.04) + d.box(T((0, 0.41, 0.11)), (1.1, 0.04, 0.1)) + d.cylinder(T((0.32, 0.0, 0.3)), 0.1, 0.2, 12) + d.lathe(T((0.32, 0.0, 0.62)), [(0.0, -0.24)] + [(0.24 * math.cos(math.radians(a)), 0.24 * math.sin(math.radians(a))) for a in range(-80, 81, 20)] + [(0.0, 0.24)], 20) + d.box(T((-0.42, 0.0, 0.3)), (0.16, 0.16, 0.2)) + k.prism(F((-0.42, -0.22, 0.56), FRONT), M.rect(0.44, 0.34, 0.08), 0.46, 0.03) + b["glass"].cylinder(F((-0.42, 0.25, 0.56), FRONT), 0.11, 0.03, 16) + for x, y, h in ((-0.68, -0.32, 0.95), (0.05, -0.34, 1.25), (0.66, -0.3, 0.8), (0.9, 0.2, 0.55)): + d.rod((x, y, 0.2), (x, y, 0.2 + h), 0.014, 6) + d.cylinder(T((x, y, 0.26)), 0.035, 0.12, 8) + return b.done() + + +def shoulder(frame, sx): + """Hero view: the ribbed bearing between the hull's cheek and the pauldron, on the shoulder's axis.""" + b = put(f"Shoulder{'L' if sx < 0 else 'R'}", frame) + x0, x1, z = 1.55, abs(PF.PAULDRON_AT[0]) - 0.7, PF.JOINTS["shoulder_r"][2] - PF.WAIST[2] + at = F((sx * x0, PF.PAULDRON_AT[1], z), (sx, 0, 0), UP) + prof = [(0.0, 0.0), (0.66, 0.0)] + n = 5 + for i in range(n): + a = (x1 - x0) * i / n + prof += [(0.66, a), (0.66, a + 0.04), (0.56, a + 0.06), (0.56, a + (x1 - x0) / n - 0.02)] + prof += [(0.66, x1 - x0), (0.0, x1 - x0)] + b["gunmetal"].lathe(at, prof, 32) + return b.done() + + +def exchangers(frame): + """DORSAL SPINE & HEAT EXCHANGERS inset and the rear view: two tall boxes on the back, each a heavy frame with + rounded corners round a dark grille, a cap on top; between them the spine: a column of blocks, a plated ridge + down its middle, a pipe a side.""" + e = PF.EXCHANGER + z0, z1 = e["z"] + h, w, dp = z1 - z0, e["width"], e["depth"] + import hardpoint as H + b = put("Exchangers", frame) + for s in (-1, 1): + back = F((s * e["x"], e["y"] + 0.5 * dp - dp, 0.5 * (z0 + z1)), (0, -1, 0), UP) # on the rear face, z out of the back + solid, cut = M.Geo(), M.Geo() + solid.prism(back @ T((0, 0, -dp)), M.rect(w, h, 0.16), dp, 0.05) + cut.prism(back @ T((0, 0, -0.14)), M.rect(w - 0.3, h - 0.34, 0.1), 0.3, 0.0) + H.drilled(b["khaki"], solid, cut) + g = b["gunmetal"] + g.box(back @ T((0, 0, -0.16)), (w - 0.28, h - 0.32, 0.04)) + nb = 13 + for i in range(nb): + g.box(back @ T(((i - (nb - 1) / 2) * (w - 0.36) / nb, 0, -0.1)), (0.022, h - 0.36, 0.06)) + for j in range(5): + g.box(back @ T((0, (j - 2) * (h - 0.4) / 5, -0.075)), (w - 0.32, 0.03, 0.03)) + b["khaki"].prism(T((s * e["x"], e["y"] - 0.05, z1)), M.rect(w * 0.62, dp * 0.6, 0.06), 0.14, 0.04) + g.box(T((s * e["x"], e["y"], z0 - 0.12)), (w * 0.7, dp * 0.7, 0.3)) + g, k = b["gunmetal"], b["khaki"] + y = e["y"] + 0.05 + g.box(T((0, y + 0.2, 0.5 * (z0 + z1) - 0.2)), (0.85, 0.5, h - 0.5)) + for i in range(5): + zc = z0 + 0.35 + i * (h - 0.9) / 4 + k.hull([(0.2, y - 0.12, zc - 0.24), (0.2, y - 0.12, zc + 0.24), (0.13, y - 0.3, zc - 0.17), (0.13, y - 0.3, zc + 0.2)], mirror=True) + g.box(T((0, y - 0.02, zc + 0.29)), (0.6, 0.3, 0.06)) + for s in (-1, 1): + g.rod((s * 0.33, y - 0.12, z0 + 0.1), (s * 0.33, y - 0.12, z1 - 0.3), 0.07, 12) + for i in range(6): + g.cylinder(T((s * 0.33, y - 0.12, z0 + 0.3 + i * (h - 0.8) / 5)), 0.095, 0.08, 12) + return b.done() + + +def abdomen(frame): + """Hero view, under the band: a ribbed column down to the waist ring, an armoured pod a side, a hose loop a side.""" + b = put("Abdomen", frame) + g, k = b["gunmetal"], b["khaki"] + foot = PF.FOOT_RING[0][2] + for i in range(5): + z = 0.02 + i * (foot - 0.05) / 5 + g.box(T((0, 0.25, z + 0.04)), (1.15 - 0.04 * i, 1.5, 0.07)) + g.box(T((0, 0.25, z + 0.1)), (0.95, 1.35, 0.06)) + for s in (-1, 1): + k.hull([(s * 0.62, 1.0, 0.52), (s * 1.1, 0.85, 0.5), (s * 1.18, 0.5, 0.2), (s * 0.66, 1.08, 0.12), (s * 1.0, 0.95, 0.02), (s * 0.7, 0.6, -0.08), (s * 1.15, 0.45, -0.05), (s * 0.75, 0.55, 0.55), (s * 1.12, 0.4, 0.5)]) + path = [(s * 1.25, 0.55, foot - 0.05), (s * 1.6, 0.75, 0.2), (s * 1.45, 0.8, -0.35), (s * 0.95, 0.75, -0.5)] + for a, c in zip(path, path[1:]): + b["rubber"].rod(a, c, 0.06, 8) + return b.done() + + +# --- the lower body ---------------------------------------------------------------------------------------------------- + +def pelvis(): + """PELVIS & HIP ASSEMBLY inset: the hip beam; in front a long shield (the codpiece) under a centre block, a + hexagonal wing plate a side; a seat plate behind.""" + hz = PF.JOINTS["hip_r"][2] + b = put("Pelvis", T((0, PF.JOINTS["hip_r"][1] + 0.05, hz))) + g, k = b["gunmetal"], b["khaki"] + g.hull([(0.95, 0.6, 0.45), (0.95, -0.6, 0.45), (0.95, 0.7, -0.35), (0.95, -0.65, -0.35), (0.6, 0.75, 0.6), (0.6, -0.7, 0.6), (0.55, 0.6, -0.75), (0.55, -0.5, -0.75)], mirror=True) + k.hull([(0.5, 0.78, 0.25), (0.42, 0.74, -1.0), (0.28, 0.76, -1.3), (0.4, 1.05, 0.1), (0.34, 1.12, -0.85), (0.22, 1.0, -1.2), (0.3, 0.95, 0.4)], mirror=True) # the codpiece + k.hull([(0.42, 0.75, 0.3), (0.42, 0.75, 0.82), (0.3, 1.0, 0.36), (0.3, 0.98, 0.74), (0.2, 1.06, 0.55)], mirror=True) # the centre block over it + g.box(T((0, 1.06, -0.55)), (0.34, 0.1, 0.3)) + for s in (-1, 1): + k.hull(sided([(0.5, 0.74, 0.2), (0.5, 0.74, 0.75), (1.0, 0.7, 0.95), (1.3, 0.62, 0.7), (1.25, 0.62, 0.3), (0.85, 0.7, 0.05), + (0.6, 0.9, 0.3), (0.6, 0.9, 0.7), (1.0, 0.86, 0.82), (1.18, 0.8, 0.66), (1.15, 0.8, 0.36), (0.85, 0.86, 0.18)], s)) # the wings + k.hull([(0.6, -0.68, 0.5), (0.5, -0.68, -0.6), (0.45, -0.95, 0.3), (0.38, -0.92, -0.45), (0.3, -0.75, -0.85)], mirror=True) # the seat plate + return b.done() + + +def hip(sx): + """PELVIS & HIP ASSEMBLY inset: the black ribbed drum between the hip beam and the thigh, on the hip's axis.""" + j = PF.JOINTS["hip_r"] + b = put(f"Hip{'L' if sx < 0 else 'R'}", F((sx * 0.9, j[1], j[2]), (sx, 0, 0), UP)) + prof, n, L = [(0.0, 0.0), (0.56, 0.0)], 6, 0.75 + for i in range(n): + a = L * i / n + prof += [(0.56, a + 0.02), (0.6, a + 0.05), (0.56, a + 0.08), (0.48, a + 0.1)] + prof += [(0.5, L), (0.0, L)] + b["rubber"].lathe(Matrix.Identity(4), prof, 32) + b["machine"].lathe(T((0, 0, L)), [(0.0, 0.0), (0.4, 0.0), (0.4, 0.5), (0.0, 0.5)], 24) + return b.done() + + +def thigh_points(sx): + t = PF.THIGH_SHIELD + top, bot = t["top"], t["bottom"] + outline = [(-0.42, top - 0.4), (-0.1, top), (0.62, top), (0.92, top - 0.5), (0.92, bot + 0.55), (0.55, bot), (-0.25, bot), (-0.42, bot + 0.5)] + cu, cz = 0.22, 0.5 * (top + bot) + pts = [] + for y, k in ((0.88, 0.8), (0.6, 1.0), (-0.4, 1.0), (-0.62, 0.78)): + pts += [(cu + (u - cu) * k, y, cz + (z - cz) * k) for u, z in outline] + return sided(pts, sx) + + +def thigh(sx, plates=True): + """Hero and rear views: the thigh as one deep hexagonal block from above the hip's axis down to the knee: a + front shield in two plates (the upper carries the mark), an outer plate, a rear plate; its inner face open.""" + s = "L" if sx < 0 else "R" + H_, K_ = (Vector(PF.JOINTS[f"{k}_{s.lower()}"]) for k in ("hip", "knee")) + frame = limb(H_, K_) + solid = mass(f"Thigh{s}.mass", thigh_points(sx), frame) + t = PF.THIGH_SHIELD + mid = 0.5 * (t["top"] + t["bottom"]) + 0.35 + specs = [("FrontUp", band("y", 0.62) + band("z", mid + 0.02), 0.15, 0.16, 0.05), + ("FrontLow", band("y", 0.62) + band("z", None, mid - 0.02), 0.08, 0.16, 0.05), + ("Outer", out(sx, 0.55) + band("y", -0.38, 0.58), 0.10, 0.14, 0.05), + ("Top", band("z", t["top"] - 0.45) + band("y", -0.38, 0.58) + out(sx, None, 0.51), 0.05, 0.1, 0.04), + ("Rear", band("y", None, -0.42), 0.10, 0.14, 0.05)] + armour(f"Thigh{s}", solid, specs, plates=plates) + b = put(f"Thigh{s}.frame", frame) + L = (H_ - K_).length + b["gunmetal"].box(T((0, 0, -0.5 * L)), (0.6, 0.7, L)) + b.done() + return frame + + +def knee(sx): + """KNEE & LEG DETAIL inset: the joints library's kneecap_bisector, at this knee's bend: the kneecap on its own + ring at half the bend, the pin's disc at the side.""" + import jointlib as J + import joints + s = "l" if sx < 0 else "r" + H_, K_, A_ = (Vector(PF.JOINTS[f"{k}_{s}"]) for k in ("hip", "knee", "ankle")) + frame = limb(H_, K_) + frame.translation = K_ + down = frame.to_3x3().inverted() @ (A_ - K_).normalized() + angle = math.degrees(math.atan2(down.y, -down.z)) + rig = J.Rig(f"Knee{s.upper()}", frame, -95.0, 0.0) + joints.kneecap_bisector(rig, angle, r=0.5, cap=(1.15, 1.25), disc=0.34) + objs = rig.done() + for o in objs: # the bench's limb stubs are this build's thigh and shin + if o.get("link") in ("root", "shin") and o.get("mat") == "khaki": + bpy.data.objects.remove(o, do_unlink=True) + print(f"KNEE {s}: bend {angle:.1f}", flush=True) + return angle + + +def shin(sx, plates=True): + """Hero view and KNEE & LEG DETAIL: the shin as a block that widens to mid-height, a guard rising over the + knee at its top; front in two plates, an outer and an inner plate; behind, open to the calf's rams.""" + s = "L" if sx < 0 else "R" + K_, A_ = (Vector(PF.JOINTS[f"{k}_{s.lower()}"]) for k in ("knee", "ankle")) + frame = limb(K_, A_) + L = (K_ - A_).length + hw = 0.5 * PF.SHIN["width"] + outline = [(-0.6 * hw, -0.45), (0.0, -0.2), (0.6 * hw, -0.45), (hw, -0.5 * L), (0.8 * hw, -L + 0.3), (-0.8 * hw, -L + 0.3), (-hw, -0.5 * L)] + cz = -0.55 * L + pts = [] + for y, k in ((0.82, 0.78), (0.55, 1.0), (-0.3, 1.0), (-0.55, 0.8)): + pts += [(u * k, y, cz + (z - cz) * k) for u, z in outline] + solid = mass(f"Shin{s}.mass", sided(pts, sx), frame) + specs = [("FrontUp", band("y", 0.58) + band("z", cz + 0.25), 0.14, 0.16, 0.05), + ("FrontLow", band("y", 0.58) + band("z", None, cz + 0.21), 0.07, 0.16, 0.05), + ("Outer", out(sx, 0.3) + band("y", -0.28, 0.54), 0.09, 0.14, 0.05), + ("Inner", out(sx, None, -0.3) + band("y", -0.28, 0.54), 0.06, 0.12, 0.04)] + armour(f"Shin{s}", solid, specs, plates=plates) + b = put(f"Shin{s}.frame", frame) + g = b["gunmetal"] + g.box(T((0, -0.1, -0.5 * L)), (0.6, 0.7, L)) + for x in (-0.3, 0.3): + g.rod((x, -0.62, -0.55), (x, -0.7, -L + 0.45), 0.11, 12) + b["steel"].rod((x, -0.7, -L + 0.45), (x, -0.62, -L + 0.05), 0.06, 12) + g.cylinder(F((x, -0.6, -0.5), (1, 0, 0)), 0.14, 0.2, 12) + b["khaki"].hull([(0.4, -0.5, -0.9), (0.4, -0.5, -1.7), (0.3, -0.78, -1.05), (0.3, -0.78, -1.55)], mirror=True) + b.done() + return frame + + +def foot(sx): + """FOOT & ANKLE inset: the ankle's disc on its pin; a block over it; three heavy toes fanned forward, each a + faceted wedge with a dark stepped tip; two shorter blocks behind.""" + s = "L" if sx < 0 else "R" + A_ = Vector(PF.JOINTS[f"ankle_{s.lower()}"]) + b = put(f"Foot{s}", T((A_.x, A_.y, 0.0))) + g, k = b["gunmetal"], b["khaki"] + az = A_.z + g.lathe(F((-0.72, 0, az), (1, 0, 0), UP), [(0, 0), (0.42, 0), (0.46, 0.06), (0.46, 1.38), (0.42, 1.44), (0, 1.44)], 28) + for x in (-0.78, 0.78): + b["machine"].cylinder(F((x, 0, az), (1, 0, 0), UP), 0.3, 0.08, 20) + k.hull([(0.6, 0.75, 0.4), (0.6, -0.55, 0.4), (0.48, 0.55, az + 0.25), (0.48, -0.4, az + 0.15), (0.66, 0.5, 0.75), (0.66, -0.45, 0.7), (0.3, 0.9, 0.7)], mirror=True) + g.box(T((0, 0, 0.3)), (1.3, 1.5, 0.5)) + tw, tl, th = PF.FOOT["toe"] + for i, a in enumerate((-36.0, 0.0, 36.0)): + to = Matrix.Rotation(math.radians(-a), 4, "Z") @ T((0, 0.5, 0)) + hw = 0.5 * tw + k.hull([to @ Vector(q) for q in both([(hw, 0.0, 0.05), (hw, 0.0, th + 0.12), (hw + 0.05, 0.6 * tl, 0.0), (hw + 0.02, 0.62 * tl, th), (hw * 0.5, 0.3 * tl, th + 0.2), + (hw - 0.02, tl, 0.0), (hw - 0.06, tl, 0.55 * th), (hw * 0.6, 0.8 * tl, 0.85 * th)])]) + g.hull([to @ Vector(q) for q in both([(hw - 0.06, tl - 0.05, 0.0), (hw - 0.1, tl - 0.05, 0.4 * th), (hw - 0.1, tl + 0.2, 0.0), (hw - 0.14, tl + 0.18, 0.24 * th)])]) + hw_, hl, hh = PF.FOOT["heel"] + for a in (142.0, -142.0): + to = Matrix.Rotation(math.radians(-a), 4, "Z") @ T((0, 0.45, 0)) + hw = 0.5 * hw_ + k.hull([to @ Vector(q) for q in both([(hw, 0.0, 0.05), (hw, 0.0, hh + 0.1), (hw + 0.04, 0.6 * hl, 0.0), (hw, 0.6 * hl, hh), (hw - 0.04, hl, 0.0), (hw - 0.08, hl, 0.5 * hh)])]) + return b.done() + + +# --- the arms ------------------------------------------------------------------------------------------------------------ + +def upper_arm(sx): + """Hero view: a short dark upper arm hanging from under the pauldron, a khaki block on its outer face, the + elbow's disc on its pin.""" + s = "l" if sx < 0 else "r" + S_, E_ = Vector(PF.JOINTS[f"shoulder_{s}"]), Vector(PF.JOINTS[f"elbow_{s}"]) + frame = limb(S_, E_) + L = (S_ - E_).length + b = put(f"UpperArm{s.upper()}", frame) + g, k = b["gunmetal"], b["khaki"] + g.box(T((0, 0, -0.5 * L)), (0.62, 0.72, L)) + for i in range(4): + g.box(T((0, 0, -0.25 - 0.22 * i)), (0.74, 0.84, 0.08)) + k.hull(sided([(0.34, 0.42, -0.25), (0.34, -0.42, -0.25), (0.5, 0.3, -0.5), (0.5, -0.3, -0.5), (0.36, 0.42, -L + 0.3), (0.36, -0.42, -L + 0.3), (0.52, 0.28, -L + 0.5), (0.52, -0.28, -L + 0.5)], sx)) + k.hull(sided([(-0.3, 0.38, -0.3), (0.3, 0.38, -0.3), (-0.3, 0.38, -L + 0.4), (0.3, 0.38, -L + 0.4), (-0.2, 0.52, -0.45), (0.2, 0.52, -0.45), (-0.2, 0.52, -L + 0.55), (0.2, 0.52, -L + 0.55)], sx)) + g.lathe(F((-0.5, 0, -L), (1, 0, 0), UP), [(0, 0), (0.4, 0), (0.44, 0.05), (0.44, 0.95), (0.4, 1.0), (0, 1.0)], 24) + for x in (-0.54, 0.54): + b["machine"].cylinder(F((x, 0, -L), (1, 0, 0), UP), 0.28, 0.08, 16) + return b.done() + + +def aim(a, b): + """A weapon's frame at a: its y along a to b, its z as near up as that leaves.""" + a, b = Vector(a), Vector(b) + y = (b - a).normalized() + x = y.cross(Vector((0, 0, 1))).normalized() + z = x.cross(y) + m = Matrix((x, y, z)).transposed().to_4x4() + m.translation = a + return m + + +def forearm_left(plates=True): + """LEFT FOREARM - MANIPULATOR & ENERGY inset and the hero view: a slab-sided housing from the elbow to the + wrist; under its end the open hand (the joints library's hand), beside the hand the emitter (the weapons + library's paladin_energy_emitter, class S).""" + import jointlib as J + import hands + import weapons_energy + E_, W_ = Vector(PF.JOINTS["elbow_l"]), Vector(PF.JOINTS["wrist_l"]) + frame = limb(E_, W_) + L = (E_ - W_).length + pts = [] + for z, k in ((-0.15, 0.7), (-0.5, 1.0), (-L + 0.2, 1.0), (-L - 0.1, 0.75)): + pts += [(u * k, y * k, z) for u, y in ((-0.38, 0.45), (0.38, 0.45), (0.46, 0.0), (0.38, -0.45), (-0.38, -0.45), (-0.46, 0.0))] + solid = mass("ForearmL.mass", pts, frame) + specs = [("Outer", out(-1, 0.16) + band("z", -L + 0.25, -0.52), 0.1, 0.14, 0.05), + ("Inner", out(-1, None, -0.16) + band("z", -L + 0.25, -0.52), 0.05, 0.12, 0.04), + ("Front", band("y", 0.3) + band("x", -0.14, 0.14) + band("z", -L + 0.25, -0.52), 0.12, 0.12, 0.04), + ("Cuff", band("z", None, -L + 0.2), 0.08, 0.14, 0.05), + ("Collar", band("z", -0.48), 0.06, 0.12, 0.04)] + armour("ForearmL", solid, specs, plates=plates) + z, y = frame.to_3x3() @ Vector((0, 0, 1)), frame.to_3x3() @ Vector((1, 0, 0)) # the hand hangs down the forearm, its palm inboard + m = Matrix((y.cross(z), y, z)).transposed().to_4x4() + m.translation = W_ - z * 0.25 + rig = J.Rig("HandL", m @ Matrix.Scale(1.55, 4), 0.0, 100.0) + hands.hand(rig, 30.0, plate="khaki") + rig.done() + side = frame.to_3x3() @ Vector((-1, 0, 0)) + at = aim(E_ + side * 0.8 - z * 0.7, W_ + side * 0.8 - z * 0.7) + put("Emitter", at, weapons_energy.paladin_energy_emitter, size="S") + return frame diff --git a/surfaces/blender/experiments/mechs/paladin_cameras.json b/surfaces/blender/experiments/mechs/paladin_cameras.json new file mode 100644 index 0000000..7eb593c --- /dev/null +++ b/surfaces/blender/experiments/mechs/paladin_cameras.json @@ -0,0 +1,575 @@ +{ + "hero": { + "C": [ + 4.024342939500392, + 38.96685007436571, + 1.9072178575925234 + ], + "R": [ + [ + -0.9746981483315451, + 0.22352328962396972, + 0.0009266254563114965 + ], + [ + 0.0974752331937773, + 0.42131371199054596, + 0.9016614303620656 + ], + [ + 0.2011519290309593, + 0.878938049628315, + -0.43244167972421166 + ] + ], + "f": 1428.1556207875658, + "c": [ + 379.2795454742095, + -289.172779334783 + ], + "box": [ + 0, + 0, + 352, + 510 + ], + "unit": null, + "names": [ + "waist", + "hip_r", + "hip_l", + "knee_r", + "knee_l", + "ankle_r", + "ankle_l", + "shoulder_r", + "shoulder_l", + "elbow_r", + "elbow_l", + "muzzle_r", + "wrist_l", + "lamp", + "visor", + "battery", + "ew" + ], + "rms": 12.503824875395983, + "rms_h": null, + "median": 7.83707312791194, + "worst": [ + "elbow_l", + 30.972341608815473 + ], + "left_out": 17.207337978826192, + "model": "free", + "tried": { + "upright": { + "rms": 15.620297640257816, + "left_out": 21.32540120099779, + "lens": 139.66883100426915 + }, + "rolled": { + "rms": 14.974012248700662, + "left_out": 21.67274860559036, + "lens": 174.4086105155622 + }, + "free": { + "rms": 12.503824875395983, + "left_out": 17.207337978826192, + "lens": 146.06137030781923 + } + }, + "lens": 146.06137030781923, + "lens_range": [ + 80.16017960876972, + 723.4467030862105 + ], + "azimuth": -6.025446714065794, + "elevation": -6.334591543633486, + "distance": 38.43252799014191, + "roll": 0.05888208961534556, + "twist": 0.0, + "horizon": [ + 396.0, + 395.77762721408243 + ], + "residuals": { + "waist": [ + -0.7279500592247814, + 10.954405924411674 + ], + "hip_r": [ + -14.087693857534646, + 6.480680858183348 + ], + "hip_l": [ + -8.969456183648958, + 6.292667085251026 + ], + "knee_r": [ + -11.94390550338153, + 1.864668154700496 + ], + "knee_l": [ + 6.506306031792747, + -4.368946902045934 + ], + "ankle_r": [ + 9.421799212615383, + 5.448228592607904 + ], + "ankle_l": [ + -3.858671269852721, + -0.13678529235318138 + ], + "shoulder_r": [ + 7.255114183885269, + 0.3298125139336321 + ], + "shoulder_l": [ + 14.999336444676885, + 9.44639582387498 + ], + "elbow_r": [ + -0.2876535584446174, + 1.0137284095269479 + ], + "elbow_l": [ + 28.309971424260993, + -12.563099247028504 + ], + "muzzle_r": [ + 11.583559472405625, + -14.306762221664428 + ], + "wrist_l": [ + -2.972803838292407, + -6.219218603053434 + ], + "lamp": [ + -6.6003118702379595, + -0.4639766611508094 + ], + "visor": [ + -0.12394333878961561, + -5.5928067596090045 + ], + "battery": [ + -0.2828812432254608, + -2.53789760560727 + ], + "ew": [ + -5.878745342355387, + 2.455803712783336 + ] + }, + "solved": { + "waist": [ + 0.0, + 0.25, + 6.65 + ], + "hip_r": [ + 1.55, + 0.05, + 5.55 + ], + "hip_l": [ + -1.55, + 0.05, + 5.55 + ], + "knee_r": [ + 1.75, + 0.8, + 3.7 + ], + "knee_l": [ + -1.75, + 0.8, + 3.7 + ], + "ankle_r": [ + 1.85, + 0.05, + 1.15 + ], + "ankle_l": [ + -1.85, + 0.05, + 1.15 + ], + "shoulder_r": [ + 2.95, + 0.5, + 8.55 + ], + "shoulder_l": [ + -2.95, + 0.5, + 8.55 + ], + "elbow_r": [ + 3.2, + 0.6, + 6.95 + ], + "elbow_l": [ + -3.0, + 0.45, + 7.05 + ], + "muzzle_r": [ + 3.35, + 3.4, + 4.15 + ], + "wrist_l": [ + -3.3, + 1.1, + 5.1 + ], + "lamp": [ + 0.0, + 2.55, + 7.9 + ], + "visor": [ + 0.0, + 1.75, + 9.46 + ], + "battery": [ + 3.1, + 1.55, + 10.45 + ], + "ew": [ + -3.1, + 2.21, + 8.9 + ] + } + }, + "rear": { + "C": [ + -17.06059734781936, + -37.309086271769914, + 0.715664445415914 + ], + "R": [ + [ + 0.7356762718996472, + -0.6720362795693844, + -0.08454384605857931 + ], + [ + -0.27147792296738843, + -0.4069104178950268, + 0.8721947312096122 + ], + [ + -0.6205482739522763, + -0.6187011804991445, + -0.4817973525703684 + ] + ], + "f": 1430.5298684287816, + "c": [ + 1056.1924449945607, + -386.7474563803904 + ], + "box": [ + 352, + 0, + 690, + 510 + ], + "unit": null, + "names": [ + "waist", + "hip_l", + "hip_r", + "knee_l", + "knee_r", + "ankle_l", + "ankle_r", + "shoulder_l", + "shoulder_r", + "elbow_l", + "elbow_r", + "wrist_l", + "exch_l", + "exch_r" + ], + "rms": 9.746732432371452, + "rms_h": null, + "median": 6.53279172590044, + "worst": [ + "elbow_r", + 28.07216576153325 + ], + "left_out": 14.292032696765954, + "model": "free", + "tried": { + "upright": { + "rms": 13.276686056223102, + "left_out": 16.982547497203164, + "lens": 246.9705786290606 + }, + "rolled": { + "rms": 12.192924736224214, + "left_out": 17.820335764607425, + "lens": 340.6074547222906 + }, + "free": { + "rms": 9.746732432371452, + "left_out": 14.292032696765954, + "lens": 152.36412799833175 + } + }, + "lens": 152.36412799833175, + "lens_range": [ + 83.61920636880411, + 306.82367527801887 + ], + "azimuth": 155.81890740538992, + "elevation": -7.0357865844790135, + "distance": 41.420948778771255, + "roll": -5.536515103731178, + "twist": 0.0, + "horizon": [ + 396.0, + 396.11660431497694 + ], + "residuals": { + "waist": [ + -7.232530105321189, + 1.0106966144215903 + ], + "hip_l": [ + -1.170900270320658, + 0.14134995309314036 + ], + "hip_r": [ + 0.943316560457788, + 0.45027252368879545 + ], + "knee_l": [ + 10.132840505881177, + 3.314762215229507 + ], + "knee_r": [ + 1.3475874092439426, + -1.494090960722474 + ], + "ankle_l": [ + 0.936318915695665, + 7.785132694588469 + ], + "ankle_r": [ + -8.093061030221179, + -5.4247614212619055 + ], + "shoulder_l": [ + -8.63320802916644, + -3.653120531304353 + ], + "shoulder_r": [ + -1.9833802668287035, + 6.623709784568632 + ], + "elbow_l": [ + 3.447491235632924, + -3.761308019024227 + ], + "elbow_r": [ + 14.431603509560318, + -24.07852384773298 + ], + "wrist_l": [ + -0.35430721475154314, + -2.768112637974582 + ], + "exch_l": [ + 1.9816922216643889, + 5.823347500832654 + ], + "exch_r": [ + 1.5775138889416667, + 1.4725583657973402 + ] + }, + "solved": { + "waist": [ + 0.0, + 0.25, + 6.65 + ], + "hip_l": [ + -1.55, + 0.05, + 5.55 + ], + "hip_r": [ + 1.55, + 0.05, + 5.55 + ], + "knee_l": [ + -1.75, + 0.8, + 3.7 + ], + "knee_r": [ + 1.75, + 0.8, + 3.7 + ], + "ankle_l": [ + -1.85, + 0.05, + 1.15 + ], + "ankle_r": [ + 1.85, + 0.05, + 1.15 + ], + "shoulder_l": [ + -2.95, + 0.5, + 8.55 + ], + "shoulder_r": [ + 2.95, + 0.5, + 8.55 + ], + "elbow_l": [ + -3.0, + 0.45, + 7.05 + ], + "elbow_r": [ + 3.2, + 0.6, + 6.95 + ], + "wrist_l": [ + -3.3, + 1.1, + 5.1 + ], + "exch_l": [ + -1.15, + -1.25, + 8.7 + ], + "exch_r": [ + 1.15, + -1.25, + 8.7 + ] + } + }, + "side": { + "C": [ + 87.84896913275175, + 1.1078440594982277, + 1.5121479421322626 + ], + "R": [ + [ + 3.061616997868383e-16, + 1.0, + 0.0 + ], + [ + 0.04269467483038552, + -1.3071474217917174e-17, + 0.9990881666505352 + ], + [ + 0.9990881666505352, + -3.0588253133864385e-16, + -0.04269467483038552 + ] + ], + "f": 3533.3698454010014, + "c": [ + 787.5, + 255.0 + ], + "box": [ + 690.0, + 0.0, + 885.0, + 510.0 + ], + "lens": 652.3144329971079, + "lens_band": [ + 131.7000126597741, + 4000.0 + ], + "lens_at_bound": null, + "rms": 14.094214065791983, + "median": 13.798717017990711, + "worst": [ + "waist", + 19.58426841132626 + ], + "left_out": 22.521663328055052, + "model": "square", + "tried": { + "square": { + "rms": 14.094214065791983, + "left_out": 22.521663328055052, + "lens": 652.3144329971079 + } + }, + "azimuth": -90.06986790263996, + "elevation": -3.1181641567690845, + "distance": 85.9512858974804, + "roll": 0.0, + "twist": 0.0, + "residuals": { + "shoulder_r": [ + -4.731279891913459, + 3.5896813767305105 + ], + "elbow_r": [ + 8.340597978301957, + 12.218021141215786 + ], + "muzzle_r": [ + 13.307399580006859, + -10.363655441629703 + ], + "knee_r": [ + -10.131262607705366, + 6.141266354327968 + ], + "ankle_r": [ + -9.010277146131102, + -9.097108713927128 + ], + "battery": [ + 5.868489342415273, + -3.650411055520294 + ], + "waist": [ + -11.94870437287966, + -15.516830636969587 + ], + "lamp": [ + 10.377988705854591, + 14.39636356282466 + ] + }, + "lens_range": [ + 131.7000126597741, + 4000.0 + ] + } +} \ No newline at end of file diff --git a/surfaces/blender/experiments/mechs/paladin_form.py b/surfaces/blender/experiments/mechs/paladin_form.py new file mode 100644 index 0000000..ef57620 --- /dev/null +++ b/surfaces/blender/experiments/mechs/paladin_form.py @@ -0,0 +1,129 @@ +"""PALADIN as numbers (concept sheet images/27.webp): the skeleton, the marks on the sheet's three views, the solved +cameras, the masses and where they split into plates. Plain Python and numpy; no Blender, no Pillow. paladin.py +builds from it, paladin_sheets.py scores against it. + + python paladin_form.py solve solves the hero, rear and side cameras from JOINTS, LANDMARKS and VIEWS' marks + (camsolve, the horizon held) and writes paladin_cameras.json beside this file + +Frames. World: x to the mech's right, y forward, z up, metres, origin on the ground under the hips' middle. Torso: +the same axes at WAIST (the slew ring's top). The sheet's pixels are the 1024-wide sheet's own. + +The character line (BELT) is the chest's knuckle: the hard edge where the sloped glacis under the turret breaks to +the hull's upright band, a shallow chevron in plan with the amber lamp at its stem, carried outboard by the +pauldrons' own knuckles at the same height and repeated above by the turret's visor band. It was built first, and +every mass above the waist is fitted round it. +""" +import json +import math +import os +import sys +from pathlib import Path + +HERE = Path(__file__).resolve().parent +HEIGHT = 11.0 # to the battery's top; the antennas stand above it +WAIST = (0.0, 0.25, 6.65) # the torso stands a little forward of the hips (side view: the battery's middle between knee and ankle) + +# The skeleton, world. hip is the thigh's head on the hip drum's axis; muzzle_r the gatling's muzzle. +JOINTS = { + "waist": (0.0, 0.25, 6.65), + "hip_r": (1.55, 0.05, 5.55), "hip_l": (-1.55, 0.05, 5.55), + "knee_r": (1.75, 0.80, 3.70), "knee_l": (-1.75, 0.80, 3.70), + "ankle_r": (1.85, 0.05, 1.15), "ankle_l": (-1.85, 0.05, 1.15), + "shoulder_r": (2.95, 0.5, 8.55), "shoulder_l": (-2.95, 0.5, 8.55), + "elbow_r": (3.20, 0.6, 6.95), "elbow_l": (-3.0, 0.45, 7.05), + "muzzle_r": (3.35, 3.4, 4.15), "wrist_l": (-3.3, 1.1, 5.1), +} +# Landmarks that are not joints, world: they hold the cameras where the joints are nearly in one plane. +LANDMARKS = { + "lamp": (0.0, 0.25 + 2.3, 6.65 + 1.25), # the amber lamp on the belt's stem + "visor": (0.0, 0.25 + 1.5, 6.65 + 2.81), # the middle of the turret's visor band + "battery": (3.1, 0.25 + 1.3, 10.45), # the middle of the battery's face + "ew": (-3.1, 0.25 + 1.96, 6.65 + 2.25), # the middle of the EW module's lower face + "exch_l": (-1.15, 0.25 - 1.5, 8.7), "exch_r": (1.15, 0.25 - 1.5, 8.7), # the middles of the heat exchangers' grilles +} +HORIZON = 396 # the sheet row the soldiers' heads stand on, in all three views: the cameras' eye is a soldier's +VIEWS = { + "hero": {"box": [0, 0, 352, 510], "label": "FRONT 3/4", + "marks": {"waist": (197, 181), "hip_r": (146, 230), "hip_l": (262, 233), "knee_r": (132, 312), "knee_l": (256, 320), + "ankle_r": (96, 425), "ankle_l": (262, 430), "shoulder_r": (80, 110), "shoulder_l": (297, 110), + "elbow_r": (72, 173), "elbow_l": (284, 191), "muzzle_r": (46, 300), "wrist_l": (330, 262), + "lamp": (216, 128), "visor": (209, 76), "battery": (90, 30), "ew": (336, 92)}}, + "rear": {"box": [352, 0, 690, 510], "label": "REAR 3/4", + "marks": {"waist": (549, 187), "hip_l": (482, 233), "hip_r": (598, 233), "knee_l": (441, 317), "knee_r": (586, 317), + "ankle_l": (446, 433), "ankle_r": (606, 433), "shoulder_l": (440, 110), "shoulder_r": (648, 112), + "elbow_l": (419, 173), "elbow_r": (635, 205), "wrist_l": (389, 262), "exch_l": (530, 85), "exch_r": (615, 95)}}, + "side": {"box": [690, 0, 885, 510], "label": "RIGHT SIDE", + "marks": {"shoulder_r": (767, 110), "elbow_r": (758, 167), "muzzle_r": (870, 306), "knee_r": (785, 310), "ankle_r": (753, 430), + "battery": (800, 38), "waist": (765, 215), "lamp": (835, 135)}}, +} + +# --- the character line ------------------------------------------------------------------------------------------ +# The belt, torso frame: (x, y) of the knuckle's right half from the stem outboard and round the flank, and its z. +# The belt, torso frame: the knuckle's right half from the stem outboard and round the flank. It is not level: it +# falls from the shoulders to the stem (the hero camera, a soldier's eye, draws the stem lowest though it is nearest; +# the side view draws the prow as a beak). +BELT = [(0.0, 2.2, 1.45), (0.42, 2.12, 1.5), (1.75, 0.95, 2.38), (1.92, 0.25, 2.42), (1.92, -0.55, 2.42), (1.3, -0.95, 2.42), (0.0, -1.0, 2.42)] +# The band's foot under it: the band is shallow at the stem and deep at the shoulders, and leans out to the knuckle. +FOOT_RING = [(0.0, 2.0, 1.0), (0.4, 1.92, 1.02), (1.6, 0.85, 1.4), (1.75, 0.2, 1.42), (1.75, -0.5, 1.42), (1.2, -0.85, 1.42), (0.0, -0.9, 1.42)] +# The glacis rises from the belt to the turret ring's deck: steep down the middle, nearly flat over the shoulders. +DECK_Z = 2.56 +DECK = [(0.0, 0.95), (0.95, 0.85), (1.45, 0.25), (1.45, -0.5), (0.9, -0.85), (0.0, -0.85)] +# The hull under the band: a keel tapering to the waist. +KEEL = [(0.8, [(0.0, 1.3), (1.0, 0.9), (1.2, 0.0), (1.0, -0.6), (0.0, -0.8)])] +# The belt as the sheet's hero view draws it (the sheet's pixels), right end to stem to left end: the traced line. +BELT_TRACE = [(122, 75), (183, 101), (216, 129), (270, 106)] +VISOR_TRACE = [(169, 73), (205, 80), (250, 76)] # the visor band's lower lip +PAULDRON_TRACE = {"r": [(48, 56), (38, 88), (62, 122), (108, 98)], # the right pauldron's knuckle: outer top, outer corner, lower tip, inner + "l": [(268, 70), (318, 74), (338, 140), (296, 124)]} +THIGH_TRACE = {"r": [(128, 196), (166, 215), (172, 262), (150, 290), (100, 276), (96, 215)]} # the right thigh shield's outline + +# --- masses -------------------------------------------------------------------------------------------------------- +# The turret: a low cap of clipped corners on the deck, the visor band across its brow. Torso frame. +TURRET = {"at": (0.0, 0.25, 2.56), "half": 1.3, "front": 1.3, "rear": 0.85, "height": 0.62, "clip": 0.45, "crown": 0.78} +# The left pauldron, in its own frame at PAULDRON_AT (torso frame; outboard is -x), mirrored for the right: a slab +# whose roof falls outboard from the crown to a knuckle at the belt's height, undercut below it. +PAULDRON_AT = (-3.1, 0.3, 1.85) +PAULDRON = {"half_y": 1.35, "crown": (0.95, 1.25), "knuckle": (-1.0, -0.15), "foot": (-0.55, -1.05), "inner_foot": (0.75, -0.9), "nose": 0.3} +EXCHANGER = {"x": 1.15, "y": -1.15, "z": (0.75, 3.3), "width": 1.25, "depth": 0.7} +# The legs' armour, each in a frame along its link (z up the link, y forward, x outboard), lengths in metres. +THIGH_SHIELD = {"width": 1.75, "top": 0.7, "bottom": -2.0, "t": 0.4} # rises above the hip's axis, as the hero view has it +SHIN = {"width": 1.45, "depth": 1.5} +FOOT = {"toes": 3, "toe": (0.62, 1.15, 0.62), "heel": (0.55, 0.8, 0.5)} + + +def world(name): + return (JOINTS | LANDMARKS)[name] + + +def cameras(): + return json.loads((HERE / "paladin_cameras.json").read_text(encoding="utf-8")) + + +def solve(): + """The three cameras, by camsolve (this branch's solver) and not brokkr_reference.core: every view holds soldiers + standing at different depths whose heads lie on one row of the sheet (HORIZON), so the camera stands at a + soldier's eye height, and only camsolve can hold a horizon. Without it the hero camera came out 5.5 m up and + drew the feet from above.""" + import camsolve + out = {} + for tag, view in VIEWS.items(): + names = list(view["marks"]) + W, Px = {k: list(world(k)) for k in names}, {k: list(view["marks"][k]) for k in names} + if tag == "side": # square-on along x: camsolve's square looks along y only, brokkr_reference's along any axis + surface = Path(os.environ["BROKKR_SURFACE"]) if os.environ.get("BROKKR_SURFACE") else HERE.parents[1] + sys.path.insert(0, str(surface / "brokkr_reference")) # core.py alone: the package's __init__ wants bpy + import core + cam = core.solve(W, Px, view["box"], model="square") + cam["lens_range"] = cam["lens_band"] + else: + cam = camsolve.solve(W, Px, view["box"], horizon=HORIZON) + out[tag] = cam + print(f"CAMERA {tag}: {cam['model']}, lens {cam['lens']:.0f} mm (range {cam['lens_range'][0]:.0f}..{cam['lens_range'][1]:.0f}), azimuth {cam['azimuth']:.1f}, elevation {cam['elevation']:.1f}, " + f"distance {cam['distance']:.1f} m, eye {cam['C'][2]:.2f} m up, rms {cam['rms']:.1f} px, left-out {cam['left_out']:.1f} px, worst {cam['worst'][0]} {cam['worst'][1]:.1f}") + print(" " + ", ".join(f"{k} {r[0]:+.0f},{r[1]:+.0f}" for k, r in cam["residuals"].items())) + (HERE / "paladin_cameras.json").write_text(json.dumps(out, indent=1), encoding="utf-8") + return out + + +if __name__ == "__main__" and "solve" in sys.argv: + solve() diff --git a/surfaces/blender/experiments/mechs/paladin_sheets.py b/surfaces/blender/experiments/mechs/paladin_sheets.py new file mode 100644 index 0000000..dd72902 --- /dev/null +++ b/surfaces/blender/experiments/mechs/paladin_sheets.py @@ -0,0 +1,170 @@ +"""Comparison sheets for PALADIN against concept sheet 27. Plain Python (Pillow, numpy); no Blender. +usage: python paladin_sheets.py [stage] (MECH_OUT, MECH_CONCEPTS as compare.py; stage defaults to full) +Reads MECH_OUT/paladin/ (paladin.py's renders); writes under MECH_OUT/compare/: + paladin_camera.png the three solved cameras: the marks (yellow) against the build's points (cyan) + paladin_flowlines.png the lines traced on the hero view (red) | our built edges at the same camera (cyan) | scores + paladin_vs_concept.png hero, rear and side: concept | ours | the two laid over each other; the silhouettes' overlap + paladin_character.png the belt, close: concept | ours with the traced belt and our edges | ours + paladin_components.png each inset of the sheet beside our part +Scores go to MECH_OUT/paladin/paladin_scores.json.""" +import json, os, sys +from pathlib import Path + +import numpy as np +from PIL import Image, ImageDraw, ImageFont + +import fitshell +import paladin_form as PF + +stage = sys.argv[1] if len(sys.argv) > 1 else "full" +out_root = Path(os.environ["MECH_OUT"]) +src, dst = out_root / "paladin", out_root / "compare" +dst.mkdir(parents=True, exist_ok=True) +sheet = Image.open(Path(os.environ["MECH_CONCEPTS"]) / "27.webp").convert("RGB") +cams = PF.cameras() +report = json.loads((src / f"paladin_report_{stage}.json").read_text(encoding="utf-8")) +try: + font, mono = ImageFont.truetype("arial.ttf", 22), ImageFont.truetype("consola.ttf", 20) +except OSError: + font = mono = ImageFont.load_default() +RED, CYAN, YELLOW, BG = (255, 50, 40), (0, 230, 255), (255, 230, 0), (24, 24, 24) +FIG = 460.0 # the figure's height in the hero view, in the sheet's pixels + + +def fit(img, h): + return img.resize((max(1, round(img.width * h / img.height)), h), Image.LANCZOS) + + +def label(img, text): + out = Image.new("RGB", (img.width, img.height + 34), BG) + out.paste(img, (0, 34)) + ImageDraw.Draw(out).text((8, 5), text, fill=(235, 235, 235), font=font) + return out + + +def row(images, gap=8): + out = Image.new("RGB", (sum(i.width for i in images) + gap * (len(images) - 1), max(i.height for i in images)), BG) + x = 0 + for i in images: + out.paste(i, (x, 0)) + x += i.width + gap + return out + + +def stack(rows, gap=8): + out = Image.new("RGB", (max(r.width for r in rows), sum(r.height for r in rows) + gap * (len(rows) - 1)), BG) + y = 0 + for r in rows: + out.paste(r, (0, y)) + y += r.height + gap + return out + + +def in_box(img, box, lines=(), segs=(), marks=(), width=3): + img = img.copy() + k = img.width / (box[2] - box[0]) + d = ImageDraw.Draw(img) + for u0, v0, u1, v1 in segs: + d.line([((u0 - box[0]) * k, (v0 - box[1]) * k), ((u1 - box[0]) * k, (v1 - box[1]) * k)], fill=CYAN, width=max(1, width // 2)) + for pts in lines: + d.line([((x - box[0]) * k, (y - box[1]) * k) for x, y in pts], fill=RED, width=width) + for (x, y), colour in marks: + x, y = (x - box[0]) * k, (y - box[1]) * k + d.ellipse([x - 6, y - 6, x + 6, y + 6], outline=colour, width=3) + return img + + +def text_panel(lines, w, h): + img = Image.new("RGB", (w, h), BG) + ImageDraw.Draw(img).text((14, 14), "\n".join(lines), fill=(235, 235, 235), font=mono, spacing=7) + return img + + +def render(stem, h=None, size=None): + img = Image.open(src / stem).convert("RGBA") + back = Image.new("RGBA", img.size, (150, 156, 164, 255)) + img = Image.alpha_composite(back, img).convert("RGB") + return img.resize(size, Image.LANCZOS) if size else fit(img, h) + + +def alpha(stem, size): + return np.asarray(Image.open(src / stem).convert("RGBA").resize(size, Image.LANCZOS))[:, :, 3] > 127 + + +scores = {"stage": stage, "height": report["height"], "width": report["width"], "frozen": report["frozen"]} +H = 1000 + +# camera +cells = [] +for tag, cam in cams.items(): + box, marks, proj = cam["box"], PF.VIEWS[tag]["marks"], report["cameras"][tag]["projected"] + pts = [(tuple(marks[k]), YELLOW) for k in marks] + [(tuple(proj[k]), CYAN) for k in proj] + c = fit(sheet.crop(tuple(box)), H) + cells.append(label(in_box(c, box, marks=pts), f"{PF.VIEWS[tag]['label']}: marks (yellow), build (cyan); rms {cam['rms']:.1f} px, lens {cam['lens']:.0f} mm, eye {cam['C'][2]:.1f} m")) + cells.append(label(in_box(render(f"{stage}_{tag}.png", size=c.size), box, marks=pts), "ours")) + scores[f"camera_{tag}"] = {"rms": round(cam["rms"], 2), "left_out": round(cam["left_out"], 2), "lens": round(cam["lens"], 1), "lens_range": [round(v, 1) for v in cam["lens_range"]], "eye": round(cam["C"][2], 2), "model": cam["model"]} +row(cells).save(dst / "paladin_camera.png") + +# vs concept +rows = [] +for tag, cam in cams.items(): + box = cam["box"] + c = fit(sheet.crop(tuple(box)), H) + o = render(f"{stage}_{tag}.png", size=c.size) + size = (int(box[2] - box[0]), int(box[3] - box[1])) + rows.append(row([label(c, f"sheet 27, {PF.VIEWS[tag]['label']}"), label(o, f"ours, at the solved {tag} camera"), label(Image.blend(c, o, 0.5), "the two laid over each other")])) +stack([row(rows[:2]), rows[2]]).save(dst / "paladin_vs_concept.png") + +# flow lines and the character line +edges_path = src / f"{stage}_edges_hero.json" +if edges_path.exists(): + edges = json.loads(edges_path.read_text(encoding="utf-8")) + segs = [e["seg"] for e in edges] + traces = {"belt": PF.BELT_TRACE, "visor": PF.VISOR_TRACE, "pauldron_r": PF.PAULDRON_TRACE["r"], "pauldron_l": PF.PAULDRON_TRACE["l"], "thigh_r": PF.THIGH_TRACE["r"] + PF.THIGH_TRACE["r"][:1]} + own = {"belt": ("Torso.",), "visor": ("Turret.", "Visor"), "pauldron_r": ("PauldronR.",), "pauldron_l": ("PauldronL.",), "thigh_r": ("ThighR.",)} + fl = {} + for k, pts in traces.items(): + mine = [e["seg"] for e in edges if e["object"].startswith(own[k])] + fl[k] = {"own": fitshell.along(pts, mine, FIG) if mine else None, "all": fitshell.along(pts, segs, FIG)} + scores["flow"] = fl + box = cams["hero"]["box"] + c = fit(sheet.crop(tuple(box)), H) + o = render(f"{stage}_hero.png", size=c.size) + body = ["traced lines against our built edges at the", "solved hero camera (fitshell.along):", "on: share of the line with a built edge", " within 1% of the figure's height,", " running its way", "run: longest unbroken share", + "off: mean distance, % of the height", "own: the part's own edges; all: any edge", "", f"{'line':11s} {'':4s} {'on':>5s} {'run':>5s} {'off':>5s}"] + for k, v in fl.items(): + for which in ("own", "all"): + if v[which]: + body.append(f"{k:11s} {which:4s} {v[which]['on']:5.2f} {v[which]['run']:5.2f} {v[which]['off']:5.2f}") + row([label(in_box(c, box, lines=traces.values(), width=4), "sheet 27, hero: the traced lines (red); the belt is the character line"), + label(in_box(o, box, lines=traces.values(), segs=segs, width=4), "ours at the solved hero camera: the traces (red), our built edges (cyan)"), text_panel(body, 560, H + 34)]).save(dst / "paladin_flowlines.png") + cb = [20, 0, 352, 200] + ours = render(f"{stage}_character.png", h=800) + crop = sheet.crop(tuple(cb)).resize(ours.size, Image.LANCZOS) + lines = [PF.BELT_TRACE, PF.VISOR_TRACE] + torso = [e["seg"] for e in edges if e["object"].startswith(("Torso.", "Turret.", "Pauldron"))] + v = fl["belt"]["own"] + note = f"belt on the hull's edges: on {v['on']:.2f}, run {v['run']:.2f}, off {v['off']:.2f}% H" if v else "" + stack([row([label(in_box(crop, cb, lines=lines, width=5), "sheet 27: the belt and the visor's lip (red)"), label(in_box(ours, cb, lines=lines, segs=torso, width=5), "ours, same camera: the traces (red), the hull's, turret's and pauldrons' edges (cyan). " + note)]), + row([label(crop, "sheet 27"), label(ours, "ours")])]).save(dst / "paladin_character.png") + +# components +INSETS = [("cockpit", (0, 512, 262, 712), "COCKPIT & SENSOR ARRAY"), ("battery", (262, 512, 512, 712), "RIGHT SHOULDER - MISSILE BATTERY"), ("ew", (512, 512, 762, 712), "LEFT SHOULDER - SENSOR / EW MODULE"), + ("exchangers", (762, 512, 1024, 712), "DORSAL SPINE & HEAT EXCHANGERS"), ("gatling", (0, 742, 205, 930), "RIGHT FOREARM - BALLISTIC WEAPON"), ("hand", (207, 742, 390, 930), "LEFT FOREARM - MANIPULATOR & ENERGY"), + ("pelvis", (392, 742, 633, 930), "PELVIS & HIP ASSEMBLY"), ("knee", (635, 742, 815, 930), "KNEE & LEG DETAIL"), ("foot", (817, 742, 1024, 930), "FOOT & ANKLE")] +cells = [] +for name, box, title in INSETS: + if (src / f"part_{name}.png").exists(): + o = fit(Image.open(src / f"part_{name}.png").convert("RGB"), 520) + cells.append(row([label(fit(sheet.crop(box), 520), f"sheet 27: {title}"), label(o, "ours")], gap=2)) +if cells: + w = max(c.width for c in cells) + cells = [c.crop((0, 0, w, c.height)) if c.width == w else row([c, Image.new("RGB", (w - c.width - 8, c.height), BG)]) for c in cells] + stack([row(cells[i:i + 3]) for i in range(0, len(cells), 3)]).save(dst / "paladin_components.png") + +for tag, cam in cams.items(): + box = cam["box"] + size = (int(box[2] - box[0]) * 3, int(box[3] - box[1]) * 3) + scores[f"filled_{tag}"] = round(float(alpha(f"{stage}_sil_{tag}.png", size).mean()), 3) +(src / "paladin_scores.json").write_text(json.dumps(scores, indent=1), encoding="utf-8") +print(json.dumps(scores, indent=1))