diff --git a/surfaces/blender/experiments/mechs/mechlib.py b/surfaces/blender/experiments/mechs/mechlib.py index df91188..22fc1d0 100644 --- a/surfaces/blender/experiments/mechs/mechlib.py +++ b/surfaces/blender/experiments/mechs/mechlib.py @@ -53,7 +53,7 @@ from mathutils.bvhtree import BVHTree SURFACE = Path(os.environ["BROKKR_SURFACE"]) if os.environ.get("BROKKR_SURFACE") else Path(__file__).resolve().parents[2] # the add-on tree: a cut's worktree when set FLIP = Matrix.Diagonal((-1.0, 1.0, -1.0, 1.0)) SHELLS = {} -FOLD_MARGIN = 1.4 # a shell whose fold estimate stands under this much of its thickness is printed (docs/kitbash.md, Thickness at a crease) +FOLDED = {} # shell name: the inner faces of its wall that fold, as brokkr_kitbash.shell counted them at the call (count_folds) MATS = {} KB = None @@ -698,8 +698,9 @@ def shell_action(name, sheet, build, mat, thickness=0.05, offset=-1.0, levels=3, `flip`, so the wall stays on the plate's inside; on a sheet that is itself mirrored about x it changes nothing. A to_host that shears is refused. thickness, bevel, and the sizes of cutters and ribs are metres as stated, at any to_host. Cut it with cuts_action, frame it with ribs_action: both take rays and planes in the component's - frame. The action owns the cage: nothing here builds geometry. Prints the action's fold estimate when the wall - is expected to fold (docs/kitbash.md, Thickness at a crease).""" + frame. The action owns the cage: nothing here builds geometry. The action counts the wall's folded inner faces + (count_folds; docs/kitbash.md, Thickness at a crease): a count over 0 is printed here and fails the build at + shells_sound().""" turn, stretch = _turn_and_stretch(name, Matrix.Identity(4) if build.to_host is None else Matrix(build.to_host)) sx, sy, sz = (stretch[k][k] for k in range(3)) sheet = dict(sheet) @@ -709,12 +710,12 @@ def shell_action(name, sheet, build, mat, thickness=0.05, offset=-1.0, levels=3, sheet["rings"] = [[[sx * p[0], sy * p[1], sz * p[2]] for p in ring] for ring in sheet["rings"]] if sx < 0: sheet["flip"] = not sheet.get("flip", False) - result = bpy.ops.brokkr_kitbash.shell(object_name=name, sheet=json.dumps(sheet), thickness=thickness, offset=offset, levels=levels, bevel=bevel) + result = bpy.ops.brokkr_kitbash.shell(object_name=name, sheet=json.dumps(sheet), thickness=thickness, offset=offset, levels=levels, bevel=bevel, count_folds=True) if "FINISHED" not in result: raise SystemExit(f"shell {name}: {result}") - fold = json.loads(getattr(bpy.context.window_manager, KB.RESULT))["fold"] - if fold is not None and fold["margin"] < FOLD_MARGIN: - print(f"FOLD {name}: thickness {thickness:g} at levels {levels} is {1 / fold['margin']:.2f} of the fold onset {fold['onset']:.4g} at cage edge {fold['edge']} (crease {fold['weight']:g})", flush=True) + FOLDED[name] = json.loads(getattr(bpy.context.window_manager, KB.RESULT))["folded"] + if FOLDED[name]: + print(f"FOLD {name}: {FOLDED[name]} inner faces of the wall fold at thickness {thickness:g}, levels {levels}", flush=True) obj = bpy.data.objects[name] if build.host is not None: obj.parent = build.host @@ -726,6 +727,25 @@ def shell_action(name, sheet, build, mat, thickness=0.05, offset=-1.0, levels=3, return obj +def shells_sound(): + """Every shell shell_action made, as built: the folded inner faces the action counted, and the edges of its whole + evaluated stack (wall, cuts, bevel) that do not join exactly two faces. Prints a line a shell and the totals, + and stops the build when either is over 0: a wall that passes through itself, or a cut that left the plate open.""" + update() + depsgraph = bpy.context.evaluated_depsgraph_get() + folded = unsound = 0 + for name in sorted(FOLDED): + mesh = bmesh.new() + mesh.from_mesh(bpy.data.objects[name].evaluated_get(depsgraph).data) + loose = sum(1 for edge in mesh.edges if not edge.is_manifold) + mesh.free() + folded, unsound = folded + FOLDED[name], unsound + loose + print(f"SHELL {name} folded {FOLDED[name]} openEdges {loose}", flush=True) + print(f"SHELLS {len(FOLDED)} folded {folded} openEdges {unsound}", flush=True) + if folded or unsound: + raise SystemExit(f"shells: {folded} folded inner faces and {unsound} open edges after cuts; thin the wall where it folds, or move the cut") + + def cuts_action(name, cuts): """Panel lines, insets and rim notches on a shell by brokkr_kitbash.cut_many: `cuts` is its list, rays in the component's frame (carried into the shell's by the stretch shell_action wrote into it; cutter sizes are metres @@ -1912,6 +1932,7 @@ def field_views(name, t0, hero=(30.0, 3.0), rear=(180.0, 6.0), hero_size=(2000, assert out.is_absolute() out.mkdir(parents=True, exist_ok=True) print("build s", round(time.time() - t0, 1), "objects", len(bpy.data.objects), "faces", sum(len(o.data.polygons) for o in bpy.data.objects if o.type == "MESH")) + shells_sound() rig, cam, centre, radius = stage_field(24 if quick else samples) size = (1000, 1200) if quick else hero_size cams = {"hero": {"lens": 60.0, "margin": 0.86, **(hero_cam or {})}, "rear": {"lens": 60.0, "margin": 0.86, **(rear_cam or {})}, "front": dict(lens=60.0, margin=0.86)} diff --git a/surfaces/blender/experiments/mechs/seraph_parts.py b/surfaces/blender/experiments/mechs/seraph_parts.py index f522c53..f2be85b 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, "khaki", thickness=0.033, levels=2, bevel=0.012) + M.shell_action(name, breast, b, "khaki", thickness=0.026, levels=2, bevel=0.012) # its first face folds at 0.035, and the cuts leave open edges from 0.032 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.018", "origin": [-0.34, 2.9, 2.55], **upper}, @@ -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, "khaki", thickness=0.032, levels=2, bevel=0.012) + M.shell_action(name, cap, b, "khaki", thickness=0.025, levels=2, bevel=0.012) # its first face folds at 0.033, and the cuts leave open edges from 0.0301 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.016", "origin": [-3, 0.32, 0.42], **side},