diff --git a/glutil-transform.js b/glutil-transform.js index 40f1f2e5..57ff9495 100644 --- a/glutil-transform.js +++ b/glutil-transform.js @@ -83,7 +83,14 @@ Transform.prototype.setMatrix=function(value){ } Transform.prototype.isIdentity=function(){ if(this._matrixDirty){ - this.getMatrix(); + if(this.complexMatrix){ + this.getMatrix(); + } else { + return this.position[0]==0 && this.position[1]==0 && + this.position[2]==0 && this.scale[0]==1 && + this.scale[1]==1 && this.scale[2]==1 && + GLMath.quatIsIdentity(this.rotation); + } } return this._isIdentity; } @@ -303,26 +310,35 @@ Transform.prototype.multOrientation=function(angle, v,vy,vz){ Transform.prototype.getMatrix=function(){ if(this._matrixDirty){ this._matrixDirty=false; - // for best results, multiply in this order: - // 1. translation + if(GLMath.quatIsIdentity(this.rotation)){ + this.matrix=[this.scale[0],0,0,0,0, + this.scale[1],0,0,0,0, + this.scale[2],0, + this.position[0], + this.position[1], + this.position[2],1]; + this._isIdentity=(this.position[0]==0 && this.position[1]==0 && + this.position[2]==0 && this.scale[0]==1 && + this.scale[1]==1 && this.scale[2]==1); + } else { + // for best results, multiply in this order: + // 1. translation this.matrix=[1,0,0,0,0,1,0,0,0,0,1,0, this.position[0], this.position[1], this.position[2],1]; - // 2. rotation - if(!GLMath.quatIsIdentity(this.rotation)){ + // 2. rotation this.matrix=GLMath.mat4multiply(this.matrix, GLMath.quatToMat4(this.rotation)); + // 3. scaling + GLMath.mat4scaleInPlace(this.matrix,this.scale); + this._isIdentity=( + m[0]==1 && m[1]==0 && m[2]==0 && m[3]==0 && + m[4]==0 && m[5]==1 && m[6]==0 && m[7]==0 && + m[8]==0 && m[9]==0 && m[10]==1 && m[11]==0 && + m[12]==0 && m[13]==0 && m[14]==0 && m[15]==1 + ); } - // 3. scaling - GLMath.mat4scaleInPlace(this.matrix,this.scale); - var m=this.matrix - this._isIdentity=( - m[0]==1 && m[1]==0 && m[2]==0 && m[3]==0 && - m[4]==0 && m[5]==1 && m[6]==0 && m[7]==0 && - m[8]==0 && m[9]==0 && m[10]==1 && m[11]==0 && - m[12]==0 && m[13]==0 && m[14]==0 && m[15]==1 - ); } else if(this._isIdentity){ return GLMath.mat4identity(); } diff --git a/glutil.js b/glutil.js index b38c22f3..0ca111c1 100644 --- a/glutil.js +++ b/glutil.js @@ -883,6 +883,7 @@ Texture.loadTexture=function(name, textureCache){ }); } + /** * Creates a texture from a byte array specifying the texture data. * @param {Uint8Array} array A byte array containing the texture data, @@ -1906,11 +1907,30 @@ Scene3D.prototype.setPointLight=function(index,position,diffuse,specular){ return this; } /** @private */ +Scene3D._isIdentityExceptTranslate=function(mat){ +return ( + mat[0]==1 && mat[1]==0 && mat[2]==0 && mat[3]==0 && + mat[4]==0 && mat[5]==1 && mat[6]==0 && mat[7]==0 && + mat[8]==0 && mat[9]==0 && mat[10]==1 && mat[11]==0 && + mat[15]==1 + ); +}; +/** @private */ Scene3D.prototype._setupMatrices=function(shape,program){ var uniforms={}; var currentMatrix=shape.getMatrix(); - var viewWorld=GLMath.mat4multiply(this._viewMatrix, + var viewWorld; + if(Scene3D._isIdentityExceptTranslate(this._viewMatrix)){ + // view matrix is just a translation matrix, so that getting the model-view + // matrix amounts to simply adding the view's position + viewWorld=currentMatrix.slice(0,16); + viewWorld[13]+=this._viewMatrix[13]; + viewWorld[14]+=this._viewMatrix[14]; + viewWorld[15]+=this._viewMatrix[15]; + } else { + viewWorld=GLMath.mat4multiply(this._viewMatrix, currentMatrix); + } var invTrans=GLMath.mat4inverseTranspose3(viewWorld); uniforms["world"]=currentMatrix; uniforms["modelMatrix"]=currentMatrix; diff --git a/glutil_min.js b/glutil_min.js index 70d6df1b..78bf1670 100644 --- a/glutil_min.js +++ b/glutil_min.js @@ -1,183 +1,185 @@ (function(b,c){"function"===typeof define&&define.amd?define(["exports"],c):"object"===typeof exports?c(exports):c(b)})(this,function(b){if(!b.Promise){var c=function(a){this._state=0;this._timeout=this._value=null;this._cb={fulfilled:[],rejected:[]};this._thenPromises=[];a&&this._invokeResolver(a)};c.resolve=function(a){return new this(function(d,b){d(a)})};c.reject=function(a){return new this(function(d,b){b(a)})};c.all=c.when=function(a){return new this(function(d,b){var c=0,g=[];a.forEach(function(a, k){c++;a.then(function(a){g[k]=a;c--;c||d(g)},function(a){c=1/0;b(a)})})})};c.race=function(a){return new this(function(d,b){a.forEach(function(a){a.then(d,b)})})};c.prototype.then=function(a,d){this._cb.fulfilled.push(a);this._cb.rejected.push(d);var b=new c;this._thenPromises.push(b);0a;a++)v[a]*=f;return v},quatConjugate:function(a){return[-a[0],-a[1],-a[2],a[3]]},quatInvert:function(a){var d=1/c.quatDot(a,a);return c.vec4scaleInPlace(d,c.quatConjugate(a))},quatInverse:function(a){return c.quatNormInPlace(c.quatConjugate(a))}, -quatIsIdentity:function(a){return 0==a[0]&&0==a[1]&&0==a[2]&&1==a[3]},quatToMat4:function(a){var d,b,c,g,f,k,l,n,p;d=2*a[0];b=2*a[1];c=2*a[2];g=d*a[0];f=d*a[1];k=d*a[2];l=b*a[1];n=c*a[1];p=c*a[2];d*=a[3];b*=a[3];a=c*a[3];return[1-(l+p),f+a,k-b,0,f-a,1-(g+p),n+d,0,k+b,n-d,1-(g+l),0,0,0,0,1]},quatToAxisAngle:function(a){var d=a[3],b=1-d*d;return 0a?a:a%360+(0>a?360:0))*c.PiDividedBy360;a=Math.cos(h);h=Math.sin(h);g=c.vec3normInPlace([g,b,d]);g=[g[0],g[1],g[2],a];g[0]*=h;g[1]*=h;g[2]*=h;return g},quatFromTaitBryan:function(a,d,b,h){var g,f;null==h&&(h=c.RollPitchYaw);if(0>h|| -6<=h)throw Error("invalid mode");a.constructor==Array?(b=(0<=a[2]&&360>a[2]?a[2]:a[2]%360+(0>a[2]?360:0))*c.PiDividedBy360,g=(0<=a[0]&&360>a[0]?a[0]:a[0]%360+(0>a[0]?360:0))*c.PiDividedBy360,f=(0<=a[1]&&360>a[1]?a[1]:a[1]%360+(0>a[1]?360:0))*c.PiDividedBy360):(b=(0<=b&&360>b?b:b%360+(0>b?360:0))*c.PiDividedBy360,g=(0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy360,f=(0<=d&&360>d?d:d%360+(0>d?360:0))*c.PiDividedBy360);a=Math.sin(g);g=Math.cos(g);d=Math.sin(f);f=Math.cos(f);var k=Math.sin(b);b=Math.cos(b); -if(h==c.PitchYawRoll||h==c.PitchRollYaw){var l=[k*d,b*d,k*f,b*f];h==c.PitchYawRoll&&(l[0]=-l[0]);h=[l[3]*a+l[0]*g,l[1]*g+l[2]*a,l[2]*g-l[1]*a,l[3]*g-l[0]*a]}else h==c.YawPitchRoll||h==c.YawRollPitch?(l=[b*a,k*a,k*g,b*g],h==c.YawRollPitch&&(l[1]=-l[1]),h=[l[0]*f-l[2]*d,l[3]*d+l[1]*f,l[2]*f+l[0]*d,l[3]*f-l[1]*d]):(l=[f*a,d*g,d*a,f*g],h==c.RollPitchYaw&&(l[2]=-l[2]),h=[l[0]*b+l[1]*k,l[1]*b-l[0]*k,l[3]*k+l[2]*b,l[3]*b-l[2]*k]);return h},quatToTaitBryan:function(a,b){var e=a[3],h,g,f,k=1;null==b&&(b=c.RollPitchYaw); -if(0>b||6<=b)throw Error("invalid mode");b==c.RollPitchYaw?(h=a[1],g=a[0],f=a[2],k=-1):b==c.PitchYawRoll?(h=a[2],g=a[1],f=a[0],k=-1):b==c.PitchRollYaw?(h=a[1],g=a[2],f=a[0]):b==c.YawPitchRoll?(h=a[2],g=a[0],f=a[1]):b==c.YawRollPitch?(h=a[0],g=a[2],f=a[1],k=-1):(h=a[0],g=a[1],f=a[2]);var l=g*g,n=f*f,p=Math.atan2(2*(e*h-k*g*f),1-2*(h*h+l)),m=2*(e*g+k*h*f);1m&&(m=-1);m=Math.asin(m);g=Math.atan2(2*(e*f-k*h*g),1-2*(l+n));p*=c.Num180DividedByPi;m*=c.Num180DividedByPi;g*=c.Num180DividedByPi; -if(1E-6>Math.abs(m-90)||1E-6>Math.abs(m+90))g=0,p=Math.atan2(h,e)*c.Num180DividedByPi,isNaN(p)&&(p=0);e=[];b==c.RollPitchYaw?(e[0]=m,e[1]=p,e[2]=g):b==c.PitchYawRoll?(e[0]=g,e[1]=m,e[2]=p):b==c.PitchRollYaw?(e[0]=g,e[1]=p,e[2]=m):b==c.YawPitchRoll?(e[0]=m,e[1]=g,e[2]=p):b==c.YawRollPitch?(e[0]=p,e[1]=g,e[2]=m):(e[0]=p,e[1]=m,e[2]=g);return e},quatSlerp:function(a,b,e){var h=c.quatDot(a,b),g=b;0>h&&(g=[-b[0],-b[1],-b[2],-b[3]],h=c.quatDot(a,g));b=0;if(-1h){if(b=Math.acos(h),0==b)return g.slice(0, -4)}else return g.slice(0,4);else b=Math.PI;var f=1/Math.sin(b),h=Math.sin((1-e)*b)*f;e=Math.sin(e*b)*f;return[a[0]*h+g[0]*e,a[1]*h+g[1]*e,a[2]*h+g[2]*e,a[3]*h+g[3]*e]},quatRotate:function(a,b,e,h,g){return c.quatMultiply(a,c.quatFromAxisAngle(b,e,h,g))},quatTransform:function(a,b){var e=c.vec3cross(a,b);e[0]+=b[0]*a[3];e[1]+=b[1]*a[3];e[2]+=b[2]*a[3];var h=c.vec3cross(e,a),g=a[0]*b[0]+a[1]*b[1]+a[2]*b[2];return[a[0]*g+e[0]*a[3]-h[0],a[1]*g+e[1]*a[3]-h[1],a[2]*g+e[2]*a[3]-h[2],1]},quatFromMat4:function(a){var b= -[],c=a[1],h=a[2],g=a[4],f=a[6],k=a[8],l=a[9],n=a[0]+a[5]+a[10];0<=n?(a=.5*Math.sqrt(n+1),n=.25/a,b[0]=(f-l)*n,b[1]=(k-h)*n,b[2]=(c-g)*n,b[3]=a):a[0]>a[5]&&a[0]>a[10]?(a=.5*Math.sqrt(1+a[0]-a[5]-a[10]),n=.25/a,b[0]=a,b[1]=(g+c)*n,b[2]=(h+k)*n,b[3]=(f-l)*n):a[5]>a[10]?(a=.5*Math.sqrt(1+a[5]-a[0]-a[10]),n=.25/a,b[0]=(g+c)*n,b[1]=a,b[2]=(l+f)*n,b[3]=(k-h)*n):(a=.5*Math.sqrt(1+a[10]-a[0]-a[5]),n=.25/a,b[0]=(k+h)*n,b[1]=(l+f)*n,b[2]=a,b[3]=(c-g)*n);return b},mat4toMat3:function(a){return[a[0],a[1],a[2], +1==a[10]&&0==a[11]&&0==a[12]&&0==a[13]&&0==a[14]&&1==a[15]},mat4invert:function(a){var d=a[0]*a[10],b=a[0]*a[11],h=a[0]*a[5],g=a[0]*a[6],e=a[0]*a[7],k=a[0]*a[9],l=a[10]*a[12],p=a[10]*a[13],q=a[10]*a[15],n=a[11]*a[12],r=a[11]*a[13],t=a[11]*a[14],v=a[1]*a[4],x=a[1]*a[6],y=a[1]*a[7],J=a[1]*a[8],B=a[2]*a[4],F=a[2]*a[5],E=a[2]*a[7],A=a[2]*a[8],z=a[2]*a[9],w=a[3]*a[4],D=a[3]*a[5],C=a[3]*a[6],L=a[3]*a[8],H=a[3]*a[9],O=a[4]*a[9],P=a[5]*a[8],N=a[6]*a[8],Q=a[6]*a[9],I=a[7]*a[8],M=a[7]*a[9],G=v-h,K=x-F,R=y- +D,S=B-g,h=h-v,x=F-x,F=E-C,v=w-e,y=D-y,E=C-E,g=g-B,B=e-w,e=a[9]*a[12]*E+l*R+n*x+a[8]*a[13]*F+p*v+r*g+a[8]*a[14]*y+a[9]*a[14]*B+t*G+a[8]*a[15]*K+a[9]*a[15]*S+q*h;if(0==e)return c.mat4identity();e=1/e;w=[];w[0]=a[6]*r-a[7]*p+M*a[14]-a[5]*t-Q*a[15]+a[5]*q;w[1]=a[3]*p-a[2]*r-H*a[14]+a[1]*t+z*a[15]-a[1]*q;w[2]=a[13]*F+a[14]*y+a[15]*K;w[3]=a[9]*E+a[10]*R+a[11]*x;w[4]=a[7]*l-a[6]*n-I*a[14]+a[4]*t+N*a[15]-a[4]*q;w[5]=a[2]*n-a[3]*l+a[14]*(L-b)+a[15]*(d-A);w[6]=a[12]*E+a[14]*B+a[15]*S;w[7]=a[8]*F+a[10]*v+a[11]* +g;w[8]=a[5]*n-M*a[12]+I*a[13]-a[4]*r+a[15]*(O-P);w[9]=H*a[12]-a[1]*n+a[13]*(b-L)+a[15]*(J-k);w[10]=a[12]*R+a[13]*v+a[15]*h;w[11]=a[8]*y+a[9]*B+a[11]*G;w[12]=Q*a[12]-a[5]*l-N*a[13]+a[4]*p+a[14]*(P-O);w[13]=a[1]*l-z*a[12]+a[13]*(A-d)+a[14]*(k-J);w[14]=a[12]*x+a[13]*g+a[14]*G;w[15]=a[8]*K+a[9]*S+a[10]*h;for(a=0;16>a;a++)w[a]*=e;return w},quatConjugate:function(a){return[-a[0],-a[1],-a[2],a[3]]},quatInvert:function(a){var d=1/c.quatDot(a,a);return c.vec4scaleInPlace(d,c.quatConjugate(a))},quatInverse:function(a){return c.quatNormInPlace(c.quatConjugate(a))}, +quatIsIdentity:function(a){return 0==a[0]&&0==a[1]&&0==a[2]&&1==a[3]},quatToMat4:function(a){var d,b,c,g,e,k,l,p,q;d=2*a[0];b=2*a[1];c=2*a[2];g=d*a[0];e=d*a[1];k=d*a[2];l=b*a[1];p=c*a[1];q=c*a[2];d*=a[3];b*=a[3];a=c*a[3];return[1-(l+q),e+a,k-b,0,e-a,1-(g+q),p+d,0,k+b,p-d,1-(g+l),0,0,0,0,1]},quatToAxisAngle:function(a){var d=a[3],b=1-d*d;return 0a?a:a%360+(0>a?360:0))*c.PiDividedBy360;a=Math.cos(h);h=Math.sin(h);g=c.vec3normInPlace([g,b,d]);g=[g[0],g[1],g[2],a];g[0]*=h;g[1]*=h;g[2]*=h;return g},quatFromTaitBryan:function(a,d,b,h){var g,e;null==h&&(h=c.RollPitchYaw);if(0>h|| +6<=h)throw Error("invalid mode");a.constructor==Array?(b=(0<=a[2]&&360>a[2]?a[2]:a[2]%360+(0>a[2]?360:0))*c.PiDividedBy360,g=(0<=a[0]&&360>a[0]?a[0]:a[0]%360+(0>a[0]?360:0))*c.PiDividedBy360,e=(0<=a[1]&&360>a[1]?a[1]:a[1]%360+(0>a[1]?360:0))*c.PiDividedBy360):(b=(0<=b&&360>b?b:b%360+(0>b?360:0))*c.PiDividedBy360,g=(0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy360,e=(0<=d&&360>d?d:d%360+(0>d?360:0))*c.PiDividedBy360);a=Math.sin(g);g=Math.cos(g);d=Math.sin(e);e=Math.cos(e);var k=Math.sin(b);b=Math.cos(b); +if(h==c.PitchYawRoll||h==c.PitchRollYaw){var l=[k*d,b*d,k*e,b*e];h==c.PitchYawRoll&&(l[0]=-l[0]);h=[l[3]*a+l[0]*g,l[1]*g+l[2]*a,l[2]*g-l[1]*a,l[3]*g-l[0]*a]}else h==c.YawPitchRoll||h==c.YawRollPitch?(l=[b*a,k*a,k*g,b*g],h==c.YawRollPitch&&(l[1]=-l[1]),h=[l[0]*e-l[2]*d,l[3]*d+l[1]*e,l[2]*e+l[0]*d,l[3]*e-l[1]*d]):(l=[e*a,d*g,d*a,e*g],h==c.RollPitchYaw&&(l[2]=-l[2]),h=[l[0]*b+l[1]*k,l[1]*b-l[0]*k,l[3]*k+l[2]*b,l[3]*b-l[2]*k]);return h},quatToTaitBryan:function(a,d){var b=a[3],h,g,e,k=1;null==d&&(d=c.RollPitchYaw); +if(0>d||6<=d)throw Error("invalid mode");d==c.RollPitchYaw?(h=a[1],g=a[0],e=a[2],k=-1):d==c.PitchYawRoll?(h=a[2],g=a[1],e=a[0],k=-1):d==c.PitchRollYaw?(h=a[1],g=a[2],e=a[0]):d==c.YawPitchRoll?(h=a[2],g=a[0],e=a[1]):d==c.YawRollPitch?(h=a[0],g=a[2],e=a[1],k=-1):(h=a[0],g=a[1],e=a[2]);var l=g*g,p=e*e,q=Math.atan2(2*(b*h-k*g*e),1-2*(h*h+l)),n=2*(b*g+k*h*e);1n&&(n=-1);n=Math.asin(n);g=Math.atan2(2*(b*e-k*h*g),1-2*(l+p));q*=c.Num180DividedByPi;n*=c.Num180DividedByPi;g*=c.Num180DividedByPi; +if(1E-6>Math.abs(n-90)||1E-6>Math.abs(n+90))g=0,q=Math.atan2(h,b)*c.Num180DividedByPi,isNaN(q)&&(q=0);b=[];d==c.RollPitchYaw?(b[0]=n,b[1]=q,b[2]=g):d==c.PitchYawRoll?(b[0]=g,b[1]=n,b[2]=q):d==c.PitchRollYaw?(b[0]=g,b[1]=q,b[2]=n):d==c.YawPitchRoll?(b[0]=n,b[1]=g,b[2]=q):d==c.YawRollPitch?(b[0]=q,b[1]=g,b[2]=n):(b[0]=q,b[1]=n,b[2]=g);return b},quatSlerp:function(a,b,f){var h=c.quatDot(a,b),g=b;0>h&&(g=[-b[0],-b[1],-b[2],-b[3]],h=c.quatDot(a,g));b=0;if(-1h){if(b=Math.acos(h),0==b)return g.slice(0, +4)}else return g.slice(0,4);else b=Math.PI;var e=1/Math.sin(b),h=Math.sin((1-f)*b)*e;f=Math.sin(f*b)*e;return[a[0]*h+g[0]*f,a[1]*h+g[1]*f,a[2]*h+g[2]*f,a[3]*h+g[3]*f]},quatRotate:function(a,b,f,h,g){return c.quatMultiply(a,c.quatFromAxisAngle(b,f,h,g))},quatTransform:function(a,b){var f=c.vec3cross(a,b);f[0]+=b[0]*a[3];f[1]+=b[1]*a[3];f[2]+=b[2]*a[3];var h=c.vec3cross(f,a),g=a[0]*b[0]+a[1]*b[1]+a[2]*b[2];return[a[0]*g+f[0]*a[3]-h[0],a[1]*g+f[1]*a[3]-h[1],a[2]*g+f[2]*a[3]-h[2],1]},quatFromMat4:function(a){var b= +[],c=a[1],h=a[2],g=a[4],e=a[6],k=a[8],l=a[9],p=a[0]+a[5]+a[10];0<=p?(a=.5*Math.sqrt(p+1),p=.25/a,b[0]=(e-l)*p,b[1]=(k-h)*p,b[2]=(c-g)*p,b[3]=a):a[0]>a[5]&&a[0]>a[10]?(a=.5*Math.sqrt(1+a[0]-a[5]-a[10]),p=.25/a,b[0]=a,b[1]=(g+c)*p,b[2]=(h+k)*p,b[3]=(e-l)*p):a[5]>a[10]?(a=.5*Math.sqrt(1+a[5]-a[0]-a[10]),p=.25/a,b[0]=(g+c)*p,b[1]=a,b[2]=(l+e)*p,b[3]=(k-h)*p):(a=.5*Math.sqrt(1+a[10]-a[0]-a[5]),p=.25/a,b[0]=(k+h)*p,b[1]=(l+e)*p,b[2]=a,b[3]=(c-g)*p);return b},mat4toMat3:function(a){return[a[0],a[1],a[2], a[4],a[5],a[6],a[8],a[9],a[10]]},mat4transpose:function(a){return mat4transposeInPlace(a.slice(0,16))},mat4transposeInPlace:function(a){var b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return a},mat4inverseTranspose3:function(a){a=[a[0],a[1],a[2],a[4],a[5],a[6],a[8],a[9],a[10]];var b=a[0]*a[4]*a[8]+a[3]*a[7]*a[2]+a[6]*a[1]*a[5]-a[6]*a[4]*a[2]-a[3]*a[1]*a[8]-a[0]*a[7]*a[5];if(0==b)return[1,0, 0,0,1,0,0,0,1];b=1/b;return[(-a[5]*a[7]+a[4]*a[8])*b,(a[5]*a[6]-a[3]*a[8])*b,(-a[4]*a[6]+a[3]*a[7])*b,(a[2]*a[7]-a[1]*a[8])*b,(-a[2]*a[6]+a[0]*a[8])*b,(a[1]*a[6]-a[0]*a[7])*b,(-a[2]*a[4]+a[1]*a[5])*b,(a[2]*a[3]-a[0]*a[5])*b,(-a[1]*a[3]+a[0]*a[4])*b]},mat4scale:function(a,b,c,h){var g;"undefined"!=typeof c&&"undefined"!=typeof h?(g=b,b=h):(g=b[0],c=b[1],b=b[2]);return[a[0]*g,a[1]*g,a[2]*g,a[3]*g,a[4]*c,a[5]*c,a[6]*c,a[7]*c,a[8]*b,a[9]*b,a[10]*b,a[11]*b,a[12],a[13],a[14],a[15]]},mat4scaled:function(a, -b,c){return"undefined"!=typeof b&&"undefined"!=typeof c?[a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1]:[a[0],0,0,0,0,a[1],0,0,0,0,a[2],0,0,0,0,1]},mat4transform:function(a,b,c,h,g){var f;"undefined"!=typeof c&&"undefined"!=typeof h&&"undefined"!=typeof g?(f=b,b=g):(f=b[0],c=b[1],h=b[2],b=b[3]);return[f*a[0]+c*a[4]+h*a[8]+b*a[12],f*a[1]+c*a[5]+h*a[9]+b*a[13],f*a[2]+c*a[6]+h*a[10]+b*a[14],f*a[3]+c*a[7]+h*a[11]+b*a[15]]},mat3transform:function(a,b,c,h){var g;"undefined"!=typeof c&&"undefined"!=typeof h?(g=b,b=h): +b,c){return"undefined"!=typeof b&&"undefined"!=typeof c?[a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1]:[a[0],0,0,0,0,a[1],0,0,0,0,a[2],0,0,0,0,1]},mat4transform:function(a,b,c,h,g){var e;"undefined"!=typeof c&&"undefined"!=typeof h&&"undefined"!=typeof g?(e=b,b=g):(e=b[0],c=b[1],h=b[2],b=b[3]);return[e*a[0]+c*a[4]+h*a[8]+b*a[12],e*a[1]+c*a[5]+h*a[9]+b*a[13],e*a[2]+c*a[6]+h*a[10]+b*a[14],e*a[3]+c*a[7]+h*a[11]+b*a[15]]},mat3transform:function(a,b,c,h){var g;"undefined"!=typeof c&&"undefined"!=typeof h?(g=b,b=h): (g=b[0],c=b[1],b=b[2]);return[g*a[0]+c*a[3]+b*a[6],g*a[1]+c*a[4]+b*a[7],g*a[2]+c*a[5]+b*a[8]]},mat4translated:function(a,b,c){var h;"undefined"!=typeof b&&"undefined"!=typeof c?(h=a,a=c):(h=a[0],b=a[1],a=a[2]);return[1,0,0,0,0,1,0,0,0,0,1,0,h,b,a,1]},mat4translate:function(a,b,c,h){var g;"undefined"!=typeof c&&"undefined"!=typeof h?(g=b,b=h):(g=b[0],c=b[1],b=b[2]);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[0]*g+a[4]*c+a[8]*b+a[12],a[1]*g+a[5]*c+a[9]*b+a[13],a[2]*g+a[6]* -c+a[10]*b+a[14],a[3]*g+a[7]*c+a[11]*b+a[15]]},mat4perspective:function(a,b,e,h){a=1/Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy360);var g;g=1/(e-h);return[a/b,0,0,0,0,a,0,0,0,0,g*(e+h),-1,0,0,g*e*h*2,0]},mat4lookat:function(a,b,e){e||(e=[0,1,0]);b||(b=[0,0,0]);b=[b[0]-a[0],b[1]-a[1],b[2]-a[2]];var h=c.vec3length(b);if(1E-6>h)return c.mat4identity();h=1/h;b[0]*=h;b[1]*=h;b[2]*=h;e=c.vec3norm(e);e=c.vec3cross(b,e);c.vec3normInPlace(e);h=c.vec3cross(e,b);c.vec3normInPlace(h);b[0]=-b[0]; -b[1]=-b[1];b[2]=-b[2];return[e[0],h[0],b[0],0,e[1],h[1],b[1],0,e[2],h[2],b[2],0,-c.vec3dot(a,e),-c.vec3dot(a,h),-c.vec3dot(a,b),1]},mat4ortho:function(a,b,c,h,g,f){var k=1/(b-a),l=1/(h-c),n=1/(f-g);return[2*k,0,0,0,0,2*l,0,0,0,0,-2*n,0,-(a+b)*k,-(h+c)*l,-(g+f)*n,1]},mat4perspectiveHorizontal:function(a,b,e,h){a=c.Num360DividedByPi*Math.atan2(Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy360),b);return c.mat4perspective(a,b,e,h)},mat4ortho2d:function(a,b,e,h){return c.mat4ortho2d(a,b,e,h, --1,1)},mat4ortho2dAspect:function(a,b,e,h,g){return c.mat4orthoAspect(a,b,e,h,-1,1,g)},mat4orthoAspect:function(a,b,e,h,g,f,k){var l=Math.abs(b-a),n=Math.abs(h-e);k/=l/n;return 1>k?c.mat4ortho(a,b,e/k,h/k,g,f):c.mat4ortho(a*k,b*k,e,h,g,f)},mat4frustum:function(a,b,c,h,g,f){var k=2*g,l=1/(b-a),n=1/(h-c),p=1/(f-g);return[k*l,0,0,0,0,k*n,0,0,(a+b)*l,(h+c)*n,-(f+g)*p,-1,0,0,-(k*f)*p,0]},mat4scaleInPlace:function(a,b,c,h){var g;"undefined"!=typeof c&&"undefined"!=typeof h?(g=b,b=h):(g=b[0],c=b[1],b=b[2]); -a[0]*=g;a[1]*=g;a[2]*=g;a[3]*=g;a[4]*=c;a[5]*=c;a[6]*=c;a[7]*=c;a[8]*=b;a[9]*=b;a[10]*=b;a[11]*=b;return a},mat4multiply:function(a,b){for(var c=[],h=0;16>h;h+=4)for(var g=0;4>g;g++)c[h+g]=b[h]*a[g]+b[h+1]*a[g+4]+b[h+2]*a[g+8]+b[h+3]*a[g+12];return c},quatMultiply:function(a,b){return[a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],a[3]*b[1]+a[1]*b[3]+a[2]*b[0]-a[0]*b[2],a[3]*b[2]+a[2]*b[3]+a[0]*b[1]-a[1]*b[0],a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2]]},mat4rotate:function(a,b,e,h,g){var f,k;"undefined"!=typeof h&& -"undefined"!=typeof g?(f=e,k=h,e=g,g=(0<=b&&360>b?b:b%360+(0>b?360:0))*c.PiDividedBy180):"undefined"==typeof e?(f=b[0],k=b[1],e=b[2],g=b[3],g=(0<=g&&360>g?g:g%360+(0>g?360:0))*c.PiDividedBy180):(f=e[0],k=e[1],e=e[2],g=(0<=b&&360>b?b:b%360+(0>b?360:0))*c.PiDividedBy180);b=Math.cos(g);var l=Math.sin(g);if(1==f&&0==k&&0==e)return[a[0],a[1],a[2],a[3],b*a[4]+a[8]*l,b*a[5]+a[9]*l,b*a[6]+a[10]*l,b*a[7]+a[11]*l,b*a[8]-l*a[4],b*a[9]-l*a[5],b*a[10]-l*a[6],b*a[11]-l*a[7],a[12],a[13],a[14],a[15]];if(0==f&&1== -k&&0==e)return[b*a[0]-l*a[8],b*a[1]-l*a[9],b*a[2]-l*a[10],b*a[3]-l*a[11],a[4],a[5],a[6],a[7],b*a[8]+a[0]*l,b*a[9]+a[1]*l,b*a[10]+a[2]*l,b*a[11]+a[3]*l,a[12],a[13],a[14],a[15]];if(0==f&&0==k&&1==e)return[b*a[0]+a[4]*l,b*a[1]+a[5]*l,b*a[2]+a[6]*l,b*a[3]+a[7]*l,b*a[4]-l*a[0],b*a[5]-l*a[1],b*a[6]-l*a[2],b*a[7]-l*a[3],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]];if(0==f&&0==k&&0==e)return a.slice(0,16);g=1/Math.sqrt(f*f+k*k+e*e);f*=g;k*=g;e*=g;var n=k*k;h=1-b;var p=f*k,m=k*e;g=f*l;k*=l;var q=e*l,l=h* -m,r=h*p,t=h*f*e;f=b+h*f*f;p=r+q;m=t-k;n=b+h*n;q=r-q;r=l+g;e=b+h*e*e;b=t+k;g=l-g;return[a[0]*f+a[4]*p+a[8]*m,a[1]*f+a[5]*p+a[9]*m,a[10]*m+a[2]*f+a[6]*p,a[11]*m+a[3]*f+a[7]*p,a[0]*q+a[4]*n+a[8]*r,a[1]*q+a[5]*n+a[9]*r,a[10]*r+a[2]*q+a[6]*n,a[11]*r+a[3]*q+a[7]*n,a[0]*b+a[4]*g+a[8]*e,a[1]*b+a[5]*g+a[9]*e,a[10]*e+a[2]*b+a[6]*g,a[11]*e+a[3]*b+a[7]*g,a[12],a[13],a[14],a[15]]},mat4rotated:function(a,b,e,h){var g;"undefined"!=typeof e&&"undefined"!=typeof h?(g=b,b=h,h=(0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy180): -"undefined"==typeof b?(g=a[0],e=a[1],b=a[2],h=a[3],h=(0<=h&&360>h?h:h%360+(0>h?360:0))*c.PiDividedBy180):(g=b[0],e=b[1],b=b[2],h=(0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy180);a=Math.cos(h);var f=Math.sin(h);if(1==g&&0==e&&0==b)return[1,0,0,0,0,a,f,0,0,-f,a,0,0,0,0,1];if(0==g&&1==e&&0==b)return[a,0,-f,0,0,1,0,0,f,0,a,0,0,0,0,1];if(0==g&&0==e&&1==b)return[a,f,0,0,-f,a,0,0,0,0,1,0,0,0,0,1];if(0==g&&0==e&&0==b)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];h=1/Math.sqrt(g*g+e*e+b*b);g*=h;e*=h;b*=h;h=g* -g;var k=e*e,l=b*b,n=g*b,p=e*b,m=g*f,q=e*f,f=b*f,r=1-a;g=r*g*e;e=r*n;b=r*p;return[a+r*h,g+f,e-q,0,g-f,a+r*k,b+m,0,e+q,b-m,a+r*l,0,0,0,0,1]}};c.quatDot=c.vec4dot;c.quatNormInPlace=c.vec4normInPlace;c.quatNorm=c.vec4norm;c.quatLength=c.vec4length;c.quatScaleInPlace=c.vec4scaleInPlace;c.quatCopy=c.vec4copy;c.PiTimes2=6.283185307179586;c.HalfPi=1.5707963267948966;c.PiDividedBy180=.017453292519943295;c.PiDividedBy360=.008726646259971648;c.Num360DividedByPi=114.59155902616465;c.Num180DividedByPi=57.29577951308232; +c+a[10]*b+a[14],a[3]*g+a[7]*c+a[11]*b+a[15]]},mat4perspective:function(a,b,f,h){a=1/Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy360);var g;g=1/(f-h);return[a/b,0,0,0,0,a,0,0,0,0,g*(f+h),-1,0,0,g*f*h*2,0]},mat4lookat:function(a,b,f){f||(f=[0,1,0]);b||(b=[0,0,0]);b=[b[0]-a[0],b[1]-a[1],b[2]-a[2]];var h=c.vec3length(b);if(1E-6>h)return c.mat4identity();h=1/h;b[0]*=h;b[1]*=h;b[2]*=h;f=c.vec3norm(f);f=c.vec3cross(b,f);c.vec3normInPlace(f);h=c.vec3cross(f,b);c.vec3normInPlace(h);b[0]=-b[0]; +b[1]=-b[1];b[2]=-b[2];return[f[0],h[0],b[0],0,f[1],h[1],b[1],0,f[2],h[2],b[2],0,-c.vec3dot(a,f),-c.vec3dot(a,h),-c.vec3dot(a,b),1]},mat4ortho:function(a,b,c,h,g,e){var k=1/(b-a),l=1/(h-c),p=1/(e-g);return[2*k,0,0,0,0,2*l,0,0,0,0,-2*p,0,-(a+b)*k,-(h+c)*l,-(g+e)*p,1]},mat4perspectiveHorizontal:function(a,b,f,h){a=c.Num360DividedByPi*Math.atan2(Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy360),b);return c.mat4perspective(a,b,f,h)},mat4ortho2d:function(a,b,f,h){return c.mat4ortho2d(a,b,f,h, +-1,1)},mat4ortho2dAspect:function(a,b,f,h,g){return c.mat4orthoAspect(a,b,f,h,-1,1,g)},mat4orthoAspect:function(a,b,f,h,g,e,k){var l=Math.abs(b-a),p=Math.abs(h-f);k/=l/p;return 1>k?c.mat4ortho(a,b,f/k,h/k,g,e):c.mat4ortho(a*k,b*k,f,h,g,e)},mat4frustum:function(a,b,c,h,g,e){var k=2*g,l=1/(b-a),p=1/(h-c),q=1/(e-g);return[k*l,0,0,0,0,k*p,0,0,(a+b)*l,(h+c)*p,-(e+g)*q,-1,0,0,-(k*e)*q,0]},mat4scaleInPlace:function(a,b,c,h){var g;"undefined"!=typeof c&&"undefined"!=typeof h?(g=b,b=h):(g=b[0],c=b[1],b=b[2]); +a[0]*=g;a[1]*=g;a[2]*=g;a[3]*=g;a[4]*=c;a[5]*=c;a[6]*=c;a[7]*=c;a[8]*=b;a[9]*=b;a[10]*=b;a[11]*=b;return a},mat4multiply:function(a,b){for(var c=[],h=0;16>h;h+=4)for(var g=0;4>g;g++)c[h+g]=b[h]*a[g]+b[h+1]*a[g+4]+b[h+2]*a[g+8]+b[h+3]*a[g+12];return c},quatMultiply:function(a,b){return[a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],a[3]*b[1]+a[1]*b[3]+a[2]*b[0]-a[0]*b[2],a[3]*b[2]+a[2]*b[3]+a[0]*b[1]-a[1]*b[0],a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2]]},mat4rotate:function(a,b,f,h,g){var e,k;"undefined"!=typeof h&& +"undefined"!=typeof g?(e=f,k=h,f=g,g=(0<=b&&360>b?b:b%360+(0>b?360:0))*c.PiDividedBy180):"undefined"==typeof f?(e=b[0],k=b[1],f=b[2],g=b[3],g=(0<=g&&360>g?g:g%360+(0>g?360:0))*c.PiDividedBy180):(e=f[0],k=f[1],f=f[2],g=(0<=b&&360>b?b:b%360+(0>b?360:0))*c.PiDividedBy180);b=Math.cos(g);var l=Math.sin(g);if(1==e&&0==k&&0==f)return[a[0],a[1],a[2],a[3],b*a[4]+a[8]*l,b*a[5]+a[9]*l,b*a[6]+a[10]*l,b*a[7]+a[11]*l,b*a[8]-l*a[4],b*a[9]-l*a[5],b*a[10]-l*a[6],b*a[11]-l*a[7],a[12],a[13],a[14],a[15]];if(0==e&&1== +k&&0==f)return[b*a[0]-l*a[8],b*a[1]-l*a[9],b*a[2]-l*a[10],b*a[3]-l*a[11],a[4],a[5],a[6],a[7],b*a[8]+a[0]*l,b*a[9]+a[1]*l,b*a[10]+a[2]*l,b*a[11]+a[3]*l,a[12],a[13],a[14],a[15]];if(0==e&&0==k&&1==f)return[b*a[0]+a[4]*l,b*a[1]+a[5]*l,b*a[2]+a[6]*l,b*a[3]+a[7]*l,b*a[4]-l*a[0],b*a[5]-l*a[1],b*a[6]-l*a[2],b*a[7]-l*a[3],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]];if(0==e&&0==k&&0==f)return a.slice(0,16);g=1/Math.sqrt(e*e+k*k+f*f);e*=g;k*=g;f*=g;var p=k*k;h=1-b;var q=e*k,n=k*f;g=e*l;k*=l;var r=f*l,l=h* +n,t=h*q,v=h*e*f;e=b+h*e*e;q=t+r;n=v-k;p=b+h*p;r=t-r;t=l+g;f=b+h*f*f;b=v+k;g=l-g;return[a[0]*e+a[4]*q+a[8]*n,a[1]*e+a[5]*q+a[9]*n,a[10]*n+a[2]*e+a[6]*q,a[11]*n+a[3]*e+a[7]*q,a[0]*r+a[4]*p+a[8]*t,a[1]*r+a[5]*p+a[9]*t,a[10]*t+a[2]*r+a[6]*p,a[11]*t+a[3]*r+a[7]*p,a[0]*b+a[4]*g+a[8]*f,a[1]*b+a[5]*g+a[9]*f,a[10]*f+a[2]*b+a[6]*g,a[11]*f+a[3]*b+a[7]*g,a[12],a[13],a[14],a[15]]},mat4rotated:function(a,b,f,h){var g;"undefined"!=typeof f&&"undefined"!=typeof h?(g=b,b=h,h=(0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy180): +"undefined"==typeof b?(g=a[0],f=a[1],b=a[2],h=a[3],h=(0<=h&&360>h?h:h%360+(0>h?360:0))*c.PiDividedBy180):(g=b[0],f=b[1],b=b[2],h=(0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy180);a=Math.cos(h);var e=Math.sin(h);if(1==g&&0==f&&0==b)return[1,0,0,0,0,a,e,0,0,-e,a,0,0,0,0,1];if(0==g&&1==f&&0==b)return[a,0,-e,0,0,1,0,0,e,0,a,0,0,0,0,1];if(0==g&&0==f&&1==b)return[a,e,0,0,-e,a,0,0,0,0,1,0,0,0,0,1];if(0==g&&0==f&&0==b)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];h=1/Math.sqrt(g*g+f*f+b*b);g*=h;f*=h;b*=h;h=g* +g;var k=f*f,l=b*b,p=g*b,q=f*b,n=g*e,r=f*e,e=b*e,t=1-a;g=t*g*f;f=t*p;b=t*q;return[a+t*h,g+e,f-r,0,g-e,a+t*k,b+n,0,f+r,b-n,a+t*l,0,0,0,0,1]}};c.quatDot=c.vec4dot;c.quatNormInPlace=c.vec4normInPlace;c.quatNorm=c.vec4norm;c.quatLength=c.vec4length;c.quatScaleInPlace=c.vec4scaleInPlace;c.quatCopy=c.vec4copy;c.PiTimes2=6.283185307179586;c.HalfPi=1.5707963267948966;c.PiDividedBy180=.017453292519943295;c.PiDividedBy360=.008726646259971648;c.Num360DividedByPi=114.59155902616465;c.Num180DividedByPi=57.29577951308232; c.PitchYawRoll=0;c.PitchRollYaw=1;c.YawPitchRoll=2;c.YawRollPitch=3;c.RollPitchYaw=4;c.RollYawPitch=5;c.quatToEuler=c.quatToTaitBryan;c.quatFromEuler=c.quatFromTaitBryan;b.GLMath=c}}); -(function(b,c){"function"===typeof define&&define.amd?define(["exports"],c):"object"===typeof exports?c(exports):c(b)})(this,function(b){function c(a,b,c,f){this.ambient=b||[0,0,0,1];this.position=a?[a[0],a[1],a[2],1]:[0,0,1,0];this.diffuse=c||[1,1,1];this.specular=f||[1,1,1]}function a(){this.lights=[new c];this.sceneAmbient=[.2,.2,.2]}function d(a,b,c,f,d){null!=a&&(a=n.toGLColor(a));null!=b&&(b=n.toGLColor(b));null!=c&&(c=n.toGLColor(c));null!=d&&(d=n.toGLColor(d));this.shininess=null==f?0:Math.min(Math.max(0, -f),128);this.ambient=a?a.slice(0,3):[.2,.2,.2];this.diffuse=b?b.slice(0,b.length):[.8,.8,.8,1];this.specular=c?c.slice(0,3):[0,0,0];this.emission=d?d.slice(0,3):[0,0,0];this.texture=null}function e(a,b){this.subMeshes=[];this.context=n._toContext(b);for(var c=0;c=a.vertices.length&&256>=a.indices.length?(d=b.UNSIGNED_BYTE,b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint8Array(a.indices),b.STATIC_DRAW)):b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(a.indices),b.STATIC_DRAW);this.verts=c;this.faces=f;this.numVertices= +(function(b,c){"function"===typeof define&&define.amd?define(["exports"],c):"object"===typeof exports?c(exports):c(b)})(this,function(b){function c(a,b,c,e){this.ambient=b||[0,0,0,1];this.position=a?[a[0],a[1],a[2],1]:[0,0,1,0];this.diffuse=c||[1,1,1];this.specular=e||[1,1,1]}function a(){this.lights=[new c];this.sceneAmbient=[.2,.2,.2]}function d(a,b,c,e,d){null!=a&&(a=p.toGLColor(a));null!=b&&(b=p.toGLColor(b));null!=c&&(c=p.toGLColor(c));null!=d&&(d=p.toGLColor(d));this.shininess=null==e?0:Math.min(Math.max(0, +e),128);this.ambient=a?a.slice(0,3):[.2,.2,.2];this.diffuse=b?b.slice(0,b.length):[.8,.8,.8,1];this.specular=c?c.slice(0,3):[0,0,0];this.emission=d?d.slice(0,3):[0,0,0];this.texture=null}function f(a,b){this.subMeshes=[];this.context=p._toContext(b);for(var c=0;c=a.vertices.length&&256>=a.indices.length?(d=b.UNSIGNED_BYTE,b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint8Array(a.indices),b.STATIC_DRAW)):b.bufferData(b.ELEMENT_ARRAY_BUFFER,new Uint16Array(a.indices),b.STATIC_DRAW);this.verts=c;this.faces=e;this.numVertices= a.vertices.length/a.getStride();this.facesLength=a.indices.length;this.type=d;this.format=a.attributeBits;this.context=b}function g(a,b,c){if(0>b||0>c)throw Error("width or height negative");this.context=a;this.textureUnit=1;this.buffer=a.createFramebuffer();this.colorTexture=a.createTexture();this.width=Math.ceil(b);this.height=Math.ceil(c);this.context.activeTexture(this.context.TEXTURE0+this.textureUnit);this.context.bindTexture(this.context.TEXTURE_2D,this.colorTexture);this.context.pixelStorei(this.context.UNPACK_FLIP_Y_WEBGL, 1);this.context.texImage2D(this.context.TEXTURE_2D,0,this.context.RGBA,this.width,this.height,0,this.context.RGBA,this.context.UNSIGNED_BYTE,null);this.context.texParameteri(this.context.TEXTURE_2D,this.context.TEXTURE_MAG_FILTER,this.context.NEAREST);this.context.texParameteri(this.context.TEXTURE_2D,this.context.TEXTURE_MIN_FILTER,this.context.NEAREST);this.context.texParameteri(this.context.TEXTURE_2D,this.context.TEXTURE_WRAP_S,this.context.CLAMP_TO_EDGE);this.context.texParameteri(this.context.TEXTURE_2D, -this.context.TEXTURE_WRAP_T,this.context.CLAMP_TO_EDGE);this.depthbuffer=this.context.createRenderbuffer();b=this.context.getParameter(a.FRAMEBUFFER_BINDING);this.context.bindFramebuffer(a.FRAMEBUFFER,this.buffer);this.context.bindRenderbuffer(a.RENDERBUFFER,this.depthbuffer);this.context.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,this.width,this.height);this.context.bindFramebuffer(a.FRAMEBUFFER,b)}function f(b){var c=b;"function"==typeof b.getContext&&(c=HTMLCanvasElement&&c.constructor== -HTMLCanvasElement?n.get3DContext(b):n._toContext(c));this.context=c;this.specularEnabled=this.lightingEnabled=!0;this.program=new ShaderProgram(c,this._getDefines()+ShaderProgram.getDefaultVertex(),this._getDefines()+ShaderProgram.getDefaultFragment());this.shapes=[];this.clearColor=[0,0,0,1];this.fboFilter=null;this.textureCache={};this._projectionMatrix=GLMath.mat4identity();this._viewMatrix=GLMath.mat4identity();this._invView=null;this.lightSource=new a;this.width=Math.ceil(1*this.context.canvas.width); +this.context.TEXTURE_WRAP_T,this.context.CLAMP_TO_EDGE);this.depthbuffer=this.context.createRenderbuffer();b=this.context.getParameter(a.FRAMEBUFFER_BINDING);this.context.bindFramebuffer(a.FRAMEBUFFER,this.buffer);this.context.bindRenderbuffer(a.RENDERBUFFER,this.depthbuffer);this.context.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,this.width,this.height);this.context.bindFramebuffer(a.FRAMEBUFFER,b)}function e(b){var c=b;"function"==typeof b.getContext&&(c=HTMLCanvasElement&&c.constructor== +HTMLCanvasElement?p.get3DContext(b):p._toContext(c));this.context=c;this.specularEnabled=this.lightingEnabled=!0;this.program=new ShaderProgram(c,this._getDefines()+ShaderProgram.getDefaultVertex(),this._getDefines()+ShaderProgram.getDefaultFragment());this.shapes=[];this.clearColor=[0,0,0,1];this.fboFilter=null;this.textureCache={};this._projectionMatrix=GLMath.mat4identity();this._viewMatrix=GLMath.mat4identity();this._invView=null;this.lightSource=new a;this.width=Math.ceil(1*this.context.canvas.width); this.height=Math.ceil(1*this.context.canvas.height);this.context.viewport(0,0,this.width,this.height);this.context.enable(c.BLEND);this.context.blendFunc(c.SRC_ALPHA,c.ONE_MINUS_SRC_ALPHA);this.context.enable(this.context.DEPTH_TEST);this.context.depthFunc(this.context.LEQUAL);this.context.clearDepth(1);this._setClearColor();this.context.clear(this.context.COLOR_BUFFER_BIT|this.context.DEPTH_BUFFER_BIT);this.useProgram(this.program)}function k(){this.shapes=[];this.parent=null;this.transform=new Transform} -function l(a){if(null==a)throw Error("mesh is null");this.bufferedMesh=a;this.transform=new Transform;this.material=new d;this.parent=null}if(!b.GLUtil){var n={renderLoop:function(a){a();var b=function(){window.requestAnimationFrame(b);a()};window.requestAnimationFrame(b)},createCanvas:function(a,b,c){var f=document.createElement("canvas");if(null==a)f.width=Math.ceil(window.innerWidth)+"";else{if(0>a)throw Error("width negative");f.width=Math.ceil(a)+""}if(null==b)f.height=Math.ceil(window.innerHeight)+ -"";else{if(0>b)throw Error("height negative");f.height=Math.ceil(b)+""}c&&c.appendChild(f);return f},get3DOr2DContext:function(a){if(!a||!a.getContext)return null;var b=null,c={antialias:!0};try{b=a.getContext("webgl",c)}catch(f){b=null}if(!b)try{b=a.getContext("experimental-webgl",c)}catch(d){b=null}if(!b)try{b=a.getContext("moz-webgl",c)}catch(g){b=null}if(!b)try{b=a.getContext("webkit-3d",c)}catch(e){b=null}if(!b)try{b=a.getContext("2d",c)}catch(h){b=null}n.is3DContext(b)&&b.getExtension("OES_element_index_uint"); -return b},get3DContext:function(a,b){var c=n.get3DOr2DContext(a),f=null;!c&&window.WebGLShader?f="Failed to initialize graphics support required by this page.":window.WebGLShader&&!n.is3DContext(c)?f="This page requires WebGL, but it failed to start. Your computer might not support WebGL.":c&&n.is3DContext(c)||(f="This page requires a WebGL-supporting browser.");return f?((b||window.alert)(f),null):c},is3DContext:function(a){return a&&"compileShader"in a},getPromiseResults:function(a,b,c){if(!a|| -0==a.length)return Promise.resolve({successes:[],failures:[],results:[]});for(var f={successes:[],failures:[],results:[]},d=[],g=0;gd.status){var g=d.response;g||(g="xml"==c?d.responseXML:"json"==c?(d.responseJSON||JSON.parse(d.responseText))+"":"arraybuffer"==c?d.response:d.responseText+"");b({url:a,data:g})}else f({url:a})};d.onerror=function(b){f({url:a,error:b})};d.open("get",a,!0);d.responseType= -c;d.send()})}};window.requestAnimationFrame||(window.requestAnimationFrame=window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,window.requestAnimationFrame||(window.requestAnimationFrame=function(a){window.setTimeout(a,17)}));(function(a){var b=function(a){var b=1*a[0],c=1*a[1],f=1*a[2],c=0>c?0:255f?0:255=c?a=c*(255+f)/255:(a=c*f/255,a=c+f-a);var d=2*c-a;if(0>b||360<=b)b=(b%360+360)%360;var g=b+ -120;360<=g&&(g-=360);c=60>g?d+(a-d)*g/60:180>g?a:240>g?d+(a-d)*(240-g)/60:d;g=b;f=60>g?d+(a-d)*g/60:180>g?a:240>g?d+(a-d)*(240-g)/60:d;g=b-120;0>g&&(g+=360);b=60>g?d+(a-d)*g/60:180>g?a:240>g?d+(a-d)*(240-g)/60:d;return[0>c?0:255f?0:255b?0:255(b=parseFloat(a))?0:100(b=parseFloat(a))?0:1(b=parseInt(a,10))?0:255a||360<=a)a=(a%360+360)%360;return a}var k=null;if(!a)return null;var l;if(null!==(k=/^#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})$/.exec(a)))return[parseInt(k[1],16),parseInt(k[2],16),parseInt(k[3],16),255];if(null!==(k=/^rgb\(\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?%)\s*\)$/.exec(a)))return[g(k[1]),g(k[2]),g(k[3]),255];if(null!==(k=/^rgb\(\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+)\s*\)$/.exec(a)))return[e(k[1]),e(k[2]), -e(k[3]),255];if(null!==(k=/^rgba\(\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?)\s*\)$/.exec(a)))return[g(k[1]),g(k[2]),g(k[3]),m(k[4])];if(null!==(k=/^rgba\(\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+(?:\.\d+)?)\s*\)$/.exec(a)))return[e(k[1]),e(k[2]),e(k[3]),m(k[4])];if(null!==(k=/^#([A-Fa-f0-9]{1})([A-Fa-f0-9]{1})([A-Fa-f0-9]{1})$/.exec(a))){var n=parseInt(k[1],16);a=parseInt(k[2],16);l=parseInt(k[3], -16);return[n+(n<<4),a+(a<<4),l+(l<<4),255]}if(null!==(k=/^hsl\(\s*([\+\-]?\d+(?:\.\d+)?)\s*,\s*([\+\-]?\d+(?:\.\d+)?)%\s*,\s*([\+\-]?\d+(?:\.\d+)?)%\s*\)$/.exec(a)))return a=b([h(k[1]),g(k[3]),g(k[2])]),[a[0],a[1],a[2],255];if(null!==(k=/^hsla\(\s*([\+\-]?\d+(?:\.\d+)?)\s*,\s*([\+\-]?\d+(?:\.\d+)?)%\s*,\s*([\+\-]?\d+(?:\.\d+)?)%\s*,\s*([\+\-]?\d+(?:\.\d+)?)\s*\)$/.exec(a)))return a=b([h(k[1]),g(k[3]),g(k[2])]),[a[0],a[1],a[2],m(k[4])];d();a=a.toLowerCase();0<=a.indexOf("grey")&&(a=a.replace("grey", -"gray"));l=f[a];return"string"===typeof l?c(l):"transparent"===a?[0,0,0,0]:null};a.toGLColor=function(a,b,f,d){return null==a?[0,0,0,0]:"string"==typeof a?(a=c(a)||[0,0,0,0],b=1/255,a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b,a):"number"==typeof a&&"number"==typeof b&&"number"==typeof f?[a,b,f,"number"!=typeof d?1:d]:a.constructor==Array?[a[0]||0,a[1]||0,a[2]||0,"number"!=typeof a[3]?1:a[3]]:a||[0,0,0,0]};var f=null,d=function(){if(!f){var a="aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4 black 000000 blanchedalmond ffebcd blue 0000ff blueviolet 8a2be2 brown a52a2a burlywood deb887 cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc crimson dc143c cyan 00ffff darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9 darkgreen 006400 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00 darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b darkslategray 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493 deepskyblue 00bfff dimgray 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0 forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 gray 808080 green 008000 greenyellow adff2f honeydew f0fff0 hotpink ff69b4 indianred cd5c5c indigo 4b0082 ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3 lightgreen 90ee90 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa lightskyblue 87cefa lightslategray 778899 lightsteelblue b0c4de lightyellow ffffe0 lime 00ff00 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370d8 mediumseagreen 3cb371 mediumslateblue 7b68ee mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23 orange ffa500 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee palevioletred d87093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f pink ffc0cb plum dda0dd powderblue b0e0e6 purple 800080 rebeccapurple 663399 red ff0000 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513 salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb slateblue 6a5acd slategray 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c teal 008080 thistle d8bfd8 tomato ff6347 turquoise 40e0d0 violet ee82ee wheat f5deb3 white ffffff whitesmoke f5f5f5 yellow ffff00 yellowgreen 9acd32".split(" "); -f={};for(var b=0;b=a)return!1;for(;1>=1;return 1==a};c.prototype.setParams=function(a){null!=a.ambient&&(this.ambient=n.toGLColor(a.ambient));if(null!=a.position){var b=a.position;this.position=[b[0],b[1],b[2],null==b[3]?0:b[3]]}null!=a.specular&&(this.specular=n.toGLColor(a.specular));null!=a.diffuse&&(this.diffuse=n.toGLColor(a.diffuse)); +function l(a){if(null==a)throw Error("mesh is null");this.bufferedMesh=a;this.transform=new Transform;this.material=new d;this.parent=null}if(!b.GLUtil){var p={renderLoop:function(a){a();var b=function(){window.requestAnimationFrame(b);a()};window.requestAnimationFrame(b)},createCanvas:function(a,b,c){var e=document.createElement("canvas");if(null==a)e.width=Math.ceil(window.innerWidth)+"";else{if(0>a)throw Error("width negative");e.width=Math.ceil(a)+""}if(null==b)e.height=Math.ceil(window.innerHeight)+ +"";else{if(0>b)throw Error("height negative");e.height=Math.ceil(b)+""}c&&c.appendChild(e);return e},get3DOr2DContext:function(a){if(!a||!a.getContext)return null;var b=null,c={antialias:!0};try{b=a.getContext("webgl",c)}catch(e){b=null}if(!b)try{b=a.getContext("experimental-webgl",c)}catch(d){b=null}if(!b)try{b=a.getContext("moz-webgl",c)}catch(g){b=null}if(!b)try{b=a.getContext("webkit-3d",c)}catch(f){b=null}if(!b)try{b=a.getContext("2d",c)}catch(h){b=null}p.is3DContext(b)&&b.getExtension("OES_element_index_uint"); +return b},get3DContext:function(a,b){var c=p.get3DOr2DContext(a),e=null;!c&&window.WebGLShader?e="Failed to initialize graphics support required by this page.":window.WebGLShader&&!p.is3DContext(c)?e="This page requires WebGL, but it failed to start. Your computer might not support WebGL.":c&&p.is3DContext(c)||(e="This page requires a WebGL-supporting browser.");return e?((b||window.alert)(e),null):c},is3DContext:function(a){return a&&"compileShader"in a},getPromiseResults:function(a,b,c){if(!a|| +0==a.length)return Promise.resolve({successes:[],failures:[],results:[]});for(var e={successes:[],failures:[],results:[]},d=[],g=0;gd.status){var g=d.response;g||(g="xml"==c?d.responseXML:"json"==c?(d.responseJSON||JSON.parse(d.responseText))+"":"arraybuffer"==c?d.response:d.responseText+"");b({url:a,data:g})}else e({url:a})};d.onerror=function(b){e({url:a,error:b})};d.open("get",a,!0);d.responseType= +c;d.send()})}};window.requestAnimationFrame||(window.requestAnimationFrame=window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,window.requestAnimationFrame||(window.requestAnimationFrame=function(a){window.setTimeout(a,17)}));(function(a){var b=function(a){var b=1*a[0],c=1*a[1],e=1*a[2],c=0>c?0:255e?0:255=c?a=c*(255+e)/255:(a=c*e/255,a=c+e-a);var d=2*c-a;if(0>b||360<=b)b=(b%360+360)%360;var n=b+ +120;360<=n&&(n-=360);c=60>n?d+(a-d)*n/60:180>n?a:240>n?d+(a-d)*(240-n)/60:d;n=b;e=60>n?d+(a-d)*n/60:180>n?a:240>n?d+(a-d)*(240-n)/60:d;n=b-120;0>n&&(n+=360);b=60>n?d+(a-d)*n/60:180>n?a:240>n?d+(a-d)*(240-n)/60:d;return[0>c?0:255e?0:255b?0:255(b=parseFloat(a))?0:100(b=parseFloat(a))?0:1(b=parseInt(a,10))?0:255a||360<=a)a=(a%360+360)%360;return a}var k=null;if(!a)return null;var l;if(null!==(k=/^#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})$/.exec(a)))return[parseInt(k[1],16),parseInt(k[2],16),parseInt(k[3],16),255];if(null!==(k=/^rgb\(\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?%)\s*\)$/.exec(a)))return[n(k[1]),n(k[2]),n(k[3]),255];if(null!==(k=/^rgb\(\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+)\s*\)$/.exec(a)))return[f(k[1]),f(k[2]), +f(k[3]),255];if(null!==(k=/^rgba\(\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?%)\s*,\s*([\+\-]?\d+(?:\.\d+)?)\s*\)$/.exec(a)))return[n(k[1]),n(k[2]),n(k[3]),g(k[4])];if(null!==(k=/^rgba\(\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+)\s*,\s*([\+\-]?\d+(?:\.\d+)?)\s*\)$/.exec(a)))return[f(k[1]),f(k[2]),f(k[3]),g(k[4])];if(null!==(k=/^#([A-Fa-f0-9]{1})([A-Fa-f0-9]{1})([A-Fa-f0-9]{1})$/.exec(a))){var p=parseInt(k[1],16);a=parseInt(k[2],16);l=parseInt(k[3], +16);return[p+(p<<4),a+(a<<4),l+(l<<4),255]}if(null!==(k=/^hsl\(\s*([\+\-]?\d+(?:\.\d+)?)\s*,\s*([\+\-]?\d+(?:\.\d+)?)%\s*,\s*([\+\-]?\d+(?:\.\d+)?)%\s*\)$/.exec(a)))return a=b([h(k[1]),n(k[3]),n(k[2])]),[a[0],a[1],a[2],255];if(null!==(k=/^hsla\(\s*([\+\-]?\d+(?:\.\d+)?)\s*,\s*([\+\-]?\d+(?:\.\d+)?)%\s*,\s*([\+\-]?\d+(?:\.\d+)?)%\s*,\s*([\+\-]?\d+(?:\.\d+)?)\s*\)$/.exec(a)))return a=b([h(k[1]),n(k[3]),n(k[2])]),[a[0],a[1],a[2],g(k[4])];d();a=a.toLowerCase();0<=a.indexOf("grey")&&(a=a.replace("grey", +"gray"));l=e[a];return"string"===typeof l?c(l):"transparent"===a?[0,0,0,0]:null};a.toGLColor=function(a,b,e,d){return null==a?[0,0,0,0]:"string"==typeof a?(a=c(a)||[0,0,0,0],b=1/255,a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b,a):"number"==typeof a&&"number"==typeof b&&"number"==typeof e?[a,b,e,"number"!=typeof d?1:d]:a.constructor==Array?[a[0]||0,a[1]||0,a[2]||0,"number"!=typeof a[3]?1:a[3]]:a||[0,0,0,0]};var e=null,d=function(){if(!e){var a="aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4 black 000000 blanchedalmond ffebcd blue 0000ff blueviolet 8a2be2 brown a52a2a burlywood deb887 cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc crimson dc143c cyan 00ffff darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9 darkgreen 006400 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00 darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b darkslategray 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493 deepskyblue 00bfff dimgray 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0 forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 gray 808080 green 008000 greenyellow adff2f honeydew f0fff0 hotpink ff69b4 indianred cd5c5c indigo 4b0082 ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3 lightgreen 90ee90 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa lightskyblue 87cefa lightslategray 778899 lightsteelblue b0c4de lightyellow ffffe0 lime 00ff00 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370d8 mediumseagreen 3cb371 mediumslateblue 7b68ee mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23 orange ffa500 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee palevioletred d87093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f pink ffc0cb plum dda0dd powderblue b0e0e6 purple 800080 rebeccapurple 663399 red ff0000 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513 salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb slateblue 6a5acd slategray 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c teal 008080 thistle d8bfd8 tomato ff6347 turquoise 40e0d0 violet ee82ee wheat f5deb3 white ffffff whitesmoke f5f5f5 yellow ffff00 yellowgreen 9acd32".split(" "); +e={};for(var b=0;b=a)return!1;for(;1>=1;return 1==a};c.prototype.setParams=function(a){null!=a.ambient&&(this.ambient=p.toGLColor(a.ambient));if(null!=a.position){var b=a.position;this.position=[b[0],b[1],b[2],null==b[3]?0:b[3]]}null!=a.specular&&(this.specular=p.toGLColor(a.specular));null!=a.diffuse&&(this.diffuse=p.toGLColor(a.diffuse)); return this};a.MAX_LIGHTS=3;a._createNewLight=function(a){var b=new c;0!=a&&(b.diffuse=[0,0,0,0],b.specular=[0,0,0]);return b};a.prototype.getLight=function(b){this.lights[b]||(this.lights[b]=a._createNewLight(b));return this.lights[b]};a.prototype.setParams=function(a,b){this.getLight(a).setParams(b);return this};a.prototype.setDirectionalLight=function(a,b){return this.setParams(a,{position:[b[0],b[1],b[2],0]})};a.prototype.setPointLight=function(a,b){return this.setParams(a,{position:[b[0],b[1], -b[2],1]})};d.prototype.copy=function(){return(new d(this.ambient.slice(0,this.ambient.length),this.diffuse.slice(0,this.diffuse.length),this.specular.slice(0,this.specular.length),this.shininess,this.emission.slice(0,this.emission.length))).setParams({texture:this.texture})};d.prototype.setParams=function(a){null!=a.ambient&&(this.ambient=n.toGLColor(a.ambient));null!=a.diffuse&&(this.diffuse=n.toGLColor(a.diffuse));null!=a.specular&&(this.specular=n.toGLColor(a.specular));null!=a.emission&&(this.emission= -n.toGLColor(a.emission));null!=a.shininess&&(this.shininess=a.shininess);null!=a.texture&&(a=a.texture,this.texture="string"==typeof a?new p(a):a);return this};d.fromColor=function(a,b,c,f){a=n.toGLColor(a,b,c,f);return new d(a,a)};d.fromTexture=function(a){return(new d).setParams({texture:a})};var p=function(a){this.image=null;this.loadStatus=0;this.loadedTexture=null;this.name=a;this.width=0;this.clamp=!1;this.height=0};p.prototype.setClamp=function(a){this.clamp=a;return this};p.loadTexture=function(a, -b){if(b&&b[a])return Promise.resolve(b[a]);var c=new p(a);b&&(b[a]=c);return c.loadImage().then(function(a){return a},function(a){return Promise.reject(a.name)})};p.fromUint8Array=function(a,b,c){if(0>b)throw Error("width less than 0");if(0>c)throw Error("height less than 0");if(a.lengthb)throw Error("width less than 0");if(0>c)throw Error("height less than 0");if(a.lengtha||0>b)throw Error("width or height negative");this.width=Math.ceil(a);this.height=Math.ceil(b);this.context.canvas.width=this.width+"";this.context.canvas.height=this.height+"";this.context.viewport(0,0,this.width,this.height);"undefined"!=this.fbo&&this.fbo&&(this.fbo.dispose(),this.fbo=this.createBuffer())};f.prototype.getWidth=function(){return this.width};f.prototype.getHeight=function(){return this.height};f.prototype.getAspect=function(){return this.getWidth()/this.getHeight()}; -f.prototype.createBuffer=function(){return new g(this.context,this.getWidth(),this.getHeight())};f.prototype.getProjectionMatrix=function(){return this._projectionMatrix.slice(0,16)};f.prototype.getViewMatrix=function(){return this._viewMatrix.slice(0,16)};f.prototype.setPerspective=function(a,b,c,f){return this.setProjectionMatrix(GLMath.mat4perspective(a,b,c,f))};f.prototype.setOrthoAspect=function(a,b,c,f,d,g,e){null==e&&(e=this.getAspect());0==e&&(e=1);return this.setProjectionMatrix(GLMath.mat4orthoAspect(a, -b,c,f,d,g,e))};f.prototype.setOrtho2DAspect=function(a,b,c,f,d){return this.setOrthoAspect(a,b,c,f,-1,1,d)};f.prototype.setFrustum=function(a,b,c,f,d,g){return this.setProjectionMatrix(GLMath.mat4frustum(a,b,f,c,d,g))};f.prototype.setOrtho=function(a,b,c,f,d,g){return this.setProjectionMatrix(GLMath.mat4ortho(a,b,c,f,d,g))};f.prototype.setOrtho2D=function(a,b,c,f){return this.setProjectionMatrix(GLMath.mat4ortho(a,b,c,f,-1,1))};f.prototype._setClearColor=function(){this.context.clearColor(this.clearColor[0], -this.clearColor[1],this.clearColor[2],this.clearColor[3]);return this};f.prototype.setClearColor=function(a,b,c,f){this.clearColor=n.toGLColor(a,b,c,f);return this._setClearColor()};f.prototype.loadTexture=function(a){return p.loadTexture(a,this.textureCache)};f.prototype.loadAndMapTexture=function(a){var b=this.context,c=null,c=a.constructor==p?a.loadImage():p.loadTexture(a,this.context,this.textureCache);return c.then(function(a){a.loadedTexture=new LoadedTexture(a,b);return a})};f.prototype.loadAndMapTextures= -function(a,b,c){for(var f=[],d=0;da||0>b)throw Error("width or height negative");this.width=Math.ceil(a);this.height=Math.ceil(b);this.context.canvas.width=this.width+"";this.context.canvas.height=this.height+"";this.context.viewport(0,0,this.width,this.height);"undefined"!=this.fbo&&this.fbo&&(this.fbo.dispose(),this.fbo=this.createBuffer())};e.prototype.getWidth=function(){return this.width};e.prototype.getHeight=function(){return this.height};e.prototype.getAspect=function(){return this.getWidth()/this.getHeight()}; +e.prototype.createBuffer=function(){return new g(this.context,this.getWidth(),this.getHeight())};e.prototype.getProjectionMatrix=function(){return this._projectionMatrix.slice(0,16)};e.prototype.getViewMatrix=function(){return this._viewMatrix.slice(0,16)};e.prototype.setPerspective=function(a,b,c,e){return this.setProjectionMatrix(GLMath.mat4perspective(a,b,c,e))};e.prototype.setOrthoAspect=function(a,b,c,e,d,g,f){null==f&&(f=this.getAspect());0==f&&(f=1);return this.setProjectionMatrix(GLMath.mat4orthoAspect(a, +b,c,e,d,g,f))};e.prototype.setOrtho2DAspect=function(a,b,c,e,d){return this.setOrthoAspect(a,b,c,e,-1,1,d)};e.prototype.setFrustum=function(a,b,c,e,d,g){return this.setProjectionMatrix(GLMath.mat4frustum(a,b,e,c,d,g))};e.prototype.setOrtho=function(a,b,c,e,d,g){return this.setProjectionMatrix(GLMath.mat4ortho(a,b,c,e,d,g))};e.prototype.setOrtho2D=function(a,b,c,e){return this.setProjectionMatrix(GLMath.mat4ortho(a,b,c,e,-1,1))};e.prototype._setClearColor=function(){this.context.clearColor(this.clearColor[0], +this.clearColor[1],this.clearColor[2],this.clearColor[3]);return this};e.prototype.setClearColor=function(a,b,c,e){this.clearColor=p.toGLColor(a,b,c,e);return this._setClearColor()};e.prototype.loadTexture=function(a){return q.loadTexture(a,this.textureCache)};e.prototype.loadAndMapTexture=function(a){var b=this.context,c=null,c=a.constructor==q?a.loadImage():q.loadTexture(a,this.context,this.textureCache);return c.then(function(a){a.loadedTexture=new LoadedTexture(a,b);return a})};e.prototype.loadAndMapTextures= +function(a,b,c){for(var e=[],d=0;dthis.mshade.diffuse.length?1:this.mshade.diffuse[3]],ms:3==this.mshade.specular.length?this.mshade.specular:[this.mshade.specular[0], this.mshade.specular[1],this.mshade.specular[2]],me:3==this.mshade.emission.length?this.mshade.emission:[this.mshade.emission[0],this.mshade.emission[1],this.mshade.emission[2]]});this.mshade.texture&&(new TextureBinder(this.mshade.texture)).bind(b);return this}; function LoadedTexture(b,c){this.context=c=GLUtil._toContext(c);this.textureUnit=0;this.loadedTexture=c.createTexture();c.activeTexture(c.TEXTURE0+this.textureUnit);c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL,1);c.bindTexture(c.TEXTURE_2D,this.loadedTexture);"src"in b.image?c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,b.image):c.texImage2D(c.TEXTURE_2D,0,c.RGBA,b.width,b.height,0,c.RGBA,c.UNSIGNED_BYTE,b.image);GLUtil._isPowerOfTwo(b.width)&&GLUtil._isPowerOfTwo(b.height)?c.generateMipmap(c.TEXTURE_2D): (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))}LoadedTexture.prototype.dispose=function(){this.loadedTexture&&this.context.deleteTexture(this.loadedTexture)};function FrameBufferMaterialBinder(b){this.fb=b} FrameBufferMaterialBinder.prototype.bind=function(b){var c={};c.sampler=this.fb.textureUnit;c.textureSize=[this.fb.width,this.fb.height];b.setUniforms(c);b=b.getContext();b.activeTexture(b.TEXTURE0+this.fb.textureUnit);b.bindTexture(b.TEXTURE_2D,this.fb.colorTexture);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.CLAMP_TO_EDGE);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.CLAMP_TO_EDGE)}; function TextureBinder(b){this.texture=b} -TextureBinder.prototype.bind=function(b){var c=this.texture,a=b.getContext();if(null!==c.image&&null===c.loadedTexture)c.loadedTexture=new LoadedTexture(c,a);else if(null===c.image&&null===c.loadedTexture&&0==c.loadStatus){var d=this;c.loadImage().then(function(a){d.bind(b)});return}if(null!==c.loadedTexture){var e={};null==c.anisotropic&&(c.anisotropic=a.getExtension("EXT_texture_filter_anisotropic")||a.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||a.getExtension("MOZ_EXT_texture_filter_anisotropic"), -null==c.anisotropic?(c.anisotropic={},c.maxAnisotropy=1):c.maxAnisotropy=a.getParameter(c.anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e.sampler=c.loadedTexture.textureUnit;e.textureSize=[c.width,c.height];b.setUniforms(e);a.activeTexture(a.TEXTURE0+c.loadedTexture.textureUnit);a.bindTexture(a.TEXTURE_2D,c.loadedTexture.loadedTexture);"undefined"!=typeof c.anisotropic.TEXTURE_MAX_ANISOTROPY_EXT&&a.texParameteri(a.TEXTURE_2D,c.anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,c.maxAnisotropy);a.texParameteri(a.TEXTURE_2D, -a.TEXTURE_MAG_FILTER,a.LINEAR);e=a.CLAMP_TO_EDGE;GLUtil._isPowerOfTwo(c.width)&&GLUtil._isPowerOfTwo(c.height)?(c.clamp||(e=a.REPEAT),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR)):a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,e);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,e)}};function LightsBinder(b){this.lights=b} -LightsBinder.prototype.bind=function(b){var c=this.lights;if(!c||!b)return this;var a={};a.sceneAmbient=c.sceneAmbient.slice(0,3);for(var d=0;db)throw Error("invalid mode");if(-1!=this.currentMode&&Mesh._isCompatibleMode(this.currentMode,b))this.subMeshes[this.subMeshes.length-1].newPrimitive();else{var c=0,a=Mesh._primitiveType(b);a==Mesh.LINES?c|=Mesh.LINES_BIT:a==Mesh.POINTS&&(c|=Mesh.POINTS_BIT);this.subMeshes.push(new SubMesh([],[],c))}this.currentMode=b;return this}; -Mesh.prototype.merge=function(b){for(var c=this.subMeshes[this.subMeshes.length-1],a=c?c.attributeBits&Mesh.PRIMITIVES_BITS:0,d=0;dd))for(b=0;bb)return this;"undefined"==typeof a&&"undefined"==typeof d&&(a=c[1],d=c[2],c=c[0]);for(var e=0,h=0;hb)return this;var e=0;"undefined"==typeof a&&"undefined"==typeof d&&(a=c[1],d=c[2],c=c[0]);for(var h=0;hb)return null;for(var c=0,a=0;ad))for(b=0;bb)return this;"undefined"==typeof a&&"undefined"==typeof d&&(a=c[1],d=c[2],c=c[0]);for(var f=0,h=0;hb)return this;var f=0;"undefined"==typeof a&&"undefined"==typeof d&&(a=c[1],d=c[2],c=c[0]);for(var h=0;hb)return null;for(var c=0,a=0;ap;a-=b,p++){for(var q=7,r=0;r=4*a&&0==(this.vertices.length-this.startIndex)%(2*a)?(f=this.vertices.length/a-4,this._setTriangle(k,a,f,f+1,f+2),this._setTriangle(k,a,f+2,f+1,f+3)):f==Mesh.QUADS&&0==(this.vertices.length-this.startIndex)%(4*a)?(f=this.vertices.length/a-4,this._setTriangle(k,a,f,f+1,f+2),this._setTriangle(k,a,f,f+2,f+3)):f==Mesh.TRIANGLES&&0==(this.vertices.length-this.startIndex)% -(3*a)?(f=this.vertices.length/a-3,this._setTriangle(k,a,f,f+1,f+2)):f==Mesh.LINES&&0==(this.vertices.length-this.startIndex)%(2*a)?(f=this.vertices.length/a-2,this.indices.push(f,f+1)):f==Mesh.TRIANGLE_FAN&&this.vertices.length-this.startIndex>=3*a?(f=this.vertices.length/a-2,b=this.startIndex/a,this._setTriangle(k,a,b,f,f+1)):f==Mesh.LINE_STRIP&&this.vertices.length-this.startIndex>=2*a?(f=this.vertices.length/a-2,this.indices.push(f,f+1)):f==Mesh.POINTS?(f=this.vertices.length/a-1,this.indices.push(f)): -f==Mesh.TRIANGLE_STRIP&&this.vertices.length-this.startIndex>=3*a&&(f=this.vertices.length/a-3,b=this.startIndex/a,0==(f-b&1)?this._setTriangle(k,a,f,f+1,f+2):this._setTriangle(k,a,f+1,f,f+2));return this}}SubMesh.prototype.makeRedundant=function(){for(var b=[],c=this.getStride(),a=this.indices.length,d=0;dd.indexOf(g)&&(d.push(g),a.push(c,g)):(b[c]=[g],a.push(c,g))}if(0!=(this.attributeBits&Mesh.PRIMITIVES_BITS))return this;for(var c=[],a={},d=0;dq;a-=b,q++){for(var r=7,t=0;t=4*a&&0==(this.vertices.length-this.startIndex)%(2*a)?(e=this.vertices.length/a-4,this._setTriangle(k,a,e,e+1,e+2),this._setTriangle(k,a,e+2,e+1,e+3)):e==Mesh.QUADS&&0==(this.vertices.length-this.startIndex)%(4*a)?(e=this.vertices.length/a-4,this._setTriangle(k,a,e,e+1,e+2),this._setTriangle(k,a,e,e+2,e+3)):e==Mesh.TRIANGLES&&0==(this.vertices.length-this.startIndex)% +(3*a)?(e=this.vertices.length/a-3,this._setTriangle(k,a,e,e+1,e+2)):e==Mesh.LINES&&0==(this.vertices.length-this.startIndex)%(2*a)?(e=this.vertices.length/a-2,this.indices.push(e,e+1)):e==Mesh.TRIANGLE_FAN&&this.vertices.length-this.startIndex>=3*a?(e=this.vertices.length/a-2,b=this.startIndex/a,this._setTriangle(k,a,b,e,e+1)):e==Mesh.LINE_STRIP&&this.vertices.length-this.startIndex>=2*a?(e=this.vertices.length/a-2,this.indices.push(e,e+1)):e==Mesh.POINTS?(e=this.vertices.length/a-1,this.indices.push(e)): +e==Mesh.TRIANGLE_STRIP&&this.vertices.length-this.startIndex>=3*a&&(e=this.vertices.length/a-3,b=this.startIndex/a,0==(e-b&1)?this._setTriangle(k,a,e,e+1,e+2):this._setTriangle(k,a,e+1,e,e+2));return this}}SubMesh.prototype.makeRedundant=function(){for(var b=[],c=this.getStride(),a=this.indices.length,d=0;dg.indexOf(d)&&(g.push(d),a.push(c,d)):(b[c]=[d],a.push(c,d))}if(0!=(this.attributeBits&Mesh.PRIMITIVES_BITS))return this;for(var c=[],a={},d=0;d=this.order)throw Error("no control points");this.k=a[0].length;this.points=a;this.evaluator=new c(this.order)}function d(b,c,d){if("undefined"==typeof c&&"undefined"==typeof d)this.uoffset=0,this.umul=1;else{if(c==d)throw Error("u1 and u2 can't be equal");this.uoffset=c;this.umul=1/(d-c)}this.evaluator=new a(b);this.k=this.evaluator.k}function e(b,c,d,e,h){if("undefined"==typeof c&&"undefined"==typeof d&& -"undefined"==typeof e&&"undefined"==typeof h)this.uoffset=0,this.umul=1,this.voffset=0,this.vmul=1;else{if(c==d)throw Error("u1 and u2 can't be equal");if(e==h)throw Error("v1 and v2 can't be equal");this.uoffset=c;this.umul=1/(d-c);this.voffset=e;this.vmul=1/(h-e)}this.evaluator=new a(b);this.k=this.evaluator.k}function h(){this.vertexCurve=this.texCoordCurve=this.normalCurve=this.colorCurve=null}c._binomial=[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1],[1,6,15,20,15,6,1],[1,7,21,35,35, +(function(b){function c(a){this.order=a;this.n=this.order-1}function a(a){this.order=a.length;if(0>=this.order)throw Error("no control points");this.k=a[0].length;this.points=a;this.evaluator=new c(this.order)}function d(b,c,d){if("undefined"==typeof c&&"undefined"==typeof d)this.uoffset=0,this.umul=1;else{if(c==d)throw Error("u1 and u2 can't be equal");this.uoffset=c;this.umul=1/(d-c)}this.evaluator=new a(b);this.k=this.evaluator.k}function f(b,c,d,f,h){if("undefined"==typeof c&&"undefined"==typeof d&& +"undefined"==typeof f&&"undefined"==typeof h)this.uoffset=0,this.umul=1,this.voffset=0,this.vmul=1;else{if(c==d)throw Error("u1 and u2 can't be equal");if(f==h)throw Error("v1 and v2 can't be equal");this.uoffset=c;this.umul=1/(d-c);this.voffset=f;this.vmul=1/(h-f)}this.evaluator=new a(b);this.k=this.evaluator.k}function h(){this.vertexCurve=this.texCoordCurve=this.normalCurve=this.colorCurve=null}c._binomial=[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1],[1,6,15,20,15,6,1],[1,7,21,35,35, 21,7,1],[1,8,28,56,70,56,28,8,1],[1,9,36,84,126,126,84,36,9,1],[1,10,45,120,210,252,210,120,45,10,1],[1,11,55,165,330,462,462,330,165,55,11,1],[1,12,66,220,495,792,924,792,495,220,66,12,1],[1,13,78,286,715,1287,1716,1716,1287,715,286,78,13,1],[1,14,91,364,1001,2002,3003,3432,3003,2002,1001,364,91,14,1],[1,15,105,455,1365,3003,5005,6435,6435,5005,3003,1365,455,105,15,1],[1,16,120,560,1820,4368,8008,11440,12870,11440,8008,4368,1820,560,120,16,1],[1,17,136,680,2380,6188,12376,19448,24310,24310,19448, 12376,6188,2380,680,136,17,1],[1,18,153,816,3060,8568,18564,31824,43758,48620,43758,31824,18564,8568,3060,816,153,18,1],[1,19,171,969,3876,11628,27132,50388,75582,92378,92378,75582,50388,27132,11628,3876,969,171,19,1],[1,20,190,1140,4845,15504,38760,77520,125970,167960,184756,167960,125970,77520,38760,15504,4845,1140,190,20,1]];c._factorial=function(a){for(var b=1;1=c)throw Error("invalid n");"undefined"==typeof d&&"undefined"==typeof e&&(d=0,e=1);null==b&&(b=Mesh.LINES);e=(e-d)/c;if(b==Mesh.POINTS)a.mode(Mesh.POINTS);else if(b==Mesh.LINES)a.mode(Mesh.LINE_STRIP);else return this;for(b=0;b<=c;b++)this.evalOne(a,d+b*e);return this};this.SurfaceEval=function(){this.vertexSurface= +return this};h.prototype.evalOne=function(a,b){var c=null,d=null,f=null;this.colorCurve&&(c=this.colorCurve.evaluate(b));this.texCoordCurve&&(f=this.texCoordCurve.evaluate(b),1==f.length&&f.push(0));this.normalCurve&&(d=this.normalCurve.evaluate(b));if(this.vertexCurve){var h=c?a.color.slice(0,3):null,n=d?a.normal.slice(0,3):null,r=f?a.texCoord.slice(0,3):null;c&&a.color3(c[0],c[1],c[2]);d&&a.normal3(d[0],d[1],d[2]);f&&a.texCoord3(f[0],f[1],f[2]);c=this.vertexCurve.evaluate(b);a.vertex3(c[0],c[1], +c[2]);h&&a.color3(h[0],h[1],h[2]);n&&a.normal3(n[0],n[1],n[2]);r&&a.texCoord3(r[0],r[1],r[2])}return this};h.prototype.evalCurve=function(a,b,c,d,f){"undefined"==typeof c&&(c=24);if(0>=c)throw Error("invalid n");"undefined"==typeof d&&"undefined"==typeof f&&(d=0,f=1);null==b&&(b=Mesh.LINES);f=(f-d)/c;if(b==Mesh.POINTS)a.mode(Mesh.POINTS);else if(b==Mesh.LINES)a.mode(Mesh.LINE_STRIP);else return this;for(b=0;b<=c;b++)this.evalOne(a,d+b*f);return this};this.SurfaceEval=function(){this.vertexSurface= this.texCoordSurface=this.normalSurface=this.colorSurface=null;this.autoNormal=!1};SurfaceEval.prototype.setAutoNormal=function(a){this.autoNormal=!!a;return this};SurfaceEval.prototype.vertex=function(a){this.vertexSurface=a;return this};SurfaceEval.prototype.normal=function(a){this.normalSurface=a;return this};SurfaceEval.prototype.color=function(a){this.colorSurface=a;return this};SurfaceEval.prototype.texCoord=function(a){this.texCoordSurface=a;return this};SurfaceEval.prototype.vertexBezier= -function(a,b,c,d,h){this.vertexSurface=new e(a,b,c,d,h);if(3!=this.vertexSurface.k)throw Error("unsupported vertex length");return this};SurfaceEval.prototype.normalBezier=function(a,b,c,d,h){this.normalSurface=new e(a,b,c,d,h);if(3!=this.normalSurface.k)throw Error("invalid normal length");return this};SurfaceEval.prototype.texCoordBezier=function(a,b,c,d,h){this.texCoordSurface=new e(a,b,c,d,h);if(1!=this.texCoordSurface.k&&2!=this.texCoordSurface.k)throw Error("unsupported texcoord length");return this}; -SurfaceEval.prototype.colorBezier=function(a,b,c,d,h){this.colorSurface=new e(a,b,c,d,h);if(3!=this.colorSurface.k)throw Error("unsupported color length");return this};SurfaceEval.prototype.evalOne=function(a,b,c){var d=null,e=null,h=null;this.colorSurface&&(d=this.colorSurface.evaluate(b,c));this.texCoordSurface&&(h=this.texCoordSurface.evaluate(b,c),1==h.length&&h.push(0));this.normalSurface&&!this.autoNormal&&(e=this.normalSurface.evaluate(b,c));if(this.vertexSurface){var m=d?a.color.slice(0,3): -null,q=e||this.autoNormal?a.normal.slice(0,3):null,r=h?a.texCoord.slice(0,3):null;d&&a.color3(d[0],d[1],d[2]);d=this.vertexSurface.evaluate(b,c);this.autoNormal?(e=this.vertexSurface.evaluate(b+.001,c),b=this.vertexSurface.evaluate(b,c+.001),GLMath.vec3subInPlace(b,d),GLMath.vec3subInPlace(e,d),GLMath.vec3scaleInPlace(e,1E3),GLMath.vec3scaleInPlace(b,1E3),GLMath.vec3normInPlace(e),GLMath.vec3normInPlace(b),0==GLMath.vec3length(e)?e=b:0!=GLMath.vec3length(b)&&(e=GLMath.vec3cross(e,b),GLMath.vec3normInPlace(e)), -a.normal3(e[0],e[1],e[2])):e&&a.normal3(e[0],e[1],e[2]);h&&a.texCoord3(h[0],h[1],h[2]);a.vertex3(d[0],d[1],d[2]);m&&a.color3(m[0],m[1],m[2]);q&&a.normal3(q[0],q[1],q[2]);r&&a.texCoord3(r[0],r[1],r[2])}return this};SurfaceEval.prototype.evalSurface=function(a,b,c,d,e,h,m,q){"undefined"==typeof c&&(c=24);"undefined"==typeof d&&(d=24);if(0>=c)throw Error("invalid un");if(0>=d)throw Error("invalid vn");null==b&&(b=Mesh.TRIANGLES);"undefined"==typeof m&&"undefined"==typeof q&&(m=0,q=1);"undefined"==typeof e&& -"undefined"==typeof h&&(e=0,h=1);h=(h-e)/c;q=(q-m)/d;if(b==Mesh.TRIANGLES)for(b=0;b=c)throw Error("invalid un");if(0>=d)throw Error("invalid vn");null==b&&(b=Mesh.TRIANGLES);"undefined"==typeof n&&"undefined"==typeof r&&(n=0,r=1);"undefined"==typeof f&& +"undefined"==typeof h&&(f=0,h=1);h=(h-f)/c;r=(r-n)/d;if(b==Mesh.TRIANGLES)for(b=0;b=d)throw Error("too few slices");if(1>e)throw Error("too few stacks");if(0>a)throw Error("negative height");if(0>=b&&0>=c||0==a)return f;for(var k=g?-1:1,l=[0,1],n=[0],p=GLMath.PiTimes2,m=1;m=a)throw Error("too few slices");if(1>d)throw Error("too few loops");if(b>c)throw Error("inner greater than outer");0>b&&(b=0);0>c&&(c=0);if(0==c||0==h)return f;var k=360==h&&0==e,l=0>h?-1:1;0>h&&(h=-h);h%=360;0==h&&(h=360);var n=[],p=[],m=GLMath.PiTimes2;h=360==h?m:h*GLMath.PiDividedBy180;e*=GLMath.PiDividedBy180;0>l&&(h=-h);for(l=0;l<=a;l++){var q=1*l/a,r=e+h*q,r=0> -r?m- -r%m:r%m;n.push(Math.sin(r),Math.cos(r));p.push(q)}k&&(n[0]=0,n[1]=1,n[n.length-1]=1,n[n.length-2]=0,p[0]=0,p[p.length-1]=1);a*=2;e=c-b;k=b;g?f.normal3(0,0,-1):f.normal3(0,0,1);for(l=0;ld)throw Error("crosswise is less than 3");if(3>a)throw Error("lengthwise is less than 3");if(0>b||0>c)throw Error("inner or outer is less than 0");if(0==c||0==b)return g;for(var f=GLMath.PiTimes2,k=[],l=[],n=0;n<=d;n++){var p=n*f/d;k.push(Math.sin(p),Math.cos(p))}for(n=0;n<=a;n++)p=n*f/a,l.push(Math.sin(p),Math.cos(p));for(f=0;fb||0>c)throw Error("width or height is less than 0");if(0>=d||0>=a)throw Error("widthDiv or heightDiv is 0 or less");if(0==b||0==c)return h;var g=.5*-b,f=.5*-c;e?h.normal3(0,0,-1):h.normal3(0,0,1);for(e=0;ed)throw Error("too few stacks");return Meshes._createCapsule(b,c,a,2*d,e,h,g)}; -Meshes._createCapsule=function(b,c,a,d,e,h,g){function f(a,b,c,d,e,f){a.normal3(c*b,d*b,e*b);a.vertex3(c,d,e+f)}var k=new Mesh;null==a&&(a=16);null==d&&(d=16);null==e&&(e=1);null==b&&(b=1);null==c&&(c=1);if(2>d)throw Error("too few stacks");if(2>=a)throw Error("too few slices");if(1>e&&0c)throw Error("negative length");if(0>b)throw Error("negative radius");if(0==b)return k;for(var l=.5*c,n=d/2,p=g?-1:1,m=[0,1],q=[],r=[],t=[0],w=GLMath.PiTimes2,x=1;x=d)throw Error("too few slices");if(1>f)throw Error("too few stacks");if(0>a)throw Error("negative height");if(0>=b&&0>=c||0==a)return e;for(var k=g?-1:1,l=[0,1],p=[0],q=GLMath.PiTimes2,n=1;n=a)throw Error("too few slices");if(1>d)throw Error("too few loops");if(b>c)throw Error("inner greater than outer");0>b&&(b=0);0>c&&(c=0);if(0==c||0==h)return e;var k=360==h&&0==f,l=0>h?-1:1;0>h&&(h=-h);h%=360;0==h&&(h=360);var p=[],q=[],n=GLMath.PiTimes2;h=360==h?n:h*GLMath.PiDividedBy180;f*=GLMath.PiDividedBy180;0>l&&(h=-h);for(l=0;l<=a;l++){var r=1*l/a,t=f+h*r,t=0> +t?n- -t%n:t%n;p.push(Math.sin(t),Math.cos(t));q.push(r)}k&&(p[0]=0,p[1]=1,p[p.length-1]=1,p[p.length-2]=0,q[0]=0,q[q.length-1]=1);a*=2;f=c-b;k=b;g?e.normal3(0,0,-1):e.normal3(0,0,1);for(l=0;ld)throw Error("crosswise is less than 3");if(3>a)throw Error("lengthwise is less than 3");if(0>b||0>c)throw Error("inner or outer is less than 0");if(0==c||0==b)return g;for(var e=GLMath.PiTimes2,k=[],l=[],p=0;p<=d;p++){var q=p*e/d;k.push(Math.sin(q),Math.cos(q))}for(p=0;p<=a;p++)q=p*e/a,l.push(Math.sin(q),Math.cos(q));for(e=0;eb||0>c)throw Error("width or height is less than 0");if(0>=d||0>=a)throw Error("widthDiv or heightDiv is 0 or less");if(0==b||0==c)return h;var g=.5*-b,e=.5*-c;f?h.normal3(0,0,-1):h.normal3(0,0,1);for(f=0;fd)throw Error("too few stacks");return Meshes._createCapsule(b,c,a,2*d,f,h,g)}; +Meshes._createCapsule=function(b,c,a,d,f,h,g){function e(a,b,c,d,e,f){a.normal3(c*b,d*b,e*b);a.vertex3(c,d,e+f)}var k=new Mesh;null==a&&(a=16);null==d&&(d=16);null==f&&(f=1);null==b&&(b=1);null==c&&(c=1);if(2>d)throw Error("too few stacks");if(2>=a)throw Error("too few slices");if(1>f&&0c)throw Error("negative length");if(0>b)throw Error("negative radius");if(0==b)return k;for(var l=.5*c,p=d/2,q=g?-1:1,n=[0,1],r=[],t=[],v=[0],x=GLMath.PiTimes2,y=1;y 0.4) {\nreturn edge_color;\n} else {\nreturn back_color;\n}}")}; ShaderProgram.getBasicVertex=function(){};ShaderProgram.getDefaultVertex=function(){return"attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec3 colorAttr;\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\nvarying vec2 uvVar;\nvarying vec3 colorAttrVar;\n#ifdef SHADING\nuniform mat3 worldViewInvTrans3; /* internal */\nvarying vec4 viewWorldPositionVar;\nvarying vec3 transformedNormalVar;\n#endif\nvoid main(){\nvec4 positionVec4;\npositionVec4.w=1.0;\npositionVec4.xyz=position;\ngl_PointSize=1.0;\ngl_Position=((projection*view)*world)*positionVec4;\ncolorAttrVar=colorAttr;\nuvVar=uv;\n#ifdef SHADING\ntransformedNormalVar=normalize(worldViewInvTrans3*normal);\nviewWorldPositionVar=view*world*positionVec4;\n#endif\n}"};