rig-play 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -263,6 +263,38 @@ box, an inverse clip removes nothing, and bounding boxes, paths and points do
263
263
  not draw and do not count. Both cost nothing until called and read the same
264
264
  numbers in `dom` and `canvas` mode.
265
265
 
266
+ ### Several tracks
267
+
268
+ A base on track 0, a layer over it, a one-shot played once and mixed back out —
269
+ rig-c's live tracks (`openTracks`), whose mixing is the Spine runtime's
270
+ `AnimationState` held at tolerance 0:
271
+
272
+ ```ts
273
+ player.play('idle'); // track 0, as always
274
+ player.play('smile', { track: 1, loop: false, mix: 0.2 }); // held at its end, mixed in over 0.2 s
275
+ player.play('wave', { track: 2, loop: false, mix: 0.1 }); // a one-shot…
276
+ player.queueClear(2, { mix: 0.1 }); // …mixed back out over its last 0.1 s
277
+ player.queue('idle_b', { track: 0, mix: 0.3 }); // after the current idle cycle completes
278
+ player.clear(1, { mix: 0.2 }); // the layer gone, the base showing through
279
+ player.entry(2); // { animation, loop, trackTime, animationTime, duration } | null
280
+ ```
281
+
282
+ `play(name)` keeps meaning what it meant: a plain play on track 0 runs on rig-c's
283
+ single live track, which poses everything the core poses. The first call that
284
+ composes — a `mix`, a `track` above 0, a `queue`, a `clear` — moves the player onto
285
+ the tracks, carrying the single track over by replay (its animation set, pose 0
286
+ taken, stepped to its time); from then on `seek` and `skin` are refused by name,
287
+ since the player cannot replay a composition to a time — step it forward instead.
288
+ Every entry mixes from the setup pose each step, so `adjust` writes still last one
289
+ pose. **What the tracks do not mix**, in rig-c's words at `play`/`queue`: an
290
+ animation keying a constraint (ik, transform, path, physics, slider), a sequence,
291
+ the draw order, or a path's deform is refused when it is set on the tracks — it
292
+ plays on the single track only. `'event'` carries `track`; a one-shot that is
293
+ mixing out fires nothing. `'complete'` is per track, the player's rule: a looping
294
+ entry each cycle, a held one when it reaches its duration, and an entry that is
295
+ replaced — by `play`, or by the queued entry that starts at its completion less the
296
+ mix — completes no more than it fires.
297
+
266
298
  ### Adjusting bones
267
299
 
268
300
  A per-pose write to bone locals — a breath's scale, a look's rotation, a mouth
@@ -338,6 +370,23 @@ calling it twice is a no-op. Load once for the page's lifetime and you can
338
370
  ignore it; load and unload repeatedly without it and you leak an atlas per
339
371
  cycle.
340
372
 
373
+ ### Loading for the canvas mode only, and `data:` regions
374
+
375
+ The region cut makes the rigid tier's bitmaps, which only the DOM mode draws.
376
+ `loadModel({ regions })` says what to do about it:
377
+
378
+ - `'blob'` (default) — `blob:` URLs the load owns; `assets.dispose()` frees them.
379
+ - `'data'` — `data:` URLs instead, for a content policy or a snapshot that does
380
+ not carry `blob:`. The same PNG bytes, inline; nothing is minted, so there is
381
+ nothing to free, and the base64 lives as long as the map does.
382
+ - `'none'` — no cut: the pages load, `assets.regionImages` is empty, and the
383
+ load is for the canvas mode. A DOM-mode player opened on it — `new RigPlayer`
384
+ without `mode: 'canvas'`, or `player.mode = 'dom'` — is refused by name, and
385
+ a refused mode change leaves the player as it was.
386
+
387
+ `assets.regions` records the choice. `unpackRegions` takes the same thing as
388
+ `{ encoding: 'blob' | 'data' }`.
389
+
341
390
  ### Pages that ship at another resolution
342
391
 
343
392
  A page image may ship at a resolution its document does not declare — a
@@ -389,7 +438,8 @@ the page's own URL holds premultiplied pixels (see below).
389
438
  ### What unloading frees
390
439
 
391
440
  `revokeRegions()` — and `assets.dispose()`, which calls it — frees the blob URLs
392
- `unpackRegions` minted, and nothing else. The page images are held by
441
+ `unpackRegions` minted, and nothing else (a `regions: 'data'` or `'none'` load
442
+ minted none, so it frees nothing). The page images are held by
393
443
  `assets.pageImages` and by every player drawing from them, so a page is
394
444
  released once you drop the assets and every player is disposed. With the
395
445
  `webgl` mesh backend the shared blitter also uploads each page image on first
@@ -578,12 +628,13 @@ name, and unloading is still elements first, bitmaps second.
578
628
  | `DomTexture` | none | Not exported; there is no atlas page to attach a texture to. |
579
629
  | `new Skeleton(assets.data)` and `new AnimationState(new AnimationStateData(assets.data))` | `new RigPlayer(root, assets, options?)` | The player holds the pose and the track. |
580
630
  | `state.setAnimation(0, 'walk', true)` | `player.play('walk', { loop: true })` | `loop` defaults to true. `play` opens the animation at its first pose with the physics reset there. `player.current` names what is playing. |
631
+ | `state.setAnimation(1, 'smile', false)` with a mix, `addAnimation`, `setEmptyAnimation`, `addEmptyAnimation`, `getCurrent(track)` | `player.play(name, { track, loop, mix })`, `player.queue(name, { track, loop, mix, delay })`, `player.clear(track, { mix })`, `player.queueClear(track, { mix, delay })`, `player.entry(track)` | Since 1.5.0, rig-c's live tracks: the runtime's mixing at tolerance 0. Constraint, sequence, draw-order and path-deform timelines are not mixed and are refused on the tracks. See *Several tracks*. |
581
632
  | `state.update(delta)`, `state.apply(skeleton)`, `skeleton.update(delta)`, `skeleton.updateWorldTransform(Physics.update)`, `renderer.render(skeleton)` | `player.frame(dt)` | Or `player.advance(dt)` then `player.draw()`, to time the two apart. |
582
633
  | time scale (the caller's own, on the spine-core side) | `player.timeScale` | Multiplies every step. 0 holds the pose without re-posing it; a negative value is not stepped. |
583
634
  | holding a pose (the caller stopped advancing) | `player.pause()`, `player.resume()` | `frame` keeps drawing the held pose. |
584
635
  | moving to a time (the caller's own, on the spine-core side) | `player.seek(time)`, `RigPlayerOptions.seekStep`, `player.time` | A seek reopens the animation and steps forward in `seekStep` increments (1/60 s by default). Events and completes crossed on the way are not fired. |
585
- | events (the caller's own listener on the spine-core side) | `player.on('event', listener)`, `player.on('complete', listener)` | `'event'` hands a `RigEvent` (`name`, `time`, `int`, `float`, `string`); `'complete'` hands `{ animation }`. `on` returns a function that removes the listener. |
586
- | skin (set by the caller on its `Skeleton`) | `RigPlayerOptions.skin` | A constructor option. The names are in `ModelAssets.skins`. Without it the rig is posed with no skin set. |
636
+ | events (the caller's own listener on the spine-core side) | `player.on('event', listener)`, `player.on('complete', listener)` | `'event'` hands a `RigEvent` (`name`, `time`, `int`, `float`, `string`, `track`); `'complete'` hands `{ animation, track }`. `on` returns a function that removes the listener. |
637
+ | skin (set by the caller on its `Skeleton`) | `RigPlayerOptions.skin`, `player.skin` | A constructor option, and settable on a live player since 1.4.0: the pose re-resolves under the new skin and the track keeps its animation, loop and time (reopened and stepped there, as `seek` does). The names are in `ModelAssets.skins`. Without it the rig is posed with no skin set. |
587
638
  | `SpineHtmlRenderer` | `DomRenderer`, reached as `player.renderer` | In `mode: 'dom'`, the default. `mode: 'canvas'` is new and makes `player.renderer` a `CanvasRenderer`. |
588
639
  | `new SpineHtmlRenderer(root, regionImages)` | `new DomRenderer(root, regionImages, pages?)` | Only for drawing your own frames; `RigPlayer` constructs its renderer. `pages` is the page-image map the mesh tier samples (`ModelAssets.pageImages`). A hand-built `regionImages` map is still accepted. |
589
640
  | `renderer.render(skeleton)` | `renderer.render(frame)` | Takes a `PosedFrame`, not a skeleton. `player.posedFrame()` returns the one the player would draw. |
@@ -616,11 +667,6 @@ export, for which 1.0.0 declares nothing:
616
667
  - **One unpacked atlas shared by different skeletons.** A document is one rig, and each
617
668
  `loadModel` cuts its own regions and owns its own blob URLs. Sharing is per rig: one
618
669
  load, several players.
619
- - **More than one track, mixing between animations, or queueing one after another.**
620
- `RigPlayer` declares one track; `play` reopens it at the animation's first pose.
621
- - **Changing the skin after construction.** `skin` is a `RigPlayerOptions` field and
622
- `RigPlayer` declares no way to change it later; a second player over the same assets
623
- is the declared route.
624
670
  - **Changing one slot from code** (its attachment, its colour). `RigPlayer` declares only
625
671
  the whole-rig `color`. The frame record is a plain object, so a caller that draws its
626
672
  own frames through `DomRenderer.render` or `CanvasRenderer.render` decides what is in
@@ -90,6 +90,16 @@ export declare function straightAlphaDerivations(): number;
90
90
  * happens once it has.
91
91
  */
92
92
  export declare function straightAlphaSource(page: HTMLImageElement, pma: boolean): PageSource;
93
+ /**
94
+ * How a cut region's PNG is handed to the `<img>`: a `blob:` URL this module
95
+ * owns and `revokeRegions` frees (the default), or a `data:` URL that owns
96
+ * nothing and needs no revoke.
97
+ */
98
+ export type RegionEncoding = 'blob' | 'data';
99
+ export interface UnpackRegionsOptions {
100
+ /** `'blob'` by default. */
101
+ encoding?: RegionEncoding;
102
+ }
93
103
  /**
94
104
  * Cuts every region of a page layout — a model document's `pages` section —
95
105
  * out of its page image into its own bitmap once at load time, restoring 90°
@@ -151,7 +161,7 @@ export declare function straightAlphaSource(page: HTMLImageElement, pma: boolean
151
161
  * unpackRegions() with a revokeRegions(); a caller that loads once for the
152
162
  * page lifetime can ignore it.
153
163
  */
154
- export declare function unpackRegions(pages: readonly PageLayout[], pageImages: ReadonlyMap<string, HTMLImageElement>): Promise<Map<string, RegionImage>>;
164
+ export declare function unpackRegions(pages: readonly PageLayout[], pageImages: ReadonlyMap<string, HTMLImageElement>, options?: UnpackRegionsOptions): Promise<Map<string, RegionImage>>;
155
165
  /**
156
166
  * Frees the blob URLs unpackRegions minted for `images` — the counterpart of
157
167
  * unpackRegions, to call once the skeletons using them are gone (after
@@ -1 +1 @@
1
- {"version":3,"file":"DomTexture.d.ts","sourceRoot":"","sources":["../src/DomTexture.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,kFAAkF;IAClF,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;CAChC;AAQD,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;;;OASG;IACH,KAAK,EAAE,MA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C;AAQD,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;;;;;;;OASG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB;AAkBD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AAqC9D;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,OAAO,GAAG,UAAU,CAcpF;AAuSD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACjD,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CA4EnC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,CAEpE"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { type CanvasBackend, CanvasRenderer, type CanvasViewport } from './CanvasRenderer.js';
2
2
  export { DomRenderer, type MeshBackend } from './DomRenderer.js';
3
- export { type PageLayout, type PageRegion, type RegionImage, revokeRegions, unpackRegions } from './DomTexture.js';
4
- export { type LoadModelOptions, loadModel, type ModelAssets, type ModelDocument } from './loadModel.js';
5
- export { type AdjustableBones, type BoneAdjust, type BoneLocals, type BoneWorld, type PoseBounds, type RenderMode, type RigEvent, RigPlayer, type RigPlayerOptions } from './player.js';
3
+ export { type PageLayout, type PageRegion, type RegionEncoding, type RegionImage, revokeRegions, type UnpackRegionsOptions, unpackRegions } from './DomTexture.js';
4
+ export { type LoadModelOptions, loadModel, type ModelAssets, type ModelDocument, type RegionLoading } from './loadModel.js';
5
+ export { type AdjustableBones, type BoneAdjust, type BoneLocals, type BoneWorld, type PlayOptions, type PoseBounds, type QueueOptions, type RenderMode, type RigComplete, type RigEvent, RigPlayer, type RigPlayerOptions, type TrackEntry } from './player.js';
6
6
  export type { BlendMode, PosedClip, PosedFrame, PosedMesh, PosedRegion, PosedSlot, } from './posedFrame.js';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnH,OAAO,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACxG,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxL,YAAY,EACV,SAAS,EACT,SAAS,EACT,U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