rig-parts 2.53.0 → 2.55.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
@@ -7001,7 +7001,7 @@ and stay absent).
7001
7001
 
7002
7002
  | rule | means | change |
7003
7003
  | --- | --- | --- |
7004
- | <a id="SCENE_FILE"></a><a id="SCENE_SPEC"></a><a id="SCENE_FIELD_PRESENT"></a><a id="SCENE_FIELD_TYPE"></a><a id="SCENE_KEY_KNOWN"></a>`SCENE_FILE`, `SCENE_SPEC`, `SCENE_FIELD_PRESENT`, `SCENE_FIELD_TYPE`, `SCENE_KEY_KNOWN` | the scene file is missing, not a JSON object, not `spine-parts-scene/1`, or a field is missing, of the wrong type or not one the format reads (`canvas` two positive integers; `characters` at least one, each `id`, `build`, `offset` — an offset is never assumed (0, 0) — and an optional `scale`, a positive finite number: 0, a negative number or a non-number is refused at `characters[i].scale`; `order` a list of strings). `note`, `*_note` (strings) and `x-…` (any value) are read by nothing | the field |
7004
+ | <a id="SCENE_FILE"></a><a id="SCENE_SPEC"></a><a id="SCENE_FIELD_PRESENT"></a><a id="SCENE_FIELD_TYPE"></a><a id="SCENE_KEY_KNOWN"></a>`SCENE_FILE`, `SCENE_SPEC`, `SCENE_FIELD_PRESENT`, `SCENE_FIELD_TYPE`, `SCENE_KEY_KNOWN` | the scene file is missing, not a JSON object, not `spine-parts-scene/1`, or a field is missing, of the wrong type or not one the format reads (`canvas` two positive integers; `characters` at least one, each `id`, `build`, `offset` — an offset is never assumed (0, 0) — optional `scale` as a positive finite number, and optional `canvas_clip` and `placement_pivot` as literal `true`; `order` a list of strings). `note`, `*_note` (strings) and `x-…` (any value) are read by nothing | the field |
7005
7005
  | <a id="SCENE_ID_UNIQUE"></a><a id="SCENE_ID_FORM"></a>`SCENE_ID_UNIQUE`, `SCENE_ID_FORM` | an `id` repeated, empty, or holding `:` — the separator of a prefixed name — or `/`, `\` or a leading `.`, because an id begins every image file of its character | another id |
7006
7006
  | <a id="SCENE_EDITOR_RECEIPT"></a>`SCENE_EDITOR_RECEIPT` | `scene.plate.editor_receipts` has a malformed ledger or receipt (issue #966) | use `{receipts: [{file, sha256, from_sha256, editor}], required?}` with the same shape rules as assemble editor receipts |
7007
7007
  | <a id="SCENE_EDITOR_RECEIPT_FILE"></a>`SCENE_EDITOR_RECEIPT_FILE` | a plate receipt names a missing file | supply the edited image relative to the scene file |
@@ -7026,7 +7026,13 @@ and stay absent).
7026
7026
  | <a id="SCENE_DIAL_KEY_DECLARED"></a>`SCENE_DIAL_KEY_DECLARED` | a scene key uses `derive` on a slider's input property, including one that also carries a raw `v`; derived slider inputs are not a supported scene dial dialect | declare an explicit numeric `v` for the named dial, within the named slider's own range; group member values are checked separately |
7027
7027
  | <a id="SCENE_ANIMATION_LOOP_CLOSES"></a>`SCENE_ANIMATION_LOOP_CLOSES` | the gated posed samples at 0 and the scene clip's declared duration differ, for a new clip or an idle extension | close the posed bone, slot, geometry, alpha, clip and draw-order state; comparison omits physics simulation only and never wraps the endpoint to zero |
7028
7028
  | <a id="SCENE_ANIMATION_POSE_READABLE"></a>`SCENE_ANIMATION_POSE_READABLE` | Core cannot read or pose the compiled scene clip for its endpoint comparison | correct the construct named by Core; unreadable poses never count as closed and no scene is emitted |
7029
- | <a id="SCENE_CHARACTER_INSIDE_CANVAS"></a>`SCENE_CHARACTER_INSIDE_CANVAS` | a character's part boxes, placed at its offset, leave the canvas (the boxes and the canvas px quoted) | the offset, or the canvas |
7029
+ | <a id="SCENE_PIVOT_NAME_FREE"></a>`SCENE_PIVOT_NAME_FREE` | an opted-in character's source build already has a bone named `placement` that resolves to the generated name | rename the source bone or omit `placement_pivot` |
7030
+ | <a id="SCENE_PIVOT_UNUSED"></a>`SCENE_PIVOT_UNUSED` | an opted-in character has no scene-authored translation key on its generated pivot | add a `translate`, `translatex` or `translatey` track with a key on `<id>:placement` in `animations`, or omit `placement_pivot` |
7031
+ | <a id="SCENE_PIVOT_TRACK"></a>`SCENE_PIVOT_TRACK` | a scene track keys a property other than translation on `<id>:placement`, or keys the generated `<id>:root` carrier | key translation on `<id>:placement` and leave the carrier unkeyed |
7032
+ | <a id="SCENE_CHARACTER_INSIDE_CANVAS"></a>`SCENE_CHARACTER_INSIDE_CANVAS` | a character without `canvas_clip` has placed part bounds that leave the canvas | adjust its scale, offset or canvas, or declare `canvas_clip: true` for intentional overflow |
7033
+ | <a id="SCENE_CHARACTER_CLIP_BOUNDS"></a>`SCENE_CHARACTER_CLIP_BOUNDS` | a character with `canvas_clip: true` has nonfinite placed part bounds | check the build's part bounds and the scene's scale and offset |
7034
+ | <a id="SCENE_CHARACTER_CLIP_UNUSED"></a>`SCENE_CHARACTER_CLIP_UNUSED` | a character with `canvas_clip: true` has placed part bounds wholly inside or flush with the canvas | omit `canvas_clip` or place the character so its bounds cross a canvas edge |
7035
+ | <a id="SCENE_CHARACTER_CLIP_EMPTY"></a>`SCENE_CHARACTER_CLIP_EMPTY` | a character with `canvas_clip: true` has placed part bounds whose canvas intersection has zero width or height, or lies entirely outside | place the character so its bounds overlap the canvas with positive width and height |
7030
7036
  | <a id="SCENE_ORDER_RESOLVES"></a>`SCENE_ORDER_RESOLVES` | an order entry names no character, or `<id>:<slot>` names a slot that character does not have (its slots listed) | the entry |
7031
7037
  | <a id="SCENE_ORDER_ONCE"></a><a id="SCENE_ORDER_COMPLETE"></a>`SCENE_ORDER_ONCE`, `SCENE_ORDER_COMPLETE` | a slot is drawn twice (a slot entry repeated, or an id listed twice), or never (the character's id is absent and some of its slots are named nowhere — they are listed) | name each slot once, or the id for the slots not named elsewhere |
7032
7038
  | <a id="SCENE_NAME_PREFIXED"></a><a id="SCENE_NAME_RESOLVES"></a>`SCENE_NAME_PREFIXED`, `SCENE_NAME_RESOLVES` | a build's constraint, `stops` entry, `invariants.detached` or physics track names a bone or physics constraint its own character does not declare — one another character does (`…_PREFIXED`, naming the prefixed names it could have meant) or none does (`…_RESOLVES`); or a `--requirements` name (bone, target bone, constraint, slot, attachment, seam part) is a bare name some character holds, which the composed rig holds only prefixed | a bone or physics constraint of the same character; in a requirements file, `<id>:<name>` |
@@ -7808,6 +7814,8 @@ single-character path (§4, steps 0–9) on its own, already isolated input to a
7808
7814
  | `plates` | optional list of named layers (issue #1345); may coexist with legacy `plate`. Every layer requires `name`, `image`, `provenance` and `at: [x, y]`. `image` resolves against the scene file and keeps its native dimensions and PNG bytes, with no scale or canvas containment requirement. `at` is two finite integers locating the image **top-left in canvas pixels, y down, origin top-left**; negative/outside positions are allowed. Missing, fractional and nonfinite placement is `SCENE_PLATE_AT`. Optional `note` and `editor_receipts` have the legacy plate meanings; every ledger is verified independently. `opaque_backdrop: true` exempts only that declared layer from compose's alpha requirement; otherwise at least one decoded texel must have alpha below 255 (`SCENE_PLATE_ALPHA`), even for an oversized image. An opaque declared backdrop must also have width at least `canvas.width` **and** height at least `canvas.height`, the composed rig's stage dimensions, matching core 3.8.0 A19's rig-spec size inference. A smaller opaque backdrop is refused before output by `SCENE_PLATE_BACKDROP_SIZE`; a transparent layer has no size floor. **Size is the only check on `opaque_backdrop`:** whether `at: [x, y]` positions the backdrop to cover the stage is the scene author's job (a canvas-sized backdrop at `[400, 0]` passes size while leaving part of the stage uncovered). rigc's A19 remains enabled |
7809
7815
  | `plates[].name` | the layer's bone, slot and attachment name and exact `order` token. Names must be unique, nonempty and distinct from `root`, legacy `plate`, shared `idle`, every character id and every prefixed character bone/slot/animation (`SCENE_PLATE_NAME_UNIQUE`, `SCENE_PLATE_NAME_FREE`; a name refused by either does not also draw a cascaded `SCENE_ORDER_COMPLETE`). Emitted image files and packed atlas regions are named by 0-based declaration index (`scene-plate.<index>.png`, atlas region `scene-plate.<index>`, Spine attachment `path: "scene-plate.<index>"`), separately from character images (`SCENE_IMAGE_NAME_FREE` on any collision) — so **reordering `plates[]` renames the `scene-plate.<index>` atlas regions** even when `plates[].name` and `order` are unchanged |
7810
7816
  | `characters[].scale` | optional, a positive number; absent is 1, and 1 composes to the bytes a scene without the key writes. The character's size on the canvas, about its stage's top-left corner: a rig px `p` lands at canvas px `scale * p + offset` (issue #197). A character scaled up past its art is drawn soft — the art is not resampled; rebuild it at a higher `assemble.rig_scale` if that matters |
7817
+ | `characters[].canvas_clip` | optional literal `true` for intentional overflow (issue #1491). The placed part bounds must be finite, extend past at least one canvas edge and overlap the canvas with positive width and height. Omitting the key requires containment, with flush edges allowed. Every explicit value other than `true` is `SCENE_FIELD_TYPE` |
7818
+ | `characters[].placement_pivot` | optional literal `true` (issue #1498). Generates an identity `<id>:placement` under `root` and requires a scene-authored `translate`, `translatex` or `translatey` key on it. Every explicit value other than `true` is `SCENE_FIELD_TYPE` |
7811
7819
  | `characters[].accept` | optional, a list of bar names: the bars this character's own check may have failed and still be composed (issue #203). `compose --accept <bar>[,<bar>…]` is the same list for every character; the two are joined, so the command line applies to every character and a character's list adds to it. Each name is one of the bars `check`'s summary names, less the gate — `loop`, `seam`, `BREATH_VISIBLE`, `BLINK_NO_HOLE`, `CHAIN_LAG`, `TIP_OVER_ROOT`, `STILL_REGIONS_DARK`, `TEXTURE_STRETCH`, `ANIMATIONS_DO_NOT_FOLD` (issue #320), `STRESS_OFF_CHAIN` (issue #347), `SEAM_OVER_MOTION` (the body-root bar, issue #686); anything else is `SCENE_ACCEPT_KNOWN`. When `check/check.json` declares `spec: "rig-parts-check/1"`, `compose` reads its `bar_outcomes` for the bars whose outcome status is `FAIL` in the report's order (issue #1373); without that spec it keeps the legacy `barsNotMet` reading. A build is taken when every bar its `check.json` failed is named; its gate red, a declared requirement not PASS, or a bar not named is `SCENE_BUILD_GREEN` as before. **It is for looking, not for shipping:** the `[compose]` line says which failing bars were accepted, `scene.json` records them as the character's `accepted`, the composed rig's own check measures them again and reports them as it finds them, and the run exits 1 even when that check is PASS (a composed rig has no `parts.json`, so the seam and four judgement lines say SKIP there). A list that accepts nothing — every build green — composes to the bytes a scene without one writes |
7812
7820
  | `animations` | optional map by scene clip name, each value a rigc `MotionAnimation` (`duration`, `tracks`, optional `loop`, `note`, and core timeline collections). Names resolve against the final scene without another prefix or unit conversion: `plate`, declared named plate bones and `<id>:<bone>`, including generated dials. A new name adds; `idle` appends tracks/timelines to the composed idle, preserving its metadata and every existing character track, deform and physics constraint. Its duration must exactly equal the composed idle (`SCENE_DURATION_AGREES`); no retiming. An imported animation name cannot be replaced (`SCENE_ANIMATION_NAME_FREE`). Absent declaration preserves legacy bytes and output paths (issue #1346) |
7813
7821
  | `order` | the draw order, back to front: a character id (its slots not named elsewhere, in its own order) or one `<id>:<slot>`. Every slot of every character is drawn exactly once. Interleaving is written by naming slots: `["a", "b:arm_l", "b"]` draws `b`'s left arm between `a` and the rest of `b` |
@@ -8056,14 +8064,17 @@ What is composed:
8056
8064
  image, provenance, note, bone, slot, size, `sha256` of the PNG's bytes as compose read them — issue #1183, additive —
8057
8065
  and `judged_by: "nothing"`), `plates` when `scene.plates` is declared (each named plate's declaration, bone, slot, size, `sha256` and `judged_by: "nothing"`; the `[compose]` header line also names them in declaration order as `<N> named plate(s): <name>, ...`, and prints `no plate` only when neither `plate` nor `plates[]` is present), per character
8058
8066
  its build, offset, `scale` (only when it is not 1), `rig_size`, `rig_scale`, placed bounds (the union of its part
8059
- boxes, canvas px), shift and what it moved (`shifted`: the first-level bones, the
8060
- regions on `root`, the count of weights bound to `root`), its counts and `accepted`
8067
+ boxes, canvas px), `canvas_clip: true` and `clipped_bounds` for clipped characters,
8068
+ `placement_pivot` with the generated bone name for characters that declare a pivot,
8069
+ shift and what it moved (`shifted`: the first-level bones, the
8070
+ regions on source `root`, the count of weights bound to source `root`), its counts
8071
+ (including any generated pivot and carrier in `bones`) and `accepted`
8061
8072
  (the failing bars of its own check that an accept list took, only when there are any), and the
8062
8073
  order —
8063
8074
  as declared and as the slot list it expands to, `judged_by: "nothing"`.
8064
8075
 
8065
- A scene of one character at offset (0, 0) on a canvas of its own size, with no
8066
- plate, composes to that character's own build renamed only: on both public
8076
+ A default scene of one character at offset (0, 0) on a canvas of its own size,
8077
+ with no plate, composes to that character's own build renamed only: on both public
8067
8078
  examples `rig.json`, `motion.json`, every image, the atlas, the packed page and
8068
8079
  every idle frame are byte-identical once `<id>:` and `<id>.` are taken off, and
8069
8080
  `skeleton.json` and `skeleton.model.json` equal as values but for Spine's `path`
@@ -8079,25 +8090,91 @@ character's input arrives isolated); a composed `parts.json`, so the bars that
8079
8090
  read See-through tags are measured per character by its own `build`, not over the
8080
8091
  scene; a rig `build` did not write.
8081
8092
 
8093
+ #### Animate a character's placement (issue #1498)
8094
+
8095
+ Set `"placement_pivot": true` on a character and key `<id>:placement` in
8096
+ `animations`. For a character with `"id": "figure"`, this is a track for a
8097
+ one-second idle extension whose pose returns to setup at both ends.
8098
+
8099
+ ```json
8100
+ {
8101
+ "bone": "figure:placement",
8102
+ "property": "translate",
8103
+ "keys": [{ "t": 0, "v": [0, 0] }, { "t": 0.5, "v": [4, 0] }, { "t": 1, "v": [0, 0] }]
8104
+ }
8105
+ ```
8106
+
8107
+ Use `translate` for `[x, y]` or `translatex` and `translatey` for single values.
8108
+ The values are offsets in final scene pixels, x right and y up. The character's
8109
+ placement scale applies to its setup art and imported tracks. These authored
8110
+ translation values are already in scene units. The existing idle duration,
8111
+ posed endpoint and rig-c checks apply. Check previews use the existing size
8112
+ and sampling limits.
8113
+
8114
+ The identity pivot sits under shared `root` and parents the character's original
8115
+ first-level bones. Their setup offset and scale still apply once. When the
8116
+ source has root-bound slots or mesh weights, the unkeyed identity child
8117
+ `<id>:root` under the pivot carries them with their existing setup placement.
8118
+ This lets an idle translate mesh-driving descendants through a parent while
8119
+ Core's A15 continues to check direct idle keys on mesh drivers. Plates and
8120
+ other characters retain their own parentage. Imported clips that key the source
8121
+ root still draw `SCENE_ROOT_SHARED`. An authored key on the shared `root` still
8122
+ targets the whole scene. Named plates that collide with a generated bone draw
8123
+ `SCENE_PLATE_NAME_FREE`. An undeclared target keeps Core's
8124
+ `CE_COMPILE_ANIMATION_BONE_UNKNOWN`.
8125
+
8126
+ #### Canvas framing for intentional overflow (issue #1491)
8127
+
8128
+ `bounds` is the full placed part-box union. `clipped_bounds` is its intersection
8129
+ with the canvas. Both are `[x0, y0, x1, y1]` in canvas pixels, y down, with
8130
+ exclusive right and bottom edges. The `[compose]` character line appends the
8131
+ clipped box for each opted-in character. These boxes record static placement.
8132
+ The rig-c gate, composed rig and packed atlas retain the full art, geometry and
8133
+ motion so offstage parts can enter the canvas during playback.
8134
+
8135
+ When any character opts in, compose gives check renders the authored stage as
8136
+ their viewport. Explicit diagnostic viewports take precedence. The retained
8137
+ `check/idle_frames/` and `check/contact.png` use check's existing preview size
8138
+ cap and sampling rate. `check/idle_frames/frames.json` records the stage in
8139
+ `viewport` and identifies the pin in `pinned.by` as `--viewport`. Extremes use
8140
+ their existing explicit diagnostic grid over the same stage box.
8141
+ The stage rectangle is `[-width/2, 0, width, height]` in rig-c world coordinates,
8142
+ y up. To verify native canvas pixels, render the packed build with the stage
8143
+ rectangle as `--viewport` and the larger canvas dimension as `--max`.
8144
+
8145
+ ```sh
8146
+ rigc render --candidate <compose-out>/check/build --animation idle \
8147
+ --viewport <stage-x>,0,<canvas-width>,<canvas-height> \
8148
+ --max <larger-canvas-dimension> --out <render-out>
8149
+ ```
8150
+
8151
+ The consumer's player must pin its viewport to the authored stage and clip the
8152
+ whole scene to that rectangle throughout playback. This includes the plates and
8153
+ every character in the declared draw order.
8082
8154
 
8083
8155
  #### Compose input record (issue #1348)
8084
8156
 
8085
8157
  A fully green compose writes `compose-run.json` at the `--out` root, beside
8086
8158
  `scene.json`, with spec `rig-compose-run/1`. It removes a previous record before
8087
8159
  the stage begins, including before stage option validation; a refused input,
8088
- rig-c gate, check or accepted failing character leaves no record. The existing
8089
- rig, scene report and check keep their bytes and paths. Core's nested
8090
- `check/build/run.json` retains its own clocks; it is a different record.
8160
+ rig-c gate, check or accepted failing character leaves no record. With neither
8161
+ canvas clipping nor a placement pivot declared, the existing rig, scene report
8162
+ and check bytes and paths are stable. Core's separate `check/build/run.json`
8163
+ retains its own clocks.
8091
8164
 
8092
8165
  The fixed top-level key order is `spec`, `scene`, `characters`, `plate`, `plates`:
8093
8166
 
8094
8167
  | entry | exact binding |
8095
8168
  | --- | --- |
8096
8169
  | `scene` | `{path, sha256}`: `path` as supplied to compose and SHA-256 of the raw scene JSON bytes parsed, including whitespace |
8097
- | `characters` | sorted by `id` in code-unit order; each `{id, build, files}`, with `build` as declared in the scene, and `files` sorted by build-relative `path`; each file is `{path, sha256}` |
8170
+ | `characters` | sorted by `id` in code-unit order. Each row has `id`, `build`, `files`, then `placement` only for `canvas_clip: true`. `build` is as declared and `files` contains `{path, sha256}` entries sorted by build-relative `path`. `placement` holds `{canvas_clip: true, bounds, clipped_bounds}` from the scene report |
8098
8171
  | `plate` | legacy plate `{path, sha256}`, with its image path as declared relative to the scene file, or `null` when absent |
8099
8172
  | `plates` | every named plate `{name, path, sha256}`, sorted by `name` in code-unit order; image paths as declared relative to the scene file; `[]` when absent |
8100
8173
 
8174
+ The raw `scene.sha256` binds the placement pivot declaration and its authored
8175
+ tracks. A pivot adds no receipt field. The `placement` entry retains its canvas
8176
+ clipping fields and key order when both options are used together.
8177
+
8101
8178
  The character file inventory is exactly `check/check.json` (admission verdict),
8102
8179
  `parts.json` (rig dimensions, scale and art bounds), `rig/rig.json` (structure,
8103
8180
  skins and references), `rig/motion.json` (animation), and each distinct image
package/docs/STABILITY.md CHANGED
@@ -1187,7 +1187,9 @@ execution in historical evidence is inferred from a current export.
1187
1187
  | named scene plates | `compose` | issue #1345 adds optional `plates[]`: required `name`, `image`, `provenance`, `at: [x, y]`; optional `note`, `editor_receipts`, `opaque_backdrop`. `at` is two finite integers for the image top-left in canvas pixels, y down from the top-left origin; negatives/outside allowed, no scale, native image size including oversize. Each bone/slot/attachment uses its declared name, bone under root at `(0,0)`; attachment centre is `stage.x + at[0] + width/2`, `cropToSpineY(at[1] + height/2, canvas.height)`. Each layer's token is required exactly once in draw order, with duplicate/missing/unknown/collision refusals. Names cannot collide with root, legacy plate, shared idle, character ids or prefixed bones/slots/animations; a plate name already refused by `SCENE_PLATE_NAME_FREE` or `SCENE_PLATE_NAME_UNIQUE` does not also draw a cascaded `SCENE_ORDER_COMPLETE` (issue #1350). Only that layer's explicit `opaque_backdrop: true` exempts it from compose alpha checks; an opaque declared backdrop must additionally meet width >= canvas.width AND height >= canvas.height (the rig stage), matching core 3.8.0 A19 size inference; otherwise SCENE_PLATE_BACKDROP_SIZE refuses before emission (placement coverage of the stage is the scene author's, not checked by the tool). Transparent layers have no size floor. rigc A19 remains enabled. Named images use `scene-plate.<index>.png` (atlas region `scene-plate.<index>`, by declaration index) with collision checks. The `[compose]` header line names composed `plates[]` in declaration order (`<N> named plate(s): <name>, ...`) when `plates[]` is non-empty and prints `no plate` only when neither `plate` nor `plates[]` is present (issue #1350). The additive report `plates` array records declaration, native size and PNG hash; absent declaration retains legacy output bytes and fixed first-plate behavior. |
1188
1188
  | scene named animations | `compose` | issue #1346 adds optional `scene.animations`, a name-to-rigc-MotionAnimation map resolved against final scene bones/groups/easings. New names add clips at their own declared durations; `idle` appends timelines while retaining existing character tracks, deforms, metadata and physics. Idle duration mismatch is `SCENE_DURATION_AGREES`, without retiming; imported non-idle names cannot be replaced. Core owns missing fields, unknown bones/references, duplicate property tracks and bad times. Unknown prefixed bones also name the character ID. Generated names `<id>:yaw_dial`, `<id>:pitch_dial`, and `<id>:<turn.body.slider>` (default `<id>:body_yaw_dial`) are stable; renaming them requires a major version. A dial exists only when generated by its character. Rotation keys use that slider's declared `[from, max]` bounds; out-of-range values are `SCENE_DIAL_KEY_RANGE`, unreadable bounds `SCENE_DIAL_RANGE_DECLARED`, never guessed. Slider-input keys require explicit numeric values; derive inputs are refused as `SCENE_DIAL_KEY_DECLARED`, including derive alongside a raw value. Bounds apply to the matching scalar or paired translate/scale/shear input channel; inherited group names are refused with `CE_COMPILE_ANIMATION_GROUP_UNKNOWN`. Each declared clip's gated posed endpoints at 0 and duration must agree before emission (`SCENE_ANIMATION_LOOP_CLOSES`), with physics simulation left out only for observation. Absent declaration retains stable output bytes at the same paths. Core `check/build/run.json` records fresh `started_at` and `finished_at` clocks; comparisons report these raw differences separately and require all other receipt fields and output bytes to match. |
1189
1189
  | scene loop refusal detail | `compose` | Issue #1358 enriches `SCENE_ANIMATION_LOOP_CLOSES` with the first differing bone or slot, channel, start/end values and numeric tolerance 0 (exact equality). The existing exact JSON endpoint comparison is unchanged: bones, slots, draw order, drawn geometry, clipping polygons and clipped geometry remain covered. Selection follows that family order, then producer row and field order; geometry-only differences name the slot and geometry channel. Physics is still excluded only from observation. The refusal code, acceptance, emitted rig/motion and built scene bytes are unchanged. |
1190
- | `compose-run.json` | `compose` | spec `rig-compose-run/1` (issue #1348), separate from `rig-run/1`; a stable contract as of 2.44.0. Written at the `--out` root only after the gate and check are green and no accepted failing character remains, so an `--accept` preview writes none. Fixed keys in order: `spec`, `scene` (`path`, `sha256`), `characters` (each `id`, `build`, `files`, each file `path`, `sha256`), `plate` (`path`, `sha256`, or null), `plates` (each `name`, `path`, `sha256`). Scene and plate paths are the supplied and declared paths; character file paths are build-relative. Characters sort by `id`, files by `path`, named plates by `name`, in code-unit order. Each character's files are exactly `check/check.json`, `parts.json`, `rig/rig.json`, `rig/motion.json` and each distinct image the default skin names under `rig/images/`, including a generator's depth image. Every `sha256` is of the raw file bytes compose consumed before the gate. There are no clocks, directory extras, requirements or CLI-option inventory, so identical inputs at identical supplied paths give identical record bytes. Compose owns the name: a file of that name at the `--out` root is deleted at the start of every compose, before stage validation, so a refused rerun leaves none. Only this file is added; legacy outputs retain stable bytes, with the existing nested Core receipt clock comparison described above. |
1190
+ | scene canvas framing | `compose` | Issue #1491 adds optional `characters[].canvas_clip` to `spine-parts-scene/1`. Literal `true` requires finite placed bounds, overflow past a canvas edge and an intersection with positive width and height. The respective refusals are `SCENE_CHARACTER_CLIP_BOUNDS`, `SCENE_CHARACTER_CLIP_UNUSED` and `SCENE_CHARACTER_CLIP_EMPTY`. Other explicit values are `SCENE_FIELD_TYPE`. Omitting the key retains the exact containment rule, output bytes and console text. The opted-in character row in `scene.json` adds `canvas_clip: true` and `clipped_bounds` after the original `bounds`. Both boxes are canvas pixels, y down, with exclusive right and bottom edges. The console appends the clipped box only for those rows. The rig-c gate and packed build retain the full art and geometry. For a scene with any opt-in, compose check renders use the stage viewport unless the render specifies its own. Preview size caps and sampling stay in effect. Native-size renders and consumer playback use the authored stage rectangle as described in [Canvas framing for intentional overflow](AUTHORING.md#canvas-framing-for-intentional-overflow-issue-1491). |
1191
+ | scene placement pivot | `compose` | Issue #1498 adds optional literal `true` at `characters[].placement_pivot` in `spine-parts-scene/1`. It emits the identity `<id>:placement` under `root` and requires a scene-authored `translate`, `translatex` or `translatey` key in final scene pixels. The existing placement math stays on the original first-level bones, root regions and root weights. Source root bindings use the unkeyed identity `<id>:root` child when needed. `SCENE_FIELD_TYPE` refuses other explicit values, `SCENE_PIVOT_NAME_FREE` a source bone collision, `SCENE_PIVOT_UNUSED` an unused declaration and `SCENE_PIVOT_TRACK` a forbidden property or carrier key. `SCENE_PLATE_NAME_FREE` still governs named plate collisions. Core's unknown-bone refusal, rig gate, scene clip timing and endpoint closure still apply. `scene.json` adds `placement_pivot` with the generated name after the bounds fields and counts the generated bones for that character. `compose-run.json` binds the declaration through `scene.sha256` with its existing shape and key order. Omitting the declaration preserves default output bytes at the same paths, subject to the existing Core receipt clocks. |
1192
+ | `compose-run.json` | `compose` | spec `rig-compose-run/1` (issue #1348), separate from `rig-run/1`; a stable contract as of 2.44.0. Written at the `--out` root only after the gate and check are green and no accepted failing character remains, so an `--accept` preview writes none. Fixed keys in order: `spec`, `scene` (`path`, `sha256`), `characters` (each `id`, `build`, `files`, each file `path`, `sha256`, then optional `placement`), `plate` (`path`, `sha256`, or null), `plates` (each `name`, `path`, `sha256`). Scene and plate paths are the supplied and declared paths; character file paths are build-relative. Characters sort by `id`, files by `path`, named plates by `name`, in code-unit order. Each character's files are exactly `check/check.json`, `parts.json`, `rig/rig.json`, `rig/motion.json` and each distinct image the default skin names under `rig/images/`, including a generator's depth image. Every `sha256` is of the raw file bytes compose consumed before the gate. Only a character with `canvas_clip: true` has `placement`, with `canvas_clip: true`, `bounds` and `clipped_bounds` in that order from the scene report. There are no clocks, directory extras, requirements or CLI-option inventory, so identical inputs at identical supplied paths give identical record bytes. Compose owns the name: a file of that name at the `--out` root is deleted at the start of every compose, before stage validation, so a refused rerun leaves none. For scenes without opt-in, legacy outputs retain stable bytes, with the existing nested Core receipt clock comparison described above. |
1191
1193
  | the scene report | `compose` | spec `spine-parts-scene-report/1`; the plate block carries `sha256` of the plate PNG's bytes after `size` (issue #1183, additive under *What "stable" means here*: a new report key in a minor version, so the spec stays `/1`); `pack_mode` records `page_size` only when `--page-size <px>` is given (issue #1352, additive; without `--page-size`, rigc's default 2048 px page and padding 2 on each side bound any plate or region side to at most 2044 px before `CE_ATLAS_REGION_EXCEEDS_PAGE`) |
1192
1194
  | `idle.png`, `idle-indexed.png`, `idle.gif` | `loop`, `build --loop` | APNG and GIF encodings of the rendered idle |
1193
1195
  | `run.json` | `rig`, `assemble` | spec `rig-run/1` (issue #1165, additive): `spec`, `package` (`name`, `version`), `command` (`"rig"` or `"assemble"`), `started_at` and `finished_at` (UTC ISO-8601 millisecond timestamps ending in `Z`, read in the CLI layer), `config` (`path` relative to `--out`, `sha256` of the config file on disk), `inputs` on `assemble` (issue #1316, additive: one `{role, path, sha256}` entry for each of `--source`, `--full` and `--head` that was given, in that order, with `path` relative to the run's cwd and `sha256` of the file or of the directory's `layers.json`), and `outputs` (`path` relative to `--out`, `sha256` of each written output file on disk, sorted by `path` in code-unit order and excluding `run.json` itself); written only after the command's gate is green |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rig-parts",
3
- "version": "2.53.0",
3
+ "version": "2.55.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
  "exports": {
package/src/check.ts CHANGED
@@ -726,7 +726,7 @@ export function readCheckInputs(rigDir: string, partsHome?: string, sourcePath?:
726
726
  object: partsPath,
727
727
  detail: `no such file; ${PARTS_HOME_SENTENCE} (the seam check composites the parts parts.json lists)${hint}`,
728
728
  });
729
- } else noParts = `no parts.json: ${partsPath} does not exist and no --parts was named, so there are no parts to composite and no See-through tags to choose regions by`;
729
+ } else noParts = 'no parts.json: parts.json does not exist and no --parts was named, so there are no parts to composite and no See-through tags to choose regions by';
730
730
  }
731
731
  else {
732
732
  try {
@@ -826,7 +826,7 @@ export function readCheckInputs(rigDir: string, partsHome?: string, sourcePath?:
826
826
  const anims = motion.animations;
827
827
  const idle = isRecord(anims) ? anims.idle : undefined;
828
828
  if (idle === undefined) {
829
- noIdle = `no idle: ${motionPath} field "animations" holds ${isRecord(anims) ? `[${Object.keys(anims).join(', ')}]` : JSON.stringify(anims) ?? 'nothing'} and no "idle", so there is no loop to close and no idle frame to read`;
829
+ noIdle = `no idle: motion.json field "animations" holds ${isRecord(anims) ? `[${Object.keys(anims).join(', ')}]` : JSON.stringify(anims) ?? 'nothing'} and no "idle", so there is no loop to close and no idle frame to read`;
830
830
  } else if (!isRecord(idle)) {
831
831
  problems.push({ code: 'CHECK_IDLE_PRESENT', object: `${motionPath} animation "idle"`, detail: `is ${JSON.stringify(idle)}; an animation object is required — the loop is measured on it` });
832
832
  } else if (!(typeof idle.duration === 'number' && idle.duration > 0)) {
@@ -7228,7 +7228,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
7228
7228
  const geometry = readGeometry(geometryPath, idle.written);
7229
7229
  idleGeometry = geometry;
7230
7230
  const beforeStretch = problems.length;
7231
- stretch = stretchLine(geometry, geometryPath, problems, { ...inp, config }, checkSlotParts(inp.rig, inp.parts?.parts.map(p => p.name) ?? [], inp.parts?.alternates?.map(set => set.name) ?? []), readingSkip('TEXTURE_STRETCH'));
7231
+ stretch = stretchLine(geometry, GEOMETRY_FILE, problems, { ...inp, config }, checkSlotParts(inp.rig, inp.parts?.parts.map(p => p.name) ?? [], inp.parts?.alternates?.map(set => set.name) ?? []), readingSkip('TEXTURE_STRETCH'));
7232
7232
  stretchFailedWithoutReading = stretch.status === 'SKIP' && problems.length > beforeStretch;
7233
7233
  if (full !== null) still = stillLine(full, idle, geometry, geometryPath, problems, notPlanted, readingSkip('STILL_REGIONS_DARK'));
7234
7234
  }
@@ -7458,7 +7458,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
7458
7458
  const rows: ClothRow[] = [];
7459
7459
  let unread: string | undefined;
7460
7460
  for (const c of clothChains(inp.rig, stripped.physics)) {
7461
- const track = boneTrackOf(idleGeometry, geometryPath, idle, c.tip);
7461
+ const track = boneTrackOf(idleGeometry, idleGeometry === null ? GEOMETRY_FILE : geometryPath, idle, c.tip);
7462
7462
  if (typeof track === 'string') {
7463
7463
  unread = track;
7464
7464
  break;
@@ -9300,7 +9300,7 @@ export function stillLine(inp: FullInputs, idle: FrameSet, geo: IdleGeometry | n
9300
9300
  const { all: allFeet, held: feet, declared } = plantedFeet(inp.parts, notPlanted);
9301
9301
  const eligible = face.length > 0 || feet.length > 0;
9302
9302
  if (face.length === 0 && allFeet.length === 0) return skipped(`no part comes from a See-through ${tagWords([...FACE_TAGS, ...FEET_TAGS])} layer, so there is no still region to read`, 'no-eligible-region');
9303
- if (geo === null) return skipped(`${geometryPath} does not exist; \`rigc render --geometry\` (rig-c ${RIGC_GEOMETRY_VERSION} or later) writes it, and the still regions are read off it`, eligible ? 'no-reading' : 'no-eligible-region');
9303
+ if (geo === null) return skipped(`${GEOMETRY_FILE} does not exist; \`rigc render --geometry\` (rig-c ${RIGC_GEOMETRY_VERSION} or later) writes it, and the still regions are read off it`, eligible ? 'no-reading' : 'no-eligible-region');
9304
9304
  const H = inp.parts.rig_size[1];
9305
9305
  const W = inp.parts.rig_size[0];
9306
9306
  const poses = attachmentPoses(geometryPath, idle.written);
package/src/runstamp.ts CHANGED
@@ -33,11 +33,20 @@ export interface RunStampFileEntry {
33
33
  sha256: string;
34
34
  }
35
35
 
36
- /** Compose's consumed inputs, captured before its gate; no clock or output inventory. */
36
+ /** Compose's consumed inputs and opted-in placement, captured before its gate. */
37
37
  export interface ComposeRun {
38
38
  spec: typeof COMPOSE_RUN_SPEC;
39
39
  scene: RunStampFileEntry;
40
- characters: Array<{ id: string; build: string; files: RunStampFileEntry[] }>;
40
+ characters: Array<{
41
+ id: string;
42
+ build: string;
43
+ files: RunStampFileEntry[];
44
+ placement?: {
45
+ canvas_clip: true;
46
+ bounds: [number, number, number, number];
47
+ clipped_bounds: [number, number, number, number];
48
+ };
49
+ }>;
41
50
  plate: RunStampFileEntry | null;
42
51
  plates: Array<{ name: string; path: string; sha256: string }>;
43
52
  }
package/src/scene.ts CHANGED
@@ -49,6 +49,10 @@
49
49
  * through `src/coords.ts`. The root is shared, so a character whose idle
50
50
  * keys it, or whose constraint or stop names it, is refused
51
51
  * (`SCENE_ROOT_SHARED`): it would move every character.
52
+ * - **Placement motion (issue #1498).** `characters[].placement_pivot: true`
53
+ * adds an identity `<id>:placement` above those already placed bones. Direct
54
+ * root bindings move to an unkeyed `<id>:root` beneath it. Scene tracks key
55
+ * only translation on the pivot, in final scene units.
52
56
  * - **The scale, with the offset (issue #197).** `characters[].scale`, a
53
57
  * positive number and 1 when absent, sizes the character about its stage's
54
58
  * top-left corner: a point p of its root frame lands at `scale * p + shift`
@@ -114,7 +118,7 @@ import { clearComposeRun, COMPOSE_RUN_FILE, COMPOSE_RUN_SPEC, type ComposeRun, t
114
118
  import { readRequirements, type RequirementsFile } from './requirements.ts';
115
119
  import { OFFSET_PLACES, rigJsonText, type RigSpec } from './rig.ts';
116
120
  import { pyRound } from './round.ts';
117
- import { mergeSceneAnimations, readSceneAnimations, sceneBoneContext, sceneClipLoopProblems, type SceneAnimations } from './sceneclips.ts';
121
+ import { mergeSceneAnimations, readSceneAnimations, sceneBoneContext, sceneClipLoopProblems, type SceneAnimations, type ScenePlacementPivot } from './sceneclips.ts';
118
122
 
119
123
  /** The scene file's `spec`. */
120
124
  export const SCENE_SPEC = 'spine-parts-scene/1';
@@ -135,6 +139,8 @@ export const IMAGE_SEP = '.';
135
139
  export const PLATE = 'plate';
136
140
  export const PLATE_IMAGE = 'plate.png';
137
141
 
142
+ const PLACEMENT_BONE = 'placement';
143
+
138
144
  /** What the author says the plate's pixels are. Recorded; judged by nothing. */
139
145
  export const PROVENANCES = ['observed', 'generated', 'unknown'] as const;
140
146
  export type Provenance = (typeof PROVENANCES)[number];
@@ -164,6 +170,10 @@ export interface SceneCharacter {
164
170
  offset: [number, number];
165
171
  /** {@link SceneCharacter.scale}: the character's size on the canvas, 1 (as built) when the file leaves it out (issue #197). */
166
172
  scale: number;
173
+ /** Allow placed part bounds to cross the canvas edge (issue #1491). */
174
+ canvas_clip?: true;
175
+ /** Add a character-local translation target for scene-authored motion. */
176
+ placement_pivot?: true;
167
177
  /** The bars this character's own check may have failed and still be taken (issue #203), as the file lists them; empty when it lists none. */
168
178
  accept: string[];
169
179
  }
@@ -364,7 +374,9 @@ export function loadScene(path: string): SceneFile {
364
374
  fail('SCENE_FIELD_TYPE', where, `is ${show(c)}; {"id", "build", "offset"} is required`);
365
375
  return;
366
376
  }
367
- known(c, where, ['id', 'build', 'offset', 'scale', 'accept']);
377
+ const keys = ['id', 'build', 'offset', 'scale', 'accept', 'canvas_clip'];
378
+ if ('placement_pivot' in c) keys.push('placement_pivot'); // Keep the default unknown-key diagnostic byte-stable.
379
+ known(c, where, keys);
368
380
  let ok = true;
369
381
  for (const k of ['id', 'build', 'offset']) {
370
382
  if (!(k in c)) {
@@ -402,6 +414,14 @@ export function loadScene(path: string): SceneFile {
402
414
  fail('SCENE_FIELD_TYPE', `${where}.scale`, `is ${show(sc)}; a positive finite number is required — the character's size on the canvas about its stage's top-left corner, 1 drawing it as built (the default when the key is absent)`);
403
415
  ok = false;
404
416
  }
417
+ if ('canvas_clip' in c && c.canvas_clip !== true) {
418
+ fail('SCENE_FIELD_TYPE', `${where}.canvas_clip`, `is ${show(c.canvas_clip)}; literal true is required when the key is present — omit it to require containment on the canvas`);
419
+ ok = false;
420
+ }
421
+ if ('placement_pivot' in c && c.placement_pivot !== true) {
422
+ fail('SCENE_FIELD_TYPE', `${where}.placement_pivot`, `is ${show(c.placement_pivot)}. Literal true is required when the key is present`);
423
+ ok = false;
424
+ }
405
425
  const acc = c.accept;
406
426
  if ('accept' in c) {
407
427
  if (!(Array.isArray(acc) && acc.every((v) => typeof v === 'string'))) {
@@ -413,7 +433,16 @@ export function loadScene(path: string): SceneFile {
413
433
  if (named.length > 0) ok = false;
414
434
  }
415
435
  }
416
- if (ok) characters.push({ id: id as string, build: c.build as string, buildDir: resolve(base, c.build as string), offset: [(off as number[])[0], (off as number[])[1]], scale: 'scale' in c ? (sc as number) : 1, accept: 'accept' in c ? [...(acc as string[])] : [] });
436
+ if (ok) characters.push({
437
+ id: id as string,
438
+ build: c.build as string,
439
+ buildDir: resolve(base, c.build as string),
440
+ offset: [(off as number[])[0], (off as number[])[1]],
441
+ scale: 'scale' in c ? (sc as number) : 1,
442
+ accept: 'accept' in c ? [...(acc as string[])] : [],
443
+ ...(c.canvas_clip === true ? { canvas_clip: true } : {}),
444
+ ...(c.placement_pivot === true ? { placement_pivot: true } : {}),
445
+ });
417
446
  });
418
447
  }
419
448
 
@@ -1063,6 +1092,11 @@ export interface SceneCharacterReport {
1063
1092
  rig_scale: number;
1064
1093
  /** The union of the character's part boxes, placed: canvas px, [x0, y0, x1, y1], x1 and y1 exclusive. */
1065
1094
  bounds: [number, number, number, number];
1095
+ canvas_clip?: true;
1096
+ /** Intersection of the placed bounds and the canvas, in the same coordinates as bounds. */
1097
+ clipped_bounds?: [number, number, number, number];
1098
+ /** Final bone name of the opted-in scene translation target. */
1099
+ placement_pivot?: string;
1066
1100
  /** {@link rootShift}: what was added to the x and y of everything the character places in root's frame (after its scale), in Spine units (canvas px, y up). */
1067
1101
  shift: [number, number];
1068
1102
  /** What the shift was added to: the first-level bones, the slots on `root` whose regions moved, and the count of mesh weights bound to `root`. */
@@ -1135,6 +1169,24 @@ export function composeScene(
1135
1169
  const ready = builds.filter((b): b is CharacterBuild => b !== null);
1136
1170
  const byId = new Map(ready.map((b) => [b.id, b]));
1137
1171
  const ids = scene.characters.map((c) => c.id);
1172
+ const pivots = new Map<string, ScenePlacementPivot>();
1173
+ const generatedBones = new Set<string>();
1174
+ scene.characters.forEach((c, i) => {
1175
+ if (c.placement_pivot !== true) return;
1176
+ const name = prefixed(c.id, PLACEMENT_BONE);
1177
+ generatedBones.add(name);
1178
+ const b = byId.get(c.id);
1179
+ if (b === undefined) return;
1180
+ const field = `scene.characters[${i}].placement_pivot`;
1181
+ if (b.rig.bones.some(bone => bone.name === PLACEMENT_BONE)) {
1182
+ fail('SCENE_PIVOT_NAME_FREE', field, `would emit bone ${show(name)}, already taken by source bone ${show(PLACEMENT_BONE)}. Rename that source bone or omit the opt-in`);
1183
+ }
1184
+ const bindsRoot = b.rig.slots.some(slot => slot.bone === ROOT_BONE) || Object.values(b.rig.skins.default).some(atts =>
1185
+ Object.values(atts).some(att => 'weights' in att && att.weights.some(vertex => vertex.some(weight => weight.bone === ROOT_BONE))));
1186
+ const rootBinding = bindsRoot ? prefixed(c.id, ROOT_BONE) : undefined;
1187
+ if (rootBinding !== undefined) generatedBones.add(rootBinding);
1188
+ pivots.set(c.id, { name, rootBinding, field });
1189
+ });
1138
1190
 
1139
1191
  // ---- the plate ----------------------------------------------------------
1140
1192
  if (scene.plate !== null && plate !== null && (plate.width !== canvas.width || plate.height !== canvas.height)) {
@@ -1143,7 +1195,7 @@ export function composeScene(
1143
1195
 
1144
1196
  const layers = scene.plates ?? [];
1145
1197
  const layerNames = new Set(layers.map(p => p.name));
1146
- const reserved = new Set([ROOT_BONE, PLATE, 'idle', ...ids, ...ready.flatMap(b => [
1198
+ const reserved = new Set([ROOT_BONE, PLATE, 'idle', ...ids, ...generatedBones, ...ready.flatMap(b => [
1147
1199
  ...b.rig.bones.map(x => prefixed(b.id, x.name)),
1148
1200
  ...b.rig.slots.map(x => prefixed(b.id, x.name)),
1149
1201
  ...Object.keys(b.motion.animations).map(n => prefixed(b.id, n)),
@@ -1194,15 +1246,36 @@ export function composeScene(
1194
1246
  const [x0, y0, x1, y1] = b.artBox;
1195
1247
  const s = c.scale;
1196
1248
  const bounds: [number, number, number, number] = [scaledBy(x0, s) + c.offset[0], scaledBy(y0, s) + c.offset[1], scaledBy(x1, s) + c.offset[0], scaledBy(y1, s) + c.offset[1]];
1197
- if (bounds[0] < 0 || bounds[1] < 0 || bounds[2] > canvas.width || bounds[3] > canvas.height) {
1249
+ const overflow = bounds[0] < 0 || bounds[1] < 0 || bounds[2] > canvas.width || bounds[3] > canvas.height;
1250
+ const where = `scene.characters[${i}] "${c.id}"`;
1251
+ const placement = `its parts' boxes (rig px [${x0}, ${y0}, ${x1}, ${y1}]) at offset [${c.offset.join(', ')}]${s === 1 ? '' : ` and scale ${s}`} cover canvas px [${bounds.join(', ')}]`;
1252
+ let clippedBounds: SceneCharacterReport['clipped_bounds'];
1253
+ if (c.canvas_clip === true) {
1254
+ if (!bounds.every(Number.isFinite)) {
1255
+ fail('SCENE_CHARACTER_CLIP_BOUNDS', where, `${placement}; canvas_clip requires four finite bounds`);
1256
+ } else if (!overflow) {
1257
+ fail('SCENE_CHARACTER_CLIP_UNUSED', where, `${placement}, entirely within the ${canvas.width}x${canvas.height} canvas; canvas_clip requires overflow past at least one edge`);
1258
+ } else {
1259
+ const left = Math.max(0, bounds[0]);
1260
+ const top = Math.max(0, bounds[1]);
1261
+ const right = Math.min(canvas.width, bounds[2]);
1262
+ const bottom = Math.min(canvas.height, bounds[3]);
1263
+ if (left >= right || top >= bottom) {
1264
+ fail('SCENE_CHARACTER_CLIP_EMPTY', where, `${placement}; canvas_clip requires positive intersection width and height on the ${canvas.width}x${canvas.height} canvas`);
1265
+ } else {
1266
+ clippedBounds = [left, top, right, bottom];
1267
+ }
1268
+ }
1269
+ } else if (overflow) {
1198
1270
  fail(
1199
1271
  'SCENE_CHARACTER_INSIDE_CANVAS',
1200
- `scene.characters[${i}] "${c.id}"`,
1201
- `its parts' boxes (rig px [${x0}, ${y0}, ${x1}, ${y1}]) at offset [${c.offset.join(', ')}]${s === 1 ? '' : ` and scale ${s}`} cover canvas px [${bounds.join(', ')}], which leaves the ${canvas.width}x${canvas.height} canvas; 0 <= x0, 0 <= y0, x1 <= ${canvas.width} and y1 <= ${canvas.height} are required`,
1272
+ where,
1273
+ `${placement}, which leaves the ${canvas.width}x${canvas.height} canvas; 0 <= x0, 0 <= y0, x1 <= ${canvas.width} and y1 <= ${canvas.height} are required`,
1202
1274
  );
1203
1275
  }
1204
1276
  problems.push(...scaleProblems(c, b));
1205
1277
  const shift = rootShift(b.rig.skeleton, stage, c.offset, s);
1278
+ const pivot = pivots.get(c.id);
1206
1279
  rows.push({
1207
1280
  id: c.id,
1208
1281
  build: c.build,
@@ -1211,13 +1284,15 @@ export function composeScene(
1211
1284
  rig_size: [...b.rigSize],
1212
1285
  rig_scale: b.rigScale,
1213
1286
  bounds,
1287
+ ...(clippedBounds === undefined ? {} : { canvas_clip: true, clipped_bounds: clippedBounds }),
1288
+ ...(pivot === undefined ? {} : { placement_pivot: pivot.name }),
1214
1289
  shift,
1215
1290
  shifted: {
1216
1291
  bones: b.rig.bones.filter((x) => x.parent === ROOT_BONE).map((x) => prefixed(c.id, x.name)),
1217
1292
  root_regions: b.rig.slots.filter((s) => s.bone === ROOT_BONE && Object.values(b.rig.skins.default[s.name] ?? {}).some((a) => !('weights' in a))).map((s) => prefixed(c.id, s.name)),
1218
1293
  root_weights: Object.values(b.rig.skins.default).flatMap((atts) => Object.values(atts)).reduce((n, a) => n + ('weights' in a ? a.weights.flat().filter((w) => w.bone === ROOT_BONE).length : 0), 0),
1219
1294
  },
1220
- bones: b.rig.bones.length - 1,
1295
+ bones: b.rig.bones.length - 1 + (pivot === undefined ? 0 : 1) + (pivot?.rootBinding === undefined ? 0 : 1),
1221
1296
  slots: b.rig.slots.length,
1222
1297
  tracks: b.motion.animations.idle.tracks.length,
1223
1298
  constraints: b.rig.constraints?.length ?? 0,
@@ -1260,6 +1335,7 @@ export function composeScene(
1260
1335
  const own = slotsOf.get(id);
1261
1336
  if (own === undefined) return;
1262
1337
  if (!own.includes(slot)) {
1338
+ if (layerNames.has(e) && generatedBones.has(e)) return; // The plate collision already names this entry.
1263
1339
  fail('SCENE_ORDER_RESOLVES', at, `is "${e}"; character "${id}" has no slot "${slot}" — its slots are ${own.map((s) => `"${s}"`).join(', ')}`);
1264
1340
  return;
1265
1341
  }
@@ -1313,6 +1389,33 @@ export function composeScene(
1313
1389
  fail('SCENE_NAME_PREFIXED', where, `names the physics constraint "${name}", which character "${id}" does not declare and ${other.map((x) => `"${x}"`).join(', ')} does${other.length > 1 ? ' each' : ''}; a name crosses characters only with its prefix — ${other.map((x) => `"${prefixed(x, name)}"`).join(' or ')} — and a build's track may name only its own physics constraints`);
1314
1390
  } else fail('SCENE_NAME_RESOLVES', where, `names the physics constraint "${name}", which no character of the scene declares`);
1315
1391
  };
1392
+ // A generated pivot must not resolve an undeclared source bone reference.
1393
+ // Group members can also be slots or physics constraints, depending on the property.
1394
+ const isBoneProperty = (property: string): boolean => SCALED_TRACK_PROPERTIES.includes(property) || UNSCALED_TRACK_PROPERTIES.includes(property);
1395
+ const sceneBoneGroups = new Set<string>();
1396
+ if (pivots.size > 0) for (const clip of Object.values(scene.animations ?? {})) for (const track of clip.tracks) {
1397
+ if (track.group !== undefined && isBoneProperty(track.property)) sceneBoneGroups.add(track.group);
1398
+ }
1399
+ for (const b of ready) if (pivots.has(b.id) && !bonesOf.get(b.id)?.has(PLACEMENT_BONE)) {
1400
+ const check = (name: unknown, where: string): void => {
1401
+ if (name === PLACEMENT_BONE) ownBone(b.id, name, `character "${b.id}" ${where}`);
1402
+ };
1403
+ for (const [i, bone] of b.rig.bones.entries()) check(bone.parent, `rig.json bones[${i}].parent`);
1404
+ for (const [i, slot] of b.rig.slots.entries()) check(slot.bone, `rig.json slots[${i}].bone`);
1405
+ for (const [slot, atts] of Object.entries(b.rig.skins.default)) for (const [name, att] of Object.entries(atts)) {
1406
+ if ('weights' in att && att.weights.some(vertex => vertex.some(weight => weight.bone === PLACEMENT_BONE))) {
1407
+ check(PLACEMENT_BONE, `rig.json skins.default.${slot}.${name}.weights`);
1408
+ }
1409
+ }
1410
+ const boneGroups = new Set(Object.keys(b.motion.groups).filter(group => sceneBoneGroups.has(prefixed(b.id, group))));
1411
+ for (const [name, anim] of Object.entries(animationsOf(b.motion))) for (const [i, track] of anim.tracks.entries()) {
1412
+ check(track.bone, `motion.json animations.${name}.tracks[${i}].bone`);
1413
+ if (track.group !== undefined && isBoneProperty(track.property)) boneGroups.add(track.group);
1414
+ }
1415
+ for (const group of boneGroups) {
1416
+ if (b.motion.groups[group]?.includes(PLACEMENT_BONE)) check(PLACEMENT_BONE, `motion.json groups.${group}`);
1417
+ }
1418
+ }
1316
1419
  for (const b of ready) {
1317
1420
  (b.rig.constraints ?? []).forEach((con, k) => {
1318
1421
  const type = con.type as keyof typeof CONSTRAINT_BONE_FIELDS;
@@ -1459,6 +1562,12 @@ export function composeScene(
1459
1562
  const id = c.id;
1460
1563
  const s = c.scale;
1461
1564
  const [dx, dy] = rootShift(b.rig.skeleton, stage, c.offset, s);
1565
+ const pivot = pivots.get(id);
1566
+ const rootBinding = pivot?.rootBinding ?? ROOT_BONE;
1567
+ if (pivot !== undefined) {
1568
+ bones.push({ name: pivot.name, parent: ROOT_BONE, x: 0, y: 0 });
1569
+ if (pivot.rootBinding !== undefined) bones.push({ name: pivot.rootBinding, parent: pivot.name, x: 0, y: 0 });
1570
+ }
1462
1571
  // At a scale other than 1 every length the character carries is scaled (issue #197): each bone's x, y and length,
1463
1572
  // each region's x, y (and its drawn size, by scaleX/scaleY), each weight's bind x, y, the constraints' lengths
1464
1573
  // (scaledConstraint), each stop's at offset in against's local frame (scaledStop; issue #431) and the translate keys
@@ -1467,9 +1576,13 @@ export function composeScene(
1467
1576
  if (bone.name === ROOT_BONE) continue;
1468
1577
  const first = bone.parent === ROOT_BONE;
1469
1578
  const sized = s === 1 ? {} : { x: scaledBy(bone.x, s), y: scaledBy(bone.y, s), ...(bone.length === undefined ? {} : { length: scaledBy(bone.length, s) }) };
1470
- bones.push({ ...bone, name: P(id, bone.name), ...(bone.parent === undefined ? {} : { parent: P(id, bone.parent) }), ...sized, ...(first ? { x: placed(bone.x, dx, s), y: placed(bone.y, dy, s) } : {}) });
1579
+ const parent = first ? pivot?.name ?? ROOT_BONE : bone.parent === undefined ? undefined : P(id, bone.parent);
1580
+ bones.push({ ...bone, name: P(id, bone.name), ...(parent === undefined ? {} : { parent }), ...sized, ...(first ? { x: placed(bone.x, dx, s), y: placed(bone.y, dy, s) } : {}) });
1581
+ }
1582
+ for (const slot of b.rig.slots) {
1583
+ const bone = slot.bone === ROOT_BONE ? rootBinding : P(id, slot.bone);
1584
+ slotDefs.set(prefixed(id, slot.name), { ...slot, name: prefixed(id, slot.name), bone, attachment: slot.attachment === null ? null : prefixed(id, slot.attachment) });
1471
1585
  }
1472
- for (const s of b.rig.slots) slotDefs.set(prefixed(id, s.name), { ...s, name: prefixed(id, s.name), bone: P(id, s.bone), attachment: s.attachment === null ? null : prefixed(id, s.attachment) });
1473
1586
  // Everything the character places in root's own frame moves with it: a region on a slot root carries, and a
1474
1587
  // weight bound to root. Every other offset is local to a bone the shift already moved.
1475
1588
  const slotBone = new Map(b.rig.slots.map((s) => [s.name, s.bone]));
@@ -1489,7 +1602,7 @@ export function composeScene(
1489
1602
  a.weights = (att.weights as Array<Array<Record<string, unknown>>>).map((v) =>
1490
1603
  v.map((w) =>
1491
1604
  w.bone === ROOT_BONE
1492
- ? { ...w, x: placed(w.x as number, dx, s), y: placed(w.y as number, dy, s) }
1605
+ ? { ...w, bone: rootBinding, x: placed(w.x as number, dx, s), y: placed(w.y as number, dy, s) }
1493
1606
  : { ...w, bone: P(id, w.bone as string), ...(s === 1 ? {} : { x: scaledBy(w.x as number, s), y: scaledBy(w.y as number, s) }) },
1494
1607
  ),
1495
1608
  );
@@ -1608,7 +1721,7 @@ export function composeScene(
1608
1721
  const note = notes.size === 1 ? [...notes][0] : ready.map((b) => `${b.id}: ${b.motion.animations.idle.note}`).join(' | ');
1609
1722
  const motion: MotionSpec = { spec: 'rigc-motion/1', archetype: name, cut: name, easings, groups, animations: { idle: { duration: durations[0], loop: true, note, tracks, ...(idleDeform.length === 0 ? {} : { deform: idleDeform }) }, ...beside } };
1610
1723
 
1611
- if (scene.animations !== undefined) mergeSceneAnimations(rig, motion, scene.animations);
1724
+ if (scene.animations !== undefined || pivots.size > 0) mergeSceneAnimations(rig, motion, scene.animations ?? {}, [...pivots.values()]);
1612
1725
 
1613
1726
  const report: SceneReport = {
1614
1727
  spec: SCENE_REPORT_SPEC,
@@ -1838,7 +1951,12 @@ export function composeFromFiles(scenePath: string, requirementsPath?: string, m
1838
1951
  const runRecord: ComposeRun = {
1839
1952
  spec: COMPOSE_RUN_SPEC,
1840
1953
  scene: { path: scenePath, sha256: scene.sha256 },
1841
- characters: scene.characters.map(c => ({ id: c.id, build: c.build, files: builds.find(b => b?.id === c.id)!.files }))
1954
+ characters: composed.report.characters.map(c => ({
1955
+ id: c.id,
1956
+ build: c.build,
1957
+ files: builds.find(b => b?.id === c.id)!.files,
1958
+ ...(c.clipped_bounds === undefined ? {} : { placement: { canvas_clip: true as const, bounds: c.bounds, clipped_bounds: c.clipped_bounds } }),
1959
+ }))
1842
1960
  .sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0),
1843
1961
  plate: scene.plate === null || plate === null ? null : { path: scene.plate.image, sha256: createHash('sha256').update(plate.bytes).digest('hex') },
1844
1962
  plates: (scene.plates ?? []).map((p, i) => ({ name: p.name, path: p.image, sha256: createHash('sha256').update(plateLayers[i]!.bytes).digest('hex') }))
@@ -1920,7 +2038,8 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
1920
2038
  : ', no plate';
1921
2039
  say(`${r.characters.length} character(s) on a ${r.canvas.width}x${r.canvas.height} canvas, rig "${r.rig_name}"${plateClause}`);
1922
2040
  for (const c of r.characters) {
1923
- say(` ${c.id}: ${c.build} at offset [${c.offset.join(', ')}], scale ${c.scale ?? 1}, bounds [${c.bounds.join(', ')}], shift [${c.shift.join(', ')}] on ${c.shifted.bones.length} first-level bone(s), ${c.shifted.root_regions.length} region(s) on root and ${c.shifted.root_weights} weight(s) bound to root; ${c.bones} bone(s), ${c.slots} slot(s), ${c.tracks} track(s), ${c.constraints} constraint(s), rig_scale ${c.rig_scale}, idle ${c.idle_duration} s${c.accepted === undefined ? '' : `; its own check FAILED ${c.accepted.join(', ')}, accepted — the scene is for looking, not shipping`}`);
2041
+ const clipped = c.clipped_bounds === undefined ? '' : `; clipped bounds [${c.clipped_bounds.join(', ')}]`;
2042
+ say(` ${c.id}: ${c.build} at offset [${c.offset.join(', ')}], scale ${c.scale ?? 1}, bounds [${c.bounds.join(', ')}], shift [${c.shift.join(', ')}] on ${c.shifted.bones.length} first-level bone(s), ${c.shifted.root_regions.length} region(s) on root and ${c.shifted.root_weights} weight(s) bound to root; ${c.bones} bone(s), ${c.slots} slot(s), ${c.tracks} track(s), ${c.constraints} constraint(s), rig_scale ${c.rig_scale}, idle ${c.idle_duration} s${c.accepted === undefined ? '' : `; its own check FAILED ${c.accepted.join(', ')}, accepted — the scene is for looking, not shipping`}${clipped}`);
1924
2043
  }
1925
2044
  say(` order (declared, judged by nothing): ${r.order.declared.join(', ')} -> ${r.order.slots.length} slot(s), back to front`);
1926
2045
  const texts: Array<[string, string]> = [
@@ -1960,9 +2079,17 @@ export function composeStage(input: ComposeInput, run: ComposeRunners, log: Log)
1960
2079
  for (const [file, text] of texts) writeFileSync(join(rigDir, file), text);
1961
2080
  writeFileSync(join(input.out, SCENE_REPORT_FILE), rigJsonText(r));
1962
2081
  say(`wrote ${join(rigDir, 'rig.json')}, motion.json and ${composed.images.length} image(s) under ${join(rigDir, 'images')}, and ${join(input.out, SCENE_REPORT_FILE)}`);
2082
+ let checkRigc = run.check;
2083
+ if (r.characters.some(c => c.canvas_clip === true)) {
2084
+ const stage = composed.rig.skeleton;
2085
+ const viewport = [stage.x, stage.y, stage.width, stage.height].join(',');
2086
+ checkRigc = args => run.check(args[0] === 'render' && !args.includes('--viewport') && !args.includes('--viewport-from')
2087
+ ? [...args, '--viewport', viewport]
2088
+ : args);
2089
+ }
1963
2090
  let report: CheckReport;
1964
2091
  try {
1965
- report = checkStage({ rig: rigDir, out: join(input.out, 'check'), pageEdges: mode.pageEdges, packShape: mode.packShape, ...(pageSize === undefined ? {} : { pageSize }), ...(input.requirements === undefined ? {} : { requirements: input.requirements }) }, run.check, run.checkBin, prefix('check'));
2092
+ report = checkStage({ rig: rigDir, out: join(input.out, 'check'), pageEdges: mode.pageEdges, packShape: mode.packShape, ...(pageSize === undefined ? {} : { pageSize }), ...(input.requirements === undefined ? {} : { requirements: input.requirements }) }, checkRigc, run.checkBin, prefix('check'));
1966
2093
  } catch (err) {
1967
2094
  return refused('check', err, composed);
1968
2095
  }
package/src/sceneclips.ts CHANGED
@@ -8,6 +8,47 @@ import type { RigSpec } from './rig.ts';
8
8
 
9
9
  export type SceneAnimations = CoreMotion['animations'];
10
10
 
11
+ export interface ScenePlacementPivot {
12
+ name: string;
13
+ rootBinding?: string;
14
+ field: string;
15
+ }
16
+
17
+ const PLACEMENT_TRANSLATIONS: readonly string[] = ['translate', 'translatex', 'translatey'];
18
+
19
+ function placementTrackProblems(clips: SceneAnimations, pivots: readonly ScenePlacementPivot[]): Problem[] {
20
+ if (pivots.length === 0) return [];
21
+ const problems: Problem[] = [];
22
+ const targets = new Map<string, ScenePlacementPivot>();
23
+ const unused = new Set(pivots);
24
+ for (const pivot of pivots) {
25
+ targets.set(pivot.name, pivot);
26
+ if (pivot.rootBinding !== undefined) targets.set(pivot.rootBinding, pivot);
27
+ }
28
+ for (const [name, clip] of Object.entries(clips)) for (const [i, track] of clip.tracks.entries()) {
29
+ if (track.bone === undefined) continue;
30
+ const pivot = targets.get(track.bone);
31
+ if (pivot === undefined) continue;
32
+ const onPivot = track.bone === pivot.name;
33
+ if (!onPivot || !PLACEMENT_TRANSLATIONS.includes(track.property)) {
34
+ problems.push({
35
+ code: 'SCENE_PIVOT_TRACK', object: `scene.animations.${name}.tracks[${i}]`,
36
+ detail: `keys ${JSON.stringify(track.bone)} with ${JSON.stringify(track.property)}. ${onPivot
37
+ ? `Its scene motion must use ${PLACEMENT_TRANSLATIONS.join(', ')} in final scene units`
38
+ : `The root binding must stay unkeyed. Key translation on ${JSON.stringify(pivot.name)}`}`,
39
+ });
40
+ unused.delete(pivot); // The track refusal already explains how to key this pivot.
41
+ } else if (track.keys.length > 0) {
42
+ unused.delete(pivot); // Core validates the key values, times, curves and target shape.
43
+ }
44
+ }
45
+ for (const pivot of unused) problems.push({
46
+ code: 'SCENE_PIVOT_UNUSED', object: pivot.field,
47
+ detail: `adds bone ${JSON.stringify(pivot.name)} with no scene translation key. Key it with ${PLACEMENT_TRANSLATIONS.join(', ')} in scene.animations or omit the opt-in`,
48
+ });
49
+ return problems;
50
+ }
51
+
11
52
  /** Core owns shape, required numbers, key times and all target families. */
12
53
  export function readSceneAnimations(raw: unknown, where: string): SceneAnimations {
13
54
  try {
@@ -32,8 +73,8 @@ function sliderInputChannel(source: unknown, property: string): number | null {
32
73
  }
33
74
 
34
75
  /** Append timelines without changing existing idle payloads or character physics. */
35
- export function mergeSceneAnimations(rig: RigSpec, motion: MotionSpec, clips: SceneAnimations): void {
36
- const problems: Problem[] = [];
76
+ export function mergeSceneAnimations(rig: RigSpec, motion: MotionSpec, clips: SceneAnimations, pivots: readonly ScenePlacementPivot[] = []): void {
77
+ const problems = placementTrackProblems(clips, pivots);
37
78
  const animations = motion.animations as unknown as SceneAnimations;
38
79
  for (const [name, clip] of Object.entries(clips)) {
39
80
  const existing = Object.hasOwn(animations, name) ? animations[name] : undefined;