From fa58d1f902e3f2321cce4947aeaba20c5a3e011b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 22:06:15 +0100 Subject: [PATCH] Seraph, second round on the mass-first foundation: the breast re-split into fewer, bigger, stepped plates with chamfered walls, the centre plate's and the pauldrons' edges cut along the operator's lines by the hero camera's sight lines (massing.Curtain: her pauldron line on 1.00 over the pauldron, from 0.38); a faceted helmet with a brow and a visible visor in a well opened to the break; pauldrons as boxed, lapped shells with a shield; plated forearm housings, the library's fist, a class M battery without its cowl; a built underside; longer cooling fin banks; the stance 0.4 m forward; surface.Skin reads massing plates and 34 detail features land; elbow rams fit (the elbow's range was wrong) and a ram that fails is not drawn; pauldron and side-view sheets Co-Authored-By: Claude Fable 5.2 --- .../blender/experiments/mechs/jointlib.py | 6 +- surfaces/blender/experiments/mechs/joints.py | 4 +- surfaces/blender/experiments/mechs/massing.py | 111 +++++++- surfaces/blender/experiments/mechs/mechlib.py | 4 +- surfaces/blender/experiments/mechs/seraph.py | 101 ++++++-- .../blender/experiments/mechs/seraph_body.py | 236 +++++++++++++++--- .../blender/experiments/mechs/seraph_form.py | 182 ++++++++++---- .../experiments/mechs/seraph_sheets.py | 21 ++ surfaces/blender/experiments/mechs/surface.py | 42 +++- .../experiments/mechs/weapons_missile.py | 28 ++- 10 files changed, 580 insertions(+), 155 deletions(-) diff --git a/surfaces/blender/experiments/mechs/jointlib.py b/surfaces/blender/experiments/mechs/jointlib.py index e661c74..99056c1 100644 --- a/surfaces/blender/experiments/mechs/jointlib.py +++ b/surfaces/blender/experiments/mechs/jointlib.py @@ -239,7 +239,8 @@ class Rig: may be a list of candidates, and then ramfit.search picks the pair). Draws the ram at the child's angle, once or as twins `twin` apart along the axis (`shift` moves the lot along it), a clevis at each end running toward_a / toward_b into its host, and cuts a recess from the ram's sweep where pocket_a / pocket_b name - the side it is open on. Returns the Fit; a ram that does not fit is still drawn, and reported.""" + the side it is open on. Returns the Fit; a ram that does not fit (it, or its twin) is reported and NOT drawn: + no ram, no clevis, no pocket.""" parent = child.parent ram = ramfit.Ram(bore, tail=tail, min_arm=min_arm) lo, hi = self.lo if lo is None else lo, self.hi if hi is None else hi @@ -264,6 +265,9 @@ class Rig: ok, text = False, text + "; TWIN: " + other.report() self.fits[name] = {"fit": fit, "ok": ok, "text": text, "twin": twin, "lo": lo, "hi": hi} print(f"RAM {self.name}.{name}: {text}", flush=True) + if not ok: # a ram that does not fit is not drawn: a drawn one reads as a working mechanism + print(f"RAM {self.name}.{name}: NOT DRAWN, no seat pair fits", flush=True) + return fit for dx in offsets: move = ax * (dx - offsets[0]) _draw_ram(parent, fit, child.angle, move, boot_, mat) diff --git a/surfaces/blender/experiments/mechs/joints.py b/surfaces/blender/experiments/mechs/joints.py index e260262..ef53bda 100644 --- a/surfaces/blender/experiments/mechs/joints.py +++ b/surfaces/blender/experiments/mechs/joints.py @@ -97,7 +97,7 @@ def yoke_ankle(rig, angle, r=0.22, span=0.5, arm=0.06, bore=0.04): @mech("yoke and clevis", "seraph_elbow", 0.0, 62.0, rom=(90, 4), concept=(8.0, 20.0, 4.0), spacing=2.2, sheet="SERAPH") -def fork_elbow(rig, angle, r=0.2, twin=0.34, bore=0.05, collar=(0.86, 0.74, 0.95)): +def fork_elbow(rig, angle, r=0.2, twin=0.34, bore=0.05, collar=(0.86, 0.74, 0.95), collar_mat="khaki"): """SERAPH, the left elbow of the hero view: the forearm's armor is a deep collar; the upper arm's ribbed spine runs down into it to the elbow pin, flanked by twin rams whose rod eyes are seated inside the collar. The collar's recess is cut from the rams' sweep, so they clear it through the whole range.""" @@ -108,7 +108,7 @@ def fork_elbow(rig, angle, r=0.2, twin=0.34, bore=0.05, collar=(0.86, 0.74, 0.95 arm.box("khaki", (0, -0.03, 1.02), (0.74, 0.62, 0.5), 0.08) arm.cyl("machine", (0, 0, 0), r, 0.26) w, d, h = collar - fore.box("khaki", (0, 0.0, -0.08 - h / 2), (w, d, h), 0.09) + fore.box(collar_mat, (0, 0.0, -0.08 - h / 2), (w, d, h), 0.09) # collar_mat: a dark core where the mech plates the forearm itself (SERAPH: seraph_body.forearm) for s in (-1, 1): fore.box("gunmetal", (s * 0.19, 0, -0.06), (0.1, 0.3, 0.34), tag="trim") fore.cap("machine", (s * 0.24, 0, 0), 0.14, X * s, bolts=6, tag="trim") diff --git a/surfaces/blender/experiments/mechs/massing.py b/surfaces/blender/experiments/mechs/massing.py index cb1b583..dd436df 100644 --- a/surfaces/blender/experiments/mechs/massing.py +++ b/surfaces/blender/experiments/mechs/massing.py @@ -10,8 +10,11 @@ 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. 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 inside the half-spaces `keep` [(normal, d): kept where - n.p <= d], lifted `proud`, walled `wall` inward, cut by `cutters`, bevelled + plate(name, mass, keep, ...) the mass's surface lifted `proud`, kept inside the half-spaces `keep` + [(normal, d): kept where n.p <= d] and on the named side of each traced + line (`curtains`), walled `wall` inward, cut by `cutters`, chamfered + 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 """ import math @@ -98,30 +101,114 @@ def carve(obj, cutters, flat=True): return obj -def plate(name, mass, keep, proud=0.06, wall=0.08, mat="khaki", cutters=(), bevel=0.018, flat=True): - """The mass's surface inside `keep`, as a plate of its own. `mass` is a solid() as built (before any carve: - pass the uncarved mesh's object, or a copy). Returns the object, or None where nothing of the surface is kept.""" +class Curtain: + """A traced line (the sheet's pixels) as a cut through a mass: the surface a solved camera's sight lines sweep + along the line. A plate cut by it has an edge that the camera draws exactly on the line, whatever the mass's + shape there. `planes` are the sight planes of the line's segments in the mass's frame (bisected, nothing + cleared); side(points) is each point's signed distance from the line in pixels as the camera draws it (positive + on the left of the line's travel on the sheet, y down). `shift` moves the line sideways first, in pixels: a + neighbour's gap. The line is run on straight past its ends (`extend`, a share of its length), so it parts the + whole mass.""" + + def __init__(self, cam, line, frame, shift=0.0, n=14, extend=1.5): + import camsolve + import numpy as np + self.cam, self.frame = cam, Matrix(frame) + p = np.asarray(line, float) + d = np.concatenate([[0], np.cumsum(np.linalg.norm(np.diff(p, axis=0), axis=1))]) + t = np.linspace(0, d[-1], n) + p = np.stack([np.interp(t, d, p[:, k]) for k in range(2)], 1) + if shift: + tan = np.gradient(p, axis=0) + tan /= np.linalg.norm(tan, axis=1)[:, None] + p = p + shift * np.stack([tan[:, 1], -tan[:, 0]], 1) + head, tail = p[0] - p[1], p[-1] - p[-2] + self.line = np.vstack([p[0] + head / np.linalg.norm(head) * extend * d[-1], p, p[-1] + tail / np.linalg.norm(tail) * extend * d[-1]]) + inv = self.frame.inverted() + eye = inv @ Vector(cam["C"]) + rays = [] + for q in self.line: + o, dr = camsolve.ray(cam, q) + rays.append((inv.to_3x3() @ Vector(dr)).normalized()) + self.eye = eye + self.planes = [(a.cross(b).normalized(), eye) for a, b in zip(rays, rays[1:])] + + def side(self, points): + import camsolve + import numpy as np + world = np.array([list(self.frame @ Vector(p)) for p in points]) + q = camsolve.project(self.cam, world) + a, d = self.line[:-1], self.line[1:] - self.line[:-1] + length = np.maximum((d * d).sum(1), 1e-12) + t = np.clip(((q[:, None] - a) * d).sum(2) / length, 0, 1) + off = q[:, None] - (a + t[:, :, None] * d) + k = np.linalg.norm(off, axis=2).argmin(1) + i = np.arange(len(q)) + return (d[k, 0] * off[i, k, 1] - d[k, 1] * off[i, k, 0]) / np.sqrt(length[k]) + + def toward(self, pixel): + """The sign of the side a pixel of the sheet is on.""" + import numpy as np + q = np.asarray(pixel, float) + a, d = self.line[:-1], self.line[1:] - self.line[:-1] + t = np.clip(((q - a) * d).sum(1) / np.maximum((d * d).sum(1), 1e-12), 0, 1) + off = q - (a + t[:, None] * d) + k = np.linalg.norm(off, axis=1).argmin() + return 1.0 if d[k, 0] * off[k, 1] - d[k, 1] * off[k, 0] > 0 else -1.0 + + +def plate(name, mass, keep, proud=0.06, wall=0.08, mat="khaki", cutters=(), bevel=0.018, flat=True, curtains=()): + """The mass's surface inside `keep`, as a plate of its own: the surface is lifted `proud` first and cut after, + so a cut stands where it was asked for on the lifted face. `mass` is a solid() as built (before any carve: + pass the uncarved mesh's object, or a copy). `curtains` are [(Curtain, pixel)]: the plate is what lies on the + pixel's side of each traced line as the camera sees it. Its wall is a Kit Solidify and its chamfer a Kit Bevel + (`bevel` wide: 0.04 and up reads as a chamfered edge at figure scale), the names brokkr_kitbash.cut and + surface.Skin look for. Returns the object, or None where nothing of the surface is kept.""" bm = bmesh.new() bm.from_mesh(mass.data) + bm.normal_update() + for v in bm.verts: + v.co += v.normal * proud for n, d in keep: n = Vector(n) bmesh.ops.bisect_plane(bm, geom=bm.verts[:] + bm.edges[:] + bm.faces[:], dist=1e-5, plane_co=n * (d / n.length_squared), plane_no=n, clear_outer=True) + for curtain, pixel in curtains: + if not bm.faces: + break + for n, co in curtain.planes: + bmesh.ops.bisect_plane(bm, geom=bm.verts[:] + bm.edges[:] + bm.faces[:], dist=1e-5, plane_co=co, plane_no=n) + faces = bm.faces[:] + side = curtain.side([f.calc_center_median() for f in faces]) * curtain.toward(pixel) + bmesh.ops.delete(bm, geom=[f for f, s in zip(faces, side) if s < 0], context="FACES") if not bm.faces: bm.free() print(f"PLATE {name}: nothing kept", flush=True) return None - bm.normal_update() - for v in bm.verts: - v.co += v.normal * proud + bmesh.ops.dissolve_limit(bm, angle_limit=math.radians(0.5), verts=bm.verts[:], edges=bm.edges[:]) obj = _object(name, bm, mat, mass.matrix_world) - mod = obj.modifiers.new("Wall", "SOLIDIFY") + mod = obj.modifiers.new("Kit Solidify", "SOLIDIFY") mod.thickness, mod.offset, mod.use_even_offset = wall, -1.0, True - for c in cutters: + world = obj.matrix_world + pts = [world @ v.co for v in obj.data.vertices] + lo, hi = Vector([min(q[k] for q in pts) - wall for k in range(3)]), Vector([max(q[k] for q in pts) + wall for k in range(3)]) + for c in cutters: # only the cutters that reach the plate: an exact Boolean is slow, and can lose a plate it does not touch + box = [c.matrix_world @ Vector(q) for q in c.bound_box] + if any(max(q[k] for q in box) < lo[k] or min(q[k] for q in box) > hi[k] for k in range(3)): + continue mod = obj.modifiers.new("Cut", "BOOLEAN") mod.operation, mod.solver, mod.object = "DIFFERENCE", "EXACT", c + M.update() + if not len(obj.evaluated_get(bpy.context.evaluated_depsgraph_get()).data.polygons): + mod.solver = "FLOAT" if hasattr(mod, "solver") and "FLOAT" in {e.identifier for e in mod.bl_rna.properties["solver"].enum_items} else "FAST" + M.update() + if not len(obj.evaluated_get(bpy.context.evaluated_depsgraph_get()).data.polygons): + obj.modifiers.remove(mod) + print(f"PLATE {name}: the cut by {c.name} leaves nothing by either solver; left uncut", flush=True) if bevel: - mod = obj.modifiers.new("Bevel", "BEVEL") - mod.width, mod.segments, mod.limit_method, mod.angle_limit = bevel, 1, "ANGLE", math.radians(40) + mod = obj.modifiers.new("Kit Bevel", "BEVEL") + mod.width, mod.segments, mod.limit_method, mod.angle_limit = min(bevel, 0.45 * wall), 1, "ANGLE", math.radians(40) for p in obj.data.polygons: p.use_smooth = not flat + 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 diff --git a/surfaces/blender/experiments/mechs/mechlib.py b/surfaces/blender/experiments/mechs/mechlib.py index 0f9f6d1..895f0d1 100644 --- a/surfaces/blender/experiments/mechs/mechlib.py +++ b/surfaces/blender/experiments/mechs/mechlib.py @@ -2065,7 +2065,7 @@ def built_edges(solved, keep=None, angle=18.0): return out -def preview(rig, cam, solved, path, width=1050): +def preview(rig, cam, solved, path, width=1050, box=None): """A solved view (camsolve) by Workbench on a transparent film, the stage hidden: seconds, not minutes. The picture's alpha is the build's silhouette in that view; its pixels are the sheet's (solved_view). For fitting rounds between full renders (field_views under MECH_PREVIEW).""" @@ -2080,7 +2080,7 @@ def preview(rig, cam, solved, path, width=1050): shading.cavity_type, shading.show_object_outline = "BOTH", False look = scene.view_settings.view_transform, scene.view_settings.look, scene.view_settings.exposure scene.view_settings.look, scene.view_settings.view_transform, scene.view_settings.exposure = "None", "Standard", 1.2 - solved_view(rig, cam, solved, width) + solved_view(rig, cam, solved, width, box) scene.render.filepath = str(path) scene.render.image_settings.file_format = "PNG" bpy.ops.render.render(write_still=True) diff --git a/surfaces/blender/experiments/mechs/seraph.py b/surfaces/blender/experiments/mechs/seraph.py index 99d77d6..d6be0e9 100644 --- a/surfaces/blender/experiments/mechs/seraph.py +++ b/surfaces/blender/experiments/mechs/seraph.py @@ -14,6 +14,15 @@ camera sees from 30 degrees below. It comes to a torso turned 0.3 degrees and pi 2.25 m before the waist's axis and no higher than the waist ring: a deep, hanging prow. Rounds 8 to 10 built a torso turned 12 degrees the other way with a shallow chest, which put the chest lines right and the shoulders wrong. +Second round on that foundation (seraph_form.py holds the numbers): the breast re-split as the concept splits it, +its centre plate and the pauldrons' outer plates cut along the operator's own lines by the hero camera's sight lines +(massing.Curtain), so those edges are drawn on her lines exactly; a faceted helmet with a brow over a visor the hero +camera sees, in a well opened to the break; plated forearm housings, the joints library's fist, a battery of class M +without its cowl; an underside of blocks, lames and conduits; a detail pass by surface.py on the plates; the feet +0.4 m further forward (STANCE), which brings the toes to within 0.07 m of the chest's lip. Elbow rams fit: the elbow +had been given a range that bent it 62 degrees backward. A ram that does not fit is no longer drawn (jointlib). +The right pauldron is posed with the raised arm (seraph_form.PAULDRON_R). + SERAPH_STAGE stops the upper body early: volume (the solid masses alone), recess (the well and the helmet), plates, full (default). MECH_QUICK renders by Workbench. Writes under MECH_OUT/seraph/: _hero.png, _rear.png, _sil_hero.png, _sil_rear.png (the kept cameras, the sheet's own pixels), _chest.png and @@ -27,6 +36,7 @@ import skeleton import seraph_parts as SP import seraph_form as SF import seraph_body as SB +import massing as MS import hardpoint as H import weapons_ballistic, weapons_energy, weapons_missile, weapons_sensor from mathutils import Matrix, Vector @@ -53,7 +63,9 @@ CFG = dict(pelvis=dict(span=1.4, ring_r=0.5, top_r=0.55, depth=1.1, height=1.5), chassis=dict(width=3.0, depth=1.1, height=3.0, top_r=0.24, side_r=0.45, shoulder=0.66), # lay() sizes a kit chassis and arms from the skeleton; this build makes neither arm=dict(pin_r=0.11, yoke=(0.6, 0.6), twist_r=0.3, upper=1.5, elbow=(0.5, 0.5), fore=1.0), aims={"L": ((0, 1, 0.05), None, (-0.05, 0.4, -1)), "R": ((0, 1, 0.25), None, (0.0, 0.75, -1.0))}, guns={}) -M.lay(SK, CFG, hull_top=8.35, depth={"L": (0.55, -0.1), "R": (0.15, -0.25)}, elbow_y={"L": 0.1, "R": 0.75}, cant=True) +# the stance in depth, {side: (knee, ankle)} before the hip axis. SERAPH_STANCE=old stands it as rounds 8 to 10 did. +STANCE = {"L": (0.55, -0.1), "R": (0.15, -0.25)} if os.environ.get("SERAPH_STANCE") == "old" else {"L": (0.75, 0.3), "R": (0.35, 0.15)} +M.lay(SK, CFG, hull_top=8.35, depth=STANCE, elbow_y={"L": 0.1, "R": 0.75}, cant=True) CFG["pelvis"]["height"] += 0.23 # the saddle stands its waist ring 0.115 m under half its height CFG["foot"] = (CFG["foot"][0], CFG["foot"][1], CFG["foot"][2] - CROSS) FOOT, LINKS = CFG["foot"], CFG["links"] @@ -116,7 +128,6 @@ mass = SB.upper_mass(FR, solid_mat) helm = SB.helmet_mass(FR, solid_mat) pauldrons = {side: SB.pauldron_mass(FR, side, P) for side in (-1, 1)} if AT >= 1: - import massing as MS recess = SB.head_recess(FR) visor_cut, face = SB.visor(FR) skin = mass.copy() # the uncarved surface, which the plates are taken from @@ -128,35 +139,58 @@ if AT >= 2: SB.torso_plates(skin, [recess, bores[-1], bores[1]]) helm_skin = SB.helmet_mass(FR, SB.CORE) helm_skin.name = "Helmet.skin" - SB.helmet_plates(helm_skin) - for o in (helm_skin,): - bpy.data.objects.remove(o, do_unlink=True) + SB.helmet_plates(helm_skin, [visor_cut]) + bpy.data.objects.remove(helm_skin, do_unlink=True) + n, dd = SF.PAULDRON["mouth"] for side, pm in pauldrons.items(): SB.pauldron_plates(pm, side, [bores[side]]) - bpy.data.objects.remove(pm, do_unlink=True) + # what is left of the mass is the shell's dark core, 0.15 m under the plates; the right one's is cut back + # behind the battery's face + for v in pm.data.vertices: + v.co -= v.normal * 0.15 + M.assign(pm, SB.CORE) + cuts = [bores[side]] + if side > 0: + nl = Vector((-n[0], n[1], n[2])).normalized() + cuts.append(MS.slab("Mouth.cut", (0, 0, 0), (4.0, 4.0, 2.0), pm.matrix_world @ M.frame_at(nl * (dd / Vector(n).length - 0.5 + 1.0), nl))) + MS.carve(pm, cuts) + pm.name = pm.name.replace(".mass", ".core") if AT >= 3: SB.abdomen(FR) - SB.cooling(FR, top=SK["height"] - SF.WAIST[2] - 0.17) # pitched with the torso, the caps' rear edge is the figure's top + SB.underside(FR) + SB.cooling(FR, top=SK["height"] - SF.WAIST[2] - 0.17, **SF.COOLING) # pitched with the torso, the caps' rear edge is the figure's top for side in (-1, 1): SB.shoulder_bearing(FR, side) - objs, fore = SB.arm(FR, side) - if side > 0: - mounted("Cannon", weapons_ballistic.seraph_cannon, fore @ T((0, 0.75, 0.0)), size="M") - else: - mounted("Emitter", weapons_energy.seraph_emitter, fore @ T((0, 0.75, 0.0)), size="M", length=1.9) + objs, fore, K = SB.arm(FR, side) + _, wrist, ob = SB.forearm(fore, side, K) + if side > 0: # the cannon slung under the housing, the fist on the housing's end over its breech + mounted("Cannon", weapons_ballistic.seraph_cannon, fore @ T((0, 0.75, -(0.37 * K + 0.42))), size="M", vambrace=False) + SB.fist(fore, side, (0, wrist, 0.05)) + else: # the emitter under the housing, the fist inboard of it + mounted("Emitter", weapons_energy.seraph_emitter, fore @ T((ob * 0.1, 0.75, -0.3 * K)), size="M", length=1.9) + SB.fist(fore, side, (-ob * (0.43 * K + 0.3), wrist - 0.3, 0.1)) mounted(f"Periscope{'L' if side < 0 else 'R'}", weapons_sensor.seraph_periscope, FR @ T((side * 1.37, -0.45, 2.12)), size="S", height=0.9) - # the battery in the right pauldron's open mouth, its face on the arch's plane (the mirror of the left's) + # the battery fills the right pauldron's open mouth: class M without its own cowl (the pauldron is its hood), + # its face just behind the arch's plane pf = FR @ SB.mat4(SF.pauldron_frame(1)) - n, dd = SF.PAULDRON["arch"] n = Vector(n).normalized() y = (pf.to_3x3() @ n).normalized() z = (Vector((0, 0, 1)) - y * y.z).normalized() at = Matrix((y.cross(z), y, z)).transposed().to_4x4() - at.translation = pf @ (n * (dd + 0.2) + Vector((0, 0, -0.3))) - mounted("Battery", weapons_missile.seraph_battery, at @ Matrix.Scale(1.3, 4), size="S", cols=2, rows=3) # class S at 1.3: the mouth is 1.5 m across, between the classes + at.translation = pf @ (n * dd + Vector((0, 0, -0.3))) + mounted("Battery", weapons_missile.seraph_battery, at, size="M", cols=2, rows=3, cowl=False, depth=1.0, door=78.0) + if not os.environ.get("SERAPH_NO_DETAIL"): + DETAIL = SB.detail() if AT >= 1: bpy.data.objects.remove(skin, do_unlink=True) M.update() +if os.environ.get("SERAPH_WHERE"): # where objects stand, evaluated: SERAPH_WHERE=Helmet,Face + dgw = bpy.context.evaluated_depsgraph_get() + for o in bpy.context.scene.objects: + if o.type == "MESH" and o.name.startswith(tuple(os.environ["SERAPH_WHERE"].split(","))): + me = o.evaluated_get(dgw).to_mesh() + pts = [o.matrix_world @ v.co for v in me.vertices] + print("WHERE", o.name, len(me.polygons), "faces", " ".join(f"{min(q[k] for q in pts):.2f}..{max(q[k] for q in pts):.2f}" for k in range(3)) if pts else "EMPTY", "hidden" if o.hide_render else "", flush=True) lo, hi = M.bounds() print("HEIGHT", round(hi.z - lo.z, 2), "LOW", round(lo.z, 2), "WIDTH", round(hi.x - lo.x, 2), "stage", STAGE, "build s", round(time.time() - t0, 1), flush=True) M.tops() @@ -180,8 +214,28 @@ for tag, cam in cams.items(): rig, cam, centre, radius = M.stage_field(8 if QUICK else int(os.environ.get("MECH_SAMPLES", 48))) scene = bpy.context.scene W = 1050 if QUICK else 1600 -CHEST = [200, 0, 520, 300] +CHEST, PAULDRON, PAULDRON_REAR = [200, 0, 520, 300], [440, 20, 700, 330], [700, 15, 810, 150] upper = lambda name: name.startswith(("Torso.", "Helmet.", "Face.")) +# the balance in the side view: every mesh taken solid and of one density, its centre of volume against the feet +import bmesh +dg, tot, mom = bpy.context.evaluated_depsgraph_get(), 0.0, Vector() +feet = [c for o in scene.objects if o.type == "MESH" and o.name.startswith("Foot") for c in (o.matrix_world @ Vector(q) for q in o.bound_box)] +for o in scene.objects: + if o.type == "MESH" and not o.get("stage") and not o.hide_render: + bm = bmesh.new() + bm.from_object(o, dg) + bm.transform(o.matrix_world) + v = abs(bm.calc_volume(signed=True)) + if v > 1e-6 and bm.faces: + c = sum((f.calc_center_median() * f.calc_area() for f in bm.faces), Vector()) / sum(f.calc_area() for f in bm.faces) + tot, mom = tot + v, mom + c * v + bm.free() +com = mom / tot +lo_b, hi_b = M.bounds() +BALANCE = {"com": [round(c, 2) for c in com], "feet_y": [round(min(c.y for c in feet), 2), round(max(c.y for c in feet), 2)], "ankles_y": round(sum(leg["links"][1].matrix_world.translation.y for leg in legs.values()) / 2, 2) if False else None, + "foremost_y": round(hi_b.y, 2), "rearmost_y": round(lo_b.y, 2), "chest_lip_y": round((FR @ Vector((0, 2.25, 0.05))).y, 2)} +print("BALANCE", json.dumps(BALANCE), flush=True) +(OUT / "seraph_balance.json").write_text(json.dumps(BALANCE), encoding="utf-8") for tag in ("hero", "rear"): M.silhouette(rig, cam, radius, 0, 0, OUT / f"{STAGE}_sil_{tag}.png", (700 if tag == "hero" else 648, 0), solved=cams[tag]) if QUICK: @@ -189,10 +243,17 @@ for tag in ("hero", "rear"): else: M.shot(rig, cam, radius, 0, 0, OUT / f"{STAGE}_{tag}.png", (W, W), solved=cams[tag]) if AT >= 2 and not os.environ.get("SERAPH_NO_EDGES"): - (OUT / f"{STAGE}_edges_hero.json").write_text(json.dumps(M.built_edges(cams["hero"])), encoding="utf-8") + armour = lambda name: ".fit." not in name and ".mark." not in name and not name.endswith((".machine", ".steel", ".rubber", ".seat", ".eye", ".ram", ".soft")) and not name.startswith(("Conduit", "ChestHose", "KneeHose", "CoolingPipe")) # noqa: E731 + (OUT / f"{STAGE}_edges_hero.json").write_text(json.dumps(M.built_edges(cams["hero"], keep=armour)), encoding="utf-8") print("edges s", round(time.time() - t0, 1), flush=True) -if not QUICK: - M.shot(rig, cam, radius, 0, 0, OUT / f"{STAGE}_chest.png", (1280, 1200), solved=cams["hero"], box=CHEST) +crops = (("chest", "hero", CHEST, 1280), ("pauldron", "hero", PAULDRON, 1040), ("pauldron_rear", "rear", PAULDRON_REAR, 880), ("battery", "hero", [110, 40, 270, 220], 800)) +if QUICK: + for name, tag, box, w in crops: + M.preview(rig, cam, cams[tag], OUT / f"{STAGE}_{name}.png", w, box) + M.shot(rig, cam, radius, 90, 6.0, OUT / f"{STAGE}_turn_090.png", (700, 700), margin=0.8, lens=85.0) +else: + for name, tag, box, w in crops: + M.shot(rig, cam, radius, 0, 0, OUT / f"{STAGE}_{name}.png", (w, w), solved=cams[tag], box=box) meshes = [o for o in scene.objects if o.type in ("MESH", "CURVE", "FONT") and not o.get("stage") and not o.hide_render] for o in meshes: o.hide_render = not upper(o.name) diff --git a/surfaces/blender/experiments/mechs/seraph_body.py b/surfaces/blender/experiments/mechs/seraph_body.py index 54e1ff4..a8f36ad 100644 --- a/surfaces/blender/experiments/mechs/seraph_body.py +++ b/surfaces/blender/experiments/mechs/seraph_body.py @@ -7,7 +7,8 @@ Order of the build, which seraph.py follows and can stop after any step of (SERA rear silhouettes recess head_recess: the well cut into the mass's top, the helmet set in it plates torso_plates, helmet_plates, pauldron_plates: the masses' surfaces split along the operator's lines - full shoulder_bearing, upper_arm, arm (joints.fork_elbow), the forearm weapons, cooling, abdomen, periscopes + full shoulder_bearing, arm (joints.fork_elbow), forearm (the plated housing), fist (hands.fist), the forearm + weapons, cooling, abdomen, underside, periscopes, and detail (surface.py on the plates) """ import math @@ -20,12 +21,37 @@ import seraph_form as SF T = Matrix.Translation CORE = "gunmetal" +COLLAR = (0.76, 0.64, 0.95) # the elbow collar under the forearm's plates, at the elbow's scale 1 def mat4(m): return Matrix([list(r) for r in m]) +_CURTAINS = {} + + +def curtains(lines, world): + """[(massing.Curtain, pixel)] for a plate's `lines` ([(traced line's tag, shift in pixels, reference pixel's + tag)], seraph_form) in a mass whose frame to the world is `world`: the hero camera's sight curtains.""" + out = [] + for tag, shift, ref in lines: + key = (tag, shift, tuple(round(v, 6) for row in world for v in row)) + if key not in _CURTAINS: + _CURTAINS[key] = MS.Curtain(SF.cameras()["hero"], SF.traced(tag), world, shift) + out.append((_CURTAINS[key], SF.PX[ref])) + return out + + +def _plates(prefix, mass, specs, cutters=(), flip=False): + out = [] + for name, keep, proud, wall, chamfer, lines in specs: + obj = MS.plate(f"{prefix}.{name}", mass, SF.mirrored(keep) if flip else keep, proud, wall, cutters=cutters, bevel=chamfer, curtains=curtains(lines, mass.matrix_world)) + if obj: + out.append(obj) + return out + + def upper_mass(frame, mat="khaki"): """Hero and rear views: chest, shoulders and cowl as ONE closed, rounded mass (seraph_form.TORSO). The sternum is its foremost point, low; the face above it recedes to the cowl. Returns the mass (uncarved).""" @@ -33,13 +59,18 @@ def upper_mass(frame, mat="khaki"): def helmet_mass(frame, mat="khaki"): - """COCKPIT / SENSOR CLUSTER inset: the helmet as a low dome (seraph_form.HELM), in the helmet's frame.""" - return MS.solid("Helmet.mass", *SF.loft(SF.HELM, crown=0.2), frame @ T(SF.HELMET["at"]), mat, levels=1) + """COCKPIT / SENSOR CLUSTER inset: the helmet as a faceted shell of eight sides, wider than it is tall + (seraph_form.HELM), in the helmet's frame. Not subdivided: its facets are the concept's.""" + return MS.solid("Helmet.mass", *SF.loft(SF.HELM, n=SF.HELM_N, crown=0.2), frame @ T(SF.HELMET["at"]), mat, levels=0) def pauldron_mass(frame, side, mat="khaki"): - """Hero and rear views: a pauldron as a closed mass (seraph_form.PAULDRON), canted, its crown inboard.""" - return MS.solid(f"Pauldron{'L' if side < 0 else 'R'}.mass", *SF.loft(SF.PAULDRON["rings"]), frame @ mat4(SF.pauldron_frame(side)), mat, levels=1) + """Hero and rear views: a pauldron as a closed mass (seraph_form.PAULDRON), canted, its crown inboard. The right + one is the left's cage mirrored, in a frame that is a rotation (brokkr_kitbash.cut refuses a mirrored object).""" + pts, faces = SF.loft(SF.PAULDRON["rings"]) + if side > 0: + pts, faces = pts * [-1.0, 1.0, 1.0], [tuple(reversed(f)) for f in faces] + return MS.solid(f"Pauldron{'L' if side < 0 else 'R'}.mass", pts, faces, frame @ mat4(SF.pauldron_frame(side, proper=True)), mat, levels=0) def head_recess(frame): @@ -54,20 +85,21 @@ def shoulder_cut(frame, side): def torso_plates(mass, cutters): - """Hero view and the operator's two chest lines: the mass's surface split into plates. The centre plate is - bounded by her lines and stands proudest; the breast blocks stand proud of the inner breasts; the collar is a - raised rim round the well. Each is a shell of its own with a wall (massing.plate).""" - out = [] - for name, keep, proud, wall in SF.torso_plates(): - obj = MS.plate(f"Torso.{name}", mass, keep, proud, wall, cutters=cutters) - if obj: - out.append(obj) - return out + """Hero view and the operator's two chest lines: the mass's surface split as the concept's breast is + (seraph_form.torso_plates): the centre plate, whose edges are her two lines as the hero camera draws them + (massing.Curtain); one big breast plate a side; heavy lower blocks under it; a deep side block and a periscope + yoke lapped over it. Each a shell of its own, at its own depth, with a chamfered wall (massing.plate).""" + return _plates("Torso", mass, SF.torso_plates(), cutters) -def helmet_plates(mass): - """COCKPIT inset: the helmet's crown panels and nape over its dark core; the brow is the crown's front edge.""" - return [o for o in (MS.plate(f"Helmet.{name}", mass, keep, proud, wall, bevel=0.012) for name, keep, proud, wall in SF.helmet_plates()) if o] +def helmet_plates(mass, cutters=()): + """COCKPIT inset: the faceted helmet's crown panels (the centre one between her chest lines run on over the + head), cheeks and nape over its dark core, and the brow: a heavy plate from the crown's front edge out over the + visor slit, its lower edge level.""" + out = _plates("Helmet", mass, SF.helmet_plates(), cutters) + b = M.Build("Helmet.Brow", None, mass.matrix_world) + b["khaki"].hull(SF.BROW, mirror=True) + return out + b.done(bevel=0.03) def visor(frame): @@ -75,23 +107,23 @@ def visor(frame): hf = frame @ T(SF.HELMET["at"]) cut = MS.slab("Visor.cut", SF.VISOR["at"], SF.VISOR["size"], hf) if "amber_eye" not in M.MATS: - M.material("amber_eye", (0.02, 0.01, 0.0), 0.0, 0.3, emission=((1.0, 0.3, 0.04), 3.0)) + M.material("amber_eye", (0.02, 0.01, 0.0), 0.0, 0.3, emission=((1.0, 0.3, 0.04), 1.2)) + z = SF.VISOR["at"][2] b = M.Build("Face", None, hf) - b[CORE].box(T((0, 0.3, -0.13)), (0.8, 0.1, 0.2)) # the dark face behind the slit + b[CORE].box(T((0, 0.36, z)), (0.96, 0.1, 0.3)) # the dark face behind the slit for s in (-1, 1): - b["amber_eye"].box(T((s * 0.2, 0.37, -0.13)) @ Matrix.Rotation(math.radians(-s * 12), 4, "Y"), (0.17, 0.04, 0.035)) - b[CORE].box(T((s * 0.33, 0.4, -0.3)), (0.2, 0.3, 0.26)) - b[CORE].box(T((0, 0.46, -0.3)), (0.3, 0.3, 0.22)) - b[CORE].box(T((0, 0.5, -0.2)), (0.5, 0.2, 0.03)) + b["amber_eye"].box(T((s * 0.24, 0.43, z)) @ Matrix.Rotation(math.radians(-s * 12), 4, "Y"), (0.17, 0.04, 0.035)) + b[CORE].box(T((s * 0.36, 0.4, z - 0.2)), (0.2, 0.3, 0.2)) + b[CORE].box(T((0, 0.44, z - 0.2)), (0.3, 0.3, 0.18)) return cut, b.done() def pauldron_plates(mass, side, cutters=()): - """Hero view, the operator's pauldron line (left) and battery line (right): the pauldron's mass split at the arch - into a hood of lapped plates and, on the left shoulder, the shield before it. The right shoulder's mouth is open - for the battery.""" - tag = "L" if side < 0 else "R" - return [o for o in (MS.plate(f"Pauldron{tag}.{name}", mass, keep, proud, wall, cutters=cutters) for name, keep, proud, wall in SF.pauldron_plates(face=side < 0)) if o] + """Hero and rear views, the operator's pauldron line (left) and battery line (right): the pauldron's mass split + into a deep shell of lapped plates (seraph_form.pauldron_plates). The big outer plate's front edge is her line + as the hero camera draws it; lames lap under it down over the upper arm; the left shoulder carries the shield + before the line, the right's mouth is open for the battery.""" + return _plates(f"Pauldron{'L' if side < 0 else 'R'}", mass, SF.pauldron_plates(side), cutters, flip=side > 0) def shoulder_bearing(frame, side): @@ -118,7 +150,8 @@ def _limb_frame(a, b, forward=(0, 1, 0)): def arm(frame, side): """Hero view: an arm from the shoulder to the wrist on joints.fork_elbow (the library's SERAPH elbow: the upper arm's ribbed spine into the forearm's deep collar, twin rams), the upper arm's armour over the spine. Returns - (objects, the forearm's frame: origin at the elbow, y down the forearm, z its upper side).""" + (objects, the forearm's frame: origin at the elbow, y down the forearm, z its upper side; the elbow's scale). + A ram that does not fit is not drawn (jointlib.Rig.drive).""" import jointlib as J import joints key = "l" if side < 0 else "r" @@ -134,8 +167,8 @@ def arm(frame, side): origin.translation = elbow bend = math.degrees(math.atan2(f.dot(y), -f.dot(z))) K = (top - elbow).length / 1.3 # fork_elbow's upper arm is 1.3 m of spine and block - rig = J.Rig(f"Elbow{tag}", frame @ origin @ Matrix.Scale(K, 4), min(-62.0, bend - 5), max(0.0, bend + 5)) - joints.fork_elbow(rig, bend) + rig = J.Rig(f"Elbow{tag}", frame @ origin @ Matrix.Scale(K, 4), 0.0, max(62.0, bend + 5)) # the library elbow's own range: it only flexes + joints.fork_elbow(rig, bend, collar=COLLAR, collar_mat=CORE) # the collar is the forearm's dark core: forearm() plates it rig.done() print(f"ARM {tag}: elbow bend {bend:.1f}, scale {K:.2f}", flush=True) # the upper arm's armour: a rounded mass round the spine, split front from flank @@ -145,15 +178,140 @@ def arm(frame, side): for name, keep, proud in (("Front", SF.band("y", 0.05) + SF.band("z", 0.3 * K, 1.2 * K), 0.07), ("Out", SF.band("y", None, 0.0) + SF.band("z", 0.2 * K, 1.1 * K) + (SF.band("x", None, 0.05) if side < 0 else SF.band("x", -0.05)), 0.05), ("Rear", SF.band("y", None, -0.05) + SF.band("z", 0.45 * K, 1.25 * K) + (SF.band("x", 0.1) if side < 0 else SF.band("x", None, -0.1)), 0.03)): out.append(MS.plate(f"UpperArm{tag}.{name}", mass, keep, proud, 0.07)) - fore = Matrix((f.cross(y.cross(f)).cross(f) * 0 + x, f, x.cross(f))).transposed().to_4x4() + fore = Matrix((x, f, x.cross(f))).transposed().to_4x4() fore.translation = elbow - return out, frame @ fore + return out, frame @ fore, K + + +def forearm(fore, side, K): + """Hero view, both arms; LEFT FOREARM inset: the forearm as a plated housing. `fore`: origin at the elbow, y down + the forearm, z its upper side. The elbow's collar (COLLAR, dark) is the core; on each of its four faces stand + plates of their own, lapped toward the wrist, the corners between them open to the core: two along the top, two + inboard, one under, and outboard the deep block of the hero view's left forearm with a smaller plate stepped on + it; a ribbed cuff at the wrist. Returns (objects, the wrist's y, the sign of the frame's x that is outboard).""" + tag = "L" if side < 0 else "R" + ob = 1 if (fore.to_3x3() @ Vector((1, 0, 0))).x * side > 0 else -1 + a, c, y0, y1 = 0.5 * COLLAR[0] * K, 0.5 * COLLAR[1] * K, 0.08 * K, 1.03 * K + F = M.frame_at + b = M.Build(f"Forearm{tag}", None, fore) + k, d = b["khaki"], b[CORE] + k.prism(F((0, y0 + 0.28 * K, c + 0.04), (0, 0, 1), (0, 1, 0)), M.rect(0.82 * K, 0.52 * K, 0.1), 0.14, 0.05) # top, by the elbow + k.prism(F((0, y0 + 0.70 * K, c + 0.01), (0, 0, 1), (0, 1, 0)), M.rect(0.72 * K, 0.46 * K, (0.12, 0.12, 0.03, 0.03)), 0.1, 0.04) # lapped under it, toward the wrist + k.prism(F((ob * (a + 0.02), y0 + 0.5 * K, 0.0), (ob, 0, 0), (0, 1, 0)), M.rect(0.72 * K, 0.84 * K, 0.1), 0.3, 0.08, 0.9) # the outboard block + k.prism(F((ob * (a + 0.32), y0 + 0.48 * K, 0.0), (ob, 0, 0), (0, 1, 0)), M.rect(0.44 * K, 0.5 * K, 0.07), 0.09, 0.035) # stepped on it + k.prism(F((-ob * (a + 0.04), y0 + 0.27 * K, 0), (-ob, 0, 0), (0, 1, 0)), M.rect(0.68 * K, 0.5 * K, 0.09), 0.12, 0.05) # inboard, by the elbow + k.prism(F((-ob * (a + 0.01), y0 + 0.69 * K, 0), (-ob, 0, 0), (0, 1, 0)), M.rect(0.6 * K, 0.44 * K, 0.07), 0.09, 0.04) # lapped under it + k.prism(F((0, y0 + 0.44 * K, -c - 0.02), (0, 0, -1), (0, 1, 0)), M.rect(0.7 * K, 0.8 * K, 0.09), 0.09, 0.04) # under + d.lathe(F((0, y1, 0), (0, 1, 0), (0, 0, 1)), [(0, 0), (0.3 * K, 0), (0.3 * K, 0.05), (0.26 * K, 0.07), (0.26 * K, 0.12), (0.3 * K, 0.14), (0.3 * K, 0.19), (0.22 * K, 0.22), (0, 0.22)], 28) + return b.done(), y1 + 0.2, ob + + +def fist(fore, side, at, curl=72.0, scale=1.0): + """Rear view and the hero view's right arm: the hand at the wrist, the joints library's SERAPH fist + (hands.fist), hanging on down the forearm from `at` (the forearm's frame), its palm turned inboard.""" + import jointlib as J + import hands + ob = 1 if (fore.to_3x3() @ Vector((1, 0, 0))).x * side > 0 else -1 + z, y = Vector((0, -1, 0)), Vector((-ob, 0, 0)) + m = Matrix((y.cross(z), y, z)).transposed().to_4x4() + m.translation = Vector(at) + rig = J.Rig(f"Hand{'L' if side < 0 else 'R'}", fore @ m @ Matrix.Scale(scale, 4), 0.0, 100.0) + hands.fist(rig, curl) + return rig.done() + + +def underside(frame): + """Hero view, under the breast: what the camera sees from below is not a plate. A slatted block under the lip, + between the two lower breast blocks; a jowl block a side hung under the outer lower block; three lames stepping + up and back from the lip to the abdomen; two fat conduits a side from under the sternum out to the armpit; + two struts from the abdomen's column up to the chest's floor.""" + b = M.Build("Underside", None, frame) + k, d, m = b["khaki"], b[CORE], b["machine"] + k.hull([(0.44, 2.16, 0.02), (0.38, 2.2, -0.42), (0.44, 1.5, 0.0), (0.36, 1.56, -0.5), (0.3, 2.26, -0.2)], mirror=True) # the block under the lip + for j in range(4): + d.box(T((0, 2.235 - 0.012 * j, -0.08 - 0.09 * j)), (0.5, 0.05, 0.035)) + for s in (-1, 1): + k.hull([(s * x, y, z) for x, y, z in ((0.62, 1.95, 0.0), (0.7, 1.9, -0.34), (1.3, 1.5, 0.0), (1.24, 1.5, -0.3), (0.62, 1.2, 0.0), (0.7, 1.24, -0.4), (1.4, 0.9, 0.05), (1.3, 0.95, -0.26))]) # the jowl + k.hull([(s * x, y, z) for x, y, z in ((1.36, 1.3, 0.3), (1.5, 1.2, -0.02), (1.7, 0.5, 0.42), (1.72, 0.55, 0.1), (1.36, 0.6, 0.3), (1.45, 0.62, 0.02))]) # and the block behind it, under the armpit + for j, (y, z, w) in enumerate(((1.42, -0.16, 1.5), (1.06, -0.3, 1.3), (0.72, -0.44, 1.1))): + (k if j == 0 else d).prism(M.frame_at((0, y, z), (0, 0.35, -1), (0, 1, 0)), M.rect(w, 0.46, 0.1), 0.1, 0.035) # the lames + for s in (-1, 1): + m.rod((s * 0.3, 0.55, -0.02), (s * 0.5, 1.25, -0.2), 0.05) + d.rod((s * 0.3, 0.55, -0.02), (s * 0.4, 0.9, -0.11), 0.085) + d.cylinder(M.frame_at((s * 0.5, 1.25, -0.2), (1, 0, 0)), 0.1, 0.16, 16) + out = b.done() + for s in (-1, 1): + for j, (r, ya, yb) in enumerate(((0.12, 1.15, 0.7), (0.09, 0.85, 0.45))): + M.hose(f"Conduit{s}{j}", frame @ Vector((s * 0.3, ya, -0.26 - 0.06 * j)), (s * 1.0, 0, -0.5), frame @ Vector((s * (1.22 - 0.1 * j), yb, 0.3)), (s * 0.2, 0, -1), r, sag=0.0, mat=CORE) + return out + + +def detail(): + """The detail pass, by surface.py on the plates (its Skin reads a massing plate's own face): the 03 and the + wings on the centre plate with two sunk panels above them, the mark on the left side block, panel lines, a + hatch and an access port on the breast plates, bolt rows inside the rims, gills in the lower blocks and in the + pauldrons' outer plates, the roundel on the left pauldron's shield, bitten lower edges. Each feature is tried on + its own: one that misses its plate is reported, not drawn. Returns (made, failed).""" + import surface as S + S.materials() + made, failed = [0], [] + + def on(plate, steps): + if plate not in bpy.data.objects: + failed.append(f"{plate}: no such plate") + return + skin = S.Skin(plate) + for label, step in steps: + try: + step(skin) + made[0] += 1 + except Exception as error: # a ray that misses, a rim too short: say so and go on + failed.append(f"{plate} {label}: {type(error).__name__} {error}") + try: + lost = skin.prune() + if lost: + failed.append(f"{plate}: {lost} cutters fall where the plate is cut away (a well, a bore); left out") + skin.commit() + except BaseException as error: + failed.append(f"{plate} commit: {type(error).__name__} {error}") + + fwd = (0, -1, 0) + ray = lambda x, z: ((x, 4.0, z), fwd) # noqa: E731 a ray at the torso's front + + def middle(s): + """A frame on the plate's face nearest the middle of its points, upright.""" + at = sum((v.co for v in s.bm.verts), Vector()) / len(s.bm.verts) + return S._frame(*s.nearest(at), (0, 0, 1)) + + def rim(k, spacing=0.24): + return (f"bolts on rim {k}", lambda s: S.bolt_row(s, S.along(s, ("rim", k), spacing=spacing, offset=0.07, margin=0.1), r=0.018)) + + on("Torso.Centre", [("03", lambda s: S.numeral(s, s.at(*ray(0.0, 0.74)), "03", 0.24, "marking_fresh")), + ("wings", lambda s: S.emblem(s, s.at(*ray(0.0, 0.42)), "wings", 0.2)), + ("inset low", lambda s: S.inset(s, s.at(*ray(0.0, 1.22)), (0.3, 0.13))), + ("inset high", lambda s: S.inset(s, s.at((0, 3.0, 4.0), (0, -0.55, -1)), (0.3, 0.13))), + ("line", lambda s: S.panel_line(s, ("line", (-0.4, 4, 1.0), (0.4, 4, 1.0), fwd), gap=0.025)), rim(0), rim(1)]) + for tag, sx in (("L", -1), ("R", 1)): + mark = (lambda s, sx=sx: S.hatch(s, s.at(*ray(sx * 0.78, 0.86)), (0.34, 0.24))) if sx < 0 else (lambda s, sx=sx: S.access_port(s, s.at(*ray(sx * 0.8, 0.9)), 0.08)) + on(f"Torso.Breast{tag}", [("line", lambda s, sx=sx: S.panel_line(s, ("line", (sx * 0.5, 4, 1.2), (sx * 1.25, 4, 1.02), fwd), gap=0.022)), ("hatch" if sx < 0 else "port", mark), + rim(0, 0.3), rim(1, 0.3), ("dings", lambda s, sx=sx: S.edge_dings(s, ("rim", 0), count=6, seed=3 + sx))]) + block = (lambda s, sx=sx: S.numeral(s, s.at(*ray(sx * 1.72, 1.02)), "8", 0.3, "marking_fresh")) if sx < 0 else (lambda s, sx=sx: S.access_port(s, s.at(*ray(sx * 1.7, 1.0)), 0.07)) + on(f"Torso.SideBlock{tag}", [("mark", block), rim(0, 0.3)]) + on(f"Torso.LowerOut{tag}", [("gills", lambda s, sx=sx: S.vent_slots(s, S.along(s, ("line", (sx * 1.2, 4, 0.52), (sx * 1.62, 4, 0.72), fwd), count=3, turn=90), 0.2, 0.035))]) + px = sx # the pauldron's outboard x in its own frame + on(f"Pauldron{tag}.Outer", [("gills", lambda s, px=px: S.vent_slots(s, S.along(s, ("line", (px * 3, 0.5, 0.1), (px * 3, 0.5, -0.3), (-px, 0, 0)), count=2, turn=90), 0.26, 0.04)), + ("line", lambda s, px=px: S.panel_line(s, ("line", (px * 3, 0.75, -0.42), (px * 3, -0.4, -0.42), (-px, 0, 0)), gap=0.022)), rim(0, 0.3), + ("dings", lambda s: S.edge_dings(s, ("rim", 1), count=7, seed=5))]) + on("PauldronL.Shield", [("roundel", lambda s: S.emblem(s, middle(s), "roundel", 0.36)), rim(0, 0.26), rim(1, 0.26)]) + print(f"DETAIL: {made[0]} features made, {len(failed)} failed" + "".join("\n DETAIL FAILED " + f for f in failed), flush=True) + return made[0], failed def cooling(frame, top=3.5, foot=0.42, half=0.78, width=0.95, depth=0.8, y=-1.02): """REAR COOLING ASSEMBLIES inset and the rear view: two tall housings on the back, each a slab-walled box with a stepped cap, its rear face a deep frame round a bank of vertical fins, a U of pipe under its foot. `top` is the - caps' top in the torso's frame: the figure's highest point.""" + caps' top in the torso's frame: the figure's highest point. The fin bank runs nearly the housing's whole height + (the rear view: 3 m of fins between a low sill and a low lintel).""" b = M.Build("Cooling", None, frame) k, d = b["khaki"], b[CORE] h = top - foot @@ -166,15 +324,15 @@ def cooling(frame, top=3.5, foot=0.42, half=0.78, width=0.95, depth=0.8, y=-1.02 k.box(at @ T((0, 0, wall / 2)), (width, depth, wall)) # foot k.box(at @ T((0, 0, h - 0.14)), (width + 0.06, depth + 0.06, 0.12)) # cap, stepped k.box(at @ T((0, 0.04, h - 0.03)), (width - 0.16, depth - 0.16, 0.1)) - k.box(at @ T((0, -depth / 2 + 0.04, 0.3)), (width, 0.08, 0.5)) # the frame's sill - k.box(at @ T((0, -depth / 2 + 0.04, h - 0.45)), (width, 0.08, 0.5)) # and lintel + k.box(at @ T((0, -depth / 2 + 0.04, 0.17)), (width, 0.08, 0.24)) # the frame's sill + k.box(at @ T((0, -depth / 2 + 0.04, h - 0.32)), (width, 0.08, 0.24)) # and lintel n = 13 for i in range(n): x = (i - (n - 1) / 2) * (width - 2 * wall - 0.06) / (n - 1) - d.box(at @ T((x, -depth / 2 + 0.2, h / 2)), (0.018, 0.3, h - 0.9)) + d.box(at @ T((x, -depth / 2 + 0.2, h / 2 - 0.07)), (0.018, 0.3, h - 0.72)) d.box(at @ T((0, 0.0, h / 2)), (width - 2 * wall, depth - 0.3, h - 0.3)) # the core behind the fins - for j in range(5): - d.box(at @ T((0, -depth / 2 + 0.08, 0.7 + j * (h - 1.4) / 4)), (width - 2 * wall, 0.04, 0.04)) + for j in range(7): + d.box(at @ T((0, -depth / 2 + 0.08, 0.5 + j * (h - 1.1) / 6)), (width - 2 * wall, 0.04, 0.04)) k.hull([(s * half + sx * 0.3, y - depth - 0.0 + 0.02, foot + h * 0.12 + dz) for sx in (-1, 1) for dz in (0, 0.5)] + [(s * half + sx * 0.3, y - depth - 0.07, foot + h * 0.12 + dz) for sx in (-1, 1) for dz in (0.06, 0.44)]) out = b.done() for s in (-1, 1): diff --git a/surfaces/blender/experiments/mechs/seraph_form.py b/surfaces/blender/experiments/mechs/seraph_form.py index 00843f6..ae2fc68 100644 --- a/surfaces/blender/experiments/mechs/seraph_form.py +++ b/surfaces/blender/experiments/mechs/seraph_form.py @@ -32,27 +32,43 @@ TORSO = [(-0.06, 0.92, 0.98, 0.85, 1.14, 3.5), # under the lip: the unders (1.95, 1.95, 1.05, 1.15, 0.00, 4.5), # the shoulders' line (2.30, 1.70, 0.60, 1.10, 0.00, 3.6), (2.50, 1.15, 0.20, 0.90, -0.10, 2.8)] -RECESS = {"at": (0.0, 0.50, 2.50), "r": (0.82, 0.85, 0.70)} # the head's well: an ellipsoid cut from the mass's top -HELMET = {"at": (0.0, 0.12, 2.52), "r": (0.56, 0.62, 0.60)} # the dome set in it: its crown stands at at.z + r.z -CENTRE = (0.20, 0.05, 0.29, 1.43) # the centre plate's half-width at a height, twice: (w0, z0, w1, z1) +RECESS = {"at": (0.0, 0.75, 2.60), "r": (0.92, 1.10, 1.10)} # the head's well: an ellipsoid cut from the mass's top and open to the front, its front rim at the break (the hero view: the centre plate ends where the well begins) +CENTRE = (0.20, 0.05, 0.29, 1.43) # the centre plate's half-width at a height, twice (w0, z0, w1, z1): the straight fit of her lines +HELMET = {"at": (0.0, 0.10, 2.60)} # the helmet's frame: its widest ring's middle # The left pauldron's mass, in its own frame: the torso's axes at PAULDRON["at"], rolled `cant` degrees about y (its # crown leaning inboard). The right one is its mirror. -PAULDRON = {"at": (-2.78, 0.0, 1.80), "cant": 14.0, "arch": ((-0.45, 0.89, 0.0), 0.62), # arch: the hood's front edge, the plane n.p = d +PAULDRON = {"at": (-2.78, 0.0, 1.80), "cant": 14.0, "arch": ((-0.45, 0.89, 0.0), 0.62), # arch: round 10's hood edge, kept for the overlay + "mouth": ((0.24, 0.97, 0.0), 0.74), # the plane the battery's face stands on (the right pauldron): square to the front, turned a little inboard, as the hero camera sees all six pipes - "rings": [(-1.20, 0.55, 0.80, 0.80, 0.0, 3.0), - (-0.65, 0.72, 1.00, 0.95, 0.0, 3.0), - (0.00, 0.76, 1.05, 1.00, 0.0, 3.0), - (0.40, 0.64, 0.86, 0.80, 0.0, 2.8), - (0.62, 0.40, 0.50, 0.50, 0.0, 2.4)]} + "rings": [(-1.20, 0.55, 0.80, 0.80, 0.0, 4.0), # powers of 4 and more: a box with broad clipped corners, a flat front (the shield's face) and a flat outer face; her line runs down the corner between them + (-0.65, 0.72, 1.00, 0.95, 0.0, 4.6), + (0.00, 0.76, 1.05, 1.00, 0.0, 4.6), + (0.40, 0.64, 0.86, 0.80, 0.0, 3.6), + (0.62, 0.40, 0.50, 0.50, 0.0, 2.6)]} +# The right pauldron rides the raised right arm of the hero view: the left's mirror, pitched forward about the shoulder's +# axis and shifted, so the battery's mouth stands before and above the upper arm as the hero view has it. (The rear +# view draws both arms down and both pauldrons level: one build cannot hold both poses.) +PAULDRON_R = {"shift": (-0.1, 0.55, 0.30), "pitch": 8.0} # The arms' pose, in the torso's frame: elbow and wrist; reach is the forearm weapon's length past the wrist. ARMS = {"r": {"elbow": (2.50, 0.55, -0.15), "wrist": (2.75, 1.70, -1.10), "reach": 3.3}, "l": {"elbow": (-2.80, -0.40, -0.10), "wrist": (-3.10, -0.10, -1.25), "reach": 1.9}} -HELM = [(-0.45, 0.50, 0.55, 0.55, 0.0, 2.6), # the helmet's own rings, about HELMET["at"] - (-0.10, 0.56, 0.64, 0.60, 0.0, 2.8), - (0.22, 0.52, 0.60, 0.58, 0.0, 2.6), - (0.45, 0.36, 0.40, 0.42, 0.0, 2.3)] -VISOR = {"at": (0.0, 0.62, -0.13), "size": (0.86, 0.6, 0.11)} # the slit under the brow, in the helmet's frame +# The helmet: a faceted shell of eight sides (HELM_N), wider than it is tall, about HELMET["at"]. +HELM_N = 8 +HELM = [(-0.46, 0.54, 0.50, 0.56, 0.0, 2.6), + (-0.14, 0.72, 0.64, 0.66, 0.0, 3.0), + (0.18, 0.70, 0.56, 0.64, 0.0, 2.8), + (0.50, 0.46, 0.18, 0.46, -0.08, 2.4)] +# The brow plate over the visor (the helmet's frame, one side; mirrored): a heavy wedge from high on the crown's +# front out over the slit, its lower edge level. Its face is steep: the hero camera, 30 degrees below, sees it. +BROW = [(0.62, 0.20, 0.02), (0.46, 0.22, 0.44), (0.40, 0.84, 0.10), (0.50, 0.90, -0.15), (0.72, 0.30, -0.13), (0.0, 0.30, 0.52), (0.0, 0.90, 0.14), (0.0, 0.96, -0.15)] +VISOR = {"at": (0.0, 0.62, -0.26), "size": (1.0, 0.6, 0.17)} # the slit under the brow, in the helmet's frame GAP = 0.03 +COOLING = {"foot": 0.28, "half": 0.72, "width": 0.84, "depth": 0.9, "y": -1.02} # the rear cooling units (seraph_body.cooling), in the torso's frame +GAP_PX = 2.5 # the same gap where a plate's edge is a traced line, in the sheet's pixels +# Reference pixels of the hero view: which side of a traced line a plate lies on (massing.Curtain). +PX = {"centre": (322, 122), "breast_r": (255, 135), "breast_l": (405, 135), "pauldron_out": (625, 110), "pauldron_in": (528, 132), + "battery_out": (150, 88), "battery_in": (205, 150)} +PAULDRON_LINE_END = 172 # her pauldron line below this row of the sheet is the arm's def band(axis, lo=None, hi=None): @@ -71,57 +87,101 @@ def mirrored(keep): def centre_edges(): - """The centre plate's two edges as planes: the operator's chest lines, lifted (seraph_pose.py).""" + """The centre plate's two edges as planes: the operator's chest lines, lifted (seraph_pose.py). The plates + themselves are cut by the lines' own sight curtains; this is the straight fit the overlays draw.""" w0, z0, w1, z1 = CENTRE k = (w1 - w0) / (z1 - z0) c = w0 - k * z0 return k, c +def plane(a, b, keep): + """The half-space bounded by the line through (x, z) points a and b, extruded along y, that holds `keep`.""" + n = np.array([b[1] - a[1], 0.0, -(b[0] - a[0])]) + n /= np.linalg.norm(n) + d = n[0] * a[0] + n[2] * a[1] + if n[0] * keep[0] + n[2] * keep[1] > d: + n, d = -n, -d + return (tuple(n), float(d)) + + +DIAG = ((0.22, 0.10), (1.34, 0.86)) # the big breast plate's lower edge, (x, z): from the lip up and out to the side block + + def torso_plates(): - """[(name, keep, proud, wall)] in the torso's frame. Sided plates are given for the mech's right and mirrored.""" - k, c = centre_edges() - inside = [((1.0, 0.0, -k), c), ((-1.0, 0.0, -k), c)] - right_of = [((-1.0, 0.0, k), -(c + GAP))] - out = [("Centre", inside + band("y", 0.2) + band("z", 0.0), 0.16, 0.12), # from the lip up over the break to the well's rim: her lines its edges all the way - ("Collar", band("x", -1.15, 1.15) + band("z", 2.02) + band("y", -0.75), 0.2, 0.14), - ("Chin", band("x", -0.6, 0.6) + band("z", None, -0.03) + band("y", 1.1), 0.05, 0.1)] - sided = [("BreastIn", right_of + band("x", None, 1.10) + band("y", 0.5) + band("z", 0.02, 1.36), 0.07, 0.08), - ("BreastBlock", band("x", 0.98) + band("y", 0.42) + band("z", 0.42, 1.50), 0.20, 0.20), - ("Deck", right_of + band("z", 1.46) + band("y", 0.25), 0.10, 0.10), - ("Flank", band("x", 0.9) + band("y", -0.40, 0.38) + band("z", 0.40), 0.05, 0.08), - ("BackUp", band("x", 0.10) + band("y", None, -0.44) + band("z", 1.25), 0.06, 0.08), - ("BackLow", band("x", 0.10) + band("y", None, -0.44) + band("z", 0.45, 1.21), 0.09, 0.08)] - for name, keep, proud, wall in sided: - out.append((name + "R", keep, proud, wall)) - out.append((name + "L", mirrored(keep), proud, wall)) + """[(name, keep, proud, wall, chamfer, lines)] in the torso's frame, as the concept's breast is split: ONE big + breast plate a side, from her line out to the side block and from its raked lower edge up over the break to + the collar; under it two heavy lower blocks, the outer standing proud of the inner; a deep side block lapped + over the big plate's outer edge and wrapping round the flank; a yoke under each periscope lapped over the big + plate's top corner. Each plate stands at its own depth, so every neighbour is a step. Sided plates are given + for the mech's right and mirrored. `lines`: [(traced line's tag, shift in pixels, reference pixel's tag)]: the + plate lies on that pixel's side of her line (the centre plate's edges ARE her two lines).""" + above, below = plane(*DIAG, (0.5, 1.2)), plane((DIAG[0][0], DIAG[0][1] - 0.05), (DIAG[1][0], DIAG[1][1] - 0.05), (0.8, 0.0)) + out = [("Centre", band("y", 0.2) + band("z", 0.0, 1.56), 0.17, 0.15, 0.05, [("chest_r", 0, "centre"), ("chest_l", 0, "centre")]), + ("CollarBack", band("x", -1.15, 1.15) + band("z", 2.02) + band("y", -0.75, 0.2), 0.20, 0.16, 0.05, [])] + sided = [("Breast", band("x", None, 1.34) + band("y", 0.25) + band("z", None, 2.0) + [above], 0.09, 0.13, 0.05, True), + ("Collar", band("x", 0.36, 1.15) + band("z", 2.03) + band("y", 0.23), 0.20, 0.16, 0.05, False), + ("LowerIn", band("x", None, 0.95) + band("y", 0.5) + band("z", 0.0) + [below], 0.01, 0.22, 0.06, True), + ("LowerOut", band("x", 0.86) + band("y", 0.15) + band("z", 0.26) + [below], 0.13, 0.24, 0.07, False), + ("SideBlock", band("x", 1.12) + band("y", 0.30) + band("z", 0.72, 1.42) + [plane((1.12, 1.0), (1.5, 0.72), (1.7, 1.2))], 0.27, 0.26, 0.08, False), + ("Yoke", band("x", 1.10) + band("z", 1.56) + band("y", -0.72, 0.75), 0.22, 0.2, 0.07, False), + ("FlankUp", band("x", 0.9) + band("y", -0.42, 0.30) + band("z", 1.18, 1.52), 0.08, 0.1, 0.04, False), + ("FlankLow", band("x", 0.9) + band("y", -0.42, 0.11) + band("z", 0.40, 1.14), 0.02, 0.1, 0.04, False), + ("Back", band("x", 0.10) + band("y", None, -0.46) + band("z", 0.98), 0.05, 0.1, 0.04, False), + ("BackSkirt", band("x", 0.10) + band("y", None, -0.46) + band("z", 0.42, 1.06), 0.12, 0.1, 0.05, False)] + for name, keep, proud, wall, chamfer, lined in sided: + out.append((name + "R", keep, proud, wall, chamfer, [("chest_r", -GAP_PX, "breast_r")] if lined else [])) + out.append((name + "L", mirrored(keep), proud, wall, chamfer, [("chest_l", GAP_PX, "breast_l")] if lined else [])) return out -def pauldron_plates(face): - """[(name, keep, proud, wall)] in the left pauldron's frame (outboard is -x). The arch plane parts the hood from - the face: the operator's pauldron line on the left shoulder, her battery line on the right. `face`: the plates - before the arch (the left shoulder's shield); without them the mouth is open (the right shoulder's battery).""" - n, d = PAULDRON["arch"] - hood = [(n, d - GAP)] - front = [(tuple(-c for c in n), -d)] - out = [("Cap", hood + band("z", 0.12), 0.10, 0.10), - ("OuterUp", hood + band("z", -0.50, 0.08) + band("x", None, 0.10), 0.06, 0.09), - ("OuterLow", hood + band("z", -1.20, -0.42) + band("x", None, 0.10), 0.0, 0.08), - ("Inner", hood + band("z", -0.90, 0.08) + band("x", 0.14), 0.04, 0.08)] - if face: - out += [("Shield", front + band("z", -0.72, 0.5), -0.02, 0.10), - ("ShieldLow", front + band("z", -1.20, -0.66), -0.09, 0.08)] +def pauldron_plates(side): + """[(name, keep, proud, wall, chamfer, lines)] in the left pauldron's frame (outboard is -x), for a side (-1 the + left, 1 the right; seraph_body mirrors the right's planes). A deep shell of lapped plates: the big outer plate, + whose front edge is the operator's line (her pauldron line on the left shoulder, her battery line on the right), + two lames lapped under its lower edge and coming down over the upper arm, a cap inboard of the line, an inner + wall, two rear plates. Before the line the left shoulder carries the shield and a lame under it; the right's + mouth is open for the battery.""" + line, out_px, in_px = ("pauldron_l", "pauldron_out", "pauldron_in") if side < 0 else ("battery", "battery_out", "battery_in") + outer, inner = [(line, 0, out_px)], [(line, GAP_PX if side < 0 else -GAP_PX, in_px)] + out = [("Outer", band("z", -1.0) + band("y", -0.52), 0.11, 0.15, 0.06, outer), + ("Lame1", band("z", -1.24, -0.88) + band("y", -0.52), 0.0, 0.11, 0.04, outer), + ("Lame2", band("z", None, -1.12) + band("y", -0.52), -0.07, 0.10, 0.04, outer), + ("Cap", band("z", 0.44), 0.05, 0.12, 0.05, inner), + ("Inner", band("x", 0.12) + band("z", None, 0.40) + band("y", None, 0.1), 0.03, 0.09, 0.03, []), + ("RearUp", band("y", None, -0.56) + band("z", -0.34) + band("x", None, 0.09), 0.07, 0.11, 0.05, []), + ("RearLow", band("y", None, -0.56) + band("z", None, -0.26) + band("x", None, 0.09), 0.0, 0.10, 0.04, [])] + if side < 0: + clip = [((0.6, 0.0, 0.8), 0.62), ((0.6, 0.0, -0.8), 1.12)] # the shield's clipped inboard corners: a hexagon + out += [("Shield", band("y", 0.13) + band("z", -0.95, 0.40) + band("x", None, 0.62) + clip, 0.15, 0.13, 0.05, inner), + ("ShieldLow", band("y", 0.13) + band("z", None, -0.85) + band("x", None, 0.46), 0.04, 0.10, 0.04, inner)] + else: + out += [("Lip", band("y", 0.13) + band("z", None, -0.95) + band("x", None, 0.46), 0.04, 0.12, 0.04, inner)] # the mouth's sill return out def helmet_plates(): - """[(name, keep, proud, wall)] in the helmet's frame: the crown's centre panel between the chest lines run on - over the head, a panel each side of it, the nape. Under the brow the helmet is its dark core: the face.""" - return [("CrownC", band("x", -0.27, 0.27) + band("z", -0.03), 0.09, 0.08), - ("CrownR", band("x", 0.30) + band("z", -0.03), 0.05, 0.07), - ("CrownL", band("x", None, -0.30) + band("z", -0.03), 0.05, 0.07), - ("Nape", band("y", None, -0.15) + band("z", None, -0.07), 0.04, 0.07)] + """[(name, keep, proud, wall, chamfer, lines)] in the helmet's frame: the crown's centre panel between the + operator's chest lines run on over the head, a faceted panel each side of it, cheeks, the nape. Under the brow + the helmet is its dark core: the face.""" + return [("CrownC", band("z", -0.02), 0.08, 0.09, 0.03, [("chest_r", 0, "centre"), ("chest_l", 0, "centre")]), + ("CrownR", band("z", -0.02) + band("x", 0.0), 0.04, 0.08, 0.03, [("chest_r", -GAP_PX, "breast_r")]), + ("CrownL", band("z", -0.02) + band("x", None, 0.0), 0.04, 0.08, 0.03, [("chest_l", GAP_PX, "breast_l")]), + ("CheekR", band("x", 0.30) + band("z", None, -0.06) + band("y", -0.2), 0.06, 0.09, 0.03, []), + ("CheekL", band("x", None, -0.30) + band("z", None, -0.06) + band("y", -0.2), 0.06, 0.09, 0.03, []), + ("Nape", band("y", None, -0.24) + band("z", None, -0.06), 0.03, 0.08, 0.03, [])] + + +def traced(tag): + """A line the operator traced on the hero view (concepts.json "flow"), in the sheet's pixels. Her pauldron line + runs on down the arm: the pauldron's part of it ends at PAULDRON_LINE_END.""" + pts = np.array(json.loads((HERE / "concepts.json").read_text(encoding="utf-8"))["seraph"]["flow"]["lines"][tag]["points"], float) + if tag == "pauldron_l": + keep = pts[pts[:, 1] <= PAULDRON_LINE_END] + nxt = pts[len(keep)] + last = keep[-1] + (nxt - keep[-1]) * (PAULDRON_LINE_END - keep[-1][1]) / (nxt[1] - keep[-1][1]) + pts = np.vstack([keep, last]) + return pts def cameras(): @@ -185,14 +245,23 @@ def reach(rings, z, side): return float(np.interp(z, zs, [r[col] for r in rings])) -def pauldron_frame(side): - """A pauldron's frame in the torso's: side -1 the left (as drawn), 1 the right (mirrored in x).""" +def pauldron_frame(side, proper=False): + """A pauldron's frame in the torso's: side -1 the left (as drawn), 1 the right (mirrored in x). `proper` gives + the right's as a rotation (the left's mirrored on both sides): what is drawn in it must itself be mirrored.""" c = math.radians(PAULDRON["cant"]) m = np.eye(4) m[:3, :3] = np.array([[math.cos(c), 0, math.sin(c)], [0, 1, 0], [-math.sin(c), 0, math.cos(c)]]) m[:3, 3] = PAULDRON["at"] if side > 0: m = np.diag([-1.0, 1, 1, 1]) @ m + dx, dy, dz = PAULDRON_R["shift"] + p = math.radians(-PAULDRON_R["pitch"]) + pose = np.eye(4) + pose[:3, :3] = np.array([[1, 0, 0], [0, math.cos(p), -math.sin(p)], [0, math.sin(p), math.cos(p)]]) + pose[:3, 3] = np.array(SHOULDER) + (dx, dy, dz) - pose[:3, :3] @ np.array(SHOULDER) # pitched about the shoulder's axis, then shifted + m = pose @ m + if proper: + m = m @ np.diag([-1.0, 1, 1, 1]) return m @@ -263,8 +332,11 @@ def curves(): for tag, s in (("plate_r", 1), ("plate_l", -1)): out[tag] = (to_world([(s * centre_w(z), front(z, centre_w(z)), z) for z in zs], m), (0, 255, 0)) out["well"] = (to_world(ellipse(RECESS["at"], RECESS["r"], "xy"), m), (255, 160, 0)) - for plane in ("xz", "yz", "xy"): - out["helmet_" + plane] = (to_world(ellipse(HELMET["at"], HELMET["r"], plane), m), (255, 255, 0)) + hp, hf = loft(HELM, n=HELM_N, crown=0.2) + hw = to_world(hp + np.array(HELMET["at"]), m) + for k in range(len(HELM)): + ring_ = hw[(k + 1) * HELM_N:(k + 2) * HELM_N] + out[f"helmet_{k}"] = (np.vstack([ring_, ring_[:1]]), (255, 255, 0)) pts, faces = loft(PAULDRON["rings"]) arch = section(pts, faces, *PAULDRON["arch"]) for tag, side in (("arch_l", -1), ("arch_r", 1)): diff --git a/surfaces/blender/experiments/mechs/seraph_sheets.py b/surfaces/blender/experiments/mechs/seraph_sheets.py index 10f6792..386b162 100644 --- a/surfaces/blender/experiments/mechs/seraph_sheets.py +++ b/surfaces/blender/experiments/mechs/seraph_sheets.py @@ -7,6 +7,8 @@ Reads MECH_OUT/seraph/ (seraph.py's renders per stage); writes under MECH_OUT/co seraph_vs_concept.png (full) concept hero | ours | the two laid over each other; concept rear | ours | laid over seraph_chest_head.png (full) the concept's chest and head | ours in the same pixels, the operator's two lines (red) and our built edges of the torso and helmet (cyan) on both; under them ours alone + seraph_pauldron.png (full) the concept's left pauldron | ours in the same pixels with her pauldron line (red) and the + pauldron's built edges (cyan) | ours; under them the rear view's pauldron, concept and ours seraph_flowlines.png (full) her markup | our hero render with her strokes (red) over our built edges (cyan) | fitshell.along per line seraph_camera.png (full) the kept cameras: the marked joints (yellow) against the build's (cyan) @@ -165,6 +167,12 @@ def full_sheets(): o = o.resize(c.size) rows.append(row([label(c, f"sheet 30, {tag} view"), label(o, f"ours, at the kept {tag} camera"), label(Image.blend(c, o, 0.5), "the two laid over each other")])) scores[f"silhouette_{tag}"] = overlap(tag, "full") + bal = json.loads((src / "seraph_balance.json").read_text(encoding="utf-8")) + scores["balance"] = bal + side = [label(fit(Image.open(src / f"full_turn_{az:03d}.png").convert("RGB"), H), t) for az, t in ((90, "ours from the left side (the sheet draws no side view)"), (35, "three-quarter"))] + body = ["the balance, side view (y forward, metres):", "", f"centre of volume y {bal['com'][1]:+.2f} z {bal['com'][2]:.2f}", " (every mesh solid, one density)", f"feet y {bal['feet_y'][0]:+.2f} .. {bal['feet_y'][1]:+.2f}", + f"chest's lip y {bal['chest_lip_y']:+.2f}", f"foremost (muzzle) y {bal['foremost_y']:+.2f}", f"rearmost y {bal['rearmost_y']:+.2f}", "", f"the lip stands {bal['chest_lip_y'] - bal['feet_y'][1]:+.2f} m past the toes"] + rows.append(row(side + [text_panel(body, 560, H + 34)])) stack(rows).save(dst / "seraph_vs_concept.png") # chest and head box = [200, 0, 520, 300] @@ -179,6 +187,19 @@ def full_sheets(): stack([row([label(in_box(crop, box, lines=lines, segs=torso, width=5), "sheet 30: her two lines (red); our torso's and helmet's built edges (cyan), same camera"), label(in_box(chest, box, lines=lines, segs=torso, width=5), "ours at the kept hero camera. " + note)]), row([label(crop, "sheet 30"), label(chest, "ours, in the build")]), row([label(in_box(crop, box, lines=lines, width=5), "her lines alone"), label(alone, "ours: torso and head alone")])]).save(dst / "seraph_chest_head.png") + # pauldron: her line against the left pauldron's built edges, hero and rear + pbox, rbox = [440, 20, 700, 330], [700, 15, 810, 150] + ours = Image.open(src / "full_pauldron.png").convert("RGB") + pc = sheet.crop(tuple(pbox)).resize(ours.size, Image.LANCZOS) + pseg = [e["seg"] for e in edges if e["object"].startswith("PauldronL.")] + part = [tuple(p) for p in SF.traced("pauldron_l")] + whole = {"pauldron_part_on_pauldron_edges": fitshell.along(part, pseg, FIG), "pauldron_part_on_all_edges": fitshell.along(part, segs, FIG), "whole_line_on_all_edges": fitshell.along(flow["pauldron_l"], segs, FIG)} + scores["pauldron_line"] = whole + v = whole["pauldron_part_on_pauldron_edges"] + rear_o = Image.open(src / "full_pauldron_rear.png").convert("RGB") + rear_c = sheet.crop(tuple(rbox)).resize(rear_o.size, Image.LANCZOS) + stack([row([label(in_box(pc, pbox, lines=[flow["pauldron_l"]], width=5), "sheet 30, left pauldron: her line (red)"), label(in_box(ours, pbox, lines=[flow["pauldron_l"]], segs=pseg, width=5), f"ours, same camera: her line (red), the pauldron's built edges (cyan). Its part of the line: on {v['on']:.2f}, run {v['run']:.2f}, off {v['off']:.2f}% H"), label(ours, "ours, in the build")]), + row([label(rear_c, "sheet 30, rear view, left pauldron"), label(rear_o, "ours, at the kept rear camera")])]).save(dst / "seraph_pauldron.png") # flow lines fl = {k: fitshell.along(pts, segs, FIG) for k, pts in flow.items()} fl["mean"] = {k: round(float(np.mean([v[k] for v in fl.values()])), 3) for k in ("on", "run", "off")} diff --git a/surfaces/blender/experiments/mechs/surface.py b/surfaces/blender/experiments/mechs/surface.py index 1fd273a..8a47b6a 100644 --- a/surfaces/blender/experiments/mechs/surface.py +++ b/surfaces/blender/experiments/mechs/surface.py @@ -185,8 +185,10 @@ def _vert_chains(edges): class Skin: - """The outer face of a shell made by brokkr_kitbash.shell, in the shell's own frame: its cage under the - Subdivision alone. Collects the cutters and the geometry features queue on it; commit() writes them.""" + """The outer face of a plate, in the plate's own frame: a brokkr_kitbash.shell's cage under its Kit Subsurf + alone, or a massing.plate's own mesh (no Kit Subsurf: the mesh is the face, a Kit Solidify walls it inward). + Any mesh with a Kit Solidify whose base mesh is its outer face will do. Collects the cutters and the geometry + features queue on it; commit() writes them.""" def __init__(self, shell): obj = bpy.data.objects[shell] if isinstance(shell, str) else shell @@ -194,18 +196,21 @@ class Skin: self.thickness = obj.modifiers["Kit Solidify"].thickness self.stretch = M.STRETCH.get(obj.name, Matrix.Identity(3)) self.mat = next((key for key, mat in M.MATS.items() if obj.data.materials and mat == obj.data.materials[0]), "khaki") - probe = bpy.data.objects.new(obj.name + ".skin", obj.data) - bpy.context.scene.collection.objects.link(probe) - source, mod = obj.modifiers["Kit Subsurf"], probe.modifiers.new("Subsurf", "SUBSURF") - for prop in source.bl_rna.properties: - if not prop.is_readonly and prop.identifier not in ("name", "show_viewport", "show_render"): - setattr(mod, prop.identifier, getattr(source, prop.identifier)) - M.update() - mesh = bpy.data.meshes.new_from_object(probe.evaluated_get(bpy.context.evaluated_depsgraph_get())) - bpy.data.objects.remove(probe, do_unlink=True) self.bm = bmesh.new() - self.bm.from_mesh(mesh) - bpy.data.meshes.remove(mesh) + if "Kit Subsurf" in obj.modifiers: + probe = bpy.data.objects.new(obj.name + ".skin", obj.data) + bpy.context.scene.collection.objects.link(probe) + source, mod = obj.modifiers["Kit Subsurf"], probe.modifiers.new("Subsurf", "SUBSURF") + for prop in source.bl_rna.properties: + if not prop.is_readonly and prop.identifier not in ("name", "show_viewport", "show_render"): + setattr(mod, prop.identifier, getattr(source, prop.identifier)) + M.update() + mesh = bpy.data.meshes.new_from_object(probe.evaluated_get(bpy.context.evaluated_depsgraph_get())) + bpy.data.objects.remove(probe, do_unlink=True) + self.bm.from_mesh(mesh) + bpy.data.meshes.remove(mesh) + else: # a massing.plate: its mesh IS the outer face, walled inward by its Kit Solidify + self.bm.from_mesh(obj.data) self.bm.normal_update() self.bm.faces.ensure_lookup_table() self.bvh = BVHTree.FromBMesh(self.bm) @@ -333,6 +338,17 @@ class Skin: "params": "; ".join(f"{k}={v:.6g}" for k, v in params.items())}) return name + def prune(self): + """Drop the queued cutters whose ray misses the plate as it stands evaluated (brokkr_kitbash.cut refuses the + whole call for one miss): a feature queued off the uncut face where a well or a bore has since taken the + plate away. Returns how many were dropped.""" + M.update() + tree = BVHTree.FromObject(self.obj, bpy.context.evaluated_depsgraph_get()) + kept = [c for c in self.cuts if tree.ray_cast(Vector(c["origin"]), Vector(c["direction"]).normalized())[0] is not None] + lost = len(self.cuts) - len(kept) + self.cuts = kept + return lost + def geo(self, mat=None): """The Geo of one material; None is the plate's own paint (its _fit twin where there is one).""" mat = mat or (self.mat + "_fit" if self.mat + "_fit" in M.MATS else self.mat) diff --git a/surfaces/blender/experiments/mechs/weapons_missile.py b/surfaces/blender/experiments/mechs/weapons_missile.py index b56f50b..cb6864a 100644 --- a/surfaces/blender/experiments/mechs/weapons_missile.py +++ b/surfaces/blender/experiments/mechs/weapons_missile.py @@ -106,24 +106,29 @@ def spectre_recessed_rack(b, size="M", cols=None, rows=None): @weapon("Launcher", "SERAPH, RIGHT SHOULDER MISSILE BATTERY", "30.webp", (863, 452, 1017, 598), view=(-24, 2, 0.84), sweeps=GRIDS + [("door=80", {"door": 80}), ("door=0", {"door": 0})]) -def seraph_battery(b, size="M", cols=None, rows=None, door=24.0): +def seraph_battery(b, size="M", cols=None, rows=None, door=24.0, cowl=True, depth=1.4): """SERAPH, RIGHT SHOULDER MISSILE BATTERY inset. A thick-walled cowl, an arch of five slabs from the upper left over the top and down the right, a floor slab, a cap slab lapped over the top; in its dark mouth `cols` columns of `rows` launch pipes, each column a little lower than the one before, each a pipe with a bright lip and a missile nose; on the left a flat door plate hinged on its outer edge, swung `door` degrees open. - (seraph_parts.battery with a grid and a size class.) Mount: behind.""" + (seraph_parts.battery with a grid and a size class.) Mount: behind. `cowl=False` leaves out the cowl's slabs for + a battery that stands in a mouth of the mech's own (SERAPH's right pauldron is its hood): the pipes, their dark + block and the door alone, so the pipes fill the mouth at the class's size. `depth` is the body's, mouth to mount neck (1.0 at least: a shallow + hood).""" + depth = max(depth, 1.0) H.begin(b, size) cols, rows = cols or pick(size, 2, 2, 3), rows or pick(size, 2, 3, 3) k, d = b["khaki"], b["gunmetal"] p = 0.44 - Rx, Rz, depth, t = 0.5 * cols * p + 0.48, 0.5 * rows * p + 0.28, 1.4, 0.2 - angles = [150, 110, 70, 30, -10, -50] - for a0, a1 in zip(angles, angles[1:]): - p0, p1 = (Vector((math.cos(math.radians(a)) * Rx * 1.05, 0, math.sin(math.radians(a)) * Rz)) for a in (a0, a1)) - mid, chord = (p0 + p1) / 2, (p1 - p0) - k.prism(T(mid + Vector((0, -depth, 0))) @ RY(-math.degrees(math.atan2(chord.z, chord.x))) @ RX(-90), M.rect(chord.length + 0.1, t, 0.03), depth, 0.03) - k.prism(T((0.0, -depth, -Rz + 0.1)) @ RX(-90), M.rect(2 * Rx - 0.2, t, 0.03), depth, 0.03) - k.prism(T((-0.2, -depth - 0.1, Rz + 0.08)) @ RY(5) @ RX(-90), M.rect(2 * Rx + 0.2, 0.14, 0.03), depth * 0.86, 0.03) + Rx, Rz, t = 0.5 * cols * p + 0.48, 0.5 * rows * p + 0.28, 0.2 + if cowl: + angles = [150, 110, 70, 30, -10, -50] + for a0, a1 in zip(angles, angles[1:]): + p0, p1 = (Vector((math.cos(math.radians(a)) * Rx * 1.05, 0, math.sin(math.radians(a)) * Rz)) for a in (a0, a1)) + mid, chord = (p0 + p1) / 2, (p1 - p0) + k.prism(T(mid + Vector((0, -depth, 0))) @ RY(-math.degrees(math.atan2(chord.z, chord.x))) @ RX(-90), M.rect(chord.length + 0.1, t, 0.03), depth, 0.03) + k.prism(T((0.0, -depth, -Rz + 0.1)) @ RX(-90), M.rect(2 * Rx - 0.2, t, 0.03), depth, 0.03) + k.prism(T((-0.2, -depth - 0.1, Rz + 0.08)) @ RY(5) @ RX(-90), M.rect(2 * Rx + 0.2, 0.14, 0.03), depth * 0.86, 0.03) d.box(T((0.05, -0.95, 0.0)), (2 * Rx - 0.3, 0.8, 2 * Rz - 0.3)) for col in range(cols): x = (col - 0.5 * (cols - 1)) * p + 0.07 @@ -136,7 +141,8 @@ def seraph_battery(b, size="M", cols=None, rows=None, door=24.0): hinge = T((-Rx - 0.1, -0.1, -0.02)) @ RZ(-door) k.prism(hinge @ T((0.36, 0, 0)) @ RX(-90), M.rect(0.72, 2 * Rz - 0.6, 0.06), 0.1, 0.03) d.rod(hinge @ Vector((0, 0.02, -Rz + 0.4)), hinge @ Vector((0, 0.02, Rz - 0.4)), 0.04, 10) - k.box(T((-Rx + 0.02, -0.5 * depth - 0.15, -0.1)), (0.15, depth - 0.3, 2 * Rz - 0.5)) + if cowl: + k.box(T((-Rx + 0.02, -0.5 * depth - 0.15, -0.1)), (0.15, depth - 0.3, 2 * Rz - 0.5)) return H.mount(b, size, F((0, -depth - 0.3, 0), (0, -1, 0), (0, 0, 1)), 0.3, muzzle=Y(0.0))