spine-rigc 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/cli.ts +88 -21
  2. package/docs/AUTHORING.md +18 -12
  3. package/package.json +1 -1
  4. package/src/assertions/bodies/a03.ts +27 -0
  5. package/src/assertions/bodies/a04.ts +40 -0
  6. package/src/assertions/bodies/a06.ts +195 -0
  7. package/src/assertions/bodies/a08.ts +76 -0
  8. package/src/assertions/bodies/a11.ts +15 -0
  9. package/src/assertions/bodies/a13.ts +51 -0
  10. package/src/assertions/bodies/a14.ts +35 -0
  11. package/src/assertions/bodies/a15.ts +97 -0
  12. package/src/assertions/bodies/a17.ts +26 -0
  13. package/src/assertions/bodies/a19.ts +295 -0
  14. package/src/assertions/bodies/a20.ts +122 -0
  15. package/src/assertions/bodies/a21.ts +190 -0
  16. package/src/assertions/bodies/a22.ts +39 -0
  17. package/src/assertions/bodies/a23.ts +255 -0
  18. package/src/assertions/bodies/a27.ts +33 -0
  19. package/src/assertions/bodies/a28.ts +70 -0
  20. package/src/assertions/bodies/a33.ts +110 -0
  21. package/src/assertions/bodies/a36.ts +81 -0
  22. package/src/assertions/bodies/a37.ts +77 -0
  23. package/src/assertions/bodies/a38.ts +73 -0
  24. package/src/assertions/bodies/a41.ts +83 -0
  25. package/src/assertions/bodies/a42.ts +97 -0
  26. package/src/assertions/bodies/a44.ts +23 -0
  27. package/src/assertions/bodies/a45.ts +172 -0
  28. package/src/assertions/bodies/a47.ts +59 -0
  29. package/src/assertions/bodies/a48.ts +83 -0
  30. package/src/assertions/constraint_words.ts +177 -0
  31. package/src/assertions/facts/animated_bones.ts +28 -0
  32. package/src/assertions/facts/atlas_pages.ts +19 -0
  33. package/src/assertions/facts/atlas_regions.ts +52 -0
  34. package/src/assertions/facts/constraints.ts +131 -0
  35. package/src/assertions/facts/linked_meshes.ts +38 -0
  36. package/src/assertions/facts/mesh_attachments.ts +71 -0
  37. package/src/assertions/facts/region_joins.ts +34 -0
  38. package/src/assertions/facts/skin_entries.ts +37 -0
  39. package/src/assertions/facts/skin_members.ts +53 -0
  40. package/src/assertions/facts/skin_meshes.ts +49 -0
  41. package/src/assertions/facts/slot_colour.ts +43 -0
  42. package/src/assertions/facts/stage.ts +24 -0
  43. package/src/assertions/facts/vertex_polygons.ts +53 -0
  44. package/src/assertions/harness.ts +109 -0
  45. package/src/assertions/kinds.ts +102 -0
  46. package/src/assertions/mesh_kinds.ts +56 -0
  47. package/src/assertions/model/animated_bones.ts +30 -0
  48. package/src/assertions/model/atlas_pages.ts +15 -0
  49. package/src/assertions/model/atlas_regions.ts +76 -0
  50. package/src/assertions/model/constraints.ts +207 -0
  51. package/src/assertions/model/given.ts +45 -0
  52. package/src/assertions/model/index.ts +247 -0
  53. package/src/assertions/model/linked_meshes.ts +24 -0
  54. package/src/assertions/model/mesh_attachments.ts +90 -0
  55. package/src/assertions/model/parse.ts +138 -0
  56. package/src/assertions/model/region_joins.ts +59 -0
  57. package/src/assertions/model/skin_entries.ts +59 -0
  58. package/src/assertions/model/skin_members.ts +62 -0
  59. package/src/assertions/model/skin_meshes.ts +90 -0
  60. package/src/assertions/model/slot_colour.ts +80 -0
  61. package/src/assertions/model/stage.ts +28 -0
  62. package/src/assertions/model/vertex_polygons.ts +71 -0
  63. package/src/assertions/reasons.ts +127 -0
  64. package/src/assertions/region_lookups.ts +61 -0
  65. package/src/assertions/values.ts +39 -0
  66. package/src/check.ts +36 -9
  67. package/src/compile.ts +204 -57
  68. package/src/core/index.ts +161 -29
  69. package/src/core/world.ts +21 -20
  70. package/src/deformmeasure.ts +377 -154
  71. package/src/deformreport.ts +3 -0
  72. package/src/deformstructure.ts +344 -0
  73. package/src/emit_spine.ts +21 -41
  74. package/src/keyorder.ts +40 -0
  75. package/src/model.ts +188 -22
  76. package/src/render.ts +243 -54
  77. package/src/render_core.ts +101 -13
  78. package/src/transform.ts +79 -30
  79. package/src/validate.ts +742 -2781
@@ -0,0 +1,122 @@
1
+ /**
2
+ * A20, the body (issue #1025, step 4c of #380): a weighted mesh's weights
3
+ * cohere — every vertex bound, every weight finite and non-negative, every
4
+ * vertex's weights summing to 1 — and, under `spine-html`, a generated mesh is
5
+ * weighted, binds only bones that move it and binds every bone it declares.
6
+ *
7
+ * Moved out of `src/validate.ts` clause by clause, every clause about the
8
+ * weights themselves moving: a document's mesh names each vertex's bindings,
9
+ * so a vertex count that disagrees with the `uvs`, an empty binding list, a
10
+ * weight that is not finite, below 0 or 0 on a generated mesh, a sum off 1 and
11
+ * a declared bone no vertex binds each have a place to live there (the reader
12
+ * refuses the first three by the record's name). The one clause that does not
13
+ * — a binding's index past the bone array — is about the encoding: the
14
+ * document names a binding's bone, and the index is the emitter's to write.
15
+ * It stays with the round trip, which hands its finding in on the binding
16
+ * (`MeshBinding.encoding`), printed where the body always printed it.
17
+ *
18
+ * The weights are the ones the runtime holds — float32 — and a binding's bone
19
+ * its index in the roster, because the weight-0 clause prints it.
20
+ */
21
+ import type { Verdicts } from '../harness.ts';
22
+ import type { MeshFacts } from '../facts/mesh_attachments.ts';
23
+ import { meshKindOf } from '../mesh_kinds.ts';
24
+ import { SKIP_NO_MESH_ATTACHMENT } from '../reasons.ts';
25
+ import type { RigInfo } from '../../types.ts';
26
+
27
+ export function a20MeshWeightsCoherent({ fail, skip }: Verdicts, { meshes, bones }: MeshFacts, policy: boolean, rig: RigInfo | undefined): void {
28
+ if (meshes.length === 0) return skip('A20_MESH_WEIGHTS_COHERENT', SKIP_NO_MESH_ATTACHMENT);
29
+ for (const mesh of meshes) {
30
+ // 🚨 Authored geometry is not rigc's to have opinions about. The two
31
+ // policy branches in this assertion are both statements about what a
32
+ // rigc GENERATOR is supposed to produce — "a mesh here is weighted",
33
+ // "a generated mesh binds only bones that move it" — and neither is a
34
+ // fact about Spine or about somebody else's mesh. Applying them to
35
+ // authored geometry failed correct data (issue #44). The coherence
36
+ // rules below the branch are unconditional and still apply.
37
+ const generated = meshKindOf(mesh, rig) !== 'authored';
38
+ if (!mesh.weights) {
39
+ // 📐 PROFILE. An unweighted mesh is perfectly valid Spine — spineboy
40
+ // ships two — and the runtime poses it from the slot bone. What is
41
+ // NOT valid, in any profile, is a weighted mesh whose weights do not
42
+ // cohere, which is everything below this branch. So the requirement
43
+ // that a mesh be weighted at all is the policy half, and it is the
44
+ // only half gated here.
45
+ if (policy && generated) {
46
+ fail('A20_MESH_WEIGHTS_COHERENT', `mesh "${mesh.name}" is unweighted; the ring tier drives meshes by bones`);
47
+ }
48
+ continue;
49
+ }
50
+ const perVertex = mesh.weights;
51
+ const expected = mesh.worldVerticesLength / 2;
52
+ if (perVertex.length !== expected) {
53
+ fail(
54
+ 'A20_MESH_WEIGHTS_COHERENT',
55
+ `mesh "${mesh.name}" has weights for ${perVertex.length} vertices but ${expected} uv pairs`,
56
+ );
57
+ continue;
58
+ }
59
+ perVertex.forEach((vertex, i) => {
60
+ if (!vertex.length) fail('A20_MESH_WEIGHTS_COHERENT', `mesh "${mesh.name}" vertex ${i} has no bones`);
61
+ let sum = 0;
62
+ for (const { bone, weight, encoding } of vertex) {
63
+ if (!Number.isFinite(weight) || weight < 0) {
64
+ fail('A20_MESH_WEIGHTS_COHERENT', `mesh "${mesh.name}" vertex ${i} has weight ${weight}`);
65
+ }
66
+ // 📐 PROFILE. A weight of exactly 0 is legal, harmless Spine: the
67
+ // runtime accumulates `(…) * weight` (Attachment.js:131), so the
68
+ // binding contributes nothing. The Spine editor writes them — the
69
+ // auto-weighted meshes in 6-arcs, 7-anticipation and 8-follow-through
70
+ // carry dozens, and their vertex weights still sum to 1. Treating one
71
+ // as corruption failed three rungs of the ladder on correct data.
72
+ // In a rigc-GENERATED ring or ribbon it is still a defect: the
73
+ // generator bound a bone that does nothing, which is a bug in the
74
+ // generator and dead work in the runtime's inner loop. So it stays a
75
+ // failure under spine-html and is not one under spine.
76
+ else if (policy && generated && weight === 0) {
77
+ fail(
78
+ 'A20_MESH_WEIGHTS_COHERENT',
79
+ `mesh "${mesh.name}" vertex ${i} is bound to bone index ${bone} at weight 0; a generated mesh binds only bones that move it`,
80
+ );
81
+ }
82
+ // The index's range is the encoding's, kept with the round trip (the header).
83
+ if (encoding !== undefined) fail('A20_MESH_WEIGHTS_COHERENT', encoding);
84
+ sum += weight;
85
+ }
86
+ if (Math.abs(sum - 1) > 1e-3) {
87
+ fail('A20_MESH_WEIGHTS_COHERENT', `mesh "${mesh.name}" vertex ${i} weights sum to ${sum.toFixed(4)}`);
88
+ }
89
+ });
90
+ // 📐 PROFILE, and the converse of the weight-0 branch above: that one
91
+ // says a generated mesh binds only bones that MOVE it, and this one says
92
+ // every bone it declares moves it. They are halves of one sentence — the
93
+ // bone set the mesh declares is the bone set its weights reference — so
94
+ // they are one assertion rather than two, and neither is a fact about
95
+ // Spine: a declared bone nothing binds loads and renders perfectly.
96
+ //
97
+ // 🚨 It is the one mesh question a vertex cannot answer, which is why
98
+ // every per-vertex rule above was green on the ring that raised it: a
99
+ // rig-spec ring naming two grips bound one of them, and the absent bone
100
+ // appears in no vertex, in no sum and in no index (issue #684). The
101
+ // declaration comes from the compiler's own record of what it bound,
102
+ // which is what the `MESH` report line prints.
103
+ if (policy && generated && rig) {
104
+ const declared = rig.meshDeclaredBones[mesh.slot] || [];
105
+ const bound = new Set<string>();
106
+ for (const vertex of perVertex) {
107
+ for (const { bone } of vertex) {
108
+ const named = bones[bone];
109
+ if (named !== undefined) bound.add(named);
110
+ }
111
+ }
112
+ for (const name of declared) {
113
+ if (bound.has(name)) continue;
114
+ fail(
115
+ 'A20_MESH_WEIGHTS_COHERENT',
116
+ `mesh "${mesh.name}" declares bone "${name}" and none of its ${perVertex.length} vertices binds it; ` +
117
+ `the weights reference ${[...bound].map((n) => `"${n}"`).join(', ')}`,
118
+ );
119
+ }
120
+ }
121
+ }
122
+ }
@@ -0,0 +1,190 @@
1
+ /**
2
+ * A21, the body (issue #1025, step 4c of #380): a generated mesh's rim — or
3
+ * a ribbon's entry row — is pinned to the slot's own bone, and a soft region
4
+ * moves only the vertices it declares. An `archetype` rule.
5
+ *
6
+ * Moved out of `src/validate.ts` whole: every clause is about the rig — which
7
+ * vertex sits on the region border or the hull, which bone carries it and at
8
+ * what weight — and a document's mesh states each of those (its `uvs`, its
9
+ * `hull`, its bindings by bone). Nothing it reads is the encoding's. The
10
+ * weights are the runtime's float32, a binding's bone its index in the roster
11
+ * (named back through the roster where the sentence names it), and a link's
12
+ * geometry its source's.
13
+ */
14
+ import type { Verdicts } from '../harness.ts';
15
+ import type { MeshFacts } from '../facts/mesh_attachments.ts';
16
+ import { authoredMeshNames, meshKindOf } from '../mesh_kinds.ts';
17
+ import type { RigInfo } from '../../types.ts';
18
+
19
+ export function a21MeshRimPinned({ fail, skip }: Verdicts, { meshes, bones }: MeshFacts, rig: RigInfo | undefined): void {
20
+ // Without the rig, ring and ribbon cannot be told apart — and the two kinds
21
+ // pin OPPOSITE edges, so guessing one would either check the wrong edge or
22
+ // check nothing while reporting a pass.
23
+ if (!rig) {
24
+ return skip('A21_MESH_RIM_PINNED', 'no rig info (validating a bare directory), so ring and ribbon cannot be told apart');
25
+ }
26
+ if (!meshes.some((m) => m.weights)) {
27
+ return skip('A21_MESH_RIM_PINNED', 'the skeleton has no weighted mesh attachment, so there is no rim to find unpinned');
28
+ }
29
+ // An authored mesh has no rim rigc drew and no entry row rigc placed, and
30
+ // a linked mesh has no rim of its OWN at all — the one it draws belongs to
31
+ // its source, and is measured there. Nothing to measure is a SKIP — never
32
+ // a pass, and never a failure on somebody else's correct geometry.
33
+ //
34
+ // 🔸 A `segments` mesh is rigc's own geometry and still has no rim to pin:
35
+ // its outline is traced off the art and weighted by distance like every
36
+ // other vertex, because a layer pulled by named bones is SUPPOSED to move
37
+ // at its edge. "Pinned to the slot bone" is not a claim that generator
38
+ // makes, so there is nothing here to hold it to — and `A20`'s coherence
39
+ // rules, which it does make, still apply to it in full.
40
+ const rimless = (m: (typeof meshes)[number]): boolean => meshKindOf(m, rig) === 'authored' || meshKindOf(m, rig) === 'segments';
41
+ const measurable = meshes.filter((m) => m.weights && !rimless(m));
42
+ if (measurable.length === 0) {
43
+ const authored = authoredMeshNames(meshes.filter((m) => m.weights), rig);
44
+ const segmented = meshes.filter((m) => m.weights && meshKindOf(m, rig) === 'segments').map((m) => `"${m.name}"`);
45
+ return skip(
46
+ 'A21_MESH_RIM_PINNED',
47
+ segmented.length === 0
48
+ ? `every weighted mesh here is authored or linked geometry (${authored.join(', ')}), not a rigc ring or ` +
49
+ 'ribbon — rigc did not place its rim, so it has no rim of its own to find unpinned'
50
+ : `every weighted mesh here is ${authored.length ? `authored or linked geometry (${authored.join(', ')}) or ` : ''}` +
51
+ `a "segments" lattice (${segmented.join(', ')}), not a rigc ring or ribbon — a segments mesh weights its ` +
52
+ 'outline by distance to the bones it names, so it has no rim pinned to the slot bone to find unpinned',
53
+ );
54
+ }
55
+ for (const mesh of measurable) {
56
+ if (!mesh.weights) continue;
57
+ const perVertexAll = mesh.weights;
58
+ const slotBoneOf = mesh.slotBone;
59
+ // A ribbon's outer boundary is SUPPOSED to move — that is the whole point
60
+ // of a strip that changes length. So the rule splits by mesh kind rather
61
+ // than being relaxed: for a ribbon the invariant is that the ENTRY row
62
+ // cannot move, because that row is where the strip joins the part it
63
+ // comes out of. Both rules protect the same thing (the mesh's join to the
64
+ // plate underneath); they just live at different edges of the mesh.
65
+ //
66
+ // A `contour` takes the hull path below, and that is the check it wants
67
+ // rather than a third branch: a contour mesh's hull IS every vertex it
68
+ // has, and every one is pinned to the slot bone at weight 1, so "the rim
69
+ // is pinned" reads over the whole mesh. If a later contour tier ever
70
+ // moves interior vertices, this is the assertion that has to grow a
71
+ // branch — it will fail rather than pass quietly, which is the right way
72
+ // round.
73
+ if (meshKindOf(mesh, rig) === 'ribbon') {
74
+ const uvs = mesh.regionUVs ?? [];
75
+ let entryRow = 0;
76
+ for (let v = 0; v < perVertexAll.length; v++) {
77
+ if (Math.abs(uvs[v * 2 + 1]) > 1e-6) continue; // not on the entry edge
78
+ entryRow++;
79
+ const vertex = perVertexAll[v];
80
+ if (vertex.length !== 1 || Math.abs(vertex[0].weight - 1) > 1e-6) {
81
+ fail(
82
+ 'A21_MESH_RIM_PINNED',
83
+ `ribbon "${mesh.name}" entry vertex ${v} is not pinned (${vertex.map((w) => w.weight.toFixed(3)).join('+')})`,
84
+ );
85
+ continue;
86
+ }
87
+ if (slotBoneOf && bones[vertex[0].bone] !== slotBoneOf) {
88
+ fail(
89
+ 'A21_MESH_RIM_PINNED',
90
+ `ribbon "${mesh.name}" entry vertex ${v} is pinned to "${bones[vertex[0].bone]}", not the anchor bone "${slotBoneOf}"`,
91
+ );
92
+ }
93
+ }
94
+ if (entryRow < 2) {
95
+ fail('A21_MESH_RIM_PINNED', `ribbon "${mesh.name}" has ${entryRow} vertices on its entry edge; a strip needs two`);
96
+ }
97
+ continue;
98
+ }
99
+ // A rim a soft mask deliberately CARRIED (issue #382). The rule splits
100
+ // by declaration rather than being relaxed — the same move the ribbon
101
+ // branch above makes, and for the same reason: a wobbling silhouette is
102
+ // supposed to move, and the invariant is that nothing ELSE does. So on
103
+ // such a mesh a vertex is either pinned to the slot bone at 1 or shared
104
+ // between it and the ONE bone the rig declared, and a third bone, a
105
+ // wrong bone or a weight that does not close is still a failure.
106
+ const boundBone = rig.meshSoftBones[mesh.slot] ?? null;
107
+ if (boundBone !== null) {
108
+ const allowed = new Set([slotBoneOf, boundBone]);
109
+ let carried = 0;
110
+ for (let v = 0; v < perVertexAll.length; v++) {
111
+ const vertex = perVertexAll[v];
112
+ let sum = 0;
113
+ for (const { bone, weight } of vertex) {
114
+ const name = bones[bone];
115
+ if (!allowed.has(name)) {
116
+ fail(
117
+ 'A21_MESH_RIM_PINNED',
118
+ `mesh "${mesh.name}" vertex ${v} is carried by "${name}", and this mesh declares only ` +
119
+ `"${slotBoneOf}" and the soft region's "${boundBone}"`,
120
+ );
121
+ }
122
+ if (name === boundBone && weight > 0) carried = carried + (weight >= 1 ? 1 : 0);
123
+ sum += weight;
124
+ }
125
+ if (Math.abs(sum - 1) > 1e-4) {
126
+ fail(
127
+ 'A21_MESH_RIM_PINNED',
128
+ `mesh "${mesh.name}" vertex ${v} weights sum to ${sum.toFixed(4)}; a depth-bound mesh splits each ` +
129
+ 'vertex between the slot bone and the bound bone, so it closes at 1',
130
+ );
131
+ }
132
+ }
133
+ // A mask that carried nothing reached here as a mesh pinned exactly
134
+ // as before, which is not the thing that was declared.
135
+ if (carried === 0) {
136
+ fail(
137
+ 'A21_MESH_RIM_PINNED',
138
+ `mesh "${mesh.name}" declares a soft region on "${boundBone}" and no vertex is fully carried by it`,
139
+ );
140
+ }
141
+ continue;
142
+ }
143
+ const hullVertices = mesh.hullLength / 2;
144
+ if (!Number.isInteger(hullVertices) || hullVertices < 3) {
145
+ fail('A21_MESH_RIM_PINNED', `mesh "${mesh.name}" declares hull ${mesh.hullLength / 2}; the rim must be a real ring`);
146
+ continue;
147
+ }
148
+ const perVertex = mesh.weights;
149
+ if (hullVertices > perVertex.length) {
150
+ fail('A21_MESH_RIM_PINNED', `mesh "${mesh.name}" hull is ${hullVertices} of ${perVertex.length} vertices`);
151
+ continue;
152
+ }
153
+ // The rim is the alpha contour where generated pixels meet untouched
154
+ // base. One bone at weight 1, and that bone must be the slot's own —
155
+ // anything else and the seam can move.
156
+ const slotBone = mesh.slotBone;
157
+ for (let i = 0; i < hullVertices; i++) {
158
+ const vertex = perVertex[i];
159
+ if (vertex.length !== 1 || Math.abs(vertex[0].weight - 1) > 1e-6) {
160
+ fail(
161
+ 'A21_MESH_RIM_PINNED',
162
+ `mesh "${mesh.name}" rim vertex ${i} is not pinned (${vertex.map((v) => v.weight.toFixed(3)).join('+')})`,
163
+ );
164
+ continue;
165
+ }
166
+ if (slotBone && bones[vertex[0].bone] !== slotBone) {
167
+ fail(
168
+ 'A21_MESH_RIM_PINNED',
169
+ `mesh "${mesh.name}" rim vertex ${i} is pinned to "${bones[vertex[0].bone]}", not the slot bone "${slotBone}"`,
170
+ );
171
+ }
172
+ }
173
+ // Independent of the ring ORDER: whatever sits on the region border is
174
+ // the outline, and the outline moving means the part's own edge moving.
175
+ // Without this, reordering the rings would move the pinned prefix off
176
+ // the outline and A21 would still pass on the count alone.
177
+ const uvs = mesh.regionUVs ?? [];
178
+ for (let v = 0; v < perVertex.length; v++) {
179
+ const u = uvs[v * 2];
180
+ const t = uvs[v * 2 + 1];
181
+ const onBorder = [u, t].some((c) => Math.abs(c) < 1e-6 || Math.abs(c - 1) < 1e-6);
182
+ if (!onBorder) continue;
183
+ const vertex = perVertex[v];
184
+ if (vertex.length !== 1 || Math.abs(vertex[0].weight - 1) > 1e-6) {
185
+ fail('A21_MESH_RIM_PINNED', `mesh "${mesh.name}" vertex ${v} is on the region border but not pinned`);
186
+ break;
187
+ }
188
+ }
189
+ }
190
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A22, the body (issue #1025, step 4c of #380): every mesh's authored UVs lie
3
+ * in the unit square, one pair per vertex.
4
+ *
5
+ * Moved out of `src/validate.ts` unchanged but for what it reads: the meshes
6
+ * are a fact (`../facts/skin_meshes.ts`). The `check` call stays in
7
+ * `validate()`.
8
+ */
9
+ import type { Verdicts } from '../harness.ts';
10
+ import type { SkinMeshFacts } from '../facts/skin_meshes.ts';
11
+ import { SKIP_NO_MESH_ATTACHMENT } from '../reasons.ts';
12
+
13
+ export function a22MeshUvsInUnitRange({ fail, skip }: Verdicts, { meshes }: SkinMeshFacts): void {
14
+ const meshAttachments = meshes;
15
+ if (meshAttachments.length === 0) return skip('A22_MESH_UVS_IN_UNIT_RANGE', SKIP_NO_MESH_ATTACHMENT);
16
+ for (const mesh of meshAttachments) {
17
+ // `regionUVs` is what the JSON authored; `uvs` is the page-space result
18
+ // and stays EMPTY until a renderer calls computeUVs, so asserting on it
19
+ // here would be asserting on the wrong array (measured: length 0 after
20
+ // a clean load). With one part per page the two are equal anyway —
21
+ // computeUVs reduces to `u + regionUV * width` with u=0, width=1
22
+ // (MeshAttachment.js:173-174), which is the claim this assertion rests
23
+ // on and this is where it is checked.
24
+ const uvs = mesh.regionUVs;
25
+ if (!uvs || uvs.length !== mesh.worldVerticesLength) {
26
+ fail(
27
+ 'A22_MESH_UVS_IN_UNIT_RANGE',
28
+ `mesh "${mesh.name}" has ${uvs?.length ?? 0} authored uv values for ${mesh.worldVerticesLength}`,
29
+ );
30
+ continue;
31
+ }
32
+ for (let i = 0; i < uvs.length; i++) {
33
+ if (!Number.isFinite(uvs[i]) || uvs[i] < -1e-6 || uvs[i] > 1 + 1e-6) {
34
+ fail('A22_MESH_UVS_IN_UNIT_RANGE', `mesh "${mesh.name}" uv[${i}] is ${uvs[i]}`);
35
+ break;
36
+ }
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,255 @@
1
+ /**
2
+ * A23, the body (issue #1025, step 4c of #380): a physics constraint that
3
+ * does nothing, quietly — at its setup pose, and on every physics key.
4
+ *
5
+ * Moved out of `src/validate.ts` whole: every clause is about the rig — the
6
+ * components a constraint drives, its four bounded setup values, its `fps`,
7
+ * every value a physics timeline keys and what switches a muted constraint on
8
+ * — and a document's constraint and timeline records state each. Nothing it
9
+ * reads is the encoding's. The values are the ones the runtime holds after
10
+ * its parse, through the facts (`../facts/constraints.ts`): a field left out
11
+ * at the parser's value, `massInverse` = `1 / mass`, `step` = `1 / fps`, a
12
+ * key's time and value as float32, a key's value as the pose field it lands
13
+ * in (`posed`), and the constraints a timeline naming none reaches.
14
+ */
15
+ import type { Verdicts } from '../harness.ts';
16
+ import type { ConstraintFacts, PhysicsSetup } from '../facts/constraints.ts';
17
+ import type { MeshFacts } from '../facts/mesh_attachments.ts';
18
+ import { noneKeysItsMixAbove0, PHYSICS_COMPONENTS, REST_OR_KEY_ITS_MIX, switchedOn } from '../constraint_words.ts';
19
+ import { SKIP_NO_PHYSICS_CONSTRAINT } from '../reasons.ts';
20
+ import {
21
+ PHYSICS_POSE_RULES,
22
+ physicsBasisFor,
23
+ physicsBasisSays,
24
+ physicsKeyRefusal,
25
+ physicsOutsideSays,
26
+ physicsRuleFor,
27
+ type PhysicsPoseRule,
28
+ } from '../../timelines.ts';
29
+
30
+ /**
31
+ * What A23 says about a SETUP pose outside its bound, per property.
32
+ *
33
+ * The predicate lives in `PHYSICS_POSE_RULES` and the sentence lives here, and
34
+ * the split is deliberate: the predicate is the thing the compiler and this file
35
+ * must not disagree about, while the sentence names what happens to THIS rig —
36
+ * "it is muted", "nothing pulls it back" — which is what the author acts on and
37
+ * is worth nothing to a compiler refusing a key. `PHYSICS_POSE_RULES` is the
38
+ * index, so a rule added there with no sentence here fails to type-check rather
39
+ * than printing `undefined`.
40
+ *
41
+ * ⚠️ These are the SETUP pose's sentences and nothing else, which matters on the
42
+ * two rows whose keyed bound is wider than their resting one — `mix` since issue
43
+ * #610 and `strength` since #727. A key of 0 on either is accepted, so "it is
44
+ * muted" and "nothing pulls it back" are read here by a rig that states the
45
+ * number at rest, and what a key is refused with is the row's own `why`.
46
+ *
47
+ * `animations` is how many animations the skeleton declares, and only the `mix`
48
+ * sentence reads it: that bound is the one a key can satisfy instead of the
49
+ * setup pose (`inertAtSetup`, issue #743), so the refusal has to say that the
50
+ * other half was looked for and how wide the search was. A rig with no animation
51
+ * at all then says "none of the 0 animations" rather than implying somebody
52
+ * keyed something.
53
+ *
54
+ * `rule` is the row the value was judged by, and every sentence reads it: the
55
+ * reason each prints is the row's `basis` arm for the value (issue #798), the
56
+ * same object the key's sentence quotes, so what the setup pose and a key say
57
+ * about one number is one text — and whether that reason is the runtime's
58
+ * arithmetic or rigc's call is stated rather than implied.
59
+ */
60
+ const SETUP_POSE_SAYS: Record<string, (pose: PhysicsSetup, animations: number, rule: PhysicsPoseRule) => string> = {
61
+ // Every reason below is the row's `basis` arm for the value (issue #798): an
62
+ // arithmetic arm names its expression, a behavioural one says refusing it is
63
+ // rigc's call and what the value does. ⚠️ Until then a setup mix BELOW 0 was
64
+ // told "it is muted", which it is not — [measured] it moves the bone by
65
+ // exactly −1× what +0.5 does — so the two ways out print two sentences.
66
+ mix: (pose, animations, rule) =>
67
+ `has mix ${pose.mix} and ${noneKeysItsMixAbove0(animations)}; ${setupBasisSays(rule, pose.mix)} — ${REST_OR_KEY_ITS_MIX}`,
68
+ mass: (pose, _animations, rule) => `has massInverse ${pose.massInverse}; mass must be ${rule.states} — ${setupBasisSays(rule, pose.massInverse)}`,
69
+ // Two arms, read off the row (issue #748): 0 is a constraint nothing pulls
70
+ // back and below 0 one that is pushed away, and the row's `why` — the key's
71
+ // sentence — quotes the second from the same object. The basis sentence ends
72
+ // on the arm's own words, which `T100` holds.
73
+ strength: (pose, _animations, rule) => `has strength ${pose.strength}; ${setupBasisSays(rule, pose.strength)}`,
74
+ // The bound is read off the row, so the setup pose and a key cannot state two
75
+ // intervals; the reason is the arm the value took, since the ends are inside (#794).
76
+ damping: (pose, _animations, rule) =>
77
+ `has damping ${pose.damping}; must be ${rule.states} — the per-step decay is \`damping ** (60 * step)\`, and ` +
78
+ setupBasisSays(rule, pose.damping),
79
+ };
80
+
81
+ /**
82
+ * The basis sentence for a setup value, or the bound itself where no arm holds
83
+ * — a pose value the parser handed over that none of the row's arms is about
84
+ * (a NaN, say), which has no reason to give and must not borrow another's.
85
+ */
86
+ function setupBasisSays(rule: PhysicsPoseRule, poseValue: number): string {
87
+ const arm = physicsBasisFor(rule, poseValue);
88
+ return arm === undefined ? physicsOutsideSays(rule, poseValue) : physicsBasisSays(arm);
89
+ }
90
+
91
+ // Every failure mode here is silent. The five component fields default to
92
+ // 0, so a constraint can drive nothing at all; `mix` 0 mutes it; `mass` 0
93
+ // becomes an infinite massInverse; and `damping` above 1 never settles, which
94
+ // on a mesh-driving bone means the canvas re-rasterises forever. 1 itself is
95
+ // inside the bound since issue #794: it never decays, which is finite and a
96
+ // choice, and what it costs a consumer's frame is the consumer's to judge.
97
+ //
98
+ // 🔑 **Two arms, one criterion.** The second arm below reads every physics
99
+ // TIMELINE key, and it is written against `PHYSICS_POSE_RULES` — the table
100
+ // this one is also written against, and the table `compileValueTrack`
101
+ // refuses a spec's own out-of-range number with. Three readings of one rule
102
+ // is how two of them come to disagree, so there is one (issue #610).
103
+ export function a23PhysicsConstraintEffective({ fail, skip, stats }: Verdicts, facts: ConstraintFacts, meshFacts: MeshFacts): void {
104
+ // ⟨subject⟩_⟨property⟩, and its two siblings already read this way: A36
105
+ // skips on "the skeleton declares no path constraint" and A37 on "no
106
+ // slider constraint", while this one passed over an empty filter (#580).
107
+ // The stat is written before the guard so a reader of a SKIP still sees
108
+ // the count that produced it.
109
+ stats.physicsConstraints = facts.constraints.filter((c) => c.physics !== undefined).length;
110
+ if (stats.physicsConstraints === 0) return skip('A23_PHYSICS_CONSTRAINT_EFFECTIVE', SKIP_NO_PHYSICS_CONSTRAINT);
111
+ const meshBoneNames = new Set<string>();
112
+ for (const mesh of meshFacts.meshes) meshBoneNames.add(mesh.slotBone);
113
+ for (const mesh of meshFacts.meshes) {
114
+ if (!mesh.weights) continue;
115
+ for (const vertex of mesh.weights) {
116
+ for (const { bone: index } of vertex) {
117
+ const bone = meshFacts.bones[index];
118
+ if (bone !== undefined) meshBoneNames.add(bone);
119
+ }
120
+ }
121
+ }
122
+ // --- which constraints an animation switches ON (issue #743) ----------
123
+ //
124
+ // 🔑 The setup pose is the rig AT REST, and one of the four bounds is a
125
+ // state rather than a break there: `PHYSICS_POSE_RULES` marks `mix`
126
+ // `inertAtSetup`, because `update` opens with `if (mix === 0) return;`
127
+ // (`PhysicsConstraint.js:109-111`) and nothing else in the pose has such a
128
+ // branch. So a constraint that rests muted and is keyed above 0 by an
129
+ // animation is a rig the runtime plays as authored, and refusing it would
130
+ // refuse a design: physics off at rest, switched on by the animation that
131
+ // needs it.
132
+ //
133
+ // 📏 Measured on a generated physics fixture, 36 steps at 60 fps with the
134
+ // constraint's own bone swung by its parent: resting at `mix` 0 with an
135
+ // animation keying `mix` to 1 poses the bone IDENTICALLY to the same rig
136
+ // resting at 1 (max |dx| 0.000000) and up to 7.771177 away from the twin
137
+ // that keys nothing — which poses identically to one keyed to 0 only
138
+ // (max |dx| 0.000000). Two states, and the file says which.
139
+ //
140
+ // ⚠️ The escape is the rule's own field rather than the word "mix": a
141
+ // setup `mass` of 0 is `massInverse` Infinity BEFORE anything plays, and
142
+ // [measured] at rest it reads NaN on every frame although an animation
143
+ // keys `mass` to 1. A key cannot rescue a value that has already broken
144
+ // the rig it is resting in.
145
+ //
146
+ // The keys are read by `switchedOn`, the one reading A36 and A37 share
147
+ // (issue #752), through the runtime's own accessor: the pose field is
148
+ // where the integrator reads the number, and for `mass` that is not the
149
+ // number the key states. It counts the unnamed global form through the
150
+ // timeline's reach and a Bezier segment's samples as well as its keys.
151
+ const unmuted = new Map<number, Set<string>>();
152
+ for (const rule of PHYSICS_POSE_RULES) {
153
+ if (!rule.inertAtSetup) continue;
154
+ const reached = switchedOn(
155
+ facts,
156
+ (timeline) => timeline.kind === 'physics' && timeline.word === rule.timeline,
157
+ 1,
158
+ (timeline, value) => rule.poseOk(timeline.posed === undefined ? value : timeline.posed(value)),
159
+ );
160
+ facts.constraints.forEach((one, index) => {
161
+ if (one.physics === undefined || !reached.has(index)) return;
162
+ const by = unmuted.get(index) ?? new Set<string>();
163
+ by.add(rule.timeline);
164
+ unmuted.set(index, by);
165
+ });
166
+ }
167
+ let mutedUntilKeyed = 0;
168
+ facts.constraints.forEach((constraint, index) => {
169
+ const physics = constraint.physics;
170
+ if (physics === undefined) return;
171
+ const where = `physics "${constraint.name}"`;
172
+ const components = PHYSICS_COMPONENTS.filter((k) => physics.components[k] > 0);
173
+ if (!components.length) {
174
+ fail('A23_PHYSICS_CONSTRAINT_EFFECTIVE', `${where} drives no component; it parses and does nothing`);
175
+ }
176
+ const pose = physics.setup;
177
+ // The four bounded fields, each judged by its `PHYSICS_POSE_RULES` row.
178
+ // The wording is per-field and stays so: "it is muted" and "nothing
179
+ // pulls it back" say what happens to THIS rig, which is what the author
180
+ // needs, and the shared table supplies the predicate rather than the
181
+ // sentence.
182
+ for (const rule of PHYSICS_POSE_RULES) {
183
+ if (rule.poseOk(pose[rule.field])) continue;
184
+ if (rule.inertAtSetup && unmuted.get(index)?.has(rule.timeline)) {
185
+ mutedUntilKeyed++;
186
+ continue;
187
+ }
188
+ const drivesAMesh = rule.timeline === 'damping' && meshBoneNames.has(physics.bone);
189
+ fail(
190
+ 'A23_PHYSICS_CONSTRAINT_EFFECTIVE',
191
+ `${where} ${SETUP_POSE_SAYS[rule.timeline](pose, facts.animations, rule)}` +
192
+ (drivesAMesh ? ' — and this bone drives a mesh, so the canvas never rests' : ''),
193
+ );
194
+ }
195
+ if (physics.step <= 0 || !Number.isFinite(physics.step)) {
196
+ fail('A23_PHYSICS_CONSTRAINT_EFFECTIVE', `${where} has step ${physics.step} (fps must be > 0)`);
197
+ }
198
+ });
199
+ // What the PASS would otherwise not say: this rig rests with physics off
200
+ // on that many constraints and an animation is what switches them on. A
201
+ // pass carries no detail — `passed` is a list of names — so `stats` is the
202
+ // channel that exists, and a number is what belongs in a line printed as
203
+ // `k=v`: naming every such constraint and the animations that reach it
204
+ // would be a paragraph on one line, and the rig where nobody meant it is
205
+ // the rig where the NUMBER is the surprise. Absent rather than 0 when
206
+ // nothing rests muted, so it appears only where it says something.
207
+ if (mutedUntilKeyed) stats.physicsMutedUntilKeyed = mutedUntilKeyed;
208
+
209
+ // --- the same criterion, on every physics timeline key (issue #610) ----
210
+ //
211
+ // The arm above reads the setup pose and, until this one existed, nothing
212
+ // else — complete while a motion spec could key `mix` and `reset` only,
213
+ // and incomplete from #593 on, when it became able to key all seven.
214
+ //
215
+ // 📏 Measured on the tree before this landed, one keyed value at a time on
216
+ // a generated physics rig, 24 steps at 60 fps: `mass: 0` reached
217
+ // `massInverse` Infinity and every offset NaN — named by
218
+ // `A10_NO_NAN_AFTER_STEPPING`, from the BONE, with no word about the
219
+ // animation, the constraint, the timeline or the key; `damping: 2` ran the
220
+ // x offset to −26,634 and the velocity to −1.55e6 and still climbing, with
221
+ // **zero** gate failures; `strength: 0` drifted monotonically with zero gate
222
+ // failures; `mix: 1.5` produced zero gate failures and an integration
223
+ // identical to `mix: 1`, because mix multiplies the finished offset onto
224
+ // the bone and never enters the solve.
225
+ //
226
+ // ⭐ The value is judged where the runtime keeps it, not where the file
227
+ // writes it: `posed` is the number the runtime's own accessor writes, so a
228
+ // `mass` key lands as its reciprocal and is then held to exactly the
229
+ // predicate the setup arm holds `massInverse` to.
230
+ let keysRead = 0;
231
+ for (const timeline of facts.timelines) {
232
+ // A `reset` timeline keys no value, and was never one of the seven the pose holds.
233
+ if (timeline.kind !== 'physics' || timeline.word === 'reset') continue;
234
+ const name = timeline.word;
235
+ const rule = physicsRuleFor(name);
236
+ // -1 is the global form: the timeline drives every physics constraint
237
+ // whose matching `…Global` flag is set, so there is no one name to give.
238
+ const target =
239
+ timeline.constraint === -1
240
+ ? 'every physics constraint'
241
+ : `physics "${facts.constraints[timeline.constraint]?.name ?? `#${timeline.constraint}`}"`;
242
+ for (const frame of timeline.frames) {
243
+ keysRead++;
244
+ if (rule === undefined) continue;
245
+ const value = frame.value;
246
+ const refusal = physicsKeyRefusal(rule, value, timeline.posed === undefined ? undefined : timeline.posed(value));
247
+ if (refusal === null) continue;
248
+ fail(
249
+ 'A23_PHYSICS_CONSTRAINT_EFFECTIVE',
250
+ `animation "${timeline.animation}" ${target} ${name} key at t=${frame.time.toFixed(6)}s is ${refusal}`,
251
+ );
252
+ }
253
+ }
254
+ stats.physicsTimelineKeys = keysRead;
255
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * A27, the body (issue #1025, step 4c of #380): the only region on a page is
3
+ * named for the page's file.
4
+ *
5
+ * Moved out of `src/validate.ts` unchanged but for what it reads: the regions
6
+ * are a fact (`../facts/atlas_regions.ts`). Why the second link of the
7
+ * attachment -> region -> file chain needs holding stays above the `check`
8
+ * call in `validate()`.
9
+ */
10
+ import { basename } from 'node:path';
11
+ import type { Verdicts } from '../harness.ts';
12
+ import type { AtlasRegionFacts } from '../facts/atlas_regions.ts';
13
+ import { SKIP_NO_ATLAS, SKIP_NO_ATLAS_REGION } from '../reasons.ts';
14
+
15
+ export function a27RegionNameMatchesPageFilename({ fail, skip }: Verdicts, { atlas }: AtlasRegionFacts): void {
16
+ if (!atlas) return skip('A27_REGION_NAME_MATCHES_PAGE_FILENAME', SKIP_NO_ATLAS);
17
+ if (atlas.regions.length === 0) return skip('A27_REGION_NAME_MATCHES_PAGE_FILENAME', SKIP_NO_ATLAS_REGION);
18
+ const perPage = new Map<string, number>();
19
+ for (const region of atlas.regions) perPage.set(region.page.name, (perPage.get(region.page.name) ?? 0) + 1);
20
+ for (const region of atlas.regions) {
21
+ // A real packer puts many regions on one page and the names stop matching
22
+ // filenames by design. Then this check has nothing to say, so it says
23
+ // nothing rather than something wrong.
24
+ if ((perPage.get(region.page.name) ?? 0) !== 1) continue;
25
+ const expected = basename(region.page.name).replace(/\.png$/i, '');
26
+ if (region.name !== expected) {
27
+ fail(
28
+ 'A27_REGION_NAME_MATCHES_PAGE_FILENAME',
29
+ `region "${region.name}" is the only region on page "${region.page.name}", whose basename is "${expected}"`,
30
+ );
31
+ }
32
+ }
33
+ }