@codexo/exojs 0.12.0 → 0.13.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/CHANGELOG.md +125 -0
- package/dist/esm/core/BuildInfo.js +2 -2
- package/dist/esm/extensions/Extension.d.ts +39 -7
- package/dist/esm/extensions/Extension.d.ts.map +1 -1
- package/dist/esm/extensions/ExtensionRegistry.d.ts.map +1 -1
- package/dist/esm/extensions/ExtensionRegistry.js.map +1 -1
- package/dist/esm/extensions/snapshot.d.ts +12 -2
- package/dist/esm/extensions/snapshot.d.ts.map +1 -1
- package/dist/esm/extensions/snapshot.js +43 -14
- package/dist/esm/extensions/snapshot.js.map +1 -1
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/rendering/Drawable.d.ts +23 -0
- package/dist/esm/rendering/Drawable.d.ts.map +1 -1
- package/dist/esm/rendering/Drawable.js +34 -0
- package/dist/esm/rendering/Drawable.js.map +1 -1
- package/dist/esm/rendering/coreRendererBindings.d.ts.map +1 -1
- package/dist/esm/rendering/coreRendererBindings.js +22 -0
- package/dist/esm/rendering/coreRendererBindings.js.map +1 -1
- package/dist/esm/rendering/index.d.ts +13 -0
- package/dist/esm/rendering/index.d.ts.map +1 -1
- package/dist/esm/rendering/pixelSnap.d.ts +219 -0
- package/dist/esm/rendering/pixelSnap.d.ts.map +1 -0
- package/dist/esm/rendering/pixelSnap.js +186 -0
- package/dist/esm/rendering/pixelSnap.js.map +1 -0
- package/dist/esm/rendering/plan/RenderPlanPlayer.d.ts.map +1 -1
- package/dist/esm/rendering/plan/RenderPlanPlayer.js +21 -1
- package/dist/esm/rendering/plan/RenderPlanPlayer.js.map +1 -1
- package/dist/esm/rendering/sprite/NineSliceSprite.d.ts +69 -0
- package/dist/esm/rendering/sprite/NineSliceSprite.d.ts.map +1 -0
- package/dist/esm/rendering/sprite/NineSliceSprite.js +207 -0
- package/dist/esm/rendering/sprite/NineSliceSprite.js.map +1 -0
- package/dist/esm/rendering/sprite/RepeatingSprite.d.ts +120 -0
- package/dist/esm/rendering/sprite/RepeatingSprite.d.ts.map +1 -0
- package/dist/esm/rendering/sprite/RepeatingSprite.js +279 -0
- package/dist/esm/rendering/sprite/RepeatingSprite.js.map +1 -0
- package/dist/esm/rendering/sprite/Sprite.d.ts +13 -0
- package/dist/esm/rendering/sprite/Sprite.d.ts.map +1 -1
- package/dist/esm/rendering/sprite/Sprite.js +23 -0
- package/dist/esm/rendering/sprite/Sprite.js.map +1 -1
- package/dist/esm/rendering/sprite/nineSlice.d.ts +53 -0
- package/dist/esm/rendering/sprite/nineSlice.d.ts.map +1 -0
- package/dist/esm/rendering/sprite/nineSlice.js +340 -0
- package/dist/esm/rendering/sprite/nineSlice.js.map +1 -0
- package/dist/esm/rendering/sprite/repeatingSpritePlan.d.ts +57 -0
- package/dist/esm/rendering/sprite/repeatingSpritePlan.d.ts.map +1 -0
- package/dist/esm/rendering/sprite/repeatingSpritePlan.js +156 -0
- package/dist/esm/rendering/sprite/repeatingSpritePlan.js.map +1 -0
- package/dist/esm/rendering/texture/TextureRegion.d.ts +100 -0
- package/dist/esm/rendering/texture/TextureRegion.d.ts.map +1 -0
- package/dist/esm/rendering/texture/TextureRegion.js +144 -0
- package/dist/esm/rendering/texture/TextureRegion.js.map +1 -0
- package/dist/esm/rendering/texture/repeat.d.ts +96 -0
- package/dist/esm/rendering/texture/repeat.d.ts.map +1 -0
- package/dist/esm/rendering/texture/repeat.js +158 -0
- package/dist/esm/rendering/texture/repeat.js.map +1 -0
- package/dist/esm/rendering/webgl2/WebGl2Backend.d.ts +20 -0
- package/dist/esm/rendering/webgl2/WebGl2Backend.d.ts.map +1 -1
- package/dist/esm/rendering/webgl2/WebGl2Backend.js +31 -2
- package/dist/esm/rendering/webgl2/WebGl2Backend.js.map +1 -1
- package/dist/esm/rendering/webgl2/WebGl2NineSliceSpriteRenderer.d.ts +32 -0
- package/dist/esm/rendering/webgl2/WebGl2NineSliceSpriteRenderer.d.ts.map +1 -0
- package/dist/esm/rendering/webgl2/WebGl2NineSliceSpriteRenderer.js +308 -0
- package/dist/esm/rendering/webgl2/WebGl2NineSliceSpriteRenderer.js.map +1 -0
- package/dist/esm/rendering/webgl2/WebGl2RepeatingSpriteRenderer.d.ts +49 -0
- package/dist/esm/rendering/webgl2/WebGl2RepeatingSpriteRenderer.d.ts.map +1 -0
- package/dist/esm/rendering/webgl2/WebGl2RepeatingSpriteRenderer.js +535 -0
- package/dist/esm/rendering/webgl2/WebGl2RepeatingSpriteRenderer.js.map +1 -0
- package/dist/esm/rendering/webgl2/WebGl2SpriteRenderer.d.ts +9 -0
- package/dist/esm/rendering/webgl2/WebGl2SpriteRenderer.d.ts.map +1 -1
- package/dist/esm/rendering/webgl2/WebGl2SpriteRenderer.js +22 -2
- package/dist/esm/rendering/webgl2/WebGl2SpriteRenderer.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuBackend.d.ts +21 -1
- package/dist/esm/rendering/webgpu/WebGpuBackend.d.ts.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuBackend.js +29 -2
- package/dist/esm/rendering/webgpu/WebGpuBackend.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuNineSliceSpriteRenderer.d.ts +36 -0
- package/dist/esm/rendering/webgpu/WebGpuNineSliceSpriteRenderer.d.ts.map +1 -0
- package/dist/esm/rendering/webgpu/WebGpuNineSliceSpriteRenderer.js +358 -0
- package/dist/esm/rendering/webgpu/WebGpuNineSliceSpriteRenderer.js.map +1 -0
- package/dist/esm/rendering/webgpu/WebGpuRepeatingSpriteRenderer.d.ts +52 -0
- package/dist/esm/rendering/webgpu/WebGpuRepeatingSpriteRenderer.d.ts.map +1 -0
- package/dist/esm/rendering/webgpu/WebGpuRepeatingSpriteRenderer.js +556 -0
- package/dist/esm/rendering/webgpu/WebGpuRepeatingSpriteRenderer.js.map +1 -0
- package/dist/esm/rendering/webgpu/WebGpuSpriteRenderer.d.ts +9 -0
- package/dist/esm/rendering/webgpu/WebGpuSpriteRenderer.d.ts.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuSpriteRenderer.js +22 -2
- package/dist/esm/rendering/webgpu/WebGpuSpriteRenderer.js.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuTransformStorage.d.ts +3 -2
- package/dist/esm/rendering/webgpu/WebGpuTransformStorage.d.ts.map +1 -1
- package/dist/esm/rendering/webgpu/WebGpuTransformStorage.js +4 -4
- package/dist/esm/rendering/webgpu/WebGpuTransformStorage.js.map +1 -1
- package/dist/esm/rendering.d.ts +1 -0
- package/dist/esm/rendering.d.ts.map +1 -1
- package/dist/esm/resources/Loader.d.ts +36 -8
- package/dist/esm/resources/Loader.d.ts.map +1 -1
- package/dist/esm/resources/Loader.js +30 -11
- package/dist/esm/resources/Loader.js.map +1 -1
- package/dist/exo.esm.js +3449 -59
- package/dist/exo.esm.js.map +1 -1
- package/package.json +10 -3
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { planRepeat } from '../texture/repeat.js';
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Validation
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
const validRepeatModes = new Set(['stretch', 'repeat', 'mirror-repeat']);
|
|
7
|
+
const validRepeatFits = new Set(['clip', 'round']);
|
|
8
|
+
function validateSizeInput(width, height) {
|
|
9
|
+
if (!Number.isFinite(width) || !Number.isFinite(height)) {
|
|
10
|
+
throw new Error(`RepeatingSprite: width and height must be finite numbers (got ${width}, ${height}).`);
|
|
11
|
+
}
|
|
12
|
+
if (width < 0) {
|
|
13
|
+
throw new Error(`RepeatingSprite: width must be non-negative (got ${width}).`);
|
|
14
|
+
}
|
|
15
|
+
if (height < 0) {
|
|
16
|
+
throw new Error(`RepeatingSprite: height must be non-negative (got ${height}).`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function validateMode(mode, label) {
|
|
20
|
+
if (typeof mode !== 'string' || !validRepeatModes.has(mode)) {
|
|
21
|
+
throw new Error(`RepeatingSprite: ${label} must be "stretch", "repeat", or "mirror-repeat" (got ${String(mode)}).`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function validateFit(fit, label) {
|
|
25
|
+
if (typeof fit !== 'string' || !validRepeatFits.has(fit)) {
|
|
26
|
+
throw new Error(`RepeatingSprite: ${label} must be "clip" or "round" (got ${String(fit)}).`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function validateOffset(value, label) {
|
|
30
|
+
if (!Number.isFinite(value)) {
|
|
31
|
+
throw new Error(`RepeatingSprite: ${label} must be a finite number (got ${value}).`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Shader-path tiling helpers
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
/**
|
|
38
|
+
* Compute the UV tiling scale for the standalone shader path.
|
|
39
|
+
*
|
|
40
|
+
* Returns how many times the source repeats across the destination span.
|
|
41
|
+
* - `stretch`: always 1.0
|
|
42
|
+
* - `repeat`/`mirror-repeat` + `round`: nearest integer count (≥ 1)
|
|
43
|
+
* - `repeat`/`mirror-repeat` + `clip`: exact fraction `destLen / srcLen`
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
function computeShaderTiling(srcLen, destLen, mode, fit) {
|
|
47
|
+
if (mode === 'stretch' || srcLen <= 0 || destLen <= 0) {
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
if (fit === 'round') {
|
|
51
|
+
return Math.max(1, Math.round(destLen / srcLen));
|
|
52
|
+
}
|
|
53
|
+
return destLen / srcLen;
|
|
54
|
+
}
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Geometry-path quad builder
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
const halfTexelInset = 0.5;
|
|
59
|
+
/**
|
|
60
|
+
* Build the geometry quads for the atlas-region repeat path.
|
|
61
|
+
*
|
|
62
|
+
* Runs {@link planRepeat} independently on both X and Y axes with optional
|
|
63
|
+
* phase offsets, then generates the Cartesian-product quad list. Each quad
|
|
64
|
+
* carries UV coordinates clamped inside the region's UV bounds, with
|
|
65
|
+
* extrusion-aware outer insets.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
function buildRepeatingSpriteQuads(region, width, height, modeX, modeY, fitX, fitY, offsetX, offsetY) {
|
|
69
|
+
if (width === 0 || height === 0 || region.width <= 0 || region.height <= 0) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const tw = region.texture.width;
|
|
73
|
+
const th = region.texture.height;
|
|
74
|
+
const ext = region.extrusion;
|
|
75
|
+
const outerInsetU = (ext.left > 0 || ext.right > 0) ? 0 : halfTexelInset / tw;
|
|
76
|
+
const outerInsetV = (ext.top > 0 || ext.bottom > 0) ? 0 : halfTexelInset / th;
|
|
77
|
+
const uMin = region.u0 + outerInsetU;
|
|
78
|
+
const uMax = region.u1 - outerInsetU;
|
|
79
|
+
const vMin = region.v0 + outerInsetV;
|
|
80
|
+
const vMax = region.v1 - outerInsetV;
|
|
81
|
+
const srcW = region.width;
|
|
82
|
+
const srcH = region.height;
|
|
83
|
+
const uRange = uMax - uMin;
|
|
84
|
+
const vRange = vMax - vMin;
|
|
85
|
+
const segsX = buildAxisSegmentsWithOffset(srcW, width, modeX, fitX, offsetX);
|
|
86
|
+
const segsY = buildAxisSegmentsWithOffset(srcH, height, modeY, fitY, offsetY);
|
|
87
|
+
const quads = [];
|
|
88
|
+
for (const sy of segsY) {
|
|
89
|
+
const qy0 = sy.destinationStart;
|
|
90
|
+
const qy1 = sy.destinationStart + sy.destinationLength;
|
|
91
|
+
const qv0 = vMin + sy.sourceStart * vRange;
|
|
92
|
+
const qv1 = vMin + sy.sourceEnd * vRange;
|
|
93
|
+
for (const sx of segsX) {
|
|
94
|
+
const qx0 = sx.destinationStart;
|
|
95
|
+
const qx1 = sx.destinationStart + sx.destinationLength;
|
|
96
|
+
const qu0 = uMin + sx.sourceStart * uRange;
|
|
97
|
+
const qu1 = uMin + sx.sourceEnd * uRange;
|
|
98
|
+
quads.push({ x0: qx0, y0: qy0, x1: qx1, y1: qy1, u0: qu0, v0: qv0, u1: qu1, v1: qv1 });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return quads;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Build repeat segments for one axis with an optional phase offset.
|
|
105
|
+
*
|
|
106
|
+
* The offset shifts the starting phase of the repeat in source-pixel units.
|
|
107
|
+
* For `stretch` mode the offset is silently ignored.
|
|
108
|
+
*
|
|
109
|
+
* Implementation: generates a plan for `(destLen + phase)`, shifts all
|
|
110
|
+
* segment destinations back by `phase`, and clips to `[0, destLen]`. This
|
|
111
|
+
* is correct for `clip` fit; for `round` fit the extended-span count may
|
|
112
|
+
* differ slightly from the zero-offset count — atlas scrolling is
|
|
113
|
+
* discouraged by design.
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
function buildAxisSegmentsWithOffset(srcLen, destLen, mode, fit, offset) {
|
|
117
|
+
if (destLen === 0 || srcLen <= 0) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
if (mode === 'stretch') {
|
|
121
|
+
return [...planRepeat(srcLen, destLen, mode, fit).segments];
|
|
122
|
+
}
|
|
123
|
+
const phase = ((offset % srcLen) + srcLen) % srcLen;
|
|
124
|
+
if (phase === 0) {
|
|
125
|
+
return [...planRepeat(srcLen, destLen, mode, fit).segments];
|
|
126
|
+
}
|
|
127
|
+
const extendedPlan = planRepeat(srcLen, destLen + phase, mode, fit);
|
|
128
|
+
const result = [];
|
|
129
|
+
for (const seg of extendedPlan.segments) {
|
|
130
|
+
const dStart = seg.destinationStart - phase;
|
|
131
|
+
const dEnd = dStart + seg.destinationLength;
|
|
132
|
+
if (dEnd <= 0 || dStart >= destLen) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const clippedStart = Math.max(0, dStart);
|
|
136
|
+
const clippedEnd = Math.min(destLen, dEnd);
|
|
137
|
+
const clippedLen = clippedEnd - clippedStart;
|
|
138
|
+
if (clippedLen <= 0) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const t0 = (clippedStart - dStart) / seg.destinationLength;
|
|
142
|
+
const t1 = (clippedEnd - dStart) / seg.destinationLength;
|
|
143
|
+
const srcRange = seg.sourceEnd - seg.sourceStart;
|
|
144
|
+
result.push({
|
|
145
|
+
destinationStart: clippedStart,
|
|
146
|
+
destinationLength: clippedLen,
|
|
147
|
+
sourceStart: seg.sourceStart + t0 * srcRange,
|
|
148
|
+
sourceEnd: seg.sourceStart + t1 * srcRange,
|
|
149
|
+
mirrored: seg.mirrored,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export { buildRepeatingSpriteQuads, computeShaderTiling, validateFit, validateMode, validateOffset, validateSizeInput };
|
|
156
|
+
//# sourceMappingURL=repeatingSpritePlan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repeatingSpritePlan.js","sources":["../../../../../src/rendering/sprite/repeatingSpritePlan.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAoCA;AACA;AACA;AAEA,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;AAChF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,SAAU,iBAAiB,CAAC,KAAa,EAAE,MAAc,EAAA;AAC7D,IAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACvD,MAAM,IAAI,KAAK,CACb,CAAA,8DAAA,EAAiE,KAAK,CAAA,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MAAM,CAAC;QACxC,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC;AAC1C,QAAA,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY;AAE5C,QAAA,IAAI,UAAU,IAAI,CAAC,EAAE;YACnB;QACF;QAEA,MAAM,EAAE,GAAG,CAAC,YAAY,GAAG,MAAM,IAAI,GAAG,CAAC,iBAAiB;QAC1D,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,MAAM,IAAI,GAAG,CAAC,iBAAiB;QACxD,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC,WAAW;QAEhD,MAAM,CAAC,IAAI,CAAC;AACV,YAAA,gBAAgB,EAAE,YAAY;AAC9B,YAAA,iBAAiB,EAAE,UAAU;AAC7B,YAAA,WAAW,EAAE,GAAG,CAAC,WAAW,GAAG,EAAE,GAAG,QAAQ;AAC5C,YAAA,SAAS,EAAE,GAAG,CAAC,WAAW,GAAG,EAAE,GAAG,QAAQ;YAC1C,QAAQ,EAAE,GAAG,CAAC,QAAQ;AACvB,SAAA,CAAC;IACJ;AAEA,IAAA,OAAO,MAAM;AACf;;;;"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Texture } from './Texture';
|
|
2
|
+
/**
|
|
3
|
+
* Per-edge extrusion/padding metadata for a {@link TextureRegion}.
|
|
4
|
+
*
|
|
5
|
+
* Describes the number of duplicated/extruded source texels available outside
|
|
6
|
+
* each logical edge so that linear filtering can sample safely without
|
|
7
|
+
* bleeding from neighbouring atlas regions.
|
|
8
|
+
* @stable
|
|
9
|
+
*/
|
|
10
|
+
export interface TextureRegionInsets {
|
|
11
|
+
/** Extrusion texels on the left edge (outside `x`). */
|
|
12
|
+
readonly left: number;
|
|
13
|
+
/** Extrusion texels on the top edge (outside `y`). */
|
|
14
|
+
readonly top: number;
|
|
15
|
+
/** Extrusion texels on the right edge (outside `x + width`). */
|
|
16
|
+
readonly right: number;
|
|
17
|
+
/** Extrusion texels on the bottom edge (outside `y + height`). */
|
|
18
|
+
readonly bottom: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Options passed to the {@link TextureRegion} constructor.
|
|
22
|
+
* @stable
|
|
23
|
+
*/
|
|
24
|
+
export interface TextureRegionOptions {
|
|
25
|
+
/** Left pixel coordinate of the region within the texture. */
|
|
26
|
+
readonly x: number;
|
|
27
|
+
/** Top pixel coordinate of the region within the texture. */
|
|
28
|
+
readonly y: number;
|
|
29
|
+
/** Width of the region in texture pixels. */
|
|
30
|
+
readonly width: number;
|
|
31
|
+
/** Height of the region in texture pixels. */
|
|
32
|
+
readonly height: number;
|
|
33
|
+
/**
|
|
34
|
+
* Number of duplicated/extruded source texels available outside each
|
|
35
|
+
* logical edge for safe linear filtering.
|
|
36
|
+
*
|
|
37
|
+
* A uniform `number` sets all four sides equally. Provide a
|
|
38
|
+
* {@link TextureRegionInsets} for per-side control.
|
|
39
|
+
*
|
|
40
|
+
* Defaults to `{ left: 0, top: 0, right: 0, bottom: 0 }`.
|
|
41
|
+
*/
|
|
42
|
+
readonly extrusion?: number | TextureRegionInsets;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* An immutable descriptor for a rectangular sub-region of a {@link Texture}.
|
|
46
|
+
*
|
|
47
|
+
* Stores the pixel-space source rectangle, pre-computed normalised UV bounds,
|
|
48
|
+
* and optional extrusion/padding metadata for atlas-safe linear filtering.
|
|
49
|
+
* Constructed once and reused across sprites, tile-sets, atlas lookups, and
|
|
50
|
+
* the scalable-sprite repeat planners.
|
|
51
|
+
*
|
|
52
|
+
* All region descriptor fields are stable after construction. Extrusion
|
|
53
|
+
* metadata is copied and frozen during construction — the caller retains no
|
|
54
|
+
* mutable reference to the stored object. The underlying {@link Texture}
|
|
55
|
+
* reference is stable, but the Texture's own lifecycle and sampler state
|
|
56
|
+
* remain owned by {@link Texture}.
|
|
57
|
+
*
|
|
58
|
+
* Texture dimensions **must** be known at construction time; a texture with
|
|
59
|
+
* zero dimensions will cause the constructor to throw.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const region = new TextureRegion(texture, {
|
|
64
|
+
* x: 32, y: 16,
|
|
65
|
+
* width: 64, height: 32,
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
* @stable
|
|
69
|
+
*/
|
|
70
|
+
export declare class TextureRegion {
|
|
71
|
+
/** The underlying {@link Texture} this region belongs to. */
|
|
72
|
+
readonly texture: Texture;
|
|
73
|
+
/** Left edge of the region in texture pixels. */
|
|
74
|
+
readonly x: number;
|
|
75
|
+
/** Top edge of the region in texture pixels. */
|
|
76
|
+
readonly y: number;
|
|
77
|
+
/** Width of the region in texture pixels. */
|
|
78
|
+
readonly width: number;
|
|
79
|
+
/** Height of the region in texture pixels. */
|
|
80
|
+
readonly height: number;
|
|
81
|
+
/** Normalised left texture coordinate (U-min). */
|
|
82
|
+
readonly u0: number;
|
|
83
|
+
/** Normalised top texture coordinate (V-min). */
|
|
84
|
+
readonly v0: number;
|
|
85
|
+
/** Normalised right texture coordinate (U-max). */
|
|
86
|
+
readonly u1: number;
|
|
87
|
+
/** Normalised bottom texture coordinate (V-max). */
|
|
88
|
+
readonly v1: number;
|
|
89
|
+
/** Per-edge extrusion/padding metadata (engine-owned, frozen). */
|
|
90
|
+
readonly extrusion: Readonly<TextureRegionInsets>;
|
|
91
|
+
/**
|
|
92
|
+
* Create a new immutable region.
|
|
93
|
+
*
|
|
94
|
+
* @throws When coordinates or dimensions are non-finite, zero, negative, or
|
|
95
|
+
* extend beyond the texture bounds, or when extrusion values are
|
|
96
|
+
* invalid.
|
|
97
|
+
*/
|
|
98
|
+
constructor(texture: Texture, options: TextureRegionOptions);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=TextureRegion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextureRegion.d.ts","sourceRoot":"","sources":["../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3B,oDAAoD;IACpD,SAAgB,EAAE,EAAE,MAAM,CAAC;IAE3B,kEAAkE;IAClE,SAAgB,SAAS,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IAEzD;;;;;;OAMG;gBACgB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB;CA+BnE"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
function isFinite(value) {
|
|
2
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
3
|
+
}
|
|
4
|
+
function normalizeExtrusion(extrusion) {
|
|
5
|
+
if (extrusion === undefined) {
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
left: 0,
|
|
8
|
+
top: 0,
|
|
9
|
+
right: 0,
|
|
10
|
+
bottom: 0,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (typeof extrusion === 'number') {
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
left: extrusion,
|
|
16
|
+
top: extrusion,
|
|
17
|
+
right: extrusion,
|
|
18
|
+
bottom: extrusion,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// Copy caller-owned values into an engine-owned frozen object so that
|
|
22
|
+
// external mutation of the original never affects the region.
|
|
23
|
+
return Object.freeze({
|
|
24
|
+
left: extrusion.left,
|
|
25
|
+
top: extrusion.top,
|
|
26
|
+
right: extrusion.right,
|
|
27
|
+
bottom: extrusion.bottom,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function validateExtrusion(extrusion, x, y, width, height, textureWidth, textureHeight) {
|
|
31
|
+
const { left, top, right, bottom } = extrusion;
|
|
32
|
+
if (!isFinite(left) || !isFinite(top) || !isFinite(right) || !isFinite(bottom)) {
|
|
33
|
+
throw new Error(`TextureRegion extrusion values must be finite numbers (got left=${left}, top=${top}, right=${right}, bottom=${bottom}).`);
|
|
34
|
+
}
|
|
35
|
+
if (left < 0 || top < 0 || right < 0 || bottom < 0) {
|
|
36
|
+
throw new Error(`TextureRegion extrusion values must be non-negative (got left=${left}, top=${top}, right=${right}, bottom=${bottom}).`);
|
|
37
|
+
}
|
|
38
|
+
if (left > x || top > y || right > textureWidth - (x + width) || bottom > textureHeight - (y + height)) {
|
|
39
|
+
throw new Error(`TextureRegion extrusion exceeds available source texture bounds: left=${left} (>${x}), top=${top} (>${y}), ` +
|
|
40
|
+
`right=${right} (>${textureWidth - (x + width)}), bottom=${bottom} (>${textureHeight - (y + height)}).`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function validateOptions(options, textureWidth, textureHeight) {
|
|
44
|
+
const { x, y, width, height } = options;
|
|
45
|
+
if (!isFinite(x) || !isFinite(y) || !isFinite(width) || !isFinite(height)) {
|
|
46
|
+
throw new Error(`TextureRegion coordinates and dimensions must be finite numbers (got x=${x}, y=${y}, width=${width}, height=${height}).`);
|
|
47
|
+
}
|
|
48
|
+
if (width <= 0 || height <= 0) {
|
|
49
|
+
throw new Error(`TextureRegion dimensions must be positive (got width=${width}, height=${height}).`);
|
|
50
|
+
}
|
|
51
|
+
if (textureWidth <= 0 || textureHeight <= 0) {
|
|
52
|
+
throw new Error(`Texture must have positive dimensions (got ${textureWidth}x${textureHeight}).`);
|
|
53
|
+
}
|
|
54
|
+
if (x < 0 || y < 0) {
|
|
55
|
+
throw new Error(`TextureRegion origin must be non-negative (got x=${x}, y=${y}).`);
|
|
56
|
+
}
|
|
57
|
+
if (x >= textureWidth || y >= textureHeight) {
|
|
58
|
+
throw new Error(`TextureRegion origin (${x}, ${y}) is outside texture bounds (${textureWidth}x${textureHeight}).`);
|
|
59
|
+
}
|
|
60
|
+
if (x + width > textureWidth) {
|
|
61
|
+
throw new Error(`TextureRegion right edge (${x + width}) exceeds texture width (${textureWidth}).`);
|
|
62
|
+
}
|
|
63
|
+
if (y + height > textureHeight) {
|
|
64
|
+
throw new Error(`TextureRegion bottom edge (${y + height}) exceeds texture height (${textureHeight}).`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* An immutable descriptor for a rectangular sub-region of a {@link Texture}.
|
|
69
|
+
*
|
|
70
|
+
* Stores the pixel-space source rectangle, pre-computed normalised UV bounds,
|
|
71
|
+
* and optional extrusion/padding metadata for atlas-safe linear filtering.
|
|
72
|
+
* Constructed once and reused across sprites, tile-sets, atlas lookups, and
|
|
73
|
+
* the scalable-sprite repeat planners.
|
|
74
|
+
*
|
|
75
|
+
* All region descriptor fields are stable after construction. Extrusion
|
|
76
|
+
* metadata is copied and frozen during construction — the caller retains no
|
|
77
|
+
* mutable reference to the stored object. The underlying {@link Texture}
|
|
78
|
+
* reference is stable, but the Texture's own lifecycle and sampler state
|
|
79
|
+
* remain owned by {@link Texture}.
|
|
80
|
+
*
|
|
81
|
+
* Texture dimensions **must** be known at construction time; a texture with
|
|
82
|
+
* zero dimensions will cause the constructor to throw.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const region = new TextureRegion(texture, {
|
|
87
|
+
* x: 32, y: 16,
|
|
88
|
+
* width: 64, height: 32,
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
* @stable
|
|
92
|
+
*/
|
|
93
|
+
class TextureRegion {
|
|
94
|
+
/** The underlying {@link Texture} this region belongs to. */
|
|
95
|
+
texture;
|
|
96
|
+
/** Left edge of the region in texture pixels. */
|
|
97
|
+
x;
|
|
98
|
+
/** Top edge of the region in texture pixels. */
|
|
99
|
+
y;
|
|
100
|
+
/** Width of the region in texture pixels. */
|
|
101
|
+
width;
|
|
102
|
+
/** Height of the region in texture pixels. */
|
|
103
|
+
height;
|
|
104
|
+
/** Normalised left texture coordinate (U-min). */
|
|
105
|
+
u0;
|
|
106
|
+
/** Normalised top texture coordinate (V-min). */
|
|
107
|
+
v0;
|
|
108
|
+
/** Normalised right texture coordinate (U-max). */
|
|
109
|
+
u1;
|
|
110
|
+
/** Normalised bottom texture coordinate (V-max). */
|
|
111
|
+
v1;
|
|
112
|
+
/** Per-edge extrusion/padding metadata (engine-owned, frozen). */
|
|
113
|
+
extrusion;
|
|
114
|
+
/**
|
|
115
|
+
* Create a new immutable region.
|
|
116
|
+
*
|
|
117
|
+
* @throws When coordinates or dimensions are non-finite, zero, negative, or
|
|
118
|
+
* extend beyond the texture bounds, or when extrusion values are
|
|
119
|
+
* invalid.
|
|
120
|
+
*/
|
|
121
|
+
constructor(texture, options) {
|
|
122
|
+
if (!texture) {
|
|
123
|
+
throw new Error('TextureRegion requires a non-null Texture.');
|
|
124
|
+
}
|
|
125
|
+
const textureWidth = texture.width;
|
|
126
|
+
const textureHeight = texture.height;
|
|
127
|
+
validateOptions(options, textureWidth, textureHeight);
|
|
128
|
+
const extrusion = normalizeExtrusion(options.extrusion);
|
|
129
|
+
validateExtrusion(extrusion, options.x, options.y, options.width, options.height, textureWidth, textureHeight);
|
|
130
|
+
this.texture = texture;
|
|
131
|
+
this.x = options.x;
|
|
132
|
+
this.y = options.y;
|
|
133
|
+
this.width = options.width;
|
|
134
|
+
this.height = options.height;
|
|
135
|
+
this.u0 = options.x / textureWidth;
|
|
136
|
+
this.v0 = options.y / textureHeight;
|
|
137
|
+
this.u1 = (options.x + options.width) / textureWidth;
|
|
138
|
+
this.v1 = (options.y + options.height) / textureHeight;
|
|
139
|
+
this.extrusion = extrusion;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { TextureRegion };
|
|
144
|
+
//# sourceMappingURL=TextureRegion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextureRegion.js","sources":["../../../../../src/rendering/texture/TextureRegion.ts"],"sourcesContent":[null],"names":[],"mappings":"AA+CA,SAAS,QAAQ,CAAC,KAAa,EAAA;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;AAC5D;AAEA,SAAS,kBAAkB,CAAC,SAAmD,EAAA;AAC7E,IAAA,IAAI,SAAS,KAAK,SAAS,EAAE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@@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a scalable sprite fills its destination span.
|
|
3
|
+
*
|
|
4
|
+
* Shared by {@link NineSliceSprite} edges/center and {@link RepeatingSprite}.
|
|
5
|
+
* @stable
|
|
6
|
+
*/
|
|
7
|
+
export type RepeatMode = 'stretch' | 'repeat' | 'mirror-repeat';
|
|
8
|
+
/**
|
|
9
|
+
* How a `'repeat'` or `'mirror-repeat'` run fits its destination span exactly.
|
|
10
|
+
* @stable
|
|
11
|
+
*/
|
|
12
|
+
export type RepeatFit = 'clip' | 'round';
|
|
13
|
+
/**
|
|
14
|
+
* A single placement segment produced by the repeat planner.
|
|
15
|
+
*
|
|
16
|
+
* Each segment describes one contiguous destination slice and the corresponding
|
|
17
|
+
* normalised source texel interval.
|
|
18
|
+
* @advanced
|
|
19
|
+
*/
|
|
20
|
+
export interface RepeatSegment {
|
|
21
|
+
/** Start position of this segment within the destination span. */
|
|
22
|
+
readonly destinationStart: number;
|
|
23
|
+
/** Length of this segment in destination units. */
|
|
24
|
+
readonly destinationLength: number;
|
|
25
|
+
/**
|
|
26
|
+
* Normalised source start coordinate (0..1 range in logical source space).
|
|
27
|
+
* For mirrored segments this is greater than {@link sourceEnd}.
|
|
28
|
+
*/
|
|
29
|
+
readonly sourceStart: number;
|
|
30
|
+
/**
|
|
31
|
+
* Normalised source end coordinate (0..1 range in logical source space).
|
|
32
|
+
* For mirrored segments this is less than {@link sourceStart}.
|
|
33
|
+
*/
|
|
34
|
+
readonly sourceEnd: number;
|
|
35
|
+
/**
|
|
36
|
+
* `true` when this segment should be rendered with mirrored (flipped)
|
|
37
|
+
* orientation. Always consistent with `sourceStart > sourceEnd`.
|
|
38
|
+
*/
|
|
39
|
+
readonly mirrored: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Result of a repeat-planning call.
|
|
43
|
+
*
|
|
44
|
+
* Contains the resolved destination length and the ordered list of segments
|
|
45
|
+
* that collectively fill the span.
|
|
46
|
+
* @advanced
|
|
47
|
+
*/
|
|
48
|
+
export interface RepeatPlan {
|
|
49
|
+
/** Total destination span length (equal to the requested length). */
|
|
50
|
+
readonly destinationLength: number;
|
|
51
|
+
/**
|
|
52
|
+
* The source length that was passed to the planner.
|
|
53
|
+
* Useful for consumers that need to map back to source scale.
|
|
54
|
+
*/
|
|
55
|
+
readonly sourceLength: number;
|
|
56
|
+
/** Ordered, non-overlapping segments that fill the destination span. */
|
|
57
|
+
readonly segments: readonly RepeatSegment[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Compute a deterministic repeat plan for filling a destination span with a
|
|
61
|
+
* tiled or stretched source pattern.
|
|
62
|
+
*
|
|
63
|
+
* This is a **pure, renderer-independent** function used as the shared repeat
|
|
64
|
+
* layout engine by {@link NineSliceSprite} edges/center,
|
|
65
|
+
* {@link RepeatingSprite} geometry path, and tilemap chunk builders.
|
|
66
|
+
*
|
|
67
|
+
* ## Modes
|
|
68
|
+
*
|
|
69
|
+
* | Mode | Behaviour |
|
|
70
|
+
* |------------------|-----------|
|
|
71
|
+
* | `'stretch'` | One segment stretched to the full destination. `fit` is ignored. |
|
|
72
|
+
* | `'repeat'` | Native-size repeats; final segment is clipped when the destination is not an exact multiple. |
|
|
73
|
+
* | `'mirror-repeat'`| Alternating normal/mirrored segments (period-2). Clipped final segment when non-exact. |
|
|
74
|
+
*
|
|
75
|
+
* ## Fit
|
|
76
|
+
*
|
|
77
|
+
* | Fit | Effect |
|
|
78
|
+
* |----------|--------|
|
|
79
|
+
* | `'clip'` | Native-size segments; the final segment is clipped if necessary. |
|
|
80
|
+
* | `'round'`| Integer count of equally-sized segments stretched or squeezed so the destination fills exactly. |
|
|
81
|
+
*
|
|
82
|
+
* ## Allocation and caching
|
|
83
|
+
*
|
|
84
|
+
* The planner returns a new result object on every call. Callers should
|
|
85
|
+
* cache the plan and recompute only when `sourceLength`, `destinationLength`,
|
|
86
|
+
* `mode`, or `fit` changes — typically on resize or texture change.
|
|
87
|
+
*
|
|
88
|
+
* @param sourceLength - Native size of the source pattern in destination units.
|
|
89
|
+
* @param destinationLength - Total span to fill.
|
|
90
|
+
* @param mode - Fill strategy.
|
|
91
|
+
* @param fit - Fitting strategy for `'repeat'` / `'mirror-repeat'`. Ignored for `'stretch'`.
|
|
92
|
+
* @throws When inputs are non-finite, negative, or zero-length source.
|
|
93
|
+
* @advanced
|
|
94
|
+
*/
|
|
95
|
+
export declare function planRepeat(sourceLength: number, destinationLength: number, mode: RepeatMode, fit?: RepeatFit): RepeatPlan;
|
|
96
|
+
//# sourceMappingURL=repeat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../../../src/rendering/texture/repeat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,QAAQ,GACR,eAAe,CAAC;AAEpB;;;GAGG;AACH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,OAAO,CAAC;AAEZ;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,mDAAmD;IACnD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEnC;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,qEAAqE;IACrE,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;CAC7C;AA+HD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,UAAU,CACxB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,UAAU,EAChB,GAAG,GAAE,SAAmB,GACvB,UAAU,CA2BZ"}
|