text: var __extends=this&&this.__extends||function(e,t){function i(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);i.prototype=t.prototype,e.prototype=new i},BABYLON;!function(e){var t=function(){function t(e,t,i){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),this.r=e,this.g=t,this.b=i}return t.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,this},t.prototype.toColor4=function(e){return void 0===e&&(e=1),new i(this.r,this.g,this.b,e)},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},t.prototype.multiply=function(e){return new t(this.r*e.r,this.g*e.g,this.b*e.b)},t.prototype.multiplyToRef=function(e,t){return t.r=this.r*e.r,t.g=this.g*e.g,t.b=this.b*e.b,this},t.prototype.equals=function(e){return e&&this.r===e.r&&this.g===e.g&&this.b===e.b},t.prototype.equalsFloats=function(e,t,i){return this.r===e&&this.g===t&&this.b===i},t.prototype.scale=function(e){return new t(this.r*e,this.g*e,this.b*e)},t.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,this},t.prototype.add=function(e){return new t(this.r+e.r,this.g+e.g,this.b+e.b)},t.prototype.addToRef=function(e,t){return t.r=this.r+e.r,t.g=this.g+e.g,t.b=this.b+e.b,this},t.prototype.subtract=function(e){return new t(this.r-e.r,this.g-e.g,this.b-e.b)},t.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,this},t.prototype.clone=function(){return new t(this.r,this.g,this.b)},t.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this},t.prototype.copyFromFloats=function(e,t,i){return this.r=e,this.g=t,this.b=i,this},t.prototype.toHexString=function(){var t=255*this.r|0,i=255*this.g|0,r=255*this.b|0;return"#"+e.Tools.ToHex(t)+e.Tools.ToHex(i)+e.Tools.ToHex(r)},t.FromHexString=function(i){if("#"!==i.substring(0,1)||7!==i.length)return e.Tools.Warn("Color3.FromHexString must be called with a string like #FFFFFF"),new t(0,0,0);var r=parseInt(i.substring(1,3),16),n=parseInt(i.substring(3,5),16),o=parseInt(i.substring(5,7),16);return t.FromInts(r,n,o)},t.FromArray=function(e,i){return void 0===i&&(i=0),new t(e[i],e[i+1],e[i+2])},t.FromInts=function(e,i,r){return new t(e/255,i/255,r/255)},t.Lerp=function(e,i,r){var n=e.r+(i.r-e.r)*r,o=e.g+(i.g-e.g)*r,s=e.b+(i.b-e.b)*r;return new t(n,o,s)},t.Red=function(){return new t(1,0,0)},t.Green=function(){return new t(0,1,0)},t.Blue=function(){return new t(0,0,1)},t.Black=function(){return new t(0,0,0)},t.White=function(){return new t(1,1,1)},t.Purple=function(){return new t(.5,0,.5)},t.Magenta=function(){return new t(1,0,1)},t.Yellow=function(){return new t(1,1,0)},t.Gray=function(){return new t(.5,.5,.5)},t}();e.Color3=t;var i=function(){function t(e,t,i,r){this.r=e,this.g=t,this.b=i,this.a=r}return t.prototype.addInPlace=function(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this.a+=e.a,this},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e[t+3]=this.a,this},t.prototype.add=function(e){return new t(this.r+e.r,this.g+e.g,this.b+e.b,this.a+e.a)},t.prototype.subtract=function(e){return new t(this.r-e.r,this.g-e.g,this.b-e.b,this.a-e.a)},t.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,t.a=this.a-e.a,this},t.prototype.scale=function(e){return new t(this.r*e,this.g*e,this.b*e,this.a*e)},t.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,t.a=this.a*e,this},t.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this},t.prototype.toHexString=function(){var t=255*this.r|0,i=255*this.g|0,r=255*this.b|0,n=255*this.a|0;return"#"+e.Tools.ToHex(t)+e.Tools.ToHex(i)+e.Tools.ToHex(r)+e.Tools.ToHex(n)},t.FromHexString=function(i){if("#"!==i.substring(0,1)||9!==i.length)return e.Tools.Warn("Color4.FromHexString must be called with a string like #FFFFFFFF"),new t(0,0,0,0);var r=parseInt(i.substring(1,3),16),n=parseInt(i.substring(3,5),16),o=parseInt(i.substring(5,7),16),s=parseInt(i.substring(7,9),16);return t.FromInts(r,n,o,s)},t.Lerp=function(e,i,r){var n=new t(0,0,0,0);return t.LerpToRef(e,i,r,n),n},t.LerpToRef=function(e,t,i,r){r.r=e.r+(t.r-e.r)*i,r.g=e.g+(t.g-e.g)*i,r.b=e.b+(t.b-e.b)*i,r.a=e.a+(t.a-e.a)*i},t.FromArray=function(e,i){return void 0===i&&(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.FromInts=function(e,i,r,n){return new t(e/255,i/255,r/255,n/255)},t}();e.Color4=i;var r=function(){function t(e,t){this.x=e,this.y=t}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,this},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this},t.prototype.copyFromFloats=function(e,t){return this.x=e,this.y=t,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.addVector3=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y)},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,this},t.prototype.multiplyByFloats=function(e,i){return new t(this.x*e,this.y*i)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,this},t.prototype.negate=function(){return new t(-this.x,-this.y)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e)},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Engine.Epsilon),t&&e.Tools.WithinEpsilon(this.x,t.x,i)&&e.Tools.WithinEpsilon(this.y,t.y,i)},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this},t.prototype.clone=function(){return new t(this.x,this.y)},t.Zero=function(){return new t(0,0)},t.FromArray=function(e,i){return void 0===i&&(i=0),new t(e[i],e[i+1])},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1]},t.CatmullRom=function(e,i,r,n,o){var s=o*o,a=o*s,h=.5*(2*i.x+(-e.x+r.x)*o+(2*e.x-5*i.x+4*r.x-n.x)*s+(-e.x+3*i.x-3*r.x+n.x)*a),l=.5*(2*i.y+(-e.y+r.y)*o+(2*e.y-5*i.y+4*r.y-n.y)*s+(-e.y+3*i.y-3*r.y+n.y)*a);return new t(h,l)},t.Clamp=function(e,i,r){var n=e.x;n=n>r.x?r.x:n,n=n<i.x?i.x:n;var o=e.y;return o=o>r.y?r.y:o,o=o<i.y?i.y:o,new t(n,o)},t.Hermite=function(e,i,r,n,o){var s=o*o,a=o*s,h=2*a-3*s+1,l=-2*a+3*s,c=a-2*s+o,u=a-s,f=e.x*h+r.x*l+i.x*c+n.x*u,d=e.y*h+r.y*l+i.y*c+n.y*u;return new t(f,d)},t.Lerp=function(e,i,r){var n=e.x+(i.x-e.x)*r,o=e.y+(i.y-e.y)*r;return new t(n,o)},t.Dot=function(e,t){return e.x*t.x+e.y*t.y},t.Normalize=function(e){var t=e.clone();return t.normalize(),t},t.Minimize=function(e,i){var r=e.x<i.x?e.x:i.x,n=e.y<i.y?e.y:i.y;return new t(r,n)},t.Maximize=function(e,i){var r=e.x>i.x?e.x:i.x,n=e.y>i.y?e.y:i.y;return new t(r,n)},t.Transform=function(e,i){var r=e.x*i.m[0]+e.y*i.m[4],n=e.x*i.m[1]+e.y*i.m[5];return new t(r,n)},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y;return i*i+r*r},t}();e.Vector2=r;var n=function(){function t(e,t,i){this.x=e,this.y=t,this.z=i}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,this},t.prototype.toQuaternion=function(){var e=new s(0,0,0,1),t=Math.cos(.5*(this.x+this.z)),i=Math.sin(.5*(this.x+this.z)),r=Math.cos(.5*(this.z-this.x)),n=Math.sin(.5*(this.z-this.x)),o=Math.cos(.5*this.y),a=Math.sin(.5*this.y);return e.x=r*a,e.y=-n*a,e.z=i*o,e.w=t*o,e},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,this},t.prototype.subtractFromFloats=function(e,i,r){return new t(this.x-e,this.y-i,this.z-r)},t.prototype.subtractFromFloatsToRef=function(e,t,i,r){return r.x=this.x-e,r.y=this.y-t,r.z=this.z-i,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e)},t.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Engine.Epsilon),t&&e.Tools.WithinEpsilon(this.x,t.x,i)&&e.Tools.WithinEpsilon(this.y,t.y,i)&&e.Tools.WithinEpsilon(this.z,t.z,i)},t.prototype.equalsToFloats=function(e,t,i){return this.x===e&&this.y===t&&this.z===i},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,this},t.prototype.multiplyByFloats=function(e,i,r){return new t(this.x*e,this.y*i,this.z*r)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,this},t.prototype.MinimizeInPlace=function(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),this},t.prototype.MaximizeInPlace=function(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},t.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},t.prototype.copyFromFloats=function(e,t,i){return this.x=e,this.y=t,this.z=i,this},t.GetClipFactor=function(e,i,r,n){var o=t.Dot(e,r)-n,s=t.Dot(i,r)-n,a=o/(o-s);return a},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2])},t.FromFloatArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2])},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2]},t.FromFloatArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2]},t.FromFloatsToRef=function(e,t,i,r){r.x=e,r.y=t,r.z=i},t.Zero=function(){return new t(0,0,0)},t.Up=function(){return new t(0,1,0)},t.TransformCoordinates=function(e,i){var r=t.Zero();return t.TransformCoordinatesToRef(e,i,r),r},t.TransformCoordinatesToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9]+t.m[13],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]+t.m[14],s=e.x*t.m[3]+e.y*t.m[7]+e.z*t.m[11]+t.m[15];i.x=r/s,i.y=n/s,i.z=o/s},t.TransformCoordinatesFromFloatsToRef=function(e,t,i,r,n){var o=e*r.m[0]+t*r.m[4]+i*r.m[8]+r.m[12],s=e*r.m[1]+t*r.m[5]+i*r.m[9]+r.m[13],a=e*r.m[2]+t*r.m[6]+i*r.m[10]+r.m[14],h=e*r.m[3]+t*r.m[7]+i*r.m[11]+r.m[15];n.x=o/h,n.y=s/h,n.z=a/h},t.TransformCoordinatesToRefSIMD=function(e,t,i){var r=SIMD.float32x4.loadXYZ(e._data,0),n=SIMD.float32x4.load(t.m,0),o=SIMD.float32x4.load(t.m,4),s=SIMD.float32x4.load(t.m,8),a=SIMD.float32x4.load(t.m,12),h=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(r,0,0,0,0),n),SIMD.float32x4.mul(SIMD.float32x4.swizzle(r,1,1,1,1),o)),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(r,2,2,2,2),s),a));h=SIMD.float32x4.div(h,SIMD.float32x4.swizzle(h,3,3,3,3)),SIMD.float32x4.storeXYZ(i._data,0,h)},t.TransformCoordinatesFromFloatsToRefSIMD=function(e,t,i,r,n){var o=SIMD.float32x4.splat(e),s=SIMD.float32x4.splat(t),a=SIMD.float32x4.splat(i),h=SIMD.float32x4.load(r.m,0),l=SIMD.float32x4.load(r.m,4),c=SIMD.float32x4.load(r.m,8),u=SIMD.float32x4.load(r.m,12),f=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(o,h),SIMD.float32x4.mul(s,l)),SIMD.float32x4.add(SIMD.float32x4.mul(a,c),u));f=SIMD.float32x4.div(f,SIMD.float32x4.swizzle(f,3,3,3,3)),SIMD.float32x4.storeXYZ(n._data,0,f)},t.TransformNormal=function(e,i){var r=t.Zero();return t.TransformNormalToRef(e,i,r),r},t.TransformNormalToRef=function(e,t,i){i.x=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],i.y=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],i.z=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]},t.TransformNormalFromFloatsToRef=function(e,t,i,r,n){n.x=e*r.m[0]+t*r.m[4]+i*r.m[8],n.y=e*r.m[1]+t*r.m[5]+i*r.m[9],n.z=e*r.m[2]+t*r.m[6]+i*r.m[10]},t.CatmullRom=function(e,i,r,n,o){var s=o*o,a=o*s,h=.5*(2*i.x+(-e.x+r.x)*o+(2*e.x-5*i.x+4*r.x-n.x)*s+(-e.x+3*i.x-3*r.x+n.x)*a),l=.5*(2*i.y+(-e.y+r.y)*o+(2*e.y-5*i.y+4*r.y-n.y)*s+(-e.y+3*i.y-3*r.y+n.y)*a),c=.5*(2*i.z+(-e.z+r.z)*o+(2*e.z-5*i.z+4*r.z-n.z)*s+(-e.z+3*i.z-3*r.z+n.z)*a);return new t(h,l,c)},t.Clamp=function(e,i,r){var n=e.x;n=n>r.x?r.x:n,n=n<i.x?i.x:n;var o=e.y;o=o>r.y?r.y:o,o=o<i.y?i.y:o;var s=e.z;return s=s>r.z?r.z:s,s=s<i.z?i.z:s,new t(n,o,s)},t.Hermite=function(e,i,r,n,o){var s=o*o,a=o*s,h=2*a-3*s+1,l=-2*a+3*s,c=a-2*s+o,u=a-s,f=e.x*h+r.x*l+i.x*c+n.x*u,d=e.y*h+r.y*l+i.y*c+n.y*u,p=e.z*h+r.z*l+i.z*c+n.z*u;return new t(f,d,p)},t.Lerp=function(e,i,r){var n=e.x+(i.x-e.x)*r,o=e.y+(i.y-e.y)*r,s=e.z+(i.z-e.z)*r;return new t(n,o,s)},t.Dot=function(e,t){return e.x*t.x+e.y*t.y+e.z*t.z},t.Cross=function(e,i){var r=t.Zero();return t.CrossToRef(e,i,r),r},t.CrossToRef=function(e,t,i){i.x=e.y*t.z-e.z*t.y,i.y=e.z*t.x-e.x*t.z,i.z=e.x*t.y-e.y*t.x},t.Normalize=function(e){var i=t.Zero();return t.NormalizeToRef(e,i),i},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Project=function(e,i,r,n){var o=n.width,s=n.height,h=n.x,l=n.y,c=a.FromValues(o/2,0,0,0,0,-s/2,0,0,0,0,1,0,h+o/2,s/2+l,0,1),u=i.multiply(r).multiply(c);return t.TransformCoordinates(e,u)},t.UnprojectFromTransform=function(i,r,n,o,s){var a=o.multiply(s);a.invert(),i.x=i.x/r*2-1,i.y=-(i.y/n*2-1);var h=t.TransformCoordinates(i,a),l=i.x*a.m[3]+i.y*a.m[7]+i.z*a.m[11]+a.m[15];return e.Tools.WithinEpsilon(l,1)&&(h=h.scale(1/l)),h},t.Unproject=function(i,r,n,o,s,a){var h=o.multiply(s).multiply(a);h.invert();var l=new t(i.x/r*2-1,-(i.y/n*2-1),i.z),c=t.TransformCoordinates(l,h),u=l.x*h.m[3]+l.y*h.m[7]+l.z*h.m[11]+h.m[15];return e.Tools.WithinEpsilon(u,1)&&(c=c.scale(1/u)),c},t.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},t.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z;return i*i+r*r+n*n},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t.RotationFromAxis=function(e,i,r){var n=t.Zero();return t.RotationFromAxisToRef(e,i,r,n),n},t.RotationFromAxisToRef=function(i,r,n,o){var s,a,h,l=t.Normalize(i),c=t.Normalize(n),u=f.X,d=f.Y,p=0,m=0,g=0,_=0,v=0,y=0,x=0,M=-1,S=0,b=0;e.Tools.WithinEpsilon(c.z,0,e.Engine.Epsilon)?y=1:e.Tools.WithinEpsilon(c.x,0,e.Engine.Epsilon)?_=1:(x=c.z/c.x,_=-x*Math.sqrt(1/(1+x*x)),y=Math.sqrt(1/(1+x*x))),a=new t(_,v,y),a.normalize(),h=t.Cross(c,a),h.normalize(),s=t.Cross(l,a),s.normalize(),t.Dot(c,s)<0&&(M=1),b=t.Dot(l,a),b=Math.min(1,Math.max(-1,b)),g=Math.acos(b)*M,t.Dot(a,u)<0&&(g=Math.PI+g,a=a.scaleInPlace(-1),h=h.scaleInPlace(-1),S++);var A,T;_=0,v=0,y=0,M=-1,e.Tools.WithinEpsilon(c.z,0,e.Engine.Epsilon)?_=1:(x=a.z/a.x,_=-x*Math.sqrt(1/(1+x*x)),y=Math.sqrt(1/(1+x*x))),A=new t(_,v,y),A.normalize(),T=t.Cross(A,a),T.normalize(),s=t.Cross(c,A),s.normalize(),t.Dot(a,s)<0&&(M=1),b=t.Dot(c,A),b=Math.min(1,Math.max(-1,b)),m=Math.acos(b)*M,t.Dot(T,d)<0&&(m=Math.PI+m,T=T.scaleInPlace(-1),A=A.scaleInPlace(-1),S++),M=-1,s=t.Cross(u,a),s.normalize(),t.Dot(s,d)<0&&(M=1),b=t.Dot(a,u),b=Math.min(1,Math.max(-1,b)),p=-Math.acos(b)*M,0>b&&2>S&&(p=Math.PI+p),o.x=m,o.y=p,o.z=g},t}();e.Vector3=n;var o=function(){function t(e,t,i,r){this.x=e,this.y=t,this.z=i,this.w=r}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"W:"+this.w+"}"},t.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},t.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,this},t.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this},t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},t.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,t.w=this.w+e.w,this},t.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this},t.prototype.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},t.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,t.w=this.w-e.w,this},t.prototype.subtractFromFloats=function(e,i,r,n){return new t(this.x-e,this.y-i,this.z-r,this.w-n)},t.prototype.subtractFromFloatsToRef=function(e,t,i,r,n){return n.x=this.x-e,n.y=this.y-t,n.z=this.z-i,n.w=this.w-r,this},t.prototype.negate=function(){return new t(-this.x,-this.y,-this.z,-this.w)},t.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e,this.w*e)},t.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t.w=this.w*e},t.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},t.prototype.equalsWithEpsilon=function(t,i){return void 0===i&&(i=e.Engine.Epsilon),t&&e.Tools.WithinEpsilon(this.x,t.x,i)&&e.Tools.WithinEpsilon(this.y,t.y,i)&&e.Tools.WithinEpsilon(this.z,t.z,i)&&e.Tools.WithinEpsilon(this.w,t.w,i)},t.prototype.equalsToFloats=function(e,t,i,r){return this.x===e&&this.y===t&&this.z===i&&this.w===r},t.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y,this.z*e.z,this.w*e.w)},t.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,t.w=this.w*e.w,this},t.prototype.multiplyByFloats=function(e,i,r,n){return new t(this.x*e,this.y*i,this.z*r,this.w*n)},t.prototype.divide=function(e){return new t(this.x/e.x,this.y/e.y,this.z/e.z,this.w/e.w)},t.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,t.w=this.w/e.w,this},t.prototype.MinimizeInPlace=function(e){return e.x<this.x&&(this.x=e.x),e.y<this.y&&(this.y=e.y),e.z<this.z&&(this.z=e.z),e.w<this.w&&(this.w=e.w),this},t.prototype.MaximizeInPlace=function(e){return e.x>this.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},t.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},t.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},t.FromFloatArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},t.FromFloatsToRef=function(e,t,i,r,n){n.x=e,n.y=t,n.z=i,n.w=r},t.Zero=function(){return new t(0,0,0,0)},t.Normalize=function(e){var i=t.Zero();return t.NormalizeToRef(e,i),i},t.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},t.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},t.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},t.Distance=function(e,i){return Math.sqrt(t.DistanceSquared(e,i))},t.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z,o=e.w-t.w;return i*i+r*r+n*n+o*o},t.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},t}();e.Vector4=o;var s=function(){function e(e,t,i,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=1),this.x=e,this.y=t,this.z=i,this.w=r}return e.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},e.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},e.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},e.prototype.clone=function(){return new e(this.x,this.y,this.z,this.w)},e.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},e.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y,this.z+t.z,this.w+t.w)},e.prototype.subtract=function(t){return new e(this.x-t.x,this.y-t.y,this.z-t.z,this.w-t.w)},e.prototype.scale=function(t){return new e(this.x*t,this.y*t,this.z*t,this.w*t)},e.prototype.multiply=function(t){var i=new e(0,0,0,1);return this.multiplyToRef(t,i),i},e.prototype.multiplyToRef=function(e,t){var i=this.x*e.w+this.y*e.z-this.z*e.y+this.w*e.x,r=-this.x*e.z+this.y*e.w+this.z*e.x+this.w*e.y,n=this.x*e.y-this.y*e.x+this.z*e.w+this.w*e.z,o=-this.x*e.x-this.y*e.y-this.z*e.z+this.w*e.w;return t.copyFromFloats(i,r,n,o),this},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},e.prototype.normalize=function(){var e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},e.prototype.toEulerAngles=function(){var e=n.Zero();return this.toEulerAnglesToRef(e),e},e.prototype.toEulerAnglesToRef=function(e){var t=this.x,i=this.y,r=this.z,n=this.w,o=t*i,s=t*r,a=n*i,h=n*r,l=n*t,c=i*r,u=t*t,f=i*i,d=u+f;return 0!==d&&1!==d?(e.x=Math.atan2(s+a,l-c),e.y=Math.acos(1-2*d),e.z=Math.atan2(s-a,l+c)):0===d?(e.x=0,e.y=0,e.z=Math.atan2(o-h,.5-f-r*r)):(e.x=Math.atan2(o-h,.5-f-r*r),e.y=Math.PI,e.z=0),this},e.prototype.toRotationMatrix=function(e){var t=this.x*this.x,i=this.y*this.y,r=this.z*this.z,n=this.x*this.y,o=this.z*this.w,s=this.z*this.x,a=this.y*this.w,h=this.y*this.z,l=this.x*this.w;return e.m[0]=1-2*(i+r),e.m[1]=2*(n+o),e.m[2]=2*(s-a),e.m[3]=0,e.m[4]=2*(n-o),e.m[5]=1-2*(r+t),e.m[6]=2*(h+l),e.m[7]=0,e.m[8]=2*(s+a),e.m[9]=2*(h-l),e.m[10]=1-2*(i+t),e.m[11]=0,e.m[12]=0,e.m[13]=0,e.m[14]=0,e.m[15]=1,this},e.prototype.fromRotationMatrix=function(t){return e.FromRotationMatrixToRef(t,this),this},e.FromRotationMatrix=function(t){var i=new e;return e.FromRotationMatrixToRef(t,i),i},e.FromRotationMatrixToRef=function(e,t){var i,r=e.m,n=r[0],o=r[4],s=r[8],a=r[1],h=r[5],l=r[9],c=r[2],u=r[6],f=r[10],d=n+h+f;d>0?(i=.5/Math.sqrt(d+1),t.w=.25/i,t.x=(u-l)*i,t.y=(s-c)*i,t.z=(a-o)*i):n>h&&n>f?(i=2*Math.sqrt(1+n-h-f),t.w=(u-l)/i,t.x=.25*i,t.y=(o+a)/i,t.z=(s+c)/i):h>f?(i=2*Math.sqrt(1+h-n-f),t.w=(s-c)/i,t.x=(o+a)/i,t.y=.25*i,t.z=(l+u)/i):(i=2*Math.sqrt(1+f-n-h),t.w=(a-o)/i,t.x=(s+c)/i,t.y=(l+u)/i,t.z=.25*i)},e.Inverse=function(t){return new e(-t.x,-t.y,-t.z,t.w)},e.Identity=function(){return new e(0,0,0,1)},e.RotationAxis=function(t,i){var r=new e,n=Math.sin(i/2);return r.w=Math.cos(i/2),r.x=t.x*n,r.y=t.y*n,r.z=t.z*n,r},e.FromArray=function(t,i){return i||(i=0),new e(t[i],t[i+1],t[i+2],t[i+3])},e.RotationYawPitchRoll=function(t,i,r){var n=new e;return e.RotationYawPitchRollToRef(t,i,r,n),n},e.RotationYawPitchRollToRef=function(e,t,i,r){var n=.5*i,o=.5*t,s=.5*e,a=Math.sin(n),h=Math.cos(n),l=Math.sin(o),c=Math.cos(o),u=Math.sin(s),f=Math.cos(s);r.x=f*l*h+u*c*a,r.y=u*c*h-f*l*a,r.z=f*c*a-u*l*h,r.w=f*c*h+u*l*a},e.RotationAlphaBetaGamma=function(t,i,r){var n=new e;return e.RotationAlphaBetaGammaToRef(t,i,r,n),n},e.RotationAlphaBetaGammaToRef=function(e,t,i,r){var n=.5*(i+e),o=.5*(i-e),s=.5*t;r.x=Math.cos(o)*Math.sin(s),r.y=Math.sin(o)*Math.sin(s),r.z=Math.sin(n)*Math.cos(s),r.w=Math.cos(n)*Math.cos(s)},e.Slerp=function(t,i,r){var n,o,s=r,a=t.x*i.x+t.y*i.y+t.z*i.z+t.w*i.w,h=!1;if(0>a&&(h=!0,a=-a),a>.999999)o=1-s,n=h?-s:s;else{var l=Math.acos(a),c=1/Math.sin(l);o=Math.sin((1-s)*l)*c,n=h?-Math.sin(s*l)*c:Math.sin(s*l)*c}return new e(o*t.x+n*i.x,o*t.y+n*i.y,o*t.z+n*i.z,o*t.w+n*i.w)},e}();e.Quaternion=s;var a=function(){function t(){this.m=new Float32Array(16)}return t.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},t.prototype.determinant=function(){var e=this.m[10]*this.m[15]-this.m[11]*this.m[14],t=this.m[9]*this.m[15]-this.m[11]*this.m[13],i=this.m[9]*this.m[14]-this.m[10]*this.m[13],r=this.m[8]*this.m[15]-this.m[11]*this.m[12],n=this.m[8]*this.m[14]-this.m[10]*this.m[12],o=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*e-this.m[6]*t+this.m[7]*i)-this.m[1]*(this.m[4]*e-this.m[6]*r+this.m[7]*n)+this.m[2]*(this.m[4]*t-this.m[5]*r+this.m[7]*o)-this.m[3]*(this.m[4]*i-this.m[5]*n+this.m[6]*o)},t.prototype.toArray=function(){return this.m},t.prototype.asArray=function(){return this.toArray()},t.prototype.invert=function(){return this.invertToRef(this),this},t.prototype.reset=function(){for(var e=0;16>e;e++)this.m[e]=0;return this},t.prototype.add=function(e){var i=new t;return this.addToRef(e,i),i},t.prototype.addToRef=function(e,t){for(var i=0;16>i;i++)t.m[i]=this.m[i]+e.m[i];return this},t.prototype.addToSelf=function(e){for(var t=0;16>t;t++)this.m[t]+=e.m[t];return this},t.prototype.invertToRef=function(e){var t=this.m[0],i=this.m[1],r=this.m[2],n=this.m[3],o=this.m[4],s=this.m[5],a=this.m[6],h=this.m[7],l=this.m[8],c=this.m[9],u=this.m[10],f=this.m[11],d=this.m[12],p=this.m[13],m=this.m[14],g=this.m[15],_=u*g-f*m,v=c*g-f*p,y=c*m-u*p,x=l*g-f*d,M=l*m-u*d,S=l*p-c*d,b=s*_-a*v+h*y,A=-(o*_-a*x+h*M),T=o*v-s*x+h*S,E=-(o*y-s*M+a*S),P=1/(t*b+i*A+r*T+n*E),D=a*g-h*m,C=s*g-h*p,I=s*m-a*p,w=o*g-h*d,R=o*m-a*d,L=o*p-s*d,O=a*f-h*u,B=s*f-h*c,F=s*u-a*c,V=o*f-h*l,N=o*u-a*l,z=o*c-s*l;return e.m[0]=b*P,e.m[4]=A*P,e.m[8]=T*P,e.m[12]=E*P,e.m[1]=-(i*_-r*v+n*y)*P,e.m[5]=(t*_-r*x+n*M)*P,e.m[9]=-(t*v-i*x+n*S)*P,e.m[13]=(t*y-i*M+r*S)*P,e.m[2]=(i*D-r*C+n*I)*P,e.m[6]=-(t*D-r*w+n*R)*P,e.m[10]=(t*C-i*w+n*L)*P,e.m[14]=-(t*I-i*R+r*L)*P,e.m[3]=-(i*O-r*B+n*F)*P,e.m[7]=(t*O-r*V+n*N)*P,e.m[11]=-(t*B-i*V+n*z)*P,e.m[15]=(t*F-i*N+r*z)*P,this},t.prototype.invertToRefSIMD=function(e){var t,i,r,n,o,s,a,h,l,c,u=this.m,f=e.m,d=SIMD.float32x4.load(u,0),p=SIMD.float32x4.load(u,4),m=SIMD.float32x4.load(u,8),g=SIMD.float32x4.load(u,12);return o=SIMD.float32x4.shuffle(d,p,0,1,4,5),i=SIMD.float32x4.shuffle(m,g,0,1,4,5),t=SIMD.float32x4.shuffle(o,i,0,2,4,6),i=SIMD.float32x4.shuffle(i,o,1,3,5,7),o=SIMD.float32x4.shuffle(d,p,2,3,6,7),n=SIMD.float32x4.shuffle(m,g,2,3,6,7),r=SIMD.float32x4.shuffle(o,n,0,2,4,6),n=SIMD.float32x4.shuffle(n,o,1,3,5,7),o=SIMD.float32x4.mul(r,n),o=SIMD.float32x4.swizzle(o,1,0,3,2),s=SIMD.float32x4.mul(i,o),a=SIMD.float32x4.mul(t,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(SIMD.float32x4.mul(i,o),s),a=SIMD.float32x4.sub(SIMD.float32x4.mul(t,o),a),a=SIMD.float32x4.swizzle(a,2,3,0,1),o=SIMD.float32x4.mul(i,r),o=SIMD.float32x4.swizzle(o,1,0,3,2),s=SIMD.float32x4.add(SIMD.float32x4.mul(n,o),s),l=SIMD.float32x4.mul(t,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(s,SIMD.float32x4.mul(n,o)),l=SIMD.float32x4.sub(SIMD.float32x4.mul(t,o),l),l=SIMD.float32x4.swizzle(l,2,3,0,1),o=SIMD.float32x4.mul(SIMD.float32x4.swizzle(i,2,3,0,1),n),o=SIMD.float32x4.swizzle(o,1,0,3,2),r=SIMD.float32x4.swizzle(r,2,3,0,1),s=SIMD.float32x4.add(SIMD.float32x4.mul(r,o),s),h=SIMD.float32x4.mul(t,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(s,SIMD.float32x4.mul(r,o)),h=SIMD.float32x4.sub(SIMD.float32x4.mul(t,o),h),h=SIMD.float32x4.swizzle(h,2,3,0,1),o=SIMD.float32x4.mul(t,i),o=SIMD.float32x4.swizzle(o,1,0,3,2),h=SIMD.float32x4.add(SIMD.float32x4.mul(n,o),h),l=SIMD.float32x4.sub(SIMD.float32x4.mul(r,o),l),o=SIMD.float32x4.swizzle(o,2,3,0,1),h=SIMD.float32x4.sub(SIMD.float32x4.mul(n,o),h),l=SIMD.float32x4.sub(l,SIMD.float32x4.mul(r,o)),o=SIMD.float32x4.mul(t,n),o=SIMD.float32x4.swizzle(o,1,0,3,2),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(r,o)),h=SIMD.float32x4.add(SIMD.float32x4.mul(i,o),h),o=SIMD.float32x4.swizzle(o,2,3,0,1),a=SIMD.float32x4.add(SIMD.float32x4.mul(r,o),a),h=SIMD.float32x4.sub(h,SIMD.float32x4.mul(i,o)),o=SIMD.float32x4.mul(t,r),o=SIMD.float32x4.swizzle(o,1,0,3,2),a=SIMD.float32x4.add(SIMD.float32x4.mul(n,o),a),l=SIMD.float32x4.sub(l,SIMD.float32x4.mul(i,o)),o=SIMD.float32x4.swizzle(o,2,3,0,1),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(n,o)),l=SIMD.float32x4.add(SIMD.float32x4.mul(i,o),l),c=SIMD.float32x4.mul(t,s),c=SIMD.float32x4.add(SIMD.float32x4.swizzle(c,2,3,0,1),c),c=SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,0,3,2),c),o=SIMD.float32x4.reciprocalApproximation(c),c=SIMD.float32x4.sub(SIMD.float32x4.add(o,o),SIMD.float32x4.mul(c,SIMD.float32x4.mul(o,o))),c=SIMD.float32x4.swizzle(c,0,0,0,0),s=SIMD.float32x4.mul(c,s),a=SIMD.float32x4.mul(c,a),h=SIMD.float32x4.mul(c,h),l=SIMD.float32x4.mul(c,l),SIMD.float32x4.store(f,0,s),SIMD.float32x4.store(f,4,a),SIMD.float32x4.store(f,8,h),SIMD.float32x4.store(f,12,l),this},t.prototype.setTranslation=function(e){return this.m[12]=e.x,this.m[13]=e.y,this.m[14]=e.z,this},t.prototype.multiply=function(e){var i=new t;return this.multiplyToRef(e,i),i},t.prototype.copyFrom=function(e){for(var t=0;16>t;t++)this.m[t]=e.m[t];return this},t.prototype.copyToArray=function(e,t){void 0===t&&(t=0);for(var i=0;16>i;i++)e[t+i]=this.m[i];return this},t.prototype.multiplyToRef=function(e,t){return this.multiplyToArray(e,t.m,0),this},t.prototype.multiplyToArray=function(e,t,i){var r=this.m[0],n=this.m[1],o=this.m[2],s=this.m[3],a=this.m[4],h=this.m[5],l=this.m[6],c=this.m[7],u=this.m[8],f=this.m[9],d=this.m[10],p=this.m[11],m=this.m[12],g=this.m[13],_=this.m[14],v=this.m[15],y=e.m[0],x=e.m[1],M=e.m[2],S=e.m[3],b=e.m[4],A=e.m[5],T=e.m[6],E=e.m[7],P=e.m[8],D=e.m[9],C=e.m[10],I=e.m[11],w=e.m[12],R=e.m[13],L=e.m[14],O=e.m[15];return t[i]=r*y+n*b+o*P+s*w,t[i+1]=r*x+n*A+o*D+s*R,t[i+2]=r*M+n*T+o*C+s*L,t[i+3]=r*S+n*E+o*I+s*O,t[i+4]=a*y+h*b+l*P+c*w,t[i+5]=a*x+h*A+l*D+c*R,t[i+6]=a*M+h*T+l*C+c*L,t[i+7]=a*S+h*E+l*I+c*O,t[i+8]=u*y+f*b+d*P+p*w,t[i+9]=u*x+f*A+d*D+p*R,t[i+10]=u*M+f*T+d*C+p*L,t[i+11]=u*S+f*E+d*I+p*O,t[i+12]=m*y+g*b+_*P+v*w,t[i+13]=m*x+g*A+_*D+v*R,t[i+14]=m*M+g*T+_*C+v*L,t[i+15]=m*S+g*E+_*I+v*O,this},t.prototype.multiplyToArraySIMD=function(e,t,i){void 0===i&&(i=0);var r=this.m,n=e.m,o=SIMD.float32x4.load(n,0),s=SIMD.float32x4.load(n,4),a=SIMD.float32x4.load(n,8),h=SIMD.float32x4.load(n,12),l=SIMD.float32x4.load(r,0);
  
  SIMD.float32x4.store(t,i+0,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,3,3,3,3),h)))));var c=SIMD.float32x4.load(r,4);SIMD.float32x4.store(t,i+4,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,3,3,3,3),h)))));var u=SIMD.float32x4.load(r,8);SIMD.float32x4.store(t,i+8,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,3,3,3,3),h)))));var f=SIMD.float32x4.load(r,12);SIMD.float32x4.store(t,i+12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,0,0,0,0),o),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,1,1,1,1),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,3,3,3,3),h)))))},t.prototype.equals=function(e){return e&&this.m[0]===e.m[0]&&this.m[1]===e.m[1]&&this.m[2]===e.m[2]&&this.m[3]===e.m[3]&&this.m[4]===e.m[4]&&this.m[5]===e.m[5]&&this.m[6]===e.m[6]&&this.m[7]===e.m[7]&&this.m[8]===e.m[8]&&this.m[9]===e.m[9]&&this.m[10]===e.m[10]&&this.m[11]===e.m[11]&&this.m[12]===e.m[12]&&this.m[13]===e.m[13]&&this.m[14]===e.m[14]&&this.m[15]===e.m[15]},t.prototype.clone=function(){return t.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])},t.prototype.decompose=function(i,r,n){n.x=this.m[12],n.y=this.m[13],n.z=this.m[14];var o=e.Tools.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,a=e.Tools.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,h=e.Tools.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(i.x=o*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),i.y=a*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),i.z=h*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===i.x||0===i.y||0===i.z)return r.x=0,r.y=0,r.z=0,r.w=1,!1;var l=t.FromValues(this.m[0]/i.x,this.m[1]/i.x,this.m[2]/i.x,0,this.m[4]/i.y,this.m[5]/i.y,this.m[6]/i.y,0,this.m[8]/i.z,this.m[9]/i.z,this.m[10]/i.z,0,0,0,0,1);return s.FromRotationMatrixToRef(l,r),!0},t.FromArray=function(e,i){var r=new t;return i||(i=0),t.FromArrayToRef(e,i,r),r},t.FromArrayToRef=function(e,t,i){for(var r=0;16>r;r++)i.m[r]=e[r+t]},t.FromFloat32ArrayToRefScaled=function(e,t,i,r){for(var n=0;16>n;n++)r.m[n]=e[n+t]*i},t.FromValuesToRef=function(e,t,i,r,n,o,s,a,h,l,c,u,f,d,p,m,g){g.m[0]=e,g.m[1]=t,g.m[2]=i,g.m[3]=r,g.m[4]=n,g.m[5]=o,g.m[6]=s,g.m[7]=a,g.m[8]=h,g.m[9]=l,g.m[10]=c,g.m[11]=u,g.m[12]=f,g.m[13]=d,g.m[14]=p,g.m[15]=m},t.FromValues=function(e,i,r,n,o,s,a,h,l,c,u,f,d,p,m,g){var _=new t;return _.m[0]=e,_.m[1]=i,_.m[2]=r,_.m[3]=n,_.m[4]=o,_.m[5]=s,_.m[6]=a,_.m[7]=h,_.m[8]=l,_.m[9]=c,_.m[10]=u,_.m[11]=f,_.m[12]=d,_.m[13]=p,_.m[14]=m,_.m[15]=g,_},t.Compose=function(e,i,r){var n=t.FromValues(e.x,0,0,0,0,e.y,0,0,0,0,e.z,0,0,0,0,1),o=t.Identity();return i.toRotationMatrix(o),n=n.multiply(o),n.setTranslation(r),n},t.Identity=function(){return t.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},t.IdentityToRef=function(e){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,e)},t.Zero=function(){return t.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},t.RotationX=function(e){var i=new t;return t.RotationXToRef(e,i),i},t.Invert=function(e){var i=new t;return e.invertToRef(i),i},t.RotationXToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[0]=1,t.m[15]=1,t.m[5]=r,t.m[10]=r,t.m[9]=-i,t.m[6]=i,t.m[1]=0,t.m[2]=0,t.m[3]=0,t.m[4]=0,t.m[7]=0,t.m[8]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationY=function(e){var i=new t;return t.RotationYToRef(e,i),i},t.RotationYToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[5]=1,t.m[15]=1,t.m[0]=r,t.m[2]=-i,t.m[8]=i,t.m[10]=r,t.m[1]=0,t.m[3]=0,t.m[4]=0,t.m[6]=0,t.m[7]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationZ=function(e){var i=new t;return t.RotationZToRef(e,i),i},t.RotationZToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[10]=1,t.m[15]=1,t.m[0]=r,t.m[1]=i,t.m[4]=-i,t.m[5]=r,t.m[2]=0,t.m[3]=0,t.m[6]=0,t.m[7]=0,t.m[8]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},t.RotationAxis=function(e,i){var r=Math.sin(-i),n=Math.cos(-i),o=1-n;e.normalize();var s=t.Zero();return s.m[0]=e.x*e.x*o+n,s.m[1]=e.x*e.y*o-e.z*r,s.m[2]=e.x*e.z*o+e.y*r,s.m[3]=0,s.m[4]=e.y*e.x*o+e.z*r,s.m[5]=e.y*e.y*o+n,s.m[6]=e.y*e.z*o-e.x*r,s.m[7]=0,s.m[8]=e.z*e.x*o-e.y*r,s.m[9]=e.z*e.y*o+e.x*r,s.m[10]=e.z*e.z*o+n,s.m[11]=0,s.m[15]=1,s},t.RotationYawPitchRoll=function(e,i,r){var n=new t;return t.RotationYawPitchRollToRef(e,i,r,n),n},t.RotationYawPitchRollToRef=function(e,t,i,r){s.RotationYawPitchRollToRef(e,t,i,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(r)},t.Scaling=function(e,i,r){var n=t.Zero();return t.ScalingToRef(e,i,r,n),n},t.ScalingToRef=function(e,t,i,r){r.m[0]=e,r.m[1]=0,r.m[2]=0,r.m[3]=0,r.m[4]=0,r.m[5]=t,r.m[6]=0,r.m[7]=0,r.m[8]=0,r.m[9]=0,r.m[10]=i,r.m[11]=0,r.m[12]=0,r.m[13]=0,r.m[14]=0,r.m[15]=1},t.Translation=function(e,i,r){var n=t.Identity();return t.TranslationToRef(e,i,r,n),n},t.TranslationToRef=function(e,i,r,n){t.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,e,i,r,1,n)},t.LookAtLH=function(e,i,r){var n=t.Zero();return t.LookAtLHToRef(e,i,r,n),n},t.LookAtLHToRef=function(e,i,r,o){i.subtractToRef(e,this._zAxis),this._zAxis.normalize(),n.CrossToRef(r,this._zAxis,this._xAxis),this._xAxis.normalize(),n.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var s=-n.Dot(this._xAxis,e),a=-n.Dot(this._yAxis,e),h=-n.Dot(this._zAxis,e);return t.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,s,a,h,1,o)},t.LookAtLHToRefSIMD=function(e,t,i,r){var n=r.m,o=SIMD.float32x4(t.x,t.y,t.z,0),s=SIMD.float32x4(e.x,e.y,e.z,0),a=SIMD.float32x4(i.x,i.y,i.z,0),h=SIMD.float32x4.sub(o,s),l=SIMD.float32x4.mul(h,h);l=SIMD.float32x4.add(l,SIMD.float32x4.add(SIMD.float32x4.swizzle(l,1,2,0,3),SIMD.float32x4.swizzle(l,2,0,1,3))),h=SIMD.float32x4.mul(h,SIMD.float32x4.reciprocalSqrtApproximation(l)),l=SIMD.float32x4.mul(a,a),l=SIMD.float32x4.add(l,SIMD.float32x4.add(SIMD.float32x4.swizzle(l,1,2,0,3),SIMD.float32x4.swizzle(l,2,0,1,3))),a=SIMD.float32x4.mul(a,SIMD.float32x4.reciprocalSqrtApproximation(l));var c=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(h,1,2,0,3),SIMD.float32x4.swizzle(a,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(h,2,0,1,3),SIMD.float32x4.swizzle(a,1,2,0,3)));l=SIMD.float32x4.mul(c,c),l=SIMD.float32x4.add(l,SIMD.float32x4.add(SIMD.float32x4.swizzle(l,1,2,0,3),SIMD.float32x4.swizzle(l,2,0,1,3))),c=SIMD.float32x4.mul(c,SIMD.float32x4.reciprocalSqrtApproximation(l));var u=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(h,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(c,2,0,1,3),SIMD.float32x4.swizzle(h,1,2,0,3)));l=SIMD.float32x4.mul(c,c),l=SIMD.float32x4.add(l,SIMD.float32x4.add(SIMD.float32x4.swizzle(l,1,2,0,3),SIMD.float32x4.swizzle(l,2,0,1,3))),c=SIMD.float32x4.mul(c,SIMD.float32x4.reciprocalSqrtApproximation(l));var f=SIMD.float32x4.splat(0);c=SIMD.float32x4.neg(c);var d=SIMD.float32x4.shuffle(c,u,0,1,4,5),p=SIMD.float32x4.shuffle(h,f,0,1,4,5),m=SIMD.float32x4.shuffle(d,p,0,2,4,6),g=SIMD.float32x4.shuffle(d,p,1,3,5,7);d=SIMD.float32x4.shuffle(c,u,2,3,6,7),p=SIMD.float32x4.shuffle(h,f,2,3,6,7);var _=SIMD.float32x4.shuffle(d,p,0,2,4,6),v=SIMD.float32x4(0,0,0,1),y=SIMD.float32x4(1,0,0,0),x=SIMD.float32x4(0,1,0,0),M=SIMD.float32x4(0,0,1,0),S=SIMD.float32x4.neg(s);S=SIMD.float32x4.withW(S,1),SIMD.float32x4.store(n,0,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,1,1,1,1),g),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,2,2,2,2),_),SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,3,3,3,3),v))))),SIMD.float32x4.store(n,4,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,1,1,1,1),g),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,2,2,2,2),_),SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,3,3,3,3),v))))),SIMD.float32x4.store(n,8,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(M,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(M,1,1,1,1),g),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(M,2,2,2,2),_),SIMD.float32x4.mul(SIMD.float32x4.swizzle(M,3,3,3,3),v))))),SIMD.float32x4.store(n,12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(S,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(S,1,1,1,1),g),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(S,2,2,2,2),_),SIMD.float32x4.mul(SIMD.float32x4.swizzle(S,3,3,3,3),v)))))},t.OrthoLH=function(e,i,r,n){var o=t.Zero();return t.OrthoLHToRef(e,i,r,n,o),o},t.OrthoLHToRef=function(e,i,r,n,o){var s=2/e,a=2/i,h=1/(n-r),l=r/(r-n);t.FromValuesToRef(s,0,0,0,0,a,0,0,0,0,h,0,0,0,l,1,o)},t.OrthoOffCenterLH=function(e,i,r,n,o,s){var a=t.Zero();return t.OrthoOffCenterLHToRef(e,i,r,n,o,s,a),a},t.OrthoOffCenterLHToRef=function(e,t,i,r,n,o,s){s.m[0]=2/(t-e),s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=2/(r-i),s.m[4]=s.m[6]=s.m[7]=0,s.m[10]=-1/(n-o),s.m[8]=s.m[9]=s.m[11]=0,s.m[12]=(e+t)/(e-t),s.m[13]=(r+i)/(i-r),s.m[14]=n/(n-o),s.m[15]=1},t.PerspectiveLH=function(e,i,r,n){var o=t.Zero();return o.m[0]=2*r/e,o.m[1]=o.m[2]=o.m[3]=0,o.m[5]=2*r/i,o.m[4]=o.m[6]=o.m[7]=0,o.m[10]=-n/(r-n),o.m[8]=o.m[9]=0,o.m[11]=1,o.m[12]=o.m[13]=o.m[15]=0,o.m[14]=r*n/(r-n),o},t.PerspectiveFovLH=function(e,i,r,n){var o=t.Zero();return t.PerspectiveFovLHToRef(e,i,r,n,o),o},t.PerspectiveFovLHToRef=function(t,i,r,n,o,s){void 0===s&&(s=e.Camera.FOVMODE_VERTICAL_FIXED);var a=1/Math.tan(.5*t),h=s===e.Camera.FOVMODE_VERTICAL_FIXED;o.m[0]=h?a/i:a,o.m[1]=o.m[2]=o.m[3]=0,o.m[5]=h?a:a*i,o.m[4]=o.m[6]=o.m[7]=0,o.m[8]=o.m[9]=0,o.m[10]=-n/(r-n),o.m[11]=1,o.m[12]=o.m[13]=o.m[15]=0,o.m[14]=r*n/(r-n)},t.GetFinalMatrix=function(e,i,r,n,o,s){var a=e.width,h=e.height,l=e.x,c=e.y,u=t.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,s-o,0,l+a/2,h/2+c,o,1);return i.multiply(r).multiply(n).multiply(u)},t.GetAsMatrix2x2=function(e){return new Float32Array([e.m[0],e.m[1],e.m[4],e.m[5]])},t.GetAsMatrix3x3=function(e){return new Float32Array([e.m[0],e.m[1],e.m[2],e.m[4],e.m[5],e.m[6],e.m[8],e.m[9],e.m[10]])},t.Transpose=function(e){var i=new t;return i.m[0]=e.m[0],i.m[1]=e.m[4],i.m[2]=e.m[8],i.m[3]=e.m[12],i.m[4]=e.m[1],i.m[5]=e.m[5],i.m[6]=e.m[9],i.m[7]=e.m[13],i.m[8]=e.m[2],i.m[9]=e.m[6],i.m[10]=e.m[10],i.m[11]=e.m[14],i.m[12]=e.m[3],i.m[13]=e.m[7],i.m[14]=e.m[11],i.m[15]=e.m[15],i},t.Reflection=function(e){var i=new t;return t.ReflectionToRef(e,i),i},t.ReflectionToRef=function(e,t){e.normalize();var i=e.normal.x,r=e.normal.y,n=e.normal.z,o=-2*i,s=-2*r,a=-2*n;t.m[0]=o*i+1,t.m[1]=s*i,t.m[2]=a*i,t.m[3]=0,t.m[4]=o*r,t.m[5]=s*r+1,t.m[6]=a*r,t.m[7]=0,t.m[8]=o*n,t.m[9]=s*n,t.m[10]=a*n+1,t.m[11]=0,t.m[12]=o*e.d,t.m[13]=s*e.d,t.m[14]=a*e.d,t.m[15]=1},t._tempQuaternion=new s,t._xAxis=n.Zero(),t._yAxis=n.Zero(),t._zAxis=n.Zero(),t}();e.Matrix=a;var h=function(){function e(e,t,i,r){this.normal=new n(e,t,i),this.d=r}return e.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},e.prototype.clone=function(){return new e(this.normal.x,this.normal.y,this.normal.z,this.d)},e.prototype.normalize=function(){var e=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),t=0;return 0!==e&&(t=1/e),this.normal.x*=t,this.normal.y*=t,this.normal.z*=t,this.d*=t,this},e.prototype.transform=function(t){var i=a.Transpose(t),r=this.normal.x,n=this.normal.y,o=this.normal.z,s=this.d,h=r*i.m[0]+n*i.m[1]+o*i.m[2]+s*i.m[3],l=r*i.m[4]+n*i.m[5]+o*i.m[6]+s*i.m[7],c=r*i.m[8]+n*i.m[9]+o*i.m[10]+s*i.m[11],u=r*i.m[12]+n*i.m[13]+o*i.m[14]+s*i.m[15];return new e(h,l,c,u)},e.prototype.dotCoordinate=function(e){return this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z+this.d},e.prototype.copyFromPoints=function(e,t,i){var r,n=t.x-e.x,o=t.y-e.y,s=t.z-e.z,a=i.x-e.x,h=i.y-e.y,l=i.z-e.z,c=o*l-s*h,u=s*a-n*l,f=n*h-o*a,d=Math.sqrt(c*c+u*u+f*f);return r=0!==d?1/d:0,this.normal.x=c*r,this.normal.y=u*r,this.normal.z=f*r,this.d=-(this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z),this},e.prototype.isFrontFacingTo=function(e,t){var i=n.Dot(this.normal,e);return t>=i},e.prototype.signedDistanceTo=function(e){return n.Dot(e,this.normal)+this.d},e.FromArray=function(t){return new e(t[0],t[1],t[2],t[3])},e.FromPoints=function(t,i,r){var n=new e(0,0,0,0);return n.copyFromPoints(t,i,r),n},e.FromPositionAndNormal=function(t,i){var r=new e(0,0,0,0);return i.normalize(),r.normal=i,r.d=-(i.x*t.x+i.y*t.y+i.z*t.z),r},e.SignedDistanceToPlaneFromPositionAndNormal=function(e,t,i){var r=-(t.x*e.x+t.y*e.y+t.z*e.z);return n.Dot(i,t)+r},e}();e.Plane=h;var l=function(){function e(e,t,i,r){this.x=e,this.y=t,this.width=i,this.height=r}return e.prototype.toGlobal=function(t){var i=t.getRenderWidth(),r=t.getRenderHeight();return new e(this.x*i,this.y*r,this.width*i,this.height*r)},e}();e.Viewport=l;var c=function(){function e(){}return e.GetPlanes=function(t){for(var i=[],r=0;6>r;r++)i.push(new h(0,0,0,0));return e.GetPlanesToRef(t,i),i},e.GetPlanesToRef=function(e,t){t[0].normal.x=e.m[3]+e.m[2],t[0].normal.y=e.m[7]+e.m[6],t[0].normal.z=e.m[11]+e.m[10],t[0].d=e.m[15]+e.m[14],t[0].normalize(),t[1].normal.x=e.m[3]-e.m[2],t[1].normal.y=e.m[7]-e.m[6],t[1].normal.z=e.m[11]-e.m[10],t[1].d=e.m[15]-e.m[14],t[1].normalize(),t[2].normal.x=e.m[3]+e.m[0],t[2].normal.y=e.m[7]+e.m[4],t[2].normal.z=e.m[11]+e.m[8],t[2].d=e.m[15]+e.m[12],t[2].normalize(),t[3].normal.x=e.m[3]-e.m[0],t[3].normal.y=e.m[7]-e.m[4],t[3].normal.z=e.m[11]-e.m[8],t[3].d=e.m[15]-e.m[12],t[3].normalize(),t[4].normal.x=e.m[3]-e.m[1],t[4].normal.y=e.m[7]-e.m[5],t[4].normal.z=e.m[11]-e.m[9],t[4].d=e.m[15]-e.m[13],t[4].normalize(),t[5].normal.x=e.m[3]+e.m[1],t[5].normal.y=e.m[7]+e.m[5],t[5].normal.z=e.m[11]+e.m[9],t[5].d=e.m[15]+e.m[13],t[5].normalize()},e}();e.Frustum=c;var u=function(){function t(e,t,i){void 0===i&&(i=Number.MAX_VALUE),this.origin=e,this.direction=t,this.length=i}return t.prototype.intersectsBoxMinMax=function(e,t){var i,r,n,o,s=0,a=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.x<e.x||this.origin.x>t.x)return!1}else if(i=1/this.direction.x,r=(e.x-this.origin.x)*i,n=(t.x-this.origin.x)*i,n===-(1/0)&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;if(Math.abs(this.direction.y)<1e-7){if(this.origin.y<e.y||this.origin.y>t.y)return!1}else if(i=1/this.direction.y,r=(e.y-this.origin.y)*i,n=(t.y-this.origin.y)*i,n===-(1/0)&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.z<e.z||this.origin.z>t.z)return!1}else if(i=1/this.direction.z,r=(e.z-this.origin.z)*i,n=(t.z-this.origin.z)*i,n===-(1/0)&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;return!0},t.prototype.intersectsBox=function(e){return this.intersectsBoxMinMax(e.minimum,e.maximum)},t.prototype.intersectsSphere=function(e){var t=e.center.x-this.origin.x,i=e.center.y-this.origin.y,r=e.center.z-this.origin.z,n=t*t+i*i+r*r,o=e.radius*e.radius;if(o>=n)return!0;var s=t*this.direction.x+i*this.direction.y+r*this.direction.z;if(0>s)return!1;var a=n-s*s;return o>=a},t.prototype.intersectsTriangle=function(t,i,r){this._edge1||(this._edge1=n.Zero(),this._edge2=n.Zero(),this._pvec=n.Zero(),this._tvec=n.Zero(),this._qvec=n.Zero()),i.subtractToRef(t,this._edge1),r.subtractToRef(t,this._edge2),n.CrossToRef(this.direction,this._edge2,this._pvec);var o=n.Dot(this._edge1,this._pvec);if(0===o)return null;var s=1/o;this.origin.subtractToRef(t,this._tvec);var a=n.Dot(this._tvec,this._pvec)*s;if(0>a||a>1)return null;n.CrossToRef(this._tvec,this._edge1,this._qvec);var h=n.Dot(this.direction,this._qvec)*s;if(0>h||a+h>1)return null;var l=n.Dot(this._edge2,this._qvec)*s;return l>this.length?null:new e.IntersectionInfo(a,h,l)},t.CreateNew=function(e,i,r,o,s,a,h){var l=n.Unproject(new n(e,i,0),r,o,s,a,h),c=n.Unproject(new n(e,i,1),r,o,s,a,h),u=c.subtract(l);return u.normalize(),new t(l,u)},t.CreateNewFromTo=function(e,i,r){void 0===r&&(r=a.Identity());var n=i.subtract(e),o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z);return n.normalize(),t.Transform(new t(e,n,o),r)},t.Transform=function(e,i){var r=n.TransformCoordinates(e.origin,i),o=n.TransformNormal(e.direction,i);return new t(r,o,e.length)},t}();e.Ray=u,function(e){e[e.LOCAL=0]="LOCAL",e[e.WORLD=1]="WORLD"}(e.Space||(e.Space={}));var f=(e.Space,function(){function e(){}return e.X=new n(1,0,0),e.Y=new n(0,1,0),e.Z=new n(0,0,1),e}());e.Axis=f;var d=function(){function e(){}return e.interpolate=function(e,t,i,r,n){for(var o=1-3*r+3*t,s=3*r-6*t,a=3*t,h=e,l=0;5>l;l++){var c=h*h,u=c*h,f=o*u+s*c+a*h,d=1/(3*o*c+2*s*h+a);h-=(f-e)*d,h=Math.min(1,Math.max(0,h))}return 3*Math.pow(1-h,2)*h*i+3*(1-h)*Math.pow(h,2)*n+Math.pow(h,3)},e}();e.BezierCurve=d,function(e){e[e.CW=0]="CW",e[e.CCW=1]="CCW"}(e.Orientation||(e.Orientation={}));var p=e.Orientation,m=function(){function e(e){var t=this;this.degrees=function(){return 180*t._radians/Math.PI},this.radians=function(){return t._radians},this._radians=e,this._radians<0&&(this._radians+=2*Math.PI)}return e.BetweenTwoPoints=function(t,i){var r=i.subtract(t),n=Math.atan2(r.y,r.x);return new e(n)},e.FromRadians=function(t){return new e(t)},e.FromDegrees=function(t){return new e(t*Math.PI/180)},e}();e.Angle=m;var g=function(){function e(e,t,i){this.startPoint=e,this.midPoint=t,this.endPoint=i;var n=Math.pow(t.x,2)+Math.pow(t.y,2),o=(Math.pow(e.x,2)+Math.pow(e.y,2)-n)/2,s=(n-Math.pow(i.x,2)-Math.pow(i.y,2))/2,a=(e.x-t.x)*(t.y-i.y)-(t.x-i.x)*(e.y-t.y);this.centerPoint=new r((o*(t.y-i.y)-s*(e.y-t.y))/a,((e.x-t.x)*s-(t.x-i.x)*o)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=m.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),l=m.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),c=m.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();l-h>180&&(l-=360),-180>l-h&&(l+=360),c-l>180&&(c-=360),-180>c-l&&(c+=360),this.orientation=0>l-h?p.CW:p.CCW,this.angle=m.FromDegrees(this.orientation===p.CW?h-c:c-h)}return e}();e.Arc2=g;var _=function(){function e(e){this.path=e,this._onchange=new Array,this.value=0,this.animations=new Array}return e.prototype.getPoint=function(){var e=this.path.getPointAtLengthPosition(this.value);return new n(e.x,0,e.y)},e.prototype.moveAhead=function(e){return void 0===e&&(e=.002),this.move(e),this},e.prototype.moveBack=function(e){return void 0===e&&(e=.002),this.move(-e),this},e.prototype.move=function(e){if(Math.abs(e)>1)throw"step size should be less than 1.";return this.value+=e,this.ensureLimits(),this.raiseOnChange(),this},e.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},e.prototype.markAsDirty=function(e){return this.ensureLimits(),this.raiseOnChange(),this},e.prototype.raiseOnChange=function(){var e=this;return this._onchange.forEach(function(t){return t(e)}),this},e.prototype.onchange=function(e){return this._onchange.push(e),this},e}();e.PathCursor=_;var v=function(){function t(e,t){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new r(e,t))}return t.prototype.addLineTo=function(t,i){if(closed)return e.Tools.Error("cannot add lines to closed paths"),this;var n=new r(t,i),o=this._points[this._points.length-1];return this._points.push(n),this._length+=n.subtract(o).length(),this},t.prototype.addArcTo=function(t,i,n,o,s){if(void 0===s&&(s=36),closed)return e.Tools.Error("cannot add arcs to closed paths"),this;var a=this._points[this._points.length-1],h=new r(t,i),l=new r(n,o),c=new g(a,h,l),u=c.angle.radians()/s;c.orientation===p.CW&&(u*=-1);for(var f=c.startAngle.radians()+u,d=0;s>d;d++){var m=Math.cos(f)*c.radius+c.centerPoint.x,_=Math.sin(f)*c.radius+c.centerPoint.y;this.addLineTo(m,_),f+=u}return this},t.prototype.close=function(){return this.closed=!0,this},t.prototype.length=function(){var e=this._length;if(!this.closed){var t=this._points[this._points.length-1],i=this._points[0];e+=i.subtract(t).length()}return e},t.prototype.getPoints=function(){return this._points},t.prototype.getPointAtLengthPosition=function(t){if(0>t||t>1)return e.Tools.Error("normalized length position should be between 0 and 1."),r.Zero();for(var i=t*this.length(),n=0,o=0;o<this._points.length;o++){var s=(o+1)%this._points.length,a=this._points[o],h=this._points[s],l=h.subtract(a),c=l.length()+n;if(i>=n&&c>=i){var u=l.normalize(),f=i-n;return new r(a.x+u.x*f,a.y+u.y*f)}n=c}return e.Tools.Error("internal error"),r.Zero()},t.StartingAt=function(e,i){return new t(e,i)},t}();e.Path2=v;var y=function(){function t(e,t,i){this.path=e,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var r=0;r<e.length;r++)this._curve[r]=e[r].clone();this._raw=i||!1,this._compute(t)}return t.prototype.getCurve=function(){return this._curve},t.prototype.getTangents=function(){return this._tangents},t.prototype.getNormals=function(){return this._normals},t.prototype.getBinormals=function(){return this._binormals},t.prototype.getDistances=function(){return this._distances},t.prototype.update=function(e,t){for(var i=0;i<e.length;i++)this._curve[i].x=e[i].x,this._curve[i].y=e[i].y,this._curve[i].z=e[i].z;return this._compute(t),this},t.prototype._compute=function(e){var t=this._curve.length;this._tangents[0]=this._getFirstNonNullVector(0),this._raw||this._tangents[0].normalize(),this._tangents[t-1]=this._curve[t-1].subtract(this._curve[t-2]),this._raw||this._tangents[t-1].normalize();var i=this._tangents[0],r=this._normalVector(this._curve[0],i,e);this._normals[0]=r,this._raw||this._normals[0].normalize(),this._binormals[0]=n.Cross(i,this._normals[0]),this._raw||this._binormals[0].normalize(),this._distances[0]=0;for(var o,s,a,h,l=1;t>l;l++)o=this._getLastNonNullVector(l),t-1>l&&(s=this._getFirstNonNullVector(l),this._tangents[l]=o.add(s),this._tangents[l].normalize()),this._distances[l]=this._distances[l-1]+o.length(),a=this._tangents[l],h=this._binormals[l-1],this._normals[l]=n.Cross(h,a),this._raw||this._normals[l].normalize(),this._binormals[l]=n.Cross(a,this._normals[l]),this._raw||this._binormals[l].normalize()},t.prototype._getFirstNonNullVector=function(e){for(var t=1,i=this._curve[e+t].subtract(this._curve[e]);0===i.length()&&e+t+1<this._curve.length;)t++,i=this._curve[e+t].subtract(this._curve[e]);return i},t.prototype._getLastNonNullVector=function(e){for(var t=1,i=this._curve[e].subtract(this._curve[e-t]);0===i.length()&&e>t+1;)t++,i=this._curve[e].subtract(this._curve[e-t]);return i},t.prototype._normalVector=function(t,i,r){var o;if(void 0===r||null===r){var s;e.Tools.WithinEpsilon(i.y,1,e.Engine.Epsilon)?e.Tools.WithinEpsilon(i.x,1,e.Engine.Epsilon)?e.Tools.WithinEpsilon(i.z,1,e.Engine.Epsilon)||(s=new n(0,0,1)):s=new n(1,0,0):s=new n(0,-1,0),o=n.Cross(i,s)}else o=n.Cross(i,r),n.CrossToRef(o,i,o);return o.normalize(),o},t}();e.Path3D=y;var x=function(){function e(e){this._length=0,this._points=e,this._length=this._computeLength(e)}return e.CreateQuadraticBezier=function(t,i,r,o){o=o>2?o:3;for(var s=new Array,a=function(e,t,i,r){var n=(1-e)*(1-e)*t+2*e*(1-e)*i+e*e*r;return n},h=0;o>=h;h++)s.push(new n(a(h/o,t.x,i.x,r.x),a(h/o,t.y,i.y,r.y),a(h/o,t.z,i.z,r.z)));return new e(s)},e.CreateCubicBezier=function(t,i,r,o,s){s=s>3?s:4;for(var a=new Array,h=function(e,t,i,r,n){var o=(1-e)*(1-e)*(1-e)*t+3*e*(1-e)*(1-e)*i+3*e*e*(1-e)*r+e*e*e*n;return o},l=0;s>=l;l++)a.push(new n(h(l/s,t.x,i.x,r.x,o.x),h(l/s,t.y,i.y,r.y,o.y),h(l/s,t.z,i.z,r.z,o.z)));return new e(a)},e.CreateHermiteSpline=function(t,i,r,o,s){for(var a=new Array,h=1/s,l=0;s>=l;l++)a.push(n.Hermite(t,i,r,o,l*h));return new e(a)},e.prototype.getPoints=function(){return this._points},e.prototype.length=function(){return this._length},e.prototype["continue"]=function(t){for(var i=this._points[this._points.length-1],r=this._points.slice(),n=t.getPoints(),o=1;o<n.length;o++)r.push(n[o].subtract(n[0]).add(i));var s=new e(r);return s},e.prototype._computeLength=function(e){for(var t=0,i=1;i<e.length;i++)t+=e[i].subtract(e[i-1]).length();return t},e}();e.Curve3=x;var M=function(){function e(e,t){void 0===e&&(e=n.Zero()),void 0===t&&(t=n.Up()),this.position=e,this.normal=t}return e.prototype.clone=function(){return new e(this.position.clone(),this.normal.clone())},e}();e.PositionNormalVertex=M;var S=function(){function e(e,t,i){void 0===e&&(e=n.Zero()),void 0===t&&(t=n.Up()),void 0===i&&(i=r.Zero()),this.position=e,this.normal=t,this.uv=i}return e.prototype.clone=function(){return new e(this.position.clone(),this.normal.clone(),this.uv.clone())},e}();e.PositionNormalTextureVertex=S;var b=a.prototype.multiplyToArray,A=a.prototype.invertToRef,T=a.LookAtLHToRef,E=n.TransformCoordinatesToRef,P=n.TransformCoordinatesFromFloatsToRef,D=function(){function e(){}return Object.defineProperty(e,"IsEnabled",{get:function(){return e._isEnabled},enumerable:!0,configurable:!0}),e.DisableSIMD=function(){a.prototype.multiplyToArray=b,a.prototype.invertToRef=A,a.LookAtLHToRef=T,n.TransformCoordinatesToRef=E,n.TransformCoordinatesFromFloatsToRef=P,e._isEnabled=!1},e.EnableSIMD=function(){void 0!==window.SIMD&&(a.prototype.multiplyToArray=a.prototype.multiplyToArraySIMD,a.prototype.invertToRef=a.prototype.invertToRefSIMD,a.LookAtLHToRef=a.LookAtLHToRefSIMD,n.TransformCoordinatesToRef=n.TransformCoordinatesToRefSIMD,n.TransformCoordinatesFromFloatsToRef=n.TransformCoordinatesFromFloatsToRefSIMD,Object.defineProperty(n.prototype,"x",{get:function(){return this._data[0]},set:function(e){this._data||(this._data=new Float32Array(3)),this._data[0]=e}}),Object.defineProperty(n.prototype,"y",{get:function(){return this._data[1]},set:function(e){this._data[1]=e}}),Object.defineProperty(n.prototype,"z",{get:function(){return this._data[2]},set:function(e){this._data[2]=e}}),e._isEnabled=!0)},e._isEnabled=!1,e}();e.SIMDHelper=D}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,i){this.idbFactory=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,this.callbackManifestChecked=i,this.currentSceneUrl=t.ReturnFullUrlLocation(e),this.db=null,this.enableSceneOffline=!1,this.enableTexturesOffline=!1,this.manifestVersionFound=0,this.mustUpdateRessources=!1,this.hasReachedQuota=!1,t.IDBStorageEnabled?this.checkManifestFile():this.callbackManifestChecked(!0)}return t.prototype.checkManifestFile=function(){function t(){r.enableSceneOffline=!1,r.enableTexturesOffline=!1,r.callbackManifestChecked(!1)}var i=this,r=this,n=this.currentSceneUrl+".manifest",o=new XMLHttpRequest,s=n+(null==n.match(/\?/)?"?":"&")+(new Date).getTime();o.open("GET",s,!0),o.addEventListener("load",function(){if(200===o.status||e.Tools.ValidateXHRData(o,1))try{var r=JSON.parse(o.response);i.enableSceneOffline=r.enableSceneOffline,i.enableTexturesOffline=r.enableTexturesOffline,r.version&&!isNaN(parseInt(r.version))&&(i.manifestVersionFound=r.version),i.callbackManifestChecked&&i.callbackManifestChecked(!0)}catch(n){t()}else t()},!1),o.addEventListener("error",function(e){t()},!1);try{o.send()}catch(a){e.Tools.Error("Error on XHR send request."),r.callbackManifestChecked(!1)}},t.prototype.openAsync=function(t,i){function r(){o.isSupported=!1,i&&i()}var n=this,o=this;if(this.idbFactory&&(this.enableSceneOffline||this.enableTexturesOffline))if(this.db)t&&t();else{this.hasReachedQuota=!1,this.isSupported=!0;var s=this.idbFactory.open("babylonjs",1);s.onerror=function(e){r()},s.onblocked=function(t){e.Tools.Error("IDB request blocked. Please reload the page."),r()},s.onsuccess=function(e){n.db=s.result,t()},s.onupgradeneeded=function(t){n.db=t.target.result;try{{n.db.createObjectStore("scenes",{keyPath:"sceneUrl"}),n.db.createObjectStore("versions",{keyPath:"sceneUrl"}),n.db.createObjectStore("textures",{keyPath:"textureUrl"})}}catch(i){e.Tools.Error("Error while creating object stores. Exception: "+i.message),r()}}}else this.isSupported=!1,i&&i()},t.prototype.loadImageFromDB=function(e,i){var r=this,n=t.ReturnFullUrlLocation(e),o=function(){r.hasReachedQuota||null===r.db?i.src=e:r._saveImageIntoDBAsync(n,i)};this.mustUpdateRessources?o():this._loadImageFromDBAsync(n,i,o)},t.prototype._loadImageFromDBAsync=function(t,i,r){if(this.isSupported&&null!==this.db){var n,o=this.db.transaction(["textures"]);o.onabort=function(e){i.src=t},o.oncomplete=function(o){var s;if(n){var a=window.URL||window.webkitURL;s=a.createObjectURL(n.data,{oneTimeOnly:!0}),i.onerror=function(){e.Tools.Error("Error loading image from blob URL: "+s+" switching back to web url: "+t),i.src=t},i.src=s}else r()};var s=o.objectStore("textures").get(t);s.onsuccess=function(e){n=e.target.result},s.onerror=function(r){e.Tools.Error("Error loading texture "+t+" from DB."),i.src=t}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i.src=t},t.prototype._saveImageIntoDBAsync=function(i,r){var n=this;if(this.isSupported){var o=function(){var e;if(s){var t=window.URL||window.webkitURL;try{e=t.createObjectURL(s,{oneTimeOnly:!0})}catch(i){e=t.createObjectURL(s)}}r.src=e};if(t.IsUASupportingBlobStorage){var s,a=new XMLHttpRequest;a.open("GET",i,!0),a.responseType="blob",a.addEventListener("load",function(){if(200===a.status){s=a.response;var e=n.db.transaction(["textures"],"readwrite");e.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}o()},e.oncomplete=function(e){o()};var h={textureUrl:i,data:s};try{var l=e.objectStore("textures").put(h);l.onsuccess=function(e){},l.onerror=function(e){o()}}catch(c){25===c.code&&(t.IsUASupportingBlobStorage=!1),r.src=i}}else r.src=i},!1),a.addEventListener("error",function(t){e.Tools.Error("Error in XHR request in BABYLON.Database."),r.src=i},!1),a.send()}else r.src=i}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r.src=i},t.prototype._checkVersionFromDB=function(e,t){var i=this,r=function(r){i._saveVersionIntoDBAsync(e,t)};this._loadVersionFromDBAsync(e,t,r)},t.prototype._loadVersionFromDBAsync=function(t,i,r){var n=this;if(this.isSupported){var o;try{var s=this.db.transaction(["versions"]);s.oncomplete=function(e){o?n.manifestVersionFound>o.data?(n.mustUpdateRessources=!0,r()):i(o.data):(n.mustUpdateRessources=!0,r())},s.onabort=function(e){i(-1)};var a=s.objectStore("versions").get(t);a.onsuccess=function(e){o=e.target.result},a.onerror=function(r){e.Tools.Error("Error loading version for scene "+t+" from DB."),i(-1)}}catch(h){e.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+h.message),i(-1)}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i(-1)},t.prototype._saveVersionIntoDBAsync=function(t,i){var r=this;if(this.isSupported&&!this.hasReachedQuota)try{var n=this.db.transaction(["versions"],"readwrite");n.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(r.hasReachedQuota=!0)}catch(t){}i(-1)},n.oncomplete=function(e){i(r.manifestVersionFound)};var o={sceneUrl:t,data:this.manifestVersionFound
  },s=n.objectStore("versions").put(o);s.onsuccess=function(e){},s.onerror=function(t){e.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(a){e.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+a.message),i(-1)}else i(-1)},t.prototype.loadFileFromDB=function(e,i,r,n,o){var s=this,a=t.ReturnFullUrlLocation(e),h=function(e){s._saveFileIntoDBAsync(a,i,r)};this._checkVersionFromDB(a,function(e){-1!==e?s.mustUpdateRessources?s._saveFileIntoDBAsync(a,i,r,o):s._loadFileFromDBAsync(a,i,h,o):n()})},t.prototype._loadFileFromDBAsync=function(t,i,r,n){if(this.isSupported){var o;o=-1!==t.indexOf(".babylon")?"scenes":"textures";var s,a=this.db.transaction([o]);a.oncomplete=function(e){s?i(s.data):r()},a.onabort=function(e){r()};var h=a.objectStore(o).get(t);h.onsuccess=function(e){s=e.target.result},h.onerror=function(i){e.Tools.Error("Error loading file "+t+" from DB."),r()}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.prototype._saveFileIntoDBAsync=function(t,i,r,n){var o=this;if(this.isSupported){var s;s=-1!==t.indexOf(".babylon")?"scenes":"textures";var a,h=new XMLHttpRequest;h.open("GET",t,!0),n&&(h.responseType="arraybuffer"),h.onprogress=r,h.addEventListener("load",function(){if(200===h.status||e.Tools.ValidateXHRData(h,n?6:1))if(a=n?h.response:h.responseText,o.hasReachedQuota)i(a);else{var r=o.db.transaction([s],"readwrite");r.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}i(a)},r.oncomplete=function(e){i(a)};var l;l="scenes"===s?{sceneUrl:t,data:a,version:o.manifestVersionFound}:{textureUrl:t,data:a};try{var c=r.objectStore(s).put(l);c.onsuccess=function(e){},c.onerror=function(t){e.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(u){i(a)}}else i()},!1),h.addEventListener("error",function(t){e.Tools.Error("error on XHR request."),i()},!1),h.send()}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.IsUASupportingBlobStorage=!0,t.IDBStorageEnabled=!0,t.parseURL=function(e){var t=document.createElement("a");t.href=e;var i=e.substring(0,e.lastIndexOf("#")),r=e.substring(i.lastIndexOf("/")+1,e.length),n=e.substring(0,e.indexOf(r,0));return n},t.ReturnFullUrlLocation=function(e){return-1===e.indexOf("http:/")?t.parseURL(window.location.href)+e:e},t}();e.Database=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var i=function(){function t(){}return t.GetTGAHeader=function(e){var t=0,i={id_length:e[t++],colormap_type:e[t++],image_type:e[t++],colormap_index:e[t++]|e[t++]<<8,colormap_length:e[t++]|e[t++]<<8,colormap_size:e[t++],origin:[e[t++]|e[t++]<<8,e[t++]|e[t++]<<8],width:e[t++]|e[t++]<<8,height:e[t++]|e[t++]<<8,pixel_size:e[t++],flags:e[t++]};return i},t.UploadContent=function(i,r){if(r.length<19)return void e.Tools.Error("Unable to load TGA file - Not enough data to contain header");var n=18,o=t.GetTGAHeader(r);if(o.id_length+n>r.length)return void e.Tools.Error("Unable to load TGA file - Not enough data");n+=o.id_length;var s=!1,a=!1,h=!1,l=!1;switch(o.image_type){case t._TYPE_RLE_INDEXED:s=!0;case t._TYPE_INDEXED:a=!0;break;case t._TYPE_RLE_RGB:s=!0;case t._TYPE_RGB:h=!0;break;case t._TYPE_RLE_GREY:s=!0;case t._TYPE_GREY:l=!0}var c,u,f=(15&o.flags,o.pixel_size>>3),d=o.width*o.height*f;if(a&&(u=r.subarray(n,n+=o.colormap_length*(o.colormap_size>>3))),s){c=new Uint8Array(d);for(var p,m,g,_=0,v=new Uint8Array(f);d>n&&d>_;)if(p=r[n++],m=(127&p)+1,128&p){for(g=0;f>g;++g)v[g]=r[n++];for(g=0;m>g;++g)c.set(v,_+g*f);_+=f*m}else{for(m*=f,g=0;m>g;++g)c[_+g]=r[n++];_+=m}}else c=r.subarray(n,n+=a?o.width*o.height:d);var y,x,M,S,b,A;switch((o.flags&t._ORIGIN_MASK)>>t._ORIGIN_SHIFT){default:case t._ORIGIN_UL:y=0,M=1,A=o.width,x=0,S=1,b=o.height;break;case t._ORIGIN_BL:y=0,M=1,A=o.width,x=o.height-1,S=-1,b=-1;break;case t._ORIGIN_UR:y=o.width-1,M=-1,A=-1,x=0,S=1,b=o.height;break;case t._ORIGIN_BR:y=o.width-1,M=-1,A=-1,x=o.height-1,S=-1,b=-1}var T="_getImageData"+(l?"Grey":"")+o.pixel_size+"bits",E=t[T](o,u,c,x,S,b,y,M,A);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,o.width,o.height,0,i.RGBA,i.UNSIGNED_BYTE,E)},t._getImageData8bits=function(e,t,i,r,n,o,s,a,h){var l,c,u,f=i,d=t,p=e.width,m=e.height,g=0,_=new Uint8Array(p*m*4);for(u=r;u!==o;u+=n)for(c=s;c!==h;c+=a,g++)l=f[g],_[4*(c+p*u)+3]=255,_[4*(c+p*u)+2]=d[3*l+0],_[4*(c+p*u)+1]=d[3*l+1],_[4*(c+p*u)+0]=d[3*l+2];return _},t._getImageData16bits=function(e,t,i,r,n,o,s,a,h){var l,c,u,f=i,d=e.width,p=e.height,m=0,g=new Uint8Array(d*p*4);for(u=r;u!==o;u+=n)for(c=s;c!==h;c+=a,m+=2)l=f[m+0]+(f[m+1]<<8),g[4*(c+d*u)+0]=(31744&l)>>7,g[4*(c+d*u)+1]=(992&l)>>2,g[4*(c+d*u)+2]=(31&l)>>3,g[4*(c+d*u)+3]=32768&l?0:255;return g},t._getImageData24bits=function(e,t,i,r,n,o,s,a,h){var l,c,u=i,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(c=r;c!==o;c+=n)for(l=s;l!==h;l+=a,p+=3)m[4*(l+f*c)+3]=255,m[4*(l+f*c)+2]=u[p+0],m[4*(l+f*c)+1]=u[p+1],m[4*(l+f*c)+0]=u[p+2];return m},t._getImageData32bits=function(e,t,i,r,n,o,s,a,h){var l,c,u=i,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(c=r;c!==o;c+=n)for(l=s;l!==h;l+=a,p+=4)m[4*(l+f*c)+2]=u[p+0],m[4*(l+f*c)+1]=u[p+1],m[4*(l+f*c)+0]=u[p+2],m[4*(l+f*c)+3]=u[p+3];return m},t._getImageDataGrey8bits=function(e,t,i,r,n,o,s,a,h){var l,c,u,f=i,d=e.width,p=e.height,m=0,g=new Uint8Array(d*p*4);for(u=r;u!==o;u+=n)for(c=s;c!==h;c+=a,m++)l=f[m],g[4*(c+d*u)+0]=l,g[4*(c+d*u)+1]=l,g[4*(c+d*u)+2]=l,g[4*(c+d*u)+3]=255;return g},t._getImageDataGrey16bits=function(e,t,i,r,n,o,s,a,h){var l,c,u=i,f=e.width,d=e.height,p=0,m=new Uint8Array(f*d*4);for(c=r;c!==o;c+=n)for(l=s;l!==h;l+=a,p+=2)m[4*(l+f*c)+0]=u[p+0],m[4*(l+f*c)+1]=u[p+0],m[4*(l+f*c)+2]=u[p+0],m[4*(l+f*c)+3]=u[p+1];return m},t._TYPE_NO_DATA=0,t._TYPE_INDEXED=1,t._TYPE_RGB=2,t._TYPE_GREY=3,t._TYPE_RLE_INDEXED=9,t._TYPE_RLE_RGB=10,t._TYPE_RLE_GREY=11,t._ORIGIN_MASK=48,t._ORIGIN_SHIFT=4,t._ORIGIN_BL=0,t._ORIGIN_BR=1,t._ORIGIN_UL=2,t._ORIGIN_UR=3,t}();t.TGATools=i}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){function i(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}function r(e){return String.fromCharCode(255&e,e>>8&255,e>>16&255,e>>24&255)}var n=542327876,o=131072,s=512,a=4,h=64,l=131072,c=i("DXT1"),u=i("DXT3"),f=i("DXT5"),d=31,p=0,m=1,g=2,_=3,v=4,y=7,x=20,M=21,S=22,b=28,A=function(){function t(){}return t.GetDDSInfo=function(e){var t=new Int32Array(e,0,d),i=1;return t[g]&o&&(i=Math.max(1,t[y])),{width:t[v],height:t[_],mipmapCount:i,isFourCC:(t[x]&a)===a,isRGB:(t[x]&h)===h,isLuminance:(t[x]&l)===l,isCube:(t[b]&s)===s}},t.GetRGBAArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n),a=0,h=t-1;h>=0;h--)for(var l=0;e>l;l++){var c=i+4*(l+h*e);o[a+2]=s[c],o[a+1]=s[c+1],o[a]=s[c+2],o[a+3]=s[c+3],a+=4}return o},t.GetRGBArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n),a=0,h=t-1;h>=0;h--)for(var l=0;e>l;l++){var c=i+3*(l+h*e);o[a+2]=s[c],o[a+1]=s[c+1],o[a]=s[c+2],a+=3}return o},t.GetLuminanceArrayBuffer=function(e,t,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n),a=0,h=t-1;h>=0;h--)for(var l=0;e>l;l++){var c=i+(l+h*e);o[a]=s[c],a++}return o},t.UploadDDSLevels=function(i,s,a,h,l,x){var b,A,T,E,P,D,C,I,w,R,L=new Int32Array(a,0,d);if(L[p]!=n)return void e.Tools.Error("Invalid magic number in DDS header");if(!h.isFourCC&&!h.isRGB&&!h.isLuminance)return void e.Tools.Error("Unsupported format, must contain a FourCC, RGB or LUMINANCE code");if(h.isFourCC)switch(b=L[M]){case c:A=8,T=s.COMPRESSED_RGBA_S3TC_DXT1_EXT;break;case u:A=16,T=s.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case f:A=16,T=s.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return void console.error("Unsupported FourCC code:",r(b))}w=1,L[g]&o&&l!==!1&&(w=Math.max(1,L[y]));for(var O=L[S],B=0;x>B;B++){var F=1==x?i.TEXTURE_2D:i.TEXTURE_CUBE_MAP_POSITIVE_X+B;for(E=L[v],P=L[_],C=L[m]+4,R=0;w>R;++R){if(h.isRGB)24==O?(D=E*P*3,I=t.GetRGBArrayBuffer(E,P,C,D,a),i.texImage2D(F,R,i.RGB,E,P,0,i.RGB,i.UNSIGNED_BYTE,I)):(D=E*P*4,I=t.GetRGBAArrayBuffer(E,P,C,D,a),i.texImage2D(F,R,i.RGBA,E,P,0,i.RGBA,i.UNSIGNED_BYTE,I));else if(h.isLuminance){var V=i.getParameter(i.UNPACK_ALIGNMENT),N=E,z=Math.floor((E+V-1)/V)*V;D=z*(P-1)+N,I=t.GetLuminanceArrayBuffer(E,P,C,D,a),i.texImage2D(F,R,i.LUMINANCE,E,P,0,i.LUMINANCE,i.UNSIGNED_BYTE,I)}else D=Math.max(4,E)/4*Math.max(4,P)/4*A,I=new Uint8Array(a,C,D),i.compressedTexImage2D(F,R,T,E,P,0,I);C+=D,E*=.5,P*=.5,E=Math.max(1,E),P=Math.max(1,P)}}},t}();t.DDSTools=A}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(t){this.length=0,this._duplicateId=0,this.data=new Array(t),this._id=e._GlobalId++}return e.prototype.push=function(e){this.data[this.length++]=e,this.length>this.data.length&&(this.data.length*=2),e.__smartArrayFlags||(e.__smartArrayFlags={}),e.__smartArrayFlags[this._id]=this._duplicateId},e.prototype.pushNoDuplicate=function(e){e.__smartArrayFlags&&e.__smartArrayFlags[this._id]===this._duplicateId||this.push(e)},e.prototype.sort=function(e){this.data.sort(e)},e.prototype.reset=function(){this.length=0,this._duplicateId++},e.prototype.concat=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t<e.length;t++)this.data[this.length++]=(e.data||e)[t]}},e.prototype.concatWithNoDuplicate=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t<e.length;t++){var i=(e.data||e)[t];this.pushNoDuplicate(i)}}},e.prototype.indexOf=function(e){var t=this.data.indexOf(e);return t>=this.length?-1:t},e._GlobalId=0,e}();e.SmartArray=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){void 0===e&&(e=10),this.count=0,this._initialCapacity=e,this.items={},this._keys=new Array(this._initialCapacity)}return e.prototype.add=function(e,t){return void 0!=this.items[e]?-1:(this.items[e]=t,this._keys[this.count++]=e,this.count>this._keys.length&&(this._keys.length*=2),this.count)},e.prototype.remove=function(e){return void 0==this.items[e]?-1:this.removeItemOfIndex(this.indexOf(e))},e.prototype.removeItemOfIndex=function(e){if(!(e<this.count&&e>-1))return-1;for(delete this.items[this._keys[e]];e<this.count;)this._keys[e]=this._keys[e+1],e++;return--this.count},e.prototype.indexOf=function(e){for(var t=0;t!==this.count;t++)if(this._keys[t]===e)return t;return-1},e.prototype.item=function(e){return this.items[e]},e.prototype.getAllKeys=function(){if(this.count>0){for(var e=new Array(this.count),t=0;t<this.count;t++)e[t]=this._keys[t];return e}return void 0},e.prototype.getKeyByIndex=function(e){return e<this.count&&e>-1?this._keys[e]:void 0},e.prototype.getItemByIndex=function(e){return e<this.count&&e>-1?this.items[this._keys[e]]:void 0},e.prototype.empty=function(){this.count>0&&(this.count=0,this.items={},this._keys=new Array(this._initialCapacity))},e.prototype.forEach=function(e){var t;for(t in this.items)this.items.hasOwnProperty(t)&&e(this.items[t])},e}();e.SmartCollection=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t,i=function(t,i){return t?t instanceof e.Mesh?null:t instanceof e.SubMesh?t.clone(i):t.clone?t.clone():null:null},r=function(){function r(){}return r.ToHex=function(e){var t=e.toString(16);return 15>=e?("0"+t).toUpperCase():t.toUpperCase()},r.SetImmediate=function(e){window.setImmediate?window.setImmediate(e):setTimeout(e,1)},r.IsExponantOfTwo=function(e){var t=1;do t*=2;while(e>t);return t===e},r.GetExponantOfTwo=function(e,t){var i=1;do i*=2;while(e>i);return i>t&&(i=t),i},r.GetFilename=function(e){var t=e.lastIndexOf("/");return 0>t?e:e.substring(t+1)},r.GetDOMTextContent=function(e){for(var t="",i=e.firstChild;i;)3===i.nodeType&&(t+=i.textContent),i=i.nextSibling;return t},r.ToDegrees=function(e){return 180*e/Math.PI},r.ToRadians=function(e){return e*Math.PI/180},r.ExtractMinAndMaxIndexed=function(t,i,r,n){for(var o=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),s=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),a=r;r+n>a;a++){var h=new e.Vector3(t[3*i[a]],t[3*i[a]+1],t[3*i[a]+2]);o=e.Vector3.Minimize(h,o),s=e.Vector3.Maximize(h,s)}return{minimum:o,maximum:s}},r.ExtractMinAndMax=function(t,i,r){for(var n=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),o=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),s=i;i+r>s;s++){var a=new e.Vector3(t[3*s],t[3*s+1],t[3*s+2]);n=e.Vector3.Minimize(a,n),o=e.Vector3.Maximize(a,o)}return{minimum:n,maximum:o}},r.MakeArray=function(e,t){return t===!0||void 0!==e&&null!=e?Array.isArray(e)?e:[e]:void 0},r.GetPointerPrefix=function(){var e="pointer";return navigator.pointerEnabled||(e="mouse"),e},r.QueueNewFrame=function(e){window.requestAnimationFrame?window.requestAnimationFrame(e):window.msRequestAnimationFrame?window.msRequestAnimationFrame(e):window.webkitRequestAnimationFrame?window.webkitRequestAnimationFrame(e):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(e):window.oRequestAnimationFrame?window.oRequestAnimationFrame(e):window.setTimeout(e,16)},r.RequestFullscreen=function(e){e.requestFullscreen?e.requestFullscreen():e.msRequestFullscreen?e.msRequestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.mozRequestFullScreen&&e.mozRequestFullScreen()},r.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},r.CleanUrl=function(e){return e=e.replace(/#/gm,"%23")},r.LoadImage=function(t,i,n,o){t=r.CleanUrl(t);var s=new Image;"data:"!==t.substr(0,5)&&(s.crossOrigin="anonymous"),s.onload=function(){i(s)},s.onerror=function(e){r.Error("Error while trying to load texture: "+t),s.src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/bAEMBBAQEBQUFCgYGChYPDA8WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFv/AABEIAQABAAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APH6KKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z",i(s)};var a=function(){s.src=t},h=function(){o.loadImageFromDB(t,s)};if(o&&o.enableTexturesOffline&&e.Database.IsUASupportingBlobStorage)o.openAsync(h,a);else if(-1===t.indexOf("file:"))a();else try{var l,c=t.substring(5);try{l=URL.createObjectURL(e.FilesInput.FilesTextures[c],{oneTimeOnly:!0})}catch(u){l=URL.createObjectURL(e.FilesInput.FilesTextures[c])}s.src=l}catch(f){s.src=null}return s},r.LoadFile=function(t,i,n,o,s,a){t=r.CleanUrl(t);var h=function(){var e=new XMLHttpRequest,o=r.BaseUrl+t;e.open("GET",o,!0),s&&(e.responseType="arraybuffer"),e.onprogress=n,e.onreadystatechange=function(){if(4===e.readyState)if(200===e.status||r.ValidateXHRData(e,s?6:1))i(s?e.response:e.responseText);else{if(!a)throw new Error("Error status: "+e.status+" - Unable to load "+o);a()}},e.send(null)},l=function(){o.loadFileFromDB(t,i,n,h,s)};if(-1!==t.indexOf("file:")){var c=t.substring(5);r.ReadFile(e.FilesInput.FilesToLoad[c],i,n,!0)}else o&&o.enableSceneOffline?o.openAsync(l,h):h()},r.ReadFileAsDataURL=function(e,t,i){var r=new FileReader;r.onload=function(e){t(e.target.result)},r.onprogress=i,r.readAsDataURL(e)},r.ReadFile=function(e,t,i,n){var o=new FileReader;o.onerror=function(i){r.Log("Error while reading file: "+e.name),t(JSON.stringify({autoClear:!0,clearColor:[1,0,0],ambientColor:[0,0,0],gravity:[0,-9.807,0],meshes:[],cameras:[],lights:[]}))},o.onload=function(e){t(e.target.result)},o.onprogress=i,n?o.readAsArrayBuffer(e):o.readAsText(e)},r.Clamp=function(e,t,i){return void 0===t&&(t=0),void 0===i&&(i=1),Math.min(i,Math.max(t,e))},r.Sign=function(e){return e=+e,0===e||isNaN(e)?e:e>0?1:-1},r.Format=function(e,t){return void 0===t&&(t=2),e.toFixed(t)},r.CheckExtends=function(e,t,i){e.x<t.x&&(t.x=e.x),e.y<t.y&&(t.y=e.y),e.z<t.z&&(t.z=e.z),e.x>i.x&&(i.x=e.x),e.y>i.y&&(i.y=e.y),e.z>i.z&&(i.z=e.z)},r.WithinEpsilon=function(e,t,i){void 0===i&&(i=1.401298e-45);var r=e-t;return r>=-i&&i>=r},r.DeepCopy=function(e,t,r,n){for(var o in e)if(("_"!==o[0]||n&&-1!==n.indexOf(o))&&(!r||-1===r.indexOf(o))){var s=e[o],a=typeof s;if("function"!==a)if("object"===a)if(s instanceof Array){if(t[o]=[],s.length>0)if("object"==typeof s[0])for(var h=0;h<s.length;h++){var l=i(s[h],t);-1===t[o].indexOf(l)&&t[o].push(l)}else t[o]=s.slice(0)}else t[o]=i(s,t);else t[o]=s}},r.IsEmpty=function(e){for(var t in e)return!1;return!0},r.RegisterTopRootEvents=function(e){for(var t=0;t<e.length;t++){var i=e[t];window.addEventListener(i.name,i.handler,!1);try{window.parent&&window.parent.addEventListener(i.name,i.handler,!1)}catch(r){}}},r.UnregisterTopRootEvents=function(e){for(var t=0;t<e.length;t++){var i=e[t];window.removeEventListener(i.name,i.handler);try{window.parent&&window.parent.removeEventListener(i.name,i.handler)}catch(r){}}},r.DumpFramebuffer=function(e,i,r,n){for(var o=4*e,s=i/2,a=r.readPixels(0,0,e,i),h=0;s>h;h++)for(var l=0;o>l;l++){var c=l+h*o,u=i-h-1,f=l+u*o,d=a[c];a[c]=a[f],a[f]=d}t||(t=document.createElement("canvas")),t.width=e,t.height=i;var p=t.getContext("2d"),m=p.createImageData(e,i),g=m.data;g.set(a),p.putImageData(m,0,0);var _=t.toDataURL();if(n)n(_);else if("download"in document.createElement("a")){var v=window.document.createElement("a");v.href=_;var y=new Date,x=y.getFullYear()+"-"+y.getMonth()+"-"+y.getDate()+"_"+y.getHours()+"-"+("0"+y.getMinutes()).slice(-2);v.setAttribute("download","screenshot_"+x+".png"),window.document.body.appendChild(v),v.addEventListener("click",function(){v.parentElement.removeChild(v)}),v.click()}else{var M=window.open(""),S=M.document.createElement("img");S.src=_,M.document.body.appendChild(S)}},r.CreateScreenshot=function(t,i,n,o){var s,a,h=i.getScene(),l=null;if(h.activeCamera!==i&&(l=h.activeCamera,h.activeCamera=i),n.precision)s=Math.round(t.getRenderWidth()*n.precision),a=Math.round(s/t.getAspectRatio(i)),n={width:s,height:a};else if(n.width&&n.height)s=n.width,a=n.height;else if(n.width&&!n.height)s=n.width,a=Math.round(s/t.getAspectRatio(i)),n={width:s,height:a};else if(n.height&&!n.width)a=n.height,s=Math.round(a*t.getAspectRatio(i)),n={width:s,height:a};else{if(isNaN(n))return void r.Error("Invalid 'size' parameter !");a=n,s=n}var c=new e.RenderTargetTexture("screenShot",n,h,!1,!1);c.renderList=h.meshes,c.onAfterRender=function(){r.DumpFramebuffer(s,a,t,o)},h.incrementRenderId(),c.render(!0),c.dispose(),l&&(h.activeCamera=l)},r.ValidateXHRData=function(t,i){void 0===i&&(i=7);try{if(1&i){if(t.responseText&&t.responseText.length>0)return!0;if(1===i)return!1}if(2&i){var r=e.Internals.TGATools.GetTGAHeader(t.response);if(r.width&&r.height&&r.width>0&&r.height>0)return!0;if(2===i)return!1}if(4&i){var n=new Uint8Array(t.response,0,3);return 68===n[0]&&68===n[1]&&83===n[2]?!0:!1}}catch(o){}return!1},Object.defineProperty(r,"NoneLogLevel",{get:function(){return r._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"MessageLogLevel",{get:function(){return r._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"WarningLogLevel",{get:function(){return r._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ErrorLogLevel",{get:function(){return r._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"AllLogLevel",{get:function(){return r._MessageLogLevel|r._WarningLogLevel|r._ErrorLogLevel},enumerable:!0,configurable:!0}),r._AddLogEntry=function(e){r._LogCache=e+r._LogCache,r.OnNewCacheEntry&&r.OnNewCacheEntry(e)},r._FormatMessage=function(e){var t=function(e){return 10>e?"0"+e:""+e},i=new Date;return"["+t(i.getHours())+":"+t(i.getMinutes())+":"+t(i.getSeconds())+"]: "+e},r._LogDisabled=function(e){},r._LogEnabled=function(e){var t=r._FormatMessage(e);console.log("BJS - "+t);var i="<div style='color:white'>"+t+"</div><br>";r._AddLogEntry(i)},r._WarnDisabled=function(e){},r._WarnEnabled=function(e){var t=r._FormatMessage(e);console.warn("BJS - "+t);var i="<div style='color:orange'>"+t+"</div><br>";r._AddLogEntry(i)},r._ErrorDisabled=function(e){},r._ErrorEnabled=function(e){r.errorsCount++;var t=r._FormatMessage(e);console.error("BJS - "+t);var i="<div style='color:red'>"+t+"</div><br>";r._AddLogEntry(i)},Object.defineProperty(r,"LogCache",{get:function(){return r._LogCache},enumerable:!0,configurable:!0}),r.ClearLogCache=function(){r._LogCache="",r.errorsCount=0},Object.defineProperty(r,"LogLevels",{set:function(e){r.Log=(e&r.MessageLogLevel)===r.MessageLogLevel?r._LogEnabled:r._LogDisabled,r.Warn=(e&r.WarningLogLevel)===r.WarningLogLevel?r._WarnEnabled:r._WarnDisabled,r.Error=(e&r.ErrorLogLevel)===r.ErrorLogLevel?r._ErrorEnabled:r._ErrorDisabled},enumerable:!0,configurable:!0}),Object.defineProperty(r,"PerformanceNoneLogLevel",{get:function(){return r._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"PerformanceUserMarkLogLevel",{get:function(){return r._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"PerformanceConsoleLogLevel",{get:function(){return r._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(r,"PerformanceLogLevel",{set:function(e){return(e&r.PerformanceUserMarkLogLevel)===r.PerformanceUserMarkLogLevel?(r.StartPerformanceCounter=r._StartUserMark,void(r.EndPerformanceCounter=r._EndUserMark)):(e&r.PerformanceConsoleLogLevel)===r.PerformanceConsoleLogLevel?(r.StartPerformanceCounter=r._StartPerformanceConsole,void(r.EndPerformanceCounter=r._EndPerformanceConsole)):(r.StartPerformanceCounter=r._StartPerformanceCounterDisabled,void(r.EndPerformanceCounter=r._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),r._StartPerformanceCounterDisabled=function(e,t){},r._EndPerformanceCounterDisabled=function(e,t){},r._StartUserMark=function(e,t){void 0===t&&(t=!0),t&&r._performance.mark&&r._performance.mark(e+"-Begin")},r._EndUserMark=function(e,t){void 0===t&&(t=!0),t&&r._performance.mark&&(r._performance.mark(e+"-End"),r._performance.measure(e,e+"-Begin",e+"-End"))},r._StartPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(r._StartUserMark(e,t),console.time&&console.time(e))},r._EndPerformanceConsole=function(e,t){void 0===t&&(t=!0),t&&(r._EndUserMark(e,t),console.time&&console.timeEnd(e))},Object.defineProperty(r,"Now",{get:function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),r.GetFps=function(){return r.Warn("Tools.GetFps() is deprecated. Please use engine.getFps() instead"),0},r.BaseUrl="",r._NoneLogLevel=0,r._MessageLogLevel=1,r._WarningLogLevel=2,r._ErrorLogLevel=4,r._LogCache="",r.errorsCount=0,r.Log=r._LogEnabled,r.Warn=r._WarnEnabled,r.Error=r._ErrorEnabled,r._PerformanceNoneLogLevel=0,r._PerformanceUserMarkLogLevel=1,r._PerformanceConsoleLogLevel=2,r._performance=window.performance,r.StartPerformanceCounter=r._StartPerformanceCounterDisabled,r.EndPerformanceCounter=r._EndPerformanceCounterDisabled,r}();e.Tools=r;var n=function(){function e(e,t,i,r){void 0===r&&(r=0),this.iterations=e,this._fn=t,this._successCallback=i,this.index=r-1,this._done=!1}return e.prototype.executeNext=function(){this._done||(this.index+1<this.iterations?(++this.index,this._fn(this)):this.breakLoop())},e.prototype.breakLoop=function(){this._done=!0,this._successCallback()},e.Run=function(t,i,r,n){void 0===n&&(n=0);var o=new e(t,i,r,n);return o.executeNext(),o},e.SyncAsyncForLoop=function(t,i,r,n,o,s){void 0===s&&(s=0),e.Run(Math.ceil(t/i),function(e){o&&o()?e.breakLoop():setTimeout(function(){for(var n=0;i>n;++n){var s=e.index*i+n;if(s>=t)break;if(r(s),o&&o()){e.breakLoop();break}}e.executeNext()},s)},n)},e}();e.AsyncLoop=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._isDepthTestDirty=!1,this._isDepthMaskDirty=!1,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isDepthFuncDirty||this._isDepthTestDirty||this._isDepthMaskDirty||this._isCullFaceDirty||this._isCullDirty||this._isZOffsetDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"zOffset",{get:function(){return this._zOffset},set:function(e){this._zOffset!==e&&(this._zOffset=e,this._isZOffsetDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"cullFace",{get:function(){return this._cullFace},set:function(e){this._cullFace!==e&&(this._cullFace=e,this._isCullFaceDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"cull",{get:function(){return this._cull},set:function(e){this._cull!==e&&(this._cull=e,this._isCullDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthFunc",{get:function(){return this._depthFunc},set:function(e){this._depthFunc!==e&&(this._depthFunc=e,this._isDepthFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthMask",{get:function(){return this._depthMask},set:function(e){this._depthMask!==e&&(this._depthMask=e,this._isDepthMaskDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthTest",{get:function(){return this._depthTest},set:function(e){this._depthTest!==e&&(this._depthTest=e,this._isDepthTestDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this._depthMask=!0,this._depthTest=!0,this._depthFunc=null,this._cull=null,this._cullFace=null,this._zOffset=0,this._isDepthTestDirty=!0,this._isDepthMaskDirty=!0,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1},e.prototype.apply=function(e){this.isDirty&&(this._isCullDirty&&(this.cull?e.enable(e.CULL_FACE):e.disable(e.CULL_FACE),this._isCullDirty=!1),this._isCullFaceDirty&&(e.cullFace(this.cullFace),this._isCullFaceDirty=!1),this._isDepthMaskDirty&&(e.depthMask(this.depthMask),this._isDepthMaskDirty=!1),this._isDepthTestDirty&&(this.depthTest?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST),this._isDepthTestDirty=!1),this._isDepthFuncDirty&&(e.depthFunc(this.depthFunc),this._isDepthFuncDirty=!1),this._isZOffsetDirty&&(this.zOffset?(e.enable(e.POLYGON_OFFSET_FILL),e.polygonOffset(this.zOffset,0)):e.disable(e.POLYGON_OFFSET_FILL),this._isZOffsetDirty=!1))},e}();e._DepthCullingState=t;var i=function(){function e(){this._isAlphaBlendDirty=!1,this._isBlendFunctionParametersDirty=!1,this._alphaBlend=!1,this._blendFunctionParameters=new Array(4)}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isAlphaBlendDirty||this._isBlendFunctionParametersDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alphaBlend",{get:function(){return this._alphaBlend},set:function(e){this._alphaBlend!==e&&(this._alphaBlend=e,this._isAlphaBlendDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.setAlphaBlendFunctionParameters=function(e,t,i,r){(this._blendFunctionParameters[0]!==e||this._blendFunctionParameters[1]!==t||this._blendFunctionParameters[2]!==i||this._blendFunctionParameters[3]!==r)&&(this._blendFunctionParameters[0]=e,this._blendFunctionParameters[1]=t,this._blendFunctionParameters[2]=i,this._blendFunctionParameters[3]=r,this._isBlendFunctionParametersDirty=!0)},e.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},e.prototype.apply=function(e){this.isDirty&&(this._isAlphaBlendDirty&&(this._alphaBlend?e.enable(e.BLEND):e.disable(e.BLEND),this._isAlphaBlendDirty=!1),this._isBlendFunctionParametersDirty&&(e.blendFuncSeparate(this._blendFunctionParameters[0],this._blendFunctionParameters[1],this._blendFunctionParameters[2],this._blendFunctionParameters[3]),this._isBlendFunctionParametersDirty=!1))},e}();e._AlphaState=i;var r=function(e,t,i,r){var n=e.createShader("vertex"===i?e.VERTEX_SHADER:e.FRAGMENT_SHADER);if(e.shaderSource(n,(r?r+"\n":"")+t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(n));return n},n=function(e,t){var i=e.UNSIGNED_BYTE;return t===c.TEXTURETYPE_FLOAT&&(i=e.FLOAT),i},o=function(t,i,r){var n=r.NEAREST,o=r.NEAREST;
  
  return t===e.Texture.BILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=i?r.LINEAR_MIPMAP_NEAREST:r.LINEAR):t===e.Texture.TRILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=i?r.LINEAR_MIPMAP_LINEAR:r.LINEAR):t===e.Texture.NEAREST_SAMPLINGMODE&&(n=r.NEAREST,o=i?r.NEAREST_MIPMAP_LINEAR:r.NEAREST),{min:o,mag:n}},s=function(t,i,r,n,s,a,h,l,c,u){void 0===u&&(u=e.Texture.TRILINEAR_SAMPLINGMODE);var f=r.getEngine(),d=e.Tools.GetExponantOfTwo(n,f.getCaps().maxTextureSize),p=e.Tools.GetExponantOfTwo(s,f.getCaps().maxTextureSize);i.bindTexture(i.TEXTURE_2D,t),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,void 0===a?1:a?1:0),t._baseWidth=n,t._baseHeight=s,t._width=d,t._height=p,t.isReady=!0,c(d,p);var m=o(u,!h,i);i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,m.mag),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,m.min),h||l||i.generateMipmap(i.TEXTURE_2D),i.bindTexture(i.TEXTURE_2D,null),f._activeTexturesCache=[],r._removePendingData(t)},a=function(t,i,r,n,o){var s=function(){r[i]=h,r._internalCount++,n._removePendingData(h),6===r._internalCount&&o(r)},a=function(){n._removePendingData(h)},h=e.Tools.LoadImage(t,s,a,n.database);n._addPendingData(h)},h=function(e,t,i,r){var n=[];n._internalCount=0;for(var o=0;6>o;o++)a(e+r[o],o,n,t,i)},l=function(){function e(){}return e}();e.EngineCapabilities=l;var c=function(){function a(r,n,o){var s=this;this.isFullscreen=!1,this.isPointerLock=!1,this.cullBackFaces=!0,this.renderEvenInBackground=!0,this.enableOfflineSupport=!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 t,this._alphaState=new i,this._alphaMode=a.ALPHA_DISABLE,this._loadedTexturesCache=new Array,this._activeTexturesCache=new Array,this._compiledEffects={},this._uintIndicesCurrentlySet=!1,this._renderingCanvas=r,o=o||{},o.antialias=n,void 0===o.preserveDrawingBuffer&&(o.preserveDrawingBuffer=!1);try{this._gl=r.getContext("webgl",o)||r.getContext("experimental-webgl",o)}catch(h){throw new Error("WebGL not supported")}if(!this._gl)throw new Error("WebGL not supported");this._onBlur=function(){s._windowIsBackground=!0},this._onFocus=function(){s._windowIsBackground=!1},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus),this._hardwareScalingLevel=1/(window.devicePixelRatio||1),this.resize(),this._caps=new l,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 c=this._gl.getExtension("WEBGL_debug_renderer_info");if(null!=c&&(this._glRenderer=this._gl.getParameter(c.UNMASKED_RENDERER_WEBGL),this._glVendor=this._gl.getParameter(c.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._caps.highPrecisionShaderSupported=!0,this._gl.getShaderPrecisionFormat){var u=this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER,this._gl.HIGH_FLOAT);this._caps.highPrecisionShaderSupported=0!=u.precision}this.setDepthBuffer(!0),this.setDepthFunctionToLessOrEqual(),this.setDepthWrite(!0),this._onFullscreenChange=function(){void 0!==document.fullscreen?s.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?s.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?s.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(s.isFullscreen=document.msIsFullScreen),s.isFullscreen&&s._pointerLockRequested&&(r.requestPointerLock=r.requestPointerLock||r.msRequestPointerLock||r.mozRequestPointerLock||r.webkitRequestPointerLock,r.requestPointerLock&&r.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(){s.isPointerLock=document.mozPointerLockElement===r||document.webkitPointerLockElement===r||document.msPointerLockElement===r||document.pointerLockElement===r},document.addEventListener("pointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mspointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this._onPointerLockChange,!1),document.addEventListener("webkitpointerlockchange",this._onPointerLockChange,!1),a.audioEngine||(a.audioEngine=new e.AudioEngine),e.Tools.Log("Babylon.js engine (v"+a.Version+") launched")}return Object.defineProperty(a,"ALPHA_DISABLE",{get:function(){return a._ALPHA_DISABLE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_ONEONE",{get:function(){return a._ALPHA_ONEONE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_ADD",{get:function(){return a._ALPHA_ADD},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_COMBINE",{get:function(){return a._ALPHA_COMBINE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_SUBTRACT",{get:function(){return a._ALPHA_SUBTRACT},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_MULTIPLY",{get:function(){return a._ALPHA_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(a,"ALPHA_MAXIMIZED",{get:function(){return a._ALPHA_MAXIMIZED},enumerable:!0,configurable:!0}),Object.defineProperty(a,"DELAYLOADSTATE_NONE",{get:function(){return a._DELAYLOADSTATE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"DELAYLOADSTATE_LOADED",{get:function(){return a._DELAYLOADSTATE_LOADED},enumerable:!0,configurable:!0}),Object.defineProperty(a,"DELAYLOADSTATE_LOADING",{get:function(){return a._DELAYLOADSTATE_LOADING},enumerable:!0,configurable:!0}),Object.defineProperty(a,"DELAYLOADSTATE_NOTLOADED",{get:function(){return a._DELAYLOADSTATE_NOTLOADED},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_ALPHA",{get:function(){return a._TEXTUREFORMAT_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_LUMINANCE",{get:function(){return a._TEXTUREFORMAT_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_LUMINANCE_ALPHA",{get:function(){return a._TEXTUREFORMAT_LUMINANCE_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_RGB",{get:function(){return a._TEXTUREFORMAT_RGB},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTUREFORMAT_RGBA",{get:function(){return a._TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTURETYPE_UNSIGNED_INT",{get:function(){return a._TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(a,"TEXTURETYPE_FLOAT",{get:function(){return a._TEXTURETYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(a,"Version",{get:function(){return"2.2.0"},enumerable:!0,configurable:!0}),a.prototype._prepareWorkingCanvas=function(){this._workingCanvas||(this._workingCanvas=document.createElement("canvas"),this._workingContext=this._workingCanvas.getContext("2d"))},a.prototype.getGlInfo=function(){return{vendor:this._glVendor,renderer:this._glRenderer,version:this._glVersion}},a.prototype.getAspectRatio=function(e){var t=e.viewport;return this.getRenderWidth()*t.width/(this.getRenderHeight()*t.height)},a.prototype.getRenderWidth=function(){return this._currentRenderTarget?this._currentRenderTarget._width:this._renderingCanvas.width},a.prototype.getRenderHeight=function(){return this._currentRenderTarget?this._currentRenderTarget._height:this._renderingCanvas.height},a.prototype.getRenderingCanvas=function(){return this._renderingCanvas},a.prototype.getRenderingCanvasClientRect=function(){return this._renderingCanvas.getBoundingClientRect()},a.prototype.setHardwareScalingLevel=function(e){this._hardwareScalingLevel=e,this.resize()},a.prototype.getHardwareScalingLevel=function(){return this._hardwareScalingLevel},a.prototype.getLoadedTexturesCache=function(){return this._loadedTexturesCache},a.prototype.getCaps=function(){return this._caps},Object.defineProperty(a.prototype,"drawCalls",{get:function(){return this._drawCalls},enumerable:!0,configurable:!0}),a.prototype.resetDrawCalls=function(){this._drawCalls=0},a.prototype.setDepthFunctionToGreater=function(){this._depthCullingState.depthFunc=this._gl.GREATER},a.prototype.setDepthFunctionToGreaterOrEqual=function(){this._depthCullingState.depthFunc=this._gl.GEQUAL},a.prototype.setDepthFunctionToLess=function(){this._depthCullingState.depthFunc=this._gl.LESS},a.prototype.setDepthFunctionToLessOrEqual=function(){this._depthCullingState.depthFunc=this._gl.LEQUAL},a.prototype.stopRenderLoop=function(e){if(!e)return void(this._activeRenderLoops=[]);var t=this._activeRenderLoops.indexOf(e);t>=0&&this._activeRenderLoops.splice(t,1)},a.prototype._renderLoop=function(){var t=this,i=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(i=!1),i){this.beginFrame();for(var r=0;r<this._activeRenderLoops.length;r++){var n=this._activeRenderLoops[r];n()}this.endFrame()}this._activeRenderLoops.length>0?e.Tools.QueueNewFrame(function(){t._renderLoop()}):this._renderingQueueLaunched=!1},a.prototype.runRenderLoop=function(t){var i=this;-1===this._activeRenderLoops.indexOf(t)&&(this._activeRenderLoops.push(t),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,e.Tools.QueueNewFrame(function(){i._renderLoop()})))},a.prototype.switchFullscreen=function(t){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,e.Tools.RequestFullscreen(this._renderingCanvas))},a.prototype.clear=function(e,t,i){this.applyStates(),this._gl.clearColor(e.r,e.g,e.b,void 0!==e.a?e.a:1),this._depthCullingState.depthMask&&this._gl.clearDepth(1);var r=0;t&&(r|=this._gl.COLOR_BUFFER_BIT),i&&this._depthCullingState.depthMask&&(r|=this._gl.DEPTH_BUFFER_BIT),this._gl.clear(r)},a.prototype.setViewport=function(e,t,i){var r=t||(navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.width),n=i||(navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.height),o=e.x||0,s=e.y||0;this._cachedViewport=e,this._gl.viewport(o*r,s*n,r*e.width,n*e.height)},a.prototype.setDirectViewport=function(e,t,i,r){this._cachedViewport=null,this._gl.viewport(e,t,i,r)},a.prototype.beginFrame=function(){this._measureFps()},a.prototype.endFrame=function(){},a.prototype.resize=function(){var e=navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.clientWidth,t=navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.clientHeight;this.setSize(e/this._hardwareScalingLevel,t/this._hardwareScalingLevel)},a.prototype.setSize=function(e,t){this._renderingCanvas.width=e,this._renderingCanvas.height=t;for(var i=0;i<this.scenes.length;i++)for(var r=this.scenes[i],n=0;n<r.cameras.length;n++){var o=r.cameras[n];o._currentRenderId=0}},a.prototype.bindFramebuffer=function(e){this._currentRenderTarget=e;var t=this._gl;t.bindFramebuffer(t.FRAMEBUFFER,e._framebuffer),this._gl.viewport(0,0,e._width,e._height),this.wipeCaches()},a.prototype.unBindFramebuffer=function(e){if(this._currentRenderTarget=null,e.generateMipMaps){var t=this._gl;t.bindTexture(t.TEXTURE_2D,e),t.generateMipmap(t.TEXTURE_2D),t.bindTexture(t.TEXTURE_2D,null)}this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null)},a.prototype.flushFramebuffer=function(){this._gl.flush()},a.prototype.restoreDefaultFramebuffer=function(){this._currentRenderTarget=null,this._gl.bindFramebuffer(this._gl.FRAMEBUFFER,null),this.setViewport(this._cachedViewport),this.wipeCaches()},a.prototype._resetVertexBufferBinding=function(){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,null),this._cachedVertexBuffers=null},a.prototype.createVertexBuffer=function(e){var t=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array(e),this._gl.STATIC_DRAW),this._resetVertexBufferBinding(),t.references=1,t},a.prototype.createDynamicVertexBuffer=function(e){var t=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW),this._resetVertexBufferBinding(),t.references=1,t},a.prototype.updateDynamicVertexBuffer=function(e,t,i){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),void 0===i&&(i=0),t instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,t):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,new Float32Array(t)),this._resetVertexBufferBinding()},a.prototype._resetIndexBufferBinding=function(){this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,null),this._cachedIndexBuffer=null},a.prototype.createIndexBuffer=function(e){var t=this._gl.createBuffer();this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t);var i,r=!1;if(this._caps.uintIndices){for(var n=0;n<e.length;n++)if(e[n]>65535){r=!0;break}i=r?new Uint32Array(e):new Uint16Array(e)}else i=new Uint16Array(e);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,i,this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),t.references=1,t.is32Bits=r,t},a.prototype.bindBuffers=function(e,t,i,r,n){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==n){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=n,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e);for(var o=0,s=0;s<i.length;s++){var a=n.getAttributeLocation(s);a>=0&&this._gl.vertexAttribPointer(a,i[s],this._gl.FLOAT,!1,r,o),o+=4*i[s]}}this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t),this._uintIndicesCurrentlySet=t.is32Bits)},a.prototype.bindMultiBuffers=function(e,t,i){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==i){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=i;for(var r=i.getAttributesNames(),n=0;n<r.length;n++){var o=i.getAttributeLocation(n);if(o>=0){var s=e[r[n]];if(!s)continue;var a=s.getStrideSize();this._gl.bindBuffer(this._gl.ARRAY_BUFFER,s.getBuffer()),this._gl.vertexAttribPointer(o,a,this._gl.FLOAT,!1,4*a,0)}}}null!=t&&this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,t),this._uintIndicesCurrentlySet=t.is32Bits)},a.prototype._releaseBuffer=function(e){return e.references--,0===e.references?(this._gl.deleteBuffer(e),!0):!1},a.prototype.createInstancesBuffer=function(e){var t=this._gl.createBuffer();return t.capacity=e,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW),t},a.prototype.deleteInstancesBuffer=function(e){this._gl.deleteBuffer(e)},a.prototype.updateAndBindInstancesBuffer=function(e,t,i){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t);for(var r=0;4>r;r++){var n=i[r];this._gl.enableVertexAttribArray(n),this._gl.vertexAttribPointer(n,4,this._gl.FLOAT,!1,64,16*r),this._caps.instancedArrays.vertexAttribDivisorANGLE(n,1)}},a.prototype.unBindInstancesBuffer=function(e,t){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e);for(var i=0;4>i;i++){var r=t[i];this._gl.disableVertexAttribArray(r),this._caps.instancedArrays.vertexAttribDivisorANGLE(r,0)}},a.prototype.applyStates=function(){this._depthCullingState.apply(this._gl),this._alphaState.apply(this._gl)},a.prototype.draw=function(e,t,i,r){this.applyStates(),this._drawCalls++;var n=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT,o=this._uintIndicesCurrentlySet?4:2;return r?void this._caps.instancedArrays.drawElementsInstancedANGLE(e?this._gl.TRIANGLES:this._gl.LINES,i,n,t*o,r):void this._gl.drawElements(e?this._gl.TRIANGLES:this._gl.LINES,i,n,t*o)},a.prototype.drawPointClouds=function(e,t,i){return this.applyStates(),this._drawCalls++,i?void this._caps.instancedArrays.drawArraysInstancedANGLE(this._gl.POINTS,e,t,i):void this._gl.drawArrays(this._gl.POINTS,e,t)},a.prototype._releaseEffect=function(e){this._compiledEffects[e._key]&&(delete this._compiledEffects[e._key],e.getProgram()&&this._gl.deleteProgram(e.getProgram()))},a.prototype.createEffect=function(t,i,r,n,o,s,a,h){var l=t.vertexElement||t.vertex||t,c=t.fragmentElement||t.fragment||t,u=l+"+"+c+"@"+o;if(this._compiledEffects[u])return this._compiledEffects[u];var f=new e.Effect(t,i,r,n,this,o,s,a,h);return f._key=u,this._compiledEffects[u]=f,f},a.prototype.createEffectForParticles=function(e,t,i,r,n,o,s){return void 0===t&&(t=[]),void 0===i&&(i=[]),void 0===r&&(r=""),this.createEffect({vertex:"particles",fragmentElement:e},["position","color","options"],["view","projection"].concat(t),["diffuseSampler"].concat(i),r,n,o,s)},a.prototype.createShaderProgram=function(e,t,i){var n=r(this._gl,e,"vertex",i),o=r(this._gl,t,"fragment",i),s=this._gl.createProgram();this._gl.attachShader(s,n),this._gl.attachShader(s,o),this._gl.linkProgram(s);var a=this._gl.getProgramParameter(s,this._gl.LINK_STATUS);if(!a){var h=this._gl.getProgramInfoLog(s);if(h)throw new Error(h)}return this._gl.deleteShader(n),this._gl.deleteShader(o),s},a.prototype.getUniforms=function(e,t){for(var i=[],r=0;r<t.length;r++)i.push(this._gl.getUniformLocation(e,t[r]));return i},a.prototype.getAttributes=function(e,t){for(var i=[],r=0;r<t.length;r++)try{i.push(this._gl.getAttribLocation(e,t[r]))}catch(n){i.push(-1)}return i},a.prototype.enableEffect=function(e){if(!e||!e.getAttributesCount()||this._currentEffect===e)return void(e&&e.onBind&&e.onBind(e));this._vertexAttribArrays=this._vertexAttribArrays||[],this._gl.useProgram(e.getProgram());for(var t in this._vertexAttribArrays)t>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[t]||(this._vertexAttribArrays[t]=!1,this._gl.disableVertexAttribArray(t));for(var i=e.getAttributesCount(),r=0;i>r;r++){var n=e.getAttributeLocation(r);n>=0&&(this._vertexAttribArrays[n]=!0,this._gl.enableVertexAttribArray(n))}this._currentEffect=e,e.onBind&&e.onBind(e)},a.prototype.setArray=function(e,t){e&&this._gl.uniform1fv(e,t)},a.prototype.setArray2=function(e,t){e&&t.length%2===0&&this._gl.uniform2fv(e,t)},a.prototype.setArray3=function(e,t){e&&t.length%3===0&&this._gl.uniform3fv(e,t)},a.prototype.setArray4=function(e,t){e&&t.length%4===0&&this._gl.uniform4fv(e,t)},a.prototype.setMatrices=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t)},a.prototype.setMatrix=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t.toArray())},a.prototype.setMatrix3x3=function(e,t){e&&this._gl.uniformMatrix3fv(e,!1,t)},a.prototype.setMatrix2x2=function(e,t){e&&this._gl.uniformMatrix2fv(e,!1,t)},a.prototype.setFloat=function(e,t){e&&this._gl.uniform1f(e,t)},a.prototype.setFloat2=function(e,t,i){e&&this._gl.uniform2f(e,t,i)},a.prototype.setFloat3=function(e,t,i,r){e&&this._gl.uniform3f(e,t,i,r)},a.prototype.setBool=function(e,t){e&&this._gl.uniform1i(e,t)},a.prototype.setFloat4=function(e,t,i,r,n){e&&this._gl.uniform4f(e,t,i,r,n)},a.prototype.setColor3=function(e,t){e&&this._gl.uniform3f(e,t.r,t.g,t.b)},a.prototype.setColor4=function(e,t,i){e&&this._gl.uniform4f(e,t.r,t.g,t.b,i)},a.prototype.setState=function(e,t,i){void 0===t&&(t=0),(this._depthCullingState.cull!==e||i)&&(e?(this._depthCullingState.cullFace=this.cullBackFaces?this._gl.BACK:this._gl.FRONT,this._depthCullingState.cull=!0):this._depthCullingState.cull=!1),this._depthCullingState.zOffset=t},a.prototype.setDepthBuffer=function(e){this._depthCullingState.depthTest=e},a.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},a.prototype.setDepthWrite=function(e){this._depthCullingState.depthMask=e},a.prototype.setColorWrite=function(e){this._gl.colorMask(e,e,e,e)},a.prototype.setAlphaMode=function(e){if(this._alphaMode!=e){switch(e){case a.ALPHA_DISABLE:this.setDepthWrite(!0),this._alphaState.alphaBlend=!1;break;case a.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 a.ALPHA_ONEONE:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_ADD:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_SUBTRACT:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_MULTIPLY:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR,this._gl.ZERO,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case a.ALPHA_MAXIMIZED:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0}this._alphaMode=e}},a.prototype.getAlphaMode=function(){return this._alphaMode},a.prototype.setAlphaTesting=function(e){this._alphaTest=e},a.prototype.getAlphaTesting=function(){return this._alphaTest},a.prototype.wipeCaches=function(){this._activeTexturesCache=[],this._currentEffect=null,this._depthCullingState.reset(),this._alphaState.reset(),this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null},a.prototype.setSamplingMode=function(t,i){var r=this._gl;r.bindTexture(r.TEXTURE_2D,t);var n=r.NEAREST,o=r.NEAREST;i===e.Texture.BILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=r.LINEAR):i===e.Texture.TRILINEAR_SAMPLINGMODE&&(n=r.LINEAR,o=r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,n),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,o),r.bindTexture(r.TEXTURE_2D,null),t.samplingMode=i},a.prototype.createTexture=function(t,i,r,n,o,a,h,l){var c=this;void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),void 0===l&&(l=null);var u,f=this._gl.createTexture(),d=!1;if("data:"===t.substr(0,5)&&(d=!0),d){var p=t;d=p.split(":"),t=p,u=d[1].substr(d[1].length-4,4).toLowerCase()}else u=t.substr(t.length-4,4).toLowerCase();var m=this.getCaps().s3tc&&".dds"===u,g=".tga"===u;n._addPendingData(f),f.url=t,f.noMipmap=i,f.references=1,f.samplingMode=o,this._loadedTexturesCache.push(f);var _=function(){n._removePendingData(f),h&&h()};if(g){var v=function(t){var h=new Uint8Array(t),l=e.Internals.TGATools.GetTGAHeader(h);s(f,c._gl,n,l.width,l.height,r,i,!1,function(){e.Internals.TGATools.UploadContent(c._gl,h),a&&a()},o)};d instanceof Array?v(l):e.Tools.LoadFile(t,function(e){v(e)},_,n.database,!0)}else if(m)v=function(t){var h=e.Internals.DDSTools.GetDDSInfo(t),l=(h.isRGB||h.isLuminance||h.mipmapCount>1)&&!i&&h.width>>h.mipmapCount-1===1;s(f,c._gl,n,h.width,h.height,r,!l,h.isFourCC,function(){e.Internals.DDSTools.UploadDDSLevels(c._gl,c.getCaps().s3tc,t,h,l,1),a&&a()},o)},d instanceof Array?v(l):e.Tools.LoadFile(t,function(e){v(e)},_,n.database,!0);else{var y=function(t){s(f,c._gl,n,t.width,t.height,r,i,!1,function(i,r){var n=t.width===i&&t.height===r;n||(c._prepareWorkingCanvas(),c._workingCanvas.width=i,c._workingCanvas.height=r,o===e.Texture.NEAREST_SAMPLINGMODE&&(c._workingContext.imageSmoothingEnabled=!1,c._workingContext.mozImageSmoothingEnabled=!1,c._workingContext.oImageSmoothingEnabled=!1,c._workingContext.webkitImageSmoothingEnabled=!1,c._workingContext.msImageSmoothingEnabled=!1),c._workingContext.drawImage(t,0,0,t.width,t.height,0,0,i,r),o===e.Texture.NEAREST_SAMPLINGMODE&&(c._workingContext.imageSmoothingEnabled=!0,c._workingContext.mozImageSmoothingEnabled=!0,c._workingContext.oImageSmoothingEnabled=!0,c._workingContext.webkitImageSmoothingEnabled=!0,c._workingContext.msImageSmoothingEnabled=!0)),c._gl.texImage2D(c._gl.TEXTURE_2D,0,c._gl.RGBA,c._gl.RGBA,c._gl.UNSIGNED_BYTE,n?t:c._workingCanvas),a&&a()},o)};d instanceof Array?e.Tools.LoadImage(l,y,_,n.database):e.Tools.LoadImage(t,y,_,n.database)}return f},a.prototype.updateRawTexture=function(e,t,i,r,n){void 0===n&&(n=null);var o=this._gl.RGBA;switch(i){case a.TEXTUREFORMAT_ALPHA:o=this._gl.ALPHA;break;case a.TEXTUREFORMAT_LUMINANCE:o=this._gl.LUMINANCE;break;case a.TEXTUREFORMAT_LUMINANCE_ALPHA:o=this._gl.LUMINANCE_ALPHA;break;case a.TEXTUREFORMAT_RGB:o=this._gl.RGB;break;case a.TEXTUREFORMAT_RGBA:o=this._gl.RGBA}this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,void 0===r?1:r?1:0),n?this._gl.compressedTexImage2D(this._gl.TEXTURE_2D,0,this.getCaps().s3tc[n],e._width,e._height,0,t):this._gl.texImage2D(this._gl.TEXTURE_2D,0,o,e._width,e._height,0,o,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],e.isReady=!0},a.prototype.createRawTexture=function(e,t,i,r,n,s,a,h){void 0===h&&(h=null);var l=this._gl.createTexture();l._baseWidth=t,l._baseHeight=i,l._width=t,l._height=i,l.references=1,this.updateRawTexture(l,e,r,s,h),this._gl.bindTexture(this._gl.TEXTURE_2D,l);var c=o(a,n,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,c.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,c.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null),l.samplingMode=a,this._loadedTexturesCache.push(l),l},a.prototype.createDynamicTexture=function(t,i,r,n,o){void 0===o&&(o=!0);var s=this._gl.createTexture();return s._baseWidth=t,s._baseHeight=i,o&&(t=e.Tools.GetExponantOfTwo(t,this._caps.maxTextureSize),i=e.Tools.GetExponantOfTwo(i,this._caps.maxTextureSize)),this._activeTexturesCache=[],s._width=t,s._height=i,s.isReady=!1,s.generateMipMaps=r,s.references=1,s.samplingMode=n,this.updateTextureSamplingMode(n,s),this._loadedTexturesCache.push(s),s},a.prototype.updateTextureSamplingMode=function(e,t){var i=o(e,t.generateMipMaps,this._gl);this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,i.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,i.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null)},a.prototype.updateDynamicTexture=function(e,t,i){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?1:0),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],e.isReady=!0},a.prototype.updateVideoTexture=function(e,t,i){if(!e._isDisabled){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?0:1);try{void 0===this._videoTextureSupported&&(this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),this._videoTextureSupported=0!==this._gl.getError()?!1:!0),this._videoTextureSupported?this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t):(e._workingCanvas||(e._workingCanvas=document.createElement("canvas"),e._workingContext=e._workingCanvas.getContext("2d"),e._workingCanvas.width=e._width,e._workingCanvas.height=e._height),e._workingContext.drawImage(t,0,0,t.videoWidth,t.videoHeight,0,0,e._width,e._height),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,e._workingCanvas)),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],e.isReady=!0}catch(r){e._isDisabled=!0}}},a.prototype.createRenderTargetTexture=function(t,i){var r=!1,s=!0,h=a.TEXTURETYPE_UNSIGNED_INT,l=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==i&&(r=void 0===i.generateMipMaps?i:i.generateMipmaps,s=void 0===i.generateDepthBuffer?!0:i.generateDepthBuffer,h=void 0===i.type?h:i.type,void 0!==i.samplingMode&&(l=i.samplingMode),h===a.TEXTURETYPE_FLOAT&&(l=e.Texture.NEAREST_SAMPLINGMODE));var c=this._gl,u=c.createTexture();c.bindTexture(c.TEXTURE_2D,u);var f=t.width||t,d=t.height||t,p=o(l,r,c);h!==a.TEXTURETYPE_FLOAT||this._caps.textureFloat||(h=a.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,p.mag),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,p.min),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,f,d,0,c.RGBA,n(c,h),null);var m;s&&(m=c.createRenderbuffer(),c.bindRenderbuffer(c.RENDERBUFFER,m),c.renderbufferStorage(c.RENDERBUFFER,c.DEPTH_COMPONENT16,f,d));var g=c.createFramebuffer();return c.bindFramebuffer(c.FRAMEBUFFER,g),c.framebufferTexture2D(c.FRAMEBUFFER,c.COLOR_ATTACHMENT0,c.TEXTURE_2D,u,0),s&&c.framebufferRenderbuffer(c.FRAMEBUFFER,c.DEPTH_ATTACHMENT,c.RENDERBUFFER,m),r&&this._gl.generateMipmap(this._gl.TEXTURE_2D),c.bindTexture(c.TEXTURE_2D,null),c.bindRenderbuffer(c.RENDERBUFFER,null),c.bindFramebuffer(c.FRAMEBUFFER,null),u._framebuffer=g,s&&(u._depthBuffer=m),u._width=f,u._height=d,u.isReady=!0,u.generateMipMaps=r,u.references=1,u.samplingMode=l,this._activeTexturesCache=[],this._loadedTexturesCache.push(u),u},a.prototype.createCubeTexture=function(t,i,r,n){var o=this,s=this._gl,a=s.createTexture();a.isCube=!0,a.url=t,a.references=1,this._loadedTexturesCache.push(a);var l=t.substr(t.length-4,4).toLowerCase(),c=this.getCaps().s3tc&&".dds"===l;return c?e.Tools.LoadFile(t,function(t){var i=e.Internals.DDSTools.GetDDSInfo(t),r=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!n;s.bindTexture(s.TEXTURE_CUBE_MAP,a),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,1),e.Internals.DDSTools.UploadDDSLevels(o._gl,o.getCaps().s3tc,t,i,r,6),n||i.isFourCC||1!==i.mipmapCount||s.generateMipmap(s.TEXTURE_CUBE_MAP),s.texParameteri(s.TEXTURE_CUBE_MAP,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_CUBE_MAP,s.TEXTURE_MIN_FILTER,r?s.LINEAR_MIPMAP_LINEAR:s.LINEAR),s.texParameteri(s.TEXTURE_CUBE_MAP,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_CUBE_MAP,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.bindTexture(s.TEXTURE_CUBE_MAP,null),o._activeTexturesCache=[],a._width=i.width,a._height=i.height,a.isReady=!0},null,null,!0):h(t,i,function(t){var i=e.Tools.GetExponantOfTwo(t[0].width,o._caps.maxCubemapTextureSize),r=i;o._prepareWorkingCanvas(),o._workingCanvas.width=i,o._workingCanvas.height=r;var h=[s.TEXTURE_CUBE_MAP_POSITIVE_X,s.TEXTURE_CUBE_MAP_POSITIVE_Y,s.TEXTURE_CUBE_MAP_POSITIVE_Z,s.TEXTURE_CUBE_MAP_NEGATIVE_X,s.TEXTURE_CUBE_MAP_NEGATIVE_Y,s.TEXTURE_CUBE_MAP_NEGATIVE_Z];s.bindTexture(s.TEXTURE_CUBE_MAP,a),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,0);for(var l=0;l<h.length;l++)o._workingContext.drawImage(t[l],0,0,t[l].width,t[l].height,0,0,i,r),s.texImage2D(h[l],0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,o._workingCanvas);n||s.generateMipmap(s.TEXTURE_CUBE_MAP),s.texParameteri(s.TEXTURE_CUBE_MAP,s.TEXTURE_MAG_FILTER,s.LINEAR),
  s.texParameteri(s.TEXTURE_CUBE_MAP,s.TEXTURE_MIN_FILTER,n?s.LINEAR:s.LINEAR_MIPMAP_LINEAR),s.texParameteri(s.TEXTURE_CUBE_MAP,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_CUBE_MAP,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.bindTexture(s.TEXTURE_CUBE_MAP,null),o._activeTexturesCache=[],a._width=i,a._height=r,a.isReady=!0},r),a},a.prototype._releaseTexture=function(e){var t=this._gl;e._framebuffer&&t.deleteFramebuffer(e._framebuffer),e._depthBuffer&&t.deleteRenderbuffer(e._depthBuffer),t.deleteTexture(e);for(var i=0;i<this._caps.maxTexturesImageUnits;i++)this._gl.activeTexture(this._gl["TEXTURE"+i]),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null),this._activeTexturesCache[i]=null;var r=this._loadedTexturesCache.indexOf(e);-1!==r&&this._loadedTexturesCache.splice(r,1)},a.prototype.bindSamplers=function(e){this._gl.useProgram(e.getProgram());for(var t=e.getSamplers(),i=0;i<t.length;i++){var r=e.getUniform(t[i]);this._gl.uniform1i(r,i)}this._currentEffect=null},a.prototype._bindTexture=function(e,t){this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._activeTexturesCache[e]=null},a.prototype.setTextureFromPostProcess=function(e,t){this._bindTexture(e,t._textures.data[t._currentRenderTextureInd])},a.prototype.setTexture=function(t,i){if(!(0>t)){if(!i||!i.isReady())return void(null!=this._activeTexturesCache[t]&&(this._gl.activeTexture(this._gl["TEXTURE"+t]),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null),this._activeTexturesCache[t]=null));if(i instanceof e.VideoTexture)i.update()&&(this._activeTexturesCache[t]=null);else if(i.delayLoadState===a.DELAYLOADSTATE_NOTLOADED)return void i.delayLoad();if(this._activeTexturesCache[t]!==i){this._activeTexturesCache[t]=i;var r=i.getInternalTexture();if(this._gl.activeTexture(this._gl["TEXTURE"+t]),r.isCube){if(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,r),r._cachedCoordinatesMode!==i.coordinatesMode){r._cachedCoordinatesMode=i.coordinatesMode;var n=i.coordinatesMode!==e.Texture.CUBIC_MODE&&i.coordinatesMode!==e.Texture.SKYBOX_MODE?this._gl.REPEAT:this._gl.CLAMP_TO_EDGE;this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_S,n),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_T,n)}this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP,i)}else{if(this._gl.bindTexture(this._gl.TEXTURE_2D,r),r._cachedWrapU!==i.wrapU)switch(r._cachedWrapU=i.wrapU,i.wrapU){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.MIRRORED_REPEAT)}if(r._cachedWrapV!==i.wrapV)switch(r._cachedWrapV=i.wrapV,i.wrapV){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.CLAMP_TO_EDGE);break;case e.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,i)}}}},a.prototype._setAnisotropicLevel=function(t,i){var r=this._caps.textureAnisotropicFilterExtension,n=i.anisotropicFilteringLevel;i.getInternalTexture().samplingMode===e.Texture.NEAREST_SAMPLINGMODE&&(n=1),r&&i._cachedAnisotropicFilteringLevel!==n&&(this._gl.texParameterf(t,r.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(n,this._caps.maxAnisotropy)),i._cachedAnisotropicFilteringLevel=n)},a.prototype.readPixels=function(e,t,i,r){var n=new Uint8Array(r*i*4);return this._gl.readPixels(e,t,i,r,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n},a.prototype.dispose=function(){for(this.hideLoadingUI(),this.stopRenderLoop();this.scenes.length;)this.scenes[0].dispose();a.audioEngine.dispose();for(var e in this._compiledEffects)this._gl.deleteProgram(this._compiledEffects[e]._program);for(var t in this._vertexAttribArrays)t>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[t]||this._gl.disableVertexAttribArray(t);this._gl=null,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)},a.prototype.displayLoadingUI=function(){var e=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 t=new Image;t.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==",t.style.position="absolute",t.style.left="50%",t.style.top="50%",t.style.marginLeft="-50px",t.style.marginTop="-50px",t.style.transition="transform 1.0s ease",t.style.webkitTransition="-webkit-transform 1.0s ease";var i=360,r=function(){i+=360,t.style.transform="rotateZ("+i+"deg)",t.style.webkitTransform="rotateZ("+i+"deg)"};t.addEventListener("transitionend",r),t.addEventListener("webkitTransitionEnd",r),this._loadingDiv.appendChild(t);var n=new Image;n.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=",n.style.position="absolute",n.style.left="50%",n.style.top="50%",n.style.marginLeft="-50px",n.style.marginTop="-50px",this._loadingDiv.appendChild(n),this._resizeLoadingUI=function(){var t=e.getRenderingCanvasClientRect();e._loadingDiv.style.position="absolute",e._loadingDiv.style.left=t.left+"px",e._loadingDiv.style.top=t.top+"px",e._loadingDiv.style.width=t.width+"px",e._loadingDiv.style.height=t.height+"px"},this._resizeLoadingUI(),window.addEventListener("resize",this._resizeLoadingUI),this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor,document.body.appendChild(this._loadingDiv),setTimeout(function(){e._loadingDiv.style.opacity="1",t.style.transform="rotateZ(360deg)",t.style.webkitTransform="rotateZ(360deg)"},0)},Object.defineProperty(a.prototype,"loadingUIText",{set:function(e){this._loadingDiv&&(this._loadingTextDiv.innerHTML=e)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"loadingUIBackgroundColor",{get:function(){return this._loadingDivBackgroundColor},set:function(e){this._loadingDivBackgroundColor=e,this._loadingDiv&&(this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor)},enumerable:!0,configurable:!0}),a.prototype.hideLoadingUI=function(){var e=this;if(this._loadingDiv){var t=function(){e._loadingDiv&&(document.body.removeChild(e._loadingDiv),window.removeEventListener("resize",e._resizeLoadingUI),e._loadingDiv=null)};this._loadingDiv.style.opacity="0",this._loadingDiv.addEventListener("transitionend",t)}},a.prototype.getFps=function(){return this.fps},a.prototype.getDeltaTime=function(){return this.deltaTime},a.prototype._measureFps=function(){this.previousFramesDuration.push(e.Tools.Now);var t=this.previousFramesDuration.length;if(t>=2&&(this.deltaTime=this.previousFramesDuration[t-1]-this.previousFramesDuration[t-2]),t>=this.fpsRange){t>this.fpsRange&&(this.previousFramesDuration.splice(0,1),t=this.previousFramesDuration.length);for(var i=0,r=0;t-1>r;r++)i+=this.previousFramesDuration[r+1]-this.previousFramesDuration[r];this.fps=1e3/(i/(t-1))}},a.isSupported=function(){try{if(navigator.isCocoonJS)return!0;var e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");return null!=t&&!!window.WebGLRenderingContext}catch(i){return!1}},a._ALPHA_DISABLE=0,a._ALPHA_ADD=1,a._ALPHA_COMBINE=2,a._ALPHA_SUBTRACT=3,a._ALPHA_MULTIPLY=4,a._ALPHA_MAXIMIZED=5,a._ALPHA_ONEONE=6,a._DELAYLOADSTATE_NONE=0,a._DELAYLOADSTATE_LOADED=1,a._DELAYLOADSTATE_LOADING=2,a._DELAYLOADSTATE_NOTLOADED=4,a._TEXTUREFORMAT_ALPHA=0,a._TEXTUREFORMAT_LUMINANCE=1,a._TEXTUREFORMAT_LUMINANCE_ALPHA=2,a._TEXTUREFORMAT_RGB=4,a._TEXTUREFORMAT_RGBA=5,a._TEXTURETYPE_UNSIGNED_INT=0,a._TEXTURETYPE_FLOAT=1,a.Epsilon=.001,a.CollisionsEpsilon=.001,a.CodeRepository="src/",a.ShadersRepository="src/Shaders/",a}();e.Engine=c}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t){this.state="",this.animations=new Array,this._childrenFlag=-1,this._isEnabled=!0,this._isReady=!0,this._currentRenderId=-1,this._parentRenderId=-1,this.name=e,this.id=e,this._scene=t,this._initCache()}return t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._scene.getEngine()},t.prototype.getWorldMatrix=function(){return e.Matrix.Identity()},t.prototype._initCache=function(){this._cache={},this._cache.parent=void 0},t.prototype.updateCache=function(e){(e||!this.isSynchronized())&&(this._cache.parent=this.parent,this._updateCache())},t.prototype._updateCache=function(e){},t.prototype._isSynchronized=function(){return!0},t.prototype._markSyncedWithParent=function(){this._parentRenderId=this.parent._currentRenderId},t.prototype.isSynchronizedWithParent=function(){return this.parent?this._parentRenderId!==this.parent._currentRenderId?!1:this.parent.isSynchronized():!0},t.prototype.isSynchronized=function(e){var t=this.hasNewParent();return t=t||!this.isSynchronizedWithParent(),t=t||!this._isSynchronized(),e&&this.updateCache(!0),!t},t.prototype.hasNewParent=function(e){return this._cache.parent===this.parent?!1:(e&&(this._cache.parent=this.parent),!0)},t.prototype.isReady=function(){return this._isReady},t.prototype.isEnabled=function(){return this._isEnabled?this.parent?this.parent.isEnabled():!0:!1},t.prototype.setEnabled=function(e){this._isEnabled=e},t.prototype.isDescendantOf=function(e){return this.parent?this.parent===e?!0:this.parent.isDescendantOf(e):!1},t.prototype._getDescendants=function(e,t){for(var i=0;i<e.length;i++){var r=e[i];r.isDescendantOf(this)&&t.push(r)}},t.prototype.getDescendants=function(){var e=[];return this._getDescendants(this._scene.meshes,e),this._getDescendants(this._scene.lights,e),this._getDescendants(this._scene.cameras,e),e},t.prototype._setReady=function(e){if(e!=this._isReady){if(!e)return void(this._isReady=!1);this._isReady=!0,this.onReady&&this.onReady(this)}},t}();e.Node=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,r,n,o,s,a){this._engine=e,this._canvas=i,this._currentScene=t,this._sceneLoadedCallback=r,this._progressCallback=n,this._additionnalRenderLoopLogicCallback=o,this._textureLoadingCallback=s,this._startingProcessingFilesCallback=a}return t.prototype.monitorElementForDragNDrop=function(e){var t=this;e&&(this._elementToMonitor=e,this._elementToMonitor.addEventListener("dragenter",function(e){t.drag(e)},!1),this._elementToMonitor.addEventListener("dragover",function(e){t.drag(e)},!1),this._elementToMonitor.addEventListener("drop",function(e){t.drop(e)},!1))},t.prototype.renderFunction=function(){if(this._additionnalRenderLoopLogicCallback&&this._additionnalRenderLoopLogicCallback(),this._currentScene){if(this._textureLoadingCallback){var e=this._currentScene.getWaitingItemsCount();e>0&&this._textureLoadingCallback(e)}this._currentScene.render()}},t.prototype.drag=function(e){e.stopPropagation(),e.preventDefault()},t.prototype.drop=function(e){e.stopPropagation(),e.preventDefault(),this.loadFiles(e)},t.prototype.loadFiles=function(e){if(this._startingProcessingFilesCallback&&this._startingProcessingFilesCallback(),e&&e.dataTransfer&&e.dataTransfer.files&&(this._filesToLoad=e.dataTransfer.files),e&&e.target&&e.target.files&&(this._filesToLoad=e.target.files),this._filesToLoad&&this._filesToLoad.length>0){for(var i=0;i<this._filesToLoad.length;i++)switch(this._filesToLoad[i].type){case"image/jpeg":case"image/png":case"image/bmp":t.FilesTextures[this._filesToLoad[i].name]=this._filesToLoad[i];break;case"image/targa":case"image/vnd.ms-dds":case"audio/wav":case"audio/x-wav":case"audio/mp3":case"audio/mpeg":case"audio/mpeg3":case"audio/x-mpeg-3":case"audio/ogg":t.FilesToLoad[this._filesToLoad[i].name]=this._filesToLoad[i];break;default:-1!==this._filesToLoad[i].name.indexOf(".babylon")&&-1===this._filesToLoad[i].name.indexOf(".manifest")&&-1===this._filesToLoad[i].name.indexOf(".incremental")&&-1===this._filesToLoad[i].name.indexOf(".babylonmeshdata")&&-1===this._filesToLoad[i].name.indexOf(".babylongeometrydata")&&-1===this._filesToLoad[i].name.indexOf(".babylonbinarymeshdata")&&-1===this._filesToLoad[i].name.indexOf(".binary.babylon")&&(this._sceneFileToLoad=this._filesToLoad[i])}this.reload()}},t.prototype.reload=function(){var t=this,i=this;this._sceneFileToLoad?(this._currentScene&&(e.Tools.errorsCount>0&&(e.Tools.ClearLogCache(),e.Tools.Log("Babylon.js engine (v"+e.Engine.Version+") launched")),this._engine.stopRenderLoop(),this._currentScene.dispose()),e.SceneLoader.Load("file:",this._sceneFileToLoad,this._engine,function(e){i._currentScene=e,i._currentScene.executeWhenReady(function(){i._currentScene.activeCamera&&0!==i._currentScene.lights.length||i._currentScene.createDefaultCameraOrLight(),i._currentScene.activeCamera.attachControl(i._canvas),i._sceneLoadedCallback&&i._sceneLoadedCallback(t._sceneFileToLoad,i._currentScene),i._engine.runRenderLoop(function(){i.renderFunction()})})},function(e){t._progressCallback&&t._progressCallback(e)})):e.Tools.Error("Please provide a valid .babylon file.")},t.FilesTextures=new Array,t.FilesToLoad=new Array,t}();e.FilesInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,i){this.bu=e,this.bv=t,this.distance=i,this.faceId=0,this.subMeshId=0}return e}();e.IntersectionInfo=t;var i=function(){function t(){this.hit=!1,this.distance=0,this.pickedPoint=null,this.pickedMesh=null,this.bu=0,this.bv=0,this.faceId=-1,this.subMeshId=0}return t.prototype.getNormal=function(t,i){if(void 0===t&&(t=!1),void 0===i&&(i=!0),!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.NormalKind))return null;var r,n=this.pickedMesh.getIndices();if(i){var o=this.pickedMesh.getVerticesData(e.VertexBuffer.NormalKind),s=e.Vector3.FromArray(o,3*n[3*this.faceId]),a=e.Vector3.FromArray(o,3*n[3*this.faceId+1]),h=e.Vector3.FromArray(o,3*n[3*this.faceId+2]);s=s.scale(this.bu),a=a.scale(this.bv),h=h.scale(1-this.bu-this.bv),r=new e.Vector3(s.x+a.x+h.x,s.y+a.y+h.y,s.z+a.z+h.z)}else{var l=this.pickedMesh.getVerticesData(e.VertexBuffer.PositionKind),c=e.Vector3.FromArray(l,3*n[3*this.faceId]),u=e.Vector3.FromArray(l,3*n[3*this.faceId+1]),f=e.Vector3.FromArray(l,3*n[3*this.faceId+2]),d=c.subtract(u),p=f.subtract(u);r=e.Vector3.Cross(d,p)}return t&&(r=e.Vector3.TransformNormal(r,this.pickedMesh.getWorldMatrix())),e.Vector3.Normalize(r)},t.prototype.getTextureCoordinates=function(){if(!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.UVKind))return null;var t=this.pickedMesh.getIndices(),i=this.pickedMesh.getVerticesData(e.VertexBuffer.UVKind),r=e.Vector2.FromArray(i,2*t[3*this.faceId]),n=e.Vector2.FromArray(i,2*t[3*this.faceId+1]),o=e.Vector2.FromArray(i,2*t[3*this.faceId+2]);return r=r.scale(1-this.bu-this.bv),n=n.scale(this.bu),o=o.scale(this.bv),new e.Vector2(r.x+n.x+o.x,r.y+n.y+o.y)},t}();e.PickingInfo=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.minimum=t,this.maximum=i,this._tempRadiusVector=e.Vector3.Zero();var r=e.Vector3.Distance(t,i);this.center=e.Vector3.Lerp(t,i,.5),this.radius=.5*r,this.centerWorld=e.Vector3.Zero(),this._update(e.Matrix.Identity())}return t.prototype._update=function(t){e.Vector3.TransformCoordinatesToRef(this.center,t,this.centerWorld),e.Vector3.TransformNormalFromFloatsToRef(1,1,1,t,this._tempRadiusVector),this.radiusWorld=Math.max(Math.abs(this._tempRadiusVector.x),Math.abs(this._tempRadiusVector.y),Math.abs(this._tempRadiusVector.z))*this.radius},t.prototype.isInFrustum=function(e){for(var t=0;6>t;t++)if(e[t].dotCoordinate(this.centerWorld)<=-this.radiusWorld)return!1;return!0},t.prototype.intersectsPoint=function(t){var i=this.centerWorld.x-t.x,r=this.centerWorld.y-t.y,n=this.centerWorld.z-t.z,o=Math.sqrt(i*i+r*r+n*n);return Math.abs(this.radiusWorld-o)<e.Engine.Epsilon?!1:!0},t.Intersects=function(e,t){var i=e.centerWorld.x-t.centerWorld.x,r=e.centerWorld.y-t.centerWorld.y,n=e.centerWorld.z-t.centerWorld.z,o=Math.sqrt(i*i+r*r+n*n);return e.radiusWorld+t.radiusWorld<o?!1:!0},t}();e.BoundingSphere=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.minimum=t,this.maximum=i,this.vectors=new Array,this.vectorsWorld=new Array,this.vectors.push(this.minimum.clone()),this.vectors.push(this.maximum.clone()),this.vectors.push(this.minimum.clone()),this.vectors[2].x=this.maximum.x,this.vectors.push(this.minimum.clone()),this.vectors[3].y=this.maximum.y,this.vectors.push(this.minimum.clone()),this.vectors[4].z=this.maximum.z,this.vectors.push(this.maximum.clone()),this.vectors[5].z=this.minimum.z,this.vectors.push(this.maximum.clone()),this.vectors[6].x=this.minimum.x,this.vectors.push(this.maximum.clone()),this.vectors[7].y=this.minimum.y,this.center=this.maximum.add(this.minimum).scale(.5),this.extendSize=this.maximum.subtract(this.minimum).scale(.5),this.directions=[e.Vector3.Zero(),e.Vector3.Zero(),e.Vector3.Zero()];for(var r=0;r<this.vectors.length;r++)this.vectorsWorld[r]=e.Vector3.Zero();this.minimumWorld=e.Vector3.Zero(),this.maximumWorld=e.Vector3.Zero(),this._update(e.Matrix.Identity())}return t.prototype.getWorldMatrix=function(){return this._worldMatrix},t.prototype._update=function(t){e.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this.minimumWorld),e.Vector3.FromFloatsToRef(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE,this.maximumWorld);for(var i=0;i<this.vectors.length;i++){var r=this.vectorsWorld[i];e.Vector3.TransformCoordinatesToRef(this.vectors[i],t,r),r.x<this.minimumWorld.x&&(this.minimumWorld.x=r.x),r.y<this.minimumWorld.y&&(this.minimumWorld.y=r.y),r.z<this.minimumWorld.z&&(this.minimumWorld.z=r.z),r.x>this.maximumWorld.x&&(this.maximumWorld.x=r.x),r.y>this.maximumWorld.y&&(this.maximumWorld.y=r.y),r.z>this.maximumWorld.z&&(this.maximumWorld.z=r.z)}this.maximumWorld.addToRef(this.minimumWorld,this.center),this.center.scaleInPlace(.5),e.Vector3.FromFloatArrayToRef(t.m,0,this.directions[0]),e.Vector3.FromFloatArrayToRef(t.m,4,this.directions[1]),e.Vector3.FromFloatArrayToRef(t.m,8,this.directions[2]),this._worldMatrix=t},t.prototype.isInFrustum=function(e){return t.IsInFrustum(this.vectorsWorld,e)},t.prototype.isCompletelyInFrustum=function(e){return t.IsCompletelyInFrustum(this.vectorsWorld,e)},t.prototype.intersectsPoint=function(t){var i=-e.Engine.Epsilon;return this.maximumWorld.x-t.x<i||i>t.x-this.minimumWorld.x?!1:this.maximumWorld.y-t.y<i||i>t.y-this.minimumWorld.y?!1:this.maximumWorld.z-t.z<i||i>t.z-this.minimumWorld.z?!1:!0},t.prototype.intersectsSphere=function(e){return t.IntersectsSphere(this.minimumWorld,this.maximumWorld,e.centerWorld,e.radiusWorld)},t.prototype.intersectsMinMax=function(e,t){return this.maximumWorld.x<e.x||this.minimumWorld.x>t.x?!1:this.maximumWorld.y<e.y||this.minimumWorld.y>t.y?!1:this.maximumWorld.z<e.z||this.minimumWorld.z>t.z?!1:!0},t.Intersects=function(e,t){return e.maximumWorld.x<t.minimumWorld.x||e.minimumWorld.x>t.maximumWorld.x?!1:e.maximumWorld.y<t.minimumWorld.y||e.minimumWorld.y>t.maximumWorld.y?!1:e.maximumWorld.z<t.minimumWorld.z||e.minimumWorld.z>t.maximumWorld.z?!1:!0},t.IntersectsSphere=function(t,i,r,n){var o=e.Vector3.Clamp(r,t,i),s=e.Vector3.DistanceSquared(r,o);return n*n>=s},t.IsCompletelyInFrustum=function(e,t){for(var i=0;6>i;i++)for(var r=0;8>r;r++)if(t[i].dotCoordinate(e[r])<0)return!1;return!0},t.IsInFrustum=function(e,t){for(var i=0;6>i;i++){for(var r=8,n=0;8>n&&t[i].dotCoordinate(e[n])<0;n++)--r;if(0===r)return!1}return!0},t}();e.BoundingBox=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t,i){var r=e.Vector3.Dot(i.center,t),n=Math.abs(e.Vector3.Dot(i.directions[0],t))*i.extendSize.x,o=Math.abs(e.Vector3.Dot(i.directions[1],t))*i.extendSize.y,s=Math.abs(e.Vector3.Dot(i.directions[2],t))*i.extendSize.z,a=n+o+s;return{min:r-a,max:r+a}},i=function(e,t,i,r){return!(e>r||i>t)},r=function(e,r,n){var o=t(e,r),s=t(e,n);return i(o.min,o.max,s.min,s.max)},n=function(){function t(t,i){this.minimum=t,this.maximum=i,this.boundingBox=new e.BoundingBox(t,i),this.boundingSphere=new e.BoundingSphere(t,i)}return t.prototype._update=function(e){this.boundingBox._update(e),this.boundingSphere._update(e)},t.prototype.isInFrustum=function(e){return this.boundingSphere.isInFrustum(e)?this.boundingBox.isInFrustum(e):!1},t.prototype.isCompletelyInFrustum=function(e){return this.boundingBox.isCompletelyInFrustum(e)},t.prototype._checkCollision=function(e){return e._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld)},t.prototype.intersectsPoint=function(e){return this.boundingSphere.centerWorld&&this.boundingSphere.intersectsPoint(e)&&this.boundingBox.intersectsPoint(e)?!0:!1},t.prototype.intersects=function(t,i){if(!this.boundingSphere.centerWorld||!t.boundingSphere.centerWorld)return!1;if(!e.BoundingSphere.Intersects(this.boundingSphere,t.boundingSphere))return!1;if(!e.BoundingBox.Intersects(this.boundingBox,t.boundingBox))return!1;if(!i)return!0;var n=this.boundingBox,o=t.boundingBox;return r(n.directions[0],n,o)&&r(n.directions[1],n,o)&&r(n.directions[2],n,o)&&r(o.directions[0],n,o)&&r(o.directions[1],n,o)&&r(o.directions[2],n,o)&&r(e.Vector3.Cross(n.directions[0],o.directions[0]),n,o)&&r(e.Vector3.Cross(n.directions[0],o.directions[1]),n,o)&&r(e.Vector3.Cross(n.directions[0],o.directions[2]),n,o)&&r(e.Vector3.Cross(n.directions[1],o.directions[0]),n,o)&&r(e.Vector3.Cross(n.directions[1],o.directions[1]),n,o)&&r(e.Vector3.Cross(n.directions[1],o.directions[2]),n,o)&&r(e.Vector3.Cross(n.directions[2],o.directions[0]),n,o)&&r(e.Vector3.Cross(n.directions[2],o.directions[1]),n,o)&&r(e.Vector3.Cross(n.directions[2],o.directions[2]),n,o)?!0:!1},t}();e.BoundingInfo=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(r,n){var o=this;t.call(this,r,n),this.definedFacingForward=!0,this.position=new e.Vector3(0,0,0),this.rotation=new e.Vector3(0,0,0),this.scaling=new e.Vector3(1,1,1),this.billboardMode=i.BILLBOARDMODE_NONE,this.visibility=1,this.alphaIndex=Number.MAX_VALUE,this.infiniteDistance=!1,this.isVisible=!0,this.isPickable=!0,this.showBoundingBox=!1,this.showSubMeshesBoundingBox=!1,this.onDispose=null,this.isBlocker=!1,this.renderingGroupId=0,this.receiveShadows=!1,this.renderOutline=!1,this.outlineColor=e.Color3.Red(),this.outlineWidth=.02,this.renderOverlay=!1,this.overlayColor=e.Color3.Red(),this.overlayAlpha=.5,this.hasVertexAlpha=!1,this.useVertexColors=!0,this.applyFog=!0,this.computeBonesUsingShaders=!0,this.useOctreeForRenderingSelection=!0,this.useOctreeForPicking=!0,this.useOctreeForCollisions=!0,this.layerMask=268435455,this.alwaysSelectAsActiveMesh=!1,this._physicImpostor=e.PhysicsEngine.NoImpostor,this._checkCollisions=!1,this.ellipsoid=new e.Vector3(.5,1,.5),this.ellipsoidOffset=new e.Vector3(0,0,0),this._collider=new e.Collider,this._oldPositionForCollisions=new e.Vector3(0,0,0),this._diffPositionForCollisions=new e.Vector3(0,0,0),this._newPositionForCollisions=new e.Vector3(0,0,0),this.edgesWidth=1,this.edgesColor=new e.Color4(1,0,0,1),this._localScaling=e.Matrix.Zero(),this._localRotation=e.Matrix.Zero(),this._localTranslation=e.Matrix.Zero(),this._localBillboard=e.Matrix.Zero(),this._localPivotScaling=e.Matrix.Zero(),this._localPivotScalingRotation=e.Matrix.Zero(),this._localWorld=e.Matrix.Zero(),this._worldMatrix=e.Matrix.Zero(),this._rotateYByPI=e.Matrix.RotationY(Math.PI),this._absolutePosition=e.Vector3.Zero(),this._collisionsTransformMatrix=e.Matrix.Zero(),this._collisionsScalingMatrix=e.Matrix.Zero(),this._isDirty=!1,this._pivotMatrix=e.Matrix.Identity(),this._isDisposed=!1,this._renderId=0,this._intersectionsInProgress=new Array,this._onAfterWorldMatrixUpdate=new Array,this._isWorldMatrixFrozen=!1,this._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=null),o.getScene().workerCollisions&&i.multiplyInPlace(o._collider.radius),i.subtractToRef(o._oldPositionForCollisions,o._diffPositionForCollisions),o._diffPositionForCollisions.length()>e.Engine.CollisionsEpsilon&&o.position.addInPlace(o._diffPositionForCollisions),o.onCollide&&r&&o.onCollide(r)},n.addMesh(this)}return __extends(i,t),Object.defineProperty(i,"BILLBOARDMODE_NONE",{get:function(){return i._BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_X",{get:function(){return i._BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Y",{get:function(){return i._BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Z",{get:function(){return i._BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_ALL",{get:function(){return i._BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),i.prototype.disableEdgesRendering=function(){void 0!==this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=void 0)},i.prototype.enableEdgesRendering=function(t,i){void 0===t&&(t=.95),void 0===i&&(i=!1),this.disableEdgesRendering(),this._edgesRenderer=new e.EdgesRenderer(this,t,i)},Object.defineProperty(i.prototype,"isBlocked",{get:function(){return!1},enumerable:!0,configurable:!0}),i.prototype.getLOD=function(e){return this},i.prototype.getTotalVertices=function(){return 0},i.prototype.getIndices=function(){return null},i.prototype.getVerticesData=function(e){return null},i.prototype.isVerticesDataPresent=function(e){return!1},i.prototype.getBoundingInfo=function(){return this._masterMesh?this._masterMesh.getBoundingInfo():(this._boundingInfo||this._updateBoundingInfo(),this._boundingInfo)},Object.defineProperty(i.prototype,"useBones",{get:function(){return this.skeleton&&this.getScene().skeletonsEnabled&&this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)},enumerable:!0,configurable:!0}),i.prototype._preActivate=function(){},i.prototype._activate=function(e){this._renderId=e},i.prototype.getWorldMatrix=function(){return this._masterMesh?this._masterMesh.getWorldMatrix():(this._currentRenderId!==this.getScene().getRenderId()&&this.computeWorldMatrix(),this._worldMatrix)},Object.defineProperty(i.prototype,"worldMatrixFromCache",{get:function(){return this._worldMatrix},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"absolutePosition",{get:function(){return this._absolutePosition},enumerable:!0,configurable:!0}),i.prototype.freezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this._isWorldMatrixFrozen=!0},i.prototype.unfreezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0)},Object.defineProperty(i.prototype,"isWorldMatrixFrozen",{get:function(){return this._isWorldMatrixFrozen;
  
  },enumerable:!0,configurable:!0}),i.prototype.rotate=function(t,i,r){if(t.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=e.Vector3.Zero()),r&&r!==e.Space.LOCAL){if(this.parent){var n=this.parent.getWorldMatrix().clone();n.invert(),t=e.Vector3.TransformNormal(t,n)}o=e.Quaternion.RotationAxis(t,i),this.rotationQuaternion=o.multiply(this.rotationQuaternion)}else{var o=e.Quaternion.RotationAxis(t,i);this.rotationQuaternion=this.rotationQuaternion.multiply(o)}},i.prototype.translate=function(t,i,r){var n=t.scale(i);if(r&&r!==e.Space.LOCAL)this.setAbsolutePosition(this.getAbsolutePosition().add(n));else{var o=this.getPositionExpressedInLocalSpace().add(n);this.setPositionWithLocalVector(o)}},i.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},i.prototype.setAbsolutePosition=function(t){if(t){var i,r,n;if(void 0===t.x){if(arguments.length<3)return;i=arguments[0],r=arguments[1],n=arguments[2]}else i=t.x,r=t.y,n=t.z;if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert();var s=new e.Vector3(i,r,n);this.position=e.Vector3.TransformCoordinates(s,o)}else this.position.x=i,this.position.y=r,this.position.z=n}},i.prototype.movePOV=function(e,t,i){this.position.addInPlace(this.calcMovePOV(e,t,i))},i.prototype.calcMovePOV=function(t,i,r){var n=new e.Matrix,o=this.rotationQuaternion?this.rotationQuaternion:e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z);o.toRotationMatrix(n);var s=e.Vector3.Zero(),a=this.definedFacingForward?-1:1;return e.Vector3.TransformCoordinatesFromFloatsToRef(t*a,i,r*a,n,s),s},i.prototype.rotatePOV=function(e,t,i){this.rotation.addInPlace(this.calcRotatePOV(e,t,i))},i.prototype.calcRotatePOV=function(t,i,r){var n=this.definedFacingForward?1:-1;return new e.Vector3(t*n,i,r*n)},i.prototype.setPivotMatrix=function(e){this._pivotMatrix=e,this._cache.pivotMatrixUpdated=!0},i.prototype.getPivotMatrix=function(){return this._pivotMatrix},i.prototype._isSynchronized=function(){if(this._isDirty)return!1;if(this.billboardMode!==i.BILLBOARDMODE_NONE)return!1;if(this._cache.pivotMatrixUpdated)return!1;if(this.infiniteDistance)return!1;if(!this._cache.position.equals(this.position))return!1;if(this.rotationQuaternion){if(!this._cache.rotationQuaternion.equals(this.rotationQuaternion))return!1}else if(!this._cache.rotation.equals(this.rotation))return!1;return this._cache.scaling.equals(this.scaling)?!0:!1},i.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.localMatrixUpdated=!1,this._cache.position=e.Vector3.Zero(),this._cache.scaling=e.Vector3.Zero(),this._cache.rotation=e.Vector3.Zero(),this._cache.rotationQuaternion=new e.Quaternion(0,0,0,0)},i.prototype.markAsDirty=function(e){"rotation"===e&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0},i.prototype._updateBoundingInfo=function(){this._boundingInfo=this._boundingInfo||new e.BoundingInfo(this.absolutePosition,this.absolutePosition),this._boundingInfo._update(this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)},i.prototype._updateSubMeshesBoundingInfo=function(e){if(this.subMeshes)for(var t=0;t<this.subMeshes.length;t++){var i=this.subMeshes[t];i.updateBoundingInfo(e)}},i.prototype.computeWorldMatrix=function(t){if(this._isWorldMatrixFrozen)return this._worldMatrix;if(!t&&(this._currentRenderId===this.getScene().getRenderId()||this.isSynchronized(!0)))return this._worldMatrix;if(this._cache.position.copyFrom(this.position),this._cache.scaling.copyFrom(this.scaling),this._cache.pivotMatrixUpdated=!1,this._currentRenderId=this.getScene().getRenderId(),this._isDirty=!1,e.Matrix.ScalingToRef(this.scaling.x,this.scaling.y,this.scaling.z,this._localScaling),this.rotationQuaternion?(this.rotationQuaternion.toRotationMatrix(this._localRotation),this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion)):(e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._localRotation),this._cache.rotation.copyFrom(this.rotation)),this.infiniteDistance&&!this.parent){var r=this.getScene().activeCamera;if(r){var n=r.getWorldMatrix(),o=new e.Vector3(n.m[12],n.m[13],n.m[14]);e.Matrix.TranslationToRef(this.position.x+o.x,this.position.y+o.y,this.position.z+o.z,this._localTranslation)}}else e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._localTranslation);if(this._pivotMatrix.multiplyToRef(this._localScaling,this._localPivotScaling),this._localPivotScaling.multiplyToRef(this._localRotation,this._localPivotScalingRotation),this.billboardMode!==i.BILLBOARDMODE_NONE&&this.getScene().activeCamera){var s=this.position.clone(),a=this.getScene().activeCamera.globalPosition.clone();this.parent&&this.parent.position&&(s.addInPlace(this.parent.position),e.Matrix.TranslationToRef(s.x,s.y,s.z,this._localTranslation)),(this.billboardMode&i.BILLBOARDMODE_ALL)!=i.BILLBOARDMODE_ALL&&(this.billboardMode&i.BILLBOARDMODE_X&&(a.x=s.x+e.Engine.Epsilon),this.billboardMode&i.BILLBOARDMODE_Y&&(a.y=s.y+.001),this.billboardMode&i.BILLBOARDMODE_Z&&(a.z=s.z+.001)),e.Matrix.LookAtLHToRef(s,a,e.Vector3.Up(),this._localBillboard),this._localBillboard.m[12]=this._localBillboard.m[13]=this._localBillboard.m[14]=0,this._localBillboard.invert(),this._localPivotScalingRotation.multiplyToRef(this._localBillboard,this._localWorld),this._rotateYByPI.multiplyToRef(this._localWorld,this._localPivotScalingRotation)}this._localPivotScalingRotation.multiplyToRef(this._localTranslation,this._localWorld),this.parent&&this.parent.getWorldMatrix&&this.billboardMode===i.BILLBOARDMODE_NONE?(this._markSyncedWithParent(),this._meshToBoneReferal?(this._localMeshReferalTransform||(this._localMeshReferalTransform=e.Matrix.Zero()),this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),this._localMeshReferalTransform),this._localMeshReferalTransform.multiplyToRef(this._meshToBoneReferal.getWorldMatrix(),this._worldMatrix)):this._localWorld.multiplyToRef(this.parent.getWorldMatrix(),this._worldMatrix)):this._worldMatrix.copyFrom(this._localWorld),this._updateBoundingInfo(),this._absolutePosition.copyFromFloats(this._worldMatrix.m[12],this._worldMatrix.m[13],this._worldMatrix.m[14]);for(var h=0;h<this._onAfterWorldMatrixUpdate.length;h++)this._onAfterWorldMatrixUpdate[h](this);return this._worldMatrix},i.prototype.registerAfterWorldMatrixUpdate=function(e){this._onAfterWorldMatrixUpdate.push(e)},i.prototype.unregisterAfterWorldMatrixUpdate=function(e){var t=this._onAfterWorldMatrixUpdate.indexOf(e);t>-1&&this._onAfterWorldMatrixUpdate.splice(t,1)},i.prototype.setPositionWithLocalVector=function(t){this.computeWorldMatrix(),this.position=e.Vector3.TransformNormal(t,this._localWorld)},i.prototype.getPositionExpressedInLocalSpace=function(){this.computeWorldMatrix();var t=this._localWorld.clone();return t.invert(),e.Vector3.TransformNormal(this.position,t)},i.prototype.locallyTranslate=function(t){this.computeWorldMatrix(!0),this.position=e.Vector3.TransformCoordinates(t,this._localWorld)},i.prototype.lookAt=function(t,i,r,n){i=i||0,r=r||0,n=n||0;var o=t.subtract(this.position),s=-Math.atan2(o.z,o.x)-Math.PI/2,a=Math.sqrt(o.x*o.x+o.z*o.z),h=Math.atan2(o.y,a);this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(s+i,h+r,n)},i.prototype.attachToBone=function(e,t){this._meshToBoneReferal=t,this.parent=e},i.prototype.detachFromBone=function(){this._meshToBoneReferal=null,this.parent=null},i.prototype.isInFrustum=function(e){return this._boundingInfo.isInFrustum(e)},i.prototype.isCompletelyInFrustum=function(t){t||(t=this.getScene().activeCamera);var i=t.getViewMatrix().multiply(t.getProjectionMatrix());return this._boundingInfo.isCompletelyInFrustum(e.Frustum.GetPlanes(i))?!0:!1},i.prototype.intersectsMesh=function(e,t){return this._boundingInfo&&e._boundingInfo?this._boundingInfo.intersects(e._boundingInfo,t):!1},i.prototype.intersectsPoint=function(e){return this._boundingInfo?this._boundingInfo.intersectsPoint(e):!1},i.prototype.setPhysicsState=function(t,i){var r=this.getScene().getPhysicsEngine();if(r)return t=t||e.PhysicsEngine.NoImpostor,t.impostor&&(i=t,t=t.impostor),t===e.PhysicsEngine.NoImpostor?void r._unregisterMesh(this):(i?(i.mass||0===i.mass||(i.mass=0),i.friction||0===i.friction||(i.friction=.2),i.restitution||0===i.restitution||(i.restitution=.2)):i={mass:0,friction:.2,restitution:.2},this._physicImpostor=t,this._physicsMass=i.mass,this._physicsFriction=i.friction,this._physicRestitution=i.restitution,r._registerMesh(this,t,i))},i.prototype.getPhysicsImpostor=function(){return this._physicImpostor?this._physicImpostor:e.PhysicsEngine.NoImpostor},i.prototype.getPhysicsMass=function(){return this._physicsMass?this._physicsMass:0},i.prototype.getPhysicsFriction=function(){return this._physicsFriction?this._physicsFriction:0},i.prototype.getPhysicsRestitution=function(){return this._physicRestitution?this._physicRestitution:0},i.prototype.getPositionInCameraSpace=function(t){return t||(t=this.getScene().activeCamera),e.Vector3.TransformCoordinates(this.absolutePosition,t.getViewMatrix())},i.prototype.getDistanceToCamera=function(e){return e||(e=this.getScene().activeCamera),this.absolutePosition.subtract(e.position).length()},i.prototype.applyImpulse=function(e,t){this._physicImpostor&&this.getScene().getPhysicsEngine()._applyImpulse(this,e,t)},i.prototype.setPhysicsLinkWith=function(e,t,i,r){this._physicImpostor&&this.getScene().getPhysicsEngine()._createLink(this,e,t,i,r)},i.prototype.updatePhysicsBodyPosition=function(){this._physicImpostor&&this.getScene().getPhysicsEngine()._updateBodyPosition(this)},Object.defineProperty(i.prototype,"checkCollisions",{get:function(){return this._checkCollisions},set:function(e){this._checkCollisions=e,this.getScene().workerCollisions&&this.getScene().collisionCoordinator.onMeshUpdated(this)},enumerable:!0,configurable:!0}),i.prototype.moveWithCollisions=function(e){var t=this.getAbsolutePosition();t.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPositionForCollisions),this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset),this._collider.radius=this.ellipsoid,this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions,e,this._collider,3,this,this._onCollisionPositionChange,this.uniqueId)},i.prototype.createOrUpdateSubmeshesOctree=function(t,i){void 0===t&&(t=64),void 0===i&&(i=2),this._submeshesOctree||(this._submeshesOctree=new e.Octree(e.Octree.CreationFuncForSubMeshes,t,i)),this.computeWorldMatrix(!0);var r=this.getBoundingInfo().boundingBox;return this._submeshesOctree.update(r.minimumWorld,r.maximumWorld,this.subMeshes),this._submeshesOctree},i.prototype._collideForSubMesh=function(t,i,r){if(this._generatePointsArray(),!t._lastColliderWorldVertices||!t._lastColliderTransformMatrix.equals(i)){t._lastColliderTransformMatrix=i.clone(),t._lastColliderWorldVertices=[],t._trianglePlanes=[];for(var n=t.verticesStart,o=t.verticesStart+t.verticesCount,s=n;o>s;s++)t._lastColliderWorldVertices.push(e.Vector3.TransformCoordinates(this._positions[s],i))}r._collide(t._trianglePlanes,t._lastColliderWorldVertices,this.getIndices(),t.indexStart,t.indexStart+t.indexCount,t.verticesStart,!!t.getMaterial()),r.collisionFound&&(r.collidedMesh=this)},i.prototype._processCollisionsForSubMeshes=function(e,t){var i,r;if(this._submeshesOctree&&this.useOctreeForCollisions){var n=e.velocityWorldLength+Math.max(e.radius.x,e.radius.y,e.radius.z),o=this._submeshesOctree.intersects(e.basePointWorld,n);r=o.length,i=o.data}else i=this.subMeshes,r=i.length;for(var s=0;r>s;s++){var a=i[s];r>1&&!a._checkCollision(e)||this._collideForSubMesh(a,t,e)}},i.prototype._checkCollision=function(t){this._boundingInfo._checkCollision(t)&&(e.Matrix.ScalingToRef(1/t.radius.x,1/t.radius.y,1/t.radius.z,this._collisionsScalingMatrix),this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix),this._processCollisionsForSubMeshes(t,this._collisionsTransformMatrix))},i.prototype._generatePointsArray=function(){return!1},i.prototype.intersects=function(t,i){var r=new e.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&t.intersectsSphere(this._boundingInfo.boundingSphere)&&t.intersectsBox(this._boundingInfo.boundingBox)))return r;if(!this._generatePointsArray())return r;var n,o,s=null;if(this._submeshesOctree&&this.useOctreeForPicking){var a=e.Ray.Transform(t,this.getWorldMatrix()),h=this._submeshesOctree.intersectsRay(a);o=h.length,n=h.data}else n=this.subMeshes,o=n.length;for(var l=0;o>l;l++){var c=n[l];if(!(o>1)||c.canIntersects(t)){var u=c.intersects(t,this._positions,this.getIndices(),i);if(u&&(i||!s||u.distance<s.distance)&&(s=u,s.subMeshId=l,i))break}}if(s){var f=this.getWorldMatrix(),d=e.Vector3.TransformCoordinates(t.origin,f),p=t.direction.clone();p=p.scale(s.distance);var m=e.Vector3.TransformNormal(p,f),g=d.add(m);return r.hit=!0,r.distance=e.Vector3.Distance(d,g),r.pickedPoint=g,r.pickedMesh=this,r.bu=s.bu,r.bv=s.bv,r.faceId=s.faceId,r.subMeshId=s.subMeshId,r}return r},i.prototype.clone=function(e,t,i){return null},i.prototype.releaseSubMeshes=function(){if(this.subMeshes)for(;this.subMeshes.length;)this.subMeshes[0].dispose();else this.subMeshes=new Array},i.prototype.dispose=function(t){var i;for(this.getPhysicsImpostor()!==e.PhysicsEngine.NoImpostor&&this.setPhysicsState(e.PhysicsEngine.NoImpostor),i=0;i<this._intersectionsInProgress.length;i++){var r=this._intersectionsInProgress[i],n=r._intersectionsInProgress.indexOf(this);r._intersectionsInProgress.splice(n,1)}if(this._intersectionsInProgress=[],this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=null),this.releaseSubMeshes(),this.getScene().removeMesh(this),t)for(i=0;i<this.getScene().meshes.length;i++){var o=this.getScene().meshes[i];o.parent===this&&(o.parent=null,o.computeWorldMatrix(!0))}else{for(i=0;i<this.getScene().particleSystems.length;i++)this.getScene().particleSystems[i].emitter===this&&(this.getScene().particleSystems[i].dispose(),i--);var s=this.getScene().meshes.slice(0);for(i=0;i<s.length;i++)s[i].parent===this&&s[i].dispose()}this._onAfterWorldMatrixUpdate=[],this._isDisposed=!0,this.onDispose&&this.onDispose()},i._BILLBOARDMODE_NONE=0,i._BILLBOARDMODE_X=1,i._BILLBOARDMODE_Y=2,i._BILLBOARDMODE_Z=4,i._BILLBOARDMODE_ALL=7,i}(e.Node);e.AbstractMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r){t.call(this,i,r),this.diffuse=new e.Color3(1,1,1),this.specular=new e.Color3(1,1,1),this.intensity=1,this.range=Number.MAX_VALUE,this.includeOnlyWithLayerMask=0,this.includedOnlyMeshes=new Array,this.excludedMeshes=new Array,this.excludeWithLayerMask=0,this._excludedMeshesIds=new Array,this._includedOnlyMeshesIds=new Array,r.addLight(this)}return __extends(i,t),i.prototype.getShadowGenerator=function(){return this._shadowGenerator},i.prototype.getAbsolutePosition=function(){return e.Vector3.Zero()},i.prototype.transferToEffect=function(e,t,i){},i.prototype._getWorldMatrix=function(){return e.Matrix.Identity()},i.prototype.canAffectMesh=function(e){return e?this.includedOnlyMeshes.length>0&&-1===this.includedOnlyMeshes.indexOf(e)?!1:this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)?!1:0!==this.includeOnlyWithLayerMask&&0===(this.includeOnlyWithLayerMask&e.layerMask)?!1:0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&e.layerMask?!1:!0:!0},i.prototype.getWorldMatrix=function(){this._currentRenderId=this.getScene().getRenderId();var t=this._getWorldMatrix();return this.parent&&this.parent.getWorldMatrix?(this._parentedWorldMatrix||(this._parentedWorldMatrix=e.Matrix.Identity()),t.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix),this._markSyncedWithParent(),this._parentedWorldMatrix):t},i.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().removeLight(this)},i}(e.Node);e.Light=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r){t.call(this,e,r),this.position=i}return __extends(i,t),i.prototype.getAbsolutePosition=function(){return this._transformedPosition?this._transformedPosition:this.position},i.prototype.transferToEffect=function(t,i){return this.parent&&this.parent.getWorldMatrix?(this._transformedPosition||(this._transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this._transformedPosition),void t.setFloat4(i,this._transformedPosition.x,this._transformedPosition.y,this._transformedPosition.z,0)):void t.setFloat4(i,this.position.x,this.position.y,this.position.z,0)},i.prototype.getShadowGenerator=function(){return null},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},i}(e.Light);e.PointLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r,n,o,s){t.call(this,e,s),this.position=i,this.direction=r,this.angle=n,this.exponent=o}return __extends(i,t),i.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},i.prototype.setShadowProjectionMatrix=function(t,i,r){var n=this.getScene().activeCamera;e.Matrix.PerspectiveFovLHToRef(this.angle,1,n.minZ,n.maxZ,t)},i.prototype.supportsVSM=function(){return!0},i.prototype.needRefreshPerFrame=function(){return!1},i.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},i.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},i.prototype.transferToEffect=function(t,i,r){var n;this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=e.Vector3.Zero()),this.computeTransformedPosition(),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),t.setFloat4(i,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent),n=e.Vector3.Normalize(this._transformedDirection)):(t.setFloat4(i,this.position.x,this.position.y,this.position.z,this.exponent),n=e.Vector3.Normalize(this.direction)),t.setFloat4(r,n.x,n.y,n.z,Math.cos(.5*this.angle))},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},i}(e.Light);e.SpotLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n){t.call(this,i,n),this.direction=r,this.groundColor=new e.Color3(0,0,0)}return __extends(i,t),i.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(e.Vector3.Zero())),this.direction},i.prototype.getShadowGenerator=function(){return null},i.prototype.transferToEffect=function(t,i,r){var n=e.Vector3.Normalize(this.direction);t.setFloat4(i,n.x,n.y,n.z,0),t.setColor3(r,this.groundColor.scale(this.intensity))},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._worldMatrix},i}(e.Light);e.HemisphericLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r){t.call(this,e,r),this.direction=i,this.shadowOrthoScale=.5,this.position=i.scale(-1)}return __extends(i,t),i.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},i.prototype.setDirectionToTarget=function(t){return this.direction=e.Vector3.Normalize(t.subtract(this.position)),this.direction},i.prototype.setShadowProjectionMatrix=function(t,i,r){for(var n=Number.MAX_VALUE,o=Number.MIN_VALUE,s=Number.MIN_VALUE,a=Number.MAX_VALUE,h=e.Vector3.Zero(),l=this.getScene().activeCamera,c=0;c<r.length;c++){var u=r[c];if(u){var f=u.getBoundingInfo();if(f)for(var d=f.boundingBox,p=0;p<d.vectorsWorld.length;p++)e.Vector3.TransformCoordinatesToRef(d.vectorsWorld[p],i,h),h.x<n&&(n=h.x),h.y<a&&(a=h.y),h.x>o&&(o=h.x),h.y>s&&(s=h.y)}}var m=o-n,g=s-a;e.Matrix.OrthoOffCenterLHToRef(n-m*this.shadowOrthoScale,o+m*this.shadowOrthoScale,a-g*this.shadowOrthoScale,s+g*this.shadowOrthoScale,-l.maxZ,l.maxZ,t)},i.prototype.supportsVSM=function(){return!0},i.prototype.needRefreshPerFrame=function(){return!0},i.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},i.prototype.transferToEffect=function(t,i){return this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=e.Vector3.Zero()),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),void t.setFloat4(i,this._transformedDirection.x,this._transformedDirection.y,this._transformedDirection.z,1)):void t.setFloat4(i,this.direction.x,this.direction.y,this.direction.z,1)},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},i}(e.Light);e.DirectionalLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(i,r){var n=this;this._filter=t.FILTER_NONE,this.blurScale=2,this._blurBoxOffset=0,this._bias=5e-5,this._lightDirection=e.Vector3.Zero(),this._darkness=0,this._transparencyShadow=!1,this._viewMatrix=e.Matrix.Zero(),this._projectionMatrix=e.Matrix.Zero(),this._transformMatrix=e.Matrix.Zero(),this._worldViewProjection=e.Matrix.Zero(),this._light=r,this._scene=r.getScene(),this._mapSize=i,r._shadowGenerator=this,this._shadowMap=new e.RenderTargetTexture(r.name+"_shadowMap",i,this._scene,!1),this._shadowMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(e.Texture.NEAREST_SAMPLINGMODE),this._shadowMap.renderParticles=!1,this._shadowMap.onAfterUnbind=function(){n.useBlurVarianceShadowMap&&(n._shadowMap2||(n._shadowMap2=new e.RenderTargetTexture(r.name+"_shadowMap",i,n._scene,!1),n._shadowMap2.wrapU=e.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.wrapV=e.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.updateSamplingMode(e.Texture.TRILINEAR_SAMPLINGMODE),n._downSamplePostprocess=new e.PassPostProcess("downScale",1/n.blurScale,null,e.Texture.BILINEAR_SAMPLINGMODE,n._scene.getEngine()),n._downSamplePostprocess.onApply=function(e){e.setTexture("textureSampler",n._shadowMap)},n.blurBoxOffset=1),n._scene.postProcessManager.directRender([n._downSamplePostprocess,n._boxBlurPostprocess],n._shadowMap2.getInternalTexture()))};var o=function(t){var i=t.getRenderingMesh(),r=n._scene,o=r.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id];if(n.isReady(t,a)){o.enableEffect(n._effect),i._bind(t,n._effect,e.Material.TriangleFillMode);var h=t.getMaterial();if(n._effect.setMatrix("viewProjection",n.getTransformMatrix()),h&&h.needAlphaTesting()){var l=h.getAlphaTestTexture();n._effect.setTexture("diffuseSampler",l),n._effect.setMatrix("diffuseMatrix",l.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&n._effect.setMatrices("mBones",i.skeleton.getTransformMatrices()),i._processRendering(t,n._effect,e.Material.TriangleFillMode,s,a,function(e,t){return n._effect.setMatrix("world",t)})}else n._shadowMap.resetRefreshCounter()}};this._shadowMap.customRenderFunction=function(e,t,i){var r;for(r=0;r<e.length;r++)o(e.data[r]);for(r=0;r<t.length;r++)o(t.data[r]);if(n._transparencyShadow)for(r=0;r<i.length;r++)o(i.data[r])},this._shadowMap.onClear=function(t){n.useBlurVarianceShadowMap||n.useVarianceShadowMap?t.clear(new e.Color4(0,0,0,0),!0,!0):t.clear(new e.Color4(1,1,1,1),!0,!0)}}return Object.defineProperty(t,"FILTER_NONE",{get:function(){return t._FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_VARIANCESHADOWMAP",{get:function(){return t._FILTER_VARIANCESHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_POISSONSAMPLING",{get:function(){return t._FILTER_POISSONSAMPLING},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FILTER_BLURVARIANCESHADOWMAP",{get:function(){return t._FILTER_BLURVARIANCESHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bias",{get:function(){return this._bias},set:function(e){this._bias=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"blurBoxOffset",{get:function(){return this._blurBoxOffset},set:function(t){var i=this;this._blurBoxOffset!==t&&(this._blurBoxOffset=t,this._boxBlurPostprocess&&this._boxBlurPostprocess.dispose(),this._boxBlurPostprocess=new e.PostProcess("DepthBoxBlur","depthBoxBlur",["screenSize","boxOffset"],[],1/this.blurScale,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define OFFSET "+t),this._boxBlurPostprocess.onApply=function(e){e.setFloat2("screenSize",i._mapSize/i.blurScale,i._mapSize/i.blurScale)})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"filter",{get:function(){return this._filter},set:function(t){this._filter!==t&&(this._filter=t,this.useVarianceShadowMap||this.useBlurVarianceShadowMap?(this._shadowMap.anisotropicFilteringLevel=16,this._shadowMap.updateSamplingMode(e.Texture.BILINEAR_SAMPLINGMODE)):(this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(e.Texture.NEAREST_SAMPLINGMODE)))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useVarianceShadowMap",{get:function(){return this.filter===t.FILTER_VARIANCESHADOWMAP&&this._light.supportsVSM()},set:function(e){this.filter=e?t.FILTER_VARIANCESHADOWMAP:t.FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"usePoissonSampling",{get:function(){return this.filter===t.FILTER_POISSONSAMPLING||!this._light.supportsVSM()&&(this.filter===t.FILTER_VARIANCESHADOWMAP||this.filter===t.FILTER_BLURVARIANCESHADOWMAP)},set:function(e){this.filter=e?t.FILTER_POISSONSAMPLING:t.FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"useBlurVarianceShadowMap",{get:function(){return this.filter===t.FILTER_BLURVARIANCESHADOWMAP&&this._light.supportsVSM()},set:function(e){this.filter=e?t.FILTER_BLURVARIANCESHADOWMAP:t.FILTER_NONE},enumerable:!0,configurable:!0}),t.prototype.isReady=function(t,i){var r=[];(this.useVarianceShadowMap||this.useBlurVarianceShadowMap)&&r.push("#define VSM");var n=[e.VertexBuffer.PositionKind],o=t.getMesh(),s=t.getMaterial();s&&s.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.push(e.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(n.push(e.VertexBuffer.UV2Kind),r.push("#define UV2"))),o.useBones&&o.computeBonesUsingShaders&&(n.push(e.VertexBuffer.MatricesIndicesKind),n.push(e.VertexBuffer.MatricesWeightsKind),r.push("#define BONES"),r.push("#define BonesPerMesh "+(o.skeleton.bones.length+1))),i&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var a=r.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("shadowMap",n,["world","mBones","viewProjection","diffuseMatrix"],["diffuseSampler"],a)),this._effect.isReady()},t.prototype.getShadowMap=function(){return this._shadowMap},t.prototype.getShadowMapForRendering=function(){return this._shadowMap2?this._shadowMap2:this._shadowMap},t.prototype.getLight=function(){return this._light},t.prototype.getTransformMatrix=function(){var t=this._scene;if(this._currentRenderID===t.getRenderId())return this._transformMatrix;this._currentRenderID=t.getRenderId();var i=this._light.position;return e.Vector3.NormalizeToRef(this._light.direction,this._lightDirection),1==Math.abs(e.Vector3.Dot(this._lightDirection,e.Vector3.Up()))&&(this._lightDirection.z=1e-13),this._light.computeTransformedPosition()&&(i=this._light.transformedPosition),!this._light.needRefreshPerFrame()&&this._cachedPosition&&this._cachedDirection&&i.equals(this._cachedPosition)&&this._lightDirection.equals(this._cachedDirection)||(this._cachedPosition=i.clone(),this._cachedDirection=this._lightDirection.clone(),e.Matrix.LookAtLHToRef(i,this._light.position.add(this._lightDirection),e.Vector3.Up(),this._viewMatrix),this._light.setShadowProjectionMatrix(this._projectionMatrix,this._viewMatrix,this.getShadowMap().renderList),this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)),this._transformMatrix},t.prototype.getDarkness=function(){return this._darkness},t.prototype.setDarkness=function(e){this._darkness=e>=1?1:0>=e?0:e},t.prototype.setTransparencyShadow=function(e){this._transparencyShadow=e},t.prototype._packHalf=function(t){var i=255*t,r=i-Math.floor(i);return new e.Vector2(t-r/255,r)},t.prototype.dispose=function(){this._shadowMap.dispose(),this._shadowMap2&&this._shadowMap2.dispose(),this._downSamplePostprocess&&this._downSamplePostprocess.dispose(),this._boxBlurPostprocess&&this._boxBlurPostprocess.dispose()},t._FILTER_NONE=0,t._FILTER_VARIANCESHADOWMAP=1,t._FILTER_POISSONSAMPLING=2,t._FILTER_BLURVARIANCESHADOWMAP=3,t}();e.ShadowGenerator=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e,t,i,r){return e.x>i.x+r?!1:i.x-r>t.x?!1:e.y>i.y+r?!1:i.y-r>t.y?!1:e.z>i.z+r?!1:i.z-r>t.z?!1:!0},i=function(e,t,i,r){var n=t*t-4*e*i,o={root:0,found:!1};if(0>n)return o;var s=Math.sqrt(n),a=(-t-s)/(2*e),h=(-t+s)/(2*e);if(a>h){var l=h;h=a,a=l}return a>0&&r>a?(o.root=a,o.found=!0,o):h>0&&r>h?(o.root=h,o.found=!0,o):o},r=function(){function r(){this.radius=new e.Vector3(1,1,1),this.retry=0,this.basePointWorld=e.Vector3.Zero(),this.velocityWorld=e.Vector3.Zero(),this.normalizedVelocity=e.Vector3.Zero(),this._collisionPoint=e.Vector3.Zero(),this._planeIntersectionPoint=e.Vector3.Zero(),this._tempVector=e.Vector3.Zero(),this._tempVector2=e.Vector3.Zero(),this._tempVector3=e.Vector3.Zero(),this._tempVector4=e.Vector3.Zero(),this._edge=e.Vector3.Zero(),this._baseToVertex=e.Vector3.Zero(),this._destinationPoint=e.Vector3.Zero(),this._slidePlaneNormal=e.Vector3.Zero(),this._displacementVector=e.Vector3.Zero()}return r.prototype._initialize=function(t,i,r){this.velocity=i,e.Vector3.NormalizeToRef(i,this.normalizedVelocity),this.basePoint=t,t.multiplyToRef(this.radius,this.basePointWorld),i.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=r,this.collisionFound=!1},r.prototype._checkPointInTriangle=function(t,i,r,n,o){i.subtractToRef(t,this._tempVector),r.subtractToRef(t,this._tempVector2),e.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var s=e.Vector3.Dot(this._tempVector4,o);return 0>s?!1:(n.subtractToRef(t,this._tempVector3),e.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),s=e.Vector3.Dot(this._tempVector4,o),0>s?!1:(e.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),s=e.Vector3.Dot(this._tempVector4,o),s>=0))},r.prototype._canDoCollision=function(i,r,n,o){var s=e.Vector3.Distance(this.basePointWorld,i),a=Math.max(this.radius.x,this.radius.y,this.radius.z);return s>this.velocityWorldLength+a+r?!1:t(n,o,this.basePointWorld,this.velocityWorldLength+a)?!0:!1},r.prototype._testTriangle=function(t,r,n,o,s,a){
  var h,l=!1;r||(r=[]),r[t]||(r[t]=new e.Plane(0,0,0,0),r[t].copyFromPoints(n,o,s));var c=r[t];if(a||c.isFrontFacingTo(this.normalizedVelocity,0)){var u=c.signedDistanceTo(this.basePoint),f=e.Vector3.Dot(c.normal,this.velocity);if(0==f){if(Math.abs(u)>=1)return;l=!0,h=0}else{h=(-1-u)/f;var d=(1-u)/f;if(h>d){var p=d;d=h,h=p}if(h>1||0>d)return;0>h&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var m=!1,g=1;if(l||(this.basePoint.subtractToRef(c.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,n,o,s,c.normal)&&(m=!0,g=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!m){var _=this.velocity.lengthSquared(),v=_;this.basePoint.subtractToRef(n,this._tempVector);var y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,M=i(v,y,x,g);M.found&&(g=M.root,m=!0,this._collisionPoint.copyFrom(n)),this.basePoint.subtractToRef(o,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,M=i(v,y,x,g),M.found&&(g=M.root,m=!0,this._collisionPoint.copyFrom(o)),this.basePoint.subtractToRef(s,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,M=i(v,y,x,g),M.found&&(g=M.root,m=!0,this._collisionPoint.copyFrom(s)),o.subtractToRef(n,this._edge),n.subtractToRef(this.basePoint,this._baseToVertex);var S=this._edge.lengthSquared(),b=e.Vector3.Dot(this._edge,this.velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex);if(v=S*-_+b*b,y=2*S*e.Vector3.Dot(this.velocity,this._baseToVertex)-2*b*A,x=S*(1-this._baseToVertex.lengthSquared())+A*A,M=i(v,y,x,g),M.found){var T=(b*M.root-A)/S;T>=0&&1>=T&&(g=M.root,m=!0,this._edge.scaleInPlace(T),n.addToRef(this._edge,this._collisionPoint))}s.subtractToRef(o,this._edge),o.subtractToRef(this.basePoint,this._baseToVertex),S=this._edge.lengthSquared(),b=e.Vector3.Dot(this._edge,this.velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex),v=S*-_+b*b,y=2*S*e.Vector3.Dot(this.velocity,this._baseToVertex)-2*b*A,x=S*(1-this._baseToVertex.lengthSquared())+A*A,M=i(v,y,x,g),M.found&&(T=(b*M.root-A)/S,T>=0&&1>=T&&(g=M.root,m=!0,this._edge.scaleInPlace(T),o.addToRef(this._edge,this._collisionPoint))),n.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex),S=this._edge.lengthSquared(),b=e.Vector3.Dot(this._edge,this.velocity),A=e.Vector3.Dot(this._edge,this._baseToVertex),v=S*-_+b*b,y=2*S*e.Vector3.Dot(this.velocity,this._baseToVertex)-2*b*A,x=S*(1-this._baseToVertex.lengthSquared())+A*A,M=i(v,y,x,g),M.found&&(T=(b*M.root-A)/S,T>=0&&1>=T&&(g=M.root,m=!0,this._edge.scaleInPlace(T),s.addToRef(this._edge,this._collisionPoint)))}if(m){var E=g*this.velocity.length();(!this.collisionFound||E<this.nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this.nearestDistance=E,this.collisionFound=!0)}}},r.prototype._collide=function(e,t,i,r,n,o,s){for(var a=r;n>a;a+=3){var h=t[i[a]-o],l=t[i[a+1]-o],c=t[i[a+2]-o];this._testTriangle(a,e,c,l,h,s)}},r.prototype._getResponse=function(t,i){t.addToRef(i,this._destinationPoint),i.scaleInPlace(this.nearestDistance/i.length()),this.basePoint.addToRef(i,t),t.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this.epsilon,this._displacementVector),t.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(e.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,i)},r}();e.Collider=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){e.CollisionWorker="",function(e){e[e.INIT=0]="INIT",e[e.UPDATE=1]="UPDATE",e[e.COLLIDE=2]="COLLIDE"}(e.WorkerTaskType||(e.WorkerTaskType={}));var t=e.WorkerTaskType;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(e.WorkerReplyType||(e.WorkerReplyType={}));var i=e.WorkerReplyType,r=function(){function r(){var n=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){n._addUpdateMeshesList[e.uniqueId]=r.SerializeMesh(e)},this.onGeometryUpdated=function(e){n._addUpdateGeometriesList[e.id]=r.SerializeGeometry(e)},this._afterRender=function(){if(n._init&&!(0==n._toRemoveGeometryArray.length&&0==n._toRemoveMeshesArray.length&&0==Object.keys(n._addUpdateGeometriesList).length&&0==Object.keys(n._addUpdateMeshesList).length||n._runningUpdated>4)){++n._runningUpdated;var e={updatedMeshes:n._addUpdateMeshesList,updatedGeometries:n._addUpdateGeometriesList,removedGeometries:n._toRemoveGeometryArray,removedMeshes:n._toRemoveMeshesArray},i={payload:e,taskType:t.UPDATE},r=[];for(var o in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(o)&&(r.push(i.payload.updatedGeometries[o].indices.buffer),r.push(i.payload.updatedGeometries[o].normals.buffer),r.push(i.payload.updatedGeometries[o].positions.buffer));n._worker.postMessage(i,r),n._addUpdateMeshesList={},n._addUpdateGeometriesList={},n._toRemoveGeometryArray=[],n._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(r){var o=r.data;if(o.error!=i.SUCCESS)return void e.Tools.Warn("error returned from worker!");switch(o.taskType){case t.INIT:n._init=!0,n._scene.meshes.forEach(function(e){n.onMeshAdded(e)}),n._scene.getGeometries().forEach(function(e){n.onGeometryAdded(e)});break;case t.UPDATE:n._runningUpdated--;break;case t.COLLIDE:n._runningCollisionTask=!1;var s=o.payload;if(!n._collisionsCallbackArray[s.collisionId])return;n._collisionsCallbackArray[s.collisionId](s.collisionId,e.Vector3.FromArray(s.newPosition),n._scene.getMeshByUniqueID(s.collidedMeshUniqueId)),n._collisionsCallbackArray[s.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return r.prototype.getNewPosition=function(e,i,r,n,o,s,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(r.radius,this._scaledPosition),i.divideToRef(r.radius,this._scaledVelocity),this._collisionsCallbackArray[a]=s;var h={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:r.radius.asArray()},collisionId:a,excludedMeshUniqueId:o?o.uniqueId:null,maximumRetry:n},l={payload:h,taskType:t.COLLIDE};this._worker.postMessage(l)}},r.prototype.init=function(i){this._scene=i,this._scene.registerAfterRender(this._afterRender);var r=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(r),this._worker.onmessage=this._onMessageFromWorker;var n={payload:{},taskType:t.INIT};this._worker.postMessage(n)},r.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},r.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},r.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},r.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},r.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},r.SerializeMesh=function(t){var i=[];t.subMeshes&&(i=t.subMeshes.map(function(e,t){return{position:t,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray()}}));var r=null;return t instanceof e.Mesh?r=t.geometry?t.geometry.id:null:t instanceof e.InstancedMesh&&(r=t.sourceMesh.geometry?t.sourceMesh.geometry.id:null),{uniqueId:t.uniqueId,id:t.id,name:t.name,geometryId:r,sphereCenter:t.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:t.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:t.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:t.getBoundingInfo().boundingBox.maximumWorld.asArray(),worldMatrixFromCache:t.worldMatrixFromCache.asArray(),subMeshes:i,checkCollisions:t.checkCollisions}},r.SerializeGeometry=function(t){return{id:t.id,positions:new Float32Array(t.getVerticesData(e.VertexBuffer.PositionKind)||[]),normals:new Float32Array(t.getVerticesData(e.VertexBuffer.NormalKind)||[]),indices:new Int32Array(t.getIndices()||[])}},r}();e.CollisionCoordinatorWorker=r;var n=function(){function t(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return t.prototype.getNewPosition=function(e,t,i,r,n,o,s){e.divideToRef(i.radius,this._scaledPosition),t.divideToRef(i.radius,this._scaledVelocity),i.collidedMesh=null,i.retry=0,i.initialVelocity=this._scaledVelocity,i.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,i,r,this._finalPosition,n),this._finalPosition.multiplyInPlace(i.radius),o(s,this._finalPosition,i.collidedMesh)},t.prototype.init=function(e){this._scene=e},t.prototype.destroy=function(){},t.prototype.onMeshAdded=function(e){},t.prototype.onMeshUpdated=function(e){},t.prototype.onMeshRemoved=function(e){},t.prototype.onGeometryAdded=function(e){},t.prototype.onGeometryUpdated=function(e){},t.prototype.onGeometryDeleted=function(e){},t.prototype._collideWithWorld=function(t,i,r,n,o,s){void 0===s&&(s=null);var a=10*e.Engine.CollisionsEpsilon;if(r.retry>=n)return void o.copyFrom(t);r._initialize(t,i,a);for(var h=0;h<this._scene.meshes.length;h++){var l=this._scene.meshes[h];l.isEnabled()&&l.checkCollisions&&l.subMeshes&&l!==s&&l._checkCollision(r)}return r.collisionFound?((0!==i.x||0!==i.y||0!==i.z)&&r._getResponse(t,i),i.length()<=a?void o.copyFrom(t):(r.retry++,void this._collideWithWorld(t,i,r,n,o,s))):void t.addToRef(i,o)},t}();e.CollisionCoordinatorLegacy=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.compensateDistorsion=!0}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return this.hResolution/(2*this.vResolution)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"aspectRatioFov",{get:function(){return 2*Math.atan(this.postProcessScaleFactor*this.vScreenSize/(2*this.eyeToScreenDistance))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"leftHMatrix",{get:function(){var t=this.hScreenSize/4-this.lensSeparationDistance/2,i=4*t/this.hScreenSize;return e.Matrix.Translation(i,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightHMatrix",{get:function(){var t=this.hScreenSize/4-this.lensSeparationDistance/2,i=4*t/this.hScreenSize;return e.Matrix.Translation(-i,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"leftPreViewMatrix",{get:function(){return e.Matrix.Translation(.5*this.interpupillaryDistance,0,0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightPreViewMatrix",{get:function(){return e.Matrix.Translation(-.5*this.interpupillaryDistance,0,0)},enumerable:!0,configurable:!0}),t.GetDefault=function(){var e=new t;return e.hResolution=1280,e.vResolution=800,e.hScreenSize=.149759993,e.vScreenSize=.0935999975,e.vScreenCenter=.0467999987,e.eyeToScreenDistance=.0410000011,e.lensSeparationDistance=.063500002,e.interpupillaryDistance=.064000003,e.distortionK=[1,.219999999,.239999995,0],e.chromaAbCorrection=[.995999992,-.00400000019,1.01400006,0],e.postProcessScaleFactor=1.714605507808412,e.lensCenterOffset=.151976421,e},t}();e.VRCameraMetrics=t;var i=function(i){function r(t,n,o){i.call(this,t,o),this.position=n,this.upVector=e.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=r.PERSPECTIVE_CAMERA,this.isIntermediate=!1,this.viewport=new e.Viewport(0,0,1,1),this.layerMask=268435455,this.fovMode=r.FOVMODE_VERTICAL_FIXED,this.cameraRigMode=r.RIG_MODE_NONE,this._rigCameras=new Array,this._computedViewMatrix=e.Matrix.Identity(),this._projectionMatrix=new e.Matrix,this._postProcesses=new Array,this._postProcessesTakenIndices=[],this._activeMeshes=new e.SmartArray(256),this._globalPosition=e.Vector3.Zero(),o.addCamera(this),o.activeCamera||(o.activeCamera=this)}return __extends(r,i),Object.defineProperty(r,"PERSPECTIVE_CAMERA",{get:function(){return r._PERSPECTIVE_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(r,"ORTHOGRAPHIC_CAMERA",{get:function(){return r._ORTHOGRAPHIC_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(r,"FOVMODE_VERTICAL_FIXED",{get:function(){return r._FOVMODE_VERTICAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(r,"FOVMODE_HORIZONTAL_FIXED",{get:function(){return r._FOVMODE_HORIZONTAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(r,"RIG_MODE_NONE",{get:function(){return r._RIG_MODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"RIG_MODE_STEREOSCOPIC_ANAGLYPH",{get:function(){return r._RIG_MODE_STEREOSCOPIC_ANAGLYPH},enumerable:!0,configurable:!0}),Object.defineProperty(r,"RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL",{get:function(){return r._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL},enumerable:!0,configurable:!0}),Object.defineProperty(r,"RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED",{get:function(){return r._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED},enumerable:!0,configurable:!0}),Object.defineProperty(r,"RIG_MODE_STEREOSCOPIC_OVERUNDER",{get:function(){return r._RIG_MODE_STEREOSCOPIC_OVERUNDER},enumerable:!0,configurable:!0}),Object.defineProperty(r,"RIG_MODE_VR",{get:function(){return r._RIG_MODE_VR},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"globalPosition",{get:function(){return this._globalPosition},enumerable:!0,configurable:!0}),r.prototype.getActiveMeshes=function(){return this._activeMeshes},r.prototype.isActiveMesh=function(e){return-1!==this._activeMeshes.indexOf(e)},r.prototype._initCache=function(){i.prototype._initCache.call(this),this._cache.position=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.upVector=new e.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},r.prototype._updateCache=function(e){e||i.prototype._updateCache.call(this);var t=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=t.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=t.getRenderWidth(),this._cache.renderHeight=t.getRenderHeight()},r.prototype._updateFromScene=function(){this.updateCache(),this._update()},r.prototype._isSynchronized=function(){return this._isSynchronizedViewMatrix()&&this._isSynchronizedProjectionMatrix()},r.prototype._isSynchronizedViewMatrix=function(){return i.prototype._isSynchronized.call(this)?this._cache.position.equals(this.position)&&this._cache.upVector.equals(this.upVector)&&this.isSynchronizedWithParent():!1},r.prototype._isSynchronizedProjectionMatrix=function(){var e=this._cache.mode===this.mode&&this._cache.minZ===this.minZ&&this._cache.maxZ===this.maxZ;if(!e)return!1;var t=this.getEngine();return e=this.mode===r.PERSPECTIVE_CAMERA?this._cache.fov===this.fov&&this._cache.aspectRatio===t.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===t.getRenderWidth()&&this._cache.renderHeight===t.getRenderHeight()},r.prototype.attachControl=function(e){},r.prototype.detachControl=function(e){},r.prototype._update=function(){this.cameraRigMode!==r.RIG_MODE_NONE&&this._updateRigCameras(),this._checkInputs()},r.prototype._checkInputs=function(){},r.prototype.attachPostProcess=function(t,i){if(void 0===i&&(i=null),!t.isReusable()&&this._postProcesses.indexOf(t)>-1)return e.Tools.Error("You're trying to reuse a post process not defined as reusable."),0;if(null==i||0>i)return this._postProcesses.push(t),this._postProcessesTakenIndices.push(this._postProcesses.length-1),this._postProcesses.length-1;var r=0;if(this._postProcesses[i]){for(var n=this._postProcesses.length-1,o=n;o>=i+1;--o)this._postProcesses[o+1]=this._postProcesses[o];r=1}for(o=0;o<this._postProcessesTakenIndices.length;++o)if(!(this._postProcessesTakenIndices[o]<i)){n=this._postProcessesTakenIndices.length-1;for(var s=n;s>=o;--s)this._postProcessesTakenIndices[s+1]=this._postProcessesTakenIndices[s]+r;this._postProcessesTakenIndices[o]=i;break}r||-1!=this._postProcessesTakenIndices.indexOf(i)||this._postProcessesTakenIndices.push(i);var a=i+r;return this._postProcesses[a]=t,a},r.prototype.detachPostProcess=function(e,t){void 0===t&&(t=null);var i=[];if(t)for(t=t instanceof Array?t:[t],o=0;o<t.length;o++){var r=this._postProcesses[t[o]];r===e?(delete this._postProcesses[t[o]],s=this._postProcessesTakenIndices.indexOf(t[o]),this._postProcessesTakenIndices.splice(s,1)):i.push(o)}else for(var n=this._postProcesses.length,o=0;n>o;o++)if(this._postProcesses[o]===e){delete this._postProcesses[o];var s=this._postProcessesTakenIndices.indexOf(o);this._postProcessesTakenIndices.splice(s,1)}return i},r.prototype.getWorldMatrix=function(){this._worldMatrix||(this._worldMatrix=e.Matrix.Identity());var t=this.getViewMatrix();return t.invertToRef(this._worldMatrix),this._worldMatrix},r.prototype._getViewMatrix=function(){return e.Matrix.Identity()},r.prototype.getViewMatrix=function(t){return this._computedViewMatrix=this._computeViewMatrix(t),!t&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this.parent&&this.parent.getWorldMatrix?(this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._computedViewMatrix.invertToRef(this._worldMatrix),this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._computedViewMatrix),this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12],this._computedViewMatrix.m[13],this._computedViewMatrix.m[14]),this._computedViewMatrix.invert(),this._markSyncedWithParent()):this._globalPosition.copyFrom(this.position),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},r.prototype._computeViewMatrix=function(e){return!e&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this._computedViewMatrix=this._getViewMatrix(),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},r.prototype.getProjectionMatrix=function(t){if(!t&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;var i=this.getEngine();if(this.mode===r.PERSPECTIVE_CAMERA)return this.minZ<=0&&(this.minZ=.1),e.Matrix.PerspectiveFovLHToRef(this.fov,i.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode),this._projectionMatrix;var n=i.getRenderWidth()/2,o=i.getRenderHeight()/2;return e.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-n,this.orthoRight||n,this.orthoBottom||-o,this.orthoTop||o,this.minZ,this.maxZ,this._projectionMatrix),this._projectionMatrix},r.prototype.dispose=function(){for(this.getScene().removeCamera(this);this._rigCameras.length>0;)this._rigCameras.pop().dispose();for(var e=0;e<this._postProcessesTakenIndices.length;++e)this._postProcesses[this._postProcessesTakenIndices[e]].dispose(this)},r.prototype.setCameraRigMode=function(i,n){for(;this._rigCameras.length>0;)this._rigCameras.pop().dispose();switch(this.cameraRigMode=i,this._cameraRigParams={},this.cameraRigMode){case r.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case r.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case r.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case r.RIG_MODE_STEREOSCOPIC_OVERUNDER:this._cameraRigParams.interaxialDistance=n.interaxialDistance||.0637,this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(this._cameraRigParams.interaxialDistance/.0637),this._rigCameras.push(this.createRigCamera(this.name+"_L",0)),this._rigCameras.push(this.createRigCamera(this.name+"_R",1))}var o=new Array;switch(this.cameraRigMode){case r.RIG_MODE_STEREOSCOPIC_ANAGLYPH:o.push(new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0])),this._rigCameras[0].isIntermediate=!0,o.push(new e.AnaglyphPostProcess(this.name+"_anaglyph",1,this._rigCameras[1])),o[1].onApply=function(e){e.setTextureFromPostProcess("leftSampler",o[0])};break;case r.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case r.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case r.RIG_MODE_STEREOSCOPIC_OVERUNDER:var s=this.cameraRigMode===r.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL||this.cameraRigMode===r.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED,a=this.cameraRigMode===r.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED?1:0,h=1-a;o.push(new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[a])),this._rigCameras[a].isIntermediate=!0,o.push(new e.StereoscopicInterlacePostProcess(this.name+"_stereoInterlace",this._rigCameras[h],o[0],s));break;case r.RIG_MODE_VR:this._rigCameras.push(this.createRigCamera(this.name+"_L",0)),this._rigCameras.push(this.createRigCamera(this.name+"_R",1));var l=n.vrCameraMetrics||t.GetDefault();this._rigCameras[0]._cameraRigParams.vrMetrics=l,this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0]._cameraRigParams.vrHMatrix=l.leftHMatrix,this._rigCameras[0]._cameraRigParams.vrPreViewMatrix=l.leftPreViewMatrix,this._rigCameras[0].getProjectionMatrix=this._rigCameras[0]._getVRProjectionMatrix,l.compensateDistorsion&&o.push(new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left",this._rigCameras[0],!1,l)),this._rigCameras[1]._cameraRigParams.vrMetrics=this._rigCameras[0]._cameraRigParams.vrMetrics,this._rigCameras[1].viewport=new e.Viewport(.5,0,.5,1),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[1]._cameraRigParams.vrHMatrix=l.rightHMatrix,this._rigCameras[1]._cameraRigParams.vrPreViewMatrix=l.rightPreViewMatrix,this._rigCameras[1].getProjectionMatrix=this._rigCameras[1]._getVRProjectionMatrix,l.compensateDistorsion&&o.push(new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right",this._rigCameras[1],!0,l))}this._update()},r.prototype._getVRProjectionMatrix=function(){return e.Matrix.PerspectiveFovLHToRef(this._cameraRigParams.vrMetrics.aspectRatioFov,this._cameraRigParams.vrMetrics.aspectRatio,this.minZ,this.maxZ,this._cameraRigParams.vrWorkMatrix),this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrHMatrix,this._projectionMatrix),this._projectionMatrix},r.prototype.setCameraRigParameter=function(t,i){this._cameraRigParams[t]=i,"interaxialDistance"===t&&(this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(i/.0637))},r.prototype.createRigCamera=function(e,t){return null},r.prototype._updateRigCameras=function(){for(var e=0;e<this._rigCameras.length;e++)this._rigCameras[e].minZ=this.minZ,this._rigCameras[e].maxZ=this.maxZ,this._rigCameras[e].fov=this.fov;this.cameraRigMode===r.RIG_MODE_STEREOSCOPIC_ANAGLYPH&&(this._rigCameras[0].viewport=this._rigCameras[1].viewport=this.viewport)},r._PERSPECTIVE_CAMERA=0,r._ORTHOGRAPHIC_CAMERA=1,r._FOVMODE_VERTICAL_FIXED=0,r._FOVMODE_HORIZONTAL_FIXED=1,r._RIG_MODE_NONE=0,r._RIG_MODE_STEREOSCOPIC_ANAGLYPH=10,r._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL=11,r._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED=12,r._RIG_MODE_STEREOSCOPIC_OVERUNDER=13,r._RIG_MODE_VR=20,r}(e.Node);e.Camera=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n){t.call(this,i,r,n),this.cameraDirection=new e.Vector3(0,0,0),this.cameraRotation=new e.Vector2(0,0),this.rotation=new e.Vector3(0,0,0),this.speed=2,this.noRotationConstraint=!1,this.lockedTarget=null,this._currentTarget=e.Vector3.Zero(),this._viewMatrix=e.Matrix.Zero(),this._camMatrix=e.Matrix.Zero(),this._cameraTransformMatrix=e.Matrix.Zero(),this._cameraRotationMatrix=e.Matrix.Zero(),this._referencePoint=new e.Vector3(0,0,1),this._transformedReferencePoint=e.Vector3.Zero(),this._lookAtTemp=e.Matrix.Zero(),this._tempMatrix=e.Matrix.Zero()}return __extends(i,t),i.prototype.getFrontPosition=function(e){var t=this.getTarget().subtract(this.position);return t.normalize(),t.scaleInPlace(e),this.globalPosition.add(t)},i.prototype._getLockedTargetPosition=function(){return this.lockedTarget?this.lockedTarget.position||this.lockedTarget:null},i.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.lockedTarget=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotation=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},i.prototype._updateCache=function(e){e||t.prototype._updateCache.call(this);var i=this._getLockedTargetPosition();i?this._cache.lockedTarget?this._cache.lockedTarget.copyFrom(i):this._cache.lockedTarget=i.clone():this._cache.lockedTarget=null,this._cache.rotation.copyFrom(this.rotation)},i.prototype._isSynchronizedViewMatrix=function(){if(!t.prototype._isSynchronizedViewMatrix.call(this))return!1;var e=this._getLockedTargetPosition();return(this._cache.lockedTarget?this._cache.lockedTarget.equals(e):!e)&&this._cache.rotation.equals(this.rotation)},i.prototype._computeLocalCameraSpeed=function(){var e=this.getEngine();return this.speed*(e.getDeltaTime()/(10*e.getFps()))},i.prototype.setTarget=function(t){this.upVector.normalize(),e.Matrix.LookAtLHToRef(this.position,t,this.upVector,this._camMatrix),this._camMatrix.invert(),this.rotation.x=Math.atan(this._camMatrix.m[6]/this._camMatrix.m[10]);var i=t.subtract(this.position);this.rotation.y=i.x>=0?-Math.atan(i.z/i.x)+Math.PI/2:-Math.atan(i.z/i.x)-Math.PI/2,this.rotation.z=-Math.acos(e.Vector3.Dot(new e.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)},i.prototype.getTarget=function(){return this._currentTarget},i.prototype._decideIfNeedsToMove=function(){return Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},i.prototype._updatePosition=function(){this.position.addInPlace(this.cameraDirection)},i.prototype._checkInputs=function(){var i=this._decideIfNeedsToMove(),r=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(i&&this._updatePosition(),r&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,!this.noRotationConstraint)){var n=Math.PI/2*.95;this.rotation.x>n&&(this.rotation.x=n),this.rotation.x<-n&&(this.rotation.x=-n)}i&&(Math.abs(this.cameraDirection.x)<e.Engine.Epsilon&&(this.cameraDirection.x=0),Math.abs(this.cameraDirection.y)<e.Engine.Epsilon&&(this.cameraDirection.y=0),Math.abs(this.cameraDirection.z)<e.Engine.Epsilon&&(this.cameraDirection.z=0),this.cameraDirection.scaleInPlace(this.inertia)),r&&(Math.abs(this.cameraRotation.x)<e.Engine.Epsilon&&(this.cameraRotation.x=0),Math.abs(this.cameraRotation.y)<e.Engine.Epsilon&&(this.cameraRotation.y=0),this.cameraRotation.scaleInPlace(this.inertia)),t.prototype._checkInputs.call(this)},i.prototype._getViewMatrix=function(){return this.lockedTarget?this._currentTarget.copyFrom(this._getLockedTargetPosition()):(0!==this.upVector.x||1!==this.upVector.y||0!==this.upVector.z?(e.Matrix.LookAtLHToRef(e.Vector3.Zero(),this._referencePoint,this.upVector,this._lookAtTemp),e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix,this._tempMatrix),this._lookAtTemp.invert(),this._tempMatrix.multiplyToRef(this._lookAtTemp,this._cameraRotationMatrix)):e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),e.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),this.position.addToRef(this._transformedReferencePoint,this._currentTarget)),e.Matrix.LookAtLHToRef(this.position,this._currentTarget,this.upVector,this._viewMatrix),this._viewMatrix},i.prototype._getVRViewMatrix=function(){return e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),e.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),e.Vector3.TransformNormalToRef(this.upVector,this._cameraRotationMatrix,this._cameraRigParams.vrActualUp),this.position.addToRef(this._transformedReferencePoint,this._currentTarget),e.Matrix.LookAtLHToRef(this.position,this._currentTarget,this._cameraRigParams.vrActualUp,this._cameraRigParams.vrWorkMatrix),this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrPreViewMatrix,this._viewMatrix),this._viewMatrix},i.prototype.createRigCamera=function(t,r){if(this.cameraRigMode!==e.Camera.RIG_MODE_NONE){var n=new i(t,this.position.clone(),this.getScene());return this.cameraRigMode===e.Camera.RIG_MODE_VR&&(n._cameraRigParams={},n._cameraRigParams.vrActualUp=new e.Vector3(0,0,0),n._getViewMatrix=n._getVRViewMatrix),n}return null},i.prototype._updateRigCameras=function(){switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:var i=this._rigCameras[0],r=this._rigCameras[1];this.cameraRigMode===e.Camera.RIG_MODE_VR?(i.rotation.x=r.rotation.x=this.rotation.x,i.rotation.y=r.rotation.y=this.rotation.y,i.rotation.z=r.rotation.z=this.rotation.z,i.position.copyFrom(this.position),r.position.copyFrom(this.position)):(this._getRigCamPosition(-this._cameraRigParams.stereoHalfAngle,i.position),this._getRigCamPosition(this._cameraRigParams.stereoHalfAngle,r.position),i.setTarget(this.getTarget()),r.setTarget(this.getTarget()))}t.prototype._updateRigCameras.call(this)},i.prototype._getRigCamPosition=function(t,i){this._rigCamTransformMatrix||(this._rigCamTransformMatrix=new e.Matrix);var r=this.getTarget();e.Matrix.Translation(-r.x,-r.y,-r.z).multiplyToRef(e.Matrix.RotationY(t),this._rigCamTransformMatrix),this._rigCamTransformMatrix=this._rigCamTransformMatrix.multiply(e.Matrix.Translation(r.x,r.y,r.z)),e.Vector3.TransformCoordinatesToRef(this.position,this._rigCamTransformMatrix,i)},i}(e.Camera);e.TargetCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n){var o=this;t.call(this,i,r,n),this.ellipsoid=new e.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 e.Collider,this._needMoveForGravity=!1,this._oldPosition=e.Vector3.Zero(),this._diffPosition=e.Vector3.Zero(),this._newPosition=e.Vector3.Zero(),this._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=null),o.getScene().workerCollisions&&i.multiplyInPlace(o._collider.radius);
  
  var n=function(t){o._newPosition.copyFrom(t),o._newPosition.subtractToRef(o._oldPosition,o._diffPosition);o.position.clone();o._diffPosition.length()>e.Engine.CollisionsEpsilon&&(o.position.addInPlace(o._diffPosition),o.onCollide&&r&&o.onCollide(r))};n(i)}}return __extends(i,t),i.prototype.attachControl=function(t,i){var r,n=this,o=this.getEngine();this._attachedElement||(this._attachedElement=t,void 0===this._onMouseDown&&(this._onMouseDown=function(e){r={x:e.clientX,y:e.clientY},i||e.preventDefault()},this._onMouseUp=function(e){r=null,i||e.preventDefault()},this._onMouseOut=function(e){r=null,n._keys=[],i||e.preventDefault()},this._onMouseMove=function(e){if(r||o.isPointerLock){var t,s;o.isPointerLock?(t=e.movementX||e.mozMovementX||e.movementX||e.msMovementX||0,s=e.movementY||e.mozMovementY||e.movementY||e.msMovementY||0):(t=e.clientX-r.x,s=e.clientY-r.y),n.cameraRotation.y+=t/n.angularSensibility,n.cameraRotation.x+=s/n.angularSensibility,r={x:e.clientX,y:e.clientY},i||e.preventDefault()}},this._onKeyDown=function(e){if(-1!==n.keysUp.indexOf(e.keyCode)||-1!==n.keysDown.indexOf(e.keyCode)||-1!==n.keysLeft.indexOf(e.keyCode)||-1!==n.keysRight.indexOf(e.keyCode)){var t=n._keys.indexOf(e.keyCode);-1===t&&n._keys.push(e.keyCode),i||e.preventDefault()}},this._onKeyUp=function(e){if(-1!==n.keysUp.indexOf(e.keyCode)||-1!==n.keysDown.indexOf(e.keyCode)||-1!==n.keysLeft.indexOf(e.keyCode)||-1!==n.keysRight.indexOf(e.keyCode)){var t=n._keys.indexOf(e.keyCode);t>=0&&n._keys.splice(t,1),i||e.preventDefault()}},this._onLostFocus=function(){n._keys=[]},this._reset=function(){n._keys=[],r=null,n.cameraDirection=new e.Vector3(0,0,0),n.cameraRotation=new e.Vector2(0,0)}),t.addEventListener("mousedown",this._onMouseDown,!1),t.addEventListener("mouseup",this._onMouseUp,!1),t.addEventListener("mouseout",this._onMouseOut,!1),t.addEventListener("mousemove",this._onMouseMove,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]))},i.prototype.detachControl=function(t){this._attachedElement==t&&(t.removeEventListener("mousedown",this._onMouseDown),t.removeEventListener("mouseup",this._onMouseUp),t.removeEventListener("mouseout",this._onMouseOut),t.removeEventListener("mousemove",this._onMouseMove),e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._attachedElement=null,this._reset&&this._reset())},i.prototype._collideWithWorld=function(t){var i;i=this.parent?e.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,i.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._collider.radius=this.ellipsoid,this.applyGravity&&t.addInPlace(this.getScene().gravity),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,t,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},i.prototype._checkInputs=function(){this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero());for(var i=0;i<this._keys.length;i++){var r=this._keys[i],n=this._computeLocalCameraSpeed();-1!==this.keysLeft.indexOf(r)?this._localDirection.copyFromFloats(-n,0,0):-1!==this.keysUp.indexOf(r)?this._localDirection.copyFromFloats(0,0,n):-1!==this.keysRight.indexOf(r)?this._localDirection.copyFromFloats(n,0,0):-1!==this.keysDown.indexOf(r)&&this._localDirection.copyFromFloats(0,0,-n),this.getViewMatrix().invertToRef(this._cameraTransformMatrix),e.Vector3.TransformNormalToRef(this._localDirection,this._cameraTransformMatrix,this._transformedDirection),this.cameraDirection.addInPlace(this._transformedDirection)}t.prototype._checkInputs.call(this)},i.prototype._decideIfNeedsToMove=function(){return this._needMoveForGravity||Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},i.prototype._updatePosition=function(){this.checkCollisions&&this.getScene().collisionsEnabled?this._collideWithWorld(this.cameraDirection):this.position.addInPlace(this.cameraDirection)},i}(e.TargetCamera);e.FreeCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r){t.call(this,e,i,r),this.radius=12,this.rotationOffset=0,this.heightOffset=4,this.cameraAcceleration=.05,this.maxCameraSpeed=20}return __extends(i,t),i.prototype.getRadians=function(e){return e*Math.PI/180},i.prototype.follow=function(t){if(t){var i;if(t.rotationQuaternion){var r=new e.Matrix;t.rotationQuaternion.toRotationMatrix(r),i=Math.atan2(r.m[8],r.m[10])}else i=t.rotation.y;var n=this.getRadians(this.rotationOffset)+i,o=t.position.x+Math.sin(n)*this.radius,s=t.position.z+Math.cos(n)*this.radius,a=o-this.position.x,h=t.position.y+this.heightOffset-this.position.y,l=s-this.position.z,c=a*this.cameraAcceleration*2,u=h*this.cameraAcceleration,f=l*this.cameraAcceleration*2;(c>this.maxCameraSpeed||c<-this.maxCameraSpeed)&&(c=1>c?-this.maxCameraSpeed:this.maxCameraSpeed),(u>this.maxCameraSpeed||u<-this.maxCameraSpeed)&&(u=1>u?-this.maxCameraSpeed:this.maxCameraSpeed),(f>this.maxCameraSpeed||f<-this.maxCameraSpeed)&&(f=1>f?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new e.Vector3(this.position.x+c,this.position.y+u,this.position.z+f),this.setTarget(t.position)}},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow(this.target)},i}(e.TargetCamera);e.FollowCamera=t;var i=function(t){function i(i,r,n,o,s,a){t.call(this,i,e.Vector3.Zero(),a),this.alpha=r,this.beta=n,this.radius=o,this.target=s,this._cartesianCoordinates=e.Vector3.Zero(),this.follow()}return __extends(i,t),i.prototype.follow=function(){this._cartesianCoordinates.x=this.radius*Math.cos(this.alpha)*Math.cos(this.beta),this._cartesianCoordinates.y=this.radius*Math.sin(this.beta),this._cartesianCoordinates.z=this.radius*Math.sin(this.alpha)*Math.cos(this.beta),this.position=this.target.position.add(this._cartesianCoordinates),this.setTarget(this.target.position)},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow()},i}(e.TargetCamera);e.ArcFollowCamera=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r){t.call(this,e,i,r),this._offsetX=null,this._offsetY=null,this._pointerCount=0,this._pointerPressed=[],this.angularSensibility=2e5,this.moveSensibility=500}return __extends(i,t),i.prototype.attachControl=function(t,i){var r,n=this;this._attachedCanvas||(this._attachedCanvas=t,void 0===this._onPointerDown&&(this._onPointerDown=function(e){i||e.preventDefault(),n._pointerPressed.push(e.pointerId),1===n._pointerPressed.length&&(r={x:e.clientX,y:e.clientY})},this._onPointerUp=function(e){i||e.preventDefault();var t=n._pointerPressed.indexOf(e.pointerId);-1!==t&&(n._pointerPressed.splice(t,1),0==t&&(r=null,n._offsetX=null,n._offsetY=null))},this._onPointerMove=function(e){if(i||e.preventDefault(),r){var t=n._pointerPressed.indexOf(e.pointerId);0==t&&(n._offsetX=e.clientX-r.x,n._offsetY=-(e.clientY-r.y))}},this._onLostFocus=function(){n._offsetX=null,n._offsetY=null}),t.addEventListener("pointerdown",this._onPointerDown),t.addEventListener("pointerup",this._onPointerUp),t.addEventListener("pointerout",this._onPointerUp),t.addEventListener("pointermove",this._onPointerMove),e.Tools.RegisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]))},i.prototype.detachControl=function(t){this._attachedCanvas==t&&(t.removeEventListener("pointerdown",this._onPointerDown),t.removeEventListener("pointerup",this._onPointerUp),t.removeEventListener("pointerout",this._onPointerUp),t.removeEventListener("pointermove",this._onPointerMove),e.Tools.UnregisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]),this._attachedCanvas=null)},i.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 i=this._computeLocalCameraSpeed(),r=new e.Vector3(0,0,i*this._offsetY/this.moveSensibility);e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(r,this._cameraRotationMatrix))}t.prototype._checkInputs.call(this)},i}(e.FreeCamera);e.TouchCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=e.Tools.GetPointerPrefix(),i=function(i){function r(t,r,n,o,s,a){var h=this;i.call(this,t,e.Vector3.Zero(),a),this.alpha=r,this.beta=n,this.radius=o,this.target=s,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.angularSensibilityX=1e3,this.angularSensibilityY=1e3,this.wheelPrecision=3,this.pinchPrecision=2,this.panningSensibility=50,this.inertialPanningX=0,this.inertialPanningY=0,this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39],this.zoomOnFactor=1,this.targetScreenOffset=e.Vector2.Zero(),this.pinchInwards=!0,this.allowUpsideDown=!0,this._keys=[],this._viewMatrix=new e.Matrix,this._isRightClick=!1,this._isCtrlPushed=!1,this.checkCollisions=!1,this.collisionRadius=new e.Vector3(.5,.5,.5),this._collider=new e.Collider,this._previousPosition=e.Vector3.Zero(),this._collisionVelocity=e.Vector3.Zero(),this._newPosition=e.Vector3.Zero(),this._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=null),h.getScene().workerCollisions&&h.checkCollisions&&i.multiplyInPlace(h._collider.radius),r?(h.setPosition(h.position),h.onCollide&&h.onCollide(r)):h._previousPosition.copyFrom(h.position);var n=Math.cos(h.alpha),o=Math.sin(h.alpha),s=Math.cos(h.beta),a=Math.sin(h.beta),l=h._getTargetPosition();l.addToRef(new e.Vector3(h.radius*n*a,h.radius*s,h.radius*o*a),h._newPosition),h.position.copyFrom(h._newPosition);var c=h.upVector;if(h.allowUpsideDown&&h.beta<0){var c=c.clone();c=c.negate()}e.Matrix.LookAtLHToRef(h.position,l,c,h._viewMatrix),h._viewMatrix.m[12]+=h.targetScreenOffset.x,h._viewMatrix.m[13]+=h.targetScreenOffset.y,h._collisionTriggered=!1},this.target||(this.target=e.Vector3.Zero()),this.getViewMatrix()}return __extends(r,i),Object.defineProperty(r.prototype,"angularSensibility",{get:function(){return e.Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead."),Math.max(this.angularSensibilityX,this.angularSensibilityY)},set:function(t){e.Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead."),this.angularSensibilityX=t,this.angularSensibilityY=t},enumerable:!0,configurable:!0}),r.prototype._getTargetPosition=function(){return this.target.position||this.target},r.prototype._initCache=function(){i.prototype._initCache.call(this),this._cache.target=new e.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},r.prototype._updateCache=function(e){e||i.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()},r.prototype._isSynchronizedViewMatrix=function(){return i.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},r.prototype.attachControl=function(i,r,n){var o=this;void 0===n&&(n=!0);var s,a=0,h=new e.SmartCollection;if(!this._attachedElement){this._attachedElement=i;var l=this.getEngine();void 0===this._onPointerDown&&(this._onPointerDown=function(e){o._isRightClick=2===e.button?!0:!1,h.add(e.pointerId,{x:e.clientX,y:e.clientY,type:e.pointerType}),s=h.item(e.pointerId),r||e.preventDefault()},this._onPointerUp=function(e){s=null,a=0,h.empty(),r||e.preventDefault()},this._onContextMenu=function(e){e.preventDefault()},this._onPointerMove=function(e){switch(r||e.preventDefault(),h.count){case 1:if(o._isCtrlPushed&&n||!n&&o._isRightClick)o.inertialPanningX+=-(e.clientX-s.x)/o.panningSensibility,o.inertialPanningY+=(e.clientY-s.y)/o.panningSensibility;else{var t=e.clientX-s.x,i=e.clientY-s.y;o.inertialAlphaOffset-=t/o.angularSensibilityX,o.inertialBetaOffset-=i/o.angularSensibilityY}s.x=e.clientX,s.y=e.clientY;break;case 2:h.item(e.pointerId).x=e.clientX,h.item(e.pointerId).y=e.clientY;var l=o.pinchInwards?1:-1,c=h.getItemByIndex(0).x-h.getItemByIndex(1).x,u=h.getItemByIndex(0).y-h.getItemByIndex(1).y,f=c*c+u*u;if(0===a)return void(a=f);f!==a&&(o.inertialRadiusOffset+=(f-a)/(o.pinchPrecision*o.wheelPrecision*((o.angularSensibilityX+o.angularSensibilityY)/2)*l),a=f);break;default:h.item(e.pointerId)&&(h.item(e.pointerId).x=e.clientX,h.item(e.pointerId).y=e.clientY)}},this._onMouseMove=function(e){if(l.isPointerLock){var t=e.movementX||e.mozMovementX||e.movementX||e.msMovementX||0,i=e.movementY||e.mozMovementY||e.movementY||e.msMovementY||0;o.inertialAlphaOffset-=t/o.angularSensibilityX,o.inertialBetaOffset-=i/o.angularSensibilityY,r||e.preventDefault()}},this._wheel=function(e){var t=0;e.wheelDelta?t=e.wheelDelta/(40*o.wheelPrecision):e.detail&&(t=-e.detail/o.wheelPrecision),t&&(o.inertialRadiusOffset+=t),e.preventDefault&&(r||e.preventDefault())},this._onKeyDown=function(e){if(o._isCtrlPushed=e.ctrlKey,-1!==o.keysUp.indexOf(e.keyCode)||-1!==o.keysDown.indexOf(e.keyCode)||-1!==o.keysLeft.indexOf(e.keyCode)||-1!==o.keysRight.indexOf(e.keyCode)){var t=o._keys.indexOf(e.keyCode);-1===t&&o._keys.push(e.keyCode),e.preventDefault&&(r||e.preventDefault())}},this._onKeyUp=function(e){if(o._isCtrlPushed=e.ctrlKey,-1!==o.keysUp.indexOf(e.keyCode)||-1!==o.keysDown.indexOf(e.keyCode)||-1!==o.keysLeft.indexOf(e.keyCode)||-1!==o.keysRight.indexOf(e.keyCode)){var t=o._keys.indexOf(e.keyCode);t>=0&&o._keys.splice(t,1),e.preventDefault&&(r||e.preventDefault())}},this._onLostFocus=function(){o._keys=[],h.empty(),a=0,s=null},this._onGestureStart=function(e){void 0!==window.MSGesture&&(o._MSGestureHandler||(o._MSGestureHandler=new MSGesture,o._MSGestureHandler.target=i),o._MSGestureHandler.addPointer(e.pointerId))},this._onGesture=function(e){o.radius*=e.scale,e.preventDefault&&(r||(e.stopPropagation(),e.preventDefault()))},this._reset=function(){o._keys=[],o.inertialAlphaOffset=0,o.inertialBetaOffset=0,o.inertialRadiusOffset=0,h.empty(),a=0,s=null}),n||i.addEventListener("contextmenu",this._onContextMenu,!1),i.addEventListener(t+"down",this._onPointerDown,!1),i.addEventListener(t+"up",this._onPointerUp,!1),i.addEventListener(t+"out",this._onPointerUp,!1),i.addEventListener(t+"move",this._onPointerMove,!1),i.addEventListener("mousemove",this._onMouseMove,!1),i.addEventListener("MSPointerDown",this._onGestureStart,!1),i.addEventListener("MSGestureChange",this._onGesture,!1),i.addEventListener("mousewheel",this._wheel,!1),i.addEventListener("DOMMouseScroll",this._wheel,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}])}},r.prototype.detachControl=function(i){this._attachedElement===i&&(i.removeEventListener("contextmenu",this._onContextMenu),i.removeEventListener(t+"down",this._onPointerDown),i.removeEventListener(t+"up",this._onPointerUp),i.removeEventListener(t+"out",this._onPointerUp),i.removeEventListener(t+"move",this._onPointerMove),i.removeEventListener("mousemove",this._onMouseMove),i.removeEventListener("MSPointerDown",this._onGestureStart),i.removeEventListener("MSGestureChange",this._onGesture),i.removeEventListener("mousewheel",this._wheel),i.removeEventListener("DOMMouseScroll",this._wheel),e.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())},r.prototype._checkInputs=function(){if(!this._collisionTriggered){for(var t=0;t<this._keys.length;t++){var r=this._keys[t];-1!==this.keysLeft.indexOf(r)?this.inertialAlphaOffset-=.01:-1!==this.keysUp.indexOf(r)?this.inertialBetaOffset-=.01:-1!==this.keysRight.indexOf(r)?this.inertialAlphaOffset+=.01:-1!==this.keysDown.indexOf(r)&&(this.inertialBetaOffset+=.01)}(0!==this.inertialAlphaOffset||0!==this.inertialBetaOffset||0!=this.inertialRadiusOffset)&&(this.alpha+=this.beta<=0?-this.inertialAlphaOffset:this.inertialAlphaOffset,this.beta+=this.inertialBetaOffset,this.radius-=this.inertialRadiusOffset,this.inertialAlphaOffset*=this.inertia,this.inertialBetaOffset*=this.inertia,this.inertialRadiusOffset*=this.inertia,Math.abs(this.inertialAlphaOffset)<e.Engine.Epsilon&&(this.inertialAlphaOffset=0),Math.abs(this.inertialBetaOffset)<e.Engine.Epsilon&&(this.inertialBetaOffset=0),Math.abs(this.inertialRadiusOffset)<e.Engine.Epsilon&&(this.inertialRadiusOffset=0)),(0!==this.inertialPanningX||0!==this.inertialPanningY)&&(this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero()),this.inertialPanningX*=this.inertia,this.inertialPanningY*=this.inertia,Math.abs(this.inertialPanningX)<e.Engine.Epsilon&&(this.inertialPanningX=0),Math.abs(this.inertialPanningY)<e.Engine.Epsilon&&(this.inertialPanningY=0),this._localDirection.copyFromFloats(this.inertialPanningX,this.inertialPanningY,0),this._viewMatrix.invertToRef(this._cameraTransformMatrix),e.Vector3.TransformNormalToRef(this._localDirection,this._cameraTransformMatrix,this._transformedDirection),this.target.addInPlace(this._transformedDirection)),this._checkLimits(),i.prototype._checkInputs.call(this)}},r.prototype._checkLimits=function(){null===this.lowerBetaLimit||void 0===this.lowerBetaLimit?this.allowUpsideDown&&this.beta>Math.PI&&(this.beta=this.beta-2*Math.PI):this.beta<this.lowerBetaLimit&&(this.beta=this.lowerBetaLimit),null===this.upperBetaLimit||void 0===this.upperBetaLimit?this.allowUpsideDown&&this.beta<-Math.PI&&(this.beta=this.beta+2*Math.PI):this.beta>this.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerAlphaLimit&&this.alpha<this.lowerAlphaLimit&&(this.alpha=this.lowerAlphaLimit),this.upperAlphaLimit&&this.alpha>this.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerRadiusLimit&&this.radius<this.lowerRadiusLimit&&(this.radius=this.lowerRadiusLimit),this.upperRadiusLimit&&this.radius>this.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},r.prototype.setPosition=function(e){var t=e.subtract(this._getTargetPosition());this.radius=t.length(),this.alpha=Math.acos(t.x/Math.sqrt(Math.pow(t.x,2)+Math.pow(t.z,2))),t.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(t.y/this.radius),this._checkLimits()},r.prototype.setTarget=function(e){this.target=e},r.prototype._getViewMatrix=function(){var t=Math.cos(this.alpha),i=Math.sin(this.alpha),r=Math.cos(this.beta),n=Math.sin(this.beta),o=this._getTargetPosition();if(o.addToRef(new e.Vector3(this.radius*t*n,this.radius*r,this.radius*i*n),this._newPosition),this.getScene().collisionsEnabled&&this.checkCollisions)this._collider.radius=this.collisionRadius,this._newPosition.subtractToRef(this.position,this._collisionVelocity),this._collisionTriggered=!0,this.getScene().collisionCoordinator.getNewPosition(this.position,this._collisionVelocity,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId);else{this.position.copyFrom(this._newPosition);var s=this.upVector;if(this.allowUpsideDown&&this.beta<0){var s=s.clone();s=s.negate()}e.Matrix.LookAtLHToRef(this.position,o,s,this._viewMatrix),this._viewMatrix.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y}return this._viewMatrix},r.prototype.zoomOn=function(t,i){void 0===i&&(i=!1),t=t||this.getScene().meshes;var r=e.Mesh.MinMax(t),n=e.Vector3.Distance(r.min,r.max);this.radius=n*this.zoomOnFactor,this.focusOn({min:r.min,max:r.max,distance:n},i)},r.prototype.focusOn=function(t,i){void 0===i&&(i=!1);var r,n;void 0===t.min?(r=t||this.getScene().meshes,r=e.Mesh.MinMax(r),n=e.Vector3.Distance(r.min,r.max)):(r=t,n=t.distance),this.target=e.Mesh.Center(r),i||(this.maxZ=2*n)},r.prototype.createRigCamera=function(t,i){switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:var n=this._cameraRigParams.stereoHalfAngle*(0===i?1:-1);return new r(t,this.alpha+n,this.beta,this.radius,this.target,this.getScene())}},r.prototype._updateRigCameras=function(){switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:var t=this._rigCameras[0],r=this._rigCameras[1];t.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle,r.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle,t.beta=r.beta=this.beta,t.radius=r.radius=this.radius}i.prototype._updateRigCameras.call(this)},r}(e.TargetCamera);e.ArcRotateCamera=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r){var n=this;t.call(this,e,i,r),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(){n._initialOrientationGamma=null},!1)}return __extends(i,t),i.prototype.attachControl=function(e,t){var i=this;this._attachedCanvas||(this._attachedCanvas=e,this._orientationChanged||(this._orientationChanged=function(e){i._initialOrientationGamma||(i._initialOrientationGamma=e.gamma,i._initialOrientationBeta=e.beta),i._orientationGamma=e.gamma,i._orientationBeta=e.beta,i._offsetY=i._initialOrientationBeta-i._orientationBeta,i._offsetX=i._initialOrientationGamma-i._orientationGamma}),window.addEventListener("deviceorientation",this._orientationChanged))},i.prototype.detachControl=function(e){this._attachedCanvas==e&&(window.removeEventListener("deviceorientation",this._orientationChanged),this._attachedCanvas=null,this._orientationGamma=0,this._orientationBeta=0,this._initialOrientationGamma=0,this._initialOrientationBeta=0)},i.prototype._checkInputs=function(){if(this._offsetX){this.cameraRotation.y-=this._offsetX/this.angularSensibility;var i=this._computeLocalCameraSpeed(),r=new e.Vector3(0,0,i*this._offsetY/this.moveSensibility);e.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(r,this._cameraRotationMatrix)),t.prototype._checkInputs.call(this)}},i}(e.FreeCamera);e.DeviceOrientationCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){var t=this;this.babylonGamepads=[],this.oneGamepadConnected=!1,this.isMonitoring=!1,this.gamepadEventSupported="GamepadEvent"in window,this.gamepadSupportAvailable=navigator.getGamepads||!!navigator.webkitGetGamepads||!!navigator.msGetGamepads||!!navigator.webkitGamepads,this.buttonADataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAA9aSURBVHja7FtpbBzneX7m3otcihSpm9Z9UJalxPKhVLZlp6ktNzEaxE0CtAnQAgnSoPWPBi3syuiPwordFi5Qt2haFygCoylSV4Vby6os1I3kOLYrS65kXXQoypJJSaFEUTyXy925+rzfzC6HFFlL1kpAIe7i5czO7H7zPs97ft8MtTAMcSu/dNzirxkCZgiYIWCGgBkCZgi4hV/mDR5fSxAt+0ZiX0ucDxMSTJLK+f83BFSA6TFgK75OclshouKBFbA+xaV4k7Z+fD6sNRlmjYFXQMu4NiUVS/oHe5/ecnHo3MYxd7QthN9UcsdW6FqEPwgDOFbqpAajL2VlTrTULzj4Ow8+s4+nipSxWMoxIUkyrl/pGswFtIR7WzHgDCX77K7vfHNkbOA+AryjYZadb27OIJdzCNZBKmXw4kbk35qPsTEfJbeEkZESentHMdBfGtY142gu1bDvqV/925f4tQJlNCaj4hXX7RHXS0AFuJEAXvfHr/zmk67vPjir0V68aFEe8xtuQ6O1FHlrEXLmHBiaDUtzYBlpNYjrF+GFZfhhCcPeBQy53ehzT+H8QBe6uwfRf7l8xjKsvX/y5X98jl8fThDhJ4i46QQkrS5I6v7oX7/++77vPtLUlFnZtnIRlubvxRxnHbJmE79sxD/SqG0oZk8MFarRqufUkQAFrxcXSkfx0eB+nOggKX2jHYZhvf79r/z4L2IiipO84aYRkASfefnAX695p3P3c9mM/UufuaMVdzRvxVx7A0xaWdOMqVULJ6Z3TZv6KmHo0ztK6CkfxpHe3Th0pAuF0fLbn1u+9cmv3vW77bE3fGoSPi0BVfAvvPEHm9rPv//iooWz5m9Z/wCWZx+Go9UrN48QTD9IGMZ1cJIzTPisRQclPMrhME4W9mDfB2+i+2z/+TXz7/z2E7/85+9OIuGGE6BV3H77zm/d33nx6Ktr18zFg2t+DQude2n1tLJ8tcJ90vDhpG5Am7qTkJAQErywiLOld7G3/d9xvL0Hy1vWPbbtS3//00Q4hDeaAFXintrx1fu7+jp2r13bgofX/gaazbVkJQdLT9P6VqRFDSu2hIgXlBUBLgtCr3cce47/CMePX0Rr08qtzz7+8k8TpfKGtcKq1jPZre7oObyjdWkGd628l7AXwvMCeL7HjO6qrS8S1E5kTE9tfbiur665ccU9EB1EF9Ep0WXesEZIJb9j5/b/XUtzNrt29Rw0og2lchmBVqLo8LSAHlCixbTpddGm8Y7pjkttCCUP+JQy3FiatNuxdvUx9F4ayopO/OL9sQeEN4oA/eHn577oWPbGVes11PsrUBxjDafze1Te1VzouqnK2TgmLQljQqmrnAsT+iaPVb5b2co7EC+QhBgUeM1R1AcrsGp9Jy6+4W8U3fZ8r+e3EnOI2uaAX3l+zgNB4O9rW5/B8tY5WGo9BtOrJ4uMfUl+uj0B8HTmPXj8Pex86xVEnTDBBSE2r78fX9i09RPyZfT2A5ceIMSPwDOH8JH7Kk5+fAHtR0Zh6MZ9e7534Wc3wgO0sXLhD9OpFOa0egjGMhguD8BgTJooMfPbV1h/umz25ondcFP90IzY2iTgrfY9uH31aqSc9CeSEHkBEyITv28M8XMGc2/z0HGCpWCs8BS/9sWrDYOrJuCBZ+vu5sUfXbicia5kYGzUw4DWTwJKbApSjHuTBBjT2H68zg0MD4KlEwabZi0Y7wd85u/3O9/B6sVrPlEXeiF9nMmRxPt6Qf4y/HyIbh3HwkdF1zefGt5fUwK8wP2WAGwh02MFE/5ogYr3Qg/STL0W3d8aB1ppa+Pw0uI2Tz6/134Mg+UoIGZlZ2HMLaJYHkPICr6//RBamvPj/UA4dYKsegGrXqAXMaqNsDT6SreOY5Gu/FptCeBFN+caAphGiKFiGaOjA3AJHoGt6r7GgNbjqjo5yQkBUVHQ8PaJExjiaZ2yue12nO27gCNdHSptvf/xGdw11I2UZSmvCIJgQiJMhoEfeqpNDvUSRvUB5hMX9fUecg0aBi+Hm2uaAz633bmbm1VN8+h07LfKJdkOkQB2fL4BTlsj8No4YLG2putMSjwjp3QNvZdH8YsiExV501isFjU30lpF7D8dVfCA8sFHp7BuWYtaIwiCsCrCSDVhh9IX8k0CoHsoMQ84FrfFAE3zQAK0VaLzO9tK79XKAxSj+aYALt3XLfNipZD1v492YexrE/sP0zBgUIQIoYaflAXbz16CzyY6YKqYl8uheTarRioD7xAxCQHUpv18L1Yud+Iloujtk4zQo9WZcKURqjbHclzKvj0Gvcw8UA6oY2WqonSuGQGb5I+TJgEFEsB4daXzc0eopabcX13W0BXwgAnRZL4Q62s8ppnR/pFz/QjF+tRvxeIsY/cizGwRt83P4czACL8HdA1JUivCNGVogvdkNkgaGDNe4CvXFyJ8n+B5XGLJ1FmJXJ53AzjZKgGbatkKL5c/liNWIPO8uM/4VO2uKCQZjLmBqQAGJ4EmI8NMabDTOuyUobYXmPlCEpiqA1IkYdWSBpjpEDl6wsrF9aAjqHNOPXDyXAGprAknY5B0btOGGk/GlfE1taqofCNuuYNIJ+omOiZ1rpUHtEYWjkpWoP5EWV2sb5isA7aIQTHHxaIniNADui8PIs0Eb6SY/Z0UQc+j+mXYuoM7Vy/Age7zkBUyCZGLhRLSOYcWpfXFA1wPhqup8JNKq5UkKeoqSHxPLSoqnUQtw5ioc60IyE/VkOji8mYE2nZELNgCXLaOkGDFJBg4OzCMDEcxCfAzS1pQX5fHSNDLClLGwmwzls6vQ09hGFJYegdZ1hha2bqIBNelB5Qjog02TzpFNVEquYpMuTSYr/lcQPKPJHoRQ8W1GYO3lDgpO9pPWTEZEQGnuodg5Hyk66Lyd8fKOQQ6gqyWict7GeuWz8HQyWEFw+bB7ksF3Nk2V1nfpZTLQqSLslzXlDmHpsQ1osVoy/Solwf/GpdErpaAQUqjWxL2GWcWaSfAMIis7RBwiuCdtD1OgmNHBJCg7r4uZBnbdjaaq+3YewB+USYicY8juYPnMtloqdCjG3f39eO+3JKIAFadSiiZigBdgdcqItMxsmZbIbvUIKlzzQjoEgLGRjU2KTp8AjRCkzEnAG0mtQh8Ku0oAqok8JzP+Lw0MkB3jpKjKpapaL5WKZxafDdBqoC6O8LtyMAQhoZdzG7MwLU8FUYKPINcl+qimismRj26v2I71I3jDxfdpM41I6CTsmG4X0djKyc8RYu9t0Vl2QJbBJ5xFPiICJIg1hdhR3fs5HnWeldleZXABLA98b7Y5HtjkgwNEtbTN4iFC5oI3I1CTsAbsfVjAizJB3Qbx9HphRp6eqr3TDprSYA0FI/3ntOxbpUNM2OjpEcE6HYEWkhIKw+ICeBxi+T09F1WZU+iJq2n8fRDf4Ymu3XSrcOIgg8H9uOFn31fNUVC0oddZ7B5YxtDwlTgo66SEici2fokwCJjju0hw7J54WypQsB7tSRAza+H+nld30Y+m2b7SS+Qn9PKFl1egRciHIfWpxC8x+7tdA97+3zUcNyWX4Ci/THOoD2x/hmlQTox+3gDjWYeg/4gmF853xjBpUsjaGnJR24fu36FNzX5pmfY7EPStlSLIgb6gwk616QRYk8tS88/l/2PT/loyqbQkEmhPpNGNp1CmvtieQHvONGtL4sdy9Hjp5kkpTWmSzM7L529hErHs0cCpt2qW00BymDV3JXSU8HkAXKIjtNnedxS48m4Mr5cR9YlMrx+XTqNRmbP2ZkMOjvHKir/PNa5pouiitFjH44iZ6YwO5tFAy+eo6SdpOUJyhBQTJR+HT9HYLJaFve0PqQmTQLaVOCdmIRIWE+wrmWTzG8iAugF7qgWjSWkGbYa32EjJQTkGFv5dBZNJKCeHdb77UPXZP1rWhKLZ4Rqjv2Fz86lLMNlpusCY9BnqTNUIyTgrVhhs7rVq2KoW2TSxWlXLOCqWX4svmpzZdEjWvgQcdVWPnu+i4ClUS+HyLIFnsVf/9eBduw8eKYy2D1XMxO8Jg+IB9wl+3s/uAC3qKMpXY88m/ecnUHaSis3Na8Ab1UtaCh3j1y+sm8m9o0J+9Fv9MR4Zhw6DufTWasOebsOs+xZKHJOtvtQtertulrwV+0BtH5yWvyW7CxubsCTX9+KUQZ4ga7qmdGUFmrya8QWHwcxlReMF8Mw4QETrR8oy7tq2ivH5Tvya8n8aXZMGc4An/nRDpy52FfR8b5KCJCImt8YkYF/KDtnegfwz3sPodGajQajCTk9z/4mQ6iphMWv9AA9IeMWdyYdn+gBkVc5amwHWV6lHvVaI2YZzfinN95Ngv/htcT/p31CRNbdV8l8e++xD5HPNeHxhx5Bgf18kTN5T1kvjBfEjGjBJCai4gnjHqAnlvqS8e9NeujEjEul/NokDbai4V/2voafHD1S0evdWLeb8ojMNyly5fS//ffbcD0L33j4K4RX4rtMh/UUGLXmr6BWXN9MEFAhYfzmZ6hcXI+TpISRH8061Ui68gTWGUJP4aU9P8ZrB39S+Xkx1ummPSMkbebnJcxU1jm4D5eGhvB7j32HJcpUJHhxLIfxTZpxwGa8eKrHC51a9Tmp+N5P1RsQ01cJAwEflHw8/+pfYn/HgaQ+n7/a1vd6k+BUS2XvVD401TXhu488gQ0r71QUuLJsrWT8mSYtfkBMm0BAmFhNrgDX4oRqqeaJMw4c6TyIv/qPP0Xf8KUJ6sXuP1XluuEEyGsD5TXKgsqBNQvW4RtbnkDb4ttJQlGt/IQqLMJE7tWqOSBZCSrL6dFSqq3AnzhzDC/tewHt5w4nr3suvgN0+P8o3TeegFe3vYDHtj+xhLt/Q3kkeW5d693YuuHXsWHZPcixW4tCwo+trVU9QEs8G6HFqW5kdBiHTu3H64dfxpGuK8r665Tv7tz2D6e/tP23cT0E1OA5QR2iiIbs1i9u/9qTPPC12CtwlIofjZVvW/BZ3LVsC5bPW4u5DQuxaPay2NpRIuy61IkLA+dw8hdHceDUPpw49z9TXUysvWPXtl3bQ4yQtMJ1a18DAsbvRO/atvM5DXXPPbp9yzP8+GXBXTkngKYBdTWvE5RXdm87+HQEfLh2T57UIAdM95Js9+04LKSDbLzG31+Omxpx9xfxKR6AukkhMP0aKuUHsag5VEzE3fGSddsUVu6KFzIE+H/iJry0mX+bu8VfMwTMEDBDwAwBMwTMEHALv/5XgAEASpR5N6rB30UAAAAASUVORK5CYII=",this._callbackGamepadConnected=e,this.gamepadSupportAvailable?(this.gamepadEventSupported?(window.addEventListener("gamepadconnected",function(e){t._onGamepadConnected(e)},!1),window.addEventListener("gamepaddisconnected",function(e){t._onGamepadDisconnected(e)},!1)):this._startMonitoringGamepads(),this.oneGamepadConnected||this._insertGamepadDOMInstructions()):this._insertGamepadDOMNotSupported()}return e.prototype._insertGamepadDOMInstructions=function(){e.gamepadDOMInfo=document.createElement("div");var t=document.createElement("img");t.src=this.buttonADataURL;var i=document.createElement("span");i.innerHTML="<strong>to activate gamepad</strong>",e.gamepadDOMInfo.appendChild(t),e.gamepadDOMInfo.appendChild(i),e.gamepadDOMInfo.style.position="absolute",e.gamepadDOMInfo.style.width="100%",e.gamepadDOMInfo.style.height="48px",e.gamepadDOMInfo.style.bottom="0px",e.gamepadDOMInfo.style.backgroundColor="rgba(1, 1, 1, 0.15)",e.gamepadDOMInfo.style.textAlign="center",e.gamepadDOMInfo.style.zIndex="10",t.style.position="relative",t.style.bottom="8px",i.style.position="relative",i.style.fontSize="32px",i.style.bottom="32px",i.style.color="green",document.body.appendChild(e.gamepadDOMInfo)},e.prototype._insertGamepadDOMNotSupported=function(){e.gamepadDOMInfo=document.createElement("div");var t=document.createElement("span");t.innerHTML="<strong>gamepad not supported</strong>",e.gamepadDOMInfo.appendChild(t),e.gamepadDOMInfo.style.position="absolute",e.gamepadDOMInfo.style.width="100%",e.gamepadDOMInfo.style.height="40px",e.gamepadDOMInfo.style.bottom="0px",e.gamepadDOMInfo.style.backgroundColor="rgba(1, 1, 1, 0.15)",e.gamepadDOMInfo.style.textAlign="center",e.gamepadDOMInfo.style.zIndex="10",t.style.position="relative",t.style.fontSize="32px",t.style.color="red",document.body.appendChild(e.gamepadDOMInfo)},e.prototype.dispose=function(){e.gamepadDOMInfo&&document.body.removeChild(e.gamepadDOMInfo)},e.prototype._onGamepadConnected=function(e){var t=this._addNewGamepad(e.gamepad);this._callbackGamepadConnected&&this._callbackGamepadConnected(t),this._startMonitoringGamepads()},e.prototype._addNewGamepad=function(t){this.oneGamepadConnected||(this.oneGamepadConnected=!0,e.gamepadDOMInfo&&(document.body.removeChild(e.gamepadDOMInfo),e.gamepadDOMInfo=null));var i;return i=-1!==t.id.search("Xbox 360")||-1!==t.id.search("xinput")?new a(t.id,t.index,t):new n(t.id,t.index,t),this.babylonGamepads.push(i),i},e.prototype._onGamepadDisconnected=function(e){for(var t in this.babylonGamepads)if(this.babylonGamepads[t].index==e.gamepad.index){this.babylonGamepads.splice(t,1);break}0==this.babylonGamepads.length&&this._stopMonitoringGamepads()},e.prototype._startMonitoringGamepads=function(){this.isMonitoring||(this.isMonitoring=!0,this._checkGamepadsStatus())},e.prototype._stopMonitoringGamepads=function(){this.isMonitoring=!1},e.prototype._checkGamepadsStatus=function(){var e=this;this._updateGamepadObjects();for(var t in this.babylonGamepads)this.babylonGamepads[t].update();this.isMonitoring&&(window.requestAnimationFrame?window.requestAnimationFrame(function(){
  e._checkGamepadsStatus()}):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(function(){e._checkGamepadsStatus()}):window.webkitRequestAnimationFrame&&window.webkitRequestAnimationFrame(function(){e._checkGamepadsStatus()}))},e.prototype._updateGamepadObjects=function(){for(var e=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[],t=0;t<e.length;t++)if(e[t])if(e[t].index in this.babylonGamepads)this.babylonGamepads[t].browserGamepad=e[t];else{var i=this._addNewGamepad(e[t]);this._callbackGamepadConnected&&this._callbackGamepadConnected(i)}},e}();e.Gamepads=t;var i=function(){function e(e,t){this.x=e,this.y=t}return e}();e.StickValues=i;var r=function(){function e(e,t,i){this.id=e,this.index=t,this.browserGamepad=i,this.browserGamepad.axes.length>=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 e.prototype.onleftstickchanged=function(e){this._onleftstickchanged=e},e.prototype.onrightstickchanged=function(e){this._onrightstickchanged=e},Object.defineProperty(e.prototype,"leftStick",{get:function(){return this._leftStick},set:function(e){!this._onleftstickchanged||this._leftStick.x===e.x&&this._leftStick.y===e.y||this._onleftstickchanged(e),this._leftStick=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightStick",{get:function(){return this._rightStick},set:function(e){!this._onrightstickchanged||this._rightStick.x===e.x&&this._rightStick.y===e.y||this._onrightstickchanged(e),this._rightStick=e},enumerable:!0,configurable:!0}),e.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]})},e}();e.Gamepad=r;var n=function(e){function t(t,i,r){e.call(this,t,i,r),this.id=t,this.index=i,this.gamepad=r,this._buttons=new Array(r.buttons.length)}return __extends(t,e),t.prototype.onbuttondown=function(e){this._onbuttondown=e},t.prototype.onbuttonup=function(e){this._onbuttonup=e},t.prototype._setButtonValue=function(e,t,i){return e!==t&&(this._onbuttondown&&1===e&&this._onbuttondown(i),this._onbuttonup&&0===e&&this._onbuttonup(i)),e},t.prototype.update=function(){e.prototype.update.call(this);for(var t=0;t<this._buttons.length;t++)this._buttons[t]=this._setButtonValue(this.gamepad.buttons[t].value,this._buttons[t],t)},t}(r);e.GenericPad=n,function(e){e[e.A=0]="A",e[e.B=1]="B",e[e.X=2]="X",e[e.Y=3]="Y",e[e.Start=4]="Start",e[e.Back=5]="Back",e[e.LB=6]="LB",e[e.RB=7]="RB",e[e.LeftStick=8]="LeftStick",e[e.RightStick=9]="RightStick"}(e.Xbox360Button||(e.Xbox360Button={}));var o=e.Xbox360Button;!function(e){e[e.Up=0]="Up",e[e.Down=1]="Down",e[e.Left=2]="Left",e[e.Right=3]="Right"}(e.Xbox360Dpad||(e.Xbox360Dpad={}));var s=e.Xbox360Dpad,a=function(e){function t(){e.apply(this,arguments),this._leftTrigger=0,this._rightTrigger=0,this._buttonA=0,this._buttonB=0,this._buttonX=0,this._buttonY=0,this._buttonBack=0,this._buttonStart=0,this._buttonLB=0,this._buttonRB=0,this._buttonLeftStick=0,this._buttonRightStick=0,this._dPadUp=0,this._dPadDown=0,this._dPadLeft=0,this._dPadRight=0}return __extends(t,e),t.prototype.onlefttriggerchanged=function(e){this._onlefttriggerchanged=e},t.prototype.onrighttriggerchanged=function(e){this._onrighttriggerchanged=e},Object.defineProperty(t.prototype,"leftTrigger",{get:function(){return this._leftTrigger},set:function(e){this._onlefttriggerchanged&&this._leftTrigger!==e&&this._onlefttriggerchanged(e),this._leftTrigger=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightTrigger",{get:function(){return this._rightTrigger},set:function(e){this._onrighttriggerchanged&&this._rightTrigger!==e&&this._onrighttriggerchanged(e),this._rightTrigger=e},enumerable:!0,configurable:!0}),t.prototype.onbuttondown=function(e){this._onbuttondown=e},t.prototype.onbuttonup=function(e){this._onbuttonup=e},t.prototype.ondpaddown=function(e){this._ondpaddown=e},t.prototype.ondpadup=function(e){this._ondpadup=e},t.prototype._setButtonValue=function(e,t,i){return e!==t&&(this._onbuttondown&&1===e&&this._onbuttondown(i),this._onbuttonup&&0===e&&this._onbuttonup(i)),e},t.prototype._setDPadValue=function(e,t,i){return e!==t&&(this._ondpaddown&&1===e&&this._ondpaddown(i),this._ondpadup&&0===e&&this._ondpadup(i)),e},Object.defineProperty(t.prototype,"buttonA",{get:function(){return this._buttonA},set:function(e){this._buttonA=this._setButtonValue(e,this._buttonA,o.A)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonB",{get:function(){return this._buttonB},set:function(e){this._buttonB=this._setButtonValue(e,this._buttonB,o.B)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonX",{get:function(){return this._buttonX},set:function(e){this._buttonX=this._setButtonValue(e,this._buttonX,o.X)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonY",{get:function(){return this._buttonY},set:function(e){this._buttonY=this._setButtonValue(e,this._buttonY,o.Y)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonStart",{get:function(){return this._buttonStart},set:function(e){this._buttonStart=this._setButtonValue(e,this._buttonStart,o.Start)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonBack",{get:function(){return this._buttonBack},set:function(e){this._buttonBack=this._setButtonValue(e,this._buttonBack,o.Back)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonLB",{get:function(){return this._buttonLB},set:function(e){this._buttonLB=this._setButtonValue(e,this._buttonLB,o.LB)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonRB",{get:function(){return this._buttonRB},set:function(e){this._buttonRB=this._setButtonValue(e,this._buttonRB,o.RB)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonLeftStick",{get:function(){return this._buttonLeftStick},set:function(e){this._buttonLeftStick=this._setButtonValue(e,this._buttonLeftStick,o.LeftStick)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buttonRightStick",{get:function(){return this._buttonRightStick},set:function(e){this._buttonRightStick=this._setButtonValue(e,this._buttonRightStick,o.RightStick)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dPadUp",{get:function(){return this._dPadUp},set:function(e){this._dPadUp=this._setDPadValue(e,this._dPadUp,s.Up)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dPadDown",{get:function(){return this._dPadDown},set:function(e){this._dPadDown=this._setDPadValue(e,this._dPadDown,s.Down)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dPadLeft",{get:function(){return this._dPadLeft},set:function(e){this._dPadLeft=this._setDPadValue(e,this._dPadLeft,s.Left)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dPadRight",{get:function(){return this._dPadRight},set:function(e){this._dPadRight=this._setDPadValue(e,this._dPadRight,s.Right)},enumerable:!0,configurable:!0}),t.prototype.update=function(){e.prototype.update.call(this),this.buttonA=this.browserGamepad.buttons[0].value,this.buttonB=this.browserGamepad.buttons[1].value,this.buttonX=this.browserGamepad.buttons[2].value,this.buttonY=this.browserGamepad.buttons[3].value,this.buttonLB=this.browserGamepad.buttons[4].value,this.buttonRB=this.browserGamepad.buttons[5].value,this.leftTrigger=this.browserGamepad.buttons[6].value,this.rightTrigger=this.browserGamepad.buttons[7].value,this.buttonBack=this.browserGamepad.buttons[8].value,this.buttonStart=this.browserGamepad.buttons[9].value,this.buttonLeftStick=this.browserGamepad.buttons[10].value,this.buttonRightStick=this.browserGamepad.buttons[11].value,this.dPadUp=this.browserGamepad.buttons[12].value,this.dPadDown=this.browserGamepad.buttons[13].value,this.dPadLeft=this.browserGamepad.buttons[14].value,this.dPadRight=this.browserGamepad.buttons[15].value},t}(r);e.Xbox360Pad=a}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n){var o=this;t.call(this,i,r,n),this.angularSensibility=200,this.moveSensibility=75,this._gamepads=new e.Gamepads(function(e){o._onNewGameConnected(e)})}return __extends(i,t),i.prototype._onNewGameConnected=function(e){0===e.index&&(this._gamepad=e)},i.prototype._checkInputs=function(){if(this._gamepad){var i=this._gamepad.leftStick,r=i.x/this.moveSensibility,n=i.y/this.moveSensibility;i.x=Math.abs(r)>.005?0+r:0,i.y=Math.abs(n)>.005?0+n:0;var o=this._gamepad.rightStick,s=o.x/this.angularSensibility,a=o.y/this.angularSensibility;o.x=Math.abs(s)>.001?0+s:0,o.y=Math.abs(a)>.001?0+a:0;var h=e.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),l=50*this._computeLocalCameraSpeed(),c=e.Vector3.TransformCoordinates(new e.Vector3(i.x*l,0,-i.y*l),h);this.cameraDirection=this.cameraDirection.add(c),this.cameraRotation=this.cameraRotation.add(new e.Vector2(o.y,o.x))}t.prototype._checkInputs.call(this)},i.prototype.dispose=function(){this._gamepads.dispose(),t.prototype.dispose.call(this)},i}(e.FreeCamera);e.GamepadCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e){this._renderingGroups=new Array,this._scene=e}return t.prototype._renderParticles=function(t,i){if(0!==this._scene._activeParticleSystems.length){for(var r=this._scene.activeCamera,n=e.Tools.Now,o=0;o<this._scene._activeParticleSystems.length;o++){var s=this._scene._activeParticleSystems.data[o];s.renderingGroupId===t&&0!==(r.layerMask&s.layerMask)&&(this._clearDepthBuffer(),s.emitter.position&&i&&-1===i.indexOf(s.emitter)||(this._scene._activeParticles+=s.render()))}this._scene._particlesDuration+=e.Tools.Now-n}},t.prototype._renderSprites=function(t){if(this._scene.spritesEnabled&&0!==this._scene.spriteManagers.length){for(var i=this._scene.activeCamera,r=e.Tools.Now,n=0;n<this._scene.spriteManagers.length;n++){var o=this._scene.spriteManagers[n];o.renderingGroupId===t&&0!==(i.layerMask&o.layerMask)&&(this._clearDepthBuffer(),o.render())}this._scene._spritesDuration+=e.Tools.Now-r}},t.prototype._clearDepthBuffer=function(){this._depthBufferAlreadyCleaned||(this._scene.getEngine().clear(0,!1,!0),this._depthBufferAlreadyCleaned=!0)},t.prototype.render=function(e,i,r,n){for(var o=0;o<t.MAX_RENDERINGGROUPS;o++){this._depthBufferAlreadyCleaned=!1;var s=this._renderingGroups[o],a=!1;s&&(this._clearDepthBuffer(),s.render(e)||(this._renderingGroups.splice(o,1),a=!0)),n&&this._renderSprites(o),r&&this._renderParticles(o,i),a&&o--}},t.prototype.reset=function(){this._renderingGroups.forEach(function(e,t,i){e&&e.prepare()})},t.prototype.dispatch=function(t){var i=t.getMesh(),r=i.renderingGroupId||0;this._renderingGroups[r]||(this._renderingGroups[r]=new e.RenderingGroup(r,this._scene)),this._renderingGroups[r].dispatch(t)},t.MAX_RENDERINGGROUPS=4,t}();e.RenderingManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.index=t,this._opaqueSubMeshes=new e.SmartArray(256),this._transparentSubMeshes=new e.SmartArray(256),this._alphaTestSubMeshes=new e.SmartArray(256),this._scene=i}return t.prototype.render=function(t){if(t)return t(this._opaqueSubMeshes,this._alphaTestSubMeshes,this._transparentSubMeshes),!0;if(0===this._opaqueSubMeshes.length&&0===this._alphaTestSubMeshes.length&&0===this._transparentSubMeshes.length)return!1;var i,r,n=this._scene.getEngine();for(i=0;i<this._opaqueSubMeshes.length;i++)r=this._opaqueSubMeshes.data[i],r.render(!1);for(n.setAlphaTesting(!0),i=0;i<this._alphaTestSubMeshes.length;i++)r=this._alphaTestSubMeshes.data[i],r.render(!1);if(n.setAlphaTesting(!1),this._transparentSubMeshes.length){for(i=0;i<this._transparentSubMeshes.length;i++)r=this._transparentSubMeshes.data[i],r._alphaIndex=r.getMesh().alphaIndex,r._distanceToCamera=r.getBoundingInfo().boundingSphere.centerWorld.subtract(this._scene.activeCamera.globalPosition).length();var o=this._transparentSubMeshes.data.slice(0,this._transparentSubMeshes.length);for(o.sort(function(e,t){return e._alphaIndex>t._alphaIndex?1:e._alphaIndex<t._alphaIndex?-1:e._distanceToCamera<t._distanceToCamera?1:e._distanceToCamera>t._distanceToCamera?-1:0}),i=0;i<o.length;i++)r=o[i],r.render(!0);n.setAlphaMode(e.Engine.ALPHA_DISABLE)}return!0},t.prototype.prepare=function(){this._opaqueSubMeshes.reset(),this._transparentSubMeshes.reset(),this._alphaTestSubMeshes.reset()},t.prototype.dispatch=function(e){var t=e.getMaterial(),i=e.getMesh();t.needAlphaBlending()||i.visibility<1||i.hasVertexAlpha?this._transparentSubMeshes.push(e):t.needAlphaTesting()?this._alphaTestSubMeshes.push(e):this._opaqueSubMeshes.push(e)},t}();e.RenderingGroup=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(i){this.autoClear=!0,this.clearColor=new e.Color3(.2,.2,.3),this.ambientColor=new e.Color3(0,0,0),this.forceWireframe=!1,this.forcePointsCloud=!1,this.forceShowBoundingBoxes=!1,this.animationsEnabled=!0,this.cameraToUseForPointers=null,this.fogEnabled=!0,this.fogMode=t.FOGMODE_NONE,this.fogColor=new e.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 e.StandardMaterial("default material",this),this.texturesEnabled=!0,this.textures=new Array,this.particlesEnabled=!0,this.particleSystems=new Array,this.spritesEnabled=!0,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 e.Vector3(0,-9.807,0),this.postProcessesEnabled=!0,this.renderTargetsEnabled=!0,this.dumpNextRenderTargets=!1,this.customRenderTargets=new Array,this.importedMeshesFiles=new Array,this._actionManagers=new Array,this._meshesForIntersections=new e.SmartArray(256),this.proceduralTexturesEnabled=!0,this._proceduralTextures=new Array,this.soundTracks=new Array,this._audioEnabled=!0,this._headphone=!1,this._totalVertices=0,this._activeIndices=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 e.SmartArray(256),this._onReadyCallbacks=new Array,this._pendingData=[],this._onBeforeRenderCallbacks=new Array,this._onAfterRenderCallbacks=new Array,this._activeMeshes=new e.SmartArray(256),this._processedMaterials=new e.SmartArray(256),this._renderTargets=new e.SmartArray(256),this._activeParticleSystems=new e.SmartArray(256),this._activeSkeletons=new e.SmartArray(32),this._softwareSkinnedMeshes=new e.SmartArray(32),this._activeBones=0,this._activeAnimatables=new Array,this._transformMatrix=e.Matrix.Zero(),this._edgesRenderers=new e.SmartArray(16),this._uniqueIdCounter=0,this._engine=i,i.scenes.push(this),this._renderingManager=new e.RenderingManager(this),this.postProcessManager=new e.PostProcessManager(this),this.postProcessRenderPipelineManager=new e.PostProcessRenderPipelineManager,this._boundingBoxRenderer=new e.BoundingBoxRenderer(this),this._outlineRenderer=new e.OutlineRenderer(this),this.attachControl(),this._debugLayer=new e.DebugLayer(this),this.mainSoundTrack=new e.SoundTrack(this,{mainTrack:!0}),this.simplificationQueue=new e.SimplificationQueue,this.workerCollisions=!1}return Object.defineProperty(t,"FOGMODE_NONE",{get:function(){return t._FOGMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FOGMODE_EXP",{get:function(){return t._FOGMODE_EXP},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FOGMODE_EXP2",{get:function(){return t._FOGMODE_EXP2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"FOGMODE_LINEAR",{get:function(){return t._FOGMODE_LINEAR},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"debugLayer",{get:function(){return this._debugLayer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"workerCollisions",{get:function(){return this._workerCollisions},set:function(t){t=t&&!!Worker,this._workerCollisions=t,this.collisionCoordinator&&this.collisionCoordinator.destroy(),this.collisionCoordinator=t?new e.CollisionCoordinatorWorker:new e.CollisionCoordinatorLegacy,this.collisionCoordinator.init(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"SelectionOctree",{get:function(){return this._selectionOctree},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"meshUnderPointer",{get:function(){return this._meshUnderPointer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pointerX",{get:function(){return this._pointerX},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pointerY",{get:function(){return this._pointerY},enumerable:!0,configurable:!0}),t.prototype.getCachedMaterial=function(){return this._cachedMaterial},t.prototype.getBoundingBoxRenderer=function(){return this._boundingBoxRenderer},t.prototype.getOutlineRenderer=function(){return this._outlineRenderer},t.prototype.getEngine=function(){return this._engine},t.prototype.getTotalVertices=function(){return this._totalVertices},t.prototype.getActiveIndices=function(){return this._activeIndices},t.prototype.getActiveParticles=function(){return this._activeParticles},t.prototype.getActiveBones=function(){return this._activeBones},t.prototype.getLastFrameDuration=function(){return this._lastFrameDuration},t.prototype.getEvaluateActiveMeshesDuration=function(){return this._evaluateActiveMeshesDuration},t.prototype.getActiveMeshes=function(){return this._activeMeshes},t.prototype.getRenderTargetsDuration=function(){return this._renderTargetsDuration},t.prototype.getRenderDuration=function(){return this._renderDuration},t.prototype.getParticlesDuration=function(){return this._particlesDuration},t.prototype.getSpritesDuration=function(){return this._spritesDuration},t.prototype.getAnimationRatio=function(){return this._animationRatio},t.prototype.getRenderId=function(){return this._renderId},t.prototype.incrementRenderId=function(){this._renderId++},t.prototype._updatePointerPosition=function(e){var t=this._engine.getRenderingCanvasClientRect();this._pointerX=e.clientX-t.left,this._pointerY=e.clientY-t.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())},t.prototype.attachControl=function(){var t=this;this._onPointerMove=function(e){var i=t._engine.getRenderingCanvas();t._updatePointerPosition(e);var r=t.pick(t._pointerX,t._pointerY,function(e){return e.isPickable&&e.isVisible&&e.isReady()},!1,t.cameraToUseForPointers);r.hit?(t._meshUnderPointer=r.pickedMesh,t.setPointerOverMesh(r.pickedMesh),i.style.cursor=t._meshUnderPointer.actionManager&&t._meshUnderPointer.actionManager.hasPointerTriggers?"pointer":""):(t.setPointerOverMesh(null),i.style.cursor="",t._meshUnderPointer=null)},this._onPointerDown=function(i){var r=null;t.onPointerDown||(r=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&e.actionManager&&e.actionManager.hasPickTriggers}),t._updatePointerPosition(i);var n=t.pick(t._pointerX,t._pointerY,r,!1,t.cameraToUseForPointers);if(n.hit&&n.pickedMesh.actionManager){switch(i.button){case 0:n.pickedMesh.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNew(n.pickedMesh,i));break;case 1:n.pickedMesh.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNew(n.pickedMesh,i));break;case 2:n.pickedMesh.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNew(n.pickedMesh,i))}n.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickTrigger,e.ActionEvent.CreateNew(n.pickedMesh,i))}t.onPointerDown&&t.onPointerDown(i,n)},this._onPointerUp=function(i){var r=null;t.onPointerUp||(r=function(t){return t.isPickable&&t.isVisible&&t.isReady()&&t.actionManager&&t.actionManager.hasSpecificTrigger(e.ActionManager.OnPickUpTrigger)}),t._updatePointerPosition(i);var n=t.pick(t._pointerX,t._pointerY,r,!1,t.cameraToUseForPointers);n.hit&&n.pickedMesh.actionManager&&n.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNew(n.pickedMesh,i)),t.onPointerUp&&t.onPointerUp(i,n)},this._onKeyDown=function(i){t.actionManager&&t.actionManager.processTrigger(e.ActionManager.OnKeyDownTrigger,e.ActionEvent.CreateNewFromScene(t,i))},this._onKeyUp=function(i){t.actionManager&&t.actionManager.processTrigger(e.ActionManager.OnKeyUpTrigger,e.ActionEvent.CreateNewFromScene(t,i))};var i=e.Tools.GetPointerPrefix();this._engine.getRenderingCanvas().addEventListener(i+"move",this._onPointerMove,!1),this._engine.getRenderingCanvas().addEventListener(i+"down",this._onPointerDown,!1),this._engine.getRenderingCanvas().addEventListener(i+"up",this._onPointerUp,!1),this._engine.getRenderingCanvas().addEventListener("mousewheel",this._onPointerMove,!1),this._engine.getRenderingCanvas().addEventListener("DOMMouseScroll",this._onPointerMove,!1),e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp}])},t.prototype.detachControl=function(){var t=e.Tools.GetPointerPrefix();this._engine.getRenderingCanvas().removeEventListener(t+"move",this._onPointerMove),this._engine.getRenderingCanvas().removeEventListener(t+"down",this._onPointerDown),this._engine.getRenderingCanvas().removeEventListener(t+"up",this._onPointerUp),this._engine.getRenderingCanvas().removeEventListener("mousewheel",this._onPointerMove),this._engine.getRenderingCanvas().removeEventListener("DOMMouseScroll",this._onPointerMove),e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp}])},t.prototype.isReady=function(){if(this._pendingData.length>0)return!1;var t;for(t=0;t<this._geometries.length;t++){var i=this._geometries[t];if(i.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING)return!1}for(t=0;t<this.meshes.length;t++){var r=this.meshes[t];if(!r.isReady())return!1;var n=r.material;if(n&&!n.isReady(r))return!1}return!0},t.prototype.resetCachedMaterial=function(){this._cachedMaterial=null},t.prototype.registerBeforeRender=function(e){this._onBeforeRenderCallbacks.push(e)},t.prototype.unregisterBeforeRender=function(e){var t=this._onBeforeRenderCallbacks.indexOf(e);t>-1&&this._onBeforeRenderCallbacks.splice(t,1)},t.prototype.registerAfterRender=function(e){this._onAfterRenderCallbacks.push(e)},t.prototype.unregisterAfterRender=function(e){var t=this._onAfterRenderCallbacks.indexOf(e);t>-1&&this._onAfterRenderCallbacks.splice(t,1)},t.prototype._addPendingData=function(e){this._pendingData.push(e)},t.prototype._removePendingData=function(e){var t=this._pendingData.indexOf(e);-1!==t&&this._pendingData.splice(t,1)},t.prototype.getWaitingItemsCount=function(){return this._pendingData.length},t.prototype.executeWhenReady=function(e){var t=this;this._onReadyCallbacks.push(e),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){t._checkIsReady()},150))},t.prototype._checkIsReady=function(){var e=this;return this.isReady()?(this._onReadyCallbacks.forEach(function(e){e()}),this._onReadyCallbacks=[],void(this._executeWhenReadyTimeoutId=-1)):void(this._executeWhenReadyTimeoutId=setTimeout(function(){e._checkIsReady()},150))},t.prototype.beginAnimation=function(t,i,r,n,o,s,a){if(void 0===o&&(o=1),this.stopAnimation(t),a||(a=new e.Animatable(this,t,i,r,n,o,s)),t.animations&&a.appendAnimations(t,t.animations),t.getAnimatables)for(var h=t.getAnimatables(),l=0;l<h.length;l++)this.beginAnimation(h[l],i,r,n,o,s,a);return a},t.prototype.beginDirectAnimation=function(t,i,r,n,o,s,a){void 0===s&&(s=1);var h=new e.Animatable(this,t,r,n,o,s,a,i);return h},t.prototype.getAnimatableByTarget=function(e){for(var t=0;t<this._activeAnimatables.length;t++)if(this._activeAnimatables[t].target===e)return this._activeAnimatables[t];return null},t.prototype.stopAnimation=function(e){var t=this.getAnimatableByTarget(e);t&&t.stop()},t.prototype._animate=function(){if(this.animationsEnabled){this._animationStartDate||(this._animationStartDate=e.Tools.Now);for(var t=e.Tools.Now,i=t-this._animationStartDate,r=0;r<this._activeAnimatables.length;r++)this._activeAnimatables[r]._animate(i)}},t.prototype.getViewMatrix=function(){return this._viewMatrix},t.prototype.getProjectionMatrix=function(){return this._projectionMatrix},t.prototype.getTransformMatrix=function(){return this._transformMatrix},t.prototype.setTransformMatrix=function(e,t){this._viewMatrix=e,this._projectionMatrix=t,this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)},t.prototype.addMesh=function(e){e.uniqueId=this._uniqueIdCounter++;var t=this.meshes.push(e);this.collisionCoordinator.onMeshAdded(e),this.onNewMeshAdded&&this.onNewMeshAdded(e,t,this)},t.prototype.removeMesh=function(e){var t=this.meshes.indexOf(e);return-1!==t&&this.meshes.splice(t,1),this.collisionCoordinator.onMeshRemoved(e),this.onMeshRemoved&&this.onMeshRemoved(e),t},t.prototype.removeLight=function(e){var t=this.lights.indexOf(e);return-1!==t&&this.lights.splice(t,1),this.onLightRemoved&&this.onLightRemoved(e),t},t.prototype.removeCamera=function(e){var t=this.cameras.indexOf(e);-1!==t&&this.cameras.splice(t,1);var i=this.activeCameras.indexOf(e);return-1!==i&&this.activeCameras.splice(i,1),this.activeCamera===e&&(this.activeCamera=this.cameras.length>0?this.cameras[0]:null),this.onCameraRemoved&&this.onCameraRemoved(e),t},t.prototype.addLight=function(e){e.uniqueId=this._uniqueIdCounter++;var t=this.lights.push(e);this.onNewLightAdded&&this.onNewLightAdded(e,t,this)},t.prototype.addCamera=function(e){e.uniqueId=this._uniqueIdCounter++;var t=this.cameras.push(e);this.onNewCameraAdded&&this.onNewCameraAdded(e,t,this)},t.prototype.setActiveCameraByID=function(e){var t=this.getCameraByID(e);return t?(this.activeCamera=t,t):null},t.prototype.setActiveCameraByName=function(e){var t=this.getCameraByName(e);return t?(this.activeCamera=t,t):null},t.prototype.getMaterialByID=function(e){for(var t=0;t<this.materials.length;t++)if(this.materials[t].id===e)return this.materials[t];return null},t.prototype.getMaterialByName=function(e){for(var t=0;t<this.materials.length;t++)if(this.materials[t].name===e)return this.materials[t];return null},t.prototype.getLensFlareSystemByName=function(e){for(var t=0;t<this.lensFlareSystems.length;t++)if(this.lensFlareSystems[t].name===e)return this.lensFlareSystems[t];return null},t.prototype.getCameraByID=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].id===e)return this.cameras[t];return null},t.prototype.getCameraByUniqueID=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].uniqueId===e)return this.cameras[t];return null},t.prototype.getCameraByName=function(e){for(var t=0;t<this.cameras.length;t++)if(this.cameras[t].name===e)return this.cameras[t];return null},t.prototype.getLightByName=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].name===e)return this.lights[t];return null},t.prototype.getLightByID=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].id===e)return this.lights[t];return null},t.prototype.getLightByUniqueID=function(e){for(var t=0;t<this.lights.length;t++)if(this.lights[t].uniqueId===e)return this.lights[t];return null},t.prototype.getGeometryByID=function(e){for(var t=0;t<this._geometries.length;t++)if(this._geometries[t].id===e)return this._geometries[t];return null},t.prototype.pushGeometry=function(e,t){return!t&&this.getGeometryByID(e.id)?!1:(this._geometries.push(e),this.collisionCoordinator.onGeometryAdded(e),this.onGeometryAdded&&this.onGeometryAdded(e),!0)},t.prototype.removeGeometry=function(e){var t=this._geometries.indexOf(e);return t>-1?(this._geometries.splice(t,1),this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemoved&&this.onGeometryRemoved(e),!0):!1},t.prototype.getGeometries=function(){return this._geometries},t.prototype.getMeshByID=function(e){for(var t=0;t<this.meshes.length;t++)if(this.meshes[t].id===e)return this.meshes[t];return null},t.prototype.getMeshByUniqueID=function(e){for(var t=0;t<this.meshes.length;t++)if(this.meshes[t].uniqueId===e)return this.meshes[t];return null},t.prototype.getLastMeshByID=function(e){for(var t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];return null},t.prototype.getLastEntryByID=function(e){var t;for(t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];for(t=this.cameras.length-1;t>=0;t--)if(this.cameras[t].id===e)return this.cameras[t];for(t=this.lights.length-1;t>=0;t--)if(this.lights[t].id===e)return this.lights[t];return null},t.prototype.getNodeByID=function(e){var t=this.getMeshByID(e);if(t)return t;var i=this.getLightByID(e);return i?i:this.getCameraByID(e)},t.prototype.getNodeByName=function(e){var t=this.getMeshByName(e);if(t)return t;var i=this.getLightByName(e);return i?i:this.getCameraByName(e)},t.prototype.getMeshByName=function(e){for(var t=0;t<this.meshes.length;t++)if(this.meshes[t].name===e)return this.meshes[t];return null},t.prototype.getSoundByName=function(e){var t;for(t=0;t<this.mainSoundTrack.soundCollection.length;t++)if(this.mainSoundTrack.soundCollection[t].name===e)return this.mainSoundTrack.soundCollection[t];for(var i=0;i<this.soundTracks.length;i++)for(t=0;t<this.soundTracks[i].soundCollection.length;t++)if(this.soundTracks[i].soundCollection[t].name===e)return this.soundTracks[i].soundCollection[t];return null},t.prototype.getLastSkeletonByID=function(e){for(var t=this.skeletons.length-1;t>=0;t--)if(this.skeletons[t].id===e)return this.skeletons[t];return null},t.prototype.getSkeletonById=function(e){for(var t=0;t<this.skeletons.length;t++)if(this.skeletons[t].id===e)return this.skeletons[t];return null},t.prototype.getSkeletonByName=function(e){for(var t=0;t<this.skeletons.length;t++)if(this.skeletons[t].name===e)return this.skeletons[t];return null},t.prototype.isActiveMesh=function(e){return-1!==this._activeMeshes.indexOf(e)},t.prototype._evaluateSubMesh=function(e,t){if(t.alwaysSelectAsActiveMesh||1===t.subMeshes.length||e.isInFrustum(this._frustumPlanes)){var i=e.getMaterial();t.showSubMeshesBoundingBox&&this._boundingBoxRenderer.renderList.push(e.getBoundingInfo().boundingBox),i&&(i.getRenderTargetTextures&&-1===this._processedMaterials.indexOf(i)&&(this._processedMaterials.push(i),this._renderTargets.concat(i.getRenderTargetTextures())),this._activeIndices+=e.indexCount,this._renderingManager.dispatch(e))}},t.prototype._evaluateActiveMeshes=function(){this.activeCamera._activeMeshes.reset(),this._activeMeshes.reset(),this._renderingManager.reset(),this._processedMaterials.reset(),this._activeParticleSystems.reset(),this._activeSkeletons.reset(),this._softwareSkinnedMeshes.reset(),this._boundingBoxRenderer.reset(),this._edgesRenderers.reset(),this._frustumPlanes?e.Frustum.GetPlanesToRef(this._transformMatrix,this._frustumPlanes):this._frustumPlanes=e.Frustum.GetPlanes(this._transformMatrix);var t,i;if(this._selectionOctree){var r=this._selectionOctree.select(this._frustumPlanes);t=r.data,i=r.length}else i=this.meshes.length,t=this.meshes;for(var n=0;i>n;n++){var o=t[n];if(!o.isBlocked&&(this._totalVertices+=o.getTotalVertices(),o.isReady()&&o.isEnabled())){o.computeWorldMatrix(),o.actionManager&&o.actionManager.hasSpecificTriggers([e.ActionManager.OnIntersectionEnterTrigger,e.ActionManager.OnIntersectionExitTrigger])&&this._meshesForIntersections.pushNoDuplicate(o);
  
  var s=o.getLOD(this.activeCamera);s&&(o._preActivate(),(o.alwaysSelectAsActiveMesh||o.isVisible&&o.visibility>0&&0!==(o.layerMask&this.activeCamera.layerMask)&&o.isInFrustum(this._frustumPlanes))&&(this._activeMeshes.push(o),this.activeCamera._activeMeshes.push(o),o._activate(this._renderId),this._activeMesh(s)))}}var a=e.Tools.Now;if(this.particlesEnabled){e.Tools.StartPerformanceCounter("Particles",this.particleSystems.length>0);for(var h=0;h<this.particleSystems.length;h++){var l=this.particleSystems[h];l.isStarted()&&(!l.emitter.position||l.emitter&&l.emitter.isEnabled())&&(this._activeParticleSystems.push(l),l.animate())}e.Tools.EndPerformanceCounter("Particles",this.particleSystems.length>0)}this._particlesDuration+=e.Tools.Now-a},t.prototype._activeMesh=function(e){if(e.skeleton&&this.skeletonsEnabled&&(this._activeSkeletons.pushNoDuplicate(e.skeleton),e.computeBonesUsingShaders||this._softwareSkinnedMeshes.pushNoDuplicate(e)),(e.showBoundingBox||this.forceShowBoundingBoxes)&&this._boundingBoxRenderer.renderList.push(e.getBoundingInfo().boundingBox),e._edgesRenderer&&this._edgesRenderers.push(e._edgesRenderer),e&&e.subMeshes){var t,i;if(e._submeshesOctree&&e.useOctreeForRenderingSelection){var r=e._submeshesOctree.select(this._frustumPlanes);t=r.length,i=r.data}else i=e.subMeshes,t=i.length;for(var n=0;t>n;n++){var o=i[n];this._evaluateSubMesh(o,e)}}},t.prototype.updateTransformMatrix=function(e){this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(e))},t.prototype._renderForCamera=function(t){var i=this._engine;if(this.activeCamera=t,!this.activeCamera)throw new Error("Active camera not set");e.Tools.StartPerformanceCounter("Rendering camera "+this.activeCamera.name),i.setViewport(this.activeCamera.viewport),this.resetCachedMaterial(),this._renderId++,this.updateTransformMatrix(),this.beforeCameraRender&&this.beforeCameraRender(this.activeCamera);var r=e.Tools.Now;e.Tools.StartPerformanceCounter("Active meshes evaluation"),this._evaluateActiveMeshes(),this._evaluateActiveMeshesDuration+=e.Tools.Now-r,e.Tools.EndPerformanceCounter("Active meshes evaluation");for(var n=0;n<this._activeSkeletons.length;n++){var o=this._activeSkeletons.data[n];o.prepare()}for(var s=0;s<this._softwareSkinnedMeshes.length;s++){var a=this._softwareSkinnedMeshes.data[s];a.applySkeleton(a.skeleton)}var h=e.Tools.Now;if(this.renderTargetsEnabled){e.Tools.StartPerformanceCounter("Render targets",this._renderTargets.length>0);for(var l=0;l<this._renderTargets.length;l++){var c=this._renderTargets.data[l];if(c._shouldRender()){this._renderId++;var u=c.activeCamera&&c.activeCamera!==this.activeCamera;c.render(u,this.dumpNextRenderTargets)}}e.Tools.EndPerformanceCounter("Render targets",this._renderTargets.length>0),this._renderId++}this._renderTargets.length>0&&i.restoreDefaultFramebuffer(),this._renderTargetsDuration+=e.Tools.Now-h,this.postProcessManager._prepareFrame();var f,d,p=e.Tools.Now;if(this.layers.length){for(i.setDepthBuffer(!1),f=0;f<this.layers.length;f++)d=this.layers[f],d.isBackground&&d.render();i.setDepthBuffer(!0)}e.Tools.StartPerformanceCounter("Main render"),this._renderingManager.render(null,null,!0,!0),e.Tools.EndPerformanceCounter("Main render"),this._boundingBoxRenderer.render();for(var m=0;m<this._edgesRenderers.length;m++)this._edgesRenderers.data[m].render();if(this.lensFlaresEnabled){e.Tools.StartPerformanceCounter("Lens flares",this.lensFlareSystems.length>0);for(var g=0;g<this.lensFlareSystems.length;g++){var _=this.lensFlareSystems[g];0!==(t.layerMask&_.layerMask)&&_.render()}e.Tools.EndPerformanceCounter("Lens flares",this.lensFlareSystems.length>0)}if(this.layers.length){for(i.setDepthBuffer(!1),f=0;f<this.layers.length;f++)d=this.layers[f],d.isBackground||d.render();i.setDepthBuffer(!0)}this._renderDuration+=e.Tools.Now-p,this.postProcessManager._finalizeFrame(t.isIntermediate),this.activeCamera._updateFromScene(),this._renderTargets.reset(),this.afterCameraRender&&this.afterCameraRender(this.activeCamera),e.Tools.EndPerformanceCounter("Rendering camera "+this.activeCamera.name)},t.prototype._processSubCameras=function(t){if(t.cameraRigMode===e.Camera.RIG_MODE_NONE)return void this._renderForCamera(t);for(var i=0;i<t._rigCameras.length;i++)this._renderForCamera(t._rigCameras[i]);this.activeCamera=t,this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix()),this.activeCamera._updateFromScene()},t.prototype._checkIntersections=function(){for(var t=0;t<this._meshesForIntersections.length;t++)for(var i=this._meshesForIntersections.data[t],r=0;r<i.actionManager.actions.length;r++){var n=i.actionManager.actions[r];if(n.trigger===e.ActionManager.OnIntersectionEnterTrigger||n.trigger===e.ActionManager.OnIntersectionExitTrigger){var o=n.getTriggerParameter(),s=o instanceof e.AbstractMesh?o:o.mesh,a=s.intersectsMesh(i,o.usePreciseIntersection),h=i._intersectionsInProgress.indexOf(s);a&&-1===h?n.trigger===e.ActionManager.OnIntersectionEnterTrigger?(n._executeCurrent(e.ActionEvent.CreateNew(i,null,s)),i._intersectionsInProgress.push(s)):n.trigger===e.ActionManager.OnIntersectionExitTrigger&&i._intersectionsInProgress.push(s):!a&&h>-1&&(n.trigger===e.ActionManager.OnIntersectionExitTrigger&&n._executeCurrent(e.ActionEvent.CreateNew(i,null,s)),i.actionManager.hasSpecificTrigger(e.ActionManager.OnIntersectionExitTrigger)&&n.trigger!==e.ActionManager.OnIntersectionExitTrigger||i._intersectionsInProgress.splice(h,1))}}},t.prototype.render=function(){var i=e.Tools.Now;this._particlesDuration=0,this._spritesDuration=0,this._activeParticles=0,this._renderDuration=0,this._renderTargetsDuration=0,this._evaluateActiveMeshesDuration=0,this._totalVertices=0,this._activeIndices=0,this._activeBones=0,this.getEngine().resetDrawCalls(),this._meshesForIntersections.reset(),this.resetCachedMaterial(),e.Tools.StartPerformanceCounter("Scene rendering"),this.actionManager&&this.actionManager.processTrigger(e.ActionManager.OnEveryFrameTrigger,null),this.simplificationQueue.running||this.simplificationQueue.executeNext(),this.beforeRender&&this.beforeRender();var r;for(r=0;r<this._onBeforeRenderCallbacks.length;r++)this._onBeforeRenderCallbacks[r]();var n=Math.max(t.MinDeltaTime,Math.min(this._engine.getDeltaTime(),t.MaxDeltaTime));this._animationRatio=.06*n,this._animate(),this._physicsEngine&&(e.Tools.StartPerformanceCounter("Physics"),this._physicsEngine._runOneStep(n/1e3),e.Tools.EndPerformanceCounter("Physics"));var o=e.Tools.Now,s=this.getEngine(),a=this.activeCamera;if(this.renderTargetsEnabled){e.Tools.StartPerformanceCounter("Custom render targets",this.customRenderTargets.length>0);for(var h=0;h<this.customRenderTargets.length;h++){var l=this.customRenderTargets[h];if(l._shouldRender()){if(this._renderId++,this.activeCamera=l.activeCamera||this.activeCamera,!this.activeCamera)throw new Error("Active camera not set");s.setViewport(this.activeCamera.viewport),this.updateTransformMatrix(),l.render(a!==this.activeCamera,this.dumpNextRenderTargets)}}e.Tools.EndPerformanceCounter("Custom render targets",this.customRenderTargets.length>0),this._renderId++}if(this.customRenderTargets.length>0&&s.restoreDefaultFramebuffer(),this._renderTargetsDuration+=e.Tools.Now-o,this.activeCamera=a,this.proceduralTexturesEnabled){e.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var c=0;c<this._proceduralTextures.length;c++){var u=this._proceduralTextures[c];u._shouldRender()&&u.render()}e.Tools.EndPerformanceCounter("Procedural textures",this._proceduralTextures.length>0)}if(this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,!0),this.shadowsEnabled)for(var f=0;f<this.lights.length;f++){var d=this.lights[f],p=d.getShadowGenerator();d.isEnabled()&&p&&-1!==p.getShadowMap().getScene().textures.indexOf(p.getShadowMap())&&this._renderTargets.push(p.getShadowMap())}if(this._depthRenderer&&this._renderTargets.push(this._depthRenderer.getDepthMap()),this.postProcessRenderPipelineManager.update(),this.activeCameras.length>0)for(var m=this._renderId,g=0;g<this.activeCameras.length;g++)this._renderId=m,this._processSubCameras(this.activeCameras[g]);else{if(!this.activeCamera)throw new Error("No camera defined");this._processSubCameras(this.activeCamera)}for(this._checkIntersections(),this._updateAudioParameters(),this.afterRender&&this.afterRender(),r=0;r<this._onAfterRenderCallbacks.length;r++)this._onAfterRenderCallbacks[r]();for(var _=0;_<this._toBeDisposed.length;_++)this._toBeDisposed.data[_].dispose(),this._toBeDisposed[_]=null;this._toBeDisposed.reset(),this.dumpNextRenderTargets&&(this.dumpNextRenderTargets=!1),e.Tools.EndPerformanceCounter("Scene rendering"),this._lastFrameDuration=e.Tools.Now-i},t.prototype._updateAudioParameters=function(){if(this.audioEnabled&&(0!==this.mainSoundTrack.soundCollection.length||0!==this.soundTracks.length)){var t,i=e.Engine.audioEngine;if(t=this.activeCameras.length>0?this.activeCameras[0]:this.activeCamera,t&&i.canUseWebAudio){i.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z);var r=e.Matrix.Invert(t.getViewMatrix()),n=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),r);n.normalize(),i.audioContext.listener.setOrientation(n.x,n.y,n.z,0,1,0);var o;for(o=0;o<this.mainSoundTrack.soundCollection.length;o++){var s=this.mainSoundTrack.soundCollection[o];s.useCustomAttenuation&&s.updateDistanceFromListener()}for(o=0;o<this.soundTracks.length;o++)for(var a=0;a<this.soundTracks[o].soundCollection.length;a++)s=this.soundTracks[o].soundCollection[a],s.useCustomAttenuation&&s.updateDistanceFromListener()}}},Object.defineProperty(t.prototype,"audioEnabled",{get:function(){return this._audioEnabled},set:function(e){this._audioEnabled=e,this._audioEnabled?this._enableAudio():this._disableAudio()},enumerable:!0,configurable:!0}),t.prototype._disableAudio=function(){var e;for(e=0;e<this.mainSoundTrack.soundCollection.length;e++)this.mainSoundTrack.soundCollection[e].pause();for(e=0;e<this.soundTracks.length;e++)for(var t=0;t<this.soundTracks[e].soundCollection.length;t++)this.soundTracks[e].soundCollection[t].pause()},t.prototype._enableAudio=function(){var e;for(e=0;e<this.mainSoundTrack.soundCollection.length;e++)this.mainSoundTrack.soundCollection[e].isPaused&&this.mainSoundTrack.soundCollection[e].play();for(e=0;e<this.soundTracks.length;e++)for(var t=0;t<this.soundTracks[e].soundCollection.length;t++)this.soundTracks[e].soundCollection[t].isPaused&&this.soundTracks[e].soundCollection[t].play()},Object.defineProperty(t.prototype,"headphone",{get:function(){return this._headphone},set:function(e){this._headphone=e,this._headphone?this._switchAudioModeForHeadphones():this._switchAudioModeForNormalSpeakers()},enumerable:!0,configurable:!0}),t.prototype._switchAudioModeForHeadphones=function(){this.mainSoundTrack.switchPanningModelToHRTF();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToHRTF()},t.prototype._switchAudioModeForNormalSpeakers=function(){this.mainSoundTrack.switchPanningModelToEqualPower();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].switchPanningModelToEqualPower()},t.prototype.enableDepthRenderer=function(){return this._depthRenderer?this._depthRenderer:(this._depthRenderer=new e.DepthRenderer(this),this._depthRenderer)},t.prototype.disableDepthRenderer=function(){this._depthRenderer&&(this._depthRenderer.dispose(),this._depthRenderer=null)},t.prototype.dispose=function(){this.beforeRender=null,this.afterRender=null,this.skeletons=[],this._boundingBoxRenderer.dispose(),this._depthRenderer&&this._depthRenderer.dispose(),this.debugLayer.hide(),this.onDispose&&this.onDispose(),this._onBeforeRenderCallbacks=[],this._onAfterRenderCallbacks=[],this.detachControl(),this.disposeSounds();var e,t=this._engine.getRenderingCanvas();for(e=0;e<this.cameras.length;e++)this.cameras[e].detachControl(t);for(;this.lights.length;)this.lights[0].dispose();for(;this.meshes.length;)this.meshes[0].dispose(!0);for(;this.cameras.length;)this.cameras[0].dispose();for(;this.materials.length;)this.materials[0].dispose();for(;this.particleSystems.length;)this.particleSystems[0].dispose();for(;this.spriteManagers.length;)this.spriteManagers[0].dispose();for(;this.layers.length;)this.layers[0].dispose();for(;this.textures.length;)this.textures[0].dispose();this.postProcessManager.dispose(),this._physicsEngine&&this.disablePhysicsEngine(),e=this._engine.scenes.indexOf(this),e>-1&&this._engine.scenes.splice(e,1),this._engine.wipeCaches()},t.prototype.disposeSounds=function(){this.mainSoundTrack.dispose();for(var e=0;e<this.soundTracks.length;e++)this.soundTracks[e].dispose()},t.prototype.getWorldExtends=function(){for(var t=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),i=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),r=0;r<this.meshes.length;r++){var n=this.meshes[r];n.computeWorldMatrix(!0);var o=n.getBoundingInfo().boundingBox.minimumWorld,s=n.getBoundingInfo().boundingBox.maximumWorld;e.Tools.CheckExtends(o,t,i),e.Tools.CheckExtends(s,t,i)}return{min:t,max:i}},t.prototype.createOrUpdateSelectionOctree=function(t,i){void 0===t&&(t=64),void 0===i&&(i=2),this._selectionOctree||(this._selectionOctree=new e.Octree(e.Octree.CreationFuncForMeshes,t,i));var r=this.getWorldExtends();return this._selectionOctree.update(r.min,r.max,this.meshes),this._selectionOctree},t.prototype.createPickingRay=function(t,i,r,n){var o=this._engine;if(!n){if(!this.activeCamera)throw new Error("Active camera not set");n=this.activeCamera}var s=n.viewport,a=s.toGlobal(o);return t=t/this._engine.getHardwareScalingLevel()-a.x,i=i/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-a.y-a.height),e.Ray.CreateNew(t,i,a.width,a.height,r?r:e.Matrix.Identity(),n.getViewMatrix(),n.getProjectionMatrix())},t.prototype._internalPick=function(t,i,r){for(var n=null,o=0;o<this.meshes.length;o++){var s=this.meshes[o];if(i){if(!i(s))continue}else if(!s.isEnabled()||!s.isVisible||!s.isPickable)continue;var a=s.getWorldMatrix(),h=t(a),l=s.intersects(h,r);if(l&&l.hit&&(r||null==n||!(l.distance>=n.distance))&&(n=l,r))break}return n||new e.PickingInfo},t.prototype.pick=function(e,t,i,r,n){var o=this;return this._internalPick(function(i){return o.createPickingRay(e,t,i,n)},i,r)},t.prototype.pickWithRay=function(t,i,r){var n=this;return this._internalPick(function(i){return n._pickWithRayInverseMatrix||(n._pickWithRayInverseMatrix=e.Matrix.Identity()),i.invertToRef(n._pickWithRayInverseMatrix),e.Ray.Transform(t,n._pickWithRayInverseMatrix)},i,r)},t.prototype.setPointerOverMesh=function(t){this._pointerOverMesh!==t&&(this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(e.ActionManager.OnPointerOutTrigger,e.ActionEvent.CreateNew(this._pointerOverMesh)),this._pointerOverMesh=t,this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(e.ActionManager.OnPointerOverTrigger,e.ActionEvent.CreateNew(this._pointerOverMesh)))},t.prototype.getPointerOverMesh=function(){return this._pointerOverMesh},t.prototype.getPhysicsEngine=function(){return this._physicsEngine},t.prototype.enablePhysics=function(t,i){return this._physicsEngine?!0:(this._physicsEngine=new e.PhysicsEngine(i),this._physicsEngine.isSupported()?(this._physicsEngine._initialize(t),!0):(this._physicsEngine=null,!1))},t.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=void 0)},t.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},t.prototype.setGravity=function(e){this._physicsEngine&&this._physicsEngine._setGravity(e)},t.prototype.createCompoundImpostor=function(e,t){if(e.parts&&(t=e,e=e.parts),!this._physicsEngine)return null;for(var i=0;i<e.length;i++){var r=e[i].mesh;r._physicImpostor=e[i].impostor,r._physicsMass=t.mass/e.length,r._physicsFriction=t.friction,r._physicRestitution=t.restitution}return this._physicsEngine._registerMeshesAsCompound(e,t)},t.prototype.deleteCompoundImpostor=function(t){for(var i=0;i<t.parts.length;i++){var r=t.parts[i].mesh;r._physicImpostor=e.PhysicsEngine.NoImpostor,this._physicsEngine._unregisterMesh(r)}},t.prototype.createDefaultCameraOrLight=function(){if(0===this.lights.length&&new e.HemisphericLight("default light",e.Vector3.Up(),this),!this.activeCamera){var t=new e.FreeCamera("default camera",e.Vector3.Zero(),this),i=this.getWorldExtends(),r=i.min.add(i.max.subtract(i.min).scale(.5));t.position=new e.Vector3(r.x,r.y,i.min.z-(i.max.z-i.min.z)),t.setTarget(r),this.activeCamera=t}},t.prototype._getByTags=function(t,i,r){if(void 0===i)return t;var n=[];r=r||function(e){};for(var o in t){var s=t[o];e.Tags.MatchesQuery(s,i)&&(n.push(s),r(s))}return n},t.prototype.getMeshesByTags=function(e,t){return this._getByTags(this.meshes,e,t)},t.prototype.getCamerasByTags=function(e,t){return this._getByTags(this.cameras,e,t)},t.prototype.getLightsByTags=function(e,t){return this._getByTags(this.lights,e,t)},t.prototype.getMaterialByTags=function(e,t){return this._getByTags(this.materials,e,t).concat(this._getByTags(this.multiMaterials,e,t))},t._FOGMODE_NONE=0,t._FOGMODE_EXP=1,t._FOGMODE_EXP2=2,t._FOGMODE_LINEAR=3,t.MinDeltaTime=1,t.MaxDeltaTime=1e3,t}();e.Scene=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(i,r,n,o,s,a){if(this._engine=i instanceof e.Mesh?i.getScene().getEngine():i,this._updatable=o,this._data=r,s||this.create(),this._kind=n,a)return void(this._strideSize=a);switch(n){case t.PositionKind:this._strideSize=3;break;case t.NormalKind:this._strideSize=3;break;case t.UVKind:case t.UV2Kind:case t.UV3Kind:case t.UV4Kind:case t.UV5Kind:case t.UV6Kind:this._strideSize=2;break;case t.ColorKind:this._strideSize=4;break;case t.MatricesIndicesKind:this._strideSize=4;break;case t.MatricesWeightsKind:this._strideSize=4}}return t.prototype.isUpdatable=function(){return this._updatable},t.prototype.getData=function(){return this._data},t.prototype.getBuffer=function(){return this._buffer},t.prototype.getStrideSize=function(){return this._strideSize},t.prototype.create=function(e){(e||!this._buffer)&&(e=e||this._data,this._buffer||(this._buffer=this._updatable?this._engine.createDynamicVertexBuffer(4*e.length):this._engine.createVertexBuffer(e)),this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,e),this._data=e))},t.prototype.update=function(e){this.create(e)},t.prototype.updateDirectly=function(e,t){this._buffer&&this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,e,t),this._data=null)},t.prototype.dispose=function(){this._buffer&&this._engine._releaseBuffer(this._buffer)&&(this._buffer=null)},Object.defineProperty(t,"PositionKind",{get:function(){return t._PositionKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"NormalKind",{get:function(){return t._NormalKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UVKind",{get:function(){return t._UVKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV2Kind",{get:function(){return t._UV2Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV3Kind",{get:function(){return t._UV3Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV4Kind",{get:function(){return t._UV4Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV5Kind",{get:function(){return t._UV5Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"UV6Kind",{get:function(){return t._UV6Kind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ColorKind",{get:function(){return t._ColorKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MatricesIndicesKind",{get:function(){return t._MatricesIndicesKind},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MatricesWeightsKind",{get:function(){return t._MatricesWeightsKind},enumerable:!0,configurable:!0}),t._PositionKind="position",t._NormalKind="normal",t._UVKind="uv",t._UV2Kind="uv2",t._UV3Kind="uv3",t._UV4Kind="uv4",t._UV5Kind="uv5",t._UV6Kind="uv6",t._ColorKind="color",t._MatricesIndicesKind="matricesIndices",t._MatricesWeightsKind="matricesWeights",t}();e.VertexBuffer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i){t.call(this,e,i.getScene()),i.instances.push(this),this._sourceMesh=i,this.position.copyFrom(i.position),this.rotation.copyFrom(i.rotation),this.scaling.copyFrom(i.scaling),i.rotationQuaternion&&(this.rotationQuaternion=i.rotationQuaternion.clone()),this.infiniteDistance=i.infiniteDistance,this.setPivotMatrix(i.getPivotMatrix()),this.refreshBoundingInfo(),this._syncSubMeshes()}return __extends(i,t),Object.defineProperty(i.prototype,"receiveShadows",{get:function(){return this._sourceMesh.receiveShadows},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"material",{get:function(){return this._sourceMesh.material},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"visibility",{get:function(){return this._sourceMesh.visibility},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"skeleton",{get:function(){return this._sourceMesh.skeleton},enumerable:!0,configurable:!0}),i.prototype.getTotalVertices=function(){return this._sourceMesh.getTotalVertices()},Object.defineProperty(i.prototype,"sourceMesh",{get:function(){return this._sourceMesh},enumerable:!0,configurable:!0}),i.prototype.getVerticesData=function(e){return this._sourceMesh.getVerticesData(e)},i.prototype.isVerticesDataPresent=function(e){return this._sourceMesh.isVerticesDataPresent(e)},i.prototype.getIndices=function(){return this._sourceMesh.getIndices()},Object.defineProperty(i.prototype,"_positions",{get:function(){return this._sourceMesh._positions},enumerable:!0,configurable:!0}),i.prototype.refreshBoundingInfo=function(){var t=this._sourceMesh.getVerticesData(e.VertexBuffer.PositionKind);if(t){var i=e.Tools.ExtractMinAndMax(t,0,this._sourceMesh.getTotalVertices());this._boundingInfo=new e.BoundingInfo(i.minimum,i.maximum)}this._updateBoundingInfo()},i.prototype._preActivate=function(){this._currentLOD&&this._currentLOD._preActivate()},i.prototype._activate=function(e){this._currentLOD&&this._currentLOD._registerInstanceForRenderId(this,e)},i.prototype.getLOD=function(e){return this._currentLOD=this.sourceMesh.getLOD(this.getScene().activeCamera,this.getBoundingInfo().boundingSphere),this._currentLOD===this.sourceMesh?this:this._currentLOD},i.prototype._syncSubMeshes=function(){if(this.releaseSubMeshes(),this._sourceMesh.subMeshes)for(var e=0;e<this._sourceMesh.subMeshes.length;e++)this._sourceMesh.subMeshes[e].clone(this,this._sourceMesh)},i.prototype._generatePointsArray=function(){return this._sourceMesh._generatePointsArray()},i.prototype.clone=function(t,i,r){var n=this._sourceMesh.createInstance(t);if(e.Tools.DeepCopy(this,n,["name"],[]),this.refreshBoundingInfo(),i&&(n.parent=i),!r)for(var o=0;o<this.getScene().meshes.length;o++){var s=this.getScene().meshes[o];s.parent===this&&s.clone(s.name,n)}return n.computeWorldMatrix(!0),n},i.prototype.dispose=function(e){var i=this._sourceMesh.instances.indexOf(this);this._sourceMesh.instances.splice(i,1),t.prototype.dispose.call(this,e)},i}(e.AbstractMesh);e.InstancedMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this.mustReturn=!1,this.visibleInstances=new Array,this.renderSelf=new Array}return e}();e._InstancesBatch=t;var i=function(i){function r(n,o,s,a,h){if(void 0===s&&(s=null),i.call(this,n,o),this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.instances=new Array,this._LODLevels=new Array,this._onBeforeRenderCallbacks=new Array,this._onAfterRenderCallbacks=new Array,this._visibleInstances={},this._renderIdForInstances=new Array,this._batchCache=new t,this._instancesBufferSize=2048,this._sideOrientation=r._DEFAULTSIDE,this._areNormalsFrozen=!1,a){if(a._geometry&&a._geometry.applyToMesh(this),e.Tools.DeepCopy(a,this,["name","material","skeleton","instances"],[]),this.id=n+"."+a.id,this.material=a.material,!h)for(var l=0;l<o.meshes.length;l++){var c=o.meshes[l];if(c.parent===a){c.clone(n+"."+c.name,this,h)}}for(l=0;l<o.particleSystems.length;l++){var u=o.particleSystems[l];u.emitter===a&&u.clone(u.name,this)}this.computeWorldMatrix(!0)}null!==s&&(this.parent=s)}return __extends(r,i),Object.defineProperty(r,"FRONTSIDE",{get:function(){return r._FRONTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"BACKSIDE",{get:function(){return r._BACKSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"DOUBLESIDE",{get:function(){return r._DOUBLESIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"DEFAULTSIDE",{get:function(){return r._DEFAULTSIDE},enumerable:!0,configurable:!0}),Object.defineProperty(r,"NO_CAP",{get:function(){return r._NO_CAP},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_START",{get:function(){return r._CAP_START},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_END",{get:function(){return r._CAP_END},enumerable:!0,configurable:!0}),Object.defineProperty(r,"CAP_ALL",{get:function(){return r._CAP_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"hasLODLevels",{get:function(){return this._LODLevels.length>0},enumerable:!0,configurable:!0}),r.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distance<t.distance?1:e.distance>t.distance?-1:0})},r.prototype.addLODLevel=function(t,i){if(i&&i._masterMesh)return e.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var r=new e.Internals.MeshLODLevel(t,i);return this._LODLevels.push(r),i&&(i._masterMesh=this),this._sortLODLevels(),this},r.prototype.getLODLevelAtDistance=function(e){for(var t=0;t<this._LODLevels.length;t++){var i=this._LODLevels[t];if(i.distance===e)return i.mesh}return null},r.prototype.removeLODLevel=function(e){for(var t=0;t<this._LODLevels.length;t++)this._LODLevels[t].mesh===e&&(this._LODLevels.splice(t,1),e&&(e._masterMesh=null));return this._sortLODLevels(),this},r.prototype.getLOD=function(e,t){if(!this._LODLevels||0===this._LODLevels.length)return this;var i=(t?t:this.getBoundingInfo().boundingSphere).centerWorld.subtract(e.position).length();if(this._LODLevels[this._LODLevels.length-1].distance>i)return this.onLODLevelSelection&&this.onLODLevelSelection(i,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var r=0;r<this._LODLevels.length;r++){var n=this._LODLevels[r];if(n.distance<i)return n.mesh&&(n.mesh._preActivate(),n.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)),this.onLODLevelSelection&&this.onLODLevelSelection(i,this,n.mesh),n.mesh}return this.onLODLevelSelection&&this.onLODLevelSelection(i,this,this),this},Object.defineProperty(r.prototype,"geometry",{get:function(){return this._geometry},enumerable:!0,configurable:!0}),r.prototype.getTotalVertices=function(){return this._geometry?this._geometry.getTotalVertices():0},r.prototype.getVerticesData=function(e,t){return this._geometry?this._geometry.getVerticesData(e,t):null},r.prototype.getVertexBuffer=function(e){return this._geometry?this._geometry.getVertexBuffer(e):void 0},r.prototype.isVerticesDataPresent=function(e){return this._geometry?this._geometry.isVerticesDataPresent(e):this._delayInfo?-1!==this._delayInfo.indexOf(e):!1},r.prototype.getVerticesDataKinds=function(){if(!this._geometry){var e=[];if(this._delayInfo)for(var t in this._delayInfo)e.push(t);return e}return this._geometry.getVerticesDataKinds()},r.prototype.getTotalIndices=function(){return this._geometry?this._geometry.getTotalIndices():0},r.prototype.getIndices=function(e){return this._geometry?this._geometry.getIndices(e):[]},Object.defineProperty(r.prototype,"isBlocked",{get:function(){return null!==this._masterMesh&&void 0!==this._masterMesh},enumerable:!0,configurable:!0}),r.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING?!1:i.prototype.isReady.call(this)},r.prototype.isDisposed=function(){return this._isDisposed},Object.defineProperty(r.prototype,"sideOrientation",{get:function(){return this._sideOrientation},set:function(e){this._sideOrientation=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"areNormalsFrozen",{get:function(){return this._areNormalsFrozen},enumerable:!0,configurable:!0}),r.prototype.freezeNormals=function(){this._areNormalsFrozen=!0},r.prototype.unfreezeNormals=function(){this._areNormalsFrozen=!1},r.prototype._preActivate=function(){var e=this.getScene().getRenderId();this._preActivateId!==e&&(this._preActivateId=e,this._visibleInstances=null)},r.prototype._registerInstanceForRenderId=function(e,t){this._visibleInstances||(this._visibleInstances={},this._visibleInstances.defaultRenderId=t,this._visibleInstances.selfDefaultRenderId=this._renderId),this._visibleInstances[t]||(this._visibleInstances[t]=new Array),this._visibleInstances[t].push(e)},r.prototype.refreshBoundingInfo=function(){var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(t){var i=e.Tools.ExtractMinAndMax(t,0,this.getTotalVertices());this._boundingInfo=new e.BoundingInfo(i.minimum,i.maximum)}if(this.subMeshes)for(var r=0;r<this.subMeshes.length;r++)this.subMeshes[r].refreshBoundingInfo();this._updateBoundingInfo()},r.prototype._createGlobalSubMesh=function(){var t=this.getTotalVertices();return t&&this.getIndices()?(this.releaseSubMeshes(),new e.SubMesh(0,0,t,0,this.getTotalIndices(),this)):null},r.prototype.subdivide=function(t){if(!(1>t)){for(var i=this.getTotalIndices(),r=i/t|0,n=0;r%3!==0;)r++;this.releaseSubMeshes();for(var o=0;t>o&&!(n>=i);o++)e.SubMesh.CreateFromIndices(0,n,Math.min(r,i-n),this),n+=r;this.synchronizeInstances()}},r.prototype.setVerticesData=function(t,i,r,n){if(t instanceof Array){var o=i;i=t,t=o,e.Tools.Warn("Deprecated usage of setVerticesData detected (since v1.12). Current signature is setVerticesData(kind, data, updatable).")}if(this._geometry)this._geometry.setVerticesData(t,i,r,n);else{var s=new e.VertexData;s.set(i,t);var a=this.getScene();new e.Geometry(e.Geometry.RandomId(),a,s,r,this)}},r.prototype.updateVerticesData=function(e,t,i,r){this._geometry&&(r?(this.makeGeometryUnique(),this.updateVerticesData(e,t,i,!1)):this._geometry.updateVerticesData(e,t,i))},r.prototype.updateVerticesDataDirectly=function(e,t,i,r){this._geometry&&(r?(this.makeGeometryUnique(),this.updateVerticesDataDirectly(e,t,i,!1)):this._geometry.updateVerticesDataDirectly(e,t,i))},r.prototype.updateMeshPositions=function(t,i){void 0===i&&(i=!0);var r=this.getVerticesData(e.VertexBuffer.PositionKind);if(t(r),this.updateVerticesData(e.VertexBuffer.PositionKind,r,!1,!1),i){var n=this.getIndices(),o=this.getVerticesData(e.VertexBuffer.NormalKind);e.VertexData.ComputeNormals(r,n,o),this.updateVerticesData(e.VertexBuffer.NormalKind,o,!1,!1)}},r.prototype.makeGeometryUnique=function(){if(this._geometry){var t=this._geometry.copy(e.Geometry.RandomId());t.applyToMesh(this)}},r.prototype.setIndices=function(t,i){if(this._geometry)this._geometry.setIndices(t,i);else{var r=new e.VertexData;r.indices=t;var n=this.getScene();new e.Geometry(e.Geometry.RandomId(),n,r,!1,this)}},r.prototype._bind=function(t,i,r){var n,o=this.getScene().getEngine();switch(r){case e.Material.PointFillMode:n=null;break;case e.Material.WireFrameFillMode:n=t.getLinesIndexBuffer(this.getIndices(),o);break;default:case e.Material.TriangleFillMode:n=this._geometry.getIndexBuffer()}o.bindMultiBuffers(this._geometry.getVertexBuffers(),n,i)},r.prototype._draw=function(t,i,r){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var n=this.getScene().getEngine();switch(i){case e.Material.PointFillMode:n.drawPointClouds(t.verticesStart,t.verticesCount,r);break;case e.Material.WireFrameFillMode:n.draw(!1,0,t.linesIndexCount,r);break;default:n.draw(!0,t.indexStart,t.indexCount,r)}}},r.prototype.registerBeforeRender=function(e){this._onBeforeRenderCallbacks.push(e);
  
  },r.prototype.unregisterBeforeRender=function(e){var t=this._onBeforeRenderCallbacks.indexOf(e);t>-1&&this._onBeforeRenderCallbacks.splice(t,1)},r.prototype.registerAfterRender=function(e){this._onAfterRenderCallbacks.push(e)},r.prototype.unregisterAfterRender=function(e){var t=this._onAfterRenderCallbacks.indexOf(e);t>-1&&this._onAfterRenderCallbacks.splice(t,1)},r.prototype._getInstancesRenderList=function(e){var t=this.getScene();if(this._batchCache.mustReturn=!1,this._batchCache.renderSelf[e]=this.isEnabled()&&this.isVisible,this._batchCache.visibleInstances[e]=null,this._visibleInstances){var i=t.getRenderId();this._batchCache.visibleInstances[e]=this._visibleInstances[i];var r=this._renderId;if(!this._batchCache.visibleInstances[e]&&this._visibleInstances.defaultRenderId&&(this._batchCache.visibleInstances[e]=this._visibleInstances[this._visibleInstances.defaultRenderId],i=Math.max(this._visibleInstances.defaultRenderId,i),r=Math.max(this._visibleInstances.selfDefaultRenderId,i)),this._batchCache.visibleInstances[e]&&this._batchCache.visibleInstances[e].length){if(this._renderIdForInstances[e]===i)return this._batchCache.mustReturn=!0,this._batchCache;i!==r&&(this._batchCache.renderSelf[e]=!1)}this._renderIdForInstances[e]=i}return this._batchCache},r.prototype._renderWithInstances=function(e,t,i,r,n){for(var o=i.visibleInstances[e._id],s=o.length+1,a=16*s*4;this._instancesBufferSize<a;)this._instancesBufferSize*=2;(!this._worldMatricesInstancesBuffer||this._worldMatricesInstancesBuffer.capacity<this._instancesBufferSize)&&(this._worldMatricesInstancesBuffer&&n.deleteInstancesBuffer(this._worldMatricesInstancesBuffer),this._worldMatricesInstancesBuffer=n.createInstancesBuffer(this._instancesBufferSize),this._worldMatricesInstancesArray=new Float32Array(this._instancesBufferSize/4));var h=0,l=0,c=this.getWorldMatrix();if(i.renderSelf[e._id]&&(c.copyToArray(this._worldMatricesInstancesArray,h),h+=16,l++),o)for(var u=0;u<o.length;u++){var f=o[u];f.getWorldMatrix().copyToArray(this._worldMatricesInstancesArray,h),h+=16,l++}var d=r.getAttributeLocationByName("world0"),p=r.getAttributeLocationByName("world1"),m=r.getAttributeLocationByName("world2"),g=r.getAttributeLocationByName("world3"),_=[d,p,m,g];n.updateAndBindInstancesBuffer(this._worldMatricesInstancesBuffer,this._worldMatricesInstancesArray,_),this._draw(e,t,l),n.unBindInstancesBuffer(this._worldMatricesInstancesBuffer,_)},r.prototype._processRendering=function(e,t,i,r,n,o){var s=this.getScene(),a=s.getEngine();if(n)this._renderWithInstances(e,i,r,t,a);else if(r.renderSelf[e._id]&&(o&&o(!1,this.getWorldMatrix()),this._draw(e,i)),r.visibleInstances[e._id])for(var h=0;h<r.visibleInstances[e._id].length;h++){var l=r.visibleInstances[e._id][h],c=l.getWorldMatrix();o&&o(!0,c),this._draw(e,i)}},r.prototype.render=function(t,i){var r=this.getScene(),n=this._getInstancesRenderList(t._id);if(!n.mustReturn&&this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var o;for(o=0;o<this._onBeforeRenderCallbacks.length;o++)this._onBeforeRenderCallbacks[o](this);var s=r.getEngine(),a=null!==s.getCaps().instancedArrays&&null!==n.visibleInstances[t._id]&&void 0!==n.visibleInstances[t._id],h=t.getMaterial();if(h&&h.isReady(this,a)){var l=s.getDepthWrite();this.renderOutline&&(s.setDepthWrite(!1),r.getOutlineRenderer().render(t,n),s.setDepthWrite(l)),h._preBind();var c=h.getEffect(),u=r.forcePointsCloud?e.Material.PointFillMode:r.forceWireframe?e.Material.WireFrameFillMode:h.fillMode;this._bind(t,c,u);var f=this.getWorldMatrix();if(h.bind(f,this),i&&s.setAlphaMode(h.alphaMode),this._processRendering(t,c,u,n,a,function(e,t){e&&h.bindOnlyWorldMatrix(t)}),h.unbind(),this.renderOutline&&l&&(s.setDepthWrite(!0),s.setColorWrite(!1),r.getOutlineRenderer().render(t,n),s.setColorWrite(!0)),this.renderOverlay){var d=s.getAlphaMode();s.setAlphaMode(e.Engine.ALPHA_COMBINE),r.getOutlineRenderer().render(t,n,!0),s.setAlphaMode(d)}for(o=0;o<this._onAfterRenderCallbacks.length;o++)this._onAfterRenderCallbacks[o](this)}}},r.prototype.getEmittedParticleSystems=function(){for(var e=new Array,t=0;t<this.getScene().particleSystems.length;t++){var i=this.getScene().particleSystems[t];i.emitter===this&&e.push(i)}return e},r.prototype.getHierarchyEmittedParticleSystems=function(){var e=new Array,t=this.getDescendants();t.push(this);for(var i=0;i<this.getScene().particleSystems.length;i++){var r=this.getScene().particleSystems[i];-1!==t.indexOf(r.emitter)&&e.push(r)}return e},r.prototype.getChildren=function(){for(var e=[],t=0;t<this.getScene().meshes.length;t++){var i=this.getScene().meshes[t];i.parent===this&&e.push(i)}return e},r.prototype._checkDelayState=function(){var t=this,i=this,r=this.getScene();if(this._geometry)this._geometry.load(r);else if(i.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED){i.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,r._addPendingData(i);var n=-1!==this.delayLoadingFile.indexOf(".babylonbinarymeshdata");e.Tools.LoadFile(this.delayLoadingFile,function(i){i instanceof ArrayBuffer?t._delayLoadingFunction(i,t):t._delayLoadingFunction(JSON.parse(i),t),t.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,r._removePendingData(t)},function(){},r.database,n)}},r.prototype.isInFrustum=function(t){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADING?!1:i.prototype.isInFrustum.call(this,t)?(this._checkDelayState(),!0):!1},r.prototype.setMaterialByID=function(e){var t,i=this.getScene().materials;for(t=0;t<i.length;t++)if(i[t].id===e)return void(this.material=i[t]);var r=this.getScene().multiMaterials;for(t=0;t<r.length;t++)if(r[t].id===e)return void(this.material=r[t])},r.prototype.getAnimatables=function(){var e=[];return this.material&&e.push(this.material),this.skeleton&&e.push(this.skeleton),e},r.prototype.bakeTransformIntoVertices=function(t){if(this.isVerticesDataPresent(e.VertexBuffer.PositionKind)){this._resetPointsArrayCache();var i,r=this.getVerticesData(e.VertexBuffer.PositionKind),n=[];for(i=0;i<r.length;i+=3)e.Vector3.TransformCoordinates(e.Vector3.FromArray(r,i),t).toArray(n,i);if(this.setVerticesData(e.VertexBuffer.PositionKind,n,this.getVertexBuffer(e.VertexBuffer.PositionKind).isUpdatable()),this.isVerticesDataPresent(e.VertexBuffer.NormalKind)){for(r=this.getVerticesData(e.VertexBuffer.NormalKind),n=[],i=0;i<r.length;i+=3)e.Vector3.TransformNormal(e.Vector3.FromArray(r,i),t).normalize().toArray(n,i);this.setVerticesData(e.VertexBuffer.NormalKind,n,this.getVertexBuffer(e.VertexBuffer.NormalKind).isUpdatable()),t.m[0]*t.m[5]*t.m[10]<0&&this.flipFaces()}}},r.prototype.bakeCurrentTransformIntoVertices=function(){this.bakeTransformIntoVertices(this.computeWorldMatrix(!0)),this.scaling.copyFromFloats(1,1,1),this.position.copyFromFloats(0,0,0),this.rotation.copyFromFloats(0,0,0),this.rotationQuaternion&&(this.rotationQuaternion=e.Quaternion.Identity()),this._worldMatrix=e.Matrix.Identity()},r.prototype._resetPointsArrayCache=function(){this._positions=null},r.prototype._generatePointsArray=function(){if(this._positions)return!0;this._positions=[];var t=this.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return!1;for(var i=0;i<t.length;i+=3)this._positions.push(e.Vector3.FromArray(t,i));return!0},r.prototype.clone=function(e,t,i){return new r(e,this.getScene(),t,this,i)},r.prototype.dispose=function(e){for(this._geometry&&this._geometry.releaseForMesh(this,!0),this._worldMatricesInstancesBuffer&&(this.getEngine().deleteInstancesBuffer(this._worldMatricesInstancesBuffer),this._worldMatricesInstancesBuffer=null);this.instances.length;)this.instances[0].dispose();i.prototype.dispose.call(this,e)},r.prototype.applyDisplacementMap=function(t,i,r,n){var o=this,s=this.getScene(),a=function(e){var t=document.createElement("canvas"),s=t.getContext("2d"),a=e.width,h=e.height;t.width=a,t.height=h,s.drawImage(e,0,0);var l=s.getImageData(0,0,a,h).data;o.applyDisplacementMapFromBuffer(l,a,h,i,r),n&&n(o)};e.Tools.LoadImage(t,a,function(){},s.database)},r.prototype.applyDisplacementMapFromBuffer=function(t,i,r,n,o){if(!this.isVerticesDataPresent(e.VertexBuffer.PositionKind)||!this.isVerticesDataPresent(e.VertexBuffer.NormalKind)||!this.isVerticesDataPresent(e.VertexBuffer.UVKind))return void e.Tools.Warn("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing");for(var s=this.getVerticesData(e.VertexBuffer.PositionKind),a=this.getVerticesData(e.VertexBuffer.NormalKind),h=this.getVerticesData(e.VertexBuffer.UVKind),l=e.Vector3.Zero(),c=e.Vector3.Zero(),u=e.Vector2.Zero(),f=0;f<s.length;f+=3){e.Vector3.FromArrayToRef(s,f,l),e.Vector3.FromArrayToRef(a,f,c),e.Vector2.FromArrayToRef(h,f/3*2,u);var d=Math.abs(u.x)*i%i|0,p=Math.abs(u.y)*r%r|0,m=4*(d+p*i),g=t[m]/255,_=t[m+1]/255,v=t[m+2]/255,y=.3*g+.59*_+.11*v;c.normalize(),c.scaleInPlace(n+(o-n)*y),l=l.add(c),l.toArray(s,f)}e.VertexData.ComputeNormals(s,this.getIndices(),a),this.updateVerticesData(e.VertexBuffer.PositionKind,s),this.updateVerticesData(e.VertexBuffer.NormalKind,a)},r.prototype.convertToFlatShadedMesh=function(){var t,i,r=this.getVerticesDataKinds(),n=[],o=[],s=[],a=!1;for(t=0;t<r.length;t++){i=r[t];var h=this.getVertexBuffer(i);i!==e.VertexBuffer.NormalKind?(n[i]=h,o[i]=n[i].getData(),s[i]=[]):(a=h.isUpdatable(),r.splice(t,1),t--)}var l,c=this.subMeshes.slice(0),u=this.getIndices(),f=this.getTotalIndices();for(l=0;f>l;l++){var d=u[l];for(t=0;t<r.length;t++){i=r[t];for(var p=n[i].getStrideSize(),m=0;p>m;m++)s[i].push(o[i][d*p+m])}}var g=[],_=s[e.VertexBuffer.PositionKind];for(l=0;f>l;l+=3){u[l]=l,u[l+1]=l+1,u[l+2]=l+2;for(var v=e.Vector3.FromArray(_,3*l),y=e.Vector3.FromArray(_,3*(l+1)),x=e.Vector3.FromArray(_,3*(l+2)),M=v.subtract(y),S=x.subtract(y),b=e.Vector3.Normalize(e.Vector3.Cross(M,S)),A=0;3>A;A++)g.push(b.x),g.push(b.y),g.push(b.z)}for(this.setIndices(u),this.setVerticesData(e.VertexBuffer.NormalKind,g,a),t=0;t<r.length;t++)i=r[t],this.setVerticesData(i,s[i],n[i].isUpdatable());this.releaseSubMeshes();for(var T=0;T<c.length;T++){var E=c[T];new e.SubMesh(E.materialIndex,E.indexStart,E.indexCount,E.indexStart,E.indexCount,this)}this.synchronizeInstances()},r.prototype.flipFaces=function(t){void 0===t&&(t=!1);var i,r=e.VertexData.ExtractFromMesh(this);if(t&&this.isVerticesDataPresent(e.VertexBuffer.NormalKind))for(i=0;i<r.normals.length;i++)r.normals[i]*=-1;var n;for(i=0;i<r.indices.length;i+=3)n=r.indices[i+1],r.indices[i+1]=r.indices[i+2],r.indices[i+2]=n;r.applyToMesh(this)},r.prototype.createInstance=function(t){return new e.InstancedMesh(t,this)},r.prototype.synchronizeInstances=function(){for(var e=0;e<this.instances.length;e++){var t=this.instances[e];t._syncSubMeshes()}},r.prototype.simplify=function(t,i,r,n){void 0===i&&(i=!0),void 0===r&&(r=e.SimplificationType.QUADRATIC),this.getScene().simplificationQueue.addTask({settings:t,parallelProcessing:i,mesh:this,simplificationType:r,successCallback:n})},r.prototype.optimizeIndices=function(t){for(var i=this,r=this.getIndices(),n=this.getVerticesData(e.VertexBuffer.PositionKind),o=[],s=0;s<n.length;s+=3)o.push(e.Vector3.FromArray(n,s));var a=[];e.AsyncLoop.SyncAsyncForLoop(o.length,40,function(e){for(var t=o.length-1-e,i=o[t],r=0;t>r;++r){var n=o[r];if(i.equals(n)){a[t]=r;break}}},function(){for(var e=0;e<r.length;++e)r[e]=a[r[e]]||r[e];var n=i.subMeshes.slice(0);i.setIndices(r),i.subMeshes=n,t&&t(i)})},r.CreateRibbon=function(t,i,n,o,s,a,h,l,c){if(void 0===l&&(l=r.DEFAULTSIDE),void 0===c&&(c=null),c){var u=function(e){for(var t=i[0].length,n=0,o=c.sideOrientation===r.DOUBLESIDE?2:1,s=1;o>=s;s++)for(var a=0;a<i.length;a++){var h=i[a],l=h.length;t=l>t?t:l;for(var u=0;t>u;)e[n]=h[u].x,e[n+1]=h[u].y,e[n+2]=h[u].z,u++,n+=3;c._closePath&&(e[n]=h[0].x,e[n+1]=h[0].y,e[n+2]=h[0].z,n+=3)}},f=c.getVerticesData(e.VertexBuffer.PositionKind);if(u(f),c.updateVerticesData(e.VertexBuffer.PositionKind,f,!1,!1),!c.areNormalsFrozen){var d=c.getIndices(),p=c.getVerticesData(e.VertexBuffer.NormalKind);if(e.VertexData.ComputeNormals(f,d,p),c._closePath)for(var m=0,g=0,_=0;_<i.length;_++)m=3*c._idx[_],g=_+1<i.length?3*(c._idx[_+1]-1):p.length-3,p[m]=.5*(p[m]+p[g]),p[m+1]=.5*(p[m+1]+p[g+1]),p[m+2]=.5*(p[m+2]+p[g+2]),p[g]=p[m],p[g+1]=p[m+1],p[g+2]=p[m+2];c.updateVerticesData(e.VertexBuffer.NormalKind,p,!1,!1)}return c}var v=new r(t,a);v.sideOrientation=l;var y=e.VertexData.CreateRibbon(i,n,o,s,l);return o&&(v._idx=y._idx),v._closePath=o,y.applyToMesh(v,h),v},r.CreateDisc=function(t,i,n,o,s,a){void 0===a&&(a=r.DEFAULTSIDE);var h=new r(t,o),l=e.VertexData.CreateDisc(i,n,a);return l.applyToMesh(h,s),h},r.CreateBox=function(t,i,n,o,s){void 0===s&&(s=r.DEFAULTSIDE),o=o||i.updatable;var a=new r(t,n),h=e.VertexData.CreateBox(i,s);return h.applyToMesh(a,o),a},r.CreateSphere=function(t,i,n,o,s,a){if(void 0===a&&(a=r.DEFAULTSIDE),n instanceof e.Scene)o=n,s=i.updatable;else{var h=i;i={segments:h,diameterX:n,diameterY:n,diameterZ:n,sideOrientation:a}}var l=new r(t,o),c=e.VertexData.CreateSphere(i);return c.applyToMesh(l,s),l},r.CreateCylinder=function(t,i,n,o,s,a,h,l,c){void 0===c&&(c=r.DEFAULTSIDE),void 0!==h&&h instanceof e.Scene||(void 0!==h&&(l=h),h=a,a=1);var u=new r(t,h),f=e.VertexData.CreateCylinder(i,n,o,s,a,c);return f.applyToMesh(u,l),u},r.CreateTorus=function(t,i,n,o,s,a,h){void 0===h&&(h=r.DEFAULTSIDE);var l=new r(t,s),c=e.VertexData.CreateTorus(i,n,o,h);return c.applyToMesh(l,a),l},r.CreateTorusKnot=function(t,i,n,o,s,a,h,l,c,u){void 0===u&&(u=r.DEFAULTSIDE);var f=new r(t,l),d=e.VertexData.CreateTorusKnot(i,n,o,s,a,h,u);return d.applyToMesh(f,c),f},r.CreateLines=function(t,i,r,n,o){if(void 0===o&&(o=null),o){var s=function(e){for(var t=0,r=0;r<i.length;r++)e[t]=i[r].x,e[t+1]=i[r].y,e[t+2]=i[r].z,t+=3};return o.updateMeshPositions(s,!1),o}var a=new e.LinesMesh(t,r),h=e.VertexData.CreateLines(i);return h.applyToMesh(a,n),a},r.CreateDashedLines=function(t,i,r,n,o,s,a,h){if(void 0===h&&(h=null),h){var l=function(t){var r=e.Vector3.Zero(),n=t.length/6,o=0,s=0,a=0,l=0,c=0,u=0,f=0,d=0;for(f=0;f<i.length-1;f++)i[f+1].subtractToRef(i[f],r),o+=r.length();for(a=o/n,l=h.dashSize*a/(h.dashSize+h.gapSize),f=0;f<i.length-1;f++)for(i[f+1].subtractToRef(i[f],r),s=Math.floor(r.length()/a),r.normalize(),d=0;s>d&&u<t.length;)c=a*d,t[u]=i[f].x+c*r.x,t[u+1]=i[f].y+c*r.y,t[u+2]=i[f].z+c*r.z,t[u+3]=i[f].x+(c+l)*r.x,t[u+4]=i[f].y+(c+l)*r.y,t[u+5]=i[f].z+(c+l)*r.z,u+=6,d++;for(;u<t.length;)t[u]=i[f].x,t[u+1]=i[f].y,t[u+2]=i[f].z,u+=3};return h.updateMeshPositions(l,!1),h}var c=new e.LinesMesh(t,s),u=e.VertexData.CreateDashedLines(i,r,n,o);return u.applyToMesh(c,a),c.dashSize=r,c.gapSize=n,c},r.ExtrudeShape=function(e,t,i,n,o,s,a,h,l,c){void 0===l&&(l=r.DEFAULTSIDE),void 0===c&&(c=null),n=n||1,o=o||0;var u=r._ExtrudeShapeGeneric(e,t,i,n,o,null,null,!1,!1,s,!1,a,h,l,c);return u},r.ExtrudeShapeCustom=function(e,t,i,n,o,s,a,h,l,c,u,f){void 0===u&&(u=r.DEFAULTSIDE),void 0===f&&(f=null);var d=r._ExtrudeShapeGeneric(e,t,i,null,null,n,o,s,a,h,!0,l,c,u,f);return d},r._ExtrudeShapeGeneric=function(t,i,n,o,s,a,h,l,c,u,f,d,p,m,g){var _,v,y=function(t,i,n,o,s,a,h,l,c,u){for(var f=n.getTangents(),d=n.getNormals(),p=n.getBinormals(),m=n.getDistances(),g=0,_=function(e,t){return s},v=function(e,t){return a},y=u?l:v,x=u?h:_,M=0,S=0;S<i.length;S++){for(var b=new Array,A=y(S,m[S]),T=x(S,m[S]),E=0;E<t.length;E++){var P=e.Matrix.RotationAxis(f[S],g),D=f[S].scale(t[E].z).add(d[S].scale(t[E].x)).add(p[S].scale(t[E].y)),C=e.Vector3.TransformCoordinates(D,P).scaleInPlace(T).add(i[S]);b.push(C)}o[M]=b,g+=A,M++}var I=function(t){var i,r=Array(),n=e.Vector3.Zero();for(i=0;i<t.length;i++)n.addInPlace(t[i]);for(n.scaleInPlace(1/t.length),i=0;i<t.length;i++)r.push(n);return r};switch(c){case r.NO_CAP:break;case r.CAP_START:o.unshift(I(o[0]));break;case r.CAP_END:o.push(I(o[o.length-1]));break;case r.CAP_ALL:o.unshift(I(o[0])),o.push(I(o[o.length-1]))}return o};if(g)return _=g.path3D.update(n),v=y(i,n,g.path3D,g.pathArray,o,s,a,h,g.cap,f),g=r.CreateRibbon(null,v,null,null,null,null,null,null,g);_=new e.Path3D(n);var x=new Array;u=0>u||u>3?0:u,v=y(i,n,_,x,o,s,a,h,u,f);var M=r.CreateRibbon(t,v,l,c,0,d,p,m);return M.pathArray=v,M.path3D=_,M.cap=u,M},r.CreateLathe=function(t,i,n,o,s,a,h){void 0===h&&(h=r.DEFAULTSIDE),n=n||1,o=o||60*n;for(var l=2*Math.PI,c=new Array,u=0;0===i[u].x;)u++;var f=i[u];for(u=0;u<i.length;u++)c.push(i[u].subtract(f));var d,p=l/o,m=new Array;for(u=0;o>u;u++)d=new e.Vector3(Math.cos(u*p)*n,0,Math.sin(u*p)*n),m.push(d);m.push(m[0]);var g=function(){return 1},_=function(){return 0},v=r.ExtrudeShapeCustom(t,c,m,g,_,!0,!1,r.NO_CAP,s,a,h);return v},r.CreatePlane=function(t,i,n,o,s){void 0===s&&(s=r.DEFAULTSIDE);var a=new r(t,n),h=e.VertexData.CreatePlane(i,s);return h.applyToMesh(a,o||i.updatable),a},r.CreateGround=function(t,i,r,n,o,s){if(r instanceof e.Scene)o=r,s=i.updatable;else{var a=i;i={width:a,height:r,subdivisions:n}}var h=new e.GroundMesh(t,o);h._setReady(!1),h._subdivisions=i.subdivisions||1;var l=e.VertexData.CreateGround(i);return l.applyToMesh(h,s||i.updatable),h._setReady(!0),h},r.CreateTiledGround=function(t,i,n,o,s,a,h,l,c){var u=new r(t,l),f=e.VertexData.CreateTiledGround(i,n,o,s,a,h);return f.applyToMesh(u,c),u},r.CreateGroundFromHeightMap=function(t,i,r,n,o,s,a,h,l,c){var u=new e.GroundMesh(t,h);u._subdivisions=o,u._setReady(!1);var f=function(t){var i=document.createElement("canvas"),h=i.getContext("2d"),f=t.width,d=t.height;i.width=f,i.height=d,h.drawImage(t,0,0);var p=h.getImageData(0,0,f,d).data,m=e.VertexData.CreateGroundFromHeightMap(r,n,o,s,a,p,f,d);m.applyToMesh(u,l),u._setReady(!0),c&&c(u)};return e.Tools.LoadImage(i,f,function(){},h.database),u},r.CreateTube=function(t,i,n,o,s,a,h,l,c,u){void 0===c&&(c=r.DEFAULTSIDE),void 0===u&&(u=null);var f,d,p=function(t,i,n,o,s,a,h){for(var l,c,u,f,d,p=i.getTangents(),m=i.getNormals(),g=i.getDistances(),_=2*Math.PI,v=_/s,y=function(e,t){return o},x=a||y,M=0,S=0;S<t.length;S++){c=x(S,g[S]),l=Array(),u=m[S];for(var b=0;s>b;b++)d=e.Matrix.RotationAxis(p[S],v*b),f=e.Vector3.TransformCoordinates(u,d).scaleInPlace(c).add(t[S]),l.push(f);n[M]=l,M++}var A=function(e,i){for(var r=Array(),n=0;e>n;n++)r.push(t[i]);return r};switch(h){case r.NO_CAP:break;case r.CAP_START:n.unshift(A(s+1,0));break;case r.CAP_END:n.push(A(s+1,t.length-1));break;case r.CAP_ALL:n.unshift(A(s+1,0)),n.push(A(s+1,t.length-1))}return n};if(u)return f=u.path3D.update(i),d=p(i,f,u.pathArray,n,u.tessellation,s,u.cap),u=r.CreateRibbon(null,d,null,null,null,null,null,null,u);f=new e.Path3D(i);var m=new Array;a=0>a||a>3?0:a,d=p(i,f,m,n,o,s,a);var g=r.CreateRibbon(t,d,!1,!0,0,h,l,c);return g.pathArray=d,g.path3D=f,g.tessellation=o,g.cap=a,g},r.CreateDecal=function(t,i,n,o,s,a){void 0===a&&(a=0);var h=i.getIndices(),l=i.getVerticesData(e.VertexBuffer.PositionKind),c=i.getVerticesData(e.VertexBuffer.NormalKind);if(!o){var u=new e.Vector3(0,0,1),f=i.getScene().activeCamera,d=e.Vector3.TransformCoordinates(u,f.getWorldMatrix());o=f.globalPosition.subtract(d)}var p=-Math.atan2(o.z,o.x)-Math.PI/2,m=Math.sqrt(o.x*o.x+o.z*o.z),g=Math.atan2(o.y,m),_=e.Matrix.RotationYawPitchRoll(p,g,a).multiply(e.Matrix.Translation(n.x,n.y,n.z)),v=e.Matrix.Invert(_),y=i.getWorldMatrix(),x=y.multiply(v),M=new e.VertexData;M.indices=[],M.positions=[],M.normals=[],M.uvs=[];for(var S=0,b=function(t){var i=h[t],r=new e.PositionNormalVertex;return r.position=new e.Vector3(l[3*i],l[3*i+1],l[3*i+2]),r.position=e.Vector3.TransformCoordinates(r.position,x),r.normal=new e.Vector3(c[3*i],c[3*i+1],c[3*i+2]),r},A=function(t,i){if(0===t.length)return t;for(var r=.5*Math.abs(e.Vector3.Dot(s,i)),n=function(t,n){var o=e.Vector3.GetClipFactor(t.position,n.position,i,r);return new e.PositionNormalVertex(e.Vector3.Lerp(t.position,n.position,o),e.Vector3.Lerp(t.normal,n.normal,o))},o=new Array,a=0;a<t.length;a+=3){var h,l,c,u,f,d,p,m=0,g=e.Vector3.Dot(t[a].position,i)-r,_=e.Vector3.Dot(t[a+1].position,i)-r,v=e.Vector3.Dot(t[a+2].position,i)-r;switch(h=g>0,l=_>0,c=v>0,m=(h?1:0)+(l?1:0)+(c?1:0)){case 0:o.push(t[a]),o.push(t[a+1]),o.push(t[a+2]);break;case 1:if(h&&(u=t[a+1],f=t[a+2],d=n(t[a],u),p=n(t[a],f)),l){u=t[a],f=t[a+2],d=n(t[a+1],u),p=n(t[a+1],f),o.push(d),o.push(f.clone()),o.push(u.clone()),o.push(f.clone()),o.push(d.clone()),o.push(p);break}c&&(u=t[a],f=t[a+1],d=n(t[a+2],u),p=n(t[a+2],f)),o.push(u.clone()),o.push(f.clone()),o.push(d),o.push(p),o.push(d.clone()),o.push(f.clone());break;case 2:h||(u=t[a].clone(),f=n(u,t[a+1]),d=n(u,t[a+2]),o.push(u),o.push(f),o.push(d)),l||(u=t[a+1].clone(),f=n(u,t[a+2]),d=n(u,t[a]),o.push(u),o.push(f),o.push(d)),c||(u=t[a+2].clone(),f=n(u,t[a]),d=n(u,t[a+1]),o.push(u),o.push(f),o.push(d));break;case 3:}}return o},T=0;T<h.length;T+=3){var E=new Array;if(E.push(b(T)),E.push(b(T+1)),E.push(b(T+2)),E=A(E,new e.Vector3(1,0,0)),E=A(E,new e.Vector3(-1,0,0)),E=A(E,new e.Vector3(0,1,0)),E=A(E,new e.Vector3(0,-1,0)),E=A(E,new e.Vector3(0,0,1)),E=A(E,new e.Vector3(0,0,-1)),0!==E.length)for(var P=0;P<E.length;P++){var D=E[P];M.indices.push(S),D.position.toArray(M.positions,3*S),D.normal.toArray(M.normals,3*S),M.uvs.push(.5+D.position.x/s.x),M.uvs.push(.5+D.position.y/s.y),S++}}var C=new r(t,i.getScene());return M.applyToMesh(C),C.position=n.clone(),C.rotation=new e.Vector3(g,p,a),C},r.prototype.applySkeleton=function(t){if(!this.isVerticesDataPresent(e.VertexBuffer.PositionKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.NormalKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind))return this;if(!this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind))return this;var i;this._sourcePositions||(i=this.getVerticesData(e.VertexBuffer.PositionKind),this._sourcePositions=new Float32Array(i),this.getVertexBuffer(e.VertexBuffer.PositionKind).isUpdatable()||this.setVerticesData(e.VertexBuffer.PositionKind,i,!0)),this._sourceNormals||(i=this.getVerticesData(e.VertexBuffer.NormalKind),this._sourceNormals=new Float32Array(i),this.getVertexBuffer(e.VertexBuffer.NormalKind).isUpdatable()||this.setVerticesData(e.VertexBuffer.NormalKind,i,!0));for(var r=this.getVerticesData(e.VertexBuffer.PositionKind),n=this.getVerticesData(e.VertexBuffer.NormalKind),o=this.getVerticesData(e.VertexBuffer.MatricesIndicesKind),s=this.getVerticesData(e.VertexBuffer.MatricesWeightsKind),a=t.getTransformMatrices(),h=e.Vector3.Zero(),l=new e.Matrix,c=new e.Matrix,u=0;u<r.length;u+=3){var f=u/3*4,d=s[f],p=s[f+1],m=s[f+2],g=s[f+3];d>0&&(e.Matrix.FromFloat32ArrayToRefScaled(a,16*o[f],d,c),l.addToSelf(c)),p>0&&(e.Matrix.FromFloat32ArrayToRefScaled(a,16*o[f+1],p,c),l.addToSelf(c)),m>0&&(e.Matrix.FromFloat32ArrayToRefScaled(a,16*o[f+2],m,c),l.addToSelf(c)),g>0&&(e.Matrix.FromFloat32ArrayToRefScaled(a,16*o[f+3],g,c),l.addToSelf(c)),e.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[u],this._sourcePositions[u+1],this._sourcePositions[u+2],l,h),h.toArray(r,u),e.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[u],this._sourceNormals[u+1],this._sourceNormals[u+2],l,h),h.toArray(n,u),l.reset()}return this.updateVerticesData(e.VertexBuffer.PositionKind,r),this.updateVerticesData(e.VertexBuffer.NormalKind,n),this},r.MinMax=function(e){var t=null,i=null;for(var r in e){var n=e[r],o=n.getBoundingInfo().boundingBox;t?(t.MinimizeInPlace(o.minimumWorld),i.MaximizeInPlace(o.maximumWorld)):(t=o.minimumWorld,i=o.maximumWorld)}return{min:t,max:i}},r.Center=function(t){var i=void 0!==t.min?t:r.MinMax(t);return e.Vector3.Center(i.min,i.max)},r.MergeMeshes=function(t,i,n,o){void 0===i&&(i=!0);var s;if(!n){var a=0;for(s=0;s<t.length;s++)if(t[s]&&(a+=t[s].getTotalVertices(),a>65536))return e.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 h,l,c;for(s=0;s<t.length;s++)t[s]&&(t[s].computeWorldMatrix(!0),l=e.VertexData.ExtractFromMesh(t[s],!0),l.transform(t[s].getWorldMatrix()),h?h.merge(l):(h=l,c=t[s]));if(o||(o=new r(c.name+"_merged",c.getScene())),h.applyToMesh(o),o.material=c.material,o.checkCollisions=c.checkCollisions,i)for(s=0;s<t.length;s++)t[s]&&t[s].dispose();return o},r._FRONTSIDE=0,r._BACKSIDE=1,r._DOUBLESIDE=2,r._DEFAULTSIDE=0,r._NO_CAP=0,r._CAP_START=1,r._CAP_END=2,r._CAP_ALL=3,r}(e.AbstractMesh);e.Mesh=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,r,n,o,s,a){void 0===a&&(a=!0),this.materialIndex=e,this.verticesStart=t,this.verticesCount=i,this.indexStart=r,this.indexCount=n,this._renderId=0,this._mesh=o,this._renderingMesh=s||o,o.subMeshes.push(this),this._trianglePlanes=[],this._id=o.subMeshes.length-1,a&&(this.refreshBoundingInfo(),o.computeWorldMatrix(!0))}return t.prototype.getBoundingInfo=function(){return this._boundingInfo},t.prototype.getMesh=function(){return this._mesh},t.prototype.getRenderingMesh=function(){return this._renderingMesh},t.prototype.getMaterial=function(){var t=this._renderingMesh.material;if(t&&t instanceof e.MultiMaterial){var i=t;return i.getSubMaterial(this.materialIndex)}return t?t:this._mesh.getScene().defaultMaterial},t.prototype.refreshBoundingInfo=function(){var t=this._renderingMesh.getVerticesData(e.VertexBuffer.PositionKind);if(!t)return void(this._boundingInfo=this._mesh._boundingInfo);var i,r=this._renderingMesh.getIndices();i=0===this.indexStart&&this.indexCount===r.length?e.Tools.ExtractMinAndMax(t,this.verticesStart,this.verticesCount):e.Tools.ExtractMinAndMaxIndexed(t,r,this.indexStart,this.indexCount),this._boundingInfo=new e.BoundingInfo(i.minimum,i.maximum)},t.prototype._checkCollision=function(e){return this._boundingInfo._checkCollision(e)},t.prototype.updateBoundingInfo=function(e){this._boundingInfo||this.refreshBoundingInfo(),this._boundingInfo._update(e)},t.prototype.isInFrustum=function(e){return this._boundingInfo.isInFrustum(e)},t.prototype.render=function(e){this._renderingMesh.render(this,e)},t.prototype.getLinesIndexBuffer=function(e,t){if(!this._linesIndexBuffer){for(var i=[],r=this.indexStart;r<this.indexStart+this.indexCount;r+=3)i.push(e[r],e[r+1],e[r+1],e[r+2],e[r+2],e[r]);this._linesIndexBuffer=t.createIndexBuffer(i),this.linesIndexCount=i.length}return this._linesIndexBuffer},t.prototype.canIntersects=function(e){return e.intersectsBox(this._boundingInfo.boundingBox)},t.prototype.intersects=function(e,t,i,r){for(var n=null,o=this.indexStart;o<this.indexStart+this.indexCount;o+=3){var s=t[i[o]],a=t[i[o+1]],h=t[i[o+2]],l=e.intersectsTriangle(s,a,h);if(l){if(l.distance<0)continue;if((r||!n||l.distance<n.distance)&&(n=l,n.faceId=o/3,r))break}}return n},t.prototype.clone=function(i,r){var n=new t(this.materialIndex,this.verticesStart,this.verticesCount,this.indexStart,this.indexCount,i,r,!1);return n._boundingInfo=new e.BoundingInfo(this._boundingInfo.minimum,this._boundingInfo.maximum),n},t.prototype.dispose=function(){this._linesIndexBuffer&&(this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer),this._linesIndexBuffer=null);var e=this._mesh.subMeshes.indexOf(this);this._mesh.subMeshes.splice(e,1)},t.CreateFromIndices=function(e,i,r,n,o){var s=Number.MAX_VALUE,a=-Number.MAX_VALUE;o=o||n;for(var h=o.getIndices(),l=i;i+r>l;l++){var c=h[l];s>c&&(s=c),c>a&&(a=c)}return new t(e,s,a-s+1,i,r,n,o)},t}();e.SubMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.delayLoadState=e.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=e.Texture.EXPLICIT_MODE,this.wrapU=e.Texture.WRAP_ADDRESSMODE,this.wrapV=e.Texture.WRAP_ADDRESSMODE,this.anisotropicFilteringLevel=4,this._scene=t,this._scene.textures.push(this)}return t.prototype.getScene=function(){return this._scene},t.prototype.getTextureMatrix=function(){return null},t.prototype.getReflectionTextureMatrix=function(){return null},t.prototype.getInternalTexture=function(){return this._texture},t.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED?!0:this._texture?this._texture.isReady:!1},t.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}},t.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}},t.prototype.scale=function(e){},Object.defineProperty(t.prototype,"canRescale",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype._removeFromCache=function(e,t){for(var i=this._scene.getEngine().getLoadedTexturesCache(),r=0;r<i.length;r++){var n=i[r];if(n.url===e&&n.noMipmap===t)return void i.splice(r,1)}},t.prototype._getFromCache=function(e,t,i){for(var r=this._scene.getEngine().getLoadedTexturesCache(),n=0;n<r.length;n++){var o=r[n];if(o.url===e&&o.noMipmap===t&&(!i||i===o.samplingMode))return o.references++,o}return null},t.prototype.delayLoad=function(){},t.prototype.releaseInternalTexture=function(){if(this._texture){var e=this._scene.getEngine().getLoadedTexturesCache();if(this._texture.references--,0===this._texture.references){var t=e.indexOf(this._texture);e.splice(t,1),this._scene.getEngine()._releaseTexture(this._texture),delete this._texture}}},t.prototype.clone=function(){return null},t.prototype.dispose=function(){var e=this._scene.textures.indexOf(this);e>=0&&this._scene.textures.splice(e,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDispose&&this.onDispose())},t}();e.BaseTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(r,n,o,s,a,h,l,c,u){void 0===a&&(a=i.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===l&&(l=null),void 0===c&&(c=null),void 0===u&&(u=!1),t.call(this,n),this.uOffset=0,this.vOffset=0,this.uScale=1,this.vScale=1,this.uAng=0,this.vAng=0,this.wAng=0,this.name=r,this.url=r,this._noMipmap=o,this._invertY=s,this._samplingMode=a,this._buffer=c,this._deleteBuffer=u,r&&(this._texture=this._getFromCache(r,o,a),this._texture?e.Tools.SetImmediate(function(){h&&h()}):n.useDelayedTextureLoading?this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:(this._texture=n.getEngine().createTexture(r,o,s,n,this._samplingMode,h,l,this._buffer),u&&delete this._buffer))}return __extends(i,t),i.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap,this._samplingMode),this._texture||(this._texture=this.getScene().getEngine().createTexture(this.url,this._noMipmap,this._invertY,this.getScene(),this._samplingMode,null,null,this._buffer),this._deleteBuffer&&delete this._buffer))},i.prototype.updateSamplingMode=function(e){this._texture&&this.getScene().getEngine().updateTextureSamplingMode(e,this._texture)},i.prototype._prepareRowForTextureGeneration=function(t,i,r,n){t-=this.uOffset+.5,i-=this.vOffset+.5,r-=.5,e.Vector3.TransformCoordinatesFromFloatsToRef(t,i,r,this._rowGenerationMatrix,n),n.x*=this.uScale,n.y*=this.vScale,n.x+=.5,n.y+=.5,n.z+=.5},i.prototype.getTextureMatrix=function(){return this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.uAng===this._cachedUAng&&this.vAng===this._cachedVAng&&this.wAng===this._cachedWAng?this._cachedTextureMatrix:(this._cachedUOffset=this.uOffset,this._cachedVOffset=this.vOffset,this._cachedUScale=this.uScale,this._cachedVScale=this.vScale,this._cachedUAng=this.uAng,this._cachedVAng=this.vAng,this._cachedWAng=this.wAng,this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._rowGenerationMatrix=new e.Matrix,this._t0=e.Vector3.Zero(),this._t1=e.Vector3.Zero(),this._t2=e.Vector3.Zero()),e.Matrix.RotationYawPitchRollToRef(this.vAng,this.uAng,this.wAng,this._rowGenerationMatrix),this._prepareRowForTextureGeneration(0,0,0,this._t0),this._prepareRowForTextureGeneration(1,0,0,this._t1),
  this._prepareRowForTextureGeneration(0,1,0,this._t2),this._t1.subtractInPlace(this._t0),this._t2.subtractInPlace(this._t0),e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix.m[0]=this._t1.x,this._cachedTextureMatrix.m[1]=this._t1.y,this._cachedTextureMatrix.m[2]=this._t1.z,this._cachedTextureMatrix.m[4]=this._t2.x,this._cachedTextureMatrix.m[5]=this._t2.y,this._cachedTextureMatrix.m[6]=this._t2.z,this._cachedTextureMatrix.m[8]=this._t0.x,this._cachedTextureMatrix.m[9]=this._t0.y,this._cachedTextureMatrix.m[10]=this._t0.z,this._cachedTextureMatrix)},i.prototype.getReflectionTextureMatrix=function(){if(this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.coordinatesMode===this._cachedCoordinatesMode)return this._cachedTextureMatrix;switch(this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._projectionModeMatrix=e.Matrix.Zero()),this._cachedCoordinatesMode=this.coordinatesMode,this.coordinatesMode){case i.SPHERICAL_MODE:e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix[0]=-.5*this.uScale,this._cachedTextureMatrix[5]=-.5*this.vScale,this._cachedTextureMatrix[12]=.5+this.uOffset,this._cachedTextureMatrix[13]=.5+this.vOffset;break;case i.PLANAR_MODE:e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix[0]=this.uScale,this._cachedTextureMatrix[5]=this.vScale,this._cachedTextureMatrix[12]=this.uOffset,this._cachedTextureMatrix[13]=this.vOffset;break;case i.PROJECTION_MODE:e.Matrix.IdentityToRef(this._projectionModeMatrix),this._projectionModeMatrix.m[0]=.5,this._projectionModeMatrix.m[5]=-.5,this._projectionModeMatrix.m[10]=0,this._projectionModeMatrix.m[12]=.5,this._projectionModeMatrix.m[13]=.5,this._projectionModeMatrix.m[14]=1,this._projectionModeMatrix.m[15]=1,this.getScene().getProjectionMatrix().multiplyToRef(this._projectionModeMatrix,this._cachedTextureMatrix);break;default:e.Matrix.IdentityToRef(this._cachedTextureMatrix)}return this._cachedTextureMatrix},i.prototype.clone=function(){var e=new i(this._texture.url,this.getScene(),this._noMipmap,this._invertY,this._samplingMode);return e.hasAlpha=this.hasAlpha,e.level=this.level,e.wrapU=this.wrapU,e.wrapV=this.wrapV,e.coordinatesIndex=this.coordinatesIndex,e.coordinatesMode=this.coordinatesMode,e.uOffset=this.uOffset,e.vOffset=this.vOffset,e.uScale=this.uScale,e.vScale=this.vScale,e.uAng=this.uAng,e.vAng=this.vAng,e.wAng=this.wAng,e},i.CreateFromBase64String=function(e,t,r,n,o,s,a,h){return void 0===s&&(s=i.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),new i("data:"+t,r,n,o,s,a,h,e)},i.NEAREST_SAMPLINGMODE=1,i.BILINEAR_SAMPLINGMODE=2,i.TRILINEAR_SAMPLINGMODE=3,i.EXPLICIT_MODE=0,i.SPHERICAL_MODE=1,i.PLANAR_MODE=2,i.CUBIC_MODE=3,i.PROJECTION_MODE=4,i.SKYBOX_MODE=5,i.CLAMP_ADDRESSMODE=0,i.WRAP_ADDRESSMODE=1,i.MIRROR_ADDRESSMODE=2,i}(e.BaseTexture);e.Texture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){t.call(this,r),this.coordinatesMode=e.Texture.CUBIC_MODE,this.name=i,this.url=i,this._noMipmap=o,this.hasAlpha=!1,this._texture=this._getFromCache(i,o),n||(n=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"]),this._extensions=n,this._texture||(r.useDelayedTextureLoading?this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED:this._texture=r.getEngine().createCubeTexture(i,r,n,o)),this.isCube=!0,this._textureMatrix=e.Matrix.Identity()}return __extends(i,t),i.prototype.clone=function(){var e=new i(this.url,this.getScene(),this._extensions,this._noMipmap);return e.level=this.level,e.wrapU=this.wrapU,e.wrapV=this.wrapV,e.coordinatesIndex=this.coordinatesIndex,e.coordinatesMode=this.coordinatesMode,e},i.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap),this._texture||(this._texture=this.getScene().getEngine().createCubeTexture(this.url,this.getScene(),this._extensions)))},i.prototype.getReflectionTextureMatrix=function(){return this._textureMatrix},i}(e.BaseTexture);e.CubeTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s,a){void 0===s&&(s=!0),void 0===a&&(a=e.Engine.TEXTURETYPE_UNSIGNED_INT),t.call(this,null,n,!o),this.renderList=new Array,this.renderParticles=!0,this.renderSprites=!1,this.coordinatesMode=e.Texture.PROJECTION_MODE,this._currentRefreshId=-1,this._refreshRate=1,this.name=i,this.isRenderTarget=!0,this._size=r,this._generateMipMaps=o,this._doNotChangeAspectRatio=s,this._texture=n.getEngine().createRenderTargetTexture(r,{generateMipMaps:o,type:a}),this._renderingManager=new e.RenderingManager(n)}return __extends(i,t),i.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},Object.defineProperty(i.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),i.prototype._shouldRender=function(){return-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1)},i.prototype.isReady=function(){return this.getScene().renderTargetsEnabled?t.prototype.isReady.call(this):!1},i.prototype.getRenderSize=function(){return this._size},Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype.scale=function(e){var t=this._size*e;this.resize(t,this._generateMipMaps)},i.prototype.resize=function(e,t){this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createRenderTargetTexture(e,t)},i.prototype.render=function(t,i){var r=this.getScene(),n=r.getEngine();if(this._waitingRenderList){this.renderList=[];for(var o=0;o<this._waitingRenderList.length;o++){var s=this._waitingRenderList[o];this.renderList.push(r.getMeshByID(s))}delete this._waitingRenderList}if(!this.renderList||0!==this.renderList.length){t&&r.postProcessManager._prepareFrame(this._texture)||n.bindFramebuffer(this._texture),this._renderingManager.reset();for(var a=this.renderList?this.renderList:r.getActiveMeshes().data,h=0;h<a.length;h++){var l=a[h];if(l){if(!l.isReady()){this.resetRefreshCounter();continue}if(l.isEnabled()&&l.isVisible&&l.subMeshes&&0!==(l.layerMask&r.activeCamera.layerMask)){l._activate(r.getRenderId());for(var c=0;c<l.subMeshes.length;c++){var u=l.subMeshes[c];r._activeIndices+=u.indexCount,this._renderingManager.dispatch(u)}}}}this.onBeforeRender&&this.onBeforeRender(),this.onClear?this.onClear(n):n.clear(r.clearColor,!0,!0),this._doNotChangeAspectRatio||r.updateTransformMatrix(!0),this._renderingManager.render(this.customRenderFunction,a,this.renderParticles,this.renderSprites),t&&r.postProcessManager._finalizeFrame(!1,this._texture),this._doNotChangeAspectRatio||r.updateTransformMatrix(!0),this.onAfterRender&&this.onAfterRender(),i&&e.Tools.DumpFramebuffer(this._size,this._size,n),n.unBindFramebuffer(this._texture),this.onAfterUnbind&&this.onAfterUnbind()}},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesMode=this.coordinatesMode,t.renderList=this.renderList.slice(0),t},i}(e.Texture);e.RenderTargetTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s){void 0===s&&(s=!0),e.call(this,null,n,!s),this.isEnabled=!0,this._currentRefreshId=-1,this._refreshRate=1,this._vertexDeclaration=[2],this._vertexStrideSize=8,this._uniforms=new Array,this._samplers=new Array,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._fallbackTextureUsed=!1,n._proceduralTextures.push(this),this.name=t,this.isRenderTarget=!0,this._size=i,this._generateMipMaps=s,this.setFragment(r),this._fallbackTexture=o,this._texture=n.getEngine().createRenderTargetTexture(i,s);var a=[];a.push(1,1),a.push(-1,1),a.push(-1,-1),a.push(1,-1),this._vertexBuffer=n.getEngine().createVertexBuffer(a);var h=[];h.push(0),h.push(1),h.push(2),h.push(0),h.push(2),h.push(3),this._indexBuffer=n.getEngine().createIndexBuffer(h)}return __extends(t,e),t.prototype.reset=function(){if(void 0!==this._effect){var e=this.getScene().getEngine();e._releaseEffect(this._effect)}},t.prototype.isReady=function(){var e,t=this,i=this.getScene().getEngine();return this._fragment?this._fallbackTextureUsed?!0:(e=void 0!==this._fragment.fragmentElement?{vertex:"procedural",fragmentElement:this._fragment.fragmentElement}:{vertex:"procedural",fragment:this._fragment},this._effect=i.createEffect(e,["position"],this._uniforms,this._samplers,"",null,null,function(){t.releaseInternalTexture(),t._fallbackTexture&&(t._texture=t._fallbackTexture._texture,t._texture.references++),t._fallbackTextureUsed=!0}),this._effect.isReady()):!1},t.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},t.prototype.setFragment=function(e){this._fragment=e},Object.defineProperty(t.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(e){this._refreshRate=e,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),t.prototype._shouldRender=function(){return this.isEnabled&&this.isReady()&&this._texture?this._fallbackTextureUsed?!1:-1===this._currentRefreshId?(this._currentRefreshId=1,!0):this.refreshRate===this._currentRefreshId?(this._currentRefreshId=1,!0):(this._currentRefreshId++,!1):!1},t.prototype.getRenderSize=function(){return this._size},t.prototype.resize=function(e,t){this._fallbackTextureUsed||(this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createRenderTargetTexture(e,t))},t.prototype._checkUniform=function(e){-1===this._uniforms.indexOf(e)&&this._uniforms.push(e)},t.prototype.setTexture=function(e,t){return-1===this._samplers.indexOf(e)&&this._samplers.push(e),this._textures[e]=t,this},t.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},t.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},t.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},t.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},t.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},t.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},t.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},t.prototype.render=function(e){var t=this.getScene(),i=t.getEngine();i.bindFramebuffer(this._texture),i.clear(t.clearColor,!0,!0),i.enableEffect(this._effect),i.setState(!1);for(var r in this._textures)this._effect.setTexture(r,this._textures[r]);for(r in this._floats)this._effect.setFloat(r,this._floats[r]);for(r in this._floatsArrays)this._effect.setArray(r,this._floatsArrays[r]);for(r in this._colors3)this._effect.setColor3(r,this._colors3[r]);for(r in this._colors4){var n=this._colors4[r];this._effect.setFloat4(r,n.r,n.g,n.b,n.a)}for(r in this._vectors2)this._effect.setVector2(r,this._vectors2[r]);for(r in this._vectors3)this._effect.setVector3(r,this._vectors3[r]);for(r in this._matrices)this._effect.setMatrix(r,this._matrices[r]);i.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect),i.draw(!0,0,6),i.unBindFramebuffer(this._texture)},t.prototype.clone=function(){var e=this.getSize(),i=new t(this.name,e.width,this._fragment,this.getScene(),this._fallbackTexture,this._generateMipMaps);return i.hasAlpha=this.hasAlpha,i.level=this.level,i.coordinatesMode=this.coordinatesMode,i},t.prototype.dispose=function(){var t=this.getScene()._proceduralTextures.indexOf(this);t>=0&&this.getScene()._proceduralTextures.splice(t,1),e.prototype.dispose.call(this)},t}(e.Texture);e.ProceduralTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){var s=this;t.call(this,i,r,n,o,!0),this.mirrorPlane=new e.Plane(0,1,0,1),this._transformMatrix=e.Matrix.Zero(),this._mirrorMatrix=e.Matrix.Zero(),this.onBeforeRender=function(){e.Matrix.ReflectionToRef(s.mirrorPlane,s._mirrorMatrix),s._savedViewMatrix=n.getViewMatrix(),s._mirrorMatrix.multiplyToRef(s._savedViewMatrix,s._transformMatrix),n.setTransformMatrix(s._transformMatrix,n.getProjectionMatrix()),n.clipPlane=s.mirrorPlane,n.getEngine().cullBackFaces=!1},this.onAfterRender=function(){n.setTransformMatrix(s._savedViewMatrix,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!0,delete n.clipPlane}}return __extends(i,t),i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.mirrorPlane=this.mirrorPlane.clone(),t.renderList=this.renderList.slice(0),t},i}(e.RenderTargetTexture);e.MirrorTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s){void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,n,!o),this.name=i,this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._generateMipMaps=o,r.getContext?(this._canvas=r,this._texture=n.getEngine().createDynamicTexture(r.width,r.height,o,s)):(this._canvas=document.createElement("canvas"),this._texture=r.width?n.getEngine().createDynamicTexture(r.width,r.height,o,s):n.getEngine().createDynamicTexture(r,r,o,s));var a=this.getSize();this._canvas.width=a.width,this._canvas.height=a.height,this._context=this._canvas.getContext("2d")}return __extends(i,t),Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype.scale=function(e){var t=this.getSize();t.width*=e,t.height*=e,this._canvas.width=t.width,this._canvas.height=t.height,this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createDynamicTexture(t.width,t.height,this._generateMipMaps,this._samplingMode)},i.prototype.getContext=function(){return this._context},i.prototype.clear=function(){var e=this.getSize();this._context.fillRect(0,0,e.width,e.height)},i.prototype.update=function(e){this.getScene().getEngine().updateDynamicTexture(this._texture,this._canvas,void 0===e?!0:e)},i.prototype.drawText=function(e,t,i,r,n,o,s,a){void 0===a&&(a=!0);var h=this.getSize();if(o&&(this._context.fillStyle=o,this._context.fillRect(0,0,h.width,h.height)),this._context.font=r,null===t){var l=this._context.measureText(e);t=(h.width-l.width)/2}this._context.fillStyle=n,this._context.fillText(e,t,i),a&&this.update(s)},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.wrapU=this.wrapU,t.wrapV=this.wrapV,t},i}(e.Texture);e.DynamicTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s,a){var h=this;void 0===o&&(o=!1),void 0===s&&(s=!1),void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,n,!o,s),this._autoLaunch=!0,this.name=i,this.video=document.createElement("video"),this.video.autoplay=!1,this.video.loop=!0,this.video.addEventListener("canplaythrough",function(){e.Tools.IsExponantOfTwo(h.video.videoWidth)&&e.Tools.IsExponantOfTwo(h.video.videoHeight)?(h.wrapU=e.Texture.WRAP_ADDRESSMODE,h.wrapV=e.Texture.WRAP_ADDRESSMODE):(h.wrapU=e.Texture.CLAMP_ADDRESSMODE,h.wrapV=e.Texture.CLAMP_ADDRESSMODE,o=!1),h._texture=n.getEngine().createDynamicTexture(h.video.videoWidth,h.video.videoHeight,o,a,!1),h._texture.isReady=!0}),r.forEach(function(e){var t=document.createElement("source");t.src=e,h.video.appendChild(t)}),this._lastUpdate=e.Tools.Now}return __extends(i,t),i.prototype.update=function(){this._autoLaunch&&(this._autoLaunch=!1,this.video.play());var t=e.Tools.Now;return t-this._lastUpdate<15||this.video.readyState!==this.video.HAVE_ENOUGH_DATA?!1:(this._lastUpdate=t,this.getScene().getEngine().updateVideoTexture(this._texture,this.video,this._invertY),!0)},i}(e.Texture);e.VideoTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r,n,o,s){t.call(this,e,r,null,n,o,s),this._animate=!0,this._time=0,this._texturePath=i,this.loadJson(i),this.refreshRate=1}return __extends(i,t),i.prototype.loadJson=function(t){function i(){e.Tools.Log("No config file found in "+t+" trying to use ShadersStore or DOM element");try{n.setFragment(n._texturePath)}catch(i){e.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}}var r=this,n=this,o=t+"/config.json",s=new XMLHttpRequest;s.open("GET",o,!0),s.addEventListener("load",function(){if(200===s.status||e.Tools.ValidateXHRData(s,1))try{r._config=JSON.parse(s.response),r.updateShaderUniforms(),r.updateTextures(),r.setFragment(r._texturePath+"/custom"),r._animate=r._config.animate,r.refreshRate=r._config.refreshrate}catch(t){i()}else i()},!1),s.addEventListener("error",function(){i()},!1);try{s.send()}catch(a){e.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},i.prototype.isReady=function(){if(!t.prototype.isReady.call(this))return!1;for(var e in this._textures){var i=this._textures[e];if(!i.isReady())return!1}return!0},i.prototype.render=function(e){this._animate&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),t.prototype.render.call(this,e)},i.prototype.updateTextures=function(){for(var t=0;t<this._config.sampler2Ds.length;t++)this.setTexture(this._config.sampler2Ds[t].sample2Dname,new e.Texture(this._texturePath+"/"+this._config.sampler2Ds[t].textureRelativeUrl,this.getScene()))},i.prototype.updateShaderUniforms=function(){if(this._config)for(var t=0;t<this._config.uniforms.length;t++){var i=this._config.uniforms[t];switch(i.type){case"float":this.setFloat(i.name,i.value);break;case"color3":this.setColor3(i.name,new e.Color3(i.r,i.g,i.b));break;case"color4":this.setColor4(i.name,new e.Color4(i.r,i.g,i.b,i.a));break;case"vector2":this.setVector2(i.name,new e.Vector2(i.x,i.y));break;case"vector3":this.setVector3(i.name,new e.Vector3(i.x,i.y,i.z))}}this.setFloat("time",this._time)},Object.defineProperty(i.prototype,"animate",{get:function(){return this._animate},set:function(e){this._animate=e},enumerable:!0,configurable:!0}),i}(e.ProceduralTexture);e.CustomProceduralTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s){t.call(this,i,r,"wood",n,o,s),this._ampScale=100,this._woodColor=new e.Color3(.32,.17,.09),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,t),i.prototype.updateShaderUniforms=function(){this.setFloat("ampScale",this._ampScale),this.setColor3("woodColor",this._woodColor)},Object.defineProperty(i.prototype,"ampScale",{get:function(){return this._ampScale},set:function(e){this._ampScale=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"woodColor",{get:function(){return this._woodColor},set:function(e){this._woodColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(e.ProceduralTexture);e.WoodProceduralTexture=t;var i=function(t){function i(r,n,o,s,a){t.call(this,r,n,"fire",o,s,a),this._time=0,this._speed=new e.Vector2(.5,.3),this._autoGenerateTime=!0,this._alphaThreshold=.5,this._fireColors=i.RedFireColors,this.updateShaderUniforms(),this.refreshRate=1}return __extends(i,t),i.prototype.updateShaderUniforms=function(){this.setFloat("time",this._time),this.setVector2("speed",this._speed),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)},i.prototype.render=function(e){this._autoGenerateTime&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),t.prototype.render.call(this,e)},Object.defineProperty(i,"PurpleFireColors",{get:function(){return[new e.Color3(.5,0,1),new e.Color3(.9,0,1),new e.Color3(.2,0,1),new e.Color3(1,.9,1),new e.Color3(.1,.1,1),new e.Color3(.9,.9,1)]},enumerable:!0,configurable:!0}),Object.defineProperty(i,"GreenFireColors",{get:function(){return[new e.Color3(.5,1,0),new e.Color3(.5,1,0),new e.Color3(.3,.4,0),new e.Color3(.5,1,0),new e.Color3(.2,0,0),new e.Color3(.5,1,0)]},enumerable:!0,configurable:!0}),Object.defineProperty(i,"RedFireColors",{get:function(){return[new e.Color3(.5,0,.1),new e.Color3(.9,0,0),new e.Color3(.2,0,0),new e.Color3(1,.9,0),new e.Color3(.1,.1,.1),new e.Color3(.9,.9,.9)]},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BlueFireColors",{get:function(){return[new e.Color3(.1,0,.5),new e.Color3(0,0,.5),new e.Color3(.1,0,.2),new e.Color3(0,0,1),new e.Color3(.1,.2,.3),new e.Color3(0,.2,.9)]},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"fireColors",{get:function(){return this._fireColors},set:function(e){this._fireColors=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"time",{get:function(){return this._time},set:function(e){this._time=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"speed",{get:function(){return this._speed},set:function(e){this._speed=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"alphaThreshold",{get:function(){return this._alphaThreshold},set:function(e){this._alphaThreshold=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(e.ProceduralTexture);e.FireProceduralTexture=i;var r=function(t){function i(i,r,n,o,s){t.call(this,i,r,"cloud",n,o,s),this._skyColor=new e.Color4(.15,.68,1,1),this._cloudColor=new e.Color4(1,1,1,1),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,t),i.prototype.updateShaderUniforms=function(){this.setColor4("skyColor",this._skyColor),this.setColor4("cloudColor",this._cloudColor)},Object.defineProperty(i.prototype,"skyColor",{get:function(){return this._skyColor},set:function(e){this._skyColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cloudColor",{get:function(){return this._cloudColor},set:function(e){this._cloudColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(e.ProceduralTexture);e.CloudProceduralTexture=r;var n=function(t){function i(i,r,n,o,s){t.call(this,i,r,"grass",n,o,s),this._herb1=new e.Color3(.29,.38,.02),this._herb2=new e.Color3(.36,.49,.09),this._herb3=new e.Color3(.51,.6,.28),this._groundColor=new e.Color3(1,1,1),this._grassColors=[new e.Color3(.29,.38,.02),new e.Color3(.36,.49,.09),new e.Color3(.51,.6,.28)],this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,t),i.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(i.prototype,"grassColors",{get:function(){return this._grassColors},set:function(e){this._grassColors=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"groundColor",{get:function(){return this._groundColor},set:function(e){this.groundColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(e.ProceduralTexture);e.GrassProceduralTexture=n;var o=function(t){function i(i,r,n,o,s){t.call(this,i,r,"road",n,o,s),this._roadColor=new e.Color3(.53,.53,.53),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,t),i.prototype.updateShaderUniforms=function(){this.setColor3("roadColor",this._roadColor)},Object.defineProperty(i.prototype,"roadColor",{get:function(){return this._roadColor},set:function(e){this._roadColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(e.ProceduralTexture);e.RoadProceduralTexture=o;var s=function(t){function i(i,r,n,o,s){t.call(this,i,r,"brick",n,o,s),this._numberOfBricksHeight=15,this._numberOfBricksWidth=5,this._jointColor=new e.Color3(.72,.72,.72),this._brickColor=new e.Color3(.77,.47,.4),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,t),i.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(i.prototype,"numberOfBricksHeight",{get:function(){return this._numberOfBricksHeight},set:function(e){this._numberOfBricksHeight=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"numberOfBricksWidth",{get:function(){return this._numberOfBricksWidth},set:function(e){this._numberOfBricksWidth=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"jointColor",{get:function(){return this._jointColor},set:function(e){this._jointColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"brickColor",{get:function(){return this._brickColor},set:function(e){this._brickColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(e.ProceduralTexture);e.BrickProceduralTexture=s;var a=function(t){function i(i,r,n,o,s){t.call(this,i,r,"marble",n,o,s),this._numberOfTilesHeight=3,this._numberOfTilesWidth=3,this._amplitude=9,this._marbleColor=new e.Color3(.77,.47,.4),this._jointColor=new e.Color3(.72,.72,.72),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,t),i.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(i.prototype,"numberOfTilesHeight",{get:function(){return this._numberOfTilesHeight},set:function(e){this._numberOfTilesHeight=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"numberOfTilesWidth",{get:function(){return this._numberOfTilesWidth},set:function(e){this._numberOfTilesWidth=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"jointColor",{get:function(){return this._jointColor},set:function(e){this._jointColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"marbleColor",{get:function(){return this._marbleColor},set:function(e){this._marbleColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(e.ProceduralTexture);e.MarbleProceduralTexture=a}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._defines={},this._currentRank=32,this._maxRank=-1}return e.prototype.addFallback=function(e,t){this._defines[e]||(e<this._currentRank&&(this._currentRank=e),e>this._maxRank&&(this._maxRank=e),this._defines[e]=new Array),this._defines[e].push(t)},Object.defineProperty(e.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),e.prototype.reduce=function(e){for(var t=this._defines[this._currentRank],i=0;i<t.length;i++)e=e.replace("#define "+t[i],"");return this._currentRank++,e},e}();e.EffectFallbacks=t;var i=function(){function t(e,t,i,r,n,o,s,a,h){var l=this;this._isReady=!1,this._compilationError="",this._valueCache=[],this._engine=n,this.name=e,this.defines=o,this._uniformsNames=i.concat(r),this._samplers=r,this._attributesNames=t,this.onError=h,this.onCompiled=a;var c,u;e.vertexElement?(c=document.getElementById(e.vertexElement),c||(c=e.vertexElement)):c=e.vertex||e,e.fragmentElement?(u=document.getElementById(e.fragmentElement),u||(u=e.fragmentElement)):u=e.fragment||e,this._loadVertexShader(c,function(e){l._loadFragmentShader(u,function(i){l._prepareEffect(e,i,t,o,s)})})}return t.prototype.isReady=function(){return this._isReady},t.prototype.getProgram=function(){return this._program},t.prototype.getAttributesNames=function(){return this._attributesNames},t.prototype.getAttributeLocation=function(e){return this._attributes[e]},t.prototype.getAttributeLocationByName=function(e){var t=this._attributesNames.indexOf(e);return this._attributes[t]},t.prototype.getAttributesCount=function(){return this._attributes.length},t.prototype.getUniformIndex=function(e){return this._uniformsNames.indexOf(e)},t.prototype.getUniform=function(e){return this._uniforms[this._uniformsNames.indexOf(e)]},t.prototype.getSamplers=function(){return this._samplers},t.prototype.getCompilationError=function(){return this._compilationError},t.prototype._loadVertexShader=function(i,r){if(i instanceof HTMLElement){var n=e.Tools.GetDOMTextContent(i);return void r(n)}if(t.ShadersStore[i+"VertexShader"])return void r(t.ShadersStore[i+"VertexShader"]);var o;o="."===i[0]||"/"===i[0]?i:e.Engine.ShadersRepository+i,e.Tools.LoadFile(o+".vertex.fx",r)},t.prototype._loadFragmentShader=function(i,r){if(i instanceof HTMLElement){var n=e.Tools.GetDOMTextContent(i);return void r(n)}if(t.ShadersStore[i+"PixelShader"])return void r(t.ShadersStore[i+"PixelShader"]);if(t.ShadersStore[i+"FragmentShader"])return void r(t.ShadersStore[i+"FragmentShader"]);var o;o="."===i[0]||"/"===i[0]?i:e.Engine.ShadersRepository+i,e.Tools.LoadFile(o+".fragment.fx",r)},t.prototype._prepareEffect=function(t,i,r,n,o){try{var s=this._engine;s.getCaps().highPrecisionShaderSupported||(t=t.replace("precision highp float","precision mediump float"),i=i.replace("precision highp float","precision mediump float")),this._program=s.createShaderProgram(t,i,n),this._uniforms=s.getUniforms(this._program,this._uniformsNames),this._attributes=s.getAttributes(this._program,r);for(var a=0;a<this._samplers.length;a++){var h=this.getUniform(this._samplers[a]);null==h&&(this._samplers.splice(a,1),a--)}s.bindSamplers(this),this._isReady=!0,this.onCompiled&&this.onCompiled(this)}catch(l){if(-1!==l.message.indexOf("highp"))return t=t.replace("precision highp float","precision mediump float"),i=i.replace("precision highp float","precision mediump float"),void this._prepareEffect(t,i,r,n,o);o&&o.isMoreFallbacks?(n=o.reduce(n),this._prepareEffect(t,i,r,n,o)):(e.Tools.Error("Unable to compile effect: "),this.name.vertexElement?(e.Tools.Error("Vertex shader:"+this.name.vertexElement),e.Tools.Error("Fragment shader:"+this.name.fragmentElement)):this.name.vertex?(e.Tools.Error("Vertex shader:"+this.name.vertex),e.Tools.Error("Fragment shader:"+this.name.fragment)):(e.Tools.Error("Vertex shader:"+this.name),e.Tools.Error("Fragment shader:"+this.name)),e.Tools.Error("Defines: "+n),e.Tools.Error("Error: "+l.message),this._compilationError=l.message,this.onError&&this.onError(this,this._compilationError))}},t.prototype._bindTexture=function(e,t){this._engine._bindTexture(this._samplers.indexOf(e),t)},t.prototype.setTexture=function(e,t){this._engine.setTexture(this._samplers.indexOf(e),t)},t.prototype.setTextureFromPostProcess=function(e,t){this._engine.setTextureFromPostProcess(this._samplers.indexOf(e),t)},t.prototype._cacheFloat2=function(e,t,i){return this._valueCache[e]?(this._valueCache[e][0]=t,void(this._valueCache[e][1]=i)):void(this._valueCache[e]=[t,i])},t.prototype._cacheFloat3=function(e,t,i,r){return this._valueCache[e]?(this._valueCache[e][0]=t,this._valueCache[e][1]=i,void(this._valueCache[e][2]=r)):void(this._valueCache[e]=[t,i,r])},t.prototype._cacheFloat4=function(e,t,i,r,n){return this._valueCache[e]?(this._valueCache[e][0]=t,this._valueCache[e][1]=i,this._valueCache[e][2]=r,void(this._valueCache[e][3]=n)):void(this._valueCache[e]=[t,i,r,n]);
  
  },t.prototype.setArray=function(e,t){return this._engine.setArray(this.getUniform(e),t),this},t.prototype.setArray2=function(e,t){return this._engine.setArray2(this.getUniform(e),t),this},t.prototype.setArray3=function(e,t){return this._engine.setArray3(this.getUniform(e),t),this},t.prototype.setArray4=function(e,t){return this._engine.setArray4(this.getUniform(e),t),this},t.prototype.setMatrices=function(e,t){return this._engine.setMatrices(this.getUniform(e),t),this},t.prototype.setMatrix=function(e,t){return this._engine.setMatrix(this.getUniform(e),t),this},t.prototype.setMatrix3x3=function(e,t){return this._engine.setMatrix3x3(this.getUniform(e),t),this},t.prototype.setMatrix2x2=function(e,t){return this._engine.setMatrix2x2(this.getUniform(e),t),this},t.prototype.setFloat=function(e,t){return this._valueCache[e]&&this._valueCache[e]===t?this:(this._valueCache[e]=t,this._engine.setFloat(this.getUniform(e),t),this)},t.prototype.setBool=function(e,t){return this._valueCache[e]&&this._valueCache[e]===t?this:(this._valueCache[e]=t,this._engine.setBool(this.getUniform(e),t?1:0),this)},t.prototype.setVector2=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y?this:(this._cacheFloat2(e,t.x,t.y),this._engine.setFloat2(this.getUniform(e),t.x,t.y),this)},t.prototype.setFloat2=function(e,t,i){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i?this:(this._cacheFloat2(e,t,i),this._engine.setFloat2(this.getUniform(e),t,i),this)},t.prototype.setVector3=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y&&this._valueCache[e][2]===t.z?this:(this._cacheFloat3(e,t.x,t.y,t.z),this._engine.setFloat3(this.getUniform(e),t.x,t.y,t.z),this)},t.prototype.setFloat3=function(e,t,i,r){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i&&this._valueCache[e][2]===r?this:(this._cacheFloat3(e,t,i,r),this._engine.setFloat3(this.getUniform(e),t,i,r),this)},t.prototype.setVector4=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y&&this._valueCache[e][2]===t.z&&this._valueCache[e][3]===t.w?this:(this._cacheFloat4(e,t.x,t.y,t.z,t.w),this._engine.setFloat4(this.getUniform(e),t.x,t.y,t.z,t.w),this)},t.prototype.setFloat4=function(e,t,i,r,n){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i&&this._valueCache[e][2]===r&&this._valueCache[e][3]===n?this:(this._cacheFloat4(e,t,i,r,n),this._engine.setFloat4(this.getUniform(e),t,i,r,n),this)},t.prototype.setColor3=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.r&&this._valueCache[e][1]===t.g&&this._valueCache[e][2]===t.b?this:(this._cacheFloat3(e,t.r,t.g,t.b),this._engine.setColor3(this.getUniform(e),t),this)},t.prototype.setColor4=function(e,t,i){return this._valueCache[e]&&this._valueCache[e][0]===t.r&&this._valueCache[e][1]===t.g&&this._valueCache[e][2]===t.b&&this._valueCache[e][3]===i?this:(this._cacheFloat4(e,t.r,t.g,t.b,i),this._engine.setColor4(this.getUniform(e),t,i),this)},t.ShadersStore={},t}();e.Effect=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(i,r,n){this.name=i,this.checkReadyOnEveryCall=!0,this.checkReadyOnlyOnce=!1,this.state="",this.alpha=1,this.backFaceCulling=!0,this.alphaMode=e.Engine.ALPHA_COMBINE,this.disableDepthWrite=!1,this._wasPreviouslyReady=!1,this._fillMode=t.TriangleFillMode,this.pointSize=1,this.zOffset=0,this.id=i,this._scene=r,n||r.materials.push(this)}return Object.defineProperty(t,"TriangleFillMode",{get:function(){return t._TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"WireFrameFillMode",{get:function(){return t._WireFrameFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PointFillMode",{get:function(){return t._PointFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"wireframe",{get:function(){return this._fillMode===t.WireFrameFillMode},set:function(e){this._fillMode=e?t.WireFrameFillMode:t.TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pointsCloud",{get:function(){return this._fillMode===t.PointFillMode},set:function(e){this._fillMode=e?t.PointFillMode:t.TriangleFillMode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fillMode",{get:function(){return this._fillMode},set:function(e){this._fillMode=e},enumerable:!0,configurable:!0}),t.prototype.isReady=function(e,t){return!0},t.prototype.getEffect=function(){return this._effect},t.prototype.getScene=function(){return this._scene},t.prototype.needAlphaBlending=function(){return this.alpha<1},t.prototype.needAlphaTesting=function(){return!1},t.prototype.getAlphaTestTexture=function(){return null},t.prototype.trackCreation=function(e,t){},t.prototype._preBind=function(){var e=this._scene.getEngine();e.enableEffect(this._effect),e.setState(this.backFaceCulling,this.zOffset)},t.prototype.bind=function(e,t){if(this._scene._cachedMaterial=this,this.onBind&&this.onBind(this,t),this.disableDepthWrite){var i=this._scene.getEngine();this._cachedDepthWriteState=i.getDepthWrite(),i.setDepthWrite(!1)}},t.prototype.bindOnlyWorldMatrix=function(e){},t.prototype.unbind=function(){if(this.disableDepthWrite){var e=this._scene.getEngine();e.setDepthWrite(this._cachedDepthWriteState)}},t.prototype.clone=function(e){return null},t.prototype.dispose=function(e){var t=this._scene.materials.indexOf(this);this._scene.materials.splice(t,1),e&&this._effect&&(this._scene.getEngine()._releaseEffect(this._effect),this._effect=null),this.onDispose&&this.onDispose()},t._TriangleFillMode=0,t._WireFrameFillMode=1,t._PointFillMode=2,t}();e.Material=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=4,i=function(){function t(){this.isEnabled=!0,this.leftColor=e.Color3.White(),this.rightColor=e.Color3.Black(),this.bias=0,this.power=1}return t}();e.FresnelParameters=i;var r=function(){function e(){this.DIFFUSE=!1,this.AMBIENT=!1,this.OPACITY=!1,this.OPACITYRGB=!1,this.REFLECTION=!1,this.EMISSIVE=!1,this.SPECULAR=!1,this.BUMP=!1,this.SPECULAROVERALPHA=!1,this.CLIPPLANE=!1,this.ALPHATEST=!1,this.ALPHAFROMDIFFUSE=!1,this.POINTSIZE=!1,this.FOG=!1,this.LIGHT0=!1,this.LIGHT1=!1,this.LIGHT2=!1,this.LIGHT3=!1,this.SPOTLIGHT0=!1,this.SPOTLIGHT1=!1,this.SPOTLIGHT2=!1,this.SPOTLIGHT3=!1,this.HEMILIGHT0=!1,this.HEMILIGHT1=!1,this.HEMILIGHT2=!1,this.HEMILIGHT3=!1,this.POINTDIRLIGHT0=!1,this.POINTDIRLIGHT1=!1,this.POINTDIRLIGHT2=!1,this.POINTDIRLIGHT3=!1,this.SPECULARTERM=!1,this.SHADOW0=!1,this.SHADOW1=!1,this.SHADOW2=!1,this.SHADOW3=!1,this.SHADOWS=!1,this.SHADOWVSM0=!1,this.SHADOWVSM1=!1,this.SHADOWVSM2=!1,this.SHADOWVSM3=!1,this.SHADOWPCF0=!1,this.SHADOWPCF1=!1,this.SHADOWPCF2=!1,this.SHADOWPCF3=!1,this.DIFFUSEFRESNEL=!1,this.OPACITYFRESNEL=!1,this.REFLECTIONFRESNEL=!1,this.EMISSIVEFRESNEL=!1,this.FRESNEL=!1,this.NORMAL=!1,this.UV1=!1,this.UV2=!1,this.VERTEXCOLOR=!1,this.VERTEXALPHA=!1,this.BONES=!1,this.BONES4=!1,this.BonesPerMesh=0,this.INSTANCES=!1,this.GLOSSINESS=!1,this.ROUGHNESS=!1,this.EMISSIVEASILLUMINATION=!1,this.REFLECTIONFRESNELFROMSPECULAR=!1,this._keys=Object.keys(this)}return e.prototype.isEqual=function(e){for(var t=0;t<this._keys.length;t++){var i=this._keys[t];if(this[i]!==e[i])return!1}return!0},e.prototype.cloneTo=function(e){for(var t=0;t<this._keys.length;t++){var i=this._keys[t];e[i]=this[i]}},e.prototype.reset=function(){for(var e=0;e<this._keys.length;e++){var t=this._keys[e];this[t]="BonesPerMesh"!==t?!1:0}},e.prototype.toString=function(){for(var e="",t=0;t<this._keys.length;t++){var i=this._keys[t];"BonesPerMesh"===i&&this[i]>0?e+="#define BonesPerMesh "+this[i]+"\n":this[i]&&(e+="#define "+i+"\n")}return e},e}(),n=function(i){function n(t,n){var o=this;i.call(this,t,n),this.ambientColor=new e.Color3(0,0,0),this.diffuseColor=new e.Color3(1,1,1),this.specularColor=new e.Color3(1,1,1),this.specularPower=64,this.emissiveColor=new e.Color3(0,0,0),this.useAlphaFromDiffuseTexture=!1,this.useEmissiveAsIllumination=!1,this.useReflectionFresnelFromSpecular=!1,this.useSpecularOverAlpha=!0,this.fogEnabled=!0,this.roughness=0,this.useGlossinessFromSpecularMapAlpha=!1,this._renderTargets=new e.SmartArray(16),this._worldViewProjectionMatrix=e.Matrix.Zero(),this._globalAmbientColor=new e.Color3(0,0,0),this._scaledDiffuse=new e.Color3,this._scaledSpecular=new e.Color3,this._defines=new r,this._cachedDefines=new r,this._cachedDefines.BonesPerMesh=-1,this.getRenderTargetTextures=function(){return o._renderTargets.reset(),o.reflectionTexture&&o.reflectionTexture.isRenderTarget&&o._renderTargets.push(o.reflectionTexture),o._renderTargets}}return __extends(n,i),n.prototype.needAlphaBlending=function(){return this.alpha<1||null!=this.opacityTexture||this._shouldUseAlphaFromDiffuseTexture()||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled},n.prototype.needAlphaTesting=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha},n.prototype._shouldUseAlphaFromDiffuseTexture=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha&&this.useAlphaFromDiffuseTexture},n.prototype.getAlphaTestTexture=function(){return this.diffuseTexture},n.prototype.isReady=function(i,r){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var o=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===o.getRenderId())return!0;var s=o.getEngine(),a=!1,h=!1;if(this._defines.reset(),o.texturesEnabled){if(this.diffuseTexture&&n.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;h=!0,this._defines.DIFFUSE=!0}if(this.ambientTexture&&n.AmbientTextureEnabled){if(!this.ambientTexture.isReady())return!1;h=!0,this._defines.AMBIENT=!0}if(this.opacityTexture&&n.OpacityTextureEnabled){if(!this.opacityTexture.isReady())return!1;h=!0,this._defines.OPACITY=!0,this.opacityTexture.getAlphaFromRGB&&(this._defines.OPACITYRGB=!0)}if(this.reflectionTexture&&n.ReflectionTextureEnabled){if(!this.reflectionTexture.isReady())return!1;a=!0,h=!0,this._defines.REFLECTION=!0,this.roughness>0&&(this._defines.ROUGHNESS=!0)}if(this.emissiveTexture&&n.EmissiveTextureEnabled){if(!this.emissiveTexture.isReady())return!1;h=!0,this._defines.EMISSIVE=!0}if(this.specularTexture&&n.SpecularTextureEnabled){if(!this.specularTexture.isReady())return!1;h=!0,this._defines.SPECULAR=!0,this._defines.GLOSSINESS=this.useGlossinessFromSpecularMapAlpha}}if(o.getEngine().getCaps().standardDerivatives&&this.bumpTexture&&n.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;h=!0,this._defines.BUMP=!0}o.clipPlane&&(this._defines.CLIPPLANE=!0),s.getAlphaTesting()&&(this._defines.ALPHATEST=!0),this._shouldUseAlphaFromDiffuseTexture()&&(this._defines.ALPHAFROMDIFFUSE=!0),this.useEmissiveAsIllumination&&(this._defines.EMISSIVEASILLUMINATION=!0),this.useReflectionFresnelFromSpecular&&(this._defines.REFLECTIONFRESNELFROMSPECULAR=!0),(this.pointsCloud||o.forcePointsCloud)&&(this._defines.POINTSIZE=!0),o.fogEnabled&&i&&i.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0);var l=0;if(o.lightsEnabled)for(var c=0;c<o.lights.length;c++){var u=o.lights[c];if(u.isEnabled()){if(u._excludedMeshesIds.length>0){for(var f=0;f<u._excludedMeshesIds.length;f++){var d=o.getMeshByID(u._excludedMeshesIds[f]);d&&u.excludedMeshes.push(d)}u._excludedMeshesIds=[]}if(u._includedOnlyMeshesIds.length>0){for(var p=0;p<u._includedOnlyMeshesIds.length;p++){var m=o.getMeshByID(u._includedOnlyMeshesIds[p]);m&&u.includedOnlyMeshes.push(m)}u._includedOnlyMeshesIds=[]}if(u.canAffectMesh(i)){a=!0,this._defines["LIGHT"+l]=!0;var g;if(g=u instanceof e.SpotLight?"SPOTLIGHT"+l:u instanceof e.HemisphericLight?"HEMILIGHT"+l:"POINTDIRLIGHT"+l,this._defines[g]=!0,u.specular.equalsFloats(0,0,0)||(this._defines.SPECULARTERM=!0),o.shadowsEnabled){var _=u.getShadowGenerator();i&&i.receiveShadows&&_&&(this._defines["SHADOW"+l]=!0,this._defines.SHADOWS=!0,(_.useVarianceShadowMap||_.useBlurVarianceShadowMap)&&(this._defines["SHADOWVSM"+l]=!0),_.usePoissonSampling&&(this._defines["SHADOWPCF"+l]=!0))}if(l++,l===t)break}}}if(n.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled||this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled||this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled)&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._defines.DIFFUSEFRESNEL=!0),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&(this._defines.OPACITYFRESNEL=!0),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._defines.REFLECTIONFRESNEL=!0),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._defines.EMISSIVEFRESNEL=!0),a=!0,this._defines.FRESNEL=!0),this._defines.SPECULARTERM&&this.useSpecularOverAlpha&&(this._defines.SPECULAROVERALPHA=!0),i&&(a&&i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),h&&(i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(this._defines.UV2=!0)),i.useVertexColors&&i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,i.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),i.useBones&&i.computeBonesUsingShaders&&(this._defines.BONES=!0,this._defines.BonesPerMesh=i.skeleton.bones.length+1,this._defines.BONES4=!0),r&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),o.resetCachedMaterial();var v=new e.EffectFallbacks;this._defines.REFLECTION&&v.addFallback(0,"REFLECTION"),this._defines.SPECULAR&&v.addFallback(0,"SPECULAR"),this._defines.BUMP&&v.addFallback(0,"BUMP"),this._defines.SPECULAROVERALPHA&&v.addFallback(0,"SPECULAROVERALPHA"),this._defines.FOG&&v.addFallback(1,"FOG");for(var l=0;t>l;l++)this._defines["LIGHT"+l]&&(l>0&&v.addFallback(l,"LIGHT"+l),this._defines["SHADOW"+l]&&v.addFallback(0,"SHADOW"+l),this._defines["SHADOWPCF"+l]&&v.addFallback(0,"SHADOWPCF"+l),this._defines["SHADOWVSM"+l]&&v.addFallback(0,"SHADOWVSM"+l));this._defines.SPECULARTERM&&v.addFallback(0,"SPECULARTERM"),this._defines.DIFFUSEFRESNEL&&v.addFallback(1,"DIFFUSEFRESNEL"),this._defines.OPACITYFRESNEL&&v.addFallback(2,"OPACITYFRESNEL"),this._defines.REFLECTIONFRESNEL&&v.addFallback(3,"REFLECTIONFRESNEL"),this._defines.EMISSIVEFRESNEL&&v.addFallback(4,"EMISSIVEFRESNEL"),this._defines.FRESNEL&&v.addFallback(4,"FRESNEL"),this._defines.BONES4&&v.addFallback(0,"BONES4");var y=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&y.push(e.VertexBuffer.NormalKind),this._defines.UV1&&y.push(e.VertexBuffer.UVKind),this._defines.UV2&&y.push(e.VertexBuffer.UV2Kind),this._defines.VERTEXCOLOR&&y.push(e.VertexBuffer.ColorKind),this._defines.BONES&&(y.push(e.VertexBuffer.MatricesIndicesKind),y.push(e.VertexBuffer.MatricesWeightsKind)),this._defines.INSTANCES&&(y.push("world0"),y.push("world1"),y.push("world2"),y.push("world3"));var x="default";o.getEngine().getCaps().standardDerivatives||(x="legacydefault");var M=this._defines.toString();this._effect=o.getEngine().createEffect(x,y,["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","shadowsInfo0","shadowsInfo1","shadowsInfo2","shadowsInfo3","diffuseLeftColor","diffuseRightColor","opacityParts","reflectionLeftColor","reflectionRightColor","emissiveLeftColor","emissiveRightColor","roughness"],["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],M,v,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0,!0):!1},n.prototype.unbind=function(){this.reflectionTexture&&this.reflectionTexture.isRenderTarget&&this._effect.setTexture("reflection2DSampler",null),i.prototype.unbind.call(this)},n.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},n.prototype.bind=function(r,o){var s=this.getScene();if(this.bindOnlyWorldMatrix(r),this._effect.setMatrix("viewProjection",s.getTransformMatrix()),o&&o.useBones&&o.computeBonesUsingShaders&&this._effect.setMatrices("mBones",o.skeleton.getTransformMatrices()),s.getCachedMaterial()!==this){if(n.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 e.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&&n.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&&n.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&&n.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&&n.ReflectionTextureEnabled&&(this.reflectionTexture.isCube?(this._effect.setTexture("reflectionCubeSampler",this.reflectionTexture),this._defines.ROUGHNESS&&this._effect.setFloat("roughness",this.roughness)):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&&n.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&&n.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&&s.getEngine().getCaps().standardDerivatives&&n.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())),s.clipPlane){var a=s.clipPlane;this._effect.setFloat4("vClipPlane",a.normal.x,a.normal.y,a.normal.z,a.d)}this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),s.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),this._scaledSpecular.r=this.specularColor.r*e.Tools.Clamp(1-this.emissiveColor.r),this._scaledSpecular.g=this.specularColor.g*e.Tools.Clamp(1-this.emissiveColor.g),this._scaledSpecular.b=this.specularColor.b*e.Tools.Clamp(1-this.emissiveColor.b),this._effect.setVector3("vEyePosition",s.activeCamera.position),this._effect.setColor3("vAmbientColor",this._globalAmbientColor),this._defines.SPECULARTERM&&this._effect.setColor4("vSpecularColor",this._scaledSpecular,this.specularPower),this._effect.setColor3("vEmissiveColor",this.emissiveColor)}if(this._scaledDiffuse.r=this.diffuseColor.r*e.Tools.Clamp(1-this.emissiveColor.r),this._scaledDiffuse.g=this.diffuseColor.g*e.Tools.Clamp(1-this.emissiveColor.g),this._scaledDiffuse.b=this.diffuseColor.b*e.Tools.Clamp(1-this.emissiveColor.b),this._effect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*o.visibility),s.lightsEnabled)for(var h=0,l=0;l<s.lights.length;l++){var c=s.lights[l];if(c.isEnabled()&&c.canAffectMesh(o)){if(c instanceof e.PointLight?c.transferToEffect(this._effect,"vLightData"+h):c instanceof e.DirectionalLight?c.transferToEffect(this._effect,"vLightData"+h):c instanceof e.SpotLight?c.transferToEffect(this._effect,"vLightData"+h,"vLightDirection"+h):c instanceof e.HemisphericLight&&c.transferToEffect(this._effect,"vLightData"+h,"vLightGround"+h),c.diffuse.scaleToRef(c.intensity,this._scaledDiffuse),this._effect.setColor4("vLightDiffuse"+h,this._scaledDiffuse,c.range),this._defines.SPECULARTERM&&(c.specular.scaleToRef(c.intensity,this._scaledSpecular),this._effect.setColor3("vLightSpecular"+h,this._scaledSpecular)),s.shadowsEnabled){var u=c.getShadowGenerator();o.receiveShadows&&u&&(this._effect.setMatrix("lightMatrix"+h,u.getTransformMatrix()),this._effect.setTexture("shadowSampler"+h,u.getShadowMapForRendering()),this._effect.setFloat3("shadowsInfo"+h,u.getDarkness(),u.getShadowMap().getSize().width,u.bias))}if(h++,h===t)break}}(s.fogEnabled&&o.applyFog&&s.fogMode!==e.Scene.FOGMODE_NONE||this.reflectionTexture)&&this._effect.setMatrix("view",s.getViewMatrix()),s.fogEnabled&&o.applyFog&&s.fogMode!==e.Scene.FOGMODE_NONE&&(this._effect.setFloat4("vFogInfos",s.fogMode,s.fogStart,s.fogEnd,s.fogDensity),this._effect.setColor3("vFogColor",s.fogColor)),i.prototype.bind.call(this,r,o)},n.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),this.ambientTexture&&this.ambientTexture.animations&&this.ambientTexture.animations.length>0&&e.push(this.ambientTexture),this.opacityTexture&&this.opacityTexture.animations&&this.opacityTexture.animations.length>0&&e.push(this.opacityTexture),this.reflectionTexture&&this.reflectionTexture.animations&&this.reflectionTexture.animations.length>0&&e.push(this.reflectionTexture),this.emissiveTexture&&this.emissiveTexture.animations&&this.emissiveTexture.animations.length>0&&e.push(this.emissiveTexture),this.specularTexture&&this.specularTexture.animations&&this.specularTexture.animations.length>0&&e.push(this.specularTexture),this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&e.push(this.bumpTexture),e},n.prototype.dispose=function(e){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(),i.prototype.dispose.call(this,e)},n.prototype.clone=function(e){var t=new n(e,this.getScene());return t.checkReadyOnEveryCall=this.checkReadyOnEveryCall,t.alpha=this.alpha,t.fillMode=this.fillMode,t.backFaceCulling=this.backFaceCulling,this.diffuseTexture&&this.diffuseTexture.clone&&(t.diffuseTexture=this.diffuseTexture.clone()),this.ambientTexture&&this.ambientTexture.clone&&(t.ambientTexture=this.ambientTexture.clone()),this.opacityTexture&&this.opacityTexture.clone&&(t.opacityTexture=this.opacityTexture.clone()),this.reflectionTexture&&this.reflectionTexture.clone&&(t.reflectionTexture=this.reflectionTexture.clone()),this.emissiveTexture&&this.emissiveTexture.clone&&(t.emissiveTexture=this.emissiveTexture.clone()),this.specularTexture&&this.specularTexture.clone&&(t.specularTexture=this.specularTexture.clone()),this.bumpTexture&&this.bumpTexture.clone&&(t.bumpTexture=this.bumpTexture.clone()),t.ambientColor=this.ambientColor.clone(),t.diffuseColor=this.diffuseColor.clone(),t.specularColor=this.specularColor.clone(),t.specularPower=this.specularPower,t.emissiveColor=this.emissiveColor.clone(),t},n.DiffuseTextureEnabled=!0,n.AmbientTextureEnabled=!0,n.OpacityTextureEnabled=!0,n.ReflectionTextureEnabled=!0,n.EmissiveTextureEnabled=!0,n.SpecularTextureEnabled=!0,n.BumpTextureEnabled=!0,n.FresnelEnabled=!0,n}(e.Material);e.StandardMaterial=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i){e.call(this,t,i,!0),this.subMaterials=new Array,i.multiMaterials.push(this)}return __extends(t,e),t.prototype.getSubMaterial=function(e){return 0>e||e>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},t.prototype.isReady=function(e){for(var t=0;t<this.subMaterials.length;t++){var i=this.subMaterials[t];if(i&&!this.subMaterials[t].isReady(e))return!1}return!0},t.prototype.clone=function(e){for(var i=new t(e,this.getScene()),r=0;r<this.subMaterials.length;r++){var n=this.subMaterials[r];i.subMaterials.push(n)}return i},t}(e.Material);e.MultiMaterial=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return Object.defineProperty(t,"ForceFullSceneLoadingForIncremental",{get:function(){return t._ForceFullSceneLoadingForIncremental},set:function(e){t._ForceFullSceneLoadingForIncremental=e},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ShowLoadingScreen",{get:function(){return t._ShowLoadingScreen},set:function(e){t._ShowLoadingScreen=e},enumerable:!0,configurable:!0}),t._getPluginForFilename=function(e){var t=e.lastIndexOf("."),i=e.indexOf("?");-1===i&&(i=e.length);for(var r=e.substring(t,i).toLowerCase(),n=0;n<this._registeredPlugins.length;n++){var o=this._registeredPlugins[n];if(-1!==o.extensions.indexOf(r))return o}return this._registeredPlugins[this._registeredPlugins.length-1]},t.RegisterPlugin=function(e){e.extensions=e.extensions.toLowerCase(),t._registeredPlugins.push(e)},t.ImportMesh=function(i,r,n,o,s,a,h){if(n.substr&&"/"===n.substr(0,1))return void e.Tools.Error("Wrong sceneFilename parameter");var l={};o._addPendingData(l);var c=function(c){o.database=u;var f=t._getPluginForFilename(n),d=function(e){var t=[],a=[],c=[];try{if(!f.importMesh(i,o,e,r,t,a,c))return h&&h(o,"Unable to import meshes from "+r+n),void o._removePendingData(l)}catch(u){return h&&h(o,"Unable to import meshes from "+r+n+" (Exception: "+u+")"),void o._removePendingData(l)}s&&(o.importedMeshesFiles.push(r+n),s(t,a,c),o._removePendingData(l))};return n.substr&&"data:"===n.substr(0,5)?void d(n.substr(5)):void e.Tools.LoadFile(r+n,function(e){d(e)},a,u)};if(o.getEngine().enableOfflineSupport)var u=new e.Database(r+n,c);else c(!0)},t.Load=function(i,r,n,o,s,a){t.Append(i,r,new e.Scene(n),o,s,a)},t.Append=function(i,r,n,o,s,a){if(r.substr&&"/"===r.substr(0,1))return void e.Tools.Error("Wrong sceneFilename parameter");var h,l=this._getPluginForFilename(r.name||r),c={};n._addPendingData(c),t.ShowLoadingScreen&&n.getEngine().displayLoadingUI();var u=function(e){return n.database=h,l.load(n,e,i)?(o&&o(n),n._removePendingData(c),void(t.ShowLoadingScreen&&n.executeWhenReady(function(){n.getEngine().hideLoadingUI()}))):(a&&a(n),n._removePendingData(c),void n.getEngine().hideLoadingUI())},f=function(t){e.Tools.LoadFile(i+r,u,s,h)};return r.substr&&"data:"===r.substr(0,5)?void u(r.substr(5)):void(-1===i.indexOf("file:")?n.getEngine().enableOfflineSupport?h=new e.Database(i+r,f):f(!0):e.Tools.ReadFile(r,u,s))},t._ForceFullSceneLoadingForIncremental=!1,t._ShowLoadingScreen=!0,t._registeredPlugins=new Array,t}();e.SceneLoader=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var i=function(e,t){if(e.length===3*t){for(var i=[],r=0;r<e.length;r+=3){var n=r/3*4;i[n]=e[r],i[n+1]=e[r+1],i[n+2]=e[r+2],i[n+3]=1}return i}return e},r=function(t,i,r){var n=null;return!i.name&&!i.extensions||i.isRenderTarget||(n=new e.CubeTexture(t+i.name,r,i.extensions),n.name=i.name,n.hasAlpha=i.hasAlpha,n.level=i.level,n.coordinatesMode=i.coordinatesMode),n},n=function(t,i,n){if(i.isCube)return r(t,i,n);if(!i.name&&!i.isRenderTarget)return null;var o;if(i.mirrorPlane?(o=new e.MirrorTexture(i.name,i.renderTargetSize,n),o._waitingRenderList=i.renderList,o.mirrorPlane=e.Plane.FromArray(i.mirrorPlane)):i.isRenderTarget?(o=new e.RenderTargetTexture(i.name,i.renderTargetSize,n),o._waitingRenderList=i.renderList):o=i.base64String?e.Texture.CreateFromBase64String(i.base64String,i.name,n):new e.Texture(t+i.name,n),o.name=i.name,o.hasAlpha=i.hasAlpha,o.getAlphaFromRGB=i.getAlphaFromRGB,o.level=i.level,o.coordinatesIndex=i.coordinatesIndex,o.coordinatesMode=i.coordinatesMode,o.uOffset=i.uOffset,o.vOffset=i.vOffset,o.uScale=i.uScale,o.vScale=i.vScale,o.uAng=i.uAng,o.vAng=i.vAng,o.wAng=i.wAng,o.wrapU=i.wrapU,o.wrapV=i.wrapV,i.animations)for(var s=0;s<i.animations.length;s++){var a=i.animations[s];o.animations.push(d(a))}return o},o=function(t,i){for(var r=new e.Skeleton(t.name,t.id,i),n=0;n<t.bones.length;n++){var o=t.bones[n],s=null;o.parentBoneIndex>-1&&(s=r.bones[o.parentBoneIndex]);var a=new e.Bone(o.name,r,s,e.Matrix.FromArray(o.matrix));o.animation&&a.animations.push(d(o.animation))}return r},s=function(t){var i=new e.FresnelParameters;return i.isEnabled=t.isEnabled,i.leftColor=e.Color3.FromArray(t.leftColor),i.rightColor=e.Color3.FromArray(t.rightColor),i.bias=t.bias,i.power=t.power||1,i},a=function(t,i,r){var o;return o=new e.StandardMaterial(t.name,i),o.ambientColor=e.Color3.FromArray(t.ambient),o.diffuseColor=e.Color3.FromArray(t.diffuse),o.specularColor=e.Color3.FromArray(t.specular),o.specularPower=t.specularPower,o.emissiveColor=e.Color3.FromArray(t.emissive),o.useReflectionFresnelFromSpecular=t.useReflectionFresnelFromSpecular,o.useEmissiveAsIllumination=t.useEmissiveAsIllumination,o.alpha=t.alpha,o.id=t.id,t.disableDepthWrite&&(o.disableDepthWrite=t.disableDepthWrite),e.Tags.AddTagsTo(o,t.tags),o.backFaceCulling=t.backFaceCulling,o.wireframe=t.wireframe,t.diffuseTexture&&(o.diffuseTexture=n(r,t.diffuseTexture,i)),t.diffuseFresnelParameters&&(o.diffuseFresnelParameters=s(t.diffuseFresnelParameters)),t.ambientTexture&&(o.ambientTexture=n(r,t.ambientTexture,i)),t.opacityTexture&&(o.opacityTexture=n(r,t.opacityTexture,i)),t.opacityFresnelParameters&&(o.opacityFresnelParameters=s(t.opacityFresnelParameters)),t.reflectionTexture&&(o.reflectionTexture=n(r,t.reflectionTexture,i)),t.reflectionFresnelParameters&&(o.reflectionFresnelParameters=s(t.reflectionFresnelParameters)),
  t.emissiveTexture&&(o.emissiveTexture=n(r,t.emissiveTexture,i)),t.emissiveFresnelParameters&&(o.emissiveFresnelParameters=s(t.emissiveFresnelParameters)),t.specularTexture&&(o.specularTexture=n(r,t.specularTexture,i)),t.bumpTexture&&(o.bumpTexture=n(r,t.bumpTexture,i)),t.checkReadyOnlyOnce&&(o.checkReadyOnlyOnce=t.checkReadyOnlyOnce),o},h=function(e,t,i,r){for(var n=0;n<t.materials.length;n++){var o=t.materials[n];if(o.id===e)return a(o,i,r)}return null},l=function(t,i){var r=new e.MultiMaterial(t.name,i);r.id=t.id,e.Tags.AddTagsTo(r,t.tags);for(var n=0;n<t.materials.length;n++){var o=t.materials[n];r.subMaterials.push(o?i.getMaterialByID(o):null)}return r},c=function(t,i,r){var n=i.getLastEntryByID(t.emitterId),o=new e.LensFlareSystem("lensFlareSystem#"+t.emitterId,n,i);o.borderLimit=t.borderLimit;for(var s=0;s<t.flares.length;s++){var a=t.flares[s];new e.LensFlare(a.size,a.position,e.Color3.FromArray(a.color),r+a.textureName,o)}return o},u=function(t,i,r){var n=i.getLastMeshByID(t.emitterId),o=new e.ParticleSystem("particles#"+n.name,t.capacity,i);return t.textureName&&(o.particleTexture=new e.Texture(r+t.textureName,i),o.particleTexture.name=t.textureName),o.minAngularSpeed=t.minAngularSpeed,o.maxAngularSpeed=t.maxAngularSpeed,o.minSize=t.minSize,o.maxSize=t.maxSize,o.minLifeTime=t.minLifeTime,o.maxLifeTime=t.maxLifeTime,o.emitter=n,o.emitRate=t.emitRate,o.minEmitBox=e.Vector3.FromArray(t.minEmitBox),o.maxEmitBox=e.Vector3.FromArray(t.maxEmitBox),o.gravity=e.Vector3.FromArray(t.gravity),o.direction1=e.Vector3.FromArray(t.direction1),o.direction2=e.Vector3.FromArray(t.direction2),o.color1=e.Color4.FromArray(t.color1),o.color2=e.Color4.FromArray(t.color2),o.colorDead=e.Color4.FromArray(t.colorDead),o.updateSpeed=t.updateSpeed,o.targetStopDuration=t.targetStopFrame,o.textureMask=e.Color4.FromArray(t.textureMask),o.blendMode=t.blendMode,o.start(),o},f=function(t,i){for(var r=i.getLightByID(t.lightId),n=new e.ShadowGenerator(t.mapSize,r),o=0;o<t.renderList.length;o++){var s=i.getMeshByID(t.renderList[o]);n.getShadowMap().renderList.push(s)}return t.usePoissonSampling?n.usePoissonSampling=!0:t.useVarianceShadowMap?n.useVarianceShadowMap=!0:t.useBlurVarianceShadowMap&&(n.useBlurVarianceShadowMap=!0,t.blurScale&&(n.blurScale=t.blurScale),t.blurBoxOffset&&(n.blurBoxOffset=t.blurBoxOffset)),void 0!==t.bias&&(n.bias=t.bias),n},d=function(t){for(var i=new e.Animation(t.name,t.property,t.framePerSecond,t.dataType,t.loopBehavior),r=t.dataType,n=[],o=0;o<t.keys.length;o++){var s,a=t.keys[o];switch(r){case e.Animation.ANIMATIONTYPE_FLOAT:s=a.values[0];break;case e.Animation.ANIMATIONTYPE_QUATERNION:s=e.Quaternion.FromArray(a.values);break;case e.Animation.ANIMATIONTYPE_MATRIX:s=e.Matrix.FromArray(a.values);break;case e.Animation.ANIMATIONTYPE_VECTOR3:default:s=e.Vector3.FromArray(a.values)}n.push({frame:a.frame,value:s})}return i.setKeys(n),i},p=function(t,i){var r;switch(t.type){case 0:r=new e.PointLight(t.name,e.Vector3.FromArray(t.position),i);break;case 1:r=new e.DirectionalLight(t.name,e.Vector3.FromArray(t.direction),i),r.position=e.Vector3.FromArray(t.position);break;case 2:r=new e.SpotLight(t.name,e.Vector3.FromArray(t.position),e.Vector3.FromArray(t.direction),t.angle,t.exponent,i);break;case 3:r=new e.HemisphericLight(t.name,e.Vector3.FromArray(t.direction),i),r.groundColor=e.Color3.FromArray(t.groundColor)}if(r.id=t.id,e.Tags.AddTagsTo(r,t.tags),void 0!==t.intensity&&(r.intensity=t.intensity),t.range&&(r.range=t.range),r.diffuse=e.Color3.FromArray(t.diffuse),r.specular=e.Color3.FromArray(t.specular),t.excludedMeshesIds&&(r._excludedMeshesIds=t.excludedMeshesIds),t.parentId&&(r._waitingParentId=t.parentId),t.includedOnlyMeshesIds&&(r._includedOnlyMeshesIds=t.includedOnlyMeshesIds),t.animations)for(var n=0;n<t.animations.length;n++){var o=t.animations[n];r.animations.push(d(o))}t.autoAnimate&&i.beginAnimation(r,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,1)},m=function(t,i){var r,n=e.Vector3.FromArray(t.position),o=t.lockedTargetId?i.getLastMeshByID(t.lockedTargetId):null;if("AnaglyphArcRotateCamera"===t.type||"ArcRotateCamera"===t.type){var s=t.alpha,a=t.beta,h=t.radius;if("AnaglyphArcRotateCamera"===t.type){var l=t.interaxial_distance;r=new e.AnaglyphArcRotateCamera(t.name,s,a,h,o,l,i)}else r=new e.ArcRotateCamera(t.name,s,a,h,o,i)}else"AnaglyphFreeCamera"===t.type?(l=t.interaxial_distance,r=new e.AnaglyphFreeCamera(t.name,n,l,i)):"DeviceOrientationCamera"===t.type?r=new e.DeviceOrientationCamera(t.name,n,i):"FollowCamera"===t.type?(r=new e.FollowCamera(t.name,n,i),r.heightOffset=t.heightOffset,r.radius=t.radius,r.rotationOffset=t.rotationOffset,o&&(r.target=o)):r="GamepadCamera"===t.type?new e.GamepadCamera(t.name,n,i):"TouchCamera"===t.type?new e.TouchCamera(t.name,n,i):"VirtualJoysticksCamera"===t.type?new e.VirtualJoysticksCamera(t.name,n,i):"WebVRFreeCamera"===t.type?new e.WebVRFreeCamera(t.name,n,i):"VRDeviceOrientationFreeCamera"===t.type?new e.VRDeviceOrientationFreeCamera(t.name,n,i):new e.FreeCamera(t.name,n,i);if(t.cameraRigMode){var c=t.interaxial_distance?{interaxialDistance:t.interaxial_distance}:{};r.setCameraRigMode(t.cameraRigMode,c)}if(o&&r instanceof e.FreeCamera&&(r.lockedTarget=o),r.id=t.id,e.Tags.AddTagsTo(r,t.tags),t.parentId&&(r._waitingParentId=t.parentId),t.target?r.setTarget?r.setTarget(e.Vector3.FromArray(t.target)):r.target=e.Vector3.FromArray(t.target):r.rotation=e.Vector3.FromArray(t.rotation),r.fov=t.fov,r.minZ=t.minZ,r.maxZ=t.maxZ,r.speed=t.speed,r.inertia=t.inertia,r.checkCollisions=t.checkCollisions,r.applyGravity=t.applyGravity,t.ellipsoid&&(r.ellipsoid=e.Vector3.FromArray(t.ellipsoid)),t.animations)for(var u=0;u<t.animations.length;u++){var f=t.animations[u];r.animations.push(d(f))}return t.autoAnimate&&i.beginAnimation(r,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,1),r.layerMask=t.layerMask&&!isNaN(t.layerMask)?Math.abs(parseInt(t.layerMask)):268435455,r},g=function(e,t){var i=e.id;return t.getGeometryByID(i)},_=function(t,i){if(g(t,i))return null;var r=new e.Geometry.Primitives.Box(t.id,i,t.size,t.canBeRegenerated,null);return e.Tags.AddTagsTo(r,t.tags),i.pushGeometry(r,!0),r},v=function(t,i){if(g(t,i))return null;var r=new e.Geometry.Primitives.Sphere(t.id,i,t.segments,t.diameter,t.canBeRegenerated,null);return e.Tags.AddTagsTo(r,t.tags),i.pushGeometry(r,!0),r},y=function(t,i){if(g(t,i))return null;var r=new e.Geometry.Primitives.Cylinder(t.id,i,t.height,t.diameterTop,t.diameterBottom,t.tessellation,t.subdivisions,t.canBeRegenerated,null);return e.Tags.AddTagsTo(r,t.tags),i.pushGeometry(r,!0),r},x=function(t,i){if(g(t,i))return null;var r=new e.Geometry.Primitives.Torus(t.id,i,t.diameter,t.thickness,t.tessellation,t.canBeRegenerated,null);return e.Tags.AddTagsTo(r,t.tags),i.pushGeometry(r,!0),r},M=function(t,i){if(g(t,i))return null;var r=new e.Geometry.Primitives.Ground(t.id,i,t.width,t.height,t.subdivisions,t.canBeRegenerated,null);return e.Tags.AddTagsTo(r,t.tags),i.pushGeometry(r,!0),r},S=function(t,i){if(g(t,i))return null;var r=new e.Geometry.Primitives.Plane(t.id,i,t.size,t.canBeRegenerated,null);return e.Tags.AddTagsTo(r,t.tags),i.pushGeometry(r,!0),r},b=function(t,i){if(g(t,i))return null;var r=new e.Geometry.Primitives.TorusKnot(t.id,i,t.radius,t.tube,t.radialSegments,t.tubularSegments,t.p,t.q,t.canBeRegenerated,null);return e.Tags.AddTagsTo(r,t.tags),i.pushGeometry(r,!0),r},A=function(t,i,r){if(g(t,i))return null;var n=new e.Geometry(t.id,i);return e.Tags.AddTagsTo(n,t.tags),t.delayLoadingFile?(n.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,n.delayLoadingFile=r+t.delayLoadingFile,n._boundingInfo=new e.BoundingInfo(e.Vector3.FromArray(t.boundingBoxMinimum),e.Vector3.FromArray(t.boundingBoxMaximum)),n._delayInfo=[],t.hasUVs&&n._delayInfo.push(e.VertexBuffer.UVKind),t.hasUVs2&&n._delayInfo.push(e.VertexBuffer.UV2Kind),t.hasUVs3&&n._delayInfo.push(e.VertexBuffer.UV3Kind),t.hasUVs4&&n._delayInfo.push(e.VertexBuffer.UV4Kind),t.hasUVs5&&n._delayInfo.push(e.VertexBuffer.UV5Kind),t.hasUVs6&&n._delayInfo.push(e.VertexBuffer.UV6Kind),t.hasColors&&n._delayInfo.push(e.VertexBuffer.ColorKind),t.hasMatricesIndices&&n._delayInfo.push(e.VertexBuffer.MatricesIndicesKind),t.hasMatricesWeights&&n._delayInfo.push(e.VertexBuffer.MatricesWeightsKind),n._delayLoadingFunction=C):C(t,n),i.pushGeometry(n,!0),n},T=function(t,i,r){var n=new e.Mesh(t.name,i);if(n.id=t.id,e.Tags.AddTagsTo(n,t.tags),n.position=e.Vector3.FromArray(t.position),t.rotationQuaternion?n.rotationQuaternion=e.Quaternion.FromArray(t.rotationQuaternion):t.rotation&&(n.rotation=e.Vector3.FromArray(t.rotation)),n.scaling=e.Vector3.FromArray(t.scaling),t.localMatrix?n.setPivotMatrix(e.Matrix.FromArray(t.localMatrix)):t.pivotMatrix&&n.setPivotMatrix(e.Matrix.FromArray(t.pivotMatrix)),n.setEnabled(t.isEnabled),n.isVisible=t.isVisible,n.infiniteDistance=t.infiniteDistance,n.showBoundingBox=t.showBoundingBox,n.showSubMeshesBoundingBox=t.showSubMeshesBoundingBox,void 0!==t.applyFog&&(n.applyFog=t.applyFog),void 0!==t.pickable&&(n.isPickable=t.pickable),void 0!==t.alphaIndex&&(n.alphaIndex=t.alphaIndex),n.receiveShadows=t.receiveShadows,n.billboardMode=t.billboardMode,void 0!==t.visibility&&(n.visibility=t.visibility),n.checkCollisions=t.checkCollisions,n._shouldGenerateFlatShading=t.useFlatShading,t.freezeWorldMatrix&&(n._waitingFreezeWorldMatrix=t.freezeWorldMatrix),t.parentId&&(n._waitingParentId=t.parentId),void 0!==t.actions&&(n._waitingActions=t.actions),n.hasVertexAlpha=t.hasVertexAlpha,t.delayLoadingFile?(n.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,n.delayLoadingFile=r+t.delayLoadingFile,n._boundingInfo=new e.BoundingInfo(e.Vector3.FromArray(t.boundingBoxMinimum),e.Vector3.FromArray(t.boundingBoxMaximum)),t._binaryInfo&&(n._binaryInfo=t._binaryInfo),n._delayInfo=[],t.hasUVs&&n._delayInfo.push(e.VertexBuffer.UVKind),t.hasUVs2&&n._delayInfo.push(e.VertexBuffer.UV2Kind),t.hasUVs3&&n._delayInfo.push(e.VertexBuffer.UV3Kind),t.hasUVs4&&n._delayInfo.push(e.VertexBuffer.UV4Kind),t.hasUVs5&&n._delayInfo.push(e.VertexBuffer.UV5Kind),t.hasUVs6&&n._delayInfo.push(e.VertexBuffer.UV6Kind),t.hasColors&&n._delayInfo.push(e.VertexBuffer.ColorKind),t.hasMatricesIndices&&n._delayInfo.push(e.VertexBuffer.MatricesIndicesKind),t.hasMatricesWeights&&n._delayInfo.push(e.VertexBuffer.MatricesWeightsKind),n._delayLoadingFunction=I,e.SceneLoader.ForceFullSceneLoadingForIncremental&&n._checkDelayState()):I(t,n),t.materialId?n.setMaterialByID(t.materialId):n.material=null,t.skeletonId>-1&&(n.skeleton=i.getLastSkeletonByID(t.skeletonId)),t.physicsImpostor&&(i.isPhysicsEnabled()||i.enablePhysics(),n.setPhysicsState({impostor:t.physicsImpostor,mass:t.physicsMass,friction:t.physicsFriction,restitution:t.physicsRestitution})),t.animations)for(var o=0;o<t.animations.length;o++){var s=t.animations[o];n.animations.push(d(s))}if(t.autoAnimate&&i.beginAnimation(n,t.autoAnimateFrom,t.autoAnimateTo,t.autoAnimateLoop,1),n.layerMask=t.layerMask&&!isNaN(t.layerMask)?Math.abs(parseInt(t.layerMask)):268435455,t.instances)for(var a=0;a<t.instances.length;a++){var h=t.instances[a],l=n.createInstance(h.name);if(e.Tags.AddTagsTo(l,h.tags),l.position=e.Vector3.FromArray(h.position),h.rotationQuaternion?l.rotationQuaternion=e.Quaternion.FromArray(h.rotationQuaternion):h.rotation&&(l.rotation=e.Vector3.FromArray(h.rotation)),l.scaling=e.Vector3.FromArray(h.scaling),l.checkCollisions=n.checkCollisions,t.animations)for(o=0;o<t.animations.length;o++)s=t.animations[o],l.animations.push(d(s))}return n},E=function(t,i,r){var n=new e.ActionManager(r);null===i?r.actionManager=n:i.actionManager=n;for(var o=function(t,i){var r=Object.create(e[t].prototype);return r.constructor.apply(r,i),r},s=function(t,i,r,n){if(null===n){var o=parseFloat(i);return"true"===i||"false"===i?"true"===i:isNaN(o)?i:o}for(var s=n.split("."),a=i.split(","),h=0;h<s.length;h++)r=r[s[h]];if("boolean"==typeof r)return"true"===a[0];if("string"==typeof r)return a[0];for(var l=new Array,h=0;h<a.length;h++)l.push(parseFloat(a[h]));return r instanceof e.Vector3?e.Vector3.FromArray(l):r instanceof e.Vector4?e.Vector4.FromArray(l):r instanceof e.Color3?e.Color3.FromArray(l):r instanceof e.Color4?e.Color4.FromArray(l):parseFloat(a[0])},a=function(t,i,h,l,c){if(void 0===c&&(c=null),!t.detached){var u=new Array,f=null,d=null,p=t.combine&&t.combine.length>0;if(u.push(2===t.type?n:i),p){for(var m=new Array,g=0;g<t.combine.length;g++)a(t.combine[g],e.ActionManager.NothingTrigger,h,l,m);u.push(m)}else for(var _=0;_<t.properties.length;_++){var v=t.properties[_].value,y=t.properties[_].name,x=t.properties[_].targetType;"target"===y?v=f=null!==x&&"SceneProperties"===x?r:r.getNodeByName(v):"parent"===y?v=r.getNodeByName(v):"sound"===y?v=r.getSoundByName(v):"propertyPath"!==y?v=2===t.type&&"operator"===y?e.ValueCondition[v]:s(y,v,f,"value"===y?d:null):d=v,u.push(v)}if(u.push(null===c?h:null),"InterpolateValueAction"===t.name){var M=u[u.length-2];u[u.length-1]=M,u[u.length-2]=h}var S=o(t.name,u);null===c?S instanceof e.Condition?(h=S,S=l):(h=null,l?l.then(S):n.registerAction(S)):c.push(S);for(var _=0;_<t.children.length;_++)a(t.children[_],i,h,S,null)}},h=0;h<t.children.length;h++){var l,c=t.children[h];if(c.properties.length>0){var u=c.properties[0].value,f=null===c.properties[0].targetType?u:r.getMeshByName(u);l={trigger:e.ActionManager[c.name],parameter:f}}else l=e.ActionManager[c.name];for(var d=0;d<c.children.length;d++)c.detached||a(c.children[d],l,null,null)}},P=function(t,i,r){var n=t.name,o=r+n,s={autoplay:t.autoplay,loop:t.loop,volume:t.volume,spatialSound:t.spatialSound,maxDistance:t.maxDistance,rolloffFactor:t.rolloffFactor,refDistance:t.refDistance,distanceModel:t.distanceModel,playbackRate:t.playbackRate},a=new e.Sound(n,o,i,function(){i._removePendingData(a)},s);if(i._addPendingData(a),t.position){var h=e.Vector3.FromArray(t.position);a.setPosition(h)}if(t.isDirectional&&(a.setDirectionalCone(t.coneInnerAngle||360,t.coneOuterAngle||360,t.coneOuterGain||0),t.localDirectionToMesh)){var l=e.Vector3.FromArray(t.localDirectionToMesh);a.setLocalDirectionToMesh(l)}if(t.connectedMeshId){var c=i.getMeshByID(t.connectedMeshId);c&&a.attachToMesh(c)}},D=function(e,t,i){t=t instanceof Array?t:[t];for(var r in t)if(e.name===t[r])return i.push(e.id),!0;return e.parentId&&-1!==i.indexOf(e.parentId)?(i.push(e.id),!0):!1},C=function(t,r){var n=new e.VertexData,o=t.positions;o&&n.set(o,e.VertexBuffer.PositionKind);var s=t.normals;s&&n.set(s,e.VertexBuffer.NormalKind);var a=t.uvs;a&&n.set(a,e.VertexBuffer.UVKind);var h=t.uv2s;h&&n.set(h,e.VertexBuffer.UV2Kind);var l=t.uv3s;l&&n.set(l,e.VertexBuffer.UV3Kind);var c=t.uv4s;c&&n.set(c,e.VertexBuffer.UV4Kind);var u=t.uv5s;u&&n.set(u,e.VertexBuffer.UV5Kind);var f=t.uv6s;f&&n.set(f,e.VertexBuffer.UV6Kind);var d=t.colors;d&&n.set(i(d,o.length/3),e.VertexBuffer.ColorKind);var p=t.matricesIndices;p&&n.set(p,e.VertexBuffer.MatricesIndicesKind);var m=t.matricesWeights;m&&n.set(m,e.VertexBuffer.MatricesWeightsKind);var g=t.indices;g&&(n.indices=g),r.setAllVerticesData(n,t.updatable)},I=function(t,r){var n=r.getScene(),o=t.geometryId;if(o){var s=n.getGeometryByID(o);s&&s.applyToMesh(r)}else if(t instanceof ArrayBuffer){var a=r._binaryInfo;if(a.positionsAttrDesc&&a.positionsAttrDesc.count>0){var h=new Float32Array(t,a.positionsAttrDesc.offset,a.positionsAttrDesc.count);r.setVerticesData(e.VertexBuffer.PositionKind,h,!1)}if(a.normalsAttrDesc&&a.normalsAttrDesc.count>0){var l=new Float32Array(t,a.normalsAttrDesc.offset,a.normalsAttrDesc.count);r.setVerticesData(e.VertexBuffer.NormalKind,l,!1)}if(a.uvsAttrDesc&&a.uvsAttrDesc.count>0){var c=new Float32Array(t,a.uvsAttrDesc.offset,a.uvsAttrDesc.count);r.setVerticesData(e.VertexBuffer.UVKind,c,!1)}if(a.uvs2AttrDesc&&a.uvs2AttrDesc.count>0){var u=new Float32Array(t,a.uvs2AttrDesc.offset,a.uvs2AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV2Kind,u,!1)}if(a.uvs3AttrDesc&&a.uvs3AttrDesc.count>0){var f=new Float32Array(t,a.uvs3AttrDesc.offset,a.uvs3AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV3Kind,f,!1)}if(a.uvs4AttrDesc&&a.uvs4AttrDesc.count>0){var d=new Float32Array(t,a.uvs4AttrDesc.offset,a.uvs4AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV4Kind,d,!1)}if(a.uvs5AttrDesc&&a.uvs5AttrDesc.count>0){var p=new Float32Array(t,a.uvs5AttrDesc.offset,a.uvs5AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV5Kind,p,!1)}if(a.uvs6AttrDesc&&a.uvs6AttrDesc.count>0){var m=new Float32Array(t,a.uvs6AttrDesc.offset,a.uvs6AttrDesc.count);r.setVerticesData(e.VertexBuffer.UV6Kind,m,!1)}if(a.colorsAttrDesc&&a.colorsAttrDesc.count>0){var g=new Float32Array(t,a.colorsAttrDesc.offset,a.colorsAttrDesc.count);r.setVerticesData(e.VertexBuffer.ColorKind,g,!1,a.colorsAttrDesc.stride)}if(a.matricesIndicesAttrDesc&&a.matricesIndicesAttrDesc.count>0){var _=new Int32Array(t,a.matricesIndicesAttrDesc.offset,a.matricesIndicesAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,_,!1)}if(a.matricesWeightsAttrDesc&&a.matricesWeightsAttrDesc.count>0){var v=new Float32Array(t,a.matricesWeightsAttrDesc.offset,a.matricesWeightsAttrDesc.count);r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,v,!1)}if(a.indicesAttrDesc&&a.indicesAttrDesc.count>0){var y=new Int32Array(t,a.indicesAttrDesc.offset,a.indicesAttrDesc.count);r.setIndices(y)}if(a.subMeshesAttrDesc&&a.subMeshesAttrDesc.count>0){var x=new Int32Array(t,a.subMeshesAttrDesc.offset,5*a.subMeshesAttrDesc.count);r.subMeshes=[];for(var M=0;M<a.subMeshesAttrDesc.count;M++){var S=x[5*M+0],b=x[5*M+1],A=x[5*M+2],T=x[5*M+3],E=x[5*M+4];new e.SubMesh(S,b,A,T,E,r)}}}else if(t.positions&&t.normals&&t.indices){if(r.setVerticesData(e.VertexBuffer.PositionKind,t.positions,!1),r.setVerticesData(e.VertexBuffer.NormalKind,t.normals,!1),t.uvs&&r.setVerticesData(e.VertexBuffer.UVKind,t.uvs,!1),t.uvs2&&r.setVerticesData(e.VertexBuffer.UV2Kind,t.uvs2,!1),t.uvs3&&r.setVerticesData(e.VertexBuffer.UV3Kind,t.uvs3,!1),t.uvs4&&r.setVerticesData(e.VertexBuffer.UV4Kind,t.uvs4,!1),t.uvs5&&r.setVerticesData(e.VertexBuffer.UV5Kind,t.uvs5,!1),t.uvs6&&r.setVerticesData(e.VertexBuffer.UV6Kind,t.uvs6,!1),t.colors&&r.setVerticesData(e.VertexBuffer.ColorKind,i(t.colors,t.positions.length/3),!1),t.matricesIndices)if(t.matricesIndices._isExpanded)delete t.matricesIndices._isExpanded,r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,t.matricesIndices,!1);else{for(var P=[],M=0;M<t.matricesIndices.length;M++){var D=t.matricesIndices[M];P.push(255&D),P.push((65280&D)>>8),P.push((16711680&D)>>16),P.push(D>>24)}r.setVerticesData(e.VertexBuffer.MatricesIndicesKind,P,!1)}t.matricesWeights&&r.setVerticesData(e.VertexBuffer.MatricesWeightsKind,t.matricesWeights,!1),r.setIndices(t.indices)}if(t.subMeshes){r.subMeshes=[];for(var C=0;C<t.subMeshes.length;C++){var I=t.subMeshes[C];new e.SubMesh(I.materialIndex,I.verticesStart,I.verticesCount,I.indexStart,I.indexCount,r)}}r._shouldGenerateFlatShading&&(r.convertToFlatShadedMesh(),delete r._shouldGenerateFlatShading),r.computeWorldMatrix(!0),n._selectionOctree&&n._selectionOctree.addMesh(r)};e.SceneLoader.RegisterPlugin({extensions:".babylon",importMesh:function(t,i,r,n,s,a,c){for(var f=JSON.parse(r),d=[],p=[],m=[],g=0;g<f.meshes.length;g++){var E=f.meshes[g];if(!t||D(E,t,m)){if(t instanceof Array&&delete t[t.indexOf(E.name)],E.geometryId&&f.geometries){var P=!1;["boxes","spheres","cylinders","toruses","grounds","planes","torusKnots","vertexData"].forEach(function(e){!P&&f.geometries[e]&&f.geometries[e]instanceof Array&&f.geometries[e].forEach(function(t){if(t.id==E.geometryId){switch(e){case"boxes":_(t,i);break;case"spheres":v(t,i);break;case"cylinders":y(t,i);break;case"toruses":x(t,i);break;case"grounds":M(t,i);break;case"planes":S(t,i);break;case"torusKnots":b(t,i);break;case"vertexData":A(t,i,n)}P=!0}})}),P||e.Tools.Warn("Geometry not found for mesh "+E.id)}if(E.materialId){var C=-1!==p.indexOf(E.materialId);if(!C&&f.multiMaterials)for(var I=0;I<f.multiMaterials.length;I++){var w=f.multiMaterials[I];if(w.id==E.materialId){for(var R=0;R<w.materials.length;R++){var L=w.materials[R];p.push(L),h(L,f,i,n)}p.push(w.id),l(w,i),C=!0;break}}C||(p.push(E.materialId),h(E.materialId,f,i,n)||e.Tools.Warn("Material not found for mesh "+E.id))}if(E.skeletonId>-1&&i.skeletons){var O=d.indexOf(E.skeletonId)>-1;if(!O)for(var B=0;B<f.skeletons.length;B++){var F=f.skeletons[B];F.id===E.skeletonId&&(c.push(o(F,i)),d.push(F.id))}}var V=T(E,i,n);s.push(V)}}for(g=0;g<i.meshes.length;g++){var N=i.meshes[g];N._waitingParentId&&(N.parent=i.getLastEntryByID(N._waitingParentId),N._waitingParentId=void 0)}for(g=0;g<i.meshes.length;g++){var N=i.meshes[g];N._waitingFreezeWorldMatrix&&(N.freezeWorldMatrix(),N._waitingFreezeWorldMatrix=void 0)}if(f.particleSystems)for(g=0;g<f.particleSystems.length;g++){var z=f.particleSystems[g];-1!==m.indexOf(z.emitterId)&&a.push(u(z,i,n))}return!0},load:function(t,i,r){var n=JSON.parse(i);t.useDelayedTextureLoading=n.useDelayedTextureLoading&&!e.SceneLoader.ForceFullSceneLoadingForIncremental,t.autoClear=n.autoClear,t.clearColor=e.Color3.FromArray(n.clearColor),t.ambientColor=e.Color3.FromArray(n.ambientColor),t.gravity=e.Vector3.FromArray(n.gravity),n.fogMode&&0!==n.fogMode&&(t.fogMode=n.fogMode,t.fogColor=e.Color3.FromArray(n.fogColor),t.fogStart=n.fogStart,t.fogEnd=n.fogEnd,t.fogDensity=n.fogDensity);for(var s=0;s<n.lights.length;s++){var h=n.lights[s];p(h,t)}if(n.materials)for(s=0;s<n.materials.length;s++){var d=n.materials[s];a(d,t,r)}if(n.multiMaterials)for(s=0;s<n.multiMaterials.length;s++){var g=n.multiMaterials[s];l(g,t)}if(n.skeletons)for(s=0;s<n.skeletons.length;s++){var D=n.skeletons[s];o(D,t)}var C=n.geometries;if(C){var I=C.boxes;if(I)for(s=0;s<I.length;s++){var w=I[s];_(w,t)}var R=C.spheres;if(R)for(s=0;s<R.length;s++){var L=R[s];v(L,t)}var O=C.cylinders;if(O)for(s=0;s<O.length;s++){var B=O[s];y(B,t)}var F=C.toruses;if(F)for(s=0;s<F.length;s++){var V=F[s];x(V,t)}var N=C.grounds;if(N)for(s=0;s<N.length;s++){var z=N[s];M(z,t)}var k=C.planes;if(k)for(s=0;s<k.length;s++){var U=k[s];S(U,t)}var W=C.torusKnots;if(W)for(s=0;s<W.length;s++){var G=W[s];b(G,t)}var Y=C.vertexData;if(Y)for(s=0;s<Y.length;s++){var H=Y[s];A(H,t,r)}}for(s=0;s<n.meshes.length;s++){var j=n.meshes[s];T(j,t,r)}for(s=0;s<n.cameras.length;s++){var K=n.cameras[s];m(K,t)}for(n.activeCameraID&&t.setActiveCameraByID(n.activeCameraID),s=0;s<t.cameras.length;s++){var X=t.cameras[s];X._waitingParentId&&(X.parent=t.getLastEntryByID(X._waitingParentId),X._waitingParentId=void 0)}for(s=0;s<t.lights.length;s++){var q=t.lights[s];q._waitingParentId&&(q.parent=t.getLastEntryByID(q._waitingParentId),q._waitingParentId=void 0)}if(n.sounds)for(s=0;s<n.sounds.length;s++){var Z=n.sounds[s];if(e.Engine.audioEngine.canUseWebAudio)P(Z,t,r);else{new e.Sound(Z.name,null,t)}}for(s=0;s<t.meshes.length;s++){var Q=t.meshes[s];Q._waitingParentId&&(Q.parent=t.getLastEntryByID(Q._waitingParentId),Q._waitingParentId=void 0),Q._waitingActions&&(E(Q._waitingActions,Q,t),Q._waitingActions=void 0)}for(s=0;s<t.meshes.length;s++){var J=t.meshes[s];J._waitingFreezeWorldMatrix&&(J.freezeWorldMatrix(),J._waitingFreezeWorldMatrix=void 0)}if(n.particleSystems)for(s=0;s<n.particleSystems.length;s++){var $=n.particleSystems[s];u($,t,r)}if(n.lensFlareSystems)for(s=0;s<n.lensFlareSystems.length;s++){var ee=n.lensFlareSystems[s];c(ee,t,r)}if(n.shadowGenerators)for(s=0;s<n.shadowGenerators.length;s++){var te=n.shadowGenerators[s];f(te,t)}return n.actions&&E(n.actions,null,t),!0}})}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n,o,s,a){void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),this.name=t,this.cellSize=n,this.sprites=new Array,this.renderingGroupId=0,this.layerMask=268435455,this.fogEnabled=!0,this._vertexDeclaration=[4,4,4,4],this._vertexStrideSize=64,this._capacity=r,this._spriteTexture=new e.Texture(i,o,!0,!1,a),this._spriteTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._spriteTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._epsilon=void 0===s?.01:s,this._scene=o,this._scene.spriteManagers.push(this),this._vertexBuffer=o.getEngine().createDynamicVertexBuffer(r*this._vertexStrideSize*4);for(var h=[],l=0,c=0;r>c;c++)h.push(l),h.push(l+1),h.push(l+2),h.push(l),h.push(l+2),h.push(l+3),l+=4;this._indexBuffer=o.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(r*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 t.prototype._appendSpriteVertex=function(e,t,i,r,n){var o=16*e;0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),0===r?r=this._epsilon:1===r&&(r=1-this._epsilon),this._vertices[o]=t.position.x,this._vertices[o+1]=t.position.y,this._vertices[o+2]=t.position.z,this._vertices[o+3]=t.angle,this._vertices[o+4]=t.width,this._vertices[o+5]=t.height,this._vertices[o+6]=i,this._vertices[o+7]=r,this._vertices[o+8]=t.invertU?1:0,this._vertices[o+9]=t.invertV?1:0;var s=t.cellIndex/n>>0;this._vertices[o+10]=t.cellIndex-s*n,this._vertices[o+11]=s,this._vertices[o+12]=t.color.r,this._vertices[o+13]=t.color.g,this._vertices[o+14]=t.color.b,this._vertices[o+15]=t.color.a},t.prototype.render=function(){if(this._effectBase.isReady()&&this._effectFog.isReady()&&this._spriteTexture&&this._spriteTexture.isReady()){for(var t=this._scene.getEngine(),i=this._spriteTexture.getBaseSize(),r=t.getDeltaTime(),n=Math.min(this._capacity,this.sprites.length),o=i.width/this.cellSize,s=0,a=0;n>a;a++){var h=this.sprites[a];h&&(h._animate(r),this._appendSpriteVertex(s++,h,0,0,o),this._appendSpriteVertex(s++,h,1,0,o),this._appendSpriteVertex(s++,h,1,1,o),this._appendSpriteVertex(s++,h,0,1,o))}t.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices);var l=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(l=this._effectFog),t.enableEffect(l);var c=this._scene.getViewMatrix();l.setTexture("diffuseSampler",this._spriteTexture),l.setMatrix("view",c),l.setMatrix("projection",this._scene.getProjectionMatrix()),l.setFloat2("textureInfos",this.cellSize/i.width,this.cellSize/i.height),this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(l.setFloat4("vFogInfos",this._scene.fogMode,this._scene.fogStart,this._scene.fogEnd,this._scene.fogDensity),l.setColor3("vFogColor",this._scene.fogColor)),t.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,l),t.setDepthFunctionToLessOrEqual(),l.setBool("alphaTest",!0),t.setColorWrite(!1),t.draw(!0,0,6*n),t.setColorWrite(!0),l.setBool("alphaTest",!1),t.setAlphaMode(e.Engine.ALPHA_COMBINE),t.draw(!0,0,6*n),t.setAlphaMode(e.Engine.ALPHA_DISABLE)}},t.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 e=this._scene.spriteManagers.indexOf(this);this._scene.spriteManagers.splice(e,1),this.onDispose&&this.onDispose()},t}();e.SpriteManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.name=t,this.color=new e.Color4(1,1,1,1),this.width=1,this.height=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=i,this._manager.sprites.push(this),this.position=e.Vector3.Zero()}return Object.defineProperty(t.prototype,"size",{get:function(){return this.width},set:function(e){this.width=e,this.height=e},enumerable:!0,configurable:!0}),t.prototype.playAnimation=function(e,t,i,r){this._fromIndex=e,this._toIndex=t,this._loopAnimation=i,this._delay=r,this._animationStarted=!0,this._direction=t>e?1:-1,this.cellIndex=e,this._time=0},t.prototype.stopAnimation=function(){this._animationStarted=!1},t.prototype._animate=function(e){this._animationStarted&&(this._time+=e,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()))))},t.prototype.dispose=function(){for(var e=0;e<this._manager.sprites.length;e++)this._manager.sprites[e]==this&&this._manager.sprites.splice(e,1)},t}();e.Sprite=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n,o){this.name=t,this._vertexDeclaration=[2],this._vertexStrideSize=8,this.texture=i?new e.Texture(i,r,!0):null,this.isBackground=void 0===n?!0:n,this.color=void 0===o?new e.Color4(1,1,1,1):o,this._scene=r,this._scene.layers.push(this);var s=[];s.push(1,1),s.push(-1,1),s.push(-1,-1),s.push(1,-1),this._vertexBuffer=r.getEngine().createVertexBuffer(s);var a=[];a.push(0),a.push(1),a.push(2),a.push(0),a.push(2),a.push(3),this._indexBuffer=r.getEngine().createIndexBuffer(a),this._effect=this._scene.getEngine().createEffect("layer",["position"],["textureMatrix","color"],["textureSampler"],"")}return t.prototype.render=function(){if(this._effect.isReady()&&this.texture&&this.texture.isReady()){var t=this._scene.getEngine();t.enableEffect(this._effect),t.setState(!1),this._effect.setTexture("textureSampler",this.texture),this._effect.setMatrix("textureMatrix",this.texture.getTextureMatrix()),this._effect.setFloat4("color",this.color.r,this.color.g,this.color.b,this.color.a),t.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect),t.setAlphaMode(e.Engine.ALPHA_COMBINE),t.draw(!0,0,6),t.setAlphaMode(e.Engine.ALPHA_DISABLE)}},t.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.texture&&(this.texture.dispose(),this.texture=null);var e=this._scene.layers.indexOf(this);this._scene.layers.splice(e,1),this.onDispose&&this.onDispose()},t}();e.Layer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.position=e.Vector3.Zero(),this.direction=e.Vector3.Zero(),this.color=new e.Color4(0,0,0,0),this.colorStep=new e.Color4(0,0,0,0),this.lifeTime=1,this.age=0,this.size=0,this.angle=0,this.angularSpeed=0}return t.prototype.copyTo=function(e){e.position.copyFrom(this.position),e.direction.copyFrom(this.direction),e.color.copyFrom(this.color),e.colorStep.copyFrom(this.colorStep),e.lifeTime=this.lifeTime,e.age=this.age,e.size=this.size,e.angle=this.angle,e.angularSpeed=this.angularSpeed},t}();e.Particle=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e,t){if(e===t)return e;var i=Math.random();return i*(t-e)+e},i=function(){function i(r,n,o,s){var a=this;this.name=r,this.renderingGroupId=0,this.emitter=null,this.emitRate=10,this.manualEmitCount=-1,this.updateSpeed=.01,this.targetStopDuration=0,this.disposeOnStop=!1,this.minEmitPower=1,this.maxEmitPower=1,this.minLifeTime=1,this.maxLifeTime=1,this.minSize=1,this.maxSize=1,this.minAngularSpeed=0,this.maxAngularSpeed=0,this.layerMask=268435455,this.blendMode=i.BLENDMODE_ONEONE,this.forceDepthWrite=!1,this.gravity=e.Vector3.Zero(),this.direction1=new e.Vector3(0,1,0),this.direction2=new e.Vector3(0,1,0),this.minEmitBox=new e.Vector3(-.5,-.5,-.5),this.maxEmitBox=new e.Vector3(.5,.5,.5),this.color1=new e.Color4(1,1,1,1),this.color2=new e.Color4(1,1,1,1),this.colorDead=new e.Color4(0,0,0,1),this.textureMask=new e.Color4(1,1,1,1),this.particles=new Array,this._vertexDeclaration=[3,4,4],this._vertexStrideSize=44,this._stockParticles=new Array,
  this._newPartsExcess=0,this._scaledColorStep=new e.Color4(0,0,0,0),this._colorDiff=new e.Color4(0,0,0,0),this._scaledDirection=e.Vector3.Zero(),this._scaledGravity=e.Vector3.Zero(),this._currentRenderId=-1,this._started=!1,this._stopped=!1,this._actualFrame=0,this.id=r,this._capacity=n,this._scene=o,this._customEffect=s,o.particleSystems.push(this),this._vertexBuffer=o.getEngine().createDynamicVertexBuffer(n*this._vertexStrideSize*4);for(var h=[],l=0,c=0;n>c;c++)h.push(l),h.push(l+1),h.push(l+2),h.push(l),h.push(l+2),h.push(l+3),l+=4;this._indexBuffer=o.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(n*this._vertexStrideSize),this.startDirectionFunction=function(i,r,n){var o=t(a.direction1.x,a.direction2.x),s=t(a.direction1.y,a.direction2.y),h=t(a.direction1.z,a.direction2.z);e.Vector3.TransformNormalFromFloatsToRef(o*i,s*i,h*i,r,n)},this.startPositionFunction=function(i,r){var n=t(a.minEmitBox.x,a.maxEmitBox.x),o=t(a.minEmitBox.y,a.maxEmitBox.y),s=t(a.minEmitBox.z,a.maxEmitBox.z);e.Vector3.TransformCoordinatesFromFloatsToRef(n,o,s,i,r)},this.updateFunction=function(e){for(var t=0;t<e.length;t++){var i=e[t];i.age+=a._scaledUpdateSpeed,i.age>=i.lifeTime?(a.recycleParticle(i),t--):(i.colorStep.scaleToRef(a._scaledUpdateSpeed,a._scaledColorStep),i.color.addInPlace(a._scaledColorStep),i.color.a<0&&(i.color.a=0),i.angle+=i.angularSpeed*a._scaledUpdateSpeed,i.direction.scaleToRef(a._scaledUpdateSpeed,a._scaledDirection),i.position.addInPlace(a._scaledDirection),a.gravity.scaleToRef(a._scaledUpdateSpeed,a._scaledGravity),i.direction.addInPlace(a._scaledGravity))}}}return i.prototype.recycleParticle=function(e){var t=this.particles.pop();t!==e&&(t.copyTo(e),this._stockParticles.push(t))},i.prototype.getCapacity=function(){return this._capacity},i.prototype.isAlive=function(){return this._alive},i.prototype.isStarted=function(){return this._started},i.prototype.start=function(){this._started=!0,this._stopped=!1,this._actualFrame=0},i.prototype.stop=function(){this._stopped=!0},i.prototype._appendParticleVertex=function(e,t,i,r){var n=11*e;this._vertices[n]=t.position.x,this._vertices[n+1]=t.position.y,this._vertices[n+2]=t.position.z,this._vertices[n+3]=t.color.r,this._vertices[n+4]=t.color.g,this._vertices[n+5]=t.color.b,this._vertices[n+6]=t.color.a,this._vertices[n+7]=t.angle,this._vertices[n+8]=t.size,this._vertices[n+9]=i,this._vertices[n+10]=r},i.prototype._update=function(i){this._alive=this.particles.length>0,this.updateFunction(this.particles);var r;r=this.emitter.position?this.emitter.getWorldMatrix():e.Matrix.Translation(this.emitter.x,this.emitter.y,this.emitter.z);for(var n=0;i>n&&this.particles.length!==this._capacity;n++){if(0!==this._stockParticles.length){var o=this._stockParticles.pop();o.age=0}else o=new e.Particle;this.particles.push(o);var s=t(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(s,r,o.direction),o.lifeTime=t(this.minLifeTime,this.maxLifeTime),o.size=t(this.minSize,this.maxSize),o.angularSpeed=t(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(r,o.position);var a=t(0,1);e.Color4.LerpToRef(this.color1,this.color2,a,o.color),this.colorDead.subtractToRef(o.color,this._colorDiff),this._colorDiff.scaleToRef(1/o.lifeTime,o.colorStep)}},i.prototype._getEffect=function(){if(this._customEffect)return this._customEffect;var e=[];this._scene.clipPlane&&e.push("#define CLIPPLANE");var t=e.join("\n");return this._cachedDefines!==t&&(this._cachedDefines=t,this._effect=this._scene.getEngine().createEffect("particles",["position","color","options"],["invView","view","projection","vClipPlane","textureMask"],["diffuseSampler"],t)),this._effect},i.prototype.animate=function(){if(this._started){var e=this._getEffect();if(this.emitter&&e.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this._currentRenderId!==this._scene.getRenderId()){this._currentRenderId=this._scene.getRenderId(),this._scaledUpdateSpeed=this.updateSpeed*this._scene.getAnimationRatio();var t;this.manualEmitCount>-1?(t=this.manualEmitCount,this.manualEmitCount=0):t=this.emitRate;var i=t*this._scaledUpdateSpeed>>0;this._newPartsExcess+=t*this._scaledUpdateSpeed-i,this._newPartsExcess>1&&(i+=this._newPartsExcess>>0,this._newPartsExcess-=this._newPartsExcess>>0),this._alive=!1,this._stopped?i=0:(this._actualFrame+=this._scaledUpdateSpeed,this.targetStopDuration&&this._actualFrame>=this.targetStopDuration&&this.stop()),this._update(i),this._stopped&&(this._alive||(this._started=!1,this.disposeOnStop&&this._scene._toBeDisposed.push(this)));for(var r=0,n=0;n<this.particles.length;n++){var o=this.particles[n];this._appendParticleVertex(r++,o,0,0),this._appendParticleVertex(r++,o,1,0),this._appendParticleVertex(r++,o,1,1),this._appendParticleVertex(r++,o,0,1)}var s=this._scene.getEngine();s.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices)}}},i.prototype.render=function(){var t=this._getEffect();if(!(this.emitter&&t.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this.particles.length))return 0;var r=this._scene.getEngine();r.enableEffect(t),r.setState(!1);var n=this._scene.getViewMatrix();if(t.setTexture("diffuseSampler",this.particleTexture),t.setMatrix("view",n),t.setMatrix("projection",this._scene.getProjectionMatrix()),t.setFloat4("textureMask",this.textureMask.r,this.textureMask.g,this.textureMask.b,this.textureMask.a),this._scene.clipPlane){var o=this._scene.clipPlane,s=n.clone();s.invert(),t.setMatrix("invView",s),t.setFloat4("vClipPlane",o.normal.x,o.normal.y,o.normal.z,o.d)}return r.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,t),r.setAlphaMode(this.blendMode===i.BLENDMODE_ONEONE?e.Engine.ALPHA_ONEONE:e.Engine.ALPHA_COMBINE),this.forceDepthWrite&&r.setDepthWrite(!0),r.draw(!0,0,6*this.particles.length),r.setAlphaMode(e.Engine.ALPHA_DISABLE),this.particles.length},i.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.particleTexture&&(this.particleTexture.dispose(),this.particleTexture=null);var e=this._scene.particleSystems.indexOf(this);this._scene.particleSystems.splice(e,1),this.onDispose&&this.onDispose()},i.prototype.clone=function(t,r){var n=new i(t,this._capacity,this._scene);return e.Tools.DeepCopy(this,n,["particles"],["_vertexDeclaration","_vertexStrideSize"]),void 0===r&&(r=this.emitter),n.emitter=r,this.particleTexture&&(n.particleTexture=new e.Texture(this.particleTexture.url,this._scene)),n.start(),n},i.BLENDMODE_ONEONE=0,i.BLENDMODE_STANDARD=1,i}();e.ParticleSystem=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,i,r,n,o){this.name=e,this.targetProperty=i,this.framePerSecond=r,this.dataType=n,this.loopMode=o,this._offsetsCache={},this._highLimitsCache={},this._stopped=!1,this.allowMatricesInterpolation=!1,this.targetPropertyPath=i.split("."),this.dataType=n,this.loopMode=void 0===o?t.ANIMATIONLOOPMODE_CYCLE:o}return t.CreateAndStartAnimation=function(i,r,n,o,s,a,h,l,c){var u=void 0;if(!isNaN(parseFloat(a))&&isFinite(a)?u=t.ANIMATIONTYPE_FLOAT:a instanceof e.Quaternion?u=t.ANIMATIONTYPE_QUATERNION:a instanceof e.Vector3?u=t.ANIMATIONTYPE_VECTOR3:a instanceof e.Vector2?u=t.ANIMATIONTYPE_VECTOR2:a instanceof e.Color3&&(u=t.ANIMATIONTYPE_COLOR3),void 0==u)return null;var f=new t(i,n,o,u,l),d=[];return d.push({frame:0,value:a}),d.push({frame:s,value:h}),f.setKeys(d),void 0!==c&&f.setEasingFunction(c),r.animations.push(f),r.getScene().beginAnimation(r,0,s,1===f.loopMode)},t.prototype.reset=function(){this._offsetsCache={},this._highLimitsCache={},this.currentFrame=0},t.prototype.isStopped=function(){return this._stopped},t.prototype.getKeys=function(){return this._keys},t.prototype.getEasingFunction=function(){return this._easingFunction},t.prototype.setEasingFunction=function(e){this._easingFunction=e},t.prototype.floatInterpolateFunction=function(e,t,i){return e+(t-e)*i},t.prototype.quaternionInterpolateFunction=function(t,i,r){return e.Quaternion.Slerp(t,i,r)},t.prototype.vector3InterpolateFunction=function(t,i,r){return e.Vector3.Lerp(t,i,r)},t.prototype.vector2InterpolateFunction=function(t,i,r){return e.Vector2.Lerp(t,i,r)},t.prototype.color3InterpolateFunction=function(t,i,r){return e.Color3.Lerp(t,i,r)},t.prototype.matrixInterpolateFunction=function(t,i,r){var n=new e.Vector3(0,0,0),o=new e.Quaternion,s=new e.Vector3(0,0,0);t.decompose(n,o,s);var a=new e.Vector3(0,0,0),h=new e.Quaternion,l=new e.Vector3(0,0,0);i.decompose(a,h,l);var c=this.vector3InterpolateFunction(n,a,r),u=this.quaternionInterpolateFunction(o,h,r),f=this.vector3InterpolateFunction(s,l,r),d=e.Matrix.Compose(c,u,f);return d},t.prototype.clone=function(){var e=new t(this.name,this.targetPropertyPath.join("."),this.framePerSecond,this.dataType,this.loopMode);return e.setKeys(this._keys),e},t.prototype.setKeys=function(e){this._keys=e.slice(0),this._offsetsCache={},this._highLimitsCache={}},t.prototype._getKeyValue=function(e){return"function"==typeof e?e():e},t.prototype._interpolate=function(e,i,r,n,o){if(r===t.ANIMATIONLOOPMODE_CONSTANT&&i>0)return o.clone?o.clone():o;this.currentFrame=e;var s=Math.max(0,Math.min(this._keys.length-1,Math.floor(this._keys.length*(e-this._keys[0].frame)/(this._keys[this._keys.length-1].frame-this._keys[0].frame))-1));if(this._keys[s].frame>=e)for(;s-1>=0&&this._keys[s].frame>=e;)s--;for(var a=s;a<this._keys.length;a++)if(this._keys[a+1].frame>=e){var h=this._getKeyValue(this._keys[a].value),l=this._getKeyValue(this._keys[a+1].value),c=(e-this._keys[a].frame)/(this._keys[a+1].frame-this._keys[a].frame);switch(null!=this._easingFunction&&(c=this._easingFunction.ease(c)),this.dataType){case t.ANIMATIONTYPE_FLOAT:switch(r){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:return this.floatInterpolateFunction(h,l,c);case t.ANIMATIONLOOPMODE_RELATIVE:return n*i+this.floatInterpolateFunction(h,l,c)}break;case t.ANIMATIONTYPE_QUATERNION:var u=null;switch(r){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:u=this.quaternionInterpolateFunction(h,l,c);break;case t.ANIMATIONLOOPMODE_RELATIVE:u=this.quaternionInterpolateFunction(h,l,c).add(n.scale(i))}return u;case t.ANIMATIONTYPE_VECTOR3:switch(r){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:return this.vector3InterpolateFunction(h,l,c);case t.ANIMATIONLOOPMODE_RELATIVE:return this.vector3InterpolateFunction(h,l,c).add(n.scale(i))}case t.ANIMATIONTYPE_VECTOR2:switch(r){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:return this.vector2InterpolateFunction(h,l,c);case t.ANIMATIONLOOPMODE_RELATIVE:return this.vector2InterpolateFunction(h,l,c).add(n.scale(i))}case t.ANIMATIONTYPE_COLOR3:switch(r){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:return this.color3InterpolateFunction(h,l,c);case t.ANIMATIONLOOPMODE_RELATIVE:return this.color3InterpolateFunction(h,l,c).add(n.scale(i))}case t.ANIMATIONTYPE_MATRIX:switch(r){case t.ANIMATIONLOOPMODE_CYCLE:case t.ANIMATIONLOOPMODE_CONSTANT:if(this.allowMatricesInterpolation)return this.matrixInterpolateFunction(h,l,c);case t.ANIMATIONLOOPMODE_RELATIVE:return h}}break}return this._getKeyValue(this._keys[this._keys.length-1].value)},t.prototype.animate=function(i,r,n,o,s){if(!this.targetPropertyPath||this.targetPropertyPath.length<1)return this._stopped=!0,!1;var a=!0;if(0!==this._keys[0].frame){var h={frame:0,value:this._keys[0].value};this._keys.splice(0,0,h)}(r<this._keys[0].frame||r>this._keys[this._keys.length-1].frame)&&(r=this._keys[0].frame),(n<this._keys[0].frame||n>this._keys[this._keys.length-1].frame)&&(n=this._keys[this._keys.length-1].frame);var l,c=n-r,u=i*this.framePerSecond*s/1e3,f=0;if(u>c&&!o)a=!1,f=this._getKeyValue(this._keys[this._keys.length-1].value);else if(this.loopMode!==t.ANIMATIONLOOPMODE_CYCLE){var d=n.toString()+r.toString();if(!this._offsetsCache[d]){var p=this._interpolate(r,0,t.ANIMATIONLOOPMODE_CYCLE),m=this._interpolate(n,0,t.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case t.ANIMATIONTYPE_FLOAT:this._offsetsCache[d]=m-p;break;case t.ANIMATIONTYPE_QUATERNION:this._offsetsCache[d]=m.subtract(p);break;case t.ANIMATIONTYPE_VECTOR3:this._offsetsCache[d]=m.subtract(p);case t.ANIMATIONTYPE_VECTOR2:this._offsetsCache[d]=m.subtract(p);case t.ANIMATIONTYPE_COLOR3:this._offsetsCache[d]=m.subtract(p)}this._highLimitsCache[d]=m}f=this._highLimitsCache[d],l=this._offsetsCache[d]}if(void 0===l)switch(this.dataType){case t.ANIMATIONTYPE_FLOAT:l=0;break;case t.ANIMATIONTYPE_QUATERNION:l=new e.Quaternion(0,0,0,0);break;case t.ANIMATIONTYPE_VECTOR3:l=e.Vector3.Zero();break;case t.ANIMATIONTYPE_VECTOR2:l=e.Vector2.Zero();break;case t.ANIMATIONTYPE_COLOR3:l=e.Color3.Black()}var g=u/c>>0,_=a?r+u%c:n,v=this._interpolate(_,g,this.loopMode,l,f);if(this.targetPropertyPath.length>1){for(var y=this._target[this.targetPropertyPath[0]],x=1;x<this.targetPropertyPath.length-1;x++)y=y[this.targetPropertyPath[x]];y[this.targetPropertyPath[this.targetPropertyPath.length-1]]=v}else this._target[this.targetPropertyPath[0]]=v;return this._target.markAsDirty&&this._target.markAsDirty(this.targetProperty),a||(this._stopped=!0),a},Object.defineProperty(t,"ANIMATIONTYPE_FLOAT",{get:function(){return t._ANIMATIONTYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ANIMATIONTYPE_VECTOR3",{get:function(){return t._ANIMATIONTYPE_VECTOR3},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ANIMATIONTYPE_VECTOR2",{get:function(){return t._ANIMATIONTYPE_VECTOR2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ANIMATIONTYPE_QUATERNION",{get:function(){return t._ANIMATIONTYPE_QUATERNION},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ANIMATIONTYPE_MATRIX",{get:function(){return t._ANIMATIONTYPE_MATRIX},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ANIMATIONTYPE_COLOR3",{get:function(){return t._ANIMATIONTYPE_COLOR3},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ANIMATIONLOOPMODE_RELATIVE",{get:function(){return t._ANIMATIONLOOPMODE_RELATIVE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ANIMATIONLOOPMODE_CYCLE",{get:function(){return t._ANIMATIONLOOPMODE_CYCLE},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ANIMATIONLOOPMODE_CONSTANT",{get:function(){return t._ANIMATIONLOOPMODE_CONSTANT},enumerable:!0,configurable:!0}),t._ANIMATIONTYPE_FLOAT=0,t._ANIMATIONTYPE_VECTOR3=1,t._ANIMATIONTYPE_QUATERNION=2,t._ANIMATIONTYPE_MATRIX=3,t._ANIMATIONTYPE_COLOR3=4,t._ANIMATIONTYPE_VECTOR2=5,t._ANIMATIONLOOPMODE_RELATIVE=0,t._ANIMATIONLOOPMODE_CYCLE=1,t._ANIMATIONLOOPMODE_CONSTANT=2,t}();e.Animation=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,i,r,n,o,s,a){void 0===i&&(i=0),void 0===r&&(r=100),void 0===n&&(n=!1),void 0===o&&(o=1),this.target=t,this.fromFrame=i,this.toFrame=r,this.loopAnimation=n,this.speedRatio=o,this.onAnimationEnd=s,this._animations=new Array,this._paused=!1,this.animationStarted=!1,a&&this.appendAnimations(t,a),this._scene=e,e._activeAnimatables.push(this)}return e.prototype.appendAnimations=function(e,t){for(var i=0;i<t.length;i++){var r=t[i];r._target=e,this._animations.push(r)}},e.prototype.getAnimationByTargetProperty=function(e){for(var t=this._animations,i=0;i<t.length;i++)if(t[i].targetProperty===e)return t[i];return null},e.prototype.reset=function(){for(var e=this._animations,t=0;t<e.length;t++)e[t].reset();this._localDelayOffset=null,this._pausedDelay=null},e.prototype.pause=function(){this._paused||(this._paused=!0)},e.prototype.restart=function(){this._paused=!1},e.prototype.stop=function(){var e=this._scene._activeAnimatables.indexOf(this);e>-1&&this._scene._activeAnimatables.splice(e,1),this.onAnimationEnd&&this.onAnimationEnd()},e.prototype._animate=function(e){if(this._paused)return this._pausedDelay||(this._pausedDelay=e),!0;this._localDelayOffset?this._pausedDelay&&(this._localDelayOffset+=e-this._pausedDelay,this._pausedDelay=null):this._localDelayOffset=e;for(var t=!1,i=this._animations,r=0;r<i.length;r++){var n=i[r],o=n.animate(e-this._localDelayOffset,this.fromFrame,this.toFrame,this.loopAnimation,this.speedRatio);t=t||o}return t||(r=this._scene._activeAnimatables.indexOf(this),this._scene._activeAnimatables.splice(r,1)),!t&&this.onAnimationEnd&&this.onAnimationEnd(),t},e}();e.Animatable=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._easingMode=e.EASINGMODE_EASEIN}return Object.defineProperty(e,"EASINGMODE_EASEIN",{get:function(){return e._EASINGMODE_EASEIN},enumerable:!0,configurable:!0}),Object.defineProperty(e,"EASINGMODE_EASEOUT",{get:function(){return e._EASINGMODE_EASEOUT},enumerable:!0,configurable:!0}),Object.defineProperty(e,"EASINGMODE_EASEINOUT",{get:function(){return e._EASINGMODE_EASEINOUT},enumerable:!0,configurable:!0}),e.prototype.setEasingMode=function(e){var t=Math.min(Math.max(e,0),2);this._easingMode=t},e.prototype.getEasingMode=function(){return this._easingMode},e.prototype.easeInCore=function(e){throw new Error("You must implement this method")},e.prototype.ease=function(t){switch(this._easingMode){case e.EASINGMODE_EASEIN:return this.easeInCore(t);case e.EASINGMODE_EASEOUT:return 1-this.easeInCore(1-t)}return t>=.5?.5*(1-this.easeInCore(2*(1-t)))+.5:.5*this.easeInCore(2*t)},e._EASINGMODE_EASEIN=0,e._EASINGMODE_EASEOUT=1,e._EASINGMODE_EASEINOUT=2,e}();e.EasingFunction=t;var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e=Math.max(0,Math.min(1,e)),1-Math.sqrt(1-e*e)},t}(t);e.CircleEase=i;var r=function(e){function t(t){void 0===t&&(t=1),e.call(this),this.amplitude=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.amplitude);return Math.pow(e,3)-e*t*Math.sin(3.141592653589793*e)},t}(t);e.BackEase=r;var n=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=2),e.call(this),this.bounces=t,this.bounciness=i}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.bounces),i=this.bounciness;1>=i&&(i=1.001);var r=Math.pow(i,t),n=1-i,o=(1-r)/n+.5*r,s=e*o,a=Math.log(-s*(1-i)+1)/Math.log(i),h=Math.floor(a),l=h+1,c=(1-Math.pow(i,h))/(n*o),u=(1-Math.pow(i,l))/(n*o),f=.5*(c+u),d=e-f,p=f-c;return-Math.pow(1/i,t-h)/(p*p)*(d-p)*(d+p)},t}(t);e.BounceEase=n;var o=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e},t}(t);e.CubicEase=o;var s=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=3),e.call(this),this.oscillations=t,this.springiness=i}return __extends(t,e),t.prototype.easeInCore=function(e){var t,i=Math.max(0,this.oscillations),r=Math.max(0,this.springiness);return t=0==r?e:(Math.exp(r*e)-1)/(Math.exp(r)-1),t*Math.sin((6.283185307179586*i+1.5707963267948966)*e)},t}(t);e.ElasticEase=s;var a=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.exponent=t}return __extends(t,e),t.prototype.easeInCore=function(e){return this.exponent<=0?e:(Math.exp(this.exponent*e)-1)/(Math.exp(this.exponent)-1)},t}(t);e.ExponentialEase=a;var h=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.power=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.power);return Math.pow(e,t)},t}(t);e.PowerEase=h;var l=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e},t}(t);e.QuadraticEase=l;var c=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e},t}(t);e.QuarticEase=c;var u=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e*e},t}(t);e.QuinticEase=u;var f=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return 1-Math.sin(1.5707963267948966*(1-e))},t}(t);e.SineEase=f;var d=function(t){function i(e,i,r,n){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1),void 0===n&&(n=1),t.call(this),this.x1=e,this.y1=i,this.x2=r,this.y2=n}return __extends(i,t),i.prototype.easeInCore=function(t){return e.BezierCurve.interpolate(t,this.x1,this.y1,this.x2,this.y2)},i}(t);e.BezierCurveEase=d}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r){void 0===r&&(r=2),this.maxDepth=r,this.dynamicContent=new Array,this._maxBlockCapacity=i||64,this._selectionContent=new e.SmartArray(1024),this._creationFunc=t}return t.prototype.update=function(e,i,r){t._CreateBlocks(e,i,r,this._maxBlockCapacity,0,this.maxDepth,this,this._creationFunc)},t.prototype.addMesh=function(e){for(var t=0;t<this.blocks.length;t++){var i=this.blocks[t];i.addEntry(e)}},t.prototype.select=function(e,t){this._selectionContent.reset();for(var i=0;i<this.blocks.length;i++){var r=this.blocks[i];r.select(e,this._selectionContent,t)}return t?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t.prototype.intersects=function(e,t,i){this._selectionContent.reset();for(var r=0;r<this.blocks.length;r++){var n=this.blocks[r];n.intersects(e,t,this._selectionContent,i)}return i?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t.prototype.intersectsRay=function(e){this._selectionContent.reset();for(var t=0;t<this.blocks.length;t++){var i=this.blocks[t];i.intersectsRay(e,this._selectionContent)}return this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},t._CreateBlocks=function(t,i,r,n,o,s,a,h){a.blocks=new Array;for(var l=new e.Vector3((i.x-t.x)/2,(i.y-t.y)/2,(i.z-t.z)/2),c=0;2>c;c++)for(var u=0;2>u;u++)for(var f=0;2>f;f++){var d=t.add(l.multiplyByFloats(c,u,f)),p=t.add(l.multiplyByFloats(c+1,u+1,f+1)),m=new e.OctreeBlock(d,p,n,o+1,s,h);m.addEntries(r),a.blocks.push(m)}},t.CreationFuncForMeshes=function(e,t){!e.isBlocked&&e.getBoundingInfo().boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},t.CreationFuncForSubMeshes=function(e,t){e.getBoundingInfo().boundingBox.intersectsMinMax(t.minPoint,t.maxPoint)&&t.entries.push(e)},t}();e.Octree=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,r,n,o){this.entries=new Array,this._boundingVectors=new Array,this._capacity=i,this._depth=r,this._maxDepth=n,this._creationFunc=o,this._minPoint=e,this._maxPoint=t,this._boundingVectors.push(e.clone()),this._boundingVectors.push(t.clone()),this._boundingVectors.push(e.clone()),this._boundingVectors[2].x=t.x,this._boundingVectors.push(e.clone()),this._boundingVectors[3].y=t.y,this._boundingVectors.push(e.clone()),this._boundingVectors[4].z=t.z,this._boundingVectors.push(t.clone()),this._boundingVectors[5].z=e.z,this._boundingVectors.push(t.clone()),this._boundingVectors[6].x=e.x,this._boundingVectors.push(t.clone()),this._boundingVectors[7].y=e.y}return Object.defineProperty(t.prototype,"capacity",{get:function(){return this._capacity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"minPoint",{get:function(){return this._minPoint},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxPoint",{get:function(){return this._maxPoint},enumerable:!0,configurable:!0}),t.prototype.addEntry=function(e){if(this.blocks)for(var t=0;t<this.blocks.length;t++){var i=this.blocks[t];i.addEntry(e)}else this._creationFunc(e,this),this.entries.length>this.capacity&&this._depth<this._maxDepth&&this.createInnerBlocks()},t.prototype.addEntries=function(e){for(var t=0;t<e.length;t++){var i=e[t];this.addEntry(i)}},t.prototype.select=function(t,i,r){if(e.BoundingBox.IsInFrustum(this._boundingVectors,t)){if(this.blocks){for(var n=0;n<this.blocks.length;n++){var o=this.blocks[n];o.select(t,i,r)}return}r?i.concat(this.entries):i.concatWithNoDuplicate(this.entries)}},t.prototype.intersects=function(t,i,r,n){if(e.BoundingBox.IntersectsSphere(this._minPoint,this._maxPoint,t,i)){if(this.blocks){for(var o=0;o<this.blocks.length;o++){var s=this.blocks[o];s.intersects(t,i,r,n)}return}n?r.concat(this.entries):r.concatWithNoDuplicate(this.entries)}},t.prototype.intersectsRay=function(e,t){if(e.intersectsBoxMinMax(this._minPoint,this._maxPoint)){if(this.blocks){for(var i=0;i<this.blocks.length;i++){var r=this.blocks[i];r.intersectsRay(e,t)}return}t.concatWithNoDuplicate(this.entries)}},t.prototype.createInnerBlocks=function(){e.Octree._CreateBlocks(this._minPoint,this._maxPoint,this.entries,this._capacity,this._depth,this._maxDepth,this,this._creationFunc)},t}();e.OctreeBlock=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){t.call(this,i,r.getScene()),this.name=i,this.children=new Array,this.animations=new Array,this._worldTransform=new e.Matrix,this._absoluteTransform=new e.Matrix,this._invertedAbsoluteTransform=new e.Matrix,this._skeleton=r,this._matrix=o,this._baseMatrix=o,r.bones.push(this),n?(this._parent=n,n.children.push(this)):this._parent=null,this._updateDifferenceMatrix()}return __extends(i,t),i.prototype.getParent=function(){return this._parent},i.prototype.getLocalMatrix=function(){return this._matrix},i.prototype.getBaseMatrix=function(){return this._baseMatrix},i.prototype.getWorldMatrix=function(){return this._worldTransform},i.prototype.getInvertedAbsoluteTransform=function(){return this._invertedAbsoluteTransform},i.prototype.getAbsoluteMatrix=function(){for(var e=this._matrix.clone(),t=this._parent;t;)e=e.multiply(t.getLocalMatrix()),t=t.getParent();return e},i.prototype.updateMatrix=function(e){this._matrix=e,this._skeleton._markAsDirty(),this._updateDifferenceMatrix()},i.prototype._updateDifferenceMatrix=function(){this._parent?this._matrix.multiplyToRef(this._parent._absoluteTransform,this._absoluteTransform):this._absoluteTransform.copyFrom(this._matrix),this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform);for(var e=0;e<this.children.length;e++)this.children[e]._updateDifferenceMatrix()},i.prototype.markAsDirty=function(){this._currentRenderId++,this._skeleton._markAsDirty()},i}(e.Node);e.Bone=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r){this.name=t,this.id=i,this.bones=new Array,this._isDirty=!0,this._identity=e.Matrix.Identity(),this.bones=[],this._scene=r,r.skeletons.push(this),this.prepare(),this._isDirty=!0}return t.prototype.getTransformMatrices=function(){return this._transformMatrices},t.prototype.getScene=function(){return this._scene},t.prototype._markAsDirty=function(){this._isDirty=!0},t.prototype.prepare=function(){if(this._isDirty){this._transformMatrices&&this._transformMatrices.length===16*(this.bones.length+1)||(this._transformMatrices=new Float32Array(16*(this.bones.length+1)));for(var e=0;e<this.bones.length;e++){var t=this.bones[e],i=t.getParent();i?t.getLocalMatrix().multiplyToRef(i.getWorldMatrix(),t.getWorldMatrix()):t.getWorldMatrix().copyFrom(t.getLocalMatrix()),t.getInvertedAbsoluteTransform().multiplyToArray(t.getWorldMatrix(),this._transformMatrices,16*e)}this._identity.copyToArray(this._transformMatrices,16*this.bones.length),this._isDirty=!1,this._scene._activeBones+=this.bones.length}},t.prototype.getAnimatables=function(){if(!this._animatables||this._animatables.length!==this.bones.length){this._animatables=[];for(var e=0;e<this.bones.length;e++)this._animatables.push(this.bones[e])}return this._animatables},t.prototype.clone=function(i,r){for(var n=new t(i,r||i,this._scene),o=0;o<this.bones.length;o++){var s=this.bones[o],a=null;if(s.getParent()){var h=this.bones.indexOf(s.getParent());a=n.bones[h]}var l=new e.Bone(s.name,n,a,s.getBaseMatrix());e.Tools.DeepCopy(s.animations,l.animations)}return n},t}();e.Skeleton=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n,o,s,a,h,l,c,u){void 0===a&&(a=e.Texture.NEAREST_SAMPLINGMODE),void 0===u&&(u=e.Engine.TEXTURETYPE_UNSIGNED_INT),this.name=t,this.width=-1,this.height=-1,this._reusable=!1,this._textures=new e.SmartArray(2),this._currentRenderTextureInd=0,null!=s?(this._camera=s,this._scene=s.getScene(),s.attachPostProcess(this),this._engine=this._scene.getEngine()):this._engine=h,this._renderRatio=o,this.renderTargetSamplingMode=a?a:e.Texture.NEAREST_SAMPLINGMODE,this._reusable=l||!1,this._textureType=u,n=n||[],n.push("textureSampler"),this._effect=this._engine.createEffect({vertex:"postprocess",fragment:i},["position"],r||[],n,void 0!==c?c:"")}return t.prototype.isReusable=function(){return this._reusable},t.prototype.activate=function(t,i){t=t||this._camera;var r=t.getScene(),n=t.getEngine().getCaps().maxTextureSize,o=(i?i._width:this._engine.getRenderingCanvas().width)*this._renderRatio|0,s=(i?i._height:this._engine.getRenderingCanvas().height)*this._renderRatio|0;if(o=this._renderRatio.width||e.Tools.GetExponantOfTwo(o,n),s=this._renderRatio.height||e.Tools.GetExponantOfTwo(s,n),this.width!==o||this.height!==s){if(this._textures.length>0){for(var a=0;a<this._textures.length;a++)this._engine._releaseTexture(this._textures.data[a]);this._textures.reset()}this.width=o,this.height=s,this._textures.push(this._engine.createRenderTargetTexture({width:this.width,height:this.height},{generateMipMaps:!1,generateDepthBuffer:t._postProcesses.indexOf(this)===t._postProcessesTakenIndices[0],samplingMode:this.renderTargetSamplingMode,type:this._textureType})),this._reusable&&this._textures.push(this._engine.createRenderTargetTexture({width:this.width,height:this.height},{generateMipMaps:!1,generateDepthBuffer:t._postProcesses.indexOf(this)===t._postProcessesTakenIndices[0],samplingMode:this.renderTargetSamplingMode,type:this._textureType})),this.onSizeChanged&&this.onSizeChanged()}this._engine.bindFramebuffer(this._textures.data[this._currentRenderTextureInd]),this.onActivate&&this.onActivate(t),this.clearColor?this._engine.clear(this.clearColor,!0,!0):this._engine.clear(r.clearColor,r.autoClear||r.forceWireframe,!0),this._reusable&&(this._currentRenderTextureInd=(this._currentRenderTextureInd+1)%2)},t.prototype.apply=function(){return this._effect.isReady()?(this._engine.enableEffect(this._effect),this._engine.setState(!1),this._engine.setAlphaMode(e.Engine.ALPHA_DISABLE),this._engine.setDepthBuffer(!1),this._engine.setDepthWrite(!1),this._effect._bindTexture("textureSampler",this._textures.data[this._currentRenderTextureInd]),this.onApply&&this.onApply(this._effect),this._effect):null},t.prototype.dispose=function(e){if(e=e||this._camera,this._textures.length>0){for(var t=0;t<this._textures.length;t++)this._engine._releaseTexture(this._textures.data[t]);this._textures.reset()}if(e){e.detachPostProcess(this);var i=e._postProcesses.indexOf(this);i===e._postProcessesTakenIndices[0]&&e._postProcessesTakenIndices.length>0&&(this._camera._postProcesses[e._postProcessesTakenIndices[0]].width=-1)}},t}();e.PostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){this._vertexDeclaration=[2],this._vertexStrideSize=8,this._scene=e}return e.prototype._prepareBuffers=function(){if(!this._vertexBuffer){var e=[];e.push(1,1),e.push(-1,1),e.push(-1,-1),e.push(1,-1),this._vertexBuffer=this._scene.getEngine().createVertexBuffer(e);var t=[];t.push(0),t.push(1),t.push(2),t.push(0),t.push(2),t.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(t)}},e.prototype._prepareFrame=function(e){var t=this._scene.activeCamera._postProcesses,i=this._scene.activeCamera._postProcessesTakenIndices;return 0!==i.length&&this._scene.postProcessesEnabled?(t[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera,e),!0):!1},e.prototype.directRender=function(e,t){for(var i=this._scene.getEngine(),r=0;r<e.length;r++){r<e.length-1?e[r+1].activate(this._scene.activeCamera,t):t?i.bindFramebuffer(t):i.restoreDefaultFramebuffer();var n=e[r],o=n.apply();
  
  o&&(n.onBeforeRender&&n.onBeforeRender(o),this._prepareBuffers(),i.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,o),i.draw(!0,0,6),n.onAfterRender&&n.onAfterRender(o))}i.setDepthBuffer(!0),i.setDepthWrite(!0)},e.prototype._finalizeFrame=function(e,t,i){i=i||this._scene.activeCamera._postProcesses;var r=this._scene.activeCamera._postProcessesTakenIndices;if(0!==r.length&&this._scene.postProcessesEnabled){for(var n=this._scene.getEngine(),o=0;o<r.length&&(o<r.length-1?i[r[o+1]].activate(this._scene.activeCamera):t?n.bindFramebuffer(t):n.restoreDefaultFramebuffer(),!e);o++){var s=i[r[o]],a=s.apply();a&&(s.onBeforeRender&&s.onBeforeRender(a),this._prepareBuffers(),n.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,a),n.draw(!0,0,6),s.onAfterRender&&s.onAfterRender(a))}n.setDepthBuffer(!0),n.setDepthWrite(!0)}},e.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)},e}();e.PostProcessManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s){e.call(this,t,"pass",null,null,i,r,n,o,s)}return __extends(t,e),t}(e.PostProcess);e.PassPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s,a,h,l){var c=this;void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),t.call(this,i,"blur",["screenSize","direction","blurWidth"],null,o,s,a,h,l),this.direction=r,this.blurWidth=n,this.onApply=function(e){e.setFloat2("screenSize",c.width,c.height),e.setVector2("direction",c.direction),e.setFloat("blurWidth",c.blurWidth)}}return __extends(i,t),i}(e.PostProcess);e.BlurPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s,a,h,l,c,u){var f=this;t.call(this,i,"refraction",["baseColor","depth","colorLevel"],["refractionSampler"],a,h,l,c,u),this.color=n,this.depth=o,this.colorLevel=s,this.onActivate=function(t){f._refRexture=f._refRexture||new e.Texture(r,t.getScene())},this.onApply=function(e){e.setColor3("baseColor",f.color),e.setFloat("depth",f.depth),e.setFloat("colorLevel",f.colorLevel),e.setTexture("refractionSampler",f._refRexture)}}return __extends(i,t),i.prototype.dispose=function(e){this._refRexture&&this._refRexture.dispose(),t.prototype.dispose.call(this,e)},i}(e.PostProcess);e.RefractionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s){e.call(this,t,"blackAndWhite",null,null,i,r,n,o,s)}return __extends(t,e),t}(e.PostProcess);e.BlackAndWhitePostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s,a){var h=this;e.call(this,t,"convolution",["kernel","screenSize"],null,r,n,o,s,a),this.kernel=i,this.onApply=function(e){e.setFloat2("screenSize",h.width,h.height),e.setArray("kernel",h.kernel)}}return __extends(t,e),t.EdgeDetect0Kernel=[1,0,-1,0,0,0,-1,0,1],t.EdgeDetect1Kernel=[0,1,0,1,-4,1,0,1,0],t.EdgeDetect2Kernel=[-1,-1,-1,-1,8,-1,-1,-1,-1],t.SharpenKernel=[0,-1,0,-1,5,-1,0,-1,0],t.EmbossKernel=[-2,-1,0,-1,1,1,0,1,2],t.GaussianKernel=[0,1,0,1,1,1,0,1,0],t}(e.PostProcess);e.ConvolutionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s,a){var h=this;e.call(this,t,"filter",["kernelMatrix"],null,r,n,o,s,a),this.kernelMatrix=i,this.onApply=function(e){e.setMatrix("kernelMatrix",h.kernelMatrix)}}return __extends(t,e),t}(e.PostProcess);e.FilterPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s){var a=this;e.call(this,t,"fxaa",["texelSize"],null,i,r,n,o,s),this.onSizeChanged=function(){a.texelWidth=1/a.width,a.texelHeight=1/a.height},this.onApply=function(e){e.setFloat2("texelSize",a.texelWidth,a.texelHeight)}}return __extends(t,e),t}(e.PostProcess);e.FxaaPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s){var a=this;t.call(this,i,"stereoscopicInterlace",["stepSize"],["camASampler"],1,r,s,r.getScene().getEngine(),!1,o?"#define IS_STEREOSCOPIC_HORIZ 1":void 0),this._stepSize=new e.Vector2(1/this.width,1/this.height),this.onSizeChanged=function(){a._stepSize=new e.Vector2(1/a.width,1/a.height)},this.onApply=function(e){e.setTextureFromPostProcess("camASampler",n),e.setFloat2("stepSize",a._stepSize.x,a._stepSize.y)}}return __extends(i,t),i}(e.PostProcess);e.StereoscopicInterlacePostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n,o){this.size=t,this.position=i,this.dispose=function(){this.texture&&this.texture.dispose();var e=this._system.lensFlares.indexOf(this);this._system.lensFlares.splice(e,1)},this.color=r||new e.Color3(1,1,1),this.texture=n?new e.Texture(n,o.getScene(),!0):null,this._system=o,o.lensFlares.push(this)}return t}();e.LensFlare=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i){this.name=e,this.lensFlares=new Array,this.borderLimit=300,this.layerMask=268435455,this._vertexDeclaration=[2],this._vertexStrideSize=8,this._isEnabled=!0,this._scene=i,this._emitter=t,i.lensFlareSystems.push(this),this.meshesSelectionPredicate=function(e){return e.material&&e.isVisible&&e.isEnabled()&&e.isBlocker&&0!=(e.layerMask&i.activeCamera.layerMask)};var r=[];r.push(1,1),r.push(-1,1),r.push(-1,-1),r.push(1,-1),this._vertexBuffer=i.getEngine().createVertexBuffer(r);var n=[];n.push(0),n.push(1),n.push(2),n.push(0),n.push(2),n.push(3),this._indexBuffer=i.getEngine().createIndexBuffer(n),this._effect=this._scene.getEngine().createEffect("lensFlare",["position"],["color","viewportMatrix"],["textureSampler"],"")}return Object.defineProperty(t.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(e){this._isEnabled=e},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getEmitter=function(){return this._emitter},t.prototype.setEmitter=function(e){this._emitter=e},t.prototype.getEmitterPosition=function(){return this._emitter.getAbsolutePosition?this._emitter.getAbsolutePosition():this._emitter.position},t.prototype.computeEffectivePosition=function(t){var i=this.getEmitterPosition();return i=e.Vector3.Project(i,e.Matrix.Identity(),this._scene.getTransformMatrix(),t),this._positionX=i.x,this._positionY=i.y,i=e.Vector3.TransformCoordinates(this.getEmitterPosition(),this._scene.getViewMatrix()),i.z>0&&this._positionX>t.x&&this._positionX<t.x+t.width&&this._positionY>t.y&&this._positionY<t.y+t.height?!0:!1},t.prototype._isVisible=function(){if(!this._isEnabled)return!1;var t=this.getEmitterPosition(),i=t.subtract(this._scene.activeCamera.position),r=i.length();i.normalize();var n=new e.Ray(this._scene.activeCamera.position,i),o=this._scene.pickWithRay(n,this.meshesSelectionPredicate,!0);return!o.hit||o.distance>r},t.prototype.render=function(){if(!this._effect.isReady())return!1;var t=this._scene.getEngine(),i=this._scene.activeCamera.viewport,r=i.toGlobal(t);if(!this.computeEffectivePosition(r))return!1;if(!this._isVisible())return!1;var n,o;n=this._positionX<this.borderLimit+r.x?this.borderLimit+r.x-this._positionX:this._positionX>r.x+r.width-this.borderLimit?this._positionX-r.x-r.width+this.borderLimit:0,o=this._positionY<this.borderLimit+r.y?this.borderLimit+r.y-this._positionY:this._positionY>r.y+r.height-this.borderLimit?this._positionY-r.y-r.height+this.borderLimit:0;var s=n>o?n:o;s>this.borderLimit&&(s=this.borderLimit);var a=1-s/this.borderLimit;if(0>a)return!1;a>1&&(a=1);var h=r.x+r.width/2,l=r.y+r.height/2,c=h-this._positionX,u=l-this._positionY;t.enableEffect(this._effect),t.setState(!1),t.setDepthBuffer(!1),t.setAlphaMode(e.Engine.ALPHA_ONEONE),t.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect);for(var f=0;f<this.lensFlares.length;f++){var d=this.lensFlares[f],p=h-c*d.position,m=l-u*d.position,g=d.size,_=d.size*t.getAspectRatio(this._scene.activeCamera),v=2*(p/r.width)-1,y=1-2*(m/r.height),x=e.Matrix.FromValues(g/2,0,0,0,0,_/2,0,0,0,0,1,0,v,y,0,1);this._effect.setMatrix("viewportMatrix",x),this._effect.setTexture("textureSampler",d.texture),this._effect.setFloat4("color",d.color.r*a,d.color.g*a,d.color.b*a,1),t.draw(!0,0,6)}return t.setDepthBuffer(!0),t.setAlphaMode(e.Engine.ALPHA_DISABLE),!0},t.prototype.dispose=function(){for(this._vertexBuffer&&(this._scene.getEngine()._releaseBuffer(this._vertexBuffer),this._vertexBuffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null);this.lensFlares.length;)this.lensFlares[0].dispose();var e=this._scene.lensFlareSystems.indexOf(this);this._scene.lensFlareSystems.splice(e,1)},t}();e.LensFlareSystem=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._registeredMeshes=[],this._physicsMaterials=[],this.updateBodyPosition=function(e){for(var t=0;t<this._registeredMeshes.length;t++){var i=this._registeredMeshes[t];if(i.mesh===e||i.mesh===e.parent){var r=i.body,n=e.getBoundingInfo().boundingBox.center;return r.position.set(n.x,n.z,n.y),r.quaternion.x=e.rotationQuaternion.x,r.quaternion.z=e.rotationQuaternion.y,r.quaternion.y=e.rotationQuaternion.z,void(r.quaternion.w=-e.rotationQuaternion.w)}}}}return t.prototype.initialize=function(e){void 0===e&&(e=10),this._world=new CANNON.World,this._world.broadphase=new CANNON.NaiveBroadphase,this._world.solver.iterations=e},t.prototype._checkWithEpsilon=function(t){return t<e.PhysicsEngine.Epsilon?e.PhysicsEngine.Epsilon:t},t.prototype.runOneStep=function(t){this._world.step(t);for(var i=0;i<this._registeredMeshes.length;i++){var r=this._registeredMeshes[i];if(!r.isChild){var n=r.body.position.x,o=r.body.position.y,s=r.body.position.z,a=r.delta;a?(r.mesh.position.x=n+a.x,r.mesh.position.y=s+a.y,r.mesh.position.z=o+a.z):(r.mesh.position.x=n,r.mesh.position.y=s,r.mesh.position.z=o),r.mesh.rotationQuaternion||(r.mesh.rotationQuaternion=new e.Quaternion(0,0,0,1)),r.mesh.rotationQuaternion.x=r.body.quaternion.x,r.mesh.rotationQuaternion.y=r.body.quaternion.z,r.mesh.rotationQuaternion.z=r.body.quaternion.y,r.mesh.rotationQuaternion.w=-r.body.quaternion.w}}},t.prototype.setGravity=function(e){this._world.gravity.set(e.x,e.z,e.y)},t.prototype.registerMesh=function(t,i,r){switch(this.unregisterMesh(t),t.computeWorldMatrix(!0),i){case e.PhysicsEngine.SphereImpostor:var n=t.getBoundingInfo().boundingBox,o=n.maximumWorld.x-n.minimumWorld.x,s=n.maximumWorld.y-n.minimumWorld.y,a=n.maximumWorld.z-n.minimumWorld.z;return this._createSphere(Math.max(this._checkWithEpsilon(o),this._checkWithEpsilon(s),this._checkWithEpsilon(a))/2,t,r);case e.PhysicsEngine.BoxImpostor:n=t.getBoundingInfo().boundingBox;var h=n.minimumWorld,l=n.maximumWorld,c=l.subtract(h).scale(.5);return this._createBox(this._checkWithEpsilon(c.x),this._checkWithEpsilon(c.y),this._checkWithEpsilon(c.z),t,r);case e.PhysicsEngine.PlaneImpostor:return this._createPlane(t,r);case e.PhysicsEngine.MeshImpostor:var u=t.getVerticesData(e.VertexBuffer.PositionKind),f=t.getIndices();return this._createConvexPolyhedron(u,f,t,r)}return null},t.prototype._createSphere=function(e,t,i){var r=new CANNON.Sphere(e);return i?this._createRigidBodyFromShape(r,t,i.mass,i.friction,i.restitution):r},t.prototype._createBox=function(e,t,i,r,n){var o=new CANNON.Box(new CANNON.Vec3(e,i,t));return n?this._createRigidBodyFromShape(o,r,n.mass,n.friction,n.restitution):o},t.prototype._createPlane=function(e,t){var i=new CANNON.Plane;return t?this._createRigidBodyFromShape(i,e,t.mass,t.friction,t.restitution):i},t.prototype._createConvexPolyhedron=function(t,i,r,n){var o=[],s=[];r.computeWorldMatrix(!0);for(var a=0;a<t.length;a+=3){var h=e.Vector3.Zero();e.Vector3.TransformNormalFromFloatsToRef(t[a],t[a+1],t[a+2],r.getWorldMatrix(),h),o.push(new CANNON.Vec3(h.x,h.z,h.y))}for(var l=0;l<i.length;l+=3)s.push([i[l],i[l+2],i[l+1]]);var c=new CANNON.ConvexPolyhedron(o,s);return n?this._createRigidBodyFromShape(c,r,n.mass,n.friction,n.restitution):c},t.prototype._addMaterial=function(e,t){var i,r;for(i=0;i<this._physicsMaterials.length;i++)if(r=this._physicsMaterials[i],r.friction===e&&r.restitution===t)return r;var n=new CANNON.Material;for(n.friction=e,n.restitution=t,this._physicsMaterials.push(n),i=0;i<this._physicsMaterials.length;i++){r=this._physicsMaterials[i];var o=new CANNON.ContactMaterial(r,n,r.friction*n.friction,r.restitution*n.restitution);o.contactEquationStiffness=1e10,o.contactEquationRegularizationTime=10,this._world.addContactMaterial(o)}return n},t.prototype._createRigidBodyFromShape=function(t,i,r,n,o){var s=null;i.rotationQuaternion&&(s=i.rotationQuaternion.clone(),i.rotationQuaternion=new e.Quaternion(0,0,0,1));var a=i.getBoundingInfo().boundingBox,h=i.position.subtract(a.center),l=this._addMaterial(n,o),c=new CANNON.RigidBody(r,t,l);return s&&(c.quaternion.x=s.x,c.quaternion.z=s.y,c.quaternion.y=s.z,c.quaternion.w=-s.w),c.position.set(a.center.x,a.center.z,a.center.y),this._world.add(c),this._registeredMeshes.push({mesh:i,body:c,material:l,delta:h}),c},t.prototype.registerMeshesAsCompound=function(e,t){for(var i=new CANNON.Compound,r=0;r<e.length;r++){var n=e[r].mesh,o=this.registerMesh(n,e[r].impostor);0==r?i.addChild(o,new CANNON.Vec3(0,0,0)):i.addChild(o,new CANNON.Vec3(n.position.x,n.position.z,n.position.y))}var s=e[0].mesh,a=this._createRigidBodyFromShape(i,s,t.mass,t.friction,t.restitution);return a.parts=e,a},t.prototype._unbindBody=function(e){for(var t=0;t<this._registeredMeshes.length;t++){var i=this._registeredMeshes[t];i.body===e&&(i.body=null,i.delta=0)}},t.prototype.unregisterMesh=function(e){for(var t=0;t<this._registeredMeshes.length;t++){var i=this._registeredMeshes[t];if(i.mesh===e)return i.body&&(this._world.remove(i.body),this._unbindBody(i.body)),void this._registeredMeshes.splice(t,1)}},t.prototype.applyImpulse=function(e,t,i){for(var r=new CANNON.Vec3(i.x,i.z,i.y),n=new CANNON.Vec3(t.x,t.z,t.y),o=0;o<this._registeredMeshes.length;o++){var s=this._registeredMeshes[o];if(s.mesh===e)return void s.body.applyImpulse(n,r)}},t.prototype.createLink=function(e,t,i,r){for(var n=null,o=null,s=0;s<this._registeredMeshes.length;s++){var a=this._registeredMeshes[s];a.mesh===e?n=a.body:a.mesh===t&&(o=a.body)}if(!n||!o)return!1;var h=new CANNON.PointToPointConstraint(n,new CANNON.Vec3(i.x,i.z,i.y),o,new CANNON.Vec3(r.x,r.z,r.y));return this._world.addConstraint(h),!0},t.prototype.dispose=function(){for(;this._registeredMeshes.length;)this.unregisterMesh(this._registeredMeshes[0].mesh)},t.prototype.isSupported=function(){return void 0!==window.CANNON},t}();e.CannonJSPlugin=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._registeredMeshes=[],this.updateBodyPosition=function(e){for(var t=0;t<this._registeredMeshes.length;t++){var i=this._registeredMeshes[t];if(i.mesh===e||i.mesh===e.parent){var r=i.body.body;e.computeWorldMatrix(!0);var n=e.getBoundingInfo().boundingBox.center;return r.setPosition(new OIMO.Vec3(n.x,n.y,n.z)),r.setRotation(new OIMO.Vec3(e.rotation.x,e.rotation.y,e.rotation.z)),void(r.sleeping=!1)}if(i.mesh.parent===e){e.computeWorldMatrix(!0),i.mesh.computeWorldMatrix(!0);var o=i.mesh.getAbsolutePosition(),s=e.rotation;return r=i.body.body,r.setPosition(new OIMO.Vec3(o.x,o.y,o.z)),r.setRotation(new OIMO.Vec3(s.x,s.y,s.z)),void(r.sleeping=!1)}}}}return t.prototype._checkWithEpsilon=function(t){return t<e.PhysicsEngine.Epsilon?e.PhysicsEngine.Epsilon:t},t.prototype.initialize=function(e){this._world=new OIMO.World,this._world.clear()},t.prototype.setGravity=function(e){this._world.gravity=e},t.prototype.registerMesh=function(t,i,r){var n=null;this.unregisterMesh(t),t.computeWorldMatrix(!0);var o=null;t.rotationQuaternion&&(o=t.rotationQuaternion.clone(),t.rotationQuaternion=new e.Quaternion(0,0,0,1),t.computeWorldMatrix(!0));var s=t.getBoundingInfo().boundingBox,a=t.position.subtract(s.center);if(o){var h=new e.Matrix;o.toRotationMatrix(h),a=e.Vector3.TransformCoordinates(a,h)}switch(i){case e.PhysicsEngine.SphereImpostor:var l=s.maximumWorld.x-s.minimumWorld.x,c=s.maximumWorld.y-s.minimumWorld.y,u=s.maximumWorld.z-s.minimumWorld.z,f=Math.max(this._checkWithEpsilon(l),this._checkWithEpsilon(c),this._checkWithEpsilon(u))/2;n=new OIMO.Body({type:"sphere",size:[f],pos:[s.center.x,s.center.y,s.center.z],rot:[t.rotation.x/OIMO.TO_RAD,t.rotation.y/OIMO.TO_RAD,t.rotation.z/OIMO.TO_RAD],move:0!=r.mass,config:[r.mass,r.friction,r.restitution],world:this._world});break;case e.PhysicsEngine.PlaneImpostor:case e.PhysicsEngine.CylinderImpostor:case e.PhysicsEngine.BoxImpostor:var d=s.minimumWorld,p=s.maximumWorld,m=p.subtract(d),g=this._checkWithEpsilon(m.x),_=this._checkWithEpsilon(m.y),v=this._checkWithEpsilon(m.z);n=new OIMO.Body({type:"box",size:[g,_,v],pos:[s.center.x,s.center.y,s.center.z],rot:[t.rotation.x/OIMO.TO_RAD,t.rotation.y/OIMO.TO_RAD,t.rotation.z/OIMO.TO_RAD],move:0!=r.mass,config:[r.mass,r.friction,r.restitution],world:this._world})}return o&&(n.body.orientation=new OIMO.Quat(o.w,o.x,o.y,o.z),n.body.syncShapes()),this._registeredMeshes.push({mesh:t,body:n,delta:a}),n},t.prototype.registerMeshesAsCompound=function(e,t){for(var i=[],r=[],n=[],o=[],s=e[0].mesh,a=0;a<e.length;a++){var h=e[a],l=this._createBodyAsCompound(h,t,s);i.push(l.type),r.push.apply(r,l.size),n.push.apply(n,l.pos),o.push.apply(o,l.rot)}var c=new OIMO.Body({type:i,size:r,pos:n,rot:o,move:0!=t.mass,config:[t.mass,t.friction,t.restitution],world:this._world});return this._registeredMeshes.push({mesh:s,body:c}),c},t.prototype._createBodyAsCompound=function(t,i,r){var n=null,o=t.mesh;switch(o.computeWorldMatrix(),t.impostor){case e.PhysicsEngine.SphereImpostor:var s=o.getBoundingInfo().boundingBox,a=s.maximumWorld.x-s.minimumWorld.x,h=s.maximumWorld.y-s.minimumWorld.y,l=s.maximumWorld.z-s.minimumWorld.z,c=Math.max(this._checkWithEpsilon(a),this._checkWithEpsilon(h),this._checkWithEpsilon(l))/2;n={type:"sphere",size:[c,-1,-1],pos:[o.position.x,o.position.y,o.position.z],rot:[o.rotation.x/OIMO.TO_RAD,o.rotation.y/OIMO.TO_RAD,o.rotation.z/OIMO.TO_RAD]};break;case e.PhysicsEngine.PlaneImpostor:case e.PhysicsEngine.BoxImpostor:s=o.getBoundingInfo().boundingBox;var u=s.minimumWorld,f=s.maximumWorld,d=f.subtract(u),p=this._checkWithEpsilon(d.x),m=this._checkWithEpsilon(d.y),g=this._checkWithEpsilon(d.z),_=o.position;n={type:"box",size:[p,m,g],pos:[_.x,_.y,_.z],rot:[o.rotation.x/OIMO.TO_RAD,o.rotation.y/OIMO.TO_RAD,o.rotation.z/OIMO.TO_RAD]}}return n},t.prototype.unregisterMesh=function(e){for(var t=0;t<this._registeredMeshes.length;t++){var i=this._registeredMeshes[t];if(i.mesh===e||i.mesh===e.parent)return i.body&&(this._world.removeRigidBody(i.body.body),this._unbindBody(i.body)),void this._registeredMeshes.splice(t,1)}},t.prototype._unbindBody=function(e){for(var t=0;t<this._registeredMeshes.length;t++){var i=this._registeredMeshes[t];i.body===e&&(i.body=null)}},t.prototype.applyImpulse=function(e,t,i){for(var r=0;r<this._registeredMeshes.length;r++){var n=this._registeredMeshes[r];if(n.mesh===e||n.mesh===e.parent){var o=n.body.body.massInfo.mass;return void n.body.body.applyImpulse(i.scale(OIMO.INV_SCALE),t.scale(OIMO.INV_SCALE*o))}}},t.prototype.createLink=function(e,t,i,r,n){for(var o=null,s=null,a=0;a<this._registeredMeshes.length;a++){var h=this._registeredMeshes[a];h.mesh===e?o=h.body.body:h.mesh===t&&(s=h.body.body)}return o&&s?(n||(n={}),new OIMO.Link({type:n.type,body1:o,body2:s,min:n.min,max:n.max,axe1:n.axe1,axe2:n.axe2,pos1:[i.x,i.y,i.z],pos2:[r.x,r.y,r.z],collision:n.collision,spring:n.spring,world:this._world}),!0):!1},t.prototype.dispose=function(){for(this._world.clear();this._registeredMeshes.length;)this.unregisterMesh(this._registeredMeshes[0].mesh)},t.prototype.isSupported=function(){return void 0!==OIMO},t.prototype._getLastShape=function(e){for(var t=e.shapes;t.next;)t=t.next;return t},t.prototype.runOneStep=function(t){this._world.step();for(var i,r=this._registeredMeshes.length;r--;){var n=this._registeredMeshes[r].body.body,o=this._registeredMeshes[r].mesh,s=this._registeredMeshes[r].delta;if(!n.sleeping)if(n.shapes.next){var a=this._getLastShape(n);o.position.x=a.position.x*OIMO.WORLD_SCALE,o.position.y=a.position.y*OIMO.WORLD_SCALE,o.position.z=a.position.z*OIMO.WORLD_SCALE;var h=e.Matrix.FromArray(n.getMatrix());o.rotationQuaternion||(o.rotationQuaternion=new e.Quaternion(0,0,0,1)),o.rotationQuaternion.fromRotationMatrix(h),o.computeWorldMatrix()}else{i=n.getMatrix(),h=e.Matrix.FromArray(i);var l=h.m[12],c=h.m[13],u=h.m[14];s?(o.position.x=l+s.x,o.position.y=c+s.y,o.position.z=u+s.z):(o.position.x=l,o.position.y=c,o.position.z=u),o.rotationQuaternion||(o.rotationQuaternion=new e.Quaternion(0,0,0,1)),e.Quaternion.FromRotationMatrixToRef(h,o.rotationQuaternion),o.computeWorldMatrix()}}},t}();e.OimoJSPlugin=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this._currentPlugin=t||new e.OimoJSPlugin}return t.prototype._initialize=function(e){this._currentPlugin.initialize(),this._setGravity(e)},t.prototype._runOneStep=function(e){e>.1?e=.1:0>=e&&(e=1/60),this._currentPlugin.runOneStep(e)},t.prototype._setGravity=function(t){this.gravity=t||new e.Vector3(0,-9.807,0),this._currentPlugin.setGravity(this.gravity)},t.prototype._registerMesh=function(e,t,i){return this._currentPlugin.registerMesh(e,t,i)},t.prototype._registerMeshesAsCompound=function(e,t){return this._currentPlugin.registerMeshesAsCompound(e,t)},t.prototype._unregisterMesh=function(e){this._currentPlugin.unregisterMesh(e)},t.prototype._applyImpulse=function(e,t,i){this._currentPlugin.applyImpulse(e,t,i)},t.prototype._createLink=function(e,t,i,r,n){return this._currentPlugin.createLink(e,t,i,r,n)},t.prototype._updateBodyPosition=function(e){this._currentPlugin.updateBodyPosition(e)},t.prototype.dispose=function(){this._currentPlugin.dispose()},t.prototype.isSupported=function(){return this._currentPlugin.isSupported()},t.NoImpostor=0,t.SphereImpostor=1,t.BoxImpostor=2,t.PlaneImpostor=3,t.MeshImpostor=4,t.CapsuleImpostor=5,t.ConeImpostor=6,t.CylinderImpostor=7,t.ConvexHullImpostor=8,t.Epsilon=.001,t}();e.PhysicsEngine=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t,i=function(t){var i={};if(i.name=t.name,i.id=t.id,i.tags=e.Tags.GetTags(t),t instanceof e.PointLight)i.type=0,i.position=t.position.asArray();else if(t instanceof e.DirectionalLight){i.type=1;var r=t;i.position=r.position.asArray(),i.direction=r.direction.asArray()}else if(t instanceof e.SpotLight){i.type=2;var n=t;i.position=n.position.asArray(),i.direction=n.position.asArray(),i.angle=n.angle,i.exponent=n.exponent}else if(t instanceof e.HemisphericLight){i.type=3;var o=t;i.direction=o.direction.asArray(),i.groundColor=o.groundColor.asArray()}return t.intensity&&(i.intensity=t.intensity),i.range=t.range,i.diffuse=t.diffuse.asArray(),i.specular=t.specular.asArray(),i},r=function(e){var t={};return t.isEnabled=e.isEnabled,t.leftColor=e.leftColor,t.rightColor=e.rightColor,t.bias=e.bias,t.power=e.power,t},n=function(e,i){if(e.animations){i.animations=[];for(var r=0;r<e.animations.length;r++){var n=e.animations[r];i.animations.push(t(n))}}},o=function(t){var i={};if(i.name=t.name,i.tags=e.Tags.GetTags(t),i.id=t.id,i.position=t.position.asArray(),t.parent&&(i.parentId=t.parent.id),i.fov=t.fov,i.minZ=t.minZ,i.maxZ=t.maxZ,i.inertia=t.inertia,t instanceof e.FreeCamera?i.type="FreeCamera":t instanceof e.ArcRotateCamera?i.type="ArcRotateCamera":t instanceof e.AnaglyphArcRotateCamera?i.type="AnaglyphArcRotateCamera":t instanceof e.GamepadCamera?i.type="GamepadCamera":t instanceof e.AnaglyphFreeCamera?i.type="AnaglyphFreeCamera":t instanceof e.DeviceOrientationCamera?i.type="DeviceOrientationCamera":t instanceof e.FollowCamera?i.type="FollowCamera":t instanceof e.TouchCamera?i.type="TouchCamera":t instanceof e.VirtualJoysticksCamera?i.type="VirtualJoysticksCamera":t instanceof e.WebVRFreeCamera?i.type="WebVRFreeCamera":t instanceof e.VRDeviceOrientationFreeCamera&&(i.type="VRDeviceOrientationFreeCamera"),t instanceof e.ArcRotateCamera||t instanceof e.AnaglyphArcRotateCamera){var r=t;i.alpha=r.alpha,i.beta=r.beta,i.radius=r.radius,r.target&&r.target.id&&(i.lockedTargetId=r.target.id)}else if(t instanceof e.FollowCamera){var o=t;i.radius=o.radius,i.heightOffset=o.heightOffset,i.rotationOffset=o.rotationOffset}else(t instanceof e.AnaglyphFreeCamera||t instanceof e.AnaglyphArcRotateCamera)&&void 0!==t._interaxialDistance&&(i.interaxial_distance=e.Tools.ToDegrees(t._interaxialDistance));return void 0!==t.speed&&(i.speed=t.speed),t.target&&t.target instanceof e.Vector3&&(i.target=t.target.asArray()),t.rotation&&t.rotation instanceof e.Vector3&&(i.rotation=t.rotation.asArray()),t.lockedTarget&&t.lockedTarget.id&&(i.lockedTargetId=t.lockedTarget.id),i.checkCollisions=t.checkCollisions||!1,i.applyGravity=t.applyGravity||!1,t.ellipsoid&&(i.ellipsoid=t.ellipsoid.asArray()),n(t,i),i.layerMask=t.layerMask,i};t=function(t){var i={};i.name=t.name,i.property=t.targetProperty,i.framePerSecond=t.framePerSecond,i.dataType=t.dataType,i.loopBehavior=t.loopMode;var r=t.dataType;i.keys=[];for(var n=t.getKeys(),o=0;o<n.length;o++){var s=n[o],a={};switch(a.frame=s.frame,r){case e.Animation.ANIMATIONTYPE_FLOAT:a.values=[s.value];break;case e.Animation.ANIMATIONTYPE_QUATERNION:case e.Animation.ANIMATIONTYPE_MATRIX:case e.Animation.ANIMATIONTYPE_VECTOR3:a.values=s.value.asArray()}i.keys.push(a)}return i};var s,a=function(t){var i={};i.name=t.name,i.id=t.id,i.tags=e.Tags.GetTags(t),i.materials=[];for(var r=0;r<t.subMaterials.length;r++){var n=t.subMaterials[r];i.materials.push(n?n.id:null)}return i},h=function(t){var i={};return i.name=t.name,i.ambient=t.ambientColor.asArray(),i.diffuse=t.diffuseColor.asArray(),i.specular=t.specularColor.asArray(),i.specularPower=t.specularPower,i.emissive=t.emissiveColor.asArray(),i.useReflectionFresnelFromSpecular=i.useReflectionFresnelFromSpecular,i.useEmissiveAsIllumination=i.useEmissiveAsIllumination,i.alpha=t.alpha,i.id=t.id,i.tags=e.Tags.GetTags(t),i.backFaceCulling=t.backFaceCulling,t.diffuseTexture&&(i.diffuseTexture=s(t.diffuseTexture)),t.diffuseFresnelParameters&&(i.diffuseFresnelParameters=r(t.diffuseFresnelParameters)),t.ambientTexture&&(i.ambientTexture=s(t.ambientTexture)),t.opacityTexture&&(i.opacityTexture=s(t.opacityTexture)),t.opacityFresnelParameters&&(i.opacityFresnelParameters=r(t.opacityFresnelParameters)),t.reflectionTexture&&(i.reflectionTexture=s(t.reflectionTexture)),t.reflectionFresnelParameters&&(i.reflectionFresnelParameters=r(t.reflectionFresnelParameters)),t.emissiveTexture&&(i.emissiveTexture=s(t.emissiveTexture)),t.emissiveFresnelParameters&&(i.emissiveFresnelParameters=r(t.emissiveFresnelParameters)),t.specularTexture&&(i.specularTexture=s(t.specularTexture)),t.bumpTexture&&(i.bumpTexture=s(t.bumpTexture)),i};s=function(t){var i={};if(!t.name)return null;if(t instanceof e.CubeTexture)return i.name=t.name,i.hasAlpha=t.hasAlpha,i.isCube=!0,i.level=t.level,i.coordinatesMode=t.coordinatesMode,i;var r;if(t instanceof e.MirrorTexture){var o=t;for(i.renderTargetSize=o.getRenderSize(),i.renderList=[],r=0;r<o.renderList.length;r++)i.renderList.push(o.renderList[r].id);i.mirrorPlane=o.mirrorPlane.asArray()}else if(t instanceof e.RenderTargetTexture){var s=t;for(i.renderTargetSize=s.getRenderSize(),i.renderList=[],r=0;r<s.renderList.length;r++)i.renderList.push(s.renderList[r].id)}var a=t;return i.name=t.name,i.hasAlpha=t.hasAlpha,i.level=t.level,i.coordinatesIndex=t.coordinatesIndex,i.coordinatesMode=t.coordinatesMode,i.uOffset=a.uOffset,i.vOffset=a.vOffset,i.uScale=a.uScale,i.vScale=a.vScale,i.uAng=a.uAng,i.vAng=a.vAng,i.wAng=a.wAng,i.wrapU=t.wrapU,i.wrapV=t.wrapV,n(t,i),i};var l,c,u,f,d,p,m,g,_=function(e){var i={};i.name=e.name,i.id=e.id,i.bones=[];for(var r=0;r<e.bones.length;r++){var n=e.bones[r],o={parentBoneIndex:n.getParent()?e.bones.indexOf(n.getParent()):-1,name:n.name,matrix:n.getLocalMatrix().toArray()};i.bones.push(o),n.animations&&n.animations.length>0&&(o.animation=t(n.animations[0]))}return i},v=function(e){var t={};return t.emitterId=e.emitter.id,t.capacity=e.getCapacity(),e.particleTexture&&(t.textureName=e.particleTexture.name),t.minAngularSpeed=e.minAngularSpeed,t.maxAngularSpeed=e.maxAngularSpeed,t.minSize=e.minSize,t.maxSize=e.maxSize,t.minLifeTime=e.minLifeTime,t.maxLifeTime=e.maxLifeTime,t.emitRate=e.emitRate,t.minEmitBox=e.minEmitBox.asArray(),t.maxEmitBox=e.maxEmitBox.asArray(),t.gravity=e.gravity.asArray(),t.direction1=e.direction1.asArray(),t.direction2=e.direction2.asArray(),t.color1=e.color1.asArray(),t.color2=e.color2.asArray(),t.colorDead=e.colorDead.asArray(),t.updateSpeed=e.updateSpeed,t.targetStopDuration=e.targetStopDuration,t.textureMask=e.textureMask.asArray(),t.blendMode=e.blendMode,t},y=function(t){var i={};i.emitterId=t.getEmitter().id,i.borderLimit=t.borderLimit,i.flares=[];for(var r=0;r<t.lensFlares.length;r++){var n=t.lensFlares[r];i.flares.push({size:n.size,position:n.position,color:n.color.asArray(),textureName:e.Tools.GetFilename(n.texture.name)})}return i},x=function(e){var t={},i=e.getShadowGenerator();t.lightId=e.id,t.mapSize=i.getShadowMap().getRenderSize(),t.useVarianceShadowMap=i.useVarianceShadowMap,t.usePoissonSampling=i.usePoissonSampling,t.renderList=[];for(var r=0;r<i.getShadowMap().renderList.length;r++){var n=i.getShadowMap().renderList[r];t.renderList.push(n.id)}return t},M=[],S=function(t,i){if(!M[t.id]){if(t instanceof e.Geometry.Primitives.Box)i.boxes.push(g(t));else if(t instanceof e.Geometry.Primitives.Sphere)i.spheres.push(m(t));else if(t instanceof e.Geometry.Primitives.Cylinder)i.cylinders.push(p(t));else if(t instanceof e.Geometry.Primitives.Torus)i.toruses.push(d(t));else if(t instanceof e.Geometry.Primitives.Ground)i.grounds.push(f(t));else if(t instanceof e.Geometry.Primitives.Plane)i.planes.push(u(t));else if(t instanceof e.Geometry.Primitives.TorusKnot)i.torusKnots.push(c(t));else{if(t instanceof e.Geometry.Primitives._Primitive)throw new Error("Unknown primitive type");i.vertexData.push(l(t))}M[t.id]=!0}},b=function(t){var i={};return i.id=t.id,e.Tags.HasTags(t)&&(i.tags=e.Tags.GetTags(t)),i};l=function(t){var i=b(t);return t.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(i.positions=t.getVerticesData(e.VertexBuffer.PositionKind)),t.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(i.normals=t.getVerticesData(e.VertexBuffer.NormalKind)),t.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(i.uvs=t.getVerticesData(e.VertexBuffer.UVKind)),t.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(i.uvs2=t.getVerticesData(e.VertexBuffer.UV2Kind)),t.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(i.uvs3=t.getVerticesData(e.VertexBuffer.UV3Kind)),t.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(i.uvs4=t.getVerticesData(e.VertexBuffer.UV4Kind)),t.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(i.uvs5=t.getVerticesData(e.VertexBuffer.UV5Kind)),t.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(i.uvs6=t.getVerticesData(e.VertexBuffer.UV6Kind)),t.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(i.colors=t.getVerticesData(e.VertexBuffer.ColorKind)),t.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(i.matricesIndices=t.getVerticesData(e.VertexBuffer.MatricesIndicesKind),i.matricesIndices._isExpanded=!0),t.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(i.matricesWeights=t.getVerticesData(e.VertexBuffer.MatricesWeightsKind)),i.indices=t.getIndices(),i};var A=function(e){var t=b(e);return t.canBeRegenerated=e.canBeRegenerated(),t};g=function(e){var t=A(e);return t.size=e.size,t},m=function(e){var t=A(e);return t.segments=e.segments,t.diameter=e.diameter,t},p=function(e){var t=A(e);return t.height=e.height,t.diameterTop=e.diameterTop,t.diameterBottom=e.diameterBottom,t.tessellation=e.tessellation,t},d=function(e){var t=A(e);return t.diameter=e.diameter,t.thickness=e.thickness,
  t.tessellation=e.tessellation,t},f=function(e){var t=A(e);return t.width=e.width,t.height=e.height,t.subdivisions=e.subdivisions,t},u=function(e){var t=A(e);return t.size=e.size,t},c=function(e){var t=A(e);return t.radius=e.radius,t.tube=e.tube,t.radialSegments=e.radialSegments,t.tubularSegments=e.tubularSegments,t.p=e.p,t.q=e.q,t};var T=function(t,i){var r={};r.name=t.name,r.id=t.id,e.Tags.HasTags(t)&&(r.tags=e.Tags.GetTags(t)),r.position=t.position.asArray(),t.rotationQuaternion?r.rotationQuaternion=t.rotationQuaternion.asArray():t.rotation&&(r.rotation=t.rotation.asArray()),r.scaling=t.scaling.asArray(),r.localMatrix=t.getPivotMatrix().asArray(),r.isEnabled=t.isEnabled(),r.isVisible=t.isVisible,r.infiniteDistance=t.infiniteDistance,r.pickable=t.isPickable,r.receiveShadows=t.receiveShadows,r.billboardMode=t.billboardMode,r.visibility=t.visibility,r.checkCollisions=t.checkCollisions,t.parent&&(r.parentId=t.parent.id);var o=t._geometry;if(o){var s=o.id;r.geometryId=s,t.getScene().getGeometryByID(s)||S(o,i.geometries),r.subMeshes=[];for(var a=0;a<t.subMeshes.length;a++){var h=t.subMeshes[a];r.subMeshes.push({materialIndex:h.materialIndex,verticesStart:h.verticesStart,verticesCount:h.verticesCount,indexStart:h.indexStart,indexCount:h.indexCount})}}if(t.material?r.materialId=t.material.id:t.material=null,t.skeleton&&(r.skeletonId=t.skeleton.id),t.getPhysicsImpostor()!==e.PhysicsEngine.NoImpostor)switch(r.physicsMass=t.getPhysicsMass(),r.physicsFriction=t.getPhysicsFriction(),r.physicsRestitution=t.getPhysicsRestitution(),t.getPhysicsImpostor()){case e.PhysicsEngine.BoxImpostor:r.physicsImpostor=1;break;case e.PhysicsEngine.SphereImpostor:r.physicsImpostor=2}r.instances=[];for(var l=0;l<t.instances.length;l++){var c=t.instances[l],u={name:c.name,position:c.position,rotation:c.rotation,rotationQuaternion:c.rotationQuaternion,scaling:c.scaling};r.instances.push(u),n(c,u)}return n(t,r),r.layerMask=t.layerMask,r},E=function(t,i){if(t.delayLoadState===e.Engine.DELAYLOADSTATE_LOADED||t.delayLoadState===e.Engine.DELAYLOADSTATE_NONE){t.material&&(t.material instanceof e.StandardMaterial?(i.materials=i.materials||[],i.materials.some(function(e){return e.id===t.material.id})||i.materials.push(h(t.material))):t.material instanceof e.MultiMaterial&&(i.multiMaterials=i.multiMaterials||[],i.multiMaterials.some(function(e){return e.id===t.material.id})||i.multiMaterials.push(a(t.material))));var r=t._geometry;r&&(i.geometries||(i.geometries={},i.geometries.boxes=[],i.geometries.spheres=[],i.geometries.cylinders=[],i.geometries.toruses=[],i.geometries.grounds=[],i.geometries.planes=[],i.geometries.torusKnots=[],i.geometries.vertexData=[]),S(r,i.geometries)),t.skeleton&&(i.skeletons=i.skeletons||[],i.skeletons.push(_(t.skeleton))),i.meshes=i.meshes||[],i.meshes.push(T(t,i))}},P=function(){function t(){}return t.Serialize=function(t){var r={};r.useDelayedTextureLoading=t.useDelayedTextureLoading,r.autoClear=t.autoClear,r.clearColor=t.clearColor.asArray(),r.ambientColor=t.ambientColor.asArray(),r.gravity=t.gravity.asArray(),t.fogMode&&0!==t.fogMode&&(r.fogMode=t.fogMode,r.fogColor=t.fogColor.asArray(),r.fogStart=t.fogStart,r.fogEnd=t.fogEnd,r.fogDensity=t.fogDensity),r.lights=[];var n,s;for(n=0;n<t.lights.length;n++)s=t.lights[n],r.lights.push(i(s));for(r.cameras=[],n=0;n<t.cameras.length;n++){var l=t.cameras[n];r.cameras.push(o(l))}t.activeCamera&&(r.activeCameraID=t.activeCamera.id),r.materials=[],r.multiMaterials=[];var c;for(n=0;n<t.materials.length;n++)c=t.materials[n],r.materials.push(h(c));for(r.multiMaterials=[],n=0;n<t.multiMaterials.length;n++){var u=t.multiMaterials[n];r.multiMaterials.push(a(u))}for(n=0;n<t.materials.length;n++)c=t.materials[n],c instanceof e.StandardMaterial?r.materials.push(h(c)):c instanceof e.MultiMaterial&&r.multiMaterials.push(a(c));for(r.skeletons=[],n=0;n<t.skeletons.length;n++)r.skeletons.push(_(t.skeletons[n]));r.geometries={},r.geometries.boxes=[],r.geometries.spheres=[],r.geometries.cylinders=[],r.geometries.toruses=[],r.geometries.grounds=[],r.geometries.planes=[],r.geometries.torusKnots=[],r.geometries.vertexData=[],M=[];var f=t.getGeometries();for(n=0;n<f.length;n++){var d=f[n];d.isReady()&&S(d,r.geometries)}for(r.meshes=[],n=0;n<t.meshes.length;n++){var p=t.meshes[n];if(p instanceof e.Mesh){var m=p;(m.delayLoadState===e.Engine.DELAYLOADSTATE_LOADED||m.delayLoadState===e.Engine.DELAYLOADSTATE_NONE)&&r.meshes.push(T(m,r))}}for(r.particleSystems=[],n=0;n<t.particleSystems.length;n++)r.particleSystems.push(v(t.particleSystems[n]));for(r.lensFlareSystems=[],n=0;n<t.lensFlareSystems.length;n++)r.lensFlareSystems.push(y(t.lensFlareSystems[n]));for(r.shadowGenerators=[],n=0;n<t.lights.length;n++)s=t.lights[n],s.getShadowGenerator()&&r.shadowGenerators.push(x(s));return r},t.SerializeMesh=function(t,i,r){void 0===i&&(i=!1),void 0===r&&(r=!1);var n={};if(t=t instanceof Array?t:[t],i||r)for(var o=0;o<t.length;++o)r&&t[o].getDescendants().forEach(function(i){i instanceof e.Mesh&&t.indexOf(i)<0&&t.push(i)}),i&&t[o].parent&&t.indexOf(t[o].parent)<0&&t.push(t[o].parent);return t.forEach(function(e){E(e,n)}),n},t}();e.SceneSerializer=P}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=0,i=function(){function t(e,t,i){this.pos=e,this.normal=t,this.uv=i}return t.prototype.clone=function(){return new t(this.pos.clone(),this.normal.clone(),this.uv.clone())},t.prototype.flip=function(){this.normal=this.normal.scale(-1)},t.prototype.interpolate=function(i,r){return new t(e.Vector3.Lerp(this.pos,i.pos,r),e.Vector3.Lerp(this.normal,i.normal,r),e.Vector2.Lerp(this.uv,i.uv,r))},t}(),r=function(){function t(e,t){this.normal=e,this.w=t}return t.FromPoints=function(i,r,n){var o=n.subtract(i),s=r.subtract(i);if(0===o.lengthSquared()||0===s.lengthSquared())return null;var a=e.Vector3.Normalize(e.Vector3.Cross(o,s));return new t(a,e.Vector3.Dot(a,i))},t.prototype.clone=function(){return new t(this.normal.clone(),this.w)},t.prototype.flip=function(){this.normal.scaleInPlace(-1),this.w=-this.w},t.prototype.splitPolygon=function(i,r,o,s,a){for(var h=0,l=1,c=2,u=3,f=0,d=[],p=0;p<i.vertices.length;p++){var m=e.Vector3.Dot(this.normal,i.vertices[p].pos)-this.w,g=m<-t.EPSILON?c:m>t.EPSILON?l:h;f|=g,d.push(g)}switch(f){case h:(e.Vector3.Dot(this.normal,i.plane.normal)>0?r:o).push(i);break;case l:s.push(i);break;case c:a.push(i);break;case u:var _=[],v=[];for(p=0;p<i.vertices.length;p++){var y=(p+1)%i.vertices.length,x=d[p],M=d[y],S=i.vertices[p],b=i.vertices[y];if(x!=c&&_.push(S),x!=l&&v.push(x!=c?S.clone():S),(x|M)==u){m=(this.w-e.Vector3.Dot(this.normal,S.pos))/e.Vector3.Dot(this.normal,b.pos.subtract(S.pos));var A=S.interpolate(b,m);_.push(A),v.push(A.clone())}}if(_.length>=3){var T=new n(_,i.shared);T.plane&&s.push(T)}v.length>=3&&(T=new n(v,i.shared),T.plane&&a.push(T))}},t.EPSILON=1e-5,t}(),n=function(){function e(e,t){this.vertices=e,this.shared=t,this.plane=r.FromPoints(e[0].pos,e[1].pos,e[2].pos)}return e.prototype.clone=function(){var t=this.vertices.map(function(e){return e.clone()});return new e(t,this.shared)},e.prototype.flip=function(){this.vertices.reverse().map(function(e){e.flip()}),this.plane.flip()},e}(),o=function(){function e(e){this.plane=null,this.front=null,this.back=null,this.polygons=[],e&&this.build(e)}return e.prototype.clone=function(){var t=new e;return t.plane=this.plane&&this.plane.clone(),t.front=this.front&&this.front.clone(),t.back=this.back&&this.back.clone(),t.polygons=this.polygons.map(function(e){return e.clone()}),t},e.prototype.invert=function(){for(var e=0;e<this.polygons.length;e++)this.polygons[e].flip();this.plane&&this.plane.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();var t=this.front;this.front=this.back,this.back=t},e.prototype.clipPolygons=function(e){if(!this.plane)return e.slice();for(var t=[],i=[],r=0;r<e.length;r++)this.plane.splitPolygon(e[r],t,i,t,i);return this.front&&(t=this.front.clipPolygons(t)),i=this.back?this.back.clipPolygons(i):[],t.concat(i)},e.prototype.clipTo=function(e){this.polygons=e.clipPolygons(this.polygons),this.front&&this.front.clipTo(e),this.back&&this.back.clipTo(e)},e.prototype.allPolygons=function(){var e=this.polygons.slice();return this.front&&(e=e.concat(this.front.allPolygons())),this.back&&(e=e.concat(this.back.allPolygons())),e},e.prototype.build=function(t){if(t.length){this.plane||(this.plane=t[0].plane.clone());for(var i=[],r=[],n=0;n<t.length;n++)this.plane.splitPolygon(t[n],this.polygons,this.polygons,i,r);i.length&&(this.front||(this.front=new e),this.front.build(i)),r.length&&(this.back||(this.back=new e),this.back.build(r))}},e}(),s=function(){function r(){this.polygons=new Array}return r.FromMesh=function(o){var s,a,h,l,c,u,f,d,p,m,g,_=new Array;if(!(o instanceof e.Mesh))throw"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh";o.computeWorldMatrix(!0),f=o.getWorldMatrix(),d=o.position.clone(),p=o.rotation.clone(),o.rotationQuaternion&&(m=o.rotationQuaternion.clone()),g=o.scaling.clone();for(var v=o.getIndices(),y=o.getVerticesData(e.VertexBuffer.PositionKind),x=o.getVerticesData(e.VertexBuffer.NormalKind),M=o.getVerticesData(e.VertexBuffer.UVKind),S=o.subMeshes,b=0,A=S.length;A>b;b++)for(var T=S[b].indexStart,E=S[b].indexCount+S[b].indexStart;E>T;T+=3){u=[];for(var P=0;3>P;P++){var D=new e.Vector3(x[3*v[T+P]],x[3*v[T+P]+1],x[3*v[T+P]+2]);h=new e.Vector2(M[2*v[T+P]],M[2*v[T+P]+1]);var C=new e.Vector3(y[3*v[T+P]],y[3*v[T+P]+1],y[3*v[T+P]+2]);l=e.Vector3.TransformCoordinates(C,f),a=e.Vector3.TransformNormal(D,f),s=new i(l,a,h),u.push(s)}c=new n(u,{subMeshId:b,meshId:t,materialIndex:S[b].materialIndex}),c.plane&&_.push(c)}var I=r.FromPolygons(_);return I.matrix=f,I.position=d,I.rotation=p,I.scaling=g,I.rotationQuaternion=m,t++,I},r.FromPolygons=function(e){var t=new r;return t.polygons=e,t},r.prototype.clone=function(){var e=new r;return e.polygons=this.polygons.map(function(e){return e.clone()}),e.copyTransformAttributes(this),e},r.prototype.toPolygons=function(){return this.polygons},r.prototype.union=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),r.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},r.prototype.unionInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),this.polygons=t.allPolygons()},r.prototype.subtract=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.invert(),t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),t.invert(),r.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},r.prototype.subtractInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.invert(),t.clipTo(i),i.clipTo(t),i.invert(),i.clipTo(t),i.invert(),t.build(i.allPolygons()),t.invert(),this.polygons=t.allPolygons()},r.prototype.intersect=function(e){var t=new o(this.clone().polygons),i=new o(e.clone().polygons);return t.invert(),i.clipTo(t),i.invert(),t.clipTo(i),i.clipTo(t),t.build(i.allPolygons()),t.invert(),r.FromPolygons(t.allPolygons()).copyTransformAttributes(this)},r.prototype.intersectInPlace=function(e){var t=new o(this.polygons),i=new o(e.polygons);t.invert(),i.clipTo(t),i.invert(),t.clipTo(i),i.clipTo(t),t.build(i.allPolygons()),t.invert(),this.polygons=t.allPolygons()},r.prototype.inverse=function(){var e=this.clone();return e.inverseInPlace(),e},r.prototype.inverseInPlace=function(){this.polygons.map(function(e){e.flip()})},r.prototype.copyTransformAttributes=function(e){return this.matrix=e.matrix,this.position=e.position,this.rotation=e.rotation,this.scaling=e.scaling,this.rotationQuaternion=e.rotationQuaternion,this},r.prototype.buildMeshGeometry=function(t,i,r){var n=this.matrix.clone();n.invert();var o,s,a,h=new e.Mesh(t,i),l=[],c=[],u=[],f=[],d=e.Vector3.Zero(),p=e.Vector3.Zero(),m=e.Vector2.Zero(),g=this.polygons,_=[0,0,0],v={},y=0,x={};r&&g.sort(function(e,t){return e.shared.meshId===t.shared.meshId?e.shared.subMeshId-t.shared.subMeshId:e.shared.meshId-t.shared.meshId});for(var M=0,S=g.length;S>M;M++){o=g[M],x[o.shared.meshId]||(x[o.shared.meshId]={}),x[o.shared.meshId][o.shared.subMeshId]||(x[o.shared.meshId][o.shared.subMeshId]={indexStart:+(1/0),indexEnd:-(1/0),materialIndex:o.shared.materialIndex}),a=x[o.shared.meshId][o.shared.subMeshId];for(var b=2,A=o.vertices.length;A>b;b++){_[0]=0,_[1]=b-1,_[2]=b;for(var T=0;3>T;T++){d.copyFrom(o.vertices[_[T]].pos),p.copyFrom(o.vertices[_[T]].normal),m.copyFrom(o.vertices[_[T]].uv);var E=e.Vector3.TransformCoordinates(d,n),P=e.Vector3.TransformNormal(p,n);s=v[E.x+","+E.y+","+E.z],("undefined"==typeof s||u[3*s]!==P.x||u[3*s+1]!==P.y||u[3*s+2]!==P.z||f[2*s]!==m.x||f[2*s+1]!==m.y)&&(l.push(E.x,E.y,E.z),f.push(m.x,m.y),u.push(p.x,p.y,p.z),s=v[E.x+","+E.y+","+E.z]=l.length/3-1),c.push(s),a.indexStart=Math.min(y,a.indexStart),a.indexEnd=Math.max(y,a.indexEnd),y++}}}if(h.setVerticesData(e.VertexBuffer.PositionKind,l),h.setVerticesData(e.VertexBuffer.NormalKind,u),h.setVerticesData(e.VertexBuffer.UVKind,f),h.setIndices(c),r){var D,C=0;h.subMeshes.length=0;for(var I in x){D=-1;for(var w in x[I])a=x[I][w],e.SubMesh.CreateFromIndices(a.materialIndex+C,a.indexStart,a.indexEnd-a.indexStart+1,h),D=Math.max(a.materialIndex,D);C+=++D}}return h},r.prototype.toMesh=function(e,t,i,r){var n=this.buildMeshGeometry(e,i,r);return n.material=t,n.position.copyFrom(this.position),n.rotation.copyFrom(this.rotation),this.rotationQuaternion&&(n.rotationQuaternion=this.rotationQuaternion.clone()),n.scaling.copyFrom(this.scaling),n.computeWorldMatrix(!0),n},r}();e.CSG=s}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){var s=this;t.call(this,i,"vrDistortionCorrection",["LensCenter","Scale","ScaleIn","HmdWarpParam"],null,o.postProcessScaleFactor,r,e.Texture.BILINEAR_SAMPLINGMODE,null,null),this._isRightEye=n,this._distortionFactors=o.distortionK,this._postProcessScaleFactor=o.postProcessScaleFactor,this._lensCenterOffset=o.lensCenterOffset,this.onSizeChanged=function(){s.aspectRatio=.5*s.width/s.height,s._scaleIn=new e.Vector2(2,2/s.aspectRatio),s._scaleFactor=new e.Vector2(.5*(1/s._postProcessScaleFactor),.5*(1/s._postProcessScaleFactor)*s.aspectRatio),s._lensCenter=new e.Vector2(s._isRightEye?.5-.5*s._lensCenterOffset:.5+.5*s._lensCenterOffset,.5)},this.onApply=function(e){e.setFloat2("LensCenter",s._lensCenter.x,s._lensCenter.y),e.setFloat2("Scale",s._scaleFactor.x,s._scaleFactor.y),e.setFloat2("ScaleIn",s._scaleIn.x,s._scaleIn.y),e.setFloat4("HmdWarpParam",s._distortionFactors[0],s._distortionFactors[1],s._distortionFactors[2],s._distortionFactors[3])}}return __extends(i,t),i}(e.PostProcess);e.VRDistortionCorrectionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){!function(e){e[e.X=0]="X",e[e.Y=1]="Y",e[e.Z=2]="Z"}(e.JoystickAxis||(e.JoystickAxis={}));var t=e.JoystickAxis,i=function(){function i(r){var n=this;this._leftJoystick=r?!0:!1,this._joystickIndex=i._globalJoystickIndex,i._globalJoystickIndex++,this._axisTargetedByLeftAndRight=t.X,this._axisTargetedByUpAndDown=t.Y,this.reverseLeftRight=!1,this.reverseUpDown=!1,this._touches=new e.SmartCollection,this.deltaPosition=e.Vector3.Zero(),this._joystickSensibility=25,this._inversedSensibility=1/(this._joystickSensibility/1e3),this._rotationSpeed=25,this._inverseRotationSpeed=1/(this._rotationSpeed/1e3),this._rotateOnAxisRelativeToMesh=!1,this._onResize=function(e){i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas.width=i.vjCanvasWidth,i.vjCanvas.height=i.vjCanvasHeight,i.halfWidth=i.vjCanvasWidth/2,i.halfHeight=i.vjCanvasHeight/2},i.vjCanvas||(window.addEventListener("resize",this._onResize,!1),i.vjCanvas=document.createElement("canvas"),i.vjCanvasWidth=window.innerWidth,i.vjCanvasHeight=window.innerHeight,i.vjCanvas.width=window.innerWidth,i.vjCanvas.height=window.innerHeight,i.vjCanvas.style.width="100%",i.vjCanvas.style.height="100%",i.vjCanvas.style.position="absolute",i.vjCanvas.style.backgroundColor="transparent",i.vjCanvas.style.top="0px",i.vjCanvas.style.left="0px",i.vjCanvas.style.zIndex="5",i.vjCanvas.style.msTouchAction="none",i.vjCanvasContext=i.vjCanvas.getContext("2d"),i.vjCanvasContext.strokeStyle="#ffffff",i.vjCanvasContext.lineWidth=2,document.body.appendChild(i.vjCanvas)),i.halfWidth=i.vjCanvas.width/2,i.halfHeight=i.vjCanvas.height/2,this.pressed=!1,this._joystickColor="cyan",this._joystickPointerID=-1,this._joystickPointerPos=new e.Vector2(0,0),this._joystickPreviousPointerPos=new e.Vector2(0,0),this._joystickPointerStartPos=new e.Vector2(0,0),this._deltaJoystickVector=new e.Vector2(0,0),this._onPointerDownHandlerRef=function(e){n._onPointerDown(e)},this._onPointerMoveHandlerRef=function(e){n._onPointerMove(e)},this._onPointerOutHandlerRef=function(e){n._onPointerUp(e)},this._onPointerUpHandlerRef=function(e){n._onPointerUp(e)},i.vjCanvas.addEventListener("pointerdown",this._onPointerDownHandlerRef,!1),i.vjCanvas.addEventListener("pointermove",this._onPointerMoveHandlerRef,!1),i.vjCanvas.addEventListener("pointerup",this._onPointerUpHandlerRef,!1),i.vjCanvas.addEventListener("pointerout",this._onPointerUpHandlerRef,!1),i.vjCanvas.addEventListener("contextmenu",function(e){e.preventDefault()},!1),requestAnimationFrame(function(){n._drawVirtualJoystick()})}return i.prototype.setJoystickSensibility=function(e){this._joystickSensibility=e,this._inversedSensibility=1/(this._joystickSensibility/1e3)},i.prototype._onPointerDown=function(e){var t;e.preventDefault(),t=this._leftJoystick===!0?e.clientX<i.halfWidth:e.clientX>i.halfWidth,t&&this._joystickPointerID<0?(this._joystickPointerID=e.pointerId,this._joystickPointerStartPos.x=e.clientX,this._joystickPointerStartPos.y=e.clientY,this._joystickPointerPos=this._joystickPointerStartPos.clone(),this._joystickPreviousPointerPos=this._joystickPointerStartPos.clone(),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this.pressed=!0,this._touches.add(e.pointerId.toString(),e)):i._globalJoystickIndex<2&&this._action&&(this._action(),this._touches.add(e.pointerId.toString(),{x:e.clientX,y:e.clientY,prevX:e.clientX,prevY:e.clientY}))},i.prototype._onPointerMove=function(e){if(this._joystickPointerID==e.pointerId){this._joystickPointerPos.x=e.clientX,this._joystickPointerPos.y=e.clientY,this._deltaJoystickVector=this._joystickPointerPos.clone(),this._deltaJoystickVector=this._deltaJoystickVector.subtract(this._joystickPointerStartPos);var i=this.reverseLeftRight?-1:1,r=i*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,r));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,r));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,r))}var n=this.reverseUpDown?1:-1,o=n*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case t.X:this.deltaPosition.x=Math.min(1,Math.max(-1,o));break;case t.Y:this.deltaPosition.y=Math.min(1,Math.max(-1,o));break;case t.Z:this.deltaPosition.z=Math.min(1,Math.max(-1,o))}}else this._touches.item(e.pointerId.toString())&&(this._touches.item(e.pointerId.toString()).x=e.clientX,this._touches.item(e.pointerId.toString()).y=e.clientY)},i.prototype._onPointerUp=function(e){if(this._joystickPointerID==e.pointerId)i.vjCanvasContext.clearRect(this._joystickPointerStartPos.x-63,this._joystickPointerStartPos.y-63,126,126),i.vjCanvasContext.clearRect(this._joystickPreviousPointerPos.x-41,this._joystickPreviousPointerPos.y-41,82,82),this._joystickPointerID=-1,this.pressed=!1;else{var t=this._touches.item(e.pointerId.toString());t&&i.vjCanvasContext.clearRect(t.prevX-43,t.prevY-43,86,86)}this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(e.pointerId.toString())},i.prototype.setJoystickColor=function(e){this._joystickColor=e},i.prototype.setActionOnTouch=function(e){this._action=e},i.prototype.setAxisForLeftRight=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByLeftAndRight=e;break;default:this._axisTargetedByLeftAndRight=t.X}},i.prototype.setAxisForUpDown=function(e){switch(e){case t.X:case t.Y:case t.Z:this._axisTargetedByUpAndDown=e;break;default:this._axisTargetedByUpAndDown=t.Y}},i.prototype._clearCanvas=function(){this._leftJoystick?i.vjCanvasContext.clearRect(0,0,i.vjCanvasWidth/2,i.vjCanvasHeight):i.vjCanvasContext.clearRect(i.vjCanvasWidth/2,0,i.vjCanvasWidth,i.vjCanvasHeight)},i.prototype._drawVirtualJoystick=function(){var e=this;this.pressed&&this._touches.forEach(function(t){t.pointerId===e._joystickPointerID?(i.vjCanvasContext.clearRect(e._joystickPointerStartPos.x-63,e._joystickPointerStartPos.y-63,126,126),i.vjCanvasContext.clearRect(e._joystickPreviousPointerPos.x-41,e._joystickPreviousPointerPos.y-41,82,82),i.vjCanvasContext.beginPath(),i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.lineWidth=2,i.vjCanvasContext.arc(e._joystickPointerStartPos.x,e._joystickPointerStartPos.y,60,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle=e._joystickColor,i.vjCanvasContext.arc(e._joystickPointerPos.x,e._joystickPointerPos.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),e._joystickPreviousPointerPos=e._joystickPointerPos.clone()):(i.vjCanvasContext.clearRect(t.prevX-43,t.prevY-43,86,86),i.vjCanvasContext.beginPath(),i.vjCanvasContext.fillStyle="white",i.vjCanvasContext.beginPath(),i.vjCanvasContext.strokeStyle="red",i.vjCanvasContext.lineWidth=6,i.vjCanvasContext.arc(t.x,t.y,40,0,2*Math.PI,!0),i.vjCanvasContext.stroke(),i.vjCanvasContext.closePath(),t.prevX=t.x,t.prevY=t.y)}),requestAnimationFrame(function(){e._drawVirtualJoystick()})},i.prototype.releaseCanvas=function(){i.vjCanvas&&(i.vjCanvas.removeEventListener("pointerdown",this._onPointerDownHandlerRef),i.vjCanvas.removeEventListener("pointermove",this._onPointerMoveHandlerRef),i.vjCanvas.removeEventListener("pointerup",this._onPointerUpHandlerRef),i.vjCanvas.removeEventListener("pointerout",this._onPointerUpHandlerRef),window.removeEventListener("resize",this._onResize),document.body.removeChild(i.vjCanvas),i.vjCanvas=null)},i._globalJoystickIndex=0,i}();e.VirtualJoystick=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n){t.call(this,i,r,n),this._leftjoystick=new e.VirtualJoystick(!0),this._leftjoystick.setAxisForUpDown(e.JoystickAxis.Z),this._leftjoystick.setAxisForLeftRight(e.JoystickAxis.X),this._leftjoystick.setJoystickSensibility(.15),this._rightjoystick=new e.VirtualJoystick(!1),this._rightjoystick.setAxisForUpDown(e.JoystickAxis.X),this._rightjoystick.setAxisForLeftRight(e.JoystickAxis.Y),this._rightjoystick.reverseUpDown=!0,this._rightjoystick.setJoystickSensibility(.05),this._rightjoystick.setJoystickColor("yellow")}return __extends(i,t),i.prototype.getLeftJoystick=function(){return this._leftjoystick},i.prototype.getRightJoystick=function(){return this._rightjoystick},i.prototype._checkInputs=function(){var i=50*this._computeLocalCameraSpeed(),r=e.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),n=e.Vector3.TransformCoordinates(new e.Vector3(this._leftjoystick.deltaPosition.x*i,this._leftjoystick.deltaPosition.y*i,this._leftjoystick.deltaPosition.z*i),r);this.cameraDirection=this.cameraDirection.add(n),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)),t.prototype._checkInputs.call(this)},i.prototype.dispose=function(){this._leftjoystick.releaseCanvas(),t.prototype.dispose.call(this)},i}(e.FreeCamera);e.VirtualJoysticksCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){t.call(this,i,r),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._vectors4=new Array,this._matrices=new Array,this._matrices3x3=new Array,this._matrices2x2=new Array,this._cachedWorldViewMatrix=new e.Matrix,this._shaderPath=n,o.needAlphaBlending=o.needAlphaBlending||!1,o.needAlphaTesting=o.needAlphaTesting||!1,o.attributes=o.attributes||["position","normal","uv"],o.uniforms=o.uniforms||["worldViewProjection"],o.samplers=o.samplers||[],o.defines=o.defines||[],this._options=o}return __extends(i,t),i.prototype.needAlphaBlending=function(){return this._options.needAlphaBlending},i.prototype.needAlphaTesting=function(){return this._options.needAlphaTesting},i.prototype._checkUniform=function(e){-1===this._options.uniforms.indexOf(e)&&this._options.uniforms.push(e)},i.prototype.setTexture=function(e,t){return-1===this._options.samplers.indexOf(e)&&this._options.samplers.push(e),this._textures[e]=t,this},i.prototype.setFloat=function(e,t){return this._checkUniform(e),this._floats[e]=t,this},i.prototype.setFloats=function(e,t){return this._checkUniform(e),this._floatsArrays[e]=t,this},i.prototype.setColor3=function(e,t){return this._checkUniform(e),this._colors3[e]=t,this},i.prototype.setColor4=function(e,t){return this._checkUniform(e),this._colors4[e]=t,this},i.prototype.setVector2=function(e,t){return this._checkUniform(e),this._vectors2[e]=t,this},i.prototype.setVector3=function(e,t){return this._checkUniform(e),this._vectors3[e]=t,this},i.prototype.setVector4=function(e,t){return this._checkUniform(e),this._vectors4[e]=t,this},i.prototype.setMatrix=function(e,t){return this._checkUniform(e),this._matrices[e]=t,this},i.prototype.setMatrix3x3=function(e,t){return this._checkUniform(e),this._matrices3x3[e]=t,this},i.prototype.setMatrix2x2=function(e,t){return this._checkUniform(e),this._matrices2x2[e]=t,this},i.prototype.isReady=function(t,i){var r=this.getScene(),n=r.getEngine();if(!this.checkReadyOnEveryCall&&this._renderId===r.getRenderId())return!0;var o=[],s=new e.EffectFallbacks;i&&o.push("#define INSTANCES");for(var a=0;a<this._options.defines.length;a++)o.push(this._options.defines[a]);t&&t.useBones&&t.computeBonesUsingShaders&&(o.push("#define BONES"),o.push("#define BonesPerMesh "+(t.skeleton.bones.length+1)),o.push("#define BONES4"),s.addFallback(0,"BONES4")),n.getAlphaTesting()&&o.push("#define ALPHATEST");var h=this._effect,l=o.join("\n");return this._effect=n.createEffect(this._shaderPath,this._options.attributes,this._options.uniforms,this._options.samplers,l,s,this.onCompiled,this.onError),this._effect.isReady()?(h!==this._effect&&r.resetCachedMaterial(),this._renderId=r.getRenderId(),!0):!1},i.prototype.bindOnlyWorldMatrix=function(e){var t=this.getScene();-1!==this._options.uniforms.indexOf("world")&&this._effect.setMatrix("world",e),-1!==this._options.uniforms.indexOf("worldView")&&(e.multiplyToRef(t.getViewMatrix(),this._cachedWorldViewMatrix),this._effect.setMatrix("worldView",this._cachedWorldViewMatrix)),-1!==this._options.uniforms.indexOf("worldViewProjection")&&this._effect.setMatrix("worldViewProjection",e.multiply(t.getTransformMatrix()))},i.prototype.bind=function(e,i){if(this.bindOnlyWorldMatrix(e),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()),i&&i.useBones&&i.computeBonesUsingShaders&&this._effect.setMatrices("mBones",i.skeleton.getTransformMatrices());for(var r in this._textures)this._effect.setTexture(r,this._textures[r]);for(r in this._floats)this._effect.setFloat(r,this._floats[r]);for(r in this._floatsArrays)this._effect.setArray(r,this._floatsArrays[r]);for(r in this._colors3)this._effect.setColor3(r,this._colors3[r]);for(r in this._colors4){var n=this._colors4[r];this._effect.setFloat4(r,n.r,n.g,n.b,n.a)}for(r in this._vectors2)this._effect.setVector2(r,this._vectors2[r]);for(r in this._vectors3)this._effect.setVector3(r,this._vectors3[r]);for(r in this._vectors4)this._effect.setVector4(r,this._vectors4[r]);for(r in this._matrices)this._effect.setMatrix(r,this._matrices[r]);for(r in this._matrices3x3)this._effect.setMatrix3x3(r,this._matrices3x3[r]);for(r in this._matrices2x2)this._effect.setMatrix2x2(r,this._matrices2x2[r])}t.prototype.bind.call(this,e,i)},i.prototype.clone=function(e){var t=new i(e,this.getScene(),this._shaderPath,this._options);return t},i.prototype.dispose=function(e){for(var i in this._textures)this._textures[i].dispose();this._textures=[],t.prototype.dispose.call(this,e)},i}(e.Material);e.ShaderMaterial=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.prototype.set=function(t,i){switch(i){case e.VertexBuffer.PositionKind:this.positions=t;break;case e.VertexBuffer.NormalKind:this.normals=t;break;case e.VertexBuffer.UVKind:this.uvs=t;break;case e.VertexBuffer.UV2Kind:this.uvs2=t;break;case e.VertexBuffer.UV3Kind:this.uvs3=t;break;case e.VertexBuffer.UV4Kind:this.uvs4=t;break;case e.VertexBuffer.UV5Kind:this.uvs5=t;break;case e.VertexBuffer.UV6Kind:this.uvs6=t;break;case e.VertexBuffer.ColorKind:this.colors=t;break;case e.VertexBuffer.MatricesIndicesKind:this.matricesIndices=t;break;case e.VertexBuffer.MatricesWeightsKind:this.matricesWeights=t}},t.prototype.applyToMesh=function(e,t){this._applyTo(e,t)},t.prototype.applyToGeometry=function(e,t){this._applyTo(e,t)},t.prototype.updateMesh=function(e,t,i){this._update(e)},t.prototype.updateGeometry=function(e,t,i){this._update(e)},t.prototype._applyTo=function(t,i){this.positions&&t.setVerticesData(e.VertexBuffer.PositionKind,this.positions,i),this.normals&&t.setVerticesData(e.VertexBuffer.NormalKind,this.normals,i),this.uvs&&t.setVerticesData(e.VertexBuffer.UVKind,this.uvs,i),this.uvs2&&t.setVerticesData(e.VertexBuffer.UV2Kind,this.uvs2,i),this.uvs3&&t.setVerticesData(e.VertexBuffer.UV3Kind,this.uvs3,i),this.uvs4&&t.setVerticesData(e.VertexBuffer.UV4Kind,this.uvs4,i),this.uvs5&&t.setVerticesData(e.VertexBuffer.UV5Kind,this.uvs5,i),this.uvs6&&t.setVerticesData(e.VertexBuffer.UV6Kind,this.uvs6,i),this.colors&&t.setVerticesData(e.VertexBuffer.ColorKind,this.colors,i),this.matricesIndices&&t.setVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,i),this.matricesWeights&&t.setVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,i),this.indices&&t.setIndices(this.indices)},t.prototype._update=function(t,i,r){this.positions&&t.updateVerticesData(e.VertexBuffer.PositionKind,this.positions,i,r),this.normals&&t.updateVerticesData(e.VertexBuffer.NormalKind,this.normals,i,r),this.uvs&&t.updateVerticesData(e.VertexBuffer.UVKind,this.uvs,i,r),this.uvs2&&t.updateVerticesData(e.VertexBuffer.UV2Kind,this.uvs2,i,r),this.uvs3&&t.updateVerticesData(e.VertexBuffer.UV3Kind,this.uvs3,i,r),this.uvs4&&t.updateVerticesData(e.VertexBuffer.UV4Kind,this.uvs4,i,r),this.uvs5&&t.updateVerticesData(e.VertexBuffer.UV5Kind,this.uvs5,i,r),this.uvs6&&t.updateVerticesData(e.VertexBuffer.UV6Kind,this.uvs6,i,r),this.colors&&t.updateVerticesData(e.VertexBuffer.ColorKind,this.colors,i,r),this.matricesIndices&&t.updateVerticesData(e.VertexBuffer.MatricesIndicesKind,this.matricesIndices,i,r),this.matricesWeights&&t.updateVerticesData(e.VertexBuffer.MatricesWeightsKind,this.matricesWeights,i,r),this.indices&&t.setIndices(this.indices)},t.prototype.transform=function(t){var i,r=e.Vector3.Zero();
  
  if(this.positions){var n=e.Vector3.Zero();for(i=0;i<this.positions.length;i+=3)e.Vector3.FromArrayToRef(this.positions,i,n),e.Vector3.TransformCoordinatesToRef(n,t,r),this.positions[i]=r.x,this.positions[i+1]=r.y,this.positions[i+2]=r.z}if(this.normals){var o=e.Vector3.Zero();for(i=0;i<this.normals.length;i+=3)e.Vector3.FromArrayToRef(this.normals,i,o),e.Vector3.TransformNormalToRef(o,t,r),this.normals[i]=r.x,this.normals[i+1]=r.y,this.normals[i+2]=r.z}},t.prototype.merge=function(e){var t;if(e.indices){this.indices||(this.indices=[]);var i=this.positions?this.positions.length/3:0;for(t=0;t<e.indices.length;t++)this.indices.push(e.indices[t]+i)}if(e.positions)for(this.positions||(this.positions=[]),t=0;t<e.positions.length;t++)this.positions.push(e.positions[t]);if(e.normals)for(this.normals||(this.normals=[]),t=0;t<e.normals.length;t++)this.normals.push(e.normals[t]);if(e.uvs)for(this.uvs||(this.uvs=[]),t=0;t<e.uvs.length;t++)this.uvs.push(e.uvs[t]);if(e.uvs2)for(this.uvs2||(this.uvs2=[]),t=0;t<e.uvs2.length;t++)this.uvs2.push(e.uvs2[t]);if(e.uvs3)for(this.uvs3||(this.uvs3=[]),t=0;t<e.uvs3.length;t++)this.uvs3.push(e.uvs3[t]);if(e.uvs4)for(this.uvs4||(this.uvs4=[]),t=0;t<e.uvs4.length;t++)this.uvs4.push(e.uvs4[t]);if(e.uvs5)for(this.uvs5||(this.uvs5=[]),t=0;t<e.uvs5.length;t++)this.uvs5.push(e.uvs5[t]);if(e.uvs6)for(this.uvs6||(this.uvs6=[]),t=0;t<e.uvs6.length;t++)this.uvs6.push(e.uvs6[t]);if(e.matricesIndices)for(this.matricesIndices||(this.matricesIndices=[]),t=0;t<e.matricesIndices.length;t++)this.matricesIndices.push(e.matricesIndices[t]);if(e.matricesWeights)for(this.matricesWeights||(this.matricesWeights=[]),t=0;t<e.matricesWeights.length;t++)this.matricesWeights.push(e.matricesWeights[t]);if(e.colors)for(this.colors||(this.colors=[]),t=0;t<e.colors.length;t++)this.colors.push(e.colors[t])},t.ExtractFromMesh=function(e,i){return t._ExtractFrom(e,i)},t.ExtractFromGeometry=function(e,i){return t._ExtractFrom(e,i)},t._ExtractFrom=function(i,r){var n=new t;return i.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(n.positions=i.getVerticesData(e.VertexBuffer.PositionKind,r)),i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(n.normals=i.getVerticesData(e.VertexBuffer.NormalKind,r)),i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.uvs=i.getVerticesData(e.VertexBuffer.UVKind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(n.uvs2=i.getVerticesData(e.VertexBuffer.UV2Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(n.uvs3=i.getVerticesData(e.VertexBuffer.UV3Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(n.uvs4=i.getVerticesData(e.VertexBuffer.UV4Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(n.uvs5=i.getVerticesData(e.VertexBuffer.UV5Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(n.uvs6=i.getVerticesData(e.VertexBuffer.UV6Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(n.colors=i.getVerticesData(e.VertexBuffer.ColorKind,r)),i.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(n.matricesIndices=i.getVerticesData(e.VertexBuffer.MatricesIndicesKind,r)),i.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(n.matricesWeights=i.getVerticesData(e.VertexBuffer.MatricesWeightsKind,r)),n.indices=i.getIndices(r),n},t.CreateRibbon=function(i,r,n,o,s){void 0===s&&(s=e.Mesh.DEFAULTSIDE),r=r||!1,n=n||!1;var a=Math.floor(i[0].length/2);o=o||a,o=o>a?a:Math.floor(o);var h,l,c,u,f=[],d=[],p=[],m=[],g=[],_=[],v=[],y=[],x=[],M=[];if(i.length<2){var S=[],b=[];for(c=0;c<i[0].length-o;c++)S.push(i[0][c]),b.push(i[0][c+o]);i=[S,b]}var A,T,E=0,P=n?1:0;h=i[0].length;var D,C;for(l=0;l<i.length;l++){for(v[l]=0,g[l]=[0],A=i[l],T=A.length,h=T>h?h:T,u=0;T>u;)f.push(A[u].x,A[u].y,A[u].z),u>0&&(D=A[u].subtract(A[u-1]).length(),C=D+v[l],g[l].push(C),v[l]=C),u++;n&&(u--,f.push(A[0].x,A[0].y,A[0].z),D=A[u].subtract(A[0]).length(),C=D+v[l],g[l].push(C),v[l]=C),x[l]=T+P,M[l]=E,E+=T+P}var I,w,R,L;for(c=0;h+P>c;c++){for(y[c]=0,_[c]=[0],l=0;l<i.length-1;l++)I=i[l],w=i[l+1],c===h?(R=I[0],L=w[0]):(R=I[c],L=w[c]),D=L.subtract(R).length(),C=D+y[c],_[c].push(C),y[c]=C;r&&(I=i[l],w=i[0],D=w[c].subtract(I[c]).length(),C=D+y[c],y[c]=C)}var O,B;for(l=0;l<i.length;l++)for(c=0;h+P>c;c++)O=g[l][c]/v[l],B=_[c][l]/y[c],m.push(O,B);l=0;for(var F=0,V=x[l]-1,N=x[l+1]-1,z=N>V?V:N,k=M[1]-M[0],U=r?x.length:x.length-1;z>=F&&U>l;)d.push(F,F+k,F+1),d.push(F+k+1,F+1,F+k),F+=1,F===z&&(l++,l===x.length-1?(k=M[0]-M[l],V=x[l]-1,N=x[0]-1):(k=M[l+1]-M[l],V=x[l]-1,N=x[l+1]-1),F=M[l],z=N>V?V+F:N+F);if(t.ComputeNormals(f,d,p),n){var W=0,G=0;for(l=0;l<i.length;l++)W=3*M[l],G=l+1<i.length?3*(M[l+1]-1):p.length-3,p[W]=.5*(p[W]+p[G]),p[W+1]=.5*(p[W+1]+p[G+1]),p[W+2]=.5*(p[W+2]+p[G+2]),p[G]=p[W],p[G+1]=p[W+1],p[G+2]=p[W+2]}t._ComputeSides(s,f,d,p,m);var Y=new t;return Y.indices=d,Y.positions=f,Y.normals=p,Y.uvs=m,n&&(Y._idx=M),Y},t.CreateBox=function(i,r){void 0===r&&(r=e.Mesh.DEFAULTSIDE);var n,o=[new e.Vector3(0,0,1),new e.Vector3(0,0,-1),new e.Vector3(1,0,0),new e.Vector3(-1,0,0),new e.Vector3(0,1,0),new e.Vector3(0,-1,0)],s=[],a=[],h=[],l=[],c=1,u=1,f=1,d=i.faceUV||new Array(6),p=[];i.faceColors&&(n=i.faceColors),void 0!==i.width?(c=i.width||1,u=i.height||1,f=i.depth||1):(c=i||1,u=i||1,f=i||1),r=r||i.sideOrientation||e.Mesh.DEFAULTSIDE;for(var m=0;6>m;m++)void 0===d[m]&&(d[m]=new e.Vector4(0,0,1,1)),n&&void 0===n[m]&&(n[m]=new e.Color4(1,1,1,1));for(var g=new e.Vector3(c/2,u/2,f/2),_=0;_<o.length;_++){var v=o[_],y=new e.Vector3(v.y,v.z,v.x),x=e.Vector3.Cross(v,y),M=a.length/3;s.push(M),s.push(M+1),s.push(M+2),s.push(M),s.push(M+2),s.push(M+3);var S=v.subtract(y).subtract(x).multiply(g);a.push(S.x,S.y,S.z),h.push(v.x,v.y,v.z),l.push(d[_].z,d[_].w),n&&p.push(n[_].r,n[_].g,n[_].b,n[_].a),S=v.subtract(y).add(x).multiply(g),a.push(S.x,S.y,S.z),h.push(v.x,v.y,v.z),l.push(d[_].x,d[_].w),n&&p.push(n[_].r,n[_].g,n[_].b,n[_].a),S=v.add(y).add(x).multiply(g),a.push(S.x,S.y,S.z),h.push(v.x,v.y,v.z),l.push(d[_].x,d[_].y),n&&p.push(n[_].r,n[_].g,n[_].b,n[_].a),S=v.add(y).subtract(x).multiply(g),a.push(S.x,S.y,S.z),h.push(v.x,v.y,v.z),l.push(d[_].z,d[_].y),n&&p.push(n[_].r,n[_].g,n[_].b,n[_].a)}t._ComputeSides(r,a,s,h,l);var b=new t;if(b.indices=s,b.positions=a,b.normals=h,b.uvs=l,n){var A=r===e.Mesh.DOUBLESIDE?p.concat(p):p;b.colors=A}return b},t.CreateSphere=function(i,r,n){void 0===n&&(n=e.Mesh.DEFAULTSIDE);var o,s,a,h;i.segments?(o=i.segments||32,s=i.diameterX||1,a=i.diameterY||1,h=i.diameterZ||1):(o=i||32,s=r||1,a=s,h=s),n=n||i.sideOrientation||e.Mesh.DEFAULTSIDE;for(var l=new e.Vector3(s/2,a/2,h/2),c=2+o,u=2*c,f=[],d=[],p=[],m=[],g=0;c>=g;g++){for(var _=g/c,v=_*Math.PI,y=0;u>=y;y++){var x=y/u,M=x*Math.PI*2,S=e.Matrix.RotationZ(-v),b=e.Matrix.RotationY(M),A=e.Vector3.TransformCoordinates(e.Vector3.Up(),S),T=e.Vector3.TransformCoordinates(A,b),E=T.multiply(l),P=e.Vector3.Normalize(E);d.push(E.x,E.y,E.z),p.push(P.x,P.y,P.z),m.push(_,x)}if(g>0)for(var D=d.length/3,C=D-2*(u+1);D>C+u+2;C++)f.push(C),f.push(C+1),f.push(C+u+1),f.push(C+u+1),f.push(C+1),f.push(C+u+2)}t._ComputeSides(n,d,f,p,m);var I=new t;return I.indices=f,I.positions=d,I.normals=p,I.uvs=m,I},t.CreateCylinder=function(i,r,n,o,s,a){void 0===s&&(s=1),void 0===a&&(a=e.Mesh.DEFAULTSIDE);var h,l,c,u,f,d=[],p=[],m=[],g=[],_=2*Math.PI/o,v=(n-r)/2/i,y=e.Vector3.Zero(),x=e.Vector3.Zero();for(u=0;s>=u;u++)for(l=u/s,c=(l*(r-n)+n)/2,f=0;o>=f;f++)h=f*_,y.x=Math.cos(-h)*c,y.y=-i/2+l*i,y.z=Math.sin(-h)*c,0===r&&u===s?(x.x=m[m.length-3*(o+1)],x.y=m[m.length-3*(o+1)+1],x.z=m[m.length-3*(o+1)+2]):(x.x=y.x,x.z=y.z,x.y=Math.sqrt(x.x*x.x+x.z*x.z)*v,x.normalize()),p.push(y.x,y.y,y.z),m.push(x.x,x.y,x.z),g.push(f/o,1-l);for(u=0;s>u;u++)for(f=0;o>f;f++){var M=u*(o+1)+f,S=(u+1)*(o+1)+f,b=u*(o+1)+(f+1),A=(u+1)*(o+1)+(f+1);d.push(M,S,b),d.push(A,b,S)}var T=function(t){var s=t?r/2:n/2;if(0!==s){var a,h,l,c=p.length/3,u=new e.Vector3(0,t?i/2:-i/2,0),f=new e.Vector2(.5,.5);for(l=0;o>l;l++){a=2*Math.PI*l/o,h=new e.Vector3(Math.cos(-a),0,Math.sin(-a));var _=h.scale(s).add(u),v=new e.Vector2(h.x*f.x+.5,h.z*f.y+.5);p.push(_.x,_.y,_.z),m.push(0,t?1:-1,0),g.push(v.x,v.y)}for(l=0;o-2>l;l++)t?(d.push(c),d.push(c+(l+2)%o),d.push(c+(l+1)%o)):(d.push(c),d.push(c+(l+1)%o),d.push(c+(l+2)%o))}};T(!0),T(!1),t._ComputeSides(a,p,d,m,g);var E=new t;return E.indices=d,E.positions=p,E.normals=m,E.uvs=g,E},t.CreateTorus=function(i,r,n,o){void 0===o&&(o=e.Mesh.DEFAULTSIDE);var s=[],a=[],h=[],l=[];i=i||1,r=r||.5,n=n||16;for(var c=n+1,u=0;n>=u;u++)for(var f=u/n,d=u*Math.PI*2/n-Math.PI/2,p=e.Matrix.Translation(i/2,0,0).multiply(e.Matrix.RotationY(d)),m=0;n>=m;m++){var g=1-m/n,_=m*Math.PI*2/n+Math.PI,v=Math.cos(_),y=Math.sin(_),x=new e.Vector3(v,y,0),M=x.scale(r/2),S=new e.Vector2(f,g);M=e.Vector3.TransformCoordinates(M,p),x=e.Vector3.TransformNormal(x,p),a.push(M.x,M.y,M.z),h.push(x.x,x.y,x.z),l.push(S.x,S.y);var b=(u+1)%c,A=(m+1)%c;s.push(u*c+m),s.push(u*c+A),s.push(b*c+m),s.push(u*c+A),s.push(b*c+A),s.push(b*c+m)}t._ComputeSides(o,a,s,h,l);var T=new t;return T.indices=s,T.positions=a,T.normals=h,T.uvs=l,T},t.CreateLines=function(e){for(var i=[],r=[],n=0;n<e.length;n++)r.push(e[n].x,e[n].y,e[n].z),n>0&&(i.push(n-1),i.push(n));var o=new t;return o.indices=i,o.positions=r,o},t.CreateDashedLines=function(i,r,n,o){r=r||3,n=n||1,o=o||200;var s=new Array,a=new Array,h=e.Vector3.Zero(),l=0,c=0,u=0,f=0,d=0,p=0,m=0;for(m=0;m<i.length-1;m++)i[m+1].subtractToRef(i[m],h),l+=h.length();for(u=l/o,f=r*u/(r+n),m=0;m<i.length-1;m++){i[m+1].subtractToRef(i[m],h),c=Math.floor(h.length()/u),h.normalize();for(var g=0;c>g;g++)d=u*g,s.push(i[m].x+d*h.x,i[m].y+d*h.y,i[m].z+d*h.z),s.push(i[m].x+(d+f)*h.x,i[m].y+(d+f)*h.y,i[m].z+(d+f)*h.z),a.push(p,p+1),p+=2}var _=new t;return _.positions=s,_.indices=a,_},t.CreateGround=function(i,r,n){var o,s,a,h=[],l=[],c=[],u=[];for(i.width?(a=i.width||1,r=i.height||1,n=i.subdivisions||1):(a=i||1,r=r||1,n=n||1),o=0;n>=o;o++)for(s=0;n>=s;s++){var f=new e.Vector3(s*a/n-a/2,0,(n-o)*r/n-r/2),d=new e.Vector3(0,1,0);l.push(f.x,f.y,f.z),c.push(d.x,d.y,d.z),u.push(s/n,1-o/n)}for(o=0;n>o;o++)for(s=0;n>s;s++)h.push(s+1+(o+1)*(n+1)),h.push(s+1+o*(n+1)),h.push(s+o*(n+1)),h.push(s+(o+1)*(n+1)),h.push(s+1+(o+1)*(n+1)),h.push(s+o*(n+1));var p=new t;return p.indices=h,p.positions=l,p.normals=c,p.uvs=u,p},t.CreateTiledGround=function(i,r,n,o,s,a){function h(t,i,r,n){var o=p.length/3,s=a.w+1;for(l=0;l<a.h;l++)for(c=0;c<a.w;c++){var h=[o+c+l*s,o+(c+1)+l*s,o+(c+1)+(l+1)*s,o+c+(l+1)*s];d.push(h[1]),d.push(h[2]),d.push(h[3]),d.push(h[0]),d.push(h[1]),d.push(h[3])}var u=e.Vector3.Zero(),f=new e.Vector3(0,1,0);for(l=0;l<=a.h;l++)for(u.z=l*(n-i)/a.h+i,c=0;c<=a.w;c++)u.x=c*(r-t)/a.w+t,u.y=0,p.push(u.x,u.y,u.z),m.push(f.x,f.y,f.z),g.push(c/a.w,l/a.h)}void 0===s&&(s={w:1,h:1}),void 0===a&&(a={w:1,h:1});var l,c,u,f,d=[],p=[],m=[],g=[];s.h=s.w<1?1:s.h,s.w=s.w<1?1:s.w,a.w=a.w<1?1:a.w,a.h=a.h<1?1:a.h;var _={w:(n-i)/s.w,h:(o-r)/s.h};for(u=0;u<s.h;u++)for(f=0;f<s.w;f++)h(i+f*_.w,r+u*_.h,i+(f+1)*_.w,r+(u+1)*_.h);var v=new t;return v.indices=d,v.positions=p,v.normals=m,v.uvs=g,v},t.CreateGroundFromHeightMap=function(i,r,n,o,s,a,h,l){var c,u,f=[],d=[],p=[],m=[];for(c=0;n>=c;c++)for(u=0;n>=u;u++){var g=new e.Vector3(u*i/n-i/2,0,(n-c)*r/n-r/2),_=(g.x+i/2)/i*(h-1)|0,v=(1-(g.z+r/2)/r)*(l-1)|0,y=4*(_+v*h),x=a[y]/255,M=a[y+1]/255,S=a[y+2]/255,b=.3*x+.59*M+.11*S;g.y=o+(s-o)*b,d.push(g.x,g.y,g.z),p.push(0,0,0),m.push(u/n,1-c/n)}for(c=0;n>c;c++)for(u=0;n>u;u++)f.push(u+1+(c+1)*(n+1)),f.push(u+1+c*(n+1)),f.push(u+c*(n+1)),f.push(u+(c+1)*(n+1)),f.push(u+1+(c+1)*(n+1)),f.push(u+c*(n+1));t.ComputeNormals(d,f,p);var A=new t;return A.indices=f,A.positions=d,A.normals=p,A.uvs=m,A},t.CreatePlane=function(i,r){void 0===r&&(r=e.Mesh.DEFAULTSIDE);var n,o,s=[],a=[],h=[],l=[];i.width?(n=i.width||1,o=i.height||1,r=i.sideOrientation||e.Mesh.DEFAULTSIDE):(n=i||1,o=i||1);var c=n/2,u=o/2;a.push(-c,-u,0),h.push(0,0,-1),l.push(0,0),a.push(c,-u,0),h.push(0,0,-1),l.push(1,0),a.push(c,u,0),h.push(0,0,-1),l.push(1,1),a.push(-c,u,0),h.push(0,0,-1),l.push(0,1),s.push(0),s.push(1),s.push(2),s.push(0),s.push(2),s.push(3),t._ComputeSides(r,a,s,h,l);var f=new t;return f.indices=s,f.positions=a,f.normals=h,f.uvs=l,f},t.CreateDisc=function(i,r,n){void 0===n&&(n=e.Mesh.DEFAULTSIDE);var o=[],s=[],a=[],h=[];o.push(0,0,0),h.push(.5,.5);for(var l=2*Math.PI/r,c=0;c<2*Math.PI;c+=l){var u=Math.cos(c),f=Math.sin(c),d=(u+1)/2,p=(1-f)/2;o.push(i*u,i*f,0),h.push(d,p)}o.push(o[3],o[4],o[5]),h.push(h[2],h[3]);for(var m=o.length/3,g=1;m-1>g;g++)s.push(g+1,0,g);t.ComputeNormals(o,s,a),t._ComputeSides(n,o,s,a,h);var _=new t;return _.indices=s,_.positions=o,_.normals=a,_.uvs=h,_},t.CreateTorusKnot=function(i,r,n,o,s,a,h){void 0===h&&(h=e.Mesh.DEFAULTSIDE);var l=[],c=[],u=[],f=[];i=i||2,r=r||.5,n=n||32,o=o||32,s=s||2,a=a||3;var d,p,m=function(t){var r=Math.cos(t),n=Math.sin(t),o=a/s*t,h=Math.cos(o),l=i*(2+h)*.5*r,c=i*(2+h)*n*.5,u=i*Math.sin(o)*.5;return new e.Vector3(l,c,u)};for(d=0;n>=d;d++){var g=d%n,_=g/n*2*s*Math.PI,v=m(_),y=m(_+.01),x=y.subtract(v),M=y.add(v),S=e.Vector3.Cross(x,M);for(M=e.Vector3.Cross(S,x),S.normalize(),M.normalize(),p=0;o>p;p++){var b=p%o,A=b/o*2*Math.PI,T=-r*Math.cos(A),E=r*Math.sin(A);c.push(v.x+T*M.x+E*S.x),c.push(v.y+T*M.y+E*S.y),c.push(v.z+T*M.z+E*S.z),f.push(d/n),f.push(p/o)}}for(d=0;n>d;d++)for(p=0;o>p;p++){var P=(p+1)%o,D=d*o+p,C=(d+1)*o+p,I=(d+1)*o+P,w=d*o+P;l.push(w),l.push(C),l.push(D),l.push(w),l.push(I),l.push(C)}t.ComputeNormals(c,l,u),t._ComputeSides(h,c,l,u,f);var R=new t;return R.indices=l,R.positions=c,R.normals=u,R.uvs=f,R},t.ComputeNormals=function(t,i,r){var n=0,o=e.Vector3.Zero(),s=e.Vector3.Zero(),a=e.Vector3.Zero(),h=e.Vector3.Zero();for(n=0;n<t.length;n++)r[n]=0;var l=i.length/3;for(n=0;l>n;n++){var c=i[3*n],u=i[3*n+1],f=i[3*n+2];o.x=t[3*c]-t[3*u],o.y=t[3*c+1]-t[3*u+1],o.z=t[3*c+2]-t[3*u+2],s.x=t[3*f]-t[3*u],s.y=t[3*f+1]-t[3*u+1],s.z=t[3*f+2]-t[3*u+2],e.Vector3.CrossToRef(o,s,a),a.normalize(),r[3*c]+=a.x,r[3*c+1]+=a.y,r[3*c+2]+=a.z,r[3*u]+=a.x,r[3*u+1]+=a.y,r[3*u+2]+=a.z,r[3*f]+=a.x,r[3*f+1]+=a.y,r[3*f+2]+=a.z}for(n=0;n<r.length/3;n++)e.Vector3.FromFloatsToRef(r[3*n],r[3*n+1],r[3*n+2],h),h.normalize(),r[3*n]=h.x,r[3*n+1]=h.y,r[3*n+2]=h.z},t._ComputeSides=function(t,i,r,n,o){var s,a,h=r.length,l=n.length;switch(t=t||e.Mesh.DEFAULTSIDE){case e.Mesh.FRONTSIDE:break;case e.Mesh.BACKSIDE:var c;for(s=0;h>s;s+=3)c=r[s],r[s]=r[s+2],r[s+2]=c;for(a=0;l>a;a++)n[a]=-n[a];break;case e.Mesh.DOUBLESIDE:for(var u=i.length,f=u/3,d=0;u>d;d++)i[u+d]=i[d];for(s=0;h>s;s+=3)r[s+h]=r[s+2]+f,r[s+1+h]=r[s+1]+f,r[s+2+h]=r[s]+f;for(a=0;l>a;a++)n[l+a]=-n[a];for(var p=o.length,m=0;p>m;m++)o[m+p]=o[m]}},t}();e.VertexData=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s){e.call(this,t,"anaglyph",null,["leftSampler"],i,r,n,o,s)}return __extends(t,e),t}(e.PostProcess);e.AnaglyphPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.EnableFor=function(e){e._tags=e._tags||{},e.hasTags=function(){return t.HasTags(e)},e.addTags=function(i){return t.AddTagsTo(e,i)},e.removeTags=function(i){return t.RemoveTagsFrom(e,i)},e.matchesTagsQuery=function(i){return t.MatchesQuery(e,i)}},t.DisableFor=function(e){delete e._tags,delete e.hasTags,delete e.addTags,delete e.removeTags,delete e.matchesTagsQuery},t.HasTags=function(t){return t._tags?!e.Tools.IsEmpty(t._tags):!1},t.GetTags=function(e){return e._tags?e._tags:null},t.AddTagsTo=function(e,i){if(i){var r=i.split(" ");for(var n in r)t._AddTagTo(e,r[n])}},t._AddTagTo=function(e,i){i=i.trim(),""!==i&&"true"!==i&&"false"!==i&&(i.match(/[\s]/)||i.match(/^([!]|([|]|[&]){2})/)||(t.EnableFor(e),e._tags[i]=!0))},t.RemoveTagsFrom=function(e,i){if(t.HasTags(e)){var r=i.split(" ");for(var n in r)t._RemoveTagFrom(e,r[n])}},t._RemoveTagFrom=function(e,t){delete e._tags[t]},t.MatchesQuery=function(i,r){return void 0===r?!0:""===r?t.HasTags(i):e.Internals.AndOrNotEvaluator.Eval(r,function(e){return t.HasTags(i)&&i._tags[e]})},t}();e.Tags=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function e(){}return e.Eval=function(t,i){return t=t.match(/\([^\(\)]*\)/g)?t.replace(/\([^\(\)]*\)/g,function(t){return t=t.slice(1,t.length-1),e._HandleParenthesisContent(t,i)}):e._HandleParenthesisContent(t,i),"true"===t?!0:"false"===t?!1:e.Eval(t,i)},e._HandleParenthesisContent=function(t,i){i=i||function(e){return"true"===e?!0:!1};var r,n=t.split("||");for(var o in n){var s=e._SimplifyNegation(n[o].trim()),a=s.split("&&");if(a.length>1)for(var h=0;h<a.length;++h){var l=e._SimplifyNegation(a[h].trim());if(r="true"!==l&&"false"!==l?"!"===l[0]?!i(l.substring(1)):i(l):"true"===l?!0:!1,!r){s="false";break}}if(r||"true"===s){r=!0;break}r="true"!==s&&"false"!==s?"!"===s[0]?!i(s.substring(1)):i(s):"true"===s?!0:!1}return r?"true":"false"},e._SimplifyNegation=function(e){return e=e.replace(/^[\s!]+/,function(e){return e=e.replace(/[\s]/g,function(){return""}),e.length%2?"!":""}),e=e.trim(),"!true"===e?e="false":"!false"===e&&(e="true"),e},e}();e.AndOrNotEvaluator=t}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n,o,s){this._enabled=!0,this._refCount=0,this._name=i,this._renderTexture=new e.RenderTargetTexture(i,r,t),this.setRenderList(n),this._renderTexture.onBeforeRender=o,this._renderTexture.onAfterRender=s,this._scene=t,this._renderList=n}return t.prototype._incRefCount=function(){return 0===this._refCount&&this._scene.customRenderTargets.push(this._renderTexture),++this._refCount},t.prototype._decRefCount=function(){return this._refCount--,this._refCount<=0&&this._scene.customRenderTargets.splice(this._scene.customRenderTargets.indexOf(this._renderTexture),1),this._refCount},t.prototype._update=function(){this.setRenderList(this._renderList)},t.prototype.setRenderList=function(e){this._renderTexture.renderList=e},t.prototype.getRenderTexture=function(){return this._renderTexture},t}();e.PostProcessRenderPass=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,r){this._engine=e,this._name=t,this._singleInstance=r||!0,this._getPostProcess=i,this._cameras=[],this._indicesForCamera=[],this._postProcesses={},this._renderPasses={},this._renderEffectAsPasses={}}return t.prototype._update=function(){for(var e in this._renderPasses)this._renderPasses[e]._update()},t.prototype.addPass=function(e){this._renderPasses[e._name]=e,this._linkParameters()},t.prototype.removePass=function(e){delete this._renderPasses[e._name],this._linkParameters()},t.prototype.addRenderEffectAsPass=function(e){this._renderEffectAsPasses[e._name]=e,this._linkParameters()},t.prototype.getPass=function(e){for(var t in this._renderPasses)if(t===e)return this._renderPasses[e]},t.prototype.emptyPasses=function(){this._renderPasses={},this._linkParameters()},t.prototype._attachCameras=function(t){for(var i,r=e.Tools.MakeArray(t||this._cameras),n=0;n<r.length;n++){var o=r[n],s=o.name;i=this._singleInstance?0:s,this._postProcesses[i]=this._postProcesses[i]||this._getPostProcess();var a=o.attachPostProcess(this._postProcesses[i]);this._indicesForCamera[s]||(this._indicesForCamera[s]=[]),this._indicesForCamera[s].push(a),-1===this._cameras.indexOf(o)&&(this._cameras[s]=o);for(var h in this._renderPasses)this._renderPasses[h]._incRefCount()}this._linkParameters()},t.prototype._detachCameras=function(t){for(var i=e.Tools.MakeArray(t||this._cameras),r=0;r<i.length;r++){var n=i[r],o=n.name;n.detachPostProcess(this._postProcesses[this._singleInstance?0:o],this._indicesForCamera[o]);var s=this._cameras.indexOf(o);this._indicesForCamera.splice(s,1),this._cameras.splice(s,1);for(var a in this._renderPasses)this._renderPasses[a]._decRefCount()}},t.prototype._enable=function(t){for(var i=e.Tools.MakeArray(t||this._cameras),r=0;r<i.length;r++){for(var n=i[r],o=n.name,s=0;s<this._indicesForCamera[o].length;s++)void 0===n._postProcesses[this._indicesForCamera[o][s]]&&t[r].attachPostProcess(this._postProcesses[this._singleInstance?0:o],this._indicesForCamera[o][s]);for(var a in this._renderPasses)this._renderPasses[a]._incRefCount()}},t.prototype._disable=function(t){for(var i=e.Tools.MakeArray(t||this._cameras),r=0;r<i.length;r++){var n=i[r],o=n.Name;n.detachPostProcess(this._postProcesses[this._singleInstance?0:o],this._indicesForCamera[o]);for(var s in this._renderPasses)this._renderPasses[s]._decRefCount()}},t.prototype.getPostProcess=function(e){return this._singleInstance?this._postProcesses[0]:this._postProcesses[e.name]},t.prototype._linkParameters=function(){var e=this;for(var t in this._postProcesses)this.applyParameters&&this.applyParameters(this._postProcesses[t]),this._postProcesses[t].onBeforeRender=function(t){e._linkTextures(t)}},t.prototype._linkTextures=function(e){for(var t in this._renderPasses)e.setTexture(t,this._renderPasses[t].getRenderTexture());for(var i in this._renderEffectAsPasses)e.setTextureFromPostProcess(i+"Sampler",this._renderEffectAsPasses[i].getPostProcess())},t}();e.PostProcessRenderEffect=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t){this._engine=e,this._name=t,this._renderEffects={},this._renderEffectsForIsolatedPass={},this._cameras=[]}return t.prototype.addEffect=function(e){this._renderEffects[e._name]=e},t.prototype._enableEffect=function(t,i){var r=this._renderEffects[t];r&&r._enable(e.Tools.MakeArray(i||this._cameras))},t.prototype._disableEffect=function(t,i){var r=this._renderEffects[t];r&&r._disable(e.Tools.MakeArray(i||this._cameras))},t.prototype._attachCameras=function(t,i){for(var r=e.Tools.MakeArray(t||this._cameras),n=[],o=0;o<r.length;o++){var s=r[o],a=s.name;-1===this._cameras.indexOf(s)?this._cameras[a]=s:i&&n.push(o)}for(var o=0;o<n.length;o++)t.splice(n[o],1);for(var h in this._renderEffects)this._renderEffects[h]._attachCameras(r)},t.prototype._detachCameras=function(t){var i=e.Tools.MakeArray(t||this._cameras);for(var r in this._renderEffects)this._renderEffects[r]._detachCameras(i);for(var n=0;n<i.length;n++)this._cameras.splice(this._cameras.indexOf(i[n]),1)},t.prototype._enableDisplayOnlyPass=function(i,r){var n=this,o=e.Tools.MakeArray(r||this._cameras),s=null;for(var a in this._renderEffects)if(s=this._renderEffects[a].getPass(i),null!=s)break;if(null!==s){for(var a in this._renderEffects)this._renderEffects[a]._disable(o);s._name=t.PASS_SAMPLER_NAME;for(var h=0;h<o.length;h++){var l=o[h],c=l.name;this._renderEffectsForIsolatedPass[c]=this._renderEffectsForIsolatedPass[c]||new e.PostProcessRenderEffect(this._engine,t.PASS_EFFECT_NAME,function(){return new e.DisplayPassPostProcess(t.PASS_EFFECT_NAME,1,null,null,n._engine,!0)}),this._renderEffectsForIsolatedPass[c].emptyPasses(),this._renderEffectsForIsolatedPass[c].addPass(s),this._renderEffectsForIsolatedPass[c]._attachCameras(l)}}},t.prototype._disableDisplayOnlyPass=function(i){for(var r=this,n=e.Tools.MakeArray(i||this._cameras),o=0;o<n.length;o++){var s=n[o],a=s.name;this._renderEffectsForIsolatedPass[a]=this._renderEffectsForIsolatedPass[a]||new e.PostProcessRenderEffect(this._engine,t.PASS_EFFECT_NAME,function(){return new e.DisplayPassPostProcess(t.PASS_EFFECT_NAME,1,null,null,r._engine,!0)}),this._renderEffectsForIsolatedPass[a]._disable(s)}for(var h in this._renderEffects)this._renderEffects[h]._enable(n)},t.prototype._update=function(){for(var e in this._renderEffects)this._renderEffects[e]._update();for(var t=0;t<this._cameras.length;t++){var i=this._cameras[t].name;this._renderEffectsForIsolatedPass[i]&&this._renderEffectsForIsolatedPass[i]._update()}},t.PASS_EFFECT_NAME="passEffect",t.PASS_SAMPLER_NAME="passSampler",t}();e.PostProcessRenderPipeline=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._renderPipelines={}}return e.prototype.addPipeline=function(e){this._renderPipelines[e._name]=e},e.prototype.attachCamerasToRenderPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._attachCameras(t,i)},e.prototype.detachCamerasFromRenderPipeline=function(e,t){var i=this._renderPipelines[e];i&&i._detachCameras(t)},e.prototype.enableEffectInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._enableEffect(t,i)},e.prototype.disableEffectInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._disableEffect(t,i)},e.prototype.enableDisplayOnlyPassInPipeline=function(e,t,i){var r=this._renderPipelines[e];r&&r._enableDisplayOnlyPass(t,i)},e.prototype.disableDisplayOnlyPassInPipeline=function(e,t){var i=this._renderPipelines[e];i&&i._disableDisplayOnlyPass(t)},e.prototype.update=function(){for(var e in this._renderPipelines)this._renderPipelines[e]._update()},e}();e.PostProcessRenderPipelineManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s){e.call(this,t,"displayPass",["passSampler"],["passSampler"],i,r,n,o,s)}return __extends(t,e),t}(e.PostProcess);e.DisplayPassPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.frontColor=new e.Color3(1,1,1),this.backColor=new e.Color3(.1,.1,.1),this.showBackLines=!0,this.renderList=new e.SmartArray(32),this._scene=t}return t.prototype._prepareRessources=function(){if(!this._colorShader){this._colorShader=new e.ShaderMaterial("colorShader",this._scene,"color",{attributes:["position"],uniforms:["worldViewProjection","color"]});var t=this._scene.getEngine(),i=e.VertexData.CreateBox(1);this._vb=new e.VertexBuffer(t,i.positions,e.VertexBuffer.PositionKind,!1),this._ib=t.createIndexBuffer([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,7,1,6,2,5,3,4])}},t.prototype.reset=function(){this.renderList.reset()},t.prototype.render=function(){if(0!==this.renderList.length&&(this._prepareRessources(),this._colorShader.isReady())){var t=this._scene.getEngine();t.setDepthWrite(!1),this._colorShader._preBind();for(var i=0;i<this.renderList.length;i++){var r=this.renderList.data[i],n=r.minimum,o=r.maximum,s=o.subtract(n),a=n.add(s.scale(.5)),h=e.Matrix.Scaling(s.x,s.y,s.z).multiply(e.Matrix.Translation(a.x,a.y,a.z)).multiply(r.getWorldMatrix());t.bindBuffers(this._vb.getBuffer(),this._ib,[3],12,this._colorShader.getEffect()),this.showBackLines&&(t.setDepthFunctionToGreaterOrEqual(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.backColor.toColor4()),this._colorShader.bind(h),t.draw(!1,0,24)),t.setDepthFunctionToLess(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.frontColor.toColor4()),this._colorShader.bind(h),t.draw(!1,0,24)}this._colorShader.unbind(),t.setDepthFunctionToLessOrEqual(),t.setDepthWrite(!0)}},t.prototype.dispose=function(){this._colorShader&&(this._colorShader.dispose(),this._vb.dispose(),this._scene.getEngine()._releaseBuffer(this._ib))},t}();e.BoundingBoxRenderer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){this._actionManager=e}return e.prototype.isValid=function(){return!0},e.prototype._getProperty=function(e){return this._actionManager._getProperty(e)},e.prototype._getEffectiveTarget=function(e,t){return this._actionManager._getEffectiveTarget(e,t)},e}();e.Condition=t;var i=function(e){function t(i,r,n,o,s){void 0===s&&(s=t.IsEqual),e.call(this,i),this.propertyPath=n,this.value=o,this.operator=s,this._target=this._getEffectiveTarget(r,this.propertyPath),this._property=this._getProperty(this.propertyPath)}return __extends(t,e),Object.defineProperty(t,"IsEqual",{get:function(){return t._IsEqual},enumerable:!0,configurable:!0}),Object.defineProperty(t,"IsDifferent",{get:function(){return t._IsDifferent},enumerable:!0,configurable:!0}),Object.defineProperty(t,"IsGreater",{get:function(){return t._IsGreater},enumerable:!0,configurable:!0}),Object.defineProperty(t,"IsLesser",{get:function(){return t._IsLesser},enumerable:!0,configurable:!0}),t.prototype.isValid=function(){switch(this.operator){case t.IsGreater:return this._target[this._property]>this.value;case t.IsLesser:return this._target[this._property]<this.value;case t.IsEqual:case t.IsDifferent:var e;return e=this.value.equals?this.value.equals(this._target[this._property]):this.value===this._target[this._property],this.operator===t.IsEqual?e:!e}return!1},t._IsEqual=0,t._IsDifferent=1,t._IsGreater=2,t._IsLesser=3,t}(t);e.ValueCondition=i;var r=function(e){function t(t,i){e.call(this,t),this.predicate=i}return __extends(t,e),t.prototype.isValid=function(){return this.predicate()},t}(t);e.PredicateCondition=r;var n=function(e){function t(t,i,r){e.call(this,t),this.value=r,this._target=i}return __extends(t,e),t.prototype.isValid=function(){return this._target.state===this.value},t}(t);e.StateCondition=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t){this.triggerOptions=e,e.parameter?(this.trigger=e.trigger,this._triggerParameter=e.parameter):this.trigger=e,this._nextActiveAction=this,this._condition=t}return e.prototype._prepare=function(){},e.prototype.getTriggerParameter=function(){return this._triggerParameter},e.prototype._executeCurrent=function(e){if(this._nextActiveAction._condition){var t=this._nextActiveAction._condition,i=this._actionManager.getScene().getRenderId();if(t._evaluationId===i){if(!t._currentResult)return}else{if(t._evaluationId=i,!t.isValid())return void(t._currentResult=!1);t._currentResult=!0}}this._nextActiveAction.execute(e),this._nextActiveAction._child?(this._nextActiveAction._child._actionManager||(this._nextActiveAction._child._actionManager=this._actionManager),this._nextActiveAction=this._nextActiveAction._child):this._nextActiveAction=this},e.prototype.execute=function(e){},e.prototype.then=function(e){return this._child=e,e._actionManager=this._actionManager,e._prepare(),e},e.prototype._getProperty=function(e){return this._actionManager._getProperty(e)},e.prototype._getEffectiveTarget=function(e,t){return this._actionManager._getEffectiveTarget(e,t)},e}();e.Action=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,i,r,n,o){this.source=e,this.pointerX=t,this.pointerY=i,this.meshUnderPointer=r,this.sourceEvent=n,this.additionalData=o}return e.CreateNew=function(t,i,r){var n=t.getScene();return new e(t,n.pointerX,n.pointerY,n.meshUnderPointer,i,r)},e.CreateNewFromScene=function(t,i){return new e(null,t.pointerX,t.pointerY,t.meshUnderPointer,i)},e}();e.ActionEvent=t;var i=function(){function t(e){this.actions=new Array,this._scene=e,e._actionManagers.push(this)}return Object.defineProperty(t,"NothingTrigger",{get:function(){return t._NothingTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickTrigger",{get:function(){return t._OnPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnLeftPickTrigger",{get:function(){return t._OnLeftPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnRightPickTrigger",{get:function(){return t._OnRightPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnCenterPickTrigger",{get:function(){return t._OnCenterPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPointerOverTrigger",{get:function(){return t._OnPointerOverTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPointerOutTrigger",{get:function(){return t._OnPointerOutTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnEveryFrameTrigger",{get:function(){return t._OnEveryFrameTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnIntersectionEnterTrigger",{get:function(){return t._OnIntersectionEnterTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnIntersectionExitTrigger",{get:function(){return t._OnIntersectionExitTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnKeyDownTrigger",{get:function(){return t._OnKeyDownTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnKeyUpTrigger",{get:function(){return t._OnKeyUpTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(t,"OnPickUpTrigger",{get:function(){return t._OnPickUpTrigger},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){var e=this._scene._actionManagers.indexOf(this);
  
  e>-1&&this._scene._actionManagers.splice(e,1)},t.prototype.getScene=function(){return this._scene},t.prototype.hasSpecificTriggers=function(e){for(var t=0;t<this.actions.length;t++){var i=this.actions[t];if(e.indexOf(i.trigger)>-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t<this.actions.length;t++){var i=this.actions[t];if(i.trigger===e)return!0}return!1},Object.defineProperty(t.prototype,"hasPointerTriggers",{get:function(){for(var e=0;e<this.actions.length;e++){var i=this.actions[e];if(i.trigger>=t._OnPickTrigger&&i.trigger<=t._OnPointerOutTrigger)return!0;if(i.trigger==t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasPickTriggers",{get:function(){for(var e=0;e<this.actions.length;e++){var i=this.actions[e];if(i.trigger>=t._OnPickTrigger&&i.trigger<=t._OnCenterPickTrigger)return!0}return!1},enumerable:!0,configurable:!0}),t.prototype.registerAction=function(i){return i.trigger===t.OnEveryFrameTrigger&&this.getScene().actionManager!==this?(e.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager"),null):(this.actions.push(i),i._actionManager=this,i._prepare(),i)},t.prototype.processTrigger=function(e,i){for(var r=0;r<this.actions.length;r++){var n=this.actions[r];if(n.trigger===e){if(e===t.OnKeyUpTrigger||e===t.OnKeyDownTrigger){var o=n.getTriggerParameter();if(o){var s=i.sourceEvent.charCode?i.sourceEvent.charCode:i.sourceEvent.keyCode,a=String.fromCharCode(s).toLowerCase();if(a!==o.toLowerCase())continue}}n._executeCurrent(i)}}},t.prototype._getEffectiveTarget=function(e,t){for(var i=t.split("."),r=0;r<i.length-1;r++)e=e[i[r]];return e},t.prototype._getProperty=function(e){var t=e.split(".");return t[t.length-1]},t._NothingTrigger=0,t._OnPickTrigger=1,t._OnLeftPickTrigger=2,t._OnRightPickTrigger=3,t._OnCenterPickTrigger=4,t._OnPointerOverTrigger=5,t._OnPointerOutTrigger=6,t._OnEveryFrameTrigger=7,t._OnIntersectionEnterTrigger=8,t._OnIntersectionExitTrigger=9,t._OnKeyDownTrigger=10,t._OnKeyUpTrigger=11,t._OnPickUpTrigger=12,t}();e.ActionManager=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r,n,o,s,a){void 0===o&&(o=1e3),t.call(this,e,s),this.propertyPath=r,this.value=n,this.duration=o,this.stopOtherAnimations=a,this._target=i}return __extends(i,t),i.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},i.prototype.execute=function(){var t,i=this._actionManager.getScene(),r=[{frame:0,value:this._target[this._property]},{frame:100,value:this.value}];if("number"==typeof this.value)t=e.Animation.ANIMATIONTYPE_FLOAT;else if(this.value instanceof e.Color3)t=e.Animation.ANIMATIONTYPE_COLOR3;else if(this.value instanceof e.Vector3)t=e.Animation.ANIMATIONTYPE_VECTOR3;else if(this.value instanceof e.Matrix)t=e.Animation.ANIMATIONTYPE_MATRIX;else{if(!(this.value instanceof e.Quaternion))return void e.Tools.Warn("InterpolateValueAction: Unsupported type ("+typeof this.value+")");t=e.Animation.ANIMATIONTYPE_QUATERNION}var n=new e.Animation("InterpolateValueAction",this._property,100*(1e3/this.duration),t,e.Animation.ANIMATIONLOOPMODE_CONSTANT);n.setKeys(r),this.stopOtherAnimations&&i.stopAnimation(this._target),i.beginDirectAnimation(this._target,[n],0,100)},i}(e.Action);e.InterpolateValueAction=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n){e.call(this,t,n),this.propertyPath=r,this._target=i}return __extends(t,e),t.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},t.prototype.execute=function(){this._target[this._property]=!this._target[this._property]},t}(e.Action);e.SwitchBooleanAction=t;var i=function(e){function t(t,i,r,n){e.call(this,t,n),this.value=r,this._target=i}return __extends(t,e),t.prototype.execute=function(){this._target.state=this.value},t}(e.Action);e.SetStateAction=i;var r=function(e){function t(t,i,r,n,o){e.call(this,t,o),this.propertyPath=r,this.value=n,this._target=i}return __extends(t,e),t.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},t.prototype.execute=function(){this._target[this._property]=this.value},t}(e.Action);e.SetValueAction=r;var n=function(t){function i(e,i,r,n,o){t.call(this,e,o),this.propertyPath=r,this.value=n,this._target=i}return __extends(i,t),i.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath),"number"!=typeof this._target[this._property]&&e.Tools.Warn("Warning: IncrementValueAction can only be used with number values")},i.prototype.execute=function(){this._target[this._property]+=this.value},i}(e.Action);e.IncrementValueAction=n;var o=function(e){function t(t,i,r,n,o,s){e.call(this,t,s),this.from=r,this.to=n,this.loop=o,this._target=i}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){var e=this._actionManager.getScene();e.beginAnimation(this._target,this.from,this.to,this.loop)},t}(e.Action);e.PlayAnimationAction=o;var s=function(e){function t(t,i,r){e.call(this,t,r),this._target=i}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){var e=this._actionManager.getScene();e.stopAnimation(this._target)},t}(e.Action);e.StopAnimationAction=s;var a=function(t){function i(i,r){void 0===i&&(i=e.ActionManager.NothingTrigger),t.call(this,i,r)}return __extends(i,t),i.prototype.execute=function(){},i}(e.Action);e.DoNothingAction=a;var h=function(e){function t(t,i,r){e.call(this,t,r),this.children=i}return __extends(t,e),t.prototype._prepare=function(){for(var e=0;e<this.children.length;e++)this.children[e]._actionManager=this._actionManager,this.children[e]._prepare()},t.prototype.execute=function(e){for(var t=0;t<this.children.length;t++)this.children[t].execute(e)},t}(e.Action);e.CombineAction=h;var l=function(e){function t(t,i,r){e.call(this,t,r),this.func=i}return __extends(t,e),t.prototype.execute=function(e){this.func(e)},t}(e.Action);e.ExecuteCodeAction=l;var c=function(t){function i(e,i,r,n){t.call(this,e,n),this._target=i,this._parent=r}return __extends(i,t),i.prototype._prepare=function(){},i.prototype.execute=function(){if(this._target.parent!==this._parent){var t=this._parent.getWorldMatrix().clone();t.invert(),this._target.position=e.Vector3.TransformCoordinates(this._target.position,t),this._target.parent=this._parent}},i}(e.Action);e.SetParentAction=c;var u=function(e){function t(t,i,r){e.call(this,t,r),this._sound=i}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.play()},t}(e.Action);e.PlaySoundAction=u;var f=function(e){function t(t,i,r){e.call(this,t,r),this._sound=i}return __extends(t,e),t.prototype._prepare=function(){},t.prototype.execute=function(){void 0!==this._sound&&this._sound.stop()},t}(e.Action);e.StopSoundAction=f}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n,o){this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this._totalVertices=0,this._indices=[],this._isDisposed=!1,this.id=t,this._engine=i.getEngine(),this._meshes=[],this._scene=i,r?this.setAllVerticesData(r,n):(this._totalVertices=0,this._indices=[]),o&&(this.applyToMesh(o),o.computeWorldMatrix(!0))}return t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._engine},t.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_LOADED||this.delayLoadState===e.Engine.DELAYLOADSTATE_NONE},t.prototype.setAllVerticesData=function(e,t){e.applyToGeometry(this,t),this.notifyUpdate()},t.prototype.setVerticesData=function(t,i,r,n){if(this._vertexBuffers=this._vertexBuffers||{},this._vertexBuffers[t]&&this._vertexBuffers[t].dispose(),this._vertexBuffers[t]=new e.VertexBuffer(this._engine,i,t,r,0===this._meshes.length,n),t===e.VertexBuffer.PositionKind){n=this._vertexBuffers[t].getStrideSize(),this._totalVertices=i.length/n;for(var o=e.Tools.ExtractMinAndMax(i,0,this._totalVertices),s=this._meshes,a=s.length,h=0;a>h;h++){var l=s[h];l._resetPointsArrayCache(),l._boundingInfo=new e.BoundingInfo(o.minimum,o.maximum),l._createGlobalSubMesh(),l.computeWorldMatrix(!0)}}this.notifyUpdate(t)},t.prototype.updateVerticesDataDirectly=function(e,t,i){var r=this.getVertexBuffer(e);r&&(r.updateDirectly(t,i),this.notifyUpdate(e))},t.prototype.updateVerticesData=function(t,i,r){var n=this.getVertexBuffer(t);if(n){if(n.update(i),t===e.VertexBuffer.PositionKind){var o,s=n.getStrideSize();this._totalVertices=i.length/s,r&&(o=e.Tools.ExtractMinAndMax(i,0,this._totalVertices));for(var a=this._meshes,h=a.length,l=0;h>l;l++){var c=a[l];if(c._resetPointsArrayCache(),r){c._boundingInfo=new e.BoundingInfo(o.minimum,o.maximum);for(var u=0;u<c.subMeshes.length;u++){var f=c.subMeshes[u];f.refreshBoundingInfo()}}}}this.notifyUpdate(t)}},t.prototype.getTotalVertices=function(){return this.isReady()?this._totalVertices:0},t.prototype.getVerticesData=function(e,t){var i=this.getVertexBuffer(e);if(!i)return null;var r=i.getData();if(t&&1!==this._meshes.length){for(var n=r.length,o=[],s=0;n>s;s++)o.push(r[s]);return o}return r},t.prototype.getVertexBuffer=function(e){return this.isReady()?this._vertexBuffers[e]:null},t.prototype.getVertexBuffers=function(){return this.isReady()?this._vertexBuffers:null},t.prototype.isVerticesDataPresent=function(e){return this._vertexBuffers?void 0!==this._vertexBuffers[e]:this._delayInfo?-1!==this._delayInfo.indexOf(e):!1},t.prototype.getVerticesDataKinds=function(){var e=[];if(!this._vertexBuffers&&this._delayInfo)for(var t in this._delayInfo)e.push(t);else for(t in this._vertexBuffers)e.push(t);return e},t.prototype.setIndices=function(e,t){this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indices=e,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),void 0!==t&&(this._totalVertices=t);for(var i=this._meshes,r=i.length,n=0;r>n;n++)i[n]._createGlobalSubMesh();this.notifyUpdate()},t.prototype.getTotalIndices=function(){return this.isReady()?this._indices.length:0},t.prototype.getIndices=function(e){if(!this.isReady())return null;var t=this._indices;if(e&&1!==this._meshes.length){for(var i=t.length,r=[],n=0;i>n;n++)r.push(t[n]);return r}return t},t.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},t.prototype.releaseForMesh=function(e,t){var i=this._meshes,r=i.indexOf(e);if(-1!==r){for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),i.splice(r,1),e._geometry=null,0===i.length&&t&&this.dispose()}},t.prototype.applyToMesh=function(e){if(e._geometry!==this){var t=e._geometry;t&&t.releaseForMesh(e);var i=this._meshes;e._geometry=this,this._scene.pushGeometry(this),i.push(e),this.isReady()?this._applyToMesh(e):e._boundingInfo=this._boundingInfo}},t.prototype._applyToMesh=function(t){var i=this._meshes.length;for(var r in this._vertexBuffers)if(1===i&&this._vertexBuffers[r].create(),this._vertexBuffers[r]._buffer.references=i,r===e.VertexBuffer.PositionKind){t._resetPointsArrayCache();var n=e.Tools.ExtractMinAndMax(this._vertexBuffers[r].getData(),0,this._totalVertices);t._boundingInfo=new e.BoundingInfo(n.minimum,n.maximum),t._createGlobalSubMesh(),t._updateBoundingInfo()}1===i&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=i)},t.prototype.notifyUpdate=function(e){this.onGeometryUpdated&&this.onGeometryUpdated(this,e)},t.prototype.load=function(t,i){var r=this;if(this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING){if(this.isReady())return void(i&&i());this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,t._addPendingData(this),e.Tools.LoadFile(this.delayLoadingFile,function(n){r._delayLoadingFunction(JSON.parse(n),r),r.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,r._delayInfo=[],t._removePendingData(r);for(var o=r._meshes,s=o.length,a=0;s>a;a++)r._applyToMesh(o[a]);i&&i()},function(){},t.database)}},t.prototype.isDisposed=function(){return this._isDisposed},t.prototype.dispose=function(){var t,i=this._meshes,r=i.length;for(t=0;r>t;t++)this.releaseForMesh(i[t]);this._meshes=[];for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._vertexBuffers=[],this._totalVertices=0,this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indexBuffer=null,this._indices=[],this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.delayLoadingFile=null,this._delayLoadingFunction=null,this._delayInfo=[],this._boundingInfo=null,this._scene.removeGeometry(this),this._isDisposed=!0},t.prototype.copy=function(i){var r=new e.VertexData;r.indices=[];for(var n=this.getIndices(),o=0;o<n.length;o++)r.indices.push(n[o]);var s=!1,a=!1;for(var h in this._vertexBuffers)r.set(this.getVerticesData(h).slice(0),h),a||(s=this.getVertexBuffer(h).isUpdatable(),a=!s);var l=new t(i,this._scene,r,s,null);l.delayLoadState=this.delayLoadState,l.delayLoadingFile=this.delayLoadingFile,l._delayLoadingFunction=this._delayLoadingFunction;for(h in this._delayInfo)l._delayInfo=l._delayInfo||[],l._delayInfo.push(h);var c=e.Tools.ExtractMinAndMax(this.getVerticesData(e.VertexBuffer.PositionKind),0,this.getTotalVertices());return l._boundingInfo=new e.BoundingInfo(c.minimum,c.maximum),l},t.ExtractFromMesh=function(e,t){var i=e._geometry;return i?i.copy(t):null},t.RandomId=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,i="x"===e?t:3&t|8;return i.toString(16)})},t}();e.Geometry=t;var t;!function(t){var i;!function(i){var r=function(e){function t(t,i,r,n,o){this._beingRegenerated=!0,this._canBeRegenerated=n,e.call(this,t,i,r,!1,o),this._beingRegenerated=!1}return __extends(t,e),t.prototype.canBeRegenerated=function(){return this._canBeRegenerated},t.prototype.regenerate=function(){this._canBeRegenerated&&(this._beingRegenerated=!0,this.setAllVerticesData(this._regenerateVertexData(),!1),this._beingRegenerated=!1)},t.prototype.asNewGeometry=function(t){return e.prototype.copy.call(this,t)},t.prototype.setAllVerticesData=function(t,i){this._beingRegenerated&&e.prototype.setAllVerticesData.call(this,t,!1)},t.prototype.setVerticesData=function(t,i,r){this._beingRegenerated&&e.prototype.setVerticesData.call(this,t,i,!1)},t.prototype._regenerateVertexData=function(){throw new Error("Abstract method")},t.prototype.copy=function(e){throw new Error("Must be overriden in sub-classes.")},t}(t);i._Primitive=r;var n=function(t){function i(i,r,n,o,s,a,h,l,c){void 0===c&&(c=e.Mesh.DEFAULTSIDE),this.pathArray=n,this.closeArray=o,this.closePath=s,this.offset=a,this.side=c,t.call(this,i,r,this._regenerateVertexData(),h,l)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateRibbon(this.pathArray,this.closeArray,this.closePath,this.offset,this.side)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.pathArray,this.closeArray,this.closePath,this.offset,this.canBeRegenerated(),null,this.side)},i}(r);i.Ribbon=n;var o=function(t){function i(i,r,n,o,s,a){void 0===a&&(a=e.Mesh.DEFAULTSIDE),this.size=n,this.side=a,t.call(this,i,r,this._regenerateVertexData(),o,s)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateBox(this.size,this.side)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},i}(r);i.Box=o;var s=function(t){function i(i,r,n,o,s,a,h){void 0===h&&(h=e.Mesh.DEFAULTSIDE),this.segments=n,this.diameter=o,this.side=h,t.call(this,i,r,this._regenerateVertexData(),s,a)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateSphere(this.segments,this.diameter,this.side)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.segments,this.diameter,this.canBeRegenerated(),null,this.side)},i}(r);i.Sphere=s;var a=function(t){function i(i,r,n,o,s,a,h,l,c,u){void 0===h&&(h=1),void 0===u&&(u=e.Mesh.DEFAULTSIDE),this.height=n,this.diameterTop=o,this.diameterBottom=s,this.tessellation=a,this.subdivisions=h,this.side=u,t.call(this,i,r,this._regenerateVertexData(),l,c)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateCylinder(this.height,this.diameterTop,this.diameterBottom,this.tessellation,this.subdivisions,this.side)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.height,this.diameterTop,this.diameterBottom,this.tessellation,this.subdivisions,this.canBeRegenerated(),null,this.side)},i}(r);i.Cylinder=a;var h=function(t){function i(i,r,n,o,s,a,h,l){void 0===l&&(l=e.Mesh.DEFAULTSIDE),this.diameter=n,this.thickness=o,this.tessellation=s,this.side=l,t.call(this,i,r,this._regenerateVertexData(),a,h)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateTorus(this.diameter,this.thickness,this.tessellation,this.side)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.diameter,this.thickness,this.tessellation,this.canBeRegenerated(),null,this.side)},i}(r);i.Torus=h;var l=function(t){function i(e,i,r,n,o,s,a){this.width=r,this.height=n,this.subdivisions=o,t.call(this,e,i,this._regenerateVertexData(),s,a)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateGround(this.width,this.height,this.subdivisions)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.width,this.height,this.subdivisions,this.canBeRegenerated(),null)},i}(r);i.Ground=l;var c=function(t){function i(e,i,r,n,o,s,a,h,l,c){this.xmin=r,this.zmin=n,this.xmax=o,this.zmax=s,this.subdivisions=a,this.precision=h,t.call(this,e,i,this._regenerateVertexData(),l,c)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateTiledGround(this.xmin,this.zmin,this.xmax,this.zmax,this.subdivisions,this.precision)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.xmin,this.zmin,this.xmax,this.zmax,this.subdivisions,this.precision,this.canBeRegenerated(),null)},i}(r);i.TiledGround=c;var u=function(t){function i(i,r,n,o,s,a){void 0===a&&(a=e.Mesh.DEFAULTSIDE),this.size=n,this.side=a,t.call(this,i,r,this._regenerateVertexData(),o,s)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreatePlane(this.size,this.side)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},i}(r);i.Plane=u;var f=function(t){function i(i,r,n,o,s,a,h,l,c,u,f){void 0===f&&(f=e.Mesh.DEFAULTSIDE),this.radius=n,this.tube=o,this.radialSegments=s,this.tubularSegments=a,this.p=h,this.q=l,this.side=f,t.call(this,i,r,this._regenerateVertexData(),c,u)}return __extends(i,t),i.prototype._regenerateVertexData=function(){return e.VertexData.CreateTorusKnot(this.radius,this.tube,this.radialSegments,this.tubularSegments,this.p,this.q,this.side)},i.prototype.copy=function(e){return new i(e,this.getScene(),this.radius,this.tube,this.radialSegments,this.tubularSegments,this.p,this.q,this.canBeRegenerated(),null,this.side)},i}(r);i.TorusKnot=f}(i=t.Primitives||(t.Primitives={}))}(t=e.Geometry||(e.Geometry={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r){t.call(this,i,r),this.generateOctree=!1,this._worldInverse=new e.Matrix}return __extends(i,t),Object.defineProperty(i.prototype,"subdivisions",{get:function(){return this._subdivisions},enumerable:!0,configurable:!0}),i.prototype.optimize=function(e,t){void 0===t&&(t=32),this._subdivisions=e,this.subdivide(this._subdivisions),this.createOrUpdateSubmeshesOctree(t)},i.prototype.getHeightAtCoordinates=function(t,i){var r=new e.Ray(new e.Vector3(t,this.getBoundingInfo().boundingBox.maximumWorld.y+1,i),new e.Vector3(0,-1,0));this.getWorldMatrix().invertToRef(this._worldInverse),r=e.Ray.Transform(r,this._worldInverse);var n=this.intersects(r);return n.hit?n.pickedPoint.y:0},i}(e.Mesh);e.GroundMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s){void 0===n&&(n=null),t.call(this,i,r,n,o,s),this.color=new e.Color3(1,1,1),this.alpha=1,this._colorShader=new e.ShaderMaterial("colorShader",r,"color",{attributes:["position"],uniforms:["worldViewProjection","color"],needAlphaBlending:!0})}return __extends(i,t),Object.defineProperty(i.prototype,"material",{get:function(){return this._colorShader},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"isPickable",{get:function(){return!1},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"checkCollisions",{get:function(){return!1},enumerable:!0,configurable:!0}),i.prototype._bind=function(t,i,r){var n=this.getScene().getEngine(),o=this._geometry.getIndexBuffer();n.bindBuffers(this._geometry.getVertexBuffer(e.VertexBuffer.PositionKind).getBuffer(),o,[3],12,this._colorShader.getEffect()),this._colorShader.setColor4("color",this.color.toColor4(this.alpha))},i.prototype._draw=function(e,t,i){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var r=this.getScene().getEngine();r.draw(!1,e.indexStart,e.indexCount)}},i.prototype.intersects=function(e,t){return null},i.prototype.dispose=function(e){this._colorShader.dispose(),t.prototype.dispose.call(this,e)},i.prototype.clone=function(e,t,r){return new i(e,this.getScene(),t,this,r)},i}(e.Mesh);e.LinesMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e){this._scene=e}return t.prototype.render=function(t,i,r){var n=this;void 0===r&&(r=!1);var o=this._scene,s=this._scene.getEngine(),a=null!==s.getCaps().instancedArrays&&null!==i.visibleInstances[t._id]&&void 0!==i.visibleInstances[t._id];if(this.isReady(t,a)){var h=t.getRenderingMesh(),l=t.getMaterial();if(s.enableEffect(this._effect),this._effect.setFloat("offset",r?0:h.outlineWidth),this._effect.setColor4("color",r?h.overlayColor:h.outlineColor,r?h.overlayAlpha:1),this._effect.setMatrix("viewProjection",o.getTransformMatrix()),h.useBones&&h.computeBonesUsingShaders&&this._effect.setMatrices("mBones",h.skeleton.getTransformMatrices()),h._bind(t,this._effect,e.Material.TriangleFillMode),l&&l.needAlphaTesting()){var c=l.getAlphaTestTexture();this._effect.setTexture("diffuseSampler",c),this._effect.setMatrix("diffuseMatrix",c.getTextureMatrix())}h._processRendering(t,this._effect,e.Material.TriangleFillMode,i,a,function(e,t){n._effect.setMatrix("world",t)})}},t.prototype.isReady=function(t,i){var r=[],n=[e.VertexBuffer.PositionKind,e.VertexBuffer.NormalKind],o=t.getMesh(),s=t.getMaterial();s&&s.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.push(e.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(n.push(e.VertexBuffer.UV2Kind),r.push("#define UV2"))),o.useBones&&o.computeBonesUsingShaders&&(n.push(e.VertexBuffer.MatricesIndicesKind),n.push(e.VertexBuffer.MatricesWeightsKind),r.push("#define BONES"),r.push("#define BonesPerMesh "+(o.skeleton.bones.length+1))),i&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var a=r.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("outline",n,["world","mBones","viewProjection","diffuseMatrix","offset","color"],["diffuseSampler"],a)),this._effect.isReady()},t}();e.OutlineRenderer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i,r){this.name=e,this.meshesNames=t,this.rootUrl=i,this.sceneFilename=r,this.isCompleted=!1}return t.prototype.run=function(t,i,r){var n=this;e.SceneLoader.ImportMesh(this.meshesNames,this.rootUrl,this.sceneFilename,t,function(e,t,r){n.loadedMeshes=e,n.loadedParticleSystems=t,n.loadedSkeletons=r,n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),i()},null,function(){n.onError&&n.onError(n),r()})},t}();e.MeshAssetTask=t;var i=function(){function t(e,t){this.name=e,this.url=t,this.isCompleted=!1}return t.prototype.run=function(t,i,r){var n=this;e.Tools.LoadFile(this.url,function(e){n.text=e,n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),i()},null,t.database,!1,function(){n.onError&&n.onError(n),r()})},t}();e.TextFileAssetTask=i;var r=function(){function t(e,t){this.name=e,this.url=t,this.isCompleted=!1}return t.prototype.run=function(t,i,r){var n=this;e.Tools.LoadFile(this.url,function(e){n.data=e,n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),i()},null,t.database,!0,function(){n.onError&&n.onError(n),r()})},t}();e.BinaryFileAssetTask=r;var n=function(){function e(e,t){this.name=e,this.url=t,this.isCompleted=!1}return e.prototype.run=function(e,t,i){var r=this,n=new Image;n.onload=function(){r.image=n,r.isCompleted=!0,r.onSuccess&&r.onSuccess(r),t()},n.onerror=function(){r.onError&&r.onError(r),i()},n.src=this.url},e}();e.ImageAssetTask=n;var o=function(){function t(t,i,r,n,o){void 0===o&&(o=e.Texture.TRILINEAR_SAMPLINGMODE),this.name=t,this.url=i,this.noMipmap=r,this.invertY=n,this.samplingMode=o,this.isCompleted=!1}return t.prototype.run=function(t,i,r){var n=this,o=function(){n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),i()};this.texture=new e.Texture(this.url,t,this.noMipmap,this.invertY,this.samplingMode,o,r)},t}();e.TextureAssetTask=o;var s=function(){function s(e){this._tasks=new Array,this._waitingTasksCount=0,this.useDefaultLoadingScreen=!0,this._scene=e}return s.prototype.addMeshTask=function(e,i,r,n){var o=new t(e,i,r,n);return this._tasks.push(o),o},s.prototype.addTextFileTask=function(e,t){var r=new i(e,t);return this._tasks.push(r),r},s.prototype.addBinaryFileTask=function(e,t){var i=new r(e,t);return this._tasks.push(i),i},s.prototype.addImageTask=function(e,t){var i=new n(e,t);return this._tasks.push(i),i},s.prototype.addTextureTask=function(t,i,r,n,s){void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE);var a=new o(t,i,r,n,s);return this._tasks.push(a),a},s.prototype._decreaseWaitingTasksCount=function(){this._waitingTasksCount--,0===this._waitingTasksCount&&(this.onFinish&&this.onFinish(this._tasks),this._scene.getEngine().hideLoadingUI())},s.prototype._runTask=function(e){var t=this;e.run(this._scene,function(){t.onTaskSuccess&&t.onTaskSuccess(e),t._decreaseWaitingTasksCount()},function(){t.onTaskError&&t.onTaskError(e),t._decreaseWaitingTasksCount()})},s.prototype.reset=function(){return this._tasks=new Array,this},s.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 e=0;e<this._tasks.length;e++){var t=this._tasks[e];this._runTask(t)}return this},s}();e.AssetsManager=s}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){void 0===o&&(o=!0),t.call(this,i,r,n),this._alpha=0,this._beta=0,this._gamma=0;var s=e.VRCameraMetrics.GetDefault();s.compensateDistorsion=o,this.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:s}),this._deviceOrientationHandler=this._onOrientationEvent.bind(this)}return __extends(i,t),i.prototype._onOrientationEvent=function(e){this._alpha=0|+e.alpha,this._beta=0|+e.beta,this._gamma=0|+e.gamma,this._gamma=this._gamma<0?90+this._gamma:270-this._gamma,this.rotation.x=this._gamma/180*Math.PI,this.rotation.y=-this._alpha/180*Math.PI,this.rotation.z=this._beta/180*Math.PI},i.prototype.attachControl=function(e,i){t.prototype.attachControl.call(this,e,i),window.addEventListener("deviceorientation",this._deviceOrientationHandler)},i.prototype.detachControl=function(e){t.prototype.detachControl.call(this,e),window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},i}(e.FreeCamera);e.VRDeviceOrientationFreeCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){void 0===o&&(o=!0),t.call(this,i,r,n),this._hmdDevice=null,this._sensorDevice=null,this._cacheState=null,this._cacheQuaternion=new e.Quaternion,this._cacheRotation=e.Vector3.Zero(),this._vrEnabled=!1;var s=e.VRCameraMetrics.GetDefault();s.compensateDistorsion=o,this.setCameraRigMode(e.Camera.RIG_MODE_VR,{vrCameraMetrics:s}),this._getWebVRDevices=this._getWebVRDevices.bind(this)}return __extends(i,t),i.prototype._getWebVRDevices=function(e){var t=e.length,i=0;for(this._sensorDevice=null,this._hmdDevice=null;t>i&&null===this._hmdDevice;)e[i]instanceof HMDVRDevice&&(this._hmdDevice=e[i]),i++;for(i=0;t>i&&null===this._sensorDevice;)e[i]instanceof PositionSensorVRDevice&&(!this._hmdDevice||e[i].hardwareUnitId===this._hmdDevice.hardwareUnitId)&&(this._sensorDevice=e[i]),i++;this._vrEnabled=this._sensorDevice&&this._hmdDevice?!0:!1},i.prototype._checkInputs=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),t.prototype._checkInputs.call(this)},i.prototype.attachControl=function(e,i){t.prototype.attachControl.call(this,e,i),navigator.getVRDevices?navigator.getVRDevices().then(this._getWebVRDevices):navigator.mozGetVRDevices&&navigator.mozGetVRDevices(this._getWebVRDevices)},i.prototype.detachControl=function(e){t.prototype.detachControl.call(this,e),this._vrEnabled=!1},i}(e.FreeCamera);e.WebVRFreeCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e){void 0===e&&(e=0),this.priority=e,this.apply=function(e){return!0}}return e}();e.SceneOptimization=t;var i=function(e){function t(t,i){var r=this;void 0===t&&(t=0),void 0===i&&(i=1024),e.call(this,t),this.priority=t,this.maximumSize=i,this.apply=function(e){for(var t=!0,i=0;i<e.textures.length;i++){var n=e.textures[i];if(n.canRescale){var o=n.getSize(),s=Math.max(o.width,o.height);s>r.maximumSize&&(n.scale(.5),t=!1)}}return t}}return __extends(t,e),t}(t);e.TextureOptimization=i;var r=function(e){function t(t,i){var r=this;void 0===t&&(t=0),void 0===i&&(i=2),e.call(this,t),this.priority=t,this.maximumScale=i,this._currentScale=1,this.apply=function(e){return r._currentScale++,e.getEngine().setHardwareScalingLevel(r._currentScale),r._currentScale>=r.maximumScale}}return __extends(t,e),t}(t);e.HardwareScalingOptimization=r;var n=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.shadowsEnabled=!1,!0}}return __extends(t,e),t}(t);e.ShadowsOptimization=n;var o=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.postProcessesEnabled=!1,!0}}return __extends(t,e),t}(t);e.PostProcessesOptimization=o;var s=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.lensFlaresEnabled=!1,!0}}return __extends(t,e),t}(t);e.LensFlaresOptimization=s;var a=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.particlesEnabled=!1,!0}}return __extends(t,e),t}(t);e.ParticlesOptimization=a;var h=function(e){function t(){e.apply(this,arguments),this.apply=function(e){return e.renderTargetsEnabled=!1,!0}}return __extends(t,e),t}(t);e.RenderTargetsOptimization=h;var l=function(t){function i(){var r=this;t.apply(this,arguments),this._canBeMerged=function(t){if(!(t instanceof e.Mesh))return!1;var i=t;return i.isVisible&&i.isEnabled()?i.instances.length>0?!1:i.skeleton||i.hasLODLevels?!1:!0:!1},this.apply=function(t,n){for(var o=t.meshes.slice(0),s=o.length,a=0;s>a;a++){var h=new Array,l=o[a];if(r._canBeMerged(l)){h.push(l);for(var c=a+1;s>c;c++){var u=o[c];r._canBeMerged(u)&&u.material===l.material&&u.checkCollisions===l.checkCollisions&&(h.push(u),
  s--,o.splice(c,1),c--)}h.length<2||e.Mesh.MergeMeshes(h)}}return void 0!=n?n&&t.createOrUpdateSelectionOctree():i.UpdateSelectionTree&&t.createOrUpdateSelectionOctree(),!0}}return __extends(i,t),Object.defineProperty(i,"UpdateSelectionTree",{get:function(){return i._UpdateSelectionTree},set:function(e){i._UpdateSelectionTree=e},enumerable:!0,configurable:!0}),i._UpdateSelectionTree=!1,i}(t);e.MergeMeshesOptimization=l;var c=function(){function e(e,t){void 0===e&&(e=60),void 0===t&&(t=2e3),this.targetFrameRate=e,this.trackerDuration=t,this.optimizations=new Array}return e.LowDegradationAllowed=function(t){var r=new e(t),h=0;return r.optimizations.push(new l(h)),r.optimizations.push(new n(h)),r.optimizations.push(new s(h)),h++,r.optimizations.push(new o(h)),r.optimizations.push(new a(h)),h++,r.optimizations.push(new i(h,1024)),r},e.ModerateDegradationAllowed=function(t){var c=new e(t),u=0;return c.optimizations.push(new l(u)),c.optimizations.push(new n(u)),c.optimizations.push(new s(u)),u++,c.optimizations.push(new o(u)),c.optimizations.push(new a(u)),u++,c.optimizations.push(new i(u,512)),u++,c.optimizations.push(new h(u)),u++,c.optimizations.push(new r(u,2)),c},e.HighDegradationAllowed=function(t){var c=new e(t),u=0;return c.optimizations.push(new l(u)),c.optimizations.push(new n(u)),c.optimizations.push(new s(u)),u++,c.optimizations.push(new o(u)),c.optimizations.push(new a(u)),u++,c.optimizations.push(new i(u,256)),u++,c.optimizations.push(new h(u)),u++,c.optimizations.push(new r(u,4)),c},e}();e.SceneOptimizerOptions=c;var u=function(){function e(){}return e._CheckCurrentState=function(t,i,r,n,o){if(t.getEngine().getFps()>=i.targetFrameRate)return void(n&&n());for(var s=!0,a=!0,h=0;h<i.optimizations.length;h++){var l=i.optimizations[h];l.priority===r&&(a=!1,s=s&&l.apply(t))}return a?void(o&&o()):(s&&r++,void t.executeWhenReady(function(){setTimeout(function(){e._CheckCurrentState(t,i,r,n,o)},i.trackerDuration)}))},e.OptimizeAsync=function(t,i,r,n){i||(i=c.ModerateDegradationAllowed()),t.executeWhenReady(function(){setTimeout(function(){e._CheckCurrentState(t,i,0,r,n)},i.trackerDuration)})},e}();e.SceneOptimizer=u}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function e(e,t){this.distance=e,this.mesh=t}return e}();e.MeshLODLevel=t}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._audioContext=null,this._audioContextInitialized=!1,this.canUseWebAudio=!1,this.WarnedWebAudioUnsupported=!1,("undefined"!=typeof window.AudioContext||"undefined"!=typeof window.webkitAudioContext)&&(window.AudioContext=window.AudioContext||window.webkitAudioContext,this.canUseWebAudio=!0)}return Object.defineProperty(t.prototype,"audioContext",{get:function(){return this._audioContextInitialized||this._initializeAudioContext(),this._audioContext},enumerable:!0,configurable:!0}),t.prototype._initializeAudioContext=function(){try{this.canUseWebAudio&&(this._audioContext=new AudioContext,this.masterGain=this._audioContext.createGain(),this.masterGain.gain.value=1,this.masterGain.connect(this._audioContext.destination),this._audioContextInitialized=!0)}catch(t){this.canUseWebAudio=!1,e.Tools.Error("Web Audio: "+t.message)}},t.prototype.dispose=function(){this.canUseWebAudio&&this._audioContextInitialized&&(this._connectedAnalyser&&(this._connectedAnalyser.stopDebugCanvas(),this._connectedAnalyser.dispose(),this.masterGain.disconnect(),this.masterGain.connect(this._audioContext.destination),this._connectedAnalyser=null),this.masterGain.gain.value=1),this.WarnedWebAudioUnsupported=!1},t.prototype.getGlobalVolume=function(){return this.canUseWebAudio&&this._audioContextInitialized?this.masterGain.gain.value:-1},t.prototype.setGlobalVolume=function(e){this.canUseWebAudio&&this._audioContextInitialized&&(this.masterGain.gain.value=e)},t.prototype.connectToAnalyser=function(e){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this.canUseWebAudio&&this._audioContextInitialized&&(this._connectedAnalyser=e,this.masterGain.disconnect(),this._connectedAnalyser.connectAudioNodes(this.masterGain,this._audioContext.destination))},t}();e.AudioEngine=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n,o){var s=this;this.autoplay=!1,this.loop=!1,this.useCustomAttenuation=!1,this.spatialSound=!1,this.refDistance=1,this.rolloffFactor=1,this.maxDistance=100,this.distanceModel="linear",this._panningModel="equalpower",this._playbackRate=1,this._startTime=0,this._startOffset=0,this._position=e.Vector3.Zero(),this._localDirection=new e.Vector3(1,0,0),this._volume=1,this._isLoaded=!1,this._isReadyToPlay=!1,this.isPlaying=!1,this.isPaused=!1,this._isDirectional=!1,this._coneInnerAngle=360,this._coneOuterAngle=360,this._coneOuterGain=0,this._isOutputConnected=!1,this.name=t,this._scene=r,this._readyToPlayCallback=n,this._customAttenuationFunction=function(e,t,i,r,n){return i>t?e*(1-t/i):0},o&&(this.autoplay=o.autoplay||!1,this.loop=o.loop||!1,void 0!==o.volume&&(this._volume=o.volume),this.spatialSound=o.spatialSound||!1,this.maxDistance=o.maxDistance||100,this.useCustomAttenuation=o.useCustomAttenuation||!1,this.rolloffFactor=o.rolloffFactor||1,this.refDistance=o.refDistance||1,this.distanceModel=o.distanceModel||"linear",this._playbackRate=o.playbackRate||1),e.Engine.audioEngine.canUseWebAudio?(this._soundGain=e.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),i&&("string"==typeof i?e.Tools.LoadFile(i,function(e){s._soundLoaded(e)},null,null,!0):i instanceof ArrayBuffer?this._soundLoaded(i):e.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound."))):(this._scene.mainSoundTrack.AddSound(this),e.Engine.audioEngine.WarnedWebAudioUnsupported||(e.Tools.Error("Web Audio is not supported by your browser."),e.Engine.audioEngine.WarnedWebAudioUnsupported=!0),this._readyToPlayCallback&&window.setTimeout(function(){s._readyToPlayCallback()},1e3))}return t.prototype.dispose=function(){e.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&&(this._soundGain.disconnect(),this._soundGain=null),this._soundPanner&&(this._soundPanner.disconnect(),this._soundPanner=null),this._soundSource&&(this._soundSource.disconnect(),this._soundSource=null),this._audioBuffer=null,this._connectedMesh&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._connectedMesh=null))},t.prototype._soundLoaded=function(t){var i=this;this._isLoaded=!0,e.Engine.audioEngine.audioContext.decodeAudioData(t,function(e){i._audioBuffer=e,i._isReadyToPlay=!0,i.autoplay&&i.play(),i._readyToPlayCallback&&i._readyToPlayCallback()},function(){e.Tools.Error("Error while decoding audio data for: "+i.name)})},t.prototype.setAudioBuffer=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._audioBuffer=t,this._isReadyToPlay=!0)},t.prototype.updateOptions=function(e){e&&(this.loop=e.loop||this.loop,this.maxDistance=e.maxDistance||this.maxDistance,this.useCustomAttenuation=e.useCustomAttenuation||this.useCustomAttenuation,this.rolloffFactor=e.rolloffFactor||this.rolloffFactor,this.refDistance=e.refDistance||this.refDistance,this.distanceModel=e.distanceModel||this.distanceModel,this._playbackRate=e.playbackRate||this._playbackRate,this._updateSpatialParameters(),this.isPlaying&&(this._soundSource.playbackRate.value=this._playbackRate))},t.prototype._createSpatialParameters=function(){e.Engine.audioEngine.canUseWebAudio&&(this._scene.headphone&&(this._panningModel="HRTF"),this._soundPanner=e.Engine.audioEngine.audioContext.createPanner(),this._updateSpatialParameters(),this._soundPanner.connect(this._ouputAudioNode),this._inputAudioNode=this._soundPanner)},t.prototype._updateSpatialParameters=function(){this.spatialSound&&(this.useCustomAttenuation?(this._soundPanner.distanceModel="linear",this._soundPanner.maxDistance=Number.MAX_VALUE,this._soundPanner.refDistance=1,this._soundPanner.rolloffFactor=1,this._soundPanner.panningModel=this._panningModel):(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))},t.prototype.switchPanningModelToHRTF=function(){this._panningModel="HRTF",this._switchPanningModel()},t.prototype.switchPanningModelToEqualPower=function(){this._panningModel="equalpower",this._switchPanningModel()},t.prototype._switchPanningModel=function(){e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&(this._soundPanner.panningModel=this._panningModel)},t.prototype.connectToSoundTrackAudioNode=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._isOutputConnected&&this._ouputAudioNode.disconnect(),this._ouputAudioNode.connect(t),this._isOutputConnected=!0)},t.prototype.setDirectionalCone=function(t,i,r){return t>i?void e.Tools.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle."):(this._coneInnerAngle=t,this._coneOuterAngle=i,this._coneOuterGain=r,this._isDirectional=!0,void(this.isPlaying&&this.loop&&(this.stop(),this.play())))},t.prototype.setPosition=function(t){this._position=t,e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z)},t.prototype.setLocalDirectionToMesh=function(t){this._localDirection=t,e.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.isPlaying&&this._updateDirection()},t.prototype._updateDirection=function(){var t=this._connectedMesh.getWorldMatrix(),i=e.Vector3.TransformNormal(this._localDirection,t);i.normalize(),this._soundPanner.setOrientation(i.x,i.y,i.z)},t.prototype.updateDistanceFromListener=function(){if(e.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.useCustomAttenuation){var t=this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);this._soundGain.gain.value=this._customAttenuationFunction(this._volume,t,this.maxDistance,this.refDistance,this.rolloffFactor)}},t.prototype.setAttenuationFunction=function(e){this._customAttenuationFunction=e},t.prototype.play=function(t){var i=this;if(this._isReadyToPlay&&this._scene.audioEnabled)try{var r=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;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=e.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=r,this._soundSource.onended=function(){i._onended()},this._soundSource.start(this._startTime,this.isPaused?this._startOffset%this._soundSource.buffer.duration:0),this.isPlaying=!0,this.isPaused=!1}catch(n){e.Tools.Error("Error while trying to play audio: "+this.name+", "+n.message)}},t.prototype._onended=function(){this.isPlaying=!1,this.onended&&this.onended()},t.prototype.stop=function(t){if(this.isPlaying){var i=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource.stop(i),this.isPlaying=!1}},t.prototype.pause=function(){this.isPlaying&&(this.stop(0),this._startOffset+=e.Engine.audioEngine.audioContext.currentTime-this._startTime,this.isPaused=!0)},t.prototype.setVolume=function(t,i){e.Engine.audioEngine.canUseWebAudio&&(i?(this._soundGain.gain.linearRampToValueAtTime(this._volume,e.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.linearRampToValueAtTime(t,i)):this._soundGain.gain.value=t),this._volume=t},t.prototype.setPlaybackRate=function(e){this._playbackRate=e,this.isPlaying&&(this._soundSource.playbackRate.value=this._playbackRate)},t.prototype.getVolume=function(){return this._volume},t.prototype.attachToMesh=function(e){var t=this;this._connectedMesh=e,this.spatialSound||(this.spatialSound=!0,this._createSpatialParameters(),this.isPlaying&&this.loop&&(this.stop(),this.play())),this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh),this._registerFunc=function(e){return t._onRegisterAfterWorldMatrixUpdate(e)},e.registerAfterWorldMatrixUpdate(this._registerFunc)},t.prototype._onRegisterAfterWorldMatrixUpdate=function(t){this.setPosition(t.getBoundingInfo().boundingSphere.centerWorld),e.Engine.audioEngine.canUseWebAudio&&this._isDirectional&&this.isPlaying&&this._updateDirection()},t}();e.Sound=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.id=-1,this._isMainTrack=!1,this._scene=t,this._audioEngine=e.Engine.audioEngine,this.soundCollection=new Array,this._audioEngine.canUseWebAudio&&(this._outputAudioNode=this._audioEngine.audioContext.createGain(),this._outputAudioNode.connect(this._audioEngine.masterGain),i&&(i.volume&&(this._outputAudioNode.gain.value=i.volume),i.mainTrack&&(this._isMainTrack=i.mainTrack))),this._isMainTrack||(this._scene.soundTracks.push(this),this.id=this._scene.soundTracks.length-1)}return t.prototype.dispose=function(){if(this._audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._outputAudioNode&&this._outputAudioNode.disconnect(),this._outputAudioNode=null}},t.prototype.AddSound=function(t){e.Engine.audioEngine.canUseWebAudio&&t.connectToSoundTrackAudioNode(this._outputAudioNode),t.soundTrackId&&(-1===t.soundTrackId?this._scene.mainSoundTrack.RemoveSound(t):this._scene.soundTracks[t.soundTrackId].RemoveSound(t)),this.soundCollection.push(t),t.soundTrackId=this.id},t.prototype.RemoveSound=function(e){var t=this.soundCollection.indexOf(e);-1!==t&&this.soundCollection.splice(t,1)},t.prototype.setVolume=function(e){this._audioEngine.canUseWebAudio&&(this._outputAudioNode.gain.value=e)},t.prototype.switchPanningModelToHRTF=function(){if(e.Engine.audioEngine.canUseWebAudio)for(var t=0;t<this.soundCollection.length;t++)this.soundCollection[t].switchPanningModelToHRTF()},t.prototype.switchPanningModelToEqualPower=function(){if(e.Engine.audioEngine.canUseWebAudio)for(var t=0;t<this.soundCollection.length;t++)this.soundCollection[t].switchPanningModelToEqualPower()},t.prototype.connectToAnalyser=function(e){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this._connectedAnalyser=e,this._audioEngine.canUseWebAudio&&(this._outputAudioNode.disconnect(),this._connectedAnalyser.connectAudioNodes(this._outputAudioNode,this._audioEngine.masterGain))},t}();e.SoundTrack=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){var i=this;this._transformationMatrix=e.Matrix.Identity(),this._enabled=!1,this._labelsEnabled=!1,this._displayStatistics=!0,this._displayTree=!1,this._displayLogs=!1,this._identityMatrix=e.Matrix.Identity(),this.axisRatio=.02,this.accentColor="orange",this._scene=t,this._syncPositions=function(){var e=i._scene.getEngine(),t=e.getRenderingCanvasClientRect();i._showUI&&(i._statsDiv.style.left=t.width-410+"px",i._statsDiv.style.top=t.height-290+"px",i._statsDiv.style.width="400px",i._statsDiv.style.height="auto",i._statsSubsetDiv.style.maxHeight="240px",i._optionsDiv.style.left="0px",i._optionsDiv.style.top="10px",i._optionsDiv.style.width="200px",i._optionsDiv.style.height="auto",i._optionsSubsetDiv.style.maxHeight=t.height-225+"px",i._logDiv.style.left="0px",i._logDiv.style.top=t.height-170+"px",i._logDiv.style.width="600px",i._logDiv.style.height="160px",i._treeDiv.style.left=t.width-310+"px",i._treeDiv.style.top="10px",i._treeDiv.style.width="300px",i._treeDiv.style.height="auto",i._treeSubsetDiv.style.maxHeight=t.height-340+"px"),i._globalDiv.style.left=t.left+"px",i._globalDiv.style.top=t.top+"px",i._drawingCanvas.style.left="0px",i._drawingCanvas.style.top="0px",i._drawingCanvas.style.width=e.getRenderWidth()+"px",i._drawingCanvas.style.height=e.getRenderHeight()+"px";var r=window.devicePixelRatio||1,n=i._drawingContext,o=n.webkitBackingStorePixelRatio||n.mozBackingStorePixelRatio||n.msBackingStorePixelRatio||n.oBackingStorePixelRatio||n.backingStorePixelRatio||1;i._ratio=r/o,i._drawingCanvas.width=e.getRenderWidth()*i._ratio,i._drawingCanvas.height=e.getRenderHeight()*i._ratio},this._onCanvasClick=function(e){i._clickPosition={x:e.clientX*i._ratio,y:e.clientY*i._ratio}},this._syncUI=function(){i._showUI&&(i._displayStatistics?(i._displayStats(),i._statsDiv.style.display=""):i._statsDiv.style.display="none",i._logDiv.style.display=i._displayLogs?"":"none",i._displayTree?(i._treeDiv.style.display="",i._needToRefreshMeshesTree&&(i._needToRefreshMeshesTree=!1,i._refreshMeshesTreeContent())):i._treeDiv.style.display="none")},this._syncData=function(){if(i._labelsEnabled||!i._showUI){i._camera.getViewMatrix().multiplyToRef(i._camera.getProjectionMatrix(),i._transformationMatrix),i._drawingContext.clearRect(0,0,i._drawingCanvas.width,i._drawingCanvas.height);for(var t=i._scene.getEngine(),r=i._camera.viewport,n=r.toGlobal(t),o=i._camera.getActiveMeshes(),s=0;s<o.length;s++){var a=o.data[s],h=a.getBoundingInfo().boundingSphere.center,l=e.Vector3.Project(h,a.getWorldMatrix(),i._transformationMatrix,n);(a.renderOverlay||i.shouldDisplayAxis&&i.shouldDisplayAxis(a))&&i._renderAxis(l,a,n),(!i.shouldDisplayLabel||i.shouldDisplayLabel(a))&&i._renderLabel(a.name,l,12,function(){a.renderOverlay=!a.renderOverlay},function(){return a.renderOverlay?"red":"black"})}var c=i._scene.cameras;for(s=0;s<c.length;s++){var u=c[s];u!==i._camera&&(l=e.Vector3.Project(e.Vector3.Zero(),u.getWorldMatrix(),i._transformationMatrix,n),(!i.shouldDisplayLabel||i.shouldDisplayLabel(u))&&i._renderLabel(u.name,l,12,function(){i._camera.detachControl(t.getRenderingCanvas()),i._camera=u,i._camera.attachControl(t.getRenderingCanvas())},function(){return"purple"}))}var f=i._scene.lights;for(s=0;s<f.length;s++){var d=f[s];d.position&&(l=e.Vector3.Project(d.getAbsolutePosition(),i._identityMatrix,i._transformationMatrix,n),(!i.shouldDisplayLabel||i.shouldDisplayLabel(d))&&i._renderLabel(d.name,l,-20,function(){d.setEnabled(!d.isEnabled())},function(){return d.isEnabled()?"orange":"gray"}))}}i._clickPosition=void 0}}return t.prototype._refreshMeshesTreeContent=function(){for(;this._treeSubsetDiv.hasChildNodes();)this._treeSubsetDiv.removeChild(this._treeSubsetDiv.lastChild);var e=this._scene.meshes.slice(0,this._scene.meshes.length);e.sort(function(e,t){return e.name===t.name?0:e.name>t.name?1:-1});for(var t=0;t<e.length;t++){var i=e[t];i.isEnabled()&&this._generateAdvancedCheckBox(this._treeSubsetDiv,i.name,i.getTotalVertices()+" verts",i.isVisible,function(e,t){t.isVisible=e.checked},i)}},t.prototype._renderSingleAxis=function(e,t,i,r,n){this._drawingContext.beginPath(),this._drawingContext.moveTo(e.x,e.y),this._drawingContext.lineTo(t.x,t.y),this._drawingContext.strokeStyle=n,this._drawingContext.lineWidth=4,this._drawingContext.stroke(),this._drawingContext.font="normal 14px Segoe UI",this._drawingContext.fillStyle=n,this._drawingContext.fillText(r,i.x,i.y)},t.prototype._renderAxis=function(t,i,r){var n=i.getBoundingInfo().boundingSphere.center,o=i.getWorldMatrix(),s=e.Vector3.UnprojectFromTransform(t.add(new e.Vector3(this._drawingCanvas.width*this.axisRatio,0,0)),r.width,r.height,o,this._transformationMatrix),a=s.subtract(n).length(),h=e.Vector3.Project(n.add(new e.Vector3(a,0,0)),o,this._transformationMatrix,r),l=e.Vector3.Project(n.add(new e.Vector3(1.5*a,0,0)),o,this._transformationMatrix,r);this._renderSingleAxis(t,h,l,"x","#FF0000");var c=e.Vector3.Project(n.add(new e.Vector3(0,a,0)),o,this._transformationMatrix,r),u=e.Vector3.Project(n.add(new e.Vector3(0,1.5*a,0)),o,this._transformationMatrix,r);this._renderSingleAxis(t,c,u,"y","#00FF00");var f=e.Vector3.Project(n.add(new e.Vector3(0,0,a)),o,this._transformationMatrix,r),d=e.Vector3.Project(n.add(new e.Vector3(0,0,1.5*a)),o,this._transformationMatrix,r);this._renderSingleAxis(t,f,d,"z","#0000FF")},t.prototype._renderLabel=function(e,t,i,r,n){if(t.z>0&&t.z<1){this._drawingContext.font="normal 12px Segoe UI";var o=this._drawingContext.measureText(e),s=t.x-o.width/2,a=t.y,h=this._drawingCanvas.getBoundingClientRect();this._showUI&&this._isClickInsideRect(h.left*this._ratio+s-5,h.top*this._ratio+a-i-12,o.width+10,17)&&r(),this._drawingContext.beginPath(),this._drawingContext.rect(s-5,a-i-12,o.width+10,17),this._drawingContext.fillStyle=n(),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(e,s,a-i),this._drawingContext.beginPath(),this._drawingContext.arc(t.x,a,5,0,2*Math.PI,!1),this._drawingContext.fill()}},t.prototype._isClickInsideRect=function(e,t,i,r){return this._clickPosition?this._clickPosition.x<e||this._clickPosition.x>e+i?!1:this._clickPosition.y<t||this._clickPosition.y>t+r?!1:!0:!1},t.prototype.isVisible=function(){return this._enabled},t.prototype.hide=function(){if(this._enabled){this._enabled=!1;var t=this._scene.getEngine();this._scene.unregisterBeforeRender(this._syncData),this._scene.unregisterAfterRender(this._syncUI),document.body.removeChild(this._globalDiv),window.removeEventListener("resize",this._syncPositions),this._scene.forceShowBoundingBoxes=!1,this._scene.forceWireframe=!1,e.StandardMaterial.DiffuseTextureEnabled=!0,e.StandardMaterial.AmbientTextureEnabled=!0,e.StandardMaterial.SpecularTextureEnabled=!0,e.StandardMaterial.EmissiveTextureEnabled=!0,e.StandardMaterial.BumpTextureEnabled=!0,e.StandardMaterial.OpacityTextureEnabled=!0,e.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,t.getRenderingCanvas().removeEventListener("click",this._onCanvasClick)}},t.prototype.show=function(e,t){if(void 0===e&&(e=!0),void 0===t&&(t=null),!this._enabled){this._enabled=!0,this._camera=t?t:this._scene.activeCamera,this._showUI=e;var i=this._scene.getEngine();this._globalDiv=document.createElement("div"),document.body.appendChild(this._globalDiv),this._generateDOMelements(),window.addEventListener("resize",this._syncPositions),i.getRenderingCanvas().addEventListener("click",this._onCanvasClick),this._syncPositions(),this._scene.registerBeforeRender(this._syncData),this._scene.registerAfterRender(this._syncUI)}},t.prototype._clearLabels=function(){this._drawingContext.clearRect(0,0,this._drawingCanvas.width,this._drawingCanvas.height);for(var e=0;e<this._scene.meshes.length;e++){var t=this._scene.meshes[e];t.renderOverlay=!1}},t.prototype._generateheader=function(e,t){var i=document.createElement("div");i.innerHTML=t+"&nbsp;",i.style.textAlign="right",i.style.width="100%",i.style.color="white",i.style.backgroundColor="Black",i.style.padding="5px 5px 4px 0px",i.style.marginLeft="-5px",i.style.fontWeight="bold",e.appendChild(i)},t.prototype._generateTexBox=function(e,t,i){var r=document.createElement("label");r.innerHTML=t,r.style.color=i,e.appendChild(r),e.appendChild(document.createElement("br"))},t.prototype._generateAdvancedCheckBox=function(e,t,i,r,n,o){void 0===o&&(o=null);var s=document.createElement("label"),a=document.createElement("input");a.type="checkbox",a.checked=r,a.addEventListener("change",function(e){n(e.target,o)}),s.appendChild(a);var h=document.createElement("span"),l=document.createElement("span"),c=document.createElement("span");c.style.cssFloat="right",l.innerHTML=t,c.innerHTML=i,c.style.fontSize="12px",c.style.maxWidth="200px",h.appendChild(l),h.appendChild(c),s.appendChild(h),e.appendChild(s),e.appendChild(document.createElement("br"))},t.prototype._generateCheckBox=function(e,t,i,r,n){void 0===n&&(n=null);var o=document.createElement("label"),s=document.createElement("input");s.type="checkbox",s.checked=i,s.addEventListener("change",function(e){r(e.target,n)}),o.appendChild(s),o.appendChild(document.createTextNode(t)),e.appendChild(o),e.appendChild(document.createElement("br"))},t.prototype._generateButton=function(e,t,i,r){void 0===r&&(r=null);var n=document.createElement("button");n.innerHTML=t,n.style.height="24px",n.style.color="#444444",n.style.border="1px solid white",n.className="debugLayerButton",n.addEventListener("click",function(e){i(e.target,r)}),e.appendChild(n),e.appendChild(document.createElement("br"))},t.prototype._generateRadio=function(e,t,i,r,n,o){void 0===o&&(o=null);var s=document.createElement("label"),a=document.createElement("input");a.type="radio",a.name=i,a.checked=r,a.addEventListener("change",function(e){n(e.target,o)}),s.appendChild(a),s.appendChild(document.createTextNode(t)),e.appendChild(s),e.appendChild(document.createElement("br"))},t.prototype._generateDOMelements=function(){var t=this;if(this._globalDiv.id="DebugLayer",this._globalDiv.style.position="absolute",this._globalDiv.style.fontFamily="Segoe UI, Arial",this._globalDiv.style.fontSize="14px",this._globalDiv.style.color="white",this._drawingCanvas=document.createElement("canvas"),this._drawingCanvas.id="DebugLayerDrawingCanvas",this._drawingCanvas.style.position="absolute",this._drawingCanvas.style.pointerEvents="none",this._drawingContext=this._drawingCanvas.getContext("2d"),this._globalDiv.appendChild(this._drawingCanvas),this._showUI){var i="rgba(128, 128, 128, 0.4)",r="rgb(180, 180, 180) solid 1px";this._statsDiv=document.createElement("div"),this._statsDiv.id="DebugLayerStats",this._statsDiv.style.border=r,this._statsDiv.style.position="absolute",this._statsDiv.style.background=i,this._statsDiv.style.padding="0px 0px 0px 5px",this._generateheader(this._statsDiv,"STATISTICS"),this._statsSubsetDiv=document.createElement("div"),this._statsSubsetDiv.style.paddingTop="5px",this._statsSubsetDiv.style.paddingBottom="5px",this._statsSubsetDiv.style.overflowY="auto",this._statsDiv.appendChild(this._statsSubsetDiv),this._treeDiv=document.createElement("div"),this._treeDiv.id="DebugLayerTree",this._treeDiv.style.border=r,this._treeDiv.style.position="absolute",this._treeDiv.style.background=i,this._treeDiv.style.padding="0px 0px 0px 5px",this._treeDiv.style.display="none",this._generateheader(this._treeDiv,"MESHES TREE"),this._treeSubsetDiv=document.createElement("div"),this._treeSubsetDiv.style.paddingTop="5px",this._treeSubsetDiv.style.paddingRight="5px",this._treeSubsetDiv.style.overflowY="auto",this._treeSubsetDiv.style.maxHeight="300px",this._treeDiv.appendChild(this._treeSubsetDiv),this._needToRefreshMeshesTree=!0,this._logDiv=document.createElement("div"),this._logDiv.style.border=r,this._logDiv.id="DebugLayerLogs",this._logDiv.style.position="absolute",this._logDiv.style.background=i,this._logDiv.style.padding="0px 0px 0px 5px",this._logDiv.style.display="none",this._generateheader(this._logDiv,"LOGS"),this._logSubsetDiv=document.createElement("div"),this._logSubsetDiv.style.height="127px",this._logSubsetDiv.style.paddingTop="5px",this._logSubsetDiv.style.overflowY="auto",this._logSubsetDiv.style.fontSize="12px",this._logSubsetDiv.style.fontFamily="consolas",this._logSubsetDiv.innerHTML=e.Tools.LogCache,this._logDiv.appendChild(this._logSubsetDiv),e.Tools.OnNewCacheEntry=function(e){t._logSubsetDiv.innerHTML=e+t._logSubsetDiv.innerHTML},this._optionsDiv=document.createElement("div"),this._optionsDiv.id="DebugLayerOptions",this._optionsDiv.style.border=r,this._optionsDiv.style.position="absolute",this._optionsDiv.style.background=i,this._optionsDiv.style.padding="0px 0px 0px 5px",this._optionsDiv.style.overflowY="auto",this._generateheader(this._optionsDiv,"OPTIONS"),this._optionsSubsetDiv=document.createElement("div"),this._optionsSubsetDiv.style.paddingTop="5px",this._optionsSubsetDiv.style.paddingBottom="5px",this._optionsSubsetDiv.style.overflowY="auto",this._optionsSubsetDiv.style.maxHeight="200px",this._optionsDiv.appendChild(this._optionsSubsetDiv),this._generateTexBox(this._optionsSubsetDiv,"<b>Windows:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Statistics",this._displayStatistics,function(e){t._displayStatistics=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Logs",this._displayLogs,function(e){t._displayLogs=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Meshes tree",this._displayTree,function(e){t._displayTree=e.checked,t._needToRefreshMeshesTree=!0}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>General:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Bounding boxes",this._scene.forceShowBoundingBoxes,function(e){t._scene.forceShowBoundingBoxes=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Clickable labels",this._labelsEnabled,function(e){t._labelsEnabled=e.checked,t._labelsEnabled||t._clearLabels()}),this._generateCheckBox(this._optionsSubsetDiv,"Generate user marks (F12)",e.Tools.PerformanceLogLevel===e.Tools.PerformanceUserMarkLogLevel,function(t){e.Tools.PerformanceLogLevel=t.checked?e.Tools.PerformanceUserMarkLogLevel:e.Tools.PerformanceNoneLogLevel}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Rendering mode:</b>",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Solid","renderMode",!this._scene.forceWireframe&&!this._scene.forcePointsCloud,function(e){e.checked&&(t._scene.forceWireframe=!1,t._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Wireframe","renderMode",this._scene.forceWireframe,function(e){e.checked&&(t._scene.forceWireframe=!0,t._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Point","renderMode",this._scene.forcePointsCloud,function(e){e.checked&&(t._scene.forceWireframe=!1,t._scene.forcePointsCloud=!0)}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Texture channels:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Diffuse",e.StandardMaterial.DiffuseTextureEnabled,function(t){e.StandardMaterial.DiffuseTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Ambient",e.StandardMaterial.AmbientTextureEnabled,function(t){e.StandardMaterial.AmbientTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Specular",e.StandardMaterial.SpecularTextureEnabled,function(t){e.StandardMaterial.SpecularTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Emissive",e.StandardMaterial.EmissiveTextureEnabled,function(t){e.StandardMaterial.EmissiveTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Bump",e.StandardMaterial.BumpTextureEnabled,function(t){e.StandardMaterial.BumpTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Opacity",e.StandardMaterial.OpacityTextureEnabled,function(t){e.StandardMaterial.OpacityTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Reflection",e.StandardMaterial.ReflectionTextureEnabled,function(t){
  e.StandardMaterial.ReflectionTextureEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fresnel",e.StandardMaterial.FresnelEnabled,function(t){e.StandardMaterial.FresnelEnabled=t.checked}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Options:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Animations",this._scene.animationsEnabled,function(e){t._scene.animationsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Collisions",this._scene.collisionsEnabled,function(e){t._scene.collisionsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fog",this._scene.fogEnabled,function(e){t._scene.fogEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lens flares",this._scene.lensFlaresEnabled,function(e){t._scene.lensFlaresEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lights",this._scene.lightsEnabled,function(e){t._scene.lightsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Particles",this._scene.particlesEnabled,function(e){t._scene.particlesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Post-processes",this._scene.postProcessesEnabled,function(e){t._scene.postProcessesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Procedural textures",this._scene.proceduralTexturesEnabled,function(e){t._scene.proceduralTexturesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Render targets",this._scene.renderTargetsEnabled,function(e){t._scene.renderTargetsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Shadows",this._scene.shadowsEnabled,function(e){t._scene.shadowsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Skeletons",this._scene.skeletonsEnabled,function(e){t._scene.skeletonsEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Sprites",this._scene.spritesEnabled,function(e){t._scene.spritesEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Textures",this._scene.texturesEnabled,function(e){t._scene.texturesEnabled=e.checked}),e.Engine.audioEngine.canUseWebAudio&&(this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Audio:</b>",this.accentColor),this._generateRadio(this._optionsSubsetDiv,"Headphones","panningModel",this._scene.headphone,function(e){e.checked&&(t._scene.headphone=!0)}),this._generateRadio(this._optionsSubsetDiv,"Normal Speakers","panningModel",!this._scene.headphone,function(e){e.checked&&(t._scene.headphone=!1)}),this._generateCheckBox(this._optionsSubsetDiv,"Disable audio",!this._scene.audioEnabled,function(e){t._scene.audioEnabled=!e.checked})),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Tools:</b>",this.accentColor),this._generateButton(this._optionsSubsetDiv,"Dump rendertargets",function(e){t._scene.dumpNextRenderTargets=!0}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._globalDiv.appendChild(this._statsDiv),this._globalDiv.appendChild(this._logDiv),this._globalDiv.appendChild(this._optionsDiv),this._globalDiv.appendChild(this._treeDiv)}},t.prototype._displayStats=function(){var t=this._scene,i=t.getEngine(),r=i.getGlInfo();this._statsSubsetDiv.innerHTML="Babylon.js v"+e.Engine.Version+" - <b>"+e.Tools.Format(i.getFps(),0)+" fps</b><br><br><div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'><b>Count</b><br>Total meshes: "+t.meshes.length+"<br>Total vertices: "+t.getTotalVertices()+"<br>Total materials: "+t.materials.length+"<br>Total textures: "+t.textures.length+"<br>Active meshes: "+t.getActiveMeshes().length+"<br>Active indices: "+t.getActiveIndices()+"<br>Active bones: "+t.getActiveBones()+"<br>Active particles: "+t.getActiveParticles()+"<br><b>Draw calls: "+i.drawCalls+"</b><br><br><b>Duration</b><br>Meshes selection:</i> "+e.Tools.Format(t.getEvaluateActiveMeshesDuration())+" ms<br>Render Targets: "+e.Tools.Format(t.getRenderTargetsDuration())+" ms<br>Particles: "+e.Tools.Format(t.getParticlesDuration())+" ms<br>Sprites: "+e.Tools.Format(t.getSpritesDuration())+" ms<br><br>Render: <b>"+e.Tools.Format(t.getRenderDuration())+" ms</b><br>Frame: "+e.Tools.Format(t.getLastFrameDuration())+" ms<br>Potential FPS: "+e.Tools.Format(1e3/t.getLastFrameDuration(),0)+"<br><br></div><div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'><b>Extensions</b><br>Std derivatives: "+(i.getCaps().standardDerivatives?"Yes":"No")+"<br>Compressed textures: "+(i.getCaps().s3tc?"Yes":"No")+"<br>Hardware instances: "+(i.getCaps().instancedArrays?"Yes":"No")+"<br>Texture float: "+(i.getCaps().textureFloat?"Yes":"No")+"<br>32bits indices: "+(i.getCaps().uintIndices?"Yes":"No")+"<br><b>Caps.</b><br>Max textures units: "+i.getCaps().maxTexturesImageUnits+"<br>Max textures size: "+i.getCaps().maxTextureSize+"<br>Max anisotropy: "+i.getCaps().maxAnisotropy+"<br><br><br></div><br><b>Info</b><br>"+r.version+"<br>"+r.renderer+"<br>",this.customStatsFunction&&(this._statsSubsetDiv.innerHTML+=this._statsSubsetDiv.innerHTML)},t}();e.DebugLayer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s,a,h,l){void 0===a&&(a=!0),void 0===h&&(h=!1),void 0===l&&(l=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,s,!a,h),this.format=o,this._texture=s.getEngine().createRawTexture(i,r,n,o,a,h,l),this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE}return __extends(i,t),i.prototype.update=function(e){this.getScene().getEngine().updateRawTexture(this._texture,e,this.format,this._invertY)},i.CreateLuminanceTexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_LUMINANCE,o,s,a,h)},i.CreateLuminanceAlphaTexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,o,s,a,h)},i.CreateAlphaTexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_ALPHA,o,s,a,h)},i.CreateRGBTexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_RGB,o,s,a,h)},i.CreateRGBATexture=function(t,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=e.Texture.TRILINEAR_SAMPLINGMODE),new i(t,r,n,e.Engine.TEXTUREFORMAT_RGBA,o,s,a,h)},i}(e.Texture);e.RawTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i){e.call(this,t.x,t.y),this.index=i}return __extends(t,e),t}(e.Vector2),i=function(){function i(){this.elements=new Array}return i.prototype.add=function(e){var i=this,r=new Array;return e.forEach(function(e){if(0===r.length||!e.equalsWithEpsilon(r[0])){var n=new t(e,i.elements.length);r.push(n),i.elements.push(n)}}),r},i.prototype.computeBounds=function(){var t=new e.Vector2(this.elements[0].x,this.elements[0].y),i=new e.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach(function(e){e.x<t.x?t.x=e.x:e.x>i.x&&(i.x=e.x),e.y<t.y?t.y=e.y:e.y>i.y&&(i.y=e.y)}),{min:t,max:i,width:i.x-t.x,height:i.y-t.y}},i}(),r=function(){function t(){}return t.Rectangle=function(t,i,r,n){return[new e.Vector2(t,i),new e.Vector2(r,i),new e.Vector2(r,n),new e.Vector2(t,n)]},t.Circle=function(t,i,r,n){void 0===i&&(i=0),void 0===r&&(r=0),void 0===n&&(n=32);for(var o=new Array,s=0,a=2*Math.PI/n,h=0;n>h;h++)o.push(new e.Vector2(i+Math.cos(s)*t,r+Math.sin(s)*t)),s-=a;return o},t.Parse=function(t){var i,r=t.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function(e){return!isNaN(e)}),n=[];for(i=0;i<(2147483646&r.length);i+=2)n.push(new e.Vector2(r[i],r[i+1]));return n},t.StartingAt=function(t,i){return e.Path2.StartingAt(t,i)},t}();e.Polygon=r;var n=function(){function t(t,r,n){if(this._points=new i,this._outlinepoints=new i,this._holes=[],!("poly2tri"in window))throw"PolygonMeshBuilder cannot be used because poly2tri is not referenced";this._name=t,this._scene=n;var o;o=r instanceof e.Path2?r.getPoints():r,this._swctx=new poly2tri.SweepContext(this._points.add(o)),this._outlinepoints.add(o)}return t.prototype.addHole=function(e){this._swctx.addHole(this._points.add(e));var t=new i;return t.add(e),this._holes.push(t),this},t.prototype.build=function(t,i){var r=this;void 0===t&&(t=!1);var n=new e.Mesh(this._name,this._scene),o=[],s=[],a=[],h=this._points.computeBounds();this._points.elements.forEach(function(e){o.push(0,1,0),s.push(e.x,0,e.y),a.push((e.x-h.min.x)/h.width,(e.y-h.min.y)/h.height)});var l=[];if(this._swctx.triangulate(),this._swctx.getTriangles().forEach(function(e){e.getPoints().forEach(function(e){l.push(e.index)})}),i>0){var c=s.length/3;this._points.elements.forEach(function(e){o.push(0,-1,0),s.push(e.x,-i,e.y),a.push(1-(e.x-h.min.x)/h.width,1-(e.y-h.min.y)/h.height)});var u,f,d=0;this._swctx.getTriangles().forEach(function(e){e.getPoints().forEach(function(e){switch(d){case 0:u=e;break;case 1:f=e;break;case 2:l.push(e.index+c),l.push(f.index+c),l.push(u.index+c),d=-1}d++})}),this.addSide(s,o,a,l,h,this._outlinepoints,i,!1),this._holes.forEach(function(e){r.addSide(s,o,a,l,h,e,i,!0)})}return n.setVerticesData(e.VertexBuffer.PositionKind,s,t),n.setVerticesData(e.VertexBuffer.NormalKind,o,t),n.setVerticesData(e.VertexBuffer.UVKind,a,t),n.setIndices(l),n},t.prototype.addSide=function(t,i,r,n,o,s,a,h){for(var l=t.length/3,c=0,u=0;u<s.elements.length;u++){var f,d=s.elements[u];f=u+1>s.elements.length-1?s.elements[0]:s.elements[u+1],t.push(d.x,0,d.y),t.push(d.x,-a,d.y),t.push(f.x,0,f.y),t.push(f.x,-a,f.y);var p=new e.Vector3(d.x,0,d.y),m=new e.Vector3(f.x,0,f.y),g=m.subtract(p),_=new e.Vector3(0,1,0),v=e.Vector3.Cross(g,_);v=v.normalize(),r.push(c/o.width,0),r.push(c/o.width,1),c+=g.length(),r.push(c/o.width,0),r.push(c/o.width,1),h?(i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),i.push(v.x,v.y,v.z),n.push(l),n.push(l+2),n.push(l+1),n.push(l+1),n.push(l+2),n.push(l+3)):(i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),i.push(-v.x,-v.y,-v.z),n.push(l),n.push(l+1),n.push(l+2),n.push(l+1),n.push(l+3),n.push(l+2)),l+=4}},t}();e.PolygonMeshBuilder=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,i){this.quality=e,this.distance=t,this.optimizeMesh=i}return e}();e.SimplificationSettings=t;var i=function(){function t(){this.running=!1,this._simplificationArray=[]}return t.prototype.addTask=function(e){this._simplificationArray.push(e)},t.prototype.executeNext=function(){var e=this._simplificationArray.pop();e?(this.running=!0,this.runSimplification(e)):this.running=!1},t.prototype.runSimplification=function(t){var i=this;if(t.parallelProcessing)t.settings.forEach(function(e){var r=i.getSimplifier(t);r.simplify(e,function(r){t.mesh.addLODLevel(e.distance,r),r.isVisible=!0,e.quality===t.settings[t.settings.length-1].quality&&t.successCallback&&t.successCallback(),i.executeNext()})});else{var r=this.getSimplifier(t),n=function(e,i){r.simplify(e,function(r){t.mesh.addLODLevel(e.distance,r),r.isVisible=!0,i()})};e.AsyncLoop.Run(t.settings.length,function(e){n(t.settings[e.index],function(){e.executeNext()})},function(){t.successCallback&&t.successCallback(),i.executeNext()})}},t.prototype.getSimplifier=function(e){switch(e.simplificationType){case r.QUADRATIC:default:return new h(e.mesh)}},t}();e.SimplificationQueue=i,function(e){e[e.QUADRATIC=0]="QUADRATIC"}(e.SimplificationType||(e.SimplificationType={}));var r=e.SimplificationType,n=function(){function e(e){this.vertices=e,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.deletePending=!1,this.borderFactor=0}return e}();e.DecimationTriangle=n;var o=function(){function e(e,t){this.position=e,this.id=t,this.isBorder=!0,this.q=new s,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return e.prototype.updatePosition=function(e){this.position.copyFrom(e)},e}();e.DecimationVertex=o;var s=function(){function e(e){this.data=new Array(10);for(var t=0;10>t;++t)this.data[t]=e&&e[t]?e[t]:0}return e.prototype.det=function(e,t,i,r,n,o,s,a,h){var l=this.data[e]*this.data[n]*this.data[h]+this.data[i]*this.data[r]*this.data[a]+this.data[t]*this.data[o]*this.data[s]-this.data[i]*this.data[n]*this.data[s]-this.data[e]*this.data[o]*this.data[a]-this.data[t]*this.data[r]*this.data[h];return l},e.prototype.addInPlace=function(e){for(var t=0;10>t;++t)this.data[t]+=e.data[t]},e.prototype.addArrayInPlace=function(e){for(var t=0;10>t;++t)this.data[t]+=e[t]},e.prototype.add=function(t){for(var i=new e,r=0;10>r;++r)i.data[r]=this.data[r]+t.data[r];return i},e.FromData=function(t,i,r,n){return new e(e.DataFromNumbers(t,i,r,n))},e.DataFromNumbers=function(e,t,i,r){return[e*e,e*t,e*i,e*r,t*t,t*i,t*r,i*i,i*r,r*r]},e}();e.QuadraticMatrix=s;var a=function(){function e(e,t){this.vertexId=e,this.triangleId=t}return e}();e.Reference=a;var h=function(){function t(t){this._mesh=t,this.initialized=!1,this.syncIterations=5e3,this.aggressiveness=7,this.decimationIterations=100,this.boundingBoxEpsilon=e.Engine.Epsilon}return t.prototype.simplify=function(t,i){var r=this;this.initDecimatedMesh(),e.AsyncLoop.Run(this._mesh.subMeshes.length,function(e){r.initWithMesh(e.index,function(){r.runDecimation(t,e.index,function(){e.executeNext()})},t.optimizeMesh)},function(){setTimeout(function(){i(r._reconstructedMesh)},0)})},t.prototype.isTriangleOnBoundingBox=function(e){var t=this,i=0;return e.vertices.forEach(function(e){var r=0,n=e.position,o=t._mesh.getBoundingInfo().boundingBox;(o.maximum.x-n.x<t.boundingBoxEpsilon||n.x-o.minimum.x>t.boundingBoxEpsilon)&&++r,(o.maximum.y==n.y||n.y==o.minimum.y)&&++r,(o.maximum.z==n.z||n.z==o.minimum.z)&&++r,r>1&&++i}),i>1&&console.log(e,i),i>1},t.prototype.runDecimation=function(t,i,r){var n=this,o=~~(this.triangles.length*t.quality),s=0,a=this.triangles.length,h=function(t,i){setTimeout(function(){t%5===0&&n.updateMesh(0===t);for(var r=0;r<n.triangles.length;++r)n.triangles[r].isDirty=!1;var h=1e-9*Math.pow(t+3,n.aggressiveness),l=function(t){var i=~~((n.triangles.length/2+t)%n.triangles.length),r=n.triangles[i];if(r&&!(r.error[3]>h||r.deleted||r.isDirty))for(var o=0;3>o;++o)if(r.error[o]<h){var a=[],l=[],c=r.vertices[o],u=r.vertices[(o+1)%3];if(c.isBorder!==u.isBorder)continue;var f=e.Vector3.Zero(),d=e.Vector3.Zero(),p=e.Vector2.Zero(),m=new e.Color4(0,0,0,1);n.calculateError(c,u,f,d,p,m);var g=[];if(n.isFlipped(c,u,f,a,r.borderFactor,g))continue;if(n.isFlipped(u,c,f,l,r.borderFactor,g))continue;if(a.indexOf(!0)<0||l.indexOf(!0)<0)continue;var _=[];if(g.forEach(function(e){-1===_.indexOf(e)&&(e.deletePending=!0,_.push(e))}),_.length%2!=0)continue;c.q=u.q.add(c.q),c.updatePosition(f);var v=n.references.length;s=n.updateTriangles(c,c,a,s),s=n.updateTriangles(c,u,l,s);var y=n.references.length-v;if(y<=c.triangleCount){if(y)for(var x=0;y>x;x++)n.references[c.triangleStart+x]=n.references[v+x]}else c.triangleStart=v;c.triangleCount=y;break}};e.AsyncLoop.SyncAsyncForLoop(n.triangles.length,n.syncIterations,l,i,function(){return o>=a-s})},0)};e.AsyncLoop.Run(this.decimationIterations,function(e){o>=a-s?e.breakLoop():h(e.index,function(){e.executeNext()})},function(){setTimeout(function(){n.reconstructMesh(i),r()},0)})},t.prototype.initWithMesh=function(t,i,r){var s=this;this.vertices=[],this.triangles=[];var a=this._mesh.getVerticesData(e.VertexBuffer.PositionKind),h=this._mesh.getIndices(),l=this._mesh.subMeshes[t],c=function(e){if(r)for(var t=0;t<s.vertices.length;++t)if(s.vertices[t].position.equals(e))return s.vertices[t];return null},u=[],f=function(t){var i=t+l.verticesStart,r=e.Vector3.FromArray(a,3*i),n=c(r)||new o(r,s.vertices.length);n.originalOffsets.push(i),n.id==s.vertices.length&&s.vertices.push(n),u.push(n.id)},d=l.verticesCount;e.AsyncLoop.SyncAsyncForLoop(d,this.syncIterations/4>>0,f,function(){var t=function(e){var t=l.indexStart/3+e,i=3*t,r=h[i+0],o=h[i+1],a=h[i+2],c=s.vertices[u[r-l.verticesStart]],f=s.vertices[u[o-l.verticesStart]],d=s.vertices[u[a-l.verticesStart]],p=new n([c,f,d]);p.originalOffset=i,s.triangles.push(p)};e.AsyncLoop.SyncAsyncForLoop(l.indexCount/3,s.syncIterations,t,function(){s.init(i)})})},t.prototype.init=function(t){var i=this,r=function(t){var r=i.triangles[t];r.normal=e.Vector3.Cross(r.vertices[1].position.subtract(r.vertices[0].position),r.vertices[2].position.subtract(r.vertices[0].position)).normalize();for(var n=0;3>n;n++)r.vertices[n].q.addArrayInPlace(s.DataFromNumbers(r.normal.x,r.normal.y,r.normal.z,-e.Vector3.Dot(r.normal,r.vertices[0].position)))};e.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,r,function(){var r=function(e){for(var t=i.triangles[e],r=0;3>r;++r)t.error[r]=i.calculateError(t.vertices[r],t.vertices[(r+1)%3]);t.error[3]=Math.min(t.error[0],t.error[1],t.error[2])};e.AsyncLoop.SyncAsyncForLoop(i.triangles.length,i.syncIterations,r,function(){i.initialized=!0,t()})})},t.prototype.reconstructMesh=function(t){var i,r=[];for(i=0;i<this.vertices.length;++i)this.vertices[i].triangleCount=0;var n,o;for(i=0;i<this.triangles.length;++i)if(!this.triangles[i].deleted){for(n=this.triangles[i],o=0;3>o;++o)n.vertices[o].triangleCount=1;r.push(n)}var s=this._reconstructedMesh.getVerticesData(e.VertexBuffer.PositionKind)||[],a=this._reconstructedMesh.getVerticesData(e.VertexBuffer.NormalKind)||[],h=this._reconstructedMesh.getVerticesData(e.VertexBuffer.UVKind)||[],l=this._reconstructedMesh.getVerticesData(e.VertexBuffer.ColorKind)||[],c=this._mesh.getVerticesData(e.VertexBuffer.NormalKind),u=this._mesh.getVerticesData(e.VertexBuffer.UVKind),f=this._mesh.getVerticesData(e.VertexBuffer.ColorKind),d=0;for(i=0;i<this.vertices.length;++i){var p=this.vertices[i];p.id=d,p.triangleCount&&p.originalOffsets.forEach(function(e){s.push(p.position.x),s.push(p.position.y),s.push(p.position.z),a.push(c[3*e]),a.push(c[3*e+1]),a.push(c[3*e+2]),u&&u.length?(h.push(u[2*e]),h.push(u[2*e+1])):f&&f.length&&(l.push(f[4*e]),l.push(f[4*e+1]),l.push(f[4*e+2]),l.push(f[4*e+3])),++d})}var m=this._reconstructedMesh.getTotalIndices(),g=this._reconstructedMesh.getTotalVertices(),_=this._reconstructedMesh.subMeshes;this._reconstructedMesh.subMeshes=[];var v=this._reconstructedMesh.getIndices(),y=this._mesh.getIndices();for(i=0;i<r.length;++i){var n=r[i];[0,1,2].forEach(function(e){var t=y[n.originalOffset+e],i=n.vertices[e].originalOffsets.indexOf(t);0>i&&(i=0),v.push(n.vertices[e].id+i+g)})}this._reconstructedMesh.setIndices(v),this._reconstructedMesh.setVerticesData(e.VertexBuffer.PositionKind,s),this._reconstructedMesh.setVerticesData(e.VertexBuffer.NormalKind,a),h.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.UVKind,h),l.length>0&&this._reconstructedMesh.setVerticesData(e.VertexBuffer.ColorKind,l);var x=this._mesh.subMeshes[t];if(t>0){this._reconstructedMesh.subMeshes=[],_.forEach(function(t){new e.SubMesh(t.materialIndex,t.verticesStart,t.verticesCount,t.indexStart,t.indexCount,t.getMesh())});{new e.SubMesh(x.materialIndex,g,d,m,3*r.length,this._reconstructedMesh)}}},t.prototype.initDecimatedMesh=function(){this._reconstructedMesh=new e.Mesh(this._mesh.name+"Decimated",this._mesh.getScene()),this._reconstructedMesh.material=this._mesh.material,this._reconstructedMesh.parent=this._mesh.parent,this._reconstructedMesh.isVisible=!1},t.prototype.isFlipped=function(t,i,r,n,o,s){for(var a=0;a<t.triangleCount;++a){var h=this.triangles[this.references[t.triangleStart+a].triangleId];if(!h.deleted){var l=this.references[t.triangleStart+a].vertexId,c=h.vertices[(l+1)%3],u=h.vertices[(l+2)%3];if(c!==i&&u!==i){var f=c.position.subtract(r);f=f.normalize();var d=u.position.subtract(r);if(d=d.normalize(),Math.abs(e.Vector3.Dot(f,d))>.999)return!0;var p=e.Vector3.Cross(f,d).normalize();if(n[a]=!1,e.Vector3.Dot(p,h.normal)<.2)return!0}else n[a]=!0,s.push(h)}}return!1},t.prototype.updateTriangles=function(e,t,i,r){for(var n=r,o=0;o<t.triangleCount;++o){var s=this.references[t.triangleStart+o],a=this.triangles[s.triangleId];a.deleted||(i[o]&&a.deletePending?(a.deleted=!0,n++):(a.vertices[s.vertexId]=e,a.isDirty=!0,a.error[0]=this.calculateError(a.vertices[0],a.vertices[1])+a.borderFactor/2,a.error[1]=this.calculateError(a.vertices[1],a.vertices[2])+a.borderFactor/2,a.error[2]=this.calculateError(a.vertices[2],a.vertices[0])+a.borderFactor/2,a.error[3]=Math.min(a.error[0],a.error[1],a.error[2]),this.references.push(s)))}return n},t.prototype.identifyBorder=function(){for(var e=0;e<this.vertices.length;++e){var t,i=[],r=[],n=this.vertices[e];for(t=0;t<n.triangleCount;++t)for(var o=this.triangles[this.references[n.triangleStart+t].triangleId],s=0;3>s;s++){for(var a=0,h=o.vertices[s];a<i.length&&r[a]!==h.id;)++a;a===i.length?(i.push(1),r.push(h.id)):i[a]++}for(t=0;t<i.length;++t)this.vertices[r[t]].isBorder=1===i[t]?!0:!1}},t.prototype.updateMesh=function(e){void 0===e&&(e=!1);var t;if(!e){var i=[];for(t=0;t<this.triangles.length;++t)this.triangles[t].deleted||i.push(this.triangles[t]);this.triangles=i}for(t=0;t<this.vertices.length;++t)this.vertices[t].triangleCount=0,this.vertices[t].triangleStart=0;var r,n,o;for(t=0;t<this.triangles.length;++t)for(r=this.triangles[t],n=0;3>n;++n)o=r.vertices[n],o.triangleCount++;var s=0;for(t=0;t<this.vertices.length;++t)this.vertices[t].triangleStart=s,s+=this.vertices[t].triangleCount,this.vertices[t].triangleCount=0;var h=new Array(3*this.triangles.length);for(t=0;t<this.triangles.length;++t)for(r=this.triangles[t],n=0;3>n;++n)o=r.vertices[n],h[o.triangleStart+o.triangleCount]=new a(n,t),o.triangleCount++;this.references=h,e&&this.identifyBorder()},t.prototype.vertexError=function(e,t){var i=t.x,r=t.y,n=t.z;return e.data[0]*i*i+2*e.data[1]*i*r+2*e.data[2]*i*n+2*e.data[3]*i+e.data[4]*r*r+2*e.data[5]*r*n+2*e.data[6]*r+e.data[7]*n*n+2*e.data[8]*n+e.data[9]},t.prototype.calculateError=function(t,i,r,n,o,s){var a=t.q.add(i.q),h=t.isBorder&&i.isBorder,l=0,c=a.det(0,1,2,1,4,5,2,5,7);if(0===c||h){var u=t.position.add(i.position).divide(new e.Vector3(2,2,2)),f=this.vertexError(a,t.position),d=this.vertexError(a,i.position),p=this.vertexError(a,u);l=Math.min(f,d,p),l===f?r&&r.copyFrom(t.position):l===d?r&&r.copyFrom(i.position):r&&r.copyFrom(u)}else r||(r=e.Vector3.Zero()),r.x=-1/c*a.det(1,2,3,4,5,6,5,7,8),r.y=1/c*a.det(0,2,3,1,5,6,2,7,8),r.z=-1/c*a.det(0,1,3,1,4,6,2,5,8),l=this.vertexError(a,r);return l},t}();e.QuadraticErrorSimplification=h}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.SMOOTHING=.75,this.FFT_SIZE=512,this.BARGRAPHAMPLITUDE=256,this.DEBUGCANVASPOS={x:20,y:20},this.DEBUGCANVASSIZE={width:320,height:200},this._scene=t,this._audioEngine=e.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 t.prototype.getFrequencyBinCount=function(){return this._audioEngine.canUseWebAudio?this._webAudioAnalyser.frequencyBinCount:0},t.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},t.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},t.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},t.prototype.drawDebugCanvas=function(){var e=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(){e.drawDebugCanvas()},this._scene.registerBeforeRender(this._registerFunc)),this._registerFunc)){var t=this.getByteFrequencyData();this._debugCanvasContext.fillStyle="rgb(0, 0, 0)",this._debugCanvasContext.fillRect(0,0,this.DEBUGCANVASSIZE.width,this.DEBUGCANVASSIZE.height);for(var i=0;i<this.getFrequencyBinCount();i++){var r=t[i],n=r/this.BARGRAPHAMPLITUDE,o=this.DEBUGCANVASSIZE.height*n,s=this.DEBUGCANVASSIZE.height-o-1,a=this.DEBUGCANVASSIZE.width/this.getFrequencyBinCount(),h=i/this.getFrequencyBinCount()*360;this._debugCanvasContext.fillStyle="hsl("+h+", 100%, 50%)",this._debugCanvasContext.fillRect(i*a,s,a,o)}}},t.prototype.stopDebugCanvas=function(){this._debugCanvas&&(this._scene.unregisterBeforeRender(this._registerFunc),this._registerFunc=null,document.body.removeChild(this._debugCanvas),this._debugCanvas=null,this._debugCanvasContext=null)},t.prototype.connectAudioNodes=function(e,t){this._audioEngine.canUseWebAudio&&(e.connect(this._webAudioAnalyser),this._webAudioAnalyser.connect(t))},t.prototype.dispose=function(){this._audioEngine.canUseWebAudio&&this._webAudioAnalyser.disconnect()},t}();e.Analyser=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){var r=this;void 0===i&&(i=e.Engine.TEXTURETYPE_FLOAT),this._viewMatrix=e.Matrix.Zero(),this._projectionMatrix=e.Matrix.Zero(),this._transformMatrix=e.Matrix.Zero(),this._worldViewProjection=e.Matrix.Zero(),this._scene=t;var n=t.getEngine();this._depthMap=new e.RenderTargetTexture("depthMap",{width:n.getRenderWidth(),height:n.getRenderHeight()},this._scene,!1,!0,i),this._depthMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._depthMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._depthMap.refreshRate=1,this._depthMap.renderParticles=!1,this._depthMap.renderList=null,this._depthMap.onClear=function(t){t.clear(new e.Color4(1,1,1,1),!0,!0)};var o=function(t){var i=t.getRenderingMesh(),n=r._scene,o=n.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id];if(r.isReady(t,a)){o.enableEffect(r._effect),i._bind(t,r._effect,e.Material.TriangleFillMode);var h=t.getMaterial();if(r._effect.setMatrix("viewProjection",n.getTransformMatrix()),r._effect.setFloat("far",n.activeCamera.maxZ),h&&h.needAlphaTesting()){var l=h.getAlphaTestTexture();r._effect.setTexture("diffuseSampler",l),r._effect.setMatrix("diffuseMatrix",l.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&r._effect.setMatrices("mBones",i.skeleton.getTransformMatrices()),i._processRendering(t,r._effect,e.Material.TriangleFillMode,s,a,function(e,t){return r._effect.setMatrix("world",t)})}}};this._depthMap.customRenderFunction=function(e,t){var i;for(i=0;i<e.length;i++)o(e.data[i]);for(i=0;i<t.length;i++)o(t.data[i])}}return t.prototype.isReady=function(t,i){var r=[],n=[e.VertexBuffer.PositionKind],o=t.getMesh(),s=(o.getScene(),t.getMaterial());s&&s.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.push(e.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(n.push(e.VertexBuffer.UV2Kind),r.push("#define UV2"))),o.useBones&&o.computeBonesUsingShaders&&(n.push(e.VertexBuffer.MatricesIndicesKind),n.push(e.VertexBuffer.MatricesWeightsKind),r.push("#define BONES"),r.push("#define BonesPerMesh "+(o.skeleton.bones.length+1))),i&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var a=r.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("depth",n,["world","mBones","viewProjection","diffuseMatrix","far"],["diffuseSampler"],a)),this._effect.isReady()},t.prototype.getDepthMap=function(){return this._depthMap},t.prototype.dispose=function(){this._depthMap.dispose()},t}();e.DepthRenderer=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){var s=this;t.call(this,r.getEngine(),i),this.SSAOOriginalSceneColorEffect="SSAOOriginalSceneColorEffect",this.SSAORenderEffect="SSAORenderEffect",this.SSAOBlurHRenderEffect="SSAOBlurHRenderEffect",this.SSAOBlurVRenderEffect="SSAOBlurVRenderEffect",this.SSAOCombineRenderEffect="SSAOCombineRenderEffect",this.totalStrength=1,this.radius=2e-4,this.area=.0075,this.fallOff=2e-4,this._firstUpdate=!0,this._scene=r,this._createRandomTexture(),this._depthTexture=r.enableDepthRenderer().getDepthMap();var a=n.ssaoRatio||n,h=n.combineRatio||n;this._originalColorPostProcess=new e.PassPostProcess("SSAOOriginalSceneColor",h,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),this._createSSAOPostProcess(a),this._blurHPostProcess=new e.BlurPostProcess("SSAOBlurH",new e.Vector2(2,0),2,a,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),this._blurVPostProcess=new e.BlurPostProcess("SSAOBlurV",new e.Vector2(0,2),2,a,null,e.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),this._createSSAOCombinePostProcess(h),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),this.SSAOOriginalSceneColorEffect,function(){return s._originalColorPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),this.SSAORenderEffect,function(){return s._ssaoPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),this.SSAOBlurHRenderEffect,function(){return s._blurHPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),this.SSAOBlurVRenderEffect,function(){return s._blurVPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(r.getEngine(),this.SSAOCombineRenderEffect,function(){return s._ssaoCombinePostProcess},!0)),r.postProcessRenderPipelineManager.addPipeline(this),o&&r.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,o)}return __extends(i,t),i.prototype.getBlurHPostProcess=function(){return this._blurHPostProcess},i.prototype.getBlurVPostProcess=function(){return this._blurVPostProcess},i.prototype.dispose=function(e){void 0===e&&(e=!1),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),this._originalColorPostProcess=void 0,this._ssaoPostProcess=void 0,this._blurHPostProcess=void 0,this._blurVPostProcess=void 0,this._ssaoCombinePostProcess=void 0,this._randomTexture.dispose(),e&&this._scene.disableDepthRenderer()},i.prototype._createSSAOPostProcess=function(t){var i=this,r=[.5381,.1856,-.4319,.1379,.2486,.443,.3371,.5679,-.0057,-.6999,-.0451,-.0019,.0689,-.1598,-.8547,.056,.0069,-.1843,-.0146,.1402,.0762,.01,-.1924,-.0344,-.3577,-.5301,-.4358,-.3169,.1063,.0158,.0103,-.5869,.0046,-.0897,-.494,.3287,.7119,-.0154,-.0918,-.0533,.0596,-.5411,.0352,-.0631,.546,-.4776,.2847,-.0271],n=1/16;this._ssaoPostProcess=new e.PostProcess("ssao","ssao",["sampleSphere","samplesFactor","randTextureTiles","totalStrength","radius","area","fallOff"],["randomSampler"],t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoPostProcess.onApply=function(e){i._firstUpdate&&(e.setArray3("sampleSphere",r),e.setFloat("samplesFactor",n),e.setFloat("randTextureTiles",4/t),i._firstUpdate=!1),e.setFloat("totalStrength",i.totalStrength),e.setFloat("radius",i.radius),
  e.setFloat("area",i.area),e.setFloat("fallOff",i.fallOff),e.setTexture("textureSampler",i._depthTexture),e.setTexture("randomSampler",i._randomTexture)}},i.prototype._createSSAOCombinePostProcess=function(t){var i=this;this._ssaoCombinePostProcess=new e.PostProcess("ssaoCombine","ssaoCombine",[],["originalColor"],t,null,e.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoCombinePostProcess.onApply=function(e){e.setTextureFromPostProcess("originalColor",i._originalColorPostProcess)}},i.prototype._createRandomTexture=function(){var t=512;this._randomTexture=new e.DynamicTexture("SSAORandomTexture",t,this._scene,!1,e.Texture.BILINEAR_SAMPLINGMODE),this._randomTexture.wrapU=e.Texture.WRAP_ADDRESSMODE,this._randomTexture.wrapV=e.Texture.WRAP_ADDRESSMODE;for(var i=this._randomTexture.getContext(),r=function(e,t){return Math.random()*(t-e)+e},n=0;t>n;n++)for(var o=0;t>o;o++){var s=e.Vector3.Zero();s.x=Math.floor(255*r(0,1)),s.y=Math.floor(255*r(0,1)),s.z=Math.floor(255*r(0,1)),i.fillStyle="rgb("+s.x+", "+s.y+", "+s.z+")",i.fillRect(n,o,1,1)}this._randomTexture.update(!1)},i}(e.PostProcessRenderPipeline);e.SSAORenderingPipeline=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(r,n,o,s,a,h,l,c,u){var f=this;void 0===a&&(a=100),void 0===h&&(h=e.Texture.BILINEAR_SAMPLINGMODE),t.call(this,r,"volumetricLightScattering",["decay","exposure","weight","meshPositionOnScreen","density"],["lightScatteringSampler"],n.postProcessRatio||n,o,h,l,c,"#define NUM_SAMPLES "+a),this._screenCoordinates=e.Vector2.Zero(),this.useCustomMeshPosition=!1,this.invert=!0,this.useDiffuseColor=!1,this.excludedMeshes=new Array,this.exposure=.3,this.decay=.96815,this.weight=.58767,this.density=.926,u=null===o?u:o.getScene(),this._viewPort=new e.Viewport(0,0,1,1).toGlobal(u.getEngine()),this.mesh=null!==s?s:i.CreateDefaultMesh("VolumetricLightScatteringMesh",u),this._createPass(u,n.passRatio||n),this.onApply=function(e){f._updateMeshScreenCoordinates(u),e.setTexture("lightScatteringSampler",f._volumetricLightScatteringRTT),e.setFloat("exposure",f.exposure),e.setFloat("decay",f.decay),e.setFloat("weight",f.weight),e.setFloat("density",f.density),e.setVector2("meshPositionOnScreen",f._screenCoordinates)}}return __extends(i,t),i.prototype.isReady=function(t,i){var r=t.getMesh(),n=[],o=[e.VertexBuffer.PositionKind],s=t.getMaterial(),a=!1;r===this.mesh&&(this.useDiffuseColor?n.push("#define DIFFUSE_COLOR_RENDER"):s&&n.push(void 0!==s.diffuseTexture?"#define BASIC_RENDER":"#define DIFFUSE_COLOR_RENDER"),n.push("#define NEED_UV"),a=!0),s&&(s.needAlphaTesting()&&n.push("#define ALPHATEST"),void 0!==s.opacityTexture&&(n.push("#define OPACITY"),s.opacityTexture.getAlphaFromRGB&&n.push("#define OPACITYRGB"),a||n.push("#define NEED_UV")),r.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(o.push(e.VertexBuffer.UVKind),n.push("#define UV1")),r.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(o.push(e.VertexBuffer.UV2Kind),n.push("#define UV2"))),r.useBones&&r.computeBonesUsingShaders&&(o.push(e.VertexBuffer.MatricesIndicesKind),o.push(e.VertexBuffer.MatricesWeightsKind),n.push("#define BONES"),n.push("#define BonesPerMesh "+(r.skeleton.bones.length+1))),i&&(n.push("#define INSTANCES"),o.push("world0"),o.push("world1"),o.push("world2"),o.push("world3"));var h=n.join("\n");return this._cachedDefines!==h&&(this._cachedDefines=h,this._volumetricLightScatteringPass=r.getScene().getEngine().createEffect({vertexElement:"depth",fragmentElement:"volumetricLightScatteringPass"},o,["world","mBones","viewProjection","diffuseMatrix","opacityLevel","color"],["diffuseSampler","opacitySampler"],h)),this._volumetricLightScatteringPass.isReady()},i.prototype.setCustomMeshPosition=function(e){this._customMeshPosition=e},i.prototype.getCustomMeshPosition=function(){return this._customMeshPosition},i.prototype.dispose=function(e){var i=e.getScene().customRenderTargets.indexOf(this._volumetricLightScatteringRTT);-1!==i&&e.getScene().customRenderTargets.splice(i,1),this._volumetricLightScatteringRTT.dispose(),t.prototype.dispose.call(this,e)},i.prototype.getPass=function(){return this._volumetricLightScatteringRTT},i.prototype._meshExcluded=function(e){return this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)?!0:!1},i.prototype._createPass=function(t,i){var r=this,n=t.getEngine();this._volumetricLightScatteringRTT=new e.RenderTargetTexture("volumetricLightScatteringMap",{width:n.getRenderWidth()*i,height:n.getRenderHeight()*i},t,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1,t.customRenderTargets.push(this._volumetricLightScatteringRTT);var o,s=function(t){var i=t.getRenderingMesh();if(!r._meshExcluded(i)){var n=i.getScene(),o=n.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id];if(r.isReady(t,a)){o.enableEffect(r._volumetricLightScatteringPass),i._bind(t,r._volumetricLightScatteringPass,e.Material.TriangleFillMode);var h=t.getMaterial();if(r._volumetricLightScatteringPass.setMatrix("viewProjection",n.getTransformMatrix()),h&&(i===r.mesh||h.needAlphaTesting()||void 0!==h.opacityTexture)){var l=h.getAlphaTestTexture();!r.useDiffuseColor&&void 0!==l||i!==r.mesh||r._volumetricLightScatteringPass.setColor3("color",h.diffuseColor),(h.needAlphaTesting()||i===r.mesh&&l&&!r.useDiffuseColor)&&(r._volumetricLightScatteringPass.setTexture("diffuseSampler",l),l&&r._volumetricLightScatteringPass.setMatrix("diffuseMatrix",l.getTextureMatrix())),void 0!==h.opacityTexture&&(r._volumetricLightScatteringPass.setTexture("opacitySampler",h.opacityTexture),r._volumetricLightScatteringPass.setFloat("opacityLevel",h.opacityTexture.level))}i.useBones&&i.computeBonesUsingShaders&&r._volumetricLightScatteringPass.setMatrices("mBones",i.skeleton.getTransformMatrices()),i._processRendering(t,r._volumetricLightScatteringPass,e.Material.TriangleFillMode,s,a,function(e,t){return r._volumetricLightScatteringPass.setMatrix("world",t)})}}}},a=new e.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRender=function(){o=t.clearColor,t.clearColor=a},this._volumetricLightScatteringRTT.onAfterRender=function(){t.clearColor=o},this._volumetricLightScatteringRTT.customRenderFunction=function(i,r,n){var o,a=t.getEngine();for(o=0;o<i.length;o++)s(i.data[o]);for(a.setAlphaTesting(!0),o=0;o<r.length;o++)s(r.data[o]);if(a.setAlphaTesting(!1),n.length){for(o=0;o<n.length;o++){var h=n.data[o];h._alphaIndex=h.getMesh().alphaIndex,h._distanceToCamera=h.getBoundingInfo().boundingSphere.centerWorld.subtract(t.activeCamera.position).length()}var l=n.data.slice(0,n.length);for(l.sort(function(e,t){return e._alphaIndex>t._alphaIndex?1:e._alphaIndex<t._alphaIndex?-1:e._distanceToCamera<t._distanceToCamera?1:e._distanceToCamera>t._distanceToCamera?-1:0}),a.setAlphaMode(e.Engine.ALPHA_COMBINE),o=0;o<l.length;o++)s(l[o]);a.setAlphaMode(e.Engine.ALPHA_DISABLE)}}},i.prototype._updateMeshScreenCoordinates=function(t){var i=t.getTransformMatrix(),r=e.Vector3.Project(this.useCustomMeshPosition?this._customMeshPosition:this.mesh.position,e.Matrix.Identity(),i,this._viewPort);this._screenCoordinates.x=r.x/this._viewPort.width,this._screenCoordinates.y=r.y/this._viewPort.height,this.invert&&(this._screenCoordinates.y=1-this._screenCoordinates.y)},i.CreateDefaultMesh=function(t,i){var r=e.Mesh.CreatePlane(t,1,i);return r.billboardMode=e.AbstractMesh.BILLBOARDMODE_ALL,r.material=new e.StandardMaterial(t+"Material",i),r},i}(e.PostProcess);e.VolumetricLightScatteringPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s){var a=this;void 0===o&&(o=1),t.call(this,n.getEngine(),i),this.LensChromaticAberrationEffect="LensChromaticAberrationEffect",this.HighlightsEnhancingEffect="HighlightsEnhancingEffect",this.LensDepthOfFieldEffect="LensDepthOfFieldEffect",this._scene=n,this._depthTexture=n.enableDepthRenderer().getDepthMap(),r.grain_texture?this._grainTexture=r.grain_texture:this._createGrainTexture(),this._edgeBlur=r.edge_blur?r.edge_blur:0,this._grainAmount=r.grain_amount?r.grain_amount:0,this._chromaticAberration=r.chromatic_aberration?r.chromatic_aberration:0,this._distortion=r.distortion?r.distortion:0,this._highlightsGain=void 0!==r.dof_gain?r.dof_gain:-1,this._highlightsThreshold=r.dof_threshold?r.dof_threshold:1,this._dofDistance=void 0!==r.dof_focus_distance?r.dof_focus_distance:-1,this._dofAperture=r.dof_aperture?r.dof_aperture:1,this._dofDarken=r.dof_darken?r.dof_darken:0,this._dofPentagon=void 0!==r.dof_pentagon?r.dof_pentagon:!0,this._blurNoise=void 0!==r.blur_noise?r.blur_noise:!0,this._createChromaticAberrationPostProcess(o),this._createHighlightsPostProcess(o),this._createDepthOfFieldPostProcess(o/4),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),this.LensChromaticAberrationEffect,function(){return a._chromaticAberrationPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),this.HighlightsEnhancingEffect,function(){return a._highlightsPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),this.LensDepthOfFieldEffect,function(){return a._depthOfFieldPostProcess},!0)),-1==this._highlightsGain&&this._disableEffect(this.HighlightsEnhancingEffect,null),n.postProcessRenderPipelineManager.addPipeline(this),s&&n.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,s)}return __extends(i,t),i.prototype.setEdgeBlur=function(e){this._edgeBlur=e},i.prototype.disableEdgeBlur=function(){this._edgeBlur=0},i.prototype.setGrainAmount=function(e){this._grainAmount=e},i.prototype.disableGrain=function(){this._grainAmount=0},i.prototype.setChromaticAberration=function(e){this._chromaticAberration=e},i.prototype.disableChromaticAberration=function(){this._chromaticAberration=0},i.prototype.setEdgeDistortion=function(e){this._distortion=e},i.prototype.disableEdgeDistortion=function(){this._distortion=0},i.prototype.setFocusDistance=function(e){this._dofDistance=e},i.prototype.disableDepthOfField=function(){this._dofDistance=-1},i.prototype.setAperture=function(e){this._dofAperture=e},i.prototype.setDarkenOutOfFocus=function(e){this._dofDarken=e},i.prototype.enablePentagonBokeh=function(){this._dofPentagon=!0},i.prototype.disablePentagonBokeh=function(){this._dofPentagon=!1},i.prototype.enableNoiseBlur=function(){this._blurNoise=!0},i.prototype.disableNoiseBlur=function(){this._blurNoise=!1},i.prototype.setHighlightsGain=function(e){this._highlightsGain=e},i.prototype.setHighlightsThreshold=function(e){-1==this._highlightsGain&&(this._highlightsGain=1),this._highlightsThreshold=e},i.prototype.disableHighlights=function(){this._highlightsGain=-1},i.prototype.dispose=function(e){void 0===e&&(e=!1),this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras),this._chromaticAberrationPostProcess=void 0,this._highlightsPostProcess=void 0,this._depthOfFieldPostProcess=void 0,this._grainTexture.dispose(),e&&this._scene.disableDepthRenderer()},i.prototype._createChromaticAberrationPostProcess=function(t){var i=this;this._chromaticAberrationPostProcess=new e.PostProcess("LensChromaticAberration","chromaticAberration",["chromatic_aberration","screen_width","screen_height"],[],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._chromaticAberrationPostProcess.onApply=function(e){e.setFloat("chromatic_aberration",i._chromaticAberration),e.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),e.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height)}},i.prototype._createHighlightsPostProcess=function(t){var i=this;this._highlightsPostProcess=new e.PostProcess("LensHighlights","lensHighlights",["pentagon","gain","threshold","screen_width","screen_height"],[],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._highlightsPostProcess.onApply=function(e){e.setFloat("gain",i._highlightsGain),e.setFloat("threshold",i._highlightsThreshold),e.setBool("pentagon",i._dofPentagon),e.setTextureFromPostProcess("textureSampler",i._chromaticAberrationPostProcess),e.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),e.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height)}},i.prototype._createDepthOfFieldPostProcess=function(t){var i=this;this._depthOfFieldPostProcess=new e.PostProcess("LensDepthOfField","depthOfField",["grain_amount","blur_noise","screen_width","screen_height","distortion","dof_enabled","screen_distance","aperture","darken","edge_blur","highlights","near","far"],["depthSampler","grainSampler","highlightsSampler"],t,null,e.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._depthOfFieldPostProcess.onApply=function(e){e.setTexture("depthSampler",i._depthTexture),e.setTexture("grainSampler",i._grainTexture),e.setTextureFromPostProcess("textureSampler",i._highlightsPostProcess),e.setTextureFromPostProcess("highlightsSampler",i._depthOfFieldPostProcess),e.setFloat("grain_amount",i._grainAmount),e.setBool("blur_noise",i._blurNoise),e.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),e.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height),e.setFloat("distortion",i._distortion),e.setBool("dof_enabled",-1!=i._dofDistance),e.setFloat("screen_distance",1/(.1-1/i._dofDistance)),e.setFloat("aperture",i._dofAperture),e.setFloat("darken",i._dofDarken),e.setFloat("edge_blur",i._edgeBlur),e.setBool("highlights",-1!=i._highlightsGain),e.setFloat("near",i._scene.activeCamera.minZ),e.setFloat("far",i._scene.activeCamera.maxZ)}},i.prototype._createGrainTexture=function(){var t=512;this._grainTexture=new e.DynamicTexture("LensNoiseTexture",t,this._scene,!1,e.Texture.BILINEAR_SAMPLINGMODE),this._grainTexture.wrapU=e.Texture.WRAP_ADDRESSMODE,this._grainTexture.wrapV=e.Texture.WRAP_ADDRESSMODE;for(var i,r=this._grainTexture.getContext(),n=function(e,t){return Math.random()*(t-e)+e},o=0;t>o;o++)for(var s=0;t>s;s++)i=Math.floor(255*n(.42,.58)),r.fillStyle="rgb("+i+", "+i+", "+i+")",r.fillRect(o,s,1,1);this._grainTexture.update(!1)},i}(e.PostProcessRenderPipeline);e.LensRenderingPipeline=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s,a,h){var l=this;t.call(this,i,"colorCorrection",null,["colorTable"],n,o,s,a,h),this._colorTableTexture=new e.Texture(r,o.getScene(),!0,!1,e.Texture.TRILINEAR_SAMPLINGMODE),this._colorTableTexture.anisotropicFilteringLevel=1,this._colorTableTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._colorTableTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this.onApply=function(e){e.setTexture("colorTable",l._colorTableTexture)}}return __extends(i,t),i}(e.PostProcess);e.ColorCorrectionPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){t.call(this,i,r,o),this.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:n})}return __extends(i,t),i}(e.FreeCamera);e.AnaglyphFreeCamera=t;var i=function(t){function i(i,r,n,o,s,a,h){t.call(this,i,r,n,o,s,h),this.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:a})}return __extends(i,t),i}(e.ArcRotateCamera);e.AnaglyphArcRotateCamera=i;var r=function(t){function i(i,r,n,o){t.call(this,i,r,o),this.setCameraRigMode(e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH,{interaxialDistance:n})}return __extends(i,t),i}(e.GamepadCamera);e.AnaglyphGamepadCamera=r;var n=function(t){function i(i,r,n,o,s){t.call(this,i,r,s),this.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n})}return __extends(i,t),i}(e.FreeCamera);e.StereoscopicFreeCamera=n;var o=function(t){function i(i,r,n,o,s,a,h,l){t.call(this,i,r,n,o,s,l),this.setCameraRigMode(h?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:a})}return __extends(i,t),i}(e.ArcRotateCamera);e.StereoscopicArcRotateCamera=o;var s=function(t){function i(i,r,n,o,s){t.call(this,i,r,s),this.setCameraRigMode(o?e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER,{interaxialDistance:n})}return __extends(i,t),i}(e.GamepadCamera);e.StereoscopicGamepadCamera=s}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(r,n,o,s,a){var h=this;void 0===s&&(s=null),t.call(this,n.getEngine(),r),this.gaussCoeff=.3,this.gaussMean=1,this.gaussStandDev=.8,this.exposure=1,this.minimumLuminance=1,this.maximumLuminance=1e20,this.luminanceIncreaserate=.5,this.luminanceDecreaseRate=.5,this.brightThreshold=.8,this._needUpdate=!0,this._scene=n,this._createBrightPassPostProcess(n,o),this._createDownSampleX4PostProcess(n,o),this._createGaussianBlurPostProcess(n,o),this._createTextureAdderPostProcess(n,o),this._createLuminanceGeneratorPostProcess(n),this._createHDRPostProcess(n,o),this._originalPostProcess=null===s?new e.PassPostProcess("hdr",o,null,e.Texture.BILINEAR_SAMPLINGMODE,n.getEngine(),!1):s,this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),"HDRPassPostProcess",function(){return h._originalPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),"HDRBrightPass",function(){return h._brightPassPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),"HDRDownSampleX4",function(){return h._downSampleX4PostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),"HDRGaussianBlurH",function(){return h._guassianBlurHPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),"HDRGaussianBlurV",function(){return h._guassianBlurVPostProcess},!0)),this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),"HDRTextureAdder",function(){return h._textureAdderPostProcess},!0));for(var l=function(t){h.addEffect(new e.PostProcessRenderEffect(n.getEngine(),"HDRDownSampler"+t,function(){return h._downSamplePostProcesses[t]},!0))},c=i.LUM_STEPS-1;c>=0;c--)l(c);this.addEffect(new e.PostProcessRenderEffect(n.getEngine(),"HDR",function(){return h._hdrPostProcess},!0)),n.postProcessRenderPipelineManager.addPipeline(this),null!==a&&n.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(r,a),this.update()}return __extends(i,t),i.prototype.update=function(){this._needUpdate=!0},i.prototype.getCurrentLuminance=function(){return this._hdrCurrentLuminance},i.prototype.getOutputLuminance=function(){return this._hdrOutputLuminance},i.prototype.dispose=function(){this._originalPostProcess=void 0,this._brightPassPostProcess=void 0,this._downSampleX4PostProcess=void 0,this._guassianBlurHPostProcess=void 0,this._guassianBlurVPostProcess=void 0,this._textureAdderPostProcess=void 0;for(var e=i.LUM_STEPS-1;e>=0;e--)this._downSamplePostProcesses[e]=void 0;this._hdrPostProcess=void 0,this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name,this._scene.cameras)},i.prototype._createHDRPostProcess=function(t,i){var r=this,n=0;this._hdrOutputLuminance=-1,this._hdrCurrentLuminance=1,this._hdrPostProcess=new e.PostProcess("hdr","hdr",["exposure","avgLuminance"],["otherSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define HDR"),this._hdrPostProcess.onApply=function(i){if(r._hdrOutputLuminance<0)r._hdrOutputLuminance=r._hdrCurrentLuminance;else{var o=(n-(n+t.getEngine().getDeltaTime()))/1e3;r._hdrCurrentLuminance<r._hdrOutputLuminance+r.luminanceDecreaseRate*o?r._hdrOutputLuminance+=r.luminanceDecreaseRate*o:r._hdrCurrentLuminance>r._hdrOutputLuminance-r.luminanceIncreaserate*o?r._hdrOutputLuminance-=r.luminanceIncreaserate*o:r._hdrOutputLuminance=r._hdrCurrentLuminance}r._hdrOutputLuminance=e.Tools.Clamp(r._hdrOutputLuminance,r.minimumLuminance,r.maximumLuminance),n+=t.getEngine().getDeltaTime(),i.setTextureFromPostProcess("textureSampler",r._textureAdderPostProcess),i.setTextureFromPostProcess("otherSampler",r._originalPostProcess),i.setFloat("exposure",r.exposure),i.setFloat("avgLuminance",r._hdrOutputLuminance),r._needUpdate=!1}},i.prototype._createTextureAdderPostProcess=function(t,i){var r=this;this._textureAdderPostProcess=new e.PostProcess("hdr","hdr",[],["otherSampler"],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define TEXTURE_ADDER"),this._textureAdderPostProcess.onApply=function(e){e.setTextureFromPostProcess("otherSampler",r._originalPostProcess)}},i.prototype._createDownSampleX4PostProcess=function(t,i){var r=this,n=new Array(32);this._downSampleX4PostProcess=new e.PostProcess("hdr","hdr",["dsOffsets"],[],i/4,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define DOWN_SAMPLE_X4"),this._downSampleX4PostProcess.onApply=function(e){if(r._needUpdate)for(var t=0,i=-2;2>i;i++)for(var o=-2;2>o;o++)n[t]=(i+.5)*(1/r._downSampleX4PostProcess.width),n[t+1]=(o+.5)*(1/r._downSampleX4PostProcess.height),t+=2;e.setArray2("dsOffsets",n)}},i.prototype._createBrightPassPostProcess=function(t,i){var r=this,n=new Array(8),o=function(e){if(r._needUpdate){var t=1/r._brightPassPostProcess.width,i=1/r._brightPassPostProcess.height;n[0]=-.5*t,n[1]=.5*i,n[2]=.5*t,n[3]=.5*i,n[4]=-.5*t,n[5]=-.5*i,n[6]=.5*t,n[7]=-.5*i}e.setArray2("dsOffsets",n),e.setFloat("brightThreshold",r.brightThreshold)};this._brightPassPostProcess=new e.PostProcess("hdr","hdr",["dsOffsets","brightThreshold"],[],i,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define BRIGHT_PASS"),this._brightPassPostProcess.onApply=o},i.prototype._createLuminanceGeneratorPostProcess=function(t){var r,n=this,o=i.LUM_STEPS,s=new Array(8),a=new Array(18);this._downSamplePostProcesses=new Array(o);var h=function(e,t){var i=1/e,r=1/t;s[0]=-.5*i,s[1]=.5*r,s[2]=.5*i,s[3]=.5*r,s[4]=-.5*i,s[5]=-.5*r,s[6]=.5*i,s[7]=-.5*r},l=function(e,t){for(var i=0,r=-1;2>r;r++)for(var n=-1;2>n;n++)a[i]=r/e,a[i+1]=n/t,i+=2},c=function(e){n._needUpdate&&h(n._textureAdderPostProcess.width,n._textureAdderPostProcess.height),e.setTextureFromPostProcess("textureSampler",n._textureAdderPostProcess),e.setArray2("lumOffsets",s)},u=function(e){var t=e;return function(e){h(n._downSamplePostProcesses[t].width,n._downSamplePostProcesses[t].height),l(n._downSamplePostProcesses[t].width,n._downSamplePostProcesses[t].height),r=.5/n._downSamplePostProcesses[t].width,e.setTextureFromPostProcess("textureSampler",n._downSamplePostProcesses[t+1]),e.setFloat("halfDestPixelSize",r),e.setArray2("dsOffsets",a)}},f=function(i){var r=t.getEngine().readPixels(0,0,1,1),o=new e.Vector4(1/16581375,1/65025,1/255,1);n._hdrCurrentLuminance=(r[0]*o.x+r[1]*o.y+r[2]*o.z+r[3]*o.w)/100},d={width:Math.pow(3,o-1),height:Math.pow(3,o-1)};this._downSamplePostProcesses[o-1]=new e.PostProcess("hdr","hdr",["lumOffsets"],[],d,null,e.Texture.NEAREST_SAMPLINGMODE,t.getEngine(),!1,"#define LUMINANCE_GENERATOR",e.Engine.TEXTURETYPE_FLOAT),this._downSamplePostProcesses[o-1].onApply=c;for(var p=o-2;p>=0;p--){var m=Math.pow(3,p);d={width:m,height:m};var g="#define DOWN_SAMPLE\n";0===p&&(g+="#define FINAL_DOWN_SAMPLE\n"),this._downSamplePostProcesses[p]=new e.PostProcess("hdr","hdr",["dsOffsets","halfDestPixelSize"],[],d,null,e.Texture.NEAREST_SAMPLINGMODE,t.getEngine(),!1,g,e.Engine.TEXTURETYPE_FLOAT),this._downSamplePostProcesses[p].onApply=u(p),0===p&&(this._downSamplePostProcesses[p].onAfterRender=f)}},i.prototype._createGaussianBlurPostProcess=function(t,i){var r=this,n=new Array(9),o=new Array(9),s=new Array(9),a=["blurOffsets","blurWeights"],h=function(e){for(var r={width:t.getEngine().getRenderWidth()*(i/4),height:t.getEngine().getRenderHeight()*(i/4)},s=0;9>s;s++){var a=(s-4)*(1/(e===!0?r.height:r.width));e?o[s]=a:n[s]=a}},l=function(){for(var e=0,t=0;9>t;t++)e=(t-4)/4,s[t]=r.gaussCoeff*(1/Math.sqrt(2*Math.PI*r.gaussStandDev))*Math.exp(-((e-r.gaussMean)*(e-r.gaussMean))/(2*r.gaussStandDev*r.gaussStandDev))},c=function(e){return function(t){r._needUpdate&&(l(),h(e)),t.setArray("blurOffsets",e?o:n),t.setArray("blurWeights",s)}};this._guassianBlurHPostProcess=new e.PostProcess("hdr","hdr",a,[],i/4,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define GAUSSIAN_BLUR_H"),this._guassianBlurHPostProcess.onApply=c(!1),this._guassianBlurVPostProcess=new e.PostProcess("hdr","hdr",a,[],i/4,null,e.Texture.BILINEAR_SAMPLINGMODE,t.getEngine(),!1,"#define GAUSSIAN_BLUR_V"),this._guassianBlurVPostProcess.onApply=c(!0)},i.LUM_STEPS=6,i}(e.PostProcessRenderPipeline);e.HDRRenderingPipeline=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this.edges=new Array,this.edgesConnectedCount=0}return e}(),i=function(){function i(e,t,i){void 0===t&&(t=.95),void 0===i&&(i=!1),this._linesPositions=new Array,this._linesNormals=new Array,this._linesIndices=new Array,this._buffers=new Array,this._checkVerticesInsteadOfIndices=!1,this._source=e,this._checkVerticesInsteadOfIndices=i,this._epsilon=t,this._prepareRessources(),this._generateEdgesLines()}return i.prototype._prepareRessources=function(){this._lineShader||(this._lineShader=new e.ShaderMaterial("lineShader",this._source.getScene(),"line",{attributes:["position","normal"],uniforms:["worldViewProjection","color","width","aspectRatio"]}),this._lineShader.disableDepthWrite=!0,this._lineShader.backFaceCulling=!1)},i.prototype.dispose=function(){this._vb0.dispose(),this._vb1.dispose(),this._source.getScene().getEngine()._releaseBuffer(this._ib),this._lineShader.dispose()},i.prototype._processEdgeForAdjacencies=function(e,t,i,r,n){return e===i&&t===r||e===r&&t===i?0:e===r&&t===n||e===n&&t===r?1:e===n&&t===i||e===i&&t===n?2:-1},i.prototype._processEdgeForAdjacenciesWithVertices=function(e,t,i,r,n){return e.equalsWithEpsilon(i)&&t.equalsWithEpsilon(r)||e.equalsWithEpsilon(r)&&t.equalsWithEpsilon(i)?0:e.equalsWithEpsilon(r)&&t.equalsWithEpsilon(n)||e.equalsWithEpsilon(n)&&t.equalsWithEpsilon(r)?1:e.equalsWithEpsilon(n)&&t.equalsWithEpsilon(i)||e.equalsWithEpsilon(i)&&t.equalsWithEpsilon(n)?2:-1},i.prototype._checkEdge=function(t,i,r,n,o){var s;if(void 0===i)s=!0;else{var a=e.Vector3.Dot(r[t],r[i]);s=a<this._epsilon}if(s){var h=this._linesPositions.length/3,l=n.subtract(o);l.normalize(),this._linesPositions.push(n.x),this._linesPositions.push(n.y),this._linesPositions.push(n.z),this._linesPositions.push(n.x),this._linesPositions.push(n.y),this._linesPositions.push(n.z),this._linesPositions.push(o.x),this._linesPositions.push(o.y),this._linesPositions.push(o.z),this._linesPositions.push(o.x),this._linesPositions.push(o.y),this._linesPositions.push(o.z),this._linesNormals.push(o.x),this._linesNormals.push(o.y),this._linesNormals.push(o.z),this._linesNormals.push(-1),this._linesNormals.push(o.x),this._linesNormals.push(o.y),this._linesNormals.push(o.z),this._linesNormals.push(1),this._linesNormals.push(n.x),this._linesNormals.push(n.y),this._linesNormals.push(n.z),this._linesNormals.push(-1),this._linesNormals.push(n.x),this._linesNormals.push(n.y),this._linesNormals.push(n.z),this._linesNormals.push(1),this._linesIndices.push(h),this._linesIndices.push(h+1),this._linesIndices.push(h+2),this._linesIndices.push(h),this._linesIndices.push(h+2),this._linesIndices.push(h+3)}},i.prototype._generateEdgesLines=function(){var i,r,n=this._source.getVerticesData(e.VertexBuffer.PositionKind),o=this._source.getIndices(),s=new Array,a=new Array;for(i=0;i<o.length;i+=3){r=new t;var h=o[i],l=o[i+1],c=o[i+2];r.p0=new e.Vector3(n[3*h],n[3*h+1],n[3*h+2]),r.p1=new e.Vector3(n[3*l],n[3*l+1],n[3*l+2]),r.p2=new e.Vector3(n[3*c],n[3*c+1],n[3*c+2]);var u=e.Vector3.Cross(r.p1.subtract(r.p0),r.p2.subtract(r.p1));u.normalize(),a.push(u),s.push(r)}for(i=0;i<s.length;i++){r=s[i];for(var f=i+1;f<s.length;f++){var d=s[f];if(3===r.edgesConnectedCount)break;if(3!==d.edgesConnectedCount)for(var p=o[3*f],m=o[3*f+1],g=o[3*f+2],_=0;3>_;_++){var v;if(void 0===r.edges[_]){switch(_){case 0:v=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(r.p0,r.p1,d.p0,d.p1,d.p2):this._processEdgeForAdjacencies(o[3*i],o[3*i+1],p,m,g);break;case 1:v=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(r.p1,r.p2,d.p0,d.p1,d.p2):this._processEdgeForAdjacencies(o[3*i+1],o[3*i+2],p,m,g);break;case 2:v=this._checkVerticesInsteadOfIndices?this._processEdgeForAdjacenciesWithVertices(r.p2,r.p0,d.p0,d.p1,d.p2):this._processEdgeForAdjacencies(o[3*i+2],o[3*i],p,m,g)}if(-1!==v&&(r.edges[_]=f,d.edges[v]=i,r.edgesConnectedCount++,d.edgesConnectedCount++,3===r.edgesConnectedCount))break}}}}for(i=0;i<s.length;i++){var y=s[i];this._checkEdge(i,y.edges[0],a,y.p0,y.p1),this._checkEdge(i,y.edges[1],a,y.p1,y.p2),this._checkEdge(i,y.edges[2],a,y.p2,y.p0)}var x=this._source.getScene().getEngine();this._vb0=new e.VertexBuffer(x,this._linesPositions,e.VertexBuffer.PositionKind,!1),this._vb1=new e.VertexBuffer(x,this._linesNormals,e.VertexBuffer.NormalKind,!1,!1,4),this._buffers[e.VertexBuffer.PositionKind]=this._vb0,this._buffers[e.VertexBuffer.NormalKind]=this._vb1,this._ib=x.createIndexBuffer(this._linesIndices),this._indicesCount=this._linesIndices.length},i.prototype.render=function(){if(this._lineShader.isReady()){var e=this._source.getScene(),t=e.getEngine();this._lineShader._preBind(),t.bindMultiBuffers(this._buffers,this._ib,this._lineShader.getEffect()),e.resetCachedMaterial(),this._lineShader.setColor4("color",this._source.edgesColor),this._lineShader.setFloat("width",this._source.edgesWidth/50),this._lineShader.setFloat("aspectRatio",t.getAspectRatio(e.activeCamera)),this._lineShader.bind(this._source.getWorldMatrix()),t.draw(!0,0,this._indicesCount),this._lineShader.unbind(),t.setDepthWrite(!0)}},i}();e.EdgesRenderer=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){!function(e){e[e.Hable=0]="Hable",e[e.Reinhard=1]="Reinhard",e[e.HejiDawson=2]="HejiDawson",e[e.Photographic=3]="Photographic"}(e.TonemappingOperator||(e.TonemappingOperator={}));var t=e.TonemappingOperator,i=function(i){function r(r,n,o,s,a,h,l){var c=this;void 0===a&&(a=e.Texture.BILINEAR_SAMPLINGMODE),void 0===l&&(l=e.Engine.TEXTURETYPE_UNSIGNED_INT),this._operator=n,this._exposureAdjustment=o;var u=["_ExposureAdjustment"],f="#define ";n===t.Hable?f+="HABLE_TONEMAPPING":n===t.Reinhard?f+="REINHARD_TONEMAPPING":n===t.HejiDawson?f+="OPTIMIZED_HEJIDAWSON_TONEMAPPING":n===t.Photographic&&(f+="PHOTOGRAPHIC_TONEMAPPING"),i.call(this,r,"tonemap",u,null,1,s,a,h,!0,f,l),this.onApply=function(e){e.setFloat("_ExposureAdjustment",c._exposureAdjustment)}}return __extends(r,i),r}(e.PostProcess);e.TonemapPostProcess=i}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore={anaglyphPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D leftSampler;\r\n\r\nvoid main(void)\r\n{\r\n    vec4 leftFrag = texture2D(leftSampler, vUV);\r\n    leftFrag = vec4(1.0, leftFrag.g, leftFrag.b, 1.0);\r\n\r\n	vec4 rightFrag = texture2D(textureSampler, vUV);\r\n    rightFrag = vec4(rightFrag.r, 1.0, 1.0, 1.0);\r\n\r\n    gl_FragColor = vec4(rightFrag.rgb * leftFrag.rgb, 1.0);\r\n}",blackAndWhitePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nvoid main(void) \r\n{\r\n	float luminance = dot(texture2D(textureSampler, vUV).rgb, vec3(0.3, 0.59, 0.11));\r\n	gl_FragColor = vec4(luminance, luminance, luminance, 1.0);\r\n}",blurPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Parameters\r\nuniform vec2 screenSize;\r\nuniform vec2 direction;\r\nuniform float blurWidth;\r\n\r\nvoid main(void)\r\n{\r\n	float weights[7];\r\n	weights[0] = 0.05;\r\n	weights[1] = 0.1;\r\n	weights[2] = 0.2;\r\n	weights[3] = 0.3;\r\n	weights[4] = 0.2;\r\n	weights[5] = 0.1;\r\n	weights[6] = 0.05;\r\n\r\n	vec2 texelSize = vec2(1.0 / screenSize.x, 1.0 / screenSize.y);\r\n	vec2 texelStep = texelSize * direction * blurWidth;\r\n	vec2 start = vUV - 3.0 * texelStep;\r\n\r\n	vec4 baseColor = vec4(0., 0., 0., 0.);\r\n	vec2 texelOffset = vec2(0., 0.);\r\n\r\n	for (int i = 0; i < 7; i++)\r\n	{\r\n		baseColor += texture2D(textureSampler, start + texelOffset) * weights[i];\r\n		texelOffset += texelStep;\r\n	}\r\n\r\n	gl_FragColor = baseColor;\r\n}",
  brickPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform float numberOfBricksHeight;\r\nuniform float numberOfBricksWidth;\r\nuniform vec3 brickColor;\r\nuniform vec3 jointColor;\r\n\r\nfloat rand(vec2 n) {\r\n	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n	const vec2 d = vec2(0.0, 1.0);\r\n	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\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);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n	float total = 0.0, amplitude = 1.0;\r\n	for (int i = 0; i < 4; i++) {\r\n		total += noise(n) * amplitude;\r\n		n += n;\r\n		amplitude *= 0.5;\r\n	}\r\n	return total;\r\n}\r\n\r\nfloat round(float number){\r\n	return sign(number)*floor(abs(number) + 0.5);\r\n}\r\n\r\nvoid main(void)\r\n{\r\n	float brickW = 1.0 / numberOfBricksWidth;\r\n	float brickH = 1.0 / numberOfBricksHeight;\r\n	float jointWPercentage = 0.01;\r\n	float jointHPercentage = 0.05;\r\n	vec3 color = brickColor;\r\n	float yi = vUV.y / brickH;\r\n	float nyi = round(yi);\r\n	float xi = vUV.x / brickW;\r\n\r\n	if (mod(floor(yi), 2.0) == 0.0){\r\n		xi = xi - 0.5;\r\n	}\r\n\r\n	float nxi = round(xi);\r\n	vec2 brickvUV = vec2((xi - floor(xi)) / brickH, (yi - floor(yi)) /  brickW);\r\n\r\n	if (yi < nyi + jointHPercentage && yi > nyi - jointHPercentage){\r\n		color = mix(jointColor, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);\r\n	}\r\n	else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){\r\n		color = mix(jointColor, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);\r\n	}\r\n	else {\r\n		float brickColorSwitch = mod(floor(yi) + floor(xi), 3.0);\r\n\r\n		if (brickColorSwitch == 0.0)\r\n			color = mix(color, vec3(0.33, 0.33, 0.33), 0.3);\r\n		else if (brickColorSwitch == 2.0)\r\n			color = mix(color, vec3(0.11, 0.11, 0.11), 0.3);\r\n	}\r\n\r\n	gl_FragColor = vec4(color, 1.0);\r\n}",chromaticAberrationPixelShader:"// BABYLON.JS Chromatic Aberration GLSL Shader\r\n// Author: Olivier Guyot\r\n// Separates very slightly R, G and B colors on the edges of the screen\r\n// Inspired by Francois Tarlier & Martins Upitis\r\n\r\n#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// samplers\r\nuniform sampler2D textureSampler;	// original color\r\n\r\n// uniforms\r\nuniform float chromatic_aberration;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\nvoid main(void)\r\n{\r\n	vec2 centered_screen_pos = vec2(vUV.x - 0.5, vUV.y - 0.5);\r\n	float radius2 = centered_screen_pos.x*centered_screen_pos.x\r\n		+ centered_screen_pos.y*centered_screen_pos.y;\r\n	float radius = sqrt(radius2);\r\n\r\n	vec4 original = texture2D(textureSampler, vUV);\r\n\r\n	if (chromatic_aberration > 0.0) {\r\n		//index of refraction of each color channel, causing chromatic dispersion\r\n		vec3 ref_indices = vec3(-0.3, 0.0, 0.3);\r\n		float ref_shiftX = chromatic_aberration * radius * 17.0 / screen_width;\r\n		float ref_shiftY = chromatic_aberration * radius * 17.0 / screen_height;\r\n\r\n		// shifts for red, green & blue\r\n		vec2 ref_coords_r = vec2(vUV.x + ref_indices.r*ref_shiftX, vUV.y + ref_indices.r*ref_shiftY*0.5);\r\n		vec2 ref_coords_g = vec2(vUV.x + ref_indices.g*ref_shiftX, vUV.y + ref_indices.g*ref_shiftY*0.5);\r\n		vec2 ref_coords_b = vec2(vUV.x + ref_indices.b*ref_shiftX, vUV.y + ref_indices.b*ref_shiftY*0.5);\r\n\r\n		original.r = texture2D(textureSampler, ref_coords_r).r;\r\n		original.g = texture2D(textureSampler, ref_coords_g).g;\r\n		original.b = texture2D(textureSampler, ref_coords_b).b;\r\n	}\r\n\r\n	gl_FragColor = original;\r\n}",cloudPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vUV;\r\n\r\nuniform vec4 skyColor;\r\nuniform vec4 cloudColor;\r\n\r\nfloat rand(vec2 n) {\r\n	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n	const vec2 d = vec2(0.0, 1.0);\r\n	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\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);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n	float total = 0.0, amplitude = 1.0;\r\n	for (int i = 0; i < 4; i++) {\r\n		total += noise(n) * amplitude;\r\n		n += n;\r\n		amplitude *= 0.5;\r\n	}\r\n	return total;\r\n}\r\n\r\nvoid main() {\r\n\r\n	vec2 p = vUV * 12.0;\r\n	vec4 c = mix(skyColor, cloudColor, fbm(p));\r\n	gl_FragColor = c;\r\n\r\n}\r\n\r\n",colorPixelShader:"precision highp float;\r\n\r\nuniform vec4 color;\r\n\r\nvoid main(void) {\r\n	gl_FragColor = color;\r\n}",colorVertexShader:"precision highp float;\r\n\r\n// Attributes\r\nattribute vec3 position;\r\n\r\n// Uniforms\r\nuniform mat4 worldViewProjection;\r\n\r\nvoid main(void) {\r\n	gl_Position = worldViewProjection * vec4(position, 1.0);\r\n}",colorCorrectionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// samplers\r\nuniform sampler2D textureSampler;	// screen render\r\nuniform sampler2D colorTable;		// color table with modified colors\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\n// constants\r\nconst float SLICE_COUNT = 16.0;		// how many slices in the color cube; 1 slice = 1 pixel\r\n// it means the image is 256x16 pixels\r\n\r\nvec4 sampleAs3DTexture(sampler2D texture, vec3 uv, float width) {\r\n	float sliceSize = 1.0 / width;              // space of 1 slice\r\n	float slicePixelSize = sliceSize / width;           // space of 1 pixel\r\n	float sliceInnerSize = slicePixelSize * (width - 1.0);  // space of width pixels\r\n	float zSlice0 = min(floor(uv.z * width), width - 1.0);\r\n	float zSlice1 = min(zSlice0 + 1.0, width - 1.0);\r\n	float xOffset = slicePixelSize * 0.5 + uv.x * sliceInnerSize;\r\n	float s0 = xOffset + (zSlice0 * sliceSize);\r\n	float s1 = xOffset + (zSlice1 * sliceSize);\r\n	vec4 slice0Color = texture2D(texture, vec2(s0, uv.y));\r\n	vec4 slice1Color = texture2D(texture, vec2(s1, uv.y));\r\n	float zOffset = mod(uv.z * width, 1.0);\r\n	vec4 result = mix(slice0Color, slice1Color, zOffset);\r\n	return result;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n	vec4 screen_color = texture2D(textureSampler, vUV);\r\n	gl_FragColor = sampleAs3DTexture(colorTable, screen_color.rgb, SLICE_COUNT);\r\n\r\n}",convolutionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nuniform vec2 screenSize;\r\nuniform float kernel[9];\r\n\r\nvoid main(void)\r\n{\r\n	vec2 onePixel = vec2(1.0, 1.0) / screenSize;\r\n	vec4 colorSum =\r\n		texture2D(textureSampler, vUV + onePixel * vec2(-1, -1)) * kernel[0] +\r\n		texture2D(textureSampler, vUV + onePixel * vec2(0, -1)) * kernel[1] +\r\n		texture2D(textureSampler, vUV + onePixel * vec2(1, -1)) * kernel[2] +\r\n		texture2D(textureSampler, vUV + onePixel * vec2(-1, 0)) * kernel[3] +\r\n		texture2D(textureSampler, vUV + onePixel * vec2(0, 0)) * kernel[4] +\r\n		texture2D(textureSampler, vUV + onePixel * vec2(1, 0)) * kernel[5] +\r\n		texture2D(textureSampler, vUV + onePixel * vec2(-1, 1)) * kernel[6] +\r\n		texture2D(textureSampler, vUV + onePixel * vec2(0, 1)) * kernel[7] +\r\n		texture2D(textureSampler, vUV + onePixel * vec2(1, 1)) * kernel[8];\r\n\r\n	float kernelWeight =\r\n		kernel[0] +\r\n		kernel[1] +\r\n		kernel[2] +\r\n		kernel[3] +\r\n		kernel[4] +\r\n		kernel[5] +\r\n		kernel[6] +\r\n		kernel[7] +\r\n		kernel[8];\r\n\r\n	if (kernelWeight <= 0.0) {\r\n		kernelWeight = 1.0;\r\n	}\r\n\r\n	gl_FragColor = vec4((colorSum / kernelWeight).rgb, 1);\r\n}",defaultPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define MAP_EXPLICIT	0.\r\n#define MAP_SPHERICAL	1.\r\n#define MAP_PLANAR		2.\r\n#define MAP_CUBIC		3.\r\n#define MAP_PROJECTION	4.\r\n#define MAP_SKYBOX		5.\r\n\r\n// Constants\r\nuniform vec3 vEyePosition;\r\nuniform vec3 vAmbientColor;\r\nuniform vec4 vDiffuseColor;\r\n#ifdef SPECULARTERM\r\nuniform vec4 vSpecularColor;\r\n#endif\r\nuniform vec3 vEmissiveColor;\r\n\r\n// Input\r\nvarying vec3 vPositionW;\r\n\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n// Lights\r\n#ifdef LIGHT0\r\nuniform vec4 vLightData0;\r\nuniform vec4 vLightDiffuse0;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular0;\r\n#endif\r\n#ifdef SHADOW0\r\nvarying vec4 vPositionFromLight0;\r\nuniform sampler2D shadowSampler0;\r\nuniform vec3 shadowsInfo0;\r\n#endif\r\n#ifdef SPOTLIGHT0\r\nuniform vec4 vLightDirection0;\r\n#endif\r\n#ifdef HEMILIGHT0\r\nuniform vec3 vLightGround0;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\nuniform vec4 vLightData1;\r\nuniform vec4 vLightDiffuse1;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular1;\r\n#endif\r\n#ifdef SHADOW1\r\nvarying vec4 vPositionFromLight1;\r\nuniform sampler2D shadowSampler1;\r\nuniform vec3 shadowsInfo1;\r\n#endif\r\n#ifdef SPOTLIGHT1\r\nuniform vec4 vLightDirection1;\r\n#endif\r\n#ifdef HEMILIGHT1\r\nuniform vec3 vLightGround1;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\nuniform vec4 vLightData2;\r\nuniform vec4 vLightDiffuse2;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular2;\r\n#endif\r\n#ifdef SHADOW2\r\nvarying vec4 vPositionFromLight2;\r\nuniform sampler2D shadowSampler2;\r\nuniform vec3 shadowsInfo2;\r\n#endif\r\n#ifdef SPOTLIGHT2\r\nuniform vec4 vLightDirection2;\r\n#endif\r\n#ifdef HEMILIGHT2\r\nuniform vec3 vLightGround2;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\nuniform vec4 vLightData3;\r\nuniform vec4 vLightDiffuse3;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular3;\r\n#endif\r\n#ifdef SHADOW3\r\nvarying vec4 vPositionFromLight3;\r\nuniform sampler2D shadowSampler3;\r\nuniform vec3 shadowsInfo3;\r\n#endif\r\n#ifdef SPOTLIGHT3\r\nuniform vec4 vLightDirection3;\r\n#endif\r\n#ifdef HEMILIGHT3\r\nuniform vec3 vLightGround3;\r\n#endif\r\n#endif\r\n\r\n// Samplers\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform sampler2D diffuseSampler;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n#ifdef AMBIENT\r\nvarying vec2 vAmbientUV;\r\nuniform sampler2D ambientSampler;\r\nuniform vec2 vAmbientInfos;\r\n#endif\r\n\r\n#ifdef OPACITY	\r\nvarying vec2 vOpacityUV;\r\nuniform sampler2D opacitySampler;\r\nuniform vec2 vOpacityInfos;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform sampler2D emissiveSampler;\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform sampler2D specularSampler;\r\n#endif\r\n\r\n// Fresnel\r\n#ifdef FRESNEL\r\nfloat computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)\r\n{\r\n	float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);\r\n	return clamp(fresnelTerm, 0., 1.);\r\n}\r\n#endif\r\n\r\n#ifdef DIFFUSEFRESNEL\r\nuniform vec4 diffuseLeftColor;\r\nuniform vec4 diffuseRightColor;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\nuniform vec4 opacityParts;\r\n#endif\r\n\r\n#ifdef REFLECTIONFRESNEL\r\nuniform vec4 reflectionLeftColor;\r\nuniform vec4 reflectionRightColor;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\nuniform vec4 emissiveLeftColor;\r\nuniform vec4 emissiveRightColor;\r\n#endif\r\n\r\n// Reflection\r\n#ifdef REFLECTION\r\nvarying vec3 vPositionUVW;\r\nuniform samplerCube reflectionCubeSampler;\r\nuniform sampler2D reflection2DSampler;\r\nuniform vec3 vReflectionInfos;\r\nuniform mat4 reflectionMatrix;\r\nuniform mat4 view;\r\n\r\n#ifdef ROUGHNESS\r\nuniform float roughness;\r\n#endif\r\n\r\nvec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)\r\n{\r\n	if (mode == MAP_SPHERICAL)\r\n	{\r\n		vec3 coords = vec3(view * vec4(worldNormal, 0.0));\r\n\r\n		return vec3(reflectionMatrix * vec4(coords, 1.0));\r\n	}\r\n	else if (mode == MAP_PLANAR)\r\n	{\r\n		vec3 viewDir = worldPos.xyz - vEyePosition;\r\n		vec3 coords = normalize(reflect(viewDir, worldNormal));\r\n\r\n		return vec3(reflectionMatrix * vec4(coords, 1));\r\n	}\r\n	else if (mode == MAP_CUBIC)\r\n	{\r\n		vec3 viewDir = worldPos.xyz - vEyePosition;\r\n		vec3 coords = reflect(viewDir, worldNormal);\r\n\r\n		return vec3(reflectionMatrix * vec4(coords, 0));\r\n	}\r\n	else if (mode == MAP_PROJECTION)\r\n	{\r\n		return vec3(reflectionMatrix * (view * worldPos));\r\n	}\r\n	else if (mode == MAP_SKYBOX)\r\n	{\r\n		return vPositionUVW;\r\n	}\r\n\r\n	return vec3(0, 0, 0);\r\n}\r\n#endif\r\n\r\n// Shadows\r\n#ifdef SHADOWS\r\n\r\nfloat unpack(vec4 color)\r\n{\r\n	const vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);\r\n	return dot(color, bit_shift);\r\n}\r\n\r\nfloat unpackHalf(vec2 color)\r\n{\r\n	return color.x + (color.y / 255.0);\r\n}\r\n\r\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)\r\n{\r\n	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n	depth = 0.5 * depth + vec3(0.5);\r\n	vec2 uv = depth.xy;\r\n\r\n	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n	{\r\n		return 1.0;\r\n	}\r\n\r\n	float shadow = unpack(texture2D(shadowSampler, uv)) + bias;\r\n\r\n	if (depth.z > shadow)\r\n	{\r\n		return darkness;\r\n	}\r\n	return 1.;\r\n}\r\n\r\nfloat computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, float mapSize, float bias, float darkness)\r\n{\r\n	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n	depth = 0.5 * depth + vec3(0.5);\r\n	vec2 uv = depth.xy;\r\n\r\n	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n	{\r\n		return 1.0;\r\n	}\r\n\r\n	float visibility = 1.;\r\n\r\n	vec2 poissonDisk[4];\r\n	poissonDisk[0] = vec2(-0.94201624, -0.39906216);\r\n	poissonDisk[1] = vec2(0.94558609, -0.76890725);\r\n	poissonDisk[2] = vec2(-0.094184101, -0.92938870);\r\n	poissonDisk[3] = vec2(0.34495938, 0.29387760);\r\n\r\n	// Poisson Sampling\r\n	float biasedDepth = depth.z - bias;\r\n\r\n	if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] / mapSize)) < biasedDepth) visibility -= 0.25;\r\n	if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] / mapSize)) < biasedDepth) visibility -= 0.25;\r\n	if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] / mapSize)) < biasedDepth) visibility -= 0.25;\r\n	if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] / mapSize)) < biasedDepth) visibility -= 0.25;\r\n\r\n	return  min(1.0, visibility + darkness);\r\n}\r\n\r\n// Thanks to http://devmaster.net/\r\nfloat linstep(float low, float high, float v) {\r\n	return clamp((v - low) / (high - low), 0.0, 1.0);\r\n}\r\n\r\nfloat ChebychevInequality(vec2 moments, float compare, float bias)\r\n{\r\n	float p = smoothstep(compare - bias, compare, moments.x);\r\n	float variance = max(moments.y - moments.x * moments.x, 0.02);\r\n	float d = compare - moments.x;\r\n	float p_max = linstep(0.2, 1.0, variance / (variance + d * d));\r\n\r\n	return clamp(max(p, p_max), 0.0, 1.0);\r\n}\r\n\r\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias, float darkness)\r\n{\r\n	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n	depth = 0.5 * depth + vec3(0.5);\r\n	vec2 uv = depth.xy;\r\n\r\n	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z >= 1.0)\r\n	{\r\n		return 1.0;\r\n	}\r\n\r\n	vec4 texel = texture2D(shadowSampler, uv);\r\n\r\n	vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\r\n	return min(1.0, 1.0 - ChebychevInequality(moments, depth.z, bias) + darkness);\r\n}\r\n#endif\r\n\r\n// Bump\r\n#ifdef BUMP\r\n#extension GL_OES_standard_derivatives : enable\r\nvarying vec2 vBumpUV;\r\nuniform vec2 vBumpInfos;\r\nuniform sampler2D bumpSampler;\r\n\r\n// Thanks to http://www.thetenthplanet.de/archives/1180\r\nmat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv)\r\n{\r\n	// get edge vectors of the pixel triangle\r\n	vec3 dp1 = dFdx(p);\r\n	vec3 dp2 = dFdy(p);\r\n	vec2 duv1 = dFdx(uv);\r\n	vec2 duv2 = dFdy(uv);\r\n\r\n	// solve the linear system\r\n	vec3 dp2perp = cross(dp2, normal);\r\n	vec3 dp1perp = cross(normal, dp1);\r\n	vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;\r\n	vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y;\r\n\r\n	// construct a scale-invariant frame \r\n	float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal)));\r\n	return mat3(tangent * invmax, binormal * invmax, normal);\r\n}\r\n\r\nvec3 perturbNormal(vec3 viewDir)\r\n{\r\n	vec3 map = texture2D(bumpSampler, vBumpUV).xyz;\r\n	map = map * 255. / 127. - 128. / 127.;\r\n	mat3 TBN = cotangent_frame(vNormalW * vBumpInfos.y, -viewDir, vBumpUV);\r\n	return normalize(TBN * map);\r\n}\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE    0.\r\n#define FOGMODE_EXP     1.\r\n#define FOGMODE_EXP2    2.\r\n#define FOGMODE_LINEAR  3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n	float fogCoeff = 1.0;\r\n	float fogStart = vFogInfos.y;\r\n	float fogEnd = vFogInfos.z;\r\n	float fogDensity = vFogInfos.w;\r\n\r\n	if (FOGMODE_LINEAR == vFogInfos.x)\r\n	{\r\n		fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n	}\r\n	else if (FOGMODE_EXP == vFogInfos.x)\r\n	{\r\n		fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n	}\r\n	else if (FOGMODE_EXP2 == vFogInfos.x)\r\n	{\r\n		fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n	}\r\n\r\n	return clamp(fogCoeff, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\n// Light Computing\r\nstruct lightingInfo\r\n{\r\n	vec3 diffuse;\r\n#ifdef SPECULARTERM\r\n	vec3 specular;\r\n#endif\r\n};\r\n\r\nlightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, float range, float glossiness) {\r\n	lightingInfo result;\r\n\r\n	vec3 lightVectorW;\r\n	float attenuation = 1.0;\r\n	if (lightData.w == 0.)\r\n	{\r\n		vec3 direction = lightData.xyz - vPositionW;\r\n\r\n		attenuation = max(0., 1.0 - length(direction) / range);\r\n		lightVectorW = normalize(direction);\r\n	}\r\n	else\r\n	{\r\n		lightVectorW = normalize(-lightData.xyz);\r\n	}\r\n\r\n	// diffuse\r\n	float ndl = max(0., dot(vNormal, lightVectorW));\r\n	result.diffuse = ndl * diffuseColor * attenuation;\r\n\r\n#ifdef SPECULARTERM\r\n	// Specular\r\n	vec3 angleW = normalize(viewDirectionW + lightVectorW);\r\n	float specComp = max(0., dot(vNormal, angleW));\r\n	specComp = pow(specComp, max(1., glossiness));\r\n\r\n	result.specular = specComp * specularColor * attenuation;\r\n#endif\r\n	return result;\r\n}\r\n\r\nlightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor, float range, float glossiness) {\r\n	lightingInfo result;\r\n\r\n	vec3 direction = lightData.xyz - vPositionW;\r\n	vec3 lightVectorW = normalize(direction);\r\n	float attenuation = max(0., 1.0 - length(direction) / range);\r\n\r\n	// diffuse\r\n	float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\r\n	float spotAtten = 0.0;\r\n\r\n	if (cosAngle >= lightDirection.w)\r\n	{\r\n		cosAngle = max(0., pow(cosAngle, lightData.w));\r\n		spotAtten = clamp((cosAngle - lightDirection.w) / (1. - cosAngle), 0.0, 1.0);\r\n\r\n		// Diffuse\r\n		float ndl = max(0., dot(vNormal, -lightDirection.xyz));\r\n		result.diffuse = ndl * spotAtten * diffuseColor * attenuation;\r\n\r\n#ifdef SPECULARTERM\r\n		// Specular\r\n		vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\r\n		float specComp = max(0., dot(vNormal, angleW));\r\n		specComp = pow(specComp, max(1., glossiness));\r\n\r\n		result.specular = specComp * specularColor * spotAtten * attenuation;\r\n#endif\r\n\r\n		return result;\r\n	}\r\n\r\n	result.diffuse = vec3(0.);\r\n#ifdef SPECULARTERM\r\n	result.specular = vec3(0.);\r\n#endif\r\n\r\n	return result;\r\n}\r\n\r\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor, float glossiness) {\r\n	lightingInfo result;\r\n\r\n	// Diffuse\r\n	float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\r\n	result.diffuse = mix(groundColor, diffuseColor, ndl);\r\n\r\n#ifdef SPECULARTERM\r\n	// Specular\r\n	vec3 angleW = normalize(viewDirectionW + lightData.xyz);\r\n	float specComp = max(0., dot(vNormal, angleW));\r\n	specComp = pow(specComp, max(1., glossiness));\r\n\r\n	result.specular = specComp * specularColor;\r\n#endif\r\n\r\n	return result;\r\n}\r\n\r\nvoid main(void) {\r\n	// Clip plane\r\n#ifdef CLIPPLANE\r\n	if (fClipDistance > 0.0)\r\n		discard;\r\n#endif\r\n\r\n	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\r\n\r\n	// Base color\r\n	vec4 baseColor = vec4(1., 1., 1., 1.);\r\n	vec3 diffuseColor = vDiffuseColor.rgb;\r\n\r\n	// Alpha\r\n	float alpha = vDiffuseColor.a;\r\n\r\n#ifdef DIFFUSE\r\n	baseColor = texture2D(diffuseSampler, vDiffuseUV);\r\n\r\n#ifdef ALPHATEST\r\n	if (baseColor.a < 0.4)\r\n		discard;\r\n#endif\r\n\r\n#ifdef ALPHAFROMDIFFUSE\r\n	alpha *= baseColor.a;\r\n#endif\r\n\r\n	baseColor.rgb *= vDiffuseInfos.y;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\n	baseColor.rgb *= vColor.rgb;\r\n#endif\r\n\r\n	// Bump\r\n#ifdef NORMAL\r\n	vec3 normalW = normalize(vNormalW);\r\n#else\r\n	vec3 normalW = vec3(1.0, 1.0, 1.0);\r\n#endif\r\n\r\n\r\n#ifdef BUMP\r\n	normalW = perturbNormal(viewDirectionW);\r\n#endif\r\n\r\n	// Ambient color\r\n	vec3 baseAmbientColor = vec3(1., 1., 1.);\r\n\r\n#ifdef AMBIENT\r\n	baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\r\n#endif\r\n\r\n\r\n	// Specular map\r\n#ifdef SPECULARTERM\r\n	float glossiness = vSpecularColor.a;\r\n	vec3 specularColor = vSpecularColor.rgb;\r\n\r\n	#ifdef SPECULAR\r\n		vec4 specularMapColor = texture2D(specularSampler, vSpecularUV);\r\n		specularColor = specularMapColor.rgb;\r\n		#ifdef GLOSSINESS\r\n			glossiness = glossiness * specularMapColor.a;\r\n		#endif\r\n	#endif\r\n#else\r\n	float glossiness = 0.;\r\n#endif\r\n\r\n	// Lighting\r\n	vec3 diffuseBase = vec3(0., 0., 0.);\r\n#ifdef SPECULARTERM\r\n	vec3 specularBase = vec3(0., 0., 0.);\r\n#endif\r\n	float shadow = 1.;\r\n\r\n#ifdef LIGHT0\r\n#ifndef SPECULARTERM\r\n	vec3 vLightSpecular0 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT0\r\n	lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a, glossiness);\r\n#endif\r\n#ifdef HEMILIGHT0\r\n	lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightGround0, glossiness);\r\n#endif\r\n#ifdef POINTDIRLIGHT0\r\n	lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a, glossiness);\r\n#endif\r\n#ifdef SHADOW0\r\n#ifdef SHADOWVSM0\r\n	shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0, shadowsInfo0.z, shadowsInfo0.x);\r\n#else\r\n	#ifdef SHADOWPCF0\r\n		shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z, shadowsInfo0.x);\r\n	#else\r\n		shadow = computeShadow(vPositionFromLight0, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);\r\n	#endif\r\n#endif\r\n#else\r\n	shadow = 1.;\r\n#endif\r\n	diffuseBase += info.diffuse * shadow;\r\n#ifdef SPECULARTERM\r\n	specularBase += info.specular * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\n#ifndef SPECULARTERM\r\n	vec3 vLightSpecular1 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT1\r\n	info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a, glossiness);\r\n#endif\r\n#ifdef HEMILIGHT1\r\n	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightGround1, glossiness);\r\n#endif\r\n#ifdef POINTDIRLIGHT1\r\n	info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a, glossiness);\r\n#endif\r\n#ifdef SHADOW1\r\n#ifdef SHADOWVSM1\r\n	shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1, shadowsInfo1.z, shadowsInfo1.x);\r\n#else\r\n	#ifdef SHADOWPCF1\r\n		shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z, shadowsInfo1.x);\r\n	#else\r\n		shadow = computeShadow(vPositionFromLight1, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);\r\n	#endif\r\n#endif\r\n#else\r\n	shadow = 1.;\r\n#endif\r\n	diffuseBase += info.diffuse * shadow;\r\n#ifdef SPECULARTERM\r\n	specularBase += info.specular * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\n#ifndef SPECULARTERM\r\n	vec3 vLightSpecular2 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT2\r\n	info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a, glossiness);\r\n#endif\r\n#ifdef HEMILIGHT2\r\n	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightGround2, glossiness);\r\n#endif\r\n#ifdef POINTDIRLIGHT2\r\n	info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a, glossiness);\r\n#endif\r\n#ifdef SHADOW2\r\n#ifdef SHADOWVSM2\r\n	shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2, shadowsInfo2.z, shadowsInfo2.x);\r\n#else\r\n	#ifdef SHADOWPCF2\r\n		shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z, shadowsInfo2.x);\r\n	#else\r\n		shadow = computeShadow(vPositionFromLight2, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);\r\n	#endif	\r\n#endif	\r\n#else\r\n	shadow = 1.;\r\n#endif\r\n	diffuseBase += info.diffuse * shadow;\r\n#ifdef SPECULARTERM\r\n	specularBase += info.specular * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\n#ifndef SPECULARTERM\r\n	vec3 vLightSpecular3 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT3\r\n	info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a, glossiness);\r\n#endif\r\n#ifdef HEMILIGHT3\r\n	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightGround3, glossiness);\r\n#endif\r\n#ifdef POINTDIRLIGHT3\r\n	info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a, glossiness);\r\n#endif\r\n#ifdef SHADOW3\r\n#ifdef SHADOWVSM3\r\n	shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3, shadowsInfo3.z, shadowsInfo3.x);\r\n#else\r\n	#ifdef SHADOWPCF3\r\n		shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z, shadowsInfo3.x);\r\n	#else\r\n		shadow = computeShadow(vPositionFromLight3, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);\r\n	#endif	\r\n#endif	\r\n#else\r\n	shadow = 1.;\r\n#endif\r\n	diffuseBase += info.diffuse * shadow;\r\n#ifdef SPECULARTERM\r\n	specularBase += info.specular * shadow;\r\n#endif\r\n#endif\r\n\r\n	// Reflection\r\n	vec3 reflectionColor = vec3(0., 0., 0.);\r\n\r\n#ifdef REFLECTION\r\n	vec3 vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), normalW);\r\n\r\n	if (vReflectionInfos.z != 0.0)\r\n	{\r\n		float bias = 0.;\r\n\r\n#ifdef ROUGHNESS\r\n		bias = roughness;\r\n#endif\r\n\r\n#ifdef SPECULARTERM\r\n#ifdef SPECULAR\r\n#ifdef GLOSSINESS\r\n		bias *= (1.0 - specularMapColor.a);\r\n#endif\r\n#endif\r\n#endif\r\n\r\n		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.y * shadow;\r\n	}\r\n	else\r\n	{\r\n		vec2 coords = vReflectionUVW.xy;\r\n\r\n		if (vReflectionInfos.x == MAP_PROJECTION)\r\n		{\r\n			coords /= vReflectionUVW.z;\r\n		}\r\n\r\n		coords.y = 1.0 - coords.y;\r\n\r\n		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y * shadow;\r\n	}\r\n\r\n#ifdef REFLECTIONFRESNEL\r\n	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);\r\n\r\n#ifdef REFLECTIONFRESNELFROMSPECULAR\r\n#ifdef SPECULARTERM\r\n	reflectionColor *= specularColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#else\r\n	reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#else\r\n	reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#endif\r\n#endif\r\n\r\n\r\n#ifdef OPACITY\r\n	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);\r\n\r\n#ifdef OPACITYRGB\r\n	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);\r\n	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\r\n#else\r\n	alpha *= opacityMap.a * vOpacityInfos.y;\r\n#endif\r\n\r\n#endif\r\n\r\n#ifdef VERTEXALPHA\r\n	alpha *= vColor.a;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\n	float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);\r\n\r\n	alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;\r\n#endif\r\n\r\n	// Emissive\r\n	vec3 emissiveColor = vEmissiveColor;\r\n#ifdef EMISSIVE\r\n    emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\n	float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);\r\n\r\n	emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;\r\n#endif\r\n\r\n	// Fresnel\r\n#ifdef DIFFUSEFRESNEL\r\n	float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);\r\n\r\n	diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;\r\n#endif\r\n\r\n	// Composition\r\n#ifdef EMISSIVEASILLUMINATION\r\n	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n#else\r\n    vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n#endif\r\n\r\n#ifdef SPECULARTERM\r\n	vec3 finalSpecular = specularBase * specularColor;\r\n#else\r\n	vec3 finalSpecular = vec3(0.0);\r\n#endif\r\n\r\n#ifdef SPECULAROVERALPHA\r\n	alpha = clamp(alpha + dot(finalSpecular, vec3(0.3, 0.59, 0.11)), 0., 1.);\r\n#endif\r\n\r\n// Composition\r\n#ifdef EMISSIVEASILLUMINATION\r\n    vec4 color = vec4(clamp(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor + emissiveColor, 0.0, 1.0), alpha);\r\n#else\r\n    vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\r\n#endif\r\n\r\n#ifdef FOG\r\n	float fog = CalcFogFactor();\r\n	color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n	gl_FragColor = color;\r\n}",defaultVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec3 position;\r\n#ifdef NORMAL\r\nattribute vec3 normal;\r\n#endif\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#ifdef VERTEXCOLOR\r\nattribute vec4 color;\r\n#endif\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniforms\r\n\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 view;\r\nuniform mat4 viewProjection;\r\n\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform mat4 diffuseMatrix;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n#ifdef AMBIENT\r\nvarying vec2 vAmbientUV;\r\nuniform mat4 ambientMatrix;\r\nuniform vec2 vAmbientInfos;\r\n#endif\r\n\r\n#ifdef OPACITY\r\nvarying vec2 vOpacityUV;\r\nuniform mat4 opacityMatrix;\r\nuniform vec2 vOpacityInfos;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform mat4 emissiveMatrix;\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform mat4 specularMatrix;\r\n#endif\r\n\r\n#ifdef BUMP\r\nvarying vec2 vBumpUV;\r\nuniform vec2 vBumpInfos;\r\nuniform mat4 bumpMatrix;\r\n#endif\r\n\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#ifdef POINTSIZE\r\nuniform float pointSize;\r\n#endif\r\n\r\n// Output\r\nvarying vec3 vPositionW;\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\n#ifdef SHADOWS\r\n#ifdef LIGHT0\r\nuniform mat4 lightMatrix0;\r\nvarying vec4 vPositionFromLight0;\r\n#endif\r\n#ifdef LIGHT1\r\nuniform mat4 lightMatrix1;\r\nvarying vec4 vPositionFromLight1;\r\n#endif\r\n#ifdef LIGHT2\r\nuniform mat4 lightMatrix2;\r\nvarying vec4 vPositionFromLight2;\r\n#endif\r\n#ifdef LIGHT3\r\nuniform mat4 lightMatrix3;\r\nvarying vec4 vPositionFromLight3;\r\n#endif\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nvarying vec3 vPositionUVW;\r\n#endif\r\n\r\nvoid main(void) {\r\n	mat4 finalWorld;\r\n\r\n#ifdef REFLECTION\r\n	vPositionUVW = position;\r\n#endif \r\n\r\n#ifdef INSTANCES\r\n	finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n	finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n	mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n\r\n#ifdef BONES4\r\n	mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n	finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n#else\r\n	finalWorld = finalWorld * (m0 + m1 + m2);\r\n#endif \r\n\r\n#endif\r\n	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n\r\n	vec4 worldPos = finalWorld * vec4(position, 1.0);\r\n	vPositionW = vec3(worldPos);\r\n\r\n#ifdef NORMAL\r\n	vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\r\n#endif\r\n\r\n	// Texture coordinates\r\n#ifndef UV1\r\n	vec2 uv = vec2(0., 0.);\r\n#endif\r\n#ifndef UV2\r\n	vec2 uv2 = vec2(0., 0.);\r\n#endif\r\n\r\n#ifdef DIFFUSE\r\n	if (vDiffuseInfos.x == 0.)\r\n	{\r\n		vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#ifdef AMBIENT\r\n	if (vAmbientInfos.x == 0.)\r\n	{\r\n		vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#ifdef OPACITY\r\n	if (vOpacityInfos.x == 0.)\r\n	{\r\n		vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\n	if (vEmissiveInfos.x == 0.)\r\n	{\r\n		vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\n	if (vSpecularInfos.x == 0.)\r\n	{\r\n		vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#ifdef BUMP\r\n	if (vBumpInfos.x == 0.)\r\n	{\r\n		vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n	// Clip plane\r\n#ifdef CLIPPLANE\r\n	fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n	// Fog\r\n#ifdef FOG\r\n	fFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n	// Shadows\r\n#ifdef SHADOWS\r\n#ifdef LIGHT0\r\n	vPositionFromLight0 = lightMatrix0 * worldPos;\r\n#endif\r\n#ifdef LIGHT1\r\n	vPositionFromLight1 = lightMatrix1 * worldPos;\r\n#endif\r\n#ifdef LIGHT2\r\n	vPositionFromLight2 = lightMatrix2 * worldPos;\r\n#endif\r\n#ifdef LIGHT3\r\n	vPositionFromLight3 = lightMatrix3 * worldPos;\r\n#endif\r\n#endif\r\n\r\n	// Vertex color\r\n#ifdef VERTEXCOLOR\r\n	vColor = color;\r\n#endif\r\n\r\n	// Point size\r\n#ifdef POINTSIZE\r\n	gl_PointSize = pointSize;\r\n#endif\r\n}",
  depthPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\nuniform float far;\r\n\r\nvoid main(void)\r\n{\r\n#ifdef ALPHATEST\r\n	if (texture2D(diffuseSampler, vUV).a < 0.4)\r\n		discard;\r\n#endif\r\n\r\n	float depth = (gl_FragCoord.z / gl_FragCoord.w) / far;\r\n	gl_FragColor = vec4(depth, depth * depth, 0.0, 1.0);\r\n}",depthVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attribute\r\nattribute vec3 position;\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniform\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 viewProjection;\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(NEED_UV)\r\nvarying vec2 vUV;\r\nuniform mat4 diffuseMatrix;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef INSTANCES\r\n	mat4 finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n	mat4 finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n	mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n	mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n	finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n#else\r\n	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\r\n#ifdef UV1\r\n	vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n#endif\r\n#ifdef UV2\r\n	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n#endif\r\n#endif\r\n}",depthBoxBlurPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Parameters\r\nuniform vec2 screenSize;\r\n\r\nvoid main(void)\r\n{\r\n	vec4 colorDepth = vec4(0.0);\r\n\r\n	for (int x = -OFFSET; x <= OFFSET; x++)\r\n		for (int y = -OFFSET; y <= OFFSET; y++)\r\n			colorDepth += texture2D(textureSampler, vUV + vec2(x, y) / screenSize);\r\n\r\n	gl_FragColor = (colorDepth / float((OFFSET * 2 + 1) * (OFFSET * 2 + 1)));\r\n}",depthOfFieldPixelShader:'// BABYLON.JS Depth-of-field GLSL Shader\r\n// Author: Olivier Guyot\r\n// Does depth-of-field blur, edge blur\r\n// Inspired by Francois Tarlier & Martins Upitis\r\n\r\n#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n\r\n// samplers\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D highlightsSampler;\r\nuniform sampler2D depthSampler;\r\nuniform sampler2D grainSampler;\r\n\r\n// uniforms\r\nuniform float grain_amount;\r\nuniform bool blur_noise;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\nuniform float distortion;\r\nuniform bool dof_enabled;\r\n//uniform float focus_distance;		// not needed; already used to compute screen distance\r\nuniform float screen_distance;		// precomputed screen distance from lens center; based on focal length & desired focus distance\r\nuniform float aperture;\r\nuniform float darken;\r\nuniform float edge_blur;\r\nuniform bool highlights;\r\n\r\n// preconputed uniforms (not effect parameters)\r\nuniform float near;\r\nuniform float far;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\n// constants\r\n#define PI 		3.14159265\r\n#define TWOPI 	6.28318530\r\n#define inverse_focal_length 0.1	// a property of the lens used\r\n\r\n// common calculations\r\nvec2 centered_screen_pos;\r\nvec2 distorted_coords;\r\nfloat radius2;\r\nfloat radius;\r\n\r\n\r\n// on-the-fly constant noise\r\nvec2 rand(vec2 co)\r\n{\r\n	float noise1 = (fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453));\r\n	float noise2 = (fract(sin(dot(co, vec2(12.9898, 78.233)*2.0)) * 43758.5453));\r\n	return clamp(vec2(noise1, noise2), 0.0, 1.0);\r\n}\r\n\r\n// applies edge distortion on texture coords\r\nvec2 getDistortedCoords(vec2 coords) {\r\n\r\n	if (distortion == 0.0) { return coords; }\r\n\r\n	vec2 direction = 1.0 * normalize(centered_screen_pos);\r\n	vec2 dist_coords = vec2(0.5, 0.5);\r\n	dist_coords.x = 0.5 + direction.x * radius2 * 1.0;\r\n	dist_coords.y = 0.5 + direction.y * radius2 * 1.0;\r\n	float dist_amount = clamp(distortion*0.23, 0.0, 1.0);\r\n\r\n	dist_coords = mix(coords, dist_coords, dist_amount);\r\n\r\n	return dist_coords;\r\n}\r\n\r\n// sample screen with an offset (randomize offset angle for better smothness), returns partial sample weight\r\nfloat sampleScreen(inout vec4 color, const in vec2 offset, const in float weight) {\r\n\r\n	// compute coords with offset (a random angle is added)\r\n	vec2 coords = distorted_coords;\r\n	float angle = rand(coords * 100.0).x * TWOPI;\r\n	coords += vec2(offset.x * cos(angle) - offset.y * sin(angle), offset.x * sin(angle) + offset.y * cos(angle));\r\n\r\n	color += texture2D(textureSampler, coords)*weight;\r\n\r\n	return weight;\r\n}\r\n\r\n// returns blur level according to blur size required\r\nfloat getBlurLevel(float size) {\r\n	return min(3.0, ceil(size / 1.0));\r\n}\r\n\r\n// returns original screen color after blur\r\nvec4 getBlurColor(float size) {\r\n\r\n	vec4 col = texture2D(textureSampler, distorted_coords);\r\n	if (size == 0.0) { return col; }\r\n\r\n	// there are max. 30 samples; the number of samples chosen is dependant on the blur size\r\n	// there can be 10, 20 or 30 samples chosen; levels of blur are then 1, 2 or 3\r\n	float blur_level = getBlurLevel(size);\r\n\r\n	float w = (size / screen_width);\r\n	float h = (size / screen_height);\r\n	float total_weight = 1.0;\r\n	vec2 sample_coords;\r\n\r\n	total_weight += sampleScreen(col, vec2(-0.50*w, 0.24*h), 0.93);\r\n	total_weight += sampleScreen(col, vec2(0.30*w, -0.75*h), 0.90);\r\n	total_weight += sampleScreen(col, vec2(0.36*w, 0.96*h), 0.87);\r\n	total_weight += sampleScreen(col, vec2(-1.08*w, -0.55*h), 0.85);\r\n	total_weight += sampleScreen(col, vec2(1.33*w, -0.37*h), 0.83);\r\n	total_weight += sampleScreen(col, vec2(-0.82*w, 1.31*h), 0.80);\r\n	total_weight += sampleScreen(col, vec2(-0.31*w, -1.67*h), 0.78);\r\n	total_weight += sampleScreen(col, vec2(1.47*w, 1.11*h), 0.76);\r\n	total_weight += sampleScreen(col, vec2(-1.97*w, 0.19*h), 0.74);\r\n	total_weight += sampleScreen(col, vec2(1.42*w, -1.57*h), 0.72);\r\n\r\n	if (blur_level > 1.0) {\r\n		total_weight += sampleScreen(col, vec2(0.01*w, 2.25*h), 0.70);\r\n		total_weight += sampleScreen(col, vec2(-1.62*w, -1.74*h), 0.67);\r\n		total_weight += sampleScreen(col, vec2(2.49*w, 0.20*h), 0.65);\r\n		total_weight += sampleScreen(col, vec2(-2.07*w, 1.61*h), 0.63);\r\n		total_weight += sampleScreen(col, vec2(0.46*w, -2.70*h), 0.61);\r\n		total_weight += sampleScreen(col, vec2(1.55*w, 2.40*h), 0.59);\r\n		total_weight += sampleScreen(col, vec2(-2.88*w, -0.75*h), 0.56);\r\n		total_weight += sampleScreen(col, vec2(2.73*w, -1.44*h), 0.54);\r\n		total_weight += sampleScreen(col, vec2(-1.08*w, 3.02*h), 0.52);\r\n		total_weight += sampleScreen(col, vec2(-1.28*w, -3.05*h), 0.49);\r\n	}\r\n\r\n	if (blur_level > 2.0) {\r\n		total_weight += sampleScreen(col, vec2(3.11*w, 1.43*h), 0.46);\r\n		total_weight += sampleScreen(col, vec2(-3.36*w, 1.08*h), 0.44);\r\n		total_weight += sampleScreen(col, vec2(1.80*w, -3.16*h), 0.41);\r\n		total_weight += sampleScreen(col, vec2(0.83*w, 3.65*h), 0.38);\r\n		total_weight += sampleScreen(col, vec2(-3.16*w, -2.19*h), 0.34);\r\n		total_weight += sampleScreen(col, vec2(3.92*w, -0.53*h), 0.31);\r\n		total_weight += sampleScreen(col, vec2(-2.59*w, 3.12*h), 0.26);\r\n		total_weight += sampleScreen(col, vec2(-0.20*w, -4.15*h), 0.22);\r\n		total_weight += sampleScreen(col, vec2(3.02*w, 3.00*h), 0.15);\r\n	}\r\n\r\n	col /= total_weight;		// scales color according to weights\r\n\r\n								// darken if out of focus\r\n	if (darken > 0.0) {\r\n		col.rgb *= clamp(0.3, 1.0, 1.05 - size*0.5*darken);\r\n	}\r\n\r\n	// blur levels debug\r\n	// if(blur_level == 1.0) { col.b *= 0.5; }\r\n	// if(blur_level == 2.0) { col.r *= 0.5; }\r\n	// if(blur_level == 3.0) { col.g *= 0.5; }\r\n\r\n	return col;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n\r\n	// Common calc: position relative to screen center, screen radius, distorted coords, position in texel space\r\n	centered_screen_pos = vec2(vUV.x - 0.5, vUV.y - 0.5);\r\n	radius2 = centered_screen_pos.x*centered_screen_pos.x + centered_screen_pos.y*centered_screen_pos.y;\r\n	radius = sqrt(radius2);\r\n	distorted_coords = getDistortedCoords(vUV);		// we distort the screen coordinates (lens "magnifying" effect)\r\n	vec2 texels_coords = vec2(vUV.x * screen_width, vUV.y * screen_height);	// varies from 0 to SCREEN_WIDTH or _HEIGHT\r\n\r\n	float depth = texture2D(depthSampler, distorted_coords).r;	// depth value from DepthRenderer: 0 to 1\r\n	float distance = near + (far - near)*depth;		// actual distance from the lens\r\n	vec4 color = texture2D(textureSampler, vUV);	// original raster\r\n\r\n\r\n													// compute the circle of confusion size (CoC), i.e. blur radius depending on depth\r\n													// screen_distance is precomputed in code\r\n	float coc = abs(aperture * (screen_distance * (inverse_focal_length - 1.0 / distance) - 1.0));\r\n\r\n	// disable blur\r\n	if (dof_enabled == false || coc < 0.07) { coc = 0.0; }\r\n\r\n	// blur from edge blur effect\r\n	float edge_blur_amount = 0.0;\r\n	if (edge_blur > 0.0) {\r\n		edge_blur_amount = clamp((radius*2.0 - 1.0 + 0.15*edge_blur) * 1.5, 0.0, 1.0) * 1.3;\r\n	}\r\n\r\n	// total blur amount\r\n	float blur_amount = max(edge_blur_amount, coc);\r\n\r\n	// apply blur if necessary\r\n	if (blur_amount == 0.0) {\r\n		gl_FragColor = texture2D(textureSampler, distorted_coords);\r\n	}\r\n	else {\r\n\r\n		// add blurred color\r\n		gl_FragColor = getBlurColor(blur_amount * 1.7);\r\n\r\n		// if we have computed highlights: enhance highlights\r\n		if (highlights) {\r\n			gl_FragColor.rgb += clamp(coc, 0.0, 1.0)*texture2D(highlightsSampler, distorted_coords).rgb;\r\n		}\r\n\r\n		if (blur_noise) {\r\n			// we put a slight amount of noise in the blurred color\r\n			vec2 noise = rand(distorted_coords) * 0.01 * blur_amount;\r\n			vec2 blurred_coord = vec2(distorted_coords.x + noise.x, distorted_coords.y + noise.y);\r\n			gl_FragColor = 0.04 * texture2D(textureSampler, blurred_coord) + 0.96 * gl_FragColor;\r\n		}\r\n	}\r\n\r\n\r\n	// apply grain\r\n	if (grain_amount > 0.0) {\r\n		vec4 grain_color = texture2D(grainSampler, texels_coords*0.003);\r\n		gl_FragColor.rgb += (-0.5 + grain_color.rgb) * 0.30 * grain_amount;\r\n	}\r\n\r\n}\r\n',displayPassPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D passSampler;\r\n\r\nvoid main(void)\r\n{\r\n    gl_FragColor = texture2D(passSampler, vUV);\r\n}",filterPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nuniform mat4 kernelMatrix;\r\n\r\nvoid main(void)\r\n{\r\n	vec3 baseColor = texture2D(textureSampler, vUV).rgb;\r\n	vec3 updatedColor = (kernelMatrix * vec4(baseColor, 1.0)).rgb;\r\n\r\n	gl_FragColor = vec4(updatedColor, 1.0);\r\n}",firePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform float time;\r\nuniform vec3 c1;\r\nuniform vec3 c2;\r\nuniform vec3 c3;\r\nuniform vec3 c4;\r\nuniform vec3 c5;\r\nuniform vec3 c6;\r\nuniform vec2 speed;\r\nuniform float shift;\r\nuniform float alphaThreshold;\r\n\r\nvarying vec2 vUV;\r\n\r\nfloat rand(vec2 n) {\r\n	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n	const vec2 d = vec2(0.0, 1.0);\r\n	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\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);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n	float total = 0.0, amplitude = 1.0;\r\n	for (int i = 0; i < 4; i++) {\r\n		total += noise(n) * amplitude;\r\n		n += n;\r\n		amplitude *= 0.5;\r\n	}\r\n	return total;\r\n}\r\n\r\nvoid main() {\r\n	vec2 p = vUV * 8.0;\r\n	float q = fbm(p - time * 0.1);\r\n	vec2 r = vec2(fbm(p + q + time * speed.x - p.x - p.y), fbm(p + q - time * speed.y));\r\n	vec3 c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);\r\n	vec3 color = c * cos(shift * vUV.y);\r\n	float luminance = dot(color.rgb, vec3(0.3, 0.59, 0.11));\r\n\r\n	gl_FragColor = vec4(color, luminance * alphaThreshold + (1.0 - alphaThreshold));\r\n}",fxaaPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define FXAA_REDUCE_MIN   (1.0/128.0)\r\n#define FXAA_REDUCE_MUL   (1.0/8.0)\r\n#define FXAA_SPAN_MAX     8.0\r\n\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform vec2 texelSize;\r\n\r\nvoid main(){\r\n	vec2 localTexelSize = texelSize;\r\n	vec4 rgbNW = texture2D(textureSampler, (vUV + vec2(-1.0, -1.0) * localTexelSize));\r\n	vec4 rgbNE = texture2D(textureSampler, (vUV + vec2(1.0, -1.0) * localTexelSize));\r\n	vec4 rgbSW = texture2D(textureSampler, (vUV + vec2(-1.0, 1.0) * localTexelSize));\r\n	vec4 rgbSE = texture2D(textureSampler, (vUV + vec2(1.0, 1.0) * localTexelSize));\r\n	vec4 rgbM = texture2D(textureSampler, vUV);\r\n	vec4 luma = vec4(0.299, 0.587, 0.114, 1.0);\r\n	float lumaNW = dot(rgbNW, luma);\r\n	float lumaNE = dot(rgbNE, luma);\r\n	float lumaSW = dot(rgbSW, luma);\r\n	float lumaSE = dot(rgbSE, luma);\r\n	float lumaM = dot(rgbM, luma);\r\n	float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\r\n	float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\r\n\r\n	vec2 dir = vec2(-((lumaNW + lumaNE) - (lumaSW + lumaSE)), ((lumaNW + lumaSW) - (lumaNE + lumaSE)));\r\n\r\n	float dirReduce = max(\r\n		(lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),\r\n		FXAA_REDUCE_MIN);\r\n\r\n	float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\r\n	dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\r\n		max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\r\n		dir * rcpDirMin)) * localTexelSize;\r\n\r\n	vec4 rgbA = 0.5 * (\r\n		texture2D(textureSampler, vUV + dir * (1.0 / 3.0 - 0.5)) +\r\n		texture2D(textureSampler, vUV + dir * (2.0 / 3.0 - 0.5)));\r\n\r\n	vec4 rgbB = rgbA * 0.5 + 0.25 * (\r\n		texture2D(textureSampler, vUV + dir *  -0.5) +\r\n		texture2D(textureSampler, vUV + dir * 0.5));\r\n	float lumaB = dot(rgbB, luma);\r\n	if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\r\n		gl_FragColor = rgbA;\r\n	}\r\n	else {\r\n		gl_FragColor = rgbB;\r\n	}\r\n}",grassPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform vec3 herb1Color;\r\nuniform vec3 herb2Color;\r\nuniform vec3 herb3Color;\r\nuniform vec3 groundColor;\r\n\r\nfloat rand(vec2 n) {\r\n	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n	const vec2 d = vec2(0.0, 1.0);\r\n	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\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);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n	float total = 0.0, amplitude = 1.0;\r\n	for (int i = 0; i < 4; i++) {\r\n		total += noise(n) * amplitude;\r\n		n += n;\r\n		amplitude *= 0.5;\r\n	}\r\n	return total;\r\n}\r\n\r\nvoid main(void) {\r\n	vec3 color = mix(groundColor, herb1Color, rand(gl_FragCoord.xy * 4.0));\r\n	color = mix(color, herb2Color, rand(gl_FragCoord.xy * 8.0));\r\n	color = mix(color, herb3Color, rand(gl_FragCoord.xy));\r\n	color = mix(color, herb1Color, fbm(gl_FragCoord.xy * 16.0));\r\n	gl_FragColor = vec4(color, 1.0);\r\n}",hdrPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform sampler2D textureSampler;\r\nvarying vec2 vUV;\r\n\r\n#if defined(GAUSSIAN_BLUR_H) || defined(GAUSSIAN_BLUR_V)\r\nuniform float blurOffsets[9];\r\nuniform float blurWeights[9];\r\n\r\nvoid main(void) {\r\n	vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\r\n\r\n	for (int i = 0; i < 9; i++) {\r\n		#ifdef GAUSSIAN_BLUR_H\r\n		color += (texture2D(textureSampler, vUV + vec2(blurOffsets[i], 0.0)) * blurWeights[i]);\r\n		#else\r\n		color += (texture2D(textureSampler, vUV + vec2(0.0, blurOffsets[i])) * blurWeights[i]);\r\n		#endif\r\n	}\r\n\r\n	color.a = 1.0;\r\n	gl_FragColor = color;\r\n}\r\n#endif\r\n\r\n#if defined(TEXTURE_ADDER)\r\nuniform sampler2D otherSampler;\r\n\r\nvoid main() {\r\n	vec4 sum = texture2D(textureSampler, vUV) + texture2D(otherSampler, vUV);\r\n	sum.a = clamp(sum.a, 0.0, 1.0);\r\n\r\n	gl_FragColor = sum;\r\n}\r\n#endif\r\n\r\n#if defined(LUMINANCE_GENERATOR)\r\nuniform vec2 lumOffsets[4];\r\n\r\nvoid main() {\r\n	float average = 0.0;\r\n	vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\r\n	float maximum = -1e20;\r\n\r\n	for (int i = 0; i < 4; i++) {\r\n		color = texture2D(textureSampler, vUV + lumOffsets[i]);\r\n\r\n		float GreyValue = length(color.rgb);\r\n\r\n		maximum = max(maximum, GreyValue);\r\n		average += (0.25 * log(1e-5 + GreyValue));\r\n	}\r\n\r\n	average = exp(average);\r\n\r\n	gl_FragColor = vec4(average, maximum, 0.0, 1.0);\r\n\r\n}\r\n#endif\r\n\r\n#if defined(DOWN_SAMPLE)\r\nuniform vec2 dsOffsets[9];\r\nuniform float halfDestPixelSize;\r\n\r\n#ifdef FINAL_DOWN_SAMPLE\r\nvec4 pack(float value) {\r\n	const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);\r\n	const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);\r\n\r\n	vec4 res = fract(value * bit_shift);\r\n	res -= res.xxyz * bit_mask;\r\n\r\n	return res;\r\n}\r\n#endif\r\n\r\nvoid main() {\r\n	vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\r\n	float average = 0.0;\r\n\r\n	for (int i = 0; i < 9; i++) {\r\n		color = texture2D(textureSampler, vUV + vec2(halfDestPixelSize, halfDestPixelSize) + dsOffsets[i]);\r\n		average += color.r;\r\n	}\r\n\r\n	average /= 9.0;\r\n\r\n	#ifndef FINAL_DOWN_SAMPLE\r\n	gl_FragColor = vec4(average, average, 0.0, 1.0);\r\n	#else\r\n	gl_FragColor = pack(average);\r\n	#endif\r\n}\r\n#endif\r\n\r\n#if defined(BRIGHT_PASS)\r\nuniform vec2 dsOffsets[4];\r\nuniform float brightThreshold;\r\n\r\nvoid main() {\r\n	vec4 average = vec4(0.0, 0.0, 0.0, 0.0);\r\n\r\n	average = texture2D(textureSampler, vUV + vec2(dsOffsets[0].x, dsOffsets[0].y));\r\n	average += texture2D(textureSampler, vUV + vec2(dsOffsets[1].x, dsOffsets[1].y));\r\n	average += texture2D(textureSampler, vUV + vec2(dsOffsets[2].x, dsOffsets[2].y));\r\n	average += texture2D(textureSampler, vUV + vec2(dsOffsets[3].x, dsOffsets[3].y));\r\n\r\n	average *= 0.25;\r\n\r\n	float luminance = length(average.rgb);\r\n\r\n	if (luminance < brightThreshold) {\r\n		average = vec4(0.0, 0.0, 0.0, 1.0);\r\n	}\r\n\r\n	gl_FragColor = average;\r\n}\r\n#endif\r\n\r\n#if defined(DOWN_SAMPLE_X4)\r\nuniform vec2 dsOffsets[16];\r\n\r\nvoid main() {\r\n	vec4 average = vec4(0.0, 0.0, 0.0, 0.0);\r\n\r\n	average = texture2D(textureSampler, vUV + dsOffsets[0]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[1]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[2]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[3]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[4]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[5]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[6]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[7]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[8]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[9]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[10]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[11]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[12]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[13]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[14]);\r\n	average += texture2D(textureSampler, vUV + dsOffsets[15]);\r\n\r\n	average /= 16.0;\r\n\r\n	gl_FragColor = average;\r\n}\r\n#endif\r\n\r\n#if defined(HDR)\r\nuniform sampler2D otherSampler;\r\n\r\nuniform float exposure;\r\nuniform float avgLuminance;\r\n\r\nvoid main() {\r\n	vec4 color = texture2D(textureSampler, vUV) + texture2D(otherSampler, vUV);\r\n	vec4 adjustedColor = color / avgLuminance * exposure;\r\n\r\n	color = adjustedColor;\r\n	color.a = 1.0;\r\n\r\n	gl_FragColor = color;\r\n}\r\n#endif\r\n",layerPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Color\r\nuniform vec4 color;\r\n\r\nvoid main(void) {\r\n	vec4 baseColor = texture2D(textureSampler, vUV);\r\n\r\n	gl_FragColor = baseColor * color;\r\n}",layerVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Uniforms\r\nuniform mat4 textureMatrix;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) {	\r\n\r\n	vUV = vec2(textureMatrix * vec4(position * madd + madd, 1.0, 0.0));\r\n	gl_Position = vec4(position, 0.0, 1.0);\r\n}",legacydefaultPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define MAP_PROJECTION	4.\r\n\r\n// Constants\r\nuniform vec3 vEyePosition;\r\nuniform vec3 vAmbientColor;\r\nuniform vec4 vDiffuseColor;\r\n#ifdef SPECULARTERM\r\nuniform vec4 vSpecularColor;\r\n#endif\r\nuniform vec3 vEmissiveColor;\r\n\r\n// Input\r\nvarying vec3 vPositionW;\r\nvarying vec3 vNormalW;\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n// Lights\r\n#ifdef LIGHT0\r\nuniform vec4 vLightData0;\r\nuniform vec4 vLightDiffuse0;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular0;\r\n#endif\r\n#ifdef SHADOW0\r\nvarying vec4 vPositionFromLight0;\r\nuniform sampler2D shadowSampler0;\r\n#endif\r\n#ifdef SPOTLIGHT0\r\nuniform vec4 vLightDirection0;\r\n#endif\r\n#ifdef HEMILIGHT0\r\nuniform vec3 vLightGround0;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\nuniform vec4 vLightData1;\r\nuniform vec4 vLightDiffuse1;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular1;\r\n#endif\r\n#ifdef SHADOW1\r\nvarying vec4 vPositionFromLight1;\r\nuniform sampler2D shadowSampler1;\r\n#endif\r\n#ifdef SPOTLIGHT1\r\nuniform vec4 vLightDirection1;\r\n#endif\r\n#ifdef HEMILIGHT1\r\nuniform vec3 vLightGround1;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\nuniform vec4 vLightData2;\r\nuniform vec4 vLightDiffuse2;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular2;\r\n#endif\r\n#ifdef SHADOW2\r\nvarying vec4 vPositionFromLight2;\r\nuniform sampler2D shadowSampler2;\r\n#endif\r\n#ifdef SPOTLIGHT2\r\nuniform vec4 vLightDirection2;\r\n#endif\r\n#ifdef HEMILIGHT2\r\nuniform vec3 vLightGround2;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\nuniform vec4 vLightData3;\r\nuniform vec4 vLightDiffuse3;\r\n#ifdef SPECULARTERM\r\nuniform vec3 vLightSpecular3;\r\n#endif\r\n#ifdef SHADOW3\r\nvarying vec4 vPositionFromLight3;\r\nuniform sampler2D shadowSampler3;\r\n#endif\r\n#ifdef SPOTLIGHT3\r\nuniform vec4 vLightDirection3;\r\n#endif\r\n#ifdef HEMILIGHT3\r\nuniform vec3 vLightGround3;\r\n#endif\r\n#endif\r\n\r\n// Samplers\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform sampler2D diffuseSampler;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n#ifdef AMBIENT\r\nvarying vec2 vAmbientUV;\r\nuniform sampler2D ambientSampler;\r\nuniform vec2 vAmbientInfos;\r\n#endif\r\n\r\n#ifdef OPACITY	\r\nvarying vec2 vOpacityUV;\r\nuniform sampler2D opacitySampler;\r\nuniform vec2 vOpacityInfos;\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nvarying vec3 vReflectionUVW;\r\nuniform samplerCube reflectionCubeSampler;\r\nuniform sampler2D reflection2DSampler;\r\nuniform vec3 vReflectionInfos;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform sampler2D emissiveSampler;\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform sampler2D specularSampler;\r\n#endif\r\n\r\n// Fresnel\r\n#ifdef FRESNEL\r\nfloat computeFresnelTerm(vec3 viewDirection, vec3 worldNormal, float bias, float power)\r\n{\r\n	float fresnelTerm = pow(bias + abs(dot(viewDirection, worldNormal)), power);\r\n	return clamp(fresnelTerm, 0., 1.);\r\n}\r\n#endif\r\n\r\n#ifdef DIFFUSEFRESNEL\r\nuniform vec4 diffuseLeftColor;\r\nuniform vec4 diffuseRightColor;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\nuniform vec4 opacityParts;\r\n#endif\r\n\r\n#ifdef REFLECTIONFRESNEL\r\nuniform vec4 reflectionLeftColor;\r\nuniform vec4 reflectionRightColor;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\nuniform vec4 emissiveLeftColor;\r\nuniform vec4 emissiveRightColor;\r\n#endif\r\n\r\n// Shadows\r\n#ifdef SHADOWS\r\n\r\nfloat unpack(vec4 color)\r\n{\r\n	const vec4 bitShift = vec4(1. / (255. * 255. * 255.), 1. / (255. * 255.), 1. / 255., 1.);\r\n	return dot(color, bitShift);\r\n}\r\n\r\nfloat unpackHalf(vec2 color)\r\n{\r\n	return color.x + (color.y / 255.0);\r\n}\r\n\r\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler)\r\n{\r\n	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n	vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\r\n\r\n	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n	{\r\n		return 1.0;\r\n	}\r\n\r\n	float shadow = unpack(texture2D(shadowSampler, uv));\r\n\r\n	if (depth.z > shadow)\r\n	{\r\n		return 0.;\r\n	}\r\n	return 1.;\r\n}\r\n\r\n// Thanks to http://devmaster.net/\r\nfloat ChebychevInequality(vec2 moments, float t)\r\n{\r\n	if (t <= moments.x)\r\n	{\r\n		return 1.0;\r\n	}\r\n\r\n	float variance = moments.y - (moments.x * moments.x);\r\n	variance = max(variance, 0.);\r\n\r\n	float d = t - moments.x;\r\n	return variance / (variance + d * d);\r\n}\r\n\r\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler)\r\n{\r\n	vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\r\n	vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\r\n\r\n	if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\r\n	{\r\n		return 1.0;\r\n	}\r\n\r\n	vec4 texel = texture2D(shadowSampler, uv);\r\n\r\n	vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\r\n	return clamp(1.3 - ChebychevInequality(moments, depth.z), 0., 1.0);\r\n}\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE    0.\r\n#define FOGMODE_EXP     1.\r\n#define FOGMODE_EXP2    2.\r\n#define FOGMODE_LINEAR  3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n	float fogCoeff = 1.0;\r\n	float fogStart = vFogInfos.y;\r\n	float fogEnd = vFogInfos.z;\r\n	float fogDensity = vFogInfos.w;\r\n\r\n	if (FOGMODE_LINEAR == vFogInfos.x)\r\n	{\r\n		fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n	}\r\n	else if (FOGMODE_EXP == vFogInfos.x)\r\n	{\r\n		fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n	}\r\n	else if (FOGMODE_EXP2 == vFogInfos.x)\r\n	{\r\n		fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n	}\r\n\r\n	return clamp(fogCoeff, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\n// Light Computing\r\nmat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor) {\r\n	mat3 result;\r\n\r\n	vec3 lightVectorW;\r\n	if (lightData.w == 0.)\r\n	{\r\n		lightVectorW = normalize(lightData.xyz - vPositionW);\r\n	}\r\n	else\r\n	{\r\n		lightVectorW = normalize(-lightData.xyz);\r\n	}\r\n\r\n	// diffuse\r\n	float ndl = max(0., dot(vNormal, lightVectorW));\r\n\r\n	result[0] = ndl * diffuseColor.rgb;\r\n\r\n#ifdef SPECULARTERM\r\n	// Specular\r\n	vec3 angleW = normalize(viewDirectionW + lightVectorW);\r\n	float specComp = max(0., dot(vNormal, angleW));\r\n	specComp = max(0., pow(specComp, max(1.0, vSpecularColor.a)));\r\n	result[1] = specComp * specularColor;\r\n#else\r\n	result[1] = vec3(0.);\r\n#endif\r\n\r\n	result[2] = vec3(0.);\r\n\r\n	return result;\r\n}\r\n\r\nmat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec4 diffuseColor, vec3 specularColor) {\r\n	mat3 result;\r\n\r\n	vec3 lightVectorW = normalize(lightData.xyz - vPositionW);\r\n\r\n	// diffuse\r\n	float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\r\n	float spotAtten = 0.0;\r\n\r\n	if (cosAngle >= lightDirection.w)\r\n	{\r\n		cosAngle = max(0., pow(cosAngle, lightData.w));\r\n		spotAtten = max(0., (cosAngle - lightDirection.w) / (1. - cosAngle));\r\n\r\n		// Diffuse\r\n		float ndl = max(0., dot(vNormal, -lightDirection.xyz));\r\n		result[0] = ndl * spotAtten * diffuseColor.rgb;\r\n\r\n#ifdef SPECULARTERM\r\n		// Specular\r\n		vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\r\n		float specComp = max(0., dot(vNormal, angleW));\r\n		specComp = pow(specComp, vSpecularColor.a);\r\n		result[1] = specComp * specularColor * spotAtten;\r\n#else\r\n		result[1] = vec3(0.);\r\n#endif\r\n		result[2] = vec3(0.);\r\n\r\n		return result;\r\n	}\r\n\r\n	result[0] = vec3(0.);\r\n	result[1] = vec3(0.);\r\n	result[2] = vec3(0.);\r\n\r\n	return result;\r\n}\r\n\r\nmat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 diffuseColor, vec3 specularColor, vec3 groundColor) {\r\n	mat3 result;\r\n\r\n	// Diffuse\r\n	float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\r\n	result[0] = mix(groundColor, diffuseColor.rgb, ndl);\r\n\r\n#ifdef SPECULARTERM\r\n	// Specular\r\n	vec3 angleW = normalize(viewDirectionW + lightData.xyz);\r\n	float specComp = max(0., dot(vNormal, angleW));\r\n	specComp = pow(specComp, vSpecularColor.a);\r\n	result[1] = specComp * specularColor;\r\n#else\r\n	result[1] = vec3(0.);\r\n#endif\r\n\r\n	result[2] = vec3(0.);\r\n\r\n	return result;\r\n}\r\n\r\nvoid main(void) {\r\n	// Clip plane\r\n#ifdef CLIPPLANE\r\n	if (fClipDistance > 0.0)\r\n		discard;\r\n#endif\r\n\r\n	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\r\n\r\n	// Base color\r\n	vec4 baseColor = vec4(1., 1., 1., 1.);\r\n	vec3 diffuseColor = vDiffuseColor.rgb;\r\n\r\n#ifdef DIFFUSE\r\n	baseColor = texture2D(diffuseSampler, vDiffuseUV);\r\n\r\n#ifdef ALPHATEST\r\n	if (baseColor.a < 0.4)\r\n		discard;\r\n#endif\r\n\r\n	baseColor.rgb *= vDiffuseInfos.y;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\n	baseColor.rgb *= vColor.rgb;\r\n#endif\r\n\r\n	// Bump\r\n	vec3 normalW = normalize(vNormalW);\r\n\r\n	// Ambient color\r\n	vec3 baseAmbientColor = vec3(1., 1., 1.);\r\n\r\n#ifdef AMBIENT\r\n	baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\r\n#endif\r\n\r\n	// Lighting\r\n	vec3 diffuseBase = vec3(0., 0., 0.);\r\n#ifdef SPECULARTERM\r\n	vec3 specularBase = vec3(0., 0., 0.);\r\n#endif\r\n	float shadow = 1.;\r\n\r\n#ifdef LIGHT0\r\n#ifndef SPECULARTERM\r\n	vec3 vLightSpecular0 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT0\r\n	mat3 info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0, vLightSpecular0);\r\n#endif\r\n#ifdef HEMILIGHT0\r\n	mat3 info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0, vLightGround0);\r\n#endif\r\n#ifdef POINTDIRLIGHT0\r\n	mat3 info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0);\r\n#endif\r\n#ifdef SHADOW0\r\n#ifdef SHADOWVSM0\r\n	shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);\r\n#else\r\n	shadow = computeShadow(vPositionFromLight0, shadowSampler0);\r\n#endif\r\n#else\r\n	shadow = 1.;\r\n#endif\r\n	diffuseBase += info[0] * shadow;\r\n#ifdef SPECULARTERM\r\n	specularBase += info[1] * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT1\r\n#ifndef SPECULARTERM\r\n	vec3 vLightSpecular1 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT1\r\n	info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1, vLightSpecular1);\r\n#endif\r\n#ifdef HEMILIGHT1\r\n	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1, vLightGround1);\r\n#endif\r\n#ifdef POINTDIRLIGHT1\r\n	info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1);\r\n#endif\r\n#ifdef SHADOW1\r\n#ifdef SHADOWVSM1\r\n	shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);\r\n#else\r\n	shadow = computeShadow(vPositionFromLight1, shadowSampler1);\r\n#endif\r\n#else\r\n	shadow = 1.;\r\n#endif\r\n	diffuseBase += info[0] * shadow;\r\n#ifdef SPECULARTERM\r\n	specularBase += info[1] * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT2\r\n#ifndef SPECULARTERM\r\n	vec3 vLightSpecular2 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT2\r\n	info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2, vLightSpecular2);\r\n#endif\r\n#ifdef HEMILIGHT2\r\n	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2, vLightGround2);\r\n#endif\r\n#ifdef POINTDIRLIGHT2\r\n	info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2);\r\n#endif\r\n#ifdef SHADOW2\r\n#ifdef SHADOWVSM2\r\n	shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);\r\n#else\r\n	shadow = computeShadow(vPositionFromLight2, shadowSampler2);\r\n#endif	\r\n#else\r\n	shadow = 1.;\r\n#endif\r\n	diffuseBase += info[0] * shadow;\r\n#ifdef SPECULARTERM\r\n	specularBase += info[1] * shadow;\r\n#endif\r\n#endif\r\n\r\n#ifdef LIGHT3\r\n#ifndef SPECULARTERM\r\n	vec3 vLightSpecular3 = vec3(0.0);\r\n#endif\r\n#ifdef SPOTLIGHT3\r\n	info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3, vLightSpecular3);\r\n#endif\r\n#ifdef HEMILIGHT3\r\n	info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3, vLightGround3);\r\n#endif\r\n#ifdef POINTDIRLIGHT3\r\n	info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3);\r\n#endif\r\n#ifdef SHADOW3\r\n#ifdef SHADOWVSM3\r\n	shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);\r\n#else\r\n	shadow = computeShadow(vPositionFromLight3, shadowSampler3);\r\n#endif	\r\n#else\r\n	shadow = 1.;\r\n#endif\r\n	diffuseBase += info[0] * shadow;\r\n#ifdef SPECULARTERM\r\n	specularBase += info[1] * shadow;\r\n#endif\r\n#endif\r\n\r\n	// Reflection\r\n	vec3 reflectionColor = vec3(0., 0., 0.);\r\n\r\n#ifdef REFLECTION\r\n	if (vReflectionInfos.z != 0.0)\r\n	{\r\n		reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y;\r\n	}\r\n	else\r\n	{\r\n		vec2 coords = vReflectionUVW.xy;\r\n\r\n		if (vReflectionInfos.x == MAP_PROJECTION)\r\n		{\r\n			coords /= vReflectionUVW.z;\r\n		}\r\n\r\n		coords.y = 1.0 - coords.y;\r\n\r\n		reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y;\r\n	}\r\n\r\n#ifdef REFLECTIONFRESNEL\r\n	float reflectionFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, reflectionRightColor.a, reflectionLeftColor.a);\r\n\r\n	reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#endif\r\n\r\n	// Alpha\r\n	float alpha = vDiffuseColor.a;\r\n\r\n#ifdef OPACITY\r\n	vec4 opacityMap = texture2D(opacitySampler, vOpacityUV);\r\n#ifdef OPACITYRGB\r\n	opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11);\r\n	alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\r\n#else\r\n	alpha *= opacityMap.a * vOpacityInfos.y;\r\n#endif\r\n#endif\r\n\r\n#ifdef VERTEXALPHA\r\n	alpha *= vColor.a;\r\n#endif\r\n\r\n#ifdef OPACITYFRESNEL\r\n	float opacityFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, opacityParts.z, opacityParts.w);\r\n\r\n	alpha += opacityParts.x * (1.0 - opacityFresnelTerm) + opacityFresnelTerm * opacityParts.y;\r\n#endif\r\n\r\n	// Emissive\r\n	vec3 emissiveColor = vEmissiveColor;\r\n#ifdef EMISSIVE\r\n	emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\r\n#endif\r\n\r\n#ifdef EMISSIVEFRESNEL\r\n	float emissiveFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, emissiveRightColor.a, emissiveLeftColor.a);\r\n\r\n	emissiveColor *= emissiveLeftColor.rgb * (1.0 - emissiveFresnelTerm) + emissiveFresnelTerm * emissiveRightColor.rgb;\r\n#endif\r\n\r\n	// Specular map\r\n#ifdef SPECULARTERM\r\n	vec3 specularColor = vSpecularColor.rgb;\r\n#ifdef SPECULAR\r\n	specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\r\n#endif\r\n#endif\r\n\r\n	// Fresnel\r\n#ifdef DIFFUSEFRESNEL\r\n	float diffuseFresnelTerm = computeFresnelTerm(viewDirectionW, normalW, diffuseRightColor.a, diffuseLeftColor.a);\r\n\r\n	diffuseBase *= diffuseLeftColor.rgb * (1.0 - diffuseFresnelTerm) + diffuseFresnelTerm * diffuseRightColor.rgb;\r\n#endif\r\n\r\n	// Composition\r\n	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\r\n#ifdef SPECULARTERM\r\n	vec3 finalSpecular = specularBase * specularColor;\r\n#else\r\n	vec3 finalSpecular = vec3(0.0);\r\n#endif\r\n\r\n	vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\r\n\r\n#ifdef FOG\r\n	float fog = CalcFogFactor();\r\n	color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n	gl_FragColor = color;\r\n}",
  legacydefaultVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define MAP_EXPLICIT	0.\r\n#define MAP_SPHERICAL	1.\r\n#define MAP_PLANAR		2.\r\n#define MAP_CUBIC		3.\r\n#define MAP_PROJECTION	4.\r\n#define MAP_SKYBOX		5.\r\n\r\n// Attributes\r\nattribute vec3 position;\r\nattribute vec3 normal;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#ifdef VERTEXCOLOR\r\nattribute vec4 color;\r\n#endif\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniforms\r\nuniform mat4 world;\r\nuniform mat4 view;\r\nuniform mat4 viewProjection;\r\n\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform mat4 diffuseMatrix;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n#ifdef AMBIENT\r\nvarying vec2 vAmbientUV;\r\nuniform mat4 ambientMatrix;\r\nuniform vec2 vAmbientInfos;\r\n#endif\r\n\r\n#ifdef OPACITY\r\nvarying vec2 vOpacityUV;\r\nuniform mat4 opacityMatrix;\r\nuniform vec2 vOpacityInfos;\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nuniform vec3 vEyePosition;\r\nvarying vec3 vReflectionUVW;\r\nuniform vec3 vReflectionInfos;\r\nuniform mat4 reflectionMatrix;\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\nvarying vec2 vEmissiveUV;\r\nuniform vec2 vEmissiveInfos;\r\nuniform mat4 emissiveMatrix;\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\nvarying vec2 vSpecularUV;\r\nuniform vec2 vSpecularInfos;\r\nuniform mat4 specularMatrix;\r\n#endif\r\n\r\n#ifdef BUMP\r\nvarying vec2 vBumpUV;\r\nuniform vec2 vBumpInfos;\r\nuniform mat4 bumpMatrix;\r\n#endif\r\n\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n// Output\r\nvarying vec3 vPositionW;\r\nvarying vec3 vNormalW;\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\n#ifdef SHADOWS\r\n#ifdef LIGHT0\r\nuniform mat4 lightMatrix0;\r\nvarying vec4 vPositionFromLight0;\r\n#endif\r\n#ifdef LIGHT1\r\nuniform mat4 lightMatrix1;\r\nvarying vec4 vPositionFromLight1;\r\n#endif\r\n#ifdef LIGHT2\r\nuniform mat4 lightMatrix2;\r\nvarying vec4 vPositionFromLight2;\r\n#endif\r\n#ifdef LIGHT3\r\nuniform mat4 lightMatrix3;\r\nvarying vec4 vPositionFromLight3;\r\n#endif\r\n#endif\r\n\r\n#ifdef REFLECTION\r\nvec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)\r\n{\r\n	if (mode == MAP_SPHERICAL)\r\n	{\r\n		vec3 coords = vec3(view * vec4(worldNormal, 0.0));\r\n\r\n		return vec3(reflectionMatrix * vec4(coords, 1.0));\r\n	}\r\n	else if (mode == MAP_PLANAR)\r\n	{\r\n		vec3 viewDir = worldPos.xyz - vEyePosition;\r\n		vec3 coords = normalize(reflect(viewDir, worldNormal));\r\n\r\n		return vec3(reflectionMatrix * vec4(coords, 1));\r\n	}\r\n	else if (mode == MAP_CUBIC)\r\n	{\r\n		vec3 viewDir = worldPos.xyz - vEyePosition;\r\n		vec3 coords = reflect(viewDir, worldNormal);\r\n\r\n		return vec3(reflectionMatrix * vec4(coords, 0));\r\n	}\r\n	else if (mode == MAP_PROJECTION)\r\n	{\r\n		return vec3(reflectionMatrix * (view * worldPos));\r\n	}\r\n	else if (mode == MAP_SKYBOX)\r\n	{\r\n		return position;\r\n	}\r\n\r\n	return vec3(0, 0, 0);\r\n}\r\n#endif\r\n\r\nvoid main(void) {\r\n	mat4 finalWorld;\r\n\r\n#ifdef BONES\r\n	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n	mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n\r\n#ifdef BONES4\r\n	mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n	finalWorld = world * (m0 + m1 + m2 + m3);\r\n#else\r\n	finalWorld = world * (m0 + m1 + m2);\r\n#endif \r\n\r\n#else\r\n	finalWorld = world;\r\n#endif\r\n\r\n	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n\r\n	vec4 worldPos = finalWorld * vec4(position, 1.0);\r\n	vPositionW = vec3(worldPos);\r\n	vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\r\n\r\n	// Texture coordinates\r\n#ifndef UV1\r\n	vec2 uv = vec2(0., 0.);\r\n#endif\r\n#ifndef UV2\r\n	vec2 uv2 = vec2(0., 0.);\r\n#endif\r\n\r\n#ifdef DIFFUSE\r\n	if (vDiffuseInfos.x == 0.)\r\n	{\r\n		vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#ifdef AMBIENT\r\n	if (vAmbientInfos.x == 0.)\r\n	{\r\n		vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#ifdef OPACITY\r\n	if (vOpacityInfos.x == 0.)\r\n	{\r\n		vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#ifdef REFLECTION\r\n	vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), vNormalW);\r\n#endif\r\n\r\n#ifdef EMISSIVE\r\n	if (vEmissiveInfos.x == 0.)\r\n	{\r\n		vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#if defined(SPECULAR) && defined(SPECULARTERM)\r\n	if (vSpecularInfos.x == 0.)\r\n	{\r\n		vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n#ifdef BUMP\r\n	if (vBumpInfos.x == 0.)\r\n	{\r\n		vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\r\n	}\r\n	else\r\n	{\r\n		vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\r\n	}\r\n#endif\r\n\r\n	// Clip plane\r\n#ifdef CLIPPLANE\r\n	fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n	// Fog\r\n#ifdef FOG\r\n	fFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n	// Shadows\r\n#ifdef SHADOWS\r\n#ifdef LIGHT0\r\n	vPositionFromLight0 = lightMatrix0 * worldPos;\r\n#endif\r\n#ifdef LIGHT1\r\n	vPositionFromLight1 = lightMatrix1 * worldPos;\r\n#endif\r\n#ifdef LIGHT2\r\n	vPositionFromLight2 = lightMatrix2 * worldPos;\r\n#endif\r\n#ifdef LIGHT3\r\n	vPositionFromLight3 = lightMatrix3 * worldPos;\r\n#endif\r\n#endif\r\n\r\n	// Vertex color\r\n#ifdef VERTEXCOLOR\r\n	vColor = color;\r\n#endif\r\n}",lensFlarePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Color\r\nuniform vec4 color;\r\n\r\nvoid main(void) {\r\n	vec4 baseColor = texture2D(textureSampler, vUV);\r\n\r\n	gl_FragColor = baseColor * color;\r\n}",lensFlareVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Uniforms\r\nuniform mat4 viewportMatrix;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) {	\r\n\r\n	vUV = position * madd + madd;\r\n	gl_Position = viewportMatrix * vec4(position, 0.0, 1.0);\r\n}",lensHighlightsPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// samplers\r\nuniform sampler2D textureSampler;	// original color\r\n\r\n// uniforms\r\nuniform float gain;\r\nuniform float threshold;\r\nuniform bool pentagon;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\n// apply luminance filter\r\nvec4 highlightColor(vec4 color) {\r\n	vec4 highlight = color;\r\n	float luminance = dot(highlight.rgb, vec3(0.2125, 0.7154, 0.0721));\r\n	float lum_threshold;\r\n	if (threshold > 1.0) { lum_threshold = 0.94 + 0.01 * threshold; }\r\n	else { lum_threshold = 0.5 + 0.44 * threshold; }\r\n\r\n	luminance = clamp((luminance - lum_threshold) * (1.0 / (1.0 - lum_threshold)), 0.0, 1.0);\r\n\r\n	highlight *= luminance * gain;\r\n	highlight.a = 1.0;\r\n\r\n	return highlight;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n	vec4 original = texture2D(textureSampler, vUV);\r\n\r\n	// quick exit if no highlight computing\r\n	if (gain == -1.0) {\r\n		gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n		return;\r\n	}\r\n\r\n	float w = 2.0 / screen_width;\r\n	float h = 2.0 / screen_height;\r\n\r\n	float weight = 1.0;\r\n\r\n	// compute blurred color\r\n	vec4 blurred = vec4(0.0, 0.0, 0.0, 0.0);\r\n\r\n	if (pentagon) {\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.84*w, 0.43*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.48*w, -1.29*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.61*w, 1.51*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.55*w, -0.74*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.71*w, -0.52*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.94*w, 1.59*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.40*w, -1.87*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.62*w, 1.16*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.09*w, 0.25*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.46*w, -1.71*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.08*w, 2.42*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.85*w, -1.89*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.89*w, 0.16*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.29*w, 1.88*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.40*w, -2.81*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.54*w, 2.26*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.60*w, -0.61*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.31*w, -1.30*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.83*w, 2.53*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.12*w, -2.48*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.60*w, 1.11*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.82*w, 0.99*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.50*w, -2.81*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.85*w, 3.33*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.94*w, -1.92*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.27*w, -0.53*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.95*w, 2.48*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.23*w, -3.04*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.17*w, 2.05*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.97*w, -0.04*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.25*w, -2.00*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.31*w, 3.08*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.94*w, -2.59*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.37*w, 0.64*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-3.13*w, 1.93*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.03*w, -3.65*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.60*w, 3.17*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-3.14*w, -1.19*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.00*w, -1.19*h)));\r\n	}\r\n	else {\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.85*w, 0.36*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.52*w, -1.14*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.46*w, 1.42*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.46*w, -0.83*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.79*w, -0.42*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.11*w, 1.62*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.29*w, -2.07*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.69*w, 1.39*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.28*w, 0.12*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.65*w, -1.69*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.08*w, 2.44*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.63*w, -1.90*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.55*w, 0.31*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.13*w, 1.52*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.56*w, -2.61*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.38*w, 2.34*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.64*w, -0.81*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.53*w, -1.21*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.06*w, 2.63*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.00*w, -2.69*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.59*w, 1.32*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.82*w, 0.78*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.57*w, -2.50*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(0.54*w, 2.93*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.39*w, -1.81*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.01*w, -0.28*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.04*w, 2.25*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.02*w, -3.05*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.09*w, 2.25*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-3.07*w, -0.25*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.44*w, -1.90*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-0.52*w, 3.05*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-1.68*w, -2.61*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(3.01*w, 0.79*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.76*w, 1.46*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.05*w, -2.94*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(1.21*w, 2.88*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(-2.84*w, -1.30*h)));\r\n		blurred += highlightColor(texture2D(textureSampler, vUV + vec2(2.98*w, -0.96*h)));\r\n	}\r\n\r\n	blurred /= 39.0;\r\n\r\n	gl_FragColor = blurred;\r\n\r\n	//if(vUV.x > 0.5) { gl_FragColor.rgb *= 0.0; }\r\n}",linePixelShader:"precision highp float;\r\n\r\nuniform vec4 color;\r\n\r\nvoid main(void) {\r\n	gl_FragColor = color;\r\n}",lineVertexShader:"precision highp float;\r\n\r\n// Attributes\r\nattribute vec3 position;\r\nattribute vec4 normal;\r\n\r\n// Uniforms\r\nuniform mat4 worldViewProjection;\r\n\r\nuniform float width;\r\nuniform float aspectRatio;\r\n\r\nvoid main(void) {\r\n	vec4 viewPosition = worldViewProjection * vec4(position, 1.0);\r\n	vec4 viewPositionNext = worldViewProjection * vec4(normal.xyz, 1.0);\r\n\r\n	vec2 currentScreen = viewPosition.xy / viewPosition.w;\r\n	vec2 nextScreen = viewPositionNext.xy / viewPositionNext.w;\r\n\r\n	currentScreen.x *= aspectRatio;\r\n	nextScreen.x *= aspectRatio;\r\n\r\n	vec2 dir = normalize(nextScreen - currentScreen);\r\n	vec2 normalDir = vec2(-dir.y, dir.x);\r\n\r\n	normalDir *= width / 2.0;\r\n	normalDir.x /= aspectRatio;\r\n\r\n	vec4 offset = vec4(normalDir * normal.w, 0.0, 0.0);\r\n	gl_Position = viewPosition + offset;\r\n}",marblePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform float numberOfTilesHeight;\r\nuniform float numberOfTilesWidth;\r\nuniform float amplitude;\r\nuniform vec3 brickColor;\r\nuniform vec3 jointColor;\r\n\r\nconst vec3 tileSize = vec3(1.1, 1.0, 1.1);\r\nconst vec3 tilePct = vec3(0.98, 1.0, 0.98);\r\n\r\nfloat rand(vec2 n) {\r\n	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n	const vec2 d = vec2(0.0, 1.0);\r\n	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\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);\r\n}\r\n\r\nfloat turbulence(vec2 P)\r\n{\r\n	float val = 0.0;\r\n	float freq = 1.0;\r\n	for (int i = 0; i < 4; i++)\r\n	{\r\n		val += abs(noise(P*freq) / freq);\r\n		freq *= 2.07;\r\n	}\r\n	return val;\r\n}\r\n\r\nfloat round(float number){\r\n	return sign(number)*floor(abs(number) + 0.5);\r\n}\r\n\r\nvec3 marble_color(float x)\r\n{\r\n	vec3 col;\r\n	x = 0.5*(x + 1.);\r\n	x = sqrt(x);             \r\n	x = sqrt(x);\r\n	x = sqrt(x);\r\n	col = vec3(.2 + .75*x);  \r\n	col.b *= 0.95;           \r\n	return col;\r\n}\r\n\r\nvoid main()\r\n{\r\n	float brickW = 1.0 / numberOfTilesWidth;\r\n	float brickH = 1.0 / numberOfTilesHeight;\r\n	float jointWPercentage = 0.01;\r\n	float jointHPercentage = 0.01;\r\n	vec3 color = brickColor;\r\n	float yi = vUV.y / brickH;\r\n	float nyi = round(yi);\r\n	float xi = vUV.x / brickW;\r\n\r\n	if (mod(floor(yi), 2.0) == 0.0){\r\n		xi = xi - 0.5;\r\n	}\r\n\r\n	float nxi = round(xi);\r\n	vec2 brickvUV = vec2((xi - floor(xi)) / brickH, (yi - floor(yi)) / brickW);\r\n\r\n	if (yi < nyi + jointHPercentage && yi > nyi - jointHPercentage){\r\n		color = mix(jointColor, vec3(0.37, 0.25, 0.25), (yi - nyi) / jointHPercentage + 0.2);\r\n	}\r\n	else if (xi < nxi + jointWPercentage && xi > nxi - jointWPercentage){\r\n		color = mix(jointColor, vec3(0.44, 0.44, 0.44), (xi - nxi) / jointWPercentage + 0.2);\r\n	}\r\n	else {\r\n		float t = 6.28 * brickvUV.x / (tileSize.x + noise(vec2(vUV)*6.0));\r\n		t += amplitude * turbulence(brickvUV.xy);\r\n		t = sin(t);\r\n		color = marble_color(t);\r\n	}\r\n\r\n	gl_FragColor = vec4(color, 0.0);\r\n}",outlinePixelShader:"precision highp float;\r\n\r\nuniform vec4 color;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\nvoid main(void) {\r\n#ifdef ALPHATEST\r\n	if (texture2D(diffuseSampler, vUV).a < 0.4)\r\n		discard;\r\n#endif\r\n\r\n	gl_FragColor = color;\r\n}",outlineVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attribute\r\nattribute vec3 position;\r\nattribute vec3 normal;\r\n\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniform\r\nuniform float offset;\r\n\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 viewProjection;\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform mat4 diffuseMatrix;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef INSTANCES\r\n	mat4 finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n	mat4 finalWorld = world;\r\n#endif\r\n\r\n	vec3 offsetPosition = position + normal * offset;\r\n\r\n#ifdef BONES\r\n	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n	mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n	mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n	finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n	gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 1.0);\r\n#else\r\n	gl_Position = viewProjection * finalWorld * vec4(offsetPosition, 1.0);\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\n#ifdef UV1\r\n	vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n#endif\r\n#ifdef UV2\r\n	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n#endif\r\n#endif\r\n}",particlesPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\nuniform vec4 textureMask;\r\nuniform sampler2D diffuseSampler;\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\nvoid main(void) {\r\n#ifdef CLIPPLANE\r\n	if (fClipDistance > 0.0)\r\n		discard;\r\n#endif\r\n	vec4 baseColor = texture2D(diffuseSampler, vUV);\r\n\r\n	gl_FragColor = (baseColor * textureMask + (vec4(1., 1., 1., 1.) - textureMask)) * vColor;\r\n}",particlesVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec3 position;\r\nattribute vec4 color;\r\nattribute vec4 options;\r\n\r\n// Uniforms\r\nuniform mat4 view;\r\nuniform mat4 projection;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nuniform mat4 invView;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\nvoid main(void) {	\r\n	vec3 viewPos = (view * vec4(position, 1.0)).xyz; \r\n	vec3 cornerPos;\r\n	float size = options.y;\r\n	float angle = options.x;\r\n	vec2 offset = options.zw;\r\n\r\n	cornerPos = vec3(offset.x - 0.5, offset.y  - 0.5, 0.) * size;\r\n\r\n	// Rotate\r\n	vec3 rotatedCorner;\r\n	rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\r\n	rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\r\n	rotatedCorner.z = 0.;\r\n\r\n	// Position\r\n	viewPos += rotatedCorner;\r\n	gl_Position = projection * vec4(viewPos, 1.0);   \r\n	\r\n	vColor = color;\r\n	vUV = offset;\r\n\r\n	// Clip plane\r\n#ifdef CLIPPLANE\r\n	vec4 worldPos = invView * vec4(viewPos, 1.0);\r\n	fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n}",passPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\nvoid main(void) \r\n{\r\n	gl_FragColor = texture2D(textureSampler, vUV);\r\n}",postprocessVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) {	\r\n\r\n	vUV = position * madd + madd;\r\n	gl_Position = vec4(position, 0.0, 1.0);\r\n}",proceduralVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec2 position;\r\n\r\n// Output\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nconst vec2 madd = vec2(0.5, 0.5);\r\n\r\nvoid main(void) {	\r\n	vPosition = position;\r\n	vUV = position * madd + madd;\r\n	gl_Position = vec4(position, 0.0, 1.0);\r\n}",refractionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D refractionSampler;\r\n\r\n// Parameters\r\nuniform vec3 baseColor;\r\nuniform float depth;\r\nuniform float colorLevel;\r\n\r\nvoid main() {\r\n	float ref = 1.0 - texture2D(refractionSampler, vUV).r;\r\n\r\n	vec2 uv = vUV - vec2(0.5);\r\n	vec2 offset = uv * depth * ref;\r\n	vec3 sourceColor = texture2D(textureSampler, vUV - offset).rgb;\r\n\r\n	gl_FragColor = vec4(sourceColor + sourceColor * ref * colorLevel, 1.0);\r\n}",roadPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vUV;                    \r\nuniform vec3 roadColor;\r\n\r\nfloat rand(vec2 n) {\r\n	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n	const vec2 d = vec2(0.0, 1.0);\r\n	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\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);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n	float total = 0.0, amplitude = 1.0;\r\n	for (int i = 0; i < 4; i++) {\r\n		total += noise(n) * amplitude;\r\n		n += n;\r\n		amplitude *= 0.5;\r\n	}\r\n	return total;\r\n}\r\n\r\nvoid main(void) {\r\n	float ratioy = mod(gl_FragCoord.y * 100.0 , fbm(vUV * 2.0));\r\n	vec3 color = roadColor * ratioy;\r\n	gl_FragColor = vec4(color, 1.0);\r\n}",shadowMapPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvec4 pack(float depth)\r\n{\r\n	const vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);\r\n	const vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);\r\n\r\n	vec4 res = fract(depth * bit_shift);\r\n	res -= res.xxyz * bit_mask;\r\n\r\n	return res;\r\n}\r\n\r\n// Thanks to http://devmaster.net/\r\nvec2 packHalf(float depth) \r\n{ \r\n	const vec2 bitOffset = vec2(1.0 / 255., 0.);\r\n	vec2 color = vec2(depth, fract(depth * 255.));\r\n\r\n	return color - (color.yy * bitOffset);\r\n}\r\n\r\nvarying vec4 vPosition;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef ALPHATEST\r\n	if (texture2D(diffuseSampler, vUV).a < 0.4)\r\n		discard;\r\n#endif\r\n	float depth = vPosition.z / vPosition.w;\r\n	depth = depth * 0.5 + 0.5;\r\n\r\n#ifdef VSM\r\n	float moment1 = depth;\r\n	float moment2 = moment1 * moment1;\r\n\r\n	gl_FragColor = vec4(packHalf(moment1), packHalf(moment2));\r\n#else\r\n	gl_FragColor = pack(depth);\r\n#endif\r\n}",shadowMapVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attribute\r\nattribute vec3 position;\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniform\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 viewProjection;\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\nvarying vec4 vPosition;\r\n\r\n#ifdef ALPHATEST\r\nvarying vec2 vUV;\r\nuniform mat4 diffuseMatrix;\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#ifdef INSTANCES\r\n	mat4 finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n	mat4 finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n	mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n	mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n	finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n#endif\r\n\r\n	vPosition = viewProjection * finalWorld * vec4(position, 1.0);\r\n	gl_Position = vPosition;\r\n\r\n#ifdef ALPHATEST\r\n#ifdef UV1\r\n	vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\r\n#endif\r\n#ifdef UV2\r\n	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\r\n#endif\r\n#endif\r\n}",spritesPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform bool alphaTest;\r\n\r\nvarying vec4 vColor;\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D diffuseSampler;\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE    0.\r\n#define FOGMODE_EXP     1.\r\n#define FOGMODE_EXP2    2.\r\n#define FOGMODE_LINEAR  3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n	float fogCoeff = 1.0;\r\n	float fogStart = vFogInfos.y;\r\n	float fogEnd = vFogInfos.z;\r\n	float fogDensity = vFogInfos.w;\r\n\r\n	if (FOGMODE_LINEAR == vFogInfos.x)\r\n	{\r\n		fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n	}\r\n	else if (FOGMODE_EXP == vFogInfos.x)\r\n	{\r\n		fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n	}\r\n	else if (FOGMODE_EXP2 == vFogInfos.x)\r\n	{\r\n		fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n	}\r\n\r\n	return min(1., max(0., fogCoeff));\r\n}\r\n#endif\r\n\r\n\r\nvoid main(void) {\r\n	vec4 baseColor = texture2D(diffuseSampler, vUV);\r\n\r\n	if (alphaTest) \r\n	{\r\n		if (baseColor.a < 0.95)\r\n			discard;\r\n	}\r\n\r\n	baseColor *= vColor;\r\n\r\n#ifdef FOG\r\n	float fog = CalcFogFactor();\r\n	baseColor.rgb = fog * baseColor.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n	gl_FragColor = baseColor;\r\n}",spritesVertexShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Attributes\r\nattribute vec4 position;\r\nattribute vec4 options;\r\nattribute vec4 cellInfo;\r\nattribute vec4 color;\r\n\r\n// Uniforms\r\nuniform vec2 textureInfos;\r\nuniform mat4 view;\r\nuniform mat4 projection;\r\n\r\n// Output\r\nvarying vec2 vUV;\r\nvarying vec4 vColor;\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\nvoid main(void) {	\r\n	vec3 viewPos = (view * vec4(position.xyz, 1.0)).xyz; \r\n	vec2 cornerPos;\r\n	\r\n	float angle = position.w;\r\n	vec2 size = vec2(options.x, options.y);\r\n	vec2 offset = options.zw;\r\n	vec2 uvScale = textureInfos.xy;\r\n\r\n	cornerPos = vec2(offset.x - 0.5, offset.y  - 0.5) * size;\r\n\r\n	// Rotate\r\n	vec3 rotatedCorner;\r\n	rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\r\n	rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\r\n	rotatedCorner.z = 0.;\r\n\r\n	// Position\r\n	viewPos += rotatedCorner;\r\n	gl_Position = projection * vec4(viewPos, 1.0);   \r\n\r\n	// Color\r\n	vColor = color;\r\n	\r\n	// Texture\r\n	vec2 uvOffset = vec2(abs(offset.x - cellInfo.x), 1.0 - abs(offset.y - cellInfo.y));\r\n\r\n	vUV = (uvOffset + cellInfo.zw) * uvScale;\r\n\r\n	// Fog\r\n#ifdef FOG\r\n	fFogDistance = viewPos.z;\r\n#endif\r\n}",ssaoPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#define SAMPLES 16\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D randomSampler;\r\n\r\nuniform float randTextureTiles;\r\nuniform float samplesFactor;\r\nuniform vec3 sampleSphere[16];\r\n\r\nuniform float totalStrength;\r\nuniform float radius;\r\nuniform float area;\r\nuniform float fallOff;\r\n\r\nvarying vec2 vUV;\r\n\r\nconst vec2 offset1 = vec2(0.0, 0.001);\r\nconst vec2 offset2 = vec2(0.001, 0.0);\r\n\r\nvec3 normalFromDepth(const float depth, const vec2 coords) {\r\n	float depth1 = texture2D(textureSampler, coords + offset1).r;\r\n	float depth2 = texture2D(textureSampler, coords + offset2).r;\r\n\r\n    vec3 p1 = vec3(offset1, depth1 - depth);\r\n    vec3 p2 = vec3(offset2, depth2 - depth);\r\n\r\n    vec3 normal = cross(p1, p2);\r\n    normal.z = -normal.z;\r\n\r\n    return normalize(normal);\r\n}\r\n\r\nvoid main(void)\r\n{\r\n	const float base = 0.2;\r\n\r\n	vec3 random = texture2D(randomSampler, vUV * randTextureTiles).rgb;\r\n	float depth = texture2D(textureSampler, vUV).r;\r\n	vec3 position = vec3(vUV, depth);\r\n	vec3 normal = normalFromDepth(depth, vUV);\r\n	float radiusDepth = radius / depth;\r\n	float occlusion = 0.0;\r\n\r\n	vec3 ray;\r\n	vec3 hemiRay;\r\n	float occlusionDepth;\r\n	float difference;\r\n\r\n	for (int i = 0; i < SAMPLES; i++)\r\n	{\r\n		ray = radiusDepth * reflect(sampleSphere[i], random);\r\n		hemiRay = position + sign(dot(ray, normal)) * ray;\r\n\r\n		occlusionDepth = texture2D(textureSampler, clamp(hemiRay.xy, 0.0, 1.0)).r;\r\n		difference = depth - occlusionDepth;\r\n\r\n		occlusion += step(fallOff, difference) * (1.0 - smoothstep(fallOff, area, difference));\r\n	}\r\n\r\n	float ao = 1.0 - totalStrength * occlusion * samplesFactor;\r\n\r\n	float result = clamp(ao + base, 0.0, 1.0);\r\n	gl_FragColor.r = result;\r\n	gl_FragColor.g = result;\r\n	gl_FragColor.b = result;\r\n	gl_FragColor.a = 1.0;\r\n}\r\n",ssaoCombinePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D originalColor;\r\n\r\nvarying vec2 vUV;\r\n\r\nvoid main(void) {\r\n	gl_FragColor = texture2D(originalColor, vUV) * texture2D(textureSampler, vUV);\r\n}\r\n",
  stereoscopicInterlacePixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nconst vec3 TWO = vec3(2.0, 2.0, 2.0);\r\n\r\nvarying vec2 vUV;\r\nuniform sampler2D camASampler;\r\nuniform sampler2D textureSampler;\r\nuniform vec2 stepSize;\r\n\r\nvoid main(void)\r\n{\r\n    bool useCamB;\r\n    vec2 texCoord1;\r\n    vec2 texCoord2;\r\n    \r\n    vec3 frag1;\r\n    vec3 frag2;\r\n    \r\n#ifdef IS_STEREOSCOPIC_HORIZ\r\n	    useCamB = vUV.x > 0.5;\r\n	    texCoord1 = vec2(useCamB ? (vUV.x - 0.5) * 2.0 : vUV.x * 2.0, vUV.y);\r\n	    texCoord2 = vec2(texCoord1.x + stepSize.x, vUV.y);\r\n#else\r\n	    useCamB = vUV.y > 0.5;\r\n	    texCoord1 = vec2(vUV.x, useCamB ? (vUV.y - 0.5) * 2.0 : vUV.y * 2.0);\r\n	    texCoord2 = vec2(vUV.x, texCoord1.y + stepSize.y);\r\n#endif\r\n    \r\n    // cannot assign a sampler to a variable, so must duplicate texture accesses\r\n    if (useCamB){\r\n        frag1 = texture2D(textureSampler, texCoord1).rgb;\r\n        frag2 = texture2D(textureSampler, texCoord2).rgb;\r\n    }else{\r\n        frag1 = texture2D(camASampler   , texCoord1).rgb;\r\n        frag2 = texture2D(camASampler   , texCoord2).rgb;\r\n    }\r\n    \r\n    gl_FragColor = vec4((frag1 + frag2) / TWO, 1.0);\r\n}",tonemapPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\n\r\n// Constants\r\nuniform float _ExposureAdjustment;\r\n\r\n#if defined(HABLE_TONEMAPPING)\r\n    const float A = 0.15;\r\n    const float B = 0.50;\r\n    const float C = 0.10;\r\n    const float D = 0.20;\r\n    const float E = 0.02;\r\n    const float F = 0.30;\r\n    const float W = 11.2;\r\n#endif\r\n\r\nfloat Luminance(vec3 c)\r\n{\r\n    return dot(c, vec3(0.22, 0.707, 0.071));\r\n}\r\n\r\nvoid main(void) \r\n{\r\n    vec3 colour = texture2D(textureSampler, vUV).rgb;\r\n\r\n#if defined(REINHARD_TONEMAPPING)\r\n\r\n    float lum = Luminance(colour.rgb); \r\n    float lumTm = lum * _ExposureAdjustment;\r\n    float scale = lumTm / (1.0 + lumTm);  \r\n\r\n    colour *= scale / lum;\r\n\r\n#elif defined(HABLE_TONEMAPPING)\r\n\r\n    colour *= _ExposureAdjustment;\r\n\r\n    const float ExposureBias = 2.0;\r\n    vec3 x = ExposureBias * colour;\r\n\r\n    vec3 curr = ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F;\r\n    \r\n    x = vec3(W, W, W);\r\n    vec3 whiteScale = 1.0 / (((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F);\r\n    colour = curr * whiteScale;\r\n\r\n#elif defined(OPTIMIZED_HEJIDAWSON_TONEMAPPING)\r\n\r\n    colour *= _ExposureAdjustment;\r\n    \r\n    vec3 X = max(vec3(0.0, 0.0, 0.0), colour - 0.004);\r\n    vec3 retColor = (X * (6.2 * X + 0.5)) / (X * (6.2 * X + 1.7) + 0.06);\r\n\r\n    colour = retColor * retColor;\r\n\r\n#elif defined(PHOTOGRAPHIC_TONEMAPPING)\r\n\r\n    colour =  vec3(1.0, 1.0, 1.0) - exp2(-_ExposureAdjustment * colour);\r\n\r\n#endif\r\n\r\n	gl_FragColor = vec4(colour.rgb, 1.0);\r\n}",volumetricLightScatteringPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nuniform sampler2D textureSampler;\r\nuniform sampler2D lightScatteringSampler;\r\n\r\nuniform float decay;\r\nuniform float exposure;\r\nuniform float weight;\r\nuniform float density;\r\nuniform vec2 meshPositionOnScreen;\r\n\r\nvarying vec2 vUV;\r\n\r\nvoid main(void) {\r\n    vec2 tc = vUV;\r\n	vec2 deltaTexCoord = (tc - meshPositionOnScreen.xy);\r\n    deltaTexCoord *= 1.0 / float(NUM_SAMPLES) * density;\r\n\r\n    float illuminationDecay = 1.0;\r\n\r\n	vec4 color = texture2D(lightScatteringSampler, tc) * 0.4;\r\n\r\n    for(int i=0; i < NUM_SAMPLES; i++) {\r\n        tc -= deltaTexCoord;\r\n		vec4 sample = texture2D(lightScatteringSampler, tc) * 0.4;\r\n        sample *= illuminationDecay * weight;\r\n        color += sample;\r\n        illuminationDecay *= decay;\r\n    }\r\n\r\n    vec4 realColor = texture2D(textureSampler, vUV);\r\n    gl_FragColor = ((vec4((vec3(color.r, color.g, color.b) * exposure), 1)) + (realColor * (1.5 - 0.4)));\r\n}\r\n",volumetricLightScatteringPassPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(NEED_UV)\r\nvarying vec2 vUV;\r\n#endif\r\n\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\r\nuniform sampler2D diffuseSampler;\r\n#endif\r\n\r\n#if defined(DIFFUSE_COLOR_RENDER)\r\nuniform vec3 color;\r\n#endif\r\n\r\n#if defined(OPACITY)\r\nuniform sampler2D opacitySampler;\r\nuniform float opacityLevel;\r\n#endif\r\n\r\nvoid main(void)\r\n{\r\n#if defined(ALPHATEST) || defined(BASIC_RENDER)\r\n	vec4 diffuseColor = texture2D(diffuseSampler, vUV);\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\n	if (diffuseColor.a < 0.4)\r\n		discard;\r\n#endif\r\n\r\n#ifdef OPACITY\r\n	vec4 opacityColor = texture2D(opacitySampler, vUV);\r\n	float alpha = 1.0;\r\n\r\n	#ifdef OPACITYRGB\r\n	opacityColor.rgb = opacityColor.rgb * vec3(0.3, 0.59, 0.11);\r\n	alpha *= (opacityColor.x + opacityColor.y + opacityColor.z) * opacityLevel;\r\n	#else\r\n	alpha *= opacityColor.a * opacityLevel;\r\n	#endif\r\n\r\n	#if defined(BASIC_RENDER)\r\n	gl_FragColor = vec4(diffuseColor.rgb, alpha);\r\n	#elif defined(DIFFUSE_COLOR_RENDER)\r\n	gl_FragColor = vec4(color.rgb, alpha);\r\n	#else\r\n	gl_FragColor = vec4(0.0, 0.0, 0.0, alpha);\r\n	#endif\r\n\r\n	gl_FragColor.a = alpha;\r\n#else\r\n\r\n	#if defined(BASIC_RENDER)\r\n	gl_FragColor = diffuseColor;\r\n	#elif defined(DIFFUSE_COLOR_RENDER)\r\n	gl_FragColor = vec4(color.rgb, 1.0);\r\n	#else\r\n	gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n	#endif\r\n#endif\r\n\r\n}\r\n",vrDistortionCorrectionPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\n// Samplers\r\nvarying vec2 vUV;\r\nuniform sampler2D textureSampler;\r\nuniform vec2 LensCenter;\r\nuniform vec2 Scale;\r\nuniform vec2 ScaleIn;\r\nuniform vec4 HmdWarpParam;\r\n\r\nvec2 HmdWarp(vec2 in01) {\r\n\r\n	vec2 theta = (in01 - LensCenter) * ScaleIn; // Scales to [-1, 1]\r\n	float rSq = theta.x * theta.x + theta.y * theta.y;\r\n	vec2 rvector = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);\r\n	return LensCenter + Scale * rvector;\r\n}\r\n\r\nvoid main(void)\r\n{\r\n	vec2 tc = HmdWarp(vUV);\r\n	if (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\r\n		gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n	else{\r\n		gl_FragColor = vec4(texture2D(textureSampler, tc).rgb, 1.0);\r\n	}\r\n}",woodPixelShader:"#ifdef GL_ES\r\nprecision highp float;\r\n#endif\r\n\r\nvarying vec2 vPosition;\r\nvarying vec2 vUV;\r\n\r\nuniform float ampScale;\r\nuniform vec3 woodColor;\r\n\r\nfloat rand(vec2 n) {\r\n	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\r\n}\r\n\r\nfloat noise(vec2 n) {\r\n	const vec2 d = vec2(0.0, 1.0);\r\n	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\r\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);\r\n}\r\n\r\nfloat fbm(vec2 n) {\r\n	float total = 0.0, amplitude = 1.0;\r\n	for (int i = 0; i < 4; i++) {\r\n		total += noise(n) * amplitude;\r\n		n += n;\r\n		amplitude *= 0.5;\r\n	}\r\n	return total;\r\n}\r\n\r\nvoid main(void) {\r\n	float ratioy = mod(vUV.x * ampScale, 2.0 + fbm(vUV * 0.8));\r\n	vec3 wood = woodColor * ratioy;\r\n	gl_FragColor = vec4(wood, 1.0);\r\n}"},BABYLON.CollisionWorker='var BABYLON;!function(t){var e=function(t,e,o,i){return t.x>o.x+i?!1:o.x-i>e.x?!1:t.y>o.y+i?!1:o.y-i>e.y?!1:t.z>o.z+i?!1:o.z-i>e.z?!1:!0},o=function(t,e,o,i){var s=e*e-4*t*o,r={root:0,found:!1};if(0>s)return r;var n=Math.sqrt(s),c=(-e-n)/(2*t),h=(-e+n)/(2*t);if(c>h){var a=h;h=c,c=a}return c>0&&i>c?(r.root=c,r.found=!0,r):h>0&&i>h?(r.root=h,r.found=!0,r):r},i=function(){function i(){this.radius=new t.Vector3(1,1,1),this.retry=0,this.basePointWorld=t.Vector3.Zero(),this.velocityWorld=t.Vector3.Zero(),this.normalizedVelocity=t.Vector3.Zero(),this._collisionPoint=t.Vector3.Zero(),this._planeIntersectionPoint=t.Vector3.Zero(),this._tempVector=t.Vector3.Zero(),this._tempVector2=t.Vector3.Zero(),this._tempVector3=t.Vector3.Zero(),this._tempVector4=t.Vector3.Zero(),this._edge=t.Vector3.Zero(),this._baseToVertex=t.Vector3.Zero(),this._destinationPoint=t.Vector3.Zero(),this._slidePlaneNormal=t.Vector3.Zero(),this._displacementVector=t.Vector3.Zero()}return i.prototype._initialize=function(e,o,i){this.velocity=o,t.Vector3.NormalizeToRef(o,this.normalizedVelocity),this.basePoint=e,e.multiplyToRef(this.radius,this.basePointWorld),o.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=i,this.collisionFound=!1},i.prototype._checkPointInTriangle=function(e,o,i,s,r){o.subtractToRef(e,this._tempVector),i.subtractToRef(e,this._tempVector2),t.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var n=t.Vector3.Dot(this._tempVector4,r);return 0>n?!1:(s.subtractToRef(e,this._tempVector3),t.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),n=t.Vector3.Dot(this._tempVector4,r),0>n?!1:(t.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),n=t.Vector3.Dot(this._tempVector4,r),n>=0))},i.prototype._canDoCollision=function(o,i,s,r){var n=t.Vector3.Distance(this.basePointWorld,o),c=Math.max(this.radius.x,this.radius.y,this.radius.z);return n>this.velocityWorldLength+c+i?!1:e(s,r,this.basePointWorld,this.velocityWorldLength+c)?!0:!1},i.prototype._testTriangle=function(e,i,s,r,n,c){var h,a=!1;i||(i=[]),i[e]||(i[e]=new t.Plane(0,0,0,0),i[e].copyFromPoints(s,r,n));var l=i[e];if(c||l.isFrontFacingTo(this.normalizedVelocity,0)){var _=l.signedDistanceTo(this.basePoint),d=t.Vector3.Dot(l.normal,this.velocity);if(0==d){if(Math.abs(_)>=1)return;a=!0,h=0}else{h=(-1-_)/d;var V=(1-_)/d;if(h>V){var u=V;V=h,h=u}if(h>1||0>V)return;0>h&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var P=!1,p=1;if(a||(this.basePoint.subtractToRef(l.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,s,r,n,l.normal)&&(P=!0,p=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!P){var m=this.velocity.lengthSquared(),f=m;this.basePoint.subtractToRef(s,this._tempVector);var T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p);y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(s)),this.basePoint.subtractToRef(r,this._tempVector),T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p),y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(r)),this.basePoint.subtractToRef(n,this._tempVector),T=2*t.Vector3.Dot(this.velocity,this._tempVector),b=this._tempVector.lengthSquared()-1,y=o(f,T,b,p),y.found&&(p=y.root,P=!0,this._collisionPoint.copyFrom(n)),r.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex);var g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex);if(f=g*-m+v*v,T=2*g*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found){var D=(v*y.root-R)/g;D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),s.addToRef(this._edge,this._collisionPoint))}n.subtractToRef(r,this._edge),r.subtractToRef(this.basePoint,this._baseToVertex),g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex),f=g*-m+v*v,T=2*g*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found&&(D=(v*y.root-R)/g,D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),r.addToRef(this._edge,this._collisionPoint))),s.subtractToRef(n,this._edge),n.subtractToRef(this.basePoint,this._baseToVertex),g=this._edge.lengthSquared(),v=t.Vector3.Dot(this._edge,this.velocity),R=t.Vector3.Dot(this._edge,this._baseToVertex),f=g*-m+v*v,T=2*g*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*v*R,b=g*(1-this._baseToVertex.lengthSquared())+R*R,y=o(f,T,b,p),y.found&&(D=(v*y.root-R)/g,D>=0&&1>=D&&(p=y.root,P=!0,this._edge.scaleInPlace(D),n.addToRef(this._edge,this._collisionPoint)))}if(P){var x=p*this.velocity.length();(!this.collisionFound||x<this.nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this.nearestDistance=x,this.collisionFound=!0)}}},i.prototype._collide=function(t,e,o,i,s,r,n){for(var c=i;s>c;c+=3){var h=e[o[c]-r],a=e[o[c+1]-r],l=e[o[c+2]-r];this._testTriangle(c,t,l,a,h,n)}},i.prototype._getResponse=function(e,o){e.addToRef(o,this._destinationPoint),o.scaleInPlace(this.nearestDistance/o.length()),this.basePoint.addToRef(o,e),e.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this.epsilon,this._displacementVector),e.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(t.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,o)},i}();t.Collider=i}(BABYLON||(BABYLON={}));var BABYLON;!function(o){o.WorkerIncluded=!0;var e=function(){function o(){this._meshes={},this._geometries={}}return o.prototype.getMeshes=function(){return this._meshes},o.prototype.getGeometries=function(){return this._geometries},o.prototype.getMesh=function(o){return this._meshes[o]},o.prototype.addMesh=function(o){this._meshes[o.uniqueId]=o},o.prototype.getGeometry=function(o){return this._geometries[o]},o.prototype.addGeometry=function(o){this._geometries[o.id]=o},o}();o.CollisionCache=e;var i=function(){function e(e,i,r){this.collider=e,this._collisionCache=i,this.finalPosition=r,this.collisionsScalingMatrix=o.Matrix.Zero(),this.collisionTranformationMatrix=o.Matrix.Zero()}return e.prototype.collideWithWorld=function(o,e,i,r){var t=.01;if(this.collider.retry>=i)return void this.finalPosition.copyFrom(o);this.collider._initialize(o,e,t);for(var s,l=this._collisionCache.getMeshes(),n=Object.keys(l),a=n.length,c=0;a>c;++c)if(s=n[c],parseInt(s)!=r){var d=l[s];d.checkCollisions&&this.checkCollision(d)}return this.collider.collisionFound?((0!==e.x||0!==e.y||0!==e.z)&&this.collider._getResponse(o,e),e.length()<=t?void this.finalPosition.copyFrom(o):(this.collider.retry++,void this.collideWithWorld(o,e,i,r))):void o.addToRef(e,this.finalPosition)},e.prototype.checkCollision=function(e){if(this.collider._canDoCollision(o.Vector3.FromArray(e.sphereCenter),e.sphereRadius,o.Vector3.FromArray(e.boxMinimum),o.Vector3.FromArray(e.boxMaximum))){o.Matrix.ScalingToRef(1/this.collider.radius.x,1/this.collider.radius.y,1/this.collider.radius.z,this.collisionsScalingMatrix);var i=o.Matrix.FromArray(e.worldMatrixFromCache);i.multiplyToRef(this.collisionsScalingMatrix,this.collisionTranformationMatrix),this.processCollisionsForSubMeshes(this.collisionTranformationMatrix,e)}},e.prototype.processCollisionsForSubMeshes=function(o,e){var i,r;if(r=e.subMeshes,i=r.length,!e.geometryId)return void console.log("no mesh geometry id");var t=this._collisionCache.getGeometry(e.geometryId);if(!t)return void console.log("couldn\'t find geometry",e.geometryId);for(var s=0;i>s;s++){var l=r[s];i>1&&!this.checkSubmeshCollision(l)||(this.collideForSubMesh(l,o,t),this.collider.collisionFound&&(this.collider.collidedMesh=e.uniqueId))}},e.prototype.collideForSubMesh=function(e,i,r){if(!r.positionsArray){r.positionsArray=[];for(var t=0,s=r.positions.length;s>t;t+=3){var l=o.Vector3.FromArray([r.positions[t],r.positions[t+1],r.positions[t+2]]);r.positionsArray.push(l)}}if(!e._lastColliderWorldVertices||!e._lastColliderTransformMatrix.equals(i)){e._lastColliderTransformMatrix=i.clone(),e._lastColliderWorldVertices=[],e._trianglePlanes=[];for(var n=e.verticesStart,a=e.verticesStart+e.verticesCount,t=n;a>t;t++)e._lastColliderWorldVertices.push(o.Vector3.TransformCoordinates(r.positionsArray[t],i))}this.collider._collide(e._trianglePlanes,e._lastColliderWorldVertices,r.indices,e.indexStart,e.indexStart+e.indexCount,e.verticesStart,e.hasMaterial)},e.prototype.checkSubmeshCollision=function(e){return this.collider._canDoCollision(o.Vector3.FromArray(e.sphereCenter),e.sphereRadius,o.Vector3.FromArray(e.boxMinimum),o.Vector3.FromArray(e.boxMaximum))},e}();o.CollideWorker=i;var r=function(){function r(){}return r.prototype.onInit=function(i){this._collisionCache=new e;var r={error:o.WorkerReplyType.SUCCESS,taskType:o.WorkerTaskType.INIT};postMessage(r,void 0)},r.prototype.onUpdate=function(e){for(var i in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(i)&&this._collisionCache.addGeometry(e.updatedGeometries[i]);for(var r in e.updatedMeshes)e.updatedMeshes.hasOwnProperty(r)&&this._collisionCache.addMesh(e.updatedMeshes[r]);var t={error:o.WorkerReplyType.SUCCESS,taskType:o.WorkerTaskType.UPDATE};postMessage(t,void 0)},r.prototype.onCollision=function(e){var r=o.Vector3.Zero(),t=new o.Collider;t.radius=o.Vector3.FromArray(e.collider.radius);var s=new i(t,this._collisionCache,r);s.collideWithWorld(o.Vector3.FromArray(e.collider.position),o.Vector3.FromArray(e.collider.velocity),e.maximumRetry,e.excludedMeshUniqueId);var l={collidedMeshUniqueId:t.collidedMesh,collisionId:e.collisionId,newPosition:r.asArray()},n={error:o.WorkerReplyType.SUCCESS,taskType:o.WorkerTaskType.COLLIDE,payload:l};postMessage(n,void 0)},r}();o.CollisionDetectorTransferable=r;try{if(self&&self instanceof WorkerGlobalScope){window={},o.Collider||(importScripts("./babylon.collisionCoordinator.js"),importScripts("./babylon.collider.js"),importScripts("../Math/babylon.math.js"));var t=new r,s=function(e){var i=e.data;switch(i.taskType){case o.WorkerTaskType.INIT:t.onInit(i.payload);break;case o.WorkerTaskType.COLLIDE:t.onCollision(i.payload);break;case o.WorkerTaskType.UPDATE:t.onUpdate(i.payload)}};self.onmessage=s}}catch(l){console.log("single worker init")}}(BABYLON||(BABYLON={}));var BABYLON;!function(e){e.CollisionWorker="",function(e){e[e.INIT=0]="INIT",e[e.UPDATE=1]="UPDATE",e[e.COLLIDE=2]="COLLIDE"}(e.WorkerTaskType||(e.WorkerTaskType={}));var o=e.WorkerTaskType;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(e.WorkerReplyType||(e.WorkerReplyType={}));var i=e.WorkerReplyType,t=function(){function t(){var r=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){r._addUpdateMeshesList[e.uniqueId]=t.SerializeMesh(e)},this.onGeometryUpdated=function(e){r._addUpdateGeometriesList[e.id]=t.SerializeGeometry(e)},this._afterRender=function(){if(r._init&&!(0==r._toRemoveGeometryArray.length&&0==r._toRemoveMeshesArray.length&&0==Object.keys(r._addUpdateGeometriesList).length&&0==Object.keys(r._addUpdateMeshesList).length||r._runningUpdated>4)){++r._runningUpdated;var e={updatedMeshes:r._addUpdateMeshesList,updatedGeometries:r._addUpdateGeometriesList,removedGeometries:r._toRemoveGeometryArray,removedMeshes:r._toRemoveMeshesArray},i={payload:e,taskType:o.UPDATE},t=[];for(var s in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(s)&&(t.push(i.payload.updatedGeometries[s].indices.buffer),t.push(i.payload.updatedGeometries[s].normals.buffer),t.push(i.payload.updatedGeometries[s].positions.buffer));r._worker.postMessage(i,t),r._addUpdateMeshesList={},r._addUpdateGeometriesList={},r._toRemoveGeometryArray=[],r._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(t){var s=t.data;if(s.error!=i.SUCCESS)return void e.Tools.Warn("error returned from worker!");switch(s.taskType){case o.INIT:r._init=!0,r._scene.meshes.forEach(function(e){r.onMeshAdded(e)}),r._scene.getGeometries().forEach(function(e){r.onGeometryAdded(e)});break;case o.UPDATE:r._runningUpdated--;break;case o.COLLIDE:r._runningCollisionTask=!1;var n=s.payload;if(!r._collisionsCallbackArray[n.collisionId])return;r._collisionsCallbackArray[n.collisionId](n.collisionId,e.Vector3.FromArray(n.newPosition),r._scene.getMeshByUniqueID(n.collidedMeshUniqueId)),r._collisionsCallbackArray[n.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return t.prototype.getNewPosition=function(e,i,t,r,s,n,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(t.radius,this._scaledPosition),i.divideToRef(t.radius,this._scaledVelocity),this._collisionsCallbackArray[a]=n;var d={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:t.radius.asArray()},collisionId:a,excludedMeshUniqueId:s?s.uniqueId:null,maximumRetry:r},l={payload:d,taskType:o.COLLIDE};this._worker.postMessage(l)}},t.prototype.init=function(i){this._scene=i,this._scene.registerAfterRender(this._afterRender);var t=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(t),this._worker.onmessage=this._onMessageFromWorker;var r={payload:{},taskType:o.INIT};this._worker.postMessage(r)},t.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},t.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},t.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},t.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},t.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},t.SerializeMesh=function(o){var i=[];o.subMeshes&&(i=o.subMeshes.map(function(e,o){return{position:o,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray()}}));var t=null;return o instanceof e.Mesh?t=o.geometry?o.geometry.id:null:o instanceof e.InstancedMesh&&(t=o.sourceMesh.geometry?o.sourceMesh.geometry.id:null),{uniqueId:o.uniqueId,id:o.id,name:o.name,geometryId:t,sphereCenter:o.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:o.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:o.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:o.getBoundingInfo().boundingBox.maximumWorld.asArray(),worldMatrixFromCache:o.worldMatrixFromCache.asArray(),subMeshes:i,checkCollisions:o.checkCollisions}},t.SerializeGeometry=function(o){return{id:o.id,positions:new Float32Array(o.getVerticesData(e.VertexBuffer.PositionKind)||[]),normals:new Float32Array(o.getVerticesData(e.VertexBuffer.NormalKind)||[]),indices:new Int32Array(o.getIndices()||[])}},t}();e.CollisionCoordinatorWorker=t;var r=function(){function o(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return o.prototype.getNewPosition=function(e,o,i,t,r,s,n){e.divideToRef(i.radius,this._scaledPosition),o.divideToRef(i.radius,this._scaledVelocity),i.collidedMesh=null,i.retry=0,i.initialVelocity=this._scaledVelocity,i.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,i,t,this._finalPosition,r),this._finalPosition.multiplyInPlace(i.radius),s(n,this._finalPosition,i.collidedMesh)},o.prototype.init=function(e){this._scene=e},o.prototype.destroy=function(){},o.prototype.onMeshAdded=function(e){},o.prototype.onMeshUpdated=function(e){},o.prototype.onMeshRemoved=function(e){},o.prototype.onGeometryAdded=function(e){},o.prototype.onGeometryUpdated=function(e){},o.prototype.onGeometryDeleted=function(e){},o.prototype._collideWithWorld=function(o,i,t,r,s,n){void 0===n&&(n=null);var a=10*e.Engine.CollisionsEpsilon;if(t.retry>=r)return void s.copyFrom(o);t._initialize(o,i,a);for(var d=0;d<this._scene.meshes.length;d++){var l=this._scene.meshes[d];l.isEnabled()&&l.checkCollisions&&l.subMeshes&&l!==n&&l._checkCollision(t)}return t.collisionFound?((0!==i.x||0!==i.y||0!==i.z)&&t._getResponse(o,i),i.length()<=a?void s.copyFrom(o):(t.retry++,void this._collideWithWorld(o,i,t,r,s,n))):void o.addToRef(i,s)},o}();e.CollisionCoordinatorLegacy=r}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var i=function(){function i(t,i,o){void 0===t&&(t=0),void 0===i&&(i=0),void 0===o&&(o=0),this.r=t,this.g=i,this.b=o}return i.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},i.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.r,t[i+1]=this.g,t[i+2]=this.b,this},i.prototype.toColor4=function(t){return void 0===t&&(t=1),new o(this.r,this.g,this.b,t)},i.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},i.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},i.prototype.multiply=function(t){return new i(this.r*t.r,this.g*t.g,this.b*t.b)},i.prototype.multiplyToRef=function(t,i){return i.r=this.r*t.r,i.g=this.g*t.g,i.b=this.b*t.b,this},i.prototype.equals=function(t){return t&&this.r===t.r&&this.g===t.g&&this.b===t.b},i.prototype.equalsFloats=function(t,i,o){return this.r===t&&this.g===i&&this.b===o},i.prototype.scale=function(t){return new i(this.r*t,this.g*t,this.b*t)},i.prototype.scaleToRef=function(t,i){return i.r=this.r*t,i.g=this.g*t,i.b=this.b*t,this},i.prototype.add=function(t){return new i(this.r+t.r,this.g+t.g,this.b+t.b)},i.prototype.addToRef=function(t,i){return i.r=this.r+t.r,i.g=this.g+t.g,i.b=this.b+t.b,this},i.prototype.subtract=function(t){return new i(this.r-t.r,this.g-t.g,this.b-t.b)},i.prototype.subtractToRef=function(t,i){return i.r=this.r-t.r,i.g=this.g-t.g,i.b=this.b-t.b,this},i.prototype.clone=function(){return new i(this.r,this.g,this.b)},i.prototype.copyFrom=function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this},i.prototype.copyFromFloats=function(t,i,o){return this.r=t,this.g=i,this.b=o,this},i.prototype.toHexString=function(){var i=255*this.r|0,o=255*this.g|0,n=255*this.b|0;return"#"+t.Tools.ToHex(i)+t.Tools.ToHex(o)+t.Tools.ToHex(n)},i.FromHexString=function(o){if("#"!==o.substring(0,1)||7!==o.length)return t.Tools.Warn("Color3.FromHexString must be called with a string like #FFFFFF"),new i(0,0,0);var n=parseInt(o.substring(1,3),16),r=parseInt(o.substring(3,5),16),s=parseInt(o.substring(5,7),16);return i.FromInts(n,r,s)},i.FromArray=function(t,o){return void 0===o&&(o=0),new i(t[o],t[o+1],t[o+2])},i.FromInts=function(t,o,n){return new i(t/255,o/255,n/255)},i.Lerp=function(t,o,n){var r=t.r+(o.r-t.r)*n,s=t.g+(o.g-t.g)*n,e=t.b+(o.b-t.b)*n;return new i(r,s,e)},i.Red=function(){return new i(1,0,0)},i.Green=function(){return new i(0,1,0)},i.Blue=function(){return new i(0,0,1)},i.Black=function(){return new i(0,0,0)},i.White=function(){return new i(1,1,1)},i.Purple=function(){return new i(.5,0,.5)},i.Magenta=function(){return new i(1,0,1)},i.Yellow=function(){return new i(1,1,0)},i.Gray=function(){return new i(.5,.5,.5)},i}();t.Color3=i;var o=function(){function i(t,i,o,n){this.r=t,this.g=i,this.b=o,this.a=n}return i.prototype.addInPlace=function(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this.a+=t.a,this},i.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},i.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.r,t[i+1]=this.g,t[i+2]=this.b,t[i+3]=this.a,this},i.prototype.add=function(t){return new i(this.r+t.r,this.g+t.g,this.b+t.b,this.a+t.a)},i.prototype.subtract=function(t){return new i(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)},i.prototype.subtractToRef=function(t,i){return i.r=this.r-t.r,i.g=this.g-t.g,i.b=this.b-t.b,i.a=this.a-t.a,this},i.prototype.scale=function(t){return new i(this.r*t,this.g*t,this.b*t,this.a*t)},i.prototype.scaleToRef=function(t,i){return i.r=this.r*t,i.g=this.g*t,i.b=this.b*t,i.a=this.a*t,this},i.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},i.prototype.clone=function(){return new i(this.r,this.g,this.b,this.a)},i.prototype.copyFrom=function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this.a=t.a,this},i.prototype.toHexString=function(){var i=255*this.r|0,o=255*this.g|0,n=255*this.b|0,r=255*this.a|0;return"#"+t.Tools.ToHex(i)+t.Tools.ToHex(o)+t.Tools.ToHex(n)+t.Tools.ToHex(r)},i.FromHexString=function(o){if("#"!==o.substring(0,1)||9!==o.length)return t.Tools.Warn("Color4.FromHexString must be called with a string like #FFFFFFFF"),new i(0,0,0,0);var n=parseInt(o.substring(1,3),16),r=parseInt(o.substring(3,5),16),s=parseInt(o.substring(5,7),16),e=parseInt(o.substring(7,9),16);return i.FromInts(n,r,s,e)},i.Lerp=function(t,o,n){var r=new i(0,0,0,0);return i.LerpToRef(t,o,n,r),r},i.LerpToRef=function(t,i,o,n){n.r=t.r+(i.r-t.r)*o,n.g=t.g+(i.g-t.g)*o,n.b=t.b+(i.b-t.b)*o,n.a=t.a+(i.a-t.a)*o},i.FromArray=function(t,o){return void 0===o&&(o=0),new i(t[o],t[o+1],t[o+2],t[o+3])},i.FromInts=function(t,o,n,r){return new i(t/255,o/255,n/255,r/255)},i}();t.Color4=o;var n=function(){function i(t,i){this.x=t,this.y=i}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},i.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,this},i.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},i.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this},i.prototype.copyFromFloats=function(t,i){return this.x=t,this.y=i,this},i.prototype.add=function(t){return new i(this.x+t.x,this.y+t.y)},i.prototype.addVector3=function(t){return new i(this.x+t.x,this.y+t.y)},i.prototype.subtract=function(t){return new i(this.x-t.x,this.y-t.y)},i.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this},i.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this},i.prototype.multiply=function(t){return new i(this.x*t.x,this.y*t.y)},i.prototype.multiplyToRef=function(t,i){return i.x=this.x*t.x,i.y=this.y*t.y,this},i.prototype.multiplyByFloats=function(t,o){return new i(this.x*t,this.y*o)},i.prototype.divide=function(t){return new i(this.x/t.x,this.y/t.y)},i.prototype.divideToRef=function(t,i){return i.x=this.x/t.x,i.y=this.y/t.y,this},i.prototype.negate=function(){return new i(-this.x,-this.y)},i.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this},i.prototype.scale=function(t){return new i(this.x*t,this.y*t)},i.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y},i.prototype.equalsWithEpsilon=function(i,o){return void 0===o&&(o=t.Engine.Epsilon),i&&t.Tools.WithinEpsilon(this.x,i.x,o)&&t.Tools.WithinEpsilon(this.y,i.y,o)},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},i.prototype.normalize=function(){var t=this.length();if(0===t)return this;var i=1/t;return this.x*=i,this.y*=i,this},i.prototype.clone=function(){return new i(this.x,this.y)},i.Zero=function(){return new i(0,0)},i.FromArray=function(t,o){return void 0===o&&(o=0),new i(t[o],t[o+1])},i.FromArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1]},i.CatmullRom=function(t,o,n,r,s){var e=s*s,a=s*e,h=.5*(2*o.x+(-t.x+n.x)*s+(2*t.x-5*o.x+4*n.x-r.x)*e+(-t.x+3*o.x-3*n.x+r.x)*a),u=.5*(2*o.y+(-t.y+n.y)*s+(2*t.y-5*o.y+4*n.y-r.y)*e+(-t.y+3*o.y-3*n.y+r.y)*a);return new i(h,u)},i.Clamp=function(t,o,n){var r=t.x;r=r>n.x?n.x:r,r=r<o.x?o.x:r;var s=t.y;return s=s>n.y?n.y:s,s=s<o.y?o.y:s,new i(r,s)},i.Hermite=function(t,o,n,r,s){var e=s*s,a=s*e,h=2*a-3*e+1,u=-2*a+3*e,l=a-2*e+s,m=a-e,f=t.x*h+n.x*u+o.x*l+r.x*m,x=t.y*h+n.y*u+o.y*l+r.y*m;return new i(f,x)},i.Lerp=function(t,o,n){var r=t.x+(o.x-t.x)*n,s=t.y+(o.y-t.y)*n;return new i(r,s)},i.Dot=function(t,i){return t.x*i.x+t.y*i.y},i.Normalize=function(t){var i=t.clone();return i.normalize(),i},i.Minimize=function(t,o){var n=t.x<o.x?t.x:o.x,r=t.y<o.y?t.y:o.y;return new i(n,r)},i.Maximize=function(t,o){var n=t.x>o.x?t.x:o.x,r=t.y>o.y?t.y:o.y;return new i(n,r)},i.Transform=function(t,o){var n=t.x*o.m[0]+t.y*o.m[4],r=t.x*o.m[1]+t.y*o.m[5];return new i(n,r)},i.Distance=function(t,o){return Math.sqrt(i.DistanceSquared(t,o))},i.DistanceSquared=function(t,i){var o=t.x-i.x,n=t.y-i.y;return o*o+n*n},i}();t.Vector2=n;var r=function(){function i(t,i,o){this.x=t,this.y=i,this.z=o}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},i.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},i.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,t[i+2]=this.z,this},i.prototype.toQuaternion=function(){var t=new e(0,0,0,1),i=Math.cos(.5*(this.x+this.z)),o=Math.sin(.5*(this.x+this.z)),n=Math.cos(.5*(this.z-this.x)),r=Math.sin(.5*(this.z-this.x)),s=Math.cos(.5*this.y),a=Math.sin(.5*this.y);return t.x=n*a,t.y=-r*a,t.z=o*s,t.w=i*s,t},i.prototype.addInPlace=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},i.prototype.add=function(t){return new i(this.x+t.x,this.y+t.y,this.z+t.z)},i.prototype.addToRef=function(t,i){return i.x=this.x+t.x,i.y=this.y+t.y,i.z=this.z+t.z,this},i.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},i.prototype.subtract=function(t){return new i(this.x-t.x,this.y-t.y,this.z-t.z)},i.prototype.subtractToRef=function(t,i){return i.x=this.x-t.x,i.y=this.y-t.y,i.z=this.z-t.z,this},i.prototype.subtractFromFloats=function(t,o,n){return new i(this.x-t,this.y-o,this.z-n)},i.prototype.subtractFromFloatsToRef=function(t,i,o,n){return n.x=this.x-t,n.y=this.y-i,n.z=this.z-o,this},i.prototype.negate=function(){return new i(-this.x,-this.y,-this.z)},i.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this.z*=t,this},i.prototype.scale=function(t){return new i(this.x*t,this.y*t,this.z*t)},i.prototype.scaleToRef=function(t,i){i.x=this.x*t,i.y=this.y*t,i.z=this.z*t},i.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z},i.prototype.equalsWithEpsilon=function(i,o){return void 0===o&&(o=t.Engine.Epsilon),i&&t.Tools.WithinEpsilon(this.x,i.x,o)&&t.Tools.WithinEpsilon(this.y,i.y,o)&&t.Tools.WithinEpsilon(this.z,i.z,o)},i.prototype.equalsToFloats=function(t,i,o){return this.x===t&&this.y===i&&this.z===o},i.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},i.prototype.multiply=function(t){return new i(this.x*t.x,this.y*t.y,this.z*t.z)},i.prototype.multiplyToRef=function(t,i){return i.x=this.x*t.x,i.y=this.y*t.y,i.z=this.z*t.z,this},i.prototype.multiplyByFloats=function(t,o,n){return new i(this.x*t,this.y*o,this.z*n)},i.prototype.divide=function(t){return new i(this.x/t.x,this.y/t.y,this.z/t.z)},i.prototype.divideToRef=function(t,i){return i.x=this.x/t.x,i.y=this.y/t.y,i.z=this.z/t.z,this},i.prototype.MinimizeInPlace=function(t){return t.x<this.x&&(this.x=t.x),t.y<this.y&&(this.y=t.y),t.z<this.z&&(this.z=t.z),this},i.prototype.MaximizeInPlace=function(t){return t.x>this.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),this},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},i.prototype.normalize=function(){var t=this.length();if(0===t||1===t)return this;var i=1/t;return this.x*=i,this.y*=i,this.z*=i,this},i.prototype.clone=function(){return new i(this.x,this.y,this.z)},i.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},i.prototype.copyFromFloats=function(t,i,o){return this.x=t,this.y=i,this.z=o,this},i.GetClipFactor=function(t,o,n,r){var s=i.Dot(t,n)-r,e=i.Dot(o,n)-r,a=s/(s-e);return a},i.FromArray=function(t,o){return o||(o=0),new i(t[o],t[o+1],t[o+2])},i.FromFloatArray=function(t,o){return o||(o=0),new i(t[o],t[o+1],t[o+2])},i.FromArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1],o.z=t[i+2]},i.FromFloatArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1],o.z=t[i+2]},i.FromFloatsToRef=function(t,i,o,n){n.x=t,n.y=i,n.z=o},i.Zero=function(){return new i(0,0,0)},i.Up=function(){return new i(0,1,0)},i.TransformCoordinates=function(t,o){var n=i.Zero();return i.TransformCoordinatesToRef(t,o,n),n},i.TransformCoordinatesToRef=function(t,i,o){var n=t.x*i.m[0]+t.y*i.m[4]+t.z*i.m[8]+i.m[12],r=t.x*i.m[1]+t.y*i.m[5]+t.z*i.m[9]+i.m[13],s=t.x*i.m[2]+t.y*i.m[6]+t.z*i.m[10]+i.m[14],e=t.x*i.m[3]+t.y*i.m[7]+t.z*i.m[11]+i.m[15];o.x=n/e,o.y=r/e,o.z=s/e},i.TransformCoordinatesFromFloatsToRef=function(t,i,o,n,r){var s=t*n.m[0]+i*n.m[4]+o*n.m[8]+n.m[12],e=t*n.m[1]+i*n.m[5]+o*n.m[9]+n.m[13],a=t*n.m[2]+i*n.m[6]+o*n.m[10]+n.m[14],h=t*n.m[3]+i*n.m[7]+o*n.m[11]+n.m[15];r.x=s/h,r.y=e/h,r.z=a/h},i.TransformCoordinatesToRefSIMD=function(t,i,o){var n=SIMD.float32x4.loadXYZ(t._data,0),r=SIMD.float32x4.load(i.m,0),s=SIMD.float32x4.load(i.m,4),e=SIMD.float32x4.load(i.m,8),a=SIMD.float32x4.load(i.m,12),h=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,0,0,0,0),r),SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,1,1,1,1),s)),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(n,2,2,2,2),e),a));h=SIMD.float32x4.div(h,SIMD.float32x4.swizzle(h,3,3,3,3)),SIMD.float32x4.storeXYZ(o._data,0,h)},i.TransformCoordinatesFromFloatsToRefSIMD=function(t,i,o,n,r){var s=SIMD.float32x4.splat(t),e=SIMD.float32x4.splat(i),a=SIMD.float32x4.splat(o),h=SIMD.float32x4.load(n.m,0),u=SIMD.float32x4.load(n.m,4),l=SIMD.float32x4.load(n.m,8),m=SIMD.float32x4.load(n.m,12),f=SIMD.float32x4.add(SIMD.float32x4.add(SIMD.float32x4.mul(s,h),SIMD.float32x4.mul(e,u)),SIMD.float32x4.add(SIMD.float32x4.mul(a,l),m));f=SIMD.float32x4.div(f,SIMD.float32x4.swizzle(f,3,3,3,3)),SIMD.float32x4.storeXYZ(r._data,0,f)},i.TransformNormal=function(t,o){var n=i.Zero();return i.TransformNormalToRef(t,o,n),n},i.TransformNormalToRef=function(t,i,o){o.x=t.x*i.m[0]+t.y*i.m[4]+t.z*i.m[8],o.y=t.x*i.m[1]+t.y*i.m[5]+t.z*i.m[9],o.z=t.x*i.m[2]+t.y*i.m[6]+t.z*i.m[10]},i.TransformNormalFromFloatsToRef=function(t,i,o,n,r){r.x=t*n.m[0]+i*n.m[4]+o*n.m[8],r.y=t*n.m[1]+i*n.m[5]+o*n.m[9],r.z=t*n.m[2]+i*n.m[6]+o*n.m[10]},i.CatmullRom=function(t,o,n,r,s){var e=s*s,a=s*e,h=.5*(2*o.x+(-t.x+n.x)*s+(2*t.x-5*o.x+4*n.x-r.x)*e+(-t.x+3*o.x-3*n.x+r.x)*a),u=.5*(2*o.y+(-t.y+n.y)*s+(2*t.y-5*o.y+4*n.y-r.y)*e+(-t.y+3*o.y-3*n.y+r.y)*a),l=.5*(2*o.z+(-t.z+n.z)*s+(2*t.z-5*o.z+4*n.z-r.z)*e+(-t.z+3*o.z-3*n.z+r.z)*a);return new i(h,u,l)},i.Clamp=function(t,o,n){var r=t.x;r=r>n.x?n.x:r,r=r<o.x?o.x:r;var s=t.y;s=s>n.y?n.y:s,s=s<o.y?o.y:s;var e=t.z;return e=e>n.z?n.z:e,e=e<o.z?o.z:e,new i(r,s,e)},i.Hermite=function(t,o,n,r,s){var e=s*s,a=s*e,h=2*a-3*e+1,u=-2*a+3*e,l=a-2*e+s,m=a-e,f=t.x*h+n.x*u+o.x*l+r.x*m,x=t.y*h+n.y*u+o.y*l+r.y*m,y=t.z*h+n.z*u+o.z*l+r.z*m;return new i(f,x,y)},i.Lerp=function(t,o,n){var r=t.x+(o.x-t.x)*n,s=t.y+(o.y-t.y)*n,e=t.z+(o.z-t.z)*n;return new i(r,s,e)},i.Dot=function(t,i){return t.x*i.x+t.y*i.y+t.z*i.z},i.Cross=function(t,o){var n=i.Zero();return i.CrossToRef(t,o,n),n},i.CrossToRef=function(t,i,o){o.x=t.y*i.z-t.z*i.y,o.y=t.z*i.x-t.x*i.z,o.z=t.x*i.y-t.y*i.x},i.Normalize=function(t){var o=i.Zero();return i.NormalizeToRef(t,o),o},i.NormalizeToRef=function(t,i){i.copyFrom(t),i.normalize()},i.Project=function(t,o,n,r){var s=r.width,e=r.height,h=r.x,u=r.y,l=a.FromValues(s/2,0,0,0,0,-e/2,0,0,0,0,1,0,h+s/2,e/2+u,0,1),m=o.multiply(n).multiply(l);return i.TransformCoordinates(t,m)},i.UnprojectFromTransform=function(o,n,r,s,e){var a=s.multiply(e);a.invert(),o.x=o.x/n*2-1,o.y=-(o.y/r*2-1);var h=i.TransformCoordinates(o,a),u=o.x*a.m[3]+o.y*a.m[7]+o.z*a.m[11]+a.m[15];return t.Tools.WithinEpsilon(u,1)&&(h=h.scale(1/u)),h},i.Unproject=function(o,n,r,s,e,a){var h=s.multiply(e).multiply(a);h.invert();var u=new i(o.x/n*2-1,-(o.y/r*2-1),o.z),l=i.TransformCoordinates(u,h),m=u.x*h.m[3]+u.y*h.m[7]+u.z*h.m[11]+h.m[15];return t.Tools.WithinEpsilon(m,1)&&(l=l.scale(1/m)),l},i.Minimize=function(t,i){var o=t.clone();return o.MinimizeInPlace(i),o},i.Maximize=function(t,i){var o=t.clone();return o.MaximizeInPlace(i),o},i.Distance=function(t,o){return Math.sqrt(i.DistanceSquared(t,o))},i.DistanceSquared=function(t,i){var o=t.x-i.x,n=t.y-i.y,r=t.z-i.z;return o*o+n*n+r*r},i.Center=function(t,i){var o=t.add(i);return o.scaleInPlace(.5),o},i.RotationFromAxis=function(t,o,n){var r=i.Zero();return i.RotationFromAxisToRef(t,o,n,r),r},i.RotationFromAxisToRef=function(o,n,r,s){var e,a,h,u=i.Normalize(o),l=i.Normalize(r),m=f.X,x=f.Y,y=0,c=0,p=0,z=0,M=0,w=0,d=0,I=-1,D=0,S=0;t.Tools.WithinEpsilon(l.z,0,t.Engine.Epsilon)?w=1:t.Tools.WithinEpsilon(l.x,0,t.Engine.Epsilon)?z=1:(d=l.z/l.x,z=-d*Math.sqrt(1/(1+d*d)),w=Math.sqrt(1/(1+d*d))),a=new i(z,M,w),a.normalize(),h=i.Cross(l,a),h.normalize(),e=i.Cross(u,a),e.normalize(),i.Dot(l,e)<0&&(I=1),S=i.Dot(u,a),S=Math.min(1,Math.max(-1,S)),p=Math.acos(S)*I,i.Dot(a,m)<0&&(p=Math.PI+p,a=a.scaleInPlace(-1),h=h.scaleInPlace(-1),D++);var v,g;z=0,M=0,w=0,I=-1,t.Tools.WithinEpsilon(l.z,0,t.Engine.Epsilon)?z=1:(d=a.z/a.x,z=-d*Math.sqrt(1/(1+d*d)),w=Math.sqrt(1/(1+d*d))),v=new i(z,M,w),v.normalize(),g=i.Cross(v,a),g.normalize(),e=i.Cross(l,v),e.normalize(),i.Dot(a,e)<0&&(I=1),S=i.Dot(l,v),S=Math.min(1,Math.max(-1,S)),c=Math.acos(S)*I,i.Dot(g,x)<0&&(c=Math.PI+c,g=g.scaleInPlace(-1),v=v.scaleInPlace(-1),D++),I=-1,e=i.Cross(m,a),e.normalize(),i.Dot(e,x)<0&&(I=1),S=i.Dot(a,m),S=Math.min(1,Math.max(-1,S)),y=-Math.acos(S)*I,0>S&&2>D&&(y=Math.PI+y),s.x=c,s.y=y,s.z=p},i}();t.Vector3=r;var s=function(){function i(t,i,o,n){this.x=t,this.y=i,this.z=o,this.w=n}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"W:"+this.w+"}"},i.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},i.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,t[i+2]=this.z,t[i+3]=this.w,this},i.prototype.addInPlace=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this},i.prototype.add=function(t){return new i(this.x+t.x,this.y+t.y,this.z+t.z,this.w+t.w)},i.prototype.addToRef=function(t,i){return i.x=this.x+t.x,i.y=this.y+t.y,i.z=this.z+t.z,i.w=this.w+t.w,this},i.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this},i.prototype.subtract=function(t){return new i(this.x-t.x,this.y-t.y,this.z-t.z,this.w-t.w)},i.prototype.subtractToRef=function(t,i){return i.x=this.x-t.x,i.y=this.y-t.y,i.z=this.z-t.z,i.w=this.w-t.w,this},i.prototype.subtractFromFloats=function(t,o,n,r){return new i(this.x-t,this.y-o,this.z-n,this.w-r)},i.prototype.subtractFromFloatsToRef=function(t,i,o,n,r){return r.x=this.x-t,r.y=this.y-i,r.z=this.z-o,r.w=this.w-n,this},i.prototype.negate=function(){return new i(-this.x,-this.y,-this.z,-this.w)},i.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},i.prototype.scale=function(t){return new i(this.x*t,this.y*t,this.z*t,this.w*t)},i.prototype.scaleToRef=function(t,i){i.x=this.x*t,i.y=this.y*t,i.z=this.z*t,i.w=this.w*t},i.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w},i.prototype.equalsWithEpsilon=function(i,o){return void 0===o&&(o=t.Engine.Epsilon),i&&t.Tools.WithinEpsilon(this.x,i.x,o)&&t.Tools.WithinEpsilon(this.y,i.y,o)&&t.Tools.WithinEpsilon(this.z,i.z,o)&&t.Tools.WithinEpsilon(this.w,i.w,o)},i.prototype.equalsToFloats=function(t,i,o,n){return this.x===t&&this.y===i&&this.z===o&&this.w===n},i.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this},i.prototype.multiply=function(t){return new i(this.x*t.x,this.y*t.y,this.z*t.z,this.w*t.w)},i.prototype.multiplyToRef=function(t,i){return i.x=this.x*t.x,i.y=this.y*t.y,i.z=this.z*t.z,i.w=this.w*t.w,this},i.prototype.multiplyByFloats=function(t,o,n,r){return new i(this.x*t,this.y*o,this.z*n,this.w*r)},i.prototype.divide=function(t){return new i(this.x/t.x,this.y/t.y,this.z/t.z,this.w/t.w)},i.prototype.divideToRef=function(t,i){return i.x=this.x/t.x,i.y=this.y/t.y,i.z=this.z/t.z,i.w=this.w/t.w,this},i.prototype.MinimizeInPlace=function(t){return t.x<this.x&&(this.x=t.x),t.y<this.y&&(this.y=t.y),t.z<this.z&&(this.z=t.z),t.w<this.w&&(this.w=t.w),this},i.prototype.MaximizeInPlace=function(t){return t.x>this.x&&(this.x=t.x),t.y>this.y&&(this.y=t.y),t.z>this.z&&(this.z=t.z),t.w>this.w&&(this.w=t.w),this},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},i.prototype.normalize=function(){var t=this.length();if(0===t)return this;var i=1/t;return this.x*=i,this.y*=i,this.z*=i,this.w*=i,this},i.prototype.clone=function(){return new i(this.x,this.y,this.z,this.w)},i.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},i.prototype.copyFromFloats=function(t,i,o,n){return this.x=t,this.y=i,this.z=o,this.w=n,this},i.FromArray=function(t,o){return o||(o=0),new i(t[o],t[o+1],t[o+2],t[o+3])},i.FromArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1],o.z=t[i+2],o.w=t[i+3]},i.FromFloatArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1],o.z=t[i+2],o.w=t[i+3]},i.FromFloatsToRef=function(t,i,o,n,r){r.x=t,r.y=i,r.z=o,r.w=n},i.Zero=function(){return new i(0,0,0,0)},i.Normalize=function(t){var o=i.Zero();return i.NormalizeToRef(t,o),o},i.NormalizeToRef=function(t,i){i.copyFrom(t),i.normalize()},i.Minimize=function(t,i){var o=t.clone();return o.MinimizeInPlace(i),o},i.Maximize=function(t,i){var o=t.clone();return o.MaximizeInPlace(i),o},i.Distance=function(t,o){return Math.sqrt(i.DistanceSquared(t,o))},i.DistanceSquared=function(t,i){var o=t.x-i.x,n=t.y-i.y,r=t.z-i.z,s=t.w-i.w;return o*o+n*n+r*r+s*s},i.Center=function(t,i){var o=t.add(i);return o.scaleInPlace(.5),o},i}();t.Vector4=s;var e=function(){function t(t,i,o,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===o&&(o=0),void 0===n&&(n=1),this.x=t,this.y=i,this.z=o,this.w=n}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},t.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},t.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w},t.prototype.clone=function(){return new t(this.x,this.y,this.z,this.w)},t.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},t.prototype.copyFromFloats=function(t,i,o,n){return this.x=t,this.y=i,this.z=o,this.w=n,this},t.prototype.add=function(i){return new t(this.x+i.x,this.y+i.y,this.z+i.z,this.w+i.w)},t.prototype.subtract=function(i){return new t(this.x-i.x,this.y-i.y,this.z-i.z,this.w-i.w)},t.prototype.scale=function(i){return new t(this.x*i,this.y*i,this.z*i,this.w*i)},t.prototype.multiply=function(i){var o=new t(0,0,0,1);return this.multiplyToRef(i,o),o},t.prototype.multiplyToRef=function(t,i){var o=this.x*t.w+this.y*t.z-this.z*t.y+this.w*t.x,n=-this.x*t.z+this.y*t.w+this.z*t.x+this.w*t.y,r=this.x*t.y-this.y*t.x+this.z*t.w+this.w*t.z,s=-this.x*t.x-this.y*t.y-this.z*t.z+this.w*t.w;return i.copyFromFloats(o,n,r,s),this},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},t.prototype.normalize=function(){var t=1/this.length();return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},t.prototype.toEulerAngles=function(){var t=r.Zero();return this.toEulerAnglesToRef(t),t},t.prototype.toEulerAnglesToRef=function(t){var i=this.x,o=this.y,n=this.z,r=this.w,s=i*o,e=i*n,a=r*o,h=r*n,u=r*i,l=o*n,m=i*i,f=o*o,x=m+f;return 0!==x&&1!==x?(t.x=Math.atan2(e+a,u-l),t.y=Math.acos(1-2*x),t.z=Math.atan2(e-a,u+l)):0===x?(t.x=0,t.y=0,t.z=Math.atan2(s-h,.5-f-n*n)):(t.x=Math.atan2(s-h,.5-f-n*n),t.y=Math.PI,t.z=0),this},t.prototype.toRotationMatrix=function(t){var i=this.x*this.x,o=this.y*this.y,n=this.z*this.z,r=this.x*this.y,s=this.z*this.w,e=this.z*this.x,a=this.y*this.w,h=this.y*this.z,u=this.x*this.w;return t.m[0]=1-2*(o+n),t.m[1]=2*(r+s),t.m[2]=2*(e-a),t.m[3]=0,t.m[4]=2*(r-s),t.m[5]=1-2*(n+i),t.m[6]=2*(h+u),t.m[7]=0,t.m[8]=2*(e+a),t.m[9]=2*(h-u),t.m[10]=1-2*(o+i),t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0,t.m[15]=1,this},t.prototype.fromRotationMatrix=function(i){return t.FromRotationMatrixToRef(i,this),this},t.FromRotationMatrix=function(i){var o=new t;return t.FromRotationMatrixToRef(i,o),o},t.FromRotationMatrixToRef=function(t,i){var o,n=t.m,r=n[0],s=n[4],e=n[8],a=n[1],h=n[5],u=n[9],l=n[2],m=n[6],f=n[10],x=r+h+f;x>0?(o=.5/Math.sqrt(x+1),i.w=.25/o,i.x=(m-u)*o,i.y=(e-l)*o,i.z=(a-s)*o):r>h&&r>f?(o=2*Math.sqrt(1+r-h-f),i.w=(m-u)/o,i.x=.25*o,i.y=(s+a)/o,i.z=(e+l)/o):h>f?(o=2*Math.sqrt(1+h-r-f),i.w=(e-l)/o,i.x=(s+a)/o,i.y=.25*o,i.z=(u+m)/o):(o=2*Math.sqrt(1+f-r-h),i.w=(a-s)/o,i.x=(e+l)/o,i.y=(u+m)/o,i.z=.25*o)},t.Inverse=function(i){return new t(-i.x,-i.y,-i.z,i.w)},t.Identity=function(){return new t(0,0,0,1)},t.RotationAxis=function(i,o){var n=new t,r=Math.sin(o/2);return n.w=Math.cos(o/2),n.x=i.x*r,n.y=i.y*r,n.z=i.z*r,n},t.FromArray=function(i,o){return o||(o=0),new t(i[o],i[o+1],i[o+2],i[o+3])},t.RotationYawPitchRoll=function(i,o,n){var r=new t;return t.RotationYawPitchRollToRef(i,o,n,r),r},t.RotationYawPitchRollToRef=function(t,i,o,n){var r=.5*o,s=.5*i,e=.5*t,a=Math.sin(r),h=Math.cos(r),u=Math.sin(s),l=Math.cos(s),m=Math.sin(e),f=Math.cos(e);n.x=f*u*h+m*l*a,n.y=m*l*h-f*u*a,n.z=f*l*a-m*u*h,n.w=f*l*h+m*u*a},t.RotationAlphaBetaGamma=function(i,o,n){var r=new t;return t.RotationAlphaBetaGammaToRef(i,o,n,r),r},t.RotationAlphaBetaGammaToRef=function(t,i,o,n){var r=.5*(o+t),s=.5*(o-t),e=.5*i;n.x=Math.cos(s)*Math.sin(e),n.y=Math.sin(s)*Math.sin(e),n.z=Math.sin(r)*Math.cos(e),n.w=Math.cos(r)*Math.cos(e)},t.Slerp=function(i,o,n){var r,s,e=n,a=i.x*o.x+i.y*o.y+i.z*o.z+i.w*o.w,h=!1;if(0>a&&(h=!0,a=-a),a>.999999)s=1-e,r=h?-e:e;else{var u=Math.acos(a),l=1/Math.sin(u);s=Math.sin((1-e)*u)*l,r=h?-Math.sin(e*u)*l:Math.sin(e*u)*l}return new t(s*i.x+r*o.x,s*i.y+r*o.y,s*i.z+r*o.z,s*i.w+r*o.w)},t}();t.Quaternion=e;var a=function(){function i(){this.m=new Float32Array(16)}return i.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},i.prototype.determinant=function(){var t=this.m[10]*this.m[15]-this.m[11]*this.m[14],i=this.m[9]*this.m[15]-this.m[11]*this.m[13],o=this.m[9]*this.m[14]-this.m[10]*this.m[13],n=this.m[8]*this.m[15]-this.m[11]*this.m[12],r=this.m[8]*this.m[14]-this.m[10]*this.m[12],s=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*t-this.m[6]*i+this.m[7]*o)-this.m[1]*(this.m[4]*t-this.m[6]*n+this.m[7]*r)+this.m[2]*(this.m[4]*i-this.m[5]*n+this.m[7]*s)-this.m[3]*(this.m[4]*o-this.m[5]*r+this.m[6]*s)},i.prototype.toArray=function(){return this.m},i.prototype.asArray=function(){return this.toArray()},i.prototype.invert=function(){return this.invertToRef(this),this},i.prototype.reset=function(){for(var t=0;16>t;t++)this.m[t]=0;return this},i.prototype.add=function(t){var o=new i;return this.addToRef(t,o),o},i.prototype.addToRef=function(t,i){for(var o=0;16>o;o++)i.m[o]=this.m[o]+t.m[o];return this},i.prototype.addToSelf=function(t){for(var i=0;16>i;i++)this.m[i]+=t.m[i];return this},i.prototype.invertToRef=function(t){var i=this.m[0],o=this.m[1],n=this.m[2],r=this.m[3],s=this.m[4],e=this.m[5],a=this.m[6],h=this.m[7],u=this.m[8],l=this.m[9],m=this.m[10],f=this.m[11],x=this.m[12],y=this.m[13],c=this.m[14],p=this.m[15],z=m*p-f*c,M=l*p-f*y,w=l*c-m*y,d=u*p-f*x,I=u*c-m*x,D=u*y-l*x,S=e*z-a*M+h*w,v=-(s*z-a*d+h*I),g=s*M-e*d+h*D,T=-(s*w-e*I+a*D),R=1/(i*S+o*v+n*g+r*T),_=a*p-h*c,b=e*p-h*y,F=e*c-a*y,A=s*p-h*x,P=s*c-a*x,C=s*y-e*x,E=a*f-h*m,L=e*f-h*l,q=e*m-a*l,Z=s*f-h*u,H=s*m-a*u,W=s*l-e*u;return t.m[0]=S*R,t.m[4]=v*R,t.m[8]=g*R,t.m[12]=T*R,t.m[1]=-(o*z-n*M+r*w)*R,t.m[5]=(i*z-n*d+r*I)*R,t.m[9]=-(i*M-o*d+r*D)*R,t.m[13]=(i*w-o*I+n*D)*R,t.m[2]=(o*_-n*b+r*F)*R,t.m[6]=-(i*_-n*A+r*P)*R,t.m[10]=(i*b-o*A+r*C)*R,t.m[14]=-(i*F-o*P+n*C)*R,t.m[3]=-(o*E-n*L+r*q)*R,t.m[7]=(i*E-n*Z+r*H)*R,t.m[11]=-(i*L-o*Z+r*W)*R,t.m[15]=(i*q-o*H+n*W)*R,this},i.prototype.invertToRefSIMD=function(t){var i,o,n,r,s,e,a,h,u,l,m=this.m,f=t.m,x=SIMD.float32x4.load(m,0),y=SIMD.float32x4.load(m,4),c=SIMD.float32x4.load(m,8),p=SIMD.float32x4.load(m,12);return s=SIMD.float32x4.shuffle(x,y,0,1,4,5),o=SIMD.float32x4.shuffle(c,p,0,1,4,5),i=SIMD.float32x4.shuffle(s,o,0,2,4,6),o=SIMD.float32x4.shuffle(o,s,1,3,5,7),s=SIMD.float32x4.shuffle(x,y,2,3,6,7),r=SIMD.float32x4.shuffle(c,p,2,3,6,7),n=SIMD.float32x4.shuffle(s,r,0,2,4,6),r=SIMD.float32x4.shuffle(r,s,1,3,5,7),s=SIMD.float32x4.mul(n,r),s=SIMD.float32x4.swizzle(s,1,0,3,2),e=SIMD.float32x4.mul(o,s),a=SIMD.float32x4.mul(i,s),s=SIMD.float32x4.swizzle(s,2,3,0,1),e=SIMD.float32x4.sub(SIMD.float32x4.mul(o,s),e),a=SIMD.float32x4.sub(SIMD.float32x4.mul(i,s),a),a=SIMD.float32x4.swizzle(a,2,3,0,1),s=SIMD.float32x4.mul(o,n),s=SIMD.float32x4.swizzle(s,1,0,3,2),e=SIMD.float32x4.add(SIMD.float32x4.mul(r,s),e),u=SIMD.float32x4.mul(i,s),s=SIMD.float32x4.swizzle(s,2,3,0,1),e=SIMD.float32x4.sub(e,SIMD.float32x4.mul(r,s)),u=SIMD.float32x4.sub(SIMD.float32x4.mul(i,s),u),u=SIMD.float32x4.swizzle(u,2,3,0,1),s=SIMD.float32x4.mul(SIMD.float32x4.swizzle(o,2,3,0,1),r),s=SIMD.float32x4.swizzle(s,1,0,3,2),n=SIMD.float32x4.swizzle(n,2,3,0,1),e=SIMD.float32x4.add(SIMD.float32x4.mul(n,s),e),h=SIMD.float32x4.mul(i,s),s=SIMD.float32x4.swizzle(s,2,3,0,1),e=SIMD.float32x4.sub(e,SIMD.float32x4.mul(n,s)),h=SIMD.float32x4.sub(SIMD.float32x4.mul(i,s),h),h=SIMD.float32x4.swizzle(h,2,3,0,1),s=SIMD.float32x4.mul(i,o),s=SIMD.float32x4.swizzle(s,1,0,3,2),h=SIMD.float32x4.add(SIMD.float32x4.mul(r,s),h),u=SIMD.float32x4.sub(SIMD.float32x4.mul(n,s),u),s=SIMD.float32x4.swizzle(s,2,3,0,1),h=SIMD.float32x4.sub(SIMD.float32x4.mul(r,s),h),u=SIMD.float32x4.sub(u,SIMD.float32x4.mul(n,s)),s=SIMD.float32x4.mul(i,r),s=SIMD.float32x4.swizzle(s,1,0,3,2),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(n,s)),h=SIMD.float32x4.add(SIMD.float32x4.mul(o,s),h),s=SIMD.float32x4.swizzle(s,2,3,0,1),a=SIMD.float32x4.add(SIMD.float32x4.mul(n,s),a),h=SIMD.float32x4.sub(h,SIMD.float32x4.mul(o,s)),s=SIMD.float32x4.mul(i,n),s=SIMD.float32x4.swizzle(s,1,0,3,2),a=SIMD.float32x4.add(SIMD.float32x4.mul(r,s),a),u=SIMD.float32x4.sub(u,SIMD.float32x4.mul(o,s)),s=SIMD.float32x4.swizzle(s,2,3,0,1),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(r,s)),u=SIMD.float32x4.add(SIMD.float32x4.mul(o,s),u),l=SIMD.float32x4.mul(i,e),l=SIMD.float32x4.add(SIMD.float32x4.swizzle(l,2,3,0,1),l),l=SIMD.float32x4.add(SIMD.float32x4.swizzle(l,1,0,3,2),l),s=SIMD.float32x4.reciprocalApproximation(l),l=SIMD.float32x4.sub(SIMD.float32x4.add(s,s),SIMD.float32x4.mul(l,SIMD.float32x4.mul(s,s))),l=SIMD.float32x4.swizzle(l,0,0,0,0),e=SIMD.float32x4.mul(l,e),a=SIMD.float32x4.mul(l,a),h=SIMD.float32x4.mul(l,h),u=SIMD.float32x4.mul(l,u),SIMD.float32x4.store(f,0,e),SIMD.float32x4.store(f,4,a),SIMD.float32x4.store(f,8,h),SIMD.float32x4.store(f,12,u),this},i.prototype.setTranslation=function(t){return this.m[12]=t.x,this.m[13]=t.y,this.m[14]=t.z,this},i.prototype.multiply=function(t){var o=new i;return this.multiplyToRef(t,o),o},i.prototype.copyFrom=function(t){for(var i=0;16>i;i++)this.m[i]=t.m[i];return this},i.prototype.copyToArray=function(t,i){void 0===i&&(i=0);for(var o=0;16>o;o++)t[i+o]=this.m[o];return this},i.prototype.multiplyToRef=function(t,i){return this.multiplyToArray(t,i.m,0),this},i.prototype.multiplyToArray=function(t,i,o){var n=this.m[0],r=this.m[1],s=this.m[2],e=this.m[3],a=this.m[4],h=this.m[5],u=this.m[6],l=this.m[7],m=this.m[8],f=this.m[9],x=this.m[10],y=this.m[11],c=this.m[12],p=this.m[13],z=this.m[14],M=this.m[15],w=t.m[0],d=t.m[1],I=t.m[2],D=t.m[3],S=t.m[4],v=t.m[5],g=t.m[6],T=t.m[7],R=t.m[8],_=t.m[9],b=t.m[10],F=t.m[11],A=t.m[12],P=t.m[13],C=t.m[14],E=t.m[15];return i[o]=n*w+r*S+s*R+e*A,i[o+1]=n*d+r*v+s*_+e*P,i[o+2]=n*I+r*g+s*b+e*C,i[o+3]=n*D+r*T+s*F+e*E,i[o+4]=a*w+h*S+u*R+l*A,i[o+5]=a*d+h*v+u*_+l*P,i[o+6]=a*I+h*g+u*b+l*C,i[o+7]=a*D+h*T+u*F+l*E,i[o+8]=m*w+f*S+x*R+y*A,i[o+9]=m*d+f*v+x*_+y*P,i[o+10]=m*I+f*g+x*b+y*C,i[o+11]=m*D+f*T+x*F+y*E,i[o+12]=c*w+p*S+z*R+M*A,i[o+13]=c*d+p*v+z*_+M*P,i[o+14]=c*I+p*g+z*b+M*C,i[o+15]=c*D+p*T+z*F+M*E,this},i.prototype.multiplyToArraySIMD=function(t,i,o){void 0===o&&(o=0);var n=this.m,r=t.m,s=SIMD.float32x4.load(r,0),e=SIMD.float32x4.load(r,4),a=SIMD.float32x4.load(r,8),h=SIMD.float32x4.load(r,12),u=SIMD.float32x4.load(n,0);SIMD.float32x4.store(i,o+0,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,0,0,0,0),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,1,1,1,1),e),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(u,3,3,3,3),h)))));\n\nvar l=SIMD.float32x4.load(n,4);SIMD.float32x4.store(i,o+4,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,0,0,0,0),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,1,1,1,1),e),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,3,3,3,3),h)))));var m=SIMD.float32x4.load(n,8);SIMD.float32x4.store(i,o+8,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,0,0,0,0),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,1,1,1,1),e),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,3,3,3,3),h)))));var f=SIMD.float32x4.load(n,12);SIMD.float32x4.store(i,o+12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,0,0,0,0),s),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,1,1,1,1),e),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,2,2,2,2),a),SIMD.float32x4.mul(SIMD.float32x4.swizzle(f,3,3,3,3),h)))))},i.prototype.equals=function(t){return t&&this.m[0]===t.m[0]&&this.m[1]===t.m[1]&&this.m[2]===t.m[2]&&this.m[3]===t.m[3]&&this.m[4]===t.m[4]&&this.m[5]===t.m[5]&&this.m[6]===t.m[6]&&this.m[7]===t.m[7]&&this.m[8]===t.m[8]&&this.m[9]===t.m[9]&&this.m[10]===t.m[10]&&this.m[11]===t.m[11]&&this.m[12]===t.m[12]&&this.m[13]===t.m[13]&&this.m[14]===t.m[14]&&this.m[15]===t.m[15]},i.prototype.clone=function(){return i.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])},i.prototype.decompose=function(o,n,r){r.x=this.m[12],r.y=this.m[13],r.z=this.m[14];var s=t.Tools.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,a=t.Tools.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,h=t.Tools.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(o.x=s*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),o.y=a*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),o.z=h*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===o.x||0===o.y||0===o.z)return n.x=0,n.y=0,n.z=0,n.w=1,!1;var u=i.FromValues(this.m[0]/o.x,this.m[1]/o.x,this.m[2]/o.x,0,this.m[4]/o.y,this.m[5]/o.y,this.m[6]/o.y,0,this.m[8]/o.z,this.m[9]/o.z,this.m[10]/o.z,0,0,0,0,1);return e.FromRotationMatrixToRef(u,n),!0},i.FromArray=function(t,o){var n=new i;return o||(o=0),i.FromArrayToRef(t,o,n),n},i.FromArrayToRef=function(t,i,o){for(var n=0;16>n;n++)o.m[n]=t[n+i]},i.FromFloat32ArrayToRefScaled=function(t,i,o,n){for(var r=0;16>r;r++)n.m[r]=t[r+i]*o},i.FromValuesToRef=function(t,i,o,n,r,s,e,a,h,u,l,m,f,x,y,c,p){p.m[0]=t,p.m[1]=i,p.m[2]=o,p.m[3]=n,p.m[4]=r,p.m[5]=s,p.m[6]=e,p.m[7]=a,p.m[8]=h,p.m[9]=u,p.m[10]=l,p.m[11]=m,p.m[12]=f,p.m[13]=x,p.m[14]=y,p.m[15]=c},i.FromValues=function(t,o,n,r,s,e,a,h,u,l,m,f,x,y,c,p){var z=new i;return z.m[0]=t,z.m[1]=o,z.m[2]=n,z.m[3]=r,z.m[4]=s,z.m[5]=e,z.m[6]=a,z.m[7]=h,z.m[8]=u,z.m[9]=l,z.m[10]=m,z.m[11]=f,z.m[12]=x,z.m[13]=y,z.m[14]=c,z.m[15]=p,z},i.Compose=function(t,o,n){var r=i.FromValues(t.x,0,0,0,0,t.y,0,0,0,0,t.z,0,0,0,0,1),s=i.Identity();return o.toRotationMatrix(s),r=r.multiply(s),r.setTranslation(n),r},i.Identity=function(){return i.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},i.IdentityToRef=function(t){i.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,t)},i.Zero=function(){return i.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},i.RotationX=function(t){var o=new i;return i.RotationXToRef(t,o),o},i.Invert=function(t){var o=new i;return t.invertToRef(o),o},i.RotationXToRef=function(t,i){var o=Math.sin(t),n=Math.cos(t);i.m[0]=1,i.m[15]=1,i.m[5]=n,i.m[10]=n,i.m[9]=-o,i.m[6]=o,i.m[1]=0,i.m[2]=0,i.m[3]=0,i.m[4]=0,i.m[7]=0,i.m[8]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},i.RotationY=function(t){var o=new i;return i.RotationYToRef(t,o),o},i.RotationYToRef=function(t,i){var o=Math.sin(t),n=Math.cos(t);i.m[5]=1,i.m[15]=1,i.m[0]=n,i.m[2]=-o,i.m[8]=o,i.m[10]=n,i.m[1]=0,i.m[3]=0,i.m[4]=0,i.m[6]=0,i.m[7]=0,i.m[9]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},i.RotationZ=function(t){var o=new i;return i.RotationZToRef(t,o),o},i.RotationZToRef=function(t,i){var o=Math.sin(t),n=Math.cos(t);i.m[10]=1,i.m[15]=1,i.m[0]=n,i.m[1]=o,i.m[4]=-o,i.m[5]=n,i.m[2]=0,i.m[3]=0,i.m[6]=0,i.m[7]=0,i.m[8]=0,i.m[9]=0,i.m[11]=0,i.m[12]=0,i.m[13]=0,i.m[14]=0},i.RotationAxis=function(t,o){var n=Math.sin(-o),r=Math.cos(-o),s=1-r;t.normalize();var e=i.Zero();return e.m[0]=t.x*t.x*s+r,e.m[1]=t.x*t.y*s-t.z*n,e.m[2]=t.x*t.z*s+t.y*n,e.m[3]=0,e.m[4]=t.y*t.x*s+t.z*n,e.m[5]=t.y*t.y*s+r,e.m[6]=t.y*t.z*s-t.x*n,e.m[7]=0,e.m[8]=t.z*t.x*s-t.y*n,e.m[9]=t.z*t.y*s+t.x*n,e.m[10]=t.z*t.z*s+r,e.m[11]=0,e.m[15]=1,e},i.RotationYawPitchRoll=function(t,o,n){var r=new i;return i.RotationYawPitchRollToRef(t,o,n,r),r},i.RotationYawPitchRollToRef=function(t,i,o,n){e.RotationYawPitchRollToRef(t,i,o,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(n)},i.Scaling=function(t,o,n){var r=i.Zero();return i.ScalingToRef(t,o,n,r),r},i.ScalingToRef=function(t,i,o,n){n.m[0]=t,n.m[1]=0,n.m[2]=0,n.m[3]=0,n.m[4]=0,n.m[5]=i,n.m[6]=0,n.m[7]=0,n.m[8]=0,n.m[9]=0,n.m[10]=o,n.m[11]=0,n.m[12]=0,n.m[13]=0,n.m[14]=0,n.m[15]=1},i.Translation=function(t,o,n){var r=i.Identity();return i.TranslationToRef(t,o,n,r),r},i.TranslationToRef=function(t,o,n,r){i.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,t,o,n,1,r)},i.LookAtLH=function(t,o,n){var r=i.Zero();return i.LookAtLHToRef(t,o,n,r),r},i.LookAtLHToRef=function(t,o,n,s){o.subtractToRef(t,this._zAxis),this._zAxis.normalize(),r.CrossToRef(n,this._zAxis,this._xAxis),this._xAxis.normalize(),r.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var e=-r.Dot(this._xAxis,t),a=-r.Dot(this._yAxis,t),h=-r.Dot(this._zAxis,t);return i.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,e,a,h,1,s)},i.LookAtLHToRefSIMD=function(t,i,o,n){var r=n.m,s=SIMD.float32x4(i.x,i.y,i.z,0),e=SIMD.float32x4(t.x,t.y,t.z,0),a=SIMD.float32x4(o.x,o.y,o.z,0),h=SIMD.float32x4.sub(s,e),u=SIMD.float32x4.mul(h,h);u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),h=SIMD.float32x4.mul(h,SIMD.float32x4.reciprocalSqrtApproximation(u)),u=SIMD.float32x4.mul(a,a),u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),a=SIMD.float32x4.mul(a,SIMD.float32x4.reciprocalSqrtApproximation(u));var l=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(h,1,2,0,3),SIMD.float32x4.swizzle(a,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(h,2,0,1,3),SIMD.float32x4.swizzle(a,1,2,0,3)));u=SIMD.float32x4.mul(l,l),u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),l=SIMD.float32x4.mul(l,SIMD.float32x4.reciprocalSqrtApproximation(u));var m=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,1,2,0,3),SIMD.float32x4.swizzle(h,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(l,2,0,1,3),SIMD.float32x4.swizzle(h,1,2,0,3)));u=SIMD.float32x4.mul(l,l),u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),l=SIMD.float32x4.mul(l,SIMD.float32x4.reciprocalSqrtApproximation(u));var f=SIMD.float32x4.splat(0);l=SIMD.float32x4.neg(l);var x=SIMD.float32x4.shuffle(l,m,0,1,4,5),y=SIMD.float32x4.shuffle(h,f,0,1,4,5),c=SIMD.float32x4.shuffle(x,y,0,2,4,6),p=SIMD.float32x4.shuffle(x,y,1,3,5,7);x=SIMD.float32x4.shuffle(l,m,2,3,6,7),y=SIMD.float32x4.shuffle(h,f,2,3,6,7);var z=SIMD.float32x4.shuffle(x,y,0,2,4,6),M=SIMD.float32x4(0,0,0,1),w=SIMD.float32x4(1,0,0,0),d=SIMD.float32x4(0,1,0,0),I=SIMD.float32x4(0,0,1,0),D=SIMD.float32x4.neg(e);D=SIMD.float32x4.withW(D,1),SIMD.float32x4.store(r,0,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(w,0,0,0,0),c),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(w,1,1,1,1),p),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(w,2,2,2,2),z),SIMD.float32x4.mul(SIMD.float32x4.swizzle(w,3,3,3,3),M))))),SIMD.float32x4.store(r,4,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,0,0,0,0),c),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,1,1,1,1),p),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,2,2,2,2),z),SIMD.float32x4.mul(SIMD.float32x4.swizzle(d,3,3,3,3),M))))),SIMD.float32x4.store(r,8,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(I,0,0,0,0),c),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(I,1,1,1,1),p),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(I,2,2,2,2),z),SIMD.float32x4.mul(SIMD.float32x4.swizzle(I,3,3,3,3),M))))),SIMD.float32x4.store(r,12,SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(D,0,0,0,0),c),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(D,1,1,1,1),p),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(D,2,2,2,2),z),SIMD.float32x4.mul(SIMD.float32x4.swizzle(D,3,3,3,3),M)))))},i.OrthoLH=function(t,o,n,r){var s=i.Zero();return i.OrthoLHToRef(t,o,n,r,s),s},i.OrthoLHToRef=function(t,o,n,r,s){var e=2/t,a=2/o,h=1/(r-n),u=n/(n-r);i.FromValuesToRef(e,0,0,0,0,a,0,0,0,0,h,0,0,0,u,1,s)},i.OrthoOffCenterLH=function(t,o,n,r,s,e){var a=i.Zero();return i.OrthoOffCenterLHToRef(t,o,n,r,s,e,a),a},i.OrthoOffCenterLHToRef=function(t,i,o,n,r,s,e){e.m[0]=2/(i-t),e.m[1]=e.m[2]=e.m[3]=0,e.m[5]=2/(n-o),e.m[4]=e.m[6]=e.m[7]=0,e.m[10]=-1/(r-s),e.m[8]=e.m[9]=e.m[11]=0,e.m[12]=(t+i)/(t-i),e.m[13]=(n+o)/(o-n),e.m[14]=r/(r-s),e.m[15]=1},i.PerspectiveLH=function(t,o,n,r){var s=i.Zero();return s.m[0]=2*n/t,s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=2*n/o,s.m[4]=s.m[6]=s.m[7]=0,s.m[10]=-r/(n-r),s.m[8]=s.m[9]=0,s.m[11]=1,s.m[12]=s.m[13]=s.m[15]=0,s.m[14]=n*r/(n-r),s},i.PerspectiveFovLH=function(t,o,n,r){var s=i.Zero();return i.PerspectiveFovLHToRef(t,o,n,r,s),s},i.PerspectiveFovLHToRef=function(i,o,n,r,s,e){void 0===e&&(e=t.Camera.FOVMODE_VERTICAL_FIXED);var a=1/Math.tan(.5*i),h=e===t.Camera.FOVMODE_VERTICAL_FIXED;s.m[0]=h?a/o:a,s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=h?a:a*o,s.m[4]=s.m[6]=s.m[7]=0,s.m[8]=s.m[9]=0,s.m[10]=-r/(n-r),s.m[11]=1,s.m[12]=s.m[13]=s.m[15]=0,s.m[14]=n*r/(n-r)},i.GetFinalMatrix=function(t,o,n,r,s,e){var a=t.width,h=t.height,u=t.x,l=t.y,m=i.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,e-s,0,u+a/2,h/2+l,s,1);return o.multiply(n).multiply(r).multiply(m)},i.GetAsMatrix2x2=function(t){return new Float32Array([t.m[0],t.m[1],t.m[4],t.m[5]])},i.GetAsMatrix3x3=function(t){return new Float32Array([t.m[0],t.m[1],t.m[2],t.m[4],t.m[5],t.m[6],t.m[8],t.m[9],t.m[10]])},i.Transpose=function(t){var o=new i;return o.m[0]=t.m[0],o.m[1]=t.m[4],o.m[2]=t.m[8],o.m[3]=t.m[12],o.m[4]=t.m[1],o.m[5]=t.m[5],o.m[6]=t.m[9],o.m[7]=t.m[13],o.m[8]=t.m[2],o.m[9]=t.m[6],o.m[10]=t.m[10],o.m[11]=t.m[14],o.m[12]=t.m[3],o.m[13]=t.m[7],o.m[14]=t.m[11],o.m[15]=t.m[15],o},i.Reflection=function(t){var o=new i;return i.ReflectionToRef(t,o),o},i.ReflectionToRef=function(t,i){t.normalize();var o=t.normal.x,n=t.normal.y,r=t.normal.z,s=-2*o,e=-2*n,a=-2*r;i.m[0]=s*o+1,i.m[1]=e*o,i.m[2]=a*o,i.m[3]=0,i.m[4]=s*n,i.m[5]=e*n+1,i.m[6]=a*n,i.m[7]=0,i.m[8]=s*r,i.m[9]=e*r,i.m[10]=a*r+1,i.m[11]=0,i.m[12]=s*t.d,i.m[13]=e*t.d,i.m[14]=a*t.d,i.m[15]=1},i._tempQuaternion=new e,i._xAxis=r.Zero(),i._yAxis=r.Zero(),i._zAxis=r.Zero(),i}();t.Matrix=a;var h=function(){function t(t,i,o,n){this.normal=new r(t,i,o),this.d=n}return t.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},t.prototype.clone=function(){return new t(this.normal.x,this.normal.y,this.normal.z,this.d)},t.prototype.normalize=function(){var t=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),i=0;return 0!==t&&(i=1/t),this.normal.x*=i,this.normal.y*=i,this.normal.z*=i,this.d*=i,this},t.prototype.transform=function(i){var o=a.Transpose(i),n=this.normal.x,r=this.normal.y,s=this.normal.z,e=this.d,h=n*o.m[0]+r*o.m[1]+s*o.m[2]+e*o.m[3],u=n*o.m[4]+r*o.m[5]+s*o.m[6]+e*o.m[7],l=n*o.m[8]+r*o.m[9]+s*o.m[10]+e*o.m[11],m=n*o.m[12]+r*o.m[13]+s*o.m[14]+e*o.m[15];return new t(h,u,l,m)},t.prototype.dotCoordinate=function(t){return this.normal.x*t.x+this.normal.y*t.y+this.normal.z*t.z+this.d},t.prototype.copyFromPoints=function(t,i,o){var n,r=i.x-t.x,s=i.y-t.y,e=i.z-t.z,a=o.x-t.x,h=o.y-t.y,u=o.z-t.z,l=s*u-e*h,m=e*a-r*u,f=r*h-s*a,x=Math.sqrt(l*l+m*m+f*f);return n=0!==x?1/x:0,this.normal.x=l*n,this.normal.y=m*n,this.normal.z=f*n,this.d=-(this.normal.x*t.x+this.normal.y*t.y+this.normal.z*t.z),this},t.prototype.isFrontFacingTo=function(t,i){var o=r.Dot(this.normal,t);return i>=o},t.prototype.signedDistanceTo=function(t){return r.Dot(t,this.normal)+this.d},t.FromArray=function(i){return new t(i[0],i[1],i[2],i[3])},t.FromPoints=function(i,o,n){var r=new t(0,0,0,0);return r.copyFromPoints(i,o,n),r},t.FromPositionAndNormal=function(i,o){var n=new t(0,0,0,0);return o.normalize(),n.normal=o,n.d=-(o.x*i.x+o.y*i.y+o.z*i.z),n},t.SignedDistanceToPlaneFromPositionAndNormal=function(t,i,o){var n=-(i.x*t.x+i.y*t.y+i.z*t.z);return r.Dot(o,i)+n},t}();t.Plane=h;var u=function(){function t(t,i,o,n){this.x=t,this.y=i,this.width=o,this.height=n}return t.prototype.toGlobal=function(i){var o=i.getRenderWidth(),n=i.getRenderHeight();return new t(this.x*o,this.y*n,this.width*o,this.height*n)},t}();t.Viewport=u;var l=function(){function t(){}return t.GetPlanes=function(i){for(var o=[],n=0;6>n;n++)o.push(new h(0,0,0,0));return t.GetPlanesToRef(i,o),o},t.GetPlanesToRef=function(t,i){i[0].normal.x=t.m[3]+t.m[2],i[0].normal.y=t.m[7]+t.m[6],i[0].normal.z=t.m[11]+t.m[10],i[0].d=t.m[15]+t.m[14],i[0].normalize(),i[1].normal.x=t.m[3]-t.m[2],i[1].normal.y=t.m[7]-t.m[6],i[1].normal.z=t.m[11]-t.m[10],i[1].d=t.m[15]-t.m[14],i[1].normalize(),i[2].normal.x=t.m[3]+t.m[0],i[2].normal.y=t.m[7]+t.m[4],i[2].normal.z=t.m[11]+t.m[8],i[2].d=t.m[15]+t.m[12],i[2].normalize(),i[3].normal.x=t.m[3]-t.m[0],i[3].normal.y=t.m[7]-t.m[4],i[3].normal.z=t.m[11]-t.m[8],i[3].d=t.m[15]-t.m[12],i[3].normalize(),i[4].normal.x=t.m[3]-t.m[1],i[4].normal.y=t.m[7]-t.m[5],i[4].normal.z=t.m[11]-t.m[9],i[4].d=t.m[15]-t.m[13],i[4].normalize(),i[5].normal.x=t.m[3]+t.m[1],i[5].normal.y=t.m[7]+t.m[5],i[5].normal.z=t.m[11]+t.m[9],i[5].d=t.m[15]+t.m[13],i[5].normalize()},t}();t.Frustum=l;var m=function(){function i(t,i,o){void 0===o&&(o=Number.MAX_VALUE),this.origin=t,this.direction=i,this.length=o}return i.prototype.intersectsBoxMinMax=function(t,i){var o,n,r,s,e=0,a=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.x<t.x||this.origin.x>i.x)return!1}else if(o=1/this.direction.x,n=(t.x-this.origin.x)*o,r=(i.x-this.origin.x)*o,r===-(1/0)&&(r=1/0),n>r&&(s=n,n=r,r=s),e=Math.max(n,e),a=Math.min(r,a),e>a)return!1;if(Math.abs(this.direction.y)<1e-7){if(this.origin.y<t.y||this.origin.y>i.y)return!1}else if(o=1/this.direction.y,n=(t.y-this.origin.y)*o,r=(i.y-this.origin.y)*o,r===-(1/0)&&(r=1/0),n>r&&(s=n,n=r,r=s),e=Math.max(n,e),a=Math.min(r,a),e>a)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.z<t.z||this.origin.z>i.z)return!1}else if(o=1/this.direction.z,n=(t.z-this.origin.z)*o,r=(i.z-this.origin.z)*o,r===-(1/0)&&(r=1/0),n>r&&(s=n,n=r,r=s),e=Math.max(n,e),a=Math.min(r,a),e>a)return!1;return!0},i.prototype.intersectsBox=function(t){return this.intersectsBoxMinMax(t.minimum,t.maximum)},i.prototype.intersectsSphere=function(t){var i=t.center.x-this.origin.x,o=t.center.y-this.origin.y,n=t.center.z-this.origin.z,r=i*i+o*o+n*n,s=t.radius*t.radius;if(s>=r)return!0;var e=i*this.direction.x+o*this.direction.y+n*this.direction.z;if(0>e)return!1;var a=r-e*e;return s>=a},i.prototype.intersectsTriangle=function(i,o,n){this._edge1||(this._edge1=r.Zero(),this._edge2=r.Zero(),this._pvec=r.Zero(),this._tvec=r.Zero(),this._qvec=r.Zero()),o.subtractToRef(i,this._edge1),n.subtractToRef(i,this._edge2),r.CrossToRef(this.direction,this._edge2,this._pvec);var s=r.Dot(this._edge1,this._pvec);if(0===s)return null;var e=1/s;this.origin.subtractToRef(i,this._tvec);var a=r.Dot(this._tvec,this._pvec)*e;if(0>a||a>1)return null;r.CrossToRef(this._tvec,this._edge1,this._qvec);var h=r.Dot(this.direction,this._qvec)*e;if(0>h||a+h>1)return null;var u=r.Dot(this._edge2,this._qvec)*e;return u>this.length?null:new t.IntersectionInfo(a,h,u)},i.CreateNew=function(t,o,n,s,e,a,h){var u=r.Unproject(new r(t,o,0),n,s,e,a,h),l=r.Unproject(new r(t,o,1),n,s,e,a,h),m=l.subtract(u);return m.normalize(),new i(u,m)},i.CreateNewFromTo=function(t,o,n){void 0===n&&(n=a.Identity());var r=o.subtract(t),s=Math.sqrt(r.x*r.x+r.y*r.y+r.z*r.z);return r.normalize(),i.Transform(new i(t,r,s),n)},i.Transform=function(t,o){var n=r.TransformCoordinates(t.origin,o),s=r.TransformNormal(t.direction,o);return new i(n,s,t.length)},i}();t.Ray=m,function(t){t[t.LOCAL=0]="LOCAL",t[t.WORLD=1]="WORLD"}(t.Space||(t.Space={}));var f=(t.Space,function(){function t(){}return t.X=new r(1,0,0),t.Y=new r(0,1,0),t.Z=new r(0,0,1),t}());t.Axis=f;var x=function(){function t(){}return t.interpolate=function(t,i,o,n,r){for(var s=1-3*n+3*i,e=3*n-6*i,a=3*i,h=t,u=0;5>u;u++){var l=h*h,m=l*h,f=s*m+e*l+a*h,x=1/(3*s*l+2*e*h+a);h-=(f-t)*x,h=Math.min(1,Math.max(0,h))}return 3*Math.pow(1-h,2)*h*o+3*(1-h)*Math.pow(h,2)*r+Math.pow(h,3)},t}();t.BezierCurve=x,function(t){t[t.CW=0]="CW",t[t.CCW=1]="CCW"}(t.Orientation||(t.Orientation={}));var y=t.Orientation,c=function(){function t(t){var i=this;this.degrees=function(){return 180*i._radians/Math.PI},this.radians=function(){return i._radians},this._radians=t,this._radians<0&&(this._radians+=2*Math.PI)}return t.BetweenTwoPoints=function(i,o){var n=o.subtract(i),r=Math.atan2(n.y,n.x);return new t(r)},t.FromRadians=function(i){return new t(i)},t.FromDegrees=function(i){return new t(i*Math.PI/180)},t}();t.Angle=c;var p=function(){function t(t,i,o){this.startPoint=t,this.midPoint=i,this.endPoint=o;var r=Math.pow(i.x,2)+Math.pow(i.y,2),s=(Math.pow(t.x,2)+Math.pow(t.y,2)-r)/2,e=(r-Math.pow(o.x,2)-Math.pow(o.y,2))/2,a=(t.x-i.x)*(i.y-o.y)-(i.x-o.x)*(t.y-i.y);this.centerPoint=new n((s*(i.y-o.y)-e*(t.y-i.y))/a,((t.x-i.x)*e-(i.x-o.x)*s)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=c.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),u=c.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),l=c.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();u-h>180&&(u-=360),-180>u-h&&(u+=360),l-u>180&&(l-=360),-180>l-u&&(l+=360),this.orientation=0>u-h?y.CW:y.CCW,this.angle=c.FromDegrees(this.orientation===y.CW?h-l:l-h)}return t}();t.Arc2=p;var z=function(){function t(t){this.path=t,this._onchange=new Array,this.value=0,this.animations=new Array}return t.prototype.getPoint=function(){var t=this.path.getPointAtLengthPosition(this.value);return new r(t.x,0,t.y)},t.prototype.moveAhead=function(t){return void 0===t&&(t=.002),this.move(t),this},t.prototype.moveBack=function(t){return void 0===t&&(t=.002),this.move(-t),this},t.prototype.move=function(t){if(Math.abs(t)>1)throw"step size should be less than 1.";return this.value+=t,this.ensureLimits(),this.raiseOnChange(),this},t.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},t.prototype.markAsDirty=function(t){return this.ensureLimits(),this.raiseOnChange(),this},t.prototype.raiseOnChange=function(){var t=this;return this._onchange.forEach(function(i){return i(t)}),this},t.prototype.onchange=function(t){return this._onchange.push(t),this},t}();t.PathCursor=z;var M=function(){function i(t,i){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new n(t,i))}return i.prototype.addLineTo=function(i,o){if(closed)return t.Tools.Error("cannot add lines to closed paths"),this;var r=new n(i,o),s=this._points[this._points.length-1];return this._points.push(r),this._length+=r.subtract(s).length(),this},i.prototype.addArcTo=function(i,o,r,s,e){if(void 0===e&&(e=36),closed)return t.Tools.Error("cannot add arcs to closed paths"),this;var a=this._points[this._points.length-1],h=new n(i,o),u=new n(r,s),l=new p(a,h,u),m=l.angle.radians()/e;l.orientation===y.CW&&(m*=-1);for(var f=l.startAngle.radians()+m,x=0;e>x;x++){var c=Math.cos(f)*l.radius+l.centerPoint.x,z=Math.sin(f)*l.radius+l.centerPoint.y;this.addLineTo(c,z),f+=m}return this},i.prototype.close=function(){return this.closed=!0,this},i.prototype.length=function(){var t=this._length;if(!this.closed){var i=this._points[this._points.length-1],o=this._points[0];t+=o.subtract(i).length()}return t},i.prototype.getPoints=function(){return this._points},i.prototype.getPointAtLengthPosition=function(i){if(0>i||i>1)return t.Tools.Error("normalized length position should be between 0 and 1."),n.Zero();for(var o=i*this.length(),r=0,s=0;s<this._points.length;s++){var e=(s+1)%this._points.length,a=this._points[s],h=this._points[e],u=h.subtract(a),l=u.length()+r;if(o>=r&&l>=o){var m=u.normalize(),f=o-r;return new n(a.x+m.x*f,a.y+m.y*f)}r=l}return t.Tools.Error("internal error"),n.Zero()},i.StartingAt=function(t,o){return new i(t,o)},i}();t.Path2=M;var w=function(){function i(t,i,o){this.path=t,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var n=0;n<t.length;n++)this._curve[n]=t[n].clone();this._raw=o||!1,this._compute(i)}return i.prototype.getCurve=function(){return this._curve},i.prototype.getTangents=function(){return this._tangents},i.prototype.getNormals=function(){return this._normals},i.prototype.getBinormals=function(){return this._binormals},i.prototype.getDistances=function(){return this._distances},i.prototype.update=function(t,i){for(var o=0;o<t.length;o++)this._curve[o].x=t[o].x,this._curve[o].y=t[o].y,this._curve[o].z=t[o].z;return this._compute(i),this},i.prototype._compute=function(t){var i=this._curve.length;this._tangents[0]=this._getFirstNonNullVector(0),this._raw||this._tangents[0].normalize(),this._tangents[i-1]=this._curve[i-1].subtract(this._curve[i-2]),this._raw||this._tangents[i-1].normalize();var o=this._tangents[0],n=this._normalVector(this._curve[0],o,t);this._normals[0]=n,this._raw||this._normals[0].normalize(),this._binormals[0]=r.Cross(o,this._normals[0]),this._raw||this._binormals[0].normalize(),this._distances[0]=0;for(var s,e,a,h,u=1;i>u;u++)s=this._getLastNonNullVector(u),i-1>u&&(e=this._getFirstNonNullVector(u),this._tangents[u]=s.add(e),this._tangents[u].normalize()),this._distances[u]=this._distances[u-1]+s.length(),a=this._tangents[u],h=this._binormals[u-1],this._normals[u]=r.Cross(h,a),this._raw||this._normals[u].normalize(),this._binormals[u]=r.Cross(a,this._normals[u]),this._raw||this._binormals[u].normalize()},i.prototype._getFirstNonNullVector=function(t){for(var i=1,o=this._curve[t+i].subtract(this._curve[t]);0===o.length()&&t+i+1<this._curve.length;)i++,o=this._curve[t+i].subtract(this._curve[t]);return o},i.prototype._getLastNonNullVector=function(t){for(var i=1,o=this._curve[t].subtract(this._curve[t-i]);0===o.length()&&t>i+1;)i++,o=this._curve[t].subtract(this._curve[t-i]);return o},i.prototype._normalVector=function(i,o,n){var s;if(void 0===n||null===n){var e;t.Tools.WithinEpsilon(o.y,1,t.Engine.Epsilon)?t.Tools.WithinEpsilon(o.x,1,t.Engine.Epsilon)?t.Tools.WithinEpsilon(o.z,1,t.Engine.Epsilon)||(e=new r(0,0,1)):e=new r(1,0,0):e=new r(0,-1,0),s=r.Cross(o,e)}else s=r.Cross(o,n),r.CrossToRef(s,o,s);return s.normalize(),s},i}();t.Path3D=w;var d=function(){function t(t){this._length=0,this._points=t,this._length=this._computeLength(t)}return t.CreateQuadraticBezier=function(i,o,n,s){s=s>2?s:3;for(var e=new Array,a=function(t,i,o,n){var r=(1-t)*(1-t)*i+2*t*(1-t)*o+t*t*n;return r},h=0;s>=h;h++)e.push(new r(a(h/s,i.x,o.x,n.x),a(h/s,i.y,o.y,n.y),a(h/s,i.z,o.z,n.z)));return new t(e)},t.CreateCubicBezier=function(i,o,n,s,e){e=e>3?e:4;for(var a=new Array,h=function(t,i,o,n,r){var s=(1-t)*(1-t)*(1-t)*i+3*t*(1-t)*(1-t)*o+3*t*t*(1-t)*n+t*t*t*r;return s},u=0;e>=u;u++)a.push(new r(h(u/e,i.x,o.x,n.x,s.x),h(u/e,i.y,o.y,n.y,s.y),h(u/e,i.z,o.z,n.z,s.z)));return new t(a)},t.CreateHermiteSpline=function(i,o,n,s,e){for(var a=new Array,h=1/e,u=0;e>=u;u++)a.push(r.Hermite(i,o,n,s,u*h));return new t(a)},t.prototype.getPoints=function(){return this._points},t.prototype.length=function(){return this._length},t.prototype["continue"]=function(i){for(var o=this._points[this._points.length-1],n=this._points.slice(),r=i.getPoints(),s=1;s<r.length;s++)n.push(r[s].subtract(r[0]).add(o));var e=new t(n);return e},t.prototype._computeLength=function(t){for(var i=0,o=1;o<t.length;o++)i+=t[o].subtract(t[o-1]).length();return i},t}();t.Curve3=d;var I=function(){function t(t,i){void 0===t&&(t=r.Zero()),void 0===i&&(i=r.Up()),this.position=t,this.normal=i}return t.prototype.clone=function(){return new t(this.position.clone(),this.normal.clone())},t}();t.PositionNormalVertex=I;var D=function(){function t(t,i,o){void 0===t&&(t=r.Zero()),void 0===i&&(i=r.Up()),void 0===o&&(o=n.Zero()),this.position=t,this.normal=i,this.uv=o}return t.prototype.clone=function(){return new t(this.position.clone(),this.normal.clone(),this.uv.clone())},t}();t.PositionNormalTextureVertex=D;var S=a.prototype.multiplyToArray,v=a.prototype.invertToRef,g=a.LookAtLHToRef,T=r.TransformCoordinatesToRef,R=r.TransformCoordinatesFromFloatsToRef,_=function(){function t(){}return Object.defineProperty(t,"IsEnabled",{get:function(){return t._isEnabled},enumerable:!0,configurable:!0}),t.DisableSIMD=function(){a.prototype.multiplyToArray=S,a.prototype.invertToRef=v,a.LookAtLHToRef=g,r.TransformCoordinatesToRef=T,r.TransformCoordinatesFromFloatsToRef=R,t._isEnabled=!1},t.EnableSIMD=function(){void 0!==window.SIMD&&(a.prototype.multiplyToArray=a.prototype.multiplyToArraySIMD,a.prototype.invertToRef=a.prototype.invertToRefSIMD,a.LookAtLHToRef=a.LookAtLHToRefSIMD,r.TransformCoordinatesToRef=r.TransformCoordinatesToRefSIMD,r.TransformCoordinatesFromFloatsToRef=r.TransformCoordinatesFromFloatsToRefSIMD,Object.defineProperty(r.prototype,"x",{get:function(){return this._data[0]},set:function(t){this._data||(this._data=new Float32Array(3)),this._data[0]=t}}),Object.defineProperty(r.prototype,"y",{get:function(){return this._data[1]},set:function(t){this._data[1]=t}}),Object.defineProperty(r.prototype,"z",{get:function(){return this._data[2]},set:function(t){this._data[2]=t}}),t._isEnabled=!0)},t._isEnabled=!1,t}();t.SIMDHelper=_}(BABYLON||(BABYLON={}));',
  ("undefined"!=typeof window&&window.module||"undefined"!=typeof module)&&"undefined"!=typeof module.exports&&(module.exports=BABYLON);
  