@flighthq/texture 0.2.1-next.410.a23f189 → 0.2.1-next.444.a313478
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/texture.d.ts +1 -0
- package/dist/texture.d.ts.map +1 -1
- package/dist/texture.js +40 -9
- package/dist/texture.js.map +1 -1
- package/dist/videoTexture.d.ts.map +1 -1
- package/dist/videoTexture.js +14 -20
- package/dist/videoTexture.js.map +1 -1
- package/package.json +4 -4
- package/src/texture.test.ts +57 -0
package/dist/texture.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare function getTextureWidth(texture: Readonly<TextureLike>): number;
|
|
|
10
10
|
export declare function hasTextureUvTransform(texture: Readonly<TextureUvTransform>): boolean;
|
|
11
11
|
export declare function isTextureReady(texture: Readonly<TextureLike>): boolean;
|
|
12
12
|
export declare function resetTextureUvTransform(texture: TextureLike): void;
|
|
13
|
+
export declare function setTextureFlip(texture: TextureLike, flipX: boolean, flipY: boolean): void;
|
|
13
14
|
export declare function setTextureImage(texture: TextureLike, image: ImageResource | null): void;
|
|
14
15
|
export declare function setTextureUvOffset(texture: TextureLike, x: number, y: number): void;
|
|
15
16
|
export declare function setTextureUvRotation(texture: TextureLike, radians: number): void;
|
package/dist/texture.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture.d.ts","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAOzB,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"texture.d.ts","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,E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AAE,OAAO,GAAG,IAAI,CAGzF;AAID,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAEvF;AAID,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAGnF;AAGD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAEhF;AAGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAGlF;AAMD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAa/G"}
|
package/dist/texture.js
CHANGED
|
@@ -7,6 +7,8 @@ import { cloneSampler, copySampler, createSampler, equalsSampler } from './sampl
|
|
|
7
7
|
export function cloneTexture(source) {
|
|
8
8
|
return createEntity({
|
|
9
9
|
colorSpace: source.colorSpace,
|
|
10
|
+
flipX: source.flipX,
|
|
11
|
+
flipY: source.flipY,
|
|
10
12
|
image: source.image,
|
|
11
13
|
resource: source.resource ?? null,
|
|
12
14
|
sampler: cloneSampler(source.sampler),
|
|
@@ -20,6 +22,8 @@ export function cloneTexture(source) {
|
|
|
20
22
|
// preserved). Safe when out aliases source.
|
|
21
23
|
export function copyTexture(out, source) {
|
|
22
24
|
const colorSpace = source.colorSpace;
|
|
25
|
+
const flipX = source.flipX;
|
|
26
|
+
const flipY = source.flipY;
|
|
23
27
|
const image = source.image;
|
|
24
28
|
const resource = source.resource ?? null;
|
|
25
29
|
const uvRotation = source.uvRotation;
|
|
@@ -27,6 +31,8 @@ export function copyTexture(out, source) {
|
|
|
27
31
|
copyVector2(out.uvOffset, source.uvOffset);
|
|
28
32
|
copyVector2(out.uvScale, source.uvScale);
|
|
29
33
|
out.colorSpace = colorSpace;
|
|
34
|
+
out.flipX = flipX;
|
|
35
|
+
out.flipY = flipY;
|
|
30
36
|
out.image = image;
|
|
31
37
|
out.resource = resource;
|
|
32
38
|
out.uvRotation = uvRotation;
|
|
@@ -37,6 +43,8 @@ export function copyTexture(out, source) {
|
|
|
37
43
|
export function createTexture(opts) {
|
|
38
44
|
return createEntity({
|
|
39
45
|
colorSpace: opts?.colorSpace ?? 'srgb',
|
|
46
|
+
flipX: opts?.flipX ?? false,
|
|
47
|
+
flipY: opts?.flipY ?? false,
|
|
40
48
|
image: opts?.image ?? null,
|
|
41
49
|
resource: opts?.resource ?? null,
|
|
42
50
|
sampler: opts?.sampler ? cloneSampler(opts.sampler) : createSampler(),
|
|
@@ -53,6 +61,8 @@ export function equalsTexture(a, b) {
|
|
|
53
61
|
if (a === b)
|
|
54
62
|
return true;
|
|
55
63
|
return (a.colorSpace === b.colorSpace &&
|
|
64
|
+
a.flipX === b.flipX &&
|
|
65
|
+
a.flipY === b.flipY &&
|
|
56
66
|
a.image === b.image &&
|
|
57
67
|
a.uvRotation === b.uvRotation &&
|
|
58
68
|
a.uvOffset.x === b.uvOffset.x &&
|
|
@@ -84,12 +94,19 @@ export function getTextureInverseUvMatrix(out, texture) {
|
|
|
84
94
|
// Safe when out is an unrelated scratch; not intended for aliased input (no in-param here).
|
|
85
95
|
export function getTextureUvMatrix(out, texture) {
|
|
86
96
|
const r = texture.uvRotation;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
97
|
+
// A flip is a -1 scale plus a +1 pre-offset on that axis (u → 1 - u), applied before scale/rotate/
|
|
98
|
+
// translate: the scale negates and the +1 (in source-uv units, so it scales) rotates into the
|
|
99
|
+
// translation, keeping the flipped range in [0, 1].
|
|
100
|
+
const flipScaleX = texture.flipX ? -1 : 1;
|
|
101
|
+
const flipScaleY = texture.flipY ? -1 : 1;
|
|
102
|
+
const sx = texture.uvScale.x * flipScaleX;
|
|
103
|
+
const sy = texture.uvScale.y * flipScaleY;
|
|
104
|
+
const preOffsetX = texture.flipX ? texture.uvScale.x : 0;
|
|
105
|
+
const preOffsetY = texture.flipY ? texture.uvScale.y : 0;
|
|
91
106
|
const cosR = Math.cos(r);
|
|
92
107
|
const sinR = Math.sin(r);
|
|
108
|
+
const tx = texture.uvOffset.x + cosR * preOffsetX - sinR * preOffsetY;
|
|
109
|
+
const ty = texture.uvOffset.y + sinR * preOffsetX + cosR * preOffsetY;
|
|
93
110
|
const m = out.m;
|
|
94
111
|
m[0] = sx * cosR; // (0,0)
|
|
95
112
|
m[1] = sx * sinR; // (1,0)
|
|
@@ -110,7 +127,9 @@ export function getTextureWidth(texture) {
|
|
|
110
127
|
// this so an untiled surface pays nothing for the uv-transform uniform or the extra vertex multiply;
|
|
111
128
|
// only a texture that actually remaps its uv compiles the transforming path.
|
|
112
129
|
export function hasTextureUvTransform(texture) {
|
|
113
|
-
return (texture.
|
|
130
|
+
return (texture.flipX ||
|
|
131
|
+
texture.flipY ||
|
|
132
|
+
texture.uvScale.x !== 1 ||
|
|
114
133
|
texture.uvScale.y !== 1 ||
|
|
115
134
|
texture.uvOffset.x !== 0 ||
|
|
116
135
|
texture.uvOffset.y !== 0 ||
|
|
@@ -121,15 +140,24 @@ export function hasTextureUvTransform(texture) {
|
|
|
121
140
|
export function isTextureReady(texture) {
|
|
122
141
|
return texture.image !== null;
|
|
123
142
|
}
|
|
124
|
-
// Resets the KHR_texture_transform to identity in place: zero offset, no rotation, unit scale
|
|
125
|
-
// Leaves the image, color space, and sampler untouched.
|
|
143
|
+
// Resets the KHR_texture_transform to identity in place: zero offset, no rotation, unit scale, and
|
|
144
|
+
// no flip. Leaves the image, color space, and sampler untouched.
|
|
126
145
|
export function resetTextureUvTransform(texture) {
|
|
146
|
+
texture.flipX = false;
|
|
147
|
+
texture.flipY = false;
|
|
127
148
|
texture.uvOffset.x = 0;
|
|
128
149
|
texture.uvOffset.y = 0;
|
|
129
150
|
texture.uvRotation = 0;
|
|
130
151
|
texture.uvScale.x = 1;
|
|
131
152
|
texture.uvScale.y = 1;
|
|
132
153
|
}
|
|
154
|
+
// Sets the vertical/horizontal flip flags in place. A flip mirrors the sampled coordinate on that
|
|
155
|
+
// axis (`u → 1 - u`, `v → 1 - v`) before scale/rotate/translate — the sampler-space fix for an
|
|
156
|
+
// upside-down image or render-target, with no pixel copy.
|
|
157
|
+
export function setTextureFlip(texture, flipX, flipY) {
|
|
158
|
+
texture.flipX = flipX;
|
|
159
|
+
texture.flipY = flipY;
|
|
160
|
+
}
|
|
133
161
|
// Binds (or clears, with null) the texture's image source in place. Does not touch sampling state
|
|
134
162
|
// or the uv-transform.
|
|
135
163
|
export function setTextureImage(texture, image) {
|
|
@@ -155,6 +183,9 @@ export function setTextureUvScale(texture, x, y) {
|
|
|
155
183
|
// getTextureUvMatrix's result, computed inline to avoid allocating a scratch matrix.
|
|
156
184
|
// Out-param form — out may be any Vector2; no aliasing hazard (u and v are scalar inputs).
|
|
157
185
|
export function transformTextureUv(out, texture, u, v) {
|
|
186
|
+
// Flip mirrors the coordinate first (u → 1 - u), then the standard scale → rotate → translate.
|
|
187
|
+
const fu = texture.flipX ? 1 - u : u;
|
|
188
|
+
const fv = texture.flipY ? 1 - v : v;
|
|
158
189
|
const r = texture.uvRotation;
|
|
159
190
|
const sx = texture.uvScale.x;
|
|
160
191
|
const sy = texture.uvScale.y;
|
|
@@ -162,7 +193,7 @@ export function transformTextureUv(out, texture, u, v) {
|
|
|
162
193
|
const ty = texture.uvOffset.y;
|
|
163
194
|
const cosR = Math.cos(r);
|
|
164
195
|
const sinR = Math.sin(r);
|
|
165
|
-
out.x = sx * cosR *
|
|
166
|
-
out.y = sx * sinR *
|
|
196
|
+
out.x = sx * cosR * fu - sy * sinR * fv + tx;
|
|
197
|
+
out.y = sx * sinR * fu + sy * cosR * fv + ty;
|
|
167
198
|
}
|
|
168
199
|
//# sourceMappingURL=texture.js.map
|
package/dist/texture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture.js","sourceRoot":"","sources":["../src/texture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAU9F,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEpF,8FAA8F;AAC9F,iGAAiG;AACjG,iGAAiG;AACjG,MAAM,UAAU,YAAY,CAAC,MAA6B;IACxD,OAAO,YAAY,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,IAAI;QACjC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;QACrC,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC;QACvC,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;KACtC,CAAC,CAAC;AACL,CAAC;AAED,+FAA+F;AAC/F,iGAAiG;AACjG,4CAA4C;AAC5C,MAAM,UAAU,WAAW,CAAC,GAAgB,EAAE,MAA6B;IACzE,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC3B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzC,WAAW,CAAC,GAAG,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AG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;IAC7C,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"videoTexture.d.ts","sourceRoot":"","sources":["../src/videoTexture.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"videoTexture.d.ts","sourceRoot":"","sources":["../src/videoTexture.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AASlG,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,gBAAgB,GAAG,MAAM,CAG1E;AAMD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,YAAY,CAYlF;AAKD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAgBhG;AAKD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,YAAY,CAYlH;AAKD,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAGtF;AAKD,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAG/G;AAMD,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAExG;AAID,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAGrF;AAKD,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAK1F;AAID,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAE3E;AAID,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAGjG"}
|
package/dist/videoTexture.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createEntity } from '@flighthq/entity';
|
|
2
2
|
import { cloneVector2, copyVector2, createVector2, inverseMatrix3 } from '@flighthq/geometry';
|
|
3
3
|
import { cloneSampler, copySampler, createSampler } from './sampler';
|
|
4
|
+
import { getTextureUvMatrix } from './texture';
|
|
4
5
|
// Marks a fresh decoded frame as available for upload by bumping `frameId`. A driver calls this once
|
|
5
6
|
// per rendered frame when the backing element reports new pixels (readyState advanced, or a
|
|
6
7
|
// requestVideoFrameCallback fired); the GPU uploader compares the id against the one it last uploaded
|
|
@@ -16,6 +17,8 @@ export function advanceVideoTexture(videoTexture) {
|
|
|
16
17
|
export function cloneVideoTexture(source) {
|
|
17
18
|
return createEntity({
|
|
18
19
|
colorSpace: source.colorSpace,
|
|
20
|
+
flipX: source.flipX,
|
|
21
|
+
flipY: source.flipY,
|
|
19
22
|
frameId: -1,
|
|
20
23
|
sampler: cloneSampler(source.sampler),
|
|
21
24
|
source: source.source,
|
|
@@ -29,6 +32,8 @@ export function cloneVideoTexture(source) {
|
|
|
29
32
|
// aliases source.
|
|
30
33
|
export function copyVideoTexture(out, source) {
|
|
31
34
|
const colorSpace = source.colorSpace;
|
|
35
|
+
const flipX = source.flipX;
|
|
36
|
+
const flipY = source.flipY;
|
|
32
37
|
const frameId = source.frameId;
|
|
33
38
|
const src = source.source;
|
|
34
39
|
const uvRotation = source.uvRotation;
|
|
@@ -36,6 +41,8 @@ export function copyVideoTexture(out, source) {
|
|
|
36
41
|
copyVector2(out.uvOffset, source.uvOffset);
|
|
37
42
|
copyVector2(out.uvScale, source.uvScale);
|
|
38
43
|
out.colorSpace = colorSpace;
|
|
44
|
+
out.flipX = flipX;
|
|
45
|
+
out.flipY = flipY;
|
|
39
46
|
out.frameId = frameId;
|
|
40
47
|
out.source = src;
|
|
41
48
|
out.uvRotation = uvRotation;
|
|
@@ -46,6 +53,8 @@ export function copyVideoTexture(out, source) {
|
|
|
46
53
|
export function createVideoTexture(source, opts) {
|
|
47
54
|
return createEntity({
|
|
48
55
|
colorSpace: opts?.colorSpace ?? 'srgb',
|
|
56
|
+
flipX: opts?.flipX ?? false,
|
|
57
|
+
flipY: opts?.flipY ?? false,
|
|
49
58
|
frameId: opts?.frameId ?? -1,
|
|
50
59
|
sampler: opts?.sampler ? cloneSampler(opts.sampler) : createSampler(),
|
|
51
60
|
source: opts?.source ?? source,
|
|
@@ -68,27 +77,12 @@ export function getVideoTextureInverseUvMatrix(out, videoTexture) {
|
|
|
68
77
|
getVideoTextureUvMatrix(out, videoTexture);
|
|
69
78
|
inverseMatrix3(out, out);
|
|
70
79
|
}
|
|
71
|
-
// Composes the KHR_texture_transform fields (uvOffset, uvRotation, uvScale) into the column-major
|
|
72
|
-
// matrix a shader consumes at sample time
|
|
73
|
-
//
|
|
80
|
+
// Composes the KHR_texture_transform fields (flip, uvOffset, uvRotation, uvScale) into the column-major
|
|
81
|
+
// 3×3 matrix a shader consumes at sample time. A VideoTexture is a TextureUvTransform, so this delegates
|
|
82
|
+
// to getTextureUvMatrix — one uv-transform path (flip → scale → rotate → translate) for both texture
|
|
83
|
+
// kinds. Out-param form.
|
|
74
84
|
export function getVideoTextureUvMatrix(out, videoTexture) {
|
|
75
|
-
|
|
76
|
-
const sx = videoTexture.uvScale.x;
|
|
77
|
-
const sy = videoTexture.uvScale.y;
|
|
78
|
-
const tx = videoTexture.uvOffset.x;
|
|
79
|
-
const ty = videoTexture.uvOffset.y;
|
|
80
|
-
const cosR = Math.cos(r);
|
|
81
|
-
const sinR = Math.sin(r);
|
|
82
|
-
const m = out.m;
|
|
83
|
-
m[0] = sx * cosR;
|
|
84
|
-
m[1] = sx * sinR;
|
|
85
|
-
m[2] = 0;
|
|
86
|
-
m[3] = -sy * sinR;
|
|
87
|
-
m[4] = sy * cosR;
|
|
88
|
-
m[5] = 0;
|
|
89
|
-
m[6] = tx;
|
|
90
|
-
m[7] = ty;
|
|
91
|
-
m[8] = 1;
|
|
85
|
+
getTextureUvMatrix(out, videoTexture);
|
|
92
86
|
}
|
|
93
87
|
// Returns the pixel width of the current video frame, or -1 when no element is attached or no frame
|
|
94
88
|
// has decoded yet.
|
package/dist/videoTexture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"videoTexture.js","sourceRoot":"","sources":["../src/videoTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG9F,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"videoTexture.js","sourceRoot":"","sources":["../src/videoTexture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG9F,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,qGAAqG;AACrG,4FAA4F;AAC5F,sGAAsG;AACtG,2FAA2F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F;AACxF,MAAM,UAAU,sBAAsB,CAAC,YAA8B;IACnE,YAAY,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,qGAAqG;AACrG,qDAAqD;AACrD,MAAM,UAAU,qBAAqB,CAAC,YAA8B,EAAE,MAAqB;IACzF,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC;IAC7B,YAAY,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,4FAA4F;AAC5F,MAAM,iBAAiB,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/texture",
|
|
3
|
-
"version": "0.2.1-next.
|
|
3
|
+
"version": "0.2.1-next.444.a313478",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/flighthq/flight.git",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@flighthq/entity": "0.2.1-next.
|
|
36
|
-
"@flighthq/geometry": "0.2.1-next.
|
|
37
|
-
"@flighthq/types": "0.2.1-next.
|
|
35
|
+
"@flighthq/entity": "0.2.1-next.444.a313478",
|
|
36
|
+
"@flighthq/geometry": "0.2.1-next.444.a313478",
|
|
37
|
+
"@flighthq/types": "0.2.1-next.444.a313478"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"typescript": "^5.3.0"
|
package/src/texture.test.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
hasTextureUvTransform,
|
|
15
15
|
isTextureReady,
|
|
16
16
|
resetTextureUvTransform,
|
|
17
|
+
setTextureFlip,
|
|
17
18
|
setTextureImage,
|
|
18
19
|
setTextureUvOffset,
|
|
19
20
|
setTextureUvRotation,
|
|
@@ -23,6 +24,13 @@ import {
|
|
|
23
24
|
|
|
24
25
|
const fakeImage = { width: 32, height: 64 } as ImageResource;
|
|
25
26
|
|
|
27
|
+
// Applies a column-major 3×3 uv matrix to (u, v, 1), writing the transformed coordinate into out.
|
|
28
|
+
function multiplyMatrix3Uv(out: { x: number; y: number }, matrix: { m: ArrayLike<number> }, u: number, v: number) {
|
|
29
|
+
const m = matrix.m;
|
|
30
|
+
out.x = m[0] * u + m[3] * v + m[6];
|
|
31
|
+
out.y = m[1] * u + m[4] * v + m[7];
|
|
32
|
+
}
|
|
33
|
+
|
|
26
34
|
describe('cloneTexture', () => {
|
|
27
35
|
it('shares the image but deep-clones the sampler and uv vectors', () => {
|
|
28
36
|
const source = createTexture({
|
|
@@ -247,6 +255,37 @@ describe('getTextureUvMatrix', () => {
|
|
|
247
255
|
expect(out.m[7]).toBeCloseTo(0.75); // ty
|
|
248
256
|
});
|
|
249
257
|
|
|
258
|
+
it('maps v to 1 - v for a vertical flip and u to 1 - u for a horizontal flip', () => {
|
|
259
|
+
const out = createMatrix3();
|
|
260
|
+
const scratch = createVector2();
|
|
261
|
+
|
|
262
|
+
getTextureUvMatrix(out, createTexture({ flipY: true }));
|
|
263
|
+
// Apply the matrix to (u, v) = (0.2, 0.3): expect (0.2, 0.7).
|
|
264
|
+
multiplyMatrix3Uv(scratch, out, 0.2, 0.3);
|
|
265
|
+
expect(scratch.x).toBeCloseTo(0.2);
|
|
266
|
+
expect(scratch.y).toBeCloseTo(0.7);
|
|
267
|
+
|
|
268
|
+
getTextureUvMatrix(out, createTexture({ flipX: true }));
|
|
269
|
+
multiplyMatrix3Uv(scratch, out, 0.2, 0.3);
|
|
270
|
+
expect(scratch.x).toBeCloseTo(0.8);
|
|
271
|
+
expect(scratch.y).toBeCloseTo(0.3);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('agrees with transformTextureUv when a flip combines with scale, rotation, and offset', () => {
|
|
275
|
+
const texture = createTexture({ flipX: true, flipY: true, uvScale: createVector2(2, 3) });
|
|
276
|
+
setTextureUvOffset(texture, 0.1, 0.2);
|
|
277
|
+
setTextureUvRotation(texture, 0.5);
|
|
278
|
+
const out = createMatrix3();
|
|
279
|
+
getTextureUvMatrix(out, texture);
|
|
280
|
+
|
|
281
|
+
const viaMatrix = createVector2();
|
|
282
|
+
multiplyMatrix3Uv(viaMatrix, out, 0.35, 0.6);
|
|
283
|
+
const viaInline = createVector2();
|
|
284
|
+
transformTextureUv(viaInline, texture, 0.35, 0.6);
|
|
285
|
+
expect(viaMatrix.x).toBeCloseTo(viaInline.x);
|
|
286
|
+
expect(viaMatrix.y).toBeCloseTo(viaInline.y);
|
|
287
|
+
});
|
|
288
|
+
|
|
250
289
|
it('encodes scale in the diagonal', () => {
|
|
251
290
|
const texture = createTexture();
|
|
252
291
|
setTextureUvScale(texture, 2, 3);
|
|
@@ -312,6 +351,11 @@ describe('hasTextureUvTransform', () => {
|
|
|
312
351
|
expect(hasTextureUvTransform(texture)).toBe(true);
|
|
313
352
|
});
|
|
314
353
|
|
|
354
|
+
it('is true when a flip flag is set', () => {
|
|
355
|
+
expect(hasTextureUvTransform(createTexture({ flipY: true }))).toBe(true);
|
|
356
|
+
expect(hasTextureUvTransform(createTexture({ flipX: true }))).toBe(true);
|
|
357
|
+
});
|
|
358
|
+
|
|
315
359
|
it('is true when the rotation is non-zero', () => {
|
|
316
360
|
const texture = createTexture();
|
|
317
361
|
setTextureUvRotation(texture, 0.5);
|
|
@@ -360,6 +404,19 @@ describe('resetTextureUvTransform', () => {
|
|
|
360
404
|
});
|
|
361
405
|
});
|
|
362
406
|
|
|
407
|
+
describe('setTextureFlip', () => {
|
|
408
|
+
it('sets the flip flags in place', () => {
|
|
409
|
+
const texture = createTexture();
|
|
410
|
+
expect(texture.flipX).toBe(false);
|
|
411
|
+
setTextureFlip(texture, true, true);
|
|
412
|
+
expect(texture.flipX).toBe(true);
|
|
413
|
+
expect(texture.flipY).toBe(true);
|
|
414
|
+
setTextureFlip(texture, false, true);
|
|
415
|
+
expect(texture.flipX).toBe(false);
|
|
416
|
+
expect(texture.flipY).toBe(true);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
|
|
363
420
|
describe('setTextureImage', () => {
|
|
364
421
|
it('binds and clears the image in place', () => {
|
|
365
422
|
const texture = createTexture();
|