UNPKG

1.9 kBJavaScriptView Raw
1import { groupD8 } from '@pixi/math';
2
3class TextureUvs {
4 constructor() {
5 this.x0 = 0;
6 this.y0 = 0;
7 this.x1 = 1;
8 this.y1 = 0;
9 this.x2 = 1;
10 this.y2 = 1;
11 this.x3 = 0;
12 this.y3 = 1;
13 this.uvsFloat32 = new Float32Array(8);
14 }
15 set(frame, baseFrame, rotate) {
16 const tw = baseFrame.width;
17 const th = baseFrame.height;
18 if (rotate) {
19 const w2 = frame.width / 2 / tw;
20 const h2 = frame.height / 2 / th;
21 const cX = frame.x / tw + w2;
22 const cY = frame.y / th + h2;
23 rotate = groupD8.add(rotate, groupD8.NW);
24 this.x0 = cX + w2 * groupD8.uX(rotate);
25 this.y0 = cY + h2 * groupD8.uY(rotate);
26 rotate = groupD8.add(rotate, 2);
27 this.x1 = cX + w2 * groupD8.uX(rotate);
28 this.y1 = cY + h2 * groupD8.uY(rotate);
29 rotate = groupD8.add(rotate, 2);
30 this.x2 = cX + w2 * groupD8.uX(rotate);
31 this.y2 = cY + h2 * groupD8.uY(rotate);
32 rotate = groupD8.add(rotate, 2);
33 this.x3 = cX + w2 * groupD8.uX(rotate);
34 this.y3 = cY + h2 * groupD8.uY(rotate);
35 } else {
36 this.x0 = frame.x / tw;
37 this.y0 = frame.y / th;
38 this.x1 = (frame.x + frame.width) / tw;
39 this.y1 = frame.y / th;
40 this.x2 = (frame.x + frame.width) / tw;
41 this.y2 = (frame.y + frame.height) / th;
42 this.x3 = frame.x / tw;
43 this.y3 = (frame.y + frame.height) / th;
44 }
45 this.uvsFloat32[0] = this.x0;
46 this.uvsFloat32[1] = this.y0;
47 this.uvsFloat32[2] = this.x1;
48 this.uvsFloat32[3] = this.y1;
49 this.uvsFloat32[4] = this.x2;
50 this.uvsFloat32[5] = this.y2;
51 this.uvsFloat32[6] = this.x3;
52 this.uvsFloat32[7] = this.y3;
53 }
54 toString() {
55 return `[@pixi/core:TextureUvs x0=${this.x0} y0=${this.y0} x1=${this.x1} y1=${this.y1} x2=${this.x2} y2=${this.y2} x3=${this.x3} y3=${this.y3}]`;
56 }
57}
58
59export { TextureUvs };
60//# sourceMappingURL=TextureUvs.mjs.map