@rig-c/play 1.27.0 → 1.28.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,28 @@
1
+ import type { CanvasViewport } from './CanvasRenderer.js';
2
+ export type SceneCameraClock = {
3
+ basis: 'authored' | 'compiled';
4
+ seconds: number;
5
+ endpoint?: 'phase';
6
+ } | {
7
+ endpoint: 'terminal';
8
+ };
9
+ export interface SceneCameraFrame {
10
+ readonly animation: string;
11
+ readonly authoredSeconds: number;
12
+ readonly compiledSeconds: number;
13
+ /** Authored offsets in scene pixels, with Y down. */
14
+ readonly pan: readonly [number, number];
15
+ readonly zoom: number;
16
+ readonly viewWorld: Readonly<CanvasViewport>;
17
+ readonly output: Readonly<{
18
+ width: number;
19
+ height: number;
20
+ }>;
21
+ readonly loop: boolean;
22
+ }
23
+ export interface BoundSceneCamera {
24
+ sample(animation: string, clock: SceneCameraClock): SceneCameraFrame | null;
25
+ }
26
+ export type SceneCameraRefusal = 'SCENE_CAMERA_REPORT_INVALID' | 'SCENE_CAMERA_MODEL_MISMATCH' | 'SCENE_CAMERA_CLIP_MISMATCH' | 'SCENE_CAMERA_CLOCK_INVALID' | 'SCENE_CAMERA_VIEW_INVALID' | 'SCENE_CAMERA_REPORT_TOO_LARGE';
27
+ export declare const SCENE_CAMERA_REPORT_MAX_BYTES: number;
28
+ //# sourceMappingURL=scene-camera.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene-camera.d.ts","sourceRoot":"","sources":["../src/scene-camera.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,MAAM,gBAAgB,GACxB;IAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GACvE;IAAE,QAAQ,EAAE,UAAU,CAAA;CAAE,CAAC;AAE7B,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,qDAAqD;IACrD,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,GAAG,IAAI,CAAC;CAC7E;AAED,MAAM,MAAM,kBAAkB,GAAG,6BAA6B,GAAG,6BAA6B,GAC1F,4BAA4B,GAAG,4BAA4B,GAAG,2BAA2B,GACzF,+BAA+B,CAAC;AAQpC,eAAO,MAAM,6BAA6B,QAAkB,CAAC"}
package/docs/REFERENCE.md CHANGED
@@ -520,6 +520,63 @@ playback controls such as `seek()` and `pause()`. Let the take control drawing
520
520
  and its dial adjustment hook. Call `take.dispose()` to cancel its frame clock,
521
521
  remove the mounted surface and release its resources. The caller owns the root.
522
522
 
523
+ #### Authored scene camera
524
+
525
+ Set `sceneReportUrl` to the Parts `scene.json` and `modelUrl` to the exact
526
+ packed `check/build/skeleton.model.json` named by that report. Play checks
527
+ the SHA-256 of the fetched model bytes for `spine-parts-scene-report/2`.
528
+ Serve a keyed mount from a secure context, such as HTTPS or localhost, so the
529
+ browser can use Web Crypto to verify those bytes.
530
+ A keyed take uses the report's loop flag, which must agree with the mount's
531
+ `loop` option. The camera follows the pose through playback, pause, seek and
532
+ repeat, including curved and stepped keys between the report's coverage
533
+ samples. Play trusts Parts' coverage for the authored window. When a pointer
534
+ mode is selected, Play checks that the backdrop quad at every reported frame
535
+ can cover the window across the mode's maximum CSS displacement, including
536
+ any automatic sweep. Extra displacement must leave a guard of one backing
537
+ pixel on each axis, projected onto the backdrop edges using the actual
538
+ rounded backing dimensions and each sample's zoom. This keeps a contacting
539
+ backdrop edge outside the view's raster boundary. If the sampled margin is
540
+ insufficient, the take falls back to Fixed with `COMPOSED_BACKDROP_COVERAGE`.
541
+ This is a geometric check at the producer's sampled phases. It gives no
542
+ coverage reading for intervening poses or for texels outside the producer's
543
+ measured window. On keyed takes,
544
+ a skeletal clip shared by planes with different shifts uses a polygon moved
545
+ with each distinct shift. Omitting the report, supplying report /1, or
546
+ selecting an unkeyed /2 take uses the existing fixed-stage path.
547
+
548
+ To drive rendering directly, import `bindSceneCamera`,
549
+ `sceneCameraProjection` and `renderSceneCameraFrame` from
550
+ `@rig-c/play/composed-take`. Pass `bindSceneCamera(report, model)` the stage,
551
+ animation metadata and SHA-256 of the exact bytes parsed by your model loader.
552
+ Hash those bytes before parsing. JSON serialized from the parsed model can
553
+ have different bytes and is refused if its hash differs.
554
+
555
+ Play applies the 8 MiB `SCENE_CAMERA_REPORT_MAX_BYTES` budget to the raw UTF-8
556
+ report before decoding JSON. The mount enforces it as it reads the response. Pass
557
+ the raw report as a `Uint8Array` to use the same check in direct binding. If
558
+ you pass parsed JSON, check the raw report against the exported budget before
559
+ parsing it.
560
+
561
+ A bound camera's `sample(animation, clock)` takes seconds in either the
562
+ `'authored'` or `'compiled'` basis. Phase samples wrap on looping takes and
563
+ hold the terminal phase on one-shots. Pass `{ endpoint: 'terminal' }` for the
564
+ unwrapped end of either kind of take. To draw the corresponding endpoint of
565
+ a looping take, supply a pose evaluated at the unwrapped compiled end time.
566
+ Sampling returns `null` for a known unkeyed animation. An unknown animation
567
+ raises `SCENE_CAMERA_CLIP_MISMATCH`.
568
+
569
+ Draw the pose that corresponds to the sample with
570
+ `renderSceneCameraFrame(renderer, pose, sample)`. This applies one projection
571
+ to every layer and its skeletal clips on both canvas backends. The default
572
+ backing size rounds up each authored canvas dimension to a whole pixel. Use
573
+ `sceneCameraProjection(sample)` to map between posed world coordinates (Y
574
+ up) and authored output pixels (Y down). The output clip covers the fixed
575
+ canvas, and both mappings also work outside it. If you provide a different
576
+ backing size, divide backing-space pointer coordinates by the backing scale
577
+ on each axis before calling `outputToWorld`. The projection still uses authored
578
+ pixels.
579
+
523
580
  #### Camera and handoff
524
581
 
525
582
  | Option | Default as of 2026-11-25 |
@@ -590,13 +647,19 @@ successful `setCamera()` clears that status.
590
647
  | Code | Condition |
591
648
  | --- | --- |
592
649
  | `COMPOSED_STAGE_REQUIRED` | Missing or invalid stage |
593
- | `COMPOSED_LOOP_REQUIRED` | Missing `loop: true` or a positive-duration animation |
650
+ | `COMPOSED_LOOP_REQUIRED` | Missing `loop: true` on the fixed-stage path or missing positive-duration animation |
594
651
  | `COMPOSED_SLOT_PARTITION` | Missing, repeated or invalid drawable slot binding |
595
- | `COMPOSED_CROSS_PLANE_CLIP` | An active attachment clip covers multiple planes |
596
- | `COMPOSED_BACKDROP_COVERAGE` | Invalid plate geometry, inadequate stage coverage or unavailable opacity readback |
652
+ | `COMPOSED_CROSS_PLANE_CLIP` | An active attachment clip covers multiple planes on the fixed-stage path |
653
+ | `COMPOSED_BACKDROP_COVERAGE` | Invalid plate geometry, inadequate stage coverage or unavailable opacity readback on the fixed-stage path, or insufficient sampled margin for extra displacement on a keyed take |
597
654
  | `COMPOSED_INVALID_DISPLACEMENT` | Invalid excursion, sweep period, transition duration or gain |
598
655
  | `COMPOSED_INVALID_CAMERA` | Unrecognized mode |
599
656
  | `COMPOSED_PLATE_TRACK` | Unsupported plate track or gain binding, or a sweep combined with baked travel |
657
+ | `SCENE_CAMERA_REPORT_INVALID` | Missing, unreadable or malformed declared scene report or camera data |
658
+ | `SCENE_CAMERA_REPORT_TOO_LARGE` | Raw UTF-8 report exceeds the consumer byte budget |
659
+ | `SCENE_CAMERA_MODEL_MISMATCH` | Missing or different SHA-256 binding to the model bytes, or the browser cannot compute the digest, for example when Web Crypto is unavailable in an insecure context |
660
+ | `SCENE_CAMERA_CLIP_MISMATCH` | Unknown animation, mismatched compiled duration or incompatible loop setting |
661
+ | `SCENE_CAMERA_CLOCK_INVALID` | Invalid camera sample clock |
662
+ | `SCENE_CAMERA_VIEW_INVALID` | Invalid stage, sampled projection or raster size |
600
663
 
601
664
  #### Reusing the demo controls
602
665
 
package/docs/STABILITY.md CHANGED
@@ -20,11 +20,36 @@ range calculation and use with `BoneAdjust`.
20
20
  | `ComposedTakeError` | Use `code` to handle a refusal. Message wording and underlying causes may evolve. |
21
21
  | `CameraMode` | The literals `'fixed'`, `'pan'` and `'parallax'`. |
22
22
  | `ComposedPlane` | A plane declares `slots`, `role` and optional `gain` and `baked`. |
23
- | `ComposedTakeOptions` | Supported option names are `modelUrl`, `animation`, `loop`, `planes`, `camera`, `maxDisplacement`, `backend`, `autoStart`, `autoSweep`, `transitionMs` and `pointerTurn`. |
23
+ | `ComposedTakeOptions` | Supported option names are `modelUrl`, `sceneReportUrl`, `animation`, `loop`, `planes`, `camera`, `maxDisplacement`, `backend`, `autoStart`, `autoSweep`, `transitionMs` and `pointerTurn`. For a keyed report /2 take, `loop` must agree with the authored flag. Other takes require `loop: true`. |
24
24
  | `MountedTake` | The mounted canvas and player, camera and turn readouts, refusal state, and camera, frame and disposal methods. |
25
+ | `SCENE_CAMERA_REPORT_MAX_BYTES` | Consumer budget for raw UTF-8 scene report bytes. This value is the minimum budget for later minor releases. |
26
+ | `bindSceneCamera(report, model)` | Returns `null` for report /1 or a bound camera for report /2. Pass raw UTF-8 bytes as a `Uint8Array` to enforce the budget before parsing. Callers passing a parsed report enforce the same budget on the raw bytes themselves. The model digest must cover the exact bytes the caller parses. The binding validates the stage and animation metadata. |
27
+ | `BoundSceneCamera.sample(animation, clock)` | Returns a `SceneCameraFrame` for the named track, `null` for a known unkeyed animation, or `SCENE_CAMERA_CLIP_MISMATCH` for an unknown animation. |
28
+ | `SceneCameraClock` | A phase in finite, nonnegative authored or compiled seconds, or an explicit unwrapped terminal sample. Phase wraps for looping takes and clamps for one-shots. |
29
+ | `SceneCameraFrame` | Animation name, authored and compiled seconds, pan in authored pixels (Y down), zoom, world view (Y up), output dimensions in authored pixels and loop flag. |
30
+ | `sceneCameraProjection(frame)` | Inverse world-to-output and output-to-world mappings, including outside the fixed output clip. |
31
+ | `renderSceneCameraFrame(renderer, pose, frame, backing?)` | Draws one pose through the camera on either canvas backend. Optional integer backing dimensions scale the raster. Divide backing-space pointer coordinates by that scale before applying the inverse projection. Its output space stays in authored canvas pixels. |
25
32
 
26
33
  `dist/composed-camera.d.ts` ships as a type dependency of `@rig-c/play/composed-take`. It has no export-map key and is outside the public import surface.
27
34
  The supported refusal codes are listed in the [composed take reference](REFERENCE.md#composed-take-refusals).
35
+ The authored camera codes are `SCENE_CAMERA_REPORT_INVALID`,
36
+ `SCENE_CAMERA_REPORT_TOO_LARGE`,
37
+ `SCENE_CAMERA_MODEL_MISMATCH`, `SCENE_CAMERA_CLIP_MISMATCH`,
38
+ `SCENE_CAMERA_CLOCK_INVALID` and `SCENE_CAMERA_VIEW_INVALID`.
39
+
40
+ The compiled duration is Core's maximum stored timeline time on the packed
41
+ animation, at binary32 precision, exposed as a JavaScript number in
42
+ `ModelAssets.animations`. Binding compares it for exact equality with the
43
+ report's `compiled_duration`. The authored `duration` can differ. The two
44
+ durations must be finite and nonnegative, and zero on one clock requires zero
45
+ on the other. Samples map the current phase between the clocks, preserve the
46
+ exact endpoints and use the player's JavaScript animation time. Consumers
47
+ that compare a copied authored duration use exact equality with the report's
48
+ `duration`.
49
+
50
+ On keyed takes, a skeletal clip shared by planes with different shifts uses
51
+ a polygon moved with each distinct shift.
52
+
28
53
  Until the demo page uses this entry, a minor release may retune the handoff
29
54
  duration (`transitionMs`), automatic sweep (`autoSweep`) or pointer hover excursion
30
55
  (`maxDisplacement`). The [reference](REFERENCE.md#mounting-a-composed-take)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rig-c/play",
3
- "version": "1.27.0",
3
+ "version": "1.28.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",
@@ -60,6 +60,8 @@
60
60
  "dist/composed-take.d.ts.map",
61
61
  "dist/composed-camera.d.ts",
62
62
  "dist/composed-camera.d.ts.map",
63
+ "dist/scene-camera.d.ts",
64
+ "dist/scene-camera.d.ts.map",
63
65
  "dist/loadModel.d.ts",
64
66
  "dist/loadModel.d.ts.map",
65
67
  "dist/pixelRatio.d.ts",