brokkr_kitbash.plate: a two-sided row with one seed is a mirrored pair; KNOWN's corner and tie plates held to repaired truths; one hash on two platforms (cut hard-plate-core, Soul s1)
plate.build draws a two-sided row with one seed (or no clad) once, at side +1, and its .L is the mirror of
its .R. A one-sided row at side -1 and a two-sided row with a pair of seeds are drawn on the mirrored solid
as before, as the mech branches' builders do (paladin's left thigh). _longest's docstring says greatest.
tests: Hull.Quarter.R/.L and Hull.BellySide.R are held, solid, facets, panels and bolts, to
plates_bastion.json's "repaired": the branch's builder at eeda8bf in Blender 5.3 with massing.corners'
inside test at 1e-5 m, and with massing.clad cutting from the other of the two tied edges. The panels whose
outline crosses itself are named (Hull.Cheek.R's render difference is one of them, by where Blender starts
its loop). The three fixtures build to one sha256 at 1e-9 m on Starfire and on Yggdrasil.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
3acd7faddb
commit
2d4943804c
4 changed files with 178 additions and 45 deletions
|
|
@ -708,7 +708,7 @@ def panel(panels: _Mesh, bolts: _Mesh, polygon: list[np.ndarray], out: np.ndarra
|
|||
|
||||
def _longest(pts: list[np.ndarray]) -> int:
|
||||
"""The index of a polygon's longest edge; edges within TIE of it tie, and the tie goes to the edge whose middle
|
||||
is least by x, y, z."""
|
||||
is greatest by x, y, z."""
|
||||
lengths = [float(np.linalg.norm(pts[(k + 1) % len(pts)] - pts[k])) for k in range(len(pts))]
|
||||
top = max(lengths)
|
||||
return max((k for k in range(len(pts)) if top - lengths[k] <= TIE), key=lambda k: _lexical((pts[k] + pts[(k + 1) % len(pts)]) / 2))
|
||||
|
|
@ -764,11 +764,20 @@ def clad_layout(V: np.ndarray, faces, facets, clad: dict, seed: int, face_n, sid
|
|||
|
||||
|
||||
# --- build ------------------------------------------------------------------------------------------------------------
|
||||
def _across(mesh):
|
||||
"""A mesh (V, faces) mirrored across x = 0, its faces wound outward still and starting where they did."""
|
||||
V, faces = mesh
|
||||
return V * (-1.0, 1.0, 1.0), [face[:1] + face[:0:-1] for face in faces]
|
||||
|
||||
|
||||
def build(table: Any, side: int = 1) -> list[dict]:
|
||||
"""One entry per plate built, in the table's order: a row with sides "both" is built at `side`, then at -side.
|
||||
Side -1 negates x of every point before the hull, so facets, panels and anchors are those of the mirrored solid
|
||||
as built; a clad selector's direction is mirrored with it. Names end .R at side +1 and .L at -1 on a two-sided
|
||||
row. Each entry: {name, row (its index in the table), mat, bevel, side, solid: (V, faces), facets, panels: (V, faces), bolts: (V, faces),
|
||||
Names end .R at side +1 and .L at -1 on a two-sided row. A two-sided row with one seed (or no clad) is drawn
|
||||
once, at side +1, and its .L is the mirror of its .R: the same facets in the same order, the same cuts and
|
||||
lifts. Anywhere else (a one-sided row at side -1, a two-sided row with a pair of seeds) side -1 negates x of
|
||||
every point before the hull, and facets, ties and draws are those of the mirrored solid as built, which is not
|
||||
the mirror of side +1's panels; a clad selector's direction is mirrored with it. Each entry: {name, row (its
|
||||
index in the table), mat, bevel, side, solid: (V, faces), facets, panels: (V, faces), bolts: (V, faces),
|
||||
anchors: [{kind, name, matrix, mirrored, height?}], report: {corners, facets, panels, bolts}}."""
|
||||
if side not in (1, -1):
|
||||
raise PlateError(f"side: {side!r} is not 1 or -1")
|
||||
|
|
@ -777,16 +786,26 @@ def build(table: Any, side: int = 1) -> list[dict]:
|
|||
for i, row in enumerate(table["plates"]):
|
||||
path = f"plates[{i}]"
|
||||
points, face = _row_points(row, path)
|
||||
clad = row["clad"]
|
||||
pair = clad is not None and not isinstance(clad["seed"], int)
|
||||
drawn: dict[int, tuple] = {}
|
||||
for s in ((side, -side) if row["sides"] == "both" else (side,)):
|
||||
flip = np.array([float(s), 1.0, 1.0])
|
||||
V, faces, facets = hull(_mirrored(points * flip, row["mirror"]), path)
|
||||
face_n = None if face is None else face[3] * flip
|
||||
clad, top = row["clad"], 0.0
|
||||
panels = bolts = (np.zeros((0, 3)), [])
|
||||
made = 0
|
||||
if clad is not None:
|
||||
seed = clad["seed"] if isinstance(clad["seed"], int) else clad["seed"][0 if s > 0 else 1]
|
||||
panels, bolts, made, top = clad_layout(V, faces, facets, clad, seed, face_n, s)
|
||||
where = 1 if row["sides"] == "both" and not pair else s # the side this plate is drawn at
|
||||
if where not in drawn:
|
||||
turn = np.array([float(where), 1.0, 1.0])
|
||||
V, faces, facets = hull(_mirrored(points * turn, row["mirror"]), path)
|
||||
panels = bolts = (np.zeros((0, 3)), [])
|
||||
made, top = 0, 0.0
|
||||
if clad is not None:
|
||||
seed = clad["seed"][0 if where > 0 else 1] if pair else clad["seed"]
|
||||
panels, bolts, made, top = clad_layout(V, faces, facets, clad, seed, None if face is None else face[3] * turn, where)
|
||||
drawn[where] = ((V, faces), facets, panels, bolts, made, top)
|
||||
solid, facets, panels, bolts, made, top = drawn[where]
|
||||
if where != s:
|
||||
solid, panels, bolts = _across(solid), _across(panels), _across(bolts)
|
||||
facets = [{"normal": f["normal"] * flip, "area": f["area"], "centre": f["centre"] * flip} for f in facets]
|
||||
anchors = []
|
||||
for j, fit in enumerate(row["fits"]):
|
||||
origin, a, b, n = face
|
||||
|
|
@ -797,6 +816,6 @@ def build(table: Any, side: int = 1) -> list[dict]:
|
|||
anchor["height"] = fit["height"]
|
||||
anchors.append(anchor)
|
||||
built.append({"name": row["name"] + ((".R" if s > 0 else ".L") if row["sides"] == "both" else ""), "row": i, "mat": row["mat"], "bevel": row["bevel"], "side": s,
|
||||
"solid": (V, faces), "facets": facets, "panels": panels, "bolts": bolts, "anchors": anchors,
|
||||
"report": {"corners": len(V), "facets": len(faces), "panels": made, "bolts": len(bolts[0]) // 12}})
|
||||
"solid": solid, "facets": facets, "panels": panels, "bolts": bolts, "anchors": anchors,
|
||||
"report": {"corners": len(solid[0]), "facets": len(solid[1]), "panels": made, "bolts": len(bolts[0]) // 12}})
|
||||
return built
|
||||
|
|
|
|||
|
|
@ -871,8 +871,15 @@ plates somewhere owns that matrix. The table alone decides the result. A table h
|
|||
| `face` | `{at, normal, up, right}`: the face anchors stand on, for a row that is not a slab |
|
||||
| `fits` | anchors (below) |
|
||||
|
||||
`mirror` and `sides` are independent. Side -1 negates x of every point before the hull is built, so facets,
|
||||
panels and anchors are those of the mirrored solid as built.
|
||||
`mirror` and `sides` are independent. A two-sided row with one seed, or with no clad, is drawn once, at side +1,
|
||||
and its `.L` is the mirror of its `.R`: the same facets in the same order, the same cuts and lifts, every face
|
||||
wound the other way from the vertex it started at. Everywhere else, which is a one-sided row built at side -1 and
|
||||
a two-sided row with a pair of seeds, side -1 negates x of every point before the hull is built, and facets, ties
|
||||
and draws are those of the mirrored solid as built. That is not the mirror of side +1's panels even under the
|
||||
same seed: a cut is measured along its edge in the facet's winding, which a mirror reverses, and a tie goes to the
|
||||
greater x of the mirrored solid. The mech tracks' builders work this way (paladin's left thigh is its right
|
||||
thigh's table at side -1 with the same seeds, and its split panels are cut at the other share), and the fixtures
|
||||
hold `build` to them.
|
||||
|
||||
### Solid forms
|
||||
|
||||
|
|
@ -928,7 +935,7 @@ first.
|
|||
| `inset` | how far a panel stands in from its facet's edges |
|
||||
| `gap` | the seam between the two panels of a split facet |
|
||||
| `split` | a facet over this area is cut in two |
|
||||
| `seed` | an integer, or `[right, left]` on a row with `sides: "both"`. There is no default. |
|
||||
| `seed` | an integer, or `[right, left]` on a row with `sides: "both"`. There is no default. One integer on a two-sided row makes a mirrored pair; a pair of seeds draws each side on its own solid, also where the two are equal. |
|
||||
| `bolt_r` | a bolt's corner radius (default 0.028) |
|
||||
|
||||
One `random.Random(seed)` draws, in facet order. A chosen facet over `split` is cut across its longest edge at a
|
||||
|
|
@ -939,6 +946,12 @@ refused under a quarter of the part's area or under 0.02 m2; it is a prism from
|
|||
above, its far rim chamfered 0.02. A hexagonal bolt of radius `bolt_r` stands inside each panel corner, 3.2
|
||||
`bolt_r` in.
|
||||
|
||||
The inset moves each corner along its own miter and does not look at its neighbours, so where it passes the two
|
||||
ends of a short edge over each other the panel's outline crosses itself. `build` makes that panel as it stands;
|
||||
Blender fills a face that crosses itself by where its loop starts, so the same vertices can render differently
|
||||
from another builder's mesh. Two of the 104 fixture panels do it (bastion's `Hull.Cheek.R` and paladin's
|
||||
`Thigh.Outer`), and the test names them.
|
||||
|
||||
### Anchors
|
||||
|
||||
A fit is a frame on the face, at `[a, b]` in the face's (a, b), standing on the face's top: the face, plus
|
||||
|
|
@ -980,10 +993,17 @@ from a mech branch's own numbers and the solids, panels and bolt counts that bra
|
|||
5.3; `tests/test_plate.py` holds `build` to them (solid vertices within 1e-6 m, panel vertices within 1e-5 m,
|
||||
facet and bolt counts equal). The branches' builders work in float32 and leave two choices to Blender's mesh
|
||||
order, so eleven of the 126 fixture plates are held to something else, each named in the test's `KNOWN`:
|
||||
eight stand 1 to 2 micrometres (solid) or 29 micrometres (panels) from the float64 result; bastion's two
|
||||
quarter pods lack a corner their faces do bound (the branch's inside test lost it to float32), so its solid is
|
||||
smaller than the table's; and one of bastion's two belly-side plates splits its panel from the other of two
|
||||
equally long edges.
|
||||
eight stand 1 to 2 micrometres (solid) or 29 micrometres (panels) from the float64 result and are held at 4 and
|
||||
40; bastion's two quarter pods lack a corner their faces do bound (the branch's inside test lost it to float32),
|
||||
so the branch's solid is smaller than the table's and its panels are another solid's; and one of bastion's two
|
||||
belly-side plates splits its panel from the other of two equally long edges. Those three are held, solid, facets,
|
||||
panels and bolts, to `repaired` in `plates_bastion.json`: the branch's own builder run in Blender 5.3 with the
|
||||
inside test at 1e-5 m, and with its clad cutting from the other tied edge.
|
||||
|
||||
The same test builds the three fixtures to one sha256 of every coordinate rounded to 1e-9 m and every face,
|
||||
pinned from Starfire (Windows 11, numpy 2.5.4) and Yggdrasil (Debian 13, numpy 2.2.4 on the system LAPACK). The
|
||||
two hosts' coordinates differ by up to 2.7e-15 m, so the bytes of `build`'s arrays are equal between runs on one
|
||||
host and not between hosts.
|
||||
|
||||
## Hoses between sockets
|
||||
|
||||
|
|
|
|||
|
|
@ -42,4 +42,9 @@
|
|||
"Hull.BellySide.R": {"solid":[[2.0999999,2.2,3.9000001],[2.0999999,-2.4000001,3.95],[2.45,2.0,4.0999999],[2.45,-2.2,4.1500001],[2.45,2.0,4.8499999],[2.45,-2.2,4.9000001],[2.25,2.2,5.0999999],[2.25,-2.4000001,5.1500001],[1.8,2.2,3.9000001],[1.8,-2.4000001,5.1500001]],"facets":15,"panels":[[2.4300001,-2.0900002,4.7886829],[2.4300001,-2.0900002,4.2586985],[2.4300001,-0.6636688,4.2417183],[2.4300001,-0.6573603,4.7716274],[2.5050001,-2.0900002,4.7886829],[2.5050001,-2.0900002,4.2586985],[2.5050001,-0.6636688,4.2417183],[2.5050001,-0.6573603,4.7716274],[2.5250001,-2.0700002,4.7684431],[2.5250001,-2.0700002,4.2784615],[2.5250001,-0.6834292,4.2619548],[2.5250001,-0.677597,4.7518668],[2.4300001,-0.3936881,4.2385039],[2.4300001,1.89,4.2113171],[2.4300001,1.89,4.7413015],[2.4300001,-0.3873795,4.7684135],[2.4750001,-0.3936881,4.2385039],[2.4750001,1.89,4.2113171],[2.4750001,1.89,4.7413015],[2.4750001,-0.3873795,4.7684135],[2.4950001,-0.3734515,4.2582645],[2.4950001,1.87,4.2315569],[2.4950001,1.87,4.7215385],[2.4950001,-0.367619,4.7481766],[2.2321301,1.8335732,5.0840106],[1.9212853,-2.2902241,5.1287899],[2.1400001,-2.2902241,5.1287899],[2.2321301,1.8343884,5.1590061],[1.9212853,-2.2894089,5.2037854],[2.1400001,-2.2894089,5.2037854],[2.2288792,1.7680224,5.179728],[1.9428494,-2.2691927,5.223567],[2.1204419,-2.2691927,5.223567]],"bolts":11},
|
||||
"Hull.BellySide.L": {"solid":[[-2.0999999,2.2,3.9000001],[-2.0999999,-2.4000001,3.95],[-2.45,2.0,4.0999999],[-2.45,-2.2,4.1500001],[-2.45,2.0,4.8499999],[-2.45,-2.2,4.9000001],[-2.25,2.2,5.0999999],[-2.25,-2.4000001,5.1500001],[-1.8,2.2,3.9000001],[-1.8,-2.4000001,5.1500001]],"facets":15,"panels":[[-2.4300001,-2.0900002,4.2586985],[-2.4300001,-2.0900002,4.7886829],[-2.4300001,0.1687398,4.7617931],[-2.4300001,0.1624316,4.2318835],[-2.5050001,-2.0900002,4.2586985],[-2.5050001,-2.0900002,4.7886829],[-2.5050001,0.1687398,4.7617931],[-2.5050001,0.1624316,4.2318835],[-2.5250001,-2.0700002,4.2784615],[-2.5250001,-2.0700002,4.7684431],[-2.5250001,0.1485032,4.7420325],[-2.5250001,0.1426711,4.2521205],[-2.4300001,0.4387209,4.7585793],[-2.4300001,1.89,4.7413015],[-2.4300001,1.89,4.2113171],[-2.4300001,0.4324124,4.2286692],[-2.4750001,0.4387209,4.7585793],[-2.4750001,1.89,4.7413015],[-2.4750001,1.89,4.2113171],[-2.4750001,0.4324124,4.2286692],[-2.4950001,0.4584814,4.7383423],[-2.4950001,1.87,4.7215385],[-2.4950001,1.87,4.2315569],[-2.4950001,0.4526491,4.2484298],[-2.2321301,1.8335732,5.0840106],[-2.1400001,-2.2902241,5.1287899],[-1.9212852,-2.2902241,5.1287899],[-2.2321301,1.8340623,5.1290078],[-2.1400001,-2.2897351,5.1737871],[-1.9212852,-2.2897351,5.1737871],[-2.2288792,1.7676963,5.1497297],[-2.1204419,-2.2695189,5.1935692],[-1.9428494,-2.2695189,5.1935692]],"bolts":11}
|
||||
}}
|
||||
]}
|
||||
],
|
||||
"repaired": {"how": {"corner": "the branch's builder with massing.corners' inside test at 1e-5 m in place of 1e-6: the corner float32 lost is kept", "tie": "the branch's massing.clad cutting from the other of the split facet's two equally long edges"}, "truth": {
|
||||
"Hull.Quarter.R": {"solid":[[4.2910318,-2.9193861,6.8925695],[4.7526722,-3.0549133,5.7045879],[4.3936944,-1.4,7.0157642],[4.9976001,-1.4,5.506],[3.5958304,-4.3421259,6.9449539],[3.9363332,-4.6085348,5.8910241],[1.75,-4.8604336,7.409956],[1.75,-5.3931999,5.9851837],[2.5643883,-1.4,7.5279703],[1.75,-2.3254409,7.6634545],[2.5643883,-1.4,5.5060005],[1.75,-2.3254409,5.6170526]],"facets":8,"panels":[[2.6039631,-1.5075765,7.4852662],[1.8505968,-2.3636744,7.6105995],[1.8505968,-3.7839808,7.4685688],[3.7708514,-3.7307458,6.9362202],[4.181469,-2.8904121,6.9052806],[4.2749047,-1.5075765,7.0174022],[2.6160405,-1.5118898,7.5284004],[1.8626742,-2.3679876,7.6537333],[1.8626742,-3.7882941,7.5117025],[3.7829289,-3.7350593,6.9793544],[4.1935463,-2.8947253,6.9484148],[4.2869821,-1.5118899,7.0605364],[2.6295795,-1.5337148,7.543292],[1.8873084,-2.3772049,7.6667795],[1.8873082,-3.7697763,7.5275221],[3.7765129,-3.7174025,7.0037818],[4.1799693,-2.8917232,6.9733815],[4.2717276,-1.5337149,7.0834904],[1.8505965,-4.0526409,7.4417028],[1.8505965,-4.7160707,7.37536],[3.5181954,-4.2478104,6.9552579],[3.6377716,-4.0030956,6.9462481],[1.8707256,-4.0598297,7.5135922],[1.8707258,-4.7232594,7.4472499],[3.5383244,-4.2549992,7.0271478],[3.6579008,-4.0102844,7.0181379],[1.8953596,-4.0811133,7.5254316],[1.8953596,-4.6992774,7.4636159],[3.5305526,-4.2401166,7.0516772],[3.6317692,-4.0329757,7.0440507],[2.7647738,-4.5948009,7.0421376],[1.8471562,-4.8524671,7.273304],[1.8471562,-5.2996264,6.0774708],[2.8457143,-4.9412479,6.0344653],[2.7796867,-4.6345687,7.0570083],[1.862069,-4.8922348,7.2881742],[1.8620691,-5.3393941,6.0923409],[2.8606274,-4.9810157,6.049336],[2.7687323,-4.6642437,7.0491562],[1.8875668,-4.9116745,7.2711391],[1.8875669,-5.3432689,6.1169314],[2.8469315,-4.9989567,6.075614],[3.5113626,-4.385159,6.8540578],[3.0230417,-4.5222793,6.9770751],[3.0996346,-4.8501167,6.0235305],[3.7892847,-4.6026044,5.9938288],[3.5362175,-4.4514389,6.8788414],[3.0478966,-4.5885587,7.0018592],[3.1244895,-4.9163966,6.0483146],[3.8141394,-4.6688843,6.0186129],[3.5286927,-4.4801512,6.8701258],[3.0752041,-4.6074901,6.9843683],[3.1484115,-4.9208369,6.0729723],[3.7952363,-4.688694,6.0451155],[4.3817148,-1.9071758,6.8648353],[4.3201332,-2.8185694,6.7909379],[4.710516,-2.9331768,5.7863297],[4.8316121,-2.1149623,5.6881447],[4.4233174,-1.9113361,6.8814764],[4.3617358,-2.8227296,6.8075786],[4.7521186,-2.9373369,5.8029709],[4.8732147,-2.1191227,5.7047858],[4.4476438,-1.9368703,6.8683591],[4.3888788,-2.8065846,6.7978411],[4.7663054,-2.9173882,5.8265738],[4.8817496,-2.1373634,5.7329712],[4.9214897,-1.5076798,5.6152711],[4.4087076,-1.5076798,6.8972268],[4.400281,-1.6323925,6.887115],[4.8708658,-1.8497338,5.6563177],[4.9908276,-1.5146136,5.6430063],[4.478045,-1.5146136,6.924962],[4.4696183,-1.6393265,6.9148502],[4.9402032,-1.8566676,5.6840525],[4.9988408,-1.536377,5.6716146],[4.5026264,-1.5363771,6.9121504],[4.4966955,-1.6241521,6.9050336],[4.9545536,-1.8356153,5.7075229],[4.2655559,-3.0223532,6.786387],[3.6602807,-4.2610564,6.8319945],[3.9375505,-4.4779921,5.9737864],[4.6440229,-3.1334624,5.8124413],[4.3285189,-3.0520933,6.8142467],[3.723244,-4.2907968,6.8598547],[4.0005136,-4.5077324,6.001646],[4.706986,-3.1632028,5.840301],[4.34373,-3.0801873,6.8037205],[3.7548051,-4.28543,6.8480964],[4.0205779,-4.4933701,6.0254736],[4.7070746,-3.186857,5.868691]],"bolts":30},
|
||||
"Hull.Quarter.L": {"solid":[[-4.2910318,-2.9193861,6.8925695],[-4.7526722,-3.0549133,5.7045879],[-4.3936944,-1.4,7.0157642],[-4.9976001,-1.4,5.506],[-3.5958304,-4.3421259,6.9449539],[-3.9363332,-4.6085348,5.8910241],[-1.75,-4.8604336,7.409956],[-1.75,-5.3931999,5.9851837],[-2.5643883,-1.4,7.5279703],[-1.75,-2.3254409,7.6634545],[-2.5643883,-1.4,5.5060005],[-1.75,-2.3254409,5.6170526]],"facets":8,"panels":[[-1.8505965,-4.7160707,7.3753595],[-1.8505963,-4.0014849,7.4468179],[-3.6631114,-3.9512372,6.9443383],[-3.5181952,-4.2478104,6.9552579],[-1.8707256,-4.7232594,7.4472494],[-1.8707255,-4.0086741,7.5187078],[-3.6832407,-3.9584262,7.0162282],[-3.5383244,-4.2549992,7.0271473],[-1.8953596,-4.6992774,7.4636154],[-1.8953595,-4.0299578,7.5305471],[-3.6571088,-3.9811172,7.042141],[-3.5305526,-4.2401166,7.0516772],[-1.8505961,-3.7328248,7.4736838],[-1.8505962,-2.3636742,7.6105995],[-2.6039624,-1.5075763,7.4852662],[-4.2749043,-1.5075763,7.0174017],[-4.1814685,-2.8904119,6.9052796],[-3.7961907,-3.6788878,6.93431],[-1.8626735,-3.7371383,7.5168176],[-1.8626738,-2.3679876,7.6537333],[-2.61604,-1.5118898,7.5283999],[-4.2869816,-1.5118897,7.0605354],[-4.1935458,-2.8947253,6.9484134],[-3.8082683,-3.6832011,6.9774437],[-1.8873075,-3.7186203,7.5326371],[-1.8873078,-2.3772047,7.666779],[-2.6295791,-1.5337147,7.543292],[-4.2717271,-1.5337147,7.0834894],[-4.1799688,-2.8917229,6.9733806],[-3.8018522,-3.6655443,7.0018711],[-3.5113626,-4.385159,6.8540568],[-3.7892847,-4.6026049,5.9938283],[-2.8620911,-4.9353704,6.0337601],[-2.7814307,-4.5901232,7.0379415],[-3.5362175,-4.4514389,6.8788409],[-3.8141396,-4.6688843,6.0186124],[-2.8869457,-5.0016503,6.0585442],[-2.8062856,-4.6564031,7.0627251],[-3.5286927,-4.4801512,6.8701248],[-3.7952363,-4.6886945,6.0451145],[-2.9108679,-5.0060902,6.0832024],[-2.8335931,-4.6753345,7.0452342],[-2.6081707,-5.0265012,6.0446959],[-1.8471559,-5.2996264,6.0774708],[-1.8471559,-4.8524671,7.273304],[-2.5231626,-4.6626449,7.103004],[-2.6230836,-5.0662689,6.059566],[-1.8620688,-5.3393941,6.0923409],[-1.8620689,-4.8922348,7.2881746],[-2.5380757,-4.7024126,7.1178746],[-2.6093876,-5.0842099,6.0858445],[-1.8875666,-5.3432684,6.1169314],[-1.8875667,-4.9116745,7.2711396],[-2.5271213,-4.7320881,7.1100225],[-4.3919301,-1.7559885,6.8770943],[-4.4087081,-1.5076798,6.8972273],[-4.9214902,-1.5076798,5.615272],[-4.85321,-1.969032,5.6706338],[-4.4335327,-1.7601488,6.8937349],[-4.4503107,-1.5118401,6.9138684],[-4.9630928,-1.5118401,5.6319127],[-4.8948126,-1.9731923,5.6872749],[-4.4606104,-1.7449744,6.8839188],[-4.4748921,-1.5336035,6.9010572],[-4.9711065,-1.5336035,5.660521],[-4.909163,-1.95214,5.7107453],[-4.3201332,-2.8185692,6.7909379],[-4.373363,-2.0307715,6.8548145],[-4.8139558,-2.2342606,5.7024608],[-4.7105155,-2.9331768,5.7863297],[-4.3894706,-2.8255031,6.8186731],[-4.4427004,-2.0377054,6.8825493],[-4.8832932,-2.2411945,5.7301955],[-4.7798533,-2.9401107,5.814065],[-4.4166136,-2.8093579,6.8089352],[-4.4670272,-2.0632396,6.869432],[-4.8918281,-2.2594352,5.7583814],[-4.7940402,-2.920162,5.8376679],[-3.9375505,-4.4779921,5.9737859],[-3.6602805,-4.2610569,6.8319945],[-4.2655559,-3.0223532,6.7863865],[-4.6440229,-3.1334624,5.8124409],[-4.0005136,-4.5077324,6.0016456],[-3.7232437,-4.2907968,6.8598542],[-4.3285189,-3.0520935,6.8142462],[-4.706986,-3.1632028,5.8403006],[-4.0205779,-4.4933701,6.0254736],[-3.7548048,-4.28543,6.8480964],[-4.34373,-3.0801876,6.8037205],[-4.7070746,-3.1868572,5.8686905]],"bolts":30},
|
||||
"Hull.BellySide.R": {"solid":[[2.0999999,2.2,3.9000001],[2.0999999,-2.4000001,3.95],[2.45,2.0,4.0999999],[2.45,-2.2,4.1500001],[2.45,2.0,4.8499999],[2.45,-2.2,4.9000001],[2.25,2.2,5.0999999],[2.25,-2.4000001,5.1500001],[1.8,2.2,3.9000001],[1.8,-2.4000001,5.1500001]],"facets":15,"panels":[[2.4300001,0.4573603,4.2283726],[2.4300001,1.89,4.2113171],[2.4300001,1.89,4.7413015],[2.4300001,0.4636687,4.7582817],[2.5050001,0.4573603,4.2283726],[2.5050001,1.89,4.2113171],[2.5050001,1.89,4.7413015],[2.5050001,0.4636687,4.7582817],[2.5250001,0.4775969,4.2481332],[2.5250001,1.87,4.2315569],[2.5250001,1.87,4.7215385],[2.5250001,0.4834292,4.7380452],[2.4300001,-2.0900002,4.7886829],[2.4300001,-2.0900002,4.2586985],[2.4300001,0.1873795,4.2315865],[2.4300001,0.193688,4.7614961],[2.4750001,-2.0900002,4.7886829],[2.4750001,-2.0900002,4.2586985],[2.4750001,0.1873795,4.2315865],[2.4750001,0.193688,4.7614961],[2.4950001,-2.0700002,4.7684431],[2.4950001,-2.0700002,4.2784615],[2.4950001,0.167619,4.2518234],[2.4950001,0.1734514,4.7417355],[2.2321301,1.8335732,5.0840106],[1.9212853,-2.2902241,5.1287899],[2.1400001,-2.2902241,5.1287899],[2.2321301,1.8343884,5.1590061],[1.9212853,-2.2894089,5.2037854],[2.1400001,-2.2894089,5.2037854],[2.2288792,1.7680224,5.179728],[1.9428494,-2.2691927,5.223567],[2.1204419,-2.2691927,5.223567]],"bolts":11}
|
||||
}}}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ tracks' own builders (fixtures/plates_*.json: each a table and the truth its bra
|
|||
Run: python3 -m unittest discover -s surfaces/blender/tests -v (needs numpy; skipped without it)
|
||||
|
||||
The truth is float32 (mathutils and Blender meshes) and plate.py is float64; KNOWN lists every fixture plate where
|
||||
that, a corner the branch's builder lost, or a tie Blender's mesh order decided keeps the two apart, with what is
|
||||
asserted of it instead.
|
||||
that, a corner the branch's builder lost, or a tie Blender's mesh order decided keeps the two apart, with what it
|
||||
is held to instead.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import hashlib
|
||||
import importlib
|
||||
import inspect
|
||||
import json
|
||||
|
|
@ -65,6 +66,29 @@ def apart(a, b):
|
|||
return float(max(d.min(axis=1).max(), d.min(axis=0).max()))
|
||||
|
||||
|
||||
def fixture(mech):
|
||||
return json.loads((FIXTURES / f"plates_{mech}.json").read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def across(mesh):
|
||||
"""A mesh mirrored across x = 0, each face wound the other way from where it started."""
|
||||
return mesh[0] * (-1, 1, 1), [face[:1] + face[:0:-1] for face in mesh[1]]
|
||||
|
||||
|
||||
def rings(panels):
|
||||
"""Every panel's three rings (under the facet, under the rim, the rim), each flat in its own plane as (n, 2)."""
|
||||
V, faces = panels
|
||||
at = 0
|
||||
while at < len(faces):
|
||||
n = len(faces[at])
|
||||
cap = V[faces[at + 1]]
|
||||
normal = np.cross(cap - cap.mean(axis=0), np.roll(cap, -1, axis=0) - cap.mean(axis=0)).sum(axis=0)
|
||||
x, y = plate._stand(normal / np.linalg.norm(normal))
|
||||
low = min(faces[at])
|
||||
yield [np.column_stack((V[low + k * n:low + (k + 1) * n] @ x, V[low + k * n:low + (k + 1) * n] @ y)) for k in range(3)]
|
||||
at += 2 + 2 * n
|
||||
|
||||
|
||||
@unittest.skipIf(np is None, "numpy is not installed")
|
||||
class CheckTests(unittest.TestCase):
|
||||
def refused(self, document, path):
|
||||
|
|
@ -318,6 +342,29 @@ class CladTests(unittest.TestCase):
|
|||
self.assertEqual(pair[1]["panels"][0].tobytes(), ten["panels"][0].tobytes())
|
||||
self.assertNotEqual(pair[1]["panels"][0].tobytes(), plate.build(doc(row(clad=dict(CLAD, facets="all", seed=9))), -1)[0]["panels"][0].tobytes())
|
||||
|
||||
def test_a_two_sided_row_with_one_seed_is_a_mirrored_pair(self):
|
||||
cube = row(sides="both", clad=dict(CLAD, facets="all")) # every facet ties with another, every edge with three
|
||||
skew = [[x + s, y, z] for x, y, s in ((1, 0, 0), (3, 0, 0), (4, 1, 0), (2, 1, 0)) for z in (0, 1)] # its top's two longest edges tie
|
||||
for case in (cube, row(points=skew, sides="both", clad=dict(CLAD, facets="all"))):
|
||||
right, left = plate.build(doc(case))
|
||||
self.assertGreater(right["report"]["panels"], 6) # facets were split: the cuts are mirrored too
|
||||
self.assertEqual(left["report"], right["report"])
|
||||
for key in ("solid", "panels", "bolts"):
|
||||
self.assertTrue(np.array_equal(across(right[key])[0], left[key][0]))
|
||||
self.assertEqual(across(right[key])[1], left[key][1])
|
||||
self.assertAlmostEqual(volume(left["panels"]), volume(right["panels"]), places=12)
|
||||
for a, b in zip(right["facets"], left["facets"]):
|
||||
self.assertTrue(np.array_equal(a["normal"] * (-1, 1, 1), b["normal"]) and np.array_equal(a["centre"] * (-1, 1, 1), b["centre"]) and a["area"] == b["area"])
|
||||
back = plate.build(doc(case), -1)
|
||||
self.assertEqual([e["name"] for e in back], ["p.L", "p.R"])
|
||||
self.assertEqual(back[0]["panels"][0].tobytes(), left["panels"][0].tobytes())
|
||||
self.assertEqual(back[1]["panels"][0].tobytes(), right["panels"][0].tobytes())
|
||||
|
||||
def test_a_pair_of_seeds_draws_each_side_on_its_own_solid(self):
|
||||
pair = plate.build(doc(row(sides="both", clad=dict(CLAD, facets="all", seed=[5, 5]))))
|
||||
self.assertGreater(apart(across(pair[0]["panels"])[0], pair[1]["panels"][0]), 0.1)
|
||||
self.assertEqual(pair[1]["panels"][0].tobytes(), plate.build(doc(row(clad=dict(CLAD, facets="all"))), -1)[0]["panels"][0].tobytes())
|
||||
|
||||
def test_a_split_facet_takes_two_panels_and_a_whole_one_a_panel(self):
|
||||
made = plate.build(doc(row(clad=dict(CLAD, facets=[{"n": [0, 0, 1], "cos": 0.9}], split=2.2))))[0]
|
||||
self.assertEqual(made["report"], {"corners": 8, "facets": 6, "panels": 2, "bolts": 8})
|
||||
|
|
@ -414,51 +461,84 @@ class DeterminismTests(unittest.TestCase):
|
|||
plate.build(table)
|
||||
self.assertEqual(table, kept)
|
||||
|
||||
def test_the_fixtures_build_to_one_hash_on_every_platform(self):
|
||||
made = hashlib.sha256()
|
||||
for mech in ("bastion", "paladin", "raptor"):
|
||||
for case in fixture(mech)["cases"]:
|
||||
for entry in plate.build(fixture(mech)["table"], case["side"]):
|
||||
made.update(entry["name"].encode())
|
||||
for key in ("solid", "panels", "bolts"):
|
||||
made.update(np.round(entry[key][0] / QUANTUM).astype("<i8").tobytes())
|
||||
made.update(json.dumps(entry[key][1]).encode())
|
||||
for anchor in entry["anchors"]:
|
||||
made.update(json.dumps([anchor["kind"], anchor["name"], anchor["mirrored"], anchor.get("height")]).encode())
|
||||
made.update(np.round(np.array(anchor["matrix"]) / QUANTUM).astype("<i8").tobytes())
|
||||
self.assertEqual(made.hexdigest(), HASH)
|
||||
|
||||
# Fixture plates the truth cannot be met on, each with what is asserted instead (cut hard-plate-core's report has the readings):
|
||||
# float32 the branch solved the plate in float32 (mathutils); it stands up to 2e-6 m (solid) or 3e-5 m (panels) from the float64 solid
|
||||
# corner the branch's massing.corners lost a true corner to its float32 inside test: its solid lacks one corner plate.py has
|
||||
# tie two edges of the split facet are equally long and the branch's choice followed Blender's loop order, which differs
|
||||
# between the two sides of this row; plate.py's rule (the greater middle) meets the other side's truth
|
||||
|
||||
# Fixture plates the branch's truth cannot be met on, each with what it is held to instead:
|
||||
# float32 the branch solved the plate in float32 (mathutils); it stands up to 2e-6 m (solid) or 3e-5 m (panels) from the float64 solid:
|
||||
# held to the truth at FLOAT32
|
||||
# corner the branch's massing.corners lost a true corner to its float32 inside test, so its solid lacks one corner plate.py has and its
|
||||
# clad is another solid's: held to the fixture's repaired truth (the branch's builder with that test at 1e-5 m), solid, facets,
|
||||
# panels and bolts, and its corners to the branch's plus that one
|
||||
# tie two edges of the split facet are equally long and the branch's choice followed Blender's loop order, which differs between
|
||||
# the two sides of this row: solid, facets and counts held to the branch's truth, panels to the fixture's repaired truth (the
|
||||
# branch's clad cutting from the other of the two edges)
|
||||
KNOWN = {("bastion", "Hull.Cheek.R"): "float32", ("bastion", "Hull.Cheek.L"): "float32", ("bastion", "Hull.BellySide.L"): "float32",
|
||||
("bastion", "Hull.Quarter.R"): "corner", ("bastion", "Hull.Quarter.L"): "corner", ("bastion", "Hull.BellySide.R"): "tie",
|
||||
("raptor", "Torso.Jaw1.L"): "float32", ("raptor", "Torso.Cheek.R"): "float32", ("raptor", "Torso.Cheek.L"): "float32",
|
||||
("raptor", "Torso.Belt3.R"): "float32", ("raptor", "Torso.Belt3.L"): "float32"}
|
||||
SOLID, PANELS = 1e-6, 1e-5 # the cut's tolerances, metres
|
||||
FLOAT32 = (4e-6, 4e-5) # for a KNOWN float32 plate: a few float32 steps at 8 m, and the same through an inset
|
||||
FLOAT32 = (4e-6, 4e-5) # for a KNOWN plate: a few float32 steps at 8 m, and the same through an inset
|
||||
# Panels whose outline crosses itself: the inset passes the two ends of a short edge over each other, as the branches' own inset does.
|
||||
# Blender fills such a cap by where its loop starts, and a facet's loop starts at plate.py's least vertex but at Blender's own in a
|
||||
# branch's mesh: that is the whole of Hull.Cheek.R's difference in a render (109 pixels at 1024 from above, vertices 2e-6 m apart).
|
||||
CROSSED = {("bastion", 1, "Hull.Cheek.R", 4), ("paladin", 1, "Thigh.Outer", 0)} # (mech, side, plate, panel)
|
||||
# The three fixtures' builds as one sha256, of coordinates rounded to QUANTUM metres and of every face. Starfire (Windows 11, numpy
|
||||
# 2.5.4) and Yggdrasil (Debian 13, numpy 2.2.4 on the system LAPACK) give this hash; their coordinates differ in 3,221 of 34,359 by up
|
||||
# to 2.7e-15 m and in no face. QUANTUM is TIE: 3.7e5 times that, and 1e3 under the least difference KNOWN holds (1.06e-6 m).
|
||||
QUANTUM = 1e-9
|
||||
HASH = "ff870b40db0baac928dd6462260e92e8c4e1ebb77f80adc15e1aff551fe41f0e"
|
||||
|
||||
|
||||
@unittest.skipIf(np is None, "numpy is not installed")
|
||||
class ParityTests(unittest.TestCase):
|
||||
"""plate.build against each branch's own builder: solid vertices as a set, facet count, panel vertices as a set,
|
||||
bolt count. Kills: the miter clamp 0.3 -> 0.5; the cut's share (0.36, 0.64) -> (0.3, 0.7); the lift-order coin
|
||||
removed; a slab's gap ignored (raptor). The outer test 0.97 -> 0.9 is CladTests' (no fixture facet stands
|
||||
between the two)."""
|
||||
removed; a slab's gap ignored (raptor); the clad of Hull.Quarter left out; Hull.BellySide.R's panels moved
|
||||
0.5 m. The outer test 0.97 -> 0.9 is CladTests' (no fixture facet stands between the two)."""
|
||||
|
||||
def held(self, made, truth, solid, panels):
|
||||
self.assertEqual(made["report"]["facets"], truth["facets"])
|
||||
self.assertEqual(made["report"]["bolts"], truth["bolts"])
|
||||
self.assertEqual(len(made["panels"][0]), len(truth["panels"]))
|
||||
self.assertEqual(len(made["solid"][0]), len(truth["solid"]))
|
||||
self.assertLessEqual(apart(made["solid"][0], truth["solid"]), solid)
|
||||
self.assertLessEqual(apart(made["panels"][0], truth["panels"]), panels)
|
||||
|
||||
def parity(self, mech, plates):
|
||||
fixture = json.loads((FIXTURES / f"plates_{mech}.json").read_text(encoding="utf-8"))
|
||||
table, cases, repaired = fixture(mech)["table"], fixture(mech)["cases"], fixture(mech).get("repaired", {"truth": {}})["truth"]
|
||||
seen = 0
|
||||
for case in fixture["cases"]:
|
||||
built = {e["name"]: e for e in plate.build(fixture["table"], case["side"])}
|
||||
self.assertEqual(set(repaired), {name for (m, name), kind in KNOWN.items() if m == mech and kind != "float32"})
|
||||
for case in cases:
|
||||
built = {e["name"]: e for e in plate.build(table, case["side"])}
|
||||
for name, truth in case["truth"].items():
|
||||
made, known = built[name], KNOWN.get((mech, name))
|
||||
seen += 1
|
||||
with self.subTest(plate=name, side=case["side"]):
|
||||
solid, panels = apart(made["solid"][0], truth["solid"]), apart(made["panels"][0], truth["panels"])
|
||||
if known == "corner":
|
||||
V, T = made["solid"][0], np.array(truth["solid"])
|
||||
d = np.linalg.norm(V[:, None, :] - T[None, :, :], axis=2)
|
||||
self.assertLess(float(d.min(axis=0).max()), FLOAT32[0]) # every corner of the branch's is one of these
|
||||
self.assertEqual(int((d.min(axis=1) > 1e-3).sum()), 1) # and one more, which the faces do bound
|
||||
continue
|
||||
self.assertEqual(made["report"]["facets"], truth["facets"])
|
||||
self.assertEqual(made["report"]["bolts"], truth["bolts"])
|
||||
self.assertEqual(len(made["panels"][0]), len(truth["panels"]))
|
||||
self.assertLessEqual(solid, FLOAT32[0] if known == "float32" else SOLID)
|
||||
if known == "tie":
|
||||
self.assertGreater(panels, 0.1)
|
||||
self.held(made, repaired[name], *FLOAT32)
|
||||
elif known == "tie":
|
||||
self.assertGreater(apart(made["panels"][0], truth["panels"]), 0.1) # the branch cut from the other edge
|
||||
self.held(made, dict(truth, panels=repaired[name]["panels"]), *FLOAT32)
|
||||
self.assertEqual({key: repaired[name][key] for key in ("solid", "facets", "bolts")}, {key: truth[key] for key in ("solid", "facets", "bolts")})
|
||||
else:
|
||||
self.assertLessEqual(panels, FLOAT32[1] if known == "float32" else PANELS)
|
||||
self.held(made, truth, *(FLOAT32 if known == "float32" else (SOLID, PANELS)))
|
||||
self.assertEqual(seen, plates)
|
||||
|
||||
def test_bastion(self):
|
||||
|
|
@ -471,7 +551,7 @@ class ParityTests(unittest.TestCase):
|
|||
self.parity("raptor", 50)
|
||||
|
||||
def test_the_lost_corner_is_a_corner(self):
|
||||
table = plate.check(json.loads((FIXTURES / "plates_bastion.json").read_text(encoding="utf-8"))["table"])
|
||||
table = plate.check(fixture("bastion")["table"])
|
||||
quarter = next(r for r in table["plates"] if r["name"] == "Hull.Quarter")
|
||||
points, _ = plate._row_points(quarter, "plates")
|
||||
planes = [(np.array(f["normal"]) / np.linalg.norm(f["normal"]), np.array(f["at"])) for f in quarter["faces"]]
|
||||
|
|
@ -479,6 +559,15 @@ class ParityTests(unittest.TestCase):
|
|||
self.assertTrue((slack < 1e-9).all()) # every corner is inside every face
|
||||
self.assertTrue(((np.abs(slack) < 1e-9).sum(axis=1) >= 3).all()) # and on three of them
|
||||
|
||||
def test_the_panels_whose_outline_crosses_itself(self):
|
||||
crossed = set()
|
||||
for mech in ("bastion", "paladin", "raptor"):
|
||||
for case in fixture(mech)["cases"]:
|
||||
for entry in plate.build(fixture(mech)["table"], case["side"]):
|
||||
if entry["name"] in case["truth"]:
|
||||
crossed |= {(mech, case["side"], entry["name"], k) for k, three in enumerate(rings(entry["panels"])) if any(plate._crosses(ring) for ring in three)}
|
||||
self.assertEqual(crossed, CROSSED)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue