Alpha version
This commit is contained in:
parent
b84c8c8175
commit
7a977ace5c
42 changed files with 3882 additions and 3 deletions
21
LICENSE
Executable file
21
LICENSE
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2013-2014 Mathew Groves
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
78
README.md
78
README.md
|
@ -1,4 +1,76 @@
|
||||||
pixi.js
|
Pixi Renderer
|
||||||
=======
|
=============
|
||||||
|
|
||||||
|
#### JavaScript 2D Renderer ####
|
||||||
|
|
||||||
|
The aim of this project is to provide a fast lightweight 2D library that works across all devices.
|
||||||
|
The Pixi renderer allows everyone to enjoy the power of hardware acceleration without prior knowledge of webGL.
|
||||||
|
Also its fast.
|
||||||
|
|
||||||
|
### Demo ###
|
||||||
|
|
||||||
|
[Check out the Bunny Demo here](http://matgroves.com/pixijs/)
|
||||||
|
|
||||||
|
### Current features ###
|
||||||
|
|
||||||
|
- webGL renderer (with automatic smart batching allowing for REALLY fast performance)
|
||||||
|
- canvas renderer
|
||||||
|
- full scene graph
|
||||||
|
- super easy to use API (similar to the flash display list API)
|
||||||
|
- support for texture atlas's
|
||||||
|
- asset loader / sprite sheet loader
|
||||||
|
- auto detect which renderer should be used
|
||||||
|
- handles device context loss
|
||||||
|
|
||||||
|
### Coming soon ###
|
||||||
|
|
||||||
|
- Filters
|
||||||
|
- Render Texture
|
||||||
|
- Text
|
||||||
|
- Interactivity
|
||||||
|
- Documentation
|
||||||
|
|
||||||
|
|
||||||
|
### Coming later ###
|
||||||
|
|
||||||
|
- Awesome Post processing effects
|
||||||
|
|
||||||
|
### Usage ###
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
|
||||||
|
/*
|
||||||
|
you can use either PIXI.WebGLRenderer or PIXI.CanvasRenderer
|
||||||
|
*/
|
||||||
|
var renderer = new PIXI.WebGLRenderer(800, 600);
|
||||||
|
|
||||||
|
document.body.appendChild(renderer.view);
|
||||||
|
|
||||||
|
var stage = new PIXI.Stage;
|
||||||
|
|
||||||
|
var bunnyTexture = new PIXI.Texture("bunny.png");
|
||||||
|
var bunny = new PIXI.Sprite(rabbitTexture);
|
||||||
|
|
||||||
|
bunny.position.x = 400;
|
||||||
|
bunny.position.y = 300;
|
||||||
|
|
||||||
|
bunny.scale.x = 2;
|
||||||
|
bunny.scale.y = 2;
|
||||||
|
|
||||||
|
stage.addChild(bunny);
|
||||||
|
|
||||||
|
requestAnimationFrame( animate );
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
|
||||||
|
requestAnimationFrame( animate );
|
||||||
|
|
||||||
|
bunny.rotation += 0.01;
|
||||||
|
|
||||||
|
renderer.render(stage);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This content is released under the (Link Goes Here) MIT License.
|
||||||
|
|
||||||
|
|
||||||
Super fast HTML 5 2D rendering engine that uses webGL with canvas fallback
|
|
110
bin/pixi.js
Normal file
110
bin/pixi.js
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(b){window.setTimeout(b,1E3/60)}}();var AjaxRequest=function(){var b=["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];if(window.ActiveXObject)for(var c=0;c<b.length;c++)try{return new ActiveXObject(b[c])}catch(f){}else return window.XMLHttpRequest?new XMLHttpRequest:!1};var PIXI=PIXI||{};PIXI.EventTarget=function(){var b={};this.addEventListener=function(c,f){void 0===b[c]&&(b[c]=[]);-1===b[c].indexOf(f)&&b[c].push(f)};this.dispatchEvent=function(c){for(var f in b[c.type])b[c.type][f](c)};this.removeEventListener=function(c,f){var e=b[c].indexOf(f);-1!==e&&b[c].splice(e,1)}};(function(b,c){"object"===typeof exports?module.exports=c(global):"function"===typeof define&&define.amd?define([],function(){return c(b)}):c(b)})(this,function(b){function c(a){return k=a}function f(){return k="undefined"!==typeof Float32Array?Float32Array:Array}var e={};if("undefined"!=typeof Float32Array){var g=new Float32Array(1),h=new Int32Array(g.buffer);e.invsqrt=function(a){g[0]=a;h[0]=1597463007-(h[0]>>1);var d=g[0];return d*(1.5-0.5*a*d*d)}}else e.invsqrt=function(a){return 1/Math.sqrt(a)};
|
||||||
|
var k=null;f();var l={create:function(a){var d=new k(3);a?(d[0]=a[0],d[1]=a[1],d[2]=a[2]):d[0]=d[1]=d[2]=0;return d},createFrom:function(a,d,j){var b=new k(3);b[0]=a;b[1]=d;b[2]=j;return b},set:function(a,d){d[0]=a[0];d[1]=a[1];d[2]=a[2];return d},equal:function(a,d){return a===d||1E-6>Math.abs(a[0]-d[0])&&1E-6>Math.abs(a[1]-d[1])&&1E-6>Math.abs(a[2]-d[2])},add:function(a,d,j){if(!j||a===j)return a[0]+=d[0],a[1]+=d[1],a[2]+=d[2],a;j[0]=a[0]+d[0];j[1]=a[1]+d[1];j[2]=a[2]+d[2];return j},subtract:function(a,
|
||||||
|
d,j){if(!j||a===j)return a[0]-=d[0],a[1]-=d[1],a[2]-=d[2],a;j[0]=a[0]-d[0];j[1]=a[1]-d[1];j[2]=a[2]-d[2];return j},multiply:function(a,d,j){if(!j||a===j)return a[0]*=d[0],a[1]*=d[1],a[2]*=d[2],a;j[0]=a[0]*d[0];j[1]=a[1]*d[1];j[2]=a[2]*d[2];return j},negate:function(a,d){d||(d=a);d[0]=-a[0];d[1]=-a[1];d[2]=-a[2];return d},scale:function(a,d,j){if(!j||a===j)return a[0]*=d,a[1]*=d,a[2]*=d,a;j[0]=a[0]*d;j[1]=a[1]*d;j[2]=a[2]*d;return j},normalize:function(a,d){d||(d=a);var j=a[0],b=a[1],c=a[2],e=Math.sqrt(j*
|
||||||
|
j+b*b+c*c);if(!e)return d[0]=0,d[1]=0,d[2]=0,d;if(1===e)return d[0]=j,d[1]=b,d[2]=c,d;e=1/e;d[0]=j*e;d[1]=b*e;d[2]=c*e;return d},cross:function(a,d,j){j||(j=a);var b=a[0],c=a[1];a=a[2];var e=d[0],n=d[1];d=d[2];j[0]=c*d-a*n;j[1]=a*e-b*d;j[2]=b*n-c*e;return j},length:function(a){var d=a[0],j=a[1];a=a[2];return Math.sqrt(d*d+j*j+a*a)},squaredLength:function(a){var d=a[0],j=a[1];a=a[2];return d*d+j*j+a*a},dot:function(a,d){return a[0]*d[0]+a[1]*d[1]+a[2]*d[2]},direction:function(a,d,j){j||(j=a);var b=
|
||||||
|
a[0]-d[0],c=a[1]-d[1];a=a[2]-d[2];d=Math.sqrt(b*b+c*c+a*a);if(!d)return j[0]=0,j[1]=0,j[2]=0,j;d=1/d;j[0]=b*d;j[1]=c*d;j[2]=a*d;return j},lerp:function(a,d,j,b){b||(b=a);b[0]=a[0]+j*(d[0]-a[0]);b[1]=a[1]+j*(d[1]-a[1]);b[2]=a[2]+j*(d[2]-a[2]);return b},dist:function(a,d){var j=d[0]-a[0],b=d[1]-a[1],c=d[2]-a[2];return Math.sqrt(j*j+b*b+c*c)}},p=null,q=new k(4);l.unproject=function(a,d,j,b,c){c||(c=a);p||(p=t.create());var e=p;q[0]=2*(a[0]-b[0])/b[2]-1;q[1]=2*(a[1]-b[1])/b[3]-1;q[2]=2*a[2]-1;q[3]=1;
|
||||||
|
t.multiply(j,d,e);if(!t.inverse(e))return null;t.multiplyVec4(e,q);if(0===q[3])return null;c[0]=q[0]/q[3];c[1]=q[1]/q[3];c[2]=q[2]/q[3];return c};var C=l.createFrom(1,0,0),F=l.createFrom(0,1,0),u=l.createFrom(0,0,1),w=l.create();l.rotationTo=function(a,d,j){j||(j=m.create());var b=l.dot(a,d);if(1<=b)m.set(H,j);else if(-0.999999>b)l.cross(C,a,w),1E-6>l.length(w)&&l.cross(F,a,w),1E-6>l.length(w)&&l.cross(u,a,w),l.normalize(w),m.fromAngleAxis(Math.PI,w,j);else{var b=Math.sqrt(2*(1+b)),c=1/b;l.cross(a,
|
||||||
|
d,w);j[0]=w[0]*c;j[1]=w[1]*c;j[2]=w[2]*c;j[3]=0.5*b;m.normalize(j)}1<j[3]?j[3]=1:-1>j[3]&&(j[3]=-1);return j};l.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+"]"};var x={create:function(a){var d=new k(9);a?(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[3],d[4]=a[4],d[5]=a[5],d[6]=a[6],d[7]=a[7],d[8]=a[8]):d[0]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=0;return d},createFrom:function(a,d,j,b,c,e,n,f,E){var s=new k(9);s[0]=a;s[1]=d;s[2]=j;s[3]=b;s[4]=c;s[5]=e;s[6]=n;s[7]=f;s[8]=E;return s},determinant:function(a){var d=
|
||||||
|
a[3],j=a[4],b=a[5],c=a[6],e=a[7],n=a[8];return a[0]*(n*j-b*e)+a[1]*(-n*d+b*c)+a[2]*(e*d-j*c)},inverse:function(a,d){var j=a[0],b=a[1],c=a[2],e=a[3],n=a[4],f=a[5],E=a[6],s=a[7],I=a[8],g=I*n-f*s,h=-I*e+f*E,k=s*e-n*E,r=j*g+b*h+c*k;if(!r)return null;r=1/r;d||(d=x.create());d[0]=g*r;d[1]=(-I*b+c*s)*r;d[2]=(f*b-c*n)*r;d[3]=h*r;d[4]=(I*j-c*E)*r;d[5]=(-f*j+c*e)*r;d[6]=k*r;d[7]=(-s*j+b*E)*r;d[8]=(n*j-b*e)*r;return d},multiply:function(a,d,j){j||(j=a);var b=a[0],c=a[1],e=a[2],f=a[3],D=a[4],E=a[5],s=a[6],I=
|
||||||
|
a[7];a=a[8];var g=d[0],h=d[1],k=d[2],r=d[3],m=d[4],l=d[5],q=d[6],v=d[7];d=d[8];j[0]=g*b+h*f+k*s;j[1]=g*c+h*D+k*I;j[2]=g*e+h*E+k*a;j[3]=r*b+m*f+l*s;j[4]=r*c+m*D+l*I;j[5]=r*e+m*E+l*a;j[6]=q*b+v*f+d*s;j[7]=q*c+v*D+d*I;j[8]=q*e+v*E+d*a;return j},multiplyVec2:function(a,d,j){j||(j=d);var b=d[0];d=d[1];j[0]=b*a[0]+d*a[3]+a[6];j[1]=b*a[1]+d*a[4]+a[7];return j},multiplyVec3:function(a,d,j){j||(j=d);var b=d[0],c=d[1];d=d[2];j[0]=b*a[0]+c*a[3]+d*a[6];j[1]=b*a[1]+c*a[4]+d*a[7];j[2]=b*a[2]+c*a[5]+d*a[8];return j},
|
||||||
|
set:function(a,d){d[0]=a[0];d[1]=a[1];d[2]=a[2];d[3]=a[3];d[4]=a[4];d[5]=a[5];d[6]=a[6];d[7]=a[7];d[8]=a[8];return d},equal:function(a,d){return a===d||1E-6>Math.abs(a[0]-d[0])&&1E-6>Math.abs(a[1]-d[1])&&1E-6>Math.abs(a[2]-d[2])&&1E-6>Math.abs(a[3]-d[3])&&1E-6>Math.abs(a[4]-d[4])&&1E-6>Math.abs(a[5]-d[5])&&1E-6>Math.abs(a[6]-d[6])&&1E-6>Math.abs(a[7]-d[7])&&1E-6>Math.abs(a[8]-d[8])},identity:function(a){a||(a=x.create());a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=1;a[5]=0;a[6]=0;a[7]=0;a[8]=1;return a},transpose:function(a,
|
||||||
|
d){if(!d||a===d){var j=a[1],b=a[2],c=a[5];a[1]=a[3];a[2]=a[6];a[3]=j;a[5]=a[7];a[6]=b;a[7]=c;return a}d[0]=a[0];d[1]=a[3];d[2]=a[6];d[3]=a[1];d[4]=a[4];d[5]=a[7];d[6]=a[2];d[7]=a[5];d[8]=a[8];return d},toMat4:function(a,d){d||(d=t.create());d[15]=1;d[14]=0;d[13]=0;d[12]=0;d[11]=0;d[10]=a[8];d[9]=a[7];d[8]=a[6];d[7]=0;d[6]=a[5];d[5]=a[4];d[4]=a[3];d[3]=0;d[2]=a[2];d[1]=a[1];d[0]=a[0];return d},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+
|
||||||
|
a[8]+"]"}},t={create:function(a){var d=new k(16);a&&(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[3],d[4]=a[4],d[5]=a[5],d[6]=a[6],d[7]=a[7],d[8]=a[8],d[9]=a[9],d[10]=a[10],d[11]=a[11],d[12]=a[12],d[13]=a[13],d[14]=a[14],d[15]=a[15]);return d},createFrom:function(a,d,j,b,c,e,f,D,E,s,g,h,m,l,r,q){var A=new k(16);A[0]=a;A[1]=d;A[2]=j;A[3]=b;A[4]=c;A[5]=e;A[6]=f;A[7]=D;A[8]=E;A[9]=s;A[10]=g;A[11]=h;A[12]=m;A[13]=l;A[14]=r;A[15]=q;return A},set:function(a,d){d[0]=a[0];d[1]=a[1];d[2]=a[2];d[3]=a[3];d[4]=a[4];
|
||||||
|
d[5]=a[5];d[6]=a[6];d[7]=a[7];d[8]=a[8];d[9]=a[9];d[10]=a[10];d[11]=a[11];d[12]=a[12];d[13]=a[13];d[14]=a[14];d[15]=a[15];return d},equal:function(a,d){return a===d||1E-6>Math.abs(a[0]-d[0])&&1E-6>Math.abs(a[1]-d[1])&&1E-6>Math.abs(a[2]-d[2])&&1E-6>Math.abs(a[3]-d[3])&&1E-6>Math.abs(a[4]-d[4])&&1E-6>Math.abs(a[5]-d[5])&&1E-6>Math.abs(a[6]-d[6])&&1E-6>Math.abs(a[7]-d[7])&&1E-6>Math.abs(a[8]-d[8])&&1E-6>Math.abs(a[9]-d[9])&&1E-6>Math.abs(a[10]-d[10])&&1E-6>Math.abs(a[11]-d[11])&&1E-6>Math.abs(a[12]-
|
||||||
|
d[12])&&1E-6>Math.abs(a[13]-d[13])&&1E-6>Math.abs(a[14]-d[14])&&1E-6>Math.abs(a[15]-d[15])},identity:function(a){a||(a=t.create());a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a},transpose:function(a,d){if(!d||a===d){var j=a[1],b=a[2],c=a[3],e=a[6],f=a[7],D=a[11];a[1]=a[4];a[2]=a[8];a[3]=a[12];a[4]=j;a[6]=a[9];a[7]=a[13];a[8]=b;a[9]=e;a[11]=a[14];a[12]=c;a[13]=f;a[14]=D;return a}d[0]=a[0];d[1]=a[4];d[2]=a[8];d[3]=a[12];
|
||||||
|
d[4]=a[1];d[5]=a[5];d[6]=a[9];d[7]=a[13];d[8]=a[2];d[9]=a[6];d[10]=a[10];d[11]=a[14];d[12]=a[3];d[13]=a[7];d[14]=a[11];d[15]=a[15];return d},determinant:function(a){var d=a[0],j=a[1],b=a[2],c=a[3],e=a[4],f=a[5],D=a[6],E=a[7],s=a[8],g=a[9],h=a[10],k=a[11],m=a[12],r=a[13],l=a[14];a=a[15];return m*g*D*c-s*r*D*c-m*f*h*c+e*r*h*c+s*f*l*c-e*g*l*c-m*g*b*E+s*r*b*E+m*j*h*E-d*r*h*E-s*j*l*E+d*g*l*E+m*f*b*k-e*r*b*k-m*j*D*k+d*r*D*k+e*j*l*k-d*f*l*k-s*f*b*a+e*g*b*a+s*j*D*a-d*g*D*a-e*j*h*a+d*f*h*a},inverse:function(a,
|
||||||
|
d){d||(d=a);var j=a[0],b=a[1],c=a[2],e=a[3],f=a[4],D=a[5],E=a[6],s=a[7],g=a[8],h=a[9],k=a[10],m=a[11],r=a[12],l=a[13],A=a[14],q=a[15],v=j*D-b*f,J=j*E-c*f,y=j*s-e*f,z=b*E-c*D,t=b*s-e*D,u=c*s-e*E,p=g*l-h*r,w=g*A-k*r,x=g*q-m*r,B=h*A-k*l,C=h*q-m*l,F=k*q-m*A,G=v*F-J*C+y*B+z*x-t*w+u*p;if(!G)return null;G=1/G;d[0]=(D*F-E*C+s*B)*G;d[1]=(-b*F+c*C-e*B)*G;d[2]=(l*u-A*t+q*z)*G;d[3]=(-h*u+k*t-m*z)*G;d[4]=(-f*F+E*x-s*w)*G;d[5]=(j*F-c*x+e*w)*G;d[6]=(-r*u+A*y-q*J)*G;d[7]=(g*u-k*y+m*J)*G;d[8]=(f*C-D*x+s*p)*G;d[9]=
|
||||||
|
(-j*C+b*x-e*p)*G;d[10]=(r*t-l*y+q*v)*G;d[11]=(-g*t+h*y-m*v)*G;d[12]=(-f*B+D*w-E*p)*G;d[13]=(j*B-b*w+c*p)*G;d[14]=(-r*z+l*J-A*v)*G;d[15]=(g*z-h*J+k*v)*G;return d},toRotationMat:function(a,d){d||(d=t.create());d[0]=a[0];d[1]=a[1];d[2]=a[2];d[3]=a[3];d[4]=a[4];d[5]=a[5];d[6]=a[6];d[7]=a[7];d[8]=a[8];d[9]=a[9];d[10]=a[10];d[11]=a[11];d[12]=0;d[13]=0;d[14]=0;d[15]=1;return d},toMat3:function(a,d){d||(d=x.create());d[0]=a[0];d[1]=a[1];d[2]=a[2];d[3]=a[4];d[4]=a[5];d[5]=a[6];d[6]=a[8];d[7]=a[9];d[8]=a[10];
|
||||||
|
return d},toInverseMat3:function(a,d){var j=a[0],b=a[1],c=a[2],e=a[4],f=a[5],D=a[6],g=a[8],s=a[9],h=a[10],k=h*f-D*s,m=-h*e+D*g,l=s*e-f*g,r=j*k+b*m+c*l;if(!r)return null;r=1/r;d||(d=x.create());d[0]=k*r;d[1]=(-h*b+c*s)*r;d[2]=(D*b-c*f)*r;d[3]=m*r;d[4]=(h*j-c*g)*r;d[5]=(-D*j+c*e)*r;d[6]=l*r;d[7]=(-s*j+b*g)*r;d[8]=(f*j-b*e)*r;return d},multiply:function(a,d,j){j||(j=a);var b=a[0],c=a[1],e=a[2],f=a[3],g=a[4],h=a[5],s=a[6],k=a[7],m=a[8],l=a[9],q=a[10],r=a[11],t=a[12],A=a[13],u=a[14];a=a[15];var v=d[0],
|
||||||
|
p=d[1],y=d[2],z=d[3];j[0]=v*b+p*g+y*m+z*t;j[1]=v*c+p*h+y*l+z*A;j[2]=v*e+p*s+y*q+z*u;j[3]=v*f+p*k+y*r+z*a;v=d[4];p=d[5];y=d[6];z=d[7];j[4]=v*b+p*g+y*m+z*t;j[5]=v*c+p*h+y*l+z*A;j[6]=v*e+p*s+y*q+z*u;j[7]=v*f+p*k+y*r+z*a;v=d[8];p=d[9];y=d[10];z=d[11];j[8]=v*b+p*g+y*m+z*t;j[9]=v*c+p*h+y*l+z*A;j[10]=v*e+p*s+y*q+z*u;j[11]=v*f+p*k+y*r+z*a;v=d[12];p=d[13];y=d[14];z=d[15];j[12]=v*b+p*g+y*m+z*t;j[13]=v*c+p*h+y*l+z*A;j[14]=v*e+p*s+y*q+z*u;j[15]=v*f+p*k+y*r+z*a;return j},multiplyVec3:function(a,d,b){b||(b=d);
|
||||||
|
var c=d[0],e=d[1];d=d[2];b[0]=a[0]*c+a[4]*e+a[8]*d+a[12];b[1]=a[1]*c+a[5]*e+a[9]*d+a[13];b[2]=a[2]*c+a[6]*e+a[10]*d+a[14];return b},multiplyVec4:function(a,d,b){b||(b=d);var c=d[0],e=d[1],f=d[2];d=d[3];b[0]=a[0]*c+a[4]*e+a[8]*f+a[12]*d;b[1]=a[1]*c+a[5]*e+a[9]*f+a[13]*d;b[2]=a[2]*c+a[6]*e+a[10]*f+a[14]*d;b[3]=a[3]*c+a[7]*e+a[11]*f+a[15]*d;return b},translate:function(a,d,b){var c=d[0],e=d[1];d=d[2];var f,n,g,h,s,k,m,l,p,r,q,t;if(!b||a===b)return a[12]=a[0]*c+a[4]*e+a[8]*d+a[12],a[13]=a[1]*c+a[5]*e+
|
||||||
|
a[9]*d+a[13],a[14]=a[2]*c+a[6]*e+a[10]*d+a[14],a[15]=a[3]*c+a[7]*e+a[11]*d+a[15],a;f=a[0];n=a[1];g=a[2];h=a[3];s=a[4];k=a[5];m=a[6];l=a[7];p=a[8];r=a[9];q=a[10];t=a[11];b[0]=f;b[1]=n;b[2]=g;b[3]=h;b[4]=s;b[5]=k;b[6]=m;b[7]=l;b[8]=p;b[9]=r;b[10]=q;b[11]=t;b[12]=f*c+s*e+p*d+a[12];b[13]=n*c+k*e+r*d+a[13];b[14]=g*c+m*e+q*d+a[14];b[15]=h*c+l*e+t*d+a[15];return b},scale:function(a,d,b){var c=d[0],e=d[1];d=d[2];if(!b||a===b)return a[0]*=c,a[1]*=c,a[2]*=c,a[3]*=c,a[4]*=e,a[5]*=e,a[6]*=e,a[7]*=e,a[8]*=d,a[9]*=
|
||||||
|
d,a[10]*=d,a[11]*=d,a;b[0]=a[0]*c;b[1]=a[1]*c;b[2]=a[2]*c;b[3]=a[3]*c;b[4]=a[4]*e;b[5]=a[5]*e;b[6]=a[6]*e;b[7]=a[7]*e;b[8]=a[8]*d;b[9]=a[9]*d;b[10]=a[10]*d;b[11]=a[11]*d;b[12]=a[12];b[13]=a[13];b[14]=a[14];b[15]=a[15];return b},rotate:function(a,d,b,c){var e=b[0],f=b[1];b=b[2];var n=Math.sqrt(e*e+f*f+b*b),g,h,k,m,l,p,q,r,t,u,w,v,x,y,z,B,C,F,H,K;if(!n)return null;1!==n&&(n=1/n,e*=n,f*=n,b*=n);g=Math.sin(d);h=Math.cos(d);k=1-h;d=a[0];n=a[1];m=a[2];l=a[3];p=a[4];q=a[5];r=a[6];t=a[7];u=a[8];w=a[9];v=
|
||||||
|
a[10];x=a[11];y=e*e*k+h;z=f*e*k+b*g;B=b*e*k-f*g;C=e*f*k-b*g;F=f*f*k+h;H=b*f*k+e*g;K=e*b*k+f*g;e=f*b*k-e*g;f=b*b*k+h;c?a!==c&&(c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a;c[0]=d*y+p*z+u*B;c[1]=n*y+q*z+w*B;c[2]=m*y+r*z+v*B;c[3]=l*y+t*z+x*B;c[4]=d*C+p*F+u*H;c[5]=n*C+q*F+w*H;c[6]=m*C+r*F+v*H;c[7]=l*C+t*F+x*H;c[8]=d*K+p*e+u*f;c[9]=n*K+q*e+w*f;c[10]=m*K+r*e+v*f;c[11]=l*K+t*e+x*f;return c},rotateX:function(a,d,b){var c=Math.sin(d);d=Math.cos(d);var e=a[4],f=a[5],n=a[6],g=a[7],h=a[8],k=a[9],m=a[10],
|
||||||
|
l=a[11];b?a!==b&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]):b=a;b[4]=e*d+h*c;b[5]=f*d+k*c;b[6]=n*d+m*c;b[7]=g*d+l*c;b[8]=e*-c+h*d;b[9]=f*-c+k*d;b[10]=n*-c+m*d;b[11]=g*-c+l*d;return b},rotateY:function(a,d,b){var c=Math.sin(d);d=Math.cos(d);var e=a[0],f=a[1],n=a[2],g=a[3],h=a[8],k=a[9],m=a[10],l=a[11];b?a!==b&&(b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]):b=a;b[0]=e*d+h*-c;b[1]=f*d+k*-c;b[2]=n*d+m*-c;b[3]=g*
|
||||||
|
d+l*-c;b[8]=e*c+h*d;b[9]=f*c+k*d;b[10]=n*c+m*d;b[11]=g*c+l*d;return b},rotateZ:function(a,d,b){var c=Math.sin(d);d=Math.cos(d);var e=a[0],f=a[1],n=a[2],g=a[3],h=a[4],k=a[5],m=a[6],l=a[7];b?a!==b&&(b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]):b=a;b[0]=e*d+h*c;b[1]=f*d+k*c;b[2]=n*d+m*c;b[3]=g*d+l*c;b[4]=e*-c+h*d;b[5]=f*-c+k*d;b[6]=n*-c+m*d;b[7]=g*-c+l*d;return b},frustum:function(a,d,b,c,e,f,n){n||(n=t.create());var g=d-a,h=c-b,k=f-e;n[0]=2*e/g;n[1]=0;
|
||||||
|
n[2]=0;n[3]=0;n[4]=0;n[5]=2*e/h;n[6]=0;n[7]=0;n[8]=(d+a)/g;n[9]=(c+b)/h;n[10]=-(f+e)/k;n[11]=-1;n[12]=0;n[13]=0;n[14]=-(2*f*e)/k;n[15]=0;return n},perspective:function(a,d,b,c,e){a=b*Math.tan(a*Math.PI/360);d*=a;return t.frustum(-d,d,-a,a,b,c,e)},ortho:function(a,d,b,c,e,f,n){n||(n=t.create());var g=d-a,h=c-b,k=f-e;n[0]=2/g;n[1]=0;n[2]=0;n[3]=0;n[4]=0;n[5]=2/h;n[6]=0;n[7]=0;n[8]=0;n[9]=0;n[10]=-2/k;n[11]=0;n[12]=-(a+d)/g;n[13]=-(c+b)/h;n[14]=-(f+e)/k;n[15]=1;return n},lookAt:function(a,d,b,c){c||
|
||||||
|
(c=t.create());var e,f,n,g,h,k,m,l,p=a[0],q=a[1];a=a[2];n=b[0];g=b[1];f=b[2];m=d[0];b=d[1];e=d[2];if(p===m&&q===b&&a===e)return t.identity(c);d=p-m;b=q-b;m=a-e;l=1/Math.sqrt(d*d+b*b+m*m);d*=l;b*=l;m*=l;e=g*m-f*b;f=f*d-n*m;n=n*b-g*d;(l=Math.sqrt(e*e+f*f+n*n))?(l=1/l,e*=l,f*=l,n*=l):n=f=e=0;g=b*n-m*f;h=m*e-d*n;k=d*f-b*e;(l=Math.sqrt(g*g+h*h+k*k))?(l=1/l,g*=l,h*=l,k*=l):k=h=g=0;c[0]=e;c[1]=g;c[2]=d;c[3]=0;c[4]=f;c[5]=h;c[6]=b;c[7]=0;c[8]=n;c[9]=k;c[10]=m;c[11]=0;c[12]=-(e*p+f*q+n*a);c[13]=-(g*p+h*q+
|
||||||
|
k*a);c[14]=-(d*p+b*q+m*a);c[15]=1;return c},fromRotationTranslation:function(a,d,b){b||(b=t.create());var c=a[0],e=a[1],f=a[2],n=a[3],g=c+c,h=e+e,k=f+f;a=c*g;var l=c*h,c=c*k,m=e*h,e=e*k,f=f*k,g=n*g,h=n*h,n=n*k;b[0]=1-(m+f);b[1]=l+n;b[2]=c-h;b[3]=0;b[4]=l-n;b[5]=1-(a+f);b[6]=e+g;b[7]=0;b[8]=c+h;b[9]=e-g;b[10]=1-(a+m);b[11]=0;b[12]=d[0];b[13]=d[1];b[14]=d[2];b[15]=1;return b},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+
|
||||||
|
a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+"]"}},m={create:function(a){var d=new k(4);a?(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[3]):d[0]=d[1]=d[2]=d[3]=0;return d},createFrom:function(a,d,b,c){var e=new k(4);e[0]=a;e[1]=d;e[2]=b;e[3]=c;return e},set:function(a,d){d[0]=a[0];d[1]=a[1];d[2]=a[2];d[3]=a[3];return d},equal:function(a,d){return a===d||1E-6>Math.abs(a[0]-d[0])&&1E-6>Math.abs(a[1]-d[1])&&1E-6>Math.abs(a[2]-d[2])&&1E-6>Math.abs(a[3]-d[3])},identity:function(a){a||(a=m.create());
|
||||||
|
a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a}},H=m.identity();m.calculateW=function(a,d){var b=a[0],c=a[1],e=a[2];if(!d||a===d)return a[3]=-Math.sqrt(Math.abs(1-b*b-c*c-e*e)),a;d[0]=b;d[1]=c;d[2]=e;d[3]=-Math.sqrt(Math.abs(1-b*b-c*c-e*e));return d};m.dot=function(a,d){return a[0]*d[0]+a[1]*d[1]+a[2]*d[2]+a[3]*d[3]};m.inverse=function(a,d){var b=a[0],c=a[1],e=a[2],f=a[3],b=(b=b*b+c*c+e*e+f*f)?1/b:0;if(!d||a===d)return a[0]*=-b,a[1]*=-b,a[2]*=-b,a[3]*=b,a;d[0]=-a[0]*b;d[1]=-a[1]*b;d[2]=-a[2]*b;d[3]=a[3]*b;
|
||||||
|
return d};m.conjugate=function(a,d){if(!d||a===d)return a[0]*=-1,a[1]*=-1,a[2]*=-1,a;d[0]=-a[0];d[1]=-a[1];d[2]=-a[2];d[3]=a[3];return d};m.length=function(a){var d=a[0],b=a[1],c=a[2];a=a[3];return Math.sqrt(d*d+b*b+c*c+a*a)};m.normalize=function(a,d){d||(d=a);var b=a[0],c=a[1],e=a[2],f=a[3],g=Math.sqrt(b*b+c*c+e*e+f*f);if(0===g)return d[0]=0,d[1]=0,d[2]=0,d[3]=0,d;g=1/g;d[0]=b*g;d[1]=c*g;d[2]=e*g;d[3]=f*g;return d};m.add=function(a,d,b){if(!b||a===b)return a[0]+=d[0],a[1]+=d[1],a[2]+=d[2],a[3]+=
|
||||||
|
d[3],a;b[0]=a[0]+d[0];b[1]=a[1]+d[1];b[2]=a[2]+d[2];b[3]=a[3]+d[3];return b};m.multiply=function(a,d,b){b||(b=a);var c=a[0],e=a[1],f=a[2];a=a[3];var g=d[0],h=d[1],k=d[2];d=d[3];b[0]=c*d+a*g+e*k-f*h;b[1]=e*d+a*h+f*g-c*k;b[2]=f*d+a*k+c*h-e*g;b[3]=a*d-c*g-e*h-f*k;return b};m.multiplyVec3=function(a,d,b){b||(b=d);var c=d[0],e=d[1],f=d[2];d=a[0];var g=a[1],h=a[2];a=a[3];var k=a*c+g*f-h*e,l=a*e+h*c-d*f,m=a*f+d*e-g*c,c=-d*c-g*e-h*f;b[0]=k*a+c*-d+l*-h-m*-g;b[1]=l*a+c*-g+m*-d-k*-h;b[2]=m*a+c*-h+k*-g-l*-d;
|
||||||
|
return b};m.scale=function(a,d,b){if(!b||a===b)return a[0]*=d,a[1]*=d,a[2]*=d,a[3]*=d,a;b[0]=a[0]*d;b[1]=a[1]*d;b[2]=a[2]*d;b[3]=a[3]*d;return b};m.toMat3=function(a,d){d||(d=x.create());var b=a[0],c=a[1],e=a[2],f=a[3],g=b+b,h=c+c,k=e+e,l=b*g,m=b*h,b=b*k,p=c*h,c=c*k,e=e*k,g=f*g,h=f*h,f=f*k;d[0]=1-(p+e);d[1]=m+f;d[2]=b-h;d[3]=m-f;d[4]=1-(l+e);d[5]=c+g;d[6]=b+h;d[7]=c-g;d[8]=1-(l+p);return d};m.toMat4=function(a,d){d||(d=t.create());var b=a[0],c=a[1],e=a[2],f=a[3],g=b+b,h=c+c,k=e+e,l=b*g,m=b*h,b=b*
|
||||||
|
k,p=c*h,c=c*k,e=e*k,g=f*g,h=f*h,f=f*k;d[0]=1-(p+e);d[1]=m+f;d[2]=b-h;d[3]=0;d[4]=m-f;d[5]=1-(l+e);d[6]=c+g;d[7]=0;d[8]=b+h;d[9]=c-g;d[10]=1-(l+p);d[11]=0;d[12]=0;d[13]=0;d[14]=0;d[15]=1;return d};m.slerp=function(a,d,b,c){c||(c=a);var e=a[0]*d[0]+a[1]*d[1]+a[2]*d[2]+a[3]*d[3],f,g;if(1<=Math.abs(e))return c!==a&&(c[0]=a[0],c[1]=a[1],c[2]=a[2],c[3]=a[3]),c;f=Math.acos(e);g=Math.sqrt(1-e*e);if(0.0010>Math.abs(g))return c[0]=0.5*a[0]+0.5*d[0],c[1]=0.5*a[1]+0.5*d[1],c[2]=0.5*a[2]+0.5*d[2],c[3]=0.5*a[3]+
|
||||||
|
0.5*d[3],c;e=Math.sin((1-b)*f)/g;b=Math.sin(b*f)/g;c[0]=a[0]*e+d[0]*b;c[1]=a[1]*e+d[1]*b;c[2]=a[2]*e+d[2]*b;c[3]=a[3]*e+d[3]*b;return c};m.fromRotationMatrix=function(a,d){d||(d=m.create());var b=a[0]+a[4]+a[8],c;if(0<b)c=Math.sqrt(b+1),d[3]=0.5*c,c=0.5/c,d[0]=(a[7]-a[5])*c,d[1]=(a[2]-a[6])*c,d[2]=(a[3]-a[1])*c;else{c=m.fromRotationMatrix.s_iNext=m.fromRotationMatrix.s_iNext||[1,2,0];b=0;a[4]>a[0]&&(b=1);a[8]>a[3*b+b]&&(b=2);var e=c[b],f=c[e];c=Math.sqrt(a[3*b+b]-a[3*e+e]-a[3*f+f]+1);d[b]=0.5*c;c=
|
||||||
|
0.5/c;d[3]=(a[3*f+e]-a[3*e+f])*c;d[e]=(a[3*e+b]+a[3*b+e])*c;d[f]=(a[3*f+b]+a[3*b+f])*c}return d};x.toQuat4=m.fromRotationMatrix;var B=x.create();m.fromAxes=function(a,d,b,c){B[0]=d[0];B[3]=d[1];B[6]=d[2];B[1]=b[0];B[4]=b[1];B[7]=b[2];B[2]=a[0];B[5]=a[1];B[8]=a[2];return m.fromRotationMatrix(B,c)};m.identity=function(a){a||(a=m.create());a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a};m.fromAngleAxis=function(a,d,b){b||(b=m.create());a*=0.5;var c=Math.sin(a);b[3]=Math.cos(a);b[0]=c*d[0];b[1]=c*d[1];b[2]=c*d[2];
|
||||||
|
return b};m.toAngleAxis=function(a,d){d||(d=a);var b=a[0]*a[0]+a[1]*a[1]+a[2]*a[2];0<b?(d[3]=2*Math.acos(a[3]),b=e.invsqrt(b),d[0]=a[0]*b,d[1]=a[1]*b,d[2]=a[2]*b):(d[3]=0,d[0]=1,d[1]=0,d[2]=0);return d};m.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"};var M={create:function(a){var d=new k(2);a?(d[0]=a[0],d[1]=a[1]):(d[0]=0,d[1]=0);return d},createFrom:function(a,d){var b=new k(2);b[0]=a;b[1]=d;return b},add:function(a,b,c){c||(c=b);c[0]=a[0]+b[0];c[1]=a[1]+b[1];return c},subtract:function(a,
|
||||||
|
b,c){c||(c=b);c[0]=a[0]-b[0];c[1]=a[1]-b[1];return c},multiply:function(a,b,c){c||(c=b);c[0]=a[0]*b[0];c[1]=a[1]*b[1];return c},divide:function(a,b,c){c||(c=b);c[0]=a[0]/b[0];c[1]=a[1]/b[1];return c},scale:function(a,b,c){c||(c=a);c[0]=a[0]*b;c[1]=a[1]*b;return c},dist:function(a,b){var c=b[0]-a[0],e=b[1]-a[1];return Math.sqrt(c*c+e*e)},set:function(a,b){b[0]=a[0];b[1]=a[1];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])},negate:function(a,b){b||(b=a);
|
||||||
|
b[0]=-a[0];b[1]=-a[1];return b},normalize:function(a,b){b||(b=a);var c=a[0]*a[0]+a[1]*a[1];0<c?(c=Math.sqrt(c),b[0]=a[0]/c,b[1]=a[1]/c):b[0]=b[1]=0;return b},cross:function(a,b,c){a=a[0]*b[1]-a[1]*b[0];if(!c)return a;c[0]=c[1]=0;c[2]=a;return c},length:function(a){var b=a[0];a=a[1];return Math.sqrt(b*b+a*a)},squaredLength:function(a){var b=a[0];a=a[1];return b*b+a*a},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]},direction:function(a,b,c){c||(c=a);var e=a[0]-b[0];a=a[1]-b[1];b=e*e+a*a;if(!b)return c[0]=
|
||||||
|
0,c[1]=0,c[2]=0,c;b=1/Math.sqrt(b);c[0]=e*b;c[1]=a*b;return c},lerp:function(a,b,c,e){e||(e=a);e[0]=a[0]+c*(b[0]-a[0]);e[1]=a[1]+c*(b[1]-a[1]);return e},str:function(a){return"["+a[0]+", "+a[1]+"]"}},L={create:function(a){var b=new k(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):b[0]=b[1]=b[2]=b[3]=0;return b},createFrom:function(a,b,c,e){var f=new k(4);f[0]=a;f[1]=b;f[2]=c;f[3]=e;return f},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1E-6>
|
||||||
|
Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])},identity:function(a){a||(a=L.create());a[0]=1;a[1]=0;a[2]=0;a[3]=1;return a},transpose:function(a,b){if(!b||a===b){var c=a[1];a[1]=a[2];a[2]=c;return a}b[0]=a[0];b[1]=a[2];b[2]=a[1];b[3]=a[3];return b},determinant:function(a){return a[0]*a[3]-a[2]*a[1]},inverse:function(a,b){b||(b=a);var c=a[0],e=a[1],f=a[2],g=a[3],h=c*g-f*e;if(!h)return null;h=1/h;b[0]=g*h;b[1]=-e*h;b[2]=-f*h;b[3]=c*h;return b},multiply:function(a,
|
||||||
|
b,c){c||(c=a);var e=a[0],f=a[1],g=a[2];a=a[3];c[0]=e*b[0]+f*b[2];c[1]=e*b[1]+f*b[3];c[2]=g*b[0]+a*b[2];c[3]=g*b[1]+a*b[3];return c},rotate:function(a,b,c){c||(c=a);var e=a[0],f=a[1],g=a[2];a=a[3];var h=Math.sin(b);b=Math.cos(b);c[0]=e*b+f*h;c[1]=e*-h+f*b;c[2]=g*b+a*h;c[3]=g*-h+a*b;return c},multiplyVec2:function(a,b,c){c||(c=b);var e=b[0];b=b[1];c[0]=e*a[0]+b*a[1];c[1]=e*a[2]+b*a[3];return c},scale:function(a,b,c){c||(c=a);var e=a[1],f=a[2],g=a[3],h=b[0];b=b[1];c[0]=a[0]*h;c[1]=e*b;c[2]=f*h;c[3]=
|
||||||
|
g*b;return c},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"}},N={create:function(a){var b=new k(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):(b[0]=0,b[1]=0,b[2]=0,b[3]=0);return b},createFrom:function(a,b,c,e){var f=new k(4);f[0]=a;f[1]=b;f[2]=c;f[3]=e;return f},add:function(a,b,c){c||(c=b);c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];c[3]=a[3]+b[3];return c},subtract:function(a,b,c){c||(c=b);c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];c[3]=a[3]-b[3];return c},multiply:function(a,
|
||||||
|
b,c){c||(c=b);c[0]=a[0]*b[0];c[1]=a[1]*b[1];c[2]=a[2]*b[2];c[3]=a[3]*b[3];return c},divide:function(a,b,c){c||(c=b);c[0]=a[0]/b[0];c[1]=a[1]/b[1];c[2]=a[2]/b[2];c[3]=a[3]/b[3];return c},scale:function(a,b,c){c||(c=a);c[0]=a[0]*b;c[1]=a[1]*b;c[2]=a[2]*b;c[3]=a[3]*b;return c},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])},negate:function(a,b){b||
|
||||||
|
(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=-a[3];return b},length:function(a){var b=a[0],c=a[1],e=a[2];a=a[3];return Math.sqrt(b*b+c*c+e*e+a*a)},squaredLength:function(a){var b=a[0],c=a[1],e=a[2];a=a[3];return b*b+c*c+e*e+a*a},lerp:function(a,b,c,e){e||(e=a);e[0]=a[0]+c*(b[0]-a[0]);e[1]=a[1]+c*(b[1]-a[1]);e[2]=a[2]+c*(b[2]-a[2]);e[3]=a[3]+c*(b[3]-a[3]);return e},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"}};b&&(b.glMatrixArrayType=k,b.MatrixArray=k,b.setMatrixArrayType=c,b.determineMatrixArrayType=
|
||||||
|
f,b.glMath=e,b.vec2=M,b.vec3=l,b.vec4=N,b.mat2=L,b.mat3=x,b.mat4=t,b.quat4=m);return{glMatrixArrayType:k,MatrixArray:k,setMatrixArrayType:c,determineMatrixArrayType:f,glMath:e,vec2:M,vec3:l,vec4:N,mat2:L,mat3:x,mat4:t,quat4:m}});PIXI=PIXI||{};PIXI.shaderFragmentSrc=["precision mediump float;","varying vec2 vTextureCoord;","varying float vColor;","uniform sampler2D uSampler;","void main(void) {","gl_FragColor \x3d texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));","gl_FragColor \x3d gl_FragColor * vColor;","}"];
|
||||||
|
PIXI.shaderVertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform mat4 uMVMatrix;","varying vec2 vTextureCoord;","varying float vColor;","void main(void) {","gl_Position \x3d uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);","vTextureCoord \x3d aTextureCoord;","vColor \x3d aColor;","}"];
|
||||||
|
PIXI.CompileVertexShader=function(b,c){for(var f="",e=0;e<c.length;e++)f+=c[e];e=b.createShader(b.VERTEX_SHADER);b.shaderSource(e,f);b.compileShader(e);return!b.getShaderParameter(e,b.COMPILE_STATUS)?(alert(b.getShaderInfoLog(e)),null):e};PIXI.CompileFragmentShader=function(b,c){for(var f="",e=0;e<c.length;e++)f+=c[e];e=b.createShader(b.FRAGMENT_SHADER);b.shaderSource(e,f);b.compileShader(e);return!b.getShaderParameter(e,b.COMPILE_STATUS)?(alert(b.getShaderInfoLog(e)),null):e};PIXI=PIXI||{};PIXI._defaultFrame={x:0,y:0,width:1,height:1};
|
||||||
|
PIXI.WebGLRenderer=function(b,c){this.width=b?b:800;this.height=c?c:600;this.view=document.createElement("canvas");this.view.width=this.width;this.view.height=this.height;this.view.background="#FF0000";var f=this;this.view.addEventListener("webglcontextlost",function(b){f.handleContextLost(b)},!1);this.view.addEventListener("webglcontextrestored",function(b){f.handleContextRestored(b)},!1);this.batchs=[];try{this.gl=this.view.getContext("experimental-webgl",{alpha:!1})}catch(e){throw Error(" This browser does not support webGL. Try using the canvas renderer"+
|
||||||
|
this);}this.initShaders();var g=this.gl;this.batch=new PIXI.WebGLBatch(g);g.disable(g.DEPTH_TEST);g.enable(g.BLEND);g.colorMask(!0,!0,!0,!1);this.projectionMatrix=mat4.create();this.resize(this.width,this.height);this.contextLost=!1};PIXI.WebGLRenderer.constructor=PIXI.WebGLRenderer;
|
||||||
|
PIXI.WebGLRenderer.prototype.initShaders=function(){var b=this.gl,c=PIXI.CompileFragmentShader(b,PIXI.shaderFragmentSrc),f=PIXI.CompileVertexShader(b,PIXI.shaderVertexSrc),e=this.shaderProgram=b.createProgram();b.attachShader(e,f);b.attachShader(e,c);b.linkProgram(e);b.getProgramParameter(e,b.LINK_STATUS)||alert("Could not initialise shaders");b.useProgram(e);e.vertexPositionAttribute=b.getAttribLocation(e,"aVertexPosition");b.enableVertexAttribArray(e.vertexPositionAttribute);e.textureCoordAttribute=
|
||||||
|
b.getAttribLocation(e,"aTextureCoord");b.enableVertexAttribArray(e.textureCoordAttribute);e.colorAttribute=b.getAttribLocation(e,"aColor");b.enableVertexAttribArray(e.colorAttribute);e.mvMatrixUniform=b.getUniformLocation(e,"uMVMatrix");e.samplerUniform=b.getUniformLocation(e,"uSampler");PIXI.shaderProgram=this.shaderProgram};
|
||||||
|
PIXI.WebGLRenderer.prototype.checkVisibility=function(b){b=b.children;for(var c=0;c<b.length;c++){var f=b[c];f.textureChange&&(f.textureChange=!1,f.visible&&(this.removeDisplayObject(f),this.addDisplayObject(f)));f.cacheVisible!=f.visible?((f.cacheVisible=f.visible)?this.addDisplayObject(f):this.removeDisplayObject(f),this.setGLVisible(f,f.visible)):0<f.children.length&&this.checkVisibility(f)}};
|
||||||
|
PIXI.WebGLRenderer.prototype.setGLVisible=function(b,c){for(var f=b.children,e=0;e<f.length;e++){var g=f[e];c?this.addDisplayObject(g):this.removeDisplayObject(g);0<g.children.length&&this.setGLVisible(g,c)}};
|
||||||
|
PIXI.WebGLRenderer.prototype.render=function(b){if(!this.contextLost){for(var c=0;c<b.__childrenRemoved.length;c++)this.removeDisplayObject(b.__childrenRemoved[c]);for(c=0;c<b.__childrenAdded.length;c++)this.addDisplayObject(b.__childrenAdded[c]);for(c=0;c<PIXI.texturesToUpdate.length;c++)this.updateTexture(PIXI.texturesToUpdate[c]);b.__childrenRemoved=[];b.__childrenAdded=[];PIXI.texturesToUpdate=[];this.checkVisibility(b);b.updateTransform();c=this.gl;c.clear(c.COLOR_BUFFER_BIT);c.clearColor(1,
|
||||||
|
1,1,1);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform,!1,this.projectionMatrix);for(c=0;c<this.batchs.length;c++)b=this.batchs[c],b instanceof PIXI.WebGLBatch?this.batchs[c].render():b instanceof PIXI.Strip&&b.visible&&this.renderStrip(b)}};
|
||||||
|
PIXI.WebGLRenderer.prototype.updateTexture=function(b){var c=this.gl;b._glTexture||(b._glTexture=c.createTexture());b.hasLoaded&&(c.bindTexture(c.TEXTURE_2D,b._glTexture),c.pixelStorei(c.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,b.image),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.LINEAR),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.LINEAR),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,
|
||||||
|
c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.bindTexture(c.TEXTURE_2D,null));this.refreshBatchs=!0};
|
||||||
|
PIXI.WebGLRenderer.prototype.addDisplayObject=function(b){if(b.stage&&(b.cacheVisible=b.visible))if(b.batch=null,b.renderable){b.__inWebGL=!0;var c=b;do{if(0==c.childIndex)c=c.parent;else for(c=c.parent.children[c.childIndex-1];0!=c.children.length;)c=c.children[c.children.length-1];if(c==b.stage)break}while(!c.renderable||!c.__inWebGL);var f=b;do{if(0==f.children.length){for(;f.childIndex==f.parent.children.length-1;)if(f=f.parent,f==b.stage){f=null;break}f&&(f=f.parent.children[f.childIndex+1])}else f=
|
||||||
|
f.children[0];if(!f)break}while(!f.renderable||!f.__inWebGL);if(b instanceof PIXI.Sprite){var e;if(c instanceof PIXI.Sprite){if((e=c.batch)&&e.texture==b.texture.baseTexture&&e.blendMode==b.blendMode){e.insertAfter(b,c);return}}else e=c;if(f&&f instanceof PIXI.Sprite&&(c=f.batch)){if(c.texture==b.texture.baseTexture&&c.blendMode==b.blendMode){c.insertBefore(b,f);return}if(c==e){f=e.split(f);c=PIXI._getBatch(this.gl);e=this.batchs.indexOf(e);c.init(b);this.batchs.splice(e+1,0,c,f);return}}c=PIXI._getBatch(this.gl);
|
||||||
|
c.init(b);e?(e=this.batchs.indexOf(e),this.batchs.splice(e+1,0,c)):this.batchs.push(c)}else b instanceof PIXI.Strip&&(this.initStrip(b),this.batchs.push(b));this.batchUpdate=!0}};
|
||||||
|
PIXI.WebGLRenderer.prototype.removeDisplayObject=function(b){b.cacheVisible=b.visible;if(b.renderable){var c;if(b instanceof PIXI.Sprite){var f=b.batch;if(!f)return;f.remove(b);0==f.size&&(c=f)}else c=b;c&&(b=this.batchs.indexOf(c),-1!=b&&(!(0==b||b==this.batchs.length-1)&&this.batchs[b-1]instanceof PIXI.WebGLBatch&&this.batchs[b+1]instanceof PIXI.WebGLBatch&&this.batchs[b-1].texture==this.batchs[b+1].texture?(this.batchs[b-1].merge(this.batchs[b+1]),c instanceof PIXI.WebGLBatch&&PIXI._returnBatch(c),
|
||||||
|
PIXI._returnBatch(this.batchs[b+1]),this.batchs.splice(b,2)):(this.batchs.splice(b,1),c instanceof PIXI.WebGLBatch&&PIXI._returnBatch(c))))}};PIXI.WebGLRenderer.prototype.resize=function(b,c){this.width=b;this.height=c;this.view.width=b;this.view.height=c;this.gl.viewport(0,0,this.width,this.height);mat4.identity(this.projectionMatrix);mat4.scale(this.projectionMatrix,[2/this.width,-2/this.height,1]);mat4.translate(this.projectionMatrix,[-this.width/2,-this.height/2,0])};
|
||||||
|
PIXI.WebGLRenderer.prototype.initStrip=function(b){var c=this.gl;b._vertexBuffer=c.createBuffer();b._indexBuffer=c.createBuffer();b._uvBuffer=c.createBuffer();b._colorBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,b._vertexBuffer);c.bufferData(c.ARRAY_BUFFER,b.verticies,c.DYNAMIC_DRAW);c.bindBuffer(c.ARRAY_BUFFER,b._uvBuffer);c.bufferData(c.ARRAY_BUFFER,b.uvs,c.STATIC_DRAW);c.bindBuffer(c.ARRAY_BUFFER,b._colorBuffer);c.bufferData(c.ARRAY_BUFFER,b.colors,c.STATIC_DRAW);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
|
||||||
|
b._indexBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,b.indices,c.STATIC_DRAW)};var bloop=!0;
|
||||||
|
PIXI.WebGLRenderer.prototype.renderStrip=function(b){var c=this.gl,f=this.shaderProgram,e=mat3.toMat4(b.worldTransform);mat4.transpose(e);mat4.multiply(this.projectionMatrix,e,e);c.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform,!1,e);b.blendMode==PIXI.blendModes.NORMAL?c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA):c.blendFunc(c.ONE,c.ONE_MINUS_SRC_COLOR);b.dirty?(b.dirty=!1,c.bindBuffer(c.ARRAY_BUFFER,b._vertexBuffer),c.bufferData(c.ARRAY_BUFFER,b.verticies,c.STATIC_DRAW),c.vertexAttribPointer(f.vertexPositionAttribute,
|
||||||
|
2,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,b._uvBuffer),c.bufferData(c.ARRAY_BUFFER,b.uvs,c.STATIC_DRAW),c.vertexAttribPointer(f.textureCoordAttribute,2,c.FLOAT,!1,0,0),c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,b.texture.baseTexture._glTexture),c.bindBuffer(c.ARRAY_BUFFER,b._colorBuffer),c.bufferData(c.ARRAY_BUFFER,b.colors,c.STATIC_DRAW),c.vertexAttribPointer(f.colorAttribute,1,c.FLOAT,!1,0,0),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,b._indexBuffer),c.bufferData(c.ELEMENT_ARRAY_BUFFER,
|
||||||
|
b.indices,c.STATIC_DRAW)):(c.bindBuffer(c.ARRAY_BUFFER,b._vertexBuffer),c.bufferSubData(c.ARRAY_BUFFER,0,b.verticies),c.vertexAttribPointer(f.vertexPositionAttribute,2,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,b._uvBuffer),c.vertexAttribPointer(f.textureCoordAttribute,2,c.FLOAT,!1,0,0),c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,b.texture.baseTexture._glTexture),c.bindBuffer(c.ARRAY_BUFFER,b._colorBuffer),c.vertexAttribPointer(f.colorAttribute,1,c.FLOAT,!1,0,0),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,
|
||||||
|
b._indexBuffer));c.drawElements(c.TRIANGLE_STRIP,b.indices.length,c.UNSIGNED_SHORT,0);c.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform,!1,this.projectionMatrix)};PIXI.WebGLRenderer.prototype.handleContextLost=function(b){b.preventDefault();this.contextLost=!0};
|
||||||
|
PIXI.WebGLRenderer.prototype.handleContextRestored=function(){this.gl=this.view.getContext("experimental-webgl",{alpha:!0});this.initShaders();for(var b=0;b<PIXI.TextureCache.length;b++)this.updateTexture(PIXI.TextureCache[b]);for(b=0;b<this.batchs.length;b++)this.batchs[b].restoreLostContext(this.gl),this.batchs[b].dirty=!0;PIXI._restoreBatchs(this.gl);this.contextLost=!1};PIXI=PIXI||{};PIXI.CanvasRenderer=function(b,c){this.width=b?b:800;this.height=c?c:600;this.refresh=!0;this.view=document.createElement("canvas");this.view.width=this.width;this.view.height=this.height;this.view.background="#FF0000";this.count=0;this.context=this.view.getContext("2d")};PIXI.CanvasRenderer.constructor=PIXI.CanvasRenderer;
|
||||||
|
PIXI.CanvasRenderer.prototype.render=function(b){b.__childrenAdded=[];b.__childrenRemoved=[];PIXI.texturesToUpdate=[];this.context.setTransform(1,0,0,1,0,0);b.updateTransform();this.context.setTransform(1,0,0,1,0,0);this.context.clearRect(0,0,this.width,this.height);this.renderDisplayObject(b)};PIXI.CanvasRenderer.prototype.resize=function(b,c){this.width=b;this.height=c;this.view.width=b;this.view.height=c};
|
||||||
|
PIXI.CanvasRenderer.prototype.renderDisplayObject=function(b){var c=b.worldTransform,f=this.context;f.globalCompositeOperation="source-over";if(b.visible){if(b instanceof PIXI.Sprite){var e=b.texture.frame;e&&(f.globalAlpha=b.worldAlpha,0==b.rotation?(this.context.setTransform(1,0,0,1,0,0),f.drawImage(b.texture.baseTexture.image,e.x,e.y,e.width,e.height,c[2]+b.anchor.x*-e.width+0.5|0,c[5]+b.anchor.y*-e.height+0.5|0,e.width*c[0],e.height*c[4])):(f.setTransform(c[0],c[3],c[1],c[4],c[2],c[5]),f.drawImage(b.texture.baseTexture.image,
|
||||||
|
e.x,e.y,e.width,e.height,b.anchor.x*-e.width,b.anchor.y*-e.height,e.width,e.height)))}else b instanceof PIXI.Strip&&(f.setTransform(c[0],c[3],c[1],c[4],c[2],c[5]),this.renderStrip(b));for(c=0;c<b.children.length;c++)this.renderDisplayObject(b.children[c])}};
|
||||||
|
PIXI.CanvasRenderer.prototype.renderStripFlat=function(b){var c=this.context;b=b.verticies;var f=b.length/2;this.count++;c.beginPath();for(var e=1;e<f-2;e++){var g=2*e,h=b[g+2],k=b[g+4],l=b[g+3],p=b[g+5];c.moveTo(b[g],b[g+1]);c.lineTo(h,l);c.lineTo(k,p)}c.fillStyle="#FF0000";c.fill();c.closePath()};
|
||||||
|
PIXI.CanvasRenderer.prototype.renderStrip=function(b){var c=this.context,f=b.verticies,e=b.uvs,g=f.length/2;this.count++;for(var h=1;h<g-2;h++){var k=2*h,l=f[k],p=f[k+2],q=f[k+4],C=f[k+1],F=f[k+3],u=f[k+5],w=e[k]*b.texture.width,x=e[k+2]*b.texture.width,t=e[k+4]*b.texture.width,m=e[k+1]*b.texture.height,H=e[k+3]*b.texture.height,k=e[k+5]*b.texture.height;c.save();c.beginPath();c.moveTo(l,C);c.lineTo(p,F);c.lineTo(q,u);c.closePath();c.clip();var B=w*H+m*t+x*k-H*t-m*x-w*k;c.transform((l*H+m*q+p*k-H*
|
||||||
|
q-m*p-l*k)/B,(C*H+m*u+F*k-H*u-m*F-C*k)/B,(w*p+l*t+x*q-p*t-l*x-w*q)/B,(w*F+C*t+x*u-F*t-C*x-w*u)/B,(w*H*q+m*p*t+l*x*k-l*H*t-m*x*q-w*p*k)/B,(w*H*u+m*F*t+C*x*k-C*H*t-m*x*u-w*F*k)/B);c.drawImage(b.texture.baseTexture.image,0,0);c.restore()}};PIXI=PIXI||{};PIXI.Point=function(b,c){this.x=b?b:0;this.y=c?c:0};PIXI.Point.clone=function(){return new PIXI.Point(this.x,this.y)};PIXI.Point.constructor=PIXI.Point;PIXI=PIXI||{};PIXI.Rectangle=function(b,c,f,e){this.x=b?b:0;this.y=c?c:0;this.width=f?f:0;this.height=e?e:0};PIXI.Point.clone=function(){return new PIXI.Rectangle(this.x,this.y,this.width,this.height)};PIXI.Rectangle.constructor=PIXI.Rectangle;PIXI=PIXI||{};PIXI.DisplayObject=function(){this.position=new PIXI.Point;this.scale=new PIXI.Point(1,1);this.rotation=0;this.alpha=1;this.visible=!0;this.stage=this.parent=null;this.worldAlpha=1;this.color=[];this.worldTransform=mat3.identity();this.localTransform=mat3.identity();this.dynamic=!0;this._sr=0;this._cr=1;this.renderable=!1};PIXI.DisplayObject.constructor=PIXI.DisplayObject;
|
||||||
|
PIXI.DisplayObject.prototype.updateTransform=function(){this.rotation!=this.rotationCache&&(this.rotationCach=this.rotation,this._sr=Math.sin(this.rotation),this._cr=Math.cos(this.rotation));this.localTransform[0]=this._cr*this.scale.x;this.localTransform[1]=-this._sr*this.scale.y;this.localTransform[3]=this._sr*this.scale.x;this.localTransform[4]=this._cr*this.scale.y;this.localTransform[2]=this.position.x;this.localTransform[5]=this.position.y;mat3.multiply(this.localTransform,this.parent.worldTransform,
|
||||||
|
this.worldTransform);this.worldAlpha=this.alpha*this.parent.worldAlpha};PIXI=PIXI||{};PIXI._batchs=[];PIXI._getBatch=function(b){return 0==PIXI._batchs.length?new PIXI.WebGLBatch(b):PIXI._batchs.pop()};PIXI._returnBatch=function(b){b.clean();PIXI._batchs.push(b)};PIXI._restoreBatchs=function(b){for(var c=0;c<PIXI._batchs.length;c++)PIXI._batchs[c].restoreLostContext(b)};
|
||||||
|
PIXI.WebGLBatch=function(b){this.gl=b;this.size=0;this.vertexBuffer=b.createBuffer();this.indexBuffer=b.createBuffer();this.uvBuffer=b.createBuffer();this.colorBuffer=b.createBuffer();this.blendMode=PIXI.blendModes.NORMAL;this.dynamicSize=1};PIXI.WebGLBatch.constructor=PIXI.WebGLBatch;PIXI.WebGLBatch.prototype.clean=function(){this.verticies=[];this.uvs=[];this.indices=[];this.colors=[];this.dynamicSize=1;this.last=this.texture=null;this.size=0;this.head;this.tail};
|
||||||
|
PIXI.WebGLBatch.prototype.restoreLostContext=function(b){this.gl=b;this.vertexBuffer=b.createBuffer();this.indexBuffer=b.createBuffer();this.uvBuffer=b.createBuffer();this.colorBuffer=b.createBuffer()};PIXI.WebGLBatch.prototype.init=function(b){b.batch=this;this.dirty=!0;this.blendMode=b.blendMode;this.texture=b.texture.baseTexture;this.tail=this.head=b;this.size=1;this.growBatch()};
|
||||||
|
PIXI.WebGLBatch.prototype.insertBefore=function(b,c){this.size++;b.batch=this;this.dirty=!0;var f=c.__prev;c.__prev=b;b.__next=c;f?(b.__prev=f,f.__next=b):this.head=b};PIXI.WebGLBatch.prototype.insertAfter=function(b,c){this.size++;b.batch=this;this.dirty=!0;var f=c.__next;c.__next=b;b.__prev=c;f?(b.__next=f,f.__prev=b):this.tail=b};
|
||||||
|
PIXI.WebGLBatch.prototype.remove=function(b){this.size--;0==this.size?(b.__prev=null,b.__next=null):(b.__prev?b.__prev.__next=b.__next:this.head=b.__next,b.__next?b.__next.__prev=b.__prev:this.tail=b.__prev,b.batch=null,b.__next=null,b.__prev=null,this.dirty=!0)};
|
||||||
|
PIXI.WebGLBatch.prototype.split=function(b){this.dirty=!0;var c=new PIXI.WebGLBatch(this.gl);c.init(b);c.tail=this.tail;this.tail=b.__prev;this.tail.__next=null;b.__prev=null;for(var f=0;b;)f++,b.batch=c,b=b.__next;c.size=f;this.size-=f;return c};PIXI.WebGLBatch.prototype.merge=function(b){this.dirty=!0;this.tail.__next=b.head;b.head.__prev=this.tail;this.size+=b.size;this.tail=b.tail;for(b=b.head;b;)b.batch=this,b=b.__next};
|
||||||
|
PIXI.WebGLBatch.prototype.growBatch=function(){var b=this.gl;this.dynamicSize=1==this.size?1:1.5*this.size;this.verticies=new Float32Array(8*this.dynamicSize);b.bindBuffer(b.ARRAY_BUFFER,this.vertexBuffer);b.bufferData(b.ARRAY_BUFFER,this.verticies,b.DYNAMIC_DRAW);this.uvs=new Float32Array(8*this.dynamicSize);b.bindBuffer(b.ARRAY_BUFFER,this.uvBuffer);b.bufferData(b.ARRAY_BUFFER,this.uvs,b.DYNAMIC_DRAW);this.dirtyUVS=!0;this.colors=new Float32Array(4*this.dynamicSize);b.bindBuffer(b.ARRAY_BUFFER,
|
||||||
|
this.colorBuffer);b.bufferData(b.ARRAY_BUFFER,this.colors,b.DYNAMIC_DRAW);this.dirtyColors=!0;this.indices=new Uint16Array(6*this.dynamicSize);for(var c=this.indices.length/6,f=0;f<c;f++){var e=6*f,g=4*f;this.indices[e+0]=g+0;this.indices[e+1]=g+1;this.indices[e+2]=g+2;this.indices[e+3]=g+0;this.indices[e+4]=g+2;this.indices[e+5]=g+3}b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.indexBuffer);b.bufferData(b.ELEMENT_ARRAY_BUFFER,this.indices,b.STATIC_DRAW)};
|
||||||
|
PIXI.WebGLBatch.prototype.refresh=function(){this.dynamicSize<this.size&&this.growBatch();for(var b=0,c,f=this.head;f;){c=8*b;var e=f.texture,g=e.frame,h=e.baseTexture.width,e=e.baseTexture.height;this.uvs[c+0]=g.x/h;this.uvs[c+1]=g.y/e;this.uvs[c+2]=(g.x+g.width)/h;this.uvs[c+3]=g.y/e;this.uvs[c+4]=(g.x+g.width)/h;this.uvs[c+5]=(g.y+g.height)/e;this.uvs[c+6]=g.x/h;this.uvs[c+7]=(g.y+g.height)/e;f.updateFrame=!1;colorIndex=4*b;this.colors[colorIndex]=this.colors[colorIndex+1]=this.colors[colorIndex+
|
||||||
|
2]=this.colors[colorIndex+3]=f.worldAlpha;f=f.__next;b++}this.dirtyColors=this.dirtyUVS=!0};
|
||||||
|
PIXI.WebGLBatch.prototype.update=function(){for(var b,c,f,e,g,h,k,l,p,q,C,F=0,u=this.head;u;)c=u.width,f=u.height,e=u.anchor.x,g=u.anchor.y,h=c*(1-e),c*=-e,e=f*(1-g),g=f*-g,f=8*F,b=u.worldTransform,k=b[0],l=b[3],p=b[1],q=b[4],C=b[2],b=b[5],this.verticies[f+0]=k*c+p*g+C,this.verticies[f+1]=q*g+l*c+b,this.verticies[f+2]=k*h+p*g+C,this.verticies[f+3]=q*g+l*h+b,this.verticies[f+4]=k*h+p*e+C,this.verticies[f+5]=q*e+l*h+b,this.verticies[f+6]=k*c+p*e+C,this.verticies[f+7]=q*e+l*c+b,u.updateFrame&&(this.dirtyUVS=
|
||||||
|
!0,e=u.texture,h=e.frame,c=e.baseTexture.width,e=e.baseTexture.height,this.uvs[f+0]=h.x/c,this.uvs[f+1]=h.y/e,this.uvs[f+2]=(h.x+h.width)/c,this.uvs[f+3]=h.y/e,this.uvs[f+4]=(h.x+h.width)/c,this.uvs[f+5]=(h.y+h.height)/e,this.uvs[f+6]=h.x/c,this.uvs[f+7]=(h.y+h.height)/e,u.updateFrame=!1),u.cacheAlpha!=u.alpha&&(u.cacheAlpha=u.alpha,h=4*F,this.colors[void 0]=this.colors[h+1]=this.colors[h+2]=this.colors[h+3]=u.worldAlpha,this.dirtyColors=!0),F++,u=u.__next};
|
||||||
|
PIXI.WebGLBatch.prototype.render=function(){this.dirty&&(this.refresh(),this.dirty=!1);if(0!=this.size){this.update();var b=this.gl;this.blendMode==PIXI.blendModes.NORMAL?b.blendFunc(b.ONE,b.ONE_MINUS_SRC_ALPHA):b.blendFunc(b.ONE,b.ONE_MINUS_SRC_COLOR);var c=PIXI.shaderProgram;b.bindBuffer(b.ARRAY_BUFFER,this.vertexBuffer);b.bufferSubData(b.ARRAY_BUFFER,0,this.verticies);b.vertexAttribPointer(c.vertexPositionAttribute,2,b.FLOAT,!1,0,0);b.bindBuffer(b.ARRAY_BUFFER,this.uvBuffer);this.dirtyUVS&&(this.dirtyUVS=
|
||||||
|
!1,b.bufferSubData(b.ARRAY_BUFFER,0,this.uvs));b.vertexAttribPointer(c.textureCoordAttribute,2,b.FLOAT,!1,0,0);b.activeTexture(b.TEXTURE0);b.bindTexture(b.TEXTURE_2D,this.texture._glTexture);b.bindBuffer(b.ARRAY_BUFFER,this.colorBuffer);this.dirtyColors&&(this.dirtyColors=!1,b.bufferSubData(b.ARRAY_BUFFER,0,this.colors));b.vertexAttribPointer(c.colorAttribute,1,b.FLOAT,!1,0,0);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.indexBuffer);b.drawElements(b.TRIANGLES,6*this.size,b.UNSIGNED_SHORT,0)}};PIXI=PIXI||{};PIXI.DisplayObjectContainer=function(){PIXI.DisplayObject.call(this);this.children=[];this.renderable=!1};PIXI.DisplayObjectContainer.constructor=PIXI.DisplayObjectContainer;PIXI.DisplayObjectContainer.prototype=Object.create(PIXI.DisplayObject.prototype);PIXI.DisplayObjectContainer.prototype.addChild=function(b){void 0!=b.parent&&b.parent.removeChild(b);b.parent=this;b.childIndex=this.children.length;this.children.push(b);this.stage&&this.stage.__addChild(b)};
|
||||||
|
PIXI.DisplayObjectContainer.prototype.addChildAt=function(b,c){if(0<=c&&c<=this.children.length){void 0!=b.parent&&b.parent.removeChild(b);c==this.children.length?this.children.push(b):this.children.splice(c,0,b);b.parent=this;b.childIndex=c;for(var f=this.children.length,e=c;e<f;e++)this.children[e].childIndex=e;this.stage&&this.stage.__addChild(b)}else throw Error(b+" The index supplied is out of bounds "+this);};
|
||||||
|
PIXI.DisplayObjectContainer.prototype.removeChild=function(b){var c=this.children.indexOf(b);if(-1!==c){this.stage&&this.stage.__removeChild(b);b.parent=void 0;this.children.splice(c,1);b=c;for(c=this.children.length;b<c;b++)this.children[b].childIndex-=1}else throw Error(b+" The supplied DisplayObject must be a child of the caller "+this);};
|
||||||
|
PIXI.DisplayObjectContainer.prototype.updateTransform=function(){if(this.visible){PIXI.DisplayObject.prototype.updateTransform.call(this);for(var b=0,c=this.children.length;b<c;b++)this.children[b].updateTransform()}};PIXI=PIXI||{};PIXI.Stage=function(){PIXI.DisplayObjectContainer.call(this);this.worldTransform=mat3.identity();this.__childrenAdded=[];this.__childrenRemoved=[];this.childIndex=0;this.stage=this};PIXI.Stage.constructor=PIXI.Stage;PIXI.Stage.prototype=Object.create(PIXI.DisplayObjectContainer.prototype);PIXI.Stage.prototype.updateTransform=function(){this.worldAlpha=1;for(var b=0,c=this.children.length;b<c;b++)this.children[b].updateTransform()};
|
||||||
|
PIXI.Stage.prototype.__addChild=function(b){this.__childrenAdded.push(b);b.stage=this;if(b.children)for(var c=0;c<b.children.length;c++)this.__addChild(b.children[c])};PIXI.Stage.prototype.__removeChild=function(b){this.__childrenRemoved.push(b);b.stage=void 0;if(b.children)for(var c=0,f=b.children.length;c<f;c++)this.__removeChild(b.children[c])};PIXI=PIXI||{};PIXI.blendModes={};PIXI.blendModes.NORMAL=0;PIXI.blendModes.SCREEN=1;
|
||||||
|
PIXI.Sprite=function(b){PIXI.DisplayObjectContainer.call(this);this.anchor=new PIXI.Point;this.texture=b;this.blendMode=PIXI.blendModes.NORMAL;this.height=this.width=1;b.baseTexture.hasLoaded?(this.width=this.texture.frame.width,this.height=this.texture.frame.height,this.updateFrame=!0):(this.onTextureUpdateBind=this.onTextureUpdate.bind(this),this.texture.addEventListener("update",this.onTextureUpdateBind));this.renderable=!0};PIXI.Sprite.constructor=PIXI.Sprite;PIXI.Sprite.prototype=Object.create(PIXI.DisplayObjectContainer.prototype);
|
||||||
|
PIXI.Sprite.prototype.setTexture=function(b){this.texture.baseTexture!=b.baseTexture&&(this.textureChange=!0);this.texture=b;this.width=b.frame.width;this.height=b.frame.height;this.updateFrame=!0};PIXI.Sprite.prototype.onTextureUpdate=function(){this.width=this.texture.frame.width;this.height=this.texture.frame.height;this.updateFrame=!0};PIXI.Sprite.fromFrame=function(b){var c=PIXI.TextureCache[b];if(!c)throw Error("The frameId '"+b+"' does not exist in the texture cache"+this);return new PIXI.Sprite(c)};
|
||||||
|
PIXI.Sprite.fromImage=function(b){b=PIXI.Texture.fromImage(b);return new PIXI.Sprite(b)};PIXI=PIXI||{};
|
||||||
|
PIXI.Strip=function(b,c,f){PIXI.DisplayObjectContainer.call(this);this.texture=b;this.blendMode=PIXI.blendModes.NORMAL;try{this.uvs=new Float32Array([0,1,1,1,1,0,0,1]),this.verticies=new Float32Array([0,0,0,0,0,0,0,0,0]),this.colors=new Float32Array([1,1,1,1]),this.indices=new Uint16Array([0,1,2,3])}catch(e){this.uvs=[0,1,1,1,1,0,0,1],this.verticies=[0,0,0,0,0,0,0,0,0],this.colors=[1,1,1,1],this.indices=[0,1,2,3]}this.width=c;this.height=f;b.baseTexture.hasLoaded?(this.width=this.texture.frame.width,this.height=
|
||||||
|
this.texture.frame.height,this.updateFrame=!0):(this.onTextureUpdateBind=this.onTextureUpdate.bind(this),this.texture.addEventListener("update",this.onTextureUpdateBind));this.renderable=!0};PIXI.Strip.constructor=PIXI.Strip;PIXI.Strip.prototype=Object.create(PIXI.DisplayObjectContainer.prototype);PIXI.Strip.prototype.setTexture=function(b){this.texture=b;this.width=b.frame.width;this.height=b.frame.height;this.updateFrame=!0};PIXI.Strip.prototype.onTextureUpdate=function(){this.updateFrame=!0};PIXI=PIXI||{};PIXI.Rope=function(b,c){PIXI.Strip.call(this,b);this.points=c;try{this.verticies=new Float32Array(4*c.length),this.uvs=new Float32Array(4*c.length),this.colors=new Float32Array(2*c.length),this.indices=new Uint16Array(2*c.length)}catch(f){this.verticies=verticies,this.uvs=uvs,this.colors=colors,this.indices=indices}this.refresh()};PIXI.Rope.constructor=GAME.Rope;PIXI.Rope.prototype=Object.create(PIXI.Strip.prototype);
|
||||||
|
PIXI.Rope.prototype.refresh=function(){var b=this.points;if(!(1>b.length)){var c=this.uvs,f=this.indices,e=this.colors;this.count-=0.2;c[0]=0;c[1]=1;c[2]=0;c[3]=1;e[0]=1;e[1]=1;f[0]=0;f[1]=1;for(var b=b.length,g=1;g<b;g++){var h=4*g,k=g/(b-1);c[h]=k;c[h+1]=0;c[h+2]=k;c[h+3]=1;h=2*g;e[h]=1;e[h+1]=1;h=2*g;f[h]=h;f[h+1]=h+1}}};
|
||||||
|
PIXI.Rope.prototype.updateTransform=function(){var b=this.points;if(!(1>b.length)){var c=this.verticies,f=b[0],e,g=e=0,h=b[0];this.count-=0.2;c[0]=h.x+e;c[1]=h.y+g;c[2]=h.x-e;c[3]=h.y-g;for(var k=b.length,l=1;l<k;l++){var h=b[l],p=4*l;e=l<b.length-1?b[l+1]:h;g=-(e.x-f.x);e=e.y-f.y;var f=Math.sqrt(e*e+g*g),q=this.texture.height/2;e/=f;g/=f;e*=q;g*=q;c[p]=h.x+e;c[p+1]=h.y+g;c[p+2]=h.x-e;c[p+3]=h.y-g;f=h}PIXI.DisplayObjectContainer.prototype.updateTransform.call(this)}};
|
||||||
|
PIXI.Rope.prototype.setTexture=function(b){this.texture=b;this.updateFrame=!0};PIXI=PIXI||{};PIXI.MovieClip=function(b){PIXI.Sprite.call(this,b[0]);this.textures=b;this.currentFrame=0;this.animationSpeed=1};PIXI.MovieClip.constructor=PIXI.MovieClip;PIXI.MovieClip.prototype=Object.create(PIXI.Sprite.prototype);PIXI.MovieClip.prototype.stop=function(){this.playing=!1};PIXI.MovieClip.prototype.play=function(){this.playing=!0};PIXI.MovieClip.prototype.gotoAndStop=function(b){this.playing=!1;this.currentFrame=b;this.setTexture(this.textures[(this.currentFrame+0.5|0)%this.textures.length])};
|
||||||
|
PIXI.MovieClip.prototype.gotoAndPlay=function(b){this.currentFrame=b;this.playing=!0};PIXI.MovieClip.prototype.updateTransform=function(){PIXI.Sprite.prototype.updateTransform.call(this);this.playing&&(this.currentFrame+=this.animationSpeed,this.setTexture(this.textures[(this.currentFrame+0.5|0)%this.textures.length]))};PIXI=PIXI||{};PIXI.BaseTextureCache={};PIXI.texturesToUpdate=[];PIXI.BaseTexture=function(b){PIXI.EventTarget.call(this);this.imageUrl=b;this.image=new Image;var c=this;this.image.onload=function(){c.hasLoaded=!0;c.width=c.image.width;c.height=c.image.height;PIXI.texturesToUpdate.push(c);c.dispatchEvent({type:"loaded",content:c})};$.proxy(this.onImageLoaded,this);this.image.src=b;this.height=this.width=100;PIXI.BaseTextureCache[b]=this};PIXI.BaseTexture.constructor=PIXI.BaseTexture;PIXI=PIXI||{};PIXI.TextureCache={};PIXI.FrameCache={};PIXI.Texture=function(b,c){PIXI.EventTarget.call(this);c||(this.noFrame=!0,c=new PIXI.Rectangle(0,0,1,1));this.baseTexture=b;this.frame=c;this.scope=this;if(b.hasLoaded)c||(c=new PIXI.Rectangle(0,0,b.width,b.height)),this.setFrame(c);else{var f=this;b.addEventListener("loaded",function(){f.onBaseTextureLoaded()})}};PIXI.Texture.constructor=PIXI.Texture;
|
||||||
|
PIXI.Texture.prototype.onBaseTextureLoaded=function(){var b=this.baseTexture;b.removeEventListener("loaded",this.onLoaded);this.noFrame&&(this.frame=new PIXI.Rectangle(0,0,b.width,b.height));this.noFrame=!1;this.width=this.frame.width;this.height=this.frame.height;this.scope.dispatchEvent({type:"update",content:this})};PIXI.Texture.prototype.setFrame=function(b){this.frame=b;this.width=b.width;this.height=b.height};
|
||||||
|
PIXI.Texture.fromImage=function(b){var c=PIXI.TextureCache[b];c||((c=PIXI.BaseTextureCache[b])||(c=new PIXI.BaseTexture(b)),c=new PIXI.Texture(c),PIXI.TextureCache[b]=c);return c};PIXI.Texture.fromFrameId=function(b){var c=PIXI.TextureCache[b];if(!c)throw Error("The frameId '"+b+"' does not exist in the texture cache"+this);return c};PIXI.Texture.addTextureToCache=function(b,c){PIXI.TextureCache[c]=b};PIXI.Texture.addTextureToCache=function(b){PIXI.TextureCache[b]=texture};PIXI=PIXI||{};PIXI.autoDetectRenderer=function(b,c){b||(b=800);c||(c=600);var f;try{f=!!window.WebGLRenderingContext&&!!document.createElement("canvas").getContext("experimental-webgl")}catch(e){f=!1}return f?new PIXI.WebGLRenderer(b,c):new PIXI.CanvasRenderer(b,c)};PIXI=PIXI||{};PIXI.SpriteSheetLoader=function(b){PIXI.EventTarget.call(this);this.url=b;this.baseUrl=b.replace(/[^\/]*$/,"");this.texture;this.frames={}};PIXI.SpriteSheetLoader.constructor=PIXI.SpriteSheetLoader;PIXI.SpriteSheetLoader.prototype.load=function(){this.ajaxRequest=new AjaxRequest;var b=this;this.ajaxRequest.onreadystatechange=function(){b.onLoaded()};this.ajaxRequest.open("GET",this.url,!0);this.ajaxRequest.send(null)};
|
||||||
|
PIXI.SpriteSheetLoader.prototype.onLoaded=function(){if(4==this.ajaxRequest.readyState&&(200==this.ajaxRequest.status||-1==window.location.href.indexOf("http"))){var b=eval("("+this.ajaxRequest.responseText+")");this.texture=PIXI.Texture.fromImage(this.baseUrl+b.meta.image).baseTexture;var b=b.frames,c;for(c in b){var f=b[c].frame;PIXI.TextureCache[c]=new PIXI.Texture(this.texture,{x:f.x,y:f.y,width:f.w,height:f.h})}if(this.texture.hasLoaded)this.dispatchEvent({type:"loaded",content:this});else{var e=
|
||||||
|
this;this.texture.addEventListener("loaded",function(){e.dispatchEvent({type:"loaded",content:e})})}}};PIXI=PIXI||{};PIXI.AssetLoader=function(b){PIXI.EventTarget.call(this);this.assetURLs=b;this.assets=[]};PIXI.AssetLoader.constructor=PIXI.AssetLoader;
|
||||||
|
PIXI.AssetLoader.prototype.load=function(){this.loadCount=this.assetURLs.length;for(var b=["jpeg","jpg","png","gif"],c=["json"],f=0;f<this.assetURLs.length;f++){for(var e=this.assetURLs[f],g=e.split(".").pop().toLowerCase(),h,k=0;k<b.length;k++)if(g==b[k]){h="img";break}if(!h)for(k=0;k<c.length;k++)if(g==c[k]){h="atlas";break}if("img"==h)if(e=PIXI.Texture.fromImage(e),e.hasLoaded)this.loadCount--;else{var l=this;e.baseTexture.addEventListener("loaded",function(){l.onAssetLoaded()});this.assets.push(e)}else if("atlas"==
|
||||||
|
h)e=new PIXI.SpriteSheetLoader(e),this.assets.push(e),l=this,e.addEventListener("loaded",function(){l.onAssetLoaded()}),e.load();else throw Error(e+" is an unsupported file type "+this);}};PIXI.AssetLoader.prototype.onAssetLoaded=function(){this.loadCount--;this.dispatchEvent({type:"progress",content:this});0==this.loadCount&&this.dispatchEvent({type:"loaded",content:this})};
|
45
build/PixiBuild.xml
Normal file
45
build/PixiBuild.xml
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<project basedir="." default="run">
|
||||||
|
|
||||||
|
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" classpath="${basedir}/compiler.jar"/>
|
||||||
|
<taskdef resource="net/sf/antcontrib/antlib.xml">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${basedir}/ant-contrib-1.0b3.jar"/>
|
||||||
|
</classpath>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
<target name="run">
|
||||||
|
|
||||||
|
<jscomp compilationLevel="simple" debug="false" output="../bin/pixi.js">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<sources dir="../src/pixi/">
|
||||||
|
<file name="utils/Utils.js"/>
|
||||||
|
<file name="utils/EventTarget.js"/>
|
||||||
|
<file name="utils/gl-matrix-min.js"/>
|
||||||
|
<file name="renderers/WebGLShaders.js"/>
|
||||||
|
<file name="renderers/WebGLRenderer.js"/>
|
||||||
|
<file name="renderers/CanvasRenderer.js"/>
|
||||||
|
<file name="Point.js"/>
|
||||||
|
<file name="Rectangle.js"/>
|
||||||
|
<file name="DisplayObject.js"/>
|
||||||
|
<file name="renderers/WebGLBatch.js"/>
|
||||||
|
<file name="DisplayObjectContainer.js"/>
|
||||||
|
<file name="Stage.js"/>
|
||||||
|
<file name="Sprite.js"/>
|
||||||
|
<file name="extras/Strip.js"/>
|
||||||
|
<file name="extras/Rope.js"/>
|
||||||
|
<file name="MovieClip.js"/>
|
||||||
|
<file name="textures/BaseTexture.js"/>
|
||||||
|
<file name="textures/Texture.js"/>
|
||||||
|
<file name="utils/Detector.js"/>
|
||||||
|
<file name="loaders/SpriteSheetLoader.js"/>
|
||||||
|
<file name="loaders/AssetLoader.js"/>
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
</jscomp>
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
BIN
build/ant-contrib-1.0b3.jar
Normal file
BIN
build/ant-contrib-1.0b3.jar
Normal file
Binary file not shown.
BIN
build/compiler.jar
Normal file
BIN
build/compiler.jar
Normal file
Binary file not shown.
21
examples/alien benchmark/css/main.css
Normal file
21
examples/alien benchmark/css/main.css
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
body{
|
||||||
|
border: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.counter {
|
||||||
|
background: #ccc;
|
||||||
|
width: 74px;
|
||||||
|
position: absolute;
|
||||||
|
background-color:#105CB6;
|
||||||
|
padding: 3px;
|
||||||
|
|
||||||
|
top:50px;
|
||||||
|
|
||||||
|
color:#0ff;
|
||||||
|
font-family: Helvetica, Arial;
|
||||||
|
font-size: 9px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
17
examples/alien benchmark/index.html
Normal file
17
examples/alien benchmark/index.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||||
|
|
||||||
|
<title>Pixi Renderer: Alien Demo</title>
|
||||||
|
<link rel="stylesheet" href="css/main.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="js/vendor/jquery-1.8.3.min.js"></script>
|
||||||
|
<script src="js/stats.min.js"></script>
|
||||||
|
<script src="js/pixi.min.js"></script>
|
||||||
|
<script src="js/StressTest.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
149
examples/alien benchmark/js/StressTest.js
Normal file
149
examples/alien benchmark/js/StressTest.js
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
|
||||||
|
|
||||||
|
$(document).ready(onReady)
|
||||||
|
|
||||||
|
$(window).resize(resize)
|
||||||
|
window.onorientationchange = resize;
|
||||||
|
|
||||||
|
var width = 480;
|
||||||
|
var height = 320;
|
||||||
|
|
||||||
|
var aliens = [];
|
||||||
|
|
||||||
|
var maxX = width;
|
||||||
|
var minX = 0;
|
||||||
|
var maxY = height;
|
||||||
|
var minY = 0;
|
||||||
|
|
||||||
|
var startAlienCount = 100;
|
||||||
|
var isAdding = false;
|
||||||
|
var count = 0;
|
||||||
|
var loader;
|
||||||
|
var alienFrames = ["eggHead.png", "flowerTop.png", "helmlok.png", "skully.png"];
|
||||||
|
|
||||||
|
function onReady()
|
||||||
|
{
|
||||||
|
loader = new PIXI.AssetLoader(["GameAssets.json"])
|
||||||
|
|
||||||
|
loader.addEventListener( 'loaded', function ( event ) {
|
||||||
|
init();
|
||||||
|
} );
|
||||||
|
|
||||||
|
loader.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
renderer = PIXI.autoDetectRenderer(800, 600);
|
||||||
|
|
||||||
|
stage = new PIXI.Stage;
|
||||||
|
|
||||||
|
document.body.appendChild(renderer.view);
|
||||||
|
|
||||||
|
stats = new Stats();
|
||||||
|
|
||||||
|
document.body.appendChild( stats.domElement );
|
||||||
|
stats.domElement.style.position = "absolute";
|
||||||
|
stats.domElement.style.top = "0px";
|
||||||
|
requestAnimFrame(update);
|
||||||
|
|
||||||
|
resize();
|
||||||
|
|
||||||
|
// add a bunch of aliens
|
||||||
|
for (var i = 0; i < startAlienCount; i++)
|
||||||
|
{
|
||||||
|
var alien = new PIXI.Sprite.spriteFromFrame(alienFrames[i % 4]);
|
||||||
|
alien.position.x = Math.random() * maxX;
|
||||||
|
alien.position.y = Math.random() * maxY;
|
||||||
|
alien.anchor.x = 0.5;
|
||||||
|
alien.anchor.y = 0.5;
|
||||||
|
aliens.push(alien);
|
||||||
|
|
||||||
|
stage.addChild(alien);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add some events counter
|
||||||
|
$(renderer.view).mousedown(function(){
|
||||||
|
isAdding = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
$(renderer.view).mouseup(function(){
|
||||||
|
isAdding = false;
|
||||||
|
})
|
||||||
|
|
||||||
|
document.addEventListener("touchstart", onTouchStart, true);
|
||||||
|
document.addEventListener("touchend", onTouchEnd, true);
|
||||||
|
|
||||||
|
// add the bunny counter
|
||||||
|
counter = document.createElement("div");
|
||||||
|
counter.className = "counter";
|
||||||
|
document.body.appendChild( counter);
|
||||||
|
|
||||||
|
count = startAlienCount;
|
||||||
|
counter.innerHTML = count + " ALIENS";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTouchStart(event)
|
||||||
|
{
|
||||||
|
isAdding = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTouchEnd(event)
|
||||||
|
{
|
||||||
|
isAdding = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resize()
|
||||||
|
{
|
||||||
|
var width = $(window).width();
|
||||||
|
var height = $(window).height();
|
||||||
|
|
||||||
|
maxX = width;
|
||||||
|
maxY = height;
|
||||||
|
|
||||||
|
renderer.resize(width, height);
|
||||||
|
|
||||||
|
for (var i = 0; i < aliens.length; i++)
|
||||||
|
{
|
||||||
|
var alien = aliens[i];
|
||||||
|
alien.position.x = Math.random() * maxX;
|
||||||
|
alien.position.y = Math.random() * maxY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function update()
|
||||||
|
{
|
||||||
|
stats.begin();
|
||||||
|
|
||||||
|
if(isAdding)
|
||||||
|
{
|
||||||
|
// add 10 at a time :)
|
||||||
|
|
||||||
|
for (var i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
var alien = PIXI.Sprite.spriteFromFrame(alienFrames[count % 4]);
|
||||||
|
alien.position.x = Math.random() * maxX;
|
||||||
|
alien.position.y = Math.random() * maxY;
|
||||||
|
alien.anchor.x = 0.5;
|
||||||
|
alien.anchor.y = 0.5;
|
||||||
|
alien.rotation = Math.random() - 0.5;
|
||||||
|
stage.addChild(alien);
|
||||||
|
count++;
|
||||||
|
aliens.push(alien);
|
||||||
|
}
|
||||||
|
|
||||||
|
counter.innerHTML = count + " ALIENS";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < aliens.length; i++)
|
||||||
|
{
|
||||||
|
var alien = aliens[i];
|
||||||
|
alien.rotation += 0.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.render(stage);
|
||||||
|
requestAnimFrame(update);
|
||||||
|
stats.end();
|
||||||
|
}
|
84
examples/alien benchmark/js/pixi.min.js
vendored
Normal file
84
examples/alien benchmark/js/pixi.min.js
vendored
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(c){window.setTimeout(c,1E3/60)}}();var AjaxRequest=function(){var c=["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];if(window.ActiveXObject)for(var d=0;d<c.length;d++)try{return new ActiveXObject(c[d])}catch(f){}else return window.XMLHttpRequest?new XMLHttpRequest:!1};var PIXI=PIXI||{};PIXI.EventTarget=function(){var c={};this.addEventListener=function(d,f){void 0===c[d]&&(c[d]=[]);-1===c[d].indexOf(f)&&c[d].push(f)};this.dispatchEvent=function(d){for(var f in c[d.type])c[d.type][f](d)};this.removeEventListener=function(d,f){var g=c[d].indexOf(f);-1!==g&&c[d].splice(g,1)}};(function(c,d){"object"===typeof exports?module.exports=d(global):"function"===typeof define&&define.amd?define([],function(){return d(c)}):d(c)})(this,function(c){function d(a){return l=a}function f(){return l="undefined"!==typeof Float32Array?Float32Array:Array}var g={};if("undefined"!=typeof Float32Array){var m=new Float32Array(1),p=new Int32Array(m.buffer);g.invsqrt=function(a){m[0]=a;p[0]=1597463007-(p[0]>>1);var b=m[0];return b*(1.5-0.5*a*b*b)}}else g.invsqrt=function(a){return 1/Math.sqrt(a)};
|
||||||
|
var l=null;f();var j={create:function(a){var b=new l(3);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2]):b[0]=b[1]=b[2]=0;return b},createFrom:function(a,b,e){var c=new l(3);c[0]=a;c[1]=b;c[2]=e;return c},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])},add:function(a,b,e){if(!e||a===e)return a[0]+=b[0],a[1]+=b[1],a[2]+=b[2],a;e[0]=a[0]+b[0];e[1]=a[1]+b[1];e[2]=a[2]+b[2];return e},subtract:function(a,
|
||||||
|
b,e){if(!e||a===e)return a[0]-=b[0],a[1]-=b[1],a[2]-=b[2],a;e[0]=a[0]-b[0];e[1]=a[1]-b[1];e[2]=a[2]-b[2];return e},multiply:function(a,b,e){if(!e||a===e)return a[0]*=b[0],a[1]*=b[1],a[2]*=b[2],a;e[0]=a[0]*b[0];e[1]=a[1]*b[1];e[2]=a[2]*b[2];return e},negate:function(a,b){b||(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];return b},scale:function(a,b,e){if(!e||a===e)return a[0]*=b,a[1]*=b,a[2]*=b,a;e[0]=a[0]*b;e[1]=a[1]*b;e[2]=a[2]*b;return e},normalize:function(a,b){b||(b=a);var e=a[0],c=a[1],d=a[2],k=Math.sqrt(e*
|
||||||
|
e+c*c+d*d);if(!k)return b[0]=0,b[1]=0,b[2]=0,b;if(1===k)return b[0]=e,b[1]=c,b[2]=d,b;k=1/k;b[0]=e*k;b[1]=c*k;b[2]=d*k;return b},cross:function(a,b,e){e||(e=a);var c=a[0],d=a[1];a=a[2];var k=b[0],h=b[1];b=b[2];e[0]=d*b-a*h;e[1]=a*k-c*b;e[2]=c*h-d*k;return e},length:function(a){var b=a[0],e=a[1];a=a[2];return Math.sqrt(b*b+e*e+a*a)},squaredLength:function(a){var b=a[0],e=a[1];a=a[2];return b*b+e*e+a*a},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},direction:function(a,b,e){e||(e=a);var c=
|
||||||
|
a[0]-b[0],d=a[1]-b[1];a=a[2]-b[2];b=Math.sqrt(c*c+d*d+a*a);if(!b)return e[0]=0,e[1]=0,e[2]=0,e;b=1/b;e[0]=c*b;e[1]=d*b;e[2]=a*b;return e},lerp:function(a,b,e,c){c||(c=a);c[0]=a[0]+e*(b[0]-a[0]);c[1]=a[1]+e*(b[1]-a[1]);c[2]=a[2]+e*(b[2]-a[2]);return c},dist:function(a,b){var e=b[0]-a[0],c=b[1]-a[1],d=b[2]-a[2];return Math.sqrt(e*e+c*c+d*d)}},x=null,n=new l(4);j.unproject=function(a,b,e,c,d){d||(d=a);x||(x=y.create());var k=x;n[0]=2*(a[0]-c[0])/c[2]-1;n[1]=2*(a[1]-c[1])/c[3]-1;n[2]=2*a[2]-1;n[3]=1;
|
||||||
|
y.multiply(e,b,k);if(!y.inverse(k))return null;y.multiplyVec4(k,n);if(0===n[3])return null;d[0]=n[0]/n[3];d[1]=n[1]/n[3];d[2]=n[2]/n[3];return d};var z=j.createFrom(1,0,0),A=j.createFrom(0,1,0),H=j.createFrom(0,0,1),C=j.create();j.rotationTo=function(a,b,e){e||(e=s.create());var c=j.dot(a,b);if(1<=c)s.set(O,e);else if(-0.999999>c)j.cross(z,a,C),1E-6>j.length(C)&&j.cross(A,a,C),1E-6>j.length(C)&&j.cross(H,a,C),j.normalize(C),s.fromAngleAxis(Math.PI,C,e);else{var c=Math.sqrt(2*(1+c)),d=1/c;j.cross(a,
|
||||||
|
b,C);e[0]=C[0]*d;e[1]=C[1]*d;e[2]=C[2]*d;e[3]=0.5*c;s.normalize(e)}1<e[3]?e[3]=1:-1>e[3]&&(e[3]=-1);return e};j.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+"]"};var F={create:function(a){var b=new l(9);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8]):b[0]=b[1]=b[2]=b[3]=b[4]=b[5]=b[6]=b[7]=b[8]=0;return b},createFrom:function(a,b,e,c,d,k,h,E,K){var q=new l(9);q[0]=a;q[1]=b;q[2]=e;q[3]=c;q[4]=d;q[5]=k;q[6]=h;q[7]=E;q[8]=K;return q},determinant:function(a){var b=
|
||||||
|
a[3],e=a[4],c=a[5],d=a[6],k=a[7],h=a[8];return a[0]*(h*e-c*k)+a[1]*(-h*b+c*d)+a[2]*(k*b-e*d)},inverse:function(a,b){var e=a[0],c=a[1],d=a[2],k=a[3],h=a[4],E=a[5],K=a[6],q=a[7],f=a[8],g=f*h-E*q,j=-f*k+E*K,J=q*k-h*K,r=e*g+c*j+d*J;if(!r)return null;r=1/r;b||(b=F.create());b[0]=g*r;b[1]=(-f*c+d*q)*r;b[2]=(E*c-d*h)*r;b[3]=j*r;b[4]=(f*e-d*K)*r;b[5]=(-E*e+d*k)*r;b[6]=J*r;b[7]=(-q*e+c*K)*r;b[8]=(h*e-c*k)*r;return b},multiply:function(a,b,e){e||(e=a);var c=a[0],d=a[1],k=a[2],h=a[3],E=a[4],f=a[5],q=a[6],g=
|
||||||
|
a[7];a=a[8];var u=b[0],j=b[1],J=b[2],r=b[3],l=b[4],t=b[5],m=b[6],p=b[7];b=b[8];e[0]=u*c+j*h+J*q;e[1]=u*d+j*E+J*g;e[2]=u*k+j*f+J*a;e[3]=r*c+l*h+t*q;e[4]=r*d+l*E+t*g;e[5]=r*k+l*f+t*a;e[6]=m*c+p*h+b*q;e[7]=m*d+p*E+b*g;e[8]=m*k+p*f+b*a;return e},multiplyVec2:function(a,b,e){e||(e=b);var c=b[0];b=b[1];e[0]=c*a[0]+b*a[3]+a[6];e[1]=c*a[1]+b*a[4]+a[7];return e},multiplyVec3:function(a,b,e){e||(e=b);var c=b[0],d=b[1];b=b[2];e[0]=c*a[0]+d*a[3]+b*a[6];e[1]=c*a[1]+d*a[4]+b*a[7];e[2]=c*a[2]+d*a[5]+b*a[8];return e},
|
||||||
|
set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])&&1E-6>Math.abs(a[4]-b[4])&&1E-6>Math.abs(a[5]-b[5])&&1E-6>Math.abs(a[6]-b[6])&&1E-6>Math.abs(a[7]-b[7])&&1E-6>Math.abs(a[8]-b[8])},identity:function(a){a||(a=F.create());a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=1;a[5]=0;a[6]=0;a[7]=0;a[8]=1;return a},transpose:function(a,
|
||||||
|
b){if(!b||a===b){var e=a[1],c=a[2],d=a[5];a[1]=a[3];a[2]=a[6];a[3]=e;a[5]=a[7];a[6]=c;a[7]=d;return a}b[0]=a[0];b[1]=a[3];b[2]=a[6];b[3]=a[1];b[4]=a[4];b[5]=a[7];b[6]=a[2];b[7]=a[5];b[8]=a[8];return b},toMat4:function(a,b){b||(b=y.create());b[15]=1;b[14]=0;b[13]=0;b[12]=0;b[11]=0;b[10]=a[8];b[9]=a[7];b[8]=a[6];b[7]=0;b[6]=a[5];b[5]=a[4];b[4]=a[3];b[3]=0;b[2]=a[2];b[1]=a[1];b[0]=a[0];return b},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+
|
||||||
|
a[8]+"]"}},y={create:function(a){var b=new l(16);a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]);return b},createFrom:function(a,b,e,c,d,k,h,E,f,q,g,u,j,J,r,m){var t=new l(16);t[0]=a;t[1]=b;t[2]=e;t[3]=c;t[4]=d;t[5]=k;t[6]=h;t[7]=E;t[8]=f;t[9]=q;t[10]=g;t[11]=u;t[12]=j;t[13]=J;t[14]=r;t[15]=m;return t},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];
|
||||||
|
b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];b[13]=a[13];b[14]=a[14];b[15]=a[15];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])&&1E-6>Math.abs(a[4]-b[4])&&1E-6>Math.abs(a[5]-b[5])&&1E-6>Math.abs(a[6]-b[6])&&1E-6>Math.abs(a[7]-b[7])&&1E-6>Math.abs(a[8]-b[8])&&1E-6>Math.abs(a[9]-b[9])&&1E-6>Math.abs(a[10]-b[10])&&1E-6>Math.abs(a[11]-b[11])&&1E-6>Math.abs(a[12]-
|
||||||
|
b[12])&&1E-6>Math.abs(a[13]-b[13])&&1E-6>Math.abs(a[14]-b[14])&&1E-6>Math.abs(a[15]-b[15])},identity:function(a){a||(a=y.create());a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a},transpose:function(a,b){if(!b||a===b){var e=a[1],c=a[2],d=a[3],k=a[6],h=a[7],E=a[11];a[1]=a[4];a[2]=a[8];a[3]=a[12];a[4]=e;a[6]=a[9];a[7]=a[13];a[8]=c;a[9]=k;a[11]=a[14];a[12]=d;a[13]=h;a[14]=E;return a}b[0]=a[0];b[1]=a[4];b[2]=a[8];b[3]=a[12];
|
||||||
|
b[4]=a[1];b[5]=a[5];b[6]=a[9];b[7]=a[13];b[8]=a[2];b[9]=a[6];b[10]=a[10];b[11]=a[14];b[12]=a[3];b[13]=a[7];b[14]=a[11];b[15]=a[15];return b},determinant:function(a){var b=a[0],e=a[1],c=a[2],d=a[3],k=a[4],h=a[5],E=a[6],f=a[7],g=a[8],I=a[9],u=a[10],j=a[11],l=a[12],r=a[13],m=a[14];a=a[15];return l*I*E*d-g*r*E*d-l*h*u*d+k*r*u*d+g*h*m*d-k*I*m*d-l*I*c*f+g*r*c*f+l*e*u*f-b*r*u*f-g*e*m*f+b*I*m*f+l*h*c*j-k*r*c*j-l*e*E*j+b*r*E*j+k*e*m*j-b*h*m*j-g*h*c*a+k*I*c*a+g*e*E*a-b*I*E*a-k*e*u*a+b*h*u*a},inverse:function(a,
|
||||||
|
b){b||(b=a);var e=a[0],c=a[1],d=a[2],k=a[3],h=a[4],f=a[5],g=a[6],q=a[7],I=a[8],u=a[9],j=a[10],l=a[11],r=a[12],m=a[13],t=a[14],p=a[15],s=e*f-c*h,n=e*g-d*h,v=e*q-k*h,w=c*g-d*f,x=c*q-k*f,y=d*q-k*g,z=I*m-u*r,A=I*t-j*r,C=I*p-l*r,D=u*t-j*m,F=u*p-l*m,H=j*p-l*t,G=s*H-n*F+v*D+w*C-x*A+y*z;if(!G)return null;G=1/G;b[0]=(f*H-g*F+q*D)*G;b[1]=(-c*H+d*F-k*D)*G;b[2]=(m*y-t*x+p*w)*G;b[3]=(-u*y+j*x-l*w)*G;b[4]=(-h*H+g*C-q*A)*G;b[5]=(e*H-d*C+k*A)*G;b[6]=(-r*y+t*v-p*n)*G;b[7]=(I*y-j*v+l*n)*G;b[8]=(h*F-f*C+q*z)*G;b[9]=
|
||||||
|
(-e*F+c*C-k*z)*G;b[10]=(r*x-m*v+p*s)*G;b[11]=(-I*x+u*v-l*s)*G;b[12]=(-h*D+f*A-g*z)*G;b[13]=(e*D-c*A+d*z)*G;b[14]=(-r*w+m*n-t*s)*G;b[15]=(I*w-u*n+j*s)*G;return b},toRotationMat:function(a,b){b||(b=y.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b},toMat3:function(a,b){b||(b=F.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[4];b[4]=a[5];b[5]=a[6];b[6]=a[8];b[7]=a[9];b[8]=a[10];
|
||||||
|
return b},toInverseMat3:function(a,b){var e=a[0],c=a[1],d=a[2],k=a[4],h=a[5],f=a[6],g=a[8],q=a[9],j=a[10],u=j*h-f*q,l=-j*k+f*g,m=q*k-h*g,r=e*u+c*l+d*m;if(!r)return null;r=1/r;b||(b=F.create());b[0]=u*r;b[1]=(-j*c+d*q)*r;b[2]=(f*c-d*h)*r;b[3]=l*r;b[4]=(j*e-d*g)*r;b[5]=(-f*e+d*k)*r;b[6]=m*r;b[7]=(-q*e+c*g)*r;b[8]=(h*e-c*k)*r;return b},multiply:function(a,b,e){e||(e=a);var c=a[0],d=a[1],k=a[2],h=a[3],f=a[4],g=a[5],q=a[6],j=a[7],u=a[8],l=a[9],m=a[10],r=a[11],p=a[12],t=a[13],s=a[14];a=a[15];var n=b[0],
|
||||||
|
B=b[1],v=b[2],w=b[3];e[0]=n*c+B*f+v*u+w*p;e[1]=n*d+B*g+v*l+w*t;e[2]=n*k+B*q+v*m+w*s;e[3]=n*h+B*j+v*r+w*a;n=b[4];B=b[5];v=b[6];w=b[7];e[4]=n*c+B*f+v*u+w*p;e[5]=n*d+B*g+v*l+w*t;e[6]=n*k+B*q+v*m+w*s;e[7]=n*h+B*j+v*r+w*a;n=b[8];B=b[9];v=b[10];w=b[11];e[8]=n*c+B*f+v*u+w*p;e[9]=n*d+B*g+v*l+w*t;e[10]=n*k+B*q+v*m+w*s;e[11]=n*h+B*j+v*r+w*a;n=b[12];B=b[13];v=b[14];w=b[15];e[12]=n*c+B*f+v*u+w*p;e[13]=n*d+B*g+v*l+w*t;e[14]=n*k+B*q+v*m+w*s;e[15]=n*h+B*j+v*r+w*a;return e},multiplyVec3:function(a,b,e){e||(e=b);
|
||||||
|
var c=b[0],d=b[1];b=b[2];e[0]=a[0]*c+a[4]*d+a[8]*b+a[12];e[1]=a[1]*c+a[5]*d+a[9]*b+a[13];e[2]=a[2]*c+a[6]*d+a[10]*b+a[14];return e},multiplyVec4:function(a,b,e){e||(e=b);var c=b[0],d=b[1],k=b[2];b=b[3];e[0]=a[0]*c+a[4]*d+a[8]*k+a[12]*b;e[1]=a[1]*c+a[5]*d+a[9]*k+a[13]*b;e[2]=a[2]*c+a[6]*d+a[10]*k+a[14]*b;e[3]=a[3]*c+a[7]*d+a[11]*k+a[15]*b;return e},translate:function(a,b,e){var c=b[0],d=b[1];b=b[2];var k,h,f,g,q,j,u,l,m,n,p,s;if(!e||a===e)return a[12]=a[0]*c+a[4]*d+a[8]*b+a[12],a[13]=a[1]*c+a[5]*d+
|
||||||
|
a[9]*b+a[13],a[14]=a[2]*c+a[6]*d+a[10]*b+a[14],a[15]=a[3]*c+a[7]*d+a[11]*b+a[15],a;k=a[0];h=a[1];f=a[2];g=a[3];q=a[4];j=a[5];u=a[6];l=a[7];m=a[8];n=a[9];p=a[10];s=a[11];e[0]=k;e[1]=h;e[2]=f;e[3]=g;e[4]=q;e[5]=j;e[6]=u;e[7]=l;e[8]=m;e[9]=n;e[10]=p;e[11]=s;e[12]=k*c+q*d+m*b+a[12];e[13]=h*c+j*d+n*b+a[13];e[14]=f*c+u*d+p*b+a[14];e[15]=g*c+l*d+s*b+a[15];return e},scale:function(a,b,e){var c=b[0],d=b[1];b=b[2];if(!e||a===e)return a[0]*=c,a[1]*=c,a[2]*=c,a[3]*=c,a[4]*=d,a[5]*=d,a[6]*=d,a[7]*=d,a[8]*=b,a[9]*=
|
||||||
|
b,a[10]*=b,a[11]*=b,a;e[0]=a[0]*c;e[1]=a[1]*c;e[2]=a[2]*c;e[3]=a[3]*c;e[4]=a[4]*d;e[5]=a[5]*d;e[6]=a[6]*d;e[7]=a[7]*d;e[8]=a[8]*b;e[9]=a[9]*b;e[10]=a[10]*b;e[11]=a[11]*b;e[12]=a[12];e[13]=a[13];e[14]=a[14];e[15]=a[15];return e},rotate:function(a,b,e,c){var d=e[0],k=e[1];e=e[2];var h=Math.sqrt(d*d+k*k+e*e),f,g,q,j,l,m,n,r,p,s,x,y,B,v,w,z,A,C,D,F;if(!h)return null;1!==h&&(h=1/h,d*=h,k*=h,e*=h);f=Math.sin(b);g=Math.cos(b);q=1-g;b=a[0];h=a[1];j=a[2];l=a[3];m=a[4];n=a[5];r=a[6];p=a[7];s=a[8];x=a[9];y=
|
||||||
|
a[10];B=a[11];v=d*d*q+g;w=k*d*q+e*f;z=e*d*q-k*f;A=d*k*q-e*f;C=k*k*q+g;D=e*k*q+d*f;F=d*e*q+k*f;d=k*e*q-d*f;k=e*e*q+g;c?a!==c&&(c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a;c[0]=b*v+m*w+s*z;c[1]=h*v+n*w+x*z;c[2]=j*v+r*w+y*z;c[3]=l*v+p*w+B*z;c[4]=b*A+m*C+s*D;c[5]=h*A+n*C+x*D;c[6]=j*A+r*C+y*D;c[7]=l*A+p*C+B*D;c[8]=b*F+m*d+s*k;c[9]=h*F+n*d+x*k;c[10]=j*F+r*d+y*k;c[11]=l*F+p*d+B*k;return c},rotateX:function(a,b,e){var c=Math.sin(b);b=Math.cos(b);var d=a[4],k=a[5],h=a[6],f=a[7],g=a[8],q=a[9],j=a[10],
|
||||||
|
l=a[11];e?a!==e&&(e[0]=a[0],e[1]=a[1],e[2]=a[2],e[3]=a[3],e[12]=a[12],e[13]=a[13],e[14]=a[14],e[15]=a[15]):e=a;e[4]=d*b+g*c;e[5]=k*b+q*c;e[6]=h*b+j*c;e[7]=f*b+l*c;e[8]=d*-c+g*b;e[9]=k*-c+q*b;e[10]=h*-c+j*b;e[11]=f*-c+l*b;return e},rotateY:function(a,b,e){var c=Math.sin(b);b=Math.cos(b);var d=a[0],k=a[1],h=a[2],f=a[3],g=a[8],j=a[9],l=a[10],m=a[11];e?a!==e&&(e[4]=a[4],e[5]=a[5],e[6]=a[6],e[7]=a[7],e[12]=a[12],e[13]=a[13],e[14]=a[14],e[15]=a[15]):e=a;e[0]=d*b+g*-c;e[1]=k*b+j*-c;e[2]=h*b+l*-c;e[3]=f*
|
||||||
|
b+m*-c;e[8]=d*c+g*b;e[9]=k*c+j*b;e[10]=h*c+l*b;e[11]=f*c+m*b;return e},rotateZ:function(a,b,e){var c=Math.sin(b);b=Math.cos(b);var d=a[0],k=a[1],h=a[2],f=a[3],g=a[4],j=a[5],l=a[6],m=a[7];e?a!==e&&(e[8]=a[8],e[9]=a[9],e[10]=a[10],e[11]=a[11],e[12]=a[12],e[13]=a[13],e[14]=a[14],e[15]=a[15]):e=a;e[0]=d*b+g*c;e[1]=k*b+j*c;e[2]=h*b+l*c;e[3]=f*b+m*c;e[4]=d*-c+g*b;e[5]=k*-c+j*b;e[6]=h*-c+l*b;e[7]=f*-c+m*b;return e},frustum:function(a,b,e,c,d,k,h){h||(h=y.create());var f=b-a,g=c-e,j=k-d;h[0]=2*d/f;h[1]=0;
|
||||||
|
h[2]=0;h[3]=0;h[4]=0;h[5]=2*d/g;h[6]=0;h[7]=0;h[8]=(b+a)/f;h[9]=(c+e)/g;h[10]=-(k+d)/j;h[11]=-1;h[12]=0;h[13]=0;h[14]=-(2*k*d)/j;h[15]=0;return h},perspective:function(a,b,e,c,d){a=e*Math.tan(a*Math.PI/360);b*=a;return y.frustum(-b,b,-a,a,e,c,d)},ortho:function(a,b,e,c,d,k,h){h||(h=y.create());var f=b-a,g=c-e,j=k-d;h[0]=2/f;h[1]=0;h[2]=0;h[3]=0;h[4]=0;h[5]=2/g;h[6]=0;h[7]=0;h[8]=0;h[9]=0;h[10]=-2/j;h[11]=0;h[12]=-(a+b)/f;h[13]=-(c+e)/g;h[14]=-(k+d)/j;h[15]=1;return h},lookAt:function(a,b,e,c){c||
|
||||||
|
(c=y.create());var d,k,h,f,g,j,l,m,n=a[0],p=a[1];a=a[2];h=e[0];f=e[1];k=e[2];l=b[0];e=b[1];d=b[2];if(n===l&&p===e&&a===d)return y.identity(c);b=n-l;e=p-e;l=a-d;m=1/Math.sqrt(b*b+e*e+l*l);b*=m;e*=m;l*=m;d=f*l-k*e;k=k*b-h*l;h=h*e-f*b;(m=Math.sqrt(d*d+k*k+h*h))?(m=1/m,d*=m,k*=m,h*=m):h=k=d=0;f=e*h-l*k;g=l*d-b*h;j=b*k-e*d;(m=Math.sqrt(f*f+g*g+j*j))?(m=1/m,f*=m,g*=m,j*=m):j=g=f=0;c[0]=d;c[1]=f;c[2]=b;c[3]=0;c[4]=k;c[5]=g;c[6]=e;c[7]=0;c[8]=h;c[9]=j;c[10]=l;c[11]=0;c[12]=-(d*n+k*p+h*a);c[13]=-(f*n+g*p+
|
||||||
|
j*a);c[14]=-(b*n+e*p+l*a);c[15]=1;return c},fromRotationTranslation:function(a,b,e){e||(e=y.create());var c=a[0],d=a[1],k=a[2],h=a[3],f=c+c,g=d+d,j=k+k;a=c*f;var l=c*g,c=c*j,m=d*g,d=d*j,k=k*j,f=h*f,g=h*g,h=h*j;e[0]=1-(m+k);e[1]=l+h;e[2]=c-g;e[3]=0;e[4]=l-h;e[5]=1-(a+k);e[6]=d+f;e[7]=0;e[8]=c+g;e[9]=d-f;e[10]=1-(a+m);e[11]=0;e[12]=b[0];e[13]=b[1];e[14]=b[2];e[15]=1;return e},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+
|
||||||
|
a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+"]"}},s={create:function(a){var b=new l(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):b[0]=b[1]=b[2]=b[3]=0;return b},createFrom:function(a,b,e,c){var d=new l(4);d[0]=a;d[1]=b;d[2]=e;d[3]=c;return d},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])},identity:function(a){a||(a=s.create());
|
||||||
|
a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a}},O=s.identity();s.calculateW=function(a,b){var e=a[0],c=a[1],d=a[2];if(!b||a===b)return a[3]=-Math.sqrt(Math.abs(1-e*e-c*c-d*d)),a;b[0]=e;b[1]=c;b[2]=d;b[3]=-Math.sqrt(Math.abs(1-e*e-c*c-d*d));return b};s.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]};s.inverse=function(a,b){var e=a[0],c=a[1],d=a[2],f=a[3],e=(e=e*e+c*c+d*d+f*f)?1/e:0;if(!b||a===b)return a[0]*=-e,a[1]*=-e,a[2]*=-e,a[3]*=e,a;b[0]=-a[0]*e;b[1]=-a[1]*e;b[2]=-a[2]*e;b[3]=a[3]*e;
|
||||||
|
return b};s.conjugate=function(a,b){if(!b||a===b)return a[0]*=-1,a[1]*=-1,a[2]*=-1,a;b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=a[3];return b};s.length=function(a){var b=a[0],e=a[1],c=a[2];a=a[3];return Math.sqrt(b*b+e*e+c*c+a*a)};s.normalize=function(a,b){b||(b=a);var e=a[0],c=a[1],d=a[2],f=a[3],h=Math.sqrt(e*e+c*c+d*d+f*f);if(0===h)return b[0]=0,b[1]=0,b[2]=0,b[3]=0,b;h=1/h;b[0]=e*h;b[1]=c*h;b[2]=d*h;b[3]=f*h;return b};s.add=function(a,b,e){if(!e||a===e)return a[0]+=b[0],a[1]+=b[1],a[2]+=b[2],a[3]+=
|
||||||
|
b[3],a;e[0]=a[0]+b[0];e[1]=a[1]+b[1];e[2]=a[2]+b[2];e[3]=a[3]+b[3];return e};s.multiply=function(a,b,e){e||(e=a);var c=a[0],d=a[1],f=a[2];a=a[3];var h=b[0],g=b[1],j=b[2];b=b[3];e[0]=c*b+a*h+d*j-f*g;e[1]=d*b+a*g+f*h-c*j;e[2]=f*b+a*j+c*g-d*h;e[3]=a*b-c*h-d*g-f*j;return e};s.multiplyVec3=function(a,b,e){e||(e=b);var c=b[0],d=b[1],f=b[2];b=a[0];var h=a[1],g=a[2];a=a[3];var j=a*c+h*f-g*d,l=a*d+g*c-b*f,m=a*f+b*d-h*c,c=-b*c-h*d-g*f;e[0]=j*a+c*-b+l*-g-m*-h;e[1]=l*a+c*-h+m*-b-j*-g;e[2]=m*a+c*-g+j*-h-l*-b;
|
||||||
|
return e};s.scale=function(a,b,e){if(!e||a===e)return a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b,a;e[0]=a[0]*b;e[1]=a[1]*b;e[2]=a[2]*b;e[3]=a[3]*b;return e};s.toMat3=function(a,b){b||(b=F.create());var e=a[0],c=a[1],d=a[2],f=a[3],h=e+e,g=c+c,j=d+d,l=e*h,m=e*g,e=e*j,n=c*g,c=c*j,d=d*j,h=f*h,g=f*g,f=f*j;b[0]=1-(n+d);b[1]=m+f;b[2]=e-g;b[3]=m-f;b[4]=1-(l+d);b[5]=c+h;b[6]=e+g;b[7]=c-h;b[8]=1-(l+n);return b};s.toMat4=function(a,b){b||(b=y.create());var e=a[0],c=a[1],d=a[2],f=a[3],g=e+e,j=c+c,l=d+d,m=e*g,n=e*j,e=e*
|
||||||
|
l,p=c*j,c=c*l,d=d*l,g=f*g,j=f*j,f=f*l;b[0]=1-(p+d);b[1]=n+f;b[2]=e-j;b[3]=0;b[4]=n-f;b[5]=1-(m+d);b[6]=c+g;b[7]=0;b[8]=e+j;b[9]=c-g;b[10]=1-(m+p);b[11]=0;b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};s.slerp=function(a,b,c,d){d||(d=a);var f=a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3],g,h;if(1<=Math.abs(f))return d!==a&&(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[3]),d;g=Math.acos(f);h=Math.sqrt(1-f*f);if(0.001>Math.abs(h))return d[0]=0.5*a[0]+0.5*b[0],d[1]=0.5*a[1]+0.5*b[1],d[2]=0.5*a[2]+0.5*b[2],d[3]=0.5*a[3]+
|
||||||
|
0.5*b[3],d;f=Math.sin((1-c)*g)/h;c=Math.sin(c*g)/h;d[0]=a[0]*f+b[0]*c;d[1]=a[1]*f+b[1]*c;d[2]=a[2]*f+b[2]*c;d[3]=a[3]*f+b[3]*c;return d};s.fromRotationMatrix=function(a,b){b||(b=s.create());var c=a[0]+a[4]+a[8],d;if(0<c)d=Math.sqrt(c+1),b[3]=0.5*d,d=0.5/d,b[0]=(a[7]-a[5])*d,b[1]=(a[2]-a[6])*d,b[2]=(a[3]-a[1])*d;else{d=s.fromRotationMatrix.s_iNext=s.fromRotationMatrix.s_iNext||[1,2,0];c=0;a[4]>a[0]&&(c=1);a[8]>a[3*c+c]&&(c=2);var f=d[c],g=d[f];d=Math.sqrt(a[3*c+c]-a[3*f+f]-a[3*g+g]+1);b[c]=0.5*d;d=
|
||||||
|
0.5/d;b[3]=(a[3*g+f]-a[3*f+g])*d;b[f]=(a[3*f+c]+a[3*c+f])*d;b[g]=(a[3*g+c]+a[3*c+g])*d}return b};F.toQuat4=s.fromRotationMatrix;var D=F.create();s.fromAxes=function(a,b,c,d){D[0]=b[0];D[3]=b[1];D[6]=b[2];D[1]=c[0];D[4]=c[1];D[7]=c[2];D[2]=a[0];D[5]=a[1];D[8]=a[2];return s.fromRotationMatrix(D,d)};s.identity=function(a){a||(a=s.create());a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a};s.fromAngleAxis=function(a,b,c){c||(c=s.create());a*=0.5;var d=Math.sin(a);c[3]=Math.cos(a);c[0]=d*b[0];c[1]=d*b[1];c[2]=d*b[2];
|
||||||
|
return c};s.toAngleAxis=function(a,b){b||(b=a);var c=a[0]*a[0]+a[1]*a[1]+a[2]*a[2];0<c?(b[3]=2*Math.acos(a[3]),c=g.invsqrt(c),b[0]=a[0]*c,b[1]=a[1]*c,b[2]=a[2]*c):(b[3]=0,b[0]=1,b[1]=0,b[2]=0);return b};s.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"};var M={create:function(a){var b=new l(2);a?(b[0]=a[0],b[1]=a[1]):(b[0]=0,b[1]=0);return b},createFrom:function(a,b){var c=new l(2);c[0]=a;c[1]=b;return c},add:function(a,b,c){c||(c=b);c[0]=a[0]+b[0];c[1]=a[1]+b[1];return c},subtract:function(a,
|
||||||
|
b,c){c||(c=b);c[0]=a[0]-b[0];c[1]=a[1]-b[1];return c},multiply:function(a,b,c){c||(c=b);c[0]=a[0]*b[0];c[1]=a[1]*b[1];return c},divide:function(a,b,c){c||(c=b);c[0]=a[0]/b[0];c[1]=a[1]/b[1];return c},scale:function(a,b,c){c||(c=a);c[0]=a[0]*b;c[1]=a[1]*b;return c},dist:function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return Math.sqrt(c*c+d*d)},set:function(a,b){b[0]=a[0];b[1]=a[1];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])},negate:function(a,b){b||(b=a);
|
||||||
|
b[0]=-a[0];b[1]=-a[1];return b},normalize:function(a,b){b||(b=a);var c=a[0]*a[0]+a[1]*a[1];0<c?(c=Math.sqrt(c),b[0]=a[0]/c,b[1]=a[1]/c):b[0]=b[1]=0;return b},cross:function(a,b,c){a=a[0]*b[1]-a[1]*b[0];if(!c)return a;c[0]=c[1]=0;c[2]=a;return c},length:function(a){var b=a[0];a=a[1];return Math.sqrt(b*b+a*a)},squaredLength:function(a){var b=a[0];a=a[1];return b*b+a*a},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]},direction:function(a,b,c){c||(c=a);var d=a[0]-b[0];a=a[1]-b[1];b=d*d+a*a;if(!b)return c[0]=
|
||||||
|
0,c[1]=0,c[2]=0,c;b=1/Math.sqrt(b);c[0]=d*b;c[1]=a*b;return c},lerp:function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);return d},str:function(a){return"["+a[0]+", "+a[1]+"]"}},L={create:function(a){var b=new l(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):b[0]=b[1]=b[2]=b[3]=0;return b},createFrom:function(a,b,c,d){var f=new l(4);f[0]=a;f[1]=b;f[2]=c;f[3]=d;return f},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1E-6>
|
||||||
|
Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])},identity:function(a){a||(a=L.create());a[0]=1;a[1]=0;a[2]=0;a[3]=1;return a},transpose:function(a,b){if(!b||a===b){var c=a[1];a[1]=a[2];a[2]=c;return a}b[0]=a[0];b[1]=a[2];b[2]=a[1];b[3]=a[3];return b},determinant:function(a){return a[0]*a[3]-a[2]*a[1]},inverse:function(a,b){b||(b=a);var c=a[0],d=a[1],f=a[2],g=a[3],h=c*g-f*d;if(!h)return null;h=1/h;b[0]=g*h;b[1]=-d*h;b[2]=-f*h;b[3]=c*h;return b},multiply:function(a,
|
||||||
|
b,c){c||(c=a);var d=a[0],f=a[1],g=a[2];a=a[3];c[0]=d*b[0]+f*b[2];c[1]=d*b[1]+f*b[3];c[2]=g*b[0]+a*b[2];c[3]=g*b[1]+a*b[3];return c},rotate:function(a,b,c){c||(c=a);var d=a[0],f=a[1],g=a[2];a=a[3];var h=Math.sin(b);b=Math.cos(b);c[0]=d*b+f*h;c[1]=d*-h+f*b;c[2]=g*b+a*h;c[3]=g*-h+a*b;return c},multiplyVec2:function(a,b,c){c||(c=b);var d=b[0];b=b[1];c[0]=d*a[0]+b*a[1];c[1]=d*a[2]+b*a[3];return c},scale:function(a,b,c){c||(c=a);var d=a[1],f=a[2],g=a[3],h=b[0];b=b[1];c[0]=a[0]*h;c[1]=d*b;c[2]=f*h;c[3]=
|
||||||
|
g*b;return c},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"}},N={create:function(a){var b=new l(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):(b[0]=0,b[1]=0,b[2]=0,b[3]=0);return b},createFrom:function(a,b,c,d){var f=new l(4);f[0]=a;f[1]=b;f[2]=c;f[3]=d;return f},add:function(a,b,c){c||(c=b);c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];c[3]=a[3]+b[3];return c},subtract:function(a,b,c){c||(c=b);c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];c[3]=a[3]-b[3];return c},multiply:function(a,
|
||||||
|
b,c){c||(c=b);c[0]=a[0]*b[0];c[1]=a[1]*b[1];c[2]=a[2]*b[2];c[3]=a[3]*b[3];return c},divide:function(a,b,c){c||(c=b);c[0]=a[0]/b[0];c[1]=a[1]/b[1];c[2]=a[2]/b[2];c[3]=a[3]/b[3];return c},scale:function(a,b,c){c||(c=a);c[0]=a[0]*b;c[1]=a[1]*b;c[2]=a[2]*b;c[3]=a[3]*b;return c},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])},negate:function(a,b){b||
|
||||||
|
(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=-a[3];return b},length:function(a){var b=a[0],c=a[1],d=a[2];a=a[3];return Math.sqrt(b*b+c*c+d*d+a*a)},squaredLength:function(a){var b=a[0],c=a[1],d=a[2];a=a[3];return b*b+c*c+d*d+a*a},lerp:function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);d[2]=a[2]+c*(b[2]-a[2]);d[3]=a[3]+c*(b[3]-a[3]);return d},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"}};c&&(c.glMatrixArrayType=l,c.MatrixArray=l,c.setMatrixArrayType=d,c.determineMatrixArrayType=
|
||||||
|
f,c.glMath=g,c.vec2=M,c.vec3=j,c.vec4=N,c.mat2=L,c.mat3=F,c.mat4=y,c.quat4=s);return{glMatrixArrayType:l,MatrixArray:l,setMatrixArrayType:d,determineMatrixArrayType:f,glMath:g,vec2:M,vec3:j,vec4:N,mat2:L,mat3:F,mat4:y,quat4:s}});PIXI=PIXI||{};PIXI.shaderFragmentSrc=["precision mediump float;","varying vec2 vTextureCoord;","varying float vColor;","uniform sampler2D uSampler;","void main(void) {","gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));","gl_FragColor = gl_FragColor * vColor;","}"];
|
||||||
|
PIXI.shaderVertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform mat4 uMVMatrix;","varying vec2 vTextureCoord;","varying float vColor;","void main(void) {","gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);","vTextureCoord = aTextureCoord;","vColor = aColor;","}"];
|
||||||
|
PIXI.CompileVertexShader=function(c,d){for(var f="",g=0;g<d.length;g++)f+=d[g];g=c.createShader(c.VERTEX_SHADER);c.shaderSource(g,f);c.compileShader(g);return!c.getShaderParameter(g,c.COMPILE_STATUS)?(alert(c.getShaderInfoLog(g)),null):g};PIXI.CompileFragmentShader=function(c,d){for(var f="",g=0;g<d.length;g++)f+=d[g];g=c.createShader(c.FRAGMENT_SHADER);c.shaderSource(g,f);c.compileShader(g);return!c.getShaderParameter(g,c.COMPILE_STATUS)?(alert(c.getShaderInfoLog(g)),null):g};PIXI=PIXI||{};PIXI._defaultFrame={x:0,y:0,width:1,height:1};
|
||||||
|
PIXI.WebGLRenderer=function(c,d){this.width=c?c:800;this.height=d?d:600;this.view=document.createElement("canvas");this.view.width=this.width;this.view.height=this.height;this.view.background="#FF0000";var f=this;this.view.addEventListener("webglcontextlost",function(c){f.handleContextLost(c)},!1);this.view.addEventListener("webglcontextrestored",function(c){f.handleContextRestored(c)},!1);this.batchs=[];try{this.gl=this.view.getContext("experimental-webgl",{alpha:!1})}catch(g){alert("Web GL only im afraid :/")}this.initShaders();
|
||||||
|
var m=this.gl;this.batch=new PIXI.WebGLBatch(m);m.disable(m.DEPTH_TEST);m.enable(m.BLEND);m.colorMask(!0,!0,!0,!1);this.projectionMatrix=mat4.create();this.resize(this.width,this.height);this.contextLost=!1};PIXI.WebGLRenderer.constructor=PIXI.WebGLRenderer;
|
||||||
|
PIXI.WebGLRenderer.prototype.initShaders=function(){var c=this.gl,d=PIXI.CompileFragmentShader(c,PIXI.shaderFragmentSrc),f=PIXI.CompileVertexShader(c,PIXI.shaderVertexSrc),g=this.shaderProgram=c.createProgram();c.attachShader(g,f);c.attachShader(g,d);c.linkProgram(g);c.getProgramParameter(g,c.LINK_STATUS)||alert("Could not initialise shaders");c.useProgram(g);g.vertexPositionAttribute=c.getAttribLocation(g,"aVertexPosition");c.enableVertexAttribArray(g.vertexPositionAttribute);g.textureCoordAttribute=
|
||||||
|
c.getAttribLocation(g,"aTextureCoord");c.enableVertexAttribArray(g.textureCoordAttribute);g.colorAttribute=c.getAttribLocation(g,"aColor");c.enableVertexAttribArray(g.colorAttribute);g.mvMatrixUniform=c.getUniformLocation(g,"uMVMatrix");g.samplerUniform=c.getUniformLocation(g,"uSampler");PIXI.shaderProgram=this.shaderProgram};
|
||||||
|
PIXI.WebGLRenderer.prototype.render=function(c){if(!this.contextLost){for(var d=0;d<c.__childrenRemoved.length;d++)this.removeDisplayObject(c.__childrenRemoved[d]);for(d=0;d<c.__childrenAdded.length;d++)this.addDisplayObject(c.__childrenAdded[d]);for(d=0;d<PIXI.texturesToUpdate.length;d++)this.updateTexture(PIXI.texturesToUpdate[d]);c.__childrenRemoved=[];c.__childrenAdded=[];PIXI.texturesToUpdate=[];c.updateTransform();var f=this.gl;f.clear(f.COLOR_BUFFER_BIT);f.clearColor(1,1,1,1);f.blendFunc(f.ONE,
|
||||||
|
f.ONE_MINUS_SRC_ALPHA);f.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform,!1,this.projectionMatrix);if(this.refreshBatchs){for(d=0;d<this.batchs.length;d++)this.batchs[d].dirty&&PIXI._returnBatch(this.batchs[d]);this.batchs=[];this.currentBatch=PIXI._getBatch(f);this.collectBatchs(c);this.currentBatch&&(this.currentBatch.cache(),this.batchs.push(this.currentBatch));this.refreshBatchs=!1}this.updateDisplayObjects(c);for(d=0;d<this.batchs.length;d++)this.batchs[d].render()}};
|
||||||
|
PIXI.WebGLRenderer.prototype.updateDisplayObjects=function(c){for(var d,f,g,m,p,l,j,x,n,z,A,H;c;){if(!c.visible&&(c=c.parent[c.childIndex+1],!c))continue;c.sprite&&(d=c.batch.verticies,g=c.width,m=c.height,p=c.anchor.x,l=c.anchor.y,j=g*(1-p),g*=-p,p=m*(1-l),l=m*-l,m=8*c.index,f=c.worldTransform,x=f[0],n=f[3],z=f[1],A=f[4],H=f[2],f=f[5],d[m+0]=x*g+z*l+H,d[m+1]=A*l+n*g+f,d[m+2]=x*j+z*l+H,d[m+3]=A*l+n*j+f,d[m+4]=x*j+z*p+H,d[m+5]=A*p+n*j+f,d[m+6]=x*g+z*p+H,d[m+7]=A*p+n*g+f,c.updateFrame&&(c.batch.dirtyUVS=
|
||||||
|
!0,j=c.frame,g=c.texture.width,p=c.texture.height,d=c.batch.uvs,d[m+0]=j.x/g,d[m+1]=j.y/p,d[m+2]=(j.x+j.width)/g,d[m+3]=j.y/p,d[m+4]=(j.x+j.width)/g,d[m+5]=(j.y+j.height)/p,d[m+6]=j.x/g,d[m+7]=(j.y+j.height)/p,c.updateFrame=!1),c.cacheAlpha!=c.alpha&&(c.cacheAlpha=c.alpha,j=4*c.index,d=c.batch.colors,d[j]=d[j+1]=d[j+2]=d[j+3]=c.alpha,c.batch.dirtyColors=!0),c.cacheVisible!=c.visible&&(c.cacheVisible=c.visible,this.refreshBatchs=c.batch.dirty=!0));c=c._next}};
|
||||||
|
PIXI.WebGLRenderer.prototype.collectBatchs=function(c){for(var d=this.currentBatch,f=this.gl,g=d.uvs,m=d.colors,p=d.indicies,l,j,x;c;){if(!c.visible&&(c=c.parent[c.childIndex+1],!c)){this.currentBatch=null;break}if(c.sprite){if(d.texture!=c.texture){d.cache();this.batchs.push(d);for(d=!1;!d;){d=!0;if(!c){this.currentBatch=null;return}c.batch&&!c.batch.dirty&&(this.batchs.push(c.batch),c=c.batch.last._next,d=!1)}d=this.currentBatch=PIXI._getBatch(f);g=d.uvs;m=d.colors;p=d.indicies;d.texture=c.texture}c.index=
|
||||||
|
d.size;l=8*d.size;j=6*d.size;x=4*d.size;index4=4*d.size;var n=c.frame,z=c.texture.width,A=c.texture.height;n||(n=PIXI._defaultFrame);g[l+0]=n.x/z;g[l+1]=n.y/A;g[l+2]=(n.x+n.width)/z;g[l+3]=n.y/A;g[l+4]=(n.x+n.width)/z;g[l+5]=(n.y+n.height)/A;g[l+6]=n.x/z;g[l+7]=(n.y+n.height)/A;m[index4]=m[index4+1]=m[index4+2]=m[index4+3]=c.alpha;p[j+0]=x+0;p[j+1]=x+1;p[j+2]=x+2;p[j+3]=x+0;p[j+4]=x+2;p[j+5]=x+3;d.last=c;d.size++}c.batch=d;d.last=c;c=c._next}};
|
||||||
|
PIXI.WebGLRenderer.prototype.updateTexture=function(c){var d=this.gl;c._glTexture||(c._glTexture=d.createTexture());c.hasLoaded&&(d.bindTexture(d.TEXTURE_2D,c._glTexture),d.pixelStorei(d.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,d.RGBA,d.UNSIGNED_BYTE,c.image),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,
|
||||||
|
d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),d.generateMipmap(d.TEXTURE_2D),d.bindTexture(d.TEXTURE_2D,null));this.refreshBatchs=!0};
|
||||||
|
PIXI.WebGLRenderer.prototype.addDisplayObject=function(c){c.batch=null;c.cacheVisible=c.visible;var d;if(0==c.childIndex)d=c.parent;else for(d=c.parent.children[c.childIndex-1];0!=d.children.length;)d=d.children[d.children.length-1];var f=d._next;d._next=c;c._prev=d;f&&(c._next=f,f._prev=c);if(c.sprite){if((d=c._prev.batch)&&d.texture==c.texture)d.dirty=!0;if(c._next&&(c=c._next.batch)&&c.texture==c.texture)c.dirty=!0;this.refreshBatchs=!0}};
|
||||||
|
PIXI.WebGLRenderer.prototype.removeDisplayObject=function(c){var d=c.batch;d&&(d.dirty=!0);c._prev&&(c._prev._next=c._next);c._next&&(c._next._prev=c._prev);c.batch=null;this.refreshBatchs=!0};
|
||||||
|
PIXI.WebGLRenderer.prototype.resize=function(c,d){this.width=c;this.height=d;this.view.width=c;this.view.height=d;this.gl.viewport(0,0,this.width,this.height);mat4.identity(this.projectionMatrix);mat4.scale(this.projectionMatrix,[2/this.width,-2/this.height,1]);mat4.translate(this.projectionMatrix,[-this.width/2,-this.height/2,0])};PIXI.WebGLRenderer.prototype.handleContextLost=function(c){c.preventDefault();this.contextLost=!0};
|
||||||
|
PIXI.WebGLRenderer.prototype.handleContextRestored=function(){this.gl=this.view.getContext("experimental-webgl",{alpha:!0});this.initShaders();for(var c=0;c<PIXI.TextureCache.length;c++)this.updateTexture(PIXI.TextureCache[c]);for(c=0;c<this.batchs.length;c++)this.batchs[c].restoreLostContext(this.gl),this.batchs[c].dirty=!0;PIXI._restoreBatchs(this.gl);this.contextLost=!1};PIXI=PIXI||{};PIXI.CanvasRenderer=function(c,d){this.width=c?c:800;this.height=d?d:600;this.refresh=!0;this.view=document.createElement("canvas");this.view.width=this.width;this.view.height=this.height;this.view.background="#FF0000";this.context=this.view.getContext("2d")};PIXI.CanvasRenderer.constructor=PIXI.CanvasRenderer;
|
||||||
|
PIXI.CanvasRenderer.prototype.render=function(c){c.__childrenAdded=[];PIXI.texturesToUpdate=[];c.updateTransform();this.context.setTransform(1,0,0,1,0,0);this.context.clearRect(0,0,this.width,this.height);this.renderDisplayObject(c)};
|
||||||
|
PIXI.CanvasRenderer.prototype.renderDisplayObject=function(c){if(c.visible){if(c.sprite){var d=c.worldTransform,f=c.frame;f&&(this.context.globalAlpha=c.worldAlpha,this.context.setTransform(d[0],d[3],d[1],d[4],d[2],d[5]),this.context.drawImage(c.texture.image,f.x,f.y,f.width,f.height,c.anchor.x*-f.width,c.anchor.y*-f.height,f.width,f.height))}for(d=0;d<c.children.length;d++)this.renderDisplayObject(c.children[d])}};
|
||||||
|
PIXI.CanvasRenderer.prototype.resize=function(c,d){this.width=c;this.height=d;this.view.width=c;this.view.height=d};PIXI=PIXI||{};PIXI._defaultFrame={x:0,y:0,width:1,height:1};PIXI.DOMRenderer=function(c,d){this.width=c?c:800;this.height=d?d:600;this.view=document.createElement("div");this.view.style.width=this.width+"px";this.view.style.height=this.height+"px";this.view.style.background="#FF0000";this.view.style["-webkit-transform"]="translateZ(0)";this.resize(this.width,this.height)};PIXI.DOMRenderer.constructor=PIXI.DOMRenderer;
|
||||||
|
PIXI.DOMRenderer.prototype.render=function(c){for(var d=0;d<c.__childrenRemoved.length;d++)this.removeDisplayObject(c.__childrenRemoved[d]);for(d=0;d<c.__childrenAdded.length;d++)this.addDisplayObject(c.__childrenAdded[d]);for(d=0;d<PIXI.texturesToUpdate.length;d++)this.updateTexture(PIXI.texturesToUpdate[d]);c.__childrenRemoved=[];c.__childrenAdded=[];PIXI.texturesToUpdate=[];c.updateTransform();this.renderDisplayObject(c)};PIXI.DOMRenderer.prototype.updateTexture=function(){};
|
||||||
|
PIXI.DOMRenderer.prototype.renderDisplayObject=function(c){if(c.visible){if(c.sprite){var d=c.worldTransform;c.frame&&(c._div.style["-webkit-transform"]="matrix("+d[0]+", "+d[3]+","+d[1]+","+d[4]+","+d[2]+","+d[5]+")")}for(d=0;d<c.children.length;d++)this.renderDisplayObject(c.children[d])}};PIXI.DOMRenderer.prototype.addDisplayObject=function(c){if(c.sprite&&!c._div){var d=document.createElement("img");d.src=c.texture.imageUrl;d.style.cssText="position:absolute;";c._div=d;this.view.appendChild(d)}};
|
||||||
|
PIXI.DOMRenderer.prototype.removeDisplayObject=function(){};PIXI.DOMRenderer.prototype.resize=function(c,d){this.width=c;this.height=d;this.view.style.width=this.width+"px";this.view.style.height=this.height+"px"};PIXI=PIXI||{};PIXI.DisplayObject=function(){this.position={x:0,y:0};this.scale={x:1,y:1};this.rotation=0;this.dynamic=!0;this.alpha=1;this.color=[];this.worldAlpha=1;this.visible=!0;this.worldTransform=mat3.identity();this.localTransform=mat3.identity();this.parent;this.stage;this._sr=0;this._cr=1};PIXI.DisplayObject.constructor=Object.create(PIXI.DisplayObject.prototype);
|
||||||
|
PIXI.DisplayObject.prototype.updateTransform=function(){this.rotation!=this.rotationCache&&(this.rotationCach=this.rotation,this._sr=Math.sin(this.rotation),this._cr=Math.cos(this.rotation));this.localTransform[0]=this._cr*this.scale.x;this.localTransform[1]=-this._sr*this.scale.y;this.localTransform[3]=this._sr*this.scale.x;this.localTransform[4]=this._cr*this.scale.y;this.localTransform[2]=this.position.x;this.localTransform[5]=this.position.y;mat3.multiply(this.localTransform,this.parent.worldTransform,
|
||||||
|
this.worldTransform);this.worldAlpha=this.alpha*this.parent.worldAlpha};PIXI=PIXI||{};PIXI._batchs=[];PIXI._getBatch=function(c){return 0==PIXI._batchs.length?new PIXI.WebGLBatch(c):PIXI._batchs.pop()};PIXI._returnBatch=function(c){c.clean();PIXI._batchs.push(c)};PIXI._restoreBatchs=function(c){for(var d=0;d<PIXI._batchs.length;d++)PIXI._batchs[d].restoreLostContext(c)};
|
||||||
|
PIXI.WebGLBatch=function(c){this.gl=c;this.size=0;this.verticies=[];this.uvs=[];this.indicies=[];this.colors=[];this.texture;this.vertexBuffer=c.createBuffer();this.indexBuffer=c.createBuffer();this.uvBuffer=c.createBuffer();this.colorBuffer=c.createBuffer()};PIXI.WebGLBatch.constructor=PIXI.WebGLBatch;PIXI.WebGLBatch.prototype.clean=function(){this.verticies=[];this.uvs=[];this.indicies=[];this.colors=[];this.last=this.texture=null;this.size=0};
|
||||||
|
PIXI.WebGLBatch.prototype.restoreLostContext=function(c){this.gl=c;this.vertexBuffer=c.createBuffer();this.indexBuffer=c.createBuffer();this.uvBuffer=c.createBuffer();this.colorBuffer=c.createBuffer()};
|
||||||
|
PIXI.WebGLBatch.prototype.render=function(){if(0!=this.size){var c=this.gl,d=PIXI.shaderProgram;c.bindBuffer(c.ARRAY_BUFFER,this.vertexBuffer);c.bufferData(c.ARRAY_BUFFER,this.verticies,c.STATIC_DRAW);c.vertexAttribPointer(d.vertexPositionAttribute,2,c.FLOAT,!1,0,0);c.bindBuffer(c.ARRAY_BUFFER,this.uvBuffer);this.dirtyUVS&&(this.dirtyUVS=!1,c.bufferData(c.ARRAY_BUFFER,this.uvs,c.STATIC_DRAW));c.vertexAttribPointer(d.textureCoordAttribute,2,c.FLOAT,!1,0,0);c.activeTexture(c.TEXTURE0);c.bindTexture(c.TEXTURE_2D,
|
||||||
|
this.texture._glTexture);c.bindBuffer(c.ARRAY_BUFFER,this.colorBuffer);this.dirtyColors&&c.bufferData(c.ARRAY_BUFFER,this.colors,c.STATIC_DRAW);c.vertexAttribPointer(d.colorAttribute,1,c.FLOAT,!1,0,0);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,this.indexBuffer);c.drawElements(c.TRIANGLES,6*this.size,c.UNSIGNED_SHORT,0)}};
|
||||||
|
PIXI.WebGLBatch.prototype.cache=function(){var c=this.gl;c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,this.indexBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indicies),c.STATIC_DRAW);this.dirtyUVS=!0;this.uvs=new Float32Array(this.uvs);this.verticies=new Float32Array(8*this.size);this.colors=new Float32Array(this.colors)};PIXI=PIXI||{};PIXI.DisplayObjectContainer=function(){PIXI.DisplayObject.call(this);this.children=[]};PIXI.DisplayObjectContainer.constructor=PIXI.DisplayObjectContainer;PIXI.DisplayObjectContainer.protoype=Object.create(PIXI.DisplayObject.prototype);PIXI.DisplayObjectContainer.prototype.updateTransform=function(){PIXI.DisplayObject.prototype.updateTransform.call(this);for(var c=0,d=this.children.length;c<d;c++)this.children[c].updateTransform()};
|
||||||
|
PIXI.DisplayObjectContainer.prototype.addChild=function(c){void 0!=c.parent&&c.parent.removeChild(c);c.parent=this;c.childIndex=this.children.length;this.children.push(c);this.stage&&this.stage.__addChild(c)};PIXI.DisplayObjectContainer.prototype.removeChild=function(c){var d=this.children.indexOf(c);-1!==d&&(this.stage.__removeChild(c),c.parent=void 0,this.children.splice(d,1))};PIXI=PIXI||{};PIXI.Stage=function(){PIXI.DisplayObjectContainer.call(this);this.worldTransform=mat3.identity();this.__childrenAdded=[];this.__childrenRemoved=[];this.childIndex=0;this.stage=this};PIXI.Stage.constructor=PIXI.Stage;PIXI.Stage.prototype=Object.create(PIXI.DisplayObjectContainer.prototype);PIXI.Stage.prototype.updateTransform=function(){this.worldAlpha=1;for(var c=0,d=this.children.length;c<d;c++)this.children[c].updateTransform()};
|
||||||
|
PIXI.Stage.prototype.__addChild=function(c){this.__childrenAdded.push(c);c.stage=this;for(var d=0;d<c.children.length;d++)this.__addChild(c.children[d])};PIXI.Stage.prototype.__removeChild=function(c){this.__childrenRemoved.push(c);c.stage=void 0;for(var d=0,f=c.children.length;d<f;d++)this.__removeChild(c.children[d])};PIXI=PIXI||{};PIXI.Sprite=function(c,d){PIXI.DisplayObjectContainer.call(this);this.anchor={x:0,y:0};this.sprite=!0;this.texture=c;this.frame=d;this.height=this.width=1;c.hasLoaded&&(d||(d={x:0,y:0,width:c.width,height:c.height}),this.setFrame(d));var f=this;c.addEventListener("loaded",function(){f.frame||(f.frame={x:0,y:0,width:c.width,height:c.height});f.width=f.frame.width;f.height=f.frame.height;f.updateFrame=!0})};PIXI.Sprite.constructor=PIXI.Sprite;PIXI.Sprite.prototype=Object.create(PIXI.DisplayObjectContainer.prototype);
|
||||||
|
PIXI.Sprite.prototype.setFrame=function(c){this.frame=c;this.width=c.width;this.height=c.height;this.updateFrame=!0};PIXI.Sprite.spriteFromFrame=function(c){c=PIXI.FrameCache[c];return new PIXI.Sprite(PIXI.TextureCache[c.texture],{x:c.x,y:c.y,width:c.width,height:c.height})};PIXI.Sprite.spriteFromTexture=function(){return new PIXI.Sprite(PIXI.TextureCache[frameData.texture])};PIXI=PIXI||{};PIXI.MovieClip=function(c,d){PIXI.Sprite.call(this,c,d[0]);this.frames=d;this.framePosition=0;this.speed=1};PIXI.MovieClip.constructor=PIXI.MovieClip;PIXI.MovieClip.prototype=Object.create(PIXI.Sprite.prototype);PIXI.MovieClip.prototype.updateTransform=function(){PIXI.Sprite.prototype.updateTransform.call(this);this.framePosition+=this.speed;this.setFrame(this.frames[Math.round(this.framePosition)%this.frames.length])};PIXI=PIXI||{};PIXI.TextureCache={};PIXI.FrameCache={};PIXI.texturesToUpdate=[];PIXI.Texture=function(c){PIXI.EventTarget.call(this);this.imageUrl=c;this.frame={x:0,y:0,width:1,height:1};this.hasLoaded=!1;this.image=new Image;this.image.onload=$.proxy(this.onImageLoaded,this);this.image.src=c;this.height=this.width=100;PIXI.TextureCache[c]=this};
|
||||||
|
PIXI.Texture.prototype.onImageLoaded=function(){this.hasLoaded=!0;this.width=this.image.width;this.height=this.image.height;PIXI.texturesToUpdate.push(this);this.dispatchEvent({type:"loaded",content:this})};PIXI.Texture.getTexture=function(c){var d=PIXI.TextureCache[c];d||(d=new PIXI.Texture(c));return d};PIXI=PIXI||{};PIXI.autoDetectRenderer=function(c,d){var f;try{f=!!window.WebGLRenderingContext&&!!document.createElement("canvas").getContext("experimental-webgl")}catch(g){f=!1}console.log(f);return f?new PIXI.WebGLRenderer(c,d):new PIXI.CanvasRenderer(c,d)};PIXI=PIXI||{};PIXI.SpriteSheetLoader=function(c){PIXI.EventTarget.call(this);this.url=c;this.baseUrl=c.replace(/[^\/]*$/,"");this.texture;this.frames={}};PIXI.SpriteSheetLoader.constructor=PIXI.SpriteSheetLoader;PIXI.SpriteSheetLoader.prototype.load=function(){this.ajaxRequest=new AjaxRequest;var c=this;this.ajaxRequest.onreadystatechange=function(){c.onLoaded()};this.ajaxRequest.open("GET",this.url,!0);this.ajaxRequest.send(null)};
|
||||||
|
PIXI.SpriteSheetLoader.prototype.onLoaded=function(){if(4==this.ajaxRequest.readyState&&(200==this.ajaxRequest.status||-1==window.location.href.indexOf("http"))){var c=eval("("+this.ajaxRequest.responseText+")"),d=this.baseUrl+c.meta.image;this.texture=PIXI.TextureCache[d];this.texture||(this.texture=new PIXI.Texture(d));var c=c.frames,f;for(f in c){var g=c[f].frame;this.frames[f]={x:g.x,y:g.y,width:g.w,height:g.h,texture:d};PIXI.FrameCache[f]=this.frames[f]}this.dispatchEvent({type:"loaded",content:this})}};PIXI=PIXI||{};PIXI.AssetLoader=function(c){PIXI.EventTarget.call(this);this.assetURLs=c;this.assets=[]};PIXI.AssetLoader.constructor=PIXI.AssetLoader;
|
||||||
|
PIXI.AssetLoader.prototype.load=function(){this.loadCount=this.assetURLs.length;for(var c=["jpeg","jpg","png","gif"],d=["json"],f=0;f<this.assetURLs.length;f++){for(var g=this.assetURLs[f],m=g.split(".").pop().toLowerCase(),p,f=0;f<c.length;f++)if(m==c[f]){p="img";break}if(!p)for(f=0;f<d.length;f++)if(m==d[f]){p="atlas";break}if("img"==p)if(g=PIXI.Texture.getTexture(g),g.hasLoaded)this.loadCount--;else{var l=this;g.addEventListener("loaded",function(){l.onAssetLoaded()});this.assets.push(g)}else"atlas"==
|
||||||
|
p?(g=new PIXI.SpriteSheetLoader(g),this.assets.push(g),l=this,g.addEventListener("loaded",function(){l.onAssetLoaded()}),g.load()):this.loadCount--}};PIXI.AssetLoader.prototype.onAssetLoaded=function(){this.loadCount--;0==this.loadCount&&this.dispatchEvent({type:"loaded",content:this})};
|
6
examples/alien benchmark/js/stats.min.js
vendored
Normal file
6
examples/alien benchmark/js/stats.min.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// stats.js - http://github.com/mrdoob/stats.js
|
||||||
|
var Stats=function(){var l=Date.now(),m=l,g=0,n=Infinity,o=0,h=0,p=Infinity,q=0,r=0,s=0,f=document.createElement("div");f.id="stats";f.addEventListener("mousedown",function(b){b.preventDefault();t(++s%2)},!1);f.style.cssText="width:80px;opacity:0.9;cursor:pointer";var a=document.createElement("div");a.id="fps";a.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#002";f.appendChild(a);var i=document.createElement("div");i.id="fpsText";i.style.cssText="color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";
|
||||||
|
i.innerHTML="FPS";a.appendChild(i);var c=document.createElement("div");c.id="fpsGraph";c.style.cssText="position:relative;width:74px;height:30px;background-color:#0ff";for(a.appendChild(c);74>c.children.length;){var j=document.createElement("span");j.style.cssText="width:1px;height:30px;float:left;background-color:#113";c.appendChild(j)}var d=document.createElement("div");d.id="ms";d.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#020;display:none";f.appendChild(d);var k=document.createElement("div");
|
||||||
|
k.id="msText";k.style.cssText="color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";k.innerHTML="MS";d.appendChild(k);var e=document.createElement("div");e.id="msGraph";e.style.cssText="position:relative;width:74px;height:30px;background-color:#0f0";for(d.appendChild(e);74>e.children.length;)j=document.createElement("span"),j.style.cssText="width:1px;height:30px;float:left;background-color:#131",e.appendChild(j);var t=function(b){s=b;switch(s){case 0:a.style.display=
|
||||||
|
"block";d.style.display="none";break;case 1:a.style.display="none",d.style.display="block"}};return{REVISION:11,domElement:f,setMode:t,begin:function(){l=Date.now()},end:function(){var b=Date.now();g=b-l;n=Math.min(n,g);o=Math.max(o,g);k.textContent=g+" MS ("+n+"-"+o+")";var a=Math.min(30,30-30*(g/200));e.appendChild(e.firstChild).style.height=a+"px";r++;b>m+1E3&&(h=Math.round(1E3*r/(b-m)),p=Math.min(p,h),q=Math.max(q,h),i.textContent=h+" FPS ("+p+"-"+q+")",a=Math.min(30,30-30*(h/100)),c.appendChild(c.firstChild).style.height=
|
||||||
|
a+"px",m=b,r=0);return b},update:function(){l=this.end()}}};
|
2
examples/alien benchmark/js/vendor/jquery-1.8.3.min.js
vendored
Normal file
2
examples/alien benchmark/js/vendor/jquery-1.8.3.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4
examples/alien benchmark/js/vendor/modernizr-2.6.2.min.js
vendored
Normal file
4
examples/alien benchmark/js/vendor/modernizr-2.6.2.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
21
examples/bunny benchmark/css/main.css
Normal file
21
examples/bunny benchmark/css/main.css
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
body{
|
||||||
|
border: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.counter {
|
||||||
|
background: #ccc;
|
||||||
|
width: 74px;
|
||||||
|
position: absolute;
|
||||||
|
background-color:#105CB6;
|
||||||
|
padding: 3px;
|
||||||
|
|
||||||
|
top:50px;
|
||||||
|
|
||||||
|
color:#0ff;
|
||||||
|
font-family: Helvetica, Arial;
|
||||||
|
font-size: 9px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
17
examples/bunny benchmark/index.html
Normal file
17
examples/bunny benchmark/index.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||||
|
|
||||||
|
<title>Pixi Renderer: Bunny Demo</title>
|
||||||
|
<link rel="stylesheet" href="css/main.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="js/vendor/jquery-1.8.3.min.js"></script>
|
||||||
|
<script src="js/stats.min.js"></script>
|
||||||
|
<script src="js/pixi.min.js"></script>
|
||||||
|
<script src="js/bunnyBenchMark.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
188
examples/bunny benchmark/js/bunnyBenchMark.js
Normal file
188
examples/bunny benchmark/js/bunnyBenchMark.js
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
|
||||||
|
|
||||||
|
$(document).ready(onReady)
|
||||||
|
|
||||||
|
$(window).resize(resize)
|
||||||
|
window.onorientationchange = resize;
|
||||||
|
|
||||||
|
var width = 480;
|
||||||
|
var height = 320;
|
||||||
|
|
||||||
|
var wabbitTexture;
|
||||||
|
var bunnys = [];
|
||||||
|
var gravity = 0.75//1.5 ;
|
||||||
|
|
||||||
|
var maxX = width;
|
||||||
|
var minX = 0;
|
||||||
|
var maxY = height;
|
||||||
|
var minY = 0;
|
||||||
|
|
||||||
|
var startBunnyCount = 10;
|
||||||
|
var isAdding = false;
|
||||||
|
var count = 0;
|
||||||
|
var container;
|
||||||
|
|
||||||
|
function onReady()
|
||||||
|
{
|
||||||
|
var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )()
|
||||||
|
|
||||||
|
if(webgl)
|
||||||
|
{
|
||||||
|
renderer = new PIXI.WebGLRenderer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
renderer = new PIXI.CanvasRenderer(480, 320);
|
||||||
|
}
|
||||||
|
|
||||||
|
stage = new PIXI.Stage;
|
||||||
|
|
||||||
|
document.body.appendChild(renderer.view);
|
||||||
|
|
||||||
|
stats = new Stats();
|
||||||
|
|
||||||
|
document.body.appendChild( stats.domElement );
|
||||||
|
stats.domElement.style.position = "absolute";
|
||||||
|
stats.domElement.style.top = "0px";
|
||||||
|
requestAnimFrame(update);
|
||||||
|
|
||||||
|
wabbitTexture = new PIXI.Texture("wabbit.png")
|
||||||
|
|
||||||
|
counter = document.createElement("div");
|
||||||
|
counter.className = "counter";
|
||||||
|
document.body.appendChild( counter);
|
||||||
|
|
||||||
|
count = startBunnyCount;
|
||||||
|
counter.innerHTML = count + " BUNNIES";
|
||||||
|
|
||||||
|
|
||||||
|
container = new PIXI.DisplayObjectContainer();
|
||||||
|
stage.addChild(container);
|
||||||
|
|
||||||
|
for (var i = 0; i < startBunnyCount; i++)
|
||||||
|
{
|
||||||
|
var bunny = new PIXI.Sprite(wabbitTexture, {x:0, y:0, width:26, height:37});
|
||||||
|
bunny.speedX = Math.random() * 10;
|
||||||
|
bunny.speedY = (Math.random() * 10) - 5;
|
||||||
|
|
||||||
|
bunny.anchor.x = 0.5;
|
||||||
|
bunny.anchor.y = 1;
|
||||||
|
bunnys.push(bunny);
|
||||||
|
|
||||||
|
container.addChild(bunny);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$(renderer.view).mousedown(function(){
|
||||||
|
isAdding = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
$(renderer.view).mouseup(function(){
|
||||||
|
isAdding = false;
|
||||||
|
})
|
||||||
|
|
||||||
|
document.addEventListener("touchstart", onTouchStart, true);
|
||||||
|
document.addEventListener("touchend", onTouchEnd, true);
|
||||||
|
|
||||||
|
renderer.view.touchstart = function(){
|
||||||
|
|
||||||
|
isAdding = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.view.touchend = function(){
|
||||||
|
isAdding = false;
|
||||||
|
}
|
||||||
|
resize();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTouchStart(event)
|
||||||
|
{
|
||||||
|
isAdding = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTouchEnd(event)
|
||||||
|
{
|
||||||
|
isAdding = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resize()
|
||||||
|
{
|
||||||
|
var width = $(window).width();
|
||||||
|
var height = $(window).height();
|
||||||
|
|
||||||
|
maxX = width;
|
||||||
|
minX = 0;
|
||||||
|
maxY = height;
|
||||||
|
minY = 0;
|
||||||
|
|
||||||
|
renderer.resize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update()
|
||||||
|
{
|
||||||
|
stats.begin();
|
||||||
|
|
||||||
|
if(isAdding)
|
||||||
|
{
|
||||||
|
// add 10 at a time :)
|
||||||
|
|
||||||
|
for (var i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
var bunny = new PIXI.Sprite(wabbitTexture, {x:0, y:0, width:26, height:37});
|
||||||
|
bunny.speedX = Math.random() * 10;
|
||||||
|
bunny.speedY = (Math.random() * 10) - 5;
|
||||||
|
|
||||||
|
bunny.anchor.x = 0.5;
|
||||||
|
bunny.anchor.y = 1;
|
||||||
|
bunny.alpha = 0.3 + Math.random() * 0.7;
|
||||||
|
bunnys.push(bunny);
|
||||||
|
bunny.rotation = Math.random() - 0.5;
|
||||||
|
container.addChild(bunny);
|
||||||
|
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
counter.innerHTML = count + " BUNNIES";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < bunnys.length; i++)
|
||||||
|
{
|
||||||
|
var bunny = bunnys[i];
|
||||||
|
|
||||||
|
bunny.position.x += bunny.speedX;
|
||||||
|
bunny.position.y += bunny.speedY;
|
||||||
|
bunny.speedY += gravity;
|
||||||
|
|
||||||
|
if (bunny.position.x > maxX)
|
||||||
|
{
|
||||||
|
bunny.speedX *= -1;
|
||||||
|
bunny.position.x = maxX;
|
||||||
|
}
|
||||||
|
else if (bunny.position.x < minX)
|
||||||
|
{
|
||||||
|
bunny.speedX *= -1;
|
||||||
|
bunny.position.x = minX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bunny.position.y > maxY)
|
||||||
|
{
|
||||||
|
bunny.speedY *= -0.85;
|
||||||
|
bunny.position.y = maxY;
|
||||||
|
bunny.spin = (Math.random()-0.5) * 0.2
|
||||||
|
if (Math.random() > 0.5)
|
||||||
|
{
|
||||||
|
bunny.speedY -= Math.random() * 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (bunny.position.y < minY)
|
||||||
|
{
|
||||||
|
bunny.speedY = 0;
|
||||||
|
bunny.position.y = minY;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.render(stage);
|
||||||
|
requestAnimFrame(update);
|
||||||
|
stats.end();
|
||||||
|
}
|
84
examples/bunny benchmark/js/pixi.min.js
vendored
Normal file
84
examples/bunny benchmark/js/pixi.min.js
vendored
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(c){window.setTimeout(c,1E3/60)}}();var AjaxRequest=function(){var c=["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];if(window.ActiveXObject)for(var d=0;d<c.length;d++)try{return new ActiveXObject(c[d])}catch(f){}else return window.XMLHttpRequest?new XMLHttpRequest:!1};var PIXI=PIXI||{};PIXI.EventTarget=function(){var c={};this.addEventListener=function(d,f){void 0===c[d]&&(c[d]=[]);-1===c[d].indexOf(f)&&c[d].push(f)};this.dispatchEvent=function(d){for(var f in c[d.type])c[d.type][f](d)};this.removeEventListener=function(d,f){var g=c[d].indexOf(f);-1!==g&&c[d].splice(g,1)}};(function(c,d){"object"===typeof exports?module.exports=d(global):"function"===typeof define&&define.amd?define([],function(){return d(c)}):d(c)})(this,function(c){function d(a){return l=a}function f(){return l="undefined"!==typeof Float32Array?Float32Array:Array}var g={};if("undefined"!=typeof Float32Array){var m=new Float32Array(1),p=new Int32Array(m.buffer);g.invsqrt=function(a){m[0]=a;p[0]=1597463007-(p[0]>>1);var b=m[0];return b*(1.5-0.5*a*b*b)}}else g.invsqrt=function(a){return 1/Math.sqrt(a)};
|
||||||
|
var l=null;f();var j={create:function(a){var b=new l(3);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2]):b[0]=b[1]=b[2]=0;return b},createFrom:function(a,b,e){var c=new l(3);c[0]=a;c[1]=b;c[2]=e;return c},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])},add:function(a,b,e){if(!e||a===e)return a[0]+=b[0],a[1]+=b[1],a[2]+=b[2],a;e[0]=a[0]+b[0];e[1]=a[1]+b[1];e[2]=a[2]+b[2];return e},subtract:function(a,
|
||||||
|
b,e){if(!e||a===e)return a[0]-=b[0],a[1]-=b[1],a[2]-=b[2],a;e[0]=a[0]-b[0];e[1]=a[1]-b[1];e[2]=a[2]-b[2];return e},multiply:function(a,b,e){if(!e||a===e)return a[0]*=b[0],a[1]*=b[1],a[2]*=b[2],a;e[0]=a[0]*b[0];e[1]=a[1]*b[1];e[2]=a[2]*b[2];return e},negate:function(a,b){b||(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];return b},scale:function(a,b,e){if(!e||a===e)return a[0]*=b,a[1]*=b,a[2]*=b,a;e[0]=a[0]*b;e[1]=a[1]*b;e[2]=a[2]*b;return e},normalize:function(a,b){b||(b=a);var e=a[0],c=a[1],d=a[2],k=Math.sqrt(e*
|
||||||
|
e+c*c+d*d);if(!k)return b[0]=0,b[1]=0,b[2]=0,b;if(1===k)return b[0]=e,b[1]=c,b[2]=d,b;k=1/k;b[0]=e*k;b[1]=c*k;b[2]=d*k;return b},cross:function(a,b,e){e||(e=a);var c=a[0],d=a[1];a=a[2];var k=b[0],h=b[1];b=b[2];e[0]=d*b-a*h;e[1]=a*k-c*b;e[2]=c*h-d*k;return e},length:function(a){var b=a[0],e=a[1];a=a[2];return Math.sqrt(b*b+e*e+a*a)},squaredLength:function(a){var b=a[0],e=a[1];a=a[2];return b*b+e*e+a*a},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},direction:function(a,b,e){e||(e=a);var c=
|
||||||
|
a[0]-b[0],d=a[1]-b[1];a=a[2]-b[2];b=Math.sqrt(c*c+d*d+a*a);if(!b)return e[0]=0,e[1]=0,e[2]=0,e;b=1/b;e[0]=c*b;e[1]=d*b;e[2]=a*b;return e},lerp:function(a,b,e,c){c||(c=a);c[0]=a[0]+e*(b[0]-a[0]);c[1]=a[1]+e*(b[1]-a[1]);c[2]=a[2]+e*(b[2]-a[2]);return c},dist:function(a,b){var e=b[0]-a[0],c=b[1]-a[1],d=b[2]-a[2];return Math.sqrt(e*e+c*c+d*d)}},x=null,n=new l(4);j.unproject=function(a,b,e,c,d){d||(d=a);x||(x=y.create());var k=x;n[0]=2*(a[0]-c[0])/c[2]-1;n[1]=2*(a[1]-c[1])/c[3]-1;n[2]=2*a[2]-1;n[3]=1;
|
||||||
|
y.multiply(e,b,k);if(!y.inverse(k))return null;y.multiplyVec4(k,n);if(0===n[3])return null;d[0]=n[0]/n[3];d[1]=n[1]/n[3];d[2]=n[2]/n[3];return d};var z=j.createFrom(1,0,0),A=j.createFrom(0,1,0),H=j.createFrom(0,0,1),C=j.create();j.rotationTo=function(a,b,e){e||(e=s.create());var c=j.dot(a,b);if(1<=c)s.set(O,e);else if(-0.999999>c)j.cross(z,a,C),1E-6>j.length(C)&&j.cross(A,a,C),1E-6>j.length(C)&&j.cross(H,a,C),j.normalize(C),s.fromAngleAxis(Math.PI,C,e);else{var c=Math.sqrt(2*(1+c)),d=1/c;j.cross(a,
|
||||||
|
b,C);e[0]=C[0]*d;e[1]=C[1]*d;e[2]=C[2]*d;e[3]=0.5*c;s.normalize(e)}1<e[3]?e[3]=1:-1>e[3]&&(e[3]=-1);return e};j.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+"]"};var F={create:function(a){var b=new l(9);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8]):b[0]=b[1]=b[2]=b[3]=b[4]=b[5]=b[6]=b[7]=b[8]=0;return b},createFrom:function(a,b,e,c,d,k,h,E,K){var q=new l(9);q[0]=a;q[1]=b;q[2]=e;q[3]=c;q[4]=d;q[5]=k;q[6]=h;q[7]=E;q[8]=K;return q},determinant:function(a){var b=
|
||||||
|
a[3],e=a[4],c=a[5],d=a[6],k=a[7],h=a[8];return a[0]*(h*e-c*k)+a[1]*(-h*b+c*d)+a[2]*(k*b-e*d)},inverse:function(a,b){var e=a[0],c=a[1],d=a[2],k=a[3],h=a[4],E=a[5],K=a[6],q=a[7],f=a[8],g=f*h-E*q,j=-f*k+E*K,J=q*k-h*K,r=e*g+c*j+d*J;if(!r)return null;r=1/r;b||(b=F.create());b[0]=g*r;b[1]=(-f*c+d*q)*r;b[2]=(E*c-d*h)*r;b[3]=j*r;b[4]=(f*e-d*K)*r;b[5]=(-E*e+d*k)*r;b[6]=J*r;b[7]=(-q*e+c*K)*r;b[8]=(h*e-c*k)*r;return b},multiply:function(a,b,e){e||(e=a);var c=a[0],d=a[1],k=a[2],h=a[3],E=a[4],f=a[5],q=a[6],g=
|
||||||
|
a[7];a=a[8];var u=b[0],j=b[1],J=b[2],r=b[3],l=b[4],t=b[5],m=b[6],p=b[7];b=b[8];e[0]=u*c+j*h+J*q;e[1]=u*d+j*E+J*g;e[2]=u*k+j*f+J*a;e[3]=r*c+l*h+t*q;e[4]=r*d+l*E+t*g;e[5]=r*k+l*f+t*a;e[6]=m*c+p*h+b*q;e[7]=m*d+p*E+b*g;e[8]=m*k+p*f+b*a;return e},multiplyVec2:function(a,b,e){e||(e=b);var c=b[0];b=b[1];e[0]=c*a[0]+b*a[3]+a[6];e[1]=c*a[1]+b*a[4]+a[7];return e},multiplyVec3:function(a,b,e){e||(e=b);var c=b[0],d=b[1];b=b[2];e[0]=c*a[0]+d*a[3]+b*a[6];e[1]=c*a[1]+d*a[4]+b*a[7];e[2]=c*a[2]+d*a[5]+b*a[8];return e},
|
||||||
|
set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])&&1E-6>Math.abs(a[4]-b[4])&&1E-6>Math.abs(a[5]-b[5])&&1E-6>Math.abs(a[6]-b[6])&&1E-6>Math.abs(a[7]-b[7])&&1E-6>Math.abs(a[8]-b[8])},identity:function(a){a||(a=F.create());a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=1;a[5]=0;a[6]=0;a[7]=0;a[8]=1;return a},transpose:function(a,
|
||||||
|
b){if(!b||a===b){var e=a[1],c=a[2],d=a[5];a[1]=a[3];a[2]=a[6];a[3]=e;a[5]=a[7];a[6]=c;a[7]=d;return a}b[0]=a[0];b[1]=a[3];b[2]=a[6];b[3]=a[1];b[4]=a[4];b[5]=a[7];b[6]=a[2];b[7]=a[5];b[8]=a[8];return b},toMat4:function(a,b){b||(b=y.create());b[15]=1;b[14]=0;b[13]=0;b[12]=0;b[11]=0;b[10]=a[8];b[9]=a[7];b[8]=a[6];b[7]=0;b[6]=a[5];b[5]=a[4];b[4]=a[3];b[3]=0;b[2]=a[2];b[1]=a[1];b[0]=a[0];return b},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+
|
||||||
|
a[8]+"]"}},y={create:function(a){var b=new l(16);a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]);return b},createFrom:function(a,b,e,c,d,k,h,E,f,q,g,u,j,J,r,m){var t=new l(16);t[0]=a;t[1]=b;t[2]=e;t[3]=c;t[4]=d;t[5]=k;t[6]=h;t[7]=E;t[8]=f;t[9]=q;t[10]=g;t[11]=u;t[12]=j;t[13]=J;t[14]=r;t[15]=m;return t},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];
|
||||||
|
b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];b[13]=a[13];b[14]=a[14];b[15]=a[15];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])&&1E-6>Math.abs(a[4]-b[4])&&1E-6>Math.abs(a[5]-b[5])&&1E-6>Math.abs(a[6]-b[6])&&1E-6>Math.abs(a[7]-b[7])&&1E-6>Math.abs(a[8]-b[8])&&1E-6>Math.abs(a[9]-b[9])&&1E-6>Math.abs(a[10]-b[10])&&1E-6>Math.abs(a[11]-b[11])&&1E-6>Math.abs(a[12]-
|
||||||
|
b[12])&&1E-6>Math.abs(a[13]-b[13])&&1E-6>Math.abs(a[14]-b[14])&&1E-6>Math.abs(a[15]-b[15])},identity:function(a){a||(a=y.create());a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a},transpose:function(a,b){if(!b||a===b){var e=a[1],c=a[2],d=a[3],k=a[6],h=a[7],E=a[11];a[1]=a[4];a[2]=a[8];a[3]=a[12];a[4]=e;a[6]=a[9];a[7]=a[13];a[8]=c;a[9]=k;a[11]=a[14];a[12]=d;a[13]=h;a[14]=E;return a}b[0]=a[0];b[1]=a[4];b[2]=a[8];b[3]=a[12];
|
||||||
|
b[4]=a[1];b[5]=a[5];b[6]=a[9];b[7]=a[13];b[8]=a[2];b[9]=a[6];b[10]=a[10];b[11]=a[14];b[12]=a[3];b[13]=a[7];b[14]=a[11];b[15]=a[15];return b},determinant:function(a){var b=a[0],e=a[1],c=a[2],d=a[3],k=a[4],h=a[5],E=a[6],f=a[7],g=a[8],I=a[9],u=a[10],j=a[11],l=a[12],r=a[13],m=a[14];a=a[15];return l*I*E*d-g*r*E*d-l*h*u*d+k*r*u*d+g*h*m*d-k*I*m*d-l*I*c*f+g*r*c*f+l*e*u*f-b*r*u*f-g*e*m*f+b*I*m*f+l*h*c*j-k*r*c*j-l*e*E*j+b*r*E*j+k*e*m*j-b*h*m*j-g*h*c*a+k*I*c*a+g*e*E*a-b*I*E*a-k*e*u*a+b*h*u*a},inverse:function(a,
|
||||||
|
b){b||(b=a);var e=a[0],c=a[1],d=a[2],k=a[3],h=a[4],f=a[5],g=a[6],q=a[7],I=a[8],u=a[9],j=a[10],l=a[11],r=a[12],m=a[13],t=a[14],p=a[15],s=e*f-c*h,n=e*g-d*h,v=e*q-k*h,w=c*g-d*f,x=c*q-k*f,y=d*q-k*g,z=I*m-u*r,A=I*t-j*r,C=I*p-l*r,D=u*t-j*m,F=u*p-l*m,H=j*p-l*t,G=s*H-n*F+v*D+w*C-x*A+y*z;if(!G)return null;G=1/G;b[0]=(f*H-g*F+q*D)*G;b[1]=(-c*H+d*F-k*D)*G;b[2]=(m*y-t*x+p*w)*G;b[3]=(-u*y+j*x-l*w)*G;b[4]=(-h*H+g*C-q*A)*G;b[5]=(e*H-d*C+k*A)*G;b[6]=(-r*y+t*v-p*n)*G;b[7]=(I*y-j*v+l*n)*G;b[8]=(h*F-f*C+q*z)*G;b[9]=
|
||||||
|
(-e*F+c*C-k*z)*G;b[10]=(r*x-m*v+p*s)*G;b[11]=(-I*x+u*v-l*s)*G;b[12]=(-h*D+f*A-g*z)*G;b[13]=(e*D-c*A+d*z)*G;b[14]=(-r*w+m*n-t*s)*G;b[15]=(I*w-u*n+j*s)*G;return b},toRotationMat:function(a,b){b||(b=y.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b},toMat3:function(a,b){b||(b=F.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[4];b[4]=a[5];b[5]=a[6];b[6]=a[8];b[7]=a[9];b[8]=a[10];
|
||||||
|
return b},toInverseMat3:function(a,b){var e=a[0],c=a[1],d=a[2],k=a[4],h=a[5],f=a[6],g=a[8],q=a[9],j=a[10],u=j*h-f*q,l=-j*k+f*g,m=q*k-h*g,r=e*u+c*l+d*m;if(!r)return null;r=1/r;b||(b=F.create());b[0]=u*r;b[1]=(-j*c+d*q)*r;b[2]=(f*c-d*h)*r;b[3]=l*r;b[4]=(j*e-d*g)*r;b[5]=(-f*e+d*k)*r;b[6]=m*r;b[7]=(-q*e+c*g)*r;b[8]=(h*e-c*k)*r;return b},multiply:function(a,b,e){e||(e=a);var c=a[0],d=a[1],k=a[2],h=a[3],f=a[4],g=a[5],q=a[6],j=a[7],u=a[8],l=a[9],m=a[10],r=a[11],p=a[12],t=a[13],s=a[14];a=a[15];var n=b[0],
|
||||||
|
B=b[1],v=b[2],w=b[3];e[0]=n*c+B*f+v*u+w*p;e[1]=n*d+B*g+v*l+w*t;e[2]=n*k+B*q+v*m+w*s;e[3]=n*h+B*j+v*r+w*a;n=b[4];B=b[5];v=b[6];w=b[7];e[4]=n*c+B*f+v*u+w*p;e[5]=n*d+B*g+v*l+w*t;e[6]=n*k+B*q+v*m+w*s;e[7]=n*h+B*j+v*r+w*a;n=b[8];B=b[9];v=b[10];w=b[11];e[8]=n*c+B*f+v*u+w*p;e[9]=n*d+B*g+v*l+w*t;e[10]=n*k+B*q+v*m+w*s;e[11]=n*h+B*j+v*r+w*a;n=b[12];B=b[13];v=b[14];w=b[15];e[12]=n*c+B*f+v*u+w*p;e[13]=n*d+B*g+v*l+w*t;e[14]=n*k+B*q+v*m+w*s;e[15]=n*h+B*j+v*r+w*a;return e},multiplyVec3:function(a,b,e){e||(e=b);
|
||||||
|
var c=b[0],d=b[1];b=b[2];e[0]=a[0]*c+a[4]*d+a[8]*b+a[12];e[1]=a[1]*c+a[5]*d+a[9]*b+a[13];e[2]=a[2]*c+a[6]*d+a[10]*b+a[14];return e},multiplyVec4:function(a,b,e){e||(e=b);var c=b[0],d=b[1],k=b[2];b=b[3];e[0]=a[0]*c+a[4]*d+a[8]*k+a[12]*b;e[1]=a[1]*c+a[5]*d+a[9]*k+a[13]*b;e[2]=a[2]*c+a[6]*d+a[10]*k+a[14]*b;e[3]=a[3]*c+a[7]*d+a[11]*k+a[15]*b;return e},translate:function(a,b,e){var c=b[0],d=b[1];b=b[2];var k,h,f,g,q,j,u,l,m,n,p,s;if(!e||a===e)return a[12]=a[0]*c+a[4]*d+a[8]*b+a[12],a[13]=a[1]*c+a[5]*d+
|
||||||
|
a[9]*b+a[13],a[14]=a[2]*c+a[6]*d+a[10]*b+a[14],a[15]=a[3]*c+a[7]*d+a[11]*b+a[15],a;k=a[0];h=a[1];f=a[2];g=a[3];q=a[4];j=a[5];u=a[6];l=a[7];m=a[8];n=a[9];p=a[10];s=a[11];e[0]=k;e[1]=h;e[2]=f;e[3]=g;e[4]=q;e[5]=j;e[6]=u;e[7]=l;e[8]=m;e[9]=n;e[10]=p;e[11]=s;e[12]=k*c+q*d+m*b+a[12];e[13]=h*c+j*d+n*b+a[13];e[14]=f*c+u*d+p*b+a[14];e[15]=g*c+l*d+s*b+a[15];return e},scale:function(a,b,e){var c=b[0],d=b[1];b=b[2];if(!e||a===e)return a[0]*=c,a[1]*=c,a[2]*=c,a[3]*=c,a[4]*=d,a[5]*=d,a[6]*=d,a[7]*=d,a[8]*=b,a[9]*=
|
||||||
|
b,a[10]*=b,a[11]*=b,a;e[0]=a[0]*c;e[1]=a[1]*c;e[2]=a[2]*c;e[3]=a[3]*c;e[4]=a[4]*d;e[5]=a[5]*d;e[6]=a[6]*d;e[7]=a[7]*d;e[8]=a[8]*b;e[9]=a[9]*b;e[10]=a[10]*b;e[11]=a[11]*b;e[12]=a[12];e[13]=a[13];e[14]=a[14];e[15]=a[15];return e},rotate:function(a,b,e,c){var d=e[0],k=e[1];e=e[2];var h=Math.sqrt(d*d+k*k+e*e),f,g,q,j,l,m,n,r,p,s,x,y,B,v,w,z,A,C,D,F;if(!h)return null;1!==h&&(h=1/h,d*=h,k*=h,e*=h);f=Math.sin(b);g=Math.cos(b);q=1-g;b=a[0];h=a[1];j=a[2];l=a[3];m=a[4];n=a[5];r=a[6];p=a[7];s=a[8];x=a[9];y=
|
||||||
|
a[10];B=a[11];v=d*d*q+g;w=k*d*q+e*f;z=e*d*q-k*f;A=d*k*q-e*f;C=k*k*q+g;D=e*k*q+d*f;F=d*e*q+k*f;d=k*e*q-d*f;k=e*e*q+g;c?a!==c&&(c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a;c[0]=b*v+m*w+s*z;c[1]=h*v+n*w+x*z;c[2]=j*v+r*w+y*z;c[3]=l*v+p*w+B*z;c[4]=b*A+m*C+s*D;c[5]=h*A+n*C+x*D;c[6]=j*A+r*C+y*D;c[7]=l*A+p*C+B*D;c[8]=b*F+m*d+s*k;c[9]=h*F+n*d+x*k;c[10]=j*F+r*d+y*k;c[11]=l*F+p*d+B*k;return c},rotateX:function(a,b,e){var c=Math.sin(b);b=Math.cos(b);var d=a[4],k=a[5],h=a[6],f=a[7],g=a[8],q=a[9],j=a[10],
|
||||||
|
l=a[11];e?a!==e&&(e[0]=a[0],e[1]=a[1],e[2]=a[2],e[3]=a[3],e[12]=a[12],e[13]=a[13],e[14]=a[14],e[15]=a[15]):e=a;e[4]=d*b+g*c;e[5]=k*b+q*c;e[6]=h*b+j*c;e[7]=f*b+l*c;e[8]=d*-c+g*b;e[9]=k*-c+q*b;e[10]=h*-c+j*b;e[11]=f*-c+l*b;return e},rotateY:function(a,b,e){var c=Math.sin(b);b=Math.cos(b);var d=a[0],k=a[1],h=a[2],f=a[3],g=a[8],j=a[9],l=a[10],m=a[11];e?a!==e&&(e[4]=a[4],e[5]=a[5],e[6]=a[6],e[7]=a[7],e[12]=a[12],e[13]=a[13],e[14]=a[14],e[15]=a[15]):e=a;e[0]=d*b+g*-c;e[1]=k*b+j*-c;e[2]=h*b+l*-c;e[3]=f*
|
||||||
|
b+m*-c;e[8]=d*c+g*b;e[9]=k*c+j*b;e[10]=h*c+l*b;e[11]=f*c+m*b;return e},rotateZ:function(a,b,e){var c=Math.sin(b);b=Math.cos(b);var d=a[0],k=a[1],h=a[2],f=a[3],g=a[4],j=a[5],l=a[6],m=a[7];e?a!==e&&(e[8]=a[8],e[9]=a[9],e[10]=a[10],e[11]=a[11],e[12]=a[12],e[13]=a[13],e[14]=a[14],e[15]=a[15]):e=a;e[0]=d*b+g*c;e[1]=k*b+j*c;e[2]=h*b+l*c;e[3]=f*b+m*c;e[4]=d*-c+g*b;e[5]=k*-c+j*b;e[6]=h*-c+l*b;e[7]=f*-c+m*b;return e},frustum:function(a,b,e,c,d,k,h){h||(h=y.create());var f=b-a,g=c-e,j=k-d;h[0]=2*d/f;h[1]=0;
|
||||||
|
h[2]=0;h[3]=0;h[4]=0;h[5]=2*d/g;h[6]=0;h[7]=0;h[8]=(b+a)/f;h[9]=(c+e)/g;h[10]=-(k+d)/j;h[11]=-1;h[12]=0;h[13]=0;h[14]=-(2*k*d)/j;h[15]=0;return h},perspective:function(a,b,e,c,d){a=e*Math.tan(a*Math.PI/360);b*=a;return y.frustum(-b,b,-a,a,e,c,d)},ortho:function(a,b,e,c,d,k,h){h||(h=y.create());var f=b-a,g=c-e,j=k-d;h[0]=2/f;h[1]=0;h[2]=0;h[3]=0;h[4]=0;h[5]=2/g;h[6]=0;h[7]=0;h[8]=0;h[9]=0;h[10]=-2/j;h[11]=0;h[12]=-(a+b)/f;h[13]=-(c+e)/g;h[14]=-(k+d)/j;h[15]=1;return h},lookAt:function(a,b,e,c){c||
|
||||||
|
(c=y.create());var d,k,h,f,g,j,l,m,n=a[0],p=a[1];a=a[2];h=e[0];f=e[1];k=e[2];l=b[0];e=b[1];d=b[2];if(n===l&&p===e&&a===d)return y.identity(c);b=n-l;e=p-e;l=a-d;m=1/Math.sqrt(b*b+e*e+l*l);b*=m;e*=m;l*=m;d=f*l-k*e;k=k*b-h*l;h=h*e-f*b;(m=Math.sqrt(d*d+k*k+h*h))?(m=1/m,d*=m,k*=m,h*=m):h=k=d=0;f=e*h-l*k;g=l*d-b*h;j=b*k-e*d;(m=Math.sqrt(f*f+g*g+j*j))?(m=1/m,f*=m,g*=m,j*=m):j=g=f=0;c[0]=d;c[1]=f;c[2]=b;c[3]=0;c[4]=k;c[5]=g;c[6]=e;c[7]=0;c[8]=h;c[9]=j;c[10]=l;c[11]=0;c[12]=-(d*n+k*p+h*a);c[13]=-(f*n+g*p+
|
||||||
|
j*a);c[14]=-(b*n+e*p+l*a);c[15]=1;return c},fromRotationTranslation:function(a,b,e){e||(e=y.create());var c=a[0],d=a[1],k=a[2],h=a[3],f=c+c,g=d+d,j=k+k;a=c*f;var l=c*g,c=c*j,m=d*g,d=d*j,k=k*j,f=h*f,g=h*g,h=h*j;e[0]=1-(m+k);e[1]=l+h;e[2]=c-g;e[3]=0;e[4]=l-h;e[5]=1-(a+k);e[6]=d+f;e[7]=0;e[8]=c+g;e[9]=d-f;e[10]=1-(a+m);e[11]=0;e[12]=b[0];e[13]=b[1];e[14]=b[2];e[15]=1;return e},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+
|
||||||
|
a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+"]"}},s={create:function(a){var b=new l(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):b[0]=b[1]=b[2]=b[3]=0;return b},createFrom:function(a,b,e,c){var d=new l(4);d[0]=a;d[1]=b;d[2]=e;d[3]=c;return d},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])},identity:function(a){a||(a=s.create());
|
||||||
|
a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a}},O=s.identity();s.calculateW=function(a,b){var e=a[0],c=a[1],d=a[2];if(!b||a===b)return a[3]=-Math.sqrt(Math.abs(1-e*e-c*c-d*d)),a;b[0]=e;b[1]=c;b[2]=d;b[3]=-Math.sqrt(Math.abs(1-e*e-c*c-d*d));return b};s.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]};s.inverse=function(a,b){var e=a[0],c=a[1],d=a[2],f=a[3],e=(e=e*e+c*c+d*d+f*f)?1/e:0;if(!b||a===b)return a[0]*=-e,a[1]*=-e,a[2]*=-e,a[3]*=e,a;b[0]=-a[0]*e;b[1]=-a[1]*e;b[2]=-a[2]*e;b[3]=a[3]*e;
|
||||||
|
return b};s.conjugate=function(a,b){if(!b||a===b)return a[0]*=-1,a[1]*=-1,a[2]*=-1,a;b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=a[3];return b};s.length=function(a){var b=a[0],e=a[1],c=a[2];a=a[3];return Math.sqrt(b*b+e*e+c*c+a*a)};s.normalize=function(a,b){b||(b=a);var e=a[0],c=a[1],d=a[2],f=a[3],h=Math.sqrt(e*e+c*c+d*d+f*f);if(0===h)return b[0]=0,b[1]=0,b[2]=0,b[3]=0,b;h=1/h;b[0]=e*h;b[1]=c*h;b[2]=d*h;b[3]=f*h;return b};s.add=function(a,b,e){if(!e||a===e)return a[0]+=b[0],a[1]+=b[1],a[2]+=b[2],a[3]+=
|
||||||
|
b[3],a;e[0]=a[0]+b[0];e[1]=a[1]+b[1];e[2]=a[2]+b[2];e[3]=a[3]+b[3];return e};s.multiply=function(a,b,e){e||(e=a);var c=a[0],d=a[1],f=a[2];a=a[3];var h=b[0],g=b[1],j=b[2];b=b[3];e[0]=c*b+a*h+d*j-f*g;e[1]=d*b+a*g+f*h-c*j;e[2]=f*b+a*j+c*g-d*h;e[3]=a*b-c*h-d*g-f*j;return e};s.multiplyVec3=function(a,b,e){e||(e=b);var c=b[0],d=b[1],f=b[2];b=a[0];var h=a[1],g=a[2];a=a[3];var j=a*c+h*f-g*d,l=a*d+g*c-b*f,m=a*f+b*d-h*c,c=-b*c-h*d-g*f;e[0]=j*a+c*-b+l*-g-m*-h;e[1]=l*a+c*-h+m*-b-j*-g;e[2]=m*a+c*-g+j*-h-l*-b;
|
||||||
|
return e};s.scale=function(a,b,e){if(!e||a===e)return a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b,a;e[0]=a[0]*b;e[1]=a[1]*b;e[2]=a[2]*b;e[3]=a[3]*b;return e};s.toMat3=function(a,b){b||(b=F.create());var e=a[0],c=a[1],d=a[2],f=a[3],h=e+e,g=c+c,j=d+d,l=e*h,m=e*g,e=e*j,n=c*g,c=c*j,d=d*j,h=f*h,g=f*g,f=f*j;b[0]=1-(n+d);b[1]=m+f;b[2]=e-g;b[3]=m-f;b[4]=1-(l+d);b[5]=c+h;b[6]=e+g;b[7]=c-h;b[8]=1-(l+n);return b};s.toMat4=function(a,b){b||(b=y.create());var e=a[0],c=a[1],d=a[2],f=a[3],g=e+e,j=c+c,l=d+d,m=e*g,n=e*j,e=e*
|
||||||
|
l,p=c*j,c=c*l,d=d*l,g=f*g,j=f*j,f=f*l;b[0]=1-(p+d);b[1]=n+f;b[2]=e-j;b[3]=0;b[4]=n-f;b[5]=1-(m+d);b[6]=c+g;b[7]=0;b[8]=e+j;b[9]=c-g;b[10]=1-(m+p);b[11]=0;b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};s.slerp=function(a,b,c,d){d||(d=a);var f=a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3],g,h;if(1<=Math.abs(f))return d!==a&&(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[3]),d;g=Math.acos(f);h=Math.sqrt(1-f*f);if(0.001>Math.abs(h))return d[0]=0.5*a[0]+0.5*b[0],d[1]=0.5*a[1]+0.5*b[1],d[2]=0.5*a[2]+0.5*b[2],d[3]=0.5*a[3]+
|
||||||
|
0.5*b[3],d;f=Math.sin((1-c)*g)/h;c=Math.sin(c*g)/h;d[0]=a[0]*f+b[0]*c;d[1]=a[1]*f+b[1]*c;d[2]=a[2]*f+b[2]*c;d[3]=a[3]*f+b[3]*c;return d};s.fromRotationMatrix=function(a,b){b||(b=s.create());var c=a[0]+a[4]+a[8],d;if(0<c)d=Math.sqrt(c+1),b[3]=0.5*d,d=0.5/d,b[0]=(a[7]-a[5])*d,b[1]=(a[2]-a[6])*d,b[2]=(a[3]-a[1])*d;else{d=s.fromRotationMatrix.s_iNext=s.fromRotationMatrix.s_iNext||[1,2,0];c=0;a[4]>a[0]&&(c=1);a[8]>a[3*c+c]&&(c=2);var f=d[c],g=d[f];d=Math.sqrt(a[3*c+c]-a[3*f+f]-a[3*g+g]+1);b[c]=0.5*d;d=
|
||||||
|
0.5/d;b[3]=(a[3*g+f]-a[3*f+g])*d;b[f]=(a[3*f+c]+a[3*c+f])*d;b[g]=(a[3*g+c]+a[3*c+g])*d}return b};F.toQuat4=s.fromRotationMatrix;var D=F.create();s.fromAxes=function(a,b,c,d){D[0]=b[0];D[3]=b[1];D[6]=b[2];D[1]=c[0];D[4]=c[1];D[7]=c[2];D[2]=a[0];D[5]=a[1];D[8]=a[2];return s.fromRotationMatrix(D,d)};s.identity=function(a){a||(a=s.create());a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a};s.fromAngleAxis=function(a,b,c){c||(c=s.create());a*=0.5;var d=Math.sin(a);c[3]=Math.cos(a);c[0]=d*b[0];c[1]=d*b[1];c[2]=d*b[2];
|
||||||
|
return c};s.toAngleAxis=function(a,b){b||(b=a);var c=a[0]*a[0]+a[1]*a[1]+a[2]*a[2];0<c?(b[3]=2*Math.acos(a[3]),c=g.invsqrt(c),b[0]=a[0]*c,b[1]=a[1]*c,b[2]=a[2]*c):(b[3]=0,b[0]=1,b[1]=0,b[2]=0);return b};s.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"};var M={create:function(a){var b=new l(2);a?(b[0]=a[0],b[1]=a[1]):(b[0]=0,b[1]=0);return b},createFrom:function(a,b){var c=new l(2);c[0]=a;c[1]=b;return c},add:function(a,b,c){c||(c=b);c[0]=a[0]+b[0];c[1]=a[1]+b[1];return c},subtract:function(a,
|
||||||
|
b,c){c||(c=b);c[0]=a[0]-b[0];c[1]=a[1]-b[1];return c},multiply:function(a,b,c){c||(c=b);c[0]=a[0]*b[0];c[1]=a[1]*b[1];return c},divide:function(a,b,c){c||(c=b);c[0]=a[0]/b[0];c[1]=a[1]/b[1];return c},scale:function(a,b,c){c||(c=a);c[0]=a[0]*b;c[1]=a[1]*b;return c},dist:function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return Math.sqrt(c*c+d*d)},set:function(a,b){b[0]=a[0];b[1]=a[1];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])},negate:function(a,b){b||(b=a);
|
||||||
|
b[0]=-a[0];b[1]=-a[1];return b},normalize:function(a,b){b||(b=a);var c=a[0]*a[0]+a[1]*a[1];0<c?(c=Math.sqrt(c),b[0]=a[0]/c,b[1]=a[1]/c):b[0]=b[1]=0;return b},cross:function(a,b,c){a=a[0]*b[1]-a[1]*b[0];if(!c)return a;c[0]=c[1]=0;c[2]=a;return c},length:function(a){var b=a[0];a=a[1];return Math.sqrt(b*b+a*a)},squaredLength:function(a){var b=a[0];a=a[1];return b*b+a*a},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]},direction:function(a,b,c){c||(c=a);var d=a[0]-b[0];a=a[1]-b[1];b=d*d+a*a;if(!b)return c[0]=
|
||||||
|
0,c[1]=0,c[2]=0,c;b=1/Math.sqrt(b);c[0]=d*b;c[1]=a*b;return c},lerp:function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);return d},str:function(a){return"["+a[0]+", "+a[1]+"]"}},L={create:function(a){var b=new l(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):b[0]=b[1]=b[2]=b[3]=0;return b},createFrom:function(a,b,c,d){var f=new l(4);f[0]=a;f[1]=b;f[2]=c;f[3]=d;return f},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1E-6>
|
||||||
|
Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])},identity:function(a){a||(a=L.create());a[0]=1;a[1]=0;a[2]=0;a[3]=1;return a},transpose:function(a,b){if(!b||a===b){var c=a[1];a[1]=a[2];a[2]=c;return a}b[0]=a[0];b[1]=a[2];b[2]=a[1];b[3]=a[3];return b},determinant:function(a){return a[0]*a[3]-a[2]*a[1]},inverse:function(a,b){b||(b=a);var c=a[0],d=a[1],f=a[2],g=a[3],h=c*g-f*d;if(!h)return null;h=1/h;b[0]=g*h;b[1]=-d*h;b[2]=-f*h;b[3]=c*h;return b},multiply:function(a,
|
||||||
|
b,c){c||(c=a);var d=a[0],f=a[1],g=a[2];a=a[3];c[0]=d*b[0]+f*b[2];c[1]=d*b[1]+f*b[3];c[2]=g*b[0]+a*b[2];c[3]=g*b[1]+a*b[3];return c},rotate:function(a,b,c){c||(c=a);var d=a[0],f=a[1],g=a[2];a=a[3];var h=Math.sin(b);b=Math.cos(b);c[0]=d*b+f*h;c[1]=d*-h+f*b;c[2]=g*b+a*h;c[3]=g*-h+a*b;return c},multiplyVec2:function(a,b,c){c||(c=b);var d=b[0];b=b[1];c[0]=d*a[0]+b*a[1];c[1]=d*a[2]+b*a[3];return c},scale:function(a,b,c){c||(c=a);var d=a[1],f=a[2],g=a[3],h=b[0];b=b[1];c[0]=a[0]*h;c[1]=d*b;c[2]=f*h;c[3]=
|
||||||
|
g*b;return c},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"}},N={create:function(a){var b=new l(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):(b[0]=0,b[1]=0,b[2]=0,b[3]=0);return b},createFrom:function(a,b,c,d){var f=new l(4);f[0]=a;f[1]=b;f[2]=c;f[3]=d;return f},add:function(a,b,c){c||(c=b);c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];c[3]=a[3]+b[3];return c},subtract:function(a,b,c){c||(c=b);c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];c[3]=a[3]-b[3];return c},multiply:function(a,
|
||||||
|
b,c){c||(c=b);c[0]=a[0]*b[0];c[1]=a[1]*b[1];c[2]=a[2]*b[2];c[3]=a[3]*b[3];return c},divide:function(a,b,c){c||(c=b);c[0]=a[0]/b[0];c[1]=a[1]/b[1];c[2]=a[2]/b[2];c[3]=a[3]/b[3];return c},scale:function(a,b,c){c||(c=a);c[0]=a[0]*b;c[1]=a[1]*b;c[2]=a[2]*b;c[3]=a[3]*b;return c},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1E-6>Math.abs(a[0]-b[0])&&1E-6>Math.abs(a[1]-b[1])&&1E-6>Math.abs(a[2]-b[2])&&1E-6>Math.abs(a[3]-b[3])},negate:function(a,b){b||
|
||||||
|
(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=-a[3];return b},length:function(a){var b=a[0],c=a[1],d=a[2];a=a[3];return Math.sqrt(b*b+c*c+d*d+a*a)},squaredLength:function(a){var b=a[0],c=a[1],d=a[2];a=a[3];return b*b+c*c+d*d+a*a},lerp:function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);d[2]=a[2]+c*(b[2]-a[2]);d[3]=a[3]+c*(b[3]-a[3]);return d},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"}};c&&(c.glMatrixArrayType=l,c.MatrixArray=l,c.setMatrixArrayType=d,c.determineMatrixArrayType=
|
||||||
|
f,c.glMath=g,c.vec2=M,c.vec3=j,c.vec4=N,c.mat2=L,c.mat3=F,c.mat4=y,c.quat4=s);return{glMatrixArrayType:l,MatrixArray:l,setMatrixArrayType:d,determineMatrixArrayType:f,glMath:g,vec2:M,vec3:j,vec4:N,mat2:L,mat3:F,mat4:y,quat4:s}});PIXI=PIXI||{};PIXI.shaderFragmentSrc=["precision mediump float;","varying vec2 vTextureCoord;","varying float vColor;","uniform sampler2D uSampler;","void main(void) {","gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));","gl_FragColor = gl_FragColor * vColor;","}"];
|
||||||
|
PIXI.shaderVertexSrc=["attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aColor;","uniform mat4 uMVMatrix;","varying vec2 vTextureCoord;","varying float vColor;","void main(void) {","gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);","vTextureCoord = aTextureCoord;","vColor = aColor;","}"];
|
||||||
|
PIXI.CompileVertexShader=function(c,d){for(var f="",g=0;g<d.length;g++)f+=d[g];g=c.createShader(c.VERTEX_SHADER);c.shaderSource(g,f);c.compileShader(g);return!c.getShaderParameter(g,c.COMPILE_STATUS)?(alert(c.getShaderInfoLog(g)),null):g};PIXI.CompileFragmentShader=function(c,d){for(var f="",g=0;g<d.length;g++)f+=d[g];g=c.createShader(c.FRAGMENT_SHADER);c.shaderSource(g,f);c.compileShader(g);return!c.getShaderParameter(g,c.COMPILE_STATUS)?(alert(c.getShaderInfoLog(g)),null):g};PIXI=PIXI||{};PIXI._defaultFrame={x:0,y:0,width:1,height:1};
|
||||||
|
PIXI.WebGLRenderer=function(c,d){this.width=c?c:800;this.height=d?d:600;this.view=document.createElement("canvas");this.view.width=this.width;this.view.height=this.height;this.view.background="#FF0000";var f=this;this.view.addEventListener("webglcontextlost",function(c){f.handleContextLost(c)},!1);this.view.addEventListener("webglcontextrestored",function(c){f.handleContextRestored(c)},!1);this.batchs=[];try{this.gl=this.view.getContext("experimental-webgl",{alpha:!1})}catch(g){alert("Web GL only im afraid :/")}this.initShaders();
|
||||||
|
var m=this.gl;this.batch=new PIXI.WebGLBatch(m);m.disable(m.DEPTH_TEST);m.enable(m.BLEND);m.colorMask(!0,!0,!0,!1);this.projectionMatrix=mat4.create();this.resize(this.width,this.height);this.contextLost=!1};PIXI.WebGLRenderer.constructor=PIXI.WebGLRenderer;
|
||||||
|
PIXI.WebGLRenderer.prototype.initShaders=function(){var c=this.gl,d=PIXI.CompileFragmentShader(c,PIXI.shaderFragmentSrc),f=PIXI.CompileVertexShader(c,PIXI.shaderVertexSrc),g=this.shaderProgram=c.createProgram();c.attachShader(g,f);c.attachShader(g,d);c.linkProgram(g);c.getProgramParameter(g,c.LINK_STATUS)||alert("Could not initialise shaders");c.useProgram(g);g.vertexPositionAttribute=c.getAttribLocation(g,"aVertexPosition");c.enableVertexAttribArray(g.vertexPositionAttribute);g.textureCoordAttribute=
|
||||||
|
c.getAttribLocation(g,"aTextureCoord");c.enableVertexAttribArray(g.textureCoordAttribute);g.colorAttribute=c.getAttribLocation(g,"aColor");c.enableVertexAttribArray(g.colorAttribute);g.mvMatrixUniform=c.getUniformLocation(g,"uMVMatrix");g.samplerUniform=c.getUniformLocation(g,"uSampler");PIXI.shaderProgram=this.shaderProgram};
|
||||||
|
PIXI.WebGLRenderer.prototype.render=function(c){if(!this.contextLost){for(var d=0;d<c.__childrenRemoved.length;d++)this.removeDisplayObject(c.__childrenRemoved[d]);for(d=0;d<c.__childrenAdded.length;d++)this.addDisplayObject(c.__childrenAdded[d]);for(d=0;d<PIXI.texturesToUpdate.length;d++)this.updateTexture(PIXI.texturesToUpdate[d]);c.__childrenRemoved=[];c.__childrenAdded=[];PIXI.texturesToUpdate=[];c.updateTransform();var f=this.gl;f.clear(f.COLOR_BUFFER_BIT);f.clearColor(1,1,1,1);f.blendFunc(f.ONE,
|
||||||
|
f.ONE_MINUS_SRC_ALPHA);f.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform,!1,this.projectionMatrix);if(this.refreshBatchs){for(d=0;d<this.batchs.length;d++)this.batchs[d].dirty&&PIXI._returnBatch(this.batchs[d]);this.batchs=[];this.currentBatch=PIXI._getBatch(f);this.collectBatchs(c);this.currentBatch&&(this.currentBatch.cache(),this.batchs.push(this.currentBatch));this.refreshBatchs=!1}this.updateDisplayObjects(c);for(d=0;d<this.batchs.length;d++)this.batchs[d].render()}};
|
||||||
|
PIXI.WebGLRenderer.prototype.updateDisplayObjects=function(c){for(var d,f,g,m,p,l,j,x,n,z,A,H;c;){if(!c.visible&&(c=c.parent[c.childIndex+1],!c))continue;c.sprite&&(d=c.batch.verticies,g=c.width,m=c.height,p=c.anchor.x,l=c.anchor.y,j=g*(1-p),g*=-p,p=m*(1-l),l=m*-l,m=8*c.index,f=c.worldTransform,x=f[0],n=f[3],z=f[1],A=f[4],H=f[2],f=f[5],d[m+0]=x*g+z*l+H,d[m+1]=A*l+n*g+f,d[m+2]=x*j+z*l+H,d[m+3]=A*l+n*j+f,d[m+4]=x*j+z*p+H,d[m+5]=A*p+n*j+f,d[m+6]=x*g+z*p+H,d[m+7]=A*p+n*g+f,c.updateFrame&&(c.batch.dirtyUVS=
|
||||||
|
!0,j=c.frame,g=c.texture.width,p=c.texture.height,d=c.batch.uvs,d[m+0]=j.x/g,d[m+1]=j.y/p,d[m+2]=(j.x+j.width)/g,d[m+3]=j.y/p,d[m+4]=(j.x+j.width)/g,d[m+5]=(j.y+j.height)/p,d[m+6]=j.x/g,d[m+7]=(j.y+j.height)/p,c.updateFrame=!1),c.cacheAlpha!=c.alpha&&(c.cacheAlpha=c.alpha,j=4*c.index,d=c.batch.colors,d[j]=d[j+1]=d[j+2]=d[j+3]=c.alpha,c.batch.dirtyColors=!0),c.cacheVisible!=c.visible&&(c.cacheVisible=c.visible,this.refreshBatchs=c.batch.dirty=!0));c=c._next}};
|
||||||
|
PIXI.WebGLRenderer.prototype.collectBatchs=function(c){for(var d=this.currentBatch,f=this.gl,g=d.uvs,m=d.colors,p=d.indicies,l,j,x;c;){if(!c.visible&&(c=c.parent[c.childIndex+1],!c)){this.currentBatch=null;break}if(c.sprite){if(d.texture!=c.texture){d.cache();this.batchs.push(d);for(d=!1;!d;){d=!0;if(!c){this.currentBatch=null;return}c.batch&&!c.batch.dirty&&(this.batchs.push(c.batch),c=c.batch.last._next,d=!1)}d=this.currentBatch=PIXI._getBatch(f);g=d.uvs;m=d.colors;p=d.indicies;d.texture=c.texture}c.index=
|
||||||
|
d.size;l=8*d.size;j=6*d.size;x=4*d.size;index4=4*d.size;var n=c.frame,z=c.texture.width,A=c.texture.height;n||(n=PIXI._defaultFrame);g[l+0]=n.x/z;g[l+1]=n.y/A;g[l+2]=(n.x+n.width)/z;g[l+3]=n.y/A;g[l+4]=(n.x+n.width)/z;g[l+5]=(n.y+n.height)/A;g[l+6]=n.x/z;g[l+7]=(n.y+n.height)/A;m[index4]=m[index4+1]=m[index4+2]=m[index4+3]=c.alpha;p[j+0]=x+0;p[j+1]=x+1;p[j+2]=x+2;p[j+3]=x+0;p[j+4]=x+2;p[j+5]=x+3;d.last=c;d.size++}c.batch=d;d.last=c;c=c._next}};
|
||||||
|
PIXI.WebGLRenderer.prototype.updateTexture=function(c){var d=this.gl;c._glTexture||(c._glTexture=d.createTexture());c.hasLoaded&&(d.bindTexture(d.TEXTURE_2D,c._glTexture),d.pixelStorei(d.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),d.texImage2D(d.TEXTURE_2D,0,d.RGBA,d.RGBA,d.UNSIGNED_BYTE,c.image),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,d.LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_WRAP_S,d.CLAMP_TO_EDGE),d.texParameteri(d.TEXTURE_2D,
|
||||||
|
d.TEXTURE_WRAP_T,d.CLAMP_TO_EDGE),d.generateMipmap(d.TEXTURE_2D),d.bindTexture(d.TEXTURE_2D,null));this.refreshBatchs=!0};
|
||||||
|
PIXI.WebGLRenderer.prototype.addDisplayObject=function(c){c.batch=null;c.cacheVisible=c.visible;var d;if(0==c.childIndex)d=c.parent;else for(d=c.parent.children[c.childIndex-1];0!=d.children.length;)d=d.children[d.children.length-1];var f=d._next;d._next=c;c._prev=d;f&&(c._next=f,f._prev=c);if(c.sprite){if((d=c._prev.batch)&&d.texture==c.texture)d.dirty=!0;if(c._next&&(c=c._next.batch)&&c.texture==c.texture)c.dirty=!0;this.refreshBatchs=!0}};
|
||||||
|
PIXI.WebGLRenderer.prototype.removeDisplayObject=function(c){var d=c.batch;d&&(d.dirty=!0);c._prev&&(c._prev._next=c._next);c._next&&(c._next._prev=c._prev);c.batch=null;this.refreshBatchs=!0};
|
||||||
|
PIXI.WebGLRenderer.prototype.resize=function(c,d){this.width=c;this.height=d;this.view.width=c;this.view.height=d;this.gl.viewport(0,0,this.width,this.height);mat4.identity(this.projectionMatrix);mat4.scale(this.projectionMatrix,[2/this.width,-2/this.height,1]);mat4.translate(this.projectionMatrix,[-this.width/2,-this.height/2,0])};PIXI.WebGLRenderer.prototype.handleContextLost=function(c){c.preventDefault();this.contextLost=!0};
|
||||||
|
PIXI.WebGLRenderer.prototype.handleContextRestored=function(){this.gl=this.view.getContext("experimental-webgl",{alpha:!0});this.initShaders();for(var c=0;c<PIXI.TextureCache.length;c++)this.updateTexture(PIXI.TextureCache[c]);for(c=0;c<this.batchs.length;c++)this.batchs[c].restoreLostContext(this.gl),this.batchs[c].dirty=!0;PIXI._restoreBatchs(this.gl);this.contextLost=!1};PIXI=PIXI||{};PIXI.CanvasRenderer=function(c,d){this.width=c?c:800;this.height=d?d:600;this.refresh=!0;this.view=document.createElement("canvas");this.view.width=this.width;this.view.height=this.height;this.view.background="#FF0000";this.context=this.view.getContext("2d")};PIXI.CanvasRenderer.constructor=PIXI.CanvasRenderer;
|
||||||
|
PIXI.CanvasRenderer.prototype.render=function(c){c.__childrenAdded=[];PIXI.texturesToUpdate=[];c.updateTransform();this.context.setTransform(1,0,0,1,0,0);this.context.clearRect(0,0,this.width,this.height);this.renderDisplayObject(c)};
|
||||||
|
PIXI.CanvasRenderer.prototype.renderDisplayObject=function(c){if(c.visible){if(c.sprite){var d=c.worldTransform,f=c.frame;f&&(this.context.globalAlpha=c.worldAlpha,this.context.setTransform(d[0],d[3],d[1],d[4],d[2],d[5]),this.context.drawImage(c.texture.image,f.x,f.y,f.width,f.height,c.anchor.x*-f.width,c.anchor.y*-f.height,f.width,f.height))}for(d=0;d<c.children.length;d++)this.renderDisplayObject(c.children[d])}};
|
||||||
|
PIXI.CanvasRenderer.prototype.resize=function(c,d){this.width=c;this.height=d;this.view.width=c;this.view.height=d};PIXI=PIXI||{};PIXI._defaultFrame={x:0,y:0,width:1,height:1};PIXI.DOMRenderer=function(c,d){this.width=c?c:800;this.height=d?d:600;this.view=document.createElement("div");this.view.style.width=this.width+"px";this.view.style.height=this.height+"px";this.view.style.background="#FF0000";this.view.style["-webkit-transform"]="translateZ(0)";this.resize(this.width,this.height)};PIXI.DOMRenderer.constructor=PIXI.DOMRenderer;
|
||||||
|
PIXI.DOMRenderer.prototype.render=function(c){for(var d=0;d<c.__childrenRemoved.length;d++)this.removeDisplayObject(c.__childrenRemoved[d]);for(d=0;d<c.__childrenAdded.length;d++)this.addDisplayObject(c.__childrenAdded[d]);for(d=0;d<PIXI.texturesToUpdate.length;d++)this.updateTexture(PIXI.texturesToUpdate[d]);c.__childrenRemoved=[];c.__childrenAdded=[];PIXI.texturesToUpdate=[];c.updateTransform();this.renderDisplayObject(c)};PIXI.DOMRenderer.prototype.updateTexture=function(){};
|
||||||
|
PIXI.DOMRenderer.prototype.renderDisplayObject=function(c){if(c.visible){if(c.sprite){var d=c.worldTransform;c.frame&&(c._div.style["-webkit-transform"]="matrix("+d[0]+", "+d[3]+","+d[1]+","+d[4]+","+d[2]+","+d[5]+")")}for(d=0;d<c.children.length;d++)this.renderDisplayObject(c.children[d])}};PIXI.DOMRenderer.prototype.addDisplayObject=function(c){if(c.sprite&&!c._div){var d=document.createElement("img");d.src=c.texture.imageUrl;d.style.cssText="position:absolute;";c._div=d;this.view.appendChild(d)}};
|
||||||
|
PIXI.DOMRenderer.prototype.removeDisplayObject=function(){};PIXI.DOMRenderer.prototype.resize=function(c,d){this.width=c;this.height=d;this.view.style.width=this.width+"px";this.view.style.height=this.height+"px"};PIXI=PIXI||{};PIXI.DisplayObject=function(){this.position={x:0,y:0};this.scale={x:1,y:1};this.rotation=0;this.dynamic=!0;this.alpha=1;this.color=[];this.worldAlpha=1;this.visible=!0;this.worldTransform=mat3.identity();this.localTransform=mat3.identity();this.parent;this.stage;this._sr=0;this._cr=1};PIXI.DisplayObject.constructor=Object.create(PIXI.DisplayObject.prototype);
|
||||||
|
PIXI.DisplayObject.prototype.updateTransform=function(){this.rotation!=this.rotationCache&&(this.rotationCach=this.rotation,this._sr=Math.sin(this.rotation),this._cr=Math.cos(this.rotation));this.localTransform[0]=this._cr*this.scale.x;this.localTransform[1]=-this._sr*this.scale.y;this.localTransform[3]=this._sr*this.scale.x;this.localTransform[4]=this._cr*this.scale.y;this.localTransform[2]=this.position.x;this.localTransform[5]=this.position.y;mat3.multiply(this.localTransform,this.parent.worldTransform,
|
||||||
|
this.worldTransform);this.worldAlpha=this.alpha*this.parent.worldAlpha};PIXI=PIXI||{};PIXI._batchs=[];PIXI._getBatch=function(c){return 0==PIXI._batchs.length?new PIXI.WebGLBatch(c):PIXI._batchs.pop()};PIXI._returnBatch=function(c){c.clean();PIXI._batchs.push(c)};PIXI._restoreBatchs=function(c){for(var d=0;d<PIXI._batchs.length;d++)PIXI._batchs[d].restoreLostContext(c)};
|
||||||
|
PIXI.WebGLBatch=function(c){this.gl=c;this.size=0;this.verticies=[];this.uvs=[];this.indicies=[];this.colors=[];this.texture;this.vertexBuffer=c.createBuffer();this.indexBuffer=c.createBuffer();this.uvBuffer=c.createBuffer();this.colorBuffer=c.createBuffer()};PIXI.WebGLBatch.constructor=PIXI.WebGLBatch;PIXI.WebGLBatch.prototype.clean=function(){this.verticies=[];this.uvs=[];this.indicies=[];this.colors=[];this.last=this.texture=null;this.size=0};
|
||||||
|
PIXI.WebGLBatch.prototype.restoreLostContext=function(c){this.gl=c;this.vertexBuffer=c.createBuffer();this.indexBuffer=c.createBuffer();this.uvBuffer=c.createBuffer();this.colorBuffer=c.createBuffer()};
|
||||||
|
PIXI.WebGLBatch.prototype.render=function(){if(0!=this.size){var c=this.gl,d=PIXI.shaderProgram;c.bindBuffer(c.ARRAY_BUFFER,this.vertexBuffer);c.bufferData(c.ARRAY_BUFFER,this.verticies,c.STATIC_DRAW);c.vertexAttribPointer(d.vertexPositionAttribute,2,c.FLOAT,!1,0,0);c.bindBuffer(c.ARRAY_BUFFER,this.uvBuffer);this.dirtyUVS&&(this.dirtyUVS=!1,c.bufferData(c.ARRAY_BUFFER,this.uvs,c.STATIC_DRAW));c.vertexAttribPointer(d.textureCoordAttribute,2,c.FLOAT,!1,0,0);c.activeTexture(c.TEXTURE0);c.bindTexture(c.TEXTURE_2D,
|
||||||
|
this.texture._glTexture);c.bindBuffer(c.ARRAY_BUFFER,this.colorBuffer);this.dirtyColors&&c.bufferData(c.ARRAY_BUFFER,this.colors,c.STATIC_DRAW);c.vertexAttribPointer(d.colorAttribute,1,c.FLOAT,!1,0,0);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,this.indexBuffer);c.drawElements(c.TRIANGLES,6*this.size,c.UNSIGNED_SHORT,0)}};
|
||||||
|
PIXI.WebGLBatch.prototype.cache=function(){var c=this.gl;c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,this.indexBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indicies),c.STATIC_DRAW);this.dirtyUVS=!0;this.uvs=new Float32Array(this.uvs);this.verticies=new Float32Array(8*this.size);this.colors=new Float32Array(this.colors)};PIXI=PIXI||{};PIXI.DisplayObjectContainer=function(){PIXI.DisplayObject.call(this);this.children=[]};PIXI.DisplayObjectContainer.constructor=PIXI.DisplayObjectContainer;PIXI.DisplayObjectContainer.protoype=Object.create(PIXI.DisplayObject.prototype);PIXI.DisplayObjectContainer.prototype.updateTransform=function(){PIXI.DisplayObject.prototype.updateTransform.call(this);for(var c=0,d=this.children.length;c<d;c++)this.children[c].updateTransform()};
|
||||||
|
PIXI.DisplayObjectContainer.prototype.addChild=function(c){void 0!=c.parent&&c.parent.removeChild(c);c.parent=this;c.childIndex=this.children.length;this.children.push(c);this.stage&&this.stage.__addChild(c)};PIXI.DisplayObjectContainer.prototype.removeChild=function(c){var d=this.children.indexOf(c);-1!==d&&(this.stage.__removeChild(c),c.parent=void 0,this.children.splice(d,1))};PIXI=PIXI||{};PIXI.Stage=function(){PIXI.DisplayObjectContainer.call(this);this.worldTransform=mat3.identity();this.__childrenAdded=[];this.__childrenRemoved=[];this.childIndex=0;this.stage=this};PIXI.Stage.constructor=PIXI.Stage;PIXI.Stage.prototype=Object.create(PIXI.DisplayObjectContainer.prototype);PIXI.Stage.prototype.updateTransform=function(){this.worldAlpha=1;for(var c=0,d=this.children.length;c<d;c++)this.children[c].updateTransform()};
|
||||||
|
PIXI.Stage.prototype.__addChild=function(c){this.__childrenAdded.push(c);c.stage=this;for(var d=0;d<c.children.length;d++)this.__addChild(c.children[d])};PIXI.Stage.prototype.__removeChild=function(c){this.__childrenRemoved.push(c);c.stage=void 0;for(var d=0,f=c.children.length;d<f;d++)this.__removeChild(c.children[d])};PIXI=PIXI||{};PIXI.Sprite=function(c,d){PIXI.DisplayObjectContainer.call(this);this.anchor={x:0,y:0};this.sprite=!0;this.texture=c;this.frame=d;this.height=this.width=1;c.hasLoaded&&(d||(d={x:0,y:0,width:c.width,height:c.height}),this.setFrame(d));var f=this;c.addEventListener("loaded",function(){f.frame||(f.frame={x:0,y:0,width:c.width,height:c.height});f.width=f.frame.width;f.height=f.frame.height;f.updateFrame=!0})};PIXI.Sprite.constructor=PIXI.Sprite;PIXI.Sprite.prototype=Object.create(PIXI.DisplayObjectContainer.prototype);
|
||||||
|
PIXI.Sprite.prototype.setFrame=function(c){this.frame=c;this.width=c.width;this.height=c.height;this.updateFrame=!0};PIXI.Sprite.spriteFromFrame=function(c){c=PIXI.FrameCache[c];return new PIXI.Sprite(PIXI.TextureCache[c.texture],{x:c.x,y:c.y,width:c.width,height:c.height})};PIXI.Sprite.spriteFromTexture=function(){return new PIXI.Sprite(PIXI.TextureCache[frameData.texture])};PIXI=PIXI||{};PIXI.MovieClip=function(c,d){PIXI.Sprite.call(this,c,d[0]);this.frames=d;this.framePosition=0;this.speed=1};PIXI.MovieClip.constructor=PIXI.MovieClip;PIXI.MovieClip.prototype=Object.create(PIXI.Sprite.prototype);PIXI.MovieClip.prototype.updateTransform=function(){PIXI.Sprite.prototype.updateTransform.call(this);this.framePosition+=this.speed;this.setFrame(this.frames[Math.round(this.framePosition)%this.frames.length])};PIXI=PIXI||{};PIXI.TextureCache={};PIXI.FrameCache={};PIXI.texturesToUpdate=[];PIXI.Texture=function(c){PIXI.EventTarget.call(this);this.imageUrl=c;this.frame={x:0,y:0,width:1,height:1};this.hasLoaded=!1;this.image=new Image;this.image.onload=$.proxy(this.onImageLoaded,this);this.image.src=c;this.height=this.width=100;PIXI.TextureCache[c]=this};
|
||||||
|
PIXI.Texture.prototype.onImageLoaded=function(){this.hasLoaded=!0;this.width=this.image.width;this.height=this.image.height;PIXI.texturesToUpdate.push(this);this.dispatchEvent({type:"loaded",content:this})};PIXI.Texture.getTexture=function(c){var d=PIXI.TextureCache[c];d||(d=new PIXI.Texture(c));return d};PIXI=PIXI||{};PIXI.autoDetectRenderer=function(c,d){var f;try{f=!!window.WebGLRenderingContext&&!!document.createElement("canvas").getContext("experimental-webgl")}catch(g){f=!1}console.log(f);return f?new PIXI.WebGLRenderer(c,d):new PIXI.CanvasRenderer(c,d)};PIXI=PIXI||{};PIXI.SpriteSheetLoader=function(c){PIXI.EventTarget.call(this);this.url=c;this.baseUrl=c.replace(/[^\/]*$/,"");this.texture;this.frames={}};PIXI.SpriteSheetLoader.constructor=PIXI.SpriteSheetLoader;PIXI.SpriteSheetLoader.prototype.load=function(){this.ajaxRequest=new AjaxRequest;var c=this;this.ajaxRequest.onreadystatechange=function(){c.onLoaded()};this.ajaxRequest.open("GET",this.url,!0);this.ajaxRequest.send(null)};
|
||||||
|
PIXI.SpriteSheetLoader.prototype.onLoaded=function(){if(4==this.ajaxRequest.readyState&&(200==this.ajaxRequest.status||-1==window.location.href.indexOf("http"))){var c=eval("("+this.ajaxRequest.responseText+")"),d=this.baseUrl+c.meta.image;this.texture=PIXI.TextureCache[d];this.texture||(this.texture=new PIXI.Texture(d));var c=c.frames,f;for(f in c){var g=c[f].frame;this.frames[f]={x:g.x,y:g.y,width:g.w,height:g.h,texture:d};PIXI.FrameCache[f]=this.frames[f]}this.dispatchEvent({type:"loaded",content:this})}};PIXI=PIXI||{};PIXI.AssetLoader=function(c){PIXI.EventTarget.call(this);this.assetURLs=c;this.assets=[]};PIXI.AssetLoader.constructor=PIXI.AssetLoader;
|
||||||
|
PIXI.AssetLoader.prototype.load=function(){this.loadCount=this.assetURLs.length;for(var c=["jpeg","jpg","png","gif"],d=["json"],f=0;f<this.assetURLs.length;f++){for(var g=this.assetURLs[f],m=g.split(".").pop().toLowerCase(),p,f=0;f<c.length;f++)if(m==c[f]){p="img";break}if(!p)for(f=0;f<d.length;f++)if(m==d[f]){p="atlas";break}if("img"==p)if(g=PIXI.Texture.getTexture(g),g.hasLoaded)this.loadCount--;else{var l=this;g.addEventListener("loaded",function(){l.onAssetLoaded()});this.assets.push(g)}else"atlas"==
|
||||||
|
p?(g=new PIXI.SpriteSheetLoader(g),this.assets.push(g),l=this,g.addEventListener("loaded",function(){l.onAssetLoaded()}),g.load()):this.loadCount--}};PIXI.AssetLoader.prototype.onAssetLoaded=function(){this.loadCount--;0==this.loadCount&&this.dispatchEvent({type:"loaded",content:this})};
|
6
examples/bunny benchmark/js/stats.min.js
vendored
Normal file
6
examples/bunny benchmark/js/stats.min.js
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// stats.js - http://github.com/mrdoob/stats.js
|
||||||
|
var Stats=function(){var l=Date.now(),m=l,g=0,n=Infinity,o=0,h=0,p=Infinity,q=0,r=0,s=0,f=document.createElement("div");f.id="stats";f.addEventListener("mousedown",function(b){b.preventDefault();t(++s%2)},!1);f.style.cssText="width:80px;opacity:0.9;cursor:pointer";var a=document.createElement("div");a.id="fps";a.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#002";f.appendChild(a);var i=document.createElement("div");i.id="fpsText";i.style.cssText="color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";
|
||||||
|
i.innerHTML="FPS";a.appendChild(i);var c=document.createElement("div");c.id="fpsGraph";c.style.cssText="position:relative;width:74px;height:30px;background-color:#0ff";for(a.appendChild(c);74>c.children.length;){var j=document.createElement("span");j.style.cssText="width:1px;height:30px;float:left;background-color:#113";c.appendChild(j)}var d=document.createElement("div");d.id="ms";d.style.cssText="padding:0 0 3px 3px;text-align:left;background-color:#020;display:none";f.appendChild(d);var k=document.createElement("div");
|
||||||
|
k.id="msText";k.style.cssText="color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px";k.innerHTML="MS";d.appendChild(k);var e=document.createElement("div");e.id="msGraph";e.style.cssText="position:relative;width:74px;height:30px;background-color:#0f0";for(d.appendChild(e);74>e.children.length;)j=document.createElement("span"),j.style.cssText="width:1px;height:30px;float:left;background-color:#131",e.appendChild(j);var t=function(b){s=b;switch(s){case 0:a.style.display=
|
||||||
|
"block";d.style.display="none";break;case 1:a.style.display="none",d.style.display="block"}};return{REVISION:11,domElement:f,setMode:t,begin:function(){l=Date.now()},end:function(){var b=Date.now();g=b-l;n=Math.min(n,g);o=Math.max(o,g);k.textContent=g+" MS ("+n+"-"+o+")";var a=Math.min(30,30-30*(g/200));e.appendChild(e.firstChild).style.height=a+"px";r++;b>m+1E3&&(h=Math.round(1E3*r/(b-m)),p=Math.min(p,h),q=Math.max(q,h),i.textContent=h+" FPS ("+p+"-"+q+")",a=Math.min(30,30-30*(h/100)),c.appendChild(c.firstChild).style.height=
|
||||||
|
a+"px",m=b,r=0);return b},update:function(){l=this.end()}}};
|
2
examples/bunny benchmark/js/vendor/jquery-1.8.3.min.js
vendored
Normal file
2
examples/bunny benchmark/js/vendor/jquery-1.8.3.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4
examples/bunny benchmark/js/vendor/modernizr-2.6.2.min.js
vendored
Normal file
4
examples/bunny benchmark/js/vendor/modernizr-2.6.2.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
examples/bunny benchmark/wabbit.png
Normal file
BIN
examples/bunny benchmark/wabbit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 449 B |
100
src/pixi/DisplayObject.js
Normal file
100
src/pixi/DisplayObject.js
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class The DisplayObject class is the base class for all objects that are rendered on the screen.
|
||||||
|
* @constructor
|
||||||
|
* @return A new DisplayObject.
|
||||||
|
*/
|
||||||
|
PIXI.DisplayObject = function()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The coordinate of the object relative to the local coordinates of the parent.
|
||||||
|
* @type Point
|
||||||
|
*/
|
||||||
|
this.position = new PIXI.Point();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scale factor of the object.
|
||||||
|
* @type Point
|
||||||
|
*/
|
||||||
|
this.scale = new PIXI.Point(1,1);//{x:1, y:1};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rotation of the object in radians.
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.rotation = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The opacity of the object.
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.alpha = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The visibility of the object.
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.visible = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [read-only] The display object container that contains this display object.
|
||||||
|
* @type DisplayObjectContainer
|
||||||
|
*/
|
||||||
|
this.parent = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.
|
||||||
|
* @type #DisplayObjectContainer
|
||||||
|
*/
|
||||||
|
this.stage = null;
|
||||||
|
|
||||||
|
this.worldAlpha = 1;
|
||||||
|
this.color = [];
|
||||||
|
|
||||||
|
this.worldTransform = mat3.identity();
|
||||||
|
this.localTransform = mat3.identity();
|
||||||
|
|
||||||
|
this.dynamic = true;
|
||||||
|
// chach that puppy!
|
||||||
|
this._sr = 0;
|
||||||
|
this._cr = 1;
|
||||||
|
|
||||||
|
this.renderable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.DisplayObject.constructor = PIXI.DisplayObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.DisplayObject.prototype.updateTransform = function()
|
||||||
|
{
|
||||||
|
// TODO OPTIMIZE THIS!! with dirty
|
||||||
|
if(this.rotation != this.rotationCache)
|
||||||
|
{
|
||||||
|
this.rotationCach = this.rotation;
|
||||||
|
this._sr = Math.sin(this.rotation);
|
||||||
|
this._cr = Math.cos(this.rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.localTransform[0] = this._cr * this.scale.x;
|
||||||
|
this.localTransform[1] = -this._sr * this.scale.y
|
||||||
|
this.localTransform[3] = this._sr * this.scale.x;
|
||||||
|
this.localTransform[4] = this._cr * this.scale.y;
|
||||||
|
|
||||||
|
///AAARR GETTER SETTTER!
|
||||||
|
|
||||||
|
this.localTransform[2] = this.position.x;
|
||||||
|
this.localTransform[5] = this.position.y;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO optimize?
|
||||||
|
mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform);
|
||||||
|
this.worldAlpha = this.alpha * this.parent.worldAlpha;
|
||||||
|
}
|
137
src/pixi/DisplayObjectContainer.js
Normal file
137
src/pixi/DisplayObjectContainer.js
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class A DisplayObjectContainer represents a collection of display objects. It is the base class of all display objects that act as a container for other objects.
|
||||||
|
* @augments PIXI.DisplayObject
|
||||||
|
* @constructor
|
||||||
|
* @return A new DisplayObjectContainer.
|
||||||
|
*/
|
||||||
|
PIXI.DisplayObjectContainer = function()
|
||||||
|
{
|
||||||
|
PIXI.DisplayObject.call( this );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [read-only] The of children of this container.
|
||||||
|
* @type Array
|
||||||
|
*/
|
||||||
|
this.children = [];
|
||||||
|
|
||||||
|
this.renderable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.DisplayObjectContainer.constructor = PIXI.DisplayObjectContainer;
|
||||||
|
PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a child to the container.
|
||||||
|
* @param DisplayObject {@link PIXI.DisplayObject}
|
||||||
|
*/
|
||||||
|
PIXI.DisplayObjectContainer.prototype.addChild = function(child)
|
||||||
|
{
|
||||||
|
if(child.parent != undefined)
|
||||||
|
{
|
||||||
|
child.parent.removeChild(child)
|
||||||
|
}
|
||||||
|
|
||||||
|
child.parent = this;
|
||||||
|
child.childIndex = this.children.length;
|
||||||
|
|
||||||
|
this.children.push(child);
|
||||||
|
if(this.stage)
|
||||||
|
{
|
||||||
|
this.stage.__addChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
|
||||||
|
* @param DisplayObject {@link PIXI.DisplayObject}
|
||||||
|
* @param index
|
||||||
|
*/
|
||||||
|
PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
|
||||||
|
{
|
||||||
|
if(index >= 0 && index <= this.children.length)
|
||||||
|
{
|
||||||
|
if(child.parent != undefined)
|
||||||
|
{
|
||||||
|
child.parent.removeChild(child)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == this.children.length)
|
||||||
|
{
|
||||||
|
this.children.push(child);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.children.splice(index, 0, child);
|
||||||
|
}
|
||||||
|
|
||||||
|
child.parent = this;
|
||||||
|
child.childIndex = index;
|
||||||
|
|
||||||
|
var length = this.children.length;
|
||||||
|
for (var i=index; i < length; i++)
|
||||||
|
{
|
||||||
|
this.children[i].childIndex = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.stage)
|
||||||
|
{
|
||||||
|
this.stage.__addChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// error!
|
||||||
|
|
||||||
|
throw new Error(child + " The index supplied is out of bounds " + this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a child from the container.
|
||||||
|
* @param DisplayObject {@link PIXI.DisplayObject}
|
||||||
|
*/
|
||||||
|
PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
|
||||||
|
{
|
||||||
|
var index = this.children.indexOf( child );
|
||||||
|
|
||||||
|
if ( index !== -1 )
|
||||||
|
{
|
||||||
|
if(this.stage)this.stage.__removeChild(child);
|
||||||
|
child.parent = undefined;
|
||||||
|
//child.childIndex = 0
|
||||||
|
this.children.splice( index, 1 );
|
||||||
|
|
||||||
|
// update in dexs!
|
||||||
|
for(var i=index,j=this.children.length; i<j; i++)
|
||||||
|
{
|
||||||
|
this.children[i].childIndex -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.DisplayObjectContainer.prototype.updateTransform = function()
|
||||||
|
{
|
||||||
|
if(!this.visible)return;
|
||||||
|
|
||||||
|
PIXI.DisplayObject.prototype.updateTransform.call( this );
|
||||||
|
|
||||||
|
for(var i=0,j=this.children.length; i<j; i++)
|
||||||
|
{
|
||||||
|
this.children[i].updateTransform();
|
||||||
|
}
|
||||||
|
}
|
92
src/pixi/MovieClip.js
Normal file
92
src/pixi/MovieClip.js
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class A MovieClip is a simple way to display an animation depicted by a list of textures.
|
||||||
|
* @augments PIXI.Sprite
|
||||||
|
* @param an array of textures that make up the animation
|
||||||
|
* @return {PIXI.MovieClip} texture {@link PIXI.MovieClip}
|
||||||
|
*/
|
||||||
|
PIXI.MovieClip = function(textures)
|
||||||
|
{
|
||||||
|
PIXI.Sprite.call( this, textures[0]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The array of textures that make up the animation
|
||||||
|
* @type Array
|
||||||
|
*/
|
||||||
|
this.textures = textures;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [read only] The index MovieClips current frame (this may not have to be a whole number)
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.currentFrame = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The speed that the MovieClip will play at. Higher is faster, lower is slower
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.animationSpeed = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [read only] indicates if the MovieClip is currently playing
|
||||||
|
* @type Boolean
|
||||||
|
*/
|
||||||
|
this.playing;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.MovieClip.constructor = PIXI.MovieClip;
|
||||||
|
PIXI.MovieClip.prototype = Object.create( PIXI.Sprite.prototype );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the MovieClip
|
||||||
|
*/
|
||||||
|
PIXI.MovieClip.prototype.stop = function()
|
||||||
|
{
|
||||||
|
this.playing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plays the MovieClip
|
||||||
|
*/
|
||||||
|
PIXI.MovieClip.prototype.play = function()
|
||||||
|
{
|
||||||
|
this.playing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the MovieClip and goes to a specific frame
|
||||||
|
* @param frame index to stop at
|
||||||
|
*/
|
||||||
|
PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber)
|
||||||
|
{
|
||||||
|
this.playing = false;
|
||||||
|
this.currentFrame = frameNumber;
|
||||||
|
var round = (this.currentFrame + 0.5) | 0;
|
||||||
|
this.setTexture(this.textures[round % this.textures.length]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Goes to a specific frame and begins playing the MovieClip
|
||||||
|
* @param frame index to start at
|
||||||
|
*/
|
||||||
|
PIXI.MovieClip.prototype.gotoAndPlay = function(frameNumber)
|
||||||
|
{
|
||||||
|
this.currentFrame = frameNumber;
|
||||||
|
this.playing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.MovieClip.prototype.updateTransform = function()
|
||||||
|
{
|
||||||
|
PIXI.Sprite.prototype.updateTransform.call(this);
|
||||||
|
|
||||||
|
if(!this.playing)return;
|
||||||
|
|
||||||
|
this.currentFrame += this.animationSpeed;
|
||||||
|
var round = (this.currentFrame + 0.5) | 0;
|
||||||
|
this.setTexture(this.textures[round % this.textures.length]);
|
||||||
|
}
|
29
src/pixi/Point.js
Normal file
29
src/pixi/Point.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
|
||||||
|
* @constructor
|
||||||
|
* @param x position of the point
|
||||||
|
* @param y position of the point
|
||||||
|
* @return A new Rectangle.
|
||||||
|
*/
|
||||||
|
PIXI.Point = function(x, y)
|
||||||
|
{
|
||||||
|
this.x = x ? x : 0;
|
||||||
|
this.y = y ? y : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a copy of the point
|
||||||
|
*/
|
||||||
|
PIXI.Point.clone = function()
|
||||||
|
{
|
||||||
|
return new PIXI.Point(this.x, this.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.Point.constructor = PIXI.Point;
|
||||||
|
|
34
src/pixi/Rectangle.js
Normal file
34
src/pixi/Rectangle.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height.
|
||||||
|
* @constructor
|
||||||
|
* @param x position of the rectangle
|
||||||
|
* @param y position of the rectangle
|
||||||
|
* @param width of the rectangle
|
||||||
|
* @param height of the rectangle
|
||||||
|
* @return A new Rectangle.
|
||||||
|
*/
|
||||||
|
PIXI.Rectangle = function(x, y, width, height)
|
||||||
|
{
|
||||||
|
this.x = x ? x : 0;
|
||||||
|
this.y = y ? y : 0;
|
||||||
|
|
||||||
|
this.width = width ? width : 0;
|
||||||
|
this.height = height ? height : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a copy of the rectangle
|
||||||
|
*/
|
||||||
|
PIXI.Point.clone = function()
|
||||||
|
{
|
||||||
|
return new PIXI.Rectangle(this.x, this.y, this.width, this.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.Rectangle.constructor = PIXI.Rectangle;
|
||||||
|
|
132
src/pixi/Sprite.js
Normal file
132
src/pixi/Sprite.js
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
PIXI.blendModes = {};
|
||||||
|
PIXI.blendModes.NORMAL = 0;
|
||||||
|
PIXI.blendModes.SCREEN = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class A Sprite
|
||||||
|
* @augments PIXI.DisplayObjectContainer
|
||||||
|
* @constructor
|
||||||
|
* @param {PIXI.textures.Texture} texture {@link PIXI.textures.Texture}
|
||||||
|
* @return A new Sprite.
|
||||||
|
*/
|
||||||
|
PIXI.Sprite = function(texture)
|
||||||
|
{
|
||||||
|
PIXI.DisplayObjectContainer.call( this );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The anchor sets the origin point of the texture.
|
||||||
|
* The default is 0,0 this means the textures origin is the top left
|
||||||
|
* Setting than anchor to 0.5,0.5 means the textures origin is centered
|
||||||
|
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
|
||||||
|
* @type #Point
|
||||||
|
*/
|
||||||
|
this.anchor = new PIXI.Point();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The texture that the sprite is using
|
||||||
|
* @type #Point
|
||||||
|
*/
|
||||||
|
this.texture = texture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The blend mode of sprite.
|
||||||
|
* currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN
|
||||||
|
* @type uint
|
||||||
|
*/
|
||||||
|
this.blendMode = PIXI.blendModes.NORMAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The width of the sprite (this is initially set by the texture)
|
||||||
|
* @type #Number
|
||||||
|
*/
|
||||||
|
this.width = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The height of the sprite (this is initially set by the texture)
|
||||||
|
* @type #Number
|
||||||
|
*/
|
||||||
|
this.height = 1;
|
||||||
|
|
||||||
|
if(texture.baseTexture.hasLoaded)
|
||||||
|
{
|
||||||
|
this.width = this.texture.frame.width;
|
||||||
|
this.height = this.texture.frame.height;
|
||||||
|
this.updateFrame = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.onTextureUpdateBind = this.onTextureUpdate.bind(this);
|
||||||
|
this.texture.addEventListener( 'update', this.onTextureUpdateBind );
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.Sprite.constructor = PIXI.Sprite;
|
||||||
|
PIXI.Sprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The PIXI texture that is displayed by the sprite
|
||||||
|
* @param {PIXI.Texture} texture {@link PIXI.Texture}
|
||||||
|
*/
|
||||||
|
PIXI.Sprite.prototype.setTexture = function(texture)
|
||||||
|
{
|
||||||
|
// stop current texture;
|
||||||
|
if(this.texture.baseTexture != texture.baseTexture)
|
||||||
|
{
|
||||||
|
this.textureChange = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.texture = texture;
|
||||||
|
this.width = texture.frame.width;
|
||||||
|
this.height = texture.frame.height;
|
||||||
|
this.updateFrame = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.Sprite.prototype.onTextureUpdate = function(event)
|
||||||
|
{
|
||||||
|
this.width = this.texture.frame.width;
|
||||||
|
this.height = this.texture.frame.height;
|
||||||
|
this.updateFrame = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// some helper functions..
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Helper function that creates a sprite that will contain a texture from the TextureCache based on tjhe frameId
|
||||||
|
* The frame ids are created when a Texture packer file has been loaded
|
||||||
|
* @param The frame Id of the texture in the cache
|
||||||
|
* @return {PIXI.Sprite} texture {@link PIXI.Sprite}
|
||||||
|
*/
|
||||||
|
PIXI.Sprite.fromFrame = function(frameId)
|
||||||
|
{
|
||||||
|
var texture = PIXI.TextureCache[frameId];
|
||||||
|
if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache" + this);
|
||||||
|
return new PIXI.Sprite(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Helper function that creates a sprite that will contain a texture based on an image url
|
||||||
|
* If the image is not in the texture cache it will be loaded
|
||||||
|
* @param The image url of the texture
|
||||||
|
* @return {PIXI.Sprite} texture {@link PIXI.Sprite}
|
||||||
|
*/
|
||||||
|
PIXI.Sprite.fromImage = function(imageId)
|
||||||
|
{
|
||||||
|
var texture = PIXI.Texture.fromImage(imageId);
|
||||||
|
return new PIXI.Sprite(texture);
|
||||||
|
}
|
||||||
|
|
72
src/pixi/Stage.js
Normal file
72
src/pixi/Stage.js
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class A Stage represents the root of the display tree. Everything connected to the stage is rendered
|
||||||
|
* @augments PIXI.DisplayObjectContainer
|
||||||
|
* @constructor
|
||||||
|
* @return A new Stage.
|
||||||
|
*/
|
||||||
|
PIXI.Stage = function()
|
||||||
|
{
|
||||||
|
PIXI.DisplayObjectContainer.call( this );
|
||||||
|
this.worldTransform = mat3.identity();
|
||||||
|
this.__childrenAdded = [];
|
||||||
|
this.__childrenRemoved = [];
|
||||||
|
this.childIndex = 0;
|
||||||
|
this.stage= this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.Stage.constructor = PIXI.Stage;
|
||||||
|
|
||||||
|
PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
|
||||||
|
|
||||||
|
PIXI.Stage.prototype.updateTransform = function()
|
||||||
|
{
|
||||||
|
this.worldAlpha = 1;
|
||||||
|
|
||||||
|
for(var i=0,j=this.children.length; i<j; i++)
|
||||||
|
{
|
||||||
|
this.children[i].updateTransform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
PIXI.Stage.prototype.setFilter = function(filters)
|
||||||
|
{
|
||||||
|
this.filters = filters;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
PIXI.Stage.prototype.__addChild = function(child)
|
||||||
|
{
|
||||||
|
this.__childrenAdded.push(child);
|
||||||
|
|
||||||
|
child.stage = this;
|
||||||
|
|
||||||
|
if(child.children)
|
||||||
|
{
|
||||||
|
for (var i=0; i < child.children.length; i++)
|
||||||
|
{
|
||||||
|
this.__addChild(child.children[i]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.Stage.prototype.__removeChild = function(child)
|
||||||
|
{
|
||||||
|
this.__childrenRemoved.push(child);
|
||||||
|
|
||||||
|
child.stage = undefined;
|
||||||
|
|
||||||
|
if(child.children)
|
||||||
|
{
|
||||||
|
for(var i=0,j=child.children.length; i<j; i++)
|
||||||
|
{
|
||||||
|
this.__removeChild(child.children[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
176
src/pixi/extras/Rope.js
Normal file
176
src/pixi/extras/Rope.js
Normal file
|
@ -0,0 +1,176 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
|
||||||
|
PIXI.Rope = function(texture, points)
|
||||||
|
{
|
||||||
|
PIXI.Strip.call( this, texture );
|
||||||
|
this.points = points;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.verticies = new Float32Array( points.length * 4);
|
||||||
|
this.uvs = new Float32Array( points.length * 4);
|
||||||
|
this.colors = new Float32Array( points.length * 2);
|
||||||
|
this.indices = new Uint16Array( points.length * 2);
|
||||||
|
}
|
||||||
|
catch(error)
|
||||||
|
{
|
||||||
|
this.verticies = verticies
|
||||||
|
|
||||||
|
this.uvs = uvs
|
||||||
|
this.colors = colors
|
||||||
|
this.indices = indices
|
||||||
|
}
|
||||||
|
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.Rope.constructor = GAME.Rope;
|
||||||
|
PIXI.Rope.prototype = Object.create( PIXI.Strip.prototype );
|
||||||
|
|
||||||
|
PIXI.Rope.prototype.refresh = function()
|
||||||
|
{
|
||||||
|
var points = this.points;
|
||||||
|
if(points.length < 1)return;
|
||||||
|
|
||||||
|
var uvs = this.uvs
|
||||||
|
var indices = this.indices;
|
||||||
|
var colors = this.colors;
|
||||||
|
|
||||||
|
var lastPoint = points[0];
|
||||||
|
var nextPoint;
|
||||||
|
var perp = {x:0, y:0};
|
||||||
|
var point = points[0];
|
||||||
|
|
||||||
|
this.count-=0.2;
|
||||||
|
|
||||||
|
|
||||||
|
uvs[0] = 0
|
||||||
|
uvs[1] = 1
|
||||||
|
uvs[2] = 0
|
||||||
|
uvs[3] = 1
|
||||||
|
|
||||||
|
colors[0] = 1;
|
||||||
|
colors[1] = 1;
|
||||||
|
|
||||||
|
indices[0] = 0;
|
||||||
|
indices[1] = 1;
|
||||||
|
|
||||||
|
var total = points.length;
|
||||||
|
|
||||||
|
for (var i = 1; i < total; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
var point = points[i];
|
||||||
|
var index = i * 4;
|
||||||
|
// time to do some smart drawing!
|
||||||
|
var amount = i/(total-1)
|
||||||
|
|
||||||
|
if(i%2)
|
||||||
|
{
|
||||||
|
uvs[index] = amount;
|
||||||
|
uvs[index+1] = 0;
|
||||||
|
|
||||||
|
uvs[index+2] = amount
|
||||||
|
uvs[index+3] = 1
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uvs[index] = amount
|
||||||
|
uvs[index+1] = 0
|
||||||
|
|
||||||
|
uvs[index+2] = amount
|
||||||
|
uvs[index+3] = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
index = i * 2;
|
||||||
|
colors[index] = 1;
|
||||||
|
colors[index+1] = 1;
|
||||||
|
|
||||||
|
index = i * 2;
|
||||||
|
indices[index] = index;
|
||||||
|
indices[index + 1] = index + 1;
|
||||||
|
|
||||||
|
lastPoint = point;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.Rope.prototype.updateTransform = function()
|
||||||
|
{
|
||||||
|
|
||||||
|
var points = this.points;
|
||||||
|
if(points.length < 1)return;
|
||||||
|
|
||||||
|
var verticies = this.verticies
|
||||||
|
|
||||||
|
var lastPoint = points[0];
|
||||||
|
var nextPoint;
|
||||||
|
var perp = {x:0, y:0};
|
||||||
|
var point = points[0];
|
||||||
|
|
||||||
|
this.count-=0.2;
|
||||||
|
|
||||||
|
verticies[0] = point.x + perp.x
|
||||||
|
verticies[1] = point.y + perp.y //+ 200
|
||||||
|
verticies[2] = point.x - perp.x
|
||||||
|
verticies[3] = point.y - perp.y//+200
|
||||||
|
// time to do some smart drawing!
|
||||||
|
|
||||||
|
var total = points.length;
|
||||||
|
|
||||||
|
for (var i = 1; i < total; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
var point = points[i];
|
||||||
|
var index = i * 4;
|
||||||
|
|
||||||
|
if(i < points.length-1)
|
||||||
|
{
|
||||||
|
nextPoint = points[i+1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nextPoint = point
|
||||||
|
}
|
||||||
|
|
||||||
|
perp.y = -(nextPoint.x - lastPoint.x);
|
||||||
|
perp.x = nextPoint.y - lastPoint.y;
|
||||||
|
|
||||||
|
var ratio = (1 - (i / (total-1))) * 10;
|
||||||
|
if(ratio > 1)ratio = 1;
|
||||||
|
|
||||||
|
var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y);
|
||||||
|
var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio;
|
||||||
|
perp.x /= perpLength;
|
||||||
|
perp.y /= perpLength;
|
||||||
|
|
||||||
|
perp.x *= num;
|
||||||
|
perp.y *= num;
|
||||||
|
|
||||||
|
verticies[index] = point.x + perp.x
|
||||||
|
verticies[index+1] = point.y + perp.y
|
||||||
|
verticies[index+2] = point.x - perp.x
|
||||||
|
verticies[index+3] = point.y - perp.y
|
||||||
|
|
||||||
|
lastPoint = point;
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.DisplayObjectContainer.prototype.updateTransform.call( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.Rope.prototype.setTexture = function(texture)
|
||||||
|
{
|
||||||
|
// stop current texture
|
||||||
|
this.texture = texture;
|
||||||
|
this.updateFrame = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
91
src/pixi/extras/Strip.js
Normal file
91
src/pixi/extras/Strip.js
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
|
||||||
|
PIXI.Strip = function(texture, width, height)
|
||||||
|
{
|
||||||
|
PIXI.DisplayObjectContainer.call( this );
|
||||||
|
this.texture = texture;
|
||||||
|
this.blendMode = PIXI.blendModes.NORMAL;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.uvs = new Float32Array([0, 1,
|
||||||
|
1, 1,
|
||||||
|
1, 0, 0,1]);
|
||||||
|
|
||||||
|
this.verticies = new Float32Array([0, 0,
|
||||||
|
0,0,
|
||||||
|
0,0, 0,
|
||||||
|
0, 0]);
|
||||||
|
|
||||||
|
this.colors = new Float32Array([1, 1, 1, 1]);
|
||||||
|
|
||||||
|
this.indices = new Uint16Array([0, 1, 2, 3]);
|
||||||
|
}
|
||||||
|
catch(error)
|
||||||
|
{
|
||||||
|
this.uvs = [0, 1,
|
||||||
|
1, 1,
|
||||||
|
1, 0, 0,1];
|
||||||
|
|
||||||
|
this.verticies = [0, 0,
|
||||||
|
0,0,
|
||||||
|
0,0, 0,
|
||||||
|
0, 0];
|
||||||
|
|
||||||
|
this.colors = [1, 1, 1, 1];
|
||||||
|
|
||||||
|
this.indices = [0, 1, 2, 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
this.uvs = new Float32Array()
|
||||||
|
this.verticies = new Float32Array()
|
||||||
|
this.colors = new Float32Array()
|
||||||
|
this.indices = new Uint16Array()
|
||||||
|
*/
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
// load the texture!
|
||||||
|
if(texture.baseTexture.hasLoaded)
|
||||||
|
{
|
||||||
|
this.width = this.texture.frame.width;
|
||||||
|
this.height = this.texture.frame.height;
|
||||||
|
this.updateFrame = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.onTextureUpdateBind = this.onTextureUpdate.bind(this);
|
||||||
|
this.texture.addEventListener( 'update', this.onTextureUpdateBind );
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.Strip.constructor = PIXI.Strip;
|
||||||
|
PIXI.Strip.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
|
||||||
|
|
||||||
|
PIXI.Strip.prototype.setTexture = function(texture)
|
||||||
|
{
|
||||||
|
//TODO SET THE TEXTURES
|
||||||
|
//TODO VISIBILITY
|
||||||
|
|
||||||
|
// stop current texture
|
||||||
|
this.texture = texture;
|
||||||
|
this.width = texture.frame.width;
|
||||||
|
this.height = texture.frame.height;
|
||||||
|
this.updateFrame = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.Strip.prototype.onTextureUpdate = function(event)
|
||||||
|
{
|
||||||
|
this.updateFrame = true;
|
||||||
|
}
|
||||||
|
// some helper functions..
|
||||||
|
|
128
src/pixi/loaders/AssetLoader.js
Normal file
128
src/pixi/loaders/AssetLoader.js
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class A Class that loads a bunch of images / sprite sheet files. Once the assets have been loaded they are added to the PIXI Texture cache and can be accessed easily through PIXI.Texture.fromFrameId(), PIXI.Texture.fromImage() and PIXI.Sprite.fromImage(), PIXI.Sprite.fromFromeId()
|
||||||
|
* @augments PIXI.EventTarget
|
||||||
|
* When all items have been loaded this class will dispatch a 'loaded' event
|
||||||
|
* As each individual item is loaded this class will dispatch a 'progress' event
|
||||||
|
* @constructor
|
||||||
|
*
|
||||||
|
* @param an array of image/sprite sheet urls that you would like loaded supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported sprite sheet data formats only include "JSON" at this time
|
||||||
|
* @return A new AssetLoader
|
||||||
|
*/
|
||||||
|
PIXI.AssetLoader = function(assetURLs)
|
||||||
|
{
|
||||||
|
PIXI.EventTarget.call( this );
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The array of asset URLs that are going to be loaded
|
||||||
|
* @type Array
|
||||||
|
*/
|
||||||
|
this.assetURLs = assetURLs;
|
||||||
|
|
||||||
|
this.assets = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.AssetLoader.constructor = PIXI.AssetLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will begin loading the assets sequentially
|
||||||
|
*/
|
||||||
|
PIXI.AssetLoader.prototype.load = function()
|
||||||
|
{
|
||||||
|
this.loadCount = this.assetURLs.length;
|
||||||
|
var imageTypes = ["jpeg", "jpg", "png", "gif"];
|
||||||
|
|
||||||
|
var spriteSheetTypes = ["json"];
|
||||||
|
|
||||||
|
for (var i=0; i < this.assetURLs.length; i++)
|
||||||
|
{
|
||||||
|
var filename = this.assetURLs[i];
|
||||||
|
var fileType = filename.split('.').pop().toLowerCase();
|
||||||
|
// what are we loading?
|
||||||
|
var type;
|
||||||
|
|
||||||
|
for (var j=0; j < imageTypes.length; j++)
|
||||||
|
{
|
||||||
|
if(fileType == imageTypes[j])
|
||||||
|
{
|
||||||
|
type = "img";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!type)
|
||||||
|
{
|
||||||
|
for (var j=0; j < spriteSheetTypes.length; j++)
|
||||||
|
{
|
||||||
|
if(fileType == spriteSheetTypes[j])
|
||||||
|
{
|
||||||
|
type = "atlas";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type == "img")
|
||||||
|
{
|
||||||
|
var texture = PIXI.Texture.fromImage(filename);
|
||||||
|
if(!texture.hasLoaded)
|
||||||
|
{
|
||||||
|
|
||||||
|
var scope = this;
|
||||||
|
texture.baseTexture.addEventListener( 'loaded', function ( event )
|
||||||
|
{
|
||||||
|
scope.onAssetLoaded();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.assets.push(texture);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
// already loaded!
|
||||||
|
this.loadCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(type == "atlas")
|
||||||
|
{
|
||||||
|
var spriteSheetLoader = new PIXI.SpriteSheetLoader(filename);
|
||||||
|
this.assets.push(spriteSheetLoader);
|
||||||
|
|
||||||
|
var scope = this;
|
||||||
|
spriteSheetLoader.addEventListener( 'loaded', function ( event )
|
||||||
|
{
|
||||||
|
scope.onAssetLoaded();
|
||||||
|
});
|
||||||
|
|
||||||
|
spriteSheetLoader.load();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// dont know what the file is! :/
|
||||||
|
//this.loadCount--;
|
||||||
|
throw new Error(filename + " is an unsupported file type " + this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//this.assets[i].load();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.AssetLoader.prototype.onAssetLoaded = function()
|
||||||
|
{
|
||||||
|
this.loadCount--;
|
||||||
|
this.dispatchEvent( { type: 'progress', content: this } );
|
||||||
|
|
||||||
|
if(this.loadCount == 0)
|
||||||
|
{
|
||||||
|
this.dispatchEvent( { type: 'loaded', content: this } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
93
src/pixi/loaders/SpriteSheetLoader.js
Normal file
93
src/pixi/loaders/SpriteSheetLoader.js
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class The sprite sheet loader is used to load in JSON sprite sheet data
|
||||||
|
* To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format
|
||||||
|
* There is a free version so thats nice, although the paid version is great value for money.
|
||||||
|
* It is highly recommended to use Sprite sheets (also know as texture atlas') as it means sprite's can be batched and drawn together for highly increased rendering speed.
|
||||||
|
* Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId()
|
||||||
|
* This loader will also load the image file that the Spritesheet points to as well as the data.
|
||||||
|
* When loaded this class will dispatch a 'loaded' event
|
||||||
|
* @augments PIXI.EventTarget
|
||||||
|
* @constructor
|
||||||
|
* @param the url of the sprite sheet JSON file
|
||||||
|
* @return A new SpriteSheetLoader
|
||||||
|
*/
|
||||||
|
|
||||||
|
PIXI.SpriteSheetLoader = function(url)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* i use texture packer to load the assets..
|
||||||
|
* http://www.codeandweb.com/texturepacker
|
||||||
|
* make sure to set the format as "JSON"
|
||||||
|
*/
|
||||||
|
PIXI.EventTarget.call( this );
|
||||||
|
this.url = url;
|
||||||
|
this.baseUrl = url.replace(/[^\/]*$/, '');
|
||||||
|
this.texture;
|
||||||
|
this.frames = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will begin loading the JSON file
|
||||||
|
*/
|
||||||
|
PIXI.SpriteSheetLoader.prototype.load = function()
|
||||||
|
{
|
||||||
|
this.ajaxRequest = new AjaxRequest();
|
||||||
|
var scope = this;
|
||||||
|
this.ajaxRequest.onreadystatechange=function()
|
||||||
|
{
|
||||||
|
scope.onLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ajaxRequest.open("GET", this.url, true)
|
||||||
|
this.ajaxRequest.send(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.SpriteSheetLoader.prototype.onLoaded = function()
|
||||||
|
{
|
||||||
|
if (this.ajaxRequest.readyState==4)
|
||||||
|
{
|
||||||
|
if (this.ajaxRequest.status==200 || window.location.href.indexOf("http")==-1)
|
||||||
|
{
|
||||||
|
var jsondata = eval("("+this.ajaxRequest.responseText+")");
|
||||||
|
|
||||||
|
var textureUrl = this.baseUrl + jsondata.meta.image;
|
||||||
|
|
||||||
|
this.texture = PIXI.Texture.fromImage(textureUrl).baseTexture;
|
||||||
|
|
||||||
|
// if(!this.texture)this.texture = new PIXI.Texture(textureUrl);
|
||||||
|
|
||||||
|
var frameData = jsondata.frames;
|
||||||
|
for (var i in frameData)
|
||||||
|
{
|
||||||
|
var rect = frameData[i].frame;
|
||||||
|
// this.frames[i] = ;
|
||||||
|
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h})
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.texture.hasLoaded)
|
||||||
|
{
|
||||||
|
this.dispatchEvent( { type: 'loaded', content: this } );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var scope = this;
|
||||||
|
// wait for the texture to load..
|
||||||
|
this.texture.addEventListener('loaded', function(){
|
||||||
|
|
||||||
|
scope.dispatchEvent( { type: 'loaded', content: scope } );
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
253
src/pixi/renderers/CanvasRenderer.js
Normal file
253
src/pixi/renderers/CanvasRenderer.js
Normal file
|
@ -0,0 +1,253 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class the CanvasRenderer is draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL.
|
||||||
|
* Dont forget to add the view to your DOM or you will not see anything :)
|
||||||
|
* @param the width of the canvas view
|
||||||
|
* @param the height of the canvas view
|
||||||
|
* @return CanvasRenderer
|
||||||
|
*/
|
||||||
|
PIXI.CanvasRenderer = function(width, height)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The width of the canvas view
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.width = width ? width : 800;
|
||||||
|
/**
|
||||||
|
* The height of the canvas view
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.height = height ? height : 600;
|
||||||
|
|
||||||
|
this.refresh = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The canvas element that the everything is drawn to
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
this.view = document.createElement( 'canvas' );
|
||||||
|
|
||||||
|
this.view.width = this.width;
|
||||||
|
this.view.height = this.height;
|
||||||
|
this.view.background = "#FF0000";
|
||||||
|
this.count = 0;
|
||||||
|
this.context = this.view.getContext("2d");
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.CanvasRenderer.constructor = PIXI.CanvasRenderer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the stage to its canvas view
|
||||||
|
* @param the PIXI.Stage element to be rendered
|
||||||
|
*/
|
||||||
|
PIXI.CanvasRenderer.prototype.render = function(stage)
|
||||||
|
{
|
||||||
|
// update children if need be
|
||||||
|
|
||||||
|
stage.__childrenAdded = [];
|
||||||
|
stage.__childrenRemoved = [];
|
||||||
|
|
||||||
|
// update textures if need be
|
||||||
|
PIXI.texturesToUpdate = [];
|
||||||
|
|
||||||
|
|
||||||
|
this.context.setTransform(1,0,0,1,0,0);
|
||||||
|
stage.updateTransform();
|
||||||
|
|
||||||
|
this.context.setTransform(1,0,0,1,0,0);
|
||||||
|
this.context.clearRect(0, 0, this.width, this.height)
|
||||||
|
this.renderDisplayObject(stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resizes the canvas view to the specified width and height
|
||||||
|
* @param the new width of the canvas view
|
||||||
|
* @param the new height of the canvas view
|
||||||
|
*/
|
||||||
|
PIXI.CanvasRenderer.prototype.resize = function(width, height)
|
||||||
|
{
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
this.view.width = width;
|
||||||
|
this.view.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
|
||||||
|
{
|
||||||
|
var transform = displayObject.worldTransform;
|
||||||
|
var context = this.context;
|
||||||
|
context.globalCompositeOperation = "source-over"
|
||||||
|
var blit = false;
|
||||||
|
|
||||||
|
if(!displayObject.visible)return;
|
||||||
|
|
||||||
|
if(displayObject instanceof PIXI.Sprite)
|
||||||
|
{
|
||||||
|
var frame = displayObject.texture.frame;
|
||||||
|
|
||||||
|
if(frame)
|
||||||
|
{
|
||||||
|
context.globalAlpha = displayObject.worldAlpha;
|
||||||
|
|
||||||
|
// BLITZ!!!
|
||||||
|
/*
|
||||||
|
* if the rotation is 0 then we can blitz it
|
||||||
|
* meaning we dont need to do a transform and also we
|
||||||
|
* can round to the nearest round number for a little extra speed!
|
||||||
|
*/
|
||||||
|
if(displayObject.rotation == 0)
|
||||||
|
{
|
||||||
|
if(!blit)this.context.setTransform(1,0,0,1,0,0);
|
||||||
|
blit = true;
|
||||||
|
context.drawImage(displayObject.texture.baseTexture.image,
|
||||||
|
frame.x,
|
||||||
|
frame.y,
|
||||||
|
frame.width,
|
||||||
|
frame.height,
|
||||||
|
(transform[2]+displayObject.anchor.x * -frame.width + 0.5) | 0,
|
||||||
|
(transform[5]+displayObject.anchor.y * -frame.height + 0.5) | 0,
|
||||||
|
(frame.width * transform[0]),
|
||||||
|
(frame.height * transform[4]));
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
blit = false;
|
||||||
|
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
|
||||||
|
context.drawImage(displayObject.texture.baseTexture.image,
|
||||||
|
frame.x,
|
||||||
|
frame.y,
|
||||||
|
frame.width,
|
||||||
|
frame.height,
|
||||||
|
displayObject.anchor.x * -frame.width,
|
||||||
|
displayObject.anchor.y * -frame.height,
|
||||||
|
frame.width,
|
||||||
|
frame.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(displayObject instanceof PIXI.Strip)
|
||||||
|
{
|
||||||
|
context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5])
|
||||||
|
this.renderStrip(displayObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
// render!
|
||||||
|
for (var i=0; i < displayObject.children.length; i++)
|
||||||
|
{
|
||||||
|
this.renderDisplayObject(displayObject.children[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip)
|
||||||
|
{
|
||||||
|
var context = this.context;
|
||||||
|
var verticies = strip.verticies;
|
||||||
|
var uvs = strip.uvs;
|
||||||
|
|
||||||
|
var length = verticies.length/2;
|
||||||
|
this.count++;
|
||||||
|
|
||||||
|
context.beginPath();
|
||||||
|
for (var i=1; i < length-2; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
// draw some triangles!
|
||||||
|
var index = i*2;
|
||||||
|
|
||||||
|
var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4];
|
||||||
|
var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5];
|
||||||
|
|
||||||
|
context.moveTo(x0, y0);
|
||||||
|
context.lineTo(x1, y1);
|
||||||
|
context.lineTo(x2, y2);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// context.globalCompositeOperation = 'lighter';
|
||||||
|
context.fillStyle = "#FF0000";
|
||||||
|
context.fill();
|
||||||
|
context.closePath();
|
||||||
|
//context.globalCompositeOperation = 'source-over';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.CanvasRenderer.prototype.renderStrip = function(strip)
|
||||||
|
{
|
||||||
|
var context = this.context;
|
||||||
|
//context.globalCompositeOperation = 'lighter';
|
||||||
|
// draw triangles!!
|
||||||
|
var verticies = strip.verticies;
|
||||||
|
var uvs = strip.uvs;
|
||||||
|
|
||||||
|
var length = verticies.length/2;
|
||||||
|
this.count++;
|
||||||
|
for (var i=1; i < length-2; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
// draw some triangles!
|
||||||
|
var index = i*2;
|
||||||
|
|
||||||
|
var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4];
|
||||||
|
var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5];
|
||||||
|
|
||||||
|
var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2]* strip.texture.width, u2 = uvs[index+4]* strip.texture.width;
|
||||||
|
var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3]* strip.texture.height, v2 = uvs[index+5]* strip.texture.height;
|
||||||
|
|
||||||
|
|
||||||
|
context.save();
|
||||||
|
context.beginPath();
|
||||||
|
context.moveTo(x0, y0);
|
||||||
|
context.lineTo(x1, y1);
|
||||||
|
context.lineTo(x2, y2);
|
||||||
|
context.closePath();
|
||||||
|
|
||||||
|
// context.fillStyle = "white"//rgb(1, 1, 1,1));
|
||||||
|
// context.fill();
|
||||||
|
context.clip();
|
||||||
|
|
||||||
|
|
||||||
|
// Compute matrix transform
|
||||||
|
var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2;
|
||||||
|
var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2;
|
||||||
|
var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2;
|
||||||
|
var delta_c = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2;
|
||||||
|
var delta_d = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2;
|
||||||
|
var delta_e = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2;
|
||||||
|
var delta_f = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
context.transform(delta_a/delta, delta_d/delta,
|
||||||
|
delta_b/delta, delta_e/delta,
|
||||||
|
delta_c/delta, delta_f/delta);
|
||||||
|
|
||||||
|
context.drawImage(strip.texture.baseTexture.image, 0, 0);
|
||||||
|
context.restore();
|
||||||
|
};
|
||||||
|
|
||||||
|
// context.globalCompositeOperation = 'source-over';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
549
src/pixi/renderers/WebGLBatch.js
Normal file
549
src/pixi/renderers/WebGLBatch.js
Normal file
|
@ -0,0 +1,549 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
PIXI._batchs = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI._getBatch = function(gl)
|
||||||
|
{
|
||||||
|
if(PIXI._batchs.length == 0)
|
||||||
|
{
|
||||||
|
return new PIXI.WebGLBatch(gl);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return PIXI._batchs.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI._returnBatch = function(batch)
|
||||||
|
{
|
||||||
|
batch.clean();
|
||||||
|
PIXI._batchs.push(batch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI._restoreBatchs = function(gl)
|
||||||
|
{
|
||||||
|
for (var i=0; i < PIXI._batchs.length; i++)
|
||||||
|
{
|
||||||
|
PIXI._batchs[i].restoreLostContext(gl);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class A WebGLBatch Enables a group of sprites to be drawn using the same settings.
|
||||||
|
* if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster the webGL renderer will run.
|
||||||
|
* @augments PIXI.Sprite
|
||||||
|
* @param an instance of the webGL context
|
||||||
|
* @return {PIXI.renderers.WebGLBatch} WebGLBatch {@link PIXI.renderers.WebGLBatch}
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch = function(gl)
|
||||||
|
{
|
||||||
|
this.gl = gl;
|
||||||
|
|
||||||
|
this.size = 0;
|
||||||
|
|
||||||
|
this.vertexBuffer = gl.createBuffer();
|
||||||
|
this.indexBuffer = gl.createBuffer();
|
||||||
|
this.uvBuffer = gl.createBuffer();
|
||||||
|
this.colorBuffer = gl.createBuffer();
|
||||||
|
this.blendMode = PIXI.blendModes.NORMAL;
|
||||||
|
this.dynamicSize = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.WebGLBatch.constructor = PIXI.WebGLBatch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans the batch so that is can be returned to an object pool and reused
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.clean = function()
|
||||||
|
{
|
||||||
|
this.verticies = [];
|
||||||
|
this.uvs = [];
|
||||||
|
this.indices = [];
|
||||||
|
this.colors = [];
|
||||||
|
//this.sprites = [];
|
||||||
|
this.dynamicSize = 1;
|
||||||
|
this.texture = null;
|
||||||
|
this.last = null;
|
||||||
|
this.size = 0;
|
||||||
|
|
||||||
|
this.head;
|
||||||
|
this.tail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* recreates the buffers in the event of a context loss
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.restoreLostContext = function(gl)
|
||||||
|
{
|
||||||
|
this.gl = gl;
|
||||||
|
this.vertexBuffer = gl.createBuffer();
|
||||||
|
this.indexBuffer = gl.createBuffer();
|
||||||
|
this.uvBuffer = gl.createBuffer();
|
||||||
|
this.colorBuffer = gl.createBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inits the batch's texture and blend mode based if the supplied sprite
|
||||||
|
* @param the first sprite to be added to the batch. Only sprites with the same base texture and blend mode will be allowed to be added to this batch
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.init = function(sprite)
|
||||||
|
{
|
||||||
|
sprite.batch = this;
|
||||||
|
this.dirty = true;
|
||||||
|
this.blendMode = sprite.blendMode;
|
||||||
|
this.texture = sprite.texture.baseTexture;
|
||||||
|
// this.sprites.push(sprite);
|
||||||
|
this.head = sprite;
|
||||||
|
this.tail = sprite;
|
||||||
|
this.size = 1;
|
||||||
|
|
||||||
|
this.growBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inserts a sprite before the specified sprite
|
||||||
|
* @param the sprite to be added
|
||||||
|
* @param the first sprite will be inserted before this sprite
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite)
|
||||||
|
{
|
||||||
|
this.size++;
|
||||||
|
|
||||||
|
sprite.batch = this;
|
||||||
|
this.dirty = true;
|
||||||
|
var tempPrev = nextSprite.__prev;
|
||||||
|
nextSprite.__prev = sprite;
|
||||||
|
sprite.__next = nextSprite;
|
||||||
|
|
||||||
|
if(tempPrev)
|
||||||
|
{
|
||||||
|
sprite.__prev = tempPrev;
|
||||||
|
tempPrev.__next = sprite;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.head = sprite;
|
||||||
|
//this.head.__prev = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inserts a sprite after the specified sprite
|
||||||
|
* @param the sprite to be added
|
||||||
|
* @param the first sprite will be inserted after this sprite
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite)
|
||||||
|
{
|
||||||
|
this.size++;
|
||||||
|
|
||||||
|
|
||||||
|
sprite.batch = this;
|
||||||
|
this.dirty = true;
|
||||||
|
|
||||||
|
var tempNext = previousSprite.__next;
|
||||||
|
previousSprite.__next = sprite;
|
||||||
|
sprite.__prev = previousSprite;
|
||||||
|
|
||||||
|
if(tempNext)
|
||||||
|
{
|
||||||
|
sprite.__next = tempNext;
|
||||||
|
tempNext.__prev = sprite;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.tail = sprite
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes a sprite from the batch
|
||||||
|
* @param the sprite to be removed
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.remove = function(sprite)
|
||||||
|
{
|
||||||
|
this.size--;
|
||||||
|
|
||||||
|
if(this.size == 0)
|
||||||
|
{
|
||||||
|
sprite.__prev = null;
|
||||||
|
sprite.__next = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sprite.__prev)
|
||||||
|
{
|
||||||
|
sprite.__prev.__next = sprite.__next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.head = sprite.__next;
|
||||||
|
//this.head.__prev = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sprite.__next)
|
||||||
|
{
|
||||||
|
sprite.__next.__prev = sprite.__prev;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.tail = sprite.__prev;
|
||||||
|
//this.tail.__next = null
|
||||||
|
}
|
||||||
|
|
||||||
|
sprite.batch = null;
|
||||||
|
sprite.__next = null;
|
||||||
|
sprite.__prev = null;
|
||||||
|
this.dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the batch into two with the specified sprite being the start of the new batch.
|
||||||
|
* @param the sprite that indicates where the batch should be split
|
||||||
|
* @return the new batch
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.split = function(sprite)
|
||||||
|
{
|
||||||
|
|
||||||
|
//console.log("Splitting batch :" + this.size)
|
||||||
|
// console.log(sprite)
|
||||||
|
// console.log("-------")
|
||||||
|
this.dirty = true;
|
||||||
|
|
||||||
|
//var val = (this.tail == this.head)
|
||||||
|
//console.log(val + " SAME?");
|
||||||
|
var batch = new PIXI.WebGLBatch(this.gl)//PIXI._getBatch(this.gl);
|
||||||
|
batch.init(sprite);
|
||||||
|
batch.tail = this.tail;
|
||||||
|
//console.log("id is " +batcheee.id)
|
||||||
|
|
||||||
|
this.tail = sprite.__prev;
|
||||||
|
this.tail.__next = null;
|
||||||
|
|
||||||
|
sprite.__prev = null;
|
||||||
|
// return a splite batch!
|
||||||
|
//sprite.__prev.__next = null;
|
||||||
|
//sprite.__prev = null;
|
||||||
|
|
||||||
|
|
||||||
|
// TODO this size is wrong!
|
||||||
|
// need to recalculate :/ problem with a linked list!
|
||||||
|
// unless it gets calculated in the "clean"?
|
||||||
|
|
||||||
|
// need to loop through items as there is no way to know the length on a linked list :/
|
||||||
|
var tempSize = 0;
|
||||||
|
while(sprite)
|
||||||
|
{
|
||||||
|
tempSize++;
|
||||||
|
sprite.batch = batch;
|
||||||
|
sprite = sprite.__next;
|
||||||
|
}
|
||||||
|
|
||||||
|
batch.size = tempSize;
|
||||||
|
this.size -= tempSize;
|
||||||
|
|
||||||
|
return batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges two batchs together
|
||||||
|
* @param the batch that will be merged
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.merge = function(batch)
|
||||||
|
{
|
||||||
|
this.dirty = true;
|
||||||
|
|
||||||
|
this.tail.__next = batch.head;
|
||||||
|
batch.head.__prev = this.tail;
|
||||||
|
|
||||||
|
this.size += batch.size;
|
||||||
|
|
||||||
|
this.tail = batch.tail;
|
||||||
|
|
||||||
|
var sprite = batch.head;
|
||||||
|
while(sprite)
|
||||||
|
{
|
||||||
|
sprite.batch = this;
|
||||||
|
sprite = sprite.__next;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grows the size of the batch. As the elements in the batch cannot have a dynamic size this function is used to increase the size of the batch. It also creates a little extra room so that the batch does not need to be resized every time a sprite is added
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.growBatch = function()
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
if( this.size == 1)
|
||||||
|
{
|
||||||
|
this.dynamicSize = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.dynamicSize = this.size * 1.5
|
||||||
|
}
|
||||||
|
// grow verts
|
||||||
|
this.verticies = new Float32Array(this.dynamicSize * 8);
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
this.uvs = new Float32Array( this.dynamicSize * 8 )
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
this.dirtyUVS = true;
|
||||||
|
|
||||||
|
this.colors = new Float32Array( this.dynamicSize * 4 )
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
this.dirtyColors = true;
|
||||||
|
|
||||||
|
this.indices = new Uint16Array(this.dynamicSize * 6);
|
||||||
|
var length = this.indices.length/6;
|
||||||
|
|
||||||
|
for (var i=0; i < length; i++)
|
||||||
|
{
|
||||||
|
var index2 = i * 6;
|
||||||
|
var index3 = i * 4;
|
||||||
|
this.indices[index2 + 0] = index3 + 0;
|
||||||
|
this.indices[index2 + 1] = index3 + 1;
|
||||||
|
this.indices[index2 + 2] = index3 + 2;
|
||||||
|
this.indices[index2 + 3] = index3 + 0;
|
||||||
|
this.indices[index2 + 4] = index3 + 2;
|
||||||
|
this.indices[index2 + 5] = index3 + 3;
|
||||||
|
};
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||||
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh's all the data in the batch and sync's it with the webGL buffers
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.refresh = function()
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
|
||||||
|
if (this.dynamicSize < this.size)
|
||||||
|
{
|
||||||
|
this.growBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
var indexRun = 0;
|
||||||
|
var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index
|
||||||
|
var a, b, c, d, tx, ty
|
||||||
|
|
||||||
|
var displayObject = this.head
|
||||||
|
|
||||||
|
while(displayObject)
|
||||||
|
{
|
||||||
|
index = indexRun * 8;
|
||||||
|
|
||||||
|
var texture = displayObject.texture;
|
||||||
|
|
||||||
|
var frame = texture.frame;
|
||||||
|
var tw = texture.baseTexture.width;
|
||||||
|
var th = texture.baseTexture.height;
|
||||||
|
|
||||||
|
this.uvs[index + 0] = frame.x / tw;
|
||||||
|
this.uvs[index +1] = frame.y / th;
|
||||||
|
|
||||||
|
this.uvs[index +2] = (frame.x + frame.width) / tw;
|
||||||
|
this.uvs[index +3] = frame.y / th;
|
||||||
|
|
||||||
|
this.uvs[index +4] = (frame.x + frame.width) / tw;
|
||||||
|
this.uvs[index +5] = (frame.y + frame.height) / th;
|
||||||
|
|
||||||
|
this.uvs[index +6] = frame.x / tw;
|
||||||
|
this.uvs[index +7] = (frame.y + frame.height) / th;
|
||||||
|
|
||||||
|
displayObject.updateFrame = false;
|
||||||
|
|
||||||
|
colorIndex = indexRun * 4;
|
||||||
|
this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
|
||||||
|
|
||||||
|
displayObject = displayObject.__next;
|
||||||
|
|
||||||
|
indexRun ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dirtyUVS = true;
|
||||||
|
this.dirtyColors = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates all the relevant geometry and uploads the data to the GPU
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.update = function()
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3
|
||||||
|
|
||||||
|
var a, b, c, d, tx, ty;
|
||||||
|
|
||||||
|
var indexRun = 0;
|
||||||
|
|
||||||
|
var displayObject = this.head;
|
||||||
|
|
||||||
|
while(displayObject)
|
||||||
|
{
|
||||||
|
width = displayObject.width;
|
||||||
|
height = displayObject.height;
|
||||||
|
|
||||||
|
aX = displayObject.anchor.x;
|
||||||
|
aY = displayObject.anchor.y;
|
||||||
|
|
||||||
|
w0 = width * (1-aX);
|
||||||
|
w1 = width * -aX;
|
||||||
|
|
||||||
|
h0 = height * (1-aY);
|
||||||
|
h1 = height * -aY;
|
||||||
|
|
||||||
|
index = indexRun * 8;
|
||||||
|
|
||||||
|
worldTransform = displayObject.worldTransform;
|
||||||
|
|
||||||
|
a = worldTransform[0];
|
||||||
|
b = worldTransform[3];
|
||||||
|
c = worldTransform[1];
|
||||||
|
d = worldTransform[4];
|
||||||
|
tx = worldTransform[2];
|
||||||
|
ty = worldTransform[5];
|
||||||
|
|
||||||
|
this.verticies[index + 0 ] = a * w1 + c * h1 + tx;
|
||||||
|
this.verticies[index + 1 ] = d * h1 + b * w1 + ty;
|
||||||
|
|
||||||
|
this.verticies[index + 2 ] = a * w0 + c * h1 + tx;
|
||||||
|
this.verticies[index + 3 ] = d * h1 + b * w0 + ty;
|
||||||
|
|
||||||
|
this.verticies[index + 4 ] = a * w0 + c * h0 + tx;
|
||||||
|
this.verticies[index + 5 ] = d * h0 + b * w0 + ty;
|
||||||
|
|
||||||
|
this.verticies[index + 6] = a * w1 + c * h0 + tx;
|
||||||
|
this.verticies[index + 7] = d * h0 + b * w1 + ty;
|
||||||
|
|
||||||
|
if(displayObject.updateFrame)
|
||||||
|
{
|
||||||
|
this.dirtyUVS = true;
|
||||||
|
|
||||||
|
var texture = displayObject.texture;
|
||||||
|
|
||||||
|
var frame = texture.frame;
|
||||||
|
var tw = texture.baseTexture.width;
|
||||||
|
var th = texture.baseTexture.height;
|
||||||
|
|
||||||
|
this.uvs[index + 0] = frame.x / tw;
|
||||||
|
this.uvs[index +1] = frame.y / th;
|
||||||
|
|
||||||
|
this.uvs[index +2] = (frame.x + frame.width) / tw;
|
||||||
|
this.uvs[index +3] = frame.y / th;
|
||||||
|
|
||||||
|
this.uvs[index +4] = (frame.x + frame.width) / tw;
|
||||||
|
this.uvs[index +5] = (frame.y + frame.height) / th;
|
||||||
|
|
||||||
|
this.uvs[index +6] = frame.x / tw;
|
||||||
|
this.uvs[index +7] = (frame.y + frame.height) / th;
|
||||||
|
|
||||||
|
displayObject.updateFrame = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO this probably could do with some optimisation....
|
||||||
|
if(displayObject.cacheAlpha != displayObject.alpha)
|
||||||
|
{
|
||||||
|
displayObject.cacheAlpha = displayObject.alpha;
|
||||||
|
|
||||||
|
var colorIndex = indexRun * 4;
|
||||||
|
this.colors[index2] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
|
||||||
|
this.dirtyColors = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
indexRun++;
|
||||||
|
displayObject = displayObject.__next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the batch to the frame buffer
|
||||||
|
*/
|
||||||
|
PIXI.WebGLBatch.prototype.render = function()
|
||||||
|
{
|
||||||
|
if(this.dirty)
|
||||||
|
{
|
||||||
|
this.refresh();
|
||||||
|
this.dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.size == 0)return;
|
||||||
|
|
||||||
|
this.update();
|
||||||
|
var gl = this.gl;
|
||||||
|
|
||||||
|
//TODO optimize this!
|
||||||
|
if(this.blendMode == PIXI.blendModes.NORMAL)
|
||||||
|
{
|
||||||
|
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
var shaderProgram = PIXI.shaderProgram;
|
||||||
|
|
||||||
|
// update the verts..
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
|
||||||
|
// ok..
|
||||||
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies)
|
||||||
|
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
// update the uvs
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
|
||||||
|
|
||||||
|
if(this.dirtyUVS)
|
||||||
|
{
|
||||||
|
this.dirtyUVS = false;
|
||||||
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs);
|
||||||
|
}
|
||||||
|
|
||||||
|
gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
gl.activeTexture(gl.TEXTURE0);
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture);
|
||||||
|
|
||||||
|
// update color!
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer);
|
||||||
|
|
||||||
|
if(this.dirtyColors)
|
||||||
|
{
|
||||||
|
this.dirtyColors = false;
|
||||||
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors);
|
||||||
|
}
|
||||||
|
|
||||||
|
gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
// dont need to upload!
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
||||||
|
|
||||||
|
// DRAW THAT this!
|
||||||
|
gl.drawElements(gl.TRIANGLES, this.size * 6, gl.UNSIGNED_SHORT, 0);
|
||||||
|
}
|
||||||
|
|
690
src/pixi/renderers/WebGLRenderer.js
Normal file
690
src/pixi/renderers/WebGLRenderer.js
Normal file
|
@ -0,0 +1,690 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};§
|
||||||
|
|
||||||
|
PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. So no need for Sprite Batch's or Sprite Cloud's
|
||||||
|
* Dont forget to add the view to your DOM or you will not see anything :)
|
||||||
|
* @param the width of the canvas view
|
||||||
|
* @param the height of the canvas view
|
||||||
|
* @return WebGLRenderer
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer = function(width, height)
|
||||||
|
{
|
||||||
|
this.width = width ? width : 800;
|
||||||
|
this.height = height ? height : 600;
|
||||||
|
|
||||||
|
this.view = document.createElement( 'canvas' );
|
||||||
|
this.view.width = this.width;
|
||||||
|
this.view.height = this.height;
|
||||||
|
this.view.background = "#FF0000";
|
||||||
|
|
||||||
|
// deal with losing context..
|
||||||
|
var scope = this;
|
||||||
|
this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false)
|
||||||
|
this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false)
|
||||||
|
|
||||||
|
this.batchs = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.gl = this.view.getContext("experimental-webgl", {
|
||||||
|
alpha: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initShaders();
|
||||||
|
|
||||||
|
|
||||||
|
var gl = this.gl;
|
||||||
|
|
||||||
|
this.batch = new PIXI.WebGLBatch(gl);
|
||||||
|
gl.disable(gl.DEPTH_TEST);
|
||||||
|
gl.enable(gl.BLEND);
|
||||||
|
gl.colorMask(true, true, true, false);
|
||||||
|
|
||||||
|
this.projectionMatrix = mat4.create();
|
||||||
|
|
||||||
|
this.resize(this.width, this.height)
|
||||||
|
this.contextLost = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
PIXI.WebGLRenderer.constructor = PIXI.WebGLRenderer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.initShaders = function()
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
var fragmentShader = PIXI.CompileFragmentShader(gl, PIXI.shaderFragmentSrc);
|
||||||
|
var vertexShader = PIXI.CompileVertexShader(gl, PIXI.shaderVertexSrc);
|
||||||
|
|
||||||
|
this.shaderProgram = gl.createProgram();
|
||||||
|
|
||||||
|
var shaderProgram = this.shaderProgram;
|
||||||
|
|
||||||
|
gl.attachShader(shaderProgram, vertexShader);
|
||||||
|
gl.attachShader(shaderProgram, fragmentShader);
|
||||||
|
gl.linkProgram(shaderProgram);
|
||||||
|
|
||||||
|
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
|
||||||
|
alert("Could not initialise shaders");
|
||||||
|
}
|
||||||
|
|
||||||
|
gl.useProgram(shaderProgram);
|
||||||
|
|
||||||
|
shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
|
||||||
|
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
|
||||||
|
|
||||||
|
shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
|
||||||
|
gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
|
||||||
|
|
||||||
|
shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor");
|
||||||
|
gl.enableVertexAttribArray(shaderProgram.colorAttribute);
|
||||||
|
|
||||||
|
|
||||||
|
shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
|
||||||
|
shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler");
|
||||||
|
|
||||||
|
PIXI.shaderProgram = this.shaderProgram;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.checkVisibility = function(displayObject)
|
||||||
|
{
|
||||||
|
var children = displayObject.children;
|
||||||
|
|
||||||
|
for (var i=0; i < children.length; i++)
|
||||||
|
{
|
||||||
|
var child = children[i];
|
||||||
|
|
||||||
|
// TODO optimize... shouldt need to loop through everything all the time
|
||||||
|
// everything should have a batch!
|
||||||
|
// time to see whats new!
|
||||||
|
if(child.textureChange)
|
||||||
|
{
|
||||||
|
child.textureChange = false;
|
||||||
|
if(child.visible)
|
||||||
|
{
|
||||||
|
this.removeDisplayObject(child)
|
||||||
|
this.addDisplayObject(child)
|
||||||
|
}
|
||||||
|
// update texture!!
|
||||||
|
}
|
||||||
|
|
||||||
|
if(child.cacheVisible != child.visible)
|
||||||
|
{
|
||||||
|
child.cacheVisible = child.visible;
|
||||||
|
if(child.visible)
|
||||||
|
{
|
||||||
|
this.addDisplayObject(child);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.removeDisplayObject(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setGLVisible(child, child.visible);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(child.children.length > 0)
|
||||||
|
{
|
||||||
|
this.checkVisibility(child);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.setGLVisible = function(displayObject, visibility)
|
||||||
|
{
|
||||||
|
var children = displayObject.children;
|
||||||
|
|
||||||
|
for (var i=0; i < children.length; i++)
|
||||||
|
{
|
||||||
|
var child = children[i];
|
||||||
|
|
||||||
|
if(visibility)
|
||||||
|
{
|
||||||
|
this.addDisplayObject(child);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.removeDisplayObject(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(child.children.length > 0)
|
||||||
|
{
|
||||||
|
this.setGLVisible(child, visibility);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the stage to its webGL view
|
||||||
|
* @param the PIXI.Stage element to be rendered
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.render = function(stage)
|
||||||
|
{
|
||||||
|
if(this.contextLost)return;
|
||||||
|
|
||||||
|
// update children if need be
|
||||||
|
// best to remove first!
|
||||||
|
for (var i=0; i < stage.__childrenRemoved.length; i++) this.removeDisplayObject(stage.__childrenRemoved[i]);
|
||||||
|
// no add all new sprites
|
||||||
|
for (var i=0; i < stage.__childrenAdded.length; i++) this.addDisplayObject(stage.__childrenAdded[i]);
|
||||||
|
// update any textures
|
||||||
|
for (var i=0; i < PIXI.texturesToUpdate.length; i++) this.updateTexture(PIXI.texturesToUpdate[i]);
|
||||||
|
|
||||||
|
// empty out the arrays
|
||||||
|
stage.__childrenRemoved = [];
|
||||||
|
stage.__childrenAdded = [];
|
||||||
|
PIXI.texturesToUpdate = [];
|
||||||
|
|
||||||
|
// recursivly loop through all items!
|
||||||
|
this.checkVisibility(stage);
|
||||||
|
|
||||||
|
// update the scen graph
|
||||||
|
stage.updateTransform();
|
||||||
|
|
||||||
|
var gl = this.gl;
|
||||||
|
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT)
|
||||||
|
|
||||||
|
gl.clearColor(1, 1, 1, 1.0);
|
||||||
|
|
||||||
|
// set the correct blend mode!
|
||||||
|
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
||||||
|
gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix);
|
||||||
|
|
||||||
|
// render all the batchs!
|
||||||
|
|
||||||
|
|
||||||
|
var renderable;
|
||||||
|
for (var i=0; i < this.batchs.length; i++)
|
||||||
|
{
|
||||||
|
renderable = this.batchs[i];
|
||||||
|
if(renderable instanceof PIXI.WebGLBatch)
|
||||||
|
{
|
||||||
|
this.batchs[i].render();
|
||||||
|
}
|
||||||
|
else if(renderable instanceof PIXI.Strip)
|
||||||
|
{
|
||||||
|
if(renderable.visible)this.renderStrip(renderable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
|
||||||
|
if(!texture._glTexture)
|
||||||
|
{
|
||||||
|
texture._glTexture = gl.createTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(texture.hasLoaded)
|
||||||
|
{
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, texture._glTexture);
|
||||||
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
||||||
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.image);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||||
|
|
||||||
|
// gl.generateMipmap(gl.TEXTURE_2D);
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.refreshBatchs = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.addDisplayObject = function(displayObject)
|
||||||
|
{
|
||||||
|
if(!displayObject.stage)return;
|
||||||
|
|
||||||
|
displayObject.cacheVisible = displayObject.visible;
|
||||||
|
|
||||||
|
if(!displayObject.visible)return;
|
||||||
|
|
||||||
|
displayObject.batch = null;
|
||||||
|
|
||||||
|
//displayObject.cacheVisible = true;
|
||||||
|
if(!displayObject.renderable)return;
|
||||||
|
|
||||||
|
// while looping below THE OBJECT MAY NOT HAVE BEEN ADDED
|
||||||
|
displayObject.__inWebGL = true;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LOOK FOR THE PREVIOUS SPRITE
|
||||||
|
* This part looks for the closest previous sprite that can go into a batch
|
||||||
|
* It keeps going back until it finds a sprite or the stage
|
||||||
|
*/
|
||||||
|
var previousSprite = displayObject;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if(previousSprite.childIndex == 0)
|
||||||
|
{
|
||||||
|
previousSprite = previousSprite.parent;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
previousSprite = previousSprite.parent.children[previousSprite.childIndex-1];
|
||||||
|
// what if the bloop has children???
|
||||||
|
while(previousSprite.children.length != 0)
|
||||||
|
{
|
||||||
|
// keep diggin till we get to the last child
|
||||||
|
previousSprite = previousSprite.children[previousSprite.children.length-1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(previousSprite == displayObject.stage)break;
|
||||||
|
}
|
||||||
|
while(!previousSprite.renderable || !previousSprite.__inWebGL)
|
||||||
|
//while(!(previousSprite instanceof PIXI.Sprite))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LOOK FOR THE NEXT SPRITE
|
||||||
|
* This part looks for the closest next sprite that can go into a batch
|
||||||
|
* it keeps looking until it finds a sprite or gets to the end of the display
|
||||||
|
* scene graph
|
||||||
|
*
|
||||||
|
* These look a lot scarier than the actually are...
|
||||||
|
*/
|
||||||
|
var nextSprite = displayObject;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
// moving forward!
|
||||||
|
// if it has no children..
|
||||||
|
if(nextSprite.children.length == 0)
|
||||||
|
{
|
||||||
|
// go along to the parent..
|
||||||
|
while(nextSprite.childIndex == nextSprite.parent.children.length-1)
|
||||||
|
{
|
||||||
|
nextSprite = nextSprite.parent;
|
||||||
|
if(nextSprite == displayObject.stage)
|
||||||
|
{
|
||||||
|
nextSprite = null
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nextSprite)nextSprite = nextSprite.parent.children[nextSprite.childIndex+1];
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nextSprite = nextSprite.children[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!nextSprite)break;
|
||||||
|
}
|
||||||
|
while(!nextSprite.renderable || !nextSprite.__inWebGL)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* so now we have the next renderable and the previous renderable
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(displayObject instanceof PIXI.Sprite)
|
||||||
|
{
|
||||||
|
var previousBatch
|
||||||
|
var nextBatch
|
||||||
|
|
||||||
|
if(previousSprite instanceof PIXI.Sprite)
|
||||||
|
{
|
||||||
|
previousBatch = previousSprite.batch;
|
||||||
|
|
||||||
|
if(previousBatch)
|
||||||
|
{
|
||||||
|
if(previousBatch.texture == displayObject.texture.baseTexture && previousBatch.blendMode == displayObject.blendMode)
|
||||||
|
{
|
||||||
|
previousBatch.insertAfter(displayObject, previousSprite);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO reword!
|
||||||
|
previousBatch = previousSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nextSprite)
|
||||||
|
{
|
||||||
|
if(nextSprite instanceof PIXI.Sprite)
|
||||||
|
{
|
||||||
|
nextBatch = nextSprite.batch;
|
||||||
|
|
||||||
|
//batch may not exist if item was added to the display list but not to the webGL
|
||||||
|
if(nextBatch)
|
||||||
|
{
|
||||||
|
if(nextBatch.texture == displayObject.texture.baseTexture && nextBatch.blendMode == displayObject.blendMode)
|
||||||
|
{
|
||||||
|
nextBatch.insertBefore(displayObject, nextSprite);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(nextBatch == previousBatch)
|
||||||
|
{
|
||||||
|
// THERE IS A SPLIT IN THIS BATCH! //
|
||||||
|
var splitBatch = previousBatch.split(nextSprite);
|
||||||
|
// COOL!
|
||||||
|
// add it back into the array
|
||||||
|
/*
|
||||||
|
* OOPS!
|
||||||
|
* seems the new sprite is in the middle of a batch
|
||||||
|
* lets split it..
|
||||||
|
*/
|
||||||
|
var batch = PIXI._getBatch(this.gl);
|
||||||
|
|
||||||
|
var index = this.batchs.indexOf( previousBatch );
|
||||||
|
batch.init(displayObject);
|
||||||
|
this.batchs.splice(index+1, 0, batch, splitBatch);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO re-word!
|
||||||
|
nextBatch = nextSprite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* looks like it does not belong to any batch!
|
||||||
|
* but is also not intersecting one..
|
||||||
|
* time to create anew one!
|
||||||
|
*/
|
||||||
|
|
||||||
|
var batch = PIXI._getBatch(this.gl);
|
||||||
|
batch.init(displayObject);
|
||||||
|
|
||||||
|
if(previousBatch) // if this is invalid it means
|
||||||
|
{
|
||||||
|
var index = this.batchs.indexOf( previousBatch );
|
||||||
|
this.batchs.splice(index+1, 0, batch);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.batchs.push(batch);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(displayObject instanceof PIXI.Strip)
|
||||||
|
{
|
||||||
|
// add to a batch!!
|
||||||
|
this.initStrip(displayObject);
|
||||||
|
this.batchs.push(displayObject);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// if its somthing else... then custom codes!
|
||||||
|
this.batchUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.removeDisplayObject = function(displayObject)
|
||||||
|
{
|
||||||
|
//if(displayObject.stage)return;
|
||||||
|
displayObject.cacheVisible = displayObject.visible;
|
||||||
|
|
||||||
|
if(!displayObject.renderable)return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* removing is a lot quicker..
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
var batchToRemove;
|
||||||
|
|
||||||
|
if(displayObject instanceof PIXI.Sprite)
|
||||||
|
{
|
||||||
|
// should always have a batch!
|
||||||
|
var batch = displayObject.batch;
|
||||||
|
if(!batch)return; // thismeans the display list has been altered befre rendering
|
||||||
|
|
||||||
|
batch.remove(displayObject);
|
||||||
|
if(batch.size==0)
|
||||||
|
{
|
||||||
|
batchToRemove = batch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
batchToRemove = displayObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Looks like there is somthing that needs removing!
|
||||||
|
*/
|
||||||
|
if(batchToRemove)
|
||||||
|
{
|
||||||
|
var index = this.batchs.indexOf( batchToRemove );
|
||||||
|
if(index == -1)return;// this means it was added then removed before rendered
|
||||||
|
|
||||||
|
// ok so.. check to see if you adjacent batchs should be joined.
|
||||||
|
// TODO may optimise?
|
||||||
|
if(index == 0 || index == this.batchs.length-1)
|
||||||
|
{
|
||||||
|
// wha - eva! just get of the empty batch!
|
||||||
|
this.batchs.splice(index, 1);
|
||||||
|
if(batchToRemove instanceof PIXI.WebGLBatch)PIXI._returnBatch(batchToRemove);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.batchs[index-1] instanceof PIXI.WebGLBatch && this.batchs[index+1] instanceof PIXI.WebGLBatch)
|
||||||
|
{
|
||||||
|
if(this.batchs[index-1].texture == this.batchs[index+1].texture)
|
||||||
|
{
|
||||||
|
//console.log("MERGE")
|
||||||
|
this.batchs[index-1].merge(this.batchs[index+1]);
|
||||||
|
|
||||||
|
if(batchToRemove instanceof PIXI.WebGLBatch)PIXI._returnBatch(batchToRemove);
|
||||||
|
PIXI._returnBatch(this.batchs[index+1]);
|
||||||
|
this.batchs.splice(index, 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.batchs.splice(index, 1);
|
||||||
|
if(batchToRemove instanceof PIXI.WebGLBatch)PIXI._returnBatch(batchToRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resizes the webGL view to the specified width and height
|
||||||
|
* @param the new width of the webGL view
|
||||||
|
* @param the new height of the webGL view
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.resize = function(width, height)
|
||||||
|
{
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
this.view.width = width;
|
||||||
|
this.view.height = height;
|
||||||
|
|
||||||
|
this.gl.viewport(0, 0, this.width, this.height);
|
||||||
|
|
||||||
|
mat4.identity(this.projectionMatrix);
|
||||||
|
mat4.scale(this.projectionMatrix, [2/this.width, -2/this.height, 1]);
|
||||||
|
mat4.translate(this.projectionMatrix, [-this.width/2, -this.height/2, 0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.initStrip = function(strip)
|
||||||
|
{
|
||||||
|
// build the strip!
|
||||||
|
var gl = this.gl;
|
||||||
|
var shaderProgram = this.shaderProgram;
|
||||||
|
|
||||||
|
strip._vertexBuffer = gl.createBuffer();
|
||||||
|
strip._indexBuffer = gl.createBuffer();
|
||||||
|
strip._uvBuffer = gl.createBuffer();
|
||||||
|
strip._colorBuffer = gl.createBuffer();
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW);
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW);
|
||||||
|
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
|
||||||
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.renderStrip = function(strip)
|
||||||
|
{
|
||||||
|
var gl = this.gl;
|
||||||
|
var shaderProgram = this.shaderProgram;
|
||||||
|
// mat
|
||||||
|
var mat4Real = mat3.toMat4(strip.worldTransform);
|
||||||
|
mat4.transpose(mat4Real);
|
||||||
|
|
||||||
|
mat4.multiply(this.projectionMatrix, mat4Real, mat4Real )
|
||||||
|
|
||||||
|
gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, mat4Real);
|
||||||
|
|
||||||
|
if(strip.blendMode == PIXI.blendModes.NORMAL)
|
||||||
|
{
|
||||||
|
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!strip.dirty)
|
||||||
|
{
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
|
||||||
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies)
|
||||||
|
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
// update the uvs
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
|
||||||
|
gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
gl.activeTexture(gl.TEXTURE0);
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture);
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
|
||||||
|
gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
// dont need to upload!
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strip.dirty = false;
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW)
|
||||||
|
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
// update the uvs
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW)
|
||||||
|
gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
gl.activeTexture(gl.TEXTURE0);
|
||||||
|
gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture);
|
||||||
|
|
||||||
|
gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
|
||||||
|
gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW)
|
||||||
|
gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
|
||||||
|
|
||||||
|
// dont need to upload!
|
||||||
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
|
||||||
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0);
|
||||||
|
|
||||||
|
gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix);
|
||||||
|
|
||||||
|
// console.log("!!!")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.handleContextLost = function(event)
|
||||||
|
{
|
||||||
|
event.preventDefault();
|
||||||
|
this.contextLost = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
PIXI.WebGLRenderer.prototype.handleContextRestored = function(event)
|
||||||
|
{
|
||||||
|
this.gl = this.view.getContext("experimental-webgl", {
|
||||||
|
alpha: true
|
||||||
|
});
|
||||||
|
|
||||||
|
this.initShaders();
|
||||||
|
|
||||||
|
for (var i=0; i < PIXI.TextureCache.length; i++)
|
||||||
|
{
|
||||||
|
this.updateTexture(PIXI.TextureCache[i]);
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i=0; i < this.batchs.length; i++)
|
||||||
|
{
|
||||||
|
this.batchs[i].restoreLostContext(this.gl)//
|
||||||
|
this.batchs[i].dirty = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
PIXI._restoreBatchs(this.gl);
|
||||||
|
|
||||||
|
this.contextLost = false;
|
||||||
|
}
|
||||||
|
|
70
src/pixi/renderers/WebGLShaders.js
Normal file
70
src/pixi/renderers/WebGLShaders.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
PIXI.shaderFragmentSrc = [ "precision mediump float;",
|
||||||
|
"varying vec2 vTextureCoord;",
|
||||||
|
"varying float vColor;",
|
||||||
|
"uniform sampler2D uSampler;",
|
||||||
|
"void main(void) {",
|
||||||
|
"gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
|
||||||
|
"gl_FragColor = gl_FragColor * vColor;",
|
||||||
|
"}"];
|
||||||
|
|
||||||
|
PIXI.shaderVertexSrc = [ "attribute vec2 aVertexPosition;",
|
||||||
|
"attribute vec2 aTextureCoord;",
|
||||||
|
"attribute float aColor;",
|
||||||
|
"uniform mat4 uMVMatrix;",
|
||||||
|
"varying vec2 vTextureCoord;",
|
||||||
|
"varying float vColor;",
|
||||||
|
"void main(void) {",
|
||||||
|
"gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);",
|
||||||
|
"vTextureCoord = aTextureCoord;",
|
||||||
|
"vColor = aColor;",
|
||||||
|
"}"]
|
||||||
|
|
||||||
|
PIXI.CompileVertexShader = function(gl, shaderSrc)
|
||||||
|
{
|
||||||
|
var src = "";
|
||||||
|
|
||||||
|
for (var i=0; i < shaderSrc.length; i++) {
|
||||||
|
src += shaderSrc[i];
|
||||||
|
};
|
||||||
|
|
||||||
|
var shader;
|
||||||
|
shader = gl.createShader(gl.VERTEX_SHADER);
|
||||||
|
|
||||||
|
gl.shaderSource(shader, src);
|
||||||
|
gl.compileShader(shader);
|
||||||
|
|
||||||
|
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||||
|
alert(gl.getShaderInfoLog(shader));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.CompileFragmentShader = function(gl, shaderSrc)
|
||||||
|
{
|
||||||
|
var src = "";
|
||||||
|
|
||||||
|
for (var i=0; i < shaderSrc.length; i++) {
|
||||||
|
src += shaderSrc[i];
|
||||||
|
};
|
||||||
|
|
||||||
|
var shader;
|
||||||
|
shader = gl.createShader(gl.FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
gl.shaderSource(shader, src);
|
||||||
|
gl.compileShader(shader);
|
||||||
|
|
||||||
|
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||||
|
alert(gl.getShaderInfoLog(shader));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shader;
|
||||||
|
}
|
67
src/pixi/textures/BaseTexture.js
Normal file
67
src/pixi/textures/BaseTexture.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
PIXI.BaseTextureCache = {};
|
||||||
|
PIXI.texturesToUpdate = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class A texture stores the information that represents an image. All textures have a base texture
|
||||||
|
* @augments PIXI.EventTarget
|
||||||
|
* @constructor
|
||||||
|
* @param image url
|
||||||
|
* @return A new BaseTexture
|
||||||
|
*/
|
||||||
|
PIXI.BaseTexture = function(imageUrl)
|
||||||
|
{
|
||||||
|
PIXI.EventTarget.call( this );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The url of the texture
|
||||||
|
* @type #BaseTexture
|
||||||
|
*/
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The html image that is loaded to create the texture
|
||||||
|
* @type #BaseTexture
|
||||||
|
*/
|
||||||
|
this.image = new Image();
|
||||||
|
|
||||||
|
var scope = this
|
||||||
|
this.image.onload = function(){
|
||||||
|
|
||||||
|
scope.hasLoaded = true;
|
||||||
|
scope.width = scope.image.width;
|
||||||
|
scope.height = scope.image.height;
|
||||||
|
|
||||||
|
// add it to somewhere...
|
||||||
|
PIXI.texturesToUpdate.push(scope);
|
||||||
|
scope.dispatchEvent( { type: 'loaded', content: scope } );
|
||||||
|
}
|
||||||
|
|
||||||
|
$.proxy(this.onImageLoaded, this);
|
||||||
|
this.image.src = imageUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [read only] The width of the base texture set when the image has loaded
|
||||||
|
* @type #BaseTexture
|
||||||
|
*/
|
||||||
|
this.width = 100;
|
||||||
|
/**
|
||||||
|
* [read only] The height of the base texture set when the image has loaded
|
||||||
|
* @type #BaseTexture
|
||||||
|
*/
|
||||||
|
this.height = 100;
|
||||||
|
|
||||||
|
|
||||||
|
PIXI.BaseTextureCache[imageUrl] = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.BaseTexture.constructor = PIXI.BaseTexture;
|
||||||
|
/*
|
||||||
|
PIXI.BaseTexture.prototype.onImageLoaded = function(image)
|
||||||
|
{
|
||||||
|
|
||||||
|
}*/
|
141
src/pixi/textures/Texture.js
Normal file
141
src/pixi/textures/Texture.js
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
PIXI.TextureCache = {};
|
||||||
|
PIXI.FrameCache = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class A texture stores the information that represents an image or part of an image. It cannot be added to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used
|
||||||
|
* @augments PIXI.EventTarget
|
||||||
|
* @constructor
|
||||||
|
* @param {PIXI.textures.BaseTexture} base texture {@link PIXI.textures.BaseTexture}
|
||||||
|
* @param {PIXI.Rectangle} frame {@link PIXI.Rectangle}
|
||||||
|
* @return A new Texture.
|
||||||
|
*/
|
||||||
|
PIXI.Texture = function(baseTexture, frame)
|
||||||
|
{
|
||||||
|
PIXI.EventTarget.call( this );
|
||||||
|
|
||||||
|
if(!frame)
|
||||||
|
{
|
||||||
|
this.noFrame = true;
|
||||||
|
frame = new PIXI.Rectangle(0,0,1,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base texture of this texture
|
||||||
|
* @type #BaseTexture
|
||||||
|
*/
|
||||||
|
this.baseTexture = baseTexture;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The frame specifies the region of the base texture that this texture uses
|
||||||
|
* @type #Rectangle
|
||||||
|
*/
|
||||||
|
this.frame = frame;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
this.scope = this;
|
||||||
|
|
||||||
|
if(baseTexture.hasLoaded)
|
||||||
|
{
|
||||||
|
if(!frame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height);
|
||||||
|
this.setFrame(frame);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var scope = this;
|
||||||
|
baseTexture.addEventListener( 'loaded', function(){ scope.onBaseTextureLoaded()} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PIXI.Texture.constructor = PIXI.Texture;
|
||||||
|
|
||||||
|
PIXI.Texture.prototype.onBaseTextureLoaded = function(event)
|
||||||
|
{
|
||||||
|
var baseTexture = this.baseTexture;
|
||||||
|
baseTexture.removeEventListener( 'loaded', this.onLoaded );
|
||||||
|
|
||||||
|
if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height);
|
||||||
|
this.noFrame = false;
|
||||||
|
this.width = this.frame.width;
|
||||||
|
this.height = this.frame.height;
|
||||||
|
|
||||||
|
this.scope.dispatchEvent( { type: 'update', content: this } );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the rectangle region of the baseTexture
|
||||||
|
* @param {PIXI.Rectangle} frame {@link PIXI.Rectangle}
|
||||||
|
* @return A new Texture.
|
||||||
|
*/
|
||||||
|
PIXI.Texture.prototype.setFrame = function(frame)
|
||||||
|
{
|
||||||
|
this.frame = frame;
|
||||||
|
this.width = frame.width;
|
||||||
|
this.height = frame.height;
|
||||||
|
//this.updateFrame = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Helper function that returns a texture based on an image url
|
||||||
|
* If the image is not in the texture cache it will be created and loaded
|
||||||
|
* @param The image url of the texture
|
||||||
|
* @return {PIXI.textures.Texture} texture {@link PIXI.textures.Texture}
|
||||||
|
*/
|
||||||
|
PIXI.Texture.fromImage = function(imageUrl)
|
||||||
|
{
|
||||||
|
var texture = PIXI.TextureCache[imageUrl];
|
||||||
|
|
||||||
|
if(!texture)
|
||||||
|
{
|
||||||
|
var baseTexture = PIXI.BaseTextureCache[imageUrl];
|
||||||
|
if(!baseTexture) baseTexture = new PIXI.BaseTexture(imageUrl);
|
||||||
|
texture = new PIXI.Texture(baseTexture);
|
||||||
|
PIXI.TextureCache[imageUrl] = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Helper function that returns a texture based on a frame id
|
||||||
|
* If the frame id is not in the texture cache an error will be thrown
|
||||||
|
* @param The frame id of the texture
|
||||||
|
* @return {PIXI.textures.Texture} texture {@link PIXI.textures.Texture}
|
||||||
|
*/
|
||||||
|
PIXI.Texture.fromFrameId = function(frameId)
|
||||||
|
{
|
||||||
|
var texture = PIXI.TextureCache[frameId];
|
||||||
|
if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache" + this);
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Adds a texture to the textureCache.
|
||||||
|
* @param {PIXI.textures.Texture} texture {@link PIXI.textures.Texture}
|
||||||
|
* @param the id that the texture will be stored against.
|
||||||
|
*/
|
||||||
|
PIXI.Texture.addTextureToCache = function(texture, id)
|
||||||
|
{
|
||||||
|
PIXI.TextureCache[id] = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Remove a texture from the textureCache.
|
||||||
|
* @param the id of the texture to be removed
|
||||||
|
*/
|
||||||
|
PIXI.Texture.addTextureToCache = function(id)
|
||||||
|
{
|
||||||
|
PIXI.TextureCache[id] = texture;
|
||||||
|
}
|
||||||
|
|
30
src/pixi/utils/Detector.js
Normal file
30
src/pixi/utils/Detector.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* @author Mat Groves http://matgroves.com/
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This helper function will automatically detect which renderer you should be using.
|
||||||
|
* WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by the browser then this function will return a canvas renderer
|
||||||
|
* @param the width of the renderers view
|
||||||
|
* @param the height of the renderers view
|
||||||
|
* @return A new Renderer
|
||||||
|
*/
|
||||||
|
PIXI.autoDetectRenderer = function(width, height)
|
||||||
|
{
|
||||||
|
if(!width)width = 800;
|
||||||
|
if(!height)height = 600;
|
||||||
|
|
||||||
|
// BORROWED from Mr Doob (mrdoob.com)
|
||||||
|
var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )()
|
||||||
|
|
||||||
|
//console.log(webgl);
|
||||||
|
if( webgl )
|
||||||
|
{
|
||||||
|
return new PIXI.WebGLRenderer(width, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PIXI.CanvasRenderer(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
49
src/pixi/utils/EventTarget.js
Normal file
49
src/pixi/utils/EventTarget.js
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/**
|
||||||
|
* https://github.com/mrdoob/eventtarget.js/
|
||||||
|
* THankS mr DOob!
|
||||||
|
*/
|
||||||
|
var PIXI = PIXI || {};
|
||||||
|
|
||||||
|
PIXI.EventTarget = function () {
|
||||||
|
|
||||||
|
var listeners = {};
|
||||||
|
|
||||||
|
this.addEventListener = function ( type, listener ) {
|
||||||
|
|
||||||
|
|
||||||
|
if ( listeners[ type ] === undefined ) {
|
||||||
|
|
||||||
|
listeners[ type ] = [];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( listeners[ type ].indexOf( listener ) === - 1 ) {
|
||||||
|
|
||||||
|
listeners[ type ].push( listener );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.dispatchEvent = function ( event ) {
|
||||||
|
|
||||||
|
for ( var listener in listeners[ event.type ] ) {
|
||||||
|
|
||||||
|
listeners[ event.type ][ listener ]( event );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.removeEventListener = function ( type, listener ) {
|
||||||
|
|
||||||
|
var index = listeners[ type ].indexOf( listener );
|
||||||
|
|
||||||
|
if ( index !== - 1 ) {
|
||||||
|
|
||||||
|
listeners[ type ].splice( index, 1 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
46
src/pixi/utils/Utils.js
Normal file
46
src/pixi/utils/Utils.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* Provides requestAnimationFrame in a cross browser way.
|
||||||
|
*/
|
||||||
|
window.requestAnimFrame = (function() {
|
||||||
|
return window.requestAnimationFrame ||
|
||||||
|
window.webkitRequestAnimationFrame ||
|
||||||
|
window.mozRequestAnimationFrame ||
|
||||||
|
window.oRequestAnimationFrame ||
|
||||||
|
window.msRequestAnimationFrame ||
|
||||||
|
function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) {
|
||||||
|
window.setTimeout(callback, 1000/60);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
var AjaxRequest = function()
|
||||||
|
{
|
||||||
|
var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
|
||||||
|
|
||||||
|
if (window.ActiveXObject)
|
||||||
|
{ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
|
||||||
|
for (var i=0; i<activexmodes.length; i++)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
return new ActiveXObject(activexmodes[i])
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
//suppress error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
|
||||||
|
{
|
||||||
|
return new XMLHttpRequest()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
47
src/pixi/utils/gl-matrix-min.js
vendored
Normal file
47
src/pixi/utils/gl-matrix-min.js
vendored
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// gl-matrix 1.3.7 - https://github.com/toji/gl-matrix/blob/master/LICENSE.md
|
||||||
|
(function(w,D){"object"===typeof exports?module.exports=D(global):"function"===typeof define&&define.amd?define([],function(){return D(w)}):D(w)})(this,function(w){function D(a){return o=a}function G(){return o="undefined"!==typeof Float32Array?Float32Array:Array}var E={};(function(){if("undefined"!=typeof Float32Array){var a=new Float32Array(1),b=new Int32Array(a.buffer);E.invsqrt=function(c){a[0]=c;b[0]=1597463007-(b[0]>>1);var d=a[0];return d*(1.5-0.5*c*d*d)}}else E.invsqrt=function(a){return 1/
|
||||||
|
Math.sqrt(a)}})();var o=null;G();var r={create:function(a){var b=new o(3);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2]):b[0]=b[1]=b[2]=0;return b},createFrom:function(a,b,c){var d=new o(3);d[0]=a;d[1]=b;d[2]=c;return d},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];return b},equal:function(a,b){return a===b||1.0E-6>Math.abs(a[0]-b[0])&&1.0E-6>Math.abs(a[1]-b[1])&&1.0E-6>Math.abs(a[2]-b[2])},add:function(a,b,c){if(!c||a===c)return a[0]+=b[0],a[1]+=b[1],a[2]+=b[2],a;c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];
|
||||||
|
return c},subtract:function(a,b,c){if(!c||a===c)return a[0]-=b[0],a[1]-=b[1],a[2]-=b[2],a;c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];return c},multiply:function(a,b,c){if(!c||a===c)return a[0]*=b[0],a[1]*=b[1],a[2]*=b[2],a;c[0]=a[0]*b[0];c[1]=a[1]*b[1];c[2]=a[2]*b[2];return c},negate:function(a,b){b||(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];return b},scale:function(a,b,c){if(!c||a===c)return a[0]*=b,a[1]*=b,a[2]*=b,a;c[0]=a[0]*b;c[1]=a[1]*b;c[2]=a[2]*b;return c},normalize:function(a,b){b||(b=a);var c=
|
||||||
|
a[0],d=a[1],e=a[2],g=Math.sqrt(c*c+d*d+e*e);if(!g)return b[0]=0,b[1]=0,b[2]=0,b;if(1===g)return b[0]=c,b[1]=d,b[2]=e,b;g=1/g;b[0]=c*g;b[1]=d*g;b[2]=e*g;return b},cross:function(a,b,c){c||(c=a);var d=a[0],e=a[1],a=a[2],g=b[0],f=b[1],b=b[2];c[0]=e*b-a*f;c[1]=a*g-d*b;c[2]=d*f-e*g;return c},length:function(a){var b=a[0],c=a[1],a=a[2];return Math.sqrt(b*b+c*c+a*a)},squaredLength:function(a){var b=a[0],c=a[1],a=a[2];return b*b+c*c+a*a},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},direction:function(a,
|
||||||
|
b,c){c||(c=a);var d=a[0]-b[0],e=a[1]-b[1],a=a[2]-b[2],b=Math.sqrt(d*d+e*e+a*a);if(!b)return c[0]=0,c[1]=0,c[2]=0,c;b=1/b;c[0]=d*b;c[1]=e*b;c[2]=a*b;return c},lerp:function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);d[2]=a[2]+c*(b[2]-a[2]);return d},dist:function(a,b){var c=b[0]-a[0],d=b[1]-a[1],e=b[2]-a[2];return Math.sqrt(c*c+d*d+e*e)}},H=null,y=new o(4);r.unproject=function(a,b,c,d,e){e||(e=a);H||(H=x.create());var g=H;y[0]=2*(a[0]-d[0])/d[2]-1;y[1]=2*(a[1]-d[1])/d[3]-1;y[2]=
|
||||||
|
2*a[2]-1;y[3]=1;x.multiply(c,b,g);if(!x.inverse(g))return null;x.multiplyVec4(g,y);if(0===y[3])return null;e[0]=y[0]/y[3];e[1]=y[1]/y[3];e[2]=y[2]/y[3];return e};var L=r.createFrom(1,0,0),M=r.createFrom(0,1,0),N=r.createFrom(0,0,1),z=r.create();r.rotationTo=function(a,b,c){c||(c=k.create());var d=r.dot(a,b);if(1<=d)k.set(O,c);else if(-0.999999>d)r.cross(L,a,z),1.0E-6>r.length(z)&&r.cross(M,a,z),1.0E-6>r.length(z)&&r.cross(N,a,z),r.normalize(z),k.fromAngleAxis(Math.PI,z,c);else{var d=Math.sqrt(2*(1+
|
||||||
|
d)),e=1/d;r.cross(a,b,z);c[0]=z[0]*e;c[1]=z[1]*e;c[2]=z[2]*e;c[3]=0.5*d;k.normalize(c)}1<c[3]?c[3]=1:-1>c[3]&&(c[3]=-1);return c};r.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+"]"};var A={create:function(a){var b=new o(9);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8]):b[0]=b[1]=b[2]=b[3]=b[4]=b[5]=b[6]=b[7]=b[8]=0;return b},createFrom:function(a,b,c,d,e,g,f,h,j){var i=new o(9);i[0]=a;i[1]=b;i[2]=c;i[3]=d;i[4]=e;i[5]=g;i[6]=f;i[7]=h;i[8]=j;return i},
|
||||||
|
determinant:function(a){var b=a[3],c=a[4],d=a[5],e=a[6],g=a[7],f=a[8];return a[0]*(f*c-d*g)+a[1]*(-f*b+d*e)+a[2]*(g*b-c*e)},inverse:function(a,b){var c=a[0],d=a[1],e=a[2],g=a[3],f=a[4],h=a[5],j=a[6],i=a[7],m=a[8],l=m*f-h*i,C=-m*g+h*j,q=i*g-f*j,n=c*l+d*C+e*q;if(!n)return null;n=1/n;b||(b=A.create());b[0]=l*n;b[1]=(-m*d+e*i)*n;b[2]=(h*d-e*f)*n;b[3]=C*n;b[4]=(m*c-e*j)*n;b[5]=(-h*c+e*g)*n;b[6]=q*n;b[7]=(-i*c+d*j)*n;b[8]=(f*c-d*g)*n;return b},multiply:function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2],
|
||||||
|
f=a[3],h=a[4],j=a[5],i=a[6],m=a[7],a=a[8],l=b[0],C=b[1],q=b[2],n=b[3],k=b[4],p=b[5],o=b[6],s=b[7],b=b[8];c[0]=l*d+C*f+q*i;c[1]=l*e+C*h+q*m;c[2]=l*g+C*j+q*a;c[3]=n*d+k*f+p*i;c[4]=n*e+k*h+p*m;c[5]=n*g+k*j+p*a;c[6]=o*d+s*f+b*i;c[7]=o*e+s*h+b*m;c[8]=o*g+s*j+b*a;return c},multiplyVec2:function(a,b,c){c||(c=b);var d=b[0],b=b[1];c[0]=d*a[0]+b*a[3]+a[6];c[1]=d*a[1]+b*a[4]+a[7];return c},multiplyVec3:function(a,b,c){c||(c=b);var d=b[0],e=b[1],b=b[2];c[0]=d*a[0]+e*a[3]+b*a[6];c[1]=d*a[1]+e*a[4]+b*a[7];c[2]=
|
||||||
|
d*a[2]+e*a[5]+b*a[8];return c},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];return b},equal:function(a,b){return a===b||1.0E-6>Math.abs(a[0]-b[0])&&1.0E-6>Math.abs(a[1]-b[1])&&1.0E-6>Math.abs(a[2]-b[2])&&1.0E-6>Math.abs(a[3]-b[3])&&1.0E-6>Math.abs(a[4]-b[4])&&1.0E-6>Math.abs(a[5]-b[5])&&1.0E-6>Math.abs(a[6]-b[6])&&1.0E-6>Math.abs(a[7]-b[7])&&1.0E-6>Math.abs(a[8]-b[8])},identity:function(a){a||(a=A.create());a[0]=1;a[1]=0;a[2]=0;a[3]=0;
|
||||||
|
a[4]=1;a[5]=0;a[6]=0;a[7]=0;a[8]=1;return a},transpose:function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[5];a[1]=a[3];a[2]=a[6];a[3]=c;a[5]=a[7];a[6]=d;a[7]=e;return a}b[0]=a[0];b[1]=a[3];b[2]=a[6];b[3]=a[1];b[4]=a[4];b[5]=a[7];b[6]=a[2];b[7]=a[5];b[8]=a[8];return b},toMat4:function(a,b){b||(b=x.create());b[15]=1;b[14]=0;b[13]=0;b[12]=0;b[11]=0;b[10]=a[8];b[9]=a[7];b[8]=a[6];b[7]=0;b[6]=a[5];b[5]=a[4];b[4]=a[3];b[3]=0;b[2]=a[2];b[1]=a[1];b[0]=a[0];return b},str:function(a){return"["+a[0]+", "+a[1]+
|
||||||
|
", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+"]"}},x={create:function(a){var b=new o(16);a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]);return b},createFrom:function(a,b,c,d,e,g,f,h,j,i,m,l,C,q,n,k){var p=new o(16);p[0]=a;p[1]=b;p[2]=c;p[3]=d;p[4]=e;p[5]=g;p[6]=f;p[7]=h;p[8]=j;p[9]=i;p[10]=m;p[11]=l;p[12]=C;p[13]=q;p[14]=n;p[15]=k;return p},set:function(a,
|
||||||
|
b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];b[13]=a[13];b[14]=a[14];b[15]=a[15];return b},equal:function(a,b){return a===b||1.0E-6>Math.abs(a[0]-b[0])&&1.0E-6>Math.abs(a[1]-b[1])&&1.0E-6>Math.abs(a[2]-b[2])&&1.0E-6>Math.abs(a[3]-b[3])&&1.0E-6>Math.abs(a[4]-b[4])&&1.0E-6>Math.abs(a[5]-b[5])&&1.0E-6>Math.abs(a[6]-b[6])&&1.0E-6>Math.abs(a[7]-b[7])&&1.0E-6>Math.abs(a[8]-b[8])&&1.0E-6>Math.abs(a[9]-b[9])&&1.0E-6>
|
||||||
|
Math.abs(a[10]-b[10])&&1.0E-6>Math.abs(a[11]-b[11])&&1.0E-6>Math.abs(a[12]-b[12])&&1.0E-6>Math.abs(a[13]-b[13])&&1.0E-6>Math.abs(a[14]-b[14])&&1.0E-6>Math.abs(a[15]-b[15])},identity:function(a){a||(a=x.create());a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a},transpose:function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[3],g=a[6],f=a[7],h=a[11];a[1]=a[4];a[2]=a[8];a[3]=a[12];a[4]=c;a[6]=a[9];a[7]=a[13];a[8]=d;a[9]=g;a[11]=
|
||||||
|
a[14];a[12]=e;a[13]=f;a[14]=h;return a}b[0]=a[0];b[1]=a[4];b[2]=a[8];b[3]=a[12];b[4]=a[1];b[5]=a[5];b[6]=a[9];b[7]=a[13];b[8]=a[2];b[9]=a[6];b[10]=a[10];b[11]=a[14];b[12]=a[3];b[13]=a[7];b[14]=a[11];b[15]=a[15];return b},determinant:function(a){var b=a[0],c=a[1],d=a[2],e=a[3],g=a[4],f=a[5],h=a[6],j=a[7],i=a[8],m=a[9],l=a[10],C=a[11],q=a[12],n=a[13],k=a[14],a=a[15];return q*m*h*e-i*n*h*e-q*f*l*e+g*n*l*e+i*f*k*e-g*m*k*e-q*m*d*j+i*n*d*j+q*c*l*j-b*n*l*j-i*c*k*j+b*m*k*j+q*f*d*C-g*n*d*C-q*c*h*C+b*n*h*C+
|
||||||
|
g*c*k*C-b*f*k*C-i*f*d*a+g*m*d*a+i*c*h*a-b*m*h*a-g*c*l*a+b*f*l*a},inverse:function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=a[3],f=a[4],h=a[5],j=a[6],i=a[7],m=a[8],l=a[9],k=a[10],q=a[11],n=a[12],o=a[13],p=a[14],r=a[15],s=c*h-d*f,v=c*j-e*f,t=c*i-g*f,u=d*j-e*h,w=d*i-g*h,x=e*i-g*j,y=m*o-l*n,z=m*p-k*n,F=m*r-q*n,A=l*p-k*o,D=l*r-q*o,E=k*r-q*p,B=s*E-v*D+t*A+u*F-w*z+x*y;if(!B)return null;B=1/B;b[0]=(h*E-j*D+i*A)*B;b[1]=(-d*E+e*D-g*A)*B;b[2]=(o*x-p*w+r*u)*B;b[3]=(-l*x+k*w-q*u)*B;b[4]=(-f*E+j*F-i*z)*B;b[5]=
|
||||||
|
(c*E-e*F+g*z)*B;b[6]=(-n*x+p*t-r*v)*B;b[7]=(m*x-k*t+q*v)*B;b[8]=(f*D-h*F+i*y)*B;b[9]=(-c*D+d*F-g*y)*B;b[10]=(n*w-o*t+r*s)*B;b[11]=(-m*w+l*t-q*s)*B;b[12]=(-f*A+h*z-j*y)*B;b[13]=(c*A-d*z+e*y)*B;b[14]=(-n*u+o*v-p*s)*B;b[15]=(m*u-l*v+k*s)*B;return b},toRotationMat:function(a,b){b||(b=x.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b},toMat3:function(a,b){b||(b=A.create());b[0]=
|
||||||
|
a[0];b[1]=a[1];b[2]=a[2];b[3]=a[4];b[4]=a[5];b[5]=a[6];b[6]=a[8];b[7]=a[9];b[8]=a[10];return b},toInverseMat3:function(a,b){var c=a[0],d=a[1],e=a[2],g=a[4],f=a[5],h=a[6],j=a[8],i=a[9],m=a[10],l=m*f-h*i,k=-m*g+h*j,q=i*g-f*j,n=c*l+d*k+e*q;if(!n)return null;n=1/n;b||(b=A.create());b[0]=l*n;b[1]=(-m*d+e*i)*n;b[2]=(h*d-e*f)*n;b[3]=k*n;b[4]=(m*c-e*j)*n;b[5]=(-h*c+e*g)*n;b[6]=q*n;b[7]=(-i*c+d*j)*n;b[8]=(f*c-d*g)*n;return b},multiply:function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2],f=a[3],h=a[4],j=a[5],
|
||||||
|
i=a[6],m=a[7],l=a[8],k=a[9],q=a[10],n=a[11],o=a[12],p=a[13],r=a[14],a=a[15],s=b[0],v=b[1],t=b[2],u=b[3];c[0]=s*d+v*h+t*l+u*o;c[1]=s*e+v*j+t*k+u*p;c[2]=s*g+v*i+t*q+u*r;c[3]=s*f+v*m+t*n+u*a;s=b[4];v=b[5];t=b[6];u=b[7];c[4]=s*d+v*h+t*l+u*o;c[5]=s*e+v*j+t*k+u*p;c[6]=s*g+v*i+t*q+u*r;c[7]=s*f+v*m+t*n+u*a;s=b[8];v=b[9];t=b[10];u=b[11];c[8]=s*d+v*h+t*l+u*o;c[9]=s*e+v*j+t*k+u*p;c[10]=s*g+v*i+t*q+u*r;c[11]=s*f+v*m+t*n+u*a;s=b[12];v=b[13];t=b[14];u=b[15];c[12]=s*d+v*h+t*l+u*o;c[13]=s*e+v*j+t*k+u*p;c[14]=s*g+
|
||||||
|
v*i+t*q+u*r;c[15]=s*f+v*m+t*n+u*a;return c},multiplyVec3:function(a,b,c){c||(c=b);var d=b[0],e=b[1],b=b[2];c[0]=a[0]*d+a[4]*e+a[8]*b+a[12];c[1]=a[1]*d+a[5]*e+a[9]*b+a[13];c[2]=a[2]*d+a[6]*e+a[10]*b+a[14];return c},multiplyVec4:function(a,b,c){c||(c=b);var d=b[0],e=b[1],g=b[2],b=b[3];c[0]=a[0]*d+a[4]*e+a[8]*g+a[12]*b;c[1]=a[1]*d+a[5]*e+a[9]*g+a[13]*b;c[2]=a[2]*d+a[6]*e+a[10]*g+a[14]*b;c[3]=a[3]*d+a[7]*e+a[11]*g+a[15]*b;return c},translate:function(a,b,c){var d=b[0],e=b[1],b=b[2],g,f,h,j,i,m,l,k,q,
|
||||||
|
n,o,p;if(!c||a===c)return a[12]=a[0]*d+a[4]*e+a[8]*b+a[12],a[13]=a[1]*d+a[5]*e+a[9]*b+a[13],a[14]=a[2]*d+a[6]*e+a[10]*b+a[14],a[15]=a[3]*d+a[7]*e+a[11]*b+a[15],a;g=a[0];f=a[1];h=a[2];j=a[3];i=a[4];m=a[5];l=a[6];k=a[7];q=a[8];n=a[9];o=a[10];p=a[11];c[0]=g;c[1]=f;c[2]=h;c[3]=j;c[4]=i;c[5]=m;c[6]=l;c[7]=k;c[8]=q;c[9]=n;c[10]=o;c[11]=p;c[12]=g*d+i*e+q*b+a[12];c[13]=f*d+m*e+n*b+a[13];c[14]=h*d+l*e+o*b+a[14];c[15]=j*d+k*e+p*b+a[15];return c},scale:function(a,b,c){var d=b[0],e=b[1],b=b[2];if(!c||a===c)return a[0]*=
|
||||||
|
d,a[1]*=d,a[2]*=d,a[3]*=d,a[4]*=e,a[5]*=e,a[6]*=e,a[7]*=e,a[8]*=b,a[9]*=b,a[10]*=b,a[11]*=b,a;c[0]=a[0]*d;c[1]=a[1]*d;c[2]=a[2]*d;c[3]=a[3]*d;c[4]=a[4]*e;c[5]=a[5]*e;c[6]=a[6]*e;c[7]=a[7]*e;c[8]=a[8]*b;c[9]=a[9]*b;c[10]=a[10]*b;c[11]=a[11]*b;c[12]=a[12];c[13]=a[13];c[14]=a[14];c[15]=a[15];return c},rotate:function(a,b,c,d){var e=c[0],g=c[1],c=c[2],f=Math.sqrt(e*e+g*g+c*c),h,j,i,m,l,k,q,n,o,p,r,s,v,t,u,w,x,y,z,A;if(!f)return null;1!==f&&(f=1/f,e*=f,g*=f,c*=f);h=Math.sin(b);j=Math.cos(b);i=1-j;b=a[0];
|
||||||
|
f=a[1];m=a[2];l=a[3];k=a[4];q=a[5];n=a[6];o=a[7];p=a[8];r=a[9];s=a[10];v=a[11];t=e*e*i+j;u=g*e*i+c*h;w=c*e*i-g*h;x=e*g*i-c*h;y=g*g*i+j;z=c*g*i+e*h;A=e*c*i+g*h;e=g*c*i-e*h;g=c*c*i+j;d?a!==d&&(d[12]=a[12],d[13]=a[13],d[14]=a[14],d[15]=a[15]):d=a;d[0]=b*t+k*u+p*w;d[1]=f*t+q*u+r*w;d[2]=m*t+n*u+s*w;d[3]=l*t+o*u+v*w;d[4]=b*x+k*y+p*z;d[5]=f*x+q*y+r*z;d[6]=m*x+n*y+s*z;d[7]=l*x+o*y+v*z;d[8]=b*A+k*e+p*g;d[9]=f*A+q*e+r*g;d[10]=m*A+n*e+s*g;d[11]=l*A+o*e+v*g;return d},rotateX:function(a,b,c){var d=Math.sin(b),
|
||||||
|
b=Math.cos(b),e=a[4],g=a[5],f=a[6],h=a[7],j=a[8],i=a[9],m=a[10],l=a[11];c?a!==c&&(c[0]=a[0],c[1]=a[1],c[2]=a[2],c[3]=a[3],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a;c[4]=e*b+j*d;c[5]=g*b+i*d;c[6]=f*b+m*d;c[7]=h*b+l*d;c[8]=e*-d+j*b;c[9]=g*-d+i*b;c[10]=f*-d+m*b;c[11]=h*-d+l*b;return c},rotateY:function(a,b,c){var d=Math.sin(b),b=Math.cos(b),e=a[0],g=a[1],f=a[2],h=a[3],j=a[8],i=a[9],m=a[10],l=a[11];c?a!==c&&(c[4]=a[4],c[5]=a[5],c[6]=a[6],c[7]=a[7],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=
|
||||||
|
a[15]):c=a;c[0]=e*b+j*-d;c[1]=g*b+i*-d;c[2]=f*b+m*-d;c[3]=h*b+l*-d;c[8]=e*d+j*b;c[9]=g*d+i*b;c[10]=f*d+m*b;c[11]=h*d+l*b;return c},rotateZ:function(a,b,c){var d=Math.sin(b),b=Math.cos(b),e=a[0],g=a[1],f=a[2],h=a[3],j=a[4],i=a[5],m=a[6],l=a[7];c?a!==c&&(c[8]=a[8],c[9]=a[9],c[10]=a[10],c[11]=a[11],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a;c[0]=e*b+j*d;c[1]=g*b+i*d;c[2]=f*b+m*d;c[3]=h*b+l*d;c[4]=e*-d+j*b;c[5]=g*-d+i*b;c[6]=f*-d+m*b;c[7]=h*-d+l*b;return c},frustum:function(a,b,c,d,e,g,f){f||
|
||||||
|
(f=x.create());var h=b-a,j=d-c,i=g-e;f[0]=2*e/h;f[1]=0;f[2]=0;f[3]=0;f[4]=0;f[5]=2*e/j;f[6]=0;f[7]=0;f[8]=(b+a)/h;f[9]=(d+c)/j;f[10]=-(g+e)/i;f[11]=-1;f[12]=0;f[13]=0;f[14]=-(2*g*e)/i;f[15]=0;return f},perspective:function(a,b,c,d,e){a=c*Math.tan(a*Math.PI/360);b*=a;return x.frustum(-b,b,-a,a,c,d,e)},ortho:function(a,b,c,d,e,g,f){f||(f=x.create());var h=b-a,j=d-c,i=g-e;f[0]=2/h;f[1]=0;f[2]=0;f[3]=0;f[4]=0;f[5]=2/j;f[6]=0;f[7]=0;f[8]=0;f[9]=0;f[10]=-2/i;f[11]=0;f[12]=-(a+b)/h;f[13]=-(d+c)/j;f[14]=
|
||||||
|
-(g+e)/i;f[15]=1;return f},lookAt:function(a,b,c,d){d||(d=x.create());var e,g,f,h,j,i,m,l,k=a[0],o=a[1],a=a[2];f=c[0];h=c[1];g=c[2];m=b[0];c=b[1];e=b[2];if(k===m&&o===c&&a===e)return x.identity(d);b=k-m;c=o-c;m=a-e;l=1/Math.sqrt(b*b+c*c+m*m);b*=l;c*=l;m*=l;e=h*m-g*c;g=g*b-f*m;f=f*c-h*b;(l=Math.sqrt(e*e+g*g+f*f))?(l=1/l,e*=l,g*=l,f*=l):f=g=e=0;h=c*f-m*g;j=m*e-b*f;i=b*g-c*e;(l=Math.sqrt(h*h+j*j+i*i))?(l=1/l,h*=l,j*=l,i*=l):i=j=h=0;d[0]=e;d[1]=h;d[2]=b;d[3]=0;d[4]=g;d[5]=j;d[6]=c;d[7]=0;d[8]=f;d[9]=
|
||||||
|
i;d[10]=m;d[11]=0;d[12]=-(e*k+g*o+f*a);d[13]=-(h*k+j*o+i*a);d[14]=-(b*k+c*o+m*a);d[15]=1;return d},fromRotationTranslation:function(a,b,c){c||(c=x.create());var d=a[0],e=a[1],g=a[2],f=a[3],h=d+d,j=e+e,i=g+g,a=d*h,m=d*j,d=d*i,k=e*j,e=e*i,g=g*i,h=f*h,j=f*j,f=f*i;c[0]=1-(k+g);c[1]=m+f;c[2]=d-j;c[3]=0;c[4]=m-f;c[5]=1-(a+g);c[6]=e+h;c[7]=0;c[8]=d+j;c[9]=e-h;c[10]=1-(a+k);c[11]=0;c[12]=b[0];c[13]=b[1];c[14]=b[2];c[15]=1;return c},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+
|
||||||
|
a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+"]"}},k={create:function(a){var b=new o(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):b[0]=b[1]=b[2]=b[3]=0;return b},createFrom:function(a,b,c,d){var e=new o(4);e[0]=a;e[1]=b;e[2]=c;e[3]=d;return e},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1.0E-6>Math.abs(a[0]-b[0])&&1.0E-6>Math.abs(a[1]-b[1])&&1.0E-6>Math.abs(a[2]-b[2])&&1.0E-6>
|
||||||
|
Math.abs(a[3]-b[3])},identity:function(a){a||(a=k.create());a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a}},O=k.identity();k.calculateW=function(a,b){var c=a[0],d=a[1],e=a[2];if(!b||a===b)return a[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e)),a;b[0]=c;b[1]=d;b[2]=e;b[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e));return b};k.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]};k.inverse=function(a,b){var c=a[0],d=a[1],e=a[2],g=a[3],c=(c=c*c+d*d+e*e+g*g)?1/c:0;if(!b||a===b)return a[0]*=-c,a[1]*=-c,a[2]*=-c,a[3]*=
|
||||||
|
c,a;b[0]=-a[0]*c;b[1]=-a[1]*c;b[2]=-a[2]*c;b[3]=a[3]*c;return b};k.conjugate=function(a,b){if(!b||a===b)return a[0]*=-1,a[1]*=-1,a[2]*=-1,a;b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=a[3];return b};k.length=function(a){var b=a[0],c=a[1],d=a[2],a=a[3];return Math.sqrt(b*b+c*c+d*d+a*a)};k.normalize=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=a[3],f=Math.sqrt(c*c+d*d+e*e+g*g);if(0===f)return b[0]=0,b[1]=0,b[2]=0,b[3]=0,b;f=1/f;b[0]=c*f;b[1]=d*f;b[2]=e*f;b[3]=g*f;return b};k.add=function(a,b,c){if(!c||
|
||||||
|
a===c)return a[0]+=b[0],a[1]+=b[1],a[2]+=b[2],a[3]+=b[3],a;c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];c[3]=a[3]+b[3];return c};k.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2],a=a[3],f=b[0],h=b[1],j=b[2],b=b[3];c[0]=d*b+a*f+e*j-g*h;c[1]=e*b+a*h+g*f-d*j;c[2]=g*b+a*j+d*h-e*f;c[3]=a*b-d*f-e*h-g*j;return c};k.multiplyVec3=function(a,b,c){c||(c=b);var d=b[0],e=b[1],g=b[2],b=a[0],f=a[1],h=a[2],a=a[3],j=a*d+f*g-h*e,i=a*e+h*d-b*g,k=a*g+b*e-f*d,d=-b*d-f*e-h*g;c[0]=j*a+d*-b+i*-h-k*-f;c[1]=i*a+
|
||||||
|
d*-f+k*-b-j*-h;c[2]=k*a+d*-h+j*-f-i*-b;return c};k.scale=function(a,b,c){if(!c||a===c)return a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b,a;c[0]=a[0]*b;c[1]=a[1]*b;c[2]=a[2]*b;c[3]=a[3]*b;return c};k.toMat3=function(a,b){b||(b=A.create());var c=a[0],d=a[1],e=a[2],g=a[3],f=c+c,h=d+d,j=e+e,i=c*f,k=c*h,c=c*j,l=d*h,d=d*j,e=e*j,f=g*f,h=g*h,g=g*j;b[0]=1-(l+e);b[1]=k+g;b[2]=c-h;b[3]=k-g;b[4]=1-(i+e);b[5]=d+f;b[6]=c+h;b[7]=d-f;b[8]=1-(i+l);return b};k.toMat4=function(a,b){b||(b=x.create());var c=a[0],d=a[1],e=a[2],g=
|
||||||
|
a[3],f=c+c,h=d+d,j=e+e,i=c*f,k=c*h,c=c*j,l=d*h,d=d*j,e=e*j,f=g*f,h=g*h,g=g*j;b[0]=1-(l+e);b[1]=k+g;b[2]=c-h;b[3]=0;b[4]=k-g;b[5]=1-(i+e);b[6]=d+f;b[7]=0;b[8]=c+h;b[9]=d-f;b[10]=1-(i+l);b[11]=0;b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};k.slerp=function(a,b,c,d){d||(d=a);var e=a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3],g,f;if(1<=Math.abs(e))return d!==a&&(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[3]),d;g=Math.acos(e);f=Math.sqrt(1-e*e);if(0.001>Math.abs(f))return d[0]=0.5*a[0]+0.5*b[0],d[1]=0.5*a[1]+0.5*b[1],
|
||||||
|
d[2]=0.5*a[2]+0.5*b[2],d[3]=0.5*a[3]+0.5*b[3],d;e=Math.sin((1-c)*g)/f;c=Math.sin(c*g)/f;d[0]=a[0]*e+b[0]*c;d[1]=a[1]*e+b[1]*c;d[2]=a[2]*e+b[2]*c;d[3]=a[3]*e+b[3]*c;return d};k.fromRotationMatrix=function(a,b){b||(b=k.create());var c=a[0]+a[4]+a[8],d;if(0<c)d=Math.sqrt(c+1),b[3]=0.5*d,d=0.5/d,b[0]=(a[7]-a[5])*d,b[1]=(a[2]-a[6])*d,b[2]=(a[3]-a[1])*d;else{d=k.fromRotationMatrix.s_iNext=k.fromRotationMatrix.s_iNext||[1,2,0];c=0;a[4]>a[0]&&(c=1);a[8]>a[3*c+c]&&(c=2);var e=d[c],g=d[e];d=Math.sqrt(a[3*c+
|
||||||
|
c]-a[3*e+e]-a[3*g+g]+1);b[c]=0.5*d;d=0.5/d;b[3]=(a[3*g+e]-a[3*e+g])*d;b[e]=(a[3*e+c]+a[3*c+e])*d;b[g]=(a[3*g+c]+a[3*c+g])*d}return b};A.toQuat4=k.fromRotationMatrix;(function(){var a=A.create();k.fromAxes=function(b,c,d,e){a[0]=c[0];a[3]=c[1];a[6]=c[2];a[1]=d[0];a[4]=d[1];a[7]=d[2];a[2]=b[0];a[5]=b[1];a[8]=b[2];return k.fromRotationMatrix(a,e)}})();k.identity=function(a){a||(a=k.create());a[0]=0;a[1]=0;a[2]=0;a[3]=1;return a};k.fromAngleAxis=function(a,b,c){c||(c=k.create());var a=0.5*a,d=Math.sin(a);
|
||||||
|
c[3]=Math.cos(a);c[0]=d*b[0];c[1]=d*b[1];c[2]=d*b[2];return c};k.toAngleAxis=function(a,b){b||(b=a);var c=a[0]*a[0]+a[1]*a[1]+a[2]*a[2];0<c?(b[3]=2*Math.acos(a[3]),c=E.invsqrt(c),b[0]=a[0]*c,b[1]=a[1]*c,b[2]=a[2]*c):(b[3]=0,b[0]=1,b[1]=0,b[2]=0);return b};k.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"};var J={create:function(a){var b=new o(2);a?(b[0]=a[0],b[1]=a[1]):(b[0]=0,b[1]=0);return b},createFrom:function(a,b){var c=new o(2);c[0]=a;c[1]=b;return c},add:function(a,b,c){c||
|
||||||
|
(c=b);c[0]=a[0]+b[0];c[1]=a[1]+b[1];return c},subtract:function(a,b,c){c||(c=b);c[0]=a[0]-b[0];c[1]=a[1]-b[1];return c},multiply:function(a,b,c){c||(c=b);c[0]=a[0]*b[0];c[1]=a[1]*b[1];return c},divide:function(a,b,c){c||(c=b);c[0]=a[0]/b[0];c[1]=a[1]/b[1];return c},scale:function(a,b,c){c||(c=a);c[0]=a[0]*b;c[1]=a[1]*b;return c},dist:function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return Math.sqrt(c*c+d*d)},set:function(a,b){b[0]=a[0];b[1]=a[1];return b},equal:function(a,b){return a===b||1.0E-6>Math.abs(a[0]-
|
||||||
|
b[0])&&1.0E-6>Math.abs(a[1]-b[1])},negate:function(a,b){b||(b=a);b[0]=-a[0];b[1]=-a[1];return b},normalize:function(a,b){b||(b=a);var c=a[0]*a[0]+a[1]*a[1];0<c?(c=Math.sqrt(c),b[0]=a[0]/c,b[1]=a[1]/c):b[0]=b[1]=0;return b},cross:function(a,b,c){a=a[0]*b[1]-a[1]*b[0];if(!c)return a;c[0]=c[1]=0;c[2]=a;return c},length:function(a){var b=a[0],a=a[1];return Math.sqrt(b*b+a*a)},squaredLength:function(a){var b=a[0],a=a[1];return b*b+a*a},dot:function(a,b){return a[0]*b[0]+a[1]*b[1]},direction:function(a,
|
||||||
|
b,c){c||(c=a);var d=a[0]-b[0],a=a[1]-b[1],b=d*d+a*a;if(!b)return c[0]=0,c[1]=0,c[2]=0,c;b=1/Math.sqrt(b);c[0]=d*b;c[1]=a*b;return c},lerp:function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);return d},str:function(a){return"["+a[0]+", "+a[1]+"]"}},I={create:function(a){var b=new o(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):b[0]=b[1]=b[2]=b[3]=0;return b},createFrom:function(a,b,c,d){var e=new o(4);e[0]=a;e[1]=b;e[2]=c;e[3]=d;return e},set:function(a,b){b[0]=a[0];b[1]=a[1];
|
||||||
|
b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1.0E-6>Math.abs(a[0]-b[0])&&1.0E-6>Math.abs(a[1]-b[1])&&1.0E-6>Math.abs(a[2]-b[2])&&1.0E-6>Math.abs(a[3]-b[3])},identity:function(a){a||(a=I.create());a[0]=1;a[1]=0;a[2]=0;a[3]=1;return a},transpose:function(a,b){if(!b||a===b){var c=a[1];a[1]=a[2];a[2]=c;return a}b[0]=a[0];b[1]=a[2];b[2]=a[1];b[3]=a[3];return b},determinant:function(a){return a[0]*a[3]-a[2]*a[1]},inverse:function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=a[3],f=c*g-e*
|
||||||
|
d;if(!f)return null;f=1/f;b[0]=g*f;b[1]=-d*f;b[2]=-e*f;b[3]=c*f;return b},multiply:function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2],a=a[3];c[0]=d*b[0]+e*b[2];c[1]=d*b[1]+e*b[3];c[2]=g*b[0]+a*b[2];c[3]=g*b[1]+a*b[3];return c},rotate:function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2],a=a[3],f=Math.sin(b),b=Math.cos(b);c[0]=d*b+e*f;c[1]=d*-f+e*b;c[2]=g*b+a*f;c[3]=g*-f+a*b;return c},multiplyVec2:function(a,b,c){c||(c=b);var d=b[0],b=b[1];c[0]=d*a[0]+b*a[1];c[1]=d*a[2]+b*a[3];return c},scale:function(a,
|
||||||
|
b,c){c||(c=a);var d=a[1],e=a[2],g=a[3],f=b[0],b=b[1];c[0]=a[0]*f;c[1]=d*b;c[2]=e*f;c[3]=g*b;return c},str:function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"}},K={create:function(a){var b=new o(4);a?(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]):(b[0]=0,b[1]=0,b[2]=0,b[3]=0);return b},createFrom:function(a,b,c,d){var e=new o(4);e[0]=a;e[1]=b;e[2]=c;e[3]=d;return e},add:function(a,b,c){c||(c=b);c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];c[3]=a[3]+b[3];return c},subtract:function(a,b,c){c||(c=
|
||||||
|
b);c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];c[3]=a[3]-b[3];return c},multiply:function(a,b,c){c||(c=b);c[0]=a[0]*b[0];c[1]=a[1]*b[1];c[2]=a[2]*b[2];c[3]=a[3]*b[3];return c},divide:function(a,b,c){c||(c=b);c[0]=a[0]/b[0];c[1]=a[1]/b[1];c[2]=a[2]/b[2];c[3]=a[3]/b[3];return c},scale:function(a,b,c){c||(c=a);c[0]=a[0]*b;c[1]=a[1]*b;c[2]=a[2]*b;c[3]=a[3]*b;return c},set:function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b},equal:function(a,b){return a===b||1.0E-6>Math.abs(a[0]-b[0])&&1.0E-6>
|
||||||
|
Math.abs(a[1]-b[1])&&1.0E-6>Math.abs(a[2]-b[2])&&1.0E-6>Math.abs(a[3]-b[3])},negate:function(a,b){b||(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=-a[3];return b},length:function(a){var b=a[0],c=a[1],d=a[2],a=a[3];return Math.sqrt(b*b+c*c+d*d+a*a)},squaredLength:function(a){var b=a[0],c=a[1],d=a[2],a=a[3];return b*b+c*c+d*d+a*a},lerp:function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);d[2]=a[2]+c*(b[2]-a[2]);d[3]=a[3]+c*(b[3]-a[3]);return d},str:function(a){return"["+a[0]+", "+
|
||||||
|
a[1]+", "+a[2]+", "+a[3]+"]"}};w&&(w.glMatrixArrayType=o,w.MatrixArray=o,w.setMatrixArrayType=D,w.determineMatrixArrayType=G,w.glMath=E,w.vec2=J,w.vec3=r,w.vec4=K,w.mat2=I,w.mat3=A,w.mat4=x,w.quat4=k);return{glMatrixArrayType:o,MatrixArray:o,setMatrixArrayType:D,determineMatrixArrayType:G,glMath:E,vec2:J,vec3:r,vec4:K,mat2:I,mat3:A,mat4:x,quat4:k}});
|
Loading…
Add table
Add a link
Reference in a new issue