|
|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
"""Live proof, in a background Blender, of brokkr_kitbash shell cuts through run_intent: cut on a mesh that is not a kit
|
|
|
|
|
part (a subdivided, solidified cage), the one Boolean modifier per operation and its collection, a cast at the surface
|
|
|
|
|
without its cuts, machinery on a cutter's floor socket and what moves when the cutter moves or is resized, boolean on
|
|
|
|
|
any mesh, the refusals, cut_many, a cutter's axis, a slot's three floors, an object in no collection, and the order of a set_params report's closures. Not part of the
|
|
|
|
|
unittest run: it needs Blender.
|
|
|
|
|
any mesh, the refusals, cut_many, a cutter's axis, a slot's three floors, an object in no collection or one Blender does not evaluate, a receipt's rows trimmed
|
|
|
|
|
to fit, and the order of a set_params report's closures. Not part of the unittest run: it needs Blender.
|
|
|
|
|
|
|
|
|
|
blender --background --factory-startup --python-exit-code 1 --python surfaces/blender/tests/live/kitbash_shell.py -- <out>
|
|
|
|
|
|
|
|
|
|
@ -11,6 +11,9 @@ without them). <out> is an absolute path; writes <out>.result.json and exits 1 w
|
|
|
|
|
|
|
|
|
|
Bounds follow lodur:ruling:deterministic-bound-margin: each sits at the geometric mean of the shipped worst reading
|
|
|
|
|
and the least claimed mutant's, both written beside it; the result file carries the readings.
|
|
|
|
|
|
|
|
|
|
The checks run inside one try: an uncaught error is a failed check that names the section it happened in, and the
|
|
|
|
|
result file is written and the checks printed whatever happened.
|
|
|
|
|
"""
|
|
|
|
|
import importlib.util
|
|
|
|
|
import json
|
|
|
|
|
@ -18,6 +21,7 @@ import math
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import tempfile
|
|
|
|
|
import traceback
|
|
|
|
|
import types
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
@ -160,123 +164,15 @@ def stack(obj):
|
|
|
|
|
return [m.name for m in obj.modifiers]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --- a cage: not a kit part. A closed loft of 6 rings of 8, subdivided and given a wall ----------------------------------
|
|
|
|
|
bm = bmesh.new()
|
|
|
|
|
rings = [[bm.verts.new((r * math.cos(math.pi / 8 + k * math.pi / 4), r * math.sin(math.pi / 8 + k * math.pi / 4), z)) for k in range(8)]
|
|
|
|
|
for z, r in ((-1.0, 0.5), (-0.6, 0.7), (-0.2, 0.8), (0.2, 0.8), (0.6, 0.7), (1.0, 0.5))]
|
|
|
|
|
for low, high in zip(rings, rings[1:]):
|
|
|
|
|
for k in range(8):
|
|
|
|
|
bm.faces.new((low[k], low[(k + 1) % 8], high[(k + 1) % 8], high[k]))
|
|
|
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:])
|
|
|
|
|
mesh = bpy.data.meshes.new("Cage")
|
|
|
|
|
bm.to_mesh(mesh)
|
|
|
|
|
bm.free()
|
|
|
|
|
cage = bpy.data.objects.new("Cage", mesh)
|
|
|
|
|
bpy.context.scene.collection.objects.link(cage)
|
|
|
|
|
cage.modifiers.new("Subsurf", "SUBSURF").levels = 2
|
|
|
|
|
wall = cage.modifiers.new("Solidify", "SOLIDIFY")
|
|
|
|
|
wall.thickness, wall.offset, wall.use_even_offset = 0.05, -1.0, True
|
|
|
|
|
cage.matrix_world = Matrix.Translation((4.0, -1.0, 2.0)) @ Matrix.Rotation(0.6, 4, "Z") @ Matrix.Rotation(-0.3, 4, "X")
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
world = np.array(cage.matrix_world, dtype=np.float64)
|
|
|
|
|
uncut, _ = evaluated(cage)
|
|
|
|
|
check("the cage is a closed wall before it is cut", uncut["nonManifoldEdges"] == 0 and 0.15 < uncut["volume"] < 0.4 and "kit_part" not in cage, uncut)
|
|
|
|
|
R["cage"] = {"uncut": uncut}
|
|
|
|
|
SECTION = ["setup"]
|
|
|
|
|
|
|
|
|
|
# --- cut-at-ray: a through bay, a blind round recess, a row of gills and a panel break --------------------------------------
|
|
|
|
|
CUTS = [("Bay", "box", (3.0, 0.0, 0.1), (-1.0, 0.0, 0.0), "width=0.3; height=0.3; depth=0.2", {}),
|
|
|
|
|
("Recess", "cyl", (-3.0, 0.1, 0.2), (2.0, 0.0, 0.0), "r=0.1; depth=0.02", {}),
|
|
|
|
|
("Gills", "slot", (0.1, 3.0, -0.2), (0.0, -1.0, 0.0), "width=0.3; height=0.04; count=4; pitch=0.08; depth=0.02", {}),
|
|
|
|
|
("Break", "slab", (0.0, -3.0, 0.3), (0.0, 1.0, 0.0), "length=0.6; depth=0.1", {"roll": 90.0})]
|
|
|
|
|
frames, volume, falls, reports = {}, uncut["volume"], [], {}
|
|
|
|
|
for name, part, origin, direction, params, more in CUTS:
|
|
|
|
|
hit, normal = cast(cage, origin, direction) # before this cutter exists; the cuts made so far are far from this ray
|
|
|
|
|
frames[name] = core.surface_frame(hit, normal, (0.0, 0.0, 1.0), more.get("roll", 0.0))
|
|
|
|
|
state = sorted(o.name for o in bpy.data.objects)
|
|
|
|
|
receipt, report = cut(name, part, origin, direction, params, **more)
|
|
|
|
|
reports[name] = report
|
|
|
|
|
cutter = bpy.data.objects.get(name)
|
|
|
|
|
ok = receipt["status"] == "accepted" and cutter is not None and sorted(o.name for o in bpy.data.objects) == sorted(state + [name])
|
|
|
|
|
ok = ok and cutter.parent == cage and np.array_equal(np.array(cutter.matrix_parent_inverse), np.eye(4))
|
|
|
|
|
ok = ok and reading("framed", np.abs(np.array(cutter.matrix_basis) - frames[name]).max()) < FRAMED
|
|
|
|
|
ok = ok and (cutter["kit_kit"], cutter["kit_part"]) == ("cutters", part) and bpy.context.scene.collection in cutter.users_collection
|
|
|
|
|
ok = ok and not cutter.hide_render and not cutter.hide_viewport and len(cutter.modifiers) == 0
|
|
|
|
|
check(f"cut places the {part} cutter {name} on the cage where the ray meets it: parented under an identity inverse, its basis the surface frame",
|
|
|
|
|
ok, [receipt["message"], cutter and np.array(cutter.matrix_basis).tolist(), frames[name].tolist()])
|
|
|
|
|
wanted = world @ frames[name]
|
|
|
|
|
check(f"cut reports {name} as a cutters part with its sockets in the world, and what cuts the cage, without evaluating it", report
|
|
|
|
|
and report["object"] == "Cage" and report["cutter"]["object"] == name and report["cutter"]["kit"] == "cutters" and "evaluated" not in report
|
|
|
|
|
and report["booleans"] == [{"cutter": n, "operation": "DIFFERENCE"} for n in [c[0] for c in CUTS][:len(frames)]]
|
|
|
|
|
and [s["name"] for s in report["cutter"]["sockets"]] == {"slab": [], "slot": ["floor", "floor_l", "floor_r"]}.get(part, ["floor"])
|
|
|
|
|
and (part == "slab" or np.abs(np.array(report["cutter"]["sockets"][0]["matrix"]) - wanted @ core.build(kits["cutters"]["parts"][part], report["cutter"]["params"]).sockets[0]["matrix"]).max() < 1e-4),
|
|
|
|
|
report)
|
|
|
|
|
shown, _ = evaluated(cage)
|
|
|
|
|
falls.append(shown["volume"] < volume - 1e-4 and shown["nonManifoldEdges"] == 0)
|
|
|
|
|
volume = shown["volume"]
|
|
|
|
|
R["cage"][name] = shown
|
|
|
|
|
modifier = cage.modifiers.get("Kit Difference")
|
|
|
|
|
check("four cuts give the cage one Boolean modifier after its own, over one collection of the four cutters in the order they came",
|
|
|
|
|
stack(cage) == ["Subsurf", "Solidify", "Kit Difference"] and modifier is not None
|
|
|
|
|
and (modifier.type, modifier.solver, modifier.use_self, modifier.operation, modifier.operand_type, modifier.material_mode) == ("BOOLEAN", "EXACT", True, "DIFFERENCE", "COLLECTION", "TRANSFER")
|
|
|
|
|
and [o.name for o in modifier.collection.objects] == [c[0] for c in CUTS] and modifier.collection.name == "Cage difference"
|
|
|
|
|
and not any(modifier.collection in s.collection.children_recursive for s in bpy.data.scenes), [stack(cage), modifier and modifier.operand_type])
|
|
|
|
|
check("the evaluated cage stays a closed wall and loses volume with each cut", all(falls) and len(falls) == 4, R["cage"])
|
|
|
|
|
receipt, report = send("brokkr_kitbash.report", object_name="")
|
|
|
|
|
check("report lists the cutters as kit parts and not the cage", report and [p["object"] for p in report["parts"]] == sorted(c[0] for c in CUTS)
|
|
|
|
|
and all(p["connection"] is None and p["baked"] is False for p in report["parts"]), report and [p["object"] for p in report["parts"]])
|
|
|
|
|
|
|
|
|
|
# --- cut-casts-the-uncut-surface --------------------------------------------------------------------------------------------
|
|
|
|
|
through = cast(cage, CUTS[0][2], CUTS[0][3])[0] # as the cage is evaluated now, with its cuts: through the bay to the far wall
|
|
|
|
|
receipt, report = cut("Bay2", "cyl", CUTS[0][2], CUTS[0][3], "r=0.05; depth=0.2")
|
|
|
|
|
again = bpy.data.objects.get("Bay2")
|
|
|
|
|
check("a second cut on the through bay's ray lands where the first did, on the surface as it was before any cut, though the ray now passes through the bay",
|
|
|
|
|
receipt["status"] == "accepted" and again is not None and np.linalg.norm(through - frames["Bay"][:3, 3]) > 1.0
|
|
|
|
|
and reading("recast", np.abs(np.array(again.matrix_basis)[:3, 3] - frames["Bay"][:3, 3]).max()) < RECAST
|
|
|
|
|
and stack(cage) == ["Subsurf", "Solidify", "Kit Difference"] and all(m.show_viewport for m in cage.modifiers),
|
|
|
|
|
[receipt["message"], through.tolist(), frames["Bay"][:3, 3].tolist(), again and list(again.matrix_basis.translation)])
|
|
|
|
|
def section(name):
|
|
|
|
|
SECTION[0] = name
|
|
|
|
|
|
|
|
|
|
# --- floor-carries-machinery ------------------------------------------------------------------------------------------------
|
|
|
|
|
recess = bpy.data.objects["Recess"]
|
|
|
|
|
vent = place("Vent", "vent", "width=0.2; height=0.15") # back size 0.135; the floor's is 0.2
|
|
|
|
|
receipt, report = send("brokkr_kitbash.attach", object_name="Vent", socket="back", parent_name="Recess", parent_socket="floor", roll=30.0)
|
|
|
|
|
floor = world @ frames["Recess"] @ np.array(Matrix.Translation((0.0, 0.0, -0.02))) # the hit point, depth along the normal
|
|
|
|
|
back = frame(vent, "back")
|
|
|
|
|
check("a mechanical vent attaches to the round recess's floor: its back on the hit point taken depth down the normal, facing in, and the connection holds",
|
|
|
|
|
receipt["status"] == "accepted" and held(report) and vent.parent == recess and report["connection"]["parent"] == "Recess" and report["kit"] == "mechanical"
|
|
|
|
|
and reading("floored", max(np.abs(back[:3, 3] - floor[:3, 3]).max(), np.abs(back[:3, 2] + floor[:3, 2]).max())) < FLOORED,
|
|
|
|
|
[receipt["message"], back.tolist(), floor.tolist()])
|
|
|
|
|
big = place("Big", "vent", "width=0.8; height=0.6")
|
|
|
|
|
refused("a vent larger than the recess's floor", "brokkr_kitbash.attach", {"object_name": "Big", "socket": "back", "parent_name": "Recess", "parent_socket": "floor"},
|
|
|
|
|
"'Big' on 'Recess': socket 'back' (mount, size 0.54) and parent socket 'floor' (mount, size 0.2) are mount sockets, where the child fits the parent: it is larger")
|
|
|
|
|
nozzle = place("Nozzle", "nozzle")
|
|
|
|
|
refused("a flange on a floor", "brokkr_kitbash.attach", {"object_name": "Nozzle", "socket": "mount", "parent_name": "Recess", "parent_socket": "floor"}, "are of different types")
|
|
|
|
|
refused("a second part on the floor", "brokkr_kitbash.attach", {"object_name": "Nozzle", "socket": "mount", "parent_name": "Recess", "parent_socket": "floor"}, "'Nozzle' on 'Recess'")
|
|
|
|
|
refused("a part on a slab, which has no floor", "brokkr_kitbash.attach", {"object_name": "Big", "socket": "back", "parent_name": "Break", "parent_socket": "floor"},
|
|
|
|
|
"kit 'cutters' part 'slab' has no socket 'floor'; its sockets: none")
|
|
|
|
|
refused("detach of a cutter, which is placed and not attached", "brokkr_kitbash.detach", {"object_name": "Recess"}, "'Recess' is not attached")
|
|
|
|
|
before = evaluated(cage)[0]
|
|
|
|
|
moved_to = np.array(recess.matrix_basis)[:3, 3] + np.array(recess.matrix_basis)[:3, :3] @ [0.0, 0.25, 0.0] # along the cutter's own y: up the wall
|
|
|
|
|
was = frame(vent, "back")
|
|
|
|
|
send("setObjectTransform", targetObjectName="Recess", location=moved_to.tolist())
|
|
|
|
|
shift = frame(vent, "back")[:3, 3] - was[:3, 3]
|
|
|
|
|
after = evaluated(cage)[0]
|
|
|
|
|
check("setObjectTransform on the cutter moves the cut and the vent on its floor together: the vent still holds, and the cage is cut elsewhere",
|
|
|
|
|
reading("floored", np.abs(shift - world[:3, :3] @ (moved_to - frames["Recess"][:3, 3])).max()) < FLOORED and abs(np.linalg.norm(shift) - 0.25) < 1e-4
|
|
|
|
|
and (connection := send("brokkr_kitbash.report", object_name="Vent")[1]["parts"][0]["connection"])["holds"] is True
|
|
|
|
|
and after["nonManifoldEdges"] == 0 and after != before, [shift.tolist(), before, after])
|
|
|
|
|
was = frame(vent, "back")
|
|
|
|
|
receipt, report = send("brokkr_kitbash.set_params", object_name="Recess", params="depth=0.04")
|
|
|
|
|
sunk = frame(vent, "back")[:3, 3] - was[:3, 3]
|
|
|
|
|
deeper = evaluated(cage)[0]
|
|
|
|
|
check("set_params depth=0.04 on the cutter deepens the cut and seats the vent on the new floor, 0.02 further down the normal",
|
|
|
|
|
receipt["status"] == "accepted" and report["params"]["depth"] == 0.04 and reading("floored", np.abs(sunk + was[:3, 2] * -0.02).max()) < FLOORED
|
|
|
|
|
and send("brokkr_kitbash.report", object_name="Vent")[1]["parts"][0]["connection"]["holds"] is True
|
|
|
|
|
and deeper["volume"] < after["volume"] - 1e-5 and deeper["nonManifoldEdges"] == 0 and stack(cage) == ["Subsurf", "Solidify", "Kit Difference"],
|
|
|
|
|
[receipt["message"], sunk.tolist(), after, deeper])
|
|
|
|
|
R["cage"]["deeper"] = deeper
|
|
|
|
|
|
|
|
|
|
# --- cut_many: several cutters for one evaluation, all or none; an axis; a slot's three floors -----------------------------------
|
|
|
|
|
def uncut_cast(origin, direction):
|
|
|
|
|
"""cast at the cage with its Kit Booleans off: the surface as designed."""
|
|
|
|
|
shown = [m for m in cage.modifiers if m.name.startswith("Kit ")]
|
|
|
|
|
for m in shown:
|
|
|
|
|
m.show_viewport = False
|
|
|
|
|
@ -287,151 +183,358 @@ def uncut_cast(origin, direction):
|
|
|
|
|
m.show_viewport = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MANY = [{"name": "Visor", "part": "slot", "params": "width=0.6; height=0.14; depth=0.02; lift=0.2", "origin": [0.6, 3.0, 0.5], "direction": [0.0, -1.0, 0.0]},
|
|
|
|
|
{"name": "Seam", "part": "slab", "params": "length=0.4; depth=0.1", "origin": [-0.5, -3.0, -0.7], "direction": [0.0, 1.0, 0.0], "up": [1.0, 0.0, 0.0], "axis": [0.0, -1.0, 0.0]},
|
|
|
|
|
{"name": "Port", "part": "cyl", "params": "r=0.05", "origin": [-0.6, 3.0, -0.5], "direction": [0.0, -2.0, 0.0], "up": [1.0, 0.0, 0.0], "roll": 45.0}]
|
|
|
|
|
wanted = {}
|
|
|
|
|
for spec in MANY:
|
|
|
|
|
hit, normal = uncut_cast(spec["origin"], spec["direction"])
|
|
|
|
|
wanted[spec["name"]] = core.surface_frame(hit, spec.get("axis", normal), spec.get("up", (0.0, 0.0, 1.0)), spec.get("roll", 0.0))
|
|
|
|
|
if "axis" in spec:
|
|
|
|
|
lean = float(np.degrees(np.arccos(np.clip(normal @ np.array(spec["axis"]), -1.0, 1.0))))
|
|
|
|
|
refused("cut_many whose second ray misses places none", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([MANY[0], {**MANY[1], "origin": [0.0, -3.0, 5.0]}])},
|
|
|
|
|
"The ray from (0.0, -3.0, 5.0) along (0.0, 1.0, 0.0) misses 'Cage'")
|
|
|
|
|
refused("cut_many with a name twice", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([MANY[0], {**MANY[1], "name": "Visor"}])}, "An object named 'Visor' exists in this call")
|
|
|
|
|
refused("cut_many with a name an object has", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([MANY[0], {**MANY[1], "name": "Bay"}])}, "An object named 'Bay' exists;")
|
|
|
|
|
refused("cut_many whose last cutter has a bad param", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps(MANY[:2] + [{**MANY[2], "params": "r=9"}])}, "param 'r' = 9.0 is outside")
|
|
|
|
|
refused("cut_many of text that is not JSON", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": "[{"}, "cuts is not JSON")
|
|
|
|
|
refused("cut_many of no cutters", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": "[]"}, "cuts must be a JSON array of 1 to 64 cutters")
|
|
|
|
|
refused("cut_many of a cutter with no direction", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{k: v for k, v in MANY[0].items() if k != "direction"}])},
|
|
|
|
|
"cuts[0] must be an object with name, part, origin and direction")
|
|
|
|
|
refused("cut_many of a cutter with a key cut does not have", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{**MANY[0], "operation": "UNION"}])}, "cuts[0] must be an object")
|
|
|
|
|
refused("cut_many of an origin of two numbers", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{**MANY[0], "origin": [0.0, 1.0]}])}, "cuts[0].origin must be three numbers")
|
|
|
|
|
refused("cut_many of a roll of 400", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{**MANY[0], "roll": 400}])}, "cuts[0].roll must be a number from -360 to 360")
|
|
|
|
|
refused("an axis that points into the surface", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{**MANY[1], "axis": [0.0, 1.0, 0.0]}])}, "'Seam': the axis (0.0, 1.0, 0.0) points into the surface")
|
|
|
|
|
addon = sys.modules["brokkr_kitbash"]
|
|
|
|
|
limit = addon.REPORT_LIMIT
|
|
|
|
|
addon.REPORT_LIMIT = 300
|
|
|
|
|
refused("cut_many whose report would not fit a receipt places none", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps(MANY)}, "over the 300 a receipt carries: cut fewer at once")
|
|
|
|
|
addon.REPORT_LIMIT = limit
|
|
|
|
|
receipt, report = send("brokkr_kitbash.cut_many", object_name="Cage", cuts=json.dumps(MANY))
|
|
|
|
|
placed = [bpy.data.objects.get(spec["name"]) for spec in MANY]
|
|
|
|
|
check("cut_many places three cutters in one action, each as cut would: parented under an identity inverse, its basis the surface frame at its own ray on the uncut cage, in the difference collection in order",
|
|
|
|
|
receipt["status"] == "accepted" and all(placed) and report == {"object": "Cage", "cutters": ["Visor", "Seam", "Port"], "booleans": report["booleans"]}
|
|
|
|
|
and [row["cutter"] for row in report["booleans"]] == ["Bay", "Recess", "Gills", "Break", "Bay2", "Visor", "Seam", "Port"]
|
|
|
|
|
and all(c.parent == cage and np.array_equal(np.array(c.matrix_parent_inverse), np.eye(4))
|
|
|
|
|
and reading("framed", np.abs(np.array(c.matrix_basis) - wanted[c.name]).max()) < FRAMED for c in placed)
|
|
|
|
|
and stack(cage) == ["Subsurf", "Solidify", "Kit Difference"] and all(m.show_viewport for m in cage.modifiers) and evaluated(cage)[0]["nonManifoldEdges"] == 0,
|
|
|
|
|
[receipt["message"], report])
|
|
|
|
|
seam = bpy.data.objects["Seam"]
|
|
|
|
|
check("a slab with an axis stands on the axis, not on the wall's normal, which leans from it there", lean > 5.0
|
|
|
|
|
and reading("framed", np.abs(np.array(seam.matrix_basis)[:3, 2] - [0.0, -1.0, 0.0]).max()) < FRAMED, [lean, np.array(seam.matrix_basis).tolist()])
|
|
|
|
|
receipt, report = send("brokkr_kitbash.cut", object_name="Cage", cutter_name="Seam2", part="slab", params="length=0.3; depth=0.1", origin_x=0.5, origin_y=-3.0, origin_z=-0.7,
|
|
|
|
|
direction_x=0.0, direction_y=1.0, direction_z=0.0, up_x=1.0, up_y=0.0, up_z=0.0, axis_x=0.0, axis_y=-1.0, axis_z=0.0)
|
|
|
|
|
check("cut takes the same axis", receipt["status"] == "accepted" and reading("framed", np.abs(np.array(bpy.data.objects["Seam2"].matrix_basis)[:3, 2] - [0.0, -1.0, 0.0]).max()) < FRAMED, receipt["message"])
|
|
|
|
|
visor = bpy.data.objects["Visor"]
|
|
|
|
|
eyes = {}
|
|
|
|
|
for socket, x in (("floor", 0.0), ("floor_l", -0.2), ("floor_r", 0.2)):
|
|
|
|
|
eye = place(f"Eye_{socket}", "vent", "width=0.2; height=0.15") # back size 0.135; each floor's is 0.14
|
|
|
|
|
receipt, report = send("brokkr_kitbash.attach", object_name=eye.name, socket="back", parent_name="Visor", parent_socket=socket)
|
|
|
|
|
there = world @ wanted["Visor"] @ np.array(Matrix.Translation((x, 0.0, -0.02)))
|
|
|
|
|
eyes[socket] = receipt["status"] == "accepted" and held(report) and eye.parent == visor \
|
|
|
|
|
and reading("floored", max(np.abs(frame(eye, "back")[:3, 3] - there[:3, 3]).max(), np.abs(frame(eye, "back")[:3, 2] + there[:3, 2]).max())) < FLOORED
|
|
|
|
|
check("a slot's three floors each take a part: at the centre and a third of the width to each side, all on the slot's one floor plane", all(eyes.values()) and len(eyes) == 3, eyes)
|
|
|
|
|
refused("a second part on a side floor", "brokkr_kitbash.attach", {"object_name": "Nozzle", "socket": "mount", "parent_name": "Visor", "parent_socket": "floor_l"}, "'Nozzle' on 'Visor'")
|
|
|
|
|
refused("a fourth eye on a floor that is taken", "brokkr_kitbash.attach", {"object_name": "Big", "socket": "back", "parent_name": "Visor", "parent_socket": "floor_l"}, "'Big' on 'Visor'")
|
|
|
|
|
def quad(name, location):
|
|
|
|
|
"""A single square face, 1 m, normal +z: a surface with one side."""
|
|
|
|
|
made = bpy.data.objects.new(name, bpy.data.meshes.new(name))
|
|
|
|
|
made.data.from_pydata([(-0.5, -0.5, 0.0), (0.5, -0.5, 0.0), (0.5, 0.5, 0.0), (-0.5, 0.5, 0.0)], [], [(0, 1, 2, 3)])
|
|
|
|
|
bpy.context.scene.collection.objects.link(made)
|
|
|
|
|
made.location = location
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
return made
|
|
|
|
|
|
|
|
|
|
# --- boolean on any mesh, and the order of the three operations -----------------------------------------------------------------
|
|
|
|
|
lump_at = world @ [0.0, 0.0, 1.0, 1.0]
|
|
|
|
|
send("createObject", objectType="MESH", name="Lump", location=lump_at[:3].tolist(), size=0.2)
|
|
|
|
|
receipt, report = send("brokkr_kitbash.boolean", object_name="Cage", cutter="Lump", operation="UNION")
|
|
|
|
|
check("boolean on the cage, which is not a kit part, adds a second modifier after the difference and reports the object, what cuts it and the evaluated mesh",
|
|
|
|
|
receipt["status"] == "accepted" and stack(cage) == ["Subsurf", "Solidify", "Kit Difference", "Kit Union"]
|
|
|
|
|
and sorted(report) == ["booleans", "evaluated", "object"] and report["object"] == "Cage" and report["evaluated"] == evaluated(cage)[0]
|
|
|
|
|
and report["booleans"] == [{"cutter": n, "operation": "DIFFERENCE"} for n in ("Bay", "Recess", "Gills", "Break", "Bay2", "Visor", "Seam", "Port", "Seam2")] + [{"cutter": "Lump", "operation": "UNION"}]
|
|
|
|
|
and report["evaluated"]["volume"] > deeper["volume"], [receipt["message"], report])
|
|
|
|
|
refused("cut-refusals: a cutter already in the target's union collection", "brokkr_kitbash.boolean", {"object_name": "Cage", "cutter": "Lump"},
|
|
|
|
|
"'Lump' already cuts 'Cage' (its Kit Union modifier's collection)")
|
|
|
|
|
refused("a cut's own cutter given to boolean again", "brokkr_kitbash.boolean", {"object_name": "Cage", "cutter": "Bay", "operation": "INTERSECT"},
|
|
|
|
|
"'Bay' already cuts 'Cage' (its Kit Difference modifier's collection)")
|
|
|
|
|
plate = place("Plate", "plate", location=[0.0, -6.0, 0.0])
|
|
|
|
|
for name, size, operation in (("Boss", 0.06, "UNION"), ("Keep", 2.0, "INTERSECT"), ("Hole", 0.05, "DIFFERENCE")):
|
|
|
|
|
send("createObject", objectType="MESH", name=name, location=[0.0, -6.0, 0.0], size=size)
|
|
|
|
|
receipt, report = send("brokkr_kitbash.boolean", object_name="Plate", cutter=name, operation=operation)
|
|
|
|
|
check("a part cut by union, then intersect, then difference carries the three modifiers as difference, union, intersect, above its Bevel, and lists its cutters so",
|
|
|
|
|
receipt["status"] == "accepted" and stack(plate) == ["Kit Difference", "Kit Union", "Kit Intersect", "Kit Bevel"]
|
|
|
|
|
and report["booleans"] == [{"cutter": "Hole", "operation": "DIFFERENCE"}, {"cutter": "Boss", "operation": "UNION"}, {"cutter": "Keep", "operation": "INTERSECT"}]
|
|
|
|
|
and report["evaluated"]["nonManifoldEdges"] == 0 and report["kit"] == "mechanical", [stack(plate), report and report["booleans"]])
|
|
|
|
|
collections = len(bpy.data.collections)
|
|
|
|
|
receipt, baked = send("brokkr_kitbash.apply", object_name="Plate")
|
|
|
|
|
check("apply removes the three collections its modifiers held and leaves every cutter in the scene", receipt["status"] == "accepted"
|
|
|
|
|
and baked["cutters"] == ["Hole", "Boss", "Keep"] and len(bpy.data.collections) == collections - 3 and len(plate.modifiers) == 0
|
|
|
|
|
and all(name in bpy.context.scene.objects for name in ("Hole", "Boss", "Keep")), [receipt["message"], [c.name for c in bpy.data.collections]])
|
|
|
|
|
refused("apply on the cage, which is not a kit part", "brokkr_kitbash.apply", {"object_name": "Cage"}, "'Cage' is not a kit part")
|
|
|
|
|
|
|
|
|
|
# --- cut-refusals -----------------------------------------------------------------------------------------------------------
|
|
|
|
|
RAY = {"object_name": "Cage", "cutter_name": "New", "part": "box", "origin_x": 3.0, "origin_y": 0.0, "origin_z": 0.1, "direction_x": -1.0, "direction_y": 0.0, "direction_z": 0.0}
|
|
|
|
|
refused("a ray that misses", "brokkr_kitbash.cut", {**RAY, "origin_z": 5.0}, "The ray from (3.0, 0.0, 5.0) along (-1.0, 0.0, 0.0) misses 'Cage'")
|
|
|
|
|
refused("a ray of no direction", "brokkr_kitbash.cut", {**RAY, "direction_x": 0.0}, "'New': the ray's direction is zero")
|
|
|
|
|
refused("a cutter name an object has", "brokkr_kitbash.cut", {**RAY, "cutter_name": "Bay"}, "An object named 'Bay' exists")
|
|
|
|
|
refused("a param the cutter part does not have", "brokkr_kitbash.cut", {**RAY, "params": "radius=0.1"}, "kit 'cutters' part 'box' has no param 'radius'")
|
|
|
|
|
refused("a slot wider across than along", "brokkr_kitbash.cut", {**RAY, "part": "slot", "params": "width=0.05; height=0.1"}, "every size must be above 0")
|
|
|
|
|
refused("a target that is not a mesh", "brokkr_kitbash.cut", {**RAY, "object_name": "Nothing"}, "No mesh object named 'Nothing'")
|
|
|
|
|
block = bpy.data.objects.new("Block", bpy.data.meshes.new("Block"))
|
|
|
|
|
bm = bmesh.new()
|
|
|
|
|
bmesh.ops.create_cube(bm, size=1.0)
|
|
|
|
|
bm.to_mesh(block.data)
|
|
|
|
|
bm.free()
|
|
|
|
|
bpy.context.scene.collection.objects.link(block)
|
|
|
|
|
block.location = (0.0, -9.0, 0.0)
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
DOWN = {**RAY, "object_name": "Block", "origin_x": 0.1, "origin_y": 0.1, "origin_z": 3.0, "direction_x": 0.0, "direction_z": -1.0}
|
|
|
|
|
refused("an up along the hit normal", "brokkr_kitbash.cut", DOWN, "up [0.0, 0.0, 1.0] runs along the surface normal [0.0, 0.0, 1.0]")
|
|
|
|
|
block.scale = (1.0, 1.0, 1.01)
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
refused("a scaled target", "brokkr_kitbash.cut", {**DOWN, "up_y": 1.0, "up_z": 0.0}, "'Block' is scaled, mirrored or sheared in the world (scale 1, 1, 1.01)")
|
|
|
|
|
refused("boolean on a scaled target", "brokkr_kitbash.boolean", {"object_name": "Block", "cutter": "Lump"}, "'Block' is scaled, mirrored or sheared")
|
|
|
|
|
block.scale = (1.0, 1.0, 1.0)
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
receipt, report = send("brokkr_kitbash.cut", **{**DOWN, "cutter_name": "Pocket", "up_y": 1.0, "up_z": 0.0, "roll": 90.0})
|
|
|
|
|
pocket = bpy.data.objects.get("Pocket")
|
|
|
|
|
check("a cut on a plain cube with up +y and roll 90: the cutter's y points along -x, its floor 0.02 under the top face", receipt["status"] == "accepted" and pocket is not None
|
|
|
|
|
and np.abs(np.array(pocket.matrix_basis) - [[0, -1, 0, 0.1], [1, 0, 0, 0.1], [0, 0, 1, 0.5], [0, 0, 0, 1]]).max() < 1e-6
|
|
|
|
|
and np.abs(np.array(report["cutter"]["sockets"][0]["matrix"])[:3, 3] - [0.1, -8.9, 0.48]).max() < 1e-6 and stack(block) == ["Kit Difference"],
|
|
|
|
|
[receipt["message"], pocket and np.array(pocket.matrix_basis).tolist()])
|
|
|
|
|
try:
|
|
|
|
|
# --- a cage: not a kit part. A closed loft of 6 rings of 8, subdivided and given a wall ----------------------------------
|
|
|
|
|
section('a cage: not a kit part. A closed loft of 6 rings of 8, subdivided and given a wall')
|
|
|
|
|
bm = bmesh.new()
|
|
|
|
|
rings = [[bm.verts.new((r * math.cos(math.pi / 8 + k * math.pi / 4), r * math.sin(math.pi / 8 + k * math.pi / 4), z)) for k in range(8)]
|
|
|
|
|
for z, r in ((-1.0, 0.5), (-0.6, 0.7), (-0.2, 0.8), (0.2, 0.8), (0.6, 0.7), (1.0, 0.5))]
|
|
|
|
|
for low, high in zip(rings, rings[1:]):
|
|
|
|
|
for k in range(8):
|
|
|
|
|
bm.faces.new((low[k], low[(k + 1) % 8], high[(k + 1) % 8], high[k]))
|
|
|
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:])
|
|
|
|
|
mesh = bpy.data.meshes.new("Cage")
|
|
|
|
|
bm.to_mesh(mesh)
|
|
|
|
|
bm.free()
|
|
|
|
|
cage = bpy.data.objects.new("Cage", mesh)
|
|
|
|
|
bpy.context.scene.collection.objects.link(cage)
|
|
|
|
|
cage.modifiers.new("Subsurf", "SUBSURF").levels = 2
|
|
|
|
|
wall = cage.modifiers.new("Solidify", "SOLIDIFY")
|
|
|
|
|
wall.thickness, wall.offset, wall.use_even_offset = 0.05, -1.0, True
|
|
|
|
|
cage.matrix_world = Matrix.Translation((4.0, -1.0, 2.0)) @ Matrix.Rotation(0.6, 4, "Z") @ Matrix.Rotation(-0.3, 4, "X")
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
world = np.array(cage.matrix_world, dtype=np.float64)
|
|
|
|
|
uncut, _ = evaluated(cage)
|
|
|
|
|
check("the cage is a closed wall before it is cut", uncut["nonManifoldEdges"] == 0 and 0.15 < uncut["volume"] < 0.4 and "kit_part" not in cage, uncut)
|
|
|
|
|
R["cage"] = {"uncut": uncut}
|
|
|
|
|
|
|
|
|
|
# --- cut-orphan and closures-ends-first -----------------------------------------------------------------------------------------
|
|
|
|
|
strut = core.build(kits["mechanical"]["parts"]["strut"], {"width": 0.09})
|
|
|
|
|
end = {name: next(s for s in strut.sockets if s["name"] == name) for name in ("end_a", "end_b")}
|
|
|
|
|
for pair, y in (("Zz", -20.0), ("Aa", -24.0)): # two closures that share no part; the open one is named to sort first
|
|
|
|
|
anchor, loose = place(f"{pair}_Anchor", "strut", "width=0.09", location=[0.0, y, 0.0]), place(f"{pair}_Loose", "strut", "width=0.09")
|
|
|
|
|
meet = Matrix((np.array(anchor.matrix_world) @ core.mate(end["end_b"], end["end_a"], 40.0)).tolist())
|
|
|
|
|
send("setObjectTransform", targetObjectName=f"{pair}_Loose", location=list(meet.translation), rotationEuler=list(meet.to_euler("XYZ")))
|
|
|
|
|
send("brokkr_kitbash.close", object_name=f"{pair}_Loose", socket="end_a", other_name=f"{pair}_Anchor", other_socket="end_b")
|
|
|
|
|
send("brokkr_kitbash.set_params", object_name="Aa_Anchor", params="length=0.9") # opens Aa's closure
|
|
|
|
|
receipt, report = send("brokkr_kitbash.set_params", object_name="Zz_Anchor", params="width=0.09")
|
|
|
|
|
check("closures-ends-first: set_params on a part whose own closure holds lists it before another part's closure that is open, though that one sorts first by holds and by name",
|
|
|
|
|
receipt["status"] == "accepted" and report["closures"] == [{"part": "Zz_Loose", "to": "Zz_Anchor", "holds": True}, {"part": "Aa_Loose", "to": "Aa_Anchor", "holds": False}],
|
|
|
|
|
report and report.get("closures"))
|
|
|
|
|
ghost = bpy.data.objects["Aa_Anchor"]
|
|
|
|
|
with bpy.context.temp_override(selected_objects=[ghost], active_object=ghost):
|
|
|
|
|
bpy.ops.object.delete() # the ordinary Delete: Aa_Loose's closure still points at it, so it stays in the file, in no collection
|
|
|
|
|
tie = place("Tie", "strut", "width=0.09")
|
|
|
|
|
check("a part deleted with the Delete operator that a closure points to is still in the file", bpy.data.objects.get("Aa_Anchor") is not None and not ghost.users_collection, list(bpy.data.objects.keys()))
|
|
|
|
|
GONE = "'Aa_Anchor' is in no collection (a deleted object something still points to)"
|
|
|
|
|
refused("cut-orphan: attach onto a deleted part's name", "brokkr_kitbash.attach", {"object_name": "Tie", "socket": "end_a", "parent_name": "Aa_Anchor", "parent_socket": "end_a"}, GONE)
|
|
|
|
|
refused("attach of a deleted part", "brokkr_kitbash.attach", {"object_name": "Aa_Anchor", "socket": "end_a", "parent_name": "Tie", "parent_socket": "end_a"}, GONE)
|
|
|
|
|
refused("set_params on a deleted part", "brokkr_kitbash.set_params", {"object_name": "Aa_Anchor", "params": "length=1.0"}, GONE)
|
|
|
|
|
refused("report of a deleted part", "brokkr_kitbash.report", {"object_name": "Aa_Anchor"}, GONE)
|
|
|
|
|
refused("cut on a deleted part", "brokkr_kitbash.cut", {**RAY, "object_name": "Aa_Anchor"}, GONE)
|
|
|
|
|
refused("boolean on a deleted part", "brokkr_kitbash.boolean", {"object_name": "Aa_Anchor", "cutter": "Lump"}, GONE)
|
|
|
|
|
refused("boolean with a deleted part as the cutter", "brokkr_kitbash.boolean", {"object_name": "Tie", "cutter": "Aa_Anchor"}, GONE)
|
|
|
|
|
refused("close onto a deleted part", "brokkr_kitbash.close", {"object_name": "Tie", "socket": "end_a", "other_name": "Aa_Anchor", "other_socket": "end_a"}, GONE)
|
|
|
|
|
# --- cut-at-ray: a through bay, a blind round recess, a row of gills and a panel break --------------------------------------
|
|
|
|
|
section('cut-at-ray: a through bay, a blind round recess, a row of gills and a panel break')
|
|
|
|
|
CUTS = [("Bay", "box", (3.0, 0.0, 0.1), (-1.0, 0.0, 0.0), "width=0.3; height=0.3; depth=0.2", {}),
|
|
|
|
|
("Recess", "cyl", (-3.0, 0.1, 0.2), (2.0, 0.0, 0.0), "r=0.1; depth=0.02", {}),
|
|
|
|
|
("Gills", "slot", (0.1, 3.0, -0.2), (0.0, -1.0, 0.0), "width=0.3; height=0.04; count=4; pitch=0.08; depth=0.02", {}),
|
|
|
|
|
("Break", "slab", (0.0, -3.0, 0.3), (0.0, 1.0, 0.0), "length=0.6; depth=0.1", {"roll": 90.0})]
|
|
|
|
|
frames, volume, falls, reports = {}, uncut["volume"], [], {}
|
|
|
|
|
for name, part, origin, direction, params, more in CUTS:
|
|
|
|
|
hit, normal = cast(cage, origin, direction) # before this cutter exists; the cuts made so far are far from this ray
|
|
|
|
|
frames[name] = core.surface_frame(hit, normal, (0.0, 0.0, 1.0), more.get("roll", 0.0))
|
|
|
|
|
state = sorted(o.name for o in bpy.data.objects)
|
|
|
|
|
receipt, report = cut(name, part, origin, direction, params, **more)
|
|
|
|
|
reports[name] = report
|
|
|
|
|
cutter = bpy.data.objects.get(name)
|
|
|
|
|
ok = receipt["status"] == "accepted" and cutter is not None and sorted(o.name for o in bpy.data.objects) == sorted(state + [name])
|
|
|
|
|
ok = ok and cutter.parent == cage and np.array_equal(np.array(cutter.matrix_parent_inverse), np.eye(4))
|
|
|
|
|
ok = ok and reading("framed", np.abs(np.array(cutter.matrix_basis) - frames[name]).max()) < FRAMED
|
|
|
|
|
ok = ok and (cutter["kit_kit"], cutter["kit_part"]) == ("cutters", part) and bpy.context.scene.collection in cutter.users_collection
|
|
|
|
|
ok = ok and not cutter.hide_render and not cutter.hide_viewport and len(cutter.modifiers) == 0
|
|
|
|
|
check(f"cut places the {part} cutter {name} on the cage where the ray meets it: parented under an identity inverse, its basis the surface frame",
|
|
|
|
|
ok, [receipt["message"], cutter and np.array(cutter.matrix_basis).tolist(), frames[name].tolist()])
|
|
|
|
|
wanted = world @ frames[name]
|
|
|
|
|
check(f"cut reports {name} as a cutters part with its sockets in the world, and what cuts the cage, without evaluating it", report
|
|
|
|
|
and report["object"] == "Cage" and report["cutter"]["object"] == name and report["cutter"]["kit"] == "cutters" and "evaluated" not in report
|
|
|
|
|
and report["booleans"] == [{"cutter": n, "operation": "DIFFERENCE"} for n in [c[0] for c in CUTS][:len(frames)]]
|
|
|
|
|
and [s["name"] for s in report["cutter"]["sockets"]] == {"slab": [], "slot": ["floor", "floor_l", "floor_r"]}.get(part, ["floor"])
|
|
|
|
|
and (part == "slab" or np.abs(np.array(report["cutter"]["sockets"][0]["matrix"]) - wanted @ core.build(kits["cutters"]["parts"][part], report["cutter"]["params"]).sockets[0]["matrix"]).max() < 1e-4),
|
|
|
|
|
report)
|
|
|
|
|
shown, _ = evaluated(cage)
|
|
|
|
|
falls.append(shown["volume"] < volume - 1e-4 and shown["nonManifoldEdges"] == 0)
|
|
|
|
|
volume = shown["volume"]
|
|
|
|
|
R["cage"][name] = shown
|
|
|
|
|
modifier = cage.modifiers.get("Kit Difference")
|
|
|
|
|
check("four cuts give the cage one Boolean modifier after its own, over one collection of the four cutters in the order they came",
|
|
|
|
|
stack(cage) == ["Subsurf", "Solidify", "Kit Difference"] and modifier is not None
|
|
|
|
|
and (modifier.type, modifier.solver, modifier.use_self, modifier.operation, modifier.operand_type, modifier.material_mode) == ("BOOLEAN", "EXACT", True, "DIFFERENCE", "COLLECTION", "TRANSFER")
|
|
|
|
|
and [o.name for o in modifier.collection.objects] == [c[0] for c in CUTS] and modifier.collection.name == "Cage difference"
|
|
|
|
|
and not any(modifier.collection in s.collection.children_recursive for s in bpy.data.scenes), [stack(cage), modifier and modifier.operand_type])
|
|
|
|
|
check("the evaluated cage stays a closed wall and loses volume with each cut", all(falls) and len(falls) == 4, R["cage"])
|
|
|
|
|
receipt, report = send("brokkr_kitbash.report", object_name="")
|
|
|
|
|
check("report lists the cutters as kit parts and not the cage", report and [p["object"] for p in report["parts"]] == sorted(c[0] for c in CUTS)
|
|
|
|
|
and all(p["connection"] is None and p["baked"] is False for p in report["parts"]), report and [p["object"] for p in report["parts"]])
|
|
|
|
|
|
|
|
|
|
R["ok"] = all(c["ok"] for c in R["checks"])
|
|
|
|
|
R["readings"] = {name: float(f"{value:.2g}") for name, value in sorted(R["readings"].items())}
|
|
|
|
|
Path(OUT + ".result.json").write_text(json.dumps(R, indent=1, default=str), encoding="utf-8")
|
|
|
|
|
for c in R["checks"]:
|
|
|
|
|
print("CHECK", "ok " if c["ok"] else "FAIL", c["name"], "" if c["ok"] else c["detail"], flush=True)
|
|
|
|
|
print("READINGS", R["readings"], flush=True)
|
|
|
|
|
# --- cut-casts-the-uncut-surface --------------------------------------------------------------------------------------------
|
|
|
|
|
section('cut-casts-the-uncut-surface')
|
|
|
|
|
through = cast(cage, CUTS[0][2], CUTS[0][3])[0] # as the cage is evaluated now, with its cuts: through the bay to the far wall
|
|
|
|
|
receipt, report = cut("Bay2", "cyl", CUTS[0][2], CUTS[0][3], "r=0.05; depth=0.2")
|
|
|
|
|
again = bpy.data.objects.get("Bay2")
|
|
|
|
|
check("a second cut on the through bay's ray lands where the first did, on the surface as it was before any cut, though the ray now passes through the bay",
|
|
|
|
|
receipt["status"] == "accepted" and again is not None and np.linalg.norm(through - frames["Bay"][:3, 3]) > 1.0
|
|
|
|
|
and reading("recast", np.abs(np.array(again.matrix_basis)[:3, 3] - frames["Bay"][:3, 3]).max()) < RECAST
|
|
|
|
|
and stack(cage) == ["Subsurf", "Solidify", "Kit Difference"] and all(m.show_viewport for m in cage.modifiers),
|
|
|
|
|
[receipt["message"], through.tolist(), frames["Bay"][:3, 3].tolist(), again and list(again.matrix_basis.translation)])
|
|
|
|
|
|
|
|
|
|
# --- floor-carries-machinery ------------------------------------------------------------------------------------------------
|
|
|
|
|
section('floor-carries-machinery')
|
|
|
|
|
recess = bpy.data.objects["Recess"]
|
|
|
|
|
vent = place("Vent", "vent", "width=0.2; height=0.15") # back size 0.135; the floor's is 0.2
|
|
|
|
|
receipt, report = send("brokkr_kitbash.attach", object_name="Vent", socket="back", parent_name="Recess", parent_socket="floor", roll=30.0)
|
|
|
|
|
floor = world @ frames["Recess"] @ np.array(Matrix.Translation((0.0, 0.0, -0.02))) # the hit point, depth along the normal
|
|
|
|
|
back = frame(vent, "back")
|
|
|
|
|
check("a mechanical vent attaches to the round recess's floor: its back on the hit point taken depth down the normal, facing in, and the connection holds",
|
|
|
|
|
receipt["status"] == "accepted" and held(report) and vent.parent == recess and report["connection"]["parent"] == "Recess" and report["kit"] == "mechanical"
|
|
|
|
|
and reading("floored", max(np.abs(back[:3, 3] - floor[:3, 3]).max(), np.abs(back[:3, 2] + floor[:3, 2]).max())) < FLOORED,
|
|
|
|
|
[receipt["message"], back.tolist(), floor.tolist()])
|
|
|
|
|
big = place("Big", "vent", "width=0.8; height=0.6")
|
|
|
|
|
refused("a vent larger than the recess's floor", "brokkr_kitbash.attach", {"object_name": "Big", "socket": "back", "parent_name": "Recess", "parent_socket": "floor"},
|
|
|
|
|
"'Big' on 'Recess': socket 'back' (mount, size 0.54) and parent socket 'floor' (mount, size 0.2) are mount sockets, where the child fits the parent: it is larger")
|
|
|
|
|
nozzle = place("Nozzle", "nozzle")
|
|
|
|
|
refused("a flange on a floor", "brokkr_kitbash.attach", {"object_name": "Nozzle", "socket": "mount", "parent_name": "Recess", "parent_socket": "floor"}, "are of different types")
|
|
|
|
|
refused("a second part on the floor", "brokkr_kitbash.attach", {"object_name": "Nozzle", "socket": "mount", "parent_name": "Recess", "parent_socket": "floor"}, "'Nozzle' on 'Recess'")
|
|
|
|
|
refused("a part on a slab, which has no floor", "brokkr_kitbash.attach", {"object_name": "Big", "socket": "back", "parent_name": "Break", "parent_socket": "floor"},
|
|
|
|
|
"kit 'cutters' part 'slab' has no socket 'floor'; its sockets: none")
|
|
|
|
|
refused("detach of a cutter, which is placed and not attached", "brokkr_kitbash.detach", {"object_name": "Recess"}, "'Recess' is not attached")
|
|
|
|
|
before = evaluated(cage)[0]
|
|
|
|
|
moved_to = np.array(recess.matrix_basis)[:3, 3] + np.array(recess.matrix_basis)[:3, :3] @ [0.0, 0.25, 0.0] # along the cutter's own y: up the wall
|
|
|
|
|
was = frame(vent, "back")
|
|
|
|
|
send("setObjectTransform", targetObjectName="Recess", location=moved_to.tolist())
|
|
|
|
|
shift = frame(vent, "back")[:3, 3] - was[:3, 3]
|
|
|
|
|
after = evaluated(cage)[0]
|
|
|
|
|
check("setObjectTransform on the cutter moves the cut and the vent on its floor together: the vent still holds, and the cage is cut elsewhere",
|
|
|
|
|
reading("floored", np.abs(shift - world[:3, :3] @ (moved_to - frames["Recess"][:3, 3])).max()) < FLOORED and abs(np.linalg.norm(shift) - 0.25) < 1e-4
|
|
|
|
|
and (connection := send("brokkr_kitbash.report", object_name="Vent")[1]["parts"][0]["connection"])["holds"] is True
|
|
|
|
|
and after["nonManifoldEdges"] == 0 and after != before, [shift.tolist(), before, after])
|
|
|
|
|
was = frame(vent, "back")
|
|
|
|
|
receipt, report = send("brokkr_kitbash.set_params", object_name="Recess", params="depth=0.04")
|
|
|
|
|
sunk = frame(vent, "back")[:3, 3] - was[:3, 3]
|
|
|
|
|
deeper = evaluated(cage)[0]
|
|
|
|
|
check("set_params depth=0.04 on the cutter deepens the cut and seats the vent on the new floor, 0.02 further down the normal",
|
|
|
|
|
receipt["status"] == "accepted" and report["params"]["depth"] == 0.04 and reading("floored", np.abs(sunk + was[:3, 2] * -0.02).max()) < FLOORED
|
|
|
|
|
and send("brokkr_kitbash.report", object_name="Vent")[1]["parts"][0]["connection"]["holds"] is True
|
|
|
|
|
and deeper["volume"] < after["volume"] - 1e-5 and deeper["nonManifoldEdges"] == 0 and stack(cage) == ["Subsurf", "Solidify", "Kit Difference"],
|
|
|
|
|
[receipt["message"], sunk.tolist(), after, deeper])
|
|
|
|
|
R["cage"]["deeper"] = deeper
|
|
|
|
|
|
|
|
|
|
# --- cut_many: several cutters for one evaluation, all or none; an axis; a slot's three floors -----------------------------------
|
|
|
|
|
section("cut_many: several cutters for one evaluation, all or none; an axis; a slot's three floors")
|
|
|
|
|
MANY = [{"name": "Visor", "part": "slot", "params": "width=0.6; height=0.14; depth=0.02; lift=0.2", "origin": [0.6, 3.0, 0.5], "direction": [0.0, -1.0, 0.0]},
|
|
|
|
|
{"name": "Seam", "part": "slab", "params": "length=0.4; depth=0.1", "origin": [-0.5, -3.0, -0.7], "direction": [0.0, 1.0, 0.0], "up": [1.0, 0.0, 0.0], "axis": [0.0, -1.0, 0.0]},
|
|
|
|
|
{"name": "Port", "part": "cyl", "params": "r=0.05", "origin": [-0.6, 3.0, -0.5], "direction": [0.0, -2.0, 0.0], "up": [1.0, 0.0, 0.0], "roll": 45.0}]
|
|
|
|
|
wanted = {}
|
|
|
|
|
for spec in MANY:
|
|
|
|
|
hit, normal = uncut_cast(spec["origin"], spec["direction"])
|
|
|
|
|
wanted[spec["name"]] = core.surface_frame(hit, spec.get("axis", normal), spec.get("up", (0.0, 0.0, 1.0)), spec.get("roll", 0.0))
|
|
|
|
|
if "axis" in spec:
|
|
|
|
|
lean = float(np.degrees(np.arccos(np.clip(normal @ np.array(spec["axis"]), -1.0, 1.0))))
|
|
|
|
|
refused("cut_many whose second ray misses places none", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([MANY[0], {**MANY[1], "origin": [0.0, -3.0, 5.0]}])},
|
|
|
|
|
"The ray from (0.0, -3.0, 5.0) along (0.0, 1.0, 0.0) misses 'Cage'")
|
|
|
|
|
refused("cut_many with a name twice", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([MANY[0], {**MANY[1], "name": "Visor"}])}, "An object named 'Visor' exists in this call")
|
|
|
|
|
refused("cut_many with a name an object has", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([MANY[0], {**MANY[1], "name": "Bay"}])}, "An object named 'Bay' exists;")
|
|
|
|
|
refused("cut_many whose last cutter has a bad param", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps(MANY[:2] + [{**MANY[2], "params": "r=9"}])}, "param 'r' = 9.0 is outside")
|
|
|
|
|
refused("cut_many of text that is not JSON", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": "[{"}, "cuts is not JSON")
|
|
|
|
|
refused("cut_many of no cutters", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": "[]"}, "cuts must be a JSON array of 1 to 64 cutters")
|
|
|
|
|
refused("cut_many of a cutter with no direction", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{k: v for k, v in MANY[0].items() if k != "direction"}])},
|
|
|
|
|
"cuts[0] must be an object with name, part, origin and direction")
|
|
|
|
|
refused("cut_many of a cutter with a key cut does not have", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{**MANY[0], "operation": "UNION"}])}, "cuts[0] must be an object")
|
|
|
|
|
refused("cut_many of an origin of two numbers", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{**MANY[0], "origin": [0.0, 1.0]}])}, "cuts[0].origin must be three numbers")
|
|
|
|
|
refused("cut_many of a roll of 400", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{**MANY[0], "roll": 400}])}, "cuts[0].roll must be a number from -360 to 360")
|
|
|
|
|
refused("an axis that points into the surface", "brokkr_kitbash.cut_many", {"object_name": "Cage", "cuts": json.dumps([{**MANY[1], "axis": [0.0, 1.0, 0.0]}])}, "'Seam': the axis (0.0, 1.0, 0.0) points into the surface")
|
|
|
|
|
quad("Many", (0.0, -27.0, 0.0)) # a target of its own, cheap to evaluate should the 65 ever be placed
|
|
|
|
|
refused("M7: cut_many of 65 cutters, one over the limit", "brokkr_kitbash.cut_many",
|
|
|
|
|
{"object_name": "Many", "cuts": json.dumps([{"name": f"Over{k}", "part": "cyl", "params": "r=0.005", "origin": [0.4 - k * 0.012, 0.0, 3.0], "direction": [0.0, 0.0, -1.0], "up": [0.0, 1.0, 0.0]}
|
|
|
|
|
for k in range(65)])}, "cuts must be a JSON array of 1 to 64 cutters")
|
|
|
|
|
receipt, report = send("brokkr_kitbash.cut_many", object_name="Cage", cuts=json.dumps(MANY))
|
|
|
|
|
placed = [bpy.data.objects.get(spec["name"]) for spec in MANY]
|
|
|
|
|
check("cut_many places three cutters in one action, each as cut would: parented under an identity inverse, its basis the surface frame at its own ray on the uncut cage, in the difference collection in order",
|
|
|
|
|
receipt["status"] == "accepted" and all(placed) and report == {"object": "Cage", "cutters": ["Visor", "Seam", "Port"], "booleans": report["booleans"]}
|
|
|
|
|
and [row["cutter"] for row in report["booleans"]] == ["Bay", "Recess", "Gills", "Break", "Bay2", "Visor", "Seam", "Port"]
|
|
|
|
|
and all(c.parent == cage and np.array_equal(np.array(c.matrix_parent_inverse), np.eye(4))
|
|
|
|
|
and reading("framed", np.abs(np.array(c.matrix_basis) - wanted[c.name]).max()) < FRAMED for c in placed)
|
|
|
|
|
and stack(cage) == ["Subsurf", "Solidify", "Kit Difference"] and all(m.show_viewport for m in cage.modifiers) and evaluated(cage)[0]["nonManifoldEdges"] == 0,
|
|
|
|
|
[receipt["message"], report])
|
|
|
|
|
seam = bpy.data.objects["Seam"]
|
|
|
|
|
check("a slab with an axis stands on the axis, not on the wall's normal, which leans from it there", lean > 5.0
|
|
|
|
|
and reading("framed", np.abs(np.array(seam.matrix_basis)[:3, 2] - [0.0, -1.0, 0.0]).max()) < FRAMED, [lean, np.array(seam.matrix_basis).tolist()])
|
|
|
|
|
receipt, report = send("brokkr_kitbash.cut", object_name="Cage", cutter_name="Seam2", part="slab", params="length=0.3; depth=0.1", origin_x=0.5, origin_y=-3.0, origin_z=-0.7,
|
|
|
|
|
direction_x=0.0, direction_y=1.0, direction_z=0.0, up_x=1.0, up_y=0.0, up_z=0.0, axis_x=0.0, axis_y=-1.0, axis_z=0.0)
|
|
|
|
|
check("cut takes the same axis", receipt["status"] == "accepted" and reading("framed", np.abs(np.array(bpy.data.objects["Seam2"].matrix_basis)[:3, 2] - [0.0, -1.0, 0.0]).max()) < FRAMED, receipt["message"])
|
|
|
|
|
visor = bpy.data.objects["Visor"]
|
|
|
|
|
eyes = {}
|
|
|
|
|
for socket, x in (("floor", 0.0), ("floor_l", -0.23), ("floor_r", 0.23)): # the round ends' centres: -+(0.6 - 0.14) / 2
|
|
|
|
|
eye = place(f"Eye_{socket}", "vent", "width=0.2; height=0.15") # back size 0.135; each floor's is 0.14
|
|
|
|
|
receipt, report = send("brokkr_kitbash.attach", object_name=eye.name, socket="back", parent_name="Visor", parent_socket=socket)
|
|
|
|
|
there = world @ wanted["Visor"] @ np.array(Matrix.Translation((x, 0.0, -0.02)))
|
|
|
|
|
eyes[socket] = receipt["status"] == "accepted" and held(report) and eye.parent == visor \
|
|
|
|
|
and reading("floored", max(np.abs(frame(eye, "back")[:3, 3] - there[:3, 3]).max(), np.abs(frame(eye, "back")[:3, 2] + there[:3, 2]).max())) < FLOORED
|
|
|
|
|
check("slot-floors: a slot's three floors each take a part: at the centre and at the round ends, all on the slot's one floor plane", all(eyes.values()) and len(eyes) == 3, eyes)
|
|
|
|
|
refused("a second part on a side floor", "brokkr_kitbash.attach", {"object_name": "Nozzle", "socket": "mount", "parent_name": "Visor", "parent_socket": "floor_l"}, "'Nozzle' on 'Visor'")
|
|
|
|
|
refused("a fourth eye on a floor that is taken", "brokkr_kitbash.attach", {"object_name": "Big", "socket": "back", "parent_name": "Visor", "parent_socket": "floor_l"}, "'Big' on 'Visor'")
|
|
|
|
|
|
|
|
|
|
# --- boolean on any mesh, and the order of the three operations -----------------------------------------------------------------
|
|
|
|
|
section('boolean on any mesh, and the order of the three operations')
|
|
|
|
|
lump_at = world @ [0.0, 0.0, 1.0, 1.0]
|
|
|
|
|
send("createObject", objectType="MESH", name="Lump", location=lump_at[:3].tolist(), size=0.2)
|
|
|
|
|
receipt, report = send("brokkr_kitbash.boolean", object_name="Cage", cutter="Lump", operation="UNION")
|
|
|
|
|
check("boolean on the cage, which is not a kit part, adds a second modifier after the difference and reports the object, what cuts it and the evaluated mesh",
|
|
|
|
|
receipt["status"] == "accepted" and stack(cage) == ["Subsurf", "Solidify", "Kit Difference", "Kit Union"]
|
|
|
|
|
and sorted(report) == ["booleans", "evaluated", "object"] and report["object"] == "Cage" and report["evaluated"] == evaluated(cage)[0]
|
|
|
|
|
and report["booleans"] == [{"cutter": n, "operation": "DIFFERENCE"} for n in ("Bay", "Recess", "Gills", "Break", "Bay2", "Visor", "Seam", "Port", "Seam2")] + [{"cutter": "Lump", "operation": "UNION"}]
|
|
|
|
|
and report["evaluated"]["volume"] > deeper["volume"], [receipt["message"], report])
|
|
|
|
|
refused("cut-refusals: a cutter already in the target's union collection", "brokkr_kitbash.boolean", {"object_name": "Cage", "cutter": "Lump"},
|
|
|
|
|
"'Lump' already cuts 'Cage' (its Kit Union modifier's collection)")
|
|
|
|
|
refused("a cut's own cutter given to boolean again", "brokkr_kitbash.boolean", {"object_name": "Cage", "cutter": "Bay", "operation": "INTERSECT"},
|
|
|
|
|
"'Bay' already cuts 'Cage' (its Kit Difference modifier's collection)")
|
|
|
|
|
blocked = cast(cage, (-0.3, 0.0, 0.95), (1.0, 0.0, 0.0))[0] # as evaluated now: the ray meets Lump, which the union added inside the cage's mouth
|
|
|
|
|
hit, normal = uncut_cast((-0.3, 0.0, 0.95), (1.0, 0.0, 0.0))
|
|
|
|
|
receipt, report = cut("Past", "cyl", (-0.3, 0.0, 0.95), (1.0, 0.0, 0.0), "r=0.02; depth=0.01")
|
|
|
|
|
past = bpy.data.objects.get("Past")
|
|
|
|
|
check("M3: a cut whose ray meets what a union added lands on the surface as designed: the cast has the Kit Union off too",
|
|
|
|
|
receipt["status"] == "accepted" and past is not None and np.linalg.norm(blocked - hit) > 0.3
|
|
|
|
|
and reading("framed", np.abs(np.array(past.matrix_basis) - core.surface_frame(hit, normal, (0.0, 0.0, 1.0))).max()) < FRAMED
|
|
|
|
|
and all(m.show_viewport for m in cage.modifiers), [receipt["message"], blocked.tolist(), hit.tolist(), past and list(past.matrix_basis.translation)])
|
|
|
|
|
plate = place("Plate", "plate", location=[0.0, -6.0, 0.0])
|
|
|
|
|
for name, size, operation in (("Boss", 0.06, "UNION"), ("Keep", 2.0, "INTERSECT"), ("Hole", 0.05, "DIFFERENCE")):
|
|
|
|
|
send("createObject", objectType="MESH", name=name, location=[0.0, -6.0, 0.0], size=size)
|
|
|
|
|
receipt, report = send("brokkr_kitbash.boolean", object_name="Plate", cutter=name, operation=operation)
|
|
|
|
|
check("a part cut by union, then intersect, then difference carries the three modifiers as difference, union, intersect, above its Bevel, and lists its cutters so",
|
|
|
|
|
receipt["status"] == "accepted" and stack(plate) == ["Kit Difference", "Kit Union", "Kit Intersect", "Kit Bevel"]
|
|
|
|
|
and report["booleans"] == [{"cutter": "Hole", "operation": "DIFFERENCE"}, {"cutter": "Boss", "operation": "UNION"}, {"cutter": "Keep", "operation": "INTERSECT"}]
|
|
|
|
|
and report["evaluated"]["nonManifoldEdges"] == 0 and report["kit"] == "mechanical", [stack(plate), report and report["booleans"]])
|
|
|
|
|
collections = len(bpy.data.collections)
|
|
|
|
|
receipt, baked = send("brokkr_kitbash.apply", object_name="Plate")
|
|
|
|
|
check("apply removes the three collections its modifiers held and leaves every cutter in the scene", receipt["status"] == "accepted"
|
|
|
|
|
and baked["cutters"] == ["Hole", "Boss", "Keep"] and len(bpy.data.collections) == collections - 3 and len(plate.modifiers) == 0
|
|
|
|
|
and all(name in bpy.context.scene.objects for name in ("Hole", "Boss", "Keep")), [receipt["message"], [c.name for c in bpy.data.collections]])
|
|
|
|
|
refused("apply on the cage, which is not a kit part", "brokkr_kitbash.apply", {"object_name": "Cage"}, "'Cage' is not a kit part")
|
|
|
|
|
twin = place("Twin", "plate", location=[0.0, -15.0, 0.0])
|
|
|
|
|
send("createObject", objectType="MESH", name="TwinHole", location=[0.0, -15.0, 0.0], size=0.05)
|
|
|
|
|
send("brokkr_kitbash.boolean", object_name="Twin", cutter="TwinHole")
|
|
|
|
|
copied = twin.copy() # a copied part: its own mesh, and a Kit Difference modifier that reads the same collection
|
|
|
|
|
copied.data = twin.data.copy()
|
|
|
|
|
bpy.context.scene.collection.objects.link(copied)
|
|
|
|
|
receipt, baked = send("brokkr_kitbash.apply", object_name="Twin")
|
|
|
|
|
kept = bpy.data.collections.get("Twin difference")
|
|
|
|
|
check("M6: apply keeps a collection a copied part's modifier still reads", receipt["status"] == "accepted" and len(twin.modifiers) == 0 and kept is not None
|
|
|
|
|
and copied.modifiers["Kit Difference"].collection == kept and [o.name for o in kept.objects] == ["TwinHole"], [receipt["message"], [c.name for c in bpy.data.collections]])
|
|
|
|
|
|
|
|
|
|
# --- cut-refusals -----------------------------------------------------------------------------------------------------------
|
|
|
|
|
section('cut-refusals')
|
|
|
|
|
RAY = {"object_name": "Cage", "cutter_name": "New", "part": "box", "origin_x": 3.0, "origin_y": 0.0, "origin_z": 0.1, "direction_x": -1.0, "direction_y": 0.0, "direction_z": 0.0}
|
|
|
|
|
refused("a ray that misses", "brokkr_kitbash.cut", {**RAY, "origin_z": 5.0}, "The ray from (3.0, 0.0, 5.0) along (-1.0, 0.0, 0.0) misses 'Cage'")
|
|
|
|
|
refused("a ray of no direction", "brokkr_kitbash.cut", {**RAY, "direction_x": 0.0}, "'New': the ray's direction is zero")
|
|
|
|
|
refused("a cutter name an object has", "brokkr_kitbash.cut", {**RAY, "cutter_name": "Bay"}, "An object named 'Bay' exists")
|
|
|
|
|
refused("a param the cutter part does not have", "brokkr_kitbash.cut", {**RAY, "params": "radius=0.1"}, "kit 'cutters' part 'box' has no param 'radius'")
|
|
|
|
|
refused("a slot wider across than along", "brokkr_kitbash.cut", {**RAY, "part": "slot", "params": "width=0.05; height=0.1"}, "every size must be above 0")
|
|
|
|
|
refused("a target that is not a mesh", "brokkr_kitbash.cut", {**RAY, "object_name": "Nothing"}, "No mesh object named 'Nothing'")
|
|
|
|
|
block = bpy.data.objects.new("Block", bpy.data.meshes.new("Block"))
|
|
|
|
|
bm = bmesh.new()
|
|
|
|
|
bmesh.ops.create_cube(bm, size=1.0)
|
|
|
|
|
bm.to_mesh(block.data)
|
|
|
|
|
bm.free()
|
|
|
|
|
bpy.context.scene.collection.objects.link(block)
|
|
|
|
|
block.location = (0.0, -9.0, 0.0)
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
DOWN = {**RAY, "object_name": "Block", "origin_x": 0.1, "origin_y": 0.1, "origin_z": 3.0, "direction_x": 0.0, "direction_z": -1.0}
|
|
|
|
|
refused("an up along the hit normal", "brokkr_kitbash.cut", DOWN, "up [0.0, 0.0, 1.0] runs along the surface normal [0.0, 0.0, 1.0]")
|
|
|
|
|
block.scale = (1.0, 1.0, 1.01)
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
refused("a scaled target", "brokkr_kitbash.cut", {**DOWN, "up_y": 1.0, "up_z": 0.0}, "'Block' is scaled, mirrored or sheared in the world (scale 1, 1, 1.01)")
|
|
|
|
|
refused("boolean on a scaled target", "brokkr_kitbash.boolean", {"object_name": "Block", "cutter": "Lump"}, "'Block' is scaled, mirrored or sheared")
|
|
|
|
|
block.scale = (1.0, 1.0, 1.0)
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
receipt, report = send("brokkr_kitbash.cut", **{**DOWN, "cutter_name": "Pocket", "up_y": 1.0, "up_z": 0.0, "roll": 90.0})
|
|
|
|
|
pocket = bpy.data.objects.get("Pocket")
|
|
|
|
|
check("a cut on a plain cube with up +y and roll 90: the cutter's y points along -x, its floor 0.02 under the top face", receipt["status"] == "accepted" and pocket is not None
|
|
|
|
|
and np.abs(np.array(pocket.matrix_basis) - [[0, -1, 0, 0.1], [1, 0, 0, 0.1], [0, 0, 1, 0.5], [0, 0, 0, 1]]).max() < 1e-6
|
|
|
|
|
and np.abs(np.array(report["cutter"]["sockets"][0]["matrix"])[:3, 3] - [0.1, -8.9, 0.48]).max() < 1e-6 and stack(block) == ["Kit Difference"],
|
|
|
|
|
[receipt["message"], pocket and np.array(pocket.matrix_basis).tolist()])
|
|
|
|
|
|
|
|
|
|
# --- lows-pinned: the surface's side, an axis along it, and an object Blender does not evaluate --------------------------------
|
|
|
|
|
section("lows-pinned: the surface's side, an axis along it, and an object Blender does not evaluate")
|
|
|
|
|
sheet = quad("Sheet", (0.0, -12.0, 0.0))
|
|
|
|
|
UNDER = {"object_name": "Sheet", "cutter_name": "Under", "part": "cyl", "origin_x": 0.1, "origin_y": 0.1, "origin_z": -3.0, "direction_x": 0.0, "direction_y": 0.0, "direction_z": 1.0,
|
|
|
|
|
"up_x": 0.0, "up_y": 1.0, "up_z": 0.0}
|
|
|
|
|
refused("M1: an axis exactly along the surface, neither out of it nor into it", "brokkr_kitbash.cut", {**UNDER, "cutter_name": "Along", "origin_z": 3.0, "direction_z": -1.0, "axis_x": 1.0},
|
|
|
|
|
"'Along': the axis (1.0, 0.0, 0.0) points into the surface")
|
|
|
|
|
receipt, report = send("brokkr_kitbash.cut", **UNDER)
|
|
|
|
|
under = bpy.data.objects.get("Under")
|
|
|
|
|
check("M16: a ray that meets a one-sided face from behind gives a cutter whose z faces the ray, against the face's own normal", receipt["status"] == "accepted" and under is not None
|
|
|
|
|
and reading("framed", np.abs(np.array(under.matrix_basis)[:3, 2] - [0.0, 0.0, -1.0]).max()) < FRAMED, [receipt["message"], under and np.array(under.matrix_basis).tolist()])
|
|
|
|
|
loose = place("Loose", "plate", location=[0.0, -18.0, 0.0])
|
|
|
|
|
apart = bpy.data.collections.new("Apart") # a collection no scene holds: Loose is in a collection, and in no view layer
|
|
|
|
|
apart.objects.link(loose)
|
|
|
|
|
bpy.context.scene.collection.objects.unlink(loose)
|
|
|
|
|
veil = quad("Veil", (0.0, -21.0, 0.0)) # nothing depends on it: a disabled object another evaluated object needs (a parent, a cutter) is still evaluated
|
|
|
|
|
veil.hide_viewport = plate.hide_viewport = True
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
for name, why in (("Veil", "disabled in viewports"), ("Loose", "in a collection outside the view layer")):
|
|
|
|
|
NOT = f"Blender does not evaluate {name!r} in this view layer"
|
|
|
|
|
refused(f"unevaluable-target: cut on a target {why}", "brokkr_kitbash.cut", {**DOWN, "object_name": name, "cutter_name": "Unseen", "up_y": 1.0, "up_z": 0.0}, NOT)
|
|
|
|
|
refused(f"cut_many on a target {why}", "brokkr_kitbash.cut_many",
|
|
|
|
|
{"object_name": name, "cuts": json.dumps([{"name": "Unseen", "part": "box", "origin": [0.1, 0.1, 3.0], "direction": [0.0, 0.0, -1.0], "up": [0.0, 1.0, 0.0]}])}, NOT)
|
|
|
|
|
refused(f"boolean on a target {why}", "brokkr_kitbash.boolean", {"object_name": name, "cutter": "Sheet"}, NOT)
|
|
|
|
|
refused("apply on a part disabled in viewports", "brokkr_kitbash.apply", {"object_name": "Plate"}, "Blender does not evaluate 'Plate' in this view layer")
|
|
|
|
|
refused("apply on a part in a collection outside the view layer", "brokkr_kitbash.apply", {"object_name": "Loose"}, "Blender does not evaluate 'Loose' in this view layer")
|
|
|
|
|
veil.hide_viewport = plate.hide_viewport = False
|
|
|
|
|
bpy.context.view_layer.update()
|
|
|
|
|
|
|
|
|
|
# --- receipt-fitted: rows that would not fit a receipt are left off and counted; the scene keeps the cutters ---------------------
|
|
|
|
|
section('receipt-fitted: rows that would not fit a receipt are left off and counted; the scene keeps the cutters')
|
|
|
|
|
addon = sys.modules["brokkr_kitbash"]
|
|
|
|
|
limit, fits = addon.REPORT_LIMIT, {}
|
|
|
|
|
SPOT = {"part": "cyl", "params": "r=0.03", "direction": [0.0, 0.0, -1.0], "up": [0.0, 1.0, 0.0]}
|
|
|
|
|
try:
|
|
|
|
|
addon.REPORT_LIMIT = 200
|
|
|
|
|
fits["cut"] = send("brokkr_kitbash.cut", **{**DOWN, "cutter_name": "Fit1", "part": "cyl", "params": "r=0.03", "origin_x": -0.3, "up_y": 1.0, "up_z": 0.0})
|
|
|
|
|
fits["cut_many"] = send("brokkr_kitbash.cut_many", object_name="Block", cuts=json.dumps([{**SPOT, "name": "Fit2", "origin": [-0.3, -0.3, 3.0]}, {**SPOT, "name": "Fit3", "origin": [0.3, -0.3, 3.0]}]))
|
|
|
|
|
fits["boolean"] = send("brokkr_kitbash.boolean", object_name="Block", cutter="Lump", operation="UNION")
|
|
|
|
|
finally:
|
|
|
|
|
addon.REPORT_LIMIT = limit
|
|
|
|
|
ROWS = [{"cutter": name, "operation": "DIFFERENCE"} for name in ("Pocket", "Fit1", "Fit2", "Fit3")] + [{"cutter": "Lump", "operation": "UNION"}]
|
|
|
|
|
for action, total, keeps in (("cut", 2, 0), ("cut_many", 4, 2), ("boolean", 5, 1)): # rows the scene had after each action, and how many of them 200 characters carry
|
|
|
|
|
receipt, report = fits[action]
|
|
|
|
|
check(f"receipt-fitted: {action} past what a receipt carries is accepted, its booleans cut short and the rest counted in booleansOmitted", receipt["status"] == "accepted"
|
|
|
|
|
and report is not None and report["booleans"] == ROWS[:keeps] and report.get("booleansOmitted") == total - keeps and (keeps == 0 or len(receipt["hostResult"]) <= 200),
|
|
|
|
|
[receipt["message"], receipt.get("hostResult")])
|
|
|
|
|
check("the scene keeps every cutter a short receipt left off", [o.name for o in block.modifiers["Kit Difference"].collection.objects] == ["Pocket", "Fit1", "Fit2", "Fit3"]
|
|
|
|
|
and [o.name for o in block.modifiers["Kit Union"].collection.objects] == ["Lump"], stack(block))
|
|
|
|
|
receipt, report = send("brokkr_kitbash.boolean", object_name="Block", cutter="Sheet", operation="INTERSECT")
|
|
|
|
|
check("a report that fits carries every row and no count", receipt["status"] == "accepted" and report["booleans"] == ROWS + [{"cutter": "Sheet", "operation": "INTERSECT"}]
|
|
|
|
|
and "booleansOmitted" not in report, report)
|
|
|
|
|
|
|
|
|
|
# --- cut-orphan and closures-ends-first -----------------------------------------------------------------------------------------
|
|
|
|
|
section('cut-orphan and closures-ends-first')
|
|
|
|
|
strut = core.build(kits["mechanical"]["parts"]["strut"], {"width": 0.09})
|
|
|
|
|
end = {name: next(s for s in strut.sockets if s["name"] == name) for name in ("end_a", "end_b")}
|
|
|
|
|
for pair, y in (("Zz", -20.0), ("Aa", -24.0)): # two closures that share no part; the open one is named to sort first
|
|
|
|
|
anchor, loose = place(f"{pair}_Anchor", "strut", "width=0.09", location=[0.0, y, 0.0]), place(f"{pair}_Loose", "strut", "width=0.09")
|
|
|
|
|
meet = Matrix((np.array(anchor.matrix_world) @ core.mate(end["end_b"], end["end_a"], 40.0)).tolist())
|
|
|
|
|
send("setObjectTransform", targetObjectName=f"{pair}_Loose", location=list(meet.translation), rotationEuler=list(meet.to_euler("XYZ")))
|
|
|
|
|
send("brokkr_kitbash.close", object_name=f"{pair}_Loose", socket="end_a", other_name=f"{pair}_Anchor", other_socket="end_b")
|
|
|
|
|
send("brokkr_kitbash.set_params", object_name="Aa_Anchor", params="length=0.9") # opens Aa's closure
|
|
|
|
|
receipt, report = send("brokkr_kitbash.set_params", object_name="Zz_Anchor", params="width=0.09")
|
|
|
|
|
check("closures-ends-first: set_params on a part whose own closure holds lists it before another part's closure that is open, though that one sorts first by holds and by name",
|
|
|
|
|
receipt["status"] == "accepted" and report["closures"] == [{"part": "Zz_Loose", "to": "Zz_Anchor", "holds": True}, {"part": "Aa_Loose", "to": "Aa_Anchor", "holds": False}],
|
|
|
|
|
report and report.get("closures"))
|
|
|
|
|
ghost = bpy.data.objects["Aa_Anchor"]
|
|
|
|
|
with bpy.context.temp_override(selected_objects=[ghost], active_object=ghost):
|
|
|
|
|
bpy.ops.object.delete() # the ordinary Delete: Aa_Loose's closure still points at it, so it stays in the file, in no collection
|
|
|
|
|
tie = place("Tie", "strut", "width=0.09")
|
|
|
|
|
check("a part deleted with the Delete operator that a closure points to is still in the file", bpy.data.objects.get("Aa_Anchor") is not None and not ghost.users_collection, list(bpy.data.objects.keys()))
|
|
|
|
|
GONE = "'Aa_Anchor' is in no collection (a deleted object something still points to)"
|
|
|
|
|
refused("cut-orphan: attach onto a deleted part's name", "brokkr_kitbash.attach", {"object_name": "Tie", "socket": "end_a", "parent_name": "Aa_Anchor", "parent_socket": "end_a"}, GONE)
|
|
|
|
|
refused("attach of a deleted part", "brokkr_kitbash.attach", {"object_name": "Aa_Anchor", "socket": "end_a", "parent_name": "Tie", "parent_socket": "end_a"}, GONE)
|
|
|
|
|
refused("set_params on a deleted part", "brokkr_kitbash.set_params", {"object_name": "Aa_Anchor", "params": "length=1.0"}, GONE)
|
|
|
|
|
refused("report of a deleted part", "brokkr_kitbash.report", {"object_name": "Aa_Anchor"}, GONE)
|
|
|
|
|
refused("cut on a deleted part", "brokkr_kitbash.cut", {**RAY, "object_name": "Aa_Anchor"}, GONE)
|
|
|
|
|
refused("boolean on a deleted part", "brokkr_kitbash.boolean", {"object_name": "Aa_Anchor", "cutter": "Lump"}, GONE)
|
|
|
|
|
refused("boolean with a deleted part as the cutter", "brokkr_kitbash.boolean", {"object_name": "Tie", "cutter": "Aa_Anchor"}, GONE)
|
|
|
|
|
refused("close onto a deleted part", "brokkr_kitbash.close", {"object_name": "Tie", "socket": "end_a", "other_name": "Aa_Anchor", "other_socket": "end_a"}, GONE)
|
|
|
|
|
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:
|
|
|
|
|
R["ok"] = all(c["ok"] for c in R["checks"])
|
|
|
|
|
R["readings"] = {name: float(f"{value:.2g}") for name, value in sorted(R["readings"].items())}
|
|
|
|
|
Path(OUT + ".result.json").write_text(json.dumps(R, indent=1, default=str), encoding="utf-8")
|
|
|
|
|
for c in R["checks"]:
|
|
|
|
|
print("CHECK", "ok " if c["ok"] else "FAIL", c["name"], "" if c["ok"] else c["detail"], flush=True)
|
|
|
|
|
print("READINGS", R["readings"], flush=True)
|
|
|
|
|
sys.exit(0 if R["ok"] else 1)
|
|
|
|
|
|