mech experiments: shell_action writes a to_host's sizes and mirror into the sheet and refuses only a shear; seven Seraph plates brought under their fold onset

shell_action splits build.to_host into a turn and move (the object's matrix) and a size along each of the sheet's
axes, x negative for a mirror, which it writes into the ring points; a mirror reverses flip (a sheet mirrored about
x is its own image). cuts_action and ribs_action carry rays and planes by the same sizes. A shear is refused, naming
the two axes and their angle. seraph.py builds all fifteen shells on both sides: 23 shell objects, none scaled.
shell_action prints the action's fold estimate where its margin is under 1.4.

Turned inner faces of the evaluated wall (Kit Subsurf and Kit Solidify alone), before -> after, with what changed:
  pauldron.cap       20 -> 0   thickness 0.09 -> 0.032, levels 3 -> 2 (measured onset 0.0437); cut depths 0.03/0.04 -> 0.016/0.02
  chest.breast       40 -> 0   thickness 0.1 -> 0.033, levels 3 -> 2 (0.0493); cut depths to 0.012-0.018
  chest.pectoral     22 -> 0   levels 3 -> 2 (0.099 against 0.08)
  chest.sternum_low   8 -> 0   levels 2 -> 1 (0.1325 against 0.08)
  chest.lame1         4 -> 0   levels 2 -> 1 (0.1179 against 0.06)
  chest.lame2         8 -> 0   levels 2 -> 1 (0.0919 against 0.06)
  thigh.plate       140 -> 0   thickness 0.12 -> 0.09, levels 3 -> 2 (0.1176)
chest.sternum (0.08 -> 0.075) and thigh.upper (0.07 -> 0.06) had no fold and stood within 1.16 and 1.08 of their
onsets; both now stand 1.2 clear. The other six were clean and are unchanged. On the built Seraph: 0 of 23.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 12:47:13 +01:00
commit a83237b82f
2 changed files with 75 additions and 32 deletions

View file

@ -53,6 +53,7 @@ from mathutils.bvhtree import BVHTree
SURFACE = Path(os.environ["BROKKR_SURFACE"]) if os.environ.get("BROKKR_SURFACE") else Path(__file__).resolve().parents[2] # the add-on tree: a cut's worktree when set
FLIP = Matrix.Diagonal((-1.0, 1.0, -1.0, 1.0))
SHELLS = {}
FOLD_MARGIN = 1.4 # a shell whose fold estimate stands under this much of its thickness is printed (docs/kitbash.md, Thickness at a crease)
MATS = {}
KB = None
@ -665,25 +666,61 @@ def shell(name, rings, host, closed=True, thickness=0.05, levels=2, mat="plate_w
return obj
STRETCH = {} # shell name -> the diagonal part of its Build's to_host, which shell_action wrote into the sheet's points
def _turn_and_stretch(name, to_host):
"""to_host as (turn, stretch): a 4x4 that only turns and moves, and a diagonal 3x3 (a size along each of the
sheet's own axes, x negative for a mirror), with to_host = turn @ stretch. A to_host whose axes are not square to
each other is a shear, which no stretch along the sheet's axes makes: refused, naming the axes and their angle."""
linear = to_host.to_3x3()
axes = [linear.col[k].copy() for k in range(3)]
if min(axis.length for axis in axes) < 1e-9:
raise SystemExit(f"shell {name}: the build's to_host flattens the component (an axis of length 0).")
for a, b in ((0, 1), (0, 2), (1, 2)):
cosine = axes[a].normalized().dot(axes[b].normalized())
if abs(cosine) > 1e-6:
raise SystemExit(f"shell {name}: the build's to_host shears: it carries the component's {'xyz'[a]} and {'xyz'[b]} axes to {math.degrees(math.acos(cosine)):.4f} degrees "
"apart, not 90. A shell takes a to_host that turns, moves, mirrors and sizes it along its own axes; write the slant into the sheet's points.")
sizes = [axis.length for axis in axes]
if linear.determinant() < 0:
sizes[0] = -sizes[0] # a mirror, kept as the sheet's x reversed: what is left only turns
turn = Matrix([axes[k] / sizes[k] for k in range(3)]).transposed().to_4x4()
turn.translation = to_host.translation
return turn, Matrix.Diagonal(sizes)
def shell_action(name, sheet, build, mat, thickness=0.05, offset=-1.0, levels=3, bevel=0.0):
"""A faceted, hollow plate by brokkr_kitbash.shell on a Build's host: `sheet` is its document ({rings, closed,
mirror, creases, rim, flip}) in the component's frame. The shell is parented to build.host and stands at
build.to_host, as Build.done puts a Geo. A to_host that scales or mirrors is refused: the kitbash actions cut and
rib only an unscaled object. Cut it with cuts_action, frame it with ribs_action. The action owns the cage:
nothing here builds geometry."""
to_host = Matrix.Identity(4) if build.to_host is None else Matrix(build.to_host)
turn = to_host.to_3x3()
if max(abs(v) for row in (turn @ turn.transposed() - Matrix.Identity(3)) for v in row) > 1e-6 or turn.determinant() < 0:
raise SystemExit(f"shell {name}: the build's to_host scales or mirrors (determinant {turn.determinant():.4g}); brokkr_kitbash cuts and ribs only an "
"unscaled shell. Write the sheet at its size and on its side, and give the Build a to_host that only turns and moves.")
mirror, creases, rim, flip}) in the component's frame. The shell is parented to build.host and stands where
Build.done puts a Geo: the turn and move of build.to_host are the object's matrix, and its sizes and mirror are
written into the ring points, since the kitbash actions cut and rib only an unscaled object. A mirror reverses
`flip`, so the wall stays on the plate's inside; on a sheet that is itself mirrored about x it changes nothing. A
to_host that shears is refused. thickness, bevel, and the sizes of cutters and ribs are metres as stated, at
any to_host. Cut it with cuts_action, frame it with ribs_action: both take rays and planes in the component's
frame. The action owns the cage: nothing here builds geometry. Prints the action's fold estimate when the wall
is expected to fold (docs/kitbash.md, Thickness at a crease)."""
turn, stretch = _turn_and_stretch(name, Matrix.Identity(4) if build.to_host is None else Matrix(build.to_host))
sx, sy, sz = (stretch[k][k] for k in range(3))
sheet = dict(sheet)
if sheet.get("mirror"):
sheet["rings"] = [[[abs(sx) * p[0], sy * p[1], sz * p[2]] for p in ring] for ring in sheet["rings"]] # the cage is its own mirror image about x
else:
sheet["rings"] = [[[sx * p[0], sy * p[1], sz * p[2]] for p in ring] for ring in sheet["rings"]]
if sx < 0:
sheet["flip"] = not sheet.get("flip", False)
result = bpy.ops.brokkr_kitbash.shell(object_name=name, sheet=json.dumps(sheet), thickness=thickness, offset=offset, levels=levels, bevel=bevel)
if "FINISHED" not in result:
raise SystemExit(f"shell {name}: {result}")
fold = json.loads(getattr(bpy.context.window_manager, KB.RESULT))["fold"]
if fold is not None and fold["margin"] < FOLD_MARGIN:
print(f"FOLD {name}: thickness {thickness:g} at levels {levels} is {1 / fold['margin']:.2f} of the fold onset {fold['onset']:.4g} at cage edge {fold['edge']} (crease {fold['weight']:g})", flush=True)
obj = bpy.data.objects[name]
if build.host is not None:
obj.parent = build.host
obj.matrix_parent_inverse = Matrix.Identity(4)
obj.matrix_local = to_host
obj.matrix_local = turn
STRETCH[name] = stretch
assign(obj, mat)
update()
return obj
@ -691,7 +728,10 @@ def shell_action(name, sheet, build, mat, thickness=0.05, offset=-1.0, levels=3,
def cuts_action(name, cuts):
"""Panel lines, insets and rim notches on a shell by brokkr_kitbash.cut_many: `cuts` is its list, rays in the
shell's frame. The cutters stay as the shell's children, hidden from the render."""
component's frame (carried into the shell's by the stretch shell_action wrote into it; cutter sizes are metres
as stated). The cutters stay as the shell's children, hidden from the render."""
stretch = STRETCH[name]
cuts = [{**cut, **{key: list(stretch @ Vector(cut[key])) for key in ("origin", "direction", "up") if key in cut}} for cut in cuts]
result = bpy.ops.brokkr_kitbash.cut_many(object_name=name, cuts=json.dumps(cuts))
if "FINISHED" not in result:
raise SystemExit(f"cuts on {name}: {result}")
@ -701,7 +741,10 @@ def cuts_action(name, cuts):
def ribs_action(name, planes, mat="gunmetal", **sizes):
"""The frame under a shell by brokkr_kitbash.ribs: planes [{origin, normal}] in the shell's frame."""
"""The frame under a shell by brokkr_kitbash.ribs: planes [{origin, normal}] in the component's frame (a plane's
normal is carried by the stretch's inverse, as a plane's is)."""
stretch = STRETCH[name]
planes = [{**plane, "origin": list(stretch @ Vector(plane["origin"])), "normal": list((stretch.inverted() @ Vector(plane["normal"])).normalized())} for plane in planes]
result = bpy.ops.brokkr_kitbash.ribs(object_name=name, ribs_name=name + ".ribs", planes=json.dumps(planes), **sizes)
if "FINISHED" not in result:
raise SystemExit(f"ribs on {name}: {result}")

View file

@ -323,20 +323,20 @@ def chest(b):
"creases": [{"column": 1, "from": 0, "to": 3, "weight": 1.0}, {"column": 3, "from": 0, "to": 3, "weight": 1.0}, {"ring": 2, "from": 0, "to": 4, "weight": 1.0},
{"ring": 3, "from": 0, "to": 4, "weight": 0.8}, {"column": 2, "from": 0, "to": 3, "weight": 0.6}, {"ring": 1, "from": 0, "to": 1, "weight": 0.6}]}
name = b.name + ".breast"
M.shell_action(name, breast, b, "khaki", thickness=0.1, levels=3, bevel=0.012)
M.shell_action(name, breast, b, "khaki", thickness=0.033, levels=2, bevel=0.012)
upper = {"direction": [0, -1.0, -1.0]}
M.cuts_action(name, [
{"name": name + ".slot_a", "part": "box", "params": "width=0.2; height=0.3; depth=0.035", "origin": [-0.34, 2.9, 2.55], **upper},
{"name": name + ".slot_b", "part": "box", "params": "width=0.2; height=0.3; depth=0.035", "origin": [-0.08, 2.9, 2.55], **upper},
{"name": name + ".slot_c", "part": "slot", "params": "width=0.36; height=0.07; depth=0.03", "origin": [0.3, 2.8, 2.45], **upper},
{"name": name + ".break", "part": "slab", "params": "gap=0.022; length=0.84; depth=0.03", "origin": [0, 3, -0.2], "direction": [0, -1, 0], "up": [1, 0, 0]},
{"name": name + ".seam", "part": "slab", "params": "gap=0.02; length=0.74; depth=0.03", "origin": [1.62, 3, -0.02], "direction": [-0.4, -1, 0], "up": [0.3, 0, 1]},
{"name": name + ".mark", "part": "cyl", "params": "r=0.075; depth=0.02", "origin": [2.2, 3, -0.16], "direction": [-0.4, -1, 0]},
{"name": name + ".flank", "part": "slab", "params": "gap=0.02; length=0.7; depth=0.03", "origin": [-3, 0.2, 0.0], "direction": [1, 0, 0], "up": [0, 0, 1]},
{"name": name + ".slot_a", "part": "box", "params": "width=0.2; height=0.3; depth=0.018", "origin": [-0.34, 2.9, 2.55], **upper},
{"name": name + ".slot_b", "part": "box", "params": "width=0.2; height=0.3; depth=0.018", "origin": [-0.08, 2.9, 2.55], **upper},
{"name": name + ".slot_c", "part": "slot", "params": "width=0.36; height=0.07; depth=0.016", "origin": [0.3, 2.8, 2.45], **upper},
{"name": name + ".break", "part": "slab", "params": "gap=0.022; length=0.84; depth=0.016", "origin": [0, 3, -0.2], "direction": [0, -1, 0], "up": [1, 0, 0]},
{"name": name + ".seam", "part": "slab", "params": "gap=0.02; length=0.74; depth=0.016", "origin": [1.62, 3, -0.02], "direction": [-0.4, -1, 0], "up": [0.3, 0, 1]},
{"name": name + ".mark", "part": "cyl", "params": "r=0.075; depth=0.012", "origin": [2.2, 3, -0.16], "direction": [-0.4, -1, 0]},
{"name": name + ".flank", "part": "slab", "params": "gap=0.02; length=0.7; depth=0.016", "origin": [-3, 0.2, 0.0], "direction": [1, 0, 0], "up": [0, 0, 1]},
])
block = b.name + ".pectoral" # the left pectoral block
M.shell_action(block, block_sheet([[(-0.66, 1.62, -0.26), (-1.5, 1.2, -0.3)], [(-0.68, 1.5, 0.5), (-1.5, 1.1, 0.46)]],
[[(-0.6, 1.1, -0.36), (-1.66, 0.56, -0.4)], [(-0.62, 0.9, 0.62), (-1.66, 0.4, 0.56)]]), b, "khaki", thickness=0.08, levels=3, bevel=0.012)
[[(-0.6, 1.1, -0.36), (-1.66, 0.56, -0.4)], [(-0.62, 0.9, 0.62), (-1.66, 0.4, 0.56)]]), b, "khaki", thickness=0.08, levels=2, bevel=0.012)
M.cuts_action(block, [{"name": block + ".panel", "part": "box", "params": "width=0.2; height=0.34; depth=0.03", "origin": [-1.28, 3, 0.12], "direction": [0, -1, 0]},
{"name": block + ".line", "part": "slab", "params": "gap=0.02; length=0.5; depth=0.025", "origin": [-0.9, 3, 0.12], "direction": [0, -1, 0], "up": [0, 0, 1]}])
for j in range(5):
@ -344,15 +344,15 @@ def chest(b):
d.box(T((0, 1.12, -0.58)), (1.1, 0.1, 0.12))
sternum = lambda x0, y0, z0, x1, y1, z1: {"mirror": True, "flip": True, "rings": [ # noqa: E731 a hung block: a front face and a flank each side
[[0, y1, z1], [x1, y1, z1], [x1, 0.7, z1]], [[0, y0, z0], [x0, y0, z0], [x0, 0.7, z0]]], "creases": [{"column": 1, "from": 0, "to": 1, "weight": 1.0}]}
M.shell_action(b.name + ".sternum", sternum(0.42, 1.22, -0.5, 0.36, 1.16, -0.95), b, "khaki", thickness=0.08, levels=2, bevel=0.012)
M.shell_action(b.name + ".sternum_low", sternum(0.3, 1.12, -0.95, 0.24, 1.04, -1.22), b, "khaki", thickness=0.08, levels=2, bevel=0.012)
M.shell_action(b.name + ".sternum", sternum(0.42, 1.22, -0.5, 0.36, 1.16, -0.95), b, "khaki", thickness=0.075, levels=2, bevel=0.012)
M.shell_action(b.name + ".sternum_low", sternum(0.3, 1.12, -0.95, 0.24, 1.04, -1.22), b, "khaki", thickness=0.08, levels=1, bevel=0.012)
d.hull([(0.6, -0.5, -0.4), (0.6, 0.75, -0.4), (0.45, -0.4, -2.3), (0.45, 0.6, -2.3)], mirror=True) # the abdomen column
for j in range(3):
z = -1.36 - 0.3 * j
lame = {"mirror": True, "flip": True, "rings": [[[0, 0.86 - 0.05 * j, z - 0.24], [0.32 - 0.03 * j, 0.86 - 0.05 * j, z - 0.24], [0.32 - 0.03 * j, 0.6, z - 0.26]],
[[0, 0.92 - 0.05 * j, z + 0.02], [0.36 - 0.03 * j, 0.92 - 0.05 * j, z + 0.02], [0.36 - 0.03 * j, 0.6, z]]],
"creases": [{"column": 1, "from": 0, "to": 1, "weight": 1.0}]}
M.shell_action(f"{b.name}.lame{j}", lame, b, "khaki", thickness=0.06, levels=2, bevel=0.01)
M.shell_action(f"{b.name}.lame{j}", lame, b, "khaki", thickness=0.06, levels=1, bevel=0.01)
for s in (-1, 1):
corrugated(d, [(s * 0.95, 0.7, -0.5), (s * 0.85, 0.9, -0.95), (s * 0.62, 0.86, -1.5), (s * 0.5, 0.66, -2.0)], 0.13)
corrugated(d, [(s * 1.25, 0.5, -0.5), (s * 1.1, 0.62, -1.1), (s * 0.7, 0.5, -1.9)], 0.09)
@ -377,16 +377,16 @@ def pauldron(b, arm=True):
"creases": [{"column": 2, "from": 0, "to": 5, "weight": 1.0}, {"ring": 1, "from": 0, "to": 4, "weight": 1.0}, {"ring": 4, "from": 0, "to": 4, "weight": 0.8},
{"column": 1, "from": 1, "to": 4, "weight": 0.5}, {"column": 3, "from": 1, "to": 3, "weight": 0.4}]}
name = b.name + ".cap"
M.shell_action(name, cap, b, "khaki", thickness=0.09, levels=3, bevel=0.012)
M.shell_action(name, cap, b, "khaki", thickness=0.032, levels=2, bevel=0.012)
side = {"direction": [1, 0, 0], "up": [0, 0, 1]}
M.cuts_action(name, [
{"name": name + ".line_a", "part": "slab", "params": "gap=0.024; length=0.95; depth=0.03", "origin": [-3, 0.32, 0.42], **side},
{"name": name + ".line_b", "part": "slab", "params": "gap=0.024; length=0.95; depth=0.03", "origin": [-3, 0.14, 0.42], **side},
{"name": name + ".slot", "part": "box", "params": "width=0.16; height=0.42; depth=0.04", "origin": [-3, 0.66, 0.72], **side},
{"name": name + ".aft", "part": "slab", "params": "gap=0.024; length=1.2; depth=0.03", "origin": [-3, -0.62, 0.3], **side},
{"name": name + ".line_a", "part": "slab", "params": "gap=0.024; length=0.95; depth=0.016", "origin": [-3, 0.32, 0.42], **side},
{"name": name + ".line_b", "part": "slab", "params": "gap=0.024; length=0.95; depth=0.016", "origin": [-3, 0.14, 0.42], **side},
{"name": name + ".slot", "part": "box", "params": "width=0.16; height=0.42; depth=0.02", "origin": [-3, 0.66, 0.72], **side},
{"name": name + ".aft", "part": "slab", "params": "gap=0.024; length=1.2; depth=0.016", "origin": [-3, -0.62, 0.3], **side},
{"name": name + ".notch_a", "part": "box", "params": "width=0.34; height=0.3; depth=0.3", "origin": [-3, 0.12, -0.3], **side}, # through the rim: what is left between is a tab
{"name": name + ".notch_b", "part": "box", "params": "width=0.3; height=0.3; depth=0.3", "origin": [-3, -0.78, -0.3], **side},
{"name": name + ".crown", "part": "slab", "params": "gap=0.022; length=1.5; depth=0.03", "origin": [-0.72, -0.1, 3], "direction": [0, 0, -1], "up": [0, 1, 0]},
{"name": name + ".crown", "part": "slab", "params": "gap=0.022; length=1.5; depth=0.016", "origin": [-0.72, -0.1, 3], "direction": [0, 0, -1], "up": [0, 1, 0]},
])
M.ribs_action(name, [{"origin": [0, y, 0], "normal": [0, 1, 0]} for y in (0.6, -0.05, -0.7)], standoff=0.03, depth=0.14, thickness=0.03, holes=0.34, posts=0.45, post_r=0.022)
band = [[[-1.11, y, 1.244 * s], [-1.242, y, 1.192 * s], [-1.294, y, 1.06 * s]] for y, s in ((0.92, 0.985), (0.3, 1.0), (-0.4, 1.0), (-1.02, 0.975))]
@ -432,7 +432,7 @@ def thigh(b):
"creases": [{"column": 1, "from": 0, "to": 4, "weight": 0.9}, {"column": 2, "from": 0, "to": 4, "weight": 1.0},
{"ring": 1, "from": 0, "to": 3, "weight": 1.0}, {"ring": 2, "from": 0, "to": 3, "weight": 1.0}, {"ring": 3, "from": 0, "to": 3, "weight": 1.0}]}
name = b.name + ".plate"
M.shell_action(name, main, b, "khaki", thickness=0.12, levels=3, bevel=0.012)
M.shell_action(name, main, b, "khaki", thickness=0.09, levels=2, bevel=0.012)
M.cuts_action(name, [{"name": name + ".flank_a", "part": "slab", "params": "gap=0.022; length=0.9; depth=0.03", "origin": [-3, 0.42, 0.4], "direction": [1, 0, 0], "up": [0, 0, 1]},
{"name": name + ".flank_b", "part": "slab", "params": "gap=0.022; length=0.9; depth=0.03", "origin": [3, 0.42, 0.4], "direction": [-1, 0, 0], "up": [0, 0, 1]}])
upper = {"mirror": True, "flip": True, "rings": [ # its lower edge is ring 0: the centre tab is drawn in it
@ -442,7 +442,7 @@ def thigh(b):
[[0, 0.72, 1.22], [0.2, 0.72, 1.22], [0.27, 0.72, 1.22], [0.54, 0.64, 1.22]]],
"creases": [{"ring": 2, "from": 0, "to": 3, "weight": 1.0}, {"column": 2, "from": 0, "to": 3, "weight": 0.35}]}
over = b.name + ".upper"
M.shell_action(over, upper, b, "khaki", thickness=0.07, levels=3, bevel=0.012)
M.shell_action(over, upper, b, "khaki", thickness=0.06, levels=3, bevel=0.012)
M.cuts_action(over, [{"name": over + ".tab", "part": "slab", "params": "gap=0.02; length=0.44; depth=0.025", "origin": [0, 3, -0.04], "direction": [0, -1, 0], "up": [1, 0, 0]}])
tongue = {"mirror": True, "flip": True, "rings": [[[0, 0.775, -1.22], [0.24, 0.775, -1.22], [0.4, 0.69, -1.22]], [[0, 0.79, -0.64], [0.27, 0.79, -0.64], [0.44, 0.7, -0.64]]],
"creases": [{"column": 1, "from": 0, "to": 1, "weight": 0.9}]}