@rig-c/parts 1.23.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/AUTHORING.md CHANGED
@@ -1619,6 +1619,28 @@ to 0.258 of its weight on the trees; and `check`'s `BREATH_VISIBLE`, which reads
1619
1619
  `topwear` part as the torso, read the dress's idle heat at 1.592 against the floor
1620
1620
  3.809, where the same dress with the robe chains read 3.9 — the half on the trees has
1621
1621
  no idle key. Neither is barred here; both are the dress's to weigh before declaring it.
1622
+ Since issue #411 the bar reads the breath alone, and on that fixture the breath moves
1623
+ the dress 0.106 and the robe-chained dress 2.62: both fail, and the 3.9 was the robe
1624
+ chains' keyed swing below the hip, not the breath (the CK502 and CK503 controls).
1625
+
1626
+ **What rides a tail** (issue #391). An accessory wrapped round a tail the `back hair`
1627
+ recipe drafts — a ribbon, in See-through's `headwear` or `earwear` layer — rides that
1628
+ tail's links, not `head`: under the recipe the tail moves by the world, and a part left on
1629
+ `head` stays where the tail was. Which links is read off the overlap, never off the
1630
+ part's name: each of the part's pixels over the tail's art is given to the span of the
1631
+ back hair's mesh nearest it (its fixed segment on `head`, or one tree link, the distance
1632
+ the weights read), and the part rides when one of those spans is a link. Its mesh's
1633
+ segments are then the spans it lies on — each link by name, the head's span written
1634
+ out — so every vertex weights by the rule the tail's own art does, the pixels off the
1635
+ tail (a ribbon's loops) included; no accessory bone, pendant or strand chain is drafted
1636
+ for it, and a note names each span with its pixel count. A part over no link keeps the
1637
+ accessory rule. It is part of the recipe's drafting, not a field: the rule reads only
1638
+ the art, and without the recipe no tail moves by the world and nothing here runs. On
1639
+ `wind` (rig-c 2.54.0, `rigc render --environment`, idle frame 200 of 200 at 60 fps,
1640
+ 0.916 px per rig px), the ribbon pixels painted over the tail that are drawn where the
1641
+ tail has no hair went from 2,429 at calm and 8,363 at wind (10, 0) to 30 and 230; the
1642
+ 230 all lie within 3.6 px of the hair's edge, where the ribbon's mesh and the hair's are
1643
+ two different lattices.
1622
1644
 
1623
1645
  **Every spring is stable at its step (A23's inequality).** Per step spine-core does
1624
1646
  `v += −strength·x·step·massInverse`, `x += v·step`, `v *= d` with d = damping^(60·step);
@@ -2753,7 +2775,7 @@ documents do not ship). Each is an input this package built; none is an author's
2753
2775
  | <a id="CHECK_LOOP_LAST_FRAME_AT_DURATION"></a>`CHECK_LOOP_LAST_FRAME_AT_DURATION` | the idle's last frame does not sit at `duration` | `motion.duration` — a whole number of 1/12 s |
2754
2776
  | <a id="CHECK_LOOP_CLOSES"></a>`CHECK_LOOP_CLOSES` | frame 0 and the frame at `duration` differ (max and first pixel quoted); with a physics constraint, the frames of the rig with every physics constraint left out, and the object says so (§7, *loop*) | a track whose last key is not its first |
2755
2777
  | <a id="CHECK_SEAM_WITHIN_BAR"></a>`CHECK_SEAM_WITHIN_BAR` | the setup pose does not reproduce the flat stack of parts | read the `seam pair` lines and `check/seam/` pictures (§7; magenta = a counted pixel, cyan = the box round them): the pair, its boxes and the pixels counted. Usually a region or mesh placed off its part; compare with `recomposite_rig.png`. A pair of one layer cut in two with `differing_copies_px` is the cut line: move the polygon's edge, not `overlap` |
2756
- | <a id="CHECK_BREATH_VISIBLE"></a>`CHECK_BREATH_VISIBLE` | the torso (`topwear`), rendered alone, barely moves over the idle — or the feet (`footwear`), rendered alone, move at all | the chest's breath tracks (`motion.tracks` on `chest`), or the torso mesh's `segments`; for the feet, the bone their region rides (`regions.<part>`, `root` in both examples) |
2778
+ | <a id="CHECK_BREATH_VISIBLE"></a>`CHECK_BREATH_VISIBLE` | the breath alone barely moves the torso (`topwear`, rendered alone, the idle with and without its breath tracks — issue #411; the whole idle's figure is printed beside it, and motion that is not the breath's is not counted), or the idle has no breath track at all — or the feet (`footwear`), rendered alone, move at all | the chest's breath tracks (`motion.tracks` on `chest`), or the torso mesh's `segments`; for the feet, the bone their region rides (`regions.<part>`, `root` in both examples) |
2757
2779
  | <a id="CHECK_BLINK_NO_HOLE"></a>`CHECK_BLINK_NO_HOLE` | with the blink held shut, the eyewhite box shows the page where the open eye had art | the layer under the eye: the `face` part has no art there. Take the face from the other run, or add a part under the eye; `motion.blink.squash` only hides the hole less |
2758
2780
  | <a id="CHECK_CHAIN_LAG"></a>`CHECK_CHAIN_LAG` | a rotate track leads (or does not lag) the keyed bone above it, or a chain link swings less than the link above — or, in a chain that carries a part the scene file declares `rests`, more than the link above (issue #245; the object names the part and the file) | that chain track's `phase`/`lag` (a positive `lag`, a child `phase` above its parent's) or its `amps` (non-decreasing toward the tip; non-increasing on a chain declared resting) |
2759
2781
  | <a id="CHECK_TIP_OVER_ROOT"></a>`CHECK_TIP_OVER_ROOT` | a `handwear`/`bottomwear` part's art in the lower half of its box travels less than 1.4725 times as far as in the upper half, measured from the idle's posed geometry (rig px quoted) | the chain track's `amps` (grow toward the tip), or the mesh's `segments` (the chain must be among them), or its mode: on `scarf`'s short skirt the proposal's lattice read 1.207 and the same part in `contour` mode 1.738 with the same segments and idle (issue #118) — both carried the `chest` segment #262 removed, after which the lattice reads 3.487. When the detail says `the root travels with the breath (x px of y px): it is carried by \`<bone>\`` (issue #262) the chain is not the cause: a bone an idle `translate` track moves (the breath) moves the root more than the tip, and with that translate held still (the part posed again without it, in proportion to each vertex's weight on the bone and those under it) the ratio passes — the row adds `carried_by`, `breath_rig_px`, `root_without_breath_rig_px` and `tip_without_breath_rig_px`; take that bone's segment off the mesh, or bind the root to the bone the part hangs from. A part the scene file declares `rests` (issue #245) is held the other way, its tip half's travel at most its root half's (ratio ≤ 1); the detail then reads `the scene file's rests declares its tip at rest, so a ratio <= 1 is required`, and for it the fix is the chain's `amps` (shrinking toward the tip) or the mesh's tip weighted to a bone the idle does not swing |
@@ -2927,7 +2949,7 @@ the two examples [observed]:
2927
2949
 
2928
2950
  | line | measures | bar | `reference-demo` | `reference-sample` | SKIP when |
2929
2951
  | --- | --- | --- | --- | --- | --- |
2930
- | <a id="BREATH_VISIBLE"></a>`BREATH_VISIBLE` | `topwear` parts rendered alone (`rigc render --slot`): heat mean over their box; `footwear` parts alone: heat max over theirs | torso mean ≥ 3.809; feet max ≤ 0 | 15.251; 0 | 7.617; 0 | no `topwear` and no `footwear` part. One of the two absent (issue #323): the other half is measured and decides the line, which then carries `halves_measured` `"1 of 2"` first, then each half's own status — `torso_status`, `feet_status` — the absent half's `SKIP` with its `torso_reason` or `feet_reason`; a run that measured both halves writes the keys it always wrote |
2952
+ | <a id="BREATH_VISIBLE"></a>`BREATH_VISIBLE` | the torso: the breath alone (issue #411). The breath bones are every bone an idle track translates, and the breath tracks every idle track that translates or scales one of them (the drafted breath: `chest` `translatey` and `scalex`). The `topwear` parts are rendered alone (`rigc render --slot`) from one throwaway build that carries, beside every animation, the idle with those tracks held at rest (0 for a translate, 1 for a scale, at each track's first and last key time — the bone as it stands without them, the idle still keyed to its end), so the two idles share a grid; per pixel, the largest \|(with_t − with_0) − (without_t − without_0)\| over the frames and channels, meaned over their box (`torso_heat_mean`). Motion in both renders — a keyed cloth swing, physics answering the world — cancels; physics the breath sets moving counts. Until #411 the figure was the whole idle's heat over the box, which a keyed swing passed for a torso that did not breathe; a refusal still prints that whole-idle figure beside the breath's. An idle with no breath track reads 0 and fails, naming why — a torso that does not breathe is what the bar finds, so it is not a SKIP. The feet: `footwear` parts alone, heat max over theirs | torso mean ≥ 3.809; feet max ≤ 0 | 15.251; 0 | 7.617; 0 | no `topwear` and no `footwear` part. One of the two absent (issue #323): the other half is measured and decides the line, which then carries `halves_measured` `"1 of 2"` first, then each half's own status — `torso_status`, `feet_status` — the absent half's `SKIP` with its `torso_reason` or `feet_reason`; a run that measured both halves writes the keys it always wrote |
2931
2953
  | <a id="BLINK_NO_HOLE"></a>`BLINK_NO_HOLE` | the setup pose with every `scaley` track on the eyewhite slots' bones held at its closed value, against the setup pose, at full size: pixels in the eyewhite box that show the page where the open eye had art | 0 px | 0 | 0 | no `eyewhite` part, or no `scaley` track on its bones goes below its first key |
2932
2954
  | ″ (reported) | the same box: each closed-eye pixel's max-channel distance to the nearest colour the open eye's box holds — max, and pixels over 40 | none | 15; 0 | 11; 0 | as above |
2933
2955
  | <a id="CHAIN_LAG"></a>`CHAIN_LAG` | `motion.json`'s rotate tracks read as sines (DFT of the keys: period, amplitude, phase) and arranged by the bone tree — a keyed bone's parent is its nearest keyed ancestor | every lag ≥ 0.001 cycle; amplitude non-decreasing down each unbranched chain — non-increasing down a chain that carries a part declared `rests` (issue #245) | lags 0.040 (neck to head) to 0.120; 12 chains | lags 0.040 to 0.100; 9 chains | no rotate track under another of the same period |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/parts",
3
- "version": "1.23.0",
3
+ "version": "1.24.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/check.ts CHANGED
@@ -101,6 +101,7 @@ import {
101
101
  FACE_FEATURE_TAGS,
102
102
  FACE_TAGS,
103
103
  FEET_TAGS,
104
+ breathHeat,
104
105
  frameBox,
105
106
  heatField,
106
107
  partsTagged,
@@ -3133,13 +3134,40 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
3133
3134
  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:'))));
3134
3135
  return readFrameSet(dir);
3135
3136
  };
3137
+ // Issue #411: the breath alone — a throwaway copy of the build carrying, beside every animation, the idle with its
3138
+ // breath tracks held at rest; the torso rendered alone in both idles, from that one build, so the two share a grid.
3139
+ const breathPair = (ps: readonly PartRecord[]): BreathPair | null => {
3140
+ const tracks = breathTracks(inp.motion);
3141
+ if (tracks.length === 0) return null;
3142
+ const dir = join(isoDir, BREATH_SCRATCH);
3143
+ const anims = isRecord(inp.motion.animations) ? inp.motion.animations : {};
3144
+ const idleAnim = isRecord(anims.idle) ? anims.idle : {};
3145
+ let name = BREATH_ANIMATION;
3146
+ while (name in anims) name = `${name}_`;
3147
+ // Each breath track held at rest over its own span: the idle without the breath, still keyed to its end, which rigc
3148
+ // requires of an animation's last key.
3149
+ const kept = (Array.isArray(idleAnim.tracks) ? idleAnim.tracks : []).map((t) => (isRecord(t) && isBreathTrack(t, tracks) ? heldTrack(t) : t));
3150
+ mkdirSync(dir, { recursive: true });
3151
+ const images = typeof inp.rig.images === 'string' ? resolve(inp.rigDir, inp.rig.images) : inp.rig.images;
3152
+ writeFileSync(join(dir, 'rig.json'), JSON.stringify({ ...inp.rig, images }));
3153
+ writeFileSync(join(dir, 'motion.json'), JSON.stringify({ ...inp.motion, animations: { ...anims, [name]: { ...idleAnim, tracks: kept } } }));
3154
+ const b = rigc(['build', '--rig', join(dir, 'rig.json'), '--motion', join(dir, 'motion.json'), '--out', join(dir, 'build'), ...packedBuildArgs(mode)]);
3155
+ 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)));
3156
+ const slots = ps.map((p) => p.name).join(',');
3157
+ const render = (animation: string, label: string): FrameSet => {
3158
+ 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)]);
3159
+ 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:'))));
3160
+ return readFrameSet(join(dir, label));
3161
+ };
3162
+ return { with: render('idle', 'with'), without: render(name, 'without'), tracks: tracks.map((t) => `${t.bone} ${t.property}`) };
3163
+ };
3136
3164
  // Issue #231: the footwear parts the scene file declares not planted; none without --requirements or the field.
3137
3165
  const notPlanted = reqFile === null ? [] : reqFile.not_planted;
3138
3166
  let breath: JudgementLine = skip(lacking);
3139
3167
  let tip: JudgementLine = skip(lacking);
3140
3168
  if (full !== null) {
3141
3169
  try {
3142
- breath = breathLine(full, isolated, problems, notPlanted);
3170
+ breath = breathLine(full, isolated, breathPair, problems, notPlanted);
3143
3171
  if (idle !== null) tip = tipLine(full, join(idle.dir, GEOMETRY_FILE), idle.written, problems, reqFile === null ? NO_TIP_EXCEPTIONS : { path: reqFile.path, not_swinging: reqFile.not_swinging, rises: reqFile.rises, rests: reqFile.rests });
3144
3172
  } finally {
3145
3173
  rmSync(isoDir, { recursive: true, force: true });
@@ -3701,33 +3729,32 @@ function noneHeldText(declared: readonly string[]): string {
3701
3729
  * `SKIP` with its reason — so a half nobody read never passes by being silent.
3702
3730
  * With neither, the line is the SKIP it was. A run that measured both halves
3703
3731
  * writes the keys it always wrote.
3732
+ *
3733
+ * Issue #411: the torso half reads the breath alone ({@link torsoBreath}):
3734
+ * `torso_heat_mean` is the heat the breath makes, the idle rendered with and
3735
+ * without its breath tracks, on the same box and against the same floor.
3736
+ * Until #411 it was the whole idle's heat over the box, so a keyed cloth swing
3737
+ * or a physics response to the world inside the torso's box passed the bar
3738
+ * for a torso that did not breathe.
3704
3739
  */
3705
- function breathLine(inp: FullInputs, isolated: Isolate, problems: Problem[], notPlanted: readonly string[] = []): JudgementLine {
3740
+ function breathLine(inp: FullInputs, isolated: Isolate, pair: BreathPairRender, problems: Problem[], notPlanted: readonly string[] = []): JudgementLine {
3706
3741
  const torso = partsTagged(inp.parts, TORSO_TAGS);
3707
3742
  const { all: allFeet, held: feet, declared } = plantedFeet(inp.parts, notPlanted);
3708
3743
  const noTorso = `no part comes from a See-through ${tagWords(TORSO_TAGS)} layer, so there is no torso to see breathe`;
3709
3744
  const noFeet = `no part comes from a See-through ${tagWords(FEET_TAGS)} layer, so there are no feet to hold still`;
3710
3745
  // Issue #323: a figure without one of the two halves still has the other read; with neither, the SKIP it always was.
3711
3746
  if (torso.length === 0 && feet.length === 0) return skip(`${noTorso}${declared.length === 0 ? '' : `; ${declared.map((n) => `"${n}"`).join(', ')} declared not planted`}`);
3712
- if (torso.length === 0) return oneHalf(inp, isolated, problems, 'feet', feet, noTorso, declared);
3713
- if (allFeet.length === 0) return oneHalf(inp, isolated, problems, 'torso', torso, noFeet, []);
3747
+ if (torso.length === 0) return oneHalf(inp, isolated, pair, problems, 'feet', feet, noTorso, declared);
3748
+ if (allFeet.length === 0) return oneHalf(inp, isolated, pair, problems, 'torso', torso, noFeet, []);
3714
3749
  const H = inp.parts.rig_size[1];
3715
- const ts = isolated('torso', torso);
3750
+ const tr = torsoBreath(inp, torso, pair);
3716
3751
  const fs = feet.length === 0 ? null : isolated('feet', feet);
3717
- const tb = frameBox(torso, H, inp.stage, ts.viewport);
3718
3752
  const fb = fs === null ? null : frameBox(feet, H, inp.stage, fs.viewport);
3719
- if (tb === null || (fs !== null && fb === null)) return skip(`the ${tb === null ? 'torso' : 'feet'} box falls outside the idle frame`);
3720
- const th = regionHeat(heatField(ts.frames.map((f) => f.image)), ts.viewport.pixelWidth, tb);
3753
+ if ('skip' in tr || (fs !== null && fb === null)) return skip(`the ${'skip' in tr ? 'torso' : 'feet'} box falls outside the idle frame`);
3721
3754
  const fh = fs === null || fb === null ? null : regionHeat(heatField(fs.frames.map((f) => f.image)), fs.viewport.pixelWidth, fb);
3722
- const mean = round3(th.mean);
3755
+ const mean = tr.mean;
3723
3756
  const ok = mean >= BREATH_TORSO_MEAN_FLOOR && (fh === null || fh.max <= BREATH_FEET_MAX_CEILING);
3724
- if (mean < BREATH_TORSO_MEAN_FLOOR) {
3725
- problems.push({
3726
- code: 'CHECK_BREATH_VISIBLE',
3727
- object: `torso ${quoteParts(torso)} rendered alone, frame box ${boxLabel(tb)}`,
3728
- detail: `heat mean ${mean}/255 over the idle; >= ${BREATH_TORSO_MEAN_FLOOR} is required — the chest's breath track moves too little, or the torso is not weighted to the bone it keys`,
3729
- });
3730
- }
3757
+ if (mean < BREATH_TORSO_MEAN_FLOOR) problems.push(torsoProblem(torso, tr, ''));
3731
3758
  if (fh !== null && fb !== null && fh.max > BREATH_FEET_MAX_CEILING) {
3732
3759
  problems.push({
3733
3760
  code: 'CHECK_BREATH_VISIBLE',
@@ -3755,22 +3782,15 @@ function breathLine(inp: FullInputs, isolated: Isolate, problems: Problem[], not
3755
3782
  * `halves_measured`, says `1 of 2` — after `declared_not_planted` when the scene
3756
3783
  * file declares some of the feet read (issue #231), which stays the first.
3757
3784
  */
3758
- function oneHalf(inp: FullInputs, isolated: Isolate, problems: Problem[], half: 'torso' | 'feet', ps: readonly PartRecord[], reason: string, declared: readonly string[]): JudgementLine {
3785
+ function oneHalf(inp: FullInputs, isolated: Isolate, pair: BreathPairRender, problems: Problem[], half: 'torso' | 'feet', ps: readonly PartRecord[], reason: string, declared: readonly string[]): JudgementLine {
3759
3786
  const H = inp.parts.rig_size[1];
3760
- const fs = isolated(half, ps);
3761
- const box = frameBox(ps, H, inp.stage, fs.viewport);
3762
- if (box === null) return skip(`the ${half} box falls outside the idle frame, and ${reason}`);
3763
- const heat = regionHeat(heatField(fs.frames.map((f) => f.image)), fs.viewport.pixelWidth, box);
3764
3787
  if (half === 'torso') {
3765
- const mean = round3(heat.mean);
3788
+ // Issue #411: the torso half is the breath alone.
3789
+ const tr = torsoBreath(inp, ps, pair);
3790
+ if ('skip' in tr) return skip(`the ${half} box falls outside the idle frame, and ${reason}`);
3791
+ const mean = tr.mean;
3766
3792
  const ok = mean >= BREATH_TORSO_MEAN_FLOOR;
3767
- if (!ok) {
3768
- problems.push({
3769
- code: 'CHECK_BREATH_VISIBLE',
3770
- object: `torso ${quoteParts(ps)} rendered alone, frame box ${boxLabel(box)}; the feet half not measured: ${reason}`,
3771
- detail: `heat mean ${mean}/255 over the idle; >= ${BREATH_TORSO_MEAN_FLOOR} is required — the chest's breath track moves too little, or the torso is not weighted to the bone it keys`,
3772
- });
3773
- }
3793
+ if (!ok) problems.push(torsoProblem(ps, tr, `; the feet half not measured: ${reason}`));
3774
3794
  return {
3775
3795
  status: ok ? 'PASS' : 'FAIL',
3776
3796
  halves_measured: '1 of 2',
@@ -3782,6 +3802,10 @@ function oneHalf(inp: FullInputs, isolated: Isolate, problems: Problem[], half:
3782
3802
  feet_reason: reason,
3783
3803
  };
3784
3804
  }
3805
+ const fs = isolated(half, ps);
3806
+ const box = frameBox(ps, H, inp.stage, fs.viewport);
3807
+ if (box === null) return skip(`the ${half} box falls outside the idle frame, and ${reason}`);
3808
+ const heat = regionHeat(heatField(fs.frames.map((f) => f.image)), fs.viewport.pixelWidth, box);
3785
3809
  const ok = heat.max <= BREATH_FEET_MAX_CEILING;
3786
3810
  if (!ok) {
3787
3811
  problems.push({
@@ -3803,6 +3827,130 @@ function oneHalf(inp: FullInputs, isolated: Isolate, problems: Problem[], half:
3803
3827
  };
3804
3828
  }
3805
3829
 
3830
+ /** The throwaway animation BREATH_VISIBLE adds beside the idle (issue #411): the idle with its breath tracks held at rest; a trailing `_` is added while the rig already has an animation of the name. */
3831
+ export const BREATH_ANIMATION = 'idle_without_breath';
3832
+ /** Where BREATH_VISIBLE's copy is built and rendered, under the stage's scratch; removed before the stage returns. */
3833
+ const BREATH_SCRATCH = 'breath';
3834
+
3835
+ /** The idle track properties that make up the breath on a breath bone (issue #411): it moves and it swells; the drafted breath is `chest` `translatey` and `scalex` (src/propose.ts). */
3836
+ const BREATH_TRACK_PROPS: readonly string[] = ['translate', 'translatex', 'translatey', 'scale', 'scalex', 'scaley'];
3837
+
3838
+ /**
3839
+ * The breath's tracks (issue #411), in the idle's order: the breath bones are
3840
+ * every bone an idle track translates ({@link BREATH_PROPS}, issue #262), and
3841
+ * their breath tracks every idle track that translates or scales one of them
3842
+ * ({@link BREATH_TRACK_PROPS}). A track that turns a breath bone, a group's
3843
+ * track and every track on another bone are not the breath. Empty when no
3844
+ * idle track translates a bone.
3845
+ */
3846
+ export function breathTracks(motion: Record<string, unknown>): Array<{ bone: string; property: string }> {
3847
+ const anims = isRecord(motion.animations) ? motion.animations : {};
3848
+ const idle = isRecord(anims.idle) ? anims.idle : {};
3849
+ const tracks = (Array.isArray(idle.tracks) ? idle.tracks : []).filter(isRecord).filter((t) => typeof t.bone === 'string' && typeof t.property === 'string');
3850
+ const bones = new Set(tracks.filter((t) => BREATH_PROPS.includes(String(t.property))).map((t) => String(t.bone)));
3851
+ return tracks.filter((t) => bones.has(String(t.bone)) && BREATH_TRACK_PROPS.includes(String(t.property))).map((t) => ({ bone: String(t.bone), property: String(t.property) }));
3852
+ }
3853
+
3854
+ /**
3855
+ * A breath track held at rest (issue #411): the setup pose's value — 0 for a translate, 1 for a scale, one per axis
3856
+ * the track's first key gives — at its first and last key times, no curve. That is the track removed, as the bone
3857
+ * stands without it, while the idle stays keyed to its end: a dropped track could leave the idle's last key before
3858
+ * its duration, which rigc refuses. (Held at its first key instead, the bone would stand offset from frame 0 on and
3859
+ * the physics under it would answer that start, which is not the idle without its breath.)
3860
+ */
3861
+ function heldTrack(t: Record<string, unknown>): Record<string, unknown> {
3862
+ const keys = (Array.isArray(t.keys) ? t.keys : []).filter(isRecord);
3863
+ if (keys.length === 0) return t;
3864
+ const first = keys[0];
3865
+ const last = keys[keys.length - 1];
3866
+ const rest = String(t.property).startsWith('scale') ? 1 : 0;
3867
+ const v = (Array.isArray(first.v) ? first.v : [first.v]).map(() => rest);
3868
+ return { ...t, keys: keys.length === 1 ? [{ t: first.t, v }] : [{ t: first.t, v }, { t: last.t, v }] };
3869
+ }
3870
+
3871
+ function isBreathTrack(t: Record<string, unknown>, tracks: ReadonlyArray<{ bone: string; property: string }>): boolean {
3872
+ return tracks.some((b) => b.bone === t.bone && b.property === t.property);
3873
+ }
3874
+
3875
+ /** The torso rendered alone twice from one build (issue #411): the idle (`with`) and the idle less its breath tracks (`without`), and those tracks as `bone property`. */
3876
+ export interface BreathPair {
3877
+ with: FrameSet;
3878
+ without: FrameSet;
3879
+ tracks: string[];
3880
+ }
3881
+
3882
+ /** Renders {@link BreathPair} for the torso parts; null when the idle has no breath track. */
3883
+ export type BreathPairRender = (ps: readonly PartRecord[]) => BreathPair | null;
3884
+
3885
+ /**
3886
+ * Why the two renders of a {@link BreathPair} cannot be compared pixel for
3887
+ * pixel, or null when they can: one grid (the viewport), one background, the
3888
+ * same number of frames, each of one size. Both come from one build, so a
3889
+ * difference is rigc's, refused by name (`CHECK_BREATH_VISIBLE`) rather than
3890
+ * read.
3891
+ */
3892
+ export function breathPairProblem(pair: BreathPair): Problem | null {
3893
+ const a = pair.with;
3894
+ const b = pair.without;
3895
+ const size = (s: FrameSet): string => [...new Set(s.frames.map((f) => `${f.image.width}x${f.image.height}`))].join(',');
3896
+ if (sameViewport(a.viewport, b.viewport) && a.background.join(',') === b.background.join(',') && a.frames.length === b.frames.length && size(a) === size(b) && !size(a).includes(',')) return null;
3897
+ return {
3898
+ code: 'CHECK_BREATH_VISIBLE',
3899
+ object: `the torso's two idle renders (with and without the breath tracks ${pair.tracks.join(', ')})`,
3900
+ detail: `are ${a.frames.length} frame(s) of ${size(a)} on ${JSON.stringify(a.viewport)} over ${JSON.stringify(a.background)} and ${b.frames.length} frame(s) of ${size(b)} on ${JSON.stringify(b.viewport)} over ${JSON.stringify(b.background)}; the breath is read pixel for pixel between them, which needs one grid, one background and one frame count`,
3901
+ };
3902
+ }
3903
+
3904
+ /** The torso half's reading (issue #411): the breath's heat mean over the box, the whole idle's beside it, and the breath tracks; `none` when the idle has no breath track. */
3905
+ type TorsoBreath = { box: PixelBox; mean: number; whole: number; tracks: string[] } | { none: string; mean: number } | { skip: true };
3906
+
3907
+ /**
3908
+ * `BREATH_VISIBLE`'s torso half (issue #411): the breath alone. The breath
3909
+ * bones are every bone an idle track translates, and the breath tracks every
3910
+ * idle track that translates or scales one of them ({@link breathTracks}).
3911
+ * The torso is rendered alone, idle at its rate and size, from one throwaway
3912
+ * build carrying every animation of the rig and, beside them, the idle with
3913
+ * its breath tracks held at rest ({@link heldTrack}: the bone as it stands
3914
+ * without them, the idle still keyed to its end) — so both renders share a
3915
+ * grid. Per pixel, the largest
3916
+ * |(with_t - with_0) - (without_t - without_0)| over the frames and the RGB
3917
+ * channels ({@link breathHeat}), meaned over the torso's frame box. Motion that
3918
+ * is not the breath's — a keyed cloth swing, physics answering the world, a
3919
+ * head turn — is in both renders and cancels; physics the breath sets moving
3920
+ * is counted. The whole idle's heat over the same box, the reading until #411,
3921
+ * is carried for the refusal's sentence only.
3922
+ *
3923
+ * With no breath track the figure is 0, by the definition (the idle with and
3924
+ * without its breath is one idle), and the bar fails naming why: a torso with
3925
+ * no breath is what the bar exists to find, so it is not a SKIP; nothing is
3926
+ * rendered.
3927
+ */
3928
+ function torsoBreath(inp: FullInputs, ps: readonly PartRecord[], pair: BreathPairRender): TorsoBreath {
3929
+ const got = pair(ps);
3930
+ if (got === null) return { none: 'no idle track translates a bone, so the rig has no breath to read (the breath bones are every bone an idle track translates); whatever else the idle moves is not counted', mean: 0 };
3931
+ const grid = breathPairProblem(got);
3932
+ if (grid !== null) refuseIfAny([grid]);
3933
+ const box = frameBox(ps, inp.parts.rig_size[1], inp.stage, got.with.viewport);
3934
+ if (box === null) return { skip: true };
3935
+ const width = got.with.viewport.pixelWidth;
3936
+ const withFrames = got.with.frames.map((f) => f.image);
3937
+ const mean = round3(regionHeat(breathHeat(withFrames, got.without.frames.map((f) => f.image)), width, box).mean);
3938
+ const whole = round3(regionHeat(heatField(withFrames), width, box).mean);
3939
+ return { box, mean, whole, tracks: got.tracks };
3940
+ }
3941
+
3942
+ /** The torso half's refusal (issue #411): the breath's figure, the tracks it was read from, and the whole idle's beside it. */
3943
+ function torsoProblem(ps: readonly PartRecord[], tr: Exclude<TorsoBreath, { skip: true }>, tail: string): Problem {
3944
+ if ('none' in tr) {
3945
+ return { code: 'CHECK_BREATH_VISIBLE', object: `torso ${quoteParts(ps)}${tail}`, detail: `breath heat mean 0/255: ${tr.none}; >= ${BREATH_TORSO_MEAN_FLOOR} is required — key the chest's breath (a translate track on the bone the torso is weighted to)` };
3946
+ }
3947
+ return {
3948
+ code: 'CHECK_BREATH_VISIBLE',
3949
+ object: `torso ${quoteParts(ps)} rendered alone, frame box ${boxLabel(tr.box)}${tail}`,
3950
+ detail: `breath heat mean ${tr.mean}/255 over the idle — the idle with and without its breath tracks (${tr.tracks.join(', ')}), on one grid; the whole idle reads ${tr.whole} over the box, and what is not the breath's is not counted; >= ${BREATH_TORSO_MEAN_FLOOR} is required — the chest's breath track moves too little, or the torso is not weighted to the bone it keys`,
3951
+ };
3952
+ }
3953
+
3806
3954
  /** The scene file's exceptions to `TIP_OVER_ROOT` (issues #231, #245), and the file they were read from, which a refusal names. */
3807
3955
  export interface TipExceptions {
3808
3956
  path: string;
package/src/cloth.ts CHANGED
@@ -62,7 +62,9 @@
62
62
  * Pure: no clock, no randomness; every value is a function of its inputs.
63
63
  */
64
64
  import type { ConfigConstraint, Point } from './config.ts';
65
+ import type { Mask } from './raster/types.ts';
65
66
  import { pyRound } from './round.ts';
67
+ import { segmentDistance } from './weights.ts';
66
68
 
67
69
  /** The tags a `cloth` recipe may name: the parts the proposer drafts chains on that hang. */
68
70
  export const CLOTH_TARGETS = ['bottomwear', 'back hair', 'front hair'] as const;
@@ -388,3 +390,67 @@ export function clothNote(part: string, tag: ClothTarget, trees: readonly TreeCh
388
390
  (defaults.length === 0 ? '' : `; the recipe's own defaults, measured on its synthetic fixture (AUTHORING §3): ${defaults.join(', ')}`)
389
391
  );
390
392
  }
393
+
394
+ /**
395
+ * Issue #391: a part wrapped round a tail the recipe drafted rides that tail's links. One span of the tail: a segment
396
+ * of the back hair's mesh as the recipe drafts it — the head's fixed segment, or one tree link from its origin to the
397
+ * next link (the last to the chain's tip), named by the link's bone.
398
+ */
399
+ export interface TailSpan {
400
+ bone: string;
401
+ a: Point;
402
+ b: Point;
403
+ /** Whether the span is a tree link (false: the head's fixed segment). */
404
+ link: boolean;
405
+ }
406
+
407
+ /** A tail the recipe drafted: the back hair part, its opaque mask on the rig canvas, and its mesh's spans in segment order. */
408
+ export interface Tail {
409
+ part: string;
410
+ mask: Mask;
411
+ spans: TailSpan[];
412
+ }
413
+
414
+ /** Where a part's opaque pixels lie against a drafted tail. */
415
+ export interface TailOverlap {
416
+ /** Per span, in the tail's order: the part's pixels over the tail's art whose nearest span it is. */
417
+ counts: number[];
418
+ /** The part's pixels over the tail's art (the sum of `counts`). */
419
+ over: number;
420
+ /** The part's opaque pixels in all. */
421
+ total: number;
422
+ }
423
+
424
+ /**
425
+ * Which span of the tail each of the part's pixels over the tail's art belongs to: every pixel where both masks are
426
+ * set is given to the span nearest it — the distance the weights read (`segmentDistance`, `src/weights.ts`), so a
427
+ * span here is the art the tail's own weights give mostly to that bone — the first in the tail's order on a tie. No
428
+ * threshold: a span the part touches by one pixel is one the part overlaps, and the counts are said in the note.
429
+ * Pure; the part's mask and the tail's are on the same canvas.
430
+ */
431
+ export function tailOverlap(tail: Tail, part: Mask, box: { x: number; y: number; w: number; h: number }): TailOverlap {
432
+ const counts = tail.spans.map(() => 0);
433
+ let over = 0;
434
+ let total = 0;
435
+ const W = part.width;
436
+ for (let y = box.y; y < box.y + box.h; y++) {
437
+ for (let x = box.x; x < box.x + box.w; x++) {
438
+ const i = y * W + x;
439
+ if (part.data[i] === 0) continue;
440
+ total++;
441
+ if (tail.mask.data[i] === 0) continue;
442
+ over++;
443
+ let best = 0;
444
+ let bd = Infinity;
445
+ tail.spans.forEach((s, k) => {
446
+ const d = segmentDistance([x, y], s.a, s.b);
447
+ if (d < bd) {
448
+ bd = d;
449
+ best = k;
450
+ }
451
+ });
452
+ counts[best]++;
453
+ }
454
+ }
455
+ return { counts, over, total };
456
+ }
@@ -137,6 +137,38 @@ export function heatField(frames: readonly Raster[]): Uint8Array {
137
137
  return d;
138
138
  }
139
139
 
140
+ /**
141
+ * The breath alone (issue #411): each pixel's largest per-channel RGB change
142
+ * that the breath makes, read off the idle rendered twice on one grid — with
143
+ * its breath tracks (`withBreath`) and without them (`withoutBreath`). At
144
+ * frame t the breath's own change at a pixel is (with_t - with_0) -
145
+ * (without_t - without_0): motion that is the same in both renders (a keyed
146
+ * cloth swing, a physics response to the world, a head turn) cancels, and so
147
+ * does a constant offset the breath holds from frame 0 on, while physics that
148
+ * the breath sets moving stays. The field is that change's largest magnitude
149
+ * over the frames and the three channels, capped at 255 — {@link heatField}'s
150
+ * reading when the render without the breath does not move. Both lists hold
151
+ * the same number of frames of one size; the caller holds the grid.
152
+ */
153
+ export function breathHeat(withBreath: readonly Raster[], withoutBreath: readonly Raster[]): Uint8Array {
154
+ const w0 = withBreath[0].data;
155
+ const o0 = withoutBreath[0].data;
156
+ const n = withBreath[0].width * withBreath[0].height;
157
+ const d = new Uint8Array(n);
158
+ withBreath.forEach((f, i) => {
159
+ const w = f.data;
160
+ const o = withoutBreath[i].data;
161
+ for (let p = 0; p < n; p++) {
162
+ for (let c = 0; c < 3; c++) {
163
+ const k = p * 4 + c;
164
+ const v = Math.min(255, Math.abs(w[k] - w0[k] - (o[k] - o0[k])));
165
+ if (v > d[p]) d[p] = v;
166
+ }
167
+ }
168
+ });
169
+ return d;
170
+ }
171
+
140
172
  export interface RegionHeat {
141
173
  /** Pixels measured. */
142
174
  px: number;
package/src/propose.ts CHANGED
@@ -43,7 +43,12 @@
43
43
  * layer with hanging strands ({@link Strand}) gets one pendulum chain per
44
44
  * strand instead of the single pendant chain, and one note naming every
45
45
  * strand and what became of it — a strand left without a chain is never
46
- * silent (issue #24).
46
+ * silent (issue #24). Under the `back hair` cloth recipe (issue #391) a
47
+ * layer of either tag lying on a drafted tail rides the links it overlaps
48
+ * instead: its pixels over the tail's art are each given to the nearest span
49
+ * of the back hair's mesh (`tailOverlap`, `src/cloth.ts`), and when one is a
50
+ * link the part's mesh takes those spans as its segments and no rule above
51
+ * runs for it; a note names each span with its pixel count.
47
52
  * - anything no rule claims rides its nearest trunk bone as a region —
48
53
  * including every part from an author-made layer (`<run>:author:<label>`,
49
54
  * issue #256), which is no See-through tag and so has no role: no rule
@@ -139,7 +144,7 @@ import { AUTHOR_NO_ROLE, isAuthorTag } from './tags.ts';
139
144
  import { TURN_BONE, TURN_CARRIER_TAG, TURN_PLACES, TURN_RIDER_OFFSET, TURN_RIDER_TAGS, turnFractions, turnNearest, turnPivot, turnRiderDepth, type TurnSpec } from './turn.ts';
140
145
  import { edgeLength } from './length.ts';
141
146
  import { chainSqueezes, type SqueezeFinding } from './squeeze.ts';
142
- import { RECIPE_LENGTH_RATIO, chainConstraints, clothNote, type ClothRecipe, type ClothRecipes, type ClothTarget, CLOTH_TARGETS, draftTrees, swingName, treeConstraints, type TreeChain, type TreeInput } from './cloth.ts';
147
+ import { RECIPE_LENGTH_RATIO, chainConstraints, clothNote, type ClothRecipe, type ClothRecipes, type ClothTarget, CLOTH_TARGETS, draftTrees, swingName, type Tail, tailOverlap, type TailSpan, treeConstraints, type TreeChain, type TreeInput } from './cloth.ts';
143
148
  import { TEXTURE_STRETCH_CEILING } from './check.ts';
144
149
 
145
150
  // ---------------------------------------------------------------------------
@@ -1364,6 +1369,8 @@ export function proposeWithBasis(
1364
1369
  const clothConstraints: ConfigConstraint[] = [];
1365
1370
  const clothUsed = new Set<ClothTarget>();
1366
1371
  const recipeOf = (tag: ClothTarget): ClothRecipe | null => cloth?.[tag] ?? null;
1372
+ // Issue #391: the tails the back hair recipe drafts, each with its mesh's spans, which an accessory wrapped round one rides.
1373
+ const tails: Tail[] = [];
1367
1374
  const T = (p: PartRecord, tag: ClothTarget, r: ClothRecipe, input: TreeInput): TreeChain[] => {
1368
1375
  const trees = draftTrees(input, r);
1369
1376
  const constants = [konst('cloth_chains', r.chains), konst('cloth_links', r.links), konst('length_ratio', roundTo(r.length_ratio ?? RECIPE_LENGTH_RATIO, 6))];
@@ -1548,6 +1555,13 @@ export function proposeWithBasis(
1548
1555
  }
1549
1556
  notes.push(clothNote(p.name, 'back hair', all, rcp, n, ' per side of the eye axis, from head, rooted on the eye line and tipped 4 px above its bottom'));
1550
1557
  meshes[p.name] = { grid: g, r, segments: segs };
1558
+ // Issue #391: the spans are this mesh's segments, the head's fixed one and every tree link, in segment order.
1559
+ const spans: TailSpan[] = [{ bone: 'head', a: rnd(head), b: rnd([axis, top + 13]), link: false }];
1560
+ for (const t of all) {
1561
+ const line = [...t.points, t.tip];
1562
+ t.points.forEach((q, i) => spans.push({ bone: `${t.chain}${i}`, a: q, b: line[i + 1], link: true }));
1563
+ }
1564
+ tails.push({ part: p.name, mask, spans });
1551
1565
  } else {
1552
1566
  const mask = P.alpha(p);
1553
1567
  const segs: Segment[] = [['head', rnd(head), rnd([axis, top + 13])]];
@@ -1726,7 +1740,39 @@ export function proposeWithBasis(
1726
1740
  // gets the bone and chain, the rest ride the head rigidly. A stable sort,
1727
1741
  // as Python's `sorted` is.
1728
1742
  const cands = [...P.byTag(tag)].sort((a, b) => b.opaque_px - a.opaque_px);
1743
+ // Issue #391: a layer of the tag lying on a tail the back hair recipe drafted rides the links it overlaps — the
1744
+ // spans of the tail its pixels over the tail's art fall nearest — and not head: its mesh names those bones and no
1745
+ // others, so every vertex weights by the rule the tail's own art does. The links are read off the overlap, never
1746
+ // off the part's name. A layer over no link keeps its rule below. Only with the recipe: without it no tail moves
1747
+ // by the world, and nothing here runs.
1748
+ const rides = (q: PartRecord): boolean => {
1749
+ const segments: Segment[] = [];
1750
+ const links: string[] = [];
1751
+ const said: string[] = [];
1752
+ for (const tail of tails) {
1753
+ const o = tailOverlap(tail, P.alpha(q), q);
1754
+ if (!tail.spans.some((sp, k) => sp.link && o.counts[k] > 0)) continue;
1755
+ const on: string[] = [];
1756
+ tail.spans.forEach((sp, k) => {
1757
+ if (o.counts[k] === 0) return;
1758
+ on.push(`${sp.link ? sp.bone : `${sp.bone}'s fixed segment`} ${o.counts[k]}`);
1759
+ // A link is named, so its segment is the link as the bones declare it; the head's span is written out, as the tail's mesh writes it.
1760
+ segments.push(sp.link ? sp.bone : [sp.bone, sp.a, sp.b]);
1761
+ if (sp.link) links.push(sp.bone);
1762
+ });
1763
+ said.push(`${o.over} of its ${o.total} px lie over ${tail.part}'s art, nearest ${tail.part}'s spans ${on.join(', ')} px`);
1764
+ }
1765
+ if (links.length === 0) return false;
1766
+ const [g, r] = gridR(q);
1767
+ delete regions[q.name];
1768
+ meshes[q.name] = { grid: g, r, segments };
1769
+ notes.push(
1770
+ `${q.name} (${q.from}): wraps a tail config.cloth."back hair" drafts — ${said.join('; ')} — so its mesh's segments are those spans and it rides the links ${links.join(', ')} with the tail, not head; no ${tag} bone, pendant or strand chain is drafted for it (issue #391)`,
1771
+ );
1772
+ return true;
1773
+ };
1729
1774
  for (const q of cands.slice(1)) {
1775
+ if (rides(q)) continue;
1730
1776
  regions[q.name] = 'head';
1731
1777
  notes.push(`${q.name} (${q.from}): second ${tag} layer, rigid on head`);
1732
1778
  // A region cannot swing, so strands found on it are only said.
@@ -1735,6 +1781,7 @@ export function proposeWithBasis(
1735
1781
  if (strands.length > 0) notes.push(strandNote(q, strands, [], strands, 'it rides the head as a region'));
1736
1782
  }
1737
1783
  for (const p of cands.slice(0, 1)) {
1784
+ if (rides(p)) continue;
1738
1785
  const [g, r] = gridR(p);
1739
1786
  const fullMask = dilate(P.alpha(p), 7);
1740
1787
  const onArt = (pts: ReadonlyArray<readonly [number, number]>): boolean => pts.every((q) => isOn(fullMask, q[0], q[1]));