spine-rigc 1.9.0 → 1.9.1
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.
- package/cli.ts +9 -0
- package/docs/AUTHORING.md +2 -2
- package/package.json +1 -1
- package/src/assertions/bodies/a09.ts +82 -0
- package/src/assertions/bodies/a12.ts +30 -0
- package/src/assertions/bodies/a24.ts +68 -0
- package/src/assertions/bodies/a25.ts +39 -0
- package/src/assertions/bodies/a26.ts +61 -0
- package/src/assertions/bodies/a29.ts +34 -0
- package/src/assertions/bodies/a30.ts +50 -0
- package/src/assertions/bodies/a32.ts +44 -0
- package/src/assertions/bodies/a39.ts +303 -0
- package/src/assertions/bodies/a43.ts +181 -0
- package/src/assertions/bodies/a46.ts +224 -0
- package/src/assertions/facts/animation_durations.ts +37 -0
- package/src/assertions/facts/bone_timelines.ts +37 -0
- package/src/assertions/facts/deform_survey.ts +27 -0
- package/src/assertions/facts/event_keys.ts +55 -0
- package/src/assertions/facts/sequences.ts +85 -0
- package/src/assertions/facts/skeleton_roster.ts +45 -0
- package/src/assertions/facts/two_colour.ts +52 -0
- package/src/assertions/inward_advance.ts +58 -0
- package/src/assertions/model/animation_durations.ts +57 -0
- package/src/assertions/model/bone_timelines.ts +56 -0
- package/src/assertions/model/constraints.ts +34 -16
- package/src/assertions/model/deform_survey.ts +24 -0
- package/src/assertions/model/event_keys.ts +45 -0
- package/src/assertions/model/index.ts +64 -2
- package/src/assertions/model/linked_meshes.ts +2 -2
- package/src/assertions/model/mesh_attachments.ts +1 -1
- package/src/assertions/model/region_joins.ts +20 -12
- package/src/assertions/model/sequences.ts +157 -0
- package/src/assertions/model/skeleton_roster.ts +23 -0
- package/src/assertions/model/skin_entries.ts +18 -8
- package/src/assertions/model/skin_members.ts +5 -3
- package/src/assertions/model/skin_meshes.ts +1 -1
- package/src/assertions/model/slot_colour.ts +5 -4
- package/src/assertions/model/two_colour.ts +61 -0
- package/src/assertions/model/vertex_polygons.ts +9 -8
- package/src/compile.ts +114 -14
- package/src/deformmeasure.ts +35 -2270
- package/src/deformstructure.ts +60 -18
- package/src/deformsurvey.ts +2295 -0
- package/src/render.ts +80 -4
- package/src/validate.ts +361 -1103
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A46, the body (issue #1025, cut 4c-3 of step 4c of #380): a numbered series
|
|
3
|
+
* shows the frame the file states.
|
|
4
|
+
*
|
|
5
|
+
* Moved out of `src/validate.ts` unchanged but for what it reads, which is
|
|
6
|
+
* `SequenceFacts` (`../facts/sequences.ts`) where it read the skeleton JSON and
|
|
7
|
+
* the loaded skeleton — and for one change of key: what it knew about an
|
|
8
|
+
* attachment it used to file under the loaded attachment OBJECT, and now files
|
|
9
|
+
* under the entry's address (skin, slot, placeholder), the one key both sides
|
|
10
|
+
* hold. The runtime's side loads one object per address, so every map below
|
|
11
|
+
* holds what it held. The argument for the rule is above its `check` call,
|
|
12
|
+
* which stays in `validate()`.
|
|
13
|
+
*/
|
|
14
|
+
import type { Verdicts } from '../harness.ts';
|
|
15
|
+
import { entryAddress, type EntryAddress, type SequenceFacts } from '../facts/sequences.ts';
|
|
16
|
+
import { attachmentRegionLookups } from '../region_lookups.ts';
|
|
17
|
+
import { SKIP_NO_SEQUENCE } from '../reasons.ts';
|
|
18
|
+
import { atStoredKey, isObj } from '../values.ts';
|
|
19
|
+
import { SEQUENCE_MODES } from '../../timelines.ts';
|
|
20
|
+
|
|
21
|
+
export function a46SequenceAttachmentsShowTheFrameTheFileStates({ fail, skip, stats }: Verdicts, facts: SequenceFacts): void {
|
|
22
|
+
const NAME = 'A46_SEQUENCE_ATTACHMENTS_SHOW_THE_FRAME_THE_FILE_STATES';
|
|
23
|
+
type Series = { where: string; lookups: string[] | null; count: number; setup: number };
|
|
24
|
+
/** The loaded attachment's address -> what the FILE says its series is. */
|
|
25
|
+
const series = new Map<EntryAddress, Series>();
|
|
26
|
+
/** The addresses the runtime loaded an attachment at, for the timelines to find. */
|
|
27
|
+
const loadedAt = new Set<EntryAddress>();
|
|
28
|
+
/** Attachments whose block was already refused above — their timelines say nothing more. */
|
|
29
|
+
const refused = new Set<EntryAddress>();
|
|
30
|
+
const whole = (v: unknown, fallback: number): number | null =>
|
|
31
|
+
v === undefined ? fallback : typeof v === 'number' && Number.isInteger(v) ? v : null;
|
|
32
|
+
let blocks = 0;
|
|
33
|
+
for (const entry of facts.entries) {
|
|
34
|
+
const at = entryAddress(entry.skin, entry.slot, entry.placeholder);
|
|
35
|
+
const loaded = entry.loaded;
|
|
36
|
+
const where = `skin ${JSON.stringify(entry.skin)} slot ${JSON.stringify(entry.slot)} attachment ${JSON.stringify(entry.placeholder)}`;
|
|
37
|
+
if (loaded) loadedAt.add(at);
|
|
38
|
+
if (entry.sequence === undefined || entry.sequence === null) continue;
|
|
39
|
+
blocks++;
|
|
40
|
+
const seq = entry.sequence;
|
|
41
|
+
const name = typeof entry.name === 'string' ? entry.name : entry.placeholder;
|
|
42
|
+
const path = typeof entry.path === 'string' ? entry.path : name;
|
|
43
|
+
const count = isObj(seq) ? whole(seq.count, 0) : null;
|
|
44
|
+
const setup = isObj(seq) ? whole(seq.setup, 0) : null;
|
|
45
|
+
if ((count === null || setup === null || count < 1) && loaded) refused.add(at);
|
|
46
|
+
if (count === null || setup === null || count < 1) {
|
|
47
|
+
fail(
|
|
48
|
+
NAME,
|
|
49
|
+
`${where}: the sequence states ${JSON.stringify(seq)}` +
|
|
50
|
+
(isObj(seq) && seq.count === undefined
|
|
51
|
+
? ' and no "count" — `readSequence` reads 0 (`SkeletonJson.js:644`), so the attachment loads holding no region and draws nothing'
|
|
52
|
+
: ' — "count" is a whole number of at least 1 and "setup" a whole number, or the series the parser builds is not the one written'),
|
|
53
|
+
);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if ((setup < 0 || setup >= count) && loaded) refused.add(at);
|
|
57
|
+
if (setup < 0 || setup >= count) {
|
|
58
|
+
fail(
|
|
59
|
+
NAME,
|
|
60
|
+
`${where}: the sequence's setup frame is ${setup} of a ${count}-frame series (frames 0 to ${count - 1}); ` +
|
|
61
|
+
'`Sequence.resolveIndex` clamps it, so the setup pose shows ' +
|
|
62
|
+
`${setup < 0 ? 'no frame at all' : `frame ${count - 1}, which the file does not name`}`,
|
|
63
|
+
);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!loaded) continue; // A00/A08 own an attachment that did not load
|
|
67
|
+
series.set(at, { where, lookups: attachmentRegionLookups(seq, path), count, setup });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The frame the file's statement gives for one key at one elapsed time —
|
|
72
|
+
* A46's prediction, not a call into the runtime. What holds it is the
|
|
73
|
+
* comparison it feeds: every sample sets it against the frame the posed
|
|
74
|
+
* slot shows, so a reading that disagreed with the runtime would fail A46
|
|
75
|
+
* on a correct file. A46 passing with samples posed on the selftest's
|
|
76
|
+
* series probes is that measurement for the modes they key; `M73` is its
|
|
77
|
+
* red half.
|
|
78
|
+
*/
|
|
79
|
+
const frameOf = (mode: string, index: number, elapsed: number, delay: number, count: number): number => {
|
|
80
|
+
if (mode === 'hold') return index;
|
|
81
|
+
let i = index + Math.trunc(elapsed / delay + 0.00001);
|
|
82
|
+
const n = count * 2 - 2;
|
|
83
|
+
switch (mode) {
|
|
84
|
+
case 'once':
|
|
85
|
+
return Math.min(count - 1, i);
|
|
86
|
+
case 'loop':
|
|
87
|
+
return i % count;
|
|
88
|
+
case 'pingpong':
|
|
89
|
+
i = n === 0 ? 0 : i % n;
|
|
90
|
+
return i >= count ? n - i : i;
|
|
91
|
+
case 'onceReverse':
|
|
92
|
+
return Math.max(count - 1 - i, 0);
|
|
93
|
+
case 'loopReverse':
|
|
94
|
+
return count - 1 - (i % count);
|
|
95
|
+
default: // pingpongReverse
|
|
96
|
+
i = n === 0 ? 0 : (i + count - 1) % n;
|
|
97
|
+
return i >= count ? n - i : i;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
let timelines = 0;
|
|
102
|
+
let compared = 0;
|
|
103
|
+
let unshown = 0;
|
|
104
|
+
for (const { animation: animName, skin: skinName, slot: slotName, placeholder, keys } of facts.timelines) {
|
|
105
|
+
if (keys.length === 0) continue; // `readAnimation` skips it; A34 owns an empty timeline
|
|
106
|
+
timelines++;
|
|
107
|
+
const where = `animation ${JSON.stringify(animName)} ${skinName}/${slotName}/${placeholder} sequence`;
|
|
108
|
+
const keyed = entryAddress(skinName, slotName, placeholder);
|
|
109
|
+
if (!loadedAt.has(keyed)) continue; // the parser throws on a missing target: A00's
|
|
110
|
+
if (refused.has(keyed)) continue; // its block is already named above
|
|
111
|
+
const own = series.get(keyed);
|
|
112
|
+
if (own === undefined) {
|
|
113
|
+
fail(
|
|
114
|
+
NAME,
|
|
115
|
+
`${where}: the timeline steps an attachment that carries no "sequence" block. The parser gives it a ` +
|
|
116
|
+
'series of ONE region (`readSequence(null)` is `new Sequence(1, false)`), so every mode shows that ' +
|
|
117
|
+
'region at every time — measured: a "loop" key on a plain region showed it throughout',
|
|
118
|
+
);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// -- the keys, as the file states them --------------------------
|
|
122
|
+
type Key = { time: number; mode: string; index: number; delay: number };
|
|
123
|
+
const read: Key[] = [];
|
|
124
|
+
let carried = 0;
|
|
125
|
+
let malformed = false;
|
|
126
|
+
keys.forEach((rawKey, k) => {
|
|
127
|
+
const key = isObj(rawKey) ? rawKey : {};
|
|
128
|
+
const at = `${where} key ${k}`;
|
|
129
|
+
const time = typeof key.time === 'number' ? key.time : 0;
|
|
130
|
+
const mode = key.mode === undefined ? 'hold' : key.mode;
|
|
131
|
+
const index = key.index === undefined ? 0 : key.index;
|
|
132
|
+
if (key.delay !== undefined) carried = typeof key.delay === 'number' ? key.delay : Number.NaN;
|
|
133
|
+
if (typeof mode !== 'string' || !(SEQUENCE_MODES as readonly string[]).includes(mode)) {
|
|
134
|
+
malformed = true;
|
|
135
|
+
fail(
|
|
136
|
+
NAME,
|
|
137
|
+
`${at} (t=${time}): mode ${JSON.stringify(key.mode)} is not one of the ${SEQUENCE_MODES.length} the ` +
|
|
138
|
+
`format has (${SEQUENCE_MODES.join(', ')}); the parser reads \`SequenceMode[mode]\`, which is ` +
|
|
139
|
+
'undefined, stores mode bits 0, and the key plays as "hold"',
|
|
140
|
+
);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (typeof index !== 'number' || !Number.isInteger(index) || index < 0 || index >= own.count) {
|
|
144
|
+
malformed = true;
|
|
145
|
+
fail(
|
|
146
|
+
NAME,
|
|
147
|
+
`${at} (t=${time}): index ${JSON.stringify(key.index)} is not a frame of the ${own.count}-frame series ` +
|
|
148
|
+
`(0 to ${own.count - 1}); the runtime stores \`index << 4\`, truncating a fraction, and ` +
|
|
149
|
+
'`Sequence.resolveIndex` clamps a frame past the end to the last one',
|
|
150
|
+
);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (mode !== 'hold' && !(carried > 0)) {
|
|
154
|
+
malformed = true;
|
|
155
|
+
fail(
|
|
156
|
+
NAME,
|
|
157
|
+
`${at} (t=${time}): "${mode}" at a delay of ${String(carried)}${key.delay === undefined ? ' (carried from the key before, 0 on the first)' : ''} — ` +
|
|
158
|
+
'the frame advances by `(time - keyTime) / delay`, and at 0 that is Infinity, `Infinity | 0` is 0, ' +
|
|
159
|
+
'and the key shows its first frame throughout: "hold" spelt as another mode',
|
|
160
|
+
);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
read.push({ time, mode, index, delay: carried });
|
|
164
|
+
});
|
|
165
|
+
if (malformed) continue;
|
|
166
|
+
|
|
167
|
+
// -- the pose, sampled ------------------------------------------
|
|
168
|
+
const end = facts.duration(animName);
|
|
169
|
+
if (end === null || !facts.hasSlot(slotName)) continue; // A00's
|
|
170
|
+
/** `key` is the index into `read`, or -1 before the first key (the setup frame). */
|
|
171
|
+
const samples: Array<{ time: number; key: number; steps: number }> = [];
|
|
172
|
+
if (read[0].time > 0) samples.push({ time: read[0].time / 2, key: -1, steps: 0 });
|
|
173
|
+
read.forEach((key, k) => {
|
|
174
|
+
const until = k + 1 < read.length ? read[k + 1].time : end;
|
|
175
|
+
if (key.mode === 'hold') {
|
|
176
|
+
samples.push({ time: key.time, key: k, steps: 0 });
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// Mid-frame, and enough steps to wrap every mode at least once.
|
|
180
|
+
for (let step = 0; step < own.count * 2 + 2; step++) {
|
|
181
|
+
const time = key.time + (step + 0.5) * key.delay;
|
|
182
|
+
if (time >= until || time > end) break;
|
|
183
|
+
samples.push({ time, key: k, steps: step + 0.5 });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
let shownHere = 0;
|
|
187
|
+
for (const sample of samples) {
|
|
188
|
+
// A `hold` sample is AT its key, so it is posed at the key as
|
|
189
|
+
// the runtime stores it (`atStoredKey`); a mid-frame sample is
|
|
190
|
+
// half a delay from any key and is posed where it is.
|
|
191
|
+
const pose = facts.posedFrame(animName, slotName, sample.key >= 0 && sample.steps === 0 ? atStoredKey(sample.time) : sample.time);
|
|
192
|
+
// The slot must show the keyed attachment or one playing its
|
|
193
|
+
// timelines — the only case `applyToSlot` writes.
|
|
194
|
+
if (pose === null || (pose.shown !== keyed && pose.playsAs !== keyed)) continue;
|
|
195
|
+
const drawn = series.get(pose.shown);
|
|
196
|
+
if (drawn === undefined || drawn.lookups === null) continue;
|
|
197
|
+
shownHere++;
|
|
198
|
+
compared++;
|
|
199
|
+
// The frame count the runtime folds by is the SHOWN attachment's:
|
|
200
|
+
// a link with a series of its own steps it by its source's keys.
|
|
201
|
+
const key = sample.key < 0 ? null : read[sample.key];
|
|
202
|
+
const want = key === null ? drawn.setup : frameOf(key.mode, key.index, sample.time - key.time, key.delay, drawn.count);
|
|
203
|
+
const region = pose.region;
|
|
204
|
+
if (region !== drawn.lookups[want]) {
|
|
205
|
+
fail(
|
|
206
|
+
NAME,
|
|
207
|
+
`${where} (t=${Number(sample.time.toFixed(4))}): the slot shows region ${JSON.stringify(region)}, and ` +
|
|
208
|
+
`the file states frame ${want} of ${drawn.count} — ${JSON.stringify(drawn.lookups[want])} — ` +
|
|
209
|
+
(key === null
|
|
210
|
+
? 'the setup frame, before the first key'
|
|
211
|
+
: `key ${sample.key} plays "${key.mode}" from frame ${key.index} every ${key.delay}s, ` +
|
|
212
|
+
`${sample.steps} delay(s) in`),
|
|
213
|
+
);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (shownHere === 0) unshown++;
|
|
218
|
+
}
|
|
219
|
+
if (blocks === 0 && timelines === 0) return skip(NAME, SKIP_NO_SEQUENCE);
|
|
220
|
+
stats.sequenceBlocks = blocks;
|
|
221
|
+
stats.sequenceTimelines = timelines;
|
|
222
|
+
stats.sequenceSamples = compared;
|
|
223
|
+
if (unshown > 0) stats.sequenceSamplesUnshown = unshown;
|
|
224
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The animations and how long each one runs (issue #1025, cut 4c-3 of step
|
|
3
|
+
* 4c of #380) — the census's F18 and F19 as A09 reads them: the animation
|
|
4
|
+
* roster in the file's order, each animation's duration as the runtime holds
|
|
5
|
+
* it, and each of its timelines' own duration.
|
|
6
|
+
*
|
|
7
|
+
* ⭐ **The runtime's durations, not the stated ones.** An animation's duration
|
|
8
|
+
* is the last key of every timeline it carries, as float32 — the number
|
|
9
|
+
* `SkeletonJson` computes and stores, which is what A09 holds against the
|
|
10
|
+
* declared duration — and a timeline's own duration is its last key, as
|
|
11
|
+
* float32 (`Timeline.getDuration`). A09 counts the timelines keyed past the
|
|
12
|
+
* declared duration in its message, so the list holds one entry per timeline
|
|
13
|
+
* the runtime builds, in no order a body may read: A09 counts them and
|
|
14
|
+
* nothing else.
|
|
15
|
+
*
|
|
16
|
+
* The order of the roster is the file's: A09's last clause prints one line per
|
|
17
|
+
* animation the spec does not declare, in it.
|
|
18
|
+
*
|
|
19
|
+
* Links nothing from the runtime: `validate()` reads it off the loaded
|
|
20
|
+
* skeleton (`spineAnimationDurations`), the model side off the document and
|
|
21
|
+
* the core (`../model/animation_durations.ts`).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** One animation, as A09 reads it. */
|
|
25
|
+
export interface AnimationDuration {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/** The runtime's duration: the last key of every timeline, float32. */
|
|
28
|
+
readonly duration: number;
|
|
29
|
+
/** Each timeline's own duration — its last key, float32 — one per timeline the runtime builds. */
|
|
30
|
+
readonly timelineDurations: readonly number[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** What A09 reads. */
|
|
34
|
+
export interface AnimationDurationFacts {
|
|
35
|
+
/** Every animation the skeleton holds, in the file's order. */
|
|
36
|
+
readonly animations: readonly AnimationDuration[];
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every animation's bone timelines, in the file's order and spelling (issue
|
|
3
|
+
* #1025, cut 4c-4 of #380) — the half of the census's F18/F19 that the stroke
|
|
4
|
+
* rules read: which bones each animation keys, with which timelines, and each
|
|
5
|
+
* key as the file states it.
|
|
6
|
+
*
|
|
7
|
+
* ⭐ **The file's order, and the file's spelling**, for the reason A45's slot
|
|
8
|
+
* timelines carry both (`./slot_colour.ts`): A24 and A30 print one line per
|
|
9
|
+
* bone and per timeline in the order the file keys them, and A24, A29 and A30
|
|
10
|
+
* print a key's `x`, `y` and `time` as the file states them. So the list holds,
|
|
11
|
+
* for every animation in the order the file keys them and every bone in the
|
|
12
|
+
* order the animation keys them, that bone's timelines — name to keys — as
|
|
13
|
+
* the file spells them. `validate()` reads it off the skeleton JSON
|
|
14
|
+
* (`rawBoneTimelines`); the model side produces it from the document by calling
|
|
15
|
+
* the emitter's own order and its parser-default and key-order passes
|
|
16
|
+
* (`../model/bone_timelines.ts`), so a key field the emitter would leave out at
|
|
17
|
+
* the parser's default is left out here too.
|
|
18
|
+
*
|
|
19
|
+
* ⚠️ `timelines` is `unknown` rather than an object because the raw JSON can
|
|
20
|
+
* hold anything there and A24 counts a keyed bone before it asks what the
|
|
21
|
+
* bone's timelines are; the document always holds an object.
|
|
22
|
+
*
|
|
23
|
+
* Links nothing from the runtime.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** One animation's timelines on one bone: timeline name -> keys, as the file states them. */
|
|
27
|
+
export interface BoneTimelines {
|
|
28
|
+
readonly animation: string;
|
|
29
|
+
readonly bone: string;
|
|
30
|
+
readonly timelines: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** What A24, A29 and A30 read. */
|
|
34
|
+
export interface BoneTimelineFacts {
|
|
35
|
+
/** Every (animation, bone) pair the file keys, in the header's order. */
|
|
36
|
+
readonly boneTimelines: readonly BoneTimelines[];
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deform survey (issue #1025, cut 4c-3 of step 4c of #380) — the
|
|
3
|
+
* census's R6 and the structure under it, as A39 reads them: every deform key
|
|
4
|
+
* of every animation measured in the frame its animation is reached in, every
|
|
5
|
+
* span between two keys scanned, and what was passed over.
|
|
6
|
+
*
|
|
7
|
+
* ⭐ **One fact, because it is one measurement.** The survey is what
|
|
8
|
+
* `explain`'s `DEFORM` block prints whole and A39 gates on, and the reason
|
|
9
|
+
* both read one survey rather than each posing for itself is that the
|
|
10
|
+
* report's reversal count and A39's are the same count
|
|
11
|
+
* (`src/deformmeasure.ts`'s header). So A39 is handed the survey, not the
|
|
12
|
+
* poses under it: `validate()` hands it spine-core's — the Spine skeleton read
|
|
13
|
+
* and posed by the runtime (`surveyDeformKeys`) — and the model side the core's
|
|
14
|
+
* — the model document's structure posed by rigc's core (`surveyOfModel`,
|
|
15
|
+
* `src/deformsurvey.ts`). `tools/survey_hashes.ts` holds the two to one survey
|
|
16
|
+
* on every corpus row, and the selftest on every call with a model in hand
|
|
17
|
+
* (`VF12`).
|
|
18
|
+
*
|
|
19
|
+
* Links nothing from the runtime.
|
|
20
|
+
*/
|
|
21
|
+
import type { DeformSurvey } from '../../deformsurvey.ts';
|
|
22
|
+
|
|
23
|
+
/** What A39 reads. */
|
|
24
|
+
export interface DeformSurveyFacts {
|
|
25
|
+
/** The survey, with the slots in `exempt` passed over unmeasured (the rig's `deformMayFold`). */
|
|
26
|
+
survey(exempt: ReadonlySet<string>): DeformSurvey;
|
|
27
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every event key, in the file's order, with the declaration it fires (issue
|
|
3
|
+
* #1025, cut 4c-4 of #380) — what A32 reads.
|
|
4
|
+
*
|
|
5
|
+
* ⭐ **Split per clause, and the split is in this interface.** A32 has five
|
|
6
|
+
* clauses. Four of them — a key with no string `name`, a key firing an event
|
|
7
|
+
* the skeleton does not declare, a key whose time is not a finite number, and
|
|
8
|
+
* a key earlier than the one before it — are states `readModel` refuses by
|
|
9
|
+
* name (`readEventKeys` in `src/core/events.ts`, measured on forged documents:
|
|
10
|
+
* each one is refused at the key's address), so no readable document reaches
|
|
11
|
+
* them and they stay with the round trip: `validate()` runs them over the
|
|
12
|
+
* skeleton JSON and hands their findings in as `kept`, in the order they
|
|
13
|
+
* print, with `stopped` where the clause ended the key's reading. The fifth —
|
|
14
|
+
* `volume` or `balance` on a key whose event declares no audio — is the rig's:
|
|
15
|
+
* the document holds the key's fields and the declaration's `audio`, and a
|
|
16
|
+
* readable document can carry it. That clause is the body's
|
|
17
|
+
* (`../bodies/a32.ts`), and the model side supplies `kept` empty.
|
|
18
|
+
*
|
|
19
|
+
* The order is the file's: animations in the order the file keys them (the
|
|
20
|
+
* emitter's `editorAnimationOrder`), and an animation's keys in the order the
|
|
21
|
+
* document lists them, which is the order the emitter writes them
|
|
22
|
+
* (`emitAnimation`'s `events`). `timelines` counts the animations carrying an
|
|
23
|
+
* event timeline at all, which is what A32 SKIPs on when it is zero.
|
|
24
|
+
*
|
|
25
|
+
* Links nothing from the runtime.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** One event key: where it is, what the kept clauses found, and what the moved clause reads. */
|
|
29
|
+
export interface EventKeyEntry {
|
|
30
|
+
readonly animation: string;
|
|
31
|
+
/** The key's index in its animation's event timeline. */
|
|
32
|
+
readonly index: number;
|
|
33
|
+
/** The findings of the clauses that stay with the round trip, in the order they print — always empty on the model side. */
|
|
34
|
+
readonly kept: readonly string[];
|
|
35
|
+
/** Whether a kept clause ended the key's reading, so the moved clause does not run on it. */
|
|
36
|
+
readonly stopped: boolean;
|
|
37
|
+
/** The event the key fires. */
|
|
38
|
+
readonly name: string;
|
|
39
|
+
/** Which of the two audio fields the key states. */
|
|
40
|
+
readonly sets: { readonly volume: boolean; readonly balance: boolean };
|
|
41
|
+
/** Whether the event the key fires declares an audio path (a string). */
|
|
42
|
+
readonly audio: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What A32 reads. */
|
|
46
|
+
export interface EventKeyFacts {
|
|
47
|
+
/** Whether the skeleton JSON parsed — always true on the model side, whose parse is the reader's. */
|
|
48
|
+
readonly parsed: boolean;
|
|
49
|
+
/** Whether the skeleton declares an `animations` object at all. */
|
|
50
|
+
readonly animations: boolean;
|
|
51
|
+
/** How many animations carry an event timeline. */
|
|
52
|
+
readonly timelines: number;
|
|
53
|
+
/** Every event key, in the file's order. */
|
|
54
|
+
readonly keys: readonly EventKeyEntry[];
|
|
55
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numbered series and the frame a slot shows (issue #1025, cut 4c-3 of step
|
|
3
|
+
* 4c of #380) — the census's F02, F03, F18 and R4 as A46 reads them: every
|
|
4
|
+
* skin entry that draws a region, as the file states it and whether the
|
|
5
|
+
* runtime loaded it; every sequence timeline, as the file states it; an
|
|
6
|
+
* animation's duration; and what a slot shows at a time.
|
|
7
|
+
*
|
|
8
|
+
* ⭐ **Attachments by address, never by object.** A46 used to key what it knew
|
|
9
|
+
* by the loaded attachment object and to ask whether the slot shows "the keyed
|
|
10
|
+
* attachment or one playing its timelines" by identity. An object is the
|
|
11
|
+
* runtime's; an address — `skin`, `slot`, `placeholder`, the triple the file
|
|
12
|
+
* files an entry under and a timeline names it by — is the file's, and on the
|
|
13
|
+
* runtime's side each loaded entry is exactly one object (one per skin, slot
|
|
14
|
+
* and placeholder, which `Skin.getAttachment` is keyed by). So `posedFrame`
|
|
15
|
+
* answers with addresses: the entry the slot shows, and the entry whose
|
|
16
|
+
* timelines it plays (itself, or a linked mesh's source when the link plays
|
|
17
|
+
* its source's timelines).
|
|
18
|
+
*
|
|
19
|
+
* ⭐ **The file's order and spelling where A46 walks and prints**: the skins in
|
|
20
|
+
* the file's order, a skin's slot keys and a slot's placeholders in it; every
|
|
21
|
+
* `sequence` block and key as the file spells it, since A46 parses them itself
|
|
22
|
+
* and prints what it found.
|
|
23
|
+
*
|
|
24
|
+
* Links nothing from the runtime: `validate()` reads it off the skeleton JSON
|
|
25
|
+
* and the loaded skeleton (`spineSequenceFacts`), the model side off the
|
|
26
|
+
* document and the core (`../model/sequences.ts`).
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** A skin entry's address: `skin`, `slot`, `placeholder`, joined by NULs. */
|
|
30
|
+
export type EntryAddress = string;
|
|
31
|
+
|
|
32
|
+
/** The address of one skin entry. */
|
|
33
|
+
export function entryAddress(skin: string, slot: string, placeholder: string): EntryAddress {
|
|
34
|
+
return `${skin}\u0000${slot}\u0000${placeholder}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** One skin entry that draws a region — a region, a mesh or a linked mesh. */
|
|
38
|
+
export interface SequenceSkinEntry {
|
|
39
|
+
readonly skin: string;
|
|
40
|
+
readonly slot: string;
|
|
41
|
+
readonly placeholder: string;
|
|
42
|
+
/** The entry's `name`, `path` and `sequence` as the file spells them (`undefined` where it states none). */
|
|
43
|
+
readonly name: unknown;
|
|
44
|
+
readonly path: unknown;
|
|
45
|
+
readonly sequence: unknown;
|
|
46
|
+
/** Whether the runtime loaded an attachment for the entry: its slot exists and the skin holds it. */
|
|
47
|
+
readonly loaded: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One sequence timeline — an attachment's `sequence` that the file states as a list — the address it keys, and its keys as the file spells them. */
|
|
51
|
+
export interface SequenceTimeline {
|
|
52
|
+
readonly animation: string;
|
|
53
|
+
readonly skin: string;
|
|
54
|
+
readonly slot: string;
|
|
55
|
+
readonly placeholder: string;
|
|
56
|
+
readonly keys: readonly unknown[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What a slot shows at one pose. */
|
|
60
|
+
export interface PosedSequence {
|
|
61
|
+
/** The entry the slot shows. */
|
|
62
|
+
readonly shown: EntryAddress;
|
|
63
|
+
/** The entry whose timelines it plays: itself, or the source of a linked mesh that plays its source's. */
|
|
64
|
+
readonly playsAs: EntryAddress;
|
|
65
|
+
/** The atlas region the shown entry's series resolves to at this pose, or `null` for none. */
|
|
66
|
+
readonly region: string | null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** What A46 reads. */
|
|
70
|
+
export interface SequenceFacts {
|
|
71
|
+
/** Every skin entry of a region, mesh or linked mesh, in the file's order: skins, then each skin's slot keys, then a slot's placeholders. */
|
|
72
|
+
readonly entries: readonly SequenceSkinEntry[];
|
|
73
|
+
/** Every animation's sequence timelines, in the file's order: animations, then skins, slots and placeholders as the animation keys them. */
|
|
74
|
+
readonly timelines: readonly SequenceTimeline[];
|
|
75
|
+
/** Whether the skeleton has a slot of this name. */
|
|
76
|
+
hasSlot(slot: string): boolean;
|
|
77
|
+
/** The runtime's duration of an animation, or `null` for no animation of that name. */
|
|
78
|
+
duration(animation: string): number | null;
|
|
79
|
+
/**
|
|
80
|
+
* What the slot shows with the animation applied at `time` on a fresh,
|
|
81
|
+
* non-looping track from the setup pose, no skin set — `null` when it
|
|
82
|
+
* shows nothing.
|
|
83
|
+
*/
|
|
84
|
+
posedFrame(animation: string, slot: string, time: number): PosedSequence | null;
|
|
85
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The skeleton's bones and slots as the file lists them (issue #1025, cut 4c-4
|
|
3
|
+
* of #380) — the census's F01 and F02, the halves of them that A12, A25 and
|
|
4
|
+
* A26 read: each bone's name and its parent's, and each slot's name and
|
|
5
|
+
* whether it declares a dark colour, in the file's order.
|
|
6
|
+
*
|
|
7
|
+
* ⭐ **The order is a value.** The slots array IS the draw order, and A26
|
|
8
|
+
* holds it to the rig's table index for index; A12 prints one line per dark
|
|
9
|
+
* slot in that order. The emitter writes both arrays in the model's own order
|
|
10
|
+
* and never re-sorts them (`emitBones`, `emitSlots` in `src/emit_spine.ts`), so
|
|
11
|
+
* the document's lists are the file's.
|
|
12
|
+
*
|
|
13
|
+
* ⚠️ **Read as the bodies always read the raw JSON.** A slot is any object in
|
|
14
|
+
* the array, its name `String(name)` (a slot with no string name reads
|
|
15
|
+
* `"undefined"`, as it always printed) and `dark` whether the key is present at
|
|
16
|
+
* all; a bone is an object whose name is a string, its parent the string the
|
|
17
|
+
* file states or `null`. `validate()` reads them off the skeleton JSON
|
|
18
|
+
* (`rawSkeletonRoster`), which it parses before the round trip, so a file the
|
|
19
|
+
* loader refuses is still read; the model side reads them off the document
|
|
20
|
+
* (`../model/skeleton_roster.ts`).
|
|
21
|
+
*
|
|
22
|
+
* Links nothing from the runtime.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** A bone as the rules over parentage read it. */
|
|
26
|
+
export interface RosterBone {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
/** The parent's name, or `null` for a root (or a parent the file does not spell as a string). */
|
|
29
|
+
readonly parent: string | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A slot as the rules over the draw order and the dark colour read it. */
|
|
33
|
+
export interface RosterSlot {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/** Whether the slot declares a dark colour — the key's presence, which is all A12 asks. */
|
|
36
|
+
readonly dark: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What A12, A25 and A26 read of the skeleton's arrays. */
|
|
40
|
+
export interface SkeletonRosterFacts {
|
|
41
|
+
/** The bones, in the file's order. */
|
|
42
|
+
readonly bones: readonly RosterBone[];
|
|
43
|
+
/** The slots, in the file's order — the draw order. */
|
|
44
|
+
readonly slots: readonly RosterSlot[];
|
|
45
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two-colour tint (issue #1025, cut 4c-3 of step 4c of #380) — the
|
|
3
|
+
* census's F02, F18, F22 and R4 as A43 reads them: the dark colour each slot
|
|
4
|
+
* states and the one the runtime loaded for it, the slot timelines the file
|
|
5
|
+
* keys, and a slot's light and dark colour posed at a time.
|
|
6
|
+
*
|
|
7
|
+
* ⭐ **The file's spelling where A43 prints it, the runtime's reading where it
|
|
8
|
+
* compares.** A43 parses the stated hex itself — a check that read the
|
|
9
|
+
* required value out of the parser it checks would agree with it whatever it
|
|
10
|
+
* did — so the stated `dark` and every key are handed over as the file spells
|
|
11
|
+
* them; the loaded and the posed colours are the values the runtime holds.
|
|
12
|
+
*
|
|
13
|
+
* The slot timelines are `SlotColourFacts`' (`./slot_colour.ts`): one walk of
|
|
14
|
+
* the file's animations, in its order and its spelling, which A45 reads too.
|
|
15
|
+
*
|
|
16
|
+
* Links nothing from the runtime: `validate()` reads it off the skeleton JSON
|
|
17
|
+
* and the loaded skeleton (`spineTwoColourFacts`), the model side off the
|
|
18
|
+
* document and the core (`../model/two_colour.ts`).
|
|
19
|
+
*/
|
|
20
|
+
import type { SlotTimelines } from './slot_colour.ts';
|
|
21
|
+
|
|
22
|
+
/** A dark colour as loaded or posed: three channels, NaN where the reading was no number. */
|
|
23
|
+
export interface DarkColour {
|
|
24
|
+
readonly r: number;
|
|
25
|
+
readonly g: number;
|
|
26
|
+
readonly b: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A slot's two colours, posed. */
|
|
30
|
+
export interface PosedTint {
|
|
31
|
+
readonly light: { readonly r: number; readonly g: number; readonly b: number; readonly a: number };
|
|
32
|
+
/** `null` where the posed slot holds no dark colour. */
|
|
33
|
+
readonly dark: DarkColour | null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What A43 reads. */
|
|
37
|
+
export interface TwoColourFacts {
|
|
38
|
+
/** Every slot whose entry states `dark` as a string, in the file's slot order, name and value as the file spells them. */
|
|
39
|
+
readonly slotDarks: ReadonlyArray<{ readonly slot: string; readonly dark: string }>;
|
|
40
|
+
/** The setup dark colour the loaded skeleton holds for the slot, or `null` for none (or no such slot). */
|
|
41
|
+
loadedDark(slot: string): DarkColour | null;
|
|
42
|
+
/** Every (animation, slot) pair whose timelines the file keys, in the file's order and spelling. */
|
|
43
|
+
readonly slotTimelines: readonly SlotTimelines[];
|
|
44
|
+
/** Whether the skeleton holds an animation of this name. */
|
|
45
|
+
hasAnimation(name: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The slot's light and dark colour with the animation applied at `time` on
|
|
48
|
+
* a fresh, non-looping track from the setup pose, no skin set — or
|
|
49
|
+
* `undefined` for a slot the skeleton does not have.
|
|
50
|
+
*/
|
|
51
|
+
posedTint(animation: string, slot: string, time: number): PosedTint | undefined;
|
|
52
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deepest inward advance the animation data asks for, in axis pixels —
|
|
3
|
+
* shared by A29 and A30 (issue #1025, cut 4c-4 of #380), moved here from
|
|
4
|
+
* `src/validate.ts` unchanged but for what it reads: the bone timelines are a
|
|
5
|
+
* fact (`./facts/bone_timelines.ts`) rather than the raw JSON.
|
|
6
|
+
*
|
|
7
|
+
* Shared by A29 and A30 because they bound the SAME quantity against two
|
|
8
|
+
* different measured facts. Two things spend the same clearance and so are added:
|
|
9
|
+
*
|
|
10
|
+
* * the stroke — a translateX on a bone in the axis subtree. A24 guarantees
|
|
11
|
+
* there is no hidden screen-space component to miss.
|
|
12
|
+
* * the mass bone's own inward keys. It typically hangs outside the axis
|
|
13
|
+
* subtree, so its keys are screen-space by design and get PROJECTED onto the
|
|
14
|
+
* axis rather than read as axis coordinates. Ignoring them would let a rig
|
|
15
|
+
* pass while a recoil key closed the last few pixels.
|
|
16
|
+
*
|
|
17
|
+
* Links nothing from the runtime.
|
|
18
|
+
*/
|
|
19
|
+
import type { RigInfo } from '../types.ts';
|
|
20
|
+
import type { BoneTimelineFacts } from './facts/bone_timelines.ts';
|
|
21
|
+
import { isObj, type Json } from './values.ts';
|
|
22
|
+
|
|
23
|
+
export function deepestInwardAdvance({ boneTimelines }: BoneTimelineFacts, rig: RigInfo): { total: number; describe: () => string } {
|
|
24
|
+
const subtree = new Set(rig.axisSubtree);
|
|
25
|
+
let strokeMax = 0;
|
|
26
|
+
let strokeWhere = '';
|
|
27
|
+
let massMax = 0;
|
|
28
|
+
let massWhere = '';
|
|
29
|
+
for (const { animation: animName, bone: boneName, timelines } of boneTimelines) {
|
|
30
|
+
if (!isObj(timelines)) continue;
|
|
31
|
+
const keys = (timelines as Json).translate;
|
|
32
|
+
if (!Array.isArray(keys)) continue;
|
|
33
|
+
for (const key of keys) {
|
|
34
|
+
if (!isObj(key)) continue;
|
|
35
|
+
if (subtree.has(boneName)) {
|
|
36
|
+
// +x is inward along the axis; a retracted key is negative and spends
|
|
37
|
+
// no clearance, so only the inward extreme matters.
|
|
38
|
+
const x = Number(key.x ?? 0);
|
|
39
|
+
if (Number.isFinite(x) && x > strokeMax) {
|
|
40
|
+
strokeMax = x;
|
|
41
|
+
strokeWhere = `${animName}.${boneName} t=${String(key.time ?? 0)}`;
|
|
42
|
+
}
|
|
43
|
+
} else if (boneName === rig.massBone && rig.inwardUnit) {
|
|
44
|
+
const inward = Number(key.x ?? 0) * rig.inwardUnit[0] + Number(key.y ?? 0) * rig.inwardUnit[1];
|
|
45
|
+
if (Number.isFinite(inward) && inward > massMax) {
|
|
46
|
+
massMax = inward;
|
|
47
|
+
massWhere = `${animName}.${boneName} t=${String(key.time ?? 0)}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
total: strokeMax + massMax,
|
|
54
|
+
describe: () =>
|
|
55
|
+
`deepest inward advance is ${(strokeMax + massMax).toFixed(3)}px (stroke ${strokeMax.toFixed(3)} at ${strokeWhere}` +
|
|
56
|
+
`${massMax > 0 ? ` + mass ${massMax.toFixed(3)} at ${massWhere}` : ''})`,
|
|
57
|
+
};
|
|
58
|
+
}
|