@rig-c/parts 2.42.0 → 2.44.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.
package/docs/STABILITY.md CHANGED
@@ -294,7 +294,7 @@ and do not certify visibility. See the
294
294
  | `check` | `--rig`, `--out`; optional `--parts`, `--source`, `--page-edges`, `--pack-shape`, `--page-size`, `--requirements`, `--seam-pairs`, `--keep-stills`, `--no-extremes` (issue #829), `--set` or `--all-sets` (issue #454), `--environment` (issue #538, additive), `--wind-band` (issue #590, additive), `--json` (issue #904) |
295
295
  | `loop` | `--frames`, `--out`; optional `--palette` |
296
296
  | `build` | `--config`, `--source`, `--full`, `--out`; optional `--head` (as for `assemble`), `--seam`, `--project`, `--page-edges`, `--pack-shape`, `--page-size`, `--loop`, `--lead-in`, `--requirements`, `--idle-keys`, `--seam-pairs`, `--keep-stills`, `--no-extremes` (issue #829), `--alt` (as for `assemble`, issue #454), `--set` or `--all-sets` (as for `check`, issue #454), `--environment` (as for `check`, issue #538, additive), `--wind-band` (as for `check`, issue #590, additive) |
297
- | `compose` | `--scene`, `--out`; optional `--requirements`, `--accept` |
297
+ | `compose` | `--scene`, `--out`; optional `--requirements`, `--accept`, `--page-size` |
298
298
  | `mesh-draft` | `--config`, `--parts`, `--out`; optional `--requirements`, `--idle-keys` (ctl, direct), `--page-edges` (pot, free), `--pack-shape` (rect, polygon), `--page-size`, `--more-triangles` |
299
299
  | `mesh-stats` | `--config`, `--parts` (issue #566, additive: prints, writes nothing) |
300
300
  | `remesh` | `--rig`, `--config`, `--parts`, `--part`, `--out`, and one of `--mesh` or `--delta` (issue #526); optional `--requirements`, `--idle-keys` (ctl, direct), `--page-edges` (pot, free), `--pack-shape` (rect, polygon), `--page-size`, `--record-input-check` and `--input-check` (issue #617, additive: without them nothing `remesh` prints or writes changes) |
@@ -732,7 +732,11 @@ execution in historical evidence is inferred from a current export.
732
732
  | `rig.json`, `motion.json`, `mesh_report.json`, `images/`, `remesh.json` | `remesh` | the input revision's files, `rig.json` and `mesh_report.json` with the part's attachment and row replaced (under `--delta` the row is the input's with its counts, `bones` and influences recomputed and `mode` "delta"), every other file byte for byte; `remesh.json` is spec `rig-parts-remesh/1`: `request` (`part`, `mesh`, `mesh_sha256`, `idle_keys`, `page_edges`, `pack_shape`; under `--delta`, issue #526: `part`, `delta` — the mesh edit as read — `delta_sha256`, `ops`, `applied` — `moved`, `added`, `removed`, `constrained` — `idle_keys`, `page_edges`, `pack_shape`), `versions` (`parts`, `rigc`), `input` (`rig` — `path`, `bytes`, `sha256` per file — `config_sha256`, `parts_json_sha256`), `baseline` (`reproduced`, `not_compared`; under `--delta` `reproduced` holds one sentence: no config is built, the input is the baseline), `target` (`before`, `after`: `vertices`, `triangles`, `hull`), `preserved` (`identical`, `spliced`), `revision` (per file as `input.rig`), `check` (`input`, `revision`: `pass`, `measured`, `not_met`, `skipped`, `physics`, then `line` and `status` — issue #541, additive, the spec stays `rig-parts-remesh/1`: `line` is the last line `check` prints on that tree, byte for byte, and `status` every block's status as that tree's `check.json` records it, by name in the file's order — `gate`, `loop` and `seam` read from their figures, every other block its own `status`, a block the file does not write absent; `scope`) |
733
733
  | `rig.json`, `motion.json`, `mesh_report.json`, `images/`, `retune.json` | `retune` | the input revision's files, `rig.json` with `constraints` and `invariants.detached` replaced and `motion.json` with `animations.idle` replaced by the config's build, every other file byte for byte; `retune.json` is spec `rig-parts-retune/1`: `request` (`idle_keys`, `page_edges`, `pack_shape`), `versions` (`parts`, `rigc`), `input` (`rig` — `path`, `bytes`, `sha256` per file — `config_sha256`, `parts_json_sha256`), `held` (`compared`, `not_compared`), `changed` (`constraints` — each `name`, `type`, `fields` — `added`, `removed`, `idle`: `tracks_changed`, `duration` as before and after), `preserved` (`identical`, `spliced`), `revision` (per file as `input.rig`), `check` (`input`, `revision`: `pass`, `measured`, `not_met`, `skipped`, `physics`, then `line` and `status` — issue #541, additive, the spec stays `rig-parts-retune/1`: `line` is the last line `check` prints on that tree, byte for byte, and `status` every block's status as that tree's `check.json` records it, by name in the file's order — `gate`, `loop` and `seam` read from their figures, every other block its own `status`, a block the file does not write absent; `scope`) |
734
734
  | `input-check.json` | `remesh --record-input-check`, `retune --record-input-check` | spec `rig-parts-input-check/1` (issue #617, additive): `versions` (`parts`, `rigc` — `rigc --version`'s whole output), `options` (`page_edges`, `pack_shape`, `page_size` when `--page-size` is given, `requirements` — null, or `path` as resolved and `sha256`), `rig` and `parts` (`dir` as resolved, `files` — `path`, `bytes`, `sha256` per file: every file under `--rig`; `parts.json` and every file under `parts/`), `check` (the input's check side as `remesh.json` carries it); `--input-check` reads it back, and either command's serves the other |
735
- | the scene report | `compose` | spec `spine-parts-scene-report/1`; the plate block carries `sha256` of the plate PNG's bytes after `size` (issue #1183, additive under *What "stable" means here*: a new report key in a minor version, so the spec stays `/1`) |
735
+ | composed turn producer inputs | `compose` | issue #1344 intentionally admits previously refused yaw/pitch derive maps, turn deform offsets/transforms, depth-grid generator images, bone inherit modes and producer mesh/fold invariants; every embedded reference is resolved and prefixed except the shared default skin. Mesh-slot ceilings sum and per-mesh triangle ceilings take the maximum, using actual counts only for unbudgeted members. Weighted lengths scale; image-sized depth grids at scale other than 1 are refused by `SCENE_SCALE_EXACT`. Other nested constructs remain refused. Previously passing scene payloads are byte-identical; the existing `check/check.json` requirement is retained, so `rig` plus `rigc build` alone is not a checked character. |
736
+ | named scene plates | `compose` | issue #1345 adds optional `plates[]`: required `name`, `image`, `provenance`, `at: [x, y]`; optional `note`, `editor_receipts`, `opaque_backdrop`. `at` is two finite integers for the image top-left in canvas pixels, y down from the top-left origin; negatives/outside allowed, no scale, native image size including oversize. Each bone/slot/attachment uses its declared name, bone under root at `(0,0)`; attachment centre is `stage.x + at[0] + width/2`, `cropToSpineY(at[1] + height/2, canvas.height)`. Each layer's token is required exactly once in draw order, with duplicate/missing/unknown/collision refusals. Names cannot collide with root, legacy plate, shared idle, character ids or prefixed bones/slots/animations. Only that layer's explicit `opaque_backdrop: true` exempts it from compose alpha checks; an opaque declared backdrop must additionally meet width >= canvas.width AND height >= canvas.height (the rig stage), matching core 3.8.0 A19 size inference; otherwise SCENE_PLATE_BACKDROP_SIZE refuses before emission. Transparent layers have no size floor. rigc A19 remains enabled. Named images use `scene-plate.<index>.png` with collision checks. The additive report `plates` array records declaration, native size and PNG hash; absent declaration retains legacy output bytes and fixed first-plate behavior. |
737
+ | scene named animations | `compose` | issue #1346 adds optional `scene.animations`, a name-to-rigc-MotionAnimation map resolved against final scene bones/groups/easings. New names add clips at their own declared durations; `idle` appends timelines while retaining existing character tracks, deforms, metadata and physics. Idle duration mismatch is `SCENE_DURATION_AGREES`, without retiming; imported non-idle names cannot be replaced. Core owns missing fields, unknown bones/references, duplicate property tracks and bad times. Unknown prefixed bones also name the character ID. Generated names `<id>:yaw_dial`, `<id>:pitch_dial`, and `<id>:<turn.body.slider>` (default `<id>:body_yaw_dial`) are stable; renaming them requires a major version. A dial exists only when generated by its character. Rotation keys use that slider's declared `[from, max]` bounds; out-of-range values are `SCENE_DIAL_KEY_RANGE`, unreadable bounds `SCENE_DIAL_RANGE_DECLARED`, never guessed. Slider-input keys require explicit numeric values; derive inputs are refused as `SCENE_DIAL_KEY_DECLARED`, including derive alongside a raw value. Bounds apply to the matching scalar or paired translate/scale/shear input channel; inherited group names are refused with `CE_COMPILE_ANIMATION_GROUP_UNKNOWN`. Each declared clip's gated posed endpoints at 0 and duration must agree before emission (`SCENE_ANIMATION_LOOP_CLOSES`), with physics simulation left out only for observation. Absent declaration retains stable output bytes at the same paths. Core `check/build/run.json` records fresh `started_at` and `finished_at` clocks; comparisons report these raw differences separately and require all other receipt fields and output bytes to match. |
738
+ | `compose-run.json` | `compose` | spec `rig-compose-run/1` (issue #1348), separate from `rig-run/1`; a stable contract as of 2.44.0. Written at the `--out` root only after the gate and check are green and no accepted failing character remains, so an `--accept` preview writes none. Fixed keys in order: `spec`, `scene` (`path`, `sha256`), `characters` (each `id`, `build`, `files`, each file `path`, `sha256`), `plate` (`path`, `sha256`, or null), `plates` (each `name`, `path`, `sha256`). Scene and plate paths are the supplied and declared paths; character file paths are build-relative. Characters sort by `id`, files by `path`, named plates by `name`, in code-unit order. Each character's files are exactly `check/check.json`, `parts.json`, `rig/rig.json`, `rig/motion.json` and each distinct image the default skin names under `rig/images/`, including a generator's depth image. Every `sha256` is of the raw file bytes compose consumed before the gate. There are no clocks, directory extras, requirements or CLI-option inventory, so identical inputs at identical supplied paths give identical record bytes. Compose owns the name: a file of that name at the `--out` root is deleted at the start of every compose, before stage validation, so a refused rerun leaves none. Only this file is added; legacy outputs retain stable bytes, with the existing nested Core receipt clock comparison described above. |
739
+ | the scene report | `compose` | spec `spine-parts-scene-report/1`; the plate block carries `sha256` of the plate PNG's bytes after `size` (issue #1183, additive under *What "stable" means here*: a new report key in a minor version, so the spec stays `/1`); `pack_mode` records `page_size` only when `--page-size <px>` is given (issue #1352, additive; without `--page-size`, rigc's default 2048 px page and padding 2 on each side bound any plate or region side to at most 2044 px before `CE_ATLAS_REGION_EXCEEDS_PAGE`) |
736
740
  | `idle.png`, `idle-indexed.png`, `idle.gif` | `loop`, `build --loop` | APNG and GIF encodings of the rendered idle |
737
741
  | `run.json` | `rig`, `assemble` | spec `rig-run/1` (issue #1165, additive): `spec`, `package` (`name`, `version`), `command` (`"rig"` or `"assemble"`), `started_at` and `finished_at` (UTC ISO-8601 millisecond timestamps ending in `Z`, read in the CLI layer), `config` (`path` relative to `--out`, `sha256` of the config file on disk), `inputs` on `assemble` (issue #1316, additive: one `{role, path, sha256}` entry for each of `--source`, `--full` and `--head` that was given, in that order, with `path` relative to the run's cwd and `sha256` of the file or of the directory's `layers.json`), and `outputs` (`path` relative to `--out`, `sha256` of each written output file on disk, sorted by `path` in code-unit order and excluding `run.json` itself); written only after the command's gate is green |
738
742
  | the difference inventory (`--out`) | `diff-components` | spec `rig-parts-diff-components/1` by default (issue #1005: `stack`, `painting`, `definition`, `error_px`, `uncovered_error_px`, `components` — each `id`, `px`, `box`, `coverage`, `uncovered_px`, `borders` — and `below_floor`, byte-identical to 2.38.1), and spec `rig-parts-diff-components/2` under `--owners` (issue #1291: adds `owners` — each `{part, px}`, the topmost `parts.json` part above `COVERED_ALPHA` per covered pixel, back to front — before `borders` on every component); `--verify` verifies both `/1` and `/2` reports (with `--owners`, `/2` is required), while a `/1`-only reader (`readDiffComponents(text, input, [DIFF_COMPONENTS_SPEC])`) refuses `/2` by name |
@@ -1200,7 +1204,7 @@ route. See [Background over every frame](AUTHORING.md#background-over-every-fram
1200
1204
  The optional `behind_seams` key in `spine-parts-requirements/1` (issue #1314,
1201
1205
  additive) declares the required `BEHIND_PART_SEAMS` check, independently of the
1202
1206
  existing requirement kinds and without a new CLI flag. Its optional fields are
1203
- `threshold`, `allowance` and `pairs`; pair entries require distinct nonempty
1207
+ `threshold`, `allowance`, `pairs` and `turn`; pair entries require distinct nonempty
1204
1208
  `part` and `neighbour` names and may override `threshold` and `allowance`.
1205
1209
  Names must resolve to known parts and an already selected pair; duplicate
1206
1210
  pairs, including reversed pairs, are invalid. Shape errors use `REQUIREMENTS_FIELD`.
@@ -1222,6 +1226,36 @@ motion support, boundary population or verified render evidence is a HOLE,
1222
1226
  not a zero PASS. Existing render/sidecar refusals remain refusals. The standing
1223
1227
  bracketed-run definition does not certify curved or diagonal openings.
1224
1228
 
1229
+ Issue #1323 adds `behind_seams.turn: true` as an explicit opt-in. It references
1230
+ existing emitted turn slider ranges, never a second range declaration. Without
1231
+ this key no turn rows are written and existing `check.json` bytes are unchanged.
1232
+ With it, `BEHIND_PART_SEAMS.turn` records named independent reset poses: each
1233
+ dial's declared `from` and `max` with other dials at setup, then every full
1234
+ min/max corner, deduplicated in that order. It records planned and observed dial locals and observed slider mapped times, per-pair
1235
+ `frames`, `sampled_poses`, `read_poses`, `unmeasured_poses`, and separate
1236
+ `motion_opened` / `standing` status and maximum counts. There are no temporal
1237
+ spans: pose indices are sample identities, and time is 0 for every reset.
1238
+ Turn uses its own setup, rest geometry and transported stock seam evidence;
1239
+ idle stock and idle counts are unchanged. The same thresholds, allowances,
1240
+ rear-set and unread rules apply. Optional unread-corridor evidence also applies
1241
+ to turn standing rows. No declared dial persists turn SKIP and a named HOLE;
1242
+ an effective authored T makes that missing required reading a
1243
+ `CHECK_BEHIND_PART_SEAMS_UNMEASURED` failure. Legacy `turn.x` has no declared
1244
+ finite range and is explicitly unread, never given a guessed range. The
1245
+ official facade supplies geometry from one throwaway gated build that appends
1246
+ one duration-0 pose animation per selected endpoint/corner, retaining setup,
1247
+ sliders, original animations, profile and pack flags. Timeline properties are
1248
+ `rotate` / `translatex` / `translatey`, with offsets from setup. Actual local
1249
+ channels (after constraints) must match planned locals at float32 precision;
1250
+ slider mapped times are also retained. Actual poser, atlas text, decoded pages
1251
+ and setup geometry must match the accepted build, or turn is a named HOLE.
1252
+ Build refusal also leaves unrelated readings available, with scratch cleanup
1253
+ in all cases. The original skeleton SHA-256 is recorded once in turn limitations.
1254
+ Without opt-in there is no scratch copy or extra build. Missing effective T for
1255
+ one pair is optional SKIP even when another pair has a required override.
1256
+ An unavailable poser or source is a HOLE. Other animations, between-sample turns and alternate
1257
+ skins remain unmeasured.
1258
+
1225
1259
  Issue #1325 adds the following optional evidence fields to
1226
1260
  `BEHIND_PART_SEAMS.pairs[].setup.standing` and
1227
1261
  `BEHIND_PART_SEAMS.pairs[].frames[].standing` only. Paths in the table are
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/parts",
3
- "version": "2.42.0",
3
+ "version": "2.44.0",
4
4
  "description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,12 +1,14 @@
1
1
  import { readFileSync } from 'node:fs';
2
+ import { createHash } from 'node:crypto';
2
3
  import { isAbsolute, join, relative, resolve } from 'node:path';
3
4
  import type { Plate } from '@rig-c/core/plate';
4
5
  import type { AttachmentRest, Frame } from '@rig-c/core/render-shared';
5
- import { seamGridOf, type SeamCell, type SeamGrid } from '@rig-c/core/seam';
6
+ import { seamGridOf, seamsOf, setupCellReader, type SeamCell, type SeamGrid } from '@rig-c/core/seam';
6
7
  import { DRAWN_ALPHA } from '@rig-c/core/passthrough';
7
8
  import { checkRow } from './checkrow.ts';
8
9
  import { seamSourceAttachment, type MotionSeamPair } from './check.ts';
9
10
  import type { Problem } from './errors.ts';
11
+ import { BODY_TURN_ANIM, BODY_YAW_DIAL_BONE, PITCH_DIAL_BONE, TURN_BONE, YAW_DIAL_BONE } from './turn.ts';
10
12
 
11
13
  export const BEHIND_SEAM_LINE = 'BEHIND_PART_SEAMS';
12
14
  export const UNDECLARED_BEHIND_SEAM_REASON = 'HOLE: no requirements.behind_seams declares an authored threshold T; not measured, never a pass';
@@ -14,6 +16,8 @@ export const BEHIND_SEAM_CODE = 'CHECK_BEHIND_PART_SEAMS';
14
16
  export const BEHIND_SEAM_UNMEASURED_CODE = 'CHECK_BEHIND_PART_SEAMS_UNMEASURED';
15
17
 
16
18
  export interface BehindSeams {
19
+ /** Opt in to the rig's declared ranges; never supplies or guesses a range. */
20
+ turn?: true;
17
21
  threshold?: number;
18
22
  allowance?: number;
19
23
  pairs?: Array<{ part: string; neighbour: string; threshold?: number; allowance?: number }>;
@@ -34,6 +38,42 @@ export interface BehindSeamsFramesInput {
34
38
  pages: Map<string, Plate>;
35
39
  stock: readonly BehindSeamsStockPair[] | null;
36
40
  fps: number;
41
+ turn?: BehindSeamsTurnInput;
42
+ }
43
+ export interface BehindSeamsTurnPose {
44
+ name: string;
45
+ values: Record<string, number>;
46
+ observed_values?: Record<string, number>;
47
+ slider_times?: Record<string, number>;
48
+ }
49
+ export interface BehindSeamsTurnInput {
50
+ poses: BehindSeamsTurnPose[];
51
+ frames: Array<Frame | null>;
52
+ setup: Frame | null;
53
+ rest: readonly AttachmentRest[];
54
+ stock: readonly BehindSeamsStockPair[] | null;
55
+ reason?: string;
56
+ sourceSkeletonSha256?: string;
57
+ poser?: string;
58
+ }
59
+ export interface BehindSeamsTurnPair {
60
+ pair: string;
61
+ parts: [string, string];
62
+ threshold: number | null;
63
+ allowance: number;
64
+ frames: BehindSeamsFrame[];
65
+ sampled_poses: number;
66
+ read_poses: number;
67
+ unmeasured_poses: number;
68
+ motion_opened: { status: BehindSeamsCount['status']; max_px: number };
69
+ standing: { status: BehindSeamsCount['status']; max_px: number };
70
+ }
71
+ export interface BehindSeamsTurnMeasured {
72
+ status: BehindSeamsCount['status'];
73
+ poses: string[];
74
+ pairs: BehindSeamsTurnPair[];
75
+ unmeasured: BehindSeamsMeasured['unmeasured'];
76
+ limitations: string;
37
77
  }
38
78
  export interface BehindSeamsSample {
39
79
  x: number;
@@ -69,7 +109,11 @@ export interface BehindSeamsStanding extends BehindSeamsCount {
69
109
  unread_corridors?: BehindSeamsUnreadCorridor[];
70
110
  }
71
111
  export interface BehindSeamsFrame {
72
- animation: 'idle' | null;
112
+ animation: 'idle' | 'turn' | null;
113
+ pose?: string;
114
+ values?: Record<string, number>;
115
+ observed_values?: Record<string, number>;
116
+ slider_times?: Record<string, number>;
73
117
  index: number;
74
118
  time: number;
75
119
  behind_slots: string[];
@@ -118,6 +162,7 @@ export interface BehindSeamsMeasured {
118
162
  pairs: BehindSeamsPair[];
119
163
  unmeasured: Array<{ pair: string | null; frame: string; reason: string }>;
120
164
  limitations: string;
165
+ turn?: BehindSeamsTurnMeasured;
121
166
  }
122
167
 
123
168
  /** The orchestration input: only an already gated build and its full stock seam
@@ -129,6 +174,7 @@ export interface BehindSeamsInput {
129
174
  stockDir: string | null;
130
175
  fps: number;
131
176
  unsupported?: string;
177
+ turnBuild?: { build?: string; reason?: string };
132
178
  }
133
179
 
134
180
  const LIMITATIONS = 'setup and every idle frame; motion uses transported setup-overlap support; standing certifies horizontal and vertical bracketed runs, not all curved or diagonal openings; rear-set attribution is not individual-slot blame; other animations and alternate skins are not measured';
@@ -142,7 +188,8 @@ export function behindSeamsProblems(value: unknown, at: string): Problem[] {
142
188
  const bad = (object: string, detail: string): void => { problems.push({ code: 'REQUIREMENTS_FIELD', object, detail }); };
143
189
  const block = (v: unknown, where: string, pair: boolean): void => {
144
190
  if (!record(v)) { bad(where, `is ${JSON.stringify(v)}; requires a behind_seams record with an authored threshold and optional allowance/pair overrides`); return; }
145
- for (const k of Object.keys(v)) if (!(pair ? ['part', 'neighbour', 'threshold', 'allowance'] : ['threshold', 'allowance', 'pairs']).includes(k) && !freeKey(k, v[k])) bad(`${where}.${k}`, 'is not a field this block reads (threshold, allowance, pairs; pair entries name part and neighbour; note or *_note as a string; x-<name> as a record)');
191
+ for (const k of Object.keys(v)) if (!(pair ? ['part', 'neighbour', 'threshold', 'allowance'] : ['threshold', 'allowance', 'pairs', 'turn']).includes(k) && !freeKey(k, v[k])) bad(`${where}.${k}`, 'is not a field this block reads (threshold, allowance, pairs, turn; pair entries name part and neighbour; note or *_note as a string; x-<name> as a record)');
192
+ if (!pair && 'turn' in v && v.turn !== true) bad(`${where}.turn`, 'requires true to read the rig\'s declared turn range endpoints and corners; omit to retain setup/idle only; no ranges are supplied here');
146
193
  if ('threshold' in v && (typeof v.threshold !== 'number' || !Number.isInteger(v.threshold) || v.threshold < 0 || v.threshold > 255)) bad(`${where}.threshold`, `is ${JSON.stringify(v.threshold)}; requires an authored integer from 0 through 255; no threshold is derived from the art`);
147
194
  if ('allowance' in v && (typeof v.allowance !== 'number' || !Number.isSafeInteger(v.allowance) || v.allowance < 0)) bad(`${where}.allowance`, `is ${JSON.stringify(v.allowance)}; requires a nonnegative safe integer count of seam cells`);
148
195
  if (pair) {
@@ -215,9 +262,10 @@ interface RasterCache { full: Plate; hidden: Plate }
215
262
 
216
263
  function readBehindFrame(api: BehindSeamsApi, input: BehindSeamsFramesInput, pair: MotionSeamPair, frame: Frame, setup: boolean,
217
264
  stock: BehindSeamsStockPair | undefined, threshold: number, allowance: number, unread: (frame: string, reason: string) => void,
218
- cache: Map<Frame, Map<string, RasterCache>>): BehindSeamsFrame {
219
- const label = setup ? 'setup' : `idle frame ${frame.index}`;
220
- const row: BehindSeamsFrame = { ...checkRow(setup ? 'BEHIND_PART_SEAMS.pairs[].setup' : 'BEHIND_PART_SEAMS.pairs[].frames', 'pair', false, [pair.a, pair.b]), animation: setup ? null : 'idle', index: frame.index, time: frame.time, behind_slots: [], grid: null, motion_opened: emptyCount(), standing: emptyCount() };
265
+ cache: Map<Frame, Map<string, RasterCache>>, pose?: BehindSeamsTurnPose): BehindSeamsFrame {
266
+ const label = pose !== undefined ? `turn ${pose.name}` : setup ? 'setup' : `idle frame ${frame.index}`;
267
+ const family = pose !== undefined ? 'BEHIND_PART_SEAMS.turn.pairs[].frames' : setup ? 'BEHIND_PART_SEAMS.pairs[].setup' : 'BEHIND_PART_SEAMS.pairs[].frames';
268
+ const row: BehindSeamsFrame = { ...checkRow(family, 'pair', false, [pair.a, pair.b]), animation: pose !== undefined ? 'turn' : setup ? null : 'idle', index: frame.index, time: frame.time, ...(pose === undefined ? {} : { pose: pose.name, values: { ...pose.values }, ...(pose.observed_values === undefined ? {} : { observed_values: pose.observed_values, slider_times: pose.slider_times }) }), behind_slots: [], grid: null, motion_opened: emptyCount(), standing: emptyCount() };
221
269
  const fail = (reason: string): BehindSeamsFrame => { unread(label, reason); return row; };
222
270
  if (pair.unread !== undefined) return fail(pair.unread);
223
271
  if (frame.attachments === undefined) return fail('draw order/whole attachment geometry is unavailable');
@@ -290,7 +338,7 @@ function readBehindFrame(api: BehindSeamsApi, input: BehindSeamsFramesInput, pai
290
338
  let motionReadable = setup;
291
339
  const motionCells = new Map<number, SeamCell>();
292
340
  if (!setup) {
293
- if (stock === undefined || stock.frames !== input.idle.length || stock.drawn !== stock.frames || stock.banded !== stock.frames) unread(label, 'stock transported setup-overlap support is unavailable on every idle frame; motion-opened is not measured');
341
+ if (stock === undefined || stock.frames !== input.idle.length || stock.drawn !== stock.frames || stock.banded !== stock.frames) unread(label, `stock transported setup-overlap support is unavailable on every ${pose === undefined ? 'idle frame' : 'named turn pose'}; motion-opened is not measured`);
294
342
  else {
295
343
  motionReadable = true;
296
344
  const hits = stock.gapCovered.filter(h => h.index === frame.index);
@@ -393,7 +441,7 @@ function readBehindFrame(api: BehindSeamsApi, input: BehindSeamsFramesInput, pai
393
441
  row.motion_opened.geometric_px = motionHits.size; row.motion_opened.raw_px = motionHits.size;
394
442
  counted(row.motion_opened, motionHits, grid, allowance);
395
443
  if (!motionReadable) row.motion_opened.status = 'SKIP';
396
- return { ...row, ...checkRow(setup ? 'BEHIND_PART_SEAMS.pairs[].setup' : 'BEHIND_PART_SEAMS.pairs[].frames', 'pair', row.standing.status === 'FAIL' || row.motion_opened.status === 'FAIL', [pair.a, pair.b]) };
444
+ return { ...row, ...checkRow(family, 'pair', row.standing.status === 'FAIL' || row.motion_opened.status === 'FAIL', [pair.a, pair.b]) };
397
445
  } catch (e) { return fail(`official raster/source reading unavailable: ${e instanceof Error ? e.message : String(e)}`); }
398
446
  }
399
447
 
@@ -486,9 +534,198 @@ export function measureBehindSeamFrames(api: BehindSeamsApi, input: BehindSeamsF
486
534
  sampled_frames: input.idle.length, read_frames: readFrames, unmeasured_frames: input.idle.length - readFrames });
487
535
  }
488
536
  line.status = problems.length > start ? 'FAIL' : line.pairs.length === 0 || line.pairs.some(p => p.threshold === null || p.motion_opened.status === 'SKIP' || p.standing.status === 'SKIP') ? 'SKIP' : 'PASS';
537
+ if (declared.turn === true) {
538
+ line.turn = measureBehindTurnFrames(api, input, declared, problems);
539
+ if (line.turn.status === 'FAIL' || problems.length > start) line.status = 'FAIL';
540
+ else if (line.turn.status === 'SKIP' && line.status !== 'FAIL') line.status = 'SKIP';
541
+ }
489
542
  return line;
490
543
  }
491
544
 
545
+ /** Turn observations are independent t=0 reset samples, never temporal spans. */
546
+ function measureBehindTurnFrames(api: BehindSeamsApi, input: BehindSeamsFramesInput, declared: BehindSeams, problems: Problem[]): BehindSeamsTurnMeasured {
547
+ const turn = input.turn;
548
+ const result: BehindSeamsTurnMeasured = { status: 'SKIP', poses: turn?.poses.map(p => p.name) ?? [], pairs: [], unmeasured: [],
549
+ limitations: 'independent setup-reset turn endpoints and full range corners only; no sweep, idle motion, temporal spans or alternate skins; standing and transported setup-overlap are separate' };
550
+ if (turn?.poser !== undefined) result.limitations += `; poser ${turn.poser}`;
551
+ if (turn?.sourceSkeletonSha256 !== undefined) result.limitations += `; original skeleton sha256 ${turn.sourceSkeletonSha256}`;
552
+ const required = declared.threshold !== undefined || declared.pairs?.some(p => p.threshold !== undefined) === true;
553
+ let mandatoryUnread = false;
554
+ const unread = (pair: MotionSeamPair | null, frame: string, reason: string, mandatory: boolean): void => {
555
+ result.unmeasured.push({ ...checkRow('BEHIND_PART_SEAMS.turn.unmeasured', pair === null ? 'rig' : 'pair', mandatory, pair === null ? [] : [pair.a, pair.b]), pair: pair?.pair ?? null, frame, reason: `HOLE: ${reason}` });
556
+ if (mandatory) mandatoryUnread = true;
557
+ if (mandatory) problems.push({ code: BEHIND_SEAM_UNMEASURED_CODE, object: `${pair?.pair ?? BEHIND_SEAM_LINE} (${frame})`, detail: `HOLE: ${reason}; required turn reading cannot pass unmeasured` });
558
+ };
559
+ if (turn === undefined || turn.poses.length === 0) {
560
+ unread(null, 'turn', turn?.reason ?? 'no declared finite turn dial range; turn is SKIP, never a pass', required);
561
+ result.pairs = input.pairs.map(pair => {
562
+ const override = declared.pairs?.find(p => keyOf(p.part, p.neighbour) === keyOf(pair.a, pair.b));
563
+ return { ...checkRow('BEHIND_PART_SEAMS.turn.pairs', 'pair', required, [pair.a, pair.b]), pair: pair.pair, parts: [pair.a, pair.b],
564
+ threshold: override?.threshold ?? declared.threshold ?? null, allowance: override?.allowance ?? declared.allowance ?? 0,
565
+ frames: [], sampled_poses: 0, read_poses: 0, unmeasured_poses: 0,
566
+ motion_opened: { status: 'SKIP', max_px: 0 }, standing: { status: 'SKIP', max_px: 0 } };
567
+ });
568
+ return result;
569
+ }
570
+ if (turn.reason !== undefined) unread(null, 'turn', turn.reason, required);
571
+ const complete = turn.frames.length === turn.poses.length && new Set(turn.poses.map(p => p.name)).size === turn.poses.length;
572
+ if (!complete) unread(null, 'turn', 'missing or duplicate named turn sample; every preselected endpoint and corner is required', required);
573
+ const frames = turn.frames.filter((f): f is Frame => f !== null);
574
+ const posedInput: BehindSeamsFramesInput = { ...input, setup: turn.setup, idle: frames, rest: turn.rest, stock: turn.stock };
575
+ const cache = new Map<Frame, Map<string, RasterCache>>();
576
+ for (const pair of input.pairs) {
577
+ const override = declared.pairs?.find(p => keyOf(p.part, p.neighbour) === keyOf(pair.a, pair.b));
578
+ const threshold = override?.threshold ?? declared.threshold ?? null, allowance = override?.allowance ?? declared.allowance ?? 0;
579
+ const parts: [string, string] = [pair.a, pair.b];
580
+ const stockRows = turn.stock?.filter(s => s.pair === pair.pair) ?? [];
581
+ const rows: BehindSeamsFrame[] = [];
582
+ if (threshold === null) unread(pair, 'turn declaration', 'no authored threshold T; turn pair is SKIP, never a pass', false);
583
+ else {
584
+ if (turn.setup === null) unread(pair, 'turn setup', 'actual turn setup pose is unavailable', true);
585
+ for (const [index, pose] of turn.poses.entries()) {
586
+ const frame = turn.frames[index];
587
+ if (frame === undefined || frame === null || frame.index !== index || frame.time !== 0) {
588
+ unread(pair, `turn ${pose.name}`, 'preselected turn pose is missing or has the wrong identity; it cannot become zero cells', true);
589
+ continue;
590
+ }
591
+ const row = readBehindFrame(api, posedInput, pair, frame, false, stockRows.length === 1 ? stockRows[0] : undefined,
592
+ threshold, allowance, (where, why) => unread(pair, where, why, true), cache, pose);
593
+ rows.push(row); cache.clear();
594
+ for (const kind of ['motion_opened', 'standing'] as const) if (row[kind].status === 'FAIL') problems.push({ code: BEHIND_SEAM_CODE,
595
+ object: `pair "${pair.pair}" turn ${pose.name} ${kind}`, detail: `${row[kind].px} native seam cells exceeds allowance ${allowance}; authored threshold ${threshold}; independent declared turn pose` });
596
+ }
597
+ }
598
+ const read = rows.filter(row => row.motion_opened.status !== 'SKIP' && row.standing.status !== 'SKIP' &&
599
+ !result.unmeasured.some(u => u.pair === pair.pair && u.frame === `turn ${row.pose}`)).length;
600
+ const aggregate = (kind: 'motion_opened' | 'standing'): BehindSeamsTurnPair['standing'] => ({
601
+ status: rows.some(r => r[kind].status === 'FAIL') ? 'FAIL' : complete && rows.length === turn.poses.length && rows.every(r => r[kind].status === 'PASS') ? 'PASS' : 'SKIP',
602
+ max_px: Math.max(0, ...rows.map(r => r[kind].px)),
603
+ });
604
+ const motion = aggregate('motion_opened'), standing = aggregate('standing');
605
+ result.pairs.push({ ...checkRow('BEHIND_PART_SEAMS.turn.pairs', 'pair', motion.status === 'FAIL' || standing.status === 'FAIL' || threshold !== null && read !== turn.poses.length, parts),
606
+ pair: pair.pair, parts, threshold, allowance, frames: rows, sampled_poses: turn.poses.length, read_poses: read, unmeasured_poses: turn.poses.length - read,
607
+ motion_opened: motion, standing });
608
+ }
609
+ if (input.pairs.length === 0) unread(null, 'turn selection', 'no selected seam pair; turn boundary population is unavailable', required);
610
+ result.status = result.pairs.some(p => p.motion_opened.status === 'FAIL' || p.standing.status === 'FAIL') || mandatoryUnread ? 'FAIL'
611
+ : result.pairs.length === 0 || result.pairs.some(p => p.motion_opened.status === 'SKIP' || p.standing.status === 'SKIP') ? 'SKIP' : 'PASS';
612
+ return result;
613
+ }
614
+
615
+ interface BehindTurnDial { bone: string; field: 'rotation' | 'x' | 'y'; min: number; max: number; setup: number }
616
+ /** Read emitted declarations, not config defaults, dial-name guesses or animation times. */
617
+ export function behindTurnPlan(rig: Record<string, unknown>): { dials: BehindTurnDial[]; poses: BehindSeamsTurnPose[]; reason?: string } {
618
+ const bones = (Array.isArray(rig.bones) ? rig.bones : []).filter(record);
619
+ const sliders = (Array.isArray(rig.constraints) ? rig.constraints : []).filter(record).filter(c => c.type === 'slider' &&
620
+ ([YAW_DIAL_BONE, PITCH_DIAL_BONE, BODY_YAW_DIAL_BONE, TURN_BONE].includes(String(c.bone)) || ['turn', 'tilt', BODY_TURN_ANIM].includes(String(c.animation))));
621
+ const dials: BehindTurnDial[] = [];
622
+ for (const c of sliders) {
623
+ const matched = bones.filter(b => b.name === c.bone), field = c.property === 'rotate' ? 'rotation' : c.property === 'x' ? 'x' : c.property === 'y' ? 'y' : null;
624
+ if (typeof c.bone !== 'string' || matched.length !== 1 || field === null || c.local !== true ||
625
+ typeof c.from !== 'number' || !Number.isFinite(c.from) || typeof c.max !== 'number' || !Number.isFinite(c.max) || c.from >= c.max || dials.some(d => d.bone === c.bone)) {
626
+ return { dials: [], poses: [], reason: `turn slider "${String(c.name)}" has no unique local dial with finite increasing from/max range; no range is invented` };
627
+ }
628
+ const setup = matched[0][field] ?? 0;
629
+ if (typeof setup !== 'number' || !Number.isFinite(setup) || setup < c.from || setup > c.max) return { dials: [], poses: [], reason: `turn dial "${c.bone}" has no finite in-range setup value` };
630
+ dials.push({ bone: c.bone, field, min: c.from, max: c.max, setup });
631
+ }
632
+ if (bones.some(b => b.name === TURN_BONE) && !dials.some(d => d.bone === TURN_BONE)) return { dials: [], poses: [], reason: `legacy dial "${TURN_BONE}" has no declared finite range; no x range is invented` };
633
+ if (dials.length === 0) return { dials, poses: [], reason: 'no declared turn dial; turn is SKIP, never a pass' };
634
+ const poses: BehindSeamsTurnPose[] = [], seen = new Set<string>();
635
+ const add = (values: Record<string, number>): void => {
636
+ const key = JSON.stringify(values);
637
+ if (!seen.has(key)) { seen.add(key); poses.push({ name: dials.map(d => `${d.bone}=${values[d.bone]}`).join(','), values }); }
638
+ };
639
+ const setup = Object.fromEntries(dials.map(d => [d.bone, d.setup]));
640
+ for (const dial of dials) for (const value of [dial.min, dial.max]) add({ ...setup, [dial.bone]: value });
641
+ const corners = (index: number, values: Record<string, number>): void => {
642
+ if (index === dials.length) { add(values); return; }
643
+ const dial = dials[index];
644
+ for (const value of [dial.min, dial.max]) corners(index + 1, { ...values, [dial.bone]: value });
645
+ };
646
+ corners(0, {});
647
+ return { dials, poses };
648
+ }
649
+
650
+ /** One gated copy can carry every selected pose. Motion keys are offsets from
651
+ * setup, so convert planned absolute locals to the public timeline schema. */
652
+ export function behindTurnAnimations(rig: Record<string, unknown>): Record<string, { duration: number; tracks: Array<{ bone: string; property: string; keys: Array<{ t: number; v: number[] }> }> }> {
653
+ const plan = behindTurnPlan(rig);
654
+ return Object.fromEntries(plan.poses.map(pose => [behindTurnAnimationName(pose.name), {
655
+ duration: 0,
656
+ tracks: plan.dials.map(d => ({ bone: d.bone, property: d.field === 'rotation' ? 'rotate' : d.field === 'x' ? 'translatex' : 'translatey',
657
+ keys: [{ t: 0, v: [pose.values[d.bone] - d.setup] }] })),
658
+ }]));
659
+ }
660
+ /** Injective safe encoding of the pose name, including every UTF-16 code unit;
661
+ * no index, truncation or per-pose digest can hide a sample identity. */
662
+ export function behindTurnAnimationName(name: string): string {
663
+ return `_behind_seams_turn_${name.split('').map(c => c.charCodeAt(0).toString(16).padStart(4, '0')).join('')}`;
664
+ }
665
+
666
+ /** Read the throwaway gated copy through the same public facade as idle.
667
+ * No skeleton, model, setup or poser implementation is changed here. */
668
+ function sampleBehindTurn(api: typeof import('@rig-c/core/render-shared'), input: BehindSeamsInput,
669
+ accepted: ReturnType<typeof api.loadCandidate>, acceptedSetup: Frame | null, acceptedPoser: string): BehindSeamsTurnInput {
670
+ const plan = behindTurnPlan(input.rig);
671
+ const empty: BehindSeamsTurnInput = { poses: plan.poses, frames: [], setup: null, rest: [], stock: null };
672
+ if (plan.reason !== undefined) return { ...empty, reason: plan.reason };
673
+ try {
674
+ empty.sourceSkeletonSha256 = createHash('sha256').update(readFileSync(join(input.build, 'skeleton.json'))).digest('hex');
675
+ if (input.turnBuild?.reason !== undefined) throw new Error(input.turnBuild.reason);
676
+ const build = input.turnBuild?.build;
677
+ if (build === undefined) throw new Error('gated turn animation copy is unavailable');
678
+ const skeleton = join(build, 'skeleton.json'), atlas = join(build, 'skeleton.atlas');
679
+ const atlasText = readFileSync(atlas, 'utf8');
680
+ if (atlasText !== readFileSync(join(input.build, 'skeleton.atlas'), 'utf8')) throw new Error('turn copy atlas text differs from accepted build');
681
+ const candidate = api.loadCandidate({ skeletonText: readFileSync(skeleton, 'utf8'), atlasText, atlasDir: build, label: 'behind seams turn samples' }, { skeleton, atlas }, undefined);
682
+ if (candidate.pages.size !== accepted.pages.size || [...accepted.pages].some(([name, page]) => {
683
+ const other = candidate.pages.get(name);
684
+ return other === undefined || other.width !== page.width || other.height !== page.height || !Buffer.from(other.data).equals(Buffer.from(page.data));
685
+ })) throw new Error('turn copy decoded atlas pages differ from accepted build');
686
+ const observed = api.throughPoser(candidate.choice, poser => {
687
+ const opts = { geometry: true, texture: true };
688
+ const setup = api.sampleSetupPose(poser, opts)[0] ?? null;
689
+ if (setup === null || JSON.stringify(setup) !== JSON.stringify(acceptedSetup)) throw new Error('turn copy setup geometry differs from accepted build');
690
+ const poses: BehindSeamsTurnPose[] = [];
691
+ const frames = plan.poses.map((pose, index) => {
692
+ const name = behindTurnAnimationName(pose.name);
693
+ const samples = api.sampleAnimation(poser, name, input.fps, { ...opts, channels: true });
694
+ if (samples.length !== 1 || samples[0].time !== 0) throw new Error(`turn ${pose.name}: animation "${name}" does not supply exactly one t=0 sample`);
695
+ const frame = samples[0];
696
+ if (frame.channelError !== undefined || frame.channels === undefined) throw new Error(`turn ${pose.name}: dial channels unavailable`);
697
+ const observed_values: Record<string, number> = {}, slider_times: Record<string, number> = {};
698
+ for (const dial of plan.dials) {
699
+ const property = dial.field === 'rotation' ? 'rotate' : `translate.${dial.field}`;
700
+ const local = frame.channels.filter(c => JSON.stringify(c.path) === JSON.stringify(['bone', dial.bone, property]));
701
+ const want = pose.values[dial.bone];
702
+ // The compiler stores float32 keys; compare at that declared precision.
703
+ if (local.length !== 1 || !Number.isFinite(local[0].value) || Math.fround(local[0].value) !== Math.fround(want)) throw new Error(`turn ${pose.name}: dial "${dial.bone}" did not reach planned local ${want}`);
704
+ observed_values[dial.bone] = local[0].value;
705
+ const slider = (Array.isArray(input.rig.constraints) ? input.rig.constraints : []).filter(record).find(c => c.type === 'slider' && c.bone === dial.bone);
706
+ const times = frame.channels.filter(c => JSON.stringify(c.path) === JSON.stringify(['slider', slider?.name, 'mapped-time']));
707
+ if (times.length !== 1 || !Number.isFinite(times[0].value)) throw new Error(`turn ${pose.name}: slider on "${dial.bone}" has no finite mapped-time observation`);
708
+ slider_times[String(slider!.name)] = times[0].value;
709
+ }
710
+ poses.push({ ...pose, observed_values, slider_times });
711
+ return { ...frame, index, time: 0 };
712
+ });
713
+ const rest = poser.rest(undefined, [setup.attachments ?? [], ...frames.map(f => f.attachments ?? [])]);
714
+ return { poses, frames, setup, rest };
715
+ });
716
+ if (observed.poser !== acceptedPoser) throw new Error(`turn copy poser "${observed.poser}" differs from accepted "${acceptedPoser}"`);
717
+ const { poses, frames, setup, rest } = observed.value;
718
+ const sources = sourceProblems(input.rig, [setup, ...frames]);
719
+ if (sources.length > 0) throw new Error(sources.join('; '));
720
+ const pairs = input.pairs.filter(p => p.unread === undefined);
721
+ const stock = seamsOf(pairs, rest, frames.map(f => ({ ...f, attachments: f.attachments ?? [] })), candidate.pages, {},
722
+ { cells: setupCellReader(() => setup.pieces, candidate.pages) }).map((read, i) => ({ pair: pairs[i].pair,
723
+ frames: frames.length, drawn: read.drawn, banded: read.banded,
724
+ gapCovered: read.gapCovered.frames.map(hit => ({ index: hit.index, time: hit.time, cell: hit.cell, cells: hit.cells ?? [] })) }));
725
+ return { poses, frames, setup, rest, stock, sourceSkeletonSha256: empty.sourceSkeletonSha256, poser: observed.poser };
726
+ } catch (e) { return { ...empty, reason: `official turn copy unread: ${e instanceof Error ? e.message : String(e)}` }; }
727
+ }
728
+
492
729
  function jsonAt(path: string): Record<string, unknown> {
493
730
  const value: unknown = JSON.parse(readFileSync(path, 'utf8'));
494
731
  if (!record(value)) throw new Error('required sidecar is not an object');
@@ -555,7 +792,14 @@ function sourceProblems(rig: Record<string, unknown>, frames: readonly Frame[]):
555
792
  export function measureBehindSeams(api: typeof import('@rig-c/core/render-shared'), input: BehindSeamsInput, declared: BehindSeams, problems: Problem[]): BehindSeamsMeasured {
556
793
  const empty: BehindSeamsFramesInput = { pairs: input.pairs, setup: null, idle: [], rest: [], pages: new Map(), stock: null, fps: input.fps };
557
794
  const active = declared.threshold !== undefined || declared.pairs?.some(p => p.threshold !== undefined) === true;
558
- if (!active) return measureBehindSeamFrames(api, empty, declared, problems);
795
+ if (!active) {
796
+ if (declared.turn === true) {
797
+ const plan = behindTurnPlan(input.rig);
798
+ empty.turn = { poses: plan.poses, frames: [], setup: null, rest: [], stock: null,
799
+ reason: plan.reason ?? 'no authored threshold T; turn samples are not measured, never a pass' };
800
+ }
801
+ return measureBehindSeamFrames(api, empty, declared, problems);
802
+ }
559
803
  const fail = (reason: string): BehindSeamsMeasured => {
560
804
  const line = measureBehindSeamFrames(api, empty, declared, problems);
561
805
  line.status = 'FAIL';
@@ -566,16 +810,19 @@ export function measureBehindSeams(api: typeof import('@rig-c/core/render-shared
566
810
  if (input.unsupported !== undefined) return fail(input.unsupported);
567
811
  let candidate: ReturnType<typeof api.loadCandidate>;
568
812
  let sampled: { setup: Frame | null; idle: Frame[]; rest: AttachmentRest[] };
813
+ let acceptedPoser: string;
569
814
  try {
570
815
  const skeleton = join(input.build, 'skeleton.json'), atlas = join(input.build, 'skeleton.atlas');
571
816
  candidate = api.loadCandidate({ skeletonText: readFileSync(skeleton, 'utf8'), atlasText: readFileSync(atlas, 'utf8'), atlasDir: input.build, label: 'behind-part seams' }, { skeleton, atlas }, undefined);
572
- sampled = api.throughPoser(candidate.choice, p => {
817
+ const observed = api.throughPoser(candidate.choice, p => {
573
818
  const opts = { geometry: true, texture: true };
574
819
  const setup = api.sampleSetupPose(p, opts)[0] ?? null;
575
820
  const idle = p.animations.some(a => a.name === 'idle') ? api.sampleAnimation(p, 'idle', input.fps, opts) : [];
576
821
  const rest = p.rest(undefined, [...(setup?.attachments === undefined ? [] : [setup.attachments]), ...idle.map(f => f.attachments ?? [])]);
577
822
  return { setup, idle, rest };
578
- }).value;
823
+ });
824
+ sampled = observed.value;
825
+ acceptedPoser = observed.poser;
579
826
  const sources = sourceProblems(input.rig, [...(sampled.setup === null ? [] : [sampled.setup]), ...sampled.idle]);
580
827
  if (sources.length > 0) return fail(sources.join('; '));
581
828
  } catch (e) { return fail(`official renderer/source unavailable: ${e instanceof Error ? e.message : String(e)}`); }
@@ -584,7 +831,8 @@ export function measureBehindSeams(api: typeof import('@rig-c/core/render-shared
584
831
  if (input.stockDir === null || sampled.setup === null) throw new Error('existing full stock seam render/setup is unavailable');
585
832
  stock = stockOf(input.stockDir, input.pairs.filter(p => p.unread === undefined), input.fps, sampled.setup, sampled.idle, sampled.rest);
586
833
  } catch (e) { stockError = e instanceof Error ? e.message : String(e); }
587
- const line = measureBehindSeamFrames(api, { ...sampled, pairs: input.pairs, pages: candidate.pages, stock, fps: input.fps }, declared, problems);
834
+ const line = measureBehindSeamFrames(api, { ...sampled, pairs: input.pairs, pages: candidate.pages, stock, fps: input.fps,
835
+ ...(declared.turn === true ? { turn: sampleBehindTurn(api, input, candidate, sampled.setup, acceptedPoser) } : {}) }, declared, problems);
588
836
  if (stockError !== null) {
589
837
  line.status = 'FAIL';
590
838
  line.unmeasured.push({ ...checkRow('BEHIND_PART_SEAMS.unmeasured', 'rig', true, []), pair: null, frame: 'stock render', reason: `HOLE: ${stockError}` });
@@ -607,6 +855,11 @@ export function behindSeamLines(line: BehindSeamsMeasured | null): string[] {
607
855
  const setupStanding = setup === null ? '' : setup.standing.px > 0 && setup.standing.status === 'SKIP' ? `${setup.standing.px} cells` : `${setup.standing.status}, ${setup.standing.px} cells`;
608
856
  return [summary('motion_opened'), summary('standing'), `${BEHIND_SEAM_LINE}: pair "${p.pair}" setup ${setup === null ? 'SKIP — HOLE: setup not read' : `standing ${setupStanding}; motion_opened ${setup.motion_opened.status}, ${setup.motion_opened.px} cells; behind [${setup.behind_slots.join(', ')}]`}`];
609
857
  }),
858
+ ...(line.turn === undefined ? [] : [
859
+ `${BEHIND_SEAM_LINE}: turn ${line.turn.status} — ${line.turn.poses.length} preselected endpoint/corner pose(s); ${line.turn.limitations}`,
860
+ ...line.turn.pairs.flatMap(p => p.frames.map(f => `${BEHIND_SEAM_LINE}: pair "${p.pair}" turn ${f.pose} — motion_opened ${f.motion_opened.status}, ${f.motion_opened.px} cells; standing ${f.standing.status}, ${f.standing.px} cells; threshold ${p.threshold}, allowance ${p.allowance}`)),
861
+ ...line.turn.unmeasured.map(u => `${BEHIND_SEAM_LINE}: ${u.pair === null ? 'rig' : `pair "${u.pair}"`} ${u.frame} SKIP — ${u.reason}`),
862
+ ]),
610
863
  ...line.unmeasured.map(u => {
611
864
  const target = u.pair === null ? 'rig' : `pair "${u.pair}"`;
612
865
  const pair = u.pair === null ? undefined : line.pairs.find(p => p.pair === u.pair);
package/src/check.ts CHANGED
@@ -8,7 +8,7 @@ import { readMaterialSources } from './cutmaterialio.ts';
8
8
  import { CUT_MATERIAL_LINE, checkJointMaterial, type MaterialLine } from './cutmaterial.ts';
9
9
  import { ART_JOINT_LINE, artJointLine, type ArtJointLine } from './artjoints.ts';
10
10
  import { BOUNDARY_COLOUR_LINE, BOUNDARY_COLOUR_UNMEASURED_CODE, BOUNDARY_COLOUR_UNMEASURED_SUFFIX, measureBoundaryColour, type BoundaryColourMeasured } from './boundarycolour.ts';
11
- import { BEHIND_SEAM_LINE, measureBehindSeams, type BehindSeamsMeasured } from './behindseams.ts';
11
+ import { BEHIND_SEAM_LINE, behindTurnAnimations, measureBehindSeams, type BehindSeamsMeasured } from './behindseams.ts';
12
12
  import { baseAnchorMoves, type AnchorRegion } from './baseanchor.ts';
13
13
  /**
14
14
  * The check stage: build a rig through rig-c, gate it under both
@@ -7477,10 +7477,46 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
7477
7477
  ...(set === undefined ? [] : ['--set skin binding is not measured']),
7478
7478
  ...(allSets ? ['--all-sets skin binding is not measured'] : []),
7479
7479
  ];
7480
- const behindSeams = behindDeclared === undefined ? null : measureBehindSeams(officialRenderer(), {
7481
- build: buildDir, rig: inp.rig, pairs: behindPairs, stockDir: behindStockDir, fps: IDLE_FPS,
7482
- ...(behindUnsupported.length === 0 ? {} : { unsupported: behindUnsupported.join('; ') }),
7483
- }, behindDeclared, problems);
7480
+ let behindSeams: BehindSeamsMeasured | null = null;
7481
+ if (behindDeclared !== undefined) {
7482
+ const turnDir = join(out, '_behind_seams_turn');
7483
+ let turnScratch = false;
7484
+ let turnBuild: { build?: string; reason?: string } | undefined;
7485
+ try {
7486
+ const active = behindDeclared.threshold !== undefined || behindDeclared.pairs?.some(p => p.threshold !== undefined) === true;
7487
+ if (behindDeclared.turn === true && active && behindUnsupported.length === 0) {
7488
+ const animations = behindTurnAnimations(inp.rig);
7489
+ if (Object.keys(animations).length > 0) {
7490
+ const original = inp.motion.animations;
7491
+ if (original === null || typeof original !== 'object' || Array.isArray(original)) turnBuild = { reason: 'turn copy requires the accepted motion animation record' };
7492
+ else if (Object.keys(animations).some(name => Object.hasOwn(original, name))) turnBuild = { reason: 'turn sample animation name collides with an accepted animation; no animation is replaced' };
7493
+ else {
7494
+ try {
7495
+ turnScratch = true;
7496
+ rmSync(turnDir, { recursive: true, force: true });
7497
+ mkdirSync(turnDir, { recursive: true });
7498
+ const images = typeof inp.rig.images === 'string' ? resolve(inp.rigDir, inp.rig.images) : inp.rig.images;
7499
+ // Keep setup, constraints and sliders; append only the pose timelines.
7500
+ writeFileSync(join(turnDir, 'rig.json'), JSON.stringify({ ...inp.rig, images }));
7501
+ writeFileSync(join(turnDir, 'motion.json'), JSON.stringify({ ...inp.motion, animations: { ...original, ...animations } }));
7502
+ const build = join(turnDir, 'build');
7503
+ const built = rigc(['build', '--rig', join(turnDir, 'rig.json'), '--motion', join(turnDir, 'motion.json'), '--out', build, ...packedBuildArgs(mode)]);
7504
+ const errors = buildGateLines(built.out).filter(line => line.includes('FAIL') || line.includes('compile error'));
7505
+ const detail = (errors.length > 0 ? errors.join('; ') : built.out.trim() || 'no gate diagnostic returned').slice(0, 1200);
7506
+ turnBuild = built.status === 0 ? { build } : { reason: `gated turn copy build refused (exit ${built.status}): ${detail}; no turn sample is available` };
7507
+ } catch (e) { turnBuild = { reason: `gated turn copy unavailable: ${e instanceof Error ? e.message : String(e)}` }; }
7508
+ }
7509
+ }
7510
+ }
7511
+ behindSeams = measureBehindSeams(officialRenderer(), {
7512
+ build: buildDir, rig: inp.rig, pairs: behindPairs, stockDir: behindStockDir, fps: IDLE_FPS,
7513
+ ...(turnBuild === undefined ? {} : { turnBuild }),
7514
+ ...(behindUnsupported.length === 0 ? {} : { unsupported: behindUnsupported.join('; ') }),
7515
+ }, behindDeclared, problems);
7516
+ } finally {
7517
+ if (turnScratch) rmSync(turnDir, { recursive: true, force: true });
7518
+ }
7519
+ }
7484
7520
 
7485
7521
  // 5. the scene's declared requirements (issue #93), only under --requirements
7486
7522
  const reqProblems: Problem[] = [];
package/src/checkrow.ts CHANGED
@@ -9,14 +9,21 @@ export const CHECK_ROW_PATHS = {
9
9
  'ART_JOINT_DISTANCE.joints': ['ART_JOINT_DISTANCE.joints'],
10
10
  'BOUNDARY_COLOUR_STEP.over': ['BOUNDARY_COLOUR_STEP.over'],
11
11
  'BOUNDARY_COLOUR_STEP.unmeasured': ['BOUNDARY_COLOUR_STEP.unmeasured'],
12
+ 'BEHIND_PART_SEAMS.turn.pairs': ['BEHIND_PART_SEAMS.turn.pairs'],
13
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames': ['BEHIND_PART_SEAMS.turn.pairs[].frames'],
14
+ 'BEHIND_PART_SEAMS.turn.unmeasured': ['BEHIND_PART_SEAMS.turn.unmeasured'],
12
15
  'BEHIND_PART_SEAMS.pairs': ['BEHIND_PART_SEAMS.pairs'],
13
16
  'BEHIND_PART_SEAMS.pairs[].setup': ['BEHIND_PART_SEAMS.pairs[].setup'],
14
17
  'BEHIND_PART_SEAMS.pairs[].frames': ['BEHIND_PART_SEAMS.pairs[].frames'],
15
18
  'BEHIND_PART_SEAMS.samples': [
19
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].standing.samples',
20
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].motion_opened.samples',
16
21
  'BEHIND_PART_SEAMS.pairs[].setup.motion_opened.samples', 'BEHIND_PART_SEAMS.pairs[].setup.standing.samples',
17
22
  'BEHIND_PART_SEAMS.pairs[].frames[].motion_opened.samples', 'BEHIND_PART_SEAMS.pairs[].frames[].standing.samples',
18
23
  ],
19
24
  'BEHIND_PART_SEAMS.contributors': [
25
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].standing.samples[].contributors',
26
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].motion_opened.samples[].contributors',
20
27
  'BEHIND_PART_SEAMS.pairs[].setup.motion_opened.samples[].contributors', 'BEHIND_PART_SEAMS.pairs[].setup.standing.samples[].contributors',
21
28
  'BEHIND_PART_SEAMS.pairs[].frames[].motion_opened.samples[].contributors', 'BEHIND_PART_SEAMS.pairs[].frames[].standing.samples[].contributors',
22
29
  ],
@@ -26,6 +33,7 @@ export const CHECK_ROW_PATHS = {
26
33
  ],
27
34
  'BEHIND_PART_SEAMS.spans': ['BEHIND_PART_SEAMS.pairs[].motion_opened.spans', 'BEHIND_PART_SEAMS.pairs[].standing.spans'],
28
35
  'BEHIND_PART_SEAMS.unread_corridors': [
36
+ 'BEHIND_PART_SEAMS.turn.pairs[].frames[].standing.unread_corridors',
29
37
  'BEHIND_PART_SEAMS.pairs[].setup.standing.unread_corridors',
30
38
  'BEHIND_PART_SEAMS.pairs[].frames[].standing.unread_corridors',
31
39
  ],