UNPKG

@awayjs/graphics

Version:
61 lines (60 loc) 2.42 kB
import { Matrix } from '@awayjs/core'; import { ImageUtils } from '@awayjs/stage'; var BitmapFillStyle = /** @class */ (function () { function BitmapFillStyle(material, matrix, repeat, smooth) { this.material = material; 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 texture = this.material.getTextureAt(0); var style = this.material.style; var image = (texture.getImageAt(0) || (style === null || style === void 0 ? void 0 : style.getImageAt(texture, 0)) || ImageUtils.getDefaultImage2D()); var projection_width_half; var projection_height_half; if (!image) { console.warn('[BitmapFillStyle] - getUVMatrix - no texture found'); projection_width_half = 512; projection_height_half = 512; } else { projection_width_half = image.width; projection_height_half = 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 };