diff --git a/surfaces/blender/experiments/mechs/concepts.json b/surfaces/blender/experiments/mechs/concepts.json index 54eeeaf..c9bb270 100644 --- a/surfaces/blender/experiments/mechs/concepts.json +++ b/surfaces/blender/experiments/mechs/concepts.json @@ -3774,7 +3774,7 @@ } }, "marks": { - "_doc": "Pass 2: marks past the joints, for the hero and rear three-quarter cameras and the arrays' two-view lift. brow.r/l: the brow's lip, its outer front corners; sole.r/l: the middle of each foot's footprint on the ground; battery.r/l: the middle of each battery's cell face; housings in the rear elevation: the centre of each housing's blob (the rear shows no ir housing: it hides behind the lidar's). The rear three-quarter's soles are left unmarked: its feet stand in shadow and ground clutter.", + "_doc": "Pass 2: marks past the joints, for the hero and rear three-quarter cameras and the arrays' two-view lift. brow.r/l: the brow's lip, its outer front corners; sole.r/l: the middle of each foot's footprint on the ground; battery.r/l: the middle of each battery's cell face; housings in the rear elevation: the centre of each housing's blob (the rear shows no ir housing: it hides behind the lidar's). The rear three-quarter's soles are left unmarked: its feet stand in shadow and ground clutter. Pass 3: rear3q battery marks re-marked on the cell faces' centres (pass 2's battery.l at 612,183 sat on the dorsal module's crown between the two batteries, which is the 96 to 102 px miss of follow-up stag-rear3q-batteries); hero_horizon: the far ground's edge behind the legs (the vehicles' and treeline's feet), v 660. n37.r/l (hero): the centre of the 37 on each breast shell: the torso's turn, which the shoulder pins under the shells do not give.", "hero": { "brow.r": [ 214, @@ -3791,16 +3791,24 @@ "sole.l": [ 322, 745 + ], + "n37.r": [ + 215, + 197 + ], + "n37.l": [ + 350, + 200 ] }, "rear3q": { "battery.l": [ - 612, - 183 + 547, + 197 ], "battery.r": [ - 675, - 192 + 708, + 208 ] }, "rear_housings": { @@ -3844,6 +3852,170 @@ 226.0, 829.0 ] + }, + "hero_horizon": 660 + }, + "array_hero": { + "_doc": "Pass 3: the two arrays' trees in the hero view, marked on a 5x grid: root (the pylon's foot on the breast), node (the trunk's top, where the spars part); a spar a housing: from (where it leaves the trunk, the node or its parent spar), base (where it enters the housing's underside), centre (the housing's face). stag_hero.py arrays lifts them through the posed hero camera onto the arrays' frontal plane.", + "r": { + "root": [ + 172, + 158 + ], + "node": [ + 142, + 106 + ], + "optical": { + "from": [ + 140, + 105 + ], + "base": [ + 65, + 68 + ], + "centre": [ + 45, + 50 + ] + }, + "comms": { + "from": [ + 125, + 103 + ], + "base": [ + 85, + 97 + ], + "centre": [ + 65, + 90 + ] + }, + "radar": { + "from": [ + 140, + 105 + ], + "base": [ + 128, + 50 + ], + "centre": [ + 125, + 30 + ] + }, + "lidar": { + "from": [ + 150, + 100 + ], + "base": [ + 155, + 62 + ], + "centre": [ + 157, + 47 + ] + }, + "ir": { + "from": [ + 178, + 145 + ], + "base": [ + 190, + 95 + ], + "centre": [ + 192, + 78 + ] + } + }, + "l": { + "root": [ + 325, + 160 + ], + "node": [ + 342, + 112 + ], + "optical": { + "from": [ + 352, + 110 + ], + "base": [ + 410, + 75 + ], + "centre": [ + 425, + 58 + ] + }, + "comms": { + "from": [ + 385, + 108 + ], + "base": [ + 392, + 103 + ], + "centre": [ + 402, + 96 + ] + }, + "radar": { + "from": [ + 345, + 105 + ], + "base": [ + 350, + 45 + ], + "centre": [ + 358, + 25 + ] + }, + "lidar": { + "from": [ + 338, + 100 + ], + "base": [ + 342, + 65 + ], + "centre": [ + 345, + 55 + ] + }, + "ir": { + "from": [ + 335, + 100 + ], + "base": [ + 325, + 68 + ], + "centre": [ + 320, + 50 + ] + } } } } diff --git a/surfaces/blender/experiments/mechs/massing.py b/surfaces/blender/experiments/mechs/massing.py index dd436df..861533c 100644 --- a/surfaces/blender/experiments/mechs/massing.py +++ b/surfaces/blender/experiments/mechs/massing.py @@ -8,6 +8,10 @@ a wall, so plates conform to the mass by construction and step from their neighb Tools here (seraph_body uses each more than once): solid(name, points, faces, frame, ...) a closed cage, subdivided: the mass. Its mesh is in its own frame. + cage(name, sheet, frame, ...) the same from a free-cage sheet as brokkr_kitbash.shell takes one (verts, + faces, creases, mirror): a closed, creased, minimal cage made a mass. + cage_sheet(sheet) is that sheet wound and with its poles declared, and + cage_report(sheet) what the shell action reports of it. ellipsoid / slab cutters (hidden objects) in a mass's frame carve(obj, cutters) wells: an exact Boolean difference, applied plate(name, mass, keep, ...) the mass's surface lifted `proud`, kept inside the half-spaces `keep` @@ -16,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 @@ -62,6 +80,142 @@ def solid(name, points, faces, frame, mat="khaki", levels=1, flat=True): return obj +def _cage_bmesh(sheet): + """(bmesh, crease layer) of a free-cage sheet, mirrored about x where it says so, its faces wound outward.""" + V = [Vector(p) for p in sheet["verts"]] + faces = [list(f) for f in sheet["faces"]] + creases = [tuple(c) for c in sheet.get("creases", ())] + if sheet.get("mirror"): + tol = 0.005 * max(abs(p.x) for p in V) + twin = {} + for i, p in enumerate(list(V)): + if abs(p.x) <= tol: + V[i] = Vector((0.0, p.y, p.z)) + twin[i] = i + else: + twin[i] = len(V) + V.append(Vector((-p.x, p.y, p.z))) + faces += [[twin[i] for i in reversed(f)] for f in faces] + creases += [(twin[a], twin[b], w) for a, b, w in creases if (twin[a], twin[b]) != (a, b)] + bm = bmesh.new() + verts = [bm.verts.new(p) for p in V] + for f in faces: + bm.faces.new([verts[i] for i in f]) + bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) + layer = bm.edges.layers.float.new("crease_edge") + bm.verts.ensure_lookup_table() + for a, b, w in creases: + e = bm.edges.get((bm.verts[a], bm.verts[b])) + if e is None: + raise ValueError(f"cage: a crease on no edge ({a}, {b})") + e[layer] = w + return bm, layer + + +def cage_sheet(sheet, inside=None): + """The sheet as brokkr_kitbash.shell takes it: every authored face wound counter-clockwise seen from outside (read + off the cage's recalculated normals; an open cage says where `inside` is, a point its faces look away from) and + its poles declared (the authored vertices whose valence is not 4 off the boundary, not 2 or 3 on it).""" + bm, _ = _cage_bmesh(sheet) + n = len(sheet["verts"]) + out = dict(sheet) + if inside is not None and sum(f.normal.dot(f.calc_center_median() - Vector(inside)) * f.calc_area() for f in bm.faces) < 0: + bmesh.ops.reverse_faces(bm, faces=bm.faces[:]) + out["faces"] = [[v.index for v in f.verts] for f in bm.faces[:len(sheet["faces"])]] + bm.verts.ensure_lookup_table() + out["poles"] = [i for i in range(n) if len(bm.verts[i].link_edges) not in ((2, 3) if bm.verts[i].is_boundary else (4,))] + bm.free() + return out + + +def cage_stats(sheet): + """{"verts" (authored), "all_verts" (mirrored), "edges", "creased", "crease_share", "poles" {valence: count}, + "triangles"} of the cage as built.""" + bm, layer = _cage_bmesh(sheet) + poles = {} + for v in bm.verts: + if len(v.link_edges) != 4: + poles[len(v.link_edges)] = poles.get(len(v.link_edges), 0) + 1 + out = {"verts": len(sheet["verts"]), "all_verts": len(bm.verts), "faces": len(bm.faces), "edges": len(bm.edges), "creased": sum(1 for e in bm.edges if e[layer] > 0), + "poles": poles, "triangles": sum(1 for f in bm.faces if len(f.verts) == 3), "closed": all(e.is_manifold for e in bm.edges)} + out["crease_share"] = out["creased"] / out["edges"] + bm.free() + return out + + +def cage(name, sheet, frame, mat="khaki", levels=3, flat=True): + """A free cage made a mass: Catmull-Clark `levels` times with its creases, applied. Closed where the cage is.""" + bm, _ = _cage_bmesh(sheet) + obj = _object(name, bm, mat, frame) + mod = obj.modifiers.new("Subdivision", "SUBSURF") + mod.levels = mod.render_levels = levels + mod.use_creases = True + M.bake(obj) + for p in obj.data.polygons: + p.use_smooth = not flat + return obj + + +def cage_through(sheet, levels=3, rounds=5): + """The sheet with its vertices moved until the subdivided surface passes through the points it was authored at: + a Catmull-Clark surface lies inside its cage, by a tenth of its size on a cage this coarse, so a cage authored + on the concept's outline builds a mass a tenth too small. Each round moves every vertex by what its surface + point misses (a subdivided mesh keeps the cage's vertices first, in order).""" + want = [Vector(p) for p in sheet["verts"]] + out = dict(sheet, verts=[list(p) for p in sheet["verts"]]) + for _ in range(rounds): + obj = cage("Cage.through", out, Matrix.Identity(4), levels=levels) + got = [obj.data.vertices[i].co.copy() for i in range(len(want))] + bpy.data.objects.remove(obj, do_unlink=True) + out["verts"] = [list(Vector(p) + (w - g)) for p, w, g in zip(out["verts"], want, got)] + if sheet.get("mirror"): + out["verts"] = [[0.0 if abs(w.x) < 1e-6 else p[0], p[1], p[2]] for p, w in zip(out["verts"], want)] + return out + + +def cage_shell(name, sheet, host=None, to_host=None, mat="khaki", thickness=0.1, levels=2, bevel=0.02, inside=(0, 0, 0)): + """A sculpted plate as a minimal free cage, by brokkr_kitbash.shell: the sheet in its own frame, the object + parented to `host` at `to_host`. Prints the cage's count (CAGE). Returns the object.""" + import json + result = bpy.ops.brokkr_kitbash.shell(object_name=name, sheet=json.dumps(cage_sheet(sheet, inside)), thickness=thickness, levels=levels, bevel=bevel, count_folds=True) + if "FINISHED" not in result: + raise SystemExit(f"cage_shell {name}: {result}") + report = json.loads(getattr(bpy.context.window_manager, M.KB.RESULT)) + stats = cage_stats_open(sheet) + print("CAGE", name, json.dumps({"authored": len(sheet["verts"]), "cageVerts": report["cageVerts"], "cageFaces": report["cageFaces"], "creases": report["creases"], "crease_share": round(stats, 3), + "poles": report["poles"], "folded": report["folded"]}), flush=True) + obj = bpy.data.objects[name] + if host is not None: + obj.parent = host + obj.matrix_parent_inverse = Matrix.Identity(4) + obj.matrix_local = Matrix(to_host) if to_host is not None else Matrix.Identity(4) + M.assign(obj, mat) + for p in obj.data.polygons: + p.use_smooth = False + return obj + + +def cage_stats_open(sheet): + """The share of the cage's edges that carry a crease (the rim's own weight not counted).""" + bm, layer = _cage_bmesh(sheet) + share = sum(1 for e in bm.edges if e[layer] > 0) / max(len(bm.edges), 1) + bm.free() + return share + + +def cage_report(sheet, thickness=0.05, levels=2): + """What brokkr_kitbash.shell reports of the cage (it refuses an unsound one, naming the fault): the action's own + count of vertices, faces, creases and poles. The shell it makes is removed.""" + import json + name = "Cage.report" + result = bpy.ops.brokkr_kitbash.shell(object_name=name, sheet=json.dumps(cage_sheet(sheet)), thickness=thickness, levels=levels) + if "FINISHED" not in result: + raise SystemExit(f"cage_report: {result}") + report = json.loads(getattr(bpy.context.window_manager, M.KB.RESULT)) + bpy.data.objects.remove(bpy.data.objects[name], do_unlink=True) + return {key: report.get(key) for key in ("cageVerts", "cageFaces", "triangles", "creases", "poles", "closed", "subdividedFaces")} + + def _cutter(name, bm, frame): obj = _object(name, bm, "frame", frame) obj.hide_render = obj.hide_viewport = True @@ -212,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/stag.py b/surfaces/blender/experiments/mechs/stag.py index 1ae3760..7079892 100644 --- a/surfaces/blender/experiments/mechs/stag.py +++ b/surfaces/blender/experiments/mechs/stag.py @@ -48,8 +48,12 @@ QUICK = bool(os.environ.get("MECH_QUICK")) OUT = Path(os.environ["MECH_OUT"]) / "stag" assert OUT.is_absolute() OUT.mkdir(parents=True, exist_ok=True) -J = SF.J -REPORT = {"legs": [], "arms": [], "arrays": [], "cages": {}, "frozen": 0} +POSE = os.environ.get("STAG_POSE", "stance") # stance: the elevations' (rear, side, rear3q, turns); hero: stag_hero.py's solved pose +assert POSE in ("stance", "hero") +HERO = SF.cameras()["hero"]["solved"] if POSE == "hero" else None +J = {k: tuple(v) for k, v in HERO["joints"].items()} if HERO else SF.J +R_TORSO = Matrix(HERO["torso"]["R"]).to_4x4() if HERO else Matrix.Identity(4) +REPORT = {"pose": POSE, "legs": [], "arms": [], "arrays": [], "cages": {}, "frozen": 0} def freeze_all(): @@ -65,18 +69,17 @@ def freeze_all(): # --- the legs and the pelvis ------------------------------------------------------------------------------------- -hip_z, waist_z = J["hip_r"][2], SF.WAIST[2] +hip_z, waist_z = J["hip_r"][2], J["waist"][2] WAIST_H = 0.12 pel = legplan.pelvis("Pelvis", span=0.5, ring_r=0.3, top_r=0.36, depth=0.8, height=2 * (waist_z - hip_z - WAIST_H)) pel.location = (0.0, 0.0, hip_z) M.update() -lean = (J["ankle_r"][0] - J["hip_r"][0]) / (J["hip_r"][2] - J["ankle_r"][2]) -CANT = math.degrees(math.atan(lean)) legs = {} for tag, s in (("L", -1), ("R", 1)): k = tag.lower() - leg = legplan.Leg(f"Leg{tag}", pel, (J[f"hip_{k}"][0], 0.0, 0.0), [J[f"knee_{k}"], J[f"hock_{k}"], J[f"ankle_{k}"]], SF.LEG["links"], SF.LEG["limits"], - pin_r=SF.LEG["pin_r"], yoke=SF.LEG["yoke"], cant=CANT, side=s) + cant = math.degrees(math.atan(s * (J[f"ankle_{k}"][0] - J[f"hip_{k}"][0]) / (J[f"hip_{k}"][2] - J[f"ankle_{k}"][2]))) # each leg's own splay: the hero's differ + leg = legplan.Leg(f"Leg{tag}", pel, (J[f"hip_{k}"][0], J[f"hip_{k}"][1], 0.0), [J[f"knee_{k}"], J[f"hock_{k}"], J[f"ankle_{k}"]], SF.LEG["links"], SF.LEG["limits"], + pin_r=SF.LEG["pin_r"], yoke=SF.LEG["yoke"], cant=cant, side=s) leg.foot(feet.stag_claws, f"Foot{tag}", **SF.LEG["foot"]) leg.feet.done() legs[tag] = leg @@ -104,7 +107,7 @@ M.update() print("SOLES were at", round(lo.z, 3), "; the build stands", round(-lo.z, 3), "m higher than stag_form's skeleton", flush=True) TORSO = bpy.data.objects.new("Torso", None) bpy.context.scene.collection.objects.link(TORSO) -TORSO.matrix_world = Matrix.Translation(M.sockets(waist)["top"].translation) +TORSO.matrix_world = Matrix.Translation(M.sockets(waist)["top"].translation) @ R_TORSO # the hero's torso turns on the waist pin M.update() print("WAIST at", [round(c, 3) for c in TORSO.matrix_world.translation], "stag_form", SF.WAIST, flush=True) freeze_all() @@ -128,23 +131,17 @@ if AT >= 1: SB.abdomen(TORSO) SB.dorsal(TORSO) if AT >= 2 else None if AT >= 2: - for s in (-1, 1): - SB.breast_shell(TORSO, s) - SB.keel(TORSO) - SB.brow(TORSO) + SB.hull(TORSO) # the hard plates: breasts, brow, cap, chin, keel (stag_form.HULL) SB.cockpit(TORSO) SB.lower_chest(TORSO) - # markings through surface (decals that read on mirrored plates): the 37 on each breast shell's front face, the - # unit number on the dorsal module's cover + # markings through surface (decals that read on mirrored plates): the 37 on each breast's front face (massing.Face + # on the hard plate), the unit number on the dorsal module's cover + SB.numerals(TORSO) import surface as S - S.materials() - for s, tag in ((-1, "L"), (1, "R")): - skin = S.Skin(f"Breast{tag}.shell") - S.numeral(skin, skin.at((s * 0.92, 2.0, 1.16), (0, -1, 0)), "37", 0.34) - skin.commit() y1 = SF.TORSO["dorsal"]["y"][1] skin = S.Skin("Dorsal.cover.shell") - S.numeral(skin, skin.at((0.0, y1 - 1.0, 1.75), (0, 1, 0)), "37", 0.26) + z0, z1 = SF.TORSO["dorsal"]["z"] + S.numeral(skin, skin.at((0.0, y1 - 1.0, z1 - 0.5), (0, 1, 0)), "37", 0.26) skin.commit() freeze_all() @@ -153,8 +150,10 @@ if AT >= 3: SB.batteries(TORSO) for tag, s in (("L", -1), ("R", 1)): k = tag.lower() - sh = Vector(J[f"shoulder_{k}"]) - TORSO.matrix_world.translation - alean = math.degrees(math.atan((J["wrist_r"][0] - J["shoulder_r"][0]) / (J["shoulder_r"][2] - J["wrist_r"][2]))) + inv = TORSO.matrix_world.inverted() + sh = inv @ Vector(J[f"shoulder_{k}"]) # the shoulder in the torso's frame (turned in the hero) + wl = inv @ Vector(J[f"wrist_{k}"]) + alean = math.degrees(math.atan(s * (wl.x - sh.x) / (sh.z - wl.z))) arm = legplan.Leg(f"Arm{tag}", TORSO, sh, [J[f"elbow_{k}"], J[f"wrist_{k}"]], [(0.26, 0.3), (0.28, 0.3)], [("shoulder_pitch", 60.0, 80.0), ("elbow_pitch", 75.0, 25.0)], pin_r=0.07, yoke=(0.28, 0.4, 0.4), cant=alean, side=s) upper, fore = arm.parts @@ -186,13 +185,14 @@ for tag, s in (("r", 1), ("l", -1)): points[f"sole.{tag}"] = list(SF.design_points()[f"sole.{tag}"]) # the footprint's middle: the ankle 0.25 m forward, on the ground if tag in SB.BATTERY_FACES: points[f"battery.{tag}"] = [round(float(c), 4) for c in tw @ SB.BATTERY_FACES[tag]] -(OUT / "stag_points.json").write_text(json.dumps(points, indent=1), encoding="utf-8") +(OUT / ("stag_points.json" if POSE == "stance" else "stag_points_hero.json")).write_text(json.dumps(points, indent=1), encoding="utf-8") REPORT["kinds"] = SF.KINDS +REPORT["hard"] = SB.HARD lo, hi = M.bounds() print("HEIGHT", round(hi.z - lo.z, 2), "LOW", round(lo.z, 2), "WIDTH", round(hi.x - lo.x, 2), "DEPTH", round(hi.y - lo.y, 2), "stage", STAGE, "build s", round(time.time() - t0, 1), flush=True) REPORT["cages"] = CK.CAGES REPORT["bounds"] = {"lo": [round(c, 3) for c in lo], "hi": [round(c, 3) for c in hi]} -(OUT / "stag_report.json").write_text(json.dumps(REPORT, indent=1, default=str), encoding="utf-8") +(OUT / ("stag_report.json" if POSE == "stance" else "stag_report_hero.json")).write_text(json.dumps(REPORT, indent=1, default=str), encoding="utf-8") # --- the built skeleton against the marks --------------------------------------------------------------------------- built = {} @@ -203,7 +203,7 @@ for tag, leg in legs.items(): built[f"{name}_{k}"] = M.sockets(seg)["clevis"].translation built["waist"] = TORSO.matrix_world.translation skel = {k: [round(float(c), 4) for c in v] for k, v in built.items()} -(OUT / "stag_skeleton.json").write_text(json.dumps({"built": skel, "design": {k: list(v) for k, v in J.items()}}, indent=1), encoding="utf-8") +(OUT / ("stag_skeleton.json" if POSE == "stance" else "stag_skeleton_hero.json")).write_text(json.dumps({"built": skel, "design": {k: list(v) for k, v in J.items()}}, indent=1), encoding="utf-8") print("SKELETON miss", {k: round((Vector(v) - Vector(J[k])).length, 3) for k, v in skel.items() if k in J}, flush=True) # --- views --------------------------------------------------------------------------------------------------------- @@ -225,25 +225,36 @@ def view(tag, stem, width, box=None): M.shot(rig, cam, radius, 0, 0, OUT / f"{stem}.png", (width, width), solved=cams[tag], box=box) -for tag in [t for t in ("hero", "rear3q", "rear", "side", "inset") if t in cams]: +VIEWS = ("hero",) if POSE == "hero" else ("rear3q", "rear", "side", "inset") +for tag in [t for t in VIEWS if t in cams]: if tag in ("hero", "rear3q"): M.silhouette(rig, cam, radius, 0, 0, OUT / f"{STAGE}_sil_{tag}.png", (cams[tag]["box"][2] - cams[tag]["box"][0], 0), solved=cams[tag]) view(tag, f"{STAGE}_{tag}", W if tag in ("hero", "rear3q") else 700) +if POSE == "hero": + # the whole figure at the hero's camera, framed wider than the sheet's box so nothing is cut (the sheet's box + # crops the arrays' tips and the feet) + u0, v0, u1, v1 = cams["hero"]["box"] + view("hero", f"{STAGE}_hero_wide", W, [u0 - 60, v0 - 60, u1 + 60, v1 + 40]) # the character: the arrays alone, at the hero camera and the inset's -for o in meshes: - o.hide_render = not ARRAYS(o.name) -view("hero", f"{STAGE}_arrays_hero", 1100, [0, 0, 470, 180]) -if "inset" in cams: +if POSE == "hero": + for o in meshes: + o.hide_render = not ARRAYS(o.name) + view("hero", f"{STAGE}_arrays_hero", 1100, [0, 0, 470, 180]) + for o in meshes: + o.hide_render = False + view("hero", f"{STAGE}_hero_arrays", 1100, [0, 0, 470, 180]) + view("hero", f"{STAGE}_hero_torso", 1100, [120, 90, 400, 330]) +elif "inset" in cams: + for o in meshes: + o.hide_render = not ARRAYS(o.name) view("inset", f"{STAGE}_arrays_inset", 900) -for o in meshes: - o.hide_render = False -view("hero", f"{STAGE}_hero_arrays", 1100, [0, 0, 470, 180]) -if "inset" in cams: + for o in meshes: + o.hide_render = False view("inset", f"{STAGE}_inset_full", 900) -if AT >= 2 and not os.environ.get("STAG_NO_EDGES"): +if POSE == "hero" and AT >= 2 and not os.environ.get("STAG_NO_EDGES"): armour = lambda name: not name.endswith((".machine", ".steel", ".rubber")) and not name.startswith(("WaistHose",)) # noqa: E731 (OUT / f"{STAGE}_edges_hero.json").write_text(json.dumps(M.built_edges(cams["hero"], keep=armour)), encoding="utf-8") -if not QUICK: +if not QUICK and POSE == "stance": for az in (35, 90, 180, 300): M.shot(rig, cam, radius, az, 8.0, OUT / f"{STAGE}_turn_{az:03d}.png", (1000, 1000), margin=0.85, lens=85.0) # the free cages over their shells diff --git a/surfaces/blender/experiments/mechs/stag_arrays.json b/surfaces/blender/experiments/mechs/stag_arrays.json index ced149d..a2213e9 100644 --- a/surfaces/blender/experiments/mechs/stag_arrays.json +++ b/surfaces/blender/experiments/mechs/stag_arrays.json @@ -1,126 +1,135 @@ { - "_doc": "Housing centres in the array's frame (origin the pylon's root, x outboard, y forward, z up), lifted from the hero view's marks: each the point on its hero ray nearest its rear-elevation ray, left and right averaged. miss: metres between the two rays (the views' disagreement); lr: metres between the left's and the right's lifted points (the hero draws the two arrays unlike). The ir housing has no rear mark: its depth is the lidar's, our plane, not a fit.", - "hero": { - "rms": 22.279605546189625, - "lens": 80.93022939754738, - "marks": [ - "shoulder_r", - "elbow_r", - "wrist_r", - "shoulder_l", - "elbow_l", - "wrist_l", - "waist", - "hip_r", - "hip_l", - "knee_r", - "knee_l", - "hock_r", - "hock_l", - "ankle_r", - "ankle_l", - "brow.r", - "brow.l", - "sole.r", - "sole.l" + "_doc": "Pass 3: the arrays measured off the hero view through the posed hero camera (stag_hero.py arrays): points in the array's frame (origin the marked root, where the trunk leaves the breast's crown, x outboard, y forward, z up), the two sides averaged; lr: metres between the sides' lifts (the hero draws the two arrays unlike); spars: length (m) and rise above the horizontal (degrees) from where a spar leaves its parent to the housing's base. Depth: the frontal plane through the roots, ours.", + "points": { + "root": [ + 0.0, + 0.0, + 0.0 + ], + "node": [ + 0.348, + 0.0, + 0.775 + ], + "optical.from": [ + 0.441, + 0.0, + 0.804 + ], + "optical.base": [ + 1.423, + 0.0, + 1.374 + ], + "optical.centre": [ + 1.69, + 0.0, + 1.656 + ], + "comms.from": [ + 0.805, + 0.0, + 0.847 + ], + "comms.base": [ + 1.128, + 0.0, + 0.918 + ], + "comms.centre": [ + 1.344, + 0.0, + 1.025 + ], + "radar.from": [ + 0.392, + 0.0, + 0.841 + ], + "radar.base": [ + 0.542, + 0.0, + 1.761 + ], + "radar.centre": [ + 0.636, + 0.0, + 2.093 + ], + "lidar.from": [ + 0.271, + 0.0, + 0.921 + ], + "lidar.base": [ + 0.28, + 0.0, + 1.511 + ], + "lidar.centre": [ + 0.29, + 0.0, + 1.716 + ], + "ir.from": [ + 0.085, + 0.0, + 0.589 + ], + "ir.base": [ + -0.078, + 0.0, + 1.237 + ], + "ir.centre": [ + -0.125, + 0.0, + 1.517 ] }, - "housings": { - "optical": [ - 1.243, - 1.556, - 1.178 - ], - "comms": [ - 1.054, - 1.462, - 0.623 - ], - "radar": [ - 0.385, - 1.621, - 1.422 - ], - "lidar": [ - 0.122, - 1.562, - 1.147 - ], - "ir": [ - -0.188, - 1.562, - 0.976 - ] - }, - "miss": { - "r.optical": 0.525, - "r.comms": 0.613, - "r.radar": 0.353, - "r.lidar": 0.386, - "r.ir": null, - "l.optical": 0.079, - "l.comms": 0.027, - "l.radar": 0.448, - "l.lidar": 0.15, - "l.ir": null - }, "lr": { - "optical": 0.916, - "comms": 0.963, - "radar": 0.895, - "lidar": 0.814, - "ir": 0.906 + "root": 0.0, + "node": 0.03, + "optical.from": 0.156, + "optical.base": 0.31, + "optical.centre": 0.392, + "comms.from": 0.486, + "comms.base": 0.171, + "comms.centre": 0.199, + "radar.from": 0.14, + "radar.base": 0.342, + "radar.centre": 0.466, + "lidar.from": 0.149, + "lidar.base": 0.356, + "lidar.centre": 0.456, + "ir.from": 0.859, + "ir.base": 0.723, + "ir.centre": 0.747 }, - "world": { - "r.optical": [ - 2.59, - 1.749, - 8.075 - ], - "r.comms": [ - 2.458, - 1.615, - 7.522 - ], - "r.radar": [ - 1.829, - 1.549, - 8.383 - ], - "r.lidar": [ - 1.507, - 1.61, - 8.127 - ], - "r.ir": [ - 1.134, - 1.61, - 7.702 - ], - "l.optical": [ - -1.897, - 1.202, - 8.318 - ], - "l.comms": [ - -1.649, - 1.149, - 7.76 - ], - "l.radar": [ - -0.941, - 1.533, - 8.495 - ], - "l.lidar": [ - -0.737, - 1.354, - 8.202 - ], - "l.ir": [ - -0.49, - 1.354, - 8.286 - ] + "spars": { + "optical": { + "length": 1.136, + "rise": 30.142 + }, + "comms": { + "length": 0.331, + "rise": 12.417 + }, + "radar": { + "length": 0.933, + "rise": 80.742 + }, + "lidar": { + "length": 0.59, + "rise": 89.173 + }, + "ir": { + "length": 0.668, + "rise": 75.869 + }, + "trunk": { + "length": 0.85, + "rise": 65.797 + } } } \ No newline at end of file diff --git a/surfaces/blender/experiments/mechs/stag_body.py b/surfaces/blender/experiments/mechs/stag_body.py index fc905f8..302d904 100644 --- a/surfaces/blender/experiments/mechs/stag_body.py +++ b/surfaces/blender/experiments/mechs/stag_body.py @@ -4,11 +4,11 @@ it stands on (the torso's host, an empty at the waist pin: every part is authore objects. Metres at the sheet's 8.5 m. Numbers in stag_form. Mass first (mech-pass2-common): torso_mass is one closed solid, the chest's weight read against the hero and rear -silhouettes before any plate; it stays as the dark core. The armour over it is "elegant interlocking curved -composite shells" (the prompt): each a free cage (cagekit, brokkr_kitbash.shell) of a few vertices with its creases -where the form breaks: the breast shells that carry the 37, the centre keel, the brow over the recessed cockpit, -the lower chest's V, the dorsal module's cover; on the limbs the thigh shields, the shin and metatarsus plates, -the upper arms' shells. +silhouettes before any plate; it stays as the dark core. Pass 3: the upper torso's armour is hard plates written by +their faces (hull(): massing.hard on stag_form.HULL, Bastion pass 2's method), detail panels stepped and bolted on +their large facets: the 37 shells, the keel and its ridge, the brow over the recessed cockpit, its cap, the chin. +Free cages (cagekit, brokkr_kitbash.shell) stay where the concept curves: the flanks, the dorsal module's cover, the +thigh shields, the upper arms' shells; and the hard limb plates with every edge creased. """ import math @@ -89,70 +89,76 @@ def _plate(name, frame, sheet, thickness, inside, levels=2, bevel=0.012): return CK.shell(f"{name}.shell", sheet, b, PLATE, thickness=thickness, levels=levels, bevel=bevel, inside=inside) -def breast_shell(frame, side): - """Hero view, hard: a "37" shell, the big faceted plate over each upper chest corner. Five stations up (the - underside's edge, the lower bevel, the front face's top, the crown's front chamfer, the crown's back) and five - round it (the inner edge, the inner chamfer, the outer front corner, the outer side, the side's rear): the front - face, its chamfers, the outer side and the crown are each one facet, every edge creased.""" - tag = "R" if side > 0 else "L" - rows = [[(0.5, 0.86, 0.64), (0.64, 0.94, 0.6), (1.18, 0.92, 0.6), (1.34, 0.5, 0.62), (1.34, -0.5, 0.66)], - [(0.46, 1.02, 0.82), (0.6, 1.1, 0.8), (1.26, 1.08, 0.8), (1.42, 0.54, 0.8), (1.42, -0.56, 0.84)], - [(0.48, 1.02, 1.5), (0.62, 1.1, 1.5), (1.28, 1.08, 1.5), (1.44, 0.52, 1.5), (1.44, -0.56, 1.5)], - [(0.52, 0.9, 1.66), (0.64, 0.96, 1.68), (1.24, 0.94, 1.66), (1.38, 0.46, 1.66), (1.38, -0.54, 1.64)], - [(0.54, -0.36, 1.74), (0.66, -0.4, 1.76), (1.2, -0.44, 1.74), (1.3, -0.48, 1.72), (1.3, -0.62, 1.56)]] - sheet = CK.grid(_mirror_rows(rows, side)) - return [_plate(f"Breast{tag}", frame, sheet, 0.08, (side * 0.9, 0.0, 1.2))] +HARD = {} # hull(): each hard plate's corners and facets, for the report -def brow(frame): - """COCKPIT inset and the hero view, hard: the sculpted armoured brow, a faceted wedge whose front turns down into - a lip over the recessed cockpit, its sides a skirt; over it a second, smaller crown plate, layered. Free cages, - mirrored, every edge a facet.""" - bx, by, bz = SF.TORSO["brow_lip"] - rows = [[(0.0, by + 0.04, bz - 0.04), (0.3, by + 0.02, bz - 0.04), (bx, by - 0.1, bz - 0.02), (bx + 0.02, by - 0.3, bz - 0.14)], - [(0.0, by + 0.08, bz + 0.08), (0.3, by + 0.06, bz + 0.08), (bx + 0.02, by - 0.06, bz + 0.08), (bx + 0.05, by - 0.28, bz - 0.06)], - [(0.0, 1.0, 2.06), (0.3, 0.98, 2.04), (0.52, 0.9, 1.96), (0.58, 0.8, 1.78)], - [(0.0, 0.2, 2.04), (0.3, 0.2, 2.02), (0.5, 0.2, 1.94), (0.56, 0.2, 1.8)]] - out = [_plate("Brow", frame, CK.mirrored(CK.grid(rows)), 0.06, (0.0, 0.7, 1.6))] - cap = [[(0.0, 1.22, 2.1), (0.22, 1.18, 2.09), (0.34, 1.08, 2.04)], - [(0.0, 0.45, 2.12), (0.24, 0.45, 2.1), (0.36, 0.45, 2.04)]] - out.append(_plate("BrowCap", frame, CK.mirrored(hard(CK.grid(cap))), 0.05, (0.0, 0.8, 1.9))) +def _hard(name, spec, frame, sx=1, mat=PLATE, seed=0): + """One hard plate of stag_form.HULL in the torso's frame: massing.hard on its corners (from its faces, or given), + then, if the plate asks, detail panels stepped and bolted on its large facets (massing.clad).""" + pts = MS.corners([MS.plane(p, n) for p, n in spec["faces"]]) if "faces" in spec else spec["points"] + obj = MS.hard(name, pts, frame, mat, mirror=spec.get("mirror", False), bevel=spec.get("bevel", 0.03), sx=sx) + out = [obj] + if spec.get("clad"): + g, bolts = M.Geo(), M.Geo() + n = MS.clad(obj, g, min_area=0.12, lifts=(0.03, 0.055), inset=0.06, gap=0.04, split=0.45, seed=seed, bolts=bolts) + if n: + out.append(bolts.to_object(name + ".bolts", "gunmetal", frame)) + o = g.to_object(name + ".panels", PLATE, frame, 1.0) + mod = o.modifiers.new("Bevel", "BEVEL") + mod.width, mod.segments, mod.limit_method, mod.angle_limit = 0.01, 1, "ANGLE", math.radians(20) + for poly in o.data.polygons: + poly.use_smooth = False + out.append(o) + HARD[name] = {"kind": "hard", "corners": len(obj.data.vertices), "facets": len(obj.data.polygons), "panels": len(out) > 1} return out +def hull(frame): + """Hero view and COCKPIT inset, pass 3: the upper torso's hard plates (stag_form.HULL, KINDS "hard"), each a + faceted solid written by its faces over the dark mass, interlocking: the two 37 shells on the chest's corners, the + keel's pentagon between them pointing down with its ridge proud, the head's wide brow wedge forward over both, its + cap stepped on it, the chin under the visor. Pass 2 built the shells as two upright boxes either side of a dome; + the hero draws the brow and keel standing as far forward as the shells, which is what joins them into one chest.""" + out = [] + for s, tag in ((1, "R"), (-1, "L")): + out += _hard(f"Breast{tag}", SF.HULL["Breast"], frame, sx=s, seed=1 if s > 0 else 2) + for name in ("Brow", "BrowCap", "Chin", "Keel", "Keel.ridge"): + out += _hard(name, SF.HULL[name], frame, seed=3) + return out + + +def numerals(frame): + """The 37 on each breast's front face, through massing.Face (surface.numeral: the decal flips on the mirrored + plate).""" + import surface as S + S.materials() + p, n = SF.HULL["Breast"]["faces"][0] + for s, tag in ((1, "R"), (-1, "L")): + o = bpy.data.objects[f"Breast{tag}"] + nn = Vector((s * n[0], n[1], n[2])).normalized() + x, y, z = SF.NUMERAL["at"] + # onto the front face: the plane through p with normal n, from (x, z) + n0 = Vector(n).normalized() + y = p[1] + (n0.x * (p[0] - x) + n0.z * (p[2] - z)) / n0.y + face = MS.Face(o, PLATE) + S.numeral(face, F(Vector((s * x, y, z)) + nn * 0.058, nn), "37", SF.NUMERAL["height"], "marking_fresh") + face.done() + + def cockpit(frame): """COCKPIT inset ("RECESSED COCKPIT"): deep under the brow, a dark well between the breast shells, the amber - canopy a long slit set back 0.3 m behind the brow's lip in a framed visor; under it the chin plate (hard).""" + canopy a long slit set back 0.3 m behind the brow's lip in a framed visor; the chin plate under it is hull()'s.""" if "amber_canopy" not in M.MATS: M.material("amber_canopy", (0.05, 0.025, 0.0), 0.2, 0.12, emission=((1.0, 0.42, 0.0), 1.2), coat=1.0) - bx, by, bz = SF.TORSO["brow_lip"] + by = 1.5 b = M.Build("Cockpit", frame, Matrix.Identity(4)) d = b[CORE] - d.hull([(s * x, y, z) for s in (-1, 1) for x, y, z in ((0.5, 0.4, 1.3), (0.5, 0.4, 1.86), (0.46, by - 0.24, 1.36), (0.46, by - 0.2, 1.8))]) + d.hull([(s * x, y, z) for s in (-1, 1) for x, y, z in ((0.5, 0.4, 1.3), (0.5, 0.4, 1.7), (0.46, by - 0.24, 1.5), (0.46, by - 0.2, 1.68))]) y = by - 0.3 - b["amber_canopy"].hull([(s * x, yy, z) for s in (-1, 1) for x, yy, z in ((0.4, y, 1.6), (0.4, y + 0.02, 1.7), (0.36, y + 0.06, 1.65))]) + b["amber_canopy"].hull([(s * x, yy, z) for s in (-1, 1) for x, yy, z in ((0.44, y, 1.58), (0.44, y + 0.02, 1.665), (0.4, y + 0.06, 1.62))]) for s in (-1, 1): - b[PLATE].box(T((s * 0.22, y + 0.06, 1.65)), (0.03, 0.05, 0.12)) # the canopy's frame posts - b[PLATE].prism(F((0, y + 0.05, 1.575), (0, 1, -0.2), (0, 0, 1)), M.rect(0.86, 0.05, 0.0), 0.05, 0.01) # its sill - out = b.done(bevel=0.01) - chin = [[(0.0, by - 0.16, 1.56), (0.24, by - 0.18, 1.56), (0.44, by - 0.26, 1.55)], - [(0.0, by - 0.04, 1.42), (0.22, by - 0.06, 1.42), (0.4, by - 0.18, 1.42)], - [(0.0, by - 0.18, 1.28), (0.2, by - 0.2, 1.29), (0.36, by - 0.3, 1.3)]] - out.append(_plate("Chin", frame, CK.mirrored(CK.grid(chin)), 0.06, (0.0, 0.9, 1.42))) - return out - - -def keel(frame): - """Hero view, hard: the sternum under the chin, a stepped V narrowing down the chest to a point over the waist, - two layers: the wide plate and, proud of it, a narrower one. Free cages, mirrored.""" - under = [[(0.0, 1.16, 1.26), (0.25, 1.12, 1.26), (0.46, 1.0, 1.24)], - [(0.0, 1.2, 0.95), (0.2, 1.14, 0.95), (0.38, 0.98, 0.94)], - [(0.0, 0.98, 0.42), (0.1, 0.94, 0.44), (0.18, 0.82, 0.48)]] - over = [[(0.0, 1.25, 1.16), (0.15, 1.21, 1.16)], - [(0.0, 1.28, 0.95), (0.12, 1.23, 0.95)], - [(0.0, 1.08, 0.62), (0.06, 1.05, 0.64)]] - return [_plate("Keel", frame, CK.mirrored(CK.grid(under)), 0.07, (0.0, 0.3, 0.9)), - _plate("Keel.over", frame, CK.mirrored(CK.grid(over)), 0.05, (0.0, 0.3, 0.9))] + b[PLATE].box(T((s * 0.24, y + 0.06, 1.62)), (0.03, 0.05, 0.1)) # the canopy's frame posts + return b.done(bevel=0.01) def lower_chest(frame): diff --git a/surfaces/blender/experiments/mechs/stag_cameras.json b/surfaces/blender/experiments/mechs/stag_cameras.json index 7b5a22e..7be8d8c 100644 --- a/surfaces/blender/experiments/mechs/stag_cameras.json +++ b/surfaces/blender/experiments/mechs/stag_cameras.json @@ -244,186 +244,47 @@ }, "hero": { "C": [ - 1.4963054952289474, - 8.716513073773697, - 4.670915448588751 + 3.9055097345214302, + 8.3753926541803, + 1.303432414597535 ], "R": [ [ - -0.9889414521587536, - 0.14802548969070695, - 0.009124615277482751 + -0.9064737585441767, + 0.4074505721694987, + -0.11085736921622212 ], [ - 0.0029348410325087896, - -0.041980243537695965, - 0.9991141305479718 + -0.04930669828440091, + 0.15860183766096536, + 0.9861106969275083 ], [ - 0.14827741200280498, - 0.988092158431764, - 0.041081571725145684 + 0.4193735501615293, + 0.8993494806410426, + -0.12367836146878064 ] ], "f": 718.0555555555555, "c": [ - 235.0, - 395.0 + 299.37906696871664, + 546.5461005949476 ], "box": [ - 0.0, - 0.0, - 470.0, - 790.0 + 0, + 0, + 470, + 790 ], + "azimuth": -24.999999999, + "distance": 9.24122331718799, "lens": 55.0, - "lens_band": [ - 55.0, - 55.0 - ], - "lens_at_bound": null, - "lens_determined": null, - "planarity": 0.14570707212051617, - "rms": 27.694660422495765, - "median": 26.02203967754923, - "worst": [ - "hip_r", - 47.78698311498756 - ], - "left_out": 30.694597654294874, - "model": "rolled", - "tried": { - "rolled": { - "rms": 27.694660422495765, - "left_out": 30.694597654294874, - "lens": 55.0 - } - }, - "azimuth": -9.983828240726629, - "elevation": -4.310317009263177, - "distance": 8.655175764486861, - "roll": 0.5232509428395301, - "twist": 0.0, - "plane": null, - "residuals": { - "shoulder_r": [ - -18.283878498359968, - -22.601631346868885 - ], - "elbow_r": [ - -26.611124382066407, - 16.37640014324711 - ], - "wrist_r": [ - -38.343427185450736, - 24.905395235480853 - ], - "shoulder_l": [ - 7.901805070895705, - -14.95879758010065 - ], - "elbow_l": [ - 2.494232894253628, - 3.839325415495864 - ], - "wrist_l": [ - -15.705670183938366, - 24.866229419343426 - ], - "waist": [ - -46.00500892615992, - 1.255818265622736 - ], - "hip_r": [ - -47.26424857028181, - 7.048869577366304 - ], - "hip_l": [ - -26.631615156666953, - 10.029854098475994 - ], - "knee_r": [ - -2.9739690244209953, - 0.32523570234656063 - ], - "knee_l": [ - -13.995740706371407, - -2.0825897178508512 - ], - "hock_r": [ - 13.072365292061136, - -29.65005535244336 - ], - "hock_l": [ - 2.24552093149822, - -33.74828335254074 - ], - "ankle_r": [ - 24.74313809129839, - -12.825156232158974 - ], - "ankle_l": [ - 13.20054750605658, - -21.33465765605581 - ], - "brow.r": [ - 9.500002232090822, - -28.645551870580505 - ], - "brow.l": [ - 8.734292186097662, - -35.142654036462375 - ], - "sole.r": [ - 35.74707787953204, - 2.8656499184304494 - ], - "sole.l": [ - 5.825448132410145, - 6.772595562303309 - ], - "r.optical": [ - -14.981484933728098, - 2.2425347569538303 - ], - "r.comms": [ - -2.5722333053783473, - -8.653883992492467 - ], - "r.radar": [ - -0.6305658515325376, - 15.885601167036725 - ], - "r.lidar": [ - 3.230501496201441, - 20.651710134111227 - ], - "r.ir": [ - 9.026272380444624, - -8.36861073067837 - ], - "l.optical": [ - 20.73106508323326, - 7.2919151457412 - ], - "l.comms": [ - 23.236560810566516, - -3.186084709982822 - ], - "l.radar": [ - 16.434978264015626, - 31.143143079907418 - ], - "l.lidar": [ - 9.077047166615898, - 19.110128082474432 - ], - "l.ir": [ - 3.0152257809518233, - 25.846759225671406 - ] - }, "unit": 1024, + "rms": 14.658338518286971, + "elevation": 7.104439232007342, + "roll": -6.414191729245742, + "horizon": 635.4809319919307, + "model": "posed", "marks": [ "shoulder_r", "elbow_r", @@ -444,39 +305,276 @@ "brow.l", "sole.r", "sole.l", - "r.optical", - "r.comms", - "r.radar", - "r.lidar", - "r.ir", - "l.optical", - "l.comms", - "l.radar", - "l.lidar", - "l.ir" - ] + "n37.r", + "n37.l" + ], + "residuals": { + "shoulder_r": [ + 6.487623107485831, + 5.9186942870026655 + ], + "elbow_r": [ + 4.564279338113636, + 9.436176650524942 + ], + "wrist_r": [ + -2.8909203509544454, + -3.2901074712550553 + ], + "shoulder_l": [ + 10.379059055880873, + 9.66956549334327 + ], + "elbow_l": [ + 9.88028974669163, + 8.403873031187004 + ], + "wrist_l": [ + -4.213013054208602, + -2.238062613479997 + ], + "waist": [ + -22.4928001017376, + 20.30312555288066 + ], + "hip_r": [ + -12.251078217149086, + 17.4603089997255 + ], + "hip_l": [ + -4.645443211220311, + 24.018426256467137 + ], + "knee_r": [ + 3.9887231877819715, + -10.810423130529784 + ], + "knee_l": [ + -8.086853779741375, + -9.465667546592101 + ], + "hock_r": [ + -5.344133162996684, + -8.552864449403728 + ], + "hock_l": [ + -0.43770734797931254, + -9.284024772058274 + ], + "ankle_r": [ + -6.734563881301966, + -2.244932543644154 + ], + "ankle_l": [ + 0.5427656004009123, + -10.094623832751495 + ], + "brow.r": [ + 1.5615299118437918, + -5.281347075299152 + ], + "brow.l": [ + 20.460955549294965, + -10.892914383364086 + ], + "sole.r": [ + 13.235196276759325, + 2.1420503896027867 + ], + "sole.l": [ + 3.7944138795383537, + 4.449531856963517 + ], + "n37.r": [ + -14.343365249068881, + -13.642148844282303 + ], + "n37.l": [ + 6.545046132616449, + -9.874852173560896 + ] + }, + "solved": { + "pose": { + "torso_yaw": -10.939220062095854, + "torso_pitch": -1e-09, + "drop": -0.1642416677290892, + "hip_abd_r": 16.25363269180241, + "hip_flex_r": -17.762119195056766, + "knee_r": 33.57689698565213, + "hock_r": -24.95260508583792, + "hip_abd_l": -13.324954970649845, + "hip_flex_l": -10.40992675694322, + "knee_l": 23.103346141750585, + "hock_l": -18.440719138757302, + "sh_flex_r": 25.072210960562682, + "sh_abd_r": 3.2094099697616016, + "elbow_r": -24.794568268804916, + "sh_flex_l": 13.442396607461477, + "sh_abd_l": -7.809833194197419, + "elbow_l": -4.863487106721294 + }, + "joints": { + "waist": [ + 0.0, + 0.0, + 5.481975657876872 + ], + "hip_r": [ + 0.5652709359605912, + 0.0, + 4.853896840142882 + ], + "knee_r": [ + 1.2265629756277283, + -0.045209947982837555, + 3.1840476019514434 + ], + "hock_r": [ + 1.6848521244881123, + -0.6173654855496296, + 2.0609039856969513 + ], + "ankle_r": [ + 2.118330089548047, + -0.23808835002637577, + 0.79846148443246 + ], + "sole.r": [ + 2.118330089548047, + 0.011911649973624233, + 0.08663882433393788 + ], + "shoulder_r": [ + 1.1922209810074704, + -0.23043204717215846, + 6.570645608615789 + ], + "elbow_r": [ + 1.6813915019717827, + 0.0884058216373705, + 5.441656111052459 + ], + "wrist_r": [ + 1.925890026699291, + 0.49445357358509817, + 4.404501508124433 + ], + "brow.r": [ + 1.0087291410314305, + 1.1087224720175448, + 7.211975657899213 + ], + "n37.r": [ + 1.1690391117036676, + 0.8842214401711814, + 6.7619756578958965 + ], + "hip_l": [ + -0.5652709359605912, + 0.0, + 4.853896840142882 + ], + "knee_l": [ + -0.3181723032041216, + 0.18399403906210932, + 3.0839149084012734 + ], + "hock_l": [ + -0.1699271238146255, + -0.4530091804438822, + 1.9129782102866764 + ], + "ankle_l": [ + 0.07054130842788409, + 0.0044578981666695775, + 0.6251839076884202 + ], + "sole.l": [ + 0.07054130842788409, + 0.2544578981666696, + -0.08663875241010188 + ], + "shoulder_l": [ + -1.192220981014682, + 0.23043204713484725, + 6.570645608615789 + ], + "elbow_l": [ + -1.3457148713107534, + 0.42873318885619827, + 5.324580219637512 + ], + "wrist_l": [ + -1.2060024743368551, + 1.0039009528583527, + 4.349897468576895 + ], + "brow.l": [ + -0.5229241663380936, + 1.4047598784782802, + 7.211975657899213 + ], + "n37.l": [ + -0.7553458129400932, + 1.2561658739295414, + 6.7619756578958965 + ] + }, + "torso": { + "R": [ + [ + 0.9818290431855923, + 0.18976756824406119, + -3.3120688793619025e-12 + ], + [ + -0.18976756824406119, + 0.9818290431855923, + -1.7136149495294184e-11 + ], + [ + 0.0, + 1.7453292519943298e-11, + 1.0 + ] + ], + "waist": [ + 0.0, + 0.0, + 5.481975657876872 + ] + }, + "stance_rms": 25.25836443098684, + "scan": { + "35": 17.813022640524103, + "42": 16.23617059206162, + "55": 14.658338518286971, + "70": 13.874354268463915 + } + } }, "rear3q": { "C": [ - -1.1209814249047891, - -5.927005950504371, - 1.84799157828791 + -0.7802415318819605, + -6.101949425694438, + 2.287237985833952 ], "R": [ [ - 0.9801552024108487, - -0.1963681681405034, - -0.02711681633398749 + 0.9898935684946091, + -0.14026460516540398, + -0.020894104211520714 ], [ - -0.04211996726146955, - -0.339974203333342, - 0.9394910587258147 + -0.01890823378129857, + -0.2765657219676307, + 0.9608089717148747 ], [ - -0.19370515621645426, - -0.9197048894123606, - -0.34149850489593153 + -0.14054608407309085, + -0.9507035510453911, + -0.27642278538753484 ] ], "f": 439.1666666666667, @@ -497,92 +595,92 @@ ], "lens_at_bound": null, "lens_determined": null, - "planarity": 0.19830612711424103, - "rms": 32.779486198294116, - "median": 19.58324729035866, + "planarity": 0.19862415641847384, + "rms": 25.801827464127516, + "median": 17.792920874930637, "worst": [ - "battery.l", - 102.22380096041246 + "battery.r", + 57.9419090320407 ], - "left_out": 42.96759618956867, + "left_out": 33.92647083442346, "model": "rolled", "tried": { "rolled": { - "rms": 32.779486198294116, - "left_out": 42.96759618956867, + "rms": 25.801827464127516, + "left_out": 33.92647083442346, "lens": 51.0 } }, - "azimuth": 170.05006632520676, - "elevation": -23.15020712219455, - "distance": 6.396893217501168, - "roll": -1.6532865099542509, + "azimuth": 173.56131040229633, + "elevation": -18.55625118138831, + "distance": 6.354640068030173, + "roll": -1.245778677356766, "twist": 0.0, "plane": null, "residuals": { "shoulder_l": [ - 16.360768305780994, - -2.7185801877380413 + 15.431188336156765, + -5.458315048451141 ], "elbow_l": [ - 5.239583786127184, - -9.469384032388461 + 4.220840113051679, + -7.280468136709715 ], "wrist_l": [ - -10.262287111815567, - 16.04578454725629 + -8.445465012040756, + 18.235625893548615 ], "shoulder_r": [ - -18.046853969127255, - 12.302798395638945 + -14.202713865197893, + 4.21125641894389 ], "elbow_r": [ - 5.207736132342234, - 21.900129662947563 + 8.88073455666472, + 17.673495416835976 ], "waist": [ - 14.697765062633948, - 13.739599675522356 + 15.365847139766743, + 11.54176099474114 ], "hip_l": [ - 16.21680034359065, - 0.6541111104155561 + 16.170586569033276, + 1.2442728899811186 ], "hip_r": [ - 11.555201482025268, - 5.271004542591356 + 12.90127002599445, + 3.763214260717291 ], "knee_l": [ - 23.18221946872802, - -6.49031700946864 + 25.41663153102172, + -6.144280484195178 ], "knee_r": [ - -21.588810484495866, - -10.573709856562346 + -19.49563538654411, + -11.58983756615362 ], "hock_l": [ - 3.721666154554896, - -7.90575336848849 + 2.416594348985882, + -3.422882308771932 ], "hock_r": [ - 3.1128946682671312, - -10.653624469228816 + 0.8369246562144781, + -7.0590412425748355 ], "ankle_l": [ - -5.91654978220987, - 16.706752299700725 + -3.3769965320499864, + 12.799010510953963 ], "ankle_r": [ - -41.17572364217676, - 4.700924904905037 + -42.41824870447158, + 2.2781371334604046 ], "battery.l": [ - -95.64459590891443, - -36.080697834361445 + -35.60875331389485, + -24.785135246587288 ], "battery.r": [ - -18.24940130691391, - -21.26675721379985 + -53.97793486693945, + -21.06293829876833 ] }, "unit": 1024, @@ -605,317 +703,27 @@ "battery.r" ] }, - "hero_body": { - "C": [ - -0.061067790666247235, - 9.071646594599112, - 2.3916286414040244 - ], - "R": [ - [ - -0.997183474552157, - -0.02405875831445358, - 0.07103727351506786 - ], - [ - 0.0644247263939911, - 0.2101697555358383, - 0.9755399163986399 - ], - [ - -0.038400165483331423, - 0.9773688403086997, - -0.20802782814921683 - ] - ], - "f": 718.0555555555555, - "c": [ - 235.0, - 395.0 - ], - "box": [ - 0.0, - 0.0, - 470.0, - 790.0 - ], - "lens": 55.0, - "lens_band": [ - 55.0, - 55.0 - ], - "lens_at_bound": null, - "lens_determined": null, - "planarity": 0.2057180605909678, - "rms": 24.30179567577597, - "median": 21.215160069044778, - "worst": [ - "hip_r", - 36.62894560619136 - ], - "left_out": 29.352067330172403, - "model": "rolled", - "tried": { - "rolled": { - "rms": 24.30179567577597, - "left_out": 29.352067330172403, - "lens": 55.0 - } - }, - "azimuth": 0.3969968772840446, - "elevation": -9.19810955000356, - "distance": 8.928362140384086, - "roll": 4.164837028717504, - "twist": 0.0, - "plane": null, - "residuals": { - "shoulder_r": [ - 8.419393152055477, - -1.0721923462543543 - ], - "elbow_r": [ - -2.979574988481886, - 22.490459129009082 - ], - "wrist_r": [ - -26.557475754736302, - 11.334411322672167 - ], - "shoulder_l": [ - 17.938590777634204, - 9.073413786233147 - ], - "elbow_l": [ - 12.371154085371018, - 19.91320800707473 - ], - "wrist_l": [ - -12.353730796822333, - 28.850835907842168 - ], - "waist": [ - -33.94561979876346, - 12.07095371882599 - ], - "hip_r": [ - -35.16265427029106, - 10.259990296745286 - ], - "hip_l": [ - -18.588215415093543, - 17.697280125097507 - ], - "knee_r": [ - -7.112508573075587, - -16.991522261823945 - ], - "knee_l": [ - -18.082685676438302, - -8.548520680931063 - ], - "hock_r": [ - 15.057545566371516, - -27.781294034931534 - ], - "hock_l": [ - 7.5736707341700935, - -18.378896197397808 - ], - "ankle_r": [ - 9.483628106382753, - -16.668130392557487 - ], - "ankle_l": [ - 7.859719735531598, - -3.935446052448924 - ], - "brow.r": [ - 13.682851561025473, - -12.935423377511484 - ], - "brow.l": [ - 0.23020402862778155, - -21.213911069399614 - ], - "sole.r": [ - 9.982169348349998, - 3.1508707693246834 - ], - "sole.l": [ - -5.51496857190773, - 32.25976029671972 - ] - }, - "unit": 1024, - "marks": [ - "shoulder_r", - "elbow_r", - "wrist_r", - "shoulder_l", - "elbow_l", - "wrist_l", - "waist", - "hip_r", - "hip_l", - "knee_r", - "knee_l", - "hock_r", - "hock_l", - "ankle_r", - "ankle_l", - "brow.r", - "brow.l", - "sole.r", - "sole.l" - ] - }, - "hero_joints": { - "C": [ - 2.542414839359114, - 8.229587684154374, - 2.935486180337758 - ], - "R": [ - [ - -0.9589066670638093, - 0.2678389552392027, - 0.0935964631647429 - ], - [ - 0.13041312693719043, - 0.12311548169820391, - 0.9837860511761098 - ], - [ - 0.25197305447813456, - 0.9555652108687254, - -0.15298597188751473 - ] - ], - "f": 717.3396014085858, - "c": [ - 235.0, - 395.0 - ], - "box": [ - 0.0, - 0.0, - 470.0, - 790.0 - ], - "lens": 54.94516095895551, - "lens_band": [ - 20.213195108655505, - 3999.999999999997 - ], - "lens_at_bound": null, - "lens_determined": false, - "planarity": 0.14649345092715688, - "rms": 22.383175283858343, - "median": 20.729521583622603, - "worst": [ - "wrist_l", - 37.379056789917456 - ], - "left_out": 32.17189170734082, - "model": "rolled", - "tried": { - "rolled": { - "rms": 22.383175283858343, - "left_out": 32.17189170734082, - "lens": 54.94516095895551 - } - }, - "azimuth": -17.3088394000926, - "elevation": -6.307794789173326, - "distance": 8.597343659880249, - "roll": 5.434707701900085, - "twist": 0.0, - "plane": null, - "residuals": { - "shoulder_r": [ - 15.220325062525603, - -30.102955519176277 - ], - "elbow_r": [ - -4.4897922689991105, - 0.8187692221258089 - ], - "wrist_r": [ - -20.717897365551238, - 0.6941137056422235 - ], - "shoulder_l": [ - 27.309265187055246, - 6.212541780945912 - ], - "elbow_l": [ - 14.028815929858581, - 22.745170618249233 - ], - "wrist_l": [ - -3.9217571084134306, - 37.17275491117766 - ], - "waist": [ - -24.503792241373844, - 2.927800881818655 - ], - "hip_r": [ - -28.339496130592693, - 0.6921761352539306 - ], - "hip_l": [ - -10.866544357737212, - 15.953313933656318 - ], - "knee_r": [ - 8.691077416544232, - -11.949142516332756 - ], - "knee_l": [ - -1.776631893898582, - 0.08952100824575382 - ], - "hock_r": [ - 5.841396872669463, - -22.954252269074573 - ], - "hock_l": [ - -0.7399078228997382, - -14.315621173220734 - ], - "ankle_r": [ - 11.442520916502247, - 1.3506741751867821 - ], - "ankle_l": [ - 9.990304845153616, - 5.0222477827985585 - ] - } - }, "inset": { "C": [ - -3.4371595147250193, - 1.8207955864998735, - 8.278558116978784 + -3.324417268862688, + 3.9762429317781858, + 8.991409604726126 ], "R": [ [ - -0.6698247446455166, - -0.6994227669871684, - 0.24928418417657708 + -0.9163452724659232, + -0.3640557510137873, + 0.16665758843551173 ], [ - 0.28392760898448044, - 0.06894907926495698, - 0.9563634964410085 + 0.22074463390844207, + -0.11209544871324653, + 0.9688686273063051 ], [ - -0.6860903179005841, - 0.7113745971627942, - 0.15240163448778285 + -0.3340406385905478, + 0.9246069546199419, + 0.1830814879731312 ] ], "f": 401.3888888888889, @@ -936,56 +744,56 @@ ], "lens_at_bound": null, "lens_determined": null, - "planarity": 0.15540208082967208, - "rms": 19.680148670073166, - "median": 13.337517465548238, + "planarity": 0.12850896556011304, + "rms": 21.396268556451894, + "median": 8.368323059755085, "worst": [ "l.radar", - 33.55168529824139 + 43.70162598642218 ], - "left_out": 30.406204589308384, + "left_out": 34.75349705626076, "model": "rolled", "tried": { "rolled": { - "rms": 19.680148670073166, - "left_out": 30.406204589308384, + "rms": 21.396268556451894, + "left_out": 34.75349705626076, "lens": 50.0 } }, - "azimuth": 48.589709265931084, - "elevation": 7.1625125058397385, - "distance": 2.659987559042347, - "roll": 14.609545732148554, + "azimuth": 23.73604207239102, + "elevation": 8.384198372759322, + "distance": 4.320751517068959, + "roll": 9.760081116333962, "twist": 0.0, "plane": null, "residuals": { "l.ir": [ - 4.83755490394276, - 12.429297433690436 + 6.80813926022995, + 17.001633039268228 ], "l.lidar": [ - 32.9223805350606, - -3.614255525068785 + 27.163655452304056, + -9.928031350325398 ], "l.radar": [ - -33.547977706842744, - -0.49877663679208695 + -42.070936885474225, + -11.826596443422531 ], "l.optical": [ - 2.314364687100806, - -4.7806560077262645 + 0.41607761943930655, + -1.7729251999795395 ], "l.comms": [ - 0.13627431629674902, - 8.730326448793363 + 1.7799454889822073, + 4.750614221679882 ], "l.node": [ - -4.212141174623866, - -13.250261757995759 + 1.411374195712824, + -4.675472080822658 ], "l.root": [ - -3.3183776823562994, - -1.354803826168677 + -8.290985678350125, + -1.1350715016340587 ] }, "unit": 1024 diff --git a/surfaces/blender/experiments/mechs/stag_cameras.py b/surfaces/blender/experiments/mechs/stag_cameras.py index 3455cc6..7da78ff 100644 --- a/surfaces/blender/experiments/mechs/stag_cameras.py +++ b/surfaces/blender/experiments/mechs/stag_cameras.py @@ -1,17 +1,11 @@ -"""STAG's cameras and the arrays' two-view lift (images/37.webp). Plain Python and numpy; brokkr_reference.core -solves and projects. +"""STAG's cameras but the hero's (images/37.webp). Plain Python and numpy; brokkr_reference.core solves and projects. -Pass 2. The hero and rear three-quarter cameras are solved on more than the joints (concepts.json stag.marks): the -brow's lip corners, the soles, the batteries' cell faces and, once the arrays are built, the housings at the spar -tips. The rear and side elevations are solved square from the joints, as in pass 1 (about 1 px). +The rear and side elevations are solved square from the joints (about 1 px). The rear three-quarter is solved on +the joints and the batteries' cell faces (pass 3: re-marked on the faces, follow-up stag-rear3q-batteries). The hero +camera is stag_hero.py's, solved together with the body's pose; this script leaves it as it stands. The inset is +solved from the built housings once a build has written them. - python stag_cameras.py solves every view, writes stag_cameras.json - python stag_cameras.py arrays the arrays' housings lifted by two views: each housing's hero ray against its - rear-elevation ray, the point taken ON THE HERO RAY nearest the rear ray (the hero - view is favoured; the miss between the rays is the views' disagreement, recorded). - The rear elevation draws no ir housing (the lidar's hides it): the ir housing's - depth is the lidar's, a plane of ours, said so in the record. Left and right are - averaged in the array's frame. Writes stag_arrays.json, which stag_form reads. + python stag_cameras.py solves rear, side, rear3q and inset, writes them into stag_cameras.json World points: stag_form.J (the skeleton, from the rear and side elevations) and the built points stag.py writes (MECH_OUT/stag/stag_points.json: brow.*, sole.*, battery.*, .); before a build, stag_form's design @@ -37,12 +31,9 @@ spec.loader.exec_module(core) C = json.loads((HERE / "concepts.json").read_text(encoding="utf-8"))["stag"] VIEWS = C["skeleton"]["views"] MARKS = C["marks"] -MODELS = {"rear": "square", "side": "square", "hero": "rolled", "rear3q": "rolled"} -# The perspective views' lenses are held at what their joints alone solve to (pass 1: hero 55 mm, rear three-quarter -# 51 mm). Free, the extra marks drive the hero to 900 to 1600 mm: the hero draws the arrays about 1.5 times the -# elevations' size and the chest shorter, and a long lens is how a solve reconciles marks that disagree, not a lens -# the view's foreshortened feet allow. -LENS = {"hero": 55.0, "rear3q": 51.0} +MODELS = {"rear": "square", "side": "square", "rear3q": "rolled"} +# The rear three-quarter's lens is held at what its joints alone solve to (pass 1: 51 mm). +LENS = {"rear3q": 51.0} OUT = Path(os.environ["MECH_OUT"]) / "stag" if os.environ.get("MECH_OUT") else None @@ -65,16 +56,14 @@ def world(pts=None, sk=None): return W -def marks(tag, housings=True): +def marks(tag): m = dict(VIEWS[tag]["joints"]) m.update(MARKS.get(tag, {})) - if tag == "hero" and housings: - m.update(C["housings"]["hero"]) return m -def solve(tag, W, housings=True): - m = marks(tag, housings) +def solve(tag, W): + m = marks(tag) names = [k for k in m if k in W] cam = core.solve({k: W[k] for k in names}, {k: m[k] for k in names}, VIEWS[tag]["box"], model=MODELS[tag], lens=LENS.get(tag)) cam["unit"] = C["unit"] @@ -88,11 +77,7 @@ def solve(tag, W, housings=True): def solve_all(): pts, sk = built_points() W = world(pts, sk) - have = any(k in W for k in C["housings"]["hero"]) - out = {tag: solve(tag, W, housings=have) for tag in MODELS} - out["hero_body"] = solve("hero", W, housings=False) # the body's marks alone, for the record - out["hero_joints"] = core.solve({k: W[k] for k in VIEWS["hero"]["joints"]}, VIEWS["hero"]["joints"], VIEWS["hero"]["box"], model="rolled") - print(f"CAMERA hero, joints alone, lens free: rms {out['hero_joints']['rms']:.1f} px, lens {out['hero_joints']['lens']:.0f} mm", flush=True) + out = {tag: solve(tag, W) for tag in MODELS} ins = C["housings"]["inset"] names = [k for k in ins if k in pts and not k.startswith("_") and k != "box"] if len(names) >= 6: @@ -103,63 +88,11 @@ def solve_all(): return out -def _nearest_on(a0, ad, b0, bd): - """The point on line a (a0 + t ad) nearest line b, and the distance between the lines there.""" - ad, bd = ad / np.linalg.norm(ad), bd / np.linalg.norm(bd) - w = a0 - b0 - b, d, e = ad @ bd, ad @ w, bd @ w - den = 1 - b * b - t = (b * e - d) / den - s = (e - b * d) / den - p, q = a0 + t * ad, b0 + s * bd - return p, float(np.linalg.norm(p - q)) - - -def arrays(): - W = world() - hero = solve("hero", W, housings=False) - rear = solve("rear", W, housings=False) - hm, rm = C["housings"]["hero"], MARKS["rear_housings"] - rx, ry, rz = SF.ROOT - lifted, misses = {}, {} - for key, px in hm.items(): - side, kind = key.split(".") - s = 1 if side == "r" else -1 - o, d = (np.asarray(v, float) for v in core.ray(hero, px)) - if key in rm: - ro, rd = (np.asarray(v, float) for v in core.ray(rear, rm[key])) - p, miss = _nearest_on(o, d, ro, rd) - misses[key] = round(miss, 3) - else: - y = lifted[f"{side}.lidar"][1] if f"{side}.lidar" in lifted else W.get(f"{side}.lidar", [0, ry, 0])[1] - p = np.asarray(core.lift(hero, px, (0.0, y, 0.0), (0.0, 1.0, 0.0)), float) - misses[key] = None - lifted[key] = p - # the rear's own reading of the same housings, for the disagreement: x and z from the rear ray at the hero's depth - local = {} - for key, p in lifted.items(): - side, kind = key.split(".") - s = 1 if side == "r" else -1 - local.setdefault(kind, []).append((s * p[0] - rx, p[1] - ry, p[2] - SF.WAIST[2] - rz)) - design = {k: [round(float(c), 3) for c in np.mean(v, axis=0)] for k, v in local.items()} - spread = {k: round(float(np.linalg.norm(np.subtract(*v))), 3) if len(v) == 2 else None for k, v in local.items()} - rec = {"_doc": "Housing centres in the array's frame (origin the pylon's root, x outboard, y forward, z up), lifted from the hero view's marks: each " - "the point on its hero ray nearest its rear-elevation ray, left and right averaged. miss: metres between the two rays (the views' " - "disagreement); lr: metres between the left's and the right's lifted points (the hero draws the two arrays unlike). The ir housing has no " - "rear mark: its depth is the lidar's, our plane, not a fit.", - "hero": {"rms": hero["rms"], "lens": hero.get("lens"), "marks": hero["marks"]}, - "housings": design, "miss": misses, "lr": spread, - "world": {k: [round(float(c), 3) for c in v] for k, v in lifted.items()}} - (HERE / "stag_arrays.json").write_text(json.dumps(rec, indent=1), encoding="utf-8") - for k in design: - print(f"ARRAY {k:8s} {design[k]} lr {spread[k]} miss r {misses.get('r.' + k)} l {misses.get('l.' + k)}") - return rec - - if __name__ == "__main__": - if sys.argv[1:] == ["arrays"]: - arrays() - else: - cams = solve_all() - (HERE / "stag_cameras.json").write_text(json.dumps(cams, indent=1), encoding="utf-8") - print("wrote", HERE / "stag_cameras.json") + path = HERE / "stag_cameras.json" + cams = json.loads(path.read_text(encoding="utf-8")) + cams.pop("hero_body", None) + cams.pop("hero_joints", None) + cams.update(solve_all()) + path.write_text(json.dumps(cams, indent=1), encoding="utf-8") + print("wrote", path, "(the hero is stag_hero.py's)") diff --git a/surfaces/blender/experiments/mechs/stag_form.py b/surfaces/blender/experiments/mechs/stag_form.py index 0d2348e..50b8ba9 100644 --- a/surfaces/blender/experiments/mechs/stag_form.py +++ b/surfaces/blender/experiments/mechs/stag_form.py @@ -41,20 +41,33 @@ LEG["foot"]["drop"] = J["ankle_r"][2] # the torso, in its frame (the waist pin): a narrow waist under a broad chest TORSO = { "column": (0.36, 0.55), # the waist's column: radius, height - "dorsal": {"x": 0.52, "y": (-0.5, -1.45), "z": (0.2, 2.42)}, # the equipment module on the back - "battery": {"at": (0.9, -1.12, 2.2), "up": 38.0, "out": 24.0}, # the batteries' centres, their cells' pitch up and yaw out + # the equipment module on the back. Pass 3: its top under the head's back and the batteries (the rear elevation and + # the rear three-quarter draw it from the waist to the shoulders' crown; pass 2 stood it 0.3 m over the head) + "dorsal": {"x": 0.52, "y": (-0.5, -1.45), "z": (0.2, 1.85)}, + # the batteries' centres, their cells' pitch up and yaw out. Pass 3: their cell faces stand at (1.0, -1.3, 2.05), + # over the dorsal module's top either side of the head, as the rear three-quarter draws them once its marks sit on + # the cell faces (follow-up stag-rear3q-batteries). A grid of face places against the stance's camera + # (stag_cameras.py) prefers 1.6 m up by 1.5 px of 24.9, too little to choose by, and 1.6 m buries them in the + # module; at 2.05 the left face misses by 33 px, the right by 51, both the same way: a turn of the torso on the + # waist (18 degrees by the solve's turned model), which the stance build does not pose. + "battery": {"at": (0.856, -0.976, 1.773), "up": 38.0, "out": 24.0}, "shoulder": (J["shoulder_r"][0], J["shoulder_r"][1], J["shoulder_r"][2] - WAIST[2]), - "brow_lip": (0.55, 1.38, 1.76), # the brow's lip, its outer front corner (the right; the left its mirror) + "brow_lip": (0.78, 1.28, 1.73), # the brow's lip, its outer front corner (the right; the left its mirror; HULL["Brow"]) } # Per plate, decided before building (mech-lessons-2026-12-03): "hard" plates have a faceted silhouette in the -# concept and are cages creased fully along every facet edge; "soft" plates are ones the concept actually curves. +# concept; "soft" plates are ones the concept actually curves. Pass 3: the hero at its posed camera draws the breast, +# the brow, its cap, the keel and the chin as flat facets meeting at chamfers (the "curved shells" of the prompt are +# faceted at figure scale: the 37 shells' outer shoulders turn in two chamfers, not a roll), so each is a hard solid +# written by its bounding faces (massing.corners, Bastion pass 2's method), detail plates stepped on its large facets. +# Soft cages stay where the concept truly curves: the flanks wrapping the ribs into the waist, the dorsal cover, the +# thigh shields, the upper arms' shells. KINDS = { - "Breast": "hard", # the "37" shells: flat faces, chamfered facets, a crisp outer corner - "Brow": "hard", # the sculpted brow: a faceted wedge with a lip, its crown ridge a facet edge - "BrowCap": "hard", # the smaller crown plate layered over the brow - "Chin": "hard", # the plate under the cockpit - "Keel": "hard", # the sternum's stepped V, two layers + "Breast": "hard", # the 37 shells: front face, its top and bottom chamfers, outer side and two shoulder chamfers, crown, inner cheek + "Brow": "hard", # the head's wide faceted wedge, its lip overhanging the recessed visor + "BrowCap": "hard", # the raised crown plate stepped on the brow + "Chin": "hard", # the plate under the visor + "Keel": "hard", # the sternum's pentagon, pointing down between the shells, its centre ridge proud "Flank": "soft", # the lower chest under each breast shell: curved ribs into the waist "Dorsal.cover": "soft", # the equipment module's rear cover: a shallow curve "Shield": "soft", # the thigh shields: ovoid, one crease down the outer front @@ -62,34 +75,76 @@ KINDS = { "Shell": "soft", # the upper arms' shells } -# The sensor arrays. ROOT: the pylon's foot on the breast shell's crown, in the torso's frame (the right; the left -# its mirror). The tree is the antler's: a short trunk on the pylon to the node; from the node the main beam -# outboard and up, toward the optical housing; off the beam a tine up (radar); low off the trunk the inner stem -# (lidar), a tine inboard (ir) and a long tine out (comms). Each terminal spar carries one housing on a tilt head (a cross and a wrist, 0.2 m) above its tip. +# The hard hull, in the torso's frame, the right side (x >= 0; mirrored). A plate is {"faces": [(point, outward +# normal)]} (its corners are where three faces meet inside the rest) or {"points": [...], "mirror": True} (one solid +# across the centre line from its right half). Read off the hero at its posed camera and the front elevation, by +# hand (about 0.05 m); depths where only one view shows a face are planes of my choosing. +HULL = { + # the 37 shell: a broad front face turned a little outboard, its top edge chamfered back to the crown, the outer + # shoulder rounded by two chamfers into the outer side, the underside cut up in a V toward the waist + "Breast": {"faces": [((0.95, 1.1, 1.25), (0.34, 1.0, 0.04)), ((0.95, 0.0, 1.76), (0.0, 0.0, 1.0)), ((0.95, 0.98, 1.64), (0.0, 0.75, 0.66)), + ((1.58, 0.0, 1.25), (1.0, 0.0, 0.06)), ((1.48, 0.9, 1.25), (0.78, 0.62, 0.0)), ((1.54, 0.0, 1.62), (0.62, 0.0, 0.78)), + ((1.4, 0.0, 1.72), (0.28, 0.0, 0.96)), ((0.52, 0.0, 1.25), (-1.0, 0.08, -0.3)), ((0.95, 0.0, 0.78), (0.0, 0.0, -1.0)), + ((1.42, 0.0, 0.92), (0.62, 0.0, -0.78)), ((0.95, 1.0, 0.86), (0.0, 0.62, -0.78)), ((0.95, -0.56, 1.25), (0.0, -1.0, 0.0))], + "bevel": 0.035, "clad": True}, + # the head: a wide flattened wedge, its lip a front face 0.22 m deep forward over the visor (the hero's camera is + # under the head: a lip that is only an edge reads as a dark underside), the crown ridged, its back low over the + # dorsal; the hero draws it about 45% of the chest's width + "Brow": {"points": [(0.0, 1.6, 1.64), (0.46, 1.53, 1.64), (0.76, 1.26, 1.62), (0.0, 1.66, 1.86), (0.46, 1.59, 1.86), (0.8, 1.3, 1.84), + (0.0, 1.3, 2.1), (0.44, 1.24, 2.08), (0.0, 0.45, 2.16), (0.56, 0.45, 2.09), (0.8, 0.5, 1.92), + (0.0, -0.25, 2.06), (0.6, -0.25, 1.96), (0.74, -0.25, 1.74), (0.7, 0.6, 1.7), (0.0, 0.6, 1.72)], + "mirror": True, "bevel": 0.03, "clad": True}, + "BrowCap": {"points": [(0.0, 1.2, 2.18), (0.32, 1.14, 2.16), (0.0, 0.3, 2.24), (0.42, 0.3, 2.18), (0.0, 1.24, 2.08), (0.36, 1.16, 2.06), + (0.0, 0.25, 2.12), (0.46, 0.25, 2.08)], "mirror": True, "bevel": 0.02, "clad": False}, + # under the visor, set low and back so a camera under the head sees the visor over it; the visor itself is the + # cockpit's (stag_body.cockpit), set back 0.3 m behind the brow's lip + "Chin": {"points": [(0.0, 1.12, 1.42), (0.28, 1.08, 1.42), (0.44, 0.96, 1.41), (0.0, 1.18, 1.3), (0.26, 1.14, 1.3), (0.4, 1.02, 1.3), + (0.0, 1.06, 1.18), (0.32, 0.96, 1.18), (0.0, 0.7, 1.42), (0.44, 0.7, 1.42), (0.0, 0.7, 1.18), (0.34, 0.7, 1.18)], + "mirror": True, "bevel": 0.025, "clad": False}, + # the sternum: a pentagon pointing down between the shells, under the cockpit's dark recess, its centre ridge proud + "Keel": {"points": [(0.0, 1.2, 1.1), (0.32, 1.12, 1.1), (0.34, 1.06, 0.84), (0.0, 0.94, 0.42), (0.14, 0.93, 0.54), + (0.0, 1.26, 0.86), (0.0, 0.75, 1.1), (0.34, 0.75, 1.1), (0.34, 0.75, 0.84), (0.0, 0.7, 0.42)], + "mirror": True, "bevel": 0.03, "clad": True}, + "Keel.ridge": {"points": [(0.0, 1.29, 1.05), (0.08, 1.26, 1.05), (0.0, 1.31, 0.86), (0.07, 1.28, 0.86), (0.0, 1.03, 0.5), + (0.0, 1.12, 1.05), (0.08, 1.12, 1.05), (0.0, 0.95, 0.5)], "mirror": True, "bevel": 0.015, "clad": False}, +} +NUMERAL = {"at": (0.98, 1.1, 1.28), "height": 0.34} # the 37 on each breast's front face, centred (the hero: x 215 and 350) + +# The sensor arrays, pass 3: measured off the hero through its posed camera (stag_hero.py arrays; stag_arrays.json: +# the two sides averaged, on the frontal plane through the roots, from each side's marked root). Pass 2's arrays were +# held to the rear elevation's heights and read as a candelabra: short spars splayed sideways under big housings. +# The hero's are a tree that climbs: the trunk rises 0.83 m at 66 degrees to the node, the optical beam runs 1.1 m +# out and up at 30 degrees with the comms tine off it (a third tier), the radar and lidar stems climb near vertical +# (81 and 89 degrees, 0.9 and 0.6 m) and the ir stem leaves the trunk low and climbs inboard. The radar's housing +# stands 2.04 m over the root, the optical's 1.65 m outboard: the array rises 1.9 m over the brow's crown, about a +# quarter of the body's height again (the rear elevation draws 0.65 m; the hero is favoured; the two sides of the +# hero disagree by 0.2 to 0.7 m at the housings). The build stands about 9.3 m to the radar's top against the +# sheet's 8.5 m and its soldier's 6.7 m: the body is held at pass 2's scale and the disagreement recorded here. +# The housings are 0.28 to 0.42 m across, a little smaller than the hero's (about 0.45 m at the solved scale) so +# each spar runs about three times its housing's width (Self's figure-scale reading); depth (y): the side elevation's. ROOT = (1.0, -0.08, 1.7) PYLON = 0.1 # the pylon's height to the trunk's yoke -NODE = (0.1, 0.0, 0.55) # the trunk's top, from the root -HEAD = 0.2 # a head's length: the cross's drop and the wrist's, aimed along the spar's rise -# kind: (centre from the root, size (w, h, d), look yaw outboard in degrees). Centres: the hero's outboard reach -# (stag_cameras.py arrays, the two sides averaged), the rear elevation's heights less 0.12 m so the radar's top -# stands at the scale comparison's 8.5 m, the side elevation's depth. +NODE = (0.34, 0.0, 0.76) # the trunk's top, from the root (measured) +HEAD = 0.14 # a head's length: the cross's drop and the wrist's, aimed along the spar's rise +# kind: (centre from the root, size (w, h, d), look yaw outboard in degrees); centres x and z measured, y the side's HOUSINGS = { - "optical": ((1.35, 0.15, 1.18), (0.4, 0.3, 0.4), 20.0), - "radar": ((0.5, 0.02, 1.32), (0.46, 0.32, 0.14), 6.0), - "lidar": ((0.18, -0.08, 1.1), (0.3, 0.3, 0.3), 0.0), - "ir": ((-0.18, 0.1, 1.0), (0.34, 0.26, 0.32), -10.0), - "comms": ((1.15, 0.24, 0.8), (0.38, 0.38, 0.18), 34.0), + "optical": ((1.65, 0.15, 1.62), (0.38, 0.28, 0.36), 20.0), + "radar": ((0.62, 0.02, 2.04), (0.42, 0.32, 0.12), 6.0), + "lidar": ((0.28, -0.08, 1.67), (0.28, 0.28, 0.28), 0.0), + "ir": ((-0.13, 0.1, 1.48), (0.32, 0.25, 0.3), -10.0), + "comms": ((1.32, 0.24, 1.0), (0.34, 0.34, 0.16), 34.0), } # branch: (parent, where along the parent 0..1, the far end: a housing's kind (its tip) or a point, radii root and tip) +# Three tiers: the trunk; the optical beam, the radar, lidar and ir stems off it; the comms tine off the beam (where +# the hero's comms spar leaves it, 0.42 along). BRANCHES = { - "beam": ("trunk", 1.0, (0.68, 0.07, 0.72), (0.11, 0.085)), - "optical": ("beam", 1.0, "optical", (0.085, 0.06)), - "radar": ("beam", 0.25, "radar", (0.075, 0.055)), - "stem": ("trunk", 0.3, "lidar", (0.09, 0.065)), - "ir": ("trunk", 0.12, "ir", (0.07, 0.05)), - "comms": ("trunk", 0.5, "comms", (0.08, 0.055)), + "optical": ("trunk", 1.0, "optical", (0.085, 0.062)), + "comms": ("optical", 0.42, "comms", (0.062, 0.048)), + "radar": ("trunk", 1.0, "radar", (0.075, 0.055)), + "lidar": ("trunk", 0.9, "lidar", (0.065, 0.05)), + "ir": ("trunk", 0.72, "ir", (0.065, 0.05)), } -TRUNK_R = (0.18, 0.14) +TRUNK_R = (0.17, 0.13) KINDS_ARRAY = tuple(HOUSINGS) @@ -119,4 +174,4 @@ def design_points(): bx, by, bz = TORSO["brow_lip"] return {"brow.r": (bx, by, wz + bz), "brow.l": (-bx, by, wz + bz), "sole.r": (J["ankle_r"][0], J["ankle_r"][1] + 0.25, 0.0), "sole.l": (J["ankle_l"][0], J["ankle_l"][1] + 0.25, 0.0), - "battery.r": (0.95, -1.25, wz + 2.4), "battery.l": (-0.95, -1.25, wz + 2.4)} + "battery.r": (1.0, -1.3, wz + 2.05), "battery.l": (-1.0, -1.3, wz + 2.05)} diff --git a/surfaces/blender/experiments/mechs/stag_hero.py b/surfaces/blender/experiments/mechs/stag_hero.py new file mode 100644 index 0000000..6439b2f --- /dev/null +++ b/surfaces/blender/experiments/mechs/stag_hero.py @@ -0,0 +1,257 @@ +"""STAG's hero camera, solved together with the body's pose (pass 3; follow-up stag-hero-pose-solve). Plain Python and +numpy; no Blender. + +Pass 2 solved the hero camera on the elevations' stance and missed by 24 to 28 px rms, every leg joint pulled the +same way: the hero does not stand as the elevations do. Its right leg strides out and forward, the torso turns on +the waist, the arms hang otherwise. A camera fitted to joints the build does not pose where the concept draws them +reconciles them with a wrong view, which is what pass 2 rendered: near-frontal, the arrays splayed sideways. + +Here the unknowns are the camera (azimuth, distance, pitch, eye height, roll, the principal point's u; the lens is +scanned and the marked horizon chooses) and the pose, about the elevations' stance (stag_form.J): + torso yaw and pitch on the waist pin, carrying shoulders, brow and everything above (pitch held at 0: free, + it runs to either bound, 20 degrees back or 12 forward at 1 px apart, and the arrays measured off it + move 0.6 m with it; the marks do not decide it) + pelvis a drop (the stance's legs straightened or bent under it) + legs a side: hip abduction (about the front axis), hip flexion, knee and hock bends (about the pin axes) + arms a side: shoulder flexion and abduction, elbow bend +fitted to the hero's 19 marks (15 joints, the brow's lip corners, the soles) and the horizon by brokkr_reference's +Levenberg-Marquardt, with the soles held to the ground and weak priors (0.4 px a degree) holding each angle near +the stance where the marks do not move it. + + python stag_hero.py arrays the arrays measured off the hero through the solved camera and pose (arrays()) + python stag_hero.py prints the lens scan, writes the hero camera into stag_cameras.json with "solved": the + pose, the posed joints ("joints", world), the torso's frame, residuals +""" +import importlib.util +import json +import math +import os +import sys +from pathlib import Path + +import numpy as np + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import stag_form as SF # noqa: E402 + +SURFACE = Path(os.environ["BROKKR_SURFACE"]) if os.environ.get("BROKKR_SURFACE") else HERE.parents[1] +_spec = importlib.util.spec_from_file_location("reference_core", SURFACE / "brokkr_reference" / "core.py") +RC = importlib.util.module_from_spec(_spec) +sys.modules["reference_core"] = RC +_spec.loader.exec_module(RC) + +C = json.loads((HERE / "concepts.json").read_text(encoding="utf-8"))["stag"] +HERO = C["skeleton"]["views"]["hero"] +BOX = HERO["box"] +MARKS = dict(HERO["joints"]) +MARKS.update({k: v for k, v in C["marks"]["hero"].items() if not k.startswith("_")}) +HZ = C["marks"]["hero_horizon"] +NAMES = list(MARKS) +J0 = {k: np.asarray(v, float) for k, v in SF.J.items()} +D0 = {k: np.asarray(v, float) for k, v in SF.design_points().items()} +WAIST = J0["waist"] +POSE = ("torso_yaw", "torso_pitch", "drop", + "hip_abd_r", "hip_flex_r", "knee_r", "hock_r", "hip_abd_l", "hip_flex_l", "knee_l", "hock_l", + "sh_flex_r", "sh_abd_r", "elbow_r", "sh_flex_l", "sh_abd_l", "elbow_l") +ANGLES = [k for k in POSE if k != "drop"] + + +def rx(t): + c, s = math.cos(t), math.sin(t) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def ry(t): + c, s = math.cos(t), math.sin(t) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def rz(t): + c, s = math.cos(t), math.sin(t) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +def torso_frame(q): + """The torso's rotation and its waist pin, world: yaw about z, then pitch about the torso's x (forward lean + positive).""" + p = dict(zip(POSE, q)) + Rt = rz(math.radians(p["torso_yaw"])) @ rx(-math.radians(p["torso_pitch"])) + return Rt, WAIST + np.array([0, 0, -p["drop"]]) + + +def posed(q): + """The world points of a pose: the joints of stag_form.J moved, plus brow.r/l, sole.r/l; and the torso frame.""" + p = {k: (math.radians(v) if k != "drop" else v) for k, v in zip(POSE, q)} + Rt, w = torso_frame(q) + W = {"waist": w} + for tag, s in (("r", 1), ("l", -1)): + # leg: knee and hock bends in the stance's own plane, then the hip's flexion and abduction about the hip pin + hip = J0[f"hip_{tag}"] + np.array([0, 0, -p["drop"]]) + knee, hock, ankle = (J0[f"{n}_{tag}"] - J0[f"hip_{tag}"] for n in ("knee", "hock", "ankle")) + Rk = rx(p[f"knee_{tag}"]) + hock2 = knee + Rk @ (hock - knee) + ankle2 = knee + Rk @ (ankle - knee) + Rh = rx(p[f"hock_{tag}"]) + ankle2 = hock2 + Rh @ (ankle2 - hock2) + Rl = ry(-s * p[f"hip_abd_{tag}"]) @ rx(p[f"hip_flex_{tag}"]) + W[f"hip_{tag}"] = hip + W[f"knee_{tag}"], W[f"hock_{tag}"], W[f"ankle_{tag}"] = (hip + Rl @ v for v in (knee, hock2, ankle2)) + a = W[f"ankle_{tag}"] + W[f"sole.{tag}"] = np.array([a[0], a[1] + 0.25, a[2] - J0[f"ankle_{tag}"][2]]) + # arm, in the torso's frame: the elbow bend, then the shoulder's flexion and abduction + sh = J0[f"shoulder_{tag}"] - WAIST + el, wr = J0[f"elbow_{tag}"] - WAIST - sh, J0[f"wrist_{tag}"] - WAIST - sh + wr = el + rx(p[f"elbow_{tag}"]) @ (wr - el) + Ra = ry(-s * p[f"sh_abd_{tag}"]) @ rx(p[f"sh_flex_{tag}"]) + W[f"shoulder_{tag}"] = w + Rt @ sh + W[f"elbow_{tag}"], W[f"wrist_{tag}"] = (w + Rt @ (sh + Ra @ v) for v in (el, wr)) + W[f"brow.{tag}"] = w + Rt @ (D0[f"brow.{tag}"] - WAIST) + W[f"n37.{tag}"] = w + Rt @ np.array([s * NUMERAL[0], NUMERAL[1], NUMERAL[2]]) + return W, Rt, w + + +def cam_of(c, lens): + az, d, pitch, eye, roll, cx, cy = c + a = math.radians(az) + return {"C": [-d * math.sin(a), d * math.cos(a), eye], "R": RC._rotation(a + math.pi, pitch, math.radians(roll)).tolist(), "f": lens * (BOX[2] - BOX[0]) / 36.0, + "c": [(BOX[0] + BOX[2]) / 2 + cx, (BOX[1] + BOX[3]) / 2 + cy], "box": list(BOX)} + + +def horizon_v(cam): + look = -np.asarray(cam["R"], float)[2] + flat = np.array([look[0], look[1], 0.0]) / max(math.hypot(look[0], look[1]), 1e-9) + return float(RC.project(cam, [np.asarray(cam["C"], float) + 1e7 * flat])[0][1]) + + +NUMERAL = (0.98, 1.09, 1.28) # the 37 on each breast shell's front face, the torso's frame (stag_form.NUMERAL on HULL["Breast"]'s front) +PRIOR = 0.4 # px a degree: how hard an angle the marks do not move is held at the stance +NC = 7 +LEVEL = 3.0 # px a degree: the hero's verticals (the mast at u 65, the treeline at u 715) stand vertical, so the camera is held level and + # unrolled, and the low horizon is a shifted frame (the principal point's v), not a camera pitched up +BALANCE = 25.0 # px a metre: the waist over the middle of the two ankles, front to back + + +def residual(x, lens): + cam = cam_of(x[:NC], lens) + W, _, _ = posed(x[NC:]) + r = (RC.project(cam, [W[k] for k in NAMES]) - np.array([MARKS[k] for k in NAMES])).ravel() + p = dict(zip(POSE, x[NC:])) + ground = [60.0 * (W[f"ankle_{t}"][2] - J0[f"ankle_{t}"][2]) for t in ("r", "l")] # 60 px a metre: the soles stay on the ground + prior = [PRIOR * p[k] for k in ANGLES] + level = [LEVEL * math.degrees(x[2]), LEVEL * x[4], BALANCE * (W["waist"][1] - 0.5 * (W["ankle_r"][1] + W["ankle_l"][1]) - (WAIST[1] - J0["ankle_r"][1]))] + return np.concatenate([r, [0.5 * (horizon_v(cam) - HZ)], ground, prior, level]) + + +LO = [-80, 3, -0.8, 0.3, -15, -80, -100] + [-60, -1e-9, -0.5] + [-15, -40, -40, -40] * 2 + [-60, -30, -60] * 2 +HI = [80, 60, 0.8, 8.0, 15, 80, 400] + [60, 1e-9, 1.0] + [35, 40, 40, 40] * 2 + [80, 50, 80] * 2 + + +# The camera's azimuth about the pelvis is not decided by the marks: held anywhere from -12 to -40 degrees the solve +# moves under a pixel (15.8 to 16.8 px at 55 mm), the legs' pose and the waist's turn taking it up, and the torso is +# seen 6 to 7 degrees off frontal throughout. Held at -25: the legs then stand three-quarter on, as the hero's feet and +# thighs draw them (the near foot large and outboard), for 0.4 px over the least. +AZIMUTH = -25.0 + + +def solve(lens, azimuth=AZIMUTH): + best = None + lo, hi = list(LO), list(HI) + lo[0], hi[0] = azimuth, azimuth + 1e-9 + for yaw in (-30, -10, 10): + for tp in (-5, 8): + x0 = [azimuth, 14 * lens / 35, 0.0, 1.5, 0, 0, 250] + [yaw, 0 * tp, 0] + [0] * 8 + [0] * 6 + x, _ = RC.lm(lambda v: residual(v, lens), x0, lo, hi, rounds=500) + r = residual(x, lens)[:2 * len(NAMES)].reshape(-1, 2) + rms = float(np.sqrt((r ** 2).sum(1).mean())) + if best is None or rms < best[0]: + best = (rms, x, r) + return best + + +def describe(rms, x, lens): + cam = cam_of(x[:NC], lens) + p = dict(zip(POSE, x[NC:])) + return (f"lens {lens}: rms {rms:.1f} px; azimuth {x[0]:.1f}, {x[1]:.1f} m off, pitch {math.degrees(x[2]):.1f}, eye {x[3]:.2f} m, roll {x[4]:.1f}, " + f"centre v {cam['c'][1]:.0f}, horizon v {horizon_v(cam):.0f} (marked {HZ}); " + ", ".join(f"{k} {v:.1f}" for k, v in p.items())) + + +def main(): + scan = {} + for lens in (35, 42, 55, 70): + rms, x, r = solve(lens) + scan[lens] = (rms, x, r) + print(describe(rms, x, lens), flush=True) + stance = RC.lm(lambda v: residual(np.concatenate([v, np.zeros(len(POSE))]), 35)[: 2 * len(NAMES) + 1], [-15, 14, 0.0, 1.5, 0, 0, 250], LO[:NC], HI[:NC], rounds=400)[0] + rs = residual(np.concatenate([stance, np.zeros(len(POSE))]), 35)[:2 * len(NAMES)].reshape(-1, 2) + print(f"the stance unposed, lens 35: rms {float(np.sqrt((rs ** 2).sum(1).mean())):.1f} px", flush=True) + best = min(v[0] for v in scan.values()) + lens = min(k for k in scan if scan[k][0] <= best + 1.0) # the shortest lens within 1 px of the best: past it a longer lens buys under a pixel + rms, x, r = scan[lens] + cam = cam_of(x[:NC], lens) + W, Rt, w = posed(x[NC:]) + cam.update(azimuth=float(x[0]), distance=float(x[1]), lens=float(lens), unit=1024, rms=rms, elevation=math.degrees(x[2]), roll=float(x[4]), horizon=horizon_v(cam), + model="posed", marks=NAMES, residuals={n: [float(a), float(b)] for n, (a, b) in zip(NAMES, r)}, + solved={"pose": {k: float(v) for k, v in zip(POSE, x[NC:])}, "joints": {k: [float(c) for c in v] for k, v in W.items()}, + "torso": {"R": Rt.tolist(), "waist": [float(c) for c in w]}, "stance_rms": float(np.sqrt((rs ** 2).sum(1).mean())), + "scan": {str(k): v[0] for k, v in scan.items()}}) + path = HERE / "stag_cameras.json" + cams = json.loads(path.read_text(encoding="utf-8")) + cams["hero"] = json.loads(json.dumps(cam, default=float)) + path.write_text(json.dumps(cams, indent=1), encoding="utf-8") + print("HERO-SOLVED", describe(rms, x, lens), flush=True) + print("worst", sorted(((n, round(math.hypot(*v))) for n, v in cam["residuals"].items()), key=lambda q: -q[1])[:6]) + + +def arrays(): + """The arrays' trees measured off the hero, after the pose: each marked point's ray through the solved hero + camera, taken into the posed torso's frame and met with the arrays' frontal plane through the pylon roots (the + side and front elevations stand the arrays over the shoulders, in one plane across the mech: the depth is that + plane's, ours, not a fit). Left and right averaged in the array's frame (x outboard, y forward, z up, origin the + root). Returns and writes stag_arrays.json: points, spar lengths and their rise from the horizontal.""" + cam = json.loads((HERE / "stag_cameras.json").read_text(encoding="utf-8"))["hero"] + Rt, w = np.asarray(cam["solved"]["torso"]["R"]), np.asarray(cam["solved"]["torso"]["waist"]) + rx_, ry_, rz_ = SF.ROOT + A = C["array_hero"] + local = {} + for tag, s in (("r", 1), ("l", -1)): + def lift(px): + o, d = (np.asarray(v, float) for v in RC.ray(cam, px)) + o, d = Rt.T @ (o - w), Rt.T @ d # into the torso's frame (origin the waist pin) + t = (ry_ - o[1]) / d[1] + p = o + t * d + return np.array([s * p[0] - rx_, p[1] - ry_, p[2] - rz_]) + pts = {"root": lift(A[tag]["root"]), "node": lift(A[tag]["node"])} + for kind, m in A[tag].items(): + if isinstance(m, dict): + for k, px in m.items(): + pts[f"{kind}.{k}"] = lift(px) + local[tag] = pts + for pts in local.values(): # from the marked root: the hero draws the breast's crown, and the root on it, 0.4 to + r0 = pts["root"].copy() # 1.0 m above the skeleton's as the pose moves; the tree over its own root holds + for k in pts: + pts[k] = pts[k] - r0 + mean = {k: (local["r"][k] + local["l"][k]) / 2 for k in local["r"]} + lr = {k: float(np.linalg.norm(local["r"][k] - local["l"][k])) for k in local["r"]} + spars = {} + for kind in ("optical", "comms", "radar", "lidar", "ir"): + v = mean[f"{kind}.base"] - mean[f"{kind}.from"] + spars[kind] = {"length": float(np.linalg.norm(v)), "rise": float(math.degrees(math.atan2(v[2], math.hypot(v[0], v[1]))))} + v = mean["node"] - mean["root"] + spars["trunk"] = {"length": float(np.linalg.norm(v)), "rise": float(math.degrees(math.atan2(v[2], math.hypot(v[0], v[1]))))} + rec = {"_doc": "Pass 3: the arrays measured off the hero view through the posed hero camera (stag_hero.py arrays): points in the array's frame (origin " + "the marked root, where the trunk leaves the breast's crown, x outboard, y forward, z up), the two sides averaged; lr: metres between the sides' lifts (the hero draws the two " + "arrays unlike); spars: length (m) and rise above the horizontal (degrees) from where a spar leaves its parent to the housing's base. " + "Depth: the frontal plane through the roots, ours.", + "points": {k: [round(float(c), 3) for c in v] for k, v in mean.items()}, "lr": {k: round(v, 3) for k, v in lr.items()}, + "spars": {k: {kk: round(vv, 3) for kk, vv in v.items()} for k, v in spars.items()}} + (HERE / "stag_arrays.json").write_text(json.dumps(rec, indent=1), encoding="utf-8") + for k, v in rec["spars"].items(): + print(f"SPAR {k:8s} {v['length']:.2f} m rising {v['rise']:.0f} deg") + for k, v in rec["points"].items(): + print(f" {k:16s} {v} lr {rec['lr'][k]}") + return rec + + +if __name__ == "__main__": + arrays() if sys.argv[1:] == ["arrays"] else main() diff --git a/surfaces/blender/experiments/mechs/stag_sheets.py b/surfaces/blender/experiments/mechs/stag_sheets.py index 0b6156d..7086967 100644 --- a/surfaces/blender/experiments/mechs/stag_sheets.py +++ b/surfaces/blender/experiments/mechs/stag_sheets.py @@ -9,8 +9,11 @@ numpy; brokkr_reference.core for the flow score. stag_character.png the character: the concept's arrays beside ours at the hero camera, whole and alone stag_sensor_arrays.png the SENSOR ARRAY DETAIL inset beside our left array at the inset's solved camera stag_components.png the turns, the free cages over their shells, the feet and arms cropped from the turns - stag_vs_pass1.png pass 1 (PASS1, default F:/aeth-wt/fable-stag/out/stag) beside pass 2 and the concept: - hero, rear three-quarter, the arrays alone, the rear elevation + stag_torso.png the hero's torso: the concept's crop beside ours at the posed hero camera + stag_vs_passes.png passes 1 and 2 (PASS1, PASS2: their out/stag) beside pass 3 and the concept: hero, + rear three-quarter, the arrays alone, the rear elevation +The hero renders are the posed build's (STAG_POSE=hero: stag_points_hero.json, stag_skeleton_hero.json); the rest +are the stance build's. """ import importlib.util import json @@ -102,20 +105,26 @@ def text_panel(lines, w, h): return im +def built_points(tag): + suffix = "_hero" if tag == "hero" else "" + built = json.loads((R / f"stag_skeleton{suffix}.json").read_text(encoding="utf-8"))["built"] + built.update(json.loads((R / f"stag_points{suffix}.json").read_text(encoding="utf-8"))) + if tag == "hero": # the posed points the build does not write (n37, soles' middles) from the solve's own + built.update({k: v for k, v in CAMS["hero"]["solved"]["joints"].items() if k not in built}) + return built + + def camera_sheet(): - built = json.loads((R / "stag_skeleton.json").read_text(encoding="utf-8"))["built"] - built.update(json.loads((R / "stag_points.json").read_text(encoding="utf-8"))) rows, lines = [], [] for tag in ("hero", "rear3q", "rear", "side"): + built = built_points(tag) cam = CAMS[tag] box = cam["box"] z = 700 / (box[3] - box[1]) im = fit(concept(box), 700).copy() d = ImageDraw.Draw(im) marks = dict(C["skeleton"]["views"][tag]["joints"]) - marks.update(C["marks"].get(tag, {})) - if tag == "hero": - marks.update(C["housings"]["hero"]) + marks.update({k: v for k, v in C["marks"].get(tag, {}).items() if not k.startswith("_")}) names = [k for k in marks if k in built] proj = core.project(cam, [built[k] for k in names]) res = [] @@ -130,9 +139,10 @@ def camera_sheet(): rms = float(np.sqrt(np.mean(np.square(res)))) if res else 0.0 lines.append(f"{tag}: model {cam['model']}, lens {cam['lens']:.0f} mm, solve rms {cam['rms']:.1f} px, built joints rms {rms:.1f} px ({len(res)})") rows.append(label(im, f"{tag}: rms {rms:.1f} px")) - hb = CAMS.get("hero_body") - if hb: - lines.append(f"hero on the body's marks alone (joints, brow, soles): lens {hb['lens']:.0f} mm, rms {hb['rms']:.1f} px") + h = CAMS["hero"] + lines.append(f"hero solved with the pose (stag_hero.py): {', '.join(f'{k} {v:.1f}' for k, v in h['solved']['pose'].items())}") + lines.append(f"hero eye {h['C'][2]:.2f} m, {h['distance']:.1f} m off, azimuth {h['azimuth']:.0f} (held; the marks leave it open), horizon v {h['horizon']:.0f} (marked {C['marks']['hero_horizon']}); " + f"the stance unposed: {h['solved']['stance_rms']:.1f} px") sheet = stack([row(rows, 700), text_panel(lines, 1400, 130)]) sheet.save(CMP / "stag_camera.png") return lines @@ -182,6 +192,10 @@ def vs_sheet(): if ours is None: continue rows.append(row([label(concept(box).resize(ours.size, Image.LANCZOS), f"concept, {title}"), label(ours, f"ours at the solved camera ({CAMS[tag]['model']}, {CAMS[tag]['lens']:.0f} mm)")], 1000)) + if tag == "hero": + wide = render(f"{STAGE}_hero_wide") + if wide is not None: + rows[-1] = row([rows[-1], label(wide, "ours, the hero camera framed wider")], 1000) small = [render(f"{STAGE}_{t}") for t in ("rear", "side")] small = [label(i, t) for i, t in zip(small, ("rear elevation", "left elevation")) if i is not None] orth = [label(concept(CAMS[t]["box"]).resize((300, round(300 * (CAMS[t]["box"][3] - CAMS[t]["box"][1]) / (CAMS[t]["box"][2] - CAMS[t]["box"][0]))), Image.LANCZOS), t) for t in ("rear", "side")] @@ -230,11 +244,19 @@ def components_sheet(): return lines -def pass1_sheet(): - p1 = Path(os.environ.get("PASS1", "F:/aeth-wt/fable-stag/out/stag")) +def torso_sheet(): + box = [120, 90, 400, 330] + ours = render(f"{STAGE}_hero_torso") + if ours is None: + return + row([label(concept(box), "concept, hero: the torso"), label(ours, "ours at the posed hero camera")], 700).save(CMP / "stag_torso.png") - def old(stem): - q = p1 / f"{stem}.png" + +def passes_sheet(): + olds = [("pass 1", Path(os.environ.get("PASS1", "F:/aeth-wt/fable-stag/out/stag"))), ("pass 2", Path(os.environ.get("PASS2", "F:/aeth-wt/fable-stag-2/out/stag")))] + + def old(root, stem): + q = root / f"{stem}.png" if not q.exists(): return None im = Image.open(q) @@ -245,17 +267,19 @@ def pass1_sheet(): return im.convert("RGB") rows = [] for stem, box, title, h in (("hero", CAMS["hero"]["box"], "hero", 900), ("rear3q", CAMS["rear3q"]["box"], "rear three-quarter", 900), - ("arrays_hero", [0, 0, 470, 180], "the arrays alone, hero camera", 380), ("rear", CAMS["rear"]["box"], "rear elevation", 700)): - a, b = old(f"full_{stem}"), render(f"{STAGE}_{stem}") + ("arrays_hero", [0, 0, 470, 180], "the arrays alone, hero camera", 300), ("rear", CAMS["rear"]["box"], "rear elevation", 700)): ims = [label(concept(box), f"concept, {title}")] - ims += [label(a, "pass 1")] if a is not None else [] - ims += [label(b, "pass 2")] if b is not None else [] + for name, root in olds: + a = old(root, f"full_{stem}") + ims += [label(a, name)] if a is not None else [] + b = render(f"{STAGE}_{stem}") + ims += [label(b, "pass 3")] if b is not None else [] rows.append(row(ims, h)) - stack(rows).save(CMP / "stag_vs_pass1.png") + stack(rows).save(CMP / "stag_vs_passes.png") if __name__ == "__main__": - for fn in (camera_sheet, flow_sheet, vs_sheet, character_sheet, sensor_sheet, components_sheet, pass1_sheet): + for fn in (camera_sheet, flow_sheet, vs_sheet, character_sheet, sensor_sheet, components_sheet, torso_sheet, passes_sheet): try: got = fn() for line in got or []: