From 56e6a780fe816ac31c179c3f9c8303a6d2287507 Mon Sep 17 00:00:00 2001 From: Victor Carlquist Date: Sun, 31 Aug 2014 21:13:26 -0300 Subject: [PATCH] Bug Fixed on chrome: Uniforms with the same name but different type/precision --- glge-compiled-min.js | 2 +- glge-compiled.js | 7151 ++++++++++++++++----------------- src/material/glge_material.js | 18 +- src/renderable/glge_object.js | 14 +- 4 files changed, 3590 insertions(+), 3595 deletions(-) mode change 100644 => 100755 src/renderable/glge_object.js diff --git a/glge-compiled-min.js b/glge-compiled-min.js index 9d086c9..dccb497 100644 --- a/glge-compiled-min.js +++ b/glge-compiled-min.js @@ -25,4 +25,4 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -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.negVec4=function(a){return[-a[0],-a[1],-a[2],-a[3]]},a.negVec3=function(a){return[-a[0],-a[1],-a[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.makePerspectiveX=function(b,c,d,e){var f=d*Math.tan(b*.00872664625972),g=-f,h=g/c,i=f/c;return a.makeFrustum(g,f,h,i,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(var i=0;i<2;i++)for(var j=0;j<2;j++)for(var k=0;k<2;k++){var l=a.mulMat4Vec4(f,[i*2-1,j*2-1,k*2-1,1]);l[0]=l[0]/l[3],l[1]=l[1]/l[3],l[2]=l[2]/l[3],g[0]=g[0]>l[0]?l[0]:g[0],g[1]=g[1]>l[1]?l[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"color":b.object.setVertexColors(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){var b;if(typeof a=="object"){for(var c=0;c0&&a.Message.loadMessages()}}(GLGE),function(a){a.Action=function(b){this.channels=[],a.Assets.registerAsset(this,b)},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){this.curves={},a.Assets.registerAsset(this,b)},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){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_UNKNOWN,a.Assets.registerAsset(this,b)},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.positions)return new a.BoundingVolume(0,0,0,0,0,0);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&&(k.push(d[c[l]*3]),k.push(d[c[l]*3+1]),k.push(d[c[l]*3+2])),e&&(i.push(e[c[l]*2]),i.push(e[c[l]*2+1])),f&&(j.push(f[c[l]*2]),j.push(f[c[l]*2+1]));else g=a,h=b,k=d,i=e,j=f;var m=[],n=[],o=[],p=[],q=[],r=[],s=[];for(var l=0;l0&&(r.push(k[l]),r.push(k[l+1]),r.push(k[l+2])),e&&(p.push(i[l/3*2]),p.push(i[l/3*2+1])),f&&(q.push(j[l/3*2]),q.push(j[l/3*2+1]))),o.push(u)}this.setPositions(m).setNormals(n).setFaces(o).setUV(p).setUV2(q).setTangents(r)},a.Mesh.prototype.GLAttributes=function(b,c,d,e){this.gl=b,d||(d=0),this.normals||this.calcNormals();for(var f=0;f<8;f++)b.disableVertexAttribArray(f);!this.faces.GL&&this.faces.data&&this.faces.data.length>0&&(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){a.Sphere=function(b){this.vertical=10,this.horizontal=10,this.radius=1,this.dirtySphere=!1,a.Mesh.apply(this,arguments),this.generateMeshData()},a.augment(a.Mesh,a.Sphere),a.Sphere.prototype.generateMeshData=function(){var b=this.vertical,c=this.horizontal,d=this.radius,e,f,g,h,i,j,f,k,l=[],m=[],n=[];for(h=0;h<=b;h++){e=h/b*Math.PI,f=Math.cos(e)*d,g=Math.sin(e)*d;for(i=0;i0)for(i=0;i0&&(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.setEmitR=function(a){this.emit.r=parseFloat(a);return this},a.Material.prototype.setEmitG=function(a){this.emit.g=parseFloat(a);return this},a.Material.prototype.setEmitB=function(a){this.emit.b=parseFloat(a);return this},a.Material.prototype.getEmitR=function(a){return this.emit.r},a.Material.prototype.getEmitG=function(a){return this.emit.g},a.Material.prototype.getEmitB=function(a){return this.emit.b},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(var d=0;dneye.z*steepdisplace"+h+"){",f=f+"textureHeight=vec3(vec2(neye.x,neye.y)*steepdisplace"+h+",0.0);",f=f+"}else{",f=f+"steepdisplace"+h+"-=steepstep"+h+";",f=f+"steepstep"+h+"*=0.5;",f=f+"}",f=f+"steepdisplace"+h+"+=steepstep"+h+";",f=f+"}"),(this.layers[h].mapto&a.M_SPECCOLOR)==a.M_SPECCOLOR&&(f=f+"specC = specC*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").rgb*mask;\n"),(this.layers[h].mapto&a.M_MSKR)==a.M_MSKR&&(f=f+"mask = texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").r;\n"),(this.layers[h].mapto&a.M_MSKG)==a.M_MSKG&&(f=f+"mask = texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").g;\n"),(this.layers[h].mapto&a.M_MSKB)==a.M_MSKB&&(f=f+"mask = texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").b;\n"),(this.layers[h].mapto&a.M_MSKA)==a.M_MSKA&&(f=f+"mask = texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").a;\n"),(this.layers[h].mapto&a.M_SPECULAR)==a.M_SPECULAR&&(f=f+"spec = spec*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").r*mask;\n"),(this.layers[h].mapto&a.M_REFLECT)==a.M_REFLECT&&(f=f+"ref = ref*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").g*mask;\n"),(this.layers[h].mapto&a.M_SHINE)==a.M_SHINE&&(f=f+"sh = sh*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").b*mask*255.0;\n"),(this.layers[h].mapto&a.M_EMIT)==a.M_EMIT&&(f=f+"em = em*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").rgb*mask;\n"),(this.layers[h].mapto&a.M_NOR)==a.M_NOR&&(f=f+"normalmap = normalmap*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+")*mask;\n",f=f+"normal = normalmap.rgb;\n",f=f+"normal = 2.0*(vec3(normal.r, -normal.g, normal.b) - vec3(0.5, -0.5, 0.5));",f=f+"b=normalize(cross(t.xyz,n));\n",f=f+"normal = normal.x*t + normal.y*b + normal.z*n;",f=f+"normal = normalize(normal);"),(this.layers[h].mapto&a.M_ALPHA)==a.M_ALPHA&&(m=!0,f=f+"al = al*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").a*mask;\n"),(this.layers[h].mapto&a.M_AMBIENT)==a.M_AMBIENT&&(f=f+"amblight = amblight*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[h].texture.idx+", textureCoords."+n+").rgb*mask;\n")}f=f+"amblight *= amb;\n";if(!m&&this.layers.length){if(this.layers[l].getTexture().className=="Texture"||this.layers[l].getTexture().className=="TextureCanvas"||this.layers[l].getTexture().className=="TextureVideo")var n="xy",o="2D";else var n="xyz",o="Cube";f=f+"al = al*(1.0-mask) + texture"+o+"(TEXTURE"+this.layers[l].texture.idx+", textureCoords."+n+").a*al*mask;\n"}c&&this.vertexColorMode==a.VC_MUL&&(f=f+"color *= vcolor;"),this.binaryAlpha?(f=f+"if(al<0.5) discard;\n",f=f+"al=1.0;\n"):f=f+"if(al==0.0) discard;\n",f=f+"vec3 lightvalue=amblight;\n",c&&this.vertexColorMode==a.VC_AMB&&(f=f+"lightvalue = vcolor.rgb;"),c&&this.vertexColorMode==a.VC_AMBMUL&&(f=f+"lightvalue *= vcolor.rgb;"),f=f+"float dotN,spotEffect;",f=f+"vec3 lightvec=vec3(0.0,0.0,0.0);",f=f+"vec3 viewvec=vec3(0.0,0.0,0.0);",f=f+"vec3 specvalue=vec3(0.0,0.0,0.0);",f=f+"vec2 scoord=vec2(0.0,0.0);",f=f+"float sDepth=0.0;",f=f+"float d1=0.0;",f=f+"float d2=0.0;",f=f+"float spotmul=0.0;",f=f+"float rnd=0.0;",f=f+"float spotsampleX=0.0;",f=f+"float spotsampleY=0.0;",f=f+"float totalweight=0.0;",f=f+"int cnt=0;",f=f+"float specularSmoothStepValue=.125;\n",f=f+"vec2 spotoffset=vec2(0.0,0.0);",f=f+"float dp=0.0;",f=f+"vec4 dist;float depth,m1,m2,prob,variance;\n",f=f+"if (normal.z<0.0) {normal.z=0.0;}\n",f=f+"float fogfact=1.0;",f=f+"if(fogtype=="+a.FOG_QUADRATIC+" || fogtype=="+a.FOG_SKYQUADRATIC+") fogfact=clamp(pow(max((fogfar - length(eyevec)) / (fogfar - fognear),0.0),2.0),0.0,1.0);\n",f=f+"if(fogtype=="+a.FOG_LINEAR+" || fogtype=="+a.FOG_SKYLINEAR+") fogfact=clamp((fogfar - length(eyevec)) / (fogfar - fognear),0.0,1.0);\n";if(e)f=f+"float shadowdepth = gl_FragCoord.z;\n",f=f+"if(shadowtype) shadowdepth=length(eyevec)/distance;\n",f=f+"vec4 rgba=fract(shadowdepth * vec4(16777216.0, 65536.0, 256.0, 1.0));\n",f=f+"gl_FragColor=rgba-rgba.rrgb*vec4(0.0,0.00390625,0.00390625,0.00390625);\n";else{f=f+"if (emitpass) {gl_FragColor=vec4(em,1.0);} else if (shadeless) {\n",f=f+"gl_FragColor=vec4(color.rgb,al);\n",this.fadeDistance>0&&(f=f+"gl_FragColor.a=gl_FragColor.a*(1.0-min(1.0,"+this.fadeDistance.toFixed(5)+"/length(eyevec)));\n"),f=f+"} else {\n";for(var h=0;h0.0){\n",b[h].diffuse&&(f=f+"lightvalue += att * dotN * lightcolor"+h+";\n"),f=f+"}\n",b[h].specular&&(f=f+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN)*att * specC * lightcolor"+h+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3*sh);\n")),f=f+"spotEffect = 0.0;\n",b[h].type==a.L_SPOT&&(f=f+"spotEffect = dot(normalize(lightdir"+h+"), normalize(-lightvec"+h+"));",f=f+"if (spotEffect > spotCosCutOff"+h+""+(this.spotCutOff?"":" || spotEffect>0.0")+") {\n",f=f+"spotEffect = pow(spotEffect, spotExp"+h+");",b[h].getCastShadows()&&this.shadow&&(f=f+"scoord=(((spotcoord"+h+".xy)/spotcoord"+h+".w)+1.0)/2.0;\n",f=f+"if(scoord.x>0.0 && scoord.x<1.0 && scoord.y>0.0 && scoord.y<1.0){\n",f=f+"dist=texture2D(TEXTURE"+j[h]+", scoord);\n",b[h].spotSoftness==0?(f=f+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0))*"+b[h].distance+".0;\n",f=f+"if(depth0.0){\n",b[h].diffuse&&(f=f+"lightvalue -= (1.0-spotEffect) / (lightAttenuation"+h+"[0] + lightAttenuation"+h+"[1] * lightdist"+h+" + lightAttenuation"+h+"[2] * lightdist"+h+" * lightdist"+h+");\n"),f=f+"}\n"):(f=f+"att = spotEffect / (lightAttenuation"+h+"[0] + lightdist"+h+"*(lightAttenuation"+h+"[1] + lightAttenuation"+h+"[2] * lightdist"+h+"));\n",f=f+"if(dotN>0.0){\n",b[h].diffuse&&(f=f+"lightvalue += att * dotN * lightcolor"+h+";\n"),f=f+"}\n",b[h].specular&&(f=f+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN) * att * specC * lightcolor"+h+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3 * sh);\n")),f=f+"}\n");if(b[h].type==a.L_DIR){this.translucency==0?f=f+"dotN=max(dot(normal,normalize(-lightvec)),0.0);\n":(f=f+"dotN=dot(normal,normalize(-lightvec));\n",f=f+"if (dotN<0.0) dotN*=-"+this.translucency.toFixed(2)+";\n");if(b[h].getCastShadows()&&this.shadow){f=f+"float shadowfact"+h+" = 0.0;\n",f=f+"scoord=((spotcoord"+h+".xy)/spotcoord"+h+".w+1.0)/2.0;\n";var p=1/b[h].bufferWidth,q=1/b[h].bufferHeight;f=f+"dist=texture2D(TEXTURE"+j[h]+", scoord );\n",f=f+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n",f=f+"d1 = depth;\n",f=f+"d2 = depth*depth;\n",f=f+"dist=texture2D(TEXTURE"+j[h]+", scoord+vec2("+p.toFixed(5)+","+q.toFixed(5)+") );\n",f=f+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n",f=f+"d1 += depth;\n",f=f+"d2 += depth*depth;\n",f=f+"dist=texture2D(TEXTURE"+j[h]+", scoord+vec2(-"+p.toFixed(5)+","+q.toFixed(5)+"));\n",f=f+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n",f=f+"d1 += depth;\n",f=f+"d2 += depth*depth;\n",f=f+"dist=texture2D(TEXTURE"+j[h]+", scoord+vec2("+p.toFixed(5)+",-"+q.toFixed(5)+"));\n",f=f+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n",f=f+"d1 += depth;\n",f=f+"d2 += depth*depth;\n",f=f+"dist=texture2D(TEXTURE"+j[h]+", scoord+vec2(-"+p.toFixed(5)+",-"+q.toFixed(5)+"));\n",f=f+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n",f=f+"d1 += depth;\n",f=f+"d2 += depth*depth;\n",f=f+"d1 *= 0.2;\n",f=f+"d2 *= 0.2;\n",f=f+"sDepth = max(0.0, ((spotcoord"+h+".z/spotcoord"+h+".w)+1.0)/2.0-d1-"+b[h].shadowBias+");\n",f=f+"variance = min(max(d2-d1*d1, 0.0)+"+b[h].varianceMin+", 1.0);\n",f=f+"prob=variance /( variance + sDepth*sDepth );\n",f=f+"prob=smoothstep("+b[h].bleedCutoff.toFixed(2)+",1.0,prob);\n",f=f+"shadowfact"+h+"=prob;\n"}else f=f+"float shadowfact"+h+" = 1.0;\n";b[h].diffuse&&(b[h].negativeShadow?f=f+"lightvalue -= lightcolor"+h+"-(dotN * lightcolor"+h+" * shadowfact"+h+");\n":(f=f+"shadowfact"+h+"="+this.translucency.toFixed(2)+"+"+(1-this.translucency).toFixed(2)+"*shadowfact"+h+";\n",f=f+"lightvalue += dotN * lightcolor"+h+" * shadowfact"+h+";\n")),b[h].specular&&(f=f+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN) * specC * lightcolor"+h+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3 * sh);\n")}}f=f+"lightvalue = (lightvalue)*ref;\n",f=f+"vec3 fc=fogcolor.rgb;\n",f=f+"if(fogtype=="+a.FOG_SKYLINEAR+" || fogtype=="+a.FOG_SKYQUADRATIC+"){",f=f+"vec4 view=projection * vec4(-eyevec,1.0);\n",f=f+"vec2 fogCoords=view.xy/view.w*0.5+0.5;\n",f=f+"fc=texture2D(sky,fogCoords.xy).rgb;\n",f=f+"}\n",f=f+"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")&&(f=f+"finalColor=GLGE_FragColor(finalColor);\n"),this.fadeDistance>0&&(f=f+"finalColor.a=finalColor.a*(1.0-min(1.0,"+this.fadeDistance.toFixed(5)+"/length(eyevec)));\n"),this.fadeDistance<0&&(f=f+"finalColor.a=finalColor.a*(min(1.0,"+(-this.fadeDistance).toFixed(5)+"/length(eyevec)));\n"),f=f+"gl_FragColor = finalColor;",a.DEBUGNORMALS&&(f=f+"gl_FragColor = vec4(normal.rgb,1.0);"),a.DEBUGCOORD0&&(f=f+"gl_FragColor = vec4(textureCoords0.rg,0.0,1.0);"),f=f+"}\n"}f=f+"}\n";return f},a.Material.prototype.textureUniforms=function(b,c,d,e){this.animation&&this.animate();var f=c.caches;if(!f.baseColor||f.baseColor.r!=this.color.r||f.baseColor.g!=this.color.g||f.baseColor.b!=this.color.b||f.baseColor.a!=this.color.a){if(!this.ccache||this.ccache.r!=this.color.r||this.ccache.g!=this.color.g||this.ccache.b!=this.color.b||this.ccache.a!=this.color.a)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;var g=1,h=0;f.lightcolor||(f.lightcolor=[],f.lightAttenuation=[],f.spotCosCutOff=[],f.spotExponent=[],f.shadowbias=[],f.castshadows=[],f.shadowsamples=[],f.shadowsoftness=[]);if(d)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.autoUpdate=!0,a.TextureCamera.prototype.rendered=!1,a.TextureCamera.prototype.render=function(){this.rendered=!1;return this},a.TextureCamera.prototype.setAutoUpdate=function(a){this.autoUpdate=a;return this},a.TextureCamera.prototype.getAutoUpdate=function(){return this.autoUpdate},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)return!1;if(!this.autoRender&&this.rendered&&0)b.bindTexture(b.TEXTURE_2D,this.glTexture);else{this.rendered=!0,this.gl=b;var d=c.getModelMatrix(),e=this.camera.pMatrix,f=this.camera.matrix;this.camera.pMatrix=null,this.camera.matrix=null;var g=this.camera.getProjectionMatrix().slice(0),h=this.camera.getViewMatrix().slice(0);this.camera.pMatrix=e,this.camera.matrix=f;var i;if(this.mirrorAxis)switch(this.mirrorAxis){case a.XAXIS:i=a.mulMat4(a.mulMat4(a.mulMat4(h,d),a.scaleMatrix(-1,1,1)),a.inverseMat4(d));break;case a.YAXIS:i=a.mulMat4(a.mulMat4(a.mulMat4(h,d),a.scaleMatrix(1,-1,1)),a.inverseMat4(d));break;case a.ZAXIS:i=a.mulMat4(a.mulMat4(a.mulMat4(h,d),a.scaleMatrix(1,1,-1)),a.inverseMat4(d))}else i=h;if(this.clipAxis){var j;switch(this.clipAxis){case a.NEG_XAXIS:var k=a.toUnitVec3([-d[0],-d[4],-d[8]]);j=[k[0],k[1],k[2],-a.dotVec3([d[3],d[7],d[11]],k)-this.planeOffset];break;case a.POS_XAXIS:var k=a.toUnitVec3([d[0],d[4],d[8]]);j=[k[0],k[1],k[2],-a.dotVec3([d[3],d[7],d[11]],k)-this.planeOffset];break;case a.NEG_YAXIS:var k=a.toUnitVec3([-d[1],-d[5],-d[9]]);j=[k[0],k[1],k[2],-a.dotVec3([d[3],d[7],d[11]],k)-this.planeOffset];break;case a.POS_YAXIS:var k=a.toUnitVec3([d[1],d[5],d[9]]);j=[k[0],k[1],k[2],-a.dotVec3([d[3],d[7],d[11]],k)-this.planeOffset];break;case a.NEG_ZAXIS:var k=a.toUnitVec3([-d[2],-d[6],-d[10]]);j=[k[0],k[1],k[2],-a.dotVec3([d[3],d[7],d[11]],k)-this.planeOffset];break;case a.POS_ZAXIS:var k=a.toUnitVec3([d[2],d[6],d[10]]);j=[k[0],k[1],k[2],-a.dotVec3([d[3],d[7],d[11]],k)-this.planeOffset]}var l=a.transposeMat4(a.inverseMat4(a.mulMat4(g,i)));j=a.mulMat4Vec4(l,j),j=a.scaleVec4(j,g[10]),j[3]-=1,j[2]<0&&a.scaleVec4(j,-1);var m=[1,0,0,0,0,1,0,0,j[0],j[1],j[2],j[3],0,0,0,1];g=a.mulMat4(m,g)}var n=this.bufferHeight?this.bufferHeight:b.scene.renderer.canvas.height,o=this.bufferWidth?this.bufferWidth:b.scene.renderer.canvas.width;if(!this.glTexture||this.update){this.createFrameBuffer(b),b.scene.addRenderPass(this.frameBuffer,i,b.scene.camera.getProjectionMatrix(),o,n,c,this.mirrorAxis?!0:!1),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,i,g,o,n,c,this.mirrorAxis?!0:!1);return!0}},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.TextureCameraCube=function(b){a.Assets.registerAsset(this,b),this.cubeBuffers=[]},a.augment(a.QuickNotation,a.TextureCameraCube),a.augment(a.JSONLoader,a.TextureCameraCube),a.augment(a.Events,a.TextureCameraCube),a.TextureCameraCube.prototype.className="TextureCube",a.TextureCameraCube.prototype.texture=null,a.TextureCameraCube.prototype.glTexture=null,a.TextureCameraCube.prototype.object=null,a.TextureCameraCube.prototype.autoUpdate=!1,a.TextureCameraCube.prototype.rendered=!1,a.TextureCameraCube.prototype.bufferHeight=512,a.TextureCameraCube.prototype.bufferWidth=512,a.TextureCameraCube.prototype.offsetX=0,a.TextureCameraCube.prototype.offsetY=0,a.TextureCameraCube.prototype.offsetZ=0,a.TextureCameraCube.prototype.cameraMatries=[[0,0,-1,0,0,1,0,0,-1,0,0,0,0,0,0,1],[0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1],[-1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],[-1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1],[1,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,1],[-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]],a.TextureCameraCube.prototype.pMatrix=a.makePerspective(90,1,1e-4,1e3),a.TextureCameraCube.prototype.render=function(){this.rendered=!1;return this},a.TextureCameraCube.prototype.setOffsetX=function(a){this.offsetX=a;return this},a.TextureCameraCube.prototype.getOffsetX=function(){return this.offsetX},a.TextureCameraCube.prototype.setOffsetY=function(a){this.offsetY=a;return this},a.TextureCameraCube.prototype.getOffsetY=function(){return this.offsetY},a.TextureCameraCube.prototype.setOffsetZ=function(a){this.offsetZ=a;return this},a.TextureCameraCube.prototype.getOffsetZ=function(){return this.offsetZ},a.TextureCameraCube.prototype.setAutoUpdate=function(a){this.autoUpdate=a;return this},a.TextureCameraCube.prototype.getAutoUpdate=function(){return this.autoUpdate},a.TextureCameraCube.prototype.setBufferWidth=function(a){this.bufferWidth=a,this.update=!0;return this},a.TextureCameraCube.prototype.getBufferWidth=function(){return this.bufferWidth},a.TextureCameraCube.prototype.setBufferHeight=function(a){this.bufferHeight=a,this.update=!0;return this},a.TextureCameraCube.prototype.getBufferHeight=function(){return this.bufferHeight},a.TextureCameraCube.prototype.doTexture=function(b,c){this.gl=b;var d=c.getModelMatrix(),e=this.bufferHeight,f=this.bufferWidth;if(!this.cubeBuffers.length||this.update){this.createFrameBuffers(b),this.update=!1;return!1}b.bindTexture(b.TEXTURE_CUBE_MAP,this.glTexture);if(!this.rendered||this.autoUpdate){for(var g=0;g<6;g++){var h=this.cameraMatries[g].slice(0),i=a.mulMat4(h,d),j=a.mulMat4Vec3(i,[this.offsetX,this.offsetY,this.offsetZ,1]);h[3]=-j[0],h[7]=-j[1],h[11]=-j[2],b.scene.addRenderPass(this.cubeBuffers[g],h,this.pMatrix,f,e,c,!0)}this.rendered=!0}return!0},a.TextureCameraCube.prototype.registerPasses=a.TextureCameraCube.prototype.doTexture,a.TextureCameraCube.prototype.createFrameBuffers=function(a){var b=this.bufferHeight,c=this.bufferWidth,d=a.createRenderbuffer();this.glTexture=a.createTexture(),a.bindTexture(a.TEXTURE_CUBE_MAP,this.glTexture),a.bindRenderbuffer(a.RENDERBUFFER,d),a.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,c,b),a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_X,0,a.RGBA,c,b,0,a.RGBA,a.UNSIGNED_BYTE,null),a.texImage2D(a.TEXTURE_CUBE_MAP_NEGATIVE_X,0,a.RGBA,c,b,0,a.RGBA,a.UNSIGNED_BYTE,null),a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_Y,0,a.RGBA,c,b,0,a.RGBA,a.UNSIGNED_BYTE,null),a.texImage2D(a.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,a.RGBA,c,b,0,a.RGBA,a.UNSIGNED_BYTE,null),a.texImage2D(a.TEXTURE_CUBE_MAP_POSITIVE_Z,0,a.RGBA,c,b,0,a.RGBA,a.UNSIGNED_BYTE,null),a.texImage2D(a.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,a.RGBA,c,b,0,a.RGBA,a.UNSIGNED_BYTE,null),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MIN_FILTER,a.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);var e;e=a.createFramebuffer(),a.bindFramebuffer(a.FRAMEBUFFER,e),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,d),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_NEGATIVE_X,this.glTexture,0),this.cubeBuffers.push(e),e=a.createFramebuffer(),a.bindFramebuffer(a.FRAMEBUFFER,e),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,d),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X,this.glTexture,0),this.cubeBuffers.push(e),e=a.createFramebuffer(),a.bindFramebuffer(a.FRAMEBUFFER,e),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,d),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_NEGATIVE_Y,this.glTexture,0),this.cubeBuffers.push(e),e=a.createFramebuffer(),a.bindFramebuffer(a.FRAMEBUFFER,e),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,d),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_Y,this.glTexture,0),this.cubeBuffers.push(e),e=a.createFramebuffer(),a.bindFramebuffer(a.FRAMEBUFFER,e),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,d),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_NEGATIVE_Z,this.glTexture,0),this.cubeBuffers.push(e),e=a.createFramebuffer(),a.bindFramebuffer(a.FRAMEBUFFER,e),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,d),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_Z,this.glTexture,0),this.cubeBuffers.push(e),a.bindRenderbuffer(a.RENDERBUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null),a.bindTexture(a.TEXTURE_CUBE_MAP,null)}}(GLGE),function(a){a.TextureCanvas=function(b){this.canvas=document.createElement("canvas"),this.t=document.createElement("canvas"),this.t.width=1,this.t.height=1,a.Assets.registerAsset(this,b)},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),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.t),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,b),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){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.Assets.registerAsset(this,b)},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){this.setMaterial(a.DEFAULT_MATERIAL),a.Assets.registerAsset(this,b)},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),this.mesh.removeEventListener("boundupdate",this.boundupdated));var c=this;this.meshupdated=function(a){c.GLShaderProgram=null},this.boundupdated=function(a){c.fireEvent("boundupdate",{})},b.addEventListener("shaderupdate",this.meshupdated),b.addEventListener("boundupdate",this.boundupdated),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){this.multimaterials=[],this.renderCaches=[];var c=this;this.downloadComplete=function(){c.isComplete()&&c.fireEvent("downloadComplete")},a.Assets.registerAsset(this,b)},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.visible=!0,a.Object.prototype.depthTest=!0,a.Object.prototype.meshFrame1=0,a.Object.prototype.meshFrame2=0,a.Object.prototype.meshBlendFactor=0,a.Object.prototype.noCastShadows=null,a.Object.prototype.noDepthMask=!1,a.Object.prototype.shadowAlpha=!0,a.Object.prototype.blending=["SRC_ALPHA","ONE_MINUS_SRC_ALPHA"];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;\n"),b.push("if(shadowtype) depth=length(eyevec)/distance;\n"),b.push("vec4 rgba=fract(depth * 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.noDepthMask,a.Object.prototype.setDepthMask=function(a){this.noDepthMask=!a;return this},a.Object.prototype.getDepthMask=function(){return!this.noDepthMask},a.Object.prototype.setVisible=function(a){this.visible=a;return this},a.Object.prototype.getVisible=function(){return this.visible},a.Object.prototype.setBlending=function(a){this.blending=a;return this},a.Object.prototype.getBlending=function(){return this.blending},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.getMeshBlendFactor=function(){return this.meshBlendFactor},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?f.push("attribute vec"+this.mesh.buffers[h].size+" "+this.mesh.buffers[h].name+";\n"):f.push("attribute float "+this.mesh.buffers[h].name+";\n"),this.mesh.buffers[h].name=="UV"&&(UV=!0),this.mesh.buffers[h].name=="color"&&(d=!0),this.mesh.buffers[h].name=="joints1"&&(joints1=this.mesh.buffers[h]),this.mesh.buffers[h].name=="joints2"&&(joints2=this.mesh.buffers[h])}if(this.mesh.framePositions.length>1){var i=!0;f.push("attribute vec3 position2;\n"),f.push("attribute vec3 normal2;\n"),f.push("uniform float framesBlend;\n"),g&&f.push("attribute vec3 tangent2;\n")}g&&f.push("attribute vec3 tangent;\n"),f.push("uniform mat4 worldView;\n"),f.push("uniform mat4 projection;\n"),f.push("uniform mat4 worldInverseTranspose;\n"),f.push("uniform mat4 envMat;\n"),f.push("uniform float cascadeLevel;\n");for(var h=0;h0&&f.push("uniform vec4 jointMat["+3*this.mesh.joints.length+"];\n"),this.material&&f.push(this.material.getVertexVarying(f)),f.push("varying vec3 n;\n"),f.push("varying vec3 t;\n"),d&&f.push("varying vec4 vcolor;\n"),f.push("varying vec4 UVCoord;\n"),f.push("varying vec3 OBJCoord;\n"),this.shaderVertexInjection&&f.push(this.shaderVertexInjection),f.push("void main(void)\n"),f.push("{\n"),d&&f.push("vcolor=color;\n"),UV?f.push("UVCoord=UV;\n"):f.push("UVCoord=vec4(0.0,0.0,0.0,0.0);\n"),f.push("OBJCoord = position;\n"),f.push("vec3 tang;\n"),f.push("vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n"),f.push("vec4 norm = vec4(0.0, 0.0, 0.0, 1.0);\n"),g&&f.push("vec4 tang4 = vec4(0.0, 0.0, 0.0, 1.0);\n");if(joints1){if(joints1.size==1)f.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"),f.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"),g&&f.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 h=0;h-1&&f.push("pos=GLGE_Position(vec4(pos.xyz, 1.0));\n"),f.push("pos = worldView * vec4(pos.xyz, 1.0);\n"),f.push("norm = worldInverseTranspose * vec4(norm.xyz, 1.0);\n"),g&&f.push("tang = (worldInverseTranspose*vec4(tang4.xyz,1.0)).xyz;\n")}else{i?f.push("vec4 pos4=vec4(mix(position,position2,framesBlend),1.0);\n"):f.push("vec4 pos4=vec4(position,1.0);\n"),this.shaderVertexInjection&&this.shaderVertexInjection.indexOf("GLGE_Position")>-1&&f.push("pos4=GLGE_Position(pos4);\n");for(var h=0;h>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(var i in this.uniforms){var j=this.uniforms[i];j.type=="Matrix4fv"?a.setUniformMatrix(b,"Matrix4fv",a.getUniformLocation(b,e,i),!1,j.value):a.setUniform(b,j.type,a.getUniformLocation(b,e,i),j.value)}e.caches||(e.caches={}),e.glarrays||(e.glarrays={});var k=e.caches,l=e.glarrays,m=b.scene,n=m.camera;k.far!=n.far&&(a.setUniform(b,"1i",a.getUniformLocation(b,e,"far"),n.far),k.far=n.far);if(c==a.RENDER_DEFAULT||c==a.RENDER_EMIT){if(k.ambientColor!=m.ambientColor){var o=m.ambientColor;a.setUniform3(b,"3f",a.getUniformLocation(b,e,"amb"),o.r,o.g,o.b),k.ambientColor=o}k.fogFar!=m.fogFar&&(a.setUniform(b,"1f",a.getUniformLocation(b,e,"fogfar"),m.fogFar),k.fogFar=m.fogFar),k.fogNear!=m.fogNear&&(a.setUniform(b,"1f",a.getUniformLocation(b,e,"fognear"),m.fogNear),k.fogNear=m.fogNear),k.fogType!=m.fogType&&(a.setUniform(b,"1i",a.getUniformLocation(b,e,"fogtype"),m.fogType),k.fogType=m.fogType),k.fogType!=m.fogcolor&&(a.setUniform3(b,"3f",a.getUniformLocation(b,e,"fogcolor"),m.fogColor.r,m.fogColor.g,m.fogColor.b),k.fogcolor=m.fogcolor)}k.meshBlendFactor!=this.meshBlendFactor&&(a.setUniform(b,"1f",a.getUniformLocation(b,e,"framesBlend"),this.meshBlendFactor),k.meshBlendFactor=this.meshBlendFactor);var p=n.getViewMatrix(),q=I=this.getModelMatrix();k.mvMatrix||(k.mvMatrix={cameraMatrix:null,modelMatrix:null});var r=k.mvMatrix;if(r.cameraMatrix!=p||r.modelMatrix!=I){this.caches.mvMatrix||(this.caches.mvMatrix=a.mulMat4(p,I)),mvMatrix=this.caches.mvMatrix,this.mesh.joints&&(mvMatrix=p);var s=a.getUniformLocation(b,e,"worldView"),t=a.transposeMat4(mvMatrix);l.mvMatrix?a.mat4gl(t,l.mvMatrixT):l.mvMatrixT=new Float32Array(t),l.mvMatrix=mvMatrix,a.setUniformMatrix(b,"Matrix4fv",s,!1,e.glarrays.mvMatrixT);var u=a.getUniformLocation(b,e,"envMat");if(u){if(!this.caches.envMat){var v=a.inverseMat4(p);v[3]=0,v[7]=0,v[11]=0,this.caches.envMat=v}v=this.caches.envMat,t=a.transposeMat4(v),e.glarrays.envMat?a.mat4gl(t,l.envMatT):l.envMatT=new Float32Array(t),l.envMat=v,a.setUniformMatrix(b,"Matrix4fv",u,!1,l.envMatT)}if(!this.caches.normalMatrix){var w=a.inverseMat4(mvMatrix);this.caches.normalMatrix=w}w=this.caches.normalMatrix;var x=a.getUniformLocation(b,e,"worldInverseTranspose");l.normalMatrix?a.mat4gl(w,l.normalMatrix):l.normalMatrix=new Float32Array(w),a.setUniformMatrix(b,"Matrix4fv",x,!1,l.normalMatrix);var y=a.getUniformLocation(b,e,"view");t=a.transposeMat4(p),l.cameraMatrix?a.mat4gl(t,l.cameraMatrixT):l.cameraMatrixT=new Float32Array(t),l.cameraMatrix=p,a.setUniformMatrix(b,"Matrix4fv",y,!1,l.cameraMatrixT),r.cameraMatrix=p,r.modelMatrix=I}var z=a.getUniformLocation(b,e,"projection");t=a.transposeMat4(n.getProjectionMatrix()),l.pMatrix?a.mat4gl(t,l.pMatrixT):l.pMatrixT=new Float32Array(t),l.pMatrix=n.getProjectionMatrix(),a.setUniformMatrix(b,"Matrix4fv",z,!1,l.pMatrixT);if(c==a.RENDER_DEFAULT||c==a.RENDER_SHADOW||c==a.RENDER_DEPTH||c==a.RENDER_EMIT){var A,B,C=b.lights;k.lights||(k.lights=[]),l.lights||(l.lights=[]),this.caches.lights||(this.caches.lights=[]);var D=k.lights;for(var E=0;E1&&!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;case a.DRAW_TRIANGLESTRIP:q=b.TRIANGLE_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.scene.renderer.cullFaces?(b.cullFace(b.scene.mirror?b.FRONT:b.BACK),b.enable(b.CULL_FACE)):b.disable(b.CULL_FACE);break;case a.Mesh.WINDING_ORDER_CLOCKWISE:b.cullFace(b.scene.mirror?b.FRONT:b.BACK),b.enable(b.CULL_FACE);break;case a.Mesh.WINDING_ORDER_COUNTER:b.cullFace(b.scene.mirror?b.BACK:b.FRONT),b.enable(b.CULL_FACE);default:}c==a.RENDER_PICK&&b.disable(b.CULL_FACE),this.noDepthMask&&b.depthMask(!1),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),b.depthMask(!0);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){this.canvas=document.createElement("canvas"),this.scaleCanvas=document.createElement("canvas"),this.color={r:1,g:1,b:1},a.Assets.registerAsset(this,b)},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.alpha=1,a.Text.prototype.dirty=!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.dirty=!0;return this},a.Text.prototype.getSize=function(){return this.size},a.Text.prototype.setSize=function(a){this.size=a,this.dirty=!0;return this},a.Text.prototype.getText=function(){return this.text},a.Text.prototype.setText=function(a){this.text=a,this.dirty=!0;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.setAlpha=function(a){this.alpha=a;return this},a.Text.prototype.getAlpha=function(){return this.alpha},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+"uniform mat4 Matrix;\n",d=d+"varying vec4 pos;\n",d=d+"uniform float far;\n",d=d+"uniform bool depthrender;\n",d=d+"uniform float distance;\n",d=d+"uniform int picktype;\n",d=d+"uniform vec3 pickcolor;\n",d=d+"uniform vec3 color;\n",d=d+"uniform float alpha;\n",d=d+"void main(void){\n",d=d+"float ob=pow(min(1.0,abs(dot(normalize(Matrix[2].rgb),vec3(0.0,0.0,1.0)))*2.0),1.5);\n",d=d+"float a=texture2D(TEXTURE,texcoord).a*alpha*ob;\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,a);};\n",d=d+"if (depthrender) { if(a<0.5) discard; float depth = gl_FragCoord.z / gl_FragCoord.w;\n",d=d+"vec4 rgba=fract(depth/distance * vec4(16777216.0, 65536.0, 256.0, 1.0));\n",d=d+"gl_FragColor=rgba-rgba.rrgb*vec4(0.0,0.00390625,0.00390625,0.00390625);}\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.dirty=!0},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.extra||"")+" "+this.size+"px "+this.font,this.aspect=b.width/b.height,c.fillText(this.text,0,0);var d=Math.pow(2,Math.ceil(Math.log(b.height))/Math.log(2)),e=Math.pow(2,Math.ceil(Math.log(b.width))/Math.log(2));this.scaleCanvas.height=d,this.scaleCanvas.width=e,this.scaleContext=this.scaleCanvas.getContext("2d"),this.scaleContext.clearRect(0,0,e,d),this.scaleContext.drawImage(b,0,0,e,d),a.bindTexture(a.TEXTURE_2D,this.glTexture);try{a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.scaleCanvas)}catch(f){a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,this.scaleCanvas,null)}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.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR_MIPMAP_LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.generateMipmap(a.TEXTURE_2D),a.bindTexture(a.TEXTURE_2D,null),this.dirty=!1},a.Text.prototype.GLRender=function(b,c,d){this.gl||this.GLInit(b),this.dirty&&this.updateCanvas(b);if(c==a.RENDER_DEFAULT||c==a.RENDER_PICK||c==a.RENDER_SHADOW){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);var j=b.scene.camera.getFar();a.setUniform(b,"1f",a.getUniformLocation(b,this.GLShaderProgram,"distance"),j),c==a.RENDER_SHADOW?a.setUniform(b,"1i",a.getUniformLocation(b,this.GLShaderProgram,"depthrender"),1):a.setUniform(b,"1i",a.getUniformLocation(b,this.GLShaderProgram,"depthrender"),0),this.GLShaderProgram.glarrays||(this.GLShaderProgram.glarrays={});var k=this.size/100,l=a.mulMat4(b.scene.camera.getViewMatrix(),a.mulMat4(this.getModelMatrix(),a.scaleMatrix(this.aspect*k,k,k))),m=a.getUniformLocation(b,this.GLShaderProgram,"Matrix");this.GLShaderProgram.glarrays.mMatrix?a.mat4gl(l,this.GLShaderProgram.glarrays.mMatrix):this.GLShaderProgram.glarrays.mMatrix=new Float32Array(l),a.setUniformMatrix(b,"Matrix4fv",m,!0,this.GLShaderProgram.glarrays.mMatrix);var m=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",m,!0,this.GLShaderProgram.glarrays.pMatrix);var n=a.getUniformLocation(b,this.GLShaderProgram,"far");a.setUniform(b,"1f",n,b.scene.camera.getFar());var o=a.getUniformLocation(b,this.GLShaderProgram,"alpha");a.setUniform(b,"1f",o,this.alpha),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([2,1,0,0,3,2]),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.gl||a.GLInit(this.gl),a.camera.updateMatrix();return this},a.Renderer.prototype.render=function(){if(this.transitonFilter){var a=+(new Date);if(ab[d]&&(b[d]=c[d])},a.Light.prototype.lightLook=function(b,c,d){var e=a.toUnitVec3(a.crossVec3(c,d)),f=a.toUnitVec3(a.crossVec3(e,c)),g=a.toUnitVec3(c),h=[];h[0]=e[0],h[4]=f[0],h[8]=-g[0],h[12]=0,h[1]=e[1],h[5]=f[1],h[9]=-g[1],h[13]=0,h[2]=e[2],h[6]=f[2],h[10]=-g[2],h[14]=0,h[3]=-a.dotVec3(e,b),h[7]=-a.dotVec3(f,b),h[11]=a.dotVec3(g,b),h[15]=1;return h},a.Light.prototype.transformPoints=function(b,c){var d=[];for(var e=0;e0&&e>0||d<0&&e<0)return!1;var f=a.subVec3(b[1],b[0]);f=a.scaleVec3(f,-d/(e-d));return a.addVec3(b[0],f)},a.Light.prototype.pointInPlanes=function(b,c){var d=-.001;for(var e=0;ed)return 1;if(cd)return 1;if(cd?1:c0){var p=this.passes.pop();b.bindFramebuffer(b.FRAMEBUFFER,p.frameBuffer),this.camera.matrix=p.cameraMatrix,this.camera.setProjectionMatrix(p.projectionMatrix),this.mirror=p.mirror,this.renderPass(b,d,0,0,p.width,p.height,a.RENDER_DEFAULT,p.self)}this.mirror=!1,this.camera.matrix=g,this.camera.setProjectionMatrix(h),b.bindFramebuffer(b.FRAMEBUFFER,this.filter?this.framebuffer:this.transbuffer),this.renderPass(b,d,this.renderer.getViewportOffsetX(),this.renderer.getViewportOffsetY(),this.renderer.getViewportWidth(),this.renderer.getViewportHeight()),this.applyFilter(b,d,this.transbuffer),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.program=this.program,a.useProgram(this.program),this.setAttributes(a),this.setUniforms(a),a.depthMask(!1),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.facesGL),a.drawElements(a.TRIANGLES,this.facesGL.num,a.UNSIGNED_SHORT,0),a.depthMask(!0),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.MD2AnimFinished=!1,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;d0&&this.addMD3Childred(),this.loaded=!0,this.fireEvent("loaded",{url:this.url})},a.MD3.prototype.addMD3Childred=function(){for(var a=0;a32768&&(b=b-65536);return b},a.MD3.prototype.getSint32At=function(a){var b=this.byteArray[a]|this.byteArray[a+1]<<8|this.byteArray[a+2]<<16|this.byteArray[a+3]<<24;b>2147483648&&(b=b-4294967296);return b},a.MD3.prototype.getFloat32At=function(a){var b=this.byteArray[a],c=this.byteArray[a+1],d=this.byteArray[a+2],e=this.byteArray[a+3];sign=1-2*(e>>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.MD3.prototype.getStringAt=function(a,b){var c="";for(var d=a;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.RGBA,a.canvas.width,a.canvas.height,0,a.RGBA,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;d lumaMax)) gl_FragColor = vec4(rgbA,1.0);"),c.push("\t else gl_FragColor = vec4(rgbB,1.0);"),c.push("\tif(length(rgbM)>"+this.fxaacutoff.toFixed(2)+") gl_FragColor = vec4(rgbM,1.0);"),c.push("\tif(length(rgbM)<"+this.fxaastartintensity.toFixed(2)+") gl_FragColor = vec4(rgbM,1.0);"),c.push("}"),this.addPass(c.join("\n"))}}}(GLGE),function(a){a.FilterAO=function(){this.setUniform("1f","cavitygamma",1/3),this.setUniform("1f","whiteMul",2),this.setUniform("1f","aogamma",1/3),this.setUniform("1f","maxDist",.025),this.passes=[]},a.augment(a.Filter2d,a.FilterAO),a.FilterAO.prototype.renderNormal=!0,a.FilterAO.prototype.quality=1,a.FilterAO.prototype.range=80,a.FilterAO.prototype.samples=16,a.FilterAO.prototype.useRender=!0,a.FilterAO.prototype.getNormalBufferHeight=function(){return this.normalBufferHeight?this.normalBufferHeight:this.gl.canvas.height*this.quality|0},a.FilterAO.prototype.getNormalBufferWidth=function(){return this.normalBufferWidth?this.normalBufferWidth:this.gl.canvas.width*this.quality|0},a.FilterAO.prototype.setUseRender=function(a){this.useRender=a,this.normalBuffers=null,this.passes=[];return this},a.FilterAO.prototype.setSamples=function(a){this.samples=a,this.normalBuffers=null,this.passes=[];return this},a.FilterAO.prototype.setQuality=function(a){this.quality=a,this.normalBuffers=null,this.passes=[];return this},a.FilterAO.prototype.setRange=function(a){this.range=a,this.gl&&(this.setUniform("1f","blurX",this.range/this.getNormalBufferWidth()*this.quality/this.samples),this.setUniform("1f","blurY",this.range/this.getNormalBufferHeight()/this.samples));return this},a.FilterAO.prototype.setCavityGamma=function(a){this.setUniform("1f","cavitygamma",1/a);return this},a.FilterAO.prototype.setAmbientMultiplier=function(a){this.setUniform("1f","whiteMul",a);return this},a.FilterAO.prototype.setAmbientGamma=function(a){this.setUniform("1f","aogamma",1/a);return this},a.FilterAO.prototype.setMaximumDistance=function(a){this.setUniform("1f","maxDist",a);return this},a.FilterAO.prototype.GLRender=function(b,c){this.gl=b,this.passes.length==0&&this.createPasses();return a.Filter2d.prototype.GLRender.call(this,b,c)},a.FilterAO.prototype.createPasses=function(){if(this.gl){var a=this.getNormalBufferWidth(),b=this.getNormalBufferHeight(),c=this.samples/4|0,d=[];for(var e=-c,f=0;e<=c;e++,f++){var g=c-Math.abs(e)+1;d[f]=g/(c*c+c)}d[c]=0,this.setUniform("1f","blurX",this.range/a*this.quality/this.samples),this.setUniform("1f","blurY",this.range/b/this.samples);var h=[];h.push("precision highp float;"),h.push("uniform sampler2D GLGE_NORMAL;"),h.push("uniform float maxDist;"),h.push("varying vec2 texCoord;"),h.push("uniform float blurX;"),h.push("float rand(vec2 co){"),h.push("return (fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453)-0.5)*2.0;"),h.push("}"),h.push("void main(void){"),h.push("vec4 n=texture2D(GLGE_NORMAL,texCoord.xy).rgba;"),h.push("vec4 color=vec4(0.0,0.0,0.0,n.a);"),h.push("float blurSize=blurX/(n.a*n.a+1.0);"),h.push("float offset=rand(texCoord.xy)*blurSize+texCoord.x;"),h.push("vec3 samp;"),h.push("float delta;");for(var e=-c,f=0;e<=c;e++,f++){if(e==0)continue;h.push("samp = texture2D(GLGE_NORMAL, vec2("+e+".0*blurSize+offset, texCoord.y)).rga;"),h.push("delta=abs(n.a-samp.b);"),h.push("if(delta lumaMax)) gl_FragColor = vec4(rgbA,1.0);"),j.push("\t else gl_FragColor = vec4(rgbB,1.0);"),j.push("\tif(length(rgbM)>10.0) gl_FragColor = vec4(rgbM,1.0);"),j.push("}"),this.passes=[],this.addPass(h.join(""),a,b),this.addPass(i.join("")),this.addPass(j.join("\n"))}}}(GLGE),typeof GLGE=="undefined"&&(GLGE={}),function(a){function c(a,b){var d=null;if(a.getAttribute("id")==b)return a;for(var e=0;e0&&(z[e].getElementsByTagName("p")[0].data=v)}var C=[],v=meshNode.getElementsByTagName("triangles");for(e=0;e0&&C.push(z[e]);for(e=0;eb?b:a}var M=21843;M*=3;var N=(l.length-l.length%M)/M+(l.length%M?1:0),O=[],P=3,Q=3,R=2;for(var S=0;S8){var T=[],U=[];for(var x=0;x0){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":m.firstChild.nodeValue<1&&(h.setAlpha(parseFloat(m.firstChild.nodeValue)),h.trans=!0);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]),h[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"?f.setRotMatrix(a.Mat4([0,-1,0,0,1,0,0,0,0,0,1,0,0,0,0,1])):f.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){this.multimaterials=[],this.materials={},this.instances=[],this.queue=[],this.idMaterials=[],a.Object.call(this,b),a.Assets.registerAsset(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,8)=="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){var c=0,d=0,e=0,f;while(d1)switch(g[0]){case"Kd":h.setColorR(parseFloat(g[1])),h.setColorG(parseFloat(g[2])),h.setColorB(parseFloat(g[3]));break;case"Ks":h.setSpecularColor({r:parseFloat(g[1]),g:parseFloat(g[2]),b:parseFloat(g[3])});break;case"Ns":h.setShininess(parseFloat(g[1]));break;case"d":this.setZtransparent(!0),h.setAlpha(parseFloat(g[1]));break;case"map_Kd":var i=new a.MaterialLayer;i.setMapto(a.M_COLOR),i.setMapinput(a.UV1);var j=new a.Texture,k=1;while(g[k][0]=="-")k=k+2;j.setSrc(this.getAbsolutePath(g[k],this.relativeTo)),h.addTexture(j),i.setTexture(j),h.addMaterialLayer(i);break;case"map_Ks":case"map_spec":var i=new a.MaterialLayer;i.setMapto(a.M_SPECULAR),i.setMapinput(a.UV1);var j=new a.Texture,k=1;while(g[k][0]=="-")k=k+2;j.setSrc(this.getAbsolutePath(g[k],this.relativeTo)),h.addTexture(j),i.setTexture(j),h.addMaterialLayer(i);break;case"bump":case"map_bump":var i=new a.MaterialLayer;i.setMapto(a.M_NOR),i.setMapinput(a.UV1);var j=new a.Texture,k=1;while(g[k][0]=="-")k=k+2;j.setSrc(this.getAbsolutePath(g[k],this.relativeTo)),h.addTexture(j),i.setTexture(j),h.addMaterialLayer(i)}c++;if(c>=b.length)break}d=c-1,this.materials[e]=h,this.idMaterials.push(f),e++}d++}},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,i){var j=[],k=[],l=[],m=[],n=[],o={};for(var p=0;p0)var s=n[p].split("/");else var s=[n[p]];d[s[0]-1]||a.error(s[0]),j.push(d[s[0]-1][1]),j.push(d[s[0]-1][2]),j.push(d[s[0]-1][3]),s[1]&&(l.push(f[s[1]-1][1]),l.push(f[s[1]-1][2])),s[2]&&(k.push(e[s[2]-1][1]),k.push(e[s[2]-1][2]),k.push(e[s[2]-1][3]))}if(j.length/3>65024){var t=[],u=[],v=[];for(var p=0;p0&&u.push(k[g[p]*3],k[g[p]*3+1],k[g[p]*3+2]),l.length>0&&v.push(l[g[p]*2],l[g[p]*2+1]);j=t,k=u,l=v,g=[]}var w=new a.MultiMaterial,x=new a.Mesh;x.setPositions(j),k.length>0&&x.setNormals(k),l.length>0&&x.setUV(l),g.length>0&&x.setFaces(g),w.setMesh(x),w.setMaterial(h),this.addMultiMaterial(w)},a.Wavefront.prototype.parseMesh=function(){objArray=this.file;var b=[],c=[],d=[],e=[],f=[],g={},h=0,i=!0,j=new a.Material;for(var k=0;k0)switch(l[0]){case"s":l[1]=="1"?i=!0:i=!1;case"o":e.length>0&&(this.createMultiMaterial(f,g,c,d,b,e,j,i),e=[],j=new a.Material);break;case"usemtl":e.length>0&&(this.createMultiMaterial(f,g,c,d,b,e,j,i),e=[]),this.idMaterials.indexOf(l[1])==-1?j=this.materials[0]:j=this.materials[this.idMaterials.indexOf(l[1])];break;case"v":c.push(l);break;case"vt":b.push(l);break;case"vn":d.push(l);break;case"f":var m=[];for(var n=1;n=this._windowSize&&(this._pos=0),this._streamPos=this._pos}},LZMA.OutWindow.prototype.releaseStream=function(){this.flush(),this._stream=null},LZMA.OutWindow.prototype.setStream=function(a){this.releaseStream(),this._stream=a},LZMA.OutWindow.prototype.init=function(a){a||(this._streamPos=0,this._pos=0)},LZMA.OutWindow.prototype.copyBlock=function(a,b){var c=this._pos-a-1;c<0&&(c+=this._windowSize);while(b--)c>=this._windowSize&&(c=0),this._buffer[this._pos++]=this._buffer[c++],this._pos>=this._windowSize&&this.flush()},LZMA.OutWindow.prototype.putByte=function(a){this._buffer[this._pos++]=a,this._pos>=this._windowSize&&this.flush()},LZMA.OutWindow.prototype.getByte=function(a){var b=this._pos-a-1;b<0&&(b+=this._windowSize);return this._buffer[b]},LZMA.RangeDecoder=function(){},LZMA.RangeDecoder.prototype.setStream=function(a){this._stream=a},LZMA.RangeDecoder.prototype.releaseStream=function(){this._stream=null},LZMA.RangeDecoder.prototype.init=function(){var a=5;this._code=0,this._range=-1;while(a--)this._code=this._code<<8|this._stream.readByte()},LZMA.RangeDecoder.prototype.decodeDirectBits=function(a){var b=0,c=a,d;while(c--)this._range>>>=1,d=this._code-this._range>>>31,this._code-=this._range&d-1,b=b<<1|1-d,(this._range&4278190080)===0&&(this._code=this._code<<8|this._stream.readByte(),this._range<<=8);return b},LZMA.RangeDecoder.prototype.decodeBit=function(a,b){var c=a[b],d=(this._range>>>11)*c;if((this._code^2147483648)<(d^2147483648)){this._range=d,a[b]+=2048-c>>>5,(this._range&4278190080)===0&&(this._code=this._code<<8|this._stream.readByte(),this._range<<=8);return 0}this._range-=d,this._code-=d,a[b]-=c>>>5,(this._range&4278190080)===0&&(this._code=this._code<<8|this._stream.readByte(),this._range<<=8);return 1},LZMA.initBitModels=function(a,b){while(b--)a[b]=1024},LZMA.BitTreeDecoder=function(a){this._models=[],this._numBitLevels=a},LZMA.BitTreeDecoder.prototype.init=function(){LZMA.initBitModels(this._models,1<>7&1,b<<=1,e=a.decodeBit(this._decoders,(1+d<<8)+c),c=c<<1|e;if(d!==e){while(c<256)c=c<<1|a.decodeBit(this._decoders,c);break}}while(c<256);return c&255},LZMA.LiteralDecoder=function(){},LZMA.LiteralDecoder.prototype.create=function(a,b){var c;if(!this._coders||this._numPrevBits!==b||this._numPosBits!==a){this._numPosBits=a,this._posMask=(1<>>8-this._numPrevBits)]},LZMA.Decoder=function(){this._outWindow=new LZMA.OutWindow,this._rangeDecoder=new LZMA.RangeDecoder,this._isMatchDecoders=[],this._isRepDecoders=[],this._isRepG0Decoders=[],this._isRepG1Decoders=[],this._isRepG2Decoders=[],this._isRep0LongDecoders=[],this._posSlotDecoder=[],this._posDecoders=[],this._posAlignDecoder=new LZMA.BitTreeDecoder(4),this._lenDecoder=new LZMA.LenDecoder,this._repLenDecoder=new LZMA.LenDecoder,this._literalDecoder=new LZMA.LiteralDecoder,this._dictionarySize=-1,this._dictionarySizeCheck=-1,this._posSlotDecoder[0]=new LZMA.BitTreeDecoder(6),this._posSlotDecoder[1]=new LZMA.BitTreeDecoder(6),this._posSlotDecoder[2]=new LZMA.BitTreeDecoder(6),this._posSlotDecoder[3]=new LZMA.BitTreeDecoder(6)},LZMA.Decoder.prototype.setDictionarySize=function(a){if(a<0)return!1;this._dictionarySize!==a&&(this._dictionarySize=a,this._dictionarySizeCheck=Math.max(this._dictionarySize,1),this._outWindow.create(Math.max(this._dictionarySizeCheck,4096)));return!0},LZMA.Decoder.prototype.setLcLpPb=function(a,b,c){var d=1<8||b>4||c>4)return!1;this._literalDecoder.create(b,a),this._lenDecoder.create(d),this._repLenDecoder.create(d),this._posStateMask=d-1;return!0},LZMA.Decoder.prototype.init=function(){var a=4;this._outWindow.init(!1),LZMA.initBitModels(this._isMatchDecoders,192),LZMA.initBitModels(this._isRep0LongDecoders,192),LZMA.initBitModels(this._isRepDecoders,12),LZMA.initBitModels(this._isRepG0Decoders,12),LZMA.initBitModels(this._isRepG1Decoders,12),LZMA.initBitModels(this._isRepG2Decoders,12),LZMA.initBitModels(this._posDecoders,114),this._literalDecoder.init();while(a--)this._posSlotDecoder[a].init();this._lenDecoder.init(),this._repLenDecoder.init(),this._posAlignDecoder.init(),this._rangeDecoder.init()},LZMA.Decoder.prototype.decode=function(a,b,c){var d=0,e=0,f=0,g=0,h=0,i=0,j=0,k,l,m,n,o,p;this._rangeDecoder.setStream(a),this._outWindow.setStream(b),this.init();while(c<0||i>1)-1,e=(2|o&1)<=i||e>=this._dictionarySizeCheck)return!1;this._outWindow.copyBlock(e,m),i+=m,j=this._outWindow.getByte(0)}}this._outWindow.flush(),this._outWindow.releaseStream(),this._rangeDecoder.releaseStream();return!0},LZMA.Decoder.prototype.setDecoderProperties=function(a){var b,c,d,e,f;if(a.size<5)return!1;b=a.readByte(),c=b%9,b=~~(b/9),d=b%5,e=~~(b/5);if(!this.setLcLpPb(c,d,e))return!1;f=a.readByte(),f|=a.readByte()<<8,f|=a.readByte()<<16,f+=a.readByte()*16777216;return this.setDictionarySize(f)},LZMA.decompress=function(a,b,c,d){var e=new LZMA.Decoder;if(!e.setDecoderProperties(a))throw"Incorrect stream properties";if(!e.decode(b,c,d))throw"Error in data stream";return!0},LZMA.decompressFile=function(a,b){var c=new LZMA.Decoder,d;if(!c.setDecoderProperties(a))throw"Incorrect stream properties";d=a.readByte(),d|=a.readByte()<<8,d|=a.readByte()<<16,d+=a.readByte()*16777216,a.readByte(),a.readByte(),a.readByte(),a.readByte();if(!c.decode(a,b,d))throw"Error in data stream";return!0};var CTM=CTM||{};CTM.CompressionMethod={RAW:5718354,MG1:3229517,MG2:3295053},CTM.Flags={NORMALS:1},CTM.File=function(a){this.load(a)},CTM.File.prototype.load=function(a){this.header=new CTM.FileHeader(a),this.body=new CTM.FileBody(this.header),this.getReader().read(a,this.body)},CTM.File.prototype.getReader=function(){var a;switch(this.header.compressionMethod){case CTM.CompressionMethod.RAW:a=new CTM.ReaderRAW;break;case CTM.CompressionMethod.MG1:a=new CTM.ReaderMG1;break;case CTM.CompressionMethod.MG2:a=new CTM.ReaderMG2}return a},CTM.FileHeader=function(a){a.readInt32(),this.fileFormat=a.readInt32(),this.compressionMethod=a.readInt32(),this.vertexCount=a.readInt32(),this.triangleCount=a.readInt32(),this.uvMapCount=a.readInt32(),this.attrMapCount=a.readInt32(),this.flags=a.readInt32(),this.comment=a.readString()},CTM.FileHeader.prototype.hasNormals=function(){return this.flags&CTM.Flags.NORMALS},CTM.FileBody=function(a){var b=a.triangleCount*3,c=a.vertexCount*3,d=a.hasNormals()?a.vertexCount*3:0,e=a.vertexCount*2,f=a.vertexCount*4,g=0,h=new ArrayBuffer((b+c+d+e*a.uvMapCount+f*a.attrMapCount)*4);this.indices=new Uint32Array(h,0,b),this.vertices=new Float32Array(h,b*4,c),a.hasNormals()&&(this.normals=new Float32Array(h,(b+c)*4,d));if(a.uvMapCount){this.uvMaps=[];for(g=0;g0&&(a[2]+=a[0]);for(;c4?f=(n[o+2]*4/e-2)*q:f=(n[o+2]-2)*q,e*=c*q,g=d*Math.sin(e),h=g*Math.cos(f),i=g*Math.sin(f),j=d*Math.cos(e),l=b[o+1],k=b[o]-b[o+2],m=Math.sqrt(2*l*l+k*k),m>1e-20&&(k/=m,l/=m),a[o]=b[o]*j+(b[o+1]*l-b[o+2]*k)*i-l*h,a[o+1]=b[o+1]*j-(b[o+2]+b[o])*l*i+k*h,a[o+2]=b[o+2]*j+(b[o]*k+b[o+1]*l)*i+l*h)},CTM.restoreMap=function(a,b,c){var d,e,f=new Uint32Array(a.buffer,a.byteOffset,a.length),g=0,h,i=a.length;for(;g>1):e>>1,a[h]=d*c}},CTM.calcSmoothNormals=function(a,b){var c=new Float32Array(b.length),d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;for(q=0,r=a.length;q1e-10&&(g/=p,h/=p,i/=p),c[d]+=g,c[d+1]+=h,c[d+2]+=i,c[e]+=g,c[e+1]+=h,c[e+2]+=i,c[f]+=g,c[f+1]+=h,c[f+2]+=i;for(q=0,r=c.length;q1e-10&&(c[q]/=p,c[q+1]/=p,c[q+2]/=p);return c},CTM.isLittleEndian=function(){var a=new ArrayBuffer(2),b=new Uint8Array(a),c=new Uint16Array(a);b[0]=1;return c[0]===1}(),CTM.InterleavedStream=function(a,b){this.data=new Uint8Array(a.buffer,a.byteOffset,a.byteLength),this.offset=CTM.isLittleEndian?3:0,this.count=b*4,this.len=this.data.length},CTM.InterleavedStream.prototype.writeByte=function(a){this.data[this.offset]=a,this.offset+=this.count,this.offset>=this.len&&(this.offset-=this.len-4,this.offset>=this.count&&(this.offset-=this.count+(CTM.isLittleEndian?1:-1)))},CTM.Stream=function(a){this.data=a,this.offset=0},CTM.Stream.prototype.TWO_POW_MINUS23=Math.pow(2,-23),CTM.Stream.prototype.TWO_POW_MINUS126=Math.pow(2,-126),CTM.Stream.prototype.readByte=function(){return this.data.charCodeAt(this.offset++)&255},CTM.Stream.prototype.readInt32=function(){var a=this.readByte();a|=this.readByte()<<8,a|=this.readByte()<<16;return a|this.readByte()<<24},CTM.Stream.prototype.readFloat32=function(){var a=this.readByte();a+=this.readByte()<<8;var b=this.readByte(),c=this.readByte();a+=(b&127)<<16;var d=(c&127)<<1|(b&128)>>>7,e=c&128?-1:1;if(d===255)return a!==0?NaN:e*Infinity;if(d>0)return e*(1+a*this.TWO_POW_MINUS23)*Math.pow(2,d-127);if(a!==0)return e*a*this.TWO_POW_MINUS126;return e*0},CTM.Stream.prototype.readString=function(){var a=this.readInt32();this.offset+=a;return this.data.substr(this.offset-a,a)},CTM.Stream.prototype.readArrayInt32=function(a){var b=0,c=a.length;while(b0&&(b=b.substr(0,b.indexOf("?")));var c=b.split("/"),d=c[2],e=c[0],f=[];for(var g=3;g65024){var g=[],h=[],i=[];for(var j=0;j0&&h.push(d[f[j]*3],d[f[j]*3+1],d[f[j]*3+2]),e.length>0&&i.push(e[f[j]*2],e[f[j]*2+1]);c=g,d=h,e=i,f=[]}var k=new a.Mesh;k.setPositions(c),d.length>0&&k.setNormals(d),e.length>0&&k.setUV(e),f.length>0&&k.setFaces(f),this.setMesh(k)},a.Document.prototype.getOpenCTM=function(b){if(!b.object){var c=this.getAbsolutePath(this.rootURL,null);b.object=new(a[this.classString(b.tagName)]),b.object.setSrc(b.getAttribute("src"),c),b.removeAttribute("src"),this.setProperties(b)}return b.object},a.Scene.prototype.addOpenCTM=a.Scene.prototype.addObject}(GLGE),function(a){a.Scene.prototype.physicsGravity=[0,0,-9.8,0],a.Scene.prototype.getPhysicsNodes=function(b){b||(b=[]),this.jigLibObj&&b.push(this);if(this.children)for(var c=0;c-1&&(this.constraints.push(a),this.physicsSystem&&this.physicsSystem.removeConstraint(a.constraint));return this}}(GLGE),function(a){a.PhysicsCar=function(b){a.PhysicsBox.call(this,b),this.wheels=[],this.setRotationalVelocityDamping([.1,.6,.1]),this.setLinearVelocityDamping([.996,.92,.996]);return this},a.augment(a.PhysicsBox,a.PhysicsCar),a.PhysicsCar.prototype.className="PhysicsCar",a.Group.prototype.addPhysicsCar=a.Group.prototype.addChild,a.Scene.prototype.addPhysicsCar=a.Group.prototype.addChild,a.PhysicsCar.prototype.drive=function(a){for(var b=0;b-1&&this.wheels.splice(c,1);return a.PhsyicsBox.prototype.addChild.call(this,b)},a.PhysicsCar.prototype.getScene=function(){var a=this;while(a.parent)a=a.parent;return a},a.PhysicsCar.prototype.preProcess=function(b){var c=this.getScene(),d=this.getVelocity(),e=this.getMass(),f=this.wheels;for(var g=0;gy&&(z=y)}if(h.driveForce){var B=h.driveForce*(1-h.braking);B<-x&&(B=x),B>x&&(B=x),this.addWorldForce(a.scaleVec3(l,B),m),z+=h.driveForce/e*b/n}if(h.braking){var C=a.dotVec3(d,l),D=-h.braking*C/b;D<-x&&(D=-x),D>x&&(D=x),this.addWorldForce(a.scaleVec3(l,D),m)}h.angVel+=z,h.brake&&(h.angVel*=1-h.braking),h.innerGroup.setRotZ(h.innerGroup.getRotZ()-h.angVel*b),h.angVel*=.995,h.oldPos=m}a.PhysicsBox.prototype.preProcess.call(this,b)},a.PhysicsWheel=function(b){a.Group.call(this,b),this.innerGroup=new a.Group,a.Group.prototype.addChild.call(this,this.innerGroup);return this},a.augment(a.Group,a.PhysicsWheel),a.PhysicsWheel.prototype.radius=1,a.PhysicsWheel.prototype.travel=.75,a.PhysicsWheel.prototype.angVel=0,a.PhysicsWheel.prototype.spring=90,a.PhysicsWheel.prototype.braking=0,a.PhysicsWheel.prototype.driveForce=0,a.PhysicsWheel.prototype.powered=!1,a.PhysicsWheel.prototype.sideFriction=3,a.PhysicsWheel.prototype.frontFriction=3,a.PhysicsWheel.prototype.className="PhysicsWheel",a.PhysicsWheel.prototype.addChild=function(a){return this.innerGroup.addChild(a)},a.PhysicsWheel.prototype.removeChild=function(a){return this.innerGroup.removeChild(a)},a.PhysicsWheel.prototype.addGroup=a.PhysicsWheel.prototype.addChild,a.PhysicsWheel.prototype.addCollada=a.PhysicsWheel.prototype.addChild,a.PhysicsWheel.prototype.addObject=a.PhysicsWheel.prototype.addChild,a.PhysicsWheel.prototype.addMD2=a.PhysicsWheel.prototype.addChild,a.PhysicsWheel.prototype.addMD3=a.PhysicsWheel.prototype.addChild,a.PhysicsWheel.prototype.addWavefront=a.PhysicsWheel.prototype.addChild,a.PhysicsWheel.prototype.setPowered=function(a){this.powered=a;return this},a.PhysicsWheel.prototype.setRadius=function(a){this.radius=a;return this},a.PhysicsWheel.prototype.setSpring=function(a){this.spring=a;return this},a.PhysicsWheel.prototype.setTravel=function(a){this.travel=a;return this},a.PhysicsWheel.prototype.setFrontFriction=function(a){this.frontFriction=a;return this},a.PhysicsWheel.prototype.setSideFriction=function(a){this.sideFriction=a;return this},a.PhysicsWheel.prototype.setWheelRotation=function(a){this.setRotY(a);return this},a.PhysicsWheel.prototype.getWheelRotation=function(a){return this.getRotY()},a.PhysicsWheel.prototype.getRadius=function(){return this.radius},a.PhysicsWheel.prototype.getSpring=function(){return this.spring},a.PhysicsWheel.prototype.getTravel=function(){return this.travel},a.PhysicsWheel.prototype.getFrontFriction=function(){return this.frontFriction},a.PhysicsWheel.prototype.getSideFriction=function(){return this.sideFriction},a.PhysicsWheel.prototype.drive=function(a){this.driveForce=a;return this},a.PhysicsWheel.prototype.brake=function(a){this.braking=a;return this}}(GLGE),function(a){a.FilePreloader=function(){this.files=[]},a.augment(a.Events,a.FilePreloader),a.FilePreloader.prototype.loadedBytes=0,a.FilePreloader.prototype.totalBytes=0,a.FilePreloader.prototype.numLoadedFiles=0,a.FilePreloader.prototype.numTotalFiles=0,a.FilePreloader.prototype.sizesCount=0,a.FilePreloader.prototype.progress=0,a.FilePreloader.prototype.files=null,a.FilePreloader.prototype.addFile=function(a,b,c){this.files.push({url:a,loaded:!1,size:-1,bytesLoaded:0,type:b,callback:c,content:null,preloader:this}),this.numTotalFiles++},a.FilePreloader.prototype.addFileRef=function(a){this.files.push(a),this.numTotalFiles++},a.FilePreloader.prototype.accumulateFileSize=function(a){var b=new XMLHttpRequest;b.preloader=this,b.active=!0,b.file=a,b.overrideMimeType("text/xml"),b.onreadystatechange=function(){this.readyState>1&&b.active&&(this.active=!1,this.file.size=parseFloat(this.getResponseHeader("Content-length")),this.preloader.totalBytes+=this.file.size,++this.preloader.sizesCount>=this.preloader.files.length&&this.preloader.loadFiles(),this.abort(),this.onreadystatechange=null)},b.open("GET",a.url,!0),b.send("")},a.FilePreloader.prototype.start=function(){for(i in this.files)this.accumulateFileSize(this.files[i])},a.FilePreloader.prototype.loadFiles=function(){for(i in this.files){var a=this.files[i];if(a.type=="image"){var b=new Image;a.content=b;var c=this;b.file=a,b.onload=function(){c.fileLoaded(this.file,this.file.size)},b.src=a.url}else{var d=new XMLHttpRequest;d.overrideMimeType("text/xml"),d.preloader=this,d.file=a;var e=setInterval(function(){if(d.readyState==3){var b=d.responseText.length-a.bytesLoaded;a.bytesLoaded=d.responseText.length,d.preloader.update(b)}},100);d.onreadystatechange=function(){if(this.readyState>=4){clearInterval(e),this.file.content=this.responseXML;var a=this.responseText.length-this.file.bytesLoaded;this.preloader.update(a),this.preloader.fileLoaded(this.file,a)}},d.open("GET",a.url,!0),d.send()}}},a.FilePreloader.prototype.update=function(a){this.loadedBytes+=a,this.progress=100*this.loadedBytes/this.totalBytes,this.fireEvent("progress",{progress:this.progress,stepBytes:a,loadedBytes:this.loadedBytes,totalBytes:this.totalBytes,loadedFiles:this.numLoadedFiles,totalFiles:this.numTotalFiles})},a.FilePreloader.prototype.fileLoaded=function(a,b){this.numLoadedFiles++,a.loaded=!0,a.bytesLoaded=a.size,this.numLoadedFiles0?(this.loadedBytes+=a.stepBytes,this.progress=this.XMLQuota*100*this.loadedBytes/this.XMLBytes):(this.progress+=this.XMLQuota*100/this.numXMLFiles,this.progress>this.XMLQuota*100&&(this.progress=this.XMLQuota*100)):this.progress=this.XMLQuota*100+this.imageQuota*this.imagePreloader.progress,this.fireEvent("progress",{progress:this.progress,stepBytes:a.stepBytes,loadedBytes:a.loadedBytes,totalBytes:a.totalBytes,loadedFiles:a.loadedFiles,totalFiles:a.totalFiles})},a.DocumentPreloader.prototype.loadXMLFile=function(b){this.changeState(1);var c=new a.FilePreloader;c.addFile(b,"xml");var d=this;this.XMLBytes>0?c.addEventListener("progress",function(a){d.updateProgress.call(d,a)}):c.addEventListener("downloadComplete",function(a){d.updateProgress.call(d,a)});var e=this.document;c.addEventListener("fileLoaded",function(a){a.file.content.getElementById=e.getElementById,e.loaded(a.file.url,a.file.content),d.fireEvent("fileLoaded",a.file)}),c.start()},a.DocumentPreloader.prototype.changeState=function(a){this.state=a,this.fireEvent("stateChange",a)},a.DocumentPreloader.prototype.finish=function(a){this.changeState(3),this.progress=100,this.fireEvent("downloadComplete")}}(GLGE),function(a){typeof a.GUI=="undefined"&&(a.GUI={}),function(b){b.useLibrary=function(a){a=="jQuery"&&jQuery&&(b.Progressbar.prototype.setValue=function(a){$(this.domRoot).progressbar({value:a})},b.Progressbar.prototype.init=function(){$(this.domRoot).progressbar({value:0})})},b.Widget=function(){this.domRoot=document.createElement("div"),this.domRoot.setAttribute("class","glge-gui-widget-root"),this.init()},b.Widget.prototype.domRoot=null,b.Widget.prototype.init=function(){},b.Progressbar=function(){this.baseclass.call(this),this.domRoot.className+=" glge-gui-progressbar"},b.Progressbar.prototype.value=0,b.Progressbar.prototype.setValue=function(a){this.value=a},a.augment(b.Widget,b.Progressbar)}(a.GUI)}(GLGE),function(a){typeof a.GUI=="undefined"&&(a.GUI={}),function(a){a.Gadget=function(){this.domGadgetRoot=document.createElement("div"),this.domGadgetRoot.setAttribute("class","glge-gui-gadget-root"),this.domGadgetRoot.style.position="absolute",this.domGadgetRoot.style.top="0px",this.domGadgetOuterWrapper=document.createElement("div"),this.domGadgetOuterWrapper.setAttribute("class","glge-gui-gadget-OuterWrapper"),this.domGadgetOuterWrapper.style.position="relative",this.domGadgetRoot.appendChild(this.domGadgetOuterWrapper),this.domGadgetInnerWrapper=document.createElement("div"),this.domGadgetInnerWrapper.setAttribute("class","glge-gui-gadget-InnerWrapper"),this.domGadgetInnerWrapper.style.position="relative",this.domGadgetOuterWrapper.appendChild(this.domGadgetInnerWrapper),this.domGadgetObject=document.createElement("div"),this.domGadgetObject.setAttribute("class","glge-gui-gadget"),this.domGadgetObject.style.position="relative",this.domGadgetInnerWrapper.appendChild(this.domGadgetObject),this.domGadgetFooter=document.createElement("div"),this.domGadgetFooter.setAttribute("class","glge-gui-gadget-footer"),this.domGadgetFooter.style.clear="both",this.domGadgetRoot.appendChild(this.domGadgetFooter),this.position={},this.position.x="middle",this.position.y="middle",this.updatePosition()},a.Gadget.prototype.domGadgetRoot=null,a.Gadget.prototype.domGadgetOuterWrapper=null,a.Gadget.prototype.domGadgetInnerWrapper=null,a.Gadget.prototype.domGadgetObject=null,a.Gadget.prototype.domGadgetFooter=null,a.Gadget.prototype.domGadgetParent=null,a.Gadget.prototype.position=null,a.Gadget.prototype.setPosition=function(a){a&&(a.x&&(this.position.x=a.x),a.y&&(this.position.y=a.y)),this.updatePosition()},a.Gadget.prototype.updatePosition=function(){if(this.domGadgetParent){var a="";document.defaultView&&document.defaultView.getComputedStyle?a=document.defaultView.getComputedStyle(this.domGadgetParent,null).getPropertyValue("position"):this.domGadgetParent.currentStyle&&(a=this.domGadgetParent.currentStyle.position),a=="absolute"?(this.domGadgetRoot.style.width="100%",this.domGadgetRoot.style.height="100%",this.domGadgetRoot.style.display="table",this.domGadgetOuterWrapper.style.display="table-cell",this.position.y=="top"?this.domGadgetOuterWrapper.style.verticalAlign="top":this.position.y=="middle"?this.domGadgetOuterWrapper.style.verticalAlign="middle":this.position.y=="bottom"&&(this.domGadgetOuterWrapper.style.verticalAlign="bottom"),this.position.x=="left"?(this.domGadgetInnerWrapper.style.cssFloat="left",this.domGadgetInnerWrapper.style.left="0px",this.domGadgetObject.style.cssFloat="left",this.domGadgetObject.style.left="0px"):this.position.x=="middle"?(this.domGadgetInnerWrapper.style.cssFloat="right",this.domGadgetInnerWrapper.style.right="50%",this.domGadgetObject.style.cssFloat="left",this.domGadgetObject.style.right="-50%"):this.position.x=="right"&&(this.domGadgetInnerWrapper.style.cssFloat="right",this.domGadgetInnerWrapper.style.right="0px",this.domGadgetObject.style.cssFloat="right",this.domGadgetObject.style.right="0px")):(this.position.y=="top"?this.domGadgetRoot.style.top=this.domGadgetParent.offsetTop:this.position.y=="middle"?this.domGadgetRoot.style.top=this.domGadgetParent.offsetTop+this.domGadgetParent.offsetHeight/2-this.domGadgetRoot.offsetHeight/2:this.position.y=="bottom"&&(this.domGadgetRoot.style.top=this.domGadgetParent.offsetTop+this.domGadgetParent.offsetHeight-this.domGadgetRoot.offsetHeight),this.position.x=="left"?this.domGadgetRoot.style.left=this.domGadgetParent.offsetLeft:this.position.x=="middle"?this.domGadgetRoot.style.left=this.domGadgetParent.offsetLeft+this.domGadgetParent.offsetWidth/2-this.domGadgetRoot.offsetWidth/2:this.position.x=="right"&&(this.domGadgetRoot.style.left=this.domGadgetParent.offsetLeft+this.domGadgetParent.offsetWidth-this.domGadgetRoot.offsetWidth))}},a.Gadget.prototype.addToDOM=function(a,b){this.domGadgetParent=a,this.domGadgetParent.appendChild(this.domGadgetRoot),this.setPosition(b)}}(a.GUI)}(GLGE),function(a){(function(b){b.Preloader=function(){this.baseclass.call(this),this.domGadgetObject.innerHTML="

Loading

",this.domGadgetObject.className+=" glge-gui-gadget-preloader",this.progressBar=new b.Progressbar,this.domGadgetObject.appendChild(this.progressBar.domRoot),this.domPercentageLabel=document.createElement("div"),this.domPercentageLabel.setAttribute("class","glge-gui-gadget-preloader-percentage"),this.domPercentageLabel.innerHTML="
0%
100%
",this.domGadgetObject.appendChild(this.domPercentageLabel),this.domInfoBox=document.createElement("div"),this.domInfoBox.setAttribute("class","glge-gui-gadget-preloader-info"),this.domInfoBox.setAttribute("style","clear:both;"),this.domGadgetObject.appendChild(this.domInfoBox),this.domStateLabel=document.createElement("div"),this.domInfoBox.appendChild(this.domStateLabel),this.domBytesLabel=document.createElement("div"),this.domInfoBox.appendChild(this.domBytesLabel),this.domFilesLabel=document.createElement("div"),this.domInfoBox.appendChild(this.domFilesLabel),this.domLastFileLabel=document.createElement("div"),this.domInfoBox.appendChild(this.domLastFileLabel)},b.Preloader.prototype.progressBar=null,b.Preloader.prototype.documentLoader=null,b.Preloader.prototype.domInfoBox=null,b.Preloader.prototype.domStateLabel=null,b.Preloader.prototype.domBytesLabel=null,b.Preloader.prototype.domFilesLabel=null,b.Preloader.prototype.domLastFileLabel=null,b.Preloader.prototype.domPercentageLabel=null,b.Preloader.prototype.setDocumentLoader=function(a){this.documentLoader=a;var b=this;this.documentLoader.addEventListener("downloadComplete",function(a){b.complete(a)}),this.documentLoader.addEventListener("progress",function(a){b.progress(a)}),this.documentLoader.addEventListener("stateChange",function(a){b.stateChange(a)}),this.documentLoader.addEventListener("fileLoaded",function(a){b.fileLoaded(a)})},b.Preloader.prototype.addToDOM=function(a,b){this.stateChange(this.documentLoader.state),this.progress({progress:0,loadedBytes:0,loadedFiles:0,totalFiles:0,totalBytes:0}),this.fileLoaded({}),this.baseclass.addToDOM.call(this,a,b)},b.Preloader.prototype.progress=function(a){this.progressBar.setValue(a.progress),this.domBytesLabel.innerHTML=a.loadedBytes+" of "+a.totalBytes+" Bytes loaded",this.domFilesLabel.innerHTML=a.loadedFiles+" of "+a.totalFiles+" Files loaded"},b.Preloader.prototype.complete=function(a){this.progressBar.setValue(100);var b=this;setTimeout(function(){b.domGadgetRoot.parentNode.removeChild(b.domGadgetRoot)},300)},b.Preloader.prototype.stateChange=function(a){switch(a){case 0:case 1:this.domStateLabel.innerHTML="Step 1 of 2: Loading XML";break;case 2:case 3:this.domStateLabel.innerHTML="Step 2 of 2: Loading Textures"}},b.Preloader.prototype.fileLoaded=function(a){if(a.url){var b=a.url;b.length>40&&(b=b.slice(-37),b="..."+b),this.domLastFileLabel.innerHTML='Last file loaded: "'+b+'"'}else this.domLastFileLabel.innerHTML==""&&(this.domLastFileLabel.innerHTML="Last file loaded: none")},a.augment(b.Gadget,b.Preloader)})(a.GUI)}(GLGE) \ No newline at end of file +if(typeof GLGE=="undefined"){GLGE={}}(function(e){function n(){var t=e.Vec([1,2,3,4]);var n=e.Vec4(e.getVec4(t,3),e.get1basedVec4(t,3),e.getVec4(t,1),e.getVec4(t,0));var r=e.identMatrix();var i=e.mulMat4Vec4(r,n);if(e.getVec4(i,0)!=4||e.getVec4(i,1)!=3||e.getVec4(i,2)!=2||e.getVec4(i,3)!=1){throw"Unit Test 1 failed MatVecMul "+i}var s=e.Mat4([3,4,5,0,.5,.75,0,0,.75,.5,0,0,.25,.25,1,1]);var o=e.Mat4([2,1,8,2,1,4,3,2,1,.5,6.5,2,8,3,1,.25]);var u=e.mulMat4(s,o);var a=e.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 f=0;f<4;++f){for(var l=0;l<4;++l){var c=e.getMat4(u,f,l)-e.getMat4(a,f,l);if(c<1e-6&&c>-1e-6){}else{throw"Unit Test 1 failed Multiplication "+e.getMat4(u,f,l)+" != "+e.getMat4(a,f,l)}}}var h=e.inverseMat4(s);var p=e.mulMat4(s,h);var d=e.mulMat4(h,s);for(var f=0;f<4;++f){for(var l=0;l<4;++l){var c=e.getMat4(p,f,l)-e.getMat4(r,f,l);if(c<1e-4&&c>-1e-4){}else{throw"Unit Test 1 failed Inverse "+e.getMat4(p,f,l)+" != "+e.getMat4(r,f,l)}}}}var t=[];e.reuseMatrix4=function(e){};e.matrix4=function(e,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m){if(t.length==0){var g=[e,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m]}else{var g=t.shift();g[0]=e;g[1]=n;g[2]=r;g[3]=i;g[4]=s;g[5]=o;g[6]=u;g[7]=a;g[8]=f;g[9]=l;g[10]=c;g[11]=h;g[12]=p;g[13]=d;g[14]=v;g[15]=m}return g};e.Vec=function(e){return e.slice(0)};e.Vec3=function(e,t,n){return[e,t,n]};e.Vec4=function(e,t,n,r){return[e,t,n,r]};e.get1basedVec4=function(e,t){return e[t-1]};e.get1basedVec3=function(e,t){return e[t-1]};e.getVec4=function(e,t){return e[t]};e.getVec3=function(e,t){return e[t]};e.addVec4=function(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2],e[3]+t[3]]};e.addVec3=function(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]};e.subVec4=function(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2],e[3]-t[3]]};e.subVec3=function(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]};e.negVec4=function(e){return[-e[0],-e[1],-e[2],-e[3]]};e.negVec3=function(e){return[-e[0],-e[1],-e[2]]};e.dotVec3=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]};e.dotVec4=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]};e.scaleVec4=function(e,t){return[e[0]*t,e[1]*t,e[2]*t,e[3]*t]};e.scaleVec3=function(e,t){return[e[0]*t,e[1]*t,e[2]*t]};e.crossVec3=function(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]};e.toUnitVec3=function(e){var t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2];var n=1;if(t>0){n=Math.pow(t,.5)}return[e[0]/n,e[1]/n,e[2]/n]};e.toUnitVec4=function(e){var t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2]+e[3]*e[3];var n=1;if(t>0){n=Math.pow(t,.5)}return[e[0]/n,e[1]/n,e[2]/n,e[3]/n]};e.lengthVec3=function(e){return Math.pow(e[0]*e[0]+e[1]*e[1]+e[2]*e[2],.5)};e.distanceVec3=function(t,n){return e.lengthVec3(e.subVec3(t,n))};e.lengthVec4=function(e,t){return Math.pow(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]+e[3]*e[3],.5)};e.distanceVec4=function(t,n){return e.lengthVec4(e.subVec4(t,n))};e.angleVec3=function(t,n){t=e.toUnitVec3(t);n=e.toUnitVec3(n);d=e.dotVec3(t,n);if(d<-1)d=-1;if(d>1)d=1;return Math.acos(d)};e.angleVec4=function(t,n){t=e.toUnitVec4(t);n=e.toUnitVec4(n);d=e.dotVec4(t,n);if(d<-1)d=-1;if(d>1)d=1;return Math.acos(d)};GLGE_math_use_webgl_float=false;e.Mat3=GLGE_math_use_webgl_float?function(e){if(e.length==9){return new Float32Array(e)}else if(e.length==16){return new Float32Array([e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]])}else{throw"invalid matrix length"}}:function(e){var t;if(e.length==9){t=e.slice(0)}else if(e.length==16){t=[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]]}else{throw"invalid matrix length"}t.get=function(e){return this[e]};return t};e.Mat=GLGE_math_use_webgl_float?function(e){return new Float32Array(e)}:function(e){var t=e.slice(0);t.get=function(e){return this[e]};return t};e.Mat4=function(e){var t;if(e.length==9){t=[e[0],e[1],e[2],0,e[3],e[4],e[5],0,e[6],e[7],e[8],0,0,0,0,1]}else if(e.length==16){if(e.slice)t=e.slice(0);else t=e.subarray(0)}else{throw"invalid matrix length"}t.get=function(e){return this[e]};return t};e.determinantMat4=function(e){return e[12]*e[9]*e[6]*e[3]-e[8]*e[13]*e[6]*e[3]-e[12]*e[5]*e[10]*e[3]+e[4]*e[13]*e[10]*e[3]+e[8]*e[5]*e[14]*e[3]-e[4]*e[9]*e[14]*e[3]-e[12]*e[9]*e[2]*e[7]+e[8]*e[13]*e[2]*e[7]+e[12]*e[1]*e[10]*e[7]-e[0]*e[13]*e[10]*e[7]-e[8]*e[1]*e[14]*e[7]+e[0]*e[9]*e[14]*e[7]+e[12]*e[5]*e[2]*e[11]-e[4]*e[13]*e[2]*e[11]-e[12]*e[1]*e[6]*e[11]+e[0]*e[13]*e[6]*e[11]+e[4]*e[1]*e[14]*e[11]-e[0]*e[5]*e[14]*e[11]-e[8]*e[5]*e[2]*e[15]+e[4]*e[9]*e[2]*e[15]+e[8]*e[1]*e[6]*e[15]-e[0]*e[9]*e[6]*e[15]-e[4]*e[1]*e[10]*e[15]+e[0]*e[5]*e[10]*e[15]};e.inverseMat4=function(t){var n=t[0],r=t[1],i=t[2],s=t[3];var o=t[4],u=t[5],a=t[6],f=t[7];var l=t[8],c=t[9],h=t[10],p=t[11];var d=t[12],v=t[13],m=t[14],g=t[15];var y=d*c*a*s-l*v*a*s-d*u*h*s+o*v*h*s+l*u*m*s-o*c*m*s-d*c*i*f+l*v*i*f+d*r*h*f-n*v*h*f-l*r*m*f+n*c*m*f+d*u*i*p-o*v*i*p-d*r*a*p+n*v*a*p+o*r*m*p-n*u*m*p-l*u*i*g+o*c*i*g+l*r*a*g-n*c*a*g-o*r*h*g+n*u*h*g;return e.matrix4((c*m*f-v*h*f+v*a*p-u*m*p-c*a*g+u*h*g)/y,(v*h*s-c*m*s-v*i*p+r*m*p+c*i*g-r*h*g)/y,(u*m*s-v*a*s+v*i*f-r*m*f-u*i*g+r*a*g)/y,(c*a*s-u*h*s-c*i*f+r*h*f+u*i*p-r*a*p)/y,(d*h*f-l*m*f-d*a*p+o*m*p+l*a*g-o*h*g)/y,(l*m*s-d*h*s+d*i*p-n*m*p-l*i*g+n*h*g)/y,(d*a*s-o*m*s-d*i*f+n*m*f+o*i*g-n*a*g)/y,(o*h*s-l*a*s+l*i*f-n*h*f-o*i*p+n*a*p)/y,(l*v*f-d*c*f+d*u*p-o*v*p-l*u*g+o*c*g)/y,(d*c*s-l*v*s-d*r*p+n*v*p+l*r*g-n*c*g)/y,(o*v*s-d*u*s+d*r*f-n*v*f-o*r*g+n*u*g)/y,(l*u*s-o*c*s-l*r*f+n*c*f+o*r*p-n*u*p)/y,(d*c*a-l*v*a-d*u*h+o*v*h+l*u*m-o*c*m)/y,(l*v*i-d*c*i+d*r*h-n*v*h-l*r*m+n*c*m)/y,(d*u*i-o*v*i-d*r*a+n*v*a+o*r*m-n*u*m)/y,(o*c*i-l*u*i+l*r*a-n*c*a-o*r*h+n*u*h)/y)};e.mulMat4Vec3=function(t,n){return e.Vec3(t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3],t[4]*n[0]+t[5]*n[1]+t[6]*n[2]+t[7],t[8]*n[0]+t[9]*n[1]+t[10]*n[2]+t[11])};e.mulMat4Vec4=function(t,n){return e.Vec4(t[0]*n[0]+t[1]*n[1]+t[2]*n[2]+t[3]*n[3],t[4]*n[0]+t[5]*n[1]+t[6]*n[2]+t[7]*n[3],t[8]*n[0]+t[9]*n[1]+t[10]*n[2]+t[11]*n[3],t[12]*n[0]+t[13]*n[1]+t[14]*n[2]+t[15]*n[3])};e.scaleMat4=function(t,n){return e.matrix4([t[0]*n,t[1]*n,t[2]*n,t[3]*n,t[4]*n,t[5]*n,t[6]*n,t[7]*n,t[8]*n,t[9]*n,t[10]*n,t[11]*n,t[12]*n,t[13]*n,t[14]*n,t[15]*n])};e.scaleInPlaceMat4=function(e,t){e.set(0,e[0]*t);e.set(1,e[1]*t);e.set(2,e[2]*t);e.set(3,e[3]*t);e.set(4,e[4]*t);e.set(5,e[5]*t);e.set(6,e[6]*t);e.set(7,e[7]*t);e.set(8,e[8]*t);e.set(9,e[9]*t);e.set(10,e[10]*t);e.set(11,e[11]*t);e.set(12,e[12]*t);e.set(13,e[13]*t);e.set(14,e[14]*t);e.set(15,e[15]*t);return e};e.addInPlaceMat4=function(e,t){e.set(0,e[0]+t[0]);e.set(1,e[1]+t[1]);e.set(2,e[2]+t[2]);e.set(3,e[3]+t[3]);e.set(4,e[4]+t[4]);e.set(5,e[5]+t[5]);e.set(6,e[6]+t[6]);e.set(7,e[7]+t[7]);e.set(8,e[8]+t[8]);e.set(9,e[9]+t[9]);e.set(10,e[10]+t[10]);e.set(11,e[11]+t[11]);e.set(12,e[12]+t[12]);e.set(13,e[13]+t[13]);e.set(14,e[14]+t[14]);e.set(15,e[15]+t[15]);return e};e.addMat4=function(t,n){return e.Mat([t[0]+n[0],t[1]+n[1],t[2]+n[2],t[3]+n[3],t[4]+n[4],t[5]+n[5],t[6]+n[6],t[7]+n[7],t[8]+n[8],t[9]+n[9],t[10]+n[10],t[11]+n[11],t[12]+n[12],t[13]+n[13],t[14]+n[14],t[15]+n[15]]);return t};e.subInPlaceMat4=function(e,t){e.set(0,e[0]-t[0]);e.set(1,e[1]-t[1]);e.set(2,e[2]-t[2]);e.set(3,e[3]-t[3]);e.set(4,e[4]-t[4]);e.set(5,e[5]-t[5]);e.set(6,e[6]-t[6]);e.set(7,e[7]-t[7]);e.set(8,e[8]-t[8]);e.set(9,e[9]-t[9]);e.set(10,e[10]-t[10]);e.set(11,e[11]-t[11]);e.set(12,e[12]-t[12]);e.set(13,e[13]-t[13]);e.set(14,e[14]-t[14]);e.set(15,e[15]-t[15]);return e};e.subMat4=function(t,n){return e.Mat([t[0]-n[0],t[1]-n[1],t[2]-n[2],t[3]-n[3],t[4]-n[4],t[5]-n[5],t[6]-n[6],t[7]-n[7],t[8]-n[8],t[9]-n[9],t[10]-n[10],t[11]-n[11],t[12]-n[12],t[13]-n[13],t[14]-n[14],t[15]-n[15]]);return t};e.mulMat4=function(t,n){var r=n[0],i=n[1],s=n[2],o=n[3];var u=n[4],a=n[5],f=n[6],l=n[7];var c=n[8],h=n[9],p=n[10],d=n[11];var v=n[12],m=n[13],g=n[14],y=n[15];var b=t[0],w=t[1],E=t[2],S=t[3];var x=t[4],T=t[5],N=t[6],C=t[7];var k=t[8],L=t[9],A=t[10],O=t[11];var M=t[12],_=t[13],D=t[14],P=t[15];return e.matrix4(b*r+w*u+E*c+S*v,b*i+w*a+E*h+S*m,b*s+w*f+E*p+S*g,b*o+w*l+E*d+S*y,x*r+T*u+N*c+C*v,x*i+T*a+N*h+C*m,x*s+T*f+N*p+C*g,x*o+T*l+N*d+C*y,k*r+L*u+A*c+O*v,k*i+L*a+A*h+O*m,k*s+L*f+A*p+O*g,k*o+L*l+A*d+O*y,M*r+_*u+D*c+P*v,M*i+_*a+D*h+P*m,M*s+_*f+D*p+P*g,M*o+_*l+D*d+P*y)};e.transposeInPlaceMat4=function(e){var t=e[1];e.set(1,e[4]);e.set(4,t);t=e[8];e.set(8,e[2]);e.set(2,t);t=e[3];e.set(3,e[12]);e.set(12,t);t=e[9];e.set(9,e[6]);e.set(6,t);t=e[13];e.set(13,e[7]);e.set(7,t);t=e[14];e.set(14,e[11]);e.set(11,t)};e.transposeMat4=function(t){return e.matrix4(t[0],t[4],t[8],t[12],t[1],t[5],t[9],t[13],t[2],t[6],t[10],t[14],t[3],t[7],t[11],t[15])};e.mat4gl=function(e,t){t[0]=e[0];t[1]=e[1];t[2]=e[2];t[3]=e[3];t[4]=e[4];t[5]=e[5];t[6]=e[6];t[7]=e[7];t[8]=e[8];t[9]=e[9];t[10]=e[10];t[11]=e[11];t[12]=e[12];t[13]=e[13];t[14]=e[14];t[15]=e[15]};e.set1basedMat4=function(e,t,n,r){e[(t-1)*4+(n-1)]=r;if(e.glData!==undefined){delete e.glData}};e.setMat4=function(e,t,n,r){e[t*4+n]=r;if(e.glData!==undefined){delete e.glData}};e.get1basedMat4=function(e,t,n){return e.get((t-1)*4+(n-1))};e.getMat4=function(e,t,n){return e[t*4+n]};e.glDataMat4=function(e){e.glArray=new Float32Array(e);return e.glArray};e.identMatrix=function(){return e.matrix4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)};e.translateMatrix=function(t){var n;var r;var i;if(arguments.length==3){n=arguments[0];r=arguments[1];i=arguments[2]}else if(t.data){n=t.data[0];r=t.data[1];i=t.data[2]}else if(t instanceof Array){n=t[0];r=t[1];i=t[2]}return e.matrix4(1,0,0,n,0,1,0,r,0,0,1,i,0,0,0,1)};e.scaleMatrix=function(t){var n;var r;var i;if(arguments.length==3){n=arguments[0];r=arguments[1];i=arguments[2]}else if(t.data){n=t.data[0];r=t.data[1];i=t.data[2]}else if(t instanceof Array){n=t[0];r=t[1];i=t[2]}return e.matrix4(n,0,0,0,0,r,0,0,0,0,i,0,0,0,0,1)};e.ROT_XYZ=1;e.ROT_XZY=2;e.ROT_YXZ=3;e.ROT_YZX=4;e.ROT_ZXY=5;e.ROT_ZYX=6;e.rotateMatrix=function(t,n){var r;var i;var s;if(arguments.length>2){r=arguments[0];i=arguments[1];s=arguments[2];n=arguments[3]}else if(t.data){r=t.data[0];i=t.data[1];s=t.data[2]}else if(t instanceof Array){r=t[0];i=t[1];s=t[2]}if(!n)n=e.ROT_XYZ;var o=Math.cos(r);var u=Math.sin(r);var a=Math.cos(i);var f=Math.sin(i);var l=Math.cos(s);var c=Math.sin(s);var h=e.matrix4(1,0,0,0,0,o,-u,0,0,u,o,0,0,0,0,1);var p=e.matrix4(a,0,f,0,0,1,0,0,-f,0,a,0,0,0,0,1);var d=e.matrix4(l,-c,0,0,c,l,0,0,0,0,1,0,0,0,0,1);switch(n){case e.ROT_XYZ:return e.mulMat4(h,e.mulMat4(p,d));break;case e.ROT_XZY:return e.mulMat4(h,e.mulMat4(d,p));break;case e.ROT_YXZ:return e.mulMat4(p,e.mulMat4(h,d));break;case e.ROT_YZX:return e.mulMat4(p,e.mulMat4(d,h));break;case e.ROT_ZXY:return e.mulMat4(d,e.mulMat4(h,p));break;case e.ROT_ZYX:return e.mulMat4(d,e.mulMat4(p,h));break}};e.angleAxis=function(t,n){var r,i,s,o,u,a,f,l,c;n=[n[0],n[1],n[2],0];var h=n[0];var p=n[1];var d=n[2];var v=Math.cos(t);var m=1-v;var g=Math.sin(t);f=h*g;l=p*g;c=d*g;r=h*h;i=p*p;s=d*d;o=h*p;u=p*d;a=d*h;var y=e.matrix4(m*r+v,m*o-c,m*a+l,0,m*o+c,m*i+v,m*u-f,0,m*a-l,m*u+f,m*s+v,0,0,0,0,1);return e.Mat(y)};e.quatFromAxisAngle=function(e,t){var n=[];var r=t*.5;var i=Math.sin(r);var s=Math.cos(r);n[0]=e[0]*i;n[1]=e[1]*i;n[2]=e[2]*i;n[3]=s;return n};e.mulQuat=function(e,t){var n=[];var r=e[0];var i=e[1];var s=e[2];var o=e[3];var u=t[0];var a=t[1];var f=t[2];var l=t[3];var c=i*f-s*a;var h=s*u-r*f;var p=r*a-i*u;var d=r*u+i*a+s*f;n[0]=r*l+u*o+c;n[1]=i*l+a*o+h;n[2]=s*l+f*o+p;n[3]=o*l-d;return n};e.mat4FromQuat=function(e){var t=e[0]*e[0];var n=e[1]*e[1];var r=e[2]*e[2];var i=e[0]*e[1];var s=e[2]*e[3];var o=e[2]*e[0];var u=e[1]*e[3];var a=e[1]*e[2];var f=e[0]*e[3];var l=[];l[0]=1-2*(n+r);l[1]=2*(i+s);l[2]=2*(o-u);l[3]=0;l[4]=2*(i-s);l[5]=1-2*(r+t);l[6]=2*(a+f);l[7]=0;l[8]=2*(o+u);l[9]=2*(a-f);l[10]=1-2*(n+t);l[11]=0;l[12]=0;l[13]=0;l[14]=0;l[15]=1;return l};e.quatRotation=function(t,n,r,i){return e.matrix4(1-2*n*n-2*r*r,2*t*n-2*r*i,2*t*r+2*n*i,0,2*t*n+2*r*i,1-2*t*t-2*r*r,2*n*r-2*t*i,0,2*t*r-2*n*i,2*n*r+2*t*i,1-2*t*t-2*n*n,0,0,0,0,1)};e.makeOrtho=function(t,n,r,i,s,o){var u=-(n+t)/(n-t);var a=-(i+r)/(i-r);var f=-(o+s)/(o-s);return e.matrix4(2/(n-t),0,0,u,0,2/(i-r),0,a,0,0,-2/(o-s),f,0,0,0,1)};e.makeFrustum=function(t,n,r,i,s,o){var u=2*s/(n-t);var a=2*s/(i-r);var f=(n+t)/(n-t);var l=(i+r)/(i-r);var c=-(o+s)/(o-s);var h=-2*o*s/(o-s);return e.matrix4(u,0,f,0,0,a,l,0,0,0,c,h,0,0,-1,0)};e.makePerspective=function(t,n,r,i){var s=r*Math.tan(t*.00872664625972);var o=-s;var u=o*n;var a=s*n;return e.makeFrustum(u,a,o,s,r,i)};e.makePerspectiveX=function(t,n,r,i){var s=r*Math.tan(t*.00872664625972);var o=-s;var u=o/n;var a=s/n;return e.makeFrustum(o,s,u,a,r,i)};e.matrix2Scale=function(e){var t=e[0];var n=e[1];var r=e[2];var i=e[4];var s=e[5];var o=e[6];var u=e[8];var a=e[9];var f=e[10];var l=Math.sqrt(t*t+n*n+r*r);var c=Math.sqrt(i*i+s*s+o*o);var h=Math.sqrt(u*u+a*a+f*f);return[l,c,h]};e.rotationMatrix2Quat=function(e){var t=e[0]+e[5]+e[10]+1;var n,r,i,s,o;if(t>0){n=.5/Math.sqrt(t);o=.25/n;r=(e[9]-e[6])*n;i=(e[2]-e[8])*n;s=(e[4]-e[1])*n}else if(e[0]>e[5]&&e[0]>e[10]){n=Math.sqrt(1+e[0]-e[5]-e[10])*2;o=(e[9]-e[6])/n;r=.25/n;i=(e[1]+e[4])/n;s=(e[2]+e[8])/n}else if(e[5]>e[10]){n=Math.sqrt(1+e[5]-e[0]-e[10])*2;o=(e[2]-e[8])/n;r=(e[1]+e[4])/n;i=.25/n;s=(e[6]+e[9])/n}else{n=Math.sqrt(1+e[10]-e[0]-e[5])*2;o=(e[4]-e[1])/n;r=(e[2]+e[8])/n;i=(e[6]+e[9])/n;s=.25/n}var u=Math.sqrt(r*r+i*i+s*s+o*o);return[r/u,i/u,s/u,o/u]};e.rayToPlane=function(t,n){var r=e.toUnitVec3(n);return[r[0],r[1],r[2],e.dotVec3(t,r)]};e.rayIntersectPlane=function(t,n,r){var i=[r[0],r[1],r[2]];var s=r[3];var o=e.dotVec3(i,n);if(o<=0){return false}var u=-(e.dotVec3(i,t)+s);var a=u/o;if(a<=0){return false}return e.addVec3(t,e.scaleVec3(n,a))};e.screenToDirection=function(t,n,r,i,s){xcoord=-(2*t/r-1)/s[0];ycoord=(2*n/i-1)/s[5];zcoord=1;return e.toUnitVec3([xcoord,ycoord,zcoord])};e.BoundingVolume=function(e,t,n,r,i,s){this.limits=[e,t,n,r,i,s];this.calcProps()};e.BoundingVolume.prototype.getCornerPoints=function(){return this.points};e.BoundingVolume.prototype.getSphereRadius=function(){return this.radius};e.BoundingVolume.prototype.getCenter=function(){return this.center};e.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};e.BoundingVolume.prototype.addBoundingVolume=function(e){if(this.isNull()){this.limits[0]=e.limits[0];this.limits[1]=e.limits[1];this.limits[2]=e.limits[2];this.limits[3]=e.limits[3];this.limits[4]=e.limits[4];this.limits[5]=e.limits[5]}else if(!e.isNull()){this.limits[0]=Math.min(e.limits[0],this.limits[0]);this.limits[2]=Math.min(e.limits[2],this.limits[2]);this.limits[4]=Math.min(e.limits[4],this.limits[4]);this.limits[1]=Math.max(e.limits[1],this.limits[1]);this.limits[3]=Math.max(e.limits[3],this.limits[3]);this.limits[5]=Math.max(e.limits[5],this.limits[5])}this.calcProps()};e.BoundingVolume.prototype.applyMatrix=function(t){var n=e.mulMat4Vec4(t,[this.limits[0],this.limits[2],this.limits[4],1]);var r=e.mulMat4Vec4(t,[this.limits[1],this.limits[2],this.limits[4],1]);var i=e.mulMat4Vec4(t,[this.limits[0],this.limits[3],this.limits[4],1]);var s=e.mulMat4Vec4(t,[this.limits[1],this.limits[3],this.limits[4],1]);var o=e.mulMat4Vec4(t,[this.limits[0],this.limits[2],this.limits[5],1]);var u=e.mulMat4Vec4(t,[this.limits[1],this.limits[2],this.limits[5],1]);var a=e.mulMat4Vec4(t,[this.limits[0],this.limits[3],this.limits[5],1]);var f=e.mulMat4Vec4(t,[this.limits[1],this.limits[3],this.limits[5],1]);this.limits[0]=Math.min(n[0],r[0],i[0],s[0],o[0],u[0],a[0],f[0]);this.limits[1]=Math.max(n[0],r[0],i[0],s[0],o[0],u[0],a[0],f[0]);this.limits[2]=Math.min(n[1],r[1],i[1],s[1],o[1],u[1],a[1],f[1]);this.limits[3]=Math.max(n[1],r[1],i[1],s[1],o[1],u[1],a[1],f[1]);this.limits[4]=Math.min(n[2],r[2],i[2],s[2],o[2],u[2],a[2],f[2]);this.limits[5]=Math.max(n[2],r[2],i[2],s[2],o[2],u[2],a[2],f[2]);this.calcProps()};e.BoundingVolume.prototype.calcProps=function(){var e=this.limits[0];var t=this.limits[1];var n=this.limits[2];var r=this.limits[3];var i=this.limits[4];var s=this.limits[5];this.points=[[e,n,i],[t,n,i],[e,r,i],[t,r,i],[e,n,s],[t,n,s],[e,r,s],[t,r,s]];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 o=this.limits[0]-this.center[0];var u=this.limits[2]-this.center[1];var a=this.limits[4]-this.center[2];this.radius=Math.sqrt(o*o+u*u+a*a)};e.BoundingVolume.prototype.clone=function(){return new e.BoundingVolume(this.limits[0],this.limits[1],this.limits[2],this.limits[3],this.limits[4],this.limits[5])};e.BoundingVolume.prototype.toString=function(){return this.limits.toString()};e.cameraViewProjectionToPlanes=function(t){var n=e.inverseMat4(t);var r=e.mulMat4Vec4;var i=e.subVec3;var s=e.crossVec3;var o=e.toUnitVec3;var u=e.dotVec3;var a=r(n,[-1,-1,-1,1]);var f=r(n,[1,-1,-1,1]);var l=r(n,[-1,-1,1,1]);var c=r(n,[1,1,-1,1]);var h=r(n,[1,1,1,1]);var p=r(n,[-1,1,1,1]);a=[a[0]/a[3],a[1]/a[3],a[2]/a[3]];f=[f[0]/f[3],f[1]/f[3],f[2]/f[3]];l=[l[0]/l[3],l[1]/l[3],l[2]/l[3]];c=[c[0]/c[3],c[1]/c[3],c[2]/c[3]];h=[h[0]/h[3],h[1]/h[3],h[2]/h[3]];p=[p[0]/p[3],p[1]/p[3],p[2]/p[3]];var d=o(s(i(c,f),i(a,f)));var v=o(s(i(p,l),i(h,l)));var m=o(s(i(a,l),i(p,l)));var g=o(s(i(h,c),i(c,f)));var y=o(s(i(p,c),i(c,h)));var b=o(s(i(a,f),i(l,a)));d.push(u(d,a));v.push(u(v,l));m.push(u(m,a));g.push(u(g,f));y.push(u(y,h));b.push(u(b,a));return[d,v,m,g,y,b]};e.sphereInFrustumPlanes=function(e,t){var n=e[0];var r=e[1];var i=e[2];var s=e[3];var o=t[0];var u=t[1];var a=t[2];var f=t[3];var l=t[4];var c=t[5];if(n*o[0]+r*o[1]+i*o[2]-o[3]-s>0||n*u[0]+r*u[1]+i*u[2]-u[3]-s>0||n*a[0]+r*a[1]+i*a[2]-a[3]-s>0||n*f[0]+r*f[1]+i*f[2]-f[3]-s>0||n*l[0]+r*l[1]+i*l[2]-l[3]-s>0||n*c[0]+r*c[1]+i*c[2]-c[3]-s>0){return false}else{return true}};e.pointsInFrustumPlanes=function(e,t){var n=t[0];var r=t[1];var i=t[2];var s=t[3];var o=t[4];var u=t[5];var a,f,l;for(var c=0;c0&&a*r[0]+f*r[1]+l*r[2]-r[3]>0&&a*i[0]+f*i[1]+l*i[2]-s[3]>0&&a*s[0]+f*s[1]+l*s[2]-o[3]>0&&a*o[0]+f*o[1]+l*o[2]-o[3]>0&&a*u[0]+f*u[1]+l*u[2]-u[3]>0){return false}}return true};e.getDirLightProjection=function(t,n,r,i){var s=e.mulMat4(n,e.inverseMat4(t));var o=[0,0,0];var u=[0,0,0];for(var a=0;a<2;a++){for(var f=0;f<2;f++){for(var l=0;l<2;l++){var c=e.mulMat4Vec4(s,[a*2-1,f*2-1,l*2-1,1]);c[0]=c[0]/c[3];c[1]=c[1]/c[3];c[2]=c[2]/c[3];o[0]=o[0]>c[0]?c[0]:o[0];o[1]=o[1]>c[1]?c[1]:o[1];u[0]=u[0]1){if(this.loop){t=(parseFloat(e)-parseFloat(this.animationStart))/1e3*this.frameRate%(this.animFrames-1)+1+this.startFrame}else{t=(parseFloat(e)-parseFloat(this.animationStart))/1e3*this.frameRate+1+this.startFrame;if(t>=this.animFrames+this.startFrame){t=this.animFrames}}}else{t=1}return Math.round(t)};e.Animatable.prototype.setStartFrame=function(e,t,n){this.loop=n;var r=parseInt((new Date).getTime());if(!t)t=0;if(t>0){if(this.animation){this.blendInitValues=this.getInitialValues(this.animation,r);this.blendTime=t}}this.animationStart=r;this.lastFrame=null;this.animFinished=false;this.startFrame=e;if(this.children){for(var i=0;i0){this.blendInitValues=this.getInitialValues(e,n);this.blendTime=t}this.animFrames=null;this.startFrame=null;this.animationStart=n;this.lastFrame=null;this.animation=e;this.animFinished=false;return this};e.Animatable.prototype.getAnimation=function(){return this.animation};e.Animatable.prototype.setFrameRate=function(e){this.frameRate=e;if(this.children){for(var t=0;t0)return this.getDefault(t);if(!t.object){t.object=new e.Mesh;this.setProperties(t);var n=t.firstChild;while(n){switch(n.tagName){case"positions":t.object.setPositions(this.parseArray(n));break;case"normals":t.object.setNormals(this.parseArray(n));break;case"uv1":t.object.setUV(this.parseArray(n));break;case"uv2":t.object.setUV2(this.parseArray(n));break;case"faces":t.object.setFaces(this.parseArray(n));break;case"color":t.object.setVertexColors(this.parseArray(n));break;case"joint_names":var r=this.parseArray(n);var i=[];for(var s=0;s0||t.className=="Light"){var n=t;while(n.parent)n=n.parent;n.updateAllPrograms()}if(t.addEventListener){t.addEventListener("shaderupdate",function(){var e=this;while(e.parent)e=e.parent;e.updateAllPrograms()});t.addEventListener("downloadComplete",this.downloadComplete)}this.fireEvent("childAdded",{obj:t});if(t.fireEvent)t.fireEvent("appened",{obj:this});this.fireEvent("childAdded",{obj:t});var r=this;while(r=r.parent)r.fireEvent("childAdded",{obj:t,target:this});return this};e.Group.prototype.addObject=e.Group.prototype.addChild;e.Group.prototype.addObjectInstance=e.Group.prototype.addChild;e.Group.prototype.addGroup=e.Group.prototype.addChild;e.Group.prototype.addLight=e.Group.prototype.addChild;e.Group.prototype.addText=e.Group.prototype.addChild;e.Group.prototype.addSkeleton=e.Group.prototype.addChild;e.Group.prototype.addCamera=e.Group.prototype.addChild;e.Group.prototype.addWavefront=e.Group.prototype.addChild;e.Group.prototype.removeChild=function(e){var t;if(typeof e=="object"){for(var n=0;n0)e.Message.loadMessages()}})(GLGE);(function(e){e.Action=function(t){this.channels=[];e.Assets.registerAsset(this,t)};e.augment(e.QuickNotation,e.Action);e.augment(e.JSONLoader,e.Action);e.augment(e.Events,e.Action);e.Action.prototype.start=function(e,t,n){if(!t)t=false;if(!e)e=0;var r=this.channels;var i=(new Date).getTime();this.animFinished=false;for(var s=0;sthis.keyFrames[n].x)){i=n;n=o}else if(this.keyFrames[o].x<=t&&(i==undefined||this.keyFrames[o].x>this.keyFrames[i].x)){i=o}if(this.keyFrames[o].x>t&&(r==undefined||this.keyFrames[o].x<=this.keyFrames[r].x)){s=r;r=o}else if(this.keyFrames[o].x>t&&(s==undefined||this.keyFrames[o].x<=this.keyFrames[s].x)){s=o}}if(n==undefined){n=r;r=s}if(r==undefined){r=n;n=i}if(this.keyFrames[n]instanceof e.BezTriple&&this.keyFrames[r]instanceof e.BezTriple){var u=this.coord(this.keyFrames[n].x,this.keyFrames[n].y);var a=this.coord(this.keyFrames[n].x3,this.keyFrames[n].y3);var f=this.coord(this.keyFrames[r].x1,this.keyFrames[r].y1);var l=this.coord(this.keyFrames[r].x,this.keyFrames[r].y);return this.atX(t,u,a,f,l).y}if(this.keyFrames[n]instanceof e.LinearPoint&&this.keyFrames[r]instanceof e.BezTriple){var u=this.coord(this.keyFrames[n].x,this.keyFrames[n].y);var a=this.coord(this.keyFrames[r].x1,this.keyFrames[r].y1);var f=this.coord(this.keyFrames[r].x1,this.keyFrames[r].y1);var l=this.coord(this.keyFrames[r].x,this.keyFrames[r].y);return this.atX(t,u,a,f,l).y}if(this.keyFrames[n]instanceof e.BezTriple&&this.keyFrames[r]instanceof e.LinearPoint){var u=this.coord(this.keyFrames[n].x,this.keyFrames[n].y);var a=this.coord(this.keyFrames[n].x3,this.keyFrames[n].y3);var f=this.coord(this.keyFrames[n].x3,this.keyFrames[n].y3);var l=this.coord(this.keyFrames[r].x,this.keyFrames[r].y);return this.atX(t,u,a,f,l).y}if(this.keyFrames[n]instanceof e.LinearPoint&&this.keyFrames[r]instanceof e.LinearPoint){var c=(t-this.keyFrames[n].x)*(this.keyFrames[r].y-this.keyFrames[n].y)/(this.keyFrames[r].x-this.keyFrames[n].x)+this.keyFrames[n].y;return c}if(this.keyFrames[n]instanceof e.StepPoint){return this.keyFrames[n].y}if(!this.keyFrames.preStartKey)this.keyFrames.preStartKey=this.keyFrames[0].y;this.caches[t]=this.keyFrames.preStartKey;return this.caches[t]};e.AnimationCurve.prototype.B1=function(e){return e*e*e};e.AnimationCurve.prototype.B2=function(e){return 3*e*e*(1-e)};e.AnimationCurve.prototype.B3=function(e){return 3*e*(1-e)*(1-e)};e.AnimationCurve.prototype.B4=function(e){return(1-e)*(1-e)*(1-e)};e.AnimationCurve.prototype.getBezier=function(e,t,n,r,i){var s={};s.x=t.x*this.B1(e)+n.x*this.B2(e)+r.x*this.B3(e)+i.x*this.B4(e);s.y=t.y*this.B1(e)+n.y*this.B2(e)+r.y*this.B3(e)+i.y*this.B4(e);return s};e.AnimationCurve.prototype.Quad3Solve=function(e,t,n,r){ref=e+"-"+t+"-"+"-"+n+"-"+r;if(this.solutions[ref]){return this.solutions[ref]}else{t/=e;n/=e;r/=e;var i,s,o,u,a,f,l;i=(3*n-t*t)/9;s=-(27*r)+t*(9*n-2*t*t);s/=54;f=t/3;discrim=i*i*i+s*s;result=[];if(discrim>0){u=s+Math.sqrt(discrim);u=u<0?-Math.pow(-u,1/3):Math.pow(u,1/3);a=s-Math.sqrt(discrim);a=a<0?-Math.pow(-a,1/3):Math.pow(a,1/3);result[0]=-f+u+a;f=f+(u+a)/2;result[1]=result[2]=-f;f=Math.sqrt(3)*(-a+u)/2}else if(discrim==0){l=s<0?-Math.pow(-s,1/3):Math.pow(s,1/3);result[1]=-f+2*l;result[1]=result[2]=-(l+f)}else{i=-i;o=i*i*i;o=Math.acos(s/Math.sqrt(1));l=2*Math.sqrt(i);result[0]=-f+l*Math.cos(o/3);result[1]=-f+l*Math.cos((o+2*Math.PI)/3);result[2]=-f+l*Math.cos((o+4*Math.PI)/3)}var c=false;if(result[0]>=0&&result[0]<=1)c=result[0];if(!c&&result[1]>=0&&result[1]<=1)c=result[1];if(!c&&result[2]>=0&&result[2]<=1)c=result[2];this.solutions[ref]=c;return c}};e.AnimationCurve.prototype.atX=function(e,t,n,r,i){a=t.x-n.x*3+r.x*3-i.x;b=n.x*3-r.x*6+i.x*3;c=r.x*3-i.x*3;d=i.x-e;return this.getBezier(this.Quad3Solve(a,b,c,d),t,n,r,i)}})(GLGE);(function(e){e.AnimationVector=function(t){this.curves={};e.Assets.registerAsset(this,t)};e.augment(e.QuickNotation,e.AnimationVector);e.augment(e.JSONLoader,e.AnimationVector);e.AnimationVector.prototype.curves={};e.AnimationVector.prototype.frames=250;e.AnimationVector.prototype.startFrame=0;e.AnimationVector.prototype.addAnimationCurve=function(e){this.curves[e.channel]=e;return this};e.AnimationVector.prototype.removeAnimationCurve=function(e){delete this.curves[e]};e.AnimationVector.prototype.setFrames=function(e){this.frames=e;return this};e.AnimationVector.prototype.getFrames=function(){return this.frames};e.AnimationVector.prototype.setStartFrame=function(e){this.startFrame=e;return this};e.AnimationVector.prototype.getStartFrame=function(){return this.startFrame}})(GLGE);(function(e){e.BezTriple=function(t){e.Assets.registerAsset(this,t)};e.augment(e.QuickNotation,e.BezTriple);e.augment(e.JSONLoader,e.BezTriple);e.BezTriple.prototype.className="BezTriple";e.BezTriple.prototype.setX1=function(e){this.x1=parseFloat(e);return this};e.BezTriple.prototype.setY1=function(e){this.y1=parseFloat(e);return this};e.BezTriple.prototype.setX2=function(e){this.x=parseFloat(e);return this};e.BezTriple.prototype.setY2=function(e){this.y=parseFloat(e);return this};e.BezTriple.prototype.setX3=function(e){this.x3=parseFloat(e);return this};e.BezTriple.prototype.setY3=function(e){this.y3=parseFloat(e);return this};e.LinearPoint=function(e){};e.augment(e.QuickNotation,e.LinearPoint);e.augment(e.JSONLoader,e.LinearPoint);e.LinearPoint.prototype.className="LinearPoint";e.LinearPoint.prototype.x=0;e.LinearPoint.prototype.y=0;e.LinearPoint.prototype.setX=function(e){this.x=parseFloat(e);return this};e.LinearPoint.prototype.setY=function(e){this.y=parseFloat(e);return this};e.StepPoint=function(e,t){this.x=parseFloat(e);this.y=t}})(GLGE);(function(e){e.Mesh=function(t,n){this.GLbuffers=[];this.buffers=[];this.framePositions=[];this.frameNormals=[];this.frameTangents=[];this.UV=[];this.boneWeights=[];this.setBuffers=[];this.faces={};if(n!==undefined)this.windingOrder=n;else this.windingOrder=e.Mesh.WINDING_ORDER_UNKNOWN;e.Assets.registerAsset(this,t)};e.Mesh.WINDING_ORDER_UNKNOWN=2;e.Mesh.WINDING_ORDER_CLOCKWISE=1;e.Mesh.WINDING_ORDER_COUNTER=0;e.augment(e.QuickNotation,e.Mesh);e.augment(e.JSONLoader,e.Mesh);e.augment(e.Events,e.Mesh);e.Mesh.prototype.gl=null;e.Mesh.prototype.className="Mesh";e.Mesh.prototype.GLbuffers=null;e.Mesh.prototype.buffers=null;e.Mesh.prototype.setBuffers=null;e.Mesh.prototype.GLfaces=null;e.Mesh.prototype.faces=null;e.Mesh.prototype.UV=null;e.Mesh.prototype.joints=null;e.Mesh.prototype.invBind=null;e.Mesh.prototype.loaded=false;e.Mesh.prototype.getBoundingVolume=function(){if(!this.positions)return new e.BoundingVolume(0,0,0,0,0,0);if(!this.boundingVolume){var t,n,r,i,s,o;var u=this.positions;for(var a=0;a0){d=l(d,-1);v=l(v,-1)}return[d,v]};e.Mesh.prototype.setFaces=function(e){this.faces={data:e,GL:false};if(!this.normals)this.calcNormals();if(!this.tangents&&this.UV.length>0)this.calcTangents();return this};e.Mesh.prototype.calcTangents=function(){for(var t=0;t0){l.push(r[n[c]*3]);l.push(r[n[c]*3+1]);l.push(r[n[c]*3+2])}if(i){a.push(i[n[c]*2]);a.push(i[n[c]*2+1])}if(s){f.push(s[n[c]*2]);f.push(s[n[c]*2+1])}}}else{o=e;u=t;l=r;a=i;f=s}var h=[];var p=[];var d=[];var v=[];var m=[];var g=[];var y=[];for(var c=0;c0){g.push(l[c]);g.push(l[c+1]);g.push(l[c+2])}if(i){v.push(a[c/3*2]);v.push(a[c/3*2+1])}if(s){m.push(f[c/3*2]);m.push(f[c/3*2+1])}}d.push(w)}this.setPositions(h).setNormals(p).setFaces(d).setUV(v).setUV2(m).setTangents(g)};e.Mesh.prototype.GLAttributes=function(t,n,r,i){this.gl=t;if(!r)r=0;if(!this.normals)this.calcNormals();for(var s=0;s<8;s++)t.disableVertexAttribArray(s);if(!this.faces.GL&&this.faces.data&&this.faces.data.length>0){this.GLSetFaceBuffer(t);this.faces.GL=true}for(s=0;s-1){t.bindBuffer(t.ARRAY_BUFFER,this.GLbuffers[this.buffers[s].name]);t.enableVertexAttribArray(attribslot);t.vertexAttribPointer(attribslot,this.GLbuffers[this.buffers[s].name].itemSize,t.FLOAT,false,0,0)}}var o=e.getAttribLocation(t,n,"position");if(o>-1){t.bindBuffer(t.ARRAY_BUFFER,this.GLbuffers["position"+r]);t.enableVertexAttribArray(o);t.vertexAttribPointer(o,this.GLbuffers["position"+r].itemSize,t.FLOAT,false,0,0)}var u=e.getAttribLocation(t,n,"normal");if(u>-1){t.bindBuffer(t.ARRAY_BUFFER,this.GLbuffers["normal"+r]);t.enableVertexAttribArray(u);t.vertexAttribPointer(u,this.GLbuffers["normal"+r].itemSize,t.FLOAT,false,0,0)}var a=e.getAttribLocation(t,n,"tangent");if(a>-1){t.bindBuffer(t.ARRAY_BUFFER,this.GLbuffers["tangent"+r]);t.enableVertexAttribArray(a);t.vertexAttribPointer(a,this.GLbuffers["tangent"+r].itemSize,t.FLOAT,false,0,0)}if(i!=undefined){var f=e.getAttribLocation(t,n,"position2");if(f>-1){t.bindBuffer(t.ARRAY_BUFFER,this.GLbuffers["position"+i]);t.enableVertexAttribArray(f);t.vertexAttribPointer(f,this.GLbuffers["position"+i].itemSize,t.FLOAT,false,0,0)}var l=e.getAttribLocation(t,n,"normal2");if(l>-1){t.bindBuffer(t.ARRAY_BUFFER,this.GLbuffers["normal"+i]);t.enableVertexAttribArray(l);t.vertexAttribPointer(l,this.GLbuffers["normal"+i].itemSize,t.FLOAT,false,0,0)}var c=e.getAttribLocation(t,n,"tangent2");if(c>-1){t.bindBuffer(t.ARRAY_BUFFER,this.GLbuffers["tangent"+i]);t.enableVertexAttribArray(c);t.vertexAttribPointer(c,this.GLbuffers["tangent"+i].itemSize,t.FLOAT,false,0,0)}}}})(GLGE);(function(e){e.Sphere=function(t){this.vertical=10;this.horizontal=10;this.radius=1;this.dirtySphere=false;e.Mesh.apply(this,arguments);this.generateMeshData()};e.augment(e.Mesh,e.Sphere);e.Sphere.prototype.generateMeshData=function(){var t=this.vertical;var n=this.horizontal;var r=this.radius;var i,s,o,u,a,f,s,l;var c=[];var h=[];var p=[];for(u=0;u<=t;u++){i=u/t*Math.PI;s=Math.cos(i)*r;o=Math.sin(i)*r;for(a=0;a0){for(a=0;a0)t={r:t,g:t,b:t};if(!t.r){t=e.colorParse(t)}this.emit={r:parseFloat(t.r),g:parseFloat(t.g),b:parseFloat(t.b)};this.fireEvent("shaderupdate",{});return this};e.Material.prototype.setEmitR=function(e){this.emit.r=parseFloat(e);return this};e.Material.prototype.setEmitG=function(e){this.emit.g=parseFloat(e);return this};e.Material.prototype.setEmitB=function(e){this.emit.b=parseFloat(e);return this};e.Material.prototype.getEmitR=function(e){return this.emit.r};e.Material.prototype.getEmitG=function(e){return this.emit.g};e.Material.prototype.getEmitB=function(e){return this.emit.b};e.Material.prototype.getEmit=function(){return this.emit};e.Material.prototype.setReflectivity=function(e){this.reflect=e;this.fireEvent("shaderupdate",{});return this};e.Material.prototype.getReflectivity=function(){return this.reflect};e.Material.prototype.setBinaryAlpha=function(e){this.binaryAlpha=e;this.fireEvent("shaderupdate",{});return this};e.Material.prototype.getBinaryAlpha=function(){return this.binaryAlpha};e.Material.prototype.addMaterialLayer=function(t){if(typeof t=="string")t=e.Assets.get(t);this.layers.push(t);var n=this;var r=function(e){n.fireEvent("shaderupdate",{})};this.layerlisteners.push(r);t.addEventListener("shaderupdate",r);this.fireEvent("shaderupdate",{});return this};e.Material.prototype.removeMaterialLayer=function(e){var t=this.layers.indexOf(e);if(t>=0){this.layers.splice(t,1);e.removeEventListener("shaderupdate",this.layerlisteners[t]);this.layerlisteners.splice(t,1);this.fireEvent("shaderupdate",{})}return this};e.Material.prototype.getLayers=function(){return this.layers};e.Material.prototype.getLayerCoords=function(t){var n=[];n.push("vec4 texturePos;\n");for(var r=0;rneye.z*steepdisplace"+u+"){";s=s+"textureHeight=vec3(vec2(neye.x,neye.y)*steepdisplace"+u+",0.0);";s=s+"}else{";s=s+"steepdisplace"+u+"-=steepstep"+u+";";s=s+"steepstep"+u+"*=0.5;";s=s+"}";s=s+"steepdisplace"+u+"+=steepstep"+u+";";s=s+"}"}if((this.layers[u].mapto&e.M_SPECCOLOR)==e.M_SPECCOLOR){s=s+"specC = specC*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").rgb*mask;\n"}if((this.layers[u].mapto&e.M_MSKR)==e.M_MSKR){s=s+"mask = texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").r;\n"}if((this.layers[u].mapto&e.M_MSKG)==e.M_MSKG){s=s+"mask = texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").g;\n"}if((this.layers[u].mapto&e.M_MSKB)==e.M_MSKB){s=s+"mask = texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").b;\n"}if((this.layers[u].mapto&e.M_MSKA)==e.M_MSKA){s=s+"mask = texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").a;\n"}if((this.layers[u].mapto&e.M_SPECULAR)==e.M_SPECULAR){s=s+"spec = spec*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").r*mask;\n"}if((this.layers[u].mapto&e.M_REFLECT)==e.M_REFLECT){s=s+"ref = ref*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").g*mask;\n"}if((this.layers[u].mapto&e.M_SHINE)==e.M_SHINE){s=s+"sh = sh*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").b*mask*255.0;\n"}if((this.layers[u].mapto&e.M_EMIT)==e.M_EMIT){s=s+"em = em*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").rgb*mask;\n"}if((this.layers[u].mapto&e.M_NOR)==e.M_NOR){s=s+"normalmap = normalmap*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+")*mask;\n";s=s+"normal = normalmap.rgb;\n";s=s+"normal = 2.0*(vec3(normal.r, -normal.g, normal.b) - vec3(0.5, -0.5, 0.5));";s=s+"b=normalize(cross(t.xyz,n));\n";s=s+"normal = normal.x*t + normal.y*b + normal.z*n;";s=s+"normal = normalize(normal);"}if((this.layers[u].mapto&e.M_ALPHA)==e.M_ALPHA){h=true;s=s+"al = al*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").a*mask;\n"}if((this.layers[u].mapto&e.M_AMBIENT)==e.M_AMBIENT){s=s+"amblight = amblight*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[u].texture.idx+", textureCoords."+p+").rgb*mask;\n"}}s=s+"amblight *= amb;\n";if(!h&&this.layers.length){if(this.layers[c].getTexture().className=="Texture"||this.layers[c].getTexture().className=="TextureCanvas"||this.layers[c].getTexture().className=="TextureVideo"){var p="xy";var d="2D"}else{var p="xyz";var d="Cube"}s=s+"al = al*(1.0-mask) + texture"+d+"(TEXTURE"+this.layers[c].texture.idx+", textureCoords."+p+").a*al*mask;\n"}if(n&&this.vertexColorMode==e.VC_MUL){s=s+"color *= vcolor;"}if(this.binaryAlpha){s=s+"if(al<0.5) discard;\n";s=s+"al=1.0;\n"}else{s=s+"if(al==0.0) discard;\n"}s=s+"vec3 lightvalue=amblight;\n";if(n&&this.vertexColorMode==e.VC_AMB){s=s+"lightvalue = vcolor.rgb;"}if(n&&this.vertexColorMode==e.VC_AMBMUL){s=s+"lightvalue *= vcolor.rgb;"}s=s+"float dotN,spotEffect;";s=s+"vec3 lightvec=vec3(0.0,0.0,0.0);";s=s+"vec3 viewvec=vec3(0.0,0.0,0.0);";s=s+"vec3 specvalue=vec3(0.0,0.0,0.0);";s=s+"vec2 scoord=vec2(0.0,0.0);";s=s+"float sDepth=0.0;";s=s+"float d1=0.0;";s=s+"float d2=0.0;";s=s+"float spotmul=0.0;";s=s+"float rnd=0.0;";s=s+"float spotsampleX=0.0;";s=s+"float spotsampleY=0.0;";s=s+"float totalweight=0.0;";s=s+"int cnt=0;";s=s+"float specularSmoothStepValue=.125;\n";s=s+"vec2 spotoffset=vec2(0.0,0.0);";s=s+"float dp=0.0;";s=s+"vec4 dist;float depth,m1,m2,prob,variance;\n";s=s+"if (normal.z<0.0) {normal.z=0.0;}\n";s=s+"float fogfact=1.0;";s=s+"if(fogtype=="+e.FOG_QUADRATIC+" || fogtype=="+e.FOG_SKYQUADRATIC+") fogfact=clamp(pow(max((fogfar - length(eyevec)) / (fogfar - fognear),0.0),2.0),0.0,1.0);\n";s=s+"if(fogtype=="+e.FOG_LINEAR+" || fogtype=="+e.FOG_SKYLINEAR+") fogfact=clamp((fogfar - length(eyevec)) / (fogfar - fognear),0.0,1.0);\n";if(!i){s=s+"if (emitpass) {gl_FragColor=vec4(em,1.0);} else if (shadeless) {\n";s=s+"gl_FragColor=vec4(color.rgb,al);\n";if(this.fadeDistance>0){s=s+"gl_FragColor.a=gl_FragColor.a*(1.0-min(1.0,"+this.fadeDistance.toFixed(5)+"/length(eyevec)));\n"}s=s+"} else {\n";for(var u=0;u0.0){\n";if(t[u].diffuse){s=s+"lightvalue += att * dotN * lightcolor"+u+";\n"}s=s+"}\n";if(t[u].specular){s=s+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN)*att * specC * lightcolor"+u+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3*sh);\n"}}s=s+"spotEffect = 0.0;\n";if(t[u].type==e.L_SPOT){s=s+"spotEffect = dot(normalize(lightdir"+u+"), normalize(-lightvec"+u+"));";s=s+"if (spotEffect > spotCosCutOff"+u+""+(!this.spotCutOff?" || spotEffect>0.0":"")+") {\n";s=s+"spotEffect = pow(spotEffect, spotExp"+u+");";if(t[u].getCastShadows()&&this.shadow){s=s+"scoord=(((spotcoord"+u+".xy)/spotcoord"+u+".w)+1.0)/2.0;\n";s=s+"if(scoord.x>0.0 && scoord.x<1.0 && scoord.y>0.0 && scoord.y<1.0){\n";s=s+"dist=texture2D(TEXTURE"+f[u]+", scoord);\n";if(t[u].spotSoftness==0){s=s+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0))*"+t[u].distance+".0;\n";s=s+"if(depth0.0){\n";if(t[u].diffuse){s=s+"lightvalue -= (1.0-spotEffect) / (lightAttenuation"+u+"[0] + lightAttenuation"+u+"[1] * lightdist"+u+" + lightAttenuation"+u+"[2] * lightdist"+u+" * lightdist"+u+");\n"}s=s+"}\n"}else{s=s+"att = spotEffect / (lightAttenuation"+u+"[0] + lightdist"+u+"*(lightAttenuation"+u+"[1] + lightAttenuation"+u+"[2] * lightdist"+u+"));\n";s=s+"if(dotN>0.0){\n";if(t[u].diffuse){s=s+"lightvalue += att * dotN * lightcolor"+u+";\n"}s=s+"}\n";if(t[u].specular){s=s+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN) * att * specC * lightcolor"+u+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3 * sh);\n"}}s=s+"}\n"}if(t[u].type==e.L_DIR){if(this.translucency==0){s=s+"dotN=max(dot(normal,normalize(-lightvec)),0.0);\n"}else{s=s+"dotN=dot(normal,normalize(-lightvec));\n";s=s+"if (dotN<0.0) dotN*=-"+this.translucency.toFixed(2)+";\n"}if(t[u].getCastShadows()&&this.shadow){s=s+"float shadowfact"+u+" = 0.0;\n";s=s+"scoord=((spotcoord"+u+".xy)/spotcoord"+u+".w+1.0)/2.0;\n";var v=1/t[u].bufferWidth;var m=1/t[u].bufferHeight;s=s+"dist=texture2D(TEXTURE"+f[u]+", scoord );\n";s=s+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n";s=s+"d1 = depth;\n";s=s+"d2 = depth*depth;\n";s=s+"dist=texture2D(TEXTURE"+f[u]+", scoord+vec2("+v.toFixed(5)+","+m.toFixed(5)+") );\n";s=s+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n";s=s+"d1 += depth;\n";s=s+"d2 += depth*depth;\n";s=s+"dist=texture2D(TEXTURE"+f[u]+", scoord+vec2(-"+v.toFixed(5)+","+m.toFixed(5)+"));\n";s=s+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n";s=s+"d1 += depth;\n";s=s+"d2 += depth*depth;\n";s=s+"dist=texture2D(TEXTURE"+f[u]+", scoord+vec2("+v.toFixed(5)+",-"+m.toFixed(5)+"));\n";s=s+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n";s=s+"d1 += depth;\n";s=s+"d2 += depth*depth;\n";s=s+"dist=texture2D(TEXTURE"+f[u]+", scoord+vec2(-"+v.toFixed(5)+",-"+m.toFixed(5)+"));\n";s=s+"depth = dot(dist, vec4(0.000000059604644775390625,0.0000152587890625,0.00390625,1.0));\n";s=s+"d1 += depth;\n";s=s+"d2 += depth*depth;\n";s=s+"d1 *= 0.2;\n";s=s+"d2 *= 0.2;\n";s=s+"sDepth = max(0.0, ((spotcoord"+u+".z/spotcoord"+u+".w)+1.0)/2.0-d1-"+t[u].shadowBias+");\n";s=s+"variance = min(max(d2-d1*d1, 0.0)+"+t[u].varianceMin+", 1.0);\n";s=s+"prob=variance /( variance + sDepth*sDepth );\n";s=s+"prob=smoothstep("+t[u].bleedCutoff.toFixed(2)+",1.0,prob);\n";s=s+"shadowfact"+u+"=prob;\n"}else{s=s+"float shadowfact"+u+" = 1.0;\n"}if(t[u].diffuse){if(t[u].negativeShadow){s=s+"lightvalue -= lightcolor"+u+"-(dotN * lightcolor"+u+" * shadowfact"+u+");\n"}else{s=s+"shadowfact"+u+"="+this.translucency.toFixed(2)+"+"+(1-this.translucency).toFixed(2)+"*shadowfact"+u+";\n";s=s+"lightvalue += dotN * lightcolor"+u+" * shadowfact"+u+";\n"}}if(t[u].specular){s=s+"specvalue += smoothstep(-specularSmoothStepValue,specularSmoothStepValue,dotN) * specC * lightcolor"+u+" * spec * pow(max(dot(reflect(normalize(lightvec), normal),normalize(viewvec)),0.0), 0.3 * sh);\n"}}}s=s+"lightvalue = (lightvalue)*ref;\n";s=s+"vec3 fc=fogcolor.rgb;\n";s=s+"if(fogtype=="+e.FOG_SKYLINEAR+" || fogtype=="+e.FOG_SKYQUADRATIC+"){";s=s+"vec4 view=projection * vec4(-eyevec,1.0);\n";s=s+"vec2 fogCoords=view.xy/view.w*0.5+0.5;\n";s=s+"fc=texture2D(sky,fogCoords.xy).rgb;\n";s=s+"}\n";s=s+"vec4 finalColor =vec4(specvalue.rgb+color.rgb*lightvalue.rgb+em.rgb,al)*fogfact+vec4(fc,al)*(1.0-fogfact);\n";if(r&&~r.indexOf("GLGE_FragColor")){s=s+"finalColor=GLGE_FragColor(finalColor);\n"}if(this.fadeDistance>0){s=s+"finalColor.a=finalColor.a*(1.0-min(1.0,"+this.fadeDistance.toFixed(5)+"/length(eyevec)));\n"}if(this.fadeDistance<0){s=s+"finalColor.a=finalColor.a*(min(1.0,"+(-this.fadeDistance).toFixed(5)+"/length(eyevec)));\n"}s=s+"gl_FragColor = finalColor;";if(e.DEBUGNORMALS)s=s+"gl_FragColor = vec4(normal.rgb,1.0);";if(e.DEBUGCOORD0)s=s+"gl_FragColor = vec4(textureCoords0.rg,0.0,1.0);";s=s+"}\n"}else{s=s+"float shadowdepth = gl_FragCoord.z;\n";s=s+"if(shadowtype) shadowdepth=length(eyevec)/distance;\n";s=s+"vec4 rgba=fract(shadowdepth * vec4(16777216.0, 65536.0, 256.0, 1.0));\n";s=s+"gl_FragColor=rgba-rgba.rrgb*vec4(0.0,0.00390625,0.00390625,0.00390625);\n"}s=s+"}\n";return s};e.Material.prototype.textureUniforms=function(t,n,r,i){if(this.animation)this.animate();var s=n.caches;if(!s.baseColor||s.baseColor.r!=this.color.r||s.baseColor.g!=this.color.g||s.baseColor.b!=this.color.b||s.baseColor.a!=this.color.a){if(!this.ccache||this.ccache.r!=this.color.r||this.ccache.g!=this.color.g||this.ccache.b!=this.color.b||this.ccache.a!=this.color.a){this.ccache=this.color;this.glColor=new Float32Array([this.color.r,this.color.g,this.color.b,this.color.a])}t.uniform4fv(e.getUniformLocation(t,n,"baseColor"),this.glColor);s.baseColor=this.color}if(s.specColor!=this.specColor){if(this.sccache!=this.specColor){this.sccache=this.specColor;this.glspecColor=new Float32Array([this.specColor.r,this.specColor.g,this.specColor.b])}t.uniform3fv(e.getUniformLocation(t,n,"specColor"),this.glspecColor);s.specColor=this.specColor}if(s.emit!=this.emit){t.uniform3f(e.getUniformLocation(t,n,"emit"),this.emit.r,this.emit.g,this.emit.b);s.emit=this.emit}if(s.specular!=this.specular){e.setUniform(t,"1f",e.getUniformLocation(t,n,"specular"),this.specular);s.specular=this.specular}if(s.shine!=this.shine){e.setUniform(t,"1f",e.getUniformLocation(t,n,"shine"),this.shine);s.shine=this.shine}if(s.reflect!=this.reflect){e.setUniform(t,"1f",e.getUniformLocation(t,n,"reflective"),this.reflect);s.reflect=this.reflect}if(s.alpha!=this.alpha){e.setUniform(t,"1f",e.getUniformLocation(t,n,"alpha"),this.alpha);s.alpha=this.alpha}if(s.shadeless==undefined||s.shadeless!=this.shadeless){e.setUniform(t,"1i",e.getUniformLocation(t,n,"shadeless"),this.shadeless);s.shadeless=this.shadeless}var o=1;var u=0;if(!s["lightcolor"]){s["lightcolor"]=[];s["lightAttenuation"]=[];s["spotCosCutOff"]=[];s["spotExponent"]=[];s["shadowbias"]=[];s["castshadows"]=[];s["shadowsamples"]=[];s["shadowsoftness"]=[]}if(r){for(var a=0;a1){for(var r=1;rt&&i0}})(GLGE);(function(e){e.TextureCamera=function(t){e.Assets.registerAsset(this,t)};e.augment(e.QuickNotation,e.TextureCamera);e.augment(e.JSONLoader,e.TextureCamera);e.augment(e.Events,e.TextureCamera);e.TextureCamera.prototype.className="Texture";e.TextureCamera.prototype.texture=null;e.TextureCamera.prototype.glTexture=null;e.TextureCamera.prototype.object=null;e.TextureCamera.prototype.camera=null;e.TextureCamera.prototype.bufferHeight=0;e.TextureCamera.prototype.bufferWidth=0;e.TextureCamera.prototype.planeOffset=0;e.TextureCamera.prototype.mirrorAxis=e.NONE;e.TextureCamera.prototype.clipAxis=e.NONE;e.TextureCamera.prototype.autoUpdate=true;e.TextureCamera.prototype.rendered=false;e.TextureCamera.prototype.render=function(){this.rendered=false;return this};e.TextureCamera.prototype.setAutoUpdate=function(e){this.autoUpdate=e;return this};e.TextureCamera.prototype.getAutoUpdate=function(){return this.autoUpdate};e.TextureCamera.prototype.setPlaneOffset=function(e){this.planeOffset=e;return this};e.TextureCamera.prototype.getPlaneOffset=function(){return this.planeOffset};e.TextureCamera.prototype.setBufferWidth=function(e){this.bufferWidth=e;this.update=true;return this};e.TextureCamera.prototype.getBufferWidth=function(){return this.bufferWidth};e.TextureCamera.prototype.setBufferHeight=function(e){this.bufferHeight=e;this.update=true;return this};e.TextureCamera.prototype.getBufferHeight=function(){return this.bufferHeight};e.TextureCamera.prototype.setClipAxis=function(e){this.clipAxis=e;return this};e.TextureCamera.prototype.getClipAxis=function(){return this.clipAxis};e.TextureCamera.prototype.setMirrorAxis=function(e){this.mirrorAxis=e;return this};e.TextureCamera.prototype.getMirrorAxis=function(){return this.mirrorAxis};e.TextureCamera.prototype.setCamera=function(e){this.camera=e;return this};e.TextureCamera.prototype.getCamera=function(){return this.camera};e.TextureCamera.prototype.doTexture=function(t,n){if(this.camera){if(this.autoRender||!this.rendered||true){this.rendered=true;this.gl=t;var r=n.getModelMatrix();var i=this.camera.pMatrix;var s=this.camera.matrix;this.camera.pMatrix=null;this.camera.matrix=null;var o=this.camera.getProjectionMatrix().slice(0);var u=this.camera.getViewMatrix().slice(0);this.camera.pMatrix=i;this.camera.matrix=s;var a;if(this.mirrorAxis){switch(this.mirrorAxis){case e.XAXIS:a=e.mulMat4(e.mulMat4(e.mulMat4(u,r),e.scaleMatrix(-1,1,1)),e.inverseMat4(r));break;case e.YAXIS:a=e.mulMat4(e.mulMat4(e.mulMat4(u,r),e.scaleMatrix(1,-1,1)),e.inverseMat4(r));break;case e.ZAXIS:a=e.mulMat4(e.mulMat4(e.mulMat4(u,r),e.scaleMatrix(1,1,-1)),e.inverseMat4(r));break}}else{a=u}if(this.clipAxis){var f;switch(this.clipAxis){case e.NEG_XAXIS:var l=e.toUnitVec3([-r[0],-r[4],-r[8]]);f=[l[0],l[1],l[2],-e.dotVec3([r[3],r[7],r[11]],l)-this.planeOffset];break;case e.POS_XAXIS:var l=e.toUnitVec3([r[0],r[4],r[8]]);f=[l[0],l[1],l[2],-e.dotVec3([r[3],r[7],r[11]],l)-this.planeOffset];break;case e.NEG_YAXIS:var l=e.toUnitVec3([-r[1],-r[5],-r[9]]);f=[l[0],l[1],l[2],-e.dotVec3([r[3],r[7],r[11]],l)-this.planeOffset];break;case e.POS_YAXIS:var l=e.toUnitVec3([r[1],r[5],r[9]]);f=[l[0],l[1],l[2],-e.dotVec3([r[3],r[7],r[11]],l)-this.planeOffset];break;case e.NEG_ZAXIS:var l=e.toUnitVec3([-r[2],-r[6],-r[10]]);f=[l[0],l[1],l[2],-e.dotVec3([r[3],r[7],r[11]],l)-this.planeOffset];break;case e.POS_ZAXIS:var l=e.toUnitVec3([r[2],r[6],r[10]]);f=[l[0],l[1],l[2],-e.dotVec3([r[3],r[7],r[11]],l)-this.planeOffset];break}var c=e.transposeMat4(e.inverseMat4(e.mulMat4(o,a)));f=e.mulMat4Vec4(c,f);f=e.scaleVec4(f,o[10]);f[3]-=1;if(f[2]<0)e.scaleVec4(f,-1);var h=[1,0,0,0,0,1,0,0,f[0],f[1],f[2],f[3],0,0,0,1];o=e.mulMat4(h,o)}var p=!this.bufferHeight?t.scene.renderer.canvas.height:this.bufferHeight;var d=!this.bufferWidth?t.scene.renderer.canvas.width:this.bufferWidth;if(!this.glTexture||this.update){this.createFrameBuffer(t);t.scene.addRenderPass(this.frameBuffer,a,t.scene.camera.getProjectionMatrix(),d,p,n,this.mirrorAxis?true:false);t.bindTexture(t.TEXTURE_2D,this.glTexture);this.update=false;return false}else{t.bindTexture(t.TEXTURE_2D,this.glTexture);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE);t.scene.addRenderPass(this.frameBuffer,a,o,d,p,n,this.mirrorAxis?true:false);return true}}else{t.bindTexture(t.TEXTURE_2D,this.glTexture)}}else{return false}};e.TextureCamera.prototype.registerPasses=e.TextureCamera.prototype.doTexture;e.TextureCamera.prototype.createFrameBuffer=function(e){var t=!this.bufferHeight?e.scene.renderer.canvas.height:this.bufferHeight;var n=!this.bufferWidth?e.scene.renderer.canvas.width:this.bufferWidth;if(!this.frameBuffer)this.frameBuffer=e.createFramebuffer();if(!this.renderBuffer)this.renderBuffer=e.createRenderbuffer();if(!this.glTexture)this.glTexture=e.createTexture();e.bindTexture(e.TEXTURE_2D,this.glTexture);var r=new Uint8Array(n*t*4);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,r);e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer);e.bindRenderbuffer(e.RENDERBUFFER,this.renderBuffer);e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,n,t);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,this.renderBuffer);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.glTexture,0);e.bindRenderbuffer(e.RENDERBUFFER,null);e.bindFramebuffer(e.FRAMEBUFFER,null);e.bindTexture(e.TEXTURE_2D,null)}})(GLGE);(function(e){e.TextureCameraCube=function(t){e.Assets.registerAsset(this,t);this.cubeBuffers=[]};e.augment(e.QuickNotation,e.TextureCameraCube);e.augment(e.JSONLoader,e.TextureCameraCube);e.augment(e.Events,e.TextureCameraCube);e.TextureCameraCube.prototype.className="TextureCube";e.TextureCameraCube.prototype.texture=null;e.TextureCameraCube.prototype.glTexture=null;e.TextureCameraCube.prototype.object=null;e.TextureCameraCube.prototype.autoUpdate=false;e.TextureCameraCube.prototype.rendered=false;e.TextureCameraCube.prototype.bufferHeight=512;e.TextureCameraCube.prototype.bufferWidth=512;e.TextureCameraCube.prototype.offsetX=0;e.TextureCameraCube.prototype.offsetY=0;e.TextureCameraCube.prototype.offsetZ=0;e.TextureCameraCube.prototype.cameraMatries=[[0,0,-1,0,0,1,0,0,-1,0,0,0,0,0,0,1],[0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1],[-1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],[-1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1],[1,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,1],[-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]];e.TextureCameraCube.prototype.pMatrix=e.makePerspective(90,1,1e-4,1e3);e.TextureCameraCube.prototype.render=function(){this.rendered=false;return this};e.TextureCameraCube.prototype.setOffsetX=function(e){this.offsetX=e;return this};e.TextureCameraCube.prototype.getOffsetX=function(){return this.offsetX};e.TextureCameraCube.prototype.setOffsetY=function(e){this.offsetY=e;return this};e.TextureCameraCube.prototype.getOffsetY=function(){return this.offsetY};e.TextureCameraCube.prototype.setOffsetZ=function(e){this.offsetZ=e;return this};e.TextureCameraCube.prototype.getOffsetZ=function(){return this.offsetZ};e.TextureCameraCube.prototype.setAutoUpdate=function(e){this.autoUpdate=e;return this};e.TextureCameraCube.prototype.getAutoUpdate=function(){return this.autoUpdate};e.TextureCameraCube.prototype.setBufferWidth=function(e){this.bufferWidth=e;this.update=true;return this};e.TextureCameraCube.prototype.getBufferWidth=function(){return this.bufferWidth};e.TextureCameraCube.prototype.setBufferHeight=function(e){this.bufferHeight=e;this.update=true;return this};e.TextureCameraCube.prototype.getBufferHeight=function(){return this.bufferHeight};e.TextureCameraCube.prototype.doTexture=function(t,n){this.gl=t;var r=n.getModelMatrix();var i=this.bufferHeight;var s=this.bufferWidth;if(!this.cubeBuffers.length||this.update){this.createFrameBuffers(t);this.update=false;return false}t.bindTexture(t.TEXTURE_CUBE_MAP,this.glTexture);if(!this.rendered||this.autoUpdate){for(var o=0;o<6;o++){var u=this.cameraMatries[o].slice(0);var a=e.mulMat4(u,r);var f=e.mulMat4Vec3(a,[this.offsetX,this.offsetY,this.offsetZ,1]);u[3]=-f[0];u[7]=-f[1];u[11]=-f[2];t.scene.addRenderPass(this.cubeBuffers[o],u,this.pMatrix,s,i,n,true)}this.rendered=true}return true};e.TextureCameraCube.prototype.registerPasses=e.TextureCameraCube.prototype.doTexture;e.TextureCameraCube.prototype.createFrameBuffers=function(e){var t=this.bufferHeight;var n=this.bufferWidth;var r=e.createRenderbuffer();this.glTexture=e.createTexture();e.bindTexture(e.TEXTURE_CUBE_MAP,this.glTexture);e.bindRenderbuffer(e.RENDERBUFFER,r);e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,n,t);e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,null);e.texImage2D(e.TEXTURE_CUBE_MAP_NEGATIVE_X,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,null);e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_Y,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,null);e.texImage2D(e.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,null);e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_Z,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,null);e.texImage2D(e.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,e.RGBA,n,t,0,e.RGBA,e.UNSIGNED_BYTE,null);e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAG_FILTER,e.LINEAR);e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,e.LINEAR);e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE);e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);var i;i=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,i);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,r);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_NEGATIVE_X,this.glTexture,0);this.cubeBuffers.push(i);i=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,i);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,r);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X,this.glTexture,0);this.cubeBuffers.push(i);i=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,i);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,r);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_NEGATIVE_Y,this.glTexture,0);this.cubeBuffers.push(i);i=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,i);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,r);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_Y,this.glTexture,0);this.cubeBuffers.push(i);i=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,i);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,r);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_NEGATIVE_Z,this.glTexture,0);this.cubeBuffers.push(i);i=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,i);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,r);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_Z,this.glTexture,0);this.cubeBuffers.push(i);e.bindRenderbuffer(e.RENDERBUFFER,null);e.bindFramebuffer(e.FRAMEBUFFER,null);e.bindTexture(e.TEXTURE_CUBE_MAP,null)}})(GLGE);(function(e){e.TextureCanvas=function(t){this.canvas=document.createElement("canvas");this.t=document.createElement("canvas");this.t.width=1;this.t.height=1;e.Assets.registerAsset(this,t)};e.augment(e.QuickNotation,e.TextureCanvas);e.augment(e.JSONLoader,e.TextureCanvas);e.augment(e.Events,e.TextureCanvas);e.TextureCanvas.prototype.className="TextureCanvas";e.TextureCanvas.prototype.glTexture=null;e.TextureCanvas.prototype.autoUpdate=true;e.TextureCanvas.prototype.getAutoUpdate=function(){return this.autoUpdate};e.TextureCanvas.prototype.setAutoUpdate=function(e){this.autoUpdate=e;return this};e.TextureCanvas.prototype.getCanvas=function(){return this.canvas};e.TextureCanvas.prototype.setCanvas=function(e){this.canvas=e;return this};e.TextureCanvas.prototype.setHeight=function(e){this.canvas.height=e;return this};e.TextureCanvas.prototype.setWidth=function(e){this.canvas.width=e;return this};e.TextureCanvas.prototype.getHeight=function(){return this.canvas.height};e.TextureCanvas.prototype.getWidth=function(){return this.canvas.width};e.TextureCanvas.prototype.doTexture=function(e){this.gl=e;if(!this.glTexture){this.glTexture=e.createTexture();e.bindTexture(e.TEXTURE_2D,this.glTexture);this.updateCanvas(e)}else{e.bindTexture(e.TEXTURE_2D,this.glTexture);if(this.autoUpdate||this.doUpdate)this.updateCanvas(e)}this.doUpdate=false;return true};e.TextureCanvas.prototype.update=function(){this.doUpdate=true};e.TextureCanvas.prototype.updateCanvas=function(e){var t=this.canvas;e.bindTexture(e.TEXTURE_2D,this.glTexture);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.t);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR);e.generateMipmap(e.TEXTURE_2D)}})(GLGE);(function(e){e.TextureCube=function(t){e.Assets.registerAsset(this,t)};e.augment(e.QuickNotation,e.TextureCube);e.augment(e.JSONLoader,e.TextureCube);e.augment(e.Events,e.TextureCube);e.TextureCube.prototype.className="TextureCube";e.TextureCube.prototype.posX=null;e.TextureCube.prototype.negX=null;e.TextureCube.prototype.posY=null;e.TextureCube.prototype.negY=null;e.TextureCube.prototype.posZ=null;e.TextureCube.prototype.negZ=null;e.TextureCube.prototype.texture=null;e.TextureCube.prototype.glTexture=null;e.TextureCube.prototype.loadState=0;e.TextureCube.prototype.setSrc=function(e,t,n){this.url=e;this.state=0;this[t]=new Image;var r=this;this[t].onload=function(){r.loadState+=n};this[t].src=e;if(this.glTexture&&this.gl){this.gl.deleteTexture(this.glTexture);this.glTexture=null}return this};e.TextureCube.prototype.setSrcPosX=function(e){this.setSrc(e,"posX",1);return this};e.TextureCube.prototype.setSrcNegX=function(e){this.setSrc(e,"negX",2);return this};e.TextureCube.prototype.setSrcPosY=function(e){this.setSrc(e,"posY",4);return this};e.TextureCube.prototype.setSrcNegY=function(e){if(typeof e!="string"){this.negY=e;this.loadState+=8}else{this.setSrc(e,"negY",8)}return this};e.TextureCube.prototype.setSrcPosZ=function(e){this.setSrc(e,"posZ",16);return this};e.TextureCube.prototype.setSrcNegZ=function(e){this.setSrc(e,"negZ",32);return this};e.TextureCube.prototype.doTexture=function(e,t){this.gl=e;if(!this.glTexture)this.glTexture=e.createTexture();e.bindTexture(e.TEXTURE_CUBE_MAP,this.glTexture);if(this.loadState==63&&this.state==0){e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.posX);e.texImage2D(e.TEXTURE_CUBE_MAP_NEGATIVE_X,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.negX);e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_Y,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.posY);e.texImage2D(e.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.negY);e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_Z,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.posZ);e.texImage2D(e.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.negZ);e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAG_FILTER,e.LINEAR);e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR);e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE);e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);e.generateMipmap(e.TEXTURE_CUBE_MAP);e.bindTexture(e.TEXTURE_CUBE_MAP,null);this.state=1}e.bindTexture(e.TEXTURE_CUBE_MAP,this.glTexture);if(this.state==1)return true;else return false}})(GLGE);(function(e){e.TextureVideo=function(t){this.video=document.createElement("video");this.video.style.display="none";this.video.setAttribute("loop","loop");this.video.autoplay=true;this.video.addEventListener("ended",function(){this.play()},true);document.getElementsByTagName("body")[0].appendChild(this.video);this.canvas=document.createElement("canvas");this.ctx=this.canvas.getContext("2d");e.Assets.registerAsset(this,t)};e.augment(e.QuickNotation,e.TextureVideo);e.augment(e.JSONLoader,e.TextureVideo);e.augment(e.Events,e.TextureVideo);e.TextureVideo.prototype.className="TextureVideo";e.TextureVideo.prototype.glTexture=null;e.TextureVideo.prototype.getVideo=function(){return this.video};e.TextureVideo.prototype.setVideo=function(e){this.video=e;return this};e.TextureVideo.prototype.setSrc=function(e){this.video.src=e;return this};e.TextureVideo.prototype.getSrc=function(e){return this.video.src};e.TextureVideo.prototype.doTexture=function(e){this.gl=e;if(!this.glTexture){this.glTexture=e.createTexture();e.bindTexture(e.TEXTURE_2D,this.glTexture);this.updateTexture(e)}else{e.bindTexture(e.TEXTURE_2D,this.glTexture);this.updateTexture(e)}return true};e.TextureVideo.prototype.updateTexture=function(e){var t=this.video;e.bindTexture(e.TEXTURE_2D,this.glTexture);if(t.readyState>0){if(t.height<=0){t.style.display="";t.height=t.offsetHeight;t.width=t.offsetWidth;t.style.display="none"}this.canvas.height=t.height;this.canvas.width=t.width;this.ctx.drawImage(t,0,0);try{e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.canvas)}catch(n){e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.canvas,null)}e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR);e.generateMipmap(e.TEXTURE_2D)}}})(GLGE);(function(e){e.ObjectLod=function(t){this.setMaterial(e.DEFAULT_MATERIAL);e.Assets.registerAsset(this,t)};e.augment(e.QuickNotation,e.ObjectLod);e.augment(e.JSONLoader,e.ObjectLod);e.augment(e.Events,e.ObjectLod);e.ObjectLod.prototype.mesh=null;e.ObjectLod.prototype.className="ObjectLod";e.ObjectLod.prototype.material=null;e.ObjectLod.prototype.program=null;e.ObjectLod.prototype.GLShaderProgramPick=null;e.ObjectLod.prototype.GLShaderProgramShadow=null;e.ObjectLod.prototype.GLShaderProgram=null;e.ObjectLod.prototype.pixelSize=0;e.ObjectLod.prototype.setMesh=function(t){if(typeof t=="string")t=e.Assets.get(t);if(this.mesh){this.mesh.removeEventListener("shaderupdate",this.meshupdated);this.mesh.removeEventListener("boundupdate",this.boundupdated)}var n=this;this.meshupdated=function(e){n.GLShaderProgram=null};this.boundupdated=function(e){n.fireEvent("boundupdate",{})};t.addEventListener("shaderupdate",this.meshupdated);t.addEventListener("boundupdate",this.boundupdated);this.GLShaderProgram=null;this.mesh=t;return this};e.ObjectLod.prototype.isComplete=function(){return this.material.isComplete()};e.ObjectLod.prototype.getMesh=function(){return this.mesh};e.ObjectLod.prototype.setMaterial=function(t){if(typeof t=="string")t=e.Assets.get(t);if(this.material){this.material.removeEventListener("shaderupdate",this.materialupdated);this.material.removeEventListener("downloadComplete",this.downloadComplete)}var n=this;this.materialupdated=function(e){n.GLShaderProgram=null};t.addEventListener("shaderupdate",this.materialupdated);this.downloadComplete=function(){n.fireEvent("downloadComplete")};t.addEventListener("downloadComplete",this.downloadComplete);this.GLShaderProgram=null;this.material=t;return this};e.ObjectLod.prototype.getMaterial=function(){return this.material};e.ObjectLod.prototype.getPixelSize=function(){return this.pixelSize};e.ObjectLod.prototype.setPixelSize=function(e){this.pixelSize=parseFloat(e)}})(GLGE);(function(e){e.Object=function(t){this.multimaterials=[];this.renderCaches=[];var n=this;this.downloadComplete=function(){if(n.isComplete())n.fireEvent("downloadComplete")};e.Assets.registerAsset(this,t)};e.augment(e.Placeable,e.Object);e.augment(e.Animatable,e.Object);e.augment(e.QuickNotation,e.Object);e.augment(e.JSONLoader,e.Object);e.Object.prototype.className="Object";e.Object.prototype.mesh=null;e.Object.prototype.skeleton=null;e.Object.prototype.scene=null;e.Object.prototype.transformMatrix=e.identMatrix();e.Object.prototype.material=null;e.Object.prototype.gl=null;e.Object.prototype.multimaterials=null;e.Object.prototype.zTrans=false;e.Object.prototype.renderCaches=null;e.Object.prototype.id="";e.Object.prototype.pickable=true;e.Object.prototype.drawType=e.DRAW_TRIS;e.Object.prototype.pointSize=1;e.Object.prototype.lineWidth=1;e.Object.prototype.cull=true;e.Object.prototype.culled=true;e.Object.prototype.visible=true;e.Object.prototype.depthTest=true;e.Object.prototype.meshFrame1=0;e.Object.prototype.meshFrame2=0;e.Object.prototype.meshBlendFactor=0;e.Object.prototype.noCastShadows=null;e.Object.prototype.noDepthMask=false;e.Object.prototype.shadowAlpha=true;e.Object.prototype.blending=["SRC_ALPHA","ONE_MINUS_SRC_ALPHA"];var t=[];t.push("#ifdef GL_ES\nprecision highp float;\n#endif\n");t.push("uniform float distance;\n");t.push("uniform bool shadowtype;\n");t.push("varying vec3 eyevec;\n");t.push("void main(void)\n ");t.push("{\n");t.push("float depth = gl_FragCoord.z;\n");t.push("if(shadowtype) depth=length(eyevec)/distance;\n");t.push("vec4 rgba=fract(depth * vec4(16777216.0, 65536.0, 256.0, 1.0));\n");t.push("gl_FragColor=rgba-rgba.rrgb*vec4(0.0,0.00390625,0.00390625,0.00390625);\n");t.push("}\n");e.Object.prototype.shfragStr=t.join("");var n=[];n.push("#ifdef GL_ES\nprecision highp float;\n#endif\n");n.push("varying vec3 n;\n");n.push("void main(void)\n");n.push("{\n");n.push("float depth = gl_FragCoord.z / gl_FragCoord.w;\n");n.push("gl_FragColor=vec4(normalize(n)/2.0+0.5,depth/1000.0);\n");n.push("}\n");e.Object.prototype.nfragStr=n.join("");var r=[];r.push("#ifdef GL_ES\nprecision highp float;\n#endif\n");r.push("uniform float far;\n");r.push("uniform vec3 pickcolor;\n");r.push("varying vec3 n;\n");r.push("varying vec4 UVCoord;\n");r.push("void main(void)\n");r.push("{\n");r.push("float Xcoord = gl_FragCoord.x+0.5;\n");r.push("if(Xcoord>0.0) gl_FragColor = vec4(pickcolor,1.0);\n");r.push("if(Xcoord>1.0) gl_FragColor = vec4(n,1.0);\n");r.push("if(Xcoord>2.0){");r.push("vec3 rgb=fract((gl_FragCoord.z/gl_FragCoord.w) * vec3(65536.0, 256.0, 1.0));\n");r.push("gl_FragColor=vec4(rgb-rgb.rrg*vec3(0.0,0.00390625,0.00390625),1.0);\n");r.push("}");r.push("if(Xcoord>3.0){");r.push("vec3 rgb=fract(UVCoord.x * vec3(65536.0, 256.0, 1.0));\n");r.push("gl_FragColor=vec4(rgb-rgb.rrg*vec3(0.0,0.00390625,0.00390625),1.0);\n");r.push("}");r.push("if(Xcoord>4.0){");r.push("vec3 rgb=fract(UVCoord.y * vec3(65536.0, 256.0, 1.0));\n");r.push("gl_FragColor=vec4(rgb-rgb.rrg*vec3(0.0,0.00390625,0.00390625),1.0);\n");r.push("}");r.push("}\n");e.Object.prototype.pkfragStr=r.join("");e.Object.prototype.noDepthMask;e.Object.prototype.setDepthMask=function(e){this.noDepthMask=!e;return this};e.Object.prototype.getDepthMask=function(){return!this.noDepthMask};e.Object.prototype.setVisible=function(e){this.visible=e;return this};e.Object.prototype.getVisible=function(){return this.visible};e.Object.prototype.setBlending=function(e){this.blending=e;return this};e.Object.prototype.getBlending=function(){return this.blending};e.Object.prototype.setMeshFrame1=function(e){this.meshFrame1=e;return this};e.Object.prototype.setMeshFrame2=function(e){this.meshFrame2=e;return this};e.Object.prototype.setMeshBlendFactor=function(e){this.meshBlendFactor=e;return this};e.Object.prototype.getMeshBlendFactor=function(){return this.meshBlendFactor};e.Object.prototype.getPickable=function(){return this.pickable};e.Object.prototype.setPickable=function(e){this.pickable=e;return this};e.Object.prototype.getDepthTest=function(){return this.depthTest};e.Object.prototype.setDepthTest=function(e){this.depthTest=e;return this};e.Object.prototype.getCull=function(){return this.cull};e.Object.prototype.setCull=function(e){this.cull=e;return this};e.Object.prototype.getDrawType=function(){return this.drawType};e.Object.prototype.setDrawType=function(e){this.drawType=e;return this};e.Object.prototype.getPointSize=function(){return this.pointSize};e.Object.prototype.setPointSize=function(e){this.pointSize=parseFloat(e);return this};e.Object.prototype.getLineWidth=function(){return this.lineWidth};e.Object.prototype.setLineWidth=function(e){this.lineWidth=parseFloat(e);return this};e.Object.prototype.setUniform=function(e,t,n){if(!this.uniforms)this.uniforms={};this.uniforms[t]={type:e,value:n}};e.Object.prototype.getUniform=function(e){if(!this.uniforms)this.uniforms={};return this.uniforms[e].value};e.Object.prototype.getUniformType=function(e){if(!this.uniforms)this.uniforms={};return this.uniforms[e].type};e.Object.prototype.setVertexShaderInjection=function(e){this.shaderVertexInjection=e;this.updateProgram();return this};e.Object.prototype.getVertexShaderInjection=function(e){return this.shaderVertexInjection};e.Object.prototype.getSkeleton=function(){return this.skeleton};e.Object.prototype.setSkeleton=function(e){this.skeleton=e;this.bones=null;return this};e.Object.prototype.getBoundingVolume=function(t){if(!t)t=0;if(!this.boundingVolume)this.boundingVolume=[];if(!this.boundmatrix)this.boundmatrix=[];var n=this.getModelMatrix();if(n!=this.boundmatrix[t]||!this.boundingVolume[t]){var r=this.multimaterials;var i;for(var s=0;s1){s.push("attribute vec"+this.mesh.buffers[u].size+" "+this.mesh.buffers[u].name+";\n")}else{s.push("attribute float "+this.mesh.buffers[u].name+";\n")}if(this.mesh.buffers[u].name=="UV")UV=true;if(this.mesh.buffers[u].name=="color")r=true;if(this.mesh.buffers[u].name=="joints1")joints1=this.mesh.buffers[u];if(this.mesh.buffers[u].name=="joints2")joints2=this.mesh.buffers[u]}if(this.mesh.framePositions.length>1){var a=true;s.push("attribute vec3 position2;\n");s.push("attribute vec3 normal2;\n");s.push("uniform float framesBlend;\n");if(o)s.push("attribute vec3 tangent2;\n")}if(o)s.push("attribute vec3 tangent;\n");s.push("uniform mediump mat4 worldView;\n");s.push("uniform mediump mat4 projection;\n");s.push("uniform mediump mat4 worldInverseTranspose;\n");s.push("uniform mediump mat4 envMat;\n");s.push("uniform float cascadeLevel;\n");for(var u=0;u0){s.push("uniform vec4 jointMat["+3*this.mesh.joints.length+"];\n")}if(this.material)s.push(this.material.getVertexVarying(s));s.push("varying vec3 n;\n");s.push("varying vec3 t;\n");if(r)s.push("varying vec4 vcolor;\n");s.push("varying vec4 UVCoord;\n");s.push("varying vec3 OBJCoord;\n");if(this.shaderVertexInjection){s.push(this.shaderVertexInjection)}s.push("void main(void)\n");s.push("{\n");if(r)s.push("vcolor=color;\n");if(UV)s.push("UVCoord=UV;\n");else s.push("UVCoord=vec4(0.0,0.0,0.0,0.0);\n");s.push("OBJCoord = position;\n");s.push("vec3 tang;\n");s.push("vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n");s.push("vec4 norm = vec4(0.0, 0.0, 0.0, 1.0);\n");if(o)s.push("vec4 tang4 = vec4(0.0, 0.0, 0.0, 1.0);\n");if(joints1){if(joints1.size==1){s.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");s.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");if(o)s.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 u=0;u-1){s.push("pos=GLGE_Position(vec4(pos.xyz, 1.0));\n")}s.push("pos = worldView * vec4(pos.xyz, 1.0);\n");s.push("norm = worldInverseTranspose * vec4(norm.xyz, 1.0);\n");if(o)s.push("tang = (worldInverseTranspose*vec4(tang4.xyz,1.0)).xyz;\n")}else{if(a){s.push("vec4 pos4=vec4(mix(position,position2,framesBlend),1.0);\n")}else{s.push("vec4 pos4=vec4(position,1.0);\n")}if(this.shaderVertexInjection&&this.shaderVertexInjection.indexOf("GLGE_Position")>-1){s.push("pos4=GLGE_Position(pos4);\n")}for(var u=0;u>16&255;var o=r>>8&255;var u=r&255;e.setUniform3(t,"3f",e.getUniformLocation(t,i,"pickcolor"),u/255,o/255,s/255);break}t.lineWidth(this.lineWidth);for(var a in this.uniforms){var f=this.uniforms[a];if(f.type=="Matrix4fv"){e.setUniformMatrix(t,"Matrix4fv",e.getUniformLocation(t,i,a),false,f.value)}else{e.setUniform(t,f.type,e.getUniformLocation(t,i,a),f.value)}}if(!i.caches)i.caches={};if(!i.glarrays)i.glarrays={};var l=i.caches;var c=i.glarrays;var h=t.scene;var p=h.camera;if(l.far!=p.far){e.setUniform(t,"1i",e.getUniformLocation(t,i,"far"),p.far);l.far=p.far}if(n==e.RENDER_DEFAULT||n==e.RENDER_EMIT){if(l.ambientColor!=h.ambientColor){var d=h.ambientColor;e.setUniform3(t,"3f",e.getUniformLocation(t,i,"amb"),d.r,d.g,d.b);l.ambientColor=d}if(l.fogFar!=h.fogFar){e.setUniform(t,"1f",e.getUniformLocation(t,i,"fogfar"),h.fogFar);l.fogFar=h.fogFar}if(l.fogNear!=h.fogNear){e.setUniform(t,"1f",e.getUniformLocation(t,i,"fognear"),h.fogNear);l.fogNear=h.fogNear}if(l.fogType!=h.fogType){e.setUniform(t,"1i",e.getUniformLocation(t,i,"fogtype"),h.fogType);l.fogType=h.fogType}if(l.fogType!=h.fogcolor){e.setUniform3(t,"3f",e.getUniformLocation(t,i,"fogcolor"),h.fogColor.r,h.fogColor.g,h.fogColor.b);l.fogcolor=h.fogcolor}}if(l.meshBlendFactor!=this.meshBlendFactor){e.setUniform(t,"1f",e.getUniformLocation(t,i,"framesBlend"),this.meshBlendFactor);l.meshBlendFactor=this.meshBlendFactor}var v=p.getViewMatrix();var m=P=this.getModelMatrix();if(!l.mvMatrix)l.mvMatrix={cameraMatrix:null,modelMatrix:null};var g=l.mvMatrix;if(g.cameraMatrix!=v||g.modelMatrix!=P){if(!this.caches.mvMatrix)this.caches.mvMatrix=e.mulMat4(v,P);mvMatrix=this.caches.mvMatrix;if(this.mesh.joints){mvMatrix=v}var y=e.getUniformLocation(t,i,"worldView");var b=e.transposeMat4(mvMatrix);if(!c.mvMatrix){c.mvMatrixT=new Float32Array(b)}else{e.mat4gl(b,c.mvMatrixT)}c.mvMatrix=mvMatrix;e.setUniformMatrix(t,"Matrix4fv",y,false,i.glarrays.mvMatrixT);var w=e.getUniformLocation(t,i,"envMat");if(w){if(!this.caches.envMat){var E=e.inverseMat4(v);E[3]=0;E[7]=0;E[11]=0;this.caches.envMat=E}E=this.caches.envMat;b=e.transposeMat4(E);if(!i.glarrays.envMat){c.envMatT=new Float32Array(b)}else{e.mat4gl(b,c.envMatT)}c.envMat=E;e.setUniformMatrix(t,"Matrix4fv",w,false,c.envMatT)}if(!this.caches.normalMatrix){var S=e.inverseMat4(mvMatrix);this.caches.normalMatrix=S}S=this.caches.normalMatrix;var x=e.getUniformLocation(t,i,"worldInverseTranspose");if(!c.normalMatrix)c.normalMatrix=new Float32Array(S);else e.mat4gl(S,c.normalMatrix);e.setUniformMatrix(t,"Matrix4fv",x,false,c.normalMatrix);var T=e.getUniformLocation(t,i,"view");b=e.transposeMat4(v);if(!c.cameraMatrix){c.cameraMatrixT=new Float32Array(b)}else{e.mat4gl(b,c.cameraMatrixT)}c.cameraMatrix=v;e.setUniformMatrix(t,"Matrix4fv",T,false,c.cameraMatrixT);g.cameraMatrix=v;g.modelMatrix=P}var N=e.getUniformLocation(t,i,"projection");b=e.transposeMat4(p.getProjectionMatrix());if(!c.pMatrix){c.pMatrixT=new Float32Array(b)}else{e.mat4gl(b,c.pMatrixT)}c.pMatrix=p.getProjectionMatrix();e.setUniformMatrix(t,"Matrix4fv",N,false,c.pMatrixT);if(n==e.RENDER_DEFAULT||n==e.RENDER_SHADOW||n==e.RENDER_DEPTH||n==e.RENDER_EMIT){var C,k;var L=t.lights;if(!l.lights)l.lights=[];if(!c.lights)c.lights=[];if(!this.caches.lights)this.caches.lights=[];var A=l.lights;for(var O=0;O1&&!a){var h=t.scene.camera.getPosition();var p=this.getPosition();var d=e.lengthVec3([h.x-p.x,h.y-p.y,h.z-p.z]);d=e.mulMat4Vec4(t.scene.camera.getProjectionMatrix(),[this.getBoundingVolume().getSphereRadius(),0,-d,1]);a=d[0]/d[3]*t.scene.renderer.canvas.width}var v=this.multimaterials[c].getLOD(a);if(v.mesh&&v.mesh.loaded){if(n==e.RENDER_NULL){if(v.material)v.material.registerPasses(t,this);break}if(!v.GLShaderProgram){this.createShaders(v)}else{this.GLShaderProgramPick=v.GLShaderProgramPick;this.GLShaderProgramShadow=v.GLShaderProgramShadow;this.GLShaderProgram=v.GLShaderProgram}this.mesh=v.mesh;this.material=v.material;var m;switch(this.drawType){case e.DRAW_LINES:m=t.LINES;break;case e.DRAW_POINTS:m=t.POINTS;break;case e.DRAW_LINELOOPS:m=t.LINE_LOOP;break;case e.DRAW_LINESTRIPS:m=t.LINE_STRIP;break;case e.DRAW_TRIANGLESTRIP:m=t.TRIANGLE_STRIP;break;default:m=t.TRIANGLES;break}switch(n){case e.RENDER_DEFAULT:case e.RENDER_EMIT:if(t.program!=this.GLShaderProgram){t.useProgram(this.GLShaderProgram);t.program=this.GLShaderProgram}this.mesh.GLAttributes(t,this.GLShaderProgram,this.meshFrame1,this.meshFrame2);break;case e.RENDER_SHADOW:case e.RENDER_DEPTH:if(t.program!=this.GLShaderProgramShadow){t.useProgram(this.GLShaderProgramShadow,this.meshFrame1,this.meshFrame2);t.program=this.GLShaderProgramShadow}if(!s)s=t.scene.camera.getFar();e.setUniform(t,"1f",e.getUniformLocation(t,this.GLShaderProgramShadow,"distance"),s);this.mesh.GLAttributes(t,this.GLShaderProgramShadow,this.meshFrame1,this.meshFrame2);break;case e.RENDER_NORMAL:if(t.program!=this.GLShaderProgramNormal){t.useProgram(this.GLShaderProgramNormal);t.program=this.GLShaderProgramNormal}this.mesh.GLAttributes(t,this.GLShaderProgramNormal,this.meshFrame1,this.meshFrame2);break;case e.RENDER_PICK:if(t.program!=this.GLShaderProgramPick){t.useProgram(this.GLShaderProgramPick);t.program=this.GLShaderProgramPick}this.mesh.GLAttributes(t,this.GLShaderProgramPick,this.meshFrame1,this.meshFrame2);m=t.TRIANGLES;break}this.GLUniforms(t,n,r);switch(this.mesh.windingOrder){case e.Mesh.WINDING_ORDER_UNKNOWN:if(t.scene.renderer.cullFaces){t.cullFace(t.scene.mirror?t.FRONT:t.BACK);t.enable(t.CULL_FACE)}else{t.disable(t.CULL_FACE)}break;case e.Mesh.WINDING_ORDER_CLOCKWISE:t.cullFace(t.scene.mirror?t.FRONT:t.BACK);t.enable(t.CULL_FACE);break;case e.Mesh.WINDING_ORDER_COUNTER:t.cullFace(t.scene.mirror?t.BACK:t.FRONT);t.enable(t.CULL_FACE);default:break}if(n==e.RENDER_PICK)t.disable(t.CULL_FACE);if(this.noDepthMask)t.depthMask(false);if(this.mesh.GLfaces){t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.mesh.GLfaces);t.drawElements(m,this.mesh.GLfaces.numItems,t.UNSIGNED_SHORT,0)}else{t.drawArrays(m,0,this.mesh.positions.length/3)}t.depthMask(true);switch(this.mesh.windingOrder){case e.Mesh.WINDING_ORDER_UNKNOWN:if(t.scene.renderer.cullFaces)t.enable(t.CULL_FACE);break;case e.Mesh.WINDING_ORDER_COUNTER:t.cullFace(t.BACK);default:break}var g=this.matrix;var y=this.caches;this.matrix=g;this.caches=y}}}})(GLGE);(function(e){e.Text=function(t){this.canvas=document.createElement("canvas");this.scaleCanvas=document.createElement("canvas");this.color={r:1,g:1,b:1};e.Assets.registerAsset(this,t)};e.augment(e.Placeable,e.Text);e.augment(e.Animatable,e.Text);e.augment(e.QuickNotation,e.Text);e.augment(e.JSONLoader,e.Text);e.Text.prototype.className="Text";e.Text.prototype.zTrans=true;e.Text.prototype.canvas=null;e.Text.prototype.aspect=1;e.Text.prototype.color=null;e.Text.prototype.text="";e.Text.prototype.font="Times";e.Text.prototype.size=100;e.Text.prototype.pickType=e.TEXT_TEXTPICK;e.Text.prototype.pickable=true;e.Text.prototype.alpha=1;e.Text.prototype.dirty=true;e.Text.prototype.getPickType=function(){return this.pickType};e.Text.prototype.setPickType=function(e){this.pickType=e;return this};e.Text.prototype.getFont=function(){return this.size};e.Text.prototype.setFont=function(e){this.font=e;this.dirty=true;return this};e.Text.prototype.getSize=function(){return this.size};e.Text.prototype.setSize=function(e){this.size=e;this.dirty=true;return this};e.Text.prototype.getText=function(){return this.text};e.Text.prototype.setText=function(e){this.text=e;this.dirty=true;return this};e.Text.prototype.setColor=function(t){t=e.colorParse(t);this.color={r:t.r,g:t.g,b:t.b};return this};e.Text.prototype.setColorR=function(e){this.color.r=e;return this};e.Text.prototype.setColorG=function(e){this.color.g=e;return this};e.Text.prototype.setColorB=function(e){this.color.b=e;return this};e.Text.prototype.getColor=function(){return this.color;return this};e.Text.prototype.setAlpha=function(e){this.alpha=e;return this};e.Text.prototype.getAlpha=function(){return this.alpha};e.Text.prototype.setZtransparent=function(e){this.zTrans=e;return this};e.Text.prototype.isZtransparent=function(){return this.zTrans};e.Text.prototype.GLGenerateShader=function(t){if(this.GLShaderProgram)t.deleteProgram(this.GLShaderProgram);var n="";n+="attribute vec3 position;\n";n+="attribute vec2 uvcoord;\n";n+="varying vec2 texcoord;\n";n+="uniform mat4 Matrix;\n";n+="uniform mat4 PMatrix;\n";n+="varying vec4 pos;\n";n+="void main(void){\n";n+="texcoord=uvcoord;\n";n+="pos = Matrix * vec4(position,1.0);\n";n+="gl_Position = PMatrix * pos;\n";n+="}\n";var r="#ifdef GL_ES\nprecision highp float;\n#endif\n";r=r+"uniform sampler2D TEXTURE;\n";r=r+"varying vec2 texcoord;\n";r=r+"uniform mat4 Matrix;\n";r=r+"varying vec4 pos;\n";r=r+"uniform float far;\n";r=r+"uniform bool depthrender;\n";r=r+"uniform float distance;\n";r=r+"uniform int picktype;\n";r=r+"uniform vec3 pickcolor;\n";r=r+"uniform vec3 color;\n";r=r+"uniform float alpha;\n";r=r+"void main(void){\n";r=r+"float ob=pow(min(1.0,abs(dot(normalize(Matrix[2].rgb),vec3(0.0,0.0,1.0)))*2.0),1.5);\n";r=r+"float a=texture2D(TEXTURE,texcoord).a*alpha*ob;\n";r=r+"if(picktype=="+e.TEXT_BOXPICK+"){gl_FragColor = vec4(pickcolor,1.0);}";r=r+"else if(picktype=="+e.TEXT_TEXTPICK+"){if(alpha<1.0) discard; gl_FragColor = vec4(pickcolor,alpha);}";r=r+"else{gl_FragColor = vec4(color.rgb,a);};\n";r=r+"if (depthrender) { if(a<0.5) discard; float depth = gl_FragCoord.z / gl_FragCoord.w;\n";r=r+"vec4 rgba=fract(depth/distance * vec4(16777216.0, 65536.0, 256.0, 1.0));\n";r=r+"gl_FragColor=rgba-rgba.rrgb*vec4(0.0,0.00390625,0.00390625,0.00390625);}\n";r=r+"}\n";this.GLFragmentShader=t.createShader(t.FRAGMENT_SHADER);this.GLVertexShader=t.createShader(t.VERTEX_SHADER);t.shaderSource(this.GLFragmentShader,r);t.compileShader(this.GLFragmentShader);if(!t.getShaderParameter(this.GLFragmentShader,t.COMPILE_STATUS)){e.error(t.getShaderInfoLog(this.GLFragmentShader));return}t.shaderSource(this.GLVertexShader,n);t.compileShader(this.GLVertexShader);if(!t.getShaderParameter(this.GLVertexShader,t.COMPILE_STATUS)){e.error(t.getShaderInfoLog(this.GLVertexShader));return}this.GLShaderProgram=t.createProgram();t.attachShader(this.GLShaderProgram,this.GLVertexShader);t.attachShader(this.GLShaderProgram,this.GLFragmentShader);t.linkProgram(this.GLShaderProgram)};e.Text.prototype.GLInit=function(e){this.gl=e;this.createPlane(e);this.GLGenerateShader(e);this.glTexture=e.createTexture();this.dirty=true};e.Text.prototype.updateCanvas=function(e){var t=this.canvas;t.width=1;t.height=this.size*1.2;var n=t.getContext("2d");n.font=this.size+"px "+this.font;t.width=n.measureText(this.text).width;t.height=this.size*1.2;n=t.getContext("2d");n.textBaseline="top";n.font=(this.extra||"")+" "+this.size+"px "+this.font;this.aspect=t.width/t.height;n.fillText(this.text,0,0);var r=Math.pow(2,Math.ceil(Math.log(t.height))/Math.log(2));var i=Math.pow(2,Math.ceil(Math.log(t.width))/Math.log(2));this.scaleCanvas.height=r;this.scaleCanvas.width=i;this.scaleContext=this.scaleCanvas.getContext("2d");this.scaleContext.clearRect(0,0,i,r);this.scaleContext.drawImage(t,0,0,i,r);e.bindTexture(e.TEXTURE_2D,this.glTexture);try{e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.scaleCanvas)}catch(s){e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.scaleCanvas,null)}e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR_MIPMAP_LINEAR);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR);e.generateMipmap(e.TEXTURE_2D);e.bindTexture(e.TEXTURE_2D,null);this.dirty=false};e.Text.prototype.GLRender=function(t,n,r){if(!this.gl){this.GLInit(t)}if(this.dirty)this.updateCanvas(t);if(n==e.RENDER_DEFAULT||n==e.RENDER_PICK||n==e.RENDER_SHADOW){if(this.lookAt)this.Lookat(this.lookAt);if(t.program!=this.GLShaderProgram){t.useProgram(this.GLShaderProgram);t.program=this.GLShaderProgram}var i;for(var s=0;s<8;s++)t.disableVertexAttribArray(s);i=e.getAttribLocation(t,this.GLShaderProgram,"position");t.bindBuffer(t.ARRAY_BUFFER,this.posBuffer);t.enableVertexAttribArray(i);t.vertexAttribPointer(i,this.posBuffer.itemSize,t.FLOAT,false,0,0);i=e.getAttribLocation(t,this.GLShaderProgram,"uvcoord");t.bindBuffer(t.ARRAY_BUFFER,this.uvBuffer);t.enableVertexAttribArray(i);t.vertexAttribPointer(i,this.uvBuffer.itemSize,t.FLOAT,false,0,0);t.activeTexture(t["TEXTURE0"]);t.bindTexture(t.TEXTURE_2D,this.glTexture);e.setUniform(t,"1i",e.getUniformLocation(t,this.GLShaderProgram,"TEXTURE"),0);if(!r)r=0;var o=r>>16&255;var u=r>>8&255;var a=r&255;e.setUniform3(t,"3f",e.getUniformLocation(t,this.GLShaderProgram,"pickcolor"),a/255,u/255,o/255);if(n==e.RENDER_PICK){e.setUniform(t,"1i",e.getUniformLocation(t,this.GLShaderProgram,"picktype"),this.pickType)}else{e.setUniform(t,"1i",e.getUniformLocation(t,this.GLShaderProgram,"picktype"),0)}var f=t.scene.camera.getFar();e.setUniform(t,"1f",e.getUniformLocation(t,this.GLShaderProgram,"distance"),f);if(n==e.RENDER_SHADOW){e.setUniform(t,"1i",e.getUniformLocation(t,this.GLShaderProgram,"depthrender"),1)}else{e.setUniform(t,"1i",e.getUniformLocation(t,this.GLShaderProgram,"depthrender"),0)}if(!this.GLShaderProgram.glarrays)this.GLShaderProgram.glarrays={};var l=this.size/100;var c=e.mulMat4(t.scene.camera.getViewMatrix(),e.mulMat4(this.getModelMatrix(),e.scaleMatrix(this.aspect*l,l,l)));var h=e.getUniformLocation(t,this.GLShaderProgram,"Matrix");if(!this.GLShaderProgram.glarrays.mMatrix)this.GLShaderProgram.glarrays.mMatrix=new Float32Array(c);else e.mat4gl(c,this.GLShaderProgram.glarrays.mMatrix);e.setUniformMatrix(t,"Matrix4fv",h,true,this.GLShaderProgram.glarrays.mMatrix);var h=e.getUniformLocation(t,this.GLShaderProgram,"PMatrix");if(!this.GLShaderProgram.glarrays.pMatrix)this.GLShaderProgram.glarrays.pMatrix=new Float32Array(t.scene.camera.getProjectionMatrix());else e.mat4gl(t.scene.camera.getProjectionMatrix(),this.GLShaderProgram.glarrays.pMatrix);e.setUniformMatrix(t,"Matrix4fv",h,true,this.GLShaderProgram.glarrays.pMatrix);var p=e.getUniformLocation(t,this.GLShaderProgram,"far");e.setUniform(t,"1f",p,t.scene.camera.getFar());var d=e.getUniformLocation(t,this.GLShaderProgram,"alpha");e.setUniform(t,"1f",d,this.alpha);e.setUniform3(t,"3f",e.getUniformLocation(t,this.GLShaderProgram,"color"),this.color.r,this.color.g,this.color.b);t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.GLfaces);t.drawElements(t.TRIANGLES,this.GLfaces.numItems,t.UNSIGNED_SHORT,0);t.scene.lastMaterial=null}};e.Text.prototype.createPlane=function(e){if(!this.posBuffer)this.posBuffer=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,this.posBuffer);e.bufferData(e.ARRAY_BUFFER,new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),e.STATIC_DRAW);this.posBuffer.itemSize=3;this.posBuffer.numItems=4;if(!this.uvBuffer)this.uvBuffer=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,this.uvBuffer);e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,1,1,0,1]),e.STATIC_DRAW);this.uvBuffer.itemSize=2;this.uvBuffer.numItems=4;if(!this.GLfaces)this.GLfaces=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.GLfaces);e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Uint16Array([2,1,0,0,3,2]),e.STATIC_DRAW);this.GLfaces.itemSize=1;this.GLfaces.numItems=6}})(GLGE);(function(e){e.Renderer=function(t,n,r){this.viewport=[];this.canvas=t;if(!r)r={alpha:true,depth:true,stencil:true,antialias:true,premultipliedAlpha:true};try{this.gl=t.getContext("experimental-webgl",r)}catch(i){}try{if(!this.gl)this.gl=t.getContext("webgl",r)}catch(i){}if(!this.gl){console.log("GLGE err:",typeof globalNoWebGLError=="undefined");if(!n&&typeof globalNoWebGLError=="undefined"){var s=document.createElement("div");s.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");s.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(s);throw"cannot create webgl context"}else{n();throw"cannot create webgl context"}}try{this.gl.canvas=t}catch(i){}if(!this.gl.getProgramParameter){this.gl.getProgramParameter=this.gl.getProgrami}if(!this.gl.getShaderParameter){this.gl.getShaderParameter=this.gl.getShaderi}this.gl.uniformMatrix4fvX=this.gl.uniformMatrix4fv;this.gl.uniformMatrix4fv=function(t,n,r){if(!n){this.uniformMatrix4fvX(t,false,r)}else{e.mat4gl(e.transposeMat4(r),r);this.uniformMatrix4fvX(t,false,r)}};var o=this.gl;o.af=o.getExtension("MOZ_EXT_texture_filter_anisotropic")||o.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||o.getExtension("EXT_texture_filter_anisotropic");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)};e.augment(e.QuickNotation,e.Renderer);e.Renderer.prototype.gl=null;e.Renderer.prototype.scene=null;e.C_STENCIL=1;e.C_DEPTH=2;e.C_COLOR=4;e.C_ALL=7;e.Renderer.prototype.clearType=e.C_ALL;e.Renderer.prototype.setViewportWidth=function(e){this.viewport[0]=e;return this};e.Renderer.prototype.setViewportHeight=function(e){this.viewport[1]=e;return this};e.Renderer.prototype.setViewportOffsetX=function(e){this.viewport[2]=e;return this};e.Renderer.prototype.setViewportOffsetY=function(e){this.viewport[3]=e;return this};e.Renderer.prototype.clearViewport=function(){this.viewport=[]};e.Renderer.prototype.getViewportWidth=function(){if(this.viewport.length>0){return this.viewport[0]}else{return this.canvas.width}};e.Renderer.prototype.getViewportHeight=function(){if(this.viewport.length>0){return this.viewport[1]}else{return this.canvas.height}};e.Renderer.prototype.getViewportOffsetX=function(){if(this.viewport.length>0){return this.viewport[2]}else{return 0}};e.Renderer.prototype.getViewportOffsetY=function(){if(this.viewport.length>0){return this.viewport[3]}else{return 0}};e.Renderer.prototype.setClearType=function(e){this.clearType=e;return this};e.Renderer.prototype.getClearType=function(){return this.clearType};e.Renderer.prototype.GLClear=function(){var t=this.gl;var n=this.clearType;var r=0;if((n&e.C_COLOR)==e.C_COLOR){r=r|t.COLOR_BUFFER_BIT}if((n&e.C_DEPTH)==e.C_DEPTH){r=r|t.DEPTH_BUFFER_BIT}if((n&e.C_STENCIL)==e.C_STENCIL){r=r|t.STENCIL_BUFFER_BIT}t.clear(r)};e.Renderer.prototype.getScene=function(){return this.scene};e.Renderer.prototype.setScene=function(e){e.renderer=this;this.scene=e;if(!e.gl)e.GLInit(this.gl);e.camera.updateMatrix();return this};e.Renderer.prototype.render=function(){if(this.transitonFilter){var e=+(new Date);if(et[r]){t[r]=n[r]}}};e.Light.prototype.lightLook=function(t,n,r){var i=e.toUnitVec3(e.crossVec3(n,r));var s=e.toUnitVec3(e.crossVec3(i,n));var o=e.toUnitVec3(n);var u=[];u[0]=i[0];u[4]=s[0];u[8]=-o[0];u[12]=0;u[1]=i[1];u[5]=s[1];u[9]=-o[1];u[13]=0;u[2]=i[2];u[6]=s[2];u[10]=-o[2];u[14]=0;u[3]=-e.dotVec3(i,t);u[7]=-e.dotVec3(s,t);u[11]=e.dotVec3(o,t);u[15]=1;return u};e.Light.prototype.transformPoints=function(t,n){var r=[];for(var i=0;i0&&i>0||r<0&&i<0){return false}else{var s=e.subVec3(t[1],t[0]);s=e.scaleVec3(s,-r/(i-r));return e.addVec3(t[0],s)}};e.Light.prototype.pointInPlanes=function(t,n){var r=-.001;for(var i=0;ir){return 1}else if(nr){return 1}else if(nr){return 1}else if(n0){var v=this.passes.pop();t.bindFramebuffer(t.FRAMEBUFFER,v.frameBuffer);this.camera.matrix=v.cameraMatrix;this.camera.setProjectionMatrix(v.projectionMatrix);this.mirror=v.mirror;this.renderPass(t,r,0,0,v.width,v.height,e.RENDER_DEFAULT,v.self)}this.mirror=false;this.camera.matrix=o;this.camera.setProjectionMatrix(u);t.bindFramebuffer(t.FRAMEBUFFER,this.filter?this.framebuffer:this.transbuffer);this.renderPass(t,r,this.renderer.getViewportOffsetX(),this.renderer.getViewportOffsetY(),this.renderer.getViewportWidth(),this.renderer.getViewportHeight());this.applyFilter(t,r,this.transbuffer);this.allowPasses=true};e.Scene.prototype.getPasses=function(t,n){for(var r=0;rsizeTimeLife[2] && (time-sizeTimeLife[2])-1){t.bindBuffer(t.ARRAY_BUFFER,this.attribute.initPosGL);t.enableVertexAttribArray(r);t.vertexAttribPointer(r,3,t.FLOAT,false,0,0)}var r=e.getAttribLocation(t,this.program,"initAcc");if(r>-1){t.bindBuffer(t.ARRAY_BUFFER,this.attribute.initAccGL);t.enableVertexAttribArray(r);t.vertexAttribPointer(r,3,t.FLOAT,false,0,0)}var r=e.getAttribLocation(t,this.program,"endAcc");if(r>-1){t.bindBuffer(t.ARRAY_BUFFER,this.attribute.endAccGL);t.enableVertexAttribArray(r);t.vertexAttribPointer(r,3,t.FLOAT,false,0,0)}var r=e.getAttribLocation(t,this.program,"initColor");if(r>-1){t.bindBuffer(t.ARRAY_BUFFER,this.attribute.initColorGL);t.enableVertexAttribArray(r);t.vertexAttribPointer(r,4,t.FLOAT,false,0,0)}var r=e.getAttribLocation(t,this.program,"endColor");if(r>-1){t.bindBuffer(t.ARRAY_BUFFER,this.attribute.endColorGL);t.enableVertexAttribArray(r);t.vertexAttribPointer(r,4,t.FLOAT,false,0,0)}var r=e.getAttribLocation(t,this.program,"sizeTimeLife");if(r>-1){t.bindBuffer(t.ARRAY_BUFFER,this.attribute.sizeAndOffsetGL);t.enableVertexAttribArray(r);t.vertexAttribPointer(r,4,t.FLOAT,false,0,0)}var r=e.getAttribLocation(t,this.program,"initVel");if(r>-1){t.bindBuffer(t.ARRAY_BUFFER,this.attribute.initVelGL);t.enableVertexAttribArray(r);t.vertexAttribPointer(r,3,t.FLOAT,false,0,0)}};e.ParticleSystem.prototype.GLRender=function(e){if(!this.attribute)this.generateParticles(e);if(!this.program)this.generateProgram(e);e.program=this.program;e.useProgram(this.program);this.setAttributes(e);this.setUniforms(e);e.depthMask(false);e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.facesGL);e.drawElements(e.TRIANGLES,this.facesGL.num,e.UNSIGNED_SHORT,0);e.depthMask(true);e.scene.lastMaterial=null};e.Scene.prototype.addParticleSystem=e.Scene.prototype.addGroup;e.Group.prototype.addParticleSystem=e.Group.prototype.addGroup})(GLGE);(function(e){e.MD2=function(t){this.MD2Started=+(new Date);this.setAnimation(new e.AnimationVector);e.Object.call(this,t)};e.augment(e.Object,e.MD2);e.MD2.prototype.loadingCache={};e.MD2.prototype.headersCache={};e.MD2.prototype.meshCache={};e.MD2.prototype.MD2Animations={};e.MD2.prototype.MD2StartFrame=0;e.MD2.prototype.MD2EndFrame=0;e.MD2.prototype.MD2Loop=true;e.MD2.prototype.MD2AnimFinished=false;e.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"];e.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]];e.MD2.prototype.MD2FrameRate=6;e.MD2.prototype.getAbsolutePath=function(e,t){if(e.substr(0,7)=="http://"||e.substr(0,7)=="file://"||e.substr(0,7)=="https://"){return e}else{if(!t){t=window.location.href}if(t.indexOf("://")==-1){return t.slice(0,t.lastIndexOf("/"))+"/"+e}var n=t.split("/");var r=n[2];var i=n[0];var s=[];for(var o=3;o>7),exponent=(i<<1&255|r>>7)-127,mantissa=(r&127)<<16|n<<8|t;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)};e.MD2.prototype.parseFrames=function(){var e=this.byteArray;var t=0;var n={};for(var r=0;r0)this.addMD3Childred();this.loaded=true;this.fireEvent("loaded",{url:this.url})};e.MD3.prototype.addMD3Childred=function(){for(var e=0;e32768)t=t-65536;return t};e.MD3.prototype.getSint32At=function(e){var t=this.byteArray[e]|this.byteArray[e+1]<<8|this.byteArray[e+2]<<16|this.byteArray[e+3]<<24;if(t>2147483648)t=t-4294967296;return t};e.MD3.prototype.getFloat32At=function(e){var t=this.byteArray[e];var n=this.byteArray[e+1];var r=this.byteArray[e+2];var i=this.byteArray[e+3];sign=1-2*(i>>7),exponent=(i<<1&255|r>>7)-127,mantissa=(r&127)<<16|n<<8|t;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)};e.MD3.prototype.getStringAt=function(e,t){var n="";for(var r=e;r-1)this.textures.splice(t,1)};e.Filter2d.prototype.createBuffer=function(e,t,n){if(!t)t=e.canvas.width;if(!n)n=e.canvas.height;var r=e.createFramebuffer();var i=e.createRenderbuffer();var s=e.createTexture();e.bindTexture(e.TEXTURE_2D,s);var o=new Uint8Array(t*n*4);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,n,0,e.RGBA,e.UNSIGNED_BYTE,o);e.bindFramebuffer(e.FRAMEBUFFER,r);e.bindRenderbuffer(e.RENDERBUFFER,i);e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,t,n);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,i);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,s,0);e.bindRenderbuffer(e.RENDERBUFFER,null);e.bindFramebuffer(e.FRAMEBUFFER,null);e.bindTexture(e.TEXTURE_2D,null);return[r,i,s]};e.Filter2d.prototype.getFrameBuffer=function(e){if(!this.passes)return null;if(!this.gl)this.gl=e;if(!this.buffers){this.buffers=this.createBuffer(e)}return this.buffers[0]};e.Filter2d.prototype.getEmitBuffer=function(e){if(!this.passes)return null;if(!this.gl)this.gl=e;if(!this.emitBuffers){this.emitBuffers=this.createBuffer(e,this.getEmitBufferWidth(),this.getEmitBufferHeight())}return this.emitBuffers[0]};e.Filter2d.prototype.setEmitBufferWidth=function(e){this.emitBufferWidth=e;this.emitBuffers=null};e.Filter2d.prototype.getEmitBufferWidth=function(){return this.emitBufferWidth?this.emitBufferWidth:this.gl.canvas.width};e.Filter2d.prototype.setEmitBufferHeight=function(e){this.emitBufferHeight=e;this.emitBuffers=null};e.Filter2d.prototype.getEmitBufferHeight=function(){return this.emitBufferHeight?this.emitBufferHeight:this.gl.canvas.height};e.Filter2d.prototype.getDepthBuffer=function(e){if(!this.passes)return null;if(!this.gl)this.gl=e;if(!this.depthBuffers){this.depthBuffers=this.createBuffer(e,this.getDepthBufferWidth(),this.getDepthBufferHeight())}return this.depthBuffers[0]};e.Filter2d.prototype.setDepthBufferWidth=function(e){this.depthBufferWidth=e;this.depthBuffers=null};e.Filter2d.prototype.getDepthBufferWidth=function(){return this.depthBufferWidth?this.depthBufferWidth:this.gl.canvas.width};e.Filter2d.prototype.setDepthBufferHeight=function(e){this.depthBufferHeight=e;this.depthBuffers=null};e.Filter2d.prototype.getDepthBufferHeight=function(){return this.depthBufferHeight?this.depthBufferHeight:this.gl.canvas.height};e.Filter2d.prototype.setNormalBufferWidth=function(e){this.normalBufferWidth=e;this.normalBuffers=null};e.Filter2d.prototype.getNormalBufferWidth=function(){return this.normalBufferWidth?this.normalBufferWidth:this.gl.canvas.width};e.Filter2d.prototype.setNormalBufferHeight=function(e){this.normalBufferHeight=e;this.normalBuffers=null};e.Filter2d.prototype.getNormalBufferHeight=function(){return this.normalBufferHeight?this.normalBufferHeight:this.gl.canvas.height};e.Filter2d.prototype.getNormalBuffer=function(e){if(!this.gl)this.gl=e;if(!this.normalBuffers){this.normalBuffers=this.createBuffer(e,this.getNormalBufferWidth(),this.getNormalBufferHeight())}return this.normalBuffers[0]};e.Filter2d.prototype.setUniform=function(e,t,n){if(!this.uniforms)this.uniforms={};this.uniforms[t]={type:e,value:n}};e.Filter2d.prototype.getUniform=function(e){if(!this.uniforms)this.uniforms={};return this.uniforms[e].value};e.Filter2d.prototype.getUniformType=function(e){if(!this.uniforms)this.uniforms={};return this.uniforms[e].type};e.Filter2d.prototype.addPassFile=function(e){var t=new XMLHttpRequest;var n=this;if(t){t.open("GET",e,false);t.send("");n.addPass(t.responseText)}};e.Filter2d.prototype.addPass=function(e,t,n){if(!this.passes)this.passes=[];this.passes.push({GLSL:e,height:n,width:t})};e.Filter2d.prototype.createPersistTexture=function(e){this.persistTexture=e.createTexture();e.bindTexture(e.TEXTURE_2D,this.persistTexture);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.canvas.width,e.canvas.height,0,e.RGBA,e.UNSIGNED_BYTE,null)};e.Filter2d.prototype.GLRender=function(t,n){t.disable(t.BLEND);if(!n)n=null;if(this.passes){for(var r=0;r lumaMax)) gl_FragColor = vec4(rgbA,1.0);");n.push(" else gl_FragColor = vec4(rgbB,1.0);");n.push(" if(length(rgbM)>"+this.fxaacutoff.toFixed(2)+") gl_FragColor = vec4(rgbM,1.0);");n.push(" if(length(rgbM)<"+this.fxaastartintensity.toFixed(2)+") gl_FragColor = vec4(rgbM,1.0);");n.push("}");this.addPass(n.join("\n"))}}})(GLGE);(function(e){e.FilterAO=function(){this.setUniform("1f","cavitygamma",1/3);this.setUniform("1f","whiteMul",2);this.setUniform("1f","aogamma",1/3);this.setUniform("1f","maxDist",.025);this.passes=[]};e.augment(e.Filter2d,e.FilterAO);e.FilterAO.prototype.renderNormal=true;e.FilterAO.prototype.quality=1;e.FilterAO.prototype.range=80;e.FilterAO.prototype.samples=16;e.FilterAO.prototype.useRender=true;e.FilterAO.prototype.getNormalBufferHeight=function(){return this.normalBufferHeight?this.normalBufferHeight:this.gl.canvas.height*this.quality|0};e.FilterAO.prototype.getNormalBufferWidth=function(){return this.normalBufferWidth?this.normalBufferWidth:this.gl.canvas.width*this.quality|0};e.FilterAO.prototype.setUseRender=function(e){this.useRender=e;this.normalBuffers=null;this.passes=[];return this};e.FilterAO.prototype.setSamples=function(e){this.samples=e;this.normalBuffers=null;this.passes=[];return this};e.FilterAO.prototype.setQuality=function(e){this.quality=e;this.normalBuffers=null;this.passes=[];return this};e.FilterAO.prototype.setRange=function(e){this.range=e;if(this.gl){this.setUniform("1f","blurX",this.range/this.getNormalBufferWidth()*this.quality/this.samples);this.setUniform("1f","blurY",this.range/this.getNormalBufferHeight()/this.samples)}return this};e.FilterAO.prototype.setCavityGamma=function(e){this.setUniform("1f","cavitygamma",1/e);return this};e.FilterAO.prototype.setAmbientMultiplier=function(e){this.setUniform("1f","whiteMul",e);return this};e.FilterAO.prototype.setAmbientGamma=function(e){this.setUniform("1f","aogamma",1/e);return this};e.FilterAO.prototype.setMaximumDistance=function(e){this.setUniform("1f","maxDist",e);return this};e.FilterAO.prototype.GLRender=function(t,n){this.gl=t;if(this.passes.length==0){this.createPasses()}return e.Filter2d.prototype.GLRender.call(this,t,n)};e.FilterAO.prototype.createPasses=function(){if(!this.gl)return;var e=this.getNormalBufferWidth();var t=this.getNormalBufferHeight();var n=this.samples/4|0;var r=[];for(var i=-n,s=0;i<=n;i++,s++){var o=n-Math.abs(i)+1;r[s]=o/(n*n+n)}r[n]=0;this.setUniform("1f","blurX",this.range/e*this.quality/this.samples);this.setUniform("1f","blurY",this.range/t/this.samples);var u=[];u.push("precision highp float;");u.push("uniform sampler2D GLGE_NORMAL;");u.push("uniform float maxDist;");u.push("varying vec2 texCoord;");u.push("uniform float blurX;");u.push("float rand(vec2 co){");u.push("return (fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453)-0.5)*2.0;");u.push("}");u.push("void main(void){");u.push("vec4 n=texture2D(GLGE_NORMAL,texCoord.xy).rgba;");u.push("vec4 color=vec4(0.0,0.0,0.0,n.a);");u.push("float blurSize=blurX/(n.a*n.a+1.0);");u.push("float offset=rand(texCoord.xy)*blurSize+texCoord.x;");u.push("vec3 samp;");u.push("float delta;");for(var i=-n,s=0;i<=n;i++,s++){if(i==0)continue;u.push("samp = texture2D(GLGE_NORMAL, vec2("+i+".0*blurSize+offset, texCoord.y)).rga;");u.push("delta=abs(n.a-samp.b);");u.push("if(delta lumaMax)) gl_FragColor = vec4(rgbA,1.0);");f.push(" else gl_FragColor = vec4(rgbB,1.0);");f.push(" if(length(rgbM)>10.0) gl_FragColor = vec4(rgbM,1.0);");f.push("}");this.passes=[];this.addPass(u.join(""),e,t);this.addPass(a.join(""));this.addPass(f.join("\n"))}})(GLGE);if(typeof GLGE=="undefined"){GLGE={}}(function(e){function n(e,t){var r=null;if(e.getAttribute("id")==t)return e;for(var i=0;i0)N[i].getElementsByTagName("p")[0].data=E}var L=[];var E=meshNode.getElementsByTagName("triangles");for(i=0;i0)L.push(N[i])}for(i=0;it?t:e}var F=21843;F*=3;var I=(c.length-c.length%F)/F+(c.length%F?1:0);var q=[];var R=3;var U=3;var z=2;for(var W=0;W8){var X=[];var V=[];for(var x=0;x0){h=d[0].firstChild;do{switch(h.tagName){case"color":p=h.firstChild.nodeValue.replace(/\s+/g," ").split(" ");u.setAmbient({r:p[0],g:p[1],b:p[2]});break;case"param":p=this.getFloat4(l,h.getAttribute("ref")).replace(/\s+/g," ").split(" ");u.setAmbient({r:p[0],g:p[1],b:p[2]});break;case"texture":this.createMaterialLayer(h,u,l,e.M_AMBIENT,i);break}}while(h=h.nextSibling)}var v=c.getElementsByTagName("diffuse");if(v.length>0){h=v[0].firstChild;do{switch(h.tagName){case"color":p=h.firstChild.nodeValue.replace(/\s+/g," ").split(" ");u.setColor({r:p[0],g:p[1],b:p[2]});break;case"param":p=this.getFloat4(l,h.getAttribute("ref")).replace(/\s+/g," ").split(" ");u.setColor({r:p[0],g:p[1],b:p[2]});break;case"texture":this.createMaterialLayer(h,u,l,e.M_COLOR,i);break}}while(h=h.nextSibling)}var m=c.getElementsByTagName("bump");if(m.length>0){h=m[0].firstChild;do{switch(h.tagName){case"texture":this.createMaterialLayer(h,u,l,e.M_NOR,i);break}}while(h=h.nextSibling)}var g=c.getElementsByTagName("shininess");if(g.length>0){u.setSpecular(1);h=c.getElementsByTagName("shininess")[0].firstChild;do{switch(h.tagName){case"float":if(parseFloat(h.firstChild.nodeValue)>1)u.setShininess(parseFloat(h.firstChild.nodeValue));else u.setShininess(parseFloat(h.firstChild.nodeValue)*128);break;case"param":var y=parseFloat(this.getFloat(l,h.getAttribute("ref")));if(y>1)u.setShininess(y);else u.setShininess(y*128);break;case"texture":this.createMaterialLayer(h,u,l,e.M_SHINE,i);break}}while(h=h.nextSibling)}var b=c.getElementsByTagName("specular");if(b.length>0){u.setSpecular(1);h=b[0].firstChild;do{switch(h.tagName){case"color":p=h.firstChild.nodeValue.replace(/\s+/g," ").split(" ");u.setSpecularColor({r:p[0],g:p[1],b:p[2]});break;case"param":p=this.getFloat4(l,h.getAttribute("ref")).replace(/\s+/g," ").split(" ");u.setSpecularColor({r:p[0],g:p[1],b:p[2]});break;case"texture":this.createMaterialLayer(h,u,l,e.M_SPECCOLOR,i);break}}while(h=h.nextSibling)}var w=c.getElementsByTagName("emission");if(w.length>0){h=w[0].firstChild;do{switch(h.tagName){case"color":p=h.firstChild.nodeValue.split(" ");u.setEmit({r:p[0],g:p[1],b:p[2]});break;case"param":p=this.getFloat4(l,h.getAttribute("ref")).split(" ");u.setEmit(p[0]);break;case"texture":this.createMaterialLayer(h,u,l,e.M_EMIT,i);break}}while(h=h.nextSibling)}var E=c.getElementsByTagName("reflective");if(E.length>0){h=E[0].firstChild;do{switch(h.tagName){case"color":p=h.firstChild.nodeValue.replace(/\s+/g," ").split(" ");break;case"param":p=this.getFloat4(l,h.getAttribute("ref")).replace(/\s+/g," ").split(" ");break;case"texture":this.createMaterialLayer(h,u,l,e.M_REFLECT,i);break}}while(h=h.nextSibling)}var S=c.getElementsByTagName("transparency");if(S.length>0){h=S[0].firstChild;do{switch(h.tagName){case"float":if(h.firstChild.nodeValue<1){u.setAlpha(parseFloat(h.firstChild.nodeValue));u.trans=true}break;case"param":break}}while(h=h.nextSibling)}var x=c.getElementsByTagName("transparent");if(x.length>0){var T=x[0].getAttribute("opaque");if(!T)T="A_ONE";h=x[0].firstChild;do{switch(h.tagName){case"float":var N=parseFloat(h.firstChild.nodeValue);if(N<1){u.setAlpha(parseFloat(h.firstChild.nodeValue));u.trans=true}break;case"color":p=h.firstChild.nodeValue.replace(/\s+/g," ").split(" ");var N=this.getMaterialAlpha(p,T,1);if(N<1){u.setAlpha(N);u.trans=true}break;case"param":p=this.getFloat4(l,h.getAttribute("ref")).replace(/\s+/g," ").split(" ");var N=this.getMaterialAlpha(p,T,1);if(N<1){u.setAlpha(N);u.trans=true}break;case"texture":this.createMaterialLayer(h,u,l,e.M_ALPHA,i);u.trans=true;break}}while(h=h.nextSibling)}return u};e.Collada.prototype.getMaterialAlpha=function(e,t,n){var r;switch(t){case"A_ONE":r=parseFloat(e[3])*n;break;case"A_ZERO":r=1-parseFloat(e[3])*n;break;case"RGB_ONE":var i=parseFloat(e[0])*.212671+parseFloat(e[1])*.71516+parseFloat(e[2])*.072169;r=i*n;break;case"RGB_ZERO":var i=parseFloat(e[0])*.212671+parseFloat(e[1])*.71516+parseFloat(e[2])*.072169;r=1-i*n;break}return r};e.Collada.prototype.setMaterialOntoMesh=function(t,n){var r=n.getElementsByTagName("instance_material");var i={};for(var s=0;s=0;--n)if(e[n]>="0"&&e[n]<="9")t=e[n]+t;if(t.length==0)return"0";return t}u[o[a].getAttribute("semantic")]=f(o[a].getAttribute("semantic"))}}mat=this.getMaterial(r[s].getAttribute("target").substr(1),u);i[r[s].getAttribute("symbol")]=mat}var l=new e.Object;for(s=0;s1)h=parseInt(h[0])+4*parseInt(h[1]);else h=parseInt(h[0]);u[sidtarget].animations[h]=l[0]}else{for(var p=0;p0){u=this.parseArray(r.getElementsByTagName("bind_shape_matrix")[0])}else{u=e.identMatrix()}var a=[u];var f=new e.Group;this.addGroup(f);var s=[f];var l;for(var c=0;c0){var s=i[0].firstChild.nodeValue.split(" ");var o="rgb("+(s[0]*255|0)+","+(s[1]*255|0)+","+(s[2]*255|0)+")";r.setColor(o)}switch(n.tagName){case"point":r.setType(e.L_POINT);case"spot":var u=n.getElementsByTagName("constant_attenuation");if(u.length>0)r.setAttenuationConstant(parseFloat(u[0].firstChild.nodeValue));var a=n.getElementsByTagName("linear_attenuation");if(a.length>0)r.setAttenuationLinear(parseFloat(a[0].firstChild.nodeValue));var f=n.getElementsByTagName("quadratic_attenuation");if(f.length>0)r.setAttenuationQuadratic(parseFloat(f[0].firstChild.nodeValue));if(n.tagName=="spot"){r.setType(e.L_SPOT)}else{break}var l=n.getElementsByTagName("falloff_exponent");if(l.length>0){var c=parseFloat(l[0].firstChild.nodeValue);if(c<1.0001)c*=128;r.setSpotExponent(c)}var h=n.getElementsByTagName("falloff_angle");if(h.length>0)r.setSpotCosCutOff(Math.cos(parseFloat(h[0].firstChild.nodeValue)/180*Math.PI));break}return r};e.Collada.prototype.addColladaCamera=function(e){e.matrix=null;e.parent=this;this.children.push(e);this.hasCamera=true;return this};e.Collada.prototype.getNode=function(t,n){if(!n&&t.GLGEObject){r=t.GLGEObject;delete this.GLGEObject;return r}if(n&&t&&t.GLGEObjects){return t.GLGEObjects[0]}var r=new e.Group;var i="bone"+ ++this.boneIdx;r.setName(i);if(!t){return r}if(!t.GLGEObjects)t.GLGEObjects=[];t.GLGEObjects.push(r);var s=t.firstChild;var o=e.identMatrix();var u;if(s)do{switch(s.tagName){case"node":r.addGroup(this.getNode(s));break;case"instance_node":r.addGroup(this.getNode(this.xml.getElementById(s.getAttribute("url").substr(1))));break;case"instance_visual_scene":r.addGroup(this.getNode(this.xml.getElementById(s.getAttribute("url").substr(1))));break;case"instance_light":if(this.useLights)r.addLight(this.getInstanceLight(this.xml.getElementById(s.getAttribute("url").substr(1))));break;case"instance_geometry":r.addObject(this.getInstanceGeometry(s));break;case"instance_controller":r.addObject(this.getInstanceController(s));break;case"instance_camera":if(!this.useCamera)break;r.addColladaCamera(this.getNode(this.xml.getElementById(s.getAttribute("url").substr(1))));break;case"optics":if(!this.useCamera)break;var a=s.getElementsByTagName("technique_common");if(a&&a.length>0){a=a[0].getElementsByTagName("perspective");if(a&&a.length>0){var f=a[0].getElementsByTagName("yfov");if(f&&f.length>0){r.yFov=parseFloat(f[0].textContent)}var l=a[0].getElementsByTagName("znear");if(l&&l.length>0){r.zNear=parseFloat(l[0].textContent)}var c=a[0].getElementsByTagName("zfar");if(c&&c.length>0){r.zFar=parseFloat(c[0].textContent)}}}break;case"matrix":o=this.parseArray(s);break;case"translate":u=this.parseArray(s);o=e.mulMat4(o,e.translateMatrix(u[0],u[1],u[2]));break;case"rotate":u=this.parseArray(s);o=e.mulMat4(o,e.angleAxis(u[3]*.017453278,[u[0],u[1],u[2]]));break;case"scale":u=this.parseArray(s);o=e.mulMat4(o,e.scaleMatrix(u[0],u[1],u[2]));break}}while(s=s.nextSibling);r.setLoc(o[3],o[7],o[11]);var h=e.Mat4([o[0],o[1],o[2],0,o[4],o[5],o[6],0,o[8],o[9],o[10],0,0,0,0,1]);r.setRotMatrix(h);if(n)t.GLGEObject=r;return r};e.Collada.prototype.initVisualScene=function(){var t=this.xml.getElementsByTagName("asset");var n="Z_UP";if(t.length){var r=t[0].getElementsByTagName("up_axis");if(r.length){r=r[0];var i=r.firstChild.nodeValue;if(i.length)n=i}}var s=this;if(n[0]!="Y"&&n[0]!="y"){s=new e.Group;this.addChild(s);if(n[0]!="Z"&&n[0]!="z"){s.setRotMatrix(e.Mat4([0,-1,0,0,1,0,0,0,0,0,1,0,0,0,0,1]))}else{s.setRotMatrix(e.Mat4([1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1]))}}if(!this.rootId){var o=this.xml.getElementsByTagName("scene");if(o.length>0){s.addGroup(this.getNode(o[0]))}else{e.error("Please indicate the asset to render in Collada Document"+this.url)}}else{var u=this.xml.getElementById(this.rootId);if(u){s.addGroup(this.getNode(u))}else{e.error("Asset "+this.rootId+" not found in document"+this.url)}}if(this.useCamera){var a;var f=function(e){if(e.hasCamera){a=e;return}if(!e.children){return}for(var t=0;t0){var l=a.children[0];if(l.yFov){pp.camera.fovy=l.yFov;pp.camera.pMatrix=null}if(l.zNear){pp.camera.near=l.zNear}if(l.zFar){pp.camera.far=l.zFar}}pp.camera.matrix=null;pp.camera.rotmatrix=a.rotmatrix;pp.camera.lookAt=null}}};var s={"default":{},"COLLADA Mixamo exporter":{badAccessor:true},"FBX COLLADA exporter":{badAccessor:true},"Blender2.5":{flipangle:true,negjoints:true}};e.Collada.prototype.getExceptions=function(){if(this.xml.getElementsByTagName("authoring_tool").length>0&&this.xml.getElementsByTagName("authoring_tool")[0].firstChild.nodeValue=="COLLADA Mixamo exporter"){return s["COLLADA Mixamo exporter"]}if(this.xml.getElementsByTagName("authoring_tool").length>0&&this.xml.getElementsByTagName("authoring_tool")[0].firstChild.nodeValue=="FBX COLLADA exporter"){return s["FBX COLLADA exporter"]}if(this.xml.getElementsByTagName("authoring_tool").length>0&&/Blender 2.5/.test(this.xml.getElementsByTagName("authoring_tool")[0].firstChild.nodeValue)){return s["Blender2.5"]}};e.Collada.prototype.loaded=function(e,t){this.xml=t;if(t.getElementsByTagName("authoring_tool").length>0)this.exceptions=s[t.getElementsByTagName("authoring_tool")[0].firstChild.nodeValue];this.exceptions=this.getExceptions();if(!this.exceptions)this.exceptions=s["default"];this.initVisualScene();this.getAnimations();if(this.loadedCallback){this.loadedCallback(this)}var n=this;setTimeout(function(){n.fireEvent("loaded",{url:this.url});if(n.isComplete())n.fireEvent("downloadComplete",{})},1)};e.Scene.prototype.addCollada=e.Scene.prototype.addGroup;e.Group.prototype.addCollada=e.Group.prototype.addGroup;if(e.Document){e.Document.prototype.getCollada=function(t){if(!t.object){t.object=new(e[this.classString(t.tagName)]);t.object.setDocument(t.getAttribute("document"),this.getAbsolutePath(this.rootURL,null));t.removeAttribute("document");this.setProperties(t)}return t.object}}})(GLGE);if(!GLGE){var GLGE={}}(function(e){e.HeightMap=function(e,t,n,r,s,o,u,a,f){this.canvas=document.createElement("canvas");this.context=this.canvas.getContext("2d");this.canvas.width=t;this.canvas.height=n;this.minX=r;this.maxX=s;this.minY=o;this.maxY=u;this.minZ=a;this.maxZ=f;var l=new Image;l.heightmap=this;l.onload=function(e){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]}}};l.src=e};e.HeightMap.prototype.canvas=null;e.HeightMap.prototype.context=null;e.HeightMap.prototype.minZ=null;e.HeightMap.prototype.maxZ=null;e.HeightMap.prototype.minY=null;e.HeightMap.prototype.maxY=null;e.HeightMap.prototype.minX=null;e.HeightMap.prototype.maxX=null;e.HeightMap.prototype.data=null;e.HeightMap.prototype.getPixelAt=function(e,t){if(this.data){return(this.data[(this.canvas.width*t+e)*4]-this.minImgValue)/(this.maxImgValue-this.minImgValue)*(this.maxZ-this.minZ)+this.minZ}else{return 0}};e.HeightMap.prototype.getHeightAt=function(e,t){var n;if(this.lastx!=undefined&&e==this.lastx&&t==this.lasty){n=this.lastValue}else{var r=Math.round((e-this.minX)/(this.maxX-this.minX)*this.canvas.width);var i=Math.round((t-this.minY)/(this.maxY-this.minY)*this.canvas.height);n=this.getPixelAt(r,i);this.lastValue=n}this.lastx=e;this.lasty=t;return n};e.KeyInput=function(){if(!document.keyStates)document.keyStates=[];document.addEventListener("keydown",this.onKeyDown,false);document.addEventListener("keyup",this.onKeyUp,false)};e.KeyInput.prototype.isKeyPressed=function(e){if(document.keyStates[e])return true;else return false};var t=null;e.KeyInput.prototype.onKeyDown=function(e){document.keyStates[e.keyCode]=true};e.KeyInput.prototype.onKeyUp=function(e){document.keyStates[e.keyCode]=false};e.MouseInput=function(e){this.element=e;this.element.mouseX=0;this.element.mouseY=0;if(!this.element.buttonState)this.element.buttonState=[];e.addEventListener("mousemove",this.onMouseMove,false);e.addEventListener("mousedown",this.onMouseDown,false);e.addEventListener("mouseup",this.onMouseUp,false)};e.MouseInput.prototype.element=null;e.MouseInput.prototype.onMouseMove=function(e){this.mouseX=e.clientX;this.mouseY=e.clientY};e.MouseInput.prototype.onMouseDown=function(e){this.buttonState[e.button]=true};e.MouseInput.prototype.onMouseUp=function(e){this.buttonState[e.button]=false};e.MouseInput.prototype.isButtonDown=function(e){if(this.element.buttonState[e])return true;else return false};e.MouseInput.prototype.getMousePosition=function(){return{x:this.element.mouseX,y:this.element.mouseY}};e.MI_LEFT=0;e.MI_MIDDLE=1;e.MI_RIGHT=2;e.KI_BACKSPACE=8;e.KI_TAB=9;e.KI_ENTER=13;e.KI_SHIFT=16;e.KI_CTRL=17;e.KI_ALT=18;e.KI_PAUSE_BREAK=19;e.KI_CAPS_LOCK=20;e.KI_ESCAPE=27;e.KI_PAGE_UP=33;e.KI_PAGE_DOWN=34;e.KI_END=35;e.KI_HOME=36;e.KI_LEFT_ARROW=37;e.KI_UP_ARROW=38;e.KI_RIGHT_ARROW=39;e.KI_DOWN_ARROW=40;e.KI_INSERT=45;e.KI_DELETE=46;e.KI_0=48;e.KI_1=49;e.KI_2=50;e.KI_3=51;e.KI_4=52;e.KI_5=53;e.KI_6=54;e.KI_7=55;e.KI_8=56;e.KI_9=57;e.KI_A=65;e.KI_B=66;e.KI_C=67;e.KI_D=68;e.KI_E=69;e.KI_F=70;e.KI_G=71;e.KI_H=72;e.KI_I=73;e.KI_J=74;e.KI_K=75;e.KI_L=76;e.KI_M=77;e.KI_N=78;e.KI_O=79;e.KI_P=80;e.KI_Q=81;e.KI_R=82;e.KI_S=83;e.KI_T=84;e.KI_U=85;e.KI_V=86;e.KI_W=87;e.KI_X=88;e.KI_Y=89;e.KI_Z=90;e.KI_LEFT_WINDOW_KEY=91;e.KI_RIGHT_WINDOW_KEY=92;e.KI_SELECT_KEY=93;e.KI_NUMPAD_0=96;e.KI_NUMPAD_1=97;e.KI_NUMPAD_2=98;e.KI_NUMPAD_3=99;e.KI_NUMPAD_4=100;e.KI_NUMPAD_5=101;e.KI_NUMPAD_6=102;e.KI_NUMPAD_7=103;e.KI_NUMPAD_8=104;e.KI_NUMPAD_9=105;e.KI_MULTIPLY=106;e.KI_ADD=107;e.KI_SUBTRACT=109;e.KI_DECIMAL_POINT=110;e.KI_DIVIDE=111;e.KI_F1=112;e.KI_F2=113;e.KI_F3=114;e.KI_F4=115;e.KI_F5=116;e.KI_F6=117;e.KI_F7=118;e.KI_F8=119;e.KI_F9=120;e.KI_F10=121;e.KI_F11=122;e.KI_F12=123;e.KI_NUM_LOCK=144;e.KI_SCROLL_LOCK=145;e.KI_SEMI_COLON=186;e.KI_EQUAL_SIGN=187;e.KI_COMMA=188;e.KI_DASH=189;e.KI_PERIOD=190;e.KI_FORWARD_SLASH=191;e.KI_GRAVE_ACCENT=192;e.KI_OPEN_BRACKET=219;e.KI_BACK_SLASH=220;e.KI_CLOSE_BRAKET=221;e.KI_SINGLE_QUOTE=222;e.KI_SPACE=32;if(!window.requestAnimationFrame){window.requestAnimationFrame=function(){return window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e,t){window.setTimeout(e,1e3/60)}}()}})(GLGE);(function(e){e.Scene.prototype.physicsGravity=[0,0,-9.8,0];e.Scene.prototype.getPhysicsNodes=function(t){if(!t)t=[];if(this.jigLibObj)t.push(this);if(this.children){for(var n=0;n-1){this.constraints.push(e);if(this.physicsSystem)this.physicsSystem.removeConstraint(e.constraint)}return this}})(GLGE);(function(e){e.PhysicsCar=function(t){e.PhysicsBox.call(this,t);this.wheels=[];this.setRotationalVelocityDamping([.1,.6,.1]);this.setLinearVelocityDamping([.996,.92,.996]);return this};e.augment(e.PhysicsBox,e.PhysicsCar);e.PhysicsCar.prototype.className="PhysicsCar";e.Group.prototype.addPhysicsCar=e.Group.prototype.addChild;e.Scene.prototype.addPhysicsCar=e.Group.prototype.addChild;e.PhysicsCar.prototype.drive=function(e){for(var t=0;t-1)this.wheels.splice(n,1);return e.PhsyicsBox.prototype.addChild.call(this,t)};e.PhysicsCar.prototype.getScene=function(){var e=this;while(e.parent)e=e.parent;return e};e.PhysicsCar.prototype.preProcess=function(t){var n=this.getScene();var r=this.getVelocity();var i=this.getMass();var s=this.wheels;for(var o=0;oT)N=T}if(u.driveForce){var k=u.driveForce*(1-u.braking);if(k<-x)k=x;if(k>x)k=x;this.addWorldForce(e.scaleVec3(c,k),h);N+=u.driveForce/i*t/p}if(u.braking){var L=e.dotVec3(r,c);var A=-u.braking*L/t;if(A<-x)A=-x;if(A>x)A=x;this.addWorldForce(e.scaleVec3(c,A),h)}u.angVel+=N;if(u.brake)u.angVel*=1-u.braking;u.innerGroup.setRotZ(u.innerGroup.getRotZ()-u.angVel*t);u.angVel*=.995;u.oldPos=h}e.PhysicsBox.prototype.preProcess.call(this,t)};e.PhysicsWheel=function(t){e.Group.call(this,t);this.innerGroup=new e.Group;e.Group.prototype.addChild.call(this,this.innerGroup);return this};e.augment(e.Group,e.PhysicsWheel);e.PhysicsWheel.prototype.radius=1;e.PhysicsWheel.prototype.travel=.75;e.PhysicsWheel.prototype.angVel=0;e.PhysicsWheel.prototype.spring=90;e.PhysicsWheel.prototype.braking=0;e.PhysicsWheel.prototype.driveForce=0;e.PhysicsWheel.prototype.powered=false;e.PhysicsWheel.prototype.sideFriction=3;e.PhysicsWheel.prototype.frontFriction=3;e.PhysicsWheel.prototype.className="PhysicsWheel";e.PhysicsWheel.prototype.addChild=function(e){return this.innerGroup.addChild(e)};e.PhysicsWheel.prototype.removeChild=function(e){return this.innerGroup.removeChild(e)};e.PhysicsWheel.prototype.addGroup=e.PhysicsWheel.prototype.addChild;e.PhysicsWheel.prototype.addCollada=e.PhysicsWheel.prototype.addChild;e.PhysicsWheel.prototype.addObject=e.PhysicsWheel.prototype.addChild;e.PhysicsWheel.prototype.addMD2=e.PhysicsWheel.prototype.addChild;e.PhysicsWheel.prototype.addMD3=e.PhysicsWheel.prototype.addChild;e.PhysicsWheel.prototype.addWavefront=e.PhysicsWheel.prototype.addChild;e.PhysicsWheel.prototype.setPowered=function(e){this.powered=e;return this};e.PhysicsWheel.prototype.setRadius=function(e){this.radius=e;return this};e.PhysicsWheel.prototype.setSpring=function(e){this.spring=e;return this};e.PhysicsWheel.prototype.setTravel=function(e){this.travel=e;return this};e.PhysicsWheel.prototype.setFrontFriction=function(e){this.frontFriction=e;return this};e.PhysicsWheel.prototype.setSideFriction=function(e){this.sideFriction=e;return this};e.PhysicsWheel.prototype.setWheelRotation=function(e){this.setRotY(e);return this};e.PhysicsWheel.prototype.getWheelRotation=function(e){return this.getRotY()};e.PhysicsWheel.prototype.getRadius=function(){return this.radius};e.PhysicsWheel.prototype.getSpring=function(){return this.spring};e.PhysicsWheel.prototype.getTravel=function(){return this.travel};e.PhysicsWheel.prototype.getFrontFriction=function(){return this.frontFriction};e.PhysicsWheel.prototype.getSideFriction=function(){return this.sideFriction};e.PhysicsWheel.prototype.drive=function(e){this.driveForce=e;return this};e.PhysicsWheel.prototype.brake=function(e){this.braking=e;return this}})(GLGE);(function(e){e.Wavefront=function(t){this.multimaterials=[];this.materials={};this.instances=[];this.queue=[];this.idMaterials=[];e.Object.call(this,t);e.Assets.registerAsset(this,t)};e.augment(e.Object,e.Wavefront);e.Wavefront.prototype.getAbsolutePath=function(e,t){if(e.substr(0,7)=="http://"||e.substr(0,7)=="file://"||e.substr(0,8)=="https://"){return e}else{if(!t){t=window.location.href}if(t.indexOf("?")>0){t=t.substr(0,t.indexOf("?"))}var n=t.split("/");var r=n[2];var i=n[0];var s=[];for(var o=3;o0){var n=this.queue.pop();this.loadMaterials(n,this.src)}else{this.parseMesh();this.fireEvent("loaded",{})}})}else{this.queue.push(e)}};e.Wavefront.prototype.parseMaterials=function(t){var n=0;var r=0;var i=0;var s;while(r1){switch(o[0]){case"Kd":u.setColorR(parseFloat(o[1]));u.setColorG(parseFloat(o[2]));u.setColorB(parseFloat(o[3]));break;case"Ks":u.setSpecularColor({r:parseFloat(o[1]),g:parseFloat(o[2]),b:parseFloat(o[3])});break;case"Ns":u.setShininess(parseFloat(o[1]));break;case"d":this.setZtransparent(true);u.setAlpha(parseFloat(o[1]));break;case"map_Kd":var a=new e.MaterialLayer;a.setMapto(e.M_COLOR);a.setMapinput(e.UV1);var f=new e.Texture;var l=1;while(o[l][0]=="-")l=l+2;f.setSrc(this.getAbsolutePath(o[l],this.relativeTo));u.addTexture(f);a.setTexture(f);u.addMaterialLayer(a);break;case"map_Ks":case"map_spec":var a=new e.MaterialLayer;a.setMapto(e.M_SPECULAR);a.setMapinput(e.UV1);var f=new e.Texture;var l=1;while(o[l][0]=="-")l=l+2;f.setSrc(this.getAbsolutePath(o[l],this.relativeTo));u.addTexture(f);a.setTexture(f);u.addMaterialLayer(a);break;case"bump":case"map_bump":var a=new e.MaterialLayer;a.setMapto(e.M_NOR);a.setMapinput(e.UV1);var f=new e.Texture;var l=1;while(o[l][0]=="-")l=l+2;f.setSrc(this.getAbsolutePath(o[l],this.relativeTo));u.addTexture(f);a.setTexture(f);u.addMaterialLayer(a);break}}n++;if(n>=t.length)break}r=n-1;this.materials[i]=u;this.idMaterials.push(s);i++}r++}};e.Wavefront.prototype.loadFile=function(t,n,r){this.loading=true;if(!r)r=this.loaded;if(!n&&this.relativeTo)n=this.relativeTo;t=this.getAbsolutePath(t,n);if(!this.relativeTo)this.relativeTo=t;var i=new XMLHttpRequest;var s=this;if(i){i.overrideMimeType("text/plain");i.onreadystatechange=function(){if(this.readyState==4){if(this.status==200||this.status==0){s.loading=false;r.call(s,t,this.responseText)}else{e.error("Error loading Document: "+t+" status "+this.status)}}};i.open("GET",t,true);i.send("")}};e.Wavefront.prototype.setSrc=function(e,t){this.src=this.getAbsolutePath(e,t);this.loadFile(this.src,t)};e.Wavefront.prototype.loaded=function(e,t){this.file=objArray=t.split("\n");var n=false;for(var r=0;r1){if(i[0]=="mtllib"){n=true;this.loadMaterials(i[1])}}}if(!n){this.parseMesh();this.fireEvent("loaded",{})}};e.Wavefront.prototype.createMultiMaterial=function(t,n,r,i,s,o,u,a){var f=[];var l=[];var c=[];var h=[];var p=[];var d={};for(var v=0;v0)var y=p[v].split("/");else var y=[p[v]];if(!r[y[0]-1])e.error(y[0]);f.push(r[y[0]-1][1]);f.push(r[y[0]-1][2]);f.push(r[y[0]-1][3]);if(y[1]){c.push(s[y[1]-1][1]);c.push(s[y[1]-1][2])}if(y[2]){l.push(i[y[2]-1][1]);l.push(i[y[2]-1][2]);l.push(i[y[2]-1][3])}}if(f.length/3>65024){var b=[];var w=[];var E=[];for(var v=0;v0)w.push(l[o[v]*3],l[o[v]*3+1],l[o[v]*3+2]);if(c.length>0)E.push(c[o[v]*2],c[o[v]*2+1])}f=b;l=w;c=E;o=[]}var S=new e.MultiMaterial;var x=new e.Mesh;x.setPositions(f);if(l.length>0)x.setNormals(l);if(c.length>0)x.setUV(c);if(o.length>0)x.setFaces(o);S.setMesh(x);S.setMaterial(u);this.addMultiMaterial(S)};e.Wavefront.prototype.parseMesh=function(){objArray=this.file;var t=[];var n=[];var r=[];var i=[];var s=[];var o={};var u=0;var a=true;var f=new e.Material;for(var l=0;l0){switch(c[0]){case"s":if(c[1]=="1")a=true;else a=false;case"o":if(i.length>0){this.createMultiMaterial(s,o,n,r,t,i,f,a);i=[];f=new e.Material}break;case"usemtl":if(i.length>0){this.createMultiMaterial(s,o,n,r,t,i,f,a);i=[]}if(this.idMaterials.indexOf(c[1])==-1)f=this.materials[0];else f=this.materials[this.idMaterials.indexOf(c[1])];break;case"v":n.push(c);break;case"vt":t.push(c);break;case"vn":r.push(c);break;case"f":var h=[];for(var p=1;p=this._windowSize){this._pos=0}this._streamPos=this._pos}};LZMA.OutWindow.prototype.releaseStream=function(){this.flush();this._stream=null};LZMA.OutWindow.prototype.setStream=function(e){this.releaseStream();this._stream=e};LZMA.OutWindow.prototype.init=function(e){if(!e){this._streamPos=0;this._pos=0}};LZMA.OutWindow.prototype.copyBlock=function(e,t){var n=this._pos-e-1;if(n<0){n+=this._windowSize}while(t--){if(n>=this._windowSize){n=0}this._buffer[this._pos++]=this._buffer[n++];if(this._pos>=this._windowSize){this.flush()}}};LZMA.OutWindow.prototype.putByte=function(e){this._buffer[this._pos++]=e;if(this._pos>=this._windowSize){this.flush()}};LZMA.OutWindow.prototype.getByte=function(e){var t=this._pos-e-1;if(t<0){t+=this._windowSize}return this._buffer[t]};LZMA.RangeDecoder=function(){};LZMA.RangeDecoder.prototype.setStream=function(e){this._stream=e};LZMA.RangeDecoder.prototype.releaseStream=function(){this._stream=null};LZMA.RangeDecoder.prototype.init=function(){var e=5;this._code=0;this._range=-1;while(e--){this._code=this._code<<8|this._stream.readByte()}};LZMA.RangeDecoder.prototype.decodeDirectBits=function(e){var t=0,n=e,r;while(n--){this._range>>>=1;r=this._code-this._range>>>31;this._code-=this._range&r-1;t=t<<1|1-r;if((this._range&4278190080)===0){this._code=this._code<<8|this._stream.readByte();this._range<<=8}}return t};LZMA.RangeDecoder.prototype.decodeBit=function(e,t){var n=e[t],r=(this._range>>>11)*n;if((this._code^2147483648)<(r^2147483648)){this._range=r;e[t]+=2048-n>>>5;if((this._range&4278190080)===0){this._code=this._code<<8|this._stream.readByte();this._range<<=8}return 0}this._range-=r;this._code-=r;e[t]-=n>>>5;if((this._range&4278190080)===0){this._code=this._code<<8|this._stream.readByte();this._range<<=8}return 1};LZMA.initBitModels=function(e,t){while(t--){e[t]=1024}};LZMA.BitTreeDecoder=function(e){this._models=[];this._numBitLevels=e};LZMA.BitTreeDecoder.prototype.init=function(){LZMA.initBitModels(this._models,1<>7&1;t<<=1;i=e.decodeBit(this._decoders,(1+r<<8)+n);n=n<<1|i;if(r!==i){while(n<256){n=n<<1|e.decodeBit(this._decoders,n)}break}}while(n<256);return n&255};LZMA.LiteralDecoder=function(){};LZMA.LiteralDecoder.prototype.create=function(e,t){var n;if(this._coders&&this._numPrevBits===t&&this._numPosBits===e){return}this._numPosBits=e;this._posMask=(1<>>8-this._numPrevBits)]};LZMA.Decoder=function(){this._outWindow=new LZMA.OutWindow;this._rangeDecoder=new LZMA.RangeDecoder;this._isMatchDecoders=[];this._isRepDecoders=[];this._isRepG0Decoders=[];this._isRepG1Decoders=[];this._isRepG2Decoders=[];this._isRep0LongDecoders=[];this._posSlotDecoder=[];this._posDecoders=[];this._posAlignDecoder=new LZMA.BitTreeDecoder(4);this._lenDecoder=new LZMA.LenDecoder;this._repLenDecoder=new LZMA.LenDecoder;this._literalDecoder=new LZMA.LiteralDecoder;this._dictionarySize=-1;this._dictionarySizeCheck=-1;this._posSlotDecoder[0]=new LZMA.BitTreeDecoder(6);this._posSlotDecoder[1]=new LZMA.BitTreeDecoder(6);this._posSlotDecoder[2]=new LZMA.BitTreeDecoder(6);this._posSlotDecoder[3]=new LZMA.BitTreeDecoder(6)};LZMA.Decoder.prototype.setDictionarySize=function(e){if(e<0){return false}if(this._dictionarySize!==e){this._dictionarySize=e;this._dictionarySizeCheck=Math.max(this._dictionarySize,1);this._outWindow.create(Math.max(this._dictionarySizeCheck,4096))}return true};LZMA.Decoder.prototype.setLcLpPb=function(e,t,n){var r=1<8||t>4||n>4){return false}this._literalDecoder.create(t,e);this._lenDecoder.create(r);this._repLenDecoder.create(r);this._posStateMask=r-1;return true};LZMA.Decoder.prototype.init=function(){var e=4;this._outWindow.init(false);LZMA.initBitModels(this._isMatchDecoders,192);LZMA.initBitModels(this._isRep0LongDecoders,192);LZMA.initBitModels(this._isRepDecoders,12);LZMA.initBitModels(this._isRepG0Decoders,12);LZMA.initBitModels(this._isRepG1Decoders,12);LZMA.initBitModels(this._isRepG2Decoders,12);LZMA.initBitModels(this._posDecoders,114);this._literalDecoder.init();while(e--){this._posSlotDecoder[e].init()}this._lenDecoder.init();this._repLenDecoder.init();this._posAlignDecoder.init();this._rangeDecoder.init()};LZMA.Decoder.prototype.decode=function(e,t,n){var r=0,i=0,s=0,o=0,u=0,a=0,f=0,l,c,h,p,d,v;this._rangeDecoder.setStream(e);this._outWindow.setStream(t);this.init();while(n<0||a=7){f=c.decodeWithMatchByte(this._rangeDecoder,this._outWindow.getByte(i))}else{f=c.decodeNormal(this._rangeDecoder)}this._outWindow.putByte(f);r=r<4?0:r-(r<10?3:6)}else{if(this._rangeDecoder.decodeBit(this._isRepDecoders,r)===1){h=0;if(this._rangeDecoder.decodeBit(this._isRepG0Decoders,r)===0){if(this._rangeDecoder.decodeBit(this._isRep0LongDecoders,(r<<4)+l)===0){r=r<7?9:11;h=1}}else{if(this._rangeDecoder.decodeBit(this._isRepG1Decoders,r)===0){p=s}else{if(this._rangeDecoder.decodeBit(this._isRepG2Decoders,r)===0){p=o}else{p=u;u=o}o=s}s=i;i=p}if(h===0){h=2+this._repLenDecoder.decode(this._rangeDecoder,l);r=r<7?8:11}}else{u=o;o=s;s=i;h=2+this._lenDecoder.decode(this._rangeDecoder,l);r=r<7?7:10;d=this._posSlotDecoder[h<=5?h-2:3].decode(this._rangeDecoder);if(d>=4){v=(d>>1)-1;i=(2|d&1)<=a||i>=this._dictionarySizeCheck){return false}this._outWindow.copyBlock(i,h);a+=h;f=this._outWindow.getByte(0)}}this._outWindow.flush();this._outWindow.releaseStream();this._rangeDecoder.releaseStream();return true};LZMA.Decoder.prototype.setDecoderProperties=function(e){var t,n,r,i,s;if(e.size<5){return false}t=e.readByte();n=t%9;t=~~(t/9);r=t%5;i=~~(t/5);if(!this.setLcLpPb(n,r,i)){return false}s=e.readByte();s|=e.readByte()<<8;s|=e.readByte()<<16;s+=e.readByte()*16777216;return this.setDictionarySize(s)};LZMA.decompress=function(e,t,n,r){var i=new LZMA.Decoder;if(!i.setDecoderProperties(e)){throw"Incorrect stream properties"}if(!i.decode(t,n,r)){throw"Error in data stream"}return true};LZMA.decompressFile=function(e,t){var n=new LZMA.Decoder,r;if(!n.setDecoderProperties(e)){throw"Incorrect stream properties"}r=e.readByte();r|=e.readByte()<<8;r|=e.readByte()<<16;r+=e.readByte()*16777216;e.readByte();e.readByte();e.readByte();e.readByte();if(!n.decode(e,t,r)){throw"Error in data stream"}return true};var CTM=CTM||{};CTM.CompressionMethod={RAW:5718354,MG1:3229517,MG2:3295053};CTM.Flags={NORMALS:1};CTM.File=function(e){this.load(e)};CTM.File.prototype.load=function(e){this.header=new CTM.FileHeader(e);this.body=new CTM.FileBody(this.header);this.getReader().read(e,this.body)};CTM.File.prototype.getReader=function(){var e;switch(this.header.compressionMethod){case CTM.CompressionMethod.RAW:e=new CTM.ReaderRAW;break;case CTM.CompressionMethod.MG1:e=new CTM.ReaderMG1;break;case CTM.CompressionMethod.MG2:e=new CTM.ReaderMG2;break}return e};CTM.FileHeader=function(e){e.readInt32();this.fileFormat=e.readInt32();this.compressionMethod=e.readInt32();this.vertexCount=e.readInt32();this.triangleCount=e.readInt32();this.uvMapCount=e.readInt32();this.attrMapCount=e.readInt32();this.flags=e.readInt32();this.comment=e.readString()};CTM.FileHeader.prototype.hasNormals=function(){return this.flags&CTM.Flags.NORMALS};CTM.FileBody=function(e){var t=e.triangleCount*3,n=e.vertexCount*3,r=e.hasNormals()?e.vertexCount*3:0,i=e.vertexCount*2,s=e.vertexCount*4,o=0;var u=new ArrayBuffer((t+n+r+i*e.uvMapCount+s*e.attrMapCount)*4);this.indices=new Uint32Array(u,0,t);this.vertices=new Float32Array(u,t*4,n);if(e.hasNormals()){this.normals=new Float32Array(u,(t+n)*4,r)}if(e.uvMapCount){this.uvMaps=[];for(o=0;o0){e[2]+=e[0]}for(;n1e-20){l/=h;c/=h}e[d]=t[d]*f+(t[d+1]*c-t[d+2]*l)*a-c*u;e[d+1]=t[d+1]*f-(t[d+2]+t[d])*c*a+l*u;e[d+2]=t[d+2]*f+(t[d]*l+t[d+1]*c)*a+c*u}}};CTM.restoreMap=function(e,t,n){var r,i,s=new Uint32Array(e.buffer,e.byteOffset,e.length),o=0,u,a=e.length;for(;o>1):i>>1;e[u]=r*n}}};CTM.calcSmoothNormals=function(e,t){var n=new Float32Array(t.length),r,i,s,o,u,a,f,l,c,h,p,d,v,m,g;for(m=0,g=e.length;m1e-10){o/=v;u/=v;a/=v}n[r]+=o;n[r+1]+=u;n[r+2]+=a;n[i]+=o;n[i+1]+=u;n[i+2]+=a;n[s]+=o;n[s+1]+=u;n[s+2]+=a}for(m=0,g=n.length;m1e-10){n[m]/=v;n[m+1]/=v;n[m+2]/=v}}return n};CTM.isLittleEndian=function(){var e=new ArrayBuffer(2),t=new Uint8Array(e),n=new Uint16Array(e);t[0]=1;return n[0]===1}();CTM.InterleavedStream=function(e,t){this.data=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);this.offset=CTM.isLittleEndian?3:0;this.count=t*4;this.len=this.data.length};CTM.InterleavedStream.prototype.writeByte=function(e){this.data[this.offset]=e;this.offset+=this.count;if(this.offset>=this.len){this.offset-=this.len-4;if(this.offset>=this.count){this.offset-=this.count+(CTM.isLittleEndian?1:-1)}}};CTM.Stream=function(e){this.data=e;this.offset=0};CTM.Stream.prototype.TWO_POW_MINUS23=Math.pow(2,-23);CTM.Stream.prototype.TWO_POW_MINUS126=Math.pow(2,-126);CTM.Stream.prototype.readByte=function(){return this.data.charCodeAt(this.offset++)&255};CTM.Stream.prototype.readInt32=function(){var e=this.readByte();e|=this.readByte()<<8;e|=this.readByte()<<16;return e|this.readByte()<<24};CTM.Stream.prototype.readFloat32=function(){var e=this.readByte();e+=this.readByte()<<8;var t=this.readByte();var n=this.readByte();e+=(t&127)<<16;var r=(n&127)<<1|(t&128)>>>7;var i=n&128?-1:1;if(r===255){return e!==0?NaN:i*Infinity}if(r>0){return i*(1+e*this.TWO_POW_MINUS23)*Math.pow(2,r-127)}if(e!==0){return i*e*this.TWO_POW_MINUS126}return i*0};CTM.Stream.prototype.readString=function(){var e=this.readInt32();this.offset+=e;return this.data.substr(this.offset-e,e)};CTM.Stream.prototype.readArrayInt32=function(e){var t=0,n=e.length;while(t0){t=t.substr(0,t.indexOf("?"))}var n=t.split("/");var r=n[2];var i=n[0];var s=[];for(var o=3;o65024){var o=[];var u=[];var a=[];for(var f=0;f0)u.push(r[s[f]*3],r[s[f]*3+1],r[s[f]*3+2]);if(i.length>0)a.push(i[s[f]*2],i[s[f]*2+1])}n=o;r=u;i=a;s=[]}var l=new e.Mesh;l.setPositions(n);if(r.length>0)l.setNormals(r);if(i.length>0)l.setUV(i);if(s.length>0)l.setFaces(s);this.setMesh(l)};e.Document.prototype.getOpenCTM=function(t){if(!t.object){var n=this.getAbsolutePath(this.rootURL,null);t.object=new(e[this.classString(t.tagName)]);t.object.setSrc(t.getAttribute("src"),n);t.removeAttribute("src");this.setProperties(t)}return t.object};e.Scene.prototype.addOpenCTM=e.Scene.prototype.addObject})(GLGE);(function(e){if(typeof e.GUI=="undefined"){e.GUI={}}(function(t){t.useLibrary=function(e){if(e=="jQuery"&&jQuery){t.Progressbar.prototype.setValue=function(e){$(this.domRoot).progressbar({value:e})};t.Progressbar.prototype.init=function(){$(this.domRoot).progressbar({value:0})}}};t.Widget=function(){this.domRoot=document.createElement("div");this.domRoot.setAttribute("class","glge-gui-widget-root");this.init()};t.Widget.prototype.domRoot=null;t.Widget.prototype.init=function(){};t.Progressbar=function(){this.baseclass.call(this);this.domRoot.className+=" glge-gui-progressbar"};t.Progressbar.prototype.value=0;t.Progressbar.prototype.setValue=function(e){this.value=e};e.augment(t.Widget,t.Progressbar)})(e.GUI)})(GLGE);(function(e){if(typeof e.GUI=="undefined"){e.GUI={}}(function(e){e.Gadget=function(){this.domGadgetRoot=document.createElement("div");this.domGadgetRoot.setAttribute("class","glge-gui-gadget-root");this.domGadgetRoot.style.position="absolute";this.domGadgetRoot.style.top="0px";this.domGadgetOuterWrapper=document.createElement("div");this.domGadgetOuterWrapper.setAttribute("class","glge-gui-gadget-OuterWrapper");this.domGadgetOuterWrapper.style.position="relative";this.domGadgetRoot.appendChild(this.domGadgetOuterWrapper);this.domGadgetInnerWrapper=document.createElement("div");this.domGadgetInnerWrapper.setAttribute("class","glge-gui-gadget-InnerWrapper");this.domGadgetInnerWrapper.style.position="relative";this.domGadgetOuterWrapper.appendChild(this.domGadgetInnerWrapper);this.domGadgetObject=document.createElement("div");this.domGadgetObject.setAttribute("class","glge-gui-gadget");this.domGadgetObject.style.position="relative";this.domGadgetInnerWrapper.appendChild(this.domGadgetObject);this.domGadgetFooter=document.createElement("div");this.domGadgetFooter.setAttribute("class","glge-gui-gadget-footer");this.domGadgetFooter.style.clear="both";this.domGadgetRoot.appendChild(this.domGadgetFooter);this.position={};this.position.x="middle";this.position.y="middle";this.updatePosition()};e.Gadget.prototype.domGadgetRoot=null;e.Gadget.prototype.domGadgetOuterWrapper=null;e.Gadget.prototype.domGadgetInnerWrapper=null;e.Gadget.prototype.domGadgetObject=null;e.Gadget.prototype.domGadgetFooter=null;e.Gadget.prototype.domGadgetParent=null;e.Gadget.prototype.position=null;e.Gadget.prototype.setPosition=function(e){if(e){if(e.x)this.position.x=e.x;if(e.y)this.position.y=e.y}this.updatePosition()};e.Gadget.prototype.updatePosition=function(){if(!this.domGadgetParent)return;var e="";if(document.defaultView&&document.defaultView.getComputedStyle)e=document.defaultView.getComputedStyle(this.domGadgetParent,null).getPropertyValue("position");else if(this.domGadgetParent.currentStyle)e=this.domGadgetParent.currentStyle["position"];if(e=="absolute"){this.domGadgetRoot.style.width="100%";this.domGadgetRoot.style.height="100%";this.domGadgetRoot.style.display="table";this.domGadgetOuterWrapper.style.display="table-cell";if(this.position.y=="top"){this.domGadgetOuterWrapper.style.verticalAlign="top"}else if(this.position.y=="middle"){this.domGadgetOuterWrapper.style.verticalAlign="middle"}else if(this.position.y=="bottom"){this.domGadgetOuterWrapper.style.verticalAlign="bottom"}if(this.position.x=="left"){this.domGadgetInnerWrapper.style.cssFloat="left";this.domGadgetInnerWrapper.style.left="0px";this.domGadgetObject.style.cssFloat="left";this.domGadgetObject.style.left="0px"}else if(this.position.x=="middle"){this.domGadgetInnerWrapper.style.cssFloat="right";this.domGadgetInnerWrapper.style.right="50%";this.domGadgetObject.style.cssFloat="left";this.domGadgetObject.style.right="-50%"}else if(this.position.x=="right"){this.domGadgetInnerWrapper.style.cssFloat="right";this.domGadgetInnerWrapper.style.right="0px";this.domGadgetObject.style.cssFloat="right";this.domGadgetObject.style.right="0px"}}else{if(this.position.y=="top"){this.domGadgetRoot.style.top=this.domGadgetParent.offsetTop}else if(this.position.y=="middle"){this.domGadgetRoot.style.top=this.domGadgetParent.offsetTop+this.domGadgetParent.offsetHeight/2-this.domGadgetRoot.offsetHeight/2}else if(this.position.y=="bottom"){this.domGadgetRoot.style.top=this.domGadgetParent.offsetTop+this.domGadgetParent.offsetHeight-this.domGadgetRoot.offsetHeight}if(this.position.x=="left"){this.domGadgetRoot.style.left=this.domGadgetParent.offsetLeft}else if(this.position.x=="middle"){this.domGadgetRoot.style.left=this.domGadgetParent.offsetLeft+this.domGadgetParent.offsetWidth/2-this.domGadgetRoot.offsetWidth/2}else if(this.position.x=="right"){this.domGadgetRoot.style.left=this.domGadgetParent.offsetLeft+this.domGadgetParent.offsetWidth-this.domGadgetRoot.offsetWidth}}};e.Gadget.prototype.addToDOM=function(e,t){this.domGadgetParent=e;this.domGadgetParent.appendChild(this.domGadgetRoot);this.setPosition(t)}})(e.GUI)})(GLGE);(function(e){(function(t){t.Preloader=function(){this.baseclass.call(this);this.domGadgetObject.innerHTML="

Loading

";this.domGadgetObject.className+=" glge-gui-gadget-preloader";this.progressBar=new t.Progressbar;this.domGadgetObject.appendChild(this.progressBar.domRoot);this.domPercentageLabel=document.createElement("div");this.domPercentageLabel.setAttribute("class","glge-gui-gadget-preloader-percentage");this.domPercentageLabel.innerHTML="
0%
100%
";this.domGadgetObject.appendChild(this.domPercentageLabel);this.domInfoBox=document.createElement("div");this.domInfoBox.setAttribute("class","glge-gui-gadget-preloader-info");this.domInfoBox.setAttribute("style","clear:both;");this.domGadgetObject.appendChild(this.domInfoBox);this.domStateLabel=document.createElement("div");this.domInfoBox.appendChild(this.domStateLabel);this.domBytesLabel=document.createElement("div");this.domInfoBox.appendChild(this.domBytesLabel);this.domFilesLabel=document.createElement("div");this.domInfoBox.appendChild(this.domFilesLabel);this.domLastFileLabel=document.createElement("div");this.domInfoBox.appendChild(this.domLastFileLabel)};t.Preloader.prototype.progressBar=null;t.Preloader.prototype.documentLoader=null;t.Preloader.prototype.domInfoBox=null;t.Preloader.prototype.domStateLabel=null;t.Preloader.prototype.domBytesLabel=null;t.Preloader.prototype.domFilesLabel=null;t.Preloader.prototype.domLastFileLabel=null;t.Preloader.prototype.domPercentageLabel=null;t.Preloader.prototype.setDocumentLoader=function(e){this.documentLoader=e;var t=this;this.documentLoader.addEventListener("downloadComplete",function(e){t.complete(e)});this.documentLoader.addEventListener("progress",function(e){t.progress(e)});this.documentLoader.addEventListener("stateChange",function(e){t.stateChange(e)});this.documentLoader.addEventListener("fileLoaded",function(e){t.fileLoaded(e)})};t.Preloader.prototype.addToDOM=function(e,t){this.stateChange(this.documentLoader.state);this.progress({progress:0,loadedBytes:0,loadedFiles:0,totalFiles:0,totalBytes:0});this.fileLoaded({});this.baseclass.addToDOM.call(this,e,t)};t.Preloader.prototype.progress=function(e){this.progressBar.setValue(e.progress);this.domBytesLabel.innerHTML=e.loadedBytes+" of "+e.totalBytes+" Bytes loaded";this.domFilesLabel.innerHTML=e.loadedFiles+" of "+e.totalFiles+" Files loaded"};t.Preloader.prototype.complete=function(e){this.progressBar.setValue(100);var t=this;setTimeout(function(){t.domGadgetRoot.parentNode.removeChild(t.domGadgetRoot)},300)};t.Preloader.prototype.stateChange=function(e){switch(e){case 0:case 1:this.domStateLabel.innerHTML="Step 1 of 2: Loading XML";break;case 2:case 3:this.domStateLabel.innerHTML="Step 2 of 2: Loading Textures";break}};t.Preloader.prototype.fileLoaded=function(e){if(e.url){var t=e.url;if(t.length>40){t=t.slice(-37);t="..."+t}this.domLastFileLabel.innerHTML='Last file loaded: "'+t+'"'}else if(this.domLastFileLabel.innerHTML=="")this.domLastFileLabel.innerHTML="Last file loaded: none"};e.augment(t.Gadget,t.Preloader)})(e.GUI)})(GLGE);(function(e){e.FilePreloader=function(){this.files=[]};e.augment(e.Events,e.FilePreloader);e.FilePreloader.prototype.loadedBytes=0;e.FilePreloader.prototype.totalBytes=0;e.FilePreloader.prototype.numLoadedFiles=0;e.FilePreloader.prototype.numTotalFiles=0;e.FilePreloader.prototype.sizesCount=0;e.FilePreloader.prototype.progress=0;e.FilePreloader.prototype.files=null;e.FilePreloader.prototype.addFile=function(e,t,n){this.files.push({url:e,loaded:false,size:-1,bytesLoaded:0,type:t,callback:n,content:null,preloader:this});this.numTotalFiles++};e.FilePreloader.prototype.addFileRef=function(e){this.files.push(e);this.numTotalFiles++};e.FilePreloader.prototype.accumulateFileSize=function(e){var t=new XMLHttpRequest;t.preloader=this;t.active=true;t.file=e;t.overrideMimeType("text/xml");t.onreadystatechange=function(){if(this.readyState>1&&t.active){this.active=false;this.file.size=parseFloat(this.getResponseHeader("Content-length"));this.preloader.totalBytes+=this.file.size;if(++this.preloader.sizesCount>=this.preloader.files.length)this.preloader.loadFiles();this.abort();this.onreadystatechange=null}};t.open("GET",e.url,true);t.send("")};e.FilePreloader.prototype.start=function(){for(i in this.files)this.accumulateFileSize(this.files[i])};e.FilePreloader.prototype.loadFiles=function(){for(i in this.files){var e=this.files[i];if(e.type=="image"){var t=new Image;e.content=t;var n=this;t.file=e;t.onload=function(){n.fileLoaded(this.file,this.file.size)};t.src=e.url}else{var r=new XMLHttpRequest;r.overrideMimeType("text/xml");r.preloader=this;r.file=e;var s=setInterval(function(){if(r.readyState==3){var t=r.responseText.length-e.bytesLoaded;e.bytesLoaded=r.responseText.length;r.preloader.update(t)}},100);r.onreadystatechange=function(){if(this.readyState>=4){clearInterval(s);this.file.content=this.responseXML;var e=this.responseText.length-this.file.bytesLoaded;this.preloader.update(e);this.preloader.fileLoaded(this.file,e)}};r.open("GET",e.url,true);r.send()}}};e.FilePreloader.prototype.update=function(e){this.loadedBytes+=e;this.progress=100*this.loadedBytes/this.totalBytes;this.fireEvent("progress",{progress:this.progress,stepBytes:e,loadedBytes:this.loadedBytes,totalBytes:this.totalBytes,loadedFiles:this.numLoadedFiles,totalFiles:this.numTotalFiles})};e.FilePreloader.prototype.fileLoaded=function(e,t){this.numLoadedFiles++;e.loaded=true;e.bytesLoaded=e.size;if(this.numLoadedFiles>=this.files.length){this.progress=100;this.fireEvent("downloadComplete",{file:e,stepBytes:t})}else{this.update(t)}this.fireEvent("fileLoaded",{file:e,stepBytes:t});if(e.callback)e.callback(e)};e.FilePreloader.prototype.getLoadedFiles=function(){var e=[];for(i in this.files)if(this.files[i].loaded)e.push(this.files[i]);return e};e.FilePreloader.prototype.getFile=function(e){for(i in this.files)if(this.files[i].url==e)return this.files[i];return-1}})(GLGE);(function(e){e.DocumentPreloader=function(t,n){this.imagePreloader=new e.FilePreloader;this.document=t;if(n.XMLQuota)this.XMLQuota=n.XMLQuota;else this.XMLQuota=.2;this.imageQuota=1-this.XMLQuota;if(n.XMLBytes)this.XMLBytes=n.XMLBytes;else if(n.numXMLFiles)this.numXMLFiles=n.numXMLFiles;else this.numXMLFiles=3};e.augment(e.Events,e.DocumentPreloader);e.DocumentPreloader.prototype.progress=0;e.DocumentPreloader.prototype.imageQuota=0;e.DocumentPreloader.prototype.XMLQuota=0;e.DocumentPreloader.prototype.XMLBytes=-1;e.DocumentPreloader.prototype.totalBytes=-1;e.DocumentPreloader.prototype.loadedBytes=0;e.DocumentPreloader.prototype.numXMLFiles=3;e.DocumentPreloader.prototype.state=0;e.DocumentPreloader.prototype.imagePreloader=null;e.DocumentPreloader.prototype.document=null;e.DocumentPreloader.prototype.addImage=function(e){this.imagePreloader.addFile(e,"image")};e.DocumentPreloader.prototype.loadImages=function(){this.changeState(2);if(this.progress0){this.loadedBytes+=e.stepBytes;this.progress=this.XMLQuota*100*this.loadedBytes/this.XMLBytes}else{this.progress+=this.XMLQuota*100/this.numXMLFiles;if(this.progress>this.XMLQuota*100)this.progress=this.XMLQuota*100}}else{this.progress=this.XMLQuota*100+this.imageQuota*this.imagePreloader.progress}this.fireEvent("progress",{progress:this.progress,stepBytes:e.stepBytes,loadedBytes:e.loadedBytes,totalBytes:e.totalBytes,loadedFiles:e.loadedFiles,totalFiles:e.totalFiles})};e.DocumentPreloader.prototype.loadXMLFile=function(t){this.changeState(1);var n=new e.FilePreloader;n.addFile(t,"xml");var r=this;if(this.XMLBytes>0)n.addEventListener("progress",function(e){r.updateProgress.call(r,e)});else n.addEventListener("downloadComplete",function(e){r.updateProgress.call(r,e)});var i=this.document;n.addEventListener("fileLoaded",function(e){e.file.content.getElementById=i.getElementById;i.loaded(e.file.url,e.file.content);r.fireEvent("fileLoaded",e.file)});n.start()};e.DocumentPreloader.prototype.changeState=function(e){this.state=e;this.fireEvent("stateChange",e)};e.DocumentPreloader.prototype.finish=function(e){this.changeState(3);this.progress=100;this.fireEvent("downloadComplete")}})(GLGE) \ No newline at end of file diff --git a/glge-compiled.js b/glge-compiled.js index 785aa15..7ec7835 100644 --- a/glge-compiled.js +++ b/glge-compiled.js @@ -3937,7 +3937,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * @event fires when and object is added as a child * @param {object} event */ - + /** * @name GLGE.Group#childRemoved * @event fires when and object is removed @@ -3945,17 +3945,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** -* @constant +* @constant * @description Enumeration for node group type */ GLGE.G_NODE=1; /** -* @constant +* @constant * @description Enumeration for root group type */ GLGE.G_ROOT=2; /** -* @class Group class to allow object transform hierarchies +* @class Group class to allow object transform hierarchies * @augments GLGE.Animatable * @augments GLGE.Placeable * @augments GLGE.QuickNotation @@ -3994,7 +3994,7 @@ GLGE.Group.prototype.setVisible=function(visible){ * @returns flag to indicate the objects visibility */ GLGE.Group.prototype.getVisible=function(){ - return this.visaible; + return this.visible; } /** @@ -4036,7 +4036,7 @@ GLGE.Group.prototype.getNames=function(names){ } /** * Gets the bounding volume for this group -* @returns {GLGE.BoundingVolume} +* @returns {GLGE.BoundingVolume} */ GLGE.Group.prototype.getBoundingVolume=function(local){ this.boundingVolume=null; @@ -4055,7 +4055,7 @@ GLGE.Group.prototype.getBoundingVolume=function(local){ }else{ this.boundingVolume.applyMatrix(this.getModelMatrix()); } - + return this.boundingVolume; } /** @@ -4116,7 +4116,7 @@ GLGE.Group.prototype.updateAllPrograms=function(){ GLGE.Group.prototype.addChild=function(object){ if(object.parent) object.parent.removeChild(object); if(this.noCastShadows!=null && object.noCastShadows==null && object.setCastShadows) object.setCastShadows(!this.noCastShadows); - + GLGE.reuseMatrix4(object.matrix); object.matrix=null; //clear any cache object.parent=this; @@ -4126,7 +4126,7 @@ GLGE.Group.prototype.addChild=function(object){ var root=object; while(root.parent) root=root.parent; root.updateAllPrograms(); - } + } if(object.addEventListener){ object.addEventListener("shaderupdate",function(){ var root=this; @@ -4170,10 +4170,10 @@ GLGE.Group.prototype.removeChild=function(child){ } else { if (this.children.length <= child) return; - + object = this.children[child]; } - + if(this.children[child].removeEventListener){ this.children[child].removeEventListener("downloadComplete",this.downloadComplete); } @@ -6750,7 +6750,7 @@ GLGE.Material.prototype.registerPasses=function(gl,object){ * @private */ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection,shadow){ - var shader="#ifdef GL_ES\nprecision mediump float;\n#endif\n#define GLGE_FRAGMENT\n"; + var shader="#ifdef GL_ES\nprecision highp float;\n#endif\n#define GLGE_FRAGMENT\n"; if(shadow){ shader=shader+"uniform float distance;\n"; @@ -6793,8 +6793,8 @@ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection shader=shader+"uniform vec3 lightAttenuation"+i+";\n"; shader=shader+"uniform float spotCosCutOff"+i+";\n"; shader=shader+"uniform float spotExp"+i+";\n"; - shader=shader+"uniform vec3 lightdir"+i+";\n"; - shader=shader+"uniform mat4 lightmat"+i+";\n"; + shader=shader+"uniform mediump vec3 lightdir"+i+";\n"; + shader=shader+"uniform mediump mat4 lightmat"+i+";\n"; shader=shader+"uniform float shadowbias"+i+";\n"; shader=shader+"uniform int shadowsamples"+i+";\n"; shader=shader+"uniform float shadowsoftness"+i+";\n"; @@ -6833,8 +6833,8 @@ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection shader=shader+"uniform int fogtype;\n"; shader=shader+"uniform vec3 fogcolor;\n"; shader=shader+"uniform float far;\n"; - shader=shader+"uniform mat4 worldInverseTranspose;\n"; - shader=shader+"uniform mat4 projection;\n"; + shader=shader+"uniform mediump mat4 worldInverseTranspose;\n"; + shader=shader+"uniform mediump mat4 projection;\n"; shader=shader+"uniform bool emitpass;\n"; shader=shader+"uniform bool shadeless;\n"; @@ -7023,7 +7023,7 @@ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection shader=shader+"vec4 dist;float depth,m1,m2,prob,variance;\n"; shader=shader+"if (normal.z<0.0) {normal.z=0.0;}\n"; - + shader=shader+"float fogfact=1.0;"; shader=shader+"if(fogtype=="+GLGE.FOG_QUADRATIC+" || fogtype=="+GLGE.FOG_SKYQUADRATIC+") fogfact=clamp(pow(max((fogfar - length(eyevec)) / (fogfar - fognear),0.0),2.0),0.0,1.0);\n"; shader=shader+"if(fogtype=="+GLGE.FOG_LINEAR+" || fogtype=="+GLGE.FOG_SKYLINEAR+") fogfact=clamp((fogfar - length(eyevec)) / (fogfar - fognear),0.0,1.0);\n"; @@ -7038,7 +7038,7 @@ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection shader=shader+"gl_FragColor.a=gl_FragColor.a*(1.0-min(1.0,"+this.fadeDistance.toFixed(5)+"/length(eyevec)));\n"; } shader=shader+"} else {\n"; - + for(var i=0; i0){ - relativeto=relativeto.substr(0,relativeto.indexOf("?")); - } - //find the path compoents - var bits=relativeto.split("/"); - var domain=bits[2]; - var proto=bits[0]; - var initpath=[]; - for(var i=3;i0){ - var matUrl=this.queue.pop(); - this.loadMaterials(matUrl,this.src); - }else{ - this.parseMesh(); - this.fireEvent("loaded",{}); - } +GLGE.Scene.prototype.physicsTick=function(dt,noIntegrate){ + var objects=this.getPhysicsNodes(); + if(!this.physicsSystem){ + //create the physics system + this.physicsSystem=jigLib.PhysicsSystem.getInstance(); + //this.physicsSystem.setCollisionSystem(true,-1000,-1000,-1000,2000,1000,2000,1,1,1); + this.physicsSystem.setGravity(this.physicsGravity); + for(var i=0;i1) - { - switch(data[0]){ - case "Kd": - material.setColorR(parseFloat(data[1])); - material.setColorG(parseFloat(data[2])); - material.setColorB(parseFloat(data[3])); - break; - case "Ks": - material.setSpecularColor({r:parseFloat(data[1]),g:parseFloat(data[2]),b:parseFloat(data[3])}); - break; - case "Ns": - material.setShininess(parseFloat(data[1])); - break; - case "d": - this.setZtransparent(true); - material.setAlpha(parseFloat(data[1])); - break; - case "map_Kd": - var ml=new GLGE.MaterialLayer; - ml.setMapto(GLGE.M_COLOR); - ml.setMapinput(GLGE.UV1); - var tex=new GLGE.Texture; - var k=1; - while(data[k][0]=="-") k=k+2; - tex.setSrc(this.getAbsolutePath(data[k],this.relativeTo)); - material.addTexture(tex); - ml.setTexture(tex); - material.addMaterialLayer(ml); - break; - case "map_Ks": - case "map_spec": - var ml=new GLGE.MaterialLayer; - ml.setMapto(GLGE.M_SPECULAR); - ml.setMapinput(GLGE.UV1); - var tex=new GLGE.Texture; - var k=1; - while(data[k][0]=="-") k=k+2; - tex.setSrc(this.getAbsolutePath(data[k],this.relativeTo)); - material.addTexture(tex); - ml.setTexture(tex); - material.addMaterialLayer(ml); - break; - case "bump": - case "map_bump": - var ml=new GLGE.MaterialLayer; - ml.setMapto(GLGE.M_NOR); - ml.setMapinput(GLGE.UV1); - var tex=new GLGE.Texture; - var k=1; - while(data[k][0]=="-") k=k+2; - tex.setSrc(this.getAbsolutePath(data[k],this.relativeTo)); - material.addTexture(tex); - ml.setTexture(tex); - material.addMaterialLayer(ml); - break; - } - } - j++; - if(j>=file.length) - break; - } - i=j-1; - this.materials[index]=material; - this.idMaterials.push(idNameMaterial); - index++; - } - i++; +GLGE.Scene.prototype.setGravity=function(gravity){ + this.physicsGravity=gravity; + if(this.physicsSystem){ + this.physicsSystem.setGravity(gravity); } -}; + return this; +} /** -* loads a resource from a url -* @param {string} url the url of the resource to load -* @param {string} relativeTo the url to load relative to -* @param {function} callback thefunction to call once the file is loaded -* @private +* Gets the gravity of the physics system +* @returns {number} */ -GLGE.Wavefront.prototype.loadFile=function(url,relativeTo,callback){ - this.loading=true; - if(!callback) callback=this.loaded; - if(!relativeTo && this.relativeTo) relativeTo=this.relativeTo; - url=this.getAbsolutePath(url,relativeTo); - if(!this.relativeTo) this.relativeTo=url; - var req = new XMLHttpRequest(); - var that=this; - if(req) { - req.overrideMimeType("text/plain") - req.onreadystatechange = function() { - if(this.readyState == 4) - { - if(this.status == 200 || this.status==0){ - that.loading=false; - callback.call(that,url,this.responseText); - }else{ - GLGE.error("Error loading Document: "+url+" status "+this.status); - } - } - }; - req.open("GET", url, true); - req.send(""); - } +GLGE.Scene.prototype.getGravity=function(gravity){ + return this.physicsSystem.getGravity(gravity); } + +GLGE.Group.prototype.addPhysicsPlane=GLGE.Group.prototype.addChild; +GLGE.Group.prototype.addPhysicsBox=GLGE.Group.prototype.addChild; +GLGE.Group.prototype.addPhysicsSphere=GLGE.Group.prototype.addChild; +GLGE.Group.prototype.addPhysicsMesh=GLGE.Group.prototype.addChild; +GLGE.Scene.prototype.addPhysicsPlane=GLGE.Group.prototype.addChild; +GLGE.Scene.prototype.addPhysicsBox=GLGE.Group.prototype.addChild; +GLGE.Scene.prototype.addPhysicsSphere=GLGE.Group.prototype.addChild; +GLGE.Scene.prototype.addPhysicsMesh=GLGE.Group.prototype.addChild; + +})(GLGE);/* +GLGE WebGL Graphics Engine +Copyright (c) 2010, Paul Brunt +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GLGE nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + /** -* loads a wavefront ojvect from a given url -* @param {DOM Element} url the url to retrieve -* @param {string} relativeTo optional the path the url is relative to + * @fileOverview + * @name glge_physicsabstract.js + * @author me@paulbrunt.co.uk + */ + + +(function(GLGE){ + + + +/** +* @class An abstract class used when constructing jiglib rigidbodies +* @augments GLGE.Group */ -GLGE.Wavefront.prototype.setSrc=function(url,relativeTo){ - this.src=this.getAbsolutePath(url,relativeTo); - this.loadFile(this.src,relativeTo); -}; +GLGE.PhysicsAbstract=function(uid){ + this.children=[]; +} +GLGE.augment(GLGE.Group,GLGE.PhysicsAbstract); + /** -* loads a resource from a url -* @param {string} url the url of the resource loaded -* @param {string} objfile the loaded file -* @private +* Enumeration for copy of rotation and location +**/ +GLGE.PHYSICS_ALL=1; +/** +* Enumeration for copy of location +**/ +GLGE.PHYSICS_LOC=2; + +GLGE.PhysicsAbstract.prototype.physicsType=GLGE.PHYSICS_ALL; +GLGE.PhysicsAbstract.prototype.sync=true; + + +/** +* Sets the physics type either GLGE.PHYSICS_ALL or GLGE.PHYSICS_LOC +* @param {number} value the enumerations for physics type +**/ +GLGE.PhysicsAbstract.prototype.setType=function(value){ + this.physicsType=value; + return this; +} + +/** +* Gets the physics type either GLGE.PHYSICS_ALL or GLGE.PHYSICS_LOC +**/ +GLGE.PhysicsAbstract.prototype.getType=function(value){ + return this.physicsType; +} + +/** +* function run before proceeding with the physics sim */ -GLGE.Wavefront.prototype.loaded=function(url,objfile){ - this.file=objArray=objfile.split("\n"); - var hasMaterial=false; - //loop through the file and load the Materials - for(var i=0;i1){ - if(data[0]=="mtllib"){ - hasMaterial=true; - this.loadMaterials(data[1]); - } +GLGE.PhysicsAbstract.prototype.preProcess=function(dt){ + if(this.sync){ + //update the oriantation and position within jiglib + var matrix=this.getModelMatrix(); + this.jigLibObj.moveTo([matrix[3],matrix[7],matrix[11],0]); + if(this.physicsType==1){ + var sx=Math.sqrt(matrix[0]*matrix[0]+matrix[1]*matrix[1]+matrix[2]*matrix[2]); + var sy=Math.sqrt(matrix[4]*matrix[4]+matrix[5]*matrix[5]+matrix[6]*matrix[6]); + var sz=Math.sqrt(matrix[8]*matrix[8]+matrix[9]*matrix[9]+matrix[10]*matrix[10]); + this.jigLibObj.setOrientation(new jigLib.Matrix3D([matrix[0]/sx,matrix[1]/sx,matrix[2]/sx,0,matrix[4]/sy,matrix[5]/sy,matrix[6]/sy,0,matrix[8]/sz,matrix[9]/sz,matrix[10]/sz,0,0,0,0,1])); } + this.sync=false; } - if(!hasMaterial){ - this.parseMesh(); - this.fireEvent("loaded",{}); - } - -}; +} + /** -* creates a new multimaterial +* get_transform gets the transform matrix +* @type jigLib.Matrix3D +* @private +**/ +GLGE.PhysicsAbstract.prototype.get_transform=function(){ + return new jigLib.Matrix3D(this.getModelMatrix()); +} + +/** +* Updates the model matrix and flag physics system to sync * @private */ -GLGE.Wavefront.prototype.createMultiMaterial=function(idxDataOrig,idxDataOrigMap,verts,norms,texCoords,faces,material,smooth){ - //loop though the indexes to produce streams - var positions=[]; - var normals=[]; - var uv=[]; - var newfaces=[]; - var idxData=[]; - var idxDataMap={}; - for(var i=0;i0) var vertData=idxData[i].split("/"); - else var vertData=[idxData[i]]; - if(!verts[vertData[0]-1]) GLGE.error(vertData[0]); - positions.push(verts[vertData[0]-1][1]); - positions.push(verts[vertData[0]-1][2]); - positions.push(verts[vertData[0]-1][3]); - if(vertData[1]){ - uv.push(texCoords[vertData[1]-1][1]); - uv.push(texCoords[vertData[1]-1][2]); - } - if(vertData[2]){ - normals.push(norms[vertData[2]-1][1]); - normals.push(norms[vertData[2]-1][2]); - normals.push(norms[vertData[2]-1][3]); - } - } - if(positions.length/3>65024){ - var newPositions=[]; - var newNormals=[]; - var newUVs=[]; - for(var i=0;i0) newNormals.push(normals[faces[i]*3],normals[faces[i]*3+1],normals[faces[i]*3+2]); - if(uv.length>0) newUVs.push(uv[faces[i]*2],uv[faces[i]*2+1]); - } - positions=newPositions; - normals=newNormals; - uv=newUVs; - faces=[]; - } - var multiMat=new GLGE.MultiMaterial; - var mesh=new GLGE.Mesh; - - mesh.setPositions(positions); - if(normals.length>0) mesh.setNormals(normals); - if(uv.length>0) mesh.setUV(uv); - if(faces.length>0) mesh.setFaces(faces); - multiMat.setMesh(mesh); - multiMat.setMaterial(material); - this.addMultiMaterial(multiMat); +GLGE.PhysicsAbstract.prototype.updateMatrix=function(){ + this.globalMatrix=null; + this.sync=true; + GLGE.Placeable.prototype.updateMatrix.call(this); +} +/** +* Gets the model matrix to transform the model within the world +*/ +GLGE.PhysicsAbstract.prototype.getModelMatrix=function(){ + if(this.globalMatrix) return this.globalMatrix; + return GLGE.Placeable.prototype.getModelMatrix.call(this); } + /** -* Parses the mesh +* set_transform sets the transform matrix +* @param {Matrix3D} value * @private -*/ -GLGE.Wavefront.prototype.parseMesh=function(){ - objArray=this.file; - var texCoords=[]; - var verts=[]; - var norms=[]; - var faces=[]; - var idxData=[]; - var idxDataMap={}; - var vertoffset=0; - var smooth=true; - var material=new GLGE.Material; - for(var i=0;i0){ - switch(data[0]){ - case "s": - if(data[1]=="1") smooth=true; - else smooth=false; - case "o": - if(faces.length>0){ - this.createMultiMaterial(idxData,idxDataMap,verts,norms,texCoords,faces,material,smooth); - faces=[]; - material=new GLGE.Material; - } - break; - case "usemtl": - if(faces.length>0){ - this.createMultiMaterial(idxData,idxDataMap,verts,norms,texCoords,faces,material,smooth); - faces=[]; - } - if(this.idMaterials.indexOf(data[1]) == -1)//Material no name - material=this.materials[0];//default - else - material=this.materials[this.idMaterials.indexOf(data[1])];//get Idname material - break; - case "v": - verts.push(data); - break; - case "vt": - texCoords.push(data); - break; - case "vn": - norms.push(data); - break; - case "f": - var tmpface=[]; - for(var j=1;j= this._windowSize){ - this._pos = 0; - } - this._streamPos = this._pos; - } -}; - -LZMA.OutWindow.prototype.releaseStream = function(){ - this.flush(); - this._stream = null; -}; +/** +* Sets the angular velocity of the physics body +* @param {array} value The velocity to set +*/ +GLGE.PhysicsAbstract.prototype.setAngularVelocity=function(value){ + if(!this.getMovable()) GLGE.error("Cannot set velocity on static object"); + this.jigLibObj.setAngVel(value); + return this; +} +/** +* Sets the x-axis angular velocity of the physics body +* @param {number} value The x velocity to set +*/ +GLGE.PhysicsAbstract.prototype.setAngularVelocityX=function(value){ + if(!this.getMovable()) GLGE.error("Cannot set velocity on static object"); + var vel=this.jigLibObj.getAngVel(); + vel[0]=+value; + this.jigLibObj.setAngVel(vel); + return this; +} +/** +* Sets the y-axis angular velocity of the physics body +* @param {number} value The y velocity to set +*/ +GLGE.PhysicsAbstract.prototype.setAngularVelocityY=function(value){ + if(!this.getMovable()) GLGE.error("Cannot set velocity on static object"); + var vel=this.jigLibObj.getAngVel(); + vel[1]=+value; + this.jigLibObj.setAngVel(vel); + return this; +} +/** +* Sets the z-axis angular velocity of the physics body +* @param {number} value The z velocity to set +*/ +GLGE.PhysicsAbstract.prototype.setAngularVelocityZ=function(value){ + if(!this.getMovable()) GLGE.error("Cannot set velocity on static object"); + var vel=this.jigLibObj.getAngVel(); + vel[2]=+value; + this.jigLibObj.setAngVel(vel); + return this; +} +/** +* Gets the angular velocity of the physics body +* @returns {array} The velocity to set +*/ +GLGE.PhysicsAbstract.prototype.getAngularVelocity=function(){ + return this.jigLibObj.getAngVel(); +} +/** +* Gets the x-axis angular velocity of the physics body +* @returns {number} The x velocity to set +*/ +GLGE.PhysicsAbstract.prototype.getAngularVelocityX=function(){ + return this.jigLibObj.getAngVel()[0]; +} +/** +* Gets the y-axis angular velocity of the physics body +* @returns {number} The y velocity to set +*/ +GLGE.PhysicsAbstract.prototype.getAngularVelocityY=function(){ + return this.jigLibObj.getAngVel()[1]; +} +/** +* Gets the z-axis angular velocity of the physics body +* @returns {number} The z velocity to set +*/ +GLGE.PhysicsAbstract.prototype.getAngularVelocityZ=function(){ + return this.jigLibObj.getAngVel()[2]; +} +/** +* Sets the movable flag for the object +* @param {boolean} value The movable flag +*/ +GLGE.PhysicsAbstract.prototype.setMovable=function(value){ + this.jigLibObj.set_movable(value); + return this; +} +/** +* Gets the movable flag for the object +* @returns {boolean} The movable flag +*/ +GLGE.PhysicsAbstract.prototype.getMovable=function(){ + return this.jigLibObj.get_movable(); +} + +/** +* Sets the friction for the object +* @param {number} value The friction 0-1 +*/ +GLGE.PhysicsAbstract.prototype.setFriction=function(value){ + this.jigLibObj.set_friction(value); + return this; +} +/** +* Gets the friction for the object +* @returns {number} The friction +*/ +GLGE.PhysicsAbstract.prototype.getFriction=function(){ + return this.jigLibObj.get_friction(); +} + + +/** +* Sets the mass for the object +* @param {number} value The mass +*/ +GLGE.PhysicsAbstract.prototype.setMass=function(value){ + this.jigLibObj.set_mass(value); + return this; +} + +/** +* Gets the mass for the object +* @returns {number} The mass +*/ +GLGE.PhysicsAbstract.prototype.getMass=function(){ + return this.jigLibObj.get_mass(); +} + + +/** +* Sets the restitution for the object +* @param {number} value The restitution 0-1 +*/ +GLGE.PhysicsAbstract.prototype.setRestitution=function(value){ + this.jigLibObj.set_restitution(value); + return this; +} +/** +* Gets the restitution for the object +* @returns {number} The restitution +*/ +GLGE.PhysicsAbstract.prototype.getRestitution=function(){ + return this.jigLibObj.get_restitution(); +} + +/** +* Add forces in the body coordinate frame +* @param {array} f force expressed as a 3D vector +* @param {array} p position of origin of the force expressed as a 3D vector +**/ +GLGE.PhysicsAbstract.prototype.addBodyForce=function(f, p){ + this.jigLibObj.addBodyForce(f,p); + return this; +} + +/** +* Add forces in the world coordinate frame +* @param {array} f force expressed as a 3D vector +* @param {array} p position of origin of the force expressed as a 3D vector +**/ +GLGE.PhysicsAbstract.prototype.addWorldForce=function(f, p){ + this.jigLibObj.addWorldForce(f,p); + return this; +} + +/** +* Add torque in the world coordinate frame +* @param {array} t torque expressed as a 3D vector +**/ +GLGE.PhysicsAbstract.prototype.addWorldTorque=function(t){ + this.jigLibObj.addWorldTorque(t); + return this; +} + +/** +* Add torque in the body coordinate frame +* @param {array} t torque expressed as a 3D vector +**/ +GLGE.PhysicsAbstract.prototype.addBodyTorque=function(t){ + this.jigLibObj.addBodyTorque(t); + return this; +} +/** +* Sets the linear velocity damping +* @param {array} damping 3D vector for linear damping +**/ +GLGE.PhysicsAbstract.prototype.setLinearVelocityDamping=function(v){ + this.jigLibObj.set_linVelocityDamping(v); + return this; +} + +/** +* Gets the rotational velocity Damping +* @returns 3D vector for rotational damping +**/ +GLGE.PhysicsAbstract.prototype.getRotationalVelocityDamping=function(v){ + return this.jigLibObj.get_rotVelocityDamping(); +} + +/** +* Gets the linear velocity damping +* @returns 3D vector for linear damping +**/ +GLGE.PhysicsAbstract.prototype.getLinearVelocityDamping=function(v){ + return this.jigLibObj.get_linVelocityDamping(); +} + +/** +* Sets the rotational velocity Damping +* @param {array} damping 3D vector for rotational damping +**/ +GLGE.PhysicsAbstract.prototype.setRotationalVelocityDamping=function(v){ + this.jigLibObj.set_rotVelocityDamping(v); + return this; +} + + +/** +* Remove active force and torque +**/ +GLGE.PhysicsAbstract.prototype.clearForces=function(){ + this.jigLibObj.clearForces(); + return this; +} + + + + +})(GLGE);/* +GLGE WebGL Graphics Engine +Copyright (c) 2010, Paul Brunt +All rights reserved. -LZMA.OutWindow.prototype.setStream = function(stream){ - this.releaseStream(); - this._stream = stream; -}; +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GLGE nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. -LZMA.OutWindow.prototype.init = function(solid){ - if (!solid){ - this._streamPos = 0; - this._pos = 0; - } -}; - -LZMA.OutWindow.prototype.copyBlock = function(distance, len){ - var pos = this._pos - distance - 1; - if (pos < 0){ - pos += this._windowSize; - } - while(len --){ - if (pos >= this._windowSize){ - pos = 0; - } - this._buffer[this._pos ++] = this._buffer[pos ++]; - if (this._pos >= this._windowSize){ - this.flush(); - } - } -}; - -LZMA.OutWindow.prototype.putByte = function(b){ - this._buffer[this._pos ++] = b; - if (this._pos >= this._windowSize){ - this.flush(); - } -}; - -LZMA.OutWindow.prototype.getByte = function(distance){ - var pos = this._pos - distance - 1; - if (pos < 0){ - pos += this._windowSize; - } - return this._buffer[pos]; -}; - -LZMA.RangeDecoder = function(){ -}; +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ -LZMA.RangeDecoder.prototype.setStream = function(stream){ - this._stream = stream; -}; +/** + * @fileOverview + * @name glge_physicssphere.js + * @author me@paulbrunt.co.uk + */ -LZMA.RangeDecoder.prototype.releaseStream = function(){ - this._stream = null; -}; +(function(GLGE){ -LZMA.RangeDecoder.prototype.init = function(){ - var i = 5; +/** +* @class A wrapping class for jiglib spheres +* @augments GLGE.PhysicsAbstract +*/ +GLGE.PhysicsBox=function(uid){ + this.jigLibObj=new jigLib.JBox(this,this.width,this.height,this.depth); + this.jigLibObj.GLGE=this; + this.jigLibObj.addEventListener(jigLib.JCollisionEvent.COLLISION, function(event){this.GLGE.fireEvent("collision",{obj:event.collisionBody.GLGE,impulse:event.collisionImpulse})}); + GLGE.PhysicsAbstract.call(this,uid); +} +GLGE.augment(GLGE.PhysicsAbstract,GLGE.PhysicsBox); - this._code = 0; - this._range = -1; - - while(i --){ - this._code = (this._code << 8) | this._stream.readByte(); - } -}; +GLGE.PhysicsBox.prototype.width=1; +GLGE.PhysicsBox.prototype.height=1; +GLGE.PhysicsBox.prototype.depth=1; -LZMA.RangeDecoder.prototype.decodeDirectBits = function(numTotalBits){ - var result = 0, i = numTotalBits, t; +GLGE.PhysicsBox.prototype.className="PhysicsBox"; +/** +* Sets the width of the box +* @param {number} value The width to set +*/ +GLGE.PhysicsBox.prototype.setWidth=function(value){ + this.width=value; + var sides=this.jigLibObj.get_sideLengths(); + sides[0]=+value + this.jigLibObj.set_sideLengths(sides); + return this; +} +/** +* Sets the height of the box +* @param {number} value The height to set +*/ +GLGE.PhysicsBox.prototype.setHeight=function(value){ + this.height=value; + var sides=this.jigLibObj.get_sideLengths(); + sides[1]=+value + this.jigLibObj.set_sideLengths(sides); + return this; +} - while(i --){ - this._range >>>= 1; - t = (this._code - this._range) >>> 31; - this._code -= this._range & (t - 1); - result = (result << 1) | (1 - t); +/** +* Sets the height of the box +* @param {number} value The depth to set +*/ +GLGE.PhysicsBox.prototype.setDepth=function(value){ + this.depth=value; + var sides=this.jigLibObj.get_sideLengths(); + sides[2]=+value + this.jigLibObj.set_sideLengths(sides); + return this; +} - if ( (this._range & 0xff000000) === 0){ - this._code = (this._code << 8) | this._stream.readByte(); - this._range <<= 8; - } - } +/** +* Gets the width of the box +* @returns {number} The width to set +*/ +GLGE.PhysicsBox.prototype.getWidth=function(){ + return this.jigLibObj.get_sideLengths()[0]; +} - return result; -}; +/** +* Gets the height of the box +* @returns {number} The height to set +*/ +GLGE.PhysicsBox.prototype.getHeight=function(){ + return this.jigLibObj.get_sideLengths()[1]; +} -LZMA.RangeDecoder.prototype.decodeBit = function(probs, index){ - var prob = probs[index], - newBound = (this._range >>> 11) * prob; +/** +* Gets the depth of the box +* @returns {number} The depth to set +*/ +GLGE.PhysicsBox.prototype.getDepth=function(){ + return this.jigLibObj.get_sideLengths()[2]; +} - if ( (this._code ^ 0x80000000) < (newBound ^ 0x80000000) ){ - this._range = newBound; - probs[index] += (2048 - prob) >>> 5; - if ( (this._range & 0xff000000) === 0){ - this._code = (this._code << 8) | this._stream.readByte(); - this._range <<= 8; - } - return 0; - } +})(GLGE);/* +GLGE WebGL Graphics Engine +Copyright (c) 2010, Paul Brunt +All rights reserved. - this._range -= newBound; - this._code -= newBound; - probs[index] -= prob >>> 5; - if ( (this._range & 0xff000000) === 0){ - this._code = (this._code << 8) | this._stream.readByte(); - this._range <<= 8; - } - return 1; -}; +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GLGE nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. -LZMA.initBitModels = function(probs, len){ - while(len --){ - probs[len] = 1024; - } -}; +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ -LZMA.BitTreeDecoder = function(numBitLevels){ - this._models = []; - this._numBitLevels = numBitLevels; -}; +/** + * @fileOverview + * @name glge_physicsmesh.js + * @author me@paulbrunt.co.uk + */ -LZMA.BitTreeDecoder.prototype.init = function(){ - LZMA.initBitModels(this._models, 1 << this._numBitLevels); -}; +(function(GLGE){ -LZMA.BitTreeDecoder.prototype.decode = function(rangeDecoder){ - var m = 1, i = this._numBitLevels; +/** +* @class A wrapping class for jiglib triangle mesh +* @augments GLGE.PhysicsAbstract +*/ +GLGE.PhysicsMesh=function(uid){ + this.jigLibObj=new jigLib.JTriangleMesh(null, 100, 0.1); + this.jigLibObj.GLGE=this; + this.jigLibObj.addEventListener(jigLib.JCollisionEvent.COLLISION, function(event){this.GLGE.fireEvent("collision",{obj:event.collisionBody.GLGE,impulse:event.collisionImpulse})}); + this.dirty=true; + this.addEventListener("matrixUpdate",this.makeDirty); + this.addEventListener("childMatrixUpdate",this.makeDirty); + this.addEventListener("childAdded",this.makeDirty); + this.addEventListener("childRemoved",this.makeDirty); + + GLGE.PhysicsAbstract.call(this,uid); +} +GLGE.augment(GLGE.PhysicsAbstract,GLGE.PhysicsMesh); - while(i --){ - m = (m << 1) | rangeDecoder.decodeBit(this._models, m); - } - return m - (1 << this._numBitLevels); -}; -LZMA.BitTreeDecoder.prototype.reverseDecode = function(rangeDecoder){ - var m = 1, symbol = 0, i = 0, bit; +GLGE.PhysicsMesh.prototype.className="PhysicsMesh"; +/** +* Forces and update of the triangle mesh +*/ +GLGE.PhysicsMesh.prototype.forceUpdate=function(){ + this.dirty=true; + return this; +} - for (; i < this._numBitLevels; ++ i){ - bit = rangeDecoder.decodeBit(this._models, m); - m = (m << 1) | bit; - symbol |= bit << i; - } - return symbol; -}; +/** +* flag to regenerate trimesh and redo octtree +* @private +*/ +GLGE.PhysicsMesh.prototype.makeDirty=function(e){ + this.dirty=true; +} +/** +* called before a system intergrate +* @private +*/ +GLGE.PhysicsMesh.prototype.preProcess=function(){ + //recreate mesh and build octree + if(this.dirty){ + var triangles=this.getTriangles(); + this.jigLibObj.createMesh(triangles.verts, triangles.faces); + this.dirty=false; + } +} +/** +* Creates the jiglib triangle arrays from the containing objects +* @private +*/ +GLGE.PhysicsMesh.prototype.getTriangles=function(){ + var objs=this.getObjects(); + var verts=[]; + var faces=[]; + for(var i=0;i> 7) & 1; - matchByte <<= 1; - bit = rangeDecoder.decodeBit(this._decoders, ( (1 + matchBit) << 8) + symbol); - symbol = (symbol << 1) | bit; - if (matchBit !== bit){ - while(symbol < 0x100){ - symbol = (symbol << 1) | rangeDecoder.decodeBit(this._decoders, symbol); - } - break; - } - }while(symbol < 0x100); +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GLGE nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. - return symbol & 0xff; -}; +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ -LZMA.LiteralDecoder = function(){ -}; +/** + * @fileOverview + * @name glge_physicssphere.js + * @author me@paulbrunt.co.uk + */ -LZMA.LiteralDecoder.prototype.create = function(numPosBits, numPrevBits){ - var i; +(function(GLGE){ - if (this._coders - && (this._numPrevBits === numPrevBits) - && (this._numPosBits === numPosBits) ){ - return; - } - this._numPosBits = numPosBits; - this._posMask = (1 << numPosBits) - 1; - this._numPrevBits = numPrevBits; - - this._coders = []; - - i = 1 << (this._numPrevBits + this._numPosBits); - while(i --){ - this._coders[i] = new LZMA.Decoder2(); - } -}; - -LZMA.LiteralDecoder.prototype.init = function(){ - var i = 1 << (this._numPrevBits + this._numPosBits); - while(i --){ - this._coders[i].init(); - } -}; - -LZMA.LiteralDecoder.prototype.getDecoder = function(pos, prevByte){ - return this._coders[( (pos & this._posMask) << this._numPrevBits) - + ( (prevByte & 0xff) >>> (8 - this._numPrevBits) )]; -}; - -LZMA.Decoder = function(){ - this._outWindow = new LZMA.OutWindow(); - this._rangeDecoder = new LZMA.RangeDecoder(); - this._isMatchDecoders = []; - this._isRepDecoders = []; - this._isRepG0Decoders = []; - this._isRepG1Decoders = []; - this._isRepG2Decoders = []; - this._isRep0LongDecoders = []; - this._posSlotDecoder = []; - this._posDecoders = []; - this._posAlignDecoder = new LZMA.BitTreeDecoder(4); - this._lenDecoder = new LZMA.LenDecoder(); - this._repLenDecoder = new LZMA.LenDecoder(); - this._literalDecoder = new LZMA.LiteralDecoder(); - this._dictionarySize = -1; - this._dictionarySizeCheck = -1; - - this._posSlotDecoder[0] = new LZMA.BitTreeDecoder(6); - this._posSlotDecoder[1] = new LZMA.BitTreeDecoder(6); - this._posSlotDecoder[2] = new LZMA.BitTreeDecoder(6); - this._posSlotDecoder[3] = new LZMA.BitTreeDecoder(6); -}; - -LZMA.Decoder.prototype.setDictionarySize = function(dictionarySize){ - if (dictionarySize < 0){ - return false; - } - if (this._dictionarySize !== dictionarySize){ - this._dictionarySize = dictionarySize; - this._dictionarySizeCheck = Math.max(this._dictionarySize, 1); - this._outWindow.create( Math.max(this._dictionarySizeCheck, 4096) ); - } - return true; -}; - -LZMA.Decoder.prototype.setLcLpPb = function(lc, lp, pb){ - var numPosStates = 1 << pb; - - if (lc > 8 || lp > 4 || pb > 4){ - return false; - } - - this._literalDecoder.create(lp, lc); - - this._lenDecoder.create(numPosStates); - this._repLenDecoder.create(numPosStates); - this._posStateMask = numPosStates - 1; - - return true; -}; - -LZMA.Decoder.prototype.init = function(){ - var i = 4; - - this._outWindow.init(false); - - LZMA.initBitModels(this._isMatchDecoders, 192); - LZMA.initBitModels(this._isRep0LongDecoders, 192); - LZMA.initBitModels(this._isRepDecoders, 12); - LZMA.initBitModels(this._isRepG0Decoders, 12); - LZMA.initBitModels(this._isRepG1Decoders, 12); - LZMA.initBitModels(this._isRepG2Decoders, 12); - LZMA.initBitModels(this._posDecoders, 114); - - this._literalDecoder.init(); - - while(i --){ - this._posSlotDecoder[i].init(); - } - - this._lenDecoder.init(); - this._repLenDecoder.init(); - this._posAlignDecoder.init(); - this._rangeDecoder.init(); -}; - -LZMA.Decoder.prototype.decode = function(inStream, outStream, outSize){ - var state = 0, rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0, nowPos64 = 0, prevByte = 0, - posState, decoder2, len, distance, posSlot, numDirectBits; - - this._rangeDecoder.setStream(inStream); - this._outWindow.setStream(outStream); - - this.init(); - - while(outSize < 0 || nowPos64 < outSize){ - posState = nowPos64 & this._posStateMask; - - if (this._rangeDecoder.decodeBit(this._isMatchDecoders, (state << 4) + posState) === 0){ - decoder2 = this._literalDecoder.getDecoder(nowPos64 ++, prevByte); - - if (state >= 7){ - prevByte = decoder2.decodeWithMatchByte(this._rangeDecoder, this._outWindow.getByte(rep0) ); - }else{ - prevByte = decoder2.decodeNormal(this._rangeDecoder); - } - this._outWindow.putByte(prevByte); - - state = state < 4? 0: state - (state < 10? 3: 6); - - }else{ - - if (this._rangeDecoder.decodeBit(this._isRepDecoders, state) === 1){ - len = 0; - if (this._rangeDecoder.decodeBit(this._isRepG0Decoders, state) === 0){ - if (this._rangeDecoder.decodeBit(this._isRep0LongDecoders, (state << 4) + posState) === 0){ - state = state < 7? 9: 11; - len = 1; - } - }else{ - if (this._rangeDecoder.decodeBit(this._isRepG1Decoders, state) === 0){ - distance = rep1; - }else{ - if (this._rangeDecoder.decodeBit(this._isRepG2Decoders, state) === 0){ - distance = rep2; - }else{ - distance = rep3; - rep3 = rep2; - } - rep2 = rep1; - } - rep1 = rep0; - rep0 = distance; - } - if (len === 0){ - len = 2 + this._repLenDecoder.decode(this._rangeDecoder, posState); - state = state < 7? 8: 11; - } - }else{ - rep3 = rep2; - rep2 = rep1; - rep1 = rep0; - - len = 2 + this._lenDecoder.decode(this._rangeDecoder, posState); - state = state < 7? 7: 10; - - posSlot = this._posSlotDecoder[len <= 5? len - 2: 3].decode(this._rangeDecoder); - if (posSlot >= 4){ - - numDirectBits = (posSlot >> 1) - 1; - rep0 = (2 | (posSlot & 1) ) << numDirectBits; - - if (posSlot < 14){ - rep0 += LZMA.reverseDecode2(this._posDecoders, - rep0 - posSlot - 1, this._rangeDecoder, numDirectBits); - }else{ - rep0 += this._rangeDecoder.decodeDirectBits(numDirectBits - 4) << 4; - rep0 += this._posAlignDecoder.reverseDecode(this._rangeDecoder); - if (rep0 < 0){ - if (rep0 === -1){ - break; - } - return false; - } - } - }else{ - rep0 = posSlot; - } - } - - if (rep0 >= nowPos64 || rep0 >= this._dictionarySizeCheck){ - return false; - } - - this._outWindow.copyBlock(rep0, len); - nowPos64 += len; - prevByte = this._outWindow.getByte(0); - } - } - - this._outWindow.flush(); - this._outWindow.releaseStream(); - this._rangeDecoder.releaseStream(); - - return true; -}; - -LZMA.Decoder.prototype.setDecoderProperties = function(properties){ - var value, lc, lp, pb, dictionarySize; - - if (properties.size < 5){ - return false; - } - - value = properties.readByte(); - lc = value % 9; - value = ~~(value / 9); - lp = value % 5; - pb = ~~(value / 5); - - if ( !this.setLcLpPb(lc, lp, pb) ){ - return false; - } - - dictionarySize = properties.readByte(); - dictionarySize |= properties.readByte() << 8; - dictionarySize |= properties.readByte() << 16; - dictionarySize += properties.readByte() * 16777216; +/** +* @class A wrapping class for jiglib spheres +* @augments GLGE.PhysicsAbstract +*/ +GLGE.PhysicsSphere=function(uid){ + this.jigLibObj=new jigLib.JSphere(this,this.radius); + this.jigLibObj.GLGE=this; + this.jigLibObj.addEventListener(jigLib.JCollisionEvent.COLLISION, function(event){this.GLGE.fireEvent("collision",{obj:event.collisionBody.GLGE,impulse:event.collisionImpulse})}); + GLGE.PhysicsAbstract.call(this,uid); +} +GLGE.augment(GLGE.PhysicsAbstract,GLGE.PhysicsSphere); - return this.setDictionarySize(dictionarySize); -}; +GLGE.PhysicsSphere.prototype.radius=1; -LZMA.decompress = function(properties, inStream, outStream, outSize){ - var decoder = new LZMA.Decoder(); +GLGE.PhysicsSphere.prototype.className="PhysicsSphere"; +/** +* Sets the radius of the sphere +* @param {number} value The radius to set +*/ +GLGE.PhysicsSphere.prototype.setRadius=function(value){ + this.physicsRadius=+value; + this.jigLibObj.set_radius(+value); + return this; +} - if ( !decoder.setDecoderProperties(properties) ){ - throw "Incorrect stream properties"; - } +/** +* Gets the radius of the sphere +* @returns {number} The radius to set +*/ +GLGE.PhysicsSphere.prototype.getRadius=function(value){ + return this.jigLibObj.get_radius(); +} - if ( !decoder.decode(inStream, outStream, outSize) ){ - throw "Error in data stream"; - } - - return true; -}; - -LZMA.decompressFile = function(inStream, outStream){ - var decoder = new LZMA.Decoder(), outSize; - - if ( !decoder.setDecoderProperties(inStream) ){ - throw "Incorrect stream properties"; - } - - outSize = inStream.readByte(); - outSize |= inStream.readByte() << 8; - outSize |= inStream.readByte() << 16; - outSize += inStream.readByte() * 16777216; - - inStream.readByte(); - inStream.readByte(); - inStream.readByte(); - inStream.readByte(); - - if ( !decoder.decode(inStream, outStream, outSize) ){ - throw "Error in data stream"; - } - - return true; -}; -/* -Copyright (c) 2011 Juan Mellado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +})(GLGE);/* +GLGE WebGL Graphics Engine +Copyright (c) 2011, Paul Brunt +All rights reserved. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GLGE nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. -/* -References: -- "OpenCTM: The Open Compressed Triangle Mesh file format" by Marcus Geelnard - http://openctm.sourceforge.net/ +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -var CTM = CTM || {}; - -CTM.CompressionMethod = { - RAW: 0x00574152, - MG1: 0x0031474d, - MG2: 0x0032474d -}; +/** + * @fileOverview + * @name glge_constraintpoint.js + * @author me@paulbrunt.co.uk + */ -CTM.Flags = { - NORMALS: 0x00000001 -}; -CTM.File = function(stream){ - this.load(stream); -}; +(function(GLGE){ -CTM.File.prototype.load = function(stream){ - this.header = new CTM.FileHeader(stream); +/** +* @class A wrapping class for jiglib constraint point +* @augments GLGE.QuickNotation +* @augments GLGE.JSONLoader +*/ +GLGE.PhysicsConstraintPoint=function(){ +} +GLGE.augment(GLGE.QuickNotation,GLGE.PhysicsConstraintPoint); +GLGE.augment(GLGE.JSONLoader,GLGE.PhysicsConstraintPoint); - this.body = new CTM.FileBody(this.header); - - this.getReader().read(stream, this.body); -}; +GLGE.PhysicsConstraintPoint.constraint=null; +GLGE.PhysicsConstraintPoint.prototype.className="PhysicsConstraintPoint"; -CTM.File.prototype.getReader = function(){ - var reader; - switch(this.header.compressionMethod){ - case CTM.CompressionMethod.RAW: - reader = new CTM.ReaderRAW(); - break; - case CTM.CompressionMethod.MG1: - reader = new CTM.ReaderMG1(); - break; - case CTM.CompressionMethod.MG2: - reader = new CTM.ReaderMG2(); - break; - } +/** +* Sets the first body to use with this constraint +* @param {GLGE.PhysicsAbstract} body1 The first body +*/ +GLGE.PhysicsConstraintPoint.prototype.setBody1=function(body1){ + this.body1=body1; + this.updateConstraint(); + return this; +} +/** +* Sets the second body to use with this constraint +* @param {GLGE.PhysicsAbstract} body2 The second body +*/ +GLGE.PhysicsConstraintPoint.prototype.setBody2=function(body2){ + this.body2=body2; + this.updateConstraint(); + return this; +} +/** +* Sets the constraing point on the first body +* @param {array} bodypos1 The first body constraint point +*/ +GLGE.PhysicsConstraintPoint.prototype.setBodyPos1=function(bodypos1){ + if(typeof(bodypos1)=="string") bodypos1=bodypos1.split(","); + this.bodypos1=[parseFloat(bodypos1[0]),parseFloat(bodypos1[1]),parseFloat(bodypos1[2])]; + this.updateConstraint(); + return this; +} +/** +* Sets the constraing point on the second body +* @param {array} bodypos2 The second body constraint point +*/ +GLGE.PhysicsConstraintPoint.prototype.setBodyPos2=function(bodypos2){ + if(typeof(bodypos2)=="string") bodypos2=bodypos2.split(","); + this.bodypos2=[parseFloat(bodypos2[0]),parseFloat(bodypos2[1]),parseFloat(bodypos2[2])]; + this.updateConstraint(); + return this; +} - return reader; -}; +/** +* Updates the jiglib constraint +* @private +*/ +GLGE.PhysicsConstraintPoint.prototype.updateConstraint=function(){ + if(this.body1 && this.body2 && this.bodypos1 && this.bodypos2){ + if(this.constraint){ + if(this.parent && this.parent.physicsSystem) this.parent.physicsSystem.removeConstraint(this.constraint); + this.body1.removeConstraint(this.constraint); + this.body2.removeConstraint(this.constraint); + } + this.constraint=new jigLib.JConstraintPoint(this.body1.jigLibObj,this.bodypos1,this.body2.jigLibObj,this.bodypos2); + if(this.parent && this.parent.physicsSystem) this.parent.physicsSystem.addConstraint(this.constraint); + } +} -CTM.FileHeader = function(stream){ - stream.readInt32(); //magic "OCTM" - this.fileFormat = stream.readInt32(); - this.compressionMethod = stream.readInt32(); - this.vertexCount = stream.readInt32(); - this.triangleCount = stream.readInt32(); - this.uvMapCount = stream.readInt32(); - this.attrMapCount = stream.readInt32(); - this.flags = stream.readInt32(); - this.comment = stream.readString(); -}; +/** +* Add a new physics constraint to the scene +* @param {GLGE.PhysicsConstraintPoint} constraint The constraint to add to the scene +*/ +GLGE.Scene.prototype.addPhysicsConstraintPoint=function(constraint){ + if(!this.constraints) this.constraints=[]; + this.constraints.push(constraint); + if(this.physicsSystem) this.physicsSystem.addConstraint(constraint.constraint); + return this; +} -CTM.FileHeader.prototype.hasNormals = function(){ - return this.flags & CTM.Flags.NORMALS; -}; +/** +* Removes a physics constraint to the scene +* @param {GLGE.PhysicsConstraintPoint} constraint The constraint to remove from the scene +*/ +GLGE.Scene.prototype.removePhysicsConstraintPoint=function(constraint){ + if(!this.constraints) this.constraints=[]; + if(this.constraints.indexOf(constraint)>-1){ + this.constraints.push(constraint); + if(this.physicsSystem) this.physicsSystem.removeConstraint(constraint.constraint); + } + return this; +} -CTM.FileBody = function(header){ - var i = header.triangleCount * 3, - v = header.vertexCount * 3, - n = header.hasNormals()? header.vertexCount * 3: 0, - u = header.vertexCount * 2, - a = header.vertexCount * 4, - j = 0; - var data = new ArrayBuffer( - (i + v + n + (u * header.uvMapCount) + (a * header.attrMapCount) ) * 4); +})(GLGE);/* +GLGE WebGL Graphics Engine +Copyright (c) 2010, Paul Brunt +All rights reserved. - this.indices = new Uint32Array(data, 0, i); +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GLGE nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. - this.vertices = new Float32Array(data, i * 4, v); +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ - if ( header.hasNormals() ){ - this.normals = new Float32Array(data, (i + v) * 4, n); - } - - if (header.uvMapCount){ - this.uvMaps = []; - for (j = 0; j < header.uvMapCount; ++ j){ - this.uvMaps[j] = {uv: new Float32Array(data, - (i + v + n + (j * u) ) * 4, u) }; - } - } - - if (header.attrMapCount){ - this.attrMaps = []; - for (j = 0; j < header.attrMapCount; ++ j){ - this.attrMaps[j] = {attr: new Float32Array(data, - (i + v + n + (u * header.uvMapCount) + (j * a) ) * 4, a) }; - } - } -}; +/** + * @fileOverview + * @name glge_physicscar.js + * @author me@paulbrunt.co.uk + */ + (function(GLGE){ + +/** +* @class Physics Car class +* @augments GLGE.PhysicsBox +* @see GLGE.PhysicsWheel +*/ +GLGE.PhysicsCar=function(uid){ + GLGE.PhysicsBox.call(this,uid); + this.wheels=[]; + this.setRotationalVelocityDamping([0.1,0.6,0.1]); + this.setLinearVelocityDamping([0.996,0.92,0.996]); + return this; +} +GLGE.augment(GLGE.PhysicsBox,GLGE.PhysicsCar); +GLGE.PhysicsCar.prototype.className="PhysicsCar"; +GLGE.Group.prototype.addPhysicsCar=GLGE.Group.prototype.addChild; +GLGE.Scene.prototype.addPhysicsCar=GLGE.Group.prototype.addChild; +/** +* Applies a driving force to the car +* @param {number} force the item driving force to apply to each powered wheel +*/ +GLGE.PhysicsCar.prototype.drive=function(force){ + for(var i=0;i-1) this.wheels.splice(idx,1); + return GLGE.PhsyicsBox.prototype.addChild.call(this,wheel); +} +/** +* does the physics stuff +* @private +*/ +GLGE.PhysicsCar.prototype.getScene=function(){ + var child=this; + while(child.parent) child=child.parent; + return child; +} +/** +* does the physics stuff +* @private +*/ +GLGE.PhysicsCar.prototype.preProcess=function(dt){ + var scene=this.getScene(); + var velocity=this.getVelocity(); + var carMass=this.getMass(); + var wheels=this.wheels + for(var i=0;imaxdw) dw=maxdw; + } + if(wheel.driveForce){ + var drive=wheel.driveForce*(1-wheel.braking); + if(drive<-maxForwardForce) drive=maxForwardForce; + if(drive>maxForwardForce) drive=maxForwardForce; + this.addWorldForce(GLGE.scaleVec3(forward,drive),position); + dw+=(wheel.driveForce/carMass*dt)/wheelRadius; + } + if(wheel.braking){ + var frontVel=GLGE.dotVec3(velocity,forward); + var braking=-wheel.braking*frontVel/dt + if(braking<-maxForwardForce) braking=-maxForwardForce; + if(braking>maxForwardForce) braking=maxForwardForce; + this.addWorldForce(GLGE.scaleVec3(forward,braking),position); + } + + wheel.angVel+=dw; + if(wheel.brake) wheel.angVel*=(1-wheel.braking); + wheel.innerGroup.setRotZ(wheel.innerGroup.getRotZ()-wheel.angVel*dt); + wheel.angVel*=0.995; + wheel.oldPos=position; + + } + + GLGE.PhysicsBox.prototype.preProcess.call(this,dt); -CTM.ReaderRAW = function(){ -}; +} -CTM.ReaderRAW.prototype.read = function(stream, body){ - this.readIndices(stream, body.indices); - this.readVertices(stream, body.vertices); - - if (body.normals){ - this.readNormals(stream, body.normals); - } - if (body.uvMaps){ - this.readUVMaps(stream, body.uvMaps); - } - if (body.attrMaps){ - this.readAttrMaps(stream, body.attrMaps); - } -}; -CTM.ReaderRAW.prototype.readIndices = function(stream, indices){ - stream.readInt32(); //magic "INDX" - stream.readArrayInt32(indices); -}; +/** +* @class physics wheel class used with PhysicsCar class +* @augments GLGE.Group +* @see GLGE.PhysicsBox +*/ +GLGE.PhysicsWheel=function(uid){ + GLGE.Group.call(this,uid); + this.innerGroup=new GLGE.Group; + GLGE.Group.prototype.addChild.call(this,this.innerGroup); + return this; +} +GLGE.augment(GLGE.Group,GLGE.PhysicsWheel); +GLGE.PhysicsWheel.prototype.radius=1; +GLGE.PhysicsWheel.prototype.travel=0.75; +GLGE.PhysicsWheel.prototype.angVel=0; +GLGE.PhysicsWheel.prototype.spring=90; +GLGE.PhysicsWheel.prototype.braking=0; +GLGE.PhysicsWheel.prototype.driveForce=0; +GLGE.PhysicsWheel.prototype.powered=false; +GLGE.PhysicsWheel.prototype.sideFriction=3; //sideways friction co-efficient +GLGE.PhysicsWheel.prototype.frontFriction=3; //front friction force +GLGE.PhysicsWheel.prototype.className="PhysicsWheel"; -CTM.ReaderRAW.prototype.readVertices = function(stream, vertices){ - stream.readInt32(); //magic "VERT" - stream.readArrayFloat32(vertices); -}; +/** +* Adds a child to the wheel container +* @param {object} child a GLGE object to represent the wheel +*/ +GLGE.PhysicsWheel.prototype.addChild=function(child){ + return this.innerGroup.addChild(child); +} +/** +* Removes a child to the wheel container +* @param {object} child a GLGE object to represent the wheel +*/ +GLGE.PhysicsWheel.prototype.removeChild=function(child){ + return this.innerGroup.removeChild(child); +} +GLGE.PhysicsWheel.prototype.addGroup=GLGE.PhysicsWheel.prototype.addChild; +GLGE.PhysicsWheel.prototype.addCollada=GLGE.PhysicsWheel.prototype.addChild; +GLGE.PhysicsWheel.prototype.addObject=GLGE.PhysicsWheel.prototype.addChild; +GLGE.PhysicsWheel.prototype.addMD2=GLGE.PhysicsWheel.prototype.addChild; +GLGE.PhysicsWheel.prototype.addMD3=GLGE.PhysicsWheel.prototype.addChild; +GLGE.PhysicsWheel.prototype.addWavefront=GLGE.PhysicsWheel.prototype.addChild; -CTM.ReaderRAW.prototype.readNormals = function(stream, normals){ - stream.readInt32(); //magic "NORM" - stream.readArrayFloat32(normals); -}; -CTM.ReaderRAW.prototype.readUVMaps = function(stream, uvMaps){ - var i = 0; - for (; i < uvMaps.length; ++ i){ - stream.readInt32(); //magic "TEXC" - - uvMaps[i].name = stream.readString(); - uvMaps[i].filename = stream.readString(); - stream.readArrayFloat32(uvMaps[i].uv); - } -}; +/** +* Sets the wheel to be a powered wheel +* @param {boolean} powered flag indicateding if wheel is powered +*/ +GLGE.PhysicsWheel.prototype.setPowered=function(powered){ + this.powered=powered; + return this; +} -CTM.ReaderRAW.prototype.readAttrMaps = function(stream, attrMaps){ - var i = 0; - for (; i < attrMaps.length; ++ i){ - stream.readInt32(); //magic "ATTR" +/** +* Sets the wheel Radius +* @param {number} radius the wheel radius +*/ +GLGE.PhysicsWheel.prototype.setRadius=function(radius){ + this.radius=radius; + return this; +} +/** +* Sets the suspension spring distance +* @param {number} radius the wheel radius +*/ +GLGE.PhysicsWheel.prototype.setSpring=function(spring){ + this.spring=spring; + return this; +} +/** +* Sets the suspension travel distance +* @param {number} travel the suspension travel +*/ +GLGE.PhysicsWheel.prototype.setTravel=function(travel){ + this.travel=travel; + return this; +} +/** +* Sets the front friction coefficient +* @param {number} friction the front fricition coefficient +*/ +GLGE.PhysicsWheel.prototype.setFrontFriction=function(friction){ + this.frontFriction=friction; + return this; +} +/** +* Sets the side friction coefficient +* @param {number} friction the side fricition coefficient +*/ +GLGE.PhysicsWheel.prototype.setSideFriction=function(friction){ + this.sideFriction=friction; + return this; +} +/** +* Sets the wheel Rotation +* @param {number} rotation the rotation of the wheel +*/ +GLGE.PhysicsWheel.prototype.setWheelRotation=function(rotation){ + this.setRotY(rotation); + return this; +} +/** +* Gets the wheel Rotation +* @returns the wheel roation in radians +*/ +GLGE.PhysicsWheel.prototype.getWheelRotation=function(rotation){ + return this.getRotY(); +} +/** +* Gets the wheel Radius +* @returns the wheel radius +*/ +GLGE.PhysicsWheel.prototype.getRadius=function(){ + return this.radius; +} +/** +* Gets the suspension spring +* @returns the wheel radius +*/ +GLGE.PhysicsWheel.prototype.getSpring=function(){ + return this.spring; +} +/** +* Gets the suspension travel distance +* @returns the suspension travel +*/ +GLGE.PhysicsWheel.prototype.getTravel=function(){ + return this.travel; +} +/** +* Gets the front friction coefficient +* @returns the front fricition coefficient +*/ +GLGE.PhysicsWheel.prototype.getFrontFriction=function(){ + return this.frontFriction; +} +/** +* Gets the side friction coefficient +* @returns the side fricition coefficient +*/ +GLGE.PhysicsWheel.prototype.getSideFriction=function(){ + return this.sideFriction; +} - attrMaps[i].name = stream.readString(); - stream.readArrayFloat32(attrMaps[i].attr); - } -}; +/** +* Sets a driving force for the wheel +* @param {number} force the driving force in N +*/ +GLGE.PhysicsWheel.prototype.drive=function(force){ + this.driveForce=force; + return this; +} +/** +* Sets the braking level +* @param {number} brake 0-1 value indicating the level of braking +*/ +GLGE.PhysicsWheel.prototype.brake=function(brake){ + this.braking=brake; + return this; +} -CTM.ReaderMG1 = function(){ -}; +})(GLGE);/* +GLGE WebGL Graphics Engine +Copyright (c) 2010, Paul Brunt +All rights reserved. -CTM.ReaderMG1.prototype.read = function(stream, body){ - this.readIndices(stream, body.indices); - this.readVertices(stream, body.vertices); - - if (body.normals){ - this.readNormals(stream, body.normals); - } - if (body.uvMaps){ - this.readUVMaps(stream, body.uvMaps); - } - if (body.attrMaps){ - this.readAttrMaps(stream, body.attrMaps); - } -}; +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GLGE nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. -CTM.ReaderMG1.prototype.readIndices = function(stream, indices){ - stream.readInt32(); //magic "INDX" - stream.readInt32(); //packed size - - var interleaved = new CTM.InterleavedStream(indices, 3); - LZMA.decompress(stream, stream, interleaved, interleaved.data.length); +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ - CTM.restoreIndices(indices, indices.length); -}; +/** + * @fileOverview + * @name glge_wavefront.js + * @author me@paulbrunt.co.uk + */ -CTM.ReaderMG1.prototype.readVertices = function(stream, vertices){ - stream.readInt32(); //magic "VERT" - stream.readInt32(); //packed size - - var interleaved = new CTM.InterleavedStream(vertices, 1); - LZMA.decompress(stream, stream, interleaved, interleaved.data.length); +(function(GLGE){ +/** +* @class parses and displays a warefront object file with mtl material +* @param {string} uid the unique id for this object +* @augments GLGE.Object +*/ +GLGE.Wavefront=function(uid){ + this.multimaterials=[]; + this.materials={}; + this.instances=[]; + this.queue=[]; + this.idMaterials = [];//storaged name of material (string) + GLGE.Object.call(this,uid); + GLGE.Assets.registerAsset(this,uid); +} +GLGE.augment(GLGE.Object,GLGE.Wavefront); +/** +* Gets the absolute path given an import path and the path it's relative to +* @param {string} path the path to get the absolute path for +* @param {string} relativeto the path the supplied path is relativeto +* @returns {string} absolute path +* @private +*/ +GLGE.Wavefront.prototype.getAbsolutePath=function(path,relativeto){ + if(path.substr(0,7)=="http://" || path.substr(0,7)=="file://" || path.substr(0,8)=="https://"){ + return path; + } + else + { + if(!relativeto){ + relativeto=window.location.href; + } + if(relativeto.indexOf("?")>0){ + relativeto=relativeto.substr(0,relativeto.indexOf("?")); + } + //find the path compoents + var bits=relativeto.split("/"); + var domain=bits[2]; + var proto=bits[0]; + var initpath=[]; + for(var i=3;i0){ + var matUrl=this.queue.pop(); + this.loadMaterials(matUrl,this.src); + }else{ + this.parseMesh(); + this.fireEvent("loaded",{}); + } + }); + }else{ + this.queue.push(url); + } -CTM.ReaderMG2.prototype.read = function(stream, body){ - this.MG2Header = new CTM.FileMG2Header(stream); - - this.readVertices(stream, body.vertices); - this.readIndices(stream, body.indices); - - if (body.normals){ - this.readNormals(stream, body); - } - if (body.uvMaps){ - this.readUVMaps(stream, body.uvMaps); - } - if (body.attrMaps){ - this.readAttrMaps(stream, body.attrMaps); - } }; - -CTM.ReaderMG2.prototype.readVertices = function(stream, vertices){ - stream.readInt32(); //magic "VERT" - stream.readInt32(); //packed size - - var interleaved = new CTM.InterleavedStream(vertices, 3); - LZMA.decompress(stream, stream, interleaved, interleaved.data.length); - - var gridIndices = this.readGridIndices(stream, vertices); - - CTM.restoreVertices(vertices, this.MG2Header, gridIndices, this.MG2Header.vertexPrecision); +/** +* creates the GLGE materials from a mtl file +* @param {string} file the file to parse +* @private +*/ +GLGE.Wavefront.prototype.parseMaterials=function(file){ + //loop though all lines and look for matlibs + var j = 0; + var i = 0; + var index = 0; + var idNameMaterial; + while(i1) + { + switch(data[0]){ + case "Kd": + material.setColorR(parseFloat(data[1])); + material.setColorG(parseFloat(data[2])); + material.setColorB(parseFloat(data[3])); + break; + case "Ks": + material.setSpecularColor({r:parseFloat(data[1]),g:parseFloat(data[2]),b:parseFloat(data[3])}); + break; + case "Ns": + material.setShininess(parseFloat(data[1])); + break; + case "d": + this.setZtransparent(true); + material.setAlpha(parseFloat(data[1])); + break; + case "map_Kd": + var ml=new GLGE.MaterialLayer; + ml.setMapto(GLGE.M_COLOR); + ml.setMapinput(GLGE.UV1); + var tex=new GLGE.Texture; + var k=1; + while(data[k][0]=="-") k=k+2; + tex.setSrc(this.getAbsolutePath(data[k],this.relativeTo)); + material.addTexture(tex); + ml.setTexture(tex); + material.addMaterialLayer(ml); + break; + case "map_Ks": + case "map_spec": + var ml=new GLGE.MaterialLayer; + ml.setMapto(GLGE.M_SPECULAR); + ml.setMapinput(GLGE.UV1); + var tex=new GLGE.Texture; + var k=1; + while(data[k][0]=="-") k=k+2; + tex.setSrc(this.getAbsolutePath(data[k],this.relativeTo)); + material.addTexture(tex); + ml.setTexture(tex); + material.addMaterialLayer(ml); + break; + case "bump": + case "map_bump": + var ml=new GLGE.MaterialLayer; + ml.setMapto(GLGE.M_NOR); + ml.setMapinput(GLGE.UV1); + var tex=new GLGE.Texture; + var k=1; + while(data[k][0]=="-") k=k+2; + tex.setSrc(this.getAbsolutePath(data[k],this.relativeTo)); + material.addTexture(tex); + ml.setTexture(tex); + material.addMaterialLayer(ml); + break; + } + } + j++; + if(j>=file.length) + break; + } + i=j-1; + this.materials[index]=material; + this.idMaterials.push(idNameMaterial); + index++; + } + i++; + } }; - -CTM.ReaderMG2.prototype.readGridIndices = function(stream, vertices){ - stream.readInt32(); //magic "GIDX" - stream.readInt32(); //packed size - - var gridIndices = new Uint32Array(vertices.length / 3); - - var interleaved = new CTM.InterleavedStream(gridIndices, 1); - LZMA.decompress(stream, stream, interleaved, interleaved.data.length); - - CTM.restoreGridIndices(gridIndices, gridIndices.length); - - return gridIndices; +/** +* loads a resource from a url +* @param {string} url the url of the resource to load +* @param {string} relativeTo the url to load relative to +* @param {function} callback thefunction to call once the file is loaded +* @private +*/ +GLGE.Wavefront.prototype.loadFile=function(url,relativeTo,callback){ + this.loading=true; + if(!callback) callback=this.loaded; + if(!relativeTo && this.relativeTo) relativeTo=this.relativeTo; + url=this.getAbsolutePath(url,relativeTo); + if(!this.relativeTo) this.relativeTo=url; + var req = new XMLHttpRequest(); + var that=this; + if(req) { + req.overrideMimeType("text/plain") + req.onreadystatechange = function() { + if(this.readyState == 4) + { + if(this.status == 200 || this.status==0){ + that.loading=false; + callback.call(that,url,this.responseText); + }else{ + GLGE.error("Error loading Document: "+url+" status "+this.status); + } + } + }; + req.open("GET", url, true); + req.send(""); + } +} +/** +* loads a wavefront ojvect from a given url +* @param {DOM Element} url the url to retrieve +* @param {string} relativeTo optional the path the url is relative to +*/ +GLGE.Wavefront.prototype.setSrc=function(url,relativeTo){ + this.src=this.getAbsolutePath(url,relativeTo); + this.loadFile(this.src,relativeTo); }; - -CTM.ReaderMG2.prototype.readIndices = function(stream, indices){ - stream.readInt32(); //magic "INDX" - stream.readInt32(); //packed size - - var interleaved = new CTM.InterleavedStream(indices, 3); - LZMA.decompress(stream, stream, interleaved, interleaved.data.length); - - CTM.restoreIndices(indices, indices.length); -}; - -CTM.ReaderMG2.prototype.readNormals = function(stream, body){ - stream.readInt32(); //magic "NORM" - stream.readInt32(); //packed size - - var interleaved = new CTM.InterleavedStream(body.normals, 3); - LZMA.decompress(stream, stream, interleaved, interleaved.data.length); - - var smooth = CTM.calcSmoothNormals(body.indices, body.vertices); - - CTM.restoreNormals(body.normals, smooth, this.MG2Header.normalPrecision); -}; - -CTM.ReaderMG2.prototype.readUVMaps = function(stream, uvMaps){ - var i = 0; - for (; i < uvMaps.length; ++ i){ - stream.readInt32(); //magic "TEXC" - - uvMaps[i].name = stream.readString(); - uvMaps[i].filename = stream.readString(); - - var precision = stream.readFloat32(); - - stream.readInt32(); //packed size - - var interleaved = new CTM.InterleavedStream(uvMaps[i].uv, 2); - LZMA.decompress(stream, stream, interleaved, interleaved.data.length); - - CTM.restoreMap(uvMaps[i].uv, 2, precision); - } -}; - -CTM.ReaderMG2.prototype.readAttrMaps = function(stream, attrMaps){ - var i = 0; - for (; i < attrMaps.length; ++ i){ - stream.readInt32(); //magic "ATTR" - - attrMaps[i].name = stream.readString(); - - var precision = stream.readFloat32(); - - stream.readInt32(); //packed size - - var interleaved = new CTM.InterleavedStream(attrMaps[i].attr, 4); - LZMA.decompress(stream, stream, interleaved, interleaved.data.length); - - CTM.restoreMap(attrMaps[i].attr, 4, precision); - } -}; - -CTM.restoreIndices = function(indices, len){ - var i = 3; - if (len > 0){ - indices[2] += indices[0]; - } - for (; i < len; i += 3){ - indices[i] += indices[i - 3]; - - if (indices[i] === indices[i - 3]){ - indices[i + 1] += indices[i - 2]; - }else{ - indices[i + 1] += indices[i]; - } - - indices[i + 2] += indices[i]; - } +/** +* loads a resource from a url +* @param {string} url the url of the resource loaded +* @param {string} objfile the loaded file +* @private +*/ +GLGE.Wavefront.prototype.loaded=function(url,objfile){ + this.file=objArray=objfile.split("\n"); + var hasMaterial=false; + //loop through the file and load the Materials + for(var i=0;i1){ + if(data[0]=="mtllib"){ + hasMaterial=true; + this.loadMaterials(data[1]); + } + } + } + if(!hasMaterial){ + this.parseMesh(); + this.fireEvent("loaded",{}); + } + }; +/** +* creates a new multimaterial +* @private +*/ +GLGE.Wavefront.prototype.createMultiMaterial=function(idxDataOrig,idxDataOrigMap,verts,norms,texCoords,faces,material,smooth){ + //loop though the indexes to produce streams + var positions=[]; + var normals=[]; + var uv=[]; + var newfaces=[]; + var idxData=[]; + var idxDataMap={}; + for(var i=0;i0) var vertData=idxData[i].split("/"); + else var vertData=[idxData[i]]; + if(!verts[vertData[0]-1]) GLGE.error(vertData[0]); + positions.push(verts[vertData[0]-1][1]); + positions.push(verts[vertData[0]-1][2]); + positions.push(verts[vertData[0]-1][3]); + if(vertData[1]){ + uv.push(texCoords[vertData[1]-1][1]); + uv.push(texCoords[vertData[1]-1][2]); + } + if(vertData[2]){ + normals.push(norms[vertData[2]-1][1]); + normals.push(norms[vertData[2]-1][2]); + normals.push(norms[vertData[2]-1][3]); + } + } + if(positions.length/3>65024){ + var newPositions=[]; + var newNormals=[]; + var newUVs=[]; + for(var i=0;i0) newNormals.push(normals[faces[i]*3],normals[faces[i]*3+1],normals[faces[i]*3+2]); + if(uv.length>0) newUVs.push(uv[faces[i]*2],uv[faces[i]*2+1]); + } + positions=newPositions; + normals=newNormals; + uv=newUVs; + faces=[]; + } + var multiMat=new GLGE.MultiMaterial; + var mesh=new GLGE.Mesh; + + mesh.setPositions(positions); + if(normals.length>0) mesh.setNormals(normals); + if(uv.length>0) mesh.setUV(uv); + if(faces.length>0) mesh.setFaces(faces); + multiMat.setMesh(mesh); + multiMat.setMaterial(material); + this.addMultiMaterial(multiMat); -CTM.restoreGridIndices = function(gridIndices, len){ - var i = 1; - for (; i < len; ++ i){ - gridIndices[i] += gridIndices[i - 1]; - } +} +/** +* Parses the mesh +* @private +*/ +GLGE.Wavefront.prototype.parseMesh=function(){ + objArray=this.file; + var texCoords=[]; + var verts=[]; + var norms=[]; + var faces=[]; + var idxData=[]; + var idxDataMap={}; + var vertoffset=0; + var smooth=true; + var material=new GLGE.Material; + for(var i=0;i0){ + switch(data[0]){ + case "s": + if(data[1]=="1") smooth=true; + else smooth=false; + case "o": + if(faces.length>0){ + this.createMultiMaterial(idxData,idxDataMap,verts,norms,texCoords,faces,material,smooth); + faces=[]; + material=new GLGE.Material; + } + break; + case "usemtl": + if(faces.length>0){ + this.createMultiMaterial(idxData,idxDataMap,verts,norms,texCoords,faces,material,smooth); + faces=[]; + } + if(this.idMaterials.indexOf(data[1]) == -1)//Material no name + material=this.materials[0];//default + else + material=this.materials[this.idMaterials.indexOf(data[1])];//get Idname material + break; + case "v": + verts.push(data); + break; + case "vt": + texCoords.push(data); + break; + case "vn": + norms.push(data); + break; + case "f": + var tmpface=[]; + for(var j=1;j 1e-20){ - by /= len; - bz /= len; - } - - normals[i] = smooth[i] * nz + - (smooth[i + 1] * bz - smooth[i + 2] * by) * ny - bz * nx; - normals[i + 1] = smooth[i + 1] * nz - - (smooth[i + 2] + smooth[i] ) * bz * ny + by * nx; - normals[i + 2] = smooth[i + 2] * nz + - (smooth[i] * by + smooth[i + 1] * bz) * ny + bz * nx; - } - } -}; - -CTM.restoreMap = function(map, count, precision){ - var delta, value, - intMap = new Uint32Array(map.buffer, map.byteOffset, map.length), - i = 0, j, len = map.length; - - for (; i < count; ++ i){ - delta = 0; - - for (j = i; j < len; j += count){ - value = intMap[j]; - - delta += value & 1? -( (value + 1) >> 1): value >> 1; - - map[j] = delta * precision; - } - } -}; - -CTM.calcSmoothNormals = function(indices, vertices){ - var smooth = new Float32Array(vertices.length), - indx, indy, indz, nx, ny, nz, - v1x, v1y, v1z, v2x, v2y, v2z, len, - i, k; - - for (i = 0, k = indices.length; i < k;){ - indx = indices[i ++] * 3; - indy = indices[i ++] * 3; - indz = indices[i ++] * 3; - - v1x = vertices[indy] - vertices[indx]; - v2x = vertices[indz] - vertices[indx]; - v1y = vertices[indy + 1] - vertices[indx + 1]; - v2y = vertices[indz + 1] - vertices[indx + 1]; - v1z = vertices[indy + 2] - vertices[indx + 2]; - v2z = vertices[indz + 2] - vertices[indx + 2]; - - nx = v1y * v2z - v1z * v2y; - ny = v1z * v2x - v1x * v2z; - nz = v1x * v2y - v1y * v2x; - - len = Math.sqrt(nx * nx + ny * ny + nz * nz); - if (len > 1e-10){ - nx /= len; - ny /= len; - nz /= len; - } - - smooth[indx] += nx; - smooth[indx + 1] += ny; - smooth[indx + 2] += nz; - smooth[indy] += nx; - smooth[indy + 1] += ny; - smooth[indy + 2] += nz; - smooth[indz] += nx; - smooth[indz + 1] += ny; - smooth[indz + 2] += nz; - } - - for (i = 0, k = smooth.length; i < k; i += 3){ - len = Math.sqrt(smooth[i] * smooth[i] + - smooth[i + 1] * smooth[i + 1] + - smooth[i + 2] * smooth[i + 2]); - - if(len > 1e-10){ - smooth[i] /= len; - smooth[i + 1] /= len; - smooth[i + 2] /= len; - } - } - - return smooth; -}; - -CTM.isLittleEndian = (function(){ - var buffer = new ArrayBuffer(2), - bytes = new Uint8Array(buffer), - ints = new Uint16Array(buffer); - - bytes[0] = 1; - - return ints[0] === 1; -}()); - -CTM.InterleavedStream = function(data, count){ - this.data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); - this.offset = CTM.isLittleEndian? 3: 0; - this.count = count * 4; - this.len = this.data.length; -}; - -CTM.InterleavedStream.prototype.writeByte = function(value){ - this.data[this.offset] = value; - - this.offset += this.count; - if (this.offset >= this.len){ - - this.offset -= this.len - 4; - if (this.offset >= this.count){ - - this.offset -= this.count + (CTM.isLittleEndian? 1: -1); - } - } -}; - -CTM.Stream = function(data){ - this.data = data; - this.offset = 0; -}; - -CTM.Stream.prototype.TWO_POW_MINUS23 = Math.pow(2, -23); - -CTM.Stream.prototype.TWO_POW_MINUS126 = Math.pow(2, -126); - -CTM.Stream.prototype.readByte = function(){ - return this.data.charCodeAt(this.offset ++) & 0xff; -}; - -CTM.Stream.prototype.readInt32 = function(){ - var i = this.readByte(); - i |= this.readByte() << 8; - i |= this.readByte() << 16; - return i | (this.readByte() << 24); -}; - -CTM.Stream.prototype.readFloat32 = function(){ - var m = this.readByte(); - m += this.readByte() << 8; - - var b1 = this.readByte(); - var b2 = this.readByte(); - - m += (b1 & 0x7f) << 16; - var e = ( (b2 & 0x7f) << 1) | ( (b1 & 0x80) >>> 7); - var s = b2 & 0x80? -1: 1; - - if (e === 255){ - return m !== 0? NaN: s * Infinity; - } - if (e > 0){ - return s * (1 + (m * this.TWO_POW_MINUS23) ) * Math.pow(2, e - 127); - } - if (m !== 0){ - return s * m * this.TWO_POW_MINUS126; - } - return s * 0; -}; - -CTM.Stream.prototype.readString = function(){ - var len = this.readInt32(); - - this.offset += len; - - return this.data.substr(this.offset - len, len); -}; - -CTM.Stream.prototype.readArrayInt32 = function(array){ - var i = 0, len = array.length; - - while(i < len){ - array[i ++] = this.readInt32(); - } - - return array; -}; - -CTM.Stream.prototype.readArrayFloat32 = function(array){ - var i = 0, len = array.length; - - while(i < len){ - array[i ++] = this.readFloat32(); - } - - return array; -}; -/* -GLGE WebGL Graphics Engine -Copyright (c) 2010, Paul Brunt -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of GLGE nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - * @fileOverview - * @name glge_wavefront.js - * @author me@paulbrunt.co.uk - */ - -(function(GLGE){ -/** -* @class parses and displays a warefront object file with mtl material -* @param {string} uid the unique id for this object -* @augments GLGE.Object -*/ -GLGE.OpenCTM=function(uid){ - this.multimaterials=[]; - this.materials={}; - this.instances=[]; - this.queue=[]; - this.idMaterials = [];//storaged name of material (string) - GLGE.Object.call(this,uid); - GLGE.Assets.registerAsset(this,uid); -} -GLGE.augment(GLGE.Object,GLGE.OpenCTM); -/** -* Gets the absolute path given an import path and the path it's relative to -* @param {string} path the path to get the absolute path for -* @param {string} relativeto the path the supplied path is relativeto -* @returns {string} absolute path -* @private -*/ -GLGE.OpenCTM.prototype.getAbsolutePath=function(path,relativeto){ - if(path.substr(0,7)=="http://" || path.substr(0,7)=="file://" || path.substr(0,7)=="https://"){ - return path; - } - else - { - if(!relativeto){ - relativeto=window.location.href; - } - if(relativeto.indexOf("?")>0){ - relativeto=relativeto.substr(0,relativeto.indexOf("?")); - } - //find the path compoents - var bits=relativeto.split("/"); - var domain=bits[2]; - var proto=bits[0]; - var initpath=[]; - for(var i=3;i65024) { - var newPositions=[]; - var newNormals=[]; - var newUVs=[]; - for (var i=0; i0) newNormals.push(normals[faces[i]*3],normals[faces[i]*3+1],normals[faces[i]*3+2]); - if(uv.length>0) newUVs.push(uv[faces[i]*2],uv[faces[i]*2+1]); - } - positions=newPositions; - normals=newNormals; - uv=newUVs; - faces=[]; - } - - var mesh=new GLGE.Mesh; - mesh.setPositions(positions); - if(normals.length>0) mesh.setNormals(normals); - if(uv.length>0) mesh.setUV(uv); - if(faces.length>0) mesh.setFaces(faces); - this.setMesh(mesh); -}; - -/** -* Parses the dom element and creates a texture -* @param {domelement} ele the element to create the objects from -* @private -*/ -GLGE.Document.prototype.getOpenCTM=function(ele){ - if(!ele.object){ - var rel=this.getAbsolutePath(this.rootURL,null); - ele.object=new GLGE[this.classString(ele.tagName)]; - //ele.object.setSrc(this.getAbsolutePath(ele.getAttribute("src"),rel)); - ele.object.setSrc(ele.getAttribute("src"),rel); - ele.removeAttribute("src"); - this.setProperties(ele); - } - return ele.object; -} - -GLGE.Scene.prototype.addOpenCTM=GLGE.Scene.prototype.addObject; -})(GLGE); - -/* -GLGE WebGL Graphics Engine -Copyright (c) 2011, Paul Brunt -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of GLGE nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - * @fileOverview - * @name glge_physicsext.js - * @author me@paulbrunt.co.uk - */ - - -(function(GLGE){ - - -GLGE.Scene.prototype.physicsGravity=[0,0,-9.8,0]; - -/** -* retrives the phsyics assets from the scene -* @returns {array} the physics assets -*/ -GLGE.Scene.prototype.getPhysicsNodes=function(ret){ - if(!ret) ret=[]; - if(this.jigLibObj) ret.push(this); - if(this.children){ - for(var i=0;i-1){ - this.constraints.push(constraint); - if(this.physicsSystem) this.physicsSystem.removeConstraint(constraint.constraint); - } - return this; -} - - -})(GLGE);/* -GLGE WebGL Graphics Engine -Copyright (c) 2010, Paul Brunt -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of GLGE nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - * @fileOverview - * @name glge_physicscar.js - * @author me@paulbrunt.co.uk - */ - (function(GLGE){ - -/** -* @class Physics Car class -* @augments GLGE.PhysicsBox -* @see GLGE.PhysicsWheel -*/ -GLGE.PhysicsCar=function(uid){ - GLGE.PhysicsBox.call(this,uid); - this.wheels=[]; - this.setRotationalVelocityDamping([0.1,0.6,0.1]); - this.setLinearVelocityDamping([0.996,0.92,0.996]); - return this; -} -GLGE.augment(GLGE.PhysicsBox,GLGE.PhysicsCar); -GLGE.PhysicsCar.prototype.className="PhysicsCar"; -GLGE.Group.prototype.addPhysicsCar=GLGE.Group.prototype.addChild; -GLGE.Scene.prototype.addPhysicsCar=GLGE.Group.prototype.addChild; -/** -* Applies a driving force to the car -* @param {number} force the item driving force to apply to each powered wheel -*/ -GLGE.PhysicsCar.prototype.drive=function(force){ - for(var i=0;i-1) this.wheels.splice(idx,1); - return GLGE.PhsyicsBox.prototype.addChild.call(this,wheel); -} -/** -* does the physics stuff -* @private -*/ -GLGE.PhysicsCar.prototype.getScene=function(){ - var child=this; - while(child.parent) child=child.parent; - return child; -} -/** -* does the physics stuff -* @private -*/ -GLGE.PhysicsCar.prototype.preProcess=function(dt){ - var scene=this.getScene(); - var velocity=this.getVelocity(); - var carMass=this.getMass(); - var wheels=this.wheels - for(var i=0;imaxdw) dw=maxdw; - } - if(wheel.driveForce){ - var drive=wheel.driveForce*(1-wheel.braking); - if(drive<-maxForwardForce) drive=maxForwardForce; - if(drive>maxForwardForce) drive=maxForwardForce; - this.addWorldForce(GLGE.scaleVec3(forward,drive),position); - dw+=(wheel.driveForce/carMass*dt)/wheelRadius; - } - if(wheel.braking){ - var frontVel=GLGE.dotVec3(velocity,forward); - var braking=-wheel.braking*frontVel/dt - if(braking<-maxForwardForce) braking=-maxForwardForce; - if(braking>maxForwardForce) braking=maxForwardForce; - this.addWorldForce(GLGE.scaleVec3(forward,braking),position); - } - - wheel.angVel+=dw; - if(wheel.brake) wheel.angVel*=(1-wheel.braking); - wheel.innerGroup.setRotZ(wheel.innerGroup.getRotZ()-wheel.angVel*dt); - wheel.angVel*=0.995; - wheel.oldPos=position; - - } - - GLGE.PhysicsBox.prototype.preProcess.call(this,dt); - -} - - -/** -* @class physics wheel class used with PhysicsCar class -* @augments GLGE.Group -* @see GLGE.PhysicsBox -*/ -GLGE.PhysicsWheel=function(uid){ - GLGE.Group.call(this,uid); - this.innerGroup=new GLGE.Group; - GLGE.Group.prototype.addChild.call(this,this.innerGroup); - return this; -} -GLGE.augment(GLGE.Group,GLGE.PhysicsWheel); -GLGE.PhysicsWheel.prototype.radius=1; -GLGE.PhysicsWheel.prototype.travel=0.75; -GLGE.PhysicsWheel.prototype.angVel=0; -GLGE.PhysicsWheel.prototype.spring=90; -GLGE.PhysicsWheel.prototype.braking=0; -GLGE.PhysicsWheel.prototype.driveForce=0; -GLGE.PhysicsWheel.prototype.powered=false; -GLGE.PhysicsWheel.prototype.sideFriction=3; //sideways friction co-efficient -GLGE.PhysicsWheel.prototype.frontFriction=3; //front friction force -GLGE.PhysicsWheel.prototype.className="PhysicsWheel"; - -/** -* Adds a child to the wheel container -* @param {object} child a GLGE object to represent the wheel -*/ -GLGE.PhysicsWheel.prototype.addChild=function(child){ - return this.innerGroup.addChild(child); -} -/** -* Removes a child to the wheel container -* @param {object} child a GLGE object to represent the wheel -*/ -GLGE.PhysicsWheel.prototype.removeChild=function(child){ - return this.innerGroup.removeChild(child); -} -GLGE.PhysicsWheel.prototype.addGroup=GLGE.PhysicsWheel.prototype.addChild; -GLGE.PhysicsWheel.prototype.addCollada=GLGE.PhysicsWheel.prototype.addChild; -GLGE.PhysicsWheel.prototype.addObject=GLGE.PhysicsWheel.prototype.addChild; -GLGE.PhysicsWheel.prototype.addMD2=GLGE.PhysicsWheel.prototype.addChild; -GLGE.PhysicsWheel.prototype.addMD3=GLGE.PhysicsWheel.prototype.addChild; -GLGE.PhysicsWheel.prototype.addWavefront=GLGE.PhysicsWheel.prototype.addChild; - - -/** -* Sets the wheel to be a powered wheel -* @param {boolean} powered flag indicateding if wheel is powered -*/ -GLGE.PhysicsWheel.prototype.setPowered=function(powered){ - this.powered=powered; - return this; -} - -/** -* Sets the wheel Radius -* @param {number} radius the wheel radius -*/ -GLGE.PhysicsWheel.prototype.setRadius=function(radius){ - this.radius=radius; - return this; -} -/** -* Sets the suspension spring distance -* @param {number} radius the wheel radius -*/ -GLGE.PhysicsWheel.prototype.setSpring=function(spring){ - this.spring=spring; - return this; -} -/** -* Sets the suspension travel distance -* @param {number} travel the suspension travel -*/ -GLGE.PhysicsWheel.prototype.setTravel=function(travel){ - this.travel=travel; - return this; -} -/** -* Sets the front friction coefficient -* @param {number} friction the front fricition coefficient -*/ -GLGE.PhysicsWheel.prototype.setFrontFriction=function(friction){ - this.frontFriction=friction; - return this; -} -/** -* Sets the side friction coefficient -* @param {number} friction the side fricition coefficient -*/ -GLGE.PhysicsWheel.prototype.setSideFriction=function(friction){ - this.sideFriction=friction; - return this; -} -/** -* Sets the wheel Rotation -* @param {number} rotation the rotation of the wheel -*/ -GLGE.PhysicsWheel.prototype.setWheelRotation=function(rotation){ - this.setRotY(rotation); - return this; -} -/** -* Gets the wheel Rotation -* @returns the wheel roation in radians -*/ -GLGE.PhysicsWheel.prototype.getWheelRotation=function(rotation){ - return this.getRotY(); -} -/** -* Gets the wheel Radius -* @returns the wheel radius -*/ -GLGE.PhysicsWheel.prototype.getRadius=function(){ - return this.radius; -} -/** -* Gets the suspension spring -* @returns the wheel radius -*/ -GLGE.PhysicsWheel.prototype.getSpring=function(){ - return this.spring; -} -/** -* Gets the suspension travel distance -* @returns the suspension travel -*/ -GLGE.PhysicsWheel.prototype.getTravel=function(){ - return this.travel; -} -/** -* Gets the front friction coefficient -* @returns the front fricition coefficient -*/ -GLGE.PhysicsWheel.prototype.getFrontFriction=function(){ - return this.frontFriction; -} -/** -* Gets the side friction coefficient -* @returns the side fricition coefficient -*/ -GLGE.PhysicsWheel.prototype.getSideFriction=function(){ - return this.sideFriction; -} - -/** -* Sets a driving force for the wheel -* @param {number} force the driving force in N -*/ -GLGE.PhysicsWheel.prototype.drive=function(force){ - this.driveForce=force; - return this; -} -/** -* Sets the braking level -* @param {number} brake 0-1 value indicating the level of braking -*/ -GLGE.PhysicsWheel.prototype.brake=function(brake){ - this.braking=brake; - return this; -} - -})(GLGE);/* -Copyright (c) 2011 Martin Ruenz +/* +Copyright (c) 2011 Juan Mellado + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/* +References: +- "LZMA SDK" by Igor Pavlov + http://www.7-zip.org/sdk.html +*/ + +var LZMA = LZMA || {}; + +LZMA.OutWindow = function(){ + this._windowSize = 0; +}; + +LZMA.OutWindow.prototype.create = function(windowSize){ + if ( (!this._buffer) || (this._windowSize !== windowSize) ){ + this._buffer = []; + } + this._windowSize = windowSize; + this._pos = 0; + this._streamPos = 0; +}; + +LZMA.OutWindow.prototype.flush = function(){ + var size = this._pos - this._streamPos; + if (size !== 0){ + while(size --){ + this._stream.writeByte(this._buffer[this._streamPos ++]); + } + if (this._pos >= this._windowSize){ + this._pos = 0; + } + this._streamPos = this._pos; + } +}; + +LZMA.OutWindow.prototype.releaseStream = function(){ + this.flush(); + this._stream = null; +}; + +LZMA.OutWindow.prototype.setStream = function(stream){ + this.releaseStream(); + this._stream = stream; +}; + +LZMA.OutWindow.prototype.init = function(solid){ + if (!solid){ + this._streamPos = 0; + this._pos = 0; + } +}; + +LZMA.OutWindow.prototype.copyBlock = function(distance, len){ + var pos = this._pos - distance - 1; + if (pos < 0){ + pos += this._windowSize; + } + while(len --){ + if (pos >= this._windowSize){ + pos = 0; + } + this._buffer[this._pos ++] = this._buffer[pos ++]; + if (this._pos >= this._windowSize){ + this.flush(); + } + } +}; -Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: +LZMA.OutWindow.prototype.putByte = function(b){ + this._buffer[this._pos ++] = b; + if (this._pos >= this._windowSize){ + this.flush(); + } +}; -The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. +LZMA.OutWindow.prototype.getByte = function(distance){ + var pos = this._pos - distance - 1; + if (pos < 0){ + pos += this._windowSize; + } + return this._buffer[pos]; +}; -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ +LZMA.RangeDecoder = function(){ +}; -/** - * @fileOverview Base class for preloaders. Enables the handling of multiple files. - * @name glge_filepreloader.js - * @author seamonkey@uni-koblenz.de - */ +LZMA.RangeDecoder.prototype.setStream = function(stream){ + this._stream = stream; +}; + +LZMA.RangeDecoder.prototype.releaseStream = function(){ + this._stream = null; +}; +LZMA.RangeDecoder.prototype.init = function(){ + var i = 5; -(function(GLGE){ + this._code = 0; + this._range = -1; + + while(i --){ + this._code = (this._code << 8) | this._stream.readByte(); + } +}; + +LZMA.RangeDecoder.prototype.decodeDirectBits = function(numTotalBits){ + var result = 0, i = numTotalBits, t; + + while(i --){ + this._range >>>= 1; + t = (this._code - this._range) >>> 31; + this._code -= this._range & (t - 1); + result = (result << 1) | (1 - t); + if ( (this._range & 0xff000000) === 0){ + this._code = (this._code << 8) | this._stream.readByte(); + this._range <<= 8; + } + } + return result; +}; +LZMA.RangeDecoder.prototype.decodeBit = function(probs, index){ + var prob = probs[index], + newBound = (this._range >>> 11) * prob; -/** -* @class FilePreloader class -* @augments GLGE.Events -*/ -GLGE.FilePreloader=function(){ - this.files=[]; -} + if ( (this._code ^ 0x80000000) < (newBound ^ 0x80000000) ){ + this._range = newBound; + probs[index] += (2048 - prob) >>> 5; + if ( (this._range & 0xff000000) === 0){ + this._code = (this._code << 8) | this._stream.readByte(); + this._range <<= 8; + } + return 0; + } -GLGE.augment(GLGE.Events,GLGE.FilePreloader); + this._range -= newBound; + this._code -= newBound; + probs[index] -= prob >>> 5; + if ( (this._range & 0xff000000) === 0){ + this._code = (this._code << 8) | this._stream.readByte(); + this._range <<= 8; + } + return 1; +}; -GLGE.FilePreloader.prototype.loadedBytes=0; -GLGE.FilePreloader.prototype.totalBytes=0; -GLGE.FilePreloader.prototype.numLoadedFiles=0; -GLGE.FilePreloader.prototype.numTotalFiles=0; -GLGE.FilePreloader.prototype.sizesCount=0; /** @description Specifies how many file sizes has been collected */ -GLGE.FilePreloader.prototype.progress=0; /** @description 0 - 100 */ -GLGE.FilePreloader.prototype.files=null; /** @description List of files. file: { "url":url,"loaded":fileloaded,"size":filesize,"bytesLoaded":loadedSize, - "type":'xml'/'image',"callback":called when loaded,"content":content, "preloader":GLGE.FilePreloader} */ -/** -* Add a file which has to be loaded -* @param {string} url The url of the file. -* @param {string} type Defines the type of the requested file. "image" or "xml" -* @param {function} [callback] Call this function when the file is loaded and pass the loaded content. -* @public -*/ -GLGE.FilePreloader.prototype.addFile=function(url, type, callback){ - //if(this.files.indexOf(url) != -1) return; - - this.files.push({"url":url,"loaded":false,"size":-1,"bytesLoaded":0,"type":type,"callback":callback,"content":null,"preloader":this}); - this.numTotalFiles++; -} +LZMA.initBitModels = function(probs, len){ + while(len --){ + probs[len] = 1024; + } +}; + +LZMA.BitTreeDecoder = function(numBitLevels){ + this._models = []; + this._numBitLevels = numBitLevels; +}; + +LZMA.BitTreeDecoder.prototype.init = function(){ + LZMA.initBitModels(this._models, 1 << this._numBitLevels); +}; + +LZMA.BitTreeDecoder.prototype.decode = function(rangeDecoder){ + var m = 1, i = this._numBitLevels; + + while(i --){ + m = (m << 1) | rangeDecoder.decodeBit(this._models, m); + } + return m - (1 << this._numBitLevels); +}; + +LZMA.BitTreeDecoder.prototype.reverseDecode = function(rangeDecoder){ + var m = 1, symbol = 0, i = 0, bit; + + for (; i < this._numBitLevels; ++ i){ + bit = rangeDecoder.decodeBit(this._models, m); + m = (m << 1) | bit; + symbol |= bit << i; + } + return symbol; +}; + +LZMA.reverseDecode2 = function(models, startIndex, rangeDecoder, numBitLevels){ + var m = 1, symbol = 0, i = 0, bit; + + for (; i < numBitLevels; ++ i){ + bit = rangeDecoder.decodeBit(models, startIndex + m); + m = (m << 1) | bit; + symbol |= bit << i; + } + return symbol; +}; + +LZMA.LenDecoder = function(){ + this._choice = []; + this._lowCoder = []; + this._midCoder = []; + this._highCoder = new LZMA.BitTreeDecoder(8); + this._numPosStates = 0; +}; + +LZMA.LenDecoder.prototype.create = function(numPosStates){ + for (; this._numPosStates < numPosStates; ++ this._numPosStates){ + this._lowCoder[this._numPosStates] = new LZMA.BitTreeDecoder(3); + this._midCoder[this._numPosStates] = new LZMA.BitTreeDecoder(3); + } +}; + +LZMA.LenDecoder.prototype.init = function(){ + var i = this._numPosStates; + LZMA.initBitModels(this._choice, 2); + while(i --){ + this._lowCoder[i].init(); + this._midCoder[i].init(); + } + this._highCoder.init(); +}; + +LZMA.LenDecoder.prototype.decode = function(rangeDecoder, posState){ + if (rangeDecoder.decodeBit(this._choice, 0) === 0){ + return this._lowCoder[posState].decode(rangeDecoder); + } + if (rangeDecoder.decodeBit(this._choice, 1) === 0){ + return 8 + this._midCoder[posState].decode(rangeDecoder); + } + return 16 + this._highCoder.decode(rangeDecoder); +}; + +LZMA.Decoder2 = function(){ + this._decoders = []; +}; + +LZMA.Decoder2.prototype.init = function(){ + LZMA.initBitModels(this._decoders, 0x300); +}; + +LZMA.Decoder2.prototype.decodeNormal = function(rangeDecoder){ + var symbol = 1; + + do{ + symbol = (symbol << 1) | rangeDecoder.decodeBit(this._decoders, symbol); + }while(symbol < 0x100); + + return symbol & 0xff; +}; + +LZMA.Decoder2.prototype.decodeWithMatchByte = function(rangeDecoder, matchByte){ + var symbol = 1, matchBit, bit; + + do{ + matchBit = (matchByte >> 7) & 1; + matchByte <<= 1; + bit = rangeDecoder.decodeBit(this._decoders, ( (1 + matchBit) << 8) + symbol); + symbol = (symbol << 1) | bit; + if (matchBit !== bit){ + while(symbol < 0x100){ + symbol = (symbol << 1) | rangeDecoder.decodeBit(this._decoders, symbol); + } + break; + } + }while(symbol < 0x100); + + return symbol & 0xff; +}; + +LZMA.LiteralDecoder = function(){ +}; + +LZMA.LiteralDecoder.prototype.create = function(numPosBits, numPrevBits){ + var i; + + if (this._coders + && (this._numPrevBits === numPrevBits) + && (this._numPosBits === numPosBits) ){ + return; + } + this._numPosBits = numPosBits; + this._posMask = (1 << numPosBits) - 1; + this._numPrevBits = numPrevBits; -/** -* Same as addFile. But instead of creating a new file object use an existing one. -* @param {object} file The file to add. -* @public -*/ -GLGE.FilePreloader.prototype.addFileRef=function(file){ - //if(this.files.indexOf(url) != -1) return; - - this.files.push(file); - this.numTotalFiles++; -} + this._coders = []; -/** -* This function accumulates the size of all files. When done it triggers loadFiles(). It has to be called for each file. -* @param {object} file Current file. -* @private -*/ -GLGE.FilePreloader.prototype.accumulateFileSize=function(file) -{ - var req = new XMLHttpRequest(); - req.preloader = this; - req.active = true; - req.file = file; - req.overrideMimeType("text/xml"); - req.onreadystatechange = function() { - if(this.readyState > 1 && req.active) - { - this.active = false; + i = 1 << (this._numPrevBits + this._numPosBits); + while(i --){ + this._coders[i] = new LZMA.Decoder2(); + } +}; - this.file.size = parseFloat(this.getResponseHeader('Content-length')); - this.preloader.totalBytes += this.file.size; - - if(++this.preloader.sizesCount >= this.preloader.files.length) // are all file sizes collected? - this.preloader.loadFiles(); - - this.abort(); - this.onreadystatechange = null; - } - }; - req.open("GET", file.url, true); - req.send(""); -} +LZMA.LiteralDecoder.prototype.init = function(){ + var i = 1 << (this._numPrevBits + this._numPosBits); + while(i --){ + this._coders[i].init(); + } +}; -/** -* Start loading -* @public -*/ -GLGE.FilePreloader.prototype.start=function(){ - for(i in this.files) - this.accumulateFileSize(this.files[i]); -} +LZMA.LiteralDecoder.prototype.getDecoder = function(pos, prevByte){ + return this._coders[( (pos & this._posMask) << this._numPrevBits) + + ( (prevByte & 0xff) >>> (8 - this._numPrevBits) )]; +}; -/** -* Load files. Assumes that the file sizes have been accumulated. -* @private -*/ -GLGE.FilePreloader.prototype.loadFiles=function(){ - - for(i in this.files){ - var file = this.files[i]; - if(file.type == "image") - { - // only update the preloader, when the file is completely loaded (no ajax) - - var image = new Image(); - file.content = image; - var that = this; - image.file = file; - image.onload = function(){ that.fileLoaded(this.file, this.file.size); } - image.src=file.url; - }else{ - // update the preloader each 0.1 seconds (ajax) - - var req = new XMLHttpRequest(); - req.overrideMimeType("text/xml"); - req.preloader = this; - req.file = file; - - var updateTrigger = setInterval (function () - { - if (req.readyState == 3) - { - // TODO: Check if the file reference is always correct - var stepBytes = req.responseText.length - file.bytesLoaded; - file.bytesLoaded = req.responseText.length; - req.preloader.update(stepBytes); - } - - }, 100); - - req.onreadystatechange = function() { - if(this.readyState >= 4) - { - clearInterval(updateTrigger); - this.file.content = this.responseXML; - - var stepBytes = this.responseText.length - this.file.bytesLoaded; - - this.preloader.update(stepBytes); - this.preloader.fileLoaded(this.file, stepBytes); - } - }; - - req.open("GET", file.url, true); - req.send(); - - } - } -} +LZMA.Decoder = function(){ + this._outWindow = new LZMA.OutWindow(); + this._rangeDecoder = new LZMA.RangeDecoder(); + this._isMatchDecoders = []; + this._isRepDecoders = []; + this._isRepG0Decoders = []; + this._isRepG1Decoders = []; + this._isRepG2Decoders = []; + this._isRep0LongDecoders = []; + this._posSlotDecoder = []; + this._posDecoders = []; + this._posAlignDecoder = new LZMA.BitTreeDecoder(4); + this._lenDecoder = new LZMA.LenDecoder(); + this._repLenDecoder = new LZMA.LenDecoder(); + this._literalDecoder = new LZMA.LiteralDecoder(); + this._dictionarySize = -1; + this._dictionarySizeCheck = -1; -/** - * This functions updates the progress. - * @param {number} stepBytes Amount of bytes that have been loaded since the last call. - * @private - */ -GLGE.FilePreloader.prototype.update=function(stepBytes){ - this.loadedBytes += stepBytes; - this.progress = (100.0 * this.loadedBytes) / this.totalBytes; + this._posSlotDecoder[0] = new LZMA.BitTreeDecoder(6); + this._posSlotDecoder[1] = new LZMA.BitTreeDecoder(6); + this._posSlotDecoder[2] = new LZMA.BitTreeDecoder(6); + this._posSlotDecoder[3] = new LZMA.BitTreeDecoder(6); +}; - this.fireEvent("progress", {"progress":this.progress, "stepBytes":stepBytes, "loadedBytes":this.loadedBytes, "totalBytes":this.totalBytes, "loadedFiles": this.numLoadedFiles, "totalFiles": this.numTotalFiles}); -} +LZMA.Decoder.prototype.setDictionarySize = function(dictionarySize){ + if (dictionarySize < 0){ + return false; + } + if (this._dictionarySize !== dictionarySize){ + this._dictionarySize = dictionarySize; + this._dictionarySizeCheck = Math.max(this._dictionarySize, 1); + this._outWindow.create( Math.max(this._dictionarySizeCheck, 4096) ); + } + return true; +}; -/** - * Called when a file has been loaded. This function triggers an event and updates the state. - * @param {object} file The file that has been loaded. - * @param {number} stepBytes Amount of bytes that have been loaded since the last call. - * @private - */ -GLGE.FilePreloader.prototype.fileLoaded=function(file, stepBytes){ +LZMA.Decoder.prototype.setLcLpPb = function(lc, lp, pb){ + var numPosStates = 1 << pb; - this.numLoadedFiles++; - - // update file - file.loaded = true; - file.bytesLoaded = file.size; - - // update progress - if(this.numLoadedFiles >= this.files.length){ - this.progress = 100; - this.fireEvent("downloadComplete", {"file":file,"stepBytes":stepBytes}); - }else{ - this.update(stepBytes); - } - - // events - this.fireEvent("fileLoaded", {"file":file,"stepBytes":stepBytes}); - if(file.callback) file.callback(file); -} + if (lc > 8 || lp > 4 || pb > 4){ + return false; + } -/** - * This function returns a list (an array) of all loaded files. - * @public - */ -GLGE.FilePreloader.prototype.getLoadedFiles=function(){ - var result = []; - for(i in this.files) - if(this.files[i].loaded) - result.push(this.files[i]); - return result; -} + this._literalDecoder.create(lp, lc); -/** - * This function returns information about one file. - * @param {string} url The url of the file. - * @public - */ -GLGE.FilePreloader.prototype.getFile=function(url){ - for(i in this.files) - if(this.files[i].url==url) - return this.files[i]; - return -1; -} + this._lenDecoder.create(numPosStates); + this._repLenDecoder.create(numPosStates); + this._posStateMask = numPosStates - 1; + + return true; +}; +LZMA.Decoder.prototype.init = function(){ + var i = 4; -})(GLGE); -/* -Copyright (c) 2011 Martin Ruenz + this._outWindow.init(false); -Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: + LZMA.initBitModels(this._isMatchDecoders, 192); + LZMA.initBitModels(this._isRep0LongDecoders, 192); + LZMA.initBitModels(this._isRepDecoders, 12); + LZMA.initBitModels(this._isRepG0Decoders, 12); + LZMA.initBitModels(this._isRepG1Decoders, 12); + LZMA.initBitModels(this._isRepG2Decoders, 12); + LZMA.initBitModels(this._posDecoders, 114); + + this._literalDecoder.init(); + + while(i --){ + this._posSlotDecoder[i].init(); + } + + this._lenDecoder.init(); + this._repLenDecoder.init(); + this._posAlignDecoder.init(); + this._rangeDecoder.init(); +}; -The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. +LZMA.Decoder.prototype.decode = function(inStream, outStream, outSize){ + var state = 0, rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0, nowPos64 = 0, prevByte = 0, + posState, decoder2, len, distance, posSlot, numDirectBits; -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ + this._rangeDecoder.setStream(inStream); + this._outWindow.setStream(outStream); -/** - * @fileOverview - * @name glge_documentpreloader.js - * @author seamonkey@uni-koblenz.de - */ + this.init(); + while(outSize < 0 || nowPos64 < outSize){ + posState = nowPos64 & this._posStateMask; -(function(GLGE){ + if (this._rangeDecoder.decodeBit(this._isMatchDecoders, (state << 4) + posState) === 0){ + decoder2 = this._literalDecoder.getDecoder(nowPos64 ++, prevByte); + if (state >= 7){ + prevByte = decoder2.decodeWithMatchByte(this._rangeDecoder, this._outWindow.getByte(rep0) ); + }else{ + prevByte = decoder2.decodeNormal(this._rangeDecoder); + } + this._outWindow.putByte(prevByte); + state = state < 4? 0: state - (state < 10? 3: 6); + }else{ -/** -* @class Document preloader class -* @augments GLGE.Events -*/ -GLGE.DocumentPreloader=function(doc, args){ + if (this._rangeDecoder.decodeBit(this._isRepDecoders, state) === 1){ + len = 0; + if (this._rangeDecoder.decodeBit(this._isRepG0Decoders, state) === 0){ + if (this._rangeDecoder.decodeBit(this._isRep0LongDecoders, (state << 4) + posState) === 0){ + state = state < 7? 9: 11; + len = 1; + } + }else{ + if (this._rangeDecoder.decodeBit(this._isRepG1Decoders, state) === 0){ + distance = rep1; + }else{ + if (this._rangeDecoder.decodeBit(this._isRepG2Decoders, state) === 0){ + distance = rep2; + }else{ + distance = rep3; + rep3 = rep2; + } + rep2 = rep1; + } + rep1 = rep0; + rep0 = distance; + } + if (len === 0){ + len = 2 + this._repLenDecoder.decode(this._rangeDecoder, posState); + state = state < 7? 8: 11; + } + }else{ + rep3 = rep2; + rep2 = rep1; + rep1 = rep0; - - // create image preloader - this.imagePreloader = new GLGE.FilePreloader(); - - this.document = doc; - + len = 2 + this._lenDecoder.decode(this._rangeDecoder, posState); + state = state < 7? 7: 10; - if(args.XMLQuota) - this.XMLQuota = args.XMLQuota; - else - this.XMLQuota = 0.2; // 20% XML, 80% images - - this.imageQuota = 1-this.XMLQuota; - - // Passing the size of all xml files will improve the accuracy of the preloader. Alternative: Pass the number of xml files (approximation) - if(args.XMLBytes) - this.XMLBytes = args.XMLBytes; - else if(args.numXMLFiles) - this.numXMLFiles = args.numXMLFiles; - else - this.numXMLFiles = 3; //TODO necessary? -} + posSlot = this._posSlotDecoder[len <= 5? len - 2: 3].decode(this._rangeDecoder); + if (posSlot >= 4){ -GLGE.augment(GLGE.Events,GLGE.DocumentPreloader); + numDirectBits = (posSlot >> 1) - 1; + rep0 = (2 | (posSlot & 1) ) << numDirectBits; -GLGE.DocumentPreloader.prototype.progress = 0; + if (posSlot < 14){ + rep0 += LZMA.reverseDecode2(this._posDecoders, + rep0 - posSlot - 1, this._rangeDecoder, numDirectBits); + }else{ + rep0 += this._rangeDecoder.decodeDirectBits(numDirectBits - 4) << 4; + rep0 += this._posAlignDecoder.reverseDecode(this._rangeDecoder); + if (rep0 < 0){ + if (rep0 === -1){ + break; + } + return false; + } + } + }else{ + rep0 = posSlot; + } + } -GLGE.DocumentPreloader.prototype.imageQuota = 0; // size quota of images (Textures) [0..1] -GLGE.DocumentPreloader.prototype.XMLQuota = 0; // size quota XML (Documents) [0..1] + if (rep0 >= nowPos64 || rep0 >= this._dictionarySizeCheck){ + return false; + } -GLGE.DocumentPreloader.prototype.XMLBytes = -1; // XML size in bytes (for higher accuracy) -GLGE.DocumentPreloader.prototype.totalBytes = -1; // XML size in bytes (highest accuracy) -GLGE.DocumentPreloader.prototype.loadedBytes=0; + this._outWindow.copyBlock(rep0, len); + nowPos64 += len; + prevByte = this._outWindow.getByte(0); + } + } -GLGE.DocumentPreloader.prototype.numXMLFiles = 3; // default value + this._outWindow.flush(); + this._outWindow.releaseStream(); + this._rangeDecoder.releaseStream(); -GLGE.DocumentPreloader.prototype.state = 0; // 0: not yet started, 1: loading XML, 2: loading images, 3: completed -GLGE.DocumentPreloader.prototype.imagePreloader = null; // GLGE.Peloader -GLGE.DocumentPreloader.prototype.document = null; // GLGE.Document + return true; +}; -/** - * Add an image, which should be loaded by the preloader. - * @param {string} url Url of the image. - */ -GLGE.DocumentPreloader.prototype.addImage=function(url){ - this.imagePreloader.addFile(url, "image"); -} +LZMA.Decoder.prototype.setDecoderProperties = function(properties){ + var value, lc, lp, pb, dictionarySize; -/** - * Start loading all images in all xml files. Assumes that XML-files have finished loading. - */ -GLGE.DocumentPreloader.prototype.loadImages=function(){ + if (properties.size < 5){ + return false; + } - this.changeState(2); - - if(this.progress < this.XMLQuota * 100.0) this.progress = this.XMLQuota * 100.0; // correct progress. + value = properties.readByte(); + lc = value % 9; + value = ~~(value / 9); + lp = value % 5; + pb = ~~(value / 5); - var that = this; - this.imagePreloader.addEventListener("progress", function(args){that.updateProgress.call(that, args);}); - this.imagePreloader.addEventListener("downloadComplete", function(args){that.finish.call(that, args);}); - this.imagePreloader.addEventListener("fileLoaded", function(args){that.fireEvent("fileLoaded", args.file);}); - this.imagePreloader.start(); -} + if ( !this.setLcLpPb(lc, lp, pb) ){ + return false; + } -/** - * Update preloader progress. - * @param {object} args Progress information. - *
args.stepBytes describes how many bytes have been loaded since the last update. - */ -GLGE.DocumentPreloader.prototype.updateProgress=function(args){ + dictionarySize = properties.readByte(); + dictionarySize |= properties.readByte() << 8; + dictionarySize |= properties.readByte() << 16; + dictionarySize += properties.readByte() * 16777216; - if(this.state < 2){ // loading xml + return this.setDictionarySize(dictionarySize); +}; - if(this.XMLBytes > 0){ // high accuracy - //if(!args.stepBytes) args.stepBytes = 0; - this.loadedBytes += args.stepBytes; - this.progress = this.XMLQuota * 100.0 * this.loadedBytes / this.XMLBytes; - } - else{ // low accuracy - this.progress += this.XMLQuota * 100.0 / this.numXMLFiles; - if(this.progress > this.XMLQuota * 100) this.progress = this.XMLQuota * 100; - } - } - else{ // loading images - this.progress = this.XMLQuota * 100 + this.imageQuota * this.imagePreloader.progress; - } - this.fireEvent("progress", {"progress":this.progress, "stepBytes":args.stepBytes, "loadedBytes":args.loadedBytes, "totalBytes":args.totalBytes, "loadedFiles": args.loadedFiles, "totalFiles": args.totalFiles}); -} +LZMA.decompress = function(properties, inStream, outStream, outSize){ + var decoder = new LZMA.Decoder(); -/** - * This function loads a XML-file. Assumes that loading images hasn't yet begun. - * @param {string} url Url of the XML-file. - */ -GLGE.DocumentPreloader.prototype.loadXMLFile=function(url){ + if ( !decoder.setDecoderProperties(properties) ){ + throw "Incorrect stream properties"; + } - this.changeState(1); + if ( !decoder.decode(inStream, outStream, outSize) ){ + throw "Error in data stream"; + } - var xmlPreloader = new GLGE.FilePreloader(); - xmlPreloader.addFile(url, "xml"); - - var that = this; - - if(this.XMLBytes > 0) xmlPreloader.addEventListener("progress", function(arg){that.updateProgress.call(that, arg);}); // high accuracy - else xmlPreloader.addEventListener("downloadComplete", function(arg){that.updateProgress.call(that, arg);}); // low accuracy + return true; +}; - var doc = this.document; - xmlPreloader.addEventListener("fileLoaded", function(args){ - args.file.content.getElementById=doc.getElementById; - doc.loaded(args.file.url,args.file.content); - that.fireEvent("fileLoaded", args.file); - }); - - xmlPreloader.start(); -} +LZMA.decompressFile = function(inStream, outStream){ + var decoder = new LZMA.Decoder(), outSize; -/** - * Sets the state of the document preloader. - * @param {number} newState New state - */ -GLGE.DocumentPreloader.prototype.changeState = function(newState) { - //if(this.state > newState) GLGE.warning("GLGE.DocumentPreloader.prototype.changeState: The new state is lower than the old."); - this.state = newState; - this.fireEvent("stateChange", newState); -} + if ( !decoder.setDecoderProperties(inStream) ){ + throw "Incorrect stream properties"; + } -/** - * Called when the document preloader loaded all files. - * @param {object} event Event parameter. Not used at all. - */ -GLGE.DocumentPreloader.prototype.finish=function(event){ - this.changeState(3); - this.progress = 100; - this.fireEvent("downloadComplete"); -} + outSize = inStream.readByte(); + outSize |= inStream.readByte() << 8; + outSize |= inStream.readByte() << 16; + outSize += inStream.readByte() * 16777216; -})(GLGE); + inStream.readByte(); + inStream.readByte(); + inStream.readByte(); + inStream.readByte(); + + if ( !decoder.decode(inStream, outStream, outSize) ){ + throw "Error in data stream"; + } + + return true; +}; +/* +Copyright (c) 2011 Juan Mellado + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/* +References: +- "OpenCTM: The Open Compressed Triangle Mesh file format" by Marcus Geelnard + http://openctm.sourceforge.net/ +*/ + +var CTM = CTM || {}; + +CTM.CompressionMethod = { + RAW: 0x00574152, + MG1: 0x0031474d, + MG2: 0x0032474d +}; + +CTM.Flags = { + NORMALS: 0x00000001 +}; + +CTM.File = function(stream){ + this.load(stream); +}; + +CTM.File.prototype.load = function(stream){ + this.header = new CTM.FileHeader(stream); + + this.body = new CTM.FileBody(this.header); + + this.getReader().read(stream, this.body); +}; + +CTM.File.prototype.getReader = function(){ + var reader; + + switch(this.header.compressionMethod){ + case CTM.CompressionMethod.RAW: + reader = new CTM.ReaderRAW(); + break; + case CTM.CompressionMethod.MG1: + reader = new CTM.ReaderMG1(); + break; + case CTM.CompressionMethod.MG2: + reader = new CTM.ReaderMG2(); + break; + } + + return reader; +}; + +CTM.FileHeader = function(stream){ + stream.readInt32(); //magic "OCTM" + this.fileFormat = stream.readInt32(); + this.compressionMethod = stream.readInt32(); + this.vertexCount = stream.readInt32(); + this.triangleCount = stream.readInt32(); + this.uvMapCount = stream.readInt32(); + this.attrMapCount = stream.readInt32(); + this.flags = stream.readInt32(); + this.comment = stream.readString(); +}; + +CTM.FileHeader.prototype.hasNormals = function(){ + return this.flags & CTM.Flags.NORMALS; +}; + +CTM.FileBody = function(header){ + var i = header.triangleCount * 3, + v = header.vertexCount * 3, + n = header.hasNormals()? header.vertexCount * 3: 0, + u = header.vertexCount * 2, + a = header.vertexCount * 4, + j = 0; + + var data = new ArrayBuffer( + (i + v + n + (u * header.uvMapCount) + (a * header.attrMapCount) ) * 4); + + this.indices = new Uint32Array(data, 0, i); + + this.vertices = new Float32Array(data, i * 4, v); + + if ( header.hasNormals() ){ + this.normals = new Float32Array(data, (i + v) * 4, n); + } + + if (header.uvMapCount){ + this.uvMaps = []; + for (j = 0; j < header.uvMapCount; ++ j){ + this.uvMaps[j] = {uv: new Float32Array(data, + (i + v + n + (j * u) ) * 4, u) }; + } + } + + if (header.attrMapCount){ + this.attrMaps = []; + for (j = 0; j < header.attrMapCount; ++ j){ + this.attrMaps[j] = {attr: new Float32Array(data, + (i + v + n + (u * header.uvMapCount) + (j * a) ) * 4, a) }; + } + } +}; + +CTM.FileMG2Header = function(stream){ + stream.readInt32(); //magic "MG2H" + this.vertexPrecision = stream.readFloat32(); + this.normalPrecision = stream.readFloat32(); + this.lowerBoundx = stream.readFloat32(); + this.lowerBoundy = stream.readFloat32(); + this.lowerBoundz = stream.readFloat32(); + this.higherBoundx = stream.readFloat32(); + this.higherBoundy = stream.readFloat32(); + this.higherBoundz = stream.readFloat32(); + this.divx = stream.readInt32(); + this.divy = stream.readInt32(); + this.divz = stream.readInt32(); + + this.sizex = (this.higherBoundx - this.lowerBoundx) / this.divx; + this.sizey = (this.higherBoundy - this.lowerBoundy) / this.divy; + this.sizez = (this.higherBoundz - this.lowerBoundz) / this.divz; +}; + +CTM.ReaderRAW = function(){ +}; + +CTM.ReaderRAW.prototype.read = function(stream, body){ + this.readIndices(stream, body.indices); + this.readVertices(stream, body.vertices); + + if (body.normals){ + this.readNormals(stream, body.normals); + } + if (body.uvMaps){ + this.readUVMaps(stream, body.uvMaps); + } + if (body.attrMaps){ + this.readAttrMaps(stream, body.attrMaps); + } +}; + +CTM.ReaderRAW.prototype.readIndices = function(stream, indices){ + stream.readInt32(); //magic "INDX" + stream.readArrayInt32(indices); +}; + +CTM.ReaderRAW.prototype.readVertices = function(stream, vertices){ + stream.readInt32(); //magic "VERT" + stream.readArrayFloat32(vertices); +}; + +CTM.ReaderRAW.prototype.readNormals = function(stream, normals){ + stream.readInt32(); //magic "NORM" + stream.readArrayFloat32(normals); +}; + +CTM.ReaderRAW.prototype.readUVMaps = function(stream, uvMaps){ + var i = 0; + for (; i < uvMaps.length; ++ i){ + stream.readInt32(); //magic "TEXC" + + uvMaps[i].name = stream.readString(); + uvMaps[i].filename = stream.readString(); + stream.readArrayFloat32(uvMaps[i].uv); + } +}; + +CTM.ReaderRAW.prototype.readAttrMaps = function(stream, attrMaps){ + var i = 0; + for (; i < attrMaps.length; ++ i){ + stream.readInt32(); //magic "ATTR" + + attrMaps[i].name = stream.readString(); + stream.readArrayFloat32(attrMaps[i].attr); + } +}; + +CTM.ReaderMG1 = function(){ +}; + +CTM.ReaderMG1.prototype.read = function(stream, body){ + this.readIndices(stream, body.indices); + this.readVertices(stream, body.vertices); + + if (body.normals){ + this.readNormals(stream, body.normals); + } + if (body.uvMaps){ + this.readUVMaps(stream, body.uvMaps); + } + if (body.attrMaps){ + this.readAttrMaps(stream, body.attrMaps); + } +}; + +CTM.ReaderMG1.prototype.readIndices = function(stream, indices){ + stream.readInt32(); //magic "INDX" + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(indices, 3); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + + CTM.restoreIndices(indices, indices.length); +}; + +CTM.ReaderMG1.prototype.readVertices = function(stream, vertices){ + stream.readInt32(); //magic "VERT" + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(vertices, 1); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); +}; + +CTM.ReaderMG1.prototype.readNormals = function(stream, normals){ + stream.readInt32(); //magic "NORM" + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(normals, 3); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); +}; + +CTM.ReaderMG1.prototype.readUVMaps = function(stream, uvMaps){ + var i = 0; + for (; i < uvMaps.length; ++ i){ + stream.readInt32(); //magic "TEXC" + + uvMaps[i].name = stream.readString(); + uvMaps[i].filename = stream.readString(); + + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(uvMaps[i].uv, 2); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + } +}; + +CTM.ReaderMG1.prototype.readAttrMaps = function(stream, attrMaps){ + var i = 0; + for (; i < attrMaps.length; ++ i){ + stream.readInt32(); //magic "ATTR" + + attrMaps[i].name = stream.readString(); + + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(attrMaps[i].attr, 4); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + } +}; + +CTM.ReaderMG2 = function(){ +}; + +CTM.ReaderMG2.prototype.read = function(stream, body){ + this.MG2Header = new CTM.FileMG2Header(stream); + + this.readVertices(stream, body.vertices); + this.readIndices(stream, body.indices); + + if (body.normals){ + this.readNormals(stream, body); + } + if (body.uvMaps){ + this.readUVMaps(stream, body.uvMaps); + } + if (body.attrMaps){ + this.readAttrMaps(stream, body.attrMaps); + } +}; + +CTM.ReaderMG2.prototype.readVertices = function(stream, vertices){ + stream.readInt32(); //magic "VERT" + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(vertices, 3); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + + var gridIndices = this.readGridIndices(stream, vertices); + + CTM.restoreVertices(vertices, this.MG2Header, gridIndices, this.MG2Header.vertexPrecision); +}; + +CTM.ReaderMG2.prototype.readGridIndices = function(stream, vertices){ + stream.readInt32(); //magic "GIDX" + stream.readInt32(); //packed size + + var gridIndices = new Uint32Array(vertices.length / 3); + + var interleaved = new CTM.InterleavedStream(gridIndices, 1); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + + CTM.restoreGridIndices(gridIndices, gridIndices.length); + + return gridIndices; +}; + +CTM.ReaderMG2.prototype.readIndices = function(stream, indices){ + stream.readInt32(); //magic "INDX" + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(indices, 3); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + + CTM.restoreIndices(indices, indices.length); +}; + +CTM.ReaderMG2.prototype.readNormals = function(stream, body){ + stream.readInt32(); //magic "NORM" + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(body.normals, 3); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + + var smooth = CTM.calcSmoothNormals(body.indices, body.vertices); + + CTM.restoreNormals(body.normals, smooth, this.MG2Header.normalPrecision); +}; + +CTM.ReaderMG2.prototype.readUVMaps = function(stream, uvMaps){ + var i = 0; + for (; i < uvMaps.length; ++ i){ + stream.readInt32(); //magic "TEXC" + + uvMaps[i].name = stream.readString(); + uvMaps[i].filename = stream.readString(); + + var precision = stream.readFloat32(); + + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(uvMaps[i].uv, 2); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + + CTM.restoreMap(uvMaps[i].uv, 2, precision); + } +}; + +CTM.ReaderMG2.prototype.readAttrMaps = function(stream, attrMaps){ + var i = 0; + for (; i < attrMaps.length; ++ i){ + stream.readInt32(); //magic "ATTR" + + attrMaps[i].name = stream.readString(); + + var precision = stream.readFloat32(); + + stream.readInt32(); //packed size + + var interleaved = new CTM.InterleavedStream(attrMaps[i].attr, 4); + LZMA.decompress(stream, stream, interleaved, interleaved.data.length); + + CTM.restoreMap(attrMaps[i].attr, 4, precision); + } +}; + +CTM.restoreIndices = function(indices, len){ + var i = 3; + if (len > 0){ + indices[2] += indices[0]; + } + for (; i < len; i += 3){ + indices[i] += indices[i - 3]; + + if (indices[i] === indices[i - 3]){ + indices[i + 1] += indices[i - 2]; + }else{ + indices[i + 1] += indices[i]; + } + + indices[i + 2] += indices[i]; + } +}; + +CTM.restoreGridIndices = function(gridIndices, len){ + var i = 1; + for (; i < len; ++ i){ + gridIndices[i] += gridIndices[i - 1]; + } +}; + +CTM.restoreVertices = function(vertices, grid, gridIndices, precision){ + var gridIdx, delta, x, y, z, + intVertices = new Uint32Array(vertices.buffer, vertices.byteOffset, vertices.length), + ydiv = grid.divx, zdiv = ydiv * grid.divy, + prevGridIdx = 0x7fffffff, prevDelta = 0, + i = 0, j = 0, len = gridIndices.length; + + for (; i < len; j += 3){ + x = gridIdx = gridIndices[i ++]; + + z = ~~(x / zdiv); + x -= ~~(z * zdiv); + y = ~~(x / ydiv); + x -= ~~(y * ydiv); + + delta = intVertices[j]; + if (gridIdx === prevGridIdx){ + delta += prevDelta; + } + + vertices[j] = grid.lowerBoundx + + x * grid.sizex + precision * delta; + vertices[j + 1] = grid.lowerBoundy + + y * grid.sizey + precision * intVertices[j + 1]; + vertices[j + 2] = grid.lowerBoundz + + z * grid.sizez + precision * intVertices[j + 2]; + + prevGridIdx = gridIdx; + prevDelta = delta; + } +}; + +CTM.restoreNormals = function(normals, smooth, precision){ + var ro, phi, theta, sinPhi, + nx, ny, nz, by, bz, len, + intNormals = new Uint32Array(normals.buffer, normals.byteOffset, normals.length), + i = 0, k = normals.length, + PI_DIV_2 = 3.141592653589793238462643 * 0.5; + + for (; i < k; i += 3){ + ro = intNormals[i] * precision; + phi = intNormals[i + 1]; + + if (phi === 0){ + normals[i] = smooth[i] * ro; + normals[i + 1] = smooth[i + 1] * ro; + normals[i + 2] = smooth[i + 2] * ro; + }else{ + + if (phi <= 4){ + theta = (intNormals[i + 2] - 2) * PI_DIV_2; + }else{ + theta = ( (intNormals[i + 2] * 4 / phi) - 2) * PI_DIV_2; + } + + phi *= precision * PI_DIV_2; + sinPhi = ro * Math.sin(phi); + + nx = sinPhi * Math.cos(theta); + ny = sinPhi * Math.sin(theta); + nz = ro * Math.cos(phi); + + bz = smooth[i + 1]; + by = smooth[i] - smooth[i + 2]; + + len = Math.sqrt(2 * bz * bz + by * by); + if (len > 1e-20){ + by /= len; + bz /= len; + } + + normals[i] = smooth[i] * nz + + (smooth[i + 1] * bz - smooth[i + 2] * by) * ny - bz * nx; + normals[i + 1] = smooth[i + 1] * nz - + (smooth[i + 2] + smooth[i] ) * bz * ny + by * nx; + normals[i + 2] = smooth[i + 2] * nz + + (smooth[i] * by + smooth[i + 1] * bz) * ny + bz * nx; + } + } +}; + +CTM.restoreMap = function(map, count, precision){ + var delta, value, + intMap = new Uint32Array(map.buffer, map.byteOffset, map.length), + i = 0, j, len = map.length; + + for (; i < count; ++ i){ + delta = 0; + + for (j = i; j < len; j += count){ + value = intMap[j]; + + delta += value & 1? -( (value + 1) >> 1): value >> 1; + + map[j] = delta * precision; + } + } +}; + +CTM.calcSmoothNormals = function(indices, vertices){ + var smooth = new Float32Array(vertices.length), + indx, indy, indz, nx, ny, nz, + v1x, v1y, v1z, v2x, v2y, v2z, len, + i, k; + + for (i = 0, k = indices.length; i < k;){ + indx = indices[i ++] * 3; + indy = indices[i ++] * 3; + indz = indices[i ++] * 3; + + v1x = vertices[indy] - vertices[indx]; + v2x = vertices[indz] - vertices[indx]; + v1y = vertices[indy + 1] - vertices[indx + 1]; + v2y = vertices[indz + 1] - vertices[indx + 1]; + v1z = vertices[indy + 2] - vertices[indx + 2]; + v2z = vertices[indz + 2] - vertices[indx + 2]; + + nx = v1y * v2z - v1z * v2y; + ny = v1z * v2x - v1x * v2z; + nz = v1x * v2y - v1y * v2x; + + len = Math.sqrt(nx * nx + ny * ny + nz * nz); + if (len > 1e-10){ + nx /= len; + ny /= len; + nz /= len; + } + + smooth[indx] += nx; + smooth[indx + 1] += ny; + smooth[indx + 2] += nz; + smooth[indy] += nx; + smooth[indy + 1] += ny; + smooth[indy + 2] += nz; + smooth[indz] += nx; + smooth[indz + 1] += ny; + smooth[indz + 2] += nz; + } + + for (i = 0, k = smooth.length; i < k; i += 3){ + len = Math.sqrt(smooth[i] * smooth[i] + + smooth[i + 1] * smooth[i + 1] + + smooth[i + 2] * smooth[i + 2]); + + if(len > 1e-10){ + smooth[i] /= len; + smooth[i + 1] /= len; + smooth[i + 2] /= len; + } + } + + return smooth; +}; + +CTM.isLittleEndian = (function(){ + var buffer = new ArrayBuffer(2), + bytes = new Uint8Array(buffer), + ints = new Uint16Array(buffer); + + bytes[0] = 1; + + return ints[0] === 1; +}()); + +CTM.InterleavedStream = function(data, count){ + this.data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength); + this.offset = CTM.isLittleEndian? 3: 0; + this.count = count * 4; + this.len = this.data.length; +}; + +CTM.InterleavedStream.prototype.writeByte = function(value){ + this.data[this.offset] = value; + + this.offset += this.count; + if (this.offset >= this.len){ + + this.offset -= this.len - 4; + if (this.offset >= this.count){ + + this.offset -= this.count + (CTM.isLittleEndian? 1: -1); + } + } +}; + +CTM.Stream = function(data){ + this.data = data; + this.offset = 0; +}; + +CTM.Stream.prototype.TWO_POW_MINUS23 = Math.pow(2, -23); + +CTM.Stream.prototype.TWO_POW_MINUS126 = Math.pow(2, -126); + +CTM.Stream.prototype.readByte = function(){ + return this.data.charCodeAt(this.offset ++) & 0xff; +}; + +CTM.Stream.prototype.readInt32 = function(){ + var i = this.readByte(); + i |= this.readByte() << 8; + i |= this.readByte() << 16; + return i | (this.readByte() << 24); +}; + +CTM.Stream.prototype.readFloat32 = function(){ + var m = this.readByte(); + m += this.readByte() << 8; + + var b1 = this.readByte(); + var b2 = this.readByte(); + + m += (b1 & 0x7f) << 16; + var e = ( (b2 & 0x7f) << 1) | ( (b1 & 0x80) >>> 7); + var s = b2 & 0x80? -1: 1; + + if (e === 255){ + return m !== 0? NaN: s * Infinity; + } + if (e > 0){ + return s * (1 + (m * this.TWO_POW_MINUS23) ) * Math.pow(2, e - 127); + } + if (m !== 0){ + return s * m * this.TWO_POW_MINUS126; + } + return s * 0; +}; + +CTM.Stream.prototype.readString = function(){ + var len = this.readInt32(); + + this.offset += len; + + return this.data.substr(this.offset - len, len); +}; + +CTM.Stream.prototype.readArrayInt32 = function(array){ + var i = 0, len = array.length; + + while(i < len){ + array[i ++] = this.readInt32(); + } + + return array; +}; + +CTM.Stream.prototype.readArrayFloat32 = function(array){ + var i = 0, len = array.length; + + while(i < len){ + array[i ++] = this.readFloat32(); + } + + return array; +}; +/* +GLGE WebGL Graphics Engine +Copyright (c) 2010, Paul Brunt +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of GLGE nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * @fileOverview + * @name glge_wavefront.js + * @author me@paulbrunt.co.uk + */ + +(function(GLGE){ +/** +* @class parses and displays a warefront object file with mtl material +* @param {string} uid the unique id for this object +* @augments GLGE.Object +*/ +GLGE.OpenCTM=function(uid){ + this.multimaterials=[]; + this.materials={}; + this.instances=[]; + this.queue=[]; + this.idMaterials = [];//storaged name of material (string) + GLGE.Object.call(this,uid); + GLGE.Assets.registerAsset(this,uid); +} +GLGE.augment(GLGE.Object,GLGE.OpenCTM); +/** +* Gets the absolute path given an import path and the path it's relative to +* @param {string} path the path to get the absolute path for +* @param {string} relativeto the path the supplied path is relativeto +* @returns {string} absolute path +* @private +*/ +GLGE.OpenCTM.prototype.getAbsolutePath=function(path,relativeto){ + if(path.substr(0,7)=="http://" || path.substr(0,7)=="file://" || path.substr(0,7)=="https://"){ + return path; + } + else + { + if(!relativeto){ + relativeto=window.location.href; + } + if(relativeto.indexOf("?")>0){ + relativeto=relativeto.substr(0,relativeto.indexOf("?")); + } + //find the path compoents + var bits=relativeto.split("/"); + var domain=bits[2]; + var proto=bits[0]; + var initpath=[]; + for(var i=3;i65024) { + var newPositions=[]; + var newNormals=[]; + var newUVs=[]; + for (var i=0; i0) newNormals.push(normals[faces[i]*3],normals[faces[i]*3+1],normals[faces[i]*3+2]); + if(uv.length>0) newUVs.push(uv[faces[i]*2],uv[faces[i]*2+1]); + } + positions=newPositions; + normals=newNormals; + uv=newUVs; + faces=[]; + } + + var mesh=new GLGE.Mesh; + mesh.setPositions(positions); + if(normals.length>0) mesh.setNormals(normals); + if(uv.length>0) mesh.setUV(uv); + if(faces.length>0) mesh.setFaces(faces); + this.setMesh(mesh); +}; + +/** +* Parses the dom element and creates a texture +* @param {domelement} ele the element to create the objects from +* @private +*/ +GLGE.Document.prototype.getOpenCTM=function(ele){ + if(!ele.object){ + var rel=this.getAbsolutePath(this.rootURL,null); + ele.object=new GLGE[this.classString(ele.tagName)]; + //ele.object.setSrc(this.getAbsolutePath(ele.getAttribute("src"),rel)); + ele.object.setSrc(ele.getAttribute("src"),rel); + ele.removeAttribute("src"); + this.setProperties(ele); + } + return ele.object; +} + +GLGE.Scene.prototype.addOpenCTM=GLGE.Scene.prototype.addObject; +})(GLGE); + /* Copyright (c) 2011 Martin Ruenz @@ -24102,3 +23680,420 @@ GUI.Preloader.prototype.fileLoaded = function(args){ GLGE.augment(GUI.Gadget,GUI.Preloader); })(GLGE.GUI);})(GLGE); +/* +Copyright (c) 2011 Martin Ruenz + +Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +/** + * @fileOverview Base class for preloaders. Enables the handling of multiple files. + * @name glge_filepreloader.js + * @author seamonkey@uni-koblenz.de + */ + + +(function(GLGE){ + + + + +/** +* @class FilePreloader class +* @augments GLGE.Events +*/ +GLGE.FilePreloader=function(){ + this.files=[]; +} + +GLGE.augment(GLGE.Events,GLGE.FilePreloader); + +GLGE.FilePreloader.prototype.loadedBytes=0; +GLGE.FilePreloader.prototype.totalBytes=0; +GLGE.FilePreloader.prototype.numLoadedFiles=0; +GLGE.FilePreloader.prototype.numTotalFiles=0; +GLGE.FilePreloader.prototype.sizesCount=0; /** @description Specifies how many file sizes has been collected */ +GLGE.FilePreloader.prototype.progress=0; /** @description 0 - 100 */ +GLGE.FilePreloader.prototype.files=null; /** @description List of files. file: { "url":url,"loaded":fileloaded,"size":filesize,"bytesLoaded":loadedSize, + "type":'xml'/'image',"callback":called when loaded,"content":content, "preloader":GLGE.FilePreloader} */ +/** +* Add a file which has to be loaded +* @param {string} url The url of the file. +* @param {string} type Defines the type of the requested file. "image" or "xml" +* @param {function} [callback] Call this function when the file is loaded and pass the loaded content. +* @public +*/ +GLGE.FilePreloader.prototype.addFile=function(url, type, callback){ + //if(this.files.indexOf(url) != -1) return; + + this.files.push({"url":url,"loaded":false,"size":-1,"bytesLoaded":0,"type":type,"callback":callback,"content":null,"preloader":this}); + this.numTotalFiles++; +} + +/** +* Same as addFile. But instead of creating a new file object use an existing one. +* @param {object} file The file to add. +* @public +*/ +GLGE.FilePreloader.prototype.addFileRef=function(file){ + //if(this.files.indexOf(url) != -1) return; + + this.files.push(file); + this.numTotalFiles++; +} + +/** +* This function accumulates the size of all files. When done it triggers loadFiles(). It has to be called for each file. +* @param {object} file Current file. +* @private +*/ +GLGE.FilePreloader.prototype.accumulateFileSize=function(file) +{ + var req = new XMLHttpRequest(); + req.preloader = this; + req.active = true; + req.file = file; + req.overrideMimeType("text/xml"); + req.onreadystatechange = function() { + if(this.readyState > 1 && req.active) + { + this.active = false; + + this.file.size = parseFloat(this.getResponseHeader('Content-length')); + this.preloader.totalBytes += this.file.size; + + if(++this.preloader.sizesCount >= this.preloader.files.length) // are all file sizes collected? + this.preloader.loadFiles(); + + this.abort(); + this.onreadystatechange = null; + } + }; + req.open("GET", file.url, true); + req.send(""); +} + +/** +* Start loading +* @public +*/ +GLGE.FilePreloader.prototype.start=function(){ + for(i in this.files) + this.accumulateFileSize(this.files[i]); +} + +/** +* Load files. Assumes that the file sizes have been accumulated. +* @private +*/ +GLGE.FilePreloader.prototype.loadFiles=function(){ + + for(i in this.files){ + var file = this.files[i]; + if(file.type == "image") + { + // only update the preloader, when the file is completely loaded (no ajax) + + var image = new Image(); + file.content = image; + var that = this; + image.file = file; + image.onload = function(){ that.fileLoaded(this.file, this.file.size); } + image.src=file.url; + }else{ + // update the preloader each 0.1 seconds (ajax) + + var req = new XMLHttpRequest(); + req.overrideMimeType("text/xml"); + req.preloader = this; + req.file = file; + + var updateTrigger = setInterval (function () + { + if (req.readyState == 3) + { + // TODO: Check if the file reference is always correct + var stepBytes = req.responseText.length - file.bytesLoaded; + file.bytesLoaded = req.responseText.length; + req.preloader.update(stepBytes); + } + + }, 100); + + req.onreadystatechange = function() { + if(this.readyState >= 4) + { + clearInterval(updateTrigger); + this.file.content = this.responseXML; + + var stepBytes = this.responseText.length - this.file.bytesLoaded; + + this.preloader.update(stepBytes); + this.preloader.fileLoaded(this.file, stepBytes); + } + }; + + req.open("GET", file.url, true); + req.send(); + + } + } +} + +/** + * This functions updates the progress. + * @param {number} stepBytes Amount of bytes that have been loaded since the last call. + * @private + */ +GLGE.FilePreloader.prototype.update=function(stepBytes){ + this.loadedBytes += stepBytes; + this.progress = (100.0 * this.loadedBytes) / this.totalBytes; + + this.fireEvent("progress", {"progress":this.progress, "stepBytes":stepBytes, "loadedBytes":this.loadedBytes, "totalBytes":this.totalBytes, "loadedFiles": this.numLoadedFiles, "totalFiles": this.numTotalFiles}); +} + +/** + * Called when a file has been loaded. This function triggers an event and updates the state. + * @param {object} file The file that has been loaded. + * @param {number} stepBytes Amount of bytes that have been loaded since the last call. + * @private + */ +GLGE.FilePreloader.prototype.fileLoaded=function(file, stepBytes){ + + this.numLoadedFiles++; + + // update file + file.loaded = true; + file.bytesLoaded = file.size; + + // update progress + if(this.numLoadedFiles >= this.files.length){ + this.progress = 100; + this.fireEvent("downloadComplete", {"file":file,"stepBytes":stepBytes}); + }else{ + this.update(stepBytes); + } + + // events + this.fireEvent("fileLoaded", {"file":file,"stepBytes":stepBytes}); + if(file.callback) file.callback(file); +} + +/** + * This function returns a list (an array) of all loaded files. + * @public + */ +GLGE.FilePreloader.prototype.getLoadedFiles=function(){ + var result = []; + for(i in this.files) + if(this.files[i].loaded) + result.push(this.files[i]); + return result; +} + +/** + * This function returns information about one file. + * @param {string} url The url of the file. + * @public + */ +GLGE.FilePreloader.prototype.getFile=function(url){ + for(i in this.files) + if(this.files[i].url==url) + return this.files[i]; + return -1; +} + + +})(GLGE); +/* +Copyright (c) 2011 Martin Ruenz + +Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +/** + * @fileOverview + * @name glge_documentpreloader.js + * @author seamonkey@uni-koblenz.de + */ + + +(function(GLGE){ + + + + +/** +* @class Document preloader class +* @augments GLGE.Events +*/ +GLGE.DocumentPreloader=function(doc, args){ + + + // create image preloader + this.imagePreloader = new GLGE.FilePreloader(); + + this.document = doc; + + + if(args.XMLQuota) + this.XMLQuota = args.XMLQuota; + else + this.XMLQuota = 0.2; // 20% XML, 80% images + + this.imageQuota = 1-this.XMLQuota; + + // Passing the size of all xml files will improve the accuracy of the preloader. Alternative: Pass the number of xml files (approximation) + if(args.XMLBytes) + this.XMLBytes = args.XMLBytes; + else if(args.numXMLFiles) + this.numXMLFiles = args.numXMLFiles; + else + this.numXMLFiles = 3; //TODO necessary? +} + +GLGE.augment(GLGE.Events,GLGE.DocumentPreloader); + +GLGE.DocumentPreloader.prototype.progress = 0; + +GLGE.DocumentPreloader.prototype.imageQuota = 0; // size quota of images (Textures) [0..1] +GLGE.DocumentPreloader.prototype.XMLQuota = 0; // size quota XML (Documents) [0..1] + +GLGE.DocumentPreloader.prototype.XMLBytes = -1; // XML size in bytes (for higher accuracy) +GLGE.DocumentPreloader.prototype.totalBytes = -1; // XML size in bytes (highest accuracy) +GLGE.DocumentPreloader.prototype.loadedBytes=0; + +GLGE.DocumentPreloader.prototype.numXMLFiles = 3; // default value + +GLGE.DocumentPreloader.prototype.state = 0; // 0: not yet started, 1: loading XML, 2: loading images, 3: completed +GLGE.DocumentPreloader.prototype.imagePreloader = null; // GLGE.Peloader +GLGE.DocumentPreloader.prototype.document = null; // GLGE.Document + +/** + * Add an image, which should be loaded by the preloader. + * @param {string} url Url of the image. + */ +GLGE.DocumentPreloader.prototype.addImage=function(url){ + this.imagePreloader.addFile(url, "image"); +} + +/** + * Start loading all images in all xml files. Assumes that XML-files have finished loading. + */ +GLGE.DocumentPreloader.prototype.loadImages=function(){ + + this.changeState(2); + + if(this.progress < this.XMLQuota * 100.0) this.progress = this.XMLQuota * 100.0; // correct progress. + + var that = this; + this.imagePreloader.addEventListener("progress", function(args){that.updateProgress.call(that, args);}); + this.imagePreloader.addEventListener("downloadComplete", function(args){that.finish.call(that, args);}); + this.imagePreloader.addEventListener("fileLoaded", function(args){that.fireEvent("fileLoaded", args.file);}); + this.imagePreloader.start(); +} + +/** + * Update preloader progress. + * @param {object} args Progress information. + *
args.stepBytes describes how many bytes have been loaded since the last update. + */ +GLGE.DocumentPreloader.prototype.updateProgress=function(args){ + + if(this.state < 2){ // loading xml + + if(this.XMLBytes > 0){ // high accuracy + //if(!args.stepBytes) args.stepBytes = 0; + this.loadedBytes += args.stepBytes; + this.progress = this.XMLQuota * 100.0 * this.loadedBytes / this.XMLBytes; + } + else{ // low accuracy + this.progress += this.XMLQuota * 100.0 / this.numXMLFiles; + if(this.progress > this.XMLQuota * 100) this.progress = this.XMLQuota * 100; + } + } + else{ // loading images + this.progress = this.XMLQuota * 100 + this.imageQuota * this.imagePreloader.progress; + } + this.fireEvent("progress", {"progress":this.progress, "stepBytes":args.stepBytes, "loadedBytes":args.loadedBytes, "totalBytes":args.totalBytes, "loadedFiles": args.loadedFiles, "totalFiles": args.totalFiles}); +} + +/** + * This function loads a XML-file. Assumes that loading images hasn't yet begun. + * @param {string} url Url of the XML-file. + */ +GLGE.DocumentPreloader.prototype.loadXMLFile=function(url){ + + this.changeState(1); + + var xmlPreloader = new GLGE.FilePreloader(); + xmlPreloader.addFile(url, "xml"); + + var that = this; + + if(this.XMLBytes > 0) xmlPreloader.addEventListener("progress", function(arg){that.updateProgress.call(that, arg);}); // high accuracy + else xmlPreloader.addEventListener("downloadComplete", function(arg){that.updateProgress.call(that, arg);}); // low accuracy + + var doc = this.document; + xmlPreloader.addEventListener("fileLoaded", function(args){ + args.file.content.getElementById=doc.getElementById; + doc.loaded(args.file.url,args.file.content); + that.fireEvent("fileLoaded", args.file); + }); + + xmlPreloader.start(); +} + +/** + * Sets the state of the document preloader. + * @param {number} newState New state + */ +GLGE.DocumentPreloader.prototype.changeState = function(newState) { + //if(this.state > newState) GLGE.warning("GLGE.DocumentPreloader.prototype.changeState: The new state is lower than the old."); + this.state = newState; + this.fireEvent("stateChange", newState); +} + +/** + * Called when the document preloader loaded all files. + * @param {object} event Event parameter. Not used at all. + */ +GLGE.DocumentPreloader.prototype.finish=function(event){ + this.changeState(3); + this.progress = 100; + this.fireEvent("downloadComplete"); +} + +})(GLGE); diff --git a/src/material/glge_material.js b/src/material/glge_material.js index d04aedc..a0ce553 100644 --- a/src/material/glge_material.js +++ b/src/material/glge_material.js @@ -787,8 +787,8 @@ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection shader=shader+"uniform vec3 lightAttenuation"+i+";\n"; shader=shader+"uniform float spotCosCutOff"+i+";\n"; shader=shader+"uniform float spotExp"+i+";\n"; - shader=shader+"uniform vec3 lightdir"+i+";\n"; - shader=shader+"uniform mat4 lightmat"+i+";\n"; + shader=shader+"uniform mediump vec3 lightdir"+i+";\n"; + shader=shader+"uniform mediump mat4 lightmat"+i+";\n"; shader=shader+"uniform float shadowbias"+i+";\n"; shader=shader+"uniform int shadowsamples"+i+";\n"; shader=shader+"uniform float shadowsoftness"+i+";\n"; @@ -827,8 +827,8 @@ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection shader=shader+"uniform int fogtype;\n"; shader=shader+"uniform vec3 fogcolor;\n"; shader=shader+"uniform float far;\n"; - shader=shader+"uniform mat4 worldInverseTranspose;\n"; - shader=shader+"uniform mat4 projection;\n"; + shader=shader+"uniform mediump mat4 worldInverseTranspose;\n"; + shader=shader+"uniform mediump mat4 projection;\n"; shader=shader+"uniform bool emitpass;\n"; shader=shader+"uniform bool shadeless;\n"; @@ -1017,7 +1017,7 @@ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection shader=shader+"vec4 dist;float depth,m1,m2,prob,variance;\n"; shader=shader+"if (normal.z<0.0) {normal.z=0.0;}\n"; - + shader=shader+"float fogfact=1.0;"; shader=shader+"if(fogtype=="+GLGE.FOG_QUADRATIC+" || fogtype=="+GLGE.FOG_SKYQUADRATIC+") fogfact=clamp(pow(max((fogfar - length(eyevec)) / (fogfar - fognear),0.0),2.0),0.0,1.0);\n"; shader=shader+"if(fogtype=="+GLGE.FOG_LINEAR+" || fogtype=="+GLGE.FOG_SKYLINEAR+") fogfact=clamp((fogfar - length(eyevec)) / (fogfar - fognear),0.0,1.0);\n"; @@ -1032,7 +1032,7 @@ GLGE.Material.prototype.getFragmentShader=function(lights,colors,shaderInjection shader=shader+"gl_FragColor.a=gl_FragColor.a*(1.0-min(1.0,"+this.fadeDistance.toFixed(5)+"/length(eyevec)));\n"; } shader=shader+"} else {\n"; - + for(var i=0; i