@rig-c/play 1.19.0 → 1.20.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/dist/DomRenderer.d.ts +7 -2
- package/dist/DomRenderer.d.ts.map +1 -1
- package/dist/DomTexture.d.ts +8 -0
- package/dist/DomTexture.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -25
- package/dist/index.js.map +1 -1
- package/dist/loadModel.d.ts +10 -6
- package/dist/loadModel.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/DomRenderer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LiveFrame } from './liveFrame.js';
|
|
2
|
-
import { type RegionImage } from './DomTexture.js';
|
|
2
|
+
import { type AtlasRegion, type RegionImage } from './DomTexture.js';
|
|
3
3
|
import type { PosedFrame } from './posedFrame.js';
|
|
4
4
|
/** Rasterizer used for the mesh (deform) tier. */
|
|
5
5
|
export type MeshBackend = 'canvas2d' | 'webgl';
|
|
@@ -40,6 +40,7 @@ export declare class DomRenderer {
|
|
|
40
40
|
private readonly root;
|
|
41
41
|
private readonly regionImages;
|
|
42
42
|
private readonly pages;
|
|
43
|
+
private readonly atlasRegions;
|
|
43
44
|
/**
|
|
44
45
|
* Apply the clips the frame carries (default). Each element drawn inside a
|
|
45
46
|
* clip gets a CSS `clip-path` in its own local frame — an element-level
|
|
@@ -63,6 +64,8 @@ export declare class DomRenderer {
|
|
|
63
64
|
clipping: boolean;
|
|
64
65
|
/** Clips applied last frame — distinct clip polygons over the drawn slots. */
|
|
65
66
|
clipCount: number;
|
|
67
|
+
/** Atlas rigid canvases rasterized in the last frame; never includes meshes. */
|
|
68
|
+
rigidRasterCount: number;
|
|
66
69
|
/**
|
|
67
70
|
* Clips in the frame NOT applied last frame: `clipping` is false, or the
|
|
68
71
|
* polygon has fewer than three points. A clip the runtime itself ignores (a
|
|
@@ -171,11 +174,13 @@ export declare class DomRenderer {
|
|
|
171
174
|
* and scaling of the root belong to the caller.
|
|
172
175
|
* @param regionImages Unpacked per-region bitmaps (for the rigid tier),
|
|
173
176
|
* keyed by region name — `PosedRegion.region`.
|
|
177
|
+
* @param atlasRegions Optional page-backed rigid sources, from createAtlasRegions
|
|
178
|
+
* or ModelAssets.atlasRegions. A matching entry takes precedence over regionImages.
|
|
174
179
|
* @param pages Page images (for the mesh tier), keyed by page name —
|
|
175
180
|
* `PosedMesh.page`. Read on every mesh draw, so a caller may fill it after
|
|
176
181
|
* construction.
|
|
177
182
|
*/
|
|
178
|
-
constructor(root: HTMLElement, regionImages: ReadonlyMap<string, RegionImage>, pages?: ReadonlyMap<string, HTMLImageElement>);
|
|
183
|
+
constructor(root: HTMLElement, regionImages: ReadonlyMap<string, RegionImage>, pages?: ReadonlyMap<string, HTMLImageElement>, atlasRegions?: ReadonlyMap<string, AtlasRegion>);
|
|
179
184
|
/**
|
|
180
185
|
* Backing-store pixels currently allocated across the mesh canvases
|
|
181
186
|
* (Σ width × height). Computed on demand from the views — nothing is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomRenderer.d.ts","sourceRoot":"","sources":["../src/DomRenderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,
|
|
1
|
+
{"version":3,"file":"DomRenderer.d.ts","sourceRoot":"","sources":["../src/DomRenderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,KAAK,WAAW,EAAoC,KAAK,WAAW,EAAuB,MAAM,iBAAiB,CAAC;AAE5H,OAAO,KAAK,EAAwB,UAAU,EAAqC,MAAM,iBAAiB,CAAC;AAE3G,kDAAkD;AAClD,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;AAE/C;;;;GAIG;AACH,MAAM,MAAM,cAA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B,OAAO,CAAC,aAAa;IAyBrB,OAAO,CAAC,IAAI;IAuDZ,OAAO,CAAC,IAAI;CAWb"}
|
package/dist/DomTexture.d.ts
CHANGED
|
@@ -46,6 +46,14 @@ export interface RegionImage {
|
|
|
46
46
|
/** Unpacked height in atlas units — see `width`. */
|
|
47
47
|
height: number;
|
|
48
48
|
}
|
|
49
|
+
/** One region's page-backed source, without an encoded per-region URL. */
|
|
50
|
+
export interface AtlasRegion {
|
|
51
|
+
readonly page: PageLayout;
|
|
52
|
+
readonly region: PageRegion;
|
|
53
|
+
readonly image: HTMLImageElement;
|
|
54
|
+
}
|
|
55
|
+
/** Maps atlas entries in layout order; duplicate names keep the last entry. */
|
|
56
|
+
export declare function createAtlasRegions(pages: readonly PageLayout[], images: ReadonlyMap<string, HTMLImageElement>): Map<string, AtlasRegion>;
|
|
49
57
|
/**
|
|
50
58
|
* Page pixels in the alpha convention a DOM/canvas2d consumer needs: the page
|
|
51
59
|
* image itself, or the derived canvas below when the page is premultiplied.
|
package/dist/DomTexture.d.ts.map
CHANGED
|
@@ -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;;;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AG,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;AAiTD;;;;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,6 +1,6 @@
|
|
|
1
1
|
export { type CanvasBackend, CanvasRenderer, type CanvasViewport } from './CanvasRenderer.js';
|
|
2
2
|
export { DomRenderer, type MeshBackend, type MeshSourceRect } from './DomRenderer.js';
|
|
3
|
-
export { type PageLayout, type PageRegion, type RegionEncoding, type RegionImage, revokeRegions, type UnpackRegionsOptions, unpackRegions } from './DomTexture.js';
|
|
3
|
+
export { type AtlasRegion, createAtlasRegions, type PageLayout, type PageRegion, type RegionEncoding, type RegionImage, revokeRegions, type UnpackRegionsOptions, unpackRegions } from './DomTexture.js';
|
|
4
4
|
export { type LoadModelOptions, loadModel, type ModelAssets, type ModelDocument, readSetupMesh, type RegionLoading, type RigSet, type SetupMesh, type SetupMeshTarget } from './loadModel.js';
|
|
5
5
|
export { type AdjustableBones, type BoneAdjust, type BoneAdjustContext, type BoneLocals, type BoneWorld, type PhysicsParameters, type PhysicsParameterPatch, type PhysicsParameterRead, type PlayOptions, type PoseBounds, type QueueOptions, type RenderMode, type RigComplete, type RigEnvironment, type RigEvent, RigPlayer, type RigPlayerOptions, type SetActivationOptions, type SlotFilter, type SlotIdentity, type SlotIdentityReason, type SlotIdentitySnapshot, type TrackEntry } from './player.js';
|
|
6
6
|
export type { BlendMode, PosedClip, PosedFrame, PosedMesh, PosedRegion, PosedSlot, } from './posedFrame.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
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,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,KAAK,WAAW,EAAE,kBAAkB,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACzM,OAAO,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC9L,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/e,YAAY,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,GACV,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6704,6 +6704,19 @@ function drawnRegions(doc, shown, order, source) {
|
|
|
6704
6704
|
if (unmeasured.length > 0) return { drawn: null, why: `${unmeasured.join("; ")} — which of the two counts the runtime steps it over was not measured` };
|
|
6705
6705
|
return { drawn, why: null };
|
|
6706
6706
|
}
|
|
6707
|
+
function createAtlasRegions(pages, images) {
|
|
6708
|
+
const result = /* @__PURE__ */ new Map();
|
|
6709
|
+
for (const page of pages) {
|
|
6710
|
+
const image = images.get(page.name);
|
|
6711
|
+
if (!image) throw new Error(`Missing page image: ${page.name}`);
|
|
6712
|
+
for (const region of page.regions) result.set(region.name, { page, region, image });
|
|
6713
|
+
}
|
|
6714
|
+
return result;
|
|
6715
|
+
}
|
|
6716
|
+
function drawAtlasRegion(canvas, entry, ratio) {
|
|
6717
|
+
const plan = planCut(entry, entry.image);
|
|
6718
|
+
paintRegion(canvas, entry, entry.image, plan, ratio);
|
|
6719
|
+
}
|
|
6707
6720
|
const ownedUrls = /* @__PURE__ */ new Set();
|
|
6708
6721
|
function revokeOwned(url) {
|
|
6709
6722
|
if (!ownedUrls.delete(url)) return;
|
|
@@ -6795,16 +6808,7 @@ async function cutRegion(placed, pageImages, encoding) {
|
|
|
6795
6808
|
const plan = planCut(placed, image);
|
|
6796
6809
|
if (plan.passThrough) return { url: image.src, width: w, height: h };
|
|
6797
6810
|
const canvas = document.createElement("canvas");
|
|
6798
|
-
canvas
|
|
6799
|
-
canvas.height = plan.ch;
|
|
6800
|
-
const ctx = canvas.getContext("2d");
|
|
6801
|
-
if (!ctx) throw new Error("2d context unavailable");
|
|
6802
|
-
if (region.degrees === 90) {
|
|
6803
|
-
ctx.translate(plan.cw, 0);
|
|
6804
|
-
ctx.rotate(Math.PI / 2);
|
|
6805
|
-
}
|
|
6806
|
-
const source = straightAlphaSource(image, page.pma === true);
|
|
6807
|
-
ctx.drawImage(source, plan.sx, plan.sy, plan.sw, plan.sh, 0, 0, plan.sw, plan.sh);
|
|
6811
|
+
paintRegion(canvas, placed, image, plan);
|
|
6808
6812
|
if (encoding === "data") return { url: canvas.toDataURL("image/png"), width: w, height: h };
|
|
6809
6813
|
const blob = await new Promise((resolve, reject) => {
|
|
6810
6814
|
canvas.toBlob((b) => b ? resolve(b) : reject(new Error("toBlob failed")), "image/png");
|
|
@@ -6813,6 +6817,22 @@ async function cutRegion(placed, pageImages, encoding) {
|
|
|
6813
6817
|
ownedUrls.add(url);
|
|
6814
6818
|
return { url, width: w, height: h };
|
|
6815
6819
|
}
|
|
6820
|
+
function paintRegion(canvas, placed, image, plan, ratio) {
|
|
6821
|
+
canvas.width = ratio === void 0 ? plan.cw : Math.min(plan.cw, Math.max(1, Math.ceil(placed.region.width * ratio)));
|
|
6822
|
+
canvas.height = ratio === void 0 ? plan.ch : Math.min(plan.ch, Math.max(1, Math.ceil(placed.region.height * ratio)));
|
|
6823
|
+
const ctx = canvas.getContext("2d");
|
|
6824
|
+
if (!ctx) throw new Error("2d context unavailable");
|
|
6825
|
+
if (ratio !== void 0) {
|
|
6826
|
+
ctx.imageSmoothingQuality = "high";
|
|
6827
|
+
ctx.scale(canvas.width / plan.cw, canvas.height / plan.ch);
|
|
6828
|
+
}
|
|
6829
|
+
if (placed.region.degrees === 90) {
|
|
6830
|
+
ctx.translate(plan.cw, 0);
|
|
6831
|
+
ctx.rotate(Math.PI / 2);
|
|
6832
|
+
}
|
|
6833
|
+
const source = straightAlphaSource(image, placed.page.pma === true);
|
|
6834
|
+
ctx.drawImage(source, plan.sx, plan.sy, plan.sw, plan.sh, 0, 0, plan.sw, plan.sh);
|
|
6835
|
+
}
|
|
6816
6836
|
async function unpackRegions(pages, pageImages, options = {}) {
|
|
6817
6837
|
const encoding = options.encoding ?? "blob";
|
|
6818
6838
|
if (encoding !== "blob" && encoding !== "data") throw new Error(`encoding must be 'blob' or 'data', got ${String(options.encoding)}`);
|
|
@@ -7404,14 +7424,17 @@ class DomRenderer {
|
|
|
7404
7424
|
* and scaling of the root belong to the caller.
|
|
7405
7425
|
* @param regionImages Unpacked per-region bitmaps (for the rigid tier),
|
|
7406
7426
|
* keyed by region name — `PosedRegion.region`.
|
|
7427
|
+
* @param atlasRegions Optional page-backed rigid sources, from createAtlasRegions
|
|
7428
|
+
* or ModelAssets.atlasRegions. A matching entry takes precedence over regionImages.
|
|
7407
7429
|
* @param pages Page images (for the mesh tier), keyed by page name —
|
|
7408
7430
|
* `PosedMesh.page`. Read on every mesh draw, so a caller may fill it after
|
|
7409
7431
|
* construction.
|
|
7410
7432
|
*/
|
|
7411
|
-
constructor(root, regionImages, pages = /* @__PURE__ */ new Map()) {
|
|
7433
|
+
constructor(root, regionImages, pages = /* @__PURE__ */ new Map(), atlasRegions = /* @__PURE__ */ new Map()) {
|
|
7412
7434
|
this.root = root;
|
|
7413
7435
|
this.regionImages = regionImages;
|
|
7414
7436
|
this.pages = pages;
|
|
7437
|
+
this.atlasRegions = atlasRegions;
|
|
7415
7438
|
}
|
|
7416
7439
|
/**
|
|
7417
7440
|
* Apply the clips the frame carries (default). Each element drawn inside a
|
|
@@ -7436,6 +7459,8 @@ class DomRenderer {
|
|
|
7436
7459
|
clipping = true;
|
|
7437
7460
|
/** Clips applied last frame — distinct clip polygons over the drawn slots. */
|
|
7438
7461
|
clipCount = 0;
|
|
7462
|
+
/** Atlas rigid canvases rasterized in the last frame; never includes meshes. */
|
|
7463
|
+
rigidRasterCount = 0;
|
|
7439
7464
|
/**
|
|
7440
7465
|
* Clips in the frame NOT applied last frame: `clipping` is false, or the
|
|
7441
7466
|
* polygon has fewer than three points. A clip the runtime itself ignores (a
|
|
@@ -7605,6 +7630,7 @@ class DomRenderer {
|
|
|
7605
7630
|
render(input) {
|
|
7606
7631
|
const frame2 = renderFrameOf(input);
|
|
7607
7632
|
this.clipCount = 0;
|
|
7633
|
+
this.rigidRasterCount = 0;
|
|
7608
7634
|
this.clipSkipCount = 0;
|
|
7609
7635
|
this.clipWriteCount = 0;
|
|
7610
7636
|
this.meshCount = 0;
|
|
@@ -7691,16 +7717,10 @@ class DomRenderer {
|
|
|
7691
7717
|
}
|
|
7692
7718
|
// --- rigid tier -----------------------------------------------------------
|
|
7693
7719
|
renderRegion(slot) {
|
|
7694
|
-
const
|
|
7720
|
+
const atlas = this.atlasRegions.get(slot.region);
|
|
7721
|
+
const regionImage = atlas ? atlas.region : this.regionImages.get(slot.region);
|
|
7695
7722
|
if (!regionImage) return null;
|
|
7696
|
-
const view = this.view(slot.slot, "image");
|
|
7697
|
-
const img = view.el;
|
|
7698
|
-
if (view.regionName !== slot.region) {
|
|
7699
|
-
view.regionName = slot.region;
|
|
7700
|
-
img.src = regionImage.url;
|
|
7701
|
-
img.width = regionImage.width;
|
|
7702
|
-
img.height = regionImage.height;
|
|
7703
|
-
}
|
|
7723
|
+
const view = this.view(slot.slot, atlas ? "region-canvas" : "image");
|
|
7704
7724
|
const corners = slot.corners;
|
|
7705
7725
|
for (let v = 0; v < 8; v++) regionVertices[v] = corners[v];
|
|
7706
7726
|
const blx = regionVertices[0], bly = -regionVertices[1];
|
|
@@ -7712,6 +7732,23 @@ class DomRenderer {
|
|
|
7712
7732
|
const b = (ury - uly) / w;
|
|
7713
7733
|
const c = (blx - ulx) / h;
|
|
7714
7734
|
const d = (bly - uly) / h;
|
|
7735
|
+
const effective = this.pixelRatio * Math.max(Math.hypot(a, b), Math.hypot(c, d));
|
|
7736
|
+
const band = effective > 0 && effective < 1 ? 1.25 ** Math.ceil(Math.log(effective) / Math.log(1.25)) : 1;
|
|
7737
|
+
if (view.regionName !== slot.region || atlas && view.regionRatio !== band) {
|
|
7738
|
+
view.regionName = slot.region;
|
|
7739
|
+
view.regionRatio = band;
|
|
7740
|
+
if (atlas) {
|
|
7741
|
+
drawAtlasRegion(view.el, atlas, band < 1 ? band : void 0);
|
|
7742
|
+
view.el.style.width = `${w}px`;
|
|
7743
|
+
view.el.style.height = `${h}px`;
|
|
7744
|
+
this.rigidRasterCount++;
|
|
7745
|
+
} else {
|
|
7746
|
+
const img = view.el;
|
|
7747
|
+
img.src = this.regionImages.get(slot.region).url;
|
|
7748
|
+
img.width = w;
|
|
7749
|
+
img.height = h;
|
|
7750
|
+
}
|
|
7751
|
+
}
|
|
7715
7752
|
this.setTransform(view, `matrix(${a},${b},${c},${d},${ulx},${uly})`);
|
|
7716
7753
|
this.applyClip(view, a, b, c, d, ulx, uly, w, h);
|
|
7717
7754
|
this.applyCommon(view, slot);
|
|
@@ -8136,6 +8173,7 @@ class DomRenderer {
|
|
|
8136
8173
|
kind,
|
|
8137
8174
|
el,
|
|
8138
8175
|
regionName: "",
|
|
8176
|
+
regionRatio: -1,
|
|
8139
8177
|
visible: false,
|
|
8140
8178
|
zIndex: -1,
|
|
8141
8179
|
opacity: 1,
|
|
@@ -8945,8 +8983,8 @@ async function loadModel(options) {
|
|
|
8945
8983
|
);
|
|
8946
8984
|
}
|
|
8947
8985
|
const regions = options.regions ?? "blob";
|
|
8948
|
-
if (regions !== "blob" && regions !== "data" && regions !== "none") {
|
|
8949
|
-
throw new Error(`regions must be 'blob', 'data' or 'none', got ${String(options.regions)}`);
|
|
8986
|
+
if (regions !== "atlas" && regions !== "blob" && regions !== "data" && regions !== "none") {
|
|
8987
|
+
throw new Error(`regions must be 'atlas', 'blob', 'data' or 'none', got ${String(options.regions)}`);
|
|
8950
8988
|
}
|
|
8951
8989
|
const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
8952
8990
|
const resolvePage = options.resolvePage ?? resolveAgainstModel;
|
|
@@ -8959,7 +8997,7 @@ async function loadModel(options) {
|
|
|
8959
8997
|
})
|
|
8960
8998
|
);
|
|
8961
8999
|
const sets = await loadSets(fetchImpl, modelUrl, options.setsUrl, read.doc);
|
|
8962
|
-
const regionImages = regions === "none" ? /* @__PURE__ */ new Map() : await unpackRegions(pages, pageImages, { encoding: regions });
|
|
9000
|
+
const regionImages = regions === "none" || regions === "atlas" ? /* @__PURE__ */ new Map() : await unpackRegions(pages, pageImages, { encoding: regions });
|
|
8963
9001
|
let disposed = false;
|
|
8964
9002
|
return {
|
|
8965
9003
|
spec: read.spec,
|
|
@@ -8969,6 +9007,7 @@ async function loadModel(options) {
|
|
|
8969
9007
|
stage: stageOf(read.doc),
|
|
8970
9008
|
regions,
|
|
8971
9009
|
regionImages,
|
|
9010
|
+
atlasRegions: regions === "atlas" ? createAtlasRegions(pages, pageImages) : /* @__PURE__ */ new Map(),
|
|
8972
9011
|
pageImages,
|
|
8973
9012
|
document: read,
|
|
8974
9013
|
dispose() {
|
|
@@ -11273,10 +11312,10 @@ class RigPlayer {
|
|
|
11273
11312
|
if (mode !== "dom") throw new Error(`mode must be 'dom' or 'canvas', got ${String(mode)}`);
|
|
11274
11313
|
if (this.assets.regions === "none") {
|
|
11275
11314
|
throw new Error(
|
|
11276
|
-
"these assets were loaded with regions: 'none' (no region bitmaps, for the canvas mode only); the DOM mode needs a load with regions 'blob' or 'data'"
|
|
11315
|
+
"these assets were loaded with regions: 'none' (no region bitmaps, for the canvas mode only); the DOM mode needs a load with regions 'atlas', 'blob' or 'data'"
|
|
11277
11316
|
);
|
|
11278
11317
|
}
|
|
11279
|
-
const renderer = new DomRenderer(this.root, this.assets.regionImages, this.assets.pageImages);
|
|
11318
|
+
const renderer = new DomRenderer(this.root, this.assets.regionImages, this.assets.pageImages, this.assets.atlasRegions);
|
|
11280
11319
|
if (this.meshBackend) renderer.meshBackend = this.meshBackend;
|
|
11281
11320
|
return renderer;
|
|
11282
11321
|
}
|
|
@@ -12741,6 +12780,7 @@ export {
|
|
|
12741
12780
|
CanvasRenderer,
|
|
12742
12781
|
DomRenderer,
|
|
12743
12782
|
RigPlayer,
|
|
12783
|
+
createAtlasRegions,
|
|
12744
12784
|
loadModel,
|
|
12745
12785
|
readSetupMesh,
|
|
12746
12786
|
revokeRegions,
|