diff --git a/glutil-transform.js b/glutil-transform.js index 57ff9495..8e64e51b 100644 --- a/glutil-transform.js +++ b/glutil-transform.js @@ -332,6 +332,7 @@ Transform.prototype.getMatrix=function(){ GLMath.quatToMat4(this.rotation)); // 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 && diff --git a/glutil_min.js b/glutil_min.js index 78bf1670..bcad83ef 100644 --- a/glutil_min.js +++ b/glutil_min.js @@ -1,100 +1,100 @@ -(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++)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], +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],g=a[0]*a[5],h=a[0]*a[6],f=a[0]*a[7],k=a[0]*a[9],l=a[10]*a[12],n=a[10]*a[13],p=a[10]*a[15],m=a[11]*a[12],q=a[11]*a[13],r=a[11]*a[14],t=a[1]*a[4],w=a[1]*a[6],x=a[1]*a[7],I=a[1]*a[8],A=a[2]*a[4],E=a[2]*a[5],D=a[2]*a[7],z=a[2]*a[8],y=a[2]*a[9],v=a[3]*a[4],C=a[3]*a[5],B=a[3]*a[6],K=a[3]*a[8],G=a[3]*a[9],N=a[4]*a[9],O=a[5]*a[8],M=a[6]*a[8],P=a[6]*a[9],H=a[7]*a[8],L=a[7]*a[9],F=t-g,J=w-E,Q=x- +C,R=A-h,g=g-t,w=E-w,E=D-B,t=v-f,x=C-x,D=B-D,h=h-A,A=f-v,f=a[9]*a[12]*D+l*Q+m*w+a[8]*a[13]*E+n*t+q*h+a[8]*a[14]*x+a[9]*a[14]*A+r*F+a[8]*a[15]*J+a[9]*a[15]*R+p*g;if(0==f)return c.mat4identity();f=1/f;v=[];v[0]=a[6]*q-a[7]*n+L*a[14]-a[5]*r-P*a[15]+a[5]*p;v[1]=a[3]*n-a[2]*q-G*a[14]+a[1]*r+y*a[15]-a[1]*p;v[2]=a[13]*E+a[14]*x+a[15]*J;v[3]=a[9]*D+a[10]*Q+a[11]*w;v[4]=a[7]*l-a[6]*m-H*a[14]+a[4]*r+M*a[15]-a[4]*p;v[5]=a[2]*m-a[3]*l+a[14]*(K-b)+a[15]*(d-z);v[6]=a[12]*D+a[14]*A+a[15]*R;v[7]=a[8]*E+a[10]*t+a[11]* +h;v[8]=a[5]*m-L*a[12]+H*a[13]-a[4]*q+a[15]*(N-O);v[9]=G*a[12]-a[1]*m+a[13]*(b-K)+a[15]*(I-k);v[10]=a[12]*Q+a[13]*t+a[15]*g;v[11]=a[8]*x+a[9]*A+a[11]*F;v[12]=P*a[12]-a[5]*l-M*a[13]+a[4]*n+a[14]*(O-N);v[13]=a[1]*l-y*a[12]+a[13]*(z-d)+a[14]*(k-I);v[14]=a[12]*w+a[13]*h+a[14]*F;v[15]=a[8]*J+a[9]*R+a[10]*g;for(a=0;16>a;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,h,f,k,l,n,p;d=2*a[0];b=2*a[1];c=2*a[2];h=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-(h+p),n+d,0,k+b,n-d,1-(h+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(g);g=Math.sin(g);h=c.vec3normInPlace([h,b,d]);h=[h[0],h[1],h[2],a];h[0]*=g;h[1]*=g;h[2]*=g;return h},quatFromTaitBryan:function(a,d,b,g){var h,f;null==g&&(g=c.RollPitchYaw);if(0>g|| +6<=g)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,h=(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,h=(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(h);h=Math.cos(h);d=Math.sin(f);f=Math.cos(f);var k=Math.sin(b);b=Math.cos(b); +if(g==c.PitchYawRoll||g==c.PitchRollYaw){var l=[k*d,b*d,k*f,b*f];g==c.PitchYawRoll&&(l[0]=-l[0]);g=[l[3]*a+l[0]*h,l[1]*h+l[2]*a,l[2]*h-l[1]*a,l[3]*h-l[0]*a]}else g==c.YawPitchRoll||g==c.YawRollPitch?(l=[b*a,k*a,k*h,b*h],g==c.YawRollPitch&&(l[1]=-l[1]),g=[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*h,d*a,f*h],g==c.RollPitchYaw&&(l[2]=-l[2]),g=[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 g},quatToTaitBryan:function(a,b){var e=a[3],g,h,f,k=1;null==b&&(b=c.RollPitchYaw); +if(0>b||6<=b)throw Error("invalid mode");b==c.RollPitchYaw?(g=a[1],h=a[0],f=a[2],k=-1):b==c.PitchYawRoll?(g=a[2],h=a[1],f=a[0],k=-1):b==c.PitchRollYaw?(g=a[1],h=a[2],f=a[0]):b==c.YawPitchRoll?(g=a[2],h=a[0],f=a[1]):b==c.YawRollPitch?(g=a[0],h=a[2],f=a[1],k=-1):(g=a[0],h=a[1],f=a[2]);var l=h*h,n=f*f,p=Math.atan2(2*(e*g-k*h*f),1-2*(g*g+l)),m=2*(e*h+k*g*f);1m&&(m=-1);m=Math.asin(m);h=Math.atan2(2*(e*f-k*g*h),1-2*(l+n));p*=c.Num180DividedByPi;m*=c.Num180DividedByPi;h*=c.Num180DividedByPi; +if(1E-6>Math.abs(m-90)||1E-6>Math.abs(m+90))h=0,p=Math.atan2(g,e)*c.Num180DividedByPi,isNaN(p)&&(p=0);e=[];b==c.RollPitchYaw?(e[0]=m,e[1]=p,e[2]=h):b==c.PitchYawRoll?(e[0]=h,e[1]=m,e[2]=p):b==c.PitchRollYaw?(e[0]=h,e[1]=p,e[2]=m):b==c.YawPitchRoll?(e[0]=m,e[1]=h,e[2]=p):b==c.YawRollPitch?(e[0]=p,e[1]=h,e[2]=m):(e[0]=p,e[1]=m,e[2]=h);return e},quatSlerp:function(a,b,e){var g=c.quatDot(a,b),h=b;0>g&&(h=[-b[0],-b[1],-b[2],-b[3]],g=c.quatDot(a,h));b=0;if(-1g){if(b=Math.acos(g),0==b)return h.slice(0, +4)}else return h.slice(0,4);else b=Math.PI;var f=1/Math.sin(b),g=Math.sin((1-e)*b)*f;e=Math.sin(e*b)*f;return[a[0]*g+h[0]*e,a[1]*g+h[1]*e,a[2]*g+h[2]*e,a[3]*g+h[3]*e]},quatRotate:function(a,b,e,g,h){return c.quatMultiply(a,c.quatFromAxisAngle(b,e,g,h))},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 g=c.vec3cross(e,a),h=a[0]*b[0]+a[1]*b[1]+a[2]*b[2];return[a[0]*h+e[0]*a[3]-g[0],a[1]*h+e[1]*a[3]-g[1],a[2]*h+e[2]*a[3]-g[2],1]},quatFromMat4:function(a){var b= +[],c=a[1],g=a[2],h=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-g)*n,b[2]=(c-h)*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]=(h+c)*n,b[2]=(g+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]=(h+c)*n,b[1]=a,b[2]=(l+f)*n,b[3]=(k-g)*n):(a=.5*Math.sqrt(1+a[10]-a[0]-a[5]),n=.25/a,b[0]=(k+g)*n,b[1]=(l+f)*n,b[2]=a,b[3]=(c-h)*n);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 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,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; +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,g){var h;"undefined"!=typeof c&&"undefined"!=typeof g?(h=b,b=g):(h=b[0],c=b[1],b=b[2]);return[a[0]*h,a[1]*h,a[2]*h,a[3]*h,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,g,h){var f;"undefined"!=typeof c&&"undefined"!=typeof g&&"undefined"!=typeof h?(f=b,b=h):(f=b[0],c=b[1],g=b[2],b=b[3]);return[f*a[0]+c*a[4]+g*a[8]+b*a[12],f*a[1]+c*a[5]+g*a[9]+b*a[13],f*a[2]+c*a[6]+g*a[10]+b*a[14],f*a[3]+c*a[7]+g*a[11]+b*a[15]]},mat3transform:function(a,b,c,g){var h;"undefined"!=typeof c&&"undefined"!=typeof g?(h=b,b=g): +(h=b[0],c=b[1],b=b[2]);return[h*a[0]+c*a[3]+b*a[6],h*a[1]+c*a[4]+b*a[7],h*a[2]+c*a[5]+b*a[8]]},mat4translated:function(a,b,c){var g;"undefined"!=typeof b&&"undefined"!=typeof c?(g=a,a=c):(g=a[0],b=a[1],a=a[2]);return[1,0,0,0,0,1,0,0,0,0,1,0,g,b,a,1]},mat4translate:function(a,b,c,g){var h;"undefined"!=typeof c&&"undefined"!=typeof g?(h=b,b=g):(h=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]*h+a[4]*c+a[8]*b+a[12],a[1]*h+a[5]*c+a[9]*b+a[13],a[2]*h+a[6]* +c+a[10]*b+a[14],a[3]*h+a[7]*c+a[11]*b+a[15]]},mat4perspective:function(a,b,e,g){a=1/Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy360);var h;h=1/(e-g);return[a/b,0,0,0,0,a,0,0,0,0,h*(e+g),-1,0,0,h*e*g*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 g=c.vec3length(b);if(1E-6>g)return c.mat4identity();g=1/g;b[0]*=g;b[1]*=g;b[2]*=g;e=c.vec3norm(e);e=c.vec3cross(b,e);c.vec3normInPlace(e);g=c.vec3cross(e,b);c.vec3normInPlace(g);b[0]=-b[0]; +b[1]=-b[1];b[2]=-b[2];return[e[0],g[0],b[0],0,e[1],g[1],b[1],0,e[2],g[2],b[2],0,-c.vec3dot(a,e),-c.vec3dot(a,g),-c.vec3dot(a,b),1]},mat4ortho:function(a,b,c,g,h,f){var k=1/(b-a),l=1/(g-c),n=1/(f-h);return[2*k,0,0,0,0,2*l,0,0,0,0,-2*n,0,-(a+b)*k,-(g+c)*l,-(h+f)*n,1]},mat4perspectiveHorizontal:function(a,b,e,g){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,g)},mat4ortho2d:function(a,b,e,g){return c.mat4ortho2d(a,b,e,g, +-1,1)},mat4ortho2dAspect:function(a,b,e,g,h){return c.mat4orthoAspect(a,b,e,g,-1,1,h)},mat4orthoAspect:function(a,b,e,g,h,f,k){var l=Math.abs(b-a),n=Math.abs(g-e);k/=l/n;return 1>k?c.mat4ortho(a,b,e/k,g/k,h,f):c.mat4ortho(a*k,b*k,e,g,h,f)},mat4frustum:function(a,b,c,g,h,f){var k=2*h,l=1/(b-a),n=1/(g-c),p=1/(f-h);return[k*l,0,0,0,0,k*n,0,0,(a+b)*l,(g+c)*n,-(f+h)*p,-1,0,0,-(k*f)*p,0]},mat4scaleInPlace:function(a,b,c,g){var h;"undefined"!=typeof c&&"undefined"!=typeof g?(h=b,b=g):(h=b[0],c=b[1],b=b[2]); +a[0]*=h;a[1]*=h;a[2]*=h;a[3]*=h;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=[],g=0;16>g;g+=4)for(var h=0;4>h;h++)c[g+h]=b[g]*a[h]+b[g+1]*a[h+4]+b[g+2]*a[h+8]+b[g+3]*a[h+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,g,h){var f,k;"undefined"!=typeof g&& +"undefined"!=typeof h?(f=e,k=g,e=h,h=(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],h=b[3],h=(0<=h&&360>h?h:h%360+(0>h?360:0))*c.PiDividedBy180):(f=e[0],k=e[1],e=e[2],h=(0<=b&&360>b?b:b%360+(0>b?360:0))*c.PiDividedBy180);b=Math.cos(h);var l=Math.sin(h);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);h=1/Math.sqrt(f*f+k*k+e*e);f*=h;k*=h;e*=h;var n=k*k;g=1-b;var p=f*k,m=k*e;h=f*l;k*=l;var q=e*l,l=g* +m,r=g*p,t=g*f*e;f=b+g*f*f;p=r+q;m=t-k;n=b+g*n;q=r-q;r=l+h;e=b+g*e*e;b=t+k;h=l-h;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]*h+a[8]*e,a[1]*b+a[5]*h+a[9]*e,a[10]*e+a[2]*b+a[6]*h,a[11]*e+a[3]*b+a[7]*h,a[12],a[13],a[14],a[15]]},mat4rotated:function(a,b,e,g){var h;"undefined"!=typeof e&&"undefined"!=typeof g?(h=b,b=g,g=(0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy180): +"undefined"==typeof b?(h=a[0],e=a[1],b=a[2],g=a[3],g=(0<=g&&360>g?g:g%360+(0>g?360:0))*c.PiDividedBy180):(h=b[0],e=b[1],b=b[2],g=(0<=a&&360>a?a:a%360+(0>a?360:0))*c.PiDividedBy180);a=Math.cos(g);var f=Math.sin(g);if(1==h&&0==e&&0==b)return[1,0,0,0,0,a,f,0,0,-f,a,0,0,0,0,1];if(0==h&&1==e&&0==b)return[a,0,-f,0,0,1,0,0,f,0,a,0,0,0,0,1];if(0==h&&0==e&&1==b)return[a,f,0,0,-f,a,0,0,0,0,1,0,0,0,0,1];if(0==h&&0==e&&0==b)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];g=1/Math.sqrt(h*h+e*e+b*b);h*=g;e*=g;b*=g;g=h* +h;var k=e*e,l=b*b,n=h*b,p=e*b,m=h*f,q=e*f,f=b*f,r=1-a;h=r*h*e;e=r*n;b=r*p;return[a+r*g,h+f,e-q,0,h-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.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,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, +(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= +a.vertices.length/a.getStride();this.facesLength=a.indices.length;this.type=d;this.format=a.attributeBits;this.context=b}function h(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 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.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.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 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)); +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(h){b=null}if(!b)try{b=a.getContext("webkit-3d",c)}catch(e){b=null}if(!b)try{b=a.getContext("2d",c)}catch(g){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=[],h=0;hd.status){var h=d.response;h||(h="xml"==c?d.responseXML:"json"==c?(d.responseJSON||JSON.parse(d.responseText))+"":"arraybuffer"==c?d.response:d.responseText+"");b({url:a,data:h})}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 m=b+ +120;360<=m&&(m-=360);c=60>m?d+(a-d)*m/60:180>m?a:240>m?d+(a-d)*(240-m)/60:d;m=b;f=60>m?d+(a-d)*m/60:180>m?a:240>m?d+(a-d)*(240-m)/60:d;m=b-120;0>m&&(m+=360);b=60>m?d+(a-d)*m/60:180>m?a:240>m?d+(a-d)*(240-m)/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[m(k[1]),m(k[2]),m(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[m(k[1]),m(k[2]),m(k[3]),h(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]),h(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([g(k[1]),m(k[3]),m(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([g(k[1]),m(k[3]),m(k[2])]),[a[0],a[1],a[2],h(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)); 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=p.toGLColor(a.ambient));null!=a.diffuse&&(this.diffuse=p.toGLColor(a.diffuse));null!=a.specular&&(this.specular=p.toGLColor(a.specular));null!=a.emission&&(this.emission= -p.toGLColor(a.emission));null!=a.shininess&&(this.shininess=a.shininess);null!=a.texture&&(a=a.texture,this.texture="string"==typeof a?new q(a):a);return this};d.fromColor=function(a,b,c,e){a=p.toGLColor(a,b,c,e);return new d(a,a)};d.fromTexture=function(a){return(new d).setParams({texture:a})};var q=function(a){this.image=null;this.loadStatus=0;this.loadedTexture=null;this.name=a;this.width=0;this.clamp=!1;this.height=0};q.prototype.setClamp=function(a){this.clamp=a;return this};q.loadTexture=function(a, -b){if(b&&b[a])return Promise.resolve(b[a]);var c=new q(a);b&&(b[a]=c);return c.loadImage().then(function(a){return a},function(a){return Promise.reject(a.name)})};q.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.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())};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;db)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 h(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,h,e){null==e&&(e=this.getAspect());0==e&&(e=1);return this.setProjectionMatrix(GLMath.mat4orthoAspect(a, +b,c,f,d,h,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,e){return this.setProjectionMatrix(GLMath.mat4frustum(a,b,f,c,d,e))};f.prototype.setOrtho=function(a,b,c,f,d,e){return this.setProjectionMatrix(GLMath.mat4ortho(a,b,c,f,d,e))};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;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 f={};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));f.sampler=c.loadedTexture.textureUnit;f.textureSize=[c.width,c.height];b.setUniforms(f);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);f=a.CLAMP_TO_EDGE;GLUtil._isPowerOfTwo(c.width)&&GLUtil._isPowerOfTwo(c.height)?(c.clamp||(f=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,f);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,f)}};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 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;ad))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,g=0;gb)return this;var e=0;"undefined"==typeof a&&"undefined"==typeof d&&(a=c[1],d=c[2],c=c[0]);for(var g=0;gb)return null;for(var c=0,a=0;aq;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;dp;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;dh.indexOf(d)&&(h.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 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, +(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 e(b,c,d,e,g){if("undefined"==typeof c&&"undefined"==typeof d&& +"undefined"==typeof e&&"undefined"==typeof g)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==g)throw Error("v1 and v2 can't be equal");this.uoffset=c;this.umul=1/(d-c);this.voffset=e;this.vmul=1/(g-e)}this.evaluator=new a(b);this.k=this.evaluator.k}function g(){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 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= +u,this.n-b);if(this.n=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= 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 f(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 f(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 f(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 f(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,f=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&&(f=this.normalSurface.evaluate(b,c));if(this.vertexSurface){var n=d?a.color.slice(0,3): -null,r=f||this.autoNormal?a.normal.slice(0,3):null,t=h?a.texCoord.slice(0,3):null;d&&a.color3(d[0],d[1],d[2]);d=this.vertexSurface.evaluate(b,c);this.autoNormal?(f=this.vertexSurface.evaluate(b+.001,c),b=this.vertexSurface.evaluate(b,c+.001),GLMath.vec3subInPlace(b,d),GLMath.vec3subInPlace(f,d),GLMath.vec3scaleInPlace(f,1E3),GLMath.vec3scaleInPlace(b,1E3),GLMath.vec3normInPlace(f),GLMath.vec3normInPlace(b),0==GLMath.vec3length(f)?f=b:0!=GLMath.vec3length(b)&&(f=GLMath.vec3cross(f,b),GLMath.vec3normInPlace(f)), -a.normal3(f[0],f[1],f[2])):f&&a.normal3(f[0],f[1],f[2]);h&&a.texCoord3(h[0],h[1],h[2]);a.vertex3(d[0],d[1],d[2]);n&&a.color3(n[0],n[1],n[2]);r&&a.normal3(r[0],r[1],r[2]);t&&a.texCoord3(t[0],t[1],t[2])}return this};SurfaceEval.prototype.evalSurface=function(a,b,c,d,f,h,n,r){"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 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=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 g&&(e=0,g=1);g=(g-e)/c;q=(q-m)/d;if(b==Mesh.TRIANGLES)for(b=0;b=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=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=h?-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==g)return f;var k=360==g&&0==e,l=0>g?-1:1;0>g&&(g=-g);g%=360;0==g&&(g=360);var n=[],p=[],m=GLMath.PiTimes2;g=360==g?m:g*GLMath.PiDividedBy180;e*=GLMath.PiDividedBy180;0>l&&(g=-g);for(l=0;l<=a;l++){var q=1*l/a,r=e+g*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;h?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 h;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 g;var h=.5*-b,f=.5*-c;e?g.normal3(0,0,-1):g.normal3(0,0,1);for(e=0;ed)throw Error("too few stacks");return Meshes._createCapsule(b,c,a,2*d,e,g,h)}; +Meshes._createCapsule=function(b,c,a,d,e,g,h){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=h?-1:1,m=[0,1],q=[],r=[],t=[0],w=GLMath.PiTimes2,x=1;x 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}"};