rig-parts 1.46.0 → 1.48.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/cli.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  import { spawnSync } from 'node:child_process';
15
15
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
16
16
  import { tmpdir } from 'node:os';
17
- import { basename, dirname, extname, join } from 'node:path';
17
+ import { basename, dirname, extname, join, resolve } from 'node:path';
18
18
  import { DEFAULT_PROJECT_RULE, DEFAULT_SEAM_RULE, HOLES_LISTED, PROJECT_RULES, type ProjectRule, proposeFields, proposePlan, proposeSinglePlan, SEAM_RULES, type SeamRule } from './src/assemble.ts';
19
19
  import { type AlternateCliInput, assembleStage, build, checkStage, ERROR_MAP_FILE, loopStage, readRuns, readSource, rigStage, suppliedCheckFlag } from './src/build.ts';
20
20
  import { ACCEPTABLE_BARS, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, findRigc, PACK_SHAPES, rigcRunnerAt, type PackShape, PAGE_EDGES, type PageEdges, PARTS_HOME_SENTENCE, RIGC_GEOMETRY_VERSION, rigcRanClause, type RigcRunner, NO_PARTS_SENTENCE, SEAM_MEAN_BAR, SOURCE_SENTENCE, SEAM_PX_BAR, SEAM_PX_LEVEL, SPINEBOY_YARDSTICK, TEXTURE_STRETCH_CEILING } from './src/check.ts';
@@ -29,7 +29,8 @@ import { depthSkipLine, exportLayers, figuresPhrase, hiddenLayerLine, implausibl
29
29
  import { checkImageSize, choosePerson, KEYPOINTS_SPEC, loadKeypoints, type RigJoints, toRigJoints } from './src/keypoints.ts';
30
30
  import { basisLines, branchSqueezeLine, checkProposal, compare, compareLines, DEFAULT_GRID_RULE, draftTurn, drawLandmarks, FIGURE_GRID_DIVISOR, FRINGE_STEP_PX, GRID_RULES, type GridRule, HIP_MIN_FRACTION, type DraftLintFinding, lint, lintLine, type PartSet, proposeWithBasis, readPartSet, serializeProposal, withTurn, WRIST_ON_PART_PX } from './src/propose.ts';
31
31
  import { BASIS_FILE, BASIS_SPEC, basisFile, basisLine, coverageLines, serializeBasis } from './src/diagnostics.ts';
32
- import { BEND_DEGREES, BEND_WORST_SHARE, DUST_MAX_PX, DUST_MAX_SHARE, IDLE_BOUND_PX, MESH_DRAFT_REPORT, MESH_DRAFT_SPEC, meshDraftStage, MORE_TRIANGLES_FLAG, TOLERANCE_FIGURE_DIVISOR } from './src/meshdraft.ts';
32
+ import { BEND_DEGREES, BEND_WORST_SHARE, DUST_MAX_PX, DUST_MAX_SHARE, IDLE_BOUND_PX, MESH_DRAFT_REPORT, MESH_DRAFT_SPEC, meshDraftStage, MORE_TRIANGLES_FLAG, relativeConfigPaths, TOLERANCE_FIGURE_DIVISOR } from './src/meshdraft.ts';
33
+ import { clothConfigEdits, editPaths, writtenClothConfig } from './src/clothconfig.ts';
33
34
  import { PROVENANCE_FILE, REMESH_SPEC, remeshStage } from './src/remesh.ts';
34
35
  import { RETUNE_FILE, RETUNE_SPEC, retuneStage } from './src/retune.ts';
35
36
  import { checkPainting } from './src/paintcheck.ts';
@@ -225,6 +226,22 @@ usage:
225
226
  a LINT line names each drafted radius and both figures. Without --cloth
226
227
  nothing changes.
227
228
 
229
+ rig-parts propose … --cloth <config.json> [--write-config <out.json>]
230
+ Also write the --cloth config's own text with what the recipe drafts
231
+ spliced in (issue #537), the way mesh-draft writes its config, so that
232
+ rig --config <out.json> builds it. What is spliced is measured: the
233
+ same parts drafted again without the recipe, and each config section
234
+ that differs — bones and constraints whole (a hand-added bone does not
235
+ survive), meshes.<part>, regions.<part> and motion.tracks entry by
236
+ entry; a section the input lacks is inserted; every other byte as
237
+ read. The text is written as stated, so a relative path in it
238
+ resolves against <out.json>'s directory (a note names each when that
239
+ is not the input's). Only with --cloth and not with --from-config
240
+ (usage errors); refused, before anything is written, when <out.json>
241
+ exists or is a file this run writes (PROPOSE_WRITE_CONFIG_FRESH), or
242
+ when the spliced text does not parse to the config with the sections
243
+ set, naming the first key that moved (PROPOSE_WRITE_CONFIG_SPLICE).
244
+
228
245
  rig-parts propose --parts <dir> --source <painting.png> --out <dir> --from-config <config.json>
229
246
  Draw the config's CURRENT bones instead (<out>/render/landmarks_config.png
230
247
  and _head) and LINT them (by the joints too, given --keypoints), with the
@@ -412,7 +429,7 @@ usage:
412
429
  rig-parts check --rig <dir> --out <dir> [--parts <dir>] [--source <painting.png>]
413
430
  [--page-edges pot|free] [--pack-shape rect|polygon]
414
431
  [--requirements <file.json>] [--seam-pairs] [--keep-stills]
415
- [--set <name> | --all-sets]
432
+ [--set <name> | --all-sets] [--environment <schedule.json>]
416
433
  Build, gate, render and measure a rig through rig-c's CLI (the rigc at
417
434
  node_modules/.bin/rigc, or on PATH). --rig holds rig.json and motion.json:
418
435
  a rig spec, which rigc build compiles, not a compiled skeleton.json.
@@ -530,6 +547,29 @@ usage:
530
547
  follow no frame of which reaches its least drive) is
531
548
  CHECK_REQUIREMENT_MEASURABLE, and the run is not PASS. Without the flag
532
549
  nothing is read, written or printed for it.
550
+ --environment <schedule.json> takes the readings in the world a person
551
+ watched: a rigc-environment/1 schedule ({ "spec": "rigc-environment/1",
552
+ "steps": [{ "t": <seconds>, "wind"?: [x, y], "gravity"?: [x, y] }, ...] },
553
+ x right, y down — what rigc render --environment reads, and what the
554
+ review editor exports). It is read once, by rig-c's own reader, before
555
+ anything is built; a malformed one, or a path with nothing at it, is
556
+ refused, CHECK_ENVIRONMENT, rigc's sentence verbatim, and --out is not
557
+ written. Every render a bar or a warning reads with the physics on is
558
+ posed under it — the idle (TIP_OVER_ROOT, STILL_REGIONS_DARK,
559
+ TEXTURE_STRETCH, CLOTH_SETTLES), the physics-on half of
560
+ ANIMATIONS_DO_NOT_FOLD, the parts BREATH_VISIBLE renders alone,
561
+ SEAM_OVER_MOTION and the --requirements renders; the physics-off renders
562
+ (the loop's, the fold bar's other half, STRESS_OFF_CHAIN,
563
+ SEAM_OVER_RANGE), the setup-pose stills and build's loop take none. What
564
+ rigc render refuses of the schedule on this rig (no physics constraint,
565
+ a half no constraint answers, a step after the last frame) is
566
+ CHECK_ENVIRONMENT with rigc's line. The world before the first step is
567
+ the runtime's, wind [1, 0] and gravity [0, 1]: a schedule stating that
568
+ reads what a run without the flag reads, and wind [0, 0] is a calm, not
569
+ the default (AUTHORING §6, The world the readings are taken in). One
570
+ environment: line names the path, the step count and the sha256's first
571
+ 16 hex; check.json's environment holds path (as given), sha256 and
572
+ steps. Without the flag no key and no render argument moves.
533
573
 
534
574
  rig-parts loop --frames <dir> --out <file.png | file.gif> [--palette]
535
575
  Encode a frame set rigc render wrote (its --out directory, or the set
@@ -646,6 +686,7 @@ usage:
646
686
  [--pack-shape rect|polygon] [--loop] [--requirements <file.json>]
647
687
  [--idle-keys ctl|direct] [--lead-in <periods>] [--seam-pairs] [--keep-stills]
648
688
  [--alt <name>=<source>:<full>[:<head>]] [--set <name> | --all-sets]
689
+ [--environment <schedule.json>]
649
690
  assemble, then rig, then check, in one process, each stage's own lines
650
691
  printed under [assemble], [rig] and [check]; the first stage that refuses
651
692
  stops the build with its own FAIL lines. The config must already carry
@@ -668,6 +709,9 @@ usage:
668
709
  and check's artifact, take them). --requirements is forwarded to check
669
710
  (as for check); the file's own shape is read before assemble runs, and
670
711
  its names resolve against the rig in the check, before it builds.
712
+ --environment is forwarded to check (as for check); the schedule is read
713
+ by rig-c's reader before assemble runs, so a malformed one is refused,
714
+ CHECK_ENVIRONMENT, under [assemble] before anything is assembled.
671
715
  --seam-pairs and --keep-stills are forwarded to check (as for check:
672
716
  the seam split by pair on a pass too, under check/seam/; the setup-pose
673
717
  still under check/setup_still/). check's --rig and --parts are refused:
@@ -861,15 +905,15 @@ const TAKES = {
861
905
  layers: { valued: ['--export', '--template', '--canvas'], switches: [] },
862
906
  sheet: { valued: ['--source', '--layers', '--out', '--cell', '--cols'], switches: [] },
863
907
  rig: { valued: ['--config', '--parts', '--out', '--idle-keys', '--page-edges', '--pack-shape'], switches: [] },
864
- propose: { valued: ['--parts', '--source', '--out', '--from-config', '--compare', '--full', '--head', '--canvas', '--keypoints', '--person', '--wrist-snap', '--grid-rule', '--cloth'], switches: ['--head-box', '--no-back-hair'] },
908
+ propose: { valued: ['--parts', '--source', '--out', '--from-config', '--compare', '--full', '--head', '--canvas', '--keypoints', '--person', '--wrist-snap', '--grid-rule', '--cloth', '--write-config'], switches: ['--head-box', '--no-back-hair'] },
865
909
  compare: { valued: ['--left', '--right', '--map'], switches: [] },
866
- check: { valued: ['--rig', '--out', '--parts', '--source', '--page-edges', '--pack-shape', '--requirements', '--set'], switches: ['--seam-pairs', '--keep-stills', '--all-sets'] },
910
+ check: { valued: ['--rig', '--out', '--parts', '--source', '--page-edges', '--pack-shape', '--requirements', '--set', '--environment'], switches: ['--seam-pairs', '--keep-stills', '--all-sets'] },
867
911
  loop: { valued: ['--frames', '--out'], switches: ['--palette'] },
868
912
  assemble: { valued: ['--source', '--full', '--head', '--config', '--out', '--seam', '--project', '--alt'], switches: ['--propose-plan'] },
869
913
  'comfy seethrough': { valued: ['--image', '--out', '--resolution', '--steps', '--seed', '--prefix', '--host', '--wait', '--timeout', '--poll'], switches: ['--offload', '--lama', '--nf4'] },
870
914
  'comfy paint': { valued: ['--config', '--out', '--seeds', '--seed0', '--host', '--wait', '--timeout', '--poll'], switches: [] },
871
915
  inputs: { valued: ['--source', '--config', '--out'], switches: [] },
872
- build: { valued: ['--config', '--source', '--full', '--head', '--out', '--seam', '--project', '--page-edges', '--pack-shape', '--requirements', '--idle-keys', '--lead-in', '--alt', '--set'], switches: ['--loop', '--seam-pairs', '--keep-stills', '--all-sets'] },
916
+ build: { valued: ['--config', '--source', '--full', '--head', '--out', '--seam', '--project', '--page-edges', '--pack-shape', '--requirements', '--idle-keys', '--lead-in', '--alt', '--set', '--environment'], switches: ['--loop', '--seam-pairs', '--keep-stills', '--all-sets'] },
873
917
  compose: { valued: ['--scene', '--out', '--requirements', '--accept'], switches: [] },
874
918
  'mesh-draft': { valued: ['--config', '--parts', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape'], switches: ['--more-triangles'] },
875
919
  remesh: { valued: ['--rig', '--config', '--parts', '--part', '--mesh', '--delta', '--out', '--requirements', '--idle-keys', '--page-edges', '--pack-shape'], switches: [] },
@@ -1140,7 +1184,7 @@ function cmdCheck(args: string[]): number {
1140
1184
  try {
1141
1185
  const bin = findRigc(import.meta.dir, process.env.PATH ?? '');
1142
1186
  const r = checkStage(
1143
- { rig, parts: f.get('--parts'), source: f.get('--source'), out, pageEdges: edges, packShape: shape, requirements: f.get('--requirements'), seamPairs: seamPairs === 1, keepStills: keepStills === 1, ...(f.has('--set') ? { set: f.get('--set') as string } : {}), allSets: allSets === 1 },
1187
+ { rig, parts: f.get('--parts'), source: f.get('--source'), out, pageEdges: edges, packShape: shape, requirements: f.get('--requirements'), seamPairs: seamPairs === 1, keepStills: keepStills === 1, ...(f.has('--set') ? { set: f.get('--set') as string } : {}), allSets: allSets === 1, ...(f.has('--environment') ? { environment: f.get('--environment') as string } : {}) },
1144
1188
  rigcRunner(bin),
1145
1189
  bin,
1146
1190
  console.log,
@@ -1258,6 +1302,16 @@ function cmdPropose(args: string[]): number {
1258
1302
  // Issue #364: the cloth and hair recipe, read from a config's cloth block; without it nothing changes.
1259
1303
  const clothArg = flags.get('--cloth');
1260
1304
  if (clothArg !== undefined && flags.has('--from-config')) return usage('--cloth drafts trees while proposing; --from-config proposes nothing');
1305
+ // Issue #537: the --cloth config's own text with what its recipe drafts spliced in, beside proposal.json.
1306
+ const writeArg = flags.get('--write-config');
1307
+ if (writeArg !== undefined && flags.has('--from-config')) return usage('--write-config writes what the recipe drafts into its config; --from-config proposes nothing');
1308
+ if (writeArg !== undefined && clothArg === undefined) return usage('--write-config writes the --cloth config with what its recipe drafts spliced in; give --cloth <config.json>');
1309
+ if (writeArg !== undefined) {
1310
+ const ours = ['proposal.json', BASIS_FILE].map((f) => resolve(out, f));
1311
+ if (existsSync(writeArg) || ours.includes(resolve(writeArg))) {
1312
+ throw new PartsError([{ code: 'PROPOSE_WRITE_CONFIG_FRESH', object: writeArg, detail: existsSync(writeArg) ? 'exists; the config is written to a new file, never over the --cloth config or an earlier one' : `is a file this run writes under ${out}; name another file` }]);
1313
+ }
1314
+ }
1261
1315
  const cloth = clothArg === undefined ? null : loadClothConfig(clothArg).cloth;
1262
1316
  const partsDir = existsSync(partsArg) && statSync(partsArg).isFile() ? dirname(partsArg) : partsArg;
1263
1317
  if (!existsSync(source)) {
@@ -1295,6 +1349,15 @@ function cmdPropose(args: string[]): number {
1295
1349
  : withTurn(drafted, draftTurn(P, { ...(fullRun === undefined ? {} : { full: readLayers(fullRun) }), ...(headRun === undefined ? {} : { head: readLayers(headRun) }) }, drafted));
1296
1350
  // Emit only after green: a proposal the config loader would refuse is not written, nor a basis record that does not hold to it.
1297
1351
  checkProposal(P, prop);
1352
+ // Issue #537: the sections the recipe moves, measured against the same parts drafted without it, spliced before anything is written.
1353
+ const written =
1354
+ writeArg === undefined || clothArg === undefined
1355
+ ? null
1356
+ : (() => {
1357
+ const edits = clothConfigEdits(drafted, proposeWithBasis(P, joints, wristSnap, gridRule, null).proposal);
1358
+ const text = readFileSync(clothArg, 'utf8');
1359
+ return { at: writeArg, text: writtenClothConfig(clothArg, text, edits), paths: editPaths(edits), relative: relativeConfigPaths(dirname(resolve(clothArg)), JSON.parse(text) as Record<string, unknown>) };
1360
+ })();
1298
1361
  const bfile = basisFile(P, prop, basis, cfg === null || cmpPath === undefined ? null : { where: cmpPath, config: cfg });
1299
1362
  const img = drawLandmarks(P, painting, prop.bones, 'PROPOSAL - CORRECT ME');
1300
1363
  mkdirSync(render, { recursive: true });
@@ -1302,10 +1365,20 @@ function cmdPropose(args: string[]): number {
1302
1365
  writeFileSync(join(out, BASIS_FILE), serializeBasis(bfile));
1303
1366
  writePng(join(render, 'landmarks.png'), img.full);
1304
1367
  if (img.head !== null) writePng(join(render, 'landmarks_head.png'), img.head);
1368
+ if (written !== null) {
1369
+ mkdirSync(dirname(written.at), { recursive: true });
1370
+ writeFileSync(written.at, written.text);
1371
+ }
1305
1372
  console.log(`wrote proposal.json (${prop.bones.length} bone entries, ${Object.keys(prop.meshes).length} meshes) and render/landmarks.png (+_head) under ${out}`);
1306
1373
  for (const n of prop.notes) console.log(`note: ${n}`);
1307
1374
  printLint(P, prop, joints, draftLint);
1308
1375
  console.log(basisLine(bfile, out));
1376
+ if (written !== null && clothArg !== undefined) {
1377
+ console.log(`wrote ${written.at}: ${clothArg}'s text with ${written.paths.join(', ')} spliced in from the draft; every other byte as read`);
1378
+ if (written.relative.length > 0 && dirname(resolve(written.at)) !== dirname(resolve(clothArg))) {
1379
+ console.log(`note: ${written.relative.map((r) => `${r.at} "${r.value}"`).join(', ')} written as stated; the loader resolves each against the directory the config sits in, ${dirname(written.at)} for ${written.at}, not ${dirname(clothArg)}; put the config beside ${clothArg} or rewrite them`);
1380
+ }
1381
+ }
1309
1382
  if (cfg !== null) for (const l of compareLines(compare(prop.bones, cfg.bones))) console.log(l);
1310
1383
  return EXIT_OK;
1311
1384
  } catch (err) {
@@ -1612,7 +1685,7 @@ function cmdBuild(args: string[]): number {
1612
1685
  const scratch = mkdtempSync(join(tmpdir(), 'rig-parts-build-'));
1613
1686
  try {
1614
1687
  const r = build(
1615
- { config, source, full, head, out, seam: seam as SeamRule, project: project as ProjectRule, loop, pageEdges: edges, packShape: shape, ...(flags.has('--requirements') ? { requirements: flags.get('--requirements') as string } : {}), idleKeys: keys, ...(leadText === undefined ? {} : { leadIn: Number(leadText) }), seamPairs: on.has('--seam-pairs'), keepStills: on.has('--keep-stills'), ...(alts.length === 0 ? {} : { alts }), ...(flags.has('--set') ? { set: flags.get('--set') as string } : {}), allSets: on.has('--all-sets') },
1688
+ { config, source, full, head, out, seam: seam as SeamRule, project: project as ProjectRule, loop, pageEdges: edges, packShape: shape, ...(flags.has('--requirements') ? { requirements: flags.get('--requirements') as string } : {}), idleKeys: keys, ...(leadText === undefined ? {} : { leadIn: Number(leadText) }), seamPairs: on.has('--seam-pairs'), keepStills: on.has('--keep-stills'), ...(alts.length === 0 ? {} : { alts }), ...(flags.has('--set') ? { set: flags.get('--set') as string } : {}), allSets: on.has('--all-sets'), ...(flags.has('--environment') ? { environment: flags.get('--environment') as string } : {}) },
1616
1689
  { rig: rigcRunner(bin), check: rigcRunner(bin), checkBin: bin, scratch: join(scratch, 'rig-gate') },
1617
1690
  console.log,
1618
1691
  );
package/docs/AUTHORING.md CHANGED
@@ -128,7 +128,7 @@ read by no CPU stage).
128
128
  | `stops` | rig (handed to rig-c as `rig.json`'s `stops`, and moves slots, mesh weights and child bones on stopped links onto `<link>_d`); `propose --from-config` (`LINT stop on <chain> …`) | **authored**, optional (issues #404, #447): `[{chain, links?, against, at, inward, outward, lower?: {inward, outward}}]` — rig-c's leg stops (`RigStop`, rig-c 2.56.0, `rig-c/src/stop.ts`). `chain` is a chain `bones` declares (`CONFIG_NAME_RESOLVES`, `RIG_NAME_RESOLVES`); `links`, optional, is a non-empty list of links of that chain (`CONFIG_NAME_RESOLVES`, `CONFIG_FIELD_TYPE`), or absent for every link of `chain` in chain order; `against` is a bone `bones` declares, a chain link as `<chain><i>` (`CONFIG_NAME_RESOLVES`, `RIG_NAME_RESOLVES`); `at` is `[x, y]` in `against`'s local space, as rig-c's stop takes it (`CONFIG_FIELD_TYPE`): since each chain link (`leg_r0`, `leg_r1`) is turned to point along its segment (`+x` from origin to next link or tip, `+y` 90° counter-clockwise in Spine world), `at: [d, n]` sits `d` px from `against`'s origin toward its end and `n` px perpendicular to it; `inward`, `outward` and `lower.inward`, `lower.outward` are finite numbers (`CONFIG_FIELD_TYPE`). Every other stop rule — non-negative bounds, each stopped link written by a constraint, `against` not under the stopped chain, the aim not degenerate, `\|rest\| + outward <= 180°` (`RIG_STOP_BOUNDS`) — is rigc's to accept or refuse at the rig stage's gate, in rigc's words (`RIG_RIGC_GREEN`). **Rising-limb / prone geometry (issue #447):** rig-c's `expandStops` aims `<chain>_rest` from `links[0]`'s setup origin at `<chain>_touch` (`at` in `against`'s local frame) and clamps `<link>_d` inside `[rest − inward, rest + outward]`; Spine wraps rotation at `±180°`, so `\|rest\| + outward <= 180°` is required (`RIG_STOP_BOUNDS`). Whenever `<chain>_touch` lies **above** `links[0]`'s root in rig pixels (`ty < y0`, i.e. higher Spine `y` — e.g. stopping a hanging cloth chain against a rising shin `leg_<s1>` in a prone or kneeling pose where the knee sits below `links[0]` and the ankle above it, so positive `at[0]` walks upward along the shin past `links[0]`'s root), `rest` lands in the upper half-plane (`\|rest\| > 90°`) and `\|rest\| + outward` exceeds `180°`. Stop against the descending thigh (`leg_<s0>`), set `links` to start at a link whose root sits above `<chain>_touch`, or omit the stop when the rising shin sits outside the hanging chain's sweep; `propose --from-config` prints `LINT stop on <chain> …` with the exact coordinates and angles when `<chain>_touch` lies above `links[0]`'s root or `\|rest\| + outward > 180°`. For every stopped link `<link>`, the rig stage moves any slot on `<link>`, any mesh weight on `<link>`, and any bone whose parent is `<link>` (a branched cloth tree's branches hanging from `<trunk_last>`, before `--idle-keys ctl` adds `<bone>_ctl` and before `turn` adds `turn_<part>_<bone>`) onto `<link>_d`, the drawn link bone rig-c's `expandStops` creates at `<link>`'s setup frame to carry the clamped rotation. Absent, `rig.json` carries no `stops` and no byte of any output moves |
129
129
  | `turn` | rig (adds the turn control) | **proposed** only with `propose --full`/`--head` (issue #251), then corrected: `{pivot, depths, deform?, band?, radius?, surface?: {radius?}, head?: {pivot?, radius?}}`. `depths` holds, per part, the See-through layer's `depth_median` the part came from (larger = further back), read from the run the part was assembled from; a `painting:` patch has none and is not carried. A rider (issue #271) — a part from an `eyewhite`, `irides`, `eyelash`, `eyebrow`, `nose` or `mouth` layer — is drafted at the `face` part's depth, 0.001 nearer when parts.json draws it after the face and 0.001 further when before: See-through makes no depth of its own for the eye group (it cuts them from one depth map of the combined eyes) and clamps nose and mouth to the face's median − 0.001, and the two runs' own medians for these layers disagreed by up to 0.47 and swapped their order against the face. Every other layer — ears, headwear and earwear included — keeps its own median, unless it rides another part's bone. With no `face` part, or more than one, the riders keep their own and a note says so. A rider by bone (issue #535) — a part every *ownable* bone of which (a chain link, or a bone no other bone hangs from; `head`, `chest` and any bone with a child are shared and never count on their own) is *hosted* by another carried part, the host of a bone being the carried part that binds it (its region's bone; a mesh's `segments`, `contour` and `auto` regions' bones) with the most `opaque_px`, the earlier in parts.json on a tie, and which hosts no bone itself — is drafted at its host's depth, 0.001 nearer when drawn after the host and 0.001 further when before, and a note names the host, the bones and its own median: a pin, clip or ornament on the back hair's links travels with the back hair, not with its own layer's depth. `propose` reads the proposal's own `bones`, `meshes` and `regions`; the face riders are read by their tag first and never by their bones. A part bound to two hosts' bones rides neither and a note says so. In the rig stage, an authored depth on a rider by bone whose fraction differs from its host's by more than 0.1 of the dial (`TURN_RIDER_APART`, a share of `pivot − nearest`) is refused (`CONFIG_TURN_RIDER_DEPTH`); the host is read off `parts.json`'s `opaque_px`, so the config loader cannot see it. One note lists each part's depth and where it came from; a carrier the other run places more than 10 % of `pivot − nearest` away gets a note naming both values and the run read — the two runs are not reconciled. `pivot` is the depth that stays put; `propose` drafts the mean of the parts' depths weighted by `opaque_px`, the one depth at which the painted pixels' centroid does not slide under the dial. The rig stage adds a bone `turn` under `root` at its origin that nothing keys — its local x is the dial, in rig px — and carries each part by `(pivot − depth) / (pivot − nearest depth)` of it: the nearest part all of it, a part behind the pivot the other way, a part at the pivot not at all. Each part rides leaf twins (`turn_<part>_<bone>`, an identity child of every bone its slot and weights bind) moved by one `transform` constraint (`turn_<part>`, after the config's own); the idle's keys, the `<bone>_ctl` controls and a physics constraint stay on the bones, and the dial moves none of them. Optional `deform` (`Partial<FaceDeformFractions>`, issue #436) overrides the Set B ×2.5 face surface deformation table (`FACE_DEFORM_FRACTIONS`, checked against `FACE_DEFORM_RANGES` by `CONFIG_TURN_DEFORM_RANGE`); when `applyFaceSurfaceDeform` runs on a rig whose `motion` carries `tilt` or `turn` slider `derive` keys, it requires `config.turn` (`CONFIG_TURN_REQUIRED`, issue #478; `propose --full`/`--head` drafts it), promotes `face` on `head` (or `turn_face_head` when `turn` is declared) to the uneven 5×5 grid mesh, keys `face`, `hair_front` and `hair_back` deform timelines and ear/topknot tracks from `evalPitchFaceSurface` and `evalYawFaceSurface`, and samples the same deform field across each `features` member's rest span (`featRx = (24 / 106) · W`, `featRy = (12 / 128) · H`) with its depth fraction `z / zRef` as the field's angle input and chord foreshortening (`scalex` narrowing on the leading side and widening on the trailing side, `scaley` on pitch) so every feature's bounding box stays inside the deformed face plate across the rated band (issue #468). On yaw (`issue #479`), `evalYawFaceSurface` evaluates a **cylinder projection** (`cylinderYawDx`: `Δx(x, θ, R) = R · (sin(clamp(arcsin(clamp(x / R, −1, 1)) − θ, −π/2, π/2)) − clamp(x / R, −1, 1))`) of radius `R` (`turnSurfaceRadius`: `turn.surface.radius ?? turn.radius ?? turn.head.radius`, positive rig px checked by `CONFIG_FIELD_TYPE`, defaulting to half the face plate's opaque width `W / 2`) tapered by a cubic Hermite outline weight (`wOutline = 1` for `\|ux\| <= 0.7`, reaching `0` at `\|ux\| = 1.0`) so features slide across a fixed outline (`iris` shift within `±2%` of `cylinderYawDx`), the trailing cheek strip widens (`>= 1.54×` at `±15°`), and the leading jaw edge holds fixed (`0 px` shift) unless explicit horizontal `turn.deform` overrides (`turn_mid_x`, `turn_lead_compress_x`, `turn_trail_shift_x`) request the flat yaw table. On yaw (`issue #478`), `applyFaceSurfaceDeform` also derives a **head-only pivot** (`headTurnPivot`: `turn.head.pivot` when authored, otherwise the `opaque_px`-weighted mean of `depths[part]` across the head parts `DEFAULT_HEAD_TURN_PARTS` — `face`, `hair_front`, `hair_back`, `ear_r`, `ear_l`, `hairpin` — from `parts.json`, falling back to `turn.pivot`) so a forward torso or arm in `turn.depths` does not pull the head's rotation axis in front of `face`: `hair_back` (`depth_median > headPivot`, negative `headTurnFraction`) and `hairpin` behind `headPivot` translate opposite to the face's turn (`dx = s · turn_face_center_x · W · (headPivot − depth) / (headPivot − nearestHeadDepth)`), emerging on the trailing side to compensate for the leading-cheek foreshortening and keeping the combined head silhouette width near-constant across `±15°` without any same-sign `turn_hair_back_cheek_x` term. Optional `band` (`number` or `{yaw?, pitch?}`, positive degrees, issue #472) declares the rig's rated face turn band (default `FACE_RATED_BAND`: `yaw <= 15°`, `pitch <= 12°`); declaring a `turn.band` or a `motion.animations_from` `turn`/`tilt` `derive.degrees` above `±15°` yaw or `±12°` pitch without an `assemble.alternates` entry that replaces `face` is refused (`CONFIG_FACE_BAND_EXCEEDED`), and on a single-plate rig `applyFaceSurfaceDeform` adds self-targeting transform constraints `yaw_clamp` (`[-15, 15]`) and `pitch_clamp` (`[-12, 12]`) ahead of the slider constraints so driving `yaw` or `pitch` beyond the rated band clamps at the boundary. At rest: with `turn` declared, no pixel differs by more than 1 level at dial 0 (not byte-identical; the cause is float noise in the identity child bones, and the constraints add nothing); without `turn`, byte-identical. Neither `pivot` nor `depths` has a default (`CONFIG_FIELD_PRESENT`); `pivot` and `head.pivot` must lie behind the nearest part (`CONFIG_TURN_PIVOT_BEHIND_NEAREST`). Absent, no control is added and no byte of any output moves |
130
130
  | `scene` | assemble (the recomposite, its holes and the figure's mask); check, through `parts.json`'s `scene` block (`RECOMPOSITE_HOLES`, the seam) | **authored**, optional; `propose` writes none (issue #242). `{}` declares the painting a scene: the figure and its surroundings in one image, See-through's full run holding only the figure. With it, `assemble` reads the recomposite figures, the hole list and the `uncovered:` lines inside the figure — the rig pixels where any full-run layer's alpha is above 8 (`OPAQUE_ALPHA_ABOVE`, the cut every layer's painted pixels are read by) — each line starting `inside the figure (config.scene: …, <n> of <m> rig px)`; writes that figure as `figure_rig.png` (white on black) beside the recomposite, and a `scene` block in `parts.json`; flags error pixels on the error map inside it only (outside, the painting grey); and `check` leaves out of the seam every frame pixel whose composite sample reaches the painting's outermost row or column, saying how many (`seam_border` in `check.json`, and on the seam line). It takes no field: the figure and its threshold are derived. A key in it other than a record or an annotation is `CONFIG_KEY_KNOWN`. Absent, no byte of any output moves |
131
- | `cloth` | `propose --cloth` only; no other stage reads it, so it moves no byte of any build | **authored**, optional (issue #364): one recipe per tag, `{"bottomwear": {…}, "back hair": {…}, "front hair": {…}}`, each `{chains, links, wind, gravity, split?, length_ratio?, strength?, damping?, alternate_damping?, translate?, swing?, part?, influence?}`. `influence` (issue #518) — `{across, max, shape, radius?}`: the parts this recipe meshes are drafted in the influence mode (`meshes.<part>.influence` above) at their lattice's cell, with `across`, `max` and `shape` as declared (each required — the reading behind the radius did not vary them) and `radius` as declared or, absent, drafted as the farthest vertex's distance plus 3 cells (the `influence.radius` row); without it the parts keep their lattice. `chains` — trees across the piece (for `back hair`, per side of the eye axis), a whole number, 1 or more; `links` — links from root to tip on every path, 1 or more; `split` — `{at, into}`: the first `at` links are the trunk, which forks into `into` (2 or more) branches; `at` below `links` (`CONFIG_CLOTH_SPLIT_BEFORE_TIP`); `length_ratio` — a path's last link over its first, above 0, default 0.5; `strength` — `{trunk, branch, edge}`, each above 0 and below the spring's stability bound (`CONFIG_CLOTH_SPRING_STABLE`), default 100 / 100 / 50; `damping` — in [0, 1], absent: rig-c's default; `alternate_damping` — the odd trees' damping, in [0, 1], beside `damping` and different from it (`CONFIG_CLOTH_ALTERNATE_DIFFERS`); `wind`, `gravity` — `[root, tip]`, each 0 or more, tip at or above root (`CONFIG_CLOTH_RESPONSE_GROWS_TO_TIP`); `translate` — the x and y mix of a dangling end's flutter, above 0 and at most 1; `swing` — `bottomwear` only, `{scales}`, one positive scale per tree (`CONFIG_CLOTH_SWING_SCALE_PER_TREE`); `part` — `bottomwear` only (`CONFIG_CLOTH_PART_ON_BOTTOMWEAR`), a non-empty part or cut-piece name: the `topwear` part that holds a skirt See-through returned inside it (a dress), or its skirt piece cut by `assemble.cuts`, which takes the skirt's trees (issue #402, *A skirt inside topwear* below; the part is checked by `propose`, `PROPOSE_CLOTH_PART`). The two defaults are the recipe's own, measured on its synthetic fixture (the recipe below). The recipe below says what each field drafts |
131
+ | `cloth` | `propose --cloth` only; no other stage reads it, so it moves no byte of any build | **authored**, optional (issue #364): one recipe per tag, `{"bottomwear": {…}, "back hair": {…}, "front hair": {…}}`, each `{chains, links, wind, gravity, split?, length_ratio?, strength?, damping?, alternate_damping?, translate?, swing?, part?, influence?}`. `influence` (issue #518) — `{across, max, shape, radius?}`: the parts this recipe meshes are drafted in the influence mode (`meshes.<part>.influence` above) at their lattice's cell, with `across`, `max` and `shape` as declared (each required — the reading behind the radius did not vary them) and `radius` as declared or, absent, drafted as the farthest vertex's distance plus 3 cells (the `influence.radius` row); without it the parts keep their lattice. `chains` — trees across the piece (for `back hair`, per side of the eye axis), a whole number, 1 or more; `links` — links from root to tip on every path, 1 or more; `split` — `{at, into}`: the first `at` links are the trunk, which forks into `into` (2 or more) branches; `at` below `links` (`CONFIG_CLOTH_SPLIT_BEFORE_TIP`); `length_ratio` — a path's last link over its first, above 0, default 0.5; `strength` — `{trunk, branch, edge}`, each above 0 and below the spring's stability bound (`CONFIG_CLOTH_SPRING_STABLE`), default 100 / 100 / 50; `damping` — in [0, 1], absent: rig-c's default; `alternate_damping` — the odd trees' damping, in [0, 1], beside `damping` and different from it (`CONFIG_CLOTH_ALTERNATE_DIFFERS`); `wind`, `gravity` — `[root, tip]`, each 0 or more, tip at or above root (`CONFIG_CLOTH_RESPONSE_GROWS_TO_TIP`); `translate` — the x and y mix of a dangling end's flutter, above 0 and at most 1; `swing` — `bottomwear` only, `{scales}`, one positive scale per tree (`CONFIG_CLOTH_SWING_SCALE_PER_TREE`); `part` — `bottomwear` only (`CONFIG_CLOTH_PART_ON_BOTTOMWEAR`), a non-empty part or cut-piece name: the `topwear` part that holds a skirt See-through returned inside it (a dress), or its skirt piece cut by `assemble.cuts`, which takes the skirt's trees (issue #402, *A skirt inside topwear* below; the part is checked by `propose`, `PROPOSE_CLOTH_PART`). The two defaults are the recipe's own, measured on its synthetic fixture (the recipe below). The recipe below says what each field drafts. The config written: `propose --cloth <config.json> --write-config <out.json>` (issue #537) writes this config's own text back with the sections the recipe drafts spliced in — `bones` and `constraints` whole, `meshes.<part>`, `regions.<part>` and `motion.tracks` entry by entry — and every other byte as read (*The config written*, under the recipe below) |
132
132
  | `proposed_rig_scale` | assemble, rig, build, `propose --from-config`/`--compare` | **proposed** by `propose` (issue #354): `parts.json`'s `scale_rig_per_source`, the `assemble.rig_scale` the rig sections (`bones`, `meshes`, `limbs`, `motion`) were drafted at. Held equal to `assemble.rig_scale` when present (`CONFIG_PROPOSED_RIG_SCALE`; 0, negative or not a number: `CONFIG_FIELD_TYPE`). Absent on a hand-authored config, where no byte of any output moves |
133
133
 
134
134
  **One drawing, one band; beyond it, another drawing (issue #472).** A single front-facing
@@ -1643,6 +1643,33 @@ idle key: the drafted idle keys none of the trees. A recipe that drafts nothing
1643
1643
  its tag on no part, or `back hair` that ends above the shoulders (a bun) — is refused,
1644
1644
  `PROPOSE_CLOTH_DRAFTED`.
1645
1645
 
1646
+ **The config written (issue #537).** `propose --cloth <config.json> --write-config
1647
+ <out.json>` writes, beside `proposal.json`, the `--cloth` config's own text with what the
1648
+ recipe drafts spliced in, the way `mesh-draft` writes its config: `rig --config <out.json>`
1649
+ builds it, and an editor that changes a recipe rebuilds through it rather than merging
1650
+ the proposal itself. What is spliced is measured on each run, not listed: the same parts
1651
+ are drafted again without the recipe, and each config section whose value differs is
1652
+ the recipe's. An object section is spliced entry by entry — `meshes.<part>` and
1653
+ `regions.<part>` for each part the recipe moved (a part it takes from `regions` into
1654
+ `meshes` leaves `regions`), `motion.tracks` and nothing else under `motion`, so
1655
+ `duration`, `blink` and `animations_from` keep their bytes — and `bones` and
1656
+ `constraints` whole: **the drafted array replaces the input's**, so a bone or a
1657
+ constraint added by hand does not survive a `--write-config`, as a hand-edited lattice
1658
+ does not survive `mesh-draft`. Every other byte is the input's; a section the input
1659
+ lacks (a config holding only `key` and `cloth`) is inserted. On the selftest's cloth
1660
+ fixture (CL201 prints the figures) the recipe moves `bones`, `meshes.hair_back`,
1661
+ `meshes.hair_front`, `meshes.skirt`, `motion.tracks` and `constraints`; `limbs` is not
1662
+ moved on the public `wind` example with its keypoints, whose tracked config the flag
1663
+ wrote back byte for byte (measured once, when the flag landed). The text is written as stated: a relative path in it
1664
+ (`motion.animations_from`, `generation.control.skeleton`) resolves against the directory
1665
+ the written config sits in, so the out path belongs beside the input, and when it is not
1666
+ a note names each such path. Refused before anything is written: `--write-config`
1667
+ without `--cloth` or beside `--from-config` (`USAGE`), an out path that exists or that
1668
+ the run writes itself (`PROPOSE_WRITE_CONFIG_FRESH`), and a text whose splice does not
1669
+ parse to the config with the sections set — a key stated twice
1670
+ (`PROPOSE_WRITE_CONFIG_SPLICE`); a recipe that drafts nothing is
1671
+ `PROPOSE_CLOTH_DRAFTED` as without the flag.
1672
+
1646
1673
  **A skirt inside topwear (issue #402).** The recipe finds a skirt by the `bottomwear`
1647
1674
  tag alone. When See-through returns the skirt inside `topwear` (a dress), nothing is
1648
1675
  tagged `bottomwear`, and the proposer does not pick the dress by its shape: with
@@ -1834,8 +1861,9 @@ rigc render --candidate out/check/build --animation idle --fps 12 --max 640 --ge
1834
1861
  Read by `CLOTH_SETTLES`'s own definition on the `geometry.json` that writes, none of the
1835
1862
  16 chains settles. The nine that settle under the default world keep moving to the last
1836
1863
  frame: the skirt's eight trees end at 7.66 to 23.79 rig px/s, and the swing at 2.778
1837
- (selftest `CH21` holds this). `check` itself always reads the default world, so `wind`'s
1838
- `check.json` keeps its WARN. The WARN states what the rig does with nothing driving it;
1864
+ (selftest `CH21` holds this). `check` without `--environment` reads the default world, so
1865
+ `wind`'s tracked `check.json` keeps its WARN; `check --environment examples/wind/breeze.json`
1866
+ takes every reading under the breeze instead (§6, *The world the readings are taken in*). The WARN states what the rig does with nothing driving it;
1839
1867
  it is not a fault (`CH20` holds that the idle keys no hip and that the chains which
1840
1868
  settle are exactly the ones no idle key drives). A soft region with no wind response,
1841
1869
  such as `reference-sample`'s `hip_jiggle`, is not reached by an environment at all:
@@ -2850,6 +2878,8 @@ says why each requirement exists and what breaks without it.
2850
2878
  | <a id="PROPOSE_LIMB_PARTS"></a>`PROPOSE_LIMB_PARTS` | `parts.json` holds a standalone or incomplete limb part `config.limbs` cut at its joints (issues #349, #440) that cannot be reassembled into the source part `of` (a missing segment or `cap` record, or `of` still present beside the limb parts); a complete `assemble` output with `config.limbs` reconstructs its pre-limb parts in the same run | `--parts` a complete `assemble` output (every segment of each limb, with its `cap` record) or a build assembled with `config.limbs` left out; `propose --from-config` reads the config's bones on either build |
2851
2879
  | <a id="PROPOSE_CLOTH_DRAFTED"></a>`PROPOSE_CLOTH_DRAFTED` | with `--cloth` (issue #364): the config's `cloth` block holds a recipe for a tag the proposer drafts no chain on — no part has that tag, or every `back hair` part ends above the shoulders (a bun bone, no chain). A `bottomwear` recipe with no `bottomwear` part names every `topwear` part shaped like a skirt (issue #402) | leave that recipe out, or assemble the layer it is for, or declare the named part in `cloth.bottomwear.part` |
2852
2880
  | <a id="PROPOSE_CLOTH_PART"></a>`PROPOSE_CLOTH_PART` | with `--cloth` (issues #402, #437): `cloth.bottomwear.part` (a string) names no part, a part or cut piece whose source is not `topwear` (a `bottomwear` part takes the recipe by its tag already), or a target whose box ends above the hip + 0.25 face heights, the topwear rule's waist line; or `cloth.<tag>.parts` (or `part` as a list, issue #437) names a part not in `parts.json`, a part no link of the drafted tree crosses (`spanCrosses == 0`), or parts out of root-to-tip depth order along the chain | name the `topwear` part or its cut skirt piece that holds the skirt (or leave `part` out), or list only parts in `parts.json` that the drafted tree links cross in root-to-tip order |
2881
+ | <a id="PROPOSE_WRITE_CONFIG_FRESH"></a>`PROPOSE_WRITE_CONFIG_FRESH` | with `--write-config` (issue #537): the out path exists, or is a file the run writes itself (`proposal.json`, `basis.json` under `--out`); the config is written to a new file, never over the `--cloth` config or an earlier one | name a file that does not exist yet, beside the `--cloth` config |
2882
+ | <a id="PROPOSE_WRITE_CONFIG_SPLICE"></a>`PROPOSE_WRITE_CONFIG_SPLICE` | with `--write-config` (issue #537): the `--cloth` config's text with the drafted sections spliced in does not parse to that config with them set, and the message names the first key that moved — the text states a key twice, so the splice lands on the first and the parse keeps the last | state each key once in the `--cloth` config |
2853
2883
  | <a id="PROPOSE_CLOTH_BACK_HAIR_CHAINS"></a>`PROPOSE_CLOTH_BACK_HAIR_CHAINS` | with `--cloth` (issues #390, #445, #461): `cloth."back hair".chains` exceeds what the narrower side's opaque width at the eye-line root row holds at the part's mesh grid (`max(1, min(floor(w_r / grid), floor(w_l / grid)))`), or places a tree root outside the 15 px dilated art mask of the `back hair` part (e.g. an inner twin-tail root over the face where the hair has no pixel); the message names the part, each side's root-row width, the grid spacing, and any off-art root with its pixel alpha | lower `cloth."back hair".chains` to at most the max fit named in the message, or omit `chains` so `propose --cloth` derives the tree count per visible hair mass on each side from its root-row width |
2854
2884
  | <a id="PROPOSE_ACCESSORY_BODY"></a>`PROPOSE_ACCESSORY_BODY` | an accessory has nothing above its pendant rows to hang its bone on | that part's plan entry, or author its bones by hand |
2855
2885
  | <a id="PROPOSE_TURN_RUN_GIVEN"></a><a id="PROPOSE_TURN_LAYER_PRESENT"></a><a id="PROPOSE_TURN_DEPTH_PRESENT"></a>`PROPOSE_TURN_RUN_GIVEN`, `PROPOSE_TURN_LAYER_PRESENT`, `PROPOSE_TURN_DEPTH_PRESENT` | with `--full`/`--head` (issue #251): a part came from a run whose layers were not given, the run given holds no layer of the part's tag, or its layer carries no `depth_median` while another part's layer carries one; a run with no depth on any part's layer (a PSD, or an export of one) is not refused — the turn is skipped, and the note says `turn: SKIP` and names the run (issue #359) | give the run the parts were assembled from, as the wrapper's `layers.json` |
@@ -3086,8 +3116,41 @@ documents do not ship). Each is an input this package built; none is an author's
3086
3116
  | <a id="REQUIREMENTS_MAY_FOLD"></a>`REQUIREMENTS_MAY_FOLD` | a `may_fold` entry names a slot with no mesh attachment — a region is one quad and cannot fold (issue #320). Refused before anything is built. Before issue #333 an entry naming the idle was refused here too; the bar reads the idle now, and `idle` is an animation name like any other | a mesh slot |
3087
3117
  | <a id="REQUIREMENTS_NOT_PLANTED"></a>`REQUIREMENTS_NOT_PLANTED` | a `not_planted` name is a part `check` does not read as a planted foot — it does not come from a See-through `footwear` layer — or there is no `parts.json` to choose the feet by (issue #231). Refused before anything is built | a `footwear` part's name |
3088
3118
  | <a id="REQUIREMENTS_TIP_EXCEPTION"></a>`REQUIREMENTS_TIP_EXCEPTION` | a `not_swinging`, `rises` or `rests` name is a part `TIP_OVER_ROOT` does not read — not from a See-through `handwear` or `bottomwear` layer — or there is no `parts.json` (refused before anything is built); or a `rises` part is not carried by a chain that rises: the chain's **last link**, at the setup pose, runs other than up — from its origin along its `length` (the extent the rig stage turns a link to), or, a last link with no length, from the link before's origin to its own — the detail giving the link read and the direction measured (refused after the idle is rendered, before `check.json` is written) (issues #231, #322; until #322 it read the chain's first link's origin to its last's, which refused a folded arm — a link that hangs, then a forearm raised) | a swinging part's name; for `rises`, a part whose chain does rise |
3119
+ | <a id="CHECK_ENVIRONMENT"></a>`CHECK_ENVIRONMENT` | `check --environment` (or `build --environment`, forwarded): the schedule is refused, the detail rigc's own sentence verbatim. Read once by rig-c's reader (`readEnvironmentSchedule`, `rig-c/src/environment.ts`) before anything is built — nothing at the path, a file that is not JSON or not an object, a `spec` other than `rigc-environment/1`, a key besides `spec`, `steps` or a step's `t`, `wind`, `gravity`, no step, a `t` not finite, below 0 or not after the step before, a `wind` or `gravity` not a pair of finite numbers (JSON's `1e999` reads as `Infinity` and is refused), a step stating neither — and `--out` is not written (`build` refuses under `[assemble]`, before it assembles). After the build, what `rigc render --environment` refuses of a well-formed schedule on this rig, quoted from its `--environment <path>:` line: no physics constraint, a half no constraint answers, two steps on one frame at 12 fps, a step after the last frame of the animation rendered. Also refused before anything is built: a `motion.json` with no animation, where no render `check` makes could pose the schedule | the schedule — rigc's sentence names the entry, the field, the value found and the value required; for a rig with no physics constraint, drop the flag: no world moves it |
3089
3120
  | <a id="REQUIREMENTS_SEAM"></a>`REQUIREMENTS_SEAM` | a `seam` cannot be read against the rig: there is no `parts.json` (a merged rig, §7 *Measuring a rig rig-parts did not assemble*), or the two parts' art does not meet at the setup pose (no 4-adjacent pair). Refused before anything is built | two parts whose art touches, on a rig with its `parts.json` |
3090
3121
 
3122
+ **The world the readings are taken in** (`--environment`, issue #538). A physics chain
3123
+ answers the world as well as the bones above it, and `check` without the flag reads
3124
+ rigc's default world, wind (1, 0) and gravity (0, 1) — not the one a person watched in
3125
+ the review editor. `check --environment <schedule.json>` hands a `rigc-environment/1`
3126
+ schedule (§3, *What moves them*) to every render whose frames a bar or a warning reads,
3127
+ and to none that writes a product: the idle render (`TIP_OVER_ROOT`, `STILL_REGIONS_DARK`,
3128
+ `TEXTURE_STRETCH`, `CLOTH_SETTLES`), the physics-on half of `ANIMATIONS_DO_NOT_FOLD`, the
3129
+ parts `BREATH_VISIBLE` renders alone, `SEAM_OVER_MOTION` and the `--requirements`
3130
+ renders. The renders with the physics left out — the loop's keyed render, the fold
3131
+ bar's physics-off half, `STRESS_OFF_CHAIN`'s turned copy and `SEAM_OVER_RANGE`'s bent
3132
+ copy — take none: no world moves a skeleton with no physics constraint, and
3133
+ `rigc render` refuses a schedule on one (`the skeleton declares no physics constraint,
3134
+ so no environment moves anything in it`, rig-c 2.60.0, measured on the fold bar's off
3135
+ half). The setup-pose stills (the seam, `BLINK_NO_HOLE`, `SETUP_POSE_VS_SOURCE`) take
3136
+ none either: each is a 0.1 s animation read at its first frame, and rigc refuses a step
3137
+ after its last (`entry 1's t 0.5 falls after the last frame of every set drawn`,
3138
+ measured). `build --loop` encodes a product and takes none. One line,
3139
+ `environment: <path>, rigc-environment/1, <n> step(s), sha256 <16 hex>`, says which
3140
+ schedule, and `check.json` carries `environment` — `path` as the command line gave it,
3141
+ the `sha256` of the bytes read, `steps` — after `pack_mode`; without the flag neither
3142
+ is written and no render argument moves.
3143
+
3144
+ The world before the first step is the runtime's, so a still schedule is the one that
3145
+ states it: `{ "t": 0, "wind": [1, 0], "gravity": [0, 1] }` reads what a run without the
3146
+ flag reads — on the cloth fixture (selftest `CK514`), the same idle frames and the same
3147
+ `check.json` but for its `environment` key. Wind `[0, 0]` is not that world but a calm,
3148
+ and it moves the readings: on the same fixture `TEXTURE_STRETCH` 1.382 → 1.214 and
3149
+ `TIP_OVER_ROOT`'s ratio 15.061 → 7.216. A gust that moves the chains moves the bars:
3150
+ wind (1, 0), then (40, 0) from 0.5 s, reads `TEXTURE_STRETCH` 32.181 (FAIL, `hair_back`
3151
+ triangle 258), two meshes folding under `ANIMATIONS_DO_NOT_FOLD` (FAIL; none without the
3152
+ flag) and 8 `CLOTH_SETTLES` warnings for 9 (selftest `CK515`).
3153
+
3091
3154
  ### compose
3092
3155
 
3093
3156
  Every refusal below is collected with the others and printed at once, under
package/docs/STABILITY.md CHANGED
@@ -53,12 +53,12 @@ defaults are the help's too, and none is guessed from the art.
53
53
  | `comfy` | `seethrough`: `--image`, `--out`; optional `--resolution`, `--steps`, `--seed`, `--prefix`, `--offload`, `--lama`, `--nf4`, `--host`, `--wait`, `--timeout`, `--poll` |
54
54
  | `assemble` | `--propose-plan` with `--source`, `--full`, `--config`, optional `--head`; or `--source`, `--full`, `--config`, `--out`, optional `--head` (without it, one run: issue #359), `--seam` (near-white, silhouette), `--project` (core, visible), `--alt` (repeatable `<name>=<source>:<full>[:<head>]`, issue #454) |
55
55
  | `propose` | `--head-box` with `--full`, `--canvas`; optional `--no-back-hair` |
56
- | `propose` | `--parts`, `--source`, `--out`; optional `--compare` or `--from-config` (one of them), `--keypoints`, `--person` and `--wrist-snap` (each with `--keypoints`), `--full`, `--head` (the turn control's depths; not with `--from-config`), `--grid-rule` (`figure` or `part`, the drafted lattice's spacing; not with `--from-config`), `--cloth` (a config whose `cloth` block is the recipe, issue #364; not with `--from-config`) |
56
+ | `propose` | `--parts`, `--source`, `--out`; optional `--compare` or `--from-config` (one of them), `--keypoints`, `--person` and `--wrist-snap` (each with `--keypoints`), `--full`, `--head` (the turn control's depths; not with `--from-config`), `--grid-rule` (`figure` or `part`, the drafted lattice's spacing; not with `--from-config`), `--cloth` (a config whose `cloth` block is the recipe, issue #364; not with `--from-config`), `--write-config` (a new file, with `--cloth` and not with `--from-config`, issue #537 — additive: without it nothing `propose` writes changes) |
57
57
  | `compare` | `--left`, `--right`; optional `--map` |
58
58
  | `rig` | `--config`, `--parts`, `--out`; optional `--idle-keys` (ctl, direct), `--page-edges` (pot, free), `--pack-shape` (rect, polygon) |
59
- | `check` | `--rig`, `--out`; optional `--parts`, `--source`, `--page-edges`, `--pack-shape`, `--requirements`, `--seam-pairs`, `--keep-stills`, `--set` or `--all-sets` (issue #454) |
59
+ | `check` | `--rig`, `--out`; optional `--parts`, `--source`, `--page-edges`, `--pack-shape`, `--requirements`, `--seam-pairs`, `--keep-stills`, `--set` or `--all-sets` (issue #454), `--environment` (issue #538, additive) |
60
60
  | `loop` | `--frames`, `--out`; optional `--palette` |
61
- | `build` | `--config`, `--source`, `--full`, `--out`; optional `--head` (as for `assemble`), `--seam`, `--project`, `--page-edges`, `--pack-shape`, `--loop`, `--lead-in`, `--requirements`, `--idle-keys`, `--seam-pairs`, `--keep-stills`, `--alt` (as for `assemble`, issue #454), `--set` or `--all-sets` (as for `check`, issue #454) |
61
+ | `build` | `--config`, `--source`, `--full`, `--out`; optional `--head` (as for `assemble`), `--seam`, `--project`, `--page-edges`, `--pack-shape`, `--loop`, `--lead-in`, `--requirements`, `--idle-keys`, `--seam-pairs`, `--keep-stills`, `--alt` (as for `assemble`, issue #454), `--set` or `--all-sets` (as for `check`, issue #454), `--environment` (as for `check`, issue #538, additive) |
62
62
  | `compose` | `--scene`, `--out`; optional `--requirements`, `--accept` |
63
63
  | `mesh-draft` | `--config`, `--parts`, `--out`; optional `--requirements`, `--idle-keys` (ctl, direct), `--page-edges` (pot, free), `--pack-shape` (rect, polygon), `--more-triangles` |
64
64
  | `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) |
@@ -193,11 +193,12 @@ every number) are AUTHORING §3's tables, and the loader refuses any other by na
193
193
  | `parts.json`, `parts/<name>.png` | `assemble`, `build` | one record per part: `from` (`<run>:<tag>` with a See-through v3 tag, `<run>:author:<label>` for a layer the author made — issue #256, read by no role rule — or `painting:<name>` for a patch), `cut_from` on a cut's piece only (the plan part it was cut from, issue #230), `limb` on a limb segment's part only (issue #349: `name`, `segment`, `of`, `bone`, and below a joint `joint`, `range` when the config segment declares one (issue #360), and `cap` — `at`, `width`, `radius`, `box`, `layer_px`, `image_px` with a cap image, `image_layer` after it when that image was a hidden-art layer — issue #359, `<run>:<layer>:hidden` — `missing_px`, then `shape` and `upper_px` under the segment's `cap_shape`, and `edge`, `feather_radius` and `feathered_px` under its `edge`, and `cut_band`, `cut_offset`, `cut_at`, `cut_crossed`, `joint_crossed`, `band_px` and `stroke_luma_max` (when the band has a split) under its `cut_band`, issue #360), the box `x`, `y`, `w`, `h` (rig px), the pixel counts `src/parts.ts` documents (`opaque_px`, `visible_px`, `occluded_px`, `projected_core_px`, `source_px_taken`, `visible_not_projected_px`, `refused_drift_px`, `merged_px`, `seam_override_px`, and `fringe_pushed_back` when not empty); `rig_size`, `scale_rig_per_source`, `ghost_px`, `recomposite`, and `scene` (`figure_alpha_above`, `figure_px`, `figure_mask`) under `config.scene` only, with the figure's mask `figure_rig.png` beside the recomposite (issue #242); `single_run_pad` (`file_size`, `side`, `left`, `top`) last, only for one run whose file is not the `seethrough.resolution` square (issue #366) |
194
194
  | `rig/rig.json`, `rig/motion.json`, `rig/images/` | `rig`, `build`, `compose` | rig-c's rig spec and motion spec, `spec` `rigc-rig/1` and `rigc-motion/1`: the format is rig-c's, and this package writes only what rig-c's parser accepts; a bone carries `inherit` only where config.bones declares one, rig-c's mode name as written (issue #348) |
195
195
  | `rig/mesh_report.json` | `rig`, `build` | one row per mesh: `part`, `vertices`, `triangles`, `hull`, `bones`, `max_influences`, `mean_influences`, `art_coverage`, then `grid` (a lattice); `mode` "contour" with `params`, `contour`, `regions` (`params.maxEdge` and `contour.outlineCut` only when the mesh declares `contour.maxEdge`; `params.bridges` and `contour.bridges` — `islands`, `units`, `joins`, and `faint` only when an island was left out as faint — only when it declares `contour.bridges`); or `mode` "influence" with `influence` (as declared), `reach` (`farthest`, `at`, `nearest`, `capped`, `widest`) and `lattice` (rig-c's `SegmentsLatticeReport`: `cols`, `rows`, `artCells`, `keptCells`, `passes`, `islands`) (issue #378); or `mode` "auto" with `settings`, `source`, `result`, `residuals`, `worst_residual`, `worst_region`, `motion_amplitude`, `termination`, `weights`, `regions`, `deformation`, `quality_report` (rig-c's `mesh-quality-report/1` document whole), `motion_report`, and, only when they apply, `stray_cleared` (after `source`, when `source.stray` is declared), `skinning_residual` and `replay` (`AutoMeshReport` in `src/rig.ts`); in every mode, `exponent` when the mesh declares one (after `grid`, or after `mode`); `influences`, as declared, when a lattice or contour mesh declares it (after `exponent`, or where `exponent` would be); `stray` and `stray_cleared` when a lattice mesh declares `stray` (after `influences`, or where `influences` would be); `ribs` when a contour or auto mesh declares them (after `exponent`, or after `mode`), and then `contour.ribs` (`source.contour.ribs` in the automatic mode) |
196
- | `check/check.json` and the rest of `check/` | `check`, `build`, `compose` | the reference's fields in its order (`gate_spine_html_green`, `rigc_entry`, `pack_mode`, `loop_max_diff`, the seam figures — `seam_mean`, `seam_px_over_40`, `seam_px_over_80` and, from issue #216, `seam_frame_scale`, the frame scale the bar divides the count by), `loop_physics` after `loop_max_diff` when the rig declares a physics constraint, `seam_border` after the seam figures when `parts.json` declares a scene (issue #242), `seam_pairs` after the seam figures when the seam bar fails or `--seam-pairs` asks (each row's picture under `check/seam/`; `--keep-stills` leaves the setup-pose still and its `frames.json` under `check/setup_still/`), then the judgement lines (`BREATH_VISIBLE`, `BLINK_NO_HOLE`, `CHAIN_LAG`, `TIP_OVER_ROOT`, `STILL_REGIONS_DARK`, `TEXTURE_STRETCH`), `ANIMATIONS_DO_NOT_FOLD` after them when `motion.json` holds an animation, the idle included — on every rig with an idle since issue #333 (issues #320, #363: `status`, `animations`, `fps`, `physics_left_out`, `folding` — each `animation`, `slot`, `attachment`, `frames`, `worst_frame`, `worst_triangles`, `triangles`, `physics_on`, `physics_off`, `physics_constraints`, `declared`, `line` — `folding_undeclared`, `declared_not_folding`, `bar`), `FEET_STAY_LEVEL` after it when a `footwear` part rides a bone that hangs from another and `motion.json` holds an animation (issue #348: `status`, `reason` on a SKIP only, `animations`, `fps`, `physics_left_out`, `bar_degrees`, `bar`, `feet` — each `part`, `bone`, `hangs_from`, `status`, `frames_posed`, `worst`), `LIMB_ONE_BONE` after it (and after `STRESS_OFF_CHAIN` where that is written) when `parts.json` holds a limb segment's part (issue #349: `status`, `parts` — each `part`, `limb`, `bone`, `status`, `others`), `SEAM_OVER_RANGE` after it when a limb record carries a `range` (issue #360: `status`, `frame_scale`, `physics_left_out`, `bar` — `mean`, `rig_px_over_40`, `level` — and `joints`, each `part`, `limb`, `segment`, `joint`, `bone`, `range`, `at`, `radius`, `under_px`, `status`, `poses` — each `degrees`, `status`, `mean`, `px_over_40`, `px_over_80`, `rig_px_over_40` — and `unread` on a joint not read), `SEAM_OVER_MOTION` after it when `parts.json` holds a limb segment or `--requirements` a `seam` (issue #493, a warning and not a bar: `status` — `WARN`, `CLEAR` or `SKIP` — `reason` on a SKIP only, `fps`, `floor`, `pairs` — each `pair`, `a`, `b`, `declared`, and `unread` on a pair not read — `animations`, `warnings`, `rows` — each `pair`, `animation`, `status`, `drawn`, `banded`, `opens`, `px`, `max_px`, `under_floor`), `CLOTH_SETTLES` after it when the rig declares a physics constraint and has an idle (issue #501, a warning and not a bar: `status` — `WARN` or `CLEAR` — `fps`, `frames`, `duration`, `floor_rig_px_per_s`, `floor`, `levers`, `warnings`, `rows` — each `tip`, `root`, `links`, `point`, `settles_at`, `max_rig_px_per_s`, `min_rig_px_per_s`), `RECOMPOSITE_HOLES` (its first figure `declared_scene` when `parts.json` declares a scene), `SETUP_POSE_VS_SOURCE`, `skipped`, a `requirements` block under `--requirements`, and `PASS`; `check/build/skeleton.json`, `.atlas` and `.png` are the packed artifact rig-c writes |
196
+ | `check/check.json` and the rest of `check/` | `check`, `build`, `compose` | the reference's fields in its order (`gate_spine_html_green`, `rigc_entry`, `pack_mode`, `environment` after it under `--environment` only (issue #538, additive: `path` as given, `sha256`, `steps`), `loop_max_diff`, the seam figures — `seam_mean`, `seam_px_over_40`, `seam_px_over_80` and, from issue #216, `seam_frame_scale`, the frame scale the bar divides the count by), `loop_physics` after `loop_max_diff` when the rig declares a physics constraint, `seam_border` after the seam figures when `parts.json` declares a scene (issue #242), `seam_pairs` after the seam figures when the seam bar fails or `--seam-pairs` asks (each row's picture under `check/seam/`; `--keep-stills` leaves the setup-pose still and its `frames.json` under `check/setup_still/`), then the judgement lines (`BREATH_VISIBLE`, `BLINK_NO_HOLE`, `CHAIN_LAG`, `TIP_OVER_ROOT`, `STILL_REGIONS_DARK`, `TEXTURE_STRETCH`), `ANIMATIONS_DO_NOT_FOLD` after them when `motion.json` holds an animation, the idle included — on every rig with an idle since issue #333 (issues #320, #363: `status`, `animations`, `fps`, `physics_left_out`, `folding` — each `animation`, `slot`, `attachment`, `frames`, `worst_frame`, `worst_triangles`, `triangles`, `physics_on`, `physics_off`, `physics_constraints`, `declared`, `line` — `folding_undeclared`, `declared_not_folding`, `bar`), `FEET_STAY_LEVEL` after it when a `footwear` part rides a bone that hangs from another and `motion.json` holds an animation (issue #348: `status`, `reason` on a SKIP only, `animations`, `fps`, `physics_left_out`, `bar_degrees`, `bar`, `feet` — each `part`, `bone`, `hangs_from`, `status`, `frames_posed`, `worst`), `LIMB_ONE_BONE` after it (and after `STRESS_OFF_CHAIN` where that is written) when `parts.json` holds a limb segment's part (issue #349: `status`, `parts` — each `part`, `limb`, `bone`, `status`, `others`), `SEAM_OVER_RANGE` after it when a limb record carries a `range` (issue #360: `status`, `frame_scale`, `physics_left_out`, `bar` — `mean`, `rig_px_over_40`, `level` — and `joints`, each `part`, `limb`, `segment`, `joint`, `bone`, `range`, `at`, `radius`, `under_px`, `status`, `poses` — each `degrees`, `status`, `mean`, `px_over_40`, `px_over_80`, `rig_px_over_40` — and `unread` on a joint not read), `SEAM_OVER_MOTION` after it when `parts.json` holds a limb segment or `--requirements` a `seam` (issue #493, a warning and not a bar: `status` — `WARN`, `CLEAR` or `SKIP` — `reason` on a SKIP only, `fps`, `floor`, `pairs` — each `pair`, `a`, `b`, `declared`, and `unread` on a pair not read — `animations`, `warnings`, `rows` — each `pair`, `animation`, `status`, `drawn`, `banded`, `opens`, `px`, `max_px`, `under_floor`), `CLOTH_SETTLES` after it when the rig declares a physics constraint and has an idle (issue #501, a warning and not a bar: `status` — `WARN` or `CLEAR` — `fps`, `frames`, `duration`, `floor_rig_px_per_s`, `floor`, `levers`, `warnings`, `rows` — each `tip`, `root`, `links`, `point`, `settles_at`, `max_rig_px_per_s`, `min_rig_px_per_s`), `RECOMPOSITE_HOLES` (its first figure `declared_scene` when `parts.json` declares a scene), `SETUP_POSE_VS_SOURCE`, `skipped`, a `requirements` block under `--requirements`, and `PASS`; `check/build/skeleton.json`, `.atlas` and `.png` are the packed artifact rig-c writes |
197
197
  | `layers.json`, `<index>_<name>.png` | `layers --export` | the wrapper form `layers` reads (issue #359): `width`, `height`, then `layers` — each `name`, `filename`, `left`, `top`, `right`, `bottom`, `depth_median` (the input's own; `null` for a PSD, the manifest's order then being the draw order) — drawn layers in draw order, then the hidden-art layers; a PNG's name is its index and its layer's name, and the manifest, not the file name, says which layer it is |
198
198
  | the template `.psd` | `layers --template` | one empty layer per name `templateLayerNames` (`src/layers.ts`) holds, bottom first; the same canvas writes the same bytes |
199
199
  | `proposal.json`, `render/landmarks*.png` | `propose` | the config's four rig sections, `constraints` with `--cloth` (issue #364: a physics constraint per tree link named `<bone>_physics`, a dangling end's `<bone>_translate`, and a skirt swing's transforms `<swing>_<tree>`), `turn` with `--full`/`--head`, `proposed_rig_scale` (issue #354), and `notes` |
200
200
  | `basis.json` | `propose` | spec `spine-parts-basis/1` |
201
+ | the `--write-config` file | `propose --cloth … --write-config` | the `--cloth` config read, byte for byte, but for the sections the recipe drafts (issue #537): `bones` and `constraints` whole, and `meshes.<part>`, `regions.<part>` and `motion.tracks` for each entry the recipe moves, measured against the same parts drafted without it; a section the input lacks is inserted |
201
202
  | `config.json`, `mesh_draft.json` | `mesh-draft` | `config.json` is the config read, byte for byte, but for each drafted part's `meshes` entry; `mesh_draft.json` is spec `rig-parts-mesh-draft/1`: `rules`, `lattice_check`, `draft_check`, `figure_overdraw`, and per lattice part `part`, `mode`, `lattice`, `candidate` (with `bridges` — `units`, `joins` of `span` and `area_px2`, `area_px2`, `overdraw`, and `faint` only when an island was left out as faint — only when the candidate is a bridged one, issue #326), `delta` (under `--more-triangles` only), `readings`, `gate` (each line's `reading`, `pass`, `text`, `margin`), `note`; and `not_compared` (issue #307), only when the config holds an `auto` or `contour` entry: per such entry, in config order, `part`, `mode` and `note` — the part was neither drafted nor compared, and a config of lattices alone writes no such key |
202
203
  | `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`; `scope`) |
203
204
  | `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`; `scope`) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rig-parts",
3
- "version": "1.46.0",
3
+ "version": "1.48.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": {
package/src/build.ts CHANGED
@@ -70,7 +70,7 @@ import {
70
70
  splitSchedule,
71
71
  untestedIntervals,
72
72
  } from './autoreplay.ts';
73
- import { besideIdleLine, CLOTH_LINE, type ClothLine, clothWarnText, frameRuns, MOTION_SEAM_LINE, type MotionSeamLine, type MotionSeamPlant, motionSeamWarnText, FOLD_LINE, type FoldsLine, LEVEL_LINE, type LevelLine, LIMB_LINE, type LimbLine, STRESS_LINE, SWEEP_LINE, type SweepLine, buildGateLines, causeLines, IDLE_FPS, IDLE_MAX_PX, maxRgbDiff, REQUIREMENTS_DIR, type CheckReport, type PackLine, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, GATE_PROFILE, JUDGEMENT_LINES, type JudgementLine, packedBuildArgs, packedBuildLabel, type PackMode, type PackShape, type PageEdges, readFrameSet, rigcFailed, rigcIdentity, rigcRanClause, REPORTED_LINES, type ReportedLine, type RigcRunner, runCheck, SEAM_DIR, SEAM_MEAN_BAR, seamPairText, seamRigPxText, SOURCE_LINE, SEAM_PX_BAR, SEAM_PX_LEVEL, SEAM_PX_LEVEL_HIGH, SPINEBOY_YARDSTICK, STILL_DIR } from './check.ts';
73
+ import { besideIdleLine, CLOTH_LINE, type ClothLine, clothWarnText, frameRuns, MOTION_SEAM_LINE, type MotionSeamLine, type MotionSeamPlant, motionSeamWarnText, FOLD_LINE, type FoldsLine, LEVEL_LINE, type LevelLine, LIMB_LINE, type LimbLine, STRESS_LINE, SWEEP_LINE, type SweepLine, buildGateLines, causeLines, environmentLine, IDLE_FPS, IDLE_MAX_PX, maxRgbDiff, REQUIREMENTS_DIR, type CheckReport, type PackLine, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, GATE_PROFILE, JUDGEMENT_LINES, type JudgementLine, packedBuildArgs, packedBuildLabel, type PackMode, readCheckEnvironment, type PackShape, type PageEdges, readFrameSet, rigcFailed, rigcIdentity, rigcRanClause, REPORTED_LINES, type ReportedLine, type RigcRunner, runCheck, SEAM_DIR, SEAM_MEAN_BAR, seamPairText, seamRigPxText, SOURCE_LINE, SEAM_PX_BAR, SEAM_PX_LEVEL, SEAM_PX_LEVEL_HIGH, SPINEBOY_YARDSTICK, STILL_DIR } from './check.ts';
74
74
  import { type Cut, type Extend, type Limb, loadConfig, loadConfigAndAnimations, loadEarlyConfig, type Patch, type PlanEntry } from './config.ts';
75
75
  import { failLine, PartsError, type Problem, refuseIfAny } from './errors.ts';
76
76
  import type { MeshQualityReport, MotionSchedule } from 'rig-c/mesh';
@@ -1359,6 +1359,11 @@ export interface CheckStageInput {
1359
1359
  set?: string;
1360
1360
  /** `check --all-sets` (issue #454): measure every declared alternate set's setup-pose seam and recomposite figures. */
1361
1361
  allSets?: boolean;
1362
+ /**
1363
+ * `check --environment <file>` (issue #538): a `rigc-environment/1` schedule every render a bar or a warning reads
1364
+ * with the physics on is posed under; absent, no render argument and no byte of `check.json` moves.
1365
+ */
1366
+ environment?: string;
1362
1367
  }
1363
1368
 
1364
1369
  /**
@@ -1581,7 +1586,8 @@ export function checkStage(input: CheckStageInput, rigc: RigcRunner, bin: string
1581
1586
  const entryLine = versionLines.find((l) => l.startsWith('entry:'));
1582
1587
  log(` ${rigcIdentity(bin, v)}${entryLine === undefined ? '' : `; ${entryLine}`}`);
1583
1588
  const mode: PackMode = { pageEdges: input.pageEdges ?? DEFAULT_PAGE_EDGES, packShape: input.packShape ?? DEFAULT_PACK_SHAPE };
1584
- const r = runCheck(input.rig, input.out, rigc, input.parts, mode, input.source, input.requirements, input.seamPairs === true, input.keepStills === true, input.set, input.allSets === true);
1589
+ const r = runCheck(input.rig, input.out, rigc, input.parts, mode, input.source, input.requirements, input.seamPairs === true, input.keepStills === true, input.set, input.allSets === true, input.environment);
1590
+ if (r.figures.environment !== undefined) log(` ${environmentLine(r.figures.environment)}`);
1585
1591
  log(` gate rig-play (rigc ${packedBuildLabel(mode)}), verbatim:`);
1586
1592
  for (const l of r.gateHtml) log(l);
1587
1593
  for (const l of packLines(r)) log(` ${l}`);
@@ -1920,6 +1926,8 @@ export interface BuildInput {
1920
1926
  set?: string;
1921
1927
  /** `--all-sets`, forwarded to the check as `check` takes it (issue #454). */
1922
1928
  allSets?: boolean;
1929
+ /** `--environment <file>`, forwarded to the check as `check` takes it (issue #538): read before assemble runs, so a schedule check would refuse is refused first; absent, nothing moves. */
1930
+ environment?: string;
1923
1931
  }
1924
1932
 
1925
1933
  /** What `build` does with one flag `check` takes: hands it to its check stage, takes it as its own, or refuses it because build supplies the value itself. */
@@ -1946,6 +1954,7 @@ export const CHECK_FLAGS_IN_BUILD: Readonly<Record<string, CheckFlagInBuild>> =
1946
1954
  '--all-sets': { as: 'forwarded' },
1947
1955
  '--seam-pairs': { as: 'forwarded' },
1948
1956
  '--keep-stills': { as: 'forwarded' },
1957
+ '--environment': { as: 'forwarded' },
1949
1958
  };
1950
1959
 
1951
1960
  /** The `build` refusal of a `check` flag build supplies itself ({@link CHECK_FLAGS_IN_BUILD}), or null for any other flag. */
@@ -2039,6 +2048,8 @@ export function build(input: BuildInput, run: BuildRunners, log: Log): BuildResu
2039
2048
  loadConfig(input.config);
2040
2049
  // The same for the requirements file's own shape; its names resolve against the rig, in the check, before it builds.
2041
2050
  if (input.requirements !== undefined) readRequirements(input.requirements);
2051
+ // And the schedule (issue #538), by rigc's own reader, as check reads it.
2052
+ if (input.environment !== undefined) readCheckEnvironment(input.environment);
2042
2053
  assembleStage(
2043
2054
  { source: input.source, full: input.full, head: input.head, config: input.config, seam: input.seam, project: input.project, ...(input.alts === undefined ? {} : { alts: input.alts }) },
2044
2055
  { partsJson: join(out, 'parts.json'), partsDir: join(out, 'parts'), recomposite: join(out, 'recomposite_rig.png'), errorMap: join(out, ERROR_MAP_FILE) },
@@ -2056,7 +2067,7 @@ export function build(input: BuildInput, run: BuildRunners, log: Log): BuildResu
2056
2067
 
2057
2068
  let report: CheckReport;
2058
2069
  try {
2059
- report = checkStage({ rig: join(out, 'rig'), parts: out, out: join(out, 'check'), pageEdges: input.pageEdges, packShape: input.packShape, ...(input.requirements === undefined ? {} : { requirements: input.requirements }), seamPairs: input.seamPairs === true, keepStills: input.keepStills === true, ...(input.set === undefined ? {} : { set: input.set }), allSets: input.allSets === true }, run.check, run.checkBin, prefixed('check'));
2070
+ report = checkStage({ rig: join(out, 'rig'), parts: out, out: join(out, 'check'), pageEdges: input.pageEdges, packShape: input.packShape, ...(input.requirements === undefined ? {} : { requirements: input.requirements }), seamPairs: input.seamPairs === true, keepStills: input.keepStills === true, ...(input.set === undefined ? {} : { set: input.set }), allSets: input.allSets === true, ...(input.environment === undefined ? {} : { environment: input.environment }) }, run.check, run.checkBin, prefixed('check'));
2060
2071
  } catch (err) {
2061
2072
  return refused('check', err);
2062
2073
  }
package/src/check.ts CHANGED
@@ -77,6 +77,7 @@
77
77
  * the last idle frame is refused unless it sits at t = duration (within
78
78
  * `TIME_SLACK`, issue #244).
79
79
  */
80
+ import { createHash } from 'node:crypto';
80
81
  import { copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
81
82
  import { basename, delimiter, dirname, join, resolve } from 'node:path';
82
83
  import { measureRecomposite, type RecompositeFigures, recompositeRecord, scenePhrase, sourceInRig } from './assemble.ts';
@@ -158,6 +159,7 @@ import {
158
159
  } from './requirements.ts';
159
160
  import { RIG_BONE_INHERIT, type RigSpec as RigcRigSpec } from 'rig-c/src/rig.ts';
160
161
  import { expandStops } from 'rig-c/src/stop.ts';
162
+ import { ENVIRONMENT_SPEC, EnvironmentError, readEnvironmentSchedule } from 'rig-c/src/environment.ts';
161
163
  import { alphaComposite } from './raster/composite.ts';
162
164
  import { readPng, writePng } from './raster/png.ts';
163
165
  import { newFloatImage, newRaster, type Raster } from './raster/types.ts';
@@ -1814,6 +1816,12 @@ export interface CheckFigures {
1814
1816
  rigc_entry: RigcEntryRecord;
1815
1817
  /** How the artifact's page was packed: the `--page-edges` and `--pack-shape` rigc was handed, which its pack line was read to agree with ({@link packEdgeProblems}). Provenance, not a bar. */
1816
1818
  pack_mode: { page_edges: PageEdges; pack_shape: PackShape };
1819
+ /**
1820
+ * Written only under `--environment` (issue #538): the `rigc-environment/1` schedule every measured render was posed
1821
+ * under — the path as the command line gave it, the sha256 of the bytes read, and how many steps rigc's reader read
1822
+ * off them ({@link readCheckEnvironment}). Provenance, not a bar; without the flag no key is written.
1823
+ */
1824
+ environment?: CheckEnvironment;
1817
1825
  /** Null when the rig has no idle (issue #77); `skipped.loop` then says why. */
1818
1826
  loop_max_diff: number | null;
1819
1827
  /**
@@ -3577,6 +3585,61 @@ export function rigcFailed(what: string, call: RigcCall, lines: readonly string[
3577
3585
  return quoted.map((l) => ({ code: 'CHECK_RIGC_GREEN', object, detail: `exit ${call.status}: ${l}${ran}` }));
3578
3586
  }
3579
3587
 
3588
+ // ---------------------------------------------------------------------------
3589
+ // the world the readings are taken in (issue #538)
3590
+ // ---------------------------------------------------------------------------
3591
+
3592
+ /** The refusal of a schedule `check --environment` names: rigc's reader's sentence, or rigc render's, verbatim. */
3593
+ export const ENVIRONMENT_RULE = 'CHECK_ENVIRONMENT';
3594
+
3595
+ /** What `check.json` records of the schedule under `--environment`: provenance, not a bar. */
3596
+ export interface CheckEnvironment {
3597
+ /** The path as the command line gave it — never resolved, so the record holds no directory the caller did not type. */
3598
+ path: string;
3599
+ /** The sha256 of the file's bytes as read, the bytes rigc's reader read. */
3600
+ sha256: string;
3601
+ /** How many steps rigc's reader read off it. */
3602
+ steps: number;
3603
+ }
3604
+
3605
+ function environmentRefused(given: string, sentence: string): PartsError {
3606
+ return new PartsError([{ code: ENVIRONMENT_RULE, object: given, detail: sentence }]);
3607
+ }
3608
+
3609
+ /**
3610
+ * `--environment <file>` read once, before anything is built (issue #538): the file's bytes hashed and handed to
3611
+ * rig-c's own reader, `readEnvironmentSchedule` (`rig-c/src/environment.ts`), which refuses every malformed schedule
3612
+ * — a `spec` other than {@link ENVIRONMENT_SPEC}, a key it does not read, no step, a `t` that is not finite, at or
3613
+ * above 0 and after the step before, a `wind` or `gravity` that is not a pair of finite numbers, a step that changes
3614
+ * nothing — by entry, field, the value found and the value required. Nothing here reads the schedule's meaning: its
3615
+ * sentence is carried as {@link ENVIRONMENT_RULE}'s detail, verbatim, and a path with no file at it is worded as
3616
+ * `rigc render --environment` words it. What a well-formed schedule cannot do to this rig — move a rig with no
3617
+ * physics constraint, change a half no constraint answers, fall after the last frame drawn — is rigc render's to
3618
+ * refuse, and {@link runCheck} carries that sentence the same way.
3619
+ */
3620
+ export function readCheckEnvironment(given: string): CheckEnvironment {
3621
+ const path = resolve(given);
3622
+ if (!existsSync(path) || !statSync(path).isFile()) throw environmentRefused(given, `--environment ${given}: nothing at ${path} — it takes a schedule file { "spec": "${ENVIRONMENT_SPEC}", "steps": [...] }`);
3623
+ let bytes: Buffer;
3624
+ try {
3625
+ bytes = readFileSync(path);
3626
+ } catch (err) {
3627
+ throw environmentRefused(given, `--environment ${given}: not readable — ${(err as Error).message}`);
3628
+ }
3629
+ try {
3630
+ const steps = readEnvironmentSchedule(bytes.toString('utf8'), given);
3631
+ return { path: given, sha256: createHash('sha256').update(bytes).digest('hex'), steps: steps.length };
3632
+ } catch (err) {
3633
+ if (err instanceof EnvironmentError) throw environmentRefused(given, err.message);
3634
+ throw err;
3635
+ }
3636
+ }
3637
+
3638
+ /** The line `check` prints under `--environment`, beside rigc's identity: which schedule, by path and digest, and which renders it poses. */
3639
+ export function environmentLine(env: CheckEnvironment): string {
3640
+ return `environment: ${env.path}, ${ENVIRONMENT_SPEC}, ${env.steps} step(s), sha256 ${env.sha256.slice(0, 16)} — every render a bar or a warning reads with the physics on is posed under it; the physics-off, setup-pose and loop renders are not`;
3641
+ }
3642
+
3580
3643
  /**
3581
3644
  * Run the whole check. Refuses (throws a PartsError) when the inputs are
3582
3645
  * unreadable or a rigc step that everything after it depends on is red — the
@@ -3603,23 +3666,28 @@ export function rigcFailed(what: string, call: RigcCall, lines: readonly string[
3603
3666
  * MEASURABLE is a problem. Without it nothing here reads, writes or prints
3604
3667
  * anything it did not before.
3605
3668
  */
3606
- export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, partsHome?: string, mode: PackMode = DEFAULT_PACK_MODE, source?: string, requirements?: string, seamPairsAsked = false, keepStills = false, set?: string, allSets = false): CheckReport {
3669
+ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, partsHome?: string, mode: PackMode = DEFAULT_PACK_MODE, source?: string, requirements?: string, seamPairsAsked = false, keepStills = false, set?: string, allSets = false, environment?: string): CheckReport {
3607
3670
  let inp: CheckInputs;
3608
3671
  let reqFile: RequirementsFile | null = null;
3609
3672
  let seams: Map<string, SeamPair[]> | null = null;
3610
- if (requirements === undefined) inp = readCheckInputs(rigDir, partsHome, source, set, allSets);
3611
- else {
3612
- // Both readers collect every problem; one refusal names both sets.
3613
- const refused: Problem[] = [];
3614
- const take = <T>(read: () => T): T | null => {
3615
- try {
3616
- return read();
3617
- } catch (err) {
3618
- if (!(err instanceof PartsError)) throw err;
3619
- refused.push(...err.problems);
3620
- return null;
3621
- }
3622
- };
3673
+ // Every reader collects every problem; one refusal names every set.
3674
+ const refused: Problem[] = [];
3675
+ const take = <T>(read: () => T): T | null => {
3676
+ try {
3677
+ return read();
3678
+ } catch (err) {
3679
+ if (!(err instanceof PartsError)) throw err;
3680
+ refused.push(...err.problems);
3681
+ return null;
3682
+ }
3683
+ };
3684
+ // Issue #538: the schedule is read once, first, by rigc's own reader; refused, nothing is built or written.
3685
+ const env = environment === undefined ? null : take(() => readCheckEnvironment(environment));
3686
+ if (requirements === undefined) {
3687
+ const got = take(() => readCheckInputs(rigDir, partsHome, source, set, allSets));
3688
+ refuseIfAny(refused);
3689
+ inp = got as CheckInputs;
3690
+ } else {
3623
3691
  const got = take(() => readCheckInputs(rigDir, partsHome, source, set, allSets));
3624
3692
  reqFile = take(() => readRequirements(requirements));
3625
3693
  refuseIfAny(refused);
@@ -3638,7 +3706,29 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
3638
3706
  }
3639
3707
  refuseIfAny(refused);
3640
3708
  }
3709
+ // Issue #538: a motion with no animation gives check no render a schedule could pose — every frame it reads would be
3710
+ // the setup still's — so the flag is refused rather than recorded over readings it did not move.
3711
+ if (env !== null && !(isRecord(inp.motion.animations) && Object.keys(inp.motion.animations).length > 0)) {
3712
+ throw environmentRefused(env.path, `${inp.motionPath} holds no animation, so check renders no frame a schedule could pose — the setup-pose stills take none; rigc render reads a schedule only over an animation's frames`);
3713
+ }
3641
3714
  const rigcEntry = readRigcEntry(requireRigcVersion(rigc));
3715
+ /**
3716
+ * Issue #538: a render whose frames a bar or a warning reads, with the physics on — posed under the schedule when
3717
+ * `--environment` names one (the path as given; rigc reads the file the same way). A refusal rigc render prints of
3718
+ * the schedule against this rig (its `--environment <path>:` line) is carried as {@link ENVIRONMENT_RULE}, verbatim;
3719
+ * any other failure is the call site's to name. Without the flag it is `rigc`, and no argument moves.
3720
+ */
3721
+ const measured: RigcRunner =
3722
+ env === null
3723
+ ? rigc
3724
+ : (args) => {
3725
+ const call = rigc([...args, '--environment', env.path]);
3726
+ if (call.status !== 0) {
3727
+ const said = call.out.split('\n').map((l) => l.trim()).find((l) => l.startsWith(`rigc: --environment ${env.path}: `));
3728
+ if (said !== undefined) throw environmentRefused(env.path, `${said.slice('rigc: '.length)}${rigcRanClause(call)}`);
3729
+ }
3730
+ return call;
3731
+ };
3642
3732
  const out = resolve(outDir);
3643
3733
  mkdirSync(out, { recursive: true });
3644
3734
  const buildDir = join(out, 'build');
@@ -3709,7 +3799,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
3709
3799
  const levelProblems: Problem[] = [];
3710
3800
  try {
3711
3801
  if (inp.idleDuration !== null) {
3712
- const render = rigc(['render', '--candidate', buildDir, '--animation', 'idle', '--fps', String(IDLE_FPS), '--max', String(IDLE_MAX_PX), '--geometry', '--out', idleDir]);
3802
+ const render = measured(['render', '--candidate', buildDir, '--animation', 'idle', '--fps', String(IDLE_FPS), '--max', String(IDLE_MAX_PX), '--geometry', '--out', idleDir]);
3713
3803
  if (render.status !== 0) refuseIfAny(rigcFailed('render --animation idle --geometry', render, render.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
3714
3804
  idle = readFrameSet(idleDir);
3715
3805
  const last = idle.frames[idle.frames.length - 1];
@@ -3784,7 +3874,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
3784
3874
  // Issue #348: with a foot to read, the keyed render writes each animation's geometry as well.
3785
3875
  const geometry = feet.length > 0 ? ['--geometry'] : [];
3786
3876
  if (stripped === null) {
3787
- const fr = rigc(['render', '--candidate', buildDir, '--folds', ...geometry, '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), '--out', foldDir]);
3877
+ const fr = measured(['render', '--candidate', buildDir, '--folds', ...geometry, '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), '--out', foldDir]);
3788
3878
  if (fr.status !== 0) refuseIfAny(rigcFailed(`render --folds${geometry.map((g) => ` ${g}`).join('')} --fps ${fps}`, fr, fr.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
3789
3879
  const readings = filterFolds(readFoldSets(foldDir, animationNames, fps, fr.out));
3790
3880
  folds = foldsLine(animationNames, fps, 0, readings, mayFoldForRun, reqFile === null ? null : reqFile.path, foldProblems, readings, inp.rig, []);
@@ -3800,8 +3890,10 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
3800
3890
  } else {
3801
3891
  const onDir = join(foldDir, 'on');
3802
3892
  const offDir = join(foldDir, 'off');
3803
- const frOn = rigc(['render', '--candidate', buildDir, '--folds', '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), '--out', onDir]);
3893
+ const frOn = measured(['render', '--candidate', buildDir, '--folds', '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), '--out', onDir]);
3804
3894
  if (frOn.status !== 0) refuseIfAny(rigcFailed(`render --folds --fps ${fps}`, frOn, frOn.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
3895
+ // The physics-off half takes no schedule (issue #538): its candidate declares no physics constraint, so no
3896
+ // world moves it, and rigc render refuses a schedule on it by name.
3805
3897
  const frOff = rigc(['render', '--candidate', keyedBuild('the animations with their physics constraint(s) left out'), '--folds', ...geometry, '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), '--out', offDir]);
3806
3898
  if (frOff.status !== 0) refuseIfAny(rigcFailed(`render --folds${geometry.map((g) => ` ${g}`).join('')} --fps ${fps} (physics constraint(s) left out)`, frOff, frOff.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
3807
3899
  const readingsOn = filterFolds(readFoldSets(onDir, animationNames, fps, frOn.out));
@@ -3828,7 +3920,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
3828
3920
  // 3b. the parts a judgement reads alone: each rendered by its own slots, on the whole rig's grid
3829
3921
  const isolated = (label: string, ps: readonly PartRecord[]): FrameSet => {
3830
3922
  const dir = join(isoDir, label);
3831
- const r = rigc(['render', '--candidate', buildDir, '--animation', 'idle', '--fps', String(IDLE_FPS), '--max', String(IDLE_MAX_PX), '--slot', ps.map((p) => p.name).join(','), '--out', dir]);
3923
+ const r = measured(['render', '--candidate', buildDir, '--animation', 'idle', '--fps', String(IDLE_FPS), '--max', String(IDLE_MAX_PX), '--slot', ps.map((p) => p.name).join(','), '--out', dir]);
3832
3924
  if (r.status !== 0) refuseIfAny(rigcFailed(`render --animation idle --slot ${ps.map((p) => p.name).join(',')}`, r, r.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
3833
3925
  return readFrameSet(dir);
3834
3926
  };
@@ -3853,7 +3945,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
3853
3945
  if (b.status !== 0) refuseIfAny(rigcFailed(`${packedBuildLabel(mode)} (BREATH_VISIBLE's copy, the idle beside it with its breath tracks held at rest)`, b, buildGateLines(b.out)));
3854
3946
  const slots = ps.map((p) => p.name).join(',');
3855
3947
  const render = (animation: string, label: string): FrameSet => {
3856
- const r = rigc(['render', '--candidate', join(dir, 'build'), '--animation', animation, '--fps', String(IDLE_FPS), '--max', String(IDLE_MAX_PX), '--slot', slots, '--out', join(dir, label)]);
3948
+ const r = measured(['render', '--candidate', join(dir, 'build'), '--animation', animation, '--fps', String(IDLE_FPS), '--max', String(IDLE_MAX_PX), '--slot', slots, '--out', join(dir, label)]);
3857
3949
  if (r.status !== 0) refuseIfAny(rigcFailed(`render --animation ${animation} --slot ${slots} (BREATH_VISIBLE's copy)`, r, r.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
3858
3950
  return readFrameSet(join(dir, label));
3859
3951
  };
@@ -4003,7 +4095,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
4003
4095
  rmSync(seamMotionDir, { recursive: true, force: true });
4004
4096
  try {
4005
4097
  const list = read.map((p) => `${p.a}:${p.b}`).join(',');
4006
- const r = rigc(['render', '--candidate', buildDir, '--seam', list, '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), '--out', seamMotionDir]);
4098
+ const r = measured(['render', '--candidate', buildDir, '--seam', list, '--fps', String(fps), '--max', String(FOLD_RENDER_MAX), '--out', seamMotionDir]);
4007
4099
  if (r.status !== 0) refuseIfAny(rigcFailed(`render --seam ${list} --fps ${fps}`, r, r.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
4008
4100
  motionSeam = motionSeamLine(pairs, animationNames, fps, readMotionSeams(seamMotionDir, animationNames, fps, read));
4009
4101
  } finally {
@@ -4183,7 +4275,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
4183
4275
 
4184
4276
  // 5. the scene's declared requirements (issue #93), only under --requirements
4185
4277
  const reqProblems: Problem[] = [];
4186
- const reqBlock = reqFile === null ? null : measureRequirements(inp, reqFile, buildDir, out, rigc, reqProblems, seams ?? new Map());
4278
+ const reqBlock = reqFile === null ? null : measureRequirements(inp, reqFile, buildDir, out, rigc, reqProblems, seams ?? new Map(), measured);
4187
4279
 
4188
4280
  const skipped: { loop?: string; seam?: string } = {};
4189
4281
  if (inp.noIdle !== null) skipped.loop = inp.noIdle;
@@ -4192,6 +4284,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
4192
4284
  gate_spine_html_green: htmlGreen,
4193
4285
  rigc_entry: rigcEntry,
4194
4286
  pack_mode: { page_edges: mode.pageEdges, pack_shape: mode.packShape },
4287
+ ...(env === null ? {} : { environment: env }),
4195
4288
  loop_max_diff: loop === null ? null : loop.max,
4196
4289
  ...(loopPhysics === null ? {} : { loop_physics: loopPhysics }),
4197
4290
  seam_mean: seam === null ? null : round3(seam.mean),
@@ -4329,7 +4422,7 @@ const REQUIREMENTS_SCRATCH = '_requirements';
4329
4422
  * `CHECK_RIGC_GREEN`, quoting rigc. Lines go into the returned block; each
4330
4423
  * FAIL and NOT MEASURABLE into `problems`.
4331
4424
  */
4332
- export function measureRequirements(inp: CheckInputs, file: RequirementsFile, buildDir: string, out: string, rigc: RigcRunner, problems: Problem[], seams: ReadonlyMap<string, readonly SeamPair[]> = new Map()): RequirementsBlock {
4425
+ export function measureRequirements(inp: CheckInputs, file: RequirementsFile, buildDir: string, out: string, rigc: RigcRunner, problems: Problem[], seams: ReadonlyMap<string, readonly SeamPair[]> = new Map(), render: RigcRunner = rigc): RequirementsBlock {
4333
4426
  const reqDir = join(out, REQUIREMENTS_DIR);
4334
4427
  const scratch = join(out, REQUIREMENTS_SCRATCH);
4335
4428
  for (const d of [reqDir, scratch]) rmSync(d, { recursive: true, force: true });
@@ -4350,7 +4443,7 @@ export function measureRequirements(inp: CheckInputs, file: RequirementsFile, bu
4350
4443
  return b.dir;
4351
4444
  };
4352
4445
  const posesOf = (candidate: string, animation: string, dir: string, label: string): { poses: Poses; geo: IdleGeometry; path: string } => {
4353
- const r = rigc(['render', '--candidate', candidate, '--animation', animation, '--fps', String(file.fps), '--max', String(IDLE_MAX_PX), '--geometry', '--out', dir]);
4446
+ const r = render(['render', '--candidate', candidate, '--animation', animation, '--fps', String(file.fps), '--max', String(IDLE_MAX_PX), '--geometry', '--out', dir]);
4354
4447
  if (r.status !== 0) refuseIfAny(rigcFailed(`render --animation ${animation} --geometry (${label})`, r, r.out.split('\n').filter((l) => l.includes('FAIL') || l.includes('rigc:'))));
4355
4448
  const set = readFrameSet(dir);
4356
4449
  if (set.written !== set.sampled || set.stride !== 1) {
@@ -0,0 +1,67 @@
1
+ /**
2
+ * `propose --cloth … --write-config <out.json>` (issue #537): the `--cloth` config's own text with the sections the
3
+ * recipe drafts spliced in, the way `mesh-draft` writes its config ({@link splicedEdits}). The producer is the one
4
+ * writer of its own config; a reviewer that edits a recipe rebuilds through it.
5
+ *
6
+ * What is spliced is measured, not listed: the same parts drafted twice, once with the recipe and once without it
7
+ * (`cloth: null`), and each config section of the proposal ({@link PROPOSAL_CONFIG_SECTIONS}) whose value differs
8
+ * between the two is drafted ({@link clothConfigEdits}). An object section (`meshes`, `regions`, `motion`) is
9
+ * spliced entry by entry — `meshes.<part>` and `regions.<part>` for each part the recipe moved, `motion.tracks` and
10
+ * not the author's `animations_from` — and an array section (`bones`, `constraints`) whole: the drafted array
11
+ * replaces the input's, so a bone the author added by hand does not survive a write. A section the recipe does not
12
+ * move keeps the input's bytes.
13
+ */
14
+
15
+ import { PartsError } from './errors.ts';
16
+ import { type ConfigEdit, splicedEdits } from './meshdraft.ts';
17
+ import { PROPOSAL_CONFIG_SECTIONS, type Proposal } from './propose.ts';
18
+
19
+ function isPlain(v: unknown): v is Record<string, unknown> {
20
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
21
+ }
22
+
23
+ /**
24
+ * The edits that turn a config holding the draft without the recipe (`plain`) into one holding the draft with it
25
+ * (`drafted`): for each config section whose value differs, an object section entry by entry (an entry the recipe
26
+ * removed, such as a part it took from `regions` into `meshes`, is removed) and any other section whole.
27
+ */
28
+ export function clothConfigEdits(drafted: Proposal, plain: Proposal): ConfigEdit[] {
29
+ const edits: ConfigEdit[] = [];
30
+ const d = drafted as unknown as Record<string, unknown>;
31
+ const p = plain as unknown as Record<string, unknown>;
32
+ for (const section of PROPOSAL_CONFIG_SECTIONS) {
33
+ const a = p[section];
34
+ const b = d[section];
35
+ if (JSON.stringify(a) === JSON.stringify(b)) continue;
36
+ if (isPlain(a) && isPlain(b)) {
37
+ for (const k of [...Object.keys(b), ...Object.keys(a).filter((k) => !(k in b))]) {
38
+ if (JSON.stringify(a[k]) !== JSON.stringify(b[k])) edits.push({ path: [section, k], value: b[k] });
39
+ }
40
+ } else edits.push({ path: [section], value: b });
41
+ }
42
+ return edits;
43
+ }
44
+
45
+ /**
46
+ * The config `--write-config` writes: `text` (the `--cloth` config at `where`) with {@link clothConfigEdits} spliced
47
+ * in. Refused, `PROPOSE_WRITE_CONFIG_SPLICE`, when the spliced text does not parse to the input with those edits
48
+ * made — the text states a key twice, so the edit lands on one and the parse keeps the other.
49
+ */
50
+ export function writtenClothConfig(where: string, text: string, edits: readonly ConfigEdit[]): string {
51
+ const r = splicedEdits(text, edits);
52
+ if (r.moved !== null) {
53
+ throw new PartsError([
54
+ {
55
+ code: 'PROPOSE_WRITE_CONFIG_SPLICE',
56
+ object: where,
57
+ detail: `the drafted sections spliced into this text do not parse to the config with them set: ${r.moved} moved (the text states a key twice, so the splice lands on the first and the parse keeps the last); state each key once`,
58
+ },
59
+ ]);
60
+ }
61
+ return r.text;
62
+ }
63
+
64
+ /** The paths the edits name, dotted, in order: what the write line prints. */
65
+ export function editPaths(edits: readonly ConfigEdit[]): string[] {
66
+ return edits.map((e) => e.path.join('.'));
67
+ }
package/src/meshdraft.ts CHANGED
@@ -483,8 +483,11 @@ export function partsNamed(p: Problem, among: readonly string[], seams: { draft:
483
483
  // the config written: the input's own text, with the drafted entries spliced in
484
484
  // ---------------------------------------------------------------------------
485
485
 
486
- /** Where a JSON value starts and ends in a text, by a path of object keys. Throws when the path does not resolve. */
487
- export function jsonValueSpan(text: string, path: readonly string[]): { start: number; end: number } {
486
+ /**
487
+ * Where a JSON value starts and ends in a text, by a path of object keys, and (for a non-empty path) where the key
488
+ * naming it starts (`key`, its opening quote). Throws when the path does not resolve.
489
+ */
490
+ export function jsonValueSpan(text: string, path: readonly string[]): { start: number; end: number; key?: number } {
488
491
  let i = 0;
489
492
  const ws = (): void => {
490
493
  while (i < text.length && /\s/.test(text[i])) i++;
@@ -530,22 +533,27 @@ export function jsonValueSpan(text: string, path: readonly string[]): { start: n
530
533
  }
531
534
  while (i < text.length && !/[\s,}\]]/.test(text[i])) i++;
532
535
  };
533
- const find = (depth: number): { start: number; end: number } => {
536
+ let keyAt: number | undefined;
537
+ const find = (depth: number): { start: number; end: number; key?: number } => {
534
538
  ws();
535
539
  if (depth === path.length) {
536
540
  const start = i;
537
541
  skip();
538
- return { start, end: i };
542
+ return keyAt === undefined ? { start, end: i } : { start, end: i, key: keyAt };
539
543
  }
540
544
  if (text[i] !== '{') throw new Error(`jsonValueSpan: ${path.slice(0, depth).join('.') || 'the document'} is not an object`);
541
545
  i++;
542
546
  for (;;) {
543
547
  ws();
544
548
  if (text[i] === '}') throw new Error(`jsonValueSpan: no key "${path[depth]}" at ${path.slice(0, depth).join('.') || 'the top'}`);
549
+ const at = i;
545
550
  const key = str();
546
551
  ws();
547
552
  i++; // ':'
548
- if (key === path[depth]) return find(depth + 1);
553
+ if (key === path[depth]) {
554
+ keyAt = at;
555
+ return find(depth + 1);
556
+ }
549
557
  skip();
550
558
  ws();
551
559
  if (text[i] === ',') i++;
@@ -554,25 +562,111 @@ export function jsonValueSpan(text: string, path: readonly string[]): { start: n
554
562
  return find(0);
555
563
  }
556
564
 
565
+ /** One edit {@link splicedEdits} makes: the value at `path` set (replaced, or inserted when absent), or, `undefined`, removed. */
566
+ export interface ConfigEdit {
567
+ path: readonly string[];
568
+ value: unknown;
569
+ }
570
+
571
+ /** The span at `path`, or null where the path does not resolve (a key absent, or a step that is not an object). */
572
+ function spanOrNull(text: string, path: readonly string[]): { start: number; end: number; key?: number } | null {
573
+ try {
574
+ return jsonValueSpan(text, path);
575
+ } catch {
576
+ return null;
577
+ }
578
+ }
579
+
580
+ /** The white space a line starts with, for the line `at` lies on. */
581
+ function indentAt(text: string, at: number): string {
582
+ const lineStart = text.lastIndexOf('\n', at) + 1;
583
+ return /^[ \t]*/.exec(text.slice(lineStart))?.[0] ?? '';
584
+ }
585
+
586
+ /** One edit on `text`; every byte it does not name is the input's. */
587
+ function spliceOne(text: string, path: readonly string[], value: unknown): string {
588
+ const at = spanOrNull(text, path);
589
+ if (value === undefined) {
590
+ if (at === null || at.key === undefined) return text;
591
+ // The member and one comma beside it: the one before it, or (the first member) the one after it.
592
+ let before = at.key - 1;
593
+ while (before >= 0 && /\s/.test(text[before])) before--;
594
+ if (text[before] === ',') return `${text.slice(0, before)}${text.slice(at.end)}`;
595
+ let after = at.end;
596
+ while (after < text.length && /\s/.test(text[after])) after++;
597
+ if (text[after] === ',') {
598
+ after++;
599
+ while (after < text.length && /\s/.test(text[after])) after++;
600
+ return `${text.slice(0, at.key)}${text.slice(after)}`;
601
+ }
602
+ return `${text.slice(0, at.key)}${text.slice(at.end)}`;
603
+ }
604
+ if (at !== null) {
605
+ const body = JSON.stringify(value, null, 2).split('\n').join(`\n${indentAt(text, at.start)}`);
606
+ return `${text.slice(0, at.start)}${body}${text.slice(at.end)}`;
607
+ }
608
+ const parentPath = path.slice(0, -1);
609
+ const parent = spanOrNull(text, parentPath);
610
+ // A parent the text lacks is inserted whole, holding this one member.
611
+ if (parent === null) return spliceOne(text, parentPath, { [path[path.length - 1]]: value });
612
+ if (text[parent.start] !== '{') throw new Error(`splicedEdits: ${parentPath.join('.') || 'the document'} is not an object`);
613
+ const indent = `${indentAt(text, parent.start)} `;
614
+ const member = `"${path[path.length - 1]}": ${JSON.stringify(value, null, 2).split('\n').join(`\n${indent}`)}`;
615
+ let last = parent.end - 2;
616
+ while (last > parent.start && /\s/.test(text[last])) last--;
617
+ if (last === parent.start) return `${text.slice(0, parent.start + 1)}\n${indent}${member}\n${indentAt(text, parent.start)}${text.slice(parent.end - 1)}`;
618
+ return `${text.slice(0, last + 1)},\n${indent}${member}${text.slice(last + 1)}`;
619
+ }
620
+
621
+ /** The first path, depth first in the intended document's key order, where `got` and `want` differ. */
622
+ function firstMoved(got: unknown, want: unknown, path: readonly string[]): string | null {
623
+ const plain = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
624
+ if (plain(got) && plain(want)) {
625
+ for (const k of [...Object.keys(want), ...Object.keys(got).filter((k) => !(k in want))]) {
626
+ const m = firstMoved(got[k], want[k], [...path, k]);
627
+ if (m !== null) return m;
628
+ }
629
+ return null;
630
+ }
631
+ return JSON.stringify(got) === JSON.stringify(want) ? null : path.join('.') || 'the document';
632
+ }
633
+
557
634
  /**
558
- * The config written: `text` with `meshes.<part>` replaced for every part in `drafted`, each entry as
559
- * `JSON.stringify(entry, null, 2)` indented to the line its key starts on. Every other byte is the input's, so a
560
- * config with nothing drafted is written byte for byte as read, and a part that keeps its lattice keeps its text.
561
- * The result is parsed and held to the intended document before it is returned.
635
+ * The input's own text with each edit made in order: a value present is replaced, as `JSON.stringify(value, null, 2)`
636
+ * indented to the line it starts on; one absent is inserted as the last member of its object (an absent parent
637
+ * inserted with it); `undefined` removes the member. Every other byte is the input's. The result is parsed and held
638
+ * to the intended document — the input parsed with the same edits made on it — and `moved` names the first path
639
+ * where it is not (a key the text states twice is the way it is not: the edit lands on the first, the parse keeps the
640
+ * last); null when it is.
562
641
  */
563
- export function splicedConfig(text: string, drafted: ReadonlyMap<string, unknown>): string {
564
- const spans = [...drafted.keys()].map((part) => ({ part, ...jsonValueSpan(text, ['meshes', part]) })).sort((a, b) => b.start - a.start);
642
+ export function splicedEdits(text: string, edits: readonly ConfigEdit[]): { text: string; moved: string | null } {
565
643
  let out = text;
566
- for (const s of spans) {
567
- const lineStart = out.lastIndexOf('\n', s.start) + 1;
568
- const indent = /^\s*/.exec(out.slice(lineStart, s.start))?.[0] ?? '';
569
- const body = JSON.stringify(drafted.get(s.part), null, 2).split('\n').join(`\n${indent}`);
570
- out = `${out.slice(0, s.start)}${body}${out.slice(s.end)}`;
644
+ for (const e of edits) out = spliceOne(out, e.path, e.value);
645
+ const want = JSON.parse(text) as Record<string, unknown>;
646
+ for (const e of edits) {
647
+ let o = want;
648
+ for (const k of e.path.slice(0, -1)) {
649
+ if (typeof o[k] !== 'object' || o[k] === null) o[k] = {};
650
+ o = o[k] as Record<string, unknown>;
651
+ }
652
+ const last = e.path[e.path.length - 1];
653
+ if (e.value === undefined) delete o[last];
654
+ else o[last] = e.value;
571
655
  }
572
- const want = JSON.parse(text) as { meshes: Record<string, unknown> };
573
- for (const [part, entry] of drafted) want.meshes[part] = entry;
574
- if (JSON.stringify(JSON.parse(out)) !== JSON.stringify(want)) throw new Error('splicedConfig: the spliced text does not parse to the intended config');
575
- return out;
656
+ return { text: out, moved: firstMoved(JSON.parse(out), want, []) };
657
+ }
658
+
659
+ /**
660
+ * The config written: `text` with `meshes.<part>` replaced for every part in `drafted`, each entry as
661
+ * `JSON.stringify(entry, null, 2)` indented to the line its key starts on ({@link splicedEdits}). Every other byte is
662
+ * the input's, so a config with nothing drafted is written byte for byte as read, and a part that keeps its lattice
663
+ * keeps its text. The result is parsed and held to the intended document before it is returned.
664
+ */
665
+ export function splicedConfig(text: string, drafted: ReadonlyMap<string, unknown>): string {
666
+ for (const part of drafted.keys()) jsonValueSpan(text, ['meshes', part]);
667
+ const r = splicedEdits(text, [...drafted].map(([part, entry]) => ({ path: ['meshes', part], value: entry })));
668
+ if (r.moved !== null) throw new Error('splicedConfig: the spliced text does not parse to the intended config');
669
+ return r.text;
576
670
  }
577
671
 
578
672
  /** A path in a config the loader resolves against the config's directory, and how to set it. */