brokkr_kitbash.plates: a row's fittings written into N.fit.<mat> (cut plate-fittings-kit)

Each fits material merges with the panels or bolts of the same material;
every material a fit names is checked before anything is written. The live
test writes a slab with a fit row of every kind on both sides.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-03 17:37:40 +01:00
commit b641b1f557
4 changed files with 147 additions and 9 deletions

View file

@ -61,8 +61,8 @@ that crosses the same pin (it bends with the pin, so it is measured as an obstac
follow-up aetheria-release:follow_up:hose-motion-clearance-from-skinning owes that check).
plates writes hard armour plates. plate.py owns the table (brokkr.plates.v0) and every point of a plate, its panels,
bolts and anchor frames, in the table's frame; this file converts its arrays and nothing else. A plate is a mesh
object on its host under an identity parent inverse, with a child per material for its panels and bolts
bolts, fittings and anchor frames, in the table's frame; this file converts its arrays and nothing else. A plate is a mesh
object on its host under an identity parent inverse, with a child per material for its panels, bolts and fittings
(<plate>.fit.<material>) and an empty per anchor (<plate>.mark.<id>, <plate>.port.<name>, kit_anchor on each). plates
is the one writer of those objects, their Kit Bevels, plate_kind and kit_plate. kit_plate is the checked row, kept as
a record: its presence admits a rebuild in place and nothing reads it to decide geometry. A plate is no kit part:
@ -2698,7 +2698,9 @@ class BROKKR_KITBASH_OT_plates(PolishOperator):
rebuild, or None), fits [(name, material, holds panels, meshes)], anchors [(name, record, matrix)], stale (the
plate's fit children and anchors this call no longer makes)}. `taken` is every name the call has planned."""
name, path, clad = self.prefix + entry["name"], f"table.plates[{entry['row']}]", row["clad"]
for key, material in (("mat", row["mat"]),) + ((("clad.mat", clad["mat"]), ("clad.bolt_mat", clad["bolt_mat"])) if clad else ()):
named = [("mat", row["mat"])] + ([("clad.mat", clad["mat"]), ("clad.bolt_mat", clad["bolt_mat"])] if clad else [])
named += [(f"fits[{j}].{key}", fit[key]) for j, fit in enumerate(row["fits"]) for key in ("mat", "bolt_mat") if key in fit]
for key, material in named:
if material not in bpy.data.materials:
raise Refused(f"{path}.{key}: no material named {material!r}; make it first (createMaterial); nothing changed.")
obj = bpy.data.objects.get(name)
@ -2713,6 +2715,8 @@ class BROKKR_KITBASH_OT_plates(PolishOperator):
if len(mesh[1]):
held = fits.setdefault(f"{name}.fit.{material}", [material, False, []])
held[1], held[2] = held[1] or panels, held[2] + [mesh]
for material, mesh in entry["fits"].items():
fits.setdefault(f"{name}.fit.{material}", [material, False, []])[2].append(mesh)
anchors = []
for anchor in entry["anchors"]:
record = {"kind": anchor["kind"], "id": anchor["name"], "height": anchor["height"]} if anchor["kind"] == "mark" else {"kind": anchor["kind"], "name": anchor["name"]}

View file

@ -1004,7 +1004,7 @@
},
{
"name": "brokkr_kitbash.plates",
"doc": "Write a table of hard armour plates into the scene. table is a brokkr.plates.v0 document as JSON (docs/kitbash.md, Hard plates): {\"schema\": \"brokkr.plates.v0\", \"plates\": [row, ...]}, each row a convex faceted solid with optional clad (raised panels and their bolts) and fits (anchors on its face). The table's coordinates are metres in frame: a JSON 4x4 of rows in the world, rigid; empty, the host's world matrix, or the world with no host. side 1 builds the table as written and -1 mirrored across its x = 0. Each built plate is a mesh object named prefix + its name (.R and .L on a two-sided row), every face flat, parented to host under an identity parent inverse, with material mat, a Kit Bevel of the row's bevel (angle 12 degrees) and the properties plate_kind \"hard\" and kit_plate (its checked row, a record). Its panels are the child <plate>.fit.<clad mat> and its bolts <plate>.fit.<clad bolt_mat>, one mesh per material, made only when not empty; a child that holds panels carries a Kit Bevel of clad.bevel (angle 20 degrees, one segment). Each anchor is an empty child at the anchor's frame: <plate>.mark.<id> with kit_anchor {kind, id, height}, <plate>.port.<name> with kit_anchor {kind, name}; brokkr_kitbash.hose takes a port empty's name as an end and leaves along its z. An object that carries kit_plate under a made name is rebuilt in place: it keeps its identity, its other children and its modifiers; its fit children are rewritten, made or removed, its anchors moved, and one the row no longer names removed. A plate is no kit part: joints and report do not list it, and a roll of its host carries it. Every material must exist (createMaterial). Refuses before it writes anything: a table the format refuses (the path is named), a missing material (named with its path), a host that is missing, scaled, mirrored or sheared, a frame that is not a rigid 4x4, a made name of over 63 bytes or taken by an object that is not this plate's, a frozen plate or one sharing its mesh, and a report over 16000 characters. Reports plates [{name, rebuilt, corners, facets, panels, bolts, anchors (the empties' names)}], host and side.",
"doc": "Write a table of hard armour plates into the scene. table is a brokkr.plates.v0 document as JSON (docs/kitbash.md, Hard plates): {\"schema\": \"brokkr.plates.v0\", \"plates\": [row, ...]}, each row a convex faceted solid with optional clad (raised panels and their bolts) and fits (anchors on its face, and fittings: parts of the fittings kit, rim bolts and steps). The table's coordinates are metres in frame: a JSON 4x4 of rows in the world, rigid; empty, the host's world matrix, or the world with no host. side 1 builds the table as written and -1 mirrored across its x = 0. Each built plate is a mesh object named prefix + its name (.R and .L on a two-sided row), every face flat, parented to host under an identity parent inverse, with material mat, a Kit Bevel of the row's bevel (angle 12 degrees) and the properties plate_kind \"hard\" and kit_plate (its checked row, a record). Its panels are the child <plate>.fit.<clad mat>, its bolts <plate>.fit.<clad bolt_mat> and each fitting <plate>.fit.<the fit's mat>, one mesh per material, made only when not empty; a child that holds panels carries a Kit Bevel of clad.bevel (angle 20 degrees, one segment). Each anchor is an empty child at the anchor's frame: <plate>.mark.<id> with kit_anchor {kind, id, height}, <plate>.port.<name> with kit_anchor {kind, name}; brokkr_kitbash.hose takes a port empty's name as an end and leaves along its z. An object that carries kit_plate under a made name is rebuilt in place: it keeps its identity, its other children and its modifiers; its fit children are rewritten, made or removed, its anchors moved, and one the row no longer names removed. A plate is no kit part: joints and report do not list it, and a roll of its host carries it. Every material must exist (createMaterial). Refuses before it writes anything: a table the format refuses (the path is named), a missing material (named with its path), a host that is missing, scaled, mirrored or sheared, a frame that is not a rigid 4x4, a made name of over 63 bytes or taken by an object that is not this plate's, a frozen plate or one sharing its mesh, and a report over 16000 characters. Reports plates [{name, rebuilt, corners, facets, panels, bolts, anchors (the empties' names)}], host and side.",
"changesScene": true,
"editModeSafe": false,
"result": "brokkr_mesh_polish_result",

View file

@ -1,8 +1,8 @@
"""Live proof, in a background Blender, of brokkr_kitbash.plates through run_intent: a plate table written onto a
mechanical-kit link under a pin, each plate's mesh, fit children and anchor empties against plate.build's own answer
under the frame, the Kit Bevels, joints unchanged by the plates, a roll of the pin carrying every plate, a hose between
two port empties either side of the pin across its range, a rebuild in place, and each refusal leaving the scene as it
was. Not part of the unittest run: it needs Blender.
two port empties either side of the pin across its range, a rebuild in place, each refusal leaving the scene as it
was, and a slab with a fit row of every kind written into a child per material. Not part of the unittest run: it needs Blender.
blender --background --factory-startup --python-exit-code 1 --python surfaces/blender/tests/live/kitbash_plates.py -- <out>
@ -67,7 +67,8 @@ COUNT, SECTION = [0], ["setup"]
# origin; X4 a plate written with no parent; X5 the host's inverse as the parent inverse; X6 a kept anchor not moved; X7
# the plate's Kit Bevel at shell's 30 degrees; X8 the panels' at 12; X9 a fit child parented to the host; X10 an
# anchor's basis under the frame again; X11 stale children kept; X12 no sharp_face written; X13 no material refusal;
# X14 no refusal of a taken child or anchor name.
# X14 no refusal of a taken child or anchor name; X15 a row's fittings not written (plan leaves entry["fits"] out); X16 no
# refusal of a fit's missing material.
#
# Metres between a written vertex in the world (the object's matrix_world on its mesh's own coordinates) and the same
# vertex of plate.build's answer under the frame this script holds, over every plate and fit child of the suite; inf
@ -183,12 +184,14 @@ def bevel(obj):
def fits_of(entry, row):
"""{material: [meshes]} of what a built entry's fit children hold, panels before bolts."""
"""{material: [meshes]} of what a built entry's fit children hold: panels, bolts, then the row's fittings."""
held = {}
if row["clad"]:
for material, mesh in ((row["clad"]["mat"], entry["panels"]), (row["clad"]["bolt_mat"], entry["bolts"])):
if len(mesh[1]):
held.setdefault(material, []).append(mesh)
for material, mesh in entry["fits"].items():
held.setdefault(material, []).append(mesh)
return held
@ -219,7 +222,7 @@ def proven(label, document, side, prefix, host, frame, report):
if child is None or child.parent != obj:
facts[f"fit {material}"] = False
continue
panels = material == row["clad"]["mat"]
panels = bool(row["clad"]) and material == row["clad"]["mat"]
facts[f"fit {material}"] = (reading("written", written(child, frame, parts)) < WRITTEN and np.array_equal(np.array(child.matrix_basis), np.eye(4))
and np.array_equal(np.array(child.matrix_parent_inverse), np.eye(4)) and [s.material.name for s in child.material_slots] == [material]
and bevel(child) == ((round(row["clad"]["bevel"], 6), 20.0, 1, "ANGLE") if panels and row["clad"]["bevel"] > 0 else None))
@ -428,6 +431,49 @@ try:
bpy.context.view_layer.update()
check("thawed, the plate is rebuilt", receipt["status"] == "accepted" and report["plates"][0]["rebuilt"], [receipt["status"], receipt["message"]])
proven("the thawed plate", THIGH, 1, "Thigh.", thigh, world(thigh), report)
section("fittings")
for name in ("pit", "machine"):
bpy.data.materials.new(name)
KIT = slab("Kit", [0.0, -0.3, 0.3], ("feed", [0.0, 0.1]))
KIT["sides"] = "both"
KIT["fits"] += [{"kind": "bolts", "inset": 0.012, "spacing": 0.08, "params": "r=0.006", "mat": "gunmetal"},
{"kind": "part", "part": "slot", "at": [0.0, 0.18], "params": "w=0.08; h=0.02", "mat": "khaki"},
{"kind": "part", "part": "pit", "at": [0.0, 0.18], "params": "w=0.08; h=0.02", "mat": "pit"},
{"kind": "part", "part": "vents", "at": [-0.06, 0.03], "params": "w=0.06; h=0.012; count=3", "mat": "khaki"},
{"kind": "part", "part": "pit", "at": [-0.06, 0.03], "params": "w=0.06; h=0.012; depth=0.01; count=3; pitch=0.0324", "mat": "pit"},
{"kind": "part", "part": "access_port", "at": [0.07, -0.1], "params": "r=0.03", "mat": "machine"},
{"kind": "part", "part": "port_bolts", "at": [0.07, -0.1], "params": "r=0.03", "mat": "gunmetal"},
{"kind": "part", "part": "handle", "at": [-0.07, -0.1], "roll": 90.0, "params": "length=0.1; lift=0.04; r=0.004", "mat": "gunmetal"},
{"kind": "part", "part": "eye", "at": [0.08, 0.12], "lift": 0.002, "params": "size=0.03", "mat": "gunmetal"},
{"kind": "part", "part": "louvres", "at": [0.0, -0.18], "params": "w=0.1; h=0.1; n=3; depth=0.02; frame=0.02", "mat": "steel"},
{"kind": "step", "outline": [[-0.1, -0.06], [0.1, -0.06], [0.1, 0.06], [-0.1, 0.06]], "at": [0.0, 0.0], "lift": 0.012, "mat": "olive_light", "bolt_mat": "steel"}]
FITS = doc(KIT)
before = scene_state()
refused("a fit whose material is not in the file", call(doc({**KIT, "fits": KIT["fits"] + [{"kind": "part", "part": "bolt", "at": [0, 0], "mat": "brass"}]}), prefix="Fit."), "table.plates[0].fits[13].mat: no material named 'brass'")
refused("a step whose bolts' material is not in the file", call(doc({**KIT, "fits": [{**KIT["fits"][-1], "bolt_mat": "brass"}]}), prefix="Fit."), "table.plates[0].fits[0].bolt_mat: no material named 'brass'")
refused("a part the fittings kit does not have", call(doc({**KIT, "fits": [{"kind": "part", "part": "rivet", "at": [0, 0], "mat": "steel"}]}), prefix="Fit."), "table: plates[0].fits[0].part: 'rivet' is no part of the fittings kit")
check("refused, the fittings call left the scene as it was", scene_state() == before)
receipt, report = send("brokkr_kitbash.plates", host="Thigh", prefix="Fit.", table=json.dumps(FITS))
bpy.context.view_layer.update()
check("a slab with a fit row of every kind is accepted", receipt["status"] == "accepted", [receipt["status"], receipt["message"]])
R["reports"]["fittings"] = report
_, fit_built = proven("a row of every fit kind, on both sides", FITS, 1, "Fit.", thigh, world(thigh), report)
mats = ["gunmetal", "khaki", "machine", "olive_light", "pit", "steel"]
for side in "RL":
kit_plate = bpy.data.objects.get(f"Fit.Kit.{side}")
check(f"fits-written: Kit.{side} has a fit child per material, the fittings beside the panels and their bolts",
kit_plate is not None and sorted(c.name for c in kit_plate.children if c.type == "MESH") == [f"Fit.Kit.{side}.fit.{m}" for m in mats]
and bevel(bpy.data.objects[f"Fit.Kit.{side}.fit.olive_light"]) == (0.012, 20.0, 1, "ANGLE") and bevel(bpy.data.objects[f"Fit.Kit.{side}.fit.pit"]) is None,
kit_plate and sorted(c.name for c in kit_plate.children))
check("the report counts what stands: the rim's bolts, nine parts and a step", report is not None and [row["fits"] for row in report["plates"]] == [fit_built[0]["report"]["fits"]] * 2
and fit_built[0]["report"]["fits"] > 11, report and [row.get("fits") for row in report["plates"]])
BARE = doc({**KIT, "fits": KIT["fits"][:3]})
receipt, report = send("brokkr_kitbash.plates", host="Thigh", prefix="Fit.", table=json.dumps(BARE))
bpy.context.view_layer.update()
proven("rebuilt with the rim's bolts alone", BARE, 1, "Fit.", thigh, world(thigh), report)
check("a rebuild removes the fit children it no longer makes", sorted(c.name for c in bpy.data.objects["Fit.Kit.R"].children if c.type == "MESH") == ["Fit.Kit.R.fit.gunmetal", "Fit.Kit.R.fit.olive_light"]
and "Fit.Kit.R.fit.pit" not in bpy.data.objects, sorted(c.name for c in bpy.data.objects["Fit.Kit.R"].children))
except Exception: # noqa: BLE001 whatever it was, it is a failed check with a name, not a missing result file
check(f"no uncaught error in section: {SECTION[0]}", False, traceback.format_exc().splitlines()[-6:])
finally:

View file

@ -270,6 +270,61 @@
"name": "written-is-built: the thawed plate",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: a fit whose material is not in the file",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: a step whose bolts' material is not in the file",
"ok": true,
"detail": null
},
{
"name": "refused, scene unchanged: a part the fittings kit does not have",
"ok": true,
"detail": null
},
{
"name": "refused, the fittings call left the scene as it was",
"ok": true,
"detail": null
},
{
"name": "a slab with a fit row of every kind is accepted",
"ok": true,
"detail": null
},
{
"name": "written-is-built: a row of every fit kind, on both sides",
"ok": true,
"detail": null
},
{
"name": "fits-written: Kit.R has a fit child per material, the fittings beside the panels and their bolts",
"ok": true,
"detail": null
},
{
"name": "fits-written: Kit.L has a fit child per material, the fittings beside the panels and their bolts",
"ok": true,
"detail": null
},
{
"name": "the report counts what stands: the rim's bolts, nine parts and a step",
"ok": true,
"detail": null
},
{
"name": "written-is-built: rebuilt with the rim's bolts alone",
"ok": true,
"detail": null
},
{
"name": "a rebuild removes the fit children it no longer makes",
"ok": true,
"detail": null
}
],
"hostErrors": [],
@ -290,6 +345,7 @@
"facets": 10,
"panels": 1,
"bolts": 8,
"fits": 0,
"anchors": [
"Thigh.Guard.port.feed",
"Thigh.Guard.mark.num"
@ -341,6 +397,38 @@
0.056641
]
}
},
"fittings": {
"plates": [
{
"name": "Fit.Kit.R",
"rebuilt": false,
"corners": 16,
"facets": 10,
"panels": 1,
"bolts": 8,
"fits": 26,
"anchors": [
"Fit.Kit.R.port.feed",
"Fit.Kit.R.mark.num"
]
},
{
"name": "Fit.Kit.L",
"rebuilt": false,
"corners": 16,
"facets": 10,
"panels": 1,
"bolts": 8,
"fits": 26,
"anchors": [
"Fit.Kit.L.port.feed",
"Fit.Kit.L.mark.num"
]
}
],
"host": "Thigh",
"side": 1
}
},
"ok": true