/*! Babylon 2014-08-08 */ var BABYLON;!function(a){var b=function(){function a(a,b,c){"undefined"==typeof a&&(a=0),"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=0),this.r=a,this.g=b,this.b=c}return a.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},a.prototype.toArray=function(a,b){void 0===b&&(b=0),a[b]=this.r,a[b+1]=this.g,a[b+2]=this.b},a.prototype.asArray=function(){var a=[];return this.toArray(a,0),a},a.prototype.multiply=function(b){return new a(this.r*b.r,this.g*b.g,this.b*b.b)},a.prototype.multiplyToRef=function(a,b){b.r=this.r*a.r,b.g=this.g*a.g,b.b=this.b*a.b},a.prototype.equals=function(a){return a&&this.r===a.r&&this.g===a.g&&this.b===a.b},a.prototype.scale=function(b){return new a(this.r*b,this.g*b,this.b*b)},a.prototype.scaleToRef=function(a,b){b.r=this.r*a,b.g=this.g*a,b.b=this.b*a},a.prototype.add=function(b){return new a(this.r+b.r,this.g+b.g,this.b+b.b)},a.prototype.addToRef=function(a,b){b.r=this.r+a.r,b.g=this.g+a.g,b.b=this.b+a.b},a.prototype.subtract=function(b){return new a(this.r-b.r,this.g-b.g,this.b-b.b)},a.prototype.subtractToRef=function(a,b){b.r=this.r-a.r,b.g=this.g-a.g,b.b=this.b-a.b},a.prototype.clone=function(){return new a(this.r,this.g,this.b)},a.prototype.copyFrom=function(a){this.r=a.r,this.g=a.g,this.b=a.b},a.prototype.copyFromFloats=function(a,b,c){this.r=a,this.g=b,this.b=c},a.FromArray=function(b){return new a(b[0],b[1],b[2])},a.FromInts=function(b,c,d){return new a(b/255,c/255,d/255)},a.Lerp=function(b,c,d){var e=b.r+(c.r-b.r)*d,f=b.g+(c.g-b.g)*d,g=b.b+(c.b-b.b)*d;return new a(e,f,g)},a.Red=function(){return new a(1,0,0)},a.Green=function(){return new a(0,1,0)},a.Blue=function(){return new a(0,0,1)},a.Black=function(){return new a(0,0,0)},a.White=function(){return new a(1,1,1)},a.Purple=function(){return new a(.5,0,.5)},a.Magenta=function(){return new a(1,0,1)},a.Yellow=function(){return new a(1,1,0)},a.Gray=function(){return new a(.5,.5,.5)},a}();a.Color3=b;var c=function(){function b(a,b,c,d){this.r=a,this.g=b,this.b=c,this.a=d}return b.prototype.addInPlace=function(a){this.r+=a.r,this.g+=a.g,this.b+=a.b,this.a+=a.a},b.prototype.asArray=function(){var a=[];return this.toArray(a,0),a},b.prototype.toArray=function(a,b){void 0===b&&(b=0),a[b]=this.r,a[b+1]=this.g,a[b+2]=this.b,a[b+3]=this.a},b.prototype.add=function(a){return new b(this.r+a.r,this.g+a.g,this.b+a.b,this.a+a.a)},b.prototype.subtract=function(a){return new b(this.r-a.r,this.g-a.g,this.b-a.b,this.a-a.a)},b.prototype.subtractToRef=function(a,b){b.r=this.r-a.r,b.g=this.g-a.g,b.b=this.b-a.b,b.a=this.a-a.a},b.prototype.scale=function(a){return new b(this.r*a,this.g*a,this.b*a,this.a*a)},b.prototype.scaleToRef=function(a,b){b.r=this.r*a,b.g=this.g*a,b.b=this.b*a,b.a=this.a*a},b.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},b.prototype.clone=function(){return new b(this.r,this.g,this.b,this.a)},b.Lerp=function(c,d,e){var f=new b(0,0,0,0);return a.Color4.LerpToRef(c,d,e,f),f},b.LerpToRef=function(a,b,c,d){d.r=a.r+(b.r-a.r)*c,d.g=a.g+(b.g-a.g)*c,d.b=a.b+(b.b-a.b)*c,d.a=a.a+(b.a-a.a)*c},b.FromArray=function(a,c){return"undefined"==typeof c&&(c=0),new b(a[c],a[c+1],a[c+2],a[c+3])},b.FromInts=function(a,c,d,e){return new b(a/255,c/255,d/255,e/255)},b}();a.Color4=c;var d=function(){function a(a,b){this.x=a,this.y=b}return a.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},a.prototype.toArray=function(a,b){void 0===b&&(b=0),a[b]=this.x,a[b+1]=this.y},a.prototype.asArray=function(){var a=[];return this.toArray(a,0),a},a.prototype.copyFrom=function(a){this.x=a.x,this.y=a.y},a.prototype.add=function(b){return new a(this.x+b.x,this.y+b.y)},a.prototype.subtract=function(b){return new a(this.x-b.x,this.y-b.y)},a.prototype.negate=function(){return new a(-this.x,-this.y)},a.prototype.scaleInPlace=function(a){this.x*=a,this.y*=a},a.prototype.scale=function(b){return new a(this.x*b,this.y*b)},a.prototype.equals=function(a){return a&&this.x===a.x&&this.y===a.y},a.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},a.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},a.prototype.normalize=function(){var a=this.length();if(0!==a){var b=1/a;this.x*=b,this.y*=b}},a.prototype.clone=function(){return new a(this.x,this.y)},a.Zero=function(){return new a(0,0)},a.FromArray=function(b,c){return c||(c=0),new a(b[c],b[c+1])},a.CatmullRom=function(b,c,d,e,f){var g=f*f,h=f*g,i=.5*(2*c.x+(-b.x+d.x)*f+(2*b.x-5*c.x+4*d.x-e.x)*g+(-b.x+3*c.x-3*d.x+e.x)*h),j=.5*(2*c.y+(-b.y+d.y)*f+(2*b.y-5*c.y+4*d.y-e.y)*g+(-b.y+3*c.y-3*d.y+e.y)*h);return new a(i,j)},a.Clamp=function(b,c,d){var e=b.x;e=e>d.x?d.x:e,e=ed.y?d.y:f,f=fc.x?b.x:c.x,e=b.y>c.y?b.y:c.y;return new a(d,e)},a.Transform=function(b,c){var d=b.x*c.m[0]+b.y*c.m[4],e=b.x*c.m[1]+b.y*c.m[5];return new a(d,e)},a.Distance=function(b,c){return Math.sqrt(a.DistanceSquared(b,c))},a.DistanceSquared=function(a,b){var c=a.x-b.x,d=a.y-b.y;return c*c+d*d},a}();a.Vector2=d;var e=function(){function b(a,b,c){this.x=a,this.y=b,this.z=c}return b.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},b.prototype.asArray=function(){var a=[];return this.toArray(a,0),a},b.prototype.toArray=function(a,b){void 0===b&&(b=0),a[b]=this.x,a[b+1]=this.y,a[b+2]=this.z},b.prototype.addInPlace=function(a){this.x+=a.x,this.y+=a.y,this.z+=a.z},b.prototype.add=function(a){return new b(this.x+a.x,this.y+a.y,this.z+a.z)},b.prototype.addToRef=function(a,b){b.x=this.x+a.x,b.y=this.y+a.y,b.z=this.z+a.z},b.prototype.subtractInPlace=function(a){this.x-=a.x,this.y-=a.y,this.z-=a.z},b.prototype.subtract=function(a){return new b(this.x-a.x,this.y-a.y,this.z-a.z)},b.prototype.subtractToRef=function(a,b){b.x=this.x-a.x,b.y=this.y-a.y,b.z=this.z-a.z},b.prototype.subtractFromFloats=function(a,c,d){return new b(this.x-a,this.y-c,this.z-d)},b.prototype.subtractFromFloatsToRef=function(a,b,c,d){d.x=this.x-a,d.y=this.y-b,d.z=this.z-c},b.prototype.negate=function(){return new b(-this.x,-this.y,-this.z)},b.prototype.scaleInPlace=function(a){this.x*=a,this.y*=a,this.z*=a},b.prototype.scale=function(a){return new b(this.x*a,this.y*a,this.z*a)},b.prototype.scaleToRef=function(a,b){b.x=this.x*a,b.y=this.y*a,b.z=this.z*a},b.prototype.equals=function(a){return a&&this.x===a.x&&this.y===a.y&&this.z===a.z},b.prototype.equalsWithEpsilon=function(b){return Math.abs(this.x-b.x)this.x&&(this.x=a.x),a.y>this.y&&(this.y=a.y),a.z>this.z&&(this.z=a.z)},b.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},b.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},b.prototype.normalize=function(){var a=this.length();if(0!==a){var b=1/a;this.x*=b,this.y*=b,this.z*=b}},b.prototype.clone=function(){return new b(this.x,this.y,this.z)},b.prototype.copyFrom=function(a){this.x=a.x,this.y=a.y,this.z=a.z},b.prototype.copyFromFloats=function(a,b,c){this.x=a,this.y=b,this.z=c},b.FromArray=function(a,c){return c||(c=0),new b(a[c],a[c+1],a[c+2])},b.FromArrayToRef=function(a,b,c){c.x=a[b],c.y=a[b+1],c.z=a[b+2]},b.FromFloatArrayToRef=function(a,b,c){c.x=a[b],c.y=a[b+1],c.z=a[b+2]},b.FromFloatsToRef=function(a,b,c,d){d.x=a,d.y=b,d.z=c},b.Zero=function(){return new b(0,0,0)},b.Up=function(){return new b(0,1,0)},b.TransformCoordinates=function(a,c){var d=b.Zero();return b.TransformCoordinatesToRef(a,c,d),d},b.TransformCoordinatesToRef=function(a,b,c){var d=a.x*b.m[0]+a.y*b.m[4]+a.z*b.m[8]+b.m[12],e=a.x*b.m[1]+a.y*b.m[5]+a.z*b.m[9]+b.m[13],f=a.x*b.m[2]+a.y*b.m[6]+a.z*b.m[10]+b.m[14],g=a.x*b.m[3]+a.y*b.m[7]+a.z*b.m[11]+b.m[15];c.x=d/g,c.y=e/g,c.z=f/g},b.TransformCoordinatesFromFloatsToRef=function(a,b,c,d,e){var f=a*d.m[0]+b*d.m[4]+c*d.m[8]+d.m[12],g=a*d.m[1]+b*d.m[5]+c*d.m[9]+d.m[13],h=a*d.m[2]+b*d.m[6]+c*d.m[10]+d.m[14],i=a*d.m[3]+b*d.m[7]+c*d.m[11]+d.m[15];e.x=f/i,e.y=g/i,e.z=h/i},b.TransformNormal=function(a,c){var d=b.Zero();return b.TransformNormalToRef(a,c,d),d},b.TransformNormalToRef=function(a,b,c){c.x=a.x*b.m[0]+a.y*b.m[4]+a.z*b.m[8],c.y=a.x*b.m[1]+a.y*b.m[5]+a.z*b.m[9],c.z=a.x*b.m[2]+a.y*b.m[6]+a.z*b.m[10]},b.TransformNormalFromFloatsToRef=function(a,b,c,d,e){e.x=a*d.m[0]+b*d.m[4]+c*d.m[8],e.y=a*d.m[1]+b*d.m[5]+c*d.m[9],e.z=a*d.m[2]+b*d.m[6]+c*d.m[10]},b.CatmullRom=function(a,c,d,e,f){var g=f*f,h=f*g,i=.5*(2*c.x+(-a.x+d.x)*f+(2*a.x-5*c.x+4*d.x-e.x)*g+(-a.x+3*c.x-3*d.x+e.x)*h),j=.5*(2*c.y+(-a.y+d.y)*f+(2*a.y-5*c.y+4*d.y-e.y)*g+(-a.y+3*c.y-3*d.y+e.y)*h),k=.5*(2*c.z+(-a.z+d.z)*f+(2*a.z-5*c.z+4*d.z-e.z)*g+(-a.z+3*c.z-3*d.z+e.z)*h);return new b(i,j,k)},b.Clamp=function(a,c,d){var e=a.x;e=e>d.x?d.x:e,e=ed.y?d.y:f,f=fd.z?d.z:g,g=g.499?(i=2*Math.atan2(a,d),k=0):-.499>l&&(i=-2*Math.atan2(a,d),k=0),new e(j,i,k)},a.prototype.toRotationMatrix=function(a){var b=this.x*this.x,c=this.y*this.y,d=this.z*this.z,e=this.x*this.y,f=this.z*this.w,g=this.z*this.x,h=this.y*this.w,i=this.y*this.z,j=this.x*this.w;a.m[0]=1-2*(c+d),a.m[1]=2*(e+f),a.m[2]=2*(g-h),a.m[3]=0,a.m[4]=2*(e-f),a.m[5]=1-2*(d+b),a.m[6]=2*(i+j),a.m[7]=0,a.m[8]=2*(g+h),a.m[9]=2*(i-j),a.m[10]=1-2*(c+b),a.m[11]=0,a.m[12]=0,a.m[13]=0,a.m[14]=0,a.m[15]=1},a.prototype.fromRotationMatrix=function(a){var b,c=a.m,d=c[0],e=c[4],f=c[8],g=c[1],h=c[5],i=c[9],j=c[2],k=c[6],l=c[10],m=d+h+l;return m>0?(b=.5/Math.sqrt(m+1),this.w=.25/b,this.x=(k-i)*b,this.y=(f-j)*b,void(this.z=(g-e)*b)):d>h&&d>l?(b=2*Math.sqrt(1+d-h-l),this.w=(k-i)/b,this.x=.25*b,this.y=(e+g)/b,void(this.z=(f+j)/b)):h>l?(b=2*Math.sqrt(1+h-d-l),this.w=(f-j)/b,this.x=(e+g)/b,this.y=.25*b,void(this.z=(i+k)/b)):(b=2*Math.sqrt(1+l-d-h),this.w=(g-e)/b,this.x=(f+j)/b,this.y=(i+k)/b,void(this.z=.25*b))},a.RotationAxis=function(b,c){var d=new a,e=Math.sin(c/2);return d.w=Math.cos(c/2),d.x=b.x*e,d.y=b.y*e,d.z=b.z*e,d},a.FromArray=function(b,c){return c||(c=0),new a(b[c],b[c+1],b[c+2],b[c+3])},a.RotationYawPitchRoll=function(b,c,d){var e=new a;return a.RotationYawPitchRollToRef(b,c,d,e),e},a.RotationYawPitchRollToRef=function(a,b,c,d){var e=.5*c,f=.5*b,g=.5*a,h=Math.sin(e),i=Math.cos(e),j=Math.sin(f),k=Math.cos(f),l=Math.sin(g),m=Math.cos(g);d.x=m*j*i+l*k*h,d.y=l*k*i-m*j*h,d.z=m*k*h-l*j*i,d.w=m*k*i+l*j*h},a.Slerp=function(b,c,d){var e,f,g=d,h=b.x*c.x+b.y*c.y+b.z*c.z+b.w*c.w,i=!1;if(0>h&&(i=!0,h=-h),h>.999999)f=1-g,e=i?-g:g;else{var j=Math.acos(h),k=1/Math.sin(j);f=Math.sin((1-g)*j)*k,e=i?-Math.sin(g*j)*k:Math.sin(g*j)*k}return new a(f*b.x+e*c.x,f*b.y+e*c.y,f*b.z+e*c.z,f*b.w+e*c.w)},a}();a.Quaternion=f;var g=function(){function a(){this.m=new Float32Array(16)}return a.prototype.isIdentity=function(){return 1!=this.m[0]||1!=this.m[5]||1!=this.m[10]||1!=this.m[15]?!1:0!=this.m[1]||0!=this.m[2]||0!=this.m[3]||0!=this.m[4]||0!=this.m[6]||0!=this.m[7]||0!=this.m[8]||0!=this.m[9]||0!=this.m[11]||0!=this.m[12]||0!=this.m[13]||0!=this.m[14]?!1:!0},a.prototype.determinant=function(){var a=this.m[10]*this.m[15]-this.m[11]*this.m[14],b=this.m[9]*this.m[15]-this.m[11]*this.m[13],c=this.m[9]*this.m[14]-this.m[10]*this.m[13],d=this.m[8]*this.m[15]-this.m[11]*this.m[12],e=this.m[8]*this.m[14]-this.m[10]*this.m[12],f=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*a-this.m[6]*b+this.m[7]*c)-this.m[1]*(this.m[4]*a-this.m[6]*d+this.m[7]*e)+this.m[2]*(this.m[4]*b-this.m[5]*d+this.m[7]*f)-this.m[3]*(this.m[4]*c-this.m[5]*e+this.m[6]*f)},a.prototype.toArray=function(){return this.m},a.prototype.asArray=function(){return this.toArray()},a.prototype.invert=function(){this.invertToRef(this)},a.prototype.invertToRef=function(a){var b=this.m[0],c=this.m[1],d=this.m[2],e=this.m[3],f=this.m[4],g=this.m[5],h=this.m[6],i=this.m[7],j=this.m[8],k=this.m[9],l=this.m[10],m=this.m[11],n=this.m[12],o=this.m[13],p=this.m[14],q=this.m[15],r=l*q-m*p,s=k*q-m*o,t=k*p-l*o,u=j*q-m*n,v=j*p-l*n,w=j*o-k*n,x=g*r-h*s+i*t,y=-(f*r-h*u+i*v),z=f*s-g*u+i*w,A=-(f*t-g*v+h*w),B=1/(b*x+c*y+d*z+e*A),C=h*q-i*p,D=g*q-i*o,E=g*p-h*o,F=f*q-i*n,G=f*p-h*n,H=f*o-g*n,I=h*m-i*l,J=g*m-i*k,K=g*l-h*k,L=f*m-i*j,M=f*l-h*j,N=f*k-g*j;a.m[0]=x*B,a.m[4]=y*B,a.m[8]=z*B,a.m[12]=A*B,a.m[1]=-(c*r-d*s+e*t)*B,a.m[5]=(b*r-d*u+e*v)*B,a.m[9]=-(b*s-c*u+e*w)*B,a.m[13]=(b*t-c*v+d*w)*B,a.m[2]=(c*C-d*D+e*E)*B,a.m[6]=-(b*C-d*F+e*G)*B,a.m[10]=(b*D-c*F+e*H)*B,a.m[14]=-(b*E-c*G+d*H)*B,a.m[3]=-(c*I-d*J+e*K)*B,a.m[7]=(b*I-d*L+e*M)*B,a.m[11]=-(b*J-c*L+e*N)*B,a.m[15]=(b*K-c*M+d*N)*B},a.prototype.setTranslation=function(a){this.m[12]=a.x,this.m[13]=a.y,this.m[14]=a.z},a.prototype.multiply=function(b){var c=new a;return this.multiplyToRef(b,c),c},a.prototype.copyFrom=function(a){for(var b=0;16>b;b++)this.m[b]=a.m[b]},a.prototype.copyToArray=function(a,b){"undefined"==typeof b&&(b=0);for(var c=0;16>c;c++)a[b+c]=this.m[c]},a.prototype.multiplyToRef=function(a,b){this.multiplyToArray(a,b.m,0)},a.prototype.multiplyToArray=function(a,b,c){var d=this.m[0],e=this.m[1],f=this.m[2],g=this.m[3],h=this.m[4],i=this.m[5],j=this.m[6],k=this.m[7],l=this.m[8],m=this.m[9],n=this.m[10],o=this.m[11],p=this.m[12],q=this.m[13],r=this.m[14],s=this.m[15],t=a.m[0],u=a.m[1],v=a.m[2],w=a.m[3],x=a.m[4],y=a.m[5],z=a.m[6],A=a.m[7],B=a.m[8],C=a.m[9],D=a.m[10],E=a.m[11],F=a.m[12],G=a.m[13],H=a.m[14],I=a.m[15];b[c]=d*t+e*x+f*B+g*F,b[c+1]=d*u+e*y+f*C+g*G,b[c+2]=d*v+e*z+f*D+g*H,b[c+3]=d*w+e*A+f*E+g*I,b[c+4]=h*t+i*x+j*B+k*F,b[c+5]=h*u+i*y+j*C+k*G,b[c+6]=h*v+i*z+j*D+k*H,b[c+7]=h*w+i*A+j*E+k*I,b[c+8]=l*t+m*x+n*B+o*F,b[c+9]=l*u+m*y+n*C+o*G,b[c+10]=l*v+m*z+n*D+o*H,b[c+11]=l*w+m*A+n*E+o*I,b[c+12]=p*t+q*x+r*B+s*F,b[c+13]=p*u+q*y+r*C+s*G,b[c+14]=p*v+q*z+r*D+s*H,b[c+15]=p*w+q*A+r*E+s*I},a.prototype.equals=function(a){return a&&this.m[0]===a.m[0]&&this.m[1]===a.m[1]&&this.m[2]===a.m[2]&&this.m[3]===a.m[3]&&this.m[4]===a.m[4]&&this.m[5]===a.m[5]&&this.m[6]===a.m[6]&&this.m[7]===a.m[7]&&this.m[8]===a.m[8]&&this.m[9]===a.m[9]&&this.m[10]===a.m[10]&&this.m[11]===a.m[11]&&this.m[12]===a.m[12]&&this.m[13]===a.m[13]&&this.m[14]===a.m[14]&&this.m[15]===a.m[15]},a.prototype.clone=function(){return a.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15])},a.FromArray=function(b,c){var d=new a;return c||(c=0),a.FromArrayToRef(b,c,d),d},a.FromArrayToRef=function(a,b,c){for(var d=0;16>d;d++)c.m[d]=a[d+b]},a.FromValuesToRef=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){q.m[0]=a,q.m[1]=b,q.m[2]=c,q.m[3]=d,q.m[4]=e,q.m[5]=f,q.m[6]=g,q.m[7]=h,q.m[8]=i,q.m[9]=j,q.m[10]=k,q.m[11]=l,q.m[12]=m,q.m[13]=n,q.m[14]=o,q.m[15]=p},a.FromValues=function(b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){var r=new a;return r.m[0]=b,r.m[1]=c,r.m[2]=d,r.m[3]=e,r.m[4]=f,r.m[5]=g,r.m[6]=h,r.m[7]=i,r.m[8]=j,r.m[9]=k,r.m[10]=l,r.m[11]=m,r.m[12]=n,r.m[13]=o,r.m[14]=p,r.m[15]=q,r},a.Identity=function(){return a.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},a.IdentityToRef=function(b){a.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,b)},a.Zero=function(){return a.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},a.RotationX=function(b){var c=new a;return a.RotationXToRef(b,c),c},a.RotationXToRef=function(a,b){var c=Math.sin(a),d=Math.cos(a);b.m[0]=1,b.m[15]=1,b.m[5]=d,b.m[10]=d,b.m[9]=-c,b.m[6]=c,b.m[1]=0,b.m[2]=0,b.m[3]=0,b.m[4]=0,b.m[7]=0,b.m[8]=0,b.m[11]=0,b.m[12]=0,b.m[13]=0,b.m[14]=0},a.RotationY=function(b){var c=new a;return a.RotationYToRef(b,c),c},a.RotationYToRef=function(a,b){var c=Math.sin(a),d=Math.cos(a);b.m[5]=1,b.m[15]=1,b.m[0]=d,b.m[2]=-c,b.m[8]=c,b.m[10]=d,b.m[1]=0,b.m[3]=0,b.m[4]=0,b.m[6]=0,b.m[7]=0,b.m[9]=0,b.m[11]=0,b.m[12]=0,b.m[13]=0,b.m[14]=0},a.RotationZ=function(b){var c=new a;return a.RotationZToRef(b,c),c},a.RotationZToRef=function(a,b){var c=Math.sin(a),d=Math.cos(a);b.m[10]=1,b.m[15]=1,b.m[0]=d,b.m[1]=c,b.m[4]=-c,b.m[5]=d,b.m[2]=0,b.m[3]=0,b.m[6]=0,b.m[7]=0,b.m[8]=0,b.m[9]=0,b.m[11]=0,b.m[12]=0,b.m[13]=0,b.m[14]=0},a.RotationAxis=function(b,c){var d=Math.sin(-c),e=Math.cos(-c),f=1-e;b.normalize();var g=a.Zero();return g.m[0]=b.x*b.x*f+e,g.m[1]=b.x*b.y*f-b.z*d,g.m[2]=b.x*b.z*f+b.y*d,g.m[3]=0,g.m[4]=b.y*b.x*f+b.z*d,g.m[5]=b.y*b.y*f+e,g.m[6]=b.y*b.z*f-b.x*d,g.m[7]=0,g.m[8]=b.z*b.x*f-b.y*d,g.m[9]=b.z*b.y*f+b.x*d,g.m[10]=b.z*b.z*f+e,g.m[11]=0,g.m[15]=1,g},a.RotationYawPitchRoll=function(b,c,d){var e=new a;return a.RotationYawPitchRollToRef(b,c,d,e),e},a.RotationYawPitchRollToRef=function(a,b,c,d){f.RotationYawPitchRollToRef(a,b,c,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(d)},a.Scaling=function(b,c,d){var e=a.Zero();return a.ScalingToRef(b,c,d,e),e},a.ScalingToRef=function(a,b,c,d){d.m[0]=a,d.m[1]=0,d.m[2]=0,d.m[3]=0,d.m[4]=0,d.m[5]=b,d.m[6]=0,d.m[7]=0,d.m[8]=0,d.m[9]=0,d.m[10]=c,d.m[11]=0,d.m[12]=0,d.m[13]=0,d.m[14]=0,d.m[15]=1},a.Translation=function(b,c,d){var e=a.Identity();return a.TranslationToRef(b,c,d,e),e},a.TranslationToRef=function(b,c,d,e){a.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,b,c,d,1,e)},a.LookAtLH=function(b,c,d){var e=a.Zero();return a.LookAtLHToRef(b,c,d,e),e},a.LookAtLHToRef=function(b,c,d,f){c.subtractToRef(b,this._zAxis),this._zAxis.normalize(),e.CrossToRef(d,this._zAxis,this._xAxis),this._xAxis.normalize(),e.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var g=-e.Dot(this._xAxis,b),h=-e.Dot(this._yAxis,b),i=-e.Dot(this._zAxis,b);return a.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,g,h,i,1,f)},a.OrthoLH=function(b,c,d,e){var f=2/b,g=2/c,h=1/(e-d),i=d/(d-e);return a.FromValues(f,0,0,0,0,g,0,0,0,0,h,0,0,0,i,1)},a.OrthoOffCenterLH=function(b,c,d,e,f,g){var h=a.Zero();return a.OrthoOffCenterLHToRef(b,c,d,e,f,g,h),h},a.OrthoOffCenterLHToRef=function(a,b,c,d,e,f,g){g.m[0]=2/(b-a),g.m[1]=g.m[2]=g.m[3]=0,g.m[5]=2/(d-c),g.m[4]=g.m[6]=g.m[7]=0,g.m[10]=-1/(e-f),g.m[8]=g.m[9]=g.m[11]=0,g.m[12]=(a+b)/(a-b),g.m[13]=(d+c)/(c-d),g.m[14]=e/(e-f),g.m[15]=1},a.PerspectiveLH=function(b,c,d,e){var f=a.Zero();return f.m[0]=2*d/b,f.m[1]=f.m[2]=f.m[3]=0,f.m[5]=2*d/c,f.m[4]=f.m[6]=f.m[7]=0,f.m[10]=-e/(d-e),f.m[8]=f.m[9]=0,f.m[11]=1,f.m[12]=f.m[13]=f.m[15]=0,f.m[14]=d*e/(d-e),f},a.PerspectiveFovLH=function(b,c,d,e){var f=a.Zero();return a.PerspectiveFovLHToRef(b,c,d,e,f),f},a.PerspectiveFovLHToRef=function(a,b,c,d,e){var f=1/Math.tan(.5*a);e.m[0]=f/b,e.m[1]=e.m[2]=e.m[3]=0,e.m[5]=f,e.m[4]=e.m[6]=e.m[7]=0,e.m[8]=e.m[9]=0,e.m[10]=-d/(c-d),e.m[11]=1,e.m[12]=e.m[13]=e.m[15]=0,e.m[14]=c*d/(c-d)},a.GetFinalMatrix=function(b,c,d,e,f,g){var h=b.width,i=b.height,j=b.x,k=b.y,l=a.FromValues(h/2,0,0,0,0,-i/2,0,0,0,0,g-f,0,j+h/2,i/2+k,f,1);return c.multiply(d).multiply(e).multiply(l)},a.Transpose=function(b){var c=new a;return c.m[0]=b.m[0],c.m[1]=b.m[4],c.m[2]=b.m[8],c.m[3]=b.m[12],c.m[4]=b.m[1],c.m[5]=b.m[5],c.m[6]=b.m[9],c.m[7]=b.m[13],c.m[8]=b.m[2],c.m[9]=b.m[6],c.m[10]=b.m[10],c.m[11]=b.m[14],c.m[12]=b.m[3],c.m[13]=b.m[7],c.m[14]=b.m[11],c.m[15]=b.m[15],c},a.Reflection=function(b){var c=new a;return a.ReflectionToRef(b,c),c},a.ReflectionToRef=function(a,b){a.normalize();var c=a.normal.x,d=a.normal.y,e=a.normal.z,f=-2*c,g=-2*d,h=-2*e;b.m[0]=f*c+1,b.m[1]=g*c,b.m[2]=h*c,b.m[3]=0,b.m[4]=f*d,b.m[5]=g*d+1,b.m[6]=h*d,b.m[7]=0,b.m[8]=f*e,b.m[9]=g*e,b.m[10]=h*e+1,b.m[11]=0,b.m[12]=f*a.d,b.m[13]=g*a.d,b.m[14]=h*a.d,b.m[15]=1},a._tempQuaternion=new f,a._xAxis=e.Zero(),a._yAxis=e.Zero(),a._zAxis=e.Zero(),a}();a.Matrix=g;var h=function(){function b(a,b,c,d){this.normal=new e(a,b,c),this.d=d}return b.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},b.prototype.clone=function(){return new b(this.normal.x,this.normal.y,this.normal.z,this.d)},b.prototype.normalize=function(){var a=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),b=0;0!=a&&(b=1/a),this.normal.x*=b,this.normal.y*=b,this.normal.z*=b,this.d*=b},b.prototype.transform=function(b){var c=a.Matrix.Transpose(b),d=this.normal.x,e=this.normal.y,f=this.normal.z,g=this.d,h=d*c.m[0]+e*c.m[1]+f*c.m[2]+g*c.m[3],i=d*c.m[4]+e*c.m[5]+f*c.m[6]+g*c.m[7],j=d*c.m[8]+e*c.m[9]+f*c.m[10]+g*c.m[11],k=d*c.m[12]+e*c.m[13]+f*c.m[14]+g*c.m[15];return new a.Plane(h,i,j,k)},b.prototype.dotCoordinate=function(a){return this.normal.x*a.x+this.normal.y*a.y+this.normal.z*a.z+this.d},b.prototype.copyFromPoints=function(a,b,c){var d,e=b.x-a.x,f=b.y-a.y,g=b.z-a.z,h=c.x-a.x,i=c.y-a.y,j=c.z-a.z,k=f*j-g*i,l=g*h-e*j,m=e*i-f*h,n=Math.sqrt(k*k+l*l+m*m);d=0!=n?1/n:0,this.normal.x=k*d,this.normal.y=l*d,this.normal.z=m*d,this.d=-(this.normal.x*a.x+this.normal.y*a.y+this.normal.z*a.z)},b.prototype.isFrontFacingTo=function(a,b){var c=e.Dot(this.normal,a);return b>=c},b.prototype.signedDistanceTo=function(a){return e.Dot(a,this.normal)+this.d},b.FromArray=function(b){return new a.Plane(b[0],b[1],b[2],b[3])},b.FromPoints=function(b,c,d){var e=new a.Plane(0,0,0,0);return e.copyFromPoints(b,c,d),e},b.FromPositionAndNormal=function(b,c){var d=new a.Plane(0,0,0,0);return c.normalize(),d.normal=c,d.d=-(c.x*b.x+c.y*b.y+c.z*b.z),d},b.SignedDistanceToPlaneFromPositionAndNormal=function(a,b,c){var d=-(b.x*a.x+b.y*a.y+b.z*a.z);return e.Dot(c,b)+d},b}();a.Plane=h;var i=function(){function a(a,b,c,d){this.x=a,this.y=b,this.width=c,this.height=d}return a.prototype.toGlobal=function(b){var c=b.getRenderWidth(),d=b.getRenderHeight();return new a(this.x*c,this.y*d,this.width*c,this.height*d)},a}();a.Viewport=i;var j=function(){function a(){}return a.GetPlanes=function(b){for(var c=[],d=0;6>d;d++)c.push(new h(0,0,0,0));return a.GetPlanesToRef(b,c),c},a.GetPlanesToRef=function(a,b){b[0].normal.x=a.m[3]+a.m[2],b[0].normal.y=a.m[7]+a.m[6],b[0].normal.z=a.m[10]+a.m[10],b[0].d=a.m[15]+a.m[14],b[0].normalize(),b[1].normal.x=a.m[3]-a.m[2],b[1].normal.y=a.m[7]-a.m[6],b[1].normal.z=a.m[11]-a.m[10],b[1].d=a.m[15]-a.m[14],b[1].normalize(),b[2].normal.x=a.m[3]+a.m[0],b[2].normal.y=a.m[7]+a.m[4],b[2].normal.z=a.m[11]+a.m[8],b[2].d=a.m[15]+a.m[12],b[2].normalize(),b[3].normal.x=a.m[3]-a.m[0],b[3].normal.y=a.m[7]-a.m[4],b[3].normal.z=a.m[11]-a.m[8],b[3].d=a.m[15]-a.m[12],b[3].normalize(),b[4].normal.x=a.m[3]-a.m[1],b[4].normal.y=a.m[7]-a.m[5],b[4].normal.z=a.m[11]-a.m[9],b[4].d=a.m[15]-a.m[13],b[4].normalize(),b[5].normal.x=a.m[3]+a.m[1],b[5].normal.y=a.m[7]+a.m[5],b[5].normal.z=a.m[11]+a.m[9],b[5].d=a.m[15]+a.m[13],b[5].normalize()},a}();a.Frustum=j;var k=function(){function b(a,b){this.origin=a,this.direction=b}return b.prototype.intersectsBoxMinMax=function(a,b){var c=0,d=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.xb.x)return!1}else{var e=1/this.direction.x,f=(a.x-this.origin.x)*e,g=(b.x-this.origin.x)*e;if(f>g){var h=f;f=g,g=h}if(c=Math.max(f,c),d=Math.min(g,d),c>d)return!1}if(Math.abs(this.direction.y)<1e-7){if(this.origin.yb.y)return!1}else if(e=1/this.direction.y,f=(a.y-this.origin.y)*e,g=(b.y-this.origin.y)*e,f>g&&(h=f,f=g,g=h),c=Math.max(f,c),d=Math.min(g,d),c>d)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.zb.z)return!1}else if(e=1/this.direction.z,f=(a.z-this.origin.z)*e,g=(b.z-this.origin.z)*e,f>g&&(h=f,f=g,g=h),c=Math.max(f,c),d=Math.min(g,d),c>d)return!1;return!0},b.prototype.intersectsBox=function(a){return this.intersectsBoxMinMax(a.minimum,a.maximum)},b.prototype.intersectsSphere=function(a){var b=a.center.x-this.origin.x,c=a.center.y-this.origin.y,d=a.center.z-this.origin.z,e=b*b+c*c+d*d,f=a.radius*a.radius;if(f>=e)return!0;var g=b*this.direction.x+c*this.direction.y+d*this.direction.z;if(0>g)return!1;var h=e-g*g;return f>=h},b.prototype.intersectsTriangle=function(b,c,d){this._edge1||(this._edge1=a.Vector3.Zero(),this._edge2=a.Vector3.Zero(),this._pvec=a.Vector3.Zero(),this._tvec=a.Vector3.Zero(),this._qvec=a.Vector3.Zero()),c.subtractToRef(b,this._edge1),d.subtractToRef(b,this._edge2),a.Vector3.CrossToRef(this.direction,this._edge2,this._pvec);var f=e.Dot(this._edge1,this._pvec);if(0===f)return null;var g=1/f;this.origin.subtractToRef(b,this._tvec);var h=e.Dot(this._tvec,this._pvec)*g;if(0>h||h>1)return null;e.CrossToRef(this._tvec,this._edge1,this._qvec);var i=e.Dot(this.direction,this._qvec)*g;return 0>i||h+i>1?null:new a.IntersectionInfo(h,i,e.Dot(this._edge2,this._qvec)*g)},b.CreateNew=function(c,d,e,f,g,h,i){var j=a.Vector3.Unproject(new a.Vector3(c,d,0),e,f,g,h,i),k=a.Vector3.Unproject(new a.Vector3(c,d,1),e,f,g,h,i),l=k.subtract(j);return l.normalize(),new b(j,l)},b.Transform=function(c,d){var e=a.Vector3.TransformCoordinates(c.origin,d),f=a.Vector3.TransformNormal(c.direction,d);return new b(e,f)},b}();a.Ray=k,function(a){a[a.LOCAL=0]="LOCAL",a[a.WORLD=1]="WORLD"}(a.Space||(a.Space={}));var l=(a.Space,function(){function b(){}return b.X=new a.Vector3(1,0,0),b.Y=new a.Vector3(0,1,0),b.Z=new a.Vector3(0,0,1),b}());a.Axis=l}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b,c=60,d=[],e=60,f=0,g=function(b,c){return b?b instanceof a.Mesh?null:b instanceof a.SubMesh?b.clone(c):b.clone?b.clone():null:null},h=function(){function h(){}return h.GetFilename=function(a){var b=a.lastIndexOf("/");return 0>b?a:a.substring(b+1)},h.GetDOMTextContent=function(a){for(var b="",c=a.firstChild;c;)3==c.nodeType&&(b+=c.textContent),c=c.nextSibling;return b},h.ToDegrees=function(a){return 180*a/Math.PI},h.ToRadians=function(a){return a*Math.PI/180},h.ExtractMinAndMaxIndexed=function(b,c,d,e){for(var f=new a.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),g=new a.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),h=d;d+e>h;h++){var i=new a.Vector3(b[3*c[h]],b[3*c[h]+1],b[3*c[h]+2]);f=a.Vector3.Minimize(i,f),g=a.Vector3.Maximize(i,g)}return{minimum:f,maximum:g}},h.ExtractMinAndMax=function(b,c,d){for(var e=new a.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),f=new a.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),g=c;c+d>g;g++){var h=new a.Vector3(b[3*g],b[3*g+1],b[3*g+2]);e=a.Vector3.Minimize(h,e),f=a.Vector3.Maximize(h,f)}return{minimum:e,maximum:f}},h.MakeArray=function(a,b){return b===!0||void 0!==a&&null!=a?Array.isArray(a)?a:[a]:void 0},h.GetPointerPrefix=function(){var a="pointer";return navigator.pointerEnabled||(a="mouse"),a},h.QueueNewFrame=function(a){window.requestAnimationFrame?window.requestAnimationFrame(a):window.msRequestAnimationFrame?window.msRequestAnimationFrame(a):window.webkitRequestAnimationFrame?window.webkitRequestAnimationFrame(a):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(a):window.oRequestAnimationFrame?window.oRequestAnimationFrame(a):window.setTimeout(a,16)},h.RequestFullscreen=function(a){a.requestFullscreen?a.requestFullscreen():a.msRequestFullscreen?a.msRequestFullscreen():a.webkitRequestFullscreen?a.webkitRequestFullscreen():a.mozRequestFullScreen&&a.mozRequestFullScreen()},h.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},h.CleanUrl=function(a){return a=a.replace(/#/gm,"%23")},h.LoadImage=function(b,c,d,e){b=h.CleanUrl(b);var f=new Image;f.crossOrigin="anonymous",f.onload=function(){c(f)},f.onerror=function(a){d(f,a)};var g=function(){f.src=b},i=function(){e.loadImageFromDB(b,f)};if(e&&e.enableTexturesOffline&&a.Database.isUASupportingBlobStorage)e.openAsync(i,g);else if(-1===b.indexOf("file:"))g();else try{var j,k=b.substring(5);try{j=URL.createObjectURL(a.FilesInput.FilesTextures[k],{oneTimeOnly:!0})}catch(l){j=URL.createObjectURL(a.FilesInput.FilesTextures[k])}f.src=j}catch(m){h.Log("Error while trying to load texture: "+k),f.src=null}return f},h.LoadFile=function(b,c,d,e,f){b=h.CleanUrl(b); var g=function(){var e=new XMLHttpRequest,g=h.BaseUrl+b;e.open("GET",g,!0),f&&(e.responseType="arraybuffer"),e.onprogress=d,e.onreadystatechange=function(){if(4==e.readyState){if(200!=e.status&&!a.Tools.ValidateXHRData(e,f?6:1))throw new Error("Error status: "+e.status+" - Unable to load "+g);c(f?e.response:e.responseText)}},e.send(null)},i=function(){e.loadFileFromDB(b,c,d,g,f)};if(-1!==b.indexOf("file:")){var j=b.substring(5);a.Tools.ReadFile(a.FilesInput.FilesToLoad[j],c,d,!0)}else e&&e.enableSceneOffline?e.openAsync(i,g):g()},h.ReadFile=function(a,b,c,d){var e=new FileReader;e.onload=function(a){b(a.target.result)},e.onprogress=c,d?e.readAsArrayBuffer(a):e.readAsText(a)},h.CheckExtends=function(a,b,c){a.xc.x&&(c.x=a.x),a.y>c.y&&(c.y=a.y),a.z>c.z&&(c.z=a.z)},h.WithinEpsilon=function(a,b){var c=a-b;return c>=-1.401298e-45&&1.401298e-45>=c},h.DeepCopy=function(a,b,c,d){for(var e in a)if(("_"!==e[0]||d&&-1!==d.indexOf(e))&&(!c||-1===c.indexOf(e))){var f=a[e],h=typeof f;if("function"!=h)if("object"==h)if(f instanceof Array){if(b[e]=[],f.length>0)if("object"==typeof f[0])for(var i=0;i=2&&(f=d[a-1]-d[a-2]),a>=c){a>c&&(d.splice(0,1),a=d.length);for(var b=0,g=0;a-1>g;g++)b+=d[g+1]-d[g];e=1e3/(b/(a-1))}},h.CreateScreenshot=function(c,d,e){var f,g,i=d.getScene(),j=null;if(i.activeCamera!==d&&(j=i.activeCamera,i.activeCamera=d),e.precision)f=Math.round(c.getRenderWidth()*e.precision),g=Math.round(f/c.getAspectRatio(d)),e={width:f,height:g};else if(e.width&&e.height)f=e.width,g=e.height;else if(e.width&&!e.height)f=e.width,g=Math.round(f/c.getAspectRatio(d)),e={width:f,height:g};else if(e.height&&!e.width)g=e.height,f=Math.round(g*c.getAspectRatio(d)),e={width:f,height:g};else{if(isNaN(e))return void h.Error("Invalid 'size' parameter !");g=e,f=e}var k=new a.RenderTargetTexture("screenShot",e,c.scenes[0],!1,!1);k.renderList=c.scenes[0].meshes,k.onAfterRender=function(){for(var a=4*f,d=g/2,e=c.readPixels(0,0,f,g),h=0;d>h;h++)for(var i=0;a>i;i++){var j=i+h*a,k=g-h-1,l=i+k*a,m=e[j];e[j]=e[l],e[l]=m}b||(b=document.createElement("canvas")),b.width=f,b.height=g;var n=b.getContext("2d"),o=n.createImageData(f,g);o.data.set(e),n.putImageData(o,0,0);var p=b.toDataURL();if("download"in document.createElement("a")){var q=window.document.createElement("a");q.href=p;var r=new Date,s=r.getFullYear()+"/"+r.getMonth()+"/"+r.getDate()+"-"+r.getHours()+":"+r.getMinutes();q.setAttribute("download","screenshot-"+s+".png"),window.document.body.appendChild(q),q.addEventListener("click",function(){q.parentElement.removeChild(q)}),q.click()}else{var t=window.open(""),u=t.document.createElement("img");u.src=p,t.document.body.appendChild(u)}},k.render(!0),k.dispose(),j&&(i.activeCamera=j)},h.ValidateXHRData=function(b,c){"undefined"==typeof c&&(c=7);try{if(1&c){if(b.responseText&&b.responseText.length>0)return!0;if(1===c)return!1}if(2&c){var d=a.Internals.TGATools.GetTGAHeader(b.response);if(d.width&&d.height&&d.width>0&&d.height>0)return!0;if(2===c)return!1}if(4&c){var e=new Uint8Array(b.response,0,3);return 68==e[0]&&68==e[1]&&83==e[2]?!0:!1}}catch(f){}return!1},Object.defineProperty(h,"NoneLogLevel",{get:function(){return h._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(h,"MessageLogLevel",{get:function(){return h._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(h,"WarningLogLevel",{get:function(){return h._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(h,"ErrorLogLevel",{get:function(){return h._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(h,"AllLogLevel",{get:function(){return h._MessageLogLevel|h._WarningLogLevel|h._ErrorLogLevel},enumerable:!0,configurable:!0}),h._FormatMessage=function(a){var b=function(a){return 10>a?"0"+a:""+a},c=new Date;return"BJS - ["+b(c.getHours())+":"+b(c.getMinutes())+":"+b(c.getSeconds())+"]: "+a},h._LogDisabled=function(){},h._LogEnabled=function(a){console.log(h._FormatMessage(a))},h._WarnDisabled=function(){},h._WarnEnabled=function(a){console.warn(h._FormatMessage(a))},h._ErrorDisabled=function(){},h._ErrorEnabled=function(a){console.error(h._FormatMessage(a))},Object.defineProperty(h,"LogLevels",{set:function(a){h.Log=(a&h.MessageLogLevel)===h.MessageLogLevel?h._LogEnabled:h._LogDisabled,h.Warn=(a&h.WarningLogLevel)===h.WarningLogLevel?h._WarnEnabled:h._WarnDisabled,h.Error=(a&h.ErrorLogLevel)===h.ErrorLogLevel?h._ErrorEnabled:h._ErrorDisabled},enumerable:!0,configurable:!0}),h.BaseUrl="",h._NoneLogLevel=0,h._MessageLogLevel=1,h._WarningLogLevel=2,h._ErrorLogLevel=4,h.Log=h._LogEnabled,h.Warn=h._WarnEnabled,h.Error=h._ErrorEnabled,h}();a.Tools=h}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(a,b,c,d){var e=a.createShader("vertex"===c?a.VERTEX_SHADER:a.FRAGMENT_SHADER);if(a.shaderSource(e,(d?d+"\n":"")+b),a.compileShader(e),!a.getShaderParameter(e,a.COMPILE_STATUS))throw new Error(a.getShaderInfoLog(e));return e},c=function(b,c,d){var e=d.NEAREST,f=d.NEAREST;return b===a.Texture.BILINEAR_SAMPLINGMODE?(e=d.LINEAR,f=c?d.LINEAR_MIPMAP_NEAREST:d.LINEAR):b===a.Texture.TRILINEAR_SAMPLINGMODE?(e=d.LINEAR,f=c?d.LINEAR_MIPMAP_LINEAR:d.LINEAR):b===a.Texture.NEAREST_SAMPLINGMODE&&(e=d.NEAREST,f=c?d.NEAREST_MIPMAP_LINEAR:d.NEAREST),{min:f,mag:e}},d=function(a,b){var c=1;do c*=2;while(a>c);return c>b&&(c=b),c},e=function(b,e,f,g,h,i,j,k,l,m){"undefined"==typeof m&&(m=a.Texture.TRILINEAR_SAMPLINGMODE);var n=f.getEngine(),o=d(g,n.getCaps().maxTextureSize),p=d(h,n.getCaps().maxTextureSize);e.bindTexture(e.TEXTURE_2D,b),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,void 0===i?1:i?1:0),l(o,p);var q=c(m,!j,e);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,q.mag),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,q.min),j||k||e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null),n._activeTexturesCache=[],b._baseWidth=g,b._baseHeight=h,b._width=o,b._height=p,b.isReady=!0,f._removePendingData(b)},f=function(b,c,d,e,g,h){var i,j=function(){d.push(i),e._removePendingData(i),c!=h.length-1?f(b,c+1,d,e,g,h):g(d)},k=function(){e._removePendingData(i)};i=a.Tools.LoadImage(b+h[c],j,k,e.database),e._addPendingData(i)},g=function(){function a(){}return a}();a.EngineCapabilities=g;var h=function(){function h(a,b,c){var d=this;this.isFullscreen=!1,this.isPointerLock=!1,this.forceWireframe=!1,this.cullBackFaces=!0,this.renderEvenInBackground=!0,this.scenes=new Array,this._windowIsBackground=!1,this._runningLoop=!1,this._loadedTexturesCache=new Array,this._activeTexturesCache=new Array,this._compiledEffects={},this._depthMask=!1,this._renderingCanvas=a,this._canvasClientRect=this._renderingCanvas.getBoundingClientRect(),c=c||{},c.antialias=b;try{this._gl=a.getContext("webgl",c)||a.getContext("experimental-webgl",c)}catch(e){throw new Error("WebGL not supported")}if(!this._gl)throw new Error("WebGL not supported");this._onBlur=function(){d._windowIsBackground=!0},this._onFocus=function(){d._windowIsBackground=!1},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus),this._workingCanvas=document.createElement("canvas"),this._workingContext=this._workingCanvas.getContext("2d"),this._hardwareScalingLevel=1/(window.devicePixelRatio||1),this.resize(),this._caps=new g,this._caps.maxTexturesImageUnits=this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),this._caps.maxTextureSize=this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),this._caps.maxCubemapTextureSize=this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE),this._caps.maxRenderTextureSize=this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE),this._caps.standardDerivatives=null!==this._gl.getExtension("OES_standard_derivatives"),this._caps.s3tc=this._gl.getExtension("WEBGL_compressed_texture_s3tc"),this._caps.textureFloat=null!==this._gl.getExtension("OES_texture_float"),this._caps.textureAnisotropicFilterExtension=this._gl.getExtension("EXT_texture_filter_anisotropic")||this._gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this._gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),this._caps.maxAnisotropy=this._caps.textureAnisotropicFilterExtension?this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0,this._caps.instancedArrays=this._gl.getExtension("ANGLE_instanced_arrays"),this.setDepthBuffer(!0),this.setDepthFunctionToLessOrEqual(),this.setDepthWrite(!0),this._onFullscreenChange=function(){void 0!==document.fullscreen?d.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?d.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?d.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(d.isFullscreen=document.msIsFullScreen),d.isFullscreen&&d._pointerLockRequested&&(a.requestPointerLock=a.requestPointerLock||a.msRequestPointerLock||a.mozRequestPointerLock||a.webkitRequestPointerLock,a.requestPointerLock&&a.requestPointerLock())},document.addEventListener("fullscreenchange",this._onFullscreenChange,!1),document.addEventListener("mozfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("webkitfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("msfullscreenchange",this._onFullscreenChange,!1),this._onPointerLockChange=function(){d.isPointerLock=document.mozPointerLockElement===a||document.webkitPointerLockElement===a||document.msPointerLockElement===a||document.pointerLockElement===a},document.addEventListener("pointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mspointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this._onPointerLockChange,!1),document.addEventListener("webkitpointerlockchange",this._onPointerLockChange,!1)}return Object.defineProperty(h,"ALPHA_DISABLE",{get:function(){return h._ALPHA_DISABLE},enumerable:!0,configurable:!0}),Object.defineProperty(h,"ALPHA_ADD",{get:function(){return h._ALPHA_ADD},enumerable:!0,configurable:!0}),Object.defineProperty(h,"ALPHA_COMBINE",{get:function(){return h._ALPHA_COMBINE},enumerable:!0,configurable:!0}),Object.defineProperty(h,"DELAYLOADSTATE_NONE",{get:function(){return h._DELAYLOADSTATE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(h,"DELAYLOADSTATE_LOADED",{get:function(){return h._DELAYLOADSTATE_LOADED},enumerable:!0,configurable:!0}),Object.defineProperty(h,"DELAYLOADSTATE_LOADING",{get:function(){return h._DELAYLOADSTATE_LOADING},enumerable:!0,configurable:!0}),Object.defineProperty(h,"DELAYLOADSTATE_NOTLOADED",{get:function(){return h._DELAYLOADSTATE_NOTLOADED},enumerable:!0,configurable:!0}),Object.defineProperty(h,"Version",{get:function(){return"1.13.0"},enumerable:!0,configurable:!0}),h.prototype.getAspectRatio=function(a){var b=a.viewport;return this.getRenderWidth()*b.width/(this.getRenderHeight()*b.height)},h.prototype.getRenderWidth=function(){return this._currentRenderTarget?this._currentRenderTarget._width:this._renderingCanvas.width},h.prototype.getRenderHeight=function(){return this._currentRenderTarget?this._currentRenderTarget._height:this._renderingCanvas.height},h.prototype.getRenderingCanvas=function(){return this._renderingCanvas},h.prototype.getRenderingCanvasClientRect=function(){return this._renderingCanvas.getBoundingClientRect()},h.prototype.setHardwareScalingLevel=function(a){this._hardwareScalingLevel=a,this.resize()},h.prototype.getHardwareScalingLevel=function(){return this._hardwareScalingLevel},h.prototype.getLoadedTexturesCache=function(){return this._loadedTexturesCache},h.prototype.getCaps=function(){return this._caps},h.prototype.setDepthFunctionToGreater=function(){this._gl.depthFunc(this._gl.GREATER)},h.prototype.setDepthFunctionToGreaterOrEqual=function(){this._gl.depthFunc(this._gl.GEQUAL)},h.prototype.setDepthFunctionToLess=function(){this._gl.depthFunc(this._gl.LESS)},h.prototype.setDepthFunctionToLessOrEqual=function(){this._gl.depthFunc(this._gl.LEQUAL)},h.prototype.stopRenderLoop=function(){this._renderFunction=null,this._runningLoop=!1},h.prototype._renderLoop=function(){var b=this,c=!0;!this.renderEvenInBackground&&this._windowIsBackground&&(c=!1),c&&(this.beginFrame(),this._renderFunction&&this._renderFunction(),this.endFrame()),this._runningLoop&&a.Tools.QueueNewFrame(function(){b._renderLoop()})},h.prototype.runRenderLoop=function(b){var c=this;this._runningLoop=!0,this._renderFunction=b,a.Tools.QueueNewFrame(function(){c._renderLoop()})},h.prototype.switchFullscreen=function(b){this.isFullscreen?a.Tools.ExitFullscreen():(this._pointerLockRequested=b,a.Tools.RequestFullscreen(this._renderingCanvas))},h.prototype.clear=function(a,b,c){this._gl.clearColor(a.r,a.g,a.b,void 0!==a.a?a.a:1),this._depthMask&&this._gl.clearDepth(1);var d=0;b&&(d|=this._gl.COLOR_BUFFER_BIT),c&&this._depthMask&&(d|=this._gl.DEPTH_BUFFER_BIT),this._gl.clear(d)},h.prototype.setViewport=function(a,b,c){var d=b||this._renderingCanvas.width,e=c||this._renderingCanvas.height,f=a.x||0,g=a.y||0;this._cachedViewport=a,this._gl.viewport(f*d,g*e,d*a.width,e*a.height)},h.prototype.setDirectViewport=function(a,b,c,d){this._cachedViewport=null,this._gl.viewport(a,b,c,d)},h.prototype.beginFrame=function(){a.Tools._MeasureFps()},h.prototype.endFrame=function(){this.flushFramebuffer()},h.prototype.resize=function(){this._renderingCanvas.width=this._renderingCanvas.clientWidth/this._hardwareScalingLevel,this._renderingCanvas.height=this._renderingCanvas.clientHeight/this._hardwareScalingLevel,this._canvasClientRect=this._renderingCanvas.getBoundingClientRect()},h.prototype.bindFramebuffer=function(a){this._currentRenderTarget=a;var b=this._gl;b.bindFramebuffer(b.FRAMEBUFFER,a._framebuffer),this._gl.viewport(0,0,a._width,a._height),this.wipeCaches()},h.prototype.unBindFramebuffer=function(a){if(this._currentRenderTarget=null,a.generateMipMaps){var b=this._gl;b.bindTexture(b.TEXTURE_2D,a),b.generateMipmap(b.TEXTURE_2D),b.bindTexture(b.TEXTURE_2D,null)}this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null)},h.prototype.flushFramebuffer=function(){this._gl.flush()},h.prototype.restoreDefaultFramebuffer=function(){this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null),this.setViewport(this._cachedViewport),this.wipeCaches()},h.prototype._resetVertexBufferBinding=function(){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,null),this._cachedVertexBuffers=null},h.prototype.createVertexBuffer=function(a){var b=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ARRAY_BUFFER,b),this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array(a),this._gl.STATIC_DRAW),this._resetVertexBufferBinding(),b.references=1,b},h.prototype.createDynamicVertexBuffer=function(a){var b=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ARRAY_BUFFER,b),this._gl.bufferData(this._gl.ARRAY_BUFFER,a,this._gl.DYNAMIC_DRAW),this._resetVertexBufferBinding(),b.references=1,b},h.prototype.updateDynamicVertexBuffer=function(a,b){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,a),b instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,b):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,new Float32Array(b)),this._resetVertexBufferBinding()},h.prototype._resetIndexBufferBinding=function(){this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,null),this._cachedIndexBuffer=null},h.prototype.createIndexBuffer=function(a){var b=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,b),this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(a),this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),b.references=1,b},h.prototype.bindBuffers=function(a,b,c,d,e){if(this._cachedVertexBuffers!==a||this._cachedEffectForVertexBuffers!==e){this._cachedVertexBuffers=a,this._cachedEffectForVertexBuffers=e,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,a);for(var f=0,g=0;g=0&&this._gl.vertexAttribPointer(h,c[g],this._gl.FLOAT,!1,d,f),f+=4*c[g]}}this._cachedIndexBuffer!==b&&(this._cachedIndexBuffer=b,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,b))},h.prototype.bindMultiBuffers=function(a,b,c){if(this._cachedVertexBuffers!==a||this._cachedEffectForVertexBuffers!==c){this._cachedVertexBuffers=a,this._cachedEffectForVertexBuffers=c;for(var d=c.getAttributesNames(),e=0;e=0){var g=a[d[e]];if(!g)continue;var h=g.getStrideSize();this._gl.bindBuffer(this._gl.ARRAY_BUFFER,g.getBuffer()),this._gl.vertexAttribPointer(f,h,this._gl.FLOAT,!1,4*h,0)}}}this._cachedIndexBuffer!==b&&(this._cachedIndexBuffer=b,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,b))},h.prototype._releaseBuffer=function(a){return a.references--,0===a.references?(this._gl.deleteBuffer(a),!0):!1},h.prototype.createInstancesBuffer=function(a){var b=this._gl.createBuffer();return b.capacity=a,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,b),this._gl.bufferData(this._gl.ARRAY_BUFFER,a,this._gl.DYNAMIC_DRAW),b},h.prototype.deleteInstancesBuffer=function(a){this._gl.deleteBuffer(a)},h.prototype.updateAndBindInstancesBuffer=function(a,b,c){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,a),this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,b);for(var d=0;4>d;d++){var e=c[d];this._gl.enableVertexAttribArray(e),this._gl.vertexAttribPointer(e,4,this._gl.FLOAT,!1,64,16*d),this._caps.instancedArrays.vertexAttribDivisorANGLE(e,1)}},h.prototype.unBindInstancesBuffer=function(a,b){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,a);for(var c=0;4>c;c++){var d=b[c];this._gl.disableVertexAttribArray(d),this._caps.instancedArrays.vertexAttribDivisorANGLE(d,0)}},h.prototype.draw=function(a,b,c,d){return d?void this._caps.instancedArrays.drawElementsInstancedANGLE(a?this._gl.TRIANGLES:this._gl.LINES,c,this._gl.UNSIGNED_SHORT,2*b,d):void this._gl.drawElements(a?this._gl.TRIANGLES:this._gl.LINES,c,this._gl.UNSIGNED_SHORT,2*b)},h.prototype._releaseEffect=function(a){this._compiledEffects[a._key]&&(delete this._compiledEffects[a._key],a.getProgram()&&this._gl.deleteProgram(a.getProgram()))},h.prototype.createEffect=function(b,c,d,e,f,g,h,i){var j=b.vertexElement||b.vertex||b,k=b.fragmentElement||b.fragment||b,l=j+"+"+k+"@"+f;if(this._compiledEffects[l])return this._compiledEffects[l];var m=new a.Effect(b,c,d,e,this,f,g,h,i);return m._key=l,this._compiledEffects[l]=m,m},h.prototype.createShaderProgram=function(a,c,d){var e=b(this._gl,a,"vertex",d),f=b(this._gl,c,"fragment",d),g=this._gl.createProgram();this._gl.attachShader(g,e),this._gl.attachShader(g,f),this._gl.linkProgram(g);var h=this._gl.getProgramParameter(g,this._gl.LINK_STATUS);if(!h){var i=this._gl.getProgramInfoLog(g);if(i)throw new Error(i)}return this._gl.deleteShader(e),this._gl.deleteShader(f),g},h.prototype.getUniforms=function(a,b){for(var c=[],d=0;dthis._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[b]||(this._vertexAttribArrays[b]=!1,this._gl.disableVertexAttribArray(b));for(var c=a.getAttributesCount(),d=0;c>d;d++){var e=a.getAttributeLocation(d);e>=0&&(this._vertexAttribArrays[e]=!0,this._gl.enableVertexAttribArray(e))}this._currentEffect=a}},h.prototype.setArray=function(a,b){a&&this._gl.uniform1fv(a,b)},h.prototype.setMatrices=function(a,b){a&&this._gl.uniformMatrix4fv(a,!1,b)},h.prototype.setMatrix=function(a,b){a&&this._gl.uniformMatrix4fv(a,!1,b.toArray())},h.prototype.setFloat=function(a,b){a&&this._gl.uniform1f(a,b)},h.prototype.setFloat2=function(a,b,c){a&&this._gl.uniform2f(a,b,c)},h.prototype.setFloat3=function(a,b,c,d){a&&this._gl.uniform3f(a,b,c,d)},h.prototype.setBool=function(a,b){a&&this._gl.uniform1i(a,b)},h.prototype.setFloat4=function(a,b,c,d,e){a&&this._gl.uniform4f(a,b,c,d,e)},h.prototype.setColor3=function(a,b){a&&this._gl.uniform3f(a,b.r,b.g,b.b)},h.prototype.setColor4=function(a,b,c){a&&this._gl.uniform4f(a,b.r,b.g,b.b,c)},h.prototype.setState=function(a){this._cullingState!==a&&(a?(this._gl.cullFace(this.cullBackFaces?this._gl.BACK:this._gl.FRONT),this._gl.enable(this._gl.CULL_FACE)):this._gl.disable(this._gl.CULL_FACE),this._cullingState=a)},h.prototype.setDepthBuffer=function(a){a?this._gl.enable(this._gl.DEPTH_TEST):this._gl.disable(this._gl.DEPTH_TEST)},h.prototype.setDepthWrite=function(a){this._gl.depthMask(a),this._depthMask=a},h.prototype.setColorWrite=function(a){this._gl.colorMask(a,a,a,a)},h.prototype.setAlphaMode=function(b){switch(b){case a.Engine.ALPHA_DISABLE:this.setDepthWrite(!0),this._gl.disable(this._gl.BLEND);break;case a.Engine.ALPHA_COMBINE:this.setDepthWrite(!1),this._gl.blendFuncSeparate(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE),this._gl.enable(this._gl.BLEND);break;case a.Engine.ALPHA_ADD:this.setDepthWrite(!1),this._gl.blendFuncSeparate(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._gl.enable(this._gl.BLEND)}},h.prototype.setAlphaTesting=function(a){this._alphaTest=a},h.prototype.getAlphaTesting=function(){return this._alphaTest},h.prototype.wipeCaches=function(){this._activeTexturesCache=[],this._currentEffect=null,this._cullingState=null,this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null},h.prototype.setSamplingMode=function(b,c){var d=this._gl;d.bindTexture(d.TEXTURE_2D,b);var e=d.NEAREST,f=d.NEAREST;c===a.Texture.BILINEAR_SAMPLINGMODE?(e=d.LINEAR,f=d.LINEAR):c===a.Texture.TRILINEAR_SAMPLINGMODE&&(e=d.LINEAR,f=d.LINEAR_MIPMAP_LINEAR),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MAG_FILTER,e),d.texParameteri(d.TEXTURE_2D,d.TEXTURE_MIN_FILTER,f),d.bindTexture(d.TEXTURE_2D,null)},h.prototype.createTexture=function(b,c,d,f,g){var h=this;"undefined"==typeof g&&(g=a.Texture.TRILINEAR_SAMPLINGMODE);var i=this._gl.createTexture(),j=b.substr(b.length-4,4).toLowerCase(),k=this.getCaps().s3tc&&".dds"===j,l=".tga"===j;if(f._addPendingData(i),i.url=b,i.noMipmap=c,i.references=1,this._loadedTexturesCache.push(i),l)a.Tools.LoadFile(b,function(b){var j=new Uint8Array(b),k=a.Internals.TGATools.GetTGAHeader(j);e(i,h._gl,f,k.width,k.height,d,c,!1,function(){a.Internals.TGATools.UploadContent(h._gl,j)},g)},null,f.database,!0);else if(k)a.Tools.LoadFile(b,function(j){var k=a.Internals.DDSTools.GetDDSInfo(j),l=(k.isRGB||k.isLuminance||k.mipmapCount>1)&&!c&&k.width>>k.mipmapCount-1==1;e(i,h._gl,f,k.width,k.height,d,!l,k.isFourCC,function(){console.log("loading "+b),a.Internals.DDSTools.UploadDDSLevels(h._gl,h.getCaps().s3tc,j,k,l,1)},g)},null,f.database,!0);else{var m=function(a){e(i,h._gl,f,a.width,a.height,d,c,!1,function(b,c){var d=a.width==b&&a.height==c;d||(h._workingCanvas.width=b,h._workingCanvas.height=c,h._workingContext.drawImage(a,0,0,a.width,a.height,0,0,b,c)),h._gl.texImage2D(h._gl.TEXTURE_2D,0,h._gl.RGBA,h._gl.RGBA,h._gl.UNSIGNED_BYTE,d?a:h._workingCanvas)},g)},n=function(){f._removePendingData(i)};a.Tools.LoadImage(b,m,n,f.database)}return i},h.prototype.createDynamicTexture=function(a,b,e,f){var g=this._gl.createTexture();a=d(a,this._caps.maxTextureSize),b=d(b,this._caps.maxTextureSize),this._gl.bindTexture(this._gl.TEXTURE_2D,g);var h=c(f,e,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,h.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,h.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],g._baseWidth=a,g._baseHeight=b,g._width=a,g._height=b,g.isReady=!1,g.generateMipMaps=e,g.references=1,this._loadedTexturesCache.push(g),g},h.prototype.updateDynamicTexture=function(a,b,c){this._gl.bindTexture(this._gl.TEXTURE_2D,a),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,c?1:0),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,b),a.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],a.isReady=!0},h.prototype.updateVideoTexture=function(a,b,c){this._gl.bindTexture(this._gl.TEXTURE_2D,a),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,c?0:1),b.videoWidth!==a._width||b.videoHeight!==a._height?(a._workingCanvas||(a._workingCanvas=document.createElement("canvas"),a._workingContext=a._workingCanvas.getContext("2d"),a._workingCanvas.width=a._width,a._workingCanvas.height=a._height),a._workingContext.drawImage(b,0,0,b.videoWidth,b.videoHeight,0,0,a._width,a._height),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,a._workingCanvas)):this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,b),a.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],a.isReady=!0},h.prototype.createRenderTargetTexture=function(b,d){var e=!1,f=!0,g=a.Texture.TRILINEAR_SAMPLINGMODE;void 0!==d&&(e=void 0===d.generateMipMaps?d:d.generateMipmaps,f=void 0===d.generateDepthBuffer?!0:d.generateDepthBuffer,void 0!==d.samplingMode&&(g=d.samplingMode));var h=this._gl,i=h.createTexture();h.bindTexture(h.TEXTURE_2D,i);var j=b.width||b,k=b.height||b,l=c(g,e,h);h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,l.mag),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,l.min),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE),h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE),h.texImage2D(h.TEXTURE_2D,0,h.RGBA,j,k,0,h.RGBA,h.UNSIGNED_BYTE,null);var m;f&&(m=h.createRenderbuffer(),h.bindRenderbuffer(h.RENDERBUFFER,m),h.renderbufferStorage(h.RENDERBUFFER,h.DEPTH_COMPONENT16,j,k));var n=h.createFramebuffer();return h.bindFramebuffer(h.FRAMEBUFFER,n),h.framebufferTexture2D(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0,h.TEXTURE_2D,i,0),f&&h.framebufferRenderbuffer(h.FRAMEBUFFER,h.DEPTH_ATTACHMENT,h.RENDERBUFFER,m),h.bindTexture(h.TEXTURE_2D,null),h.bindRenderbuffer(h.RENDERBUFFER,null),h.bindFramebuffer(h.FRAMEBUFFER,null),i._framebuffer=n,f&&(i._depthBuffer=m),i._width=j,i._height=k,i.isReady=!0,i.generateMipMaps=e,i.references=1,this._activeTexturesCache=[],this._loadedTexturesCache.push(i),i},h.prototype.createCubeTexture=function(b,c,e,g){var h=this,i=this._gl,j=i.createTexture();j.isCube=!0,j.url=b,j.references=1,this._loadedTexturesCache.push(j);var k=b.substr(b.length-4,4).toLowerCase(),l=this.getCaps().s3tc&&".dds"===k;return l?a.Tools.LoadFile(b,function(b){var c=a.Internals.DDSTools.GetDDSInfo(b),d=(c.isRGB||c.isLuminance||c.mipmapCount>1)&&!g;i.bindTexture(i.TEXTURE_CUBE_MAP,j),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),a.Internals.DDSTools.UploadDDSLevels(h._gl,h.getCaps().s3tc,b,c,d,6),g||c.isFourCC||1!=c.mipmapCount||i.generateMipmap(i.TEXTURE_CUBE_MAP),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MIN_FILTER,d?i.LINEAR_MIPMAP_LINEAR:i.LINEAR),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.bindTexture(i.TEXTURE_CUBE_MAP,null),h._activeTexturesCache=[],j._width=c.width,j._height=c.height,j.isReady=!0}):f(b,0,[],c,function(a){var b=d(a[0].width,h._caps.maxCubemapTextureSize),c=b;h._workingCanvas.width=b,h._workingCanvas.height=c;var e=[i.TEXTURE_CUBE_MAP_POSITIVE_X,i.TEXTURE_CUBE_MAP_POSITIVE_Y,i.TEXTURE_CUBE_MAP_POSITIVE_Z,i.TEXTURE_CUBE_MAP_NEGATIVE_X,i.TEXTURE_CUBE_MAP_NEGATIVE_Y,i.TEXTURE_CUBE_MAP_NEGATIVE_Z];i.bindTexture(i.TEXTURE_CUBE_MAP,j),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,0);for(var f=0;fb)){if(!c||!c.isReady())return void(null!=this._activeTexturesCache[b]&&(this._gl.activeTexture(this._gl["TEXTURE"+b]),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null),this._activeTexturesCache[b]=null));if(c instanceof a.VideoTexture)c.update()&&(this._activeTexturesCache[b]=null);else if(c.delayLoadState==a.Engine.DELAYLOADSTATE_NOTLOADED)return void c.delayLoad();if(this._activeTexturesCache[b]!=c){this._activeTexturesCache[b]=c;var d=c.getInternalTexture();if(this._gl.activeTexture(this._gl["TEXTURE"+b]),d.isCube){if(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,d),d._cachedCoordinatesMode!==c.coordinatesMode){d._cachedCoordinatesMode=c.coordinatesMode;var e=c.coordinatesMode!==a.Texture.CUBIC_MODE&&c.coordinatesMode!==a.Texture.SKYBOX_MODE?this._gl.REPEAT:this._gl.CLAMP_TO_EDGE;this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_S,e),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_T,e)}this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP,c)}else{if(this._gl.bindTexture(this._gl.TEXTURE_2D,d),d._cachedWrapU!==c.wrapU)switch(d._cachedWrapU=c.wrapU,c.wrapU){case a.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.REPEAT);break;case a.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.CLAMP_TO_EDGE);break;case a.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.MIRRORED_REPEAT)}if(d._cachedWrapV!==c.wrapV)switch(d._cachedWrapV=c.wrapV,c.wrapV){case a.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.REPEAT);break;case a.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.CLAMP_TO_EDGE);break;case a.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.MIRRORED_REPEAT) }this._setAnisotropicLevel(this._gl.TEXTURE_2D,c)}}}},h.prototype._setAnisotropicLevel=function(a,b){var c=this._caps.textureAnisotropicFilterExtension;c&&b._cachedAnisotropicFilteringLevel!==b.anisotropicFilteringLevel&&(this._gl.texParameterf(a,c.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(b.anisotropicFilteringLevel,this._caps.maxAnisotropy)),b._cachedAnisotropicFilteringLevel=b.anisotropicFilteringLevel)},h.prototype.readPixels=function(a,b,c,d){var e=new Uint8Array(d*c*4);return this._gl.readPixels(0,0,c,d,this._gl.RGBA,this._gl.UNSIGNED_BYTE,e),e},h.prototype.dispose=function(){for(this.stopRenderLoop();this.scenes.length;)this.scenes[0].dispose();for(var a in this._compiledEffects)this._gl.deleteProgram(this._compiledEffects[a]._program);for(var b in this._vertexAttribArrays)b>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[b]||this._gl.disableVertexAttribArray(b);window.removeEventListener("blur",this._onBlur),window.removeEventListener("focus",this._onFocus),document.removeEventListener("fullscreenchange",this._onFullscreenChange),document.removeEventListener("mozfullscreenchange",this._onFullscreenChange),document.removeEventListener("webkitfullscreenchange",this._onFullscreenChange),document.removeEventListener("msfullscreenchange",this._onFullscreenChange),document.removeEventListener("pointerlockchange",this._onPointerLockChange),document.removeEventListener("mspointerlockchange",this._onPointerLockChange),document.removeEventListener("mozpointerlockchange",this._onPointerLockChange),document.removeEventListener("webkitpointerlockchange",this._onPointerLockChange)},h.isSupported=function(){try{var a=document.createElement("canvas"),b=a.getContext("webgl")||a.getContext("experimental-webgl");return null!=b&&!!window.WebGLRenderingContext}catch(c){return!1}},h._ALPHA_DISABLE=0,h._ALPHA_ADD=1,h._ALPHA_COMBINE=2,h._DELAYLOADSTATE_NONE=0,h._DELAYLOADSTATE_LOADED=1,h._DELAYLOADSTATE_LOADING=2,h._DELAYLOADSTATE_NOTLOADED=4,h.Epsilon=.001,h.CollisionsEpsilon=.001,h.ShadersRepository="Babylon/Shaders/",h}();a.Engine=h}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(a,b){this.state="",this.animations=new Array,this._childrenFlag=-1,this._isEnabled=!0,this._isReady=!0,this._currentRenderId=-1,this.name=a,this.id=a,this._scene=b,this._initCache()}return b.prototype.getScene=function(){return this._scene},b.prototype.getEngine=function(){return this._scene.getEngine()},b.prototype.getWorldMatrix=function(){return a.Matrix.Identity()},b.prototype._initCache=function(){this._cache={},this._cache.parent=void 0},b.prototype.updateCache=function(a){(a||!this.isSynchronized())&&(this._cache.parent=this.parent,this._updateCache())},b.prototype._updateCache=function(){},b.prototype._isSynchronized=function(){return!0},b.prototype.isSynchronizedWithParent=function(){return this.parent?this.parent._currentRenderId<=this._currentRenderId:!0},b.prototype.isSynchronized=function(a){var b=this.hasNewParent();return b=b||!this.isSynchronizedWithParent(),b=b||!this._isSynchronized(),a&&this.updateCache(!0),!b},b.prototype.hasNewParent=function(a){return this._cache.parent===this.parent?!1:(a&&(this._cache.parent=this.parent),!0)},b.prototype.isReady=function(){return this._isReady},b.prototype.isEnabled=function(){return this._isEnabled?this.parent?this.parent.isEnabled():!0:!1},b.prototype.setEnabled=function(a){this._isEnabled=a},b.prototype.isDescendantOf=function(a){return this.parent?this.parent===a?!0:this.parent.isDescendantOf(a):!1},b.prototype._getDescendants=function(a,b){for(var c=0;cb;b++)if(a[b].dotCoordinate(this.centerWorld)<=-this.radiusWorld)return!1;return!0},b.prototype.intersectsPoint=function(b){var c=this.centerWorld.x-b.x,d=this.centerWorld.y-b.y,e=this.centerWorld.z-b.z,f=Math.sqrt(c*c+d*d+e*e);return Math.abs(this.radiusWorld-f)this.maximumWorld.x&&(this.maximumWorld.x=d.x),d.y>this.maximumWorld.y&&(this.maximumWorld.y=d.y),d.z>this.maximumWorld.z&&(this.maximumWorld.z=d.z)}this.maximumWorld.addToRef(this.minimumWorld,this.center),this.center.scaleInPlace(.5),a.Vector3.FromFloatArrayToRef(b.m,0,this.directions[0]),a.Vector3.FromFloatArrayToRef(b.m,4,this.directions[1]),a.Vector3.FromFloatArrayToRef(b.m,8,this.directions[2]),this._worldMatrix=b},b.prototype.isInFrustum=function(a){return b.IsInFrustum(this.vectorsWorld,a)},b.prototype.intersectsPoint=function(b){var c=a.Engine.Epsilon;return this.maximumWorld.x-b.xb.x-this.minimumWorld.x?!1:this.maximumWorld.y-b.yb.y-this.minimumWorld.y?!1:this.maximumWorld.z-b.zb.z-this.minimumWorld.z?!1:!0},b.prototype.intersectsSphere=function(a){return b.IntersectsSphere(this.minimumWorld,this.maximumWorld,a.centerWorld,a.radiusWorld)},b.prototype.intersectsMinMax=function(a,b){return this.maximumWorld.xb.x?!1:this.maximumWorld.yb.y?!1:this.maximumWorld.zb.z?!1:!0},b.Intersects=function(a,b){return a.maximumWorld.xb.maximumWorld.x?!1:a.maximumWorld.yb.maximumWorld.y?!1:a.maximumWorld.zb.maximumWorld.z?!1:!0},b.IntersectsSphere=function(b,c,d,e){var f=a.Vector3.Clamp(d,b,c),g=a.Vector3.DistanceSquared(d,f);return e*e>=g},b.IsInFrustum=function(a,b){for(var c=0;6>c;c++){for(var d=8,e=0;8>e&&b[c].dotCoordinate(a[e])<0;e++)--d;if(0==d)return!1}return!0},b}();a.BoundingBox=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b,c){var d=a.Vector3.Dot(c.center,b),e=Math.abs(a.Vector3.Dot(c.directions[0],b))*c.extends.x,f=Math.abs(a.Vector3.Dot(c.directions[1],b))*c.extends.y,g=Math.abs(a.Vector3.Dot(c.directions[2],b))*c.extends.z,h=e+f+g;return{min:d-h,max:d+h}},c=function(a,b,c,d){return!(a>d||c>b)},d=function(a,d,e){var f=b(a,d),g=b(a,e);return c(f.min,f.max,g.min,g.max)},e=function(){function b(b,c){this.minimum=b,this.maximum=c,this.boundingBox=new a.BoundingBox(b,c),this.boundingSphere=new a.BoundingSphere(b,c)}return b.prototype._update=function(a){this.boundingBox._update(a),this.boundingSphere._update(a)},b.prototype.isInFrustum=function(a){return this.boundingSphere.isInFrustum(a)?this.boundingBox.isInFrustum(a):!1},b.prototype._checkCollision=function(a){return a._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld)},b.prototype.intersectsPoint=function(a){return this.boundingSphere.centerWorld&&this.boundingSphere.intersectsPoint(a)&&this.boundingBox.intersectsPoint(a)?!0:!1},b.prototype.intersects=function(b,c){if(!this.boundingSphere.centerWorld||!b.boundingSphere.centerWorld)return!1;if(!a.BoundingSphere.Intersects(this.boundingSphere,b.boundingSphere))return!1;if(!a.BoundingBox.Intersects(this.boundingBox,b.boundingBox))return!1;if(!c)return!0;var e=this.boundingBox,f=b.boundingBox;return d(e.directions[0],e,f)&&d(e.directions[1],e,f)&&d(e.directions[2],e,f)&&d(f.directions[0],e,f)&&d(f.directions[1],e,f)&&d(f.directions[2],e,f)&&d(a.Vector3.Cross(e.directions[0],f.directions[0]),e,f)&&d(a.Vector3.Cross(e.directions[0],f.directions[1]),e,f)&&d(a.Vector3.Cross(e.directions[0],f.directions[2]),e,f)&&d(a.Vector3.Cross(e.directions[1],f.directions[0]),e,f)&&d(a.Vector3.Cross(e.directions[1],f.directions[1]),e,f)&&d(a.Vector3.Cross(e.directions[1],f.directions[2]),e,f)&&d(a.Vector3.Cross(e.directions[2],f.directions[0]),e,f)&&d(a.Vector3.Cross(e.directions[2],f.directions[1]),e,f)&&d(a.Vector3.Cross(e.directions[2],f.directions[2]),e,f)?!0:!1},b}();a.BoundingInfo=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(c,d){b.call(this,c,d),this.diffuse=new a.Color3(1,1,1),this.specular=new a.Color3(1,1,1),this.intensity=1,this.range=Number.MAX_VALUE,this.excludedMeshes=new Array,this._excludedMeshesIds=new Array,d.lights.push(this)}return __extends(c,b),c.prototype.getShadowGenerator=function(){return this._shadowGenerator},c.prototype.transferToEffect=function(){},c.prototype._getWorldMatrix=function(){return a.Matrix.Identity()},c.prototype.getWorldMatrix=function(){this._currentRenderId=this.getScene().getRenderId();var b=this._getWorldMatrix();return this.parent&&this.parent.getWorldMatrix?(this._parentedWorldMatrix||(this._parentedWorldMatrix=a.Matrix.Identity()),b.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix),this._parentedWorldMatrix):b},c.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null);var a=this.getScene().lights.indexOf(this);this.getScene().lights.splice(a,1)},c}(a.Node);a.Light=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(a,c,d){b.call(this,a,d),this.position=c}return __extends(c,b),c.prototype.transferToEffect=function(b,c){return this.parent&&this.parent.getWorldMatrix?(this._transformedPosition||(this._transformedPosition=a.Vector3.Zero()),a.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this._transformedPosition),void b.setFloat4(c,this._transformedPosition.x,this._transformedPosition.y,this._transformedPosition.z,0)):void b.setFloat4(c,this.position.x,this.position.y,this.position.z,0)},c.prototype.getShadowGenerator=function(){return null},c.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=a.Matrix.Identity()),a.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},c}(a.Light);a.PointLight=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(a,c,d,e,f,g){b.call(this,a,g),this.position=c,this.direction=d,this.angle=e,this.exponent=f}return __extends(c,b),c.prototype.setDirectionToTarget=function(b){return this.direction=a.Vector3.Normalize(b.subtract(this.position)),this.direction},c.prototype.transferToEffect=function(b,c,d){var e;if(this.parent&&this.parent.getWorldMatrix){this._transformedDirection||(this._transformedDirection=a.Vector3.Zero()),this._transformedPosition||(this._transformedPosition=a.Vector3.Zero());var f=this.parent.getWorldMatrix();a.Vector3.TransformCoordinatesToRef(this.position,f,this._transformedPosition),a.Vector3.TransformNormalToRef(this.direction,f,this._transformedDirection),b.setFloat4(c,this._transformedPosition.x,this._transformedPosition.y,this._transformedPosition.z,this.exponent),e=a.Vector3.Normalize(this._transformedDirection)}else b.setFloat4(c,this.position.x,this.position.y,this.position.z,this.exponent),e=a.Vector3.Normalize(this.direction);b.setFloat4(d,e.x,e.y,e.z,Math.cos(.5*this.angle))},c.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=a.Matrix.Identity()),a.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},c}(a.Light);a.SpotLight=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(a,c,d){b.call(this,a,d),this.direction=c,this.position=c.scale(-1)}return __extends(c,b),c.prototype.setDirectionToTarget=function(b){return this.direction=a.Vector3.Normalize(b.subtract(this.position)),this.direction},c.prototype._computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this._transformedPosition||(this._transformedPosition=a.Vector3.Zero()),a.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this._transformedPosition),!0):!1},c.prototype.transferToEffect=function(b,c){return this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=a.Vector3.Zero()),a.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),void b.setFloat4(c,this._transformedDirection.x,this._transformedDirection.y,this._transformedDirection.z,1)):void b.setFloat4(c,this.direction.x,this.direction.y,this.direction.z,1)},c.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=a.Matrix.Identity()),a.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},c}(a.Light);a.DirectionalLight=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(c,d){var e=this;this.filter=b.FILTER_VARIANCESHADOWMAP,this._darkness=0,this._transparencyShadow=!1,this._viewMatrix=a.Matrix.Zero(),this._projectionMatrix=a.Matrix.Zero(),this._transformMatrix=a.Matrix.Zero(),this._worldViewProjection=a.Matrix.Zero(),this._light=d,this._scene=d.getScene(),d._shadowGenerator=this,this._shadowMap=new a.RenderTargetTexture(d.name+"_shadowMap",c,this._scene,!1),this._shadowMap.wrapU=a.Texture.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=a.Texture.CLAMP_ADDRESSMODE,this._shadowMap.renderParticles=!1;var f=function(b){var c=b.getRenderingMesh(),d=e._scene,f=d.getEngine();f.setState(b.getMaterial().backFaceCulling);var g=c._getInstancesRenderList(b._id);if(!g.mustReturn){var h=null!==f.getCaps().instancedArrays&&null!==g.visibleInstances;if(e.isReady(b,h)){f.enableEffect(e._effect),c._bind(b,e._effect,!1);var i=b.getMaterial();if(e._effect.setMatrix("viewProjection",e.getTransformMatrix()),i&&i.needAlphaTesting()){var j=i.getAlphaTestTexture();e._effect.setTexture("diffuseSampler",j),e._effect.setMatrix("diffuseMatrix",j.getTextureMatrix())}var k=c.skeleton&&c.isVerticesDataPresent(a.VertexBuffer.MatricesIndicesKind)&&c.isVerticesDataPresent(a.VertexBuffer.MatricesWeightsKind);if(k&&e._effect.setMatrices("mBones",c.skeleton.getTransformMatrices()),h)c._renderWithInstances(b,!1,g,e._effect,f);else if(g.renderSelf[b._id]&&(e._effect.setMatrix("world",c.getWorldMatrix()),c._draw(b,!0)),g.visibleInstances[b._id])for(var l=0;l=1?this._darkness=1:0>=a&&(this._darkness=0),elsethis._darkness=a},b.prototype.setTransparencyShadow=function(a){this._transparencyShadow=a},b.prototype.dispose=function(){this._shadowMap.dispose()},b._FILTER_NONE=0,b._FILTER_VARIANCESHADOWMAP=1,b._FILTER_POISSONSAMPLING=2,b}();a.ShadowGenerator=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(c,d,e){b.call(this,c,e),this.direction=d,this.groundColor=new a.Color3(0,0,0)}return __extends(c,b),c.prototype.setDirectionToTarget=function(b){return this.direction=a.Vector3.Normalize(b.subtract(a.Vector3.Zero())),this.direction},c.prototype.getShadowGenerator=function(){return null},c.prototype.transferToEffect=function(b,c,d){var e=a.Vector3.Normalize(this.direction);b.setFloat4(c,e.x,e.y,e.z,0),b.setColor3(d,this.groundColor.scale(this.intensity))},c.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=a.Matrix.Identity()),this._worldMatrix},c}(a.Light);a.HemisphericLight=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(a,b,c,d){return a.x>c.x+d?!1:c.x-d>b.x?!1:a.y>c.y+d?!1:c.y-d>b.y?!1:a.z>c.z+d?!1:c.z-d>b.z?!1:!0},c=function(a,b,c,d){var e=b*b-4*a*c,f={root:0,found:!1};if(0>e)return f;var g=Math.sqrt(e),h=(-b-g)/(2*a),i=(-b+g)/(2*a);if(h>i){var j=i;i=h,h=j}return h>0&&d>h?(f.root=h,f.found=!0,f):i>0&&d>i?(f.root=i,f.found=!0,f):f},d=function(){function d(){this.radius=new a.Vector3(1,1,1),this.retry=0,this.basePointWorld=a.Vector3.Zero(),this.velocityWorld=a.Vector3.Zero(),this.normalizedVelocity=a.Vector3.Zero(),this._collisionPoint=a.Vector3.Zero(),this._planeIntersectionPoint=a.Vector3.Zero(),this._tempVector=a.Vector3.Zero(),this._tempVector2=a.Vector3.Zero(),this._tempVector3=a.Vector3.Zero(),this._tempVector4=a.Vector3.Zero(),this._edge=a.Vector3.Zero(),this._baseToVertex=a.Vector3.Zero(),this._destinationPoint=a.Vector3.Zero(),this._slidePlaneNormal=a.Vector3.Zero(),this._displacementVector=a.Vector3.Zero()}return d.prototype._initialize=function(b,c,d){this.velocity=c,a.Vector3.NormalizeToRef(c,this.normalizedVelocity),this.basePoint=b,b.multiplyToRef(this.radius,this.basePointWorld),c.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=d,this.collisionFound=!1},d.prototype._checkPointInTriangle=function(b,c,d,e,f){c.subtractToRef(b,this._tempVector),d.subtractToRef(b,this._tempVector2),a.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var g=a.Vector3.Dot(this._tempVector4,f);return 0>g?!1:(e.subtractToRef(b,this._tempVector3),a.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),g=a.Vector3.Dot(this._tempVector4,f),0>g?!1:(a.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),g=a.Vector3.Dot(this._tempVector4,f),g>=0))},d.prototype._canDoCollision=function(c,d,e,f){var g=a.Vector3.Distance(this.basePointWorld,c),h=Math.max(this.radius.x,this.radius.y,this.radius.z);return g>this.velocityWorldLength+h+d?!1:b(e,f,this.basePointWorld,this.velocityWorldLength+h)?!0:!1},d.prototype._testTriangle=function(b,d,e,f,g){var h,i=!1;d._trianglePlanes||(d._trianglePlanes=[]),d._trianglePlanes[b]||(d._trianglePlanes[b]=new a.Plane(0,0,0,0),d._trianglePlanes[b].copyFromPoints(e,f,g));var j=d._trianglePlanes[b];if(d.getMaterial()||j.isFrontFacingTo(this.normalizedVelocity,0)){var k=j.signedDistanceTo(this.basePoint),l=a.Vector3.Dot(j.normal,this.velocity);if(0==l){if(Math.abs(k)>=1)return;i=!0,h=0}else{h=(-1-k)/l;var m=(1-k)/l;if(h>m){var n=m;m=h,h=n}if(h>1||0>m)return;0>h&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var o=!1,p=1;if(i||(this.basePoint.subtractToRef(j.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,e,f,g,j.normal)&&(o=!0,p=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!o){var q=this.velocity.lengthSquared(),r=q;this.basePoint.subtractToRef(e,this._tempVector);var s=2*a.Vector3.Dot(this.velocity,this._tempVector),t=this._tempVector.lengthSquared()-1,u=c(r,s,t,p);u.found&&(p=u.root,o=!0,this._collisionPoint.copyFrom(e)),this.basePoint.subtractToRef(f,this._tempVector),s=2*a.Vector3.Dot(this.velocity,this._tempVector),t=this._tempVector.lengthSquared()-1,u=c(r,s,t,p),u.found&&(p=u.root,o=!0,this._collisionPoint.copyFrom(f)),this.basePoint.subtractToRef(g,this._tempVector),s=2*a.Vector3.Dot(this.velocity,this._tempVector),t=this._tempVector.lengthSquared()-1,u=c(r,s,t,p),u.found&&(p=u.root,o=!0,this._collisionPoint.copyFrom(g)),f.subtractToRef(e,this._edge),e.subtractToRef(this.basePoint,this._baseToVertex);var v=this._edge.lengthSquared(),w=a.Vector3.Dot(this._edge,this.velocity),x=a.Vector3.Dot(this._edge,this._baseToVertex);if(r=v*-q+w*w,s=2*v*a.Vector3.Dot(this.velocity,this._baseToVertex)-2*w*x,t=v*(1-this._baseToVertex.lengthSquared())+x*x,u=c(r,s,t,p),u.found){var y=(w*u.root-x)/v;y>=0&&1>=y&&(p=u.root,o=!0,this._edge.scaleInPlace(y),e.addToRef(this._edge,this._collisionPoint))}g.subtractToRef(f,this._edge),f.subtractToRef(this.basePoint,this._baseToVertex),v=this._edge.lengthSquared(),w=a.Vector3.Dot(this._edge,this.velocity),x=a.Vector3.Dot(this._edge,this._baseToVertex),r=v*-q+w*w,s=2*v*a.Vector3.Dot(this.velocity,this._baseToVertex)-2*w*x,t=v*(1-this._baseToVertex.lengthSquared())+x*x,u=c(r,s,t,p),u.found&&(y=(w*u.root-x)/v,y>=0&&1>=y&&(p=u.root,o=!0,this._edge.scaleInPlace(y),f.addToRef(this._edge,this._collisionPoint))),e.subtractToRef(g,this._edge),g.subtractToRef(this.basePoint,this._baseToVertex),v=this._edge.lengthSquared(),w=a.Vector3.Dot(this._edge,this.velocity),x=a.Vector3.Dot(this._edge,this._baseToVertex),r=v*-q+w*w,s=2*v*a.Vector3.Dot(this.velocity,this._baseToVertex)-2*w*x,t=v*(1-this._baseToVertex.lengthSquared())+x*x,u=c(r,s,t,p),u.found&&(y=(w*u.root-x)/v,y>=0&&1>=y&&(p=u.root,o=!0,this._edge.scaleInPlace(y),g.addToRef(this._edge,this._collisionPoint)))}if(o){var z=p*this.velocity.length();(!this.collisionFound||zg;g+=3){var h=b[c[g]-f],i=b[c[g+1]-f],j=b[c[g+2]-f];this._testTriangle(g,a,j,i,h)}},d.prototype._getResponse=function(b,c){b.addToRef(c,this._destinationPoint),c.scaleInPlace(this.nearestDistance/c.length()),this.basePoint.addToRef(c,b),b.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this.epsilon,this._displacementVector),b.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(a.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,c)},d}();a.Collider=d}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(d,e,f){b.call(this,d,f),this.position=e,this.upVector=a.Vector3.Up(),this.orthoLeft=null,this.orthoRight=null,this.orthoBottom=null,this.orthoTop=null,this.fov=.8,this.minZ=.1,this.maxZ=1e3,this.inertia=.9,this.mode=c.PERSPECTIVE_CAMERA,this.isIntermediate=!1,this.viewport=new a.Viewport(0,0,1,1),this.subCameras=[],this.layerMask=4294967295,this._computedViewMatrix=a.Matrix.Identity(),this._projectionMatrix=new a.Matrix,this._postProcesses=new Array,this._postProcessesTakenIndices=[],f.cameras.push(this),f.activeCamera||(f.activeCamera=this)}return __extends(c,b),c.prototype._initCache=function(){b.prototype._initCache.call(this),this._cache.position=new a.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.upVector=new a.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.mode=void 0,this._cache.minZ=void 0,this._cache.maxZ=void 0,this._cache.fov=void 0,this._cache.aspectRatio=void 0,this._cache.orthoLeft=void 0,this._cache.orthoRight=void 0,this._cache.orthoBottom=void 0,this._cache.orthoTop=void 0,this._cache.renderWidth=void 0,this._cache.renderHeight=void 0},c.prototype._updateCache=function(a){a||b.prototype._updateCache.call(this);var c=this.getEngine();this._cache.position.copyFrom(this.position),this._cache.upVector.copyFrom(this.upVector),this._cache.mode=this.mode,this._cache.minZ=this.minZ,this._cache.maxZ=this.maxZ,this._cache.fov=this.fov,this._cache.aspectRatio=c.getAspectRatio(this),this._cache.orthoLeft=this.orthoLeft,this._cache.orthoRight=this.orthoRight,this._cache.orthoBottom=this.orthoBottom,this._cache.orthoTop=this.orthoTop,this._cache.renderWidth=c.getRenderWidth(),this._cache.renderHeight=c.getRenderHeight()},c.prototype._updateFromScene=function(){this.updateCache(),this._update()},c.prototype._isSynchronized=function(){return this._isSynchronizedViewMatrix()&&this._isSynchronizedProjectionMatrix()},c.prototype._isSynchronizedViewMatrix=function(){return b.prototype._isSynchronized.call(this)?this._cache.position.equals(this.position)&&this._cache.upVector.equals(this.upVector)&&this.isSynchronizedWithParent():!1},c.prototype._isSynchronizedProjectionMatrix=function(){var b=this._cache.mode===this.mode&&this._cache.minZ===this.minZ&&this._cache.maxZ===this.maxZ;if(!b)return!1;var c=this.getEngine();return b=this.mode===a.Camera.PERSPECTIVE_CAMERA?this._cache.fov===this.fov&&this._cache.aspectRatio===c.getAspectRatio(this):this._cache.orthoLeft===this.orthoLeft&&this._cache.orthoRight===this.orthoRight&&this._cache.orthoBottom===this.orthoBottom&&this._cache.orthoTop===this.orthoTop&&this._cache.renderWidth===c.getRenderWidth()&&this._cache.renderHeight===c.getRenderHeight()},c.prototype.attachControl=function(){},c.prototype.detachControl=function(){},c.prototype._update=function(){},c.prototype.attachPostProcess=function(b,c){if("undefined"==typeof c&&(c=null),!b.isReusable()&&this._postProcesses.indexOf(b)>-1)return a.Tools.Error("You're trying to reuse a post process not defined as reusable."),0;if(null==c||0>c)return this._postProcesses.push(b),this._postProcessesTakenIndices.push(this._postProcesses.length-1),this._postProcesses.length-1;var d=0;if(this._postProcesses[c]){for(var e=this._postProcesses.length-1,f=e;f>=c+1;--f)this._postProcesses[f+1]=this._postProcesses[f];d=1}for(f=0;f=f;--g)this._postProcessesTakenIndices[g+1]=this._postProcessesTakenIndices[g]+d;this._postProcessesTakenIndices[f]=c;break}d||-1!=this._postProcessesTakenIndices.indexOf(c)||this._postProcessesTakenIndices.push(c);var h=c+d;return this._postProcesses[h]=b,h},c.prototype.detachPostProcess=function(a,b){"undefined"==typeof b&&(b=null);var c=[];if(b)for(b=b instanceof Array?b:[b],f=0;ff;f++)if(this._postProcesses[f]===a){delete this._postProcesses[f];var g=this._postProcessesTakenIndices.indexOf(f);this._postProcessesTakenIndices.splice(g,1)}return c},c.prototype.getWorldMatrix=function(){this._worldMatrix||(this._worldMatrix=a.Matrix.Identity());var b=this.getViewMatrix();return b.invertToRef(this._worldMatrix),this._worldMatrix},c.prototype._getViewMatrix=function(){return a.Matrix.Identity()},c.prototype.getViewMatrix=function(){return this._computedViewMatrix=this._computeViewMatrix(),this.parent&&this.parent.getWorldMatrix&&!this.isSynchronized()?(this._worldMatrix||(this._worldMatrix=a.Matrix.Identity()),this._computedViewMatrix.invertToRef(this._worldMatrix),this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._computedViewMatrix),this._computedViewMatrix.invert(),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix):this._computedViewMatrix},c.prototype._computeViewMatrix=function(a){return!a&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this._computedViewMatrix=this._getViewMatrix(),this.parent&&this.parent.getWorldMatrix||(this._currentRenderId=this.getScene().getRenderId()),this._computedViewMatrix)},c.prototype.getProjectionMatrix=function(b){if(!b&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;var c=this.getEngine();if(this.mode===a.Camera.PERSPECTIVE_CAMERA)return this.minZ<=0&&(this.minZ=.1),a.Matrix.PerspectiveFovLHToRef(this.fov,c.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix),this._projectionMatrix;var d=c.getRenderWidth()/2,e=c.getRenderHeight()/2;return a.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-d,this.orthoRight||d,this.orthoBottom||-e,this.orthoTop||e,this.minZ,this.maxZ,this._projectionMatrix),this._projectionMatrix},c.prototype.dispose=function(){var a=this.getScene().cameras.indexOf(this);this.getScene().cameras.splice(a,1);for(var b=0;b=0?-Math.atan(c.z/c.x)+Math.PI/2:-Math.atan(c.z/c.x)-Math.PI/2,this.rotation.z=-Math.acos(a.Vector3.Dot(new a.Vector3(0,1,0),this.upVector)),isNaN(this.rotation.x)&&(this.rotation.x=0),isNaN(this.rotation.y)&&(this.rotation.y=0),isNaN(this.rotation.z)&&(this.rotation.z=0)},c.prototype.getTarget=function(){return this._currentTarget},c.prototype.attachControl=function(b,c){var d,e=this,f=this.getEngine();this._attachedElement||(this._attachedElement=b,void 0===this._onMouseDown&&(this._onMouseDown=function(a){d={x:a.clientX,y:a.clientY},c||a.preventDefault()},this._onMouseUp=function(a){d=null,c||a.preventDefault()},this._onMouseOut=function(a){d=null,e._keys=[],c||a.preventDefault()},this._onMouseMove=function(a){if(d||f.isPointerLock){var b,g;f.isPointerLock?(b=a.movementX||a.mozMovementX||a.webkitMovementX||a.msMovementX||0,g=a.movementY||a.mozMovementY||a.webkitMovementY||a.msMovementY||0):(b=a.clientX-d.x,g=a.clientY-d.y),e.cameraRotation.y+=b/e.angularSensibility,e.cameraRotation.x+=g/e.angularSensibility,d={x:a.clientX,y:a.clientY},c||a.preventDefault()}},this._onKeyDown=function(a){if(-1!==e.keysUp.indexOf(a.keyCode)||-1!==e.keysDown.indexOf(a.keyCode)||-1!==e.keysLeft.indexOf(a.keyCode)||-1!==e.keysRight.indexOf(a.keyCode)){var b=e._keys.indexOf(a.keyCode);-1===b&&e._keys.push(a.keyCode),c||a.preventDefault()}},this._onKeyUp=function(a){if(-1!==e.keysUp.indexOf(a.keyCode)||-1!==e.keysDown.indexOf(a.keyCode)||-1!==e.keysLeft.indexOf(a.keyCode)||-1!==e.keysRight.indexOf(a.keyCode)){var b=e._keys.indexOf(a.keyCode);b>=0&&e._keys.splice(b,1),c||a.preventDefault()}},this._onLostFocus=function(){e._keys=[]},this._reset=function(){e._keys=[],d=null,e.cameraDirection=new a.Vector3(0,0,0),e.cameraRotation=new a.Vector2(0,0)}),b.addEventListener("mousedown",this._onMouseDown,!1),b.addEventListener("mouseup",this._onMouseUp,!1),b.addEventListener("mouseout",this._onMouseOut,!1),b.addEventListener("mousemove",this._onMouseMove,!1),a.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]))},c.prototype.detachControl=function(b){this._attachedElement==b&&(b.removeEventListener("mousedown",this._onMouseDown),b.removeEventListener("mouseup",this._onMouseUp),b.removeEventListener("mouseout",this._onMouseOut),b.removeEventListener("mousemove",this._onMouseMove),a.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._attachedElement=null,this._reset&&this._reset())},c.prototype._collideWithWorld=function(b){var c;c=this.parent?a.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,c.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._collider.radius=this.ellipsoid,this.getScene()._getNewPosition(this._oldPosition,b,this._collider,3,this._newPosition),this._newPosition.subtractToRef(this._oldPosition,this._diffPosition),this._diffPosition.length()>a.Engine.CollisionsEpsilon&&(this.position.addInPlace(this._diffPosition),this.onCollide&&this.onCollide(this._collider.collidedMesh))},c.prototype._checkInputs=function(){this._localDirection||(this._localDirection=a.Vector3.Zero(),this._transformedDirection=a.Vector3.Zero());for(var b=0;b0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0,c=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(b)if(this.checkCollisions&&this.getScene().collisionsEnabled){if(this._collideWithWorld(this.cameraDirection),this.applyGravity){var d=this.position;this._collideWithWorld(this.getScene().gravity),this._needMoveForGravity=0!=a.Vector3.DistanceSquared(d,this.position)}}else this.position.addInPlace(this.cameraDirection);if(c&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,!this.noRotationConstraint)){var e=Math.PI/2*.95;this.rotation.x>e&&(this.rotation.x=e),this.rotation.x<-e&&(this.rotation.x=-e)}b&&(Math.abs(this.cameraDirection.x)1)this.cameraRotation.x+=-this._offsetY/this.angularSensibility;else{var b=this._computeLocalCameraSpeed(),c=new a.Vector3(0,0,b*this._offsetY/this.moveSensibility);a.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(a.Vector3.TransformCoordinates(c,this._cameraRotationMatrix))}},c}(a.FreeCamera);a.TouchCamera=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(a,c,d){var e=this;b.call(this,a,c,d),this._offsetX=null,this._offsetY=null,this._orientationGamma=0,this._orientationBeta=0,this._initialOrientationGamma=0,this._initialOrientationBeta=0,this.angularSensibility=1e4,this.moveSensibility=50,window.addEventListener("resize",function(){e._initialOrientationGamma=null},!1)}return __extends(c,b),c.prototype.attachControl=function(a){var b=this;this._attachedCanvas||(this._attachedCanvas=a,this._orientationChanged||(this._orientationChanged=function(a){b._initialOrientationGamma||(b._initialOrientationGamma=a.gamma,b._initialOrientationBeta=a.beta),b._orientationGamma=a.gamma,b._orientationBeta=a.beta,b._offsetY=b._initialOrientationBeta-b._orientationBeta,b._offsetX=b._initialOrientationGamma-b._orientationGamma}),window.addEventListener("deviceorientation",this._orientationChanged))},c.prototype.detachControl=function(a){this._attachedCanvas==a&&(window.removeEventListener("deviceorientation",this._orientationChanged),this._attachedCanvas=null,this._orientationGamma=0,this._orientationBeta=0,this._initialOrientationGamma=0,this._initialOrientationBeta=0)},c.prototype._checkInputs=function(){if(this._offsetX){this.cameraRotation.y-=this._offsetX/this.angularSensibility;var b=this._computeLocalCameraSpeed(),c=new a.Vector3(0,0,b*this._offsetY/this.moveSensibility);a.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(a.Vector3.TransformCoordinates(c,this._cameraRotationMatrix))}},c}(a.FreeCamera);a.DeviceOrientationCamera=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=a.Tools.GetPointerPrefix(),c=function(c){function d(b,d,e,f,g,h){c.call(this,b,a.Vector3.Zero(),h),this.alpha=d,this.beta=e,this.radius=f,this.target=g,this.inertialAlphaOffset=0,this.inertialBetaOffset=0,this.inertialRadiusOffset=0,this.lowerAlphaLimit=null,this.upperAlphaLimit=null,this.lowerBetaLimit=.01,this.upperBetaLimit=Math.PI,this.lowerRadiusLimit=null,this.upperRadiusLimit=null,this.angularSensibility=1e3,this.wheelPrecision=3,this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39],this.zoomOnFactor=1,this._keys=[],this._viewMatrix=new a.Matrix,this.checkCollisions=!1,this.collisionRadius=new a.Vector3(.5,.5,.5),this._collider=new a.Collider,this._previousPosition=a.Vector3.Zero(),this._collisionVelocity=a.Vector3.Zero(),this._newPosition=a.Vector3.Zero(),this.getViewMatrix()}return __extends(d,c),d.prototype._getTargetPosition=function(){return this.target.position||this.target},d.prototype._initCache=function(){c.prototype._initCache.call(this),this._cache.target=new a.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.alpha=void 0,this._cache.beta=void 0,this._cache.radius=void 0},d.prototype._updateCache=function(a){a||c.prototype._updateCache.call(this),this._cache.target.copyFrom(this._getTargetPosition()),this._cache.alpha=this.alpha,this._cache.beta=this.beta,this._cache.radius=this.radius},d.prototype._isSynchronizedViewMatrix=function(){return c.prototype._isSynchronizedViewMatrix.call(this)?this._cache.target.equals(this._getTargetPosition())&&this._cache.alpha===this.alpha&&this._cache.beta===this.beta&&this._cache.radius===this.radius:!1},d.prototype.attachControl=function(c,d){var e,f,g=this;if(!this._attachedElement){this._attachedElement=c;var h=this.getEngine();void 0===this._onPointerDown&&(this._onPointerDown=function(a){f||(f=a.pointerId,e={x:a.clientX,y:a.clientY},d||a.preventDefault())},this._onPointerUp=function(a){e=null,f=null,d||a.preventDefault()},this._onPointerMove=function(a){if(e&&f===a.pointerId){var b=a.clientX-e.x,c=a.clientY-e.y;g.inertialAlphaOffset-=b/g.angularSensibility,g.inertialBetaOffset-=c/g.angularSensibility,e={x:a.clientX,y:a.clientY},d||a.preventDefault()}},this._onMouseMove=function(a){if(h.isPointerLock){var b=a.movementX||a.mozMovementX||a.webkitMovementX||a.msMovementX||0,c=a.movementY||a.mozMovementY||a.webkitMovementY||a.msMovementY||0;g.inertialAlphaOffset-=b/g.angularSensibility,g.inertialBetaOffset-=c/g.angularSensibility,d||a.preventDefault()}},this._wheel=function(a){var b=0;a.wheelDelta?b=a.wheelDelta/(40*g.wheelPrecision):a.detail&&(b=-a.detail/g.wheelPrecision),b&&(g.inertialRadiusOffset+=b),a.preventDefault&&(d||a.preventDefault())},this._onKeyDown=function(a){if(-1!==g.keysUp.indexOf(a.keyCode)||-1!==g.keysDown.indexOf(a.keyCode)||-1!==g.keysLeft.indexOf(a.keyCode)||-1!==g.keysRight.indexOf(a.keyCode)){var b=g._keys.indexOf(a.keyCode);-1===b&&g._keys.push(a.keyCode),a.preventDefault&&(d||a.preventDefault())}},this._onKeyUp=function(a){if(-1!==g.keysUp.indexOf(a.keyCode)||-1!==g.keysDown.indexOf(a.keyCode)||-1!==g.keysLeft.indexOf(a.keyCode)||-1!==g.keysRight.indexOf(a.keyCode)){var b=g._keys.indexOf(a.keyCode);b>=0&&g._keys.splice(b,1),a.preventDefault&&(d||a.preventDefault())}},this._onLostFocus=function(){g._keys=[],f=null},this._onGestureStart=function(a){void 0!==window.MSGesture&&(g._MSGestureHandler||(g._MSGestureHandler=new MSGesture,g._MSGestureHandler.target=c),g._MSGestureHandler.addPointer(a.pointerId))},this._onGesture=function(a){g.radius*=a.scale,a.preventDefault&&(d||(a.stopPropagation(),a.preventDefault()))},this._reset=function(){g._keys=[],g.inertialAlphaOffset=0,g.inertialBetaOffset=0,g.inertialRadiusOffset=0,e=null,f=null}),c.addEventListener(b+"down",this._onPointerDown,!1),c.addEventListener(b+"up",this._onPointerUp,!1),c.addEventListener(b+"out",this._onPointerUp,!1),c.addEventListener(b+"move",this._onPointerMove,!1),c.addEventListener("mousemove",this._onMouseMove,!1),c.addEventListener("MSPointerDown",this._onGestureStart,!1),c.addEventListener("MSGestureChange",this._onGesture,!1),c.addEventListener("mousewheel",this._wheel,!1),c.addEventListener("DOMMouseScroll",this._wheel,!1),a.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}])}},d.prototype.detachControl=function(c){this._attachedElement==c&&(c.removeEventListener(b+"down",this._onPointerDown),c.removeEventListener(b+"up",this._onPointerUp),c.removeEventListener(b+"out",this._onPointerUp),c.removeEventListener(b+"move",this._onPointerMove),c.removeEventListener("mousemove",this._onMouseMove),c.removeEventListener("MSPointerDown",this._onGestureStart),c.removeEventListener("MSGestureChange",this._onGesture),c.removeEventListener("mousewheel",this._wheel),c.removeEventListener("DOMMouseScroll",this._wheel),a.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._MSGestureHandler=null,this._attachedElement=null,this._reset&&this._reset())},d.prototype._update=function(){for(var b=0;bthis.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerBetaLimit&&this.betathis.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerRadiusLimit&&this.radiusthis.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},d.prototype.setPosition=function(a){var b=a.subtract(this._getTargetPosition());this.radius=b.length(),this.alpha=Math.acos(b.x/Math.sqrt(Math.pow(b.x,2)+Math.pow(b.z,2))),b.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(b.y/this.radius)},d.prototype._getViewMatrix=function(){var b=Math.cos(this.alpha),c=Math.sin(this.alpha),d=Math.cos(this.beta),e=Math.sin(this.beta),f=this._getTargetPosition();return f.addToRef(new a.Vector3(this.radius*b*e,this.radius*d,this.radius*c*e),this.position),this.checkCollisions&&(this._collider.radius=this.collisionRadius,this.position.subtractToRef(this._previousPosition,this._collisionVelocity),this.getScene()._getNewPosition(this._previousPosition,this._collisionVelocity,this._collider,3,this._newPosition),this._newPosition.equalsWithEpsilon(this.position)||(this.position.copyFrom(this._previousPosition),this.alpha=this._previousAlpha,this.beta=this._previousBeta,this.radius=this._previousRadius,this.onCollide&&this.onCollide(this._collider.collidedMesh))),a.Matrix.LookAtLHToRef(this.position,f,this.upVector,this._viewMatrix),this._previousAlpha=this.alpha,this._previousBeta=this.beta,this._previousRadius=this.radius,this._previousPosition.copyFrom(this.position),this._viewMatrix},d.prototype.zoomOn=function(b){b=b||this.getScene().meshes;var c=a.Mesh.MinMax(b),d=a.Vector3.Distance(c.min,c.max);this.radius=d*this.zoomOnFactor,this.focusOn({min:c.min,max:c.max,distance:d})},d.prototype.focusOn=function(b){var c,d;void 0===b.min?(c=b||this.getScene().meshes,c=a.Mesh.MinMax(c),d=a.Vector3.Distance(c.min,c.max)):(c=b,d=b.distance),this.target=a.Mesh.Center(c),this.maxZ=2*d},d}(a.Camera);a.ArcRotateCamera=c}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(b){this.autoClear=!0,this.clearColor=new a.Color3(.2,.2,.3),this.ambientColor=new a.Color3(0,0,0),this.forceWireframe=!1,this.cameraToUseForPointers=null,this.fogMode=a.Scene.FOGMODE_NONE,this.fogColor=new a.Color3(.2,.2,.3),this.fogDensity=.1,this.fogStart=0,this.fogEnd=1e3,this.lightsEnabled=!0,this.lights=new Array,this.cameras=new Array,this.activeCameras=new Array,this.meshes=new Array,this._geometries=new Array,this.materials=new Array,this.multiMaterials=new Array,this.defaultMaterial=new a.StandardMaterial("default material",this),this.texturesEnabled=!0,this.textures=new Array,this.particlesEnabled=!0,this.particleSystems=new Array,this.spriteManagers=new Array,this.layers=new Array,this.skeletons=new Array,this.lensFlareSystems=new Array,this.collisionsEnabled=!0,this.gravity=new a.Vector3(0,-9,0),this.postProcessesEnabled=!0,this.renderTargetsEnabled=!0,this.customRenderTargets=new Array,this.importedMeshesFiles=new Array,this._actionManagers=new Array,this._meshesForIntersections=new a.SmartArray(256),this._totalVertices=0,this._activeVertices=0,this._activeParticles=0,this._lastFrameDuration=0,this._evaluateActiveMeshesDuration=0,this._renderTargetsDuration=0,this._particlesDuration=0,this._renderDuration=0,this._spritesDuration=0,this._animationRatio=0,this._renderId=0,this._executeWhenReadyTimeoutId=-1,this._toBeDisposed=new a.SmartArray(256),this._onReadyCallbacks=new Array,this._pendingData=[],this._onBeforeRenderCallbacks=new Array,this._activeMeshes=new a.SmartArray(256),this._processedMaterials=new a.SmartArray(256),this._renderTargets=new a.SmartArray(256),this._activeParticleSystems=new a.SmartArray(256),this._activeSkeletons=new a.SmartArray(32),this._activeAnimatables=new Array,this._transformMatrix=a.Matrix.Zero(),this._scaledPosition=a.Vector3.Zero(),this._scaledVelocity=a.Vector3.Zero(),this._engine=b,b.scenes.push(this),this._renderingManager=new a.RenderingManager(this),this.postProcessManager=new a.PostProcessManager(this),this.postProcessRenderPipelineManager=new a.PostProcessRenderPipelineManager,this._boundingBoxRenderer=new a.BoundingBoxRenderer(this),this.attachControl()}return Object.defineProperty(b.prototype,"meshUnderPointer",{get:function(){return this._meshUnderPointer},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"pointerX",{get:function(){return this._pointerX},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"pointerY",{get:function(){return this._pointerY},enumerable:!0,configurable:!0}),b.prototype.getBoundingBoxRenderer=function(){return this._boundingBoxRenderer},b.prototype.getEngine=function(){return this._engine},b.prototype.getTotalVertices=function(){return this._totalVertices},b.prototype.getActiveVertices=function(){return this._activeVertices},b.prototype.getActiveParticles=function(){return this._activeParticles},b.prototype.getLastFrameDuration=function(){return this._lastFrameDuration},b.prototype.getEvaluateActiveMeshesDuration=function(){return this._evaluateActiveMeshesDuration},b.prototype.getActiveMeshes=function(){return this._activeMeshes},b.prototype.getRenderTargetsDuration=function(){return this._renderTargetsDuration},b.prototype.getRenderDuration=function(){return this._renderDuration},b.prototype.getParticlesDuration=function(){return this._particlesDuration},b.prototype.getSpritesDuration=function(){return this._spritesDuration},b.prototype.getAnimationRatio=function(){return this._animationRatio},b.prototype.getRenderId=function(){return this._renderId},b.prototype._updatePointerPosition=function(a){var b=this._engine.getRenderingCanvasClientRect();this._pointerX=a.clientX-b.left,this._pointerY=a.clientY-b.top,this.cameraToUseForPointers&&(this._pointerX=this._pointerX-this.cameraToUseForPointers.viewport.x*this._engine.getRenderWidth(),this._pointerY=this._pointerY-this.cameraToUseForPointers.viewport.y*this._engine.getRenderHeight())},b.prototype.attachControl=function(){var b=this;this._onPointerMove=function(a){var c=b._engine.getRenderingCanvas();b._updatePointerPosition(a);var d=b.pick(b._pointerX,b._pointerY,function(a){return a.isPickable&&a.isVisible&&a.isReady()&&a.actionManager&&a.actionManager.hasPointerTriggers},!1,b.cameraToUseForPointers);d.hit?(b.setPointerOverMesh(d.pickedMesh),c.style.cursor="pointer",b._meshUnderPointer=d.pickedMesh):(b.setPointerOverMesh(null),c.style.cursor="",b._meshUnderPointer=null)},this._onPointerDown=function(c){var d=null;b.onPointerDown||(d=function(a){return a.isPickable&&a.isVisible&&a.isReady()&&a.actionManager&&a.actionManager.hasPickTriggers}),b._updatePointerPosition(c);var e=b.pick(b._pointerX,b._pointerY,d,!1,b.cameraToUseForPointers);if(e.hit&&e.pickedMesh.actionManager){switch(c.button){case 0:e.pickedMesh.actionManager.processTrigger(a.ActionManager.OnLeftPickTrigger,a.ActionEvent.CreateNew(e.pickedMesh));break;case 1:e.pickedMesh.actionManager.processTrigger(a.ActionManager.OnCenterPickTrigger,a.ActionEvent.CreateNew(e.pickedMesh));break;case 2:e.pickedMesh.actionManager.processTrigger(a.ActionManager.OnRightPickTrigger,a.ActionEvent.CreateNew(e.pickedMesh))}e.pickedMesh.actionManager.processTrigger(a.ActionManager.OnPickTrigger,a.ActionEvent.CreateNew(e.pickedMesh))}b.onPointerDown&&b.onPointerDown(c,e)},this._onKeyDown=function(c){b.actionManager&&b.actionManager.processTrigger(a.ActionManager.OnKeyDownTrigger,a.ActionEvent.CreateNewFromScene(b,c))},this._onKeyUp=function(c){b.actionManager&&b.actionManager.processTrigger(a.ActionManager.OnKeyUpTrigger,a.ActionEvent.CreateNewFromScene(b,c))};var c=a.Tools.GetPointerPrefix();this._engine.getRenderingCanvas().addEventListener(c+"move",this._onPointerMove,!1),this._engine.getRenderingCanvas().addEventListener(c+"down",this._onPointerDown,!1),window.addEventListener("keydown",this._onKeyDown,!1),window.addEventListener("keyup",this._onKeyUp,!1)},b.prototype.detachControl=function(){var b=a.Tools.GetPointerPrefix();this._engine.getRenderingCanvas().removeEventListener(b+"move",this._onPointerMove),this._engine.getRenderingCanvas().removeEventListener(b+"down",this._onPointerDown),window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp)},b.prototype.isReady=function(){if(this._pendingData.length>0)return!1;for(var b=0;b-1&&this._onBeforeRenderCallbacks.splice(b,1)},b.prototype._addPendingData=function(a){this._pendingData.push(a)},b.prototype._removePendingData=function(a){var b=this._pendingData.indexOf(a);-1!==b&&this._pendingData.splice(b,1)},b.prototype.getWaitingItemsCount=function(){return this._pendingData.length},b.prototype.executeWhenReady=function(a){var b=this;this._onReadyCallbacks.push(a),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){b._checkIsReady()},150))},b.prototype._checkIsReady=function(){var a=this;return this.isReady()?(this._onReadyCallbacks.forEach(function(a){a()}),this._onReadyCallbacks=[],void(this._executeWhenReadyTimeoutId=-1)):void(this._executeWhenReadyTimeoutId=setTimeout(function(){a._checkIsReady()},150))},b.prototype.beginAnimation=function(b,c,d,e,f,g,h){if(void 0===f&&(f=1),this.stopAnimation(b),h||(h=new a.Animatable(this,b,c,d,e,f,g)),b.animations&&h.appendAnimations(b,b.animations),b.getAnimatables)for(var i=b.getAnimatables(),j=0;j=0;b--)if(this.meshes[b].id===a)return this.meshes[b];return null},b.prototype.getLastEntryByID=function(a){for(var b=this.meshes.length-1;b>=0;b--)if(this.meshes[b].id===a)return this.meshes[b];for(b=this.cameras.length-1;b>=0;b--)if(this.cameras[b].id===a)return this.cameras[b];for(b=this.lights.length-1;b>=0;b--)if(this.lights[b].id===a)return this.lights[b];return null},b.prototype.getMeshByName=function(a){for(var b=0;b=0;b--)if(this.skeletons[b].id===a)return this.skeletons[b];return null},b.prototype.getSkeletonById=function(a){for(var b=0;be;e++){var f=b[e];this._totalVertices+=f.getTotalVertices(),f.isReady()&&(f.computeWorldMatrix(),f._preActivate(),f.actionManager&&f.actionManager.hasSpecificTriggers([a.ActionManager.OnIntersectionEnterTrigger,a.ActionManager.OnIntersectionExitTrigger])&&this._meshesForIntersections.pushNoDuplicate(f),f.isEnabled()&&f.isVisible&&f.visibility>0&&0!=(f.layerMask&this.activeCamera.layerMask)&&f.isInFrustum(this._frustumPlanes)&&(this._activeMeshes.push(f),f._activate(this._renderId),this._activeMesh(f)))}var g=(new Date).getTime();if(this.particlesEnabled)for(var h=0;he;e++){var f=c[e];this._evaluateSubMesh(f,a)}}},b.prototype.updateTransformMatrix=function(a){this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(a))},b.prototype._renderForCamera=function(a){var b=this._engine;if(this.activeCamera=a,!this.activeCamera)throw new Error("Active camera not set");b.setViewport(this.activeCamera.viewport),this._renderId++,this.updateTransformMatrix(),this.beforeCameraRender&&this.beforeCameraRender(this.activeCamera);var c=(new Date).getTime();this._evaluateActiveMeshes(),this._evaluateActiveMeshesDuration+=(new Date).getTime()-c;for(var d=0;d0&&b.restoreDefaultFramebuffer(),this._renderTargetsDuration=(new Date).getTime()-h,this.postProcessManager._prepareFrame();var j=(new Date).getTime();if(this.layers.length){b.setDepthBuffer(!1);var k,l;for(k=0;k-1&&e.trigger==a.ActionManager.OnIntersectionExitTrigger){c.actionManager.processTrigger(a.ActionManager.OnIntersectionExitTrigger,a.ActionEvent.CreateNew(c));var i=c._intersectionsInProgress.indexOf(f);i>-1&&c._intersectionsInProgress.splice(i,1)}}}},b.prototype.render=function(){var c=(new Date).getTime();this._particlesDuration=0,this._spritesDuration=0,this._activeParticles=0,this._renderDuration=0,this._evaluateActiveMeshesDuration=0,this._totalVertices=0,this._activeVertices=0,this._meshesForIntersections.reset(),this.actionManager&&this.actionManager.processTrigger(a.ActionManager.OnEveryFrameTrigger,null),this.beforeRender&&this.beforeRender();for(var d=0;d0)for(var i=this._renderId,j=0;j=e)return void f.copyFrom(b);d._initialize(b,c,h);for(var i=0;i=e.distance))&&(e=j,d))break}return e||new a.PickingInfo},b.prototype.pick=function(a,b,c,d,e){var f=this;return this._internalPick(function(c){return f.createPickingRay(a,b,c,e)},c,d)},b.prototype.pickWithRay=function(b,c,d){var e=this;return this._internalPick(function(c){return e._pickWithRayInverseMatrix||(e._pickWithRayInverseMatrix=a.Matrix.Identity()),c.invertToRef(e._pickWithRayInverseMatrix),a.Ray.Transform(b,e._pickWithRayInverseMatrix)},c,d)},b.prototype.setPointerOverMesh=function(b){this._pointerOverMesh!==b&&(this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(a.ActionManager.OnPointerOutTrigger,a.ActionEvent.CreateNew(this._pointerOverMesh)),this._pointerOverMesh=b,this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(a.ActionManager.OnPointerOverTrigger,a.ActionEvent.CreateNew(this._pointerOverMesh)))},b.prototype.getPointerOverMesh=function(){return this._pointerOverMesh},b.prototype.getPhysicsEngine=function(){return this._physicsEngine},b.prototype.enablePhysics=function(b,c){return this._physicsEngine?!0:(this._physicsEngine=new a.PhysicsEngine(c),this._physicsEngine.isSupported()?(this._physicsEngine._initialize(b),!0):(this._physicsEngine=null,!1))},b.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=void 0)},b.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},b.prototype.setGravity=function(a){this._physicsEngine&&this._physicsEngine._setGravity(a)},b.prototype.createCompoundImpostor=function(a,b){if(a.parts&&(b=a,a=a.parts),!this._physicsEngine)return null;for(var c=0;ca.Engine.CollisionsEpsilon&&this.position.addInPlace(this._diffPositionForCollisions)},c.prototype.createOrUpdateSubmeshesOctree=function(b,c){"undefined"==typeof b&&(b=64),"undefined"==typeof c&&(c=2),this._submeshesOctree||(this._submeshesOctree=new a.Octree(a.Octree.CreationFuncForSubMeshes,b,c)),this.computeWorldMatrix(!0);var d=this.getBoundingInfo().boundingBox;return this._submeshesOctree.update(d.minimumWorld,d.maximumWorld,this.subMeshes),this._submeshesOctree},c.prototype._collideForSubMesh=function(b,c,d){if(this._generatePointsArray(),!b._lastColliderWorldVertices||!b._lastColliderTransformMatrix.equals(c)){b._lastColliderTransformMatrix=c.clone(),b._lastColliderWorldVertices=[],b._trianglePlanes=[];for(var e=b.verticesStart,f=b.verticesStart+b.verticesCount,g=e;f>g;g++)b._lastColliderWorldVertices.push(a.Vector3.TransformCoordinates(this._positions[g],c))}d._collide(b,b._lastColliderWorldVertices,this.getIndices(),b.indexStart,b.indexStart+b.indexCount,b.verticesStart)},c.prototype._processCollisionsForSubMeshes=function(a,b){var c,d;if(this._submeshesOctree&&this.useOctreeForCollisions){var e=a.velocityWorldLength+Math.max(a.radius.x,a.radius.y,a.radius.z),f=this._submeshesOctree.intersects(a.basePointWorld,e);d=f.length,c=f.data}else c=this.subMeshes,d=c.length;for(var g=0;d>g;g++){var h=c[g];d>1&&!h._checkCollision(a)||this._collideForSubMesh(h,b,a)}},c.prototype._checkCollision=function(b){this._boundingInfo._checkCollision(b)&&(a.Matrix.ScalingToRef(1/b.radius.x,1/b.radius.y,1/b.radius.z,this._collisionsScalingMatrix),this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix),this._processCollisionsForSubMeshes(b,this._collisionsTransformMatrix))},c.prototype._generatePointsArray=function(){return!1},c.prototype.intersects=function(b,c){var d=new a.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&b.intersectsSphere(this._boundingInfo.boundingSphere)&&b.intersectsBox(this._boundingInfo.boundingBox)))return d;if(!this._generatePointsArray())return d;var e,f,g=null;if(this._submeshesOctree&&this.useOctreeForPicking){var h=a.Ray.Transform(b,this.getWorldMatrix()),i=this._submeshesOctree.intersectsRay(h);f=i.length,e=i.data}else e=this.subMeshes,f=e.length;for(var j=0;f>j;j++){var k=e[j];if(!(f>1)||k.canIntersects(b)){var l=k.intersects(b,this._positions,this.getIndices(),c);if(l&&(c||!g||l.distanceb)){for(var c=this.getTotalIndices(),d=c/b|0,e=0;d%3!=0;)d++;this.releaseSubMeshes();for(var f=0;b>f&&!(e>=c);f++)a.SubMesh.CreateFromIndices(0,e,Math.min(d,c-e),this),e+=d;this.synchronizeInstances()}},d.prototype.setVerticesData=function(b,c,d){if(b instanceof Array){var e=c;c=b,b=e,a.Tools.Warn("Deprecated usage of setVerticesData detected (since v1.12). Current signature is setVerticesData(kind, data, updatable).")}if(this._geometry)this._geometry.setVerticesData(b,c,d);else{var f=new a.VertexData;f.set(c,b);var g=this.getScene();new a.Geometry(a.Geometry.RandomId(),g,f,d,this)}},d.prototype.updateVerticesData=function(a,b,c,d){this._geometry&&(d?(this.makeGeometryUnique(),this.updateVerticesData(a,b,c,!1)):this._geometry.updateVerticesData(a,b,c))},d.prototype.makeGeometryUnique=function(){if(this._geometry){var b=this._geometry.copy(a.Geometry.RandomId());b.applyToMesh(this)}},d.prototype.setIndices=function(b){if(this._geometry)this._geometry.setIndices(b);else{var c=new a.VertexData;c.indices=b;var d=this.getScene();new a.Geometry(a.Geometry.RandomId(),d,c,!1,this)}},d.prototype._bind=function(a,b,c){var d=this.getScene().getEngine(),e=this._geometry.getIndexBuffer();c&&(e=a.getLinesIndexBuffer(this.getIndices(),d)),d.bindMultiBuffers(this._geometry.getVertexBuffers(),e,b)},d.prototype._draw=function(a,b,c){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var d=this.getScene().getEngine();d.draw(b,b?a.indexStart:0,b?a.indexCount:a.linesIndexCount,c)}},d.prototype.registerBeforeRender=function(a){this._onBeforeRenderCallbacks.push(a)},d.prototype.unregisterBeforeRender=function(a){var b=this._onBeforeRenderCallbacks.indexOf(a);b>-1&&this._onBeforeRenderCallbacks.splice(b,1)},d.prototype.registerAfterRender=function(a){this._onAfterRenderCallbacks.push(a)},d.prototype.unregisterAfterRender=function(a){var b=this._onAfterRenderCallbacks.indexOf(a);b>-1&&this._onAfterRenderCallbacks.splice(b,1)},d.prototype._getInstancesRenderList=function(a){var b=this.getScene();if(this._batchCache.mustReturn=!1,this._batchCache.renderSelf[a]=this.isEnabled()&&this.isVisible,this._batchCache.visibleInstances[a]=null,this._visibleInstances){var c=b.getRenderId();this._batchCache.visibleInstances[a]=this._visibleInstances[c];var d=this._renderId;if(!this._batchCache.visibleInstances[a]&&this._visibleInstances.defaultRenderId&&(this._batchCache.visibleInstances[a]=this._visibleInstances[this._visibleInstances.defaultRenderId],c=this._visibleInstances.defaultRenderId,d=this._visibleInstances.selfDefaultRenderId),this._batchCache.visibleInstances[a]&&this._batchCache.visibleInstances[a].length){if(this._renderIdForInstances[a]===c)return this._batchCache.mustReturn=!0,this._batchCache;c!==d&&(this._batchCache.renderSelf[a]=!1)}this._renderIdForInstances[a]=c}return this._batchCache},d.prototype._renderWithInstances=function(a,b,c,d,e){for(var f=this.instances.length+1,g=16*f*4;this._instancesBufferSizer;r++){var m=k[r];for(g=0;go;o++)e[h].push(d[h][m*n+o])}}for(var p=[],q=e[a.VertexBuffer.PositionKind],r=0;l>r;r+=3){k[r]=r,k[r+1]=r+1,k[r+2]=r+2;for(var s=a.Vector3.FromArray(q,3*r),t=a.Vector3.FromArray(q,3*(r+1)),u=a.Vector3.FromArray(q,3*(r+2)),v=s.subtract(t),w=u.subtract(t),x=a.Vector3.Normalize(a.Vector3.Cross(v,w)),y=0;3>y;y++)p.push(x.x),p.push(x.y),p.push(x.z)}for(this.setIndices(k),this.setVerticesData(a.VertexBuffer.NormalKind,p,f),g=0;gj;j++){var k=i[j];g>k&&(g=k),k>h&&(h=k)}return new a.SubMesh(b,g,h-g+1,c,d,e,f)},b}();a.SubMesh=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(b){this.delayLoadState=a.Engine.DELAYLOADSTATE_NONE,this.hasAlpha=!1,this.getAlphaFromRGB=!1,this.level=1,this.isCube=!1,this.isRenderTarget=!1,this.animations=new Array,this.coordinatesIndex=0,this.coordinatesMode=a.Texture.EXPLICIT_MODE,this.wrapU=a.Texture.WRAP_ADDRESSMODE,this.wrapV=a.Texture.WRAP_ADDRESSMODE,this.anisotropicFilteringLevel=4,this._scene=b,this._scene.textures.push(this)}return b.prototype.getScene=function(){return this._scene},b.prototype.getTextureMatrix=function(){return null},b.prototype.getReflectionTextureMatrix=function(){return null},b.prototype.getInternalTexture=function(){return this._texture},b.prototype.isReady=function(){return this.delayLoadState===a.Engine.DELAYLOADSTATE_NOTLOADED?!0:this._texture?this._texture.isReady:!1},b.prototype.getSize=function(){return this._texture._width?{width:this._texture._width,height:this._texture._height}:this._texture._size?{width:this._texture._size,height:this._texture._size}:{width:0,height:0}},b.prototype.getBaseSize=function(){return this.isReady()?this._texture._size?{width:this._texture._size,height:this._texture._size}:{width:this._texture._baseWidth,height:this._texture._baseHeight}:{width:0,height:0}},b.prototype._getFromCache=function(a,b){for(var c=this._scene.getEngine().getLoadedTexturesCache(),d=0;d=0&&this._scene.textures.splice(a,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDispose&&this.onDispose())},b}();a.BaseTexture=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(b,c){this.index=b,this._opaqueSubMeshes=new a.SmartArray(256),this._transparentSubMeshes=new a.SmartArray(256),this._alphaTestSubMeshes=new a.SmartArray(256),this._scene=c}return b.prototype.render=function(b,c){if(b)return b(this._opaqueSubMeshes,this._alphaTestSubMeshes,this._transparentSubMeshes,c),!0;if(0===this._opaqueSubMeshes.length&&0===this._alphaTestSubMeshes.length&&0===this._transparentSubMeshes.length)return!1;var d,e,f=this._scene.getEngine();for(d=0;db._distanceToCamera?-1:0}),f.setAlphaMode(a.Engine.ALPHA_COMBINE),d=0;d0||c.visibility<1)&&this._transparentSubMeshes.push(a):b.needAlphaTesting()?this._alphaTestSubMeshes.push(a):this._opaqueSubMeshes.push(a)},b}();a.RenderingGroup=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(a){this._renderingGroups=new Array,this._scene=a}return b.prototype._renderParticles=function(a,b){if(0!==this._scene._activeParticleSystems.length){for(var c=(new Date).getTime(),d=0;d 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n float shadow = unpack(texture2D(shadowSampler, uv));\n\n if (depth.z > shadow)\n {\n return darkness;\n }\n return 1.;\n}\n\nfloat computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n float visibility = 1.;\n\n vec2 poissonDisk[4];\n poissonDisk[0] = vec2(-0.94201624, -0.39906216);\n poissonDisk[1] = vec2(0.94558609, -0.76890725);\n poissonDisk[2] = vec2(-0.094184101, -0.92938870);\n poissonDisk[3] = vec2(0.34495938, 0.29387760);\n\n // Poisson Sampling\n for (int i = 0; i<4; i++){\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[i] / 1500.0)) < depth.z){\n visibility -= 0.2;\n }\n }\n return visibility;\n}\n\n// Thanks to http://devmaster.net/\nfloat ChebychevInequality(vec2 moments, float t)\n{\n if (t <= moments.x)\n {\n return 1.0;\n }\n\n float variance = moments.y - (moments.x * moments.x);\n variance = max(variance, 0.);\n\n float d = t - moments.x;\n return variance / (variance + d * d);\n}\n\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n vec4 texel = texture2D(shadowSampler, uv);\n\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\n return clamp(1.3 - ChebychevInequality(moments, depth.z), 0., 1.0);\n}\n#endif\n\n// Bump\n#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform sampler2D bumpSampler;\n\n// Thanks to http://www.thetenthplanet.de/archives/1180\nmat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv)\n{\n // get edge vectors of the pixel triangle\n vec3 dp1 = dFdx(p);\n vec3 dp2 = dFdy(p);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n\n // solve the linear system\n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y;\n\n // construct a scale-invariant frame \n float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal)));\n return mat3(tangent * invmax, binormal * invmax, normal);\n}\n\nvec3 perturbNormal(vec3 viewDir)\n{\n vec3 map = texture2D(bumpSampler, vBumpUV).xyz * vBumpInfos.y;\n map = map * 255. / 127. - 128. / 127.;\n mat3 TBN = cotangent_frame(vNormalW, -viewDir, vBumpUV);\n return normalize(TBN * map);\n}\n#endif\n\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\n// Fog\n#ifdef FOG\n\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\n\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\n\nfloat CalcFogFactor()\n{\n float fogCoeff = 1.0;\n float fogStart = vFogInfos.y;\n float fogEnd = vFogInfos.z;\n float fogDensity = vFogInfos.w;\n\n if (FOGMODE_LINEAR == vFogInfos.x)\n {\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\n }\n else if (FOGMODE_EXP == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\n }\n else if (FOGMODE_EXP2 == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\n }\n\n return clamp(fogCoeff, 0.0, 1.0);\n}\n#endif\n\n// Light Computing\nstruct lightingInfo\n{\n vec3 diffuse;\n vec3 specular;\n};\n\nlightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, float range) {\n lightingInfo result;\n\n vec3 lightVectorW;\n float attenuation = 1.0;\n if (lightData.w == 0.)\n {\n vec3 direction = lightData.xyz - vPositionW;\n\n attenuation = max(0., 1.0 - length(direction) / range);\n lightVectorW = normalize(direction);\n }\n else\n {\n lightVectorW = normalize(-lightData.xyz);\n }\n\n // diffuse\n float ndl = max(0., dot(vNormal, lightVectorW));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = pow(specComp, max(1., vSpecularColor.a));\n\n result.diffuse = ndl * diffuseColor * attenuation;\n result.specular = specComp * specularColor * attenuation;\n\n return result;\n}\n\nlightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor, float range) {\n lightingInfo result;\n\n vec3 direction = lightData.xyz - vPositionW;\n vec3 lightVectorW = normalize(direction);\n float attenuation = max(0., 1.0 - length(direction) / range);\n\n // diffuse\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\n float spotAtten = 0.0;\n\n if (cosAngle >= lightDirection.w)\n {\n cosAngle = max(0., pow(cosAngle, lightData.w));\n spotAtten = max(0., (cosAngle - lightDirection.w) / (1. - cosAngle));\n\n // Diffuse\n float ndl = max(0., dot(vNormal, -lightDirection.xyz));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result.diffuse = ndl * spotAtten * diffuseColor * attenuation;\n result.specular = specComp * specularColor * spotAtten * attenuation;\n\n return result;\n }\n\n result.diffuse = vec3(0.);\n result.specular = vec3(0.);\n\n return result;\n}\n\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor) {\n lightingInfo result;\n\n // Diffuse\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result.diffuse = mix(groundColor, diffuseColor, ndl);\n result.specular = specComp * specularColor;\n\n return result;\n}\n\nvoid main(void) {\n // Clip plane\n#ifdef CLIPPLANE\n if (fClipDistance > 0.0)\n discard;\n#endif\n\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\n\n // Base color\n vec4 baseColor = vec4(1., 1., 1., 1.);\n vec3 diffuseColor = vDiffuseColor.rgb;\n\n // Alpha\n float alpha = vDiffuseColor.a;\n\n#ifdef VERTEXCOLOR\n diffuseColor *= vColor;\n#endif\n\n#ifdef DIFFUSE\n baseColor = texture2D(diffuseSampler, vDiffuseUV);\n\n#ifdef ALPHATEST\n if (baseColor.a < 0.4)\n discard;\n#endif\n\n#ifdef ALPHAFROMDIFFUSE\n alpha *= baseColor.a;\n#endif\n\n baseColor.rgb *= vDiffuseInfos.y;\n#endif\n\n // Bump\n vec3 normalW = normalize(vNormalW);\n\n#ifdef BUMP\n normalW = perturbNormal(viewDirectionW);\n#endif\n\n // Ambient color\n vec3 baseAmbientColor = vec3(1., 1., 1.);\n\n#ifdef AMBIENT\n baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\n#endif\n\n // Lighting\n vec3 diffuseBase = vec3(0., 0., 0.);\n vec3 specularBase = vec3(0., 0., 0.);\n float shadow = 1.;\n\n#ifdef LIGHT0\n#ifdef SPOTLIGHT0\n lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a);\n#endif\n#ifdef HEMILIGHT0\n lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightGround0);\n#endif\n#ifdef POINTDIRLIGHT0\n lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a);\n#endif\n#ifdef SHADOW0\n#ifdef SHADOWVSM0\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);\n#else\n #ifdef SHADOWPCF0\n shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0);\n #else\n shadow = computeShadow(vPositionFromLight0, shadowSampler0, darkness0);\n #endif\n#endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n specularBase += info.specular * shadow;\n#endif\n\n#ifdef LIGHT1\n#ifdef SPOTLIGHT1\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a);\n#endif\n#ifdef HEMILIGHT1\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightGround1);\n#endif\n#ifdef POINTDIRLIGHT1\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a);\n#endif\n#ifdef SHADOW1\n#ifdef SHADOWVSM1\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);\n#else\n #ifdef SHADOWPCF1\n shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1);\n #else\n shadow = computeShadow(vPositionFromLight1, shadowSampler1, darkness1);\n #endif\n#endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n specularBase += info.specular * shadow;\n#endif\n\n#ifdef LIGHT2\n#ifdef SPOTLIGHT2\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a);\n#endif\n#ifdef HEMILIGHT2\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightGround2);\n#endif\n#ifdef POINTDIRLIGHT2\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a);\n#endif\n#ifdef SHADOW2\n#ifdef SHADOWVSM2\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);\n#else\n #ifdef SHADOWPCF2\n shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2);\n #else\n shadow = computeShadow(vPositionFromLight2, shadowSampler2, darkness2);\n #endif \n#endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n specularBase += info.specular * shadow;\n#endif\n\n#ifdef LIGHT3\n#ifdef SPOTLIGHT3\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a);\n#endif\n#ifdef HEMILIGHT3\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightGround3);\n#endif\n#ifdef POINTDIRLIGHT3\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a);\n#endif\n#ifdef SHADOW3\n#ifdef SHADOWVSM3\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);\n#else\n #ifdef SHADOWPCF3\n shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3);\n #else\n shadow = computeShadow(vPositionFromLight3, shadowSampler3, darkness3);\n #endif \n#endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n specularBase += info.specular * shadow;\n#endif\n\n // Reflection\n vec3 reflectionColor = vec3(0., 0., 0.);\n\n#ifdef REFLECTION\n vec3 vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), normalW);\n\n if (vReflectionInfos.z != 0.0)\n {\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y * shadow;\n }\n else\n {\n vec2 coords = vReflectionUVW.xy;\n\n if (vReflectionInfos.x == MAP_PROJECTION)\n {\n coords /= vReflectionUVW.z;\n }\n\n coords.y = 1.0 - coords.y;\n\n reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y * shadow;\n }\n#endif\n\n#ifdef OPACITY\n vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);\n\n#ifdef OPACITYRGB\n opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);\n alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\n#else\n alpha *= opacityMap.a * vOpacityInfos.y;\n#endif\n\n\n#endif\n\n // Emissive\n vec3 emissiveColor = vEmissiveColor;\n#ifdef EMISSIVE\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\n#endif\n\n // Specular map\n vec3 specularColor = vSpecularColor.rgb;\n#ifdef SPECULAR\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\n#endif\n\n // Composition\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\n vec3 finalSpecular = specularBase * specularColor;\n\n vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\n\n#ifdef FOG\n float fog = CalcFogFactor();\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\n#endif\n\n gl_FragColor = color;\n}",defaultVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attributes\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec3 color;\n#endif\n#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\n// Uniforms\n\n#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif\n\nuniform mat4 view;\nuniform mat4 viewProjection;\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n\n#ifdef SPECULAR\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n\n#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n\n#ifdef BONES\nuniform mat4 mBones[BonesPerMesh];\n#endif\n\n// Output\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef VERTEXCOLOR\nvarying vec3 vColor;\n#endif\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n\n#ifdef FOG\nvarying float fFogDistance;\n#endif\n\n#ifdef SHADOWS\n#ifdef LIGHT0\nuniform mat4 lightMatrix0;\nvarying vec4 vPositionFromLight0;\n#endif\n#ifdef LIGHT1\nuniform mat4 lightMatrix1;\nvarying vec4 vPositionFromLight1;\n#endif\n#ifdef LIGHT2\nuniform mat4 lightMatrix2;\nvarying vec4 vPositionFromLight2;\n#endif\n#ifdef LIGHT3\nuniform mat4 lightMatrix3;\nvarying vec4 vPositionFromLight3;\n#endif\n#endif\n\n#ifdef REFLECTION\nvarying vec3 vPositionUVW;\n#endif\n\nvoid main(void) {\n mat4 finalWorld;\n\n#ifdef REFLECTION\n vPositionUVW = position;\n#endif \n\n#ifdef BONES\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\n\n#ifdef BONES4\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\n finalWorld = world * (m0 + m1 + m2 + m3);\n#else\n finalWorld = world * (m0 + m1 + m2);\n#endif \n\n#else\n#ifdef INSTANCES\n finalWorld = mat4(world0, world1, world2, world3);\n#else\n finalWorld = world;\n#endif\n#endif\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\n\n vec4 worldPos = finalWorld * vec4(position, 1.0);\n vPositionW = vec3(worldPos);\n vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\n\n // Texture coordinates\n#ifndef UV1\n vec2 uv = vec2(0., 0.);\n#endif\n#ifndef UV2\n vec2 uv2 = vec2(0., 0.);\n#endif\n\n#ifdef DIFFUSE\n if (vDiffuseInfos.x == 0.)\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef AMBIENT\n if (vAmbientInfos.x == 0.)\n {\n vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef OPACITY\n if (vOpacityInfos.x == 0.)\n {\n vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef EMISSIVE\n if (vEmissiveInfos.x == 0.)\n {\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef SPECULAR\n if (vSpecularInfos.x == 0.)\n {\n vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef BUMP\n if (vBumpInfos.x == 0.)\n {\n vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n // Clip plane\n#ifdef CLIPPLANE\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n\n // Fog\n#ifdef FOG\n fFogDistance = (view * worldPos).z;\n#endif\n\n // Shadows\n#ifdef SHADOWS\n#ifdef LIGHT0\n vPositionFromLight0 = lightMatrix0 * worldPos;\n#endif\n#ifdef LIGHT1\n vPositionFromLight1 = lightMatrix1 * worldPos;\n#endif\n#ifdef LIGHT2\n vPositionFromLight2 = lightMatrix2 * worldPos;\n#endif\n#ifdef LIGHT3\n vPositionFromLight3 = lightMatrix3 * worldPos;\n#endif\n#endif\n\n // Vertex color\n#ifdef VERTEXCOLOR\n vColor = color;\n#endif\n}",displayPassPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D passSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(passSampler, vUV);\n}",filterPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform mat4 kernelMatrix;\n\nvoid main(void)\n{\n vec3 baseColor = texture2D(textureSampler, vUV).rgb;\n vec3 updatedColor = (kernelMatrix * vec4(baseColor, 1.0)).rgb;\n\n gl_FragColor = vec4(updatedColor, 1.0);\n}",fxaaPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n#define FXAA_REDUCE_MIN (1.0/128.0)\n#define FXAA_REDUCE_MUL (1.0/8.0)\n#define FXAA_SPAN_MAX 8.0\n\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 texelSize;\n\nvoid main(){\n vec2 localTexelSize = texelSize;\n vec4 rgbNW = texture2D(textureSampler, (vUV + vec2(-1.0, -1.0) * localTexelSize));\n vec4 rgbNE = texture2D(textureSampler, (vUV + vec2(1.0, -1.0) * localTexelSize));\n vec4 rgbSW = texture2D(textureSampler, (vUV + vec2(-1.0, 1.0) * localTexelSize));\n vec4 rgbSE = texture2D(textureSampler, (vUV + vec2(1.0, 1.0) * localTexelSize));\n vec4 rgbM = texture2D(textureSampler, vUV);\n vec4 luma = vec4(0.299, 0.587, 0.114, 1.0);\n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\n vec2 dir = vec2(-((lumaNW + lumaNE) - (lumaSW + lumaSE)), ((lumaNW + lumaSW) - (lumaNE + lumaSE)));\n\n float dirReduce = max(\n (lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),\n FXAA_REDUCE_MIN);\n\n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * localTexelSize;\n\n vec4 rgbA = 0.5 * (\n texture2D(textureSampler, vUV + dir * (1.0 / 3.0 - 0.5)) +\n texture2D(textureSampler, vUV + dir * (2.0 / 3.0 - 0.5)));\n\n vec4 rgbB = rgbA * 0.5 + 0.25 * (\n texture2D(textureSampler, vUV + dir * -0.5) +\n texture2D(textureSampler, vUV + dir * 0.5));\n float lumaB = dot(rgbB, luma);\n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = rgbA;\n }\n else {\n gl_FragColor = rgbB;\n }\n}",layerPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\n// Color\nuniform vec4 color;\n\nvoid main(void) {\n vec4 baseColor = texture2D(textureSampler, vUV);\n\n gl_FragColor = baseColor * color;\n}",layerVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attributes\nattribute vec2 position;\n\n// Uniforms\nuniform mat4 textureMatrix;\n\n// Output\nvarying vec2 vUV;\n\nconst vec2 madd = vec2(0.5, 0.5);\n\nvoid main(void) { \n\n vUV = vec2(textureMatrix * vec4(position * madd + madd, 1.0, 0.0));\n gl_Position = vec4(position, 0.0, 1.0);\n}",legacydefaultPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n#define MAP_PROJECTION 4.\n\n// Constants\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vDiffuseColor;\nuniform vec4 vSpecularColor;\nuniform vec3 vEmissiveColor;\n\n// Input\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef VERTEXCOLOR\nvarying vec3 vColor;\n#endif\n\n// Lights\n#ifdef LIGHT0\nuniform vec4 vLightData0;\nuniform vec4 vLightDiffuse0;\nuniform vec3 vLightSpecular0;\n#ifdef SHADOW0\nvarying vec4 vPositionFromLight0;\nuniform sampler2D shadowSampler0;\n#endif\n#ifdef SPOTLIGHT0\nuniform vec4 vLightDirection0;\n#endif\n#ifdef HEMILIGHT0\nuniform vec3 vLightGround0;\n#endif\n#endif\n\n#ifdef LIGHT1\nuniform vec4 vLightData1;\nuniform vec4 vLightDiffuse1;\nuniform vec3 vLightSpecular1;\n#ifdef SHADOW1\nvarying vec4 vPositionFromLight1;\nuniform sampler2D shadowSampler1;\n#endif\n#ifdef SPOTLIGHT1\nuniform vec4 vLightDirection1;\n#endif\n#ifdef HEMILIGHT1\nuniform vec3 vLightGround1;\n#endif\n#endif\n\n#ifdef LIGHT2\nuniform vec4 vLightData2;\nuniform vec4 vLightDiffuse2;\nuniform vec3 vLightSpecular2;\n#ifdef SHADOW2\nvarying vec4 vPositionFromLight2;\nuniform sampler2D shadowSampler2;\n#endif\n#ifdef SPOTLIGHT2\nuniform vec4 vLightDirection2;\n#endif\n#ifdef HEMILIGHT2\nuniform vec3 vLightGround2;\n#endif\n#endif\n\n#ifdef LIGHT3\nuniform vec4 vLightData3;\nuniform vec4 vLightDiffuse3;\nuniform vec3 vLightSpecular3;\n#ifdef SHADOW3\nvarying vec4 vPositionFromLight3;\nuniform sampler2D shadowSampler3;\n#endif\n#ifdef SPOTLIGHT3\nuniform vec4 vLightDirection3;\n#endif\n#ifdef HEMILIGHT3\nuniform vec3 vLightGround3;\n#endif\n#endif\n\n// Samplers\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n\n#ifdef REFLECTION\nvarying vec3 vReflectionUVW;\nuniform samplerCube reflectionCubeSampler;\nuniform sampler2D reflection2DSampler;\nuniform vec3 vReflectionInfos;\n#endif\n\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n\n#ifdef SPECULAR\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform sampler2D specularSampler;\n#endif\n\n// Shadows\n#ifdef SHADOWS\n\nfloat unpack(vec4 color)\n{\n const vec4 bitShift = vec4(1. / (255. * 255. * 255.), 1. / (255. * 255.), 1. / 255., 1.);\n return dot(color, bitShift);\n}\n\nfloat unpackHalf(vec2 color)\n{\n return color.x + (color.y / 255.0);\n}\n\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n float shadow = unpack(texture2D(shadowSampler, uv));\n\n if (depth.z > shadow)\n {\n return 0.;\n }\n return 1.;\n}\n\n// Thanks to http://devmaster.net/\nfloat ChebychevInequality(vec2 moments, float t)\n{\n if (t <= moments.x)\n {\n return 1.0;\n }\n\n float variance = moments.y - (moments.x * moments.x);\n variance = max(variance, 0.);\n\n float d = t - moments.x;\n return variance / (variance + d * d);\n}\n\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n vec4 texel = texture2D(shadowSampler, uv);\n\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\n return clamp(1.3 - ChebychevInequality(moments, depth.z), 0., 1.0);\n}\n#endif\n\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\n// Fog\n#ifdef FOG\n\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\n\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\n\nfloat CalcFogFactor()\n{\n float fogCoeff = 1.0;\n float fogStart = vFogInfos.y;\n float fogEnd = vFogInfos.z;\n float fogDensity = vFogInfos.w;\n\n if (FOGMODE_LINEAR == vFogInfos.x)\n {\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\n }\n else if (FOGMODE_EXP == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\n }\n else if (FOGMODE_EXP2 == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\n }\n\n return clamp(fogCoeff, 0.0, 1.0);\n}\n#endif\n\n// Light Computing\nmat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor) {\n mat3 result;\n\n vec3 lightVectorW;\n if (lightData.w == 0.)\n {\n lightVectorW = normalize(lightData.xyz - vPositionW);\n }\n else\n {\n lightVectorW = normalize(-lightData.xyz);\n }\n\n // diffuse\n float ndl = max(0., dot(vNormal, lightVectorW));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = max(0., pow(specComp, max(1.0, vSpecularColor.a)));\n\n result[0] = ndl * diffuseColor.rgb;\n result[1] = specComp * specularColor;\n result[2] = vec3(0.);\n\n return result;\n}\n\nmat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec4 diffuseColor, vec3 specularColor) {\n mat3 result;\n\n vec3 lightVectorW = normalize(lightData.xyz - vPositionW);\n\n // diffuse\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\n float spotAtten = 0.0;\n\n if (cosAngle >= lightDirection.w)\n {\n cosAngle = max(0., pow(cosAngle, lightData.w));\n spotAtten = max(0., (cosAngle - lightDirection.w) / (1. - cosAngle));\n\n // Diffuse\n float ndl = max(0., dot(vNormal, -lightDirection.xyz));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result[0] = ndl * spotAtten * diffuseColor.rgb;\n result[1] = specComp * specularColor * spotAtten;\n result[2] = vec3(0.);\n\n return result;\n }\n\n result[0] = vec3(0.);\n result[1] = vec3(0.);\n result[2] = vec3(0.);\n\n return result;\n}\n\nmat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor, vec3 groundColor) {\n mat3 result;\n\n // Diffuse\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result[0] = mix(groundColor, diffuseColor.rgb, ndl);\n result[1] = specComp * specularColor;\n result[2] = vec3(0.);\n\n return result;\n}\n\nvoid main(void) {\n // Clip plane\n#ifdef CLIPPLANE\n if (fClipDistance > 0.0)\n discard;\n#endif\n\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\n\n // Base color\n vec4 baseColor = vec4(1., 1., 1., 1.);\n vec3 diffuseColor = vDiffuseColor.rgb;\n\n#ifdef VERTEXCOLOR\n diffuseColor *= vColor;\n#endif\n\n#ifdef DIFFUSE\n baseColor = texture2D(diffuseSampler, vDiffuseUV);\n\n#ifdef ALPHATEST\n if (baseColor.a < 0.4)\n discard;\n#endif\n\n baseColor.rgb *= vDiffuseInfos.y;\n#endif\n\n // Bump\n vec3 normalW = normalize(vNormalW);\n\n // Ambient color\n vec3 baseAmbientColor = vec3(1., 1., 1.);\n\n#ifdef AMBIENT\n baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\n#endif\n\n // Lighting\n vec3 diffuseBase = vec3(0., 0., 0.);\n vec3 specularBase = vec3(0., 0., 0.);\n float shadow = 1.;\n\n#ifdef LIGHT0\n#ifdef SPOTLIGHT0\n mat3 info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0, vLightSpecular0);\n#endif\n#ifdef HEMILIGHT0\n mat3 info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0, vLightGround0);\n#endif\n#ifdef POINTDIRLIGHT0\n mat3 info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0);\n#endif\n#ifdef SHADOW0\n#ifdef SHADOWVSM0\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);\n#else\n shadow = computeShadow(vPositionFromLight0, shadowSampler0);\n#endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info[0] * shadow;\n specularBase += info[1] * shadow;\n#endif\n\n#ifdef LIGHT1\n#ifdef SPOTLIGHT1\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1, vLightSpecular1);\n#endif\n#ifdef HEMILIGHT1\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1, vLightGround1);\n#endif\n#ifdef POINTDIRLIGHT1\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1);\n#endif\n#ifdef SHADOW1\n#ifdef SHADOWVSM1\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);\n#else\n shadow = computeShadow(vPositionFromLight1, shadowSampler1);\n#endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info[0] * shadow;\n specularBase += info[1] * shadow;\n#endif\n\n#ifdef LIGHT2\n#ifdef SPOTLIGHT2\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2, vLightSpecular2);\n#endif\n#ifdef HEMILIGHT2\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2, vLightGround2);\n#endif\n#ifdef POINTDIRLIGHT2\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2);\n#endif\n#ifdef SHADOW2\n#ifdef SHADOWVSM2\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);\n#else\n shadow = computeShadow(vPositionFromLight2, shadowSampler2);\n#endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info[0] * shadow;\n specularBase += info[1] * shadow;\n#endif\n\n#ifdef LIGHT3\n#ifdef SPOTLIGHT3\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3, vLightSpecular3);\n#endif\n#ifdef HEMILIGHT3\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3, vLightGround3);\n#endif\n#ifdef POINTDIRLIGHT3\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3);\n#endif\n#ifdef SHADOW3\n#ifdef SHADOWVSM3\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);\n#else\n shadow = computeShadow(vPositionFromLight3, shadowSampler3);\n#endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info[0] * shadow;\n specularBase += info[1] * shadow;\n#endif\n\n // Reflection\n vec3 reflectionColor = vec3(0., 0., 0.);\n\n#ifdef REFLECTION\n if (vReflectionInfos.z != 0.0)\n {\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y;\n }\n else\n {\n vec2 coords = vReflectionUVW.xy;\n\n if (vReflectionInfos.x == MAP_PROJECTION)\n {\n coords /= vReflectionUVW.z;\n }\n\n coords.y = 1.0 - coords.y;\n\n reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y;\n }\n#endif\n\n // Alpha\n float alpha = vDiffuseColor.a;\n\n#ifdef OPACITY\n vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);\n#ifdef OPACITYRGB\n opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);\n alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\n#else\n alpha *= opacityMap.a * vOpacityInfos.y;\n#endif\n#endif\n\n // Emissive\n vec3 emissiveColor = vEmissiveColor;\n#ifdef EMISSIVE\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\n#endif\n\n // Specular map\n vec3 specularColor = vSpecularColor.rgb;\n#ifdef SPECULAR\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\n#endif\n\n // Composition\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\n vec3 finalSpecular = specularBase * specularColor;\n\n vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\n\n#ifdef FOG\n float fog = CalcFogFactor();\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\n#endif\n\n gl_FragColor = color;\n}",legacydefaultVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n#define MAP_EXPLICIT 0.\n#define MAP_SPHERICAL 1.\n#define MAP_PLANAR 2.\n#define MAP_CUBIC 3.\n#define MAP_PROJECTION 4.\n#define MAP_SKYBOX 5.\n\n// Attributes\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec3 color;\n#endif\n#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec3 vEyePosition;\nvarying vec3 vReflectionUVW;\nuniform vec3 vReflectionInfos;\nuniform mat4 reflectionMatrix;\n#endif\n\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n\n#ifdef SPECULAR\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n\n#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n\n#ifdef BONES\nuniform mat4 mBones[BonesPerMesh];\n#endif\n\n// Output\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef VERTEXCOLOR\nvarying vec3 vColor;\n#endif\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n\n#ifdef FOG\nvarying float fFogDistance;\n#endif\n\n#ifdef SHADOWS\n#ifdef LIGHT0\nuniform mat4 lightMatrix0;\nvarying vec4 vPositionFromLight0;\n#endif\n#ifdef LIGHT1\nuniform mat4 lightMatrix1;\nvarying vec4 vPositionFromLight1;\n#endif\n#ifdef LIGHT2\nuniform mat4 lightMatrix2;\nvarying vec4 vPositionFromLight2;\n#endif\n#ifdef LIGHT3\nuniform mat4 lightMatrix3;\nvarying vec4 vPositionFromLight3;\n#endif\n#endif\n\n#ifdef REFLECTION\nvec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)\n{\n if (mode == MAP_SPHERICAL)\n {\n vec3 coords = vec3(view * vec4(worldNormal, 0.0));\n\n return vec3(reflectionMatrix * vec4(coords, 1.0));\n }\n else if (mode == MAP_PLANAR)\n {\n vec3 viewDir = worldPos.xyz - vEyePosition;\n vec3 coords = normalize(reflect(viewDir, worldNormal));\n\n return vec3(reflectionMatrix * vec4(coords, 1));\n }\n else if (mode == MAP_CUBIC)\n {\n vec3 viewDir = worldPos.xyz - vEyePosition;\n vec3 coords = reflect(viewDir, worldNormal);\n\n return vec3(reflectionMatrix * vec4(coords, 0));\n }\n else if (mode == MAP_PROJECTION)\n {\n return vec3(reflectionMatrix * (view * worldPos));\n }\n else if (mode == MAP_SKYBOX)\n {\n return position;\n }\n\n return vec3(0, 0, 0);\n}\n#endif\n\nvoid main(void) {\n mat4 finalWorld;\n\n#ifdef BONES\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\n\n#ifdef BONES4\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\n finalWorld = world * (m0 + m1 + m2 + m3);\n#else\n finalWorld = world * (m0 + m1 + m2);\n#endif \n\n#else\n finalWorld = world;\n#endif\n\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\n\n vec4 worldPos = finalWorld * vec4(position, 1.0);\n vPositionW = vec3(worldPos);\n vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\n\n // Texture coordinates\n#ifndef UV1\n vec2 uv = vec2(0., 0.);\n#endif\n#ifndef UV2\n vec2 uv2 = vec2(0., 0.);\n#endif\n\n#ifdef DIFFUSE\n if (vDiffuseInfos.x == 0.)\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef AMBIENT\n if (vAmbientInfos.x == 0.)\n {\n vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef OPACITY\n if (vOpacityInfos.x == 0.)\n {\n vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef REFLECTION\n vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), vNormalW);\n#endif\n\n#ifdef EMISSIVE\n if (vEmissiveInfos.x == 0.)\n {\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef SPECULAR\n if (vSpecularInfos.x == 0.)\n {\n vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef BUMP\n if (vBumpInfos.x == 0.)\n {\n vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n // Clip plane\n#ifdef CLIPPLANE\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n\n // Fog\n#ifdef FOG\n fFogDistance = (view * worldPos).z;\n#endif\n\n // Shadows\n#ifdef SHADOWS\n#ifdef LIGHT0\n vPositionFromLight0 = lightMatrix0 * worldPos;\n#endif\n#ifdef LIGHT1\n vPositionFromLight1 = lightMatrix1 * worldPos;\n#endif\n#ifdef LIGHT2\n vPositionFromLight2 = lightMatrix2 * worldPos;\n#endif\n#ifdef LIGHT3\n vPositionFromLight3 = lightMatrix3 * worldPos;\n#endif\n#endif\n\n // Vertex color\n#ifdef VERTEXCOLOR\n vColor = color;\n#endif\n}",lensFlarePixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\n// Color\nuniform vec4 color;\n\nvoid main(void) {\n vec4 baseColor = texture2D(textureSampler, vUV);\n\n gl_FragColor = baseColor * color;\n}",lensFlareVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attributes\nattribute vec2 position;\n\n// Uniforms\nuniform mat4 viewportMatrix;\n\n// Output\nvarying vec2 vUV;\n\nconst vec2 madd = vec2(0.5, 0.5);\n\nvoid main(void) { \n\n vUV = position * madd + madd;\n gl_Position = viewportMatrix * vec4(position, 0.0, 1.0);\n}",oculusDistortionCorrectionPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 LensCenter;\nuniform vec2 Scale;\nuniform vec2 ScaleIn;\nuniform vec4 HmdWarpParam;\n\nvec2 HmdWarp(vec2 in01) {\n\n vec2 theta = (in01 - LensCenter) * ScaleIn; // Scales to [-1, 1]\n float rSq = theta.x * theta.x + theta.y * theta.y;\n vec2 rvector = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);\n return LensCenter + Scale * rvector;\n}\n\n\n\nvoid main(void)\n{\n vec2 tc = HmdWarp(vUV);\n if (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n else{\n gl_FragColor = vec4(texture2D(textureSampler, tc).rgb, 1.0);\n }\n}",particlesPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nvarying vec4 vColor;\nuniform vec4 textureMask;\nuniform sampler2D diffuseSampler;\n\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\nvoid main(void) {\n#ifdef CLIPPLANE\n if (fClipDistance > 0.0)\n discard;\n#endif\n vec4 baseColor = texture2D(diffuseSampler, vUV);\n\n gl_FragColor = (baseColor * textureMask + (vec4(1., 1., 1., 1.) - textureMask)) * vColor;\n}",particlesVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attributes\nattribute vec3 position;\nattribute vec4 color;\nattribute vec4 options;\n\n// Uniforms\nuniform mat4 view;\nuniform mat4 projection;\n\n// Output\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nuniform mat4 invView;\nvarying float fClipDistance;\n#endif\n\nvoid main(void) { \n vec3 viewPos = (view * vec4(position, 1.0)).xyz; \n vec3 cornerPos;\n float size = options.y;\n float angle = options.x;\n vec2 offset = options.zw;\n\n cornerPos = vec3(offset.x - 0.5, offset.y - 0.5, 0.) * size;\n\n // Rotate\n vec3 rotatedCorner;\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\n rotatedCorner.z = 0.;\n\n // Position\n viewPos += rotatedCorner;\n gl_Position = projection * vec4(viewPos, 1.0); \n \n vColor = color;\n vUV = offset;\n\n // Clip plane\n#ifdef CLIPPLANE\n vec4 worldPos = invView * vec4(viewPos, 1.0);\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n}",passPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nvoid main(void) \n{\n gl_FragColor = texture2D(textureSampler, vUV);\n}",postprocessVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attributes\nattribute vec2 position;\n\n// Output\nvarying vec2 vUV;\n\nconst vec2 madd = vec2(0.5, 0.5);\n\nvoid main(void) { \n\n vUV = position * madd + madd;\n gl_Position = vec4(position, 0.0, 1.0);\n}",refractionPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D refractionSampler;\n\n// Parameters\nuniform vec3 baseColor;\nuniform float depth;\nuniform float colorLevel;\n\nvoid main() {\n float ref = 1.0 - texture2D(refractionSampler, vUV).r;\n\n vec2 uv = vUV - vec2(0.5);\n vec2 offset = uv * depth * ref;\n vec3 sourceColor = texture2D(textureSampler, vUV - offset).rgb;\n\n gl_FragColor = vec4(sourceColor + sourceColor * ref * colorLevel, 1.0);\n}",shadowMapPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\nvec4 pack(float depth)\n{\n const vec4 bitOffset = vec4(255. * 255. * 255., 255. * 255., 255., 1.);\n const vec4 bitMask = vec4(0., 1. / 255., 1. / 255., 1. / 255.);\n \n vec4 comp = mod(depth * bitOffset * vec4(254.), vec4(255.)) / vec4(254.);\n comp -= comp.xxyz * bitMask;\n \n return comp;\n}\n\n// Thanks to http://devmaster.net/\nvec2 packHalf(float depth) \n{ \n const vec2 bitOffset = vec2(1.0 / 255., 0.);\n vec2 color = vec2(depth, fract(depth * 255.));\n\n return color - (color.yy * bitOffset);\n}\n\n#ifndef VSM\nvarying vec4 vPosition;\n#endif\n\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n\nvoid main(void)\n{\n#ifdef ALPHATEST\n if (texture2D(diffuseSampler, vUV).a < 0.4)\n discard;\n#endif\n\n#ifdef VSM\n float moment1 = gl_FragCoord.z / gl_FragCoord.w;\n float moment2 = moment1 * moment1;\n gl_FragColor = vec4(packHalf(moment1), packHalf(moment2));\n#else\n gl_FragColor = pack(vPosition.z / vPosition.w);\n#endif\n}",shadowMapVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attribute\nattribute vec3 position;\n#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\n// Uniform\n#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif\n\nuniform mat4 viewProjection;\n#ifdef BONES\nuniform mat4 mBones[BonesPerMesh];\n#endif\n\n#ifndef VSM\nvarying vec4 vPosition;\n#endif\n\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n\nvoid main(void)\n{\n#ifdef INSTANCES\n mat4 finalWorld = mat4(world0, world1, world2, world3);\n#else\n mat4 finalWorld = world;\n#endif\n\n#ifdef BONES\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\n#else\n#ifndef VSM\n vPosition = viewProjection * finalWorld * vec4(position, 1.0);\n#endif\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\n#endif\n\n#ifdef ALPHATEST\n#ifdef UV1\n vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\n#endif\n#ifdef UV2\n vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\n#endif\n#endif\n}",spritesPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\nuniform bool alphaTest;\n\nvarying vec4 vColor;\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n\n// Fog\n#ifdef FOG\n\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\n\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\n\nfloat CalcFogFactor()\n{\n float fogCoeff = 1.0;\n float fogStart = vFogInfos.y;\n float fogEnd = vFogInfos.z;\n float fogDensity = vFogInfos.w;\n\n if (FOGMODE_LINEAR == vFogInfos.x)\n {\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\n }\n else if (FOGMODE_EXP == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\n }\n else if (FOGMODE_EXP2 == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\n }\n\n return min(1., max(0., fogCoeff));\n}\n#endif\n\n\nvoid main(void) {\n vec4 baseColor = texture2D(diffuseSampler, vUV);\n\n if (alphaTest) \n {\n if (baseColor.a < 0.95)\n discard;\n }\n\n baseColor *= vColor;\n\n#ifdef FOG\n float fog = CalcFogFactor();\n baseColor.rgb = fog * baseColor.rgb + (1.0 - fog) * vFogColor;\n#endif\n\n gl_FragColor = baseColor;\n}",spritesVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attributes\nattribute vec3 position;\nattribute vec4 options;\nattribute vec4 cellInfo;\nattribute vec4 color;\n\n// Uniforms\nuniform vec2 textureInfos;\nuniform mat4 view;\nuniform mat4 projection;\n\n// Output\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef FOG\nvarying float fFogDistance;\n#endif\n\nvoid main(void) { \n vec3 viewPos = (view * vec4(position, 1.0)).xyz; \n vec3 cornerPos;\n \n float angle = options.x;\n float size = options.y;\n vec2 offset = options.zw;\n vec2 uvScale = textureInfos.xy;\n\n cornerPos = vec3(offset.x - 0.5, offset.y - 0.5, 0.) * size;\n\n // Rotate\n vec3 rotatedCorner;\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\n rotatedCorner.z = 0.;\n\n // Position\n viewPos += rotatedCorner;\n gl_Position = projection * vec4(viewPos, 1.0); \n\n // Color\n vColor = color;\n \n // Texture\n vec2 uvOffset = vec2(abs(offset.x - cellInfo.x), 1.0 - abs(offset.y - cellInfo.y));\n\n vUV = (uvOffset + cellInfo.zw) * uvScale;\n\n // Fog\n#ifdef FOG\n fFogDistance = viewPos.z;\n#endif\n}"},b }();a.Effect=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function a(a,b,c){this.name=a,this.checkReadyOnEveryCall=!0,this.checkReadyOnlyOnce=!1,this.state="",this.alpha=1,this.wireframe=!1,this.backFaceCulling=!0,this._wasPreviouslyReady=!1,this.id=a,this._scene=b,c||b.materials.push(this)}return a.prototype.isReady=function(){return!0},a.prototype.getEffect=function(){return this._effect},a.prototype.getScene=function(){return this._scene},a.prototype.needAlphaBlending=function(){return this.alpha<1},a.prototype.needAlphaTesting=function(){return!1},a.prototype.getAlphaTestTexture=function(){return null},a.prototype.trackCreation=function(){},a.prototype._preBind=function(){var a=this._scene.getEngine();a.enableEffect(this._effect),a.setState(this.backFaceCulling)},a.prototype.bind=function(){},a.prototype.bindOnlyWorldMatrix=function(){},a.prototype.unbind=function(){},a.prototype.dispose=function(a){var b=this._scene.materials.indexOf(this);this._scene.materials.splice(b,1),a&&this._effect&&(this._scene.getEngine()._releaseEffect(this._effect),this._effect=null),this.onDispose&&this.onDispose()},a}();a.Material=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=4,c=function(c){function d(b,d){var e=this;c.call(this,b,d),this.ambientColor=new a.Color3(0,0,0),this.diffuseColor=new a.Color3(1,1,1),this.specularColor=new a.Color3(1,1,1),this.specularPower=64,this.emissiveColor=new a.Color3(0,0,0),this.useAlphaFromDiffuseTexture=!1,this._cachedDefines=null,this._renderTargets=new a.SmartArray(16),this._worldViewProjectionMatrix=a.Matrix.Zero(),this._globalAmbientColor=new a.Color3(0,0,0),this._baseColor=new a.Color3,this._scaledDiffuse=new a.Color3,this._scaledSpecular=new a.Color3,this.getRenderTargetTextures=function(){return e._renderTargets.reset(),e.reflectionTexture&&e.reflectionTexture.isRenderTarget&&e._renderTargets.push(e.reflectionTexture),e._renderTargets}}return __extends(d,c),d.prototype.needAlphaBlending=function(){return this.alpha<1||null!=this.opacityTexture||this._shouldUseAlphaFromDiffuseTexture()},d.prototype.needAlphaTesting=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha&&!this.diffuseTexture.getAlphaFromRGB},d.prototype._shouldUseAlphaFromDiffuseTexture=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha&&this.useAlphaFromDiffuseTexture},d.prototype.getAlphaTestTexture=function(){return this.diffuseTexture},d.prototype.isReady=function(c,d){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var e=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===e.getRenderId())return!0;var f=e.getEngine(),g=[],h=new Array;if(e.texturesEnabled){if(this.diffuseTexture&&a.StandardMaterial.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;g.push("#define DIFFUSE")}if(this.ambientTexture&&a.StandardMaterial.AmbientTextureEnabled){if(!this.ambientTexture.isReady())return!1;g.push("#define AMBIENT")}if(this.opacityTexture&&a.StandardMaterial.OpacityTextureEnabled){if(!this.opacityTexture.isReady())return!1;g.push("#define OPACITY"),this.opacityTexture.getAlphaFromRGB&&g.push("#define OPACITYRGB")}if(this.reflectionTexture&&a.StandardMaterial.ReflectionTextureEnabled){if(!this.reflectionTexture.isReady())return!1;g.push("#define REFLECTION")}if(this.emissiveTexture&&a.StandardMaterial.EmissiveTextureEnabled){if(!this.emissiveTexture.isReady())return!1;g.push("#define EMISSIVE")}if(this.specularTexture&&a.StandardMaterial.SpecularTextureEnabled){if(!this.specularTexture.isReady())return!1;g.push("#define SPECULAR"),h.push(g[g.length-1])}}if(e.getEngine().getCaps().standardDerivatives&&this.bumpTexture&&a.StandardMaterial.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;g.push("#define BUMP"),h.push(g[g.length-1])}e.clipPlane&&g.push("#define CLIPPLANE"),f.getAlphaTesting()&&g.push("#define ALPHATEST"),this._shouldUseAlphaFromDiffuseTexture()&&g.push("#define ALPHAFROMDIFFUSE"),e.fogMode!==a.Scene.FOGMODE_NONE&&(g.push("#define FOG"),h.push(g[g.length-1]));var i=!1,j=0;if(e.lightsEnabled)for(var k=0;k0){for(var m=0;m0&&h.push(g[g.length-1]);var o;o=l instanceof a.SpotLight?"#define SPOTLIGHT"+j:l instanceof a.HemisphericLight?"#define HEMILIGHT"+j:"#define POINTDIRLIGHT"+j,g.push(o),j>0&&h.push(g[g.length-1]);var p=l.getShadowGenerator();if(c&&c.receiveShadows&&p&&(g.push("#define SHADOW"+j),j>0&&h.push(g[g.length-1]),i||(g.push("#define SHADOWS"),i=!0),p.useVarianceShadowMap&&(g.push("#define SHADOWVSM"+j),j>0&&h.push(g[g.length-1])),p.usePoissonSampling&&(g.push("#define SHADOWPCF"+j),j>0&&h.push(g[g.length-1]))),j++,j==b)break}}}var q=[a.VertexBuffer.PositionKind,a.VertexBuffer.NormalKind];c&&(c.isVerticesDataPresent(a.VertexBuffer.UVKind)&&(q.push(a.VertexBuffer.UVKind),g.push("#define UV1")),c.isVerticesDataPresent(a.VertexBuffer.UV2Kind)&&(q.push(a.VertexBuffer.UV2Kind),g.push("#define UV2")),c.isVerticesDataPresent(a.VertexBuffer.ColorKind)&&(q.push(a.VertexBuffer.ColorKind),g.push("#define VERTEXCOLOR")),c.skeleton&&c.isVerticesDataPresent(a.VertexBuffer.MatricesIndicesKind)&&c.isVerticesDataPresent(a.VertexBuffer.MatricesWeightsKind)&&(q.push(a.VertexBuffer.MatricesIndicesKind),q.push(a.VertexBuffer.MatricesWeightsKind),g.push("#define BONES"),g.push("#define BonesPerMesh "+(c.skeleton.bones.length+1)),g.push("#define BONES4"),h.push(g[g.length-1])),d&&(g.push("#define INSTANCES"),q.push("world0"),q.push("world1"),q.push("world2"),q.push("world3")));var r=g.join("\n");if(this._cachedDefines!=r){this._cachedDefines=r;var s="default";e.getEngine().getCaps().standardDerivatives||(s="legacydefault"),this._effect=e.getEngine().createEffect(s,q,["world","view","viewProjection","vEyePosition","vLightsType","vAmbientColor","vDiffuseColor","vSpecularColor","vEmissiveColor","vLightData0","vLightDiffuse0","vLightSpecular0","vLightDirection0","vLightGround0","lightMatrix0","vLightData1","vLightDiffuse1","vLightSpecular1","vLightDirection1","vLightGround1","lightMatrix1","vLightData2","vLightDiffuse2","vLightSpecular2","vLightDirection2","vLightGround2","lightMatrix2","vLightData3","vLightDiffuse3","vLightSpecular3","vLightDirection3","vLightGround3","lightMatrix3","vFogInfos","vFogColor","vDiffuseInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vSpecularInfos","vBumpInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix","darkness0","darkness1","darkness2","darkness3"],["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],r,h,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=e.getRenderId(),this._wasPreviouslyReady=!0,!0):!1},d.prototype.unbind=function(){this.reflectionTexture&&this.reflectionTexture.isRenderTarget&&this._effect.setTexture("reflection2DSampler",null)},d.prototype.bindOnlyWorldMatrix=function(a){this._effect.setMatrix("world",a)},d.prototype.bind=function(c,d){var e=this.getScene();if(this._baseColor.copyFrom(this.diffuseColor),this.bindOnlyWorldMatrix(c),this._effect.setMatrix("viewProjection",e.getTransformMatrix()),d.skeleton&&d.isVerticesDataPresent(a.VertexBuffer.MatricesIndicesKind)&&d.isVerticesDataPresent(a.VertexBuffer.MatricesWeightsKind)&&this._effect.setMatrices("mBones",d.skeleton.getTransformMatrices()),this.diffuseTexture&&a.StandardMaterial.DiffuseTextureEnabled&&(this._effect.setTexture("diffuseSampler",this.diffuseTexture),this._effect.setFloat2("vDiffuseInfos",this.diffuseTexture.coordinatesIndex,this.diffuseTexture.level),this._effect.setMatrix("diffuseMatrix",this.diffuseTexture.getTextureMatrix()),this._baseColor.copyFromFloats(1,1,1)),this.ambientTexture&&a.StandardMaterial.AmbientTextureEnabled&&(this._effect.setTexture("ambientSampler",this.ambientTexture),this._effect.setFloat2("vAmbientInfos",this.ambientTexture.coordinatesIndex,this.ambientTexture.level),this._effect.setMatrix("ambientMatrix",this.ambientTexture.getTextureMatrix())),this.opacityTexture&&a.StandardMaterial.OpacityTextureEnabled&&(this._effect.setTexture("opacitySampler",this.opacityTexture),this._effect.setFloat2("vOpacityInfos",this.opacityTexture.coordinatesIndex,this.opacityTexture.level),this._effect.setMatrix("opacityMatrix",this.opacityTexture.getTextureMatrix())),this.reflectionTexture&&a.StandardMaterial.ReflectionTextureEnabled&&(this.reflectionTexture.isCube?this._effect.setTexture("reflectionCubeSampler",this.reflectionTexture):this._effect.setTexture("reflection2DSampler",this.reflectionTexture),this._effect.setMatrix("reflectionMatrix",this.reflectionTexture.getReflectionTextureMatrix()),this._effect.setFloat3("vReflectionInfos",this.reflectionTexture.coordinatesMode,this.reflectionTexture.level,this.reflectionTexture.isCube?1:0)),this.emissiveTexture&&a.StandardMaterial.EmissiveTextureEnabled&&(this._effect.setTexture("emissiveSampler",this.emissiveTexture),this._effect.setFloat2("vEmissiveInfos",this.emissiveTexture.coordinatesIndex,this.emissiveTexture.level),this._effect.setMatrix("emissiveMatrix",this.emissiveTexture.getTextureMatrix())),this.specularTexture&&a.StandardMaterial.SpecularTextureEnabled&&(this._effect.setTexture("specularSampler",this.specularTexture),this._effect.setFloat2("vSpecularInfos",this.specularTexture.coordinatesIndex,this.specularTexture.level),this._effect.setMatrix("specularMatrix",this.specularTexture.getTextureMatrix())),this.bumpTexture&&e.getEngine().getCaps().standardDerivatives&&a.StandardMaterial.BumpTextureEnabled&&(this._effect.setTexture("bumpSampler",this.bumpTexture),this._effect.setFloat2("vBumpInfos",this.bumpTexture.coordinatesIndex,this.bumpTexture.level),this._effect.setMatrix("bumpMatrix",this.bumpTexture.getTextureMatrix())),e.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),this._effect.setVector3("vEyePosition",e.activeCamera.position),this._effect.setColor3("vAmbientColor",this._globalAmbientColor),this._effect.setColor4("vDiffuseColor",this._baseColor,this.alpha*d.visibility),this._effect.setColor4("vSpecularColor",this.specularColor,this.specularPower),this._effect.setColor3("vEmissiveColor",this.emissiveColor),e.lightsEnabled)for(var f=0,g=0;g0&&a.push(this.diffuseTexture),this.ambientTexture&&this.ambientTexture.animations&&this.ambientTexture.animations.length>0&&a.push(this.ambientTexture),this.opacityTexture&&this.opacityTexture.animations&&this.opacityTexture.animations.length>0&&a.push(this.opacityTexture),this.reflectionTexture&&this.reflectionTexture.animations&&this.reflectionTexture.animations.length>0&&a.push(this.reflectionTexture),this.emissiveTexture&&this.emissiveTexture.animations&&this.emissiveTexture.animations.length>0&&a.push(this.emissiveTexture),this.specularTexture&&this.specularTexture.animations&&this.specularTexture.animations.length>0&&a.push(this.specularTexture),this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&a.push(this.bumpTexture),a},d.prototype.dispose=function(a){this.diffuseTexture&&this.diffuseTexture.dispose(),this.ambientTexture&&this.ambientTexture.dispose(),this.opacityTexture&&this.opacityTexture.dispose(),this.reflectionTexture&&this.reflectionTexture.dispose(),this.emissiveTexture&&this.emissiveTexture.dispose(),this.specularTexture&&this.specularTexture.dispose(),this.bumpTexture&&this.bumpTexture.dispose(),c.prototype.dispose.call(this,a)},d.prototype.clone=function(b){var c=new a.StandardMaterial(b,this.getScene());return c.checkReadyOnEveryCall=this.checkReadyOnEveryCall,c.alpha=this.alpha,c.wireframe=this.wireframe,c.backFaceCulling=this.backFaceCulling,this.diffuseTexture&&this.diffuseTexture.clone&&(c.diffuseTexture=this.diffuseTexture.clone()),this.ambientTexture&&this.ambientTexture.clone&&(c.ambientTexture=this.ambientTexture.clone()),this.opacityTexture&&this.opacityTexture.clone&&(c.opacityTexture=this.opacityTexture.clone()),this.reflectionTexture&&this.reflectionTexture.clone&&(c.reflectionTexture=this.reflectionTexture.clone()),this.emissiveTexture&&this.emissiveTexture.clone&&(c.emissiveTexture=this.emissiveTexture.clone()),this.specularTexture&&this.specularTexture.clone&&(c.specularTexture=this.specularTexture.clone()),this.bumpTexture&&this.bumpTexture.clone&&(c.bumpTexture=this.bumpTexture.clone()),c.ambientColor=this.ambientColor.clone(),c.diffuseColor=this.diffuseColor.clone(),c.specularColor=this.specularColor.clone(),c.specularPower=this.specularPower,c.emissiveColor=this.emissiveColor.clone(),c},d.DiffuseTextureEnabled=!0,d.AmbientTextureEnabled=!0,d.OpacityTextureEnabled=!0,d.ReflectionTextureEnabled=!0,d.EmissiveTextureEnabled=!0,d.SpecularTextureEnabled=!0,d.BumpTextureEnabled=!0,d}(a.Material);a.StandardMaterial=c}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(a){function b(b,c){a.call(this,b,c,!0),this.subMaterials=new Array,c.multiMaterials.push(this)}return __extends(b,a),b.prototype.getSubMaterial=function(a){return 0>a||a>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[a]},b.prototype.isReady=function(a){for(var b=0;b0&&(e.db.deleteObjectStore("scenes"),e.db.deleteObjectStore("versions"),e.db.deleteObjectStore("textures"));{e.db.createObjectStore("scenes",{keyPath:"sceneUrl"}),e.db.createObjectStore("versions",{keyPath:"sceneUrl"}),e.db.createObjectStore("textures",{keyPath:"textureUrl"})}}catch(c){a.Tools.Error("Error while creating object stores. Exception: "+c.message),d()}}}else this.isSupported=!1,c&&c()},b.prototype.loadImageFromDB=function(b,c){var d=this,e=a.Database.ReturnFullUrlLocation(b),f=function(){d.hasReachedQuota||null===d.db?c.src=b:d._saveImageIntoDBAsync(e,c)};this.mustUpdateRessources?f():this._loadImageFromDBAsync(e,c,f)},b.prototype._loadImageFromDBAsync=function(b,c,d){if(this.isSupported&&null!==this.db){var e,f=this.db.transaction(["textures"]);f.onabort=function(){c.src=b},f.oncomplete=function(){var f;if(e){var g=window.URL||window.webkitURL;f=g.createObjectURL(e.data,{oneTimeOnly:!0}),c.onerror=function(){a.Tools.Error("Error loading image from blob URL: "+f+" switching back to web url: "+b),c.src=b},c.src=f}else d()};var g=f.objectStore("textures").get(b);g.onsuccess=function(a){e=a.target.result},g.onerror=function(){a.Tools.Error("Error loading texture "+b+" from DB."),c.src=b}}else a.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),c.src=b},b.prototype._saveImageIntoDBAsync=function(b,c){var d=this;if(this.isSupported){var e=function(){var a;if(f){var b=window.URL||window.webkitURL;try{a=b.createObjectURL(f,{oneTimeOnly:!0})}catch(d){a=b.createObjectURL(f)}}c.src=a};if(a.Database.isUASupportingBlobStorage){var f,g=new XMLHttpRequest;g.open("GET",b,!0),g.responseType="blob",g.addEventListener("load",function(){if(200===g.status){f=g.response;var h=d.db.transaction(["textures"],"readwrite");h.onabort=function(a){try{"QuotaExceededError"===a.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(b){}e()},h.oncomplete=function(){e()};var i={textureUrl:b,data:f};try{var j=h.objectStore("textures").put(i);j.onsuccess=function(){},j.onerror=function(){e()}}catch(k){25===k.code&&(a.Database.isUASupportingBlobStorage=!1),c.src=b}}else c.src=b},!1),g.addEventListener("error",function(){a.Tools.Error("Error in XHR request in BABYLON.Database."),c.src=b},!1),g.send()}else c.src=b}else a.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),c.src=b},b.prototype._checkVersionFromDB=function(a,b){var c=this,d=function(){c._saveVersionIntoDBAsync(a,b)};this._loadVersionFromDBAsync(a,b,d)},b.prototype._loadVersionFromDBAsync=function(b,c,d){var e=this;if(this.isSupported){var f;try{var g=this.db.transaction(["versions"]);g.oncomplete=function(){f?e.manifestVersionFound>f.data?(e.mustUpdateRessources=!0,d()):c(f.data):(e.mustUpdateRessources=!0,d())},g.onabort=function(){c(-1)};var h=g.objectStore("versions").get(b);h.onsuccess=function(a){f=a.target.result},h.onerror=function(){a.Tools.Error("Error loading version for scene "+b+" from DB."),c(-1)}}catch(i){a.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+i.message),c(-1)}}else a.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),c(-1)},b.prototype._saveVersionIntoDBAsync=function(b,c){var d=this;if(this.isSupported&&!this.hasReachedQuota)try{var e=this.db.transaction(["versions"],"readwrite");e.onabort=function(a){try{"QuotaExceededError"===a.srcElement.error.name&&(d.hasReachedQuota=!0)}catch(b){}c(-1)},e.oncomplete=function(){c(d.manifestVersionFound)};var f={sceneUrl:b,data:this.manifestVersionFound},g=e.objectStore("versions").put(f);g.onsuccess=function(){},g.onerror=function(){a.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(h){a.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+h.message),c(-1)}else c(-1)},b.prototype.loadFileFromDB=function(b,c,d,e,f){var g=this,h=a.Database.ReturnFullUrlLocation(b),i=function(){g._saveFileIntoDBAsync(h,c,d)};this._checkVersionFromDB(h,function(a){-1!==a?g.mustUpdateRessources?g._saveFileIntoDBAsync(h,c,d,f):g._loadFileFromDBAsync(h,c,i,f):e()})},b.prototype._loadFileFromDBAsync=function(b,c,d){if(this.isSupported){var e;e=-1!==b.indexOf(".babylon")?"scenes":"textures";var f,g=this.db.transaction([e]);g.oncomplete=function(){f?c(f.data):d()},g.onabort=function(){d()};var h=g.objectStore(e).get(b);h.onsuccess=function(a){f=a.target.result},h.onerror=function(){a.Tools.Error("Error loading file "+b+" from DB."),d()}}else a.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),c()},b.prototype._saveFileIntoDBAsync=function(b,c,d,e){var f=this;if(this.isSupported){var g;g=-1!==b.indexOf(".babylon")?"scenes":"textures";var h,i=new XMLHttpRequest;i.open("GET",b,!0),e&&(i.responseType="arraybuffer"),i.onprogress=d,i.addEventListener("load",function(){if(200===i.status||a.Tools.ValidateXHRData(i,e?6:1))if(h=e?i.response:i.responseText,f.hasReachedQuota)c(h);else{var d=f.db.transaction([g],"readwrite");d.onabort=function(a){try{"QuotaExceededError"===a.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(b){}c(h)},d.oncomplete=function(){c(h)};var j;j="scenes"===g?{sceneUrl:b,data:h,version:f.manifestVersionFound}:{textureUrl:b,data:h};try{var k=d.objectStore(g).put(j);k.onsuccess=function(){},k.onerror=function(){a.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(l){c(h)}}else c()},!1),i.addEventListener("error",function(){a.Tools.Error("error on XHR request."),c()},!1),i.send()}else a.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),c()},b.isUASupportingBlobStorage=!0,b.parseURL=function(a){var b=document.createElement("a");b.href=a;var c=a.substring(a.lastIndexOf("/")+1,a.length),d=a.substring(0,a.indexOf(c,0));return d},b.ReturnFullUrlLocation=function(b){return-1===b.indexOf("http:/")?a.Database.parseURL(window.location.href)+b:b},b}();a.Database=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(b,c,d,e,f,g){this.name=b,this.cellSize=e,this.sprites=new Array,this.renderingGroupId=0,this._vertexDeclaration=[3,4,4,4],this._vertexStrideSize=60,this._capacity=d,this._spriteTexture=new a.Texture(c,f,!0,!1),this._spriteTexture.wrapU=a.Texture.CLAMP_ADDRESSMODE,this._spriteTexture.wrapV=a.Texture.CLAMP_ADDRESSMODE,this._epsilon=void 0===g?.01:g,this._scene=f,this._scene.spriteManagers.push(this),this._vertexDeclaration=[3,4,4,4],this._vertexStrideSize=60,this._vertexBuffer=f.getEngine().createDynamicVertexBuffer(d*this._vertexStrideSize*4);for(var h=[],i=0,j=0;d>j;j++)h.push(i),h.push(i+1),h.push(i+2),h.push(i),h.push(i+2),h.push(i+3),i+=4;this._indexBuffer=f.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(d*this._vertexStrideSize),this._effectBase=this._scene.getEngine().createEffect("sprites",["position","options","cellInfo","color"],["view","projection","textureInfos","alphaTest"],["diffuseSampler"],""),this._effectFog=this._scene.getEngine().createEffect("sprites",["position","options","cellInfo","color"],["view","projection","textureInfos","alphaTest","vFogInfos","vFogColor"],["diffuseSampler"],"#define FOG")}return b.prototype._appendSpriteVertex=function(a,b,c,d,e){var f=15*a;0==c?c=this._epsilon:1==c&&(c=1-this._epsilon),0==d?d=this._epsilon:1==d&&(d=1-this._epsilon),this._vertices[f]=b.position.x,this._vertices[f+1]=b.position.y,this._vertices[f+2]=b.position.z,this._vertices[f+3]=b.angle,this._vertices[f+4]=b.size,this._vertices[f+5]=c,this._vertices[f+6]=d,this._vertices[f+7]=b.invertU?1:0,this._vertices[f+8]=b.invertV?1:0;var g=b.cellIndex/e>>0;this._vertices[f+9]=b.cellIndex-g*e,this._vertices[f+10]=g,this._vertices[f+11]=b.color.r,this._vertices[f+12]=b.color.g,this._vertices[f+13]=b.color.b,this._vertices[f+14]=b.color.a},b.prototype.render=function(){if(this._effectBase.isReady()&&this._effectFog.isReady()&&this._spriteTexture&&this._spriteTexture.isReady()){for(var b=this._scene.getEngine(),c=this._spriteTexture.getBaseSize(),d=a.Tools.GetDeltaTime(),e=Math.min(this._capacity,this.sprites.length),f=c.width/this.cellSize,g=0,h=0;e>h;h++){var i=this.sprites[h];i&&(i._animate(d),this._appendSpriteVertex(g++,i,0,0,f),this._appendSpriteVertex(g++,i,1,0,f),this._appendSpriteVertex(g++,i,1,1,f),this._appendSpriteVertex(g++,i,0,1,f))}b.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices,e*this._vertexStrideSize);var j=this._effectBase;this._scene.fogMode!==a.Scene.FOGMODE_NONE&&(j=this._effectFog),b.enableEffect(j);var k=this._scene.getViewMatrix();j.setTexture("diffuseSampler",this._spriteTexture),j.setMatrix("view",k),j.setMatrix("projection",this._scene.getProjectionMatrix()),j.setFloat2("textureInfos",this.cellSize/c.width,this.cellSize/c.height),this._scene.fogMode!==a.Scene.FOGMODE_NONE&&(j.setFloat4("vFogInfos",this._scene.fogMode,this._scene.fogStart,this._scene.fogEnd,this._scene.fogDensity),j.setColor3("vFogColor",this._scene.fogColor)),b.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,j),j.setBool("alphaTest",!0),b.setColorWrite(!1),b.draw(!0,0,6*e),b.setColorWrite(!0),j.setBool("alphaTest",!1),b.setAlphaMode(a.Engine.ALPHA_COMBINE),b.draw(!0,0,6*e),b.setAlphaMode(a.Engine.ALPHA_DISABLE)}},b.prototype.dispose=function(){this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this._spriteTexture&&(this._spriteTexture.dispose(),this._spriteTexture=null);var a=this._scene.spriteManagers.indexOf(this);this._scene.spriteManagers.splice(a,1),this.onDispose&&this.onDispose()},b}();a.SpriteManager=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(b,c){this.name=b,this.color=new a.Color4(1,1,1,1),this.size=1,this.angle=0,this.cellIndex=0,this.invertU=0,this.invertV=0,this.animations=new Array,this._animationStarted=!1,this._loopAnimation=!1,this._fromIndex=0,this._toIndex=0,this._delay=0,this._direction=1,this._frameCount=0,this._time=0,this._manager=c,this._manager.sprites.push(this),this.position=a.Vector3.Zero()}return b.prototype.playAnimation=function(a,b,c,d){this._fromIndex=a,this._toIndex=b,this._loopAnimation=c,this._delay=d,this._animationStarted=!0,this._direction=b>a?1:-1,this.cellIndex=a,this._time=0},b.prototype.stopAnimation=function(){this._animationStarted=!1},b.prototype._animate=function(a){this._animationStarted&&(this._time+=a,this._time>this._delay&&(this._time=this._time%this._delay,this.cellIndex+=this._direction,this.cellIndex==this._toIndex&&(this._loopAnimation?this.cellIndex=this._fromIndex:(this._animationStarted=!1,this.disposeWhenFinishedAnimating&&this.dispose()))))},b.prototype.dispose=function(){for(var a=0;aj;j++)h.push(i),h.push(i+1),h.push(i+2),h.push(i),h.push(i+2),h.push(i+3),i+=4;this._indexBuffer=e.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(d*this._vertexStrideSize),this.startDirectionFunction=function(c,d,e){var f=b(g.direction1.x,g.direction2.x),h=b(g.direction1.y,g.direction2.y),i=b(g.direction1.z,g.direction2.z); a.Vector3.TransformNormalFromFloatsToRef(f*c,h*c,i*c,d,e)},this.startPositionFunction=function(c,d){var e=b(g.minEmitBox.x,g.maxEmitBox.x),f=b(g.minEmitBox.y,g.maxEmitBox.y),h=b(g.minEmitBox.z,g.maxEmitBox.z);a.Vector3.TransformCoordinatesFromFloatsToRef(e,f,h,c,d)}}return c.prototype.getCapacity=function(){return this._capacity},c.prototype.isAlive=function(){return this._alive},c.prototype.isStarted=function(){return this._started},c.prototype.start=function(){this._started=!0,this._stopped=!1,this._actualFrame=0},c.prototype.stop=function(){this._stopped=!0},c.prototype._appendParticleVertex=function(a,b,c,d){var e=11*a;this._vertices[e]=b.position.x,this._vertices[e+1]=b.position.y,this._vertices[e+2]=b.position.z,this._vertices[e+3]=b.color.r,this._vertices[e+4]=b.color.g,this._vertices[e+5]=b.color.b,this._vertices[e+6]=b.color.a,this._vertices[e+7]=b.angle,this._vertices[e+8]=b.size,this._vertices[e+9]=c,this._vertices[e+10]=d},c.prototype._update=function(c){this._alive=this.particles.length>0;for(var d=0;d=e.lifeTime?(this._stockParticles.push(this.particles.splice(d,1)[0]),d--):(e.colorStep.scaleToRef(this._scaledUpdateSpeed,this._scaledColorStep),e.color.addInPlace(this._scaledColorStep),e.color.a<0&&(e.color.a=0),e.angle+=e.angularSpeed*this._scaledUpdateSpeed,e.direction.scaleToRef(this._scaledUpdateSpeed,this._scaledDirection),e.position.addInPlace(this._scaledDirection),this.gravity.scaleToRef(this._scaledUpdateSpeed,this._scaledGravity),e.direction.addInPlace(this._scaledGravity))}var f;for(f=this.emitter.position?this.emitter.getWorldMatrix():a.Matrix.Translation(this.emitter.x,this.emitter.y,this.emitter.z),d=0;c>d&&this.particles.length!=this._capacity;d++){0!==this._stockParticles.length?(e=this._stockParticles.pop(),e.age=0):e=new a.Particle,this.particles.push(e);var g=b(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(g,f,e.direction),e.lifeTime=b(this.minLifeTime,this.maxLifeTime),e.size=b(this.minSize,this.maxSize),e.angularSpeed=b(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(f,e.position);var h=b(0,1);a.Color4.LerpToRef(this.color1,this.color2,h,e.color),this.colorDead.subtractToRef(e.color,this._colorDiff),this._colorDiff.scaleToRef(1/e.lifeTime,e.colorStep)}},c.prototype._getEffect=function(){var a=[];this._scene.clipPlane&&a.push("#define CLIPPLANE");var b=a.join("\n");if(this._cachedDefines!=b){this._cachedDefines=b;var c;c=this.fragmentElement?{vertex:"particles",fragmentElement:this.fragmentElement}:"particles",this._effect=this._scene.getEngine().createEffect(c,["position","color","options"],["invView","view","projection","vClipPlane","textureMask"],["diffuseSampler"],b)}return this._effect},c.prototype.animate=function(){if(this._started){var a=this._getEffect();if(this.emitter&&a.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this._currentRenderId!==this._scene.getRenderId()){this._currentRenderId=this._scene.getRenderId(),this._scaledUpdateSpeed=this.updateSpeed*this._scene.getAnimationRatio();var b;this.manualEmitCount>-1?(b=this.manualEmitCount,this.manualEmitCount=0):b=this.emitRate;var c=b*this._scaledUpdateSpeed>>0;this._newPartsExcess+=b*this._scaledUpdateSpeed-c,this._newPartsExcess>1&&(c+=this._newPartsExcess>>0,this._newPartsExcess-=this._newPartsExcess>>0),this._alive=!1,this._stopped?c=0:(this._actualFrame+=this._scaledUpdateSpeed,this.targetStopDuration&&this._actualFrame>=this.targetStopDuration&&this.stop()),this._update(c),this._stopped&&(this._alive||(this._started=!1,this.disposeOnStop&&this._scene._toBeDisposed.push(this)));for(var d=0,e=0;e0)return f.clone?f.clone():f;this.currentFrame=a;for(var g=0;g=a){var h=this._keys[g].value,i=this._keys[g+1].value,j=(a-this._keys[g].frame)/(this._keys[g+1].frame-this._keys[g].frame);switch(this.dataType){case b.ANIMATIONTYPE_FLOAT:switch(d){case b.ANIMATIONLOOPMODE_CYCLE:case b.ANIMATIONLOOPMODE_CONSTANT:return this.floatInterpolateFunction(h,i,j);case b.ANIMATIONLOOPMODE_RELATIVE:return e*c+this.floatInterpolateFunction(h,i,j)}break;case b.ANIMATIONTYPE_QUATERNION:var k=null;switch(d){case b.ANIMATIONLOOPMODE_CYCLE:case b.ANIMATIONLOOPMODE_CONSTANT:k=this.quaternionInterpolateFunction(h,i,j);break;case b.ANIMATIONLOOPMODE_RELATIVE:k=this.quaternionInterpolateFunction(h,i,j).add(e.scale(c))}return k;case b.ANIMATIONTYPE_VECTOR3:switch(d){case b.ANIMATIONLOOPMODE_CYCLE:case b.ANIMATIONLOOPMODE_CONSTANT:return this.vector3InterpolateFunction(h,i,j);case b.ANIMATIONLOOPMODE_RELATIVE:return this.vector3InterpolateFunction(h,i,j).add(e.scale(c))}case b.ANIMATIONTYPE_COLOR3:switch(d){case b.ANIMATIONLOOPMODE_CYCLE:case b.ANIMATIONLOOPMODE_CONSTANT:return this.color3InterpolateFunction(h,i,j);case b.ANIMATIONLOOPMODE_RELATIVE:return this.color3InterpolateFunction(h,i,j).add(e.scale(c))}case b.ANIMATIONTYPE_MATRIX:switch(d){case b.ANIMATIONLOOPMODE_CYCLE:case b.ANIMATIONLOOPMODE_CONSTANT:case b.ANIMATIONLOOPMODE_RELATIVE:return h}}break}return this._keys[this._keys.length-1].value},b.prototype.animate=function(a,c,d,e,f){if(!this.targetPropertyPath||this.targetPropertyPath.length<1)return this._stopped=!0,!1;var g=!0;if(0!=this._keys[0].frame){var h={frame:0,value:this._keys[0].value};this._keys.splice(0,0,h)}(cthis._keys[this._keys.length-1].frame)&&(c=this._keys[0].frame),(dthis._keys[this._keys.length-1].frame)&&(d=this._keys[this._keys.length-1].frame);var i=d-c,j=a*this.framePerSecond*f/1e3;if(j>i&&!e)k=0,g=!1,l=this._keys[this._keys.length-1].value;else{var k=0,l=0;if(this.loopMode!=b.ANIMATIONLOOPMODE_CYCLE){var m=d.toString()+c.toString();if(!this._offsetsCache[m]){var n=this._interpolate(c,0,b.ANIMATIONLOOPMODE_CYCLE),o=this._interpolate(d,0,b.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case b.ANIMATIONTYPE_FLOAT:this._offsetsCache[m]=o-n;break;case b.ANIMATIONTYPE_QUATERNION:this._offsetsCache[m]=o.subtract(n);break;case b.ANIMATIONTYPE_VECTOR3:this._offsetsCache[m]=o.subtract(n);case b.ANIMATIONTYPE_COLOR3:this._offsetsCache[m]=o.subtract(n)}this._highLimitsCache[m]=o}l=this._highLimitsCache[m],k=this._offsetsCache[m]}}var p=j/i>>0,q=g?c+j%i:d,r=this._interpolate(q,p,this.loopMode,k,l);if(this.targetPropertyPath.length>1){for(var s=this._target[this.targetPropertyPath[0]],t=1;t-1&&this._scene._activeAnimatables.splice(a,1),this.onAnimationEnd&&this.onAnimationEnd()},a.prototype._animate=function(a){if(this._paused)return!0;this._localDelayOffset||(this._localDelayOffset=a);for(var b=!1,c=this._animations,d=0;dk;k++)for(var l=0;2>l;l++)for(var m=0;2>m;m++){var n=b.add(j.multiplyByFloats(k,l,m)),o=b.add(j.multiplyByFloats(k+1,l+1,m+1)),p=new a.OctreeBlock(n,o,e,f+1,g,i);p.addEntries(d),h.blocks.push(p)}},b.CreationFuncForMeshes=function(a,b){a.getBoundingInfo().boundingBox.intersectsMinMax(b.minPoint,b.maxPoint)&&b.entries.push(a)},b.CreationFuncForSubMeshes=function(a,b){a.getBoundingInfo().boundingBox.intersectsMinMax(b.minPoint,b.maxPoint)&&b.entries.push(a)},b}();a.Octree=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(a,b,c,d,e,f){this.entries=new Array,this._boundingVectors=new Array,this._capacity=c,this._depth=d,this._maxDepth=e,this._creationFunc=f,this._minPoint=a,this._maxPoint=b,this._boundingVectors.push(a.clone()),this._boundingVectors.push(b.clone()),this._boundingVectors.push(a.clone()),this._boundingVectors[2].x=b.x,this._boundingVectors.push(a.clone()),this._boundingVectors[3].y=b.y,this._boundingVectors.push(a.clone()),this._boundingVectors[4].z=b.z,this._boundingVectors.push(b.clone()),this._boundingVectors[5].z=a.z,this._boundingVectors.push(b.clone()),this._boundingVectors[6].x=a.x,this._boundingVectors.push(b.clone()),this._boundingVectors[7].y=a.y}return Object.defineProperty(b.prototype,"capacity",{get:function(){return this._capacity},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"minPoint",{get:function(){return this._minPoint},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"maxPoint",{get:function(){return this._maxPoint},enumerable:!0,configurable:!0}),b.prototype.addEntry=function(a){if(this.blocks)for(var b=0;bthis.capacity&&this._depth0){for(var f=0;f0){for(var b=0;b0&&(this._camera._postProcesses[a._postProcessesTakenIndices[0]].width=-1)},b}();a.PostProcess=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function a(a){this._vertexDeclaration=[2],this._vertexStrideSize=8,this._scene=a;var b=[];b.push(1,1),b.push(-1,1),b.push(-1,-1),b.push(1,-1),this._vertexBuffer=a.getEngine().createVertexBuffer(b);var c=[];c.push(0),c.push(1),c.push(2),c.push(0),c.push(2),c.push(3),this._indexBuffer=a.getEngine().createIndexBuffer(c)}return a.prototype._prepareFrame=function(a){var b=this._scene.activeCamera._postProcesses,c=this._scene.activeCamera._postProcessesTakenIndices;return 0!==c.length&&this._scene.postProcessesEnabled?(b[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera,a),!0):!1},a.prototype._finalizeFrame=function(a,b){var c=this._scene.activeCamera._postProcesses,d=this._scene.activeCamera._postProcessesTakenIndices;if(0!==d.length&&this._scene.postProcessesEnabled){for(var e=this._scene.getEngine(),f=0;f0&&this._positionX>b.x&&this._positionXb.y&&this._positionYd},b.prototype.render=function(){if(!this._effect.isReady())return!1;var b=this._scene.getEngine(),c=this._scene.activeCamera.viewport,d=c.toGlobal(b);if(!this.computeEffectivePosition(d))return!1;if(!this._isVisible())return!1;var e,f;e=this._positionXd.x+d.width-this.borderLimit?this._positionX-d.x-d.width+this.borderLimit:0,f=this._positionYd.y+d.height-this.borderLimit?this._positionY-d.y-d.height+this.borderLimit:0;var g=e>f?e:f;g>this.borderLimit&&(g=this.borderLimit);var h=1-g/this.borderLimit;if(0>h)return!1;h>1&&(h=1);var i=d.x+d.width/2,j=d.y+d.height/2,k=i-this._positionX,l=j-this._positionY;b.enableEffect(this._effect),b.setState(!1),b.setDepthBuffer(!1),b.setAlphaMode(a.Engine.ALPHA_ADD),b.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect);for(var m=0;m0&&this.textureLoadingCallback(a)}this.currentScene.render()}},b.prototype.drag=function(a){a.stopPropagation(),a.preventDefault()},b.prototype.drop=function(a){a.stopPropagation(),a.preventDefault(),this.loadFiles(a)},b.prototype.loadFiles=function(b){var c=this,d=this;this.startingProcessingFilesCallback&&this.startingProcessingFilesCallback();var e,f;if(b&&b.dataTransfer&&b.dataTransfer.files&&(f=b.dataTransfer.files),b&&b.target&&b.target.files&&(f=b.target.files),f&&f.length>0){for(var g=0;g.1?a=.1:0>=a&&(a=1/60),this._currentPlugin.runOneStep(a)},b.prototype._setGravity=function(b){this.gravity=b||new a.Vector3(0,-9.82,0),this._currentPlugin.setGravity(this.gravity)},b.prototype._registerMesh=function(a,b,c){return this._currentPlugin.registerMesh(a,b,c)},b.prototype._registerMeshesAsCompound=function(a,b){return this._currentPlugin.registerMeshesAsCompound(a,b)},b.prototype._unregisterMesh=function(a){this._currentPlugin.unregisterMesh(a)},b.prototype._applyImpulse=function(a,b,c){this._currentPlugin.applyImpulse(a,b,c)},b.prototype._createLink=function(a,b,c,d,e){return this._currentPlugin.createLink(a,b,c,d,e)},b.prototype._updateBodyPosition=function(a){this._currentPlugin.updateBodyPosition(a)},b.prototype.dispose=function(){this._currentPlugin.dispose()},b.prototype.isSupported=function(){return this._currentPlugin.isSupported()},b.NoImpostor=0,b.SphereImpostor=1,b.BoxImpostor=2,b.PlaneImpostor=3,b.CompoundImpostor=4,b.MeshImpostor=4,b.CapsuleImpostor=5,b.ConeImpostor=6,b.CylinderImpostor=7,b.ConvexHullImpostor=8,b.Epsilon=.001,b}();a.PhysicsEngine=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b){var c={};if(c.name=b.name,c.id=b.id,c.tags=a.Tags.GetTags(b),b instanceof a.PointLight)c.type=0,c.position=b.position.asArray();else if(b instanceof a.DirectionalLight){c.type=1;var d=b;c.position=d.position.asArray(),c.direction=d.direction.asArray()}else if(b instanceof a.SpotLight){c.type=2;var e=b;c.position=e.position.asArray(),c.direction=e.position.asArray(),c.angle=e.angle,c.exponent=e.exponent}else if(b instanceof a.HemisphericLight){c.type=3;var f=b;c.direction=f.direction.asArray(),c.groundColor=f.groundColor.asArray()}return b.intensity&&(c.intensity=b.intensity),c.range=b.range,c.diffuse=b.diffuse.asArray(),c.specular=b.specular.asArray(),c},c=function(b){var c={};return c.name=b.name,c.tags=a.Tags.GetTags(b),c.id=b.id,c.position=b.position.asArray(),b.parent&&(c.parentId=b.parent.id),c.rotation=b.rotation.asArray(),b.lockedTarget&&b.lockedTarget.id&&(c.lockedTargetId=b.lockedTarget.id),c.fov=b.fov,c.minZ=b.minZ,c.maxZ=b.maxZ,c.speed=b.speed,c.inertia=b.inertia,c.checkCollisions=b.checkCollisions,c.applyGravity=b.applyGravity,b.ellipsoid&&(c.ellipsoid=b.ellipsoid.asArray()),d(b,c),c.layerMask=b.layerMask,c},d=function(a,b){if(a.animations){b.animations=[];for(var c=0;c0&&(f.animation=e(d.animations[0]))}return b},j=function(a){var b={};return b.emitterId=a.emitter.id,b.capacity=a.getCapacity(),a.particleTexture&&(b.textureName=a.particleTexture.name),b.minAngularSpeed=a.minAngularSpeed,b.maxAngularSpeed=a.maxAngularSpeed,b.minSize=a.minSize,b.maxSize=a.maxSize,b.minLifeTime=a.minLifeTime,b.maxLifeTime=a.maxLifeTime,b.emitRate=a.emitRate,b.minEmitBox=a.minEmitBox.asArray(),b.maxEmitBox=a.maxEmitBox.asArray(),b.gravity=a.gravity.asArray(),b.direction1=a.direction1.asArray(),b.direction2=a.direction2.asArray(),b.color1=a.color1.asArray(),b.color2=a.color2.asArray(),b.colorDead=a.colorDead.asArray(),b.updateSpeed=a.updateSpeed,b.targetStopDuration=a.targetStopDuration,b.textureMask=a.textureMask.asArray(),b.blendMode=a.blendMode,b},k=function(b){var c={};c.emitterId=b.getEmitter().id,c.borderLimit=b.borderLimit,c.flares=[];for(var d=0;d-1&&(g=d.bones[f.parentBoneIndex]);var h=new a.Bone(f.name,d,g,a.Matrix.FromArray(f.matrix));f.animation&&h.animations.push(k(f.animation))}return d},e=function(b,d,e){var f;return f=new a.StandardMaterial(b.name,d),f.ambientColor=a.Color3.FromArray(b.ambient),f.diffuseColor=a.Color3.FromArray(b.diffuse),f.specularColor=a.Color3.FromArray(b.specular),f.specularPower=b.specularPower,f.emissiveColor=a.Color3.FromArray(b.emissive),f.alpha=b.alpha,f.id=b.id,a.Tags.AddTagsTo(f,b.tags),f.backFaceCulling=b.backFaceCulling,f.wireframe=b.wireframe,b.diffuseTexture&&(f.diffuseTexture=c(e,b.diffuseTexture,d)),b.ambientTexture&&(f.ambientTexture=c(e,b.ambientTexture,d)),b.opacityTexture&&(f.opacityTexture=c(e,b.opacityTexture,d)),b.reflectionTexture&&(f.reflectionTexture=c(e,b.reflectionTexture,d)),b.emissiveTexture&&(f.emissiveTexture=c(e,b.emissiveTexture,d)),b.specularTexture&&(f.specularTexture=c(e,b.specularTexture,d)),b.bumpTexture&&(f.bumpTexture=c(e,b.bumpTexture,d)),f},f=function(a,b,c,d){for(var f=0;f-1&&(e.skeleton=c.getLastSkeletonByID(b.skeletonId)),b.physicsImpostor&&(c.isPhysicsEnabled()||c.enablePhysics(),e.setPhysicsState({impostor:b.physicsImpostor,mass:b.physicsMass,friction:b.physicsFriction,restitution:b.physicsRestitution})),b.animations)for(var f=0;f>8),g.push((16711680&i)>>16),g.push(i>>24)}c.setVerticesData(a.VertexBuffer.MatricesIndicesKind,g,!1)}b.matricesWeights&&c.setVerticesData(a.VertexBuffer.MatricesWeightsKind,b.matricesWeights,!1),c.setIndices(b.indices)}if(b.subMeshes){c.subMeshes=[];for(var j=0;j-1&&b.skeletons){var y=m.indexOf(q.skeletonId)>-1;if(!y)for(var z=0;zb.EPSILON?j:i;m|=q,n.push(q)}switch(m){case i:(a.Vector3.Dot(this.normal,c.plane.normal)>0?d:f).push(c);break;case j:g.push(c);break;case k:h.push(c);break;case l:var r=[],s=[];for(o=0;o=3){var z=new e(r,c.shared);z.plane&&g.push(z)}s.length>=3&&(z=new e(s,c.shared),z.plane&&h.push(z))}},b.EPSILON=1e-5,b}(),e=function(){function a(a,b){this.vertices=a,this.shared=b,this.plane=d.FromPoints(a[0].pos,a[1].pos,a[2].pos)}return a.prototype.clone=function(){var b=this.vertices.map(function(a){return a.clone()});return new a(b,this.shared)},a.prototype.flip=function(){this.vertices.reverse().map(function(a){a.flip()}),this.plane.flip()},a}(),f=function(){function a(a){this.plane=null,this.front=null,this.back=null,this.polygons=[],a&&this.build(a)}return a.prototype.clone=function(){var b=new a;return b.plane=this.plane&&this.plane.clone(),b.front=this.front&&this.front.clone(),b.back=this.back&&this.back.clone(),b.polygons=this.polygons.map(function(a){return a.clone()}),b},a.prototype.invert=function(){for(var a=0;aw;w++)for(var y=v[w].indexStart,z=v[w].indexCount+v[w].indexStart;z>y;y+=3){l=[];for(var A=0;3>A;A++)h=new a.Vector3(t[3*r[y+A]],t[3*r[y+A]+1],t[3*r[y+A]+2]),i=new a.Vector2(u[2*r[y+A]],u[2*r[y+A]+1]),j=new a.Vector3(s[3*r[y+A]],s[3*r[y+A]+1],s[3*r[y+A]+2]),a.Vector3.TransformCoordinatesToRef(j,n,j),a.Vector3.TransformNormalToRef(h,n,h),g=new c(j,h,i),l.push(g);k=new e(l,{subMeshId:w,meshId:b,materialIndex:v[w].materialIndex}),k.plane&&m.push(k)}var B=d.FromPolygons(m);return B.matrix=n,B.position=o,B.rotation=p,B.scaling=q,b++,B},d.FromPolygons=function(b){var c=new a.CSG;return c.polygons=b,c},d.prototype.clone=function(){var b=new a.CSG;return b.polygons=this.polygons.map(function(a){return a.clone()}),b.copyTransformAttributes(this),b},d.prototype.toPolygons=function(){return this.polygons},d.prototype.union=function(a){var b=new f(this.clone().polygons),c=new f(a.clone().polygons);return b.clipTo(c),c.clipTo(b),c.invert(),c.clipTo(b),c.invert(),b.build(c.allPolygons()),d.FromPolygons(b.allPolygons()).copyTransformAttributes(this)},d.prototype.unionInPlace=function(a){var b=new f(this.polygons),c=new f(a.polygons);b.clipTo(c),c.clipTo(b),c.invert(),c.clipTo(b),c.invert(),b.build(c.allPolygons()),this.polygons=b.allPolygons()},d.prototype.subtract=function(a){var b=new f(this.clone().polygons),c=new f(a.clone().polygons);return b.invert(),b.clipTo(c),c.clipTo(b),c.invert(),c.clipTo(b),c.invert(),b.build(c.allPolygons()),b.invert(),d.FromPolygons(b.allPolygons()).copyTransformAttributes(this)},d.prototype.subtractInPlace=function(a){var b=new f(this.polygons),c=new f(a.polygons);b.invert(),b.clipTo(c),c.clipTo(b),c.invert(),c.clipTo(b),c.invert(),b.build(c.allPolygons()),b.invert(),this.polygons=b.allPolygons()},d.prototype.intersect=function(a){var b=new f(this.clone().polygons),c=new f(a.clone().polygons);return b.invert(),c.clipTo(b),c.invert(),b.clipTo(c),c.clipTo(b),b.build(c.allPolygons()),b.invert(),d.FromPolygons(b.allPolygons()).copyTransformAttributes(this)},d.prototype.intersectInPlace=function(a){var b=new f(this.polygons),c=new f(a.polygons);b.invert(),c.clipTo(b),c.invert(),b.clipTo(c),c.clipTo(b),b.build(c.allPolygons()),b.invert(),this.polygons=b.allPolygons()},d.prototype.inverse=function(){var a=this.clone();return a.inverseInPlace(),a},d.prototype.inverseInPlace=function(){this.polygons.map(function(a){a.flip()})},d.prototype.copyTransformAttributes=function(a){return this.matrix=a.matrix,this.position=a.position,this.rotation=a.rotation,this.scaling=a.scaling,this},d.prototype.buildMeshGeometry=function(b,c,d){var e=this.matrix.clone();e.invert();var f,g,h,i=new a.Mesh(b,c),j=[],k=[],l=[],m=[],n=a.Vector3.Zero(),o=a.Vector3.Zero(),p=a.Vector2.Zero(),q=this.polygons,r=[0,0,0],s={},t=0,u={};d&&q.sort(function(a,b){return a.shared.meshId===b.shared.meshId?a.shared.subMeshId-b.shared.subMeshId:a.shared.meshId-b.shared.meshId});for(var v=0,w=q.length;w>v;v++){f=q[v],u[f.shared.meshId]||(u[f.shared.meshId]={}),u[f.shared.meshId][f.shared.subMeshId]||(u[f.shared.meshId][f.shared.subMeshId]={indexStart:+1/0,indexEnd:-1/0,materialIndex:f.shared.materialIndex}),h=u[f.shared.meshId][f.shared.subMeshId];for(var x=2,y=f.vertices.length;y>x;x++){r[0]=0,r[1]=x-1,r[2]=x;for(var z=0;3>z;z++)n.copyFrom(f.vertices[r[z]].pos),o.copyFrom(f.vertices[r[z]].normal),p.copyFrom(f.vertices[r[z]].uv),a.Vector3.TransformCoordinatesToRef(n,e,n),a.Vector3.TransformNormalToRef(o,e,o),g=s[n.x+","+n.y+","+n.z],("undefined"==typeof g||l[3*g]!==o.x||l[3*g+1]!==o.y||l[3*g+2]!==o.z||m[2*g]!==p.x||m[2*g+1]!==p.y)&&(j.push(n.x,n.y,n.z),m.push(p.x,p.y),l.push(o.x,o.y,o.z),g=s[n.x+","+n.y+","+n.z]=j.length/3-1),k.push(g),h.indexStart=Math.min(t,h.indexStart),h.indexEnd=Math.max(t,h.indexEnd),t++}}if(i.setVerticesData(a.VertexBuffer.PositionKind,j),i.setVerticesData(a.VertexBuffer.NormalKind,l),i.setVerticesData(a.VertexBuffer.UVKind,m),i.setIndices(k),d){var A,B=0;i.subMeshes.length=0;for(var C in u){A=-1;for(var D in u[C])h=u[C][D],a.SubMesh.CreateFromIndices(h.materialIndex+B,h.indexStart,h.indexEnd-h.indexStart+1,i),A=Math.max(h.materialIndex,A);B+=++A}}return i},d.prototype.toMesh=function(a,b,c,d){var e=this.buildMeshGeometry(a,c,d);return e.material=b,e.position.copyFrom(this.position),e.rotation.copyFrom(this.rotation),e.scaling.copyFrom(this.scaling),e.computeWorldMatrix(!0),e},d}();a.CSG=g}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(c,d,e,f){var g=this;b.call(this,c,"oculusDistortionCorrection",["LensCenter","Scale","ScaleIn","HmdWarpParam"],null,f.PostProcessScaleFactor,d,a.Texture.BILINEAR_SAMPLINGMODE,null,null),this._isRightEye=e,this._distortionFactors=f.DistortionK,this._postProcessScaleFactor=f.PostProcessScaleFactor,this._lensCenterOffset=f.LensCenterOffset,this.onSizeChanged=function(){g.aspectRatio=.5*g.width/g.height,g._scaleIn=new a.Vector2(2,2/g.aspectRatio),g._scaleFactor=new a.Vector2(.5*(1/g._postProcessScaleFactor),.5*(1/g._postProcessScaleFactor)*g.aspectRatio),g._lensCenter=new a.Vector2(g._isRightEye?.5-.5*g._lensCenterOffset:.5+.5*g._lensCenterOffset,.5)},this.onApply=function(a){a.setFloat2("LensCenter",g._lensCenter.x,g._lensCenter.y),a.setFloat2("Scale",g._scaleFactor.x,g._scaleFactor.y),a.setFloat2("ScaleIn",g._scaleIn.x,g._scaleIn.y),a.setFloat4("HmdWarpParam",g._distortionFactors[0],g._distortionFactors[1],g._distortionFactors[2],g._distortionFactors[3])}}return __extends(c,b),c}(a.PostProcess);a.OculusDistortionCorrectionPostProcess=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){!function(a){a[a.X=0]="X",a[a.Y=1]="Y",a[a.Z=2]="Z"}(a.JoystickAxis||(a.JoystickAxis={}));var b=(a.JoystickAxis,function(){function b(c){var d=this;this._leftJoystick=c?!0:!1,this._joystickIndex=b._globalJoystickIndex,b._globalJoystickIndex++,this._axisTargetedByLeftAndRight=0,this._axisTargetedByUpAndDown=1,this.reverseLeftRight=!1,this.reverseUpDown=!1,this._touches=new a.VirtualJoystick.Collection,this.deltaPosition=a.Vector3.Zero(),this._joystickSensibility=25,this._inversedSensibility=1/(this._joystickSensibility/1e3),this._rotationSpeed=25,this._inverseRotationSpeed=1/(this._rotationSpeed/1e3),this._rotateOnAxisRelativeToMesh=!1,b.vjCanvas||(window.addEventListener("resize",function(){b.vjCanvasWidth=window.innerWidth,b.vjCanvasHeight=window.innerHeight,b.vjCanvas.width=b.vjCanvasWidth,b.vjCanvas.height=b.vjCanvasHeight,b.halfWidth=b.vjCanvasWidth/2,b.halfHeight=b.vjCanvasHeight/2},!1),b.vjCanvas=document.createElement("canvas"),b.vjCanvasWidth=window.innerWidth,b.vjCanvasHeight=window.innerHeight,b.vjCanvas.width=window.innerWidth,b.vjCanvas.height=window.innerHeight,b.vjCanvas.style.width="100%",b.vjCanvas.style.height="100%",b.vjCanvas.style.position="absolute",b.vjCanvas.style.backgroundColor="transparent",b.vjCanvas.style.top="0px",b.vjCanvas.style.left="0px",b.vjCanvas.style.zIndex="5",b.vjCanvas.style.msTouchAction="none",b.vjCanvasContext=b.vjCanvas.getContext("2d"),b.vjCanvasContext.strokeStyle="#ffffff",b.vjCanvasContext.lineWidth=2,document.body.appendChild(b.vjCanvas)),b.halfWidth=b.vjCanvas.width/2,b.halfHeight=b.vjCanvas.height/2,this.pressed=!1,this._joystickColor="cyan",this._joystickPointerID=-1,this._joystickPointerPos=new a.Vector2(0,0),this._joystickPointerStartPos=new a.Vector2(0,0),this._deltaJoystickVector=new a.Vector2(0,0),b.vjCanvas.addEventListener("pointerdown",function(a){d._onPointerDown(a)},!1),b.vjCanvas.addEventListener("pointermove",function(a){d._onPointerMove(a)},!1),b.vjCanvas.addEventListener("pointerup",function(a){d._onPointerUp(a)},!1),b.vjCanvas.addEventListener("pointerout",function(a){d._onPointerUp(a)},!1),b.vjCanvas.addEventListener("contextmenu",function(a){a.preventDefault()},!1),requestAnimationFrame(function(){d._drawVirtualJoystick()})}return b.prototype.setJoystickSensibility=function(a){this._joystickSensibility=a,this._inversedSensibility=1/(this._joystickSensibility/1e3)},b.prototype._onPointerDown=function(a){var c;a.preventDefault(),c=this._leftJoystick===!0?a.clientXb.halfWidth,c&&this._joystickPointerID<0?(this._joystickPointerID=a.pointerId,this._joystickPointerStartPos.x=a.clientX,this._joystickPointerStartPos.y=a.clientY,this._joystickPointerPos=this._joystickPointerStartPos.clone(),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this.pressed=!0,this._touches.add(a.pointerId.toString(),a)):b._globalJoystickIndex<2&&this._action&&(this._action(),this._touches.add(a.pointerId.toString(),a))},b.prototype._onPointerMove=function(a){if(this._joystickPointerID==a.pointerId){this._joystickPointerPos.x=a.clientX,this._joystickPointerPos.y=a.clientY,this._deltaJoystickVector=this._joystickPointerPos.clone(),this._deltaJoystickVector=this._deltaJoystickVector.subtract(this._joystickPointerStartPos);var b=this.reverseLeftRight?-1:1,c=b*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){case 0:this.deltaPosition.x=Math.min(1,Math.max(-1,c));break;case 1:this.deltaPosition.y=Math.min(1,Math.max(-1,c));break;case 2:this.deltaPosition.z=Math.min(1,Math.max(-1,c))}var d=this.reverseUpDown?1:-1,e=d*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case 0:this.deltaPosition.x=Math.min(1,Math.max(-1,e));break;case 1:this.deltaPosition.y=Math.min(1,Math.max(-1,e));break;case 2:this.deltaPosition.z=Math.min(1,Math.max(-1,e))}}else this._touches.item(a.pointerId.toString())&&(this._touches.item(a.pointerId.toString()).x=a.clientX,this._touches.item(a.pointerId.toString()).y=a.clientY)},b.prototype._onPointerUp=function(a){this._clearCanvas(),this._joystickPointerID==a.pointerId&&(this._joystickPointerID=-1,this.pressed=!1),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(a.pointerId.toString())},b.prototype.setJoystickColor=function(a){this._joystickColor=a},b.prototype.setActionOnTouch=function(a){this._action=a},b.prototype.setAxisForLeftRight=function(a){switch(a){case 0:case 1:case 2:this._axisTargetedByLeftAndRight=a;break;default:this._axisTargetedByLeftAndRight=0}},b.prototype.setAxisForUpDown=function(a){switch(a){case 0:case 1:case 2:this._axisTargetedByUpAndDown=a;break;default:this._axisTargetedByUpAndDown=1}},b.prototype._clearCanvas=function(){this._leftJoystick?b.vjCanvasContext.clearRect(0,0,b.vjCanvasWidth/2,b.vjCanvasHeight):b.vjCanvasContext.clearRect(b.vjCanvasWidth/2,0,b.vjCanvasWidth,b.vjCanvasHeight)},b.prototype._drawVirtualJoystick=function(){var a=this;this.pressed&&(this._clearCanvas(),this._touches.forEach(function(c){c.pointerId===a._joystickPointerID?(b.vjCanvasContext.beginPath(),b.vjCanvasContext.strokeStyle=a._joystickColor,b.vjCanvasContext.lineWidth=6,b.vjCanvasContext.arc(a._joystickPointerStartPos.x,a._joystickPointerStartPos.y,40,0,2*Math.PI,!0),b.vjCanvasContext.stroke(),b.vjCanvasContext.beginPath(),b.vjCanvasContext.strokeStyle=a._joystickColor,b.vjCanvasContext.lineWidth=2,b.vjCanvasContext.arc(a._joystickPointerStartPos.x,a._joystickPointerStartPos.y,60,0,2*Math.PI,!0),b.vjCanvasContext.stroke(),b.vjCanvasContext.beginPath(),b.vjCanvasContext.strokeStyle=a._joystickColor,b.vjCanvasContext.arc(a._joystickPointerPos.x,a._joystickPointerPos.y,40,0,2*Math.PI,!0),b.vjCanvasContext.stroke()):(b.vjCanvasContext.beginPath(),b.vjCanvasContext.fillStyle="white",b.vjCanvasContext.beginPath(),b.vjCanvasContext.strokeStyle="red",b.vjCanvasContext.lineWidth=6,b.vjCanvasContext.arc(c.x,c.y,40,0,2*Math.PI,!0),b.vjCanvasContext.stroke())})),requestAnimationFrame(function(){a._drawVirtualJoystick()})},b.prototype.releaseCanvas=function(){b.vjCanvas&&(document.body.removeChild(b.vjCanvas),b.vjCanvas=null)},b._globalJoystickIndex=0,b}());a.VirtualJoystick=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){!function(a){var b=function(){function a(){this._count=0,this._collection=new Array}return a.prototype.Count=function(){return this._count},a.prototype.add=function(a,b){return void 0!=this._collection[a]?void 0:(this._collection[a]=b,++this._count)},a.prototype.remove=function(a){return void 0==this._collection[a]?void 0:(delete this._collection[a],--this._count)},a.prototype.item=function(a){return this._collection[a]},a.prototype.forEach=function(a){var b;for(b in this._collection)this._collection.hasOwnProperty(b)&&a(this._collection[b])},a}();a.Collection=b}(a.VirtualJoystick||(a.VirtualJoystick={}));a.VirtualJoystick}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b={HResolution:1280,VResolution:800,HScreenSize:.149759993,VScreenSize:.0935999975,VScreenCenter:.0467999987,EyeToScreenDistance:.0410000011,LensSeparationDistance:.063500002,InterpupillaryDistance:.064000003,DistortionK:[1,.219999999,.239999995,0],ChromaAbCorrection:[.995999992,-.00400000019,1.01400006,0],PostProcessScaleFactor:1.714605507808412,LensCenterOffset:.151976421},c=function(c){function d(d,e,f,g){c.call(this,d,e,f),this._workMatrix=new a.Matrix,this._actualUp=new a.Vector3(0,0,0),this._aspectRatioAspectRatio=b.HResolution/(2*b.VResolution),this._aspectRatioFov=2*Math.atan(b.PostProcessScaleFactor*b.VScreenSize/(2*b.EyeToScreenDistance));var h=b.HScreenSize/4-b.LensSeparationDistance/2,i=4*h/b.HScreenSize;this._hMatrix=a.Matrix.Translation(g?i:-i,0,0),this.viewport=new a.Viewport(g?0:.5,0,.5,1),this._preViewMatrix=a.Matrix.Translation(g?.5*b.InterpupillaryDistance:-.5*b.InterpupillaryDistance,0,0);new a.OculusDistortionCorrectionPostProcess("Oculus Distortion",this,!g,b)}return __extends(d,c),d.prototype.getProjectionMatrix=function(){return a.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov,this._aspectRatioAspectRatio,this.minZ,this.maxZ,this._workMatrix),this._workMatrix.multiplyToRef(this._hMatrix,this._projectionMatrix),this._projectionMatrix},d.prototype._getViewMatrix=function(){return a.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),a.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),a.Vector3.TransformNormalToRef(this.upVector,this._cameraRotationMatrix,this._actualUp),this.position.addToRef(this._transformedReferencePoint,this._currentTarget),a.Matrix.LookAtLHToRef(this.position,this._currentTarget,this._actualUp,this._workMatrix),this._workMatrix.multiplyToRef(this._preViewMatrix,this._viewMatrix),this._viewMatrix},d}(a.FreeCamera),d=function(a){function b(b,d,e){a.call(this,b,d,e),this._leftCamera=new c(b+"_left",d.clone(),e,!0),this._rightCamera=new c(b+"_right",d.clone(),e,!1),this.subCameras.push(this._leftCamera),this.subCameras.push(this._rightCamera),this._deviceOrientationHandler=this._onOrientationEvent.bind(this)}return __extends(b,a),b.prototype._update=function(){this._leftCamera.position.copyFrom(this.position),this._rightCamera.position.copyFrom(this.position),this._updateCamera(this._leftCamera),this._updateCamera(this._rightCamera),a.prototype._update.call(this)},b.prototype._updateCamera=function(a){a.minZ=this.minZ,a.maxZ=this.maxZ,a.rotation.x=this.rotation.x,a.rotation.y=this.rotation.y,a.rotation.z=this.rotation.z},b.prototype._onOrientationEvent=function(a){var b=a.alpha/180*Math.PI,c=a.beta/180*Math.PI,d=a.gamma/180*Math.PI;return this._offsetOrientation?(this.rotation.y+=b-this._offsetOrientation.yaw,this.rotation.x+=c-this._offsetOrientation.pitch,this.rotation.z+=this._offsetOrientation.roll-d,this._offsetOrientation.yaw=b,this._offsetOrientation.pitch=c,this._offsetOrientation.roll=d,void 0):void(this._offsetOrientation={yaw:b,pitch:c,roll:d})},b.prototype.attachControl=function(b,c){a.prototype.attachControl.call(this,b,c),window.addEventListener("deviceorientation",this._deviceOrientationHandler)},b.prototype.detachControl=function(b){a.prototype.detachControl.call(this,b),window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},b}(a.FreeCamera);a.OculusCamera=d}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(c,d,e){b.call(this,c,d,e),this._leftjoystick=new a.VirtualJoystick(!0),this._leftjoystick.setAxisForUpDown(2),this._leftjoystick.setAxisForLeftRight(0),this._leftjoystick.setJoystickSensibility(.15),this._rightjoystick=new a.VirtualJoystick(!1),this._rightjoystick.setAxisForUpDown(0),this._rightjoystick.setAxisForLeftRight(1),this._rightjoystick.reverseUpDown=!0,this._rightjoystick.setJoystickSensibility(.05),this._rightjoystick.setJoystickColor("yellow")}return __extends(c,b),c.prototype._checkInputs=function(){var b=a.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),c=a.Vector3.TransformCoordinates(this._leftjoystick.deltaPosition,b);this.cameraDirection=this.cameraDirection.add(c),this.cameraRotation=this.cameraRotation.add(this._rightjoystick.deltaPosition),this._leftjoystick.pressed||(this._leftjoystick.deltaPosition=this._leftjoystick.deltaPosition.scale(.9)),this._rightjoystick.pressed||(this._rightjoystick.deltaPosition=this._rightjoystick.deltaPosition.scale(.9))},c.prototype.dispose=function(){this._leftjoystick.releaseCanvas()},c}(a.FreeCamera);a.VirtualJoysticksCamera=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(c,d,e,f){b.call(this,c,d),this._textures=new Array,this._floats=new Array,this._floatsArrays={},this._colors3=new Array,this._colors4=new Array,this._vectors2=new Array,this._vectors3=new Array,this._matrices=new Array,this._cachedWorldViewMatrix=new a.Matrix,this._shaderPath=e,f.needAlphaBlending=f.needAlphaBlending||!1,f.needAlphaTesting=f.needAlphaTesting||!1,f.attributes=f.attributes||["position","normal","uv"],f.uniforms=f.uniforms||["worldViewProjection"],f.samplers=f.samplers||[],this._options=f}return __extends(c,b),c.prototype.needAlphaBlending=function(){return this._options.needAlphaBlending},c.prototype.needAlphaTesting=function(){return this._options.needAlphaTesting},c.prototype._checkUniform=function(a){-1===this._options.uniforms.indexOf(a)&&this._options.uniforms.push(a)},c.prototype.setTexture=function(a,b){return-1===this._options.samplers.indexOf(a)&&this._options.samplers.push(a),this._textures[a]=b,this},c.prototype.setFloat=function(a,b){return this._checkUniform(a),this._floats[a]=b,this},c.prototype.setFloats=function(a,b){return this._checkUniform(a),this._floatsArrays[a]=b,this},c.prototype.setColor3=function(a,b){return this._checkUniform(a),this._colors3[a]=b,this},c.prototype.setColor4=function(a,b){return this._checkUniform(a),this._colors4[a]=b,this},c.prototype.setVector2=function(a,b){return this._checkUniform(a),this._vectors2[a]=b,this},c.prototype.setVector3=function(a,b){return this._checkUniform(a),this._vectors3[a]=b,this},c.prototype.setMatrix=function(a,b){return this._checkUniform(a),this._matrices[a]=b,this},c.prototype.isReady=function(){var a=this.getScene().getEngine();return this._effect=a.createEffect(this._shaderPath,this._options.attributes,this._options.uniforms,this._options.samplers,"",null,this.onCompiled,this.onError),this._effect.isReady()?!0:!1},c.prototype.bind=function(a){-1!==this._options.uniforms.indexOf("world")&&this._effect.setMatrix("world",a),-1!==this._options.uniforms.indexOf("view")&&this._effect.setMatrix("view",this.getScene().getViewMatrix()),-1!==this._options.uniforms.indexOf("worldView")&&(a.multiplyToRef(this.getScene().getViewMatrix(),this._cachedWorldViewMatrix),this._effect.setMatrix("worldView",this._cachedWorldViewMatrix)),-1!==this._options.uniforms.indexOf("projection")&&this._effect.setMatrix("projection",this.getScene().getProjectionMatrix()),-1!==this._options.uniforms.indexOf("worldViewProjection")&&this._effect.setMatrix("worldViewProjection",a.multiply(this.getScene().getTransformMatrix()));for(var b in this._textures)this._effect.setTexture(b,this._textures[b]);for(b in this._floats)this._effect.setFloat(b,this._floats[b]);for(b in this._floatsArrays)this._effect.setArray(b,this._floatsArrays[b]);for(b in this._colors3)this._effect.setColor3(b,this._colors3[b]);for(b in this._colors4){var c=this._colors4[b];this._effect.setFloat4(b,c.r,c.g,c.b,c.a)}for(b in this._vectors2)this._effect.setVector2(b,this._vectors2[b]);for(b in this._vectors3)this._effect.setVector3(b,this._vectors3[b]);for(b in this._matrices)this._effect.setMatrix(b,this._matrices[b])},c.prototype.dispose=function(a){for(var c in this._textures)this._textures[c].dispose();this._textures=[],b.prototype.dispose.call(this,a)},c}(a.Material);a.ShaderMaterial=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(){}return b.prototype.set=function(b,c){switch(c){case a.VertexBuffer.PositionKind:this.positions=b;break;case a.VertexBuffer.NormalKind:this.normals=b;break;case a.VertexBuffer.UVKind:this.uvs=b;break;case a.VertexBuffer.UV2Kind:this.uv2s=b;break;case a.VertexBuffer.ColorKind:this.colors=b;break;case a.VertexBuffer.MatricesIndicesKind:this.matricesIndices=b;break;case a.VertexBuffer.MatricesWeightsKind:this.matricesWeights=b}},b.prototype.applyToMesh=function(a,b){this._applyTo(a,b)},b.prototype.applyToGeometry=function(a,b){this._applyTo(a,b)},b.prototype.updateMesh=function(a){this._update(a)},b.prototype.updateGeometry=function(a){this._update(a)},b.prototype._applyTo=function(b,c){this.positions&&b.setVerticesData(a.VertexBuffer.PositionKind,this.positions,c),this.normals&&b.setVerticesData(a.VertexBuffer.NormalKind,this.normals,c),this.uvs&&b.setVerticesData(a.VertexBuffer.UVKind,this.uvs,c),this.uv2s&&b.setVerticesData(a.VertexBuffer.UV2Kind,this.uv2s,c),this.colors&&b.setVerticesData(a.VertexBuffer.ColorKind,this.colors,c),this.matricesIndices&&b.setVerticesData(a.VertexBuffer.MatricesIndicesKind,this.matricesIndices,c),this.matricesWeights&&b.setVerticesData(a.VertexBuffer.MatricesWeightsKind,this.matricesWeights,c),this.indices&&b.setIndices(this.indices) },b.prototype._update=function(b,c,d){this.positions&&b.updateVerticesData(a.VertexBuffer.PositionKind,this.positions,c,d),this.normals&&b.updateVerticesData(a.VertexBuffer.NormalKind,this.normals,c,d),this.uvs&&b.updateVerticesData(a.VertexBuffer.UVKind,this.uvs,c,d),this.uv2s&&b.updateVerticesData(a.VertexBuffer.UV2Kind,this.uv2s,c,d),this.colors&&b.updateVerticesData(a.VertexBuffer.ColorKind,this.colors,c,d),this.matricesIndices&&b.updateVerticesData(a.VertexBuffer.MatricesIndicesKind,this.matricesIndices,c,d),this.matricesWeights&&b.updateVerticesData(a.VertexBuffer.MatricesWeightsKind,this.matricesWeights,c,d),this.indices&&b.setIndices(this.indices)},b.prototype.transform=function(b){var c=a.Vector3.Zero();if(this.positions)for(var d=a.Vector3.Zero(),e=0;e=k;k++){for(var l=k/e,m=l*Math.PI,n=0;f>=n;n++){var o=n/f,p=o*Math.PI*2,q=a.Matrix.RotationZ(-m),r=a.Matrix.RotationY(p),s=a.Vector3.TransformCoordinates(a.Vector3.Up(),q),t=a.Vector3.TransformCoordinates(s,r),u=t.scale(d),v=a.Vector3.Normalize(u);h.push(u.x,u.y,u.z),i.push(v.x,v.y,v.z),j.push(l,o)}if(k>0)for(var w=h.length/3,x=w-2*(f+1);w>x+f+2;x++)g.push(x),g.push(x+1),g.push(x+f+1),g.push(x+f+1),g.push(x+1),g.push(x+f+2)}var y=new a.VertexData;return y.indices=g,y.positions=h,y.normals=i,y.uvs=j,y},b.CreateCylinder=function(b,c,d,e,f){"undefined"==typeof f&&(f=1);var g=c/2,h=d/2,i=[],j=[],k=[],l=[];b=b||1,c=c||.5,d=d||1,e=e||16,f=f||1,f=1>f?1:f;for(var m=function(b){var c=2*b*Math.PI/e,d=Math.cos(c),f=Math.sin(c);return new a.Vector3(d,0,f)},n=function(c){var d=c?g:h;if(0!=d){var f=j.length/3,k=new a.Vector3(0,b/2,0),n=new a.Vector2(.5,.5);for(c||(k.scaleInPlace(-1),n.x=-n.x),r=0;e>r;r++){var o=m(r),p=o.scale(d).add(k),q=new a.Vector2(o.x*n.x+.5,o.z*n.y+.5);j.push(p.x,p.y,p.z),l.push(q.x,q.y)}for(var r=0;e-2>r;r++)c?(i.push(f),i.push(f+(r+1)%e),i.push(f+(r+2)%e)):(i.push(f),i.push(f+(r+2)%e),i.push(f+(r+1)%e))}},o=new a.Vector3(0,-1,0).scale(b/2),p=new a.Vector3(0,1,0).scale(b/f),q=e+1,r=0;e>=r;r++)for(var s,t=m(r),u=new a.Vector2(r/e,0),v=h,w=0;f>=w;w++)s=t.scale(v),s.addInPlace(o.add(p.scale(w))),u.y+=1/f,v+=(g-h)/f,j.push(s.x,s.y,s.z),l.push(u.x,u.y);f+=1;for(var w=0;f-1>w;w++)for(var r=0;e>=r;r++)i.push(r*f+w),i.push((r*f+(w+f))%(q*f)),i.push(r*f+(w+1)),i.push(r*f+(w+1)),i.push((r*f+(w+f))%(q*f)),i.push((r*f+(w+f+1))%(q*f));n(!0),n(!1),a.VertexData.ComputeNormals(j,i,k);var x=new a.VertexData;return x.indices=i,x.positions=j,x.normals=k,x.uvs=l,x},b.CreateTorus=function(b,c,d){var e=[],f=[],g=[],h=[];b=b||1,c=c||.5,d=d||16;for(var i=d+1,j=0;d>=j;j++)for(var k=j/d,l=j*Math.PI*2/d-Math.PI/2,m=a.Matrix.Translation(b/2,0,0).multiply(a.Matrix.RotationY(l)),n=0;d>=n;n++){var o=1-n/d,p=n*Math.PI*2/d+Math.PI,q=Math.cos(p),r=Math.sin(p),s=new a.Vector3(q,r,0),t=s.scale(c/2),u=new a.Vector2(k,o);t=a.Vector3.TransformCoordinates(t,m),s=a.Vector3.TransformNormal(s,m),f.push(t.x,t.y,t.z),g.push(s.x,s.y,s.z),h.push(u.x,u.y);var v=(j+1)%i,w=(n+1)%i;e.push(j*i+n),e.push(j*i+w),e.push(v*i+n),e.push(j*i+w),e.push(v*i+w),e.push(v*i+n)}var x=new a.VertexData;return x.indices=e,x.positions=f,x.normals=g,x.uvs=h,x},b.CreateLines=function(b){for(var c=[],d=[],e=0;e0&&(c.push(e-1),c.push(e));var f=new a.VertexData;return f.indices=c,f.positions=d,f},b.CreateGround=function(b,c,d){var e,f,g=[],h=[],i=[],j=[];for(b=b||1,c=c||1,d=d||1,e=0;d>=e;e++)for(f=0;d>=f;f++){var k=new a.Vector3(f*b/d-b/2,0,(d-e)*c/d-c/2),l=new a.Vector3(0,1,0);h.push(k.x,k.y,k.z),i.push(l.x,l.y,l.z),j.push(f/d,1-e/d)}for(e=0;d>e;e++)for(f=0;d>f;f++)g.push(f+1+(e+1)*(d+1)),g.push(f+1+e*(d+1)),g.push(f+e*(d+1)),g.push(f+(e+1)*(d+1)),g.push(f+1+(e+1)*(d+1)),g.push(f+e*(d+1));var m=new a.VertexData;return m.indices=g,m.positions=h,m.normals=i,m.uvs=j,m},b.CreateTiledGround=function(b,c,d,e,f,g){function h(b,c,d,e){var f=n.length/3,h=g.w+1;for(i=0;i=j;j++)for(k=0;d>=k;k++){var p=new a.Vector3(k*b/d-b/2,0,(d-j)*c/d-c/2),q=(p.x+b/2)/b*(h-1)|0,r=(1-(p.z+c/2)/c)*(i-1)|0,s=4*(q+r*h),t=g[s]/255,u=g[s+1]/255,v=g[s+2]/255,w=.3*t+.59*u+.11*v;p.y=e+(f-e)*w,m.push(p.x,p.y,p.z),n.push(0,0,0),o.push(k/d,1-j/d)}for(j=0;d>j;j++)for(k=0;d>k;k++)l.push(k+1+(j+1)*(d+1)),l.push(k+1+j*(d+1)),l.push(k+j*(d+1)),l.push(k+(j+1)*(d+1)),l.push(k+1+(j+1)*(d+1)),l.push(k+j*(d+1));a.VertexData.ComputeNormals(m,l,n);var x=new a.VertexData;return x.indices=l,x.positions=m,x.normals=n,x.uvs=o,x},b.CreatePlane=function(b){var c=[],d=[],e=[],f=[];b=b||1;var g=b/2;d.push(-g,-g,0),e.push(0,0,-1),f.push(0,0),d.push(g,-g,0),e.push(0,0,-1),f.push(1,0),d.push(g,g,0),e.push(0,0,-1),f.push(1,1),d.push(-g,g,0),e.push(0,0,-1),f.push(0,1),c.push(0),c.push(1),c.push(2),c.push(0),c.push(2),c.push(3);var h=new a.VertexData;return h.indices=c,h.positions=d,h.normals=e,h.uvs=f,h},b.CreateTorusKnot=function(b,c,d,e,f,g){var h=[],i=[],j=[],k=[];b=b||2,c=c||.5,d=d||32,e=e||32,f=f||2,g=g||3;for(var l=function(c){var d=Math.cos(c),e=Math.sin(c),h=g/f*c,i=Math.cos(h),j=b*(2+i)*.5*d,k=b*(2+i)*e*.5,l=b*Math.sin(h)*.5;return new a.Vector3(j,k,l)},m=0;d>=m;m++){var n=m%d,o=n/d*2*f*Math.PI,p=l(o),q=l(o+.01),r=q.subtract(p),s=q.add(p),t=a.Vector3.Cross(r,s);s=a.Vector3.Cross(t,r),t.normalize(),s.normalize();for(var u=0;e>u;u++){var v=u%e,w=v/e*2*Math.PI,x=-c*Math.cos(w),y=c*Math.sin(w);i.push(p.x+x*s.x+y*t.x),i.push(p.y+x*s.y+y*t.y),i.push(p.z+x*s.z+y*t.z),k.push(m/d),k.push(u/e)}}for(m=0;d>m;m++)for(u=0;e>u;u++){var z=(u+1)%e,A=m*e+u,B=(m+1)*e+u,C=(m+1)*e+z,D=m*e+z;h.push(D),h.push(B),h.push(A),h.push(D),h.push(C),h.push(B)}a.VertexData.ComputeNormals(i,h,j);var E=new a.VertexData;return E.indices=h,E.positions=i,E.normals=j,E.uvs=k,E},b.ComputeNormals=function(b,c,d){var e,f=[],g=[];for(e=0;e1)for(var i=0;id.length)return void a.Tools.Error("Unable to load TGA file - Not enough data");e+=f.id_length;var g=!1,h=!1,i=!1,j=!1;switch(f.image_type){case b._TYPE_RLE_INDEXED:g=!0;case b._TYPE_INDEXED:h=!0;break;case b._TYPE_RLE_RGB:g=!0;case b._TYPE_RGB:i=!0;break;case b._TYPE_RLE_GREY:g=!0;case b._TYPE_GREY:j=!0}var k,l,m=(15&f.flags,f.pixel_size>>3),n=f.width*f.height*m;if(h&&(l=d.subarray(e,e+=f.colormap_length*(f.colormap_size>>3))),g){k=new Uint8Array(n);for(var o,p,q,r=0,s=new Uint8Array(m);n>e;)if(o=d[e++],p=(127&o)+1,128&o){for(q=0;m>q;++q)s[q]=d[e++];for(q=0;p>q;++q)k.set(s,r+q*m);r+=m*p}else{for(p*=m,q=0;p>q;++q)k[r+q]=d[e++];r+=p}}else k=d.subarray(e,e+=h?f.width*f.height:n);var t,u,v,w,x,y;switch((f.flags&b._ORIGIN_MASK)>>b._ORIGIN_SHIFT){default:case b._ORIGIN_UL:t=0,v=1,y=f.width,u=0,w=1,x=f.height;break;case b._ORIGIN_BL:t=0,v=1,y=f.width,u=f.height-1,w=-1,x=-1;break;case b._ORIGIN_UR:t=f.width-1,v=-1,y=-1,u=0,w=1,x=f.height;break;case b._ORIGIN_BR:t=f.width-1,v=-1,y=-1,u=f.height-1,w=-1,x=-1}var z="_getImageData"+(j?"Grey":"")+f.pixel_size+"bits",A=b[z](f,l,k,u,w,x,t,v,y);c.texImage2D(c.TEXTURE_2D,0,c.RGBA,f.width,f.height,0,c.RGBA,c.UNSIGNED_BYTE,A)},b._getImageData8bits=function(a,b,c,d,e,f,g,h,i){var j,k,l,m=c,n=b,o=a.width,p=a.height,q=0,r=new Uint8Array(o*p*4);for(l=d;l!==f;l+=e)for(k=g;k!==i;k+=h,q++)j=m[q],r[4*(k+o*l)+3]=255,r[4*(k+o*l)+2]=n[3*j+0],r[4*(k+o*l)+1]=n[3*j+1],r[4*(k+o*l)+0]=n[3*j+2];return r},b._getImageData16bits=function(a,b,c,d,e,f,g,h,i){var j,k,l,m=c,n=a.width,o=a.height,p=0,q=new Uint8Array(n*o*4);for(l=d;l!==f;l+=e)for(k=g;k!==i;k+=h,p+=2)j=m[p+0]+(m[p+1]<<8),q[4*(k+n*l)+0]=(31744&j)>>7,q[4*(k+n*l)+1]=(992&j)>>2,q[4*(k+n*l)+2]=(31&j)>>3,q[4*(k+n*l)+3]=32768&j?0:255;return q},b._getImageData24bits=function(a,b,c,d,e,f,g,h,i){var j,k,l=c,m=a.width,n=a.height,o=0,p=new Uint8Array(m*n*4);for(k=d;k!==f;k+=e)for(j=g;j!==i;j+=h,o+=3)p[4*(j+m*k)+3]=255,p[4*(j+m*k)+2]=l[o+0],p[4*(j+m*k)+1]=l[o+1],p[4*(j+m*k)+0]=l[o+2];return p},b._getImageData32bits=function(a,b,c,d,e,f,g,h,i){var j,k,l=c,m=a.width,n=a.height,o=0,p=new Uint8Array(m*n*4);for(k=d;k!==f;k+=e)for(j=g;j!==i;j+=h,o+=4)p[4*(j+m*k)+2]=l[o+0],p[4*(j+m*k)+1]=l[o+1],p[4*(j+m*k)+0]=l[o+2],p[4*(j+m*k)+3]=l[o+3];return p},b._getImageDataGrey8bits=function(a,b,c,d,e,f,g,h,i){var j,k,l,m=c,n=a.width,o=a.height,p=0,q=new Uint8Array(n*o*4);for(l=d;l!==f;l+=e)for(k=g;k!==i;k+=h,p++)j=m[p],q[4*(k+n*l)+0]=j,q[4*(k+n*l)+1]=j,q[4*(k+n*l)+2]=j,q[4*(k+n*l)+3]=255;return q},b._getImageDataGrey16bits=function(a,b,c,d,e,f,g,h,i){var j,k,l=c,m=a.width,n=a.height,o=0,p=new Uint8Array(m*n*4);for(k=d;k!==f;k+=e)for(j=g;j!==i;j+=h,o+=2)p[4*(j+m*k)+0]=l[o+0],p[4*(j+m*k)+1]=l[o+0],p[4*(j+m*k)+2]=l[o+0],p[4*(j+m*k)+3]=l[o+1];return p},b._TYPE_NO_DATA=0,b._TYPE_INDEXED=1,b._TYPE_RGB=2,b._TYPE_GREY=3,b._TYPE_RLE_INDEXED=9,b._TYPE_RLE_RGB=10,b._TYPE_RLE_GREY=11,b._ORIGIN_MASK=48,b._ORIGIN_SHIFT=4,b._ORIGIN_BL=0,b._ORIGIN_BR=1,b._ORIGIN_UL=2,b._ORIGIN_UR=3,b}();b.TGATools=c}(a.Internals||(a.Internals={}));a.Internals}(BABYLON||(BABYLON={}));var BABYLON;!function(a){!function(b){function c(a){return a.charCodeAt(0)+(a.charCodeAt(1)<<8)+(a.charCodeAt(2)<<16)+(a.charCodeAt(3)<<24)}function d(a){return String.fromCharCode(255&a,a>>8&255,a>>16&255,a>>24&255)}var e=542327876,f=131072,g=512,h=4,i=64,j=131072,k=c("DXT1"),l=c("DXT3"),m=c("DXT5"),n=31,o=0,p=1,q=2,r=3,s=4,t=7,u=20,v=21,w=22,x=28,y=function(){function b(){}return b.GetDDSInfo=function(a){var b=new Int32Array(a,0,n),c=1;return b[q]&f&&(c=Math.max(1,b[t])),{width:b[s],height:b[r],mipmapCount:c,isFourCC:(b[u]&h)===h,isRGB:(b[u]&i)===i,isLuminance:(b[u]&j)===j,isCube:(b[x]&g)===g}},b.GetRGBAArrayBuffer=function(a,b,c,d,e){for(var f=new Uint8Array(d),g=new Uint8Array(e),h=0,i=b-1;i>=0;i--)for(var j=0;a>j;j++){var k=c+4*(j+i*a);f[h+2]=g[k],f[h+1]=g[k+1],f[h]=g[k+2],f[h+3]=g[k+3],h+=4}return f},b.GetRGBArrayBuffer=function(a,b,c,d,e){for(var f=new Uint8Array(d),g=new Uint8Array(e),h=0,i=b-1;i>=0;i--)for(var j=0;a>j;j++){var k=c+3*(j+i*a);f[h+2]=g[k],f[h+1]=g[k+1],f[h]=g[k+2],h+=3}return f},b.GetLuminanceArrayBuffer=function(a,b,c,d,e){for(var f=new Uint8Array(d),g=new Uint8Array(e),h=0,i=b-1;i>=0;i--)for(var j=0;a>j;j++){var k=c+(j+i*a);f[h]=g[k],h++}return f},b.UploadDDSLevels=function(c,g,h,i,j,u){var x,y,z,A,B,C,D,E,F,G,H=new Int32Array(h,0,n);if(H[o]!=e)return void a.Tools.Error("Invalid magic number in DDS header");if(!i.isFourCC&&!i.isRGB&&!i.isLuminance)return void a.Tools.Error("Unsupported format, must contain a FourCC, RGB or LUMINANCE code");if(i.isFourCC)switch(x=H[v]){case k:y=8,z=g.COMPRESSED_RGBA_S3TC_DXT1_EXT;break;case l:y=16,z=g.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case m:y=16,z=g.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return void console.error("Unsupported FourCC code:",d(x))}F=1,H[q]&f&&j!==!1&&(F=Math.max(1,H[t]));for(var I=H[w],J=0;u>J;J++){var K=1==u?c.TEXTURE_2D:c.TEXTURE_CUBE_MAP_POSITIVE_X+J;for(A=H[s],B=H[r],D=H[p]+4,G=0;F>G;++G){if(i.isRGB)24==I?(C=A*B*3,E=b.GetRGBArrayBuffer(A,B,D,C,h),c.texImage2D(K,G,c.RGB,A,B,0,c.RGB,c.UNSIGNED_BYTE,E)):(C=A*B*4,E=b.GetRGBAArrayBuffer(A,B,D,C,h),c.texImage2D(K,G,c.RGBA,A,B,0,c.RGBA,c.UNSIGNED_BYTE,E));else if(i.isLuminance){var L=c.getParameter(c.UNPACK_ALIGNMENT),M=A,N=Math.floor((A+L-1)/L)*L;C=N*(B-1)+M,E=b.GetLuminanceArrayBuffer(A,B,D,C,h),c.texImage2D(K,G,c.LUMINANCE,A,B,0,c.LUMINANCE,c.UNSIGNED_BYTE,E)}else C=Math.max(4,A)/4*Math.max(4,B)/4*y,E=new Uint8Array(h,D,C),c.compressedTexImage2D(K,G,z,A,B,0,E);D+=C,A*=.5,B*=.5,A=Math.max(1,A),B=Math.max(1,B)}}},b}();b.DDSTools=y}(a.Internals||(a.Internals={}));a.Internals}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function a(b){this.length=0,this._duplicateId=0,this.data=new Array(b),this._id=a._GlobalId++}return a.prototype.push=function(a){this.data[this.length++]=a,this.length>this.data.length&&(this.data.length*=2),a.__smartArrayFlags||(a.__smartArrayFlags={}),a.__smartArrayFlags[this._id]=this._duplicateId},a.prototype.pushNoDuplicate=function(a){a.__smartArrayFlags&&a.__smartArrayFlags[this._id]===this._duplicateId||this.push(a) },a.prototype.sort=function(a){this.data.sort(a)},a.prototype.reset=function(){this.length=0,this._duplicateId++},a.prototype.concat=function(a){if(0!==a.length){this.length+a.length>this.data.length&&(this.data.length=2*(this.length+a.length));for(var b=0;bthis.data.length&&(this.data.length=2*(this.length+a.length));for(var b=0;b=this.length?-1:b},a._GlobalId=0,a}();a.SmartArray=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function b(){this._registeredMeshes=[],this._physicsMaterials=[],this.updateBodyPosition=function(a){for(var b=0;bthis.value;case b.IsLesser:return this._target[this._property]-1&&this._scene._actionManagers.splice(a,1)},b.prototype.getScene=function(){return this._scene},b.prototype.hasSpecificTriggers=function(a){for(var b=0;b-1)return!0}return!1},Object.defineProperty(b.prototype,"hasPointerTriggers",{get:function(){for(var a=0;a=b._OnPickTrigger&&c.trigger<=b._OnPointerOutTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"hasPickTriggers",{get:function(){for(var a=0;a=b._OnPickTrigger&&c.trigger<=b._OnCenterPickTrigger)return!0}return!1},enumerable:!0,configurable:!0}),b.prototype.registerAction=function(c){return c.trigger===b.OnEveryFrameTrigger&&this.getScene().actionManager!==this?(a.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager"),null):(this.actions.push(c),c._actionManager=this,c._prepare(),c)},b.prototype.processTrigger=function(a,c){for(var d=0;di;i++){var j=g[i];j._resetPointsArrayCache(),j._boundingInfo=new a.BoundingInfo(f.minimum,f.maximum),j._createGlobalSubMesh(),j.computeWorldMatrix(!0)}}},b.prototype.updateVerticesData=function(b,c,d){var e=this.getVertexBuffer(b);if(e&&(e.update(c),b===a.VertexBuffer.PositionKind)){var f;if(d){var g=e.getStrideSize();this._totalVertices=c.length/g,f=a.Tools.ExtractMinAndMax(c,0,this._totalVertices)}for(var h=this._meshes,i=h.length,j=0;i>j;j++){var k=h[j];k._resetPointsArrayCache(),d&&(k._boundingInfo=new a.BoundingInfo(f.minimum,f.maximum))}}},b.prototype.getTotalVertices=function(){return this.isReady()?this._totalVertices:0},b.prototype.getVerticesData=function(a){var b=this.getVertexBuffer(a);return b?b.getData():null},b.prototype.getVertexBuffer=function(a){return this.isReady()?this._vertexBuffers[a]:null},b.prototype.getVertexBuffers=function(){return this.isReady()?this._vertexBuffers:null},b.prototype.isVerticesDataPresent=function(a){return this._vertexBuffers?void 0!==this._vertexBuffers[a]:this._delayInfo?-1!==this._delayInfo.indexOf(a):!1},b.prototype.getVerticesDataKinds=function(){var a=[];if(!this._vertexBuffers&&this._delayInfo)for(var b in this._delayInfo)a.push(b);else for(b in this._vertexBuffers)a.push(b);return a},b.prototype.setIndices=function(a){this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indices=a,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices));for(var b=this._meshes,c=b.length,d=0;c>d;d++)b[d]._createGlobalSubMesh()},b.prototype.getTotalIndices=function(){return this.isReady()?this._indices.length:0},b.prototype.getIndices=function(){return this.isReady()?this._indices:null},b.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},b.prototype.releaseForMesh=function(a,b){var c=this._meshes,d=c.indexOf(a);if(-1!==d){for(var e in this._vertexBuffers)this._vertexBuffers[e].dispose();this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),c.splice(d,1),a._geometry=null,0==c.length&&b&&this.dispose()}},b.prototype.applyToMesh=function(a){if(a._geometry!==this){var b=a._geometry;b&&b.releaseForMesh(a);var c=this._meshes;a._geometry=this,this._scene.pushGeometry(this),c.push(a),this.isReady()?this._applyToMesh(a):a._boundingInfo=this._boundingInfo}},b.prototype._applyToMesh=function(b){var c=this._meshes.length;for(var d in this._vertexBuffers)if(1===c&&this._vertexBuffers[d].create(),this._vertexBuffers[d]._buffer.references=c,d===a.VertexBuffer.PositionKind){b._resetPointsArrayCache();var e=a.Tools.ExtractMinAndMax(this._vertexBuffers[d].getData(),0,this._totalVertices);b._boundingInfo=new a.BoundingInfo(e.minimum,e.maximum),b._createGlobalSubMesh()}1===c&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=c)},b.prototype.load=function(b,c){var d=this;if(this.delayLoadState!==a.Engine.DELAYLOADSTATE_LOADING){if(this.isReady())return void(c&&c());this.delayLoadState=a.Engine.DELAYLOADSTATE_LOADING,b._addPendingData(this),a.Tools.LoadFile(this.delayLoadingFile,function(e){d._delayLoadingFunction(JSON.parse(e),d),d.delayLoadState=a.Engine.DELAYLOADSTATE_LOADED,d._delayInfo=[],b._removePendingData(d);for(var f=d._meshes,g=f.length,h=0;g>h;h++)d._applyToMesh(f[h]);c&&c()},function(){},b.database)}},b.prototype.dispose=function(){for(var b=this._meshes,c=b.length,d=0;c>d;d++)this.releaseForMesh(b[d]);this._meshes=[];for(var e in this._vertexBuffers)this._vertexBuffers[e].dispose();this._vertexBuffers=[],this._totalVertices=0,this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indexBuffer=null,this._indices=[],this.delayLoadState=a.Engine.DELAYLOADSTATE_NONE,this.delayLoadingFile=null,this._delayLoadingFunction=null,this._delayInfo=[],this._boundingInfo=null;var f=this._scene.getGeometries();d=f.indexOf(this),d>-1&&f.splice(d,1)},b.prototype.copy=function(b){var c=new a.VertexData;c.indices=[];for(var d=this.getIndices(),e=0;eto activate gamepad",b.gamepadDOMInfo.appendChild(a),b.gamepadDOMInfo.appendChild(c),b.gamepadDOMInfo.style.position="absolute",b.gamepadDOMInfo.style.width="100%",b.gamepadDOMInfo.style.height="48px",b.gamepadDOMInfo.style.bottom="0px",b.gamepadDOMInfo.style.backgroundColor="rgba(1, 1, 1, 0.15)",b.gamepadDOMInfo.style.textAlign="center",b.gamepadDOMInfo.style.zIndex="10",a.style.position="relative",a.style.bottom="8px",c.style.position="relative",c.style.fontSize="32px",c.style.bottom="32px",c.style.color="green",document.body.appendChild(b.gamepadDOMInfo)},b.prototype._insertGamepadDOMNotSupported=function(){b.gamepadDOMInfo=document.createElement("div");var a=document.createElement("span");a.innerHTML="gamepad not supported",b.gamepadDOMInfo.appendChild(a),b.gamepadDOMInfo.style.position="absolute",b.gamepadDOMInfo.style.width="100%",b.gamepadDOMInfo.style.height="40px",b.gamepadDOMInfo.style.bottom="0px",b.gamepadDOMInfo.style.backgroundColor="rgba(1, 1, 1, 0.15)",b.gamepadDOMInfo.style.textAlign="center",b.gamepadDOMInfo.style.zIndex="10",a.style.position="relative",a.style.fontSize="32px",a.style.color="red",document.body.appendChild(b.gamepadDOMInfo)},b.prototype.dispose=function(){document.body.removeChild(b.gamepadDOMInfo)},b.prototype._onGamepadConnected=function(a){var b=this._addNewGamepad(a.gamepad);this._callbackGamepadConnected&&this._callbackGamepadConnected(b),this._startMonitoringGamepads()},b.prototype._addNewGamepad=function(c){this.oneGamepadConnected||(this.oneGamepadConnected=!0,b.gamepadDOMInfo&&(document.body.removeChild(b.gamepadDOMInfo),b.gamepadDOMInfo=null));var d;return d=-1!==c.id.search("Xbox 360")||-1!==c.id.search("xinput")?new a.Xbox360Pad(c.id,c.index,c):new a.GenericPad(c.id,c.index,c),this.babylonGamepads.push(d),d},b.prototype._onGamepadDisconnected=function(a){for(var b in this.babylonGamepads)if(this.babylonGamepads[b].index==a.gamepad.index){this.babylonGamepads.splice(b,1);break}0==this.babylonGamepads.length&&this._stopMonitoringGamepads()},b.prototype._startMonitoringGamepads=function(){this.isMonitoring||(this.isMonitoring=!0,this._checkGamepadsStatus())},b.prototype._stopMonitoringGamepads=function(){this.isMonitoring=!1},b.prototype._checkGamepadsStatus=function(){var a=this;this._updateGamepadObjects();for(var b in this.babylonGamepads)this.babylonGamepads[b].update();this.isMonitoring&&(window.requestAnimationFrame?window.requestAnimationFrame(function(){a._checkGamepadsStatus()}):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(function(){a._checkGamepadsStatus()}):window.webkitRequestAnimationFrame&&window.webkitRequestAnimationFrame(function(){a._checkGamepadsStatus()}))},b.prototype._updateGamepadObjects=function(){for(var a=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[],b=0;b=2&&(this._leftStick={x:this.browserGamepad.axes[0],y:this.browserGamepad.axes[1]}),this.browserGamepad.axes.length>=4&&(this._rightStick={x:this.browserGamepad.axes[2],y:this.browserGamepad.axes[3]})}return a.prototype.onleftstickchanged=function(a){this._onleftstickchanged=a},a.prototype.onrightstickchanged=function(a){this._onrightstickchanged=a},Object.defineProperty(a.prototype,"leftStick",{get:function(){return this._leftStick},set:function(a){!this._onleftstickchanged||this._leftStick.x===a.x&&this._leftStick.y===a.y||this._onleftstickchanged(a),this._leftStick=a},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"rightStick",{get:function(){return this._rightStick},set:function(a){!this._onrightstickchanged||this._rightStick.x===a.x&&this._rightStick.y===a.y||this._onrightstickchanged(a),this._rightStick=a},enumerable:!0,configurable:!0}),a.prototype.update=function(){this._leftStick&&(this.leftStick={x:this.browserGamepad.axes[0],y:this.browserGamepad.axes[1]}),this._rightStick&&(this.rightStick={x:this.browserGamepad.axes[2],y:this.browserGamepad.axes[3]})},a}();a.Gamepad=d;var e=function(a){function b(b,c,d){a.call(this,b,c,d),this.id=b,this.index=c,this.gamepad=d,this._buttons=new Array(d.buttons.length)}return __extends(b,a),b.prototype.onbuttondown=function(a){this._onbuttondown=a},b.prototype.onbuttonup=function(a){this._onbuttonup=a},b.prototype._setButtonValue=function(a,b,c){return a!==b&&(this._onbuttondown&&1===a&&this._onbuttondown(c),this._onbuttonup&&0===a&&this._onbuttonup(c)),a},b.prototype.update=function(){a.prototype.update.call(this);for(var b=0;b.005?0+c:0,b.y=Math.abs(d)>.005?0+d:0;var e=this._gamepad.rightStick,f=e.x/this.angularSensibility,g=e.y/this.angularSensibility;e.x=Math.abs(f)>.001?0+f:0,e.y=Math.abs(g)>.001?0+g:0;var h=a.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),i=a.Vector3.TransformCoordinates(new a.Vector3(b.x,0,-b.y),h);this.cameraDirection=this.cameraDirection.add(i),this.cameraRotation=this.cameraRotation.add(new a.Vector3(e.y,e.x,0))}},c.prototype.dispose=function(){this._gamepads.dispose()},c}(a.FreeCamera);a.GamepadCamera=b}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},BABYLON;!function(a){var b=function(b){function c(c,d,e){"undefined"==typeof e&&(e=!1),b.call(this,c,d),this.color=new a.Color3(1,1,1),this._indices=new Array,this._colorShader=new a.ShaderMaterial("colorShader",d,"color",{attributes:["position"],uniforms:["worldViewProjection","color"]})}return __extends(c,b),Object.defineProperty(c.prototype,"material",{get:function(){return this._colorShader},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"isPickable",{get:function(){return!1},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"checkCollisions",{get:function(){return!1},enumerable:!0,configurable:!0}),c.prototype._bind=function(){var b=this.getScene().getEngine(),c=this._geometry.getIndexBuffer();b.bindBuffers(this._geometry.getVertexBuffer(a.VertexBuffer.PositionKind).getBuffer(),c,[3],12,this._colorShader.getEffect()),this._colorShader.setColor3("color",this.color)},c.prototype._draw=function(a){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var b=this.getScene().getEngine();b.draw(!1,a.indexStart,a.indexCount)}},c.prototype.intersects=function(){return null},c.prototype.dispose=function(a){this._colorShader.dispose(),b.prototype.dispose.call(this,a)},c}(a.Mesh);a.LinesMesh=b}(BABYLON||(BABYLON={}));