@pixi/sprite-tiling
Advanced tools
Comparing version 6.5.3 to 7.0.0-alpha
/*! | ||
* @pixi/sprite-tiling - v6.5.3 | ||
* Compiled Fri, 09 Sep 2022 13:55:20 UTC | ||
* @pixi/sprite-tiling - v7.0.0-alpha | ||
* Compiled Fri, 09 Sep 2022 16:09:18 UTC | ||
* | ||
@@ -13,232 +13,108 @@ * @pixi/sprite-tiling is licensed under the MIT License. | ||
var core = require('@pixi/core'); | ||
var math = require('@pixi/math'); | ||
var sprite = require('@pixi/sprite'); | ||
var constants = require('@pixi/constants'); | ||
var utils = require('@pixi/utils'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var tempPoint = new math.Point(); | ||
/** | ||
* A tiling sprite is a fast way of rendering a tiling image. | ||
* @memberof PIXI | ||
*/ | ||
var TilingSprite = /** @class */ (function (_super) { | ||
__extends(TilingSprite, _super); | ||
/** | ||
* @param texture - The texture of the tiling sprite. | ||
* @param width - The width of the tiling sprite. | ||
* @param height - The height of the tiling sprite. | ||
*/ | ||
function TilingSprite(texture, width, height) { | ||
if (width === void 0) { width = 100; } | ||
if (height === void 0) { height = 100; } | ||
var _this = _super.call(this, texture) || this; | ||
_this.tileTransform = new math.Transform(); | ||
// The width of the tiling sprite | ||
_this._width = width; | ||
// The height of the tiling sprite | ||
_this._height = height; | ||
_this.uvMatrix = _this.texture.uvMatrix || new core.TextureMatrix(texture); | ||
/** | ||
* Plugin that is responsible for rendering this element. | ||
* Allows to customize the rendering process without overriding '_render' method. | ||
* @default 'tilingSprite' | ||
*/ | ||
_this.pluginName = 'tilingSprite'; | ||
_this.uvRespectAnchor = false; | ||
return _this; | ||
const tempPoint = new core.Point(); | ||
class TilingSprite extends sprite.Sprite { | ||
constructor(texture, width = 100, height = 100) { | ||
super(texture); | ||
this.tileTransform = new core.Transform(); | ||
this._width = width; | ||
this._height = height; | ||
this.uvMatrix = this.texture.uvMatrix || new core.TextureMatrix(texture); | ||
this.pluginName = "tilingSprite"; | ||
this.uvRespectAnchor = false; | ||
} | ||
get clampMargin() { | ||
return this.uvMatrix.clampMargin; | ||
} | ||
set clampMargin(value) { | ||
this.uvMatrix.clampMargin = value; | ||
this.uvMatrix.update(true); | ||
} | ||
get tileScale() { | ||
return this.tileTransform.scale; | ||
} | ||
set tileScale(value) { | ||
this.tileTransform.scale.copyFrom(value); | ||
} | ||
get tilePosition() { | ||
return this.tileTransform.position; | ||
} | ||
set tilePosition(value) { | ||
this.tileTransform.position.copyFrom(value); | ||
} | ||
_onTextureUpdate() { | ||
if (this.uvMatrix) { | ||
this.uvMatrix.texture = this._texture; | ||
} | ||
Object.defineProperty(TilingSprite.prototype, "clampMargin", { | ||
/** | ||
* Changes frame clamping in corresponding textureTransform, shortcut | ||
* Change to -0.5 to add a pixel to the edge, recommended for transparent trimmed textures in atlas | ||
* @default 0.5 | ||
* @member {number} | ||
*/ | ||
get: function () { | ||
return this.uvMatrix.clampMargin; | ||
}, | ||
set: function (value) { | ||
this.uvMatrix.clampMargin = value; | ||
this.uvMatrix.update(true); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(TilingSprite.prototype, "tileScale", { | ||
/** The scaling of the image that is being tiled. */ | ||
get: function () { | ||
return this.tileTransform.scale; | ||
}, | ||
set: function (value) { | ||
this.tileTransform.scale.copyFrom(value); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(TilingSprite.prototype, "tilePosition", { | ||
/** The offset of the image that is being tiled. */ | ||
get: function () { | ||
return this.tileTransform.position; | ||
}, | ||
set: function (value) { | ||
this.tileTransform.position.copyFrom(value); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* @protected | ||
*/ | ||
TilingSprite.prototype._onTextureUpdate = function () { | ||
if (this.uvMatrix) { | ||
this.uvMatrix.texture = this._texture; | ||
this._cachedTint = 16777215; | ||
} | ||
_render(renderer) { | ||
const texture = this._texture; | ||
if (!texture || !texture.valid) { | ||
return; | ||
} | ||
this.tileTransform.updateLocalTransform(); | ||
this.uvMatrix.update(); | ||
renderer.batch.setObjectRenderer(renderer.plugins[this.pluginName]); | ||
renderer.plugins[this.pluginName].render(this); | ||
} | ||
_calculateBounds() { | ||
const minX = this._width * -this._anchor._x; | ||
const minY = this._height * -this._anchor._y; | ||
const maxX = this._width * (1 - this._anchor._x); | ||
const maxY = this._height * (1 - this._anchor._y); | ||
this._bounds.addFrame(this.transform, minX, minY, maxX, maxY); | ||
} | ||
getLocalBounds(rect) { | ||
if (this.children.length === 0) { | ||
this._bounds.minX = this._width * -this._anchor._x; | ||
this._bounds.minY = this._height * -this._anchor._y; | ||
this._bounds.maxX = this._width * (1 - this._anchor._x); | ||
this._bounds.maxY = this._height * (1 - this._anchor._y); | ||
if (!rect) { | ||
if (!this._localBoundsRect) { | ||
this._localBoundsRect = new core.Rectangle(); | ||
} | ||
this._cachedTint = 0xFFFFFF; | ||
}; | ||
/** | ||
* Renders the object using the WebGL renderer | ||
* @param renderer - The renderer | ||
*/ | ||
TilingSprite.prototype._render = function (renderer) { | ||
// tweak our texture temporarily.. | ||
var texture = this._texture; | ||
if (!texture || !texture.valid) { | ||
return; | ||
} | ||
this.tileTransform.updateLocalTransform(); | ||
this.uvMatrix.update(); | ||
renderer.batch.setObjectRenderer(renderer.plugins[this.pluginName]); | ||
renderer.plugins[this.pluginName].render(this); | ||
}; | ||
/** Updates the bounds of the tiling sprite. */ | ||
TilingSprite.prototype._calculateBounds = function () { | ||
var minX = this._width * -this._anchor._x; | ||
var minY = this._height * -this._anchor._y; | ||
var maxX = this._width * (1 - this._anchor._x); | ||
var maxY = this._height * (1 - this._anchor._y); | ||
this._bounds.addFrame(this.transform, minX, minY, maxX, maxY); | ||
}; | ||
/** | ||
* Gets the local bounds of the sprite object. | ||
* @param rect - Optional output rectangle. | ||
* @returns The bounds. | ||
*/ | ||
TilingSprite.prototype.getLocalBounds = function (rect) { | ||
// we can do a fast local bounds if the sprite has no children! | ||
if (this.children.length === 0) { | ||
this._bounds.minX = this._width * -this._anchor._x; | ||
this._bounds.minY = this._height * -this._anchor._y; | ||
this._bounds.maxX = this._width * (1 - this._anchor._x); | ||
this._bounds.maxY = this._height * (1 - this._anchor._y); | ||
if (!rect) { | ||
if (!this._localBoundsRect) { | ||
this._localBoundsRect = new math.Rectangle(); | ||
} | ||
rect = this._localBoundsRect; | ||
} | ||
return this._bounds.getRectangle(rect); | ||
} | ||
return _super.prototype.getLocalBounds.call(this, rect); | ||
}; | ||
/** | ||
* Checks if a point is inside this tiling sprite. | ||
* @param point - The point to check. | ||
* @returns Whether or not the sprite contains the point. | ||
*/ | ||
TilingSprite.prototype.containsPoint = function (point) { | ||
this.worldTransform.applyInverse(point, tempPoint); | ||
var width = this._width; | ||
var height = this._height; | ||
var x1 = -width * this.anchor._x; | ||
if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { | ||
var y1 = -height * this.anchor._y; | ||
if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Destroys this sprite and optionally its texture and children | ||
* @param {object|boolean} [options] - Options parameter. A boolean will act as if all options | ||
* have been set to that value | ||
* @param {boolean} [options.children=false] - if set to true, all the children will have their destroy | ||
* method called as well. 'options' will be passed on to those calls. | ||
* @param {boolean} [options.texture=false] - Should it destroy the current texture of the sprite as well | ||
* @param {boolean} [options.baseTexture=false] - Should it destroy the base texture of the sprite as well | ||
*/ | ||
TilingSprite.prototype.destroy = function (options) { | ||
_super.prototype.destroy.call(this, options); | ||
this.tileTransform = null; | ||
this.uvMatrix = null; | ||
}; | ||
/** | ||
* Helper function that creates a new tiling sprite based on the source you provide. | ||
* The source can be - frame id, image url, video url, canvas element, video element, base texture | ||
* @static | ||
* @param {string|PIXI.Texture|HTMLCanvasElement|HTMLVideoElement} source - Source to create texture from | ||
* @param {object} options - See {@link PIXI.BaseTexture}'s constructor for options. | ||
* @param {number} options.width - required width of the tiling sprite | ||
* @param {number} options.height - required height of the tiling sprite | ||
* @returns {PIXI.TilingSprite} The newly created texture | ||
*/ | ||
TilingSprite.from = function (source, options) { | ||
var texture = (source instanceof core.Texture) | ||
? source | ||
: core.Texture.from(source, options); | ||
return new TilingSprite(texture, options.width, options.height); | ||
}; | ||
Object.defineProperty(TilingSprite.prototype, "width", { | ||
/** The width of the sprite, setting this will actually modify the scale to achieve the value set. */ | ||
get: function () { | ||
return this._width; | ||
}, | ||
set: function (value) { | ||
this._width = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(TilingSprite.prototype, "height", { | ||
/** The height of the TilingSprite, setting this will actually modify the scale to achieve the value set. */ | ||
get: function () { | ||
return this._height; | ||
}, | ||
set: function (value) { | ||
this._height = value; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return TilingSprite; | ||
}(sprite.Sprite)); | ||
rect = this._localBoundsRect; | ||
} | ||
return this._bounds.getRectangle(rect); | ||
} | ||
return super.getLocalBounds.call(this, rect); | ||
} | ||
containsPoint(point) { | ||
this.worldTransform.applyInverse(point, tempPoint); | ||
const width = this._width; | ||
const height = this._height; | ||
const x1 = -width * this.anchor._x; | ||
if (tempPoint.x >= x1 && tempPoint.x < x1 + width) { | ||
const y1 = -height * this.anchor._y; | ||
if (tempPoint.y >= y1 && tempPoint.y < y1 + height) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
destroy(options) { | ||
super.destroy(options); | ||
this.tileTransform = null; | ||
this.uvMatrix = null; | ||
} | ||
static from(source, options) { | ||
const texture = source instanceof core.Texture ? source : core.Texture.from(source, options); | ||
return new TilingSprite(texture, options.width, options.height); | ||
} | ||
get width() { | ||
return this._width; | ||
} | ||
set width(value) { | ||
this._width = value; | ||
} | ||
get height() { | ||
return this._height; | ||
} | ||
set height(value) { | ||
this._height = value; | ||
} | ||
} | ||
@@ -255,111 +131,76 @@ var fragmentSimpleSrc = "#version 100\n#define SHADER_NAME Tiling-Sprite-Simple-100\n\nprecision lowp float;\n\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform vec4 uColor;\n\nvoid main(void)\n{\n vec4 texSample = texture2D(uSampler, vTextureCoord);\n gl_FragColor = texSample * uColor;\n}\n"; | ||
var tempMat = new math.Matrix(); | ||
/** | ||
* WebGL renderer plugin for tiling sprites | ||
* @class | ||
* @memberof PIXI | ||
* @extends PIXI.ObjectRenderer | ||
*/ | ||
var TilingSpriteRenderer = /** @class */ (function (_super) { | ||
__extends(TilingSpriteRenderer, _super); | ||
/** | ||
* constructor for renderer | ||
* @param {PIXI.Renderer} renderer - The renderer this tiling awesomeness works for. | ||
*/ | ||
function TilingSpriteRenderer(renderer) { | ||
var _this = _super.call(this, renderer) || this; | ||
// WebGL version is not available during initialization! | ||
renderer.runners.contextChange.add(_this); | ||
_this.quad = new core.QuadUv(); | ||
/** | ||
* The WebGL state in which this renderer will work. | ||
* @member {PIXI.State} | ||
* @readonly | ||
*/ | ||
_this.state = core.State.for2d(); | ||
return _this; | ||
const tempMat = new core.Matrix(); | ||
class TilingSpriteRenderer extends core.ObjectRenderer { | ||
constructor(renderer) { | ||
super(renderer); | ||
renderer.runners.contextChange.add(this); | ||
this.quad = new core.QuadUv(); | ||
this.state = core.State.for2d(); | ||
} | ||
contextChange() { | ||
const renderer = this.renderer; | ||
const uniforms = { globals: renderer.globalUniforms }; | ||
this.simpleShader = core.Shader.from(gl1VertexSrc, fragmentSimpleSrc, uniforms); | ||
this.shader = renderer.context.webGLVersion > 1 ? core.Shader.from(gl2VertexSrc, gl2FragmentSrc, uniforms) : core.Shader.from(gl1VertexSrc, gl1FragmentSrc, uniforms); | ||
} | ||
render(ts) { | ||
const renderer = this.renderer; | ||
const quad = this.quad; | ||
let vertices = quad.vertices; | ||
vertices[0] = vertices[6] = ts._width * -ts.anchor.x; | ||
vertices[1] = vertices[3] = ts._height * -ts.anchor.y; | ||
vertices[2] = vertices[4] = ts._width * (1 - ts.anchor.x); | ||
vertices[5] = vertices[7] = ts._height * (1 - ts.anchor.y); | ||
const anchorX = ts.uvRespectAnchor ? ts.anchor.x : 0; | ||
const anchorY = ts.uvRespectAnchor ? ts.anchor.y : 0; | ||
vertices = quad.uvs; | ||
vertices[0] = vertices[6] = -anchorX; | ||
vertices[1] = vertices[3] = -anchorY; | ||
vertices[2] = vertices[4] = 1 - anchorX; | ||
vertices[5] = vertices[7] = 1 - anchorY; | ||
quad.invalidate(); | ||
const tex = ts._texture; | ||
const baseTex = tex.baseTexture; | ||
const premultiplied = baseTex.alphaMode > 0; | ||
const lt = ts.tileTransform.localTransform; | ||
const uv = ts.uvMatrix; | ||
let isSimple = baseTex.isPowerOfTwo && tex.frame.width === baseTex.width && tex.frame.height === baseTex.height; | ||
if (isSimple) { | ||
if (!baseTex._glTextures[renderer.CONTEXT_UID]) { | ||
if (baseTex.wrapMode === core.WRAP_MODES.CLAMP) { | ||
baseTex.wrapMode = core.WRAP_MODES.REPEAT; | ||
} | ||
} else { | ||
isSimple = baseTex.wrapMode !== core.WRAP_MODES.CLAMP; | ||
} | ||
} | ||
/** Creates shaders when context is initialized. */ | ||
TilingSpriteRenderer.prototype.contextChange = function () { | ||
var renderer = this.renderer; | ||
var uniforms = { globals: renderer.globalUniforms }; | ||
this.simpleShader = core.Shader.from(gl1VertexSrc, fragmentSimpleSrc, uniforms); | ||
this.shader = renderer.context.webGLVersion > 1 | ||
? core.Shader.from(gl2VertexSrc, gl2FragmentSrc, uniforms) | ||
: core.Shader.from(gl1VertexSrc, gl1FragmentSrc, uniforms); | ||
}; | ||
/** | ||
* @param {PIXI.TilingSprite} ts - tilingSprite to be rendered | ||
*/ | ||
TilingSpriteRenderer.prototype.render = function (ts) { | ||
var renderer = this.renderer; | ||
var quad = this.quad; | ||
var vertices = quad.vertices; | ||
vertices[0] = vertices[6] = (ts._width) * -ts.anchor.x; | ||
vertices[1] = vertices[3] = ts._height * -ts.anchor.y; | ||
vertices[2] = vertices[4] = (ts._width) * (1.0 - ts.anchor.x); | ||
vertices[5] = vertices[7] = ts._height * (1.0 - ts.anchor.y); | ||
var anchorX = ts.uvRespectAnchor ? ts.anchor.x : 0; | ||
var anchorY = ts.uvRespectAnchor ? ts.anchor.y : 0; | ||
vertices = quad.uvs; | ||
vertices[0] = vertices[6] = -anchorX; | ||
vertices[1] = vertices[3] = -anchorY; | ||
vertices[2] = vertices[4] = 1.0 - anchorX; | ||
vertices[5] = vertices[7] = 1.0 - anchorY; | ||
quad.invalidate(); | ||
var tex = ts._texture; | ||
var baseTex = tex.baseTexture; | ||
var premultiplied = baseTex.alphaMode > 0; | ||
var lt = ts.tileTransform.localTransform; | ||
var uv = ts.uvMatrix; | ||
var isSimple = baseTex.isPowerOfTwo | ||
&& tex.frame.width === baseTex.width && tex.frame.height === baseTex.height; | ||
// auto, force repeat wrapMode for big tiling textures | ||
if (isSimple) { | ||
if (!baseTex._glTextures[renderer.CONTEXT_UID]) { | ||
if (baseTex.wrapMode === constants.WRAP_MODES.CLAMP) { | ||
baseTex.wrapMode = constants.WRAP_MODES.REPEAT; | ||
} | ||
} | ||
else { | ||
isSimple = baseTex.wrapMode !== constants.WRAP_MODES.CLAMP; | ||
} | ||
} | ||
var shader = isSimple ? this.simpleShader : this.shader; | ||
var w = tex.width; | ||
var h = tex.height; | ||
var W = ts._width; | ||
var H = ts._height; | ||
tempMat.set(lt.a * w / W, lt.b * w / H, lt.c * h / W, lt.d * h / H, lt.tx / W, lt.ty / H); | ||
// that part is the same as above: | ||
// tempMat.identity(); | ||
// tempMat.scale(tex.width, tex.height); | ||
// tempMat.prepend(lt); | ||
// tempMat.scale(1.0 / ts._width, 1.0 / ts._height); | ||
tempMat.invert(); | ||
if (isSimple) { | ||
tempMat.prepend(uv.mapCoord); | ||
} | ||
else { | ||
shader.uniforms.uMapCoord = uv.mapCoord.toArray(true); | ||
shader.uniforms.uClampFrame = uv.uClampFrame; | ||
shader.uniforms.uClampOffset = uv.uClampOffset; | ||
} | ||
shader.uniforms.uTransform = tempMat.toArray(true); | ||
shader.uniforms.uColor = utils.premultiplyTintToRgba(ts.tint, ts.worldAlpha, shader.uniforms.uColor, premultiplied); | ||
shader.uniforms.translationMatrix = ts.transform.worldTransform.toArray(true); | ||
shader.uniforms.uSampler = tex; | ||
renderer.shader.bind(shader); | ||
renderer.geometry.bind(quad); | ||
this.state.blendMode = utils.correctBlendMode(ts.blendMode, premultiplied); | ||
renderer.state.set(this.state); | ||
renderer.geometry.draw(this.renderer.gl.TRIANGLES, 6, 0); | ||
}; | ||
/** @ignore */ | ||
TilingSpriteRenderer.extension = { | ||
name: 'tilingSprite', | ||
type: core.ExtensionType.RendererPlugin, | ||
}; | ||
return TilingSpriteRenderer; | ||
}(core.ObjectRenderer)); | ||
const shader = isSimple ? this.simpleShader : this.shader; | ||
const w = tex.width; | ||
const h = tex.height; | ||
const W = ts._width; | ||
const H = ts._height; | ||
tempMat.set(lt.a * w / W, lt.b * w / H, lt.c * h / W, lt.d * h / H, lt.tx / W, lt.ty / H); | ||
tempMat.invert(); | ||
if (isSimple) { | ||
tempMat.prepend(uv.mapCoord); | ||
} else { | ||
shader.uniforms.uMapCoord = uv.mapCoord.toArray(true); | ||
shader.uniforms.uClampFrame = uv.uClampFrame; | ||
shader.uniforms.uClampOffset = uv.uClampOffset; | ||
} | ||
shader.uniforms.uTransform = tempMat.toArray(true); | ||
shader.uniforms.uColor = core.utils.premultiplyTintToRgba(ts.tint, ts.worldAlpha, shader.uniforms.uColor, premultiplied); | ||
shader.uniforms.translationMatrix = ts.transform.worldTransform.toArray(true); | ||
shader.uniforms.uSampler = tex; | ||
renderer.shader.bind(shader); | ||
renderer.geometry.bind(quad); | ||
this.state.blendMode = core.utils.correctBlendMode(ts.blendMode, premultiplied); | ||
renderer.state.set(this.state); | ||
renderer.geometry.draw(this.renderer.gl.TRIANGLES, 6, 0); | ||
} | ||
} | ||
TilingSpriteRenderer.extension = { | ||
name: "tilingSprite", | ||
type: core.ExtensionType.RendererPlugin | ||
}; | ||
@@ -366,0 +207,0 @@ exports.TilingSprite = TilingSprite; |
@@ -1,9 +0,122 @@ | ||
/*! | ||
* @pixi/sprite-tiling - v6.5.3 | ||
* Compiled Fri, 09 Sep 2022 13:55:20 UTC | ||
"use strict";/*! | ||
* @pixi/sprite-tiling - v7.0.0-alpha | ||
* Compiled Fri, 09 Sep 2022 16:09:18 UTC | ||
* | ||
* @pixi/sprite-tiling is licensed under the MIT License. | ||
* http://www.opensource.org/licenses/mit-license | ||
*/ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@pixi/core"),t=require("@pixi/math"),r=require("@pixi/sprite"),n=require("@pixi/constants"),o=require("@pixi/utils"),i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},i(e,t)};function a(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var u=new t.Point,s=function(r){function n(n,o,i){void 0===o&&(o=100),void 0===i&&(i=100);var a=r.call(this,n)||this;return a.tileTransform=new t.Transform,a._width=o,a._height=i,a.uvMatrix=a.texture.uvMatrix||new e.TextureMatrix(n),a.pluginName="tilingSprite",a.uvRespectAnchor=!1,a}return a(n,r),Object.defineProperty(n.prototype,"clampMargin",{get:function(){return this.uvMatrix.clampMargin},set:function(e){this.uvMatrix.clampMargin=e,this.uvMatrix.update(!0)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"tileScale",{get:function(){return this.tileTransform.scale},set:function(e){this.tileTransform.scale.copyFrom(e)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"tilePosition",{get:function(){return this.tileTransform.position},set:function(e){this.tileTransform.position.copyFrom(e)},enumerable:!1,configurable:!0}),n.prototype._onTextureUpdate=function(){this.uvMatrix&&(this.uvMatrix.texture=this._texture),this._cachedTint=16777215},n.prototype._render=function(e){var t=this._texture;t&&t.valid&&(this.tileTransform.updateLocalTransform(),this.uvMatrix.update(),e.batch.setObjectRenderer(e.plugins[this.pluginName]),e.plugins[this.pluginName].render(this))},n.prototype._calculateBounds=function(){var e=this._width*-this._anchor._x,t=this._height*-this._anchor._y,r=this._width*(1-this._anchor._x),n=this._height*(1-this._anchor._y);this._bounds.addFrame(this.transform,e,t,r,n)},n.prototype.getLocalBounds=function(e){return 0===this.children.length?(this._bounds.minX=this._width*-this._anchor._x,this._bounds.minY=this._height*-this._anchor._y,this._bounds.maxX=this._width*(1-this._anchor._x),this._bounds.maxY=this._height*(1-this._anchor._y),e||(this._localBoundsRect||(this._localBoundsRect=new t.Rectangle),e=this._localBoundsRect),this._bounds.getRectangle(e)):r.prototype.getLocalBounds.call(this,e)},n.prototype.containsPoint=function(e){this.worldTransform.applyInverse(e,u);var t=this._width,r=this._height,n=-t*this.anchor._x;if(u.x>=n&&u.x<n+t){var o=-r*this.anchor._y;if(u.y>=o&&u.y<o+r)return!0}return!1},n.prototype.destroy=function(e){r.prototype.destroy.call(this,e),this.tileTransform=null,this.uvMatrix=null},n.from=function(t,r){return new n(t instanceof e.Texture?t:e.Texture.from(t,r),r.width,r.height)},Object.defineProperty(n.prototype,"width",{get:function(){return this._width},set:function(e){this._width=e},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this._height},set:function(e){this._height=e},enumerable:!1,configurable:!0}),n}(r.Sprite),c="#version 100\n#define SHADER_NAME Tiling-Sprite-100\n\nprecision lowp float;\n\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform mat3 uTransform;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy;\n}\n",l=new t.Matrix,d=function(t){function r(r){var n=t.call(this,r)||this;return r.runners.contextChange.add(n),n.quad=new e.QuadUv,n.state=e.State.for2d(),n}return a(r,t),r.prototype.contextChange=function(){var t=this.renderer,r={globals:t.globalUniforms};this.simpleShader=e.Shader.from(c,"#version 100\n#define SHADER_NAME Tiling-Sprite-Simple-100\n\nprecision lowp float;\n\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform vec4 uColor;\n\nvoid main(void)\n{\n vec4 texSample = texture2D(uSampler, vTextureCoord);\n gl_FragColor = texSample * uColor;\n}\n",r),this.shader=t.context.webGLVersion>1?e.Shader.from("#version 300 es\n#define SHADER_NAME Tiling-Sprite-300\n\nprecision lowp float;\n\nin vec2 aVertexPosition;\nin vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform mat3 uTransform;\n\nout vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy;\n}\n","#version 300 es\n#define SHADER_NAME Tiling-Sprite-100\n\nprecision lowp float;\n\nin vec2 vTextureCoord;\n\nout vec4 fragmentColor;\n\nuniform sampler2D uSampler;\nuniform vec4 uColor;\nuniform mat3 uMapCoord;\nuniform vec4 uClampFrame;\nuniform vec2 uClampOffset;\n\nvoid main(void)\n{\n vec2 coord = vTextureCoord + ceil(uClampOffset - vTextureCoord);\n coord = (uMapCoord * vec3(coord, 1.0)).xy;\n vec2 unclamped = coord;\n coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);\n\n vec4 texSample = texture(uSampler, coord, unclamped == coord ? 0.0f : -32.0f);// lod-bias very negative to force lod 0\n\n fragmentColor = texSample * uColor;\n}\n",r):e.Shader.from(c,"#version 100\n#ifdef GL_EXT_shader_texture_lod\n #extension GL_EXT_shader_texture_lod : enable\n#endif\n#define SHADER_NAME Tiling-Sprite-100\n\nprecision lowp float;\n\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform vec4 uColor;\nuniform mat3 uMapCoord;\nuniform vec4 uClampFrame;\nuniform vec2 uClampOffset;\n\nvoid main(void)\n{\n vec2 coord = vTextureCoord + ceil(uClampOffset - vTextureCoord);\n coord = (uMapCoord * vec3(coord, 1.0)).xy;\n vec2 unclamped = coord;\n coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);\n\n #ifdef GL_EXT_shader_texture_lod\n vec4 texSample = unclamped == coord\n ? texture2D(uSampler, coord) \n : texture2DLodEXT(uSampler, coord, 0);\n #else\n vec4 texSample = texture2D(uSampler, coord);\n #endif\n\n gl_FragColor = texSample * uColor;\n}\n",r)},r.prototype.render=function(e){var t=this.renderer,r=this.quad,i=r.vertices;i[0]=i[6]=e._width*-e.anchor.x,i[1]=i[3]=e._height*-e.anchor.y,i[2]=i[4]=e._width*(1-e.anchor.x),i[5]=i[7]=e._height*(1-e.anchor.y);var a=e.uvRespectAnchor?e.anchor.x:0,u=e.uvRespectAnchor?e.anchor.y:0;(i=r.uvs)[0]=i[6]=-a,i[1]=i[3]=-u,i[2]=i[4]=1-a,i[5]=i[7]=1-u,r.invalidate();var s=e._texture,c=s.baseTexture,d=c.alphaMode>0,h=e.tileTransform.localTransform,p=e.uvMatrix,m=c.isPowerOfTwo&&s.frame.width===c.width&&s.frame.height===c.height;m&&(c._glTextures[t.CONTEXT_UID]?m=c.wrapMode!==n.WRAP_MODES.CLAMP:c.wrapMode===n.WRAP_MODES.CLAMP&&(c.wrapMode=n.WRAP_MODES.REPEAT));var f=m?this.simpleShader:this.shader,v=s.width,x=s.height,_=e._width,g=e._height;l.set(h.a*v/_,h.b*v/g,h.c*x/_,h.d*x/g,h.tx/_,h.ty/g),l.invert(),m?l.prepend(p.mapCoord):(f.uniforms.uMapCoord=p.mapCoord.toArray(!0),f.uniforms.uClampFrame=p.uClampFrame,f.uniforms.uClampOffset=p.uClampOffset),f.uniforms.uTransform=l.toArray(!0),f.uniforms.uColor=o.premultiplyTintToRgba(e.tint,e.worldAlpha,f.uniforms.uColor,d),f.uniforms.translationMatrix=e.transform.worldTransform.toArray(!0),f.uniforms.uSampler=s,t.shader.bind(f),t.geometry.bind(r),this.state.blendMode=o.correctBlendMode(e.blendMode,d),t.state.set(this.state),t.geometry.draw(this.renderer.gl.TRIANGLES,6,0)},r.extension={name:"tilingSprite",type:e.ExtensionType.RendererPlugin},r}(e.ObjectRenderer);exports.TilingSprite=s,exports.TilingSpriteRenderer=d; | ||
*/Object.defineProperty(exports,"__esModule",{value:!0});var n=require("@pixi/core"),S=require("@pixi/sprite");const h=new n.Point;class f extends S.Sprite{constructor(e,r=100,i=100){super(e),this.tileTransform=new n.Transform,this._width=r,this._height=i,this.uvMatrix=this.texture.uvMatrix||new n.TextureMatrix(e),this.pluginName="tilingSprite",this.uvRespectAnchor=!1}get clampMargin(){return this.uvMatrix.clampMargin}set clampMargin(e){this.uvMatrix.clampMargin=e,this.uvMatrix.update(!0)}get tileScale(){return this.tileTransform.scale}set tileScale(e){this.tileTransform.scale.copyFrom(e)}get tilePosition(){return this.tileTransform.position}set tilePosition(e){this.tileTransform.position.copyFrom(e)}_onTextureUpdate(){this.uvMatrix&&(this.uvMatrix.texture=this._texture),this._cachedTint=16777215}_render(e){const r=this._texture;!r||!r.valid||(this.tileTransform.updateLocalTransform(),this.uvMatrix.update(),e.batch.setObjectRenderer(e.plugins[this.pluginName]),e.plugins[this.pluginName].render(this))}_calculateBounds(){const e=this._width*-this._anchor._x,r=this._height*-this._anchor._y,i=this._width*(1-this._anchor._x),t=this._height*(1-this._anchor._y);this._bounds.addFrame(this.transform,e,r,i,t)}getLocalBounds(e){return this.children.length===0?(this._bounds.minX=this._width*-this._anchor._x,this._bounds.minY=this._height*-this._anchor._y,this._bounds.maxX=this._width*(1-this._anchor._x),this._bounds.maxY=this._height*(1-this._anchor._y),e||(this._localBoundsRect||(this._localBoundsRect=new n.Rectangle),e=this._localBoundsRect),this._bounds.getRectangle(e)):super.getLocalBounds.call(this,e)}containsPoint(e){this.worldTransform.applyInverse(e,h);const r=this._width,i=this._height,t=-r*this.anchor._x;if(h.x>=t&&h.x<t+r){const l=-i*this.anchor._y;if(h.y>=l&&h.y<l+i)return!0}return!1}destroy(e){super.destroy(e),this.tileTransform=null,this.uvMatrix=null}static from(e,r){const i=e instanceof n.Texture?e:n.Texture.from(e,r);return new f(i,r.width,r.height)}get width(){return this._width}set width(e){this._width=e}get height(){return this._height}set height(e){this._height=e}}var w=`#version 100 | ||
#define SHADER_NAME Tiling-Sprite-Simple-100 | ||
precision lowp float; | ||
varying vec2 vTextureCoord; | ||
uniform sampler2D uSampler; | ||
uniform vec4 uColor; | ||
void main(void) | ||
{ | ||
vec4 texSample = texture2D(uSampler, vTextureCoord); | ||
gl_FragColor = texSample * uColor; | ||
} | ||
`,C=`#version 100 | ||
#define SHADER_NAME Tiling-Sprite-100 | ||
precision lowp float; | ||
attribute vec2 aVertexPosition; | ||
attribute vec2 aTextureCoord; | ||
uniform mat3 projectionMatrix; | ||
uniform mat3 translationMatrix; | ||
uniform mat3 uTransform; | ||
varying vec2 vTextureCoord; | ||
void main(void) | ||
{ | ||
gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); | ||
vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy; | ||
} | ||
`,y=`#version 100 | ||
#ifdef GL_EXT_shader_texture_lod | ||
#extension GL_EXT_shader_texture_lod : enable | ||
#endif | ||
#define SHADER_NAME Tiling-Sprite-100 | ||
precision lowp float; | ||
varying vec2 vTextureCoord; | ||
uniform sampler2D uSampler; | ||
uniform vec4 uColor; | ||
uniform mat3 uMapCoord; | ||
uniform vec4 uClampFrame; | ||
uniform vec2 uClampOffset; | ||
void main(void) | ||
{ | ||
vec2 coord = vTextureCoord + ceil(uClampOffset - vTextureCoord); | ||
coord = (uMapCoord * vec3(coord, 1.0)).xy; | ||
vec2 unclamped = coord; | ||
coord = clamp(coord, uClampFrame.xy, uClampFrame.zw); | ||
#ifdef GL_EXT_shader_texture_lod | ||
vec4 texSample = unclamped == coord | ||
? texture2D(uSampler, coord) | ||
: texture2DLodEXT(uSampler, coord, 0); | ||
#else | ||
vec4 texSample = texture2D(uSampler, coord); | ||
#endif | ||
gl_FragColor = texSample * uColor; | ||
} | ||
`,b=`#version 300 es | ||
#define SHADER_NAME Tiling-Sprite-300 | ||
precision lowp float; | ||
in vec2 aVertexPosition; | ||
in vec2 aTextureCoord; | ||
uniform mat3 projectionMatrix; | ||
uniform mat3 translationMatrix; | ||
uniform mat3 uTransform; | ||
out vec2 vTextureCoord; | ||
void main(void) | ||
{ | ||
gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); | ||
vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy; | ||
} | ||
`,R=`#version 300 es | ||
#define SHADER_NAME Tiling-Sprite-100 | ||
precision lowp float; | ||
in vec2 vTextureCoord; | ||
out vec4 fragmentColor; | ||
uniform sampler2D uSampler; | ||
uniform vec4 uColor; | ||
uniform mat3 uMapCoord; | ||
uniform vec4 uClampFrame; | ||
uniform vec2 uClampOffset; | ||
void main(void) | ||
{ | ||
vec2 coord = vTextureCoord + ceil(uClampOffset - vTextureCoord); | ||
coord = (uMapCoord * vec3(coord, 1.0)).xy; | ||
vec2 unclamped = coord; | ||
coord = clamp(coord, uClampFrame.xy, uClampFrame.zw); | ||
vec4 texSample = texture(uSampler, coord, unclamped == coord ? 0.0f : -32.0f);// lod-bias very negative to force lod 0 | ||
fragmentColor = texSample * uColor; | ||
} | ||
`;const m=new n.Matrix;class M extends n.ObjectRenderer{constructor(e){super(e),e.runners.contextChange.add(this),this.quad=new n.QuadUv,this.state=n.State.for2d()}contextChange(){const e=this.renderer,r={globals:e.globalUniforms};this.simpleShader=n.Shader.from(C,w,r),this.shader=e.context.webGLVersion>1?n.Shader.from(b,R,r):n.Shader.from(C,y,r)}render(e){const r=this.renderer,i=this.quad;let t=i.vertices;t[0]=t[6]=e._width*-e.anchor.x,t[1]=t[3]=e._height*-e.anchor.y,t[2]=t[4]=e._width*(1-e.anchor.x),t[5]=t[7]=e._height*(1-e.anchor.y);const l=e.uvRespectAnchor?e.anchor.x:0,v=e.uvRespectAnchor?e.anchor.y:0;t=i.uvs,t[0]=t[6]=-l,t[1]=t[3]=-v,t[2]=t[4]=1-l,t[5]=t[7]=1-v,i.invalidate();const s=e._texture,a=s.baseTexture,_=a.alphaMode>0,u=e.tileTransform.localTransform,d=e.uvMatrix;let c=a.isPowerOfTwo&&s.frame.width===a.width&&s.frame.height===a.height;c&&(a._glTextures[r.CONTEXT_UID]?c=a.wrapMode!==n.WRAP_MODES.CLAMP:a.wrapMode===n.WRAP_MODES.CLAMP&&(a.wrapMode=n.WRAP_MODES.REPEAT));const o=c?this.simpleShader:this.shader,g=s.width,T=s.height,p=e._width,x=e._height;m.set(u.a*g/p,u.b*g/x,u.c*T/p,u.d*T/x,u.tx/p,u.ty/x),m.invert(),c?m.prepend(d.mapCoord):(o.uniforms.uMapCoord=d.mapCoord.toArray(!0),o.uniforms.uClampFrame=d.uClampFrame,o.uniforms.uClampOffset=d.uClampOffset),o.uniforms.uTransform=m.toArray(!0),o.uniforms.uColor=n.utils.premultiplyTintToRgba(e.tint,e.worldAlpha,o.uniforms.uColor,_),o.uniforms.translationMatrix=e.transform.worldTransform.toArray(!0),o.uniforms.uSampler=s,r.shader.bind(o),r.geometry.bind(i),this.state.blendMode=n.utils.correctBlendMode(e.blendMode,_),r.state.set(this.state),r.geometry.draw(this.renderer.gl.TRIANGLES,6,0)}}M.extension={name:"tilingSprite",type:n.ExtensionType.RendererPlugin},exports.TilingSprite=f,exports.TilingSpriteRenderer=M; | ||
//# sourceMappingURL=sprite-tiling.min.js.map |
@@ -6,8 +6,8 @@ /// <reference path="./global.d.ts" /> | ||
import type { IDestroyOptions } from '@pixi/display'; | ||
import type { IPointData } from '@pixi/math'; | ||
import type { ISize } from '@pixi/math'; | ||
import type { IPointData } from '@pixi/core'; | ||
import type { ISize } from '@pixi/core'; | ||
import { ObjectRenderer } from '@pixi/core'; | ||
import type { ObservablePoint } from '@pixi/math'; | ||
import type { ObservablePoint } from '@pixi/core'; | ||
import { QuadUv } from '@pixi/core'; | ||
import { Rectangle } from '@pixi/math'; | ||
import { Rectangle } from '@pixi/core'; | ||
import type { Renderer } from '@pixi/core'; | ||
@@ -20,3 +20,3 @@ import { Shader } from '@pixi/core'; | ||
import type { TextureSource } from '@pixi/core'; | ||
import { Transform } from '@pixi/math'; | ||
import { Transform } from '@pixi/core'; | ||
@@ -23,0 +23,0 @@ export declare interface TilingSprite extends GlobalMixins.TilingSprite { |
{ | ||
"name": "@pixi/sprite-tiling", | ||
"version": "6.5.3", | ||
"version": "7.0.0-alpha", | ||
"main": "dist/cjs/sprite-tiling.js", | ||
"module": "dist/esm/sprite-tiling.mjs", | ||
"bundle": "dist/browser/sprite-tiling.js", | ||
"types": "index.d.ts", | ||
@@ -36,15 +35,11 @@ "exports": { | ||
"files": [ | ||
"lib", | ||
"dist", | ||
"*.d.ts" | ||
], | ||
"peerDependencies": { | ||
"@pixi/constants": "6.5.3", | ||
"@pixi/core": "6.5.3", | ||
"@pixi/display": "6.5.3", | ||
"@pixi/math": "6.5.3", | ||
"@pixi/sprite": "6.5.3", | ||
"@pixi/utils": "6.5.3" | ||
}, | ||
"gitHead": "28e6b2841a65837a5e2873a3d5a9c27cabbe795a" | ||
"pixiRequirements": [ | ||
"@pixi/core", | ||
"@pixi/display", | ||
"@pixi/sprite" | ||
], | ||
"gitHead": "da993226df64b804a9c00ed9ee4d011191467b8a" | ||
} |
@@ -12,6 +12,3 @@ # @pixi/sprite-tiling | ||
```js | ||
import { TilingSpriteRenderer } from '@pixi/sprite-tiling'; | ||
import { extensions } from '@pixi/core'; | ||
extensions.add(TilingSpriteRenderer); | ||
import '@pixi/sprite-tiling'; | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
125504
13
764
2
13
1