dmpixi
Version:
多卖pixi 淘宝小程序 支持骨骼动画,整屏滚动等
1,061 lines • 169 kB
JavaScript
import * as PIXI from '@tbminiapp/pixi-miniprogram-engine';
var pixi_projection;
(function (pixi_projection) {
var utils;
(function (utils) {
function createIndicesForQuads(size) {
var totalIndices = size * 6;
var indices = new Uint16Array(totalIndices);
for (var i = 0, j = 0; i < totalIndices; i += 6, j += 4) {
indices[i + 0] = j + 0;
indices[i + 1] = j + 1;
indices[i + 2] = j + 2;
indices[i + 3] = j + 0;
indices[i + 4] = j + 2;
indices[i + 5] = j + 3;
}
return indices;
}
utils.createIndicesForQuads = createIndicesForQuads;
function isPow2(v) {
return !(v & (v - 1)) && (!!v);
}
utils.isPow2 = isPow2;
function nextPow2(v) {
v += +(v === 0);
--v;
v |= v >>> 1;
v |= v >>> 2;
v |= v >>> 4;
v |= v >>> 8;
v |= v >>> 16;
return v + 1;
}
utils.nextPow2 = nextPow2;
function log2(v) {
var r, shift;
r = +(v > 0xFFFF) << 4;
v >>>= r;
shift = +(v > 0xFF) << 3;
v >>>= shift;
r |= shift;
shift = +(v > 0xF) << 2;
v >>>= shift;
r |= shift;
shift = +(v > 0x3) << 1;
v >>>= shift;
r |= shift;
return r | (v >> 1);
}
utils.log2 = log2;
function getIntersectionFactor(p1, p2, p3, p4, out) {
var A1 = p2.x - p1.x, B1 = p3.x - p4.x, C1 = p3.x - p1.x;
var A2 = p2.y - p1.y, B2 = p3.y - p4.y, C2 = p3.y - p1.y;
var D = A1 * B2 - A2 * B1;
if (Math.abs(D) < 1e-7) {
out.x = A1;
out.y = A2;
return 0;
}
var T = C1 * B2 - C2 * B1;
var U = A1 * C2 - A2 * C1;
var t = T / D, u = U / D;
if (u < (1e-6) || u - 1 > -1e-6) {
return -1;
}
out.x = p1.x + t * (p2.x - p1.x);
out.y = p1.y + t * (p2.y - p1.y);
return 1;
}
utils.getIntersectionFactor = getIntersectionFactor;
function getPositionFromQuad(p, anchor, out) {
out = out || new PIXI.Point();
var a1 = 1.0 - anchor.x, a2 = 1.0 - a1;
var b1 = 1.0 - anchor.y, b2 = 1.0 - b1;
out.x = (p[0].x * a1 + p[1].x * a2) * b1 + (p[3].x * a1 + p[2].x * a2) * b2;
out.y = (p[0].y * a1 + p[1].y * a2) * b1 + (p[3].y * a1 + p[2].y * a2) * b2;
return out;
}
utils.getPositionFromQuad = getPositionFromQuad;
})(utils = pixi_projection.utils || (pixi_projection.utils = {}));
})(pixi_projection || (pixi_projection = {}));
PIXI.projection = pixi_projection;
var pixi_projection;
(function (pixi_projection) {
var AbstractProjection = (function () {
function AbstractProjection(legacy, enable) {
if (enable === void 0) { enable = true; }
this._enabled = false;
this.legacy = legacy;
if (enable) {
this.enabled = true;
}
this.legacy.proj = this;
}
Object.defineProperty(AbstractProjection.prototype, "enabled", {
get: function () {
return this._enabled;
},
set: function (value) {
this._enabled = value;
},
enumerable: true,
configurable: true
});
AbstractProjection.prototype.clear = function () {
};
return AbstractProjection;
}());
pixi_projection.AbstractProjection = AbstractProjection;
var TRANSFORM_STEP;
(function (TRANSFORM_STEP) {
TRANSFORM_STEP[TRANSFORM_STEP["NONE"] = 0] = "NONE";
TRANSFORM_STEP[TRANSFORM_STEP["BEFORE_PROJ"] = 4] = "BEFORE_PROJ";
TRANSFORM_STEP[TRANSFORM_STEP["PROJ"] = 5] = "PROJ";
TRANSFORM_STEP[TRANSFORM_STEP["ALL"] = 9] = "ALL";
})(TRANSFORM_STEP = pixi_projection.TRANSFORM_STEP || (pixi_projection.TRANSFORM_STEP = {}));
})(pixi_projection || (pixi_projection = {}));
var __extends = (this && this.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var pixi_projection;
(function (pixi_projection) {
function transformHack(parentTransform) {
var proj = this.proj;
var ta = this;
var pwid = parentTransform._worldID;
var lt = ta.localTransform;
if (ta._localID !== ta._currentLocalID) {
lt.a = ta._cx * ta.scale._x;
lt.b = ta._sx * ta.scale._x;
lt.c = ta._cy * ta.scale._y;
lt.d = ta._sy * ta.scale._y;
lt.tx = ta.position._x - ((ta.pivot._x * lt.a) + (ta.pivot._y * lt.c));
lt.ty = ta.position._y - ((ta.pivot._x * lt.b) + (ta.pivot._y * lt.d));
ta._currentLocalID = ta._localID;
proj._currentProjID = -1;
}
var _matrixID = proj._projID;
if (proj._currentProjID !== _matrixID) {
proj._currentProjID = _matrixID;
proj.updateLocalTransform(lt);
ta._parentID = -1;
}
if (ta._parentID !== pwid) {
var pp = parentTransform.proj;
if (pp && !pp._affine) {
proj.world.setToMult(pp.world, proj.local);
}
else {
proj.world.setToMultLegacy(parentTransform.worldTransform, proj.local);
}
proj.world.copy(ta.worldTransform, proj._affine);
ta._parentID = pwid;
ta._worldID++;
}
}
var LinearProjection = (function (_super) {
__extends(LinearProjection, _super);
function LinearProjection() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._projID = 0;
_this._currentProjID = -1;
_this._affine = pixi_projection.AFFINE.NONE;
return _this;
}
LinearProjection.prototype.updateLocalTransform = function (lt) {
};
Object.defineProperty(LinearProjection.prototype, "affine", {
get: function () {
return this._affine;
},
set: function (value) {
if (this._affine == value)
return;
this._affine = value;
this._currentProjID = -1;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LinearProjection.prototype, "enabled", {
set: function (value) {
if (value === this._enabled) {
return;
}
this._enabled = value;
if (value) {
this.legacy.updateTransform = transformHack;
this.legacy._parentID = -1;
}
else {
this.legacy.updateTransform = PIXI.TransformStatic.prototype.updateTransform;
this.legacy._parentID = -1;
}
},
enumerable: true,
configurable: true
});
LinearProjection.prototype.clear = function () {
this._currentProjID = -1;
this._projID = 0;
};
return LinearProjection;
}(pixi_projection.AbstractProjection));
pixi_projection.LinearProjection = LinearProjection;
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var webgl;
(function (webgl) {
var BatchBuffer = (function () {
function BatchBuffer(size) {
this.vertices = new ArrayBuffer(size);
this.float32View = new Float32Array(this.vertices);
this.uint32View = new Uint32Array(this.vertices);
}
BatchBuffer.prototype.destroy = function () {
this.vertices = null;
};
return BatchBuffer;
}());
webgl.BatchBuffer = BatchBuffer;
})(webgl = pixi_projection.webgl || (pixi_projection.webgl = {}));
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var webgl;
(function (webgl) {
function generateMultiTextureShader(vertexSrc, fragmentSrc, gl, maxTextures) {
fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures + '');
fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures));
var shader = new PIXI.Shader(gl, vertexSrc, fragmentSrc);
var sampleValues = new Int32Array(maxTextures);
for (var i = 0; i < maxTextures; i++) {
sampleValues[i] = i;
}
shader.bind();
shader.uniforms.uSamplers = sampleValues;
return shader;
}
webgl.generateMultiTextureShader = generateMultiTextureShader;
function generateSampleSrc(maxTextures) {
var src = '';
src += '\n';
src += '\n';
for (var i = 0; i < maxTextures; i++) {
if (i > 0) {
src += '\nelse ';
}
if (i < maxTextures - 1) {
src += "if(textureId == " + i + ".0)";
}
src += '\n{';
src += "\n\tcolor = texture2D(uSamplers[" + i + "], textureCoord);";
src += '\n}';
}
src += '\n';
src += '\n';
return src;
}
})(webgl = pixi_projection.webgl || (pixi_projection.webgl = {}));
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var webgl;
(function (webgl) {
var ObjectRenderer = PIXI.ObjectRenderer;
var settings = PIXI.settings;
var GLBuffer = PIXI.glCore.GLBuffer;
var premultiplyTint = PIXI.utils.premultiplyTint;
var premultiplyBlendMode = PIXI.utils.premultiplyBlendMode;
var TICK = 0;
var BatchGroup = (function () {
function BatchGroup() {
this.textures = [];
this.textureCount = 0;
this.ids = [];
this.size = 0;
this.start = 0;
this.blend = PIXI.BLEND_MODES.NORMAL;
this.uniforms = null;
}
return BatchGroup;
}());
webgl.BatchGroup = BatchGroup;
var MultiTextureSpriteRenderer = (function (_super) {
__extends(MultiTextureSpriteRenderer, _super);
function MultiTextureSpriteRenderer(renderer) {
var _this = _super.call(this, renderer) || this;
_this.shaderVert = '';
_this.shaderFrag = '';
_this.MAX_TEXTURES_LOCAL = 32;
_this.vertSize = 5;
_this.vertByteSize = _this.vertSize * 4;
_this.size = settings.SPRITE_BATCH_SIZE;
_this.currentIndex = 0;
_this.sprites = [];
_this.vertexBuffers = [];
_this.vaos = [];
_this.vaoMax = 2;
_this.vertexCount = 0;
_this.MAX_TEXTURES = 1;
_this.indices = pixi_projection.utils.createIndicesForQuads(_this.size);
_this.groups = [];
for (var k = 0; k < _this.size; k++) {
_this.groups[k] = new BatchGroup();
}
_this.vaoMax = 2;
_this.vertexCount = 0;
_this.renderer.on('prerender', _this.onPrerender, _this);
return _this;
}
MultiTextureSpriteRenderer.prototype.getUniforms = function (spr) {
return null;
};
MultiTextureSpriteRenderer.prototype.syncUniforms = function (obj) {
if (!obj)
return;
var sh = this.shader;
for (var key in obj) {
sh.uniforms[key] = obj[key];
}
};
MultiTextureSpriteRenderer.prototype.onContextChange = function () {
var gl = this.renderer.gl;
this.MAX_TEXTURES = Math.min(this.MAX_TEXTURES_LOCAL, this.renderer.plugins['sprite'].MAX_TEXTURES);
this.shader = webgl.generateMultiTextureShader(this.shaderVert, this.shaderFrag, gl, this.MAX_TEXTURES);
this.indexBuffer = GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW);
this.renderer.bindVao(null);
var attrs = this.shader.attributes;
for (var i = 0; i < this.vaoMax; i++) {
var vertexBuffer = this.vertexBuffers[i] = GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW);
this.vaos[i] = this.createVao(vertexBuffer);
}
if (!this.buffers) {
this.buffers = [];
for (var i = 1; i <= pixi_projection.utils.nextPow2(this.size); i *= 2) {
this.buffers.push(new webgl.BatchBuffer(i * 4 * this.vertByteSize));
}
}
this.vao = this.vaos[0];
};
MultiTextureSpriteRenderer.prototype.onPrerender = function () {
this.vertexCount = 0;
};
MultiTextureSpriteRenderer.prototype.render = function (sprite) {
if (this.currentIndex >= this.size) {
this.flush();
}
if (!sprite._texture._uvs) {
return;
}
if (!sprite._texture.baseTexture) {
return;
}
this.sprites[this.currentIndex++] = sprite;
};
MultiTextureSpriteRenderer.prototype.flush = function () {
if (this.currentIndex === 0) {
return;
}
var gl = this.renderer.gl;
var MAX_TEXTURES = this.MAX_TEXTURES;
var np2 = pixi_projection.utils.nextPow2(this.currentIndex);
var log2 = pixi_projection.utils.log2(np2);
var buffer = this.buffers[log2];
var sprites = this.sprites;
var groups = this.groups;
var float32View = buffer.float32View;
var uint32View = buffer.uint32View;
var index = 0;
var nextTexture;
var currentTexture;
var currentUniforms = null;
var groupCount = 1;
var textureCount = 0;
var currentGroup = groups[0];
var vertexData;
var uvs;
var blendMode = premultiplyBlendMode[sprites[0]._texture.baseTexture.premultipliedAlpha ? 1 : 0][sprites[0].blendMode];
currentGroup.textureCount = 0;
currentGroup.start = 0;
currentGroup.blend = blendMode;
TICK++;
var i;
for (i = 0; i < this.currentIndex; ++i) {
var sprite = sprites[i];
sprites[i] = null;
nextTexture = sprite._texture.baseTexture;
var spriteBlendMode = premultiplyBlendMode[Number(nextTexture.premultipliedAlpha)][sprite.blendMode];
if (blendMode !== spriteBlendMode) {
blendMode = spriteBlendMode;
currentTexture = null;
textureCount = MAX_TEXTURES;
TICK++;
}
var uniforms = this.getUniforms(sprite);
if (currentUniforms !== uniforms) {
currentUniforms = uniforms;
currentTexture = null;
textureCount = MAX_TEXTURES;
TICK++;
}
if (currentTexture !== nextTexture) {
currentTexture = nextTexture;
if (nextTexture._enabled !== TICK) {
if (textureCount === MAX_TEXTURES) {
TICK++;
textureCount = 0;
currentGroup.size = i - currentGroup.start;
currentGroup = groups[groupCount++];
currentGroup.textureCount = 0;
currentGroup.blend = blendMode;
currentGroup.start = i;
currentGroup.uniforms = currentUniforms;
}
nextTexture._enabled = TICK;
nextTexture._virtalBoundId = textureCount;
currentGroup.textures[currentGroup.textureCount++] = nextTexture;
textureCount++;
}
}
var alpha = Math.min(sprite.worldAlpha, 1.0);
var argb = alpha < 1.0 && nextTexture.premultipliedAlpha ? premultiplyTint(sprite._tintRGB, alpha)
: sprite._tintRGB + (alpha * 255 << 24);
this.fillVertices(float32View, uint32View, index, sprite, argb, nextTexture._virtalBoundId);
index += this.vertSize * 4;
}
currentGroup.size = i - currentGroup.start;
if (!settings.CAN_UPLOAD_SAME_BUFFER) {
if (this.vaoMax <= this.vertexCount) {
this.vaoMax++;
var attrs = this.shader.attributes;
var vertexBuffer = this.vertexBuffers[this.vertexCount] = GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW);
this.vaos[this.vertexCount] = this.createVao(vertexBuffer);
}
this.renderer.bindVao(this.vaos[this.vertexCount]);
this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0, false);
this.vertexCount++;
}
else {
this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0, true);
}
currentUniforms = null;
for (i = 0; i < groupCount; i++) {
var group = groups[i];
var groupTextureCount = group.textureCount;
if (group.uniforms !== currentUniforms) {
this.syncUniforms(group.uniforms);
}
for (var j = 0; j < groupTextureCount; j++) {
this.renderer.bindTexture(group.textures[j], j, true);
group.textures[j]._virtalBoundId = -1;
var v = this.shader.uniforms.samplerSize;
if (v) {
v[0] = group.textures[j].realWidth;
v[1] = group.textures[j].realHeight;
this.shader.uniforms.samplerSize = v;
}
}
this.renderer.state.setBlendMode(group.blend);
gl.drawElements(gl.TRIANGLES, group.size * 6, gl.UNSIGNED_SHORT, group.start * 6 * 2);
}
this.currentIndex = 0;
};
MultiTextureSpriteRenderer.prototype.start = function () {
this.renderer.bindShader(this.shader);
if (settings.CAN_UPLOAD_SAME_BUFFER) {
this.renderer.bindVao(this.vaos[this.vertexCount]);
this.vertexBuffers[this.vertexCount].bind();
}
};
MultiTextureSpriteRenderer.prototype.stop = function () {
this.flush();
};
MultiTextureSpriteRenderer.prototype.destroy = function () {
for (var i = 0; i < this.vaoMax; i++) {
if (this.vertexBuffers[i]) {
this.vertexBuffers[i].destroy();
}
if (this.vaos[i]) {
this.vaos[i].destroy();
}
}
if (this.indexBuffer) {
this.indexBuffer.destroy();
}
this.renderer.off('prerender', this.onPrerender, this);
_super.prototype.destroy.call(this);
if (this.shader) {
this.shader.destroy();
this.shader = null;
}
this.vertexBuffers = null;
this.vaos = null;
this.indexBuffer = null;
this.indices = null;
this.sprites = null;
for (var i = 0; i < this.buffers.length; ++i) {
this.buffers[i].destroy();
}
};
return MultiTextureSpriteRenderer;
}(ObjectRenderer));
webgl.MultiTextureSpriteRenderer = MultiTextureSpriteRenderer;
})(webgl = pixi_projection.webgl || (pixi_projection.webgl = {}));
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var p = [new PIXI.Point(), new PIXI.Point(), new PIXI.Point(), new PIXI.Point()];
var a = [0, 0, 0, 0];
var Surface = (function () {
function Surface() {
this.surfaceID = "default";
this._updateID = 0;
this.vertexSrc = "";
this.fragmentSrc = "";
}
Surface.prototype.fillUniforms = function (uniforms) {
};
Surface.prototype.clear = function () {
};
Surface.prototype.boundsQuad = function (v, out, after) {
var minX = out[0], minY = out[1];
var maxX = out[0], maxY = out[1];
for (var i = 2; i < 8; i += 2) {
if (minX > out[i])
minX = out[i];
if (maxX < out[i])
maxX = out[i];
if (minY > out[i + 1])
minY = out[i + 1];
if (maxY < out[i + 1])
maxY = out[i + 1];
}
p[0].set(minX, minY);
this.apply(p[0], p[0]);
p[1].set(maxX, minY);
this.apply(p[1], p[1]);
p[2].set(maxX, maxY);
this.apply(p[2], p[2]);
p[3].set(minX, maxY);
this.apply(p[3], p[3]);
if (after) {
after.apply(p[0], p[0]);
after.apply(p[1], p[1]);
after.apply(p[2], p[2]);
after.apply(p[3], p[3]);
out[0] = p[0].x;
out[1] = p[0].y;
out[2] = p[1].x;
out[3] = p[1].y;
out[4] = p[2].x;
out[5] = p[2].y;
out[6] = p[3].x;
out[7] = p[3].y;
}
else {
for (var i = 1; i <= 3; i++) {
if (p[i].y < p[0].y || p[i].y == p[0].y && p[i].x < p[0].x) {
var t = p[0];
p[0] = p[i];
p[i] = t;
}
}
for (var i = 1; i <= 3; i++) {
a[i] = Math.atan2(p[i].y - p[0].y, p[i].x - p[0].x);
}
for (var i = 1; i <= 3; i++) {
for (var j = i + 1; j <= 3; j++) {
if (a[i] > a[j]) {
var t = p[i];
p[i] = p[j];
p[j] = t;
var t2 = a[i];
a[i] = a[j];
a[j] = t2;
}
}
}
out[0] = p[0].x;
out[1] = p[0].y;
out[2] = p[1].x;
out[3] = p[1].y;
out[4] = p[2].x;
out[5] = p[2].y;
out[6] = p[3].x;
out[7] = p[3].y;
if ((p[3].x - p[2].x) * (p[1].y - p[2].y) - (p[1].x - p[2].x) * (p[3].y - p[2].y) < 0) {
out[4] = p[3].x;
out[5] = p[3].y;
return;
}
}
};
return Surface;
}());
pixi_projection.Surface = Surface;
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var tempMat = new PIXI.Matrix();
var tempRect = new PIXI.Rectangle();
var tempPoint = new PIXI.Point();
var BilinearSurface = (function (_super) {
__extends(BilinearSurface, _super);
function BilinearSurface() {
var _this = _super.call(this) || this;
_this.distortion = new PIXI.Point();
return _this;
}
BilinearSurface.prototype.clear = function () {
this.distortion.set(0, 0);
};
BilinearSurface.prototype.apply = function (pos, newPos) {
newPos = newPos || new PIXI.Point();
var d = this.distortion;
var m = pos.x * pos.y;
newPos.x = pos.x + d.x * m;
newPos.y = pos.y + d.y * m;
return newPos;
};
BilinearSurface.prototype.applyInverse = function (pos, newPos) {
newPos = newPos || new PIXI.Point();
var vx = pos.x, vy = pos.y;
var dx = this.distortion.x, dy = this.distortion.y;
if (dx == 0.0) {
newPos.x = vx;
newPos.y = vy / (1.0 + dy * vx);
}
else if (dy == 0.0) {
newPos.y = vy;
newPos.x = vx / (1.0 + dx * vy);
}
else {
var b = (vy * dx - vx * dy + 1.0) * 0.5 / dy;
var d = b * b + vx / dy;
if (d <= 0.00001) {
newPos.set(NaN, NaN);
return;
}
if (dy > 0.0) {
newPos.x = -b + Math.sqrt(d);
}
else {
newPos.x = -b - Math.sqrt(d);
}
newPos.y = (vx / newPos.x - 1.0) / dx;
}
return newPos;
};
BilinearSurface.prototype.mapSprite = function (sprite, quad, outTransform) {
var tex = sprite.texture;
tempRect.x = -sprite.anchor.x * tex.orig.width;
tempRect.y = -sprite.anchor.y * tex.orig.height;
tempRect.width = tex.orig.width;
tempRect.height = tex.orig.height;
return this.mapQuad(tempRect, quad, outTransform || sprite.transform);
};
BilinearSurface.prototype.mapQuad = function (rect, quad, outTransform) {
var ax = -rect.x / rect.width;
var ay = -rect.y / rect.height;
var ax2 = (1.0 - rect.x) / rect.width;
var ay2 = (1.0 - rect.y) / rect.height;
var up1x = (quad[0].x * (1.0 - ax) + quad[1].x * ax);
var up1y = (quad[0].y * (1.0 - ax) + quad[1].y * ax);
var up2x = (quad[0].x * (1.0 - ax2) + quad[1].x * ax2);
var up2y = (quad[0].y * (1.0 - ax2) + quad[1].y * ax2);
var down1x = (quad[3].x * (1.0 - ax) + quad[2].x * ax);
var down1y = (quad[3].y * (1.0 - ax) + quad[2].y * ax);
var down2x = (quad[3].x * (1.0 - ax2) + quad[2].x * ax2);
var down2y = (quad[3].y * (1.0 - ax2) + quad[2].y * ax2);
var x00 = up1x * (1.0 - ay) + down1x * ay;
var y00 = up1y * (1.0 - ay) + down1y * ay;
var x10 = up2x * (1.0 - ay) + down2x * ay;
var y10 = up2y * (1.0 - ay) + down2y * ay;
var x01 = up1x * (1.0 - ay2) + down1x * ay2;
var y01 = up1y * (1.0 - ay2) + down1y * ay2;
var x11 = up2x * (1.0 - ay2) + down2x * ay2;
var y11 = up2y * (1.0 - ay2) + down2y * ay2;
var mat = tempMat;
mat.tx = x00;
mat.ty = y00;
mat.a = x10 - x00;
mat.b = y10 - y00;
mat.c = x01 - x00;
mat.d = y01 - y00;
tempPoint.set(x11, y11);
mat.applyInverse(tempPoint, tempPoint);
this.distortion.set(tempPoint.x - 1, tempPoint.y - 1);
outTransform.setFromMatrix(mat);
return this;
};
BilinearSurface.prototype.fillUniforms = function (uniforms) {
uniforms.distortion = uniforms.distortion || new Float32Array([0, 0, 0, 0]);
var ax = Math.abs(this.distortion.x);
var ay = Math.abs(this.distortion.y);
uniforms.distortion[0] = ax * 10000 <= ay ? 0 : this.distortion.x;
uniforms.distortion[1] = ay * 10000 <= ax ? 0 : this.distortion.y;
uniforms.distortion[2] = 1.0 / uniforms.distortion[0];
uniforms.distortion[3] = 1.0 / uniforms.distortion[1];
};
return BilinearSurface;
}(pixi_projection.Surface));
pixi_projection.BilinearSurface = BilinearSurface;
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var Container2s = (function (_super) {
__extends(Container2s, _super);
function Container2s() {
var _this = _super.call(this) || this;
_this.proj = new pixi_projection.ProjectionSurface(_this.transform);
return _this;
}
Object.defineProperty(Container2s.prototype, "worldTransform", {
get: function () {
return this.proj;
},
enumerable: true,
configurable: true
});
return Container2s;
}(PIXI.Container));
pixi_projection.Container2s = Container2s;
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var fun = PIXI.TransformStatic.prototype.updateTransform;
function transformHack(parentTransform) {
var proj = this.proj;
var pp = parentTransform.proj;
var ta = this;
if (!pp) {
fun.call(this, parentTransform);
proj._activeProjection = null;
return;
}
if (pp._surface) {
proj._activeProjection = pp;
this.updateLocalTransform();
this.localTransform.copy(this.worldTransform);
if (ta._parentID < 0) {
++ta._worldID;
}
return;
}
fun.call(this, parentTransform);
proj._activeProjection = pp._activeProjection;
}
var ProjectionSurface = (function (_super) {
__extends(ProjectionSurface, _super);
function ProjectionSurface(legacy, enable) {
var _this = _super.call(this, legacy, enable) || this;
_this._surface = null;
_this._activeProjection = null;
_this._currentSurfaceID = -1;
_this._currentLegacyID = -1;
_this._lastUniforms = null;
return _this;
}
Object.defineProperty(ProjectionSurface.prototype, "enabled", {
set: function (value) {
if (value === this._enabled) {
return;
}
this._enabled = value;
if (value) {
this.legacy.updateTransform = transformHack;
this.legacy._parentID = -1;
}
else {
this.legacy.updateTransform = PIXI.TransformStatic.prototype.updateTransform;
this.legacy._parentID = -1;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(ProjectionSurface.prototype, "surface", {
get: function () {
return this._surface;
},
set: function (value) {
if (this._surface == value) {
return;
}
this._surface = value || null;
this.legacy._parentID = -1;
},
enumerable: true,
configurable: true
});
ProjectionSurface.prototype.applyPartial = function (pos, newPos) {
if (this._activeProjection !== null) {
newPos = this.legacy.worldTransform.apply(pos, newPos);
return this._activeProjection.surface.apply(newPos, newPos);
}
if (this._surface !== null) {
return this.surface.apply(pos, newPos);
}
return this.legacy.worldTransform.apply(pos, newPos);
};
ProjectionSurface.prototype.apply = function (pos, newPos) {
if (this._activeProjection !== null) {
newPos = this.legacy.worldTransform.apply(pos, newPos);
this._activeProjection.surface.apply(newPos, newPos);
return this._activeProjection.legacy.worldTransform.apply(newPos, newPos);
}
if (this._surface !== null) {
newPos = this.surface.apply(pos, newPos);
return this.legacy.worldTransform.apply(newPos, newPos);
}
return this.legacy.worldTransform.apply(pos, newPos);
};
ProjectionSurface.prototype.applyInverse = function (pos, newPos) {
if (this._activeProjection !== null) {
newPos = this._activeProjection.legacy.worldTransform.applyInverse(pos, newPos);
this._activeProjection._surface.applyInverse(newPos, newPos);
return this.legacy.worldTransform.applyInverse(newPos, newPos);
}
if (this._surface !== null) {
newPos = this.legacy.worldTransform.applyInverse(pos, newPos);
return this._surface.applyInverse(newPos, newPos);
}
return this.legacy.worldTransform.applyInverse(pos, newPos);
};
ProjectionSurface.prototype.mapBilinearSprite = function (sprite, quad) {
if (!(this._surface instanceof pixi_projection.BilinearSurface)) {
this.surface = new pixi_projection.BilinearSurface();
}
this.surface.mapSprite(sprite, quad, this.legacy);
};
ProjectionSurface.prototype.clear = function () {
if (this.surface) {
this.surface.clear();
}
};
Object.defineProperty(ProjectionSurface.prototype, "uniforms", {
get: function () {
if (this._currentLegacyID === this.legacy._worldID &&
this._currentSurfaceID === this.surface._updateID) {
return this._lastUniforms;
}
this._lastUniforms = this._lastUniforms || {};
this._lastUniforms.worldTransform = this.legacy.worldTransform.toArray(true);
this._surface.fillUniforms(this._lastUniforms);
return this._lastUniforms;
},
enumerable: true,
configurable: true
});
return ProjectionSurface;
}(pixi_projection.AbstractProjection));
pixi_projection.ProjectionSurface = ProjectionSurface;
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var MultiTextureSpriteRenderer = pixi_projection.webgl.MultiTextureSpriteRenderer;
var SpriteBilinearRenderer = (function (_super) {
__extends(SpriteBilinearRenderer, _super);
function SpriteBilinearRenderer() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.size = 100;
_this.MAX_TEXTURES_LOCAL = 1;
_this.shaderVert = "precision highp float;\nattribute vec2 aVertexPosition;\nattribute vec3 aTrans1;\nattribute vec3 aTrans2;\nattribute vec4 aFrame;\nattribute vec4 aColor;\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\nuniform mat3 worldTransform;\n\nvarying vec2 vTextureCoord;\nvarying vec3 vTrans1;\nvarying vec3 vTrans2;\nvarying vec4 vFrame;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nvoid main(void){\n gl_Position.xyw = projectionMatrix * worldTransform * vec3(aVertexPosition, 1.0);\n gl_Position.z = 0.0;\n \n vTextureCoord = aVertexPosition;\n vTrans1 = aTrans1;\n vTrans2 = aTrans2;\n vTextureId = aTextureId;\n vColor = aColor;\n vFrame = aFrame;\n}\n";
_this.shaderFrag = "precision highp float;\nvarying vec2 vTextureCoord;\nvarying vec3 vTrans1;\nvarying vec3 vTrans2;\nvarying vec4 vFrame;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nuniform sampler2D uSamplers[%count%];\nuniform vec2 samplerSize[%count%]; \nuniform vec4 distortion;\n\nvoid main(void){\nvec2 surface;\nvec2 surface2;\n\nfloat vx = vTextureCoord.x;\nfloat vy = vTextureCoord.y;\nfloat dx = distortion.x;\nfloat dy = distortion.y;\nfloat revx = distortion.z;\nfloat revy = distortion.w;\n\nif (distortion.x == 0.0) {\n surface.x = vx;\n surface.y = vy / (1.0 + dy * vx);\n surface2 = surface;\n} else\nif (distortion.y == 0.0) {\n surface.y = vy;\n surface.x = vx/ (1.0 + dx * vy);\n surface2 = surface;\n} else {\n float c = vy * dx - vx * dy;\n float b = (c + 1.0) * 0.5;\n float b2 = (-c + 1.0) * 0.5;\n float d = b * b + vx * dy;\n if (d < -0.00001) {\n discard;\n }\n d = sqrt(max(d, 0.0));\n surface.x = (- b + d) * revy;\n surface2.x = (- b - d) * revy;\n surface.y = (- b2 + d) * revx;\n surface2.y = (- b2 - d) * revx;\n}\n\nvec2 uv;\nuv.x = vTrans1.x * surface.x + vTrans1.y * surface.y + vTrans1.z;\nuv.y = vTrans2.x * surface.x + vTrans2.y * surface.y + vTrans2.z;\n\nvec2 pixels = uv * samplerSize[0];\n\nif (pixels.x < vFrame.x || pixels.x > vFrame.z ||\n pixels.y < vFrame.y || pixels.y > vFrame.w) {\n uv.x = vTrans1.x * surface2.x + vTrans1.y * surface2.y + vTrans1.z;\n uv.y = vTrans2.x * surface2.x + vTrans2.y * surface2.y + vTrans2.z;\n pixels = uv * samplerSize[0];\n \n if (pixels.x < vFrame.x || pixels.x > vFrame.z ||\n pixels.y < vFrame.y || pixels.y > vFrame.w) {\n discard;\n }\n}\n\nvec4 edge;\nedge.xy = clamp(pixels - vFrame.xy + 0.5, vec2(0.0, 0.0), vec2(1.0, 1.0));\nedge.zw = clamp(vFrame.zw - pixels + 0.5, vec2(0.0, 0.0), vec2(1.0, 1.0));\n\nfloat alpha = 1.0; //edge.x * edge.y * edge.z * edge.w;\nvec4 rColor = vColor * alpha;\n\nfloat textureId = floor(vTextureId+0.5);\nvec4 color;\nvec2 textureCoord = uv;\n%forloop%\ngl_FragColor = color * rColor;\n}";
_this.defUniforms = {
worldTransform: new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]),
distortion: new Float32Array([0, 0])
};
return _this;
}
SpriteBilinearRenderer.prototype.getUniforms = function (sprite) {
var proj = sprite.proj;
var shader = this.shader;
if (proj.surface !== null) {
return proj.uniforms;
}
if (proj._activeProjection !== null) {
return proj._activeProjection.uniforms;
}
return this.defUniforms;
};
SpriteBilinearRenderer.prototype.createVao = function (vertexBuffer) {
var attrs = this.shader.attributes;
this.vertSize = 14;
this.vertByteSize = this.vertSize * 4;
var gl = this.renderer.gl;
var vao = this.renderer.createVao()
.addIndex(this.indexBuffer)
.addAttribute(vertexBuffer, attrs.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0)
.addAttribute(vertexBuffer, attrs.aTrans1, gl.FLOAT, false, this.vertByteSize, 2 * 4)
.addAttribute(vertexBuffer, attrs.aTrans2, gl.FLOAT, false, this.vertByteSize, 5 * 4)
.addAttribute(vertexBuffer, attrs.aFrame, gl.FLOAT, false, this.vertByteSize, 8 * 4)
.addAttribute(vertexBuffer, attrs.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 12 * 4);
if (attrs.aTextureId) {
vao.addAttribute(vertexBuffer, attrs.aTextureId, gl.FLOAT, false, this.vertByteSize, 13 * 4);
}
return vao;
};
SpriteBilinearRenderer.prototype.fillVertices = function (float32View, uint32View, index, sprite, argb, textureId) {
var vertexData = sprite.vertexData;
var tex = sprite._texture;
var w = tex.orig.width;
var h = tex.orig.height;
var ax = sprite._anchor._x;
var ay = sprite._anchor._y;
var frame = tex._frame;
var aTrans = sprite.aTrans;
for (var i = 0; i < 4; i++) {
float32View[index] = vertexData[i * 2];
float32View[index + 1] = vertexData[i * 2 + 1];
float32View[index + 2] = aTrans.a;
float32View[index + 3] = aTrans.c;
float32View[index + 4] = aTrans.tx;
float32View[index + 5] = aTrans.b;
float32View[index + 6] = aTrans.d;
float32View[index + 7] = aTrans.ty;
float32View[index + 8] = frame.x;
float32View[index + 9] = frame.y;
float32View[index + 10] = frame.x + frame.width;
float32View[index + 11] = frame.y + frame.height;
uint32View[index + 12] = argb;
float32View[index + 13] = textureId;
index += 14;
}
};
return SpriteBilinearRenderer;
}(MultiTextureSpriteRenderer));
PIXI.WebGLRenderer.registerPlugin('sprite_bilinear', SpriteBilinearRenderer);
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var MultiTextureSpriteRenderer = pixi_projection.webgl.MultiTextureSpriteRenderer;
var SpriteStrangeRenderer = (function (_super) {
__extends(SpriteStrangeRenderer, _super);
function SpriteStrangeRenderer() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.size = 100;
_this.MAX_TEXTURES_LOCAL = 1;
_this.shaderVert = "precision highp float;\nattribute vec2 aVertexPosition;\nattribute vec3 aTrans1;\nattribute vec3 aTrans2;\nattribute vec4 aFrame;\nattribute vec4 aColor;\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\nuniform mat3 worldTransform;\n\nvarying vec2 vTextureCoord;\nvarying vec3 vTrans1;\nvarying vec3 vTrans2;\nvarying vec4 vFrame;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nvoid main(void){\n gl_Position.xyw = projectionMatrix * worldTransform * vec3(aVertexPosition, 1.0);\n gl_Position.z = 0.0;\n \n vTextureCoord = aVertexPosition;\n vTrans1 = aTrans1;\n vTrans2 = aTrans2;\n vTextureId = aTextureId;\n vColor = aColor;\n vFrame = aFrame;\n}\n";
_this.shaderFrag = "precision highp float;\nvarying vec2 vTextureCoord;\nvarying vec3 vTrans1;\nvarying vec3 vTrans2;\nvarying vec4 vFrame;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nuniform sampler2D uSamplers[%count%];\nuniform vec2 samplerSize[%count%]; \nuniform vec4 params;\n\nvoid main(void){\nvec2 surface;\n\nfloat vx = vTextureCoord.x;\nfloat vy = vTextureCoord.y;\nfloat aleph = params.x;\nfloat bet = params.y;\nfloat A = params.z;\nfloat B = params.w;\n\nif (aleph == 0.0) {\n\tsurface.y = vy / (1.0 + vx * bet);\n\tsurface.x = vx;\n}\nelse if (bet == 0.0) {\n\tsurface.x = vx / (1.0 + vy * aleph);\n\tsurface.y = vy;\n} else {\n\tsurface.x = vx * (bet + 1.0) / (bet + 1.0 + vy * aleph);\n\tsurface.y = vy * (aleph + 1.0) / (aleph + 1.0 + vx * bet);\n}\n\nvec2 uv;\nuv.x = vTrans1.x * surface.x + vTrans1.y * surface.y + vTrans1.z;\nuv.y = vTrans2.x * surface.x + vTrans2.y * surface.y + vTrans2.z;\n\nvec2 pixels = uv * samplerSize[0];\n\nvec4 edge;\nedge.xy = clamp(pixels - vFrame.xy + 0.5, vec2(0.0, 0.0), vec2(1.0, 1.0));\nedge.zw = clamp(vFrame.zw - pixels + 0.5, vec2(0.0, 0.0), vec2(1.0, 1.0));\n\nfloat alpha = edge.x * edge.y * edge.z * edge.w;\nvec4 rColor = vColor * alpha;\n\nfloat textureId = floor(vTextureId+0.5);\nvec4 color;\nvec2 textureCoord = uv;\n%forloop%\ngl_FragColor = color * rColor;\n}";
_this.defUniforms = {
worldTransform: new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]),
distortion: new Float32Array([0, 0])
};
return _this;
}
SpriteStrangeRenderer.prototype.getUniforms = function (sprite) {
var proj = sprite.proj;
var shader = this.shader;
if (proj.surface !== null) {
return proj.uniforms;
}
if (proj._activeProjection !== null) {
return proj._activeProjection.uniforms;
}
return this.defUniforms;
};
SpriteStrangeRenderer.prototype.createVao = function (vertexBuffer) {
var attrs = this.shader.attributes;
this.vertSize = 14;
this.vertByteSize = this.vertSize * 4;
var gl = this.renderer.gl;
var vao = this.renderer.createVao()
.addIndex(this.indexBuffer)
.addAttribute(vertexBuffer, attrs.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0)
.addAttribute(vertexBuffer, attrs.aTrans1, gl.FLOAT, false, this.vertByteSize, 2 * 4)
.addAttribute(vertexBuffer, attrs.aTrans2, gl.FLOAT, false, this.vertByteSize, 5 * 4)
.addAttribute(vertexBuffer, attrs.aFrame, gl.FLOAT, false, this.vertByteSize, 8 * 4)
.addAttribute(vertexBuffer, attrs.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 12 * 4);
if (attrs.aTextureId) {
vao.addAttribute(vertexBuffer, attrs.aTextureId, gl.FLOAT, false, this.vertByteSize, 13 * 4);
}
return vao;
};
SpriteStrangeRenderer.prototype.fillVertices = function (float32View, uint32View, index, sprite, argb, textureId) {
var vertexData = sprite.vertexData;
var tex = sprite._texture;
var w = tex.orig.width;
var h = tex.orig.height;
var ax = sprite._anchor._x;
var ay = sprite._anchor._y;
var frame = tex._frame;
var aTrans = sprite.aTrans;
for (var i = 0; i < 4; i++) {
float32View[index] = vertexData[i * 2];
float32View[index + 1] = vertexData[i * 2 + 1];
float32View[index + 2] = aTrans.a;
float32View[index + 3] = aTrans.c;
float32View[index + 4] = aTrans.tx;
float32View[index + 5] = aTrans.b;
float32View[index + 6] = aTrans.d;
float32View[index + 7] = aTrans.ty;
float32View[index + 8] = frame.x;
float32View[index + 9] = frame.y;
float32View[index + 10] = frame.x + frame.width;
float32View[index + 11] = frame.y + frame.height;
uint32View[index + 12] = argb;
float32View[index + 13] = textureId;
index += 14;
}
};
return SpriteStrangeRenderer;
}(MultiTextureSpriteRenderer));
PIXI.WebGLRenderer.registerPlugin('sprite_strange', SpriteStrangeRenderer);
})(pixi_projection || (pixi_projection = {}));
var pixi_projection;
(function (pixi_projection) {
var tempMat = new PIXI.Matrix();
var tempRect = new PIXI.Rectangle();
var tempPoint = new PIXI.Point();
var StrangeSurface = (function (_super) {
__extends(StrangeSurface, _super);
function StrangeSurface() {
var _this = _super.call(this) || this;
_this.params = [0, 0, NaN, NaN];
return _this;
}
StrangeSurface.prototype.clear = function () {
var p = this.params;
p[0] = 0;
p[1] = 0;
p[2] = NaN;
p[3] = NaN;
};
StrangeSurface.prototype.setAxisX = function (pos, factor, outTransform) {
var x = pos.x, y = pos.y;
var d = Math.sqrt(x * x + y * y);
var rot = outTransform.rotation;
if (rot !== 0) {
outTransform.skew._x -= rot;
outTransform.skew._y += rot;
outTransform.rotation = 0;
}
outTransform.skew.y = Math.atan2(y, x);
var p = this.params;
if (factor !== 0) {
p[2] = -d * factor;
}
else {
p[2] = NaN;
}
this._calc01();
};
StrangeSurface.prototype.setAxisY = function (pos, factor, outTransform) {
var x = pos.x, y = pos.y;
var d = Math.sqrt(x * x + y * y);
var rot = outTransform.rotation;
if (rot !== 0) {
outTransform.skew._x -= rot;
outTransform.skew._y += rot;
outTransform.rotation = 0;