diff --git a/surfaces/blender/experiments/mechs/bastion.py b/surfaces/blender/experiments/mechs/bastion.py index 635fc66..a399b40 100644 --- a/surfaces/blender/experiments/mechs/bastion.py +++ b/surfaces/blender/experiments/mechs/bastion.py @@ -1,26 +1,27 @@ -"""BASTION (sheet 36, images/36.webp): a quadruped, a broad low tortoise hull on four heavy legs, a ballistic turret. +"""BASTION (sheet 36, images/36.webp), second pass: a quadruped, a broad low angular carapace on four heavy legs, a +ballistic turret. -Mass first: the hull is one closed free cage fitted to the sheet's five views (hero, front, side, rear, plan) at their -solved cameras (bastion_cameras.json, by quadruped.cameras), then cut by its wells and split into plates. The legs are +Mass first, and hard: the hull is a set of hard plates, each a faceted solid authored by its faces (bastion_form, +bastion_body), looked at as mass against the sheet's five views at their solved cameras (bastion_cameras.json, by +bastion_cams.py) before any detail; then the detail plating, the legs, the rest (bastion_build). The legs are quadruped.build's kit skeleton, a joint record an axis; the turret's yaw and the gun's pitch are two more. -BASTION_STAGE stops early: volume (the hull's mass alone), legs (mass and skeleton with its legs), recess, plates, -full (default). MECH_QUICK renders by Workbench. Writes under MECH_OUT/bastion/: _.png for hero, front, -side, rear, top (the kept cameras, the sheet's own pixels; alpha is the silhouette), _turn_*.png.""" +BASTION_STAGE stops early: volume (the hull's mass alone), legs (mass and legs), full (default). MECH_QUICK renders +by Workbench. Writes under MECH_OUT/bastion/: _.png for hero, front, side, rear, top (the kept cameras, +the sheet's own pixels; alpha is the silhouette), _turn_*.png, close_*.png, bastion.blend.""" 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 bastion_form as BF -import bastion_body as BB from mathutils import Matrix, Vector import bpy t0 = time.time() M.setup() M.cache_kits() -STAGES = ("volume", "legs", "recess", "plates", "full") +STAGES = ("volume", "legs", "full") STAGE = os.environ.get("BASTION_STAGE", "full") AT = STAGES.index(STAGE) QUICK = bool(os.environ.get("MECH_QUICK")) @@ -30,13 +31,8 @@ OUT.mkdir(parents=True, exist_ok=True) KEPT = BF.cameras() CAMS, STAND = KEPT["cameras"], KEPT["stand"] -mass = BB.hull_mass("khaki") -sheet = BB.hull_cage() -print("CAGE Hull", json.dumps(MS.cage_stats(sheet)), flush=True) -print("CAGE Hull (brokkr_kitbash.shell)", json.dumps(MS.cage_report(sheet)), flush=True) -if AT >= 1: - import bastion_build - bastion_build.run(mass, AT, STAND) +import bastion_build +bastion_build.run(AT, STAND) 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), "LENGTH", round(hi.y - lo.y, 2), "stage", STAGE, "build s", round(time.time() - t0, 1), flush=True) @@ -44,11 +40,13 @@ print("HEIGHT", round(hi.z - lo.z, 2), "LOW", round(lo.z, 2), "WIDTH", round(hi. rig, cam, centre, radius = M.stage_field(8 if QUICK else int(os.environ.get("MECH_SAMPLES", 48))) if not QUICK: import paint - paint.apply(os.environ.get("BASTION_PAINT", "paladin")) + # a slit of upright panes seen level mirrors the horizon, the brightest band of MechGlass's sky: at the preset's Sky + # 2.2 the visor rendered pale grey in the cockpit close-up, so the sky is painted weaker on this glass + paint.apply(os.environ.get("BASTION_PAINT", "paladin"), glass={"sky": 0.4}) WIDTH = {"hero": 1536, "front": 711, "side": 855, "rear": 795, "top": 711} # three times the sheet's pixels; the hero one and a half -VIEWS = os.environ.get("BASTION_VIEWS", "hero,front,side,rear,top").split(",") -if AT >= 3 and not os.environ.get("BASTION_NO_EDGES"): - armour = lambda name: name.startswith(("Hull.", "Cooling.hood", "Thigh.guard", "Shin.guard", "Turret.housing")) and ".fit." not in name and ".mark." not in name # noqa: E731 +VIEWS = [v for v in os.environ.get("BASTION_VIEWS", "hero,front,side,rear,top").split(",") if v and v != "none"] +if AT >= 2 and VIEWS and not os.environ.get("BASTION_NO_EDGES"): + armour = lambda name: name.startswith(("Hull.", "Cooling.hood", "Cooling.frame", "Thigh.guard", "Thigh.shroud", "Shin.guard", "Turret.housing")) and ".fit." not in name and ".mark." not in name # noqa: E731 for tag in ("hero", "side", "top"): (OUT / f"{STAGE}_edges_{tag}.json").write_text(json.dumps(M.built_edges(CAMS[tag], keep=armour)), encoding="utf-8") print("edges s", round(time.time() - t0, 1), flush=True) @@ -70,13 +68,17 @@ for tag in VIEWS: scene.render.film_transparent, scene.render.image_settings.color_mode = keep for o in hidden: o.hide_render = False +ONLY = [c for c in os.environ.get("BASTION_CLOSE", "").split(",") if c] if not QUICK and not os.environ.get("BASTION_NO_TURNS"): - for az in (35, 145, 215): + for az in (() if ONLY else (35, 145, 215)): M.shot(rig, cam, radius, az, 8.0, OUT / f"{STAGE}_turn_{az:03d}.png", (1200, 900), margin=0.8, lens=85.0) if STAGE == "full": - CLOSE = {"cockpit": ((0, 6.0, 5.1), 2.4, 18, -2), "magazine": ((-5.0, 0.0, 6.3), 2.3, 72, 4), "turret": ((0, 1.2, 8.6), 3.6, 35, 10), "interceptor": ((-1.5, 4.25, 7.6), 1.1, 28, 12), - "rear_leg": ((-4.7, -5.7, 2.7), 3.6, 98, 4), "cooling": ((0, -6.0, 6.2), 3.4, 180, 8), "front_leg": ((-4.4, 5.0, 2.2), 3.0, 55, 4), "foot": ((-4.3, 5.4, 0.5), 1.9, 40, 14)} + CLOSE = {"cockpit": ((0, 6.0, 5.1), 2.6, 18, -2), "magazine": ((-5.0, -0.2, 6.2), 2.3, 72, 4), "turret": ((0, 1.2, 8.6), 3.6, 35, 10), "interceptor": ((-3.55, 4.0, 7.0), 1.2, 40, 12), + "rear_leg": ((-4.7, -5.7, 2.9), 3.8, 98, 4), "cooling": ((0, -6.6, 6.2), 3.6, 180, 6), "front_leg": ((-4.4, 5.0, 2.4), 3.2, 55, 4), "foot": ((-4.3, 5.4, 0.5), 1.9, 40, 14), + "hull": ((-1.5, 2.5, 6.2), 6.2, 42, 12), "cooling_flank": ((-3.6, -6.2, 6.2), 3.0, 120, 6)} for name, (target, span, az, el) in CLOSE.items(): + if ONLY and name not in ONLY: + continue M.closeup(rig, cam, target, span, az, el, OUT / f"close_{name}.png", size=(640, 640)) bpy.ops.wm.save_as_mainfile(filepath=str(OUT / "bastion.blend")) print("total s", round(time.time() - t0, 1)) diff --git a/surfaces/blender/experiments/mechs/bastion_body.py b/surfaces/blender/experiments/mechs/bastion_body.py index 6b6aa16..a47a4ef 100644 --- a/surfaces/blender/experiments/mechs/bastion_body.py +++ b/surfaces/blender/experiments/mechs/bastion_body.py @@ -1,5 +1,12 @@ -"""BASTION's body, mass first (sheet 36): the hull as one closed free cage made a mass, its wells, its plates. -Runs inside Blender beside mechlib, massing and bastion_form.""" +"""BASTION's body, second pass (sheet 36): the carapace as hard plates over a dark core, then its detail plating. +Runs inside Blender beside mechlib, massing and bastion_form. + + hull(host) the mass: the core and every main plate of bastion_form.PLATES, each a faceted solid on the + corners of its faces (massing.corners, massing.hard), and the deck's collar. This is what + the volume stage shows against the silhouettes, before any detail. + plating(plates, host) the detail plating after the main split (massing.clad): a raised panel on each large + facet that faces out, split and stepped + report(plates) each plate's kind, corners and facets (the hard-plate counterpart of a cage report)""" import math import bpy @@ -9,20 +16,75 @@ import bastion_form as BF import massing as MS import mechlib as M -CORE = "gunmetal" I4 = Matrix.Identity(4) +T = Matrix.Translation -_CAGE = {} +def _face(f, sx=1): + if f[0] == "at": + return MS.plane(f[1], f[2]) + return MS.through(f[1], f[2], f[3], f[4]) -def hull_cage(): - """The hull's cage, moved so its surface passes through bastion_form's points (massing.cage_through).""" - if "hull" not in _CAGE: - _CAGE["hull"] = MS.cage_through(BF.hull_sheet()) - return _CAGE["hull"] +def _points(plate): + return MS.corners([_face(f) for f in plate["faces"]]) if "faces" in plate else [Vector(p) for p in plate["points"]] -def hull_mass(mat="khaki", levels=3): - """The hull: carapace and belly, one closed volume from the minimal cage (bastion_form.hull_sheet).""" - return MS.cage("Hull.mass", hull_cage(), I4, mat, levels=levels) +def hull(host): + """The carapace's mass. Returns ({name: object} of the armour plates, {name: object} of the dark core).""" + plates, dark = {}, {} + for group, out in ((BF.DARK, dark), (BF.PLATES, plates)): + for name, plate, sided in group: + pts = _points(plate) + for sx in ((1, -1) if sided else (1,)): + key = f"{name}.{'R' if sx > 0 else 'L'}" if sided else name + out[key] = MS.hard(key, pts, host, plate["mat"], mirror=plate.get("mirror", False), bevel=plate["bevel"], sx=sx) + out[key]["clad"] = bool(plate["clad"]) + g = M.Geo() + g.lathe(T((0, 0, 0)) @ Matrix.Rotation(math.radians(22.5), 4, "Z"), BF.COLLAR, 8) + collar = g.to_object("Hull.Collar", BF.P, host, 1.0) + mod = collar.modifiers.new("Bevel", "BEVEL") + mod.width, mod.segments, mod.limit_method, mod.angle_limit = 0.04, 1, "ANGLE", math.radians(12) + collar["plate_kind"], collar["clad"] = "hard", True + plates["Hull.Collar"] = collar + g = M.Geo() + g.lathe(I4, [(0, 7.2), (2.6, 7.2), (2.6, 7.56), (0, 7.56)], 48) + dark["Core.deck"] = g.to_object("Core.deck", BF.CORE, host) + return plates, dark + + +def outward(n, c): + """A facet the detail plating takes: one that faces out of the hull, not down, not into a neighbour.""" + if n.z < -0.35: + return False + radial = Vector((c.x, c.y, 0.0)) + return n.z > 0.6 or (radial.length > 1.0 and n.dot(radial.normalized()) > 0.25) + + +def plating(plates, host): + """Detail plating: one object of raised panels a plate (Hull..panels), olive_light on olive and the other + way round, so a panel reads against its plate; a bolt inside each panel corner (Hull.bolts). Returns + {name: panels made}.""" + made, bolts = {}, M.Geo() + for k, (name, obj) in enumerate(sorted(plates.items())): + if not obj.get("clad"): + continue + g = M.Geo() + n = MS.clad(obj, g, keep=outward, seed=k, bolts=bolts) + if n: + mat = BF.P2 if obj.data.materials[0] == M.MATS[BF.P] else BF.P + o = g.to_object(f"{name}.panels", mat, host, 1.0) + mod = o.modifiers.new("Bevel", "BEVEL") + mod.width, mod.segments, mod.limit_method, mod.angle_limit = 0.012, 1, "ANGLE", math.radians(20) + for p in o.data.polygons: + p.use_smooth = False + made[name] = n + bolts.to_object("Hull.bolts", "gunmetal", host) + return made + + +def report(plates): + rows = {} + for name, obj in sorted(plates.items()): + rows[name] = {"kind": obj.get("plate_kind", "hard"), "corners": len(obj.data.vertices), "facets": len(obj.data.polygons)} + return rows diff --git a/surfaces/blender/experiments/mechs/bastion_build.py b/surfaces/blender/experiments/mechs/bastion_build.py index 2b63e01..3f4cb19 100644 --- a/surfaces/blender/experiments/mechs/bastion_build.py +++ b/surfaces/blender/experiments/mechs/bastion_build.py @@ -1,18 +1,20 @@ -"""BASTION beyond its hull's mass: the kit skeleton (quadruped.build), the wells, the plates, the hip housings, the -legs' dress and rams, the feet (feet.bastion_pads), the turret and gun, the magazines, the interceptors, the cooling. +"""BASTION beyond its hull's mass, second pass: the kit skeleton (quadruped.build), the head's visor, the magazines, +the legs as armoured housings on rotary bearings with their rams (ram core), the feet (feet.bastion_pads), the +turret and gun, the interceptors, the cooling assemblies under their housings, the surface detail. Every part function takes the host it is authored on; every finished part is frozen (brokkr_kitbash.freeze). +Rebuilt in this pass: the hull (bastion_body: hard plates), the visor, the hip housings, both leg dresses, the +cooling, the detail. Carried over from the first pass unchanged in form: magazine, interceptor, foot, turret, gun. + Reconciliations with the design prompt (ruling concept-prompt-is-design-intent), each built as the prompt says: magazines the sheet draws an open recess in the flank and, in plan, a box outside the rim. The prompt: recessed - side compartments with segmented doors that open upward. Built: a recess in the flank band, a + side compartments with segmented doors that open upward. Built: a framed compartment in the flank, a three-segment door hinged on its upper edge and standing open (the plan's box is the open door). - interceptors the sheet's inset shows one launcher; the hero scatters seven boxes on the dome. The prompt: spread - round the shell's perimeter. Built: eight, evenly round the shoulder line, the inset's look. - cooling the rear view shows two bare radiator faces flush in the tail, the side view a block 2 m behind the - hull, the plan nothing behind the tail. The prompt: under sculpted protective housings. Built: two - housings (free cages) over the banks, standing 0.7 m behind the tail, the fins in their mouths. - hips the prompt: rotary housings at the hull's corners. Built: a fixed drum housing under each corner of the - overhang, the thigh's drum turning in it. + interceptors the sheet's inset shows one launcher; the hero scatters seven boxes on the deck. The prompt: spread + round the shell's perimeter. Built: eight, on the pods and the flank roofs, the inset's look. + cooling the rear view shows two framed radiator faces either side of the tail, the hero a ribbed housing with + a grille in its flank, the side view a block 1.3 m behind the tail. Built: two housings, each a + hood over a ribbed wall, radiator faces to the rear and in the flank, a machinery block between. legs front shorter and heavily armoured, rear longer with exposed hydraulics: as the sheet draws them.""" import json import math @@ -20,7 +22,7 @@ import os import time import bpy -from mathutils import Matrix, Vector +from mathutils import Matrix, Quaternion, Vector import bastion_form as BF import bastion_body as BB @@ -29,8 +31,9 @@ import mechlib as M import quadruped as Q F, T = M.frame_at, Matrix.Translation -P, P2, CORE = "olive", "olive_light", "gunmetal" +P, P2, CORE = BF.P, BF.P2, BF.CORE FOOT_PIN = 0.1 +LEAN_FRONT = 18.0 # degrees a front thigh's housing stands off upright (the side view) RECORDS = {"hip_splay": ((-6.0, 14.0), "hip_splay"), "hip_pitch_front": ((-32.0, 32.0), "hip_pitch"), "hip_pitch_rear": ((-30.0, 34.0), "hip_pitch"), "knee_front": ((-35.0, 40.0), "knee"), "knee_rear": ((-40.0, 45.0), "knee"), "turret_yaw": ((-180.0, 180.0), "turret_yaw"), "gun_pitch": ((-8.0, 28.0), "gun_pitch"), "ankle": ((-30.0, 30.0), "ankle_pitch"), "ankle_roll": ((-22.0, 22.0), "ankle_roll")} @@ -38,6 +41,7 @@ RX = lambda d: Matrix.Rotation(math.radians(d), 4, "X") # noqa: E731 RY = lambda d: Matrix.Rotation(math.radians(d), 4, "Y") # noqa: E731 RZ = lambda d: Matrix.Rotation(math.radians(d), 4, "Z") # noqa: E731 TIMES = {} +HARD = {} # every hard plate's report: kind, corners, facets def frozen(before): @@ -74,6 +78,36 @@ def geo(name, mat, host, build, smooth=38.0, bevel=0.0): return obj +def hard(name, points, host, mat=P, bevel=0.035, clad=None, seed=0, **kw): + """massing.hard, reported; `clad` is a test (normal, centre) of which facets take detail plating.""" + obj = MS.hard(name, points, host, mat, bevel=bevel, **kw) + HARD[name] = {"kind": "hard", "corners": len(obj.data.vertices), "facets": len(obj.data.polygons)} + if clad: + g, bolts = M.Geo(), M.Geo() + if MS.clad(obj, g, keep=clad, min_area=0.5, seed=seed, inset=0.09, bolts=bolts): + bolts.to_object(name + ".bolts", "gunmetal", host) + o = g.to_object(name + ".panels", P2 if mat == P else P, host, 1.0) + mod = o.modifiers.new("Bevel", "BEVEL") + mod.width, mod.segments, mod.limit_method, mod.angle_limit = 0.012, 1, "ANGLE", math.radians(20) + for p in o.data.polygons: + p.use_smooth = False + return obj + + +def box_pts(x0, x1, y0, y1, z0, z1): + return [(x, y, z) for x in (x0, x1) for y in (y0, y1) for z in (z0, z1)] + + +def ring8(w, y0, y1, c): + """A chamfered rectangle's eight corners: w across x, from y0 to y1.""" + return [(-w / 2 + c, y0), (w / 2 - c, y0), (w / 2, y0 + c), (w / 2, y1 - c), (w / 2 - c, y1), (-w / 2 + c, y1), (-w / 2, y1 - c), (-w / 2, y0 + c)] + + +def housing_pts(sections): + """A housing's corners from its sections down a limb: [(z, width, y0, y1, chamfer)].""" + return [(x, y, z) for z, w, y0, y1, c in sections for x, y in ring8(w, y0, y1, c)] + + def disc(g, at, r, w, rings=3, bolts=12): """A rotary housing's face: a drum along at's z from 0 to w, its outer face stepped in `rings` rings to a hub.""" prof = [(0, 0), (r, 0), (r, 0.72 * w)] @@ -87,64 +121,56 @@ def disc(g, at, r, w, rings=3, bolts=12): return g -# --- wells and plates --------------------------------------------------------------------------------------------------- -CROWN = 7.6 -MAG = dict(y0=-1.25, y1=1.05, z0=5.55, z1=6.55, depth=1.5) - - -def wells(): - """The cutters: the cockpit's recess under the nose's rim, a magazine's compartment in each flank band.""" - cuts = [MS.slab("Cockpit.cut", (0, 6.0, 5.2), (3.5, 1.9, 0.5), BB.I4)] - for sx in (-1, 1): - cuts.append(MS.slab(f"Magazine.cut.{'L' if sx < 0 else 'R'}", (sx * 4.6, 0.5 * (MAG["y0"] + MAG["y1"]), 0.5 * (MAG["z0"] + MAG["z1"])), (2 * MAG["depth"], MAG["y1"] - MAG["y0"], MAG["z1"] - MAG["z0"]), BB.I4)) - return cuts - - -def plates(skin, cuts): - """The carapace split into its plates along the shoulder line and the quarters: fewer, bigger, each at its own - depth. A plate is the mass's own surface (massing.plate), so they conform by construction.""" - g = 0.035 - up = lambda e: ((0, -0.065, -1), -(6.62 + e)) # noqa: E731 above the shoulder line - low = lambda e: ((0, 0.065, 1), 6.62 - e) # noqa: E731 below it - rim = ((0, -0.085, -1), -5.27) # above the rim: the overhang's underside stays the mass - H = MS.half - made = [] - - def add(name, keep, proud, wall, mat=P): - o = MS.plate(name, skin, keep, proud=proud, wall=wall, mat=mat, cutters=cuts, bevel=0.03) - if o is not None: - made.append(o) - add("Hull.Crown", [H("z", -1, CROWN)], 0.07, 0.1) - add("Hull.Glacis", [H("x", 1, 1.85), H("x", -1, -1.85), H("y", -1, 2.3), H("z", 1, CROWN - 2 * g), H("z", -1, 5.52)], 0.15, 0.16) - add("Hull.Tail", [H("x", 1, 1.15), H("x", -1, -1.15), H("y", 1, -2.7), H("z", 1, CROWN - 2 * g), rim], 0.12, 0.14) - for sx, tag in ((-1, "L"), (1, "R")): - side = lambda at: H("x", -sx, sx * at) # noqa: E731 outboard of |x| = at - for name, extra, proud, wall, mat in ( - ("CheekUp", [side(1.85 + 2 * g), H("y", -1, 1.5), up(g)], 0.08, 0.12, P), - ("CheekBand", [side(1.85 + 2 * g), H("y", -1, 1.5), low(g), rim], 0.13, 0.16, P), - ("FlankUp", [side(1.0), H("y", 1, 1.5 - 2 * g), H("y", -1, -2.0), up(g)], 0.05, 0.1, P2), - ("FlankBand", [side(1.0), H("y", 1, 1.5 - 2 * g), H("y", -1, -2.0), low(g), rim], 0.17, 0.2, P), - ("RearUp", [side(1.15 + 2 * g), H("y", 1, -2.0 - 2 * g), up(g)], 0.09, 0.12, P), - ("RearBand", [side(1.15 + 2 * g), H("y", 1, -2.0 - 2 * g), low(g), rim], 0.12, 0.15, P2)): - add(f"Hull.{name}.{tag}", [H("z", 1, CROWN - 2 * g)] + extra, proud, wall, mat) - add("Hull.Chin", [H("x", 1, 2.0), H("x", -1, -2.0), H("y", -1, 4.75), H("z", 1, 4.9), H("z", -1, 3.75)], 0.1, 0.14, P2) - return made +def stack(g, at, bolts=20): + """A rear hip's bearing as the hero draws it: a drum, a flange, two stepped discs and a hub along at's z, bolted, + the second step webbed with eight ribs.""" + g.lathe(at, [(0, 0.55), (1.2, 0.55), (1.2, 0.8), (1.32, 0.8), (1.32, 0.88), (1.0, 0.88), (1.0, 1.06), (0.78, 1.06), (0.78, 1.2), (0.3, 1.2), (0.3, 1.32), (0, 1.32)], 56) + g.bolts(at @ T((0, 0, 0.88)), 1.16, bolts, 0.04, 0.05) + g.bolts(at @ T((0, 0, 1.2)), 0.54, 10, 0.035, 0.04) + for k in range(8): + g.box(at @ RZ(45.0 * k + 22.5) @ T((0.89, 0, 1.13)), (0.2, 0.08, 0.14)) + return g +# --- the head ------------------------------------------------------------------------------------------------------------ def cockpit(host): - """RECESSED COCKPIT & SENSOR SUITE inset: a narrow armoured visor deep under the nose's rim, a row of lamps.""" - def build(g): - g.box(T((0, 5.45, 5.2)), (3.3, 0.3, 0.46)) - for x in (-1.2, 0.0, 1.2): - g.box(T((x, 5.62, 5.2)), (0.12, 0.2, 0.46)) - geo("Cockpit.frame", CORE, host, build) - geo("Cockpit.visor", "glass", host, lambda g: [g.box(T((x, 5.61, 5.22)) @ RX(-12), (1.05, 0.05, 0.3)) for x in (-0.6, 0.6)]) - geo("Cockpit.lamps", "glow_blue", host, lambda g: [g.box(T((x, 5.64, 5.07)), (0.22, 0.04, 0.05)) for x in (-1.0, -0.45, 0.45, 1.0)]) - # the cheeks' lamp slots under the rim, either side (the hero's light bars) - for sx in (-1, 1): - at = F((sx * 3.3, 5.02, 4.98), (sx * 0.45, 1, -0.1)) - geo(f"Cheek.lamp.{sx}", CORE, host, lambda g: g.box(at, (1.3, 0.34, 0.5)), bevel=0.02) - geo(f"Cheek.glow.{sx}", "lamp", host, lambda g: g.box(at @ T((0.2, 0.0, 0.26)), (0.42, 0.09, 0.02))) + """RECESSED COCKPIT & SENSOR SUITE inset: a narrow armoured visor deep under the brow, three panes round the + head's front and its two chamfers, dark glass between an upper and a lower armoured lid, two sensor lamps.""" + V = BF.VISOR + z0, z1, yf, h, (wx, wy), yb, (g0, g1) = V["z0"], V["z1"], V["front"], V["half"], V["wing"], V["back"], V["glass"] + MS.hard("Cockpit.tub", [(x, y, z) for z in (z0, z1) for x, y in ((0, yf), (h, yf), (wx, wy), (wx, yb), (0, yb))], host, CORE, mirror=True, bevel=0.0) + zc, gh = 0.5 * (g0 + g1), g1 - g0 + n = Vector((yf - wy, wx - h, 0)).normalized() + length = math.hypot(wx - h, wy - yf) + wing = lambda sx, lift: F((sx * (0.5 * (h + wx) + n.x * lift), 0.5 * (yf + wy) + n.y * lift, 0), (sx * n.x, n.y, 0)) # noqa: E731 + + def glass(g): + g.box(T((0, yf + 0.02, zc)), (2 * h - 0.14, 0.04, gh)) + for sx in (-1, 1): + g.box(wing(sx, 0.02) @ T((0, zc, 0)), (length - 0.16, gh, 0.04)) + geo("Cockpit.visor", "glass", host, glass) + + def lids(g): + for za, zb in ((g1, z1), (z0, g0)): + g.box(T((0, yf + 0.05, 0.5 * (za + zb))), (2 * h + 0.06, 0.12, zb - za)) + for sx in (-1, 1): + g.box(wing(sx, 0.05) @ T((0, 0.5 * (za + zb), 0)), (length + 0.04, zb - za, 0.12)) + for sx in (-1, 1): + g.box(T((sx * h, yf + 0.03, zc)), (0.12, 0.14, gh + 0.02)) + g.box(wing(sx, 0.05) @ T((sx * 0.5 * length - sx * 0.04, zc, 0)), (0.1, gh, 0.12)) + g.box(T((0, yf + 0.04, zc)), (0.07, 0.1, gh)) + geo("Cockpit.frame", P2, host, lids, bevel=0.015) + geo("Cockpit.lamps", "glow_blue", host, lambda g: [g.box(T((x, yf + 0.045, g0 + 0.07)), (0.14, 0.02, 0.045)) for x in (-0.62, 0.62)]) + + +def cheek_lamp(host, sx): + """The light bar in the slot under a cheek pod's front (the hero and the front view): a dark housing on the + tray's face, one lit lens at its inboard end, two dark ones.""" + L = BF.LAMP + at = F((sx * L["at"][0], L["at"][1], L["at"][2]), (sx * L["normal"][0], L["normal"][1], 0)) + tag = "L" if sx < 0 else "R" + geo(f"Cheek.lamp.{tag}", CORE, host, lambda g: [g.box(at @ T((0, 0, 0.03)), (2.0, 0.17, 0.1))] + [g.box(at @ T((x, 0, 0.09)), (0.34, 0.12, 0.04)) for x in (-0.25, 0.3)], bevel=0.01) + geo(f"Cheek.glow.{tag}", "lamp", host, lambda g: g.box(at @ T((sx * 0.72, 0, 0.1)), (0.3, 0.07, 0.02))) def magazine(host, sx): @@ -152,9 +178,10 @@ def magazine(host, sx): prompt's segmented door, hinged on the upper edge, open upward.""" import hardpoint as HP tag = "L" if sx < 0 else "R" + MAG = BF.MAG y0, y1, z0, z1 = MAG["y0"], MAG["y1"], MAG["z0"], MAG["z1"] w, h = y1 - y0, z1 - z0 - face = F((sx * 4.3, 0.5 * (y0 + y1), 0.5 * (z0 + z1)), (sx, 0, 0.0), (0, 0, 1)) # z outboard, y up, x along the hull + face = F((sx * (MAG["face"] - 0.1), 0.5 * (y0 + y1), 0.5 * (z0 + z1)), (sx, 0, 0.0), (0, 0, 1)) # z outboard, y up, x along the hull b = M.Build(f"Magazine.{tag}", host, None) fr = b["gunmetal"] for u in (-0.5 * w - 0.06, 0.5 * w + 0.06): @@ -186,7 +213,6 @@ def magazine(host, sx): b["steel"].rod(face @ Vector((s * 0.46 * w, 0.45 * h, 0.0)), hinge @ RX(-78.0) @ Vector((s * 0.46 * w, -0.8 * seg, 0.0)), 0.03, 8) return b.done() - def interceptor(name, host, at, yaw): """PERIMETER INTERCEPTOR LAUNCHER inset: a small box of four tubes, two over two, with a hooded sight on its cheek, trunnioned in a fork on a turning pedestal. `at` is the pedestal's foot, z out of the shell.""" @@ -206,141 +232,181 @@ def interceptor(name, host, at, yaw): return b.done() +# --- cooling --------------------------------------------------------------------------------------------------------------- def cooling(host): - """REAR COOLING ARRAYS inset under the prompt's sculpted housings: two fin banks on the tail, each under a - housing that is a minimal free cage (an arched hood open to the rear), a manifold between them.""" + """REAR COOLING ARRAYS inset, the rear view's two framed radiator faces and the hero's ribbed housing: each + assembly is a fin bank behind a framed rear face of two panels and a second bank in its flank, under a housing + (a chamfered hood that overhangs the rear face and falls forward into the tail, a ribbed outer wall, an inner + wall, a floor); a machinery block with its manifold stands between the two. Hard: the concept draws them boxed.""" + x0, x1, ya, yb, z0, z1 = 1.5, 3.64, -4.85, -7.15, 5.14, 7.35 + xc = 0.5 * (x0 + x1) out = [] for sx in (-1, 1): tag = "L" if sx < 0 else "R" - c = Vector((sx * 2.25, -5.6, 6.3)) - w, d, h = 1.6, 1.8, 2.2 - # the hood: authored on its right half and mirrored; front (toward the hull), crown and flank, open behind and below - verts = [[0.0, 0.5 * d, 0.5 * h + 0.05], [0.0, -0.5 * d, 0.5 * h + 0.2], - [0.5 * w, 0.5 * d, 0.32 * h], [0.5 * w, -0.5 * d, 0.4 * h], - [0.56 * w, 0.42 * d, -0.5 * h], [0.56 * w, -0.5 * d, -0.5 * h], - [0.0, 0.62 * d, -0.1 * h], [0.5 * w, 0.6 * d, -0.2 * h]] - faces = [[0, 1, 3, 2], [2, 3, 5, 4], [6, 0, 2, 7]] - sheet = {"verts": verts, "faces": faces, "creases": [[2, 3, 0.7], [0, 2, 0.5]], "mirror": True, "rim": 0.6} - out.append(MS.cage_shell(f"Cooling.hood.{tag}", sheet, host, T(c), mat=P, thickness=0.14, levels=2, bevel=0.03, inside=(0, 0, -0.3))) + hood = [(x0 - 0.08, yb - 0.1, z1 - 0.2), (x1 + 0.08, yb - 0.1, z1 - 0.2), (x0 + 0.12, yb - 0.02, z1), (x1 - 0.14, yb - 0.02, z1), (x0 + 0.12, ya - 0.7, z1 + 0.04), (x1 - 0.14, ya - 0.7, z1 + 0.04), + (x0, ya + 0.55, 6.98), (x1 - 0.1, ya + 0.55, 6.84), (x0 - 0.08, ya - 0.7, z1 - 0.2), (x1 + 0.08, ya - 0.7, z1 - 0.2), (x0 - 0.08, ya + 0.55, 6.78), (x1 + 0.08, ya + 0.55, 6.66), + (x0 - 0.08, yb - 0.1, z1 - 0.36), (x1 + 0.08, yb - 0.1, z1 - 0.36), (x0 - 0.08, ya + 0.55, 6.6), (x1 + 0.08, ya + 0.55, 6.5)] + out.append(hard(f"Cooling.hood.{tag}", hood, host, P, bevel=0.06, sx=sx, clad=lambda n, c: n.z > 0.6, seed=3)) + out.append(hard(f"Cooling.wall.{tag}", box_pts(x1 - 0.16, x1 + 0.04, ya, yb + 0.78, z0, z1 - 0.3), host, P, bevel=0.03, sx=sx)) + out.append(hard(f"Cooling.inner.{tag}", box_pts(x0 - 0.04, x0 + 0.14, ya, yb, z0, z1 - 0.3), host, P, bevel=0.03, sx=sx)) + out.append(hard(f"Cooling.floor.{tag}", box_pts(x0 - 0.08, x1 + 0.08, ya, yb - 0.06, z0 - 0.04, z0 + 0.16), host, P2, bevel=0.04, sx=sx)) + + def frame(g): + for x, w in ((x0 + 0.1, 0.22), (xc, 0.14), (x1 - 0.07, 0.2)): # posts and the mullion of the rear face + g.box(T((sx * x, yb + 0.06, 0.5 * (z0 + z1) - 0.1)), (w, 0.2, z1 - z0 - 0.5)) + for z, hgt in ((z1 - 0.44, 0.2), (z0 + 0.25, 0.2)): + g.box(T((sx * xc, yb + 0.06, z)), (x1 - x0, 0.2, hgt)) + for y in (yb + 0.74,): # the flank window's forward post + g.box(T((sx * (x1 - 0.06), y, 0.5 * (z0 + z1) - 0.1)), (0.2, 0.16, z1 - z0 - 0.5)) + for k in range(5): # the ribs of the outer wall + g.box(T((sx * (x1 + 0.07), ya - 0.2 - 0.27 * k, 0.5 * (z0 + z1) - 0.12)), (0.12, 0.11, z1 - z0 - 0.62)) + out.append(geo(f"Cooling.frame.{tag}", P2, host, frame, bevel=0.03)) def fins(g): - n = 15 - for k in range(n): - g.box(T(c + Vector(((k - (n - 1) / 2) * 0.085, -0.25, -0.1))), (0.03, 1.2, 1.9)) + for x_a, x_b in ((x0 + 0.23, xc - 0.09), (xc + 0.09, x1 - 0.19)): + n = int((x_b - x_a) / 0.062) + for k in range(n + 1): + g.box(T((sx * (x_a + (x_b - x_a) * k / n), yb + 0.24, 0.5 * (z0 + z1) - 0.1)), (0.02, 0.3, z1 - z0 - 0.86)) + n = 9 + for k in range(n + 1): + g.box(T((sx * (x1 - 0.2), yb + 0.2 + 0.46 * k / n, 0.5 * (z0 + z1) - 0.1)), (0.3, 0.02, z1 - z0 - 0.86)) out.append(geo(f"Cooling.fins.{tag}", "machine", host, fins, smooth=5)) - - def core(g): - g.box(T(c + Vector((0, 0.1, -0.15))), (1.36, 1.5, 1.7)) - g.box(T(c + Vector((0, -0.86, -1.1))), (1.42, 0.12, 0.14)) - g.box(T(c + Vector((0, -0.86, 0.82))), (1.42, 0.12, 0.14)) - out.append(geo(f"Cooling.core.{tag}", CORE, host, core)) + out.append(geo(f"Cooling.core.{tag}", CORE, host, lambda g: g.box(T((sx * xc, 0.5 * (ya + yb) + 0.2, 0.5 * (z0 + z1) - 0.1)), (x1 - x0 - 0.5, ya - yb - 0.4, z1 - z0 - 0.5)))) + out.append(hard("Cooling.block", box_pts(-1.5, 1.5, -6.5, -4.6, 5.5, 7.18), host, CORE, bevel=0.04)) + out.append(hard("Cooling.block.cap", [(-1.46, -6.62, 7.18), (1.46, -6.62, 7.18), (-1.46, -4.9, 7.18), (1.46, -4.9, 7.18), (-1.3, -6.5, 7.34), (1.3, -6.5, 7.34), (-1.3, -4.9, 7.34), (1.3, -4.9, 7.34)], + host, P2, bevel=0.03, clad=lambda n, c: n.z > 0.6, seed=5)) + out.append(hard("Cooling.block.low", box_pts(-1.15, 1.15, -6.1, -4.4, 4.1, 5.5), host, CORE, bevel=0.04)) def manifold(g): - g.box(T((0, -5.5, 5.75)), (3.0, 1.2, 1.3)) - for z in (5.4, 5.9, 6.3): - g.rod((-1.5, -6.05, z), (1.5, -6.05, z), 0.11, 12) - g.box(T((0, -5.8, 4.9)), (1.8, 0.9, 0.7)) - out.append(geo("Cooling.manifold", CORE, host, manifold)) + for z in (5.95, 6.4, 6.85): + g.rod((-1.5, -6.6, z), (1.5, -6.6, z), 0.12, 12) + for x in (-1.2, 0.0, 1.2): + g.cylinder(T((x, -6.6, z)) @ RY(90), 0.16, 0.12, 12) + g.box(T((0, -6.62, 5.2)), (1.7, 0.3, 0.75)) + for x in (-0.55, 0.55): + g.cylinder(T((x, -6.8, 5.2)) @ RX(90), 0.24, 0.12, 20) + out.append(geo("Cooling.manifold", "machine", host, manifold)) return out # --- legs ----------------------------------------------------------------------------------------------------------- def hip_housing(tag, host, hip, rear): - """The rotary housing at a corner of the hull: a fixed drum under the overhang, on the hull's flank, the thigh's - drum turning in it. Authored in the world (the trunk's frame).""" + """The reinforced rotary housing at a corner of the hull (the prompt): a fixed drum under the overhang on a + bracket into the hull, its outer race bolted; over a front hip an armoured shroud.""" sx = -1 if tag[-1] == "l" else 1 - r = 1.3 if rear else 0.98 + r = 1.25 if rear else 0.8 hip = Vector(hip) inner = 2.3 + reach = abs(hip.x) - inner - (0.62 if rear else 1.0) def fixed(g): at = F((sx * inner, hip.y, hip.z), (sx, 0, 0), (0, 0, 1)) - g.lathe(at, [(0, 0), (1.02 * r, 0), (1.02 * r, abs(hip.x) - inner - 0.5), (0.9 * r, abs(hip.x) - inner - 0.42), (0, abs(hip.x) - inner - 0.42)], 48) - # the bracket up into the overhang + g.lathe(at, [(0, 0), (1.02 * r, 0), (1.02 * r, reach), (0.9 * r, reach + 0.08), (0, reach + 0.08)], 48) g.box(T((sx * (inner + 0.6), hip.y, hip.z + 0.75 * r)), (1.3, 1.5 * r, 1.4 * r)) geo(f"Hip.housing.{tag}", CORE, host, fixed) - geo(f"Hip.collar.{tag}", "machine", host, lambda g: (g.lathe(F((sx * (abs(hip.x) - 0.52), hip.y, hip.z), (sx, 0, 0), (0, 0, 1)), - [(1.08 * r, 0), (1.08 * r, 0.14), (0.96 * r, 0.14), (0.96 * r, 0)], 48), - g.bolts(F((sx * (abs(hip.x) - 0.38), hip.y, hip.z), (sx, 0, 0), (0, 0, 1)), 1.02 * r, 20, 0.035, 0.04))) + geo(f"Hip.collar.{tag}", "machine", host, lambda g: (g.lathe(F((sx * (inner + reach - 0.02), hip.y, hip.z), (sx, 0, 0), (0, 0, 1)), [(1.08 * r, 0), (1.08 * r, 0.14), (0.96 * r, 0.14), (0.96 * r, 0)], 48), + g.bolts(F((sx * (inner + reach + 0.12), hip.y, hip.z), (sx, 0, 0), (0, 0, 1)), 1.02 * r, 20, 0.035, 0.04))) + if not rear: + hard(f"Hip.shroud.{tag}", [(sx * x, hip.y + y, hip.z + z) for x, y, z in ((2.35, -1.2, 0.5), (2.35, 1.0, 0.5), (3.5, -1.2, 0.7), (3.5, 1.0, 0.7), (2.35, -1.3, 1.75), (2.35, 1.1, 1.75), (3.7, -1.3, 1.75), (3.7, 1.1, 1.75))], + host, P2, bevel=0.03) -def shield_sheet(w, top, bottom, lead, crown, back): - """A leg's guard plate as a minimal free cage, right half (mirrored): a front face from `top` to `bottom` (z, - down the limb is negative) standing `lead` before the limb's axis and `crown` further at its middle, a side - wrapped back to `back`, a hood over the top. Ten authored vertices.""" - mid = 0.45 * top + 0.55 * bottom - verts = [[0, lead + 0.1, top + 0.1], [0, lead + crown, mid], [0, lead + 0.05, bottom - 0.1], # the seam - [0.5 * w, lead - 0.05, top], [0.52 * w, lead + 0.7 * crown, mid], [0.44 * w, lead - 0.05, bottom], # the front's edge - [0.56 * w, back, top - 0.05], [0.58 * w, back + 0.05, mid], [0.5 * w, back + 0.1, bottom + 0.1], # the side's rear edge - [0, back + 0.1, top + 0.22]] # the hood's rear, on the seam - faces = [[0, 3, 4, 1], [1, 4, 5, 2], [3, 6, 7, 4], [4, 7, 8, 5], [9, 6, 3, 0]] - return {"verts": verts, "faces": faces, "creases": [[3, 4, 0.75], [4, 5, 0.75], [0, 3, 0.5]], "mirror": True, "rim": 0.7} - - -def leg_dress(tag, bones, pose): - """One leg's machinery and armour on its bones (z up the segment, toward its upper joint; x the pin). - Front: a short stout girder, a great guard plate before the thigh that hides the hip from the front, a smaller - one down the shin. Rear: REAR LEG PROPULSION ASSEMBLY inset - a long open twin-beam thigh, two exposed chromed - rams from the hip's housing to the hock, a great layered hip disc, a guard plate behind the lower thigh.""" - rear, sx = tag[0] == "r", (-1 if tag[-1] == "l" else 1) +def leg_front(tag, bones, pose): + """A front leg (the hero's near leg, the side and front views; no inset): short and heavily armoured. The thigh is + an armoured housing on the hip's bearing, its discs standing proud either side; the shin a second, flared + housing; each housing a hard solid of chamfered sections with stepped panels on its face and flanks. A ram + behind the thigh drives the hip's pitch (ram core).""" + sx = -1 if tag[-1] == "l" else 1 th, sh, hipb = bones[f"Thigh.{tag}"], bones[f"Shin.{tag}"], bones[f"Bone.hip_splay.{tag}"] l1, l2 = (float(json.loads(o["kit_params"])["length"]) for o in (th, sh)) - r_hip, r_knee = (1.22, 0.62) if rear else (0.9, 0.56) - out = F((0, 0, 0), (sx, 0, 0), (0, 0, 1)) # a frame whose z is outboard + r_hip, r_knee = 0.88, 0.56 + out = F((0, 0, 0), (sx, 0, 0), (0, 0, 1)) + face = lambda n, c: n.y > 0.5 or abs(n.x) > 0.7 # noqa: E731 the front and the flanks take panels - def thigh(g): - if rear: - for s in (-1, 1): - g.sweep([(s * 0.52, 0, 0), (s * 0.52, 0, -l1)], [(-0.09, -0.3), (0.09, -0.3), (0.09, 0.3), (-0.09, 0.3)], (0, 1, 0)) - for z in (0.3, 0.52, 0.74): - g.box(T((0, 0.12, -z * l1)), (1.0, 0.18, 0.24)) - g.cylinder(T((0, 0, -l1)) @ RY(90), 0.3, 1.3, 20) - else: - g.box(T((0, 0, -0.5 * l1)), (0.9, 0.8, l1)) - g.box(T((0, -0.36, -0.5 * l1)), (0.6, 0.3, 0.7 * l1)) - geo(f"Thigh.girder.{tag}", CORE, th, thigh, bevel=0.015) + # the housing leans less than the thigh under it: the side view's guard stands about 18 degrees off upright over a + # thigh the marks put at 39, and the hero's near leg reads as a pillar. G is that frame, in the thigh's own. + M.update() + upright = (th.matrix_world.inverted() @ hipb.matrix_world).to_3x3().to_quaternion() + pitch = math.degrees(upright.angle) + G = Quaternion().slerp(upright, max(0.0, 1.0 - LEAN_FRONT / max(pitch, 1e-6))).to_matrix().to_4x4() + knee = G.inverted() @ Vector((0, 0, -l1)) + geo(f"Thigh.girder.{tag}", CORE, th, lambda g: (g.box(T((0, 0, -0.5 * l1)), (1.5, 0.9, l1)), g.box(T((0, -0.5, -0.5 * l1)), (0.7, 0.4, 0.8 * l1))), bevel=0.015) + y1 = knee.y + 0.62 + pts = housing_pts([(1.0, 1.35, -0.3, 0.6, 0.2), (0.72, 1.9, -0.6, y1, 0.24), (knee.z + 0.1, 1.9, -0.45, y1, 0.24), (knee.z - 0.42, 1.62, -0.2, y1 - 0.14, 0.2)]) + made = [hard(f"Thigh.guard.{tag}", [G @ Vector(p) for p in pts], th, P, clad=lambda n, c: (G.inverted().to_3x3() @ n).y > 0.5 or abs(n.x) > 0.7, seed=11)] def drums(g): - disc(g, out @ T((0, 0, 0.1)), r_hip, 0.62 if rear else 0.5, rings=4 if rear else 3, bolts=20 if rear else 14) - g.cylinder(RY(90), 0.82 * r_hip, 1.0, 40) - kn = T((0, 0, -l1)) - disc(g, kn @ out @ T((0, 0, 0.42)), r_knee, 0.22, rings=2, bolts=10) - g.cylinder(kn @ RY(90), r_knee, 0.84, 32) - disc(g, kn @ F((0, 0, 0), (-sx, 0, 0), (0, 0, 1)) @ T((0, 0, 0.42)), 0.8 * r_knee, 0.14, rings=2, bolts=8) + for s in (-1, 1): + side = F((0, 0, 0), (s, 0, 0), (0, 0, 1)) + disc(g, side @ T((0, 0, 0.93)), r_hip, 0.3, rings=3, bolts=14) + disc(g, T((0, 0, -l1)) @ side @ T((0, 0, 0.93)), r_knee, 0.22, rings=2, bolts=10) + g.cylinder(RY(90), 0.8 * r_hip, 1.9, 40) + g.cylinder(T((0, 0, -l1)) @ RY(90), 0.9 * r_knee, 1.9, 32) geo(f"Thigh.drums.{tag}", "machine", th, drums) - def shin(g): - g.box(T((0, 0, -0.5 * l2)), (0.74, 0.7, l2)) - g.cylinder(T((0, 0, -l2)) @ RY(90), 0.4, 1.0, 24) - if rear: - g.box(T((0, 0.3, -0.45 * l2)), (0.5, 0.4, 0.7 * l2)) - geo(f"Shin.column.{tag}", CORE, sh, shin, bevel=0.015) - made = [] - if rear: - # the guard plate behind the lower thigh (the hero's plate standing up from the hock), its face aft - sheet = shield_sheet(1.5, -0.42 * l1, -l1 - 0.25, 0.62, 0.16, 0.05) - made.append(MS.cage_shell(f"Thigh.guard.{tag}", sheet, th, RZ(180), mat=P, thickness=0.12, levels=2, bevel=0.025, inside=(0, 0, -0.7 * l1))) - # the propulsion rams: from the fixed housing under the hip, either side of the beams' middle, to the hock - M.update() - to_hip = hipb.matrix_world.inverted() @ th.matrix_world - a = [to_hip @ Vector((0, y, z)) for y in (0.7, 0.95, 1.2) for z in (0.3, 0.0, -0.3)] - fit, objs = Q.drive(f"Leg.ram.{tag}", hipb, th, a, [(0, 0.34, -k * l1) for k in (0.9, 0.8, 0.7)], 0.15, RECORDS["hip_pitch_rear"][0], twin=0.26) - made += objs - else: - # the thigh's guard hangs upright at the stance, a boxed shroud before the hip and over the knee: the concept's - # front leg reads as a pillar, whatever the thigh's lean under it - M.update() - upright = (th.matrix_world.inverted() @ hipb.matrix_world).to_3x3().to_4x4() - knee = upright.inverted() @ Vector((0, 0, -l1)) - sheet = shield_sheet(2.0, 1.0, knee.z - 0.45, knee.y + 0.55, 0.14, 0.4) - made.append(MS.cage_shell(f"Thigh.guard.{tag}", sheet, th, upright @ T((sx * 0.25, 0, 0)), mat=P, thickness=0.14, levels=2, bevel=0.03, inside=(0, 0, 0.5 * knee.z))) - sheet = shield_sheet(1.45, 0.25, -l2 + 0.1, 0.5, 0.12, -0.2) - made.append(MS.cage_shell(f"Shin.guard.{tag}", sheet, sh, T((sx * 0.1, 0, 0)), mat=P2, thickness=0.11, levels=2, bevel=0.025, inside=(0, 0, -0.5 * l2))) - to_hip = hipb.matrix_world.inverted() @ th.matrix_world - a = [to_hip @ Vector((0, y, z)) for y in (-0.5, -0.75, -1.0) for z in (0.9, 0.6, 0.3)] - fit, objs = Q.drive(f"Leg.ram.{tag}", hipb, th, a, [(0, -0.52, -k * l1) for k in (0.95, 0.8, 0.65)], 0.11, RECORDS["hip_pitch_front"][0]) - made += objs - return made + geo(f"Shin.column.{tag}", CORE, sh, lambda g: (g.box(T((0, 0, -0.5 * l2)), (1.2, 0.8, l2)), g.cylinder(T((0, 0, -l2)) @ RY(90), 0.42, 1.5, 24)), bevel=0.015) + made.append(hard(f"Shin.guard.{tag}", housing_pts([(0.02, 1.5, -0.42, 0.62, 0.18), (-0.3, 1.74, -0.5, 0.76, 0.2), (-l2 + 0.3, 1.9, -0.56, 0.84, 0.22), (-l2 + 0.08, 1.7, -0.46, 0.72, 0.2)]), sh, P2, clad=face, seed=12)) + M.update() + to_hip = hipb.matrix_world.inverted() @ th.matrix_world + a = [to_hip @ Vector((0, y, z)) for y in (-0.6, -0.85, -1.1) for z in (0.9, 0.6, 0.3)] + fit, objs = Q.drive(f"Leg.ram.{tag}", hipb, th, a, [(0, -0.66, -k * l1) for k in (0.95, 0.8, 0.65)], 0.11, RECORDS["hip_pitch_front"][0]) + return made + objs + + +def leg_rear(tag, bones, pose): + """A rear leg, REAR LEG PROPULSION ASSEMBLY inset with orientation and exposure from the side view and the hero: + longer, its hydraulics exposed. A great stepped bearing stack outboard of the hip; a long open twin-beam thigh; + two chromed rams under it from a mount on the hull's hip housing to the hock, seated by ram core (the hip's + pitch); an armoured shroud over the thigh's head and a tall guard plate standing off the back of its lower + half; a bearing either side of the hock; a short armoured shin.""" + sx = -1 if tag[-1] == "l" else 1 + th, sh, hipb = bones[f"Thigh.{tag}"], bones[f"Shin.{tag}"], bones[f"Bone.hip_splay.{tag}"] + l1, l2 = (float(json.loads(o["kit_params"])["length"]) for o in (th, sh)) + out = F((0, 0, 0), (sx, 0, 0), (0, 0, 1)) + inb = F((0, 0, 0), (-sx, 0, 0), (0, 0, 1)) + kn = T((0, 0, -l1)) + + def thigh(g): + for s in (-1, 1): + g.sweep([(s * 0.52, 0, 0), (s * 0.52, 0, -l1)], [(-0.09, -0.32), (0.09, -0.32), (0.09, 0.32), (-0.09, 0.32)], (0, 1, 0)) + g.sweep([(s * 0.52, -0.3, -0.1 * l1), (s * 0.52, -0.3, -0.95 * l1)], [(-0.13, -0.05), (0.13, -0.05), (0.13, 0.05), (-0.13, 0.05)], (0, 1, 0)) + for z in (0.3, 0.46, 0.62, 0.78): + g.box(T((0, 0.1, -z * l1)), (1.0, 0.2, 0.26)) + g.rod((0, -0.12, -0.2 * l1), (0, -0.12, -0.92 * l1), 0.16, 16) + g.cylinder(kn @ RY(90), 0.34, 1.5, 24) + geo(f"Thigh.girder.{tag}", CORE, th, thigh, bevel=0.015) + + def bearings(g): + stack(g, out) + g.cylinder(RY(90), 0.98, 1.3, 48) + g.lathe(inb, [(0, 0.6), (1.05, 0.6), (1.05, 0.72), (0.6, 0.72), (0.6, 0.8), (0, 0.8)], 40) + for at in (kn @ out, kn @ inb): + disc(g, at @ T((0, 0, 0.62)), 0.62, 0.24, rings=3, bolts=12) + geo(f"Thigh.drums.{tag}", "machine", th, bearings) + + behind = lambda n, c: n.y < -0.5 # noqa: E731 + made = [hard(f"Thigh.shroud.{tag}", housing_pts([(-0.75, 1.5, -1.08, -0.25, 0.2), (-1.35, 1.62, -1.12, -0.2, 0.22), (-0.42 * l1, 1.5, -0.98, -0.2, 0.2), (-0.42 * l1 - 0.3, 1.2, -0.8, -0.2, 0.16)]), th, P2, clad=behind, seed=21)] + zt, zb = -0.4 * l1, -l1 - 0.35 + outline = [(-0.5, zt), (0.5, zt), (0.8, zt - 0.4), (0.8, zb + 0.35), (0.55, zb), (-0.55, zb), (-0.8, zb + 0.35), (-0.8, zt - 0.4)] + made.append(hard(f"Thigh.guard.{tag}", [(x, -0.86, z) for x, z in outline] + [(1.06 * x, -0.56, z + 0.04 * (1 if z > 0.5 * (zt + zb) else -1)) for x, z in outline], th, P, clad=behind, seed=22)) + geo(f"Thigh.struts.{tag}", CORE, th, lambda g: [g.box(T((s * 0.52, -0.46, z * l1)), (0.2, 0.3, 0.3)) for s in (-1, 1) for z in (-0.5, -0.72, -0.94)]) + + geo(f"Shin.column.{tag}", CORE, sh, lambda g: (g.box(T((0, 0, -0.5 * l2)), (0.9, 0.7, l2)), g.cylinder(T((0, 0, -l2)) @ RY(90), 0.4, 1.3, 24), g.box(T((0, 0.3, -0.45 * l2)), (0.6, 0.4, 0.7 * l2))), bevel=0.015) + made.append(hard(f"Shin.guard.{tag}", housing_pts([(-0.1, 1.3, -0.62, -0.15, 0.14), (-l2 + 0.05, 1.5, -0.7, -0.15, 0.16)]), sh, P2, clad=behind, seed=23)) + + # the propulsion rams: from the hull's mount ahead of and under the hip to the hock, a pair either side of the beams' middle + M.update() + to_hip = hipb.matrix_world.inverted() @ th.matrix_world + a = [to_hip @ Vector((0, y, z)) for y in (0.85, 1.1, 1.35) for z in (0.25, -0.05, -0.35)] + fit, objs = Q.drive(f"Leg.ram.{tag}", hipb, th, a, [(0, 0.44, -k * l1) for k in (0.93, 0.85, 0.77)], 0.18, RECORDS["hip_pitch_rear"][0], twin=0.3) + if fit is not None: + from brokkr_kitbash import ram as R + base = Vector(R.pose(fit.m, [0.0]).base[0]) + axis = (to_hip.to_3x3() @ Vector((1, 0, 0))).normalized() + toward = (-base).normalized() + pts = [base + axis * s * 0.62 + d for s in (-1, 1) for d in (toward * -0.3, toward.cross(axis) * 0.3, toward.cross(axis) * -0.3)] + [axis * s * 0.6 + toward.cross(axis) * k for s in (-1, 1) for k in (-0.5, 0.5)] + objs.append(MS.hard(f"Leg.ram.mount.{tag}", pts, hipb, CORE, bevel=0.03)) + return made + objs def foot(tag, bones, pose): @@ -354,7 +420,6 @@ def foot(tag, bones, pose): f.done() return f - # --- turret ------------------------------------------------------------------------------------------------------------- def turret_ring(host): """The reinforced circular bearing on the crown (the plan view's ring): a bolted outer race on the deck.""" @@ -407,117 +472,133 @@ def gun(gb): return out -def detail(): - """The detail pass by surface.py on the plates (its Skin reads a massing plate's own face): the 03 on each cheek - band, the wings on the chin, panel lines, bolt rows inside the rims, hatches on the upper plates. A feature that - misses its plate is reported, not drawn. Returns (made, failed).""" +# --- detail ---------------------------------------------------------------------------------------------------------------- +def ray_down(xy, keep=lambda name: name.startswith("Hull.")): + """Where a ray straight down meets the hull's plates at a plan point: (point, normal, object) in the world.""" + dg = bpy.context.evaluated_depsgraph_get() + origin = Vector((xy[0], xy[1], 30.0)) + for _ in range(8): + ok, loc, nor, _, obj, _ = bpy.context.scene.ray_cast(dg, origin, Vector((0, 0, -1))) + if not ok: + return None + if keep(obj.name): + return loc, nor, obj + origin = loc - Vector((0, 0, 0.002)) + return None + + +def detail(plates, host): + """The detail pass on the hard plates (massing.Face stands in for surface.py's Skin): the 03 on each skirt and the + wings on the chin, each on a raised panel of its own; bolt rows round the collar and along the brow; grab + handles and lifting eyes on the pods. Returns (made, failed).""" import surface as S S.materials() - made, failed = [0], [] - - def on(plate, steps): - if plate not in bpy.data.objects: - failed.append(f"{plate}: no such plate") - return - try: - skin = S.Skin(plate) - except BaseException as error: - failed.append(f"{plate}: {type(error).__name__} {error}") - return - for label, step in steps: - try: - step(skin) - made[0] += 1 - except BaseException as error: - failed.append(f"{plate} {label}: {type(error).__name__} {error}") - try: - skin.prune() - skin.commit() - except BaseException as error: - failed.append(f"{plate} commit: {type(error).__name__} {error}") - - def rim(k, spacing=0.4): - return (f"bolts on rim {k}", lambda s: S.bolt_row(s, S.along(s, ("rim", k), spacing=spacing, offset=0.12, margin=0.2), r=0.03)) - for sx, tag in ((-1, "L"), (1, "R")): - side = ((sx * 9.0, 3.2, 5.9), (-sx, 0, 0)) - on(f"Hull.CheekBand.{tag}", [("03", lambda s: S.numeral(s, s.at(*side), "03", 0.75, "marking_fresh")), rim(0), - ("hatch", lambda s: S.hatch(s, s.at((sx * 9.0, 2.0, 5.75), (-sx, 0, 0)), size=(0.6, 0.5)))]) - on(f"Hull.CheekUp.{tag}", [rim(0), ("hatch", lambda s: S.hatch(s, s.at((sx * 3.0, 3.2, 12.0), (0, 0, -1), up=(0, 1, 0)), size=(0.8, 0.6))), - ("port", lambda s: S.access_port(s, s.at((sx * 3.4, 2.2, 12.0), (0, 0, -1), up=(0, 1, 0)), r=0.16))]) - on(f"Hull.RearUp.{tag}", [rim(0), ("louvres", lambda s: S.louvre_bank(s, s.at((sx * 2.6, -3.4, 12.0), (0, 0, -1), up=(0, 1, 0)), size=(0.9, 0.6), slats=6))]) - on(f"Hull.RearBand.{tag}", [rim(0), ("port", lambda s: S.access_port(s, s.at((sx * 9.0, -3.2, 6.3), (-sx, 0, 0)), r=0.18))]) - on(f"Hull.FlankUp.{tag}", [rim(0)]) - on("Hull.Chin", [("wings", lambda s: S.emblem(s, s.at((0, 9.0, 4.45), (0, -1, 0)), "wings", 0.6, "marking_fresh")), rim(0)]) - on("Hull.Glacis", [rim(0), ("hatch", lambda s: S.hatch(s, s.at((0.9, 4.4, 12.0), (0, 0, -1), up=(0, 1, 0)), size=(0.7, 0.6))), - ("panel", lambda s: S.inset(s, s.at((-0.8, 4.6, 12.0), (0, 0, -1), up=(0, 1, 0)), size=(0.8, 0.5)))]) - on("Hull.Crown", [rim(0, 0.5)]) - print(f"DETAIL {made[0]} features made; {len(failed)} failed", flush=True) + made, failed = 0, [] + for sx, tag in ((1, "R"), (-1, "L")): + sk = plates[f"Hull.Skirt.{tag}"] + n = Vector((sx * BF.NUMERAL["normal"][0], BF.NUMERAL["normal"][1], BF.NUMERAL["normal"][2])) + g = M.Geo() + MS.panel(g, [(sx * x, y, z) for x, y, z in BF.SKIRT["points"][:6]], lift=0.06, inset=0.13, out=n) + o = g.to_object(f"Hull.Skirt.{tag}.panels", P, host, 1.0) + face = MS.Face(o, P) + at = Vector((sx * BF.NUMERAL["at"][0], BF.NUMERAL["at"][1], BF.NUMERAL["at"][2])) + n * 0.068 + S.numeral(face, F(at, n), BF.NUMERAL["text"], BF.NUMERAL["height"], "marking_fresh") + face.done() + made += 2 + chin = plates["Hull.Chin"] + n = Vector(BF.EMBLEM["normal"]).normalized() + c = BF.CHIN["points"] + g = M.Geo() + MS.panel(g, [c[1], (-c[1][0], c[1][1], c[1][2]), (-c[5][0], c[5][1], c[5][2]), c[5]], lift=0.06, inset=0.1, out=n) + o = g.to_object("Hull.Chin.panels", P2, host, 1.0) + face = MS.Face(o, P2) + S.emblem(face, F(Vector(BF.EMBLEM["at"]) + n * 0.068, n), "wings", BF.EMBLEM["height"], "marking_fresh") + face.done() + made += 2 + M.update() + fit = MS.Face(plates["Hull.Collar"], "gunmetal") + for k in range(8): + a = math.radians(45.0 * k) + for off in (-0.8, 0.0, 0.8): + hit = ray_down((3.2 * math.sin(a) + off * math.cos(a), 3.2 * math.cos(a) - off * math.sin(a)), keep=lambda name: name == "Hull.Collar") + if hit: + S.bolt_row(fit, [F(hit[0], hit[1])], r=0.04, mat="gunmetal") + made += 1 + for sx in (-1, 1): + for xy, length, turn in (((sx * 3.9, -2.9), 0.7, 20.0 * sx), ((sx * 3.3, -3.9), 0.6, 60.0 * sx), ((sx * 3.9, 2.6), 0.7, -10.0 * sx), ((sx * 1.1, 4.6), 0.6, 90.0)): + hit = ray_down(xy) + if hit: + S.grab_handle(fit, F(hit[0], hit[1], (0, 1, 0)) @ RZ(turn), length=length, lift=0.11, r=0.025) + made += 1 + else: + failed.append(f"handle at {xy}: no plate under it") + for xy in ((sx * 4.2, 1.4), (sx * 2.9, 4.4), (sx * 4.3, -1.9)): + hit = ray_down(xy) + if hit: + S.lifting_eye(fit, F(hit[0], hit[1], (0, 1, 0)), size=0.16) + made += 1 + fit.done() + print(f"DETAIL {made} features made; {len(failed)} failed", flush=True) for f in failed: print(" DETAIL failed:", f, flush=True) - return made[0], failed + return made, failed # --- the build ------------------------------------------------------------------------------------------------------------ -def run(mass, at, stand): +def body(trunk, at): + """The hull: its mass (bastion_body.hull), the magazines' wells cut from the core, and from the full stage its + detail plating.""" + plates, dark = BB.hull(trunk) + M.update() + cuts = [MS.slab(f"Magazine.cut.{'L' if sx < 0 else 'R'}", (sx * (BF.MAG["face"] - 0.5 * BF.MAG["depth"] + 0.3), 0.5 * (BF.MAG["y0"] + BF.MAG["y1"]), 0.5 * (BF.MAG["z0"] + BF.MAG["z1"])), + (BF.MAG["depth"] + 0.6, BF.MAG["y1"] - BF.MAG["y0"] + 0.2, BF.MAG["z1"] - BF.MAG["z0"] + 0.2), BB.I4) for sx in (-1, 1)] + MS.carve(dark["Core.upper"], cuts) + HARD.update(BB.report(plates)) + if at >= 2: + made = BB.plating(plates, trunk) + print("PLATING", sum(made.values()), "panels on", len(made), "plates", flush=True) + return plates, dark + + +def run(at, stand): pose = {k: list(v) for k, v in stand.items()} ring = BF.RING trunnion = (0.0, 1.75, ring[2] + 0.68) bones = part("skeleton", Q.build, pose, RECORDS, pin=2 * FOOT_PIN, turret={"ring": list(ring), "trunnion": list(trunnion), "yaw": 0.0, "pitch": 2.0}) trunk = bones["Trunk"] print("SKELETON miss", round(Q.miss(bones, pose), 4), "m", flush=True) - mass.parent = trunk - for t in Q.LEGS: - part(f"hip {t}", hip_housing, t, trunk, pose[f"hip_{t}"], t[0] == "r") - part(f"leg {t}", leg_dress, t, bones, pose) - part(f"foot {t}", foot, t, bones, pose) - part("turret ring", turret_ring, trunk) - part("turret", turret, bones["Aim.Turret"]) - part("gun", gun, bones["Aim.Gun"]) - part("cooling", cooling, trunk) + plates, dark = part("hull", body, trunk, at) + if at >= 1: + for t in Q.LEGS: + part(f"hip {t}", hip_housing, t, trunk, pose[f"hip_{t}"], t[0] == "r") + part(f"leg {t}", leg_rear if t[0] == "r" else leg_front, t, bones, pose) + part(f"foot {t}", foot, t, bones, pose) if at >= 2: - skin = mass.copy() - skin.data = mass.data.copy() - bpy.context.scene.collection.objects.link(skin) - skin.hide_render = True - M.update() - cuts = wells() - MS.carve(mass, cuts) part("cockpit", cockpit, trunk) for sx in (-1, 1): + part(f"cheek lamp {sx}", cheek_lamp, trunk, sx) part(f"magazine {sx}", magazine, trunk, sx) - if at >= 3: - M.assign(mass, CORE) - before = set(bpy.data.objects.keys()) - t = time.time() - made = plates(skin, cuts) - for o in made: - o.parent = trunk - if at >= 4: - detail() - M.update() - TIMES["plates"] = round(time.time() - t, 1) - print(f"PART plates: {TIMES['plates']} s, {frozen(before)} frozen", flush=True) - n = 8 - for k in range(n): - a = math.radians(22.5 + 360.0 * k / n) - d = Vector((math.sin(a), math.cos(a), 0)) - hit = ray_down(skin, d * 1.0 + Vector((d.x * 2.9, d.y * 3.6, 0))) - if hit: - part(f"interceptor {k}", interceptor, f"Interceptor.{k}", trunk, T(hit[0] - Vector((0, 0, 0.12))), -math.degrees(a)) - if at >= 2: - bpy.data.objects.remove(skin, do_unlink=True) - report = Q.report(trunk, more=[bones[f"Ankle.{t}"] for t in Q.LEGS]) - rows = report["joints"] - print("JOINTS", report["schema"], len(rows), "rows;", json.dumps({m: sum(1 for r in rows if r["mechanism"] == m) for m in sorted({str(r["mechanism"]) for r in rows})}), flush=True) - out = os.environ.get("MECH_OUT") - if out: - with open(os.path.join(out, "bastion", "bastion_joints.json"), "w", encoding="utf-8") as fh: - json.dump(report, fh, indent=1) + part("turret ring", turret_ring, trunk) + part("turret", turret, bones["Aim.Turret"]) + part("gun", gun, bones["Aim.Gun"]) + part("cooling", cooling, trunk) + k = 0 + for sx in (-1, 1): + for x, y in BF.INTERCEPTORS: + hit = ray_down((sx * x, y)) + if hit: + part(f"interceptor {k}", interceptor, f"Interceptor.{k}", trunk, T(hit[0] - Vector((0, 0, 0.1))), -math.degrees(math.atan2(sx * x, y))) + k += 1 + part("detail", detail, plates, trunk) + report = Q.report(trunk, more=[bones[f"Ankle.{t}"] for t in Q.LEGS]) + rows = report["joints"] + print("JOINTS", report["schema"], len(rows), "rows;", json.dumps({m: sum(1 for r in rows if r["mechanism"] == m) for m in sorted({str(r["mechanism"]) for r in rows})}), flush=True) + out = os.environ.get("MECH_OUT") + if out: + with open(os.path.join(out, "bastion", "bastion_joints.json"), "w", encoding="utf-8") as fh: + json.dump(report, fh, indent=1) + with open(os.path.join(out, "bastion", "bastion_plates.json"), "w", encoding="utf-8") as fh: + json.dump({"kinds": BF.KINDS, "plates": HARD}, fh, indent=1) + print("HARD", len(HARD), "hard plates;", json.dumps({k: v["corners"] for k, v in sorted(HARD.items())}), flush=True) print("TIMES", json.dumps(TIMES), flush=True) return bones - - -def ray_down(obj, xy): - """Where a ray straight down meets the mass at a plan point: (point, normal) in the world.""" - ok, loc, nor, _ = obj.ray_cast(obj.matrix_world.inverted() @ Vector((xy.x, xy.y, 20.0)), Vector((0, 0, -1))) - return (obj.matrix_world @ loc, (obj.matrix_world.to_3x3() @ nor).normalized()) if ok else None diff --git a/surfaces/blender/experiments/mechs/bastion_cameras.json b/surfaces/blender/experiments/mechs/bastion_cameras.json index 2a566c2..0d8b91c 100644 --- a/surfaces/blender/experiments/mechs/bastion_cameras.json +++ b/surfaces/blender/experiments/mechs/bastion_cameras.json @@ -23,10 +23,10 @@ 0.0 ] ], - "f": 10549.880922862098, + "f": 10557.412793807414, "c": [ - 365.2180216639705, - 743.9939909588088 + 365.1563151584422, + 744.2078878263869 ], "box": [ 237, @@ -49,76 +49,106 @@ "trunnion", "cupola", "block", - "emblem" + "emblem", + "lamp_l", + "num_l", + "mag_l", + "cool_l", + "disc_fl", + "disc_rl" ], "model": "elevation", - "scale_m_per_px": 0.05687267983279046, - "rms": 1.5321926572259845, + "scale_m_per_px": 0.056832105717410014, + "rms": 1.4367184172690377, "residuals": { "ring": [ - 0.2180216639704895, - -1.2428670565559514 + 0.15631515844222577, + -1.127661556403723 ], "hip_fl": [ - 0.04593864145988391, - -0.6582036164438705 + -0.06943542981207429, + -0.4890359972271199 ], "knee_fl": [ - -0.018879551606630685, - 0.12786938593023933 + -0.14857848799101703, + 0.3147325132251808 ], "ankle_fl": [ - -0.0138921575945119, - 1.5256890900922144 + -0.1421596743819009, + 1.7285426810428817 ], "hip_rl": [ - 0.3249497391885825, - -0.832180574321228 + 0.31686428336672634, + -0.6767018224018102 ], "knee_rl": [ - 0.672118244926196, - 0.11758989670329356 + 0.7014049756172653, + 0.312298909389483 ], "ankle_rl": [ - 0.6202108219420097, - 0.43246697745144047 + 0.6437490585963133, + 0.6381097322869209 ], "nose": [ - -1.4229269419024035, - 0.4620842264175735 + -1.5621954227988795, + 0.6056362615818216 ], "tail": [ - -0.9131588857168822, - 0.5708331673771454 + -0.9007103795381681, + 0.6980424636977887 ], "muzzle": [ - 0.3444739988335641, - -4.561957334486692 + 0.20932303546106823, + -4.448407501238421 ], "trunnion": [ - 0.38350918282208113, - 0.6417563897421132 + 0.2969332920969805, + 0.7583073781213443 ], "cupola": [ - 0.10927272301091762, - 0.7410489010529773 + 0.0639089563262587, + 0.8426782583142085 ], "block": [ - -0.44392841143576334, - 0.4857253005391158 + -0.40615737617679315, + 0.6257245663896356 ], "emblem": [ - 0.6908431464034948, - 0.5483091806593166 + 0.558081254598676, + 0.7026317164802549 + ], + "lamp_l": [ + -0.004523809981151317, + -1.4603820770096263 + ], + "num_l": [ + 0.004018906918531684, + -1.472714634620047 + ], + "mag_l": [ + 0.17174129457390563, + -0.7967541691548377 + ], + "cool_l": [ + 0.4260376883154322, + -1.225596461806731 + ], + "disc_fl": [ + -0.17424490152234284, + -0.5763894820701125 + ], + "disc_rl": [ + 0.4782185937817758, + -0.8524912711250181 ] }, - "lens": 1332.616537624686, + "lens": 1333.5679318493576, "azimuth": 90.0, "elevation": 0.0, "distance": 600.0, "worst": [ "muzzle", - 4.57494448682706 + 4.453329701498519 ] }, "front": { @@ -144,10 +174,10 @@ -0.0 ] ], - "f": 10243.955912558718, + "f": 10194.252514955515, "c": [ - 118.00000000000011, - 742.3042866937758 + 117.97368421052636, + 742.0096773058192 ], "box": [ 0, @@ -167,64 +197,104 @@ "ring", "flank_l", "flank_r", - "emblem" + "emblem", + "lamp_l", + "lamp_r", + "num_l", + "num_r", + "mag_l", + "mag_r", + "disc_fl", + "disc_fr" ], "model": "elevation", - "scale_m_per_px": 0.05857112282808849, - "rms": 1.462801137908827, + "scale_m_per_px": 0.058856693918437654, + "rms": 1.227410336571514, "residuals": { "hip_fl": [ - 1.2865472539539553, - -0.5353431206955293 + 0.9094990882190928, + -0.5347602668548461 ], "hip_fr": [ - -1.286547253953728, - -0.5353431206955293 + -0.9621306671663632, + -0.5347602668548461 ], "knee_fl": [ - 1.4642878560768224, - -0.5290292372160366 + 1.0766733517177158, + -0.6449243704072387 ], "knee_fr": [ - -1.464287856076595, - -0.5290292372160366 + -1.1293049306649863, + -0.6449243704072387 ], "ankle_fl": [ - 1.4501136316823988, - -0.73925023832021 + 1.062567900277486, + -0.9608687911076004 ], "ankle_fr": [ - -1.4501136316821714, - -0.73925023832021 + -1.1151994792247564, + -0.9608687911076004 ], "muzzle": [ - 1.1368683772161603e-13, - 2.480229922947956 + -0.026315789473642326, + 2.854339138570026 ], "ring": [ - 1.1368683772161603e-13, - 0.07601536501647388 + -0.026315789473642326, + 0.43267792672384076 ], "flank_l": [ - -0.19810083281382163, - -0.7216661984898565 + -0.645577094262137, + -0.574620119805104 ], "flank_r": [ - 0.198100832814049, - -0.7216661984898565 + 0.5929455153148666, + -0.574620119805104 ], "emblem": [ - 1.1368683772161603e-13, - -1.4933161568810647 + -0.026315789473642326, + -1.3910457835248735 + ], + "lamp_l": [ + 1.0494704300367346, + -0.6762084344363757 + ], + "lamp_r": [ + -0.6021020089840263, + -0.17620843443637568 + ], + "num_l": [ + 0.7538109185561837, + -0.29686215675178573 + ], + "num_r": [ + -0.8064424975034683, + -0.29686215675178573 + ], + "mag_l": [ + 0.4564584804569449, + -0.3280100309751788 + ], + "mag_r": [ + -0.5090900594042296, + -0.3280100309751788 + ], + "disc_fl": [ + 1.094025965510582, + -0.5347602668548461 + ], + "disc_fr": [ + -1.1466575444578524, + -0.5347602668548461 ] }, - "lens": 1556.0439360848684, + "lens": 1548.4940529046353, "azimuth": 0.0, "elevation": -0.0, "distance": 600.0, "worst": [ "muzzle", - 2.480229922947956 + 2.854460446169871 ] }, "rear": { @@ -250,10 +320,10 @@ -0.0 ] ], - "f": 10352.694133391838, + "f": 10352.470275288557, "c": [ - 651.4285714285712, - 742.0112732454559 + 651.818181818182, + 741.9097172750725 ], "box": [ 522, @@ -269,48 +339,68 @@ "knee_rr", "ankle_rl", "ankle_rr", - "ring" + "ring", + "cool_l", + "cool_r", + "disc_rl", + "disc_rr" ], "model": "elevation", - "scale_m_per_px": 0.05795592840560652, - "rms": 1.0198824491435732, + "scale_m_per_px": 0.05795718162381066, + "rms": 1.382221262636801, "residuals": { "hip_rl": [ - -0.6437456768096581, - -0.36072657028705635 + -0.2527498403580921, + -0.46054464295957587 ], "hip_rr": [ - 0.500888533952093, - -0.36072657028705635 + 0.8891134767220592, + -0.46054464295957587 ], "knee_rl": [ - -1.270375107618861, - -0.4617362121722408 + -0.8788900116294371, + -0.5627197520743721 ], "knee_rr": [ - 1.1275179647612958, - -0.4617362121722408 + 1.5152536479934042, + -0.5627197520743721 ], "ankle_rl": [ - -1.177701465837913, - -0.37025075480130454 + -0.7862616200940238, + -0.47156062051453773 ], "ankle_rr": [ - 1.034844322980348, - -0.37025075480130454 + 1.4226252564579909, + -0.47156062051453773 ], "ring": [ - 0.42857142857121744, - 0.35818678332600484 + 0.8181818181819835, + 0.2595640631910783 + ], + "cool_l": [ + -2.5647240158962177, + -1.262393201365171 + ], + "cool_r": [ + -0.7989123477398152, + -1.262393201365171 + ], + "disc_rl": [ + -0.4505529346555477, + -0.46054464295957587 + ], + "disc_rr": [ + 1.0869165710195148, + -0.46054464295957587 ] }, - "lens": 1406.4037313287026, + "lens": 1406.3733204165587, "azimuth": 180.0, "elevation": -0.0, "distance": 600.0, "worst": [ - "knee_rl", - 1.35168533456896 + "cool_l", + 2.858574097792084 ] }, "top": { @@ -396,28 +486,28 @@ }, "hero": { "C": [ - -21.401224826667082, - 20.832214777219917, - 1.5983239046664677 + -47.90595422438004, + 42.161968415918594, + 1.4191744957315824 ], "R": [ [ - -0.6937977676765082, - -0.7201698810468916, + -0.6601358668867912, + -0.751146215626242, 0.0 ], [ - -0.0770954889717917, - 0.0742723065130173, - 0.9942534435773592 + -0.03715072306682777, + 0.03264946859479947, + 0.9987761691070173 ], [ - -0.7160313841915691, - 0.6898108196586529, - -0.10705180958098395 + -0.7502269396824115, + 0.6593279722193292, + -0.04945871029364722 ] ], - "f": 1459.3742244264236, + "f": 3172.618149221271, "c": [ 512.0, 280.0 @@ -430,112 +520,132 @@ ], "unit": 1024, "names": [ - "hip_fl", "hip_fr", - "hip_rl", "knee_rl", "ankle_fl", "ankle_fr", "ankle_rl", "muzzle", - "emblem" + "emblem", + "nose", + "lamp_l", + "lamp_r", + "num_l", + "mag_l", + "cool_l", + "disc_fl", + "disc_rl" ], - "rms": 28.830695433314496, - "rms_h": 0.05686527698878599, - "median": 18.65280182595586, + "rms": 20.943841905081147, + "rms_h": 0.04130935286998254, + "median": 16.657152024413485, "worst": [ - "hip_rl", - 65.58658976067986 + "nose", + 32.27450058599836 ], - "left_out": 40.57531044119979, + "left_out": 28.18640363364716, "model": "upright", "tried": { "upright": { - "rms": 28.830695433314496, - "left_out": 40.57531044119979, - "lens": 51.30612507749145 + "rms": 20.943841905081147, + "left_out": 28.18640363364716, + "lens": 111.5373568085603 } }, - "lens": 51.30612507749145, + "lens": 111.5373568085603, "lens_range": [ - 34.39152412385434, - 126.19270486200558 + 67.65082660769946, + 674.7616878042289 ], - "azimuth": 45.64390496556719, - "elevation": -3.1922127370566113, - "distance": 27.8768008864902, + "azimuth": 48.48302871274557, + "elevation": -2.6020817895897363, + "distance": 61.450849301437444, "roll": 0.0, "twist": 0.0, "horizon": [ 437.0, - 437.1316172852039 + 437.1058729354695 ], "residuals": { - "hip_fl": [ - -20.14885881211933, - -13.692356297364029 - ], "hip_fr": [ - 6.755832757879091, - -2.83406741611617 - ], - "hip_rl": [ - -65.15173117749214, - 7.540071684772897 + -2.49218604880582, + -12.743772814481076 ], "knee_rl": [ - -1.0426390666935959, - -13.976272294239493 + 14.319774649406213, + -22.637929633071565 ], "ankle_fl": [ - 26.34853208550919, - 18.617022757220866 + 8.252974760583243, + 2.522530990081634 ], "ankle_fr": [ - -10.988721886978169, - 11.722351237037856 + -15.938884839742911, + 2.4151637975302265 ], "ankle_rl": [ - 18.974495151886913, - 0.26636239069694057 + 30.503326399973957, + -7.125873195922225 ], "muzzle": [ - -12.857678146792637, - 12.781747952606338 + -17.192120072959426, + 22.22808537300358 ], "emblem": [ - 15.935587520105855, - -9.694537964618462 + 13.211494101937035, + -8.508821438490259 + ], + "nose": [ + -28.528237796149824, + 15.092482775273822 + ], + "lamp_l": [ + -2.342764544462966, + 13.47074309029972 + ], + "lamp_r": [ + 21.380793327582126, + 9.554043601906642 + ], + "num_l": [ + 9.907287200803808, + 1.168046215916263 + ], + "mag_l": [ + 1.9366325255346055, + -1.6247022747182882 + ], + "cool_l": [ + -16.088582655125265, + 19.11382039534294 + ], + "disc_fl": [ + -11.087492701360247, + -12.430937983985984 + ], + "disc_rl": [ + -19.94398576616345, + -12.609927008899604 ] }, "solved": { - "hip_fl": [ - -4.203947368421052, - 4.245283018867925, - 3.5382323733862955 - ], "hip_fr": [ - 4.203947368421052, + 4.203947368421053, 4.245283018867925, 3.5382323733862955 ], - "hip_rl": [ - -3.6870967741935488, - -4.245283018867925, - 4.62507608034084 - ], "knee_rl": [ -4.964516129032258, -7.188679245283019, 1.5158855751673768 ], "ankle_fl": [ - -4.322368421052631, + -4.322368421052632, 5.264150943396227, 0.8733862959285005 ], "ankle_fr": [ - 4.322368421052631, + 4.322368421052632, 5.264150943396227, 0.8733862959285005 ], @@ -553,18 +663,98 @@ 0.0, 5.660377358490567, 4.745779543197616 + ], + "nose": [ + 0.0, + 6.178701886792453, + 5.60377358490566 + ], + "lamp_l": [ + -3.65625, + 4.3584905660377355, + 5.06498262164846 + ], + "lamp_r": [ + 3.65625, + 4.3584905660377355, + 5.06498262164846 + ], + "num_l": [ + -4.796052631578947, + 2.150943396226415, + 5.647964250248262 + ], + "mag_l": [ + -5.032894736842104, + -0.19811320754716982, + 6.142999006951341 + ], + "cool_l": [ + -3.6870967741935488, + -7.132075471698113, + 7.254290931223372 + ], + "disc_fl": [ + -5.032894736842104, + 4.245283018867925, + 3.5382323733862955 + ], + "disc_rl": [ + -4.964516129032258, + -4.245283018867925, + 4.62507608034084 ] + }, + "hull_only": { + "rms": 18.011066521413937, + "names": [ + "hip_fr", + "muzzle", + "emblem", + "nose", + "lamp_l", + "lamp_r", + "num_l", + "mag_l", + "cool_l", + "disc_fl", + "disc_rl" + ], + "lens": 223.58920875803136, + "C": [ + -91.07651985993354, + 82.8077594253626, + 1.439359573068422 + ], + "leg_miss_px": { + "knee_rl": [ + 31.73780618058663, + -21.88119895894124 + ], + "ankle_fl": [ + 14.444053686183167, + 2.9964105198682773 + ], + "ankle_fr": [ + -29.173677749816477, + 4.382759676489343 + ], + "ankle_rl": [ + 46.4009179884863, + -4.570948416206761 + ] + } } } }, "stand": { "ankle_fl": [ - -4.322368421052631, + -4.322368421052632, 5.264150943396227, 0.8733862959285005 ], "ankle_fr": [ - 4.322368421052631, + 4.322368421052632, 5.264150943396227, 0.8733862959285005 ], @@ -583,11 +773,41 @@ -7.9245283018867925, 5.886792452830189 ], + "cool_l": [ + -3.6870967741935488, + -7.132075471698113, + 7.254290931223372 + ], + "cool_r": [ + 3.6870967741935488, + -7.132075471698113, + 7.254290931223372 + ], "cupola": [ 0.0, -1.3018867924528301, 8.943396226415095 ], + "disc_fl": [ + -5.032894736842104, + 4.245283018867925, + 3.5382323733862955 + ], + "disc_fr": [ + 5.032894736842104, + 4.245283018867925, + 3.5382323733862955 + ], + "disc_rl": [ + -4.964516129032258, + -4.245283018867925, + 4.62507608034084 + ], + "disc_rr": [ + 4.964516129032258, + -4.245283018867925, + 4.62507608034084 + ], "emblem": [ 0.0, 5.660377358490567, @@ -604,12 +824,12 @@ 5.328947368421052 ], "hip_fl": [ - -4.203947368421052, + -4.203947368421053, 4.245283018867925, 3.5382323733862955 ], "hip_fr": [ - 4.203947368421052, + 4.203947368421053, 4.245283018867925, 3.5382323733862955 ], @@ -624,12 +844,12 @@ 4.62507608034084 ], "knee_fl": [ - -4.322368421052631, + -4.322368421052632, 5.377358490566038, 2.1380337636544193 ], "knee_fr": [ - 4.322368421052631, + 4.322368421052632, 5.377358490566038, 2.1380337636544193 ], @@ -643,6 +863,26 @@ -7.188679245283019, 1.5158855751673768 ], + "lamp_l": [ + -3.65625, + 4.3584905660377355, + 5.06498262164846 + ], + "lamp_r": [ + 3.65625, + 4.3584905660377355, + 5.06498262164846 + ], + "mag_l": [ + -5.032894736842104, + -0.19811320754716982, + 6.142999006951341 + ], + "mag_r": [ + 5.032894736842104, + -0.19811320754716982, + 6.142999006951341 + ], "muzzle": [ 0.0, 5.850694339622642, @@ -653,6 +893,16 @@ 6.178701886792453, 5.60377358490566 ], + "num_l": [ + -4.796052631578947, + 2.150943396226415, + 5.647964250248262 + ], + "num_r": [ + 4.796052631578947, + 2.150943396226415, + 5.647964250248262 + ], "ring": [ 0.0, 0.0, @@ -670,85 +920,133 @@ ] }, "spread": { - "knee_rr": { - "x": 0.0, + "knee_rl": { + "x": 0.04645161290322264, "z": 0.018624467437614145 }, - "hip_rr": { - "x": 0.0, + "ankle_fl": { + "x": 0.0037006578947371693, + "z": 0.1333167825223437 + }, + "hip_rl": { + "x": 0.04645161290322308, "z": 0.060255629945221933 }, - "ankle_fr": { - "x": 0.0, - "z": 0.1333167825223437 + "disc_rr": { + "x": 0.04645161290322264, + "z": 0.060255629945221933 }, - "trunnion": {}, - "ankle_fl": { - "x": 0.0, - "z": 0.1333167825223437 - }, - "flank_l": { - "x": 0.1393157894736845, + "flank_r": { + "x": 0.14116611842105264, "y": 0.0, "z": 0.0 }, - "ankle_rl": { - "x": 0.0, - "z": 0.04053560559951308 + "hip_fr": { + "x": 0.0037006578947371693, + "z": 0.04319761668321709 }, - "emblem": { - "z": 0.017874875868917783 + "lamp_r": { + "x": 0.025904605263157965, + "z": 0.14057845084409148 }, "nose": { "y": 0.2441962264150943 }, - "block": {}, - "ankle_rr": { - "x": 0.0, - "z": 0.04053560559951308 - }, - "knee_fl": { - "x": 0.0, - "z": 0.019364448857994265 + "cupola": {}, + "mag_l": { + "x": 0.0037006578947371693, + "z": 0.04468718967229357 }, "ring": { - "x": 0.02903225806451613, + "x": 0.05225806451612772, "y": 0.0, "z": 0.17949354518371408 }, + "block": {}, + "disc_rl": { + "x": 0.04645161290322264, + "z": 0.060255629945221933 + }, + "ankle_rl": { + "x": 0.04645161290322264, + "z": 0.04053560559951308 + }, + "lamp_l": { + "x": 0.025904605263157965, + "z": 0.14057845084409148 + }, + "mag_r": { + "x": 0.0037006578947371693, + "z": 0.04468718967229357 + }, + "num_r": { + "x": 0.0037006578947371693, + "z": 0.10873882820258185 + }, + "hip_fl": { + "x": 0.0037006578947371693, + "z": 0.04319761668321709 + }, + "disc_fr": { + "x": 0.0037006578947371693, + "z": 0.04319761668321709 + }, + "tail": { + "y": 0.0721962264150946 + }, + "disc_fl": { + "x": 0.0037006578947371693, + "z": 0.04319761668321709 + }, + "cool_r": { + "x": 0.1858064516129061, + "z": 0.09841752891052913 + }, + "hip_rr": { + "x": 0.04645161290322308, + "z": 0.060255629945221933 + }, + "knee_fl": { + "x": 0.0037006578947371693, + "z": 0.019364448857994265 + }, + "num_l": { + "x": 0.0037006578947371693, + "z": 0.10873882820258185 + }, + "trunnion": {}, "muzzle": { - "x": 0.0, + "x": 0.001850328947368421, "y": 0.04101132075471714, "z": 0.5913604766633558 }, - "hip_fr": { - "x": 0.0, - "z": 0.04319761668321709 + "emblem": { + "z": 0.017874875868917783 }, - "flank_r": { - "x": 0.1393157894736845, + "knee_fr": { + "x": 0.0037006578947371693, + "z": 0.019364448857994265 + }, + "ankle_rr": { + "x": 0.04645161290322264, + "z": 0.04053560559951308 + }, + "flank_l": { + "x": 0.14116611842105264, "y": 0.0, "z": 0.0 }, - "hip_fl": { - "x": 0.0, - "z": 0.04319761668321709 + "cool_l": { + "x": 0.1858064516129061, + "z": 0.09841752891052913 }, - "knee_fr": { - "x": 0.0, - "z": 0.019364448857994265 - }, - "hip_rl": { - "x": 0.0, - "z": 0.060255629945221933 - }, - "knee_rl": { - "x": 0.0, + "knee_rr": { + "x": 0.04645161290322264, "z": 0.018624467437614145 }, - "cupola": {}, - "tail": { - "y": 0.0721962264150946 + "ankle_fr": { + "x": 0.0037006578947371693, + "z": 0.1333167825223437 } } } \ No newline at end of file diff --git a/surfaces/blender/experiments/mechs/bastion_cams.py b/surfaces/blender/experiments/mechs/bastion_cams.py new file mode 100644 index 0000000..4b0b2ec --- /dev/null +++ b/surfaces/blender/experiments/mechs/bastion_cams.py @@ -0,0 +1,41 @@ +"""python bastion_cams.py [--write]: BASTION's cameras from concepts.json's marks (quadruped.cameras): the elevations +and the plan by quadruped.elevation_camera, the hero by camsolve on every mark the hero and the elevations share +(hull marks: nose, emblem, lamp slots, the 03, the magazine, the cooling housing's corner, the muzzle; leg marks: hips, +a knee, ankles). --write keeps them, with the standing skeleton and the views' spread, as bastion_cameras.json. +HULL names the marks that are rigid with the hull: the hero is also solved on those alone and each leg mark's miss +at that camera printed, which is how far the hero poses its legs from the elevations' stance. Plain Python.""" +import json, sys +from pathlib import Path +import numpy as np +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import camsolve, quadruped as Q + +# The solver's own choice here is "free" (16.0 px against upright's 20.9): it puts the lens's centre 1700 px under the frame, +# which no camera at a standing man's eye has, and from there the deck's top shows. The hero is kept upright: level, the +# centre in the frame, the horizon on the soldiers' heads. +MODEL = "upright" +HULL = ("nose", "emblem", "lamp_l", "lamp_r", "num_l", "mag_l", "cool_l", "muzzle", "disc_fl", "hip_fr", "disc_rl") + +if __name__ == "__main__": + world, spread = Q.stand("bastion"), Q.spread("bastion") + cams = Q.cameras("bastion", world, models={"hero": MODEL}) + auto = Q.cameras("bastion", world)["hero"] + print(f"hero by camsolve's auto: model {auto['model']}, rms {auto['rms']:.1f} px, centre ({auto['c'][0]:.0f}, {auto['c'][1]:.0f}), lens {auto['lens']:.0f} mm, {auto['distance']:.0f} m off: not kept (MODEL)") + s = Q.spec("bastion") + view = s["views"]["hero"] + hero = cams["hero"] + print("\n".join(camsolve.report("hero, all marks", hero))) + for k, (du, dv) in hero["residuals"].items(): + print(f" {k:10s} {du:+6.1f} {dv:+6.1f} {np.hypot(du, dv):5.1f}") + marks = {m: p for m, p in view["joints"].items() if m in world and m in HULL} + hull = camsolve.solve(world, marks, view["box"], model="upright", unit=s["unit"], height_px=view["ground"] - view["top"], horizon=view.get("horizon")) + print("\n".join(camsolve.report("hero, hull marks alone", hull))) + legs = {m: p for m, p in view["joints"].items() if m in world and m not in HULL} + miss = {m: [float(v) for v in camsolve.project(hull, [world[m]])[0] - np.array(p)] for m, p in legs.items()} + for k, (du, dv) in {**hull["residuals"], **miss}.items(): + print(f" {k:10s} {du:+6.1f} {dv:+6.1f} {np.hypot(du, dv):5.1f}" + (" (a leg mark, not solved on)" if k in miss else "")) + hero["hull_only"] = {"rms": hull["rms"], "names": hull["names"], "lens": hull["lens"], "C": hull["C"], "leg_miss_px": miss} + if "--write" in sys.argv: + (HERE / "bastion_cameras.json").write_text(json.dumps({"cameras": cams, "stand": world, "spread": spread}, indent=1), encoding="utf-8") + print("written") diff --git a/surfaces/blender/experiments/mechs/bastion_form.py b/surfaces/blender/experiments/mechs/bastion_form.py index 521490f..eeb2032 100644 --- a/surfaces/blender/experiments/mechs/bastion_form.py +++ b/surfaces/blender/experiments/mechs/bastion_form.py @@ -1,63 +1,126 @@ -"""BASTION's numbers (sheet 36): the hull's cage, the wells, the plates' cuts, the kept cameras. Plain Python. +"""BASTION's numbers (sheet 36), second pass: the hull as hard plates, each authored by its faces. Plain Python. -The hull is one closed free cage, authored on the mech's right (x >= 0) and mirrored: five rings of seven points -from the nose (on the seam) round the flank to the tail (on the seam), closed over the deck and under the belly by a -centre line each. The points are where the SURFACE passes: massing.cage_through moves the cage until its subdivided -surface goes through them. World metres: x right, y forward, z up, the origin on the ground under the turret ring. +The first pass built the carapace as one soft cage and it read as a smooth dome. The concept draws an angular, +layered hull: every plate has a faceted silhouette, so every plate here is HARD (KINDS; mech-lessons-2026-12-03) and +is written as the flat faces that bound it (massing.corners finds its corners), not as a cage to be subdivided. +Nothing on this hull is soft: the round forms are turned machinery (the turret ring, the hip bearings). - A the rim: the carapace's overhanging edge, the plan view's outline - B the shoulder: where the flank band breaks into the dome - C the deck's rim round the turret ring - D under the overhang, where the belly's box meets the carapace - E the belly's lower edge -""" +World metres: x right, y forward, z up, the origin on the ground under the turret ring. Plates are authored on the +mech's right (x >= 0) and mirrored. The numbers are read off the elevations and the plan at their cameras +(bastion_cameras.json: 1.1 to 1.4 px rms, 0.057 to 0.072 m a pixel), by hand, to about 2 px (0.12 m); depth where one +view alone shows a face is my own choice of plane, not a fit. + +A face is ("at", point, normal) or ("by", a, b, c, out): three points and the side that is outside. A plate is +{"faces": [...]} or {"points": [...]} (corners given outright), "mirror" for one solid across the centre line, +"mat", "bevel" and "clad": whether the detail plating pass panels its facets.""" import json +import math from pathlib import Path HERE = Path(__file__).resolve().parent -N = 7 -RINGS = { - "A": [(0.0, 6.25, 5.55), (2.3, 5.95, 5.35), (4.4, 4.9, 5.1), (5.05, 2.6, 5.05), (5.05, -2.6, 5.5), (3.9, -4.9, 5.9), (0.0, -5.85, 5.95)], - "B": [(0.0, 5.35, 6.3), (1.9, 5.05, 6.35), (3.6, 4.0, 6.5), (4.1, 2.2, 6.8), (4.1, -2.4, 6.95), (3.1, -4.2, 7.0), (0.0, -5.0, 7.0)], - "C": [(0.0, 2.9, 7.55), (1.3, 2.7, 7.6), (2.35, 1.8, 7.7), (2.6, 0.6, 7.75), (2.6, -1.6, 7.75), (1.9, -2.9, 7.7), (0.0, -3.3, 7.65)], - "D": [(0.0, 5.70, 4.95), (1.7, 5.50, 4.9), (2.45, 4.6, 4.75), (2.45, 2.4, 4.7), (2.45, -2.6, 5.0), (2.0, -4.8, 5.3), (0.0, -5.6, 5.4)], - "E": [(0.0, 5.45, 3.9), (1.5, 5.25, 3.8), (2.15, 4.3, 3.3), (2.2, 2.2, 3.05), (2.2, -2.6, 3.2), (1.8, -4.6, 3.9), (0.0, -5.3, 4.2)], -} -DECK = [(0.0, 2.0, 7.82), (0.0, 1.2, 7.85), (0.0, 0.0, 7.86), (0.0, -1.3, 7.85), (0.0, -2.4, 7.8)] # the deck's centre line, under the turret ring -BELLY = [(0.0, 4.4, 3.5), (0.0, 3.0, 3.05), (0.0, 0.0, 3.0), (0.0, -2.6, 3.1), (0.0, -4.3, 3.8)] -# creases: (ring, from point, to point, weight) along a ring; (ring, ring, point, weight) a column between two rings -RING_CREASES = [("A", 0, 6, 1.0), ("B", 1, 6, 0.85), ("E", 1, 5, 0.6)] -COLUMN_CREASES = [("A", "B", 2, 0.6), ("A", "B", 5, 0.6), ("A", "D", 2, 0.5), ("B", "C", 2, 0.6), ("B", "C", 5, 0.6), ("B", "C", 3, 0.4), ("B", "C", 4, 0.4)] RING = (0.0, 0.0, 7.86) # the turret ring's centre on the deck RING_R = 1.95 +P, P2, CORE = "olive", "olive_light", "gunmetal" -def hull_sheet(rings=None): - """The hull's cage as a free-cage sheet (brokkr_kitbash.shell's form): verts, faces, creases, mirror. Faces are - wound by massing.cage_sheet, which also declares the poles.""" - R = rings or RINGS - order = ["C", "B", "A", "D", "E"] - index = {(r, j): k * N + j for k, r in enumerate(order) for j in range(N)} - verts = [list(p) for r in order for p in R[r]] - deck0 = len(verts) - verts += [list(p) for p in DECK] - belly0 = len(verts) - verts += [list(p) for p in BELLY] - faces = [] - for a, b in zip(order, order[1:]): - for j in range(N - 1): - faces.append([index[a, j], index[a, j + 1], index[b, j + 1], index[b, j]]) - for ring, c0 in (("C", deck0), ("E", belly0)): - faces.append([index[ring, 0], index[ring, 1], c0]) - for j in range(1, N - 2): - faces.append([index[ring, j], index[ring, j + 1], c0 + j, c0 + j - 1]) - faces.append([index[ring, N - 2], index[ring, N - 1], c0 + N - 3]) - creases = [] - for ring, a, b, w in RING_CREASES: - creases += [[index[ring, j], index[ring, j + 1], w] for j in range(a, b)] - for ra, rb, j, w in COLUMN_CREASES: - creases.append([index[ra, j], index[rb, j], w]) - return {"verts": verts, "faces": faces, "creases": creases, "mirror": True} +def at(point, normal): + return ("at", tuple(point), tuple(normal)) + + +def by(a, b, c, out): + return ("by", tuple(a), tuple(b), tuple(c), tuple(out)) + + +def _unit(v): + k = math.sqrt(sum(c * c for c in v)) + return tuple(c / k for c in v) + + +LEAN = 0.38 # how far a pod's flank leans in a metre of height (the front view: 5.04 m out at the rim, 4.1 at the shoulder) + + +def _side_x(y, z, d): + """x on a face x + 0.07 y + LEAN z = d.""" + return d - 0.07 * y - LEAN * z + + +# --- the cheek pod: the front quarter of the carapace, over a front leg ---------------------------------------------------- +A1, B1, A2 = (2.4, 5.5, 5.25), (4.72, 4.0, 5.25), (2.38, 5.2, 6.2) +C_FRONT = by(A1, B1, A2, (0.5, 1.0, 0.2)) +C_SIDE_N = (1.0, 0.07, LEAN) +C_SIDE_AT = (5.03, 0.9, 4.8) +C_SIDE_D = 5.03 + 0.07 * 0.9 + LEAN * 4.8 +_U = _unit((0.72, 0.69, 0.0)) +_FN = _unit((1.425, 2.204, 0.0)) # the front face's normal, level +_SIDE_IN = lambda by_m: tuple(c - n * by_m for c, n in zip(C_SIDE_AT, _unit(C_SIDE_N))) # noqa: E731 +_FRONT_IN = lambda by_m, z: (A1[0] - _FN[0] * by_m, A1[1] - _FN[1] * by_m, z) # noqa: E731 + +CHEEK = {"faces": [C_FRONT, at(_SIDE_IN(0.1), C_SIDE_N), at((4.2, 0.9, 6.95), (0.3, 0.08, 1.0)), at(A2, (0.12, 0.4, 1.0)), at((0, 0, 5.25), (0, 0, -1)), + at((0, 0.9, 0), (0, -1, 0)), at((2.38, 0, 0), (-1, 0, 0)), at(tuple(2.85 * c for c in _U), tuple(-c for c in _U))], + "mat": P, "bevel": 0.04, "clad": True} +CHEEK_TRAY = {"faces": [at(_FRONT_IN(0.28, 5.0), (_FN[0], _FN[1], 0.0)), at(_FRONT_IN(1.3, 5.0), (-_FN[0], -_FN[1], 0.0)), at((0, 0, 4.9), (0, 0, -1)), at((0, 0, 5.3), (0, 0, 1)), + at((2.5, 0, 0), (-1, 0, 0)), at(_SIDE_IN(0.3), C_SIDE_N)], "mat": CORE, "bevel": 0.0, "clad": False} +CHEEK_LIP = {"faces": [at(_FRONT_IN(0.0, 5.0), (_FN[0], _FN[1], 0.0)), at(_FRONT_IN(0.16, 5.0), (-_FN[0], -_FN[1], 0.0)), at((0, 0, 4.84), (0, 0, -1)), at((0, 0, 4.99), (0, 0, 1)), + at((2.45, 0, 0), (-1, 0, 0)), at(_SIDE_IN(0.1), C_SIDE_N)], "mat": P2, "bevel": 0.02, "clad": False} +LAMP = {"at": ((A1[0] + B1[0]) / 2 - 0.3 * _FN[0], (A1[1] + B1[1]) / 2 - 0.3 * _FN[1], 5.12), "normal": (_FN[0], _FN[1], 0.0)} +# the skirt under the pod's flank: the plate that carries the 03, hanging below the pod, standing 0.1 proud of its side +_SKIRT_YZ = [(4.0, 5.3), (3.62, 4.9), (1.35, 4.35), (0.9, 4.8), (0.9, 6.5), (3.8, 6.2)] +_sn = _unit(C_SIDE_N) +SKIRT = {"points": [(_side_x(y, z, C_SIDE_D), y, z) for y, z in _SKIRT_YZ] + [(_side_x(y, z, C_SIDE_D) - 0.32 * _sn[0], y - 0.32 * _sn[1], z - 0.32 * _sn[2]) for y, z in _SKIRT_YZ], + "mat": P, "bevel": 0.035, "clad": False} +NUMERAL = {"at": (_side_x(2.15, 5.6, C_SIDE_D), 2.15, 5.6), "normal": _sn, "text": "03", "height": 0.78} + +# --- the rear quarter pod, over a rear hip ----------------------------------------------------------------------------------- +_V = _unit((0.75, -0.66, 0.0)) +QUARTER = {"faces": [at((5.0, -1.4, 5.5), (1.0, -0.1, 0.4)), at((4.45, -3.7, 5.7), (0.904, -0.427, 0.4)), at((3.2, -4.9, 5.85), (0.351, -0.936, 0.35)), + at((4.2, -2.6, 6.95), (0.28, -0.1, 1.0)), at((0, -1.35, 5.5), (0, -0.12, -1.0)), at((0, -1.4, 0), (0, 1, 0)), at((1.75, 0, 0), (-1, 0, 0)), + at(tuple(2.85 * c for c in _V), tuple(-c for c in _V))], "mat": P, "bevel": 0.04, "clad": True} + +# --- the flank between them: the magazine's compartment, its roof and sill --------------------------------------------------- +MAG = dict(y0=-1.2, y1=0.75, z0=5.57, z1=6.74, face=4.95, depth=1.25) +FLANK_ROOF = {"faces": [at((4.3, 0, 7.05), (0.3, 0, 1.0)), at((4.7, 0, 0), (1, 0, 0.25)), at((0, 0, 6.88), (0, 0, -1)), at((0, 0.85, 0), (0, 1, 0)), at((0, -1.3, 0), (0, -1, 0)), + at((2.8, 0, 0), (-1, 0, 0))], "mat": P2, "bevel": 0.03, "clad": True} +FLANK_SILL = {"faces": [at((4.98, 0, 0), (1, 0, 0.12)), at((3.9, 0, 0), (-1, 0, 0)), at((0, 0, 5.12), (0, 0, -1)), at((0, 0, 5.45), (0, 0, 1)), at((0, 0.85, 0), (0, 1, 0)), + at((0, -1.3, 0), (0, -1, 0))], "mat": P, "bevel": 0.03, "clad": False} + +# --- the head: brow over the visor's recess, chin under it --------------------------------------------------------------------- +BROW = {"points": [(0, 6.3, 5.58), (1.05, 6.25, 5.72), (2.0, 5.72, 5.76), (2.28, 4.95, 5.8), (0, 6.14, 6.12), (1.0, 6.1, 6.14), (1.92, 5.6, 6.16), (2.2, 4.95, 6.2), + (0, 3.25, 7.0), (2.05, 3.25, 7.0), (0, 3.25, 6.2), (2.28, 3.25, 6.2)], "mirror": True, "mat": P, "bevel": 0.04, "clad": True} +VISOR = dict(z0=5.2, z1=5.78, front=5.45, half=1.0, wing=(2.05, 4.85), back=4.2, glass=(5.3, 5.64)) +SILL = {"faces": [at((4.98, 0, 0), (1, 0, 0.12)), at((3.9, 0, 0), (-1, 0, 0)), at((0, 0, 5.12), (0, 0, -1)), at((0, 0, 5.45), (0, 0, 1)), at((0, 0.85, 0), (0, 1, 0)), + at((0, -1.3, 0), (0, -1, 0))], "mat": P, "bevel": 0.03, "clad": False} + +# --- the head: brow over the visor's recess, chin under it --------------------------------------------------------------------- +BROW = {"points": [(0, 6.3, 5.58), (1.05, 6.25, 5.72), (2.0, 5.72, 5.76), (2.28, 4.95, 5.8), (0, 6.14, 6.12), (1.0, 6.1, 6.14), (1.92, 5.6, 6.16), (2.2, 4.95, 6.2), + (0, 3.25, 7.0), (2.05, 3.25, 7.0), (0, 3.25, 6.2), (2.28, 3.25, 6.2)], "mirror": True, "mat": P, "bevel": 0.04, "clad": True} +VISOR = dict(z0=5.2, z1=5.78, front=5.45, half=1.0, wing=(2.05, 4.85), back=4.2, glass=(5.3, 5.64)) +CHIN = {"points": [(0, 5.78, 5.2), (1.0, 5.78, 5.2), (2.1, 5.15, 5.2), (2.3, 4.3, 5.2), (0, 5.45, 3.95), (0.85, 5.45, 3.95), (1.75, 4.95, 3.98), (1.95, 4.3, 4.0), + (2.3, 3.5, 5.2), (1.95, 3.5, 3.95)], "mirror": True, "mat": P, "bevel": 0.04, "clad": True} +SILL = {"points": [(0, 5.9, 5.2), (1.05, 5.9, 5.2), (2.2, 5.22, 5.2), (0, 5.84, 5.3), (1.02, 5.84, 5.3), (2.14, 5.18, 5.3), (0, 5.3, 5.2), (2.0, 4.9, 5.2), (0, 5.3, 5.3), (2.0, 4.9, 5.3)], + "mirror": True, "mat": P2, "bevel": 0.02, "clad": False} +JAW = {"points": [(1.2, 5.3, 3.97), (1.2, 3.7, 3.97), (1.0, 5.12, 3.3), (1.0, 3.85, 3.3)], "mirror": True, "mat": P2, "bevel": 0.03, "clad": False} +EMBLEM = {"at": (0.0, 5.45 + (4.72 - 3.95) * 0.33 / 1.25, 4.72), "normal": (0.0, 1.25, -0.33), "height": 0.62} + +# --- the deck: a faceted collar round the turret ring, a plate behind it --------------------------------------------------------- +COLLAR = [(2.55, 7.05), (3.78, 7.05), (3.25, 7.6), (2.55, 7.6)] # (radius, z) turned in eight flats, one facing forward +TAIL = {"points": [(1.72, -2.75, 7.5), (1.72, -5.0, 7.3), (1.72, -2.75, 7.15), (1.72, -5.0, 7.0)], "mirror": True, "mat": P2, "bevel": 0.03, "clad": True} + +# --- under the plates: the dark core they stand on, and the belly --------------------------------------------------------------- +CORE_UP = {"points": [(0, 5.3, 5.3), (2.2, 5.0, 5.3), (4.3, 3.6, 5.3), (4.5, 0.9, 5.2), (4.5, -1.4, 5.4), (4.3, -2.8, 5.6), (3.6, -4.4, 5.8), (2.2, -5.0, 5.9), (0, -5.0, 5.9), + (0, 3.4, 6.8), (2.2, 3.4, 6.8), (4.0, 3.0, 6.6), (4.2, 0.9, 6.8), (4.2, -1.4, 6.8), (3.9, -2.8, 6.8), (3.2, -4.2, 6.8), (0, -4.6, 6.9), + (2.6, 2.6, 7.3), (2.6, -2.6, 7.3), (0, 3.4, 7.0)], "mirror": True, "mat": CORE, "bevel": 0.0, "clad": False} +BELLY = {"points": [(2.3, 4.7, 5.3), (2.3, -4.9, 5.9), (1.7, 4.0, 3.6), (1.8, 2.2, 3.3), (1.8, -2.6, 3.35), (1.5, -4.6, 4.0), (1.2, 4.9, 3.7)], "mirror": True, "mat": CORE, "bevel": 0.03, "clad": False} +BELLY_SIDE = {"points": [(2.1, 2.2, 3.9), (2.1, -2.4, 3.95), (2.45, 2.0, 4.1), (2.45, -2.2, 4.15), (2.45, 2.0, 4.85), (2.45, -2.2, 4.9), (2.25, 2.2, 5.1), (2.25, -2.4, 5.15), (1.8, 2.2, 3.9), (1.8, -2.4, 5.15)], + "mat": P2, "bevel": 0.03, "clad": True} + +# name, plate, one a side? - the order is the build's. Every plate is hard: the concept draws each with a faceted outline. +PLATES = [("Hull.Brow", BROW, False), ("Hull.Chin", CHIN, False), ("Hull.Sill", SILL, False), ("Hull.Jaw", JAW, False), ("Hull.Cheek", CHEEK, True), ("Hull.Skirt", SKIRT, True), + ("Hull.CheekLip", CHEEK_LIP, True), ("Hull.Quarter", QUARTER, True), ("Hull.FlankRoof", FLANK_ROOF, True), ("Hull.FlankSill", FLANK_SILL, True), ("Hull.Tail", TAIL, False), + ("Hull.BellySide", BELLY_SIDE, True)] +DARK = [("Core.upper", CORE_UP, False), ("Core.belly", BELLY, False), ("Core.cheek_tray", CHEEK_TRAY, True)] +KINDS = {name: "hard" for name, _, _ in PLATES} +KINDS.update({"Hull.Collar": "hard", "Cooling.hood": "hard", "Thigh.guard": "hard", "Shin.guard": "hard", "Turret.housing": "hard"}) +INTERCEPTORS = [(3.55, 4.0), (3.5, 1.7), (3.9, -0.3), (3.6, -3.3)] # plan places on the right; mirrored: eight round the perimeter (the prompt) def cameras(): diff --git a/surfaces/blender/experiments/mechs/bastion_sheets.py b/surfaces/blender/experiments/mechs/bastion_sheets.py index 87af59d..f92586c 100644 --- a/surfaces/blender/experiments/mechs/bastion_sheets.py +++ b/surfaces/blender/experiments/mechs/bastion_sheets.py @@ -7,6 +7,8 @@ the kept cameras (bastion_cameras.json) and the marks and traced lines of concep bastion_character.png the character line: the carapace's rim under the dome, the mass alone and the plated build bastion_plan.png our top view against the concept's, and ours drawn over it bastion_components.png each inset beside its built part + bastion_vs_pass1.png concept | first pass | this pass, hero, side, rear and front (BASTION_PASS1 names the first + pass's render directory; each pass stands at its own solved cameras) bastion_scores.json the cameras' errors, the flow scores, the silhouettes' overlap""" import json, math, os, sys from pathlib import Path @@ -189,12 +191,12 @@ def character_sheet(): crop = lambda im: im.crop([round(v * k) for v in box]) # noqa: E731 c = SHEET.crop(box).resize((round((box[2] - box[0]) * k), round((box[3] - box[1]) * k)), Image.LANCZOS) panels = [label(c, "concept: the rim and the dome")] - for stage, text in (("volume", "the mass alone (one closed free cage, 45 authored vertices)"), ("full", "plated, at the solved hero camera")): + for stage, text in (("volume", "the mass alone: hard plates, each authored by its faces, before any detail"), ("full", "detail plating and the rest, at the solved hero camera")): p = OUT / f"{stage}_hero.png" if p.exists(): panels.append(label(crop(framed(Image.open(p).resize((1536, 840), Image.LANCZOS))), text)) side = [label(fit(concept("side", 3), 420), "concept, side"), label(fit(framed(ours("side")), 420), "ours, side")] - label(stack([row(panels), row(side)]), "BASTION character line: the carapace's overhanging rim under a low dome").save(CMP / "bastion_character.png") + label(stack([row(panels), row(side)]), "BASTION character: an angular, layered carapace - faceted pods overhanging round the turret's collar").save(CMP / "bastion_character.png") def plan_sheet(scores): @@ -224,11 +226,27 @@ def components_sheet(): continue c = SHEET.crop(box) cells.append(label(row([fit(c, 400), fit(Image.open(p).convert("RGB"), 400)]), names[key])) - extra = [label(fit(Image.open(OUT / f"close_{k}.png").convert("RGB"), 400), t) for k, t in (("front_leg", "front leg (no inset): guard plates, hip housing"), ("foot", "foot (no inset): feet.bastion_pads")) if (OUT / f"close_{k}.png").exists()] - rows = [row(cells[i:i + 2]) for i in range(0, len(cells), 2)] + ([row(extra)] if extra else []) + extra = [label(fit(Image.open(OUT / f"close_{k}.png").convert("RGB"), 400), t) for k, t in (("front_leg", "front leg (no inset): armoured housings on the hip's and knee's bearings"), ("foot", "foot (no inset): feet.bastion_pads"), + ("hull", "the carapace: hard plates, stepped panels"), ("cooling_flank", "a cooling housing's flank (the hero)")) if (OUT / f"close_{k}.png").exists()] + rows = [row(cells[i:i + 2]) for i in range(0, len(cells), 2)] + [row(extra[i:i + 2]) for i in range(0, len(extra), 2)] label(stack(rows), "BASTION components: the sheet's inset | the built part").save(CMP / "bastion_components.png") +def pass1_sheet(): + """Concept | first pass | this pass. The first pass's renders are read where BASTION_PASS1 says they are.""" + old = Path(os.environ.get("BASTION_PASS1", "")) + if not old.is_dir(): + return + rows = [] + for tag, h in (("hero", 620), ("side", 460), ("rear", 460), ("front", 460)): + p = old / f"full_{tag}.png" + if not p.exists(): + continue + cells = [label(fit(concept(tag, 2), h), f"{tag}: concept"), label(fit(framed(Image.open(p)), h), "first pass (one soft cage)"), label(fit(framed(ours(tag)), h), "this pass (hard plates)")] + rows.append(row(cells)) + label(stack(rows), "BASTION: concept | first pass | second pass, each pass at its own solved camera").save(CMP / "bastion_vs_pass1.png") + + if __name__ == "__main__": scores = {"cameras": {}, "flow": {}} camera_sheet(scores) @@ -237,6 +255,7 @@ if __name__ == "__main__": character_sheet() plan_sheet(scores) components_sheet() + pass1_sheet() (CMP / "bastion_scores.json").write_text(json.dumps(scores, indent=1), encoding="utf-8") for p in sorted(CMP.glob("bastion_*.png")): im = Image.open(p) diff --git a/surfaces/blender/experiments/mechs/concepts.json b/surfaces/blender/experiments/mechs/concepts.json index 6bfcb77..393e2af 100644 --- a/surfaces/blender/experiments/mechs/concepts.json +++ b/surfaces/blender/experiments/mechs/concepts.json @@ -3286,6 +3286,30 @@ "emblem": [ 265, 660 + ], + "lamp_l": [ + 288, + 656 + ], + "num_l": [ + 327, + 645.5 + ], + "mag_l": [ + 368.5, + 636 + ], + "cool_l": [ + 491, + 617 + ], + "disc_fl": [ + 290, + 682 + ], + "disc_rl": [ + 440, + 663 ] } }, @@ -3343,6 +3367,38 @@ "emblem": [ 118, 662 + ], + "lamp_l": [ + 179.5, + 656 + ], + "lamp_r": [ + 56, + 655.5 + ], + "num_l": [ + 199, + 646 + ], + "num_r": [ + 37, + 646 + ], + "mag_l": [ + 203, + 638 + ], + "mag_r": [ + 33, + 638 + ], + "disc_fl": [ + 203, + 682 + ], + "disc_fr": [ + 33, + 682 ] } }, @@ -3384,6 +3440,22 @@ "ring": [ 651, 606 + ], + "cool_l": [ + 590, + 616.5 + ], + "cool_r": [ + 717, + 616.5 + ], + "disc_rl": [ + 566, + 662 + ], + "disc_rr": [ + 737, + 662 ] } }, @@ -3438,18 +3510,10 @@ "ground": 525, "top": 18, "joints": { - "hip_fl": [ - 533, - 332 - ], "hip_fr": [ 222, 345 ], - "hip_rl": [ - 855, - 283 - ], "knee_rl": [ 925, 455 @@ -3473,6 +3537,38 @@ "emblem": [ 277, 270 + ], + "nose": [ + 297, + 200 + ], + "lamp_l": [ + 470, + 225 + ], + "lamp_r": [ + 210, + 246 + ], + "num_l": [ + 588, + 208 + ], + "mag_l": [ + 695, + 190 + ], + "cool_l": [ + 905, + 137 + ], + "disc_fl": [ + 533, + 332 + ], + "disc_rl": [ + 860, + 288 ] }, "horizon": 437, diff --git a/surfaces/blender/experiments/mechs/massing.py b/surfaces/blender/experiments/mechs/massing.py index f9f5900..861533c 100644 --- a/surfaces/blender/experiments/mechs/massing.py +++ b/surfaces/blender/experiments/mechs/massing.py @@ -20,6 +20,20 @@ Tools here (seraph_body uses each more than once): Curtain(cam, line, frame) a line traced on the concept as a cut: the solved camera's sight lines along it, so the plate's edge is drawn exactly on the line half(axis, sign, at) a half-space by axis: half("x", -1, 0.3) keeps x >= 0.3 + +Hard plates (a plate whose silhouette the concept draws faceted: mech-lessons-2026-12-03; bastion_body uses each): + + plane(point, normal) / through(a, b, c, out) a face as a half-space (n, d): kept where n.p <= d + corners(planes) the corners of the convex solid a set of faces bounds: every three + faces' meeting point that lies inside all the others. Authoring a + plate by its faces is what keeps every facet flat. + hard(name, points, host, ...) a faceted solid on those corners (or any points): flat faces, every + edge chamfered by a bevel; obj["plate_kind"] = "hard" + panel(geo, polygon, ...) a raised inner panel on a flat polygon: inset, lifted, chamfered + clad(obj, geo, ...) detail plating after the main split: every large facet of a hard solid + gets its own raised panel, split in two at varied depths + Face(obj) a flat facet standing in for a surface.Skin, so surface.py's numerals, + emblems, bolt rows and handles land on a hard plate """ import math @@ -352,3 +366,159 @@ def plate(name, mass, keep, proud=0.06, wall=0.08, mat="khaki", cutters=(), beve lo, hi = (min(v.co[k] for v in obj.data.vertices) for k in range(3)), (max(v.co[k] for v in obj.data.vertices) for k in range(3)) print(f"PLATE {name}: {len(obj.data.polygons)} faces, " + " ".join(f"{a:.2f}..{b:.2f}" for a, b in zip(lo, hi)), flush=True) return obj + + +# --- hard plates --------------------------------------------------------------------------------------------------------- +def plane(point, normal): + """A face through `point` whose outward normal is `normal`: (n, d), kept where n.p <= d.""" + n = Vector(normal).normalized() + return (n, n.dot(Vector(point))) + + +def through(a, b, c, out): + """The face through three points, its outward side the one `out` points to.""" + a, b, c = Vector(a), Vector(b), Vector(c) + n = (b - a).cross(c - a).normalized() + if n.dot(Vector(out)) < 0: + n = -n + return (n, n.dot(a)) + + +def moved(face, by): + """A face moved `by` metres along its outward normal (negative: inward).""" + return (face[0], face[1] + by) + + +def corners(planes, tol=1e-6): + """The corners of the convex solid bounded by `planes` [(n, d)]: each three faces' meeting point that is inside + every other face. An unbounded or empty set of faces is an error, not a guess.""" + out = [] + P = [(Vector(n), float(d)) for n, d in planes] + for i in range(len(P)): + for j in range(i + 1, len(P)): + for k in range(j + 1, len(P)): + m = Matrix((P[i][0], P[j][0], P[k][0])) + if abs(m.determinant()) < 1e-7: + continue + p = m.inverted() @ Vector((P[i][1], P[j][1], P[k][1])) + if p.length < 1e3 and all(n.dot(p) <= d + tol for n, d in P) and not any((p - q).length < 1e-5 for q in out): + out.append(p) + if len(out) < 4: + raise ValueError(f"massing.corners: {len(planes)} faces bound no solid ({len(out)} corners)") + return out + + +def hard(name, points, host=None, mat="olive", mirror=False, bevel=0.03, sx=1): + """A hard plate or block: the faceted convex solid on `points` (massing.corners of its faces, or corners given + outright), every facet flat, every edge chamfered `bevel` wide. `sx` -1 builds its mirror across x; `mirror` + one solid across the centre line from its right half.""" + g = M.Geo() + g.hull([(sx * Vector(p).x, Vector(p).y, Vector(p).z) for p in points], mirror=mirror) + bmesh.ops.dissolve_limit(g.bm, angle_limit=math.radians(0.5), verts=g.bm.verts[:], edges=g.bm.edges[:]) + obj = g.to_object(name, mat, host, 1.0) + if bevel: + mod = obj.modifiers.new("Bevel", "BEVEL") + mod.width, mod.segments, mod.limit_method, mod.angle_limit = bevel, 1, "ANGLE", math.radians(12) + for p in obj.data.polygons: + p.use_smooth = False + obj["plate_kind"] = "hard" + return obj + + +def _clip(poly, point, normal): + """A convex polygon (3D points in one plane) kept on the side of a line the normal points away from.""" + out = [] + for i, a in enumerate(poly): + b = poly[(i + 1) % len(poly)] + da, db = (a - point).dot(normal), (b - point).dot(normal) + if da <= 0: + out.append(a) + if (da < 0) != (db < 0) and abs(da - db) > 1e-9: + out.append(a + (b - a) * (da / (da - db))) + return out + + +def panel(geo, polygon, lift=0.05, inset=0.1, chamfer=0.02, out=None, sink=0.02, bolts=None, bolt_r=0.028): + """A raised inner panel on a flat convex polygon (3D points, either winding): the polygon moved in `inset` on + every edge, standing `lift` proud, its outer rim chamfered. `bolts` is a Geo that takes a hex head inside each + of the panel's corners. Returns its frame (z the outward normal), or None for a polygon too small to take one.""" + P = [Vector(p) for p in polygon] + c = sum(P, Vector()) / len(P) + n = sum(((P[i] - c).cross(P[(i + 1) % len(P)] - c) for i in range(len(P))), Vector()) + if n.length < 1e-9: + return None + n.normalize() + if out is not None and n.dot(Vector(out)) < 0: + P.reverse() + n = -n + frame = M.frame_at(c, n) + inv = frame.inverted() + flat = [(inv @ p).to_2d() for p in P] + inner = M._inset(flat, inset) + area = lambda q: 0.5 * sum(q[i].x * q[(i + 1) % len(q)].y - q[(i + 1) % len(q)].x * q[i].y for i in range(len(q))) # noqa: E731 + if area(inner) < 0.25 * area(flat) or area(inner) < 0.02: + return None + geo.prism(frame @ Matrix.Translation((0, 0, -sink)), inner, lift + sink, chamfer) + if bolts is not None: + for q in M._inset(inner, 3.2 * bolt_r): + bolts.cylinder(frame @ Matrix.Translation((q.x, q.y, lift + 0.3 * bolt_r)), bolt_r, 0.6 * bolt_r, 6) + return frame + + +def facets(obj, min_area=0.6): + """The flat facets of a hard solid's own mesh, in its frame: [(points, normal, area)], largest first.""" + out = [] + for p in obj.data.polygons: + if p.area >= min_area: + out.append(([obj.data.vertices[i].co.copy() for i in p.vertices], p.normal.copy(), p.area)) + return sorted(out, key=lambda f: -f[2]) + + +def clad(obj, geo, keep=None, min_area=0.9, lifts=(0.045, 0.075), inset=0.11, gap=0.05, split=2.2, seed=0, bolts=None): + """Detail plating on a hard solid, after the main split: each facet of at least `min_area` (and passing + `keep(normal, centre)`) takes a raised panel; a facet over `split` square metres is cut in two across its + longest side at an uneven share, the two panels at different lifts. Geometry goes into `geo`, in the solid's + frame; `bolts` is a Geo for the panels' corner bolts. Returns the number of panels made.""" + import random + rnd = random.Random(seed) + made = 0 + for pts, n, area in facets(obj, min_area): + c = sum(pts, Vector()) / len(pts) + if keep and not keep(n, c): + continue + if area > split: + k = max(range(len(pts)), key=lambda i: (pts[(i + 1) % len(pts)] - pts[i]).length) + a, b = pts[k], pts[(k + 1) % len(pts)] + way = (b - a).normalized() + at = a + (b - a) * rnd.uniform(0.36, 0.64) + parts = [_clip(pts, at - way * gap / 2, way), _clip(pts, at + way * gap / 2, -way)] + else: + parts = [pts] + order = list(lifts) if rnd.random() < 0.5 else list(reversed(lifts)) + for i, part in enumerate(parts): + if len(part) >= 3 and panel(geo, part, lift=order[i % len(order)], inset=inset, out=n, bolts=bolts) is not None: + made += 1 + return made + + +class Face: + """A hard plate's flat facet standing in for a surface.Skin: surface.py's numeral, emblem, bolt_row, rivet_row, + grab_handle and lifting_eye take it. Frames are in the plate object's own frame; done() makes the geometry.""" + + def __init__(self, obj, mat="olive"): + self.obj, self.name, self.mat = obj, obj.name, mat + self.geos, self.decals, self.count = {}, [], 0 + + def frame(self, point, normal, up=(0, 0, 1)): + return M.frame_at(point, normal, up) + + def sub(self, frame, x, y, roll=0.0, z=0.0): + return frame @ Matrix.Translation((x, y, z)) @ Matrix.Rotation(math.radians(roll), 4, "Z") + + def geo(self, mat=None): + return self.geos.setdefault(mat or self.mat, M.Geo()) + + def done(self, smooth=32.0): + made = [g.to_object(f"{self.name}.fit.{mat}", mat, self.obj, smooth) for mat, g in self.geos.items() if len(g.bm.verts)] + self.geos = {} + return made + self.decals diff --git a/surfaces/blender/experiments/mechs/paint.py b/surfaces/blender/experiments/mechs/paint.py index d69f1cb..4b9f4fc 100644 --- a/surfaces/blender/experiments/mechs/paint.py +++ b/surfaces/blender/experiments/mechs/paint.py @@ -7,9 +7,10 @@ The hook, after a mech is built and before it is rendered: import paint; paint.apply("seraph") -apply(preset, ground=0.0, objects=None, scale=1.0, **overrides) swaps, by material name, every armour paint for -the preset's paint, every bare-metal material for its metal, every marking for its worn stencil; it leaves glass, -rubber, glows and pits alone; called again with another preset it repaints. Returns {old material name: new material}. `ground` is the world height of the +apply(preset, ground=0.0, objects=None, scale=1.0, roles=None, glass="smoked", lens="lens", **overrides) swaps, by material name, every armour paint for +the preset's paint, every bare-metal material for its metal, every marking for its worn stencil, every glass for +a MechGlass (glass="smoked" on panes, lens="lens" on optics under `lens_below` metres across); it leaves rubber, +glows and pits alone; called again with another preset it repaints. Returns {old material name: new material}. `ground` is the world height of the soles (mud and wet are measured from it); `scale` multiplies every noise frequency (a mech half as tall wants 2). An override is any MechPaint input by its lower-case name with underscores, e.g. apply("mcr3", wear=1.4); it reaches the armour and the markings, not the bare metal (material() tunes one role alone). @@ -18,11 +19,35 @@ PRESETS seraph (cleaner, warm drab: 30.webp), mcr3 (grey drab, middli breaker (dark, heavy wear, mud to the knee: 24.webp), paladin (27.webp), kestrel (29.webp). material(name, role="armour", preset="seraph", **overrides) one material of a preset: role is armour, metal, mark or hazard. +glass(name, preset="smoked", **overrides) + one MechGlass material. GLASS: smoked (a near-black canopy pane: RAPTOR, 38.webp), amber (a + dark amber dome: WYVERN, 35.webp), faceted (smoked, broken into panes by a dark lattice), + lens (a coated blue optic), lens_amber (a laser's or lamp's warm optic). +shield(objects=None, lights=None) + light-links the glass out of the stage's area lights; only a glass with Reflect over 0 needs it. +mirrored(*matrices) + True where a chain of frames (4x4 or 3x3) reverses handedness: what a marking placed in it + must be flipped by to read left to right. surface.decal asks it of the plate and the frame. + +Why glass is its own group, and why it does not mirror the scene. mechlib.stage_field lights a mech with three +square area lights, the key 5 scene radii across at 4 radii: half the sky over a canopy. A smooth dielectric +mirrors that key at Fresnel strength, and the key's radiance is many times the sky's, so any glossy pane turned +up or forward renders pale whatever its colour. Measured on WYVERN pass 2's canopy (wyvern.blend, 16 samples, mean +scene-linear radiance of the pane): 0.236 as built (roughness 0.3, coat 0.15); 0.061 with the key hidden from +glossy rays; 0.037 under the world alone; 0.406 with mechlib's own "glass" (roughness 0.04, coat 1). Transmission, +the light path and the missing interior play no part: the pane is opaque, and with its specular off it renders +(0.012, 0.005, 0.002) brown. So MechGlass keeps Cycles' specular off (Reflect 0) and paints its reflection as +emission, from the reflected ray alone: a horizon-bright overcast sky in banks, a dark ground, a small sun's glint, all at +Fresnel strength. It reads the same on any stage. Reflect over 0 brings Cycles' own reflections back +(the mech's frames in the pane); then call shield() once the stage's lights exist, or the pane goes pale again. group() the MechPaint node group (built once per file). Its layers, bottom up: base paint Base Color, toned per plate by Object Info's Random and Geometry's Random Per Island (value, and a little hue and saturation: Tone Variation), mottled by two world-space noises (Mottle). cover a marking's own colour over the paint (Cover Color, Cover); Cover Wear opens it, by Alpha, to - the plate under the decal, in specks and in patches. + the plate under the decal, in specks and in patches. Legibility (0 to 2) lifts the marking back + out of the film, streaks and dust laid over it, brightens it past 1 and closes part of the + wear; chips and mud still take it. 0 is the paint of the first pass, where a number under + breaker's grime could not be read at figure scale. cavity grime Ambient Occlusion (4 samples, 0.45 m) darkens recesses, seams and the undersides of overhangs, and a thin film lies in patches on open faces (Grime, Grime Color). streaks noise stretched along world Z, on faces that stand upright, stronger where AO says something @@ -50,6 +75,7 @@ INPUTS = { "Cover Color": ("NodeSocketColor", (0.2, 0.19, 0.165, 1.0)), "Cover": ("NodeSocketFloat", 0.0), "Cover Wear": ("NodeSocketFloat", 0.5), + "Legibility": ("NodeSocketFloat", 0.0), "Grime": ("NodeSocketFloat", 1.0), "Grime Color": ("NodeSocketColor", (0.02, 0.017, 0.013, 1.0)), "Streaks": ("NodeSocketFloat", 1.0), @@ -75,32 +101,33 @@ PRESETS = { # SERAPH, 30.webp: a warm grey drab, the cleanest of the sheets; small chips, light streaks, mud on the feet only. "seraph": {"armour": {"base_color": (0.066, 0.056, 0.038), "wear": 0.85, "grime": 0.8, "streaks": 0.8, "dust": 0.6, "mud": 0.8, "mud_top": 1.2, "wet_top": 2.0}, "metal": {**_METAL, "wear": 0.6, "mud": 0.8, "mud_top": 1.2}, - "mark": {"cover_color": (0.22, 0.21, 0.18), "cover_wear": 0.55}}, + "mark": {"cover_color": (0.3, 0.29, 0.25), "cover_wear": 0.5, "legibility": 0.8}}, # MCR-3, 25.webp: greyer and darker, every plate chipped along its edges, streaked, dirty to the shin. "mcr3": {"armour": {"base_color": (0.048, 0.044, 0.034), "wear": 1.0, "grime": 1.0, "streaks": 1.0, "dust": 0.45, "mud": 1.0, "mud_top": 1.4, "wet_top": 2.4, "tone_variation": 0.32}, "metal": {**_METAL, "wear": 0.9}, - "mark": {"cover_color": (0.2, 0.195, 0.175), "cover_wear": 0.5}}, + "mark": {"cover_color": (0.3, 0.29, 0.26), "cover_wear": 0.45, "legibility": 0.9}}, # BREAKER, 24.webp: the same drab two stops down, the heaviest wear on any sheet, mud to the knee. "breaker": {"armour": {"base_color": (0.03, 0.028, 0.021), "wear": 1.5, "grime": 1.3, "streaks": 1.3, "dust": 0.35, "mud": 1.3, "mud_top": 2.2, "wet_top": 4.0, "tone_variation": 0.35, "primer_color": (0.12, 0.11, 0.09)}, "metal": {**_METAL, "wear": 1.3, "grime": 1.5, "mud": 1.3, "mud_top": 2.2}, - "mark": {"cover_color": (0.19, 0.18, 0.15), "cover_wear": 0.75}}, + "mark": {"cover_color": (0.3, 0.285, 0.24), "cover_wear": 0.6, "legibility": 0.75}}, # PALADIN, 27.webp: an olive greener than SERAPH's, middling wear. "paladin": {"armour": {"base_color": (0.05, 0.052, 0.033), "wear": 0.9, "grime": 0.9, "streaks": 0.9}, "metal": {**_METAL, "wear": 0.8}, - "mark": {"cover_wear": 0.5}}, + "mark": {"cover_color": (0.3, 0.29, 0.25), "cover_wear": 0.5, "legibility": 0.8}}, # KESTREL, 29.webp: a light grey-green scout paint, thin wear, long streaks. "kestrel": {"armour": {"base_color": (0.06, 0.062, 0.048), "wear": 0.8, "grime": 0.9, "streaks": 1.2, "mud_top": 1.0}, "metal": {**_METAL, "wear": 0.7}, - "mark": {"cover_wear": 0.5}}, + "mark": {"cover_color": (0.3, 0.29, 0.25), "cover_wear": 0.5, "legibility": 0.8}}, } ROLES = { "armour": {"khaki", "olive", "olive_light", "plate_olive", "plate_white", "plate_grey", "plate_sand", "drab", "drab_fit", "drab_dark", "drab_dark_fit"}, "metal": {"gunmetal", "frame", "machine", "structure", "plate_dark"}, "mark": {"stencil", "marking", "marking_fresh"}, "hazard": {"hazard", "accent_yellow"}, + "glass": {"glass", "canopy", "wyvern_canopy", "optic"}, } -HAZARD = {"cover_color": (0.32, 0.2, 0.025), "cover_wear": 0.7} +HAZARD = {"cover_color": (0.32, 0.2, 0.025), "cover_wear": 0.7, "legibility": 0.5} class _Net: @@ -163,11 +190,22 @@ class _Net: return node.outputs[0] +def _current(name, inputs): + """The file's node group of this name if its inputs are this module's, else a new, empty one: a .blend painted + by an older paint.py keeps its group under .old, for whatever still uses it.""" + old = bpy.data.node_groups.get(name) + if old and [i.name for i in old.interface.items_tree if i.item_type == "SOCKET" and i.in_out == "INPUT"] == list(inputs): + return old + if old: + old.name = name + ".old" + return bpy.data.node_groups.new(name, "ShaderNodeTree") + + def group(): """The MechPaint node group; built on first call, then the one in the file.""" - if GROUP in bpy.data.node_groups: - return bpy.data.node_groups[GROUP] - tree = bpy.data.node_groups.new(GROUP, "ShaderNodeTree") + tree = _current(GROUP, INPUTS) + if tree.nodes: + return tree for name, (kind, default) in INPUTS.items(): s = tree.interface.new_socket(name, in_out="INPUT", socket_type=kind) s.default_value = default @@ -197,10 +235,11 @@ def group(): shade = n.math("ADD", n.math("ADD", n.ramp(blotch, 0.3, 0.7, (-0.3, 0.3)), n.ramp(speck, 0.3, 0.7, (-0.2, 0.2))), n.ramp(n.noise(pos, 6.0, 5.0, 0.7), 0.3, 0.7, (-0.22, 0.22))) col = n.vec("SCALE", hsv.outputs["Color"], scale=n.math("MULTIPLY_ADD", shade, G["Mottle"], 1.0)) # a marking's own colour over it, worn through by Alpha - col = n.mix(col, n.vec("SCALE", G["Cover Color"], scale=n.ramp(n.noise(pos, 7.0, 4.0), 0.3, 0.7, (0.6, 1.05))), G["Cover"]) + cover = n.vec("SCALE", G["Cover Color"], scale=n.ramp(n.noise(pos, 7.0, 4.0), 0.3, 0.7, (0.6, 1.05))) + col = n.mix(col, cover, G["Cover"]) fine_lo, patch_lo = n.ramp(G["Cover Wear"], 0.0, 1.0, (0.7, 0.46)), n.ramp(G["Cover Wear"], 0.0, 1.0, (0.82, 0.46)) gone = n.math("MAXIMUM", n.ramp(n.noise(pos, 38.0, 3.0, 0.6, 1.2), fine_lo, n.math("ADD", fine_lo, 0.03)), n.ramp(n.noise(pos, 4.5, 5.0), patch_lo, n.math("ADD", patch_lo, 0.05))) - alpha = n.math("SUBTRACT", 1.0, n.mul(gone, n.math("MINIMUM", G["Cover"], 1.0)), clamp=True) + alpha = n.math("SUBTRACT", 1.0, n.mul(gone, n.math("MINIMUM", G["Cover"], 1.0), n.ramp(G["Legibility"], 0.0, 2.0, (1.0, 0.3))), clamp=True) # cavity grime ao = tree.nodes.new("ShaderNodeAmbientOcclusion") @@ -224,6 +263,8 @@ def group(): # dust on what looks up dust = n.mul(n.ramp(up, 0.45, 0.95), n.ramp(n.noise(pos, 3.0, 6.0, 0.7), 0.25, 0.7, (0.25, 1.0)), G["Dust"], 0.6, clamp=True) col = n.mix(col, G["Dust Color"], dust) + # legibility: the marking's paint lifted back out of the film, streaks and dust; chips and mud below still take it + col = n.mix(col, n.vec("SCALE", cover, scale=n.ramp(G["Legibility"], 1.0, 2.0, (1.0, 1.7))), n.mul(G["Cover"], G["Legibility"], clamp=True)) # edge wear: chips to metal with a primer ring, scuffs on open faces bevel = tree.nodes.new("ShaderNodeBevel") @@ -262,11 +303,195 @@ def group(): return tree -def _input_name(key): - for name in INPUTS: +GLASS_GROUP = "MechGlass" +GLASS_INPUTS = { + "Tint": ("NodeSocketColor", (0.006, 0.007, 0.008, 1.0)), # the pane's own colour, seen where nothing shows through + "Interior": ("NodeSocketFloat", 0.5), # how much of Interior Color shows where the eye looks straight in + "Interior Color": ("NodeSocketColor", (0.01, 0.011, 0.012, 1.0)), + "Roughness": ("NodeSocketFloat", 0.04), + "Reflect": ("NodeSocketFloat", 0.0), # Cycles' own specular, 1 a plain dielectric: see shield() + "Sky": ("NodeSocketFloat", 2.2), # 1 is the physical reflection of the sky; the sheets paint it stronger + "Sky Color": ("NodeSocketColor", (0.58, 0.61, 0.67, 1.0)), # stage_field's world: (0.5, 0.53, 0.58) at 1.15 + "Clouds": ("NodeSocketFloat", 1.0), # the reflected sky broken into banks, so a reflection has a shape + "Ground Color": ("NodeSocketColor", (0.06, 0.055, 0.05, 1.0)), + "Glint": ("NodeSocketFloat", 1.0), + "Glint Direction": ("NodeSocketVector", (0.35, 0.5, 0.8)), # toward the sun, in the world: high over the mech's front left, where the hero views stand + "Glint Size": ("NodeSocketFloat", 0.006), # 1 - cos of the sun's half angle: 0.006 is 6 degrees + "Facets": ("NodeSocketFloat", 0.0), # panes a metre; 0 is one pane + "Facet Tilt": ("NodeSocketFloat", 0.1), + "Mullion": ("NodeSocketFloat", 0.02), # the lattice bar's width, metres + "Mullion Color": ("NodeSocketColor", (0.003, 0.003, 0.003, 1.0)), + "Dirt": ("NodeSocketFloat", 1.0), + "Dirt Color": ("NodeSocketColor", (0.03, 0.028, 0.023, 1.0)), + "Scale": ("NodeSocketFloat", 1.0), +} +GLASS_OUTPUTS = {"Color": "NodeSocketColor", "Roughness": "NodeSocketFloat", "Specular": "NodeSocketFloat", "Normal": "NodeSocketVector", "Emission": "NodeSocketColor"} +_LENS = {"roughness": 0.02, "interior": 1.0, "dirt": 0.5} +GLASS = { + # RAPTOR, 38.webp, RECESSED COCKPIT: near-black panes in an armour lattice, a pale sky low on each, no interior. + "smoked": {}, + # WYVERN, 35.webp, COCKPIT & SENSOR CANOPY: a dark amber dome, the amber showing where the eye looks in. + "amber": {"tint": (0.006, 0.0025, 0.001), "interior": 1.0, "interior_color": (0.02, 0.0062, 0.0012)}, + # one blown pane read as a lattice of flat ones: for a canopy built as a single dome with no frames of its own. + "faceted": {"facets": 3.5, "facet_tilt": 0.12, "mullion": 0.022}, + # a coated optic: a blue-violet depth, a cold reflection (WYVERN's projector and helmet sensor; RAPTOR's emitters). + "lens": {**_LENS, "tint": (0.004, 0.005, 0.012), "interior_color": (0.0015, 0.005, 0.022), "sky_color": (0.3, 0.45, 0.95), "sky": 1.2}, + "lens_amber": {**_LENS, "tint": (0.012, 0.005, 0.002), "interior_color": (0.02, 0.0055, 0.0008), "sky_color": (0.95, 0.6, 0.3), "sky": 1.2}, +} + + +def glass_group(): + """The MechGlass node group; built on first call, then the one in the file. See the module header for why its + reflection is painted. Its layers: the pane (Tint, Interior Color where the view is square to it, broken by a + slow noise); facets (a Voronoi lattice in the object's frame: each cell's normal tilted its own way, a bar of + Mullion Color on the cell borders); dirt (Ambient Occlusion puts it in the corners a frame makes, a noise on + what looks up); the painted reflection (sky above the reflected horizon, brightest at it and broken into banks by Clouds; ground below; a + sun's disc and halo about Glint Direction), at Fresnel strength for IOR 1.5, dimmed by the dirt.""" + tree = _current(GLASS_GROUP, GLASS_INPUTS) + if tree.nodes: + return tree + for name, (kind, default) in GLASS_INPUTS.items(): + tree.interface.new_socket(name, in_out="INPUT", socket_type=kind).default_value = default + for name, kind in GLASS_OUTPUTS.items(): + tree.interface.new_socket(name, in_out="OUTPUT", socket_type=kind) + n = _Net(tree) + gin, gout = tree.nodes.new("NodeGroupInput"), tree.nodes.new("NodeGroupOutput") + G = gin.outputs + geo, coords = tree.nodes.new("ShaderNodeNewGeometry"), tree.nodes.new("ShaderNodeTexCoord") + own = n.vec("SCALE", coords.outputs["Object"], scale=G["Scale"]) + + def z_of(vector): + node = tree.nodes.new("ShaderNodeSeparateXYZ") + tree.links.new(vector, node.inputs[0]) + return node.outputs["Z"] + + # facets: a tilt a cell, a bar on the borders + on = n.ramp(G["Facets"], 0.0, 0.01) + cells = n.vec("SCALE", own, scale=G["Facets"]) + lattice = {} + for feature in ("F1", "DISTANCE_TO_EDGE"): + node = tree.nodes.new("ShaderNodeTexVoronoi") + node.voronoi_dimensions, node.feature = "3D", feature + node.inputs["Scale"].default_value, node.inputs["Randomness"].default_value = 1.0, 0.75 + tree.links.new(cells, node.inputs["Vector"]) + lattice[feature] = node + tilt = n.vec("SCALE", n.vec("SUBTRACT", lattice["F1"].outputs["Color"], (0.5, 0.5, 0.5)), scale=n.mul(G["Facet Tilt"], on, 2.0)) + normal = n.vec("NORMALIZE", n.vec("ADD", geo.outputs["Normal"], tilt)) + half = n.mul(G["Mullion"], G["Facets"], 0.5) + bar = n.mul(n.ramp(lattice["DISTANCE_TO_EDGE"].outputs["Distance"], n.math("MULTIPLY_ADD", half, 1.25, 0.002), half), on) + + # dirt: in the corners a frame makes, and on what looks up + ao = tree.nodes.new("ShaderNodeAmbientOcclusion") + ao.samples, ao.inputs["Distance"].default_value = 4, 0.22 + patchy = n.ramp(n.noise(own, 6.0, 5.0, 0.7), 0.3, 0.65, (0.35, 1.0)) + corner = n.mul(n.ramp(ao.outputs["AO"], 0.9, 0.45), patchy) + settled = n.mul(n.ramp(z_of(geo.outputs["Normal"]), 0.35, 0.95), n.ramp(n.noise(own, 2.2, 6.0, 0.7), 0.35, 0.7, (0.05, 0.45))) + dirt = n.mul(n.math("MAXIMUM", corner, settled), G["Dirt"], clamp=True) + + # the pane: its tint, the interior's colour where the eye looks straight in + facing = tree.nodes.new("ShaderNodeLayerWeight") + facing.inputs["Blend"].default_value = 0.5 + tree.links.new(normal, facing.inputs["Normal"]) + square = n.math("POWER", n.math("SUBTRACT", 1.0, facing.outputs["Facing"], clamp=True), 3.0) + inside = n.mul(square, G["Interior"], n.ramp(n.noise(own, 2.6, 3.0, 0.5), 0.3, 0.7, (0.35, 1.0)), clamp=True) + col = n.mix(G["Tint"], G["Interior Color"], inside) + col = n.mix(col, G["Mullion Color"], bar) + col = n.mix(col, G["Dirt Color"], n.math("MULTIPLY", dirt, 0.8)) + + # the painted reflection, from the reflected ray + ray = n.vec("REFLECT", n.vec("SCALE", geo.outputs["Incoming"], scale=-1.0), normal) + rz = z_of(ray) + banks = n.noise(n.vec("MULTIPLY", ray, (1.6, 1.6, 4.0)), 1.0, 3.0, 0.55, 0.6) + banks = n.math("MULTIPLY_ADD", n.math("SUBTRACT", n.ramp(banks, 0.4, 0.62, (0.3, 1.45)), 1.0), G["Clouds"], 1.0) + sky = n.vec("SCALE", G["Sky Color"], scale=n.mul(n.ramp(rz, -0.06, 0.04), n.ramp(rz, 0.0, 0.75, (1.25, 0.4)), banks, G["Sky"])) + env = n.mix(n.vec("SCALE", G["Ground Color"], scale=G["Sky"]), sky, n.ramp(rz, -0.06, 0.04)) + toward = n.vec("DOT_PRODUCT", ray, n.vec("NORMALIZE", G["Glint Direction"])) + edge = n.math("SUBTRACT", 1.0, G["Glint Size"]) + disc = n.math("POWER", n.ramp(toward, n.math("MULTIPLY_ADD", G["Glint Size"], -3.0, edge), 1.0), 3.0) + halo = n.math("POWER", n.ramp(toward, 0.6, 1.0), 10.0) + sun = n.mul(n.math("ADD", n.math("MULTIPLY", disc, 7.0), n.math("MULTIPLY", halo, 0.4)), G["Glint"]) + env = n.vec("ADD", env, n.vec("SCALE", (1.0, 0.96, 0.9), scale=sun)) + fresnel = tree.nodes.new("ShaderNodeFresnel") + fresnel.inputs["IOR"].default_value = 1.5 + tree.links.new(normal, fresnel.inputs["Normal"]) + clear = n.mul(n.math("SUBTRACT", 1.0, n.math("MULTIPLY", dirt, 0.6)), n.math("SUBTRACT", 1.0, bar)) + painted = n.vec("SCALE", env, scale=n.mul(fresnel.outputs[0], clear, n.math("SUBTRACT", 1.0, G["Reflect"], clamp=True))) + + tree.links.new(col, gout.inputs["Color"]) + tree.links.new(n.math("ADD", G["Roughness"], n.math("MAXIMUM", n.math("MULTIPLY", dirt, 0.55), n.math("MULTIPLY", bar, 0.5)), clamp=True), gout.inputs["Roughness"]) + tree.links.new(n.mul(G["Reflect"], 0.5, n.math("SUBTRACT", 1.0, n.math("MULTIPLY", dirt, 0.6))), gout.inputs["Specular"]) + tree.links.new(normal, gout.inputs["Normal"]) + tree.links.new(painted, gout.inputs["Emission"]) + return tree + + +def glass(name, preset="smoked", **overrides): + """One MechGlass material: GLASS[preset], then `overrides` (MechGlass inputs, lower case with underscores).""" + values = {**GLASS[preset], **overrides} + mat = bpy.data.materials.get(name) or bpy.data.materials.new(name) + mat.use_nodes = True + nodes, links = mat.node_tree.nodes, mat.node_tree.links + nodes.clear() + out, bsdf, grp = nodes.new("ShaderNodeOutputMaterial"), nodes.new("ShaderNodeBsdfPrincipled"), nodes.new("ShaderNodeGroup") + grp.node_tree = glass_group() + for key, value in values.items(): + socket = grp.inputs[_input_name(key, GLASS_INPUTS)] + socket.default_value = value if isinstance(value, (int, float)) or len(value) == len(socket.default_value) else (*value, 1.0) + for a, b in (("Color", "Base Color"), ("Roughness", "Roughness"), ("Specular", "Specular IOR Level"), ("Normal", "Normal"), ("Emission", "Emission Color")): + links.new(grp.outputs[a], bsdf.inputs[b]) + bsdf.inputs["Emission Strength"].default_value = 1.0 + links.new(bsdf.outputs[0], out.inputs[0]) + tint = values.get("tint", GLASS_INPUTS["Tint"][1]) + mat.diffuse_color = (*tint[:3], 1.0) + mat["paint_role"], mat["paint_glass"] = "glass", preset + return mat + + +_make_glass = glass # apply() has a parameter of that name + + +def shield(objects=None, lights=None): + """Light-link glass out of the stage's softboxes, so a pane with Reflect over 0 mirrors the world and the mech + and not a key light half the sky across (the module header has the measurement). objects: default every + object whose only material is a MechGlass; lights: default every area light in the scene. Call it after the + stage's lights exist; call it again after adding glass. Returns the objects shielded. An object that also + carries another material is left alone and named: linking is per object, and its paint needs the lights.""" + scene = bpy.context.scene + lights = lights or [o for o in scene.objects if o.type == "LIGHT" and o.data.type == "AREA"] + if objects is None: + objects = [o for o in scene.objects if o.type == "MESH" and any(s.material and s.material.get("paint_role") == "glass" for s in o.material_slots)] + mixed = [o.name for o in objects if any(not s.material or s.material.get("paint_role") != "glass" for s in o.material_slots)] + if mixed: + print("SHIELD left alone, glass beside another material:", ", ".join(mixed), flush=True) + objects = [o for o in objects if o.name not in mixed] + group_ = bpy.data.collections.get("paint.shielded") or bpy.data.collections.new("paint.shielded") + for obj in list(group_.objects): + group_.objects.unlink(obj) + for obj in objects: + group_.objects.link(obj) + for entry in group_.collection_objects: + entry.light_linking.link_state = "EXCLUDE" + for light in lights: + light.light_linking.receiver_collection = group_ if objects else None + return objects + + +def mirrored(*matrices): + """True where the product of these frames (4x4 or 3x3, outermost first) reverses handedness: a reflection in + the object's world matrix, in a Build's to_host, or in a frame written for the other side. A marking laid in + such a chain reads right to left until its own x is reversed; surface.decal does that.""" + sign = 1.0 + for m in matrices: + sign *= (m.to_3x3() if len(m) == 4 else m).determinant() + return sign < 0.0 + + +def _input_name(key, table=None): + table = INPUTS if table is None else table + for name in table: if name.lower().replace(" ", "_") == key: return name - raise KeyError(f"MechPaint has no input {key!r}; it has " + ", ".join(k.lower().replace(" ", "_") for k in INPUTS)) + raise KeyError(f"no input {key!r}; there are " + ", ".join(k.lower().replace(" ", "_") for k in table)) def material(name, role="armour", preset="seraph", **overrides): @@ -298,8 +523,11 @@ def material(name, role="armour", preset="seraph", **overrides): return mat -def apply(preset="seraph", ground=0.0, objects=None, scale=1.0, roles=None, **overrides): - """Repaint a built mech: see the module header. `roles` adds or moves material names, {name: role}.""" +def apply(preset="seraph", ground=0.0, objects=None, scale=1.0, roles=None, glass="smoked", lens="lens", lens_below=0.3, **overrides): + """Repaint a built mech: see the module header. `roles` adds or moves material names, {name: role}; a role of + None leaves that material alone. glass, lens: the GLASS preset (or a dict of MechGlass inputs, over "smoked" + unless it names a "preset") for panes and for optics, an optic being a glass object under `lens_below` metres + across at scale 1.""" role_of = {name: role for role, names in ROLES.items() for name in names} role_of.update(roles or {}) made, swapped = {}, {} @@ -307,11 +535,20 @@ def apply(preset="seraph", ground=0.0, objects=None, scale=1.0, roles=None, **ov if obj.type not in {"MESH", "CURVE", "FONT"} or obj.get("stage"): continue for slot in obj.material_slots: - role = slot.material and (slot.material.get("paint_role") or role_of.get(slot.material.name)) # a painted mech can be repainted + role = slot.material and role_of.get(slot.material.name, slot.material.get("paint_role")) # a painted mech can be repainted if not role: continue - if role not in made: - made[role] = material(f"paint_{preset}_{role}", role, preset, ground_z=ground, scale=scale, **({} if role == "metal" else overrides)) - swapped[slot.material.name] = made[role] - slot.material = made[role] + key = role + if role == "glass": + key = "lens" if max(obj.dimensions) * scale < lens_below else "pane" + if key not in made: + if role == "glass": + which = lens if key == "lens" else glass + made[key] = _make_glass(f"paint_glass_{key}", **({"preset": which} if isinstance(which, str) else which), scale=scale) + else: + made[key] = material(f"paint_{preset}_{role}", role, preset, ground_z=ground, scale=scale, **({} if role == "metal" else overrides)) + swapped[slot.material.name] = made[key] + slot.material = made[key] + if any(m.get("paint_role") == "glass" and m.node_tree.nodes["Group"].inputs["Reflect"].default_value > 0 for m in made.values()): + shield() return swapped diff --git a/surfaces/blender/experiments/mechs/surface.py b/surfaces/blender/experiments/mechs/surface.py index 8a47b6a..2eb3739 100644 --- a/surfaces/blender/experiments/mechs/surface.py +++ b/surfaces/blender/experiments/mechs/surface.py @@ -46,6 +46,7 @@ from mathutils import Matrix, Vector from mathutils.bvhtree import BVHTree import mechlib as M +from paint import mirrored T = Matrix.Translation RX = lambda deg: Matrix.Rotation(math.radians(deg), 4, "X") # noqa: E731 @@ -784,7 +785,12 @@ FONT = r"C:\Windows\Fonts\bahnschrift.ttf" def decal(skin, frame, curve, mat="marking", lift=0.0012, grid=0.03): """A flat 2D curve (in its own xy, metres, centred) laid on the surface along the frame's -z: filled, cut to a - `grid` so it bends over a curve or a crease, each vertex set `lift` off the face. Becomes .mark..""" + `grid` so it bends over a curve or a crease, each vertex set `lift` off the face. Becomes .mark.. + It reads left to right from outside the plate on either side of a mech: where the plate's world matrix and the + frame together reverse handedness (paint.mirrored(): a plate instanced at a negative scale, a frame carried + through a mirroring to_host or written for the other side), the curve's own x is reversed before it is laid. + paint_test.py pins that on a mirrored plate.""" + reading = -1.0 if mirrored(skin.obj.matrix_world, frame) else 1.0 holder = bpy.data.objects.new("decal.tmp", curve) bpy.context.scene.collection.objects.link(holder) M.update() @@ -803,7 +809,7 @@ def decal(skin, frame, curve, mat="marking", lift=0.0012, grid=0.03): bmesh.ops.bisect_plane(bm, geom=bm.verts[:] + bm.edges[:] + bm.faces[:], plane_co=normal * (k * grid), plane_no=normal) k += 1 for v in bm.verts: - seat = skin.sub(frame, v.co.x - centre.x, v.co.y - centre.y) + seat = skin.sub(frame, reading * (v.co.x - centre.x), v.co.y - centre.y) v.co = seat.translation + seat.col[2].xyz * lift bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) probe = next(iter(bm.faces))