UNPKG

2.04 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var math = require('@pixi/math');
6
7class TextureUvs {
8 constructor() {
9 this.x0 = 0;
10 this.y0 = 0;
11 this.x1 = 1;
12 this.y1 = 0;
13 this.x2 = 1;
14 this.y2 = 1;
15 this.x3 = 0;
16 this.y3 = 1;
17 this.uvsFloat32 = new Float32Array(8);
18 }
19 set(frame, baseFrame, rotate) {
20 const tw = baseFrame.width;
21 const th = baseFrame.height;
22 if (rotate) {
23 const w2 = frame.width / 2 / tw;
24 const h2 = frame.height / 2 / th;
25 const cX = frame.x / tw + w2;
26 const cY = frame.y / th + h2;
27 rotate = math.groupD8.add(rotate, math.groupD8.NW);
28 this.x0 = cX + w2 * math.groupD8.uX(rotate);
29 this.y0 = cY + h2 * math.groupD8.uY(rotate);
30 rotate = math.groupD8.add(rotate, 2);
31 this.x1 = cX + w2 * math.groupD8.uX(rotate);
32 this.y1 = cY + h2 * math.groupD8.uY(rotate);
33 rotate = math.groupD8.add(rotate, 2);
34 this.x2 = cX + w2 * math.groupD8.uX(rotate);
35 this.y2 = cY + h2 * math.groupD8.uY(rotate);
36 rotate = math.groupD8.add(rotate, 2);
37 this.x3 = cX + w2 * math.groupD8.uX(rotate);
38 this.y3 = cY + h2 * math.groupD8.uY(rotate);
39 } else {
40 this.x0 = frame.x / tw;
41 this.y0 = frame.y / th;
42 this.x1 = (frame.x + frame.width) / tw;
43 this.y1 = frame.y / th;
44 this.x2 = (frame.x + frame.width) / tw;
45 this.y2 = (frame.y + frame.height) / th;
46 this.x3 = frame.x / tw;
47 this.y3 = (frame.y + frame.height) / th;
48 }
49 this.uvsFloat32[0] = this.x0;
50 this.uvsFloat32[1] = this.y0;
51 this.uvsFloat32[2] = this.x1;
52 this.uvsFloat32[3] = this.y1;
53 this.uvsFloat32[4] = this.x2;
54 this.uvsFloat32[5] = this.y2;
55 this.uvsFloat32[6] = this.x3;
56 this.uvsFloat32[7] = this.y3;
57 }
58 toString() {
59 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}]`;
60 }
61}
62
63exports.TextureUvs = TextureUvs;
64//# sourceMappingURL=TextureUvs.js.map