rig-parts 2.57.0 → 2.59.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/README.md CHANGED
@@ -278,6 +278,7 @@ Command details and config saving are in the [command reference](docs/AUTHORING.
278
278
  | `diff-components` | [List every place the stacked parts differ from the painting](docs/AUTHORING.md#whole-figure-difference-inventory) |
279
279
  | `diff-drafts` | [Compare two assemble outputs](docs/AUTHORING.md#command-reference) |
280
280
  | `depth-prepare` | [Write one depth-model input image per part](docs/DEPTH.md#1-prepare-one-inference-image-per-part) |
281
+ | `depth-map` | [Convert a NumPy array to a depth or normals map](docs/DEPTH.md#convert-a-numpy-array) |
281
282
  | `depth-bind` | [Bind a depth map to its prepared input](docs/DEPTH.md#3-bind-every-map-to-its-prepared-input) |
282
283
  | `depth-apply` | [Apply depth maps to the parts as depth sheets](docs/DEPTH.md#4-apply-the-maps-as-depth-sheets) |
283
284
  | `edited-part` | [Record an edited part receipt](docs/AUTHORING.md#edited-rig-space-parts-assembleedited_parts-issue-1278) |
package/cli.ts CHANGED
@@ -4,6 +4,8 @@ import { diffComponentsCommand } from './src/diffcomponents.ts';
4
4
  import { DIFF_DRAFTS_SPEC, diffDraftsCommand } from './src/diffdrafts.ts';
5
5
  import { applyTakenLayers } from './src/takelayers.ts';
6
6
  import { applyDepth, bindDepthMap, prepareDepth } from './src/depthworkflow.ts';
7
+ import { depthMapFail } from './src/depthmaps.ts';
8
+ import { modelArrayMap, serializeModelArrayMap } from './src/modelarray.ts';
7
9
  import { externalReceipt } from './src/externalreceipt.ts';
8
10
  import { BUST_LANDMARKS_ACT_SCHEMA, BUST_LANDMARKS_COMMENT_ACT_SCHEMA, BUST_LANDMARKS_PROVENANCE_SPEC, BUST_LANDMARKS_PROVENANCE_SUFFIX, BUST_POINT_SHAPE_FIELDS, bustShapeClause, type BustSidecar, effectiveBustShape, planBustLandmarks, readBustSidecar, stageBustLandmarks, stageReplacements, type StagedBustLandmarks } from './src/bustlandmarks.ts';
9
11
  import { writeEditedPart } from './tools/edited-part-cli.ts';
@@ -21,7 +23,7 @@ import { writeEditedPart } from './tools/edited-part-cli.ts';
21
23
  */
22
24
  import { spawnSync } from 'node:child_process';
23
25
  import { runBuildProcess, processRigcRunner as rigcRunner } from './tools/build-process.ts';
24
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
26
+ import { existsSync, linkSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
25
27
  import { tmpdir } from 'node:os';
26
28
  import { basename, dirname, extname, join, resolve } from 'node:path';
27
29
  import { DEFAULT_PROJECT_RULE, DEFAULT_SEAM_RULE, headGarmentOverlaps, headGarmentWarning, HOLES_LISTED, PROJECT_RULES, type ProjectRule, proposeFields, proposePlan, proposeSinglePlan, SEAM_RULES, type SeamRule } from './src/assemble.ts';
@@ -51,7 +53,7 @@ import { chainsLeftBehind, clothConfigEdits, editPaths, plainCount, previousCoun
51
53
  import { INPUT_CHECK_FILE, INPUT_CHECK_SPEC, PROVENANCE_FILE, REMESH_SPEC, remeshStage } from './src/remesh.ts';
52
54
  import { RETUNE_FILE, RETUNE_SPEC, retuneStage } from './src/retune.ts';
53
55
  import { checkPainting, DEFAULT_PAINTING_FORM, isPaintingForm, PAINTING_FORMS, paintingFormOf } from './src/paintcheck.ts';
54
- import { readPng, writePng } from './src/raster/png.ts';
56
+ import { decodePngBytes, readPng, writePng } from './src/raster/png.ts';
55
57
  import { REQUIREMENTS_SENTENCE } from './src/requirements.ts';
56
58
  import { composeStage, IMAGE_SEP, PLATE, PROVENANCES, SCENE_REPORT_FILE, SCENE_REPORT_SPEC, SCENE_SPEC } from './src/scene.ts';
57
59
  import { buildSheet, defaultCaption, type Tile, tilesFrom } from './src/sheet.ts';
@@ -100,6 +102,12 @@ usage:
100
102
  Write per-part inference PNGs on neutral gray, upscaled and padded as
101
103
  declared, plus a source-hashed manifest. No model is bundled or called.
102
104
 
105
+ rig-parts depth-map --array <file.npy> --input <prepared.png> --kind <depth|normals>
106
+ --part <name> --out <map.json> [--padding LEFT,TOP,RIGHT,BOTTOM]
107
+ Convert little-endian float32/float64 C-order NumPy values to rig-parts-map/1.
108
+ Crop declared array padding before integer box pooling to the prepared PNG
109
+ size. Normalize signed XYZ normals after pooling. Print the depth-bind command.
110
+
103
111
  rig-parts depth-bind --map <numeric-map.json> --input <prepared.png> --part <name>
104
112
  Write <map>.binding.json with both file hashes; never overwrite a receipt.
105
113
  Attests the current files, not that inference used this input.
@@ -973,9 +981,9 @@ usage:
973
981
  [--idle-keys ctl|direct] [--lead-in <periods>] [--seam-pairs] [--keep-stills] [--no-extremes]
974
982
  [--alt <name>=<source>:<full>[:<head>]] [--set <name> | --all-sets]
975
983
  [--environment <schedule.json>] [--wind-band <spec.json>]
976
- build-run.json (rig-run/2, as check-run.json for check) records a run whose
977
- check completed, with argv starting "build": these arguments reproduce the
978
- check with the same package version, run from the --out directory.
984
+ build-run.json (rig-run/3, STABILITY) records a run whose check completed,
985
+ with input paths and SHA-256 digests. Its argv reproduces the check with
986
+ the same package version, run from the --out directory.
979
987
  assemble, then rig, then check, in one process, each stage's own lines
980
988
  printed under [assemble], [rig] and [check]; the first stage that refuses
981
989
  stops the build with its own FAIL lines. The config must already carry
@@ -1260,6 +1268,7 @@ const TAKES = {
1260
1268
  'bust-landmarks': { valued: ['--from-act', '--parts', '--config', '--out'], switches: ['--write-config', '--help'] },
1261
1269
  'diff-components': { valued: ['--stack', '--painting', '--parts', '--figure', '--floor', '--threshold', '--out', '--verify'], switches: ['--owners', '--help'] },
1262
1270
  'diff-drafts': { valued: ['--left', '--right', '--out'], switches: ['--help'] },
1271
+ 'depth-map': { valued: ['--array', '--input', '--kind', '--part', '--out', '--padding'], switches: ['--help'] },
1263
1272
  'depth-bind': { valued: ['--map', '--input', '--part'], switches: ['--help'] },
1264
1273
  'depth-prepare': { valued: ['--parts', '--config', '--out'], switches: ['--help'] },
1265
1274
  'depth-apply': { valued: ['--parts', '--manifest', '--config', '--rig-config', '--out', '--groups'], switches: ['--help'] },
@@ -2511,6 +2520,9 @@ function cmdBuild(args: string[]): number {
2511
2520
  }
2512
2521
  const [config, source, full, out] = ['--config', '--source', '--full', '--out'].map((f) => flags.get(f) as string);
2513
2522
  const head = flags.get('--head') ?? null;
2523
+ const requirements = flags.get('--requirements');
2524
+ const environment = flags.get('--environment');
2525
+ const windBand = flags.get('--wind-band');
2514
2526
  let bin: string;
2515
2527
  let fixedClock: string | undefined;
2516
2528
  let pkg: { name: string; version: string };
@@ -2526,7 +2538,7 @@ function cmdBuild(args: string[]): number {
2526
2538
  const scratch = mkdtempSync(join(tmpdir(), 'rig-parts-build-'));
2527
2539
  try {
2528
2540
  const r = build(
2529
- { config, source, full, head, out, ...(seam === undefined ? {} : { seam: seam as SeamRule }), ...(project === undefined ? {} : { project: project as ProjectRule }), loop, pageEdges: edges, packShape: shape, ...(size === undefined ? {} : { pageSize: size }), ...(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'), noExtremes: on.has('--no-extremes'), ...(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 } : {}), ...(flags.has('--wind-band') ? { windBand: flags.get('--wind-band') as string } : {}) },
2541
+ { config, source, full, head, out, ...(seam === undefined ? {} : { seam: seam as SeamRule }), ...(project === undefined ? {} : { project: project as ProjectRule }), loop, pageEdges: edges, packShape: shape, ...(size === undefined ? {} : { pageSize: size }), ...(requirements === undefined ? {} : { requirements }), idleKeys: keys, ...(leadText === undefined ? {} : { leadIn: Number(leadText) }), seamPairs: on.has('--seam-pairs'), keepStills: on.has('--keep-stills'), noExtremes: on.has('--no-extremes'), ...(alts.length === 0 ? {} : { alts }), ...(flags.has('--set') ? { set: flags.get('--set') as string } : {}), allSets: on.has('--all-sets'), ...(environment === undefined ? {} : { environment }), ...(windBand === undefined ? {} : { windBand }) },
2530
2542
  { rig: rigcRunner(bin), check: rigcRunner(bin), checkBin: bin, scratch: join(scratch, 'rig-gate'), stages: {
2531
2543
  assemble: (input, outputs) => runBuildProcess({ stage: 'assemble', bin, input, outputs }, join(scratch, 'workers')),
2532
2544
  rig: (input, _rigc, gateScratch) => runBuildProcess({ stage: 'rig', bin, input, scratch: gateScratch }, join(scratch, 'workers')),
@@ -2536,8 +2548,10 @@ function cmdBuild(args: string[]): number {
2536
2548
  );
2537
2549
  // Issue #1541: written whenever this build's check completed its report, green or not.
2538
2550
  if (r.check !== null) {
2551
+ const cwd = process.cwd();
2539
2552
  writeRunRecord({ pkg, command: 'build', startedAt, finishedAt: fixedClock ?? new Date().toISOString(), outDir: out, configPath: config,
2540
- outputs: [...BUILD_OWNS, ...BUILD_OWNS_FILES], argv: recordArgv('build', args, BUILD_ARGV, out, process.cwd()) });
2553
+ inputs: { cwd, source, full, head, requirements, environment, windBand, alts },
2554
+ outputs: [...BUILD_OWNS, ...BUILD_OWNS_FILES], argv: recordArgv('build', args, BUILD_ARGV, out, cwd) });
2541
2555
  }
2542
2556
  return r.stoppedAt === null ? EXIT_OK : EXIT_REFUSED;
2543
2557
  } finally {
@@ -2945,6 +2959,60 @@ function cmdBustLandmarks(args: string[]): number {
2945
2959
  } catch (error) { return printRefusal(error); }
2946
2960
  }
2947
2961
 
2962
+ function readDepthMapInput(file: string): Uint8Array {
2963
+ try {
2964
+ if (!statSync(file).isFile()) throw new Error('found a nonregular file');
2965
+ return readFileSync(file);
2966
+ } catch (error) {
2967
+ return depthMapFail('DEPTH_INPUT_PRESENT', JSON.stringify(file),
2968
+ `read failed (${JSON.stringify(error instanceof Error ? error.message : String(error))}); required a readable regular file`);
2969
+ }
2970
+ }
2971
+
2972
+ function writeDepthMapFile(out: string, contents: string): void {
2973
+ try {
2974
+ const stage = mkdtempSync(join(realpathSync(dirname(out)), '.depth-map-'));
2975
+ try {
2976
+ const candidate = join(stage, 'map.json');
2977
+ writeFileSync(candidate, contents, { flag: 'wx' });
2978
+ // Publish complete bytes exclusively, including when two writers race for --out.
2979
+ linkSync(candidate, out);
2980
+ } finally {
2981
+ rmSync(stage, { recursive: true, force: true });
2982
+ }
2983
+ } catch (error) {
2984
+ const code = error !== null && typeof error === 'object' && 'code' in error ? String(error.code) : 'unknown error';
2985
+ return depthMapFail('DEPTH_OUTPUT_EMPTY', JSON.stringify(out),
2986
+ `map write failed (${code}); required an absent output file in a writable directory`);
2987
+ }
2988
+ }
2989
+
2990
+ function cmdDepthMap(args: string[]): number {
2991
+ const f = flags(args, 'depth-map', ['--array', '--input', '--kind', '--part', '--out']);
2992
+ if (typeof f === 'string') return usage(f);
2993
+ const array = f.get('--array')!, input = f.get('--input')!, part = f.get('--part')!, out = f.get('--out')!;
2994
+ try {
2995
+ // Match depth-bind's accepted part names so the printed command can use the same name.
2996
+ if (!part || part.startsWith('.') || /[\\/]/.test(part) || part.includes('\0')) {
2997
+ return depthMapFail('DEPTH_MAP_BINDING', 'depth-map --part',
2998
+ `found ${JSON.stringify(part)}; required a nonempty plain part filename accepted by depth-bind`);
2999
+ }
3000
+ const raw = readDepthMapInput(array), png = readDepthMapInput(input);
3001
+ let image: ReturnType<typeof decodePngBytes>;
3002
+ try { image = decodePngBytes(png, JSON.stringify(input)); }
3003
+ catch (error) {
3004
+ return depthMapFail('DEPTH_INPUT_PRESENT', JSON.stringify(input),
3005
+ `decode failed (${JSON.stringify(error instanceof Error ? error.message : String(error))}); required a decodable prepared PNG`);
3006
+ }
3007
+ const map = modelArrayMap(raw, image, f.get('--kind')!, f.get('--padding'), JSON.stringify(array));
3008
+ writeDepthMapFile(out, serializeModelArrayMap(map));
3009
+ const quote = (value: string): string => "'" + value.replaceAll("'", "'\"'\"'") + "'";
3010
+ console.log(`depth-map: wrote ${JSON.stringify(out)} (${map.width}x${map.height}, ${map.channels} channel(s))`);
3011
+ console.log(`rig-parts depth-bind --map ${quote(out)} --input ${quote(input)} --part ${quote(part)}`);
3012
+ return EXIT_OK;
3013
+ } catch (error) { return printRefusal(error); }
3014
+ }
3015
+
2948
3016
  function cmdDepthBind(args: string[]): number {
2949
3017
  const f = flags(args, 'depth-bind', ['--map', '--input', '--part']);
2950
3018
  if (typeof f === 'string') return usage(f);
@@ -2986,6 +3054,7 @@ function main(argv: string[]): number | Promise<number> {
2986
3054
  if (command === 'diff-drafts') return cmdDiffDrafts(rest);
2987
3055
  if (command === 'layers') return cmdLayers(rest);
2988
3056
  if (command === 'depth-prepare') return cmdDepthPrepare(rest);
3057
+ if (command === 'depth-map') return cmdDepthMap(rest);
2989
3058
  if (command === 'edited-part') return cmdEditedPart(rest);
2990
3059
  if (command === 'external-receipt') return cmdExternalReceipt(rest);
2991
3060
  if (command === 'bust-landmarks') return cmdBustLandmarks(rest);
package/docs/AUTHORING.md CHANGED
@@ -4045,14 +4045,18 @@ assemble/config step; this bounded draft names that refusal. Reassembly uses the
4045
4045
  CLI defaults `seam=near-white` and `project=core`, explicitly stated in its note
4046
4046
  because `parts.json` does not record the source command's selected rules.
4047
4047
 
4048
- The `note:` line derives `turn.body.unitDepths.<part>` as
4049
- `round4(bodyPivot + neckWorldMedian - firstBodySurfaceWorldMedian)`, using the
4050
- existing scalar sheet, declared `near` polarity and `zScale`. If the new source
4048
+ The draft writes the neck's world median to `turn.body.unitDepths.<part>`,
4049
+ using the existing scalar sheet, declared `near` polarity and `zScale`.
4050
+ The note also reports the projected depth the rig stage computes as
4051
+ `round4(bodyPivot + neckWorldMedian - firstBodySurfaceWorldMedian)`.
4052
+ If the new source
4051
4053
  has no sheet, only new opaque art overlapping the previous registered neck
4052
4054
  sheet is sampled. An absent sheet, empty overlap, missing body reference or
4053
4055
  missing pivot is refused by name; legacy `depth_median` is never converted to
4054
4056
  world units. Other proposal modes (`--keypoints`, `--compare`, `--grid-rule`,
4055
4057
  `--only-missing`) must run separately and are refused in this mode.
4058
+ For a config drafted before #1575, copy the neck world median from the original
4059
+ draft note into its body unit depth, or draft again from the same source.
4056
4060
 
4057
4061
  **The chest on such a config (issue #1436).** With `--bust-landmarks <file>` or
4058
4062
  `--no-bust "<reason>"` and without `--full` and `--head`, `propose --write-config`
@@ -7237,6 +7241,7 @@ and stay absent).
7237
7241
  | <a id="RIG_TURN_SURFACE_OVERLAP_SUPPORT"></a>`RIG_TURN_SURFACE_OVERLAP_SUPPORT` | a selected neighbour has missing/invalid geometry, unresolved emitted vectors, or no triangle covering the requested setup point | supply its actual shown setup triangles and existing emitted field; no nearest triangle, extrapolation or target-field fallback is used; an unrelated disconnected drawing with no actual overlap is not selected |
7238
7242
  | <a id="RIG_TURN_SURFACE_OVERLAP_DEPTH"></a>`RIG_TURN_SURFACE_OVERLAP_DEPTH` | same-group overlap neighbours demand incompatible emitted offsets at one target setup point | separate the conflicting support or provide coincident neighbour fields; the refusal names the fields and target vertex |
7239
7243
  | <a id="RIG_TURN_SURFACE_MESH_BINDINGS"></a>`RIG_TURN_SURFACE_MESH_BINDINGS` | an authored surface mesh has unresolved/nonclosing weights or shares a frame moved by a unit/rear turn carrier; declared stop draw aliases resolve to their links for setup sampling | provide weighted bindings closing at 1 in the authored frame; `<link>_d` resolves only for links declared in `config.stops`; use independent chains for parts with different roles |
7244
+ | <a id="RIG_TURN_LEGACY_FACE_WEIGHTS"></a>`RIG_TURN_LEGACY_FACE_WEIGHTS` | legacy head-turn animation derivation reaches a face mesh without the weight rows it needs to locate the face frame | configure the generated face surface through `config.turn.roles` |
7240
7245
  | <a id="RIG_TURN_SURFACE_MESH_ATTACHMENT"></a>`RIG_TURN_SURFACE_MESH_ATTACHMENT` | a surface mesh has an alternate drawing without its own registered depth sampling frame | use the base attachment; explicit islands retain their own slot, attachment and bindings |
7241
7246
  | <a id="RIG_TURN_BODY_UNCOVERED"></a>`RIG_TURN_BODY_UNCOVERED` | **Warning:** a shown part without a body role overlaps a moved `turn.body` surface at setup alpha >= 128 and has different emitted endpoint displacement | declare the intended body role and inspect both endpoints; no role or depth is inferred |
7242
7247
  | <a id="RIG_TURN_HEAD_ROLL"></a>`RIG_TURN_HEAD_ROLL` | **Warning:** a declared head turn has an absolute authored-eye-origin roll above the empirical limit displayed as 18.485385 degrees; names the face/eye parts, both eye bones, signed roll and limit | inspect the neck at both extremes; this proxy does not detect the painting independently, correct tilt or change emitted bytes; see [Head roll before a declared turn](#head-roll-before-a-declared-turn) |
@@ -7244,8 +7249,9 @@ and stay absent).
7244
7249
  | <a id="RIG_TURN_GRID_BUDGET"></a>`RIG_TURN_GRID_BUDGET` | a `"surface"` grid exceeds 2,400 triangles on one slot or 4,000 triangles across all `"surface"` slots | lower `config.turn.grid` / `config.turn.body.grid` `[cols, rows]` within the per-slot and total budgets |
7245
7250
  | <a id="RIG_TURN_HEAD_BONE"></a>`RIG_TURN_HEAD_BONE` | `buildRig` found no `"head"` (or body turn root) bone when emitting 2.5D turn carriers | declare `"head"` (or the body turn root bone) in `config.bones` |
7246
7251
  | <a id="RIG_TURN_BOUNDARY_DEPTH"></a>`RIG_TURN_BOUNDARY_DEPTH` | boundary names or sheets do not resolve; surfaces are not different, abutting without overlap in one group with common units; band is empty/outside/not boundary-reaching; declarations cycle; or grid support is missing | use exact existing parts, different abutting surfaces in one group with common near/zScale, a contained nonempty band reaching their boundary, acyclic declarations and the generated grid support |
7247
- | <a id="RIG_TURN_SHARED_DEPTH_SCALE"></a>`RIG_TURN_SHARED_DEPTH_SCALE` | `"surface"` parts bound to one head or body turn declare different `near` polarities or `zScale` values | use one shared `near` and `zScale` across all `"surface"` parts in the turn group |
7252
+ | <a id="RIG_TURN_SHARED_DEPTH_SCALE"></a>`RIG_TURN_SHARED_DEPTH_SCALE` | `"surface"` parts bound to one head or body turn declare different `near` polarities or `zScale` values | use one shared `near` and `zScale` across all `"surface"` parts in the turn group. The check runs separately for the head and body role sets, so if a surface belongs to both, use the larger required `zScale` in both groups. |
7248
7253
  | <a id="RIG_TURN_UNIT_DEPTH_REQUIRED"></a>`RIG_TURN_UNIT_DEPTH_REQUIRED` | a `"unit"` bone has neither a `unitDepths` entry nor a readable `"surface"` depth sheet | provide a `"surface"` depth sheet or an explicit `unitDepths.<part>` value |
7254
+ | <a id="RIG_TURN_BODY_UNIT_CARRIER"></a>`RIG_TURN_BODY_UNIT_CARRIER` | an explicit body unit depth has no movable carrier for its binding, or a shared carrier needs incompatible depths | bind the unit to a movable body branch and use independent branches for different depths |
7249
7255
  | <a id="RIG_TURN_UNIT_DEPTH_SUPPORT"></a>`RIG_TURN_UNIT_DEPTH_SUPPORT` | WARN only: an implicit unit depth sample is outside the source surface pixel-index bounds or its sampled art alpha is below 255 | author an explicit calibrated `unitDepths.<part>` value when this cross-part extrapolation is unintended; existing scalar sampling and refusal behavior are retained |
7250
7256
  | <a id="RIG_TURN_EAR_DEPTH_BEHIND_CHEEK"></a>`RIG_TURN_EAR_DEPTH_BEHIND_CHEEK` | an ear bone in `config.turn.roles` has a calibrated depth at or in front of the cheek surface depth | place the ear behind the cheek surface (for example via `config.turn.unitDepths`) |
7251
7257
 
@@ -9729,7 +9735,11 @@ once at the region `bone`'s setup position (requiring `alpha === 255` on the
9729
9735
  cover's art there, [`RIG_TURN_BAND_COVER_SUPPORT`](#RIG_TURN_BAND_COVER_SUPPORT),
9730
9736
  and a valid other-group surface cover,
9731
9737
  [`CONFIG_TURN_BAND_COVER`](#CONFIG_TURN_BAND_COVER)), so every band vertex takes
9732
- `g · D(z_cover)` on that group's side and stays monotone in `g`. A polygon
9738
+ `g · D(z_cover)` on that group's side and stays monotone in `g`.
9739
+ A declared cover on a stopped link raises [`CONFIG_TURN_BAND_COVER`](#CONFIG_TURN_BAND_COVER),
9740
+ and a cover whose region supplies no positive mesh influence or whose part has no
9741
+ blended attachment raises [`RIG_TURN_BAND_COVER_SUPPORT`](#RIG_TURN_BAND_COVER_SUPPORT).
9742
+ A polygon
9733
9743
  region whose edge has short segments can make the band offset cross itself,
9734
9744
  refused as `CONTOUR_PARAMETER` on `regions[i].band`: on that build, a jaw line
9735
9745
  with two extra points, its edges there 23–29 px long, crossed at any band above
@@ -9967,20 +9977,36 @@ re-run depth for these inputs, then call
9967
9977
  `rig-parts depth-bind --map <numeric-map.json> --input <prepared.png> --part <name>`. Malformed
9968
9978
  present receipts also refuse. Symlinked receipts, including dangling links, are
9969
9979
  refused; a regular file is required. Preparing again never rebinds a map.
9970
- Under the compatibility policy dated **2026-11-16**, a missing receipt preserves
9971
- legacy output bytes and exits, with one `DEPTH_MAP_BINDING_ABSENT` WARN per
9972
- selected map on stderr. This is unverified inference-input identity, not a
9980
+ Under the compatibility policy dated **2026-11-16**, an otherwise valid recipe
9981
+ can use a map with a missing receipt. This adds one `DEPTH_MAP_BINDING_ABSENT`
9982
+ WARN per selected map on stderr. This is unverified inference-input identity, not a
9973
9983
  binding pass. The provider flow calls the writer when producing a map. The writer binds these
9974
9984
  files at invocation; it cannot prove the map was inferred from that input.
9975
9985
  Parts does not run inference or invent provenance.
9976
9986
 
9977
- Apply computes `u=(raw-median(raw))/(p95-p5)` inside original alpha >=128,
9978
- using linear percentiles, then `Z=median+relief*u`. A flat map requires explicit
9979
- relief 0. Encode `Z/zScale` for near white, `1-Z/zScale` for near black, clip to
9980
- [0,1], and round to the nearest 8-bit level with even ties. Extend every
9981
- non-support pixel with the Euclidean nearest support value, with row-major ties.
9987
+ Apply computes `u=(raw-median(raw))/(p95-p5)` on original part pixels with
9988
+ alpha >= 128, using linear percentiles, then `z=median+relief*u`. A flat map
9989
+ requires explicit relief 0 and uses a zero relief offset. Every supported pixel
9990
+ must satisfy `0 < z < zScale` before encoding. `DEPTH_APPLY_CLIPPED` refuses
9991
+ any nonzero clip fraction before writing outputs. The fraction counts supported
9992
+ pixels with `z <= 0` or `z >= zScale` divided by all supported pixels.
9993
+
9994
+ For upper clipping, the refusal gives the smallest binary64 group `zScale`
9995
+ strictly above the maximum original supported depth in the group. For each part
9996
+ with lower clipping, it gives the minimum authored `median`, the next binary64
9997
+ value above the maximum of `-(relief*u)` across that part's supported pixels.
9998
+ It also gives the difference between that target and the previous authored
9999
+ median in rig pixels. Both remedies are reported when both boundaries clip.
10000
+ If no finite scale clears the upper boundary, revise the median or relief.
10001
+ If no finite median clears the lower boundary, reduce the relief.
10002
+ Recompute the group scale if changing medians changes the maximum supported
10003
+ depth, then prepare the revised recipe again.
10004
+
10005
+ Encode `z/zScale` for near white or `1-z/zScale` for near black and round to
10006
+ the nearest 8-bit level with even ties. Extend every non-support pixel with the
10007
+ Euclidean nearest support value, with row-major ties.
9982
10008
  The resulting opaque gray sheet carries no background cliff. The report names
9983
- levels, clip fraction (Z <=0 or >=zScale on support), declared relief in rig
10009
+ levels, clip fraction (zero on success), declared relief in rig
9984
10010
  pixels, group pivot, sign, raw median/p5/p95 and source/input/map/sheet hashes.
9985
10011
  It reports measurements, not a depth-quality pass mark. `rig` still runs Core's
9986
10012
  gate; apply writes parts and configuration, never a skeleton or a gate verdict.
@@ -10028,10 +10054,9 @@ same medians, group pivot and `zScale`; only the declared relief changes.
10028
10054
  Read each named report row's `relief`, `zScale` and `clipFraction` before
10029
10055
  judging its render. The clipping denominator is every original part pixel
10030
10056
  with alpha >=128, including boundary support, never the padded input area.
10031
- A low clipped fraction does not establish shape quality. Inspect setup,
10032
- both yaw endpoints and their difference at native scale, then enlarge the
10033
- same pixels with nearest-neighbour sampling. Neither clipping nor agreement
10034
- with a reference map substitutes for that inspection.
10057
+ Use those readings to confirm the calibration. To judge shape quality, inspect
10058
+ setup, both yaw endpoints and their difference at native scale, then enlarge
10059
+ the same pixels with nearest-neighbour sampling.
10035
10060
 
10036
10061
  The owner's preference for per-part volume is subjective provenance, not an
10037
10062
  automated quality conclusion. Model licence posture remains the owner's choice.
@@ -10047,17 +10072,25 @@ by `rig`, so their output requires no alternate compiler or dependency pin.
10047
10072
  | --- | --- | --- |
10048
10073
  | <a id="DEPTH_RECIPE"></a>`DEPTH_RECIPE` | unknown, absent or wrongly typed recipe field, group, source or frame | use the documented explicit recipe schema; no guessed field |
10049
10074
  | <a id="DEPTH_RECIPE_NUMBER"></a>`DEPTH_RECIPE_NUMBER` | missing/nonfinite median, relief, near-scale pivot or prepare number; invalid range/integer | declare every numeric field in its documented units and range |
10050
- | <a id="DEPTH_INPUT_PRESENT"></a>`DEPTH_INPUT_PRESENT` | declared JSON input missing or not a file | restore the named file |
10075
+ | <a id="DEPTH_INPUT_PRESENT"></a>`DEPTH_INPUT_PRESENT` | declared input missing or not a file, or `depth-map` input unreadable or prepared PNG undecodable | restore the named readable input file in its expected format |
10051
10076
  | <a id="DEPTH_INPUT_JSON"></a>`DEPTH_INPUT_JSON` | malformed numeric or configuration JSON | write valid finite JSON |
10052
10077
  | <a id="DEPTH_PART_RESOLVES"></a>`DEPTH_PART_RESOLVES` | selected or cleared name absent from parts.json | use the assembled part name |
10053
- | <a id="DEPTH_OUTPUT_EMPTY"></a>`DEPTH_OUTPUT_EMPTY` | nonempty output or output containing an input | choose a separate absent or empty directory |
10054
- | <a id="DEPTH_MAP_BINDING"></a>`DEPTH_MAP_BINDING` | malformed present map receipt, wrong part, map hash or inference-input hash | re-run depth for these inputs, then `rig-parts depth-bind --map <numeric-map.json> --input <prepared.png> --part <name>` |
10055
- | <a id="DEPTH_MAP_BINDING_ABSENT"></a>`DEPTH_MAP_BINDING_ABSENT` | WARN only: no receipt, compatibility policy dated 2026-11-16 | legacy behavior is retained; re-run depth for these inputs, then `rig-parts depth-bind --map <numeric-map.json> --input <prepared.png> --part <name>` |
10078
+ | <a id="DEPTH_OUTPUT_EMPTY"></a>`DEPTH_OUTPUT_EMPTY` | nonempty output directory or output containing an input, or `depth-map` cannot create its output exclusively | choose a separate absent or empty output directory, or for `depth-map` an absent output file in a writable directory |
10079
+ | <a id="DEPTH_MAP_BINDING"></a>`DEPTH_MAP_BINDING` | invalid part name for `depth-map` or `depth-bind`, or malformed present map receipt, wrong part, map hash or inference-input hash | use a nonempty plain part filename for the command, or re-run depth for the affected receipt and call `rig-parts depth-bind --map <numeric-map.json> --input <prepared.png> --part <name>` |
10080
+ | <a id="DEPTH_MAP_BINDING_ABSENT"></a>`DEPTH_MAP_BINDING_ABSENT` | WARN only: no receipt, compatibility policy dated 2026-11-16 | re-run depth for these inputs, then `rig-parts depth-bind --map <numeric-map.json> --input <prepared.png> --part <name>` |
10056
10081
  | <a id="DEPTH_INPUT_BINDING"></a>`DEPTH_INPUT_BINDING` | changed recipe, art, part record, crop, padding or inference PNG | prepare again for these exact inputs |
10082
+ | <a id="DEPTH_ARRAY_FORMAT"></a>`DEPTH_ARRAY_FORMAT` | unsupported NumPy version, malformed header, wrong dtype or order, or payload byte count does not match the header | export `.npy` v1.0, v2.0 or v3.0 as little-endian float32 or float64 in C order |
10083
+ | <a id="DEPTH_ARRAY_KIND"></a>`DEPTH_ARRAY_KIND` | unknown `depth-map --kind` | declare `depth` or `normals` |
10084
+ | <a id="DEPTH_ARRAY_SHAPE"></a>`DEPTH_ARRAY_SHAPE` | rank, dimension or channel count does not match the declared kind | export `(H,W)` or `(H,W,1)` for depth and `(H,W,3)` for normals, with positive safe integer dimensions |
10085
+ | <a id="DEPTH_ARRAY_PADDING"></a>`DEPTH_ARRAY_PADDING` | malformed padding or padding removes the entire extent on either axis | declare four nonnegative safe integers in left, top, right, bottom order that leave a nonempty crop |
10086
+ | <a id="DEPTH_ARRAY_SIZE"></a>`DEPTH_ARRAY_SIZE` | cropped dimensions are not positive integer multiples of the prepared PNG dimensions on both axes | check the input PNG and declare the raw array's actual padding, or re-export at a supported size |
10087
+ | <a id="DEPTH_ARRAY_NONFINITE"></a>`DEPTH_ARRAY_NONFINITE` | retained raw depth pixel contains `NaN` or an infinity | export finite depth values at the named raw pixel |
10088
+ | <a id="DEPTH_ARRAY_NORMAL"></a>`DEPTH_ARRAY_NORMAL` | retained raw normal is zero or nonfinite, or a pooled normal cancels to zero | export finite nonzero signed XYZ normals in image axes and inspect the named raw or output pixel |
10057
10089
  | <a id="DEPTH_MAP_FORMAT"></a>`DEPTH_MAP_FORMAT` | wrong numeric schema, channels, shape, count, unknown field or nonfinite element | provide the declared float JSON map, not a preview |
10058
10090
  | <a id="DEPTH_MAP_SIZE"></a>`DEPTH_MAP_SIZE` | map dimensions differ from its explicit frame | use the registered part, enlarged art or padded input grid |
10059
10091
  | <a id="DEPTH_MAP_SUPPORT"></a>`DEPTH_MAP_SUPPORT` | no alpha>=128 support | provide a supported part |
10060
10092
  | <a id="DEPTH_MAP_SPREAD"></a>`DEPTH_MAP_SPREAD` | p5=p95 with nonzero relief | supply a nonflat map or declare relief 0 |
10093
+ | <a id="DEPTH_APPLY_CLIPPED"></a>`DEPTH_APPLY_CLIPPED` | a pixel with original alpha >= 128 has pre-encoding depth `z <= 0` or `z >= zScale` | use the reported minimum median for each low-clipped part and the reported minimum group scale for upper clipping. The rig checks the head and body role sets separately, so if a surface belongs to both, use the larger required `zScale` in both groups. Recompute the group scale after median edits if the maximum changes, then prepare again. |
10061
10094
  | <a id="DEPTH_NORMAL_ISLANDS"></a>`DEPTH_NORMAL_ISLANDS` | zero/multiple connected components at native or integration resolution | scalar source, or a larger registered normal input that preserves one island |
10062
10095
  | <a id="DEPTH_NORMAL_VECTOR"></a>`DEPTH_NORMAL_VECTOR` | a sampled support normal is zero | provide nonzero signed XYZ normals |
10063
10096
  | <a id="DEPTH_NORMAL_CONVEXITY"></a>`DEPTH_NORMAL_CONVEXITY` | core/rim or its convexity sign is unresolved | larger closed convex mask or scalar source |
@@ -10088,6 +10121,15 @@ For each carried unit bone, the existing producer resolves depth in this order:
10088
10121
  landmarks or a mesh sampling position. No documented configuration is
10089
10122
  provided here to bypass primary sampling and select the own sheet instead.
10090
10123
 
10124
+ An explicit body unit value is the world depth `z`. At body yaw angle `a`,
10125
+ its rigid horizontal displacement is `-(pivot + z - zRef) * sin(a)`, using
10126
+ the same primary surface reference `zRef` as the body's surface projection.
10127
+ A region bound to a torso root gets its own mover under `bodyshift`; a
10128
+ region farther down a body branch uses the branch directly under
10129
+ `bodyshift`. Each blink-still piece resolves its binding independently.
10130
+ When the binding cannot be moved at the declared depth, the rig stage
10131
+ refuses with [`RIG_TURN_BODY_UNIT_CARRIER`](#RIG_TURN_BODY_UNIT_CARRIER).
10132
+
10091
10133
  Outside or nonopaque primary support produces
10092
10134
  [`RIG_TURN_UNIT_DEPTH_SUPPORT`](#RIG_TURN_UNIT_DEPTH_SUPPORT), retains the
10093
10135
  extended primary sample, and does not select the own sheet. Removing all
package/docs/DEPTH.md CHANGED
@@ -136,14 +136,16 @@ belong to these parts and nothing moved in between.
136
136
 
137
137
  ### 2. Run your depth model
138
138
 
139
- This is your step, with your model, on your machine or wherever you run it.
140
- Read `inference/<part>.png`, write one numeric map per part as JSON
141
- (`rig-parts-map/1`: width, height, channels, and the raw floating-point values
142
- row by row), the same size as the image you read. `"frame": "input"` in the
143
- recipe is what says so, and the manifest binds it, so choose it before you
144
- prepare. Scalar depth is one channel; the face's normals are three signed
145
- channels in image axes. Save the model's actual numbers — a greyscale preview
146
- has already thrown away the normalisation the next stage needs.
139
+ Run your model on `inference/<part>.png` and save its numeric output. The
140
+ recipe above declares `"frame": "input"`, so each JSON map must match the
141
+ size of the prepared PNG, including its grey margin. Choose the frame before
142
+ preparing because the manifest binds the recipe.
143
+
144
+ You can write the JSON directly as before. Use `rig-parts-map/1` with `width`,
145
+ `height`, `channels`, and a flat `data` array of finite floating-point values
146
+ in row order. Scalar depth has one channel and normals have three signed XYZ
147
+ channels in image axes (X right, Y down). A greyscale or RGB preview loses
148
+ the numeric values needed by the next stage.
147
149
 
148
150
  What we used: Depth Anything for the parts (V2 Large, and Depth Anything 3's
149
151
  monocular model), and Lotus's normal model for the face. Any model that
@@ -152,6 +154,35 @@ which one you ran. Model licences are the model's own and are not this
152
154
  package's to restate — the site's [licensing page](https://rig-c.org/docs/licensing/)
153
155
  says where each kind of term sits.
154
156
 
157
+ #### Convert a NumPy array
158
+
159
+ If the model exports a NumPy array, convert it to an input-frame map at the
160
+ recipe's map path. Use the same prepared PNG you supplied to the model:
161
+
162
+ ```sh
163
+ rig-parts depth-map --array face.npy --input inference/face.png --kind normals --part face --out face.json
164
+ ```
165
+
166
+ The array must be a C-order `.npy` file (format 1.0, 2.0, or 3.0) with
167
+ little-endian `float32` or `float64` values. Use `--kind depth` for `(H, W)`
168
+ or `(H, W, 1)` and `--kind normals` for `(H, W, 3)` signed XYZ in image axes.
169
+
170
+ If the model added padding to its output array, pass
171
+ `--padding LEFT,TOP,RIGHT,BOTTOM` in array pixels. The values are nonnegative
172
+ integers and default to zero. Keep the prepared PNG's own grey margin in the
173
+ map. After cropping the declared padding, each array dimension must be a
174
+ positive integer multiple of the corresponding PNG dimension. Each output
175
+ pixel is the mean of its corresponding rectangular block, with independent
176
+ horizontal and vertical factors. For normals, average each component and
177
+ normalize the resulting vector to unit length. A retained nonfinite sample,
178
+ a retained zero normal, or a pooled zero normal is refused with its pixel
179
+ coordinates.
180
+
181
+ `--out` must name a new file in an existing writable directory. `depth-map`
182
+ writes only the `rig-parts-map/1` JSON and prints the next `depth-bind`
183
+ command with the map path, prepared PNG path and part name quoted for a POSIX
184
+ shell.
185
+
155
186
  ### 3. Bind every map to its prepared input
156
187
 
157
188
  After the model writes each numeric map, bind those exact bytes to the input
@@ -169,8 +200,8 @@ it does not prove the model inferred one from the other. Use each recipe map
169
200
  path and its matching prepared image, retain the receipts with the maps, then
170
201
  apply them. Existing receipts are never overwritten. If a map changes, retain
171
202
  the old map and receipt and bind the new map at a new path; update the recipe
172
- and prepare again so its manifest binds that recipe. `depth-apply` refuses
173
- missing, stale or mismatched bindings before emission.
203
+ and prepare again so its manifest binds that recipe. `depth-apply` warns when
204
+ a binding is absent and refuses stale or mismatched bindings before emission.
174
205
 
175
206
  ### 4. Apply the maps as depth sheets
176
207
 
@@ -189,12 +220,34 @@ depth-apply: face levels=30 clip=0 reliefRigPixels=10 sign=1
189
220
  depth-apply: wrote registered parts, config.json and depth-report.json; run rig for the core gate
190
221
  ```
191
222
 
192
- `levels` is how many distinct grey levels the sheet uses, `clip` the share of
193
- pixels that fell outside the group's scale (keep it at or near zero), and
194
- `sign` the convexity sign the face integration chose. `mapped/` is a complete
195
- assembled directory: the art unchanged, a `<part>_depth.png` beside each mapped
196
- part, `parts.json` pointing at them, a copy of your config with the group
197
- pivots written in, and `depth-report.json` with every number and hash. Nothing
223
+ `levels` is how many distinct grey levels the sheet uses, and `sign` is the
224
+ convexity sign the face integration chose. `clip` (`clipFraction` in
225
+ `depth-report.json`) is the share of original part pixels with alpha >= 128
226
+ whose depth is at or beyond either boundary before encoding. Every supported
227
+ depth must satisfy `0 < z < zScale`. A nonzero fraction triggers
228
+ `DEPTH_APPLY_CLIPPED` before any output is written.
229
+
230
+ For clipping at the upper boundary, the refusal gives the smallest binary64
231
+ group `zScale` strictly greater than the largest original supported depth in
232
+ the group. For each part that clips at the lower boundary, it gives the
233
+ minimum authored `median` and how far it is above the previous median in rig
234
+ pixels. The minimum is the next binary64 value above the greatest negated
235
+ relief offset among that part's supported pixels. A group that clips at both
236
+ boundaries gets both remedies across its affected parts. If a required value
237
+ has no finite binary64 representation, revise the calibration as directed by
238
+ the refusal. A median rise can increase the group's maximum depth, so
239
+ recompute the required group scale after changing the median. After
240
+ editing the recipe, run `depth-prepare` again to bind the revised recipe, then
241
+ rerun `depth-apply` with the matching manifest.
242
+
243
+ The bound covers the newly mapped parts in each applied recipe group. At the
244
+ rig stage, each turn group checks its member sheets for one scale and polarity.
245
+ A surface shared by both turn groups must satisfy both groups' checks.
246
+
247
+ On success, `mapped/` is a complete assembled directory with the original
248
+ art, a `<part>_depth.png` beside each mapped part, `parts.json` pointing at
249
+ the sheets, a copy of your config with the group pivots written in, and
250
+ `depth-report.json` with every number and hash. Nothing
198
251
  in `work/rig` or your original config is touched. Any mismatch — a recipe edited
199
252
  after prepare, a part that moved, a map of the wrong size, a part your
200
253
  `turn.roles` does not name — is refused by name before a byte is written.
@@ -272,14 +325,13 @@ judge from a sweep or from the `turn` animation played straight through. Put
272
325
  the build in a page where the pointer drives both dials; the adapters' look
273
326
  example shows [how to bind a pointer to declared sliders](https://github.com/rig-c/adapters/blob/main/examples/look/README.md).
274
327
  Separately, render the setup pose and both yaw endpoints and look at their
275
- difference at native scale: that is where a tear, a clipped sheet or a feature
276
- sliding off the face shows, and it is a check for defects, not for volume.
328
+ difference at native scale to find tears or features sliding off the face.
277
329
 
278
330
  **Read the report before you read the render.** `depth-report.json` names each
279
- part's relief, scale and clip fraction. A high clip fraction means the declared
280
- numbers do not fit the group's scale; fix the recipe, not the render. Small
281
- units — eyes, mouth, brows, ears — usually look best following the face surface
282
- rather than carrying a sheet of their own: list them under `clear`, or give
331
+ part's relief, scale and clip fraction. A zero clip fraction confirms the
332
+ supported depths fit the declared range. Inspect the render for shape quality.
333
+ Small units — eyes, mouth, brows, ears — usually look best following the face
334
+ surface rather than carrying a sheet of their own: list them under `clear`, or give
283
335
  them an explicit depth under the group's `unitDepths`. Which depth a unit ends
284
336
  up using is spelled out in
285
337
  [Unit depth precedence](AUTHORING.md#unit-depth-precedence).