spine-html 1.26.0 → 1.27.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.
@@ -0,0 +1,201 @@
1
+ # Migrating to @rig-c/play
2
+
3
+ This guide covers adding live-frame consumers and the earlier migration notes
4
+ moved from the README (#182): the 1.8 → 1.9 mesh backend default, and the
5
+ `spine-html` 0.8 → 1.0 guide.
6
+
7
+ ## Importing a composed take
8
+
9
+ Replace the `./samples/composed-take.js` import of `mountComposedTake` with `@rig-c/play/composed-take` and pass named `planes` as shown in the [composed take reference](REFERENCE.md#mounting-a-composed-take).
10
+
11
+ ## Adding live-frame consumers
12
+
13
+ `posedFrame()` keeps its detached snapshot contract. Existing callers may retain
14
+ it across `advance()` calls. There is no migration that turns that snapshot into
15
+ a volatile view.
16
+
17
+ For a consumer that draws immediately, borrow the runtime buffers instead:
18
+
19
+ ```ts
20
+ player.advance(dt);
21
+ renderer.render(player.liveFrame());
22
+ ```
23
+
24
+ The built-in DOM and canvas renderers accept this view as well as `PosedFrame`.
25
+ Custom renderers read attachment indices from `drawOrder[0..count)`, then use
26
+ that attachment's vertex offset/count and static UV/index/page metadata. Tint
27
+ is indexed by setup slot, `slotIndex * 4`. Do not save the live frame, its nested
28
+ buffers or attachment views for a later pose. Development stale-view checks
29
+ refuse those reads; production reuses the same buffers without per-borrow
30
+ leases. Call `posedFrame()` when retaining data is required.
31
+
32
+ Selection is automatic for covered models and animations; inspect `player.poser`
33
+ for the named oracle fallback. Unsupported tracks, sets and adjustments preserve
34
+ the old semantics on that path. Covered events reach the existing listener API, including when a listener
35
+ re-enters the player. Supported skin switches preserve wrapped animation time.
36
+ No event waiver or silent feature drop is used.
37
+ The oracle live view may allocate; development diagnostic leases also allocate.
38
+ Neither is evidence for the production runtime's allocation bar. The raw view's
39
+ oracle `placeholder` is `null`, not a display-name guess.
40
+
41
+ ## Coming from 1.8: meshes draw through WebGL by default
42
+
43
+ From 1.9 the element mode rasterizes its meshes through the one shared WebGL
44
+ context unless told otherwise (`DomRenderer.meshBackend` defaults to `'webgl'`,
45
+ #109). The picture is the same within the parity suite's bounds, the API is
46
+ unchanged, and canvas2d is still drawn wherever WebGL is unavailable or the
47
+ context is lost. What a caller can notice:
48
+
49
+ - The page holds one more WebGL context (one for every mesh of every player, not
50
+ one per player). A page already near the browser's cap of about 16 live
51
+ contexts can lose its oldest one when this one is created.
52
+ - `meshBackendActive` reads `'webgl'` where it read `'canvas2d'`.
53
+ - Frame cost moves from the page to the GPU blit (see *Measured*).
54
+
55
+ To keep 1.8's raster, set it back, up front or on a live player:
56
+
57
+ ```ts
58
+ const player = new RigPlayer(root, assets, { meshBackend: 'canvas2d' });
59
+ // or, on a renderer you hold:
60
+ renderer.meshBackend = 'canvas2d';
61
+ ```
62
+
63
+ The canvas mode was already webgl by default and does not change.
64
+
65
+ ## Coming from spine-html 0.8
66
+
67
+ This is not a drop-in upgrade. 0.8 drew a Spine export (`.json` or `.skel`, plus its
68
+ `.atlas`) that `@esotericsoftware/spine-core` parsed and posed: the caller built the
69
+ `Skeleton` and the `AnimationState`, advanced them each frame, and handed the skeleton to
70
+ `renderer.render(skeleton)`. 1.0 loads one file, the `skeleton.model.json` that
71
+ `rigc build` writes, poses it through `@rig-c/core/core` (bundled into the package, with no peer
72
+ dependency), and `RigPlayer` owns the track, so the caller's frame is `player.frame(dt)`.
73
+ A Spine export is refused by name before anything is fetched: the data has to be a rigc
74
+ build, and this package declares no loader for anything else.
75
+
76
+ What did not move: a positioned root element is still the rig's origin (Y up) with its
77
+ layout and scaling left to the caller, the DOM tier keeps its knobs under a new class
78
+ name, and unloading is still elements first, bitmaps second.
79
+
80
+ ### 0.8 → 1.0
81
+
82
+ | 0.8.0 (`spine-html`) | 1.x (`@rig-c/play`, formerly `rig-play`) | Note |
83
+ | --- | --- | --- |
84
+ | `npm i spine-html @esotericsoftware/spine-core` | `npm i @rig-c/play`, and `npm i -D @rig-c/core` for the build tool | 0.8 declared spine-core as a peer dependency (`>=4.0.0 <4.4.0`). 1.0.0 declares no dependencies and no peer dependencies. |
85
+ | `loadSkeletonAssets(options)` | `loadModel(options)` | One URL instead of two. The `.atlas` and `skeleton.json` a build writes beside the document are not fetched. |
86
+ | `LoadSkeletonAssetsOptions.atlasUrl`, `skeletonUrl` | `LoadModelOptions.modelUrl` | |
87
+ | `resolvePage(pageName, atlasUrl)` | `resolvePage(pageName, modelUrl)` | The default now resolves a page name against the model URL's directory. |
88
+ | `crossOrigin`, `fetch` | `crossOrigin`, `fetch` | Unchanged. |
89
+ | `scale` (`LoadSkeletonAssetsOptions`, `LoadSkeletonJsonOptions`) | none | See below. |
90
+ | `SkeletonAssets` | `ModelAssets` | |
91
+ | `SkeletonAssets.data` | `ModelAssets.document`, `animations`, `skins`, `stage`, `spec` | `document` is opaque (`ModelDocument`); the player poses it. What a caller used to read off the skeleton data is stated as `animations` (name and duration), `skins` (names) and `stage` (the stage the build declared, or null). |
92
+ | `SkeletonAssets.atlas` | `ModelAssets.pageImages` | The page images, keyed by page name. There is no atlas object; where each region sits is in the document's `pages` section. |
93
+ | `SkeletonAssets.regionImages` | `ModelAssets.regionImages` | Same `Map<string, RegionImage>`. |
94
+ | `SkeletonAssets.dispose()`, `AtlasAssets.dispose()` | `ModelAssets.dispose()` | Same contract: frees the blob URLs the load minted, idempotent, called after the players are disposed. |
95
+ | `loadAtlasAssets` + `loadSkeletonJson` (one atlas, several skeletons) | none | One `loadModel` backs any number of `RigPlayer`s of the same rig. Two rigs are two loads, and each cuts its own regions. See below. |
96
+ | `loadSkeletonBinary` from `spine-html/binary` | none | 1.0.0 has one entry point. A `.skel` URL is refused by name. |
97
+ | `unpackRegions(atlas, pageImages)` | `unpackRegions(pages, pageImages)` | The first argument is the document's `pages` section (`readonly PageLayout[]`) instead of a `TextureAtlas`. |
98
+ | `revokeRegions(images)` | `revokeRegions(images)` | Unchanged. |
99
+ | `RegionImage` | `RegionImage` | Unchanged (`url`, `width`, `height`, in atlas units). |
100
+ | `DomTexture` | none | Not exported; there is no atlas page to attach a texture to. |
101
+ | `new Skeleton(assets.data)` and `new AnimationState(new AnimationStateData(assets.data))` | `new RigPlayer(root, assets, options?)` | The player holds the pose and the track. |
102
+ | `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. |
103
+ | `skeleton.findSlot('x').attachment = null` to hide a slot, or a second skeleton with slots emptied | `RigPlayerOptions.slots`, `player.slots`, `player.posedFrame(slots)` | A draw filter since 1.6.0 — the pose is the whole rig's; a clipping slot left out does not clip. See *Drawing some slots only*. |
104
+ | `state.setAnimation(1, 'smile', false)` with a mix, `addAnimation`, `setEmptyAnimation`, `addEmptyAnimation`, `getCurrent(track)`, `entry.alpha`, `entry.additive` | `player.play(name, { track, loop, mix, alpha, additive })`, `player.queue(name, { track, loop, mix, delay, alpha, additive })`, `player.clear(track, { mix })`, `player.queueClear(track, { mix, delay })`, `player.setAlpha(track, alpha)`, `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*. |
105
+ | `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. |
106
+ | 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. |
107
+ | holding a pose (the caller stopped advancing) | `player.pause()`, `player.resume()` | `frame` keeps drawing the held pose. |
108
+ | 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. |
109
+ | 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. |
110
+ | 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. |
111
+ | `SpineHtmlRenderer` | `DomRenderer`, reached as `player.renderer` | In `mode: 'dom'`, the default. `mode: 'canvas'` is new and makes `player.renderer` a `CanvasRenderer`. |
112
+ | `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. |
113
+ | `renderer.render(skeleton)` | `renderer.render(frame)` | Takes a `PosedFrame`, not a skeleton. `player.posedFrame()` returns the one the player would draw. |
114
+ | `renderer.pixelRatio` | `player.renderer.pixelRatio` | On both renderers. Carried over when `player.mode` changes. |
115
+ | `renderer.syncPixelRatio()` | `player.renderer.syncPixelRatio()` | On both renderers, the same meaning and the same deadband (since 1.3.0; before it, DOM mode only). |
116
+ | `renderer.meshBackingPixels` | `DomRenderer.meshBackingPixels` | DOM mode only. |
117
+ | `renderer.meshBackend`, `meshBackendActive`, type `MeshBackend` | `DomRenderer.meshBackend`, `meshBackendActive`, type `MeshBackend` | Same values; the default is `'webgl'` since 1.9 (`'canvas2d'` before). Also settable up front as `RigPlayerOptions.meshBackend`. |
118
+ | `renderer.triangleExpand` | `DomRenderer.triangleExpand` | Same default (0.5). |
119
+ | `renderer.clipping` | `player.renderer.clipping` | On both renderers. Carried over when `player.mode` changes. |
120
+ | `clipCount`, `clipSkipCount`, `clipWriteCount` | same names on `DomRenderer` | `clipSkipCount` counts less than it did: a second clip met while one is in force, and a clip on an inactive bone, no longer reach the frame, so they are not counted. |
121
+ | `meshCount`, `meshReuseCount`, `canvasReallocCount`, `triangleCount` | same names on `DomRenderer` | |
122
+ | tint: skeleton × slot × attachment colour | `player.color` × slot × attachment | `player.color` is `[r, g, b, a]` and takes the place of the skeleton's colour. The product arrives as `tint` on each `PosedSlot`. |
123
+ | dark (two-colour) tint: unsupported | `DomRenderer`: unsupported. `CanvasRenderer`: drawn | Carried as `dark` on a `PosedSlot`. The canvas mode's canvas2d fallback draws alpha only. |
124
+ | `renderer.dispose()` | `player.dispose()` | Then `assets.dispose()`, as before. `DomRenderer.dispose()` and `CanvasRenderer.dispose()` exist for a renderer you constructed yourself. |
125
+ | `skeleton.findBone('head').worldX`, `.worldY`, `.a` … `.d` | `player.bone('head')` | `{ x, y, a, b, c, d, rotationX, rotationY, scaleX, scaleY, active }`, the core's world transform for the pose the player holds (the setup pose before `play`). An unknown name is refused by name. Since 1.1.0. |
126
+ | `bone.scaleY = …` on a `Skeleton` between `state.apply` and `updateWorldTransform` | `RigPlayerOptions.adjust`, `player.adjust`, `player.repose()` | A function `(bones, ctx)` called once per pose with the pose's bone locals and current-entry context (unary callbacks remain valid) (`bones.bone('mouth').scaleY = v`). A write lasts one pose: the core poses every step from the setup pose, so write the value you want, every pose — nothing compounds. See *Adjusting bones*. Since 1.2.0. |
127
+ | `skeleton.getBounds(offset, size)` | `player.bounds()` | `{ x, y, width, height }` or null, world units, Y up: the box of every drawn region's corners and mesh's vertices, a slot under a clip counted inside the clip's own box. `ModelAssets.stage` remains the declared framing, not this box. Since 1.1.0. |
128
+ | live named physics constraint tuning | `player.setPhysicsParameters(name, patch)`, `readPhysicsParameters(name)`, `clearPhysicsParameters(name)` | Six scalar fields, per-player pending patch plus last evaluated effective values. Clear resumes authored values without resetting history. Replay uses the current standing patch, with no historical journal. See *Live physics parameters*. |
129
+ | named setup mesh geometry | `readSetupMesh(assets, { slot, attachment, skin? })` | Detached full-double world x/y (Y up), triangles and hull for any named mesh/linked mesh, including non-setup selections; no player/time mutation. Selected geometry includes setup-slider deform; unselected geometry is stored geometry through unchanged setup matrices. See the measured official-runtime distinction under *Reading the pose*. |
130
+
131
+ ### No counterpart in 1.0.0
132
+
133
+ Things a 0.8 caller could do because it held the spine-core objects, or through a 0.8
134
+ export, for which 1.0.0 declares nothing:
135
+
136
+ - **A Spine export as input.** `loadSkeletonJson`, `loadSkeletonBinary`, `loadAtlasAssets`,
137
+ the `spine-html/binary` entry and `DomTexture` have no counterpart, and neither does
138
+ choosing which spine-core generation reads the data. `loadModel` reads a compiled model
139
+ document and nothing else.
140
+ - **Scaling the skeleton as it is read.** `LoadModelOptions` declares no `scale`. Scaling
141
+ the root element is still the caller's.
142
+ - **One unpacked atlas shared by different skeletons.** A document is one rig, and each
143
+ `loadModel` cuts its own regions and owns its own blob URLs. Sharing is per rig: one
144
+ load, several players.
145
+ - **Changing one slot from code** (its attachment, its colour). `RigPlayer` declares only
146
+ the whole-rig `color`. The frame record is a plain object, so a caller that draws its
147
+ own frames through `DomRenderer.render` or `CanvasRenderer.render` decides what is in
148
+ it.
149
+ - **Choosing how physics is stepped each frame.** 0.8's loop passed `Physics.update`
150
+ itself; 1.0.0 declares no physics option. `play` and `seek` reset physics at the
151
+ animation's first pose and every step advances it.
152
+ - **Track callbacks other than the two declared.** `on` accepts `'event'` and
153
+ `'complete'`.
154
+
155
+ Knobs on `DomRenderer` that `CanvasRenderer` does not declare:
156
+
157
+ - `meshBackend` and `meshBackendActive`. The canvas mode has its own pair, `backend` and
158
+ `backendActive` (type `CanvasBackend`, `'webgl'` by default).
159
+ - `triangleExpand`, `meshBackingPixels`, `clipWriteCount`, `meshCount`, `meshReuseCount`,
160
+ `triangleCount`. The canvas mode's counters are `drawCalls`, `blendFlushes`,
161
+ `trianglesDrawn`, `framesReused` and `blits`.
162
+
163
+ Both declare `pixelRatio`, `clipping`, `clipCount`, `clipSkipCount`, `canvasReallocCount`,
164
+ `render` and `dispose`. Only `pixelRatio` and `clipping` carry over when `player.mode`
165
+ changes.
166
+
167
+ ### Before and after
168
+
169
+ 0.8.0:
170
+
171
+ ```ts
172
+ import { Skeleton, AnimationState, AnimationStateData, Physics } from '@esotericsoftware/spine-core';
173
+ import { loadSkeletonAssets, SpineHtmlRenderer } from 'spine-html';
174
+ const assets = await loadSkeletonAssets({ atlasUrl: '/hero/hero.atlas', skeletonUrl: '/hero/hero.json' });
175
+ const skeleton = new Skeleton(assets.data);
176
+ const state = new AnimationState(new AnimationStateData(assets.data));
177
+ state.setAnimation(0, 'walk', true);
178
+ const renderer = new SpineHtmlRenderer(rootElement, assets.regionImages);
179
+ function frame(delta: number) {
180
+ state.update(delta);
181
+ state.apply(skeleton);
182
+ skeleton.update(delta);
183
+ skeleton.updateWorldTransform(Physics.update);
184
+ renderer.render(skeleton);
185
+ }
186
+ renderer.dispose(); assets.dispose(); // on unload
187
+ ```
188
+
189
+ 1.0.0:
190
+
191
+ ```ts
192
+ import { loadModel, RigPlayer } from '@rig-c/play';
193
+ const assets = await loadModel({ modelUrl: '/rigs/walk/skeleton.model.json' });
194
+ const player = new RigPlayer(rootElement, assets);
195
+ player.play('walk', { loop: true });
196
+ function frame(delta: number) {
197
+ player.frame(delta);
198
+ }
199
+ player.dispose(); assets.dispose(); // on unload
200
+ ```
201
+