diff --git a/src/core/index.js b/src/core/index.js index 1de5da5..f2b3af1 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -29,7 +29,6 @@ export { default as GraphicsRenderer } from './graphics/webgl/GraphicsRenderer'; export { default as CanvasGraphicsRenderer } from './graphics/canvas/CanvasGraphicsRenderer'; export { default as Texture } from './textures/Texture'; -export { default as TextureTransform } from './textures/TextureTransform'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as RenderTexture } from './textures/RenderTexture'; export { default as BaseRenderTexture } from './textures/BaseRenderTexture'; diff --git a/src/core/index.js b/src/core/index.js index 1de5da5..f2b3af1 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -29,7 +29,6 @@ export { default as GraphicsRenderer } from './graphics/webgl/GraphicsRenderer'; export { default as CanvasGraphicsRenderer } from './graphics/canvas/CanvasGraphicsRenderer'; export { default as Texture } from './textures/Texture'; -export { default as TextureTransform } from './textures/TextureTransform'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as RenderTexture } from './textures/RenderTexture'; export { default as BaseRenderTexture } from './textures/BaseRenderTexture'; diff --git a/src/core/textures/TextureTransform.js b/src/core/textures/TextureTransform.js deleted file mode 100644 index 5b58021..0000000 --- a/src/core/textures/TextureTransform.js +++ /dev/null @@ -1,96 +0,0 @@ -import { default as Matrix } from '../math/Matrix'; - -const tempMat = new Matrix(); - -/** - * class controls uv transform and frame clamp for texture - */ -export default class TextureTransform { - /** - * - * @param {PIXI.Texture} texture observed texture - * @constructor - */ - constructor(texture) - { - this._texture = texture; - - this.mapCoord = new Matrix(); - - this.clampFrame = new Float32Array(4); - - this.clampOffset = new Float32Array(2); - - this._lastTextureID = -1; - - this.update(); - } - - /** - * texture property - * @member {PIXI.Texture} - * @memberof PIXI.TextureTransform - */ - get texture() - { - return this._texture; - } - - /** - * sets texture value - * @param {PIXI.Texture} value texture to be set - */ - set texture(value) - { - this._texture = value; - this._lastTextureID = -1; - } - - /** - * updates matrices if texture was changed - * @param {boolean} forceUpdate if true, matrices will be updated any case - */ - update(forceUpdate) - { - const tex = this.texture; - - if (!tex || !tex.valid) - { - return; - } - - if (!forceUpdate - && this._lastTextureID === this.texture._updateID) - { - return; - } - - this._lastTextureID = this.texture._updateID; - - const uvs = this.texture._uvs; - - this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0); - - const orig = tex.orig; - const trim = tex.trim; - - if (trim) - { - tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, - -trim.x / trim.width, -trim.y / trim.height); - this.mapCoord.append(tempMat); - } - - const texBase = tex.baseTexture; - const frame = this.clampFrame; - const margin = tex.clampMargin / texBase.resolution; - const offset = tex.clampOffset; - - 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.clampOffset[0] = offset / texBase.realWidth; - this.clampOffset[1] = offset / texBase.realHeight; - } -} diff --git a/src/core/index.js b/src/core/index.js index 1de5da5..f2b3af1 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -29,7 +29,6 @@ export { default as GraphicsRenderer } from './graphics/webgl/GraphicsRenderer'; export { default as CanvasGraphicsRenderer } from './graphics/canvas/CanvasGraphicsRenderer'; export { default as Texture } from './textures/Texture'; -export { default as TextureTransform } from './textures/TextureTransform'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as RenderTexture } from './textures/RenderTexture'; export { default as BaseRenderTexture } from './textures/BaseRenderTexture'; diff --git a/src/core/textures/TextureTransform.js b/src/core/textures/TextureTransform.js deleted file mode 100644 index 5b58021..0000000 --- a/src/core/textures/TextureTransform.js +++ /dev/null @@ -1,96 +0,0 @@ -import { default as Matrix } from '../math/Matrix'; - -const tempMat = new Matrix(); - -/** - * class controls uv transform and frame clamp for texture - */ -export default class TextureTransform { - /** - * - * @param {PIXI.Texture} texture observed texture - * @constructor - */ - constructor(texture) - { - this._texture = texture; - - this.mapCoord = new Matrix(); - - this.clampFrame = new Float32Array(4); - - this.clampOffset = new Float32Array(2); - - this._lastTextureID = -1; - - this.update(); - } - - /** - * texture property - * @member {PIXI.Texture} - * @memberof PIXI.TextureTransform - */ - get texture() - { - return this._texture; - } - - /** - * sets texture value - * @param {PIXI.Texture} value texture to be set - */ - set texture(value) - { - this._texture = value; - this._lastTextureID = -1; - } - - /** - * updates matrices if texture was changed - * @param {boolean} forceUpdate if true, matrices will be updated any case - */ - update(forceUpdate) - { - const tex = this.texture; - - if (!tex || !tex.valid) - { - return; - } - - if (!forceUpdate - && this._lastTextureID === this.texture._updateID) - { - return; - } - - this._lastTextureID = this.texture._updateID; - - const uvs = this.texture._uvs; - - this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0); - - const orig = tex.orig; - const trim = tex.trim; - - if (trim) - { - tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, - -trim.x / trim.width, -trim.y / trim.height); - this.mapCoord.append(tempMat); - } - - const texBase = tex.baseTexture; - const frame = this.clampFrame; - const margin = tex.clampMargin / texBase.resolution; - const offset = tex.clampOffset; - - 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.clampOffset[0] = offset / texBase.realWidth; - this.clampOffset[1] = offset / texBase.realHeight; - } -} diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index cfa8c0b..0ed66e6 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -27,7 +27,6 @@ this.y3 = 1; this.uvsUint32 = new Uint32Array(4); - this.uvsMatrix = null; } /** diff --git a/src/core/index.js b/src/core/index.js index 1de5da5..f2b3af1 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -29,7 +29,6 @@ export { default as GraphicsRenderer } from './graphics/webgl/GraphicsRenderer'; export { default as CanvasGraphicsRenderer } from './graphics/canvas/CanvasGraphicsRenderer'; export { default as Texture } from './textures/Texture'; -export { default as TextureTransform } from './textures/TextureTransform'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as RenderTexture } from './textures/RenderTexture'; export { default as BaseRenderTexture } from './textures/BaseRenderTexture'; diff --git a/src/core/textures/TextureTransform.js b/src/core/textures/TextureTransform.js deleted file mode 100644 index 5b58021..0000000 --- a/src/core/textures/TextureTransform.js +++ /dev/null @@ -1,96 +0,0 @@ -import { default as Matrix } from '../math/Matrix'; - -const tempMat = new Matrix(); - -/** - * class controls uv transform and frame clamp for texture - */ -export default class TextureTransform { - /** - * - * @param {PIXI.Texture} texture observed texture - * @constructor - */ - constructor(texture) - { - this._texture = texture; - - this.mapCoord = new Matrix(); - - this.clampFrame = new Float32Array(4); - - this.clampOffset = new Float32Array(2); - - this._lastTextureID = -1; - - this.update(); - } - - /** - * texture property - * @member {PIXI.Texture} - * @memberof PIXI.TextureTransform - */ - get texture() - { - return this._texture; - } - - /** - * sets texture value - * @param {PIXI.Texture} value texture to be set - */ - set texture(value) - { - this._texture = value; - this._lastTextureID = -1; - } - - /** - * updates matrices if texture was changed - * @param {boolean} forceUpdate if true, matrices will be updated any case - */ - update(forceUpdate) - { - const tex = this.texture; - - if (!tex || !tex.valid) - { - return; - } - - if (!forceUpdate - && this._lastTextureID === this.texture._updateID) - { - return; - } - - this._lastTextureID = this.texture._updateID; - - const uvs = this.texture._uvs; - - this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0); - - const orig = tex.orig; - const trim = tex.trim; - - if (trim) - { - tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, - -trim.x / trim.width, -trim.y / trim.height); - this.mapCoord.append(tempMat); - } - - const texBase = tex.baseTexture; - const frame = this.clampFrame; - const margin = tex.clampMargin / texBase.resolution; - const offset = tex.clampOffset; - - 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.clampOffset[0] = offset / texBase.realWidth; - this.clampOffset[1] = offset / texBase.realHeight; - } -} diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index cfa8c0b..0ed66e6 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -27,7 +27,6 @@ this.y3 = 1; this.uvsUint32 = new Uint32Array(4); - this.uvsMatrix = null; } /** diff --git a/src/extras/TextureTransform.js b/src/extras/TextureTransform.js new file mode 100644 index 0000000..01f26a3 --- /dev/null +++ b/src/extras/TextureTransform.js @@ -0,0 +1,96 @@ +import { default as Matrix } from '../core/math/Matrix'; + +const tempMat = new Matrix(); + +/** + * class controls uv transform and frame clamp for texture + */ +export default class TextureTransform { + /** + * + * @param {PIXI.Texture} texture observed texture + * @constructor + */ + constructor(texture) + { + this._texture = texture; + + this.mapCoord = new Matrix(); + + this.clampFrame = new Float32Array(4); + + this.clampOffset = new Float32Array(2); + + this._lastTextureID = -1; + + this.update(); + } + + /** + * texture property + * @member {PIXI.Texture} + * @memberof PIXI.TextureTransform + */ + get texture() + { + return this._texture; + } + + /** + * sets texture value + * @param {PIXI.Texture} value texture to be set + */ + set texture(value) + { + this._texture = value; + this._lastTextureID = -1; + } + + /** + * updates matrices if texture was changed + * @param {boolean} forceUpdate if true, matrices will be updated any case + */ + update(forceUpdate) + { + const tex = this.texture; + + if (!tex || !tex.valid) + { + return; + } + + if (!forceUpdate + && this._lastTextureID === this.texture._updateID) + { + return; + } + + this._lastTextureID = this.texture._updateID; + + const uvs = this.texture._uvs; + + this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0); + + const orig = tex.orig; + const trim = tex.trim; + + if (trim) + { + tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, + -trim.x / trim.width, -trim.y / trim.height); + this.mapCoord.append(tempMat); + } + + const texBase = tex.baseTexture; + const frame = this.clampFrame; + const margin = tex.clampMargin / texBase.resolution; + const offset = tex.clampOffset; + + 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.clampOffset[0] = offset / texBase.realWidth; + this.clampOffset[1] = offset / texBase.realHeight; + } +} diff --git a/src/core/index.js b/src/core/index.js index 1de5da5..f2b3af1 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -29,7 +29,6 @@ export { default as GraphicsRenderer } from './graphics/webgl/GraphicsRenderer'; export { default as CanvasGraphicsRenderer } from './graphics/canvas/CanvasGraphicsRenderer'; export { default as Texture } from './textures/Texture'; -export { default as TextureTransform } from './textures/TextureTransform'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as RenderTexture } from './textures/RenderTexture'; export { default as BaseRenderTexture } from './textures/BaseRenderTexture'; diff --git a/src/core/textures/TextureTransform.js b/src/core/textures/TextureTransform.js deleted file mode 100644 index 5b58021..0000000 --- a/src/core/textures/TextureTransform.js +++ /dev/null @@ -1,96 +0,0 @@ -import { default as Matrix } from '../math/Matrix'; - -const tempMat = new Matrix(); - -/** - * class controls uv transform and frame clamp for texture - */ -export default class TextureTransform { - /** - * - * @param {PIXI.Texture} texture observed texture - * @constructor - */ - constructor(texture) - { - this._texture = texture; - - this.mapCoord = new Matrix(); - - this.clampFrame = new Float32Array(4); - - this.clampOffset = new Float32Array(2); - - this._lastTextureID = -1; - - this.update(); - } - - /** - * texture property - * @member {PIXI.Texture} - * @memberof PIXI.TextureTransform - */ - get texture() - { - return this._texture; - } - - /** - * sets texture value - * @param {PIXI.Texture} value texture to be set - */ - set texture(value) - { - this._texture = value; - this._lastTextureID = -1; - } - - /** - * updates matrices if texture was changed - * @param {boolean} forceUpdate if true, matrices will be updated any case - */ - update(forceUpdate) - { - const tex = this.texture; - - if (!tex || !tex.valid) - { - return; - } - - if (!forceUpdate - && this._lastTextureID === this.texture._updateID) - { - return; - } - - this._lastTextureID = this.texture._updateID; - - const uvs = this.texture._uvs; - - this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0); - - const orig = tex.orig; - const trim = tex.trim; - - if (trim) - { - tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, - -trim.x / trim.width, -trim.y / trim.height); - this.mapCoord.append(tempMat); - } - - const texBase = tex.baseTexture; - const frame = this.clampFrame; - const margin = tex.clampMargin / texBase.resolution; - const offset = tex.clampOffset; - - 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.clampOffset[0] = offset / texBase.realWidth; - this.clampOffset[1] = offset / texBase.realHeight; - } -} diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index cfa8c0b..0ed66e6 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -27,7 +27,6 @@ this.y3 = 1; this.uvsUint32 = new Uint32Array(4); - this.uvsMatrix = null; } /** diff --git a/src/extras/TextureTransform.js b/src/extras/TextureTransform.js new file mode 100644 index 0000000..01f26a3 --- /dev/null +++ b/src/extras/TextureTransform.js @@ -0,0 +1,96 @@ +import { default as Matrix } from '../core/math/Matrix'; + +const tempMat = new Matrix(); + +/** + * class controls uv transform and frame clamp for texture + */ +export default class TextureTransform { + /** + * + * @param {PIXI.Texture} texture observed texture + * @constructor + */ + constructor(texture) + { + this._texture = texture; + + this.mapCoord = new Matrix(); + + this.clampFrame = new Float32Array(4); + + this.clampOffset = new Float32Array(2); + + this._lastTextureID = -1; + + this.update(); + } + + /** + * texture property + * @member {PIXI.Texture} + * @memberof PIXI.TextureTransform + */ + get texture() + { + return this._texture; + } + + /** + * sets texture value + * @param {PIXI.Texture} value texture to be set + */ + set texture(value) + { + this._texture = value; + this._lastTextureID = -1; + } + + /** + * updates matrices if texture was changed + * @param {boolean} forceUpdate if true, matrices will be updated any case + */ + update(forceUpdate) + { + const tex = this.texture; + + if (!tex || !tex.valid) + { + return; + } + + if (!forceUpdate + && this._lastTextureID === this.texture._updateID) + { + return; + } + + this._lastTextureID = this.texture._updateID; + + const uvs = this.texture._uvs; + + this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0); + + const orig = tex.orig; + const trim = tex.trim; + + if (trim) + { + tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, + -trim.x / trim.width, -trim.y / trim.height); + this.mapCoord.append(tempMat); + } + + const texBase = tex.baseTexture; + const frame = this.clampFrame; + const margin = tex.clampMargin / texBase.resolution; + const offset = tex.clampOffset; + + 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.clampOffset[0] = offset / texBase.realWidth; + this.clampOffset[1] = offset / texBase.realHeight; + } +} diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 244a134..e299e0e 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,5 +1,6 @@ import * as core from '../core'; import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import { default as TextureTransform } from './TextureTransform'; const tempPoint = new core.Point(); @@ -52,9 +53,9 @@ /** * transform that is applied to UV to get the texture coords - * @member {PIXI.TextureTransform} + * @member {PIXI.extras.TextureTransform} */ - this.uvTransform = new core.TextureTransform(texture); + this.uvTransform = new TextureTransform(texture); } /** diff --git a/src/core/index.js b/src/core/index.js index 1de5da5..f2b3af1 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -29,7 +29,6 @@ export { default as GraphicsRenderer } from './graphics/webgl/GraphicsRenderer'; export { default as CanvasGraphicsRenderer } from './graphics/canvas/CanvasGraphicsRenderer'; export { default as Texture } from './textures/Texture'; -export { default as TextureTransform } from './textures/TextureTransform'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as RenderTexture } from './textures/RenderTexture'; export { default as BaseRenderTexture } from './textures/BaseRenderTexture'; diff --git a/src/core/textures/TextureTransform.js b/src/core/textures/TextureTransform.js deleted file mode 100644 index 5b58021..0000000 --- a/src/core/textures/TextureTransform.js +++ /dev/null @@ -1,96 +0,0 @@ -import { default as Matrix } from '../math/Matrix'; - -const tempMat = new Matrix(); - -/** - * class controls uv transform and frame clamp for texture - */ -export default class TextureTransform { - /** - * - * @param {PIXI.Texture} texture observed texture - * @constructor - */ - constructor(texture) - { - this._texture = texture; - - this.mapCoord = new Matrix(); - - this.clampFrame = new Float32Array(4); - - this.clampOffset = new Float32Array(2); - - this._lastTextureID = -1; - - this.update(); - } - - /** - * texture property - * @member {PIXI.Texture} - * @memberof PIXI.TextureTransform - */ - get texture() - { - return this._texture; - } - - /** - * sets texture value - * @param {PIXI.Texture} value texture to be set - */ - set texture(value) - { - this._texture = value; - this._lastTextureID = -1; - } - - /** - * updates matrices if texture was changed - * @param {boolean} forceUpdate if true, matrices will be updated any case - */ - update(forceUpdate) - { - const tex = this.texture; - - if (!tex || !tex.valid) - { - return; - } - - if (!forceUpdate - && this._lastTextureID === this.texture._updateID) - { - return; - } - - this._lastTextureID = this.texture._updateID; - - const uvs = this.texture._uvs; - - this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0); - - const orig = tex.orig; - const trim = tex.trim; - - if (trim) - { - tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, - -trim.x / trim.width, -trim.y / trim.height); - this.mapCoord.append(tempMat); - } - - const texBase = tex.baseTexture; - const frame = this.clampFrame; - const margin = tex.clampMargin / texBase.resolution; - const offset = tex.clampOffset; - - 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.clampOffset[0] = offset / texBase.realWidth; - this.clampOffset[1] = offset / texBase.realHeight; - } -} diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index cfa8c0b..0ed66e6 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -27,7 +27,6 @@ this.y3 = 1; this.uvsUint32 = new Uint32Array(4); - this.uvsMatrix = null; } /** diff --git a/src/extras/TextureTransform.js b/src/extras/TextureTransform.js new file mode 100644 index 0000000..01f26a3 --- /dev/null +++ b/src/extras/TextureTransform.js @@ -0,0 +1,96 @@ +import { default as Matrix } from '../core/math/Matrix'; + +const tempMat = new Matrix(); + +/** + * class controls uv transform and frame clamp for texture + */ +export default class TextureTransform { + /** + * + * @param {PIXI.Texture} texture observed texture + * @constructor + */ + constructor(texture) + { + this._texture = texture; + + this.mapCoord = new Matrix(); + + this.clampFrame = new Float32Array(4); + + this.clampOffset = new Float32Array(2); + + this._lastTextureID = -1; + + this.update(); + } + + /** + * texture property + * @member {PIXI.Texture} + * @memberof PIXI.TextureTransform + */ + get texture() + { + return this._texture; + } + + /** + * sets texture value + * @param {PIXI.Texture} value texture to be set + */ + set texture(value) + { + this._texture = value; + this._lastTextureID = -1; + } + + /** + * updates matrices if texture was changed + * @param {boolean} forceUpdate if true, matrices will be updated any case + */ + update(forceUpdate) + { + const tex = this.texture; + + if (!tex || !tex.valid) + { + return; + } + + if (!forceUpdate + && this._lastTextureID === this.texture._updateID) + { + return; + } + + this._lastTextureID = this.texture._updateID; + + const uvs = this.texture._uvs; + + this.mapCoord.set(uvs.x1 - uvs.x0, uvs.y1 - uvs.y0, uvs.x3 - uvs.x0, uvs.y3 - uvs.y0, uvs.x0, uvs.y0); + + const orig = tex.orig; + const trim = tex.trim; + + if (trim) + { + tempMat.set(orig.width / trim.width, 0, 0, orig.height / trim.height, + -trim.x / trim.width, -trim.y / trim.height); + this.mapCoord.append(tempMat); + } + + const texBase = tex.baseTexture; + const frame = this.clampFrame; + const margin = tex.clampMargin / texBase.resolution; + const offset = tex.clampOffset; + + 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.clampOffset[0] = offset / texBase.realWidth; + this.clampOffset[1] = offset / texBase.realHeight; + } +} diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 244a134..e299e0e 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,5 +1,6 @@ import * as core from '../core'; import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import { default as TextureTransform } from './TextureTransform'; const tempPoint = new core.Point(); @@ -52,9 +53,9 @@ /** * transform that is applied to UV to get the texture coords - * @member {PIXI.TextureTransform} + * @member {PIXI.extras.TextureTransform} */ - this.uvTransform = new core.TextureTransform(texture); + this.uvTransform = new TextureTransform(texture); } /** diff --git a/src/extras/index.js b/src/extras/index.js index 1a90436..fc9da64 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,6 +1,7 @@ /** * @namespace PIXI.extras */ +export { default as TextureTransform } from './TextureTransform'; export { default as MovieClip } from './MovieClip'; export { default as TilingSprite } from './TilingSprite'; export { default as TilingRenderer } from './webgl/TilingRenderer';