/*! Babylon 2015-02-09 */ 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(){function a(a,b,c){void 0===a&&(a=0),void 0===b&&(b=0),void 0===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){return void 0===b&&(b=0),a[b]=this.r,a[b+1]=this.g,a[b+2]=this.b,this},a.prototype.toColor4=function(a){return void 0===a&&(a=1),new c(this.r,this.g,this.b,a)},a.prototype.asArray=function(){var a=[];return this.toArray(a,0),a},a.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},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){return b.r=this.r*a.r,b.g=this.g*a.g,b.b=this.b*a.b,this},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){return b.r=this.r*a,b.g=this.g*a,b.b=this.b*a,this},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){return b.r=this.r+a.r,b.g=this.g+a.g,b.b=this.b+a.b,this},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){return b.r=this.r-a.r,b.g=this.g-a.g,b.b=this.b-a.b,this},a.prototype.clone=function(){return new a(this.r,this.g,this.b)},a.prototype.copyFrom=function(a){return this.r=a.r,this.g=a.g,this.b=a.b,this},a.prototype.copyFromFloats=function(a,b,c){return this.r=a,this.g=b,this.b=c,this},a.FromArray=function(b,c){return void 0===c&&(c=0),new a(b[c],b[c+1],b[c+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 a(a,b,c,d){this.r=a,this.g=b,this.b=c,this.a=d}return a.prototype.addInPlace=function(a){return this.r+=a.r,this.g+=a.g,this.b+=a.b,this.a+=a.a,this},a.prototype.asArray=function(){var a=[];return this.toArray(a,0),a},a.prototype.toArray=function(a,b){return void 0===b&&(b=0),a[b]=this.r,a[b+1]=this.g,a[b+2]=this.b,a[b+3]=this.a,this},a.prototype.add=function(b){return new a(this.r+b.r,this.g+b.g,this.b+b.b,this.a+b.a)},a.prototype.subtract=function(b){return new a(this.r-b.r,this.g-b.g,this.b-b.b,this.a-b.a)},a.prototype.subtractToRef=function(a,b){return b.r=this.r-a.r,b.g=this.g-a.g,b.b=this.b-a.b,b.a=this.a-a.a,this},a.prototype.scale=function(b){return new a(this.r*b,this.g*b,this.b*b,this.a*b)},a.prototype.scaleToRef=function(a,b){return b.r=this.r*a,b.g=this.g*a,b.b=this.b*a,b.a=this.a*a,this},a.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},a.prototype.clone=function(){return new a(this.r,this.g,this.b,this.a)},a.prototype.copyFrom=function(a){return this.r=a.r,this.g=a.g,this.b=a.b,this.a=a.a,this},a.Lerp=function(b,c,d){var e=new a(0,0,0,0);return a.LerpToRef(b,c,d,e),e},a.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},a.FromArray=function(b,c){return void 0===c&&(c=0),new a(b[c],b[c+1],b[c+2],b[c+3])},a.FromInts=function(b,c,d,e){return new a(b/255,c/255,d/255,e/255)},a}();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){return void 0===b&&(b=0),a[b]=this.x,a[b+1]=this.y,this},a.prototype.asArray=function(){var a=[];return this.toArray(a,0),a},a.prototype.copyFrom=function(a){return this.x=a.x,this.y=a.y,this},a.prototype.copyFromFloats=function(a,b){return this.x=a,this.y=b,this},a.prototype.add=function(b){return new a(this.x+b.x,this.y+b.y)},a.prototype.addVector3=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.subtractInPlace=function(a){return this.x-=a.x,this.y-=a.y,this},a.prototype.multiplyInPlace=function(a){return this.x*=a.x,this.y*=a.y,this},a.prototype.multiply=function(b){return new a(this.x*b.x,this.y*b.y)},a.prototype.multiplyToRef=function(a,b){return b.x=this.x*a.x,b.y=this.y*a.y,this},a.prototype.multiplyByFloats=function(b,c){return new a(this.x*b,this.y*c)},a.prototype.divide=function(b){return new a(this.x/b.x,this.y/b.y)},a.prototype.divideToRef=function(a,b){return b.x=this.x/a.x,b.y=this.y/a.y,this},a.prototype.negate=function(){return new a(-this.x,-this.y)},a.prototype.scaleInPlace=function(a){return this.x*=a,this.y*=a,this},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)return this;var b=1/a;return this.x*=b,this.y*=b,this},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 void 0===c&&(c=0),new a(b[c],b[c+1])},a.FromArrayToRef=function(a,b,c){c.x=a[b],c.y=a[b+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){return void 0===b&&(b=0),a[b]=this.x,a[b+1]=this.y,a[b+2]=this.z,this},b.prototype.toQuaternion=function(){var a=new g(0,0,0,1),b=Math.cos(.5*(this.x+this.z)),c=Math.sin(.5*(this.x+this.z)),d=Math.cos(.5*(this.z-this.x)),e=Math.sin(.5*(this.z-this.x)),f=Math.cos(.5*this.y),h=Math.sin(.5*this.y);return a.x=d*h,a.y=-e*h,a.z=c*f,a.w=b*f,a},b.prototype.addInPlace=function(a){return this.x+=a.x,this.y+=a.y,this.z+=a.z,this},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){return b.x=this.x+a.x,b.y=this.y+a.y,b.z=this.z+a.z,this},b.prototype.subtractInPlace=function(a){return this.x-=a.x,this.y-=a.y,this.z-=a.z,this},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){return b.x=this.x-a.x,b.y=this.y-a.y,b.z=this.z-a.z,this},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){return d.x=this.x-a,d.y=this.y-b,d.z=this.z-c,this},b.prototype.negate=function(){return new b(-this.x,-this.y,-this.z)},b.prototype.scaleInPlace=function(a){return this.x*=a,this.y*=a,this.z*=a,this},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),this},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)return this;var b=1/a;return this.x*=b,this.y*=b,this.z*=b,this},b.prototype.clone=function(){return new b(this.x,this.y,this.z)},b.prototype.copyFrom=function(a){return this.x=a.x,this.y=a.y,this.z=a.z,this},b.prototype.copyFromFloats=function(a,b,c){return this.x=a,this.y=b,this.z=c,this},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=gthis.x&&(this.x=a.x),a.y>this.y&&(this.y=a.y),a.z>this.z&&(this.z=a.z),a.w>this.w&&(this.w=a.w),this},b.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},b.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},b.prototype.normalize=function(){var a=this.length();if(0===a)return this;var b=1/a;return this.x*=b,this.y*=b,this.z*=b,this.w*=b,this},b.prototype.clone=function(){return new b(this.x,this.y,this.z,this.w)},b.prototype.copyFrom=function(a){return this.x=a.x,this.y=a.y,this.z=a.z,this.w=a.w,this},b.prototype.copyFromFloats=function(a,b,c,d){return this.x=a,this.y=b,this.z=c,this.w=d,this},b.FromArray=function(a,c){return c||(c=0),new b(a[c],a[c+1],a[c+2],a[c+3])},b.FromArrayToRef=function(a,b,c){c.x=a[b],c.y=a[b+1],c.z=a[b+2],c.w=a[b+3]},b.FromFloatArrayToRef=function(a,b,c){c.x=a[b],c.y=a[b+1],c.z=a[b+2],c.w=a[b+3]},b.FromFloatsToRef=function(a,b,c,d,e){e.x=a,e.y=b,e.z=c,e.w=d},b.Zero=function(){return new b(0,0,0,0)},b.Normalize=function(a){var c=b.Zero();return b.NormalizeToRef(a,c),c},b.NormalizeToRef=function(a,b){b.copyFrom(a),b.normalize()},b.Minimize=function(a,b){var c=a.clone();return c.MinimizeInPlace(b),c},b.Maximize=function(a,b){var c=a.clone();return c.MaximizeInPlace(b),c},b.Distance=function(a,c){return Math.sqrt(b.DistanceSquared(a,c))},b.DistanceSquared=function(a,b){var c=a.x-b.x,d=a.y-b.y,e=a.z-b.z,f=a.w-b.w;return c*c+d*d+e*e+f*f},b.Center=function(a,b){var c=a.add(b);return c.scaleInPlace(.5),c},b}();a.Vector4=f;var g=function(){function a(a,b,c,d){void 0===a&&(a=0),void 0===b&&(b=0),void 0===c&&(c=0),void 0===d&&(d=1),this.x=a,this.y=b,this.z=c,this.w=d}return a.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},a.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},a.prototype.equals=function(a){return a&&this.x===a.x&&this.y===a.y&&this.z===a.z&&this.w===a.w},a.prototype.clone=function(){return new a(this.x,this.y,this.z,this.w)},a.prototype.copyFrom=function(a){return this.x=a.x,this.y=a.y,this.z=a.z,this.w=a.w,this},a.prototype.copyFromFloats=function(a,b,c,d){return this.x=a,this.y=b,this.z=c,this.w=d,this},a.prototype.add=function(b){return new a(this.x+b.x,this.y+b.y,this.z+b.z,this.w+b.w)},a.prototype.subtract=function(b){return new a(this.x-b.x,this.y-b.y,this.z-b.z,this.w-b.w)},a.prototype.scale=function(b){return new a(this.x*b,this.y*b,this.z*b,this.w*b)},a.prototype.multiply=function(b){var c=new a(0,0,0,1);return this.multiplyToRef(b,c),c},a.prototype.multiplyToRef=function(a,b){return b.x=this.x*a.w+this.y*a.z-this.z*a.y+this.w*a.x,b.y=-this.x*a.z+this.y*a.w+this.z*a.x+this.w*a.y,b.z=this.x*a.y-this.y*a.x+this.z*a.w+this.w*a.z,b.w=-this.x*a.x-this.y*a.y-this.z*a.z+this.w*a.w,this},a.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},a.prototype.normalize=function(){var a=1/this.length();return this.x*=a,this.y*=a,this.z*=a,this.w*=a,this},a.prototype.toEulerAngles=function(){var a=e.Zero();return this.toEulerAnglesToRef(a),a},a.prototype.toEulerAnglesToRef=function(a){var b=this.x,c=this.y,d=this.z,e=this.w,f=b*c,g=b*d,h=e*c,i=e*d,j=e*b,k=c*d,l=b*b,m=c*c,n=l+m;return 0!==n&&1!==n?(a.x=Math.atan2(g+h,j-k),a.y=Math.acos(1-2*n),a.z=Math.atan2(g-h,j+k)):0===n?(a.x=0,a.y=0,a.z=Math.atan2(f-i,.5-m-d*d)):(a.x=Math.atan2(f-i,.5-m-d*d),a.y=Math.PI,a.z=0),this},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;return 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,this},a.prototype.fromRotationMatrix=function(b){return a.FromRotationMatrixToRef(b,this),this},a.FromRotationMatrix=function(b){var c=new a;return a.FromRotationMatrixToRef(b,c),c},a.FromRotationMatrixToRef=function(a,b){var c,d=a.m,e=d[0],f=d[4],g=d[8],h=d[1],i=d[5],j=d[9],k=d[2],l=d[6],m=d[10],n=e+i+m;n>0?(c=.5/Math.sqrt(n+1),b.w=.25/c,b.x=(l-j)*c,b.y=(g-k)*c,b.z=(h-f)*c):e>i&&e>m?(c=2*Math.sqrt(1+e-i-m),b.w=(l-j)/c,b.x=.25*c,b.y=(f+h)/c,b.z=(g+k)/c):i>m?(c=2*Math.sqrt(1+i-e-m),b.w=(g-k)/c,b.x=(f+h)/c,b.y=.25*c,b.z=(j+l)/c):(c=2*Math.sqrt(1+m-e-i),b.w=(h-f)/c,b.x=(g+k)/c,b.y=(j+l)/c,b.z=.25*c)},a.Inverse=function(b){return new a(-b.x,-b.y,-b.z,b.w)},a.Identity=function(){return new a(0,0,0,1)},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=g;var h=function(){function b(){this.m=new Float32Array(16)}return b.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},b.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)},b.prototype.toArray=function(){return this.m},b.prototype.asArray=function(){return this.toArray()},b.prototype.invert=function(){return this.invertToRef(this),this},b.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;return 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,this},b.prototype.setTranslation=function(a){return this.m[12]=a.x,this.m[13]=a.y,this.m[14]=a.z,this},b.prototype.multiply=function(a){var c=new b;return this.multiplyToRef(a,c),c},b.prototype.copyFrom=function(a){for(var b=0;16>b;b++)this.m[b]=a.m[b];return this},b.prototype.copyToArray=function(a,b){void 0===b&&(b=0);for(var c=0;16>c;c++)a[b+c]=this.m[c];return this},b.prototype.multiplyToRef=function(a,b){return this.multiplyToArray(a,b.m,0),this},b.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];return 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,this},b.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]},b.prototype.clone=function(){return b.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])},b.prototype.decompose=function(c,d,e){e.x=this.m[12],e.y=this.m[13],e.z=this.m[14];var f=a.Tools.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,h=a.Tools.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,i=a.Tools.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(c.x=f*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),c.y=h*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),c.z=i*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===c.x||0===c.y||0===c.z)return d.x=0,d.y=0,d.z=0,d.w=1,!1;var j=b.FromValues(this.m[0]/c.x,this.m[1]/c.x,this.m[2]/c.x,0,this.m[4]/c.y,this.m[5]/c.y,this.m[6]/c.y,0,this.m[8]/c.z,this.m[9]/c.z,this.m[10]/c.z,0,0,0,0,1);return g.FromRotationMatrixToRef(j,d),!0},b.FromArray=function(a,c){var d=new b;return c||(c=0),b.FromArrayToRef(a,c,d),d},b.FromArrayToRef=function(a,b,c){for(var d=0;16>d;d++)c.m[d]=a[d+b]},b.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},b.FromValues=function(a,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){var r=new b;return r.m[0]=a,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},b.Compose=function(a,c,d){var e=b.FromValues(a.x,0,0,0,0,a.y,0,0,0,0,a.z,0,0,0,0,1),f=b.Identity();return c.toRotationMatrix(f),e=e.multiply(f),e.setTranslation(d),e},b.Identity=function(){return b.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},b.IdentityToRef=function(a){b.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,a)},b.Zero=function(){return b.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},b.RotationX=function(a){var c=new b;return b.RotationXToRef(a,c),c},b.Invert=function(a){var c=new b;return a.invertToRef(c),c},b.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},b.RotationY=function(a){var c=new b;return b.RotationYToRef(a,c),c},b.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},b.RotationZ=function(a){var c=new b;return b.RotationZToRef(a,c),c},b.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},b.RotationAxis=function(a,c){var d=Math.sin(-c),e=Math.cos(-c),f=1-e;a.normalize();var g=b.Zero();return g.m[0]=a.x*a.x*f+e,g.m[1]=a.x*a.y*f-a.z*d,g.m[2]=a.x*a.z*f+a.y*d,g.m[3]=0,g.m[4]=a.y*a.x*f+a.z*d,g.m[5]=a.y*a.y*f+e,g.m[6]=a.y*a.z*f-a.x*d,g.m[7]=0,g.m[8]=a.z*a.x*f-a.y*d,g.m[9]=a.z*a.y*f+a.x*d,g.m[10]=a.z*a.z*f+e,g.m[11]=0,g.m[15]=1,g},b.RotationYawPitchRoll=function(a,c,d){var e=new b;return b.RotationYawPitchRollToRef(a,c,d,e),e},b.RotationYawPitchRollToRef=function(a,b,c,d){g.RotationYawPitchRollToRef(a,b,c,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(d)},b.Scaling=function(a,c,d){var e=b.Zero();return b.ScalingToRef(a,c,d,e),e},b.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},b.Translation=function(a,c,d){var e=b.Identity();return b.TranslationToRef(a,c,d,e),e},b.TranslationToRef=function(a,c,d,e){b.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,a,c,d,1,e)},b.LookAtLH=function(a,c,d){var e=b.Zero();return b.LookAtLHToRef(a,c,d,e),e},b.LookAtLHToRef=function(a,c,d,f){c.subtractToRef(a,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,a),h=-e.Dot(this._yAxis,a),i=-e.Dot(this._zAxis,a);return b.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)},b.OrthoLH=function(a,c,d,e){var f=2/a,g=2/c,h=1/(e-d),i=d/(d-e);return b.FromValues(f,0,0,0,0,g,0,0,0,0,h,0,0,0,i,1)},b.OrthoOffCenterLH=function(a,c,d,e,f,g){var h=b.Zero();return b.OrthoOffCenterLHToRef(a,c,d,e,f,g,h),h},b.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},b.PerspectiveLH=function(a,c,d,e){var f=b.Zero();return f.m[0]=2*d/a,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},b.PerspectiveFovLH=function(a,c,d,e){var f=b.Zero();return b.PerspectiveFovLHToRef(a,c,d,e,f),f},b.PerspectiveFovLHToRef=function(b,c,d,e,f,g){void 0===g&&(g=a.Camera.FOVMODE_VERTICAL_FIXED);var h=1/Math.tan(.5*b),i=g===a.Camera.FOVMODE_VERTICAL_FIXED;f.m[0]=i?h/c:h,f.m[1]=f.m[2]=f.m[3]=0,f.m[5]=i?h:h*c,f.m[4]=f.m[6]=f.m[7]=0,f.m[8]=f.m[9]=0,f.m[10]=-e/(d-e),f.m[11]=1,f.m[12]=f.m[13]=f.m[15]=0,f.m[14]=d*e/(d-e)},b.GetFinalMatrix=function(a,c,d,e,f,g){var h=a.width,i=a.height,j=a.x,k=a.y,l=b.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)},b.Transpose=function(a){var c=new b;return c.m[0]=a.m[0],c.m[1]=a.m[4],c.m[2]=a.m[8],c.m[3]=a.m[12],c.m[4]=a.m[1],c.m[5]=a.m[5],c.m[6]=a.m[9],c.m[7]=a.m[13],c.m[8]=a.m[2],c.m[9]=a.m[6],c.m[10]=a.m[10],c.m[11]=a.m[14],c.m[12]=a.m[3],c.m[13]=a.m[7],c.m[14]=a.m[11],c.m[15]=a.m[15],c},b.Reflection=function(a){var c=new b;return b.ReflectionToRef(a,c),c},b.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},b._tempQuaternion=new g,b._xAxis=e.Zero(),b._yAxis=e.Zero(),b._zAxis=e.Zero(),b}();a.Matrix=h;var i=function(){function a(a,b,c,d){this.normal=new e(a,b,c),this.d=d}return a.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},a.prototype.clone=function(){return new a(this.normal.x,this.normal.y,this.normal.z,this.d)},a.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;return 0!==a&&(b=1/a),this.normal.x*=b,this.normal.y*=b,this.normal.z*=b,this.d*=b,this },a.prototype.transform=function(b){var c=h.Transpose(b),d=this.normal.x,e=this.normal.y,f=this.normal.z,g=this.d,i=d*c.m[0]+e*c.m[1]+f*c.m[2]+g*c.m[3],j=d*c.m[4]+e*c.m[5]+f*c.m[6]+g*c.m[7],k=d*c.m[8]+e*c.m[9]+f*c.m[10]+g*c.m[11],l=d*c.m[12]+e*c.m[13]+f*c.m[14]+g*c.m[15];return new a(i,j,k,l)},a.prototype.dotCoordinate=function(a){return this.normal.x*a.x+this.normal.y*a.y+this.normal.z*a.z+this.d},a.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);return 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),this},a.prototype.isFrontFacingTo=function(a,b){var c=e.Dot(this.normal,a);return b>=c},a.prototype.signedDistanceTo=function(a){return e.Dot(a,this.normal)+this.d},a.FromArray=function(b){return new a(b[0],b[1],b[2],b[3])},a.FromPoints=function(b,c,d){var e=new a(0,0,0,0);return e.copyFromPoints(b,c,d),e},a.FromPositionAndNormal=function(b,c){var d=new a(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},a.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},a}();a.Plane=i;var j=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=j;var k=function(){function a(){}return a.GetPlanes=function(b){for(var c=[],d=0;6>d;d++)c.push(new i(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=k;var l=function(){function b(a,b,c){void 0===c&&(c=Number.MAX_VALUE),this.origin=a,this.direction=b,this.length=c}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(g===-1/0&&(g=1/0),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,g===-1/0&&(g=1/0),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,g===-1/0&&(g=1/0),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=e.Zero(),this._edge2=e.Zero(),this._pvec=e.Zero(),this._tvec=e.Zero(),this._qvec=e.Zero()),c.subtractToRef(b,this._edge1),d.subtractToRef(b,this._edge2),e.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;if(0>i||h+i>1)return null;var j=e.Dot(this._edge2,this._qvec)*g;return j>this.length?null:new a.IntersectionInfo(h,i,j)},b.CreateNew=function(a,c,d,f,g,h,i){var j=e.Unproject(new e(a,c,0),d,f,g,h,i),k=e.Unproject(new e(a,c,1),d,f,g,h,i),l=k.subtract(j);return l.normalize(),new b(j,l)},b.CreateNewFromTo=function(a,c,d){void 0===d&&(d=h.Identity());var e=c.subtract(a),f=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);return e.normalize(),b.Transform(new b(a,e,f),d)},b.Transform=function(a,c){var d=e.TransformCoordinates(a.origin,c),f=e.TransformNormal(a.direction,c);return new b(d,f,a.length)},b}();a.Ray=l,function(a){a[a.LOCAL=0]="LOCAL",a[a.WORLD=1]="WORLD"}(a.Space||(a.Space={}));var m=(a.Space,function(){function a(){}return a.X=new e(1,0,0),a.Y=new e(0,1,0),a.Z=new e(0,0,1),a}());a.Axis=m;var n=function(){function a(){}return a.interpolate=function(a,b,c,d,e){for(var f=1-3*d+3*b,g=3*d-6*b,h=3*b,i=a,j=0;5>j;j++){var k=i*i,l=k*i,m=f*l+g*k+h*i,n=1/(3*f*k+2*g*i+h);i-=(m-a)*n,i=Math.min(1,Math.max(0,i))}return 3*Math.pow(1-i,2)*i*c+3*(1-i)*Math.pow(i,2)*e+Math.pow(i,3)},a}();a.BezierCurve=n,function(a){a[a.CW=0]="CW",a[a.CCW=1]="CCW"}(a.Orientation||(a.Orientation={}));var o=(a.Orientation,function(){function a(a){var b=this;this.degrees=function(){return 180*b._radians/Math.PI},this.radians=function(){return b._radians},this._radians=a,this._radians<0&&(this._radians+=2*Math.PI)}return a.BetweenTwoPoints=function(b,c){var d=c.subtract(b),e=Math.atan2(d.y,d.x);return new a(e)},a.FromRadians=function(b){return new a(b)},a.FromDegrees=function(b){return new a(b*Math.PI/180)},a}());a.Angle=o;var p=function(){function a(a,b,c){this.startPoint=a,this.midPoint=b,this.endPoint=c;var e=Math.pow(b.x,2)+Math.pow(b.y,2),f=(Math.pow(a.x,2)+Math.pow(a.y,2)-e)/2,g=(e-Math.pow(c.x,2)-Math.pow(c.y,2))/2,h=(a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y);this.centerPoint=new d((f*(b.y-c.y)-g*(a.y-b.y))/h,((a.x-b.x)*g-(b.x-c.x)*f)/h),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=o.BetweenTwoPoints(this.centerPoint,this.startPoint);var i=this.startAngle.degrees(),j=o.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),k=o.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();j-i>180&&(j-=360),-180>j-i&&(j+=360),k-j>180&&(k-=360),-180>k-j&&(k+=360),this.orientation=0>j-i?0:1,this.angle=o.FromDegrees(0===this.orientation?i-k:k-i)}return a}();a.Arc2=p;var q=function(){function a(a){this.path=a,this._onchange=new Array,this.value=0,this.animations=new Array}return a.prototype.getPoint=function(){var a=this.path.getPointAtLengthPosition(this.value);return new e(a.x,0,a.y)},a.prototype.moveAhead=function(a){return void 0===a&&(a=.002),this.move(a),this},a.prototype.moveBack=function(a){return void 0===a&&(a=.002),this.move(-a),this},a.prototype.move=function(a){if(Math.abs(a)>1)throw"step size should be less than 1.";return this.value+=a,this.ensureLimits(),this.raiseOnChange(),this},a.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},a.prototype.markAsDirty=function(){return this.ensureLimits(),this.raiseOnChange(),this},a.prototype.raiseOnChange=function(){var a=this;return this._onchange.forEach(function(b){return b(a)}),this},a.prototype.onchange=function(a){return this._onchange.push(a),this},a}();a.PathCursor=q;var r=function(){function b(a,b){this._points=[],this._length=0,this.closed=!1,this._points.push(new d(a,b))}return b.prototype.addLineTo=function(b,c){if(closed)return a.Tools.Error("cannot add lines to closed paths"),this;var e=new d(b,c),f=this._points[this._points.length-1];return this._points.push(e),this._length+=e.subtract(f).length(),this},b.prototype.addArcTo=function(b,c,e,f,g){if(void 0===g&&(g=36),closed)return a.Tools.Error("cannot add arcs to closed paths"),this;var h=this._points[this._points.length-1],i=new d(b,c),j=new d(e,f),k=new p(h,i,j),l=k.angle.radians()/g;0===k.orientation&&(l*=-1);for(var m=k.startAngle.radians()+l,n=0;g>n;n++){var o=Math.cos(m)*k.radius+k.centerPoint.x,q=Math.sin(m)*k.radius+k.centerPoint.y;this.addLineTo(o,q),m+=l}return this},b.prototype.close=function(){return this.closed=!0,this},b.prototype.length=function(){var a=this._length;if(!this.closed){var b=this._points[this._points.length-1],c=this._points[0];a+=c.subtract(b).length()}return a},b.prototype.getPoints=function(){return this._points},b.prototype.getPointAtLengthPosition=function(b){if(0>b||b>1)return a.Tools.Error("normalized length position should be between 0 and 1."),d.Zero();for(var c=b*this.length(),e=0,f=0;f=e&&k>=c){var l=j.normalize(),m=c-e;return new d(h.x+l.x*m,h.y+l.y*m)}e=k}return a.Tools.Error("internal error"),d.Zero()},b.StartingAt=function(a,c){return new b(a,c)},b}();a.Path2=r}(BABYLON||(BABYLON={})),function(a){var b,c=function(b,c){return b?b instanceof a.Mesh?null:b instanceof a.SubMesh?b.clone(c):b.clone?b.clone():null:null},d=function(){function d(){}return d.GetFilename=function(a){var b=a.lastIndexOf("/");return 0>b?a:a.substring(b+1)},d.GetDOMTextContent=function(a){for(var b="",c=a.firstChild;c;)3===c.nodeType&&(b+=c.textContent),c=c.nextSibling;return b},d.ToDegrees=function(a){return 180*a/Math.PI},d.ToRadians=function(a){return a*Math.PI/180},d.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}},d.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}},d.MakeArray=function(a,b){return b===!0||void 0!==a&&null!=a?Array.isArray(a)?a:[a]:void 0},d.GetPointerPrefix=function(){var a="pointer";return navigator.pointerEnabled||(a="mouse"),a},d.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)},d.RequestFullscreen=function(a){a.requestFullscreen?a.requestFullscreen():a.msRequestFullscreen?a.msRequestFullscreen():a.webkitRequestFullscreen?a.webkitRequestFullscreen():a.mozRequestFullScreen&&a.mozRequestFullScreen()},d.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},d.CleanUrl=function(a){return a=a.replace(/#/gm,"%23")},d.LoadImage=function(b,c,e,f){b=d.CleanUrl(b);var g=new Image;"data:"!==b.substr(0,5)&&(g.crossOrigin="anonymous"),g.onload=function(){c(g)},g.onerror=function(a){e(g,a)};var h=function(){g.src=b},i=function(){f.loadImageFromDB(b,g)};if(f&&f.enableTexturesOffline&&a.Database.isUASupportingBlobStorage)f.openAsync(i,h);else if(-1===b.indexOf("file:"))h();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])}g.src=j}catch(m){d.Log("Error while trying to load texture: "+k),g.src=null}return g},d.LoadFile=function(b,c,e,f,g,h){b=d.CleanUrl(b);var i=function(){var a=new XMLHttpRequest,f=d.BaseUrl+b;a.open("GET",f,!0),g&&(a.responseType="arraybuffer"),a.onprogress=e,a.onreadystatechange=function(){if(4===a.readyState)if(200===a.status||d.ValidateXHRData(a,g?6:1))c(g?a.response:a.responseText);else{if(!h)throw new Error("Error status: "+a.status+" - Unable to load "+f);h()}},a.send(null)},j=function(){f.loadFileFromDB(b,c,e,i,g)};if(-1!==b.indexOf("file:")){var k=b.substring(5);d.ReadFile(a.FilesInput.FilesToLoad[k],c,e,!0)}else f&&f.enableSceneOffline?f.openAsync(j,i):i()},d.ReadFileAsDataURL=function(a,b,c){var d=new FileReader;d.onload=function(a){b(a.target.result)},d.onprogress=c,d.readAsDataURL(a)},d.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)},d.Clamp=function(a,b,c){return void 0===b&&(b=0),void 0===c&&(c=1),Math.min(c,Math.max(b,a))},d.Sign=function(a){return a=+a,0===a||isNaN(a)?a:a>0?1:-1},d.Format=function(a,b){return void 0===b&&(b=2),a.toFixed(b)},d.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)},d.WithinEpsilon=function(a,b,c){void 0===c&&(c=1.401298e-45);var d=a-b;return d>=-c&&c>=d},d.DeepCopy=function(a,b,d,e){for(var f in a)if(("_"!==f[0]||e&&-1!==e.indexOf(f))&&(!d||-1===d.indexOf(f))){var g=a[f],h=typeof g;if("function"!==h)if("object"===h)if(g instanceof Array){if(b[f]=[],g.length>0)if("object"==typeof g[0])for(var i=0;if;f++)for(var i=0;a>i;i++){var j=i+f*a,k=h-f-1,l=i+k*a,m=e[j];e[j]=e[l],e[l]=m}b||(b=document.createElement("canvas")),b.width=g,b.height=h;var n=b.getContext("2d"),o=n.createImageData(g,h);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)}},i.incrementRenderId(),k.render(!0),k.dispose(),j&&(i.activeCamera=j)},d.ValidateXHRData=function(b,c){void 0===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(d,"NoneLogLevel",{get:function(){return d._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(d,"MessageLogLevel",{get:function(){return d._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(d,"WarningLogLevel",{get:function(){return d._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(d,"ErrorLogLevel",{get:function(){return d._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(d,"AllLogLevel",{get:function(){return d._MessageLogLevel|d._WarningLogLevel|d._ErrorLogLevel},enumerable:!0,configurable:!0}),d._AddLogEntry=function(a){d._LogCache=a+d._LogCache,d.OnNewCacheEntry&&d.OnNewCacheEntry(a)},d._FormatMessage=function(a){var b=function(a){return 10>a?"0"+a:""+a},c=new Date;return"["+b(c.getHours())+":"+b(c.getMinutes())+":"+b(c.getSeconds())+"]: "+a},d._LogDisabled=function(){},d._LogEnabled=function(a){var b=d._FormatMessage(a);console.log("BJS - "+b);var c="
"+b+"

";d._AddLogEntry(c)},d._WarnDisabled=function(){},d._WarnEnabled=function(a){var b=d._FormatMessage(a);console.warn("BJS - "+b);var c="
"+b+"

";d._AddLogEntry(c)},d._ErrorDisabled=function(){},d._ErrorEnabled=function(a){var b=d._FormatMessage(a);console.error("BJS - "+b);var c="
"+b+"

";d._AddLogEntry(c)},Object.defineProperty(d,"LogCache",{get:function(){return d._LogCache},enumerable:!0,configurable:!0}),Object.defineProperty(d,"LogLevels",{set:function(a){d.Log=(a&d.MessageLogLevel)===d.MessageLogLevel?d._LogEnabled:d._LogDisabled,d.Warn=(a&d.WarningLogLevel)===d.WarningLogLevel?d._WarnEnabled:d._WarnDisabled,d.Error=(a&d.ErrorLogLevel)===d.ErrorLogLevel?d._ErrorEnabled:d._ErrorDisabled},enumerable:!0,configurable:!0}),Object.defineProperty(d,"PerformanceNoneLogLevel",{get:function(){return d._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(d,"PerformanceUserMarkLogLevel",{get:function(){return d._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(d,"PerformanceConsoleLogLevel",{get:function(){return d._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(d,"PerformanceLogLevel",{set:function(a){return(a&d.PerformanceUserMarkLogLevel)===d.PerformanceUserMarkLogLevel?(d.StartPerformanceCounter=d._StartUserMark,void(d.EndPerformanceCounter=d._EndUserMark)):(a&d.PerformanceConsoleLogLevel)===d.PerformanceConsoleLogLevel?(d.StartPerformanceCounter=d._StartPerformanceConsole,void(d.EndPerformanceCounter=d._EndPerformanceConsole)):(d.StartPerformanceCounter=d._StartPerformanceCounterDisabled,void(d.EndPerformanceCounter=d._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),d._StartPerformanceCounterDisabled=function(){},d._EndPerformanceCounterDisabled=function(){},d._StartUserMark=function(a,b){void 0===b&&(b=!0),b&&d._performance.mark&&d._performance.mark(a+"-Begin")},d._EndUserMark=function(a,b){void 0===b&&(b=!0),b&&d._performance.mark&&(d._performance.mark(a+"-End"),d._performance.measure(a,a+"-Begin",a+"-End"))},d._StartPerformanceConsole=function(a,b){void 0===b&&(b=!0),b&&(d._StartUserMark(a,b),console.time&&console.time(a))},d._EndPerformanceConsole=function(a,b){void 0===b&&(b=!0),b&&(d._EndUserMark(a,b),console.time&&console.timeEnd(a))},Object.defineProperty(d,"Now",{get:function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),d.GetFps=function(){return d.Warn("Tools.GetFps() is deprecated. Please use engine.getFps() instead"),0},d.BaseUrl="",d.GetExponantOfTwo=function(a,b){var c=1;do c*=2;while(a>c);return c>b&&(c=b),c},d._NoneLogLevel=0,d._MessageLogLevel=1,d._WarningLogLevel=2,d._ErrorLogLevel=4,d._LogCache="",d.Log=d._LogEnabled,d.Warn=d._WarnEnabled,d.Error=d._ErrorEnabled,d._PerformanceNoneLogLevel=0,d._PerformanceUserMarkLogLevel=1,d._PerformanceConsoleLogLevel=2,d._performance=window.performance,d.StartPerformanceCounter=d._StartPerformanceCounterDisabled,d.EndPerformanceCounter=d._EndPerformanceCounterDisabled,d}();a.Tools=d;var e=function(){function a(a,b,c,d){void 0===d&&(d=0),this.iterations=a,this._fn=b,this._successCallback=c,this.index=d-1,this._done=!1}return a.prototype.executeNext=function(){this._done||(this.index+1e;++e){var g=a.index*c+e;if(g>=b)break;if(d(g),f&&f()){a.breakLoop();break}}a.executeNext()},g)},e)},a}();a.AsyncLoop=e}(BABYLON||(BABYLON={})),function(a){var b=function(){function a(){this._isDepthTestDirty=!1,this._isDepthMaskDirty=!1,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1}return Object.defineProperty(a.prototype,"isDirty",{get:function(){return this._isDepthFuncDirty||this._isDepthTestDirty||this._isDepthMaskDirty||this._isCullFaceDirty||this._isCullDirty},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"cullFace",{get:function(){return this._cullFace},set:function(a){this._cullFace!==a&&(this._cullFace=a,this._isCullFaceDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"cull",{get:function(){return this._cull},set:function(a){this._cull!==a&&(this._cull=a,this._isCullDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"depthFunc",{get:function(){return this._depthFunc},set:function(a){this._depthFunc!==a&&(this._depthFunc=a,this._isDepthFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"depthMask",{get:function(){return this._depthMask},set:function(a){this._depthMask!==a&&(this._depthMask=a,this._isDepthMaskDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"depthTest",{get:function(){return this._depthTest},set:function(a){this._depthTest!==a&&(this._depthTest=a,this._isDepthTestDirty=!0)},enumerable:!0,configurable:!0}),a.prototype.reset=function(){this._depthMask=!0,this._depthTest=!0,this._depthFunc=null,this._cull=null,this._cullFace=null,this._isDepthTestDirty=!0,this._isDepthMaskDirty=!0,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1},a.prototype.apply=function(a){this.isDirty&&(this._isCullDirty&&(this.cull?a.enable(a.CULL_FACE):a.disable(a.CULL_FACE),this._isCullDirty=!1),this._isCullFaceDirty&&(a.cullFace(this.cullFace),this._isCullFaceDirty=!1),this._isDepthMaskDirty&&(a.depthMask(this.depthMask),this._isDepthMaskDirty=!1),this._isDepthTestDirty&&(this.depthTest?a.enable(a.DEPTH_TEST):a.disable(a.DEPTH_TEST),this._isDepthTestDirty=!1),this._isDepthFuncDirty&&(a.depthFunc(this.depthFunc),this._isDepthFuncDirty=!1))},a}();a._DepthCullingState=b;var c=function(){function a(){this._isAlphaBlendDirty=!1,this._isBlendFunctionParametersDirty=!1,this._alphaBlend=!1,this._blendFunctionParameters=new Array(4)}return Object.defineProperty(a.prototype,"isDirty",{get:function(){return this._isAlphaBlendDirty||this._isBlendFunctionParametersDirty},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"alphaBlend",{get:function(){return this._alphaBlend},set:function(a){this._alphaBlend!==a&&(this._alphaBlend=a,this._isAlphaBlendDirty=!0)},enumerable:!0,configurable:!0}),a.prototype.setAlphaBlendFunctionParameters=function(a,b,c,d){(this._blendFunctionParameters[0]!==a||this._blendFunctionParameters[1]!==b||this._blendFunctionParameters[2]!==c||this._blendFunctionParameters[3]!==d)&&(this._blendFunctionParameters[0]=a,this._blendFunctionParameters[1]=b,this._blendFunctionParameters[2]=c,this._blendFunctionParameters[3]=d,this._isBlendFunctionParametersDirty=!0)},a.prototype.reset=function(){this._alphaBlend=!1,this._blendFunctionParameters[0]=null,this._blendFunctionParameters[1]=null,this._blendFunctionParameters[2]=null,this._blendFunctionParameters[3]=null,this._isAlphaBlendDirty=!0,this._isBlendFunctionParametersDirty=!1},a.prototype.apply=function(a){this.isDirty&&(this._isAlphaBlendDirty&&(this._alphaBlend?a.enable(a.BLEND):a.disable(a.BLEND),this._isAlphaBlendDirty=!1),this._isBlendFunctionParametersDirty&&(a.blendFuncSeparate(this._blendFunctionParameters[0],this._blendFunctionParameters[1],this._blendFunctionParameters[2],this._blendFunctionParameters[3]),this._isBlendFunctionParametersDirty=!1))},a}();a._AlphaState=c;var d=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},e=function(a,b){var c=a.UNSIGNED_BYTE;return b===k.TEXTURETYPE_FLOAT&&(c=a.FLOAT),c},f=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}},g=function(b,c,d,e,g,h,i,j,k,l){void 0===l&&(l=a.Texture.TRILINEAR_SAMPLINGMODE);var m=d.getEngine(),n=a.Tools.GetExponantOfTwo(e,m.getCaps().maxTextureSize),o=a.Tools.GetExponantOfTwo(g,m.getCaps().maxTextureSize);c.bindTexture(c.TEXTURE_2D,b),c.pixelStorei(c.UNPACK_FLIP_Y_WEBGL,void 0===h?1:h?1:0),k(n,o);var p=f(l,!i,c);c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,p.mag),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,p.min),i||j||c.generateMipmap(c.TEXTURE_2D),c.bindTexture(c.TEXTURE_2D,null),m._activeTexturesCache=[],b._baseWidth=e,b._baseHeight=g,b._width=n,b._height=o,b.isReady=!0,b.samplingMode=l,d._removePendingData(b)},h=function(b,c,d,e,f){var g=function(){d[c]=i,d._internalCount++,e._removePendingData(i),6===d._internalCount&&f(d)},h=function(){e._removePendingData(i)},i=a.Tools.LoadImage(b,g,h,e.database);e._addPendingData(i)},i=function(a,b,c,d){var e=[];e._internalCount=0;for(var f=0;6>f;f++)h(a+d[f],f,e,b,c)},j=function(){function a(){}return a}();a.EngineCapabilities=j;var k=function(){function h(d,e,f){var g=this;this.isFullscreen=!1,this.isPointerLock=!1,this.cullBackFaces=!0,this.renderEvenInBackground=!0,this.scenes=new Array,this._windowIsBackground=!1,this._loadingDivBackgroundColor="black",this._drawCalls=0,this._renderingQueueLaunched=!1,this._activeRenderLoops=[],this.fpsRange=60,this.previousFramesDuration=[],this.fps=60,this.deltaTime=0,this._depthCullingState=new b,this._alphaState=new c,this._alphaMode=h.ALPHA_DISABLE,this._loadedTexturesCache=new Array,this._activeTexturesCache=new Array,this._compiledEffects={},this._uintIndicesCurrentlySet=!1,this._renderingCanvas=d,this._canvasClientRect=this._renderingCanvas.getBoundingClientRect(),f=f||{},f.antialias=e;try{this._gl=d.getContext("webgl",f)||d.getContext("experimental-webgl",f)}catch(i){throw new Error("WebGL not supported")}if(!this._gl)throw new Error("WebGL not supported");this._onBlur=function(){g._windowIsBackground=!0},this._onFocus=function(){g._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 j,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._glVersion=this._gl.getParameter(this._gl.VERSION);var k=this._gl.getExtension("WEBGL_debug_renderer_info");null!=k&&(this._glRenderer=this._gl.getParameter(k.UNMASKED_RENDERER_WEBGL),this._glVendor=this._gl.getParameter(k.UNMASKED_VENDOR_WEBGL)),this._glVendor||(this._glVendor="Unknown vendor"),this._glRenderer||(this._glRenderer="Unknown renderer"),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._caps.uintIndices=null!==this._gl.getExtension("OES_element_index_uint"),this.setDepthBuffer(!0),this.setDepthFunctionToLessOrEqual(),this.setDepthWrite(!0),this._onFullscreenChange=function(){void 0!==document.fullscreen?g.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?g.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?g.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(g.isFullscreen=document.msIsFullScreen),g.isFullscreen&&g._pointerLockRequested&&(d.requestPointerLock=d.requestPointerLock||d.msRequestPointerLock||d.mozRequestPointerLock||d.webkitRequestPointerLock,d.requestPointerLock&&d.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(){g.isPointerLock=document.mozPointerLockElement===d||document.webkitPointerLockElement===d||document.msPointerLockElement===d||document.pointerLockElement===d},document.addEventListener("pointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mspointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this._onPointerLockChange,!1),document.addEventListener("webkitpointerlockchange",this._onPointerLockChange,!1),h.audioEngine||(h.audioEngine=new a.AudioEngine),a.Tools.Log("Babylon.js engine (v"+h.Version+") launched")}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,"TEXTUREFORMAT_ALPHA",{get:function(){return h._TEXTUREFORMAT_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(h,"TEXTUREFORMAT_LUMINANCE",{get:function(){return h._TEXTUREFORMAT_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(h,"TEXTUREFORMAT_LUMINANCE_ALPHA",{get:function(){return h._TEXTUREFORMAT_LUMINANCE_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(h,"TEXTUREFORMAT_RGB",{get:function(){return h._TEXTUREFORMAT_RGB },enumerable:!0,configurable:!0}),Object.defineProperty(h,"TEXTUREFORMAT_RGBA",{get:function(){return h._TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),Object.defineProperty(h,"TEXTURETYPE_UNSIGNED_INT",{get:function(){return h._TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(h,"TEXTURETYPE_FLOAT",{get:function(){return h._TEXTURETYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(h,"Version",{get:function(){return"2.0.0"},enumerable:!0,configurable:!0}),h.prototype.getGlInfo=function(){return{vendor:this._glVendor,renderer:this._glRenderer,version:this._glVersion}},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},Object.defineProperty(h.prototype,"drawCalls",{get:function(){return this._drawCalls},enumerable:!0,configurable:!0}),h.prototype.resetDrawCalls=function(){this._drawCalls=0},h.prototype.setDepthFunctionToGreater=function(){this._depthCullingState.depthFunc=this._gl.GREATER},h.prototype.setDepthFunctionToGreaterOrEqual=function(){this._depthCullingState.depthFunc=this._gl.GEQUAL},h.prototype.setDepthFunctionToLess=function(){this._depthCullingState.depthFunc=this._gl.LESS},h.prototype.setDepthFunctionToLessOrEqual=function(){this._depthCullingState.depthFunc=this._gl.LEQUAL},h.prototype.stopRenderLoop=function(a){if(!a)return void(this._activeRenderLoops=[]);var b=this._activeRenderLoops.indexOf(a);b>=0&&this._activeRenderLoops.splice(b,1)},h.prototype._renderLoop=function(){var b=this,c=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(c=!1),c){this.beginFrame();for(var d=0;d0?a.Tools.QueueNewFrame(function(){b._renderLoop()}):this._renderingQueueLaunched=!1},h.prototype.runRenderLoop=function(b){var c=this;-1===this._activeRenderLoops.indexOf(b)&&(this._activeRenderLoops.push(b),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,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.applyStates(),this._gl.clearColor(a.r,a.g,a.b,void 0!==a.a?a.a:1),this._depthCullingState.depthMask&&this._gl.clearDepth(1);var d=0;b&&(d|=this._gl.COLOR_BUFFER_BIT),c&&this._depthCullingState.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(){this._measureFps()},h.prototype.endFrame=function(){},h.prototype.resize=function(){this.setSize(this._renderingCanvas.clientWidth/this._hardwareScalingLevel,this._renderingCanvas.clientHeight/this._hardwareScalingLevel)},h.prototype.setSize=function(a,b){this._renderingCanvas.width=a,this._renderingCanvas.height=b,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._currentRenderTarget=null,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,c){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,a),void 0===c&&(c=0),b instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,c,b):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,c,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();this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,b);var c,d=!1;if(this._caps.uintIndices){for(var e=0;e65535){d=!0;break}c=d?new Uint32Array(a):new Uint16Array(a)}else c=new Uint16Array(a);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,c,this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),b.references=1,b.is32Bits=d,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),this._uintIndicesCurrentlySet=b.is32Bits)},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)}}}null!=b&&this._cachedIndexBuffer!==b&&(this._cachedIndexBuffer=b,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,b),this._uintIndicesCurrentlySet=b.is32Bits)},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.applyStates=function(){this._depthCullingState.apply(this._gl),this._alphaState.apply(this._gl)},h.prototype.draw=function(a,b,c,d){this.applyStates(),this._drawCalls++;var e=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT;return d?void this._caps.instancedArrays.drawElementsInstancedANGLE(a?this._gl.TRIANGLES:this._gl.LINES,c,e,2*b,d):void this._gl.drawElements(a?this._gl.TRIANGLES:this._gl.LINES,c,e,2*b)},h.prototype.drawPointClouds=function(a,b,c){return this.applyStates(),this._drawCalls++,c?void this._caps.instancedArrays.drawArraysInstancedANGLE(this._gl.POINTS,a,b,c):void this._gl.drawArrays(this._gl.POINTS,a,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.createEffectForParticles=function(a,b,c,d,e,f,g){return void 0===b&&(b=[]),void 0===c&&(c=[]),void 0===d&&(d=""),this.createEffect({vertex:"particles",fragmentElement:a},["position","color","options"],["view","projection"].concat(b),["diffuseSampler"].concat(c),d,e,f,g)},h.prototype.createShaderProgram=function(a,b,c){var e=d(this._gl,a,"vertex",c),f=d(this._gl,b,"fragment",c),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,a.onBind&&a.onBind(a)},h.prototype.setArray=function(a,b){a&&this._gl.uniform1fv(a,b)},h.prototype.setArray2=function(a,b){a&&b.length%2===0&&this._gl.uniform2fv(a,b)},h.prototype.setArray3=function(a,b){a&&b.length%3===0&&this._gl.uniform3fv(a,b)},h.prototype.setArray4=function(a,b){a&&b.length%4===0&&this._gl.uniform4fv(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,b){(this._depthCullingState.cull!==a||b)&&(a?(this._depthCullingState.cullFace=this.cullBackFaces?this._gl.BACK:this._gl.FRONT,this._depthCullingState.cull=!0):this._depthCullingState.cull=!1)},h.prototype.setDepthBuffer=function(a){this._depthCullingState.depthTest=a},h.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},h.prototype.setDepthWrite=function(a){this._depthCullingState.depthMask=a},h.prototype.setColorWrite=function(a){this._gl.colorMask(a,a,a,a)},h.prototype.setAlphaMode=function(a){switch(a){case h.ALPHA_DISABLE:this.setDepthWrite(!0),this._alphaState.alphaBlend=!1;break;case h.ALPHA_COMBINE:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case h.ALPHA_ADD:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0}this._alphaMode=a},h.prototype.getAlphaMode=function(){return this._alphaMode},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._depthCullingState.reset(),this._alphaState.reset(),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),b.samplingMode=c},h.prototype.createTexture=function(b,c,d,e,f,h,i,j){var k=this;void 0===f&&(f=a.Texture.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===i&&(i=null),void 0===j&&(j=null);var l,m=this._gl.createTexture(),n=!1;if("data:"===b.substr(0,5)&&(n=!0),n){var o=b;n=o.split(":"),b=o,l=n[1].substr(n[1].length-4,4).toLowerCase()}else l=b.substr(b.length-4,4).toLowerCase();var p=this.getCaps().s3tc&&".dds"===l,q=".tga"===l;e._addPendingData(m),m.url=b,m.noMipmap=c,m.references=1,this._loadedTexturesCache.push(m);var r=function(){e._removePendingData(m),i&&i()};if(q){var s=function(b){var i=new Uint8Array(b),j=a.Internals.TGATools.GetTGAHeader(i);g(m,k._gl,e,j.width,j.height,d,c,!1,function(){a.Internals.TGATools.UploadContent(k._gl,i),h&&h()},f)};n instanceof Array?s(j):a.Tools.LoadFile(b,function(a){s(a)},r,e.database,!0)}else if(p)s=function(b){var i=a.Internals.DDSTools.GetDDSInfo(b),j=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!c&&i.width>>i.mipmapCount-1===1;g(m,k._gl,e,i.width,i.height,d,!j,i.isFourCC,function(){a.Internals.DDSTools.UploadDDSLevels(k._gl,k.getCaps().s3tc,b,i,j,1),h&&h()},f)},n instanceof Array?s(j):a.Tools.LoadFile(b,function(a){s(a)},r,e.database,!0);else{var t=function(b){g(m,k._gl,e,b.width,b.height,d,c,!1,function(c,d){var e=b.width===c&&b.height===d;e||(k._workingCanvas.width=c,k._workingCanvas.height=d,f===a.Texture.NEAREST_SAMPLINGMODE&&(k._workingContext.imageSmoothingEnabled=!1,k._workingContext.mozImageSmoothingEnabled=!1,k._workingContext.oImageSmoothingEnabled=!1,k._workingContext.webkitImageSmoothingEnabled=!1,k._workingContext.msImageSmoothingEnabled=!1),k._workingContext.drawImage(b,0,0,b.width,b.height,0,0,c,d),f===a.Texture.NEAREST_SAMPLINGMODE&&(k._workingContext.imageSmoothingEnabled=!0,k._workingContext.mozImageSmoothingEnabled=!0,k._workingContext.oImageSmoothingEnabled=!0,k._workingContext.webkitImageSmoothingEnabled=!0,k._workingContext.msImageSmoothingEnabled=!0)),k._gl.texImage2D(k._gl.TEXTURE_2D,0,k._gl.RGBA,k._gl.RGBA,k._gl.UNSIGNED_BYTE,e?b:k._workingCanvas),h&&h()},f)};n instanceof Array?a.Tools.LoadImage(j,t,r,e.database):a.Tools.LoadImage(b,t,r,e.database)}return m},h.prototype.createRawTexture=function(a,b,c,d,e,g,i){var j=this._gl.createTexture();this._gl.bindTexture(this._gl.TEXTURE_2D,j),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,void 0===g?1:g?1:0);var k=this._gl.RGBA;switch(d){case h.TEXTUREFORMAT_ALPHA:k=this._gl.ALPHA;break;case h.TEXTUREFORMAT_LUMINANCE:k=this._gl.LUMINANCE;break;case h.TEXTUREFORMAT_LUMINANCE_ALPHA:k=this._gl.LUMINANCE_ALPHA;break;case h.TEXTUREFORMAT_RGB:k=this._gl.RGB;break;case h.TEXTUREFORMAT_RGBA:k=this._gl.RGBA}this._gl.texImage2D(this._gl.TEXTURE_2D,0,k,b,c,0,k,this._gl.UNSIGNED_BYTE,a),e&&this._gl.generateMipmap(this._gl.TEXTURE_2D);var l=f(i,e,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,l.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,l.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],j._baseWidth=b,j._baseHeight=c,j._width=b,j._height=c,j.isReady=!0,j.references=1,j.samplingMode=i,this._loadedTexturesCache.push(j),j},h.prototype.createDynamicTexture=function(b,c,d,e){var g=this._gl.createTexture();b=a.Tools.GetExponantOfTwo(b,this._caps.maxTextureSize),c=a.Tools.GetExponantOfTwo(c,this._caps.maxTextureSize),this._gl.bindTexture(this._gl.TEXTURE_2D,g);var h=f(e,d,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=b,g._baseHeight=c,g._width=b,g._height=c,g.isReady=!1,g.generateMipMaps=d,g.references=1,g.samplingMode=e,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,c){var d=!1,g=!0,i=h.TEXTURETYPE_UNSIGNED_INT,j=a.Texture.TRILINEAR_SAMPLINGMODE;void 0!==c&&(d=void 0===c.generateMipMaps?c:c.generateMipmaps,g=void 0===c.generateDepthBuffer?!0:c.generateDepthBuffer,i=void 0===c.type?i:c.type,void 0!==c.samplingMode&&(j=c.samplingMode),i===h.TEXTURETYPE_FLOAT&&(j=a.Texture.NEAREST_SAMPLINGMODE));var k=this._gl,l=k.createTexture();k.bindTexture(k.TEXTURE_2D,l);var m=b.width||b,n=b.height||b,o=f(j,d,k);i!==h.TEXTURETYPE_FLOAT||this._caps.textureFloat||(i=h.TEXTURETYPE_UNSIGNED_INT,a.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_MAG_FILTER,o.mag),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_MIN_FILTER,o.min),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_WRAP_S,k.CLAMP_TO_EDGE),k.texParameteri(k.TEXTURE_2D,k.TEXTURE_WRAP_T,k.CLAMP_TO_EDGE),k.texImage2D(k.TEXTURE_2D,0,k.RGBA,m,n,0,k.RGBA,e(k,i),null);var p;g&&(p=k.createRenderbuffer(),k.bindRenderbuffer(k.RENDERBUFFER,p),k.renderbufferStorage(k.RENDERBUFFER,k.DEPTH_COMPONENT16,m,n));var q=k.createFramebuffer();return k.bindFramebuffer(k.FRAMEBUFFER,q),k.framebufferTexture2D(k.FRAMEBUFFER,k.COLOR_ATTACHMENT0,k.TEXTURE_2D,l,0),g&&k.framebufferRenderbuffer(k.FRAMEBUFFER,k.DEPTH_ATTACHMENT,k.RENDERBUFFER,p),k.bindTexture(k.TEXTURE_2D,null),k.bindRenderbuffer(k.RENDERBUFFER,null),k.bindFramebuffer(k.FRAMEBUFFER,null),l._framebuffer=q,g&&(l._depthBuffer=p),l._width=m,l._height=n,l.isReady=!0,l.generateMipMaps=d,l.references=1,l.samplingMode=j,this._activeTexturesCache=[],this._loadedTexturesCache.push(l),l},h.prototype.createCubeTexture=function(b,c,d,e){var f=this,g=this._gl,h=g.createTexture();h.isCube=!0,h.url=b,h.references=1,this._loadedTexturesCache.push(h);var j=b.substr(b.length-4,4).toLowerCase(),k=this.getCaps().s3tc&&".dds"===j;return k?a.Tools.LoadFile(b,function(b){var c=a.Internals.DDSTools.GetDDSInfo(b),d=(c.isRGB||c.isLuminance||c.mipmapCount>1)&&!e;g.bindTexture(g.TEXTURE_CUBE_MAP,h),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,1),a.Internals.DDSTools.UploadDDSLevels(f._gl,f.getCaps().s3tc,b,c,d,6),e||c.isFourCC||1!==c.mipmapCount||g.generateMipmap(g.TEXTURE_CUBE_MAP),g.texParameteri(g.TEXTURE_CUBE_MAP,g.TEXTURE_MAG_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_CUBE_MAP,g.TEXTURE_MIN_FILTER,d?g.LINEAR_MIPMAP_LINEAR:g.LINEAR),g.texParameteri(g.TEXTURE_CUBE_MAP,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_CUBE_MAP,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE),g.bindTexture(g.TEXTURE_CUBE_MAP,null),f._activeTexturesCache=[],h._width=c.width,h._height=c.height,h.isReady=!0},null,null,!0):i(b,c,function(b){var c=a.Tools.GetExponantOfTwo(b[0].width,f._caps.maxCubemapTextureSize),d=c;f._workingCanvas.width=c,f._workingCanvas.height=d;var i=[g.TEXTURE_CUBE_MAP_POSITIVE_X,g.TEXTURE_CUBE_MAP_POSITIVE_Y,g.TEXTURE_CUBE_MAP_POSITIVE_Z,g.TEXTURE_CUBE_MAP_NEGATIVE_X,g.TEXTURE_CUBE_MAP_NEGATIVE_Y,g.TEXTURE_CUBE_MAP_NEGATIVE_Z];g.bindTexture(g.TEXTURE_CUBE_MAP,h),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,0);for(var j=0;jb)){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===h.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.hideLoadingUI(),this.stopRenderLoop();this.scenes.length;)this.scenes[0].dispose();h.audioEngine.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.prototype.displayLoadingUI=function(){var a=this;this._loadingDiv=document.createElement("div"),this._loadingDiv.style.opacity="0",this._loadingDiv.style.transition="opacity 1.5s ease",this._loadingTextDiv=document.createElement("div"),this._loadingTextDiv.style.position="absolute",this._loadingTextDiv.style.left="0",this._loadingTextDiv.style.top="50%",this._loadingTextDiv.style.marginTop="80px",this._loadingTextDiv.style.width="100%",this._loadingTextDiv.style.height="20px",this._loadingTextDiv.style.fontFamily="Arial",this._loadingTextDiv.style.fontSize="14px",this._loadingTextDiv.style.color="white",this._loadingTextDiv.style.textAlign="center",this._loadingTextDiv.innerHTML="Loading",this._loadingDiv.appendChild(this._loadingTextDiv);var b=new Image;b.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAARbSURBVHhe7Z09aFNRFMc716kuLrq4FdyLq4Wi4CAoRQcR0UJBUBdRiuLSIYMo6CA4FF2sgw6CFAdFUOpSQYcWO4hD26UQCfXrIQrx/JJzw1OSWq3NPeL/B4Fy+0jg/HO+7j3vpUcI8b/Q39+/49ihfWdPHT94Yf/e3Se3bd263f8lus218TPn6vV6Ya8Wi/MzNRNmj18iusX9W1evmP1/EKNEIVG6CMbG6E3bt+fT++pHha8NoHdT72bLE8NDg7tGU64gLLndV4Wc4m8j/pS+vr4tGB/DT16v3Fyr8dvBe/jbit8BL0AES9LX1iPAz+BR/hFiLVCynj95dPzNy6fv3IZ/k4L3948Sq7FzYGBg4vLFGxitabuOFCbWNKGrMnbiUuo18KaV6tIHv6YtvL9/nOgE31jCktmrY7k6+/zhE4yP4Vf7hiNqh/BWWEl8mzDol4p22Lf7cIdvdUMEvv0Y2S9fE5S1hLzpqTsPkiep//gFGPnR3Yl7GL5p/xYFBrTwM+iXio3GqpwDGL5p/xYNIX7XG8Q6IJRgdIzf1KBBgafII7oMidhyQtVFaMA2Bt7il4huQRhaXphbcR2g4RXqBzKAGHiCCwGFVUAj/m/RTRDj29cvn10I0PZ3LghH5f4CL1EFlQmqqXK3jDDKFxmhQ3Yt6oQseUZGKmMnTpsOqc8o1F9kBOMjQlOLeqEeIyOc6JV6jYLJD/+XyIFvnzdgl9aXRQ5I2qZDK1SpospMqaoqON/wZZGDciLnMMiXRS7IF4hhqMTNTdk7CFu+LHLhR7BQqBvPDJUUQqCGvCMATHUgBmhWNgApmdOda9YpM+VwRYfuyyIXDK8hBlilNerLIheMZCKGwlUAyru6GlwOgPUbRxADdJ9FAChxXY864viyyEXqPxhc0M2TAfAbatSdRyHtXymhByEdRnE3ky+JnHAIhSA0h74kckETmHoQbSgGwJrCIRMEPSRIBCRIMAhZaYhaggQhJXUJEoRU9mofKwh+F22dLRRfEjlJM7w6KQwCoQpBOKTyJZETjmwRxKqtGV8SOSkNOGjKPQppBEgDDkFgpxdBVGkFgaYQQXRIFQSObk0P5ZFIpAZRHXsQ0r0hCluBWKkuvVbYCkQaCdL5ehBScudJP4yY+rLISdps1NBDEJKXMMmoSfggWC4ZQRR17oFYXph7hSiquIKQ+hJGTX1J5MYSPD/GVdNzsgLBwZVCVyAQAkF0ohiI/c1fS6tNXq9UfEnkhudmIQolsS+J3Hh/UtNDzQLhj42VKJFInqLwFYiUU5ToA+HdfI0JevUpQUAIn+vSz2lHIuUV/dJOIHhOY/IWVWGBIHQtzs88s9zyWBuTgcBLzGOmeNnfF/QslSDgMeQW85i3DOQxuipxAkCyZ8SIm4Omp+7MMlCB59j6sKZcMoM4iIEoeI2J9AKxrFobZx0v4vYInuHFS4J1GQRCAGaLEYQXfyMML5XSQgghhBBCCCH+cXp6vgNhKpSKX/XdOAAAAABJRU5ErkJggg==",b.style.position="absolute",b.style.left="50%",b.style.top="50%",b.style.marginLeft="-50px",b.style.marginTop="-50px",b.style.transition="transform 1.0s ease",b.style.webkitTransition="-webkit-transform 1.0s ease";var c=360,d=function(){c+=360,b.style.transform="rotateZ("+c+"deg)",b.style.webkitTransform="rotateZ("+c+"deg)"};b.addEventListener("transitionend",d),b.addEventListener("webkitTransitionEnd",d),this._loadingDiv.appendChild(b);var e=new Image;e.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAAYJSURBVHhe7Zy/qx1FFMff/2Av2Nvbi4WFiiAEY/OQ2IgQsbCJQoqkCAgpFLXyoZURLfwBIiIpgqZJoYQYlWelNsIrNOxDJcrzfHe+G97dnTl75u7euzv7zgcWHrlnZmfOmXPmzI/NjuM4juM4juM4juM4juM4juM4juM4juM45fPic08/uHf5/CvffH7lnT8PfrtxdHS0n3p+/fHGl5+89/prr5599iEWd8bg0rkXHoFyqehKnlxQpjYSDHTm9JMPsGrHylOPPXofvICKXMcIGtXdf/76AYbm6xyNW9e/eAtKC7rbKLXnvHHx5Sf4auc4Ek7OQkFU1Dap/vv37k/wSjblZANFiFIGzw98hhizwqBgs04mCBdQRNCHidoAEtY+lLIvtSdoGFeyql2ZH57HBH4sE7O+o/r9l+8/ZXUni68+2jsHBQQ9qNRGeP/tSxdSYQX/roUcpL4/f3vtM9TD+jTq92n1LQ7jxF1hhGPtwWL3gGccy8JuS1r8sVWBGXNVdSKMYjBGPUJjCzooiGuSpnwlnnOGP2dhHRSLNgpHp2oMKIriK8TmG4Qh/rwW8D6pps9b9im+LDDipXOqMVJrAngBfg9i98gevWKA+/nnCod3Dr5GfaHaDgidVym6HKRjGIkpqthcAVKGxNqBImbEo66kjCih8AOpNmkUmbMuUrR8kEqiU6FvHZLGAPJ71JCYSyhiBqmwFE2GoD6jLGIfDHtG6EzoU4dK21PCqIRMEF0FGRjFzGDtIkXVAdATvsqfT9CJ0JcOFdYiFIsiMlqYy1YOFpQo2OddqBtyEaq9y+efoVh5oPHoROjLKn0j3JIE5Ka8UqZRtGrMnneX6yVofOhDh94MSbznTcpqmDOt1vyQzOgaJAF4F3JBfIXesrNEGWWmjIX7UBZ6jRJbBMLg/DmJiKUGVHleIpnVNTa+jakzkAviJqLhi4MC9XQGBrZeKJZESSrKy7ik0VGFWhQBRDTHIACKQ5l9nAjy75gya4a2w+Jhs0FJdc0xX/GwUbAqFBkZi7QpJ2w16WUbjFyK9MJF3KaoEM74KhVtLrQOrsmRxkbdHEqmSC/c+EuGnIFkjW7Ih2Kr4CCMIvNG2hrrgLpCjiFloooYCjyYrzCRyvhyBthkIPuQtsZGdnbMTezyDiU71KTC5zr7aVsHbsz2tllrEkS5UHwU1tq1HbtPW4UbeB0O7xx8R5EsMJql+BheUmHjkNVmIRP7LutoM3+D4O4tG7vCkNO9ESZ4lL3J6rKRMPx4qKbD/A0icf8CG7tC7kTahnMTwleuYSrsS7GatRAvfZh1tTm5BmmQCdZ8a0Sefe28xUrRBkmFLKy8KTIKUDRX0Y1xagPgwbaIdeFnQULmKak3xvwNMkVGgok/N5XNoehJvejRlCDl9escI28dJU0tZ++nBTJE9mEF647x5Ehbo4s5hDOKFIU0PdofeA5F5k1q63zIWmQqNI/P3ZubjFTqKxQ3jyjHAOX0RdlgVO9hzRFpczRcjZ3Gbxxpc7Qj6+5pTYF2OFXawNI+yDGf1k2NcvOlzBQeDQ/t7zD7DsEDpJ2xATXaNtDWUS4IzP4DS2ljajAVu57SUkYw245ptxZxA5JiZaJ0DswudGn3kYUy54426EjoT4dZfYbccxC2nI92cDkZHQr96jD4AGkMDKeSy/COBsRe6VTSKFN6irLeaCh3IteQjt1E5+oudsG/b/2DfZ5AqsYo8vMDK9LB1HzSsLWvlGThdxXvC6+NsqyPPWP0pMINtbdsajfVeC6f/GZ+cdAofQoB1d+Hf9waY98I7+RXWab3Lt4zYkjHtTnlOLXHYMsCh1zWeQYehu1zfNPOOiys/d91LAKEBSgh6MJMbSA82AaHofDgAIwbgvVvlLNS11nModMm4UZergLHZBZrodmBuA3lBB1thdorSjkOmATMDwg/UBQVtglqQyx6fbEJ+H3IWIapjYAjAfeIgeCMHldueJvFaqDaAHhwf8qNsEEQ1iQbOoUUGIbCLRc8+Bvfp4jyd2FEijuO4ziO4ziO4ziO4ziO4ziO4ziO4ziOUzw7O/8D0P7rcZ/GEboAAAAASUVORK5CYII=",e.style.position="absolute",e.style.left="50%",e.style.top="50%",e.style.marginLeft="-50px",e.style.marginTop="-50px",this._loadingDiv.appendChild(e),this._resizeLoadingUI=function(){var b=a.getRenderingCanvasClientRect(); a._loadingDiv.style.position="absolute",a._loadingDiv.style.left=b.left+"px",a._loadingDiv.style.top=b.top+"px",a._loadingDiv.style.width=b.width+"px",a._loadingDiv.style.height=b.height+"px"},this._resizeLoadingUI(),window.addEventListener("resize",this._resizeLoadingUI),this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor,document.body.appendChild(this._loadingDiv),setTimeout(function(){a._loadingDiv.style.opacity="1",b.style.transform="rotateZ(360deg)",b.style.webkitTransform="rotateZ(360deg)"},0)},Object.defineProperty(h.prototype,"loadingUIText",{set:function(a){this._loadingDiv&&(this._loadingTextDiv.innerHTML=a)},enumerable:!0,configurable:!0}),Object.defineProperty(h.prototype,"loadingUIBackgroundColor",{get:function(){return this._loadingDivBackgroundColor},set:function(a){this._loadingDivBackgroundColor=a,this._loadingDiv&&(this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor)},enumerable:!0,configurable:!0}),h.prototype.hideLoadingUI=function(){var a=this;if(this._loadingDiv){var b=function(){a._loadingDiv&&(document.body.removeChild(a._loadingDiv),window.removeEventListener("resize",a._resizeLoadingUI),a._loadingDiv=null)};this._loadingDiv.style.opacity="0",this._loadingDiv.addEventListener("transitionend",b)}},h.prototype.getFps=function(){return this.fps},h.prototype.getDeltaTime=function(){return this.deltaTime},h.prototype._measureFps=function(){this.previousFramesDuration.push(a.Tools.Now);var b=this.previousFramesDuration.length;if(b>=2&&(this.deltaTime=this.previousFramesDuration[b-1]-this.previousFramesDuration[b-2]),b>=this.fpsRange){b>this.fpsRange&&(this.previousFramesDuration.splice(0,1),b=this.previousFramesDuration.length);for(var c=0,d=0;b-1>d;d++)c+=this.previousFramesDuration[d+1]-this.previousFramesDuration[d];this.fps=1e3/(c/(b-1))}},h.isSupported=function(){try{if(navigator.isCocoonJS)return!0;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._TEXTUREFORMAT_ALPHA=0,h._TEXTUREFORMAT_LUMINANCE=1,h._TEXTUREFORMAT_LUMINANCE_ALPHA=2,h._TEXTUREFORMAT_RGB=4,h._TEXTUREFORMAT_RGBA=4,h._TEXTURETYPE_UNSIGNED_INT=0,h._TEXTURETYPE_FLOAT=1,h.Epsilon=.001,h.CollisionsEpsilon=.001,h.ShadersRepository="Babylon/Shaders/",h}();a.Engine=k}(BABYLON||(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.isCompletelyInFrustum=function(a){return b.IsCompletelyInFrustum(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.IsCompletelyInFrustum=function(a,b){for(var c=0;6>c;c++)for(var d=0;8>d;d++)if(b[c].dotCoordinate(a[d])<0)return!1;return!0},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={})),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.extendSize.x,f=Math.abs(a.Vector3.Dot(c.directions[1],b))*c.extendSize.y,g=Math.abs(a.Vector3.Dot(c.directions[2],b))*c.extendSize.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.isCompletelyInFrustum=function(a){return this.boundingBox.isCompletelyInFrustum(a)},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 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.includedOnlyMeshes=new Array,this.excludedMeshes=new Array,this._excludedMeshesIds=new Array,this._includedOnlyMeshesIds=new Array,d.lights.push(this)}return __extends(c,b),c.prototype.getShadowGenerator=function(){return this._shadowGenerator},c.prototype.getAbsolutePosition=function(){return a.Vector3.Zero()},c.prototype.transferToEffect=function(){},c.prototype._getWorldMatrix=function(){return a.Matrix.Identity()},c.prototype.canAffectMesh=function(a){return a?this.includedOnlyMeshes.length>0&&-1===this.includedOnlyMeshes.indexOf(a)?!1:this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(a)?!1:!0:!0},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 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.getAbsolutePosition=function(){return this._transformedPosition?this._transformedPosition:this.position},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 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.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},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,d){var e;this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=a.Vector3.Zero()),this.computeTransformedPosition(),a.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),b.setFloat4(c,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent),e=a.Vector3.Normalize(this._transformedDirection)):(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 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.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},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={})),function(a){var b=function(){function b(c,d){var e=this;this.filter=b.FILTER_NONE,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[b._id];if(e.isReady(b,h)){f.enableEffect(e._effect),c._bind(b,e._effect,a.Material.TriangleFillMode);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())}c.useBones&&e._effect.setMatrices("mBones",c.skeleton.getTransformMatrices()),c._processRendering(b,e._effect,a.Material.TriangleFillMode,g,h,function(a,b){return e._effect.setMatrix("world",b)})}else e._shadowMap.resetRefreshCounter()}};this._shadowMap.customRenderFunction=function(a,b,c){var d;for(d=0;d=1?1:0>=a?0: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 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={})),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 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=1e4,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.fovMode=c.FOVMODE_VERTICAL_FIXED,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),Object.defineProperty(c,"PERSPECTIVE_CAMERA",{get:function(){return c._PERSPECTIVE_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(c,"ORTHOGRAPHIC_CAMERA",{get:function(){return c._ORTHOGRAPHIC_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(c,"FOVMODE_VERTICAL_FIXED",{get:function(){return c._FOVMODE_VERTICAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(c,"FOVMODE_HORIZONTAL_FIXED",{get:function(){return c._FOVMODE_HORIZONTAL_FIXED},enumerable:!0,configurable:!0}),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 a=this._cache.mode===this.mode&&this._cache.minZ===this.minZ&&this._cache.maxZ===this.maxZ;if(!a)return!1;var b=this.getEngine();return a=this.mode===c.PERSPECTIVE_CAMERA?this._cache.fov===this.fov&&this._cache.aspectRatio===b.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===b.getRenderWidth()&&this._cache.renderHeight===b.getRenderHeight()},c.prototype.attachControl=function(){},c.prototype.detachControl=function(){},c.prototype._update=function(){},c.prototype.attachPostProcess=function(b,c){if(void 0===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){void 0===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 d=this.getEngine();if(this.mode===c.PERSPECTIVE_CAMERA)return this.minZ<=0&&(this.minZ=.1),a.Matrix.PerspectiveFovLHToRef(this.fov,d.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode),this._projectionMatrix;var e=d.getRenderWidth()/2,f=d.getRenderHeight()/2;return a.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-e,this.orthoRight||e,this.orthoBottom||-f,this.orthoTop||f,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._decideIfNeedsToMove=function(){return Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},c.prototype._updatePosition=function(){this.position.addInPlace(this.cameraDirection)},c.prototype._update=function(){var b=this._decideIfNeedsToMove(),c=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(b&&this._updatePosition(),c&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,!this.noRotationConstraint)){var d=Math.PI/2*.95;this.rotation.x>d&&(this.rotation.x=d),this.rotation.x<-d&&(this.rotation.x=-d)}b&&(Math.abs(this.cameraDirection.x)this.maxCameraSpeed||i<-this.maxCameraSpeed)&&(i=1>i?-this.maxCameraSpeed:this.maxCameraSpeed),(j>this.maxCameraSpeed||j<-this.maxCameraSpeed)&&(j=1>j?-this.maxCameraSpeed:this.maxCameraSpeed),(k>this.maxCameraSpeed||k<-this.maxCameraSpeed)&&(k=1>k?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new a.Vector3(this.position.x+i,this.position.y+j,this.position.z+k),this.setTarget(b.position)}},c.prototype._update=function(){b.prototype._update.call(this),this.follow(this.target)},c}(a.TargetCamera);a.FollowCamera=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b){function c(c,d,e){b.call(this,c,d,e),this.ellipsoid=new a.Vector3(.5,1,.5),this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39],this.checkCollisions=!1,this.applyGravity=!1,this.angularSensibility=2e3,this._keys=[],this._collider=new a.Collider,this._needMoveForGravity=!0,this._oldPosition=a.Vector3.Zero(),this._diffPosition=a.Vector3.Zero(),this._newPosition=a.Vector3.Zero()}return __extends(c,b),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.prototype._updatePosition=function(){if(this.checkCollisions&&this.getScene().collisionsEnabled){if(this._collideWithWorld(this.cameraDirection),this.applyGravity){var b=this.position;this._collideWithWorld(this.getScene().gravity),this._needMoveForGravity=0!=a.Vector3.DistanceSquared(b,this.position)}}else this.position.addInPlace(this.cameraDirection)},c.prototype._update=function(){this._checkInputs(),b.prototype._update.call(this)},c}(a.TargetCamera);a.FreeCamera=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b){function c(a,c,d){b.call(this,a,c,d),this._offsetX=null,this._offsetY=null,this._pointerCount=0,this._pointerPressed=[],this.angularSensibility=2e5,this.moveSensibility=500}return __extends(c,b),c.prototype.attachControl=function(b,c){var d,e=this;this._attachedCanvas||(this._attachedCanvas=b,void 0===this._onPointerDown&&(this._onPointerDown=function(a){c||a.preventDefault(),e._pointerPressed.push(a.pointerId),1===e._pointerPressed.length&&(d={x:a.clientX,y:a.clientY})},this._onPointerUp=function(a){c||a.preventDefault();var b=e._pointerPressed.indexOf(a.pointerId);-1!==b&&(e._pointerPressed.splice(b,1),0==b&&(d=null,e._offsetX=null,e._offsetY=null))},this._onPointerMove=function(a){if(c||a.preventDefault(),d){var b=e._pointerPressed.indexOf(a.pointerId);0==b&&(e._offsetX=a.clientX-d.x,e._offsetY=-(a.clientY-d.y))}},this._onLostFocus=function(){e._offsetX=null,e._offsetY=null}),b.addEventListener("pointerdown",this._onPointerDown),b.addEventListener("pointerup",this._onPointerUp),b.addEventListener("pointerout",this._onPointerUp),b.addEventListener("pointermove",this._onPointerMove),a.Tools.RegisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]))},c.prototype.detachControl=function(b){this._attachedCanvas==b&&(b.removeEventListener("pointerdown",this._onPointerDown),b.removeEventListener("pointerup",this._onPointerUp),b.removeEventListener("pointerout",this._onPointerUp),b.removeEventListener("pointermove",this._onPointerMove),a.Tools.UnregisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]),this._attachedCanvas=null)},c.prototype._checkInputs=function(){if(this._offsetX)if(this.cameraRotation.y+=this._offsetX/this.angularSensibility,this._pointerPressed.length>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 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 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.targetScreenOffset=a.Vector2.Zero(),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.pinchPrecision=20,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,this._cache.targetScreenOffset=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,this._cache.targetScreenOffset=this.targetScreenOffset.clone()},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&&this._cache.targetScreenOffset.equals(this.targetScreenOffset):!1},d.prototype.attachControl=function(c,d){var e,f,g,h,i=this,j=!1;if(!this._attachedElement){this._attachedElement=c;var k=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&&!j){var b=a.clientX-e.x,c=a.clientY-e.y;i.inertialAlphaOffset-=b/i.angularSensibility,i.inertialBetaOffset-=c/i.angularSensibility,e={x:a.clientX,y:a.clientY},d||a.preventDefault()}},this._onMouseMove=function(a){if(k.isPointerLock&&!j){var b=a.movementX||a.mozMovementX||a.webkitMovementX||a.msMovementX||0,c=a.movementY||a.mozMovementY||a.webkitMovementY||a.msMovementY||0;i.inertialAlphaOffset-=b/i.angularSensibility,i.inertialBetaOffset-=c/i.angularSensibility,d||a.preventDefault()}},this._wheel=function(a){var b=0;a.wheelDelta?b=a.wheelDelta/(40*i.wheelPrecision):a.detail&&(b=-a.detail/i.wheelPrecision),b&&(i.inertialRadiusOffset+=b),a.preventDefault&&(d||a.preventDefault())},this._onKeyDown=function(a){if(-1!==i.keysUp.indexOf(a.keyCode)||-1!==i.keysDown.indexOf(a.keyCode)||-1!==i.keysLeft.indexOf(a.keyCode)||-1!==i.keysRight.indexOf(a.keyCode)){var b=i._keys.indexOf(a.keyCode);-1===b&&i._keys.push(a.keyCode),a.preventDefault&&(d||a.preventDefault())}},this._onKeyUp=function(a){if(-1!==i.keysUp.indexOf(a.keyCode)||-1!==i.keysDown.indexOf(a.keyCode)||-1!==i.keysLeft.indexOf(a.keyCode)||-1!==i.keysRight.indexOf(a.keyCode)){var b=i._keys.indexOf(a.keyCode);b>=0&&i._keys.splice(b,1),a.preventDefault&&(d||a.preventDefault())}},this._onLostFocus=function(){i._keys=[],f=null},this._onGestureStart=function(a){void 0!==window.MSGesture&&(i._MSGestureHandler||(i._MSGestureHandler=new MSGesture,i._MSGestureHandler.target=c),i._MSGestureHandler.addPointer(a.pointerId))},this._onGesture=function(a){i.radius*=a.scale,a.preventDefault&&(d||(a.stopPropagation(),a.preventDefault()))},this._reset=function(){i._keys=[],i.inertialAlphaOffset=0,i.inertialBetaOffset=0,i.inertialRadiusOffset=0,e=null,f=null},this._touchStart=function(a){2===a.touches.length&&(j=!0,i._pinchStart(a))},this._touchMove=function(a){j&&i._pinchMove(a)},this._touchEnd=function(a){j&&i._pinchEnd(a)},this._pinchStart=function(a){g=a.touches[0].clientX,h=a.touches[1].clientX,j=!0},this._pinchMove=function(a){var b,c,d=0,e=1;2===a.touches.length&&(b=Math.abs(g-h),c=Math.abs(a.touches[0].clientX-a.touches[1].clientX),b>c&&(e=-1),d=i.pinchPrecision/(40*i.wheelPrecision)*e,i.inertialRadiusOffset-=d,g=a.touches[0].clientX,h=a.touches[1].clientX)},this._pinchEnd=function(){j=!1}),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),c.addEventListener("touchstart",this._touchStart,!1),c.addEventListener("touchmove",this._touchMove,!1),c.addEventListener("touchend",this._touchEnd,!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),c.removeEventListener("touchstart",this._touchStart),c.removeEventListener("touchmove",this._touchMove),c.removeEventListener("touchend",this._touchEnd),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.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y,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={})),function(a){var b=function(){function b(c){this.autoClear=!0,this.clearColor=new a.Color3(.2,.2,.3),this.ambientColor=new a.Color3(0,0,0),this.forceWireframe=!1,this.forcePointsCloud=!1,this.forceShowBoundingBoxes=!1,this.animationsEnabled=!0,this.cameraToUseForPointers=null,this.fogEnabled=!0,this.fogMode=b.FOGMODE_NONE,this.fogColor=new a.Color3(.2,.2,.3),this.fogDensity=.1,this.fogStart=0,this.fogEnd=1e3,this.shadowsEnabled=!0,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.skeletonsEnabled=!0,this.skeletons=new Array,this.lensFlaresEnabled=!0,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.proceduralTexturesEnabled=!0,this._proceduralTextures=new Array,this.soundTracks=new Array,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._onAfterRenderCallbacks=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._activeBones=0,this._activeAnimatables=new Array,this._transformMatrix=a.Matrix.Zero(),this._scaledPosition=a.Vector3.Zero(),this._scaledVelocity=a.Vector3.Zero(),this._engine=c,c.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._outlineRenderer=new a.OutlineRenderer(this),this.attachControl(),this._debugLayer=new a.DebugLayer(this),this.mainSoundTrack=new a.SoundTrack(this,{mainTrack:!0})}return Object.defineProperty(b,"FOGMODE_NONE",{get:function(){return b._FOGMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(b,"FOGMODE_EXP",{get:function(){return b._FOGMODE_EXP},enumerable:!0,configurable:!0}),Object.defineProperty(b,"FOGMODE_EXP2",{get:function(){return b._FOGMODE_EXP2},enumerable:!0,configurable:!0}),Object.defineProperty(b,"FOGMODE_LINEAR",{get:function(){return b._FOGMODE_LINEAR},enumerable:!0,configurable:!0}),Object.defineProperty(b.prototype,"debugLayer",{get:function(){return this._debugLayer},enumerable:!0,configurable:!0}),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.getCachedMaterial=function(){return this._cachedMaterial},b.prototype.getBoundingBoxRenderer=function(){return this._boundingBoxRenderer},b.prototype.getOutlineRenderer=function(){return this._outlineRenderer},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.getActiveBones=function(){return this._activeBones},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.incrementRenderId=function(){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._meshUnderPointer=d.pickedMesh,b.setPointerOverMesh(d.pickedMesh),c.style.cursor="pointer"):(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,c));break;case 1:e.pickedMesh.actionManager.processTrigger(a.ActionManager.OnCenterPickTrigger,a.ActionEvent.CreateNew(e.pickedMesh,c));break;case 2:e.pickedMesh.actionManager.processTrigger(a.ActionManager.OnRightPickTrigger,a.ActionEvent.CreateNew(e.pickedMesh,c))}e.pickedMesh.actionManager.processTrigger(a.ActionManager.OnPickTrigger,a.ActionEvent.CreateNew(e.pickedMesh,c))}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),a.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp}])},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),a.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler: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.registerAfterRender=function(a){this._onAfterRenderCallbacks.push(a)},b.prototype.unregisterAfterRender=function(a){var b=this._onAfterRenderCallbacks.indexOf(a);b>-1&&this._onAfterRenderCallbacks.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.getNodeByName=function(a){var b=this.getMeshByName(a);if(b)return b;var c=this.getLightByName(a);return c?c:this.getCameraByName(a)},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];if(!f.isBlocked&&(this._totalVertices+=f.getTotalVertices(),f.isReady())){f.computeWorldMatrix(),f.actionManager&&f.actionManager.hasSpecificTriggers([a.ActionManager.OnIntersectionEnterTrigger,a.ActionManager.OnIntersectionExitTrigger])&&this._meshesForIntersections.pushNoDuplicate(f);var g=f.getLOD(this.activeCamera);g&&(f._preActivate(),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(g)))}}var h=a.Tools.Now;if(this.particlesEnabled){a.Tools.StartPerformanceCounter("Particles",this.particleSystems.length>0);for(var i=0;i0)}this._particlesDuration+=a.Tools.Now-h},b.prototype._activeMesh=function(a){if(a.skeleton&&this.skeletonsEnabled&&this._activeSkeletons.pushNoDuplicate(a.skeleton),(a.showBoundingBox||this.forceShowBoundingBoxes)&&this._boundingBoxRenderer.renderList.push(a.getBoundingInfo().boundingBox),a&&a.subMeshes){var b,c;if(a._submeshesOctree&&a.useOctreeForRenderingSelection){var d=a._submeshesOctree.select(this._frustumPlanes);b=d.length,c=d.data}else c=a.subMeshes,b=c.length;for(var e=0;b>e;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(b){var c=this._engine;if(this.activeCamera=b,!this.activeCamera)throw new Error("Active camera not set");a.Tools.StartPerformanceCounter("Rendering camera "+this.activeCamera.name),c.setViewport(this.activeCamera.viewport),this._renderId++,this.updateTransformMatrix(),this.beforeCameraRender&&this.beforeCameraRender(this.activeCamera);var d=a.Tools.Now;a.Tools.StartPerformanceCounter("Active meshes evaluation"),this._evaluateActiveMeshes(),this._evaluateActiveMeshesDuration+=a.Tools.Now-d,a.Tools.EndPerformanceCounter("Active meshes evaluation");for(var e=0;e0);for(var h=0;h0),this._renderId++}this._renderTargets.length>0&&c.restoreDefaultFramebuffer(),this._renderTargetsDuration+=a.Tools.Now-g,this.postProcessManager._prepareFrame();var j=a.Tools.Now;if(this.layers.length){c.setDepthBuffer(!1);var k,l;for(k=0;k0);for(var m=0;m0)}if(this.layers.length){for(c.setDepthBuffer(!1),k=0;k-1&&e.trigger===a.ActionManager.OnIntersectionExitTrigger){e._executeCurrent(a.ActionEvent.CreateNew(c));var j=c._intersectionsInProgress.indexOf(g);j>-1&&c._intersectionsInProgress.splice(j,1)}}}},b.prototype.render=function(){var c=a.Tools.Now;this._particlesDuration=0,this._spritesDuration=0,this._activeParticles=0,this._renderDuration=0,this._renderTargetsDuration=0,this._evaluateActiveMeshesDuration=0,this._totalVertices=0,this._activeVertices=0,this._activeBones=0,this.getEngine().resetDrawCalls(),this._meshesForIntersections.reset(),this.resetCachedMaterial(),a.Tools.StartPerformanceCounter("Scene rendering"),this.actionManager&&this.actionManager.processTrigger(a.ActionManager.OnEveryFrameTrigger,null),this.beforeRender&&this.beforeRender();for(var d=0;d0);for(var i=0;i0),this._renderId++}if(this.customRenderTargets.length>0&&g.restoreDefaultFramebuffer(),this._renderTargetsDuration+=a.Tools.Now-f,this.activeCamera=h,this.proceduralTexturesEnabled){a.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var k=0;k0)}if(this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,!0),this.shadowsEnabled)for(var m=0;m0)for(var p=this._renderId,q=0;q0?this.activeCameras[0]:this.activeCamera,b&&c.canUseWebAudio){c.audioContext.listener.setPosition(b.position.x,b.position.y,b.position.z);var d=a.Matrix.Invert(b.getViewMatrix()),e=a.Vector3.TransformNormal(new a.Vector3(0,0,-1),d);e.normalize(),c.audioContext.listener.setOrientation(e.x,e.y,e.z,0,1,0);for(var f=0;f-1&&this._engine.scenes.splice(b,1),this._engine.wipeCaches()},b.prototype._getNewPosition=function(a,b,c,d,e,f){void 0===f&&(f=null),a.divideToRef(c.radius,this._scaledPosition),b.divideToRef(c.radius,this._scaledVelocity),c.retry=0,c.initialVelocity=this._scaledVelocity,c.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,c,d,e,f),e.multiplyInPlace(c.radius)},b.prototype._collideWithWorld=function(b,c,d,e,f,g){void 0===g&&(g=null);var h=10*a.Engine.CollisionsEpsilon;if(d.retry>=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;c-1&&this._onAfterWorldMatrixUpdate.splice(b,1)},c.prototype.setPositionWithLocalVector=function(b){this.computeWorldMatrix(),this.position=a.Vector3.TransformNormal(b,this._localWorld)},c.prototype.getPositionExpressedInLocalSpace=function(){this.computeWorldMatrix();var b=this._localWorld.clone();return b.invert(),a.Vector3.TransformNormal(this.position,b)},c.prototype.locallyTranslate=function(b){this.computeWorldMatrix(),this.position=a.Vector3.TransformCoordinates(b,this._localWorld)},c.prototype.lookAt=function(b,c,d,e){c=c||0,d=d||0,e=e||0;var f=b.subtract(this.position),g=-Math.atan2(f.z,f.x)-Math.PI/2,h=Math.sqrt(f.x*f.x+f.z*f.z),i=Math.atan2(f.y,h);this.rotationQuaternion=a.Quaternion.RotationYawPitchRoll(g+c,i+d,e)},c.prototype.isInFrustum=function(a){return this._boundingInfo.isInFrustum(a)?!0:!1},c.prototype.isCompletelyInFrustum=function(b){b||(b=this.getScene().activeCamera);var c=b.getViewMatrix().multiply(b.getProjectionMatrix());return this._boundingInfo.isCompletelyInFrustum(a.Frustum.GetPlanes(c))?!0:!1},c.prototype.intersectsMesh=function(a,b){return this._boundingInfo&&a._boundingInfo?this._boundingInfo.intersects(a._boundingInfo,b):!1},c.prototype.intersectsPoint=function(a){return this._boundingInfo?this._boundingInfo.intersectsPoint(a):!1},c.prototype.setPhysicsState=function(b,c){var d=this.getScene().getPhysicsEngine();if(d)return b=b||a.PhysicsEngine.NoImpostor,b.impostor&&(c=b,b=b.impostor),b===a.PhysicsEngine.NoImpostor?void d._unregisterMesh(this):(c?(c.mass=c.mass||0,c.friction=c.friction||.2,c.restitution=c.restitution||.2):c={mass:0,friction:.2,restitution:.2},this._physicImpostor=b,this._physicsMass=c.mass,this._physicsFriction=c.friction,this._physicRestitution=c.restitution,d._registerMesh(this,b,c))},c.prototype.getPhysicsImpostor=function(){return this._physicImpostor?this._physicImpostor:a.PhysicsEngine.NoImpostor},c.prototype.getPhysicsMass=function(){return this._physicsMass?this._physicsMass:0},c.prototype.getPhysicsFriction=function(){return this._physicsFriction?this._physicsFriction:0},c.prototype.getPhysicsRestitution=function(){return this._physicRestitution?this._physicRestitution:0},c.prototype.getPositionInCameraSpace=function(b){return b||(b=this.getScene().activeCamera),a.Vector3.TransformCoordinates(this.absolutePosition,b.getViewMatrix())},c.prototype.getDistanceToCamera=function(a){return a||(a=this.getScene().activeCamera),this.absolutePosition.subtract(a.position).length()},c.prototype.applyImpulse=function(a,b){this._physicImpostor&&this.getScene().getPhysicsEngine()._applyImpulse(this,a,b)},c.prototype.setPhysicsLinkWith=function(a,b,c,d){this._physicImpostor&&this.getScene().getPhysicsEngine()._createLink(this,a,b,c,d)},c.prototype.updatePhysicsBodyPosition=function(){this._physicImpostor&&this.getScene().getPhysicsEngine()._updateBodyPosition(this)},c.prototype.moveWithCollisions=function(b){var c=this.getAbsolutePosition();c.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPositionForCollisions),this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset),this._collider.radius=this.ellipsoid,this.getScene()._getNewPosition(this._oldPositionForCollisions,b,this._collider,3,this._newPositionForCollisions,this),this._newPositionForCollisions.subtractToRef(this._oldPositionForCollisions,this._diffPositionForCollisions),this._diffPositionForCollisions.length()>a.Engine.CollisionsEpsilon&&this.position.addInPlace(this._diffPositionForCollisions)},c.prototype.createOrUpdateSubmeshesOctree=function(b,c){void 0===b&&(b=64),void 0===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.distance0},enumerable:!0,configurable:!0}),d.prototype._sortLODLevels=function(){this._LODLevels.sort(function(a,b){return a.distanceb.distance?-1:0})},d.prototype.addLODLevel=function(b,c){if(c&&c._masterMesh)return a.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var d=new a.Internals.MeshLODLevel(b,c);return this._LODLevels.push(d),c&&(c._masterMesh=this),this._sortLODLevels(),this},d.prototype.removeLODLevel=function(a){for(var b=0;bc)return this;for(var d=0;db)){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,e){if(b instanceof Array){var f=c;c=b,b=f,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,e);else{var g=new a.VertexData;g.set(c,b);var h=this.getScene();new a.Geometry(a.Geometry.RandomId(),h,g,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.updateVerticesDataDirectly=function(a,b,c,d){this._geometry&&(d?(this.makeGeometryUnique(),this.updateVerticesDataDirectly(a,b,c,!1)):this._geometry.updateVerticesDataDirectly(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,c){if(this._geometry)this._geometry.setIndices(b,c);else{var d=new a.VertexData;d.indices=b;var e=this.getScene();new a.Geometry(a.Geometry.RandomId(),e,d,!1,this)}},d.prototype._bind=function(b,c,d){var e,f=this.getScene().getEngine();switch(d){case a.Material.PointFillMode:e=null;break;case a.Material.WireFrameFillMode:e=b.getLinesIndexBuffer(this.getIndices(),f);break;default:case a.Material.TriangleFillMode:e=this._geometry.getIndexBuffer()}f.bindMultiBuffers(this._geometry.getVertexBuffers(),e,c)},d.prototype._draw=function(b,c,d){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var e=this.getScene().getEngine();switch(c){case a.Material.PointFillMode:e.drawPointClouds(b.verticesStart,b.verticesCount,d);break;case a.Material.WireFrameFillMode:e.draw(!1,0,b.linesIndexCount,d);break;default:e.draw(!0,b.indexStart,b.indexCount,d)}}},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=Math.max(this._visibleInstances.defaultRenderId,c),d=Math.max(this._visibleInstances.selfDefaultRenderId,c)),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=c.visibleInstances[a._id],g=f.length+1,h=16*g*4;this._instancesBufferSizem;m++){var n=k[m];for(g=0;gp;p++)e[h].push(d[h][n*o+p])}}var q=[],r=e[a.VertexBuffer.PositionKind];for(m=0;l>m;m+=3){k[m]=m,k[m+1]=m+1,k[m+2]=m+2;for(var s=a.Vector3.FromArray(r,3*m),t=a.Vector3.FromArray(r,3*(m+1)),u=a.Vector3.FromArray(r,3*(m+2)),v=s.subtract(t),w=u.subtract(t),x=a.Vector3.Normalize(a.Vector3.Cross(v,w)),y=0;3>y;y++)q.push(x.x),q.push(x.y),q.push(x.z)}for(this.setIndices(k),this.setVerticesData(a.VertexBuffer.NormalKind,q,f),g=0;g65536)return a.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices"),null;var k=a.VertexData.ExtractFromMesh(f);for(k.transform(f.getWorldMatrix()),j=1;jj;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={})),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.scale=function(){},Object.defineProperty(b.prototype,"canRescale",{get:function(){return!1},enumerable:!0,configurable:!0}),b.prototype._removeFromCache=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={})),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){if(b)return b(this._opaqueSubMeshes,this._alphaTestSubMeshes,this._transparentSubMeshes),!0;if(0===this._opaqueSubMeshes.length&&0===this._alphaTestSubMeshes.length&&0===this._transparentSubMeshes.length)return!1;var c,d,e=this._scene.getEngine();for(c=0;cb._alphaIndex?1:a._alphaIndexb._distanceToCamera?-1:0}),e.setAlphaMode(a.Engine.ALPHA_COMBINE),c=0;c=0&&this.getScene()._proceduralTextures.splice(b,1),a.prototype.dispose.call(this)},b}(a.Texture);a.ProceduralTexture=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b){function c(c,d,e,f,g){b.call(this,c,d,"wood",e,f,g),this._ampScale=100,this._woodColor=new a.Color3(.32,.17,.09),this.updateShaderUniforms(),this.refreshRate=0}return __extends(c,b),c.prototype.updateShaderUniforms=function(){this.setFloat("ampScale",this._ampScale),this.setColor3("woodColor",this._woodColor)},Object.defineProperty(c.prototype,"ampScale",{get:function(){return this._ampScale},set:function(a){this._ampScale=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"woodColor",{get:function(){return this._woodColor},set:function(a){this._woodColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),c}(a.ProceduralTexture);a.WoodProceduralTexture=b;var c=function(b){function c(d,e,f,g,h){b.call(this,d,e,"fire",f,g,h),this._time=0,this._speed=new a.Vector2(.5,.3),this._shift=1.6,this._autoGenerateTime=!0,this._alphaThreshold=.5,this._fireColors=c.RedFireColors,this.updateShaderUniforms(),this.refreshRate=1}return __extends(c,b),c.prototype.updateShaderUniforms=function(){this.setFloat("time",this._time),this.setVector2("speed",this._speed),this.setFloat("shift",this._shift),this.setColor3("c1",this._fireColors[0]),this.setColor3("c2",this._fireColors[1]),this.setColor3("c3",this._fireColors[2]),this.setColor3("c4",this._fireColors[3]),this.setColor3("c5",this._fireColors[4]),this.setColor3("c6",this._fireColors[5]),this.setFloat("alphaThreshold",this._alphaThreshold)},c.prototype.render=function(a){this._autoGenerateTime&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),b.prototype.render.call(this,a)},Object.defineProperty(c,"PurpleFireColors",{get:function(){return[new a.Color3(.5,0,1),new a.Color3(.9,0,1),new a.Color3(.2,0,1),new a.Color3(1,.9,1),new a.Color3(.1,.1,1),new a.Color3(.9,.9,1)]},enumerable:!0,configurable:!0}),Object.defineProperty(c,"GreenFireColors",{get:function(){return[new a.Color3(.5,1,0),new a.Color3(.5,1,0),new a.Color3(.3,.4,0),new a.Color3(.5,1,0),new a.Color3(.2,0,0),new a.Color3(.5,1,0)]},enumerable:!0,configurable:!0}),Object.defineProperty(c,"RedFireColors",{get:function(){return[new a.Color3(.5,0,.1),new a.Color3(.9,0,0),new a.Color3(.2,0,0),new a.Color3(1,.9,0),new a.Color3(.1,.1,.1),new a.Color3(.9,.9,.9)]},enumerable:!0,configurable:!0}),Object.defineProperty(c,"BlueFireColors",{get:function(){return[new a.Color3(.1,0,.5),new a.Color3(0,0,.5),new a.Color3(.1,0,.2),new a.Color3(0,0,1),new a.Color3(.1,.2,.3),new a.Color3(0,.2,.9)]},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"fireColors",{get:function(){return this._fireColors},set:function(a){this._fireColors=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"time",{get:function(){return this._time},set:function(a){this._time=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"speed",{get:function(){return this._speed},set:function(a){this._speed=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"shift",{get:function(){return this._shift},set:function(a){this._shift=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"alphaThreshold",{get:function(){return this._alphaThreshold},set:function(a){this._alphaThreshold=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),c}(a.ProceduralTexture);a.FireProceduralTexture=c;var d=function(b){function c(c,d,e,f,g){b.call(this,c,d,"cloud",e,f,g),this._skyColor=new a.Color3(.15,.68,1),this._cloudColor=new a.Color3(1,1,1),this.updateShaderUniforms(),this.refreshRate=0}return __extends(c,b),c.prototype.updateShaderUniforms=function(){this.setColor3("skyColor",this._skyColor),this.setColor3("cloudColor",this._cloudColor)},Object.defineProperty(c.prototype,"skyColor",{get:function(){return this._skyColor},set:function(a){this._skyColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"cloudColor",{get:function(){return this._cloudColor},set:function(a){this._cloudColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),c}(a.ProceduralTexture);a.CloudProceduralTexture=d;var e=function(b){function c(c,d,e,f,g){b.call(this,c,d,"grass",e,f,g),this._herb1=new a.Color3(.29,.38,.02),this._herb2=new a.Color3(.36,.49,.09),this._herb3=new a.Color3(.51,.6,.28),this._groundColor=new a.Color3(1,1,1),this._grassColors=[new a.Color3(.29,.38,.02),new a.Color3(.36,.49,.09),new a.Color3(.51,.6,.28)],this.updateShaderUniforms(),this.refreshRate=0 }return __extends(c,b),c.prototype.updateShaderUniforms=function(){this.setColor3("herb1Color",this._grassColors[0]),this.setColor3("herb2Color",this._grassColors[1]),this.setColor3("herb3Color",this._grassColors[2]),this.setColor3("groundColor",this._groundColor)},Object.defineProperty(c.prototype,"grassColors",{get:function(){return this._grassColors},set:function(a){this._grassColors=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"groundColor",{get:function(){return this._groundColor},set:function(a){this.groundColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),c}(a.ProceduralTexture);a.GrassProceduralTexture=e;var f=function(b){function c(c,d,e,f,g){b.call(this,c,d,"road",e,f,g),this._roadColor=new a.Color3(.53,.53,.53),this.updateShaderUniforms(),this.refreshRate=0}return __extends(c,b),c.prototype.updateShaderUniforms=function(){this.setColor3("roadColor",this._roadColor)},Object.defineProperty(c.prototype,"roadColor",{get:function(){return this._roadColor},set:function(a){this._roadColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),c}(a.ProceduralTexture);a.RoadProceduralTexture=f;var g=function(b){function c(c,d,e,f,g){b.call(this,c,d,"brick",e,f,g),this._numberOfBricksHeight=15,this._numberOfBricksWidth=5,this._jointColor=new a.Color3(.72,.72,.72),this._brickColor=new a.Color3(.77,.47,.4),this.updateShaderUniforms(),this.refreshRate=0}return __extends(c,b),c.prototype.updateShaderUniforms=function(){this.setFloat("numberOfBricksHeight",this._numberOfBricksHeight),this.setFloat("numberOfBricksWidth",this._numberOfBricksWidth),this.setColor3("brickColor",this._brickColor),this.setColor3("jointColor",this._jointColor)},Object.defineProperty(c.prototype,"numberOfBricksHeight",{get:function(){return this._numberOfBricksHeight},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"cloudColor",{set:function(a){this._numberOfBricksHeight=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"numberOfBricksWidth",{get:function(){return this._numberOfBricksWidth},set:function(a){this._numberOfBricksHeight=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"jointColor",{get:function(){return this._jointColor},set:function(a){this._jointColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"brickColor",{get:function(){return this._brickColor},set:function(a){this._brickColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),c}(a.ProceduralTexture);a.BrickProceduralTexture=g;var h=function(b){function c(c,d,e,f,g){b.call(this,c,d,"marble",e,f,g),this._numberOfTilesHeight=3,this._numberOfTilesWidth=3,this._amplitude=9,this._marbleColor=new a.Color3(.77,.47,.4),this._jointColor=new a.Color3(.72,.72,.72),this.updateShaderUniforms(),this.refreshRate=0}return __extends(c,b),c.prototype.updateShaderUniforms=function(){this.setFloat("numberOfTilesHeight",this._numberOfTilesHeight),this.setFloat("numberOfTilesWidth",this._numberOfTilesWidth),this.setFloat("amplitude",this._amplitude),this.setColor3("marbleColor",this._marbleColor),this.setColor3("jointColor",this._jointColor)},Object.defineProperty(c.prototype,"numberOfTilesHeight",{get:function(){return this._numberOfTilesHeight},set:function(a){this._numberOfTilesHeight=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"numberOfTilesWidth",{get:function(){return this._numberOfTilesWidth},set:function(a){this._numberOfTilesWidth=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"jointColor",{get:function(){return this._jointColor},set:function(a){this._jointColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"marbleColor",{get:function(){return this._marbleColor},set:function(a){this._marbleColor=a,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),c}(a.ProceduralTexture);a.MarbleProceduralTexture=h}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b){function c(a,c,d,e,f,g){b.call(this,a,d,null,e,f,g),this._animate=!0,this._time=0,this._texturePath=c,this.loadJson(c),this.refreshRate=1}return __extends(c,b),c.prototype.loadJson=function(b){function c(){a.Tools.Log("No config file found in "+b+" trying to use ShadersStore or DOM element");try{e.setFragment(e._texturePath)}catch(c){a.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}}var d=this,e=this,f=b+"/config.json",g=new XMLHttpRequest;g.open("GET",f,!0),g.addEventListener("load",function(){if(200===g.status||a.Tools.ValidateXHRData(g,1))try{d._config=JSON.parse(g.response),d.updateShaderUniforms(),d.updateTextures(),d.setFragment(d._texturePath+"/custom"),d._animate=d._config.animate,d.refreshRate=d._config.refreshrate}catch(b){c()}else c()},!1),g.addEventListener("error",function(){c()},!1);try{g.send()}catch(h){a.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},c.prototype.isReady=function(){if(!b.prototype.isReady.call(this))return!1;for(var a in this._textures){var c=this._textures[a];if(!c.isReady())return!1}return!0},c.prototype.render=function(a){this._animate&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),b.prototype.render.call(this,a)},c.prototype.updateTextures=function(){for(var b=0;bthis._maxRank&&(this._maxRank=a),this._defines[a]=new Array),this._defines[a].push(b)},Object.defineProperty(a.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),a.prototype.reduce=function(a){for(var b=this._defines[this._currentRank],c=0;c nyi - jointHPercentage){\n color = mix(jointColor, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);\n }\n else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){\n color = mix(jointColor, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);\n }\n else {\n float brickColorSwitch = mod(floor(yi) + floor(xi), 3.0);\n\n if (brickColorSwitch == 0.0)\n color = mix(color, vec3(0.33, 0.33, 0.33), 0.3);\n else if (brickColorSwitch == 2.0)\n color = mix(color, vec3(0.11, 0.11, 0.11), 0.3);\n }\n\n gl_FragColor = vec4(color, 1.0);\n}",cloudPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nvarying vec2 vUV;\n\nuniform vec3 skyColor;\nuniform vec3 cloudColor;\n\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\n\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\n\nfloat fbm(vec2 n) {\n float total = 0.0, amplitude = 1.0;\n for (int i = 0; i < 4; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.5;\n }\n return total;\n}\n\nvoid main() {\n\n vec2 p = vUV * 12.0;\n vec3 c = mix(skyColor, cloudColor, fbm(p));\n gl_FragColor = vec4(c, 1);\n\n}",colorPixelShader:"precision highp float;\n\nuniform vec4 color;\n\nvoid main(void) {\n gl_FragColor = color;\n}",colorVertexShader:"precision highp float;\n\n// Attributes\nattribute vec3 position;\n\n// Uniforms\nuniform mat4 worldViewProjection;\n\nvoid main(void) {\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}",convolutionPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nuniform float kernel[9];\n\nvoid main(void)\n{\n vec2 onePixel = vec2(1.0, 1.0) / screenSize;\n vec4 colorSum =\n texture2D(textureSampler, vUV + onePixel * vec2(-1, -1)) * kernel[0] +\n texture2D(textureSampler, vUV + onePixel * vec2(0, -1)) * kernel[1] +\n texture2D(textureSampler, vUV + onePixel * vec2(1, -1)) * kernel[2] +\n texture2D(textureSampler, vUV + onePixel * vec2(-1, 0)) * kernel[3] +\n texture2D(textureSampler, vUV + onePixel * vec2(0, 0)) * kernel[4] +\n texture2D(textureSampler, vUV + onePixel * vec2(1, 0)) * kernel[5] +\n texture2D(textureSampler, vUV + onePixel * vec2(-1, 1)) * kernel[6] +\n texture2D(textureSampler, vUV + onePixel * vec2(0, 1)) * kernel[7] +\n texture2D(textureSampler, vUV + onePixel * vec2(1, 1)) * kernel[8];\n\n float kernelWeight =\n kernel[0] +\n kernel[1] +\n kernel[2] +\n kernel[3] +\n kernel[4] +\n kernel[5] +\n kernel[6] +\n kernel[7] +\n kernel[8];\n\n if (kernelWeight <= 0.0) {\n kernelWeight = 1.0;\n }\n\n gl_FragColor = vec4((colorSum / kernelWeight).rgb, 1);\n}",defaultPixelShader:"#ifdef GL_ES\nprecision highp 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// 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 vec4 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;\nuniform float darkness0;\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;\nuniform float darkness1;\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;\nuniform float darkness2;\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;\nuniform float darkness3;\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 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// Fresnel\n#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)\n{\n float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);\n return clamp(fresnelTerm, 0., 1.);\n}\n#endif\n\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n// Reflection\n#ifdef REFLECTION\nvarying vec3 vPositionUVW;\nuniform samplerCube reflectionCubeSampler;\nuniform sampler2D reflection2DSampler;\nuniform vec3 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform mat4 view;\n\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 vPositionUVW;\n }\n\n return vec3(0, 0, 0);\n}\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, float darkness)\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 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 if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] / 1500.0)) < depth.z) visibility -= 0.2;\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] / 1500.0)) < depth.z) visibility -= 0.2;\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] / 1500.0)) < depth.z) visibility -= 0.2;\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] / 1500.0)) < depth.z) visibility -= 0.2;\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.0 - 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;\n map = map * 255. / 127. - 128. / 127.;\n mat3 TBN = cotangent_frame(vNormalW * vBumpInfos.y, -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 baseColor.rgb *= vColor.rgb;\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\n#ifdef REFLECTIONFRESNEL\n float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);\n\n reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\n#endif\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#endif\n\n#ifdef VERTEXALPHA\n alpha *= vColor.a;\n#endif\n\n#ifdef OPACITYFRESNEL\n float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);\n\n alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;\n#endif\n\n // Emissive\n vec3 emissiveColor = vEmissiveColor;\n#ifdef EMISSIVE\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\n#endif\n\n#ifdef EMISSIVEFRESNEL\n float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);\n\n emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;\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 // Fresnel\n#ifdef DIFFUSEFRESNEL\n float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);\n\n diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;\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#ifdef SPECULAROVERALPHA\n alpha = clamp(alpha + dot(finalSpecular, vec3(0.3, 0.59, 0.11)), 0., 1.);\n#endif\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 highp 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 vec4 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#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\n// Output\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef VERTEXCOLOR\nvarying vec4 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 INSTANCES\n finalWorld = mat4(world0, world1, world2, world3);\n#else\n 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\n#ifdef BONES4\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\n#else\n finalWorld = finalWorld * (m0 + m1 + m2);\n#endif \n\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\n // Point size\n#ifdef POINTSIZE\n gl_PointSize = pointSize;\n#endif\n}",depthPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n\nuniform float far;\n\nvoid main(void)\n{\n#ifdef ALPHATEST\n if (texture2D(diffuseSampler, vUV).a < 0.4)\n discard;\n#endif\n\n float depth = (gl_FragCoord.z / gl_FragCoord.w) / far;\n gl_FragColor = vec4(depth, depth * depth, 0.0, 1.0);\n}",depthVertexShader:"#ifdef GL_ES\nprecision highp 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#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 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}",displayPassPixelShader:"#ifdef GL_ES\nprecision highp 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 highp 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}",firePixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform float time;\nuniform vec3 c1;\nuniform vec3 c2;\nuniform vec3 c3;\nuniform vec3 c4;\nuniform vec3 c5;\nuniform vec3 c6;\nuniform vec2 speed;\nuniform float shift;\nuniform float alphaThreshold;\n\nvarying vec2 vUV;\n\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\n\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\n\nfloat fbm(vec2 n) {\n float total = 0.0, amplitude = 1.0;\n for (int i = 0; i < 4; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.5;\n }\n return total;\n}\n\nvoid main() {\n vec2 p = vUV * 8.0;\n float q = fbm(p - time * 0.1);\n vec2 r = vec2(fbm(p + q + time * speed.x - p.x - p.y), fbm(p + q - time * speed.y));\n vec3 c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);\n vec3 color = c * cos(shift * vUV.y);\n float luminance = dot(color.rgb, vec3(0.3, 0.59, 0.11));\n\n gl_FragColor = vec4(color, luminance * alphaThreshold + (1.0 - alphaThreshold));\n}",fxaaPixelShader:"#ifdef GL_ES\nprecision highp 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}",grassPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nvarying vec2 vPosition;\nvarying vec2 vUV;\n\nuniform vec3 herb1Color;\nuniform vec3 herb2Color;\nuniform vec3 herb3Color;\nuniform vec3 groundColor;\n\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\n\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\n\nfloat fbm(vec2 n) {\n float total = 0.0, amplitude = 1.0;\n for (int i = 0; i < 4; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.5;\n }\n return total;\n}\n\nvoid main(void) {\n vec3 color = mix(groundColor, herb1Color, rand(gl_FragCoord.xy * 4.0));\n color = mix(color, herb2Color, rand(gl_FragCoord.xy * 8.0));\n color = mix(color, herb3Color, rand(gl_FragCoord.xy));\n color = mix(color, herb1Color, fbm(gl_FragCoord.xy * 16.0));\n gl_FragColor = vec4(color, 1.0);\n}",layerPixelShader:"#ifdef GL_ES\nprecision highp 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 highp 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 highp 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 vec4 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// Fresnel\n#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)\n{\n float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);\n return clamp(fresnelTerm, 0., 1.);\n}\n#endif\n\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\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 baseColor.rgb *= vColor.rgb;\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\n#ifdef REFLECTIONFRESNEL\n float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);\n\n reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\n#endif\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#ifdef VERTEXALPHA\n alpha *= vColor.a;\n#endif\n\n#ifdef OPACITYFRESNEL\n float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);\n\n alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;\n#endif\n\n // Emissive\n vec3 emissiveColor = vEmissiveColor;\n#ifdef EMISSIVE\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\n#endif\n\n#ifdef EMISSIVEFRESNEL\n float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);\n\n emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;\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 // Fresnel\n#ifdef DIFFUSEFRESNEL\n float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);\n\n diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;\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 highp 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 vec4 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 vec4 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 highp 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 highp 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}",marblePixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nvarying vec2 vPosition;\nvarying vec2 vUV;\n\nuniform float numberOfTilesHeight;\nuniform float numberOfTilesWidth;\nuniform float amplitude;\nuniform vec3 brickColor;\nuniform vec3 jointColor;\n\nconst vec3 tileSize = vec3(1.1, 1.0, 1.1);\nconst vec3 tilePct = vec3(0.98, 1.0, 0.98);\n\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\n\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\n\nfloat turbulence(vec2 P)\n{\n float val = 0.0;\n float freq = 1.0;\n for (int i = 0; i < 4; i++)\n {\n val += abs(noise(P*freq) / freq);\n freq *= 2.07;\n }\n return val;\n}\n\nfloat round(float number){\n return sign(number)*floor(abs(number) + 0.5);\n}\n\nvec3 marble_color(float x)\n{\n vec3 col;\n x = 0.5*(x + 1.);\n x = sqrt(x); \n x = sqrt(x);\n x = sqrt(x);\n col = vec3(.2 + .75*x); \n col.b *= 0.95; \n return col;\n}\n\nvoid main()\n{\n float brickW = 1.0 / numberOfTilesWidth;\n float brickH = 1.0 / numberOfTilesHeight;\n float jointWPercentage = 0.01;\n float jointHPercentage = 0.01;\n vec3 color = brickColor;\n float yi = vUV.y / brickH;\n float nyi = round(yi);\n float xi = vUV.x / brickW;\n\n if (mod(floor(yi), 2.0) == 0.0){\n xi = xi - 0.5;\n }\n\n float nxi = round(xi);\n vec2 brickvUV = vec2((xi - floor(xi)) / brickH, (yi - floor(yi)) / brickW);\n\n if (yi < nyi + jointHPercentage && yi > nyi - jointHPercentage){\n color = mix(jointColor, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);\n }\n else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){\n color = mix(jointColor, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);\n }\n else {\n float t = 6.28 * brickvUV.x / (tileSize.x + noise(vec2(vUV)*6.0));\n t += amplitude * turbulence(brickvUV.xy);\n t = sin(t);\n color = marble_color(t);\n }\n\n gl_FragColor = vec4(color, 0.0);\n}",oculusDistortionCorrectionPixelShader:"#ifdef GL_ES\nprecision highp 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\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}",outlinePixelShader:"precision highp float;\n\nuniform vec4 color;\n\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n\nvoid main(void) {\n#ifdef ALPHATEST\n if (texture2D(diffuseSampler, vUV).a < 0.4)\n discard;\n#endif\n\n gl_FragColor = color;\n}",outlineVertexShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\n// Attribute\nattribute vec3 position;\nattribute vec3 normal;\n\n#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\n// Uniform\nuniform float offset;\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 viewProjection;\n#ifdef BONES\nuniform mat4 mBones[BonesPerMesh];\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 vec3 offsetPosition = position + normal * offset;\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(offsetPosition, 1.0);\n#else\n gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 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}",particlesPixelShader:"#ifdef GL_ES\nprecision highp 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 highp 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 highp 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 highp 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}",proceduralVertexShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\n// Attributes\nattribute vec2 position;\n\n// Output\nvarying vec2 vPosition;\nvarying vec2 vUV;\n\nconst vec2 madd = vec2(0.5, 0.5);\n\nvoid main(void) { \n vPosition = position;\n vUV = position * madd + madd;\n gl_Position = vec4(position, 0.0, 1.0);\n}",refractionPixelShader:"#ifdef GL_ES\nprecision highp 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}",roadPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nvarying vec2 vUV; \nuniform vec3 roadColor;\n\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\n\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\n\nfloat fbm(vec2 n) {\n float total = 0.0, amplitude = 1.0;\n for (int i = 0; i < 4; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.5;\n }\n return total;\n}\n\nvoid main(void) {\n float ratioy = mod(gl_FragCoord.y * 100.0 , fbm(vUV * 2.0));\n vec3 color = roadColor * ratioy;\n gl_FragColor = vec4(color, 1.0);\n}",shadowMapPixelShader:"#ifdef GL_ES\nprecision highp 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 highp 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 highp 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 highp 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}",ssaoPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\n#define SAMPLES 16\n\nuniform sampler2D textureSampler;\nuniform sampler2D randomSampler;\n\nuniform float randTextureTiles;\nuniform float samplesFactor;\nuniform vec3 sampleSphere[16];\n\nvarying vec2 vUV;\n\nconst vec2 offset1 = vec2(0.0, 0.01);\nconst vec2 offset2 = vec2(0.01, 0.0);\n\nvec3 normalFromDepth(const float depth, const vec2 coords) {\n float depth1 = texture2D(textureSampler, coords + offset1).r;\n float depth2 = texture2D(textureSampler, coords + offset2).r;\n\n vec3 p1 = vec3(offset1, depth1 - depth);\n vec3 p2 = vec3(offset2, depth2 - depth);\n\n vec3 normal = cross(p1, p2);\n normal.z = -normal.z;\n\n return normalize(normal);\n}\n\nvoid main(void)\n{\n const float totalStrength = 1.0;\n const float base = 0.2;\n const float area = 0.0075;\n const float fallOff = 0.000001;\n const float radius = 0.0005;\n\n vec3 random = texture2D(randomSampler, vUV * randTextureTiles).rgb;\n float depth = texture2D(textureSampler, vUV).r;\n vec3 position = vec3(vUV, depth);\n vec3 normal = normalFromDepth(depth, vUV);\n float radiusDepth = radius / depth;\n float occlusion = 0.0;\n\n vec3 ray;\n vec3 hemiRay;\n float occlusionDepth;\n float difference;\n\n for (int i = 0; i < SAMPLES; i++)\n {\n ray = radiusDepth * reflect(sampleSphere[i], random);\n hemiRay = position + dot(ray, normal) * ray;\n\n occlusionDepth = texture2D(textureSampler, clamp(hemiRay.xy, 0.0, 1.0)).r;\n difference = depth - occlusionDepth;\n\n occlusion += step(fallOff, difference) * (1.0 - smoothstep(fallOff, area, difference));\n }\n\n float ao = 1.0 - totalStrength * occlusion * samplesFactor;\n\n float result = clamp(ao + base, 0.0, 1.0);\n gl_FragColor.r = result;\n gl_FragColor.g = result;\n gl_FragColor.b = result;\n gl_FragColor.a = 1.0;\n}",ssaoCombinePixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform sampler2D textureSampler;\nuniform sampler2D originalColor;\n\nvarying vec2 vUV;\n\nvoid main(void) {\n gl_FragColor = texture2D(originalColor, vUV) * texture2D(textureSampler, vUV);\n}",volumetricLightScatteringPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform sampler2D textureSampler;\nuniform sampler2D lightScatteringSampler;\n\nuniform float decay;\nuniform float exposure;\nuniform float weight;\nuniform float density;\nuniform vec2 meshPositionOnScreen;\n\nvarying vec2 vUV;\n\nvoid main(void) {\n vec2 tc = vUV;\n vec2 deltaTexCoord = (tc - meshPositionOnScreen.xy);\n deltaTexCoord *= 1.0 / float(NUM_SAMPLES) * density;\n\n float illuminationDecay = 1.0;\n\n vec4 color = texture2D(lightScatteringSampler, tc) * 0.4;\n\n for(int i=0; i < NUM_SAMPLES; i++) {\n tc -= deltaTexCoord;\n vec4 sample = texture2D(lightScatteringSampler, tc) * 0.4;\n sample *= illuminationDecay * weight;\n color += sample;\n illuminationDecay *= decay;\n }\n\n vec4 realColor = texture2D(textureSampler, vUV);\n gl_FragColor = ((vec4((vec3(color.r, color.g, color.b) * exposure), 1)) + (realColor * (1.5 - 0.4)));\n}",volumetricLightScatteringPassPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\n#if defined(ALPHATEST) || defined(BASIC_RENDER) || defined(OPACITY)\nvarying vec2 vUV;\n#endif\n\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\nuniform sampler2D diffuseSampler;\n#endif\n\n#if defined(OPACITY)\nuniform sampler2D opacitySampler;\n#endif\n\nvoid main(void)\n{\n#if defined(ALPHATEST) || defined(OPACITY) || defined(BASIC_RENDER)\n vec4 diffuseColor = texture2D(diffuseSampler, vUV);\n#endif\n\n#ifdef ALPHATEST\n if (diffuseColor.a < 0.4)\n discard;\n#endif\n\n#ifdef BASIC_RENDER\n#ifdef OPACITY\n gl_FragColor = diffuseColor * texture2D(opacitySampler, vUV);\n#else\n gl_FragColor = diffuseColor;\n#endif\n#else\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n#endif\n\n}",woodPixelShader:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nvarying vec2 vPosition;\nvarying vec2 vUV;\n\nuniform float ampScale;\nuniform vec3 woodColor;\n\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\n\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\n\nfloat fbm(vec2 n) {\n float total = 0.0, amplitude = 1.0;\n for (int i = 0; i < 4; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.5;\n }\n return total;\n}\n\nvoid main(void) {\n float ratioy = mod(vUV.x * ampScale, 2.0 + fbm(vUV * 0.8));\n vec3 wood = woodColor * ratioy;\n gl_FragColor = vec4(wood, 1.0);\n}"},b }();a.Effect=c}(BABYLON||(BABYLON={})),function(a){var b=function(){function a(b,c,d){this.name=b,this.checkReadyOnEveryCall=!0,this.checkReadyOnlyOnce=!1,this.state="",this.alpha=1,this.backFaceCulling=!0,this._wasPreviouslyReady=!1,this._fillMode=a.TriangleFillMode,this.pointSize=1,this.id=b,this._scene=c,d||c.materials.push(this)}return Object.defineProperty(a,"TriangleFillMode",{get:function(){return a._TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(a,"WireFrameFillMode",{get:function(){return a._WireFrameFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(a,"PointFillMode",{get:function(){return a._PointFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"wireframe",{get:function(){return this._fillMode===a.WireFrameFillMode},set:function(b){this._fillMode=b?a.WireFrameFillMode:a.TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"pointsCloud",{get:function(){return this._fillMode===a.PointFillMode},set:function(b){this._fillMode=b?a.PointFillMode:a.TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"fillMode",{get:function(){return this._fillMode},set:function(a){this._fillMode=a},enumerable:!0,configurable:!0}),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(){this._scene._cachedMaterial=this,this.onBind&&this.onBind(this)},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._TriangleFillMode=0,a._WireFrameFillMode=1,a._PointFillMode=2,a}();a.Material=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=4,c=function(){function b(){this.isEnabled=!0,this.leftColor=a.Color3.White(),this.rightColor=a.Color3.Black(),this.bias=0,this.power=1}return b}();a.FresnelParameters=c;var d=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.useSpecularOverAlpha=!0,this.fogEnabled=!0,this._cachedDefines=null,this._renderTargets=new a.SmartArray(16),this._worldViewProjectionMatrix=a.Matrix.Zero(),this._globalAmbientColor=new a.Color3(0,0,0),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()||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled},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,e){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var f=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===f.getRenderId())return!0;var g=f.getEngine(),h=[],i=new a.EffectFallbacks;if(f.texturesEnabled){if(this.diffuseTexture&&d.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;h.push("#define DIFFUSE")}if(this.ambientTexture&&d.AmbientTextureEnabled){if(!this.ambientTexture.isReady())return!1;h.push("#define AMBIENT")}if(this.opacityTexture&&d.OpacityTextureEnabled){if(!this.opacityTexture.isReady())return!1;h.push("#define OPACITY"),this.opacityTexture.getAlphaFromRGB&&h.push("#define OPACITYRGB")}if(this.reflectionTexture&&d.ReflectionTextureEnabled){if(!this.reflectionTexture.isReady())return!1;h.push("#define REFLECTION"),i.addFallback(0,"REFLECTION")}if(this.emissiveTexture&&d.EmissiveTextureEnabled){if(!this.emissiveTexture.isReady())return!1;h.push("#define EMISSIVE")}if(this.specularTexture&&d.SpecularTextureEnabled){if(!this.specularTexture.isReady())return!1;h.push("#define SPECULAR"),i.addFallback(0,"SPECULAR")}}if(f.getEngine().getCaps().standardDerivatives&&this.bumpTexture&&d.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;h.push("#define BUMP"),i.addFallback(0,"BUMP")}this.useSpecularOverAlpha&&(h.push("#define SPECULAROVERALPHA"),i.addFallback(0,"SPECULAROVERALPHA")),f.clipPlane&&h.push("#define CLIPPLANE"),g.getAlphaTesting()&&h.push("#define ALPHATEST"),this._shouldUseAlphaFromDiffuseTexture()&&h.push("#define ALPHAFROMDIFFUSE"),(this.pointsCloud||f.forcePointsCloud)&&h.push("#define POINTSIZE"),f.fogEnabled&&c&&c.applyFog&&f.fogMode!==a.Scene.FOGMODE_NONE&&this.fogEnabled&&(h.push("#define FOG"),i.addFallback(1,"FOG"));var j=!1,k=0;if(f.lightsEnabled)for(var l=0;l0){for(var n=0;n0){for(var p=0;p0&&i.addFallback(k,"LIGHT"+k);var r;if(r=m instanceof a.SpotLight?"#define SPOTLIGHT"+k:m instanceof a.HemisphericLight?"#define HEMILIGHT"+k:"#define POINTDIRLIGHT"+k,h.push(r),k>0&&i.addFallback(k,r.replace("#define ","")),f.shadowsEnabled){var s=m.getShadowGenerator();c&&c.receiveShadows&&s&&(h.push("#define SHADOW"+k),i.addFallback(0,"SHADOW"+k),j||(h.push("#define SHADOWS"),j=!0),s.useVarianceShadowMap&&(h.push("#define SHADOWVSM"+k),k>0&&i.addFallback(0,"SHADOWVSM"+k)),s.usePoissonSampling&&(h.push("#define SHADOWPCF"+k),k>0&&i.addFallback(0,"SHADOWPCF"+k)))}if(k++,k===b)break}}}if(d.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled||this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled||this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled)){var t=1;this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(h.push("#define DIFFUSEFRESNEL"),i.addFallback(t,"DIFFUSEFRESNEL"),t++),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&(h.push("#define OPACITYFRESNEL"),i.addFallback(t,"OPACITYFRESNEL"),t++),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(h.push("#define REFLECTIONFRESNEL"),i.addFallback(t,"REFLECTIONFRESNEL"),t++),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(h.push("#define EMISSIVEFRESNEL"),i.addFallback(t,"EMISSIVEFRESNEL"),t++),h.push("#define FRESNEL"),i.addFallback(t-1,"FRESNEL")}var u=[a.VertexBuffer.PositionKind,a.VertexBuffer.NormalKind];c&&(c.isVerticesDataPresent(a.VertexBuffer.UVKind)&&(u.push(a.VertexBuffer.UVKind),h.push("#define UV1")),c.isVerticesDataPresent(a.VertexBuffer.UV2Kind)&&(u.push(a.VertexBuffer.UV2Kind),h.push("#define UV2")),c.useVertexColors&&c.isVerticesDataPresent(a.VertexBuffer.ColorKind)&&(u.push(a.VertexBuffer.ColorKind),h.push("#define VERTEXCOLOR"),c.hasVertexAlpha&&h.push("#define VERTEXALPHA")),c.useBones&&(u.push(a.VertexBuffer.MatricesIndicesKind),u.push(a.VertexBuffer.MatricesWeightsKind),h.push("#define BONES"),h.push("#define BonesPerMesh "+(c.skeleton.bones.length+1)),h.push("#define BONES4"),i.addFallback(0,"BONES4")),e&&(h.push("#define INSTANCES"),u.push("world0"),u.push("world1"),u.push("world2"),u.push("world3")));var v=h.join("\n");if(this._cachedDefines!==v){this._cachedDefines=v,f.resetCachedMaterial();var w="default";f.getEngine().getCaps().standardDerivatives||(w="legacydefault"),this._effect=f.getEngine().createEffect(w,u,["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","pointSize","vDiffuseInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vSpecularInfos","vBumpInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix","darkness0","darkness1","darkness2","darkness3","diffuseLeftColor","diffuseRightColor","opacityParts","reflectionLeftColor","reflectionRightColor","emissiveLeftColor","emissiveRightColor"],["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],v,i,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=f.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(e,f){var g=this.getScene();if(this.bindOnlyWorldMatrix(e),this._effect.setMatrix("viewProjection",g.getTransformMatrix()),f.useBones&&this._effect.setMatrices("mBones",f.skeleton.getTransformMatrices()),g.getCachedMaterial()!==this){if(d.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._effect.setColor4("diffuseLeftColor",this.diffuseFresnelParameters.leftColor,this.diffuseFresnelParameters.power),this._effect.setColor4("diffuseRightColor",this.diffuseFresnelParameters.rightColor,this.diffuseFresnelParameters.bias)),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&this._effect.setColor4("opacityParts",new a.Color3(this.opacityFresnelParameters.leftColor.toLuminance(),this.opacityFresnelParameters.rightColor.toLuminance(),this.opacityFresnelParameters.bias),this.opacityFresnelParameters.power),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._effect.setColor4("reflectionLeftColor",this.reflectionFresnelParameters.leftColor,this.reflectionFresnelParameters.power),this._effect.setColor4("reflectionRightColor",this.reflectionFresnelParameters.rightColor,this.reflectionFresnelParameters.bias)),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._effect.setColor4("emissiveLeftColor",this.emissiveFresnelParameters.leftColor,this.emissiveFresnelParameters.power),this._effect.setColor4("emissiveRightColor",this.emissiveFresnelParameters.rightColor,this.emissiveFresnelParameters.bias))),this.diffuseTexture&&d.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.ambientTexture&&d.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&&d.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&&d.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&&d.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&&d.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&&g.getEngine().getCaps().standardDerivatives&&d.BumpTextureEnabled&&(this._effect.setTexture("bumpSampler",this.bumpTexture),this._effect.setFloat2("vBumpInfos",this.bumpTexture.coordinatesIndex,1/this.bumpTexture.level),this._effect.setMatrix("bumpMatrix",this.bumpTexture.getTextureMatrix())),g.clipPlane){var h=g.clipPlane;this._effect.setFloat4("vClipPlane",h.normal.x,h.normal.y,h.normal.z,h.d)}this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),g.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),this._scaledSpecular.r=this.specularColor.r*a.Tools.Clamp(1-this.emissiveColor.r),this._scaledSpecular.g=this.specularColor.g*a.Tools.Clamp(1-this.emissiveColor.g),this._scaledSpecular.b=this.specularColor.b*a.Tools.Clamp(1-this.emissiveColor.b),this._effect.setVector3("vEyePosition",g.activeCamera.position),this._effect.setColor3("vAmbientColor",this._globalAmbientColor),this._effect.setColor4("vSpecularColor",this._scaledSpecular,this.specularPower),this._effect.setColor3("vEmissiveColor",this.emissiveColor)}if(this._scaledDiffuse.r=this.diffuseColor.r*a.Tools.Clamp(1-this.emissiveColor.r),this._scaledDiffuse.g=this.diffuseColor.g*a.Tools.Clamp(1-this.emissiveColor.g),this._scaledDiffuse.b=this.diffuseColor.b*a.Tools.Clamp(1-this.emissiveColor.b),this._effect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*f.visibility),g.lightsEnabled)for(var i=0,j=0;j0&&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(a){var b=new d(a,this.getScene());return b.checkReadyOnEveryCall=this.checkReadyOnEveryCall,b.alpha=this.alpha,b.fillMode=this.fillMode,b.backFaceCulling=this.backFaceCulling,this.diffuseTexture&&this.diffuseTexture.clone&&(b.diffuseTexture=this.diffuseTexture.clone()),this.ambientTexture&&this.ambientTexture.clone&&(b.ambientTexture=this.ambientTexture.clone()),this.opacityTexture&&this.opacityTexture.clone&&(b.opacityTexture=this.opacityTexture.clone()),this.reflectionTexture&&this.reflectionTexture.clone&&(b.reflectionTexture=this.reflectionTexture.clone()),this.emissiveTexture&&this.emissiveTexture.clone&&(b.emissiveTexture=this.emissiveTexture.clone()),this.specularTexture&&this.specularTexture.clone&&(b.specularTexture=this.specularTexture.clone()),this.bumpTexture&&this.bumpTexture.clone&&(b.bumpTexture=this.bumpTexture.clone()),b.ambientColor=this.ambientColor.clone(),b.diffuseColor=this.diffuseColor.clone(),b.specularColor=this.specularColor.clone(),b.specularPower=this.specularPower,b.emissiveColor=this.emissiveColor.clone(),b},d.DiffuseTextureEnabled=!0,d.AmbientTextureEnabled=!0,d.OpacityTextureEnabled=!0,d.ReflectionTextureEnabled=!0,d.EmissiveTextureEnabled=!0,d.SpecularTextureEnabled=!0,d.BumpTextureEnabled=!0,d.FresnelEnabled=!0,d}(a.Material);a.StandardMaterial=d}(BABYLON||(BABYLON={}));var 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;bf.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(0,a.lastIndexOf("#")),d=a.substring(c.lastIndexOf("/")+1,a.length),e=a.substring(0,a.indexOf(d,0));return e},b.ReturnFullUrlLocation=function(b){return-1===b.indexOf("http:/")?a.Database.parseURL(window.location.href)+b:b},b}();a.Database=b}(BABYLON||(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.fogEnabled=!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=b.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);var j=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==a.Scene.FOGMODE_NONE&&this.fogEnabled&&(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.fogEnabled&&this._scene.fogMode!==a.Scene.FOGMODE_NONE&&this.fogEnabled&&(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={})),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;ak;k++)i.push(j),i.push(j+1),i.push(j+2),i.push(j),i.push(j+2),i.push(j+3),j+=4;this._indexBuffer=f.getEngine().createIndexBuffer(i),this._vertices=new Float32Array(e*this._vertexStrideSize),this.startDirectionFunction=function(c,d,e){var f=b(h.direction1.x,h.direction2.x),g=b(h.direction1.y,h.direction2.y),i=b(h.direction1.z,h.direction2.z);a.Vector3.TransformNormalFromFloatsToRef(f*c,g*c,i*c,d,e)},this.startPositionFunction=function(c,d){var e=b(h.minEmitBox.x,h.maxEmitBox.x),f=b(h.minEmitBox.y,h.maxEmitBox.y),g=b(h.minEmitBox.z,h.maxEmitBox.z);a.Vector3.TransformCoordinatesFromFloatsToRef(e,f,g,c,d)},this.updateFunction=function(a){for(var b=0;b=c.lifeTime?(h.recycleParticle(c),b--):(c.colorStep.scaleToRef(h._scaledUpdateSpeed,h._scaledColorStep),c.color.addInPlace(h._scaledColorStep),c.color.a<0&&(c.color.a=0),c.angle+=c.angularSpeed*h._scaledUpdateSpeed,c.direction.scaleToRef(h._scaledUpdateSpeed,h._scaledDirection),c.position.addInPlace(h._scaledDirection),h.gravity.scaleToRef(h._scaledUpdateSpeed,h._scaledGravity),c.direction.addInPlace(h._scaledGravity))}}}return c.prototype.recycleParticle=function(a){var b=this.particles.pop();b!==a&&(b.copyTo(a),this._stockParticles.push(b))},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,this.updateFunction(this.particles);var d;d=this.emitter.position?this.emitter.getWorldMatrix():a.Matrix.Translation(this.emitter.x,this.emitter.y,this.emitter.z);for(var e=0;c>e&&this.particles.length!==this._capacity;e++){if(0!==this._stockParticles.length){var f=this._stockParticles.pop();f.age=0}else f=new a.Particle;this.particles.push(f);var g=b(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(g,d,f.direction),f.lifeTime=b(this.minLifeTime,this.maxLifeTime),f.size=b(this.minSize,this.maxSize),f.angularSpeed=b(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(d,f.position);var h=b(0,1);a.Color4.LerpToRef(this.color1,this.color2,h,f.color),this.colorDead.subtractToRef(f.color,this._colorDiff),this._colorDiff.scaleToRef(1/f.lifeTime,f.colorStep)}},c.prototype._getEffect=function(){if(this._customEffect)return this._customEffect;var a=[];this._scene.clipPlane&&a.push("#define CLIPPLANE");var b=a.join("\n");return this._cachedDefines!==b&&(this._cachedDefines=b,this._effect=this._scene.getEngine().createEffect("particles",["position","color","options"],["invView","view","projection","vClipPlane","textureMask"],["diffuseSampler"],b)),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._getKeyValue(this._keys[g].value),i=this._getKeyValue(this._keys[g+1].value),j=(a-this._keys[g].frame)/(this._keys[g+1].frame-this._keys[g].frame);switch(null!=this._easingFunction&&(j=this._easingFunction.ease(j)),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_VECTOR2:switch(d){case b.ANIMATIONLOOPMODE_CYCLE:case b.ANIMATIONLOOPMODE_CONSTANT:return this.vector2InterpolateFunction(h,i,j);case b.ANIMATIONLOOPMODE_RELATIVE:return this.vector2InterpolateFunction(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._getKeyValue(this._keys[this._keys.length-1].value)},b.prototype.animate=function(c,d,e,f,g){if(!this.targetPropertyPath||this.targetPropertyPath.length<1)return this._stopped=!0,!1;var h=!0;if(0!==this._keys[0].frame){var i={frame:0,value:this._keys[0].value};this._keys.splice(0,0,i)}(dthis._keys[this._keys.length-1].frame)&&(d=this._keys[0].frame),(ethis._keys[this._keys.length-1].frame)&&(e=this._keys[this._keys.length-1].frame);var j,k=e-d,l=c*this.framePerSecond*g/1e3,m=0;if(l>k&&!f)h=!1,m=this._getKeyValue(this._keys[this._keys.length-1].value);else if(this.loopMode!==b.ANIMATIONLOOPMODE_CYCLE){var n=e.toString()+d.toString();if(!this._offsetsCache[n]){var o=this._interpolate(d,0,b.ANIMATIONLOOPMODE_CYCLE),p=this._interpolate(e,0,b.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case b.ANIMATIONTYPE_FLOAT:this._offsetsCache[n]=p-o;break;case b.ANIMATIONTYPE_QUATERNION:this._offsetsCache[n]=p.subtract(o);break;case b.ANIMATIONTYPE_VECTOR3:this._offsetsCache[n]=p.subtract(o);case b.ANIMATIONTYPE_VECTOR2:this._offsetsCache[n]=p.subtract(o);case b.ANIMATIONTYPE_COLOR3:this._offsetsCache[n]=p.subtract(o)}this._highLimitsCache[n]=p}m=this._highLimitsCache[n],j=this._offsetsCache[n]}if(void 0===j)switch(this.dataType){case b.ANIMATIONTYPE_FLOAT:j=0;break;case b.ANIMATIONTYPE_QUATERNION:j=new a.Quaternion(0,0,0,0);break;case b.ANIMATIONTYPE_VECTOR3:j=a.Vector3.Zero();break;case b.ANIMATIONTYPE_VECTOR2:j=a.Vector2.Zero();break;case b.ANIMATIONTYPE_COLOR3:j=a.Color3.Black()}var q=l/k>>0,r=h?d+l%k:e,s=this._interpolate(r,q,this.loopMode,j,m);if(this.targetPropertyPath.length>1){for(var t=this._target[this.targetPropertyPath[0]],u=1;u-1&&this._scene._activeAnimatables.splice(a,1),this.onAnimationEnd&&this.onAnimationEnd()},a.prototype._animate=function(a){if(this._paused)return this._pausedDelay||(this._pausedDelay=a),!0;this._localDelayOffset?this._pausedDelay&&(this._localDelayOffset+=a-this._pausedDelay,this._pausedDelay=null):this._localDelayOffset=a;for(var b=!1,c=this._animations,d=0;d=.5?.5*(1-this.easeInCore(2*(1-b)))+.5:.5*this.easeInCore(2*b)},a._EASINGMODE_EASEIN=0,a._EASINGMODE_EASEOUT=1,a._EASINGMODE_EASEINOUT=2,a}();a.EasingFunction=b;var c=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.easeInCore=function(a){return a=Math.max(0,Math.min(1,a)),1-Math.sqrt(1-a*a)},b}(b);a.CircleEase=c;var d=function(a){function b(b){void 0===b&&(b=1),a.call(this),this.amplitude=b}return __extends(b,a),b.prototype.easeInCore=function(a){var b=Math.max(0,this.amplitude);return Math.pow(a,3)-a*b*Math.sin(3.141592653589793*a)},b}(b);a.BackEase=d;var e=function(a){function b(b,c){void 0===b&&(b=3),void 0===c&&(c=2),a.call(this),this.bounces=b,this.bounciness=c}return __extends(b,a),b.prototype.easeInCore=function(a){var b=Math.max(0,this.bounces),c=this.bounciness;1>=c&&(c=1.001);var d=Math.pow(c,b),e=1-c,f=(1-d)/e+.5*d,g=a*f,h=Math.log(-g*(1-c)+1)/Math.log(c),i=Math.floor(h),j=i+1,k=(1-Math.pow(c,i))/(e*f),l=(1-Math.pow(c,j))/(e*f),m=.5*(k+l),n=a-m,o=m-k;return-Math.pow(1/c,b-i)/(o*o)*(n-o)*(n+o)},b}(b);a.BounceEase=e;var f=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.easeInCore=function(a){return a*a*a},b}(b);a.CubicEase=f;var g=function(a){function b(b,c){void 0===b&&(b=3),void 0===c&&(c=3),a.call(this),this.oscillations=b,this.springiness=c}return __extends(b,a),b.prototype.easeInCore=function(a){var b,c=Math.max(0,this.oscillations),d=Math.max(0,this.springiness);return b=0==d?a:(Math.exp(d*a)-1)/(Math.exp(d)-1),b*Math.sin((6.283185307179586*c+1.5707963267948966)*a)},b}(b);a.ElasticEase=g;var h=function(a){function b(b){void 0===b&&(b=2),a.call(this),this.exponent=b}return __extends(b,a),b.prototype.easeInCore=function(a){return this.exponent<=0?a:(Math.exp(this.exponent*a)-1)/(Math.exp(this.exponent)-1)},b}(b);a.ExponentialEase=h;var i=function(a){function b(b){void 0===b&&(b=2),a.call(this),this.power=b}return __extends(b,a),b.prototype.easeInCore=function(a){var b=Math.max(0,this.power);return Math.pow(a,b)},b}(b);a.PowerEase=i;var j=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.easeInCore=function(a){return a*a},b}(b);a.QuadraticEase=j;var k=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.easeInCore=function(a){return a*a*a*a},b}(b);a.QuarticEase=k;var l=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.easeInCore=function(a){return a*a*a*a*a},b}(b);a.QuinticEase=l;var m=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.easeInCore=function(a){return 1-Math.sin(1.5707963267948966*(1-a))},b}(b);a.SineEase=m;var n=function(b){function c(a,c,d,e){void 0===a&&(a=0),void 0===c&&(c=0),void 0===d&&(d=1),void 0===e&&(e=1),b.call(this),this.x1=a,this.y1=c,this.x2=d,this.y2=e}return __extends(c,b),c.prototype.easeInCore=function(b){return a.BezierCurve.interpolate(b,this.x1,this.y1,this.x2,this.y2)},c}(b);a.BezierCurveEase=n}(BABYLON||(BABYLON={})),function(a){var b=function(){function b(b,c,d){void 0===d&&(d=2),this.maxDepth=d,this.dynamicContent=new Array,this._maxBlockCapacity=c||64,this._selectionContent=new a.SmartArray(1024),this._creationFunc=b}return b.prototype.update=function(a,c,d){b._CreateBlocks(a,c,d,this._maxBlockCapacity,0,this.maxDepth,this,this._creationFunc)},b.prototype.addMesh=function(a){for(var b=0;bk;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.isBlocked&&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={})),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 h=0;h0){for(var b=0;b0&&(this._camera._postProcesses[a._postProcessesTakenIndices[0]].width=-1)},b}();a.PostProcess=b}(BABYLON||(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.MeshImpostor=4,b.CapsuleImpostor=5,b.ConeImpostor=6,b.CylinderImpostor=7,b.ConvexHullImpostor=8,b.Epsilon=.001,b}();a.PhysicsEngine=b}(BABYLON||(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(a){var b={};return b.isEnabled=a.isEnabled,b.leftColor=a.leftColor,b.rightColor=a.rightColor,b.bias=a.bias,b.power=a.power,b},d=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()),e(b,c),c.layerMask=b.layerMask,c},e=function(a,b){if(a.animations){b.animations=[];for(var c=0;c0&&(e.animation=f(d.animations[0]))}return b},k=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},l=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(m(f.animation))}return d},f=function(b){var c=new a.FresnelParameters;return c.isEnabled=b.isEnabled,c.leftColor=a.Color3.FromArray(b.leftColor),c.rightColor=a.Color3.FromArray(b.rightColor),c.bias=b.bias,c.power=b.power||1,c},g=function(b,c,e){var g;return g=new a.StandardMaterial(b.name,c),g.ambientColor=a.Color3.FromArray(b.ambient),g.diffuseColor=a.Color3.FromArray(b.diffuse),g.specularColor=a.Color3.FromArray(b.specular),g.specularPower=b.specularPower,g.emissiveColor=a.Color3.FromArray(b.emissive),g.alpha=b.alpha,g.id=b.id,a.Tags.AddTagsTo(g,b.tags),g.backFaceCulling=b.backFaceCulling,g.wireframe=b.wireframe,b.diffuseTexture&&(g.diffuseTexture=d(e,b.diffuseTexture,c)),b.diffuseFresnelParameters&&(g.diffuseFresnelParameters=f(b.diffuseFresnelParameters)),b.ambientTexture&&(g.ambientTexture=d(e,b.ambientTexture,c)),b.opacityTexture&&(g.opacityTexture=d(e,b.opacityTexture,c)),b.opacityFresnelParameters&&(g.opacityFresnelParameters=f(b.opacityFresnelParameters)),b.reflectionTexture&&(g.reflectionTexture=d(e,b.reflectionTexture,c)),b.reflectionFresnelParameters&&(g.reflectionFresnelParameters=f(b.reflectionFresnelParameters)),b.emissiveTexture&&(g.emissiveTexture=d(e,b.emissiveTexture,c)),b.emissiveFresnelParameters&&(g.emissiveFresnelParameters=f(b.emissiveFresnelParameters)),b.specularTexture&&(g.specularTexture=d(e,b.specularTexture,c)),b.bumpTexture&&(g.bumpTexture=d(e,b.bumpTexture,c)),g},h=function(a,b,c,d){for(var e=0;e-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;f0?{trigger:a.ActionManager[k.name],parameter:d.getMeshByName(k.properties[0].value)}:a.ActionManager[k.name];for(var l=0;l0){var i=new Float32Array(c,h.positionsAttrDesc.offset,h.positionsAttrDesc.count);d.setVerticesData(a.VertexBuffer.PositionKind,i,!1)}if(h.normalsAttrDesc&&h.normalsAttrDesc.count>0){var j=new Float32Array(c,h.normalsAttrDesc.offset,h.normalsAttrDesc.count);d.setVerticesData(a.VertexBuffer.NormalKind,j,!1)}if(h.uvsAttrDesc&&h.uvsAttrDesc.count>0){var k=new Float32Array(c,h.uvsAttrDesc.offset,h.uvsAttrDesc.count);d.setVerticesData(a.VertexBuffer.UVKind,k,!1)}if(h.uvs2AttrDesc&&h.uvs2AttrDesc.count>0){var l=new Float32Array(c,h.uvs2AttrDesc.offset,h.uvs2AttrDesc.count);d.setVerticesData(a.VertexBuffer.UV2Kind,l,!1)}if(h.colorsAttrDesc&&h.colorsAttrDesc.count>0){var m=new Float32Array(c,h.colorsAttrDesc.offset,h.colorsAttrDesc.count);d.setVerticesData(a.VertexBuffer.ColorKind,m,!1)}if(h.matricesIndicesAttrDesc&&h.matricesIndicesAttrDesc.count>0){var n=new Int32Array(c,h.matricesIndicesAttrDesc.offset,h.matricesIndicesAttrDesc.count);d.setVerticesData(a.VertexBuffer.MatricesIndicesKind,n,!1)}if(h.matricesWeightsAttrDesc&&h.matricesWeightsAttrDesc.count>0){var o=new Float32Array(c,h.matricesWeightsAttrDesc.offset,h.matricesWeightsAttrDesc.count);d.setVerticesData(a.VertexBuffer.MatricesWeightsKind,o,!1)}if(h.indicesAttrDesc&&h.indicesAttrDesc.count>0){var p=new Int32Array(c,h.indicesAttrDesc.offset,h.indicesAttrDesc.count);d.setIndices(p)}if(h.subMeshesAttrDesc&&h.subMeshesAttrDesc.count>0){var q=new Int32Array(c,h.subMeshesAttrDesc.offset,5*h.subMeshesAttrDesc.count);d.subMeshes=[];for(var r=0;r>8),x.push((16711680&y)>>16),x.push(y>>24)}d.setVerticesData(a.VertexBuffer.MatricesIndicesKind,x,!1)}if(c.matricesWeights&&d.setVerticesData(a.VertexBuffer.MatricesWeightsKind,c.matricesWeights,!1),d.setIndices(c.indices),c.subMeshes){d.subMeshes=[];for(var z=0;z-1&&b.skeletons){var w=m.indexOf(q.skeletonId)>-1;if(!w)for(var x=0;xb.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++){var B=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]);var C=new a.Vector3(s[3*r[y+A]],s[3*r[y+A]+1],s[3*r[y+A]+2]);j=a.Vector3.TransformCoordinates(C,n),h=a.Vector3.TransformNormal(B,n),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 D=d.FromPolygons(m);return D.matrix=n,D.position=o,D.rotation=p,D.scaling=q,b++,D},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);var A=a.Vector3.TransformCoordinates(n,e),B=a.Vector3.TransformNormal(o,e);g=s[A.x+","+A.y+","+A.z],("undefined"==typeof g||l[3*g]!==B.x||l[3*g+1]!==B.y||l[3*g+2]!==B.z||m[2*g]!==p.x||m[2*g+1]!==p.y)&&(j.push(A.x,A.y,A.z),m.push(p.x,p.y),l.push(o.x,o.y,o.z),g=s[A.x+","+A.y+","+A.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 C,D=0;i.subMeshes.length=0;for(var E in u){C=-1;for(var F in u[E])h=u[E][F],a.SubMesh.CreateFromIndices(h.materialIndex+D,h.indexStart,h.indexEnd-h.indexStart+1,i),C=Math.max(h.materialIndex,C);D+=++C}}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 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){var b;!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}(b=a.VirtualJoystick||(a.VirtualJoystick={}))}(BABYLON||(BABYLON={}));var 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 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(b){function d(d,e,f){var g=this;b.call(this,d,e,f),this.angularSensibility=200,this.moveSensibility=75,this._leftCamera=new c(d+"_left",e.clone(),f,!0),this._rightCamera=new c(d+"_right",e.clone(),f,!1),this.subCameras.push(this._leftCamera),this.subCameras.push(this._rightCamera),this._deviceOrientationHandler=this._onOrientationEvent.bind(this),this._gamepads=new a.Gamepads(function(a){g._onNewGameConnected(a)})}return __extends(d,b),d.prototype._onNewGameConnected=function(a){0===a.index&&(this._gamepad=a)},d.prototype._update=function(){this._leftCamera.position.copyFrom(this.position),this._rightCamera.position.copyFrom(this.position),this._updateCamera(this._leftCamera),this._updateCamera(this._rightCamera),b.prototype._update.call(this)},d.prototype._checkInputs=function(){if(this._gamepad){var b=this._gamepad.leftStick,c=b.x/this.moveSensibility,d=b.y/this.moveSensibility;b.x=Math.abs(c)>.005?0+c:0,b.y=Math.abs(d)>.005?0+d:0;var e=a.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),f=a.Vector3.TransformCoordinates(new a.Vector3(b.x,0,-b.y),e);this.cameraDirection=this.cameraDirection.add(f)}},d.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},d.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})},d.prototype.attachControl=function(a,c){b.prototype.attachControl.call(this,a,c),window.addEventListener("deviceorientation",this._deviceOrientationHandler)},d.prototype.detachControl=function(a){b.prototype.detachControl.call(this,a),window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},d.prototype.dispose=function(){this._gamepads.dispose(),b.prototype.dispose.call(this)},d}(a.FreeCamera);a.OculusGamepadCamera=d}(BABYLON||(BABYLON={}));var 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.addVector3(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(),b.prototype.dispose.call(this)},c}(a.FreeCamera);a.VirtualJoysticksCamera=b}(BABYLON||(BABYLON={}));var 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(),b=a.getEngine();if(!this.checkReadyOnEveryCall&&this._renderId===a.getRenderId())return!0;var c=this._effect;return this._effect=b.createEffect(this._shaderPath,this._options.attributes,this._options.uniforms,this._options.samplers,"",null,this.onCompiled,this.onError),this._effect.isReady()?(c!==this._effect&&a.resetCachedMaterial(),this._renderId=a.getRenderId(),!0):!1},c.prototype.bindOnlyWorldMatrix=function(a){var b=this.getScene();-1!==this._options.uniforms.indexOf("world")&&this._effect.setMatrix("world",a),-1!==this._options.uniforms.indexOf("worldView")&&(a.multiplyToRef(b.getViewMatrix(),this._cachedWorldViewMatrix),this._effect.setMatrix("worldView",this._cachedWorldViewMatrix)),-1!==this._options.uniforms.indexOf("worldViewProjection")&&this._effect.setMatrix("worldViewProjection",a.multiply(b.getTransformMatrix()))},c.prototype.bind=function(a){if(this.bindOnlyWorldMatrix(a),this.getScene().getCachedMaterial()!==this){-1!==this._options.uniforms.indexOf("view")&&this._effect.setMatrix("view",this.getScene().getViewMatrix()),-1!==this._options.uniforms.indexOf("projection")&&this._effect.setMatrix("projection",this.getScene().getProjectionMatrix()),-1!==this._options.uniforms.indexOf("viewProjection")&&this._effect.setMatrix("viewProjection",this.getScene().getTransformMatrix());for(var c in this._textures)this._effect.setTexture(c,this._textures[c]);for(c in this._floats)this._effect.setFloat(c,this._floats[c]);for(c in this._floatsArrays)this._effect.setArray(c,this._floatsArrays[c]);for(c in this._colors3)this._effect.setColor3(c,this._colors3[c]);for(c in this._colors4){var d=this._colors4[c];this._effect.setFloat4(c,d.r,d.g,d.b,d.a)}for(c in this._vectors2)this._effect.setVector2(c,this._vectors2[c]);for(c in this._vectors3)this._effect.setVector3(c,this._vectors3[c]);for(c in this._matrices)this._effect.setMatrix(c,this._matrices[c])}b.prototype.bind.call(this,a,null)},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={})),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){void 0===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&&n>r;)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}(b=a.Internals||(a.Internals={}))}(BABYLON||(BABYLON={})),function(a){var b;!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}(b=a.Internals||(a.Internals={}))}(BABYLON||(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={})),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.updateVerticesDataDirectly=function(a,b,c){var d=this.getVertexBuffer(a);d&&d.updateDirectly(b,c)},b.prototype.updateVerticesData=function(b,c,d){var e=this.getVertexBuffer(b);if(e&&(e.update(c),b===a.VertexBuffer.PositionKind)){var f,g=e.getStrideSize();this._totalVertices=c.length/g,d&&(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,b){this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indices=a,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),void 0!==b&&(this._totalVertices=b);for(var c=this._meshes,d=c.length,e=0;d>e;e++)c[e]._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(),b._updateBoundingInfo()}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(){var b,c=this._meshes,d=c.length;for(b=0;d>b;b++)this.releaseForMesh(c[b]);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();b=f.indexOf(this),b>-1&&f.splice(b,1)},b.prototype.copy=function(c){var d=new a.VertexData;d.indices=[];for(var e=this.getIndices(),f=0;fto 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=50*this._computeLocalCameraSpeed(),j=a.Vector3.TransformCoordinates(new a.Vector3(b.x*i,0,-b.y*i),h);this.cameraDirection=this.cameraDirection.add(j),this.cameraRotation=this.cameraRotation.add(new a.Vector2(e.y,e.x))}},c.prototype.dispose=function(){this._gamepads.dispose(),b.prototype.dispose.call(this)},c}(a.FreeCamera);a.GamepadCamera=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b){function c(c,d,e){void 0===e&&(e=!1),b.call(this,c,d),this.color=new a.Color3(1,1,1),this.alpha=1,this._indices=new Array,this._colorShader=new a.ShaderMaterial("colorShader",d,"color",{attributes:["position"],uniforms:["worldViewProjection","color"],needAlphaBlending:!0})}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.setColor4("color",this.color.toColor4(this.alpha))},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={})),function(a){var b=function(){function b(a){this._scene=a}return b.prototype.render=function(b,c,d){var e=this;void 0===d&&(d=!1);var f=this._scene,g=this._scene.getEngine(),h=null!==g.getCaps().instancedArrays&&null!==c.visibleInstances[b._id]&&void 0!==c.visibleInstances[b._id];if(this.isReady(b,h)){var i=b.getRenderingMesh(),j=b.getMaterial();if(g.enableEffect(this._effect),this._effect.setFloat("offset",d?0:i.outlineWidth),this._effect.setColor4("color",d?i.overlayColor:i.outlineColor,d?i.overlayAlpha:1),this._effect.setMatrix("viewProjection",f.getTransformMatrix()),i.useBones&&this._effect.setMatrices("mBones",i.skeleton.getTransformMatrices()),i._bind(b,this._effect,a.Material.TriangleFillMode),j&&j.needAlphaTesting()){var k=j.getAlphaTestTexture();this._effect.setTexture("diffuseSampler",k),this._effect.setMatrix("diffuseMatrix",k.getTextureMatrix())}i._processRendering(b,this._effect,a.Material.TriangleFillMode,c,h,function(a,b){e._effect.setMatrix("world",b)})}},b.prototype.isReady=function(b,c){var d=[],e=[a.VertexBuffer.PositionKind,a.VertexBuffer.NormalKind],f=b.getMesh(),g=b.getMaterial();g&&g.needAlphaTesting()&&(d.push("#define ALPHATEST"),f.isVerticesDataPresent(a.VertexBuffer.UVKind)&&(e.push(a.VertexBuffer.UVKind),d.push("#define UV1")),f.isVerticesDataPresent(a.VertexBuffer.UV2Kind)&&(e.push(a.VertexBuffer.UV2Kind),d.push("#define UV2"))),f.useBones&&(e.push(a.VertexBuffer.MatricesIndicesKind),e.push(a.VertexBuffer.MatricesWeightsKind),d.push("#define BONES"),d.push("#define BonesPerMesh "+(f.skeleton.bones.length+1))),c&&(d.push("#define INSTANCES"),e.push("world0"),e.push("world1"),e.push("world2"),e.push("world3"));var h=d.join("\n");return this._cachedDefines!==h&&(this._cachedDefines=h,this._effect=this._scene.getEngine().createEffect("outline",e,["world","mBones","viewProjection","diffuseMatrix","offset","color"],["diffuseSampler"],h)),this._effect.isReady()},b}();a.OutlineRenderer=b}(BABYLON||(BABYLON={})),function(a){var b=function(){function b(a,b,c,d){this.name=a,this.meshesNames=b,this.rootUrl=c,this.sceneFilename=d,this.isCompleted=!1}return b.prototype.run=function(b,c,d){var e=this;a.SceneLoader.ImportMesh(this.meshesNames,this.rootUrl,this.sceneFilename,b,function(a,b,d){e.loadedMeshes=a,e.loadedParticleSystems=b,e.loadedSkeletons=d,e.isCompleted=!0,e.onSuccess&&e.onSuccess(e),c()},null,function(){e.onError&&e.onError(e),d()})},b}();a.MeshAssetTask=b;var c=function(){function b(a,b){this.name=a,this.url=b,this.isCompleted=!1}return b.prototype.run=function(b,c,d){var e=this;a.Tools.LoadFile(this.url,function(a){e.text=a,e.isCompleted=!0,e.onSuccess&&e.onSuccess(e),c()},null,b.database,!1,function(){e.onError&&e.onError(e),d()})},b}();a.TextFileAssetTask=c;var d=function(){function b(a,b){this.name=a,this.url=b,this.isCompleted=!1}return b.prototype.run=function(b,c,d){var e=this;a.Tools.LoadFile(this.url,function(a){e.data=a,e.isCompleted=!0,e.onSuccess&&e.onSuccess(e),c()},null,b.database,!0,function(){e.onError&&e.onError(e),d()})},b}();a.BinaryFileAssetTask=d;var e=function(){function a(a,b){this.name=a,this.url=b,this.isCompleted=!1}return a.prototype.run=function(a,b,c){var d=this,e=new Image;e.onload=function(){d.image=e,d.isCompleted=!0,d.onSuccess&&d.onSuccess(d),b()},e.onerror=function(){d.onError&&d.onError(d),c()},e.src=this.url},a}();a.ImageAssetTask=e;var f=function(){function b(b,c,d,e,f){void 0===f&&(f=a.Texture.TRILINEAR_SAMPLINGMODE),this.name=b,this.url=c,this.noMipmap=d,this.invertY=e,this.samplingMode=f,this.isCompleted=!1}return b.prototype.run=function(b,c,d){var e=this,f=function(){e.isCompleted=!0,e.onSuccess&&e.onSuccess(e),c()};this.texture=new a.Texture(this.url,b,this.noMipmap,this.invertY,this.samplingMode,f,d)},b}();a.TextureAssetTask=f;var g=function(){function g(a){this._tasks=new Array,this._waitingTasksCount=0,this.useDefaultLoadingScreen=!0,this._scene=a}return g.prototype.addMeshTask=function(a,c,d,e){var f=new b(a,c,d,e);return this._tasks.push(f),f},g.prototype.addTextFileTask=function(a,b){var d=new c(a,b);return this._tasks.push(d),d},g.prototype.addBinaryFileTask=function(a,b){var c=new d(a,b);return this._tasks.push(c),c},g.prototype.addImageTask=function(a,b){var c=new e(a,b);return this._tasks.push(c),c},g.prototype.addTextureTask=function(b,c,d,e,g){void 0===g&&(g=a.Texture.TRILINEAR_SAMPLINGMODE);var h=new f(b,c,d,e,g);return this._tasks.push(h),h},g.prototype._decreaseWaitingTasksCount=function(){this._waitingTasksCount--,0===this._waitingTasksCount&&(this.onFinish&&this.onFinish(this._tasks),this._scene.getEngine().hideLoadingUI())},g.prototype._runTask=function(a){var b=this;a.run(this._scene,function(){b.onTaskSuccess&&b.onTaskSuccess(a),b._decreaseWaitingTasksCount()},function(){b.onTaskError&&b.onTaskError(a),b._decreaseWaitingTasksCount()})},g.prototype.reset=function(){return this._tasks=new Array,this},g.prototype.load=function(){if(this._waitingTasksCount=this._tasks.length,0===this._waitingTasksCount)return this.onFinish&&this.onFinish(this._tasks),this;this.useDefaultLoadingScreen&&this._scene.getEngine().displayLoadingUI();for(var a=0;ac&&null===this._hmdDevice;)a[c]instanceof HMDVRDevice&&(this._hmdDevice=a[c]),c++;for(c=0;b>c&&null===this._sensorDevice;)a[c]instanceof PositionSensorVRDevice&&(!this._hmdDevice||a[c].hardwareUnitId===this._hmdDevice.hardwareUnitId)&&(this._sensorDevice=a[c]),c++;this._vrEnabled=this._sensorDevice&&this._hmdDevice?!0:!1},c.prototype._update=function(){this._vrEnabled&&(this._cacheState=this._sensorDevice.getState(),this._cacheQuaternion.copyFromFloats(this._cacheState.orientation.x,this._cacheState.orientation.y,this._cacheState.orientation.z,this._cacheState.orientation.w),this._cacheQuaternion.toEulerAnglesToRef(this._cacheRotation),this.rotation.x=-this._cacheRotation.z,this.rotation.y=-this._cacheRotation.y,this.rotation.z=this._cacheRotation.x),b.prototype._update.call(this)},c.prototype.attachControl=function(a,c){b.prototype.attachControl.call(this,a,c),navigator.getVRDevices?navigator.getVRDevices().then(this._getWebVRDevices):navigator.mozGetVRDevices&&navigator.mozGetVRDevices(this._getWebVRDevices)},c.prototype.detachControl=function(a){b.prototype.detachControl.call(this,a),this._vrEnabled=!1},c}(a.OculusCamera);a.WebVRCamera=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(){function a(a){void 0===a&&(a=0),this.priority=a,this.apply=function(){return!0}}return a}();a.SceneOptimization=b;var c=function(a){function b(b,c){var d=this;void 0===b&&(b=0),void 0===c&&(c=1024),a.call(this,b),this.priority=b,this.maximumSize=c,this.apply=function(a){for(var b=!0,c=0;cd.maximumSize&&(e.scale(.5),b=!1)}}return b}}return __extends(b,a),b}(b);a.TextureOptimization=c;var d=function(a){function b(b,c){var d=this;void 0===b&&(b=0),void 0===c&&(c=2),a.call(this,b),this.priority=b,this.maximumScale=c,this._currentScale=1,this.apply=function(a){return d._currentScale++,a.getEngine().setHardwareScalingLevel(d._currentScale),d._currentScale>=d.maximumScale}}return __extends(b,a),b}(b);a.HardwareScalingOptimization=d;var e=function(a){function b(){a.apply(this,arguments),this.apply=function(a){return a.shadowsEnabled=!1,!0}}return __extends(b,a),b}(b);a.ShadowsOptimization=e;var f=function(a){function b(){a.apply(this,arguments),this.apply=function(a){return a.postProcessesEnabled=!1,!0}}return __extends(b,a),b}(b);a.PostProcessesOptimization=f;var g=function(a){function b(){a.apply(this,arguments),this.apply=function(a){return a.lensFlaresEnabled=!1,!0}}return __extends(b,a),b}(b);a.LensFlaresOptimization=g;var h=function(a){function b(){a.apply(this,arguments),this.apply=function(a){return a.particlesEnabled=!1,!0}}return __extends(b,a),b}(b);a.ParticlesOptimization=h;var i=function(a){function b(){a.apply(this,arguments),this.apply=function(a){return a.renderTargetsEnabled=!1,!0}}return __extends(b,a),b}(b);a.RenderTargetsOptimization=i;var j=function(b){function c(){var c=this;b.apply(this,arguments),this._canBeMerged=function(b){if(!(b instanceof a.Mesh))return!1;var c=b;return c.isVisible&&c.isEnabled()?c.instances.length>0?!1:c.skeleton||c.hasLODLevels?!1:!0:!1},this.apply=function(b){for(var d=b.meshes.slice(0),e=d.length,f=0;e>f;f++){var g=new Array,h=d[f];if(c._canBeMerged(h)){g.push(h);for(var i=f+1;e>i;i++){var j=d[i];c._canBeMerged(j)&&j.material===h.material&&j.checkCollisions===h.checkCollisions&&(g.push(j),e--,d.splice(i,1),i--)}g.length<2||a.Mesh.MergeMeshes(g)}}return!0}}return __extends(c,b),c}(b);a.MergeMeshesOptimization=j;var k=function(){function a(a,b){void 0===a&&(a=60),void 0===b&&(b=2e3),this.targetFrameRate=a,this.trackerDuration=b,this.optimizations=new Array}return a.LowDegradationAllowed=function(b){var d=new a(b),i=0;return d.optimizations.push(new j(i)),d.optimizations.push(new e(i)),d.optimizations.push(new g(i)),i++,d.optimizations.push(new f(i)),d.optimizations.push(new h(i)),i++,d.optimizations.push(new c(i,1024)),d},a.ModerateDegradationAllowed=function(b){var k=new a(b),l=0;return k.optimizations.push(new j(l)),k.optimizations.push(new e(l)),k.optimizations.push(new g(l)),l++,k.optimizations.push(new f(l)),k.optimizations.push(new h(l)),l++,k.optimizations.push(new c(l,512)),l++,k.optimizations.push(new i(l)),l++,k.optimizations.push(new d(l,2)),k},a.HighDegradationAllowed=function(b){var k=new a(b),l=0;return k.optimizations.push(new j(l)),k.optimizations.push(new e(l)),k.optimizations.push(new g(l)),l++,k.optimizations.push(new f(l)),k.optimizations.push(new h(l)),l++,k.optimizations.push(new c(l,256)),l++,k.optimizations.push(new i(l)),l++,k.optimizations.push(new d(l,4)),k},a}();a.SceneOptimizerOptions=k;var l=function(){function a(){}return a._CheckCurrentState=function(b,c,d,e,f){if(b.getEngine().getFps()>=c.targetFrameRate)return void(e&&e());for(var g=!0,h=!0,i=0;ib?a*(1-b/c):0},f&&(this.autoplay=f.autoplay||!1,this.loop=f.loop||!1,void 0!==f.volume&&(this._volume=f.volume),this.spatialSound=f.spatialSound||!1,this.maxDistance=f.maxDistance||100,this.useCustomAttenuation=f.useCustomAttenuation||!1,this.rolloffFactor=f.rolloffFactor||1,this.refDistance=f.refDistance||1,this.distanceModel=f.distanceModel||"linear",this.panningModel=f.panningModel||"HRTF",this._playbackRate=f.playbackRate||1),a.Engine.audioEngine.canUseWebAudio?(this._soundGain=a.Engine.audioEngine.audioContext.createGain(),this._soundGain.gain.value=this._volume,this._inputAudioNode=this._soundGain,this._ouputAudioNode=this._soundGain,this.spatialSound&&this._createSpatialParameters(),this._scene.mainSoundTrack.AddSound(this),c&&("string"==typeof c?a.Tools.LoadFile(c,function(a){g._soundLoaded(a)},null,null,!0):c instanceof ArrayBuffer?this._soundLoaded(c):a.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound."))):(this._scene.mainSoundTrack.AddSound(this),a.Engine.audioEngine.WarnedWebAudioUnsupported||(a.Tools.Error("Web Audio is not supported by your browser."),a.Engine.audioEngine.WarnedWebAudioUnsupported=!0))}return b.prototype.dispose=function(){a.Engine.audioEngine.canUseWebAudio&&this._isReadyToPlay&&(this._isPlaying&&this.stop(),this._isReadyToPlay=!1,-1===this.soundTrackId?this._scene.mainSoundTrack.RemoveSound(this):this._scene.soundTracks[this.soundTrackId].RemoveSound(this),this._soundGain.disconnect(),this._soundSource.disconnect(),this._soundPanner&&(this._soundPanner.disconnect(),this._soundPanner=null),this._audioBuffer=null,this._soundGain=null,this._soundSource=null,this._connectedMesh&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._connectedMesh=null))},b.prototype._soundLoaded=function(b){var c=this;this._isLoaded=!0,a.Engine.audioEngine.audioContext.decodeAudioData(b,function(a){c._audioBuffer=a,c._isReadyToPlay=!0,c.autoplay&&c.play(),c._readyToPlayCallback&&c._readyToPlayCallback()},function(b){a.Tools.Error("Error while decoding audio data: "+b.err)})},b.prototype.setAudioBuffer=function(b){a.Engine.audioEngine.canUseWebAudio&&(this._audioBuffer=b,this._isReadyToPlay=!0)},b.prototype.updateOptions=function(a){a&&(this.loop=a.loop||this.loop,this.maxDistance=a.maxDistance||this.maxDistance,this.useCustomAttenuation=a.useCustomAttenuation||this.useCustomAttenuation,this.rolloffFactor=a.rolloffFactor||this.rolloffFactor,this.refDistance=a.refDistance||this.refDistance,this.distanceModel=a.distanceModel||this.distanceModel,this.panningModel=a.panningModel||this.panningModel,this._playbackRate=a.playbackRate||this._playbackRate)},b.prototype._createSpatialParameters=function(){a.Engine.audioEngine.canUseWebAudio&&(this._soundPanner=a.Engine.audioEngine.audioContext.createPanner(),this.useCustomAttenuation?(this._soundPanner.distanceModel="linear",this._soundPanner.maxDistance=Number.MAX_VALUE,this._soundPanner.refDistance=1,this._soundPanner.rolloffFactor=1,this._soundPanner.panningModel="HRTF"):(this._soundPanner.distanceModel=this.distanceModel,this._soundPanner.maxDistance=this.maxDistance,this._soundPanner.refDistance=this.refDistance,this._soundPanner.rolloffFactor=this.rolloffFactor,this._soundPanner.panningModel=this.panningModel),this._soundPanner.connect(this._ouputAudioNode),this._inputAudioNode=this._soundPanner)},b.prototype.connectToSoundTrackAudioNode=function(b){a.Engine.audioEngine.canUseWebAudio&&(this._ouputAudioNode.disconnect(),this._ouputAudioNode.connect(b))},b.prototype.setDirectionalCone=function(b,c,d){return b>c?void a.Tools.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle."):(this._coneInnerAngle=b,this._coneOuterAngle=c,this._coneOuterGain=d,this._isDirectional=!0,void(this._isPlaying&&this.loop&&(this.stop(),this.play())))},b.prototype.setPosition=function(a){this._position=a,this._isPlaying&&this.spatialSound&&this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z)},b.prototype.setLocalDirectionToMesh=function(a){this._localDirection=a,this._connectedMesh&&this._isPlaying&&this._updateDirection()},b.prototype._updateDirection=function(){var b=this._connectedMesh.getWorldMatrix(),c=a.Vector3.TransformNormal(this._localDirection,b);c.normalize(),this._soundPanner.setOrientation(c.x,c.y,c.z)},b.prototype.updateDistanceFromListener=function(){if(this._connectedMesh&&this.useCustomAttenuation){var a=this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);this._soundGain.gain.value=this._customAttenuationFunction(this._volume,a,this.maxDistance,this.refDistance,this.rolloffFactor)}},b.prototype.setAttenuationFunction=function(a){this._customAttenuationFunction=a},b.prototype.play=function(b){if(this._isReadyToPlay)try{var c=b?a.Engine.audioEngine.audioContext.currentTime+b:0;this._soundSource||this.spatialSound&&(this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z),this._isDirectional&&(this._soundPanner.coneInnerAngle=this._coneInnerAngle,this._soundPanner.coneOuterAngle=this._coneOuterAngle,this._soundPanner.coneOuterGain=this._coneOuterGain,this._connectedMesh?this._updateDirection():this._soundPanner.setOrientation(this._localDirection.x,this._localDirection.y,this._localDirection.z))),this._soundSource=a.Engine.audioEngine.audioContext.createBufferSource(),this._soundSource.buffer=this._audioBuffer,this._soundSource.connect(this._inputAudioNode),this._soundSource.loop=this.loop,this._soundSource.playbackRate.value=this._playbackRate,this._startTime=c,this.onended&&(this._soundSource.onended=this.onended),this._soundSource.start(c,this._startOffset%this._soundSource.buffer.duration),this._isPlaying=!0}catch(d){a.Tools.Error("Error while trying to play audio: "+this.name+", "+d.message)}},b.prototype.stop=function(b){if(this._isPlaying){var c=b?a.Engine.audioEngine.audioContext.currentTime+b:0;this._soundSource.stop(c),this._isPlaying=!1}},b.prototype.pause=function(){this._isPlaying&&(this._soundSource.stop(0),this._startOffset+=a.Engine.audioEngine.audioContext.currentTime-this._startTime)},b.prototype.setVolume=function(b,c){a.Engine.audioEngine.canUseWebAudio&&(c?(this._soundGain.gain.linearRampToValueAtTime(this._volume,a.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.linearRampToValueAtTime(b,c)):this._soundGain.gain.value=b),this._volume=b},b.prototype.setPlaybackRate=function(a){this._playbackRate=a,this._isPlaying&&(this._soundSource.playbackRate.value=this._playbackRate)},b.prototype.getVolume=function(){return this._volume},b.prototype.attachToMesh=function(a){var b=this;this._connectedMesh=a,this.spatialSound||(this._createSpatialParameters(),this.spatialSound=!0,this._isPlaying&&this.loop&&(this.stop(),this.play())),this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh),this._registerFunc=function(a){return b._onRegisterAfterWorldMatrixUpdate(a)},a.registerAfterWorldMatrixUpdate(this._registerFunc)},b.prototype._onRegisterAfterWorldMatrixUpdate=function(a){this.setPosition(a.getBoundingInfo().boundingSphere.centerWorld),this._isDirectional&&this._isPlaying&&this._updateDirection()},b}();a.Sound=b}(BABYLON||(BABYLON={})),function(a){var b=function(){function b(b,c){this.id=-1,this._isMainTrack=!1,this._scene=b,this._audioEngine=a.Engine.audioEngine,this.soundCollection=new Array,this._audioEngine.canUseWebAudio&&(this._trackGain=this._audioEngine.audioContext.createGain(),this._trackGain.connect(this._audioEngine.masterGain),c&&(c.volume&&(this._trackGain.gain.value=c.volume),c.mainTrack&&(this._isMainTrack=c.mainTrack))),this._isMainTrack||(this._scene.soundTracks.push(this),this.id=this._scene.soundTracks.length-1)}return b.prototype.dispose=function(){if(this._audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._trackGain.disconnect(),this._trackGain=null}},b.prototype.AddSound=function(b){a.Engine.audioEngine.canUseWebAudio&&b.connectToSoundTrackAudioNode(this._trackGain),b.soundTrackId&&(-1===b.soundTrackId?this._scene.mainSoundTrack.RemoveSound(b):this._scene.soundTracks[b.soundTrackId].RemoveSound(b)),this.soundCollection.push(b),b.soundTrackId=this.id},b.prototype.RemoveSound=function(a){var b=this.soundCollection.indexOf(a);-1!==b&&this.soundCollection.splice(b,1)},b.prototype.setVolume=function(a){this._audioEngine.canUseWebAudio&&(this._trackGain.gain.value=a)},b.prototype.connectToAnalyser=function(a){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this._connectedAnalyser=a,this._audioEngine.canUseWebAudio&&(this._trackGain.disconnect(),this._connectedAnalyser.connectAudioNodes(this._trackGain,this._audioEngine.masterGain))},b}();a.SoundTrack=b}(BABYLON||(BABYLON={})),function(a){var b=function(){function b(b){var c=this;this._enabled=!1,this._labelsEnabled=!1,this._displayStatistics=!0,this._displayTree=!1,this._displayLogs=!1,this._identityMatrix=a.Matrix.Identity(),this.axisRatio=.02,this.accentColor="orange",this._scene=b,this._syncPositions=function(){var a=c._scene.getEngine(),b=a.getRenderingCanvasClientRect();c._showUI&&(c._statsDiv.style.left=b.width-410+"px",c._statsDiv.style.top=b.height-290+"px",c._statsDiv.style.width="400px",c._statsDiv.style.height="auto",c._statsSubsetDiv.style.maxHeight="240px",c._optionsDiv.style.left="0px",c._optionsDiv.style.top="10px",c._optionsDiv.style.width="200px",c._optionsDiv.style.height="auto",c._optionsSubsetDiv.style.maxHeight=b.height-225+"px",c._logDiv.style.left="0px",c._logDiv.style.top=b.height-170+"px",c._logDiv.style.width="600px",c._logDiv.style.height="160px",c._treeDiv.style.left=b.width-310+"px",c._treeDiv.style.top="10px",c._treeDiv.style.width="300px",c._treeDiv.style.height="auto",c._treeSubsetDiv.style.maxHeight=b.height-340+"px"),c._globalDiv.style.left=b.left+"px",c._globalDiv.style.top=b.top+"px",c._drawingCanvas.style.left="0px",c._drawingCanvas.style.top="0px",c._drawingCanvas.style.width=a.getRenderWidth()+"px",c._drawingCanvas.style.height=a.getRenderHeight()+"px";var d=window.devicePixelRatio||1,e=c._drawingContext,f=e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1;c._ratio=d/f,c._drawingCanvas.width=a.getRenderWidth()*c._ratio,c._drawingCanvas.height=a.getRenderHeight()*c._ratio},this._onCanvasClick=function(a){c._clickPosition={x:a.clientX*c._ratio,y:a.clientY*c._ratio}},this._syncData=function(){if(c._showUI&&(c._displayStatistics?(c._displayStats(),c._statsDiv.style.display=""):c._statsDiv.style.display="none",c._logDiv.style.display=c._displayLogs?"":"none",c._displayTree?(c._treeDiv.style.display="",c._needToRefreshMeshesTree&&(c._needToRefreshMeshesTree=!1,c._refreshMeshesTreeContent())):c._treeDiv.style.display="none"),c._labelsEnabled||!c._showUI){c._drawingContext.clearRect(0,0,c._drawingCanvas.width,c._drawingCanvas.height);for(var b=c._scene.getEngine(),d=c._scene.activeCamera.viewport,e=d.toGlobal(b),f=c._scene.getActiveMeshes(),g=0;gb.name?1:-1});for(var b=0;b0&&b.z<1){this._drawingContext.font="normal 12px Segoe UI";var f=this._drawingContext.measureText(a),g=b.x-f.width/2,h=b.y;this._isClickInsideRect(g-5,h-c-12,f.width+10,17)&&d(),this._drawingContext.beginPath(),this._drawingContext.rect(g-5,h-c-12,f.width+10,17),this._drawingContext.fillStyle=e(),this._drawingContext.globalAlpha=.5,this._drawingContext.fill(),this._drawingContext.globalAlpha=1,this._drawingContext.strokeStyle="#FFFFFF",this._drawingContext.lineWidth=1,this._drawingContext.stroke(),this._drawingContext.fillStyle="#FFFFFF",this._drawingContext.fillText(a,g,h-c),this._drawingContext.beginPath(),this._drawingContext.arc(b.x,h,5,0,2*Math.PI,!1),this._drawingContext.fill()}},b.prototype._isClickInsideRect=function(a,b,c,d){return this._clickPosition?this._clickPosition.xa+c?!1:this._clickPosition.yb+d?!1:!0:!1},b.prototype.isVisible=function(){return this._enabled},b.prototype.hide=function(){if(this._enabled){this._enabled=!1;var b=this._scene.getEngine();this._scene.unregisterAfterRender(this._syncData),document.body.removeChild(this._globalDiv),window.removeEventListener("resize",this._syncPositions),this._scene.forceShowBoundingBoxes=!1,this._scene.forceWireframe=!1,a.StandardMaterial.DiffuseTextureEnabled=!0,a.StandardMaterial.AmbientTextureEnabled=!0,a.StandardMaterial.SpecularTextureEnabled=!0,a.StandardMaterial.EmissiveTextureEnabled=!0,a.StandardMaterial.BumpTextureEnabled=!0,a.StandardMaterial.OpacityTextureEnabled=!0,a.StandardMaterial.ReflectionTextureEnabled=!0,this._scene.shadowsEnabled=!0,this._scene.particlesEnabled=!0,this._scene.postProcessesEnabled=!0,this._scene.collisionsEnabled=!0,this._scene.lightsEnabled=!0,this._scene.texturesEnabled=!0,this._scene.lensFlaresEnabled=!0,this._scene.proceduralTexturesEnabled=!0,this._scene.renderTargetsEnabled=!0,b.getRenderingCanvas().removeEventListener("click",this._onCanvasClick)}},b.prototype.show=function(a){if(void 0===a&&(a=!0),!this._enabled){this._enabled=!0,this._showUI=a;var b=this._scene.getEngine();this._globalDiv=document.createElement("div"),document.body.appendChild(this._globalDiv),this._generateDOMelements(),window.addEventListener("resize",this._syncPositions),b.getRenderingCanvas().addEventListener("click",this._onCanvasClick),this._syncPositions(),this._scene.registerAfterRender(this._syncData)}},b.prototype._clearLabels=function(){this._drawingContext.clearRect(0,0,this._drawingCanvas.width,this._drawingCanvas.height);for(var a=0;aWindows:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Statistics",this._displayStatistics,function(a){b._displayStatistics=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Logs",this._displayLogs,function(a){b._displayLogs=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Meshes tree",this._displayTree,function(a){b._displayTree=a.checked,b._needToRefreshMeshesTree=!0}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"General:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Bounding boxes",this._scene.forceShowBoundingBoxes,function(a){b._scene.forceShowBoundingBoxes=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Clickable labels",this._labelsEnabled,function(a){b._labelsEnabled=a.checked,b._labelsEnabled||b._clearLabels()}),this._generateCheckBox(this._optionsSubsetDiv,"Generate user marks (F12)",a.Tools.PerformanceLogLevel===a.Tools.PerformanceUserMarkLogLevel,function(b){a.Tools.PerformanceLogLevel=b.checked?a.Tools.PerformanceUserMarkLogLevel:a.Tools.PerformanceNoneLogLevel}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Rendering mode:",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Solid","renderMode",!this._scene.forceWireframe&&!this._scene.forcePointsCloud,function(a){a.checked&&(b._scene.forceWireframe=!1,b._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Wireframe","renderMode",this._scene.forceWireframe,function(a){a.checked&&(b._scene.forceWireframe=!0,b._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Point","renderMode",this._scene.forcePointsCloud,function(a){a.checked&&(b._scene.forceWireframe=!1,b._scene.forcePointsCloud=!0)}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Texture channels:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Diffuse",a.StandardMaterial.DiffuseTextureEnabled,function(b){a.StandardMaterial.DiffuseTextureEnabled=b.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Ambient",a.StandardMaterial.AmbientTextureEnabled,function(b){a.StandardMaterial.AmbientTextureEnabled=b.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Specular",a.StandardMaterial.SpecularTextureEnabled,function(b){a.StandardMaterial.SpecularTextureEnabled=b.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Emissive",a.StandardMaterial.EmissiveTextureEnabled,function(b){a.StandardMaterial.EmissiveTextureEnabled=b.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Bump",a.StandardMaterial.BumpTextureEnabled,function(b){a.StandardMaterial.BumpTextureEnabled=b.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Opacity",a.StandardMaterial.OpacityTextureEnabled,function(b){a.StandardMaterial.OpacityTextureEnabled=b.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Reflection",a.StandardMaterial.ReflectionTextureEnabled,function(b){a.StandardMaterial.ReflectionTextureEnabled=b.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fresnel",a.StandardMaterial.FresnelEnabled,function(b){a.StandardMaterial.FresnelEnabled=b.checked}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"Options:",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Animations",this._scene.animationsEnabled,function(a){b._scene.animationsEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Collisions",this._scene.collisionsEnabled,function(a){b._scene.collisionsEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fog",this._scene.fogEnabled,function(a){b._scene.fogEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lens flares",this._scene.lensFlaresEnabled,function(a){b._scene.lensFlaresEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lights",this._scene.lightsEnabled,function(a){b._scene.lightsEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Particles",this._scene.particlesEnabled,function(a){b._scene.particlesEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Post-processes",this._scene.postProcessesEnabled,function(a){b._scene.postProcessesEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Procedural textures",this._scene.proceduralTexturesEnabled,function(a){b._scene.proceduralTexturesEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Render targets",this._scene.renderTargetsEnabled,function(a){b._scene.renderTargetsEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Shadows",this._scene.shadowsEnabled,function(a){b._scene.shadowsEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Skeletons",this._scene.skeletonsEnabled,function(a){b._scene.skeletonsEnabled=a.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Textures",this._scene.texturesEnabled,function(a){b._scene.texturesEnabled=a.checked}),this._globalDiv.appendChild(this._statsDiv),this._globalDiv.appendChild(this._logDiv),this._globalDiv.appendChild(this._optionsDiv),this._globalDiv.appendChild(this._treeDiv)}},b.prototype._displayStats=function(){var b=this._scene,c=b.getEngine(),d=c.getGlInfo();this._statsSubsetDiv.innerHTML="Babylon.js v"+a.Engine.Version+" - "+a.Tools.Format(c.getFps(),0)+" fps

Count
Total meshes: "+b.meshes.length+"
Total vertices: "+b.getTotalVertices()+"
Total materials: "+b.materials.length+"
Total textures: "+b.textures.length+"
Active meshes: "+b.getActiveMeshes().length+"
Active vertices: "+b.getActiveVertices()+"
Active bones: "+b.getActiveBones()+"
Active particles: "+b.getActiveParticles()+"
Draw calls: "+c.drawCalls+"

Duration
Meshes selection: "+a.Tools.Format(b.getEvaluateActiveMeshesDuration())+" ms
Render Targets: "+a.Tools.Format(b.getRenderTargetsDuration())+" ms
Particles: "+a.Tools.Format(b.getParticlesDuration())+" ms
Sprites: "+a.Tools.Format(b.getSpritesDuration())+" ms

Render: "+a.Tools.Format(b.getRenderDuration())+" ms
Frame: "+a.Tools.Format(b.getLastFrameDuration())+" ms
Potential FPS: "+a.Tools.Format(1e3/b.getLastFrameDuration(),0)+"

Extensions
Std derivatives: "+(c.getCaps().standardDerivatives?"Yes":"No")+"
Compressed textures: "+(c.getCaps().s3tc?"Yes":"No")+"
Hardware instances: "+(c.getCaps().instancedArrays?"Yes":"No")+"
Texture float: "+(c.getCaps().textureFloat?"Yes":"No")+"
32bits indices: "+(c.getCaps().uintIndices?"Yes":"No")+"
Caps.
Max textures units: "+c.getCaps().maxTexturesImageUnits+"
Max textures size: "+c.getCaps().maxTextureSize+"
Max anisotropy: "+c.getCaps().maxAnisotropy+"



Info
"+d.version+"
"+d.renderer+"
",this.customStatsFunction&&(this._statsSubsetDiv.innerHTML+=this._statsSubsetDiv.innerHTML)},b}();a.DebugLayer=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b){function c(c,d,e,f,g,h,i,j){void 0===h&&(h=!0),void 0===i&&(i=!1),void 0===j&&(j=a.Texture.TRILINEAR_SAMPLINGMODE),b.call(this,null,g,!h,i),this._texture=g.getEngine().createRawTexture(c,d,e,f,h,i,j),this.wrapU=a.Texture.CLAMP_ADDRESSMODE,this.wrapV=a.Texture.CLAMP_ADDRESSMODE}return __extends(c,b),c.CreateLuminanceTexture=function(b,d,e,f,g,h,i){return void 0===g&&(g=!0),void 0===h&&(h=!1),void 0===i&&(i=a.Texture.TRILINEAR_SAMPLINGMODE),new c(b,d,e,a.Engine.TEXTUREFORMAT_LUMINANCE,f,g,h,i)},c.CreateLuminanceAlphaTexture=function(b,d,e,f,g,h,i){return void 0===g&&(g=!0),void 0===h&&(h=!1),void 0===i&&(i=a.Texture.TRILINEAR_SAMPLINGMODE),new c(b,d,e,a.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,f,g,h,i)},c.CreateAlphaTexture=function(b,d,e,f,g,h,i){return void 0===g&&(g=!0),void 0===h&&(h=!1),void 0===i&&(i=a.Texture.TRILINEAR_SAMPLINGMODE),new c(b,d,e,a.Engine.TEXTUREFORMAT_ALPHA,f,g,h,i)},c.CreateRGBTexture=function(b,d,e,f,g,h,i){return void 0===g&&(g=!0),void 0===h&&(h=!1),void 0===i&&(i=a.Texture.TRILINEAR_SAMPLINGMODE),new c(b,d,e,a.Engine.TEXTUREFORMAT_RGB,f,g,h,i)},c.CreateRGBATexture=function(b,d,e,f,g,h,i){return void 0===g&&(g=!0),void 0===h&&(h=!1),void 0===i&&(i=a.Texture.TRILINEAR_SAMPLINGMODE),new c(b,d,e,a.Engine.TEXTUREFORMAT_RGBA,f,g,h,i)},c}(a.Texture);a.RawTexture=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(a){function b(b,c){a.call(this,b.x,b.y),this.index=c}return __extends(b,a),b}(a.Vector2),c=function(){function c(){this.elements=new Array}return c.prototype.add=function(c){var d=this,e=new Array;return c.forEach(function(c){if(0===e.length||!a.Tools.WithinEpsilon(c.x,e[0].x,1e-5)||!a.Tools.WithinEpsilon(c.y,e[0].y,1e-5)){var f=new b(c,d.elements.length);e.push(f),d.elements.push(f)}}),e},c.prototype.computeBounds=function(){var b=new a.Vector2(this.elements[0].x,this.elements[0].y),c=new a.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach(function(a){a.xc.x&&(c.x=a.x),a.yc.y&&(c.y=a.y)}),{min:b,max:c,width:c.x-b.x,height:c.y-b.y}},c}(),d=function(){function b(){}return b.Rectangle=function(b,c,d,e){return[new a.Vector2(b,c),new a.Vector2(d,c),new a.Vector2(d,e),new a.Vector2(b,e)]},b.Circle=function(b,c,d,e){void 0===c&&(c=0),void 0===d&&(d=0),void 0===e&&(e=32);for(var f=new Array,g=0,h=2*Math.PI/e,i=0;e>i;i++)f.push(new a.Vector2(c+Math.cos(g)*b,d+Math.sin(g)*b)),g-=h;return f},b.Parse=function(a){var b,c=a.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function(a){return!isNaN(a)}),d=[];for(b=0;b<(2147483646&c.length);b+=2)d.push(new poly2tri.Point(c[b],c[b+1]));return d},b.StartingAt=function(b,c){return a.Path2.StartingAt(b,c)},b}();a.Polygon=d;var e=function(){function b(b,d,e){if(this._points=new c,!("poly2tri"in window))throw"PolygonMeshBuilder cannot be used because poly2tri is not referenced";this._name=b,this._scene=e;var f;f=d instanceof a.Path2?d.getPoints():d,this._swctx=new poly2tri.SweepContext(this._points.add(f))}return b.prototype.addHole=function(a){return this._swctx.addHole(this._points.add(a)),this},b.prototype.build=function(b){void 0===b&&(b=!1);var c=new a.Mesh(this._name,this._scene),d=[],e=[],f=[],g=this._points.computeBounds();this._points.elements.forEach(function(a){d.push(0,1,0),e.push(a.x,0,a.y),f.push((a.x-g.min.x)/g.width,(a.y-g.min.y)/g.height)});var h=[];return this._swctx.triangulate(),this._swctx.getTriangles().forEach(function(a){a.getPoints().forEach(function(a){h.push(a.index)})}),c.setVerticesData(e,a.VertexBuffer.PositionKind,b),c.setVerticesData(d,a.VertexBuffer.NormalKind,b),c.setVerticesData(f,a.VertexBuffer.UVKind,b),c.setIndices(h),c},b}();a.PolygonMeshBuilder=e}(BABYLON||(BABYLON={})),function(a){var b=function(){function a(a,b){this.quality=a,this.distance=b}return a}();a.SimplificationSettings=b,function(a){a[a.QUADRATIC=0]="QUADRATIC"}(a.SimplificationType||(a.SimplificationType={}));var c=(a.SimplificationType,function(){function a(a){this.vertices=a,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.borderFactor=0}return a}());a.DecimationTriangle=c;var d=function(){function a(a,b,c,d){this.position=a,this.normal=b,this.uv=c,this.id=d,this.isBorder=!0,this.q=new e,this.triangleCount=0,this.triangleStart=0}return a}();a.DecimationVertex=d;var e=function(){function a(a){this.data=new Array(10);for(var b=0;10>b;++b)this.data[b]=a&&a[b]?a[b]:0}return a.prototype.det=function(a,b,c,d,e,f,g,h,i){var j=this.data[a]*this.data[e]*this.data[i]+this.data[c]*this.data[d]*this.data[h]+this.data[b]*this.data[f]*this.data[g]-this.data[c]*this.data[e]*this.data[g]-this.data[a]*this.data[f]*this.data[h]-this.data[b]*this.data[d]*this.data[i];return j},a.prototype.addInPlace=function(a){for(var b=0;10>b;++b)this.data[b]+=a.data[b]},a.prototype.addArrayInPlace=function(a){for(var b=0;10>b;++b)this.data[b]+=a[b]},a.prototype.add=function(b){for(var c=new a,d=0;10>d;++d)c.data[d]=this.data[d]+b.data[d];return c},a.FromData=function(b,c,d,e){return new a(a.DataFromNumbers(b,c,d,e))},a.DataFromNumbers=function(a,b,c,d){return[a*a,a*b,a*c,a*d,b*b,b*c,b*d,c*c,c*d,d*d]},a}();a.QuadraticMatrix=e;var f=function(){function a(a,b){this.vertexId=a,this.triangleId=b}return a}();a.Reference=f;var g=function(){function b(a){this._mesh=a,this.initialised=!1,this.syncIterations=5e3,this.aggressiveness=7,this.decimationIterations=100}return b.prototype.simplify=function(a,b){var c=this;this.initWithMesh(this._mesh,function(){c.runDecimation(a,b)})},b.prototype.runDecimation=function(b,c){var d=this,e=~~(this.triangles.length*b.quality),f=0,g=this.triangles.length,h=function(b,c){setTimeout(function(){b%5===0&&d.updateMesh(0===b);for(var h=0;hi||e.deleted||e.isDirty))for(var g=0;3>g;++g)if(e.error[g]v;v++)d.references[m.triangleStart+v]=d.references[t+v]}else m.triangleStart=t;m.triangleCount=u;break}};a.AsyncLoop.SyncAsyncForLoop(d.triangles.length,d.syncIterations,j,c,function(){return e>=g-f})},0)};a.AsyncLoop.Run(this.decimationIterations,function(a){e>=g-f?a.breakLoop():h(a.index,function(){a.executeNext()})},function(){setTimeout(function(){c(d.reconstructMesh())},0)})},b.prototype.initWithMesh=function(b,e){var f=this;if(b){this.vertices=[],this.triangles=[],this._mesh=b;var g=this._mesh.getVerticesData(a.VertexBuffer.PositionKind),h=this._mesh.getVerticesData(a.VertexBuffer.NormalKind),i=this._mesh.getVerticesData(a.VertexBuffer.UVKind),j=this._mesh.getVerticesData(a.VertexBuffer.ColorKind),k=b.getIndices(),l=function(b){var c=new d(a.Vector3.FromArray(g,3*b),a.Vector3.FromArray(h,3*b),null,b);f._mesh.isVerticesDataPresent(a.VertexBuffer.UVKind)?c.uv=a.Vector2.FromArray(i,2*b):f._mesh.isVerticesDataPresent(a.VertexBuffer.ColorKind)&&(c.color=a.Color4.FromArray(j,4*b)),f.vertices.push(c)},m=b.getTotalVertices();a.AsyncLoop.SyncAsyncForLoop(m,this.syncIterations,l,function(){var b=function(a){var b=3*a,d=k[b+0],e=k[b+1],g=k[b+2],h=new c([f.vertices[d].id,f.vertices[e].id,f.vertices[g].id]);f.triangles.push(h)};a.AsyncLoop.SyncAsyncForLoop(k.length/3,f.syncIterations,b,function(){f.init(e)})})}},b.prototype.init=function(b){var c=this,d=function(b){var d=c.triangles[b];d.normal=a.Vector3.Cross(c.vertices[d.vertices[1]].position.subtract(c.vertices[d.vertices[0]].position),c.vertices[d.vertices[2]].position.subtract(c.vertices[d.vertices[0]].position)).normalize();for(var f=0;3>f;f++)c.vertices[d.vertices[f]].q.addArrayInPlace(e.DataFromNumbers(d.normal.x,d.normal.y,d.normal.z,-a.Vector3.Dot(d.normal,c.vertices[d.vertices[0]].position)))};a.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,d,function(){var d=function(a){for(var b=c.triangles[a],d=0;3>d;++d)b.error[d]=c.calculateError(c.vertices[b.vertices[d]],c.vertices[b.vertices[(d+1)%3]]);b.error[3]=Math.min(b.error[0],b.error[1],b.error[2])};a.AsyncLoop.SyncAsyncForLoop(c.triangles.length,c.syncIterations,d,function(){c.initialised=!0,b()})})},b.prototype.reconstructMesh=function(){var b,c=[];for(b=0;be;++e)this.vertices[d.vertices[e]].triangleCount=1;c.push(d)}var f=[],g=0;for(b=0;be;++e)d.vertices[e]=this.vertices[d.vertices[e]].triangleStart;this.vertices=this.vertices.slice(0,g);var h=[],i=[],j=[],k=[];for(b=0;b0&&m.setVerticesData(a.VertexBuffer.UVKind,j),k.length>0&&m.setVerticesData(a.VertexBuffer.ColorKind,k),this._mesh.skeleton,m},b.prototype.isFlipped=function(b,c,d,e,f,g){for(var h=0;hf)e[h]=!0,g.push(i);else{var m=this.vertices[k].position.subtract(d);m=m.normalize();var n=this.vertices[l].position.subtract(d);if(n=n.normalize(),Math.abs(a.Vector3.Dot(m,n))>.999)return!0;var o=a.Vector3.Cross(m,n).normalize();if(e[h]=!1,a.Vector3.Dot(o,i.normal)<.2)return!0}}}return!1},b.prototype.updateTriangles=function(a,b,c,d){for(var e=d,f=0;fg;g++){for(var h=0,i=f.vertices[g];he;++e)g=this.vertices[d.vertices[e]],g.triangleCount++;var h=0;for(b=0;be;++e)g=this.vertices[d.vertices[e]],i[g.triangleStart+g.triangleCount]=new f(e,b),g.triangleCount++;this.references=i,a&&this.identifyBorder()},b.prototype.vertexError=function(a,b){var c=b.x,d=b.y,e=b.z;return a.data[0]*c*c+2*a.data[1]*c*d+2*a.data[2]*c*e+2*a.data[3]*c+a.data[4]*d*d+2*a.data[5]*d*e+2*a.data[6]*d+a.data[7]*e*e+2*a.data[8]*e+a.data[9]},b.prototype.calculateError=function(b,c,d,e,f,g){var h=b.q.add(c.q),i=b.isBorder&&c.isBorder,j=0,k=h.det(0,1,2,1,4,5,2,5,7);if(0===k||i){var l=b.position.add(c.position).divide(new a.Vector3(2,2,2)),m=this.vertexError(h,b.position),n=this.vertexError(h,c.position),o=this.vertexError(h,l);j=Math.min(m,n,o),j===m?d&&(d.copyFrom(b.position),e.copyFrom(b.normal),b.uv?f.copyFrom(b.uv):b.color&&g.copyFrom(b.color)):j===n?d&&(d.copyFrom(c.position),e.copyFrom(c.normal),c.uv?f.copyFrom(c.uv):c.color&&g.copyFrom(c.color)):d&&(d.copyFrom(l),e.copyFrom(b.normal),b.uv?f.copyFrom(b.uv):b.color&&g.copyFrom(b.color))}else d||(d=a.Vector3.Zero()),d.x=-1/k*h.det(1,2,3,4,5,6,5,7,8),d.y=1/k*h.det(0,2,3,1,5,6,2,7,8),d.z=-1/k*h.det(0,1,3,1,4,6,2,5,8),j=this.vertexError(h,d),e&&(e.copyFrom(b.normal),b.uv?f.copyFrom(b.uv):b.color&&g.copyFrom(b.color));return j},b}();a.QuadraticErrorSimplification=g}(BABYLON||(BABYLON={})),function(a){var b=function(){function b(b){this.SMOOTHING=.75,this.FFT_SIZE=512,this.BARGRAPHAMPLITUDE=256,this.DEBUGCANVASPOS={x:20,y:20},this.DEBUGCANVASSIZE={width:320,height:200},this._scene=b,this._audioEngine=a.Engine.audioEngine,this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser=this._audioEngine.audioContext.createAnalyser(),this._webAudioAnalyser.minDecibels=-140,this._webAudioAnalyser.maxDecibels=0,this._byteFreqs=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._byteTime=new Uint8Array(this._webAudioAnalyser.frequencyBinCount),this._floatFreqs=new Float32Array(this._webAudioAnalyser.frequencyBinCount)) }return b.prototype.getFrequencyBinCount=function(){return this._audioEngine.canUseWebAudio?this._webAudioAnalyser.frequencyBinCount:0},b.prototype.getByteFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs)),this._byteFreqs},b.prototype.getByteTimeDomainData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getByteTimeDomainData(this._byteTime)),this._byteTime},b.prototype.getFloatFrequencyData=function(){return this._audioEngine.canUseWebAudio&&(this._webAudioAnalyser.smoothingTimeConstant=this.SMOOTHING,this._webAudioAnalyser.fftSize=this.FFT_SIZE,this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs)),this._floatFreqs},b.prototype.drawDebugCanvas=function(){var a=this;if(this._audioEngine.canUseWebAudio&&(this._debugCanvas||(this._debugCanvas=document.createElement("canvas"),this._debugCanvas.width=this.DEBUGCANVASSIZE.width,this._debugCanvas.height=this.DEBUGCANVASSIZE.height,this._debugCanvas.style.position="absolute",this._debugCanvas.style.top=this.DEBUGCANVASPOS.y+"px",this._debugCanvas.style.left=this.DEBUGCANVASPOS.x+"px",this._debugCanvasContext=this._debugCanvas.getContext("2d"),document.body.appendChild(this._debugCanvas),this._registerFunc=function(){a.drawDebugCanvas()},this._scene.registerBeforeRender(this._registerFunc)),this._registerFunc)){var b=this.getByteFrequencyData();this._debugCanvasContext.fillStyle="rgb(0, 0, 0)",this._debugCanvasContext.fillRect(0,0,this.DEBUGCANVASSIZE.width,this.DEBUGCANVASSIZE.height);for(var c=0;ce;e++)for(var f=0;b>f;f++){var g=a.Vector3.Zero();g.x=Math.floor(255*d(0,1)),g.y=Math.floor(255*d(0,1)),g.z=Math.floor(255*d(0,1)),c.fillStyle="rgb("+g.x+", "+g.y+", "+g.z+")",c.fillRect(e,f,1,1)}this._randomTexture.update(!1)},c}(a.PostProcessRenderPipeline);a.SSAORenderingPipeline=b}(BABYLON||(BABYLON={}));var BABYLON;!function(a){var b=function(b){function c(d,e,f,g,h,i,j,k){var l=this;void 0===h&&(h=100),void 0===i&&(i=a.Texture.BILINEAR_SAMPLINGMODE),b.call(this,d,"volumetricLightScattering",["decay","exposure","weight","meshPositionOnScreen","density"],["lightScatteringSampler"],e,f,i,j,k,"#define NUM_SAMPLES "+h),this._screenCoordinates=a.Vector2.Zero(),this.useCustomMeshPosition=!1,this.invert=!0,this.excludedMeshes=new Array,this.exposure=.3,this.decay=.96815,this.weight=.58767,this.density=.926;var m=f.getScene();this._viewPort=new a.Viewport(0,0,1,1).toGlobal(m.getEngine()),this.mesh=null!==g?g:c.CreateDefaultMesh("VolumetricLightScatteringMesh",m),this._createPass(m,.5),this.onApply=function(a){l._updateMeshScreenCoordinates(m),a.setTexture("lightScatteringSampler",l._volumetricLightScatteringRTT),a.setFloat("exposure",l.exposure),a.setFloat("decay",l.decay),a.setFloat("weight",l.weight),a.setFloat("density",l.density),a.setVector2("meshPositionOnScreen",l._screenCoordinates)}}return __extends(c,b),c.prototype.isReady=function(b,c){var d=b.getMesh(),e=[],f=[a.VertexBuffer.PositionKind],g=b.getMaterial();d===this.mesh&&e.push("#define BASIC_RENDER"),g&&((g.needAlphaTesting()||d===this.mesh)&&e.push("#define ALPHATEST"),void 0!==g.opacityTexture&&e.push("#define OPACITY"),d.isVerticesDataPresent(a.VertexBuffer.UVKind)&&(f.push(a.VertexBuffer.UVKind),e.push("#define UV1")),d.isVerticesDataPresent(a.VertexBuffer.UV2Kind)&&(f.push(a.VertexBuffer.UV2Kind),e.push("#define UV2"))),d.useBones&&(f.push(a.VertexBuffer.MatricesIndicesKind),f.push(a.VertexBuffer.MatricesWeightsKind),e.push("#define BONES"),e.push("#define BonesPerMesh "+(d.skeleton.bones.length+1))),c&&(e.push("#define INSTANCES"),f.push("world0"),f.push("world1"),f.push("world2"),f.push("world3"));var h=e.join("\n");return this._cachedDefines!==h&&(this._cachedDefines=h,this._volumetricLightScatteringPass=d.getScene().getEngine().createEffect({vertexElement:"depth",fragmentElement:"volumetricLightScatteringPass"},f,["world","mBones","viewProjection","diffuseMatrix","far"],["diffuseSampler","opacitySampler"],h)),this._volumetricLightScatteringPass.isReady()},c.prototype.setCustomMeshPosition=function(a){this._customMeshPosition=a},c.prototype.getCustomMeshPosition=function(){return this._customMeshPosition},c.prototype.dispose=function(a){var c=a.getScene().customRenderTargets.indexOf(this._volumetricLightScatteringRTT);-1!==c&&a.getScene().customRenderTargets.splice(c,1),this._volumetricLightScatteringRTT.dispose(),b.prototype.dispose.call(this,a)},c.prototype.getPass=function(){return this._volumetricLightScatteringRTT},c.prototype._meshExcluded=function(a){return this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(a)?!0:!1},c.prototype._createPass=function(b,c){var d=this,e=b.getEngine();this._volumetricLightScatteringRTT=new a.RenderTargetTexture("volumetricLightScatteringMap",{width:e.getRenderWidth()*c,height:e.getRenderHeight()*c},b,!1,!0,a.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=a.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=a.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1,b.customRenderTargets.push(this._volumetricLightScatteringRTT);var f,g=function(b){var c=b.getRenderingMesh();if(!d._meshExcluded(c)){var e=c.getScene(),f=e.getEngine();f.setState(b.getMaterial().backFaceCulling);var g=c._getInstancesRenderList(b._id);if(!g.mustReturn){var h=null!==f.getCaps().instancedArrays&&null!==g.visibleInstances[b._id];if(d.isReady(b,h)){f.enableEffect(d._volumetricLightScatteringPass),c._bind(b,d._volumetricLightScatteringPass,a.Material.TriangleFillMode);var i=b.getMaterial();if(d._volumetricLightScatteringPass.setMatrix("viewProjection",e.getTransformMatrix()),i&&(c===d.mesh||i.needAlphaTesting()||void 0!==i.opacityTexture)){var j=i.getAlphaTestTexture();d._volumetricLightScatteringPass.setTexture("diffuseSampler",j),d.mesh.material&&j&&d._volumetricLightScatteringPass.setMatrix("diffuseMatrix",j.getTextureMatrix()),void 0!==i.opacityTexture&&d._volumetricLightScatteringPass.setTexture("opacitySampler",i.opacityTexture)}c.useBones&&d._volumetricLightScatteringPass.setMatrices("mBones",c.skeleton.getTransformMatrices()),c._processRendering(b,d._volumetricLightScatteringPass,a.Material.TriangleFillMode,g,h,function(a,b){return d._volumetricLightScatteringPass.setMatrix("world",b)})}}}},h=new a.Color3(0,0,0);this._volumetricLightScatteringRTT.onBeforeRender=function(){f=b.clearColor,b.clearColor=h},this._volumetricLightScatteringRTT.onAfterRender=function(){b.clearColor=f},this._volumetricLightScatteringRTT.customRenderFunction=function(a,b,c){var d;for(d=0;d