1 | "use strict";
|
2 | var math = require("@pixi/math");
|
3 | const tempMat = new math.Matrix();
|
4 | class TextureMatrix {
|
5 | |
6 |
|
7 |
|
8 |
|
9 | constructor(texture, clampMargin) {
|
10 | this._texture = texture, this.mapCoord = new math.Matrix(), this.uClampFrame = new Float32Array(4), this.uClampOffset = new Float32Array(2), this._textureID = -1, this._updateID = 0, this.clampOffset = 0, this.clampMargin = typeof clampMargin > "u" ? 0.5 : clampMargin, this.isSimple = !1;
|
11 | }
|
12 |
|
13 | get texture() {
|
14 | return this._texture;
|
15 | }
|
16 | set texture(value) {
|
17 | this._texture = value, this._textureID = -1;
|
18 | }
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | multiplyUvs(uvs, out) {
|
26 | out === void 0 && (out = uvs);
|
27 | const mat = this.mapCoord;
|
28 | for (let i = 0; i < uvs.length; i += 2) {
|
29 | const x = uvs[i], y = uvs[i + 1];
|
30 | out[i] = x * mat.a + y * mat.c + mat.tx, out[i + 1] = x * mat.b + y * mat.d + mat.ty;
|
31 | }
|
32 | return out;
|
33 | }
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | update(forceUpdate) {
|
40 | const tex = this._texture;
|
41 | if (!tex || !tex.valid || !forceUpdate && this._textureID === tex._updateID)
|
42 | return !1;
|
43 | this._textureID = tex._updateID, this._updateID++;
|
44 | const uvs = tex._uvs;
|
45 | this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0);
|
46 | const orig = tex.orig, trim = tex.trim;
|
47 | trim && (tempMat.set(
|
48 | orig.width / trim.width,
|
49 | 0,
|
50 | 0,
|
51 | orig.height / trim.height,
|
52 | -trim.x / trim.width,
|
53 | -trim.y / trim.height
|
54 | ), this.mapCoord.append(tempMat));
|
55 | const texBase = tex.baseTexture, frame = this.uClampFrame, margin = this.clampMargin / texBase.resolution, offset = this.clampOffset;
|
56 | return frame[0] = (tex._frame.x + margin + offset) / texBase.width, frame[1] = (tex._frame.y + margin + offset) / texBase.height, frame[2] = (tex._frame.x + tex._frame.width - margin + offset) / texBase.width, frame[3] = (tex._frame.y + tex._frame.height - margin + offset) / texBase.height, this.uClampOffset[0] = offset / texBase.realWidth, this.uClampOffset[1] = offset / texBase.realHeight, this.isSimple = tex._frame.width === texBase.width && tex._frame.height === texBase.height && tex.rotate === 0, !0;
|
57 | }
|
58 | }
|
59 | exports.TextureMatrix = TextureMatrix;
|
60 |
|