typeof GLGE=="undefined"&&(GLGE={}),function(a){function c(){var b=a.Vec([1,2,3,4]),c=a.Vec4(a.getVec4(b,3),a.get1basedVec4(b,3),a.getVec4(b,1),a.getVec4(b,0)),d=a.identMatrix(),e=a.mulMat4Vec4(d,c);if(a.getVec4(e,0)!=4||a.getVec4(e,1)!=3||a.getVec4(e,2)!=2||a.getVec4(e,3)!=1)throw"Unit Test 1 failed MatVecMul "+e;var f=a.Mat4([3,4,5,0,.5,.75,0,0,.75,.5,0,0,.25,.25,1,1]),g=a.Mat4([2,1,8,2,1,4,3,2,1,.5,6.5,2,8,3,1,.25]),h=a.mulMat4(f,g),i=a.Mat4([15,21.5,68.5,24,1.75,3.5,6.25,2.5,2,2.75,7.5,2.5,9.75,4.75,10.25,3.25]);for(var j=0;j<4;++j)for(var k=0;k<4;++k){var l=a.getMat4(h,j,k)-a.getMat4(i,j,k);if(l>=1e-6||l<=-1e-6)throw"Unit Test 1 failed Multiplication "+a.getMat4(h,j,k)+" != "+a.getMat4(i,j,k)}var m=a.inverseMat4(f),n=a.mulMat4(f,m),o=a.mulMat4(m,f);for(var j=0;j<4;++j)for(var k=0;k<4;++k){var l=a.getMat4(n,j,k)-a.getMat4(d,j,k);if(l>=1e-4||l<=-1e-4)throw"Unit Test 1 failed Inverse "+a.getMat4(n,j,k)+" != "+a.getMat4(d,j,k)}}var b=[];a.reuseMatrix4=function(a){},a.matrix4=function(a,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){if(b.length==0)var r=[a,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q];else{var r=b.shift();r[0]=a,r[1]=c,r[2]=d,r[3]=e,r[4]=f,r[5]=g,r[6]=h,r[7]=i,r[8]=j,r[9]=k,r[10]=l,r[11]=m,r[12]=n,r[13]=o,r[14]=p,r[15]=q}return r},a.Vec=function(a){return a.slice(0)},a.Vec3=function(a,b,c){return[a,b,c]},a.Vec4=function(a,b,c,d){return[a,b,c,d]},a.get1basedVec4=function(a,b){return a[b-1]},a.get1basedVec3=function(a,b){return a[b-1]},a.getVec4=function(a,b){return a[b]},a.getVec3=function(a,b){return a[b]},a.addVec4=function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2],a[3]+b[3]]},a.addVec3=function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2]]},a.subVec4=function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2],a[3]-b[3]]},a.subVec3=function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]},a.dotVec3=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},a.dotVec4=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},a.scaleVec4=function(a,b){return[a[0]*b,a[1]*b,a[2]*b,a[3]*b]},a.scaleVec3=function(a,b){return[a[0]*b,a[1]*b,a[2]*b]},a.crossVec3=function(a,b){return[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]},a.toUnitVec3=function(a){var b=a[0]*a[0]+a[1]*a[1]+a[2]*a[2],c=1;b>0&&(c=Math.pow(b,.5));return[a[0]/c,a[1]/c,a[2]/c]},a.toUnitVec4=function(a){var b=a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3],c=1;b>0&&(c=Math.pow(b,.5));return[a[0]/c,a[1]/c,a[2]/c,a[3]/c]},a.lengthVec3=function(a){return Math.pow(a[0]*a[0]+a[1]*a[1]+a[2]*a[2],.5)},a.distanceVec3=function(b,c){return a.lengthVec3(a.subVec3(b,c))},a.lengthVec4=function(a,b){return Math.pow(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3],.5)},a.distanceVec4=function(b,c){return a.lengthVec4(a.subVec4(b,c))},a.angleVec3=function(b,c){b=a.toUnitVec3(b),c=a.toUnitVec3(c),d=a.dotVec3(b,c),d<-1&&(d=-1),d>1&&(d=1);return Math.acos(d)},a.angleVec4=function(b,c){b=a.toUnitVec4(b),c=a.toUnitVec4(c),d=a.dotVec4(b,c),d<-1&&(d=-1),d>1&&(d=1);return Math.acos(d)},GLGE_math_use_webgl_float=!1,a.Mat3=GLGE_math_use_webgl_float?function(a){if(a.length==9)return new Float32Array(a);if(a.length==16)return new Float32Array([a[0],a[1],a[2],a[4],a[5],a[6],a[8],a[9],a[10]]);throw"invalid matrix length"}:function(a){var b;if(a.length==9)b=a.slice(0);else if(a.length==16)b=[a[0],a[1],a[2],a[4],a[5],a[6],a[8],a[9],a[10]];else throw"invalid matrix length";b.get=function(a){return this[a]};return b},a.Mat=GLGE_math_use_webgl_float?function(a){return new Float32Array(a)}:function(a){var b=a.slice(0);b.get=function(a){return this[a]};return b},a.Mat4=function(a){var b;if(a.length==9)b=[a[0],a[1],a[2],0,a[3],a[4],a[5],0,a[6],a[7],a[8],0,0,0,0,1];else if(a.length==16)a.slice?b=a.slice(0):b=a.subarray(0);else throw"invalid matrix length";b.get=function(a){return this[a]};return b},a.determinantMat4=function(a){return a[12]*a[9]*a[6]*a[3]-a[8]*a[13]*a[6]*a[3]-a[12]*a[5]*a[10]*a[3]+a[4]*a[13]*a[10]*a[3]+a[8]*a[5]*a[14]*a[3]-a[4]*a[9]*a[14]*a[3]-a[12]*a[9]*a[2]*a[7]+a[8]*a[13]*a[2]*a[7]+a[12]*a[1]*a[10]*a[7]-a[0]*a[13]*a[10]*a[7]-a[8]*a[1]*a[14]*a[7]+a[0]*a[9]*a[14]*a[7]+a[12]*a[5]*a[2]*a[11]-a[4]*a[13]*a[2]*a[11]-a[12]*a[1]*a[6]*a[11]+a[0]*a[13]*a[6]*a[11]+a[4]*a[1]*a[14]*a[11]-a[0]*a[5]*a[14]*a[11]-a[8]*a[5]*a[2]*a[15]+a[4]*a[9]*a[2]*a[15]+a[8]*a[1]*a[6]*a[15]-a[0]*a[9]*a[6]*a[15]-a[4]*a[1]*a[10]*a[15]+a[0]*a[5]*a[10]*a[15]},a.inverseMat4=function(b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i=b[6],j=b[7],k=b[8],l=b[9],m=b[10],n=b[11],o=b[12],p=b[13],q=b[14],r=b[15],s=o*l*i*f-k*p*i*f-o*h*m*f+g*p*m*f+k*h*q*f-g*l*q*f-o*l*e*j+k*p*e*j+o*d*m*j-c*p*m*j-k*d*q*j+c*l*q*j+o*h*e*n-g*p*e*n-o*d*i*n+c*p*i*n+g*d*q*n-c*h*q*n-k*h*e*r+g*l*e*r+k*d*i*r-c*l*i*r-g*d*m*r+c*h*m*r;return a.matrix4((l*q*j-p*m*j+p*i*n-h*q*n-l*i*r+h*m*r)/s,(p*m*f-l*q*f-p*e*n+d*q*n+l*e*r-d*m*r)/s,(h*q*f-p*i*f+p*e*j-d*q*j-h*e*r+d*i*r)/s,(l*i*f-h*m*f-l*e*j+d*m*j+h*e*n-d*i*n)/s,(o*m*j-k*q*j-o*i*n+g*q*n+k*i*r-g*m*r)/s,(k*q*f-o*m*f+o*e*n-c*q*n-k*e*r+c*m*r)/s,(o*i*f-g*q*f-o*e*j+c*q*j+g*e*r-c*i*r)/s,(g*m*f-k*i*f+k*e*j-c*m*j-g*e*n+c*i*n)/s,(k*p*j-o*l*j+o*h*n-g*p*n-k*h*r+g*l*r)/s,(o*l*f-k*p*f-o*d*n+c*p*n+k*d*r-c*l*r)/s,(g*p*f-o*h*f+o*d*j-c*p*j-g*d*r+c*h*r)/s,(k*h*f-g*l*f-k*d*j+c*l*j+g*d*n-c*h*n)/s,(o*l*i-k*p*i-o*h*m+g*p*m+k*h*q-g*l*q)/s,(k*p*e-o*l*e+o*d*m-c*p*m-k*d*q+c*l*q)/s,(o*h*e-g*p*e-o*d*i+c*p*i+g*d*q-c*h*q)/s,(g*l*e-k*h*e+k*d*i-c*l*i-g*d*m+c*h*m)/s)},a.mulMat4Vec3=function(b,c){return a.Vec3(b[0]*c[0]+b[1]*c[1]+b[2]*c[2]+b[3],b[4]*c[0]+b[5]*c[1]+b[6]*c[2]+b[7],b[8]*c[0]+b[9]*c[1]+b[10]*c[2]+b[11])},a.mulMat4Vec4=function(b,c){return a.Vec4(b[0]*c[0]+b[1]*c[1]+b[2]*c[2]+b[3]*c[3],b[4]*c[0]+b[5]*c[1]+b[6]*c[2]+b[7]*c[3],b[8]*c[0]+b[9]*c[1]+b[10]*c[2]+b[11]*c[3],b[12]*c[0]+b[13]*c[1]+b[14]*c[2]+b[15]*c[3])},a.scaleMat4=function(b,c){return a.matrix4([b[0]*c,b[1]*c,b[2]*c,b[3]*c,b[4]*c,b[5]*c,b[6]*c,b[7]*c,b[8]*c,b[9]*c,b[10]*c,b[11]*c,b[12]*c,b[13]*c,b[14]*c,b[15]*c])},a.scaleInPlaceMat4=function(a,b){a.set(0,a[0]*b),a.set(1,a[1]*b),a.set(2,a[2]*b),a.set(3,a[3]*b),a.set(4,a[4]*b),a.set(5,a[5]*b),a.set(6,a[6]*b),a.set(7,a[7]*b),a.set(8,a[8]*b),a.set(9,a[9]*b),a.set(10,a[10]*b),a.set(11,a[11]*b),a.set(12,a[12]*b),a.set(13,a[13]*b),a.set(14,a[14]*b),a.set(15,a[15]*b);return a},a.addInPlaceMat4=function(a,b){a.set(0,a[0]+b[0]),a.set(1,a[1]+b[1]),a.set(2,a[2]+b[2]),a.set(3,a[3]+b[3]),a.set(4,a[4]+b[4]),a.set(5,a[5]+b[5]),a.set(6,a[6]+b[6]),a.set(7,a[7]+b[7]),a.set(8,a[8]+b[8]),a.set(9,a[9]+b[9]),a.set(10,a[10]+b[10]),a.set(11,a[11]+b[11]),a.set(12,a[12]+b[12]),a.set(13,a[13]+b[13]),a.set(14,a[14]+b[14]),a.set(15,a[15]+b[15]);return a},a.addMat4=function(b,c){return a.Mat([b[0]+c[0],b[1]+c[1],b[2]+c[2],b[3]+c[3],b[4]+c[4],b[5]+c[5],b[6]+c[6],b[7]+c[7],b[8]+c[8],b[9]+c[9],b[10]+c[10],b[11]+c[11],b[12]+c[12],b[13]+c[13],b[14]+c[14],b[15]+c[15]])},a.subInPlaceMat4=function(a,b){a.set(0,a[0]-b[0]),a.set(1,a[1]-b[1]),a.set(2,a[2]-b[2]),a.set(3,a[3]-b[3]),a.set(4,a[4]-b[4]),a.set(5,a[5]-b[5]),a.set(6,a[6]-b[6]),a.set(7,a[7]-b[7]),a.set(8,a[8]-b[8]),a.set(9,a[9]-b[9]),a.set(10,a[10]-b[10]),a.set(11,a[11]-b[11]),a.set(12,a[12]-b[12]),a.set(13,a[13]-b[13]),a.set(14,a[14]-b[14]),a.set(15,a[15]-b[15]);return a},a.subMat4=function(b,c){return a.Mat([b[0]-c[0],b[1]-c[1],b[2]-c[2],b[3]-c[3],b[4]-c[4],b[5]-c[5],b[6]-c[6],b[7]-c[7],b[8]-c[8],b[9]-c[9],b[10]-c[10],b[11]-c[11],b[12]-c[12],b[13]-c[13],b[14]-c[14],b[15]-c[15]])},a.mulMat4=function(b,c){var d=c[0],e=c[1],f=c[2],g=c[3],h=c[4],i=c[5],j=c[6],k=c[7],l=c[8],m=c[9],n=c[10],o=c[11],p=c[12],q=c[13],r=c[14],s=c[15],t=b[0],u=b[1],v=b[2],w=b[3],x=b[4],y=b[5],z=b[6],A=b[7],B=b[8],C=b[9],D=b[10],E=b[11],F=b[12],G=b[13],H=b[14],I=b[15];return a.matrix4(t*d+u*h+v*l+w*p,t*e+u*i+v*m+w*q,t*f+u*j+v*n+w*r,t*g+u*k+v*o+w*s,x*d+y*h+z*l+A*p,x*e+y*i+z*m+A*q,x*f+y*j+z*n+A*r,x*g+y*k+z*o+A*s,B*d+C*h+D*l+E*p,B*e+C*i+D*m+E*q,B*f+C*j+D*n+E*r,B*g+C*k+D*o+E*s,F*d+G*h+H*l+I*p,F*e+G*i+H*m+I*q,F*f+G*j+H*n+I*r,F*g+G*k+H*o+I*s)},a.transposeInPlaceMat4=function(a){var b=a[1];a.set(1,a[4]),a.set(4,b),b=a[8],a.set(8,a[2]),a.set(2,b),b=a[3],a.set(3,a[12]),a.set(12,b),b=a[9],a.set(9,a[6]),a.set(6,b),b=a[13],a.set(13,a[7]),a.set(7,b),b=a[14],a.set(14,a[11]),a.set(11,b)},a.transposeMat4=function(b){return a.matrix4(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15])},a.mat4gl=function(a,b){b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]},a.set1basedMat4=function(a,b,c,d){a[(b-1)*4+(c-1)]=d,a.glData!==undefined&&delete a.glData},a.setMat4=function(a,b,c,d){a[b*4+c]=d,a.glData!==undefined&&delete a.glData},a.get1basedMat4=function(a,b,c){return a.get((b-1)*4+(c-1))},a.getMat4=function(a,b,c){return a[b*4+c]},a.glDataMat4=function(a){a.glArray=new Float32Array(a);return a.glArray},a.identMatrix=function(){return a.matrix4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},a.translateMatrix=function(b){var c,d,e;arguments.length==3?(c=arguments[0],d=arguments[1],e=arguments[2]):b.data?(c=b.data[0],d=b.data[1],e=b.data[2]):b instanceof Array&&(c=b[0],d=b[1],e=b[2]);return a.matrix4(1,0,0,c,0,1,0,d,0,0,1,e,0,0,0,1)},a.scaleMatrix=function(b){var c,d,e;arguments.length==3?(c=arguments[0],d=arguments[1],e=arguments[2]):b.data?(c=b.data[0],d=b.data[1],e=b.data[2]):b instanceof Array&&(c=b[0],d=b[1],e=b[2]);return a.matrix4(c,0,0,0,0,d,0,0,0,0,e,0,0,0,0,1)},a.ROT_XYZ=1,a.ROT_XZY=2,a.ROT_YXZ=3,a.ROT_YZX=4,a.ROT_ZXY=5,a.ROT_ZYX=6,a.rotateMatrix=function(b,c){var d,e,f;arguments.length>2?(d=arguments[0],e=arguments[1],f=arguments[2],c=arguments[3]):b.data?(d=b.data[0],e=b.data[1],f=b.data[2]):b instanceof Array&&(d=b[0],e=b[1],f=b[2]),c||(c=a.ROT_XYZ);var g=Math.cos(d),h=Math.sin(d),i=Math.cos(e),j=Math.sin(e),k=Math.cos(f),l=Math.sin(f),m=a.matrix4(1,0,0,0,0,g,-h,0,0,h,g,0,0,0,0,1),n=a.matrix4(i,0,j,0,0,1,0,0,-j,0,i,0,0,0,0,1),o=a.matrix4(k,-l,0,0,l,k,0,0,0,0,1,0,0,0,0,1);switch(c){case a.ROT_XYZ:return a.mulMat4(m,a.mulMat4(n,o));case a.ROT_XZY:return a.mulMat4(m,a.mulMat4(o,n));case a.ROT_YXZ:return a.mulMat4(n,a.mulMat4(m,o));case a.ROT_YZX:return a.mulMat4(n,a.mulMat4(o,m));case a.ROT_ZXY:return a.mulMat4(o,a.mulMat4(m,n));case a.ROT_ZYX:return a.mulMat4(o,a.mulMat4(n,m))}},a.angleAxis=function(b,c){var d,e,f,g,h,i,j,k,l;c=[c[0],c[1],c[2],0];var m=c[0],n=c[1],o=c[2],p=Math.cos(b),q=1-p,r=Math.sin(b);j=m*r,k=n*r,l=o*r,d=m*m,e=n*n,f=o*o,g=m*n,h=n*o,i=o*m;var s=a.matrix4(q*d+p,q*g-l,q*i+k,0,q*g+l,q*e+p,q*h-j,0,q*i-k,q*h+j,q*f+p,0,0,0,0,1);return a.Mat(s)},a.quatFromAxisAngle=function(a,b){var c=[],d=b*.5,e=Math.sin(d),f=Math.cos(d);c[0]=a[0]*e,c[1]=a[1]*e,c[2]=a[2]*e,c[3]=f;return c},a.mulQuat=function(a,b){var c=[],d=a[0],e=a[1],f=a[2],g=a[3],h=b[0],i=b[1],j=b[2],k=b[3],l=e*j-f*i,m=f*h-d*j,n=d*i-e*h,o=d*h+e*i+f*j;c[0]=d*k+h*g+l,c[1]=e*k+i*g+m,c[2]=f*k+j*g+n,c[3]=g*k-o;return c},a.mat4FromQuat=function(a){var b=a[0]*a[0],c=a[1]*a[1],d=a[2]*a[2],e=a[0]*a[1],f=a[2]*a[3],g=a[2]*a[0],h=a[1]*a[3],i=a[1]*a[2],j=a[0]*a[3],k=[];k[0]=1-2*(c+d),k[1]=2*(e+f),k[2]=2*(g-h),k[3]=0,k[4]=2*(e-f),k[5]=1-2*(d+b),k[6]=2*(i+j),k[7]=0,k[8]=2*(g+h),k[9]=2*(i-j),k[10]=1-2*(c+b),k[11]=0,k[12]=0,k[13]=0,k[14]=0,k[15]=1;return k},a.quatRotation=function(b,c,d,e){return a.matrix4(1-2*c*c-2*d*d,2*b*c-2*d*e,2*b*d+2*c*e,0,2*b*c+2*d*e,1-2*b*b-2*d*d,2*c*d-2*b*e,0,2*b*d-2*c*e,2*c*d+2*b*e,1-2*b*b-2*c*c,0,0,0,0,1)},a.makeOrtho=function(b,c,d,e,f,g){var h=-(c+b)/(c-b),i=-(e+d)/(e-d),j=-(g+f)/(g-f);return a.matrix4(2/(c-b),0,0,h,0,2/(e-d),0,i,0,0,-2/(g-f),j,0,0,0,1)},a.makeFrustum=function(b,c,d,e,f,g){var h=2*f/(c-b),i=2*f/(e-d),j=(c+b)/(c-b),k=(e+d)/(e-d),l=-(g+f)/(g-f),m=-2*g*f/(g-f);return a.matrix4(h,0,j,0,0,i,k,0,0,0,l,m,0,0,-1,0)},a.makePerspective=function(b,c,d,e){var f=d*Math.tan(b*.00872664625972),g=-f,h=g*c,i=f*c;return a.makeFrustum(h,i,g,f,d,e)},a.matrix2Scale=function(a){var b=a[0],c=a[1],d=a[2],e=a[4],f=a[5],g=a[6],h=a[8],i=a[9],j=a[10],k=Math.sqrt(b*b+c*c+d*d),l=Math.sqrt(e*e+f*f+g*g),m=Math.sqrt(h*h+i*i+j*j);return[k,l,m]},a.rotationMatrix2Quat=function(a){var b=a[0]+a[5]+a[10]+1,c,d,e,f,g;b>0?(c=.5/Math.sqrt(b),g=.25/c,d=(a[9]-a[6])*c,e=(a[2]-a[8])*c,f=(a[4]-a[1])*c):a[0]>a[5]&&a[0]>a[10]?(c=Math.sqrt(1+a[0]-a[5]-a[10])*2,g=(a[9]-a[6])/c,d=.25/c,e=(a[1]+a[4])/c,f=(a[2]+a[8])/c):a[5]>a[10]?(c=Math.sqrt(1+a[5]-a[0]-a[10])*2,g=(a[2]-a[8])/c,d=(a[1]+a[4])/c,e=.25/c,f=(a[6]+a[9])/c):(c=Math.sqrt(1+a[10]-a[0]-a[5])*2,g=(a[4]-a[1])/c,d=(a[2]+a[8])/c,e=(a[6]+a[9])/c,f=.25/c);var h=Math.sqrt(d*d+e*e+f*f+g*g);return[d/h,e/h,f/h,g/h]},a.rayToPlane=function(b,c){var d=a.toUnitVec3(c);return[d[0],d[1],d[2],a.dotVec3(b,d)]},a.rayIntersectPlane=function(b,c,d){var e=[d[0],d[1],d[2]],f=d[3],g=a.dotVec3(e,c);if(g<=0)return!1;var h=-(a.dotVec3(e,b)+f),i=h/g;if(i<=0)return!1;return a.addVec3(b,a.scaleVec3(c,i))},a.screenToDirection=function(b,c,d,e,f){xcoord=-(2*b/d-1)/f[0],ycoord=(2*c/e-1)/f[5],zcoord=1;return a.toUnitVec3([xcoord,ycoord,zcoord])},a.BoundingVolume=function(a,b,c,d,e,f){this.limits=[a,b,c,d,e,f],this.calcProps()},a.BoundingVolume.prototype.getCornerPoints=function(){return this.points},a.BoundingVolume.prototype.getSphereRadius=function(){return this.radius},a.BoundingVolume.prototype.getCenter=function(){return this.center},a.BoundingVolume.prototype.isNull=function(){return this.limits[0]==0&&this.limits[1]==0&&this.limits[2]==0&&this.limits[3]==0&&this.limits[4]==0&&this.limits[5]==0},a.BoundingVolume.prototype.addBoundingVolume=function(a){this.isNull()?(this.limits[0]=a.limits[0],this.limits[1]=a.limits[1],this.limits[2]=a.limits[2],this.limits[3]=a.limits[3],this.limits[4]=a.limits[4],this.limits[5]=a.limits[5]):a.isNull()||(this.limits[0]=Math.min(a.limits[0],this.limits[0]),this.limits[2]=Math.min(a.limits[2],this.limits[2]),this.limits[4]=Math.min(a.limits[4],this.limits[4]),this.limits[1]=Math.max(a.limits[1],this.limits[1]),this.limits[3]=Math.max(a.limits[3],this.limits[3]),this.limits[5]=Math.max(a.limits[5],this.limits[5])),this.calcProps()},a.BoundingVolume.prototype.applyMatrix=function(b){var c=a.mulMat4Vec4(b,[this.limits[0],this.limits[2],this.limits[4],1]),d=a.mulMat4Vec4(b,[this.limits[1],this.limits[2],this.limits[4],1]),e=a.mulMat4Vec4(b,[this.limits[0],this.limits[3],this.limits[4],1]),f=a.mulMat4Vec4(b,[this.limits[1],this.limits[3],this.limits[4],1]),g=a.mulMat4Vec4(b,[this.limits[0],this.limits[2],this.limits[5],1]),h=a.mulMat4Vec4(b,[this.limits[1],this.limits[2],this.limits[5],1]),i=a.mulMat4Vec4(b,[this.limits[0],this.limits[3],this.limits[5],1]),j=a.mulMat4Vec4(b,[this.limits[1],this.limits[3],this.limits[5],1]);this.limits[0]=Math.min(c[0],d[0],e[0],f[0],g[0],h[0],i[0],j[0]),this.limits[1]=Math.max(c[0],d[0],e[0],f[0],g[0],h[0],i[0],j[0]),this.limits[2]=Math.min(c[1],d[1],e[1],f[1],g[1],h[1],i[1],j[1]),this.limits[3]=Math.max(c[1],d[1],e[1],f[1],g[1],h[1],i[1],j[1]),this.limits[4]=Math.min(c[2],d[2],e[2],f[2],g[2],h[2],i[2],j[2]),this.limits[5]=Math.max(c[2],d[2],e[2],f[2],g[2],h[2],i[2],j[2]),this.calcProps()},a.BoundingVolume.prototype.calcProps=function(){var a=this.limits[0],b=this.limits[1],c=this.limits[2],d=this.limits[3],e=this.limits[4],f=this.limits[5];this.points=[[a,c,e],[b,c,e],[a,d,e],[b,d,e],[a,c,f],[b,c,f],[a,d,f],[b,d,f]],this.center=[(this.limits[1]-this.limits[0])/2+this.limits[0],(this.limits[3]-this.limits[2])/2+this.limits[2],(this.limits[5]-this.limits[4])/2+this.limits[4]];var g=this.limits[0]-this.center[0],h=this.limits[2]-this.center[1],i=this.limits[4]-this.center[2];this.radius=Math.sqrt(g*g+h*h+i*i)},a.BoundingVolume.prototype.clone=function(){return new a.BoundingVolume(this.limits[0],this.limits[1],this.limits[2],this.limits[3],this.limits[4],this.limits[5])},a.BoundingVolume.prototype.toString=function(){return this.limits.toString()},a.cameraViewProjectionToPlanes=function(b){var c=a.inverseMat4(b),d=a.mulMat4Vec4,e=a.subVec3,f=a.crossVec3,g=a.toUnitVec3,h=a.dotVec3,i=d(c,[-1,-1,-1,1]),j=d(c,[1,-1,-1,1]),k=d(c,[-1,-1,1,1]),l=d(c,[1,1,-1,1]),m=d(c,[1,1,1,1]),n=d(c,[-1,1,1,1]);i=[i[0]/i[3],i[1]/i[3],i[2]/i[3]],j=[j[0]/j[3],j[1]/j[3],j[2]/j[3]],k=[k[0]/k[3],k[1]/k[3],k[2]/k[3]],l=[l[0]/l[3],l[1]/l[3],l[2]/l[3]],m=[m[0]/m[3],m[1]/m[3],m[2]/m[3]],n=[n[0]/n[3],n[1]/n[3],n[2]/n[3]];var o=g(f(e(l,j),e(i,j))),p=g(f(e(n,k),e(m,k))),q=g(f(e(i,k),e(n,k))),r=g(f(e(m,l),e(l,j))),s=g(f(e(n,l),e(l,m))),t=g(f(e(i,j),e(k,i)));o.push(h(o,i)),p.push(h(p,k)),q.push(h(q,i)),r.push(h(r,j)),s.push(h(s,m)),t.push(h(t,i));return[o,p,q,r,s,t]},a.sphereInFrustumPlanes=function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3],g=b[0],h=b[1],i=b[2],j=b[3],k=b[4],l=b[5];return c*g[0]+d*g[1]+e*g[2]-g[3]-f>0||c*h[0]+d*h[1]+e*h[2]-h[3]-f>0||c*i[0]+d*i[1]+e*i[2]-i[3]-f>0||c*j[0]+d*j[1]+e*j[2]-j[3]-f>0||c*k[0]+d*k[1]+e*k[2]-k[3]-f>0||c*l[0]+d*l[1]+e*l[2]-l[3]-f>0?!1:!0},a.pointsInFrustumPlanes=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],i,j,k;for(var l=0;l0&&i*d[0]+j*d[1]+k*d[2]-d[3]>0&&i*e[0]+j*e[1]+k*e[2]-f[3]>0&&i*f[0]+j*f[1]+k*f[2]-g[3]>0&&i*g[0]+j*g[1]+k*g[2]-g[3]>0&&i*h[0]+j*h[1]+k*h[2]-h[3]>0)return!1}return!0},a.getDirLightProjection=function(b,c,d,e){var f=a.mulMat4(c,a.inverseMat4(b)),g=[0,0,0],h=[0,0,0];for(x=0;x<2;x++)for(y=0;y<2;y++)for(z=0;z<2;z++){var i=a.mulMat4Vec4(f,[x*2-1,y*2-1,z*d,1]);i[0]=i[0]/i[3],i[1]=i[1]/i[3],i[2]=i[2]/i[3],g[0]=g[0]>i[0]?i[0]:g[0],g[1]=g[1]>i[1]?i[1]:g[1],h[0]=h[0]1?this.loop?b=(parseFloat(a)-parseFloat(this.animationStart))/1e3*this.frameRate%(this.animFrames-1)+1+this.startFrame:(b=(parseFloat(a)-parseFloat(this.animationStart))/1e3*this.frameRate+1+this.startFrame,b>=this.animFrames+this.startFrame&&(b=this.animFrames)):b=1;return Math.round(b)},a.Animatable.prototype.setStartFrame=function(a,b,c){this.loop=c;var d=parseInt((new Date).getTime());b||(b=0),b>0&&(this.animation&&(this.blendInitValues=this.getInitialValues(this.animation,d),this.blendTime=b)),this.animationStart=d,this.lastFrame=null,this.animFinished=!1,this.startFrame=a;if(this.children)for(var e=0;e0&&(this.blendInitValues=this.getInitialValues(a,c),this.blendTime=b),this.animFrames=null,this.startFrame=null,this.animationStart=c,this.lastFrame=null,this.animation=a,this.animFinished=!1;return this},a.Animatable.prototype.getAnimation=function(){return this.animation},a.Animatable.prototype.setFrameRate=function(a){this.frameRate=a;if(this.children)for(var b=0;b0)return this.getDefault(b);if(!b.object){b.object=new a.Mesh,this.setProperties(b);var c=b.firstChild;while(c){switch(c.tagName){case"positions":b.object.setPositions(this.parseArray(c));break;case"normals":b.object.setNormals(this.parseArray(c));break;case"uv1":b.object.setUV(this.parseArray(c));break;case"uv2":b.object.setUV2(this.parseArray(c));break;case"faces":b.object.setFaces(this.parseArray(c));break;case"joint_names":var d=this.parseArray(c),e=[];for(var f=0;f0||b.className=="Light"){var c=b;while(c.parent)c=c.parent;c.updateAllPrograms()}b.addEventListener&&(b.addEventListener("shaderupdate",function(){var a=this;while(a.parent)a=a.parent;a.updateAllPrograms()}),b.addEventListener("downloadComplete",this.downloadComplete)),this.fireEvent("childAdded",{obj:b}),b.fireEvent&&b.fireEvent("appened",{obj:this}),this.fireEvent("childAdded",{obj:b});var d=this;while(d=d.parent)d.fireEvent("childAdded",{obj:b,target:this});return this},a.Group.prototype.addObject=a.Group.prototype.addChild,a.Group.prototype.addObjectInstance=a.Group.prototype.addChild,a.Group.prototype.addGroup=a.Group.prototype.addChild,a.Group.prototype.addLight=a.Group.prototype.addChild,a.Group.prototype.addText=a.Group.prototype.addChild,a.Group.prototype.addSkeleton=a.Group.prototype.addChild,a.Group.prototype.addCamera=a.Group.prototype.addChild,a.Group.prototype.addWavefront=a.Group.prototype.addChild,a.Group.prototype.removeChild=function(a){for(var b=0;b0&&a.Message.loadMessages()}}(GLGE),function(a){a.Action=function(b){a.Assets.registerAsset(this,b),this.channels=[]},a.augment(a.QuickNotation,a.Action),a.augment(a.JSONLoader,a.Action),a.augment(a.Events,a.Action),a.Action.prototype.start=function(a,b,c){b||(b=!1),a||(a=0);var d=this.channels,e=(new Date).getTime();this.animFinished=!1;for(var f=0;fa||b!=undefined&&this.keyFrames[g].x<=this.keyFrames[b].x?this.keyFrames[g].x<=a&&(d==undefined||this.keyFrames[g].x>this.keyFrames[d].x)&&(d=g):(d=b,b=g),this.keyFrames[g].x<=a||c!=undefined&&this.keyFrames[g].x>this.keyFrames[c].x?this.keyFrames[g].x>a&&(f==undefined||this.keyFrames[g].x<=this.keyFrames[f].x)&&(f=g):(f=c,c=g)}b==undefined&&(b=c,c=f),c==undefined&&(c=b,b=d);if(this.keyFrames[b]instanceof e.BezTriple&&this.keyFrames[c]instanceof e.BezTriple){var h=this.coord(this.keyFrames[b].x,this.keyFrames[b].y),i=this.coord(this.keyFrames[b].x3,this.keyFrames[b].y3),j=this.coord(this.keyFrames[c].x1,this.keyFrames[c].y1),k=this.coord(this.keyFrames[c].x,this.keyFrames[c].y);return this.atX(a,h,i,j,k).y}if(this.keyFrames[b]instanceof e.LinearPoint&&this.keyFrames[c]instanceof e.BezTriple){var h=this.coord(this.keyFrames[b].x,this.keyFrames[b].y),i=this.coord(this.keyFrames[c].x1,this.keyFrames[c].y1),j=this.coord(this.keyFrames[c].x1,this.keyFrames[c].y1),k=this.coord(this.keyFrames[c].x,this.keyFrames[c].y);return this.atX(a,h,i,j,k).y}if(this.keyFrames[b]instanceof e.BezTriple&&this.keyFrames[c]instanceof e.LinearPoint){var h=this.coord(this.keyFrames[b].x,this.keyFrames[b].y),i=this.coord(this.keyFrames[b].x3,this.keyFrames[b].y3),j=this.coord(this.keyFrames[b].x3,this.keyFrames[b].y3),k=this.coord(this.keyFrames[c].x,this.keyFrames[c].y);return this.atX(a,h,i,j,k).y}if(this.keyFrames[b]instanceof e.LinearPoint&&this.keyFrames[c]instanceof e.LinearPoint){var l=(a-this.keyFrames[b].x)*(this.keyFrames[c].y-this.keyFrames[b].y)/(this.keyFrames[c].x-this.keyFrames[b].x)+this.keyFrames[b].y;return l}if(this.keyFrames[b]instanceof e.StepPoint)return this.keyFrames[b].y;this.keyFrames.preStartKey||(this.keyFrames.preStartKey=this.keyFrames[0].y),this.caches[a]=this.keyFrames.preStartKey;return this.caches[a]},e.AnimationCurve.prototype.B1=function(a){return a*a*a},e.AnimationCurve.prototype.B2=function(a){return 3*a*a*(1-a)},e.AnimationCurve.prototype.B3=function(a){return 3*a*(1-a)*(1-a)},e.AnimationCurve.prototype.B4=function(a){return(1-a)*(1-a)*(1-a)},e.AnimationCurve.prototype.getBezier=function(a,b,c,d,e){var f={};f.x=b.x*this.B1(a)+c.x*this.B2(a)+d.x*this.B3(a)+e.x*this.B4(a),f.y=b.y*this.B1(a)+c.y*this.B2(a)+d.y*this.B3(a)+e.y*this.B4(a);return f},e.AnimationCurve.prototype.Quad3Solve=function(a,b,c,d){ref=a+"-"+b+"--"+c+"-"+d;if(this.solutions[ref])return this.solutions[ref];b/=a,c/=a,d/=a;var e,f,g,h,i,j,k;e=(3*c-b*b)/9,f=-(27*d)+b*(9*c-2*(b*b)),f/=54,j=b/3,discrim=e*e*e+f*f,result=[],discrim>0?(h=f+Math.sqrt(discrim),h=h<0?-Math.pow(-h,1/3):Math.pow(h,1/3),i=f-Math.sqrt(discrim),i=i<0?-Math.pow(-i,1/3):Math.pow(i,1/3),result[0]=-j+h+i,j=j+(h+i)/2,result[1]=result[2]=-j,j=Math.sqrt(3)*(-i+h)/2):discrim==0?(k=f<0?-Math.pow(-f,1/3):Math.pow(f,1/3),result[1]=-j+2*k,result[1]=result[2]=-(k+j)):(e=-e,g=e*e*e,g=Math.acos(f/Math.sqrt(1)),k=2*Math.sqrt(e),result[0]=-j+k*Math.cos(g/3),result[1]=-j+k*Math.cos((g+2*Math.PI)/3),result[2]=-j+k*Math.cos((g+4*Math.PI)/3));var l=!1;result[0]>=0&&result[0]<=1&&(l=result[0]),!l&&result[1]>=0&&result[1]<=1&&(l=result[1]),!l&&result[2]>=0&&result[2]<=1&&(l=result[2]),this.solutions[ref]=l;return l},e.AnimationCurve.prototype.atX=function(e,f,g,h,i){a=f.x-g.x*3+h.x*3-i.x,b=g.x*3-h.x*6+i.x*3,c=h.x*3-i.x*3,d=i.x-e;return this.getBezier(this.Quad3Solve(a,b,c,d),f,g,h,i)}}(GLGE),function(a){a.AnimationVector=function(b){a.Assets.registerAsset(this,b),this.curves={}},a.augment(a.QuickNotation,a.AnimationVector),a.augment(a.JSONLoader,a.AnimationVector),a.AnimationVector.prototype.curves={},a.AnimationVector.prototype.frames=250,a.AnimationVector.prototype.startFrame=0,a.AnimationVector.prototype.addAnimationCurve=function(a){this.curves[a.channel]=a;return this},a.AnimationVector.prototype.removeAnimationCurve=function(a){delete this.curves[a]},a.AnimationVector.prototype.setFrames=function(a){this.frames=a;return this},a.AnimationVector.prototype.getFrames=function(){return this.frames},a.AnimationVector.prototype.setStartFrame=function(a){this.startFrame=a;return this},a.AnimationVector.prototype.getStartFrame=function(){return this.startFrame}}(GLGE),function(a){a.BezTriple=function(b){a.Assets.registerAsset(this,b)},a.augment(a.QuickNotation,a.BezTriple),a.augment(a.JSONLoader,a.BezTriple),a.BezTriple.prototype.className="BezTriple",a.BezTriple.prototype.setX1=function(a){this.x1=parseFloat(a);return this},a.BezTriple.prototype.setY1=function(a){this.y1=parseFloat(a);return this},a.BezTriple.prototype.setX2=function(a){this.x=parseFloat(a);return this},a.BezTriple.prototype.setY2=function(a){this.y=parseFloat(a);return this},a.BezTriple.prototype.setX3=function(a){this.x3=parseFloat(a);return this},a.BezTriple.prototype.setY3=function(a){this.y3=parseFloat(a);return this},a.LinearPoint=function(a){},a.augment(a.QuickNotation,a.LinearPoint),a.augment(a.JSONLoader,a.LinearPoint),a.LinearPoint.prototype.className="LinearPoint",a.LinearPoint.prototype.x=0,a.LinearPoint.prototype.y=0,a.LinearPoint.prototype.setX=function(a){this.x=parseFloat(a);return this},a.LinearPoint.prototype.setY=function(a){this.y=parseFloat(a);return this},a.StepPoint=function(a,b){this.x=parseFloat(a),this.y=b}}(GLGE),function(a){a.Mesh=function(b,c){a.Assets.registerAsset(this,b),this.GLbuffers=[],this.buffers=[],this.framePositions=[],this.frameNormals=[],this.frameTangents=[],this.UV=[],this.boneWeights=[],this.setBuffers=[],this.faces={},c!==undefined?this.windingOrder=c:this.windingOrder=a.Mesh.WINDING_ORDER_CLOCKWISE},a.Mesh.WINDING_ORDER_UNKNOWN=2,a.Mesh.WINDING_ORDER_CLOCKWISE=1,a.Mesh.WINDING_ORDER_COUNTER=0,a.augment(a.QuickNotation,a.Mesh),a.augment(a.JSONLoader,a.Mesh),a.augment(a.Events,a.Mesh),a.Mesh.prototype.gl=null,a.Mesh.prototype.className="Mesh",a.Mesh.prototype.GLbuffers=null,a.Mesh.prototype.buffers=null,a.Mesh.prototype.setBuffers=null,a.Mesh.prototype.GLfaces=null,a.Mesh.prototype.faces=null,a.Mesh.prototype.UV=null,a.Mesh.prototype.joints=null,a.Mesh.prototype.invBind=null,a.Mesh.prototype.loaded=!1,a.Mesh.prototype.getBoundingVolume=function(){if(!this.boundingVolume){var b,c,d,e,f,g,h=this.positions;for(var i=0;i0&&(o=k(o,-1),p=k(p,-1));return[o,p]},a.Mesh.prototype.setFaces=function(a){this.faces={data:a,GL:!1},this.normals||this.calcNormals(),!this.tangents&&this.UV.length>0&&this.calcTangents();return this},a.Mesh.prototype.calcTangents=function(){for(var b=0;b0&&(this.GLSetFaceBuffer(b),this.faces.GL=!0);for(f=0;f-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.GLbuffers[this.buffers[f].name]),b.enableVertexAttribArray(attribslot),b.vertexAttribPointer(attribslot,this.GLbuffers[this.buffers[f].name].itemSize,b.FLOAT,!1,0,0));var g=a.getAttribLocation(b,c,"position");g>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.GLbuffers["position"+d]),b.enableVertexAttribArray(g),b.vertexAttribPointer(g,this.GLbuffers["position"+d].itemSize,b.FLOAT,!1,0,0));var h=a.getAttribLocation(b,c,"normal");h>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.GLbuffers["normal"+d]),b.enableVertexAttribArray(h),b.vertexAttribPointer(h,this.GLbuffers["normal"+d].itemSize,b.FLOAT,!1,0,0));var i=a.getAttribLocation(b,c,"tangent");i>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.GLbuffers["tangent"+d]),b.enableVertexAttribArray(i),b.vertexAttribPointer(i,this.GLbuffers["tangent"+d].itemSize,b.FLOAT,!1,0,0));if(e!=undefined){var j=a.getAttribLocation(b,c,"position2");j>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.GLbuffers["position"+e]),b.enableVertexAttribArray(j),b.vertexAttribPointer(j,this.GLbuffers["position"+e].itemSize,b.FLOAT,!1,0,0));var k=a.getAttribLocation(b,c,"normal2");k>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.GLbuffers["normal"+e]),b.enableVertexAttribArray(k),b.vertexAttribPointer(k,this.GLbuffers["normal"+e].itemSize,b.FLOAT,!1,0,0));var l=a.getAttribLocation(b,c,"tangent2");l>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.GLbuffers["tangent"+e]),b.enableVertexAttribArray(l),b.vertexAttribPointer(l,this.GLbuffers["tangent"+e].itemSize,b.FLOAT,!1,0,0))}}}(GLGE),function(a){var b=0;a.Material=function(c){a.Assets.registerAsset(this,c),this.layers=[],this.layerlisteners=[],this.textures=[],this.lights=[],this.color={r:1,g:1,b:1,a:1},this.specColor={r:1,g:1,b:1},this.reflect=.8,this.shine=10,this.specular=1,this.emit={r:0,g:0,b:0},this.alpha=1,this.materialIdx=b++},a.augment(a.Animatable,a.Material),a.augment(a.QuickNotation,a.Material),a.augment(a.JSONLoader,a.Material),a.augment(a.Events,a.Material),a.M_COLOR=1,a.M_NOR=2,a.M_ALPHA=4,a.M_SPECCOLOR=8,a.M_SPECULAR=16,a.M_SHINE=32,a.M_REFLECT=64,a.M_EMIT=128,a.M_ALPHA=256,a.M_MSKR=512,a.M_MSKG=1024,a.M_MSKB=2048,a.M_MSKA=4096,a.M_HEIGHT=8192,a.M_AMBIENT=16384,a.UV1=0,a.UV2=1,a.MAP_NORM=3,a.MAP_OBJ=4,a.MAP_REF=5,a.MAP_ENV=6,a.MAP_VIEW=7,a.MAP_POINT=8,a.BL_MIX=0,a.BL_MUL=1,a.Material.prototype.layers=null,a.Material.prototype.className="Material",a.Material.prototype.textures=null,a.Material.prototype.color=null,a.Material.prototype.specColor=null,a.Material.prototype.specular=null,a.Material.prototype.emit={r:0,g:0,b:0},a.Material.prototype.shine=null,a.Material.prototype.reflect=null,a.Material.prototype.lights=null,a.Material.prototype.alpha=null,a.Material.prototype.ambient=null,a.Material.prototype.shadow=!0,a.Material.prototype.shadeless=!1,a.Material.prototype.downloadComplete=!1,a.Material.prototype.setShadeless=function(a){this.shadeless=a;return this},a.Material.prototype.getShadeless=function(a){return this.shadeless},a.Material.prototype.setShadow=function(a){this.shadow=a;return this},a.Material.prototype.getShadow=function(a){return this.shadow},a.Material.prototype.setColor=function(b){b.r||(b=a.colorParse(b)),this.color={r:b.r,g:b.g,b:b.b},this.fireEvent("shaderupdate",{});return this},a.Material.prototype.setColorR=function(a){this.color.r=a,this.fireEvent("shaderupdate",{});return this},a.Material.prototype.setColorG=function(a){this.color.g=a,this.fireEvent("shaderupdate",{});return this},a.Material.prototype.setColorB=function(a){this.color.b=a,this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getColor=function(){return this.color},a.Material.prototype.setSpecularColor=function(b){b.r||(b=a.colorParse(b)),this.specColor={r:parseFloat(b.r),g:parseFloat(b.g),b:parseFloat(b.b)},this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getAmbient=function(){return this.ambient},a.Material.prototype.setAmbient=function(b){b.r||(b=a.colorParse(b)),this.ambient={r:parseFloat(b.r),g:parseFloat(b.g),b:parseFloat(b.b)},this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getSpecularColor=function(){return this.specColor},a.Material.prototype.setAlpha=function(a){this.alpha=a,this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getAlpha=function(){return this.alpha},a.Material.prototype.setSpecular=function(a){this.specular=a,this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getSpecular=function(){return this.specular},a.Material.prototype.setShininess=function(a){a<=0&&(a=.001),this.shine=a,this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getShininess=function(){return this.shine},a.Material.prototype.setEmit=function(b){b>0&&(b={r:b,g:b,b:b}),b.r||(b=a.colorParse(b)),this.emit={r:parseFloat(b.r),g:parseFloat(b.g),b:parseFloat(b.b)},this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getEmit=function(){return this.emit},a.Material.prototype.setReflectivity=function(a){this.reflect=a,this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getReflectivity=function(){return this.reflect},a.Material.prototype.setBinaryAlpha=function(a){this.binaryAlpha=a,this.fireEvent("shaderupdate",{});return this},a.Material.prototype.getBinaryAlpha=function(){return this.binaryAlpha},a.Material.prototype.addMaterialLayer=function(b){typeof b=="string"&&(b=a.Assets.get(b)),this.layers.push(b);var c=this,d=function(a){c.fireEvent("shaderupdate",{})};this.layerlisteners.push(d),b.addEventListener("shaderupdate",d),this.fireEvent("shaderupdate",{});return this},a.Material.prototype.removeMaterialLayer=function(a){var b=this.layers.indexOf(a);b>=0&&(this.layers.splice(b,1),a.removeEventListener("shaderupdate",this.layerlisteners[b]),this.layerlisteners.splice(b,1),this.fireEvent("shaderupdate",{}));return this},a.Material.prototype.getLayers=function(){return this.layers},a.Material.prototype.getLayerCoords=function(b){var c=[];c.push("vec4 texturePos;\n");for(i=0;i0.0){\n",b[g].diffuse&&(e=e+"lightvalue += att * dotN * lightcolor"+g+";\n"),e=e+"}\n",b[g].specular&&(e=e+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN)*att * specC * lightcolor"+g+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3*sh);\n")),e=e+"spotEffect = 0.0;\n",b[g].type==a.L_SPOT&&(e=e+"spotEffect = dot(normalize(lightdir"+g+"), normalize(-lightvec"+g+"));",e=e+"if (spotEffect > spotCosCutOff"+g+") {\n",e=e+"spotEffect = pow(spotEffect, spotExp"+g+");",b[g].getCastShadows()&&this.shadow&&(e=e+"scoord=(((spotcoord"+g+".xy)/spotcoord"+g+".w)+1.0)/2.0;\n",e=e+"if(scoord.x>0.0 && scoord.x<1.0 && scoord.y>0.0 && scoord.y<1.0){\n",e=e+"dist=texture2D(TEXTURE"+i[g]+", scoord);\n",e=e+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0))*"+b[g].distance+".0;\n",e=e+"spotmul=0.0;\n",e=e+"totalweight=0.0;\n",e=e+"if((depth+shadowbias"+g+"-length(lightvec"+g+"))<0.0) {spotmul=1.0; totalweight=1.0;}\n",b[g].samples>0&&(e=e+"for(int cnt=0; cnt<4; cnt++){;\n",e=e+"spotsampleX=-0.707106781;spotsampleY=-0.707106781;\n",e=e+"if(cnt==0 || cnt==3) spotsampleX=0.707106781;\n",e=e+"if(cnt==1 || cnt==3) spotsampleY=0.707106781;\n",e=e+"spotoffset=vec2(spotsampleX,spotsampleY)*0.5;\n",e=e+"dist=texture2D(TEXTURE"+i[g]+", scoord+spotoffset*shadowsoftness"+g+");\n",e=e+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0))*"+b[g].distance+".0;\n",e=e+"if((depth+shadowbias"+g+"-length(lightvec"+g+"))<0.0){\n",e=e+"spotmul+=length(spotoffset);\n",e=e+"}\n",e=e+"totalweight+=length(spotoffset);\n",e=e+"};\n",e=e+"if(totalweight!=spotmul){\n",e=e+"spotmul=0.0;\n",e=e+"totalweight=0.0;\n",e=e+"for(int cnt=0; cnt<"+b[g].samples+"; cnt++){;\n",e=e+"rnd=(fract(sin(dot(scoord,vec2(12.9898,78.233))) * 43758.5453)-0.5)*2.0;\n",e=e+"spotsampleX=cos(float(cnt)*"+(360/b[g].samples).toFixed(2)+"+rnd);\n",e=e+"spotsampleY=sin(float(cnt)*"+(360/b[g].samples).toFixed(2)+"+rnd);\n",e=e+"spotoffset=vec2(spotsampleX,spotsampleY)*0.5;\n",e=e+"dist=texture2D(TEXTURE"+i[g]+", scoord+spotoffset*shadowsoftness"+g+");\n",e=e+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0))*"+b[g].distance+".0;\n",e=e+"if((depth+shadowbias"+g+"-length(lightvec"+g+"))<0.0){\n",e=e+"spotmul+=length(spotoffset);\n",e=e+"}\n",e=e+"totalweight+=length(spotoffset);\n",e=e+"};\n",e=e+"}\n"),e=e+"if(totalweight>0.0) spotEffect=spotEffect*pow(1.0-spotmul/totalweight,3.0);\n",e=e+"}\n"),e=e+"dotN=max(dot(normal,normalize(-lightvec)),0.0);\n",b[g].negativeShadow?(e=e+"if(dotN>0.0){\n",b[g].diffuse&&(e=e+"lightvalue -= (1.0-spotEffect) / (lightAttenuation"+g+"[0] + lightAttenuation"+g+"[1] * lightdist"+g+" + lightAttenuation"+g+"[2] * lightdist"+g+" * lightdist"+g+");\n"),e=e+"}\n"):(e=e+"att = spotEffect / (lightAttenuation"+g+"[0] + lightdist"+g+"*(lightAttenuation"+g+"[1] + lightAttenuation"+g+"[2] * lightdist"+g+"));\n",e=e+"if(dotN>0.0){\n",b[g].diffuse&&(e=e+"lightvalue += att * dotN * lightcolor"+g+";\n"),e=e+"}\n",b[g].specular&&(e=e+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN) * att * specC * lightcolor"+g+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3 * sh);\n")),e=e+"}\n");if(b[g].type==a.L_DIR){e=e+"dotN=max(dot(normal,-normalize(lightvec)),0.0);\n";if(b[g].getCastShadows()&&this.shadow){e=e+"float shadowfact"+g+" = 0.0;\n",e=e+"float level"+g+" = 1.0;\n",e=e+"scoord=((spotcoord"+g+".xy)+1.0)/2.0;\n";var o=b[g].getCascadeLevels();for(var p=1;p1.0 || scoord.y<0.0 || scoord.y>1.0) {scoord=((spotcoord"+g+".xy-shadowoffset"+g+")*"+Math.pow(.5,p).toFixed(5)+"+shadowoffset"+g+"+1.0)/2.0;level"+g+"="+(p+1).toFixed(2)+";};\n";e=e+"scoord.y=scoord.y/"+o.toFixed(2)+"+1.0-"+1/o+"*level"+g+";\n";if(b[g].samples==0)e=e+"dist=texture2D(TEXTURE"+i[g]+", scoord);\n",e=e+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0))*"+(+b[g].distance).toFixed(2)+";\n",e=e+"sDepth = ((spotcoord"+g+".z)/spotcoord"+g+".w+1.0)/2.0;\n",e=e+"if(scoord.x>0.0 && scoord.x<1.0 && scoord.y>0.0 && scoord.y<1.0 && sDepth-shadowbias"+g+"-depth>0.0) {\n",e=e+"shadowfact"+g+"=pow(clamp(2.0*length(eyevec)/"+(+b[g].distance).toFixed(2)+",0.0,1.0),2.0);\n",e=e+"}else{shadowfact"+g+"=1.0;}\n";else{e=e+"rnd=(fract(sin(dot(scoord,vec2(12.9898,78.233))) * 43758.5453)-0.5)*2.0;\n";for(var q=-b[g].samples;q<=b[g].samples;q++)for(var r=-b[g].samples;r<=b[g].samples;r++)e=e+"dist=texture2D(TEXTURE"+i[g]+", scoord+vec2("+(q/b[g].bufferWidth).toFixed(4)+","+(r/b[g].bufferHeight).toFixed(4)+")*shadowsoftness"+g+"*100.0/level"+g+"+vec2("+(1/b[g].bufferWidth).toFixed(4)+","+(1/b[g].bufferHeight).toFixed(4)+")*rnd);\n",e=e+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0))*"+(+b[g].distance).toFixed(2)+";\n",e=e+"sDepth = ((spotcoord"+g+".z)/spotcoord"+g+".w+1.0)/2.0;\n",e=e+"if(scoord.x>0.0 && scoord.x<1.0 && scoord.y>0.0 && scoord.y<1.0 && sDepth-shadowbias"+g+"-depth>0.0) {\n",e=e+"shadowfact"+g+"+=pow(clamp(2.0*length(eyevec)/"+(+b[g].distance).toFixed(2)+",0.0,1.0),2.0);\n",e=e+"}else{shadowfact"+g+"+=1.0;}\n";e=e+"shadowfact"+g+"/="+((b[g].samples*2+1)*(b[g].samples*2+1)).toFixed(1)+";\n"}}else e=e+"float shadowfact"+g+" = 1.0;\n";b[g].diffuse&&(e=e+"lightvalue += dotN * lightcolor"+g+" * shadowfact"+g+";\n"),b[g].specular&&(e=e+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN) * specC * lightcolor"+g+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3 * sh);\n")}}e=e+"lightvalue = (lightvalue)*ref;\n",e=e+"vec3 fc=fogcolor.rgb;\n",e=e+"if(fogtype=="+a.FOG_SKYLINEAR+" || fogtype=="+a.FOG_SKYQUADRATIC+"){",e=e+"vec4 view=projection * vec4(-eyevec,1.0);\n",e=e+"vec2 fogCoords=view.xy/view.w*0.5+0.5;\n",e=e+"fc=texture2D(sky,fogCoords.xy).rgb;\n",e=e+"}\n",e=e+"vec4 finalColor =vec4(specvalue.rgb+color.rgb*lightvalue.rgb+em.rgb,al)*fogfact+vec4(fc,al)*(1.0-fogfact);\n",d&&~d.indexOf("GLGE_FragColor")&&(e=e+"finalColor=GLGE_FragColor(finalColor);\n"),e=e+"gl_FragColor = finalColor;",a.DEBUGNORMALS&&(e=e+"gl_FragColor = vec4(normal.rgb,1.0);"),a.DEBUGCOORD0&&(e=e+"gl_FragColor = vec4(textureCoords0.rg,0.0,1.0);"),e=e+"}\n",e=e+"}\n";return e},a.Material.prototype.textureUniforms=function(b,c,d,e){this.animation&&this.animate();var f=c.caches;f.baseColor!=this.color&&(this.ccache!=this.color&&(this.ccache=this.color,this.glColor=new Float32Array([this.color.r,this.color.g,this.color.b,this.color.a])),b.uniform4fv(a.getUniformLocation(b,c,"baseColor"),this.glColor),f.baseColor=this.color),f.specColor!=this.specColor&&(this.sccache!=this.specColor&&(this.sccache=this.specColor,this.glspecColor=new Float32Array([this.specColor.r,this.specColor.g,this.specColor.b])),b.uniform3fv(a.getUniformLocation(b,c,"specColor"),this.glspecColor),f.specColor=this.specColor),f.emit!=this.emit&&(b.uniform3f(a.getUniformLocation(b,c,"emit"),this.emit.r,this.emit.g,this.emit.b),f.emit=this.emit),f.specular!=this.specular&&(a.setUniform(b,"1f",a.getUniformLocation(b,c,"specular"),this.specular),f.specular=this.specular),f.shine!=this.shine&&(a.setUniform(b,"1f",a.getUniformLocation(b,c,"shine"),this.shine),f.shine=this.shine),f.reflect!=this.reflect&&(a.setUniform(b,"1f",a.getUniformLocation(b,c,"reflective"),this.reflect),f.reflect=this.reflect),f.alpha!=this.alpha&&(a.setUniform(b,"1f",a.getUniformLocation(b,c,"alpha"),this.alpha),f.alpha=this.alpha);if(f.shadeless==undefined||f.shadeless!=this.shadeless)a.setUniform(b,"1i",a.getUniformLocation(b,c,"shadeless"),this.shadeless),f.shadeless=this.shadeless;b.scene.skyTexture&&(b.activeTexture(b.TEXTURE0),b.bindTexture(b.TEXTURE_2D,b.scene.skyTexture),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR),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),a.setUniform(b,"1i",a.getUniformLocation(b,c,"sky"),0));var g=1,h=0;f.lightcolor||(f.lightcolor=[],f.lightAttenuation=[],f.spotCosCutOff=[],f.spotExponent=[],f.shadowbias=[],f.castshadows=[],f.shadowsamples=[],f.shadowsoftness=[]);for(var i=0;i1)for(var d=1;db&&e0}}(GLGE),function(a){a.TextureCamera=function(b){a.Assets.registerAsset(this,b)},a.augment(a.QuickNotation,a.TextureCamera),a.augment(a.JSONLoader,a.TextureCamera),a.augment(a.Events,a.TextureCamera),a.TextureCamera.prototype.className="Texture",a.TextureCamera.prototype.texture=null,a.TextureCamera.prototype.glTexture=null,a.TextureCamera.prototype.object=null,a.TextureCamera.prototype.camera=null,a.TextureCamera.prototype.bufferHeight=0,a.TextureCamera.prototype.bufferWidth=0,a.TextureCamera.prototype.planeOffset=0,a.TextureCamera.prototype.mirrorAxis=a.NONE,a.TextureCamera.prototype.clipAxis=a.NONE,a.TextureCamera.prototype.setPlaneOffset=function(a){this.planeOffset=a;return this},a.TextureCamera.prototype.getPlaneOffset=function(){return this.planeOffset},a.TextureCamera.prototype.setBufferWidth=function(a){this.bufferWidth=a,this.update=!0;return this},a.TextureCamera.prototype.getBufferWidth=function(){return this.bufferWidth},a.TextureCamera.prototype.setBufferHeight=function(a){this.bufferHeight=a,this.update=!0;return this},a.TextureCamera.prototype.getBufferHeight=function(){return this.bufferHeight},a.TextureCamera.prototype.setClipAxis=function(a){this.clipAxis=a;return this},a.TextureCamera.prototype.getClipAxis=function(){return this.clipAxis},a.TextureCamera.prototype.setMirrorAxis=function(a){this.mirrorAxis=a;return this},a.TextureCamera.prototype.getMirrorAxis=function(){return this.mirrorAxis},a.TextureCamera.prototype.setCamera=function(a){this.camera=a;return this},a.TextureCamera.prototype.getCamera=function(){return this.camera},a.TextureCamera.prototype.doTexture=function(b,c){if(this.camera){this.gl=b;var d=c.getModelMatrix(),e=b.scene.camera.getProjectionMatrix(),f=this.camera.getViewMatrix(),g;if(this.mirrorAxis)switch(this.mirrorAxis){case a.XAXIS:g=a.mulMat4(a.mulMat4(a.mulMat4(f,d),a.scaleMatrix(-1,1,1)),a.inverseMat4(d));break;case a.YAXIS:g=a.mulMat4(a.mulMat4(a.mulMat4(f,d),a.scaleMatrix(1,-1,1)),a.inverseMat4(d));break;case a.ZAXIS:g=a.mulMat4(a.mulMat4(a.mulMat4(f,d),a.scaleMatrix(1,1,-1)),a.inverseMat4(d))}else g=f;if(this.clipAxis){var h;switch(this.clipAxis){case a.NEG_XAXIS:var i=a.toUnitVec3([-d[0],-d[4],-d[8]]);h=[i[0],i[1],i[2],-a.dotVec3([d[3],d[7],d[11]],i)-this.planeOffset];break;case a.POS_XAXIS:var i=a.toUnitVec3([d[0],d[4],d[8]]);h=[i[0],i[1],i[2],-a.dotVec3([d[3],d[7],d[11]],i)-this.planeOffset];break;case a.NEG_YAXIS:var i=a.toUnitVec3([-d[1],-d[5],-d[9]]);h=[i[0],i[1],i[2],-a.dotVec3([d[3],d[7],d[11]],i)-this.planeOffset];break;case a.POS_YAXIS:var i=a.toUnitVec3([d[1],d[5],d[9]]);h=[i[0],i[1],i[2],-a.dotVec3([d[3],d[7],d[11]],i)-this.planeOffset];break;case a.NEG_ZAXIS:var i=a.toUnitVec3([-d[2],-d[6],-d[10]]);h=[i[0],i[1],i[2],-a.dotVec3([d[3],d[7],d[11]],i)-this.planeOffset];break;case a.POS_ZAXIS:var i=a.toUnitVec3([d[2],d[6],d[10]]);h=[i[0],i[1],i[2],-a.dotVec3([d[3],d[7],d[11]],i)-this.planeOffset]}var j=a.transposeMat4(a.inverseMat4(a.mulMat4(e,g)));h=a.mulMat4Vec4(j,h),h=a.scaleVec4(h,e[10]),h[3]-=1,h[2]<0&&a.scaleVec4(h,-1);var k=[1,0,0,0,0,1,0,0,h[0],h[1],h[2],h[3],0,0,0,1];e=a.mulMat4(k,e)}var l=this.bufferHeight?this.bufferHeight:b.scene.renderer.canvas.height,m=this.bufferWidth?this.bufferWidth:b.scene.renderer.canvas.width;if(!this.glTexture||this.update){this.createFrameBuffer(b),b.scene.addRenderPass(this.frameBuffer,g,b.scene.camera.getProjectionMatrix(),m,l,c),b.bindTexture(b.TEXTURE_2D,this.glTexture),this.update=!1;return!1}b.bindTexture(b.TEXTURE_2D,this.glTexture),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.LINEAR),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.LINEAR),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),b.scene.addRenderPass(this.frameBuffer,g,e,m,l,c);return!0}return!1},a.TextureCamera.prototype.registerPasses=a.TextureCamera.prototype.doTexture,a.TextureCamera.prototype.createFrameBuffer=function(a){var b=this.bufferHeight?this.bufferHeight:a.scene.renderer.canvas.height,c=this.bufferWidth?this.bufferWidth:a.scene.renderer.canvas.width;this.frameBuffer||(this.frameBuffer=a.createFramebuffer()),this.renderBuffer||(this.renderBuffer=a.createRenderbuffer()),this.glTexture||(this.glTexture=a.createTexture()),a.bindTexture(a.TEXTURE_2D,this.glTexture);var d=new Uint8Array(c*b*4);a.texImage2D(a.TEXTURE_2D,0,a.RGBA,c,b,0,a.RGBA,a.UNSIGNED_BYTE,d),a.bindFramebuffer(a.FRAMEBUFFER,this.frameBuffer),a.bindRenderbuffer(a.RENDERBUFFER,this.renderBuffer),a.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,c,b),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,this.renderBuffer),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,this.glTexture,0),a.bindRenderbuffer(a.RENDERBUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_2D,null)}}(GLGE),function(a){a.TextureCanvas=function(b){a.Assets.registerAsset(this,b),this.canvas=document.createElement("canvas")},a.augment(a.QuickNotation,a.TextureCanvas),a.augment(a.JSONLoader,a.TextureCanvas),a.augment(a.Events,a.TextureCanvas),a.TextureCanvas.prototype.className="TextureCanvas",a.TextureCanvas.prototype.glTexture=null,a.TextureCanvas.prototype.autoUpdate=!0,a.TextureCanvas.prototype.getAutoUpdate=function(){return this.autoUpdate},a.TextureCanvas.prototype.setAutoUpdate=function(a){this.autoUpdate=a;return this},a.TextureCanvas.prototype.getCanvas=function(){return this.canvas},a.TextureCanvas.prototype.setCanvas=function(a){this.canvas=a;return this},a.TextureCanvas.prototype.setHeight=function(a){this.canvas.height=a;return this},a.TextureCanvas.prototype.setWidth=function(a){this.canvas.width=a;return this},a.TextureCanvas.prototype.getHeight=function(){return this.canvas.height},a.TextureCanvas.prototype.getWidth=function(){return this.canvas.width},a.TextureCanvas.prototype.doTexture=function(a){this.gl=a,this.glTexture?(a.bindTexture(a.TEXTURE_2D,this.glTexture),(this.autoUpdate||this.doUpdate)&&this.updateCanvas(a)):(this.glTexture=a.createTexture(),a.bindTexture(a.TEXTURE_2D,this.glTexture),this.updateCanvas(a)),this.doUpdate=!1;return!0},a.TextureCanvas.prototype.update=function(){this.doUpdate=!0},a.TextureCanvas.prototype.updateCanvas=function(a){var b=this.canvas;a.bindTexture(a.TEXTURE_2D,this.glTexture);try{a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,b)}catch(c){a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,b,null)}a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.generateMipmap(a.TEXTURE_2D)}}(GLGE),function(a){a.TextureCube=function(b){a.Assets.registerAsset(this,b)},a.augment(a.QuickNotation,a.TextureCube),a.augment(a.JSONLoader,a.TextureCube),a.augment(a.Events,a.TextureCube),a.TextureCube.prototype.className="TextureCube",a.TextureCube.prototype.posX=null,a.TextureCube.prototype.negX=null,a.TextureCube.prototype.posY=null,a.TextureCube.prototype.negY=null,a.TextureCube.prototype.posZ=null,a.TextureCube.prototype.negZ=null,a.TextureCube.prototype.texture=null,a.TextureCube.prototype.glTexture=null,a.TextureCube.prototype.loadState=0,a.TextureCube.prototype.setSrc=function(a,b,c){this.url=a,this.state=0,this[b]=new Image;var d=this;this[b].onload=function(){d.loadState+=c},this[b].src=a,this.glTexture&&this.gl&&(this.gl.deleteTexture(this.glTexture),this.glTexture=null);return this},a.TextureCube.prototype.setSrcPosX=function(a){this.setSrc(a,"posX",1);return this},a.TextureCube.prototype.setSrcNegX=function(a){this.setSrc(a,"negX",2);return this},a.TextureCube.prototype.setSrcPosY=function(a){this.setSrc(a,"posY",4);return this},a.TextureCube.prototype.setSrcNegY=function(a){typeof a!="string"?(this.negY=a,this.loadState+=8):this.setSrc(a,"negY",8);return this},a.TextureCube.prototype.setSrcPosZ=function(a){this.setSrc(a,"posZ",16);return this},a.TextureCube.prototype.setSrcNegZ=function(a){this.setSrc(a,"negZ",32);return this},a.TextureCube.prototype.doTexture=function(a,b){this.gl=a,this.glTexture||(this.glTexture=a.createTexture()),a.bindTexture(a.TEXTURE_CUBE_MAP,this.glTexture),this.loadState==63&&this.state==0&&(a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.posX),a.texImage2D(a.TEXTURE_CUBE_MAP_NEGATIVE_X,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.negX),a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_Y,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.posY),a.texImage2D(a.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.negY),a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_Z,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.posZ),a.texImage2D(a.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.negZ),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MIN_FILTER,a.LINEAR_MIPMAP_LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.generateMipmap(a.TEXTURE_CUBE_MAP),a.bindTexture(a.TEXTURE_CUBE_MAP,null),this.state=1),a.bindTexture(a.TEXTURE_CUBE_MAP,this.glTexture);return this.state==1?!0:!1}}(GLGE),function(a){a.TextureVideo=function(b){a.Assets.registerAsset(this,b),this.video=document.createElement("video"),this.video.style.display="none",this.video.setAttribute("loop","loop"),this.video.autoplay=!0,this.video.addEventListener("ended",function(){this.play()},!0),document.getElementsByTagName("body")[0].appendChild(this.video),this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d")},a.augment(a.QuickNotation,a.TextureVideo),a.augment(a.JSONLoader,a.TextureVideo),a.augment(a.Events,a.TextureVideo),a.TextureVideo.prototype.className="TextureVideo",a.TextureVideo.prototype.glTexture=null,a.TextureVideo.prototype.getVideo=function(){return this.video},a.TextureVideo.prototype.setVideo=function(a){this.video=a;return this},a.TextureVideo.prototype.setSrc=function(a){this.video.src=a;return this},a.TextureVideo.prototype.getSrc=function(a){return this.video.src},a.TextureVideo.prototype.doTexture=function(a){this.gl=a,this.glTexture?(a.bindTexture(a.TEXTURE_2D,this.glTexture),this.updateTexture(a)):(this.glTexture=a.createTexture(),a.bindTexture(a.TEXTURE_2D,this.glTexture),this.updateTexture(a));return!0},a.TextureVideo.prototype.updateTexture=function(a){var b=this.video;a.bindTexture(a.TEXTURE_2D,this.glTexture);if(b.readyState>0){b.height<=0&&(b.style.display="",b.height=b.offsetHeight,b.width=b.offsetWidth,b.style.display="none"),this.canvas.height=b.height,this.canvas.width=b.width,this.ctx.drawImage(b,0,0);try{a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.canvas)}catch(c){a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.canvas,null)}a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.generateMipmap(a.TEXTURE_2D)}}}(GLGE),function(a){a.ObjectLod=function(b){a.Assets.registerAsset(this,b),this.setMaterial(a.DEFAULT_MATERIAL)},a.augment(a.QuickNotation,a.ObjectLod),a.augment(a.JSONLoader,a.ObjectLod),a.augment(a.Events,a.ObjectLod),a.ObjectLod.prototype.mesh=null,a.ObjectLod.prototype.className="ObjectLod",a.ObjectLod.prototype.material=null,a.ObjectLod.prototype.program=null,a.ObjectLod.prototype.GLShaderProgramPick=null,a.ObjectLod.prototype.GLShaderProgramShadow=null,a.ObjectLod.prototype.GLShaderProgram=null,a.ObjectLod.prototype.pixelSize=0,a.ObjectLod.prototype.setMesh=function(b){typeof b=="string"&&(b=a.Assets.get(b)),this.mesh&&this.mesh.removeEventListener("shaderupdate",this.meshupdated);var c=this;this.meshupdated=function(a){c.GLShaderProgram=null},b.addEventListener("shaderupdate",this.meshupdated),this.GLShaderProgram=null,this.mesh=b;return this},a.ObjectLod.prototype.isComplete=function(){return this.material.isComplete()},a.ObjectLod.prototype.getMesh=function(){return this.mesh},a.ObjectLod.prototype.setMaterial=function(b){typeof b=="string"&&(b=a.Assets.get(b)),this.material&&(this.material.removeEventListener("shaderupdate",this.materialupdated),this.material.removeEventListener("downloadComplete",this.downloadComplete));var c=this;this.materialupdated=function(a){c.GLShaderProgram=null},b.addEventListener("shaderupdate",this.materialupdated),this.downloadComplete=function(){c.fireEvent("downloadComplete")},b.addEventListener("downloadComplete",this.downloadComplete),this.GLShaderProgram=null,this.material=b;return this},a.ObjectLod.prototype.getMaterial=function(){return this.material},a.ObjectLod.prototype.getPixelSize=function(){return this.pixelSize},a.ObjectLod.prototype.setPixelSize=function(a){this.pixelSize=parseFloat(a)}}(GLGE),function(a){a.Object=function(b){a.Assets.registerAsset(this,b),this.multimaterials=[],this.renderCaches=[];var c=this;this.downloadComplete=function(){c.isComplete()&&c.fireEvent("downloadComplete")}},a.augment(a.Placeable,a.Object),a.augment(a.Animatable,a.Object),a.augment(a.QuickNotation,a.Object),a.augment(a.JSONLoader,a.Object),a.Object.prototype.className="Object",a.Object.prototype.mesh=null,a.Object.prototype.skeleton=null,a.Object.prototype.scene=null,a.Object.prototype.transformMatrix=a.identMatrix(),a.Object.prototype.material=null,a.Object.prototype.gl=null,a.Object.prototype.multimaterials=null,a.Object.prototype.zTrans=!1,a.Object.prototype.renderCaches=null,a.Object.prototype.id="",a.Object.prototype.pickable=!0,a.Object.prototype.drawType=a.DRAW_TRIS,a.Object.prototype.pointSize=1,a.Object.prototype.lineWidth=1,a.Object.prototype.cull=!0,a.Object.prototype.culled=!0,a.Object.prototype.depthTest=!0,a.Object.prototype.meshFrame1=0,a.Object.prototype.meshFrame2=0,a.Object.prototype.meshBlendFactor=0;var b=[];b.push("#ifdef GL_ES\nprecision highp float;\n#endif\n"),b.push("uniform float distance;\n"),b.push("uniform bool shadowtype;\n"),b.push("varying vec3 eyevec;\n"),b.push("void main(void)\n "),b.push("{\n"),b.push("float depth = gl_FragCoord.z / gl_FragCoord.w;\n"),b.push("vec4 rgba=fract(depth/distance * vec4(16777216.0, 65536.0, 256.0, 1.0));\n"),b.push("gl_FragColor=rgba-rgba.rrgb*vec4(0.0,0.00390625,0.00390625,0.00390625);\n"),b.push("}\n"),a.Object.prototype.shfragStr=b.join("");var c=[];c.push("#ifdef GL_ES\nprecision highp float;\n#endif\n"),c.push("varying vec3 n;\n"),c.push("void main(void)\n"),c.push("{\n"),c.push("float depth = gl_FragCoord.z / gl_FragCoord.w;\n"),c.push("gl_FragColor=vec4(normalize(n)/2.0+0.5,depth/1000.0);\n"),c.push("}\n"),a.Object.prototype.nfragStr=c.join("");var d=[];d.push("#ifdef GL_ES\nprecision highp float;\n#endif\n"),d.push("uniform float far;\n"),d.push("uniform vec3 pickcolor;\n"),d.push("varying vec3 n;\n"),d.push("varying vec4 UVCoord;\n"),d.push("void main(void)\n"),d.push("{\n"),d.push("float Xcoord = gl_FragCoord.x+0.5;\n"),d.push("if(Xcoord>0.0) gl_FragColor = vec4(pickcolor,1.0);\n"),d.push("if(Xcoord>1.0) gl_FragColor = vec4(n,1.0);\n"),d.push("if(Xcoord>2.0){"),d.push("vec3 rgb=fract((gl_FragCoord.z/gl_FragCoord.w) * vec3(65536.0, 256.0, 1.0));\n"),d.push("gl_FragColor=vec4(rgb-rgb.rrg*vec3(0.0,0.00390625,0.00390625),1.0);\n"),d.push("}"),d.push("if(Xcoord>3.0){"),d.push("vec3 rgb=fract(UVCoord.x * vec3(65536.0, 256.0, 1.0));\n"),d.push("gl_FragColor=vec4(rgb-rgb.rrg*vec3(0.0,0.00390625,0.00390625),1.0);\n"),d.push("}"),d.push("if(Xcoord>4.0){"),d.push("vec3 rgb=fract(UVCoord.y * vec3(65536.0, 256.0, 1.0));\n"),d.push("gl_FragColor=vec4(rgb-rgb.rrg*vec3(0.0,0.00390625,0.00390625),1.0);\n"),d.push("}"),d.push("}\n"),a.Object.prototype.pkfragStr=d.join(""),a.Object.prototype.setMeshFrame1=function(a){this.meshFrame1=a;return this},a.Object.prototype.setMeshFrame2=function(a){this.meshFrame2=a;return this},a.Object.prototype.setMeshBlendFactor=function(a){this.meshBlendFactor=a;return this},a.Object.prototype.getPickable=function(){return this.pickable},a.Object.prototype.setPickable=function(a){this.pickable=a;return this},a.Object.prototype.getDepthTest=function(){return this.depthTest},a.Object.prototype.setDepthTest=function(a){this.depthTest=a;return this},a.Object.prototype.getCull=function(){return this.cull},a.Object.prototype.setCull=function(a){this.cull=a;return this},a.Object.prototype.getDrawType=function(){return this.drawType},a.Object.prototype.setDrawType=function(a){this.drawType=a;return this},a.Object.prototype.getPointSize=function(){return this.pointSize},a.Object.prototype.setPointSize=function(a){this.pointSize=parseFloat(a);return this},a.Object.prototype.getLineWidth=function(){return this.lineWidth},a.Object.prototype.setLineWidth=function(a){this.lineWidth=parseFloat(a);return this},a.Object.prototype.setUniform=function(a,b,c){this.uniforms||(this.uniforms={}),this.uniforms[b]={type:a,value:c}},a.Object.prototype.getUniform=function(a){this.uniforms||(this.uniforms={});return this.uniforms[a].value},a.Object.prototype.getUniformType=function(a){this.uniforms||(this.uniforms={});return this.uniforms[a].type},a.Object.prototype.setVertexShaderInjection=function(a){this.shaderVertexInjection=a,this.updateProgram();return this},a.Object.prototype.getVertexShaderInjection=function(a){return this.shaderVertexInjection},a.Object.prototype.getSkeleton=function(){return this.skeleton},a.Object.prototype.setSkeleton=function(a){this.skeleton=a,this.bones=null;return this},a.Object.prototype.getBoundingVolume=function(b){b||(b=0),this.boundingVolume||(this.boundingVolume=[]),this.boundmatrix||(this.boundmatrix=[]);var c=this.getModelMatrix();if(c!=this.boundmatrix[b]||!this.boundingVolume[b]){var d=this.multimaterials,e;for(var f=0;f1?e.push("attribute vec"+this.mesh.buffers[g].size+" "+this.mesh.buffers[g].name+";\n"):e.push("attribute float "+this.mesh.buffers[g].name+";\n"),this.mesh.buffers[g].name=="UV"&&(UV=!0),this.mesh.buffers[g].name=="color"&&(c=!0),this.mesh.buffers[g].name=="joints1"&&(joints1=this.mesh.buffers[g]),this.mesh.buffers[g].name=="joints2"&&(joints2=this.mesh.buffers[g])}if(this.mesh.framePositions.length>1){var h=!0;e.push("attribute vec3 position2;\n"),e.push("attribute vec3 normal2;\n"),e.push("uniform float framesBlend;\n"),f&&e.push("attribute vec3 tangent2;\n")}f&&e.push("attribute vec3 tangent;\n"),e.push("uniform mat4 worldView;\n"),e.push("uniform mat4 projection;\n"),e.push("uniform mat4 worldInverseTranspose;\n"),e.push("uniform mat4 envMat;\n"),e.push("uniform float cascadeLevel;\n");for(var g=0;g0&&e.push("uniform vec4 jointMat["+3*this.mesh.joints.length+"];\n"),this.material&&e.push(this.material.getVertexVarying(e)),e.push("varying vec3 n;\n"),e.push("varying vec3 t;\n"),c&&e.push("varying vec4 vcolor;\n"),e.push("varying vec4 UVCoord;\n"),e.push("varying vec3 OBJCoord;\n"),this.shaderVertexInjection&&e.push(this.shaderVertexInjection),e.push("void main(void)\n"),e.push("{\n"),c&&e.push("vcolor=color;\n"),UV?e.push("UVCoord=UV;\n"):e.push("UVCoord=vec4(0.0,0.0,0.0,0.0);\n"),e.push("OBJCoord = position;\n"),e.push("vec3 tang;\n"),e.push("vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n"),e.push("vec4 norm = vec4(0.0, 0.0, 0.0, 1.0);\n"),f&&e.push("vec4 tang4 = vec4(0.0, 0.0, 0.0, 1.0);\n");if(joints1){if(joints1.size==1)e.push("pos += vec4(dot(jointMat[int(3.0*joints1)],vec4(position,1.0)),\n dot(jointMat[int(3.0*joints1+1.0)],vec4(position,1.0)),\n dot(jointMat[int(3.0*joints1+2.0)],vec4(position,1.0)),1.0)*weights1;\n"),e.push("norm += vec4(dot(jointMat[int(3.0*joints1)].xyz,normal),\n dot(jointMat[int(3.0*joints1+1.0)].xyz,normal),\n dot(jointMat[int(3.0*joints1+2.0)].xyz,normal),1.0)*weights1;\n"),f&&e.push("tang4 += vec4(dot(jointMat[int(3.0*joints1)].xyz,tangent),\n dot(jointMat[int(3.0*joints1+1.0)].xyz,tangent),\n dot(jointMat[int(3.0*joints1+2.0)].xyz,tangent),1.0)*weights1;\n");else for(var g=0;g-1&&e.push("pos=GLGE_Position(vec4(pos.xyz, 1.0));\n"),e.push("pos = worldView * vec4(pos.xyz, 1.0);\n"),e.push("norm = worldInverseTranspose * vec4(norm.xyz, 1.0);\n"),f&&e.push("tang = (worldInverseTranspose*vec4(tang4.xyz,1.0)).xyz;\n")}else{h?e.push("vec4 pos4=vec4(mix(position,position2,framesBlend),1.0);\n"):e.push("vec4 pos4=vec4(position,1.0);\n"),this.shaderVertexInjection&&this.shaderVertexInjection.indexOf("GLGE_Position")>-1&&e.push("pos4=GLGE_Position(pos4);\n");for(var g=0;g>16&255,g=d>>8&255,h=d&255;a.setUniform3(b,"3f",a.getUniformLocation(b,e,"pickcolor"),h/255,g/255,f/255)}b.lineWidth(this.lineWidth);for(key in this.uniforms){var i=this.uniforms[key];i.type=="Matrix4fv"?a.setUniformMatrix(b,"Matrix4fv",a.getUniformLocation(b,e,key),!1,i.value):a.setUniform(b,i.type,a.getUniformLocation(b,e,key),i.value)}e.caches||(e.caches={}),e.glarrays||(e.glarrays={});var j=e.caches,k=e.glarrays,l=b.scene,m=l.camera;j.far!=m.far&&(a.setUniform(b,"1i",a.getUniformLocation(b,e,"far"),m.far),j.far=m.far);if(c==a.RENDER_DEFAULT||c==a.RENDER_EMIT){if(j.ambientColor!=l.ambientColor){var n=l.ambientColor;a.setUniform3(b,"3f",a.getUniformLocation(b,e,"amb"),n.r,n.g,n.b),j.ambientColor=n}j.fogFar!=l.fogFar&&(a.setUniform(b,"1f",a.getUniformLocation(b,e,"fogfar"),l.fogFar),j.fogFar=l.fogFar),j.fogNear!=l.fogNear&&(a.setUniform(b,"1f",a.getUniformLocation(b,e,"fognear"),l.fogNear),j.fogNear=l.fogNear),j.fogType!=l.fogType&&(a.setUniform(b,"1i",a.getUniformLocation(b,e,"fogtype"),l.fogType),j.fogType=l.fogType),j.fogType!=l.fogcolor&&(a.setUniform3(b,"3f",a.getUniformLocation(b,e,"fogcolor"),l.fogColor.r,l.fogColor.g,l.fogColor.b),j.fogcolor=l.fogcolor)}j.meshBlendFactor!=this.meshBlendFactor&&(a.setUniform(b,"1f",a.getUniformLocation(b,e,"framesBlend"),this.meshBlendFactor),j.meshBlendFactor=this.meshBlendFactor);var o=m.getViewMatrix(),p=this.getModelMatrix();j.mvMatrix||(j.mvMatrix={cameraMatrix:null,modelMatrix:null});var q=j.mvMatrix;if(q.cameraMatrix!=o||q.modelMatrix!=p){this.caches.mvMatrix||(this.caches.mvMatrix=a.mulMat4(o,p)),mvMatrix=this.caches.mvMatrix,this.mesh.joints&&(mvMatrix=o);var r=a.getUniformLocation(b,e,"worldView"),s=a.transposeMat4(mvMatrix);k.mvMatrix?a.mat4gl(s,k.mvMatrixT):k.mvMatrixT=new Float32Array(s),k.mvMatrix=mvMatrix,a.setUniformMatrix(b,"Matrix4fv",r,!1,e.glarrays.mvMatrixT);var t=a.getUniformLocation(b,e,"envMat");if(t){if(!this.caches.envMat){var u=a.inverseMat4(mvMatrix);u[3]=0,u[7]=0,u[11]=0,this.caches.envMat=u}u=this.caches.envMat,s=a.transposeMat4(u),e.glarrays.envMat?a.mat4gl(s,k.envMatT):k.envMatT=new Float32Array(s),k.envMat=u,a.setUniformMatrix(b,"Matrix4fv",t,!1,k.envMatT)}if(!this.caches.normalMatrix){var v=a.inverseMat4(mvMatrix);this.caches.normalMatrix=v}v=this.caches.normalMatrix;var w=a.getUniformLocation(b,e,"worldInverseTranspose");k.normalMatrix?a.mat4gl(v,k.normalMatrix):k.normalMatrix=new Float32Array(v),a.setUniformMatrix(b,"Matrix4fv",w,!1,k.normalMatrix);var x=a.getUniformLocation(b,e,"view");s=a.transposeMat4(o),k.cameraMatrix?a.mat4gl(s,k.cameraMatrixT):k.cameraMatrixT=new Float32Array(s),k.cameraMatrix=o,a.setUniformMatrix(b,"Matrix4fv",x,!1,k.cameraMatrixT),q.cameraMatrix=o,q.modelMatrix=p}var y=a.getUniformLocation(b,e,"projection");s=a.transposeMat4(m.getProjectionMatrix()),k.pMatrix?a.mat4gl(s,k.pMatrixT):k.pMatrixT=new Float32Array(s),k.pMatrix=m.getProjectionMatrix(),a.setUniformMatrix(b,"Matrix4fv",y,!1,k.pMatrixT);if(c==a.RENDER_DEFAULT||c==a.RENDER_SHADOW||c==a.RENDER_DEPTH||c==a.RENDER_EMIT){var z,A,B=b.lights;j.lights||(j.lights=[]),k.lights||(k.lights=[]),this.caches.lights||(this.caches.lights=[]);var C=j.lights;for(var D=0;D1&&!i){var m=b.scene.camera.getPosition(),n=this.getPosition(),o=a.lengthVec3([m.x-n.x,m.y-n.y,m.z-n.z]);o=a.mulMat4Vec4(b.scene.camera.getProjectionMatrix(),[this.getBoundingVolume().getSphereRadius(),0,-o,1]),i=o[0]/o[3]*b.scene.renderer.canvas.width}var p=this.multimaterials[l].getLOD(i);if(p.mesh&&p.mesh.loaded){if(c==a.RENDER_NULL){p.material&&p.material.registerPasses(b,this);break}p.GLShaderProgram?(this.GLShaderProgramPick=p.GLShaderProgramPick,this.GLShaderProgramShadow=p.GLShaderProgramShadow,this.GLShaderProgram=p.GLShaderProgram):this.createShaders(p),this.mesh=p.mesh,this.material=p.material;var q;switch(this.drawType){case a.DRAW_LINES:q=b.LINES;break;case a.DRAW_POINTS:q=b.POINTS;break;case a.DRAW_LINELOOPS:q=b.LINE_LOOP;break;case a.DRAW_LINESTRIPS:q=b.LINE_STRIP;break;default:q=b.TRIANGLES}switch(c){case a.RENDER_DEFAULT:case a.RENDER_EMIT:b.program!=this.GLShaderProgram&&(b.useProgram(this.GLShaderProgram),b.program=this.GLShaderProgram),this.mesh.GLAttributes(b,this.GLShaderProgram,this.meshFrame1,this.meshFrame2);break;case a.RENDER_SHADOW:case a.RENDER_DEPTH:b.program!=this.GLShaderProgramShadow&&(b.useProgram(this.GLShaderProgramShadow,this.meshFrame1,this.meshFrame2),b.program=this.GLShaderProgramShadow),f||(f=b.scene.camera.getFar()),a.setUniform(b,"1f",a.getUniformLocation(b,this.GLShaderProgramShadow,"distance"),f),this.mesh.GLAttributes(b,this.GLShaderProgramShadow,this.meshFrame1,this.meshFrame2);break;case a.RENDER_NORMAL:b.program!=this.GLShaderProgramNormal&&(b.useProgram(this.GLShaderProgramNormal),b.program=this.GLShaderProgramNormal),this.mesh.GLAttributes(b,this.GLShaderProgramNormal,this.meshFrame1,this.meshFrame2);break;case a.RENDER_PICK:b.program!=this.GLShaderProgramPick&&(b.useProgram(this.GLShaderProgramPick),b.program=this.GLShaderProgramPick),this.mesh.GLAttributes(b,this.GLShaderProgramPick,this.meshFrame1,this.meshFrame2),q=b.TRIANGLES}this.GLUniforms(b,c,d);switch(this.mesh.windingOrder){case a.Mesh.WINDING_ORDER_UNKNOWN:b.disable(b.CULL_FACE);break;case a.Mesh.WINDING_ORDER_COUNTER:b.cullFace(b.FRONT);default:}this.mesh.GLfaces?(b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.mesh.GLfaces),b.drawElements(q,this.mesh.GLfaces.numItems,b.UNSIGNED_SHORT,0)):b.drawArrays(q,0,this.mesh.positions.length/3);switch(this.mesh.windingOrder){case a.Mesh.WINDING_ORDER_UNKNOWN:b.scene.renderer.cullFaces&&b.enable(b.CULL_FACE);break;case a.Mesh.WINDING_ORDER_COUNTER:b.cullFace(b.BACK);default:}var r=this.matrix,s=this.caches;this.matrix=r,this.caches=s}}}}}(GLGE),function(a){a.Text=function(b){a.Assets.registerAsset(this,b),this.canvas=document.createElement("canvas"),this.color={r:1,g:1,b:1}},a.augment(a.Placeable,a.Text),a.augment(a.Animatable,a.Text),a.augment(a.QuickNotation,a.Text),a.augment(a.JSONLoader,a.Text),a.Text.prototype.className="Text",a.Text.prototype.zTrans=!0,a.Text.prototype.canvas=null,a.Text.prototype.aspect=1,a.Text.prototype.color=null,a.Text.prototype.text="",a.Text.prototype.font="Times",a.Text.prototype.size=100,a.Text.prototype.pickType=a.TEXT_TEXTPICK,a.Text.prototype.pickable=!0,a.Text.prototype.getPickType=function(){return this.pickType},a.Text.prototype.setPickType=function(a){this.pickType=a;return this},a.Text.prototype.getFont=function(){return this.size},a.Text.prototype.setFont=function(a){this.font=a,this.gl&&this.updateCanvas(this.gl);return this},a.Text.prototype.getSize=function(){return this.size},a.Text.prototype.setSize=function(a){this.size=a,this.gl&&this.updateCanvas(this.gl);return this},a.Text.prototype.getText=function(){return this.text},a.Text.prototype.setText=function(a){this.text=a,this.gl&&this.updateCanvas(this.gl);return this},a.Text.prototype.setColor=function(b){b=a.colorParse(b),this.color={r:b.r,g:b.g,b:b.b};return this},a.Text.prototype.setColorR=function(a){this.color.r=a;return this},a.Text.prototype.setColorG=function(a){this.color.g=a;return this},a.Text.prototype.setColorB=function(a){this.color.b=a;return this},a.Text.prototype.getColor=function(){return this.color},a.Text.prototype.setZtransparent=function(a){this.zTrans=a;return this},a.Text.prototype.isZtransparent=function(){return this.zTrans},a.Text.prototype.GLGenerateShader=function(b){this.GLShaderProgram&&b.deleteProgram(this.GLShaderProgram);var c="";c+="attribute vec3 position;\n",c+="attribute vec2 uvcoord;\n",c+="varying vec2 texcoord;\n",c+="uniform mat4 Matrix;\n",c+="uniform mat4 PMatrix;\n",c+="varying vec4 pos;\n",c+="void main(void){\n",c+="texcoord=uvcoord;\n",c+="pos = Matrix * vec4(position,1.0);\n",c+="gl_Position = PMatrix * pos;\n",c+="}\n";var d="#ifdef GL_ES\nprecision highp float;\n#endif\n";d=d+"uniform sampler2D TEXTURE;\n",d=d+"varying vec2 texcoord;\n",d=d+"varying vec4 pos;\n",d=d+"uniform float far;\n",d=d+"uniform int picktype;\n",d=d+"uniform vec3 pickcolor;\n",d=d+"uniform vec3 color;\n",d=d+"void main(void){\n",d=d+"float alpha=texture2D(TEXTURE,texcoord).a;\n",d=d+"if(picktype=="+a.TEXT_BOXPICK+"){gl_FragColor = vec4(pickcolor,1.0);}",d=d+"else if(picktype=="+a.TEXT_TEXTPICK+"){if(alpha<1.0) discard; gl_FragColor = vec4(pickcolor,alpha);}",d=d+"else{gl_FragColor = vec4(color.rgb*alpha,alpha);};\n",d=d+"}\n",this.GLFragmentShader=b.createShader(b.FRAGMENT_SHADER),this.GLVertexShader=b.createShader(b.VERTEX_SHADER),b.shaderSource(this.GLFragmentShader,d),b.compileShader(this.GLFragmentShader);if(b.getShaderParameter(this.GLFragmentShader,b.COMPILE_STATUS)){b.shaderSource(this.GLVertexShader,c),b.compileShader(this.GLVertexShader);if(!b.getShaderParameter(this.GLVertexShader,b.COMPILE_STATUS)){a.error(b.getShaderInfoLog(this.GLVertexShader));return}this.GLShaderProgram=b.createProgram(),b.attachShader(this.GLShaderProgram,this.GLVertexShader),b.attachShader(this.GLShaderProgram,this.GLFragmentShader),b.linkProgram(this.GLShaderProgram)}else a.error(b.getShaderInfoLog(this.GLFragmentShader))},a.Text.prototype.GLInit=function(a){this.gl=a,this.createPlane(a),this.GLGenerateShader(a),this.glTexture=a.createTexture(),this.updateCanvas(a)},a.Text.prototype.updateCanvas=function(a){var b=this.canvas;b.width=1,b.height=this.size*1.2;var c=b.getContext("2d");c.font=this.size+"px "+this.font,b.width=c.measureText(this.text).width,b.height=this.size*1.2,c=b.getContext("2d"),c.textBaseline="top",c.font=this.size+"px "+this.font,this.aspect=b.width/b.height,c.fillText(this.text,0,0),a.bindTexture(a.TEXTURE_2D,this.glTexture);try{a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,b)}catch(d){a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,b,null)}a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.bindTexture(a.TEXTURE_2D,null)},a.Text.prototype.GLRender=function(b,c,d){this.gl||this.GLInit(b);if(c==a.RENDER_DEFAULT||c==a.RENDER_PICK){this.lookAt&&this.Lookat(this.lookAt),b.program!=this.GLShaderProgram&&(b.useProgram(this.GLShaderProgram),b.program=this.GLShaderProgram);var e;for(var f=0;f<8;f++)b.disableVertexAttribArray(f);e=a.getAttribLocation(b,this.GLShaderProgram,"position"),b.bindBuffer(b.ARRAY_BUFFER,this.posBuffer),b.enableVertexAttribArray(e),b.vertexAttribPointer(e,this.posBuffer.itemSize,b.FLOAT,!1,0,0),e=a.getAttribLocation(b,this.GLShaderProgram,"uvcoord"),b.bindBuffer(b.ARRAY_BUFFER,this.uvBuffer),b.enableVertexAttribArray(e),b.vertexAttribPointer(e,this.uvBuffer.itemSize,b.FLOAT,!1,0,0),b.activeTexture(b.TEXTURE0),b.bindTexture(b.TEXTURE_2D,this.glTexture),a.setUniform(b,"1i",a.getUniformLocation(b,this.GLShaderProgram,"TEXTURE"),0),d||(d=0);var g=d>>16&255,h=d>>8&255,i=d&255;a.setUniform3(b,"3f",a.getUniformLocation(b,this.GLShaderProgram,"pickcolor"),i/255,h/255,g/255),c==a.RENDER_PICK?a.setUniform(b,"1i",a.getUniformLocation(b,this.GLShaderProgram,"picktype"),this.pickType):a.setUniform(b,"1i",a.getUniformLocation(b,this.GLShaderProgram,"picktype"),0),this.GLShaderProgram.glarrays||(this.GLShaderProgram.glarrays={});var j=this.size/100,k=a.mulMat4(b.scene.camera.getViewMatrix(),a.mulMat4(this.getModelMatrix(),a.scaleMatrix(this.aspect*j,j,j))),l=a.getUniformLocation(b,this.GLShaderProgram,"Matrix");this.GLShaderProgram.glarrays.mMatrix?a.mat4gl(k,this.GLShaderProgram.glarrays.mMatrix):this.GLShaderProgram.glarrays.mMatrix=new Float32Array(k),a.setUniformMatrix(b,"Matrix4fv",l,!0,this.GLShaderProgram.glarrays.mMatrix);var l=a.getUniformLocation(b,this.GLShaderProgram,"PMatrix");this.GLShaderProgram.glarrays.pMatrix?a.mat4gl(b.scene.camera.getProjectionMatrix(),this.GLShaderProgram.glarrays.pMatrix):this.GLShaderProgram.glarrays.pMatrix=new Float32Array(b.scene.camera.getProjectionMatrix()),a.setUniformMatrix(b,"Matrix4fv",l,!0,this.GLShaderProgram.glarrays.pMatrix);var m=a.getUniformLocation(b,this.GLShaderProgram,"far");a.setUniform(b,"1f",m,b.scene.camera.getFar()),a.setUniform3(b,"3f",a.getUniformLocation(b,this.GLShaderProgram,"color"),this.color.r,this.color.g,this.color.b),b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.GLfaces),b.drawElements(b.TRIANGLES,this.GLfaces.numItems,b.UNSIGNED_SHORT,0),b.scene.lastMaterial=null}},a.Text.prototype.createPlane=function(a){this.posBuffer||(this.posBuffer=a.createBuffer()),a.bindBuffer(a.ARRAY_BUFFER,this.posBuffer),a.bufferData(a.ARRAY_BUFFER,new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a.STATIC_DRAW),this.posBuffer.itemSize=3,this.posBuffer.numItems=4,this.uvBuffer||(this.uvBuffer=a.createBuffer()),a.bindBuffer(a.ARRAY_BUFFER,this.uvBuffer),a.bufferData(a.ARRAY_BUFFER,new Float32Array([0,0,1,0,1,1,0,1]),a.STATIC_DRAW),this.uvBuffer.itemSize=2,this.uvBuffer.numItems=4,this.GLfaces||(this.GLfaces=a.createBuffer()),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.GLfaces),a.bufferData(a.ELEMENT_ARRAY_BUFFER,new Uint16Array([0,1,2,2,3,0]),a.STATIC_DRAW),this.GLfaces.itemSize=1,this.GLfaces.numItems=6}}(GLGE),function(a){a.Renderer=function(b,c,d){this.viewport=[],this.canvas=b,d||(d={alpha:!0,depth:!0,stencil:!0,antialias:!0,premultipliedAlpha:!0});try{this.gl=b.getContext("experimental-webgl",d)}catch(e){}try{this.gl||(this.gl=b.getContext("webgl",d))}catch(e){}if(!this.gl){console.log("GLGE err:",typeof globalNoWebGLError=="undefined");if(c||typeof globalNoWebGLError!="undefined"){c();throw"cannot create webgl context"}var f=document.createElement("div");f.setAttribute("style","position: absolute; top: 10px; left: 10px; font-family: sans-serif; font-size: 14px; padding: 10px;background-color: #fcffcb;color: #800; width: 200px; border:2px solid #f00"),f.innerHTML="WebGL compatible Browser Required(Firefox 4 or Chrome 9 and up) or you may need to update your graphics card driver.",document.getElementsByTagName("body")[0].appendChild(f);throw"cannot create webgl context"}try{this.gl.canvas=b}catch(e){}this.gl.getProgramParameter||(this.gl.getProgramParameter=this.gl.getProgrami),this.gl.getShaderParameter||(this.gl.getShaderParameter=this.gl.getShaderi),this.gl.uniformMatrix4fvX=this.gl.uniformMatrix4fv,this.gl.uniformMatrix4fv=function(b,c,d){c?(a.mat4gl(a.transposeMat4(d),d),this.uniformMatrix4fvX(b,!1,d)):this.uniformMatrix4fvX(b,!1,d)};var g=this.gl;this.gl.clearDepth(1),this.gl.clearStencil(0),this.gl.enable(this.gl.DEPTH_TEST),this.gl.depthFunc(this.gl.LEQUAL),this.gl.blendFuncSeparate(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA,this.gl.ZERO,this.gl.ONE)},a.augment(a.QuickNotation,a.Renderer),a.Renderer.prototype.gl=null,a.Renderer.prototype.scene=null,a.C_STENCIL=1,a.C_DEPTH=2,a.C_COLOR=4,a.C_ALL=7,a.Renderer.prototype.clearType=a.C_ALL,a.Renderer.prototype.setViewportWidth=function(a){this.viewport[0]=a;return this},a.Renderer.prototype.setViewportHeight=function(a){this.viewport[1]=a;return this},a.Renderer.prototype.setViewportOffsetX=function(a){this.viewport[2]=a;return this},a.Renderer.prototype.setViewportOffsetY=function(a){this.viewport[3]=a;return this},a.Renderer.prototype.clearViewport=function(){this.viewport=[]},a.Renderer.prototype.getViewportWidth=function(){return this.viewport.length>0?this.viewport[0]:this.canvas.width},a.Renderer.prototype.getViewportHeight=function(){return this.viewport.length>0?this.viewport[1]:this.canvas.height},a.Renderer.prototype.getViewportOffsetX=function(){return this.viewport.length>0?this.viewport[2]:0},a.Renderer.prototype.getViewportOffsetY=function(){return this.viewport.length>0?this.viewport[3]:0},a.Renderer.prototype.setClearType=function(a){this.clearType=a;return this},a.Renderer.prototype.getClearType=function(){return this.clearType},a.Renderer.prototype.GLClear=function(){var b=this.gl,c=this.clearType,d=0;c&a.C_COLOR==a.C_COLOR&&(d=d|b.COLOR_BUFFER_BIT),c&a.C_DEPTH==a.C_DEPTH&&(d=d|b.DEPTH_BUFFER_BIT),c&a.C_STENCIL==a.C_STENCIL&&(d=d|b.STENCIL_BUFFER_BIT),b.clear(d)},a.Renderer.prototype.getScene=function(){return this.scene},a.Renderer.prototype.setScene=function(a){a.renderer=this,this.scene=a,a.GLInit(this.gl),this.render(),a.camera.matrix=null;return this},a.Renderer.prototype.render=function(){this.cullFaces&&this.gl.enable(this.gl.CULL_FACE),this.scene&&this.scene.render(this.gl),!this.rendered&&this.scene&&(this.scene.render(this.gl),this.rendered=!0)}}(GLGE),function(a){a.C_PERSPECTIVE=1,a.C_ORTHO=2,a.Camera=function(b){a.Assets.registerAsset(this,b)},a.augment(a.Placeable,a.Camera),a.augment(a.Animatable,a.Camera),a.augment(a.QuickNotation,a.Camera),a.augment(a.JSONLoader,a.Camera),a.Camera.prototype.className="Camera",a.Camera.prototype.fovy=35,a.Camera.prototype.aspect=1,a.Camera.prototype.near=.1,a.Camera.prototype.far=1e3,a.Camera.prototype.orthoscale=5,a.Camera.prototype.type=a.C_PERSPECTIVE,a.Camera.prototype.pMatrix=null,a.Camera.prototype.getOrthoScale=function(){if(this.type==a.C_ORTHO)return this.orthoscale;a.error("You may only get a scale for a orthographic camera");return 1},a.Camera.prototype.setOrthoScale=function(b){this.type==a.C_ORTHO?(this.orthoscale=b,this.pMatrix=null):a.error("You may only set a scale for a orthographic camera");return this},a.Camera.prototype.getFar=function(){return this.far},a.Camera.prototype.setFar=function(a){this.pMatrix=null,this.far=+a;return this},a.Camera.prototype.getNear=function(){return this.near},a.Camera.prototype.setNear=function(a){this.pMatrix=null,this.near=+a;return this},a.Camera.prototype.getType=function(){this.pMatrix=null;return this.type},a.Camera.prototype.setType=function(b){b==a.C_PERSPECTIVE||b==a.C_ORTHO?(this.type=b,this.pMatrix=null):a.error("unsuported camera type");return this},a.Camera.prototype.getFovY=function(){if(this.type==a.C_PERSPECTIVE)return this.fovy;a.error("You may only get a yfov for a perspective camera");return 1},a.Camera.prototype.setFovY=function(b){this.type==a.C_PERSPECTIVE?(this.fovy=+b,this.ymax=null,this.pMatrix=null):a.error("You may only set a yfov for a perspective camera");return this},a.Camera.prototype.getAspect=function(){if(this.type==a.C_PERSPECTIVE||this.type==a.C_ORTHO)return this.aspect;a.error("You may only set a aspect for a perspective or orthographic camera");return 1},a.Camera.prototype.setAspect=function(b){this.type==a.C_PERSPECTIVE||this.type==a.C_ORTHO?(this.aspect=+b,this.pMatrix=null):a.error("You may only set a aspect for a perspective or orthographic camera");return this},a.Camera.prototype.getProjectionMatrix=function(){if(!this.pMatrix)switch(this.type){case a.C_PERSPECTIVE:this.pMatrix=a.makePerspective(this.fovy,this.aspect,this.near,this.far);break;case a.C_ORTHO:this.pMatrix=a.makeOrtho(-this.orthoscale*this.aspect,this.orthoscale*this.aspect,-this.orthoscale,this.orthoscale,this.near,this.far)}return this.pMatrix},a.Camera.prototype.setProjectionMatrix=function(a){this.pMatrix=a;return this},a.Camera.prototype.updateMatrix=function(){var b=this.getPosition(),c=a.translateMatrix(b.x,b.y,b.z);c=a.mulMat4(c,this.getRotMatrix()),this.parent&&(c=a.mulMat4(this.parent.getModelMatrix(),c)),this.location=[c[3],c[7],c[11]],this.matrix=a.inverseMat4(c)},a.Camera.prototype.getViewMatrix=function(){(!this.matrix||!this.rotmatrix)&&this.updateMatrix();return this.matrix},a.Camera.prototype.getViewProjection=function(){var b=this.getProjectionMatrix(),c=this.getViewMatrix();if(b!=this.vpProjectionMatrix||c!=this.vpViewMatrix)this.cameraViewProjection=a.mulMat4(b,c),this.vpProjectionMatrix=b,this.vpViewMatrix=c;return this.cameraViewProjection}}(GLGE),function(a){a.Light=function(b){a.Assets.registerAsset(this,b),this.color={r:1,g:1,b:1}},a.augment(a.Placeable,a.Light),a.augment(a.Animatable,a.Light),a.augment(a.QuickNotation,a.Light),a.augment(a.JSONLoader,a.Light),a.Light.prototype.className="Light",a.L_POINT=1,a.L_DIR=2,a.L_SPOT=3,a.L_OFF=4,a.Light.prototype.constantAttenuation=1,a.Light.prototype.linearAttenuation=.002,a.Light.prototype.quadraticAttenuation=8e-4,a.Light.prototype.spotCosCutOff=.95,a.Light.prototype.spotPMatrix=null,a.Light.prototype.spotExponent=10,a.Light.prototype.color=null,a.Light.prototype.diffuse=!0,a.Light.prototype.specular=!0,a.Light.prototype.samples=0,a.Light.prototype.softness=.01,a.Light.prototype.type=a.L_POINT,a.Light.prototype.frameBuffer=null,a.Light.prototype.renderBuffer=null,a.Light.prototype.texture=null,a.Light.prototype.bufferHeight=256,a.Light.prototype.bufferWidth=256,a.Light.prototype.shadowBias=.002,a.Light.prototype.castShadows=!1,a.Light.prototype.cascadeLevels=3,a.Light.prototype.distance=500,a.Light.prototype.getCascadeLevels=function(){return this.cascadeLevels},a.Light.prototype.setCascadeLevels=function(a){this.cascadeLevels=+a,this.fireEvent("shaderupdate",{});return this},a.Light.prototype.getPMatrix=function(b,c,d,e){if(!this.spotPMatrix){var f;this.scene&&this.scene.camera?f=this.scene.camera.far:f=1e3,this.type==a.L_SPOT&&(this.spotPMatrix=a.makePerspective(Math.acos(this.spotCosCutOff)/3.14159*360,1,.1,f))}this.type==a.L_DIR&&(this.spotPMatrix=a.getDirLightProjection(b,c,d,e));return this.spotPMatrix},a.Light.prototype.setDistance=function(a){this.distance=a,this.fireEvent("shaderupdate",{});return this},a.Light.prototype.getDistance=function(){return this.distance},a.Light.prototype.setNegativeShadow=function(a){this.negativeShadow=a,this.fireEvent("shaderupdate",{});return this},a.Light.prototype.getNegative=function(){return this.negativeShadow},a.Light.prototype.setCastShadows=function(a){this.castShadows=a,this.fireEvent("shaderupdate",{});return this},a.Light.prototype.getCastShadows=function(){return this.castShadows},a.Light.prototype.setShadowBias=function(a){this.shadowBias=a;return this},a.Light.prototype.getShadowBias=function(){return this.shadowBias},a.Light.prototype.setShadowSamples=function(a){this.samples=a,this.fireEvent("shaderupdate",{});return this},a.Light.prototype.getShadowSamples=function(){return this.samples},a.Light.prototype.setShadowSoftness=function(a){this.softness=a,this.fireEvent("shaderupdate",{});return this},a.Light.prototype.getShadowSamples=function(){return this.softness},a.Light.prototype.setBufferWidth=function(a){this.bufferWidth=a;return this},a.Light.prototype.getBufferHeight=function(){return this.bufferHeight},a.Light.prototype.setBufferHeight=function(a){this.bufferHeight=a;return this},a.Light.prototype.getBufferWidth=function(){return this.bufferWidth},a.Light.prototype.setSpotCosCutOff=function(a){this.spotPMatrix=null,this.spotCosCutOff=a;return this},a.Light.prototype.getSpotCosCutOff=function(){return this.spotCosCutOff},a.Light.prototype.setSpotExponent=function(a){this.spotExponent=a;return this},a.Light.prototype.getSpotExponent=function(){return this.spotExponent},a.Light.prototype.getAttenuation=function(a,b,c){var d={};d.constant=this.constantAttenuation,d.linear=this.linearAttenuation,d.quadratic=this.quadraticAttenuation;return d},a.Light.prototype.setAttenuation=function(a,b,c){this.constantAttenuation=a,this.linearAttenuation=b,this.quadraticAttenuation=c;return this},a.Light.prototype.setAttenuationConstant=function(a){this.constantAttenuation=a;return this},a.Light.prototype.setAttenuationLinear=function(a){this.linearAttenuation=a;return this},a.Light.prototype.setAttenuationQuadratic=function(a){this.quadraticAttenuation=a;return this},a.Light.prototype.setColor=function(b){b=a.colorParse(b),this.color={r:b.r,g:b.g,b:b.b};return this},a.Light.prototype.setColorR=function(a){this.color.r=a;return this},a.Light.prototype.setColorG=function(a){this.color.g=a;return this},a.Light.prototype.setColorB=function(a){this.color.b=a;return this},a.Light.prototype.getColor=function(){return this.color},a.Light.prototype.getType=function(){return this.type},a.Light.prototype.setType=function(a){this.type=a,this.fireEvent("shaderupdate",{});return this},a.Light.prototype.enableLight=function(){this.type==a.L_OFF&&this.old_type!==undefined&&(this.setType(this.old_type),delete this.old_type)},a.Light.prototype.disableLight=function(){this.type!=a.L_OFF&&(this.old_type=this.type,this.setType(a.L_OFF))},a.Light.prototype.GLInit=function(b){this.gl=b,(this.type==a.L_SPOT||this.type==a.L_DIR)&&!this.texture&&this.createSpotBuffer(b)},a.Light.prototype.createSpotBuffer=function(b){this.frameBuffer=b.createFramebuffer(),this.renderBuffer=b.createRenderbuffer(),this.texture=b.createTexture(),b.bindTexture(b.TEXTURE_2D,this.texture);try{b.texImage2D(b.TEXTURE_2D,0,b.RGBA,this.bufferWidth,this.bufferHeight,0,b.RGBA,b.UNSIGNED_BYTE,null)}catch(c){a.error("incompatible texture creation method");var d=parseFloat(this.bufferWidth),e=parseFloat(this.bufferHeight),f=new Uint8Array(d*e*4);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,d,e,0,b.RGBA,b.UNSIGNED_BYTE,f)}b.bindFramebuffer(b.FRAMEBUFFER,this.frameBuffer),b.bindRenderbuffer(b.RENDERBUFFER,this.renderBuffer),b.renderbufferStorage(b.RENDERBUFFER,b.DEPTH_COMPONENT16,this.bufferWidth,this.bufferHeight),b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,this.texture,0),b.framebufferRenderbuffer(b.FRAMEBUFFER,b.DEPTH_ATTACHMENT,b.RENDERBUFFER,this.renderBuffer),b.bindFramebuffer(b.FRAMEBUFFER,null),b.bindRenderbuffer(b.RENDERBUFFER,null),b.bindTexture(b.TEXTURE_2D,null)}}(GLGE),function(a){a.FOG_NONE=1,a.FOG_LINEAR=2,a.FOG_QUADRATIC=3,a.FOG_SKYLINEAR=4,a.FOG_SKYQUADRATIC=5,a.Scene=function(b){a.Assets.registerAsset(this,b),a.Group.call(this),this.children=[],this.camera=new a.Camera,this.backgroundColor={r:1,g:1,b:1,a:1},this.ambientColor={r:0,g:0,b:0},this.fogColor={r:.5,g:.5,b:.5},this.passes=[]},a.augment(a.Group,a.Scene),a.Scene.prototype.camera=null,a.Scene.prototype.className="Scene",a.Scene.prototype.renderer=null,a.Scene.prototype.backgroundColor=null,a.Scene.prototype.filter=null,a.Scene.prototype.fogColor=null,a.Scene.prototype.ambientColor=null,a.Scene.prototype.fogNear=10,a.Scene.prototype.fogFar=80,a.Scene.prototype.fogType=a.FOG_NONE,a.Scene.prototype.passes=null,a.Scene.prototype.culling=!0,a.Scene.prototype.getFogType=function(){return this.fogType},a.Scene.prototype.setFogType=function(a){this.fogType=a;return this},a.Scene.prototype.getFogFar=function(){return this.fogFar},a.Scene.prototype.setFogFar=function(a){this.fogFar=a;return this},a.Scene.prototype.getFogNear=function(){return this.fogNear},a.Scene.prototype.setFogNear=function(a){this.fogNear=a;return this},a.Scene.prototype.getFogColor=function(){return this.fogColor},a.Scene.prototype.setFogColor=function(b){b=a.colorParse(b),this.fogColor={r:b.r,g:b.g,b:b.b};return this},a.Scene.prototype.getBackgroundColor=function(){return this.backgroundColor},a.Scene.prototype.setBackgroundColor=function(b){b=a.colorParse(b),this.backgroundColor={r:b.r,g:b.g,b:b.b,a:b.a};return this},a.Scene.prototype.getAmbientColor=function(){return this.ambientColor},a.Scene.prototype.setAmbientColor=function(b){b=a.colorParse(b),this.ambientColor={r:b.r,g:b.g,b:b.b},this.renderer&&this.renderer.gl.clearColor(this.backgroundColor.r,this.backgroundColor.g,this.backgroundColor.b,1);return this},a.Scene.prototype.setAmbientColorR=function(a){this.ambientColor.r=a;return this},a.Scene.prototype.setAmbientColorG=function(a){this.ambientColor.g=a;return this},a.Scene.prototype.setAmbientColorB=function(a){this.ambientColor.b=a;return this},a.Scene.prototype.setCamera=function(b){typeof b=="string"&&(b=a.Assets.get(b)),this.camera=b;return this},a.Scene.prototype.getCamera=function(){return this.camera},a.Scene.prototype.setCull=function(a){this.culling=a;return this},a.Scene.prototype.getCull=function(){return this.culling},a.Scene.prototype.GLInit=function(a){this.gl=a,a.lights=this.getLights(),this.camera.setAspect(this.renderer.canvas.width/this.renderer.canvas.height),this.renderer.gl.clearColor(this.backgroundColor.r,this.backgroundColor.g,this.backgroundColor.b,1);for(var b=0;bd)return 1;if(cd)return 1;if(cd?1:c0){var r=this.passes.pop();b.bindFramebuffer(b.FRAMEBUFFER,r.frameBuffer),this.camera.matrix=r.cameraMatrix,this.camera.setProjectionMatrix(r.projectionMatrix),this.renderPass(b,d,0,0,r.width,r.height,a.RENDER_DEFAULT,r.self)}this.camera.matrix=g,this.camera.setProjectionMatrix(h),b.bindFramebuffer(b.FRAMEBUFFER,this.framebuffer),this.renderPass(b,d,this.renderer.getViewportOffsetX(),this.renderer.getViewportOffsetY(),this.renderer.getViewportWidth(),this.renderer.getViewportHeight()),this.applyFilter(b,d,null),this.allowPasses=!0},a.Scene.prototype.getPasses=function(b,c){for(var d=0;dsizeTimeLife[2] && (time-sizeTimeLife[2])-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.attribute.initPosGL),b.enableVertexAttribArray(d),b.vertexAttribPointer(d,3,b.FLOAT,!1,0,0));var d=a.getAttribLocation(b,this.program,"initAcc");d>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.attribute.initAccGL),b.enableVertexAttribArray(d),b.vertexAttribPointer(d,3,b.FLOAT,!1,0,0));var d=a.getAttribLocation(b,this.program,"endAcc");d>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.attribute.endAccGL),b.enableVertexAttribArray(d),b.vertexAttribPointer(d,3,b.FLOAT,!1,0,0));var d=a.getAttribLocation(b,this.program,"initColor");d>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.attribute.initColorGL),b.enableVertexAttribArray(d),b.vertexAttribPointer(d,4,b.FLOAT,!1,0,0));var d=a.getAttribLocation(b,this.program,"endColor");d>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.attribute.endColorGL),b.enableVertexAttribArray(d),b.vertexAttribPointer(d,4,b.FLOAT,!1,0,0));var d=a.getAttribLocation(b,this.program,"sizeTimeLife");d>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.attribute.sizeAndOffsetGL),b.enableVertexAttribArray(d),b.vertexAttribPointer(d,4,b.FLOAT,!1,0,0));var d=a.getAttribLocation(b,this.program,"initVel");d>-1&&(b.bindBuffer(b.ARRAY_BUFFER,this.attribute.initVelGL),b.enableVertexAttribArray(d),b.vertexAttribPointer(d,3,b.FLOAT,!1,0,0))},a.ParticleSystem.prototype.GLRender=function(a){this.attribute||this.generateParticles(a),this.program||this.generateProgram(a),a.useProgram(this.program),this.setAttributes(a),this.setUniforms(a),a.colorMask(0,0,0,0),a.disable(a.BLEND),a.enable(a.STENCIL_TEST),a.stencilFunc(a.ALWAYS,1,1),a.stencilOp(a.KEEP,a.KEEP,a.REPLACE),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.facesGL),a.drawElements(a.TRIANGLES,this.facesGL.num,a.UNSIGNED_SHORT,0),a.stencilFunc(a.EQUAL,1,1),a.stencilOp(a.KEEP,a.KEEP,a.KEEP),a.colorMask(1,1,1,1),a.disable(a.DEPTH_TEST),a.enable(a.BLEND),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.facesGL),a.drawElements(a.TRIANGLES,this.facesGL.num,a.UNSIGNED_SHORT,0),a.stencilOp(a.REPLACE,a.REPLACE,a.REPLACE),a.stencilFunc(a.ALWAYS,0,0),a.enable(a.DEPTH_TEST),a.scene.lastMaterial=null},a.Scene.prototype.addParticleSystem=a.Scene.prototype.addGroup,a.Group.prototype.addParticleSystem=a.Group.prototype.addGroup}(GLGE),function(a){a.MD2=function(b){this.MD2Started=+(new Date),this.setAnimation(new a.AnimationVector),a.Object.call(this,b)},a.augment(a.Object,a.MD2),a.MD2.prototype.loadingCache={},a.MD2.prototype.headersCache={},a.MD2.prototype.meshCache={},a.MD2.prototype.MD2Animations={},a.MD2.prototype.MD2StartFrame=0,a.MD2.prototype.MD2EndFrame=0,a.MD2.prototype.MD2Loop=!0,a.MD2.prototype.headerNames=["ident","version","skinwidth","skinheight","framesize","num_skins","num_xyz","num_st","num_tris","num_glcmds","num_frames","ofs_skins","ofs_st","ofs_tris","ofs_frames","ofs_glcmds","ofs_end"],a.MD2.prototype.preNormals=[[-.525731,0,.850651],[-.442863,.238856,.864188],[-.295242,0,.955423],[-.309017,.5,.809017],[-.16246,.262866,.951056],[0,0,1],[0,.850651,.525731],[-.147621,.716567,.681718],[.147621,.716567,.681718],[0,.525731,.850651],[.309017,.5,.809017],[.525731,0,.850651],[.295242,0,.955423],[.442863,.238856,.864188],[.16246,.262866,.951056],[-.681718,.147621,.716567],[-.809017,.309017,.5],[-.587785,.425325,.688191],[-.850651,.525731,0],[-.864188,.442863,.238856],[-.716567,.681718,.147621],[-.688191,.587785,.425325],[-.5,.809017,.309017],[-.238856,.864188,.442863],[-.425325,.688191,.587785],[-.716567,.681718,-.147621],[-.5,.809017,-.309017],[-.525731,.850651,0],[0,.850651,-.525731],[-.238856,.864188,-.442863],[0,.955423,-.295242],[-.262866,.951056,-.16246],[0,1,0],[0,.955423,.295242],[-.262866,.951056,.16246],[.238856,.864188,.442863],[.262866,.951056,.16246],[.5,.809017,.309017],[.238856,.864188,-.442863],[.262866,.951056,-.16246],[.5,.809017,-.309017],[.850651,.525731,0],[.716567,.681718,.147621],[.716567,.681718,-.147621],[.525731,.850651,0],[.425325,.688191,.587785],[.864188,.442863,.238856],[.688191,.587785,.425325],[.809017,.309017,.5],[.681718,.147621,.716567],[.587785,.425325,.688191],[.955423,.295242,0],[1,0,0],[.951056,.16246,.262866],[.850651,-.525731,0],[.955423,-.295242,0],[.864188,-.442863,.238856],[.951056,-.16246,.262866],[.809017,-.309017,.5],[.681718,-.147621,.716567],[.850651,0,.525731],[.864188,.442863,-.238856],[.809017,.309017,-.5],[.951056,.16246,-.262866],[.525731,0,-.850651],[.681718,.147621,-.716567],[.681718,-.147621,-.716567],[.850651,0,-.525731],[.809017,-.309017,-.5],[.864188,-.442863,-.238856],[.951056,-.16246,-.262866],[.147621,.716567,-.681718],[.309017,.5,-.809017],[.425325,.688191,-.587785],[.442863,.238856,-.864188],[.587785,.425325,-.688191],[.688191,.587785,-.425325],[-.147621,.716567,-.681718],[-.309017,.5,-.809017],[0,.525731,-.850651],[-.525731,0,-.850651],[-.442863,.238856,-.864188],[-.295242,0,-.955423],[-.16246,.262866,-.951056],[0,0,-1],[.295242,0,-.955423],[.16246,.262866,-.951056],[-.442863,-.238856,-.864188],[-.309017,-.5,-.809017],[-.16246,-.262866,-.951056],[0,-.850651,-.525731],[-.147621,-.716567,-.681718],[.147621,-.716567,-.681718],[0,-.525731,-.850651],[.309017,-.5,-.809017],[.442863,-.238856,-.864188],[.16246,-.262866,-.951056],[.238856,-.864188,-.442863],[.5,-.809017,-.309017],[.425325,-.688191,-.587785],[.716567,-.681718,-.147621],[.688191,-.587785,-.425325],[.587785,-.425325,-.688191],[0,-.955423,-.295242],[0,-1,0],[.262866,-.951056,-.16246],[0,-.850651,.525731],[0,-.955423,.295242],[.238856,-.864188,.442863],[.262866,-.951056,.16246],[.5,-.809017,.309017],[.716567,-.681718,.147621],[.525731,-.850651,0],[-.238856,-.864188,-.442863],[-.5,-.809017,-.309017],[-.262866,-.951056,-.16246],[-.850651,-.525731,0],[-.716567,-.681718,-.147621],[-.716567,-.681718,.147621],[-.525731,-.850651,0],[-.5,-.809017,.309017],[-.238856,-.864188,.442863],[-.262866,-.951056,.16246],[-.864188,-.442863,.238856],[-.809017,-.309017,.5],[-.688191,-.587785,.425325],[-.681718,-.147621,.716567],[-.442863,-.238856,.864188],[-.587785,-.425325,.688191],[-.309017,-.5,.809017],[-.147621,-.716567,.681718],[-.425325,-.688191,.587785],[-.16246,-.262866,.951056],[.442863,-.238856,.864188],[.16246,-.262866,.951056],[.309017,-.5,.809017],[.147621,-.716567,.681718],[0,-.525731,.850651],[.425325,-.688191,.587785],[.587785,-.425325,.688191],[.688191,-.587785,.425325],[-.955423,.295242,0],[-.951056,.16246,.262866],[-1,0,0],[-.850651,0,.525731],[-.955423,-.295242,0],[-.951056,-.16246,.262866],[-.864188,.442863,-.238856],[-.951056,.16246,-.262866],[-.809017,.309017,-.5],[-.864188,-.442863,-.238856],[-.951056,-.16246,-.262866],[-.809017,-.309017,-.5],[-.681718,.147621,-.716567],[-.681718,-.147621,-.716567],[-.850651,0,-.525731],[-.688191,.587785,-.425325],[-.587785,.425325,-.688191],[-.425325,.688191,-.587785],[-.425325,-.688191,-.587785],[-.587785,-.425325,-.688191],[-.688191,-.587785,-.425325]],a.MD2.prototype.MD2FrameRate=6,a.MD2.prototype.getAbsolutePath=function(a,b){if(a.substr(0,7)=="http://"||a.substr(0,7)=="file://"||a.substr(0,7)=="https://")return a;b||(b=window.location.href);if(b.indexOf("://")==-1)return b.slice(0,b.lastIndexOf("/"))+"/"+a;var c=b.split("/"),d=c[2],e=c[0],f=[];for(var g=3;g>7),exponent=(e<<1&255|d>>7)-127,mantissa=(d&127)<<16|c<<8|b;if(mantissa==0&&exponent==-127)return 0;if(exponent==-127)return sign*mantissa*Math.pow(2,-126-23);return sign*(1+mantissa*Math.pow(2,-23))*Math.pow(2,exponent)},a.MD2.prototype.parseFrames=function(){var a=this.byteArray,b=0,c={};for(var d=0;d-1&&this.textures.splice(b,1)},a.Filter2d.prototype.createBuffer=function(a,b,c){b||(b=a.canvas.width),c||(c=a.canvas.height);var d=a.createFramebuffer(),e=a.createRenderbuffer(),f=a.createTexture();a.bindTexture(a.TEXTURE_2D,f);var g=new Uint8Array(b*c*4);a.texImage2D(a.TEXTURE_2D,0,a.RGBA,b,c,0,a.RGBA,a.UNSIGNED_BYTE,g),a.bindFramebuffer(a.FRAMEBUFFER,d),a.bindRenderbuffer(a.RENDERBUFFER,e),a.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,b,c),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,e),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,f,0),a.bindRenderbuffer(a.RENDERBUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_2D,null);return[d,e,f]},a.Filter2d.prototype.getFrameBuffer=function(a){if(!this.passes)return null;this.gl||(this.gl=a),this.buffers||(this.buffers=this.createBuffer(a));return this.buffers[0]},a.Filter2d.prototype.getEmitBuffer=function(a){if(!this.passes)return null;this.gl||(this.gl=a),this.emitBuffers||(this.emitBuffers=this.createBuffer(a,this.getEmitBufferWidth(),this.getEmitBufferHeight()));return this.emitBuffers[0]},a.Filter2d.prototype.setEmitBufferWidth=function(a){this.emitBufferWidth=a,this.emitBuffers=null},a.Filter2d.prototype.getEmitBufferWidth=function(){return this.emitBufferWidth?this.emitBufferWidth:this.gl.canvas.width},a.Filter2d.prototype.setEmitBufferHeight=function(a){this.emitBufferHeight=a,this.emitBuffers=null},a.Filter2d.prototype.getEmitBufferHeight=function(){return this.emitBufferHeight?this.emitBufferHeight:this.gl.canvas.height},a.Filter2d.prototype.getDepthBuffer=function(a){if(!this.passes)return null;this.gl||(this.gl=a),this.depthBuffers||(this.depthBuffers=this.createBuffer(a,this.getDepthBufferWidth(),this.getDepthBufferHeight()));return this.depthBuffers[0]},a.Filter2d.prototype.setDepthBufferWidth=function(a){this.depthBufferWidth=a,this.depthBuffers=null},a.Filter2d.prototype.getDepthBufferWidth=function(){return this.depthBufferWidth?this.depthBufferWidth:this.gl.canvas.width},a.Filter2d.prototype.setDepthBufferHeight=function(a){this.depthBufferHeight=a,this.depthBuffers=null},a.Filter2d.prototype.getDepthBufferHeight=function(){return this.depthBufferHeight?this.depthBufferHeight:this.gl.canvas.height},a.Filter2d.prototype.setNormalBufferWidth=function(a){this.normalBufferWidth=a,this.normalBuffers=null},a.Filter2d.prototype.getNormalBufferWidth=function(){return this.normalBufferWidth?this.normalBufferWidth:this.gl.canvas.width},a.Filter2d.prototype.setNormalBufferHeight=function(a){this.normalBufferHeight=a,this.normalBuffers=null},a.Filter2d.prototype.getNormalBufferHeight=function(){return this.normalBufferHeight?this.normalBufferHeight:this.gl.canvas.height},a.Filter2d.prototype.getNormalBuffer=function(a){this.gl||(this.gl=a),this.normalBuffers||(this.normalBuffers=this.createBuffer(a,this.getNormalBufferWidth(),this.getNormalBufferHeight()));return this.normalBuffers[0]},a.Filter2d.prototype.setUniform=function(a,b,c){this.uniforms||(this.uniforms={}),this.uniforms[b]={type:a,value:c}},a.Filter2d.prototype.getUniform=function(a){this.uniforms||(this.uniforms={});return this.uniforms[a].value},a.Filter2d.prototype.getUniformType=function(a){this.uniforms||(this.uniforms={});return this.uniforms[a].type},a.Filter2d.prototype.addPassFile=function(a){var b=new XMLHttpRequest,c=this;b&&(b.open("GET",a,!1),b.send(""),c.addPass(b.responseText))},a.Filter2d.prototype.addPass=function(a,b,c){this.passes||(this.passes=[]),this.passes.push({GLSL:a,height:c,width:b})},a.Filter2d.prototype.createPersistTexture=function(a){this.persistTexture=a.createTexture(),a.bindTexture(a.TEXTURE_2D,this.persistTexture),a.texImage2D(a.TEXTURE_2D,0,a.RGB,a.canvas.width,a.canvas.height,0,a.RGB,a.UNSIGNED_BYTE,null)},a.Filter2d.prototype.GLRender=function(b,c){b.disable(b.BLEND),c||(c=null);if(this.passes){for(var d=0;d0&&(y[e].getElementsByTagName("p")[0].data=w)}var B=[],w=meshNode.getElementsByTagName("triangles");for(e=0;e0&&B.push(y[e]);for(e=0;eb?b:a}var L=21843;L*=3;var M=(m.length-m.length%L)/L+(m.length%L?1:0),N=[],O=3,P=3,Q=2;for(var R=0;R8){var S=[],T=[];for(var U=0;U0){m=o[0].firstChild;do switch(m.tagName){case"color":n=m.firstChild.nodeValue.replace(/\s+/g," ").split(" "),h.setAmbient({r:n[0],g:n[1],b:n[2]});break;case"param":n=this.getFloat4(k,m.getAttribute("ref")).replace(/\s+/g," ").split(" "),h.setAmbient({r:n[0],g:n[1],b:n[2]});break;case"texture":this.createMaterialLayer(m,h,k,a.M_AMBIENT,e)}while(m=m.nextSibling)}var p=l.getElementsByTagName("diffuse");if(p.length>0){m=p[0].firstChild;do switch(m.tagName){case"color":n=m.firstChild.nodeValue.replace(/\s+/g," ").split(" "),h.setColor({r:n[0],g:n[1],b:n[2]});break;case"param":n=this.getFloat4(k,m.getAttribute("ref")).replace(/\s+/g," ").split(" "),h.setColor({r:n[0],g:n[1],b:n[2]});break;case"texture":this.createMaterialLayer(m,h,k,a.M_COLOR,e)}while(m=m.nextSibling)}var q=l.getElementsByTagName("bump");if(q.length>0){m=q[0].firstChild;do switch(m.tagName){case"texture":this.createMaterialLayer(m,h,k,a.M_NOR,e)}while(m=m.nextSibling)}var r=l.getElementsByTagName("shininess");if(r.length>0){h.setSpecular(1),m=l.getElementsByTagName("shininess")[0].firstChild;do switch(m.tagName){case"float":parseFloat(m.firstChild.nodeValue)>1?h.setShininess(parseFloat(m.firstChild.nodeValue)):h.setShininess(parseFloat(m.firstChild.nodeValue)*128);break;case"param":var s=parseFloat(this.getFloat(k,m.getAttribute("ref")));s>1?h.setShininess(s):h.setShininess(s*128);break;case"texture":this.createMaterialLayer(m,h,k,a.M_SHINE,e)}while(m=m.nextSibling)}var t=l.getElementsByTagName("specular");if(t.length>0){h.setSpecular(1),m=t[0].firstChild;do switch(m.tagName){case"color":n=m.firstChild.nodeValue.replace(/\s+/g," ").split(" "),h.setSpecularColor({r:n[0],g:n[1],b:n[2]});break;case"param":n=this.getFloat4(k,m.getAttribute("ref")).replace(/\s+/g," ").split(" "),h.setSpecularColor({r:n[0],g:n[1],b:n[2]});break;case"texture":this.createMaterialLayer(m,h,k,a.M_SPECCOLOR,e)}while(m=m.nextSibling)}var u=l.getElementsByTagName("emission");if(u.length>0){m=u[0].firstChild;do switch(m.tagName){case"color":n=m.firstChild.nodeValue.split(" "),h.setEmit({r:n[0],g:n[1],b:n[2]});break;case"param":n=this.getFloat4(k,m.getAttribute("ref")).split(" "),h.setEmit(n[0]);break;case"texture":this.createMaterialLayer(m,h,k,a.M_EMIT,e)}while(m=m.nextSibling)}var v=l.getElementsByTagName("reflective");if(v.length>0){m=v[0].firstChild;do switch(m.tagName){case"color":n=m.firstChild.nodeValue.replace(/\s+/g," ").split(" ");break;case"param":n=this.getFloat4(k,m.getAttribute("ref")).replace(/\s+/g," ").split(" ");break;case"texture":this.createMaterialLayer(m,h,k,a.M_REFLECT,e)}while(m=m.nextSibling)}var w=l.getElementsByTagName("transparency");if(w.length>0){m=w[0].firstChild;do switch(m.tagName){case"float":break;case"param":}while(m=m.nextSibling)}var x=l.getElementsByTagName("transparent");if(x.length>0){var y=x[0].getAttribute("opaque");y||(y="A_ONE"),m=x[0].firstChild;do switch(m.tagName){case"float":var z=parseFloat(m.firstChild.nodeValue);z<1&&(h.setAlpha(parseFloat(m.firstChild.nodeValue)),h.trans=!0);break;case"color":n=m.firstChild.nodeValue.replace(/\s+/g," ").split(" ");var z=this.getMaterialAlpha(n,y,1);z<1&&(h.setAlpha(z),h.trans=!0);break;case"param":n=this.getFloat4(k,m.getAttribute("ref")).replace(/\s+/g," ").split(" ");var z=this.getMaterialAlpha(n,y,1);z<1&&(h.setAlpha(z),h.trans=!0);break;case"texture":this.createMaterialLayer(m,h,k,a.M_ALPHA,e),h.trans=!0}while(m=m.nextSibling)}return h},a.Collada.prototype.getMaterialAlpha=function(a,b,c){var d;switch(b){case"A_ONE":d=parseFloat(a[3])*c;break;case"A_ZERO":d=1-parseFloat(a[3])*c;break;case"RGB_ONE":var e=parseFloat(a[0])*.212671+parseFloat(a[1])*.71516+parseFloat(a[2])*.072169;d=e*c;break;case"RGB_ZERO":var e=parseFloat(a[0])*.212671+parseFloat(a[1])*.71516+parseFloat(a[2])*.072169;d=1-e*c}return d},a.Collada.prototype.setMaterialOntoMesh=function(b,c){var d=c.getElementsByTagName("instance_material"),e={};for(var f=0;f=0;--c)a[c]>="0"&&a[c]<="9"&&(b=a[c]+b);if(b.length==0)return"0";return b}h[g[i].getAttribute("semantic")]=j(g[i].getAttribute("semantic"))}mat=this.getMaterial(d[f].getAttribute("target").substr(1),h),e[d[f].getAttribute("symbol")]=mat}var k=new a.Object;for(f=0;f1?m=parseInt(m[0])+4*parseInt(m[1]):m=parseInt(m[0]),g[sidtarget].animations[m]=k[0]}else for(var n=0;n0?h=this.parseArray(d.getElementsByTagName("bind_shape_matrix")[0]):h=a.identMatrix();var i=[h],j=new a.Group;this.addGroup(j);var f=[j],k;for(var l=0;l0){var f=e[0].firstChild.nodeValue.split(" "),g="rgb("+(f[0]*255|0)+","+(f[1]*255|0)+","+(f[2]*255|0)+")";d.setColor(g)}switch(c.tagName){case"point":d.setType(a.L_POINT);case"spot":var h=c.getElementsByTagName("constant_attenuation");h.length>0&&d.setAttenuationConstant(parseFloat(h[0].firstChild.nodeValue));var i=c.getElementsByTagName("linear_attenuation");i.length>0&&d.setAttenuationLinear(parseFloat(i[0].firstChild.nodeValue));var j=c.getElementsByTagName("quadratic_attenuation");j.length>0&&d.setAttenuationQuadratic(parseFloat(j[0].firstChild.nodeValue));if(c.tagName=="spot")d.setType(a.L_SPOT);else break;var k=c.getElementsByTagName("falloff_exponent");if(k.length>0){var l=parseFloat(k[0].firstChild.nodeValue);l<1.0001&&(l*=128),d.setSpotExponent(l)}var m=c.getElementsByTagName("falloff_angle");m.length>0&&d.setSpotCosCutOff(Math.cos(parseFloat(m[0].firstChild.nodeValue)/180*Math.PI))}return d},a.Collada.prototype.addColladaCamera=function(a){a.matrix=null,a.parent=this,this.children.push(a),this.hasCamera=!0;return this},a.Collada.prototype.getNode=function(b,c){if(!c&&b.GLGEObject){d=b.GLGEObject,delete this.GLGEObject;return d}if(c&&b&&b.GLGEObjects)return b.GLGEObjects[0];var d=new a.Group,e="bone"+ ++this.boneIdx;d.setName(e);if(!b)return d;b.GLGEObjects||(b.GLGEObjects=[]),b.GLGEObjects.push(d);var f=b.firstChild,g=a.identMatrix(),h;if(f)do switch(f.tagName){case"node":d.addGroup(this.getNode(f));break;case"instance_node":d.addGroup(this.getNode(this.xml.getElementById(f.getAttribute("url").substr(1))));break;case"instance_visual_scene":d.addGroup(this.getNode(this.xml.getElementById(f.getAttribute("url").substr(1))));break;case"instance_light":this.useLights&&d.addLight(this.getInstanceLight(this.xml.getElementById(f.getAttribute("url").substr(1))));break;case"instance_geometry":d.addObject(this.getInstanceGeometry(f));break;case"instance_controller":d.addObject(this.getInstanceController(f));break;case"instance_camera":if(!this.useCamera)break;d.addColladaCamera(this.getNode(this.xml.getElementById(f.getAttribute("url").substr(1))));break;case"optics":if(!this.useCamera)break;var i=f.getElementsByTagName("technique_common");if(i&&i.length>0){i=i[0].getElementsByTagName("perspective");if(i&&i.length>0){var j=i[0].getElementsByTagName("yfov");j&&j.length>0&&(d.yFov=parseFloat(j[0].textContent));var k=i[0].getElementsByTagName("znear");k&&k.length>0&&(d.zNear=parseFloat(k[0].textContent));var l=i[0].getElementsByTagName("zfar");l&&l.length>0&&(d.zFar=parseFloat(l[0].textContent))}}break;case"matrix":g=this.parseArray(f);break;case"translate":h=this.parseArray(f),g=a.mulMat4(g,a.translateMatrix(h[0],h[1],h[2]));break;case"rotate":h=this.parseArray(f),g=a.mulMat4(g,a.angleAxis(h[3]*.017453278,[h[0],h[1],h[2]]));break;case"scale":h=this.parseArray(f),g=a.mulMat4(g,a.scaleMatrix(h[0],h[1],h[2]))}while(f=f.nextSibling);d.setLoc(g[3],g[7],g[11]);var m=a.Mat4([g[0],g[1],g[2],0,g[4],g[5],g[6],0,g[8],g[9],g[10],0,0,0,0,1]);d.setRotMatrix(m),c&&(b.GLGEObject=d);return d},a.Collada.prototype.initVisualScene=function(){var b=this.xml.getElementsByTagName("asset"),c="Z_UP";if(b.length){var d=b[0].getElementsByTagName("up_axis");if(d.length){d=d[0];var e=d.firstChild.nodeValue;e.length&&(c=e)}}var f=this;c[0]!="Y"&&c[0]!="y"&&(f=new a.Group,this.addChild(f),c[0]!="Z"&&c[0]!="z"?this.setRotMatrix(a.Mat4([0,-1,0,0,1,0,0,0,0,0,1,0,0,0,0,1])):this.setRotMatrix(a.Mat4([1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1])));if(this.rootId){var h=this.xml.getElementById(this.rootId);h?f.addGroup(this.getNode(h)):a.error("Asset "+this.rootId+" not found in document"+this.url)}else{var g=this.xml.getElementsByTagName("scene");g.length>0?f.addGroup(this.getNode(g[0])):a.error("Please indicate the asset to render in Collada Document"+this.url)}if(this.useCamera){var i,j=function(a){if(a.hasCamera)i=a;else{if(!a.children)return;for(var b=0;b0){var k=i.children[0];k.yFov&&(pp.camera.fovy=k.yFov,pp.camera.pMatrix=null),k.zNear&&(pp.camera.near=k.zNear),k.zFar&&(pp.camera.far=k.zFar)}pp.camera.matrix=null,pp.camera.rotmatrix=i.rotmatrix,pp.camera.lookAt=null}}};var f={"default":{},"COLLADA Mixamo exporter":{badAccessor:!0},"FBX COLLADA exporter":{badAccessor:!0},"Blender2.5":{flipangle:!0,negjoints:!0}};a.Collada.prototype.getExceptions=function(){if(this.xml.getElementsByTagName("authoring_tool").length>0&&this.xml.getElementsByTagName("authoring_tool")[0].firstChild.nodeValue=="COLLADA Mixamo exporter")return f["COLLADA Mixamo exporter"];if(this.xml.getElementsByTagName("authoring_tool").length>0&&this.xml.getElementsByTagName("authoring_tool")[0].firstChild.nodeValue=="FBX COLLADA exporter")return f["FBX COLLADA exporter"];if(this.xml.getElementsByTagName("authoring_tool").length>0&&/Blender 2.5/.test(this.xml.getElementsByTagName("authoring_tool")[0].firstChild.nodeValue))return f["Blender2.5"]},a.Collada.prototype.loaded=function(a,b){this.xml=b,b.getElementsByTagName("authoring_tool").length>0&&(this.exceptions=f[b.getElementsByTagName("authoring_tool")[0].firstChild.nodeValue]),this.exceptions=this.getExceptions(),this.exceptions||(this.exceptions=f["default"]),this.initVisualScene(),this.getAnimations(),this.loadedCallback&&this.loadedCallback(this);var c=this;setTimeout(function(){c.fireEvent("loaded",{url:this.url}),c.isComplete()&&c.fireEvent("downloadComplete",{})},1)},a.Scene.prototype.addCollada=a.Scene.prototype.addGroup,a.Group.prototype.addCollada=a.Group.prototype.addGroup,a.Document&&(a.Document.prototype.getCollada=function(b){b.object||(b.object=new(a[this.classString(b.tagName)]),b.object.setDocument(b.getAttribute("document"),this.getAbsolutePath(this.rootURL,null)),b.removeAttribute("document"),this.setProperties(b));return b.object})}(GLGE);if(!GLGE)var GLGE={};(function(a){a.HeightMap=function(a,b,c,d,e,f,g,h,j){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.canvas.width=b,this.canvas.height=c,this.minX=d,this.maxX=e,this.minY=f,this.maxY=g,this.minZ=h,this.maxZ=j;var k=new Image;k.heightmap=this,k.onload=function(a){this.heightmap.context.drawImage(this,0,0),this.heightmap.data=this.heightmap.context.getImageData(0,0,this.heightmap.canvas.width,this.heightmap.canvas.height).data,this.heightmap.minImgValue=this.heightmap.data[0],this.heightmap.maxImgValue=this.heightmap.data[0];for(i=0;ithis.heightmap.maxImgValue&&(this.heightmap.maxImgValue=this.heightmap.data[i])},k.src=a},a.HeightMap.prototype.canvas=null,a.HeightMap.prototype.context=null,a.HeightMap.prototype.minZ=null,a.HeightMap.prototype.maxZ=null,a.HeightMap.prototype.minY=null,a.HeightMap.prototype.maxY=null,a.HeightMap.prototype.minX=null,a.HeightMap.prototype.maxX=null,a.HeightMap.prototype.data=null,a.HeightMap.prototype.getPixelAt=function(a,b){return this.data?(this.data[(this.canvas.width*b+a)*4]-this.minImgValue)/(this.maxImgValue-this.minImgValue)*(this.maxZ-this.minZ)+this.minZ:0},a.HeightMap.prototype.getHeightAt=function(a,b){var c;if(this.lastx!=undefined&&a==this.lastx&&b==this.lasty)c=this.lastValue;else{var d=Math.round((a-this.minX)/(this.maxX-this.minX)*this.canvas.width),e=Math.round((b-this.minY)/(this.maxY-this.minY)*this.canvas.height);c=this.getPixelAt(d,e),this.lastValue=c}this.lastx=a,this.lasty=b;return c},a.KeyInput=function(){document.keyStates||(document.keyStates=[]),document.addEventListener("keydown",this.onKeyDown,!1),document.addEventListener("keyup",this.onKeyUp,!1)},a.KeyInput.prototype.isKeyPressed=function(a){return document.keyStates[a]?!0:!1};var b=null;a.KeyInput.prototype.onKeyDown=function(a){document.keyStates[a.keyCode]=!0},a.KeyInput.prototype.onKeyUp=function(a){document.keyStates[a.keyCode]=!1},a.MouseInput=function(a){this.element=a,this.element.mouseX=0,this.element.mouseY=0,this.element.buttonState||(this.element.buttonState=[]),a.addEventListener("mousemove",this.onMouseMove,!1),a.addEventListener("mousedown",this.onMouseDown,!1),a.addEventListener("mouseup",this.onMouseUp,!1)},a.MouseInput.prototype.element=null,a.MouseInput.prototype.onMouseMove=function(a){this.mouseX=a.clientX,this.mouseY=a.clientY},a.MouseInput.prototype.onMouseDown=function(a){this.buttonState[a.button]=!0},a.MouseInput.prototype.onMouseUp=function(a){this.buttonState[a.button]=!1},a.MouseInput.prototype.isButtonDown=function(a){return this.element.buttonState[a]?!0:!1},a.MouseInput.prototype.getMousePosition=function(){return{x:this.element.mouseX,y:this.element.mouseY}},a.MI_LEFT=0,a.MI_MIDDLE=1,a.MI_RIGHT=2,a.KI_BACKSPACE=8,a.KI_TAB=9,a.KI_ENTER=13,a.KI_SHIFT=16,a.KI_CTRL=17,a.KI_ALT=18,a.KI_PAUSE_BREAK=19,a.KI_CAPS_LOCK=20,a.KI_ESCAPE=27,a.KI_PAGE_UP=33,a.KI_PAGE_DOWN=34,a.KI_END=35,a.KI_HOME=36,a.KI_LEFT_ARROW=37,a.KI_UP_ARROW=38,a.KI_RIGHT_ARROW=39,a.KI_DOWN_ARROW=40,a.KI_INSERT=45,a.KI_DELETE=46,a.KI_0=48,a.KI_1=49,a.KI_2=50,a.KI_3=51,a.KI_4=52,a.KI_5=53,a.KI_6=54,a.KI_7=55,a.KI_8=56,a.KI_9=57,a.KI_A=65,a.KI_B=66,a.KI_C=67,a.KI_D=68,a.KI_E=69,a.KI_F=70,a.KI_G=71,a.KI_H=72,a.KI_I=73,a.KI_J=74,a.KI_K=75,a.KI_L=76,a.KI_M=77,a.KI_N=78,a.KI_O=79,a.KI_P=80,a.KI_Q=81,a.KI_R=82,a.KI_S=83,a.KI_T=84,a.KI_U=85,a.KI_V=86,a.KI_W=87,a.KI_X=88,a.KI_Y=89,a.KI_Z=90,a.KI_LEFT_WINDOW_KEY=91,a.KI_RIGHT_WINDOW_KEY=92,a.KI_SELECT_KEY=93,a.KI_NUMPAD_0=96,a.KI_NUMPAD_1=97,a.KI_NUMPAD_2=98,a.KI_NUMPAD_3=99,a.KI_NUMPAD_4=100,a.KI_NUMPAD_5=101,a.KI_NUMPAD_6=102,a.KI_NUMPAD_7=103,a.KI_NUMPAD_8=104,a.KI_NUMPAD_9=105,a.KI_MULTIPLY=106,a.KI_ADD=107,a.KI_SUBTRACT=109,a.KI_DECIMAL_POINT=110,a.KI_DIVIDE=111,a.KI_F1=112,a.KI_F2=113,a.KI_F3=114,a.KI_F4=115,a.KI_F5=116,a.KI_F6=117,a.KI_F7=118,a.KI_F8=119,a.KI_F9=120,a.KI_F10=121,a.KI_F11=122,a.KI_F12=123,a.KI_NUM_LOCK=144,a.KI_SCROLL_LOCK=145,a.KI_SEMI_COLON=186,a.KI_EQUAL_SIGN=187,a.KI_COMMA=188,a.KI_DASH=189,a.KI_PERIOD=190,a.KI_FORWARD_SLASH=191,a.KI_GRAVE_ACCENT=192,a.KI_OPEN_BRACKET=219,a.KI_BACK_SLASH=220,a.KI_CLOSE_BRAKET=221,a.KI_SINGLE_QUOTE=222,a.KI_SPACE=32,window.requestAnimationFrame||(window.requestAnimationFrame=function(){return window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a,b){window.setTimeout(a,1e3/60)}}())})(GLGE),function(a){a.Wavefront=function(b){a.Assets.registerAsset(this,b),this.multimaterials=[],this.materials={},this.instances=[],this.queue=[],a.Object.call(this,b)},a.augment(a.Object,a.Wavefront),a.Wavefront.prototype.getAbsolutePath=function(a,b){if(a.substr(0,7)=="http://"||a.substr(0,7)=="file://"||a.substr(0,7)=="https://")return a;b||(b=window.location.href),b.indexOf("?")>0&&(b=b.substr(0,b.indexOf("?")));var c=b.split("/"),d=c[2],e=c[0],f=[];for(var g=3;g0){var c=this.queue.pop();this.loadMaterials(c,this.src)}else this.parseMesh(),this.fireEvent("loaded",{})})},a.Wavefront.prototype.parseMaterials=function(b){for(var c=0;c1)switch(d[0]){case"Kd":e.setColorR(parseFloat(d[1])),e.setColorG(parseFloat(d[2])),e.setColorB(parseFloat(d[3]));break;case"Ks":e.setSpecularColor({r:parseFloat(d[1]),g:parseFloat(d[2]),b:parseFloat(d[3])});break;case"Ns":e.setShininess(parseFloat(d[1]));break;case"d":this.setZtransparent(!0),e.setAlpha(parseFloat(d[1]));break;case"map_Kd":var f=new a.MaterialLayer;f.setMapto(a.M_COLOR),f.setMapinput(a.UV1);var g=new a.Texture,h=1;while(d[h][0]=="-")h=h+2;g.setSrc(this.getAbsolutePath(d[h],this.relativeTo)),e.addTexture(g),f.setTexture(g),e.addMaterialLayer(f);case"map_Ks":case"map_spec":var f=new a.MaterialLayer;f.setMapto(a.M_SPECULAR),f.setMapinput(a.UV1);var g=new a.Texture,h=1;while(d[h][0]=="-")h=h+2;g.setSrc(this.getAbsolutePath(d[h],this.relativeTo)),e.addTexture(g),f.setTexture(g),e.addMaterialLayer(f);case"bump":case"map_bump":var f=new a.MaterialLayer;f.setMapto(a.M_NOR),f.setMapinput(a.UV1);var g=new a.Texture,h=1;while(d[h][0]=="-")h=h+2;g.setSrc(this.getAbsolutePath(d[h],this.relativeTo)),e.addTexture(g),f.setTexture(g),e.addMaterialLayer(f)}}},a.Wavefront.prototype.loadFile=function(b,c,d){this.loading=!0,d||(d=this.loaded),!c&&this.relativeTo&&(c=this.relativeTo),b=this.getAbsolutePath(b,c),this.relativeTo||(this.relativeTo=b);var e=new XMLHttpRequest,f=this;e&&(e.overrideMimeType("text/plain"),e.onreadystatechange=function(){this.readyState==4&&(this.status==200||this.status==0?(f.loading=!1,d.call(f,b,this.responseText)):a.error("Error loading Document: "+b+" status "+this.status))},e.open("GET",b,!0),e.send(""))},a.Wavefront.prototype.setSrc=function(a,b){this.src=this.getAbsolutePath(a,b),this.loadFile(this.src,b)},a.Wavefront.prototype.loaded=function(a,b){this.file=objArray=b.split("\n");var c=!1;for(var d=0;d1&&(e[0]=="mtllib"&&(c=!0,this.loadMaterials(e[1])))}c||(this.parseMesh(),this.fireEvent("loaded",{}))},a.Wavefront.prototype.createMultiMaterial=function(b,c,d,e,f,g,h){var j=[],k=[],l=[],m=[],n=[];for(i=0;i0)var p=n[i].split("/");else var p=[n[i]];c[p[0]-1]||a.error(p[0]),j.push(c[p[0]-1][1]),j.push(c[p[0]-1][2]),j.push(c[p[0]-1][3]),p[1]&&(l.push(e[p[1]-1][1]),l.push(e[p[1]-1][2])),p[2]&&(k.push(d[p[2]-1][1]),k.push(d[p[2]-1][2]),k.push(d[p[2]-1][3]))}var q=new a.MultiMaterial,r=new a.Mesh;r.setPositions(j),l.length>0&&r.setUV(l),k.length>0&&r.setNormals(k),r.setFaces(f),q.setMesh(r),q.setMaterial(g),this.addMultiMaterial(q)},a.Wavefront.prototype.parseMesh=function(){objArray=this.file;var b=[],c=[],d=[],e=[],f=[],g=0,h=!0,i=new a.Material;for(var j=0;j0)switch(k[0]){case"s":k[1]=="1"?h=!0:h=!1;case"o":e.length>0&&(this.createMultiMaterial(f,c,d,b,e,i,h),e=[],i=new a.Material);break;case"usemtl":e.length>0&&(this.createMultiMaterial(f,c,d,b,e,i,h),e=[]),i=this.materials[k[1]];break;case"v":c.push(k);break;case"vt":b.push(k);break;case"vn":d.push(k);break;case"f":var l=[];for(var m=1;m-1&&(this.constraints.push(a),this.physicsSystem&&this.physicsSystem.removeConstraint(a.constraint));return this}}(GLGE)