@awayjs/graphics
Version:
AwayJS graphics classes
57 lines (56 loc) • 2.13 kB
JavaScript
import { Matrix } from '@awayjs/core';
var BitmapFillStyle = /** @class */ (function () {
function BitmapFillStyle(image, matrix, repeat, smooth) {
this.image = image;
this.matrix = matrix;
this.repeat = repeat;
this.smooth = smooth;
}
Object.defineProperty(BitmapFillStyle.prototype, "data_type", {
get: function () {
return BitmapFillStyle.data_type;
},
enumerable: false,
configurable: true
});
BitmapFillStyle.prototype.getUVMatrix = function () {
if (!this.matrix)
this.matrix = new Matrix();
if (!this._uvMatrix)
this._uvMatrix = new Matrix();
var projection_width_half;
var projection_height_half;
if (!this.image) {
console.warn('[BitmapFillStyle] - getUVMatrix - no texture found');
projection_width_half = 512;
projection_height_half = 512;
}
else {
projection_width_half = this.image.width;
projection_height_half = this.image.height;
}
// Get and invert the uv transform:
var a = this.matrix.a;
var b = this.matrix.b;
var c = this.matrix.c;
var d = this.matrix.d;
var tx = this.matrix.tx;
var ty = this.matrix.ty;
var a_inv = d / (a * d - b * c);
var b_inv = -b / (a * d - b * c);
var c_inv = -c / (a * d - b * c);
var d_inv = a / (a * d - b * c);
var tx_inv = (c * ty - d * tx) / (a * d - b * c);
var ty_inv = -(a * ty - b * tx) / (a * d - b * c);
this._uvMatrix.a = a_inv / projection_width_half;
this._uvMatrix.b = b_inv / projection_height_half;
this._uvMatrix.c = c_inv / projection_width_half;
this._uvMatrix.d = d_inv / projection_height_half;
this._uvMatrix.tx = tx_inv / projection_width_half;
this._uvMatrix.ty = ty_inv / projection_height_half;
return this._uvMatrix;
};
BitmapFillStyle.data_type = '[graphicsdata BitmapFillStyle]';
return BitmapFillStyle;
}());
export { BitmapFillStyle };