diff --git a/surfaces/blender/experiments/mechs/mechlib.py b/surfaces/blender/experiments/mechs/mechlib.py index e79b7ea..1d3ba6c 100644 --- a/surfaces/blender/experiments/mechs/mechlib.py +++ b/surfaces/blender/experiments/mechs/mechlib.py @@ -665,16 +665,25 @@ def shell(name, rings, host, closed=True, thickness=0.05, levels=2, mat="plate_w return obj -def shell_action(name, sheet, host, mat, thickness=0.05, offset=-1.0, levels=3, bevel=0.0): - """A faceted, hollow plate by brokkr_kitbash.shell: `sheet` is its document ({rings, closed, mirror, creases, rim, - flip}) in the host's frame. The shell is parented to the host under identity matrices and given `mat`. Cut it - with cuts_action, frame it with ribs_action. The action owns the cage: nothing here builds geometry.""" +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.") 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}") obj = bpy.data.objects[name] - if host is not None: - obj.parent = host + if build.host is not None: + obj.parent = build.host + obj.matrix_parent_inverse = Matrix.Identity(4) + obj.matrix_local = to_host assign(obj, mat) update() return obj diff --git a/surfaces/blender/experiments/mechs/seraph_parts.py b/surfaces/blender/experiments/mechs/seraph_parts.py index b597082..1c178a8 100644 --- a/surfaces/blender/experiments/mechs/seraph_parts.py +++ b/surfaces/blender/experiments/mechs/seraph_parts.py @@ -323,7 +323,7 @@ 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.host, "khaki", thickness=0.1, levels=3, bevel=0.012) + M.shell_action(name, breast, b, "khaki", thickness=0.1, levels=3, 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}, @@ -336,7 +336,7 @@ def chest(b): ]) 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.host, "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=3, 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.host, "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.host, "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.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) 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.host, "khaki", thickness=0.06, levels=2, bevel=0.01) + M.shell_action(f"{b.name}.lame{j}", lame, b, "khaki", thickness=0.06, levels=2, 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,7 +377,7 @@ 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.host, "khaki", thickness=0.09, levels=3, bevel=0.012) + M.shell_action(name, cap, b, "khaki", thickness=0.09, levels=3, 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}, @@ -390,13 +390,13 @@ def pauldron(b, arm=True): ]) 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))] - M.shell_action(b.name + ".band", {"rings": band, "creases": [{"column": 1, "from": 0, "to": 3, "weight": 1.0}]}, b.host, "khaki", thickness=0.05, levels=2, bevel=0.008) - M.shell_action(b.name + ".ridge", {"flip": True, "rings": [[[0.352, y, 1.307], [-0.143, y, 1.511]] for y in (-0.6, 0.2)]}, b.host, "khaki", thickness=0.07, levels=1, bevel=0.01) + M.shell_action(b.name + ".band", {"rings": band, "creases": [{"column": 1, "from": 0, "to": 3, "weight": 1.0}]}, b, "khaki", thickness=0.05, levels=2, bevel=0.008) + M.shell_action(b.name + ".ridge", {"flip": True, "rings": [[[0.352, y, 1.307], [-0.143, y, 1.511]] for y in (-0.6, 0.2)]}, b, "khaki", thickness=0.07, levels=1, bevel=0.01) rows = (((-0.25, -0.6), (0.2, -0.76), (0.62, -0.66)), ((-0.72, -0.3), (0.15, -0.32), (1.0, -0.3)), ((-0.75, 0.35), (0.15, 0.38), (1.05, 0.42)), ((-0.5, 0.62), (0.15, 0.74), (0.82, 0.84))) shield = {"rings": [[[-0.45 - u, 1.4 - 0.1 * v + (0.07, 0.14, -0.3)[j], 0.3 + v] for j, (u, v) in enumerate(row)] for row in rows], # u runs outboard, v up "creases": [{"column": 1, "from": 0, "to": 3, "weight": 0.9}, {"ring": 1, "from": 0, "to": 2, "weight": 0.5}, {"ring": 2, "from": 0, "to": 2, "weight": 0.5}]} plate = b.name + ".shield" - M.shell_action(plate, shield, b.host, "khaki", thickness=0.08, levels=3, bevel=0.012) + M.shell_action(plate, shield, b, "khaki", thickness=0.08, levels=3, bevel=0.012) M.cuts_action(plate, [{"name": plate + ".bracket", "part": "slot", "params": "width=0.3; height=0.06; depth=0.03", "origin": [-0.62, 3, -0.2], "direction": [0, -1, 0]}, {"name": plate + ".bolt", "part": "cyl", "params": "r=0.05; depth=0.03", "origin": [-1.05, 3, 0.02], "direction": [0, -1, 0]}]) if arm: @@ -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.host, "khaki", thickness=0.12, levels=3, bevel=0.012) + M.shell_action(name, main, b, "khaki", thickness=0.12, levels=3, 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,15 +442,15 @@ 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.host, "khaki", thickness=0.07, levels=3, bevel=0.012) + M.shell_action(over, upper, b, "khaki", thickness=0.07, 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}]} - M.shell_action(b.name + ".tongue", tongue, b.host, "khaki", thickness=0.06, levels=2, bevel=0.01) + M.shell_action(b.name + ".tongue", tongue, b, "khaki", thickness=0.06, levels=2, bevel=0.01) strip = {"rings": [[[-0.88, 0.6, -0.42], [-1.02, 0.2, -0.7], [-1.04, -0.5, -0.6]], [[-0.88, 0.6, 0.3], [-1.03, 0.2, 0.3], [-1.05, -0.5, 0.3]], [[-0.86, 0.6, 1.05], [-1.0, 0.2, 1.0], [-1.02, -0.5, 0.9]]], "creases": [{"column": 1, "from": 0, "to": 2, "weight": 1.0}]} edge = b.name + ".strip" - M.shell_action(edge, strip, b.host, "khaki", thickness=0.1, levels=3, bevel=0.012) + M.shell_action(edge, strip, b, "khaki", thickness=0.1, levels=3, bevel=0.012) M.cuts_action(edge, [{"name": f"{edge}.bolt{j}", "part": "cyl", "params": "r=0.045; depth=0.03", "origin": [-3, -0.15, z], "direction": [1, 0, 0]} for j, z in enumerate((0.6, -0.2))]) d.box(T((0, 0.05, 0)), (0.9, 0.9, 2.9))