1234567891011121314151617181920212223242526 |
- var BABYLON;!function(t){var e=function(){function t(t,e,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.r=t,this.g=e,this.b=i}return t.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},t.prototype.toArray=function(t,e){return void 0===e&&(e=0),t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,this},t.prototype.toColor4=function(t){return void 0===t&&(t=1),new i(this.r,this.g,this.b,t)},t.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},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(t,e){return e.r=this.r*t.r,e.g=this.g*t.g,e.b=this.b*t.b,this},t.prototype.equals=function(t){return t&&this.r===t.r&&this.g===t.g&&this.b===t.b},t.prototype.scale=function(e){return new t(this.r*e,this.g*e,this.b*e)},t.prototype.scaleToRef=function(t,e){return e.r=this.r*t,e.g=this.g*t,e.b=this.b*t,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(t,e){return e.r=this.r+t.r,e.g=this.g+t.g,e.b=this.b+t.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(t,e){return e.r=this.r-t.r,e.g=this.g-t.g,e.b=this.b-t.b,this},t.prototype.clone=function(){return new t(this.r,this.g,this.b)},t.prototype.copyFrom=function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this},t.prototype.copyFromFloats=function(t,e,i){return this.r=t,this.g=e,this.b=i,this},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}();t.Color3=e;var i=function(){function t(t,e,i,r){this.r=t,this.g=e,this.b=i,this.a=r}return t.prototype.addInPlace=function(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this.a+=t.a,this},t.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},t.prototype.toArray=function(t,e){return void 0===e&&(e=0),t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t[e+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(t,e){return e.r=this.r-t.r,e.g=this.g-t.g,e.b=this.b-t.b,e.a=this.a-t.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(t,e){return e.r=this.r*t,e.g=this.g*t,e.b=this.b*t,e.a=this.a*t,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(t){return this.r=t.r,this.g=t.g,this.b=t.b,this.a=t.a,this},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(t,e,i,r){r.r=t.r+(e.r-t.r)*i,r.g=t.g+(e.g-t.g)*i,r.b=t.b+(e.b-t.b)*i,r.a=t.a+(e.a-t.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}();t.Color4=i;var r=function(){function t(t,e){this.x=t,this.y=e}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},t.prototype.toArray=function(t,e){return void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,this},t.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},t.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this},t.prototype.copyFromFloats=function(t,e){return this.x=t,this.y=e,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(t){return this.x-=t.x,this.y-=t.y,this},t.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this},t.prototype.multiply=function(e){return new t(this.x*e.x,this.y*e.y)},t.prototype.multiplyToRef=function(t,e){return e.x=this.x*t.x,e.y=this.y*t.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(t,e){return e.x=this.x/t.x,e.y=this.y/t.y,this},t.prototype.negate=function(){return new t(-this.x,-this.y)},t.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this},t.prototype.scale=function(e){return new t(this.x*e,this.y*e)},t.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y},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 t=this.length();if(0===t)return this;var e=1/t;return this.x*=e,this.y*=e,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(t,e,i){i.x=t[e],i.y=t[e+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),c=.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,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;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,c=-2*a+3*s,l=a-2*s+o,u=a-s,f=e.x*h+r.x*c+i.x*l+n.x*u,d=e.y*h+r.y*c+i.y*l+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(t,e){return t.x*e.x+t.y*e.y},t.Normalize=function(t){var e=t.clone();return e.normalize(),e},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(t,e){var i=t.x-e.x,r=t.y-e.y;return i*i+r*r},t}();t.Vector2=r;var n=function(){function e(t,e,i){this.x=t,this.y=e,this.z=i}return e.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},e.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},e.prototype.toArray=function(t,e){return void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,this},e.prototype.toQuaternion=function(){var t=new s(0,0,0,1),e=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 t.x=r*a,t.y=-n*a,t.z=i*o,t.w=e*o,t},e.prototype.addInPlace=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y,this.z+t.z)},e.prototype.addToRef=function(t,e){return e.x=this.x+t.x,e.y=this.y+t.y,e.z=this.z+t.z,this},e.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},e.prototype.subtract=function(t){return new e(this.x-t.x,this.y-t.y,this.z-t.z)},e.prototype.subtractToRef=function(t,e){return e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z,this},e.prototype.subtractFromFloats=function(t,i,r){return new e(this.x-t,this.y-i,this.z-r)},e.prototype.subtractFromFloatsToRef=function(t,e,i,r){return r.x=this.x-t,r.y=this.y-e,r.z=this.z-i,this},e.prototype.negate=function(){return new e(-this.x,-this.y,-this.z)},e.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this.z*=t,this},e.prototype.scale=function(t){return new e(this.x*t,this.y*t,this.z*t)},e.prototype.scaleToRef=function(t,e){e.x=this.x*t,e.y=this.y*t,e.z=this.z*t},e.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z},e.prototype.equalsWithEpsilon=function(e){return Math.abs(this.x-e.x)<t.Engine.Epsilon&&Math.abs(this.y-e.y)<t.Engine.Epsilon&&Math.abs(this.z-e.z)<t.Engine.Epsilon},e.prototype.equalsToFloats=function(t,e,i){return this.x===t&&this.y===e&&this.z===i},e.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},e.prototype.multiply=function(t){return new e(this.x*t.x,this.y*t.y,this.z*t.z)},e.prototype.multiplyToRef=function(t,e){return e.x=this.x*t.x,e.y=this.y*t.y,e.z=this.z*t.z,this},e.prototype.multiplyByFloats=function(t,i,r){return new e(this.x*t,this.y*i,this.z*r)},e.prototype.divide=function(t){return new e(this.x/t.x,this.y/t.y,this.z/t.z)},e.prototype.divideToRef=function(t,e){return e.x=this.x/t.x,e.y=this.y/t.y,e.z=this.z/t.z,this},e.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},e.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},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},e.prototype.normalize=function(){var t=this.length();if(0===t)return this;var e=1/t;return this.x*=e,this.y*=e,this.z*=e,this},e.prototype.clone=function(){return new e(this.x,this.y,this.z)},e.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},e.prototype.copyFromFloats=function(t,e,i){return this.x=t,this.y=e,this.z=i,this},e.GetClipFactor=function(t,i,r,n){var o=e.Dot(t,r)-n,s=e.Dot(i,r)-n,a=o/(o-s);return a},e.FromArray=function(t,i){return i||(i=0),new e(t[i],t[i+1],t[i+2])},e.FromArrayToRef=function(t,e,i){i.x=t[e],i.y=t[e+1],i.z=t[e+2]},e.FromFloatArrayToRef=function(t,e,i){i.x=t[e],i.y=t[e+1],i.z=t[e+2]},e.FromFloatsToRef=function(t,e,i,r){r.x=t,r.y=e,r.z=i},e.Zero=function(){return new e(0,0,0)},e.Up=function(){return new e(0,1,0)},e.TransformCoordinates=function(t,i){var r=e.Zero();return e.TransformCoordinatesToRef(t,i,r),r},e.TransformCoordinatesToRef=function(t,e,i){var r=t.x*e.m[0]+t.y*e.m[4]+t.z*e.m[8]+e.m[12],n=t.x*e.m[1]+t.y*e.m[5]+t.z*e.m[9]+e.m[13],o=t.x*e.m[2]+t.y*e.m[6]+t.z*e.m[10]+e.m[14],s=t.x*e.m[3]+t.y*e.m[7]+t.z*e.m[11]+e.m[15];i.x=r/s,i.y=n/s,i.z=o/s},e.TransformCoordinatesFromFloatsToRef=function(t,e,i,r,n){var o=t*r.m[0]+e*r.m[4]+i*r.m[8]+r.m[12],s=t*r.m[1]+e*r.m[5]+i*r.m[9]+r.m[13],a=t*r.m[2]+e*r.m[6]+i*r.m[10]+r.m[14],h=t*r.m[3]+e*r.m[7]+i*r.m[11]+r.m[15];n.x=o/h,n.y=s/h,n.z=a/h},e.TransformCoordinatesToRefSIMD=function(t,e,i){var r=SIMD.float32x4.loadXYZ(t._data,0),n=SIMD.float32x4.load(e.m,0),o=SIMD.float32x4.load(e.m,4),s=SIMD.float32x4.load(e.m,8),a=SIMD.float32x4.load(e.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)},e.TransformCoordinatesFromFloatsToRefSIMD=function(t,e,i,r,n){var o=SIMD.float32x4.splat(t),s=SIMD.float32x4.splat(e),a=SIMD.float32x4.splat(i),h=SIMD.float32x4.load(r.m,0),c=SIMD.float32x4.load(r.m,4),l=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,c)),SIMD.float32x4.add(SIMD.float32x4.mul(a,l),u));f=SIMD.float32x4.div(f,SIMD.float32x4.swizzle(f,3,3,3,3)),SIMD.float32x4.storeXYZ(n._data,0,f)},e.TransformNormal=function(t,i){var r=e.Zero();return e.TransformNormalToRef(t,i,r),r},e.TransformNormalToRef=function(t,e,i){i.x=t.x*e.m[0]+t.y*e.m[4]+t.z*e.m[8],i.y=t.x*e.m[1]+t.y*e.m[5]+t.z*e.m[9],i.z=t.x*e.m[2]+t.y*e.m[6]+t.z*e.m[10]},e.TransformNormalFromFloatsToRef=function(t,e,i,r,n){n.x=t*r.m[0]+e*r.m[4]+i*r.m[8],n.y=t*r.m[1]+e*r.m[5]+i*r.m[9],n.z=t*r.m[2]+e*r.m[6]+i*r.m[10]},e.CatmullRom=function(t,i,r,n,o){var s=o*o,a=o*s,h=.5*(2*i.x+(-t.x+r.x)*o+(2*t.x-5*i.x+4*r.x-n.x)*s+(-t.x+3*i.x-3*r.x+n.x)*a),c=.5*(2*i.y+(-t.y+r.y)*o+(2*t.y-5*i.y+4*r.y-n.y)*s+(-t.y+3*i.y-3*r.y+n.y)*a),l=.5*(2*i.z+(-t.z+r.z)*o+(2*t.z-5*i.z+4*r.z-n.z)*s+(-t.z+3*i.z-3*r.z+n.z)*a);return new e(h,c,l)},e.Clamp=function(t,i,r){var n=t.x;n=n>r.x?r.x:n,n=n<i.x?i.x:n;var o=t.y;o=o>r.y?r.y:o,o=o<i.y?i.y:o;var s=t.z;return s=s>r.z?r.z:s,s=s<i.z?i.z:s,new e(n,o,s)},e.Hermite=function(t,i,r,n,o){var s=o*o,a=o*s,h=2*a-3*s+1,c=-2*a+3*s,l=a-2*s+o,u=a-s,f=t.x*h+r.x*c+i.x*l+n.x*u,d=t.y*h+r.y*c+i.y*l+n.y*u,p=t.z*h+r.z*c+i.z*l+n.z*u;return new e(f,d,p)},e.Lerp=function(t,i,r){var n=t.x+(i.x-t.x)*r,o=t.y+(i.y-t.y)*r,s=t.z+(i.z-t.z)*r;return new e(n,o,s)},e.Dot=function(t,e){return t.x*e.x+t.y*e.y+t.z*e.z},e.Cross=function(t,i){var r=e.Zero();return e.CrossToRef(t,i,r),r},e.CrossToRef=function(t,e,i){i.x=t.y*e.z-t.z*e.y,i.y=t.z*e.x-t.x*e.z,i.z=t.x*e.y-t.y*e.x},e.Normalize=function(t){var i=e.Zero();return e.NormalizeToRef(t,i),i},e.NormalizeToRef=function(t,e){e.copyFrom(t),e.normalize()},e.Project=function(t,i,r,n){var o=n.width,s=n.height,h=n.x,c=n.y,l=a.FromValues(o/2,0,0,0,0,-s/2,0,0,0,0,1,0,h+o/2,s/2+c,0,1),u=i.multiply(r).multiply(l);return e.TransformCoordinates(t,u)},e.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=e.TransformCoordinates(i,a),c=i.x*a.m[3]+i.y*a.m[7]+i.z*a.m[11]+a.m[15];return t.Tools.WithinEpsilon(c,1)&&(h=h.scale(1/c)),h},e.Unproject=function(i,r,n,o,s,a){var h=o.multiply(s).multiply(a);h.invert(),i.x=i.x/r*2-1,i.y=-(i.y/n*2-1);var c=e.TransformCoordinates(i,h),l=i.x*h.m[3]+i.y*h.m[7]+i.z*h.m[11]+h.m[15];return t.Tools.WithinEpsilon(l,1)&&(c=c.scale(1/l)),c},e.Minimize=function(t,e){var i=t.clone();return i.MinimizeInPlace(e),i},e.Maximize=function(t,e){var i=t.clone();return i.MaximizeInPlace(e),i},e.Distance=function(t,i){return Math.sqrt(e.DistanceSquared(t,i))},e.DistanceSquared=function(t,e){var i=t.x-e.x,r=t.y-e.y,n=t.z-e.z;return i*i+r*r+n*n},e.Center=function(t,e){var i=t.add(e);return i.scaleInPlace(.5),i},e}();t.Vector3=n;var o=function(){function e(t,e,i,r){this.x=t,this.y=e,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(){var t=[];return this.toArray(t,0),t},e.prototype.toArray=function(t,e){return void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,this},e.prototype.addInPlace=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,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.addToRef=function(t,e){return e.x=this.x+t.x,e.y=this.y+t.y,e.z=this.z+t.z,e.w=this.w+t.w,this},e.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this},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.subtractToRef=function(t,e){return e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z,e.w=this.w-t.w,this},e.prototype.subtractFromFloats=function(t,i,r,n){return new e(this.x-t,this.y-i,this.z-r,this.w-n)},e.prototype.subtractFromFloatsToRef=function(t,e,i,r,n){return n.x=this.x-t,n.y=this.y-e,n.z=this.z-i,n.w=this.w-r,this},e.prototype.negate=function(){return new e(-this.x,-this.y,-this.z,-this.w)},e.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},e.prototype.scale=function(t){return new e(this.x*t,this.y*t,this.z*t,this.w*t)},e.prototype.scaleToRef=function(t,e){e.x=this.x*t,e.y=this.y*t,e.z=this.z*t,e.w=this.w*t},e.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w},e.prototype.equalsWithEpsilon=function(e){return Math.abs(this.x-e.x)<t.Engine.Epsilon&&Math.abs(this.y-e.y)<t.Engine.Epsilon&&Math.abs(this.z-e.z)<t.Engine.Epsilon&&Math.abs(this.w-e.w)<t.Engine.Epsilon},e.prototype.equalsToFloats=function(t,e,i,r){return this.x===t&&this.y===e&&this.z===i&&this.w===r},e.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this},e.prototype.multiply=function(t){return new e(this.x*t.x,this.y*t.y,this.z*t.z,this.w*t.w)},e.prototype.multiplyToRef=function(t,e){return e.x=this.x*t.x,e.y=this.y*t.y,e.z=this.z*t.z,e.w=this.w*t.w,this},e.prototype.multiplyByFloats=function(t,i,r,n){return new e(this.x*t,this.y*i,this.z*r,this.w*n)},e.prototype.divide=function(t){return new e(this.x/t.x,this.y/t.y,this.z/t.z,this.w/t.w)},e.prototype.divideToRef=function(t,e){return e.x=this.x/t.x,e.y=this.y/t.y,e.z=this.z/t.z,e.w=this.w/t.w,this},e.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},e.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},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.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},e.prototype.normalize=function(){var t=this.length();if(0===t)return this;var e=1/t;return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},e.prototype.clone=function(){return new e(this.x,this.y,this.z,this.w)},e.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},e.prototype.copyFromFloats=function(t,e,i,r){return this.x=t,this.y=e,this.z=i,this.w=r,this},e.FromArray=function(t,i){return i||(i=0),new e(t[i],t[i+1],t[i+2],t[i+3])},e.FromArrayToRef=function(t,e,i){i.x=t[e],i.y=t[e+1],i.z=t[e+2],i.w=t[e+3]},e.FromFloatArrayToRef=function(t,e,i){i.x=t[e],i.y=t[e+1],i.z=t[e+2],i.w=t[e+3]},e.FromFloatsToRef=function(t,e,i,r,n){n.x=t,n.y=e,n.z=i,n.w=r},e.Zero=function(){return new e(0,0,0,0)},e.Normalize=function(t){var i=e.Zero();return e.NormalizeToRef(t,i),i},e.NormalizeToRef=function(t,e){e.copyFrom(t),e.normalize()},e.Minimize=function(t,e){var i=t.clone();return i.MinimizeInPlace(e),i},e.Maximize=function(t,e){var i=t.clone();return i.MaximizeInPlace(e),i},e.Distance=function(t,i){return Math.sqrt(e.DistanceSquared(t,i))},e.DistanceSquared=function(t,e){var i=t.x-e.x,r=t.y-e.y,n=t.z-e.z,o=t.w-e.w;return i*i+r*r+n*n+o*o},e.Center=function(t,e){var i=t.add(e);return i.scaleInPlace(.5),i},e}();t.Vector4=o;var s=function(){function t(t,e,i,r){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1),this.x=t,this.y=e,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(){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,e,i,r){return this.x=t,this.y=e,this.z=i,this.w=r,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.subtract=function(e){return new t(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},t.prototype.scale=function(e){return new t(this.x*e,this.y*e,this.z*e,this.w*e)},t.prototype.multiply=function(e){var i=new t(0,0,0,1);return this.multiplyToRef(e,i),i},t.prototype.multiplyToRef=function(t,e){return e.x=this.x*t.w+this.y*t.z-this.z*t.y+this.w*t.x,e.y=-this.x*t.z+this.y*t.w+this.z*t.x+this.w*t.y,e.z=this.x*t.y-this.y*t.x+this.z*t.w+this.w*t.z,e.w=-this.x*t.x-this.y*t.y-this.z*t.z+this.w*t.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.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=n.Zero();return this.toEulerAnglesToRef(t),t},t.prototype.toEulerAnglesToRef=function(t){var e=this.x,i=this.y,r=this.z,n=this.w,o=e*i,s=e*r,a=n*i,h=n*r,c=n*e,l=i*r,u=e*e,f=i*i,d=u+f;return 0!==d&&1!==d?(t.x=Math.atan2(s+a,c-l),t.y=Math.acos(1-2*d),t.z=Math.atan2(s-a,c+l)):0===d?(t.x=0,t.y=0,t.z=Math.atan2(o-h,.5-f-r*r)):(t.x=Math.atan2(o-h,.5-f-r*r),t.y=Math.PI,t.z=0),this},t.prototype.toRotationMatrix=function(t){var e=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,c=this.x*this.w;return t.m[0]=1-2*(i+r),t.m[1]=2*(n+o),t.m[2]=2*(s-a),t.m[3]=0,t.m[4]=2*(n-o),t.m[5]=1-2*(r+e),t.m[6]=2*(h+c),t.m[7]=0,t.m[8]=2*(s+a),t.m[9]=2*(h-c),t.m[10]=1-2*(i+e),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(e){return t.FromRotationMatrixToRef(e,this),this},t.FromRotationMatrix=function(e){var i=new t;return t.FromRotationMatrixToRef(e,i),i},t.FromRotationMatrixToRef=function(t,e){var i,r=t.m,n=r[0],o=r[4],s=r[8],a=r[1],h=r[5],c=r[9],l=r[2],u=r[6],f=r[10],d=n+h+f;d>0?(i=.5/Math.sqrt(d+1),e.w=.25/i,e.x=(u-c)*i,e.y=(s-l)*i,e.z=(a-o)*i):n>h&&n>f?(i=2*Math.sqrt(1+n-h-f),e.w=(u-c)/i,e.x=.25*i,e.y=(o+a)/i,e.z=(s+l)/i):h>f?(i=2*Math.sqrt(1+h-n-f),e.w=(s-l)/i,e.x=(o+a)/i,e.y=.25*i,e.z=(c+u)/i):(i=2*Math.sqrt(1+f-n-h),e.w=(a-o)/i,e.x=(s+l)/i,e.y=(c+u)/i,e.z=.25*i)},t.Inverse=function(e){return new t(-e.x,-e.y,-e.z,e.w)},t.Identity=function(){return new t(0,0,0,1)},t.RotationAxis=function(e,i){var r=new t,n=Math.sin(i/2);return r.w=Math.cos(i/2),r.x=e.x*n,r.y=e.y*n,r.z=e.z*n,r},t.FromArray=function(e,i){return i||(i=0),new t(e[i],e[i+1],e[i+2],e[i+3])},t.RotationYawPitchRoll=function(e,i,r){var n=new t;return t.RotationYawPitchRollToRef(e,i,r,n),n},t.RotationYawPitchRollToRef=function(t,e,i,r){var n=.5*i,o=.5*e,s=.5*t,a=Math.sin(n),h=Math.cos(n),c=Math.sin(o),l=Math.cos(o),u=Math.sin(s),f=Math.cos(s);r.x=f*c*h+u*l*a,r.y=u*l*h-f*c*a,r.z=f*l*a-u*c*h,r.w=f*l*h+u*c*a},t.RotationAlphaBetaGamma=function(e,i,r){var n=new t;return t.RotationAlphaBetaGammaToRef(e,i,r,n),n},t.RotationAlphaBetaGammaToRef=function(t,e,i,r){var n=.5*(i+t),o=.5*(i-t),s=.5*e;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)},t.Slerp=function(e,i,r){var n,o,s=r,a=e.x*i.x+e.y*i.y+e.z*i.z+e.w*i.w,h=!1;if(0>a&&(h=!0,a=-a),a>.999999)o=1-s,n=h?-s:s;else{var c=Math.acos(a),l=1/Math.sin(c);o=Math.sin((1-s)*c)*l,n=h?-Math.sin(s*c)*l:Math.sin(s*c)*l}return new t(o*e.x+n*i.x,o*e.y+n*i.y,o*e.z+n*i.z,o*e.w+n*i.w)},t}();t.Quaternion=s;var a=function(){function e(){this.m=new Float32Array(16)}return e.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},e.prototype.determinant=function(){var t=this.m[10]*this.m[15]-this.m[11]*this.m[14],e=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]*t-this.m[6]*e+this.m[7]*i)-this.m[1]*(this.m[4]*t-this.m[6]*r+this.m[7]*n)+this.m[2]*(this.m[4]*e-this.m[5]*r+this.m[7]*o)-this.m[3]*(this.m[4]*i-this.m[5]*n+this.m[6]*o)},e.prototype.toArray=function(){return this.m},e.prototype.asArray=function(){return this.toArray()},e.prototype.invert=function(){return this.invertToRef(this),this},e.prototype.invertToRef=function(t){var e=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],c=this.m[8],l=this.m[9],u=this.m[10],f=this.m[11],d=this.m[12],p=this.m[13],m=this.m[14],_=this.m[15],g=u*_-f*m,v=l*_-f*p,y=l*m-u*p,x=c*_-f*d,b=c*m-u*d,M=c*p-l*d,T=s*g-a*v+h*y,S=-(o*g-a*x+h*b),A=o*v-s*x+h*M,w=-(o*y-s*b+a*M),D=1/(e*T+i*S+r*A+n*w),E=a*_-h*m,C=s*_-h*p,P=s*m-a*p,I=o*_-h*d,L=o*m-a*d,R=o*p-s*d,O=a*f-h*u,B=s*f-h*l,F=s*u-a*l,V=o*f-h*c,N=o*u-a*c,z=o*l-s*c;return t.m[0]=T*D,t.m[4]=S*D,t.m[8]=A*D,t.m[12]=w*D,t.m[1]=-(i*g-r*v+n*y)*D,t.m[5]=(e*g-r*x+n*b)*D,t.m[9]=-(e*v-i*x+n*M)*D,t.m[13]=(e*y-i*b+r*M)*D,t.m[2]=(i*E-r*C+n*P)*D,t.m[6]=-(e*E-r*I+n*L)*D,t.m[10]=(e*C-i*I+n*R)*D,t.m[14]=-(e*P-i*L+r*R)*D,t.m[3]=-(i*O-r*B+n*F)*D,t.m[7]=(e*O-r*V+n*N)*D,t.m[11]=-(e*B-i*V+n*z)*D,t.m[15]=(e*F-i*N+r*z)*D,this},e.prototype.invertToRefSIMD=function(t){var e,i,r,n,o,s,a,h,c,l,u=this.m,f=t.m,d=SIMD.float32x4.load(u,0),p=SIMD.float32x4.load(u,4),m=SIMD.float32x4.load(u,8),_=SIMD.float32x4.load(u,12);return o=SIMD.float32x4.shuffle(d,p,0,1,4,5),i=SIMD.float32x4.shuffle(m,_,0,1,4,5),e=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,_,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(e,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(e,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),c=SIMD.float32x4.mul(e,o),o=SIMD.float32x4.swizzle(o,2,3,0,1),s=SIMD.float32x4.sub(s,SIMD.float32x4.mul(n,o)),c=SIMD.float32x4.sub(SIMD.float32x4.mul(e,o),c),c=SIMD.float32x4.swizzle(c,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(e,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(e,o),h),h=SIMD.float32x4.swizzle(h,2,3,0,1),o=SIMD.float32x4.mul(e,i),o=SIMD.float32x4.swizzle(o,1,0,3,2),h=SIMD.float32x4.add(SIMD.float32x4.mul(n,o),h),c=SIMD.float32x4.sub(SIMD.float32x4.mul(r,o),c),o=SIMD.float32x4.swizzle(o,2,3,0,1),h=SIMD.float32x4.sub(SIMD.float32x4.mul(n,o),h),c=SIMD.float32x4.sub(c,SIMD.float32x4.mul(r,o)),o=SIMD.float32x4.mul(e,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(e,r),o=SIMD.float32x4.swizzle(o,1,0,3,2),a=SIMD.float32x4.add(SIMD.float32x4.mul(n,o),a),c=SIMD.float32x4.sub(c,SIMD.float32x4.mul(i,o)),o=SIMD.float32x4.swizzle(o,2,3,0,1),a=SIMD.float32x4.sub(a,SIMD.float32x4.mul(n,o)),c=SIMD.float32x4.add(SIMD.float32x4.mul(i,o),c),l=SIMD.float32x4.mul(e,s),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),o=SIMD.float32x4.reciprocalApproximation(l),l=SIMD.float32x4.sub(SIMD.float32x4.add(o,o),SIMD.float32x4.mul(l,SIMD.float32x4.mul(o,o))),l=SIMD.float32x4.swizzle(l,0,0,0,0),s=SIMD.float32x4.mul(l,s),a=SIMD.float32x4.mul(l,a),h=SIMD.float32x4.mul(l,h),c=SIMD.float32x4.mul(l,c),SIMD.float32x4.store(f,0,s),SIMD.float32x4.store(f,4,a),SIMD.float32x4.store(f,8,h),SIMD.float32x4.store(f,12,c),this},e.prototype.setTranslation=function(t){return this.m[12]=t.x,this.m[13]=t.y,this.m[14]=t.z,this},e.prototype.multiply=function(t){var i=new e;return this.multiplyToRef(t,i),i},e.prototype.copyFrom=function(t){for(var e=0;16>e;e++)this.m[e]=t.m[e];return this},e.prototype.copyToArray=function(t,e){void 0===e&&(e=0);for(var i=0;16>i;i++)t[e+i]=this.m[i];return this},e.prototype.multiplyToRef=function(t,e){return this.multiplyToArray(t,e.m,0),this},e.prototype.multiplyToArray=function(t,e,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],c=this.m[6],l=this.m[7],u=this.m[8],f=this.m[9],d=this.m[10],p=this.m[11],m=this.m[12],_=this.m[13],g=this.m[14],v=this.m[15],y=t.m[0],x=t.m[1],b=t.m[2],M=t.m[3],T=t.m[4],S=t.m[5],A=t.m[6],w=t.m[7],D=t.m[8],E=t.m[9],C=t.m[10],P=t.m[11],I=t.m[12],L=t.m[13],R=t.m[14],O=t.m[15];return e[i]=r*y+n*T+o*D+s*I,e[i+1]=r*x+n*S+o*E+s*L,e[i+2]=r*b+n*A+o*C+s*R,e[i+3]=r*M+n*w+o*P+s*O,e[i+4]=a*y+h*T+c*D+l*I,e[i+5]=a*x+h*S+c*E+l*L,e[i+6]=a*b+h*A+c*C+l*R,e[i+7]=a*M+h*w+c*P+l*O,e[i+8]=u*y+f*T+d*D+p*I,e[i+9]=u*x+f*S+d*E+p*L,e[i+10]=u*b+f*A+d*C+p*R,e[i+11]=u*M+f*w+d*P+p*O,e[i+12]=m*y+_*T+g*D+v*I,e[i+13]=m*x+_*S+g*E+v*L,e[i+14]=m*b+_*A+g*C+v*R,e[i+15]=m*M+_*w+g*P+v*O,this},e.prototype.multiplyToArraySIMD=function(t,e,i){void 0===i&&(i=0);var r=this.m,n=t.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),c=SIMD.float32x4.load(r,0);SIMD.float32x4.store(e,i+0,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 l=SIMD.float32x4.load(r,4);SIMD.float32x4.store(e,i+4,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 u=SIMD.float32x4.load(r,8);SIMD.float32x4.store(e,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(e,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)))))},e.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]},e.prototype.clone=function(){return e.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])},e.prototype.decompose=function(i,r,n){n.x=this.m[12],n.y=this.m[13],n.z=this.m[14];var o=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(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 c=e.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(c,r),!0},e.FromArray=function(t,i){var r=new e;return i||(i=0),e.FromArrayToRef(t,i,r),r},e.FromArrayToRef=function(t,e,i){for(var r=0;16>r;r++)i.m[r]=t[r+e]},e.FromValuesToRef=function(t,e,i,r,n,o,s,a,h,c,l,u,f,d,p,m,_){
- _.m[0]=t,_.m[1]=e,_.m[2]=i,_.m[3]=r,_.m[4]=n,_.m[5]=o,_.m[6]=s,_.m[7]=a,_.m[8]=h,_.m[9]=c,_.m[10]=l,_.m[11]=u,_.m[12]=f,_.m[13]=d,_.m[14]=p,_.m[15]=m},e.FromValues=function(t,i,r,n,o,s,a,h,c,l,u,f,d,p,m,_){var g=new e;return g.m[0]=t,g.m[1]=i,g.m[2]=r,g.m[3]=n,g.m[4]=o,g.m[5]=s,g.m[6]=a,g.m[7]=h,g.m[8]=c,g.m[9]=l,g.m[10]=u,g.m[11]=f,g.m[12]=d,g.m[13]=p,g.m[14]=m,g.m[15]=_,g},e.Compose=function(t,i,r){var n=e.FromValues(t.x,0,0,0,0,t.y,0,0,0,0,t.z,0,0,0,0,1),o=e.Identity();return i.toRotationMatrix(o),n=n.multiply(o),n.setTranslation(r),n},e.Identity=function(){return e.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},e.IdentityToRef=function(t){e.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,t)},e.Zero=function(){return e.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},e.RotationX=function(t){var i=new e;return e.RotationXToRef(t,i),i},e.Invert=function(t){var i=new e;return t.invertToRef(i),i},e.RotationXToRef=function(t,e){var i=Math.sin(t),r=Math.cos(t);e.m[0]=1,e.m[15]=1,e.m[5]=r,e.m[10]=r,e.m[9]=-i,e.m[6]=i,e.m[1]=0,e.m[2]=0,e.m[3]=0,e.m[4]=0,e.m[7]=0,e.m[8]=0,e.m[11]=0,e.m[12]=0,e.m[13]=0,e.m[14]=0},e.RotationY=function(t){var i=new e;return e.RotationYToRef(t,i),i},e.RotationYToRef=function(t,e){var i=Math.sin(t),r=Math.cos(t);e.m[5]=1,e.m[15]=1,e.m[0]=r,e.m[2]=-i,e.m[8]=i,e.m[10]=r,e.m[1]=0,e.m[3]=0,e.m[4]=0,e.m[6]=0,e.m[7]=0,e.m[9]=0,e.m[11]=0,e.m[12]=0,e.m[13]=0,e.m[14]=0},e.RotationZ=function(t){var i=new e;return e.RotationZToRef(t,i),i},e.RotationZToRef=function(t,e){var i=Math.sin(t),r=Math.cos(t);e.m[10]=1,e.m[15]=1,e.m[0]=r,e.m[1]=i,e.m[4]=-i,e.m[5]=r,e.m[2]=0,e.m[3]=0,e.m[6]=0,e.m[7]=0,e.m[8]=0,e.m[9]=0,e.m[11]=0,e.m[12]=0,e.m[13]=0,e.m[14]=0},e.RotationAxis=function(t,i){var r=Math.sin(-i),n=Math.cos(-i),o=1-n;t.normalize();var s=e.Zero();return s.m[0]=t.x*t.x*o+n,s.m[1]=t.x*t.y*o-t.z*r,s.m[2]=t.x*t.z*o+t.y*r,s.m[3]=0,s.m[4]=t.y*t.x*o+t.z*r,s.m[5]=t.y*t.y*o+n,s.m[6]=t.y*t.z*o-t.x*r,s.m[7]=0,s.m[8]=t.z*t.x*o-t.y*r,s.m[9]=t.z*t.y*o+t.x*r,s.m[10]=t.z*t.z*o+n,s.m[11]=0,s.m[15]=1,s},e.RotationYawPitchRoll=function(t,i,r){var n=new e;return e.RotationYawPitchRollToRef(t,i,r,n),n},e.RotationYawPitchRollToRef=function(t,e,i,r){s.RotationYawPitchRollToRef(t,e,i,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(r)},e.Scaling=function(t,i,r){var n=e.Zero();return e.ScalingToRef(t,i,r,n),n},e.ScalingToRef=function(t,e,i,r){r.m[0]=t,r.m[1]=0,r.m[2]=0,r.m[3]=0,r.m[4]=0,r.m[5]=e,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},e.Translation=function(t,i,r){var n=e.Identity();return e.TranslationToRef(t,i,r,n),n},e.TranslationToRef=function(t,i,r,n){e.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,t,i,r,1,n)},e.LookAtLH=function(t,i,r){var n=e.Zero();return e.LookAtLHToRef(t,i,r,n),n},e.LookAtLHToRef=function(t,i,r,o){i.subtractToRef(t,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,t),a=-n.Dot(this._yAxis,t),h=-n.Dot(this._zAxis,t);return e.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)},e.LookAtLHToRefSIMD=function(t,e,i,r){var n=r.m,o=SIMD.float32x4(e.x,e.y,e.z,0),s=SIMD.float32x4(t.x,t.y,t.z,0),a=SIMD.float32x4(i.x,i.y,i.z,0),h=SIMD.float32x4.sub(o,s),c=SIMD.float32x4.mul(h,h);c=SIMD.float32x4.add(c,SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(c,2,0,1,3))),h=SIMD.float32x4.mul(h,SIMD.float32x4.reciprocalSqrtApproximation(c)),c=SIMD.float32x4.mul(a,a),c=SIMD.float32x4.add(c,SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(c,2,0,1,3))),a=SIMD.float32x4.mul(a,SIMD.float32x4.reciprocalSqrtApproximation(c));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)));c=SIMD.float32x4.mul(l,l),c=SIMD.float32x4.add(c,SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(c,2,0,1,3))),l=SIMD.float32x4.mul(l,SIMD.float32x4.reciprocalSqrtApproximation(c));var u=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)));c=SIMD.float32x4.mul(l,l),c=SIMD.float32x4.add(c,SIMD.float32x4.add(SIMD.float32x4.swizzle(c,1,2,0,3),SIMD.float32x4.swizzle(c,2,0,1,3))),l=SIMD.float32x4.mul(l,SIMD.float32x4.reciprocalSqrtApproximation(c));var f=SIMD.float32x4.splat(0);l=SIMD.float32x4.neg(l);var d=SIMD.float32x4.shuffle(l,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),_=SIMD.float32x4.shuffle(d,p,1,3,5,7);d=SIMD.float32x4.shuffle(l,u,2,3,6,7),p=SIMD.float32x4.shuffle(h,f,2,3,6,7);var g=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),b=SIMD.float32x4(0,0,1,0),M=SIMD.float32x4.neg(s);M=SIMD.float32x4.withW(M,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),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(y,2,2,2,2),g),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),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(x,2,2,2,2),g),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(b,0,0,0,0),m),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(b,1,1,1,1),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(b,2,2,2,2),g),SIMD.float32x4.mul(SIMD.float32x4.swizzle(b,3,3,3,3),v))))),SIMD.float32x4.store(n,12,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),_),SIMD.float32x4.add(SIMD.float32x4.mul(SIMD.float32x4.swizzle(M,2,2,2,2),g),SIMD.float32x4.mul(SIMD.float32x4.swizzle(M,3,3,3,3),v)))))},e.OrthoLH=function(t,i,r,n){var o=e.Zero();return e.OrthoLHToRef(t,i,r,n,o),o},e.OrthoLHToRef=function(t,i,r,n,o){var s=2/t,a=2/i,h=1/(n-r),c=r/(r-n);e.FromValuesToRef(s,0,0,0,0,a,0,0,0,0,h,0,0,0,c,1,o)},e.OrthoOffCenterLH=function(t,i,r,n,o,s){var a=e.Zero();return e.OrthoOffCenterLHToRef(t,i,r,n,o,s,a),a},e.OrthoOffCenterLHToRef=function(t,e,i,r,n,o,s){s.m[0]=2/(e-t),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]=(t+e)/(t-e),s.m[13]=(r+i)/(i-r),s.m[14]=n/(n-o),s.m[15]=1},e.PerspectiveLH=function(t,i,r,n){var o=e.Zero();return o.m[0]=2*r/t,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},e.PerspectiveFovLH=function(t,i,r,n){var o=e.Zero();return e.PerspectiveFovLHToRef(t,i,r,n,o),o},e.PerspectiveFovLHToRef=function(e,i,r,n,o,s){void 0===s&&(s=t.Camera.FOVMODE_VERTICAL_FIXED);var a=1/Math.tan(.5*e),h=s===t.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)},e.GetFinalMatrix=function(t,i,r,n,o,s){var a=t.width,h=t.height,c=t.x,l=t.y,u=e.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,s-o,0,c+a/2,h/2+l,o,1);return i.multiply(r).multiply(n).multiply(u)},e.Transpose=function(t){var i=new e;return i.m[0]=t.m[0],i.m[1]=t.m[4],i.m[2]=t.m[8],i.m[3]=t.m[12],i.m[4]=t.m[1],i.m[5]=t.m[5],i.m[6]=t.m[9],i.m[7]=t.m[13],i.m[8]=t.m[2],i.m[9]=t.m[6],i.m[10]=t.m[10],i.m[11]=t.m[14],i.m[12]=t.m[3],i.m[13]=t.m[7],i.m[14]=t.m[11],i.m[15]=t.m[15],i},e.Reflection=function(t){var i=new e;return e.ReflectionToRef(t,i),i},e.ReflectionToRef=function(t,e){t.normalize();var i=t.normal.x,r=t.normal.y,n=t.normal.z,o=-2*i,s=-2*r,a=-2*n;e.m[0]=o*i+1,e.m[1]=s*i,e.m[2]=a*i,e.m[3]=0,e.m[4]=o*r,e.m[5]=s*r+1,e.m[6]=a*r,e.m[7]=0,e.m[8]=o*n,e.m[9]=s*n,e.m[10]=a*n+1,e.m[11]=0,e.m[12]=o*t.d,e.m[13]=s*t.d,e.m[14]=a*t.d,e.m[15]=1},e._tempQuaternion=new s,e._xAxis=n.Zero(),e._yAxis=n.Zero(),e._zAxis=n.Zero(),e}();t.Matrix=a;var h=function(){function t(t,e,i,r){this.normal=new n(t,e,i),this.d=r}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),e=0;return 0!==t&&(e=1/t),this.normal.x*=e,this.normal.y*=e,this.normal.z*=e,this.d*=e,this},t.prototype.transform=function(e){var i=a.Transpose(e),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],c=r*i.m[4]+n*i.m[5]+o*i.m[6]+s*i.m[7],l=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 t(h,c,l,u)},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,e,i){var r,n=e.x-t.x,o=e.y-t.y,s=e.z-t.z,a=i.x-t.x,h=i.y-t.y,c=i.z-t.z,l=o*c-s*h,u=s*a-n*c,f=n*h-o*a,d=Math.sqrt(l*l+u*u+f*f);return r=0!==d?1/d:0,this.normal.x=l*r,this.normal.y=u*r,this.normal.z=f*r,this.d=-(this.normal.x*t.x+this.normal.y*t.y+this.normal.z*t.z),this},t.prototype.isFrontFacingTo=function(t,e){var i=n.Dot(this.normal,t);return e>=i},t.prototype.signedDistanceTo=function(t){return n.Dot(t,this.normal)+this.d},t.FromArray=function(e){return new t(e[0],e[1],e[2],e[3])},t.FromPoints=function(e,i,r){var n=new t(0,0,0,0);return n.copyFromPoints(e,i,r),n},t.FromPositionAndNormal=function(e,i){var r=new t(0,0,0,0);return i.normalize(),r.normal=i,r.d=-(i.x*e.x+i.y*e.y+i.z*e.z),r},t.SignedDistanceToPlaneFromPositionAndNormal=function(t,e,i){var r=-(e.x*t.x+e.y*t.y+e.z*t.z);return n.Dot(i,e)+r},t}();t.Plane=h;var c=function(){function t(t,e,i,r){this.x=t,this.y=e,this.width=i,this.height=r}return t.prototype.toGlobal=function(e){var i=e.getRenderWidth(),r=e.getRenderHeight();return new t(this.x*i,this.y*r,this.width*i,this.height*r)},t}();t.Viewport=c;var l=function(){function t(){}return t.GetPlanes=function(e){for(var i=[],r=0;6>r;r++)i.push(new h(0,0,0,0));return t.GetPlanesToRef(e,i),i},t.GetPlanesToRef=function(t,e){e[0].normal.x=t.m[3]+t.m[2],e[0].normal.y=t.m[7]+t.m[6],e[0].normal.z=t.m[10]+t.m[10],e[0].d=t.m[15]+t.m[14],e[0].normalize(),e[1].normal.x=t.m[3]-t.m[2],e[1].normal.y=t.m[7]-t.m[6],e[1].normal.z=t.m[11]-t.m[10],e[1].d=t.m[15]-t.m[14],e[1].normalize(),e[2].normal.x=t.m[3]+t.m[0],e[2].normal.y=t.m[7]+t.m[4],e[2].normal.z=t.m[11]+t.m[8],e[2].d=t.m[15]+t.m[12],e[2].normalize(),e[3].normal.x=t.m[3]-t.m[0],e[3].normal.y=t.m[7]-t.m[4],e[3].normal.z=t.m[11]-t.m[8],e[3].d=t.m[15]-t.m[12],e[3].normalize(),e[4].normal.x=t.m[3]-t.m[1],e[4].normal.y=t.m[7]-t.m[5],e[4].normal.z=t.m[11]-t.m[9],e[4].d=t.m[15]-t.m[13],e[4].normalize(),e[5].normal.x=t.m[3]+t.m[1],e[5].normal.y=t.m[7]+t.m[5],e[5].normal.z=t.m[11]+t.m[9],e[5].d=t.m[15]+t.m[13],e[5].normalize()},t}();t.Frustum=l;var u=function(){function e(t,e,i){void 0===i&&(i=Number.MAX_VALUE),this.origin=t,this.direction=e,this.length=i}return e.prototype.intersectsBoxMinMax=function(t,e){var i=0,r=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.x<t.x||this.origin.x>e.x)return!1}else{var n=1/this.direction.x,o=(t.x-this.origin.x)*n,s=(e.x-this.origin.x)*n;if(s===-(1/0)&&(s=1/0),o>s){var a=o;o=s,s=a}if(i=Math.max(o,i),r=Math.min(s,r),i>r)return!1}if(Math.abs(this.direction.y)<1e-7){if(this.origin.y<t.y||this.origin.y>e.y)return!1}else if(n=1/this.direction.y,o=(t.y-this.origin.y)*n,s=(e.y-this.origin.y)*n,s===-(1/0)&&(s=1/0),o>s&&(a=o,o=s,s=a),i=Math.max(o,i),r=Math.min(s,r),i>r)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.z<t.z||this.origin.z>e.z)return!1}else if(n=1/this.direction.z,o=(t.z-this.origin.z)*n,s=(e.z-this.origin.z)*n,s===-(1/0)&&(s=1/0),o>s&&(a=o,o=s,s=a),i=Math.max(o,i),r=Math.min(s,r),i>r)return!1;return!0},e.prototype.intersectsBox=function(t){return this.intersectsBoxMinMax(t.minimum,t.maximum)},e.prototype.intersectsSphere=function(t){var e=t.center.x-this.origin.x,i=t.center.y-this.origin.y,r=t.center.z-this.origin.z,n=e*e+i*i+r*r,o=t.radius*t.radius;if(o>=n)return!0;var s=e*this.direction.x+i*this.direction.y+r*this.direction.z;if(0>s)return!1;var a=n-s*s;return o>=a},e.prototype.intersectsTriangle=function(e,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(e,this._edge1),r.subtractToRef(e,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(e,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 c=n.Dot(this._edge2,this._qvec)*s;return c>this.length?null:new t.IntersectionInfo(a,h,c)},e.CreateNew=function(t,i,r,o,s,a,h){var c=n.Unproject(new n(t,i,0),r,o,s,a,h),l=n.Unproject(new n(t,i,1),r,o,s,a,h),u=l.subtract(c);return u.normalize(),new e(c,u)},e.CreateNewFromTo=function(t,i,r){void 0===r&&(r=a.Identity());var n=i.subtract(t),o=Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z);return n.normalize(),e.Transform(new e(t,n,o),r)},e.Transform=function(t,i){var r=n.TransformCoordinates(t.origin,i),o=n.TransformNormal(t.direction,i);return new e(r,o,t.length)},e}();t.Ray=u,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 n(1,0,0),t.Y=new n(0,1,0),t.Z=new n(0,0,1),t}());t.Axis=f;var d=function(){function t(){}return t.interpolate=function(t,e,i,r,n){for(var o=1-3*r+3*e,s=3*r-6*e,a=3*e,h=t,c=0;5>c;c++){var l=h*h,u=l*h,f=o*u+s*l+a*h,d=1/(3*o*l+2*s*h+a);h-=(f-t)*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)},t}();t.BezierCurve=d,function(t){t[t.CW=0]="CW",t[t.CCW=1]="CCW"}(t.Orientation||(t.Orientation={}));var p=(t.Orientation,function(){function t(t){var e=this;this.degrees=function(){return 180*e._radians/Math.PI},this.radians=function(){return e._radians},this._radians=t,this._radians<0&&(this._radians+=2*Math.PI)}return t.BetweenTwoPoints=function(e,i){var r=i.subtract(e),n=Math.atan2(r.y,r.x);return new t(n)},t.FromRadians=function(e){return new t(e)},t.FromDegrees=function(e){return new t(e*Math.PI/180)},t}());t.Angle=p;var m=function(){function t(t,e,i){this.startPoint=t,this.midPoint=e,this.endPoint=i;var n=Math.pow(e.x,2)+Math.pow(e.y,2),o=(Math.pow(t.x,2)+Math.pow(t.y,2)-n)/2,s=(n-Math.pow(i.x,2)-Math.pow(i.y,2))/2,a=(t.x-e.x)*(e.y-i.y)-(e.x-i.x)*(t.y-e.y);this.centerPoint=new r((o*(e.y-i.y)-s*(t.y-e.y))/a,((t.x-e.x)*s-(e.x-i.x)*o)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=p.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),c=p.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),l=p.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();c-h>180&&(c-=360),-180>c-h&&(c+=360),l-c>180&&(l-=360),-180>l-c&&(l+=360),this.orientation=0>c-h?0:1,this.angle=p.FromDegrees(0===this.orientation?h-l:l-h)}return t}();t.Arc2=m;var _=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 n(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(e){return e(t)}),this},t.prototype.onchange=function(t){return this._onchange.push(t),this},t}();t.PathCursor=_;var g=function(){function e(t,e){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new r(t,e))}return e.prototype.addLineTo=function(e,i){if(closed)return t.Tools.Error("cannot add lines to closed paths"),this;var n=new r(e,i),o=this._points[this._points.length-1];return this._points.push(n),this._length+=n.subtract(o).length(),this},e.prototype.addArcTo=function(e,i,n,o,s){if(void 0===s&&(s=36),closed)return t.Tools.Error("cannot add arcs to closed paths"),this;var a=this._points[this._points.length-1],h=new r(e,i),c=new r(n,o),l=new m(a,h,c),u=l.angle.radians()/s;0===l.orientation&&(u*=-1);for(var f=l.startAngle.radians()+u,d=0;s>d;d++){var p=Math.cos(f)*l.radius+l.centerPoint.x,_=Math.sin(f)*l.radius+l.centerPoint.y;this.addLineTo(p,_),f+=u}return this},e.prototype.close=function(){return this.closed=!0,this},e.prototype.length=function(){var t=this._length;if(!this.closed){var e=this._points[this._points.length-1],i=this._points[0];t+=i.subtract(e).length()}return t},e.prototype.getPoints=function(){return this._points},e.prototype.getPointAtLengthPosition=function(e){if(0>e||e>1)return t.Tools.Error("normalized length position should be between 0 and 1."),r.Zero();for(var i=e*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],c=h.subtract(a),l=c.length()+n;if(i>=n&&l>=i){var u=c.normalize(),f=i-n;return new r(a.x+u.x*f,a.y+u.y*f)}n=l}return t.Tools.Error("internal error"),r.Zero()},e.StartingAt=function(t,i){return new e(t,i)},e}();t.Path2=g;var v=function(){function t(t,e){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 i=0;i<t.length;i++)this._curve[i]=t[i].clone();this._compute(e)}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(t,e){for(var i=0;i<t.length;i++)this._curve[i].x=t[i].x,this._curve[i].y=t[i].y,this._curve[i].z=t[i].z;return this._compute(e),this},t.prototype._compute=function(t){var e=this._curve.length;this._tangents[0]=this._getFirstNonNullVector(0),this._tangents[0].normalize(),this._tangents[e-1]=this._curve[e-1].subtract(this._curve[e-2]),this._tangents[e-1].normalize();var i=this._tangents[0],r=this._normalVector(this._curve[0],i,t);this._normals[0]=r,this._normals[0].normalize(),this._binormals[0]=n.Cross(i,this._normals[0]),this._binormals[0].normalize(),this._distances[0]=0;for(var o,s,a,h,c,l=1;e>l;l++)o=this._getLastNonNullVector(l),e-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._normals[l-1],c=this._binormals[l-1],this._normals[l]=n.Cross(c,a),this._normals[l].normalize(),this._binormals[l]=n.Cross(a,this._normals[l]),this._binormals[l].normalize()},t.prototype._getFirstNonNullVector=function(t){for(var e=1,i=this._curve[t+e].subtract(this._curve[t]);0==i.length()&&t+e+1<this._curve.length;)e++,i=this._curve[t+e].subtract(this._curve[t]);return i},t.prototype._getLastNonNullVector=function(t){for(var e=1,i=this._curve[t].subtract(this._curve[t-e]);0==i.length()&&t>e+1;)e++,i=this._curve[t].subtract(this._curve[t-e]);return i},t.prototype._normalVector=function(t,e,i){var r;if(void 0===i||null===i){var o;1!==e.x?o=new n(1,0,0):1!==e.y?o=new n(0,1,0):1!==e.z&&(o=new n(0,0,1)),r=n.Cross(e,o)}else r=n.Cross(e,i),n.CrossToRef(r,e,r);return r.normalize(),r},t}();t.Path3D=v;var y=function(){function e(t){this._length=0,this._points=t,this._length=this._computeLength(t)}return e.CreateQuadraticBezier=function(t,i,r,o){o=o>2?o:3;for(var s=new Array,a=function(t,e,i,r){var n=(1-t)*(1-t)*e+2*t*(1-t)*i+t*t*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(t,e,i,r,n){var o=(1-t)*(1-t)*(1-t)*e+3*t*(1-t)*(1-t)*i+3*t*t*(1-t)*r+t*t*t*n;return o},c=0;s>=c;c++)a.push(new n(h(c/s,t.x,i.x,r.x,o.x),h(c/s,t.y,i.y,r.y,o.y),h(c/s,t.z,i.z,r.z,o.z)));return new e(a)},e.CreateHermiteSpline=function(i,r,n,o,s){for(var a=new Array,h=1/s,c=0;s>=c;c++)a.push(t.Vector3.Hermite(i,r,n,o,c*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(t){for(var e=0,i=1;i<t.length;i++)e+=t[i].subtract(t[i-1]).length();return e},e}();t.Curve3=y;var x=function(){function t(t,e){void 0===t&&(t=n.Zero()),void 0===e&&(e=n.Up()),this.position=t,this.normal=e}return t.prototype.clone=function(){return new t(this.position.clone(),this.normal.clone())},t}();t.PositionNormalVertex=x;var b=function(){function t(t,e,i){void 0===t&&(t=n.Zero()),void 0===e&&(e=n.Up()),void 0===i&&(i=r.Zero()),this.position=t,this.normal=e,this.uv=i}return t.prototype.clone=function(){return new t(this.position.clone(),this.normal.clone(),this.uv.clone())},t}();t.PositionNormalTextureVertex=b;var M=a.prototype.multiplyToArray,T=a.prototype.invertToRef,S=a.LookAtLHToRef,A=n.TransformCoordinatesToRef,w=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=M,a.prototype.invertToRef=T,a.LookAtLHToRef=S,n.TransformCoordinatesToRef=A,n.TransformCoordinatesFromFloatsToRef=w,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(t.Vector3.prototype,"x",{get:function(){return this._data[0]},set:function(t){this._data||(this._data=new Float32Array(3)),this._data[0]=t}}),Object.defineProperty(t.Vector3.prototype,"y",{get:function(){return this._data[1]},set:function(t){this._data[1]=t}}),Object.defineProperty(t.Vector3.prototype,"z",{get:function(){return this._data[2]},set:function(t){this._data[2]=t}}),e._isEnabled=!0)},e._isEnabled=!1,e}();t.SIMDHelper=D,void 0!==window.SIMD&&D.EnableSIMD()}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i){this.idbFactory=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,this.callbackManifestChecked=i,this.currentSceneUrl=t.Database.ReturnFullUrlLocation(e),this.db=null,this.enableSceneOffline=!1,this.enableTexturesOffline=!1,this.manifestVersionFound=0,this.mustUpdateRessources=!1,this.hasReachedQuota=!1,this.checkManifestFile()}return e.prototype.checkManifestFile=function(){function e(){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||t.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){e()}else e()},!1),o.addEventListener("error",function(t){e()},!1);try{o.send()}catch(a){t.Tools.Error("Error on XHR send request."),r.callbackManifestChecked(!1)}},e.prototype.openAsync=function(e,i){function r(){o.isSupported=!1,i&&i()}var n=this,o=this;if(this.idbFactory&&(this.enableSceneOffline||this.enableTexturesOffline))if(this.db)e&&e();else{this.hasReachedQuota=!1,this.isSupported=!0;var s=this.idbFactory.open("babylonjs",1);s.onerror=function(t){r()},s.onblocked=function(e){t.Tools.Error("IDB request blocked. Please reload the page."),r()},s.onsuccess=function(t){n.db=s.result,e()},s.onupgradeneeded=function(e){n.db=e.target.result;try{{n.db.createObjectStore("scenes",{keyPath:"sceneUrl"}),n.db.createObjectStore("versions",{keyPath:"sceneUrl"}),n.db.createObjectStore("textures",{keyPath:"textureUrl"})}}catch(i){t.Tools.Error("Error while creating object stores. Exception: "+i.message),r()}}}else this.isSupported=!1,i&&i()},e.prototype.loadImageFromDB=function(t,i){var r=this,n=e.ReturnFullUrlLocation(t),o=function(){r.hasReachedQuota||null===r.db?i.src=t:r._saveImageIntoDBAsync(n,i)};this.mustUpdateRessources?o():this._loadImageFromDBAsync(n,i,o)},e.prototype._loadImageFromDBAsync=function(e,i,r){if(this.isSupported&&null!==this.db){var n,o=this.db.transaction(["textures"]);o.onabort=function(t){i.src=e},o.oncomplete=function(o){var s;if(n){var a=window.URL||window.webkitURL;s=a.createObjectURL(n.data,{oneTimeOnly:!0}),i.onerror=function(){t.Tools.Error("Error loading image from blob URL: "+s+" switching back to web url: "+e),i.src=e},i.src=s}else r()};var s=o.objectStore("textures").get(e);s.onsuccess=function(t){n=t.target.result},s.onerror=function(r){t.Tools.Error("Error loading texture "+e+" from DB."),i.src=e}}else t.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i.src=e},e.prototype._saveImageIntoDBAsync=function(i,r){var n=this;if(this.isSupported){var o=function(){var t;if(s){var e=window.URL||window.webkitURL;try{t=e.createObjectURL(s,{oneTimeOnly:!0})}catch(i){t=e.createObjectURL(s)}}r.src=t};if(e.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 t=n.db.transaction(["textures"],"readwrite");t.onabort=function(t){try{t.srcElement.error&&"QuotaExceededError"===t.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(e){}o()},t.oncomplete=function(t){o()};var h={textureUrl:i,data:s};try{var c=t.objectStore("textures").put(h);c.onsuccess=function(t){},c.onerror=function(t){o()}}catch(l){25===l.code&&(e.isUASupportingBlobStorage=!1),r.src=i}}else r.src=i},!1),a.addEventListener("error",function(e){t.Tools.Error("Error in XHR request in BABYLON.Database."),r.src=i},!1),a.send()}else r.src=i}else t.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r.src=i},e.prototype._checkVersionFromDB=function(t,e){var i=this,r=function(r){i._saveVersionIntoDBAsync(t,e)};this._loadVersionFromDBAsync(t,e,r)},e.prototype._loadVersionFromDBAsync=function(e,i,r){var n=this;if(this.isSupported){var o;try{var s=this.db.transaction(["versions"]);s.oncomplete=function(t){o?n.manifestVersionFound>o.data?(n.mustUpdateRessources=!0,r()):i(o.data):(n.mustUpdateRessources=!0,r())},s.onabort=function(t){i(-1)};var a=s.objectStore("versions").get(e);a.onsuccess=function(t){o=t.target.result},a.onerror=function(r){t.Tools.Error("Error loading version for scene "+e+" from DB."),i(-1)}}catch(h){t.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+h.message),i(-1)}}else t.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i(-1)},e.prototype._saveVersionIntoDBAsync=function(e,i){var r=this;if(this.isSupported&&!this.hasReachedQuota)try{var n=this.db.transaction(["versions"],"readwrite");n.onabort=function(t){try{t.srcElement.error&&"QuotaExceededError"===t.srcElement.error.name&&(r.hasReachedQuota=!0)}catch(e){}i(-1)},n.oncomplete=function(t){i(r.manifestVersionFound)};var o={sceneUrl:e,data:this.manifestVersionFound},s=n.objectStore("versions").put(o);s.onsuccess=function(t){},s.onerror=function(e){t.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(a){t.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+a.message),i(-1)}else i(-1)},e.prototype.loadFileFromDB=function(t,i,r,n,o){var s=this,a=e.ReturnFullUrlLocation(t),h=function(t){s._saveFileIntoDBAsync(a,i,r)};this._checkVersionFromDB(a,function(t){-1!==t?s.mustUpdateRessources?s._saveFileIntoDBAsync(a,i,r,o):s._loadFileFromDBAsync(a,i,h,o):n()})},e.prototype._loadFileFromDBAsync=function(e,i,r,n){if(this.isSupported){var o;o=-1!==e.indexOf(".babylon")?"scenes":"textures";var s,a=this.db.transaction([o]);a.oncomplete=function(t){s?i(s.data):r()},a.onabort=function(t){r()};var h=a.objectStore(o).get(e);h.onsuccess=function(t){s=t.target.result},h.onerror=function(i){t.Tools.Error("Error loading file "+e+" from DB."),r()}}else t.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},e.prototype._saveFileIntoDBAsync=function(e,i,r,n){var o=this;if(this.isSupported){var s;s=-1!==e.indexOf(".babylon")?"scenes":"textures";var a,h=new XMLHttpRequest;h.open("GET",e,!0),n&&(h.responseType="arraybuffer"),h.onprogress=r,h.addEventListener("load",function(){if(200===h.status||t.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(t){try{t.srcElement.error&&"QuotaExceededError"===t.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(e){}i(a)},r.oncomplete=function(t){i(a)};var c;c="scenes"===s?{sceneUrl:e,data:a,version:o.manifestVersionFound}:{textureUrl:e,data:a};try{var l=r.objectStore(s).put(c);l.onsuccess=function(t){},l.onerror=function(e){t.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(u){i(a)}}else i()},!1),h.addEventListener("error",function(e){t.Tools.Error("error on XHR request."),i()},!1),h.send()}else t.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},e.isUASupportingBlobStorage=!0,e.parseURL=function(t){var e=document.createElement("a");e.href=t;var i=t.substring(0,t.lastIndexOf("#")),r=t.substring(i.lastIndexOf("/")+1,t.length),n=t.substring(0,t.indexOf(r,0));return n},e.ReturnFullUrlLocation=function(e){return-1===e.indexOf("http:/")?t.Database.parseURL(window.location.href)+e:e},e}();t.Database=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e;!function(e){var i=function(){function e(){}return e.GetTGAHeader=function(t){var e=0,i={id_length:t[e++],colormap_type:t[e++],image_type:t[e++],colormap_index:t[e++]|t[e++]<<8,colormap_length:t[e++]|t[e++]<<8,colormap_size:t[e++],origin:[t[e++]|t[e++]<<8,t[e++]|t[e++]<<8],width:t[e++]|t[e++]<<8,height:t[e++]|t[e++]<<8,pixel_size:t[e++],flags:t[e++]};return i},e.UploadContent=function(i,r){if(r.length<19)return void t.Tools.Error("Unable to load TGA file - Not enough data to contain header");var n=18,o=e.GetTGAHeader(r);if(o.id_length+n>r.length)return void t.Tools.Error("Unable to load TGA file - Not enough data");n+=o.id_length;var s=!1,a=!1,h=!1,c=!1;switch(o.image_type){case e._TYPE_RLE_INDEXED:s=!0;case e._TYPE_INDEXED:a=!0;break;case e._TYPE_RLE_RGB:s=!0;case e._TYPE_RGB:h=!0;break;case e._TYPE_RLE_GREY:s=!0;case e._TYPE_GREY:
- c=!0}var l,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){l=new Uint8Array(d);for(var p,m,_,g=0,v=new Uint8Array(f);d>n&&d>g;)if(p=r[n++],m=(127&p)+1,128&p){for(_=0;f>_;++_)v[_]=r[n++];for(_=0;m>_;++_)l.set(v,g+_*f);g+=f*m}else{for(m*=f,_=0;m>_;++_)l[g+_]=r[n++];g+=m}}else l=r.subarray(n,n+=a?o.width*o.height:d);var y,x,b,M,T,S;switch((o.flags&e._ORIGIN_MASK)>>e._ORIGIN_SHIFT){default:case e._ORIGIN_UL:y=0,b=1,S=o.width,x=0,M=1,T=o.height;break;case e._ORIGIN_BL:y=0,b=1,S=o.width,x=o.height-1,M=-1,T=-1;break;case e._ORIGIN_UR:y=o.width-1,b=-1,S=-1,x=0,M=1,T=o.height;break;case e._ORIGIN_BR:y=o.width-1,b=-1,S=-1,x=o.height-1,M=-1,T=-1}var A="_getImageData"+(c?"Grey":"")+o.pixel_size+"bits",w=e[A](o,u,l,x,M,T,y,b,S);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,o.width,o.height,0,i.RGBA,i.UNSIGNED_BYTE,w)},e._getImageData8bits=function(t,e,i,r,n,o,s,a,h){var c,l,u,f=i,d=e,p=t.width,m=t.height,_=0,g=new Uint8Array(p*m*4);for(u=r;u!==o;u+=n)for(l=s;l!==h;l+=a,_++)c=f[_],g[4*(l+p*u)+3]=255,g[4*(l+p*u)+2]=d[3*c+0],g[4*(l+p*u)+1]=d[3*c+1],g[4*(l+p*u)+0]=d[3*c+2];return g},e._getImageData16bits=function(t,e,i,r,n,o,s,a,h){var c,l,u,f=i,d=t.width,p=t.height,m=0,_=new Uint8Array(d*p*4);for(u=r;u!==o;u+=n)for(l=s;l!==h;l+=a,m+=2)c=f[m+0]+(f[m+1]<<8),_[4*(l+d*u)+0]=(31744&c)>>7,_[4*(l+d*u)+1]=(992&c)>>2,_[4*(l+d*u)+2]=(31&c)>>3,_[4*(l+d*u)+3]=32768&c?0:255;return _},e._getImageData24bits=function(t,e,i,r,n,o,s,a,h){var c,l,u=i,f=t.width,d=t.height,p=0,m=new Uint8Array(f*d*4);for(l=r;l!==o;l+=n)for(c=s;c!==h;c+=a,p+=3)m[4*(c+f*l)+3]=255,m[4*(c+f*l)+2]=u[p+0],m[4*(c+f*l)+1]=u[p+1],m[4*(c+f*l)+0]=u[p+2];return m},e._getImageData32bits=function(t,e,i,r,n,o,s,a,h){var c,l,u=i,f=t.width,d=t.height,p=0,m=new Uint8Array(f*d*4);for(l=r;l!==o;l+=n)for(c=s;c!==h;c+=a,p+=4)m[4*(c+f*l)+2]=u[p+0],m[4*(c+f*l)+1]=u[p+1],m[4*(c+f*l)+0]=u[p+2],m[4*(c+f*l)+3]=u[p+3];return m},e._getImageDataGrey8bits=function(t,e,i,r,n,o,s,a,h){var c,l,u,f=i,d=t.width,p=t.height,m=0,_=new Uint8Array(d*p*4);for(u=r;u!==o;u+=n)for(l=s;l!==h;l+=a,m++)c=f[m],_[4*(l+d*u)+0]=c,_[4*(l+d*u)+1]=c,_[4*(l+d*u)+2]=c,_[4*(l+d*u)+3]=255;return _},e._getImageDataGrey16bits=function(t,e,i,r,n,o,s,a,h){var c,l,u=i,f=t.width,d=t.height,p=0,m=new Uint8Array(f*d*4);for(l=r;l!==o;l+=n)for(c=s;c!==h;c+=a,p+=2)m[4*(c+f*l)+0]=u[p+0],m[4*(c+f*l)+1]=u[p+0],m[4*(c+f*l)+2]=u[p+0],m[4*(c+f*l)+3]=u[p+1];return m},e._TYPE_NO_DATA=0,e._TYPE_INDEXED=1,e._TYPE_RGB=2,e._TYPE_GREY=3,e._TYPE_RLE_INDEXED=9,e._TYPE_RLE_RGB=10,e._TYPE_RLE_GREY=11,e._ORIGIN_MASK=48,e._ORIGIN_SHIFT=4,e._ORIGIN_BL=0,e._ORIGIN_BR=1,e._ORIGIN_UL=2,e._ORIGIN_UR=3,e}();e.TGATools=i}(e=t.Internals||(t.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e;!function(e){function i(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}function r(t){return String.fromCharCode(255&t,t>>8&255,t>>16&255,t>>24&255)}var n=542327876,o=131072,s=512,a=4,h=64,c=131072,l=i("DXT1"),u=i("DXT3"),f=i("DXT5"),d=31,p=0,m=1,_=2,g=3,v=4,y=7,x=20,b=21,M=22,T=28,S=function(){function e(){}return e.GetDDSInfo=function(t){var e=new Int32Array(t,0,d),i=1;return e[_]&o&&(i=Math.max(1,e[y])),{width:e[v],height:e[g],mipmapCount:i,isFourCC:(e[x]&a)===a,isRGB:(e[x]&h)===h,isLuminance:(e[x]&c)===c,isCube:(e[T]&s)===s}},e.GetRGBAArrayBuffer=function(t,e,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n),a=0,h=e-1;h>=0;h--)for(var c=0;t>c;c++){var l=i+4*(c+h*t);o[a+2]=s[l],o[a+1]=s[l+1],o[a]=s[l+2],o[a+3]=s[l+3],a+=4}return o},e.GetRGBArrayBuffer=function(t,e,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n),a=0,h=e-1;h>=0;h--)for(var c=0;t>c;c++){var l=i+3*(c+h*t);o[a+2]=s[l],o[a+1]=s[l+1],o[a]=s[l+2],a+=3}return o},e.GetLuminanceArrayBuffer=function(t,e,i,r,n){for(var o=new Uint8Array(r),s=new Uint8Array(n),a=0,h=e-1;h>=0;h--)for(var c=0;t>c;c++){var l=i+(c+h*t);o[a]=s[l],a++}return o},e.UploadDDSLevels=function(i,s,a,h,c,x){var T,S,A,w,D,E,C,P,I,L,R=new Int32Array(a,0,d);if(R[p]!=n)return void t.Tools.Error("Invalid magic number in DDS header");if(!h.isFourCC&&!h.isRGB&&!h.isLuminance)return void t.Tools.Error("Unsupported format, must contain a FourCC, RGB or LUMINANCE code");if(h.isFourCC)switch(T=R[b]){case l:S=8,A=s.COMPRESSED_RGBA_S3TC_DXT1_EXT;break;case u:S=16,A=s.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case f:S=16,A=s.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return void console.error("Unsupported FourCC code:",r(T))}I=1,R[_]&o&&c!==!1&&(I=Math.max(1,R[y]));for(var O=R[M],B=0;x>B;B++){var F=1==x?i.TEXTURE_2D:i.TEXTURE_CUBE_MAP_POSITIVE_X+B;for(w=R[v],D=R[g],C=R[m]+4,L=0;I>L;++L){if(h.isRGB)24==O?(E=w*D*3,P=e.GetRGBArrayBuffer(w,D,C,E,a),i.texImage2D(F,L,i.RGB,w,D,0,i.RGB,i.UNSIGNED_BYTE,P)):(E=w*D*4,P=e.GetRGBAArrayBuffer(w,D,C,E,a),i.texImage2D(F,L,i.RGBA,w,D,0,i.RGBA,i.UNSIGNED_BYTE,P));else if(h.isLuminance){var V=i.getParameter(i.UNPACK_ALIGNMENT),N=w,z=Math.floor((w+V-1)/V)*V;E=z*(D-1)+N,P=e.GetLuminanceArrayBuffer(w,D,C,E,a),i.texImage2D(F,L,i.LUMINANCE,w,D,0,i.LUMINANCE,i.UNSIGNED_BYTE,P)}else E=Math.max(4,w)/4*Math.max(4,D)/4*S,P=new Uint8Array(a,C,E),i.compressedTexImage2D(F,L,A,w,D,0,P);C+=E,w*=.5,D*=.5,w=Math.max(1,w),D=Math.max(1,D)}}},e}();e.DDSTools=S}(e=t.Internals||(t.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(e){this.length=0,this._duplicateId=0,this.data=new Array(e),this._id=t._GlobalId++}return t.prototype.push=function(t){this.data[this.length++]=t,this.length>this.data.length&&(this.data.length*=2),t.__smartArrayFlags||(t.__smartArrayFlags={}),t.__smartArrayFlags[this._id]=this._duplicateId},t.prototype.pushNoDuplicate=function(t){t.__smartArrayFlags&&t.__smartArrayFlags[this._id]===this._duplicateId||this.push(t)},t.prototype.sort=function(t){this.data.sort(t)},t.prototype.reset=function(){this.length=0,this._duplicateId++},t.prototype.concat=function(t){if(0!==t.length){this.length+t.length>this.data.length&&(this.data.length=2*(this.length+t.length));for(var e=0;e<t.length;e++)this.data[this.length++]=(t.data||t)[e]}},t.prototype.concatWithNoDuplicate=function(t){if(0!==t.length){this.length+t.length>this.data.length&&(this.data.length=2*(this.length+t.length));for(var e=0;e<t.length;e++){var i=(t.data||t)[e];this.pushNoDuplicate(i)}}},t.prototype.indexOf=function(t){var e=this.data.indexOf(t);return e>=this.length?-1:e},t._GlobalId=0,t}();t.SmartArray=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(t){void 0===t&&(t=10),this.count=0,this._initialCapacity=t,this.items={},this._keys=new Array(this._initialCapacity)}return t.prototype.add=function(t,e){return void 0!=this.items[t]?-1:(this.items[t]=e,this._keys[this.count++]=t,this.count>this._keys.length&&(this._keys.length*=2),this.count)},t.prototype.remove=function(t){return void 0==this.items[t]?-1:this.removeItemOfIndex(this.indexOf(t))},t.prototype.removeItemOfIndex=function(t){if(!(t<this.count&&t>-1))return-1;for(delete this.items[this._keys[t]];t<this.count;)this._keys[t]=this._keys[t+1],t++;return--this.count},t.prototype.indexOf=function(t){for(var e=0;e!==this.count;e++)if(this._keys[e]===t)return e;return-1},t.prototype.item=function(t){return this.items[t]},t.prototype.getAllKeys=function(){if(this.count>0){for(var t=new Array(this.count),e=0;e<this.count;e++)t[e]=this._keys[e];return t}return void 0},t.prototype.getKeyByIndex=function(t){return t<this.count&&t>-1?this._keys[t]:void 0},t.prototype.getItemByIndex=function(t){return t<this.count&&t>-1?this.items[this._keys[t]]:void 0},t.prototype.empty=function(){this.count>0&&(this.count=0,this.items={},this._keys=new Array(this._initialCapacity))},t.prototype.forEach=function(t){var e;for(e in this.items)this.items.hasOwnProperty(e)&&t(this.items[e])},t}();t.SmartCollection=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e,i=function(e,i){return e?e instanceof t.Mesh?null:e instanceof t.SubMesh?e.clone(i):e.clone?e.clone():null:null},r=function(){function r(){}return r.GetFilename=function(t){var e=t.lastIndexOf("/");return 0>e?t:t.substring(e+1)},r.GetDOMTextContent=function(t){for(var e="",i=t.firstChild;i;)3===i.nodeType&&(e+=i.textContent),i=i.nextSibling;return e},r.ToDegrees=function(t){return 180*t/Math.PI},r.ToRadians=function(t){return t*Math.PI/180},r.ExtractMinAndMaxIndexed=function(e,i,r,n){for(var o=new t.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),s=new t.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),a=r;r+n>a;a++){var h=new t.Vector3(e[3*i[a]],e[3*i[a]+1],e[3*i[a]+2]);o=t.Vector3.Minimize(h,o),s=t.Vector3.Maximize(h,s)}return{minimum:o,maximum:s}},r.ExtractMinAndMax=function(e,i,r){for(var n=new t.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),o=new t.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),s=i;i+r>s;s++){var a=new t.Vector3(e[3*s],e[3*s+1],e[3*s+2]);n=t.Vector3.Minimize(a,n),o=t.Vector3.Maximize(a,o)}return{minimum:n,maximum:o}},r.MakeArray=function(t,e){return e===!0||void 0!==t&&null!=t?Array.isArray(t)?t:[t]:void 0},r.GetPointerPrefix=function(){var t="pointer";return navigator.pointerEnabled||(t="mouse"),t},r.QueueNewFrame=function(t){window.requestAnimationFrame?window.requestAnimationFrame(t):window.msRequestAnimationFrame?window.msRequestAnimationFrame(t):window.webkitRequestAnimationFrame?window.webkitRequestAnimationFrame(t):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(t):window.oRequestAnimationFrame?window.oRequestAnimationFrame(t):window.setTimeout(t,16)},r.RequestFullscreen=function(t){t.requestFullscreen?t.requestFullscreen():t.msRequestFullscreen?t.msRequestFullscreen():t.webkitRequestFullscreen?t.webkitRequestFullscreen():t.mozRequestFullScreen&&t.mozRequestFullScreen()},r.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},r.CleanUrl=function(t){return t=t.replace(/#/gm,"%23")},r.LoadImage=function(e,i,n,o){e=r.CleanUrl(e);var s=new Image;"data:"!==e.substr(0,5)&&(s.crossOrigin="anonymous"),s.onload=function(){i(s)},s.onerror=function(t){n(s,t)};var a=function(){s.src=e},h=function(){o.loadImageFromDB(e,s)};if(o&&o.enableTexturesOffline&&t.Database.isUASupportingBlobStorage)o.openAsync(h,a);else if(-1===e.indexOf("file:"))a();else try{var c,l=e.substring(5);try{c=URL.createObjectURL(t.FilesInput.FilesTextures[l],{oneTimeOnly:!0})}catch(u){c=URL.createObjectURL(t.FilesInput.FilesTextures[l])}s.src=c}catch(f){r.Log("Error while trying to load texture: "+l),s.src=null}return s},r.LoadFile=function(e,i,n,o,s,a){e=r.CleanUrl(e);var h=function(){var t=new XMLHttpRequest,o=r.BaseUrl+e;t.open("GET",o,!0),s&&(t.responseType="arraybuffer"),t.onprogress=n,t.onreadystatechange=function(){if(4===t.readyState)if(200===t.status||r.ValidateXHRData(t,s?6:1))i(s?t.response:t.responseText);else{if(!a)throw new Error("Error status: "+t.status+" - Unable to load "+o);a()}},t.send(null)},c=function(){o.loadFileFromDB(e,i,n,h,s)};if(-1!==e.indexOf("file:")){var l=e.substring(5);r.ReadFile(t.FilesInput.FilesToLoad[l],i,n,!0)}else o&&o.enableSceneOffline?o.openAsync(c,h):h()},r.ReadFileAsDataURL=function(t,e,i){var r=new FileReader;r.onload=function(t){e(t.target.result)},r.onprogress=i,r.readAsDataURL(t)},r.ReadFile=function(t,e,i,n){var o=new FileReader;o.onerror=function(i){r.Log("Error while reading file: "+t.name),e(JSON.stringify({autoClear:!0,clearColor:[1,0,0],ambientColor:[0,0,0],gravity:[0,-9.81,0],meshes:[],cameras:[],lights:[]}))},o.onload=function(t){e(t.target.result)},o.onprogress=i,n?o.readAsArrayBuffer(t):o.readAsText(t)},r.Clamp=function(t,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),Math.min(i,Math.max(e,t))},r.Sign=function(t){return t=+t,0===t||isNaN(t)?t:t>0?1:-1},r.Format=function(t,e){return void 0===e&&(e=2),t.toFixed(e)},r.CheckExtends=function(t,e,i){t.x<e.x&&(e.x=t.x),t.y<e.y&&(e.y=t.y),t.z<e.z&&(e.z=t.z),t.x>i.x&&(i.x=t.x),t.y>i.y&&(i.y=t.y),t.z>i.z&&(i.z=t.z)},r.WithinEpsilon=function(t,e,i){void 0===i&&(i=1.401298e-45);var r=t-e;return r>=-i&&i>=r},r.DeepCopy=function(t,e,r,n){for(var o in t)if(("_"!==o[0]||n&&-1!==n.indexOf(o))&&(!r||-1===r.indexOf(o))){var s=t[o],a=typeof s;if("function"!==a)if("object"===a)if(s instanceof Array){if(e[o]=[],s.length>0)if("object"==typeof s[0])for(var h=0;h<s.length;h++){var c=i(s[h],e);-1===e[o].indexOf(c)&&e[o].push(c)}else e[o]=s.slice(0)}else e[o]=i(s,e);else e[o]=s}},r.IsEmpty=function(t){for(var e in t)return!1;return!0},r.RegisterTopRootEvents=function(t){for(var e=0;e<t.length;e++){var i=t[e];window.addEventListener(i.name,i.handler,!1);try{window.parent&&window.parent.addEventListener(i.name,i.handler,!1)}catch(r){}}},r.UnregisterTopRootEvents=function(t){for(var e=0;e<t.length;e++){var i=t[e];window.removeEventListener(i.name,i.handler);try{window.parent&&window.parent.removeEventListener(i.name,i.handler)}catch(r){}}},r.DumpFramebuffer=function(t,i,r){for(var n=4*t,o=i/2,s=r.readPixels(0,0,t,i),a=0;o>a;a++)for(var h=0;n>h;h++){var c=h+a*n,l=i-a-1,u=h+l*n,f=s[c];s[c]=s[u],s[u]=f}e||(e=document.createElement("canvas")),e.width=t,e.height=i;var d=e.getContext("2d"),p=d.createImageData(t,i),m=p.data;m.set(s),d.putImageData(p,0,0);var _=e.toDataURL();if("download"in document.createElement("a")){var g=window.document.createElement("a");g.href=_;var v=new Date,y=v.getFullYear()+"/"+v.getMonth()+"/"+v.getDate()+"-"+v.getHours()+":"+v.getMinutes();g.setAttribute("download","screenshot-"+y+".png"),window.document.body.appendChild(g),g.addEventListener("click",function(){g.parentElement.removeChild(g)}),g.click()}else{var x=window.open(""),b=x.document.createElement("img");b.src=_,x.document.body.appendChild(b)}},r.CreateScreenshot=function(e,i,n){var o,s,a=i.getScene(),h=null;if(a.activeCamera!==i&&(h=a.activeCamera,a.activeCamera=i),n.precision)o=Math.round(e.getRenderWidth()*n.precision),s=Math.round(o/e.getAspectRatio(i)),n={width:o,height:s};else if(n.width&&n.height)o=n.width,s=n.height;else if(n.width&&!n.height)o=n.width,s=Math.round(o/e.getAspectRatio(i)),n={width:o,height:s};else if(n.height&&!n.width)s=n.height,o=Math.round(s*e.getAspectRatio(i)),n={width:o,height:s};else{if(isNaN(n))return void r.Error("Invalid 'size' parameter !");s=n,o=n}var c=new t.RenderTargetTexture("screenShot",n,a,!1,!1);c.renderList=a.meshes,c.onAfterRender=function(){r.DumpFramebuffer(o,s,e)},a.incrementRenderId(),c.render(!0),c.dispose(),h&&(a.activeCamera=h)},r.ValidateXHRData=function(e,i){void 0===i&&(i=7);try{if(1&i){if(e.responseText&&e.responseText.length>0)return!0;if(1===i)return!1}if(2&i){var r=t.Internals.TGATools.GetTGAHeader(e.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(e.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(t){r._LogCache=t+r._LogCache,r.OnNewCacheEntry&&r.OnNewCacheEntry(t)},r._FormatMessage=function(t){var e=function(t){return 10>t?"0"+t:""+t},i=new Date;return"["+e(i.getHours())+":"+e(i.getMinutes())+":"+e(i.getSeconds())+"]: "+t},r._LogDisabled=function(t){},r._LogEnabled=function(t){var e=r._FormatMessage(t);console.log("BJS - "+e);var i="<div style='color:white'>"+e+"</div><br>";r._AddLogEntry(i)},r._WarnDisabled=function(t){},r._WarnEnabled=function(t){var e=r._FormatMessage(t);console.warn("BJS - "+e);var i="<div style='color:orange'>"+e+"</div><br>";r._AddLogEntry(i)},r._ErrorDisabled=function(t){},r._ErrorEnabled=function(t){var e=r._FormatMessage(t);console.error("BJS - "+e);var i="<div style='color:red'>"+e+"</div><br>";r._AddLogEntry(i)},Object.defineProperty(r,"LogCache",{get:function(){return r._LogCache},enumerable:!0,configurable:!0}),Object.defineProperty(r,"LogLevels",{set:function(t){r.Log=(t&r.MessageLogLevel)===r.MessageLogLevel?r._LogEnabled:r._LogDisabled,r.Warn=(t&r.WarningLogLevel)===r.WarningLogLevel?r._WarnEnabled:r._WarnDisabled,r.Error=(t&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(t){return(t&r.PerformanceUserMarkLogLevel)===r.PerformanceUserMarkLogLevel?(r.StartPerformanceCounter=r._StartUserMark,void(r.EndPerformanceCounter=r._EndUserMark)):(t&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(t,e){},r._EndPerformanceCounterDisabled=function(t,e){},r._StartUserMark=function(t,e){void 0===e&&(e=!0),e&&r._performance.mark&&r._performance.mark(t+"-Begin")},r._EndUserMark=function(t,e){void 0===e&&(e=!0),e&&r._performance.mark&&(r._performance.mark(t+"-End"),r._performance.measure(t,t+"-Begin",t+"-End"))},r._StartPerformanceConsole=function(t,e){void 0===e&&(e=!0),e&&(r._StartUserMark(t,e),console.time&&console.time(t))},r._EndPerformanceConsole=function(t,e){void 0===e&&(e=!0),e&&(r._EndUserMark(t,e),console.time&&console.timeEnd(t))},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.GetExponantOfTwo=function(t,e){var i=1;do i*=2;while(t>i);return i>e&&(i=e),i},r._NoneLogLevel=0,r._MessageLogLevel=1,r._WarningLogLevel=2,r._ErrorLogLevel=4,r._LogCache="",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}();t.Tools=r;var n=function(){function t(t,e,i,r){void 0===r&&(r=0),this.iterations=t,this._fn=e,this._successCallback=i,this.index=r-1,this._done=!1}return t.prototype.executeNext=function(){this._done||(this.index+1<this.iterations?(++this.index,this._fn(this)):this.breakLoop())},t.prototype.breakLoop=function(){this._done=!0,this._successCallback()},t.Run=function(e,i,r,n){void 0===n&&(n=0);var o=new t(e,i,r,n);return o.executeNext(),o},t.SyncAsyncForLoop=function(e,i,r,n,o,s){void 0===s&&(s=0),t.Run(Math.ceil(e/i),function(t){o&&o()?t.breakLoop():setTimeout(function(){for(var n=0;i>n;++n){var s=t.index*i+n;if(s>=e)break;if(r(s),o&&o()){t.breakLoop();break}}t.executeNext()},s)},n)},t}();t.AsyncLoop=n}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(){this._isDepthTestDirty=!1,this._isDepthMaskDirty=!1,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1}return Object.defineProperty(t.prototype,"isDirty",{get:function(){return this._isDepthFuncDirty||this._isDepthTestDirty||this._isDepthMaskDirty||this._isCullFaceDirty||this._isCullDirty||this._isZOffsetDirty},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"zOffset",{get:function(){return this._zOffset},set:function(t){this._zOffset!==t&&(this._zOffset=t,this._isZOffsetDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cullFace",{get:function(){return this._cullFace},set:function(t){this._cullFace!==t&&(this._cullFace=t,this._isCullFaceDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cull",{get:function(){return this._cull},set:function(t){this._cull!==t&&(this._cull=t,this._isCullDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"depthFunc",{get:function(){return this._depthFunc},set:function(t){this._depthFunc!==t&&(this._depthFunc=t,this._isDepthFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"depthMask",{get:function(){return this._depthMask},set:function(t){this._depthMask!==t&&(this._depthMask=t,this._isDepthMaskDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"depthTest",{get:function(){return this._depthTest},set:function(t){this._depthTest!==t&&(this._depthTest=t,this._isDepthTestDirty=!0)},enumerable:!0,configurable:!0}),t.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},t.prototype.apply=function(t){this.isDirty&&(this._isCullDirty&&(this.cull?t.enable(t.CULL_FACE):t.disable(t.CULL_FACE),this._isCullDirty=!1),this._isCullFaceDirty&&(t.cullFace(this.cullFace),this._isCullFaceDirty=!1),this._isDepthMaskDirty&&(t.depthMask(this.depthMask),this._isDepthMaskDirty=!1),this._isDepthTestDirty&&(this.depthTest?t.enable(t.DEPTH_TEST):t.disable(t.DEPTH_TEST),this._isDepthTestDirty=!1),this._isDepthFuncDirty&&(t.depthFunc(this.depthFunc),this._isDepthFuncDirty=!1),this._isZOffsetDirty&&(this.zOffset?(t.enable(t.POLYGON_OFFSET_FILL),t.polygonOffset(this.zOffset,0)):t.disable(t.POLYGON_OFFSET_FILL),this._isZOffsetDirty=!1))},t}();t._DepthCullingState=e;var i=function(){function t(){this._isAlphaBlendDirty=!1,this._isBlendFunctionParametersDirty=!1,this._alphaBlend=!1,this._blendFunctionParameters=new Array(4)}return Object.defineProperty(t.prototype,"isDirty",{get:function(){return this._isAlphaBlendDirty||this._isBlendFunctionParametersDirty},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"alphaBlend",{get:function(){return this._alphaBlend},set:function(t){this._alphaBlend!==t&&(this._alphaBlend=t,this._isAlphaBlendDirty=!0)},enumerable:!0,configurable:!0}),t.prototype.setAlphaBlendFunctionParameters=function(t,e,i,r){(this._blendFunctionParameters[0]!==t||this._blendFunctionParameters[1]!==e||this._blendFunctionParameters[2]!==i||this._blendFunctionParameters[3]!==r)&&(this._blendFunctionParameters[0]=t,this._blendFunctionParameters[1]=e,this._blendFunctionParameters[2]=i,this._blendFunctionParameters[3]=r,this._isBlendFunctionParametersDirty=!0)},t.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},t.prototype.apply=function(t){this.isDirty&&(this._isAlphaBlendDirty&&(this._alphaBlend?t.enable(t.BLEND):t.disable(t.BLEND),this._isAlphaBlendDirty=!1),this._isBlendFunctionParametersDirty&&(t.blendFuncSeparate(this._blendFunctionParameters[0],this._blendFunctionParameters[1],this._blendFunctionParameters[2],this._blendFunctionParameters[3]),this._isBlendFunctionParametersDirty=!1))},t}();t._AlphaState=i;var r=function(t,e,i,r){var n=t.createShader("vertex"===i?t.VERTEX_SHADER:t.FRAGMENT_SHADER);if(t.shaderSource(n,(r?r+"\n":"")+e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(n));return n},n=function(t,e){var i=t.UNSIGNED_BYTE;return e===l.TEXTURETYPE_FLOAT&&(i=t.FLOAT),i},o=function(e,i,r){var n=r.NEAREST,o=r.NEAREST;return e===t.Texture.BILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=i?r.LINEAR_MIPMAP_NEAREST:r.LINEAR):e===t.Texture.TRILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=i?r.LINEAR_MIPMAP_LINEAR:r.LINEAR):e===t.Texture.NEAREST_SAMPLINGMODE&&(n=r.NEAREST,o=i?r.NEAREST_MIPMAP_LINEAR:r.NEAREST),{min:o,mag:n}},s=function(e,i,r,n,s,a,h,c,l,u){void 0===u&&(u=t.Texture.TRILINEAR_SAMPLINGMODE);var f=r.getEngine(),d=t.Tools.GetExponantOfTwo(n,f.getCaps().maxTextureSize),p=t.Tools.GetExponantOfTwo(s,f.getCaps().maxTextureSize);i.bindTexture(i.TEXTURE_2D,e),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,void 0===a?1:a?1:0),e._baseWidth=n,e._baseHeight=s,e._width=d,e._height=p,e.isReady=!0,l(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||c||i.generateMipmap(i.TEXTURE_2D),i.bindTexture(i.TEXTURE_2D,null),f._activeTexturesCache=[],r._removePendingData(e)},a=function(e,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=t.Tools.LoadImage(e,s,a,n.database);n._addPendingData(h)},h=function(t,e,i,r){var n=[];n._internalCount=0;for(var o=0;6>o;o++)a(t+r[o],o,n,e,i)},c=function(){function t(){}return t}();t.EngineCapabilities=c;var l=function(){function a(r,n,o){var s=this;this.isFullscreen=!1,this.isPointerLock=!1,this.cullBackFaces=!0,this.renderEvenInBackground=!0,this.scenes=new Array,this._windowIsBackground=!1,this._loadingDivBackgroundColor="black",this._drawCalls=0,this._renderingQueueLaunched=!1,this._activeRenderLoops=[],this.fpsRange=60,this.previousFramesDuration=[],this.fps=60,this.deltaTime=0,this._depthCullingState=new e,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,this._canvasClientRect=this._renderingCanvas.getBoundingClientRect(),o=o||{},o.antialias=n;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 c,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 l=this._gl.getExtension("WEBGL_debug_renderer_info");if(null!=l&&(this._glRenderer=this._gl.getParameter(l.UNMASKED_RENDERER_WEBGL),this._glVendor=this._gl.getParameter(l.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 t.AudioEngine),t.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_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,"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.1.0 beta"},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(t){var e=t.viewport;return this.getRenderWidth()*e.width/(this.getRenderHeight()*e.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(t){this._hardwareScalingLevel=t,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(t){if(!t)return void(this._activeRenderLoops=[]);var e=this._activeRenderLoops.indexOf(t);e>=0&&this._activeRenderLoops.splice(e,1)},a.prototype._renderLoop=function(){var e=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?t.Tools.QueueNewFrame(function(){e._renderLoop()}):this._renderingQueueLaunched=!1},a.prototype.runRenderLoop=function(e){var i=this;-1===this._activeRenderLoops.indexOf(e)&&(this._activeRenderLoops.push(e),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,t.Tools.QueueNewFrame(function(){i._renderLoop()})))},a.prototype.switchFullscreen=function(e){this.isFullscreen?t.Tools.ExitFullscreen():(this._pointerLockRequested=e,t.Tools.RequestFullscreen(this._renderingCanvas))},a.prototype.clear=function(t,e,i){this.applyStates(),this._gl.clearColor(t.r,t.g,t.b,void 0!==t.a?t.a:1),this._depthCullingState.depthMask&&this._gl.clearDepth(1);var r=0;e&&(r|=this._gl.COLOR_BUFFER_BIT),i&&this._depthCullingState.depthMask&&(r|=this._gl.DEPTH_BUFFER_BIT),this._gl.clear(r)},a.prototype.setViewport=function(t,e,i){var r=e||(navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.width),n=i||(navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.height),o=t.x||0,s=t.y||0;this._cachedViewport=t,this._gl.viewport(o*r,s*n,r*t.width,n*t.height)},a.prototype.setDirectViewport=function(t,e,i,r){this._cachedViewport=null,this._gl.viewport(t,e,i,r)},a.prototype.beginFrame=function(){this._measureFps()},a.prototype.endFrame=function(){},a.prototype.resize=function(){var t=navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.clientWidth,e=navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.clientHeight;this.setSize(t/this._hardwareScalingLevel,e/this._hardwareScalingLevel)},a.prototype.setSize=function(t,e){this._renderingCanvas.width=t,this._renderingCanvas.height=e,this._canvasClientRect=this._renderingCanvas.getBoundingClientRect();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(t){this._currentRenderTarget=t;var e=this._gl;e.bindFramebuffer(e.FRAMEBUFFER,t._framebuffer),this._gl.viewport(0,0,t._width,t._height),this.wipeCaches()},a.prototype.unBindFramebuffer=function(t){if(this._currentRenderTarget=null,t.generateMipMaps){var e=this._gl;e.bindTexture(e.TEXTURE_2D,t),e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.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(t){var e=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array(t),this._gl.STATIC_DRAW),this._resetVertexBufferBinding(),e.references=1,e},a.prototype.createDynamicVertexBuffer=function(t){var e=this._gl.createBuffer();return this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),this._gl.bufferData(this._gl.ARRAY_BUFFER,t,this._gl.DYNAMIC_DRAW),this._resetVertexBufferBinding(),e.references=1,e},a.prototype.updateDynamicVertexBuffer=function(t,e,i){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),void 0===i&&(i=0),e instanceof Float32Array?this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,e):this._gl.bufferSubData(this._gl.ARRAY_BUFFER,i,new Float32Array(e)),this._resetVertexBufferBinding()},a.prototype._resetIndexBufferBinding=function(){this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,null),this._cachedIndexBuffer=null},a.prototype.createIndexBuffer=function(t){var e=this._gl.createBuffer();this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,e);var i,r=!1;if(this._caps.uintIndices){for(var n=0;n<t.length;n++)if(t[n]>65535){r=!0;break}i=r?new Uint32Array(t):new Uint16Array(t)}else i=new Uint16Array(t);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,i,this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),e.references=1,e.is32Bits=r,e},a.prototype.bindBuffers=function(t,e,i,r,n){if(this._cachedVertexBuffers!==t||this._cachedEffectForVertexBuffers!==n){this._cachedVertexBuffers=t,this._cachedEffectForVertexBuffers=n,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t);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!==e&&(this._cachedIndexBuffer=e,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,e),this._uintIndicesCurrentlySet=e.is32Bits)},a.prototype.bindMultiBuffers=function(t,e,i){if(this._cachedVertexBuffers!==t||this._cachedEffectForVertexBuffers!==i){this._cachedVertexBuffers=t,this._cachedEffectForVertexBuffers=i;for(var r=i.getAttributesNames(),n=0;n<r.length;n++){var o=i.getAttributeLocation(n);if(o>=0){var s=t[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!=e&&this._cachedIndexBuffer!==e&&(this._cachedIndexBuffer=e,this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,e),this._uintIndicesCurrentlySet=e.is32Bits)},a.prototype._releaseBuffer=function(t){return t.references--,0===t.references?(this._gl.deleteBuffer(t),!0):!1},a.prototype.createInstancesBuffer=function(t){var e=this._gl.createBuffer();return e.capacity=t,this._gl.bindBuffer(this._gl.ARRAY_BUFFER,e),this._gl.bufferData(this._gl.ARRAY_BUFFER,t,this._gl.DYNAMIC_DRAW),e},a.prototype.deleteInstancesBuffer=function(t){this._gl.deleteBuffer(t)},a.prototype.updateAndBindInstancesBuffer=function(t,e,i){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t),this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,e);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(t,e){this._gl.bindBuffer(this._gl.ARRAY_BUFFER,t);for(var i=0;4>i;i++){var r=e[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(t,e,i,r){this.applyStates(),this._drawCalls++;var n=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT;return r?void this._caps.instancedArrays.drawElementsInstancedANGLE(t?this._gl.TRIANGLES:this._gl.LINES,i,n,2*e,r):void this._gl.drawElements(t?this._gl.TRIANGLES:this._gl.LINES,i,n,2*e)},a.prototype.drawPointClouds=function(t,e,i){return this.applyStates(),this._drawCalls++,i?void this._caps.instancedArrays.drawArraysInstancedANGLE(this._gl.POINTS,t,e,i):void this._gl.drawArrays(this._gl.POINTS,t,e)},a.prototype._releaseEffect=function(t){this._compiledEffects[t._key]&&(delete this._compiledEffects[t._key],t.getProgram()&&this._gl.deleteProgram(t.getProgram()))},a.prototype.createEffect=function(e,i,r,n,o,s,a,h){var c=e.vertexElement||e.vertex||e,l=e.fragmentElement||e.fragment||e,u=c+"+"+l+"@"+o;if(this._compiledEffects[u])return this._compiledEffects[u];var f=new t.Effect(e,i,r,n,this,o,s,a,h);return f._key=u,this._compiledEffects[u]=f,f},a.prototype.createEffectForParticles=function(t,e,i,r,n,o,s){return void 0===e&&(e=[]),void 0===i&&(i=[]),void 0===r&&(r=""),this.createEffect({vertex:"particles",fragmentElement:t},["position","color","options"],["view","projection"].concat(e),["diffuseSampler"].concat(i),r,n,o,s)},a.prototype.createShaderProgram=function(t,e,i){var n=r(this._gl,t,"vertex",i),o=r(this._gl,e,"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(t,e){for(var i=[],r=0;r<e.length;r++)i.push(this._gl.getUniformLocation(t,e[r]));return i},a.prototype.getAttributes=function(t,e){for(var i=[],r=0;r<e.length;r++)try{i.push(this._gl.getAttribLocation(t,e[r]))}catch(n){i.push(-1)}return i},a.prototype.enableEffect=function(t){if(!t||!t.getAttributesCount()||this._currentEffect===t)return void(t&&t.onBind&&t.onBind(t));this._vertexAttribArrays=this._vertexAttribArrays||[],this._gl.useProgram(t.getProgram());for(var e in this._vertexAttribArrays)e>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[e]||(this._vertexAttribArrays[e]=!1,this._gl.disableVertexAttribArray(e));for(var i=t.getAttributesCount(),r=0;i>r;r++){var n=t.getAttributeLocation(r);n>=0&&(this._vertexAttribArrays[n]=!0,this._gl.enableVertexAttribArray(n))}this._currentEffect=t,t.onBind&&t.onBind(t)},a.prototype.setArray=function(t,e){t&&this._gl.uniform1fv(t,e)},a.prototype.setArray2=function(t,e){t&&e.length%2===0&&this._gl.uniform2fv(t,e)},a.prototype.setArray3=function(t,e){t&&e.length%3===0&&this._gl.uniform3fv(t,e)},a.prototype.setArray4=function(t,e){t&&e.length%4===0&&this._gl.uniform4fv(t,e)},a.prototype.setMatrices=function(t,e){t&&this._gl.uniformMatrix4fv(t,!1,e)},a.prototype.setMatrix=function(t,e){t&&this._gl.uniformMatrix4fv(t,!1,e.toArray())},a.prototype.setFloat=function(t,e){t&&this._gl.uniform1f(t,e)},a.prototype.setFloat2=function(t,e,i){t&&this._gl.uniform2f(t,e,i)},a.prototype.setFloat3=function(t,e,i,r){t&&this._gl.uniform3f(t,e,i,r)},a.prototype.setBool=function(t,e){t&&this._gl.uniform1i(t,e)},a.prototype.setFloat4=function(t,e,i,r,n){t&&this._gl.uniform4f(t,e,i,r,n)},a.prototype.setColor3=function(t,e){t&&this._gl.uniform3f(t,e.r,e.g,e.b)},a.prototype.setColor4=function(t,e,i){t&&this._gl.uniform4f(t,e.r,e.g,e.b,i)},a.prototype.setState=function(t,e,i){void 0===e&&(e=0),(this._depthCullingState.cull!==t||i)&&(t?(this._depthCullingState.cullFace=this.cullBackFaces?this._gl.BACK:this._gl.FRONT,this._depthCullingState.cull=!0):this._depthCullingState.cull=!1),this._depthCullingState.zOffset=e},a.prototype.setDepthBuffer=function(t){this._depthCullingState.depthTest=t},a.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},a.prototype.setDepthWrite=function(t){this._depthCullingState.depthMask=t},a.prototype.setColorWrite=function(t){this._gl.colorMask(t,t,t,t)},a.prototype.setAlphaMode=function(t){switch(t){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_ADD:this.setDepthWrite(!1),this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0}this._alphaMode=t},a.prototype.getAlphaMode=function(){return this._alphaMode},a.prototype.setAlphaTesting=function(t){this._alphaTest=t},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(e,i){var r=this._gl;r.bindTexture(r.TEXTURE_2D,e);var n=r.NEAREST,o=r.NEAREST;i===t.Texture.BILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=r.LINEAR):i===t.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),e.samplingMode=i},a.prototype.createTexture=function(e,i,r,n,o,a,h,c){var l=this;void 0===o&&(o=t.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),void 0===c&&(c=null);var u,f=this._gl.createTexture(),d=!1;if("data:"===e.substr(0,5)&&(d=!0),d){var p=e;d=p.split(":"),e=p,u=d[1].substr(d[1].length-4,4).toLowerCase()}else u=e.substr(e.length-4,4).toLowerCase();var m=this.getCaps().s3tc&&".dds"===u,_=".tga"===u;n._addPendingData(f),f.url=e,f.noMipmap=i,f.references=1,f.samplingMode=o,this._loadedTexturesCache.push(f);var g=function(){n._removePendingData(f),h&&h()};if(_){var v=function(e){var h=new Uint8Array(e),c=t.Internals.TGATools.GetTGAHeader(h);s(f,l._gl,n,c.width,c.height,r,i,!1,function(){t.Internals.TGATools.UploadContent(l._gl,h),a&&a()},o)};d instanceof Array?v(c):t.Tools.LoadFile(e,function(t){v(t)},g,n.database,!0)}else if(m)v=function(e){var h=t.Internals.DDSTools.GetDDSInfo(e),c=(h.isRGB||h.isLuminance||h.mipmapCount>1)&&!i&&h.width>>h.mipmapCount-1===1;s(f,l._gl,n,h.width,h.height,r,!c,h.isFourCC,function(){t.Internals.DDSTools.UploadDDSLevels(l._gl,l.getCaps().s3tc,e,h,c,1),a&&a()},o)},d instanceof Array?v(c):t.Tools.LoadFile(e,function(t){v(t)},g,n.database,!0);else{var y=function(e){s(f,l._gl,n,e.width,e.height,r,i,!1,function(i,r){var n=e.width===i&&e.height===r;n||(l._prepareWorkingCanvas(),l._workingCanvas.width=i,l._workingCanvas.height=r,o===t.Texture.NEAREST_SAMPLINGMODE&&(l._workingContext.imageSmoothingEnabled=!1,l._workingContext.mozImageSmoothingEnabled=!1,l._workingContext.oImageSmoothingEnabled=!1,l._workingContext.webkitImageSmoothingEnabled=!1,l._workingContext.msImageSmoothingEnabled=!1),l._workingContext.drawImage(e,0,0,e.width,e.height,0,0,i,r),o===t.Texture.NEAREST_SAMPLINGMODE&&(l._workingContext.imageSmoothingEnabled=!0,l._workingContext.mozImageSmoothingEnabled=!0,l._workingContext.oImageSmoothingEnabled=!0,l._workingContext.webkitImageSmoothingEnabled=!0,l._workingContext.msImageSmoothingEnabled=!0)),l._gl.texImage2D(l._gl.TEXTURE_2D,0,l._gl.RGBA,l._gl.RGBA,l._gl.UNSIGNED_BYTE,n?e:l._workingCanvas),a&&a()},o)};d instanceof Array?t.Tools.LoadImage(c,y,g,n.database):t.Tools.LoadImage(e,y,g,n.database)}return f},a.prototype.createRawTexture=function(t,e,i,r,n,s,h){var c=this._gl.createTexture();this._gl.bindTexture(this._gl.TEXTURE_2D,c),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,void 0===s?1:s?1:0);var l=this._gl.RGBA;switch(r){case a.TEXTUREFORMAT_ALPHA:l=this._gl.ALPHA;break;case a.TEXTUREFORMAT_LUMINANCE:l=this._gl.LUMINANCE;break;case a.TEXTUREFORMAT_LUMINANCE_ALPHA:l=this._gl.LUMINANCE_ALPHA;break;case a.TEXTUREFORMAT_RGB:l=this._gl.RGB;break;case a.TEXTUREFORMAT_RGBA:l=this._gl.RGBA}this._gl.texImage2D(this._gl.TEXTURE_2D,0,l,e,i,0,l,this._gl.UNSIGNED_BYTE,t),n&&this._gl.generateMipmap(this._gl.TEXTURE_2D);var u=o(h,n,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,u.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,u.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],c._baseWidth=e,c._baseHeight=i,c._width=e,c._height=i,c.isReady=!0,c.references=1,c.samplingMode=h,this._loadedTexturesCache.push(c),c},a.prototype.createDynamicTexture=function(e,i,r,n){var o=this._gl.createTexture();return e=t.Tools.GetExponantOfTwo(e,this._caps.maxTextureSize),i=t.Tools.GetExponantOfTwo(i,this._caps.maxTextureSize),this._activeTexturesCache=[],o._baseWidth=e,o._baseHeight=i,o._width=e,o._height=i,o.isReady=!1,o.generateMipMaps=r,o.references=1,o.samplingMode=n,this.updateTextureSamplingMode(n,o),this._loadedTexturesCache.push(o),o},a.prototype.updateTextureSamplingMode=function(t,e){var i=o(t,e.generateMipMaps,this._gl);this._gl.bindTexture(this._gl.TEXTURE_2D,e),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(t,e,i){this._gl.bindTexture(this._gl.TEXTURE_2D,t),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,e),t.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],t.isReady=!0},a.prototype.updateVideoTexture=function(t,e,i){this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?0:1),e.videoWidth!==t._width||e.videoHeight!==t._height?(t._workingCanvas||(t._workingCanvas=document.createElement("canvas"),t._workingContext=t._workingCanvas.getContext("2d"),t._workingCanvas.width=t._width,t._workingCanvas.height=t._height),t._workingContext.drawImage(e,0,0,e.videoWidth,e.videoHeight,0,0,t._width,t._height),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t._workingCanvas)):this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,e),t.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._activeTexturesCache=[],t.isReady=!0},a.prototype.createRenderTargetTexture=function(e,i){var r=!1,s=!0,h=a.TEXTURETYPE_UNSIGNED_INT,c=t.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&&(c=i.samplingMode),h===a.TEXTURETYPE_FLOAT&&(c=t.Texture.NEAREST_SAMPLINGMODE));var l=this._gl,u=l.createTexture();l.bindTexture(l.TEXTURE_2D,u);var f=e.width||e,d=e.height||e,p=o(c,r,l);h!==a.TEXTURETYPE_FLOAT||this._caps.textureFloat||(h=a.TEXTURETYPE_UNSIGNED_INT,t.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,p.mag),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,p.min),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,f,d,0,l.RGBA,n(l,h),null);var m;s&&(m=l.createRenderbuffer(),l.bindRenderbuffer(l.RENDERBUFFER,m),l.renderbufferStorage(l.RENDERBUFFER,l.DEPTH_COMPONENT16,f,d));var _=l.createFramebuffer();return l.bindFramebuffer(l.FRAMEBUFFER,_),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,l.TEXTURE_2D,u,0),s&&l.framebufferRenderbuffer(l.FRAMEBUFFER,l.DEPTH_ATTACHMENT,l.RENDERBUFFER,m),l.bindTexture(l.TEXTURE_2D,null),l.bindRenderbuffer(l.RENDERBUFFER,null),l.bindFramebuffer(l.FRAMEBUFFER,null),u._framebuffer=_,s&&(u._depthBuffer=m),u._width=f,u._height=d,u.isReady=!0,u.generateMipMaps=r,u.references=1,u.samplingMode=c,this._activeTexturesCache=[],this._loadedTexturesCache.push(u),u},a.prototype.createCubeTexture=function(e,i,r,n){var o=this,s=this._gl,a=s.createTexture();a.isCube=!0,a.url=e,a.references=1,this._loadedTexturesCache.push(a);var c=e.substr(e.length-4,4).toLowerCase(),l=this.getCaps().s3tc&&".dds"===c;return l?t.Tools.LoadFile(e,function(e){var i=t.Internals.DDSTools.GetDDSInfo(e),r=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!n;s.bindTexture(s.TEXTURE_CUBE_MAP,a),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,1),t.Internals.DDSTools.UploadDDSLevels(o._gl,o.getCaps().s3tc,e,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(e,i,function(e){var i=t.Tools.GetExponantOfTwo(e[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 c=0;c<h.length;c++)o._workingContext.drawImage(e[c],0,0,e[c].width,e[c].height,0,0,i,r),s.texImage2D(h[c],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(t){var e=this._gl;t._framebuffer&&e.deleteFramebuffer(t._framebuffer),t._depthBuffer&&e.deleteRenderbuffer(t._depthBuffer),e.deleteTexture(t);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(t);-1!==r&&this._loadedTexturesCache.splice(r,1)},a.prototype.bindSamplers=function(t){this._gl.useProgram(t.getProgram());for(var e=t.getSamplers(),i=0;i<e.length;i++){var r=t.getUniform(e[i]);this._gl.uniform1i(r,i)}this._currentEffect=null},a.prototype._bindTexture=function(t,e){this._gl.activeTexture(this._gl["TEXTURE"+t]),this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._activeTexturesCache[t]=null},a.prototype.setTextureFromPostProcess=function(t,e){this._bindTexture(t,e._textures.data[e._currentRenderTextureInd])},a.prototype.setTexture=function(e,i){if(!(0>e)){if(!i||!i.isReady())return void(null!=this._activeTexturesCache[e]&&(this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null),this._activeTexturesCache[e]=null));if(i instanceof t.VideoTexture)i.update()&&(this._activeTexturesCache[e]=null);else if(i.delayLoadState===a.DELAYLOADSTATE_NOTLOADED)return void i.delayLoad();if(this._activeTexturesCache[e]!==i){this._activeTexturesCache[e]=i;var r=i.getInternalTexture();if(this._gl.activeTexture(this._gl["TEXTURE"+e]),r.isCube){if(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,r),r._cachedCoordinatesMode!==i.coordinatesMode){r._cachedCoordinatesMode=i.coordinatesMode;var n=i.coordinatesMode!==t.Texture.CUBIC_MODE&&i.coordinatesMode!==t.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 t.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.REPEAT);break;case t.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.CLAMP_TO_EDGE);break;case t.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 t.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.REPEAT);break;case t.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.CLAMP_TO_EDGE);break;case t.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(e,i){var r=this._caps.textureAnisotropicFilterExtension,n=i.anisotropicFilteringLevel;i.getInternalTexture().samplingMode===t.Texture.NEAREST_SAMPLINGMODE&&(n=1),r&&i._cachedAnisotropicFilteringLevel!==n&&(this._gl.texParameterf(e,r.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(n,this._caps.maxAnisotropy)),i._cachedAnisotropicFilteringLevel=n)},a.prototype.readPixels=function(t,e,i,r){var n=new Uint8Array(r*i*4);return this._gl.readPixels(0,0,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 t in this._compiledEffects)this._gl.deleteProgram(this._compiledEffects[t]._program);for(var e in this._vertexAttribArrays)e>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArrays[e]||this._gl.disableVertexAttribArray(e);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 t=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 e=new Image;e.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==",e.style.position="absolute",e.style.left="50%",e.style.top="50%",e.style.marginLeft="-50px",e.style.marginTop="-50px",e.style.transition="transform 1.0s ease",e.style.webkitTransition="-webkit-transform 1.0s ease";var i=360,r=function(){i+=360,e.style.transform="rotateZ("+i+"deg)",e.style.webkitTransform="rotateZ("+i+"deg)"};e.addEventListener("transitionend",r),e.addEventListener("webkitTransitionEnd",r),this._loadingDiv.appendChild(e);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 e=t.getRenderingCanvasClientRect();t._loadingDiv.style.position="absolute",t._loadingDiv.style.left=e.left+"px",t._loadingDiv.style.top=e.top+"px",t._loadingDiv.style.width=e.width+"px",t._loadingDiv.style.height=e.height+"px"},this._resizeLoadingUI(),window.addEventListener("resize",this._resizeLoadingUI),this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor,document.body.appendChild(this._loadingDiv),setTimeout(function(){t._loadingDiv.style.opacity="1",e.style.transform="rotateZ(360deg)",e.style.webkitTransform="rotateZ(360deg)"},0)},Object.defineProperty(a.prototype,"loadingUIText",{set:function(t){this._loadingDiv&&(this._loadingTextDiv.innerHTML=t)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"loadingUIBackgroundColor",{get:function(){return this._loadingDivBackgroundColor},set:function(t){this._loadingDivBackgroundColor=t,this._loadingDiv&&(this._loadingDiv.style.backgroundColor=this._loadingDivBackgroundColor)},enumerable:!0,configurable:!0}),a.prototype.hideLoadingUI=function(){var t=this;if(this._loadingDiv){var e=function(){t._loadingDiv&&(document.body.removeChild(t._loadingDiv),window.removeEventListener("resize",t._resizeLoadingUI),t._loadingDiv=null)};this._loadingDiv.style.opacity="0",this._loadingDiv.addEventListener("transitionend",e)}},a.prototype.getFps=function(){return this.fps},a.prototype.getDeltaTime=function(){return this.deltaTime},a.prototype._measureFps=function(){this.previousFramesDuration.push(t.Tools.Now);var e=this.previousFramesDuration.length;if(e>=2&&(this.deltaTime=this.previousFramesDuration[e-1]-this.previousFramesDuration[e-2]),e>=this.fpsRange){e>this.fpsRange&&(this.previousFramesDuration.splice(0,1),e=this.previousFramesDuration.length);for(var i=0,r=0;e-1>r;r++)i+=this.previousFramesDuration[r+1]-this.previousFramesDuration[r];this.fps=1e3/(i/(e-1))}},a.isSupported=function(){try{if(navigator.isCocoonJS)return!0;var t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");return null!=e&&!!window.WebGLRenderingContext}catch(i){return!1}},a._ALPHA_DISABLE=0,a._ALPHA_ADD=1,a._ALPHA_COMBINE=2,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=4,a._TEXTURETYPE_UNSIGNED_INT=0,a._TEXTURETYPE_FLOAT=1,a.Epsilon=.001,a.CollisionsEpsilon=.001,a.CodeRepository="Babylon/",a.ShadersRepository="Babylon/Shaders/",a}();t.Engine=l}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,e){this.state="",this.animations=new Array,this._childrenFlag=-1,this._isEnabled=!0,this._isReady=!0,this._currentRenderId=-1,this._parentRenderId=-1,this.name=t,this.id=t,this._scene=e,this._initCache()}return e.prototype.getScene=function(){return this._scene},e.prototype.getEngine=function(){return this._scene.getEngine()},e.prototype.getWorldMatrix=function(){return t.Matrix.Identity()},e.prototype._initCache=function(){this._cache={},this._cache.parent=void 0},e.prototype.updateCache=function(t){(t||!this.isSynchronized())&&(this._cache.parent=this.parent,this._updateCache())},e.prototype._updateCache=function(t){},e.prototype._isSynchronized=function(){return!0},e.prototype._markSyncedWithParent=function(){this._parentRenderId=this.parent._currentRenderId},e.prototype.isSynchronizedWithParent=function(){return this.parent?this._parentRenderId!==this.parent._currentRenderId?!1:this.parent.isSynchronized():!0},e.prototype.isSynchronized=function(t){var e=this.hasNewParent();return e=e||!this.isSynchronizedWithParent(),e=e||!this._isSynchronized(),t&&this.updateCache(!0),!e},e.prototype.hasNewParent=function(t){return this._cache.parent===this.parent?!1:(t&&(this._cache.parent=this.parent),!0)},e.prototype.isReady=function(){return this._isReady},e.prototype.isEnabled=function(){return this._isEnabled?this.parent?this.parent.isEnabled():!0:!1},e.prototype.setEnabled=function(t){this._isEnabled=t},e.prototype.isDescendantOf=function(t){return this.parent?this.parent===t?!0:this.parent.isDescendantOf(t):!1},e.prototype._getDescendants=function(t,e){for(var i=0;i<t.length;i++){var r=t[i];r.isDescendantOf(this)&&e.push(r)}},e.prototype.getDescendants=function(){var t=[];return this._getDescendants(this._scene.meshes,t),this._getDescendants(this._scene.lights,t),this._getDescendants(this._scene.cameras,t),t},e.prototype._setReady=function(t){if(t!=this._isReady){if(!t)return void(this._isReady=!1);this._isReady=!0,this.onReady&&this.onReady(this)}},e}();t.Node=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,e,i,r,n,o,s,a){this._engine=t,this._canvas=i,this._currentScene=e,this._sceneLoadedCallback=r,this._progressCallback=n,this._additionnalRenderLoopLogicCallback=o,this._textureLoadingCallback=s,this._startingProcessingFilesCallback=a}return e.prototype.monitorElementForDragNDrop=function(t){var e=this;t&&(this._elementToMonitor=t,this._elementToMonitor.addEventListener("dragenter",function(t){e.drag(t)},!1),this._elementToMonitor.addEventListener("dragover",function(t){e.drag(t)},!1),this._elementToMonitor.addEventListener("drop",function(t){e.drop(t)},!1))},e.prototype.renderFunction=function(){if(this._additionnalRenderLoopLogicCallback&&this._additionnalRenderLoopLogicCallback(),this._currentScene){if(this._textureLoadingCallback){var t=this._currentScene.getWaitingItemsCount();t>0&&this._textureLoadingCallback(t)}this._currentScene.render()}},e.prototype.drag=function(t){t.stopPropagation(),t.preventDefault()},e.prototype.drop=function(t){t.stopPropagation(),t.preventDefault(),this.loadFiles(t)},e.prototype.loadFiles=function(t){if(this._startingProcessingFilesCallback&&this._startingProcessingFilesCallback(),t&&t.dataTransfer&&t.dataTransfer.files&&(this._filesToLoad=t.dataTransfer.files),t&&t.target&&t.target.files&&(this._filesToLoad=t.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":e.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":e.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")&&(this._sceneFileToLoad=this._filesToLoad[i])}this.reload()}},e.prototype.reload=function(){var e=this,i=this;this._sceneFileToLoad?(this._currentScene&&(this._engine.stopRenderLoop(),this._currentScene.dispose()),t.SceneLoader.Load("file:",this._sceneFileToLoad,this._engine,function(t){i._currentScene=t,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(e._sceneFileToLoad,i._currentScene),i._engine.runRenderLoop(function(){i.renderFunction()})})},function(t){e._progressCallback&&e._progressCallback(t)})):t.Tools.Error("Please provide a valid .babylon file.")},e.FilesTextures=new Array,e.FilesToLoad=new Array,e}();t.FilesInput=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(t,e,i){this.bu=t,this.bv=e,this.distance=i,this.faceId=0,this.subMeshId=0}return t}();t.IntersectionInfo=e;var i=function(){function e(){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 e.prototype.getNormal=function(e){if(void 0===e&&(e=!1),!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(t.VertexBuffer.NormalKind))return null;var i=this.pickedMesh.getIndices(),r=this.pickedMesh.getVerticesData(t.VertexBuffer.NormalKind),n=t.Vector3.FromArray(r,3*i[3*this.faceId]),o=t.Vector3.FromArray(r,3*i[3*this.faceId+1]),s=t.Vector3.FromArray(r,3*i[3*this.faceId+2]);n=n.scale(this.bu),o=o.scale(this.bv),s=s.scale(1-this.bu-this.bv);var a=new t.Vector3(n.x+o.x+s.x,n.y+o.y+s.y,n.z+o.z+s.z);return e&&(a=t.Vector3.TransformNormal(a,this.pickedMesh.getWorldMatrix())),a},e.prototype.getTextureCoordinates=function(){if(!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(t.VertexBuffer.UVKind))return null;var e=this.pickedMesh.getIndices(),i=this.pickedMesh.getVerticesData(t.VertexBuffer.UVKind),r=t.Vector2.FromArray(i,2*e[3*this.faceId]),n=t.Vector2.FromArray(i,2*e[3*this.faceId+1]),o=t.Vector2.FromArray(i,2*e[3*this.faceId+2]);return r=r.scale(this.bu),n=n.scale(this.bv),o=o.scale(1-this.bu-this.bv),new t.Vector2(r.x+n.x+o.x,r.y+n.y+o.y)},e}();t.PickingInfo=i}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i){this.minimum=e,this.maximum=i,this._tempRadiusVector=t.Vector3.Zero();var r=t.Vector3.Distance(e,i);this.center=t.Vector3.Lerp(e,i,.5),this.radius=.5*r,this.centerWorld=t.Vector3.Zero(),this._update(t.Matrix.Identity())}return e.prototype._update=function(e){t.Vector3.TransformCoordinatesToRef(this.center,e,this.centerWorld),t.Vector3.TransformNormalFromFloatsToRef(1,1,1,e,this._tempRadiusVector),this.radiusWorld=Math.max(Math.abs(this._tempRadiusVector.x),Math.abs(this._tempRadiusVector.y),Math.abs(this._tempRadiusVector.z))*this.radius},e.prototype.isInFrustum=function(t){for(var e=0;6>e;e++)if(t[e].dotCoordinate(this.centerWorld)<=-this.radiusWorld)return!1;return!0},e.prototype.intersectsPoint=function(e){var i=this.centerWorld.x-e.x,r=this.centerWorld.y-e.y,n=this.centerWorld.z-e.z,o=Math.sqrt(i*i+r*r+n*n);return Math.abs(this.radiusWorld-o)<t.Engine.Epsilon?!1:!0},e.Intersects=function(t,e){var i=t.centerWorld.x-e.centerWorld.x,r=t.centerWorld.y-e.centerWorld.y,n=t.centerWorld.z-e.centerWorld.z,o=Math.sqrt(i*i+r*r+n*n);return t.radiusWorld+e.radiusWorld<o?!1:!0},e}();t.BoundingSphere=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i){this.minimum=e,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=[t.Vector3.Zero(),t.Vector3.Zero(),t.Vector3.Zero()];for(var r=0;r<this.vectors.length;r++)this.vectorsWorld[r]=t.Vector3.Zero();this.minimumWorld=t.Vector3.Zero(),this.maximumWorld=t.Vector3.Zero(),this._update(t.Matrix.Identity())}return e.prototype.getWorldMatrix=function(){return this._worldMatrix},e.prototype._update=function(e){t.Vector3.FromFloatsToRef(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,this.minimumWorld),t.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];t.Vector3.TransformCoordinatesToRef(this.vectors[i],e,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),t.Vector3.FromFloatArrayToRef(e.m,0,this.directions[0]),t.Vector3.FromFloatArrayToRef(e.m,4,this.directions[1]),t.Vector3.FromFloatArrayToRef(e.m,8,this.directions[2]),this._worldMatrix=e},e.prototype.isInFrustum=function(t){return e.IsInFrustum(this.vectorsWorld,t)},e.prototype.isCompletelyInFrustum=function(t){return e.IsCompletelyInFrustum(this.vectorsWorld,t)},e.prototype.intersectsPoint=function(e){var i=-t.Engine.Epsilon;return this.maximumWorld.x-e.x<i||i>e.x-this.minimumWorld.x?!1:this.maximumWorld.y-e.y<i||i>e.y-this.minimumWorld.y?!1:this.maximumWorld.z-e.z<i||i>e.z-this.minimumWorld.z?!1:!0},e.prototype.intersectsSphere=function(t){return e.IntersectsSphere(this.minimumWorld,this.maximumWorld,t.centerWorld,t.radiusWorld)},e.prototype.intersectsMinMax=function(t,e){return this.maximumWorld.x<t.x||this.minimumWorld.x>e.x?!1:this.maximumWorld.y<t.y||this.minimumWorld.y>e.y?!1:this.maximumWorld.z<t.z||this.minimumWorld.z>e.z?!1:!0},e.Intersects=function(t,e){return t.maximumWorld.x<e.minimumWorld.x||t.minimumWorld.x>e.maximumWorld.x?!1:t.maximumWorld.y<e.minimumWorld.y||t.minimumWorld.y>e.maximumWorld.y?!1:t.maximumWorld.z<e.minimumWorld.z||t.minimumWorld.z>e.maximumWorld.z?!1:!0},e.IntersectsSphere=function(e,i,r,n){var o=t.Vector3.Clamp(r,e,i),s=t.Vector3.DistanceSquared(r,o);return n*n>=s},e.IsCompletelyInFrustum=function(t,e){for(var i=0;6>i;i++)for(var r=0;8>r;r++)if(e[i].dotCoordinate(t[r])<0)return!1;return!0},e.IsInFrustum=function(t,e){for(var i=0;6>i;i++){for(var r=8,n=0;8>n&&e[i].dotCoordinate(t[n])<0;n++)--r;if(0===r)return!1}return!0},e}();t.BoundingBox=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(e,i){var r=t.Vector3.Dot(i.center,e),n=Math.abs(t.Vector3.Dot(i.directions[0],e))*i.extendSize.x,o=Math.abs(t.Vector3.Dot(i.directions[1],e))*i.extendSize.y,s=Math.abs(t.Vector3.Dot(i.directions[2],e))*i.extendSize.z,a=n+o+s;return{min:r-a,max:r+a}},i=function(t,e,i,r){return!(t>r||i>e)},r=function(t,r,n){var o=e(t,r),s=e(t,n);return i(o.min,o.max,s.min,s.max)},n=function(){function e(e,i){this.minimum=e,this.maximum=i,this.boundingBox=new t.BoundingBox(e,i),this.boundingSphere=new t.BoundingSphere(e,i)}return e.prototype._update=function(t){this.boundingBox._update(t),this.boundingSphere._update(t)},e.prototype.isInFrustum=function(t){return this.boundingSphere.isInFrustum(t)?this.boundingBox.isInFrustum(t):!1},e.prototype.isCompletelyInFrustum=function(t){return this.boundingBox.isCompletelyInFrustum(t)},e.prototype._checkCollision=function(t){return t._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld)},e.prototype.intersectsPoint=function(t){return this.boundingSphere.centerWorld&&this.boundingSphere.intersectsPoint(t)&&this.boundingBox.intersectsPoint(t)?!0:!1},e.prototype.intersects=function(e,i){if(!this.boundingSphere.centerWorld||!e.boundingSphere.centerWorld)return!1;if(!t.BoundingSphere.Intersects(this.boundingSphere,e.boundingSphere))return!1;if(!t.BoundingBox.Intersects(this.boundingBox,e.boundingBox))return!1;if(!i)return!0;var n=this.boundingBox,o=e.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(t.Vector3.Cross(n.directions[0],o.directions[0]),n,o)&&r(t.Vector3.Cross(n.directions[0],o.directions[1]),n,o)&&r(t.Vector3.Cross(n.directions[0],o.directions[2]),n,o)&&r(t.Vector3.Cross(n.directions[1],o.directions[0]),n,o)&&r(t.Vector3.Cross(n.directions[1],o.directions[1]),n,o)&&r(t.Vector3.Cross(n.directions[1],o.directions[2]),n,o)&&r(t.Vector3.Cross(n.directions[2],o.directions[0]),n,o)&&r(t.Vector3.Cross(n.directions[2],o.directions[1]),n,o)&&r(t.Vector3.Cross(n.directions[2],o.directions[2]),n,o)?!0:!1},e}();t.BoundingInfo=n}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(r,n){var o=this;e.call(this,r,n),this.definedFacingForward=!0,this.position=new t.Vector3(0,0,0),this.rotation=new t.Vector3(0,0,0),this.scaling=new t.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.checkCollisions=!1,this.isBlocker=!1,this.renderingGroupId=0,this.receiveShadows=!1,this.renderOutline=!1,this.outlineColor=t.Color3.Red(),this.outlineWidth=.02,this.renderOverlay=!1,this.overlayColor=t.Color3.Red(),this.overlayAlpha=.5,this.hasVertexAlpha=!1,this.useVertexColors=!0,this.applyFog=!0,this.useOctreeForRenderingSelection=!0,this.useOctreeForPicking=!0,this.useOctreeForCollisions=!0,this.layerMask=268435455,this.alwaysSelectAsActiveMesh=!1,this._physicImpostor=t.PhysicsEngine.NoImpostor,this.ellipsoid=new t.Vector3(.5,1,.5),this.ellipsoidOffset=new t.Vector3(0,0,0),this._collider=new t.Collider,this._oldPositionForCollisions=new t.Vector3(0,0,0),this._diffPositionForCollisions=new t.Vector3(0,0,0),this._newPositionForCollisions=new t.Vector3(0,0,0),this._localScaling=t.Matrix.Zero(),this._localRotation=t.Matrix.Zero(),this._localTranslation=t.Matrix.Zero(),this._localBillboard=t.Matrix.Zero(),this._localPivotScaling=t.Matrix.Zero(),this._localPivotScalingRotation=t.Matrix.Zero(),this._localWorld=t.Matrix.Zero(),this._worldMatrix=t.Matrix.Zero(),this._rotateYByPI=t.Matrix.RotationY(Math.PI),this._absolutePosition=t.Vector3.Zero(),this._collisionsTransformMatrix=t.Matrix.Zero(),this._collisionsScalingMatrix=t.Matrix.Zero(),this._isDirty=!1,this._pivotMatrix=t.Matrix.Identity(),this._isDisposed=!1,this._renderId=0,this._intersectionsInProgress=new Array,this._onAfterWorldMatrixUpdate=new Array,this._isWorldMatrixFrozen=!1,this._onCollisionPositionChange=function(e,i,r){void 0===r&&(r=null),(null!=e||void 0!=e)&&i.multiplyInPlace(o._collider.radius),i.subtractToRef(o._oldPositionForCollisions,o._diffPositionForCollisions),o._diffPositionForCollisions.length()>t.Engine.CollisionsEpsilon&&o.position.addInPlace(o._diffPositionForCollisions)},n.addMesh(this)}return __extends(i,e),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}),Object.defineProperty(i.prototype,"isBlocked",{get:function(){return!1},enumerable:!0,configurable:!0}),i.prototype.getLOD=function(t){return this},i.prototype.getTotalVertices=function(){return 0},i.prototype.getIndices=function(){return null},i.prototype.getVerticesData=function(t){return null},i.prototype.isVerticesDataPresent=function(t){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(t.VertexBuffer.MatricesIndicesKind)&&this.isVerticesDataPresent(t.VertexBuffer.MatricesWeightsKind)},enumerable:!0,configurable:!0}),i.prototype._preActivate=function(){},i.prototype._activate=function(t){this._renderId=t},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(e,i,r){if(this.rotationQuaternion||(this.rotationQuaternion=t.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=t.Vector3.Zero()),r&&0!==r){if(this.parent){var n=this.parent.getWorldMatrix().clone();n.invert(),e=t.Vector3.TransformNormal(e,n)}o=t.Quaternion.RotationAxis(e,i),this.rotationQuaternion=o.multiply(this.rotationQuaternion)}else{var o=t.Quaternion.RotationAxis(e,i);this.rotationQuaternion=this.rotationQuaternion.multiply(o)}},i.prototype.translate=function(t,e,i){var r=t.scale(e);if(i&&0!==i)this.setAbsolutePosition(this.getAbsolutePosition().add(r));else{var n=this.getPositionExpressedInLocalSpace().add(r);this.setPositionWithLocalVector(n)}},i.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},i.prototype.setAbsolutePosition=function(e){if(e){var i,r,n;if(void 0===e.x){if(arguments.length<3)return;i=arguments[0],r=arguments[1],n=arguments[2]}else i=e.x,r=e.y,n=e.z;if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert();var s=new t.Vector3(i,r,n);this.position=t.Vector3.TransformCoordinates(s,o)}else this.position.x=i,this.position.y=r,this.position.z=n}},i.prototype.movePOV=function(t,e,i){this.position.addInPlace(this.calcMovePOV(t,e,i))},i.prototype.calcMovePOV=function(e,i,r){var n=new t.Matrix,o=this.rotationQuaternion?this.rotationQuaternion:t.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z);o.toRotationMatrix(n);var s=t.Vector3.Zero(),a=this.definedFacingForward?-1:1;return t.Vector3.TransformCoordinatesFromFloatsToRef(e*a,i,r*a,n,s),s},i.prototype.rotatePOV=function(t,e,i){this.rotation.addInPlace(this.calcRotatePOV(t,e,i))},i.prototype.calcRotatePOV=function(e,i,r){var n=this.definedFacingForward?1:-1;return new t.Vector3(e*n,i,r*n)},i.prototype.setPivotMatrix=function(t){this._pivotMatrix=t,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(){e.prototype._initCache.call(this),this._cache.localMatrixUpdated=!1,this._cache.position=t.Vector3.Zero(),this._cache.scaling=t.Vector3.Zero(),this._cache.rotation=t.Vector3.Zero(),this._cache.rotationQuaternion=new t.Quaternion(0,0,0,0)},i.prototype.markAsDirty=function(t){"rotation"===t&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0},i.prototype._updateBoundingInfo=function(){this._boundingInfo=this._boundingInfo||new t.BoundingInfo(this.absolutePosition,this.absolutePosition),this._boundingInfo._update(this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)},i.prototype._updateSubMeshesBoundingInfo=function(t){if(this.subMeshes)for(var e=0;e<this.subMeshes.length;e++){var i=this.subMeshes[e];i.updateBoundingInfo(t)}},i.prototype.computeWorldMatrix=function(e){if(this._isWorldMatrixFrozen)return this._worldMatrix;if(!e&&(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,t.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)):(t.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,n=r.getWorldMatrix(),o=new t.Vector3(n.m[12],n.m[13],n.m[14]);t.Matrix.TranslationToRef(this.position.x+o.x,this.position.y+o.y,this.position.z+o.z,this._localTranslation)}else t.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),t.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+t.Engine.Epsilon),this.billboardMode&i.BILLBOARDMODE_Y&&(a.y=s.y+.001),this.billboardMode&i.BILLBOARDMODE_Z&&(a.z=s.z+.001)),t.Matrix.LookAtLHToRef(s,a,t.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._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(t){this._onAfterWorldMatrixUpdate.push(t)},i.prototype.unregisterAfterWorldMatrixUpdate=function(t){var e=this._onAfterWorldMatrixUpdate.indexOf(t);e>-1&&this._onAfterWorldMatrixUpdate.splice(e,1)},i.prototype.setPositionWithLocalVector=function(e){this.computeWorldMatrix(),this.position=t.Vector3.TransformNormal(e,this._localWorld)},i.prototype.getPositionExpressedInLocalSpace=function(){this.computeWorldMatrix();var e=this._localWorld.clone();return e.invert(),t.Vector3.TransformNormal(this.position,e)},i.prototype.locallyTranslate=function(e){this.computeWorldMatrix(),this.position=t.Vector3.TransformCoordinates(e,this._localWorld)},i.prototype.lookAt=function(e,i,r,n){i=i||0,r=r||0,n=n||0;var o=e.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=t.Quaternion.RotationYawPitchRoll(s+i,h+r,n)},i.prototype.isInFrustum=function(t){return this._boundingInfo.isInFrustum(t)?!0:!1},i.prototype.isCompletelyInFrustum=function(e){e||(e=this.getScene().activeCamera);var i=e.getViewMatrix().multiply(e.getProjectionMatrix());return this._boundingInfo.isCompletelyInFrustum(t.Frustum.GetPlanes(i))?!0:!1},i.prototype.intersectsMesh=function(t,e){return this._boundingInfo&&t._boundingInfo?this._boundingInfo.intersects(t._boundingInfo,e):!1},i.prototype.intersectsPoint=function(t){return this._boundingInfo?this._boundingInfo.intersectsPoint(t):!1},i.prototype.setPhysicsState=function(e,i){var r=this.getScene().getPhysicsEngine();if(r)return e=e||t.PhysicsEngine.NoImpostor,e.impostor&&(i=e,e=e.impostor),e===t.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=e,this._physicsMass=i.mass,this._physicsFriction=i.friction,this._physicRestitution=i.restitution,r._registerMesh(this,e,i))},i.prototype.getPhysicsImpostor=function(){return this._physicImpostor?this._physicImpostor:t.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(e){return e||(e=this.getScene().activeCamera),t.Vector3.TransformCoordinates(this.absolutePosition,e.getViewMatrix())},i.prototype.getDistanceToCamera=function(t){return t||(t=this.getScene().activeCamera),this.absolutePosition.subtract(t.position).length()},i.prototype.applyImpulse=function(t,e){this._physicImpostor&&this.getScene().getPhysicsEngine()._applyImpulse(this,t,e)},i.prototype.setPhysicsLinkWith=function(t,e,i,r){this._physicImpostor&&this.getScene().getPhysicsEngine()._createLink(this,t,e,i,r)},i.prototype.updatePhysicsBodyPosition=function(){this._physicImpostor&&this.getScene().getPhysicsEngine()._updateBodyPosition(this)},i.prototype.moveWithCollisions=function(t){var e=this.getAbsolutePosition();e.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPositionForCollisions),this._oldPositionForCollisions.addInPlace(this.ellipsoidOffset),this._collider.radius=this.ellipsoid,this.getScene().collisionCoordinator.getNewPosition(this._oldPositionForCollisions,t,this._collider,3,this,this._onCollisionPositionChange,this.uniqueId)},i.prototype.createOrUpdateSubmeshesOctree=function(e,i){void 0===e&&(e=64),void 0===i&&(i=2),this._submeshesOctree||(this._submeshesOctree=new t.Octree(t.Octree.CreationFuncForSubMeshes,e,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(e,i,r){if(this._generatePointsArray(),!e._lastColliderWorldVertices||!e._lastColliderTransformMatrix.equals(i)){e._lastColliderTransformMatrix=i.clone(),e._lastColliderWorldVertices=[],e._trianglePlanes=[];for(var n=e.verticesStart,o=e.verticesStart+e.verticesCount,s=n;o>s;s++)e._lastColliderWorldVertices.push(t.Vector3.TransformCoordinates(this._positions[s],i))}r._collide(e._trianglePlanes,e._lastColliderWorldVertices,this.getIndices(),e.indexStart,e.indexStart+e.indexCount,e.verticesStart,!!e.getMaterial()),r.collisionFound&&(r.collidedMesh=this)},i.prototype._processCollisionsForSubMeshes=function(t,e){var i,r;if(this._submeshesOctree&&this.useOctreeForCollisions){var n=t.velocityWorldLength+Math.max(t.radius.x,t.radius.y,t.radius.z),o=this._submeshesOctree.intersects(t.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(t)||this._collideForSubMesh(a,e,t)}},i.prototype._checkCollision=function(e){this._boundingInfo._checkCollision(e)&&(t.Matrix.ScalingToRef(1/e.radius.x,1/e.radius.y,1/e.radius.z,this._collisionsScalingMatrix),
- this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix),this._processCollisionsForSubMeshes(e,this._collisionsTransformMatrix))},i.prototype._generatePointsArray=function(){return!1},i.prototype.intersects=function(e,i){var r=new t.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&e.intersectsSphere(this._boundingInfo.boundingSphere)&&e.intersectsBox(this._boundingInfo.boundingBox)))return r;if(!this._generatePointsArray())return r;var n,o,s=null;if(this._submeshesOctree&&this.useOctreeForPicking){var a=t.Ray.Transform(e,this.getWorldMatrix()),h=this._submeshesOctree.intersectsRay(a);o=h.length,n=h.data}else n=this.subMeshes,o=n.length;for(var c=0;o>c;c++){var l=n[c];if(!(o>1)||l.canIntersects(e)){var u=l.intersects(e,this._positions,this.getIndices(),i);if(u&&(i||!s||u.distance<s.distance)&&(s=u,s.subMeshId=c,i))break}}if(s){var f=this.getWorldMatrix(),d=t.Vector3.TransformCoordinates(e.origin,f),p=e.direction.clone();p=p.scale(s.distance);var m=t.Vector3.TransformNormal(p,f),_=d.add(m);return r.hit=!0,r.distance=t.Vector3.Distance(d,_),r.pickedPoint=_,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(t,e,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(e){var i;for(this.getPhysicsImpostor()!==t.PhysicsEngine.NoImpostor&&this.setPhysicsState(t.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.releaseSubMeshes(),this.getScene().removeMesh(this),e)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}(t.Node);t.AbstractMesh=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r){e.call(this,i,r),this.diffuse=new t.Color3(1,1,1),this.specular=new t.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,e),i.prototype.getShadowGenerator=function(){return this._shadowGenerator},i.prototype.getAbsolutePosition=function(){return t.Vector3.Zero()},i.prototype.transferToEffect=function(t,e,i){},i.prototype._getWorldMatrix=function(){return t.Matrix.Identity()},i.prototype.canAffectMesh=function(t){return t?this.includedOnlyMeshes.length>0&&-1===this.includedOnlyMeshes.indexOf(t)?!1:this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(t)?!1:0!==this.includeOnlyWithLayerMask&&0===(this.includeOnlyWithLayerMask&t.layerMask)?!1:0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&t.layerMask?!1:!0:!0},i.prototype.getWorldMatrix=function(){this._currentRenderId=this.getScene().getRenderId();var e=this._getWorldMatrix();return this.parent&&this.parent.getWorldMatrix?(this._parentedWorldMatrix||(this._parentedWorldMatrix=t.Matrix.Identity()),e.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix),this._markSyncedWithParent(),this._parentedWorldMatrix):e},i.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().removeLight(this)},i}(t.Node);t.Light=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i,r){e.call(this,t,r),this.position=i}return __extends(i,e),i.prototype.getAbsolutePosition=function(){return this._transformedPosition?this._transformedPosition:this.position},i.prototype.transferToEffect=function(e,i){return this.parent&&this.parent.getWorldMatrix?(this._transformedPosition||(this._transformedPosition=t.Vector3.Zero()),t.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this._transformedPosition),void e.setFloat4(i,this._transformedPosition.x,this._transformedPosition.y,this._transformedPosition.z,0)):void e.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=t.Matrix.Identity()),t.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},i}(t.Light);t.PointLight=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i,r,n,o,s){e.call(this,t,s),this.position=i,this.direction=r,this.angle=n,this.exponent=o}return __extends(i,e),i.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},i.prototype.setShadowProjectionMatrix=function(e,i,r){var n=this.getScene().activeCamera;t.Matrix.PerspectiveFovLHToRef(this.angle,1,n.minZ,n.maxZ,e)},i.prototype.supportsVSM=function(){return!0},i.prototype.needRefreshPerFrame=function(){return!1},i.prototype.setDirectionToTarget=function(e){return this.direction=t.Vector3.Normalize(e.subtract(this.position)),this.direction},i.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=t.Vector3.Zero()),t.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},i.prototype.transferToEffect=function(e,i,r){var n;this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=t.Vector3.Zero()),this.computeTransformedPosition(),t.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),e.setFloat4(i,this.transformedPosition.x,this.transformedPosition.y,this.transformedPosition.z,this.exponent),n=t.Vector3.Normalize(this._transformedDirection)):(e.setFloat4(i,this.position.x,this.position.y,this.position.z,this.exponent),n=t.Vector3.Normalize(this.direction)),e.setFloat4(r,n.x,n.y,n.z,Math.cos(.5*this.angle))},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=t.Matrix.Identity()),t.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},i}(t.Light);t.SpotLight=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n){e.call(this,i,n),this.direction=r,this.groundColor=new t.Color3(0,0,0)}return __extends(i,e),i.prototype.setDirectionToTarget=function(e){return this.direction=t.Vector3.Normalize(e.subtract(t.Vector3.Zero())),this.direction},i.prototype.getShadowGenerator=function(){return null},i.prototype.transferToEffect=function(e,i,r){var n=t.Vector3.Normalize(this.direction);e.setFloat4(i,n.x,n.y,n.z,0),e.setColor3(r,this.groundColor.scale(this.intensity))},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=t.Matrix.Identity()),this._worldMatrix},i}(t.Light);t.HemisphericLight=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i,r){e.call(this,t,r),this.direction=i,this.shadowOrthoScale=.5,this.position=i.scale(-1)}return __extends(i,e),i.prototype.getAbsolutePosition=function(){return this.transformedPosition?this.transformedPosition:this.position},i.prototype.setDirectionToTarget=function(e){return this.direction=t.Vector3.Normalize(e.subtract(this.position)),this.direction},i.prototype.setShadowProjectionMatrix=function(e,i,r){for(var n=Number.MAX_VALUE,o=Number.MIN_VALUE,s=Number.MIN_VALUE,a=Number.MAX_VALUE,h=t.Vector3.Zero(),c=this.getScene().activeCamera,l=0;l<r.length;l++){var u=r[l];if(u){var f=u.getBoundingInfo();if(f)for(var d=f.boundingBox,p=0;p<d.vectorsWorld.length;p++)t.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,_=s-a;t.Matrix.OrthoOffCenterLHToRef(n-m*this.shadowOrthoScale,o+m*this.shadowOrthoScale,a-_*this.shadowOrthoScale,s+_*this.shadowOrthoScale,-c.maxZ,c.maxZ,e)},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=t.Vector3.Zero()),t.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},i.prototype.transferToEffect=function(e,i){return this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=t.Vector3.Zero()),t.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),void e.setFloat4(i,this._transformedDirection.x,this._transformedDirection.y,this._transformedDirection.z,1)):void e.setFloat4(i,this.direction.x,this.direction.y,this.direction.z,1)},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=t.Matrix.Identity()),t.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},i}(t.Light);t.DirectionalLight=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(i,r){var n=this;this._filter=e.FILTER_NONE,this.blurScale=2,this._blurBoxOffset=0,this._bias=5e-5,this._darkness=0,this._transparencyShadow=!1,this._viewMatrix=t.Matrix.Zero(),this._projectionMatrix=t.Matrix.Zero(),this._transformMatrix=t.Matrix.Zero(),this._worldViewProjection=t.Matrix.Zero(),this._light=r,this._scene=r.getScene(),this._mapSize=i,r._shadowGenerator=this,this._shadowMap=new t.RenderTargetTexture(r.name+"_shadowMap",i,this._scene,!1),this._shadowMap.wrapU=t.Texture.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=t.Texture.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(t.Texture.NEAREST_SAMPLINGMODE),this._shadowMap.renderParticles=!1,this._shadowMap.onAfterUnbind=function(){n.useBlurVarianceShadowMap&&(n._shadowMap2||(n._shadowMap2=new t.RenderTargetTexture(r.name+"_shadowMap",i,n._scene,!1),n._shadowMap2.wrapU=t.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.wrapV=t.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.updateSamplingMode(t.Texture.TRILINEAR_SAMPLINGMODE),n._downSamplePostprocess=new t.PassPostProcess("downScale",1/n.blurScale,null,t.Texture.BILINEAR_SAMPLINGMODE,n._scene.getEngine()),n._downSamplePostprocess.onApply=function(t){t.setTexture("textureSampler",n._shadowMap)},n.blurBoxOffset=1),n._scene.postProcessManager.directRender([n._downSamplePostprocess,n._boxBlurPostprocess],n._shadowMap2.getInternalTexture()))};var o=function(e){var i=e.getRenderingMesh(),r=n._scene,o=r.getEngine();o.setState(e.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(e._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[e._id];if(n.isReady(e,a)){o.enableEffect(n._effect),i._bind(e,n._effect,t.Material.TriangleFillMode);var h=e.getMaterial();if(n._effect.setMatrix("viewProjection",n.getTransformMatrix()),h&&h.needAlphaTesting()){var c=h.getAlphaTestTexture();n._effect.setTexture("diffuseSampler",c),n._effect.setMatrix("diffuseMatrix",c.getTextureMatrix())}i.useBones&&n._effect.setMatrices("mBones",i.skeleton.getTransformMatrices()),i._processRendering(e,n._effect,t.Material.TriangleFillMode,s,a,function(t,e){return n._effect.setMatrix("world",e)})}else n._shadowMap.resetRefreshCounter()}};this._shadowMap.customRenderFunction=function(t,e,i){var r;for(r=0;r<t.length;r++)o(t.data[r]);for(r=0;r<e.length;r++)o(e.data[r]);if(n._transparencyShadow)for(r=0;r<i.length;r++)o(i.data[r])},this._shadowMap.onClear=function(e){n.useBlurVarianceShadowMap||n.useVarianceShadowMap?e.clear(new t.Color4(0,0,0,0),!0,!0):e.clear(new t.Color4(1,1,1,1),!0,!0)}}return Object.defineProperty(e,"FILTER_NONE",{get:function(){return e._FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FILTER_VARIANCESHADOWMAP",{get:function(){return e._FILTER_VARIANCESHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FILTER_POISSONSAMPLING",{get:function(){return e._FILTER_POISSONSAMPLING},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FILTER_BLURVARIANCESHADOWMAP",{get:function(){return e._FILTER_BLURVARIANCESHADOWMAP},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bias",{get:function(){return this._bias},set:function(t){this._bias=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"blurBoxOffset",{get:function(){return this._blurBoxOffset},set:function(e){var i=this;this._blurBoxOffset!==e&&(this._blurBoxOffset=e,this._boxBlurPostprocess&&this._boxBlurPostprocess.dispose(),this._boxBlurPostprocess=new t.PostProcess("DepthBoxBlur","depthBoxBlur",["screenSize","boxOffset"],[],1/this.blurScale,null,t.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1,"#define OFFSET "+e),this._boxBlurPostprocess.onApply=function(t){t.setFloat2("screenSize",i._mapSize/i.blurScale,i._mapSize/i.blurScale)})},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"filter",{get:function(){return this._filter},set:function(e){this._filter!==e&&(this._filter=e,this.useVarianceShadowMap||this.useBlurVarianceShadowMap?(this._shadowMap.anisotropicFilteringLevel=16,this._shadowMap.updateSamplingMode(t.Texture.BILINEAR_SAMPLINGMODE)):(this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(t.Texture.NEAREST_SAMPLINGMODE)))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useVarianceShadowMap",{get:function(){return this.filter===e.FILTER_VARIANCESHADOWMAP&&this._light.supportsVSM()},set:function(t){this.filter=t?e.FILTER_VARIANCESHADOWMAP:e.FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"usePoissonSampling",{get:function(){return this.filter===e.FILTER_POISSONSAMPLING||!this._light.supportsVSM()&&(this.filter===e.FILTER_VARIANCESHADOWMAP||this.filter===e.FILTER_BLURVARIANCESHADOWMAP)},set:function(t){this.filter=t?e.FILTER_POISSONSAMPLING:e.FILTER_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useBlurVarianceShadowMap",{get:function(){return this.filter===e.FILTER_BLURVARIANCESHADOWMAP&&this._light.supportsVSM()},set:function(t){this.filter=t?e.FILTER_BLURVARIANCESHADOWMAP:e.FILTER_NONE},enumerable:!0,configurable:!0}),e.prototype.isReady=function(e,i){var r=[];(this.useVarianceShadowMap||this.useBlurVarianceShadowMap)&&r.push("#define VSM");var n=[t.VertexBuffer.PositionKind],o=e.getMesh(),s=e.getMaterial();s&&s.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(t.VertexBuffer.UVKind)&&(n.push(t.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(t.VertexBuffer.UV2Kind)&&(n.push(t.VertexBuffer.UV2Kind),r.push("#define UV2"))),o.useBones&&(n.push(t.VertexBuffer.MatricesIndicesKind),n.push(t.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()},e.prototype.getShadowMap=function(){return this._shadowMap},e.prototype.getShadowMapForRendering=function(){return this._shadowMap2?this._shadowMap2:this._shadowMap},e.prototype.getLight=function(){return this._light},e.prototype.getTransformMatrix=function(){var e=this._scene;if(this._currentRenderID===e.getRenderId())return this._transformMatrix;this._currentRenderID=e.getRenderId();var i=this._light.position,r=this._light.direction;return this._light.computeTransformedPosition()&&(i=this._light.transformedPosition),!this._light.needRefreshPerFrame()&&this._cachedPosition&&this._cachedDirection&&i.equals(this._cachedPosition)&&r.equals(this._cachedDirection)||(this._cachedPosition=i.clone(),this._cachedDirection=r.clone(),t.Matrix.LookAtLHToRef(i,this._light.position.add(r),t.Vector3.Up(),this._viewMatrix),this._light.setShadowProjectionMatrix(this._projectionMatrix,this._viewMatrix,this.getShadowMap().renderList),this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)),this._transformMatrix},e.prototype.getDarkness=function(){return this._darkness},e.prototype.setDarkness=function(t){this._darkness=t>=1?1:0>=t?0:t},e.prototype.setTransparencyShadow=function(t){this._transparencyShadow=t},e.prototype._packHalf=function(e){var i=255*e,r=i-Math.floor(i);return new t.Vector2(e-r/255,r)},e.prototype.dispose=function(){this._shadowMap.dispose(),this._shadowMap2&&this._shadowMap2.dispose(),this._downSamplePostprocess&&this._downSamplePostprocess.dispose(),this._boxBlurPostprocess&&this._boxBlurPostprocess.dispose()},e._FILTER_NONE=0,e._FILTER_VARIANCESHADOWMAP=1,e._FILTER_POISSONSAMPLING=2,e._FILTER_BLURVARIANCESHADOWMAP=3,e}();t.ShadowGenerator=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(t,e,i,r){return t.x>i.x+r?!1:i.x-r>e.x?!1:t.y>i.y+r?!1:i.y-r>e.y?!1:t.z>i.z+r?!1:i.z-r>e.z?!1:!0},i=function(t,e,i,r){var n=e*e-4*t*i,o={root:0,found:!1};if(0>n)return o;var s=Math.sqrt(n),a=(-e-s)/(2*t),h=(-e+s)/(2*t);if(a>h){var c=h;h=a,a=c}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 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 r.prototype._initialize=function(e,i,r){this.velocity=i,t.Vector3.NormalizeToRef(i,this.normalizedVelocity),this.basePoint=e,e.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(e,i,r,n,o){i.subtractToRef(e,this._tempVector),r.subtractToRef(e,this._tempVector2),t.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var s=t.Vector3.Dot(this._tempVector4,o);return 0>s?!1:(n.subtractToRef(e,this._tempVector3),t.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),s=t.Vector3.Dot(this._tempVector4,o),0>s?!1:(t.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),s=t.Vector3.Dot(this._tempVector4,o),s>=0))},r.prototype._canDoCollision=function(i,r,n,o){var s=t.Vector3.Distance(this.basePointWorld,i),a=Math.max(this.radius.x,this.radius.y,this.radius.z);return s>this.velocityWorldLength+a+r?!1:e(n,o,this.basePointWorld,this.velocityWorldLength+a)?!0:!1},r.prototype._testTriangle=function(e,r,n,o,s,a){var h,c=!1;r||(r=[]),r[e]||(r[e]=new t.Plane(0,0,0,0),r[e].copyFromPoints(n,o,s));var l=r[e];if(a||l.isFrontFacingTo(this.normalizedVelocity,0)){var u=l.signedDistanceTo(this.basePoint),f=t.Vector3.Dot(l.normal,this.velocity);if(0==f){if(Math.abs(u)>=1)return;c=!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,_=1;if(c||(this.basePoint.subtractToRef(l.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,n,o,s,l.normal)&&(m=!0,_=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!m){var g=this.velocity.lengthSquared(),v=g;this.basePoint.subtractToRef(n,this._tempVector);var y=2*t.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,_);b.found&&(_=b.root,m=!0,this._collisionPoint.copyFrom(n)),this.basePoint.subtractToRef(o,this._tempVector),y=2*t.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,_),b.found&&(_=b.root,m=!0,this._collisionPoint.copyFrom(o)),this.basePoint.subtractToRef(s,this._tempVector),y=2*t.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,_),b.found&&(_=b.root,m=!0,this._collisionPoint.copyFrom(s)),o.subtractToRef(n,this._edge),n.subtractToRef(this.basePoint,this._baseToVertex);var M=this._edge.lengthSquared(),T=t.Vector3.Dot(this._edge,this.velocity),S=t.Vector3.Dot(this._edge,this._baseToVertex);if(v=M*-g+T*T,y=2*M*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*T*S,x=M*(1-this._baseToVertex.lengthSquared())+S*S,b=i(v,y,x,_),b.found){var A=(T*b.root-S)/M;A>=0&&1>=A&&(_=b.root,m=!0,this._edge.scaleInPlace(A),n.addToRef(this._edge,this._collisionPoint))}s.subtractToRef(o,this._edge),o.subtractToRef(this.basePoint,this._baseToVertex),M=this._edge.lengthSquared(),T=t.Vector3.Dot(this._edge,this.velocity),S=t.Vector3.Dot(this._edge,this._baseToVertex),v=M*-g+T*T,y=2*M*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*T*S,x=M*(1-this._baseToVertex.lengthSquared())+S*S,b=i(v,y,x,_),b.found&&(A=(T*b.root-S)/M,A>=0&&1>=A&&(_=b.root,m=!0,this._edge.scaleInPlace(A),o.addToRef(this._edge,this._collisionPoint))),n.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex),M=this._edge.lengthSquared(),T=t.Vector3.Dot(this._edge,this.velocity),S=t.Vector3.Dot(this._edge,this._baseToVertex),v=M*-g+T*T,y=2*M*t.Vector3.Dot(this.velocity,this._baseToVertex)-2*T*S,x=M*(1-this._baseToVertex.lengthSquared())+S*S,b=i(v,y,x,_),b.found&&(A=(T*b.root-S)/M,A>=0&&1>=A&&(_=b.root,m=!0,this._edge.scaleInPlace(A),s.addToRef(this._edge,this._collisionPoint)))}if(m){var w=_*this.velocity.length();(!this.collisionFound||w<this.nearestDistance)&&(this.intersectionPoint?this.intersectionPoint.copyFrom(this._collisionPoint):this.intersectionPoint=this._collisionPoint.clone(),this.nearestDistance=w,this.collisionFound=!0)}}},r.prototype._collide=function(t,e,i,r,n,o,s){for(var a=r;n>a;a+=3){var h=e[i[a]-o],c=e[i[a+1]-o],l=e[i[a+2]-o];this._testTriangle(a,t,l,c,h,s)}},r.prototype._getResponse=function(e,i){e.addToRef(i,this._destinationPoint),i.scaleInPlace(this.nearestDistance/i.length()),this.basePoint.addToRef(i,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,i)},r}();t.Collider=r}(BABYLON||(BABYLON={}));var BABYLON;!function(t){t.CollisionWorker="",function(t){t[t.INIT=0]="INIT",t[t.UPDATE=1]="UPDATE",t[t.COLLIDE=2]="COLLIDE"}(t.WorkerTaskType||(t.WorkerTaskType={}));t.WorkerTaskType;!function(t){t[t.SUCCESS=0]="SUCCESS",t[t.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(t.WorkerReplyType||(t.WorkerReplyType={}));var e=(t.WorkerReplyType,function(){function e(){var i=this;this._scaledPosition=t.Vector3.Zero(),this._scaledVelocity=t.Vector3.Zero(),this.onMeshUpdated=function(t){i._addUpdateMeshesList[t.uniqueId]=e.SerializeMesh(t)},this.onGeometryUpdated=function(t){i._addUpdateGeometriesList[t.id]=e.SerializeGeometry(t)},this._afterRender=function(){if(i._init&&!(0==i._toRemoveGeometryArray.length&&0==i._toRemoveMeshesArray.length&&0==Object.keys(i._addUpdateGeometriesList).length&&0==Object.keys(i._addUpdateMeshesList).length||i._runningUpdated>4)){++i._runningUpdated;var t={updatedMeshes:i._addUpdateMeshesList,updatedGeometries:i._addUpdateGeometriesList,removedGeometries:i._toRemoveGeometryArray,removedMeshes:i._toRemoveMeshesArray},e={payload:t,taskType:1},r=[];for(var n in t.updatedGeometries)t.updatedGeometries.hasOwnProperty(n)&&(r.push(e.payload.updatedGeometries[n].indices.buffer),r.push(e.payload.updatedGeometries[n].normals.buffer),r.push(e.payload.updatedGeometries[n].positions.buffer));i._worker.postMessage(e,r),i._addUpdateMeshesList={},i._addUpdateGeometriesList={},i._toRemoveGeometryArray=[],i._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(e){var r=e.data;if(0!=r.error)return void t.Tools.Warn("error returned from worker!");switch(r.taskType){case 0:i._init=!0,i._scene.meshes.forEach(function(t){i.onMeshAdded(t)}),i._scene.getGeometries().forEach(function(t){i.onGeometryAdded(t)});break;case 1:i._runningUpdated--;break;case 2:i._runningCollisionTask=!1;var n=r.payload;if(!i._collisionsCallbackArray[n.collisionId])return;i._collisionsCallbackArray[n.collisionId](n.collisionId,t.Vector3.FromArray(n.newPosition),i._scene.getMeshByUniqueID(n.collidedMeshUniqueId)),i._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 e.prototype.getNewPosition=function(t,e,i,r,n,o,s){if(!this._init,!this._collisionsCallbackArray[s]){t.divideToRef(i.radius,this._scaledPosition),e.divideToRef(i.radius,this._scaledVelocity),this._collisionsCallbackArray[s]=o;var a={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:i.radius.asArray()},collisionId:s,excludedMeshUniqueId:n?n.uniqueId:null,maximumRetry:r},h={payload:a,taskType:2};this._worker.postMessage(h)}},e.prototype.init=function(e){this._scene=e,this._scene.registerAfterRender(this._afterRender);var i=t.WorkerIncluded?t.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([t.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(i),this._worker.onmessage=this._onMessageFromWorker;var r={payload:{},taskType:0};this._worker.postMessage(r)},e.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},e.prototype.onMeshAdded=function(t){t.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(t)},e.prototype.onMeshRemoved=function(t){this._toRemoveMeshesArray.push(t.uniqueId)},e.prototype.onGeometryAdded=function(t){t.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(t)},e.prototype.onGeometryDeleted=function(t){this._toRemoveGeometryArray.push(t.id)},e.SerializeMesh=function(t){var e=[];t.subMeshes&&(e=t.subMeshes.map(function(t,e){return{position:e,verticesStart:t.verticesStart,verticesCount:t.verticesCount,indexStart:t.indexStart,indexCount:t.indexCount,hasMaterial:!!t.getMaterial(),sphereCenter:t.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:t.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:t.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:t.getBoundingInfo().boundingBox.maximumWorld.asArray()}}));var i=t.geometry?t.geometry.id:null;return{uniqueId:t.uniqueId,id:t.id,name:t.name,geometryId:i,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:e,checkCollisions:t.checkCollisions}},e.SerializeGeometry=function(e){return{id:e.id,positions:new Float32Array(e.getVerticesData(t.VertexBuffer.PositionKind)||[]),normals:new Float32Array(e.getVerticesData(t.VertexBuffer.NormalKind)||[]),indices:new Int32Array(e.getIndices()||[])}},e}());t.CollisionCoordinatorWorker=e;var i=function(){function e(){this._scaledPosition=t.Vector3.Zero(),this._scaledVelocity=t.Vector3.Zero(),this._finalPosition=t.Vector3.Zero()}return e.prototype.getNewPosition=function(t,e,i,r,n,o,s){t.divideToRef(i.radius,this._scaledPosition),e.divideToRef(i.radius,this._scaledVelocity),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(null,this._finalPosition,i.collidedMesh)},e.prototype.init=function(t){this._scene=t},e.prototype.destroy=function(){},e.prototype.onMeshAdded=function(t){},e.prototype.onMeshUpdated=function(t){},e.prototype.onMeshRemoved=function(t){},e.prototype.onGeometryAdded=function(t){},e.prototype.onGeometryUpdated=function(t){},e.prototype.onGeometryDeleted=function(t){},e.prototype._collideWithWorld=function(e,i,r,n,o,s){void 0===s&&(s=null);var a=10*t.Engine.CollisionsEpsilon;if(r.retry>=n)return void o.copyFrom(e);r._initialize(e,i,a);for(var h=0;h<this._scene.meshes.length;h++){var c=this._scene.meshes[h];c.isEnabled()&&c.checkCollisions&&c.subMeshes&&c!==s&&c._checkCollision(r)}return r.collisionFound?((0!==i.x||0!==i.y||0!==i.z)&&r._getResponse(e,i),i.length()<=a?void o.copyFrom(e):(r.retry++,void this._collideWithWorld(e,i,r,n,o,s))):void e.addToRef(i,o)},e}();t.CollisionCoordinatorLegacy=i}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(r,n,o){e.call(this,r,o),this.position=n,this.upVector=t.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=i.PERSPECTIVE_CAMERA,this.isIntermediate=!1,this.viewport=new t.Viewport(0,0,1,1),this.subCameras=[],this.layerMask=4294967295,this.fovMode=i.FOVMODE_VERTICAL_FIXED,this._computedViewMatrix=t.Matrix.Identity(),this._projectionMatrix=new t.Matrix,this._postProcesses=new Array,this._postProcessesTakenIndices=[],this._activeMeshes=new t.SmartArray(256),this._globalPosition=t.Vector3.Zero(),o.addCamera(this),o.activeCamera||(o.activeCamera=this)}return __extends(i,e),Object.defineProperty(i,"PERSPECTIVE_CAMERA",{get:function(){return i._PERSPECTIVE_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(i,"ORTHOGRAPHIC_CAMERA",{get:function(){return i._ORTHOGRAPHIC_CAMERA},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOVMODE_VERTICAL_FIXED",{
- get:function(){return i._FOVMODE_VERTICAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(i,"FOVMODE_HORIZONTAL_FIXED",{get:function(){return i._FOVMODE_HORIZONTAL_FIXED},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"globalPosition",{get:function(){return this._globalPosition},enumerable:!0,configurable:!0}),i.prototype.getActiveMeshes=function(){return this._activeMeshes},i.prototype.isActiveMesh=function(t){return-1!==this._activeMeshes.indexOf(t)},i.prototype._initCache=function(){e.prototype._initCache.call(this),this._cache.position=new t.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.upVector=new t.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},i.prototype._updateCache=function(t){t||e.prototype._updateCache.call(this);var i=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=i.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=i.getRenderWidth(),this._cache.renderHeight=i.getRenderHeight()},i.prototype._updateFromScene=function(){this.updateCache(),this._update()},i.prototype._isSynchronized=function(){return this._isSynchronizedViewMatrix()&&this._isSynchronizedProjectionMatrix()},i.prototype._isSynchronizedViewMatrix=function(){return e.prototype._isSynchronized.call(this)?this._cache.position.equals(this.position)&&this._cache.upVector.equals(this.upVector)&&this.isSynchronizedWithParent():!1},i.prototype._isSynchronizedProjectionMatrix=function(){var t=this._cache.mode===this.mode&&this._cache.minZ===this.minZ&&this._cache.maxZ===this.maxZ;if(!t)return!1;var e=this.getEngine();return t=this.mode===i.PERSPECTIVE_CAMERA?this._cache.fov===this.fov&&this._cache.aspectRatio===e.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===e.getRenderWidth()&&this._cache.renderHeight===e.getRenderHeight()},i.prototype.attachControl=function(t){},i.prototype.detachControl=function(t){},i.prototype._update=function(){},i.prototype.attachPostProcess=function(e,i){if(void 0===i&&(i=null),!e.isReusable()&&this._postProcesses.indexOf(e)>-1)return t.Tools.Error("You're trying to reuse a post process not defined as reusable."),0;if(null==i||0>i)return this._postProcesses.push(e),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]=e,a},i.prototype.detachPostProcess=function(t,e){void 0===e&&(e=null);var i=[];if(e)for(e=e instanceof Array?e:[e],o=0;o<e.length;o++){var r=this._postProcesses[e[o]];r===t?(delete this._postProcesses[e[o]],s=this._postProcessesTakenIndices.indexOf(e[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]===t){delete this._postProcesses[o];var s=this._postProcessesTakenIndices.indexOf(o);this._postProcessesTakenIndices.splice(s,1)}return i},i.prototype.getWorldMatrix=function(){this._worldMatrix||(this._worldMatrix=t.Matrix.Identity());var e=this.getViewMatrix();return e.invertToRef(this._worldMatrix),this._worldMatrix},i.prototype._getViewMatrix=function(){return t.Matrix.Identity()},i.prototype.getViewMatrix=function(e){return this._computedViewMatrix=this._computeViewMatrix(e),!e&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this.parent&&this.parent.getWorldMatrix?(this._worldMatrix||(this._worldMatrix=t.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)},i.prototype._computeViewMatrix=function(t){return!t&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this._computedViewMatrix=this._getViewMatrix(),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype.getProjectionMatrix=function(e){if(!e&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;var r=this.getEngine();if(this.mode===i.PERSPECTIVE_CAMERA)return this.minZ<=0&&(this.minZ=.1),t.Matrix.PerspectiveFovLHToRef(this.fov,r.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode),this._projectionMatrix;var n=r.getRenderWidth()/2,o=r.getRenderHeight()/2;return t.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-n,this.orthoRight||n,this.orthoBottom||-o,this.orthoTop||o,this.minZ,this.maxZ,this._projectionMatrix),this._projectionMatrix},i.prototype.dispose=function(){this.getScene().removeCamera(this);for(var t=0;t<this._postProcessesTakenIndices.length;++t)this._postProcesses[this._postProcessesTakenIndices[t]].dispose(this)},i._PERSPECTIVE_CAMERA=0,i._ORTHOGRAPHIC_CAMERA=1,i._FOVMODE_VERTICAL_FIXED=0,i._FOVMODE_HORIZONTAL_FIXED=1,i}(t.Node);t.Camera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n){e.call(this,i,r,n),this.cameraDirection=new t.Vector3(0,0,0),this.cameraRotation=new t.Vector2(0,0),this.rotation=new t.Vector3(0,0,0),this.speed=2,this.noRotationConstraint=!1,this.lockedTarget=null,this._currentTarget=t.Vector3.Zero(),this._viewMatrix=t.Matrix.Zero(),this._camMatrix=t.Matrix.Zero(),this._cameraTransformMatrix=t.Matrix.Zero(),this._cameraRotationMatrix=t.Matrix.Zero(),this._referencePoint=new t.Vector3(0,0,1),this._transformedReferencePoint=t.Vector3.Zero(),this._lookAtTemp=t.Matrix.Zero(),this._tempMatrix=t.Matrix.Zero()}return __extends(i,e),i.prototype._getLockedTargetPosition=function(){return this.lockedTarget?this.lockedTarget.position||this.lockedTarget:null},i.prototype._initCache=function(){e.prototype._initCache.call(this),this._cache.lockedTarget=new t.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotation=new t.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},i.prototype._updateCache=function(t){t||e.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(!e.prototype._isSynchronizedViewMatrix.call(this))return!1;var t=this._getLockedTargetPosition();return(this._cache.lockedTarget?this._cache.lockedTarget.equals(t):!t)&&this._cache.rotation.equals(this.rotation)},i.prototype._computeLocalCameraSpeed=function(){var t=this.getEngine();return this.speed*(t.getDeltaTime()/(10*t.getFps()))},i.prototype.setTarget=function(e){this.upVector.normalize(),t.Matrix.LookAtLHToRef(this.position,e,this.upVector,this._camMatrix),this._camMatrix.invert(),this.rotation.x=Math.atan(this._camMatrix.m[6]/this._camMatrix.m[10]);var i=e.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(t.Vector3.Dot(new t.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._update=function(){var e=this._decideIfNeedsToMove(),i=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(e&&this._updatePosition(),i&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,!this.noRotationConstraint)){var r=Math.PI/2*.95;this.rotation.x>r&&(this.rotation.x=r),this.rotation.x<-r&&(this.rotation.x=-r)}e&&(Math.abs(this.cameraDirection.x)<t.Engine.Epsilon&&(this.cameraDirection.x=0),Math.abs(this.cameraDirection.y)<t.Engine.Epsilon&&(this.cameraDirection.y=0),Math.abs(this.cameraDirection.z)<t.Engine.Epsilon&&(this.cameraDirection.z=0),this.cameraDirection.scaleInPlace(this.inertia)),i&&(Math.abs(this.cameraRotation.x)<t.Engine.Epsilon&&(this.cameraRotation.x=0),Math.abs(this.cameraRotation.y)<t.Engine.Epsilon&&(this.cameraRotation.y=0),this.cameraRotation.scaleInPlace(this.inertia))},i.prototype._getViewMatrix=function(){return this.lockedTarget?this._currentTarget.copyFrom(this._getLockedTargetPosition()):(0!==this.upVector.x||1!==this.upVector.y||0!==this.upVector.z?(t.Matrix.LookAtLHToRef(t.Vector3.Zero(),this._referencePoint,this.upVector,this._lookAtTemp),t.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)):t.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),t.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),this.position.addToRef(this._transformedReferencePoint,this._currentTarget)),t.Matrix.LookAtLHToRef(this.position,this._currentTarget,this.upVector,this._viewMatrix),this._viewMatrix},i}(t.Camera);t.TargetCamera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n){var o=this;e.call(this,i,r,n),this.ellipsoid=new t.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 t.Collider,this._needMoveForGravity=!0,this._oldPosition=t.Vector3.Zero(),this._diffPosition=t.Vector3.Zero(),this._newPosition=t.Vector3.Zero(),this._onCollisionPositionChange=function(e,i,r){void 0===r&&(r=null),(null!=e||void 0!=e)&&i.multiplyInPlace(o._collider.radius),o._newPosition.copyFrom(i),o._newPosition.subtractToRef(o._oldPosition,o._diffPosition);var n=o.position.clone();o._diffPosition.length()>t.Engine.CollisionsEpsilon&&(o.position.addInPlace(o._diffPosition),o.onCollide&&r&&o.onCollide(r)),e!=o.uniqueId&&(o._needMoveForGravity=0!=t.Vector3.DistanceSquared(n,o.position))}}return __extends(i,e),i.prototype.attachControl=function(e,i){var r,n=this,o=this.getEngine();this._attachedElement||(this._attachedElement=e,void 0===this._onMouseDown&&(this._onMouseDown=function(t){r={x:t.clientX,y:t.clientY},i||t.preventDefault()},this._onMouseUp=function(t){r=null,i||t.preventDefault()},this._onMouseOut=function(t){r=null,n._keys=[],i||t.preventDefault()},this._onMouseMove=function(t){if(r||o.isPointerLock){var e,s;o.isPointerLock?(e=t.movementX||t.mozMovementX||t.webkitMovementX||t.msMovementX||0,s=t.movementY||t.mozMovementY||t.webkitMovementY||t.msMovementY||0):(e=t.clientX-r.x,s=t.clientY-r.y),n.cameraRotation.y+=e/n.angularSensibility,n.cameraRotation.x+=s/n.angularSensibility,r={x:t.clientX,y:t.clientY},i||t.preventDefault()}},this._onKeyDown=function(t){if(-1!==n.keysUp.indexOf(t.keyCode)||-1!==n.keysDown.indexOf(t.keyCode)||-1!==n.keysLeft.indexOf(t.keyCode)||-1!==n.keysRight.indexOf(t.keyCode)){var e=n._keys.indexOf(t.keyCode);-1===e&&n._keys.push(t.keyCode),i||t.preventDefault()}},this._onKeyUp=function(t){if(-1!==n.keysUp.indexOf(t.keyCode)||-1!==n.keysDown.indexOf(t.keyCode)||-1!==n.keysLeft.indexOf(t.keyCode)||-1!==n.keysRight.indexOf(t.keyCode)){var e=n._keys.indexOf(t.keyCode);e>=0&&n._keys.splice(e,1),i||t.preventDefault()}},this._onLostFocus=function(){n._keys=[]},this._reset=function(){n._keys=[],r=null,n.cameraDirection=new t.Vector3(0,0,0),n.cameraRotation=new t.Vector2(0,0)}),e.addEventListener("mousedown",this._onMouseDown,!1),e.addEventListener("mouseup",this._onMouseUp,!1),e.addEventListener("mouseout",this._onMouseOut,!1),e.addEventListener("mousemove",this._onMouseMove,!1),t.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]))},i.prototype.detachControl=function(e){this._attachedElement==e&&(e.removeEventListener("mousedown",this._onMouseDown),e.removeEventListener("mouseup",this._onMouseUp),e.removeEventListener("mouseout",this._onMouseOut),e.removeEventListener("mousemove",this._onMouseMove),t.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(e,i){void 0===i&&(i=!1);var r;r=this.parent?t.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,r.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._collider.radius=this.ellipsoid,this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,e,this._collider,3,null,this._onCollisionPositionChange,e.equals(this.getScene().gravity)?this.uniqueId+1e5:this.uniqueId)},i.prototype._checkInputs=function(){this._localDirection||(this._localDirection=t.Vector3.Zero(),this._transformedDirection=t.Vector3.Zero());for(var e=0;e<this._keys.length;e++){var i=this._keys[e],r=this._computeLocalCameraSpeed();-1!==this.keysLeft.indexOf(i)?this._localDirection.copyFromFloats(-r,0,0):-1!==this.keysUp.indexOf(i)?this._localDirection.copyFromFloats(0,0,r):-1!==this.keysRight.indexOf(i)?this._localDirection.copyFromFloats(r,0,0):-1!==this.keysDown.indexOf(i)&&this._localDirection.copyFromFloats(0,0,-r),this.getViewMatrix().invertToRef(this._cameraTransformMatrix),t.Vector3.TransformNormalToRef(this._localDirection,this._cameraTransformMatrix,this._transformedDirection),this.cameraDirection.addInPlace(this._transformedDirection)}},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,!1),this.applyGravity&&this._collideWithWorld(this.getScene().gravity,!0)):this.position.addInPlace(this.cameraDirection)},i.prototype._update=function(){this._checkInputs(),e.prototype._update.call(this)},i}(t.TargetCamera);t.FreeCamera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i,r){e.call(this,t,i,r),this.radius=12,this.rotationOffset=0,this.heightOffset=4,this.cameraAcceleration=.05,this.maxCameraSpeed=20}return __extends(i,e),i.prototype.getRadians=function(t){return t*Math.PI/180},i.prototype.follow=function(e){if(e){var i;if(e.rotationQuaternion){var r=new t.Matrix;e.rotationQuaternion.toRotationMatrix(r),i=Math.atan2(r.m[8],r.m[10])}else i=e.rotation.y;var n=this.getRadians(this.rotationOffset)+i,o=e.position.x+Math.sin(n)*this.radius,s=e.position.z+Math.cos(n)*this.radius,a=o-this.position.x,h=e.position.y+this.heightOffset-this.position.y,c=s-this.position.z,l=a*this.cameraAcceleration*2,u=h*this.cameraAcceleration,f=c*this.cameraAcceleration*2;(l>this.maxCameraSpeed||l<-this.maxCameraSpeed)&&(l=1>l?-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 t.Vector3(this.position.x+l,this.position.y+u,this.position.z+f),this.setTarget(e.position)}},i.prototype._update=function(){e.prototype._update.call(this),this.follow(this.target)},i}(t.TargetCamera);t.FollowCamera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i,r){e.call(this,t,i,r),this._offsetX=null,this._offsetY=null,this._pointerCount=0,this._pointerPressed=[],this.angularSensibility=2e5,this.moveSensibility=500}return __extends(i,e),i.prototype.attachControl=function(e,i){var r,n=this;this._attachedCanvas||(this._attachedCanvas=e,void 0===this._onPointerDown&&(this._onPointerDown=function(t){i||t.preventDefault(),n._pointerPressed.push(t.pointerId),1===n._pointerPressed.length&&(r={x:t.clientX,y:t.clientY})},this._onPointerUp=function(t){i||t.preventDefault();var e=n._pointerPressed.indexOf(t.pointerId);-1!==e&&(n._pointerPressed.splice(e,1),0==e&&(r=null,n._offsetX=null,n._offsetY=null))},this._onPointerMove=function(t){if(i||t.preventDefault(),r){var e=n._pointerPressed.indexOf(t.pointerId);0==e&&(n._offsetX=t.clientX-r.x,n._offsetY=-(t.clientY-r.y))}},this._onLostFocus=function(){n._offsetX=null,n._offsetY=null}),e.addEventListener("pointerdown",this._onPointerDown),e.addEventListener("pointerup",this._onPointerUp),e.addEventListener("pointerout",this._onPointerUp),e.addEventListener("pointermove",this._onPointerMove),t.Tools.RegisterTopRootEvents([{name:"blur",handler:this._onLostFocus}]))},i.prototype.detachControl=function(e){this._attachedCanvas==e&&(e.removeEventListener("pointerdown",this._onPointerDown),e.removeEventListener("pointerup",this._onPointerUp),e.removeEventListener("pointerout",this._onPointerUp),e.removeEventListener("pointermove",this._onPointerMove),t.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 e=this._computeLocalCameraSpeed(),i=new t.Vector3(0,0,e*this._offsetY/this.moveSensibility);t.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(t.Vector3.TransformCoordinates(i,this._cameraRotationMatrix))}},i}(t.FreeCamera);t.TouchCamera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=t.Tools.GetPointerPrefix(),i=function(i){function r(e,r,n,o,s,a){var h=this;i.call(this,e,t.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.angularSensibility=1e3,this.wheelPrecision=3,this.pinchPrecision=2,this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39],this.zoomOnFactor=1,this.targetScreenOffset=t.Vector2.Zero(),this.pinchInwards=!0,this._keys=[],this._viewMatrix=new t.Matrix,this.checkCollisions=!1,this.collisionRadius=new t.Vector3(.5,.5,.5),this._collider=new t.Collider,this._previousPosition=t.Vector3.Zero(),this._collisionVelocity=t.Vector3.Zero(),this._newPosition=t.Vector3.Zero(),this._onCollisionPositionChange=function(t,e,i){void 0===i&&(i=null),(null!=t||void 0!=t)&&e.multiplyInPlace(h._collider.radius),e.equalsWithEpsilon(h.position)||(h.position.copyFrom(h._previousPosition),h.alpha=h._previousAlpha,h.beta=h._previousBeta,h.radius=h._previousRadius,h.onCollide&&i&&h.onCollide(i)),h._collisionTriggered=!1},this.target||(this.target=t.Vector3.Zero()),this.getViewMatrix()}return __extends(r,i),r.prototype._getTargetPosition=function(){return this.target.position||this.target},r.prototype._initCache=function(){i.prototype._initCache.call(this),this._cache.target=new t.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(t){t||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){var n,o=this,s=0,a=new t.SmartCollection;if(!this._attachedElement){this._attachedElement=i;var h=this.getEngine();void 0===this._onPointerDown&&(this._onPointerDown=function(t){a.add(t.pointerId,{x:t.clientX,y:t.clientY,type:t.pointerType}),n=a.item(t.pointerId),r||t.preventDefault()},this._onPointerUp=function(t){n=null,s=0,a.remove(t.pointerId),r||t.preventDefault()},this._onPointerMove=function(t){switch(r||t.preventDefault(),a.count){case 1:var e=t.clientX-n.x,i=t.clientY-n.y;o.inertialAlphaOffset-=e/o.angularSensibility,o.inertialBetaOffset-=i/o.angularSensibility,n.x=t.clientX,n.y=t.clientY;break;case 2:a.item(t.pointerId).x=t.clientX,a.item(t.pointerId).y=t.clientY;var h=o.pinchInwards?1:-1,c=a.getItemByIndex(0).x-a.getItemByIndex(1).x,l=a.getItemByIndex(0).y-a.getItemByIndex(1).y,u=c*c+l*l;if(0===s)return void(s=u);u!==s&&(o.inertialRadiusOffset+=(u-s)/(o.pinchPrecision*o.wheelPrecision*o.angularSensibility*h),s=u);break;default:a.item(t.pointerId)&&(a.item(t.pointerId).x=t.clientX,a.item(t.pointerId).y=t.clientY)}},this._onMouseMove=function(t){if(h.isPointerLock){var e=t.movementX||t.mozMovementX||t.webkitMovementX||t.msMovementX||0,i=t.movementY||t.mozMovementY||t.webkitMovementY||t.msMovementY||0;o.inertialAlphaOffset-=e/o.angularSensibility,o.inertialBetaOffset-=i/o.angularSensibility,r||t.preventDefault()}},this._wheel=function(t){var e=0;t.wheelDelta?e=t.wheelDelta/(40*o.wheelPrecision):t.detail&&(e=-t.detail/o.wheelPrecision),e&&(o.inertialRadiusOffset+=e),t.preventDefault&&(r||t.preventDefault())},this._onKeyDown=function(t){if(-1!==o.keysUp.indexOf(t.keyCode)||-1!==o.keysDown.indexOf(t.keyCode)||-1!==o.keysLeft.indexOf(t.keyCode)||-1!==o.keysRight.indexOf(t.keyCode)){var e=o._keys.indexOf(t.keyCode);-1===e&&o._keys.push(t.keyCode),t.preventDefault&&(r||t.preventDefault())}},this._onKeyUp=function(t){if(-1!==o.keysUp.indexOf(t.keyCode)||-1!==o.keysDown.indexOf(t.keyCode)||-1!==o.keysLeft.indexOf(t.keyCode)||-1!==o.keysRight.indexOf(t.keyCode)){var e=o._keys.indexOf(t.keyCode);e>=0&&o._keys.splice(e,1),t.preventDefault&&(r||t.preventDefault())}},this._onLostFocus=function(){o._keys=[],a.empty(),s=0,n=null},this._onGestureStart=function(t){void 0!==window.MSGesture&&(o._MSGestureHandler||(o._MSGestureHandler=new MSGesture,o._MSGestureHandler.target=i),o._MSGestureHandler.addPointer(t.pointerId))},this._onGesture=function(t){o.radius*=t.scale,t.preventDefault&&(r||(t.stopPropagation(),t.preventDefault()))},this._reset=function(){o._keys=[],o.inertialAlphaOffset=0,o.inertialBetaOffset=0,o.inertialRadiusOffset=0,a.empty(),s=0,n=null}),i.addEventListener(e+"down",this._onPointerDown,!1),i.addEventListener(e+"up",this._onPointerUp,!1),i.addEventListener(e+"out",this._onPointerUp,!1),i.addEventListener(e+"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),t.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(e+"down",this._onPointerDown),i.removeEventListener(e+"up",this._onPointerUp),i.removeEventListener(e+"out",this._onPointerUp),i.removeEventListener(e+"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),t.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._update=function(){if(!this._collisionTriggered){for(var e=0;e<this._keys.length;e++){var i=this._keys[e];-1!==this.keysLeft.indexOf(i)?this.inertialAlphaOffset-=.01:-1!==this.keysUp.indexOf(i)?this.inertialBetaOffset-=.01:-1!==this.keysRight.indexOf(i)?this.inertialAlphaOffset+=.01:-1!==this.keysDown.indexOf(i)&&(this.inertialBetaOffset+=.01)}(0!==this.inertialAlphaOffset||0!==this.inertialBetaOffset||0!=this.inertialRadiusOffset)&&(this.alpha+=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)<t.Engine.Epsilon&&(this.inertialAlphaOffset=0),Math.abs(this.inertialBetaOffset)<t.Engine.Epsilon&&(this.inertialBetaOffset=0),Math.abs(this.inertialRadiusOffset)<t.Engine.Epsilon&&(this.inertialRadiusOffset=0)),this.lowerAlphaLimit&&this.alpha<this.lowerAlphaLimit&&(this.alpha=this.lowerAlphaLimit),this.upperAlphaLimit&&this.alpha>this.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerBetaLimit&&this.beta<this.lowerBetaLimit&&(this.beta=this.lowerBetaLimit),this.upperBetaLimit&&this.beta>this.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerRadiusLimit&&this.radius<this.lowerRadiusLimit&&(this.radius=this.lowerRadiusLimit),this.upperRadiusLimit&&this.radius>this.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)}},r.prototype.setPosition=function(t){var e=t.subtract(this._getTargetPosition());this.radius=e.length(),this.alpha=Math.acos(e.x/Math.sqrt(Math.pow(e.x,2)+Math.pow(e.z,2))),e.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(e.y/this.radius)},r.prototype._getViewMatrix=function(){var e=Math.cos(this.alpha),i=Math.sin(this.alpha),r=Math.cos(this.beta),n=Math.sin(this.beta),o=this._getTargetPosition();return o.addToRef(new t.Vector3(this.radius*e*n,this.radius*r,this.radius*i*n),this.position),this.checkCollisions&&(this._collider.radius=this.collisionRadius,this.position.subtractToRef(this._previousPosition,this._collisionVelocity),this._collisionTriggered=!0,this.getScene().collisionCoordinator.getNewPosition(this._previousPosition,this._collisionVelocity,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)),t.Matrix.LookAtLHToRef(this.position,o,this.upVector,this._viewMatrix),this._previousAlpha=this.alpha,this._previousBeta=this.beta,this._previousRadius=this.radius,this._previousPosition.copyFrom(this.position),this._viewMatrix.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y,this._viewMatrix},r.prototype.zoomOn=function(e){e=e||this.getScene().meshes;var i=t.Mesh.MinMax(e),r=t.Vector3.Distance(i.min,i.max);this.radius=r*this.zoomOnFactor,this.focusOn({min:i.min,max:i.max,distance:r})},r.prototype.focusOn=function(e){var i,r;void 0===e.min?(i=e||this.getScene().meshes,i=t.Mesh.MinMax(i),r=t.Vector3.Distance(i.min,i.max)):(i=e,r=e.distance),this.target=t.Mesh.Center(i),this.maxZ=2*r},r}(t.Camera);t.ArcRotateCamera=i}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i,r){var n=this;e.call(this,t,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,e),i.prototype.attachControl=function(t,e){var i=this;this._attachedCanvas||(this._attachedCanvas=t,this._orientationChanged||(this._orientationChanged=function(t){i._initialOrientationGamma||(i._initialOrientationGamma=t.gamma,i._initialOrientationBeta=t.beta),i._orientationGamma=t.gamma,i._orientationBeta=t.beta,i._offsetY=i._initialOrientationBeta-i._orientationBeta,i._offsetX=i._initialOrientationGamma-i._orientationGamma}),window.addEventListener("deviceorientation",this._orientationChanged))},i.prototype.detachControl=function(t){this._attachedCanvas==t&&(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 e=this._computeLocalCameraSpeed(),i=new t.Vector3(0,0,e*this._offsetY/this.moveSensibility);t.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix),this.cameraDirection.addInPlace(t.Vector3.TransformCoordinates(i,this._cameraRotationMatrix))}},i}(t.FreeCamera);t.DeviceOrientationCamera=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t){this._renderingGroups=new Array,this._scene=t}return e.prototype._renderParticles=function(e,i){if(0!==this._scene._activeParticleSystems.length){for(var r=t.Tools.Now,n=0;n<this._scene._activeParticleSystems.length;n++){var o=this._scene._activeParticleSystems.data[n];o.renderingGroupId===e&&(this._clearDepthBuffer(),o.emitter.position&&i&&-1===i.indexOf(o.emitter)||(this._scene._activeParticles+=o.render()))}this._scene._particlesDuration+=t.Tools.Now-r}},e.prototype._renderSprites=function(e){if(this._scene.spritesEnabled&&0!==this._scene.spriteManagers.length){for(var i=t.Tools.Now,r=0;r<this._scene.spriteManagers.length;r++){var n=this._scene.spriteManagers[r];n.renderingGroupId===e&&(this._clearDepthBuffer(),
- n.render())}this._scene._spritesDuration+=t.Tools.Now-i}},e.prototype._clearDepthBuffer=function(){this._depthBufferAlreadyCleaned||(this._scene.getEngine().clear(0,!1,!0),this._depthBufferAlreadyCleaned=!0)},e.prototype.render=function(t,i,r,n){for(var o=0;o<e.MAX_RENDERINGGROUPS;o++){this._depthBufferAlreadyCleaned=!1;var s=this._renderingGroups[o],a=!1;s&&(this._clearDepthBuffer(),s.render(t)||(this._renderingGroups.splice(o,1),a=!0)),n&&this._renderSprites(o),r&&this._renderParticles(o,i),a&&o--}},e.prototype.reset=function(){for(var t in this._renderingGroups){var e=this._renderingGroups[t];e.prepare()}},e.prototype.dispatch=function(e){var i=e.getMesh(),r=i.renderingGroupId||0;this._renderingGroups[r]||(this._renderingGroups[r]=new t.RenderingGroup(r,this._scene)),this._renderingGroups[r].dispatch(e)},e.MAX_RENDERINGGROUPS=4,e}();t.RenderingManager=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i){this.index=e,this._opaqueSubMeshes=new t.SmartArray(256),this._transparentSubMeshes=new t.SmartArray(256),this._alphaTestSubMeshes=new t.SmartArray(256),this._scene=i}return e.prototype.render=function(e){if(e)return e(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();for(n.setAlphaTesting(!0),i=0;i<this._alphaTestSubMeshes.length;i++)r=this._alphaTestSubMeshes.data[i],r.render();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.position).length();var o=this._transparentSubMeshes.data.slice(0,this._transparentSubMeshes.length);for(o.sort(function(t,e){return t._alphaIndex>e._alphaIndex?1:t._alphaIndex<e._alphaIndex?-1:t._distanceToCamera<e._distanceToCamera?1:t._distanceToCamera>e._distanceToCamera?-1:0}),n.setAlphaMode(t.Engine.ALPHA_COMBINE),i=0;i<o.length;i++)r=o[i],r.render();n.setAlphaMode(t.Engine.ALPHA_DISABLE)}return!0},e.prototype.prepare=function(){this._opaqueSubMeshes.reset(),this._transparentSubMeshes.reset(),this._alphaTestSubMeshes.reset()},e.prototype.dispatch=function(t){var e=t.getMaterial(),i=t.getMesh();e.needAlphaBlending()||i.visibility<1||i.hasVertexAlpha?this._transparentSubMeshes.push(t):e.needAlphaTesting()?this._alphaTestSubMeshes.push(t):this._opaqueSubMeshes.push(t)},e}();t.RenderingGroup=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(i){this.autoClear=!0,this.clearColor=new t.Color3(.2,.2,.3),this.ambientColor=new t.Color3(0,0,0),this.forceWireframe=!1,this.forcePointsCloud=!1,this.forceShowBoundingBoxes=!1,this.animationsEnabled=!0,this.cameraToUseForPointers=null,this.fogEnabled=!0,this.fogMode=e.FOGMODE_NONE,this.fogColor=new t.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 t.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 t.Vector3(0,-9,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 t.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 t.SmartArray(256),this._onReadyCallbacks=new Array,this._pendingData=[],this._onBeforeRenderCallbacks=new Array,this._onAfterRenderCallbacks=new Array,this._activeMeshes=new t.SmartArray(256),this._processedMaterials=new t.SmartArray(256),this._renderTargets=new t.SmartArray(256),this._activeParticleSystems=new t.SmartArray(256),this._activeSkeletons=new t.SmartArray(32),this._activeBones=0,this._activeAnimatables=new Array,this._transformMatrix=t.Matrix.Zero(),this._uniqueIdCounter=0,this._engine=i,i.scenes.push(this),this._renderingManager=new t.RenderingManager(this),this.postProcessManager=new t.PostProcessManager(this),this.postProcessRenderPipelineManager=new t.PostProcessRenderPipelineManager,this._boundingBoxRenderer=new t.BoundingBoxRenderer(this),this._outlineRenderer=new t.OutlineRenderer(this),this.attachControl(),this._debugLayer=new t.DebugLayer(this),this.mainSoundTrack=new t.SoundTrack(this,{mainTrack:!0}),this.simplificationQueue=new t.SimplificationQueue,this.workerCollisions=!1}return Object.defineProperty(e,"FOGMODE_NONE",{get:function(){return e._FOGMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FOGMODE_EXP",{get:function(){return e._FOGMODE_EXP},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FOGMODE_EXP2",{get:function(){return e._FOGMODE_EXP2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"FOGMODE_LINEAR",{get:function(){return e._FOGMODE_LINEAR},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"debugLayer",{get:function(){return this._debugLayer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"workerCollisions",{get:function(){return this._workerCollisions},set:function(e){this._workerCollisions=e,this.collisionCoordinator&&this.collisionCoordinator.destroy(),this.collisionCoordinator=e?new t.CollisionCoordinatorWorker:new t.CollisionCoordinatorLegacy,this.collisionCoordinator.init(this)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"meshUnderPointer",{get:function(){return this._meshUnderPointer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"pointerX",{get:function(){return this._pointerX},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"pointerY",{get:function(){return this._pointerY},enumerable:!0,configurable:!0}),e.prototype.getCachedMaterial=function(){return this._cachedMaterial},e.prototype.getBoundingBoxRenderer=function(){return this._boundingBoxRenderer},e.prototype.getOutlineRenderer=function(){return this._outlineRenderer},e.prototype.getEngine=function(){return this._engine},e.prototype.getTotalVertices=function(){return this._totalVertices},e.prototype.getActiveIndices=function(){return this._activeIndices},e.prototype.getActiveParticles=function(){return this._activeParticles},e.prototype.getActiveBones=function(){return this._activeBones},e.prototype.getLastFrameDuration=function(){return this._lastFrameDuration},e.prototype.getEvaluateActiveMeshesDuration=function(){return this._evaluateActiveMeshesDuration},e.prototype.getActiveMeshes=function(){return this._activeMeshes},e.prototype.getRenderTargetsDuration=function(){return this._renderTargetsDuration},e.prototype.getRenderDuration=function(){return this._renderDuration},e.prototype.getParticlesDuration=function(){return this._particlesDuration},e.prototype.getSpritesDuration=function(){return this._spritesDuration},e.prototype.getAnimationRatio=function(){return this._animationRatio},e.prototype.getRenderId=function(){return this._renderId},e.prototype.incrementRenderId=function(){this._renderId++},e.prototype._updatePointerPosition=function(t){var e=this._engine.getRenderingCanvasClientRect();this._pointerX=t.clientX-e.left,this._pointerY=t.clientY-e.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())},e.prototype.attachControl=function(){var e=this;this._onPointerMove=function(t){var i=e._engine.getRenderingCanvas();e._updatePointerPosition(t);var r=e.pick(e._pointerX,e._pointerY,function(t){return t.isPickable&&t.isVisible&&t.isReady()&&t.actionManager&&t.actionManager.hasPointerTriggers},!1,e.cameraToUseForPointers);r.hit?(e._meshUnderPointer=r.pickedMesh,e.setPointerOverMesh(r.pickedMesh),i.style.cursor="pointer"):(e.setPointerOverMesh(null),i.style.cursor="",e._meshUnderPointer=null)},this._onPointerDown=function(i){var r=null;e.onPointerDown||(r=function(t){return t.isPickable&&t.isVisible&&t.isReady()&&t.actionManager&&t.actionManager.hasPickTriggers}),e._updatePointerPosition(i);var n=e.pick(e._pointerX,e._pointerY,r,!1,e.cameraToUseForPointers);if(n.hit&&n.pickedMesh.actionManager){switch(i.button){case 0:n.pickedMesh.actionManager.processTrigger(t.ActionManager.OnLeftPickTrigger,t.ActionEvent.CreateNew(n.pickedMesh,i));break;case 1:n.pickedMesh.actionManager.processTrigger(t.ActionManager.OnCenterPickTrigger,t.ActionEvent.CreateNew(n.pickedMesh,i));break;case 2:n.pickedMesh.actionManager.processTrigger(t.ActionManager.OnRightPickTrigger,t.ActionEvent.CreateNew(n.pickedMesh,i))}n.pickedMesh.actionManager.processTrigger(t.ActionManager.OnPickTrigger,t.ActionEvent.CreateNew(n.pickedMesh,i))}e.onPointerDown&&e.onPointerDown(i,n)},this._onPointerUp=function(i){var r=null;e.onPointerUp||(r=function(e){return e.isPickable&&e.isVisible&&e.isReady()&&e.actionManager&&e.actionManager.hasSpecificTrigger(t.ActionManager.OnPickUpTrigger)}),e._updatePointerPosition(i);var n=e.pick(e._pointerX,e._pointerY,r,!1,e.cameraToUseForPointers);n.hit&&n.pickedMesh.actionManager&&n.pickedMesh.actionManager.processTrigger(t.ActionManager.OnPickUpTrigger,t.ActionEvent.CreateNew(n.pickedMesh,i)),e.onPointerUp&&e.onPointerUp(i,n)},this._onKeyDown=function(i){e.actionManager&&e.actionManager.processTrigger(t.ActionManager.OnKeyDownTrigger,t.ActionEvent.CreateNewFromScene(e,i))},this._onKeyUp=function(i){e.actionManager&&e.actionManager.processTrigger(t.ActionManager.OnKeyUpTrigger,t.ActionEvent.CreateNewFromScene(e,i))};var i=t.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),t.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp}])},e.prototype.detachControl=function(){var e=t.Tools.GetPointerPrefix();this._engine.getRenderingCanvas().removeEventListener(e+"move",this._onPointerMove),this._engine.getRenderingCanvas().removeEventListener(e+"down",this._onPointerDown),this._engine.getRenderingCanvas().removeEventListener(e+"up",this._onPointerUp),t.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp}])},e.prototype.isReady=function(){if(this._pendingData.length>0)return!1;for(var e=0;e<this._geometries.length;e++){var i=this._geometries[e];if(i.delayLoadState===t.Engine.DELAYLOADSTATE_LOADING)return!1}for(e=0;e<this.meshes.length;e++){var r=this.meshes[e];if(!r.isReady())return!1;var n=r.material;if(n&&!n.isReady(r))return!1}return!0},e.prototype.resetCachedMaterial=function(){this._cachedMaterial=null},e.prototype.registerBeforeRender=function(t){this._onBeforeRenderCallbacks.push(t)},e.prototype.unregisterBeforeRender=function(t){var e=this._onBeforeRenderCallbacks.indexOf(t);e>-1&&this._onBeforeRenderCallbacks.splice(e,1)},e.prototype.registerAfterRender=function(t){this._onAfterRenderCallbacks.push(t)},e.prototype.unregisterAfterRender=function(t){var e=this._onAfterRenderCallbacks.indexOf(t);e>-1&&this._onAfterRenderCallbacks.splice(e,1)},e.prototype._addPendingData=function(t){this._pendingData.push(t)},e.prototype._removePendingData=function(t){var e=this._pendingData.indexOf(t);-1!==e&&this._pendingData.splice(e,1)},e.prototype.getWaitingItemsCount=function(){return this._pendingData.length},e.prototype.executeWhenReady=function(t){var e=this;this._onReadyCallbacks.push(t),-1===this._executeWhenReadyTimeoutId&&(this._executeWhenReadyTimeoutId=setTimeout(function(){e._checkIsReady()},150))},e.prototype._checkIsReady=function(){var t=this;return this.isReady()?(this._onReadyCallbacks.forEach(function(t){t()}),this._onReadyCallbacks=[],void(this._executeWhenReadyTimeoutId=-1)):void(this._executeWhenReadyTimeoutId=setTimeout(function(){t._checkIsReady()},150))},e.prototype.beginAnimation=function(e,i,r,n,o,s,a){if(void 0===o&&(o=1),this.stopAnimation(e),a||(a=new t.Animatable(this,e,i,r,n,o,s)),e.animations&&a.appendAnimations(e,e.animations),e.getAnimatables)for(var h=e.getAnimatables(),c=0;c<h.length;c++)this.beginAnimation(h[c],i,r,n,o,s,a);return a},e.prototype.beginDirectAnimation=function(e,i,r,n,o,s,a){void 0===s&&(s=1);var h=new t.Animatable(this,e,r,n,o,s,a,i);return h},e.prototype.getAnimatableByTarget=function(t){for(var e=0;e<this._activeAnimatables.length;e++)if(this._activeAnimatables[e].target===t)return this._activeAnimatables[e];return null},e.prototype.stopAnimation=function(t){var e=this.getAnimatableByTarget(t);e&&e.stop()},e.prototype._animate=function(){if(this.animationsEnabled){this._animationStartDate||(this._animationStartDate=t.Tools.Now);for(var e=t.Tools.Now,i=e-this._animationStartDate,r=0;r<this._activeAnimatables.length;r++)this._activeAnimatables[r]._animate(i)}},e.prototype.getViewMatrix=function(){return this._viewMatrix},e.prototype.getProjectionMatrix=function(){return this._projectionMatrix},e.prototype.getTransformMatrix=function(){return this._transformMatrix},e.prototype.setTransformMatrix=function(t,e){this._viewMatrix=t,this._projectionMatrix=e,this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)},e.prototype.addMesh=function(t){t.uniqueId=this._uniqueIdCounter++;var e=this.meshes.push(t);this.collisionCoordinator.onMeshAdded(t),this.onNewMeshAdded&&this.onNewMeshAdded(t,e,this)},e.prototype.removeMesh=function(t){var e=this.meshes.indexOf(t);return-1!==e&&this.meshes.splice(e,1),this.collisionCoordinator.onMeshRemoved(t),this.onMeshRemoved&&this.onMeshRemoved(t),e},e.prototype.removeLight=function(t){var e=this.lights.indexOf(t);return-1!==e&&this.lights.splice(e,1),this.onLightRemoved&&this.onLightRemoved(t),e},e.prototype.removeCamera=function(t){var e=this.cameras.indexOf(t);-1!==e&&this.cameras.splice(e,1);var i=this.activeCameras.indexOf(t);return-1!==i&&this.activeCameras.splice(i,1),this.activeCamera===t&&(this.activeCamera=this.cameras.length>0?this.cameras[0]:null),this.onCameraRemoved&&this.onCameraRemoved(t),e},e.prototype.addLight=function(t){t.uniqueId=this._uniqueIdCounter++;var e=this.lights.push(t);this.onNewLightAdded&&this.onNewLightAdded(t,e,this)},e.prototype.addCamera=function(t){t.uniqueId=this._uniqueIdCounter++;var e=this.cameras.push(t);this.onNewCameraAdded&&this.onNewCameraAdded(t,e,this)},e.prototype.setActiveCameraByID=function(t){var e=this.getCameraByID(t);return e?(this.activeCamera=e,e):null},e.prototype.setActiveCameraByName=function(t){var e=this.getCameraByName(t);return e?(this.activeCamera=e,e):null},e.prototype.getMaterialByID=function(t){for(var e=0;e<this.materials.length;e++)if(this.materials[e].id===t)return this.materials[e];return null},e.prototype.getMaterialByName=function(t){for(var e=0;e<this.materials.length;e++)if(this.materials[e].name===t)return this.materials[e];return null},e.prototype.getCameraByID=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e].id===t)return this.cameras[e];return null},e.prototype.getCameraByUniqueID=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e].uniqueId===t)return this.cameras[e];return null},e.prototype.getCameraByName=function(t){for(var e=0;e<this.cameras.length;e++)if(this.cameras[e].name===t)return this.cameras[e];return null},e.prototype.getLightByName=function(t){for(var e=0;e<this.lights.length;e++)if(this.lights[e].name===t)return this.lights[e];return null},e.prototype.getLightByID=function(t){for(var e=0;e<this.lights.length;e++)if(this.lights[e].id===t)return this.lights[e];return null},e.prototype.getLightByUniqueID=function(t){for(var e=0;e<this.lights.length;e++)if(this.lights[e].uniqueId===t)return this.lights[e];return null},e.prototype.getGeometryByID=function(t){for(var e=0;e<this._geometries.length;e++)if(this._geometries[e].id===t)return this._geometries[e];return null},e.prototype.pushGeometry=function(t,e){return!e&&this.getGeometryByID(t.id)?!1:(this._geometries.push(t),this.collisionCoordinator.onGeometryAdded(t),this.onGeometryAdded&&this.onGeometryAdded(t),!0)},e.prototype.removeGeometry=function(t){var e=this._geometries.indexOf(t);return e>-1?(this._geometries.splice(e,1),this.collisionCoordinator.onGeometryDeleted(t),this.onGeometryRemoved&&this.onGeometryRemoved(t),!0):!1},e.prototype.getGeometries=function(){return this._geometries},e.prototype.getMeshByID=function(t){for(var e=0;e<this.meshes.length;e++)if(this.meshes[e].id===t)return this.meshes[e];return null},e.prototype.getMeshByUniqueID=function(t){for(var e=0;e<this.meshes.length;e++)if(this.meshes[e].uniqueId===t)return this.meshes[e];return null},e.prototype.getLastMeshByID=function(t){for(var e=this.meshes.length-1;e>=0;e--)if(this.meshes[e].id===t)return this.meshes[e];return null},e.prototype.getLastEntryByID=function(t){for(var e=this.meshes.length-1;e>=0;e--)if(this.meshes[e].id===t)return this.meshes[e];for(e=this.cameras.length-1;e>=0;e--)if(this.cameras[e].id===t)return this.cameras[e];for(e=this.lights.length-1;e>=0;e--)if(this.lights[e].id===t)return this.lights[e];return null},e.prototype.getNodeByName=function(t){var e=this.getMeshByName(t);if(e)return e;var i=this.getLightByName(t);return i?i:this.getCameraByName(t)},e.prototype.getMeshByName=function(t){for(var e=0;e<this.meshes.length;e++)if(this.meshes[e].name===t)return this.meshes[e];return null},e.prototype.getSoundByName=function(t){for(var e=0;e<this.mainSoundTrack.soundCollection.length;e++)if(this.mainSoundTrack.soundCollection[e].name===t)return this.mainSoundTrack.soundCollection[e];for(var i=0;i<this.soundTracks.length;i++)for(e=0;e<this.soundTracks[i].soundCollection.length;e++)if(this.soundTracks[i].soundCollection[e].name===t)return this.soundTracks[i].soundCollection[e];return null},e.prototype.getLastSkeletonByID=function(t){for(var e=this.skeletons.length-1;e>=0;e--)if(this.skeletons[e].id===t)return this.skeletons[e];return null},e.prototype.getSkeletonById=function(t){for(var e=0;e<this.skeletons.length;e++)if(this.skeletons[e].id===t)return this.skeletons[e];return null},e.prototype.getSkeletonByName=function(t){for(var e=0;e<this.skeletons.length;e++)if(this.skeletons[e].name===t)return this.skeletons[e];return null},e.prototype.isActiveMesh=function(t){return-1!==this._activeMeshes.indexOf(t)},e.prototype._evaluateSubMesh=function(t,e){if(e.alwaysSelectAsActiveMesh||1===e.subMeshes.length||t.isInFrustum(this._frustumPlanes)){var i=t.getMaterial();e.showSubMeshesBoundingBox&&this._boundingBoxRenderer.renderList.push(t.getBoundingInfo().boundingBox),i&&(i.getRenderTargetTextures&&-1===this._processedMaterials.indexOf(i)&&(this._processedMaterials.push(i),this._renderTargets.concat(i.getRenderTargetTextures())),this._activeIndices+=t.indexCount,this._renderingManager.dispatch(t))}},e.prototype._evaluateActiveMeshes=function(){this.activeCamera._activeMeshes.reset(),this._activeMeshes.reset(),this._renderingManager.reset(),this._processedMaterials.reset(),this._activeParticleSystems.reset(),this._activeSkeletons.reset(),this._boundingBoxRenderer.reset(),this._frustumPlanes?t.Frustum.GetPlanesToRef(this._transformMatrix,this._frustumPlanes):this._frustumPlanes=t.Frustum.GetPlanes(this._transformMatrix);var e,i;if(this._selectionOctree){var r=this._selectionOctree.select(this._frustumPlanes);e=r.data,i=r.length}else i=this.meshes.length,e=this.meshes;for(var n=0;i>n;n++){var o=e[n];if(!o.isBlocked&&(this._totalVertices+=o.getTotalVertices(),o.isReady()&&o.isEnabled())){o.computeWorldMatrix(),o.actionManager&&o.actionManager.hasSpecificTriggers([t.ActionManager.OnIntersectionEnterTrigger,t.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=t.Tools.Now;if(this.particlesEnabled){t.Tools.StartPerformanceCounter("Particles",this.particleSystems.length>0);for(var h=0;h<this.particleSystems.length;h++){var c=this.particleSystems[h];c.isStarted()&&(!c.emitter.position||c.emitter&&c.emitter.isEnabled())&&(this._activeParticleSystems.push(c),c.animate())}t.Tools.EndPerformanceCounter("Particles",this.particleSystems.length>0)}this._particlesDuration+=t.Tools.Now-a},e.prototype._activeMesh=function(t){if(t.skeleton&&this.skeletonsEnabled&&this._activeSkeletons.pushNoDuplicate(t.skeleton),(t.showBoundingBox||this.forceShowBoundingBoxes)&&this._boundingBoxRenderer.renderList.push(t.getBoundingInfo().boundingBox),t&&t.subMeshes){var e,i;if(t._submeshesOctree&&t.useOctreeForRenderingSelection){var r=t._submeshesOctree.select(this._frustumPlanes);e=r.length,i=r.data}else i=t.subMeshes,e=i.length;for(var n=0;e>n;n++){var o=i[n];this._evaluateSubMesh(o,t)}}},e.prototype.updateTransformMatrix=function(t){this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(t))},e.prototype._renderForCamera=function(e){var i=this._engine;if(this.activeCamera=e,!this.activeCamera)throw new Error("Active camera not set");t.Tools.StartPerformanceCounter("Rendering camera "+this.activeCamera.name),i.setViewport(this.activeCamera.viewport),this._renderId++,this.updateTransformMatrix(),this.beforeCameraRender&&this.beforeCameraRender(this.activeCamera);var r=t.Tools.Now;t.Tools.StartPerformanceCounter("Active meshes evaluation"),this._evaluateActiveMeshes(),this._evaluateActiveMeshesDuration+=t.Tools.Now-r,t.Tools.EndPerformanceCounter("Active meshes evaluation");for(var n=0;n<this._activeSkeletons.length;n++){var o=this._activeSkeletons.data[n];o.prepare()}var s=t.Tools.Now;if(this.renderTargetsEnabled){t.Tools.StartPerformanceCounter("Render targets",this._renderTargets.length>0);for(var a=0;a<this._renderTargets.length;a++){var h=this._renderTargets.data[a];if(h._shouldRender()){this._renderId++;var c=h.activeCamera&&h.activeCamera!==this.activeCamera;h.render(c,this.dumpNextRenderTargets)}}t.Tools.EndPerformanceCounter("Render targets",this._renderTargets.length>0),this._renderId++}this._renderTargets.length>0&&i.restoreDefaultFramebuffer(),this._renderTargetsDuration+=t.Tools.Now-s,this.postProcessManager._prepareFrame();var l=t.Tools.Now;if(this.layers.length){i.setDepthBuffer(!1);var u,f;for(u=0;u<this.layers.length;u++)f=this.layers[u],f.isBackground&&f.render();i.setDepthBuffer(!0)}if(t.Tools.StartPerformanceCounter("Main render"),this._renderingManager.render(null,null,!0,!0),t.Tools.EndPerformanceCounter("Main render"),this._boundingBoxRenderer.render(),this.lensFlaresEnabled){t.Tools.StartPerformanceCounter("Lens flares",this.lensFlareSystems.length>0);for(var d=0;d<this.lensFlareSystems.length;d++)this.lensFlareSystems[d].render();t.Tools.EndPerformanceCounter("Lens flares",this.lensFlareSystems.length>0)}if(this.layers.length){for(i.setDepthBuffer(!1),u=0;u<this.layers.length;u++)f=this.layers[u],f.isBackground||f.render();i.setDepthBuffer(!0)}this._renderDuration+=t.Tools.Now-l,this.postProcessManager._finalizeFrame(e.isIntermediate),this.activeCamera._updateFromScene(),this._renderTargets.reset(),this.afterCameraRender&&this.afterCameraRender(this.activeCamera),t.Tools.EndPerformanceCounter("Rendering camera "+this.activeCamera.name)},e.prototype._processSubCameras=function(t){if(0===t.subCameras.length)return void this._renderForCamera(t);for(var e=0;e<t.subCameras.length;e++)this._renderForCamera(t.subCameras[e]);this.activeCamera=t,this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix()),this.activeCamera._updateFromScene()},e.prototype._checkIntersections=function(){for(var e=0;e<this._meshesForIntersections.length;e++)for(var i=this._meshesForIntersections.data[e],r=0;r<i.actionManager.actions.length;r++){var n=i.actionManager.actions[r];if(n.trigger===t.ActionManager.OnIntersectionEnterTrigger||n.trigger===t.ActionManager.OnIntersectionExitTrigger){var o=n.getTriggerParameter(),s=o instanceof t.AbstractMesh?o:o.mesh,a=s.intersectsMesh(i,o.usePreciseIntersection),h=i._intersectionsInProgress.indexOf(s);if(a&&-1===h)n.trigger===t.ActionManager.OnIntersectionEnterTrigger?(n._executeCurrent(t.ActionEvent.CreateNew(i)),i._intersectionsInProgress.push(s)):n.trigger===t.ActionManager.OnIntersectionExitTrigger&&i._intersectionsInProgress.push(s);else if(!a&&h>-1&&n.trigger===t.ActionManager.OnIntersectionExitTrigger){n._executeCurrent(t.ActionEvent.CreateNew(i));var c=i._intersectionsInProgress.indexOf(s);c>-1&&i._intersectionsInProgress.splice(c,1)}}}},e.prototype.render=function(){var i=t.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(),t.Tools.StartPerformanceCounter("Scene rendering"),this.actionManager&&this.actionManager.processTrigger(t.ActionManager.OnEveryFrameTrigger,null),this.simplificationQueue.running||this.simplificationQueue.executeNext(),this.beforeRender&&this.beforeRender();for(var r=0;r<this._onBeforeRenderCallbacks.length;r++)this._onBeforeRenderCallbacks[r]();var n=Math.max(e.MinDeltaTime,Math.min(this._engine.getDeltaTime(),e.MaxDeltaTime));this._animationRatio=.06*n,this._animate(),this._physicsEngine&&(t.Tools.StartPerformanceCounter("Physics"),this._physicsEngine._runOneStep(n/1e3),t.Tools.EndPerformanceCounter("Physics"));var o=t.Tools.Now,s=this.getEngine(),a=this.activeCamera;if(this.renderTargetsEnabled){t.Tools.StartPerformanceCounter("Custom render targets",this.customRenderTargets.length>0);for(var h=0;h<this.customRenderTargets.length;h++){var c=this.customRenderTargets[h];if(c._shouldRender()){if(this._renderId++,this.activeCamera=c.activeCamera||this.activeCamera,!this.activeCamera)throw new Error("Active camera not set");s.setViewport(this.activeCamera.viewport),this.updateTransformMatrix(),c.render(a!==this.activeCamera,this.dumpNextRenderTargets)}}t.Tools.EndPerformanceCounter("Custom render targets",this.customRenderTargets.length>0),this._renderId++}if(this.customRenderTargets.length>0&&s.restoreDefaultFramebuffer(),this._renderTargetsDuration+=t.Tools.Now-o,this.activeCamera=a,this.proceduralTexturesEnabled){t.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var l=0;l<this._proceduralTextures.length;l++){var u=this._proceduralTextures[l];u._shouldRender()&&u.render()}t.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,_=0;_<this.activeCameras.length;_++)this._renderId=m,this._processSubCameras(this.activeCameras[_]);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 g=0;g<this._toBeDisposed.length;g++)this._toBeDisposed.data[g].dispose(),this._toBeDisposed[g]=null;this._toBeDisposed.reset(),this.dumpNextRenderTargets&&(this.dumpNextRenderTargets=!1),t.Tools.EndPerformanceCounter("Scene rendering"),this._lastFrameDuration=t.Tools.Now-i},e.prototype._updateAudioParameters=function(){if(this.audioEnabled&&(0!==this.mainSoundTrack.soundCollection.length||0!==this.soundTracks.length)){var e,i=t.Engine.audioEngine;if(e=this.activeCameras.length>0?this.activeCameras[0]:this.activeCamera,e&&i.canUseWebAudio){i.audioContext.listener.setPosition(e.position.x,e.position.y,e.position.z);var r=t.Matrix.Invert(e.getViewMatrix()),n=t.Vector3.TransformNormal(new t.Vector3(0,0,-1),r);n.normalize(),i.audioContext.listener.setOrientation(n.x,n.y,n.z,0,1,0);for(var 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(e.prototype,"audioEnabled",{get:function(){return this._audioEnabled},set:function(t){this._audioEnabled=t,this._audioEnabled?this._enableAudio():this._disableAudio()},enumerable:!0,configurable:!0}),e.prototype._disableAudio=function(){for(var t=0;t<this.mainSoundTrack.soundCollection.length;t++)this.mainSoundTrack.soundCollection[t].pause();for(t=0;t<this.soundTracks.length;t++)for(var e=0;e<this.soundTracks[t].soundCollection.length;e++)this.soundTracks[t].soundCollection[e].pause()},e.prototype._enableAudio=function(){for(var t=0;t<this.mainSoundTrack.soundCollection.length;t++)this.mainSoundTrack.soundCollection[t].isPaused&&this.mainSoundTrack.soundCollection[t].play();for(t=0;t<this.soundTracks.length;t++)for(var e=0;e<this.soundTracks[t].soundCollection.length;e++)this.soundTracks[t].soundCollection[e].isPaused&&this.soundTracks[t].soundCollection[e].play()},Object.defineProperty(e.prototype,"headphone",{get:function(){return this._headphone},set:function(t){this._headphone=t,this._headphone?this._switchAudioModeForHeadphones():this._switchAudioModeForNormalSpeakers()},enumerable:!0,configurable:!0}),e.prototype._switchAudioModeForHeadphones=function(){this.mainSoundTrack.switchPanningModelToHRTF();for(var t=0;t<this.soundTracks.length;t++)this.soundTracks[t].switchPanningModelToHRTF()},e.prototype._switchAudioModeForNormalSpeakers=function(){this.mainSoundTrack.switchPanningModelToEqualPower();for(var t=0;t<this.soundTracks.length;t++)this.soundTracks[t].switchPanningModelToEqualPower()},e.prototype.enableDepthRenderer=function(){return this._depthRenderer?this._depthRenderer:(this._depthRenderer=new t.DepthRenderer(this),this._depthRenderer)},e.prototype.disableDepthRenderer=function(){this._depthRenderer&&(this._depthRenderer.dispose(),this._depthRenderer=null)},e.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 t,e=this._engine.getRenderingCanvas();for(t=0;t<this.cameras.length;t++)this.cameras[t].detachControl(e);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(),t=this._engine.scenes.indexOf(this),t>-1&&this._engine.scenes.splice(t,1),this._engine.wipeCaches()},e.prototype.disposeSounds=function(){this.mainSoundTrack.dispose();for(var t=0;t<this.soundTracks.length;t++)this.soundTracks[t].dispose()},e.prototype.getWorldExtends=function(){for(var e=new t.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),i=new t.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;t.Tools.CheckExtends(o,e,i),t.Tools.CheckExtends(s,e,i)}return{min:e,max:i}},e.prototype.createOrUpdateSelectionOctree=function(e,i){void 0===e&&(e=64),void 0===i&&(i=2),this._selectionOctree||(this._selectionOctree=new t.Octree(t.Octree.CreationFuncForMeshes,e,i));var r=this.getWorldExtends();return this._selectionOctree.update(r.min,r.max,this.meshes),this._selectionOctree},e.prototype.createPickingRay=function(e,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 e=e/this._engine.getHardwareScalingLevel()-a.x,i=i/this._engine.getHardwareScalingLevel()-(this._engine.getRenderHeight()-a.y-a.height),t.Ray.CreateNew(e,i,a.width,a.height,r?r:t.Matrix.Identity(),n.getViewMatrix(),n.getProjectionMatrix())},e.prototype._internalPick=function(e,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=e(a),c=s.intersects(h,r);if(c&&c.hit&&(r||null==n||!(c.distance>=n.distance))&&(n=c,r))break}return n||new t.PickingInfo},e.prototype.pick=function(t,e,i,r,n){var o=this;return this._internalPick(function(i){return o.createPickingRay(t,e,i,n)},i,r)},e.prototype.pickWithRay=function(e,i,r){var n=this;return this._internalPick(function(i){return n._pickWithRayInverseMatrix||(n._pickWithRayInverseMatrix=t.Matrix.Identity()),i.invertToRef(n._pickWithRayInverseMatrix),t.Ray.Transform(e,n._pickWithRayInverseMatrix)},i,r)},e.prototype.setPointerOverMesh=function(e){this._pointerOverMesh!==e&&(this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(t.ActionManager.OnPointerOutTrigger,t.ActionEvent.CreateNew(this._pointerOverMesh)),this._pointerOverMesh=e,this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(t.ActionManager.OnPointerOverTrigger,t.ActionEvent.CreateNew(this._pointerOverMesh)))},e.prototype.getPointerOverMesh=function(){return this._pointerOverMesh},e.prototype.getPhysicsEngine=function(){return this._physicsEngine},e.prototype.enablePhysics=function(e,i){return this._physicsEngine?!0:(this._physicsEngine=new t.PhysicsEngine(i),this._physicsEngine.isSupported()?(this._physicsEngine._initialize(e),!0):(this._physicsEngine=null,!1))},e.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=void 0)},e.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},e.prototype.setGravity=function(t){this._physicsEngine&&this._physicsEngine._setGravity(t)},e.prototype.createCompoundImpostor=function(t,e){if(t.parts&&(e=t,t=t.parts),!this._physicsEngine)return null;for(var i=0;i<t.length;i++){var r=t[i].mesh;r._physicImpostor=t[i].impostor,r._physicsMass=e.mass/t.length,r._physicsFriction=e.friction,r._physicRestitution=e.restitution}return this._physicsEngine._registerMeshesAsCompound(t,e)},e.prototype.deleteCompoundImpostor=function(e){for(var i=0;i<e.parts.length;i++){var r=e.parts[i].mesh;r._physicImpostor=t.PhysicsEngine.NoImpostor,this._physicsEngine._unregisterMesh(r)}},e.prototype.createDefaultCameraOrLight=function(){if(0===this.lights.length&&new t.HemisphericLight("default light",t.Vector3.Up(),this),!this.activeCamera){var e=new t.FreeCamera("default camera",t.Vector3.Zero(),this),i=this.getWorldExtends(),r=i.min.add(i.max.subtract(i.min).scale(.5));e.position=new t.Vector3(r.x,r.y,i.min.z-(i.max.z-i.min.z)),e.setTarget(r),this.activeCamera=e}},e.prototype._getByTags=function(e,i,r){if(void 0===i)return e;var n=[];r=r||function(t){};for(var o in e){var s=e[o];t.Tags.MatchesQuery(s,i)&&(n.push(s),r(s))}return n},e.prototype.getMeshesByTags=function(t,e){return this._getByTags(this.meshes,t,e)},e.prototype.getCamerasByTags=function(t,e){return this._getByTags(this.cameras,t,e)},e.prototype.getLightsByTags=function(t,e){return this._getByTags(this.lights,t,e)},e.prototype.getMaterialByTags=function(t,e){return this._getByTags(this.materials,t,e).concat(this._getByTags(this.multiMaterials,t,e))},e._FOGMODE_NONE=0,e._FOGMODE_EXP=1,e._FOGMODE_EXP2=2,e._FOGMODE_LINEAR=3,e.MinDeltaTime=1,e.MaxDeltaTime=1e3,e}();t.Scene=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(i,r,n,o,s,a){if(this._engine=i instanceof t.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 e.PositionKind:this._strideSize=3;break;case e.NormalKind:this._strideSize=3;break;case e.UVKind:this._strideSize=2;break;case e.UV2Kind:this._strideSize=2;break;case e.ColorKind:this._strideSize=4;break;case e.MatricesIndicesKind:this._strideSize=4;break;case e.MatricesWeightsKind:this._strideSize=4}}return e.prototype.isUpdatable=function(){return this._updatable},e.prototype.getData=function(){return this._data},e.prototype.getBuffer=function(){return this._buffer},e.prototype.getStrideSize=function(){return this._strideSize},e.prototype.create=function(t){(t||!this._buffer)&&(t=t||this._data,this._buffer||(this._buffer=this._updatable?this._engine.createDynamicVertexBuffer(4*t.length):this._engine.createVertexBuffer(t)),this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,t),this._data=t))},e.prototype.update=function(t){this.create(t)},e.prototype.updateDirectly=function(t,e){this._buffer&&this._updatable&&(this._engine.updateDynamicVertexBuffer(this._buffer,t,e),this._data=null)},e.prototype.dispose=function(){this._buffer&&this._engine._releaseBuffer(this._buffer)&&(this._buffer=null)},Object.defineProperty(e,"PositionKind",{get:function(){return e._PositionKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"NormalKind",{get:function(){return e._NormalKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"UVKind",{get:function(){return e._UVKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"UV2Kind",{get:function(){return e._UV2Kind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ColorKind",{get:function(){return e._ColorKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"MatricesIndicesKind",{get:function(){return e._MatricesIndicesKind},enumerable:!0,configurable:!0}),Object.defineProperty(e,"MatricesWeightsKind",{get:function(){return e._MatricesWeightsKind},enumerable:!0,configurable:!0}),e._PositionKind="position",e._NormalKind="normal",e._UVKind="uv",e._UV2Kind="uv2",e._ColorKind="color",e._MatricesIndicesKind="matricesIndices",e._MatricesWeightsKind="matricesWeights",e}();t.VertexBuffer=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i){e.call(this,t,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,e),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(t){return this._sourceMesh.getVerticesData(t)},i.prototype.isVerticesDataPresent=function(t){return this._sourceMesh.isVerticesDataPresent(t)},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 e=this._sourceMesh.getVerticesData(t.VertexBuffer.PositionKind);if(e){var i=t.Tools.ExtractMinAndMax(e,0,this._sourceMesh.getTotalVertices());this._boundingInfo=new t.BoundingInfo(i.minimum,i.maximum)}this._updateBoundingInfo()},i.prototype._preActivate=function(){this._currentLOD&&this._currentLOD._preActivate()},i.prototype._activate=function(t){this._currentLOD&&this._currentLOD._registerInstanceForRenderId(this,t)},i.prototype.getLOD=function(t){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 t=0;t<this._sourceMesh.subMeshes.length;t++)this._sourceMesh.subMeshes[t].clone(this,this._sourceMesh)},i.prototype._generatePointsArray=function(){return this._sourceMesh._generatePointsArray()},i.prototype.clone=function(e,i,r){var n=this._sourceMesh.createInstance(e);if(t.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(t){var i=this._sourceMesh.instances.indexOf(this);this._sourceMesh.instances.splice(i,1),e.prototype.dispose.call(this,t)},i}(t.AbstractMesh);t.InstancedMesh=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(){function t(){this.mustReturn=!1,this.visibleInstances=new Array,this.renderSelf=new Array}return t}();t._InstancesBatch=e;var i=function(i){function r(n,o,s,a,h){if(void 0===s&&(s=null),i.call(this,n,o),this.delayLoadState=t.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 e,this._instancesBufferSize=2048,this._sideOrientation=r._DEFAULTSIDE,this._areNormalsFrozen=!1,a){if(a._geometry&&a._geometry.applyToMesh(this),t.Tools.DeepCopy(a,this,["name","material","skeleton","instances"],[]),this.material=a.material,!h)for(var c=0;c<o.meshes.length;c++){var l=o.meshes[c];if(l.parent===a){l.clone(n+"."+l.name,this,h)}}for(c=0;c<o.particleSystems.length;c++){var u=o.particleSystems[c];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(t,e){return t.distance<e.distance?1:t.distance>e.distance?-1:0})},r.prototype.addLODLevel=function(e,i){if(i&&i._masterMesh)return t.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var r=new t.Internals.MeshLODLevel(e,i);return this._LODLevels.push(r),i&&(i._masterMesh=this),this._sortLODLevels(),this},r.prototype.getLODLevelAtDistance=function(t){for(var e=0;e<this._LODLevels.length;e++){var i=this._LODLevels[e];if(i.distance===t)return i.mesh}return null},r.prototype.removeLODLevel=function(t){for(var e=0;e<this._LODLevels.length;e++)this._LODLevels[e].mesh===t&&(this._LODLevels.splice(e,1),t&&(t._masterMesh=null));return this._sortLODLevels(),this},r.prototype.getLOD=function(t,e){if(!this._LODLevels||0===this._LODLevels.length)return this;var i=(e?e:this.getBoundingInfo().boundingSphere).centerWorld.subtract(t.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(t,e){return this._geometry?this._geometry.getVerticesData(t,e):null},r.prototype.getVertexBuffer=function(t){return this._geometry?this._geometry.getVertexBuffer(t):void 0},r.prototype.isVerticesDataPresent=function(t){return this._geometry?this._geometry.isVerticesDataPresent(t):this._delayInfo?-1!==this._delayInfo.indexOf(t):!1},r.prototype.getVerticesDataKinds=function(){if(!this._geometry){var t=[];if(this._delayInfo)for(var e in this._delayInfo)t.push(e);return t}return this._geometry.getVerticesDataKinds()},r.prototype.getTotalIndices=function(){return this._geometry?this._geometry.getTotalIndices():0},r.prototype.getIndices=function(t){return this._geometry?this._geometry.getIndices(t):[]},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===t.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(t){this._sideOrientation=t},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 t=this.getScene().getRenderId();this._preActivateId!==t&&(this._preActivateId=t,this._visibleInstances=null)},r.prototype._registerInstanceForRenderId=function(t,e){this._visibleInstances||(this._visibleInstances={},this._visibleInstances.defaultRenderId=e,this._visibleInstances.selfDefaultRenderId=this._renderId),this._visibleInstances[e]||(this._visibleInstances[e]=new Array),this._visibleInstances[e].push(t)},r.prototype.refreshBoundingInfo=function(){var e=this.getVerticesData(t.VertexBuffer.PositionKind);if(e){var i=t.Tools.ExtractMinAndMax(e,0,this.getTotalVertices());this._boundingInfo=new t.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 e=this.getTotalVertices();return e&&this.getIndices()?(this.releaseSubMeshes(),new t.SubMesh(0,0,e,0,this.getTotalIndices(),this)):null},r.prototype.subdivide=function(e){if(!(1>e)){for(var i=this.getTotalIndices(),r=i/e|0,n=0;r%3!==0;)r++;this.releaseSubMeshes();for(var o=0;e>o&&!(n>=i);o++)t.SubMesh.CreateFromIndices(0,n,Math.min(r,i-n),this),n+=r;this.synchronizeInstances()}},r.prototype.setVerticesData=function(e,i,r,n){if(e instanceof Array){var o=i;i=e,e=o,t.Tools.Warn("Deprecated usage of setVerticesData detected (since v1.12). Current signature is setVerticesData(kind, data, updatable).")}if(this._geometry)this._geometry.setVerticesData(e,i,r,n);else{var s=new t.VertexData;s.set(i,e);var a=this.getScene();new t.Geometry(t.Geometry.RandomId(),a,s,r,this)}},r.prototype.updateVerticesData=function(t,e,i,r){this._geometry&&(r?(this.makeGeometryUnique(),this.updateVerticesData(t,e,i,!1)):this._geometry.updateVerticesData(t,e,i))},r.prototype.updateVerticesDataDirectly=function(t,e,i,r){this._geometry&&(r?(this.makeGeometryUnique(),this.updateVerticesDataDirectly(t,e,i,!1)):this._geometry.updateVerticesDataDirectly(t,e,i))},r.prototype.updateMeshPositions=function(e,i){void 0===i&&(i=!0);var r=this.getVerticesData(t.VertexBuffer.PositionKind);if(e(r),this.updateVerticesData(t.VertexBuffer.PositionKind,r,!1,!1),i){var n=this.getIndices(),o=this.getVerticesData(t.VertexBuffer.NormalKind);t.VertexData.ComputeNormals(r,n,o),this.updateVerticesData(t.VertexBuffer.NormalKind,o,!1,!1)}},r.prototype.makeGeometryUnique=function(){if(this._geometry){var e=this._geometry.copy(t.Geometry.RandomId());e.applyToMesh(this)}},r.prototype.setIndices=function(e,i){if(this._geometry)this._geometry.setIndices(e,i);else{var r=new t.VertexData;r.indices=e;var n=this.getScene();new t.Geometry(t.Geometry.RandomId(),n,r,!1,this)}},r.prototype._bind=function(e,i,r){var n,o=this.getScene().getEngine();switch(r){case t.Material.PointFillMode:n=null;break;case t.Material.WireFrameFillMode:n=e.getLinesIndexBuffer(this.getIndices(),o);break;default:case t.Material.TriangleFillMode:n=this._geometry.getIndexBuffer()}o.bindMultiBuffers(this._geometry.getVertexBuffers(),n,i)},r.prototype._draw=function(e,i,r){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var n=this.getScene().getEngine();switch(i){case t.Material.PointFillMode:n.drawPointClouds(e.verticesStart,e.verticesCount,r);break;case t.Material.WireFrameFillMode:n.draw(!1,0,e.linesIndexCount,r);break;default:n.draw(!0,e.indexStart,e.indexCount,r)}}},r.prototype.registerBeforeRender=function(t){this._onBeforeRenderCallbacks.push(t)},r.prototype.unregisterBeforeRender=function(t){var e=this._onBeforeRenderCallbacks.indexOf(t);e>-1&&this._onBeforeRenderCallbacks.splice(e,1)},r.prototype.registerAfterRender=function(t){this._onAfterRenderCallbacks.push(t)},r.prototype.unregisterAfterRender=function(t){var e=this._onAfterRenderCallbacks.indexOf(t);e>-1&&this._onAfterRenderCallbacks.splice(e,1)},r.prototype._getInstancesRenderList=function(t){var e=this.getScene();if(this._batchCache.mustReturn=!1,this._batchCache.renderSelf[t]=this.isEnabled()&&this.isVisible,this._batchCache.visibleInstances[t]=null,this._visibleInstances){var i=e.getRenderId();this._batchCache.visibleInstances[t]=this._visibleInstances[i];var r=this._renderId;if(!this._batchCache.visibleInstances[t]&&this._visibleInstances.defaultRenderId&&(this._batchCache.visibleInstances[t]=this._visibleInstances[this._visibleInstances.defaultRenderId],i=Math.max(this._visibleInstances.defaultRenderId,i),r=Math.max(this._visibleInstances.selfDefaultRenderId,i)),this._batchCache.visibleInstances[t]&&this._batchCache.visibleInstances[t].length){if(this._renderIdForInstances[t]===i)return this._batchCache.mustReturn=!0,this._batchCache;i!==r&&(this._batchCache.renderSelf[t]=!1)}this._renderIdForInstances[t]=i}return this._batchCache},r.prototype._renderWithInstances=function(t,e,i,r,n){for(var o=i.visibleInstances[t._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,c=0,l=this.getWorldMatrix();if(i.renderSelf[t._id]&&(l.copyToArray(this._worldMatricesInstancesArray,h),h+=16,c++),o)for(var u=0;u<o.length;u++){var f=o[u];f.getWorldMatrix().copyToArray(this._worldMatricesInstancesArray,h),h+=16,c++}var d=r.getAttributeLocationByName("world0"),p=r.getAttributeLocationByName("world1"),m=r.getAttributeLocationByName("world2"),_=r.getAttributeLocationByName("world3"),g=[d,p,m,_];n.updateAndBindInstancesBuffer(this._worldMatricesInstancesBuffer,this._worldMatricesInstancesArray,g),this._draw(t,e,c),n.unBindInstancesBuffer(this._worldMatricesInstancesBuffer,g)},r.prototype._processRendering=function(t,e,i,r,n,o){var s=this.getScene(),a=s.getEngine();if(n)this._renderWithInstances(t,i,r,e,a);else if(r.renderSelf[t._id]&&(o&&o(!1,this.getWorldMatrix()),this._draw(t,i)),r.visibleInstances[t._id])for(var h=0;h<r.visibleInstances[t._id].length;h++){var c=r.visibleInstances[t._id][h],l=c.getWorldMatrix();o&&o(!0,l),this._draw(t,i)}},r.prototype.render=function(e){var i=this.getScene(),r=this._getInstancesRenderList(e._id);if(!r.mustReturn&&this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){for(var n=0;n<this._onBeforeRenderCallbacks.length;n++)this._onBeforeRenderCallbacks[n](this);var o=i.getEngine(),s=null!==o.getCaps().instancedArrays&&null!==r.visibleInstances[e._id]&&void 0!==r.visibleInstances[e._id],a=e.getMaterial();if(a&&a.isReady(this,s)){var h=o.getDepthWrite();this.renderOutline&&(o.setDepthWrite(!1),i.getOutlineRenderer().render(e,r),o.setDepthWrite(h)),a._preBind();var c=a.getEffect(),l=i.forcePointsCloud?t.Material.PointFillMode:i.forceWireframe?t.Material.WireFrameFillMode:a.fillMode;this._bind(e,c,l);var u=this.getWorldMatrix();if(a.bind(u,this),this._processRendering(e,c,l,r,s,function(t,e){t&&a.bindOnlyWorldMatrix(e)}),a.unbind(),this.renderOutline&&h&&(o.setDepthWrite(!0),o.setColorWrite(!1),i.getOutlineRenderer().render(e,r),o.setColorWrite(!0)),this.renderOverlay){var f=o.getAlphaMode();o.setAlphaMode(t.Engine.ALPHA_COMBINE),i.getOutlineRenderer().render(e,r,!0),o.setAlphaMode(f)}for(n=0;n<this._onAfterRenderCallbacks.length;n++)this._onAfterRenderCallbacks[n](this)}}},r.prototype.getEmittedParticleSystems=function(){for(var t=new Array,e=0;e<this.getScene().particleSystems.length;e++){var i=this.getScene().particleSystems[e];i.emitter===this&&t.push(i)}return t},r.prototype.getHierarchyEmittedParticleSystems=function(){var t=new Array,e=this.getDescendants();e.push(this);for(var i=0;i<this.getScene().particleSystems.length;i++){var r=this.getScene().particleSystems[i];-1!==e.indexOf(r.emitter)&&t.push(r)}return t},r.prototype.getChildren=function(){for(var t=[],e=0;e<this.getScene().meshes.length;e++){var i=this.getScene().meshes[e];i.parent===this&&t.push(i)}return t},r.prototype._checkDelayState=function(){var e=this,i=this,r=this.getScene();if(this._geometry)this._geometry.load(r);else if(i.delayLoadState===t.Engine.DELAYLOADSTATE_NOTLOADED){i.delayLoadState=t.Engine.DELAYLOADSTATE_LOADING,r._addPendingData(i);var n=-1!==this.delayLoadingFile.indexOf(".babylonbinarymeshdata");t.Tools.LoadFile(this.delayLoadingFile,function(i){i instanceof ArrayBuffer?e._delayLoadingFunction(i,e):e._delayLoadingFunction(JSON.parse(i),e),e.delayLoadState=t.Engine.DELAYLOADSTATE_LOADED,r._removePendingData(e)},function(){},r.database,n)}},r.prototype.isInFrustum=function(e){return this.delayLoadState===t.Engine.DELAYLOADSTATE_LOADING?!1:i.prototype.isInFrustum.call(this,e)?(this._checkDelayState(),!0):!1},r.prototype.setMaterialByID=function(t){for(var e=this.getScene().materials,i=0;i<e.length;i++)if(e[i].id===t)return void(this.material=e[i]);var r=this.getScene().multiMaterials;for(i=0;i<r.length;i++)if(r[i].id===t)return void(this.material=r[i])},r.prototype.getAnimatables=function(){var t=[];return this.material&&t.push(this.material),this.skeleton&&t.push(this.skeleton),t},r.prototype.bakeTransformIntoVertices=function(e){if(this.isVerticesDataPresent(t.VertexBuffer.PositionKind)){this._resetPointsArrayCache();for(var i=this.getVerticesData(t.VertexBuffer.PositionKind),r=[],n=0;n<i.length;n+=3)t.Vector3.TransformCoordinates(t.Vector3.FromArray(i,n),e).toArray(r,n);if(this.setVerticesData(t.VertexBuffer.PositionKind,r,this.getVertexBuffer(t.VertexBuffer.PositionKind).isUpdatable()),this.isVerticesDataPresent(t.VertexBuffer.NormalKind)){for(i=this.getVerticesData(t.VertexBuffer.NormalKind),r=[],n=0;n<i.length;n+=3)t.Vector3.TransformNormal(t.Vector3.FromArray(i,n),e).toArray(r,n);this.setVerticesData(t.VertexBuffer.NormalKind,r,this.getVertexBuffer(t.VertexBuffer.NormalKind).isUpdatable())}}},r.prototype._resetPointsArrayCache=function(){this._positions=null},r.prototype._generatePointsArray=function(){if(this._positions)return!0;this._positions=[];var e=this.getVerticesData(t.VertexBuffer.PositionKind);if(!e)return!1;for(var i=0;i<e.length;i+=3)this._positions.push(t.Vector3.FromArray(e,i));return!0},r.prototype.clone=function(t,e,i){return new r(t,this.getScene(),e,this,i)},r.prototype.dispose=function(t){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,t)},r.prototype.applyDisplacementMap=function(e,i,r,n){var o=this,s=this.getScene(),a=function(t){var e=document.createElement("canvas"),s=e.getContext("2d"),a=t.width,h=t.height;e.width=a,e.height=h,s.drawImage(t,0,0);var c=s.getImageData(0,0,a,h).data;o.applyDisplacementMapFromBuffer(c,a,h,i,r),n&&n(o)};t.Tools.LoadImage(e,a,function(){},s.database)},r.prototype.applyDisplacementMapFromBuffer=function(e,i,r,n,o){if(!this.isVerticesDataPresent(t.VertexBuffer.PositionKind)||!this.isVerticesDataPresent(t.VertexBuffer.NormalKind)||!this.isVerticesDataPresent(t.VertexBuffer.UVKind))return void t.Tools.Warn("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing");for(var s=this.getVerticesData(t.VertexBuffer.PositionKind),a=this.getVerticesData(t.VertexBuffer.NormalKind),h=this.getVerticesData(t.VertexBuffer.UVKind),c=t.Vector3.Zero(),l=t.Vector3.Zero(),u=t.Vector2.Zero(),f=0;f<s.length;f+=3){t.Vector3.FromArrayToRef(s,f,c),t.Vector3.FromArrayToRef(a,f,l),t.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),_=e[m]/255,g=e[m+1]/255,v=e[m+2]/255,y=.3*_+.59*g+.11*v;l.normalize(),l.scaleInPlace(n+(o-n)*y),c=c.add(l),c.toArray(s,f)}t.VertexData.ComputeNormals(s,this.getIndices(),a),this.updateVerticesData(t.VertexBuffer.PositionKind,s),this.updateVerticesData(t.VertexBuffer.NormalKind,a)},r.prototype.convertToFlatShadedMesh=function(){for(var e=this.getVerticesDataKinds(),i=[],r=[],n=[],o=!1,s=0;s<e.length;s++){var a=e[s],h=this.getVertexBuffer(a);a!==t.VertexBuffer.NormalKind?(i[a]=h,r[a]=i[a].getData(),n[a]=[]):(o=h.isUpdatable(),e.splice(s,1),s--)}for(var c=this.subMeshes.slice(0),l=this.getIndices(),u=this.getTotalIndices(),f=0;u>f;f++){var d=l[f];for(s=0;s<e.length;s++){a=e[s];for(var p=i[a].getStrideSize(),m=0;p>m;m++)n[a].push(r[a][d*p+m])}}var _=[],g=n[t.VertexBuffer.PositionKind];for(f=0;u>f;f+=3){l[f]=f,l[f+1]=f+1,l[f+2]=f+2;for(var v=t.Vector3.FromArray(g,3*f),y=t.Vector3.FromArray(g,3*(f+1)),x=t.Vector3.FromArray(g,3*(f+2)),b=v.subtract(y),M=x.subtract(y),T=t.Vector3.Normalize(t.Vector3.Cross(b,M)),S=0;3>S;S++)_.push(T.x),_.push(T.y),_.push(T.z)}for(this.setIndices(l),this.setVerticesData(t.VertexBuffer.NormalKind,_,o),s=0;s<e.length;s++)a=e[s],this.setVerticesData(a,n[a],i[a].isUpdatable());this.releaseSubMeshes();for(var A=0;A<c.length;A++){var w=c[A];new t.SubMesh(w.materialIndex,w.indexStart,w.indexCount,w.indexStart,w.indexCount,this)}this.synchronizeInstances()},r.prototype.createInstance=function(e){return new t.InstancedMesh(e,this)},r.prototype.synchronizeInstances=function(){for(var t=0;t<this.instances.length;t++){var e=this.instances[t];e._syncSubMeshes()}},r.prototype.simplify=function(t,e,i,r){void 0===e&&(e=!0),void 0===i&&(i=0),this.getScene().simplificationQueue.addTask({settings:t,parallelProcessing:e,mesh:this,simplificationType:i,successCallback:r})},r.prototype.optimizeIndices=function(e){for(var i=this,r=this.getIndices(),n=this.getVerticesData(t.VertexBuffer.PositionKind),o=[],s=0;s<n.length;s+=3)o.push(t.Vector3.FromArray(n,s));var a=[];t.AsyncLoop.SyncAsyncForLoop(o.length,40,function(t){for(var e=o.length-1-t,i=o[e],r=0;e>r;++r){var n=o[r];if(i.equals(n)){a[e]=r;break}}},function(){for(var t=0;t<r.length;++t)r[t]=a[r[t]]||r[t];var n=i.subMeshes.slice(0);i.setIndices(r),i.subMeshes=n,e&&e(i)})},r.CreateRibbon=function(e,i,n,o,s,a,h,c,l){if(void 0===c&&(c=r.DEFAULTSIDE),void 0===l&&(l=null),l){var u=function(e,i){var r=function(r){for(var n=e[0].length,o=0,s=i==t.Mesh.DOUBLESIDE?2:1,a=1;s>=a;a++)for(var h=0;h<e.length;h++){var c=e[h],l=c.length;n=l>n?n:l;for(var u=0;n>u;)r[o]=c[u].x,r[o+1]=c[u].y,r[o+2]=c[u].z,u++,o+=3}};return r},c=l.sideOrientation,f=u(i,c),d=!l.areNormalsFrozen;return l.updateMeshPositions(f,d),l}var p=new r(e,a);p.sideOrientation=c;var m=t.VertexData.CreateRibbon(i,n,o,s,c);return m.applyToMesh(p,h),p},r.CreateDisc=function(e,i,n,o,s,a){void 0===a&&(a=r.DEFAULTSIDE);var h=new r(e,o),c=t.VertexData.CreateDisc(i,n,a);return c.applyToMesh(h,s),h},r.CreateBox=function(e,i,n,o,s){void 0===s&&(s=r.DEFAULTSIDE);var a=new r(e,n),h=t.VertexData.CreateBox(i,s);return h.applyToMesh(a,o),a},r.CreateSphere=function(e,i,n,o,s,a){void 0===a&&(a=r.DEFAULTSIDE);var h=new r(e,o),c=t.VertexData.CreateSphere(i,n,a);return c.applyToMesh(h,s),h},r.CreateCylinder=function(e,i,n,o,s,a,h,c,l){void 0===l&&(l=r.DEFAULTSIDE),void 0!==h&&h instanceof t.Scene||(void 0!==h&&(c=h),h=a,a=1);var u=new r(e,h),f=t.VertexData.CreateCylinder(i,n,o,s,a);return f.applyToMesh(u,c),u},r.CreateTorus=function(e,i,n,o,s,a,h){void 0===h&&(h=r.DEFAULTSIDE);var c=new r(e,s),l=t.VertexData.CreateTorus(i,n,o,h);
- return l.applyToMesh(c,a),c},r.CreateTorusKnot=function(e,i,n,o,s,a,h,c,l,u){void 0===u&&(u=r.DEFAULTSIDE);var f=new r(e,c),d=t.VertexData.CreateTorusKnot(i,n,o,s,a,h,u);return d.applyToMesh(f,l),f},r.CreateLines=function(e,i,r,n,o){if(void 0===o&&(o=null),o){var s=function(t){var e=function(e){for(var i=0,r=0;r<t.length;r++)e[i]=t[r].x,e[i+1]=t[r].y,e[i+2]=t[r].z,i+=3};return e},a=s(i);return o.updateMeshPositions(a,!1),o}var h=new t.LinesMesh(e,r,n),c=t.VertexData.CreateLines(i);return c.applyToMesh(h,n),h},r.ExtrudeShape=function(t,e,i,n,o,s,a,h,c,l){void 0===c&&(c=r.DEFAULTSIDE),void 0===l&&(l=null),n=n||1,o=o||0;var u=r._ExtrudeShapeGeneric(t,e,i,n,o,null,null,!1,!1,s,!1,a,h,c,l);return u},r.ExtrudeShapeCustom=function(t,e,i,n,o,s,a,h,c,l,u,f){void 0===u&&(u=r.DEFAULTSIDE),void 0===f&&(f=null);var d=r._ExtrudeShapeGeneric(t,e,i,null,null,n,o,s,a,h,!0,c,l,u,f);return d},r._ExtrudeShapeGeneric=function(e,i,n,o,s,a,h,c,l,u,f,d,p,m,_){var g=function(e,i,r,n,o,s,a,h,c,l){for(var u=r.getTangents(),f=r.getNormals(),d=r.getBinormals(),p=r.getDistances(),m=0,_=function(t,e){return o},g=function(t,e){return s},v=l?h:g,y=l?a:_,x=0,b=0;b<i.length;b++){for(var M=new Array,T=v(b,p[b]),S=y(b,p[b]),A=0;A<e.length;A++){var w=t.Matrix.RotationAxis(u[b],m),D=u[b].scale(e[A].z).add(f[b].scale(e[A].x)).add(d[b].scale(e[A].y)),E=t.Vector3.TransformCoordinates(D,w).scaleInPlace(S).add(i[b]);M.push(E)}n[x]=M,m+=T,x++}var C=function(e){var i,r=Array(),n=t.Vector3.Zero();for(i=0;i<e.length;i++)n.addInPlace(e[i]);for(n.scaleInPlace(1/e.length),i=0;i<e.length;i++)r.push(n);return r};switch(c){case t.Mesh.NO_CAP:break;case t.Mesh.CAP_START:n.unshift(C(n[0]));break;case t.Mesh.CAP_END:n.push(C(n[n.length-1]));break;case t.Mesh.CAP_ALL:n.unshift(C(n[0])),n.push(C(n[n.length-1]))}return n};if(_){var v=_.path3D.update(n),y=g(i,n,_.path3D,_.pathArray,o,s,a,h,_.cap,f);return _=r.CreateRibbon(null,y,null,null,null,null,null,null,_)}var v=new t.Path3D(n),x=new Array;u=0>u||u>3?0:u;var y=g(i,n,v,x,o,s,a,h,u,f),b=r.CreateRibbon(e,y,c,l,0,d,p,m);return b.pathArray=y,b.path3D=v,b.cap=u,b},r.CreatePlane=function(e,i,n,o,s){void 0===s&&(s=r.DEFAULTSIDE);var a=new r(e,n),h=t.VertexData.CreatePlane(i,s);return h.applyToMesh(a,o),a},r.CreateGround=function(e,i,r,n,o,s){var a=new t.GroundMesh(e,o);a._setReady(!1),a._subdivisions=n;var h=t.VertexData.CreateGround(i,r,n);return h.applyToMesh(a,s),a._setReady(!0),a},r.CreateTiledGround=function(e,i,n,o,s,a,h,c,l){var u=new r(e,c),f=t.VertexData.CreateTiledGround(i,n,o,s,a,h);return f.applyToMesh(u,l),u},r.CreateGroundFromHeightMap=function(e,i,r,n,o,s,a,h,c,l){var u=new t.GroundMesh(e,h);u._subdivisions=o,u._setReady(!1);var f=function(e){var i=document.createElement("canvas"),h=i.getContext("2d"),f=e.width,d=e.height;i.width=f,i.height=d,h.drawImage(e,0,0);var p=h.getImageData(0,0,f,d).data,m=t.VertexData.CreateGroundFromHeightMap(r,n,o,s,a,p,f,d);m.applyToMesh(u,c),u._setReady(!0),l&&l(u)};return t.Tools.LoadImage(i,f,function(){},h.database),u},r.CreateTube=function(e,i,n,o,s,a,h,c,l,u){void 0===l&&(l=r.DEFAULTSIDE),void 0===u&&(u=null);var f=function(e,i,r,n,o,s,a){for(var h,c,l,u,f,d=i.getTangents(),p=i.getNormals(),m=i.getDistances(),_=2*Math.PI,g=_/o,v=function(t,e){return n},y=s||v,x=0,b=0;b<e.length;b++){c=y(b,m[b]),h=Array(),l=p[b];for(var M=0;o>M;M++)f=t.Matrix.RotationAxis(d[b],g*M),u=t.Vector3.TransformCoordinates(l,f).scaleInPlace(c).add(e[b]),h.push(u);h.push(h[0]),r[x]=h,x++}var T=function(t,i){for(var r=Array(),n=0;t>n;n++)r.push(e[i]);return r};switch(a){case t.Mesh.NO_CAP:break;case t.Mesh.CAP_START:r.unshift(T(o+1,0));break;case t.Mesh.CAP_END:r.push(T(o+1,e.length-1));break;case t.Mesh.CAP_ALL:r.unshift(T(o+1,0)),r.push(T(o+1,e.length-1))}return r};if(u){var d=u.path3D.update(i),p=f(i,d,u.pathArray,n,u.tessellation,s,u.cap);return u=r.CreateRibbon(null,p,null,null,null,null,null,null,u)}var d=new t.Path3D(i),m=new Array;a=0>a||a>3?0:a;var p=f(i,d,m,n,o,s,a),_=r.CreateRibbon(e,p,!1,!0,0,h,c,l);return _.pathArray=p,_.path3D=d,_.tessellation=o,_.cap=a,_},r.CreateDecal=function(e,i,n,o,s,a){void 0===a&&(a=0);var h=i.getIndices(),c=i.getVerticesData(t.VertexBuffer.PositionKind),l=i.getVerticesData(t.VertexBuffer.NormalKind);if(!o){var u=new t.Vector3(0,0,1),f=i.getScene().activeCamera,d=t.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),_=Math.atan2(o.y,m),g=t.Matrix.RotationYawPitchRoll(p,_,a).multiply(t.Matrix.Translation(n.x,n.y,n.z)),v=t.Matrix.Invert(g),y=i.getWorldMatrix(),x=y.multiply(v),b=new t.VertexData;b.indices=[],b.positions=[],b.normals=[],b.uvs=[];for(var M=0,T=function(e){var i=h[e],r=new t.PositionNormalVertex;return r.position=new t.Vector3(c[3*i],c[3*i+1],c[3*i+2]),r.position=t.Vector3.TransformCoordinates(r.position,x),r.normal=new t.Vector3(l[3*i],l[3*i+1],l[3*i+2]),r},S=function(e,i){if(0===e.length)return e;for(var r=.5*Math.abs(t.Vector3.Dot(s,i)),n=function(e,n){var o=t.Vector3.GetClipFactor(e.position,n.position,i,r);return new t.PositionNormalVertex(t.Vector3.Lerp(e.position,n.position,o),t.Vector3.Lerp(e.normal,n.normal,o))},o=new Array,a=0;a<e.length;a+=3){var h,c,l,u,f,d,p,m=0,_=t.Vector3.Dot(e[a].position,i)-r,g=t.Vector3.Dot(e[a+1].position,i)-r,v=t.Vector3.Dot(e[a+2].position,i)-r;switch(h=_>0,c=g>0,l=v>0,m=(h?1:0)+(c?1:0)+(l?1:0)){case 0:o.push(e[a]),o.push(e[a+1]),o.push(e[a+2]);break;case 1:if(h&&(u=e[a+1],f=e[a+2],d=n(e[a],u),p=n(e[a],f)),c){u=e[a],f=e[a+2],d=n(e[a+1],u),p=n(e[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}l&&(u=e[a],f=e[a+1],d=n(e[a+2],u),p=n(e[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=e[a].clone(),f=n(u,e[a+1]),d=n(u,e[a+2]),o.push(u),o.push(f),o.push(d)),c||(u=e[a+1].clone(),f=n(u,e[a+2]),d=n(u,e[a]),o.push(u),o.push(f),o.push(d)),l||(u=e[a+2].clone(),f=n(u,e[a]),d=n(u,e[a+1]),o.push(u),o.push(f),o.push(d));break;case 3:}}return o},A=0;A<h.length;A+=3){var w=new Array;if(w.push(T(A)),w.push(T(A+1)),w.push(T(A+2)),w=S(w,new t.Vector3(1,0,0)),w=S(w,new t.Vector3(-1,0,0)),w=S(w,new t.Vector3(0,1,0)),w=S(w,new t.Vector3(0,-1,0)),w=S(w,new t.Vector3(0,0,1)),w=S(w,new t.Vector3(0,0,-1)),0!==w.length)for(var D=(t.Matrix.RotationYawPitchRoll(p,_,a),0);D<w.length;D++){var E=w[D];b.indices.push(M),E.position.toArray(b.positions,3*M),E.normal.toArray(b.normals,3*M),b.uvs.push(.5+E.position.x/s.x),b.uvs.push(.5+E.position.y/s.y),M++}}var C=new r(e,i.getScene());return b.applyToMesh(C),C.position=n.clone(),C.rotation=new t.Vector3(_,p,a),C},r.MinMax=function(t){var e=null,i=null;for(var r in t){var n=t[r],o=n.getBoundingInfo().boundingBox;e?(e.MinimizeInPlace(o.minimumWorld),i.MaximizeInPlace(o.maximumWorld)):(e=o.minimumWorld,i=o.maximumWorld)}return{min:e,max:i}},r.Center=function(e){var i=void 0!==e.min?e:r.MinMax(e);return t.Vector3.Center(i.min,i.max)},r.MergeMeshes=function(e,i,n,o){if(void 0===i&&(i=!0),!n)for(var s=0,a=0;a<e.length;a++)if(e[a]&&(s+=e[a].getTotalVertices(),s>65536))return t.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,c,l;for(a=0;a<e.length;a++)e[a]&&(c=t.VertexData.ExtractFromMesh(e[a],!0),c.transform(e[a].getWorldMatrix()),h?h.merge(c):(h=c,l=e[a]));if(o||(o=new r(l.name+"_merged",l.getScene())),h.applyToMesh(o),o.material=l.material,o.checkCollisions=l.checkCollisions,i)for(a=0;a<e.length;a++)e[a]&&e[a].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}(t.AbstractMesh);t.Mesh=i}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,e,i,r,n,o,s,a){void 0===a&&(a=!0),this.materialIndex=t,this.verticesStart=e,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 e.prototype.getBoundingInfo=function(){return this._boundingInfo},e.prototype.getMesh=function(){return this._mesh},e.prototype.getRenderingMesh=function(){return this._renderingMesh},e.prototype.getMaterial=function(){var e=this._renderingMesh.material;if(e&&e instanceof t.MultiMaterial){var i=e;return i.getSubMaterial(this.materialIndex)}return e?e:this._mesh.getScene().defaultMaterial},e.prototype.refreshBoundingInfo=function(){var e=this._renderingMesh.getVerticesData(t.VertexBuffer.PositionKind);if(!e)return void(this._boundingInfo=this._mesh._boundingInfo);var i,r=this._renderingMesh.getIndices();i=0===this.indexStart&&this.indexCount===r.length?t.Tools.ExtractMinAndMax(e,this.verticesStart,this.verticesCount):t.Tools.ExtractMinAndMaxIndexed(e,r,this.indexStart,this.indexCount),this._boundingInfo=new t.BoundingInfo(i.minimum,i.maximum)},e.prototype._checkCollision=function(t){return this._boundingInfo._checkCollision(t)},e.prototype.updateBoundingInfo=function(t){this._boundingInfo||this.refreshBoundingInfo(),this._boundingInfo._update(t)},e.prototype.isInFrustum=function(t){return this._boundingInfo.isInFrustum(t)},e.prototype.render=function(){this._renderingMesh.render(this)},e.prototype.getLinesIndexBuffer=function(t,e){if(!this._linesIndexBuffer){for(var i=[],r=this.indexStart;r<this.indexStart+this.indexCount;r+=3)i.push(t[r],t[r+1],t[r+1],t[r+2],t[r+2],t[r]);this._linesIndexBuffer=e.createIndexBuffer(i),this.linesIndexCount=i.length}return this._linesIndexBuffer},e.prototype.canIntersects=function(t){return t.intersectsBox(this._boundingInfo.boundingBox)},e.prototype.intersects=function(t,e,i,r){for(var n=null,o=this.indexStart;o<this.indexStart+this.indexCount;o+=3){var s=e[i[o]],a=e[i[o+1]],h=e[i[o+2]],c=t.intersectsTriangle(s,a,h);if(c){if(c.distance<0)continue;if((r||!n||c.distance<n.distance)&&(n=c,n.faceId=o/3,r))break}}return n},e.prototype.clone=function(i,r){var n=new e(this.materialIndex,this.verticesStart,this.verticesCount,this.indexStart,this.indexCount,i,r,!1);return n._boundingInfo=new t.BoundingInfo(this._boundingInfo.minimum,this._boundingInfo.maximum),n},e.prototype.dispose=function(){this._linesIndexBuffer&&(this._mesh.getScene().getEngine()._releaseBuffer(this._linesIndexBuffer),this._linesIndexBuffer=null);var t=this._mesh.subMeshes.indexOf(this);this._mesh.subMeshes.splice(t,1)},e.CreateFromIndices=function(e,i,r,n,o){var s=Number.MAX_VALUE,a=-Number.MAX_VALUE;o=o||n;for(var h=o.getIndices(),c=i;i+r>c;c++){var l=h[c];s>l&&(s=l),l>a&&(a=l)}return new t.SubMesh(e,s,a-s+1,i,r,n,o)},e}();t.SubMesh=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e){this.delayLoadState=t.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=t.Texture.EXPLICIT_MODE,this.wrapU=t.Texture.WRAP_ADDRESSMODE,this.wrapV=t.Texture.WRAP_ADDRESSMODE,this.anisotropicFilteringLevel=4,this._scene=e,this._scene.textures.push(this)}return e.prototype.getScene=function(){return this._scene},e.prototype.getTextureMatrix=function(){return null},e.prototype.getReflectionTextureMatrix=function(){return null},e.prototype.getInternalTexture=function(){return this._texture},e.prototype.isReady=function(){return this.delayLoadState===t.Engine.DELAYLOADSTATE_NOTLOADED?!0:this._texture?this._texture.isReady:!1},e.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}},e.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}},e.prototype.scale=function(t){},Object.defineProperty(e.prototype,"canRescale",{get:function(){return!1},enumerable:!0,configurable:!0}),e.prototype._removeFromCache=function(t,e){for(var i=this._scene.getEngine().getLoadedTexturesCache(),r=0;r<i.length;r++){var n=i[r];if(n.url===t&&n.noMipmap===e)return void i.splice(r,1)}},e.prototype._getFromCache=function(t,e,i){for(var r=this._scene.getEngine().getLoadedTexturesCache(),n=0;n<r.length;n++){var o=r[n];if(o.url===t&&o.noMipmap===e&&(!i||i===o.samplingMode))return o.references++,o}return null},e.prototype.delayLoad=function(){},e.prototype.releaseInternalTexture=function(){if(this._texture){var t=this._scene.getEngine().getLoadedTexturesCache();if(this._texture.references--,0===this._texture.references){var e=t.indexOf(this._texture);t.splice(e,1),this._scene.getEngine()._releaseTexture(this._texture),delete this._texture}}},e.prototype.clone=function(){return null},e.prototype.dispose=function(){var t=this._scene.textures.indexOf(this);t>=0&&this._scene.textures.splice(t,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDispose&&this.onDispose())},e}();t.BaseTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(r,n,o,s,a,h,c,l,u){void 0===a&&(a=i.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===c&&(c=null),void 0===l&&(l=null),void 0===u&&(u=!1),e.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=l,this._deleteBuffer=u,r&&(this._texture=this._getFromCache(r,o,a),this._texture||(n.useDelayedTextureLoading?this.delayLoadState=t.Engine.DELAYLOADSTATE_NOTLOADED:(this._texture=n.getEngine().createTexture(r,o,s,n,this._samplingMode,h,c,this._buffer),u&&delete this._buffer)))}return __extends(i,e),i.prototype.delayLoad=function(){this.delayLoadState===t.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=t.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(t){this._texture&&this.getScene().getEngine().updateTextureSamplingMode(t,this._texture)},i.prototype._prepareRowForTextureGeneration=function(e,i,r,n){e-=this.uOffset+.5,i-=this.vOffset+.5,r-=.5,t.Vector3.TransformCoordinatesFromFloatsToRef(e,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=t.Matrix.Zero(),this._rowGenerationMatrix=new t.Matrix,this._t0=t.Vector3.Zero(),this._t1=t.Vector3.Zero(),this._t2=t.Vector3.Zero()),t.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),t.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=t.Matrix.Zero(),this._projectionModeMatrix=t.Matrix.Zero()),this._cachedCoordinatesMode=this.coordinatesMode,this.coordinatesMode){case i.SPHERICAL_MODE:t.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:t.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:t.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:t.Matrix.IdentityToRef(this._cachedTextureMatrix)}return this._cachedTextureMatrix},i.prototype.clone=function(){var t=new i(this._texture.url,this.getScene(),this._noMipmap,this._invertY,this._samplingMode);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.wrapU=this.wrapU,t.wrapV=this.wrapV,t.coordinatesIndex=this.coordinatesIndex,t.coordinatesMode=this.coordinatesMode,t.uOffset=this.uOffset,t.vOffset=this.vOffset,t.uScale=this.uScale,t.vScale=this.vScale,t.uAng=this.uAng,t.vAng=this.vAng,t.wAng=this.wAng,t},i.CreateFromBase64String=function(t,e,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:"+e,r,n,o,s,a,h,t)},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}(t.BaseTexture);t.Texture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o){e.call(this,r),this.coordinatesMode=t.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=t.Engine.DELAYLOADSTATE_NOTLOADED:this._texture=r.getEngine().createCubeTexture(i,r,n,o)),this.isCube=!0,this._textureMatrix=t.Matrix.Identity()}return __extends(i,e),i.prototype.clone=function(){var t=new i(this.url,this.getScene(),this._extensions,this._noMipmap);return t.level=this.level,t.wrapU=this.wrapU,t.wrapV=this.wrapV,t.coordinatesIndex=this.coordinatesIndex,t.coordinatesMode=this.coordinatesMode,t},i.prototype.delayLoad=function(){this.delayLoadState===t.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=t.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}(t.BaseTexture);t.CubeTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s,a){void 0===s&&(s=!0),void 0===a&&(a=t.Engine.TEXTURETYPE_UNSIGNED_INT),e.call(this,null,n,!o),this.renderList=new Array,this.renderParticles=!0,this.renderSprites=!1,this.coordinatesMode=t.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 t.RenderingManager(n)}return __extends(i,e),i.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},Object.defineProperty(i.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(t){this._refreshRate=t,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?e.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(t){var e=this._size*t;this.resize(e,this._generateMipMaps)},i.prototype.resize=function(t,e){this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createRenderTargetTexture(t,e)},i.prototype.render=function(e,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){e&&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 c=a[h];if(c){if(!c.isReady()){this.resetRefreshCounter();continue}if(c.isEnabled()&&c.isVisible&&c.subMeshes&&0!==(c.layerMask&r.activeCamera.layerMask)){c._activate(r.getRenderId());for(var l=0;l<c.subMeshes.length;l++){var u=c.subMeshes[l];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),e&&r.postProcessManager._finalizeFrame(!1,this._texture),this._doNotChangeAspectRatio||r.updateTransformMatrix(!0),this.onAfterRender&&this.onAfterRender(),i&&t.Tools.DumpFramebuffer(this._size,this._size,n),n.unBindFramebuffer(this._texture),this.onAfterUnbind&&this.onAfterUnbind()}},i.prototype.clone=function(){var t=this.getSize(),e=new i(this.name,t.width,this.getScene(),this._generateMipMaps);return e.hasAlpha=this.hasAlpha,e.level=this.level,e.coordinatesMode=this.coordinatesMode,e.renderList=this.renderList.slice(0),e},i}(t.Texture);t.RenderTargetTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n,o,s){void 0===s&&(s=!0),t.call(this,null,n,!s),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=e,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(e,t),e.prototype.reset=function(){if(void 0!==this._effect){var t=this.getScene().getEngine();t._releaseEffect(this._effect)}},e.prototype.isReady=function(){var t,e=this,i=this.getScene().getEngine();return this._fragment?this._fallbackTextureUsed?!0:(t=void 0!==this._fragment.fragmentElement?{vertex:"procedural",fragmentElement:this._fragment.fragmentElement}:{vertex:"procedural",fragment:this._fragment},this._effect=i.createEffect(t,["position"],this._uniforms,this._samplers,"",null,null,function(){e.releaseInternalTexture(),e._fallbackTexture&&(e._texture=e._fallbackTexture._texture,e._texture.references++),e._fallbackTextureUsed=!0}),this._effect.isReady()):!1},e.prototype.resetRefreshCounter=function(){this._currentRefreshId=-1},e.prototype.setFragment=function(t){this._fragment=t},Object.defineProperty(e.prototype,"refreshRate",{get:function(){return this._refreshRate},set:function(t){this._refreshRate=t,this.resetRefreshCounter()},enumerable:!0,configurable:!0}),e.prototype._shouldRender=function(){return 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},e.prototype.getRenderSize=function(){return this._size},e.prototype.resize=function(t,e){this._fallbackTextureUsed||(this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createRenderTargetTexture(t,e))},e.prototype._checkUniform=function(t){-1===this._uniforms.indexOf(t)&&this._uniforms.push(t)},e.prototype.setTexture=function(t,e){return-1===this._samplers.indexOf(t)&&this._samplers.push(t),this._textures[t]=e,this},e.prototype.setFloat=function(t,e){return this._checkUniform(t),this._floats[t]=e,this},e.prototype.setFloats=function(t,e){return this._checkUniform(t),this._floatsArrays[t]=e,this},e.prototype.setColor3=function(t,e){return this._checkUniform(t),this._colors3[t]=e,this},e.prototype.setColor4=function(t,e){return this._checkUniform(t),this._colors4[t]=e,this},e.prototype.setVector2=function(t,e){return this._checkUniform(t),this._vectors2[t]=e,this},e.prototype.setVector3=function(t,e){return this._checkUniform(t),this._vectors3[t]=e,this},e.prototype.setMatrix=function(t,e){return this._checkUniform(t),this._matrices[t]=e,this},e.prototype.render=function(t){var e=this.getScene(),i=e.getEngine();i.bindFramebuffer(this._texture),i.clear(e.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)},e.prototype.clone=function(){var t=this.getSize(),i=new e(this.name,t.width,this._fragment,this.getScene(),this._fallbackTexture,this._generateMipMaps);return i.hasAlpha=this.hasAlpha,i.level=this.level,i.coordinatesMode=this.coordinatesMode,i},e.prototype.dispose=function(){var e=this.getScene()._proceduralTextures.indexOf(this);e>=0&&this.getScene()._proceduralTextures.splice(e,1),t.prototype.dispose.call(this)},e}(t.Texture);t.ProceduralTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o){var s=this;e.call(this,i,r,n,o,!0),this.mirrorPlane=new t.Plane(0,1,0,1),this._transformMatrix=t.Matrix.Zero(),this._mirrorMatrix=t.Matrix.Zero(),this.onBeforeRender=function(){t.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,e),i.prototype.clone=function(){var e=this.getSize(),i=new t.MirrorTexture(this.name,e.width,this.getScene(),this._generateMipMaps);return i.hasAlpha=this.hasAlpha,i.level=this.level,i.mirrorPlane=this.mirrorPlane.clone(),i.renderList=this.renderList.slice(0),i},i}(t.RenderTargetTexture);t.MirrorTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s){void 0===s&&(s=t.Texture.TRILINEAR_SAMPLINGMODE),e.call(this,null,n,!o),this.name=i,this.wrapU=t.Texture.CLAMP_ADDRESSMODE,this.wrapV=t.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,e),Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype.scale=function(t){var e=this.getSize();e.width*=t,e.height*=t,this._canvas.width=e.width,this._canvas.height=e.height,this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createDynamicTexture(e.width,e.height,this._generateMipMaps,this._samplingMode)},i.prototype.getContext=function(){return this._context},i.prototype.clear=function(){var t=this.getSize();this._context.fillRect(0,0,t.width,t.height)},i.prototype.update=function(t){this.getScene().getEngine().updateDynamicTexture(this._texture,this._canvas,void 0===t?!0:t)},i.prototype.drawText=function(t,e,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===e){var c=this._context.measureText(t);e=(h.width-c.width)/2}this._context.fillStyle=n,this._context.fillText(t,e,i),a&&this.update(s)},i.prototype.clone=function(){var t=this.getSize(),e=new i(this.name,t.width,this.getScene(),this._generateMipMaps);return e.hasAlpha=this.hasAlpha,e.level=this.level,e.wrapU=this.wrapU,e.wrapV=this.wrapV,e},i}(t.Texture);t.DynamicTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s,a,h){var c=this;void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),e.call(this,null,o,!s,a),this._autoLaunch=!0,this.name=i,this.wrapU=t.Texture.WRAP_ADDRESSMODE,
- this.wrapV=t.Texture.WRAP_ADDRESSMODE;var l=n.width||n,u=n.height||n;this._texture=o.getEngine().createDynamicTexture(l,u,s,h);var f=this.getSize();this.video=document.createElement("video"),this.video.width=f.width,this.video.height=f.height,this.video.autoplay=!1,this.video.loop=!0,this.video.addEventListener("canplaythrough",function(){c._texture&&(c._texture.isReady=!0)}),r.forEach(function(t){var e=document.createElement("source");e.src=t,c.video.appendChild(e)}),this._lastUpdate=t.Tools.Now}return __extends(i,e),i.prototype.update=function(){this._autoLaunch&&(this._autoLaunch=!1,this.video.play());var e=t.Tools.Now;return e-this._lastUpdate<15?!1:(this._lastUpdate=e,this.getScene().getEngine().updateVideoTexture(this._texture,this.video,this._invertY),!0)},i}(t.Texture);t.VideoTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i,r,n,o,s){e.call(this,t,r,null,n,o,s),this._animate=!0,this._time=0,this._texturePath=i,this.loadJson(i),this.refreshRate=1}return __extends(i,e),i.prototype.loadJson=function(e){function i(){t.Tools.Log("No config file found in "+e+" trying to use ShadersStore or DOM element");try{n.setFragment(n._texturePath)}catch(i){t.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}}var r=this,n=this,o=e+"/config.json",s=new XMLHttpRequest;s.open("GET",o,!0),s.addEventListener("load",function(){if(200===s.status||t.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(e){i()}else i()},!1),s.addEventListener("error",function(){i()},!1);try{s.send()}catch(a){t.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},i.prototype.isReady=function(){if(!e.prototype.isReady.call(this))return!1;for(var t in this._textures){var i=this._textures[t];if(!i.isReady())return!1}return!0},i.prototype.render=function(t){this._animate&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),e.prototype.render.call(this,t)},i.prototype.updateTextures=function(){for(var e=0;e<this._config.sampler2Ds.length;e++)this.setTexture(this._config.sampler2Ds[e].sample2Dname,new t.Texture(this._texturePath+"/"+this._config.sampler2Ds[e].textureRelativeUrl,this.getScene()))},i.prototype.updateShaderUniforms=function(){if(this._config)for(var e=0;e<this._config.uniforms.length;e++){var i=this._config.uniforms[e];switch(i.type){case"float":this.setFloat(i.name,i.value);break;case"color3":this.setColor3(i.name,new t.Color3(i.r,i.g,i.b));break;case"color4":this.setColor4(i.name,new t.Color4(i.r,i.g,i.b,i.a));break;case"vector2":this.setVector2(i.name,new t.Vector2(i.x,i.y));break;case"vector3":this.setVector3(i.name,new t.Vector3(i.x,i.y,i.z))}}this.setFloat("time",this._time)},Object.defineProperty(i.prototype,"animate",{get:function(){return this._animate},set:function(t){this._animate=t},enumerable:!0,configurable:!0}),i}(t.ProceduralTexture);t.CustomProceduralTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s){e.call(this,i,r,"wood",n,o,s),this._ampScale=100,this._woodColor=new t.Color3(.32,.17,.09),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,e),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(t){this._ampScale=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"woodColor",{get:function(){return this._woodColor},set:function(t){this._woodColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(t.ProceduralTexture);t.WoodProceduralTexture=e;var i=function(e){function i(r,n,o,s,a){e.call(this,r,n,"fire",o,s,a),this._time=0,this._speed=new t.Vector2(.5,.3),this._autoGenerateTime=!0,this._alphaThreshold=.5,this._fireColors=i.RedFireColors,this.updateShaderUniforms(),this.refreshRate=1}return __extends(i,e),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(t){this._autoGenerateTime&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),e.prototype.render.call(this,t)},Object.defineProperty(i,"PurpleFireColors",{get:function(){return[new t.Color3(.5,0,1),new t.Color3(.9,0,1),new t.Color3(.2,0,1),new t.Color3(1,.9,1),new t.Color3(.1,.1,1),new t.Color3(.9,.9,1)]},enumerable:!0,configurable:!0}),Object.defineProperty(i,"GreenFireColors",{get:function(){return[new t.Color3(.5,1,0),new t.Color3(.5,1,0),new t.Color3(.3,.4,0),new t.Color3(.5,1,0),new t.Color3(.2,0,0),new t.Color3(.5,1,0)]},enumerable:!0,configurable:!0}),Object.defineProperty(i,"RedFireColors",{get:function(){return[new t.Color3(.5,0,.1),new t.Color3(.9,0,0),new t.Color3(.2,0,0),new t.Color3(1,.9,0),new t.Color3(.1,.1,.1),new t.Color3(.9,.9,.9)]},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BlueFireColors",{get:function(){return[new t.Color3(.1,0,.5),new t.Color3(0,0,.5),new t.Color3(.1,0,.2),new t.Color3(0,0,1),new t.Color3(.1,.2,.3),new t.Color3(0,.2,.9)]},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"fireColors",{get:function(){return this._fireColors},set:function(t){this._fireColors=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"time",{get:function(){return this._time},set:function(t){this._time=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"speed",{get:function(){return this._speed},set:function(t){this._speed=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"alphaThreshold",{get:function(){return this._alphaThreshold},set:function(t){this._alphaThreshold=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(t.ProceduralTexture);t.FireProceduralTexture=i;var r=function(e){function i(i,r,n,o,s){e.call(this,i,r,"cloud",n,o,s),this._skyColor=new t.Color3(.15,.68,1),this._cloudColor=new t.Color3(1,1,1),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,e),i.prototype.updateShaderUniforms=function(){this.setColor3("skyColor",this._skyColor),this.setColor3("cloudColor",this._cloudColor)},Object.defineProperty(i.prototype,"skyColor",{get:function(){return this._skyColor},set:function(t){this._skyColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"cloudColor",{get:function(){return this._cloudColor},set:function(t){this._cloudColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(t.ProceduralTexture);t.CloudProceduralTexture=r;var n=function(e){function i(i,r,n,o,s){e.call(this,i,r,"grass",n,o,s),this._herb1=new t.Color3(.29,.38,.02),this._herb2=new t.Color3(.36,.49,.09),this._herb3=new t.Color3(.51,.6,.28),this._groundColor=new t.Color3(1,1,1),this._grassColors=[new t.Color3(.29,.38,.02),new t.Color3(.36,.49,.09),new t.Color3(.51,.6,.28)],this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,e),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(t){this._grassColors=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"groundColor",{get:function(){return this._groundColor},set:function(t){this.groundColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(t.ProceduralTexture);t.GrassProceduralTexture=n;var o=function(e){function i(i,r,n,o,s){e.call(this,i,r,"road",n,o,s),this._roadColor=new t.Color3(.53,.53,.53),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,e),i.prototype.updateShaderUniforms=function(){this.setColor3("roadColor",this._roadColor)},Object.defineProperty(i.prototype,"roadColor",{get:function(){return this._roadColor},set:function(t){this._roadColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(t.ProceduralTexture);t.RoadProceduralTexture=o;var s=function(e){function i(i,r,n,o,s){e.call(this,i,r,"brick",n,o,s),this._numberOfBricksHeight=15,this._numberOfBricksWidth=5,this._jointColor=new t.Color3(.72,.72,.72),this._brickColor=new t.Color3(.77,.47,.4),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,e),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(t){this._numberOfBricksHeight=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"numberOfBricksWidth",{get:function(){return this._numberOfBricksWidth},set:function(t){this._numberOfBricksHeight=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"jointColor",{get:function(){return this._jointColor},set:function(t){this._jointColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"brickColor",{get:function(){return this._brickColor},set:function(t){this._brickColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(t.ProceduralTexture);t.BrickProceduralTexture=s;var a=function(e){function i(i,r,n,o,s){e.call(this,i,r,"marble",n,o,s),this._numberOfTilesHeight=3,this._numberOfTilesWidth=3,this._amplitude=9,this._marbleColor=new t.Color3(.77,.47,.4),this._jointColor=new t.Color3(.72,.72,.72),this.updateShaderUniforms(),this.refreshRate=0}return __extends(i,e),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(t){this._numberOfTilesHeight=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"numberOfTilesWidth",{get:function(){return this._numberOfTilesWidth},set:function(t){this._numberOfTilesWidth=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"jointColor",{get:function(){return this._jointColor},set:function(t){this._jointColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"marbleColor",{get:function(){return this._marbleColor},set:function(t){this._marbleColor=t,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),i}(t.ProceduralTexture);t.MarbleProceduralTexture=a}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(){this._defines={},this._currentRank=32,this._maxRank=-1}return t.prototype.addFallback=function(t,e){this._defines[t]||(t<this._currentRank&&(this._currentRank=t),t>this._maxRank&&(this._maxRank=t),this._defines[t]=new Array),this._defines[t].push(e)},Object.defineProperty(t.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),t.prototype.reduce=function(t){for(var e=this._defines[this._currentRank],i=0;i<e.length;i++)t=t.replace("#define "+e[i],"");return this._currentRank++,t},t}();t.EffectFallbacks=e;var i=function(){function e(t,e,i,r,n,o,s,a,h){var c=this;this._isReady=!1,this._compilationError="",this._valueCache=[],this._engine=n,this.name=t,this.defines=o,this._uniformsNames=i.concat(r),this._samplers=r,this._attributesNames=e,this.onError=h,this.onCompiled=a;var l,u;t.vertexElement?(l=document.getElementById(t.vertexElement),l||(l=t.vertexElement)):l=t.vertex||t,t.fragmentElement?(u=document.getElementById(t.fragmentElement),u||(u=t.fragmentElement)):u=t.fragment||t,this._loadVertexShader(l,function(t){c._loadFragmentShader(u,function(i){c._prepareEffect(t,i,e,o,s)})})}return e.prototype.isReady=function(){return this._isReady},e.prototype.getProgram=function(){return this._program},e.prototype.getAttributesNames=function(){return this._attributesNames},e.prototype.getAttributeLocation=function(t){return this._attributes[t]},e.prototype.getAttributeLocationByName=function(t){var e=this._attributesNames.indexOf(t);return this._attributes[e]},e.prototype.getAttributesCount=function(){return this._attributes.length},e.prototype.getUniformIndex=function(t){return this._uniformsNames.indexOf(t)},e.prototype.getUniform=function(t){return this._uniforms[this._uniformsNames.indexOf(t)]},e.prototype.getSamplers=function(){return this._samplers},e.prototype.getCompilationError=function(){return this._compilationError},e.prototype._loadVertexShader=function(i,r){if(i instanceof HTMLElement){var n=t.Tools.GetDOMTextContent(i);return void r(n)}if(e.ShadersStore[i+"VertexShader"])return void r(e.ShadersStore[i+"VertexShader"]);var o;o="."===i[0]?i:t.Engine.ShadersRepository+i,t.Tools.LoadFile(o+".vertex.fx",r)},e.prototype._loadFragmentShader=function(i,r){if(i instanceof HTMLElement){var n=t.Tools.GetDOMTextContent(i);return void r(n)}if(e.ShadersStore[i+"PixelShader"])return void r(e.ShadersStore[i+"PixelShader"]);if(e.ShadersStore[i+"FragmentShader"])return void r(e.ShadersStore[i+"FragmentShader"]);var o;o="."===i[0]?i:t.Engine.ShadersRepository+i,t.Tools.LoadFile(o+".fragment.fx",r)},e.prototype._prepareEffect=function(e,i,r,n,o){try{var s=this._engine;s.getCaps().highPrecisionShaderSupported||(e=e.replace("precision highp float","precision mediump float"),i=i.replace("precision highp float","precision mediump float")),this._program=s.createShaderProgram(e,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(c){if(-1!==c.message.indexOf("highp"))return e=e.replace("precision highp float","precision mediump float"),i=i.replace("precision highp float","precision mediump float"),void this._prepareEffect(e,i,r,n,o);o&&o.isMoreFallbacks?(n=o.reduce(n),this._prepareEffect(e,i,r,n,o)):(t.Tools.Error("Unable to compile effect: "+this.name),t.Tools.Error("Defines: "+n),t.Tools.Error("Error: "+c.message),this._compilationError=c.message,this.onError&&this.onError(this,this._compilationError))}},e.prototype._bindTexture=function(t,e){this._engine._bindTexture(this._samplers.indexOf(t),e)},e.prototype.setTexture=function(t,e){this._engine.setTexture(this._samplers.indexOf(t),e)},e.prototype.setTextureFromPostProcess=function(t,e){this._engine.setTextureFromPostProcess(this._samplers.indexOf(t),e)},e.prototype._cacheFloat2=function(t,e,i){return this._valueCache[t]?(this._valueCache[t][0]=e,void(this._valueCache[t][1]=i)):void(this._valueCache[t]=[e,i])},e.prototype._cacheFloat3=function(t,e,i,r){return this._valueCache[t]?(this._valueCache[t][0]=e,this._valueCache[t][1]=i,void(this._valueCache[t][2]=r)):void(this._valueCache[t]=[e,i,r])},e.prototype._cacheFloat4=function(t,e,i,r,n){return this._valueCache[t]?(this._valueCache[t][0]=e,this._valueCache[t][1]=i,this._valueCache[t][2]=r,void(this._valueCache[t][3]=n)):void(this._valueCache[t]=[e,i,r,n])},e.prototype.setArray=function(t,e){return this._engine.setArray(this.getUniform(t),e),this},e.prototype.setArray2=function(t,e){return this._engine.setArray2(this.getUniform(t),e),this},e.prototype.setArray3=function(t,e){return this._engine.setArray3(this.getUniform(t),e),this},e.prototype.setArray4=function(t,e){return this._engine.setArray4(this.getUniform(t),e),this},e.prototype.setMatrices=function(t,e){return this._engine.setMatrices(this.getUniform(t),e),this},e.prototype.setMatrix=function(t,e){return this._engine.setMatrix(this.getUniform(t),e),this},e.prototype.setFloat=function(t,e){return this._valueCache[t]&&this._valueCache[t]===e?this:(this._valueCache[t]=e,this._engine.setFloat(this.getUniform(t),e),this)},e.prototype.setBool=function(t,e){return this._valueCache[t]&&this._valueCache[t]===e?this:(this._valueCache[t]=e,this._engine.setBool(this.getUniform(t),e?1:0),this)},e.prototype.setVector2=function(t,e){return this._valueCache[t]&&this._valueCache[t][0]===e.x&&this._valueCache[t][1]===e.y?this:(this._cacheFloat2(t,e.x,e.y),this._engine.setFloat2(this.getUniform(t),e.x,e.y),this)},e.prototype.setFloat2=function(t,e,i){return this._valueCache[t]&&this._valueCache[t][0]===e&&this._valueCache[t][1]===i?this:(this._cacheFloat2(t,e,i),this._engine.setFloat2(this.getUniform(t),e,i),this)},e.prototype.setVector3=function(t,e){return this._valueCache[t]&&this._valueCache[t][0]===e.x&&this._valueCache[t][1]===e.y&&this._valueCache[t][2]===e.z?this:(this._cacheFloat3(t,e.x,e.y,e.z),this._engine.setFloat3(this.getUniform(t),e.x,e.y,e.z),this)},e.prototype.setFloat3=function(t,e,i,r){return this._valueCache[t]&&this._valueCache[t][0]===e&&this._valueCache[t][1]===i&&this._valueCache[t][2]===r?this:(this._cacheFloat3(t,e,i,r),this._engine.setFloat3(this.getUniform(t),e,i,r),this)},e.prototype.setFloat4=function(t,e,i,r,n){return this._valueCache[t]&&this._valueCache[t][0]===e&&this._valueCache[t][1]===i&&this._valueCache[t][2]===r&&this._valueCache[t][3]===n?this:(this._cacheFloat4(t,e,i,r,n),this._engine.setFloat4(this.getUniform(t),e,i,r,n),this)},e.prototype.setColor3=function(t,e){return this._valueCache[t]&&this._valueCache[t][0]===e.r&&this._valueCache[t][1]===e.g&&this._valueCache[t][2]===e.b?this:(this._cacheFloat3(t,e.r,e.g,e.b),this._engine.setColor3(this.getUniform(t),e),this)},e.prototype.setColor4=function(t,e,i){return this._valueCache[t]&&this._valueCache[t][0]===e.r&&this._valueCache[t][1]===e.g&&this._valueCache[t][2]===e.b&&this._valueCache[t][3]===i?this:(this._cacheFloat4(t,e.r,e.g,e.b,i),this._engine.setColor4(this.getUniform(t),e,i),this)},e.ShadersStore={},e}();t.Effect=i}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(e,i,r){this.name=e,this.checkReadyOnEveryCall=!0,this.checkReadyOnlyOnce=!1,this.state="",this.alpha=1,this.backFaceCulling=!0,this._wasPreviouslyReady=!1,this._fillMode=t.TriangleFillMode,this.pointSize=1,this.zOffset=0,this.id=e,this._scene=i,r||i.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(t){this._fillMode=t},enumerable:!0,configurable:!0}),t.prototype.isReady=function(t,e){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(t,e){},t.prototype._preBind=function(){var t=this._scene.getEngine();t.enableEffect(this._effect),t.setState(this.backFaceCulling,this.zOffset)},t.prototype.bind=function(t,e){this._scene._cachedMaterial=this,this.onBind&&this.onBind(this,e)},t.prototype.bindOnlyWorldMatrix=function(t){},t.prototype.unbind=function(){},t.prototype.dispose=function(t){var e=this._scene.materials.indexOf(this);this._scene.materials.splice(e,1),t&&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}();t.Material=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=4,i=function(){function e(){this.isEnabled=!0,this.leftColor=t.Color3.White(),this.rightColor=t.Color3.Black(),this.bias=0,this.power=1}return e}();t.FresnelParameters=i;var r=function(i){function r(e,r){var n=this;i.call(this,e,r),this.ambientColor=new t.Color3(0,0,0),this.diffuseColor=new t.Color3(1,1,1),this.specularColor=new t.Color3(1,1,1),this.specularPower=64,this.emissiveColor=new t.Color3(0,0,0),this.useAlphaFromDiffuseTexture=!1,this.useSpecularOverAlpha=!0,this.fogEnabled=!0,this._cachedDefines=null,this._renderTargets=new t.SmartArray(16),this._worldViewProjectionMatrix=t.Matrix.Zero(),this._globalAmbientColor=new t.Color3(0,0,0),this._scaledDiffuse=new t.Color3,this._scaledSpecular=new t.Color3,this.getRenderTargetTextures=function(){return n._renderTargets.reset(),n.reflectionTexture&&n.reflectionTexture.isRenderTarget&&n._renderTargets.push(n.reflectionTexture),n._renderTargets}}return __extends(r,i),r.prototype.needAlphaBlending=function(){return this.alpha<1||null!=this.opacityTexture||this._shouldUseAlphaFromDiffuseTexture()||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled},r.prototype.needAlphaTesting=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha},r.prototype._shouldUseAlphaFromDiffuseTexture=function(){return null!=this.diffuseTexture&&this.diffuseTexture.hasAlpha&&this.useAlphaFromDiffuseTexture},r.prototype.getAlphaTestTexture=function(){return this.diffuseTexture},r.prototype.isReady=function(i,n){this.checkReadyOnlyOnce&&this._wasPreviouslyReady;var o=this.getScene();this.checkReadyOnEveryCall||this._renderId===o.getRenderId();var s=o.getEngine(),a=[],h=new t.EffectFallbacks,c=!1,l=!1;if(o.texturesEnabled){if(this.diffuseTexture&&r.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;l=!0,a.push("#define DIFFUSE")}if(this.ambientTexture&&r.AmbientTextureEnabled){if(!this.ambientTexture.isReady())return!1;l=!0,a.push("#define AMBIENT")}if(this.opacityTexture&&r.OpacityTextureEnabled){if(!this.opacityTexture.isReady())return!1;l=!0,a.push("#define OPACITY"),this.opacityTexture.getAlphaFromRGB&&a.push("#define OPACITYRGB")}if(this.reflectionTexture&&r.ReflectionTextureEnabled){if(!this.reflectionTexture.isReady())return!1;c=!0,l=!0,a.push("#define REFLECTION"),h.addFallback(0,"REFLECTION")}if(this.emissiveTexture&&r.EmissiveTextureEnabled){if(!this.emissiveTexture.isReady())return!1;l=!0,a.push("#define EMISSIVE")}if(this.specularTexture&&r.SpecularTextureEnabled){if(!this.specularTexture.isReady())return!1;l=!0,a.push("#define SPECULAR"),h.addFallback(0,"SPECULAR")}}if(o.getEngine().getCaps().standardDerivatives&&this.bumpTexture&&r.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;l=!0,a.push("#define BUMP"),h.addFallback(0,"BUMP")}this.useSpecularOverAlpha&&(a.push("#define SPECULAROVERALPHA"),h.addFallback(0,"SPECULAROVERALPHA")),o.clipPlane&&a.push("#define CLIPPLANE"),s.getAlphaTesting()&&a.push("#define ALPHATEST"),this._shouldUseAlphaFromDiffuseTexture()&&a.push("#define ALPHAFROMDIFFUSE"),(this.pointsCloud||o.forcePointsCloud)&&a.push("#define POINTSIZE"),o.fogEnabled&&i&&i.applyFog&&o.fogMode!==t.Scene.FOGMODE_NONE&&this.fogEnabled&&(a.push("#define FOG"),h.addFallback(1,"FOG"));var u=!1,f=0;if(o.lightsEnabled)for(var d=0;d<o.lights.length;d++){var p=o.lights[d];if(p.isEnabled()){if(p._excludedMeshesIds.length>0){for(var m=0;m<p._excludedMeshesIds.length;m++){var _=o.getMeshByID(p._excludedMeshesIds[m]);_&&p.excludedMeshes.push(_)}p._excludedMeshesIds=[]}if(p._includedOnlyMeshesIds.length>0){for(var g=0;g<p._includedOnlyMeshesIds.length;g++){var v=o.getMeshByID(p._includedOnlyMeshesIds[g]);v&&p.includedOnlyMeshes.push(v)}p._includedOnlyMeshesIds=[]}if(p.canAffectMesh(i)){c=!0,a.push("#define LIGHT"+f),f>0&&h.addFallback(f,"LIGHT"+f);var y;if(y=p instanceof t.SpotLight?"#define SPOTLIGHT"+f:p instanceof t.HemisphericLight?"#define HEMILIGHT"+f:"#define POINTDIRLIGHT"+f,a.push(y),f>0&&h.addFallback(f,y.replace("#define ","")),o.shadowsEnabled){var x=p.getShadowGenerator();i&&i.receiveShadows&&x&&(a.push("#define SHADOW"+f),h.addFallback(0,"SHADOW"+f),u||(a.push("#define SHADOWS"),u=!0),(x.useVarianceShadowMap||x.useBlurVarianceShadowMap)&&(a.push("#define SHADOWVSM"+f),f>0&&h.addFallback(0,"SHADOWVSM"+f)),x.usePoissonSampling&&(a.push("#define SHADOWPCF"+f),f>0&&h.addFallback(0,"SHADOWPCF"+f)))}if(f++,f===e)break}}}if(r.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled||this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled||this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled)){var b=1;this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(a.push("#define DIFFUSEFRESNEL"),h.addFallback(b,"DIFFUSEFRESNEL"),b++),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&(a.push("#define OPACITYFRESNEL"),h.addFallback(b,"OPACITYFRESNEL"),b++),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(a.push("#define REFLECTIONFRESNEL"),h.addFallback(b,"REFLECTIONFRESNEL"),b++),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(a.push("#define EMISSIVEFRESNEL"),h.addFallback(b,"EMISSIVEFRESNEL"),b++),c=!0,a.push("#define FRESNEL"),h.addFallback(b-1,"FRESNEL")}var M=[t.VertexBuffer.PositionKind];i&&(c&&i.isVerticesDataPresent(t.VertexBuffer.NormalKind)&&(M.push(t.VertexBuffer.NormalKind),a.push("#define NORMAL")),l&&(i.isVerticesDataPresent(t.VertexBuffer.UVKind)&&(M.push(t.VertexBuffer.UVKind),a.push("#define UV1")),i.isVerticesDataPresent(t.VertexBuffer.UV2Kind)&&(M.push(t.VertexBuffer.UV2Kind),a.push("#define UV2"))),i.useVertexColors&&i.isVerticesDataPresent(t.VertexBuffer.ColorKind)&&(M.push(t.VertexBuffer.ColorKind),a.push("#define VERTEXCOLOR"),i.hasVertexAlpha&&a.push("#define VERTEXALPHA")),i.useBones&&(M.push(t.VertexBuffer.MatricesIndicesKind),M.push(t.VertexBuffer.MatricesWeightsKind),a.push("#define BONES"),a.push("#define BonesPerMesh "+(i.skeleton.bones.length+1)),a.push("#define BONES4"),h.addFallback(0,"BONES4")),n&&(a.push("#define INSTANCES"),M.push("world0"),M.push("world1"),M.push("world2"),M.push("world3")));var T=a.join("\n");if(this._cachedDefines!==T){this._cachedDefines=T,o.resetCachedMaterial();var S="default";o.getEngine().getCaps().standardDerivatives||(S="legacydefault"),this._effect=o.getEngine().createEffect(S,M,["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"],["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],T,h,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0,!0):!1},r.prototype.unbind=function(){this.reflectionTexture&&this.reflectionTexture.isRenderTarget&&this._effect.setTexture("reflection2DSampler",null)},r.prototype.bindOnlyWorldMatrix=function(t){this._effect.setMatrix("world",t)},r.prototype.bind=function(n,o){var s=this.getScene();if(this.bindOnlyWorldMatrix(n),this._effect.setMatrix("viewProjection",s.getTransformMatrix()),o&&o.useBones&&this._effect.setMatrices("mBones",o.skeleton.getTransformMatrices()),s.getCachedMaterial()!==this){if(r.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 t.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&&r.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&&r.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&&r.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&&r.ReflectionTextureEnabled&&(this.reflectionTexture.isCube?this._effect.setTexture("reflectionCubeSampler",this.reflectionTexture):this._effect.setTexture("reflection2DSampler",this.reflectionTexture),this._effect.setMatrix("reflectionMatrix",this.reflectionTexture.getReflectionTextureMatrix()),this._effect.setFloat3("vReflectionInfos",this.reflectionTexture.coordinatesMode,this.reflectionTexture.level,this.reflectionTexture.isCube?1:0)),this.emissiveTexture&&r.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&&r.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&&r.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*t.Tools.Clamp(1-this.emissiveColor.r),this._scaledSpecular.g=this.specularColor.g*t.Tools.Clamp(1-this.emissiveColor.g),this._scaledSpecular.b=this.specularColor.b*t.Tools.Clamp(1-this.emissiveColor.b),this._effect.setVector3("vEyePosition",s.activeCamera.position),this._effect.setColor3("vAmbientColor",this._globalAmbientColor),this._effect.setColor4("vSpecularColor",this._scaledSpecular,this.specularPower),this._effect.setColor3("vEmissiveColor",this.emissiveColor)}if(this._scaledDiffuse.r=this.diffuseColor.r*t.Tools.Clamp(1-this.emissiveColor.r),this._scaledDiffuse.g=this.diffuseColor.g*t.Tools.Clamp(1-this.emissiveColor.g),this._scaledDiffuse.b=this.diffuseColor.b*t.Tools.Clamp(1-this.emissiveColor.b),this._effect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*o.visibility),s.lightsEnabled)for(var h=0,c=0;c<s.lights.length;c++){var l=s.lights[c];if(l.isEnabled()&&l.canAffectMesh(o)){if(l instanceof t.PointLight?l.transferToEffect(this._effect,"vLightData"+h):l instanceof t.DirectionalLight?l.transferToEffect(this._effect,"vLightData"+h):l instanceof t.SpotLight?l.transferToEffect(this._effect,"vLightData"+h,"vLightDirection"+h):l instanceof t.HemisphericLight&&l.transferToEffect(this._effect,"vLightData"+h,"vLightGround"+h),l.diffuse.scaleToRef(l.intensity,this._scaledDiffuse),l.specular.scaleToRef(l.intensity,this._scaledSpecular),this._effect.setColor4("vLightDiffuse"+h,this._scaledDiffuse,l.range),this._effect.setColor3("vLightSpecular"+h,this._scaledSpecular),s.shadowsEnabled){var u=l.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===e)break}}(s.fogEnabled&&o.applyFog&&s.fogMode!==t.Scene.FOGMODE_NONE||this.reflectionTexture)&&this._effect.setMatrix("view",s.getViewMatrix()),s.fogEnabled&&o.applyFog&&s.fogMode!==t.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,n,o)},r.prototype.getAnimatables=function(){var t=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&t.push(this.diffuseTexture),this.ambientTexture&&this.ambientTexture.animations&&this.ambientTexture.animations.length>0&&t.push(this.ambientTexture),this.opacityTexture&&this.opacityTexture.animations&&this.opacityTexture.animations.length>0&&t.push(this.opacityTexture),this.reflectionTexture&&this.reflectionTexture.animations&&this.reflectionTexture.animations.length>0&&t.push(this.reflectionTexture),this.emissiveTexture&&this.emissiveTexture.animations&&this.emissiveTexture.animations.length>0&&t.push(this.emissiveTexture),this.specularTexture&&this.specularTexture.animations&&this.specularTexture.animations.length>0&&t.push(this.specularTexture),this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&t.push(this.bumpTexture),t},r.prototype.dispose=function(t){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,t)},r.prototype.clone=function(t){var e=new r(t,this.getScene());return e.checkReadyOnEveryCall=this.checkReadyOnEveryCall,e.alpha=this.alpha,e.fillMode=this.fillMode,e.backFaceCulling=this.backFaceCulling,this.diffuseTexture&&this.diffuseTexture.clone&&(e.diffuseTexture=this.diffuseTexture.clone()),this.ambientTexture&&this.ambientTexture.clone&&(e.ambientTexture=this.ambientTexture.clone()),this.opacityTexture&&this.opacityTexture.clone&&(e.opacityTexture=this.opacityTexture.clone()),this.reflectionTexture&&this.reflectionTexture.clone&&(e.reflectionTexture=this.reflectionTexture.clone()),this.emissiveTexture&&this.emissiveTexture.clone&&(e.emissiveTexture=this.emissiveTexture.clone()),this.specularTexture&&this.specularTexture.clone&&(e.specularTexture=this.specularTexture.clone()),this.bumpTexture&&this.bumpTexture.clone&&(e.bumpTexture=this.bumpTexture.clone()),e.ambientColor=this.ambientColor.clone(),e.diffuseColor=this.diffuseColor.clone(),e.specularColor=this.specularColor.clone(),e.specularPower=this.specularPower,e.emissiveColor=this.emissiveColor.clone(),e},r.DiffuseTextureEnabled=!0,r.AmbientTextureEnabled=!0,r.OpacityTextureEnabled=!0,r.ReflectionTextureEnabled=!0,r.EmissiveTextureEnabled=!0,r.SpecularTextureEnabled=!0,r.BumpTextureEnabled=!0,r.FresnelEnabled=!0,r}(t.Material);t.StandardMaterial=r}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i){t.call(this,e,i,!0),this.subMaterials=new Array,i.multiMaterials.push(this)}return __extends(e,t),e.prototype.getSubMaterial=function(t){return 0>t||t>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[t]},e.prototype.isReady=function(t){for(var e=0;e<this.subMaterials.length;e++){var i=this.subMaterials[e];if(i&&!this.subMaterials[e].isReady(t))return!1}return!0},e}(t.Material);t.MultiMaterial=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(){}return Object.defineProperty(e,"ForceFullSceneLoadingForIncremental",{get:function(){return e._ForceFullSceneLoadingForIncremental},set:function(t){e._ForceFullSceneLoadingForIncremental=t},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ShowLoadingScreen",{get:function(){return e._ShowLoadingScreen},set:function(t){e._ShowLoadingScreen=t},enumerable:!0,configurable:!0}),e._getPluginForFilename=function(t){var e=t.lastIndexOf("."),i=t.indexOf("?");-1===i&&(i=t.length);for(var r=t.substring(e,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]},e.RegisterPlugin=function(t){t.extensions=t.extensions.toLowerCase(),e._registeredPlugins.push(t)},e.ImportMesh=function(i,r,n,o,s,a,h){if(n.substr&&"/"===n.substr(0,1))return void t.Tools.Error("Wrong sceneFilename parameter");var c=function(c){o.database=l;var u=e._getPluginForFilename(n),f=function(t){var e=[],a=[],c=[];try{if(!u.importMesh(i,o,t,r,e,a,c))return void(h&&h(o,"unable to load the scene"))}catch(l){return void(h&&h(o,l))}s&&(o.importedMeshesFiles.push(r+n),s(e,a,c))};return n.substr&&"data:"===n.substr(0,5)?void f(n.substr(5)):void t.Tools.LoadFile(r+n,function(t){f(t)},a,l)},l=new t.Database(r+n,c)},e.Load=function(i,r,n,o,s,a){e.Append(i,r,new t.Scene(n),o,s,a)},e.Append=function(i,r,n,o,s,a){if(r.substr&&"/"===r.substr(0,1))return void t.Tools.Error("Wrong sceneFilename parameter");var h,c=this._getPluginForFilename(r.name||r);e.ShowLoadingScreen&&n.getEngine().displayLoadingUI();var l=function(t){return n.database=h,c.load(n,t,i)?(o&&o(n),void(e.ShowLoadingScreen&&n.executeWhenReady(function(){n.getEngine().hideLoadingUI()}))):(a&&a(n),void n.getEngine().hideLoadingUI())},u=function(e){t.Tools.LoadFile(i+r,l,s,h)};return r.substr&&"data:"===r.substr(0,5)?void l(r.substr(5)):void(-1===i.indexOf("file:")?h=new t.Database(i+r,u):t.Tools.ReadFile(r,l,s))},e._ForceFullSceneLoadingForIncremental=!1,e._ShowLoadingScreen=!0,e._registeredPlugins=new Array,e}();t.SceneLoader=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e;!function(e){var i=function(t,e){if(t.length===3*e){for(var i=[],r=0;r<t.length;r+=3){var n=r/3*4;i[n]=t[r],i[n+1]=t[r+1],i[n+2]=t[r+2],i[n+3]=1}return i}return t},r=function(e,i,r){var n=new t.CubeTexture(e+i.name,r);return n.name=i.name,n.hasAlpha=i.hasAlpha,n.level=i.level,n.coordinatesMode=i.coordinatesMode,n},n=function(e,i,n){if(!i.name&&!i.isRenderTarget)return null;if(i.isCube)return r(e,i,n);var o;if(i.mirrorPlane?(o=new t.MirrorTexture(i.name,i.renderTargetSize,n),o._waitingRenderList=i.renderList,o.mirrorPlane=t.Plane.FromArray(i.mirrorPlane)):i.isRenderTarget?(o=new t.RenderTargetTexture(i.name,i.renderTargetSize,n),o._waitingRenderList=i.renderList):o=new t.Texture(e+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(e,i){for(var r=new t.Skeleton(e.name,e.id,i),n=0;n<e.bones.length;n++){var o=e.bones[n],s=null;o.parentBoneIndex>-1&&(s=r.bones[o.parentBoneIndex]);var a=new t.Bone(o.name,r,s,t.Matrix.FromArray(o.matrix));o.animation&&a.animations.push(d(o.animation))}return r},s=function(e){var i=new t.FresnelParameters;return i.isEnabled=e.isEnabled,i.leftColor=t.Color3.FromArray(e.leftColor),i.rightColor=t.Color3.FromArray(e.rightColor),i.bias=e.bias,i.power=e.power||1,i},a=function(e,i,r){var o;return o=new t.StandardMaterial(e.name,i),o.ambientColor=t.Color3.FromArray(e.ambient),o.diffuseColor=t.Color3.FromArray(e.diffuse),o.specularColor=t.Color3.FromArray(e.specular),o.specularPower=e.specularPower,o.emissiveColor=t.Color3.FromArray(e.emissive),o.alpha=e.alpha,o.id=e.id,t.Tags.AddTagsTo(o,e.tags),o.backFaceCulling=e.backFaceCulling,o.wireframe=e.wireframe,e.diffuseTexture&&(o.diffuseTexture=n(r,e.diffuseTexture,i)),e.diffuseFresnelParameters&&(o.diffuseFresnelParameters=s(e.diffuseFresnelParameters)),e.ambientTexture&&(o.ambientTexture=n(r,e.ambientTexture,i)),e.opacityTexture&&(o.opacityTexture=n(r,e.opacityTexture,i)),e.opacityFresnelParameters&&(o.opacityFresnelParameters=s(e.opacityFresnelParameters)),e.reflectionTexture&&(o.reflectionTexture=n(r,e.reflectionTexture,i)),e.reflectionFresnelParameters&&(o.reflectionFresnelParameters=s(e.reflectionFresnelParameters)),e.emissiveTexture&&(o.emissiveTexture=n(r,e.emissiveTexture,i)),e.emissiveFresnelParameters&&(o.emissiveFresnelParameters=s(e.emissiveFresnelParameters)),e.specularTexture&&(o.specularTexture=n(r,e.specularTexture,i)),e.bumpTexture&&(o.bumpTexture=n(r,e.bumpTexture,i)),o},h=function(t,e,i,r){for(var n=0;n<e.materials.length;n++){var o=e.materials[n];if(o.id===t)return a(o,i,r)}return null},c=function(e,i){var r=new t.MultiMaterial(e.name,i);r.id=e.id,t.Tags.AddTagsTo(r,e.tags);for(var n=0;n<e.materials.length;n++){var o=e.materials[n];r.subMaterials.push(o?i.getMaterialByID(o):null)}return r},l=function(e,i,r){var n=i.getLastEntryByID(e.emitterId),o=new t.LensFlareSystem("lensFlareSystem#"+e.emitterId,n,i);o.borderLimit=e.borderLimit;for(var s=0;s<e.flares.length;s++){var a=e.flares[s];new t.LensFlare(a.size,a.position,t.Color3.FromArray(a.color),r+a.textureName,o)}return o},u=function(e,i,r){var n=i.getLastMeshByID(e.emitterId),o=new t.ParticleSystem("particles#"+n.name,e.capacity,i);return e.textureName&&(o.particleTexture=new t.Texture(r+e.textureName,i),o.particleTexture.name=e.textureName),o.minAngularSpeed=e.minAngularSpeed,o.maxAngularSpeed=e.maxAngularSpeed,o.minSize=e.minSize,o.maxSize=e.maxSize,o.minLifeTime=e.minLifeTime,o.maxLifeTime=e.maxLifeTime,o.emitter=n,o.emitRate=e.emitRate,o.minEmitBox=t.Vector3.FromArray(e.minEmitBox),o.maxEmitBox=t.Vector3.FromArray(e.maxEmitBox),o.gravity=t.Vector3.FromArray(e.gravity),o.direction1=t.Vector3.FromArray(e.direction1),o.direction2=t.Vector3.FromArray(e.direction2),o.color1=t.Color4.FromArray(e.color1),o.color2=t.Color4.FromArray(e.color2),o.colorDead=t.Color4.FromArray(e.colorDead),o.updateSpeed=e.updateSpeed,o.targetStopDuration=e.targetStopFrame,o.textureMask=t.Color4.FromArray(e.textureMask),o.blendMode=e.blendMode,o.start(),o},f=function(e,i){for(var r=i.getLightByID(e.lightId),n=new t.ShadowGenerator(e.mapSize,r),o=0;o<e.renderList.length;o++){var s=i.getMeshByID(e.renderList[o]);n.getShadowMap().renderList.push(s)}return e.usePoissonSampling?n.usePoissonSampling=!0:e.useVarianceShadowMap?n.useVarianceShadowMap=!0:e.useBlurVarianceShadowMap&&(n.useBlurVarianceShadowMap=!0,e.blurScale&&(n.blurScale=e.blurScale),e.blurBoxOffset&&(n.blurBoxOffset=e.blurBoxOffset)),void 0!==e.bias&&(n.bias=e.bias),n},d=function(e){for(var i=new t.Animation(e.name,e.property,e.framePerSecond,e.dataType,e.loopBehavior),r=e.dataType,n=[],o=0;o<e.keys.length;o++){var s,a=e.keys[o];switch(r){case t.Animation.ANIMATIONTYPE_FLOAT:s=a.values[0];break;case t.Animation.ANIMATIONTYPE_QUATERNION:s=t.Quaternion.FromArray(a.values);break;case t.Animation.ANIMATIONTYPE_MATRIX:s=t.Matrix.FromArray(a.values);break;case t.Animation.ANIMATIONTYPE_VECTOR3:default:s=t.Vector3.FromArray(a.values)}n.push({frame:a.frame,value:s})}return i.setKeys(n),i},p=function(e,i){var r;switch(e.type){case 0:r=new t.PointLight(e.name,t.Vector3.FromArray(e.position),i);break;case 1:r=new t.DirectionalLight(e.name,t.Vector3.FromArray(e.direction),i),r.position=t.Vector3.FromArray(e.position);break;case 2:r=new t.SpotLight(e.name,t.Vector3.FromArray(e.position),t.Vector3.FromArray(e.direction),e.angle,e.exponent,i);break;case 3:r=new t.HemisphericLight(e.name,t.Vector3.FromArray(e.direction),i),r.groundColor=t.Color3.FromArray(e.groundColor)}if(r.id=e.id,t.Tags.AddTagsTo(r,e.tags),void 0!==e.intensity&&(r.intensity=e.intensity),e.range&&(r.range=e.range),r.diffuse=t.Color3.FromArray(e.diffuse),r.specular=t.Color3.FromArray(e.specular),e.excludedMeshesIds&&(r._excludedMeshesIds=e.excludedMeshesIds),e.parentId&&(r._waitingParentId=e.parentId),e.includedOnlyMeshesIds&&(r._includedOnlyMeshesIds=e.includedOnlyMeshesIds),e.animations)for(var n=0;n<e.animations.length;n++){var o=e.animations[n];r.animations.push(d(o))}e.autoAnimate&&i.beginAnimation(r,e.autoAnimateFrom,e.autoAnimateTo,e.autoAnimateLoop,1)},m=function(e,i){var r,n=t.Vector3.FromArray(e.position),o=e.lockedTargetId?i.getLastMeshByID(e.lockedTargetId):null;if("AnaglyphArcRotateCamera"===e.type||"ArcRotateCamera"===e.type){var s=e.alpha,a=e.beta,h=e.radius;if("AnaglyphArcRotateCamera"===e.type){var c=e.eye_space;r=new t.AnaglyphArcRotateCamera(e.name,s,a,h,o,c,i)}else r=new t.ArcRotateCamera(e.name,s,a,h,o,i)}else"AnaglyphFreeCamera"===e.type?(c=e.eye_space,r=new t.AnaglyphFreeCamera(e.name,n,c,i)):"DeviceOrientationCamera"===e.type?r=new t.DeviceOrientationCamera(e.name,n,i):"FollowCamera"===e.type?(r=new t.FollowCamera(e.name,n,i),r.heightOffset=e.heightOffset,r.radius=e.radius,r.rotationOffset=e.rotationOffset,o&&(r.target=o)):r="GamepadCamera"===e.type?new t.GamepadCamera(e.name,n,i):"OculusCamera"===e.type?new t.OculusCamera(e.name,n,i):"OculusGamepadCamera"===e.type?new t.OculusGamepadCamera(e.name,n,i):"TouchCamera"===e.type?new t.TouchCamera(e.name,n,i):"VirtualJoysticksCamera"===e.type?new t.VirtualJoysticksCamera(e.name,n,i):"WebVRCamera"===e.type?new t.WebVRCamera(e.name,n,i):"VRDeviceOrientationCamera"===e.type?new t.VRDeviceOrientationCamera(e.name,n,i):new t.FreeCamera(e.name,n,i);if(o&&r instanceof t.FreeCamera&&(r.lockedTarget=o),r.id=e.id,t.Tags.AddTagsTo(r,e.tags),e.parentId&&(r._waitingParentId=e.parentId),e.target?r.setTarget?r.setTarget(t.Vector3.FromArray(e.target)):r.target=t.Vector3.FromArray(e.target):r.rotation=t.Vector3.FromArray(e.rotation),r.fov=e.fov,r.minZ=e.minZ,r.maxZ=e.maxZ,r.speed=e.speed,r.inertia=e.inertia,r.checkCollisions=e.checkCollisions,r.applyGravity=e.applyGravity,e.ellipsoid&&(r.ellipsoid=t.Vector3.FromArray(e.ellipsoid)),e.animations)for(var l=0;l<e.animations.length;l++){var u=e.animations[l];r.animations.push(d(u))}return e.autoAnimate&&i.beginAnimation(r,e.autoAnimateFrom,e.autoAnimateTo,e.autoAnimateLoop,1),r.layerMask=e.layerMask&&!isNaN(e.layerMask)?Math.abs(parseInt(e.layerMask)):4294967295,r},_=function(t,e){var i=t.id;return e.getGeometryByID(i)},g=function(e,i){if(_(e,i))return null;var r=new t.Geometry.Primitives.Box(e.id,i,e.size,e.canBeRegenerated,null);return t.Tags.AddTagsTo(r,e.tags),i.pushGeometry(r,!0),r},v=function(e,i){if(_(e,i))return null;var r=new t.Geometry.Primitives.Sphere(e.id,i,e.segments,e.diameter,e.canBeRegenerated,null);return t.Tags.AddTagsTo(r,e.tags),i.pushGeometry(r,!0),r},y=function(e,i){if(_(e,i))return null;var r=new t.Geometry.Primitives.Cylinder(e.id,i,e.height,e.diameterTop,e.diameterBottom,e.tessellation,e.subdivisions,e.canBeRegenerated,null);return t.Tags.AddTagsTo(r,e.tags),i.pushGeometry(r,!0),r},x=function(e,i){if(_(e,i))return null;var r=new t.Geometry.Primitives.Torus(e.id,i,e.diameter,e.thickness,e.tessellation,e.canBeRegenerated,null);return t.Tags.AddTagsTo(r,e.tags),i.pushGeometry(r,!0),r},b=function(e,i){if(_(e,i))return null;var r=new t.Geometry.Primitives.Ground(e.id,i,e.width,e.height,e.subdivisions,e.canBeRegenerated,null);return t.Tags.AddTagsTo(r,e.tags),i.pushGeometry(r,!0),r},M=function(e,i){if(_(e,i))return null;var r=new t.Geometry.Primitives.Plane(e.id,i,e.size,e.canBeRegenerated,null);return t.Tags.AddTagsTo(r,e.tags),i.pushGeometry(r,!0),r},T=function(e,i){if(_(e,i))return null;var r=new t.Geometry.Primitives.TorusKnot(e.id,i,e.radius,e.tube,e.radialSegments,e.tubularSegments,e.p,e.q,e.canBeRegenerated,null);return t.Tags.AddTagsTo(r,e.tags),i.pushGeometry(r,!0),r},S=function(e,i,r){if(_(e,i))return null;var n=new t.Geometry(e.id,i);return t.Tags.AddTagsTo(n,e.tags),e.delayLoadingFile?(n.delayLoadState=t.Engine.DELAYLOADSTATE_NOTLOADED,n.delayLoadingFile=r+e.delayLoadingFile,n._boundingInfo=new t.BoundingInfo(t.Vector3.FromArray(e.boundingBoxMinimum),t.Vector3.FromArray(e.boundingBoxMaximum)),n._delayInfo=[],e.hasUVs&&n._delayInfo.push(t.VertexBuffer.UVKind),e.hasUVs2&&n._delayInfo.push(t.VertexBuffer.UV2Kind),e.hasColors&&n._delayInfo.push(t.VertexBuffer.ColorKind),e.hasMatricesIndices&&n._delayInfo.push(t.VertexBuffer.MatricesIndicesKind),e.hasMatricesWeights&&n._delayInfo.push(t.VertexBuffer.MatricesWeightsKind),n._delayLoadingFunction=C):C(e,n),i.pushGeometry(n,!0),n},A=function(e,i,r){var n=new t.Mesh(e.name,i);if(n.id=e.id,t.Tags.AddTagsTo(n,e.tags),n.position=t.Vector3.FromArray(e.position),e.rotationQuaternion?n.rotationQuaternion=t.Quaternion.FromArray(e.rotationQuaternion):e.rotation&&(n.rotation=t.Vector3.FromArray(e.rotation)),n.scaling=t.Vector3.FromArray(e.scaling),e.localMatrix?n.setPivotMatrix(t.Matrix.FromArray(e.localMatrix)):e.pivotMatrix&&n.setPivotMatrix(t.Matrix.FromArray(e.pivotMatrix)),n.setEnabled(e.isEnabled),n.isVisible=e.isVisible,n.infiniteDistance=e.infiniteDistance,n.showBoundingBox=e.showBoundingBox,n.showSubMeshesBoundingBox=e.showSubMeshesBoundingBox,void 0!==e.applyFog&&(n.applyFog=e.applyFog),void 0!==e.pickable&&(n.isPickable=e.pickable),void 0!==e.alphaIndex&&(n.alphaIndex=e.alphaIndex),n.receiveShadows=e.receiveShadows,n.billboardMode=e.billboardMode,void 0!==e.visibility&&(n.visibility=e.visibility),n.checkCollisions=e.checkCollisions,n._shouldGenerateFlatShading=e.useFlatShading,e.parentId&&(n._waitingParentId=e.parentId),void 0!==e.actions&&(n._waitingActions=e.actions),n.hasVertexAlpha=e.hasVertexAlpha,e.delayLoadingFile?(n.delayLoadState=t.Engine.DELAYLOADSTATE_NOTLOADED,n.delayLoadingFile=r+e.delayLoadingFile,n._boundingInfo=new t.BoundingInfo(t.Vector3.FromArray(e.boundingBoxMinimum),t.Vector3.FromArray(e.boundingBoxMaximum)),e._binaryInfo&&(n._binaryInfo=e._binaryInfo),n._delayInfo=[],e.hasUVs&&n._delayInfo.push(t.VertexBuffer.UVKind),e.hasUVs2&&n._delayInfo.push(t.VertexBuffer.UV2Kind),e.hasColors&&n._delayInfo.push(t.VertexBuffer.ColorKind),e.hasMatricesIndices&&n._delayInfo.push(t.VertexBuffer.MatricesIndicesKind),e.hasMatricesWeights&&n._delayInfo.push(t.VertexBuffer.MatricesWeightsKind),n._delayLoadingFunction=P,t.SceneLoader.ForceFullSceneLoadingForIncremental&&n._checkDelayState()):P(e,n),e.materialId?n.setMaterialByID(e.materialId):n.material=null,e.skeletonId>-1&&(n.skeleton=i.getLastSkeletonByID(e.skeletonId)),e.physicsImpostor&&(i.isPhysicsEnabled()||i.enablePhysics(),n.setPhysicsState({impostor:e.physicsImpostor,mass:e.physicsMass,friction:e.physicsFriction,restitution:e.physicsRestitution})),e.animations)for(var o=0;o<e.animations.length;o++){var s=e.animations[o];n.animations.push(d(s))}if(e.autoAnimate&&i.beginAnimation(n,e.autoAnimateFrom,e.autoAnimateTo,e.autoAnimateLoop,1),n.layerMask=e.layerMask&&!isNaN(e.layerMask)?Math.abs(parseInt(e.layerMask)):4294967295,e.instances)for(var a=0;a<e.instances.length;a++){var h=e.instances[a],c=n.createInstance(h.name);if(t.Tags.AddTagsTo(c,h.tags),c.position=t.Vector3.FromArray(h.position),h.rotationQuaternion?c.rotationQuaternion=t.Quaternion.FromArray(h.rotationQuaternion):h.rotation&&(c.rotation=t.Vector3.FromArray(h.rotation)),c.scaling=t.Vector3.FromArray(h.scaling),c.checkCollisions=n.checkCollisions,e.animations)for(o=0;o<e.animations.length;o++)s=e.animations[o],c.animations.push(d(s))}return n},w=function(e,i,r){var n=new t.ActionManager(r);null===i?r.actionManager=n:i.actionManager=n;for(var o=function(e,i){var r=Object.create(t[e].prototype);return r.constructor.apply(r,i),r},s=function(e,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 c=new Array,h=0;h<a.length;h++)c.push(parseFloat(a[h]));return r instanceof t.Vector3?t.Vector3.FromArray(c):r instanceof t.Vector4?t.Vector4.FromArray(c):r instanceof t.Color3?t.Color3.FromArray(c):r instanceof t.Color4?t.Color4.FromArray(c):parseFloat(a[0])},a=function(e,i,h,c,l){if(void 0===l&&(l=null),!e.detached){var u=new Array,f=null,d=null,p=e.combine&&e.combine.length>0;if(u.push(2===e.type?n:i),p){for(var m=new Array,_=0;_<e.combine.length;_++)a(e.combine[_],t.ActionManager.NothingTrigger,h,c,m);u.push(m)}else for(var g=0;g<e.properties.length;g++){var v=e.properties[g].value,y=e.properties[g].name,x=e.properties[g].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===e.type&&"operator"===y?t.ValueCondition[v]:s(y,v,f,"value"===y?d:null):d=v,u.push(v)}if(u.push(null===l?h:null),"InterpolateValueAction"===e.name){var b=u[u.length-2];u[u.length-1]=b,u[u.length-2]=h}var M=o(e.name,u);null===l?M instanceof t.Condition?(h=M,M=c):(h=null,c?c.then(M):n.registerAction(M)):l.push(M);for(var g=0;g<e.children.length;g++)a(e.children[g],i,h,M,null)}},h=0;h<e.children.length;h++){var c,l=e.children[h];if(l.properties.length>0){var u=l.properties[0].value,f=null===l.properties[0].targetType?u:r.getMeshByName(u);c={trigger:t.ActionManager[l.name],parameter:f}}else c=t.ActionManager[l.name];for(var d=0;d<l.children.length;d++)l.detached||a(l.children[d],c,null,null)}},D=function(e,i,r){var n=e.name,o=r+n,s={autoplay:e.autoplay,loop:e.loop,volume:e.volume,spatialSound:e.spatialSound,maxDistance:e.maxDistance,rolloffFactor:e.rolloffFactor,refDistance:e.refDistance,distanceModel:e.distanceModel,playbackRate:e.playbackRate},a=new t.Sound(n,o,i,function(){i._removePendingData(a)},s);if(i._addPendingData(a),e.position){var h=t.Vector3.FromArray(e.position);a.setPosition(h)}if(e.isDirectional&&(a.setDirectionalCone(e.coneInnerAngle||360,e.coneOuterAngle||360,e.coneOuterGain||0),e.localDirectionToMesh)){var c=t.Vector3.FromArray(e.localDirectionToMesh);a.setLocalDirectionToMesh(c)}if(e.connectedMeshId){var l=i.getMeshByID(e.connectedMeshId);l&&a.attachToMesh(l)}},E=function(t,e,i){e=e instanceof Array?e:[e];for(var r in e)if(t.name===e[r])return i.push(t.id),!0;return t.parentId&&-1!==i.indexOf(t.parentId)?(i.push(t.id),!0):!1},C=function(e,r){var n=new t.VertexData,o=e.positions;o&&n.set(o,t.VertexBuffer.PositionKind);var s=e.normals;s&&n.set(s,t.VertexBuffer.NormalKind);var a=e.uvs;a&&n.set(a,t.VertexBuffer.UVKind);var h=e.uv2s;h&&n.set(h,t.VertexBuffer.UV2Kind);var c=e.colors;c&&n.set(i(c,o.length/3),t.VertexBuffer.ColorKind);var l=e.matricesIndices;l&&n.set(l,t.VertexBuffer.MatricesIndicesKind);var u=e.matricesWeights;u&&n.set(u,t.VertexBuffer.MatricesWeightsKind);var f=e.indices;f&&(n.indices=f),r.setAllVerticesData(n,e.updatable)},P=function(e,r){var n=r.getScene(),o=e.geometryId;if(o){var s=n.getGeometryByID(o);s&&s.applyToMesh(r)}else if(e instanceof ArrayBuffer){var a=r._binaryInfo;if(a.positionsAttrDesc&&a.positionsAttrDesc.count>0){var h=new Float32Array(e,a.positionsAttrDesc.offset,a.positionsAttrDesc.count);r.setVerticesData(t.VertexBuffer.PositionKind,h,!1)}if(a.normalsAttrDesc&&a.normalsAttrDesc.count>0){var c=new Float32Array(e,a.normalsAttrDesc.offset,a.normalsAttrDesc.count);r.setVerticesData(t.VertexBuffer.NormalKind,c,!1)}if(a.uvsAttrDesc&&a.uvsAttrDesc.count>0){var l=new Float32Array(e,a.uvsAttrDesc.offset,a.uvsAttrDesc.count);r.setVerticesData(t.VertexBuffer.UVKind,l,!1)}if(a.uvs2AttrDesc&&a.uvs2AttrDesc.count>0){var u=new Float32Array(e,a.uvs2AttrDesc.offset,a.uvs2AttrDesc.count);r.setVerticesData(t.VertexBuffer.UV2Kind,u,!1)}if(a.colorsAttrDesc&&a.colorsAttrDesc.count>0){var f=new Float32Array(e,a.colorsAttrDesc.offset,a.colorsAttrDesc.count);r.setVerticesData(t.VertexBuffer.ColorKind,f,!1)}if(a.matricesIndicesAttrDesc&&a.matricesIndicesAttrDesc.count>0){var d=new Int32Array(e,a.matricesIndicesAttrDesc.offset,a.matricesIndicesAttrDesc.count);r.setVerticesData(t.VertexBuffer.MatricesIndicesKind,d,!1)}if(a.matricesWeightsAttrDesc&&a.matricesWeightsAttrDesc.count>0){var p=new Float32Array(e,a.matricesWeightsAttrDesc.offset,a.matricesWeightsAttrDesc.count);r.setVerticesData(t.VertexBuffer.MatricesWeightsKind,p,!1)}if(a.indicesAttrDesc&&a.indicesAttrDesc.count>0){var m=new Int32Array(e,a.indicesAttrDesc.offset,a.indicesAttrDesc.count);r.setIndices(m)}if(a.subMeshesAttrDesc&&a.subMeshesAttrDesc.count>0){var _=new Int32Array(e,a.subMeshesAttrDesc.offset,5*a.subMeshesAttrDesc.count);r.subMeshes=[];for(var g=0;g<a.subMeshesAttrDesc.count;g++){var v=_[5*g+0],y=_[5*g+1],x=_[5*g+2],b=_[5*g+3],M=_[5*g+4];new t.SubMesh(v,y,x,b,M,r)}}}else if(e.positions&&e.normals&&e.indices){if(r.setVerticesData(t.VertexBuffer.PositionKind,e.positions,!1),r.setVerticesData(t.VertexBuffer.NormalKind,e.normals,!1),e.uvs&&r.setVerticesData(t.VertexBuffer.UVKind,e.uvs,!1),e.uvs2&&r.setVerticesData(t.VertexBuffer.UV2Kind,e.uvs2,!1),e.colors&&r.setVerticesData(t.VertexBuffer.ColorKind,i(e.colors,e.positions.length/3),!1),e.matricesIndices)if(e.matricesIndices._isExpanded)delete e.matricesIndices._isExpanded,r.setVerticesData(t.VertexBuffer.MatricesIndicesKind,e.matricesIndices,!1);else{for(var T=[],g=0;g<e.matricesIndices.length;g++){var S=e.matricesIndices[g];T.push(255&S),T.push((65280&S)>>8),T.push((16711680&S)>>16),T.push(S>>24)}r.setVerticesData(t.VertexBuffer.MatricesIndicesKind,T,!1)}if(e.matricesWeights&&r.setVerticesData(t.VertexBuffer.MatricesWeightsKind,e.matricesWeights,!1),r.setIndices(e.indices),e.subMeshes){r.subMeshes=[];for(var A=0;A<e.subMeshes.length;A++){var w=e.subMeshes[A];new t.SubMesh(w.materialIndex,w.verticesStart,w.verticesCount,w.indexStart,w.indexCount,r)}}}r._shouldGenerateFlatShading&&(r.convertToFlatShadedMesh(),delete r._shouldGenerateFlatShading),r.computeWorldMatrix(!0),n._selectionOctree&&n._selectionOctree.addMesh(r)};t.SceneLoader.RegisterPlugin({extensions:".babylon",importMesh:function(t,e,i,r,n,s,a){for(var l=JSON.parse(i),f=[],d=[],p=[],m=0;m<l.meshes.length;m++){var _=l.meshes[m];if(!t||E(_,t,p)){if(t instanceof Array&&delete t[t.indexOf(_.name)],_.materialId){var g=-1!==d.indexOf(_.materialId);if(!g)for(var v=0;v<l.multiMaterials.length;v++){var y=l.multiMaterials[v];if(y.id==_.materialId){for(var x=0;x<y.materials.length;x++){var b=y.materials[x];d.push(b),h(b,l,e,r)}d.push(y.id),c(y,e),g=!0;break}}g||(d.push(_.materialId),h(_.materialId,l,e,r))}if(_.skeletonId>-1&&e.skeletons){var M=f.indexOf(_.skeletonId)>-1;if(!M)for(var T=0;T<l.skeletons.length;T++){var S=l.skeletons[T];S.id===_.skeletonId&&(a.push(o(S,e)),f.push(S.id))}}var w=A(_,e,r);n.push(w)}}for(m=0;m<e.meshes.length;m++){var D=e.meshes[m];D._waitingParentId&&(D.parent=e.getLastEntryByID(D._waitingParentId),D._waitingParentId=void 0)}if(l.particleSystems)for(m=0;m<l.particleSystems.length;m++){var C=l.particleSystems[m];-1!==p.indexOf(C.emitterId)&&s.push(u(C,e,r))}return!0},load:function(e,i,r){var n=JSON.parse(i);e.useDelayedTextureLoading=n.useDelayedTextureLoading&&!t.SceneLoader.ForceFullSceneLoadingForIncremental,e.autoClear=n.autoClear,e.clearColor=t.Color3.FromArray(n.clearColor),e.ambientColor=t.Color3.FromArray(n.ambientColor),e.gravity=t.Vector3.FromArray(n.gravity),n.fogMode&&0!==n.fogMode&&(e.fogMode=n.fogMode,e.fogColor=t.Color3.FromArray(n.fogColor),e.fogStart=n.fogStart,e.fogEnd=n.fogEnd,e.fogDensity=n.fogDensity);for(var s=0;s<n.lights.length;s++){var h=n.lights[s];p(h,e)}if(n.materials)for(s=0;s<n.materials.length;s++){var d=n.materials[s];a(d,e,r)}if(n.multiMaterials)for(s=0;s<n.multiMaterials.length;s++){var _=n.multiMaterials[s];c(_,e)}if(n.skeletons)for(s=0;s<n.skeletons.length;s++){var E=n.skeletons[s];o(E,e)}var C=n.geometries;if(C){var P=C.boxes;if(P)for(s=0;s<P.length;s++){var I=P[s];g(I,e)}var L=C.spheres;if(L)for(s=0;s<L.length;s++){var R=L[s];v(R,e)}var O=C.cylinders;if(O)for(s=0;s<O.length;s++){var B=O[s];y(B,e)}var F=C.toruses;if(F)for(s=0;s<F.length;s++){var V=F[s];x(V,e)}var N=C.grounds;if(N)for(s=0;s<N.length;s++){var z=N[s];b(z,e)}var k=C.planes;if(k)for(s=0;s<k.length;s++){var U=k[s];M(U,e)}var W=C.torusKnots;if(W)for(s=0;s<W.length;s++){var G=W[s];T(G,e)}var Y=C.vertexData;if(Y)for(s=0;s<Y.length;s++){var H=Y[s];S(H,e,r)}}for(s=0;s<n.meshes.length;s++){var j=n.meshes[s];A(j,e,r)}for(s=0;s<n.cameras.length;s++){var X=n.cameras[s];m(X,e)}for(n.activeCameraID&&e.setActiveCameraByID(n.activeCameraID),s=0;s<e.cameras.length;s++){var q=e.cameras[s];q._waitingParentId&&(q.parent=e.getLastEntryByID(q._waitingParentId),q._waitingParentId=void 0)}for(s=0;s<e.lights.length;s++){
- var Z=e.lights[s];Z._waitingParentId&&(Z.parent=e.getLastEntryByID(Z._waitingParentId),Z._waitingParentId=void 0)}if(n.sounds)for(s=0;s<n.sounds.length;s++){var K=n.sounds[s];if(t.Engine.audioEngine.canUseWebAudio)D(K,e,r);else{new t.Sound(K.name,null,e)}}for(s=0;s<e.meshes.length;s++){var Q=e.meshes[s];Q._waitingParentId&&(Q.parent=e.getLastEntryByID(Q._waitingParentId),Q._waitingParentId=void 0),Q._waitingActions&&(w(Q._waitingActions,Q,e),Q._waitingActions=void 0)}if(n.particleSystems)for(s=0;s<n.particleSystems.length;s++){var J=n.particleSystems[s];u(J,e,r)}if(n.lensFlareSystems)for(s=0;s<n.lensFlareSystems.length;s++){var $=n.lensFlareSystems[s];l($,e,r)}if(n.shadowGenerators)for(s=0;s<n.shadowGenerators.length;s++){var tt=n.shadowGenerators[s];f(tt,e)}return n.actions&&w(n.actions,null,e),!0}})}(e=t.Internals||(t.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i,r,n,o,s,a){void 0===a&&(a=t.Texture.TRILINEAR_SAMPLINGMODE),this.name=e,this.cellSize=n,this.sprites=new Array,this.renderingGroupId=0,this.fogEnabled=!0,this._vertexDeclaration=[4,4,4,4],this._vertexStrideSize=64,this._capacity=r,this._spriteTexture=new t.Texture(i,o,!0,!1,a),this._spriteTexture.wrapU=t.Texture.CLAMP_ADDRESSMODE,this._spriteTexture.wrapV=t.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=[],c=0,l=0;r>l;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=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 e.prototype._appendSpriteVertex=function(t,e,i,r,n){var o=16*t;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]=e.position.x,this._vertices[o+1]=e.position.y,this._vertices[o+2]=e.position.z,this._vertices[o+3]=e.angle,this._vertices[o+4]=e.width,this._vertices[o+5]=e.height,this._vertices[o+6]=i,this._vertices[o+7]=r,this._vertices[o+8]=e.invertU?1:0,this._vertices[o+9]=e.invertV?1:0;var s=e.cellIndex/n>>0;this._vertices[o+10]=e.cellIndex-s*n,this._vertices[o+11]=s,this._vertices[o+12]=e.color.r,this._vertices[o+13]=e.color.g,this._vertices[o+14]=e.color.b,this._vertices[o+15]=e.color.a},e.prototype.render=function(){if(this._effectBase.isReady()&&this._effectFog.isReady()&&this._spriteTexture&&this._spriteTexture.isReady()){for(var e=this._scene.getEngine(),i=this._spriteTexture.getBaseSize(),r=e.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))}e.updateDynamicVertexBuffer(this._vertexBuffer,this._vertices);var c=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==t.Scene.FOGMODE_NONE&&this.fogEnabled&&(c=this._effectFog),e.enableEffect(c);var l=this._scene.getViewMatrix();c.setTexture("diffuseSampler",this._spriteTexture),c.setMatrix("view",l),c.setMatrix("projection",this._scene.getProjectionMatrix()),c.setFloat2("textureInfos",this.cellSize/i.width,this.cellSize/i.height),this._scene.fogEnabled&&this._scene.fogMode!==t.Scene.FOGMODE_NONE&&this.fogEnabled&&(c.setFloat4("vFogInfos",this._scene.fogMode,this._scene.fogStart,this._scene.fogEnd,this._scene.fogDensity),c.setColor3("vFogColor",this._scene.fogColor)),e.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,c),e.setDepthFunctionToLessOrEqual(),c.setBool("alphaTest",!0),e.setColorWrite(!1),e.draw(!0,0,6*n),e.setColorWrite(!0),c.setBool("alphaTest",!1),e.setAlphaMode(t.Engine.ALPHA_COMBINE),e.draw(!0,0,6*n),e.setAlphaMode(t.Engine.ALPHA_DISABLE)}},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),this._spriteTexture&&(this._spriteTexture.dispose(),this._spriteTexture=null);var t=this._scene.spriteManagers.indexOf(this);this._scene.spriteManagers.splice(t,1),this.onDispose&&this.onDispose()},e}();t.SpriteManager=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i){this.name=e,this.color=new t.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=t.Vector3.Zero()}return Object.defineProperty(e.prototype,"size",{get:function(){return this.width},set:function(t){this.width=t,this.height=t},enumerable:!0,configurable:!0}),e.prototype.playAnimation=function(t,e,i,r){this._fromIndex=t,this._toIndex=e,this._loopAnimation=i,this._delay=r,this._animationStarted=!0,this._direction=e>t?1:-1,this.cellIndex=t,this._time=0},e.prototype.stopAnimation=function(){this._animationStarted=!1},e.prototype._animate=function(t){this._animationStarted&&(this._time+=t,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()))))},e.prototype.dispose=function(){for(var t=0;t<this._manager.sprites.length;t++)this._manager.sprites[t]==this&&this._manager.sprites.splice(t,1)},e}();t.Sprite=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i,r,n,o){this.name=e,this._vertexDeclaration=[2],this._vertexStrideSize=8,this.texture=i?new t.Texture(i,r,!0):null,this.isBackground=void 0===n?!0:n,this.color=void 0===o?new t.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 e.prototype.render=function(){if(this._effect.isReady()&&this.texture&&this.texture.isReady()){var e=this._scene.getEngine();e.enableEffect(this._effect),e.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),e.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect),e.setAlphaMode(t.Engine.ALPHA_COMBINE),e.draw(!0,0,6),e.setAlphaMode(t.Engine.ALPHA_DISABLE)}},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),this.texture&&(this.texture.dispose(),this.texture=null);var t=this._scene.layers.indexOf(this);this._scene.layers.splice(t,1),this.onDispose&&this.onDispose()},e}();t.Layer=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(){this.position=t.Vector3.Zero(),this.direction=t.Vector3.Zero(),this.color=new t.Color4(0,0,0,0),this.colorStep=new t.Color4(0,0,0,0),this.lifeTime=1,this.age=0,this.size=0,this.angle=0,this.angularSpeed=0}return e.prototype.copyTo=function(t){t.position.copyFrom(this.position),t.direction.copyFrom(this.direction),t.color.copyFrom(this.color),t.colorStep.copyFrom(this.colorStep),t.lifeTime=this.lifeTime,t.age=this.age,t.size=this.size,t.angle=this.angle,t.angularSpeed=this.angularSpeed},e}();t.Particle=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(t,e){if(t===e)return t;var i=Math.random();return i*(e-t)+t},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.blendMode=i.BLENDMODE_ONEONE,this.forceDepthWrite=!1,this.gravity=t.Vector3.Zero(),this.direction1=new t.Vector3(0,1,0),this.direction2=new t.Vector3(0,1,0),this.minEmitBox=new t.Vector3(-.5,-.5,-.5),this.maxEmitBox=new t.Vector3(.5,.5,.5),this.color1=new t.Color4(1,1,1,1),this.color2=new t.Color4(1,1,1,1),this.colorDead=new t.Color4(0,0,0,1),this.textureMask=new t.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 t.Color4(0,0,0,0),this._colorDiff=new t.Color4(0,0,0,0),this._scaledDirection=t.Vector3.Zero(),this._scaledGravity=t.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=[],c=0,l=0;n>l;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=4;this._indexBuffer=o.getEngine().createIndexBuffer(h),this._vertices=new Float32Array(n*this._vertexStrideSize),this.startDirectionFunction=function(i,r,n){var o=e(a.direction1.x,a.direction2.x),s=e(a.direction1.y,a.direction2.y),h=e(a.direction1.z,a.direction2.z);t.Vector3.TransformNormalFromFloatsToRef(o*i,s*i,h*i,r,n)},this.startPositionFunction=function(i,r){var n=e(a.minEmitBox.x,a.maxEmitBox.x),o=e(a.minEmitBox.y,a.maxEmitBox.y),s=e(a.minEmitBox.z,a.maxEmitBox.z);t.Vector3.TransformCoordinatesFromFloatsToRef(n,o,s,i,r)},this.updateFunction=function(t){for(var e=0;e<t.length;e++){var i=t[e];i.age+=a._scaledUpdateSpeed,i.age>=i.lifeTime?(a.recycleParticle(i),e--):(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(t){var e=this.particles.pop();e!==t&&(e.copyTo(t),this._stockParticles.push(e))},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(t,e,i,r){var n=11*t;this._vertices[n]=e.position.x,this._vertices[n+1]=e.position.y,this._vertices[n+2]=e.position.z,this._vertices[n+3]=e.color.r,this._vertices[n+4]=e.color.g,this._vertices[n+5]=e.color.b,this._vertices[n+6]=e.color.a,this._vertices[n+7]=e.angle,this._vertices[n+8]=e.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():t.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 t.Particle;this.particles.push(o);var s=e(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(s,r,o.direction),o.lifeTime=e(this.minLifeTime,this.maxLifeTime),o.size=e(this.minSize,this.maxSize),o.angularSpeed=e(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(r,o.position);var a=e(0,1);t.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 t=[];this._scene.clipPlane&&t.push("#define CLIPPLANE");var e=t.join("\n");return this._cachedDefines!==e&&(this._cachedDefines=e,this._effect=this._scene.getEngine().createEffect("particles",["position","color","options"],["invView","view","projection","vClipPlane","textureMask"],["diffuseSampler"],e)),this._effect},i.prototype.animate=function(){if(this._started){var t=this._getEffect();if(this.emitter&&t.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this._currentRenderId!==this._scene.getRenderId()){this._currentRenderId=this._scene.getRenderId(),this._scaledUpdateSpeed=this.updateSpeed*this._scene.getAnimationRatio();var e;this.manualEmitCount>-1?(e=this.manualEmitCount,this.manualEmitCount=0):e=this.emitRate;var i=e*this._scaledUpdateSpeed>>0;this._newPartsExcess+=e*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 e=this._getEffect();if(!(this.emitter&&e.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this.particles.length))return 0;var r=this._scene.getEngine();r.enableEffect(e),r.setState(!1);var n=this._scene.getViewMatrix();if(e.setTexture("diffuseSampler",this.particleTexture),e.setMatrix("view",n),e.setMatrix("projection",this._scene.getProjectionMatrix()),e.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(),e.setMatrix("invView",s),e.setFloat4("vClipPlane",o.normal.x,o.normal.y,o.normal.z,o.d)}return r.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,e),r.setAlphaMode(this.blendMode===i.BLENDMODE_ONEONE?t.Engine.ALPHA_ADD:t.Engine.ALPHA_COMBINE),this.forceDepthWrite&&r.setDepthWrite(!0),r.draw(!0,0,6*this.particles.length),r.setAlphaMode(t.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 t=this._scene.particleSystems.indexOf(this);this._scene.particleSystems.splice(t,1),this.onDispose&&this.onDispose()},i.prototype.clone=function(e,r){var n=new i(e,this._capacity,this._scene);return t.Tools.DeepCopy(this,n,["particles"],["_vertexDeclaration","_vertexStrideSize"]),void 0===r&&(r=this.emitter),n.emitter=r,this.particleTexture&&(n.particleTexture=new t.Texture(this.particleTexture.url,this._scene)),n.start(),n},i.BLENDMODE_ONEONE=0,i.BLENDMODE_STANDARD=1,i}();t.ParticleSystem=i}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,i,r,n,o){this.name=t,this.targetProperty=i,this.framePerSecond=r,this.dataType=n,this.loopMode=o,this._offsetsCache={},this._highLimitsCache={},this._stopped=!1,this.targetPropertyPath=i.split("."),this.dataType=n,this.loopMode=void 0===o?e.ANIMATIONLOOPMODE_CYCLE:o}return e.CreateAndStartAnimation=function(i,r,n,o,s,a,h,c){var l=void 0;if(!isNaN(parseFloat(a))&&isFinite(a)?l=e.ANIMATIONTYPE_FLOAT:a instanceof t.Quaternion?l=e.ANIMATIONTYPE_QUATERNION:a instanceof t.Vector3?l=e.ANIMATIONTYPE_VECTOR3:a instanceof t.Vector2?l=e.ANIMATIONTYPE_VECTOR2:a instanceof t.Color3&&(l=e.ANIMATIONTYPE_COLOR3),void 0==l)return null;var u=new e(i,n,o,l,c),f=[];return f.push({frame:0,value:a}),f.push({frame:s,value:h}),u.setKeys(f),r.animations.push(u),r.getScene().beginAnimation(r,0,s,1===u.loopMode)},e.prototype.isStopped=function(){return this._stopped},e.prototype.getKeys=function(){return this._keys},e.prototype.getEasingFunction=function(){return this._easingFunction},e.prototype.setEasingFunction=function(t){this._easingFunction=t},e.prototype.floatInterpolateFunction=function(t,e,i){return t+(e-t)*i},e.prototype.quaternionInterpolateFunction=function(e,i,r){return t.Quaternion.Slerp(e,i,r)},e.prototype.vector3InterpolateFunction=function(e,i,r){return t.Vector3.Lerp(e,i,r)},e.prototype.vector2InterpolateFunction=function(e,i,r){return t.Vector2.Lerp(e,i,r)},e.prototype.color3InterpolateFunction=function(e,i,r){return t.Color3.Lerp(e,i,r)},e.prototype.matrixInterpolateFunction=function(e,i,r){var n=new t.Vector3(0,0,0),o=new t.Quaternion,s=new t.Vector3(0,0,0);e.decompose(n,o,s);var a=new t.Vector3(0,0,0),h=new t.Quaternion,c=new t.Vector3(0,0,0);i.decompose(a,h,c);var l=this.vector3InterpolateFunction(n,a,r),u=this.quaternionInterpolateFunction(o,h,r),f=this.vector3InterpolateFunction(s,c,r),d=t.Matrix.Compose(l,u,f);return d},e.prototype.clone=function(){var t=new e(this.name,this.targetPropertyPath.join("."),this.framePerSecond,this.dataType,this.loopMode);return t.setKeys(this._keys),t},e.prototype.setKeys=function(t){this._keys=t.slice(0),this._offsetsCache={},this._highLimitsCache={}},e.prototype._getKeyValue=function(t){return"function"==typeof t?t():t},e.prototype._interpolate=function(t,i,r,n,o){if(r===e.ANIMATIONLOOPMODE_CONSTANT&&i>0)return o.clone?o.clone():o;this.currentFrame=t;var s=Math.max(0,Math.min(this._keys.length-1,Math.floor(this._keys.length*(t-this._keys[0].frame)/(this._keys[this._keys.length-1].frame-this._keys[0].frame))-1));if(this._keys[s].frame>=t)for(;s-1>=0&&this._keys[s].frame>=t;)s--;for(var a=s;a<this._keys.length;a++)if(this._keys[a+1].frame>=t){var h=this._getKeyValue(this._keys[a].value),c=this._getKeyValue(this._keys[a+1].value),l=(t-this._keys[a].frame)/(this._keys[a+1].frame-this._keys[a].frame);switch(null!=this._easingFunction&&(l=this._easingFunction.ease(l)),this.dataType){case e.ANIMATIONTYPE_FLOAT:switch(r){case e.ANIMATIONLOOPMODE_CYCLE:case e.ANIMATIONLOOPMODE_CONSTANT:return this.floatInterpolateFunction(h,c,l);case e.ANIMATIONLOOPMODE_RELATIVE:return n*i+this.floatInterpolateFunction(h,c,l)}break;case e.ANIMATIONTYPE_QUATERNION:var u=null;switch(r){case e.ANIMATIONLOOPMODE_CYCLE:case e.ANIMATIONLOOPMODE_CONSTANT:u=this.quaternionInterpolateFunction(h,c,l);break;case e.ANIMATIONLOOPMODE_RELATIVE:u=this.quaternionInterpolateFunction(h,c,l).add(n.scale(i))}return u;case e.ANIMATIONTYPE_VECTOR3:switch(r){case e.ANIMATIONLOOPMODE_CYCLE:case e.ANIMATIONLOOPMODE_CONSTANT:return this.vector3InterpolateFunction(h,c,l);case e.ANIMATIONLOOPMODE_RELATIVE:return this.vector3InterpolateFunction(h,c,l).add(n.scale(i))}case e.ANIMATIONTYPE_VECTOR2:switch(r){case e.ANIMATIONLOOPMODE_CYCLE:case e.ANIMATIONLOOPMODE_CONSTANT:return this.vector2InterpolateFunction(h,c,l);case e.ANIMATIONLOOPMODE_RELATIVE:return this.vector2InterpolateFunction(h,c,l).add(n.scale(i))}case e.ANIMATIONTYPE_COLOR3:switch(r){case e.ANIMATIONLOOPMODE_CYCLE:case e.ANIMATIONLOOPMODE_CONSTANT:return this.color3InterpolateFunction(h,c,l);case e.ANIMATIONLOOPMODE_RELATIVE:return this.color3InterpolateFunction(h,c,l).add(n.scale(i))}case e.ANIMATIONTYPE_MATRIX:switch(r){case e.ANIMATIONLOOPMODE_CYCLE:case e.ANIMATIONLOOPMODE_CONSTANT:case e.ANIMATIONLOOPMODE_RELATIVE:return h}}break}return this._getKeyValue(this._keys[this._keys.length-1].value)},e.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 c,l=n-r,u=i*this.framePerSecond*s/1e3,f=0;if(u>l&&!o)a=!1,f=this._getKeyValue(this._keys[this._keys.length-1].value);else if(this.loopMode!==e.ANIMATIONLOOPMODE_CYCLE){var d=n.toString()+r.toString();if(!this._offsetsCache[d]){var p=this._interpolate(r,0,e.ANIMATIONLOOPMODE_CYCLE),m=this._interpolate(n,0,e.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case e.ANIMATIONTYPE_FLOAT:this._offsetsCache[d]=m-p;break;case e.ANIMATIONTYPE_QUATERNION:this._offsetsCache[d]=m.subtract(p);break;case e.ANIMATIONTYPE_VECTOR3:this._offsetsCache[d]=m.subtract(p);case e.ANIMATIONTYPE_VECTOR2:this._offsetsCache[d]=m.subtract(p);case e.ANIMATIONTYPE_COLOR3:this._offsetsCache[d]=m.subtract(p)}this._highLimitsCache[d]=m}f=this._highLimitsCache[d],c=this._offsetsCache[d]}if(void 0===c)switch(this.dataType){case e.ANIMATIONTYPE_FLOAT:c=0;break;case e.ANIMATIONTYPE_QUATERNION:c=new t.Quaternion(0,0,0,0);break;case e.ANIMATIONTYPE_VECTOR3:c=t.Vector3.Zero();break;case e.ANIMATIONTYPE_VECTOR2:c=t.Vector2.Zero();break;case e.ANIMATIONTYPE_COLOR3:c=t.Color3.Black()}var _=u/l>>0,g=a?r+u%l:n,v=this._interpolate(g,_,this.loopMode,c,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(e,"ANIMATIONTYPE_FLOAT",{get:function(){return e._ANIMATIONTYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ANIMATIONTYPE_VECTOR3",{get:function(){return e._ANIMATIONTYPE_VECTOR3},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ANIMATIONTYPE_VECTOR2",{get:function(){return e._ANIMATIONTYPE_VECTOR2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ANIMATIONTYPE_QUATERNION",{get:function(){return e._ANIMATIONTYPE_QUATERNION},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ANIMATIONTYPE_MATRIX",{get:function(){return e._ANIMATIONTYPE_MATRIX},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ANIMATIONTYPE_COLOR3",{get:function(){return e._ANIMATIONTYPE_COLOR3},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ANIMATIONLOOPMODE_RELATIVE",{get:function(){return e._ANIMATIONLOOPMODE_RELATIVE},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ANIMATIONLOOPMODE_CYCLE",{get:function(){return e._ANIMATIONLOOPMODE_CYCLE},enumerable:!0,configurable:!0}),Object.defineProperty(e,"ANIMATIONLOOPMODE_CONSTANT",{get:function(){return e._ANIMATIONLOOPMODE_CONSTANT},enumerable:!0,configurable:!0}),e._ANIMATIONTYPE_FLOAT=0,e._ANIMATIONTYPE_VECTOR3=1,e._ANIMATIONTYPE_QUATERNION=2,e._ANIMATIONTYPE_MATRIX=3,e._ANIMATIONTYPE_COLOR3=4,e._ANIMATIONTYPE_VECTOR2=5,e._ANIMATIONLOOPMODE_RELATIVE=0,e._ANIMATIONLOOPMODE_CYCLE=1,e._ANIMATIONLOOPMODE_CONSTANT=2,e}();t.Animation=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(t,e,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=e,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(e,a),this._scene=t,t._activeAnimatables.push(this)}return t.prototype.appendAnimations=function(t,e){for(var i=0;i<e.length;i++){var r=e[i];r._target=t,this._animations.push(r)}},t.prototype.getAnimationByTargetProperty=function(t){for(var e=this._animations,i=0;i<e.length;i++)if(e[i].targetProperty===t)return e[i];return null},t.prototype.pause=function(){this._paused||(this._paused=!0)},t.prototype.restart=function(){this._paused=!1},t.prototype.stop=function(){var t=this._scene._activeAnimatables.indexOf(this);t>-1&&this._scene._activeAnimatables.splice(t,1),this.onAnimationEnd&&this.onAnimationEnd()},t.prototype._animate=function(t){if(this._paused)return this._pausedDelay||(this._pausedDelay=t),!0;this._localDelayOffset?this._pausedDelay&&(this._localDelayOffset+=t-this._pausedDelay,this._pausedDelay=null):this._localDelayOffset=t;for(var e=!1,i=this._animations,r=0;r<i.length;r++){var n=i[r],o=n.animate(t-this._localDelayOffset,this.fromFrame,this.toFrame,this.loopAnimation,this.speedRatio);e=e||o}return e||(r=this._scene._activeAnimatables.indexOf(this),this._scene._activeAnimatables.splice(r,1)),!e&&this.onAnimationEnd&&this.onAnimationEnd(),e},t}();t.Animatable=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(){function t(){this._easingMode=t.EASINGMODE_EASEIN}return Object.defineProperty(t,"EASINGMODE_EASEIN",{get:function(){return t._EASINGMODE_EASEIN},enumerable:!0,configurable:!0}),Object.defineProperty(t,"EASINGMODE_EASEOUT",{get:function(){return t._EASINGMODE_EASEOUT},enumerable:!0,configurable:!0}),Object.defineProperty(t,"EASINGMODE_EASEINOUT",{get:function(){return t._EASINGMODE_EASEINOUT},enumerable:!0,configurable:!0}),t.prototype.setEasingMode=function(t){var e=Math.min(Math.max(t,0),2);this._easingMode=e},t.prototype.getEasingMode=function(){return this._easingMode},t.prototype.easeInCore=function(t){throw new Error("You must implement this method")},t.prototype.ease=function(e){switch(this._easingMode){case t.EASINGMODE_EASEIN:return this.easeInCore(e);case t.EASINGMODE_EASEOUT:return 1-this.easeInCore(1-e)}return e>=.5?.5*(1-this.easeInCore(2*(1-e)))+.5:.5*this.easeInCore(2*e)},t._EASINGMODE_EASEIN=0,t._EASINGMODE_EASEOUT=1,t._EASINGMODE_EASEINOUT=2,t}();t.EasingFunction=e;var i=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.easeInCore=function(t){return t=Math.max(0,Math.min(1,t)),1-Math.sqrt(1-t*t)},e}(e);t.CircleEase=i;var r=function(t){function e(e){void 0===e&&(e=1),t.call(this),this.amplitude=e}return __extends(e,t),e.prototype.easeInCore=function(t){var e=Math.max(0,this.amplitude);return Math.pow(t,3)-t*e*Math.sin(3.141592653589793*t)},e}(e);t.BackEase=r;var n=function(t){function e(e,i){void 0===e&&(e=3),void 0===i&&(i=2),t.call(this),this.bounces=e,this.bounciness=i}return __extends(e,t),e.prototype.easeInCore=function(t){var e=Math.max(0,this.bounces),i=this.bounciness;1>=i&&(i=1.001);var r=Math.pow(i,e),n=1-i,o=(1-r)/n+.5*r,s=t*o,a=Math.log(-s*(1-i)+1)/Math.log(i),h=Math.floor(a),c=h+1,l=(1-Math.pow(i,h))/(n*o),u=(1-Math.pow(i,c))/(n*o),f=.5*(l+u),d=t-f,p=f-l;return-Math.pow(1/i,e-h)/(p*p)*(d-p)*(d+p)},e}(e);t.BounceEase=n;var o=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.easeInCore=function(t){return t*t*t},e}(e);t.CubicEase=o;var s=function(t){function e(e,i){void 0===e&&(e=3),void 0===i&&(i=3),t.call(this),this.oscillations=e,this.springiness=i}return __extends(e,t),e.prototype.easeInCore=function(t){var e,i=Math.max(0,this.oscillations),r=Math.max(0,this.springiness);return e=0==r?t:(Math.exp(r*t)-1)/(Math.exp(r)-1),e*Math.sin((6.283185307179586*i+1.5707963267948966)*t)},e}(e);t.ElasticEase=s;var a=function(t){function e(e){void 0===e&&(e=2),t.call(this),this.exponent=e}return __extends(e,t),e.prototype.easeInCore=function(t){return this.exponent<=0?t:(Math.exp(this.exponent*t)-1)/(Math.exp(this.exponent)-1)},e}(e);t.ExponentialEase=a;var h=function(t){function e(e){void 0===e&&(e=2),t.call(this),this.power=e}return __extends(e,t),e.prototype.easeInCore=function(t){var e=Math.max(0,this.power);return Math.pow(t,e)},e}(e);t.PowerEase=h;var c=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.easeInCore=function(t){return t*t},e}(e);t.QuadraticEase=c;var l=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.easeInCore=function(t){return t*t*t*t},e}(e);t.QuarticEase=l;var u=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.easeInCore=function(t){return t*t*t*t*t},e}(e);t.QuinticEase=u;var f=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.easeInCore=function(t){return 1-Math.sin(1.5707963267948966*(1-t))},e}(e);t.SineEase=f;var d=function(e){function i(t,i,r,n){void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=1),void 0===n&&(n=1),e.call(this),this.x1=t,this.y1=i,this.x2=r,this.y2=n}return __extends(i,e),i.prototype.easeInCore=function(e){return t.BezierCurve.interpolate(e,this.x1,this.y1,this.x2,this.y2)},i}(e);t.BezierCurveEase=d}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i,r){void 0===r&&(r=2),this.maxDepth=r,this.dynamicContent=new Array,this._maxBlockCapacity=i||64,this._selectionContent=new t.SmartArray(1024),this._creationFunc=e}return e.prototype.update=function(t,i,r){e._CreateBlocks(t,i,r,this._maxBlockCapacity,0,this.maxDepth,this,this._creationFunc)},e.prototype.addMesh=function(t){for(var e=0;e<this.blocks.length;e++){var i=this.blocks[e];i.addEntry(t)}},e.prototype.select=function(t,e){this._selectionContent.reset();for(var i=0;i<this.blocks.length;i++){var r=this.blocks[i];r.select(t,this._selectionContent,e)}return e?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},e.prototype.intersects=function(t,e,i){this._selectionContent.reset();for(var r=0;r<this.blocks.length;r++){var n=this.blocks[r];n.intersects(t,e,this._selectionContent,i)}return i?this._selectionContent.concat(this.dynamicContent):this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},e.prototype.intersectsRay=function(t){this._selectionContent.reset();for(var e=0;e<this.blocks.length;e++){var i=this.blocks[e];i.intersectsRay(t,this._selectionContent)}return this._selectionContent.concatWithNoDuplicate(this.dynamicContent),this._selectionContent},e._CreateBlocks=function(e,i,r,n,o,s,a,h){a.blocks=new Array;for(var c=new t.Vector3((i.x-e.x)/2,(i.y-e.y)/2,(i.z-e.z)/2),l=0;2>l;l++)for(var u=0;2>u;u++)for(var f=0;2>f;f++){var d=e.add(c.multiplyByFloats(l,u,f)),p=e.add(c.multiplyByFloats(l+1,u+1,f+1)),m=new t.OctreeBlock(d,p,n,o+1,s,h);m.addEntries(r),a.blocks.push(m)}},e.CreationFuncForMeshes=function(t,e){!t.isBlocked&&t.getBoundingInfo().boundingBox.intersectsMinMax(e.minPoint,e.maxPoint)&&e.entries.push(t)},e.CreationFuncForSubMeshes=function(t,e){t.getBoundingInfo().boundingBox.intersectsMinMax(e.minPoint,e.maxPoint)&&e.entries.push(t)},e}();t.Octree=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,e,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=t,this._maxPoint=e,this._boundingVectors.push(t.clone()),this._boundingVectors.push(e.clone()),this._boundingVectors.push(t.clone()),this._boundingVectors[2].x=e.x,this._boundingVectors.push(t.clone()),this._boundingVectors[3].y=e.y,this._boundingVectors.push(t.clone()),
- this._boundingVectors[4].z=e.z,this._boundingVectors.push(e.clone()),this._boundingVectors[5].z=t.z,this._boundingVectors.push(e.clone()),this._boundingVectors[6].x=t.x,this._boundingVectors.push(e.clone()),this._boundingVectors[7].y=t.y}return Object.defineProperty(e.prototype,"capacity",{get:function(){return this._capacity},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minPoint",{get:function(){return this._minPoint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxPoint",{get:function(){return this._maxPoint},enumerable:!0,configurable:!0}),e.prototype.addEntry=function(t){if(this.blocks)for(var e=0;e<this.blocks.length;e++){var i=this.blocks[e];i.addEntry(t)}else this._creationFunc(t,this),this.entries.length>this.capacity&&this._depth<this._maxDepth&&this.createInnerBlocks()},e.prototype.addEntries=function(t){for(var e=0;e<t.length;e++){var i=t[e];this.addEntry(i)}},e.prototype.select=function(e,i,r){if(t.BoundingBox.IsInFrustum(this._boundingVectors,e)){if(this.blocks){for(var n=0;n<this.blocks.length;n++){var o=this.blocks[n];o.select(e,i,r)}return}r?i.concat(this.entries):i.concatWithNoDuplicate(this.entries)}},e.prototype.intersects=function(e,i,r,n){if(t.BoundingBox.IntersectsSphere(this._minPoint,this._maxPoint,e,i)){if(this.blocks){for(var o=0;o<this.blocks.length;o++){var s=this.blocks[o];s.intersects(e,i,r,n)}return}n?r.concat(this.entries):r.concatWithNoDuplicate(this.entries)}},e.prototype.intersectsRay=function(t,e){if(t.intersectsBoxMinMax(this._minPoint,this._maxPoint)){if(this.blocks){for(var i=0;i<this.blocks.length;i++){var r=this.blocks[i];r.intersectsRay(t,e)}return}e.concatWithNoDuplicate(this.entries)}},e.prototype.createInnerBlocks=function(){t.Octree._CreateBlocks(this._minPoint,this._maxPoint,this.entries,this._capacity,this._depth,this._maxDepth,this,this._creationFunc)},e}();t.OctreeBlock=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i,r,n){this.name=e,this.children=new Array,this.animations=new Array,this._worldTransform=new t.Matrix,this._absoluteTransform=new t.Matrix,this._invertedAbsoluteTransform=new t.Matrix,this._skeleton=i,this._matrix=n,this._baseMatrix=n,i.bones.push(this),r?(this._parent=r,r.children.push(this)):this._parent=null,this._updateDifferenceMatrix()}return e.prototype.getParent=function(){return this._parent},e.prototype.getLocalMatrix=function(){return this._matrix},e.prototype.getBaseMatrix=function(){return this._baseMatrix},e.prototype.getWorldMatrix=function(){return this._worldTransform},e.prototype.getInvertedAbsoluteTransform=function(){return this._invertedAbsoluteTransform},e.prototype.getAbsoluteMatrix=function(){for(var t=this._matrix.clone(),e=this._parent;e;)t=t.multiply(e.getLocalMatrix()),e=e.getParent();return t},e.prototype.updateMatrix=function(t){this._matrix=t,this._skeleton._markAsDirty(),this._updateDifferenceMatrix()},e.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 t=0;t<this.children.length;t++)this.children[t]._updateDifferenceMatrix()},e.prototype.markAsDirty=function(){this._skeleton._markAsDirty()},e}();t.Bone=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i,r){this.name=e,this.id=i,this.bones=new Array,this._isDirty=!0,this._identity=t.Matrix.Identity(),this.bones=[],this._scene=r,r.skeletons.push(this),this.prepare(),this._isDirty=!0}return e.prototype.getTransformMatrices=function(){return this._transformMatrices},e.prototype._markAsDirty=function(){this._isDirty=!0},e.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 t=0;t<this.bones.length;t++){var e=this.bones[t],i=e.getParent();i?e.getLocalMatrix().multiplyToRef(i.getWorldMatrix(),e.getWorldMatrix()):e.getWorldMatrix().copyFrom(e.getLocalMatrix()),e.getInvertedAbsoluteTransform().multiplyToArray(e.getWorldMatrix(),this._transformMatrices,16*t)}this._identity.copyToArray(this._transformMatrices,16*this.bones.length),this._isDirty=!1,this._scene._activeBones+=this.bones.length}},e.prototype.getAnimatables=function(){if(!this._animatables||this._animatables.length!==this.bones.length){this._animatables=[];for(var t=0;t<this.bones.length;t++)this._animatables.push(this.bones[t])}return this._animatables},e.prototype.clone=function(i,r){for(var n=new e(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 c=new t.Bone(s.name,n,a,s.getBaseMatrix());t.Tools.DeepCopy(s.animations,c.animations)}return n},e}();t.Skeleton=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i,r,n,o,s,a,h,c,l){void 0===a&&(a=t.Texture.NEAREST_SAMPLINGMODE),this.name=e,this.width=-1,this.height=-1,this._reusable=!1,this._textures=new t.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:t.Texture.NEAREST_SAMPLINGMODE,this._reusable=c||!1,n=n||[],n.push("textureSampler"),this._effect=this._engine.createEffect({vertex:"postprocess",fragment:i},["position"],r||[],n,void 0!==l?l:"")}return e.prototype.isReusable=function(){return this._reusable},e.prototype.activate=function(e,i){e=e||this._camera;var r=e.getScene(),n=e.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=t.Tools.GetExponantOfTwo(o,n),s=t.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:e._postProcesses.indexOf(this)===e._postProcessesTakenIndices[0],samplingMode:this.renderTargetSamplingMode})),this._reusable&&this._textures.push(this._engine.createRenderTargetTexture({width:this.width,height:this.height},{generateMipMaps:!1,generateDepthBuffer:e._postProcesses.indexOf(this)===e._postProcessesTakenIndices[0],samplingMode:this.renderTargetSamplingMode})),this.onSizeChanged&&this.onSizeChanged()}this._engine.bindFramebuffer(this._textures.data[this._currentRenderTextureInd]),this.onActivate&&this.onActivate(e),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)},e.prototype.apply=function(){return this._effect.isReady()?(this._engine.enableEffect(this._effect),this._engine.setState(!1),this._engine.setAlphaMode(t.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},e.prototype.dispose=function(t){if(t=t||this._camera,this._textures.length>0){for(var e=0;e<this._textures.length;e++)this._engine._releaseTexture(this._textures.data[e]);this._textures.reset()}if(t){t.detachPostProcess(this);var i=t._postProcesses.indexOf(this);i===t._postProcessesTakenIndices[0]&&t._postProcessesTakenIndices.length>0&&(this._camera._postProcesses[t._postProcessesTakenIndices[0]].width=-1)}},e}();t.PostProcess=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(t){this._vertexDeclaration=[2],this._vertexStrideSize=8,this._scene=t}return t.prototype._prepareBuffers=function(){if(!this._vertexBuffer){var t=[];t.push(1,1),t.push(-1,1),t.push(-1,-1),t.push(1,-1),this._vertexBuffer=this._scene.getEngine().createVertexBuffer(t);var e=[];e.push(0),e.push(1),e.push(2),e.push(0),e.push(2),e.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(e)}},t.prototype._prepareFrame=function(t){var e=this._scene.activeCamera._postProcesses,i=this._scene.activeCamera._postProcessesTakenIndices;return 0!==i.length&&this._scene.postProcessesEnabled?(e[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera,t),!0):!1},t.prototype.directRender=function(t,e){for(var i=this._scene.getEngine(),r=0;r<t.length;r++){r<t.length-1?t[r+1].activate(this._scene.activeCamera,e):e?i.bindFramebuffer(e):i.restoreDefaultFramebuffer();var n=t[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))}i.setDepthBuffer(!0),i.setDepthWrite(!0)},t.prototype._finalizeFrame=function(t,e,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):e?n.bindFramebuffer(e):n.restoreDefaultFramebuffer(),!t);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))}n.setDepthBuffer(!0),n.setDepthWrite(!0)}},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)},t}();t.PostProcessManager=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n,o,s){t.call(this,e,"pass",null,null,i,r,n,o,s)}return __extends(e,t),e}(t.PostProcess);t.PassPostProcess=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s,a,h,c){var l=this;void 0===a&&(a=t.Texture.BILINEAR_SAMPLINGMODE),e.call(this,i,"blur",["screenSize","direction","blurWidth"],null,o,s,a,h,c),this.direction=r,this.blurWidth=n,this.onApply=function(t){t.setFloat2("screenSize",l.width,l.height),t.setVector2("direction",l.direction),t.setFloat("blurWidth",l.blurWidth)}}return __extends(i,e),i}(t.PostProcess);t.BlurPostProcess=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s,a,h,c,l,u){var f=this;e.call(this,i,"refraction",["baseColor","depth","colorLevel"],["refractionSampler"],a,h,c,l,u),this.color=n,this.depth=o,this.colorLevel=s,this.onActivate=function(e){f._refRexture=f._refRexture||new t.Texture(r,e.getScene())},this.onApply=function(t){t.setColor3("baseColor",f.color),t.setFloat("depth",f.depth),t.setFloat("colorLevel",f.colorLevel),t.setTexture("refractionSampler",f._refRexture)}}return __extends(i,e),i.prototype.dispose=function(t){this._refRexture&&this._refRexture.dispose(),e.prototype.dispose.call(this,t)},i}(t.PostProcess);t.RefractionPostProcess=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n,o,s){t.call(this,e,"blackAndWhite",null,null,i,r,n,o,s)}return __extends(e,t),e}(t.PostProcess);t.BlackAndWhitePostProcess=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n,o,s,a){var h=this;t.call(this,e,"convolution",["kernel","screenSize"],null,r,n,o,s,a),this.kernel=i,this.onApply=function(t){t.setFloat2("screenSize",h.width,h.height),t.setArray("kernel",h.kernel)}}return __extends(e,t),e.EdgeDetect0Kernel=[1,0,-1,0,0,0,-1,0,1],e.EdgeDetect1Kernel=[0,1,0,1,-4,1,0,1,0],e.EdgeDetect2Kernel=[-1,-1,-1,-1,8,-1,-1,-1,-1],e.SharpenKernel=[0,-1,0,-1,5,-1,0,-1,0],e.EmbossKernel=[-2,-1,0,-1,1,1,0,1,2],e.GaussianKernel=[0,1,0,1,1,1,0,1,0],e}(t.PostProcess);t.ConvolutionPostProcess=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n,o,s,a){var h=this;t.call(this,e,"filter",["kernelMatrix"],null,r,n,o,s,a),this.kernelMatrix=i,this.onApply=function(t){t.setMatrix("kernelMatrix",h.kernelMatrix)}}return __extends(e,t),e}(t.PostProcess);t.FilterPostProcess=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n,o,s){var a=this;t.call(this,e,"fxaa",["texelSize"],null,i,r,n,o,s),this.onSizeChanged=function(){a.texelWidth=1/a.width,a.texelHeight=1/a.height},this.onApply=function(t){t.setFloat2("texelSize",a.texelWidth,a.texelHeight)}}return __extends(e,t),e}(t.PostProcess);t.FxaaPostProcess=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i,r,n,o){this.size=e,this.position=i,this.dispose=function(){this.texture&&this.texture.dispose();var t=this._system.lensFlares.indexOf(this);this._system.lensFlares.splice(t,1)},this.color=r||new t.Color3(1,1,1),this.texture=n?new t.Texture(n,o.getScene(),!0):null,this._system=o,o.lensFlares.push(this)}return e}();t.LensFlare=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,e,i){this.name=t,this.lensFlares=new Array,this.borderLimit=300,this._vertexDeclaration=[2],this._vertexStrideSize=8,this._isEnabled=!0,this._scene=i,this._emitter=e,i.lensFlareSystems.push(this),this.meshesSelectionPredicate=function(t){return t.material&&t.isVisible&&t.isEnabled()&&t.isBlocker&&0!=(t.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(e.prototype,"isEnabled",{get:function(){return this._isEnabled},set:function(t){this._isEnabled=t},enumerable:!0,configurable:!0}),e.prototype.getScene=function(){return this._scene},e.prototype.getEmitter=function(){return this._emitter},e.prototype.getEmitterPosition=function(){return this._emitter.getAbsolutePosition?this._emitter.getAbsolutePosition():this._emitter.position},e.prototype.computeEffectivePosition=function(e){var i=this.getEmitterPosition();return i=t.Vector3.Project(i,t.Matrix.Identity(),this._scene.getTransformMatrix(),e),this._positionX=i.x,this._positionY=i.y,i=t.Vector3.TransformCoordinates(this.getEmitterPosition(),this._scene.getViewMatrix()),i.z>0&&this._positionX>e.x&&this._positionX<e.x+e.width&&this._positionY>e.y&&this._positionY<e.y+e.height?!0:!1},e.prototype._isVisible=function(){if(!this._isEnabled)return!1;var e=this.getEmitterPosition(),i=e.subtract(this._scene.activeCamera.position),r=i.length();i.normalize();var n=new t.Ray(this._scene.activeCamera.position,i),o=this._scene.pickWithRay(n,this.meshesSelectionPredicate,!0);return!o.hit||o.distance>r},e.prototype.render=function(){if(!this._effect.isReady())return!1;var e=this._scene.getEngine(),i=this._scene.activeCamera.viewport,r=i.toGlobal(e);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,c=r.y+r.height/2,l=h-this._positionX,u=c-this._positionY;e.enableEffect(this._effect),e.setState(!1),e.setDepthBuffer(!1),e.setAlphaMode(t.Engine.ALPHA_ADD),e.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-l*d.position,m=c-u*d.position,_=d.size,g=d.size*e.getAspectRatio(this._scene.activeCamera),v=2*(p/r.width)-1,y=1-2*(m/r.height),x=t.Matrix.FromValues(_/2,0,0,0,0,g/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),e.draw(!0,0,6)}return e.setDepthBuffer(!0),e.setAlphaMode(t.Engine.ALPHA_DISABLE),!0},e.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 t=this._scene.lensFlareSystems.indexOf(this);this._scene.lensFlareSystems.splice(t,1)},e}();t.LensFlareSystem=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(){this._registeredMeshes=[],this._physicsMaterials=[],this.updateBodyPosition=function(t){for(var e=0;e<this._registeredMeshes.length;e++){var i=this._registeredMeshes[e];if(i.mesh===t||i.mesh===t.parent){var r=i.body,n=t.getBoundingInfo().boundingBox.center;return r.position.set(n.x,n.z,n.y),r.quaternion.x=t.rotationQuaternion.x,r.quaternion.z=t.rotationQuaternion.y,r.quaternion.y=t.rotationQuaternion.z,void(r.quaternion.w=-t.rotationQuaternion.w)}}}}return e.prototype.initialize=function(t){void 0===t&&(t=10),this._world=new CANNON.World,this._world.broadphase=new CANNON.NaiveBroadphase,this._world.solver.iterations=t},e.prototype._checkWithEpsilon=function(e){return e<t.PhysicsEngine.Epsilon?t.PhysicsEngine.Epsilon:e},e.prototype.runOneStep=function(e){this._world.step(e);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 t.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}}},e.prototype.setGravity=function(t){this._world.gravity.set(t.x,t.z,t.y)},e.prototype.registerMesh=function(e,i,r){switch(this.unregisterMesh(e),e.computeWorldMatrix(!0),i){case t.PhysicsEngine.SphereImpostor:var n=e.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,e,r);case t.PhysicsEngine.BoxImpostor:n=e.getBoundingInfo().boundingBox;var h=n.minimumWorld,c=n.maximumWorld,l=c.subtract(h).scale(.5);return this._createBox(this._checkWithEpsilon(l.x),this._checkWithEpsilon(l.y),this._checkWithEpsilon(l.z),e,r);case t.PhysicsEngine.PlaneImpostor:return this._createPlane(e,r);case t.PhysicsEngine.MeshImpostor:var u=e.getVerticesData(t.VertexBuffer.PositionKind),f=e.getIndices();return this._createConvexPolyhedron(u,f,e,r)}return null},e.prototype._createSphere=function(t,e,i){var r=new CANNON.Sphere(t);return i?this._createRigidBodyFromShape(r,e,i.mass,i.friction,i.restitution):r},e.prototype._createBox=function(t,e,i,r,n){var o=new CANNON.Box(new CANNON.Vec3(t,i,e));return n?this._createRigidBodyFromShape(o,r,n.mass,n.friction,n.restitution):o},e.prototype._createPlane=function(t,e){var i=new CANNON.Plane;return e?this._createRigidBodyFromShape(i,t,e.mass,e.friction,e.restitution):i},e.prototype._createConvexPolyhedron=function(e,i,r,n){var o=[],s=[];r.computeWorldMatrix(!0);for(var a=0;a<e.length;a+=3){var h=t.Vector3.Zero();t.Vector3.TransformNormalFromFloatsToRef(e[a],e[a+1],e[a+2],r.getWorldMatrix(),h),o.push(new CANNON.Vec3(h.x,h.z,h.y))}for(var c=0;c<i.length;c+=3)s.push([i[c],i[c+2],i[c+1]]);var l=new CANNON.ConvexPolyhedron(o,s);return n?this._createRigidBodyFromShape(l,r,n.mass,n.friction,n.restitution):l},e.prototype._addMaterial=function(t,e){var i,r;for(i=0;i<this._physicsMaterials.length;i++)if(r=this._physicsMaterials[i],r.friction===t&&r.restitution===e)return r;var n=new CANNON.Material;for(n.friction=t,n.restitution=e,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},e.prototype._createRigidBodyFromShape=function(e,i,r,n,o){var s=null;i.rotationQuaternion&&(s=i.rotationQuaternion.clone(),i.rotationQuaternion=new t.Quaternion(0,0,0,1));var a=i.getBoundingInfo().boundingBox,h=i.position.subtract(a.center),c=this._addMaterial(n,o),l=new CANNON.RigidBody(r,e,c);return s&&(l.quaternion.x=s.x,l.quaternion.z=s.y,l.quaternion.y=s.z,l.quaternion.w=-s.w),l.position.set(a.center.x,a.center.z,a.center.y),this._world.add(l),this._registeredMeshes.push({mesh:i,body:l,material:c,delta:h}),l},e.prototype.registerMeshesAsCompound=function(t,e){for(var i=new CANNON.Compound,r=0;r<t.length;r++){var n=t[r].mesh,o=this.registerMesh(n,t[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=t[0].mesh,a=this._createRigidBodyFromShape(i,s,e.mass,e.friction,e.restitution);return a.parts=t,a},e.prototype._unbindBody=function(t){for(var e=0;e<this._registeredMeshes.length;e++){var i=this._registeredMeshes[e];i.body===t&&(i.body=null,i.delta=0)}},e.prototype.unregisterMesh=function(t){for(var e=0;e<this._registeredMeshes.length;e++){var i=this._registeredMeshes[e];if(i.mesh===t)return i.body&&(this._world.remove(i.body),this._unbindBody(i.body)),void this._registeredMeshes.splice(e,1)}},e.prototype.applyImpulse=function(t,e,i){for(var r=new CANNON.Vec3(i.x,i.z,i.y),n=new CANNON.Vec3(e.x,e.z,e.y),o=0;o<this._registeredMeshes.length;o++){var s=this._registeredMeshes[o];if(s.mesh===t)return void s.body.applyImpulse(n,r)}},e.prototype.createLink=function(t,e,i,r){for(var n=null,o=null,s=0;s<this._registeredMeshes.length;s++){var a=this._registeredMeshes[s];a.mesh===t?n=a.body:a.mesh===e&&(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},e.prototype.dispose=function(){for(;this._registeredMeshes.length;)this.unregisterMesh(this._registeredMeshes[0].mesh)},e.prototype.isSupported=function(){return void 0!==window.CANNON},e}();t.CannonJSPlugin=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(){this._registeredMeshes=[],this.updateBodyPosition=function(t){for(var e=0;e<this._registeredMeshes.length;e++){var i=this._registeredMeshes[e];if(i.mesh===t||i.mesh===t.parent){var r=i.body.body;t.computeWorldMatrix(!0);var n=t.getBoundingInfo().boundingBox.center;return r.setPosition(n.x,n.y,n.z),void r.setRotation(t.rotation.x,t.rotation.y,t.rotation.z)}if(i.mesh.parent===t){t.computeWorldMatrix(!0),i.mesh.computeWorldMatrix(!0);var o=i.mesh.getAbsolutePosition(),s=t.rotation;return r=i.body.body,r.setPosition(o.x,o.y,o.z),void r.setRotation(s.x,s.y,s.z)}}}}return e.prototype._checkWithEpsilon=function(e){return e<t.PhysicsEngine.Epsilon?t.PhysicsEngine.Epsilon:e},e.prototype.initialize=function(t){this._world=new OIMO.World,this._world.clear()},e.prototype.setGravity=function(t){this._world.gravity=t},e.prototype.registerMesh=function(e,i,r){var n=null;this.unregisterMesh(e),e.computeWorldMatrix(!0);var o=null;e.rotationQuaternion&&(o=e.rotationQuaternion.clone(),e.rotationQuaternion=new t.Quaternion(0,0,0,1),e.computeWorldMatrix(!0));var s=e.getBoundingInfo().boundingBox,a=e.position.subtract(s.center);if(o){var h=new t.Matrix;o.toRotationMatrix(h),a=t.Vector3.TransformCoordinates(a,h)}switch(i){case t.PhysicsEngine.SphereImpostor:var c=s.maximumWorld.x-s.minimumWorld.x,l=s.maximumWorld.y-s.minimumWorld.y,u=s.maximumWorld.z-s.minimumWorld.z,f=Math.max(this._checkWithEpsilon(c),this._checkWithEpsilon(l),this._checkWithEpsilon(u))/2;n=new OIMO.Body({type:"sphere",size:[f],pos:[s.center.x,s.center.y,s.center.z],rot:[e.rotation.x/OIMO.TO_RAD,e.rotation.y/OIMO.TO_RAD,e.rotation.z/OIMO.TO_RAD],move:0!=r.mass,config:[r.mass,r.friction,r.restitution],world:this._world});break;case t.PhysicsEngine.PlaneImpostor:case t.PhysicsEngine.CylinderImpostor:case t.PhysicsEngine.BoxImpostor:var d=s.minimumWorld,p=s.maximumWorld,m=p.subtract(d),_=this._checkWithEpsilon(m.x),g=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:[e.rotation.x/OIMO.TO_RAD,e.rotation.y/OIMO.TO_RAD,e.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:e,body:n,delta:a}),n},e.prototype.registerMeshesAsCompound=function(t,e){for(var i=[],r=[],n=[],o=[],s=t[0].mesh,a=0;a<t.length;a++){var h=t[a],c=this._createBodyAsCompound(h,e,s);i.push(c.type),r.push.apply(r,c.size),n.push.apply(n,c.pos),o.push.apply(o,c.rot)}var l=new OIMO.Body({type:i,size:r,pos:n,rot:o,move:0!=e.mass,config:[e.mass,e.friction,e.restitution],world:this._world});return this._registeredMeshes.push({mesh:s,body:l}),l},e.prototype._createBodyAsCompound=function(e,i,r){var n=null,o=e.mesh;switch(o.computeWorldMatrix(),e.impostor){case t.PhysicsEngine.SphereImpostor:var s=o.getBoundingInfo().boundingBox,a=s.maximumWorld.x-s.minimumWorld.x,h=s.maximumWorld.y-s.minimumWorld.y,c=s.maximumWorld.z-s.minimumWorld.z,l=Math.max(this._checkWithEpsilon(a),this._checkWithEpsilon(h),this._checkWithEpsilon(c))/2;n={type:"sphere",size:[l,-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 t.PhysicsEngine.PlaneImpostor:case t.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),_=this._checkWithEpsilon(d.z),g=o.position;n={type:"box",size:[p,m,_],pos:[g.x,g.y,g.z],rot:[o.rotation.x/OIMO.TO_RAD,o.rotation.y/OIMO.TO_RAD,o.rotation.z/OIMO.TO_RAD]}}return n},e.prototype.unregisterMesh=function(t){for(var e=0;e<this._registeredMeshes.length;e++){var i=this._registeredMeshes[e];if(i.mesh===t||i.mesh===t.parent)return i.body&&(this._world.removeRigidBody(i.body.body),this._unbindBody(i.body)),void this._registeredMeshes.splice(e,1)}},e.prototype._unbindBody=function(t){for(var e=0;e<this._registeredMeshes.length;e++){var i=this._registeredMeshes[e];i.body===t&&(i.body=null)}},e.prototype.applyImpulse=function(t,e,i){for(var r=0;r<this._registeredMeshes.length;r++){var n=this._registeredMeshes[r];if(n.mesh===t||n.mesh===t.parent){var o=n.body.body.massInfo.mass;return void n.body.body.applyImpulse(i.scale(OIMO.INV_SCALE),e.scale(OIMO.INV_SCALE*o))}}},e.prototype.createLink=function(t,e,i,r,n){for(var o=null,s=null,a=0;a<this._registeredMeshes.length;a++){var h=this._registeredMeshes[a];h.mesh===t?o=h.body.body:h.mesh===e&&(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},e.prototype.dispose=function(){for(this._world.clear();this._registeredMeshes.length;)this.unregisterMesh(this._registeredMeshes[0].mesh)},e.prototype.isSupported=function(){return void 0!==OIMO},e.prototype._getLastShape=function(t){for(var e=t.shapes;e.next;)e=e.next;return e},e.prototype.runOneStep=function(e){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=t.Matrix.FromArray(n.getMatrix());o.rotationQuaternion||(o.rotationQuaternion=new t.Quaternion(0,0,0,1)),o.rotationQuaternion.fromRotationMatrix(h),o.computeWorldMatrix()}else{i=n.getMatrix(),h=t.Matrix.FromArray(i);var c=h.m[12],l=h.m[13],u=h.m[14];s?(o.position.x=c+s.x,o.position.y=l+s.y,o.position.z=u+s.z):(o.position.x=c,o.position.y=l,o.position.z=u),o.rotationQuaternion||(o.rotationQuaternion=new t.Quaternion(0,0,0,1)),t.Quaternion.FromRotationMatrixToRef(h,o.rotationQuaternion),o.computeWorldMatrix()}}},e}();t.OimoJSPlugin=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e){this._currentPlugin=e||new t.OimoJSPlugin}return e.prototype._initialize=function(t){this._currentPlugin.initialize(),this._setGravity(t)},e.prototype._runOneStep=function(t){t>.1?t=.1:0>=t&&(t=1/60),this._currentPlugin.runOneStep(t)},e.prototype._setGravity=function(e){this.gravity=e||new t.Vector3(0,-9.82,0),this._currentPlugin.setGravity(this.gravity)},e.prototype._registerMesh=function(t,e,i){return this._currentPlugin.registerMesh(t,e,i)},e.prototype._registerMeshesAsCompound=function(t,e){return this._currentPlugin.registerMeshesAsCompound(t,e)},e.prototype._unregisterMesh=function(t){this._currentPlugin.unregisterMesh(t)},e.prototype._applyImpulse=function(t,e,i){this._currentPlugin.applyImpulse(t,e,i)},e.prototype._createLink=function(t,e,i,r,n){return this._currentPlugin.createLink(t,e,i,r,n)},e.prototype._updateBodyPosition=function(t){this._currentPlugin.updateBodyPosition(t)},e.prototype.dispose=function(){this._currentPlugin.dispose()},e.prototype.isSupported=function(){return this._currentPlugin.isSupported()},e.NoImpostor=0,e.SphereImpostor=1,e.BoxImpostor=2,e.PlaneImpostor=3,e.MeshImpostor=4,e.CapsuleImpostor=5,e.ConeImpostor=6,e.CylinderImpostor=7,e.ConvexHullImpostor=8,e.Epsilon=.001,e}();t.PhysicsEngine=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(e){var i={};if(i.name=e.name,i.id=e.id,i.tags=t.Tags.GetTags(e),e instanceof t.PointLight)i.type=0,i.position=e.position.asArray();else if(e instanceof t.DirectionalLight){i.type=1;var r=e;i.position=r.position.asArray(),i.direction=r.direction.asArray()}else if(e instanceof t.SpotLight){i.type=2;var n=e;i.position=n.position.asArray(),i.direction=n.position.asArray(),i.angle=n.angle,i.exponent=n.exponent}else if(e instanceof t.HemisphericLight){
- i.type=3;var o=e;i.direction=o.direction.asArray(),i.groundColor=o.groundColor.asArray()}return e.intensity&&(i.intensity=e.intensity),i.range=e.range,i.diffuse=e.diffuse.asArray(),i.specular=e.specular.asArray(),i},i=function(t){var e={};return e.isEnabled=t.isEnabled,e.leftColor=t.leftColor,e.rightColor=t.rightColor,e.bias=t.bias,e.power=t.power,e},r=function(t,e){if(t.animations){e.animations=[];for(var i=0;i<t.animations.length;i++){var r=t.animations[i];e.animations.push(o(r))}}},n=function(e){var i={};if(i.name=e.name,i.tags=t.Tags.GetTags(e),i.id=e.id,i.position=e.position.asArray(),e.parent&&(i.parentId=e.parent.id),i.fov=e.fov,i.minZ=e.minZ,i.maxZ=e.maxZ,i.inertia=e.inertia,e instanceof t.FreeCamera?i.type="FreeCamera":e instanceof t.ArcRotateCamera?i.type="ArcRotateCamera":e instanceof t.AnaglyphArcRotateCamera?i.type="AnaglyphArcRotateCamera":e instanceof t.GamepadCamera?i.type="GamepadCamera":e instanceof t.AnaglyphFreeCamera?i.type="AnaglyphFreeCamera":e instanceof t.DeviceOrientationCamera?i.type="DeviceOrientationCamera":e instanceof t.FollowCamera?i.type="FollowCamera":e instanceof t.OculusCamera?i.type="OculusCamera":e instanceof t.OculusGamepadCamera?i.type="OculusGamepadCamera":e instanceof t.TouchCamera?i.type="TouchCamera":e instanceof t.VirtualJoysticksCamera?i.type="VirtualJoysticksCamera":e instanceof t.WebVRCamera?i.type="WebVRCamera":e instanceof t.VRDeviceOrientationCamera&&(i.type="VRDeviceOrientationCamera"),e instanceof t.ArcRotateCamera||e instanceof t.AnaglyphArcRotateCamera){var n=e;i.alpha=n.alpha,i.beta=n.beta,i.radius=n.radius,n.target&&n.target.id&&(i.lockedTargetId=n.target.id)}else if(e instanceof t.FollowCamera){var o=e;i.radius=o.radius,i.heightOffset=o.heightOffset,i.rotationOffset=o.rotationOffset}else(e instanceof t.AnaglyphFreeCamera||e instanceof t.AnaglyphArcRotateCamera)&&void 0!==e._eyeSpace&&(i.eye_space=t.Tools.ToDegrees(e._eyeSpace));return void 0!==e.speed&&(i.speed=e.speed),e.target&&e.target instanceof t.Vector3&&(i.target=e.target.asArray()),e.rotation&&e.rotation instanceof t.Vector3&&(i.rotation=e.rotation.asArray()),e.lockedTarget&&e.lockedTarget.id&&(i.lockedTargetId=e.lockedTarget.id),i.checkCollisions=e.checkCollisions||!1,i.applyGravity=e.applyGravity||!1,e.ellipsoid&&(i.ellipsoid=e.ellipsoid.asArray()),r(e,i),i.layerMask=e.layerMask,i},o=function(e){var i={};i.name=e.name,i.property=e.targetProperty,i.framePerSecond=e.framePerSecond,i.dataType=e.dataType,i.loopBehavior=e.loopMode;var r=e.dataType;i.keys=[];for(var n=e.getKeys(),o=0;o<n.length;o++){var s=n[o],a={};switch(a.frame=s.frame,r){case t.Animation.ANIMATIONTYPE_FLOAT:a.values=[s.value];break;case t.Animation.ANIMATIONTYPE_QUATERNION:case t.Animation.ANIMATIONTYPE_MATRIX:case t.Animation.ANIMATIONTYPE_VECTOR3:a.values=s.value.asArray()}i.keys.push(a)}return i},s=function(e){var i={};i.name=e.name,i.id=e.id,i.tags=t.Tags.GetTags(e),i.materials=[];for(var r=0;r<e.subMaterials.length;r++){var n=e.subMaterials[r];i.materials.push(n?n.id:null)}return i},a=function(e){var r={};return r.name=e.name,r.ambient=e.ambientColor.asArray(),r.diffuse=e.diffuseColor.asArray(),r.specular=e.specularColor.asArray(),r.specularPower=e.specularPower,r.emissive=e.emissiveColor.asArray(),r.alpha=e.alpha,r.id=e.id,r.tags=t.Tags.GetTags(e),r.backFaceCulling=e.backFaceCulling,e.diffuseTexture&&(r.diffuseTexture=h(e.diffuseTexture)),e.diffuseFresnelParameters&&(r.diffuseFresnelParameters=i(e.diffuseFresnelParameters)),e.ambientTexture&&(r.ambientTexture=h(e.ambientTexture)),e.opacityTexture&&(r.opacityTexture=h(e.opacityTexture)),e.opacityFresnelParameters&&(r.opacityFresnelParameters=i(e.opacityFresnelParameters)),e.reflectionTexture&&(r.reflectionTexture=h(e.reflectionTexture)),e.reflectionFresnelParameters&&(r.reflectionFresnelParameters=i(e.reflectionFresnelParameters)),e.emissiveTexture&&(r.emissiveTexture=h(e.emissiveTexture)),e.emissiveFresnelParameters&&(r.emissiveFresnelParameters=i(e.emissiveFresnelParameters)),e.specularTexture&&(r.specularTexture=h(e.specularTexture)),e.bumpTexture&&(r.bumpTexture=h(e.bumpTexture)),r},h=function(e){var i={};if(!e.name)return null;if(e instanceof t.CubeTexture)return i.name=e.name,i.hasAlpha=e.hasAlpha,i.level=e.level,i.coordinatesMode=e.coordinatesMode,i;if(e instanceof t.MirrorTexture){var n=e;i.renderTargetSize=n.getRenderSize(),i.renderList=[];for(var o=0;o<n.renderList.length;o++)i.renderList.push(n.renderList[o].id);i.mirrorPlane=n.mirrorPlane.asArray()}else if(e instanceof t.RenderTargetTexture){var s=e;for(i.renderTargetSize=s.getRenderSize(),i.renderList=[],o=0;o<s.renderList.length;o++)i.renderList.push(s.renderList[o].id)}var a=e;return i.name=e.name,i.hasAlpha=e.hasAlpha,i.level=e.level,i.coordinatesIndex=e.coordinatesIndex,i.coordinatesMode=e.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=e.wrapU,i.wrapV=e.wrapV,r(e,i),i},c=function(t){var e={};e.name=t.name,e.id=t.id,e.bones=[];for(var i=0;i<t.bones.length;i++){var r=t.bones[i],n={parentBoneIndex:r.getParent()?t.bones.indexOf(r.getParent()):-1,name:r.name,matrix:r.getLocalMatrix().toArray()};e.bones.push(n),r.animations&&r.animations.length>0&&(n.animation=o(r.animations[0]))}return e},l=function(t){var e={};return e.emitterId=t.emitter.id,e.capacity=t.getCapacity(),t.particleTexture&&(e.textureName=t.particleTexture.name),e.minAngularSpeed=t.minAngularSpeed,e.maxAngularSpeed=t.maxAngularSpeed,e.minSize=t.minSize,e.maxSize=t.maxSize,e.minLifeTime=t.minLifeTime,e.maxLifeTime=t.maxLifeTime,e.emitRate=t.emitRate,e.minEmitBox=t.minEmitBox.asArray(),e.maxEmitBox=t.maxEmitBox.asArray(),e.gravity=t.gravity.asArray(),e.direction1=t.direction1.asArray(),e.direction2=t.direction2.asArray(),e.color1=t.color1.asArray(),e.color2=t.color2.asArray(),e.colorDead=t.colorDead.asArray(),e.updateSpeed=t.updateSpeed,e.targetStopDuration=t.targetStopDuration,e.textureMask=t.textureMask.asArray(),e.blendMode=t.blendMode,e},u=function(e){var i={};i.emitterId=e.getEmitter().id,i.borderLimit=e.borderLimit,i.flares=[];for(var r=0;r<e.lensFlares.length;r++){var n=e.lensFlares[r];i.flares.push({size:n.size,position:n.position,color:n.color.asArray(),textureName:t.Tools.GetFilename(n.texture.name)})}return i},f=function(t){var e={},i=t.getShadowGenerator();e.lightId=t.id,e.mapSize=i.getShadowMap().getRenderSize(),e.useVarianceShadowMap=i.useVarianceShadowMap,e.usePoissonSampling=i.usePoissonSampling,e.renderList=[];for(var r=0;r<i.getShadowMap().renderList.length;r++){var n=i.getShadowMap().renderList[r];e.renderList.push(n.id)}return e},d=[],p=function(e,i){if(!d[e.id]){if(e instanceof t.Geometry.Primitives.Box)i.boxes.push(v(e));else if(e instanceof t.Geometry.Primitives.Sphere)i.spheres.push(y(e));else if(e instanceof t.Geometry.Primitives.Cylinder)i.cylinders.push(x(e));else if(e instanceof t.Geometry.Primitives.Torus)i.toruses.push(b(e));else if(e instanceof t.Geometry.Primitives.Ground)i.grounds.push(M(e));else if(e instanceof t.Geometry.Primitives.Plane)i.planes.push(T(e));else if(e instanceof t.Geometry.Primitives.TorusKnot)i.torusKnots.push(S(e));else{if(e instanceof t.Geometry.Primitives._Primitive)throw new Error("Unknow primitive type");i.vertexData.push(_(e))}d[e.id]=!0}},m=function(e){var i={};return i.id=e.id,t.Tags.HasTags(e)&&(i.tags=t.Tags.GetTags(e)),i},_=function(e){var i=m(e);return e.isVerticesDataPresent(t.VertexBuffer.PositionKind)&&(i.positions=e.getVerticesData(t.VertexBuffer.PositionKind)),e.isVerticesDataPresent(t.VertexBuffer.NormalKind)&&(i.normals=e.getVerticesData(t.VertexBuffer.NormalKind)),e.isVerticesDataPresent(t.VertexBuffer.UVKind)&&(i.uvs=e.getVerticesData(t.VertexBuffer.UVKind)),e.isVerticesDataPresent(t.VertexBuffer.UV2Kind)&&(i.uvs2=e.getVerticesData(t.VertexBuffer.UV2Kind)),e.isVerticesDataPresent(t.VertexBuffer.ColorKind)&&(i.colors=e.getVerticesData(t.VertexBuffer.ColorKind)),e.isVerticesDataPresent(t.VertexBuffer.MatricesIndicesKind)&&(i.matricesIndices=e.getVerticesData(t.VertexBuffer.MatricesIndicesKind),i.matricesIndices._isExpanded=!0),e.isVerticesDataPresent(t.VertexBuffer.MatricesWeightsKind)&&(i.matricesWeights=e.getVerticesData(t.VertexBuffer.MatricesWeightsKind)),i.indices=e.getIndices(),i},g=function(t){var e=m(t);return e.canBeRegenerated=t.canBeRegenerated(),e},v=function(t){var e=g(t);return e.size=t.size,e},y=function(t){var e=g(t);return e.segments=t.segments,e.diameter=t.diameter,e},x=function(t){var e=g(t);return e.height=t.height,e.diameterTop=t.diameterTop,e.diameterBottom=t.diameterBottom,e.tessellation=t.tessellation,e},b=function(t){var e=g(t);return e.diameter=t.diameter,e.thickness=t.thickness,e.tessellation=t.tessellation,e},M=function(t){var e=g(t);return e.width=t.width,e.height=t.height,e.subdivisions=t.subdivisions,e},T=function(t){var e=g(t);return e.size=t.size,e},S=function(t){var e=g(t);return e.radius=t.radius,e.tube=t.tube,e.radialSegments=t.radialSegments,e.tubularSegments=t.tubularSegments,e.p=t.p,e.q=t.q,e},A=function(e,i){var n={};n.name=e.name,n.id=e.id,t.Tags.HasTags(e)&&(n.tags=t.Tags.GetTags(e)),n.position=e.position.asArray(),e.rotationQuaternion?n.rotationQuaternion=e.rotationQuaternion.asArray():e.rotation&&(n.rotation=e.rotation.asArray()),n.scaling=e.scaling.asArray(),n.localMatrix=e.getPivotMatrix().asArray(),n.isEnabled=e.isEnabled(),n.isVisible=e.isVisible,n.infiniteDistance=e.infiniteDistance,n.pickable=e.isPickable,n.receiveShadows=e.receiveShadows,n.billboardMode=e.billboardMode,n.visibility=e.visibility,n.checkCollisions=e.checkCollisions,e.parent&&(n.parentId=e.parent.id);var o=e._geometry;if(o){var s=o.id;n.geometryId=s,e.getScene().getGeometryByID(s)||p(o,i.geometries),n.subMeshes=[];for(var a=0;a<e.subMeshes.length;a++){var h=e.subMeshes[a];n.subMeshes.push({materialIndex:h.materialIndex,verticesStart:h.verticesStart,verticesCount:h.verticesCount,indexStart:h.indexStart,indexCount:h.indexCount})}}if(e.material?n.materialId=e.material.id:e.material=null,e.skeleton&&(n.skeletonId=e.skeleton.id),e.getPhysicsImpostor()!==t.PhysicsEngine.NoImpostor)switch(n.physicsMass=e.getPhysicsMass(),n.physicsFriction=e.getPhysicsFriction(),n.physicsRestitution=e.getPhysicsRestitution(),e.getPhysicsImpostor()){case t.PhysicsEngine.BoxImpostor:n.physicsImpostor=1;break;case t.PhysicsEngine.SphereImpostor:n.physicsImpostor=2}n.instances=[];for(var c=0;c<e.instances.length;c++){var l=e.instances[c],u={name:l.name,position:l.position,rotation:l.rotation,rotationQuaternion:l.rotationQuaternion,scaling:l.scaling};n.instances.push(u),r(l,u)}return r(e,n),n.layerMask=e.layerMask,n},w=function(){function i(){}return i.Serialize=function(i){var r={};r.useDelayedTextureLoading=i.useDelayedTextureLoading,r.autoClear=i.autoClear,r.clearColor=i.clearColor.asArray(),r.ambientColor=i.ambientColor.asArray(),r.gravity=i.gravity.asArray(),i.fogMode&&0!==i.fogMode&&(r.fogMode=i.fogMode,r.fogColor=i.fogColor.asArray(),r.fogStart=i.fogStart,r.fogEnd=i.fogEnd,r.fogDensity=i.fogDensity),r.lights=[];for(var o=0;o<i.lights.length;o++){var h=i.lights[o];r.lights.push(e(h))}for(r.cameras=[],o=0;o<i.cameras.length;o++){var m=i.cameras[o];r.cameras.push(n(m))}for(i.activeCamera&&(r.activeCameraID=i.activeCamera.id),r.materials=[],r.multiMaterials=[],o=0;o<i.materials.length;o++){var _=i.materials[o];_ instanceof t.StandardMaterial?r.materials.push(a(_)):_ instanceof t.MultiMaterial&&r.multiMaterials.push(s(_))}for(r.skeletons=[],o=0;o<i.skeletons.length;o++)r.skeletons.push(c(i.skeletons[o]));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=[],d=[];var g=i.getGeometries();for(o=0;o<g.length;o++){var v=g[o];v.isReady()&&p(v,r.geometries)}for(r.meshes=[],o=0;o<i.meshes.length;o++){var y=i.meshes[o];if(y instanceof t.Mesh){var x=y;(x.delayLoadState===t.Engine.DELAYLOADSTATE_LOADED||x.delayLoadState===t.Engine.DELAYLOADSTATE_NONE)&&r.meshes.push(A(x,r))}}for(r.particleSystems=[],o=0;o<i.particleSystems.length;o++)r.particleSystems.push(l(i.particleSystems[o]));for(r.lensFlareSystems=[],o=0;o<i.lensFlareSystems.length;o++)r.lensFlareSystems.push(u(i.lensFlareSystems[o]));for(r.shadowGenerators=[],o=0;o<i.lights.length;o++)h=i.lights[o],h.getShadowGenerator()&&r.shadowGenerators.push(f(h));return r},i}();t.SceneSerializer=w}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=0,i=function(){function e(t,e,i){this.pos=t,this.normal=e,this.uv=i}return e.prototype.clone=function(){return new e(this.pos.clone(),this.normal.clone(),this.uv.clone())},e.prototype.flip=function(){this.normal=this.normal.scale(-1)},e.prototype.interpolate=function(i,r){return new e(t.Vector3.Lerp(this.pos,i.pos,r),t.Vector3.Lerp(this.normal,i.normal,r),t.Vector2.Lerp(this.uv,i.uv,r))},e}(),r=function(){function e(t,e){this.normal=t,this.w=e}return e.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=t.Vector3.Normalize(t.Vector3.Cross(o,s));return new e(a,t.Vector3.Dot(a,i))},e.prototype.clone=function(){return new e(this.normal.clone(),this.w)},e.prototype.flip=function(){this.normal.scaleInPlace(-1),this.w=-this.w},e.prototype.splitPolygon=function(i,r,o,s,a){for(var h=0,c=1,l=2,u=3,f=0,d=[],p=0;p<i.vertices.length;p++){var m=t.Vector3.Dot(this.normal,i.vertices[p].pos)-this.w,_=m<-e.EPSILON?l:m>e.EPSILON?c:h;f|=_,d.push(_)}switch(f){case h:(t.Vector3.Dot(this.normal,i.plane.normal)>0?r:o).push(i);break;case c:s.push(i);break;case l:a.push(i);break;case u:var g=[],v=[];for(p=0;p<i.vertices.length;p++){var y=(p+1)%i.vertices.length,x=d[p],b=d[y],M=i.vertices[p],T=i.vertices[y];if(x!=l&&g.push(M),x!=c&&v.push(x!=l?M.clone():M),(x|b)==u){m=(this.w-t.Vector3.Dot(this.normal,M.pos))/t.Vector3.Dot(this.normal,T.pos.subtract(M.pos));var S=M.interpolate(T,m);g.push(S),v.push(S.clone())}}if(g.length>=3){var A=new n(g,i.shared);A.plane&&s.push(A)}v.length>=3&&(A=new n(v,i.shared),A.plane&&a.push(A))}},e.EPSILON=1e-5,e}(),n=function(){function t(t,e){this.vertices=t,this.shared=e,this.plane=r.FromPoints(t[0].pos,t[1].pos,t[2].pos)}return t.prototype.clone=function(){var e=this.vertices.map(function(t){return t.clone()});return new t(e,this.shared)},t.prototype.flip=function(){this.vertices.reverse().map(function(t){t.flip()}),this.plane.flip()},t}(),o=function(){function t(t){this.plane=null,this.front=null,this.back=null,this.polygons=[],t&&this.build(t)}return t.prototype.clone=function(){var e=new t;return e.plane=this.plane&&this.plane.clone(),e.front=this.front&&this.front.clone(),e.back=this.back&&this.back.clone(),e.polygons=this.polygons.map(function(t){return t.clone()}),e},t.prototype.invert=function(){for(var t=0;t<this.polygons.length;t++)this.polygons[t].flip();this.plane&&this.plane.flip(),this.front&&this.front.invert(),this.back&&this.back.invert();var e=this.front;this.front=this.back,this.back=e},t.prototype.clipPolygons=function(t){if(!this.plane)return t.slice();for(var e=[],i=[],r=0;r<t.length;r++)this.plane.splitPolygon(t[r],e,i,e,i);return this.front&&(e=this.front.clipPolygons(e)),i=this.back?this.back.clipPolygons(i):[],e.concat(i)},t.prototype.clipTo=function(t){this.polygons=t.clipPolygons(this.polygons),this.front&&this.front.clipTo(t),this.back&&this.back.clipTo(t)},t.prototype.allPolygons=function(){var t=this.polygons.slice();return this.front&&(t=t.concat(this.front.allPolygons())),this.back&&(t=t.concat(this.back.allPolygons())),t},t.prototype.build=function(e){if(e.length){this.plane||(this.plane=e[0].plane.clone());for(var i=[],r=[],n=0;n<e.length;n++)this.plane.splitPolygon(e[n],this.polygons,this.polygons,i,r);i.length&&(this.front||(this.front=new t),this.front.build(i)),r.length&&(this.back||(this.back=new t),this.back.build(r))}},t}(),s=function(){function r(){this.polygons=new Array}return r.FromMesh=function(o){var s,a,h,c,l,u,f=[];if(!(o instanceof t.Mesh))throw"BABYLON.CSG: Wrong Mesh type, must be BABYLON.Mesh";o.computeWorldMatrix(!0);for(var d=o.getWorldMatrix(),p=o.position.clone(),m=o.rotation.clone(),_=o.scaling.clone(),g=o.getIndices(),v=o.getVerticesData(t.VertexBuffer.PositionKind),y=o.getVerticesData(t.VertexBuffer.NormalKind),x=o.getVerticesData(t.VertexBuffer.UVKind),b=o.subMeshes,M=0,T=b.length;T>M;M++)for(var S=b[M].indexStart,A=b[M].indexCount+b[M].indexStart;A>S;S+=3){u=[];for(var w=0;3>w;w++){var D=new t.Vector3(y[3*g[S+w]],y[3*g[S+w]+1],y[3*g[S+w]+2]);h=new t.Vector2(x[2*g[S+w]],x[2*g[S+w]+1]);var E=new t.Vector3(v[3*g[S+w]],v[3*g[S+w]+1],v[3*g[S+w]+2]);c=t.Vector3.TransformCoordinates(E,d),a=t.Vector3.TransformNormal(D,d),s=new i(c,a,h),u.push(s)}l=new n(u,{subMeshId:M,meshId:e,materialIndex:b[M].materialIndex}),l.plane&&f.push(l)}var C=r.FromPolygons(f);return C.matrix=d,C.position=p,C.rotation=m,C.scaling=_,e++,C},r.FromPolygons=function(e){var i=new t.CSG;return i.polygons=e,i},r.prototype.clone=function(){var e=new t.CSG;return e.polygons=this.polygons.map(function(t){return t.clone()}),e.copyTransformAttributes(this),e},r.prototype.toPolygons=function(){return this.polygons},r.prototype.union=function(t){var e=new o(this.clone().polygons),i=new o(t.clone().polygons);return e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),r.FromPolygons(e.allPolygons()).copyTransformAttributes(this)},r.prototype.unionInPlace=function(t){var e=new o(this.polygons),i=new o(t.polygons);e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),this.polygons=e.allPolygons()},r.prototype.subtract=function(t){var e=new o(this.clone().polygons),i=new o(t.clone().polygons);return e.invert(),e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),e.invert(),r.FromPolygons(e.allPolygons()).copyTransformAttributes(this)},r.prototype.subtractInPlace=function(t){var e=new o(this.polygons),i=new o(t.polygons);e.invert(),e.clipTo(i),i.clipTo(e),i.invert(),i.clipTo(e),i.invert(),e.build(i.allPolygons()),e.invert(),this.polygons=e.allPolygons()},r.prototype.intersect=function(t){var e=new o(this.clone().polygons),i=new o(t.clone().polygons);return e.invert(),i.clipTo(e),i.invert(),e.clipTo(i),i.clipTo(e),e.build(i.allPolygons()),e.invert(),r.FromPolygons(e.allPolygons()).copyTransformAttributes(this)},r.prototype.intersectInPlace=function(t){var e=new o(this.polygons),i=new o(t.polygons);e.invert(),i.clipTo(e),i.invert(),e.clipTo(i),i.clipTo(e),e.build(i.allPolygons()),e.invert(),this.polygons=e.allPolygons()},r.prototype.inverse=function(){var t=this.clone();return t.inverseInPlace(),t},r.prototype.inverseInPlace=function(){this.polygons.map(function(t){t.flip()})},r.prototype.copyTransformAttributes=function(t){return this.matrix=t.matrix,this.position=t.position,this.rotation=t.rotation,this.scaling=t.scaling,this},r.prototype.buildMeshGeometry=function(e,i,r){var n=this.matrix.clone();n.invert();var o,s,a,h=new t.Mesh(e,i),c=[],l=[],u=[],f=[],d=t.Vector3.Zero(),p=t.Vector3.Zero(),m=t.Vector2.Zero(),_=this.polygons,g=[0,0,0],v={},y=0,x={};r&&_.sort(function(t,e){return t.shared.meshId===e.shared.meshId?t.shared.subMeshId-e.shared.subMeshId:t.shared.meshId-e.shared.meshId});for(var b=0,M=_.length;M>b;b++){o=_[b],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 T=2,S=o.vertices.length;S>T;T++){g[0]=0,g[1]=T-1,g[2]=T;for(var A=0;3>A;A++){d.copyFrom(o.vertices[g[A]].pos),p.copyFrom(o.vertices[g[A]].normal),m.copyFrom(o.vertices[g[A]].uv);var w=t.Vector3.TransformCoordinates(d,n),D=t.Vector3.TransformNormal(p,n);s=v[w.x+","+w.y+","+w.z],("undefined"==typeof s||u[3*s]!==D.x||u[3*s+1]!==D.y||u[3*s+2]!==D.z||f[2*s]!==m.x||f[2*s+1]!==m.y)&&(c.push(w.x,w.y,w.z),f.push(m.x,m.y),u.push(p.x,p.y,p.z),s=v[w.x+","+w.y+","+w.z]=c.length/3-1),l.push(s),a.indexStart=Math.min(y,a.indexStart),a.indexEnd=Math.max(y,a.indexEnd),y++}}}if(h.setVerticesData(t.VertexBuffer.PositionKind,c),h.setVerticesData(t.VertexBuffer.NormalKind,u),h.setVerticesData(t.VertexBuffer.UVKind,f),h.setIndices(l),r){var E,C=0;h.subMeshes.length=0;for(var P in x){E=-1;for(var I in x[P])a=x[P][I],t.SubMesh.CreateFromIndices(a.materialIndex+C,a.indexStart,a.indexEnd-a.indexStart+1,h),E=Math.max(a.materialIndex,E);C+=++E}}return h},r.prototype.toMesh=function(t,e,i,r){var n=this.buildMeshGeometry(t,i,r);return n.material=e,n.position.copyFrom(this.position),n.rotation.copyFrom(this.rotation),n.scaling.copyFrom(this.scaling),n.computeWorldMatrix(!0),n},r}();t.CSG=s}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o){var s=this;e.call(this,i,"oculusDistortionCorrection",["LensCenter","Scale","ScaleIn","HmdWarpParam"],null,o.PostProcessScaleFactor,r,t.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 t.Vector2(2,2/s.aspectRatio),s._scaleFactor=new t.Vector2(.5*(1/s._postProcessScaleFactor),.5*(1/s._postProcessScaleFactor)*s.aspectRatio),s._lensCenter=new t.Vector2(s._isRightEye?.5-.5*s._lensCenterOffset:.5+.5*s._lensCenterOffset,.5)},this.onApply=function(t){t.setFloat2("LensCenter",s._lensCenter.x,s._lensCenter.y),t.setFloat2("Scale",s._scaleFactor.x,s._scaleFactor.y),t.setFloat2("ScaleIn",s._scaleIn.x,s._scaleIn.y),t.setFloat4("HmdWarpParam",s._distortionFactors[0],s._distortionFactors[1],s._distortionFactors[2],s._distortionFactors[3])}}return __extends(i,e),i}(t.PostProcess);t.OculusDistortionCorrectionPostProcess=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){!function(t){t[t.X=0]="X",t[t.Y=1]="Y",t[t.Z=2]="Z"}(t.JoystickAxis||(t.JoystickAxis={}));var e=(t.JoystickAxis,function(){function e(i){var r=this;this._leftJoystick=i?!0:!1,this._joystickIndex=e._globalJoystickIndex,e._globalJoystickIndex++,this._axisTargetedByLeftAndRight=0,this._axisTargetedByUpAndDown=1,this.reverseLeftRight=!1,this.reverseUpDown=!1,this._touches=new t.SmartCollection,this.deltaPosition=t.Vector3.Zero(),this._joystickSensibility=25,this._inversedSensibility=1/(this._joystickSensibility/1e3),this._rotationSpeed=25,this._inverseRotationSpeed=1/(this._rotationSpeed/1e3),this._rotateOnAxisRelativeToMesh=!1,e.vjCanvas||(window.addEventListener("resize",function(){e.vjCanvasWidth=window.innerWidth,e.vjCanvasHeight=window.innerHeight,e.vjCanvas.width=e.vjCanvasWidth,e.vjCanvas.height=e.vjCanvasHeight,e.halfWidth=e.vjCanvasWidth/2,e.halfHeight=e.vjCanvasHeight/2},!1),e.vjCanvas=document.createElement("canvas"),e.vjCanvasWidth=window.innerWidth,e.vjCanvasHeight=window.innerHeight,e.vjCanvas.width=window.innerWidth,e.vjCanvas.height=window.innerHeight,e.vjCanvas.style.width="100%",e.vjCanvas.style.height="100%",e.vjCanvas.style.position="absolute",e.vjCanvas.style.backgroundColor="transparent",e.vjCanvas.style.top="0px",e.vjCanvas.style.left="0px",e.vjCanvas.style.zIndex="5",e.vjCanvas.style.msTouchAction="none",e.vjCanvasContext=e.vjCanvas.getContext("2d"),e.vjCanvasContext.strokeStyle="#ffffff",e.vjCanvasContext.lineWidth=2,document.body.appendChild(e.vjCanvas)),e.halfWidth=e.vjCanvas.width/2,e.halfHeight=e.vjCanvas.height/2,this.pressed=!1,this._joystickColor="cyan",this._joystickPointerID=-1,this._joystickPointerPos=new t.Vector2(0,0),this._joystickPointerStartPos=new t.Vector2(0,0),this._deltaJoystickVector=new t.Vector2(0,0),e.vjCanvas.addEventListener("pointerdown",function(t){r._onPointerDown(t)},!1),e.vjCanvas.addEventListener("pointermove",function(t){r._onPointerMove(t)},!1),e.vjCanvas.addEventListener("pointerup",function(t){r._onPointerUp(t)},!1),e.vjCanvas.addEventListener("pointerout",function(t){r._onPointerUp(t)},!1),e.vjCanvas.addEventListener("contextmenu",function(t){t.preventDefault()},!1),requestAnimationFrame(function(){r._drawVirtualJoystick()})}return e.prototype.setJoystickSensibility=function(t){this._joystickSensibility=t,this._inversedSensibility=1/(this._joystickSensibility/1e3)},e.prototype._onPointerDown=function(t){var i;t.preventDefault(),i=this._leftJoystick===!0?t.clientX<e.halfWidth:t.clientX>e.halfWidth,i&&this._joystickPointerID<0?(this._joystickPointerID=t.pointerId,this._joystickPointerStartPos.x=t.clientX,this._joystickPointerStartPos.y=t.clientY,this._joystickPointerPos=this._joystickPointerStartPos.clone(),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this.pressed=!0,this._touches.add(t.pointerId.toString(),t)):e._globalJoystickIndex<2&&this._action&&(this._action(),this._touches.add(t.pointerId.toString(),t))},e.prototype._onPointerMove=function(t){if(this._joystickPointerID==t.pointerId){this._joystickPointerPos.x=t.clientX,this._joystickPointerPos.y=t.clientY,this._deltaJoystickVector=this._joystickPointerPos.clone(),this._deltaJoystickVector=this._deltaJoystickVector.subtract(this._joystickPointerStartPos);var e=this.reverseLeftRight?-1:1,i=e*this._deltaJoystickVector.x/this._inversedSensibility;switch(this._axisTargetedByLeftAndRight){case 0:this.deltaPosition.x=Math.min(1,Math.max(-1,i));break;case 1:this.deltaPosition.y=Math.min(1,Math.max(-1,i));break;case 2:this.deltaPosition.z=Math.min(1,Math.max(-1,i))}var r=this.reverseUpDown?1:-1,n=r*this._deltaJoystickVector.y/this._inversedSensibility;switch(this._axisTargetedByUpAndDown){case 0:this.deltaPosition.x=Math.min(1,Math.max(-1,n));break;case 1:this.deltaPosition.y=Math.min(1,Math.max(-1,n));break;case 2:this.deltaPosition.z=Math.min(1,Math.max(-1,n))}}else this._touches.item(t.pointerId.toString())&&(this._touches.item(t.pointerId.toString()).x=t.clientX,this._touches.item(t.pointerId.toString()).y=t.clientY)},e.prototype._onPointerUp=function(t){this._clearCanvas(),this._joystickPointerID==t.pointerId&&(this._joystickPointerID=-1,this.pressed=!1),this._deltaJoystickVector.x=0,this._deltaJoystickVector.y=0,this._touches.remove(t.pointerId.toString())},e.prototype.setJoystickColor=function(t){this._joystickColor=t},e.prototype.setActionOnTouch=function(t){this._action=t},e.prototype.setAxisForLeftRight=function(t){switch(t){case 0:case 1:case 2:this._axisTargetedByLeftAndRight=t;break;default:this._axisTargetedByLeftAndRight=0}},e.prototype.setAxisForUpDown=function(t){switch(t){case 0:case 1:case 2:this._axisTargetedByUpAndDown=t;break;default:this._axisTargetedByUpAndDown=1}},e.prototype._clearCanvas=function(){this._leftJoystick?e.vjCanvasContext.clearRect(0,0,e.vjCanvasWidth/2,e.vjCanvasHeight):e.vjCanvasContext.clearRect(e.vjCanvasWidth/2,0,e.vjCanvasWidth,e.vjCanvasHeight)},e.prototype._drawVirtualJoystick=function(){var t=this;this.pressed&&(this._clearCanvas(),this._touches.forEach(function(i){i.pointerId===t._joystickPointerID?(e.vjCanvasContext.beginPath(),e.vjCanvasContext.strokeStyle=t._joystickColor,e.vjCanvasContext.lineWidth=6,e.vjCanvasContext.arc(t._joystickPointerStartPos.x,t._joystickPointerStartPos.y,40,0,2*Math.PI,!0),e.vjCanvasContext.stroke(),e.vjCanvasContext.beginPath(),e.vjCanvasContext.strokeStyle=t._joystickColor,e.vjCanvasContext.lineWidth=2,e.vjCanvasContext.arc(t._joystickPointerStartPos.x,t._joystickPointerStartPos.y,60,0,2*Math.PI,!0),e.vjCanvasContext.stroke(),e.vjCanvasContext.beginPath(),e.vjCanvasContext.strokeStyle=t._joystickColor,e.vjCanvasContext.arc(t._joystickPointerPos.x,t._joystickPointerPos.y,40,0,2*Math.PI,!0),e.vjCanvasContext.stroke()):(e.vjCanvasContext.beginPath(),e.vjCanvasContext.fillStyle="white",e.vjCanvasContext.beginPath(),e.vjCanvasContext.strokeStyle="red",e.vjCanvasContext.lineWidth=6,e.vjCanvasContext.arc(i.x,i.y,40,0,2*Math.PI,!0),e.vjCanvasContext.stroke())})),requestAnimationFrame(function(){t._drawVirtualJoystick()})},e.prototype.releaseCanvas=function(){e.vjCanvas&&(document.body.removeChild(e.vjCanvas),e.vjCanvas=null)},e._globalJoystickIndex=0,e}());t.VirtualJoystick=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e={HResolution:1280,VResolution:800,HScreenSize:.149759993,VScreenSize:.0935999975,VScreenCenter:.0467999987,EyeToScreenDistance:.0410000011,LensSeparationDistance:.063500002,InterpupillaryDistance:.064000003,DistortionK:[1,.219999999,.239999995,0],ChromaAbCorrection:[.995999992,-.00400000019,1.01400006,0],PostProcessScaleFactor:1.714605507808412,LensCenterOffset:.151976421},i=function(i){function r(r,n,o,s){i.call(this,r,n,o),this._workMatrix=new t.Matrix,this._actualUp=new t.Vector3(0,0,0),this._aspectRatioAspectRatio=e.HResolution/(2*e.VResolution),this._aspectRatioFov=2*Math.atan(e.PostProcessScaleFactor*e.VScreenSize/(2*e.EyeToScreenDistance));var a=e.HScreenSize/4-e.LensSeparationDistance/2,h=4*a/e.HScreenSize;this._hMatrix=t.Matrix.Translation(s?h:-h,0,0),this.viewport=new t.Viewport(s?0:.5,0,.5,1),this._preViewMatrix=t.Matrix.Translation(s?.5*e.InterpupillaryDistance:-.5*e.InterpupillaryDistance,0,0);new t.OculusDistortionCorrectionPostProcess("Oculus Distortion",this,!s,e)}return __extends(r,i),r.prototype.getProjectionMatrix=function(){return t.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov,this._aspectRatioAspectRatio,this.minZ,this.maxZ,this._workMatrix),this._workMatrix.multiplyToRef(this._hMatrix,this._projectionMatrix),this._projectionMatrix},r.prototype._getViewMatrix=function(){return t.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),t.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),t.Vector3.TransformNormalToRef(this.upVector,this._cameraRotationMatrix,this._actualUp),this.position.addToRef(this._transformedReferencePoint,this._currentTarget),t.Matrix.LookAtLHToRef(this.position,this._currentTarget,this._actualUp,this._workMatrix),this._workMatrix.multiplyToRef(this._preViewMatrix,this._viewMatrix),this._viewMatrix},r}(t.FreeCamera),r=function(t){function e(e,r,n){t.call(this,e,r,n),this._leftCamera=new i(e+"_left",r.clone(),n,!0),this._rightCamera=new i(e+"_right",r.clone(),n,!1),this.subCameras.push(this._leftCamera),this.subCameras.push(this._rightCamera),this._deviceOrientationHandler=this._onOrientationEvent.bind(this)}return __extends(e,t),e.prototype._update=function(){this._leftCamera.position.copyFrom(this.position),this._rightCamera.position.copyFrom(this.position),this._updateCamera(this._leftCamera),this._updateCamera(this._rightCamera),t.prototype._update.call(this)},e.prototype._updateCamera=function(t){t.minZ=this.minZ,t.maxZ=this.maxZ,t.rotation.x=this.rotation.x,t.rotation.y=this.rotation.y,t.rotation.z=this.rotation.z},e.prototype._onOrientationEvent=function(t){var e=t.alpha/180*Math.PI,i=t.beta/180*Math.PI,r=t.gamma/180*Math.PI;return this._offsetOrientation?(this.rotation.y+=e-this._offsetOrientation.yaw,this.rotation.x+=i-this._offsetOrientation.pitch,this.rotation.z+=this._offsetOrientation.roll-r,this._offsetOrientation.yaw=e,this._offsetOrientation.pitch=i,this._offsetOrientation.roll=r,void 0):void(this._offsetOrientation={yaw:e,pitch:i,roll:r})},e.prototype.attachControl=function(e,i){t.prototype.attachControl.call(this,e,i),window.addEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype.detachControl=function(e){t.prototype.detachControl.call(this,e),window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},e}(t.FreeCamera);t.OculusCamera=r}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t;
- }for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e={HResolution:1280,VResolution:800,HScreenSize:.149759993,VScreenSize:.0935999975,VScreenCenter:.0467999987,EyeToScreenDistance:.0410000011,LensSeparationDistance:.063500002,InterpupillaryDistance:.064000003,DistortionK:[1,.219999999,.239999995,0],ChromaAbCorrection:[.995999992,-.00400000019,1.01400006,0],PostProcessScaleFactor:1.714605507808412,LensCenterOffset:.151976421},i=function(i){function r(r,n,o,s){i.call(this,r,n,o),this._workMatrix=new t.Matrix,this._actualUp=new t.Vector3(0,0,0),this._aspectRatioAspectRatio=e.HResolution/(2*e.VResolution),this._aspectRatioFov=2*Math.atan(e.PostProcessScaleFactor*e.VScreenSize/(2*e.EyeToScreenDistance));var a=e.HScreenSize/4-e.LensSeparationDistance/2,h=4*a/e.HScreenSize;this._hMatrix=t.Matrix.Translation(s?h:-h,0,0),this.viewport=new t.Viewport(s?0:.5,0,.5,1),this._preViewMatrix=t.Matrix.Translation(s?.5*e.InterpupillaryDistance:-.5*e.InterpupillaryDistance,0,0);new t.OculusDistortionCorrectionPostProcess("Oculus Distortion",this,!s,e)}return __extends(r,i),r.prototype.getProjectionMatrix=function(){return t.Matrix.PerspectiveFovLHToRef(this._aspectRatioFov,this._aspectRatioAspectRatio,this.minZ,this.maxZ,this._workMatrix),this._workMatrix.multiplyToRef(this._hMatrix,this._projectionMatrix),this._projectionMatrix},r.prototype._getViewMatrix=function(){return t.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix),t.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint),t.Vector3.TransformNormalToRef(this.upVector,this._cameraRotationMatrix,this._actualUp),this.position.addToRef(this._transformedReferencePoint,this._currentTarget),t.Matrix.LookAtLHToRef(this.position,this._currentTarget,this._actualUp,this._workMatrix),this._workMatrix.multiplyToRef(this._preViewMatrix,this._viewMatrix),this._viewMatrix},r}(t.FreeCamera),r=function(e){function r(r,n,o){var s=this;e.call(this,r,n,o),this.angularSensibility=200,this.moveSensibility=75,this._leftCamera=new i(r+"_left",n.clone(),o,!0),this._rightCamera=new i(r+"_right",n.clone(),o,!1),this.subCameras.push(this._leftCamera),this.subCameras.push(this._rightCamera),this._deviceOrientationHandler=this._onOrientationEvent.bind(this),this._gamepads=new t.Gamepads(function(t){s._onNewGameConnected(t)})}return __extends(r,e),r.prototype._onNewGameConnected=function(t){0===t.index&&(this._gamepad=t)},r.prototype._update=function(){this._leftCamera.position.copyFrom(this.position),this._rightCamera.position.copyFrom(this.position),this._updateCamera(this._leftCamera),this._updateCamera(this._rightCamera),e.prototype._update.call(this)},r.prototype._checkInputs=function(){if(this._gamepad){var e=this._gamepad.leftStick,i=e.x/this.moveSensibility,r=e.y/this.moveSensibility;e.x=Math.abs(i)>.005?0+i:0,e.y=Math.abs(r)>.005?0+r:0;var n=t.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),o=t.Vector3.TransformCoordinates(new t.Vector3(e.x,0,-e.y),n);this.cameraDirection=this.cameraDirection.add(o)}},r.prototype._updateCamera=function(t){t.minZ=this.minZ,t.maxZ=this.maxZ,t.rotation.x=this.rotation.x,t.rotation.y=this.rotation.y,t.rotation.z=this.rotation.z},r.prototype._onOrientationEvent=function(t){var e=t.alpha/180*Math.PI,i=t.beta/180*Math.PI,r=t.gamma/180*Math.PI;return this._offsetOrientation?(this.rotation.y+=e-this._offsetOrientation.yaw,this.rotation.x+=i-this._offsetOrientation.pitch,this.rotation.z+=this._offsetOrientation.roll-r,this._offsetOrientation.yaw=e,this._offsetOrientation.pitch=i,this._offsetOrientation.roll=r,void 0):void(this._offsetOrientation={yaw:e,pitch:i,roll:r})},r.prototype.attachControl=function(t,i){e.prototype.attachControl.call(this,t,i),window.addEventListener("deviceorientation",this._deviceOrientationHandler)},r.prototype.detachControl=function(t){e.prototype.detachControl.call(this,t),window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},r.prototype.dispose=function(){this._gamepads.dispose(),e.prototype.dispose.call(this)},r}(t.FreeCamera);t.OculusGamepadCamera=r}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n){e.call(this,i,r,n),this._leftjoystick=new t.VirtualJoystick(!0),this._leftjoystick.setAxisForUpDown(2),this._leftjoystick.setAxisForLeftRight(0),this._leftjoystick.setJoystickSensibility(.15),this._rightjoystick=new t.VirtualJoystick(!1),this._rightjoystick.setAxisForUpDown(0),this._rightjoystick.setAxisForLeftRight(1),this._rightjoystick.reverseUpDown=!0,this._rightjoystick.setJoystickSensibility(.05),this._rightjoystick.setJoystickColor("yellow")}return __extends(i,e),i.prototype._checkInputs=function(){var e=t.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),i=t.Vector3.TransformCoordinates(this._leftjoystick.deltaPosition,e);this.cameraDirection=this.cameraDirection.add(i),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))},i.prototype.dispose=function(){this._leftjoystick.releaseCanvas(),e.prototype.dispose.call(this)},i}(t.FreeCamera);t.VirtualJoysticksCamera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o){e.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._matrices=new Array,this._cachedWorldViewMatrix=new t.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||[],this._options=o}return __extends(i,e),i.prototype.needAlphaBlending=function(){return this._options.needAlphaBlending},i.prototype.needAlphaTesting=function(){return this._options.needAlphaTesting},i.prototype._checkUniform=function(t){-1===this._options.uniforms.indexOf(t)&&this._options.uniforms.push(t)},i.prototype.setTexture=function(t,e){return-1===this._options.samplers.indexOf(t)&&this._options.samplers.push(t),this._textures[t]=e,this},i.prototype.setFloat=function(t,e){return this._checkUniform(t),this._floats[t]=e,this},i.prototype.setFloats=function(t,e){return this._checkUniform(t),this._floatsArrays[t]=e,this},i.prototype.setColor3=function(t,e){return this._checkUniform(t),this._colors3[t]=e,this},i.prototype.setColor4=function(t,e){return this._checkUniform(t),this._colors4[t]=e,this},i.prototype.setVector2=function(t,e){return this._checkUniform(t),this._vectors2[t]=e,this},i.prototype.setVector3=function(t,e){return this._checkUniform(t),this._vectors3[t]=e,this},i.prototype.setMatrix=function(t,e){return this._checkUniform(t),this._matrices[t]=e,this},i.prototype.isReady=function(e,i){var r=this.getScene(),n=r.getEngine();if(!this.checkReadyOnEveryCall&&this._renderId===r.getRenderId())return!0;var o=[],s=new t.EffectFallbacks;i&&o.push("#define INSTANCES"),e&&e.useBones&&(o.push("#define BONES"),o.push("#define BonesPerMesh "+(e.skeleton.bones.length+1)),o.push("#define BONES4"),s.addFallback(0,"BONES4")),n.getAlphaTesting()&&o.push("#define ALPHATEST");var a=this._effect,h=o.join("\n");return this._effect=n.createEffect(this._shaderPath,this._options.attributes,this._options.uniforms,this._options.samplers,h,s,this.onCompiled,this.onError),this._effect.isReady()?(a!==this._effect&&r.resetCachedMaterial(),this._renderId=r.getRenderId(),!0):!1},i.prototype.bindOnlyWorldMatrix=function(t){var e=this.getScene();-1!==this._options.uniforms.indexOf("world")&&this._effect.setMatrix("world",t),-1!==this._options.uniforms.indexOf("worldView")&&(t.multiplyToRef(e.getViewMatrix(),this._cachedWorldViewMatrix),this._effect.setMatrix("worldView",this._cachedWorldViewMatrix)),-1!==this._options.uniforms.indexOf("worldViewProjection")&&this._effect.setMatrix("worldViewProjection",t.multiply(e.getTransformMatrix()))},i.prototype.bind=function(t,i){if(this.bindOnlyWorldMatrix(t),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&&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._matrices)this._effect.setMatrix(r,this._matrices[r])}e.prototype.bind.call(this,t,i)},i.prototype.dispose=function(t){for(var i in this._textures)this._textures[i].dispose();this._textures=[],e.prototype.dispose.call(this,t)},i}(t.Material);t.ShaderMaterial=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(){}return e.prototype.set=function(e,i){switch(i){case t.VertexBuffer.PositionKind:this.positions=e;break;case t.VertexBuffer.NormalKind:this.normals=e;break;case t.VertexBuffer.UVKind:this.uvs=e;break;case t.VertexBuffer.UV2Kind:this.uv2s=e;break;case t.VertexBuffer.ColorKind:this.colors=e;break;case t.VertexBuffer.MatricesIndicesKind:this.matricesIndices=e;break;case t.VertexBuffer.MatricesWeightsKind:this.matricesWeights=e}},e.prototype.applyToMesh=function(t,e){this._applyTo(t,e)},e.prototype.applyToGeometry=function(t,e){this._applyTo(t,e)},e.prototype.updateMesh=function(t,e,i){this._update(t)},e.prototype.updateGeometry=function(t,e,i){this._update(t)},e.prototype._applyTo=function(e,i){this.positions&&e.setVerticesData(t.VertexBuffer.PositionKind,this.positions,i),this.normals&&e.setVerticesData(t.VertexBuffer.NormalKind,this.normals,i),this.uvs&&e.setVerticesData(t.VertexBuffer.UVKind,this.uvs,i),this.uv2s&&e.setVerticesData(t.VertexBuffer.UV2Kind,this.uv2s,i),this.colors&&e.setVerticesData(t.VertexBuffer.ColorKind,this.colors,i),this.matricesIndices&&e.setVerticesData(t.VertexBuffer.MatricesIndicesKind,this.matricesIndices,i),this.matricesWeights&&e.setVerticesData(t.VertexBuffer.MatricesWeightsKind,this.matricesWeights,i),this.indices&&e.setIndices(this.indices)},e.prototype._update=function(e,i,r){this.positions&&e.updateVerticesData(t.VertexBuffer.PositionKind,this.positions,i,r),this.normals&&e.updateVerticesData(t.VertexBuffer.NormalKind,this.normals,i,r),this.uvs&&e.updateVerticesData(t.VertexBuffer.UVKind,this.uvs,i,r),this.uv2s&&e.updateVerticesData(t.VertexBuffer.UV2Kind,this.uv2s,i,r),this.colors&&e.updateVerticesData(t.VertexBuffer.ColorKind,this.colors,i,r),this.matricesIndices&&e.updateVerticesData(t.VertexBuffer.MatricesIndicesKind,this.matricesIndices,i,r),this.matricesWeights&&e.updateVerticesData(t.VertexBuffer.MatricesWeightsKind,this.matricesWeights,i,r),this.indices&&e.setIndices(this.indices)},e.prototype.transform=function(e){var i=t.Vector3.Zero();if(this.positions)for(var r=t.Vector3.Zero(),n=0;n<this.positions.length;n+=3)t.Vector3.FromArrayToRef(this.positions,n,r),t.Vector3.TransformCoordinatesToRef(r,e,i),this.positions[n]=i.x,this.positions[n+1]=i.y,this.positions[n+2]=i.z;if(this.normals){var o=t.Vector3.Zero();for(n=0;n<this.normals.length;n+=3)t.Vector3.FromArrayToRef(this.normals,n,o),t.Vector3.TransformNormalToRef(o,e,i),this.normals[n]=i.x,this.normals[n+1]=i.y,this.normals[n+2]=i.z}},e.prototype.merge=function(t){if(t.indices){this.indices||(this.indices=[]);for(var e=this.positions?this.positions.length/3:0,i=0;i<t.indices.length;i++)this.indices.push(t.indices[i]+e)}if(t.positions)for(this.positions||(this.positions=[]),i=0;i<t.positions.length;i++)this.positions.push(t.positions[i]);if(t.normals)for(this.normals||(this.normals=[]),i=0;i<t.normals.length;i++)this.normals.push(t.normals[i]);if(t.uvs)for(this.uvs||(this.uvs=[]),i=0;i<t.uvs.length;i++)this.uvs.push(t.uvs[i]);if(t.uv2s)for(this.uv2s||(this.uv2s=[]),i=0;i<t.uv2s.length;i++)this.uv2s.push(t.uv2s[i]);if(t.matricesIndices)for(this.matricesIndices||(this.matricesIndices=[]),i=0;i<t.matricesIndices.length;i++)this.matricesIndices.push(t.matricesIndices[i]);if(t.matricesWeights)for(this.matricesWeights||(this.matricesWeights=[]),i=0;i<t.matricesWeights.length;i++)this.matricesWeights.push(t.matricesWeights[i]);if(t.colors)for(this.colors||(this.colors=[]),i=0;i<t.colors.length;i++)this.colors.push(t.colors[i])},e.ExtractFromMesh=function(t,i){return e._ExtractFrom(t,i)},e.ExtractFromGeometry=function(t,i){return e._ExtractFrom(t,i)},e._ExtractFrom=function(i,r){var n=new e;return i.isVerticesDataPresent(t.VertexBuffer.PositionKind)&&(n.positions=i.getVerticesData(t.VertexBuffer.PositionKind,r)),i.isVerticesDataPresent(t.VertexBuffer.NormalKind)&&(n.normals=i.getVerticesData(t.VertexBuffer.NormalKind,r)),i.isVerticesDataPresent(t.VertexBuffer.UVKind)&&(n.uvs=i.getVerticesData(t.VertexBuffer.UVKind,r)),i.isVerticesDataPresent(t.VertexBuffer.UV2Kind)&&(n.uv2s=i.getVerticesData(t.VertexBuffer.UV2Kind,r)),i.isVerticesDataPresent(t.VertexBuffer.ColorKind)&&(n.colors=i.getVerticesData(t.VertexBuffer.ColorKind,r)),i.isVerticesDataPresent(t.VertexBuffer.MatricesIndicesKind)&&(n.matricesIndices=i.getVerticesData(t.VertexBuffer.MatricesIndicesKind,r)),i.isVerticesDataPresent(t.VertexBuffer.MatricesWeightsKind)&&(n.matricesWeights=i.getVerticesData(t.VertexBuffer.MatricesWeightsKind,r)),n.indices=i.getIndices(r),n},e.CreateRibbon=function(i,r,n,o,s){void 0===s&&(s=t.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,c,l,u,f=[],d=[],p=[],m=[],_=[],g=[],v=[],y=[],x=[],b=[];if(i.length<2){var M=[],T=[];for(l=0;l<i[0].length-o;l++)M.push(i[0][l]),T.push(i[0][l+o]);i=[M,T]}var S=0;for(h=i[0].length,c=0;c<i.length;c++){v[c]=0,_[c]=[0];var A=i[c],w=A.length;for(h=w>h?h:w,x[c]=w,b[c]=S,u=0;w>u;){if(f.push(A[u].x,A[u].y,A[u].z),u>0){var D=A[u].subtract(A[u-1]).length(),E=D+v[c];_[c].push(E),v[c]=E}u++}n&&(D=A[0].subtract(A[u-1]).length(),E=D+v[c],v[c]=E),S+=w}for(l=0;h>l;l++){y[l]=0,g[l]=[0];var C,P;for(c=0;c<i.length-1;c++)C=i[c],P=i[c+1],D=P[l].subtract(C[l]).length(),E=D+y[l],g[l].push(E),y[l]=E;r&&(C=i[c],P=i[0],D=P[l].subtract(C[l]).length(),E=D+y[l],y[l]=E)}var I,L;for(c=0;c<i.length;c++)for(l=0;h>l;l++)I=_[c][l]/v[c],L=g[l][c]/y[l],m.push(I,L);c=0;for(var R,O,B,F,V=0,N=x[c]-1,z=x[c+1]-1,k=z>N?N:z,U=b[1]-b[0],W=r?x.length:x.length-1;k>=V&&W>c;)R=V,O=V+U,B=V+1,F=V+U+1,d.push(V,V+U,V+1),d.push(V+U+1,V+1,V+U),V+=1,V===k&&(n&&(d.push(V,V+U,b[c]),d.push(b[c]+U,b[c],V+U),B=b[c],F=b[c]+U),c++,c===x.length-1?(U=b[0]-b[c],N=x[c]-1,z=x[0]-1):(U=b[c+1]-b[c],N=x[c]-1,z=x[c+1]-1),V=b[c],k=z>N?N+V:z+V);e.ComputeNormals(f,d,p),e._ComputeSides(s,f,d,p,m);var G=new e;return G.indices=d,G.positions=f,G.normals=p,G.uvs=m,G},e.CreateBox=function(i,r){void 0===r&&(r=t.Mesh.DEFAULTSIDE);var n=[new t.Vector3(0,0,1),new t.Vector3(0,0,-1),new t.Vector3(1,0,0),new t.Vector3(-1,0,0),new t.Vector3(0,1,0),new t.Vector3(0,-1,0)],o=[],s=[],a=[],h=[];i=i||1;for(var c=0;c<n.length;c++){var l=n[c],u=new t.Vector3(l.y,l.z,l.x),f=t.Vector3.Cross(l,u),d=s.length/3;o.push(d),o.push(d+1),o.push(d+2),o.push(d),o.push(d+2),o.push(d+3);var p=l.subtract(u).subtract(f).scale(i/2);s.push(p.x,p.y,p.z),a.push(l.x,l.y,l.z),h.push(1,1),p=l.subtract(u).add(f).scale(i/2),s.push(p.x,p.y,p.z),a.push(l.x,l.y,l.z),h.push(0,1),p=l.add(u).add(f).scale(i/2),s.push(p.x,p.y,p.z),a.push(l.x,l.y,l.z),h.push(0,0),p=l.add(u).subtract(f).scale(i/2),s.push(p.x,p.y,p.z),a.push(l.x,l.y,l.z),h.push(1,0)}e._ComputeSides(r,s,o,a,h);var m=new e;return m.indices=o,m.positions=s,m.normals=a,m.uvs=h,m},e.CreateSphere=function(i,r,n){void 0===n&&(n=t.Mesh.DEFAULTSIDE),i=i||32,r=r||1;for(var o=r/2,s=2+i,a=2*s,h=[],c=[],l=[],u=[],f=0;s>=f;f++){for(var d=f/s,p=d*Math.PI,m=0;a>=m;m++){var _=m/a,g=_*Math.PI*2,v=t.Matrix.RotationZ(-p),y=t.Matrix.RotationY(g),x=t.Vector3.TransformCoordinates(t.Vector3.Up(),v),b=t.Vector3.TransformCoordinates(x,y),M=b.scale(o),T=t.Vector3.Normalize(M);c.push(M.x,M.y,M.z),l.push(T.x,T.y,T.z),u.push(d,_)}if(f>0)for(var S=c.length/3,A=S-2*(a+1);S>A+a+2;A++)h.push(A),h.push(A+1),h.push(A+a+1),h.push(A+a+1),h.push(A+1),h.push(A+a+2)}e._ComputeSides(n,c,h,l,u);var w=new e;return w.indices=h,w.positions=c,w.normals=l,w.uvs=u,w},e.CreateCylinder=function(i,r,n,o,s,a){void 0===s&&(s=1),void 0===a&&(a=t.Mesh.DEFAULTSIDE);var h=r/2,c=n/2,l=[],u=[],f=[],d=[];i=i||1,r=r||.5,n=n||1,o=o||16,s=s||1,s=1>s?1:s;for(var p=function(e){var i=2*e*Math.PI/o,r=Math.cos(i),n=Math.sin(i);return new t.Vector3(r,0,n)},m=function(e){var r=e?h:c;if(0!==r){var n=u.length/3,s=new t.Vector3(0,i/2,0),a=new t.Vector2(.5,.5);e||(s.scaleInPlace(-1),a.x=-a.x);for(var f=0;o>f;f++){var m=p(f),_=m.scale(r).add(s),g=new t.Vector2(m.x*a.x+.5,m.z*a.y+.5);u.push(_.x,_.y,_.z),d.push(g.x,g.y)}for(f=0;o-2>f;f++)e?(l.push(n),l.push(n+(f+1)%o),l.push(n+(f+2)%o)):(l.push(n),l.push(n+(f+2)%o),l.push(n+(f+1)%o))}},_=new t.Vector3(0,-1,0).scale(i/2),g=new t.Vector3(0,1,0).scale(i/s),v=o+1,y=0;o>=y;y++)for(var x,b=p(y),M=new t.Vector2(y/o,0),T=c,S=0;s>=S;S++)x=b.scale(T),x.addInPlace(_.add(g.scale(S))),M.y+=1/s,T+=(h-c)/s,u.push(x.x,x.y,x.z),d.push(M.x,M.y);for(s+=1,S=0;s-1>S;S++)for(y=0;o>=y;y++)l.push(y*s+S),l.push((y*s+(S+s))%(v*s)),l.push(y*s+(S+1)),l.push(y*s+(S+1)),l.push((y*s+(S+s))%(v*s)),l.push((y*s+(S+s+1))%(v*s));m(!0),m(!1),e.ComputeNormals(u,l,f),e._ComputeSides(a,u,l,f,d);var A=new e;return A.indices=l,A.positions=u,A.normals=f,A.uvs=d,A},e.CreateTorus=function(i,r,n,o){void 0===o&&(o=t.Mesh.DEFAULTSIDE);var s=[],a=[],h=[],c=[];i=i||1,r=r||.5,n=n||16;for(var l=n+1,u=0;n>=u;u++)for(var f=u/n,d=u*Math.PI*2/n-Math.PI/2,p=t.Matrix.Translation(i/2,0,0).multiply(t.Matrix.RotationY(d)),m=0;n>=m;m++){var _=1-m/n,g=m*Math.PI*2/n+Math.PI,v=Math.cos(g),y=Math.sin(g),x=new t.Vector3(v,y,0),b=x.scale(r/2),M=new t.Vector2(f,_);b=t.Vector3.TransformCoordinates(b,p),x=t.Vector3.TransformNormal(x,p),a.push(b.x,b.y,b.z),h.push(x.x,x.y,x.z),c.push(M.x,M.y);var T=(u+1)%l,S=(m+1)%l;s.push(u*l+m),s.push(u*l+S),s.push(T*l+m),s.push(u*l+S),s.push(T*l+S),s.push(T*l+m)}e._ComputeSides(o,a,s,h,c);var A=new e;return A.indices=s,A.positions=a,A.normals=h,A.uvs=c,A},e.CreateLines=function(t){for(var i=[],r=[],n=0;n<t.length;n++)r.push(t[n].x,t[n].y,t[n].z),n>0&&(i.push(n-1),i.push(n));var o=new e;return o.indices=i,o.positions=r,o},e.CreateGround=function(i,r,n){var o,s,a=[],h=[],c=[],l=[];for(i=i||1,r=r||1,n=n||1,o=0;n>=o;o++)for(s=0;n>=s;s++){var u=new t.Vector3(s*i/n-i/2,0,(n-o)*r/n-r/2),f=new t.Vector3(0,1,0);h.push(u.x,u.y,u.z),c.push(f.x,f.y,f.z),l.push(s/n,1-o/n)}for(o=0;n>o;o++)for(s=0;n>s;s++)a.push(s+1+(o+1)*(n+1)),a.push(s+1+o*(n+1)),a.push(s+o*(n+1)),a.push(s+(o+1)*(n+1)),a.push(s+1+(o+1)*(n+1)),a.push(s+o*(n+1));var d=new e;return d.indices=a,d.positions=h,d.normals=c,d.uvs=l,d},e.CreateTiledGround=function(i,r,n,o,s,a){function h(e,i,r,n){var o=p.length/3,s=a.w+1;for(c=0;c<a.h;c++)for(l=0;l<a.w;l++){var h=[o+l+c*s,o+(l+1)+c*s,o+(l+1)+(c+1)*s,o+l+(c+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=t.Vector3.Zero(),f=new t.Vector3(0,1,0);for(c=0;c<=a.h;c++)for(u.z=c*(n-i)/a.h+i,l=0;l<=a.w;l++)u.x=l*(r-e)/a.w+e,u.y=0,p.push(u.x,u.y,u.z),m.push(f.x,f.y,f.z),_.push(l/a.w,c/a.h)}void 0===s&&(s={w:1,h:1}),void 0===a&&(a={w:1,h:1});var c,l,u,f,d=[],p=[],m=[],_=[];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 g={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*g.w,r+u*g.h,i+(f+1)*g.w,r+(u+1)*g.h);var v=new e;return v.indices=d,v.positions=p,v.normals=m,v.uvs=_,v},e.CreateGroundFromHeightMap=function(i,r,n,o,s,a,h,c){var l,u,f=[],d=[],p=[],m=[];for(l=0;n>=l;l++)for(u=0;n>=u;u++){var _=new t.Vector3(u*i/n-i/2,0,(n-l)*r/n-r/2),g=(_.x+i/2)/i*(h-1)|0,v=(1-(_.z+r/2)/r)*(c-1)|0,y=4*(g+v*h),x=a[y]/255,b=a[y+1]/255,M=a[y+2]/255,T=.3*x+.59*b+.11*M;_.y=o+(s-o)*T,d.push(_.x,_.y,_.z),p.push(0,0,0),m.push(u/n,1-l/n)}for(l=0;n>l;l++)for(u=0;n>u;u++)f.push(u+1+(l+1)*(n+1)),f.push(u+1+l*(n+1)),f.push(u+l*(n+1)),f.push(u+(l+1)*(n+1)),f.push(u+1+(l+1)*(n+1)),f.push(u+l*(n+1));e.ComputeNormals(d,f,p);var S=new e;return S.indices=f,S.positions=d,S.normals=p,S.uvs=m,S},e.CreatePlane=function(i,r){void 0===r&&(r=t.Mesh.DEFAULTSIDE);var n=[],o=[],s=[],a=[];i=i||1;var h=i/2;o.push(-h,-h,0),s.push(0,0,-1),a.push(0,0),o.push(h,-h,0),s.push(0,0,-1),a.push(1,0),o.push(h,h,0),s.push(0,0,-1),a.push(1,1),o.push(-h,h,0),s.push(0,0,-1),a.push(0,1),n.push(0),n.push(1),n.push(2),n.push(0),n.push(2),n.push(3),e._ComputeSides(r,o,n,s,a);var c=new e;return c.indices=n,c.positions=o,c.normals=s,c.uvs=a,c},e.CreateDisc=function(i,r,n){void 0===n&&(n=t.Mesh.DEFAULTSIDE);var o=[],s=[],a=[],h=[];o.push(0,0,0),h.push(.5,.5);for(var c=2*Math.PI/r,l=0;l<2*Math.PI;l+=c){var u=Math.cos(l),f=Math.sin(l),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,_=1;m-1>_;_++)s.push(_+1,0,_);e.ComputeNormals(o,s,a),e._ComputeSides(n,o,s,a,h);var g=new e;return g.indices=s,g.positions=o,g.normals=a,g.uvs=h,g},e.CreateTorusKnot=function(i,r,n,o,s,a,h){void 0===h&&(h=t.Mesh.DEFAULTSIDE);var c=[],l=[],u=[],f=[];i=i||2,r=r||.5,n=n||32,o=o||32,s=s||2,a=a||3;for(var d=function(e){var r=Math.cos(e),n=Math.sin(e),o=a/s*e,h=Math.cos(o),c=i*(2+h)*.5*r,l=i*(2+h)*n*.5,u=i*Math.sin(o)*.5;return new t.Vector3(c,l,u)},p=0;n>=p;p++){var m=p%n,_=m/n*2*s*Math.PI,g=d(_),v=d(_+.01),y=v.subtract(g),x=v.add(g),b=t.Vector3.Cross(y,x);x=t.Vector3.Cross(b,y),b.normalize(),x.normalize();for(var M=0;o>M;M++){var T=M%o,S=T/o*2*Math.PI,A=-r*Math.cos(S),w=r*Math.sin(S);l.push(g.x+A*x.x+w*b.x),l.push(g.y+A*x.y+w*b.y),l.push(g.z+A*x.z+w*b.z),f.push(p/n),f.push(M/o)}}for(p=0;n>p;p++)for(M=0;o>M;M++){var D=(M+1)%o,E=p*o+M,C=(p+1)*o+M,P=(p+1)*o+D,I=p*o+D;c.push(I),c.push(C),c.push(E),c.push(I),c.push(P),c.push(C)}e.ComputeNormals(l,c,u),e._ComputeSides(h,l,c,u,f);var L=new e;return L.indices=c,L.positions=l,L.normals=u,L.uvs=f,L},e.ComputeNormals=function(e,i,r){var n=0,o=t.Vector3.Zero(),s=t.Vector3.Zero(),a=t.Vector3.Zero(),h=t.Vector3.Zero(),c=t.Vector3.Zero(),l=t.Vector3.Zero(),u=t.Vector3.Zero(),f=t.Vector3.Zero(),d=t.Vector3.Zero(),p=i.length/3;for(n=0;p>n;n++){var m=i[3*n],_=i[3*n+1],g=i[3*n+2];t.Vector3.FromFloatsToRef(e[3*m],e[3*m+1],e[3*m+2],o),t.Vector3.FromFloatsToRef(e[3*_],e[3*_+1],e[3*_+2],s),t.Vector3.FromFloatsToRef(e[3*g],e[3*g+1],e[3*g+2],a),o.subtractToRef(s,h),a.subtractToRef(s,c),t.Vector3.CrossToRef(h,c,l),l.normalize(),r[3*m]=r[3*m]||0,r[3*m+1]=r[3*m+1]||0,r[3*m+2]=r[3*m+2]||0,r[3*_]=r[3*_]||0,r[3*_+1]=r[3*_+1]||0,r[3*_+2]=r[3*_+2]||0,r[3*g]=r[3*g]||0,r[3*g+1]=r[3*g+1]||0,r[3*g+2]=r[3*g+2]||0,t.Vector3.FromFloatsToRef(r[3*m],r[3*m+1],r[3*m+2],u),t.Vector3.FromFloatsToRef(r[3*_],r[3*_+1],r[3*_+2],f),t.Vector3.FromFloatsToRef(r[3*g],r[3*g+1],r[3*g+2],d),u=u.addInPlace(l),f=f.addInPlace(l),d=d.addInPlace(l),r[3*m]=u.x,r[3*m+1]=u.y,r[3*m+2]=u.z,r[3*_]=f.x,r[3*_+1]=f.y,r[3*_+2]=f.z,r[3*g]=d.x,r[3*g+1]=d.y,r[3*g+2]=d.z}for(n=0;n<r.length/3;n++)t.Vector3.FromFloatsToRef(r[3*n],r[3*n+1],r[3*n+2],u),u.normalize(),r[3*n]=u.x,r[3*n+1]=u.y,r[3*n+2]=u.z},e._ComputeSides=function(e,i,r,n,o){var s,a,h=r.length,c=n.length;switch(e=e||t.Mesh.DEFAULTSIDE){case t.Mesh.FRONTSIDE:break;case t.Mesh.BACKSIDE:var l;for(s=0;h>s;s+=3)l=r[s],r[s]=r[s+2],r[s+2]=l;for(a=0;c>a;a++)n[a]=-n[a];break;case t.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;c>a;a++)n[c+a]=-n[a];for(var p=o.length,m=0;p>m;m++)o[m+p]=o[m]}},e}();t.VertexData=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e,i){e._leftCamera.isIntermediate=!0,e.subCameras.push(e._leftCamera),e.subCameras.push(e._rightCamera),e._leftTexture=new t.PassPostProcess(i+"_leftTexture",1,e._leftCamera),e._anaglyphPostProcess=new t.AnaglyphPostProcess(i+"_anaglyph",1,e._rightCamera),e._anaglyphPostProcess.onApply=function(t){t.setTextureFromPostProcess("leftSampler",e._leftTexture)},e._update()},i=function(i){function r(r,n,o,s,a,h,c){i.call(this,r,n,o,s,a,c),this._eyeSpace=t.Tools.ToRadians(h),this._leftCamera=new t.ArcRotateCamera(r+"_left",n-this._eyeSpace,o,s,a,c),this._rightCamera=new t.ArcRotateCamera(r+"_right",n+this._eyeSpace,o,s,a,c),e(this,r)}return __extends(r,i),r.prototype._update=function(){this._updateCamera(this._leftCamera),this._updateCamera(this._rightCamera),this._leftCamera.alpha=this.alpha-this._eyeSpace,this._rightCamera.alpha=this.alpha+this._eyeSpace,i.prototype._update.call(this)},r.prototype._updateCamera=function(t){t.beta=this.beta,t.radius=this.radius,t.minZ=this.minZ,t.maxZ=this.maxZ,t.fov=this.fov,t.target=this.target},r}(t.ArcRotateCamera);t.AnaglyphArcRotateCamera=i;var r=function(i){function r(r,n,o,s){i.call(this,r,n,s),this._eyeSpace=t.Tools.ToRadians(o),this._transformMatrix=new t.Matrix,this._leftCamera=new t.FreeCamera(r+"_left",n.clone(),s),this._rightCamera=new t.FreeCamera(r+"_right",n.clone(),s),e(this,r)}return __extends(r,i),r.prototype._getSubCameraPosition=function(e,i){var r=this.getTarget();t.Matrix.Translation(-r.x,-r.y,-r.z).multiplyToRef(t.Matrix.RotationY(e),this._transformMatrix),this._transformMatrix=this._transformMatrix.multiply(t.Matrix.Translation(r.x,r.y,r.z)),t.Vector3.TransformCoordinatesToRef(this.position,this._transformMatrix,i)},r.prototype._update=function(){this._getSubCameraPosition(-this._eyeSpace,this._leftCamera.position),this._getSubCameraPosition(this._eyeSpace,this._rightCamera.position),this._updateCamera(this._leftCamera),this._updateCamera(this._rightCamera),i.prototype._update.call(this)},r.prototype._updateCamera=function(t){t.minZ=this.minZ,t.maxZ=this.maxZ,t.fov=this.fov,t.viewport=this.viewport,t.setTarget(this.getTarget())},r}(t.FreeCamera);t.AnaglyphFreeCamera=r}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n,o,s){t.call(this,e,"anaglyph",null,["leftSampler"],i,r,n,o,s)}return __extends(e,t),e}(t.PostProcess);t.AnaglyphPostProcess=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(){}return e.EnableFor=function(t){t._tags=t._tags||{},t.hasTags=function(){return e.HasTags(t)},t.addTags=function(i){return e.AddTagsTo(t,i)},t.removeTags=function(i){return e.RemoveTagsFrom(t,i)},t.matchesTagsQuery=function(i){return e.MatchesQuery(t,i)}},e.DisableFor=function(t){delete t._tags,delete t.hasTags,delete t.addTags,delete t.removeTags,delete t.matchesTagsQuery},e.HasTags=function(e){return e._tags?!t.Tools.IsEmpty(e._tags):!1},e.GetTags=function(t){return t._tags?t._tags:null},e.AddTagsTo=function(t,i){if(i){var r=i.split(" ");for(var n in r)e._AddTagTo(t,r[n])}},e._AddTagTo=function(t,i){i=i.trim(),""!==i&&"true"!==i&&"false"!==i&&(i.match(/[\s]/)||i.match(/^([!]|([|]|[&]){2})/)||(e.EnableFor(t),t._tags[i]=!0))},e.RemoveTagsFrom=function(t,i){if(e.HasTags(t)){var r=i.split(" ");for(var n in r)e._RemoveTagFrom(t,r[n])}},e._RemoveTagFrom=function(t,e){delete t._tags[e]},e.MatchesQuery=function(i,r){return void 0===r?!0:""===r?e.HasTags(i):t.Internals.AndOrNotEvaluator.Eval(r,function(t){return e.HasTags(i)&&i._tags[t]})},e}();t.Tags=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e;!function(t){var e=function(){function t(){}return t.Eval=function(e,i){return e=e.match(/\([^\(\)]*\)/g)?e.replace(/\([^\(\)]*\)/g,function(e){return e=e.slice(1,e.length-1),t._HandleParenthesisContent(e,i)}):t._HandleParenthesisContent(e,i),"true"===e?!0:"false"===e?!1:t.Eval(e,i)},t._HandleParenthesisContent=function(e,i){i=i||function(t){return"true"===t?!0:!1};var r,n=e.split("||");for(var o in n){var s=t._SimplifyNegation(n[o].trim()),a=s.split("&&");if(a.length>1)for(var h=0;h<a.length;++h){var c=t._SimplifyNegation(a[h].trim());if(r="true"!==c&&"false"!==c?"!"===c[0]?!i(c.substring(1)):i(c):"true"===c?!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"},t._SimplifyNegation=function(t){return t=t.replace(/^[\s!]+/,function(t){return t=t.replace(/[\s]/g,function(){return""}),t.length%2?"!":""}),t=t.trim(),"!true"===t?t="false":"!false"===t&&(t="true"),t},t}();t.AndOrNotEvaluator=e}(e=t.Internals||(t.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i,r,n,o,s){this._enabled=!0,this._refCount=0,this._name=i,this._renderTexture=new t.RenderTargetTexture(i,r,e),this.setRenderList(n),this._renderTexture.onBeforeRender=o,this._renderTexture.onAfterRender=s,this._scene=e,this._renderList=n}return e.prototype._incRefCount=function(){return 0===this._refCount&&this._scene.customRenderTargets.push(this._renderTexture),++this._refCount},e.prototype._decRefCount=function(){return this._refCount--,this._refCount<=0&&this._scene.customRenderTargets.splice(this._scene.customRenderTargets.indexOf(this._renderTexture),1),this._refCount},e.prototype._update=function(){this.setRenderList(this._renderList)},e.prototype.setRenderList=function(t){this._renderTexture.renderList=t},e.prototype.getRenderTexture=function(){return this._renderTexture},e}();t.PostProcessRenderPass=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,e,i,r){this._engine=t,this._name=e,this._singleInstance=r||!0,this._getPostProcess=i,this._cameras=[],this._indicesForCamera=[],this._postProcesses={},this._renderPasses={},this._renderEffectAsPasses={}}return e.prototype._update=function(){for(var t in this._renderPasses)this._renderPasses[t]._update()},e.prototype.addPass=function(t){this._renderPasses[t._name]=t,this._linkParameters()},e.prototype.removePass=function(t){delete this._renderPasses[t._name],this._linkParameters()},e.prototype.addRenderEffectAsPass=function(t){this._renderEffectAsPasses[t._name]=t,this._linkParameters()},e.prototype.getPass=function(t){for(var e in this._renderPasses)if(e===t)return this._renderPasses[t]},e.prototype.emptyPasses=function(){this._renderPasses={},this._linkParameters()},e.prototype._attachCameras=function(e){for(var i,r=t.Tools.MakeArray(e||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()},e.prototype._detachCameras=function(e){for(var i=t.Tools.MakeArray(e||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()}},e.prototype._enable=function(e){for(var i=t.Tools.MakeArray(e||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]]&&e[r].attachPostProcess(this._postProcesses[this._singleInstance?0:o],this._indicesForCamera[o][s]);for(var a in this._renderPasses)this._renderPasses[a]._incRefCount()}},e.prototype._disable=function(e){for(var i=t.Tools.MakeArray(e||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()}},e.prototype.getPostProcess=function(t){return this._singleInstance?this._postProcesses[0]:this._postProcesses[t.name]},e.prototype._linkParameters=function(){var t=this;for(var e in this._postProcesses)this.applyParameters&&this.applyParameters(this._postProcesses[e]),this._postProcesses[e].onBeforeRender=function(e){t._linkTextures(e)}},e.prototype._linkTextures=function(t){for(var e in this._renderPasses)t.setTexture(e,this._renderPasses[e].getRenderTexture());for(var i in this._renderEffectAsPasses)t.setTextureFromPostProcess(i+"Sampler",this._renderEffectAsPasses[i].getPostProcess())},e}();t.PostProcessRenderEffect=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,e){this._engine=t,this._name=e,this._renderEffects={},this._renderEffectsForIsolatedPass={},this._cameras=[]}return e.prototype.addEffect=function(t){this._renderEffects[t._name]=t},e.prototype._enableEffect=function(e,i){var r=this._renderEffects[e];r&&r._enable(t.Tools.MakeArray(i||this._cameras))},e.prototype._disableEffect=function(e,i){var r=this._renderEffects[e];r&&r._disable(t.Tools.MakeArray(i||this._cameras))},e.prototype._attachCameras=function(e,i){for(var r=t.Tools.MakeArray(e||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++)e.splice(n[o],1);for(var h in this._renderEffects)this._renderEffects[h]._attachCameras(r)},e.prototype._detachCameras=function(e){var i=t.Tools.MakeArray(e||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)},e.prototype._enableDisplayOnlyPass=function(i,r){var n=this,o=t.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=e.PASS_SAMPLER_NAME;for(var h=0;h<o.length;h++){var c=o[h],l=c.name;this._renderEffectsForIsolatedPass[l]=this._renderEffectsForIsolatedPass[l]||new t.PostProcessRenderEffect(this._engine,e.PASS_EFFECT_NAME,function(){return new t.DisplayPassPostProcess(e.PASS_EFFECT_NAME,1,null,null,n._engine,!0)}),this._renderEffectsForIsolatedPass[l].emptyPasses(),this._renderEffectsForIsolatedPass[l].addPass(s),this._renderEffectsForIsolatedPass[l]._attachCameras(c)}}},e.prototype._disableDisplayOnlyPass=function(i){for(var r=this,n=t.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 t.PostProcessRenderEffect(this._engine,e.PASS_EFFECT_NAME,function(){return new t.DisplayPassPostProcess(e.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)},e.prototype._update=function(){for(var t in this._renderEffects)this._renderEffects[t]._update();for(var e=0;e<this._cameras.length;e++){var i=this._cameras[e].name;this._renderEffectsForIsolatedPass[i]&&this._renderEffectsForIsolatedPass[i]._update()}},e.PASS_EFFECT_NAME="passEffect",e.PASS_SAMPLER_NAME="passSampler",e}();t.PostProcessRenderPipeline=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(){this._renderPipelines={}}return t.prototype.addPipeline=function(t){this._renderPipelines[t._name]=t},t.prototype.attachCamerasToRenderPipeline=function(t,e,i){var r=this._renderPipelines[t];r&&r._attachCameras(e,i)},t.prototype.detachCamerasFromRenderPipeline=function(t,e){var i=this._renderPipelines[t];i&&i._detachCameras(e)},t.prototype.enableEffectInPipeline=function(t,e,i){var r=this._renderPipelines[t];r&&r._enableEffect(e,i)},t.prototype.disableEffectInPipeline=function(t,e,i){var r=this._renderPipelines[t];r&&r._disableEffect(e,i)},t.prototype.enableDisplayOnlyPassInPipeline=function(t,e,i){var r=this._renderPipelines[t];r&&r._enableDisplayOnlyPass(e,i)},t.prototype.disableDisplayOnlyPassInPipeline=function(t,e){var i=this._renderPipelines[t];i&&i._disableDisplayOnlyPass(e)},t.prototype.update=function(){for(var t in this._renderPipelines)this._renderPipelines[t]._update()},t}();t.PostProcessRenderPipelineManager=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n,o,s){t.call(this,e,"displayPass",["passSampler"],["passSampler"],i,r,n,o,s)}return __extends(e,t),e}(t.PostProcess);t.DisplayPassPostProcess=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e){this.frontColor=new t.Color3(1,1,1),this.backColor=new t.Color3(.1,.1,.1),this.showBackLines=!0,this.renderList=new t.SmartArray(32),this._scene=e}return e.prototype._prepareRessources=function(){if(!this._colorShader){this._colorShader=new t.ShaderMaterial("colorShader",this._scene,"color",{attributes:["position"],uniforms:["worldViewProjection","color"]});var e=this._scene.getEngine(),i=t.VertexData.CreateBox(1);this._vb=new t.VertexBuffer(e,i.positions,t.VertexBuffer.PositionKind,!1),this._ib=e.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])}},e.prototype.reset=function(){this.renderList.reset()},e.prototype.render=function(){if(0!==this.renderList.length&&(this._prepareRessources(),this._colorShader.isReady())){var e=this._scene.getEngine();e.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=t.Matrix.Scaling(s.x,s.y,s.z).multiply(t.Matrix.Translation(a.x,a.y,a.z)).multiply(r.getWorldMatrix());e.bindBuffers(this._vb.getBuffer(),this._ib,[3],12,this._colorShader.getEffect()),this.showBackLines&&(e.setDepthFunctionToGreaterOrEqual(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.backColor.toColor4()),this._colorShader.bind(h),e.draw(!1,0,24)),e.setDepthFunctionToLess(),this._scene.resetCachedMaterial(),this._colorShader.setColor4("color",this.frontColor.toColor4()),this._colorShader.bind(h),e.draw(!1,0,24)}this._colorShader.unbind(),e.setDepthFunctionToLessOrEqual(),e.setDepthWrite(!0)}},e.prototype.dispose=function(){this._colorShader&&(this._colorShader.dispose(),this._vb.dispose(),this._scene.getEngine()._releaseBuffer(this._ib))},e}();t.BoundingBoxRenderer=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(){function t(t){this._actionManager=t}return t.prototype.isValid=function(){return!0},t.prototype._getProperty=function(t){return this._actionManager._getProperty(t)},t.prototype._getEffectiveTarget=function(t,e){return this._actionManager._getEffectiveTarget(t,e)},t}();t.Condition=e;var i=function(t){function e(i,r,n,o,s){void 0===s&&(s=e.IsEqual),t.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(e,t),Object.defineProperty(e,"IsEqual",{get:function(){return e._IsEqual},enumerable:!0,configurable:!0}),Object.defineProperty(e,"IsDifferent",{get:function(){return e._IsDifferent},enumerable:!0,configurable:!0}),Object.defineProperty(e,"IsGreater",{get:function(){return e._IsGreater},enumerable:!0,configurable:!0}),Object.defineProperty(e,"IsLesser",{get:function(){return e._IsLesser},enumerable:!0,configurable:!0}),e.prototype.isValid=function(){switch(this.operator){case e.IsGreater:return this._target[this._property]>this.value;case e.IsLesser:return this._target[this._property]<this.value;case e.IsEqual:case e.IsDifferent:var t;return t=this.value.equals?this.value.equals(this._target[this._property]):this.value===this._target[this._property],this.operator===e.IsEqual?t:!t}return!1},e._IsEqual=0,e._IsDifferent=1,e._IsGreater=2,e._IsLesser=3,e}(e);t.ValueCondition=i;var r=function(t){function e(e,i){t.call(this,e),this.predicate=i}return __extends(e,t),e.prototype.isValid=function(){return this.predicate()},e}(e);t.PredicateCondition=r;var n=function(t){function e(e,i,r){t.call(this,e),this.value=r,this._target=i}return __extends(e,t),e.prototype.isValid=function(){return this._target.state===this.value},e}(e);t.StateCondition=n}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(t,e){this.triggerOptions=t,t.parameter?(this.trigger=t.trigger,this._triggerParameter=t.parameter):this.trigger=t,this._nextActiveAction=this,this._condition=e}return t.prototype._prepare=function(){},t.prototype.getTriggerParameter=function(){return this._triggerParameter},t.prototype._executeCurrent=function(t){if(this._nextActiveAction._condition){var e=this._nextActiveAction._condition,i=this._actionManager.getScene().getRenderId();if(e._evaluationId===i){if(!e._currentResult)return}else{if(e._evaluationId=i,!e.isValid())return void(e._currentResult=!1);e._currentResult=!0}}this._nextActiveAction.execute(t),this._nextActiveAction._child?(this._nextActiveAction._child._actionManager||(this._nextActiveAction._child._actionManager=this._actionManager),this._nextActiveAction=this._nextActiveAction._child):this._nextActiveAction=this},t.prototype.execute=function(t){},t.prototype.then=function(t){return this._child=t,t._actionManager=this._actionManager,t._prepare(),t},t.prototype._getProperty=function(t){return this._actionManager._getProperty(t)},t.prototype._getEffectiveTarget=function(t,e){return this._actionManager._getEffectiveTarget(t,e)},t}();t.Action=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(t,e,i,r,n){this.source=t,this.pointerX=e,this.pointerY=i,this.meshUnderPointer=r,this.sourceEvent=n}return t.CreateNew=function(e,i){var r=e.getScene();return new t(e,r.pointerX,r.pointerY,r.meshUnderPointer,i)},t.CreateNewFromScene=function(e,i){return new t(null,e.pointerX,e.pointerY,e.meshUnderPointer,i)},t}();t.ActionEvent=e;var i=function(){function e(t){this.actions=new Array,this._scene=t,t._actionManagers.push(this)}return Object.defineProperty(e,"NothingTrigger",{get:function(){return e._NothingTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnPickTrigger",{get:function(){return e._OnPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnLeftPickTrigger",{get:function(){return e._OnLeftPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnRightPickTrigger",{get:function(){return e._OnRightPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnCenterPickTrigger",{get:function(){return e._OnCenterPickTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnPointerOverTrigger",{get:function(){return e._OnPointerOverTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnPointerOutTrigger",{get:function(){return e._OnPointerOutTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnEveryFrameTrigger",{get:function(){return e._OnEveryFrameTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnIntersectionEnterTrigger",{get:function(){return e._OnIntersectionEnterTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnIntersectionExitTrigger",{get:function(){return e._OnIntersectionExitTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnKeyDownTrigger",{get:function(){return e._OnKeyDownTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnKeyUpTrigger",{get:function(){return e._OnKeyUpTrigger},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OnPickUpTrigger",{get:function(){return e._OnPickUpTrigger},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){var t=this._scene._actionManagers.indexOf(this);t>-1&&this._scene._actionManagers.splice(t,1)},e.prototype.getScene=function(){return this._scene},e.prototype.hasSpecificTriggers=function(t){for(var e=0;e<this.actions.length;e++){var i=this.actions[e];if(t.indexOf(i.trigger)>-1)return!0}return!1},e.prototype.hasSpecificTrigger=function(t){for(var e=0;e<this.actions.length;e++){var i=this.actions[e];if(i.trigger===t)return!0}return!1},Object.defineProperty(e.prototype,"hasPointerTriggers",{get:function(){for(var t=0;t<this.actions.length;t++){var i=this.actions[t];if(i.trigger>=e._OnPickTrigger&&i.trigger<=e._OnPointerOutTrigger)return!0;if(i.trigger==e._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasPickTriggers",{get:function(){for(var t=0;t<this.actions.length;t++){var i=this.actions[t];if(i.trigger>=e._OnPickTrigger&&i.trigger<=e._OnCenterPickTrigger)return!0}return!1},enumerable:!0,configurable:!0}),e.prototype.registerAction=function(i){return i.trigger===e.OnEveryFrameTrigger&&this.getScene().actionManager!==this?(t.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager"),null):(this.actions.push(i),i._actionManager=this,i._prepare(),i)},e.prototype.processTrigger=function(t,i){for(var r=0;r<this.actions.length;r++){var n=this.actions[r];if(n.trigger===t){if(t===e.OnKeyUpTrigger||t===e.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)}}},e.prototype._getEffectiveTarget=function(t,e){for(var i=e.split("."),r=0;r<i.length-1;r++)t=t[i[r]];return t},e.prototype._getProperty=function(t){var e=t.split(".");return e[e.length-1]},e._NothingTrigger=0,e._OnPickTrigger=1,e._OnLeftPickTrigger=2,e._OnRightPickTrigger=3,e._OnCenterPickTrigger=4,e._OnPointerOverTrigger=5,e._OnPointerOutTrigger=6,e._OnEveryFrameTrigger=7,e._OnIntersectionEnterTrigger=8,e._OnIntersectionExitTrigger=9,e._OnKeyDownTrigger=10,e._OnKeyUpTrigger=11,e._OnPickUpTrigger=12,e}();t.ActionManager=i}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(t,i,r,n,o,s,a){void 0===o&&(o=1e3),e.call(this,t,s),this.propertyPath=r,this.value=n,this.duration=o,this.stopOtherAnimations=a,this._target=i}return __extends(i,e),i.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},i.prototype.execute=function(){var e,i=this._actionManager.getScene(),r=[{frame:0,value:this._target[this._property]},{frame:100,value:this.value}];if("number"==typeof this.value)e=t.Animation.ANIMATIONTYPE_FLOAT;else if(this.value instanceof t.Color3)e=t.Animation.ANIMATIONTYPE_COLOR3;else if(this.value instanceof t.Vector3)e=t.Animation.ANIMATIONTYPE_VECTOR3;else if(this.value instanceof t.Matrix)e=t.Animation.ANIMATIONTYPE_MATRIX;else{if(!(this.value instanceof t.Quaternion))return void t.Tools.Warn("InterpolateValueAction: Unsupported type ("+typeof this.value+")");e=t.Animation.ANIMATIONTYPE_QUATERNION}var n=new t.Animation("InterpolateValueAction",this._property,100*(1e3/this.duration),e,t.Animation.ANIMATIONLOOPMODE_CONSTANT);n.setKeys(r),this.stopOtherAnimations&&i.stopAnimation(this._target),i.beginDirectAnimation(this._target,[n],0,100)},i}(t.Action);t.InterpolateValueAction=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r,n){t.call(this,e,n),this.propertyPath=r,this._target=i}return __extends(e,t),e.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},e.prototype.execute=function(){this._target[this._property]=!this._target[this._property]},e}(t.Action);t.SwitchBooleanAction=e;var i=function(t){function e(e,i,r,n){t.call(this,e,n),this.value=r,this._target=i}return __extends(e,t),e.prototype.execute=function(){this._target.state=this.value},e}(t.Action);t.SetStateAction=i;var r=function(t){function e(e,i,r,n,o){t.call(this,e,o),this.propertyPath=r,this.value=n,this._target=i}return __extends(e,t),e.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath)},e.prototype.execute=function(){this._target[this._property]=this.value},e}(t.Action);t.SetValueAction=r;var n=function(e){function i(t,i,r,n,o){e.call(this,t,o),this.propertyPath=r,this.value=n,this._target=i}return __extends(i,e),i.prototype._prepare=function(){this._target=this._getEffectiveTarget(this._target,this.propertyPath),this._property=this._getProperty(this.propertyPath),"number"!=typeof this._target[this._property]&&t.Tools.Warn("Warning: IncrementValueAction can only be used with number values")},i.prototype.execute=function(){this._target[this._property]+=this.value},i}(t.Action);t.IncrementValueAction=n;var o=function(t){function e(e,i,r,n,o,s){t.call(this,e,s),this.from=r,this.to=n,this.loop=o,this._target=i}return __extends(e,t),e.prototype._prepare=function(){},e.prototype.execute=function(){var t=this._actionManager.getScene();t.beginAnimation(this._target,this.from,this.to,this.loop)},e}(t.Action);t.PlayAnimationAction=o;var s=function(t){function e(e,i,r){t.call(this,e,r),this._target=i}return __extends(e,t),e.prototype._prepare=function(){},e.prototype.execute=function(){var t=this._actionManager.getScene();t.stopAnimation(this._target)},e}(t.Action);t.StopAnimationAction=s;var a=function(e){function i(i,r){void 0===i&&(i=t.ActionManager.NothingTrigger),e.call(this,i,r)}return __extends(i,e),i.prototype.execute=function(){},i}(t.Action);t.DoNothingAction=a;var h=function(t){function e(e,i,r){t.call(this,e,r),this.children=i}return __extends(e,t),e.prototype._prepare=function(){for(var t=0;t<this.children.length;t++)this.children[t]._actionManager=this._actionManager,this.children[t]._prepare()},e.prototype.execute=function(t){for(var e=0;e<this.children.length;e++)this.children[e].execute(t)},e}(t.Action);t.CombineAction=h;var c=function(t){function e(e,i,r){t.call(this,e,r),this.func=i}return __extends(e,t),e.prototype.execute=function(t){this.func(t)},e}(t.Action);t.ExecuteCodeAction=c;var l=function(e){function i(t,i,r,n){e.call(this,t,n),this._target=i,this._parent=r}return __extends(i,e),i.prototype._prepare=function(){},i.prototype.execute=function(){if(this._target.parent!==this._parent){var e=this._parent.getWorldMatrix().clone();e.invert(),this._target.position=t.Vector3.TransformCoordinates(this._target.position,e),this._target.parent=this._parent}},i}(t.Action);t.SetParentAction=l;var u=function(t){function e(e,i,r){t.call(this,e,r),this._sound=i}return __extends(e,t),e.prototype._prepare=function(){},e.prototype.execute=function(){void 0!==this._sound&&this._sound.play()},e}(t.Action);t.PlaySoundAction=u;var f=function(t){function e(e,i,r){t.call(this,e,r),this._sound=i}return __extends(e,t),e.prototype._prepare=function(){},e.prototype.execute=function(){void 0!==this._sound&&this._sound.stop()},e}(t.Action);t.StopSoundAction=f}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(){function e(e,i,r,n,o){this.delayLoadState=t.Engine.DELAYLOADSTATE_NONE,this._totalVertices=0,this._indices=[],this._isDisposed=!1,this.id=e,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 e.prototype.getScene=function(){return this._scene},e.prototype.getEngine=function(){return this._engine},e.prototype.isReady=function(){return this.delayLoadState===t.Engine.DELAYLOADSTATE_LOADED||this.delayLoadState===t.Engine.DELAYLOADSTATE_NONE},e.prototype.setAllVerticesData=function(t,e){t.applyToGeometry(this,e),this.notifyUpdate()},e.prototype.setVerticesData=function(e,i,r,n){if(this._vertexBuffers=this._vertexBuffers||{},this._vertexBuffers[e]&&this._vertexBuffers[e].dispose(),this._vertexBuffers[e]=new t.VertexBuffer(this._engine,i,e,r,0===this._meshes.length,n),e===t.VertexBuffer.PositionKind){n=this._vertexBuffers[e].getStrideSize(),this._totalVertices=i.length/n;for(var o=t.Tools.ExtractMinAndMax(i,0,this._totalVertices),s=this._meshes,a=s.length,h=0;a>h;h++){var c=s[h];c._resetPointsArrayCache(),c._boundingInfo=new t.BoundingInfo(o.minimum,o.maximum),c._createGlobalSubMesh(),c.computeWorldMatrix(!0)}}this.notifyUpdate(e)},e.prototype.updateVerticesDataDirectly=function(t,e,i){var r=this.getVertexBuffer(t);r&&(r.updateDirectly(e,i),this.notifyUpdate(t))},e.prototype.updateVerticesData=function(e,i,r){var n=this.getVertexBuffer(e);if(n){if(n.update(i),e===t.VertexBuffer.PositionKind){var o,s=n.getStrideSize();this._totalVertices=i.length/s,r&&(o=t.Tools.ExtractMinAndMax(i,0,this._totalVertices));for(var a=this._meshes,h=a.length,c=0;h>c;c++){var l=a[c];if(l._resetPointsArrayCache(),r){l._boundingInfo=new t.BoundingInfo(o.minimum,o.maximum);for(var u=0;u<l.subMeshes.length;u++){var f=l.subMeshes[u];f.refreshBoundingInfo()}}}}this.notifyUpdate(e)}},e.prototype.getTotalVertices=function(){return this.isReady()?this._totalVertices:0},e.prototype.getVerticesData=function(t,e){var i=this.getVertexBuffer(t);if(!i)return null;var r=i.getData();if(e&&1!==this._meshes.length){for(var n=r.length,o=[],s=0;n>s;s++)o.push(r[s]);return o}return r},e.prototype.getVertexBuffer=function(t){return this.isReady()?this._vertexBuffers[t]:null},e.prototype.getVertexBuffers=function(){return this.isReady()?this._vertexBuffers:null},e.prototype.isVerticesDataPresent=function(t){return this._vertexBuffers?void 0!==this._vertexBuffers[t]:this._delayInfo?-1!==this._delayInfo.indexOf(t):!1},e.prototype.getVerticesDataKinds=function(){var t=[];if(!this._vertexBuffers&&this._delayInfo)for(var e in this._delayInfo)t.push(e);else for(e in this._vertexBuffers)t.push(e);return t},e.prototype.setIndices=function(t,e){this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indices=t,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),void 0!==e&&(this._totalVertices=e);for(var i=this._meshes,r=i.length,n=0;r>n;n++)i[n]._createGlobalSubMesh();this.notifyUpdate()},e.prototype.getTotalIndices=function(){return this.isReady()?this._indices.length:0},e.prototype.getIndices=function(t){if(!this.isReady())return null;var e=this._indices;if(t&&1!==this._meshes.length){for(var i=e.length,r=[],n=0;i>n;n++)r.push(e[n]);return r}return e},e.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},e.prototype.releaseForMesh=function(t,e){var i=this._meshes,r=i.indexOf(t);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),t._geometry=null,0===i.length&&e&&this.dispose()}},e.prototype.applyToMesh=function(t){if(t._geometry!==this){var e=t._geometry;e&&e.releaseForMesh(t);var i=this._meshes;t._geometry=this,this._scene.pushGeometry(this),i.push(t),this.isReady()?this._applyToMesh(t):t._boundingInfo=this._boundingInfo}},e.prototype._applyToMesh=function(e){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===t.VertexBuffer.PositionKind){e._resetPointsArrayCache();var n=t.Tools.ExtractMinAndMax(this._vertexBuffers[r].getData(),0,this._totalVertices);e._boundingInfo=new t.BoundingInfo(n.minimum,n.maximum),e._createGlobalSubMesh(),e._updateBoundingInfo()}1===i&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=i)},e.prototype.notifyUpdate=function(t){this.onGeometryUpdated&&this.onGeometryUpdated(this,t)},e.prototype.load=function(e,i){var r=this;if(this.delayLoadState!==t.Engine.DELAYLOADSTATE_LOADING){if(this.isReady())return void(i&&i());this.delayLoadState=t.Engine.DELAYLOADSTATE_LOADING,e._addPendingData(this),t.Tools.LoadFile(this.delayLoadingFile,function(n){r._delayLoadingFunction(JSON.parse(n),r),r.delayLoadState=t.Engine.DELAYLOADSTATE_LOADED,r._delayInfo=[],e._removePendingData(r);for(var o=r._meshes,s=o.length,a=0;s>a;a++)r._applyToMesh(o[a]);i&&i()},function(){},e.database)}},e.prototype.isDisposed=function(){return this._isDisposed},e.prototype.dispose=function(){var e,i=this._meshes,r=i.length;for(e=0;r>e;e++)this.releaseForMesh(i[e]);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=t.Engine.DELAYLOADSTATE_NONE,this.delayLoadingFile=null,this._delayLoadingFunction=null,this._delayInfo=[],this._boundingInfo=null,this._scene.removeGeometry(this),this._isDisposed=!0},e.prototype.copy=function(i){var r=new t.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 c=new e(i,this._scene,r,s,null);c.delayLoadState=this.delayLoadState,c.delayLoadingFile=this.delayLoadingFile,c._delayLoadingFunction=this._delayLoadingFunction;for(h in this._delayInfo)c._delayInfo=c._delayInfo||[],c._delayInfo.push(h);var l=t.Tools.ExtractMinAndMax(this.getVerticesData(t.VertexBuffer.PositionKind),0,this.getTotalVertices());return c._boundingInfo=new t.BoundingInfo(l.minimum,l.maximum),c},e.ExtractFromMesh=function(t,e){var i=t._geometry;return i?i.copy(e):null},e.RandomId=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0,i="x"===t?e:3&e|8;return i.toString(16)})},e}();t.Geometry=e;var e;!function(e){var i;!function(i){var r=function(t){function e(e,i,r,n,o){this._beingRegenerated=!0,this._canBeRegenerated=n,t.call(this,e,i,r,!1,o),this._beingRegenerated=!1}return __extends(e,t),e.prototype.canBeRegenerated=function(){return this._canBeRegenerated},e.prototype.regenerate=function(){this._canBeRegenerated&&(this._beingRegenerated=!0,this.setAllVerticesData(this._regenerateVertexData(),!1),this._beingRegenerated=!1)},e.prototype.asNewGeometry=function(e){return t.prototype.copy.call(this,e)},e.prototype.setAllVerticesData=function(e,i){this._beingRegenerated&&t.prototype.setAllVerticesData.call(this,e,!1)},e.prototype.setVerticesData=function(e,i,r){this._beingRegenerated&&t.prototype.setVerticesData.call(this,e,i,!1)},e.prototype._regenerateVertexData=function(){throw new Error("Abstract method")},e.prototype.copy=function(t){throw new Error("Must be overriden in sub-classes.")},e}(e);i._Primitive=r;var n=function(e){function i(i,r,n,o,s,a,h,c,l){void 0===l&&(l=t.Mesh.DEFAULTSIDE),this.pathArray=n,this.closeArray=o,this.closePath=s,this.offset=a,this.side=l,e.call(this,i,r,this._regenerateVertexData(),h,c)}return __extends(i,e),i.prototype._regenerateVertexData=function(){return t.VertexData.CreateRibbon(this.pathArray,this.closeArray,this.closePath,this.offset,this.side)},i.prototype.copy=function(t){return new i(t,this.getScene(),this.pathArray,this.closeArray,this.closePath,this.offset,this.canBeRegenerated(),null,this.side)},i}(r);i.Ribbon=n;var o=function(e){function i(i,r,n,o,s,a){void 0===a&&(a=t.Mesh.DEFAULTSIDE),this.size=n,this.side=a,e.call(this,i,r,this._regenerateVertexData(),o,s)}return __extends(i,e),i.prototype._regenerateVertexData=function(){return t.VertexData.CreateBox(this.size,this.side)},i.prototype.copy=function(t){return new i(t,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},i}(r);i.Box=o;var s=function(e){function i(i,r,n,o,s,a,h){void 0===h&&(h=t.Mesh.DEFAULTSIDE),this.segments=n,this.diameter=o,this.side=h,e.call(this,i,r,this._regenerateVertexData(),s,a)}return __extends(i,e),i.prototype._regenerateVertexData=function(){return t.VertexData.CreateSphere(this.segments,this.diameter,this.side)},i.prototype.copy=function(t){return new i(t,this.getScene(),this.segments,this.diameter,this.canBeRegenerated(),null,this.side)},i}(r);i.Sphere=s;var a=function(e){function i(i,r,n,o,s,a,h,c,l,u){void 0===h&&(h=1),void 0===u&&(u=t.Mesh.DEFAULTSIDE),this.height=n,this.diameterTop=o,this.diameterBottom=s,this.tessellation=a,this.subdivisions=h,this.side=u,e.call(this,i,r,this._regenerateVertexData(),c,l)}return __extends(i,e),i.prototype._regenerateVertexData=function(){return t.VertexData.CreateCylinder(this.height,this.diameterTop,this.diameterBottom,this.tessellation,this.subdivisions,this.side)},i.prototype.copy=function(t){return new i(t,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(e){function i(i,r,n,o,s,a,h,c){void 0===c&&(c=t.Mesh.DEFAULTSIDE),this.diameter=n,this.thickness=o,this.tessellation=s,this.side=c,e.call(this,i,r,this._regenerateVertexData(),a,h)}return __extends(i,e),i.prototype._regenerateVertexData=function(){return t.VertexData.CreateTorus(this.diameter,this.thickness,this.tessellation,this.side)},i.prototype.copy=function(t){return new i(t,this.getScene(),this.diameter,this.thickness,this.tessellation,this.canBeRegenerated(),null,this.side)},i}(r);i.Torus=h;var c=function(e){function i(t,i,r,n,o,s,a){this.width=r,this.height=n,this.subdivisions=o,e.call(this,t,i,this._regenerateVertexData(),s,a)}return __extends(i,e),i.prototype._regenerateVertexData=function(){return t.VertexData.CreateGround(this.width,this.height,this.subdivisions)},i.prototype.copy=function(t){return new i(t,this.getScene(),this.width,this.height,this.subdivisions,this.canBeRegenerated(),null)},i}(r);i.Ground=c;var l=function(e){function i(t,i,r,n,o,s,a,h,c,l){this.xmin=r,this.zmin=n,this.xmax=o,this.zmax=s,this.subdivisions=a,this.precision=h,e.call(this,t,i,this._regenerateVertexData(),c,l)}return __extends(i,e),i.prototype._regenerateVertexData=function(){return t.VertexData.CreateTiledGround(this.xmin,this.zmin,this.xmax,this.zmax,this.subdivisions,this.precision)},i.prototype.copy=function(t){return new i(t,this.getScene(),this.xmin,this.zmin,this.xmax,this.zmax,this.subdivisions,this.precision,this.canBeRegenerated(),null)},i}(r);i.TiledGround=l;var u=function(e){function i(i,r,n,o,s,a){void 0===a&&(a=t.Mesh.DEFAULTSIDE),this.size=n,this.side=a,e.call(this,i,r,this._regenerateVertexData(),o,s)}return __extends(i,e),
- i.prototype._regenerateVertexData=function(){return t.VertexData.CreatePlane(this.size,this.side)},i.prototype.copy=function(t){return new i(t,this.getScene(),this.size,this.canBeRegenerated(),null,this.side)},i}(r);i.Plane=u;var f=function(e){function i(i,r,n,o,s,a,h,c,l,u,f){void 0===f&&(f=t.Mesh.DEFAULTSIDE),this.radius=n,this.tube=o,this.radialSegments=s,this.tubularSegments=a,this.p=h,this.q=c,this.side=f,e.call(this,i,r,this._regenerateVertexData(),l,u)}return __extends(i,e),i.prototype._regenerateVertexData=function(){return t.VertexData.CreateTorusKnot(this.radius,this.tube,this.radialSegments,this.tubularSegments,this.p,this.q,this.side)},i.prototype.copy=function(t){return new i(t,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=e.Primitives||(e.Primitives={}))}(e=t.Geometry||(t.Geometry={}))}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r){e.call(this,i,r),this.generateOctree=!1,this._worldInverse=new t.Matrix}return __extends(i,e),Object.defineProperty(i.prototype,"subdivisions",{get:function(){return this._subdivisions},enumerable:!0,configurable:!0}),i.prototype.optimize=function(t){this.subdivide(this._subdivisions),this.createOrUpdateSubmeshesOctree(32)},i.prototype.getHeightAtCoordinates=function(e,i){var r=new t.Ray(new t.Vector3(e,this.getBoundingInfo().boundingBox.maximumWorld.y+1,i),new t.Vector3(0,-1,0));this.getWorldMatrix().invertToRef(this._worldInverse),r=t.Ray.Transform(r,this._worldInverse);var n=this.intersects(r);return n.hit?n.pickedPoint.y:0},i}(t.Mesh);t.GroundMesh=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(){function e(t){var e=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=t,this.gamepadSupportAvailable?(this.gamepadEventSupported?(window.addEventListener("gamepadconnected",function(t){e._onGamepadConnected(t)},!1),window.addEventListener("gamepaddisconnected",function(t){e._onGamepadDisconnected(t)},!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(t){var e=this._addNewGamepad(t.gamepad);this._callbackGamepadConnected&&this._callbackGamepadConnected(e),this._startMonitoringGamepads()},e.prototype._addNewGamepad=function(i){this.oneGamepadConnected||(this.oneGamepadConnected=!0,e.gamepadDOMInfo&&(document.body.removeChild(e.gamepadDOMInfo),e.gamepadDOMInfo=null));var r;return r=-1!==i.id.search("Xbox 360")||-1!==i.id.search("xinput")?new t.Xbox360Pad(i.id,i.index,i):new t.GenericPad(i.id,i.index,i),this.babylonGamepads.push(r),r},e.prototype._onGamepadDisconnected=function(t){for(var e in this.babylonGamepads)if(this.babylonGamepads[e].index==t.gamepad.index){this.babylonGamepads.splice(e,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 t=this;this._updateGamepadObjects();for(var e in this.babylonGamepads)this.babylonGamepads[e].update();this.isMonitoring&&(window.requestAnimationFrame?window.requestAnimationFrame(function(){t._checkGamepadsStatus()}):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(function(){t._checkGamepadsStatus()}):window.webkitRequestAnimationFrame&&window.webkitRequestAnimationFrame(function(){t._checkGamepadsStatus()}))},e.prototype._updateGamepadObjects=function(){for(var t=navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads():[],e=0;e<t.length;e++)if(t[e])if(t[e].index in this.babylonGamepads)this.babylonGamepads[e].browserGamepad=t[e];else{var i=this._addNewGamepad(t[e]);this._callbackGamepadConnected&&this._callbackGamepadConnected(i)}},e}();t.Gamepads=e;var i=function(){function t(t,e){this.x=t,this.y=e}return t}();t.StickValues=i;var r=function(){function t(t,e,i){this.id=t,this.index=e,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 t.prototype.onleftstickchanged=function(t){this._onleftstickchanged=t},t.prototype.onrightstickchanged=function(t){this._onrightstickchanged=t},Object.defineProperty(t.prototype,"leftStick",{get:function(){return this._leftStick},set:function(t){!this._onleftstickchanged||this._leftStick.x===t.x&&this._leftStick.y===t.y||this._onleftstickchanged(t),this._leftStick=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rightStick",{get:function(){return this._rightStick},set:function(t){!this._onrightstickchanged||this._rightStick.x===t.x&&this._rightStick.y===t.y||this._onrightstickchanged(t),this._rightStick=t},enumerable:!0,configurable:!0}),t.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]})},t}();t.Gamepad=r;var n=function(t){function e(e,i,r){t.call(this,e,i,r),this.id=e,this.index=i,this.gamepad=r,this._buttons=new Array(r.buttons.length)}return __extends(e,t),e.prototype.onbuttondown=function(t){this._onbuttondown=t},e.prototype.onbuttonup=function(t){this._onbuttonup=t},e.prototype._setButtonValue=function(t,e,i){return t!==e&&(this._onbuttondown&&1===t&&this._onbuttondown(i),this._onbuttonup&&0===t&&this._onbuttonup(i)),t},e.prototype.update=function(){t.prototype.update.call(this);for(var e=0;e<this._buttons.length;e++)this._buttons[e]=this._setButtonValue(this.gamepad.buttons[e].value,this._buttons[e],e)},e}(r);t.GenericPad=n,function(t){t[t.A=0]="A",t[t.B=1]="B",t[t.X=2]="X",t[t.Y=3]="Y",t[t.Start=4]="Start",t[t.Back=5]="Back",t[t.LB=6]="LB",t[t.RB=7]="RB",t[t.LeftStick=8]="LeftStick",t[t.RightStick=9]="RightStick"}(t.Xbox360Button||(t.Xbox360Button={}));t.Xbox360Button;!function(t){t[t.Up=0]="Up",t[t.Down=1]="Down",t[t.Left=2]="Left",t[t.Right=3]="Right"}(t.Xbox360Dpad||(t.Xbox360Dpad={}));var o=(t.Xbox360Dpad,function(t){function e(){t.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(e,t),e.prototype.onlefttriggerchanged=function(t){this._onlefttriggerchanged=t},e.prototype.onrighttriggerchanged=function(t){this._onrighttriggerchanged=t},Object.defineProperty(e.prototype,"leftTrigger",{get:function(){return this._leftTrigger},set:function(t){this._onlefttriggerchanged&&this._leftTrigger!==t&&this._onlefttriggerchanged(t),this._leftTrigger=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rightTrigger",{get:function(){return this._rightTrigger},set:function(t){this._onrighttriggerchanged&&this._rightTrigger!==t&&this._onrighttriggerchanged(t),this._rightTrigger=t},enumerable:!0,configurable:!0}),e.prototype.onbuttondown=function(t){this._onbuttondown=t},e.prototype.onbuttonup=function(t){this._onbuttonup=t},e.prototype.ondpaddown=function(t){this._ondpaddown=t},e.prototype.ondpadup=function(t){this._ondpadup=t},e.prototype._setButtonValue=function(t,e,i){return t!==e&&(this._onbuttondown&&1===t&&this._onbuttondown(i),this._onbuttonup&&0===t&&this._onbuttonup(i)),t},e.prototype._setDPadValue=function(t,e,i){return t!==e&&(this._ondpaddown&&1===t&&this._ondpaddown(i),this._ondpadup&&0===t&&this._ondpadup(i)),t},Object.defineProperty(e.prototype,"buttonA",{get:function(){return this._buttonA},set:function(t){this._buttonA=this._setButtonValue(t,this._buttonA,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonB",{get:function(){return this._buttonB},set:function(t){this._buttonB=this._setButtonValue(t,this._buttonB,1)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonX",{get:function(){return this._buttonX},set:function(t){this._buttonX=this._setButtonValue(t,this._buttonX,2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonY",{get:function(){return this._buttonY},set:function(t){this._buttonY=this._setButtonValue(t,this._buttonY,3)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonStart",{get:function(){return this._buttonStart},set:function(t){this._buttonStart=this._setButtonValue(t,this._buttonStart,4)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonBack",{get:function(){return this._buttonBack},set:function(t){this._buttonBack=this._setButtonValue(t,this._buttonBack,5)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonLB",{get:function(){return this._buttonLB},set:function(t){this._buttonLB=this._setButtonValue(t,this._buttonLB,6)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonRB",{get:function(){return this._buttonRB},set:function(t){this._buttonRB=this._setButtonValue(t,this._buttonRB,7)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonLeftStick",{get:function(){return this._buttonLeftStick},set:function(t){this._buttonLeftStick=this._setButtonValue(t,this._buttonLeftStick,8)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"buttonRightStick",{get:function(){return this._buttonRightStick},set:function(t){this._buttonRightStick=this._setButtonValue(t,this._buttonRightStick,9)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dPadUp",{get:function(){return this._dPadUp},set:function(t){this._dPadUp=this._setDPadValue(t,this._dPadUp,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dPadDown",{get:function(){return this._dPadDown},set:function(t){this._dPadDown=this._setDPadValue(t,this._dPadDown,1)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dPadLeft",{get:function(){return this._dPadLeft},set:function(t){this._dPadLeft=this._setDPadValue(t,this._dPadLeft,2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dPadRight",{get:function(){return this._dPadRight},set:function(t){this._dPadRight=this._setDPadValue(t,this._dPadRight,3)},enumerable:!0,configurable:!0}),e.prototype.update=function(){t.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},e}(r));t.Xbox360Pad=o}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n){var o=this;e.call(this,i,r,n),this.angularSensibility=200,this.moveSensibility=75,this._gamepads=new t.Gamepads(function(t){o._onNewGameConnected(t)})}return __extends(i,e),i.prototype._onNewGameConnected=function(t){0===t.index&&(this._gamepad=t)},i.prototype._checkInputs=function(){if(this._gamepad){var e=this._gamepad.leftStick,i=e.x/this.moveSensibility,r=e.y/this.moveSensibility;e.x=Math.abs(i)>.005?0+i:0,e.y=Math.abs(r)>.005?0+r:0;var n=this._gamepad.rightStick,o=n.x/this.angularSensibility,s=n.y/this.angularSensibility;n.x=Math.abs(o)>.001?0+o:0,n.y=Math.abs(s)>.001?0+s:0;var a=t.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0),h=50*this._computeLocalCameraSpeed(),c=t.Vector3.TransformCoordinates(new t.Vector3(e.x*h,0,-e.y*h),a);this.cameraDirection=this.cameraDirection.add(c),this.cameraRotation=this.cameraRotation.add(new t.Vector2(n.y,n.x))}},i.prototype.dispose=function(){this._gamepads.dispose(),e.prototype.dispose.call(this)},i}(t.FreeCamera);t.GamepadCamera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n){void 0===n&&(n=!1),e.call(this,i,r),this.color=new t.Color3(1,1,1),this.alpha=1,this._indices=new Array,this._colorShader=new t.ShaderMaterial("colorShader",r,"color",{attributes:["position"],uniforms:["worldViewProjection","color"],needAlphaBlending:!0})}return __extends(i,e),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(e,i,r){var n=this.getScene().getEngine(),o=this._geometry.getIndexBuffer();n.bindBuffers(this._geometry.getVertexBuffer(t.VertexBuffer.PositionKind).getBuffer(),o,[3],12,this._colorShader.getEffect()),this._colorShader.setColor4("color",this.color.toColor4(this.alpha))},i.prototype._draw=function(t,e,i){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){var r=this.getScene().getEngine();r.draw(!1,t.indexStart,t.indexCount)}},i.prototype.intersects=function(t,e){return null},i.prototype.dispose=function(t){this._colorShader.dispose(),e.prototype.dispose.call(this,t)},i}(t.Mesh);t.LinesMesh=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t){this._scene=t}return e.prototype.render=function(e,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[e._id]&&void 0!==i.visibleInstances[e._id];if(this.isReady(e,a)){var h=e.getRenderingMesh(),c=e.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&&this._effect.setMatrices("mBones",h.skeleton.getTransformMatrices()),h._bind(e,this._effect,t.Material.TriangleFillMode),c&&c.needAlphaTesting()){var l=c.getAlphaTestTexture();this._effect.setTexture("diffuseSampler",l),this._effect.setMatrix("diffuseMatrix",l.getTextureMatrix())}h._processRendering(e,this._effect,t.Material.TriangleFillMode,i,a,function(t,e){n._effect.setMatrix("world",e)})}},e.prototype.isReady=function(e,i){var r=[],n=[t.VertexBuffer.PositionKind,t.VertexBuffer.NormalKind],o=e.getMesh(),s=e.getMaterial();s&&s.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(t.VertexBuffer.UVKind)&&(n.push(t.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(t.VertexBuffer.UV2Kind)&&(n.push(t.VertexBuffer.UV2Kind),r.push("#define UV2"))),o.useBones&&(n.push(t.VertexBuffer.MatricesIndicesKind),n.push(t.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()},e}();t.OutlineRenderer=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(t,e,i,r){this.name=t,this.meshesNames=e,this.rootUrl=i,this.sceneFilename=r,this.isCompleted=!1}return e.prototype.run=function(e,i,r){var n=this;t.SceneLoader.ImportMesh(this.meshesNames,this.rootUrl,this.sceneFilename,e,function(t,e,r){n.loadedMeshes=t,n.loadedParticleSystems=e,n.loadedSkeletons=r,n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),i()},null,function(){n.onError&&n.onError(n),r()})},e}();t.MeshAssetTask=e;var i=function(){function e(t,e){this.name=t,this.url=e,this.isCompleted=!1}return e.prototype.run=function(e,i,r){var n=this;t.Tools.LoadFile(this.url,function(t){n.text=t,n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),i()},null,e.database,!1,function(){n.onError&&n.onError(n),r()})},e}();t.TextFileAssetTask=i;var r=function(){function e(t,e){this.name=t,this.url=e,this.isCompleted=!1}return e.prototype.run=function(e,i,r){var n=this;t.Tools.LoadFile(this.url,function(t){n.data=t,n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),i()},null,e.database,!0,function(){n.onError&&n.onError(n),r()})},e}();t.BinaryFileAssetTask=r;var n=function(){function t(t,e){this.name=t,this.url=e,this.isCompleted=!1}return t.prototype.run=function(t,e,i){var r=this,n=new Image;n.onload=function(){r.image=n,r.isCompleted=!0,r.onSuccess&&r.onSuccess(r),e()},n.onerror=function(){r.onError&&r.onError(r),i()},n.src=this.url},t}();t.ImageAssetTask=n;var o=function(){function e(e,i,r,n,o){void 0===o&&(o=t.Texture.TRILINEAR_SAMPLINGMODE),this.name=e,this.url=i,this.noMipmap=r,this.invertY=n,this.samplingMode=o,this.isCompleted=!1}return e.prototype.run=function(e,i,r){var n=this,o=function(){n.isCompleted=!0,n.onSuccess&&n.onSuccess(n),i()};this.texture=new t.Texture(this.url,e,this.noMipmap,this.invertY,this.samplingMode,o,r)},e}();t.TextureAssetTask=o;var s=function(){function s(t){this._tasks=new Array,this._waitingTasksCount=0,this.useDefaultLoadingScreen=!0,this._scene=t}return s.prototype.addMeshTask=function(t,i,r,n){var o=new e(t,i,r,n);return this._tasks.push(o),o},s.prototype.addTextFileTask=function(t,e){var r=new i(t,e);return this._tasks.push(r),r},s.prototype.addBinaryFileTask=function(t,e){var i=new r(t,e);return this._tasks.push(i),i},s.prototype.addImageTask=function(t,e){var i=new n(t,e);return this._tasks.push(i),i},s.prototype.addTextureTask=function(e,i,r,n,s){void 0===s&&(s=t.Texture.TRILINEAR_SAMPLINGMODE);var a=new o(e,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(t){var e=this;t.run(this._scene,function(){e.onTaskSuccess&&e.onTaskSuccess(t),e._decreaseWaitingTasksCount()},function(){e.onTaskError&&e.onTaskError(t),e._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 t=0;t<this._tasks.length;t++){var e=this._tasks[t];this._runTask(e)}return this},s}();t.AssetsManager=s}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i,r){t.call(this,e,i,r),this._alpha=0,this._beta=0,this._gamma=0}return __extends(e,t),e.prototype._onOrientationEvent=function(t){this._alpha=0|+t.alpha,this._beta=0|+t.beta,this._gamma=0|+t.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},e}(t.OculusCamera);t.VRDeviceOrientationCamera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n){e.call(this,i,r,n),this._hmdDevice=null,this._sensorDevice=null,this._cacheState=null,this._cacheQuaternion=new t.Quaternion,this._cacheRotation=t.Vector3.Zero(),this._vrEnabled=!1,this._getWebVRDevices=this._getWebVRDevices.bind(this)}return __extends(i,e),i.prototype._getWebVRDevices=function(t){var e=t.length,i=0;for(this._sensorDevice=null,this._hmdDevice=null;e>i&&null===this._hmdDevice;)t[i]instanceof HMDVRDevice&&(this._hmdDevice=t[i]),i++;for(i=0;e>i&&null===this._sensorDevice;)t[i]instanceof PositionSensorVRDevice&&(!this._hmdDevice||t[i].hardwareUnitId===this._hmdDevice.hardwareUnitId)&&(this._sensorDevice=t[i]),i++;this._vrEnabled=this._sensorDevice&&this._hmdDevice?!0:!1},i.prototype._update=function(){this._vrEnabled&&(this._cacheState=this._sensorDevice.getState(),this._cacheQuaternion.copyFromFloats(this._cacheState.orientation.x,this._cacheState.orientation.y,this._cacheState.orientation.z,this._cacheState.orientation.w),this._cacheQuaternion.toEulerAnglesToRef(this._cacheRotation),this.rotation.x=-this._cacheRotation.z,this.rotation.y=-this._cacheRotation.y,this.rotation.z=this._cacheRotation.x),e.prototype._update.call(this)},i.prototype.attachControl=function(t,i){e.prototype.attachControl.call(this,t,i),navigator.getVRDevices?navigator.getVRDevices().then(this._getWebVRDevices):navigator.mozGetVRDevices&&navigator.mozGetVRDevices(this._getWebVRDevices)},i.prototype.detachControl=function(t){e.prototype.detachControl.call(this,t),this._vrEnabled=!1},i}(t.OculusCamera);t.WebVRCamera=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(){function t(t){void 0===t&&(t=0),this.priority=t,this.apply=function(t){return!0}}return t}();t.SceneOptimization=e;var i=function(t){function e(e,i){var r=this;void 0===e&&(e=0),void 0===i&&(i=1024),t.call(this,e),this.priority=e,this.maximumSize=i,this.apply=function(t){for(var e=!0,i=0;i<t.textures.length;i++){var n=t.textures[i];if(n.canRescale){var o=n.getSize(),s=Math.max(o.width,o.height);s>r.maximumSize&&(n.scale(.5),e=!1)}}return e}}return __extends(e,t),e}(e);t.TextureOptimization=i;var r=function(t){function e(e,i){var r=this;void 0===e&&(e=0),void 0===i&&(i=2),t.call(this,e),this.priority=e,this.maximumScale=i,this._currentScale=1,this.apply=function(t){return r._currentScale++,t.getEngine().setHardwareScalingLevel(r._currentScale),r._currentScale>=r.maximumScale}}return __extends(e,t),e}(e);t.HardwareScalingOptimization=r;var n=function(t){function e(){t.apply(this,arguments),this.apply=function(t){return t.shadowsEnabled=!1,!0}}return __extends(e,t),e}(e);t.ShadowsOptimization=n;var o=function(t){function e(){t.apply(this,arguments),this.apply=function(t){return t.postProcessesEnabled=!1,!0}}return __extends(e,t),e}(e);t.PostProcessesOptimization=o;var s=function(t){function e(){t.apply(this,arguments),this.apply=function(t){return t.lensFlaresEnabled=!1,!0}}return __extends(e,t),e}(e);t.LensFlaresOptimization=s;var a=function(t){function e(){t.apply(this,arguments),this.apply=function(t){return t.particlesEnabled=!1,!0}}return __extends(e,t),e}(e);t.ParticlesOptimization=a;var h=function(t){function e(){t.apply(this,arguments),this.apply=function(t){return t.renderTargetsEnabled=!1,!0}}return __extends(e,t),e}(e);t.RenderTargetsOptimization=h;var c=function(e){function i(){var i=this;e.apply(this,arguments),this._canBeMerged=function(e){if(!(e instanceof t.Mesh))return!1;var i=e;return i.isVisible&&i.isEnabled()?i.instances.length>0?!1:i.skeleton||i.hasLODLevels?!1:!0:!1},this.apply=function(e){for(var r=e.meshes.slice(0),n=r.length,o=0;n>o;o++){var s=new Array,a=r[o];if(i._canBeMerged(a)){s.push(a);for(var h=o+1;n>h;h++){var c=r[h];i._canBeMerged(c)&&c.material===a.material&&c.checkCollisions===a.checkCollisions&&(s.push(c),n--,r.splice(h,1),h--)}s.length<2||t.Mesh.MergeMeshes(s)}}return!0}}return __extends(i,e),
- i}(e);t.MergeMeshesOptimization=c;var l=function(){function t(t,e){void 0===t&&(t=60),void 0===e&&(e=2e3),this.targetFrameRate=t,this.trackerDuration=e,this.optimizations=new Array}return t.LowDegradationAllowed=function(e){var r=new t(e),h=0;return r.optimizations.push(new c(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},t.ModerateDegradationAllowed=function(e){var l=new t(e),u=0;return l.optimizations.push(new c(u)),l.optimizations.push(new n(u)),l.optimizations.push(new s(u)),u++,l.optimizations.push(new o(u)),l.optimizations.push(new a(u)),u++,l.optimizations.push(new i(u,512)),u++,l.optimizations.push(new h(u)),u++,l.optimizations.push(new r(u,2)),l},t.HighDegradationAllowed=function(e){var l=new t(e),u=0;return l.optimizations.push(new c(u)),l.optimizations.push(new n(u)),l.optimizations.push(new s(u)),u++,l.optimizations.push(new o(u)),l.optimizations.push(new a(u)),u++,l.optimizations.push(new i(u,256)),u++,l.optimizations.push(new h(u)),u++,l.optimizations.push(new r(u,4)),l},t}();t.SceneOptimizerOptions=l;var u=function(){function t(){}return t._CheckCurrentState=function(e,i,r,n,o){if(e.getEngine().getFps()>=i.targetFrameRate)return void(n&&n());for(var s=!0,a=!0,h=0;h<i.optimizations.length;h++){var c=i.optimizations[h];c.priority===r&&(a=!1,s=s&&c.apply(e))}return a?void(o&&o()):(s&&r++,void e.executeWhenReady(function(){setTimeout(function(){t._CheckCurrentState(e,i,r,n,o)},i.trackerDuration)}))},t.OptimizeAsync=function(e,i,r,n){i||(i=l.ModerateDegradationAllowed()),e.executeWhenReady(function(){setTimeout(function(){t._CheckCurrentState(e,i,0,r,n)},i.trackerDuration)})},t}();t.SceneOptimizer=u}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e;!function(t){var e=function(){function t(t,e){this.distance=t,this.mesh=e}return t}();t.MeshLODLevel=e}(e=t.Internals||(t.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(){this._audioContext=null,this._audioContextInitialized=!1,this.canUseWebAudio=!1,this.WarnedWebAudioUnsupported=!1,("undefined"!=typeof AudioContext||"undefined"!=typeof webkitAudioContext)&&(window.AudioContext=window.AudioContext||window.webkitAudioContext,this.canUseWebAudio=!0)}return Object.defineProperty(e.prototype,"audioContext",{get:function(){return this._audioContextInitialized||this._initializeAudioContext(),this._audioContext},enumerable:!0,configurable:!0}),e.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(e){this.canUseWebAudio=!1,t.Tools.Error("Web Audio: "+e.message)}},e.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},e.prototype.getGlobalVolume=function(){return this.canUseWebAudio&&this._audioContextInitialized?this.masterGain.gain.value:-1},e.prototype.setGlobalVolume=function(t){this.canUseWebAudio&&this._audioContextInitialized&&(this.masterGain.gain.value=t)},e.prototype.connectToAnalyser=function(t){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this.canUseWebAudio&&this._audioContextInitialized&&(this._connectedAnalyser=t,this.masterGain.disconnect(),this._connectedAnalyser.connectAudioNodes(this.masterGain,this._audioContext.destination))},e}();t.AudioEngine=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,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=t.Vector3.Zero(),this._localDirection=new t.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.name=e,this._scene=r,this._readyToPlayCallback=n,this._customAttenuationFunction=function(t,e,i,r,n){return i>e?t*(1-e/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),t.Engine.audioEngine.canUseWebAudio?(this._soundGain=t.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?t.Tools.LoadFile(i,function(t){s._soundLoaded(t)},null,null,!0):i instanceof ArrayBuffer?this._soundLoaded(i):t.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound."))):(this._scene.mainSoundTrack.AddSound(this),t.Engine.audioEngine.WarnedWebAudioUnsupported||(t.Tools.Error("Web Audio is not supported by your browser."),t.Engine.audioEngine.WarnedWebAudioUnsupported=!0),this._readyToPlayCallback&&window.setTimeout(function(){s._readyToPlayCallback()},1e3))}return e.prototype.dispose=function(){t.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))},e.prototype._soundLoaded=function(e){var i=this;this._isLoaded=!0,t.Engine.audioEngine.audioContext.decodeAudioData(e,function(t){i._audioBuffer=t,i._isReadyToPlay=!0,i.autoplay&&i.play(),i._readyToPlayCallback&&i._readyToPlayCallback()},function(e){t.Tools.Error("Error while decoding audio data: "+e.err)})},e.prototype.setAudioBuffer=function(e){t.Engine.audioEngine.canUseWebAudio&&(this._audioBuffer=e,this._isReadyToPlay=!0)},e.prototype.updateOptions=function(t){t&&(this.loop=t.loop||this.loop,this.maxDistance=t.maxDistance||this.maxDistance,this.useCustomAttenuation=t.useCustomAttenuation||this.useCustomAttenuation,this.rolloffFactor=t.rolloffFactor||this.rolloffFactor,this.refDistance=t.refDistance||this.refDistance,this.distanceModel=t.distanceModel||this.distanceModel,this._playbackRate=t.playbackRate||this._playbackRate)},e.prototype._createSpatialParameters=function(){t.Engine.audioEngine.canUseWebAudio&&(this._scene.headphone&&(this._panningModel="HRTF"),this._soundPanner=t.Engine.audioEngine.audioContext.createPanner(),this.useCustomAttenuation?(this._soundPanner.distanceModel="linear",this._soundPanner.maxDistance=Number.MAX_VALUE,this._soundPanner.refDistance=1,this._soundPanner.rolloffFactor=1,this._soundPanner.panningModel=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),this._soundPanner.connect(this._ouputAudioNode),this._inputAudioNode=this._soundPanner)},e.prototype.switchPanningModelToHRTF=function(){this._panningModel="HRTF",this._switchPanningModel()},e.prototype.switchPanningModelToEqualPower=function(){this._panningModel="equalpower",this._switchPanningModel()},e.prototype._switchPanningModel=function(){t.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&(this._soundPanner.panningModel=this._panningModel)},e.prototype.connectToSoundTrackAudioNode=function(e){t.Engine.audioEngine.canUseWebAudio&&(this._ouputAudioNode.disconnect(),this._ouputAudioNode.connect(e))},e.prototype.setDirectionalCone=function(e,i,r){return e>i?void t.Tools.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle."):(this._coneInnerAngle=e,this._coneOuterAngle=i,this._coneOuterGain=r,this._isDirectional=!0,void(this.isPlaying&&this.loop&&(this.stop(),this.play())))},e.prototype.setPosition=function(e){this._position=e,t.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z)},e.prototype.setLocalDirectionToMesh=function(e){this._localDirection=e,t.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.isPlaying&&this._updateDirection()},e.prototype._updateDirection=function(){var e=this._connectedMesh.getWorldMatrix(),i=t.Vector3.TransformNormal(this._localDirection,e);i.normalize(),this._soundPanner.setOrientation(i.x,i.y,i.z)},e.prototype.updateDistanceFromListener=function(){if(t.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.useCustomAttenuation){var e=this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);this._soundGain.gain.value=this._customAttenuationFunction(this._volume,e,this.maxDistance,this.refDistance,this.rolloffFactor)}},e.prototype.setAttenuationFunction=function(t){this._customAttenuationFunction=t},e.prototype.play=function(e){var i=this;if(this._isReadyToPlay&&this._scene.audioEnabled)try{var r=e?t.Engine.audioEngine.audioContext.currentTime+e:t.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=t.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){t.Tools.Error("Error while trying to play audio: "+this.name+", "+n.message)}},e.prototype._onended=function(){this.isPlaying=!1,this.onended&&this.onended()},e.prototype.stop=function(e){if(this.isPlaying){var i=e?t.Engine.audioEngine.audioContext.currentTime+e:t.Engine.audioEngine.audioContext.currentTime;this._soundSource.stop(i),this.isPlaying=!1}},e.prototype.pause=function(){this.isPlaying&&(this.stop(0),this._startOffset+=t.Engine.audioEngine.audioContext.currentTime-this._startTime,this.isPaused=!0)},e.prototype.setVolume=function(e,i){t.Engine.audioEngine.canUseWebAudio&&!this.spatialSound&&(i?(this._soundGain.gain.linearRampToValueAtTime(this._volume,t.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.linearRampToValueAtTime(e,i)):this._soundGain.gain.value=e),this._volume=e},e.prototype.setPlaybackRate=function(t){this._playbackRate=t,this.isPlaying&&(this._soundSource.playbackRate.value=this._playbackRate)},e.prototype.getVolume=function(){return this._volume},e.prototype.attachToMesh=function(t){var e=this;this._connectedMesh=t,this.spatialSound||(this._createSpatialParameters(),this.spatialSound=!0,this.isPlaying&&this.loop&&(this.stop(),this.play())),this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh),this._registerFunc=function(t){return e._onRegisterAfterWorldMatrixUpdate(t)},t.registerAfterWorldMatrixUpdate(this._registerFunc)},e.prototype._onRegisterAfterWorldMatrixUpdate=function(e){this.setPosition(e.getBoundingInfo().boundingSphere.centerWorld),t.Engine.audioEngine.canUseWebAudio&&this._isDirectional&&this.isPlaying&&this._updateDirection()},e}();t.Sound=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i){this.id=-1,this._isMainTrack=!1,this._scene=e,this._audioEngine=t.Engine.audioEngine,this.soundCollection=new Array,this._audioEngine.canUseWebAudio&&(this._trackGain=this._audioEngine.audioContext.createGain(),this._trackGain.connect(this._audioEngine.masterGain),i&&(i.volume&&(this._trackGain.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 e.prototype.dispose=function(){if(this._audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._trackGain.disconnect(),this._trackGain=null}},e.prototype.AddSound=function(e){t.Engine.audioEngine.canUseWebAudio&&e.connectToSoundTrackAudioNode(this._trackGain),e.soundTrackId&&(-1===e.soundTrackId?this._scene.mainSoundTrack.RemoveSound(e):this._scene.soundTracks[e.soundTrackId].RemoveSound(e)),this.soundCollection.push(e),e.soundTrackId=this.id},e.prototype.RemoveSound=function(t){var e=this.soundCollection.indexOf(t);-1!==e&&this.soundCollection.splice(e,1)},e.prototype.setVolume=function(t){this._audioEngine.canUseWebAudio&&(this._trackGain.gain.value=t)},e.prototype.switchPanningModelToHRTF=function(){if(t.Engine.audioEngine.canUseWebAudio)for(var e=0;e<this.soundCollection.length;e++)this.soundCollection[e].switchPanningModelToHRTF()},e.prototype.switchPanningModelToEqualPower=function(){if(t.Engine.audioEngine.canUseWebAudio)for(var e=0;e<this.soundCollection.length;e++)this.soundCollection[e].switchPanningModelToEqualPower()},e.prototype.connectToAnalyser=function(t){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this._connectedAnalyser=t,this._audioEngine.canUseWebAudio&&(this._trackGain.disconnect(),this._connectedAnalyser.connectAudioNodes(this._trackGain,this._audioEngine.masterGain))},e}();t.SoundTrack=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e){var i=this;this._transformationMatrix=t.Matrix.Identity(),this._enabled=!1,this._labelsEnabled=!1,this._displayStatistics=!0,this._displayTree=!1,this._displayLogs=!1,this._identityMatrix=t.Matrix.Identity(),this.axisRatio=.02,this.accentColor="orange",this._scene=e,this._syncPositions=function(){var t=i._scene.getEngine(),e=t.getRenderingCanvasClientRect();i._showUI&&(i._statsDiv.style.left=e.width-410+"px",i._statsDiv.style.top=e.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=e.height-225+"px",i._logDiv.style.left="0px",i._logDiv.style.top=e.height-170+"px",i._logDiv.style.width="600px",i._logDiv.style.height="160px",i._treeDiv.style.left=e.width-310+"px",i._treeDiv.style.top="10px",i._treeDiv.style.width="300px",i._treeDiv.style.height="auto",i._treeSubsetDiv.style.maxHeight=e.height-340+"px"),i._globalDiv.style.left=e.left+"px",i._globalDiv.style.top=e.top+"px",i._drawingCanvas.style.left="0px",i._drawingCanvas.style.top="0px",i._drawingCanvas.style.width=t.getRenderWidth()+"px",i._drawingCanvas.style.height=t.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=t.getRenderWidth()*i._ratio,i._drawingCanvas.height=t.getRenderHeight()*i._ratio},this._onCanvasClick=function(t){i._clickPosition={x:t.clientX*i._ratio,y:t.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 e=i._scene.getEngine(),r=i._camera.viewport,n=r.toGlobal(e),o=i._camera.getActiveMeshes(),s=0;s<o.length;s++){var a=o.data[s],h=a.getBoundingInfo().boundingSphere.center,c=t.Vector3.Project(h,a.getWorldMatrix(),i._transformationMatrix,n);(a.renderOverlay||i.shouldDisplayAxis&&i.shouldDisplayAxis(a))&&i._renderAxis(c,a,n),(!i.shouldDisplayLabel||i.shouldDisplayLabel(a))&&i._renderLabel(a.name,c,12,function(){a.renderOverlay=!a.renderOverlay},function(){return a.renderOverlay?"red":"black"})}var l=i._scene.cameras;for(s=0;s<l.length;s++){var u=l[s];u!==i._camera&&(c=t.Vector3.Project(t.Vector3.Zero(),u.getWorldMatrix(),i._transformationMatrix,n),(!i.shouldDisplayLabel||i.shouldDisplayLabel(u))&&i._renderLabel(u.name,c,12,function(){i._camera.detachControl(e.getRenderingCanvas()),i._camera=u,i._camera.attachControl(e.getRenderingCanvas())},function(){return"purple"}))}var f=i._scene.lights;for(s=0;s<f.length;s++){var d=f[s];d.position&&(c=t.Vector3.Project(d.getAbsolutePosition(),i._identityMatrix,i._transformationMatrix,n),(!i.shouldDisplayLabel||i.shouldDisplayLabel(d))&&i._renderLabel(d.name,c,-20,function(){d.setEnabled(!d.isEnabled())},function(){return d.isEnabled()?"orange":"gray"}))}}i._clickPosition=void 0}}return e.prototype._refreshMeshesTreeContent=function(){for(;this._treeSubsetDiv.hasChildNodes();)this._treeSubsetDiv.removeChild(this._treeSubsetDiv.lastChild);var t=this._scene.meshes.slice(0,this._scene.meshes.length);t.sort(function(t,e){return t.name===e.name?0:t.name>e.name?1:-1});for(var e=0;e<t.length;e++){var i=t[e];i.isEnabled()&&this._generateAdvancedCheckBox(this._treeSubsetDiv,i.name,i.getTotalVertices()+" verts",i.isVisible,function(t,e){e.isVisible=t.checked},i)}},e.prototype._renderSingleAxis=function(t,e,i,r,n){this._drawingContext.beginPath(),this._drawingContext.moveTo(t.x,t.y),this._drawingContext.lineTo(e.x,e.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)},e.prototype._renderAxis=function(e,i,r){var n=i.getBoundingInfo().boundingSphere.center,o=i.getWorldMatrix(),s=t.Vector3.UnprojectFromTransform(e.add(new t.Vector3(this._drawingCanvas.width*this.axisRatio,0,0)),r.width,r.height,o,this._transformationMatrix),a=s.subtract(n).length(),h=t.Vector3.Project(n.add(new t.Vector3(a,0,0)),o,this._transformationMatrix,r),c=t.Vector3.Project(n.add(new t.Vector3(1.5*a,0,0)),o,this._transformationMatrix,r);this._renderSingleAxis(e,h,c,"x","#FF0000");var l=t.Vector3.Project(n.add(new t.Vector3(0,a,0)),o,this._transformationMatrix,r),u=t.Vector3.Project(n.add(new t.Vector3(0,1.5*a,0)),o,this._transformationMatrix,r);this._renderSingleAxis(e,l,u,"y","#00FF00");var f=t.Vector3.Project(n.add(new t.Vector3(0,0,a)),o,this._transformationMatrix,r),d=t.Vector3.Project(n.add(new t.Vector3(0,0,1.5*a)),o,this._transformationMatrix,r);this._renderSingleAxis(e,f,d,"z","#0000FF")},e.prototype._renderLabel=function(t,e,i,r,n){if(e.z>0&&e.z<1){this._drawingContext.font="normal 12px Segoe UI";var o=this._drawingContext.measureText(t),s=e.x-o.width/2,a=e.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(t,s,a-i),this._drawingContext.beginPath(),this._drawingContext.arc(e.x,a,5,0,2*Math.PI,!1),this._drawingContext.fill()}},e.prototype._isClickInsideRect=function(t,e,i,r){return this._clickPosition?this._clickPosition.x<t||this._clickPosition.x>t+i?!1:this._clickPosition.y<e||this._clickPosition.y>e+r?!1:!0:!1},e.prototype.isVisible=function(){return this._enabled},e.prototype.hide=function(){if(this._enabled){this._enabled=!1;var e=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,t.StandardMaterial.DiffuseTextureEnabled=!0,t.StandardMaterial.AmbientTextureEnabled=!0,t.StandardMaterial.SpecularTextureEnabled=!0,t.StandardMaterial.EmissiveTextureEnabled=!0,t.StandardMaterial.BumpTextureEnabled=!0,t.StandardMaterial.OpacityTextureEnabled=!0,t.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,e.getRenderingCanvas().removeEventListener("click",this._onCanvasClick)}},e.prototype.show=function(t,e){if(void 0===t&&(t=!0),void 0===e&&(e=null),!this._enabled){this._enabled=!0,this._camera=e?e:this._scene.activeCamera,this._showUI=t;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)}},e.prototype._clearLabels=function(){this._drawingContext.clearRect(0,0,this._drawingCanvas.width,this._drawingCanvas.height);for(var t=0;t<this._scene.meshes.length;t++){var e=this._scene.meshes[t];e.renderOverlay=!1}},e.prototype._generateheader=function(t,e){var i=document.createElement("div");i.innerHTML=e+" ",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",t.appendChild(i)},e.prototype._generateTexBox=function(t,e,i){var r=document.createElement("label");r.innerHTML=e,r.style.color=i,t.appendChild(r),t.appendChild(document.createElement("br"))},e.prototype._generateAdvancedCheckBox=function(t,e,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(t){n(t.target,o)}),s.appendChild(a);var h=document.createElement("span"),c=document.createElement("span"),l=document.createElement("span");l.style.cssFloat="right",c.innerHTML=e,l.innerHTML=i,l.style.fontSize="12px",l.style.maxWidth="200px",h.appendChild(c),h.appendChild(l),s.appendChild(h),t.appendChild(s),t.appendChild(document.createElement("br"))},e.prototype._generateCheckBox=function(t,e,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(t){r(t.target,n)}),o.appendChild(s),o.appendChild(document.createTextNode(e)),t.appendChild(o),t.appendChild(document.createElement("br"))},e.prototype._generateButton=function(t,e,i,r){void 0===r&&(r=null);var n=document.createElement("button");n.innerHTML=e,n.style.height="24px",n.style.color="#444444",n.style.border="1px solid white",n.className="debugLayerButton",n.addEventListener("click",function(t){i(t.target,r)}),t.appendChild(n),t.appendChild(document.createElement("br"))},e.prototype._generateRadio=function(t,e,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(t){n(t.target,o)}),s.appendChild(a),s.appendChild(document.createTextNode(e)),t.appendChild(s),t.appendChild(document.createElement("br"))},e.prototype._generateDOMelements=function(){var e=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=t.Tools.LogCache,this._logDiv.appendChild(this._logSubsetDiv),t.Tools.OnNewCacheEntry=function(t){e._logSubsetDiv.innerHTML=t+e._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(t){e._displayStatistics=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Logs",this._displayLogs,function(t){e._displayLogs=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Meshes tree",this._displayTree,function(t){e._displayTree=t.checked,e._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(t){e._scene.forceShowBoundingBoxes=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Clickable labels",this._labelsEnabled,function(t){e._labelsEnabled=t.checked,e._labelsEnabled||e._clearLabels()}),this._generateCheckBox(this._optionsSubsetDiv,"Generate user marks (F12)",t.Tools.PerformanceLogLevel===t.Tools.PerformanceUserMarkLogLevel,function(e){t.Tools.PerformanceLogLevel=e.checked?t.Tools.PerformanceUserMarkLogLevel:t.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(t){t.checked&&(e._scene.forceWireframe=!1,e._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Wireframe","renderMode",this._scene.forceWireframe,function(t){t.checked&&(e._scene.forceWireframe=!0,e._scene.forcePointsCloud=!1)}),this._generateRadio(this._optionsSubsetDiv,"Point","renderMode",this._scene.forcePointsCloud,function(t){t.checked&&(e._scene.forceWireframe=!1,e._scene.forcePointsCloud=!0)}),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Texture channels:</b>",this.accentColor),this._generateCheckBox(this._optionsSubsetDiv,"Diffuse",t.StandardMaterial.DiffuseTextureEnabled,function(e){t.StandardMaterial.DiffuseTextureEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Ambient",t.StandardMaterial.AmbientTextureEnabled,function(e){t.StandardMaterial.AmbientTextureEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Specular",t.StandardMaterial.SpecularTextureEnabled,function(e){t.StandardMaterial.SpecularTextureEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Emissive",t.StandardMaterial.EmissiveTextureEnabled,function(e){t.StandardMaterial.EmissiveTextureEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Bump",t.StandardMaterial.BumpTextureEnabled,function(e){t.StandardMaterial.BumpTextureEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Opacity",t.StandardMaterial.OpacityTextureEnabled,function(e){t.StandardMaterial.OpacityTextureEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Reflection",t.StandardMaterial.ReflectionTextureEnabled,function(e){t.StandardMaterial.ReflectionTextureEnabled=e.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fresnel",t.StandardMaterial.FresnelEnabled,function(e){t.StandardMaterial.FresnelEnabled=e.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(t){e._scene.animationsEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Collisions",this._scene.collisionsEnabled,function(t){e._scene.collisionsEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Fog",this._scene.fogEnabled,function(t){
- e._scene.fogEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lens flares",this._scene.lensFlaresEnabled,function(t){e._scene.lensFlaresEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Lights",this._scene.lightsEnabled,function(t){e._scene.lightsEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Particles",this._scene.particlesEnabled,function(t){e._scene.particlesEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Post-processes",this._scene.postProcessesEnabled,function(t){e._scene.postProcessesEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Procedural textures",this._scene.proceduralTexturesEnabled,function(t){e._scene.proceduralTexturesEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Render targets",this._scene.renderTargetsEnabled,function(t){e._scene.renderTargetsEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Shadows",this._scene.shadowsEnabled,function(t){e._scene.shadowsEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Skeletons",this._scene.skeletonsEnabled,function(t){e._scene.skeletonsEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Sprites",this._scene.spritesEnabled,function(t){e._scene.spritesEnabled=t.checked}),this._generateCheckBox(this._optionsSubsetDiv,"Textures",this._scene.texturesEnabled,function(t){e._scene.texturesEnabled=t.checked}),t.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(t){t.checked&&(e._scene.headphone=!0)}),this._generateRadio(this._optionsSubsetDiv,"Normal Speakers","panningModel",!this._scene.headphone,function(t){t.checked&&(e._scene.headphone=!1)}),this._generateCheckBox(this._optionsSubsetDiv,"Disable audio",!this._scene.audioEnabled,function(t){e._scene.audioEnabled=!t.checked})),this._optionsSubsetDiv.appendChild(document.createElement("br")),this._generateTexBox(this._optionsSubsetDiv,"<b>Tools:</b>",this.accentColor),this._generateButton(this._optionsSubsetDiv,"Dump rendertargets",function(t){e._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)}},e.prototype._displayStats=function(){var e=this._scene,i=e.getEngine(),r=i.getGlInfo();this._statsSubsetDiv.innerHTML="Babylon.js v"+t.Engine.Version+" - <b>"+t.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: "+e.meshes.length+"<br>Total vertices: "+e.getTotalVertices()+"<br>Total materials: "+e.materials.length+"<br>Total textures: "+e.textures.length+"<br>Active meshes: "+e.getActiveMeshes().length+"<br>Active indices: "+e.getActiveIndices()+"<br>Active bones: "+e.getActiveBones()+"<br>Active particles: "+e.getActiveParticles()+"<br><b>Draw calls: "+i.drawCalls+"</b><br><br><b>Duration</b><br>Meshes selection:</i> "+t.Tools.Format(e.getEvaluateActiveMeshesDuration())+" ms<br>Render Targets: "+t.Tools.Format(e.getRenderTargetsDuration())+" ms<br>Particles: "+t.Tools.Format(e.getParticlesDuration())+" ms<br>Sprites: "+t.Tools.Format(e.getSpritesDuration())+" ms<br><br>Render: <b>"+t.Tools.Format(e.getRenderDuration())+" ms</b><br>Frame: "+t.Tools.Format(e.getLastFrameDuration())+" ms<br>Potential FPS: "+t.Tools.Format(1e3/e.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)},e}();t.DebugLayer=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s,a,h,c){void 0===a&&(a=!0),void 0===h&&(h=!1),void 0===c&&(c=t.Texture.TRILINEAR_SAMPLINGMODE),e.call(this,null,s,!a,h),this._texture=s.getEngine().createRawTexture(i,r,n,o,a,h,c),this.wrapU=t.Texture.CLAMP_ADDRESSMODE,this.wrapV=t.Texture.CLAMP_ADDRESSMODE}return __extends(i,e),i.CreateLuminanceTexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_LUMINANCE,o,s,a,h)},i.CreateLuminanceAlphaTexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_LUMINANCE_ALPHA,o,s,a,h)},i.CreateAlphaTexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_ALPHA,o,s,a,h)},i.CreateRGBTexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_RGB,o,s,a,h)},i.CreateRGBATexture=function(e,r,n,o,s,a,h){return void 0===s&&(s=!0),void 0===a&&(a=!1),void 0===h&&(h=t.Texture.TRILINEAR_SAMPLINGMODE),new i(e,r,n,t.Engine.TEXTUREFORMAT_RGBA,o,s,a,h)},i}(t.Texture);t.RawTexture=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(t){function e(e,i){t.call(this,e.x,e.y),this.index=i}return __extends(e,t),e}(t.Vector2),i=function(){function i(){this.elements=new Array}return i.prototype.add=function(i){var r=this,n=new Array;return i.forEach(function(i){if(0===n.length||!t.Tools.WithinEpsilon(i.x,n[0].x,1e-5)||!t.Tools.WithinEpsilon(i.y,n[0].y,1e-5)){var o=new e(i,r.elements.length);n.push(o),r.elements.push(o)}}),n},i.prototype.computeBounds=function(){var e=new t.Vector2(this.elements[0].x,this.elements[0].y),i=new t.Vector2(this.elements[0].x,this.elements[0].y);return this.elements.forEach(function(t){t.x<e.x?e.x=t.x:t.x>i.x&&(i.x=t.x),t.y<e.y?e.y=t.y:t.y>i.y&&(i.y=t.y)}),{min:e,max:i,width:i.x-e.x,height:i.y-e.y}},i}(),r=function(){function e(){}return e.Rectangle=function(e,i,r,n){return[new t.Vector2(e,i),new t.Vector2(r,i),new t.Vector2(r,n),new t.Vector2(e,n)]},e.Circle=function(e,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 t.Vector2(i+Math.cos(s)*e,r+Math.sin(s)*e)),s-=a;return o},e.Parse=function(t){var e,i=t.split(/[^-+eE\.\d]+/).map(parseFloat).filter(function(t){return!isNaN(t)}),r=[];for(e=0;e<(2147483646&i.length);e+=2)r.push(new poly2tri.Point(i[e],i[e+1]));return r},e.StartingAt=function(e,i){return t.Path2.StartingAt(e,i)},e}();t.Polygon=r;var n=function(){function e(e,r,n){if(this._points=new i,!("poly2tri"in window))throw"PolygonMeshBuilder cannot be used because poly2tri is not referenced";this._name=e,this._scene=n;var o;o=r instanceof t.Path2?r.getPoints():r,this._swctx=new poly2tri.SweepContext(this._points.add(o))}return e.prototype.addHole=function(t){return this._swctx.addHole(this._points.add(t)),this},e.prototype.build=function(e){void 0===e&&(e=!1);var i=new t.Mesh(this._name,this._scene),r=[],n=[],o=[],s=this._points.computeBounds();this._points.elements.forEach(function(t){r.push(0,1,0),n.push(t.x,0,t.y),o.push((t.x-s.min.x)/s.width,(t.y-s.min.y)/s.height)});var a=[];return this._swctx.triangulate(),this._swctx.getTriangles().forEach(function(t){t.getPoints().forEach(function(t){a.push(t.index)})}),i.setVerticesData(t.VertexBuffer.PositionKind,n,e),i.setVerticesData(t.VertexBuffer.NormalKind,r,e),i.setVerticesData(t.VertexBuffer.UVKind,o,e),i.setIndices(a),i},e}();t.PolygonMeshBuilder=n}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function t(t,e,i){this.quality=t,this.distance=e,this.optimizeMesh=i}return t}();t.SimplificationSettings=e;var i=function(){function e(){this.running=!1,this._simplificationArray=[]}return e.prototype.addTask=function(t){this._simplificationArray.push(t)},e.prototype.executeNext=function(){var t=this._simplificationArray.pop();t?(this.running=!0,this.runSimplification(t)):this.running=!1},e.prototype.runSimplification=function(e){var i=this;if(e.parallelProcessing)e.settings.forEach(function(t){var r=i.getSimplifier(e);r.simplify(t,function(r){e.mesh.addLODLevel(t.distance,r),r.isVisible=!0,t.quality===e.settings[e.settings.length-1].quality&&e.successCallback&&e.successCallback(),i.executeNext()})});else{var r=this.getSimplifier(e),n=function(t,i){r.simplify(t,function(r){e.mesh.addLODLevel(t.distance,r),r.isVisible=!0,i()})};t.AsyncLoop.Run(e.settings.length,function(t){n(e.settings[t.index],function(){t.executeNext()})},function(){e.successCallback&&e.successCallback(),i.executeNext()})}},e.prototype.getSimplifier=function(t){switch(t.simplificationType){case 0:default:return new a(t.mesh)}},e}();t.SimplificationQueue=i,function(t){t[t.QUADRATIC=0]="QUADRATIC"}(t.SimplificationType||(t.SimplificationType={}));var r=(t.SimplificationType,function(){function t(t){this.vertices=t,this.error=new Array(4),this.deleted=!1,this.isDirty=!1,this.deletePending=!1,this.borderFactor=0}return t}());t.DecimationTriangle=r;var n=function(){function t(t,e){this.position=t,this.id=e,this.isBorder=!0,this.q=new o,this.triangleCount=0,this.triangleStart=0,this.originalOffsets=[]}return t.prototype.updatePosition=function(t){this.position.copyFrom(t)},t}();t.DecimationVertex=n;var o=function(){function t(t){this.data=new Array(10);for(var e=0;10>e;++e)this.data[e]=t&&t[e]?t[e]:0}return t.prototype.det=function(t,e,i,r,n,o,s,a,h){var c=this.data[t]*this.data[n]*this.data[h]+this.data[i]*this.data[r]*this.data[a]+this.data[e]*this.data[o]*this.data[s]-this.data[i]*this.data[n]*this.data[s]-this.data[t]*this.data[o]*this.data[a]-this.data[e]*this.data[r]*this.data[h];return c},t.prototype.addInPlace=function(t){for(var e=0;10>e;++e)this.data[e]+=t.data[e]},t.prototype.addArrayInPlace=function(t){for(var e=0;10>e;++e)this.data[e]+=t[e]},t.prototype.add=function(e){for(var i=new t,r=0;10>r;++r)i.data[r]=this.data[r]+e.data[r];return i},t.FromData=function(e,i,r,n){return new t(t.DataFromNumbers(e,i,r,n))},t.DataFromNumbers=function(t,e,i,r){return[t*t,t*e,t*i,t*r,e*e,e*i,e*r,i*i,i*r,r*r]},t}();t.QuadraticMatrix=o;var s=function(){function t(t,e){this.vertexId=t,this.triangleId=e}return t}();t.Reference=s;var a=function(){function e(e){this._mesh=e,this.initialized=!1,this.syncIterations=5e3,this.aggressiveness=7,this.decimationIterations=100,this.boundingBoxEpsilon=t.Engine.Epsilon}return e.prototype.simplify=function(e,i){var r=this;this.initDecimatedMesh(),t.AsyncLoop.Run(this._mesh.subMeshes.length,function(t){r.initWithMesh(t.index,function(){r.runDecimation(e,t.index,function(){t.executeNext()})},e.optimizeMesh)},function(){setTimeout(function(){i(r._reconstructedMesh)},0)})},e.prototype.isTriangleOnBoundingBox=function(t){var e=this,i=0;return t.vertices.forEach(function(t){var r=0,n=t.position,o=e._mesh.getBoundingInfo().boundingBox;(o.maximum.x-n.x<e.boundingBoxEpsilon||n.x-o.minimum.x>e.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(t,i),i>1},e.prototype.runDecimation=function(e,i,r){var n=this,o=~~(this.triangles.length*e.quality),s=0,a=this.triangles.length,h=function(e,i){setTimeout(function(){e%5===0&&n.updateMesh(0===e);for(var r=0;r<n.triangles.length;++r)n.triangles[r].isDirty=!1;var h=1e-9*Math.pow(e+3,n.aggressiveness),c=function(e){var i=~~((n.triangles.length/2+e)%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=[],c=[],l=r.vertices[o],u=r.vertices[(o+1)%3];if(l.isBorder!==u.isBorder)continue;var f=t.Vector3.Zero(),d=t.Vector3.Zero(),p=t.Vector2.Zero(),m=new t.Color4(0,0,0,1);n.calculateError(l,u,f,d,p,m);var _=[];if(n.isFlipped(l,u,f,a,r.borderFactor,_))continue;if(n.isFlipped(u,l,f,c,r.borderFactor,_))continue;if(a.indexOf(!0)<0||c.indexOf(!0)<0)continue;var g=[];if(_.forEach(function(t){-1===g.indexOf(t)&&(t.deletePending=!0,g.push(t))}),g.length%2!=0)continue;l.q=u.q.add(l.q),l.updatePosition(f);var v=n.references.length;s=n.updateTriangles(l,l,a,s),s=n.updateTriangles(l,u,c,s);var y=n.references.length-v;if(y<=l.triangleCount){if(y)for(var x=0;y>x;x++)n.references[l.triangleStart+x]=n.references[v+x]}else l.triangleStart=v;l.triangleCount=y;break}};t.AsyncLoop.SyncAsyncForLoop(n.triangles.length,n.syncIterations,c,i,function(){return o>=a-s})},0)};t.AsyncLoop.Run(this.decimationIterations,function(t){o>=a-s?t.breakLoop():h(t.index,function(){t.executeNext()})},function(){setTimeout(function(){n.reconstructMesh(i),r()},0)})},e.prototype.initWithMesh=function(e,i,o){var s=this;this.vertices=[],this.triangles=[];var a=this._mesh.getVerticesData(t.VertexBuffer.PositionKind),h=this._mesh.getIndices(),c=this._mesh.subMeshes[e],l=function(t){if(o)for(var e=0;e<s.vertices.length;++e)if(s.vertices[e].position.equals(t))return s.vertices[e];return null},u=[],f=function(e){var i=e+c.verticesStart,r=t.Vector3.FromArray(a,3*i),o=l(r)||new n(r,s.vertices.length);o.originalOffsets.push(i),o.id==s.vertices.length&&s.vertices.push(o),u.push(o.id)},d=c.verticesCount;t.AsyncLoop.SyncAsyncForLoop(d,this.syncIterations/4>>0,f,function(){var e=function(t){var e=c.indexStart/3+t,i=3*e,n=h[i+0],o=h[i+1],a=h[i+2],l=s.vertices[u[n-c.verticesStart]],f=s.vertices[u[o-c.verticesStart]],d=s.vertices[u[a-c.verticesStart]],p=new r([l,f,d]);p.originalOffset=i,s.triangles.push(p)};t.AsyncLoop.SyncAsyncForLoop(c.indexCount/3,s.syncIterations,e,function(){s.init(i)})})},e.prototype.init=function(e){var i=this,r=function(e){var r=i.triangles[e];r.normal=t.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(o.DataFromNumbers(r.normal.x,r.normal.y,r.normal.z,-t.Vector3.Dot(r.normal,r.vertices[0].position)))};t.AsyncLoop.SyncAsyncForLoop(this.triangles.length,this.syncIterations,r,function(){var r=function(t){for(var e=i.triangles[t],r=0;3>r;++r)e.error[r]=i.calculateError(e.vertices[r],e.vertices[(r+1)%3]);e.error[3]=Math.min(e.error[0],e.error[1],e.error[2])};t.AsyncLoop.SyncAsyncForLoop(i.triangles.length,i.syncIterations,r,function(){i.initialized=!0,e()})})},e.prototype.reconstructMesh=function(e){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(t.VertexBuffer.PositionKind)||[],a=this._reconstructedMesh.getVerticesData(t.VertexBuffer.NormalKind)||[],h=this._reconstructedMesh.getVerticesData(t.VertexBuffer.UVKind)||[],c=this._reconstructedMesh.getVerticesData(t.VertexBuffer.ColorKind)||[],l=this._mesh.getVerticesData(t.VertexBuffer.NormalKind),u=this._mesh.getVerticesData(t.VertexBuffer.UVKind),f=this._mesh.getVerticesData(t.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(t){s.push(p.position.x),s.push(p.position.y),s.push(p.position.z),a.push(l[3*t]),a.push(l[3*t+1]),a.push(l[3*t+2]),u&&u.length?(h.push(u[2*t]),h.push(u[2*t+1])):f&&f.length&&(c.push(f[4*t]),c.push(f[4*t+1]),c.push(f[4*t+2]),c.push(f[4*t+3])),++d})}var m=this._reconstructedMesh.getTotalIndices(),_=this._reconstructedMesh.getTotalVertices(),g=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(t){var e=y[n.originalOffset+t],i=n.vertices[t].originalOffsets.indexOf(e);0>i&&(i=0),v.push(n.vertices[t].id+i+_)})}this._reconstructedMesh.setIndices(v),this._reconstructedMesh.setVerticesData(t.VertexBuffer.PositionKind,s),this._reconstructedMesh.setVerticesData(t.VertexBuffer.NormalKind,a),h.length>0&&this._reconstructedMesh.setVerticesData(t.VertexBuffer.UVKind,h),c.length>0&&this._reconstructedMesh.setVerticesData(t.VertexBuffer.ColorKind,c);var x=this._mesh.subMeshes[e];if(e>0){this._reconstructedMesh.subMeshes=[],g.forEach(function(e){new t.SubMesh(e.materialIndex,e.verticesStart,e.verticesCount,e.indexStart,e.indexCount,e.getMesh())});{new t.SubMesh(x.materialIndex,_,d,m,3*r.length,this._reconstructedMesh)}}},e.prototype.initDecimatedMesh=function(){this._reconstructedMesh=new t.Mesh(this._mesh.name+"Decimated",this._mesh.getScene()),this._reconstructedMesh.material=this._mesh.material,this._reconstructedMesh.parent=this._mesh.parent,this._reconstructedMesh.isVisible=!1},e.prototype.isFlipped=function(e,i,r,n,o,s){for(var a=0;a<e.triangleCount;++a){var h=this.triangles[this.references[e.triangleStart+a].triangleId];if(!h.deleted){var c=this.references[e.triangleStart+a].vertexId,l=h.vertices[(c+1)%3],u=h.vertices[(c+2)%3];if(l!==i&&u!==i){var f=l.position.subtract(r);f=f.normalize();var d=u.position.subtract(r);if(d=d.normalize(),Math.abs(t.Vector3.Dot(f,d))>.999)return!0;var p=t.Vector3.Cross(f,d).normalize();if(n[a]=!1,t.Vector3.Dot(p,h.normal)<.2)return!0}else n[a]=!0,s.push(h)}}return!1},e.prototype.updateTriangles=function(t,e,i,r){for(var n=r,o=0;o<e.triangleCount;++o){var s=this.references[e.triangleStart+o],a=this.triangles[s.triangleId];a.deleted||(i[o]&&a.deletePending?(a.deleted=!0,n++):(a.vertices[s.vertexId]=t,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},e.prototype.identifyBorder=function(){for(var t=0;t<this.vertices.length;++t){var e,i=[],r=[],n=this.vertices[t];for(e=0;e<n.triangleCount;++e)for(var o=this.triangles[this.references[n.triangleStart+e].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(e=0;e<i.length;++e)this.vertices[r[e]].isBorder=1===i[e]?!0:!1}},e.prototype.updateMesh=function(t){void 0===t&&(t=!1);var e;if(!t){var i=[];for(e=0;e<this.triangles.length;++e)this.triangles[e].deleted||i.push(this.triangles[e]);this.triangles=i}for(e=0;e<this.vertices.length;++e)this.vertices[e].triangleCount=0,this.vertices[e].triangleStart=0;var r,n,o;for(e=0;e<this.triangles.length;++e)for(r=this.triangles[e],n=0;3>n;++n)o=r.vertices[n],o.triangleCount++;var a=0;for(e=0;e<this.vertices.length;++e)this.vertices[e].triangleStart=a,a+=this.vertices[e].triangleCount,this.vertices[e].triangleCount=0;var h=new Array(3*this.triangles.length);for(e=0;e<this.triangles.length;++e)for(r=this.triangles[e],n=0;3>n;++n)o=r.vertices[n],h[o.triangleStart+o.triangleCount]=new s(n,e),o.triangleCount++;this.references=h,t&&this.identifyBorder()},e.prototype.vertexError=function(t,e){var i=e.x,r=e.y,n=e.z;return t.data[0]*i*i+2*t.data[1]*i*r+2*t.data[2]*i*n+2*t.data[3]*i+t.data[4]*r*r+2*t.data[5]*r*n+2*t.data[6]*r+t.data[7]*n*n+2*t.data[8]*n+t.data[9]},e.prototype.calculateError=function(e,i,r,n,o,s){var a=e.q.add(i.q),h=e.isBorder&&i.isBorder,c=0,l=a.det(0,1,2,1,4,5,2,5,7);if(0===l||h){var u=e.position.add(i.position).divide(new t.Vector3(2,2,2)),f=this.vertexError(a,e.position),d=this.vertexError(a,i.position),p=this.vertexError(a,u);c=Math.min(f,d,p),c===f?r&&r.copyFrom(e.position):c===d?r&&r.copyFrom(i.position):r&&r.copyFrom(u)}else r||(r=t.Vector3.Zero()),r.x=-1/l*a.det(1,2,3,4,5,6,5,7,8),r.y=1/l*a.det(0,2,3,1,5,6,2,7,8),r.z=-1/l*a.det(0,1,3,1,4,6,2,5,8),c=this.vertexError(a,r);return c},e}();t.QuadraticErrorSimplification=a}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e){this.SMOOTHING=.75,this.FFT_SIZE=512,this.BARGRAPHAMPLITUDE=256,this.DEBUGCANVASPOS={x:20,y:20},this.DEBUGCANVASSIZE={width:320,height:200},this._scene=e,this._audioEngine=t.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 e.prototype.getFrequencyBinCount=function(){return this._audioEngine.canUseWebAudio?this._webAudioAnalyser.frequencyBinCount:0},e.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},e.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},e.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},e.prototype.drawDebugCanvas=function(){var t=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(){t.drawDebugCanvas()},this._scene.registerBeforeRender(this._registerFunc)),this._registerFunc)){var e=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=e[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)}}},e.prototype.stopDebugCanvas=function(){this._debugCanvas&&(this._scene.unregisterBeforeRender(this._registerFunc),this._registerFunc=null,document.body.removeChild(this._debugCanvas),this._debugCanvas=null,this._debugCanvasContext=null)},e.prototype.connectAudioNodes=function(t,e){this._audioEngine.canUseWebAudio&&(t.connect(this._webAudioAnalyser),this._webAudioAnalyser.connect(e))},e.prototype.dispose=function(){this._audioEngine.canUseWebAudio&&this._webAudioAnalyser.disconnect()},e}();t.Analyser=e}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var e=function(){function e(e,i){var r=this;void 0===i&&(i=t.Engine.TEXTURETYPE_FLOAT),this._viewMatrix=t.Matrix.Zero(),this._projectionMatrix=t.Matrix.Zero(),this._transformMatrix=t.Matrix.Zero(),this._worldViewProjection=t.Matrix.Zero(),this._scene=e;var n=e.getEngine();this._depthMap=new t.RenderTargetTexture("depthMap",{width:n.getRenderWidth(),height:n.getRenderHeight()},this._scene,!1,!0,i),this._depthMap.wrapU=t.Texture.CLAMP_ADDRESSMODE,this._depthMap.wrapV=t.Texture.CLAMP_ADDRESSMODE,this._depthMap.refreshRate=1,this._depthMap.renderParticles=!1,this._depthMap.renderList=null,this._depthMap.onClear=function(e){e.clear(new t.Color4(1,1,1,1),!0,!0)};var o=function(e){var i=e.getRenderingMesh(),n=r._scene,o=n.getEngine();o.setState(e.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(e._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[e._id];if(r.isReady(e,a)){o.enableEffect(r._effect),i._bind(e,r._effect,t.Material.TriangleFillMode);var h=e.getMaterial();if(r._effect.setMatrix("viewProjection",n.getTransformMatrix()),r._effect.setFloat("far",n.activeCamera.maxZ),h&&h.needAlphaTesting()){var c=h.getAlphaTestTexture();r._effect.setTexture("diffuseSampler",c),r._effect.setMatrix("diffuseMatrix",c.getTextureMatrix())}i.useBones&&r._effect.setMatrices("mBones",i.skeleton.getTransformMatrices()),i._processRendering(e,r._effect,t.Material.TriangleFillMode,s,a,function(t,e){return r._effect.setMatrix("world",e)})}}};this._depthMap.customRenderFunction=function(t,e){var i;for(i=0;i<t.length;i++)o(t.data[i]);for(i=0;i<e.length;i++)o(e.data[i])}}return e.prototype.isReady=function(e,i){var r=[],n=[t.VertexBuffer.PositionKind],o=e.getMesh(),s=(o.getScene(),e.getMaterial());s&&s.needAlphaTesting()&&(r.push("#define ALPHATEST"),o.isVerticesDataPresent(t.VertexBuffer.UVKind)&&(n.push(t.VertexBuffer.UVKind),r.push("#define UV1")),o.isVerticesDataPresent(t.VertexBuffer.UV2Kind)&&(n.push(t.VertexBuffer.UV2Kind),r.push("#define UV2"))),o.useBones&&(n.push(t.VertexBuffer.MatricesIndicesKind),n.push(t.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()},e.prototype.getDepthMap=function(){return this._depthMap},e.prototype.dispose=function(){this._depthMap.dispose()},e}();t.DepthRenderer=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o){var s=this;e.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 t.PassPostProcess("SSAOOriginalSceneColor",h,null,t.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),this._createSSAOPostProcess(a),this._blurHPostProcess=new t.BlurPostProcess("SSAOBlurH",new t.Vector2(2,0),2,a,null,t.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),this._blurVPostProcess=new t.BlurPostProcess("SSAOBlurV",new t.Vector2(0,2),2,a,null,t.Texture.BILINEAR_SAMPLINGMODE,r.getEngine(),!1),this._createSSAOCombinePostProcess(h),this.addEffect(new t.PostProcessRenderEffect(r.getEngine(),this.SSAOOriginalSceneColorEffect,function(){return s._originalColorPostProcess},!0)),this.addEffect(new t.PostProcessRenderEffect(r.getEngine(),this.SSAORenderEffect,function(){return s._ssaoPostProcess},!0)),this.addEffect(new t.PostProcessRenderEffect(r.getEngine(),this.SSAOBlurHRenderEffect,function(){return s._blurHPostProcess},!0)),this.addEffect(new t.PostProcessRenderEffect(r.getEngine(),this.SSAOBlurVRenderEffect,function(){return s._blurVPostProcess},!0)),this.addEffect(new t.PostProcessRenderEffect(r.getEngine(),this.SSAOCombineRenderEffect,function(){return s._ssaoCombinePostProcess},!0)),r.postProcessRenderPipelineManager.addPipeline(this),o&&r.postProcessRenderPipelineManager.attachCamerasToRenderPipeline(i,o)}return __extends(i,e),i.prototype.getBlurHPostProcess=function(){return this._blurHPostProcess},i.prototype.getBlurVPostProcess=function(){return this._blurVPostProcess},i.prototype.dispose=function(t){void 0===t&&(t=!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(),t&&this._scene.disableDepthRenderer()},i.prototype._createSSAOPostProcess=function(e){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 t.PostProcess("ssao","ssao",["sampleSphere","samplesFactor","randTextureTiles","totalStrength","radius","area","fallOff"],["randomSampler"],e,null,t.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoPostProcess.onApply=function(t){i._firstUpdate&&(t.setArray3("sampleSphere",r),t.setFloat("samplesFactor",n),t.setFloat("randTextureTiles",4/e),i._firstUpdate=!1),t.setFloat("totalStrength",i.totalStrength),t.setFloat("radius",i.radius),t.setFloat("area",i.area),t.setFloat("fallOff",i.fallOff),t.setTexture("textureSampler",i._depthTexture),t.setTexture("randomSampler",i._randomTexture)}},i.prototype._createSSAOCombinePostProcess=function(e){var i=this;this._ssaoCombinePostProcess=new t.PostProcess("ssaoCombine","ssaoCombine",[],["originalColor"],e,null,t.Texture.BILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._ssaoCombinePostProcess.onApply=function(t){t.setTextureFromPostProcess("originalColor",i._originalColorPostProcess)}},i.prototype._createRandomTexture=function(){var e=512;this._randomTexture=new t.DynamicTexture("SSAORandomTexture",e,this._scene,!1,t.Texture.BILINEAR_SAMPLINGMODE),this._randomTexture.wrapU=t.Texture.WRAP_ADDRESSMODE,this._randomTexture.wrapV=t.Texture.WRAP_ADDRESSMODE;for(var i=this._randomTexture.getContext(),r=function(t,e){return Math.random()*(e-t)+t},n=0;e>n;n++)for(var o=0;e>o;o++){var s=t.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}(t.PostProcessRenderPipeline);t.SSAORenderingPipeline=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(r,n,o,s,a,h,c,l){var u=this;void 0===a&&(a=100),void 0===h&&(h=t.Texture.BILINEAR_SAMPLINGMODE),e.call(this,r,"volumetricLightScattering",["decay","exposure","weight","meshPositionOnScreen","density"],["lightScatteringSampler"],n.postProcessRatio||n,o,h,c,l,"#define NUM_SAMPLES "+a),this._screenCoordinates=t.Vector2.Zero(),this.useCustomMeshPosition=!1,this.invert=!0,
- this.excludedMeshes=new Array,this.exposure=.3,this.decay=.96815,this.weight=.58767,this.density=.926;var f=o.getScene();this._viewPort=new t.Viewport(0,0,1,1).toGlobal(f.getEngine()),this.mesh=null!==s?s:i.CreateDefaultMesh("VolumetricLightScatteringMesh",f),this._createPass(f,n.passRatio||n),this.onApply=function(t){u._updateMeshScreenCoordinates(f),t.setTexture("lightScatteringSampler",u._volumetricLightScatteringRTT),t.setFloat("exposure",u.exposure),t.setFloat("decay",u.decay),t.setFloat("weight",u.weight),t.setFloat("density",u.density),t.setVector2("meshPositionOnScreen",u._screenCoordinates)}}return __extends(i,e),i.prototype.isReady=function(e,i){var r=e.getMesh(),n=[],o=[t.VertexBuffer.PositionKind],s=e.getMaterial(),a=!1;r===this.mesh&&(n.push("#define BASIC_RENDER"),n.push("#define NEED_UV"),a=!0),s&&((s.needAlphaTesting()||r===this.mesh)&&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(t.VertexBuffer.UVKind)&&(o.push(t.VertexBuffer.UVKind),n.push("#define UV1")),r.isVerticesDataPresent(t.VertexBuffer.UV2Kind)&&(o.push(t.VertexBuffer.UV2Kind),n.push("#define UV2"))),r.useBones&&(o.push(t.VertexBuffer.MatricesIndicesKind),o.push(t.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"],["diffuseSampler","opacitySampler"],h)),this._volumetricLightScatteringPass.isReady()},i.prototype.setCustomMeshPosition=function(t){this._customMeshPosition=t},i.prototype.getCustomMeshPosition=function(){return this._customMeshPosition},i.prototype.dispose=function(t){var i=t.getScene().customRenderTargets.indexOf(this._volumetricLightScatteringRTT);-1!==i&&t.getScene().customRenderTargets.splice(i,1),this._volumetricLightScatteringRTT.dispose(),e.prototype.dispose.call(this,t)},i.prototype.getPass=function(){return this._volumetricLightScatteringRTT},i.prototype._meshExcluded=function(t){return this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(t)?!0:!1},i.prototype._createPass=function(e,i){var r=this,n=e.getEngine();this._volumetricLightScatteringRTT=new t.RenderTargetTexture("volumetricLightScatteringMap",{width:n.getRenderWidth()*i,height:n.getRenderHeight()*i},e,!1,!0,t.Engine.TEXTURETYPE_UNSIGNED_INT),this._volumetricLightScatteringRTT.wrapU=t.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.wrapV=t.Texture.CLAMP_ADDRESSMODE,this._volumetricLightScatteringRTT.renderList=null,this._volumetricLightScatteringRTT.renderParticles=!1,e.customRenderTargets.push(this._volumetricLightScatteringRTT);var o,s=function(e){var i=e.getRenderingMesh();if(!r._meshExcluded(i)){var n=i.getScene(),o=n.getEngine();o.setState(e.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(e._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[e._id];if(r.isReady(e,a)){o.enableEffect(r._volumetricLightScatteringPass),i._bind(e,r._volumetricLightScatteringPass,t.Material.TriangleFillMode);var h=e.getMaterial();if(r._volumetricLightScatteringPass.setMatrix("viewProjection",n.getTransformMatrix()),h&&(i===r.mesh||h.needAlphaTesting()||void 0!==h.opacityTexture)){var c=h.getAlphaTestTexture();r._volumetricLightScatteringPass.setTexture("diffuseSampler",c),c&&r._volumetricLightScatteringPass.setMatrix("diffuseMatrix",c.getTextureMatrix()),void 0!==h.opacityTexture&&(r._volumetricLightScatteringPass.setTexture("opacitySampler",h.opacityTexture),r._volumetricLightScatteringPass.setFloat("opacityLevel",h.opacityTexture.level))}i.useBones&&r._volumetricLightScatteringPass.setMatrices("mBones",i.skeleton.getTransformMatrices()),i._processRendering(e,r._volumetricLightScatteringPass,t.Material.TriangleFillMode,s,a,function(t,e){return r._volumetricLightScatteringPass.setMatrix("world",e)})}}}},a=new t.Color4(0,0,0,1);this._volumetricLightScatteringRTT.onBeforeRender=function(){o=e.clearColor,e.clearColor=a},this._volumetricLightScatteringRTT.onAfterRender=function(){e.clearColor=o},this._volumetricLightScatteringRTT.customRenderFunction=function(i,r,n){var o,a=e.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(e.activeCamera.position).length()}var c=n.data.slice(0,n.length);for(c.sort(function(t,e){return t._alphaIndex>e._alphaIndex?1:t._alphaIndex<e._alphaIndex?-1:t._distanceToCamera<e._distanceToCamera?1:t._distanceToCamera>e._distanceToCamera?-1:0}),a.setAlphaMode(t.Engine.ALPHA_COMBINE),o=0;o<c.length;o++)s(c[o]);a.setAlphaMode(t.Engine.ALPHA_DISABLE)}}},i.prototype._updateMeshScreenCoordinates=function(e){var i=e.getTransformMatrix(),r=t.Vector3.Project(this.useCustomMeshPosition?this._customMeshPosition:this.mesh.position,t.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(e,i){var r=t.Mesh.CreatePlane(e,1,i);return r.billboardMode=t.AbstractMesh.BILLBOARDMODE_ALL,r.material=new t.StandardMaterial(e+"Material",i),r},i}(t.PostProcess);t.VolumetricLightScatteringPostProcess=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s){var a=this;void 0===o&&(o=1),e.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._dofDepth=void 0!==r.dof_focus_depth?r.dof_focus_depth:-1,this._dofAperture=r.dof_aperture?r.dof_aperture:1,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),this.addEffect(new t.PostProcessRenderEffect(n.getEngine(),this.LensChromaticAberrationEffect,function(){return a._chromaticAberrationPostProcess},!0)),this.addEffect(new t.PostProcessRenderEffect(n.getEngine(),this.HighlightsEnhancingEffect,function(){return a._highlightsPostProcess},!0)),this.addEffect(new t.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,e),i.prototype.setEdgeBlur=function(t){this._edgeBlur=t},i.prototype.disableEdgeBlur=function(){this._edgeBlur=0},i.prototype.setGrainAmount=function(t){this._grainAmount=t},i.prototype.disableGrain=function(){this._grainAmount=0},i.prototype.setChromaticAberration=function(t){this._chromaticAberration=t},i.prototype.disableChromaticAberration=function(){this._chromaticAberration=0},i.prototype.setEdgeDistortion=function(t){this._distortion=t},i.prototype.disableEdgeDistortion=function(){this._distortion=0},i.prototype.setFocusDepth=function(t){this._dofDepth=t},i.prototype.disableDepthOfField=function(){this._dofDepth=-1},i.prototype.setAperture=function(t){this._dofAperture=t},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(t){this._highlightsGain=t},i.prototype.setHighlightsThreshold=function(t){-1==this._highlightsGain&&(this._highlightsGain=1),this._highlightsThreshold=t},i.prototype.disableHighlights=function(){this._highlightsGain=-1},i.prototype.dispose=function(t){void 0===t&&(t=!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(),t&&this._scene.disableDepthRenderer()},i.prototype._createChromaticAberrationPostProcess=function(e){var i=this;this._chromaticAberrationPostProcess=new t.PostProcess("LensChromaticAberration","chromaticAberration",["chromatic_aberration","screen_width","screen_height"],[],e,null,t.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._chromaticAberrationPostProcess.onApply=function(t){t.setFloat("chromatic_aberration",i._chromaticAberration),t.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),t.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height)}},i.prototype._createHighlightsPostProcess=function(e){var i=this;this._highlightsPostProcess=new t.PostProcess("LensHighlights","lensHighlights",["pentagon","gain","threshold","screen_width","screen_height"],[],e,null,t.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._highlightsPostProcess.onApply=function(t){t.setFloat("gain",i._highlightsGain),t.setFloat("threshold",i._highlightsThreshold),t.setBool("pentagon",i._dofPentagon),t.setTextureFromPostProcess("textureSampler",i._chromaticAberrationPostProcess),t.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),t.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height)}},i.prototype._createDepthOfFieldPostProcess=function(e){var i=this;this._depthOfFieldPostProcess=new t.PostProcess("LensDepthOfField","depthOfField",["focus_depth","aperture","pentagon","maxZ","edge_blur","chromatic_aberration","distortion","blur_noise","grain_amount","screen_width","screen_height","highlights"],["depthSampler","grainSampler","highlightsSampler"],e,null,t.Texture.TRILINEAR_SAMPLINGMODE,this._scene.getEngine(),!1),this._depthOfFieldPostProcess.onApply=function(t){t.setBool("blur_noise",i._blurNoise),t.setFloat("maxZ",i._scene.activeCamera.maxZ),t.setFloat("grain_amount",i._grainAmount),t.setTexture("depthSampler",i._depthTexture),t.setTexture("grainSampler",i._grainTexture),t.setTextureFromPostProcess("textureSampler",i._highlightsPostProcess),t.setTextureFromPostProcess("highlightsSampler",i._depthOfFieldPostProcess),t.setFloat("screen_width",i._scene.getEngine().getRenderingCanvas().width),t.setFloat("screen_height",i._scene.getEngine().getRenderingCanvas().height),t.setFloat("distortion",i._distortion),t.setFloat("focus_depth",i._dofDepth),t.setFloat("aperture",i._dofAperture),t.setFloat("edge_blur",i._edgeBlur),t.setBool("highlights",-1!=i._highlightsGain)}},i.prototype._createGrainTexture=function(){var e=512;this._grainTexture=new t.DynamicTexture("LensNoiseTexture",e,this._scene,!1,t.Texture.BILINEAR_SAMPLINGMODE),this._grainTexture.wrapU=t.Texture.WRAP_ADDRESSMODE,this._grainTexture.wrapV=t.Texture.WRAP_ADDRESSMODE;for(var i,r=this._grainTexture.getContext(),n=function(t,e){return Math.random()*(e-t)+t},o=0;e>o;o++)for(var s=0;e>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}(t.PostProcessRenderPipeline);t.LensRenderingPipeline=e}(BABYLON||(BABYLON={}));var __extends=this.__extends||function(t,e){function i(){this.constructor=t}for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);i.prototype=e.prototype,t.prototype=new i},BABYLON;!function(t){var e=function(e){function i(i,r,n,o,s,a,h){var c=this;e.call(this,i,"colorCorrection",null,["colorTable"],n,o,s,a,h),this._colorTableTexture=new t.Texture(r,o.getScene(),!0,!1,t.Texture.TRILINEAR_SAMPLINGMODE),this._colorTableTexture.anisotropicFilteringLevel=1,this._colorTableTexture.wrapU=t.Texture.CLAMP_ADDRESSMODE,this._colorTableTexture.wrapV=t.Texture.CLAMP_ADDRESSMODE,this.onApply=function(t){t.setTexture("colorTable",c._colorTableTexture)}}return __extends(i,e),i}(t.PostProcess);t.ColorCorrectionPostProcess=e}(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 vec3 skyColor;\r\nuniform vec3 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 vec3 c = mix(skyColor, cloudColor, fbm(p));\r\n gl_FragColor = vec4(c, 1);\r\n\r\n}",colorPixelShader:"precision highp float;\n\nuniform vec4 color;\n\nvoid main(void) {\n gl_FragColor = color;\n}",colorVertexShader:"precision highp float;\n\n// Attributes\nattribute vec3 position;\n\n// Uniforms\nuniform mat4 worldViewProjection;\n\nvoid main(void) {\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}",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\nuniform vec4 vSpecularColor;\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\nuniform vec3 vLightSpecular0;\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\nuniform vec3 vLightSpecular1;\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\nuniform vec3 vLightSpecular2;\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\nuniform vec3 vLightSpecular3;\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#ifdef SPECULAR\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\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)\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 visibility;\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)\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 1.0 - ChebychevInequality(moments, depth.z, bias);\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 vec3 specular;\r\n};\r\n\r\nlightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, float range) {\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\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., vSpecularColor.a));\r\n\r\n result.diffuse = ndl * diffuseColor * attenuation;\r\n result.specular = specComp * specularColor * attenuation;\r\n\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) {\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\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\r\n result.diffuse = ndl * spotAtten * diffuseColor * attenuation;\r\n result.specular = specComp * specularColor * spotAtten * attenuation;\r\n\r\n return result;\r\n }\r\n\r\n result.diffuse = vec3(0.);\r\n result.specular = vec3(0.);\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) {\r\n lightingInfo result;\r\n\r\n // Diffuse\r\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\r\n\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\r\n result.diffuse = mix(groundColor, diffuseColor, ndl);\r\n result.specular = specComp * specularColor;\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 VERTEXCOLOR\r\n baseColor.rgb *= vColor.rgb;\r\n#endif\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 // 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\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 vec3 specularBase = vec3(0., 0., 0.);\r\n float shadow = 1.;\r\n\r\n#ifdef LIGHT0\r\n#ifdef SPOTLIGHT0\r\n lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a);\r\n#endif\r\n#ifdef HEMILIGHT0\r\n lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightGround0);\r\n#endif\r\n#ifdef POINTDIRLIGHT0\r\n lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a);\r\n#endif\r\n#ifdef SHADOW0\r\n#ifdef SHADOWVSM0\r\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0, shadowsInfo0.z);\r\n#else\r\n #ifdef SHADOWPCF0\r\n shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z);\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 specularBase += info.specular * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT1\r\n#ifdef SPOTLIGHT1\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a);\r\n#endif\r\n#ifdef HEMILIGHT1\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightGround1);\r\n#endif\r\n#ifdef POINTDIRLIGHT1\r\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a);\r\n#endif\r\n#ifdef SHADOW1\r\n#ifdef SHADOWVSM1\r\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1, shadowsInfo1.z);\r\n#else\r\n #ifdef SHADOWPCF1\r\n shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z);\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 specularBase += info.specular * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT2\r\n#ifdef SPOTLIGHT2\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a);\r\n#endif\r\n#ifdef HEMILIGHT2\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightGround2);\r\n#endif\r\n#ifdef POINTDIRLIGHT2\r\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a);\r\n#endif\r\n#ifdef SHADOW2\r\n#ifdef SHADOWVSM2\r\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2, shadowsInfo2.z);\r\n#else\r\n #ifdef SHADOWPCF2\r\n shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z);\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 specularBase += info.specular * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT3\r\n#ifdef SPOTLIGHT3\r\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a);\r\n#endif\r\n#ifdef HEMILIGHT3\r\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightGround3);\r\n#endif\r\n#ifdef POINTDIRLIGHT3\r\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a);\r\n#endif\r\n#ifdef SHADOW3\r\n#ifdef SHADOWVSM3\r\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3, shadowsInfo3.z);\r\n#else\r\n #ifdef SHADOWPCF3\r\n shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z);\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 specularBase += info.specular * shadow;\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 reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).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 reflectionColor *= reflectionLeftColor.rgb * (1.0 - reflectionFresnelTerm) + reflectionFresnelTerm * reflectionRightColor.rgb;\r\n#endif\r\n#endif\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 // Specular map\r\n vec3 specularColor = vSpecularColor.rgb;\r\n#ifdef SPECULAR\r\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\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 vec3 finalSpecular = specularBase * specularColor;\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 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}",
- 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#ifdef SPECULAR\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#ifdef SPECULAR\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 float maxZ;\r\nuniform bool blur_noise;\r\nuniform float screen_width;\r\nuniform float screen_height;\r\nuniform float distortion;\r\nuniform float focus_depth;\r\nuniform float aperture;\r\nuniform float edge_blur;\r\nuniform bool highlights;\r\n\r\n// varyings\r\nvarying vec2 vUV;\r\n\r\n// constants\r\n#define PI 3.14159265\r\n\r\n// common calculations\r\nvec2 centered_screen_pos;\r\nfloat radius2;\r\nfloat radius;\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// returns original screen color after blur\r\nvec4 getBlurColor(vec2 coords, float size) {\r\n\r\n vec4 col = texture2D(textureSampler, 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 = min(3.0, ceil(size / 1.0));\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\r\n col += texture2D(textureSampler, coords + vec2(-0.53*w, 0.15*h))*0.93;\r\n col += texture2D(textureSampler, coords + vec2(0.42*w, -0.69*h))*0.90;\r\n col += texture2D(textureSampler, coords + vec2(0.20*w, 1.00*h))*0.87;\r\n col += texture2D(textureSampler, coords + vec2(-0.97*w, -0.72*h))*0.85;\r\n col += texture2D(textureSampler, coords + vec2(1.37*w, -0.14*h))*0.83;\r\n col += texture2D(textureSampler, coords + vec2(-1.02*w, 1.16*h))*0.80;\r\n col += texture2D(textureSampler, coords + vec2(-0.03*w, -1.69*h))*0.78;\r\n col += texture2D(textureSampler, coords + vec2(1.27*w, 1.34*h))*0.76;\r\n col += texture2D(textureSampler, coords + vec2(-1.98*w, -0.14*h))*0.74;\r\n col += texture2D(textureSampler, coords + vec2(1.66*w, -1.32*h))*0.72;\r\n total_weight += 8.18;\r\n\r\n if (blur_level > 1.0) {\r\n col += texture2D(textureSampler, coords + vec2(-0.35*w, 2.22*h))*0.70;\r\n col += texture2D(textureSampler, coords + vec2(-1.31*w, -1.98*h))*0.67;\r\n col += texture2D(textureSampler, coords + vec2(2.42*w, 0.61*h))*0.65;\r\n col += texture2D(textureSampler, coords + vec2(-2.31*w, 1.25*h))*0.63;\r\n col += texture2D(textureSampler, coords + vec2(0.90*w, -2.59*h))*0.61;\r\n col += texture2D(textureSampler, coords + vec2(1.14*w, 2.62*h))*0.59;\r\n col += texture2D(textureSampler, coords + vec2(-2.72*w, -1.21*h))*0.56;\r\n col += texture2D(textureSampler, coords + vec2(2.93*w, -0.98*h))*0.54;\r\n col += texture2D(textureSampler, coords + vec2(-1.56*w, 2.80*h))*0.52;\r\n col += texture2D(textureSampler, coords + vec2(-0.77*w, -3.22*h))*0.49;\r\n total_weight += 5.96;\r\n }\r\n\r\n if (blur_level > 2.0) {\r\n col += texture2D(textureSampler, coords + vec2(2.83*w, 1.92*h))*0.46;\r\n col += texture2D(textureSampler, coords + vec2(-3.49*w, 0.51*h))*0.44;\r\n col += texture2D(textureSampler, coords + vec2(2.30*w, -2.82*h))*0.41;\r\n col += texture2D(textureSampler, coords + vec2(0.22*w, 3.74*h))*0.38;\r\n col += texture2D(textureSampler, coords + vec2(-2.76*w, -2.68*h))*0.34;\r\n col += texture2D(textureSampler, coords + vec2(3.95*w, 0.11*h))*0.31;\r\n col += texture2D(textureSampler, coords + vec2(-3.07*w, 2.65*h))*0.26;\r\n col += texture2D(textureSampler, coords + vec2(0.48*w, -4.13*h))*0.22;\r\n col += texture2D(textureSampler, coords + vec2(2.49*w, 3.46*h))*0.15;\r\n total_weight += 2.97;\r\n }\r\n\r\n col /= total_weight; // scales color according to weights\r\n col.a = 1.0;\r\n\r\n // blur levels debug\r\n // if(blur_level == 1.0) { col.b = 0.0; }\r\n // if(blur_level == 2.0) { col.r = 0.0; }\r\n // if(blur_level == 3.0) { col.g = 0.0; }\r\n\r\n return col;\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\nvoid main(void)\r\n{\r\n\r\n // Common calc\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\r\n vec4 final_color;\r\n vec2 distorted_coords = getDistortedCoords(vUV);\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 // blur from depth of field effect\r\n float dof_blur_amount = 0.0;\r\n float depth_bias = 0.0; // positive if the pixel is further than focus depth; negative if closer\r\n if (focus_depth != -1.0) {\r\n vec4 depth_sample = texture2D(depthSampler, distorted_coords);\r\n float depth = depth_sample.r;\r\n depth_bias = depth - focus_depth;\r\n\r\n // compute blur amount with distance\r\n if (depth_bias > 0.0) { dof_blur_amount = depth_bias * aperture * 2.2; }\r\n else { dof_blur_amount = depth_bias * depth_bias * aperture * 30.0; }\r\n\r\n if (dof_blur_amount < 0.05) { dof_blur_amount = 0.0; } // no blur at all\r\n }\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, dof_blur_amount);\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(distorted_coords, blur_amount * 1.7);\r\n\r\n // if further than focus depth & we have computed highlights: enhance highlights\r\n if (depth_bias > 0.0 && highlights) {\r\n gl_FragColor += clamp(dof_blur_amount, 0.0, 1.0)*texture2D(highlightsSampler, distorted_coords);\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 // 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.20;\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}",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\nuniform vec4 vSpecularColor;\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\nuniform vec3 vLightSpecular0;\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\nuniform vec3 vLightSpecular1;\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\nuniform vec3 vLightSpecular2;\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\nuniform vec3 vLightSpecular3;\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#ifdef SPECULAR\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 // 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\r\n result[0] = ndl * diffuseColor.rgb;\r\n result[1] = specComp * specularColor;\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\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\r\n result[0] = ndl * spotAtten * diffuseColor.rgb;\r\n result[1] = specComp * specularColor * spotAtten;\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\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\r\n result[0] = mix(groundColor, diffuseColor.rgb, ndl);\r\n result[1] = specComp * specularColor;\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 VERTEXCOLOR\r\n baseColor.rgb *= vColor.rgb;\r\n#endif\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 // 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 vec3 specularBase = vec3(0., 0., 0.);\r\n float shadow = 1.;\r\n\r\n#ifdef LIGHT0\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 specularBase += info[1] * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT1\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 specularBase += info[1] * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT2\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 specularBase += info[1] * shadow;\r\n#endif\r\n\r\n#ifdef LIGHT3\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 specularBase += info[1] * shadow;\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 vec3 specularColor = vSpecularColor.rgb;\r\n#ifdef SPECULAR\r\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\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 vec3 finalSpecular = specularBase * specularColor;\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#ifdef SPECULAR\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#ifdef SPECULAR\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}",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}",oculusDistortionCorrectionPixelShader:"#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}",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",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(BASIC_RENDER) || defined(OPACITY)\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(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 #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 #ifndef BASIC_RENDER\r\n gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n #else\r\n gl_FragColor = diffuseColor;\r\n #endif\r\n#endif\r\n\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 i=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=i;var e=function(){function i(i,e,r){this.collider=i,this._collisionCache=e,this.finalPosition=r,this.collisionsScalingMatrix=o.Matrix.Zero(),this.collisionTranformationMatrix=o.Matrix.Zero()}return i.prototype.collideWithWorld=function(o,i,e,r){var t=.01;if(this.collider.retry>=e)return void this.finalPosition.copyFrom(o);this.collider._initialize(o,i,t);var s=this._collisionCache.getMeshes();for(var l in s)if(s.hasOwnProperty(l)&&parseInt(l)!=r){var n=s[l];n.checkCollisions&&this.checkCollision(n)}return this.collider.collisionFound?((0!==i.x||0!==i.y||0!==i.z)&&this.collider._getResponse(o,i),i.length()<=t?void this.finalPosition.copyFrom(o):(this.collider.retry++,void this.collideWithWorld(o,i,e,r))):void o.addToRef(i,this.finalPosition)},i.prototype.checkCollision=function(i){if(this.collider._canDoCollision(o.Vector3.FromArray(i.sphereCenter),i.sphereRadius,o.Vector3.FromArray(i.boxMinimum),o.Vector3.FromArray(i.boxMaximum))){o.Matrix.ScalingToRef(1/this.collider.radius.x,1/this.collider.radius.y,1/this.collider.radius.z,this.collisionsScalingMatrix);var e=o.Matrix.FromArray(i.worldMatrixFromCache);e.multiplyToRef(this.collisionsScalingMatrix,this.collisionTranformationMatrix),this.processCollisionsForSubMeshes(this.collisionTranformationMatrix,i)}},i.prototype.processCollisionsForSubMeshes=function(o,i){var e,r;if(r=i.subMeshes,e=r.length,!i.geometryId)return void console.log("no mesh geometry id");var t=this._collisionCache.getGeometry(i.geometryId);if(!t)return void console.log("couldn\'t find geometry",i.geometryId);for(var s=0;e>s;s++){var l=r[s];e>1&&!this.checkSubmeshCollision(l)||this.collideForSubMesh(l,o,t)}},i.prototype.collideForSubMesh=function(i,e,r){for(var t=[],s=0;s<r.positions.length;s+=3){var l=o.Vector3.FromArray([r.positions[s],r.positions[s+1],r.positions[s+2]]);t.push(l)}i._lastColliderTransformMatrix=e.clone(),i._lastColliderWorldVertices=[],i._trianglePlanes=[];for(var n=i.verticesStart,a=i.verticesStart+i.verticesCount,s=n;a>s;s++)i._lastColliderWorldVertices.push(o.Vector3.TransformCoordinates(t[s],e));this.collider._collide(i._trianglePlanes=[],i._lastColliderWorldVertices,r.indices,i.indexStart,i.indexStart+i.indexCount,i.verticesStart,i.hasMaterial)},i.prototype.checkSubmeshCollision=function(i){return this.collider._canDoCollision(o.Vector3.FromArray(i.sphereCenter),i.sphereRadius,o.Vector3.FromArray(i.boxMinimum),o.Vector3.FromArray(i.boxMaximum))},i}();o.CollideWorker=e;var r=function(){function r(){}return r.prototype.onInit=function(o){this._collisionCache=new i;var e={error:0,taskType:0};postMessage(e,void 0)},r.prototype.onUpdate=function(o){for(var i in o.updatedGeometries)o.updatedGeometries.hasOwnProperty(i)&&this._collisionCache.addGeometry(o.updatedGeometries[i]);for(var e in o.updatedMeshes)o.updatedMeshes.hasOwnProperty(e)&&this._collisionCache.addMesh(o.updatedMeshes[e]);var r={error:0,taskType:1};postMessage(r,void 0)},r.prototype.onCollision=function(i){var r=o.Vector3.Zero(),t=new o.Collider;t.radius=o.Vector3.FromArray(i.collider.radius);var s=new e(t,this._collisionCache,r);s.collideWithWorld(o.Vector3.FromArray(i.collider.position),o.Vector3.FromArray(i.collider.velocity),i.maximumRetry,i.excludedMeshUniqueId);var l={collidedMeshUniqueId:t.collidedMesh,collisionId:i.collisionId,newPosition:r.asArray()},n={error:0,taskType:2,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(o){var i=o.data;switch(i.taskType){case 0:t.onInit(i.payload);break;case 2:t.onCollision(i.payload);break;case 1: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={}));e.WorkerTaskType;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(e.WorkerReplyType||(e.WorkerReplyType={}));var o=(e.WorkerReplyType,function(){function o(){var i=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){i._addUpdateMeshesList[e.uniqueId]=o.SerializeMesh(e)},this.onGeometryUpdated=function(e){i._addUpdateGeometriesList[e.id]=o.SerializeGeometry(e)},this._afterRender=function(){if(i._init&&!(0==i._toRemoveGeometryArray.length&&0==i._toRemoveMeshesArray.length&&0==Object.keys(i._addUpdateGeometriesList).length&&0==Object.keys(i._addUpdateMeshesList).length||i._runningUpdated>4)){++i._runningUpdated;var e={updatedMeshes:i._addUpdateMeshesList,updatedGeometries:i._addUpdateGeometriesList,removedGeometries:i._toRemoveGeometryArray,removedMeshes:i._toRemoveMeshesArray},o={payload:e,taskType:1},t=[];for(var r in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(r)&&(t.push(o.payload.updatedGeometries[r].indices.buffer),t.push(o.payload.updatedGeometries[r].normals.buffer),t.push(o.payload.updatedGeometries[r].positions.buffer));i._worker.postMessage(o,t),i._addUpdateMeshesList={},i._addUpdateGeometriesList={},i._toRemoveGeometryArray=[],i._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(o){var t=o.data;if(0!=t.error)return void e.Tools.Warn("error returned from worker!");switch(t.taskType){case 0:i._init=!0,i._scene.meshes.forEach(function(e){i.onMeshAdded(e)}),i._scene.getGeometries().forEach(function(e){i.onGeometryAdded(e)});break;case 1:i._runningUpdated--;break;case 2:i._runningCollisionTask=!1;var r=t.payload;if(!i._collisionsCallbackArray[r.collisionId])return;i._collisionsCallbackArray[r.collisionId](r.collisionId,e.Vector3.FromArray(r.newPosition),i._scene.getMeshByUniqueID(r.collidedMeshUniqueId)),i._collisionsCallbackArray[r.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return o.prototype.getNewPosition=function(e,o,i,t,r,s,n){if(!this._init,!this._collisionsCallbackArray[n]){e.divideToRef(i.radius,this._scaledPosition),o.divideToRef(i.radius,this._scaledVelocity),this._collisionsCallbackArray[n]=s;var a={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:i.radius.asArray()},collisionId:n,excludedMeshUniqueId:r?r.uniqueId:null,maximumRetry:t},d={payload:a,taskType:2};this._worker.postMessage(d)}},o.prototype.init=function(o){this._scene=o,this._scene.registerAfterRender(this._afterRender);var i=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(i),this._worker.onmessage=this._onMessageFromWorker;var t={payload:{},taskType:0};this._worker.postMessage(t)},o.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},o.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},o.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},o.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},o.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},o.SerializeMesh=function(e){var o=[];e.subMeshes&&(o=e.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 i=e.geometry?e.geometry.id:null;return{uniqueId:e.uniqueId,id:e.id,name:e.name,geometryId:i,sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray(),worldMatrixFromCache:e.worldMatrixFromCache.asArray(),subMeshes:o,checkCollisions:e.checkCollisions}},o.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()||[])}},o}());e.CollisionCoordinatorWorker=o;var i=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.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(null,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=i}(BABYLON||(BABYLON={}));var BABYLON;!function(t){var i=function(){function t(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 t.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},t.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},t.prototype.toColor4=function(t){return void 0===t&&(t=1),new o(this.r,this.g,this.b,t)},t.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},t.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},t.prototype.multiply=function(i){return new t(this.r*i.r,this.g*i.g,this.b*i.b)},t.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},t.prototype.equals=function(t){return t&&this.r===t.r&&this.g===t.g&&this.b===t.b},t.prototype.scale=function(i){return new t(this.r*i,this.g*i,this.b*i)},t.prototype.scaleToRef=function(t,i){return i.r=this.r*t,i.g=this.g*t,i.b=this.b*t,this},t.prototype.add=function(i){return new t(this.r+i.r,this.g+i.g,this.b+i.b)},t.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},t.prototype.subtract=function(i){return new t(this.r-i.r,this.g-i.g,this.b-i.b)},t.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},t.prototype.clone=function(){return new t(this.r,this.g,this.b)},t.prototype.copyFrom=function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this},t.prototype.copyFromFloats=function(t,i,o){return this.r=t,this.g=i,this.b=o,this},t.FromArray=function(i,o){return void 0===o&&(o=0),new t(i[o],i[o+1],i[o+2])},t.FromInts=function(i,o,n){return new t(i/255,o/255,n/255)},t.Lerp=function(i,o,n){var r=i.r+(o.r-i.r)*n,s=i.g+(o.g-i.g)*n,e=i.b+(o.b-i.b)*n;return new t(r,s,e)},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}();t.Color3=i;var o=function(){function t(t,i,o,n){this.r=t,this.g=i,this.b=o,this.a=n}return t.prototype.addInPlace=function(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this.a+=t.a,this},t.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},t.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},t.prototype.add=function(i){return new t(this.r+i.r,this.g+i.g,this.b+i.b,this.a+i.a)},t.prototype.subtract=function(i){return new t(this.r-i.r,this.g-i.g,this.b-i.b,this.a-i.a)},t.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},t.prototype.scale=function(i){return new t(this.r*i,this.g*i,this.b*i,this.a*i)},t.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},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(t){return this.r=t.r,this.g=t.g,this.b=t.b,this.a=t.a,this},t.Lerp=function(i,o,n){var r=new t(0,0,0,0);return t.LerpToRef(i,o,n,r),r},t.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},t.FromArray=function(i,o){return void 0===o&&(o=0),new t(i[o],i[o+1],i[o+2],i[o+3])},t.FromInts=function(i,o,n,r){return new t(i/255,o/255,n/255,r/255)},t}();t.Color4=o;var n=function(){function t(t,i){this.x=t,this.y=i}return t.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}"},t.prototype.toArray=function(t,i){return void 0===i&&(i=0),t[i]=this.x,t[i+1]=this.y,this},t.prototype.asArray=function(){var t=[];return this.toArray(t,0),t},t.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this},t.prototype.copyFromFloats=function(t,i){return this.x=t,this.y=i,this},t.prototype.add=function(i){return new t(this.x+i.x,this.y+i.y)},t.prototype.addVector3=function(i){return new t(this.x+i.x,this.y+i.y)},t.prototype.subtract=function(i){return new t(this.x-i.x,this.y-i.y)},t.prototype.subtractInPlace=function(t){return this.x-=t.x,this.y-=t.y,this},t.prototype.multiplyInPlace=function(t){return this.x*=t.x,this.y*=t.y,this},t.prototype.multiply=function(i){return new t(this.x*i.x,this.y*i.y)},t.prototype.multiplyToRef=function(t,i){return i.x=this.x*t.x,i.y=this.y*t.y,this},t.prototype.multiplyByFloats=function(i,o){return new t(this.x*i,this.y*o)},t.prototype.divide=function(i){return new t(this.x/i.x,this.y/i.y)},t.prototype.divideToRef=function(t,i){return i.x=this.x/t.x,i.y=this.y/t.y,this},t.prototype.negate=function(){return new t(-this.x,-this.y)},t.prototype.scaleInPlace=function(t){return this.x*=t,this.y*=t,this},t.prototype.scale=function(i){return new t(this.x*i,this.y*i)},t.prototype.equals=function(t){return t&&this.x===t.x&&this.y===t.y},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 t=this.length();if(0===t)return this;var i=1/t;return this.x*=i,this.y*=i,this},t.prototype.clone=function(){return new t(this.x,this.y)},t.Zero=function(){return new t(0,0)},t.FromArray=function(i,o){return void 0===o&&(o=0),new t(i[o],i[o+1])},t.FromArrayToRef=function(t,i,o){o.x=t[i],o.y=t[i+1]},t.CatmullRom=function(i,o,n,r,s){var e=s*s,a=s*e,h=.5*(2*o.x+(-i.x+n.x)*s+(2*i.x-5*o.x+4*n.x-r.x)*e+(-i.x+3*o.x-3*n.x+r.x)*a),u=.5*(2*o.y+(-i.y+n.y)*s+(2*i.y-5*o.y+4*n.y-r.y)*e+(-i.y+3*o.y-3*n.y+r.y)*a);return new t(h,u)},t.Clamp=function(i,o,n){var r=i.x;r=r>n.x?n.x:r,r=r<o.x?o.x:r;var s=i.y;return s=s>n.y?n.y:s,s=s<o.y?o.y:s,new t(r,s)},t.Hermite=function(i,o,n,r,s){var e=s*s,a=s*e,h=2*a-3*e+1,u=-2*a+3*e,m=a-2*e+s,l=a-e,f=i.x*h+n.x*u+o.x*m+r.x*l,x=i.y*h+n.y*u+o.y*m+r.y*l;return new t(f,x)},t.Lerp=function(i,o,n){var r=i.x+(o.x-i.x)*n,s=i.y+(o.y-i.y)*n;return new t(r,s)},t.Dot=function(t,i){return t.x*i.x+t.y*i.y},t.Normalize=function(t){var i=t.clone();return i.normalize(),i},t.Minimize=function(i,o){var n=i.x<o.x?i.x:o.x,r=i.y<o.y?i.y:o.y;return new t(n,r)},t.Maximize=function(i,o){var n=i.x>o.x?i.x:o.x,r=i.y>o.y?i.y:o.y;return new t(n,r)},t.Transform=function(i,o){var n=i.x*o.m[0]+i.y*o.m[4],r=i.x*o.m[1]+i.y*o.m[5];return new t(n,r)},t.Distance=function(i,o){return Math.sqrt(t.DistanceSquared(i,o))},t.DistanceSquared=function(t,i){var o=t.x-i.x,n=t.y-i.y;return o*o+n*n},t}();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){return Math.abs(this.x-i.x)<t.Engine.Epsilon&&Math.abs(this.y-i.y)<t.Engine.Epsilon&&Math.abs(this.z-i.z)<t.Engine.Epsilon},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)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.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),m=SIMD.float32x4.load(n.m,8),l=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,m),l));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),m=.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,m)},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,m=a-2*e+s,l=a-e,f=t.x*h+n.x*u+o.x*m+r.x*l,x=t.y*h+n.y*u+o.y*m+r.y*l,y=t.z*h+n.z*u+o.z*m+r.z*l;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,m=a.FromValues(s/2,0,0,0,0,-e/2,0,0,0,0,1,0,h+s/2,e/2+u,0,1),l=o.multiply(n).multiply(m);return i.TransformCoordinates(t,l)},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(),o.x=o.x/n*2-1,o.y=-(o.y/r*2-1);var u=i.TransformCoordinates(o,h),m=o.x*h.m[3]+o.y*h.m[7]+o.z*h.m[11]+h.m[15];return t.Tools.WithinEpsilon(m,1)&&(u=u.scale(1/m)),u},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}();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){return Math.abs(this.x-i.x)<t.Engine.Epsilon&&Math.abs(this.y-i.y)<t.Engine.Epsilon&&Math.abs(this.z-i.z)<t.Engine.Epsilon&&Math.abs(this.w-i.w)<t.Engine.Epsilon},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){return i.x=this.x*t.w+this.y*t.z-this.z*t.y+this.w*t.x,i.y=-this.x*t.z+this.y*t.w+this.z*t.x+this.w*t.y,i.z=this.x*t.y-this.y*t.x+this.z*t.w+this.w*t.z,i.w=-this.x*t.x-this.y*t.y-this.z*t.z+this.w*t.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.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,m=o*n,l=i*i,f=o*o,x=l+f;return 0!==x&&1!==x?(t.x=Math.atan2(e+a,u-m),t.y=Math.acos(1-2*x),t.z=Math.atan2(e-a,u+m)):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],m=n[2],l=n[6],f=n[10],x=r+h+f;x>0?(o=.5/Math.sqrt(x+1),i.w=.25/o,i.x=(l-u)*o,i.y=(e-m)*o,i.z=(a-s)*o):r>h&&r>f?(o=2*Math.sqrt(1+r-h-f),i.w=(l-u)/o,i.x=.25*o,i.y=(s+a)/o,i.z=(e+m)/o):h>f?(o=2*Math.sqrt(1+h-r-f),i.w=(e-m)/o,i.x=(s+a)/o,i.y=.25*o,i.z=(u+l)/o):(o=2*Math.sqrt(1+f-r-h),i.w=(a-s)/o,i.x=(e+m)/o,i.y=(u+l)/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),m=Math.cos(s),l=Math.sin(e),f=Math.cos(e);n.x=f*u*h+l*m*a,n.y=l*m*h-f*u*a,n.z=f*m*a-l*u*h,n.w=f*m*h+l*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),m=1/Math.sin(u);s=Math.sin((1-e)*u)*m,r=h?-Math.sin(e*u)*m:Math.sin(e*u)*m}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.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],m=this.m[9],l=this.m[10],f=this.m[11],x=this.m[12],y=this.m[13],c=this.m[14],p=this.m[15],z=l*p-f*c,M=m*p-f*y,w=m*c-l*y,d=u*p-f*x,I=u*c-l*x,D=u*y-m*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,A=e*c-a*y,F=s*p-h*x,P=s*c-a*x,C=s*y-e*x,L=a*f-h*l,q=e*f-h*m,E=e*l-a*m,Z=s*f-h*u,V=s*l-a*u,N=s*m-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*A)*R,t.m[6]=-(i*_-n*F+r*P)*R,t.m[10]=(i*b-o*F+r*C)*R,t.m[14]=-(i*A-o*P+n*C)*R,t.m[3]=-(o*L-n*q+r*E)*R,t.m[7]=(i*L-n*Z+r*V)*R,t.m[11]=-(i*q-o*Z+r*N)*R,t.m[15]=(i*E-o*V+n*N)*R,this},i.prototype.invertToRefSIMD=function(t){var i,o,n,r,s,e,a,h,u,m,l=this.m,f=t.m,x=SIMD.float32x4.load(l,0),y=SIMD.float32x4.load(l,4),c=SIMD.float32x4.load(l,8),p=SIMD.float32x4.load(l,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),m=SIMD.float32x4.mul(i,e),m=SIMD.float32x4.add(SIMD.float32x4.swizzle(m,2,3,0,1),m),m=SIMD.float32x4.add(SIMD.float32x4.swizzle(m,1,0,3,2),m),s=SIMD.float32x4.reciprocalApproximation(m),m=SIMD.float32x4.sub(SIMD.float32x4.add(s,s),SIMD.float32x4.mul(m,SIMD.float32x4.mul(s,s))),m=SIMD.float32x4.swizzle(m,0,0,0,0),e=SIMD.float32x4.mul(m,e),a=SIMD.float32x4.mul(m,a),h=SIMD.float32x4.mul(m,h),u=SIMD.float32x4.mul(m,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],m=this.m[7],l=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],A=t.m[11],F=t.m[12],P=t.m[13],C=t.m[14],L=t.m[15];return i[o]=n*w+r*S+s*R+e*F,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*A+e*L,i[o+4]=a*w+h*S+u*R+m*F,i[o+5]=a*d+h*v+u*_+m*P,i[o+6]=a*I+h*g+u*b+m*C,i[o+7]=a*D+h*T+u*A+m*L,i[o+8]=l*w+f*S+x*R+y*F,i[o+9]=l*d+f*v+x*_+y*P,i[o+10]=l*I+f*g+x*b+y*C,i[o+11]=l*D+f*T+x*A+y*L,i[o+12]=c*w+p*S+z*R+M*F,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*A+M*L,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)))));var m=SIMD.float32x4.load(n,4);SIMD.float32x4.store(i,o+4,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 l=SIMD.float32x4.load(n,8);SIMD.float32x4.store(i,o+8,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 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.FromValuesToRef=function(t,i,o,n,r,s,e,a,h,u,m,l,f,x,y,c,p){\np.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]=m,p.m[11]=l,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,m,l,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]=m,z.m[10]=l,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 m=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(m,m),u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),m=SIMD.float32x4.mul(m,SIMD.float32x4.reciprocalSqrtApproximation(u));var l=SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,1,2,0,3),SIMD.float32x4.swizzle(h,2,0,1,3)),SIMD.float32x4.mul(SIMD.float32x4.swizzle(m,2,0,1,3),SIMD.float32x4.swizzle(h,1,2,0,3)));u=SIMD.float32x4.mul(m,m),u=SIMD.float32x4.add(u,SIMD.float32x4.add(SIMD.float32x4.swizzle(u,1,2,0,3),SIMD.float32x4.swizzle(u,2,0,1,3))),m=SIMD.float32x4.mul(m,SIMD.float32x4.reciprocalSqrtApproximation(u));var f=SIMD.float32x4.splat(0);m=SIMD.float32x4.neg(m);var x=SIMD.float32x4.shuffle(m,l,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(m,l,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,m=t.y,l=i.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,e-s,0,u+a/2,h/2+m,s,1);return o.multiply(n).multiply(r).multiply(l)},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],m=n*o.m[8]+r*o.m[9]+s*o.m[10]+e*o.m[11],l=n*o.m[12]+r*o.m[13]+s*o.m[14]+e*o.m[15];return new t(h,u,m,l)},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,m=s*u-e*h,l=e*a-r*u,f=r*h-s*a,x=Math.sqrt(m*m+l*l+f*f);return n=0!==x?1/x:0,this.normal.x=m*n,this.normal.y=l*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 m=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[10]+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=m;var l=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=0,n=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{var r=1/this.direction.x,s=(t.x-this.origin.x)*r,e=(i.x-this.origin.x)*r;if(e===-(1/0)&&(e=1/0),s>e){var a=s;s=e,e=a}if(o=Math.max(s,o),n=Math.min(e,n),o>n)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(r=1/this.direction.y,s=(t.y-this.origin.y)*r,e=(i.y-this.origin.y)*r,e===-(1/0)&&(e=1/0),s>e&&(a=s,s=e,e=a),o=Math.max(s,o),n=Math.min(e,n),o>n)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(r=1/this.direction.z,s=(t.z-this.origin.z)*r,e=(i.z-this.origin.z)*r,e===-(1/0)&&(e=1/0),s>e&&(a=s,s=e,e=a),o=Math.max(s,o),n=Math.min(e,n),o>n)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),m=r.Unproject(new r(t,o,1),n,s,e,a,h),l=m.subtract(u);return l.normalize(),new i(u,l)},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=l,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 m=h*h,l=m*h,f=s*l+e*m+a*h,x=1/(3*s*m+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,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=y;var c=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=y.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),u=y.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),m=y.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();u-h>180&&(u-=360),-180>u-h&&(u+=360),m-u>180&&(m-=360),-180>m-u&&(m+=360),this.orientation=0>u-h?0:1,this.angle=y.FromDegrees(0===this.orientation?h-m:m-h)}return t}();t.Arc2=c;var p=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=p;var z=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),m=new c(a,h,u),l=m.angle.radians()/e;0===m.orientation&&(l*=-1);for(var f=m.startAngle.radians()+l,x=0;e>x;x++){var y=Math.cos(f)*m.radius+m.centerPoint.x,p=Math.sin(f)*m.radius+m.centerPoint.y;this.addLineTo(y,p),f+=l}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),m=u.length()+r;if(o>=r&&m>=o){var l=u.normalize(),f=o-r;return new n(a.x+l.x*f,a.y+l.y*f)}r=m}return t.Tools.Error("internal error"),n.Zero()},i.StartingAt=function(t,o){return new i(t,o)},i}();t.Path2=z;var M=function(){function t(t,i){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 o=0;o<t.length;o++)this._curve[o]=t[o].clone();this._compute(i)}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(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},t.prototype._compute=function(t){var i=this._curve.length;this._tangents[0]=this._getFirstNonNullVector(0),this._tangents[0].normalize(),this._tangents[i-1]=this._curve[i-1].subtract(this._curve[i-2]),this._tangents[i-1].normalize();var o=this._tangents[0],n=this._normalVector(this._curve[0],o,t);this._normals[0]=n,this._normals[0].normalize(),this._binormals[0]=r.Cross(o,this._normals[0]),this._binormals[0].normalize(),this._distances[0]=0;for(var s,e,a,h,u,m=1;i>m;m++)s=this._getLastNonNullVector(m),i-1>m&&(e=this._getFirstNonNullVector(m),this._tangents[m]=s.add(e),this._tangents[m].normalize()),this._distances[m]=this._distances[m-1]+s.length(),a=this._tangents[m],h=this._normals[m-1],u=this._binormals[m-1],this._normals[m]=r.Cross(u,a),this._normals[m].normalize(),this._binormals[m]=r.Cross(a,this._normals[m]),this._binormals[m].normalize()},t.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},t.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},t.prototype._normalVector=function(t,i,o){var n;if(void 0===o||null===o){var s;1!==i.x?s=new r(1,0,0):1!==i.y?s=new r(0,1,0):1!==i.z&&(s=new r(0,0,1)),n=r.Cross(i,s)}else n=r.Cross(i,o),r.CrossToRef(n,i,n);return n.normalize(),n},t}();t.Path3D=M;var w=function(){function i(t){this._length=0,this._points=t,this._length=this._computeLength(t)}return i.CreateQuadraticBezier=function(t,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,t.x,o.x,n.x),a(h/s,t.y,o.y,n.y),a(h/s,t.z,o.z,n.z)));return new i(e)},i.CreateCubicBezier=function(t,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,t.x,o.x,n.x,s.x),h(u/e,t.y,o.y,n.y,s.y),h(u/e,t.z,o.z,n.z,s.z)));return new i(a)},i.CreateHermiteSpline=function(o,n,r,s,e){for(var a=new Array,h=1/e,u=0;e>=u;u++)a.push(t.Vector3.Hermite(o,n,r,s,u*h));return new i(a)},i.prototype.getPoints=function(){return this._points},i.prototype.length=function(){return this._length},i.prototype["continue"]=function(t){for(var o=this._points[this._points.length-1],n=this._points.slice(),r=t.getPoints(),s=1;s<r.length;s++)n.push(r[s].subtract(r[0]).add(o));var e=new i(n);return e},i.prototype._computeLength=function(t){for(var i=0,o=1;o<t.length;o++)i+=t[o].subtract(t[o-1]).length();return i},i}();t.Curve3=w;var d=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=d;var I=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=I;var D=a.prototype.multiplyToArray,S=a.prototype.invertToRef,v=a.LookAtLHToRef,g=r.TransformCoordinatesToRef,T=r.TransformCoordinatesFromFloatsToRef,R=function(){function i(){}return Object.defineProperty(i,"IsEnabled",{get:function(){return i._isEnabled},enumerable:!0,configurable:!0}),i.DisableSIMD=function(){a.prototype.multiplyToArray=D,a.prototype.invertToRef=S,a.LookAtLHToRef=v,r.TransformCoordinatesToRef=g,r.TransformCoordinatesFromFloatsToRef=T,i._isEnabled=!1},i.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(t.Vector3.prototype,"x",{get:function(){return this._data[0]},set:function(t){this._data||(this._data=new Float32Array(3)),this._data[0]=t}}),Object.defineProperty(t.Vector3.prototype,"y",{get:function(){return this._data[1]},set:function(t){this._data[1]=t}}),Object.defineProperty(t.Vector3.prototype,"z",{get:function(){return this._data[2]},set:function(t){this._data[2]=t}}),i._isEnabled=!0)},i._isEnabled=!1,i}();t.SIMDHelper=R,void 0!==window.SIMD&&R.EnableSIMD()}(BABYLON||(BABYLON={}));';
|