rig-parts 2.54.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) — optional `scale` as a positive finite number, and optional `canvas_clip` as literal `true`; `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,6 +7026,9 @@ 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_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 |
7029
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 |
7030
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 |
7031
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 |
@@ -7812,6 +7815,7 @@ single-character path (§4, steps 0–9) on its own, already isolated input to a
7812
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 |
7813
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 |
7814
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` |
7815
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 |
7816
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) |
7817
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` |
@@ -8060,15 +8064,17 @@ What is composed:
8060
8064
  image, provenance, note, bone, slot, size, `sha256` of the PNG's bytes as compose read them — issue #1183, additive —
8061
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
8062
8066
  its build, offset, `scale` (only when it is not 1), `rig_size`, `rig_scale`, placed bounds (the union of its part
8063
- boxes, canvas px), `canvas_clip: true` and `clipped_bounds` for opted-in characters,
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,
8064
8069
  shift and what it moved (`shifted`: the first-level bones, the
8065
- regions on `root`, the count of weights bound to `root`), its counts and `accepted`
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`
8066
8072
  (the failing bars of its own check that an accept list took, only when there are any), and the
8067
8073
  order —
8068
8074
  as declared and as the slot list it expands to, `judged_by: "nothing"`.
8069
8075
 
8070
- A scene of one character at offset (0, 0) on a canvas of its own size, with no
8071
- 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
8072
8078
  examples `rig.json`, `motion.json`, every image, the atlas, the packed page and
8073
8079
  every idle frame are byte-identical once `<id>:` and `<id>.` are taken off, and
8074
8080
  `skeleton.json` and `skeleton.model.json` equal as values but for Spine's `path`
@@ -8084,6 +8090,39 @@ character's input arrives isolated); a composed `parts.json`, so the bars that
8084
8090
  read See-through tags are measured per character by its own `build`, not over the
8085
8091
  scene; a rig `build` did not write.
8086
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
+
8087
8126
  #### Canvas framing for intentional overflow (issue #1491)
8088
8127
 
8089
8128
  `bounds` is the full placed part-box union. `clipped_bounds` is its intersection
@@ -8118,9 +8157,10 @@ every character in the declared draw order.
8118
8157
  A fully green compose writes `compose-run.json` at the `--out` root, beside
8119
8158
  `scene.json`, with spec `rig-compose-run/1`. It removes a previous record before
8120
8159
  the stage begins, including before stage option validation; a refused input,
8121
- rig-c gate, check or accepted failing character leaves no record. Scenes without
8122
- canvas clipping retain the existing rig, scene report and check bytes and paths.
8123
- Core's separate `check/build/run.json` retains its own clocks.
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.
8124
8164
 
8125
8165
  The fixed top-level key order is `spec`, `scene`, `characters`, `plate`, `plates`:
8126
8166
 
@@ -8131,6 +8171,10 @@ The fixed top-level key order is `spec`, `scene`, `characters`, `plate`, `plates
8131
8171
  | `plate` | legacy plate `{path, sha256}`, with its image path as declared relative to the scene file, or `null` when absent |
8132
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 |
8133
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
+
8134
8178
  The character file inventory is exactly `check/check.json` (admission verdict),
8135
8179
  `parts.json` (rig dimensions, scale and art bounds), `rig/rig.json` (structure,
8136
8180
  skins and references), `rig/motion.json` (animation), and each distinct image
package/docs/STABILITY.md CHANGED
@@ -1188,6 +1188,7 @@ execution in historical evidence is inferred from a current export.
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
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. |
1191
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. |
1192
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`) |
1193
1194
  | `idle.png`, `idle-indexed.png`, `idle.gif` | `loop`, `build --loop` | APNG and GIF encodings of the rendered idle |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rig-parts",
3
- "version": "2.54.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/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];
@@ -166,6 +172,8 @@ export interface SceneCharacter {
166
172
  scale: number;
167
173
  /** Allow placed part bounds to cross the canvas edge (issue #1491). */
168
174
  canvas_clip?: true;
175
+ /** Add a character-local translation target for scene-authored motion. */
176
+ placement_pivot?: true;
169
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. */
170
178
  accept: string[];
171
179
  }
@@ -366,7 +374,9 @@ export function loadScene(path: string): SceneFile {
366
374
  fail('SCENE_FIELD_TYPE', where, `is ${show(c)}; {"id", "build", "offset"} is required`);
367
375
  return;
368
376
  }
369
- known(c, where, ['id', 'build', 'offset', 'scale', 'accept', 'canvas_clip']);
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);
370
380
  let ok = true;
371
381
  for (const k of ['id', 'build', 'offset']) {
372
382
  if (!(k in c)) {
@@ -408,6 +418,10 @@ export function loadScene(path: string): SceneFile {
408
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`);
409
419
  ok = false;
410
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
+ }
411
425
  const acc = c.accept;
412
426
  if ('accept' in c) {
413
427
  if (!(Array.isArray(acc) && acc.every((v) => typeof v === 'string'))) {
@@ -427,6 +441,7 @@ export function loadScene(path: string): SceneFile {
427
441
  scale: 'scale' in c ? (sc as number) : 1,
428
442
  accept: 'accept' in c ? [...(acc as string[])] : [],
429
443
  ...(c.canvas_clip === true ? { canvas_clip: true } : {}),
444
+ ...(c.placement_pivot === true ? { placement_pivot: true } : {}),
430
445
  });
431
446
  });
432
447
  }
@@ -1080,6 +1095,8 @@ export interface SceneCharacterReport {
1080
1095
  canvas_clip?: true;
1081
1096
  /** Intersection of the placed bounds and the canvas, in the same coordinates as bounds. */
1082
1097
  clipped_bounds?: [number, number, number, number];
1098
+ /** Final bone name of the opted-in scene translation target. */
1099
+ placement_pivot?: string;
1083
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). */
1084
1101
  shift: [number, number];
1085
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`. */
@@ -1152,6 +1169,24 @@ export function composeScene(
1152
1169
  const ready = builds.filter((b): b is CharacterBuild => b !== null);
1153
1170
  const byId = new Map(ready.map((b) => [b.id, b]));
1154
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
+ });
1155
1190
 
1156
1191
  // ---- the plate ----------------------------------------------------------
1157
1192
  if (scene.plate !== null && plate !== null && (plate.width !== canvas.width || plate.height !== canvas.height)) {
@@ -1160,7 +1195,7 @@ export function composeScene(
1160
1195
 
1161
1196
  const layers = scene.plates ?? [];
1162
1197
  const layerNames = new Set(layers.map(p => p.name));
1163
- 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 => [
1164
1199
  ...b.rig.bones.map(x => prefixed(b.id, x.name)),
1165
1200
  ...b.rig.slots.map(x => prefixed(b.id, x.name)),
1166
1201
  ...Object.keys(b.motion.animations).map(n => prefixed(b.id, n)),
@@ -1240,6 +1275,7 @@ export function composeScene(
1240
1275
  }
1241
1276
  problems.push(...scaleProblems(c, b));
1242
1277
  const shift = rootShift(b.rig.skeleton, stage, c.offset, s);
1278
+ const pivot = pivots.get(c.id);
1243
1279
  rows.push({
1244
1280
  id: c.id,
1245
1281
  build: c.build,
@@ -1249,13 +1285,14 @@ export function composeScene(
1249
1285
  rig_scale: b.rigScale,
1250
1286
  bounds,
1251
1287
  ...(clippedBounds === undefined ? {} : { canvas_clip: true, clipped_bounds: clippedBounds }),
1288
+ ...(pivot === undefined ? {} : { placement_pivot: pivot.name }),
1252
1289
  shift,
1253
1290
  shifted: {
1254
1291
  bones: b.rig.bones.filter((x) => x.parent === ROOT_BONE).map((x) => prefixed(c.id, x.name)),
1255
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)),
1256
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),
1257
1294
  },
1258
- bones: b.rig.bones.length - 1,
1295
+ bones: b.rig.bones.length - 1 + (pivot === undefined ? 0 : 1) + (pivot?.rootBinding === undefined ? 0 : 1),
1259
1296
  slots: b.rig.slots.length,
1260
1297
  tracks: b.motion.animations.idle.tracks.length,
1261
1298
  constraints: b.rig.constraints?.length ?? 0,
@@ -1298,6 +1335,7 @@ export function composeScene(
1298
1335
  const own = slotsOf.get(id);
1299
1336
  if (own === undefined) return;
1300
1337
  if (!own.includes(slot)) {
1338
+ if (layerNames.has(e) && generatedBones.has(e)) return; // The plate collision already names this entry.
1301
1339
  fail('SCENE_ORDER_RESOLVES', at, `is "${e}"; character "${id}" has no slot "${slot}" — its slots are ${own.map((s) => `"${s}"`).join(', ')}`);
1302
1340
  return;
1303
1341
  }
@@ -1351,6 +1389,33 @@ export function composeScene(
1351
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`);
1352
1390
  } else fail('SCENE_NAME_RESOLVES', where, `names the physics constraint "${name}", which no character of the scene declares`);
1353
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
+ }
1354
1419
  for (const b of ready) {
1355
1420
  (b.rig.constraints ?? []).forEach((con, k) => {
1356
1421
  const type = con.type as keyof typeof CONSTRAINT_BONE_FIELDS;
@@ -1497,6 +1562,12 @@ export function composeScene(
1497
1562
  const id = c.id;
1498
1563
  const s = c.scale;
1499
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
+ }
1500
1571
  // At a scale other than 1 every length the character carries is scaled (issue #197): each bone's x, y and length,
1501
1572
  // each region's x, y (and its drawn size, by scaleX/scaleY), each weight's bind x, y, the constraints' lengths
1502
1573
  // (scaledConstraint), each stop's at offset in against's local frame (scaledStop; issue #431) and the translate keys
@@ -1505,9 +1576,13 @@ export function composeScene(
1505
1576
  if (bone.name === ROOT_BONE) continue;
1506
1577
  const first = bone.parent === ROOT_BONE;
1507
1578
  const sized = s === 1 ? {} : { x: scaledBy(bone.x, s), y: scaledBy(bone.y, s), ...(bone.length === undefined ? {} : { length: scaledBy(bone.length, s) }) };
1508
- 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) });
1509
1585
  }
1510
- 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) });
1511
1586
  // Everything the character places in root's own frame moves with it: a region on a slot root carries, and a
1512
1587
  // weight bound to root. Every other offset is local to a bone the shift already moved.
1513
1588
  const slotBone = new Map(b.rig.slots.map((s) => [s.name, s.bone]));
@@ -1527,7 +1602,7 @@ export function composeScene(
1527
1602
  a.weights = (att.weights as Array<Array<Record<string, unknown>>>).map((v) =>
1528
1603
  v.map((w) =>
1529
1604
  w.bone === ROOT_BONE
1530
- ? { ...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) }
1531
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) }) },
1532
1607
  ),
1533
1608
  );
@@ -1646,7 +1721,7 @@ export function composeScene(
1646
1721
  const note = notes.size === 1 ? [...notes][0] : ready.map((b) => `${b.id}: ${b.motion.animations.idle.note}`).join(' | ');
1647
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 } };
1648
1723
 
1649
- if (scene.animations !== undefined) mergeSceneAnimations(rig, motion, scene.animations);
1724
+ if (scene.animations !== undefined || pivots.size > 0) mergeSceneAnimations(rig, motion, scene.animations ?? {}, [...pivots.values()]);
1650
1725
 
1651
1726
  const report: SceneReport = {
1652
1727
  spec: SCENE_REPORT_SPEC,
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;