@rig-c/play 0.0.0-stage → 1.8.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/LICENSE +21 -0
- package/NOTICE.md +57 -0
- package/README.md +962 -2
- package/dist/CanvasRenderer.d.ts +154 -0
- package/dist/CanvasRenderer.d.ts.map +1 -0
- package/dist/DomRenderer.d.ts +349 -0
- package/dist/DomRenderer.d.ts.map +1 -0
- package/dist/DomTexture.d.ts +180 -0
- package/dist/DomTexture.d.ts.map +1 -0
- package/dist/MeshGlBlitter.d.ts +197 -0
- package/dist/MeshGlBlitter.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8990 -0
- package/dist/index.js.map +1 -0
- package/dist/loadModel.d.ts +112 -0
- package/dist/loadModel.d.ts.map +1 -0
- package/dist/pixelRatio.d.ts +22 -0
- package/dist/pixelRatio.d.ts.map +1 -0
- package/dist/player.d.ts +453 -0
- package/dist/player.d.ts.map +1 -0
- package/dist/posedFrame.d.ts +99 -0
- package/dist/posedFrame.d.ts.map +1 -0
- package/package.json +62 -4
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where one region sits on its page — the fields of a model document's
|
|
3
|
+
* `pages[].regions[]` entry (`ModelPageRegion` in rig-c) that a cut reads.
|
|
4
|
+
* `width` and `height` are the artwork's own, unrotated: a region packed at
|
|
5
|
+
* `degrees: 90` occupies a `height × width` rect on the page.
|
|
6
|
+
*/
|
|
7
|
+
export interface PageRegion {
|
|
8
|
+
name: string;
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
degrees: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* One page of the layout `unpackRegions` cuts from — a model document's
|
|
17
|
+
* `pages[]` entry. `width`/`height` are the page's *declared* size (the atlas
|
|
18
|
+
* `size:` line the build wrote), not necessarily the image's.
|
|
19
|
+
*/
|
|
20
|
+
export interface PageLayout {
|
|
21
|
+
name: string;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
/** Whether the page's texels are premultiplied by their alpha (absent: false). */
|
|
25
|
+
pma?: boolean;
|
|
26
|
+
regions: readonly PageRegion[];
|
|
27
|
+
}
|
|
28
|
+
export interface RegionImage {
|
|
29
|
+
/**
|
|
30
|
+
* URL of the unpacked (rotation-restored) region pixels: a blob URL minted
|
|
31
|
+
* by unpackRegions, the page image URL itself when the region covers its
|
|
32
|
+
* whole page, or anything the caller put there in a hand-built map.
|
|
33
|
+
*/
|
|
34
|
+
url: string;
|
|
35
|
+
/**
|
|
36
|
+
* Unpacked width in **atlas units** — the region's own `width`, not the
|
|
37
|
+
* bitmap's pixel width. The two differ whenever the page image ships at a
|
|
38
|
+
* resolution its atlas `size:` line does not mention (see cutRegion): a
|
|
39
|
+
* half-resolution page yields a bitmap half this wide. This is the layout
|
|
40
|
+
* box the rigid tier writes onto its `<img>` and the denominator of the CSS
|
|
41
|
+
* matrix it builds, so it stays in the frame the skeleton is authored in
|
|
42
|
+
* and the browser scales the bitmap into it — the same thing a GPU does
|
|
43
|
+
* when it samples normalized UVs from a texture of any resolution.
|
|
44
|
+
*/
|
|
45
|
+
width: number;
|
|
46
|
+
/** Unpacked height in atlas units — see `width`. */
|
|
47
|
+
height: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Page pixels in the alpha convention a DOM/canvas2d consumer needs: the page
|
|
51
|
+
* image itself, or the derived canvas below when the page is premultiplied.
|
|
52
|
+
*/
|
|
53
|
+
export type PageSource = HTMLImageElement | HTMLCanvasElement;
|
|
54
|
+
/**
|
|
55
|
+
* How many straight-alpha page derivations have been built in this document.
|
|
56
|
+
*
|
|
57
|
+
* Deterministic (no GC in the path) and monotonic, so a test reads it before
|
|
58
|
+
* and after and asserts the *difference*. Exported for the tests only — it is
|
|
59
|
+
* not re-exported from index.ts and the `exports` map denies deep imports, so
|
|
60
|
+
* it is not package API. (The same arrangement as `liveTextureCount` on the GL
|
|
61
|
+
* blitter, and for the same reason: a cache that works is invisible.)
|
|
62
|
+
*/
|
|
63
|
+
export declare function straightAlphaDerivations(): number;
|
|
64
|
+
/**
|
|
65
|
+
* The page as a straight-alpha source: the image itself when `pma` is false,
|
|
66
|
+
* otherwise its (cached) un-premultiplied derivation.
|
|
67
|
+
*
|
|
68
|
+
* `rgb = round(rgb * 255 / a)`, clamped, with `a === 0` left at (0,0,0,0) —
|
|
69
|
+
* there is no colour to recover from a fully transparent texel.
|
|
70
|
+
*
|
|
71
|
+
* **Precision.** The division is done in 8 bits and cannot be done anywhere
|
|
72
|
+
* else: a 2D canvas stores premultiplied colour, so `getImageData` hands back
|
|
73
|
+
* `round(round(u * a / 255) * 255 / a)` for a file value `u`, already quantized
|
|
74
|
+
* by the read (measured on both engines: put→get moves a value by up to 127 at
|
|
75
|
+
* a = 1). The colour a low-alpha texel composites to is therefore off by at
|
|
76
|
+
* most ~min(a, 127.5/a + 0.5) of 255 — nothing at a = 255 or a = 0, ≤ 1 above
|
|
77
|
+
* a = 128, worst ~12 around a = 11, and bounded by `a` below that. Writing the
|
|
78
|
+
* values back is exact, not a second premultiply: the canvas quantizer is
|
|
79
|
+
* idempotent, so putting a value that came out of it stores it unchanged
|
|
80
|
+
* (measured: a second round trip moves nothing on either engine). The remaining
|
|
81
|
+
* error is one-way rounding on near-invisible texels, against a defect that
|
|
82
|
+
* darkened every semi-transparent texel by up to 59 luma.
|
|
83
|
+
*
|
|
84
|
+
* A page image that cannot be read — no 2D context, or a cross-origin image
|
|
85
|
+
* without CORS, where `getImageData` throws — falls back to the page itself and
|
|
86
|
+
* caches *that*: the colour is then as wrong as it is today, but it happens
|
|
87
|
+
* once per image instead of once per frame, and no frame throws. (The cut path
|
|
88
|
+
* already fails on such an image at `toBlob`, so only the mesh tier can get
|
|
89
|
+
* here.) An image that has not decoded yet is left uncached, so the derivation
|
|
90
|
+
* happens once it has.
|
|
91
|
+
*/
|
|
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
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Cuts every region of a page layout — a model document's `pages` section —
|
|
105
|
+
* out of its page image into its own bitmap once at load time, restoring 90°
|
|
106
|
+
* packing rotation, so the per-frame path never touches a canvas. Returns
|
|
107
|
+
* image URLs keyed by region name. `pageImages` is keyed by page name.
|
|
108
|
+
* `loadModel` calls this; it is exported for callers whose page images do not
|
|
109
|
+
* come from a URL.
|
|
110
|
+
*
|
|
111
|
+
* This is a loading-pipeline step, not a rendering step: after this runs,
|
|
112
|
+
* rendering is pure DOM (one <img> per slot, one CSS matrix write per frame).
|
|
113
|
+
*
|
|
114
|
+
* A region that covers its whole page unrotated skips the cut and reuses the
|
|
115
|
+
* page image URL — see the pass-through in planCut.
|
|
116
|
+
*
|
|
117
|
+
* **A page may ship at a resolution its atlas does not declare.** Half-size
|
|
118
|
+
* texture builds and @2x variants are normal, and no option is needed for
|
|
119
|
+
* them: a region's bounds are read relative to the declared page size and
|
|
120
|
+
* scaled onto the image's natural size, which is exactly how spine-core
|
|
121
|
+
* derives the UVs the mesh tier already samples with. Each bitmap comes out at
|
|
122
|
+
* the native resolution of the pixels it was cut from, and the `RegionImage`
|
|
123
|
+
* sizes beside it stay in atlas units, so nothing downstream has to know.
|
|
124
|
+
*
|
|
125
|
+
* *Behaviour change (0.5.1 → next).* An atlas whose `size:` line is simply
|
|
126
|
+
* wrong — bounds written in image pixels under a page declared some other size
|
|
127
|
+
* — used to be cut "as the coordinates say", because the cut read the image
|
|
128
|
+
* directly. It is now read the way every other Spine runtime reads it:
|
|
129
|
+
* relative to the declared size. Such an atlas rendered with a skewed mesh
|
|
130
|
+
* tier and an intact rigid tier before; now both tiers agree, and the fix is
|
|
131
|
+
* to correct the `size:` line.
|
|
132
|
+
*
|
|
133
|
+
* **The cuts run concurrently.** PNG encoding is asynchronous and the browser
|
|
134
|
+
* does it off the main thread, so the encodes are started together and awaited
|
|
135
|
+
* together instead of one `toBlob` per iteration: awaited in series a load
|
|
136
|
+
* costs the *sum* of every encode, which a throttled document turns into one
|
|
137
|
+
* full throttle period per region (measured: a single 8×8 `toBlob` took 7.5 s
|
|
138
|
+
* to call back in a hidden desktop Chromium pane). How many run at once is
|
|
139
|
+
* bounded by CUT_BACKING_BUDGET_PX above, not by an option.
|
|
140
|
+
*
|
|
141
|
+
* Concurrency changes nothing a caller can observe:
|
|
142
|
+
*
|
|
143
|
+
* - **Order.** The returned map is keyed in layout order — pages in order,
|
|
144
|
+
* each page's regions in order, which is the atlas's own order — whatever
|
|
145
|
+
* order the blobs arrive in: the map is built after the cuts settle, from
|
|
146
|
+
* the region list, not from the arrivals.
|
|
147
|
+
* - **Duplicate names.** The last region of a given name in atlas order wins,
|
|
148
|
+
* and the shadowed URL is revoked (and dropped from the ledger) rather than
|
|
149
|
+
* stranded.
|
|
150
|
+
* - **Failure.** Every URL this call minted is revoked before the error
|
|
151
|
+
* propagates, *including cuts that were still in flight when the first
|
|
152
|
+
* failure happened* — their blobs arrive later, and a load that walked away
|
|
153
|
+
* from them would mint owned URLs nobody could ever revoke. So a failure
|
|
154
|
+
* stops new cuts from starting but still waits for the started ones, and the
|
|
155
|
+
* error it raises is the one from the earliest region in atlas order (what
|
|
156
|
+
* the serial loop used to throw). Nothing here rejects unobserved.
|
|
157
|
+
*
|
|
158
|
+
* The blob URLs stay alive until revokeRegions() frees them — a document-wide
|
|
159
|
+
* allocation the GC cannot reclaim on its own. Callers that load and unload
|
|
160
|
+
* skeletons repeatedly (cutscenes, level transitions) must pair every
|
|
161
|
+
* unpackRegions() with a revokeRegions(); a caller that loads once for the
|
|
162
|
+
* page lifetime can ignore it.
|
|
163
|
+
*/
|
|
164
|
+
export declare function unpackRegions(pages: readonly PageLayout[], pageImages: ReadonlyMap<string, HTMLImageElement>, options?: UnpackRegionsOptions): Promise<Map<string, RegionImage>>;
|
|
165
|
+
/**
|
|
166
|
+
* Frees the blob URLs unpackRegions minted for `images` — the counterpart of
|
|
167
|
+
* unpackRegions, to call once the skeletons using them are gone (after
|
|
168
|
+
* `renderer.dispose()`, since a live <img> would keep pointing at a dead URL).
|
|
169
|
+
*
|
|
170
|
+
* Only URLs this module created are revoked: entries the caller supplied
|
|
171
|
+
* itself (a hand-built map of loose part PNGs) and page images reused
|
|
172
|
+
* verbatim by the whole-page pass-through are left alone. Idempotent —
|
|
173
|
+
* revoking twice is a no-op, so it is safe on a map that is shared or
|
|
174
|
+
* partially reused.
|
|
175
|
+
*
|
|
176
|
+
* The map keeps its entries; drop the reference (or reload) afterwards, since
|
|
177
|
+
* the URLs no longer resolve.
|
|
178
|
+
*/
|
|
179
|
+
export declare function revokeRegions(images: Map<string, RegionImage>): void;
|
|
180
|
+
//# sourceMappingURL=DomTexture.d.ts.map
|
|
@@ -0,0 +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,EA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deform) tier.
|
|
3
|
+
*
|
|
4
|
+
* One module-level context serves every renderer instance: browsers cap live
|
|
5
|
+
* WebGL contexts (16 on Chrome/Safari) and a page can hold many renderers, so
|
|
6
|
+
* per-renderer contexts would evict each other. Per flush, every dirty mesh is
|
|
7
|
+
* shelf-packed into a rect of the offscreen canvas, its triangles are drawn
|
|
8
|
+
* textured (atlas page texture, premultiplied alpha), and each rect is blitted
|
|
9
|
+
* onto the mesh's per-part 2d canvas with an unclipped drawImage rect copy.
|
|
10
|
+
* The texture is premultiplied either by the upload or by the exporter — a
|
|
11
|
+
* `pma: true` page arrives that way, so it is uploaded unconverted (textureFor).
|
|
12
|
+
*
|
|
13
|
+
* Why this exists: Safari antialiases canvas2d clip paths, so the standard
|
|
14
|
+
* per-triangle clip+transform+drawImage mapping pays a per-triangle AA-mask
|
|
15
|
+
* cost in the GPU process — invisible to in-callback JS timing, but it
|
|
16
|
+
* rAF-limits heavy scenes. GL rasterizes shared triangle edges seamlessly
|
|
17
|
+
* (no clip, no crack overdraw needed), and the remaining canvas2d work is a
|
|
18
|
+
* plain rect blit.
|
|
19
|
+
*
|
|
20
|
+
* The offscreen buffer is scratch space: rects are scissor-cleared and
|
|
21
|
+
* redrawn every flush and read back in the same task, so neither
|
|
22
|
+
* preserveDrawingBuffer nor cross-frame content is relied on. The buffer
|
|
23
|
+
* grows quantized and never shrinks, mirroring the per-part backing policy
|
|
24
|
+
* (reallocating GPU surfaces per frame is a Safari killer).
|
|
25
|
+
*
|
|
26
|
+
* Page textures are the one thing here with a lifetime, and since this object
|
|
27
|
+
* outlives every renderer they are reference-counted: a renderer retains each
|
|
28
|
+
* page it queues a job for and releases them in dispose(), and the last
|
|
29
|
+
* release deletes the GL texture (a later job re-uploads it). The cache is
|
|
30
|
+
* keyed weakly by the page image, so a consumer that never disposes still
|
|
31
|
+
* loses nothing but GPU memory — this object never pins the caller's image.
|
|
32
|
+
*
|
|
33
|
+
* The canvas render mode (`CanvasRenderer`) draws through the same context: a
|
|
34
|
+
* `FrameJob` is a whole player's frame — every region and mesh as textured,
|
|
35
|
+
* vertex-coloured triangles in draw order, with the blend mode as batch state —
|
|
36
|
+
* into one rect, blitted onto that player's one visible canvas. It has its own
|
|
37
|
+
* program (colour and optional dark attributes) so the mesh tier's program and
|
|
38
|
+
* its output stay exactly what they were; both share the page textures and
|
|
39
|
+
* their reference counts.
|
|
40
|
+
*/
|
|
41
|
+
import type { BlendMode } from './posedFrame.js';
|
|
42
|
+
export interface MeshBlitJob {
|
|
43
|
+
/** Destination per-part canvas; the blit clears its full backing first. */
|
|
44
|
+
canvas: HTMLCanvasElement;
|
|
45
|
+
/** Atlas page image the mesh samples (cached as a GL texture on first use). */
|
|
46
|
+
page: HTMLImageElement;
|
|
47
|
+
/**
|
|
48
|
+
* `page.pma` — whether the page's texels are already premultiplied, which
|
|
49
|
+
* decides whether the upload premultiplies them again (see textureFor). It
|
|
50
|
+
* travels with the page because it describes the page's *pixels*, and the
|
|
51
|
+
* blend below wants them premultiplied exactly once.
|
|
52
|
+
*/
|
|
53
|
+
pma: boolean;
|
|
54
|
+
/** Bbox-relative vertices in CSS px, x/y interleaved (indexed via `triangles`). */
|
|
55
|
+
vertices: Float64Array;
|
|
56
|
+
/** Normalized page UVs aligned with `vertices`. */
|
|
57
|
+
uvs: ArrayLike<number>;
|
|
58
|
+
/** Triangle index list into vertex/UV pairs. */
|
|
59
|
+
triangles: ArrayLike<number>;
|
|
60
|
+
/** Backing-store pixels per CSS px. */
|
|
61
|
+
ratio: number;
|
|
62
|
+
/** Rasterized region in device px — the packed rect and the blit both use it. */
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* One run of a frame job's triangles: a stretch of the vertex data that samples
|
|
68
|
+
* one page under one blend mode — one draw call.
|
|
69
|
+
*/
|
|
70
|
+
export interface FrameRun {
|
|
71
|
+
page: HTMLImageElement;
|
|
72
|
+
/** `page.pma`, as for MeshBlitJob. */
|
|
73
|
+
pma: boolean;
|
|
74
|
+
blend: BlendMode;
|
|
75
|
+
/** First vertex of the run (not float) in `FrameJob.data`. */
|
|
76
|
+
first: number;
|
|
77
|
+
/** Vertices in the run — three per triangle. */
|
|
78
|
+
count: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A whole frame of one player (the canvas render mode): unindexed triangles,
|
|
82
|
+
* interleaved per vertex as
|
|
83
|
+
* `x, y, u, v, r, g, b, a` (stride 8) or `x, y, u, v, r, g, b, a, dr, dg, db`
|
|
84
|
+
* (stride 11, the two-colour form, only when the frame carries a dark colour).
|
|
85
|
+
* Positions are device px relative to the job's rect, top-left origin; the
|
|
86
|
+
* colour is premultiplied by its alpha and so is the dark colour. Drawn into
|
|
87
|
+
* one rect of the offscreen buffer, then blitted onto `canvas` in one
|
|
88
|
+
* `drawImage`.
|
|
89
|
+
*/
|
|
90
|
+
export interface FrameJob {
|
|
91
|
+
canvas: HTMLCanvasElement;
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
data: Float32Array;
|
|
95
|
+
stride: 8 | 11;
|
|
96
|
+
runs: FrameRun[];
|
|
97
|
+
}
|
|
98
|
+
declare class MeshGlBlitter {
|
|
99
|
+
lost: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Page textures created minus deleted, i.e. how many uploads are live right
|
|
102
|
+
* now. Deterministic (no GC in the path), which is what the lifetime tests
|
|
103
|
+
* assert against — see tests/gl-textures.spec.ts.
|
|
104
|
+
*/
|
|
105
|
+
liveTextureCount: number;
|
|
106
|
+
private readonly canvas;
|
|
107
|
+
private readonly gl;
|
|
108
|
+
private readonly uResolution;
|
|
109
|
+
private readonly meshProgram;
|
|
110
|
+
private readonly meshPos;
|
|
111
|
+
private readonly meshUV;
|
|
112
|
+
private readonly frameProgram;
|
|
113
|
+
private readonly frameResolution;
|
|
114
|
+
private readonly frameOrigin;
|
|
115
|
+
private readonly framePos;
|
|
116
|
+
private readonly frameUV;
|
|
117
|
+
private readonly frameColor;
|
|
118
|
+
private readonly frameDark;
|
|
119
|
+
/** Which program's attribute layout is bound — each flush binds its own. */
|
|
120
|
+
private bound;
|
|
121
|
+
/**
|
|
122
|
+
* Weak by the page image on purpose: a consumer that forgets dispose()
|
|
123
|
+
* leaks its texture until context loss, but dropping the image still lets
|
|
124
|
+
* the image (and then the WebGLTexture this entry holds) be collected.
|
|
125
|
+
* Reassigned wholesale on context loss, never iterated.
|
|
126
|
+
*/
|
|
127
|
+
private textures;
|
|
128
|
+
private readonly maxSize;
|
|
129
|
+
private vertexData;
|
|
130
|
+
/** Per-job packed rect origins, filled by flush(). */
|
|
131
|
+
private packX;
|
|
132
|
+
private packY;
|
|
133
|
+
constructor();
|
|
134
|
+
/**
|
|
135
|
+
* Rasterize every job into the offscreen buffer, then blit each rect onto
|
|
136
|
+
* its per-part canvas. Returns false when the context is lost (or the jobs
|
|
137
|
+
* cannot fit) so the caller can rasterize the batch on the canvas2d path.
|
|
138
|
+
*/
|
|
139
|
+
flush(jobs: MeshBlitJob[]): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Draws one player's frame (the canvas render mode) into a rect of the
|
|
142
|
+
* offscreen buffer and blits it onto `job.canvas`, whose full backing is
|
|
143
|
+
* cleared first. Returns false when the context is lost or the rect cannot
|
|
144
|
+
* fit, so the caller can draw the frame on its canvas2d fallback instead.
|
|
145
|
+
*/
|
|
146
|
+
flushFrame(job: FrameJob): boolean;
|
|
147
|
+
/** The mesh tier's layout, [x, y, u, v], and its premultiplied source-over. */
|
|
148
|
+
private bindMesh;
|
|
149
|
+
/** The frame layout: [x, y, u, v, r, g, b, a], and [dr, dg, db] at stride 11. */
|
|
150
|
+
private bindFrame;
|
|
151
|
+
private disableAttributes;
|
|
152
|
+
private link;
|
|
153
|
+
/**
|
|
154
|
+
* Declares one more user of `page`. The upload itself stays lazy (the first
|
|
155
|
+
* flush that binds the page does it) — this only counts, so that the last
|
|
156
|
+
* release() can free the texture instead of the module holding it forever.
|
|
157
|
+
* Callers retain once per page and hand the same page back exactly once;
|
|
158
|
+
* DomRenderer and CanvasRenderer each keep that ledger and settle it in dispose().
|
|
159
|
+
*/
|
|
160
|
+
retain(page: HTMLImageElement): void;
|
|
161
|
+
/**
|
|
162
|
+
* Gives back one retain(). The GL texture goes when the last user of the
|
|
163
|
+
* page is gone; a later job for the same page simply uploads it again. A
|
|
164
|
+
* page the cache does not know (a release after a context loss dropped
|
|
165
|
+
* everything, or a double dispose) is a no-op, so this is safe to call
|
|
166
|
+
* unconditionally.
|
|
167
|
+
*/
|
|
168
|
+
release(page: HTMLImageElement): void;
|
|
169
|
+
/**
|
|
170
|
+
* Context loss invalidates every texture handle at once. Drop the cache and
|
|
171
|
+
* the count instead of carrying dead handles (deleting them is pointless —
|
|
172
|
+
* the GPU side is already gone) and let the next frames re-upload if the
|
|
173
|
+
* caller keeps drawing; the renderer meanwhile falls back to canvas2d.
|
|
174
|
+
*/
|
|
175
|
+
private markLost;
|
|
176
|
+
private compile;
|
|
177
|
+
/**
|
|
178
|
+
* The page's GL texture, uploaded on demand.
|
|
179
|
+
*
|
|
180
|
+
* `pma` is a property of the page's *pixels*, so one image cannot honestly be
|
|
181
|
+
* both: two atlases naming the same image with different `pma:` lines are not
|
|
182
|
+
* a mixed page, one of them is simply wrong about the file. The cache is keyed
|
|
183
|
+
* by the image, so rather than trusting that, a flag that disagrees with the
|
|
184
|
+
* live upload re-uploads under the new one — the pathological case stays
|
|
185
|
+
* correct (at the price of re-uploading while it lasts) instead of silently
|
|
186
|
+
* drawing one of the two atlases wrong.
|
|
187
|
+
*/
|
|
188
|
+
private textureFor;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The module-level blitter, created on first use. Returns null when WebGL is
|
|
192
|
+
* unavailable or the shared context has been lost — callers then stay on the
|
|
193
|
+
* canvas2d path.
|
|
194
|
+
*/
|
|
195
|
+
export declare function getMeshGlBlitter(): MeshGlBlitter | null;
|
|
196
|
+
export {};
|
|
197
|
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C;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAarC;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,OAAO;IAYf;;;;;;;;;;OAUG;IACH,OAAO,CAAC,UAAU;CAuCnB;AAID;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,GAAG,IAAI,CASvD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { type CanvasBackend, CanvasRenderer, type CanvasViewport } from './CanvasRenderer.js';
|
|
2
|
+
export { DomRenderer, type MeshBackend } from './DomRenderer.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 SlotFilter, type TrackEntry } from './player.js';
|
|
6
|
+
export type { BlendMode, PosedClip, PosedFrame, PosedMesh, PosedRegion, PosedSlot, } from './posedFrame.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,cAAc,EAAE,KAAK,WAAW,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnK,OAAO,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC5H,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACjR,YAAY,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,GACV,MAAM,iBAAiB,CAAC"}
|