brokkr_kitbash.shell: count_folds counts the folded faces of the evaluated wall; the cage estimate is gone
The fold receipt read from the cage ({onset, margin, edge, weight}) was no
bound in either direction: seeded lofts fold at 0.03 to 0.44 of it, and it
warned on Seraph plates that do not fold. core.fold_depths and the receipt are
deleted. With count_folds, shell evaluates the wall alone (Kit Subsurf and Kit
Solidify, every other modifier hidden for the reading and shown again) and
reports folded: inner faces with a corner turned to run with their outer
twin's normal. Without it folded is null and nothing is evaluated. Measured:
3.9 ms on a new plate of 1600 subdivided faces; nothing separable on a rebuild
under six cutters (0.94 s against 0.92 s).
Live kitbash_faceted holds the count to its own, face for face, on the wedge,
on three of Soul's seeded lofts (seed 5185 offset -1, 5101 offset 0, 5196
offset 1; tests/fixtures/fold_lofts.json) and on a rebuild under cutters.
Mutants caught there: never folded, all corners for any, stack left hidden.
docs/kitbash.md: folded 0 is not yet a wall an Exact Boolean takes cleanly;
on the Seraph's cap and breast it left open edges from 0.91 of the first
folding thickness, on one hand of a mirrored pair.
Finding: aetheria-release:finding:cut-kit-faceted-shell.s3.fold-receipt-margin-is-not-a-bound
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
d3c68edf79
commit
617eb2acbc
8 changed files with 735 additions and 127 deletions
|
|
@ -57,6 +57,7 @@ solves a loop: a closure never places a part, and a report says how far its two
|
|||
bl_info = {"name": "Brokkr Kitbash", "author": "GameCult", "version": (0, 1, 0), "blender": (5, 3, 0),
|
||||
"category": "Object", "description": "Parametric machine parts from kits, with socket frames; agent-callable through Brokkr."}
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
import math
|
||||
|
||||
|
|
@ -1304,6 +1305,7 @@ class BROKKR_KITBASH_OT_shell(PolishOperator):
|
|||
offset: bpy.props.FloatProperty(name="Offset", default=-1.0, min=-1.0, max=1.0, description="-1: the wall grows inward from the designed surface; 1: outward")
|
||||
levels: bpy.props.IntProperty(name="Levels", default=3, min=1, max=4, description="Subdivision levels")
|
||||
bevel: bpy.props.FloatProperty(name="Bevel", default=0.0, min=0.0, max=0.1, description="Width of the Kit Bevel on the plate's edges; 0: none")
|
||||
count_folds: bpy.props.BoolProperty(name="Count Folds", default=False, description="Evaluate the wall and report how many of its inner faces fold")
|
||||
|
||||
# the action table states thickness from 0.001: a float property rounds 0.001 up, so its bound stands just under
|
||||
@kit_work
|
||||
|
|
@ -1316,6 +1318,13 @@ class BROKKR_KITBASH_OT_shell(PolishOperator):
|
|||
raise Refused(f"An object named {obj.name!r} exists and is no shell (it carries no {SHELL}): shell rebuilds only what shell made; nothing changed.")
|
||||
rigid(obj)
|
||||
own_mesh(obj, "rebuilding")
|
||||
if self.count_folds:
|
||||
unseen = [modifier.name for modifier in obj.modifiers if modifier.name in (SUBSURF, SOLIDIFY) and not modifier.show_viewport]
|
||||
if unseen:
|
||||
raise Refused(f"{obj.name!r} has its {' and '.join(unseen)} hidden in viewports, and count_folds reads the wall those two make. "
|
||||
"Show them, or leave count_folds off; nothing changed.")
|
||||
with self.wall_alone(obj):
|
||||
evaluable(context, obj)
|
||||
try:
|
||||
document = json.loads(self.sheet)
|
||||
except ValueError as error:
|
||||
|
|
@ -1355,20 +1364,46 @@ class BROKKR_KITBASH_OT_shell(PolishOperator):
|
|||
corners = built.V[built.faces.reshape(-1, 4)]
|
||||
facing = np.cross(corners[:, 2] - corners[:, 0], corners[:, 3] - corners[:, 1]).sum(axis=0) # twice the quads' vector areas, summed
|
||||
cancels = np.linalg.norm(facing) <= 1e-9 * np.linalg.norm(np.cross(corners[:, 2] - corners[:, 0], corners[:, 3] - corners[:, 1]), axis=1).sum()
|
||||
pairs, depths, ridges, weights = core.fold_depths(built, self.levels)
|
||||
behind, front = 0.5 * (1.0 - self.offset), 0.5 * (1.0 + self.offset) # the wall's share behind the designed surface, and in front of it
|
||||
with np.errstate(divide="ignore"):
|
||||
onsets = depths / np.where(ridges, behind, front) # the thickness at which each cage edge's concave side holds its fold depth
|
||||
first = int(onsets.argmin()) if len(onsets) and np.isfinite(onsets.min()) else None
|
||||
fold = None if first is None else {
|
||||
"onset": round(float(onsets[first]), 6), "margin": round(float(onsets[first]) / self.thickness, 4),
|
||||
"edge": [[int(v) // built.points, int(v) % built.points] for v in pairs[first]], "weight": round(float(weights[first]), 6)}
|
||||
return {"object": obj.name, "rebuilt": rebuilt, "rings": built.rings, "points": built.points, "cageFaces": cage_faces, "creases": len(built.creases),
|
||||
"fold": fold,
|
||||
"folded": self.folded_faces(context, obj, cage_faces * 4 ** self.levels) if self.count_folds else None,
|
||||
"corners": len(built.corners), "subdividedFaces": cage_faces * 4 ** self.levels,
|
||||
"facing": None if cancels else [round(float(v), 6) for v in facing / np.linalg.norm(facing)],
|
||||
"thickness": round(self.thickness, 6), "offset": round(self.offset, 6), "levels": self.levels, "children": sorted(child.name for child in obj.children)}
|
||||
|
||||
@staticmethod
|
||||
@contextlib.contextmanager
|
||||
def wall_alone(shell):
|
||||
"""The shell with every modifier but its Kit Subsurf and Kit Solidify hidden, and shown again on the way out: what
|
||||
an evaluation inside reads is the wall, and no Boolean runs for it."""
|
||||
hidden = [modifier for modifier in shell.modifiers if modifier.name not in (SUBSURF, SOLIDIFY) and modifier.show_viewport]
|
||||
for modifier in hidden:
|
||||
modifier.show_viewport = False
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
for modifier in hidden:
|
||||
modifier.show_viewport = True
|
||||
|
||||
@staticmethod
|
||||
def folded_faces(context, shell, faces: int) -> int:
|
||||
"""How many inner faces of a shell's wall fold, counted on the wall as Blender evaluates it (wall_alone): Kit
|
||||
Solidify lists the `faces` subdivided faces of the designed surface, then their inner twins in the same order,
|
||||
each wound the other way. An inner face folds when the turn at any of its corners runs with its outer twin's
|
||||
normal instead of against it: the corner has passed over its neighbour. 0 is a wall that nowhere folds."""
|
||||
with BROKKR_KITBASH_OT_shell.wall_alone(shell):
|
||||
_, evaluated = evaluable(context, shell)
|
||||
mesh = evaluated.to_mesh()
|
||||
try:
|
||||
points, corners = np.zeros(3 * len(mesh.vertices)), np.zeros(len(mesh.loops), dtype=np.int32)
|
||||
mesh.vertices.foreach_get("co", points)
|
||||
mesh.loops.foreach_get("vertex_index", corners)
|
||||
quads = points.reshape(-1, 3)[corners[:8 * faces].reshape(2, faces, 4)]
|
||||
outward = np.cross(quads[0, :, 2] - quads[0, :, 0], quads[0, :, 3] - quads[0, :, 1])
|
||||
turns = np.cross(quads[1] - np.roll(quads[1], 1, axis=1), np.roll(quads[1], -1, axis=1) - quads[1])
|
||||
return int((np.einsum("fkc,fc->fk", turns, outward) > 0).any(axis=1).sum())
|
||||
finally:
|
||||
evaluated.to_mesh_clear()
|
||||
|
||||
|
||||
class BROKKR_KITBASH_OT_describe(PolishOperator):
|
||||
"""List a kit's parts, or one part: params with type, bounds, default and doc, and sockets in the part's frame
|
||||
|
|
|
|||
|
|
@ -719,7 +719,7 @@
|
|||
},
|
||||
{
|
||||
"name": "brokkr_kitbash.shell",
|
||||
"doc": "Make a faceted, hollow armor shell: the cage that cut, cut_many and ribs work on. sheet is a JSON object {\"rings\": 2 to 64 rings of 2 to 64 [x, y, z] points with equal counts, in the shell's own frame; \"closed\": each ring joins back to its first point (false); \"mirror\": each ring is authored from its point 0 on x = 0 toward +x and mirrored across x (false; not with closed); \"creases\": [{\"ring\": i, \"from\": a, \"to\": b, \"weight\": w} | {\"column\": j, \"from\": a, \"to\": b, \"weight\": w} | {\"point\": [i, j], \"weight\": w}], runs of ring or column edges and single points, weights 0 to 1, 1 a hard facet edge; \"rim\": the weight of every boundary edge no run names (1); \"flip\": reverse every face (false)}. Quads lie between neighbouring rings; the surface faces out where, seen from outside, a ring's points run left to right and the rings run upward. The cage is subdivided (Kit Subsurf, creases kept) and given a wall (Kit Solidify, rim filled). On an object that is already a shell the cage is rebuilt in place: the object, its cutters, ribs, Booleans and material slots stay, and ribs are stale until run again. Refuses before it writes anything, naming the field and index. Reports object, rebuilt, rings, points, cageFaces, creases, fold ({onset, margin, edge, weight}: the thickness at which the cage says the wall first folds over itself beside an edge, onset over the thickness asked, the edge as two [ring, point] and its crease; null where no edge can fold; an estimate from the cage, margin under 1 is a folded wall), corners, subdividedFaces, facing, thickness, offset, levels and children.",
|
||||
"doc": "Make a faceted, hollow armor shell: the cage that cut, cut_many and ribs work on. sheet is a JSON object {\"rings\": 2 to 64 rings of 2 to 64 [x, y, z] points with equal counts, in the shell's own frame; \"closed\": each ring joins back to its first point (false); \"mirror\": each ring is authored from its point 0 on x = 0 toward +x and mirrored across x (false; not with closed); \"creases\": [{\"ring\": i, \"from\": a, \"to\": b, \"weight\": w} | {\"column\": j, \"from\": a, \"to\": b, \"weight\": w} | {\"point\": [i, j], \"weight\": w}], runs of ring or column edges and single points, weights 0 to 1, 1 a hard facet edge; \"rim\": the weight of every boundary edge no run names (1); \"flip\": reverse every face (false)}. Quads lie between neighbouring rings; the surface faces out where, seen from outside, a ring's points run left to right and the rings run upward. The cage is subdivided (Kit Subsurf, creases kept) and given a wall (Kit Solidify, rim filled). On an object that is already a shell the cage is rebuilt in place: the object, its cutters, ribs, Booleans and material slots stay, and ribs are stale until run again. A thickness the cage cannot hold is not refused: the wall folds over itself beside a tight crease or rim corner, and a cut there is unsound. count_folds evaluates the wall alone (Kit Subsurf and Kit Solidify, no Boolean; 4 ms on a plate of 1600 subdivided faces) and counts the folded inner faces; nothing else in the report reads an evaluated mesh, and no figure of the cage bounds the fold. Refuses before it writes anything, naming the field and index. Reports object, rebuilt, rings, points, cageFaces, creases, folded (null unless count_folds: then the number of the wall's inner faces that fold over, counted on the evaluated wall; 0 is a wall with no folded face, which an Exact Boolean can still fail on just short of a fold: read nonManifoldEdges after cutting), corners, subdividedFaces, facing, thickness, offset, levels and children.",
|
||||
"changesScene": true,
|
||||
"editModeSafe": false,
|
||||
"result": "brokkr_mesh_polish_result",
|
||||
|
|
@ -771,6 +771,12 @@
|
|||
"maximum": 0.1,
|
||||
"default": 0,
|
||||
"doc": "width of the Kit Bevel on the plate's edges; 0: none"
|
||||
},
|
||||
{
|
||||
"name": "count_folds",
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"doc": "evaluate the wall (Kit Subsurf and Kit Solidify alone) and report folded, the number of its inner faces that fold over"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1134,43 +1134,6 @@ def sheet(document: Any) -> Sheet:
|
|||
corners=np.array([key for key, _ in pinned], dtype=np.int64), corner_weights=np.array([w for _, w in pinned], dtype=np.float64), rings=R, points=N)
|
||||
|
||||
|
||||
def fold_depths(built: Sheet, levels: int) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
|
||||
"""Where an even wall on a shell's cage would fold, from the cage alone: for every cage edge between two quads,
|
||||
(pairs (E, 2) of vertex indices, depth (E,), ridge (E,), weight (E,)). depth is the wall depth on the edge's
|
||||
concave side at which the wall's far face first folds over itself beside the edge when the edge is a full
|
||||
crease between flat facets: (W / 2^levels) / tan(phi), W the lesser perpendicular reach of the two quads from
|
||||
the edge (the narrower facet binds) and phi half the angle between their normals; infinite where they are
|
||||
coplanar. ridge: the facets fall away from their normals, so the concave side is behind the surface (a wall
|
||||
grown inward); else it is in front. weight is the edge's crease, 0 where it has none: under a full crease a
|
||||
softer edge folds later than its depth, never sooner."""
|
||||
quads = built.faces.reshape(-1, 4)
|
||||
V = built.V
|
||||
normals = np.cross(V[quads[:, 2]] - V[quads[:, 0]], V[quads[:, 3]] - V[quads[:, 1]])
|
||||
normals /= np.linalg.norm(normals, axis=1)[:, None]
|
||||
centres = V[quads].mean(axis=1)
|
||||
sides = {}
|
||||
for face, quad in enumerate(quads):
|
||||
for k in range(4):
|
||||
a, b = int(quad[k]), int(quad[(k + 1) % 4])
|
||||
sides.setdefault((min(a, b), max(a, b)), []).append((face, int(quad[(k + 2) % 4]), int(quad[(k + 3) % 4])))
|
||||
creased = {(int(a), int(b)): float(w) for (a, b), w in zip(built.creases, built.weights)}
|
||||
pairs, depths, ridges, weights = [], [], [], []
|
||||
for (a, b), faces in sorted(sides.items()):
|
||||
if len(faces) != 2:
|
||||
continue
|
||||
along = V[b] - V[a]
|
||||
along /= np.linalg.norm(along)
|
||||
reach = min(float(np.linalg.norm((V[v] - V[a]) - along * ((V[v] - V[a]) @ along))) for _, c, d in faces for v in (c, d))
|
||||
(f0, _, _), (f1, _, _) = faces
|
||||
middle = 0.5 * (V[a] + V[b])
|
||||
phi = 0.5 * math.acos(float(np.clip(normals[f0] @ normals[f1], -1.0, 1.0)))
|
||||
pairs.append((a, b))
|
||||
depths.append(reach / 2 ** levels / math.tan(phi) if phi > 1e-9 else math.inf)
|
||||
ridges.append(bool(normals[f0] @ (centres[f1] - middle) + normals[f1] @ (centres[f0] - middle) < 0))
|
||||
weights.append(creased.get((a, b), 0.0))
|
||||
return np.array(pairs, dtype=np.int64).reshape(-1, 2), np.array(depths), np.array(ridges, dtype=bool), np.array(weights)
|
||||
|
||||
|
||||
# --- reports -------------------------------------------------------------------------------------------------
|
||||
|
||||
def rows(matrix) -> list[list[float]]:
|
||||
|
|
|
|||
|
|
@ -351,9 +351,9 @@ The object carries the cage, `crease_edge` and `crease_vert`, and the modifiers
|
|||
used) then `Kit Solidify` (`thickness`, `offset`, even, rim filled), then any Booleans `cut` adds, then the `Kit
|
||||
Bevel` when `bevel` is over 0. `kit_shell` on it is the request, and it owns the cage as `kit_params` owns a
|
||||
part's mesh: an edit of the cage by hand is lost at the next `shell` call. `shell` reports `object`, `rebuilt`,
|
||||
`rings`, `points`, `cageFaces`, `creases` (edges with a weight over 0), `fold` (see Thickness at a crease),
|
||||
`corners`, `subdividedFaces`, `facing`, `thickness`, `offset`, `levels` and `children`, all facts of the cage: it
|
||||
reads no evaluated mesh.
|
||||
`rings`, `points`, `cageFaces`, `creases` (edges with a weight over 0), `folded` (see Thickness at a crease),
|
||||
`corners`, `subdividedFaces`, `facing`, `thickness`, `offset`, `levels` and `children`. All but `folded` are facts
|
||||
of the cage: without `count_folds`, `shell` reads no evaluated mesh.
|
||||
|
||||
**Rebuilding.** `shell` on a name that is already a shell rewrites its cage in place. The object, its mesh
|
||||
datablock, its material slots, its cutters, its ribs and its Booleans stay, so a plate can be reshaped after it is
|
||||
|
|
@ -370,7 +370,7 @@ the outline, and the plate left between two bites is a tab.
|
|||
it; a rib deeper than the room a tight crease leaves is refused with the size to lower.
|
||||
|
||||
**Thickness at a crease.** `shell` takes any `thickness` in its range and does not refuse one the cage cannot
|
||||
hold: it reads no evaluated mesh, and the limit is a fact of the subdivided one. Even thickness moves a vertex on a
|
||||
hold: the limit is a fact of the subdivided mesh, not of the cage. Even thickness moves a vertex on a
|
||||
full crease along the crease's bisector, which slides it `thickness` x tan(phi) across each facet, phi being half
|
||||
the angle between the two facets' normals; the vertices beside it move straight in. Where that slide is longer than
|
||||
the first row of subdivided faces, the wall's far face folds over itself beside the crease: at a wall depth over
|
||||
|
|
@ -384,16 +384,27 @@ uncreased edge folds too, at 1.17 to 4.2 of it. The fold is inside the wall and
|
|||
designed surface is unchanged and the mesh has no open or non-manifold edge, but the solid passes through itself
|
||||
there, and a cut through that place is untested.
|
||||
|
||||
`shell` reports this at the call, from the cage: `fold` is `{onset, margin, edge, weight}`, or null where no cage
|
||||
edge has a wall on its concave side. `onset` is the least `thickness` at which the figure above says some cage edge
|
||||
folds, every edge between two quads taken as a full crease between flat facets, and the wall's share on that edge's
|
||||
concave side taken from `offset`; `margin` is `onset` over the `thickness` asked, so under 1 the wall is expected to
|
||||
fold; `edge` is that edge as two `[ring, point]` (points as built: 2C - 1 on a mirrored ring), and `weight` its
|
||||
crease. It is an estimate: a `weight` under 1 folds later than `onset`, and where a crease runs out to the rim
|
||||
through a tapering quad the wall can fold sooner. On the Seraph's fourteen creased plates the evaluated wall first
|
||||
folded at 0.74 to 1.2 of `onset` in thirteen and at 2.6 of it in one, whose binding edge had a crease of 0.6
|
||||
(`experiments/mechs`, 2026-12-02). Keep `margin` over about 1.4 where a plate is cut near a crease, with a thinner
|
||||
wall, fewer `levels` or wider facets, and count the turned inner faces of the evaluated wall when it matters.
|
||||
No figure read from the cage bounds this. The flat-facet figure above, taken over every cage edge, is neither a
|
||||
floor nor a ceiling on a real plate: on seeded lofts of planar trapezoid facets with partial crease runs the
|
||||
evaluated wall first folded at 0.44 of it with the wall grown inward, at 0.03 of it at `offset` 0 and at 0.08 of it
|
||||
grown outward, and on the Seraph's plates a first face normal turned at 0.74 to 2.6 of it (`tests/fixtures/fold_lofts.json` holds three of
|
||||
those lofts; 2026-12-02). So `shell` counts instead of estimating: with `count_folds` it evaluates the wall alone,
|
||||
`Kit Subsurf` and `Kit Solidify` with every other modifier hidden for the reading and shown again, and reports
|
||||
`folded`, the number of the wall's inner faces that fold. An inner face folds when the turn at any of its corners
|
||||
runs with its outer twin's normal: the corner has passed over its neighbour. That is sooner than the face's own
|
||||
normal turning: on the Seraph's cap a corner turned at 0.033 and no face normal had at 0.0416. Without `count_folds`, `folded` is null
|
||||
and nothing is evaluated. The count cost 3.9 ms on a new plate of 1600 subdivided faces (a call of 7.7 ms against
|
||||
3.8 ms), and nothing measurable on a rebuild under six cutters (0.94 s against 0.92 s, the call's own Boolean),
|
||||
medians of three interleaved calls in the live suite (Blender 5.3 on Starfire). On a shell whose `Kit Subsurf` or
|
||||
`Kit Solidify` is hidden in viewports `count_folds` is refused before anything is written.
|
||||
|
||||
`folded` 0 is not yet a wall an Exact Boolean takes cleanly. Short of the fold the inner quads at a tight rim corner
|
||||
are twisted, and the Boolean, which cuts quads into triangles, can read the wall as passing through itself and
|
||||
leave edges with four faces. On the Seraph's cap that began at 0.91 of the thickness at which the first face
|
||||
folds (0.0301 against 0.033), on the left cap and not on its mirror, the right; on its breast plate at 0.91 as
|
||||
well (0.032 against 0.035). Read `nonManifoldEdges` after cutting (`boolean`, `apply`, or a count on the evaluated
|
||||
mesh), and keep `thickness` clear of the first folding one with a thinner wall, fewer `levels` or wider facets at
|
||||
the corner.
|
||||
|
||||
Refused, each before anything is written and naming the field and index: a missing or unknown key; a non-finite
|
||||
number; fewer than 2 or more than 64 rings or points; rings of unequal counts; a quad under 1e-8 m2 (a collapsed
|
||||
|
|
@ -598,7 +609,7 @@ vertices overflow.
|
|||
| `brokkr_kitbash.cut_many` | `object_name` (any mesh), `cuts` (a JSON array of 1 to 64 cutters) | `cut` for several cutters in one action: all placed or none, one evaluation of the target afterwards. Reports `object`, `cutters` (names) and `booleans` (with `booleansOmitted`, as `boolean`). |
|
||||
| `brokkr_kitbash.apply` | `object_name` | Bakes the evaluated mesh into the kit part and clears its modifiers and the collections its Booleans held. Refuses a part with no modifiers, a mesh another object shares and a part Blender does not evaluate. Reports the part, `faces`, `volume`, `nonManifoldEdges` and the `cutters` it no longer refers to. |
|
||||
| `brokkr_kitbash.ribs` | `object_name` (the cage), `ribs_name`, `planes` (a JSON array of 1 to 64 `{origin, normal}`, up to 16000 characters), `standoff`, `depth`, `thickness`, `step`, `holes`, `posts`, `post_r`, `bridge`, `clearance`, `longerons` (a JSON array of 0 to 16 `{origin, axis, toward}`, up to 8000 characters), `longeron`, `longeron_w`, `longeron_h`, `longeron_t` | Derives ribs, lightening holes, posts and longerons from the cage as it is cut, as one mesh object under it. Refuses before it writes anything, naming the plane or longeron. Reports `object`, `ribs`, `thickness`, `sections: [{plane, chains, pieces, length, open}]`, `posts`, `holes`, `longerons: [{index, stations}]` (trimmed to a receipt, with `longeronsOmitted`), `faces`, `volume` and `nonManifoldEdges`. |
|
||||
| `brokkr_kitbash.shell` | `object_name`, `sheet` (a JSON object `{rings, closed, mirror, creases, rim, flip}`, up to 32000 characters), `thickness`, `offset`, `levels`, `bevel` | Makes a faceted, hollow armor shell from a loft of rings with crease runs, or rebuilds a shell's cage in place under its cutters and ribs. Refuses before it writes anything, naming the field and index. Reports `object`, `rebuilt`, `rings`, `points`, `cageFaces`, `creases`, `fold` (`{onset, margin, edge, weight}`: the thickness at which the cage says the wall first folds beside an edge, or null), `corners`, `subdividedFaces`, `facing`, `thickness`, `offset`, `levels` and `children`. |
|
||||
| `brokkr_kitbash.shell` | `object_name`, `sheet` (a JSON object `{rings, closed, mirror, creases, rim, flip}`, up to 32000 characters), `thickness`, `offset`, `levels`, `bevel`, `count_folds` | Makes a faceted, hollow armor shell from a loft of rings with crease runs, or rebuilds a shell's cage in place under its cutters and ribs. Refuses before it writes anything, naming the field and index. Reports `object`, `rebuilt`, `rings`, `points`, `cageFaces`, `creases`, `folded` (with `count_folds`, the number of the evaluated wall's inner faces that fold; else null), `corners`, `subdividedFaces`, `facing`, `thickness`, `offset`, `levels` and `children`. |
|
||||
|
||||
`params` is `name=value; name=value`; a param left out takes the part's default (`place_part`) or keeps its stored
|
||||
value (`set_params`). A value outside its bounds is refused with the bounds in the message.
|
||||
|
|
|
|||
543
surfaces/blender/tests/fixtures/fold_lofts.json
vendored
Normal file
543
surfaces/blender/tests/fixtures/fold_lofts.json
vendored
Normal file
|
|
@ -0,0 +1,543 @@
|
|||
{
|
||||
"about": "Lofts of planar trapezoid facets on which a shell's wall folds well under any figure read from the cage: the seeded lofts of Soul's probe of 2026-12-02 (aetheria-release:verdict:cut-kit-faceted-shell.s3), seed, levels and offset as drawn there. thickness is one at which the evaluated wall folds; holds, where the action's range reaches it, one at which it does not.",
|
||||
"lofts": [
|
||||
{
|
||||
"seed": 5185,
|
||||
"levels": 1,
|
||||
"offset": -1.0,
|
||||
"thickness": 0.006342,
|
||||
"holds": 0.001,
|
||||
"sheet": {
|
||||
"rings": [
|
||||
[
|
||||
[
|
||||
-0.824534,
|
||||
0.0,
|
||||
-0.055726
|
||||
],
|
||||
[
|
||||
-0.20124,
|
||||
0.0,
|
||||
-0.555671
|
||||
],
|
||||
[
|
||||
0.277571,
|
||||
0.0,
|
||||
-0.326276
|
||||
],
|
||||
[
|
||||
0.355141,
|
||||
0.0,
|
||||
-0.095203
|
||||
],
|
||||
[
|
||||
0.451529,
|
||||
0.0,
|
||||
-0.526972
|
||||
],
|
||||
[
|
||||
0.730665,
|
||||
0.0,
|
||||
-0.126214
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.644054,
|
||||
0.57461,
|
||||
-0.007851
|
||||
],
|
||||
[
|
||||
-0.166195,
|
||||
0.57461,
|
||||
-0.391143
|
||||
],
|
||||
[
|
||||
0.200893,
|
||||
0.57461,
|
||||
-0.215272
|
||||
],
|
||||
[
|
||||
0.260364,
|
||||
0.57461,
|
||||
-0.038117
|
||||
],
|
||||
[
|
||||
0.334261,
|
||||
0.57461,
|
||||
-0.36914
|
||||
],
|
||||
[
|
||||
0.548265,
|
||||
0.57461,
|
||||
-0.061892
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.670812,
|
||||
0.958364,
|
||||
0.100578
|
||||
],
|
||||
[
|
||||
-0.338388,
|
||||
0.958364,
|
||||
-0.16606
|
||||
],
|
||||
[
|
||||
-0.083022,
|
||||
0.958364,
|
||||
-0.043715
|
||||
],
|
||||
[
|
||||
-0.041652,
|
||||
0.958364,
|
||||
0.079523
|
||||
],
|
||||
[
|
||||
0.009755,
|
||||
0.958364,
|
||||
-0.150754
|
||||
],
|
||||
[
|
||||
0.158628,
|
||||
0.958364,
|
||||
0.062984
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.121748,
|
||||
1.402066,
|
||||
-0.069972
|
||||
],
|
||||
[
|
||||
0.06524,
|
||||
1.402066,
|
||||
-0.219956
|
||||
],
|
||||
[
|
||||
0.208883,
|
||||
1.402066,
|
||||
-0.151137
|
||||
],
|
||||
[
|
||||
0.232154,
|
||||
1.402066,
|
||||
-0.081816
|
||||
],
|
||||
[
|
||||
0.261071,
|
||||
1.402066,
|
||||
-0.211346
|
||||
],
|
||||
[
|
||||
0.344812,
|
||||
1.402066,
|
||||
-0.091119
|
||||
]
|
||||
]
|
||||
],
|
||||
"creases": [
|
||||
{
|
||||
"ring": 1,
|
||||
"from": 4,
|
||||
"to": 5,
|
||||
"weight": 0.3
|
||||
},
|
||||
{
|
||||
"column": 3,
|
||||
"from": 0,
|
||||
"to": 3,
|
||||
"weight": 1.0
|
||||
},
|
||||
{
|
||||
"ring": 2,
|
||||
"from": 0,
|
||||
"to": 3,
|
||||
"weight": 1.0
|
||||
}
|
||||
],
|
||||
"rim": 0.5
|
||||
}
|
||||
},
|
||||
{
|
||||
"seed": 5101,
|
||||
"levels": 3,
|
||||
"offset": 0.0,
|
||||
"thickness": 0.010394,
|
||||
"holds": null,
|
||||
"sheet": {
|
||||
"rings": [
|
||||
[
|
||||
[
|
||||
-0.70481,
|
||||
0.0,
|
||||
0.07744
|
||||
],
|
||||
[
|
||||
-0.108308,
|
||||
0.0,
|
||||
0.00574
|
||||
],
|
||||
[
|
||||
0.492256,
|
||||
0.0,
|
||||
-0.339801
|
||||
],
|
||||
[
|
||||
0.608357,
|
||||
0.0,
|
||||
-0.456893
|
||||
],
|
||||
[
|
||||
0.685935,
|
||||
0.0,
|
||||
-0.379315
|
||||
],
|
||||
[
|
||||
0.817607,
|
||||
0.0,
|
||||
0.061337
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.355146,
|
||||
0.797251,
|
||||
0.328588
|
||||
],
|
||||
[
|
||||
0.181707,
|
||||
0.797251,
|
||||
0.264058
|
||||
],
|
||||
[
|
||||
0.722214,
|
||||
0.797251,
|
||||
-0.046929
|
||||
],
|
||||
[
|
||||
0.826705,
|
||||
0.797251,
|
||||
-0.152312
|
||||
],
|
||||
[
|
||||
0.896525,
|
||||
0.797251,
|
||||
-0.082492
|
||||
],
|
||||
[
|
||||
1.01503,
|
||||
0.797251,
|
||||
0.314095
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.785461,
|
||||
1.527843,
|
||||
-0.183277
|
||||
],
|
||||
[
|
||||
-0.308259,
|
||||
1.527843,
|
||||
-0.240637
|
||||
],
|
||||
[
|
||||
0.172192,
|
||||
1.527843,
|
||||
-0.51707
|
||||
],
|
||||
[
|
||||
0.265072,
|
||||
1.527843,
|
||||
-0.610743
|
||||
],
|
||||
[
|
||||
0.327135,
|
||||
1.527843,
|
||||
-0.548681
|
||||
],
|
||||
[
|
||||
0.432473,
|
||||
1.527843,
|
||||
-0.19616
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.488084,
|
||||
2.123542,
|
||||
-0.236617
|
||||
],
|
||||
[
|
||||
-0.070532,
|
||||
2.123542,
|
||||
-0.286807
|
||||
],
|
||||
[
|
||||
0.349863,
|
||||
2.123542,
|
||||
-0.528686
|
||||
],
|
||||
[
|
||||
0.431133,
|
||||
2.123542,
|
||||
-0.61065
|
||||
],
|
||||
[
|
||||
0.485438,
|
||||
2.123542,
|
||||
-0.556346
|
||||
],
|
||||
[
|
||||
0.577608,
|
||||
2.123542,
|
||||
-0.247889
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.714517,
|
||||
2.852512,
|
||||
0.062817
|
||||
],
|
||||
[
|
||||
-0.356616,
|
||||
2.852512,
|
||||
0.019796
|
||||
],
|
||||
[
|
||||
0.003723,
|
||||
2.852512,
|
||||
-0.187528
|
||||
],
|
||||
[
|
||||
0.073383,
|
||||
2.852512,
|
||||
-0.257783
|
||||
],
|
||||
[
|
||||
0.11993,
|
||||
2.852512,
|
||||
-0.211237
|
||||
],
|
||||
[
|
||||
0.198933,
|
||||
2.852512,
|
||||
0.053154
|
||||
]
|
||||
]
|
||||
],
|
||||
"creases": [
|
||||
{
|
||||
"ring": 2,
|
||||
"from": 3,
|
||||
"to": 5,
|
||||
"weight": 1.0
|
||||
},
|
||||
{
|
||||
"column": 1,
|
||||
"from": 3,
|
||||
"to": 4,
|
||||
"weight": 0.6
|
||||
},
|
||||
{
|
||||
"column": 3,
|
||||
"from": 3,
|
||||
"to": 4,
|
||||
"weight": 1.0
|
||||
}
|
||||
],
|
||||
"rim": 0.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"seed": 5196,
|
||||
"levels": 1,
|
||||
"offset": 1.0,
|
||||
"thickness": 0.00617,
|
||||
"holds": null,
|
||||
"sheet": {
|
||||
"rings": [
|
||||
[
|
||||
[
|
||||
-0.383345,
|
||||
0.0,
|
||||
-0.359947
|
||||
],
|
||||
[
|
||||
-0.036452,
|
||||
0.0,
|
||||
-0.050835
|
||||
],
|
||||
[
|
||||
0.567786,
|
||||
0.0,
|
||||
-0.587238
|
||||
],
|
||||
[
|
||||
0.622834,
|
||||
0.0,
|
||||
-0.467053
|
||||
],
|
||||
[
|
||||
0.672276,
|
||||
0.0,
|
||||
-0.379683
|
||||
],
|
||||
[
|
||||
0.730008,
|
||||
0.0,
|
||||
-0.43819
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.557286,
|
||||
0.459757,
|
||||
-0.324159
|
||||
],
|
||||
[
|
||||
-0.2711,
|
||||
0.459757,
|
||||
-0.069142
|
||||
],
|
||||
[
|
||||
0.227397,
|
||||
0.459757,
|
||||
-0.511675
|
||||
],
|
||||
[
|
||||
0.272811,
|
||||
0.459757,
|
||||
-0.412522
|
||||
],
|
||||
[
|
||||
0.313601,
|
||||
0.459757,
|
||||
-0.340441
|
||||
],
|
||||
[
|
||||
0.36123,
|
||||
0.459757,
|
||||
-0.38871
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.062837,
|
||||
0.80579,
|
||||
-0.458467
|
||||
],
|
||||
[
|
||||
0.162644,
|
||||
0.80579,
|
||||
-0.257545
|
||||
],
|
||||
[
|
||||
0.555399,
|
||||
0.80579,
|
||||
-0.606206
|
||||
],
|
||||
[
|
||||
0.591179,
|
||||
0.80579,
|
||||
-0.528086
|
||||
],
|
||||
[
|
||||
0.623317,
|
||||
0.80579,
|
||||
-0.471295
|
||||
],
|
||||
[
|
||||
0.660843,
|
||||
0.80579,
|
||||
-0.509325
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
-0.125811,
|
||||
1.151684,
|
||||
-0.10837
|
||||
],
|
||||
[
|
||||
0.038964,
|
||||
1.151684,
|
||||
0.038458
|
||||
],
|
||||
[
|
||||
0.325977,
|
||||
1.151684,
|
||||
-0.216334
|
||||
],
|
||||
[
|
||||
0.352124,
|
||||
1.151684,
|
||||
-0.159246
|
||||
],
|
||||
[
|
||||
0.375609,
|
||||
1.151684,
|
||||
-0.117745
|
||||
],
|
||||
[
|
||||
0.403032,
|
||||
1.151684,
|
||||
-0.145536
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
0.161946,
|
||||
1.542628,
|
||||
0.17642
|
||||
],
|
||||
[
|
||||
0.266014,
|
||||
1.542628,
|
||||
0.269154
|
||||
],
|
||||
[
|
||||
0.447285,
|
||||
1.542628,
|
||||
0.108233
|
||||
],
|
||||
[
|
||||
0.463799,
|
||||
1.542628,
|
||||
0.144288
|
||||
],
|
||||
[
|
||||
0.478632,
|
||||
1.542628,
|
||||
0.170499
|
||||
],
|
||||
[
|
||||
0.495952,
|
||||
1.542628,
|
||||
0.152947
|
||||
]
|
||||
]
|
||||
],
|
||||
"creases": [
|
||||
{
|
||||
"ring": 3,
|
||||
"from": 3,
|
||||
"to": 4,
|
||||
"weight": 1.0
|
||||
},
|
||||
{
|
||||
"column": 3,
|
||||
"from": 3,
|
||||
"to": 4,
|
||||
"weight": 1.0
|
||||
}
|
||||
],
|
||||
"rim": 0.5
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -30,6 +30,7 @@ import bpy
|
|||
import numpy as np
|
||||
from mathutils import Matrix, Vector
|
||||
from mathutils.bvhtree import BVHTree
|
||||
from mathutils.geometry import normal as triangle_normal
|
||||
|
||||
SURFACE = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(SURFACE / "tools"))
|
||||
|
|
@ -84,10 +85,10 @@ SOLID = 0.0313
|
|||
# Metres between the thickness and the distance from a vertex of the wall's inner face to the designed surface. Shipped
|
||||
# 0.0001 (a float32 mesh under three levels of subdivision); least claimed mutant 0.024 (S6: the inner face is subdivided again and pulls in); the geometric mean, separation 15 each side.
|
||||
EVEN = 1.5e-3
|
||||
# Metres: the thickness at which the wedge of shell-fold folds, (W / 2^levels) / tan(phi) of its narrower facet. The
|
||||
# wall is built at FOLD / FOLD_STEP (no inner face turned) and at FOLD x FOLD_STEP (some turned). Least claimed mutant:
|
||||
# F1, the wider facet's reach taken (max for min in core.fold_depths), which reads 0.25, 3.3 of shipped; FOLD_STEP is
|
||||
# the 1.2 separation the margin rule asks on each side of the onset.
|
||||
# Metres: the thickness at which the wedge of shell-fold folds, (W / 2^levels) / tan(phi) of its narrower facet, as
|
||||
# measured on flat facets (docs/kitbash.md, Thickness at a crease). The wall is built at FOLD / FOLD_STEP (no inner
|
||||
# face folded) and at FOLD x FOLD_STEP (some folded); FOLD_STEP is the 1.2 separation the margin rule asks on each
|
||||
# side of the onset. The counts themselves are exact: count_folds is held to this script's own count, face for face.
|
||||
FOLD, FOLD_STEP = 0.075, 1.2
|
||||
|
||||
|
||||
|
|
@ -213,7 +214,7 @@ try:
|
|||
and sorted(stored) == ["bevel", "levels", "offset", "sheet", "thickness"] and stored["sheet"] == PAULDRON
|
||||
and (stored["levels"], stored["offset"]) == (3, -1.0) and abs(stored["thickness"] - WALL) < 1e-7, [receipt["message"], stored])
|
||||
check("shell reports cage facts: rings, points, quads, creased edges, the subdivided count, an upward facing, no children",
|
||||
report and sorted(report) == ["cageFaces", "children", "corners", "creases", "facing", "fold", "levels", "object", "offset", "points", "rebuilt", "rings", "subdividedFaces", "thickness"]
|
||||
report and sorted(report) == ["cageFaces", "children", "corners", "creases", "facing", "folded", "levels", "object", "offset", "points", "rebuilt", "rings", "subdividedFaces", "thickness"]
|
||||
and (report["object"], report["rebuilt"], report["rings"], report["points"], report["cageFaces"], report["creases"], report["corners"], report["subdividedFaces"], report["levels"],
|
||||
report["thickness"], report["offset"], report["children"]) == ("Pauldron", False, 6, 6, 25, 25, 0, 1600, 3, 0.06, -1.0, [])
|
||||
and report["facing"][2] > 0.5 and abs(np.linalg.norm(report["facing"]) - 1.0) < 1e-5, report)
|
||||
|
|
@ -252,34 +253,47 @@ try:
|
|||
surface.free()
|
||||
check("shell-crisp: a sheet whose rim is soft keeps its four corners", R["readings"]["corner"] < CORNER, R["readings"])
|
||||
|
||||
# --- shell-fold: the receipt's fold onset, against the evaluated wall ---------------------------------------------------------
|
||||
# --- shell-fold: count_folds, against this script's own count on the evaluated wall -------------------------------------------
|
||||
section("shell-fold")
|
||||
# a ridge of two flat facets 0.3 and 1.0 wide, each tilted 45 degrees, full crease, levels 2: the narrower facet binds, (0.3 / 4) / tan 45 = 0.075
|
||||
wedge = {"rings": [[[-1.0 * math.sqrt(0.5), y, -1.0 * math.sqrt(0.5)], [0.0, y, 0.0], [0.3 * math.sqrt(0.5), y, -0.3 * math.sqrt(0.5)]] for y in (0.0, 0.5, 1.0)],
|
||||
"creases": [{"column": 1, "from": 0, "to": 2, "weight": 1.0}]}
|
||||
|
||||
def folded(name, thickness, offset=-1.0):
|
||||
"""(the receipt's fold, inner faces of the evaluated wall whose normal runs with their outer face's)."""
|
||||
_, told = send("brokkr_kitbash.shell", object_name=name, sheet=json.dumps(wedge), thickness=thickness, offset=offset, levels=2)
|
||||
wall_mesh = evaluated(bpy.data.objects[name])
|
||||
def own_folds(obj):
|
||||
"""This script's count on its own evaluation: inner faces of the wall (Subsurf and Solidify alone) with a corner
|
||||
whose triangle, the corner and its two neighbours, faces with their outer twin's normal (mathutils' normals)."""
|
||||
wall_mesh = evaluated(obj, off=("BOOLEAN", "BEVEL"))
|
||||
wall_mesh.faces.ensure_lookup_table()
|
||||
count = len(bpy.data.objects[name].data.polygons) * 4 ** 2 # Solidify lists the outer faces, then their inner twins in the same order, then the rim
|
||||
turned = sum(1 for k in range(count) if wall_mesh.faces[k].normal.dot(wall_mesh.faces[count + k].normal) > 0)
|
||||
count = len(obj.data.polygons) * 4 ** obj.modifiers["Kit Subsurf"].levels # Solidify lists the outer faces, then their inner twins in the same order, then the rim
|
||||
found = 0
|
||||
for k in range(count):
|
||||
at = [v.co for v in wall_mesh.faces[count + k].verts]
|
||||
found += any(triangle_normal(at[i - 1], at[i], at[(i + 1) % len(at)]).dot(wall_mesh.faces[k].normal) > 0 for i in range(len(at)))
|
||||
wall_mesh.free()
|
||||
return told["fold"], turned
|
||||
return found
|
||||
|
||||
under, over = folded("FoldUnder", FOLD / FOLD_STEP), folded("FoldOver", FOLD * FOLD_STEP)
|
||||
def folded(name, sheet, thickness, offset=-1.0, levels=2, **asked):
|
||||
"""[the report's folded (-1: no report), this script's own count]."""
|
||||
_, told = send("brokkr_kitbash.shell", object_name=name, sheet=json.dumps(sheet), thickness=thickness, offset=offset, levels=levels, **asked)
|
||||
return [told.get("folded", -1) if told else -1, own_folds(bpy.data.objects[name]) if name in bpy.data.objects else -1]
|
||||
|
||||
under, over = folded("FoldUnder", wedge, FOLD / FOLD_STEP, count_folds=True), folded("FoldOver", wedge, FOLD * FOLD_STEP, count_folds=True)
|
||||
reading("foldUnder", under[1])
|
||||
reading("foldOver", over[1], least=True)
|
||||
check("shell-fold: the receipt names the fold onset of a creased ridge by its narrower facet, the margin and the edge, and the evaluated wall folds over it and not under it",
|
||||
abs(under[0]["onset"] - FOLD) < 1e-6 and abs(under[0]["margin"] - FOLD_STEP) < 1e-3 and abs(over[0]["margin"] - 1 / FOLD_STEP) < 1e-3
|
||||
and under[0]["edge"] in ([[0, 1], [1, 1]], [[1, 1], [2, 1]]) and under[0]["weight"] == 1.0 and under[1] == 0 and over[1] > 0, [under, over])
|
||||
outward = folded("FoldOut", 0.3, offset=1.0)
|
||||
half = folded("FoldHalf", FOLD / FOLD_STEP, offset=0.0)
|
||||
check("shell-fold: a ridge under a wall grown outward has no fold to name, and a wall half behind the surface holds twice the thickness",
|
||||
outward == (None, 0) and abs(half[0]["onset"] - 2 * FOLD) < 1e-6 and half[1] == 0, [outward, half])
|
||||
for name in ("FoldUnder", "FoldOver", "FoldOut", "FoldHalf"):
|
||||
bpy.data.objects.remove(bpy.data.objects[name])
|
||||
check("shell-fold: count_folds counts no folded face on a creased ridge under the thickness its narrower facet holds, and the faces this script counts over it",
|
||||
under == [0, 0] and over[0] == over[1] > 0, [under, over])
|
||||
unasked, outward = folded("FoldUnasked", wedge, FOLD * FOLD_STEP), folded("FoldOut", wedge, 0.3, offset=1.0, count_folds=True)
|
||||
check("shell-fold: folded is null unless count_folds asks, whatever the wall does, and a ridge under a wall grown outward folds nowhere",
|
||||
unasked[0] is None and unasked[1] == over[1] and outward == [0, 0], [unasked, outward])
|
||||
lofts = json.loads((SURFACE / "tests" / "fixtures" / "fold_lofts.json").read_text(encoding="utf-8"))["lofts"]
|
||||
seeded = {f"{loft['seed']} offset {loft['offset']:g}": folded(f"Loft{loft['seed']}", loft["sheet"], loft["thickness"], offset=loft["offset"], levels=loft["levels"], count_folds=True) for loft in lofts}
|
||||
held = {f"{loft['seed']} offset {loft['offset']:g}": folded(f"Held{loft['seed']}", loft["sheet"], loft["holds"], offset=loft["offset"], levels=loft["levels"], count_folds=True) for loft in lofts if loft["holds"]}
|
||||
R["folds"] = {"seeded": seeded, "held": held}
|
||||
check("shell-fold: on seeded lofts whose walls fold under any figure of the cage, at offsets -1, 0 and 1, count_folds counts the faces this script counts, and none at a thickness the wall holds",
|
||||
len(seeded) == 3 and all(told == own > 0 for told, own in seeded.values()) and held and all(pair == [0, 0] for pair in held.values()), [seeded, held])
|
||||
for name in ["FoldUnder", "FoldOver", "FoldUnasked", "FoldOut"] + [f"{kind}{loft['seed']}" for loft in lofts for kind in ("Loft", "Held")]:
|
||||
if name in bpy.data.objects:
|
||||
bpy.data.objects.remove(bpy.data.objects[name])
|
||||
|
||||
# --- shell-solid ------------------------------------------------------------------------------------------------------------
|
||||
section("shell-solid")
|
||||
|
|
@ -356,15 +370,22 @@ try:
|
|||
plate = evaluated(again)
|
||||
check("shell-rebuild: the rebuilt plate is still cut, and closed", sum(1 for e in plate.edges if not e.is_manifold) == 0 and len(plate.faces) > 2 * 400 + 4 * 20 + 20, len(plate.faces))
|
||||
plate.free()
|
||||
receipt, report = send("brokkr_kitbash.shell", object_name="Pauldron", sheet=json.dumps(MOVED), thickness=0.05, levels=2, bevel=0.004, count_folds=True)
|
||||
check("shell-rebuild: count_folds under cutters counts the wall as this script does and leaves the stack shown, in order",
|
||||
receipt["status"] == "accepted" and report and report["folded"] == own_folds(again) and [(m.name, m.show_viewport) for m in again.modifiers]
|
||||
== [("Kit Subsurf", True), ("Kit Solidify", True), ("Kit Difference", True), ("Kit Bevel", True)], [receipt["message"], report and report.get("folded"), [(m.name, m.show_viewport) for m in again.modifiers]])
|
||||
|
||||
# --- costs: wall times of this run, never bounded -----------------------------------------------------------------------------
|
||||
section("costs")
|
||||
times = {"shell": [], "evaluation": [], "rebuildUnderCuts": []}
|
||||
times = {"shell": [], "shellCountingFolds": [], "evaluation": [], "rebuildUnderCuts": [], "rebuildCall": [], "rebuildCallCountingFolds": []}
|
||||
for k in range(3):
|
||||
name = f"Timed{k}"
|
||||
start = time.perf_counter()
|
||||
bpy.ops.brokkr_kitbash.shell(object_name=name, sheet=json.dumps(PAULDRON), thickness=WALL)
|
||||
times["shell"].append(time.perf_counter() - start)
|
||||
start = time.perf_counter()
|
||||
bpy.ops.brokkr_kitbash.shell(object_name=name + "Counted", sheet=json.dumps(PAULDRON), thickness=WALL, count_folds=True)
|
||||
times["shellCountingFolds"].append(time.perf_counter() - start)
|
||||
bpy.data.objects[name].update_tag() # Blender's own update after the action evaluated it already: once more, alone
|
||||
start = time.perf_counter()
|
||||
faces = len(bpy.data.objects[name].evaluated_get(bpy.context.evaluated_depsgraph_get()).data.polygons) # one whole evaluation: Subdivision and Solidify
|
||||
|
|
@ -373,6 +394,10 @@ try:
|
|||
bpy.ops.brokkr_kitbash.shell(object_name="Pauldron", sheet=json.dumps(MOVED if k % 2 else PAULDRON), thickness=WALL, bevel=0.004)
|
||||
cut_faces = len(pauldron.evaluated_get(bpy.context.evaluated_depsgraph_get()).data.polygons) # with its one Boolean of six cutters
|
||||
times["rebuildUnderCuts"].append(time.perf_counter() - start)
|
||||
for counting in (False, True): # the call alone: what count_folds adds to a rebuild under six cutters
|
||||
start = time.perf_counter()
|
||||
bpy.ops.brokkr_kitbash.shell(object_name="Pauldron", sheet=json.dumps(MOVED if k % 2 else PAULDRON), thickness=WALL, bevel=0.004, count_folds=counting)
|
||||
times["rebuildCallCountingFolds" if counting else "rebuildCall"].append(time.perf_counter() - start)
|
||||
R["costs"] = {name: float(f"{statistics.median(values):.2g}") for name, values in times.items()}
|
||||
check("costs: the timed shells evaluated whole", faces == 3360 and cut_faces > 3360, [faces, cut_faces])
|
||||
|
||||
|
|
@ -405,6 +430,9 @@ try:
|
|||
"sheet.creases[0].to must be a whole number from 0 to 5, not 6")
|
||||
refused("two weights on one edge", {"object_name": "Mixed", "sheet": json.dumps({**PAULDRON, "creases": [{"ring": 1, "from": 0, "to": 2, "weight": 1}, {"ring": 1, "from": 1, "to": 3, "weight": 0.5}]})},
|
||||
"sheet.creases[1] gives an edge weight 0.5 that sheet.creases[0] gives 1")
|
||||
mixed.modifiers["Kit Solidify"].show_viewport = False
|
||||
refused("count_folds on a shell whose Kit Solidify is hidden", {"object_name": "Mixed", "sheet": SHEET, "count_folds": True}, "'Mixed' has its Kit Solidify hidden in viewports")
|
||||
mixed.modifiers["Kit Solidify"].show_viewport = True
|
||||
refused("a sheet that is not JSON", {"object_name": "Mixed", "sheet": "{rings"}, "sheet is not JSON")
|
||||
refused("a sheet with an unknown key", {"object_name": "New", "sheet": json.dumps({**PAULDRON, "inside": [0, 0, 0]})}, "sheet has no key 'inside'")
|
||||
dense = {"rings": [[[j / 10, 0, i / 10] for j in range(34)] for i in range(34)]}
|
||||
|
|
|
|||
|
|
@ -37,12 +37,17 @@
|
|||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "shell-fold: the receipt names the fold onset of a creased ridge by its narrower facet, the margin and the edge, and the evaluated wall folds over it and not under it",
|
||||
"name": "shell-fold: count_folds counts no folded face on a creased ridge under the thickness its narrower facet holds, and the faces this script counts over it",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "shell-fold: a ridge under a wall grown outward has no fold to name, and a wall half behind the surface holds twice the thickness",
|
||||
"name": "shell-fold: folded is null unless count_folds asks, whatever the wall does, and a ridge under a wall grown outward folds nowhere",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "shell-fold: on seeded lofts whose walls fold under any figure of the cage, at offsets -1, 0 and 1, count_folds counts the faces this script counts, and none at a thickness the wall holds",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
|
|
@ -81,6 +86,11 @@
|
|||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "shell-rebuild: count_folds under cutters counts the wall as this script does and leaves the stack shown, in order",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "costs: the timed shells evaluated whole",
|
||||
"ok": true,
|
||||
|
|
@ -131,6 +141,11 @@
|
|||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: count_folds on a shell whose Kit Solidify is hidden",
|
||||
"ok": true,
|
||||
"detail": null
|
||||
},
|
||||
{
|
||||
"name": "refused, scene unchanged: a sheet that is not JSON",
|
||||
"ok": true,
|
||||
|
|
@ -169,9 +184,34 @@
|
|||
"solid": 0.027
|
||||
},
|
||||
"costs": {
|
||||
"shell": 0.0074,
|
||||
"evaluation": 0.0015,
|
||||
"rebuildUnderCuts": 1.1
|
||||
"shell": 0.0059,
|
||||
"shellCountingFolds": 0.0091,
|
||||
"evaluation": 0.0022,
|
||||
"rebuildUnderCuts": 1.7,
|
||||
"rebuildCall": 1.6,
|
||||
"rebuildCallCountingFolds": 1.6
|
||||
},
|
||||
"folds": {
|
||||
"seeded": {
|
||||
"5185 offset -1": [
|
||||
2,
|
||||
2
|
||||
],
|
||||
"5101 offset 0": [
|
||||
13,
|
||||
13
|
||||
],
|
||||
"5196 offset 1": [
|
||||
4,
|
||||
4
|
||||
]
|
||||
},
|
||||
"held": {
|
||||
"5185 offset -1": [
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
},
|
||||
"creaseRibs": "Operator brokkr_kitbash.ribs finished.",
|
||||
"ok": true
|
||||
|
|
|
|||
|
|
@ -1558,34 +1558,6 @@ class SheetTests(unittest.TestCase):
|
|||
with self.assertRaisesRegex(core.KitError, r"\.to must be a whole number from 0 to 3, not 4"):
|
||||
core.sheet({**closed, "creases": [{"ring": 0, "from": 0, "to": 4, "weight": 1}]})
|
||||
|
||||
def test_fold_depths_are_the_narrower_facets_first_row_over_the_tangent(self):
|
||||
"""A ridge of two flat facets 1.0 and 0.3 wide, each tilted 45 degrees: the crease's fold depth is
|
||||
(0.3 / 2^levels) / tan 45, the narrower facet's (F1: the wider facet's reach reads 0.25 at levels 2); the
|
||||
facets fall away from their normals, a ridge, and turned over they are a valley; coplanar facets never fold."""
|
||||
h = math.sqrt(0.5)
|
||||
|
||||
def wedge(sign, flat=False):
|
||||
return core.sheet({"rings": [[[-h, y, 0.0 if flat else -sign * h], [0.0, y, 0.0], [0.3 * h, y, 0.0 if flat else -sign * 0.3 * h]] for y in (0.0, 0.5, 1.0)],
|
||||
"creases": [{"column": 1, "from": 0, "to": 2, "weight": 1.0}]})
|
||||
|
||||
pairs, depths, ridges, weights = core.fold_depths(wedge(1), 2)
|
||||
crease = [k for k, pair in enumerate(pairs.tolist()) if pair in ([1, 4], [4, 7])]
|
||||
self.assertEqual(len(pairs), 4) # the two crease edges and the middle ring's edge on each facet: an edge of the rim has one quad and no fold
|
||||
self.assertEqual(len(crease), 2)
|
||||
for k in crease:
|
||||
self.assertAlmostEqual(depths[k], 0.075, places=12)
|
||||
self.assertTrue(ridges[k])
|
||||
self.assertEqual(weights[k], 1.0)
|
||||
self.assertTrue(all(math.isinf(depths[k]) and weights[k] == 0.0 for k in range(len(pairs)) if k not in crease)) # an edge inside a flat facet
|
||||
self.assertAlmostEqual(core.fold_depths(wedge(1), 3)[1][crease[0]], 0.0375, places=12) # a level more halves the first row
|
||||
valley = core.fold_depths(wedge(-1), 2)
|
||||
self.assertAlmostEqual(valley[1][crease[0]], 0.075, places=12)
|
||||
self.assertFalse(valley[2][crease[0]])
|
||||
self.assertTrue(np.isinf(core.fold_depths(wedge(1, flat=True), 2)[1]).all())
|
||||
steep = core.sheet({"rings": [[[-0.5, y, -math.sqrt(0.75)], [0.0, y, 0.0], [0.5, y, -math.sqrt(0.75)]] for y in (0.0, 1.0)]}) # facets 60 degrees off level, no crease stated
|
||||
self.assertAlmostEqual(core.fold_depths(steep, 1)[1][0], 0.5 / math.tan(math.radians(60)), places=12)
|
||||
self.assertEqual(core.fold_depths(steep, 1)[3][0], 0.0)
|
||||
|
||||
|
||||
ROWS = ["brokkr_kitbash.place_part", "brokkr_kitbash.set_params", "brokkr_kitbash.describe", "brokkr_kitbash.report",
|
||||
"brokkr_kitbash.attach", "brokkr_kitbash.detach", "brokkr_kitbash.roll", "brokkr_kitbash.aim", "brokkr_kitbash.reach", "brokkr_kitbash.close",
|
||||
|
|
@ -1656,16 +1628,18 @@ class HostFileTests(unittest.TestCase):
|
|||
with self.assertRaises(at.IntentInvalid, msg=str(bad)):
|
||||
at.validate(bad, host)
|
||||
for row in self.document["actions"][4:]:
|
||||
self.assertTrue(all(field["type"] in ("string", "number", "integer") for field in row["fields"]), row["name"])
|
||||
self.assertTrue(all(field["type"] in ("string", "number", "integer", "boolean") for field in row["fields"]), row["name"])
|
||||
self.assertEqual([(row["name"], field["name"], field["default"]) for row in self.document["actions"] for field in row["fields"] if field["type"] == "boolean"],
|
||||
[("brokkr_kitbash.shell", "count_folds", False)]) # the one evaluation shell makes is asked for, never the default
|
||||
self.assertEqual([(row["name"], field["name"]) for row in self.document["actions"] for field in row["fields"] if field["type"] == "integer"],
|
||||
[("brokkr_kitbash.shell", "levels")])
|
||||
sheet = json.dumps({"rings": [[[0, 0, 0], [1, 0, 0]], [[0, 0, 1], [1, 0, 1]]]})
|
||||
shell = {**envelope, "action": "brokkr_kitbash.shell", "object_name": "Plate", "sheet": sheet}
|
||||
self.assertEqual([at.validate(shell, host)[k] for k in ("thickness", "offset", "levels", "bevel")], [0.05, -1, 3, 0])
|
||||
self.assertEqual([at.validate(shell, host)[k] for k in ("thickness", "offset", "levels", "bevel", "count_folds")], [0.05, -1, 3, 0, False])
|
||||
self.assertEqual(at.validate({**shell, "thickness": 0.001, "levels": 4}, host)["levels"], 4)
|
||||
for bad in ({**shell, "levels": 5}, {**shell, "levels": 2.5}, {**shell, "levels": 0}, {**shell, "thickness": 0.0005}, {**shell, "offset": 1.5}, {**shell, "bevel": 0.2},
|
||||
{**shell, "sheet": "{" + " " * 32000}, {**shell, "sheet": ""}, {k: v for k, v in shell.items() if k != "sheet"}, {**shell, "object_name": "x" * 64},
|
||||
{**shell, "rings": []}):
|
||||
{**shell, "rings": []}, {**shell, "count_folds": 1}):
|
||||
with self.assertRaises(at.IntentInvalid, msg=str(bad)[:200]):
|
||||
at.validate(bad, host)
|
||||
|
||||
|
|
@ -1749,9 +1723,9 @@ class OwnershipTests(unittest.TestCase):
|
|||
self.assertLess(place.index("evaluable("), place.index("modifier.show_viewport = True"))
|
||||
# unevaluable-target: every action that evaluates refuses an object Blender does not evaluate before its first write
|
||||
for body, first_write in ((place, "bpy.data.meshes.new("), (bodies["boolean"], ".objects.link("), (bodies["apply"], "bpy.data.meshes.new_from_object("),
|
||||
(bodies["ribs"], "show_viewport = False")):
|
||||
(bodies["ribs"], "show_viewport = False"), (bodies["shell"], "clear_geometry()")):
|
||||
self.assertLess(body.index("evaluable("), body.index(first_write))
|
||||
self.assertEqual([name for name, body in bodies.items() if "evaluable(" in body], ["boolean", "apply", "ribs"])
|
||||
self.assertEqual([name for name, body in bodies.items() if "evaluable(" in body], ["boolean", "apply", "ribs", "shell"])
|
||||
ribs = bodies["ribs"] # every refusal before the ribs object is written, and the cage's modifiers shown again whatever happened
|
||||
self.assertLess(ribs.rindex("raise Refused("), ribs.index("mesh = bpy.data.meshes.new(self.ribs_name)"))
|
||||
self.assertLess(ribs.index("finally:"), ribs.index("modifier.show_viewport = True"))
|
||||
|
|
@ -1759,14 +1733,22 @@ class OwnershipTests(unittest.TestCase):
|
|||
for body in (place, *(source.split(f"class BROKKR_KITBASH_OT_{name}(")[1].split("class BROKKR_KITBASH_OT_")[0] for name in ("cut", "cut_many"))):
|
||||
self.assertNotIn("view_layer.update", body) # an update after a cutter joins would evaluate the Boolean
|
||||
self.assertEqual(body.count("place_cutters("), 0 if body is place else 1)
|
||||
shell = bodies["shell"] # shell evaluates nothing: Blender's own update after the action evaluates the plate once
|
||||
for call in ("evaluated_of(", "evaluable(", "to_mesh(", "view_layer.update", "evaluated_get(", "depsgraph"):
|
||||
shell, count = bodies["shell"].split(" def folded_faces(") # shell evaluates nothing unless count_folds asks, and then the wall alone: no Boolean runs for it
|
||||
shell, alone = shell.split(" def wall_alone(")
|
||||
for call in ("evaluated_of(", "to_mesh(", "view_layer.update", "evaluated_get(", "depsgraph"):
|
||||
self.assertNotIn(call, shell)
|
||||
self.assertEqual((shell.count("evaluable("), shell.count("folded_faces("), shell.count("self.count_folds")), (1, 1, 2))
|
||||
self.assertLess(shell.index("if self.count_folds:"), shell.index("with self.wall_alone(obj):"))
|
||||
self.assertLess(shell.index("with self.wall_alone(obj):"), shell.index("evaluable("))
|
||||
self.assertIn("self.folded_faces(context, obj, cage_faces * 4 ** self.levels) if self.count_folds else None", shell)
|
||||
self.assertLess(count.index("wall_alone(shell):"), count.index("evaluable("))
|
||||
self.assertEqual((count.count("evaluable("), count.count("to_mesh("), source.count("folded_faces("), source.count("wall_alone(")), (1, 1, 2, 3))
|
||||
self.assertLess(alone.index("finally:"), alone.index("modifier.show_viewport = True"))
|
||||
self.assertLess(shell.rindex("raise Refused("), shell.index("clear_geometry()")) # every refusal before any write
|
||||
self.assertLess(shell.index("core.sheet("), shell.index("clear_geometry()"))
|
||||
self.assertLess(shell.index("clear_geometry()"), shell.index("bpy.data.meshes.new("))
|
||||
self.assertNotIn("objects.remove(", shell) # a rebuild rewrites the mesh in place: a new object would orphan its cutters and ribs
|
||||
self.assertEqual(source.count("to_mesh("), 4) # boolean's report, and in ribs the designed surface, the plate's two faces and the holed webs
|
||||
self.assertEqual(source.count("to_mesh("), 5) # boolean's report, in ribs the designed surface, the plate's two faces and the holed webs, and shell's fold count
|
||||
|
||||
def test_only_ribs_writes_kit_ribs(self):
|
||||
"""kit_ribs is the request a ribs object was derived from: ribs assigns it once and nothing reads it back to
|
||||
|
|
|
|||
Loading…
Reference in a new issue