rig-play 1.0.0 → 1.2.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 +187 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +318 -9
- package/dist/index.js.map +1 -1
- package/dist/player.d.ts +103 -0
- package/dist/player.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/player.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface RigPlayerOptions {
|
|
|
25
25
|
* or constraints applied, every slot resolved through the default skin.
|
|
26
26
|
*/
|
|
27
27
|
skin?: string;
|
|
28
|
+
/** The per-pose adjustment of bone locals (`player.adjust`), set from the first pose. */
|
|
29
|
+
adjust?: BoneAdjust | null;
|
|
28
30
|
/** How the player draws (see `RenderMode`). Default `'dom'`. Can be changed later through `mode`. */
|
|
29
31
|
mode?: RenderMode;
|
|
30
32
|
/** The mesh tier's rasterizer (see `DomRenderer.meshBackend`) — the DOM mode only. */
|
|
@@ -55,6 +57,66 @@ type Listener<T> = (payload: T) => void;
|
|
|
55
57
|
* requestAnimationFrame(function tick(now) { player.frame(dt); requestAnimationFrame(tick); });
|
|
56
58
|
* ```
|
|
57
59
|
*/
|
|
60
|
+
/**
|
|
61
|
+
* One bone's local values at a pose, read and written in place: the seven
|
|
62
|
+
* channels the runtime's bone has, in its units (degrees, world-unit
|
|
63
|
+
* translation, scale factors, shear in degrees). What `BoneAdjust` receives
|
|
64
|
+
* through `AdjustableBones.bone`.
|
|
65
|
+
*/
|
|
66
|
+
export interface BoneLocals {
|
|
67
|
+
rotation: number;
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
scaleX: number;
|
|
71
|
+
scaleY: number;
|
|
72
|
+
shearX: number;
|
|
73
|
+
shearY: number;
|
|
74
|
+
}
|
|
75
|
+
/** The bones of one pose, by name, as a `BoneAdjust` sees them. */
|
|
76
|
+
export interface AdjustableBones {
|
|
77
|
+
/** The document's bones, in its order. */
|
|
78
|
+
readonly names: readonly string[];
|
|
79
|
+
/** One bone's locals, read and written in place; a name the document has no bone for is refused by name. */
|
|
80
|
+
bone(name: string): BoneLocals;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A caller's adjustment of a pose's bone locals — a breath's scale, a look's
|
|
84
|
+
* rotation, a mouth's `scaleY` — called once per pose after the animation's
|
|
85
|
+
* timelines and before the world transforms, constraints and physics (the
|
|
86
|
+
* core's `openTrack({ adjust })`, held to the Spine runtime at tolerance 0
|
|
87
|
+
* by rig-c). **A write lasts one pose**: the core poses every step from the
|
|
88
|
+
* setup pose, so a value the caller wants held is written again each pose,
|
|
89
|
+
* and nothing compounds. A non-finite value, an unknown bone, or an error the
|
|
90
|
+
* function throws refuses that step in the core's words.
|
|
91
|
+
*/
|
|
92
|
+
export type BoneAdjust = (bones: AdjustableBones) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Where a bone is in the pose the player holds — world units, Y up, the
|
|
95
|
+
* numbers `rig-c/core` posed (`RawBone`): the world matrix `a b c d`, the
|
|
96
|
+
* world position, the world rotation of each axis in degrees and the world
|
|
97
|
+
* scale of each, and whether the bone is active under the player's skin.
|
|
98
|
+
*/
|
|
99
|
+
export interface BoneWorld {
|
|
100
|
+
name: string;
|
|
101
|
+
active: boolean;
|
|
102
|
+
x: number;
|
|
103
|
+
y: number;
|
|
104
|
+
a: number;
|
|
105
|
+
b: number;
|
|
106
|
+
c: number;
|
|
107
|
+
d: number;
|
|
108
|
+
rotationX: number;
|
|
109
|
+
rotationY: number;
|
|
110
|
+
scaleX: number;
|
|
111
|
+
scaleY: number;
|
|
112
|
+
}
|
|
113
|
+
/** A box in world units, Y up: `y` is the bottom edge. */
|
|
114
|
+
export interface PoseBounds {
|
|
115
|
+
x: number;
|
|
116
|
+
y: number;
|
|
117
|
+
width: number;
|
|
118
|
+
height: number;
|
|
119
|
+
}
|
|
58
120
|
export declare class RigPlayer {
|
|
59
121
|
/**
|
|
60
122
|
* The renderer this player draws through — its knobs and counters are the
|
|
@@ -78,6 +140,10 @@ export declare class RigPlayer {
|
|
|
78
140
|
private loop;
|
|
79
141
|
private paused;
|
|
80
142
|
private pose;
|
|
143
|
+
private setup;
|
|
144
|
+
private adjustFn;
|
|
145
|
+
/** Handed to every track the player opens; reads the current `adjust` so setting it later needs no reopen. */
|
|
146
|
+
private readonly adjustHook;
|
|
81
147
|
private readonly listeners;
|
|
82
148
|
constructor(root: HTMLElement, assets: ModelAssets, options?: RigPlayerOptions);
|
|
83
149
|
/**
|
|
@@ -130,6 +196,43 @@ export declare class RigPlayer {
|
|
|
130
196
|
advance(dt: number): void;
|
|
131
197
|
/** Draws the pose the player holds. */
|
|
132
198
|
draw(): void;
|
|
199
|
+
/**
|
|
200
|
+
* The per-pose adjustment of bone locals (`BoneAdjust`), or null for none.
|
|
201
|
+
* It is applied by every track the player opens — `play`, the reopen inside
|
|
202
|
+
* `seek` — and by the pose drawn again after `mode` changes, on every pose
|
|
203
|
+
* the animation is applied to, the first one included. Setting it re-poses
|
|
204
|
+
* the pose the player holds at once (`repose`), so a held or paused player
|
|
205
|
+
* shows the change on its next `draw` without a step.
|
|
206
|
+
*/
|
|
207
|
+
get adjust(): BoneAdjust | null;
|
|
208
|
+
set adjust(fn: BoneAdjust | null);
|
|
209
|
+
/**
|
|
210
|
+
* Poses the held pose again at the same track time, through the current
|
|
211
|
+
* `adjust`, without stepping, firing or drawing. A paused player and a zero
|
|
212
|
+
* step re-pose nothing, so a caller whose adjustment reads its own state
|
|
213
|
+
* (a mouth driven while the body is held) calls this when that state
|
|
214
|
+
* changed, then `draw`. Nothing before `play`.
|
|
215
|
+
*/
|
|
216
|
+
repose(): void;
|
|
217
|
+
/**
|
|
218
|
+
* Where `name` is in the pose the player holds — the pose of the last
|
|
219
|
+
* `advance`/`frame`/`seek`, or the setup pose before `play`. Read off the
|
|
220
|
+
* core's pose, so it is the same in `dom` and `canvas` mode and costs nothing
|
|
221
|
+
* until called. An unknown bone is refused by name.
|
|
222
|
+
*/
|
|
223
|
+
bone(name: string): BoneWorld;
|
|
224
|
+
/**
|
|
225
|
+
* The box of what the pose the player holds draws, in world units, Y up:
|
|
226
|
+
* every region's four corners and every mesh's vertices, in the same frame
|
|
227
|
+
* record the renderer takes (`posedFrame`). A slot under a clip counts only
|
|
228
|
+
* inside the clip polygon's own box (an inverse clip removes nothing from
|
|
229
|
+
* the count); bounding boxes, paths and points are not drawn and do not
|
|
230
|
+
* count. `null` when nothing draws. The same numbers in `dom` and `canvas`
|
|
231
|
+
* mode; nothing is computed until called.
|
|
232
|
+
*/
|
|
233
|
+
bounds(): PoseBounds | null;
|
|
234
|
+
/** The pose the reads above see: the track's, or the setup pose before `play` (posed once). */
|
|
235
|
+
private posed;
|
|
133
236
|
/** The pose the player holds, as the frame record the renderer draws. */
|
|
134
237
|
posedFrame(): PosedFrame;
|
|
135
238
|
/** Removes the renderer's elements and hands its GPU pages back. The assets stay the caller's. */
|
package/dist/player.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../src/player.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAA0C,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1F;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE1C,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qGAAqG;IACrG,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,sFAAsF;IACtF,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1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K,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKvB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAUzB,uCAAuC;IACvC,IAAI,IAAI,IAAI;IAKZ;;;;;;;OAOG;IACH,IAAI,MAAM,IAAI,UAAU,GAAG,IAAI,CAE9B;IAED,IAAI,MAAM,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,EAI/B;IAED;;;;;;OAMG;IACH,MAAM,IAAI,IAAI;IAKd;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAsB7B;;;;;;;;OAQG;IACH,MAAM,IAAI,UAAU,GAAG,IAAI;IA6B3B,+FAA+F;IAC/F,OAAO,CAAC,KAAK;IAMb,yEAAyE;IACzE,UAAU,IAAI,UAAU;IAKxB,kGAAkG;IAClG,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,IAAI;IAKZ;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ;CAkBjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rig-play",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Plays skeleton.model.json written by rigc build as plain DOM elements — rigid slots as <img> posed by CSS matrix, deform meshes on small per-part canvases — or as one canvas.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@playwright/test": "1.62.1",
|
|
59
59
|
"@types/node": "^22",
|
|
60
|
-
"rig-c": "2.
|
|
60
|
+
"rig-c": "2.36.0",
|
|
61
61
|
"typescript": "^5.6.0",
|
|
62
62
|
"vite": "^6.0.0"
|
|
63
63
|
}
|